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
|
|---|---|---|---|---|---|---|---|---|
kevinr/750book-web
|
750book-web-env/lib/python2.7/site-packages/debug_toolbar/utils/sqlparse/lexer.py
|
18
|
11470
|
# -*- coding: utf-8 -*-
# Copyright (C) 2008 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php.
"""SQL Lexer"""
# This code is based on the SqlLexer in pygments.
# http://pygments.org/
# It's separated from the rest of pygments to increase performance
# and to allow some customizations.
import re
from debug_toolbar.utils.sqlparse.keywords import KEYWORDS, KEYWORDS_COMMON
from debug_toolbar.utils.sqlparse.tokens import *
from debug_toolbar.utils.sqlparse.tokens import _TokenType
class include(str):
pass
class combined(tuple):
"""Indicates a state combined from multiple states."""
def __new__(cls, *args):
return tuple.__new__(cls, args)
def __init__(self, *args):
# tuple.__init__ doesn't do anything
pass
def is_keyword(value):
test = value.upper()
return KEYWORDS_COMMON.get(test, KEYWORDS.get(test, Name)), value
def apply_filters(stream, filters, lexer=None):
"""
Use this method to apply an iterable of filters to
a stream. If lexer is given it's forwarded to the
filter, otherwise the filter receives `None`.
"""
def _apply(filter_, stream):
for token in filter_.filter(lexer, stream):
yield token
for filter_ in filters:
stream = _apply(filter_, stream)
return stream
class LexerMeta(type):
"""
Metaclass for Lexer, creates the self._tokens attribute from
self.tokens on the first instantiation.
"""
def _process_state(cls, unprocessed, processed, state):
assert type(state) is str, "wrong state name %r" % state
assert state[0] != '#', "invalid state name %r" % state
if state in processed:
return processed[state]
tokens = processed[state] = []
rflags = cls.flags
for tdef in unprocessed[state]:
if isinstance(tdef, include):
# it's a state reference
assert tdef != state, "circular state reference %r" % state
tokens.extend(cls._process_state(unprocessed, processed, str(tdef)))
continue
assert type(tdef) is tuple, "wrong rule def %r" % tdef
try:
rex = re.compile(tdef[0], rflags).match
except Exception, err:
raise ValueError("uncompilable regex %r in state %r of %r: %s" %
(tdef[0], state, cls, err))
assert type(tdef[1]) is _TokenType or callable(tdef[1]), \
'token type must be simple type or callable, not %r' % (tdef[1],)
if len(tdef) == 2:
new_state = None
else:
tdef2 = tdef[2]
if isinstance(tdef2, str):
# an existing state
if tdef2 == '#pop':
new_state = -1
elif tdef2 in unprocessed:
new_state = (tdef2,)
elif tdef2 == '#push':
new_state = tdef2
elif tdef2[:5] == '#pop:':
new_state = -int(tdef2[5:])
else:
assert False, 'unknown new state %r' % tdef2
elif isinstance(tdef2, combined):
# combine a new state from existing ones
new_state = '_tmp_%d' % cls._tmpname
cls._tmpname += 1
itokens = []
for istate in tdef2:
assert istate != state, 'circular state ref %r' % istate
itokens.extend(cls._process_state(unprocessed,
processed, istate))
processed[new_state] = itokens
new_state = (new_state,)
elif isinstance(tdef2, tuple):
# push more than one state
for state in tdef2:
assert (state in unprocessed or
state in ('#pop', '#push')), \
'unknown new state ' + state
new_state = tdef2
else:
assert False, 'unknown new state def %r' % tdef2
tokens.append((rex, tdef[1], new_state))
return tokens
def process_tokendef(cls):
cls._all_tokens = {}
cls._tmpname = 0
processed = cls._all_tokens[cls.__name__] = {}
#tokendefs = tokendefs or cls.tokens[name]
for state in cls.tokens.keys():
cls._process_state(cls.tokens, processed, state)
return processed
def __call__(cls, *args, **kwds):
if not hasattr(cls, '_tokens'):
cls._all_tokens = {}
cls._tmpname = 0
if hasattr(cls, 'token_variants') and cls.token_variants:
# don't process yet
pass
else:
cls._tokens = cls.process_tokendef()
return type.__call__(cls, *args, **kwds)
class Lexer:
__metaclass__ = LexerMeta
encoding = 'utf-8'
stripall = False
stripnl = False
tabsize = 0
flags = re.IGNORECASE
tokens = {
'root': [
(r'--.*?(\r|\n|\r\n)', Comment.Single),
(r'(\r|\n|\r\n)', Newline),
(r'\s+', Whitespace),
(r'/\*', Comment.Multiline, 'multiline-comments'),
(r':=', Assignment),
(r'::', Punctuation),
(r'[*]', Wildcard),
(r"`(``|[^`])*`", Name),
(r"´(´´|[^´])*´", Name),
(r'@[a-zA-Z_][a-zA-Z0-9_]+', Name),
(r'[+/<>=~!@#%^&|`?^-]', Operator),
(r'[0-9]+', Number.Integer),
# TODO: Backslash escapes?
(r"'(''|[^'])*'", String.Single),
(r'"(""|[^"])*"', String.Symbol), # not a real string literal in ANSI SQL
(r'(LEFT |RIGHT )?(INNER |OUTER )?JOIN', Keyword),
(r'END( IF| LOOP)?', Keyword),
(r'CREATE( OR REPLACE)?', Keyword.DDL),
(r'[a-zA-Z_][a-zA-Z0-9_]*', is_keyword),
(r'\$([a-zA-Z_][a-zA-Z0-9_]*)?\$', Name.Builtin),
(r'[;:()\[\],\.]', Punctuation),
],
'multiline-comments': [
(r'/\*', Comment.Multiline, 'multiline-comments'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[^/\*]+', Comment.Multiline),
(r'[/*]', Comment.Multiline)
]
}
def __init__(self):
self.filters = []
def add_filter(self, filter_, **options):
from sqlparse.filters import Filter
if not isinstance(filter_, Filter):
filter_ = filter_(**options)
self.filters.append(filter_)
def get_tokens(self, text, unfiltered=False):
"""
Return an iterable of (tokentype, value) pairs generated from
`text`. If `unfiltered` is set to `True`, the filtering mechanism
is bypassed even if filters are defined.
Also preprocess the text, i.e. expand tabs and strip it if
wanted and applies registered filters.
"""
if not isinstance(text, unicode):
if self.encoding == 'guess':
try:
text = text.decode('utf-8')
if text.startswith(u'\ufeff'):
text = text[len(u'\ufeff'):]
except UnicodeDecodeError:
text = text.decode('latin1')
elif self.encoding == 'chardet':
try:
import chardet
except ImportError:
raise ImportError('To enable chardet encoding guessing, '
'please install the chardet library '
'from http://chardet.feedparser.org/')
enc = chardet.detect(text)
text = text.decode(enc['encoding'])
else:
text = text.decode(self.encoding)
if self.stripall:
text = text.strip()
elif self.stripnl:
text = text.strip('\n')
if self.tabsize > 0:
text = text.expandtabs(self.tabsize)
# if not text.endswith('\n'):
# text += '\n'
def streamer():
for i, t, v in self.get_tokens_unprocessed(text):
yield t, v
stream = streamer()
if not unfiltered:
stream = apply_filters(stream, self.filters, self)
return stream
def get_tokens_unprocessed(self, text, stack=('root',)):
"""
Split ``text`` into (tokentype, text) pairs.
``stack`` is the inital stack (default: ``['root']``)
"""
pos = 0
tokendefs = self._tokens
statestack = list(stack)
statetokens = tokendefs[statestack[-1]]
known_names = {}
while 1:
for rexmatch, action, new_state in statetokens:
m = rexmatch(text, pos)
if m:
# print rex.pattern
value = m.group()
if value in known_names:
yield pos, known_names[value], value
elif type(action) is _TokenType:
yield pos, action, value
elif hasattr(action, '__call__'):
ttype, value = action(value)
known_names[value] = ttype
yield pos, ttype, value
else:
for item in action(self, m):
yield item
pos = m.end()
if new_state is not None:
# state transition
if isinstance(new_state, tuple):
for state in new_state:
if state == '#pop':
statestack.pop()
elif state == '#push':
statestack.append(statestack[-1])
else:
statestack.append(state)
elif isinstance(new_state, int):
# pop
del statestack[new_state:]
elif new_state == '#push':
statestack.append(statestack[-1])
else:
assert False, "wrong state def: %r" % new_state
statetokens = tokendefs[statestack[-1]]
break
else:
try:
if text[pos] == '\n':
# at EOL, reset state to "root"
pos += 1
statestack = ['root']
statetokens = tokendefs['root']
yield pos, Text, u'\n'
continue
yield pos, Error, text[pos]
pos += 1
except IndexError:
break
def tokenize(sql):
"""Tokenize sql.
Tokenize *sql* using the :class:`Lexer` and return a 2-tuple stream
of ``(token type, value)`` items.
"""
lexer = Lexer()
return lexer.get_tokens(sql)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
9079,
1626,
328,
4580,
10205,
335,
84,
12,
741,
10205,
335,
84,
14,
290,
328,
32,
6799,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
2366,
13,
3009,
1122,
436,
365,
14286,
1334,
199,
3,
314,
6289,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
14,
199,
199,
624,
4657,
21125,
624,
199,
199,
3,
961,
1233,
365,
4079,
641,
314,
428,
1710,
5838,
315,
13277,
14,
199,
3,
1455,
921,
12173,
14,
1308,
15,
199,
3,
2779,
1159,
11673,
687,
314,
4618,
402,
13277,
370,
19781,
10238,
199,
3,
436,
370,
2040,
2005,
3537,
12270,
14,
199,
199,
646,
295,
199,
199,
504,
3105,
63,
13951,
14,
1208,
14,
3009,
1122,
14,
7511,
492,
9301,
19984,
12,
9301,
19984,
63,
21637,
199,
504,
3105,
63,
13951,
14,
1208,
14,
3009,
1122,
14,
4504,
492,
627,
199,
504,
3105,
63,
13951,
14,
1208,
14,
3009,
1122,
14,
4504,
492,
485,
3264,
804,
421,
199,
533,
2387,
8,
495,
304,
272,
986,
199,
199,
533,
12149,
8,
2960,
304,
272,
408,
607,
16292,
282,
1174,
12149,
687,
3663,
6363,
1041,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
304,
267,
372,
2008,
855,
1222,
721,
1886,
12,
1249,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
327,
2008,
855,
826,
363,
3181,
1133,
886,
7003,
267,
986,
199,
199,
318,
365,
63,
6691,
8,
585,
304,
272,
511,
275,
574,
14,
4142,
342,
272,
372,
9301,
19984,
63,
21637,
14,
362,
8,
396,
12,
9301,
19984,
14,
362,
8,
396,
12,
2812,
1826,
574,
421,
199,
318,
4838,
63,
4273,
8,
1745,
12,
4766,
12,
10426,
29,
403,
304,
272,
408,
272,
3645,
642,
1083,
370,
4838,
376,
6076,
402,
4766,
370,
272,
282,
2547,
14,
982,
10426,
365,
1627,
652,
1159,
24172,
370,
314,
272,
2457,
12,
4257,
314,
2457,
23192,
658,
403,
2313,
272,
408,
272,
347,
485,
4998,
8,
1541,
3131,
2547,
304,
267,
367,
1526,
315,
2457,
3754,
1541,
8,
11729,
12,
2547,
304,
288,
1995,
1526,
272,
367,
2457,
63,
315,
4766,
26,
267,
2547,
275,
485,
4998,
8,
1541,
3131,
2547,
9,
272,
372,
2547,
421,
199,
533,
21125,
3396,
8,
466,
304,
272,
408,
272,
6288,
533,
367,
21125,
12,
8491,
314,
291,
423,
4504,
2225,
687,
272,
291,
14,
4504,
641,
314,
1642,
26621,
14,
272,
408,
339,
347,
485,
1412,
63,
929,
8,
1886,
12,
625,
7292,
12,
7686,
12,
1174,
304,
267,
702,
730,
8,
929,
9,
365,
620,
12,
298,
10603,
1174,
536,
450,
82,
2,
450,
1174,
267,
702,
1174,
59,
16,
61,
1137,
3943,
297,
298,
3197,
1174,
536,
450,
82,
2,
450,
1174,
267,
340,
1174,
315,
7686,
26,
288,
372,
7686,
59,
929,
61,
267,
4645,
275,
7686,
59,
929,
61,
275,
942,
267,
519,
2469,
275,
843,
14,
2469,
267,
367,
307,
318,
315,
625,
7292,
59,
929,
2189,
288,
340,
1228,
8,
84,
318,
12,
2387,
304,
355,
327,
652,
1159,
282,
1174,
3659,
355,
702,
307,
318,
1137,
1174,
12,
298,
23022,
1174,
3659,
450,
82,
2,
450,
1174,
355,
4645,
14,
2880,
8,
1886,
423,
1412,
63,
929,
8,
24088,
12,
7686,
12,
620,
8,
84,
318,
1724,
355,
1980,
953,
702,
730,
8,
84,
318,
9,
365,
2008,
12,
298,
10603,
2332,
347,
450,
82,
2,
450,
307,
318,
953,
862,
26,
355,
295,
88,
275,
295,
14,
2014,
8,
84,
318,
59,
16,
467,
519,
2469,
680,
1431,
288,
871,
2186,
12,
2329,
26,
355,
746,
1722,
480,
324,
863,
382,
461,
5163,
450,
82,
315,
1174,
450,
82,
402,
450,
82,
26,
450,
83,
2,
450,
639,
334,
84,
318,
59,
16,
467,
1174,
12,
843,
12,
2329,
430,
953,
702,
730,
8,
84,
318,
59,
17,
566,
365,
485,
3264,
804,
503,
4550,
8,
84,
318,
59,
17,
2522,
971,
673,
283,
1418,
730,
1471,
506,
3486,
730,
503,
4550,
12,
440,
450,
82,
7,
450,
334,
84,
318,
59,
17,
467,
9,
953,
340,
822,
8,
84,
318,
9,
508,
499,
26,
355,
892,
63,
929,
275,
488,
288,
587,
26,
355,
307,
318,
18,
275,
307,
318,
59,
18,
61,
355,
340,
1228,
8,
84,
318,
18,
12,
620,
304,
490,
327,
376,
3411,
1174,
490,
340,
307,
318,
18,
508,
3943,
1935,
356,
717,
892,
63,
929,
275,
446,
17,
490,
916,
307,
318,
18,
315,
625,
7292,
26,
717,
892,
63,
929,
275,
334,
84,
318,
18,
4258,
490,
916,
307,
318,
18,
508,
3943,
5335,
356,
717,
892,
63,
929,
275,
307,
318,
18,
490,
916,
307,
318,
18,
1491,
21,
61,
508,
3943,
1935,
25156,
717,
892,
63,
929,
275,
446,
442,
8,
84,
318,
18,
59,
21,
5728,
490,
587,
26,
717,
702,
756,
12,
283,
5187,
892,
1174,
450,
82,
7,
450,
307,
318,
18,
355,
916,
1228,
8,
84,
318,
18,
12,
12149,
304,
490,
327,
13323,
282,
892,
1174,
687,
3411,
7869,
490,
892,
63,
929,
275,
2513,
2791,
4970,
68,
7,
450,
843,
423,
2791,
354,
490,
843,
423,
2791,
354,
847,
413,
490,
284,
4504,
275,
942,
490,
367,
284,
929,
315,
307,
318,
18,
26,
717,
702,
284,
929,
1137,
1174,
12,
283,
23022,
1174,
2984,
450,
82,
7,
450,
284,
929,
717,
284,
4504,
14,
2880,
8,
1886,
423,
1412,
63,
929,
8,
24088,
12,
12933,
7686,
12,
284,
929,
430,
490,
7686,
59,
1222,
63,
929,
61,
275,
284,
4504,
490,
892,
63,
929,
275,
334,
1222,
63,
929,
4258,
355,
916,
1228,
8,
84,
318,
18,
12,
2008,
304,
490,
327,
6675,
1655,
2419,
1373,
1174,
490,
367,
1174,
315,
307,
318,
18,
26,
717,
702,
334,
929,
315,
625,
7292,
503,
1816,
1174,
315,
22870,
1935,
297,
3943,
5335,
3855,
971,
3044,
283,
5187,
892,
1174,
283,
435,
1174,
490,
892,
63,
929,
275,
307,
318,
18,
355,
587,
26,
490,
702,
756,
12,
283,
5187,
892,
1174,
347,
450,
82,
7,
450,
307,
318,
18,
288,
4645,
14,
740,
1332,
15063,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
9079,
1626,
328,
4580,
10205,
335,
84,
12,
741,
10205,
335,
84,
14,
290,
328,
32,
6799,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
2366,
13,
3009,
1122,
436,
365,
14286,
1334,
199,
3,
314,
6289,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
14,
199,
199,
624,
4657,
21125,
624,
199,
199,
3,
961,
1233,
365,
4079,
641,
314,
428,
1710,
5838,
315,
13277,
14,
199,
3,
1455,
921,
12173,
14,
1308,
15,
199,
3,
2779,
1159,
11673,
687,
314,
4618,
402,
13277,
370,
19781,
10238,
199,
3,
436,
370,
2040,
2005,
3537,
12270,
14,
199,
199,
646,
295,
199,
199,
504,
3105,
63,
13951,
14,
1208,
14,
3009,
1122,
14,
7511,
492,
9301,
19984,
12,
9301,
19984,
63,
21637,
199,
504,
3105,
63,
13951,
14,
1208,
14,
3009,
1122,
14,
4504,
492,
627,
199,
504,
3105,
63,
13951,
14,
1208,
14,
3009,
1122,
14,
4504,
492,
485,
3264,
804,
421,
199,
533,
2387,
8,
495,
304,
272,
986,
199,
199,
533,
12149,
8,
2960,
304,
272,
408,
607,
16292,
282,
1174,
12149,
687,
3663,
6363,
1041,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
304,
267,
372,
2008,
855,
1222,
721,
1886,
12,
1249,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
327,
2008,
855,
826,
363,
3181,
1133,
886,
7003,
267,
986,
199,
199,
318,
365,
63,
6691,
8,
585,
304,
272,
511,
275,
574,
14,
4142,
342,
272,
372,
9301,
19984,
63,
21637,
14,
362,
8,
396,
12,
9301,
19984,
14,
362,
8,
396,
12,
2812,
1826,
574,
421,
199,
318,
4838,
63,
4273,
8,
1745,
12,
4766,
12,
10426,
29,
403,
304,
272,
408,
272,
3645,
642,
1083,
370,
4838,
376,
6076,
402,
4766,
370,
272,
282,
2547,
14,
982,
10426,
365,
1627,
652,
1159,
24172,
370,
314,
272,
2457,
12,
4257,
314,
2457,
23192,
658,
403,
2313,
272,
408,
272,
347,
485,
4998,
8,
1541,
3131,
2547,
304,
267,
367,
1526,
315,
2457,
3754,
1541,
8,
11729,
12,
2547,
304,
288,
1995,
1526,
272,
367,
2457,
63,
315,
4766,
26,
267,
2547,
275,
485,
4998,
8,
1541,
3131,
2547,
9,
272,
372,
2547,
421,
199,
533,
21125,
3396,
8,
466,
304,
272,
408,
272,
6288,
533,
367,
21125,
12,
8491,
314,
291,
423,
4504,
2225,
687,
272,
291,
14,
4504,
641,
314,
1642,
26621,
14,
272,
408,
339,
347,
485,
1412,
63,
929,
8,
1886,
12,
625,
7292,
12,
7686,
12,
1174,
304,
267,
702,
730,
8,
929,
9,
365,
620,
12,
298,
10603,
1174,
536,
450,
82,
2,
450,
1174,
267,
702,
1174,
59,
16,
61,
1137,
3943,
297,
298,
3197,
1174,
536,
450,
82,
2,
450,
1174,
267,
340,
1174,
315,
7686,
26,
288,
372,
7686,
59,
929,
61,
267,
4645,
275,
7686,
59,
929,
61,
275,
942,
267,
519,
2469,
275,
843,
14,
2469,
267,
367,
307,
318,
315,
625,
7292,
59,
929,
2189,
288,
340,
1228,
8,
84,
318,
12,
2387,
304,
355,
327,
652,
1159,
282,
1174,
3659,
355,
702,
307,
318,
1137,
1174,
12,
298,
23022,
1174,
3659,
450,
82,
2,
450,
1174,
355,
4645,
14,
2880,
8,
1886,
423,
1412,
63,
929,
8,
24088,
12,
7686,
12,
620,
8,
84,
318,
1724,
355,
1980,
953,
702,
730,
8,
84,
318,
9,
365,
2008,
12,
298,
10603,
2332,
347,
450,
82,
2,
450,
307,
318,
953,
862,
26,
355,
295,
88,
275,
295,
14,
2014,
8,
84,
318,
59,
16,
467,
519,
2469,
680,
1431,
288,
871,
2186,
12,
2329,
26,
355,
746,
1722,
480,
324,
863,
382,
461,
5163,
450,
82,
315,
1174,
450,
82,
402,
450,
82,
26,
450,
83,
2,
450,
639,
334,
84,
318,
59,
16,
467,
1174,
12,
843,
12,
2329,
430,
953,
702,
730,
8,
84,
318,
59,
17,
566,
365,
485,
3264,
804,
503,
4550,
8,
84,
318,
59,
17,
2522,
971,
673,
283,
1418,
730,
1471,
506,
3486,
730,
503,
4550,
12,
440,
450,
82,
7,
450,
334,
84,
318,
59,
17,
467,
9,
953,
340,
822,
8,
84,
318,
9,
508,
499,
26,
355,
892,
63,
929,
275,
488,
288,
587,
26,
355,
307,
318,
18,
275,
307,
318,
59,
18,
61,
355,
340,
1228,
8,
84,
318,
18,
12,
620,
304,
490,
327,
376,
3411,
1174,
490,
340,
307,
318,
18,
508,
3943,
1935,
356,
717,
892,
63,
929,
275,
446,
17,
490,
916,
307,
318,
18,
315,
625,
7292,
26,
717,
892,
63,
929,
275,
334,
84,
318,
18,
4258,
490,
916,
307,
318,
18,
508,
3943,
5335,
356,
717,
892,
63,
929,
275,
307,
318,
18,
490,
916,
307,
318,
18,
1491,
21,
61,
508,
3943,
1935,
25156,
717,
892,
63,
929,
275,
446,
442,
8,
84,
318,
18,
59,
21,
5728,
490,
587,
26,
717,
702,
756,
12,
283,
5187,
892,
1174,
450,
82,
7,
450,
307,
318,
18,
355,
916,
1228,
8,
84,
318,
18,
12,
12149,
304,
490,
327,
13323,
282,
892,
1174,
687,
3411,
7869,
490,
892,
63,
929,
275,
2513,
2791,
4970,
68,
7,
450,
843,
423,
2791,
354,
490,
843,
423,
2791,
354,
847,
413,
490,
284,
4504,
275,
942,
490,
367,
284,
929,
315,
307,
318,
18,
26,
717,
702,
284,
929,
1137,
1174,
12,
283,
23022,
1174,
2984,
450,
82,
7,
450,
284,
929,
717,
284,
4504,
14,
2880,
8,
1886,
423,
1412,
63,
929,
8,
24088,
12,
12933,
7686,
12,
284,
929,
430,
490,
7686,
59,
1222,
63,
929,
61,
275,
284,
4504,
490,
892,
63,
929,
275,
334,
1222,
63,
929,
4258,
355,
916,
1228,
8,
84,
318,
18,
12,
2008,
304,
490,
327,
6675,
1655,
2419,
1373,
1174,
490,
367,
1174,
315,
307,
318,
18,
26,
717,
702,
334,
929,
315,
625,
7292,
503,
1816,
1174,
315,
22870,
1935,
297,
3943,
5335,
3855,
971,
3044,
283,
5187,
892,
1174,
283,
435,
1174,
490,
892,
63,
929,
275,
307,
318,
18,
355,
587,
26,
490,
702,
756,
12,
283,
5187,
892,
1174,
347,
450,
82,
7,
450,
307,
318,
18,
288,
4645,
14,
740,
1332,
15063,
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,
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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
] |
camptocamp/ngo-addons-backport
|
addons/knowledge/res_config.py
|
54
|
2119
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
#
# 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
class knowledge_config_settings(osv.osv_memory):
_name = 'knowledge.config.settings'
_inherit = 'res.config.settings'
_columns = {
'module_document_page': fields.boolean('Create static web pages',
help="""This installs the module document_page."""),
'module_document': fields.boolean('Manage documents',
help="""This is a complete document management system, with: user authentication,
full document search (but pptx and docx are not supported), and a document dashboard.
This installs the module document."""),
'module_document_ftp': fields.boolean('Share repositories (FTP)',
help="""Access your documents in OpenERP through an FTP interface.
This installs the module document_ftp."""),
'module_document_webdav': fields.boolean('Share repositories (WebDAV)',
help="""Access your documents in OpenERP through WebDAV.
This installs the module document_webdav."""),
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
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,
199,
533,
29105,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
14996,
14693,
14,
888,
14,
1751,
7,
272,
485,
6486,
275,
283,
470,
14,
888,
14,
1751,
7,
272,
485,
3406,
275,
469,
267,
283,
578,
63,
3554,
63,
1606,
356,
1504,
14,
4871,
360,
2499,
2955,
3330,
6497,
297,
288,
1720,
11916,
2765,
25801,
314,
859,
2213,
63,
1606,
1041,
395,
267,
283,
578,
63,
3554,
356,
1504,
14,
4871,
360,
20588,
8247,
297,
288,
1720,
11916,
2765,
365,
282,
4890,
2213,
10041,
2656,
12,
543,
26,
922,
6299,
12,
355,
2615,
2213,
2754,
334,
7911,
299,
541,
88,
436,
1382,
88,
787,
440,
3748,
395,
436,
282,
2213,
17216,
14,
355,
961,
25801,
314,
859,
2213,
1041,
395,
267,
283,
578,
63,
3554,
63,
8915,
356,
1504,
14,
4871,
360,
18713,
23737,
334,
15123,
3196,
288,
1720,
11916,
3946,
2195,
8247,
315,
7653,
4012,
376,
23125,
3217,
14,
355,
961,
25801,
314,
859,
2213,
63,
8915,
1041,
395,
267,
283,
578,
63,
3554,
63,
2520,
31496,
356,
1504,
14,
4871,
360,
18713,
23737,
334,
5926,
36,
6087,
3196,
288,
1720,
11916,
3946,
2195,
8247,
315,
7653,
4012,
6001,
36,
6087,
14,
355,
961,
25801,
314,
859,
2213,
63,
2520,
31496,
1041,
395,
272,
789,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
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,
199,
533,
29105,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
14996,
14693,
14,
888,
14,
1751,
7,
272,
485,
6486,
275,
283,
470,
14,
888,
14,
1751,
7,
272,
485,
3406,
275,
469,
267,
283,
578,
63,
3554,
63,
1606,
356,
1504,
14,
4871,
360,
2499,
2955,
3330,
6497,
297,
288,
1720,
11916,
2765,
25801,
314,
859,
2213,
63,
1606,
1041,
395,
267,
283,
578,
63,
3554,
356,
1504,
14,
4871,
360,
20588,
8247,
297,
288,
1720,
11916,
2765,
365,
282,
4890,
2213,
10041,
2656,
12,
543,
26,
922,
6299,
12,
355,
2615,
2213,
2754,
334,
7911,
299,
541,
88,
436,
1382,
88,
787,
440,
3748,
395,
436,
282,
2213,
17216,
14,
355,
961,
25801,
314,
859,
2213,
1041,
395,
267,
283,
578,
63,
3554,
63,
8915,
356,
1504,
14,
4871,
360,
18713,
23737,
334,
15123,
3196,
288,
1720,
11916,
3946,
2195,
8247,
315,
7653,
4012,
376,
23125,
3217,
14,
355,
961,
25801,
314,
859,
2213,
63,
8915,
1041,
395,
267,
283,
578,
63,
3554,
63,
2520,
31496,
356,
1504,
14,
4871,
360,
18713,
23737,
334,
5926,
36,
6087,
3196,
288,
1720,
11916,
3946,
2195,
8247,
315,
7653,
4012,
6001,
36,
6087,
14,
355,
961,
25801,
314,
859,
2213,
63,
2520,
31496,
1041,
395,
272,
789,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
WoLpH/EventGhost
|
plugins/Streamzap/__init__.py
|
1
|
6300
|
# -*- coding: utf-8 -*-
#
# This file is a plugin for EventGhost.
# Copyright © 2005-2016 EventGhost Project <http://www.eventghost.net/>
#
# EventGhost 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.
#
# EventGhost 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 EventGhost. If not, see <http://www.gnu.org/licenses/>.
"""<rst>
Hardware plugin for the `Streamzap PC Remote`_.
|
.. image:: crr.jpg
:align: center
.. _Streamzap PC Remote: http://www.streamzap.com/products/pcremote/
"""
import eg
eg.RegisterPlugin(
name = "Streamzap PC Remote",
author = "Bitmonster",
version = "1.1",
kind = "remote",
hardwareId = "USB\\VID_0E9C&PID_0000",
guid = "{C188351F-44E3-459D-92FC-66F51104B1DB}",
description = __doc__,
icon = (
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAOElEQVR42mNkoBAwDl4D"
"/gMRIxEWMFKimWgD8BnISIlmkg3AZhh9DaBPIBJjK0EDSDFkEOcFYgEAwk8kEWJRdKUA"
"AAAASUVORK5CYII="
),
)
import threading
from os.path import abspath, split, join
from time import sleep
from ctypes import cdll, c_ubyte, byref
from ctypes.wintypes import DWORD
DLL_PATH = join(abspath(split(__file__)[0]), "irdata.dll")
CODES = {
0x0009C272: "Ok",
0x00204272: "Ok",
0x002709C2: "Left",
0x008109C2: "Left",
0x002709C8: "Right",
0x008109C8: "Right",
0x008109C0: "Up",
0x002709C0: "Up",
0x0020427C: "Down",
0x0009C27C: "Down",
0x02042402: "Num1",
0x009C2402: "Num1",
0x00270902: "Num2",
0x00810902: "Num2",
0x02042408: "Num3",
0x009C2408: "Num3",
0x0081090C: "Num4",
0x0027090C: "Num4",
0x0081090E: "Num5",
0x0027090E: "Num5",
0x00810908: "Num6",
0x00270908: "Num6",
0x02042420: "Num7",
0x009C2420: "Num7",
0x00810930: "Num8",
0x00270930: "Num8",
0x00810932: "Num9",
0x00270932: "Num9",
0x02042400: "Num0",
0x009C2400: "Num0",
0x0020424E: "Power",
0x0009C24E: "Power",
0x00810938: "Mute",
0x00270938: "Mute",
0x00810924: "ChannelUp",
0x00270924: "ChannelUp",
0x00810920: "ChannelDown",
0x00270920: "ChannelDown",
0x00810926: "VolumeUp",
0x00270926: "VolumeUp",
0x02042480: "VolumeDown",
0x009C2480: "VolumeDown",
0x0020427E: "Menu",
0x0009C27E: "Menu",
0x00204278: "Exit",
0x0009C278: "Exit",
0x008109E0: "Play",
0x002709E0: "Play",
0x00810990: "Pause",
0x00270990: "Pause",
0x00810992: "Stop",
0x00270992: "Stop",
0x00810992: "Stop",
0x00270992: "Stop",
0x0009C266: "PreviousTrack",
0x00204266: "PreviousTrack",
0x00270998: "NextTrack",
0x00810998: "NextTrack",
0x00270984: "Record",
0x00810984: "Record",
0x00270986: "Rewind",
0x00810986: "Rewind",
0x00270980: "Forward",
0x00810980: "Forward",
0x009C2100: "Red",
0x02042100: "Red",
0x009C2102: "Green",
0x02042102: "Green",
0x00810842: "Yellow",
0x00270842: "Yellow",
0x02042108: "Blue",
0x009C2108: "Blue",
}
# Even though the Streamzap should be able to deliver raw timecode diagrams,
# it doesn't work right. Sometimes the last pulse is missing. So we use a
# simple decoder especially for this remote, that only reacts to known
# Streamzap codes.
def Decode(data):
buf = 2
for value in data:
if value < 5:
pass
elif value < 10:
buf |= 1
else:
return None
buf <<= 1
return buf
class Streamzap(eg.PluginBase):
def __init__(self):
eg.PluginBase.__init__(self)
self.AddEvents()
def __start__(self):
self.timer = eg.ResettableTimer(self.OnTimeout)
self.lastCode = None
self.abortThread = False
self.lastException = None
startupEvent = threading.Event()
self.thread = threading.Thread(
target=self.ReceiveThread,
name="StreamzapReceiveThread",
args=(startupEvent,)
)
self.thread.start()
startupEvent.wait(5.0)
if self.lastException:
self.timer.Stop()
raise self.lastException
def __stop__(self):
self.abortThread = True
self.timer.Stop()
self.thread.join(5.0)
def ReceiveThread(self, startupEvent):
# This is the code executing in the new thread.
try:
dll = cdll.LoadLibrary(DLL_PATH)
except WindowsError:
self.lastException = self.Exceptions.DriverNotFound
startupEvent.set()
return
if dll.sz_Open() != 1:
self.lastException = self.Exceptions.DriverNotOpen
startupEvent.set()
return
dll.sz_Flush()
dwNumBytesRead = DWORD()
byteIRdata = c_ubyte()
irData = []
i = 0
szReadFile = dll.sz_ReadFile
startupEvent.set()
while not self.abortThread:
szReadFile(byref(byteIRdata), byref(dwNumBytesRead))
val = byteIRdata.value
if dwNumBytesRead.value == 0:
sleep(0.001)
else:
i += 1
if val > 78 or i == 511:
code = Decode(irData)
eventname = CODES.get(code, None)
if eventname is None:
self.EndLastEvent()
self.lastCode = None
else:
if code != self.lastCode:
self.TriggerEnduringEvent(eventname)
self.lastCode = code
self.timer.Reset(140)
irData = []
i = 0
continue
irData.append(val)
dll.sz_Close()
def OnTimeout(self):
self.EndLastEvent()
self.lastCode = None
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
282,
3589,
367,
6763,
39,
1102,
14,
199,
3,
1898,
22405,
103,
11811,
13,
9261,
6763,
39,
1102,
7290,
665,
1014,
921,
1544,
14,
1430,
71,
1102,
14,
846,
3133,
199,
3,
199,
3,
6763,
39,
1102,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
6763,
39,
1102,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
199,
3,
543,
6763,
39,
1102,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
28,
8332,
30,
199,
199,
23219,
3589,
367,
314,
658,
3296,
24568,
510,
35,
17283,
32578,
199,
199,
92,
199,
199,
703,
1834,
447,
2467,
82,
14,
8476,
2043,
520,
5743,
26,
8126,
199,
199,
703,
485,
3296,
24568,
510,
35,
17283,
26,
1455,
921,
1544,
14,
1745,
24568,
14,
957,
15,
13336,
15,
80,
1353,
2137,
15,
199,
624,
199,
199,
646,
11837,
199,
199,
5902,
14,
7099,
5061,
8,
272,
536,
275,
298,
3296,
24568,
510,
35,
17283,
401,
272,
4132,
275,
298,
4734,
2106,
11652,
401,
272,
1015,
275,
298,
17,
14,
17,
401,
272,
4928,
275,
298,
3846,
401,
272,
14991,
1304,
275,
298,
19919,
1103,
5437,
63,
16,
37,
25,
35,
6,
16098,
63,
993,
401,
272,
15593,
275,
5310,
35,
11501,
16860,
38,
13,
1602,
37,
19,
13,
28976,
36,
13,
2942,
4161,
13,
1272,
38,
2869,
6785,
34,
17,
2846,
10750,
272,
1369,
275,
636,
1301,
3108,
272,
7016,
275,
334,
267,
298,
73,
27966,
726,
87,
16,
14634,
1939,
10985,
5622,
53,
72,
23539,
71,
31723,
6151,
20152,
3263,
57,
6151,
70,
24,
15,
25,
72,
6151,
47,
10420,
17420,
20271,
2260,
77,
46,
7697,
4134,
87,
22904,
20,
36,
2,
267,
3286,
71,
45,
6129,
6991,
13073,
21490,
1017,
55,
71,
36,
24,
34,
78,
1311,
27965,
3880,
71,
19,
17613,
12156,
25,
25014,
24408,
2100,
42,
74,
43,
16,
1149,
3693,
38,
75,
15471,
67,
18114,
71,
11765,
14947,
24,
75,
37,
55,
42,
50,
68,
43,
21659,
2,
267,
298,
10985,
1179,
15110,
726,
43,
21,
15068,
8921,
628,
272,
2318,
199,
9,
421,
199,
646,
5796,
199,
504,
747,
14,
515,
492,
19529,
12,
3715,
12,
4263,
199,
504,
900,
492,
9435,
199,
504,
5577,
492,
286,
9259,
12,
286,
63,
20790,
12,
15968,
199,
504,
5577,
14,
27171,
492,
13936,
421,
199,
15982,
63,
3243,
275,
4263,
8,
4832,
8,
1294,
3460,
493,
363,
2788,
16,
2522,
298,
723,
576,
14,
9259,
531,
199,
199,
15639,
275,
469,
272,
378,
88,
21144,
35,
12900,
26,
298,
11622,
401,
272,
378,
88,
383,
6686,
12900,
26,
298,
11622,
401,
272,
378,
88,
28355,
1643,
35,
18,
26,
298,
8185,
401,
272,
378,
88,
8662,
6996,
35,
18,
26,
298,
8185,
401,
272,
378,
88,
28355,
1643,
35,
24,
26,
298,
9121,
401,
272,
378,
88,
8662,
6996,
35,
24,
26,
298,
9121,
401,
272,
378,
88,
8662,
6996,
35,
16,
26,
298,
1721,
401,
272,
378,
88,
28355,
1643,
35,
16,
26,
298,
1721,
401,
272,
378,
88,
383,
6686,
1465,
35,
26,
298,
3514,
401,
272,
378,
88,
21144,
35,
1465,
35,
26,
298,
3514,
401,
272,
378,
88,
996,
966,
1194,
996,
26,
298,
5667,
17,
401,
272,
378,
88,
8581,
35,
1194,
996,
26,
298,
5667,
17,
401,
272,
378,
88,
28355,
1643,
996,
26,
298,
5667,
18,
401,
272,
378,
88,
8662,
6996,
996,
26,
298,
5667,
18,
401,
272,
378,
88,
996,
966,
1194,
2036,
26,
298,
5667,
19,
401,
272,
378,
88,
8581,
35,
1194,
2036,
26,
298,
5667,
19,
401,
272,
378,
88,
8662,
709,
2710,
35,
26,
298,
5667,
20,
401,
272,
378,
88,
28355,
18526,
35,
26,
298,
5667,
20,
401,
272,
378,
88,
8662,
709,
2710,
37,
26,
298,
5667,
21,
401,
272,
378,
88,
28355,
18526,
37,
26,
298,
5667,
21,
401,
272,
378,
88,
8662,
6996,
2036,
26,
298,
5667,
22,
401,
272,
378,
88,
28355,
1643,
2036,
26,
298,
5667,
22,
401,
272,
378,
88,
996,
966,
1194,
1165,
26,
298,
5667,
23,
401,
272,
378,
88,
8581,
35,
1194,
1165,
26,
298,
5667,
23,
401,
272,
378,
88,
8662,
6996,
1216,
26,
298,
5667,
24,
401,
272,
378,
88,
28355,
1643,
1216,
26,
298,
5667,
24,
401,
272,
378,
88,
8662,
6996,
708,
26,
298,
5667,
25,
401,
272,
378,
88,
28355,
1643,
708,
26,
298,
5667,
25,
401,
272,
378,
88,
996,
966,
1194,
383,
26,
298,
5667,
16,
401,
272,
378,
88,
8581,
35,
1194,
383,
26,
298,
5667,
16,
401,
272,
378,
88,
383,
6686,
1194,
37,
26,
298,
6921,
401,
272,
378,
88,
21144,
35,
1194,
37,
26,
298,
6921,
401,
272,
378,
88,
8662,
6996,
1703,
26,
298,
45,
938,
401,
272,
378,
88,
28355,
1643,
1703,
26,
298,
45,
938,
401,
272,
378,
88,
8662,
6996,
1194,
26,
298,
5358,
1721,
401,
272,
378,
88,
28355,
1643,
1194,
26,
298,
5358,
1721,
401,
272,
378,
88,
8662,
6996,
1165,
26,
298,
5358,
3514,
401,
272,
378,
88,
28355,
1643,
1165,
26,
298,
5358,
3514,
401,
272,
378,
88,
8662,
6996,
1479,
26,
298,
6464,
1721,
401,
272,
378,
88,
28355,
1643,
1479,
26,
298,
6464,
1721,
401,
272,
378,
88,
996,
966,
1194,
1257,
26,
298,
6464,
3514,
401,
272,
378,
88,
8581,
35,
1194,
1257,
26,
298,
6464,
3514,
401,
272,
378,
88,
383,
6686,
1465,
37,
26,
298,
5977,
401,
272,
378,
88,
21144,
35,
1465,
37,
26,
298,
5977
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
282,
3589,
367,
6763,
39,
1102,
14,
199,
3,
1898,
22405,
103,
11811,
13,
9261,
6763,
39,
1102,
7290,
665,
1014,
921,
1544,
14,
1430,
71,
1102,
14,
846,
3133,
199,
3,
199,
3,
6763,
39,
1102,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
6763,
39,
1102,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
199,
3,
543,
6763,
39,
1102,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
28,
8332,
30,
199,
199,
23219,
3589,
367,
314,
658,
3296,
24568,
510,
35,
17283,
32578,
199,
199,
92,
199,
199,
703,
1834,
447,
2467,
82,
14,
8476,
2043,
520,
5743,
26,
8126,
199,
199,
703,
485,
3296,
24568,
510,
35,
17283,
26,
1455,
921,
1544,
14,
1745,
24568,
14,
957,
15,
13336,
15,
80,
1353,
2137,
15,
199,
624,
199,
199,
646,
11837,
199,
199,
5902,
14,
7099,
5061,
8,
272,
536,
275,
298,
3296,
24568,
510,
35,
17283,
401,
272,
4132,
275,
298,
4734,
2106,
11652,
401,
272,
1015,
275,
298,
17,
14,
17,
401,
272,
4928,
275,
298,
3846,
401,
272,
14991,
1304,
275,
298,
19919,
1103,
5437,
63,
16,
37,
25,
35,
6,
16098,
63,
993,
401,
272,
15593,
275,
5310,
35,
11501,
16860,
38,
13,
1602,
37,
19,
13,
28976,
36,
13,
2942,
4161,
13,
1272,
38,
2869,
6785,
34,
17,
2846,
10750,
272,
1369,
275,
636,
1301,
3108,
272,
7016,
275,
334,
267,
298,
73,
27966,
726,
87,
16,
14634,
1939,
10985,
5622,
53,
72,
23539,
71,
31723,
6151,
20152,
3263,
57,
6151,
70,
24,
15,
25,
72,
6151,
47,
10420,
17420,
20271,
2260,
77,
46,
7697,
4134,
87,
22904,
20,
36,
2,
267,
3286,
71,
45,
6129,
6991,
13073,
21490,
1017,
55,
71,
36,
24,
34,
78,
1311,
27965,
3880,
71,
19,
17613,
12156,
25,
25014,
24408,
2100,
42,
74,
43,
16,
1149,
3693,
38,
75,
15471,
67,
18114,
71,
11765,
14947,
24,
75,
37,
55,
42,
50,
68,
43,
21659,
2,
267,
298,
10985,
1179,
15110,
726,
43,
21,
15068,
8921,
628,
272,
2318,
199,
9,
421,
199,
646,
5796,
199,
504,
747,
14,
515,
492,
19529,
12,
3715,
12,
4263,
199,
504,
900,
492,
9435,
199,
504,
5577,
492,
286,
9259,
12,
286,
63,
20790,
12,
15968,
199,
504,
5577,
14,
27171,
492,
13936,
421,
199,
15982,
63,
3243,
275,
4263,
8,
4832,
8,
1294,
3460,
493,
363,
2788,
16,
2522,
298,
723,
576,
14,
9259,
531,
199,
199,
15639,
275,
469,
272,
378,
88,
21144,
35,
12900,
26,
298,
11622,
401,
272,
378,
88,
383,
6686,
12900,
26,
298,
11622,
401,
272,
378,
88,
28355,
1643,
35,
18,
26,
298,
8185,
401,
272,
378,
88,
8662,
6996,
35,
18,
26,
298,
8185,
401,
272,
378,
88,
28355,
1643,
35,
24,
26,
298,
9121,
401,
272,
378,
88,
8662,
6996,
35,
24,
26,
298,
9121,
401,
272,
378,
88,
8662,
6996,
35,
16,
26,
298,
1721,
401,
272,
378,
88,
28355,
1643,
35,
16,
26,
298,
1721,
401,
272,
378,
88,
383,
6686,
1465,
35,
26,
298,
3514,
401,
272,
378,
88,
21144,
35,
1465,
35,
26,
298,
3514,
401,
272,
378,
88,
996,
966,
1194,
996,
26,
298,
5667,
17,
401,
272,
378,
88,
8581,
35,
1194,
996,
26,
298,
5667,
17,
401,
272,
378,
88,
28355,
1643,
996,
26,
298,
5667,
18,
401,
272,
378,
88,
8662,
6996,
996,
26,
298,
5667,
18,
401,
272,
378,
88,
996,
966,
1194,
2036,
26,
298,
5667,
19,
401,
272,
378,
88,
8581,
35,
1194,
2036,
26,
298,
5667,
19,
401,
272,
378,
88,
8662,
709,
2710,
35,
26,
298,
5667,
20,
401,
272,
378,
88,
28355,
18526,
35,
26,
298,
5667,
20,
401,
272,
378,
88,
8662,
709,
2710,
37,
26,
298,
5667,
21,
401,
272,
378,
88,
28355,
18526,
37,
26,
298,
5667,
21,
401,
272,
378,
88,
8662,
6996,
2036,
26,
298,
5667,
22,
401,
272,
378,
88,
28355,
1643,
2036,
26,
298,
5667,
22,
401,
272,
378,
88,
996,
966,
1194,
1165,
26,
298,
5667,
23,
401,
272,
378,
88,
8581,
35,
1194,
1165,
26,
298,
5667,
23,
401,
272,
378,
88,
8662,
6996,
1216,
26,
298,
5667,
24,
401,
272,
378,
88,
28355,
1643,
1216,
26,
298,
5667,
24,
401,
272,
378,
88,
8662,
6996,
708,
26,
298,
5667,
25,
401,
272,
378,
88,
28355,
1643,
708,
26,
298,
5667,
25,
401,
272,
378,
88,
996,
966,
1194,
383,
26,
298,
5667,
16,
401,
272,
378,
88,
8581,
35,
1194,
383,
26,
298,
5667,
16,
401,
272,
378,
88,
383,
6686,
1194,
37,
26,
298,
6921,
401,
272,
378,
88,
21144,
35,
1194,
37,
26,
298,
6921,
401,
272,
378,
88,
8662,
6996,
1703,
26,
298,
45,
938,
401,
272,
378,
88,
28355,
1643,
1703,
26,
298,
45,
938,
401,
272,
378,
88,
8662,
6996,
1194,
26,
298,
5358,
1721,
401,
272,
378,
88,
28355,
1643,
1194,
26,
298,
5358,
1721,
401,
272,
378,
88,
8662,
6996,
1165,
26,
298,
5358,
3514,
401,
272,
378,
88,
28355,
1643,
1165,
26,
298,
5358,
3514,
401,
272,
378,
88,
8662,
6996,
1479,
26,
298,
6464,
1721,
401,
272,
378,
88,
28355,
1643,
1479,
26,
298,
6464,
1721,
401,
272,
378,
88,
996,
966,
1194,
1257,
26,
298,
6464,
3514,
401,
272,
378,
88,
8581,
35,
1194,
1257,
26,
298,
6464,
3514,
401,
272,
378,
88,
383,
6686,
1465,
37,
26,
298,
5977,
401,
272,
378,
88,
21144,
35,
1465,
37,
26,
298,
5977,
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,
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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
] |
rdio/translate-toolkit
|
storage/xml_extract/test_unit_tree.py
|
3
|
3194
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2002-2006 Zuza Software Foundation
#
# This file is part of translate.
#
# translate 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.
#
# translate 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 translate; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
from translate.storage.xml_extract import unit_tree
from translate.storage import factory
# _split_xpath_component
def test__split_xpath_component():
assert (u'some-tag', 0) == unit_tree._split_xpath_component(u'some-tag[0]')
# _split_xpath
def test__split_xpath():
assert [(u'p', 4), (u'text', 3), (u'body', 2), (u'document-content', 1)] == \
unit_tree._split_xpath(u'document-content[1]/body[2]/text[3]/p[4]')
# _add_unit_to_tree
def make_tree_1(unit):
root = unit_tree.XPathTree()
node = root
node.children[u'document-content', 1] = unit_tree.XPathTree()
node = node.children[u'document-content', 1]
node.children[u'body', 1] = unit_tree.XPathTree()
node = node.children[u'body', 1]
node.children[u'text', 1] = unit_tree.XPathTree()
node = node.children[u'text', 1]
node.children[u'p', 1] = unit_tree.XPathTree()
node = node.children[u'p', 1]
node.unit = unit
return root
def make_tree_2(unit_1, unit_2):
root = make_tree_1(unit_1)
node = root.children[u'document-content', 1]
node.children[u'body', 2] = unit_tree.XPathTree()
node = node.children[u'body', 2]
node.children[u'text', 3] = unit_tree.XPathTree()
node = node.children[u'text', 3]
node.children[u'p', 4] = unit_tree.XPathTree()
node = node.children[u'p', 4]
node.unit = unit_2
return root
def test__add_unit_to_tree():
from translate.storage import xliff
xliff_file = xliff.xlifffile
# xliff_file = factory.classes[u'xlf']()
# Add the first unit
unit_1 = xliff_file.UnitClass(u'Hello')
xpath_1 = u'document-content[1]/body[1]/text[1]/p[1]'
constructed_tree_1 = unit_tree.XPathTree()
unit_tree._add_unit_to_tree(constructed_tree_1,
unit_tree._split_xpath(xpath_1),
unit_1)
test_tree_1 = make_tree_1(unit_1)
assert test_tree_1 == constructed_tree_1
# Add another unit
unit_2 = xliff_file.UnitClass(u'World')
xpath_2 = u'document-content[1]/body[2]/text[3]/p[4]'
constructed_tree_2 = make_tree_1(unit_1)
unit_tree._add_unit_to_tree(constructed_tree_2,
unit_tree._split_xpath(xpath_2),
unit_2)
test_tree_2 = make_tree_2(unit_1, unit_2)
assert test_tree_2 == constructed_tree_2
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
14790,
13,
7968,
3107,
85,
8076,
2290,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
9028,
14,
199,
3,
199,
3,
9028,
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,
9028,
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,
9028,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
199,
504,
9028,
14,
3494,
14,
1652,
63,
5005,
492,
4137,
63,
2350,
199,
504,
9028,
14,
3494,
492,
6434,
199,
199,
3,
485,
1294,
63,
8006,
63,
3173,
421,
199,
318,
511,
363,
1294,
63,
8006,
63,
3173,
837,
272,
702,
334,
85,
1159,
1377,
13,
1450,
297,
378,
9,
508,
4137,
63,
2350,
423,
1294,
63,
8006,
63,
3173,
8,
85,
1159,
1377,
13,
1450,
59,
16,
10374,
199,
199,
3,
485,
1294,
63,
8006,
421,
199,
318,
511,
363,
1294,
63,
8006,
837,
272,
702,
3842,
85,
7,
80,
297,
841,
395,
334,
85,
1133,
832,
297,
650,
395,
334,
85,
7,
2030,
297,
499,
395,
334,
85,
5121,
679,
760,
13,
1317,
297,
413,
1874,
508,
971,
267,
4137,
63,
2350,
423,
1294,
63,
8006,
8,
85,
5121,
679,
760,
13,
1317,
59,
17,
12978,
2030,
59,
18,
12978,
505,
59,
19,
12978,
80,
59,
20,
10374,
199,
199,
3,
485,
525,
63,
3248,
63,
475,
63,
2350,
421,
199,
318,
1852,
63,
2350,
63,
17,
8,
3248,
304,
272,
1738,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1738,
339,
1031,
14,
3223,
59,
85,
5121,
679,
760,
13,
1317,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
5121,
679,
760,
13,
1317,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
7,
2030,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
2030,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
1133,
832,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
1133,
832,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
7,
80,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
80,
297,
413,
61,
339,
1031,
14,
3248,
275,
4137,
339,
372,
1738,
421,
199,
318,
1852,
63,
2350,
63,
18,
8,
3248,
63,
17,
12,
4137,
63,
18,
304,
272,
1738,
275,
1852,
63,
2350,
63,
17,
8,
3248,
63,
17,
9,
272,
1031,
275,
1738,
14,
3223,
59,
85,
5121,
679,
760,
13,
1317,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
7,
2030,
297,
499,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
2030,
297,
499,
61,
339,
1031,
14,
3223,
59,
85,
1133,
832,
297,
650,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
1133,
832,
297,
650,
61,
339,
1031,
14,
3223,
59,
85,
7,
80,
297,
841,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
80,
297,
841,
61,
339,
1031,
14,
3248,
275,
4137,
63,
18,
339,
372,
1738,
421,
199,
318,
511,
363,
525,
63,
3248,
63,
475,
63,
2350,
837,
272,
687,
9028,
14,
3494,
492,
671,
317,
556,
272,
671,
317,
556,
63,
493,
275,
671,
317,
556,
14,
88,
317,
556,
493,
199,
3,
259,
671,
317,
556,
63,
493,
275,
6434,
14,
2888,
59,
85,
7,
88,
276,
418,
342,
339,
327,
2654,
314,
1642,
4137,
339,
4137,
63,
17,
275,
671,
317,
556,
63,
493,
14,
5072,
2543,
8,
85,
7,
6257,
358,
272,
14462,
63,
17,
275,
399,
5121,
679,
760,
13,
1317,
59,
17,
12978,
2030,
59,
17,
12978,
505,
59,
17,
12978,
80,
59,
17,
6616,
339,
14701,
63,
2350,
63,
17,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
4137,
63,
2350,
423,
525,
63,
3248,
63,
475,
63,
2350,
8,
388,
11614,
63,
2350,
63,
17,
12,
1816,
4137,
63,
2350,
423,
1294,
63,
8006,
8,
8006,
63,
17,
395,
1816,
4137,
63,
17,
9,
272,
511,
63,
2350,
63,
17,
275,
1852,
63,
2350,
63,
17,
8,
3248,
63,
17,
9,
272,
702,
511,
63,
2350,
63,
17,
508,
14701,
63,
2350,
63,
17,
339,
327,
2654,
4573,
4137,
339,
4137,
63,
18,
275,
671,
317,
556,
63,
493,
14,
5072,
2543,
8,
85,
7,
15943,
358,
272,
14462,
63,
18,
275,
399,
5121,
679,
760,
13,
1317,
59,
17,
12978,
2030,
59,
18,
12978,
505,
59,
19,
12978,
80,
59,
20,
6616,
339,
14701,
63,
2350,
63,
18,
275,
1852,
63,
2350,
63,
17,
8,
3248,
63,
17,
9,
272,
4137,
63,
2350,
423,
525,
63,
3248,
63,
475,
63,
2350,
8,
388,
11614,
63,
2350,
63,
18,
12,
1816,
4137,
63,
2350,
423,
1294,
63,
8006,
8,
8006,
63,
18,
395,
1816,
4137,
63,
18,
9,
272,
511,
63,
2350,
63,
18,
275,
1852,
63,
2350,
63,
18,
8,
3248,
63,
17,
12,
4137,
63,
18,
9,
272,
702,
511,
63,
2350,
63,
18,
508,
14701,
63,
2350,
63,
18,
199,
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,
3,
199,
3,
1898,
14790,
13,
7968,
3107,
85,
8076,
2290,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
9028,
14,
199,
3,
199,
3,
9028,
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,
9028,
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,
9028,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
199,
504,
9028,
14,
3494,
14,
1652,
63,
5005,
492,
4137,
63,
2350,
199,
504,
9028,
14,
3494,
492,
6434,
199,
199,
3,
485,
1294,
63,
8006,
63,
3173,
421,
199,
318,
511,
363,
1294,
63,
8006,
63,
3173,
837,
272,
702,
334,
85,
1159,
1377,
13,
1450,
297,
378,
9,
508,
4137,
63,
2350,
423,
1294,
63,
8006,
63,
3173,
8,
85,
1159,
1377,
13,
1450,
59,
16,
10374,
199,
199,
3,
485,
1294,
63,
8006,
421,
199,
318,
511,
363,
1294,
63,
8006,
837,
272,
702,
3842,
85,
7,
80,
297,
841,
395,
334,
85,
1133,
832,
297,
650,
395,
334,
85,
7,
2030,
297,
499,
395,
334,
85,
5121,
679,
760,
13,
1317,
297,
413,
1874,
508,
971,
267,
4137,
63,
2350,
423,
1294,
63,
8006,
8,
85,
5121,
679,
760,
13,
1317,
59,
17,
12978,
2030,
59,
18,
12978,
505,
59,
19,
12978,
80,
59,
20,
10374,
199,
199,
3,
485,
525,
63,
3248,
63,
475,
63,
2350,
421,
199,
318,
1852,
63,
2350,
63,
17,
8,
3248,
304,
272,
1738,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1738,
339,
1031,
14,
3223,
59,
85,
5121,
679,
760,
13,
1317,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
5121,
679,
760,
13,
1317,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
7,
2030,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
2030,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
1133,
832,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
1133,
832,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
7,
80,
297,
413,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
80,
297,
413,
61,
339,
1031,
14,
3248,
275,
4137,
339,
372,
1738,
421,
199,
318,
1852,
63,
2350,
63,
18,
8,
3248,
63,
17,
12,
4137,
63,
18,
304,
272,
1738,
275,
1852,
63,
2350,
63,
17,
8,
3248,
63,
17,
9,
272,
1031,
275,
1738,
14,
3223,
59,
85,
5121,
679,
760,
13,
1317,
297,
413,
61,
339,
1031,
14,
3223,
59,
85,
7,
2030,
297,
499,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
2030,
297,
499,
61,
339,
1031,
14,
3223,
59,
85,
1133,
832,
297,
650,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
1133,
832,
297,
650,
61,
339,
1031,
14,
3223,
59,
85,
7,
80,
297,
841,
61,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
1031,
275,
1031,
14,
3223,
59,
85,
7,
80,
297,
841,
61,
339,
1031,
14,
3248,
275,
4137,
63,
18,
339,
372,
1738,
421,
199,
318,
511,
363,
525,
63,
3248,
63,
475,
63,
2350,
837,
272,
687,
9028,
14,
3494,
492,
671,
317,
556,
272,
671,
317,
556,
63,
493,
275,
671,
317,
556,
14,
88,
317,
556,
493,
199,
3,
259,
671,
317,
556,
63,
493,
275,
6434,
14,
2888,
59,
85,
7,
88,
276,
418,
342,
339,
327,
2654,
314,
1642,
4137,
339,
4137,
63,
17,
275,
671,
317,
556,
63,
493,
14,
5072,
2543,
8,
85,
7,
6257,
358,
272,
14462,
63,
17,
275,
399,
5121,
679,
760,
13,
1317,
59,
17,
12978,
2030,
59,
17,
12978,
505,
59,
17,
12978,
80,
59,
17,
6616,
339,
14701,
63,
2350,
63,
17,
275,
4137,
63,
2350,
14,
27645,
3987,
342,
272,
4137,
63,
2350,
423,
525,
63,
3248,
63,
475,
63,
2350,
8,
388,
11614,
63,
2350,
63,
17,
12,
1816,
4137,
63,
2350,
423,
1294,
63,
8006,
8,
8006,
63,
17,
395,
1816,
4137,
63,
17,
9,
272,
511,
63,
2350,
63,
17,
275,
1852,
63,
2350,
63,
17,
8,
3248,
63,
17,
9,
272,
702,
511,
63,
2350,
63,
17,
508,
14701,
63,
2350,
63,
17,
339,
327,
2654,
4573,
4137,
339,
4137,
63,
18,
275,
671,
317,
556,
63,
493,
14,
5072,
2543,
8,
85,
7,
15943,
358,
272,
14462,
63,
18,
275,
399,
5121,
679,
760,
13,
1317,
59,
17,
12978,
2030,
59,
18,
12978,
505,
59,
19,
12978,
80,
59,
20,
6616,
339,
14701,
63,
2350,
63,
18,
275,
1852,
63,
2350,
63,
17,
8,
3248,
63,
17,
9,
272,
4137,
63,
2350,
423,
525,
63,
3248,
63,
475,
63,
2350,
8,
388,
11614,
63,
2350,
63,
18,
12,
1816,
4137,
63,
2350,
423,
1294,
63,
8006,
8,
8006,
63,
18,
395,
1816,
4137,
63,
18,
9,
272,
511,
63,
2350,
63,
18,
275,
1852,
63,
2350,
63,
18,
8,
3248,
63,
17,
12,
4137,
63,
18,
9,
272,
702,
511,
63,
2350,
63,
18,
508,
14701,
63,
2350,
63,
18,
199,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
pec1985/titanium_mobile
|
apidoc/generators/jsca_generator.py
|
31
|
13433
|
#!/usr/bin/env python
#
# Copyright (c) 2010-2012 Appcelerator, Inc. All Rights Reserved.
# Licensed under the Apache Public License (version 2)
import os, sys, re
this_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.abspath(os.path.join(this_dir, "..")))
from common import dict_has_non_empty_member, strip_tags, not_real_titanium_types, to_ordered_dict
android_support_dir = os.path.abspath(os.path.join(this_dir, "..", "..", "support", "android"))
sys.path.append(android_support_dir)
# We package markdown and simplejson in support/common.
common_support_dir = os.path.abspath(os.path.join(this_dir, "..", "..", "support", "common"))
sys.path.append(common_support_dir)
from markdown import markdown
from tilogger import *
log = None
all_annotated_apis = None
try:
import json
except:
import simplejson as json
def markdown_to_html(s):
# When Ti Studio starts using a rich control for displaying code assist free text
# (which they're planning, according to Kevin Lindsey), we can start doing more
# with this like coming up with ways to link to other types. For now the free-form
# text goes straight is as html generated by markdown. They strip out tags.
# Discussed with Kevin 8/19/2011.
html = markdown(s)
# Any <Titanium.XX.XX> type of markdown links need to have their brackets removed so
# the code assist doesn't see them as tags and thus strip them, thereby losing the
# useful text within. Same for known pseudo-types.
pattern = r"\<[^\>\s]+\>"
matches = re.findall(pattern, html)
if matches:
for m in matches:
tag_name = m[1:-1]
if tag_name.startswith("Titanium") or tag_name in all_annotated_apis:
html = html.replace(m, tag_name)
return html
# Fixes illegal names like "2DMatrix" (not valid Javascript name)
def clean_namespace(ns_in):
def clean_part(part):
if len(part) and part[0].isdigit():
return "_" + part
else:
return part
return ".".join([clean_part(s) for s in ns_in.split(".") ])
# Do not prepend 'Global' to class names (TIDOC-860)
def clean_class_name(class_name):
if class_name.startswith('Global.'):
return class_name[7:]
else:
return class_name
def build_deprecation_message(api):
# Returns the message in markdown format.
result = None
if api.deprecated:
result = " **Deprecated"
if api.deprecated.has_key("since"):
result += " since %s." % api.deprecated["since"]
if api.deprecated.has_key("removed"):
result += " Removed in %s." % api.deprecated["removed"]
if api.deprecated.has_key("notes"):
result += " %s" % api.deprecated["notes"]
result += "**"
return result
def to_jsca_description(summary, api=None):
if summary is None:
return ""
new_summary = summary
if api is not None and api.deprecated is not None:
deprecation_message = build_deprecation_message(api)
if deprecation_message is not None:
new_summary += deprecation_message
return markdown_to_html(new_summary)
def to_jsca_example(example):
return {
"name": example["title"],
"code": markdown_to_html(example["example"])
}
def to_jsca_examples(api):
if dict_has_non_empty_member(api.api_obj, "examples"):
return [to_jsca_example(example) for example in api.api_obj["examples"]]
else:
return []
def to_jsca_inherits(api):
if dict_has_non_empty_member(api.api_obj, "extends"):
return api.api_obj["extends"]
else:
return 'Object'
def to_jsca_permission(prop):
if dict_has_non_empty_member(prop.api_obj, "permission"):
return prop.api_obj["permission"]
else:
return "read-write"
def to_jsca_availability(prop):
if dict_has_non_empty_member(prop.api_obj, "availability"):
return prop.api_obj["availability"]
else:
return "always"
def to_jsca_type_name(type_info):
if isinstance(type_info, list) or isinstance(type_info, tuple) and len(type_info) > 0:
# Currently the JSCA spec allows for just one type per parameter/property/returnType.
# We have to choose one.
# We'll take "Object" if it's one of the possible types, else we'll just take the first one.
if "object" in [t.lower() for t in type_info]:
return "Object"
else:
return to_jsca_type_name(type_info[0])
type_test = type_info
if type_test.startswith("Callback"):
type_test ="Function"
elif type_test.startswith("Array"):
type_test = "Array"
# for jsca we're setting Dictionary<XX> to just XX as we did in the old jsca generator when
# setting the parameter type of createXX methods to XX in order to get rich documentation
# for what's expected in that parameter.
elif type_test.startswith("Dictionary<"):
match = re.findall(r"<([^>]+)>", type_test)
if match is not None and len(match) > 0:
type_test = match[0]
elif type_test == "Dictionary":
type_test = "Object"
return clean_namespace(type_test)
def to_jsca_constants(constants_list):
global all_annotated_apis
rv = []
if type(constants_list) is not list:
a = [constants_list]
constants_list = a
for item in constants_list:
namespace = item.rsplit('.', 1)[0]
token = item.rsplit('.', 1)[-1]
if item[-1] == '*':
token = token[:-1]
if namespace in all_annotated_apis:
for property in all_annotated_apis[namespace].api_obj["properties"]:
if (token and property["name"].startswith(token)) or (not token and re.match(r"[_A-Z]+", property["name"])):
rv.append(namespace + "." + property["name"])
if property["name"] == token:
break
return rv
def to_jsca_property(prop, for_event=False):
result = {
"name": prop.name,
"description": "" if "summary" not in prop.api_obj else to_jsca_description(prop.api_obj["summary"], prop),
"deprecated": prop.deprecated is not None and len(prop.deprecated) > 0,
"type": "" if "type" not in prop.api_obj else to_jsca_type_name(prop.api_obj["type"])
}
if not for_event:
creatable = False;
if dict_has_non_empty_member(prop.parent.api_obj, "extends"):
ancestor = prop.parent.api_obj["extends"]
if (ancestor == "Titanium.Proxy" or ancestor == "Titanium.UI.View"):
creatable = True
if ("createable" in prop.parent.api_obj):
creatable = prop.parent.api_obj["createable"]
result["isClassProperty"] = False if (creatable and prop.name != prop.name.upper()) else True
result["isInstanceProperty"] = True if (creatable and prop.name != prop.name.upper()) else False
result["since"] = to_jsca_since(prop.platforms)
result["userAgents"] = to_jsca_userAgents(prop.platforms)
result["isInternal"] = False
result["examples"] = to_jsca_examples(prop)
result["availability"] = to_jsca_availability(prop)
result["permission"] = to_jsca_permission(prop)
if "constants" in prop.api_obj:
result["constants"] = to_jsca_constants(prop.api_obj["constants"])
return to_ordered_dict(result, ("name",))
def to_jsca_properties(props, for_event=False):
return [to_jsca_property(prop, for_event) for prop in props]
def to_jsca_return_types(return_types):
if return_types is None or len(return_types) == 0:
return []
orig_types = return_types
if not isinstance(orig_types, list):
orig_types = [orig_types]
return [{
"type": to_jsca_type_name(t["type"]),
"description": "" if "summary" not in t else to_jsca_description(t["summary"])
} for t in orig_types]
def to_jsca_method_parameter(p):
data_type = to_jsca_type_name(p.api_obj["type"])
if data_type.lower() == "object" and p.parent.name.startswith("create"):
if "returns" in p.parent.api_obj:
method_return_type = p.parent.api_obj["returns"]["type"]
if method_return_type in all_annotated_apis:
type_in_method_name = p.parent.name.replace("create", "")
if len(type_in_method_name) > 0 and type_in_method_name == method_return_type.split(".")[-1]:
data_type = to_jsca_type_name(method_return_type)
usage = "required"
if "optional" in p.api_obj and p.api_obj["optional"]:
usage = "optional"
elif p.repeatable:
usage = "one-or-more"
result = {
"name": p.name,
"description": "" if "summary" not in p.api_obj else to_jsca_description(p.api_obj["summary"], p),
"type": data_type,
"usage": usage
}
if "constants" in p.api_obj:
result["constants"] = to_jsca_constants(p.api_obj["constants"])
return to_ordered_dict(result, ('name',))
def to_jsca_function(method):
log.trace("%s.%s" % (method.parent.name, method.name))
creatable = False;
if dict_has_non_empty_member(method.parent.api_obj, "extends"):
ancestor = method.parent.api_obj["extends"]
if (ancestor == "Titanium.Proxy" or ancestor == "Titanium.UI.View"):
creatable = True;
if ("createable" in method.parent.api_obj):
creatable = method.parent.api_obj["createable"]
result = {
"name": method.name,
"deprecated": method.deprecated is not None and len(method.deprecated) > 0,
"description": "" if "summary" not in method.api_obj else to_jsca_description(method.api_obj["summary"], method)
}
if dict_has_non_empty_member(method.api_obj, "returns") and method.api_obj["returns"] != "void":
result["returnTypes"] = to_jsca_return_types(method.api_obj["returns"])
if method.parameters is not None and len(method.parameters) > 0:
result["parameters"] = [to_jsca_method_parameter(p) for p in method.parameters]
result["since"] = to_jsca_since(method.platforms)
result['userAgents'] = to_jsca_userAgents(method.platforms)
result['isInstanceProperty'] = True if creatable else False
result['isClassProperty'] = False if creatable else True
result['isInternal'] = False # we don't make this distinction (yet anyway)
result['examples'] = to_jsca_examples(method)
result['references'] = [] # we don't use the notion of 'references' (yet anyway)
result['exceptions'] = [] # we don't specify exceptions (yet anyway)
result['isConstructor'] = False # we don't expose native class constructors
result['isMethod'] = True # all of our functions are class instance functions, ergo methods
return to_ordered_dict(result, ('name',))
def to_jsca_functions(methods):
return [to_jsca_function(method) for method in methods]
def to_jsca_event(event):
return to_ordered_dict({
"name": event.name,
"description": "" if "summary" not in event.api_obj else to_jsca_description(event.api_obj["summary"], event),
"deprecated": event.deprecated is not None and len(event.deprecated) > 0,
"properties": to_jsca_properties(event.properties, for_event=True)
}, ("name",))
def to_jsca_events(events):
return [to_jsca_event(event) for event in events]
def to_jsca_remarks(api):
if dict_has_non_empty_member(api.api_obj, "description"):
return [markdown_to_html(api.api_obj["description"])]
else:
return []
def to_jsca_userAgents(platforms):
return [{"platform": platform["name"]} for platform in platforms]
def to_jsca_since(platforms):
return [to_ordered_dict({
"name": "Titanium Mobile SDK - %s" % platform["pretty_name"],
"version": platform["since"]
}, ("name",)) for platform in platforms]
def to_jsca_type(api):
# Objects marked as external should be ignored
if api.external:
return None
if api.name in not_real_titanium_types:
return None
log.trace("Converting %s to jsca" % api.name)
result = {
"name": clean_class_name(clean_namespace(api.name)),
"isInternal": False,
"description": "" if "summary" not in api.api_obj else to_jsca_description(api.api_obj["summary"], api),
"deprecated": api.deprecated is not None and len(api.deprecated) > 0,
"examples": to_jsca_examples(api),
"properties": to_jsca_properties(api.properties),
"functions": to_jsca_functions(api.methods),
"events": to_jsca_events(api.events),
"remarks": to_jsca_remarks(api),
"userAgents": to_jsca_userAgents(api.platforms),
"since": to_jsca_since(api.platforms),
"inherits": to_jsca_inherits(api)
}
# TIMOB-7169. If it's a proxy (non-module) and it has no "class properties",
# mark it as internal. This avoids it being displayed in Code Assist.
# TIDOC-860. Do not mark Global types as internal.
if api.typestr == "proxy" and not (api.name).startswith('Global.'):
can_hide = True
for p in result["properties"]:
if p["isClassProperty"]:
can_hide = False
break
result["isInternal"] = can_hide
return to_ordered_dict(result, ('name',))
def generate(raw_apis, annotated_apis, options):
global all_annotated_apis, log
log_level = TiLogger.INFO
if options.verbose:
log_level = TiLogger.TRACE
all_annotated_apis = annotated_apis
log = TiLogger(None, level=log_level, output_stream=sys.stderr)
log.info("Generating JSCA")
result = {'aliases': [ {'name': 'Ti', 'type': 'Titanium'} ]}
types = []
result['types'] = types
for key in all_annotated_apis.keys():
jsca_type = to_jsca_type(all_annotated_apis[key])
if jsca_type is not None:
types.append(jsca_type)
if options.stdout:
json.dump(result, sys.stdout, sort_keys=False, indent=4)
else:
output_folder = None
if options.output:
output_folder = options.output
else:
dist_dir = os.path.abspath(os.path.join(this_dir, "..", "..", "dist"))
if os.path.exists(dist_dir):
output_folder = os.path.join(dist_dir, "apidoc")
if not os.path.exists(output_folder):
os.mkdir(output_folder)
if not output_folder:
log.warn("No output folder specified and dist path does not exist. Forcing output to stdout.")
json.dump(result, sys.stdout, sort_keys=False, indent=4)
else:
output_file = os.path.join(output_folder, "api.jsca")
f = open(output_file, "w")
json.dump(result, f, sort_keys=False, indent=4)
f.close()
log.info("%s written" % output_file)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
13,
7409,
4693,
27139,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
1334,
314,
3668,
1684,
844,
334,
1023,
499,
9,
199,
199,
646,
747,
12,
984,
12,
295,
199,
199,
3749,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
13324,
199,
199,
504,
2863,
492,
1211,
63,
1989,
63,
2865,
63,
1667,
63,
1114,
12,
6202,
63,
2969,
12,
440,
63,
3093,
63,
6403,
290,
5170,
63,
1313,
12,
370,
63,
8235,
63,
807,
199,
199,
6238,
63,
4058,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
401,
21777,
401,
298,
4058,
401,
298,
6238,
2237,
199,
1274,
14,
515,
14,
740,
8,
6238,
63,
4058,
63,
694,
9,
199,
199,
3,
2136,
2559,
18502,
436,
13804,
315,
2291,
15,
2330,
14,
199,
2330,
63,
4058,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
401,
21777,
401,
298,
4058,
401,
298,
2330,
2237,
199,
1274,
14,
515,
14,
740,
8,
2330,
63,
4058,
63,
694,
9,
199,
504,
18502,
492,
18502,
199,
199,
504,
3367,
2921,
492,
627,
199,
793,
275,
488,
199,
452,
63,
3226,
972,
63,
12662,
275,
488,
199,
199,
893,
26,
199,
198,
646,
2022,
199,
2590,
26,
199,
198,
646,
13804,
465,
2022,
199,
199,
318,
18502,
63,
475,
63,
1360,
8,
83,
304,
199,
198,
3,
3979,
377,
73,
13225,
9174,
1808,
282,
30162,
3304,
367,
20589,
1233,
465,
11734,
2867,
1318,
199,
198,
3,
334,
6777,
2985,
3984,
1620,
11495,
12,
7182,
370,
25645,
11908,
491,
688,
261,
89,
395,
781,
883,
1343,
9689,
1655,
199,
198,
3,
543,
642,
2839,
17262,
1536,
543,
15217,
370,
2142,
370,
1163,
2943,
14,
221,
2104,
3063,
314,
2867,
13,
964,
199,
198,
3,
1318,
13538,
23669,
365,
465,
3517,
4046,
701,
18502,
14,
221,
9322,
6202,
734,
3762,
14,
199,
198,
3,
5289,
67,
527,
939,
543,
25645,
11908,
1695,
15,
1167,
15,
8128,
14,
199,
198,
1360,
275,
18502,
8,
83,
9,
199,
198,
3,
6184,
665,
52,
390,
290,
5170,
14,
2483,
14,
2483,
30,
730,
402,
18502,
6220,
1929,
370,
1172,
3932,
21873,
4829,
880,
199,
198,
3,
314,
1233,
465,
11734,
3181,
1133,
1937,
3062,
465,
3762,
436,
12850,
6202,
3062,
12,
2337,
991,
560,
1044,
314,
199,
198,
3,
2997,
1318,
4453,
14,
221,
14766,
367,
6040,
15984,
13,
1313,
14,
199,
198,
3401,
275,
519,
3212,
28,
16045,
3072,
83,
24621,
4335,
199,
198,
6742,
275,
295,
14,
6452,
8,
3401,
12,
3517,
9,
199,
198,
692,
4450,
26,
507,
198,
509,
333,
315,
4450,
26,
686,
198,
1450,
63,
354,
275,
333,
59,
17,
6809,
17,
61,
686,
198,
692,
1947,
63,
354,
14,
2460,
480,
52,
390,
290,
5170,
531,
503,
1947,
63,
354,
315,
1006,
63,
3226,
972,
63,
12662,
26,
1585,
198,
1360,
275,
3517,
14,
1814,
8,
77,
12,
1947,
63,
354,
9,
199,
198,
1107,
3517,
199,
199,
3,
14811,
397,
20282,
1561,
2839,
298,
18,
36,
6443,
2,
334,
1397,
1686,
31861,
536,
9,
199,
318,
3633,
63,
3251,
8,
561,
63,
262,
304,
199,
198,
318,
3633,
63,
2064,
8,
2064,
304,
507,
198,
692,
822,
8,
2064,
9,
436,
1777,
59,
16,
1055,
13896,
837,
686,
198,
1107,
14220,
435,
1777,
507,
198,
2836,
26,
686,
198,
1107,
1777,
199,
198,
1107,
32443,
904,
779,
3118,
63,
2064,
8,
83,
9,
367,
308,
315,
700,
63,
262,
14,
1294,
15857,
4794,
199,
199,
3,
4226,
440,
18213,
283,
7025,
7,
370,
1021,
1561,
334,
52,
998,
21137,
13,
14832,
9,
199,
318,
3633,
63,
533,
63,
354,
8,
533,
63,
354,
304,
199,
198,
692,
1021,
63,
354,
14,
2460,
360,
7025,
30194,
507,
198,
1107,
1021,
63,
354,
59,
23,
2938,
199,
198,
2836,
26,
507,
198,
1107,
1021,
63,
354,
199,
199,
318,
1900,
63,
15383,
63,
1188,
8,
1246,
304,
199,
198,
3,
1803,
314,
1245,
315,
18502,
1475,
14,
199,
198,
1099,
275,
488,
199,
198,
692,
2986,
14,
6667,
26,
507,
198,
1099,
275,
298,
221,
1011,
19727,
2,
507,
198,
692,
2986,
14,
6667,
14,
1989,
63,
498,
480,
8585,
2349,
686,
198,
1099,
847,
298,
3967,
450,
83,
2122,
450,
2986,
14,
6667,
905,
8585,
937,
507,
198,
692,
2986,
14,
6667,
14,
1989,
63,
498,
480,
10649,
2349,
686,
198,
1099,
847,
298,
799,
3539,
315,
450,
83,
2122,
450,
2986,
14,
6667,
905,
10649,
937,
507,
198,
692,
2986,
14,
6667,
14,
1989,
63,
498,
480,
5983,
2349,
686,
198,
1099,
847,
298,
450,
83,
2,
450,
2986,
14,
6667,
905,
5983,
937,
507,
198,
1099,
847,
298,
538,
2,
199,
198,
1107,
754,
199,
199,
318,
370,
63,
74,
7101,
63,
1802,
8,
4705,
12,
2986,
29,
403,
304,
199,
198,
692,
6212,
365,
488,
26,
507,
198,
1107,
3087,
199,
198,
1222,
63,
4705,
275,
6212,
199,
198,
692,
2986,
365,
440,
488,
436,
2986,
14,
6667,
365,
440,
488,
26,
507,
198,
15383,
63,
1188,
275,
1900,
63,
15383,
63,
1188,
8,
1246,
9,
507,
198,
692,
17831,
63,
1188,
365,
440,
488,
26,
686,
198,
1222,
63,
4705,
847,
17831,
63,
1188,
199,
198,
1107,
18502,
63,
475,
63,
1360,
8,
1222,
63,
4705,
9,
199,
199,
318,
370,
63,
74,
7101,
63,
2694,
8,
2694,
304,
199,
198,
1107,
469,
686,
198,
2,
354,
582,
2893,
905,
1213,
2255,
686,
198,
2,
600,
582,
18502,
63,
475,
63,
1360,
8,
2694,
905,
2694,
3135,
686,
198,
93,
199,
199,
318,
370,
63,
74,
7101,
63,
8589,
8,
1246,
304,
199,
198,
692,
1211,
63,
1989,
63,
2865,
63,
1667,
63,
1114,
8,
1246,
14,
1246,
63,
1113,
12,
298,
8589,
2349,
507,
198,
1107,
359,
475,
63,
74,
7101,
63,
2694,
8,
2694,
9
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
13,
7409,
4693,
27139,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
1334,
314,
3668,
1684,
844,
334,
1023,
499,
9,
199,
199,
646,
747,
12,
984,
12,
295,
199,
199,
3749,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
13324,
199,
199,
504,
2863,
492,
1211,
63,
1989,
63,
2865,
63,
1667,
63,
1114,
12,
6202,
63,
2969,
12,
440,
63,
3093,
63,
6403,
290,
5170,
63,
1313,
12,
370,
63,
8235,
63,
807,
199,
199,
6238,
63,
4058,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
401,
21777,
401,
298,
4058,
401,
298,
6238,
2237,
199,
1274,
14,
515,
14,
740,
8,
6238,
63,
4058,
63,
694,
9,
199,
199,
3,
2136,
2559,
18502,
436,
13804,
315,
2291,
15,
2330,
14,
199,
2330,
63,
4058,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
21777,
401,
21777,
401,
298,
4058,
401,
298,
2330,
2237,
199,
1274,
14,
515,
14,
740,
8,
2330,
63,
4058,
63,
694,
9,
199,
504,
18502,
492,
18502,
199,
199,
504,
3367,
2921,
492,
627,
199,
793,
275,
488,
199,
452,
63,
3226,
972,
63,
12662,
275,
488,
199,
199,
893,
26,
199,
198,
646,
2022,
199,
2590,
26,
199,
198,
646,
13804,
465,
2022,
199,
199,
318,
18502,
63,
475,
63,
1360,
8,
83,
304,
199,
198,
3,
3979,
377,
73,
13225,
9174,
1808,
282,
30162,
3304,
367,
20589,
1233,
465,
11734,
2867,
1318,
199,
198,
3,
334,
6777,
2985,
3984,
1620,
11495,
12,
7182,
370,
25645,
11908,
491,
688,
261,
89,
395,
781,
883,
1343,
9689,
1655,
199,
198,
3,
543,
642,
2839,
17262,
1536,
543,
15217,
370,
2142,
370,
1163,
2943,
14,
221,
2104,
3063,
314,
2867,
13,
964,
199,
198,
3,
1318,
13538,
23669,
365,
465,
3517,
4046,
701,
18502,
14,
221,
9322,
6202,
734,
3762,
14,
199,
198,
3,
5289,
67,
527,
939,
543,
25645,
11908,
1695,
15,
1167,
15,
8128,
14,
199,
198,
1360,
275,
18502,
8,
83,
9,
199,
198,
3,
6184,
665,
52,
390,
290,
5170,
14,
2483,
14,
2483,
30,
730,
402,
18502,
6220,
1929,
370,
1172,
3932,
21873,
4829,
880,
199,
198,
3,
314,
1233,
465,
11734,
3181,
1133,
1937,
3062,
465,
3762,
436,
12850,
6202,
3062,
12,
2337,
991,
560,
1044,
314,
199,
198,
3,
2997,
1318,
4453,
14,
221,
14766,
367,
6040,
15984,
13,
1313,
14,
199,
198,
3401,
275,
519,
3212,
28,
16045,
3072,
83,
24621,
4335,
199,
198,
6742,
275,
295,
14,
6452,
8,
3401,
12,
3517,
9,
199,
198,
692,
4450,
26,
507,
198,
509,
333,
315,
4450,
26,
686,
198,
1450,
63,
354,
275,
333,
59,
17,
6809,
17,
61,
686,
198,
692,
1947,
63,
354,
14,
2460,
480,
52,
390,
290,
5170,
531,
503,
1947,
63,
354,
315,
1006,
63,
3226,
972,
63,
12662,
26,
1585,
198,
1360,
275,
3517,
14,
1814,
8,
77,
12,
1947,
63,
354,
9,
199,
198,
1107,
3517,
199,
199,
3,
14811,
397,
20282,
1561,
2839,
298,
18,
36,
6443,
2,
334,
1397,
1686,
31861,
536,
9,
199,
318,
3633,
63,
3251,
8,
561,
63,
262,
304,
199,
198,
318,
3633,
63,
2064,
8,
2064,
304,
507,
198,
692,
822,
8,
2064,
9,
436,
1777,
59,
16,
1055,
13896,
837,
686,
198,
1107,
14220,
435,
1777,
507,
198,
2836,
26,
686,
198,
1107,
1777,
199,
198,
1107,
32443,
904,
779,
3118,
63,
2064,
8,
83,
9,
367,
308,
315,
700,
63,
262,
14,
1294,
15857,
4794,
199,
199,
3,
4226,
440,
18213,
283,
7025,
7,
370,
1021,
1561,
334,
52,
998,
21137,
13,
14832,
9,
199,
318,
3633,
63,
533,
63,
354,
8,
533,
63,
354,
304,
199,
198,
692,
1021,
63,
354,
14,
2460,
360,
7025,
30194,
507,
198,
1107,
1021,
63,
354,
59,
23,
2938,
199,
198,
2836,
26,
507,
198,
1107,
1021,
63,
354,
199,
199,
318,
1900,
63,
15383,
63,
1188,
8,
1246,
304,
199,
198,
3,
1803,
314,
1245,
315,
18502,
1475,
14,
199,
198,
1099,
275,
488,
199,
198,
692,
2986,
14,
6667,
26,
507,
198,
1099,
275,
298,
221,
1011,
19727,
2,
507,
198,
692,
2986,
14,
6667,
14,
1989,
63,
498,
480,
8585,
2349,
686,
198,
1099,
847,
298,
3967,
450,
83,
2122,
450,
2986,
14,
6667,
905,
8585,
937,
507,
198,
692,
2986,
14,
6667,
14,
1989,
63,
498,
480,
10649,
2349,
686,
198,
1099,
847,
298,
799,
3539,
315,
450,
83,
2122,
450,
2986,
14,
6667,
905,
10649,
937,
507,
198,
692,
2986,
14,
6667,
14,
1989,
63,
498,
480,
5983,
2349,
686,
198,
1099,
847,
298,
450,
83,
2,
450,
2986,
14,
6667,
905,
5983,
937,
507,
198,
1099,
847,
298,
538,
2,
199,
198,
1107,
754,
199,
199,
318,
370,
63,
74,
7101,
63,
1802,
8,
4705,
12,
2986,
29,
403,
304,
199,
198,
692,
6212,
365,
488,
26,
507,
198,
1107,
3087,
199,
198,
1222,
63,
4705,
275,
6212,
199,
198,
692,
2986,
365,
440,
488,
436,
2986,
14,
6667,
365,
440,
488,
26,
507,
198,
15383,
63,
1188,
275,
1900,
63,
15383,
63,
1188,
8,
1246,
9,
507,
198,
692,
17831,
63,
1188,
365,
440,
488,
26,
686,
198,
1222,
63,
4705,
847,
17831,
63,
1188,
199,
198,
1107,
18502,
63,
475,
63,
1360,
8,
1222,
63,
4705,
9,
199,
199,
318,
370,
63,
74,
7101,
63,
2694,
8,
2694,
304,
199,
198,
1107,
469,
686,
198,
2,
354,
582,
2893,
905,
1213,
2255,
686,
198,
2,
600,
582,
18502,
63,
475,
63,
1360,
8,
2694,
905,
2694,
3135,
686,
198,
93,
199,
199,
318,
370,
63,
74,
7101,
63,
8589,
8,
1246,
304,
199,
198,
692,
1211,
63,
1989,
63,
2865,
63,
1667,
63,
1114,
8,
1246,
14,
1246,
63,
1113,
12,
298,
8589,
2349,
507,
198,
1107,
359,
475,
63,
74,
7101,
63,
2694,
8,
2694,
9,
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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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dvitme/account-financial-tools
|
account_asset_management/tests/__init__.py
|
35
|
1101
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# account_asset_management tests
#
# Copyright (c) 2014 ACSONE SA/NV (acsone.eu).
#
# 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 . import test_account_asset_management
checks = [
test_account_asset_management,
]
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
2933,
63,
6562,
63,
8110,
2295,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
6927,
437,
3298,
4817,
13950,
15,
7312,
334,
645,
83,
368,
14,
16913,
680,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
1275,
492,
511,
63,
2048,
63,
6562,
63,
8110,
199,
199,
8625,
275,
359,
272,
511,
63,
2048,
63,
6562,
63,
8110,
12,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
2933,
63,
6562,
63,
8110,
2295,
199,
3,
199,
3,
259,
1898,
334,
67,
9,
6927,
437,
3298,
4817,
13950,
15,
7312,
334,
645,
83,
368,
14,
16913,
680,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
1275,
492,
511,
63,
2048,
63,
6562,
63,
8110,
199,
199,
8625,
275,
359,
272,
511,
63,
2048,
63,
6562,
63,
8110,
12,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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-admin startproject' using Django 1.11.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
from .secrets import SECRET_KEY
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'jet',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'phonenumber_field',
'firearm',
'member',
'register'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'fusilier.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'fusilier.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-gb'
TIME_ZONE = 'Europe/London'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
|
agpl-3.0
|
[
624,
199,
9323,
2202,
367,
15632,
338,
5697,
2199,
14,
199,
199,
12706,
701,
283,
1176,
13,
2113,
1343,
1715,
7,
1808,
5634,
413,
14,
845,
14,
17,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
646,
747,
199,
504,
1275,
16153,
492,
5795,
11771,
63,
3078,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
942,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
359,
272,
283,
74,
386,
297,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
272,
283,
838,
265,
287,
884,
63,
698,
297,
272,
283,
8935,
5362,
297,
272,
283,
1114,
297,
272,
283,
2683,
7,
199,
61,
199,
199,
19987,
275,
359,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
61,
199,
199,
5441,
63,
18125,
275,
283,
13499,
338,
5697,
14,
3603,
7,
199,
199,
25437,
275,
359,
272,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
283,
14455,
356,
990,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
469,
288,
283,
1100,
63,
10547,
356,
359,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1757,
297,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1069,
297,
355,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
355,
283,
1176,
14,
2828,
14,
3431,
14,
1100,
63,
10547,
14,
3431,
297,
288,
2156,
267,
1660,
272,
1660,
199,
61,
199,
199,
16828,
63,
24051,
275,
283,
13499,
338,
5697,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
421,
199,
3,
13635,
6411,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
1121,
15,
1751,
12645,
1178,
13,
2060,
13,
11346,
199,
199,
5580,
63,
9032,
63,
5600,
19033,
275,
359,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
1899,
1646,
7467,
13093,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
12092,
4625,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
7844,
6139,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
14687,
6139,
8640,
297,
272,
1660,
199,
61,
421,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
4908,
7,
199,
199,
4961,
63,
15353,
275,
283,
15201,
15,
44,
7835,
265,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
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
] |
[
199,
9323,
2202,
367,
15632,
338,
5697,
2199,
14,
199,
199,
12706,
701,
283,
1176,
13,
2113,
1343,
1715,
7,
1808,
5634,
413,
14,
845,
14,
17,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
646,
747,
199,
504,
1275,
16153,
492,
5795,
11771,
63,
3078,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
942,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
359,
272,
283,
74,
386,
297,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
272,
283,
838,
265,
287,
884,
63,
698,
297,
272,
283,
8935,
5362,
297,
272,
283,
1114,
297,
272,
283,
2683,
7,
199,
61,
199,
199,
19987,
275,
359,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
61,
199,
199,
5441,
63,
18125,
275,
283,
13499,
338,
5697,
14,
3603,
7,
199,
199,
25437,
275,
359,
272,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
283,
14455,
356,
990,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
469,
288,
283,
1100,
63,
10547,
356,
359,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1757,
297,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1069,
297,
355,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
355,
283,
1176,
14,
2828,
14,
3431,
14,
1100,
63,
10547,
14,
3431,
297,
288,
2156,
267,
1660,
272,
1660,
199,
61,
199,
199,
16828,
63,
24051,
275,
283,
13499,
338,
5697,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
421,
199,
3,
13635,
6411,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
1121,
15,
1751,
12645,
1178,
13,
2060,
13,
11346,
199,
199,
5580,
63,
9032,
63,
5600,
19033,
275,
359,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
1899,
1646,
7467,
13093,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
12092,
4625,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
7844,
6139,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
14687,
6139,
8640,
297,
272,
1660,
199,
61,
421,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
4908,
7,
199,
199,
4961,
63,
15353,
275,
283,
15201,
15,
44,
7835,
265,
7,
199,
199,
4701,
63,
41,
1085,
46,
275,
715,
199,
199,
4701,
63,
44,
709,
46,
275,
715,
199,
199,
4701,
63,
14226,
275,
715,
421,
199,
3,
13599,
1584,
334,
14391,
12,
15250,
12,
32658,
9,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
845,
15,
21232,
15,
1986,
13,
1725,
15,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
ujjwalwahi/odoo
|
addons/product_extended/wizard/__init__.py
|
374
|
1078
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard_price
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
198,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
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,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
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,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
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,
646,
12262,
63,
4777,
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
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
198,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
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,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
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,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
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,
646,
12262,
63,
4777,
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,
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,
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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
] |
MaxTyutyunnikov/lino
|
obsolete/src/lino/apps/pinboard/quotes.py
|
1
|
4769
|
## Copyright 2003-2006 Luc Saffre
## This file is part of the Lino project.
## Lino 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.
## Lino 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 Lino; if not, write to the Free Software Foundation,
## Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from lino.adamo.ddl import *
#from lino.apps.pinboard.babel import Language
#from lino.apps.pinboard.tables import Person, City, Language
import pinboard_tables as tables
from lino.apps.contacts.contacts_tables import Person
class Quote(StoredDataRow):
tableName="Quotes"
def initTable(self,table):
#MemoTable.init(self)
table.addField('id',ROWID)
table.addField('quote',MEMO)
table.addPointer('author',Author)
#.setDetail('quotesByAuthor')
table.addPointer('lang',tables.Language)
#table.addField('lang',LANG)
#self.pubRef = Field(STRING)
#self.pub = Pointer("PUBLICATIONS")
def __str__(self):
return "[q"+str(self.id)+"]"
class QuotesReport(DataReport):
leadTable=Quote
class Publication(MemoTreeRow):
tableName="Publications"
def initTable(self,table):
MemoTreeRow.initTable(self,table)
table.addField('id',ROWID)
table.addField('pubYear',INT)
table.addField('subtitle',STRING)
table.addField('typeRef',STRING)
table.addPointer('pubType', PubType)
table.addPointer('author',Author)
table.addPointer('lang',tables.Language)
#table.addField('lang',LANG)
table.addField('url',URL)
class PublicationsReport(DataReport):
leadTable=Publication
class PubType(BabelRow):
tableName="PubTypes"
def initTable(self,table):
table.addField('id',STRING)
BabelRow.initTable(self,table)
table.addField('typeRefPrefix',STRING)
table.addBabelField('pubRefLabel',STRING)
class PubTypesReport(DataReport):
leadTable=PubType
class Topic(TreeRow):
tableName="Topics"
def initTable(self,table):
TreeRow.initTable(self,table)
table.addField('id',ROWID)
table.addBabelField('name',STRING)
#table.addPointer('lang',Language)
table.addField('dewey',STRING)
table.addField('cdu',STRING)
table.addField('dmoz',URL)
table.addField('wikipedia',URL)
table.addBabelField('url',URL)
#table.addView('simple',"name url super children")
def __str__(self):
return self.name
class TopicsReport(DataReport):
leadTable=Topic
columnNames="name url super children"
class Author(Person):
tableName="Authors"
def initTable(self,table):
Person.initTable(self,table)
table.addDetail('quotesByAuthor',Quote,'author')
## def quotesByAuthor(self,*args,**kw):
## kw['author']=self
## return self.detail(Quote,*args,**kw)
class AuthorsReport(DataReport):
leadTable=Author
class PubAuthor(LinkingRow):
tableName="PubAuthors"
fromClass=Publication
toClass=Author
## def __init__(self,parent,**kw):
## LinkingRow.__init__(self,parent,Publication,Author,**kw)
class PubAuthorsReport(DataReport):
leadTable=PubAuthor
class AuthorEvent(BabelRow):
"Birth, diplom, marriage, death..."
tableName="AuthorEvents"
def initTable(self,table):
BabelRow.initTable(self,table)
table.addField('seq',ROWID)
table.addPointer('aetype',AuthorEventType)
table.addPointer('author',Author)
table.addField('aedate',DATE)
table.addPointer('place',tables.City)
table.setPrimaryKey('author seq')
def __str__(self):
s = str(self.type)
if self.date is not None:
s += " " + str(self.date)
return s
class AuthorEventsReport(DataReport):
leadTable=AuthorEvent
class AuthorEventType(BabelRow):
"Birth, diplom, marriage, death..."
tableName="AuthorEventTypes"
def initTable(self,table):
BabelRow.initTable(self,table)
table.addField('id',ROWID,\
doc="the internal id" )
#self.name = BabelField(STRING)
class AuthorEventTypesReport(DataReport):
leadTable=AuthorEventType
|
gpl-3.0
|
[
309,
1898,
13004,
13,
7968,
491,
947,
428,
9181,
264,
199,
199,
309,
961,
570,
365,
1777,
402,
314,
491,
10175,
2199,
14,
199,
199,
309,
491,
10175,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
309,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
491,
10175,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
309,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
199,
309,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
199,
309,
844,
367,
1655,
2436,
14,
199,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
491,
10175,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
199,
309,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
199,
504,
7403,
79,
14,
350,
4393,
14,
17102,
492,
627,
199,
3,
504,
7403,
79,
14,
5181,
14,
7751,
3576,
14,
66,
902,
492,
8466,
199,
199,
3,
504,
7403,
79,
14,
5181,
14,
7751,
3576,
14,
5987,
492,
8028,
12,
14753,
12,
8466,
199,
646,
10713,
3576,
63,
5987,
465,
6716,
199,
504,
7403,
79,
14,
5181,
14,
18147,
14,
18147,
63,
5987,
492,
8028,
199,
199,
533,
29335,
8,
4759,
581,
1451,
5810,
304,
272,
32652,
628,
2371,
6510,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
327,
1352,
573,
3186,
14,
826,
8,
277,
9,
267,
1817,
14,
525,
792,
360,
344,
297,
1092,
9845,
9,
267,
1817,
14,
525,
792,
360,
3513,
297,
3635,
2679,
9,
267,
1817,
14,
525,
12190,
360,
2502,
297,
5949,
9,
267,
327,
14,
409,
8064,
360,
14005,
2175,
5949,
358,
267,
1817,
14,
525,
12190,
360,
4159,
297,
5987,
14,
8493,
9,
267,
327,
1224,
14,
525,
792,
360,
4159,
297,
7442,
9,
2728,
327,
277,
14,
5645,
2891,
275,
5024,
8,
5353,
9,
267,
327,
277,
14,
5645,
275,
28833,
480,
19476,
12969,
531,
5493,
347,
636,
495,
721,
277,
304,
267,
372,
7369,
81,
7709,
495,
8,
277,
14,
344,
6393,
937,
2,
199,
199,
533,
5843,
6510,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
12838,
421,
199,
533,
1684,
425,
8,
1352,
573,
3987,
5810,
304,
272,
32652,
628,
9885,
1298,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
3194,
573,
3987,
5810,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
792,
360,
344,
297,
1092,
9845,
9,
267,
1817,
14,
525,
792,
360,
5645,
15731,
297,
2919,
9,
267,
1817,
14,
525,
792,
360,
14348,
297,
5353,
9,
267,
1817,
14,
525,
792,
360,
466,
2891,
297,
5353,
9,
267,
1817,
14,
525,
12190,
360,
5645,
804,
297,
510,
456,
804,
9,
267,
1817,
14,
525,
12190,
360,
2502,
297,
5949,
9,
267,
1817,
14,
525,
12190,
360,
4159,
297,
5987,
14,
8493,
9,
267,
327,
1224,
14,
525,
792,
360,
4159,
297,
7442,
9,
267,
1817,
14,
525,
792,
360,
633,
297,
2632,
9,
199,
199,
533,
1684,
1298,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
27283,
199,
199,
533,
510,
456,
804,
8,
34,
902,
5810,
304,
272,
32652,
628,
18060,
4100,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
1817,
14,
525,
792,
360,
344,
297,
5353,
9,
267,
699,
902,
5810,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
792,
360,
466,
2891,
4793,
297,
5353,
9,
267,
1817,
14,
525,
34,
902,
792,
360,
5645,
2891,
4314,
297,
5353,
9,
268,
199,
533,
510,
456,
4100,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
18060,
804,
199,
199,
533,
32166,
8,
3987,
5810,
304,
272,
32652,
628,
6105,
2932,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
12178,
5810,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
792,
360,
344,
297,
1092,
9845,
9,
267,
1817,
14,
525,
34,
902,
792,
360,
354,
297,
5353,
9,
267,
327,
1224,
14,
525,
12190,
360,
4159,
297,
8493,
9,
267,
1817,
14,
525,
792,
360,
271,
1129,
89,
297,
5353,
9,
267,
1817,
14,
525,
792,
360,
67,
2033,
297,
5353,
9,
267,
1817,
14,
525,
792,
360,
68,
23120,
297,
2632,
9,
267,
1817,
14,
525,
792,
360,
13961,
297,
2632,
9,
267,
1817,
14,
525,
34,
902,
792,
360,
633,
297,
2632,
9,
2728,
327,
1224,
14,
525,
2768,
360,
4129,
297,
2,
354,
1166,
1613,
4978,
531,
5493,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
1362,
199,
533,
14132,
2932,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
12157,
272,
2763,
5866,
628,
354,
1166,
1613,
4978,
2,
421,
199,
533,
6529,
8,
7344,
304,
272,
32652,
628,
2817,
1384,
2,
2286,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
8028,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
8064,
360,
14005,
2175,
5949,
297,
12838,
2584,
2502,
358,
1362,
199,
309,
258,
347,
9344,
2175,
5949,
8,
277,
19166,
589,
12663,
829,
304,
199,
309,
260,
4775,
459,
2502,
13784,
277,
199,
309,
260,
372,
291,
14,
5506,
8,
12838,
19166,
589,
12663,
829,
9,
199,
199,
533,
6642,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
5949,
1362,
421,
199,
533,
510,
456,
5949,
8,
3834,
316,
5810,
304,
272,
32652,
628,
18060,
2817,
1384,
2,
272,
687,
2543,
29,
27283,
272,
370,
2543,
29,
5949,
1362,
199,
309,
258,
347,
636,
826,
721,
277,
12,
1708,
12663,
829,
304,
199,
309,
260,
10967,
316,
5810,
855,
826,
721,
277,
12,
1708,
12,
27283,
12,
5949,
12663,
829,
9,
1362,
199,
533,
510,
456,
2817,
1384,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
18060,
5949,
1362,
421,
199,
533,
6529,
2390,
8,
34,
902,
5810,
304,
272,
298,
29229,
12,
487,
80,
320,
77,
12
] |
[
1898,
13004,
13,
7968,
491,
947,
428,
9181,
264,
199,
199,
309,
961,
570,
365,
1777,
402,
314,
491,
10175,
2199,
14,
199,
199,
309,
491,
10175,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
309,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
491,
10175,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
309,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
199,
309,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
199,
309,
844,
367,
1655,
2436,
14,
199,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
491,
10175,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
199,
309,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
199,
504,
7403,
79,
14,
350,
4393,
14,
17102,
492,
627,
199,
3,
504,
7403,
79,
14,
5181,
14,
7751,
3576,
14,
66,
902,
492,
8466,
199,
199,
3,
504,
7403,
79,
14,
5181,
14,
7751,
3576,
14,
5987,
492,
8028,
12,
14753,
12,
8466,
199,
646,
10713,
3576,
63,
5987,
465,
6716,
199,
504,
7403,
79,
14,
5181,
14,
18147,
14,
18147,
63,
5987,
492,
8028,
199,
199,
533,
29335,
8,
4759,
581,
1451,
5810,
304,
272,
32652,
628,
2371,
6510,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
327,
1352,
573,
3186,
14,
826,
8,
277,
9,
267,
1817,
14,
525,
792,
360,
344,
297,
1092,
9845,
9,
267,
1817,
14,
525,
792,
360,
3513,
297,
3635,
2679,
9,
267,
1817,
14,
525,
12190,
360,
2502,
297,
5949,
9,
267,
327,
14,
409,
8064,
360,
14005,
2175,
5949,
358,
267,
1817,
14,
525,
12190,
360,
4159,
297,
5987,
14,
8493,
9,
267,
327,
1224,
14,
525,
792,
360,
4159,
297,
7442,
9,
2728,
327,
277,
14,
5645,
2891,
275,
5024,
8,
5353,
9,
267,
327,
277,
14,
5645,
275,
28833,
480,
19476,
12969,
531,
5493,
347,
636,
495,
721,
277,
304,
267,
372,
7369,
81,
7709,
495,
8,
277,
14,
344,
6393,
937,
2,
199,
199,
533,
5843,
6510,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
12838,
421,
199,
533,
1684,
425,
8,
1352,
573,
3987,
5810,
304,
272,
32652,
628,
9885,
1298,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
3194,
573,
3987,
5810,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
792,
360,
344,
297,
1092,
9845,
9,
267,
1817,
14,
525,
792,
360,
5645,
15731,
297,
2919,
9,
267,
1817,
14,
525,
792,
360,
14348,
297,
5353,
9,
267,
1817,
14,
525,
792,
360,
466,
2891,
297,
5353,
9,
267,
1817,
14,
525,
12190,
360,
5645,
804,
297,
510,
456,
804,
9,
267,
1817,
14,
525,
12190,
360,
2502,
297,
5949,
9,
267,
1817,
14,
525,
12190,
360,
4159,
297,
5987,
14,
8493,
9,
267,
327,
1224,
14,
525,
792,
360,
4159,
297,
7442,
9,
267,
1817,
14,
525,
792,
360,
633,
297,
2632,
9,
199,
199,
533,
1684,
1298,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
27283,
199,
199,
533,
510,
456,
804,
8,
34,
902,
5810,
304,
272,
32652,
628,
18060,
4100,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
1817,
14,
525,
792,
360,
344,
297,
5353,
9,
267,
699,
902,
5810,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
792,
360,
466,
2891,
4793,
297,
5353,
9,
267,
1817,
14,
525,
34,
902,
792,
360,
5645,
2891,
4314,
297,
5353,
9,
268,
199,
533,
510,
456,
4100,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
18060,
804,
199,
199,
533,
32166,
8,
3987,
5810,
304,
272,
32652,
628,
6105,
2932,
2,
272,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
12178,
5810,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
792,
360,
344,
297,
1092,
9845,
9,
267,
1817,
14,
525,
34,
902,
792,
360,
354,
297,
5353,
9,
267,
327,
1224,
14,
525,
12190,
360,
4159,
297,
8493,
9,
267,
1817,
14,
525,
792,
360,
271,
1129,
89,
297,
5353,
9,
267,
1817,
14,
525,
792,
360,
67,
2033,
297,
5353,
9,
267,
1817,
14,
525,
792,
360,
68,
23120,
297,
2632,
9,
267,
1817,
14,
525,
792,
360,
13961,
297,
2632,
9,
267,
1817,
14,
525,
34,
902,
792,
360,
633,
297,
2632,
9,
2728,
327,
1224,
14,
525,
2768,
360,
4129,
297,
2,
354,
1166,
1613,
4978,
531,
5493,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
1362,
199,
533,
14132,
2932,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
12157,
272,
2763,
5866,
628,
354,
1166,
1613,
4978,
2,
421,
199,
533,
6529,
8,
7344,
304,
272,
32652,
628,
2817,
1384,
2,
2286,
347,
4205,
3186,
8,
277,
12,
1224,
304,
267,
8028,
14,
826,
3186,
8,
277,
12,
1224,
9,
267,
1817,
14,
525,
8064,
360,
14005,
2175,
5949,
297,
12838,
2584,
2502,
358,
1362,
199,
309,
258,
347,
9344,
2175,
5949,
8,
277,
19166,
589,
12663,
829,
304,
199,
309,
260,
4775,
459,
2502,
13784,
277,
199,
309,
260,
372,
291,
14,
5506,
8,
12838,
19166,
589,
12663,
829,
9,
199,
199,
533,
6642,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
5949,
1362,
421,
199,
533,
510,
456,
5949,
8,
3834,
316,
5810,
304,
272,
32652,
628,
18060,
2817,
1384,
2,
272,
687,
2543,
29,
27283,
272,
370,
2543,
29,
5949,
1362,
199,
309,
258,
347,
636,
826,
721,
277,
12,
1708,
12663,
829,
304,
199,
309,
260,
10967,
316,
5810,
855,
826,
721,
277,
12,
1708,
12,
27283,
12,
5949,
12663,
829,
9,
1362,
199,
533,
510,
456,
2817,
1384,
7457,
8,
1451,
7457,
304,
272,
12690,
3186,
29,
18060,
5949,
1362,
421,
199,
533,
6529,
2390,
8,
34,
902,
5810,
304,
272,
298,
29229,
12,
487,
80,
320,
77,
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,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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
] |
benchisell/curate_flask_appengine
|
lib/flask/testsuite/subclassing.py
|
563
|
1214
|
# -*- coding: utf-8 -*-
"""
flask.testsuite.subclassing
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Test that certain behavior of flask can be customized by
subclasses.
:copyright: (c) 2011 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
import flask
import unittest
from logging import StreamHandler
from flask.testsuite import FlaskTestCase
from flask._compat import StringIO
class FlaskSubclassingTestCase(FlaskTestCase):
def test_suppressed_exception_logging(self):
class SuppressedFlask(flask.Flask):
def log_exception(self, exc_info):
pass
out = StringIO()
app = SuppressedFlask(__name__)
app.logger_name = 'flask_tests/test_suppressed_exception_logging'
app.logger.addHandler(StreamHandler(out))
@app.route('/')
def index():
1 // 0
rv = app.test_client().get('/')
self.assert_equal(rv.status_code, 500)
self.assert_in(b'Internal Server Error', rv.data)
err = out.getvalue()
self.assert_equal(err, '')
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(FlaskSubclassingTestCase))
return suite
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
14,
14239,
14,
27904,
272,
18294,
4919,
23597,
339,
1379,
626,
9842,
5953,
402,
7209,
883,
506,
26707,
701,
272,
9180,
14,
339,
520,
7307,
26,
334,
67,
9,
7760,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
7209,
199,
646,
2882,
199,
504,
2050,
492,
8271,
2461,
199,
504,
7209,
14,
14239,
492,
16704,
1746,
199,
504,
7209,
423,
5819,
492,
5228,
421,
199,
533,
16704,
23636,
316,
1746,
8,
14182,
1746,
304,
339,
347,
511,
63,
8621,
5111,
63,
1971,
63,
4806,
8,
277,
304,
267,
1021,
29083,
5111,
14182,
8,
15720,
14,
14182,
304,
288,
347,
943,
63,
1971,
8,
277,
12,
3178,
63,
815,
304,
355,
986,
398,
734,
275,
5228,
342,
267,
1145,
275,
29083,
5111,
14182,
3460,
354,
3368,
267,
1145,
14,
2921,
63,
354,
275,
283,
15720,
63,
2219,
15,
396,
63,
8621,
5111,
63,
1971,
63,
4806,
7,
267,
1145,
14,
2921,
14,
18826,
8,
22482,
8,
548,
430,
398,
768,
571,
14,
4449,
7825,
267,
347,
1478,
837,
288,
413,
5001,
378,
398,
4336,
275,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
291,
14,
479,
63,
1452,
8,
6310,
14,
1205,
63,
600,
12,
6891,
9,
267,
291,
14,
479,
63,
262,
8,
66,
7,
8405,
7146,
4520,
297,
4336,
14,
576,
9,
398,
2329,
275,
734,
14,
7150,
342,
267,
291,
14,
479,
63,
1452,
8,
1508,
12,
4074,
421,
199,
318,
5241,
837,
272,
5241,
275,
2882,
14,
10591,
342,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
14182,
23636,
316,
1746,
430,
272,
372,
5241,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
7209,
14,
14239,
14,
27904,
272,
18294,
4919,
23597,
339,
1379,
626,
9842,
5953,
402,
7209,
883,
506,
26707,
701,
272,
9180,
14,
339,
520,
7307,
26,
334,
67,
9,
7760,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
646,
7209,
199,
646,
2882,
199,
504,
2050,
492,
8271,
2461,
199,
504,
7209,
14,
14239,
492,
16704,
1746,
199,
504,
7209,
423,
5819,
492,
5228,
421,
199,
533,
16704,
23636,
316,
1746,
8,
14182,
1746,
304,
339,
347,
511,
63,
8621,
5111,
63,
1971,
63,
4806,
8,
277,
304,
267,
1021,
29083,
5111,
14182,
8,
15720,
14,
14182,
304,
288,
347,
943,
63,
1971,
8,
277,
12,
3178,
63,
815,
304,
355,
986,
398,
734,
275,
5228,
342,
267,
1145,
275,
29083,
5111,
14182,
3460,
354,
3368,
267,
1145,
14,
2921,
63,
354,
275,
283,
15720,
63,
2219,
15,
396,
63,
8621,
5111,
63,
1971,
63,
4806,
7,
267,
1145,
14,
2921,
14,
18826,
8,
22482,
8,
548,
430,
398,
768,
571,
14,
4449,
7825,
267,
347,
1478,
837,
288,
413,
5001,
378,
398,
4336,
275,
1145,
14,
396,
63,
1258,
1252,
362,
7825,
267,
291,
14,
479,
63,
1452,
8,
6310,
14,
1205,
63,
600,
12,
6891,
9,
267,
291,
14,
479,
63,
262,
8,
66,
7,
8405,
7146,
4520,
297,
4336,
14,
576,
9,
398,
2329,
275,
734,
14,
7150,
342,
267,
291,
14,
479,
63,
1452,
8,
1508,
12,
4074,
421,
199,
318,
5241,
837,
272,
5241,
275,
2882,
14,
10591,
342,
272,
5241,
14,
15714,
8,
2796,
14,
18275,
8,
14182,
23636,
316,
1746,
430,
272,
372,
5241,
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,
32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
0,
0,
0,
0,
0,
0,
0
] |
sunny-wyb/xen-4.1.2
|
dist/install/usr/lib/python2.7/site-packages/xen/web/httpserver.py
|
49
|
10765
|
#============================================================================
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
# Copyright (C) 2006 XenSource Ltd.
#============================================================================
import threading
import string
import socket
import types
from urllib import quote, unquote
import os
import os.path
import fcntl
from xen.xend import sxp
from xen.xend.Args import ArgError
from xen.xend.XendError import XendError
import http
import unix
from resource import Resource, ErrorPage
from SrvDir import SrvDir
class ThreadRequest:
"""A request to complete processing using a thread.
"""
def __init__(self, processor, req, fn, args, kwds):
self.processor = processor
self.req = req
self.fn = fn
self.args = args
self.kwds = kwds
def run(self):
self.processor.setInThread()
thread = threading.Thread(target=self.main)
thread.setDaemon(True)
thread.start()
def call(self):
try:
self.fn(*self.args, **self.kwds)
except SystemExit:
raise
except Exception, ex:
self.req.resultErr(ex)
self.req.finish()
def main(self):
self.call()
self.processor.process()
class RequestProcessor:
"""Processor for requests on a connection to an http server.
Requests are executed synchonously unless they ask for a thread by returning
a ThreadRequest.
"""
done = False
inThread = False
def __init__(self, server, sock, addr):
self.server = server
self.sock = sock
self.srd = sock.makefile('rb')
self.srw = sock.makefile('wb')
self.srvaddr = server.getServerAddr()
def isInThread(self):
return self.inThread
def setInThread(self):
self.inThread = True
def getServer(self):
return self.server
def getRequest(self):
return HttpServerRequest(self, self.srvaddr, self.srd, self.srw)
def close(self):
try:
self.sock.close()
except:
pass
def finish(self):
self.done = True
self.close()
def process(self):
while not self.done:
req = self.getRequest()
res = req.process()
if isinstance(res, ThreadRequest):
if self.isInThread():
res.call()
else:
res.run()
break
else:
req.finish()
class HttpServerRequest(http.HttpRequest):
"""A single request to an http server.
"""
def __init__(self, processor, addr, srd, srw):
self.processor = processor
self.prepath = ''
http.HttpRequest.__init__(self, addr, srd, srw)
def getServer(self):
return self.processor.getServer()
def process(self):
"""Process the request. If the return value is a ThreadRequest
it is evaluated in a thread.
"""
try:
self.prepath = []
self.postpath = map(unquote, string.split(self.request_path[1:], '/'))
resource = self.getResource()
return self.render(resource)
except SystemExit:
raise
except Exception, ex:
self.processError(ex)
def processError(self, ex):
import traceback; traceback.print_exc()
self.sendError(http.INTERNAL_SERVER_ERROR, msg=str(ex))
self.setCloseConnection('close')
def finish(self):
self.sendResponse()
if self.close_connection:
self.processor.finish()
def prePathURL(self):
url_host = self.getRequestHostname()
port = self.getPort()
if self.isSecure():
url_proto = "https"
default_port = 443
else:
url_proto = "http"
default_port = 80
if port != default_port:
url_host += (':%d' % port)
url_path = quote(string.join(self.prepath, '/'))
return ('%s://%s/%s' % (url_proto, url_host, url_path))
def getResource(self):
return self.getServer().getResource(self)
def render(self, resource):
val = None
if resource is None:
self.sendError(http.NOT_FOUND)
else:
try:
while True:
val = resource.render(self)
if not isinstance(val, Resource):
break
val = self.result(val)
except SystemExit:
raise
except Exception, ex:
self.resultErr(ex)
return val
def threadRequest(self, _fn, *_args, **_kwds):
"""Create a request to finish request processing in a thread.
Use this to create a ThreadRequest to return from rendering a
resource if you need a thread to complete processing.
"""
return ThreadRequest(self.processor, self, _fn, _args, _kwds)
def result(self, val):
if isinstance(val, Exception):
return self.resultErr(val)
else:
return self.resultVal(val)
def resultVal(self, val):
"""Callback to complete the request.
@param val: the value
"""
if val is None:
return val
elif isinstance(val, ThreadRequest):
return val
elif self.useSxp():
self.setHeader("Content-Type", sxp.mime_type)
sxp.show(val, out=self)
else:
self.write('<html><head></head><body>')
self.printPath()
if isinstance(val, types.ListType):
self.write('<code><pre>')
PrettyPrint.prettyprint(val, out=self)
self.write('</pre></code>')
else:
self.write(str(val))
self.write('</body></html>')
return None
def resultErr(self, err):
"""Error callback to complete a request.
@param err: the error
"""
if not isinstance(err, (ArgError, sxp.ParseError, XendError)):
raise
#log.exception("op=%s: %s", op, str(err))
if self.useSxp():
self.setHeader("Content-Type", sxp.mime_type)
sxp.show(['xend.err', str(err)], out=self)
else:
self.setHeader("Content-Type", "text/plain")
self.write('Error ')
self.write(': ')
self.write(str(err))
return None
def useSxp(self):
"""Determine whether to send an SXP response to a request.
Uses SXP if there is no User-Agent, no Accept, or application/sxp is in Accept.
returns 1 for SXP, 0 otherwise
"""
ok = 0
user_agent = self.getHeader('User-Agent')
accept = self.getHeader('Accept')
if (not user_agent) or (not accept) or (accept.find(sxp.mime_type) >= 0):
ok = 1
return ok
def printPath(self):
pathlist = [x for x in self.prepath if x != '' ]
s = "/"
self.write('<h1><a href="/">/</a>')
for x in pathlist:
s += x + "/"
self.write(' <a href="%s">%s</a>/' % (s, x))
self.write("</h1>")
class HttpServerClient:
def __init__(self, server, sock, addr):
self.server = server
self.sock = sock
self.addr = addr
def process(self):
thread = threading.Thread(target=self.doProcess)
thread.setDaemon(True)
thread.start()
def doProcess(self):
try:
rp = RequestProcessor(self.server, self.sock, self.addr)
rp.process()
except SystemExit:
raise
except Exception, ex:
print 'HttpServer>processRequest> exception: ', ex
try:
self.sock.close()
except:
pass
class HttpServer:
backlog = 5
def __init__(self, root, interface, port=8080):
self.root = root
self.interface = interface
self.port = port
# ready indicates when we are ready to begin accept connections
# it should be set after a successful bind
self.ready = False
self.closed = False
def run(self):
self.bind()
self.listen()
self.ready = True
while not self.closed:
(sock, addr) = self.accept()
cl = HttpServerClient(self, sock, addr)
cl.process()
def stop(self):
self.close()
def bind(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
flags = fcntl.fcntl(self.socket.fileno(), fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(self.socket.fileno(), fcntl.F_SETFD, flags)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind((self.interface, self.port))
def listen(self):
self.socket.listen(self.backlog)
def accept(self):
return self.socket.accept()
def close(self):
self.closed = True
self.ready = False
# shutdown socket explicitly to allow reuse
try:
self.socket.shutdown(2)
except socket.error:
pass
try:
self.socket.close()
except socket.error:
pass
def getServerAddr(self):
return (socket.gethostname(), self.port)
def getResource(self, req):
return self.root.getRequestResource(req)
def shutdown(self):
self.close()
class UnixHttpServer(HttpServer):
def __init__(self, root, path):
HttpServer.__init__(self, root, 'localhost')
self.path = path
def bind(self):
self.socket = unix.bind(self.path)
flags = fcntl.fcntl(self.socket.fileno(), fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(self.socket.fileno(), fcntl.F_SETFD, flags)
|
gpl-2.0
|
[
14813,
5769,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
1015,
499,
14,
17,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
14813,
5769,
199,
3,
1898,
334,
35,
9,
11811,
603,
7455,
644,
803,
665,
2664,
415,
14,
87,
803,
32,
12025,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
8315,
30211,
2980,
12126,
14,
199,
14813,
5769,
199,
199,
646,
5796,
199,
199,
646,
1059,
199,
646,
2838,
199,
646,
2943,
199,
504,
4011,
492,
6313,
12,
14342,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
12871,
199,
199,
504,
20388,
14,
88,
500,
492,
308,
9290,
199,
504,
20388,
14,
88,
500,
14,
6213,
492,
29560,
547,
199,
504,
20388,
14,
88,
500,
14,
56,
500,
547,
492,
31314,
547,
199,
199,
646,
1455,
199,
646,
16572,
199,
504,
2073,
492,
7337,
12,
4520,
3276,
199,
504,
428,
6310,
3567,
492,
428,
6310,
3567,
199,
199,
533,
11086,
2017,
26,
272,
408,
33,
1056,
370,
4890,
6661,
1808,
282,
2462,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
12,
12495,
12,
2648,
12,
4325,
12,
1249,
12,
16286,
304,
267,
291,
14,
6459,
275,
12495,
267,
291,
14,
2103,
275,
2648,
267,
291,
14,
2324,
275,
4325,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
10340,
275,
16286,
5493,
347,
1255,
8,
277,
304,
267,
291,
14,
6459,
14,
409,
607,
4436,
342,
267,
2462,
275,
5796,
14,
4436,
8,
1375,
29,
277,
14,
973,
9,
267,
2462,
14,
409,
20555,
8,
549,
9,
267,
2462,
14,
928,
342,
339,
347,
1240,
8,
277,
304,
267,
862,
26,
288,
291,
14,
2324,
2031,
277,
14,
589,
12,
1011,
277,
14,
10340,
9,
267,
871,
14838,
26,
288,
746,
267,
871,
2186,
12,
444,
26,
288,
291,
14,
2103,
14,
1099,
5432,
8,
476,
9,
267,
291,
14,
2103,
14,
8192,
342,
339,
347,
2446,
8,
277,
304,
267,
291,
14,
1250,
342,
267,
291,
14,
6459,
14,
1412,
342,
267,
199,
199,
533,
4784,
10438,
26,
272,
408,
10438,
367,
4145,
641,
282,
1950,
370,
376,
1455,
1654,
14,
272,
20260,
787,
7934,
308,
5654,
265,
1785,
590,
7444,
2985,
7198,
367,
282,
2462,
701,
8152,
272,
282,
11086,
2017,
14,
272,
408,
339,
4224,
275,
756,
339,
315,
4436,
275,
756,
339,
347,
636,
826,
721,
277,
12,
1654,
12,
6771,
12,
5552,
304,
267,
291,
14,
1000,
275,
1654,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
5474,
68,
275,
6771,
14,
13941,
360,
4848,
358,
267,
291,
14,
5474,
87,
275,
6771,
14,
13941,
360,
6603,
358,
267,
291,
14,
15165,
2697,
275,
1654,
14,
362,
3120,
11404,
342,
339,
347,
365,
607,
4436,
8,
277,
304,
267,
372,
291,
14,
262,
4436,
339,
347,
663,
607,
4436,
8,
277,
304,
267,
291,
14,
262,
4436,
275,
715,
339,
347,
664,
3120,
8,
277,
304,
267,
372,
291,
14,
1000,
339,
347,
664,
2017,
8,
277,
304,
267,
372,
4760,
3120,
2017,
8,
277,
12,
291,
14,
15165,
2697,
12,
291,
14,
5474,
68,
12,
291,
14,
5474,
87,
9,
339,
347,
4002,
8,
277,
304,
267,
862,
26,
288,
291,
14,
5096,
14,
1600,
342,
267,
871,
26,
288,
986,
339,
347,
9578,
8,
277,
304,
267,
291,
14,
4456,
275,
715,
267,
291,
14,
1600,
342,
339,
347,
2112,
8,
277,
304,
267,
1830,
440,
291,
14,
4456,
26,
288,
2648,
275,
291,
14,
362,
2017,
342,
288,
522,
275,
2648,
14,
1412,
342,
288,
340,
1228,
8,
470,
12,
11086,
2017,
304,
355,
340,
291,
14,
374,
607,
4436,
837,
490,
522,
14,
1250,
342,
355,
587,
26,
490,
522,
14,
1065,
342,
490,
2059,
288,
587,
26,
355,
2648,
14,
8192,
342,
1460,
199,
533,
4760,
3120,
2017,
8,
1014,
14,
10441,
304,
272,
408,
33,
2849,
1056,
370,
376,
1455,
1654,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
12495,
12,
5552,
12,
308,
6883,
12,
11483,
87,
304,
267,
291,
14,
6459,
275,
12495,
267,
291,
14,
657,
515,
275,
2125,
267,
1455,
14,
10441,
855,
826,
721,
277,
12,
5552,
12,
308,
6883,
12,
11483,
87,
9,
339,
347,
664,
3120,
8,
277,
304,
267,
372,
291,
14,
6459,
14,
362,
3120,
342,
339,
347,
2112,
8,
277,
304,
267,
408,
3498,
314,
1056,
14,
982,
314,
372,
574,
365,
282,
11086,
2017,
267,
652,
365,
13006,
315,
282,
2462,
14,
267,
408,
267,
862,
26,
288,
291,
14,
657,
515,
275,
942,
288,
291,
14,
1932,
515,
275,
2341,
8,
12240,
12,
1059,
14,
1294,
8,
277,
14,
1069,
63,
515,
59,
17,
8429,
1994,
1333,
288,
2073,
275,
291,
14,
362,
4031,
342,
288,
372,
291,
14,
3352,
8,
1927,
9,
267,
871,
14838,
26,
288,
746,
267,
871,
2186,
12,
444,
26,
288,
291,
14,
1412,
547,
8,
476,
9,
339,
347,
2112,
547,
8,
277,
12,
444,
304,
267,
492,
5190,
27,
5190,
14,
1361,
63,
2804,
342,
267,
291,
14,
2254,
547,
8,
1014,
14,
17681,
63,
6613,
63,
3170,
12,
1499,
29,
495,
8,
476,
430,
267,
291,
14,
409,
4724,
3225,
360,
1600,
358,
339,
347,
9578,
8,
277,
304,
267,
291,
14,
2254,
2364,
342,
267,
340,
291,
14,
1600,
63,
2105,
26,
288,
291,
14,
6459,
14,
8192,
342,
339,
347,
876,
2042,
2632,
8,
277,
304,
267,
1166,
63,
1102
] |
[
5769,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
1015,
499,
14,
17,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
14813,
5769,
199,
3,
1898,
334,
35,
9,
11811,
603,
7455,
644,
803,
665,
2664,
415,
14,
87,
803,
32,
12025,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
8315,
30211,
2980,
12126,
14,
199,
14813,
5769,
199,
199,
646,
5796,
199,
199,
646,
1059,
199,
646,
2838,
199,
646,
2943,
199,
504,
4011,
492,
6313,
12,
14342,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
12871,
199,
199,
504,
20388,
14,
88,
500,
492,
308,
9290,
199,
504,
20388,
14,
88,
500,
14,
6213,
492,
29560,
547,
199,
504,
20388,
14,
88,
500,
14,
56,
500,
547,
492,
31314,
547,
199,
199,
646,
1455,
199,
646,
16572,
199,
504,
2073,
492,
7337,
12,
4520,
3276,
199,
504,
428,
6310,
3567,
492,
428,
6310,
3567,
199,
199,
533,
11086,
2017,
26,
272,
408,
33,
1056,
370,
4890,
6661,
1808,
282,
2462,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
12,
12495,
12,
2648,
12,
4325,
12,
1249,
12,
16286,
304,
267,
291,
14,
6459,
275,
12495,
267,
291,
14,
2103,
275,
2648,
267,
291,
14,
2324,
275,
4325,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
10340,
275,
16286,
5493,
347,
1255,
8,
277,
304,
267,
291,
14,
6459,
14,
409,
607,
4436,
342,
267,
2462,
275,
5796,
14,
4436,
8,
1375,
29,
277,
14,
973,
9,
267,
2462,
14,
409,
20555,
8,
549,
9,
267,
2462,
14,
928,
342,
339,
347,
1240,
8,
277,
304,
267,
862,
26,
288,
291,
14,
2324,
2031,
277,
14,
589,
12,
1011,
277,
14,
10340,
9,
267,
871,
14838,
26,
288,
746,
267,
871,
2186,
12,
444,
26,
288,
291,
14,
2103,
14,
1099,
5432,
8,
476,
9,
267,
291,
14,
2103,
14,
8192,
342,
339,
347,
2446,
8,
277,
304,
267,
291,
14,
1250,
342,
267,
291,
14,
6459,
14,
1412,
342,
267,
199,
199,
533,
4784,
10438,
26,
272,
408,
10438,
367,
4145,
641,
282,
1950,
370,
376,
1455,
1654,
14,
272,
20260,
787,
7934,
308,
5654,
265,
1785,
590,
7444,
2985,
7198,
367,
282,
2462,
701,
8152,
272,
282,
11086,
2017,
14,
272,
408,
339,
4224,
275,
756,
339,
315,
4436,
275,
756,
339,
347,
636,
826,
721,
277,
12,
1654,
12,
6771,
12,
5552,
304,
267,
291,
14,
1000,
275,
1654,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
5474,
68,
275,
6771,
14,
13941,
360,
4848,
358,
267,
291,
14,
5474,
87,
275,
6771,
14,
13941,
360,
6603,
358,
267,
291,
14,
15165,
2697,
275,
1654,
14,
362,
3120,
11404,
342,
339,
347,
365,
607,
4436,
8,
277,
304,
267,
372,
291,
14,
262,
4436,
339,
347,
663,
607,
4436,
8,
277,
304,
267,
291,
14,
262,
4436,
275,
715,
339,
347,
664,
3120,
8,
277,
304,
267,
372,
291,
14,
1000,
339,
347,
664,
2017,
8,
277,
304,
267,
372,
4760,
3120,
2017,
8,
277,
12,
291,
14,
15165,
2697,
12,
291,
14,
5474,
68,
12,
291,
14,
5474,
87,
9,
339,
347,
4002,
8,
277,
304,
267,
862,
26,
288,
291,
14,
5096,
14,
1600,
342,
267,
871,
26,
288,
986,
339,
347,
9578,
8,
277,
304,
267,
291,
14,
4456,
275,
715,
267,
291,
14,
1600,
342,
339,
347,
2112,
8,
277,
304,
267,
1830,
440,
291,
14,
4456,
26,
288,
2648,
275,
291,
14,
362,
2017,
342,
288,
522,
275,
2648,
14,
1412,
342,
288,
340,
1228,
8,
470,
12,
11086,
2017,
304,
355,
340,
291,
14,
374,
607,
4436,
837,
490,
522,
14,
1250,
342,
355,
587,
26,
490,
522,
14,
1065,
342,
490,
2059,
288,
587,
26,
355,
2648,
14,
8192,
342,
1460,
199,
533,
4760,
3120,
2017,
8,
1014,
14,
10441,
304,
272,
408,
33,
2849,
1056,
370,
376,
1455,
1654,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
12495,
12,
5552,
12,
308,
6883,
12,
11483,
87,
304,
267,
291,
14,
6459,
275,
12495,
267,
291,
14,
657,
515,
275,
2125,
267,
1455,
14,
10441,
855,
826,
721,
277,
12,
5552,
12,
308,
6883,
12,
11483,
87,
9,
339,
347,
664,
3120,
8,
277,
304,
267,
372,
291,
14,
6459,
14,
362,
3120,
342,
339,
347,
2112,
8,
277,
304,
267,
408,
3498,
314,
1056,
14,
982,
314,
372,
574,
365,
282,
11086,
2017,
267,
652,
365,
13006,
315,
282,
2462,
14,
267,
408,
267,
862,
26,
288,
291,
14,
657,
515,
275,
942,
288,
291,
14,
1932,
515,
275,
2341,
8,
12240,
12,
1059,
14,
1294,
8,
277,
14,
1069,
63,
515,
59,
17,
8429,
1994,
1333,
288,
2073,
275,
291,
14,
362,
4031,
342,
288,
372,
291,
14,
3352,
8,
1927,
9,
267,
871,
14838,
26,
288,
746,
267,
871,
2186,
12,
444,
26,
288,
291,
14,
1412,
547,
8,
476,
9,
339,
347,
2112,
547,
8,
277,
12,
444,
304,
267,
492,
5190,
27,
5190,
14,
1361,
63,
2804,
342,
267,
291,
14,
2254,
547,
8,
1014,
14,
17681,
63,
6613,
63,
3170,
12,
1499,
29,
495,
8,
476,
430,
267,
291,
14,
409,
4724,
3225,
360,
1600,
358,
339,
347,
9578,
8,
277,
304,
267,
291,
14,
2254,
2364,
342,
267,
340,
291,
14,
1600,
63,
2105,
26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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
] |
donyfeng/httpac
|
httpac.py
|
1
|
4588
|
#!/usr/bin/env python
import urllib.request
import urllib.parse
import http.cookiejar
import re
import time
import json
caller_url = "http://caller.ap01.aws.af.cm"
tieba_url = "http://tieba.baidu.com"
token_url = "https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=1385610373352&class=login&logintype=dialogLogin&callback=bd__cbs__rh1uhg"
login_url = "https://passport.baidu.com/v2/api/?login"
user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
user_name = "winden@yeah.net"
password = "185400ab"
sign_url = "http://tieba.baidu.com/mo/q/sign"
def ReadCookie(cookie_file):
try:
cj = http.cookiejar.MozillaCookieJar(cookie_file)
cj.load()
except:
fp = open(cookie_file,'w')
fp.write("")
fp.close
cj = http.cookiejar.MozillaCookieJar(cookie_file)
return cj
def BuildOpener(cj):
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
return opener
def BuildReq(url):
req = urllib.request.Request(url)
req.add_header('User-Agent',user_agent)
return req
def BuildPostdata(user_name,password,token):
postdata = {
"username" : user_name,
"password" : password,
"staticpage" : "http://www.baidu.com/cache/user/html/v3Jump.html",
"charset" : "UTF-8",
"token" : token,
"tpl" : "mn",
"apiver" : "v3",
"tt" : "1385610476365",
"safeflg" : "0",
"u" : tieba_url,
"isPhone" : "false",
"quick_user" : "0",
"logintype" : "dialogLogin",
"splogin" : "rate",
"verifycode" : "",
"mem_pass" : "on",
"ppui_logintime" : "103013",
"callback" : "parent.bd__pcbs__an5hr1",
"connection" : "keep-alive"
}
postdata = urllib.parse.urlencode(postdata)
postdata = postdata.encode('utf-8')
return postdata
def FindFavTieba(data):
data = data.decode('utf-8')
fav_tiebas = re.findall('<a class="j_forumTile_wrapper forumTile_wrapper" href="(.+?)&',data)
return fav_tiebas
def FindTbs(data):
data = data.decode('utf-8')
try:
tbs = re.findall('"tbs" : "(\w+)"',data)[0]
kw = re.findall('"kw" : "(.+?)"',data)[0]
fid = re.findall('"fid" : "(\d+)"',data)[0]
except:
tbs = ''
kw = ''
fid = ''
signdata = {
'tbs': tbs,
'is_like' : 1,
'fid' : fid
}
signdata = urllib.parse.urlencode(signdata)
signdata = '?kw='+kw+'&'+signdata
return signdata
def SignTieba(fav_tiebas):
for fav_tieba in fav_tiebas:
req = BuildReq(urllib.parse.urljoin(tieba_url,fav_tieba))
data = opener.open(req).read()
postdata = FindTbs(data)
url = urllib.parse.urljoin(sign_url,postdata)
req = BuildReq(url)
data = opener.open(req).read()
resp = json.loads(data.decode('utf-8'))
try:
if not resp:
print('Error: NO TBS')
elif resp['error'] != '':
print('Error:' + resp['error'])
else:
print('Signed')
except:
print('can not display!')
fp.write(data)
time.sleep(2)
if __name__ == "__main__":
while(1):
print(time.strftime("%Y-%m-%d %A %X",time.localtime()))
for line in open('users.txt'):
user_name = line.split(':')[0]
password = line.split(':')[1]
fp = open("1.html",'wb')
cookie_file = 'cookie.'+user_name+'.txt'
cj = ReadCookie(cookie_file)
opener = BuildOpener(cj)
req = BuildReq(tieba_url)
data = opener.open(req)
req = BuildReq(token_url)
data = opener.open(req).read()
token = re.findall('"token" : "(\w+)"',data.decode('utf-8'))[0]
postdata = BuildPostdata(user_name,password,token)
req = BuildReq(login_url)
data = opener.open(req,postdata)
cj.save()
req = BuildReq(tieba_url)
data = opener.open(req).read()
fav_tiebas = FindFavTieba(data)
if fav_tiebas:
print('%s logined!'%user_name)
else:
print("%s can't login!"%user_name)
SignTieba(fav_tiebas)
time.sleep(3600*4)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
202,
199,
646,
4011,
14,
1069,
202,
199,
646,
4011,
14,
1122,
202,
199,
646,
1455,
14,
30552,
202,
199,
646,
295,
202,
199,
646,
900,
202,
199,
646,
2022,
2999,
199,
11219,
63,
633,
275,
298,
1014,
921,
11219,
14,
439,
614,
14,
7231,
14,
2756,
14,
4400,
2,
202,
199,
23958,
2470,
63,
633,
275,
298,
1014,
921,
23958,
2470,
14,
2470,
344,
85,
14,
957,
2,
202,
199,
1418,
63,
633,
275,
298,
2859,
921,
1529,
719,
14,
2470,
344,
85,
14,
957,
15,
86,
18,
15,
1246,
10197,
362,
1246,
6,
15436,
29,
10344,
6,
1246,
422,
29,
86,
19,
6,
6215,
29,
8527,
1367,
709,
1401,
1153,
2528,
6,
533,
29,
2886,
6,
2886,
466,
29,
7196,
8880,
6,
3058,
29,
3691,
363,
67,
1533,
363,
17157,
17,
85,
9208,
2,
202,
199,
2886,
63,
633,
275,
298,
2859,
921,
1529,
719,
14,
2470,
344,
85,
14,
957,
15,
86,
18,
15,
1246,
10197,
2886,
2,
202,
199,
751,
63,
4054,
275,
298,
22285,
15,
21,
14,
16,
334,
73,
15199,
27,
11952,
284,
15199,
4403,
1227,
63,
16,
2839,
10444,
4403,
1323,
9,
21257,
21666,
15,
25839,
14,
1479,
334,
43,
4943,
12,
2839,
30506,
9,
3394,
15,
22,
14,
16,
29724,
15,
709,
33,
21,
11452,
69,
428,
2756,
759,
15,
2426,
1344,
14,
821,
2,
202,
199,
751,
63,
354,
275,
298,
2676,
848,
32,
89,
4489,
72,
14,
846,
2,
202,
199,
2060,
275,
298,
1085,
1477,
383,
371,
2,
202,
199,
1037,
63,
633,
275,
298,
1014,
921,
23958,
2470,
14,
2470,
344,
85,
14,
957,
15,
573,
15,
81,
15,
1037,
2,
2999,
199,
318,
5574,
7810,
8,
5306,
63,
493,
304,
1128,
862,
26,
1039,
286,
74,
275,
1455,
14,
30552,
14,
22285,
21315,
8,
5306,
63,
493,
9,
1039,
286,
74,
14,
912,
342,
1128,
871,
26,
1039,
4090,
275,
1551,
8,
5306,
63,
493,
2584,
87,
358,
1039,
4090,
14,
952,
10804,
1039,
4090,
14,
1600,
1039,
286,
74,
275,
1455,
14,
30552,
14,
22285,
21315,
8,
5306,
63,
493,
9,
1128,
372,
286,
74,
2999,
199,
318,
6516,
29993,
8,
24862,
304,
1128,
16088,
275,
4011,
14,
1069,
14,
1506,
63,
11637,
8,
4078,
14,
1069,
14,
2856,
7810,
10438,
8,
24862,
430,
1128,
372,
16088,
2999,
199,
318,
6516,
11981,
8,
633,
304,
1128,
2648,
275,
4011,
14,
1069,
14,
2017,
8,
633,
9,
1128,
2648,
14,
525,
63,
1291,
360,
1899,
13,
7788,
297,
751,
63,
4054,
9,
1128,
372,
2648,
2999,
199,
318,
6516,
6564,
576,
8,
751,
63,
354,
12,
2060,
12,
1418,
304,
1128,
2963,
576,
275,
469,
1039,
298,
2473,
2,
520,
922,
63,
354,
12,
1039,
298,
2060,
2,
520,
2505,
12,
1039,
298,
1986,
1606,
2,
520,
298,
1014,
921,
1544,
14,
2470,
344,
85,
14,
957,
15,
1637,
15,
751,
15,
1360,
15,
86,
19,
42,
1220,
14,
1360,
401,
1039,
298,
6043,
2,
520,
298,
6610,
13,
24,
401,
1039,
298,
1418,
2,
520,
1526,
12,
1039,
298,
15436,
2,
520,
298,
10344,
401,
1039,
298,
1246,
422,
2,
520,
298,
86,
19,
401,
1039,
298,
6215,
2,
520,
298,
8527,
1367,
6785,
2114,
12664,
401,
1039,
298,
3489,
2327,
71,
2,
520,
298,
16,
401,
1039,
298,
85,
2,
520,
3367,
69,
2470,
63,
633,
12,
1039,
298,
374,
15199,
2,
520,
298,
3910,
401,
1039,
298,
13239,
63,
751,
2,
520,
298,
16,
401,
1039,
298,
2886,
466,
2,
520,
298,
7196,
8880,
401,
1039,
298,
681,
2886,
2,
520,
298,
1866,
401,
1039,
298,
4712,
600,
2,
520,
4873,
1039,
298,
5286,
63,
1529,
2,
520,
298,
265,
401,
1039,
298,
802,
1907,
63,
2886,
521,
2,
520,
298,
709,
8507,
19,
401,
1039,
298,
3058,
2,
520,
298,
1708,
14,
3691,
363,
2352,
1533,
363,
290,
21,
6271,
17,
401,
1039,
298,
2105,
2,
520,
298,
3250,
13,
9631,
2,
1128,
789,
1128,
2963,
576,
275,
4011,
14,
1122,
14,
10738,
8,
1932,
576,
9,
1128,
2963,
576,
275,
2963,
576,
14,
2143,
360,
1624,
13,
24,
358,
1128,
372,
2963,
576,
2999,
199,
318,
6668,
38,
1214,
52,
1873,
2470,
8,
576,
304,
1128,
666,
275,
666,
14,
2708,
360,
1624,
13,
24,
358,
1128,
289,
1214,
63,
280,
2871,
305,
275,
295,
14,
6452,
4827,
65,
1021,
628,
74,
63,
10044,
29746,
63,
5029,
21575,
29746,
63,
5029,
2,
4369,
628,
28149,
9,
6,
5282,
297,
576,
9,
1128,
372,
289,
1214,
63,
280,
2871,
305,
2999,
199,
318,
6668,
52,
1533,
8,
576,
304,
1128,
666,
275,
666,
14,
2708,
360,
1624,
13,
24,
358,
1128,
862,
26,
8428,
198,
84,
1533,
275,
295,
14,
6452,
14088,
84,
1533,
2,
520,
298,
2961,
87,
20415,
297,
576,
2788,
16,
61,
8428,
198,
829,
275,
295,
14,
6452,
14088,
829,
2,
520,
7340,
11198,
32691,
576,
2788,
16,
61,
8428,
198,
9430,
275,
295,
14,
6452,
14088,
9430,
2,
520,
298,
2961,
68,
20415,
297,
576,
2788,
16,
61,
1128,
871,
26,
1039,
307,
1533,
275,
2125,
1039,
4775,
275,
2125,
1039,
8289,
275,
2125,
1128,
2070,
576,
275,
469,
1675,
283,
84,
1533,
356,
307,
1533,
12,
1675,
283,
374,
63,
2930,
7,
520,
413,
12,
1675,
283,
9430,
7,
520,
8289,
1675,
789,
1128,
2070,
576,
275,
4011,
14,
1122,
14,
10738,
8,
1037,
576,
9,
1128,
2070,
576,
275,
8720,
829,
22078,
829,
4786,
6,
6828,
1037,
576,
1128,
372,
2070,
576,
2999,
199,
318,
6632,
52,
1873,
2470,
8,
30763,
63,
280,
2871,
305,
304,
1128,
367,
289,
1214,
63,
23958,
2470,
315,
289,
1214,
63,
280,
2871,
305,
26,
1039,
2648,
275,
6516,
11981,
8,
4078,
14,
1122,
14,
17755,
8,
23958,
2470,
63,
633,
12,
30763,
63,
23958,
2470,
430,
1039,
666,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
4341,
2963,
576,
275,
6668,
52,
1533,
8,
576,
9,
1039,
1166,
275,
4011,
14,
1122,
14,
17755,
8,
1037,
63,
633,
12,
1932,
576,
9,
1039,
2648,
275,
6516,
11981,
8,
633,
9,
1039,
666,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
4341,
3085,
275,
2022
] |
[
2647,
15,
1393,
15,
1813,
2366,
202,
199,
646,
4011,
14,
1069,
202,
199,
646,
4011,
14,
1122,
202,
199,
646,
1455,
14,
30552,
202,
199,
646,
295,
202,
199,
646,
900,
202,
199,
646,
2022,
2999,
199,
11219,
63,
633,
275,
298,
1014,
921,
11219,
14,
439,
614,
14,
7231,
14,
2756,
14,
4400,
2,
202,
199,
23958,
2470,
63,
633,
275,
298,
1014,
921,
23958,
2470,
14,
2470,
344,
85,
14,
957,
2,
202,
199,
1418,
63,
633,
275,
298,
2859,
921,
1529,
719,
14,
2470,
344,
85,
14,
957,
15,
86,
18,
15,
1246,
10197,
362,
1246,
6,
15436,
29,
10344,
6,
1246,
422,
29,
86,
19,
6,
6215,
29,
8527,
1367,
709,
1401,
1153,
2528,
6,
533,
29,
2886,
6,
2886,
466,
29,
7196,
8880,
6,
3058,
29,
3691,
363,
67,
1533,
363,
17157,
17,
85,
9208,
2,
202,
199,
2886,
63,
633,
275,
298,
2859,
921,
1529,
719,
14,
2470,
344,
85,
14,
957,
15,
86,
18,
15,
1246,
10197,
2886,
2,
202,
199,
751,
63,
4054,
275,
298,
22285,
15,
21,
14,
16,
334,
73,
15199,
27,
11952,
284,
15199,
4403,
1227,
63,
16,
2839,
10444,
4403,
1323,
9,
21257,
21666,
15,
25839,
14,
1479,
334,
43,
4943,
12,
2839,
30506,
9,
3394,
15,
22,
14,
16,
29724,
15,
709,
33,
21,
11452,
69,
428,
2756,
759,
15,
2426,
1344,
14,
821,
2,
202,
199,
751,
63,
354,
275,
298,
2676,
848,
32,
89,
4489,
72,
14,
846,
2,
202,
199,
2060,
275,
298,
1085,
1477,
383,
371,
2,
202,
199,
1037,
63,
633,
275,
298,
1014,
921,
23958,
2470,
14,
2470,
344,
85,
14,
957,
15,
573,
15,
81,
15,
1037,
2,
2999,
199,
318,
5574,
7810,
8,
5306,
63,
493,
304,
1128,
862,
26,
1039,
286,
74,
275,
1455,
14,
30552,
14,
22285,
21315,
8,
5306,
63,
493,
9,
1039,
286,
74,
14,
912,
342,
1128,
871,
26,
1039,
4090,
275,
1551,
8,
5306,
63,
493,
2584,
87,
358,
1039,
4090,
14,
952,
10804,
1039,
4090,
14,
1600,
1039,
286,
74,
275,
1455,
14,
30552,
14,
22285,
21315,
8,
5306,
63,
493,
9,
1128,
372,
286,
74,
2999,
199,
318,
6516,
29993,
8,
24862,
304,
1128,
16088,
275,
4011,
14,
1069,
14,
1506,
63,
11637,
8,
4078,
14,
1069,
14,
2856,
7810,
10438,
8,
24862,
430,
1128,
372,
16088,
2999,
199,
318,
6516,
11981,
8,
633,
304,
1128,
2648,
275,
4011,
14,
1069,
14,
2017,
8,
633,
9,
1128,
2648,
14,
525,
63,
1291,
360,
1899,
13,
7788,
297,
751,
63,
4054,
9,
1128,
372,
2648,
2999,
199,
318,
6516,
6564,
576,
8,
751,
63,
354,
12,
2060,
12,
1418,
304,
1128,
2963,
576,
275,
469,
1039,
298,
2473,
2,
520,
922,
63,
354,
12,
1039,
298,
2060,
2,
520,
2505,
12,
1039,
298,
1986,
1606,
2,
520,
298,
1014,
921,
1544,
14,
2470,
344,
85,
14,
957,
15,
1637,
15,
751,
15,
1360,
15,
86,
19,
42,
1220,
14,
1360,
401,
1039,
298,
6043,
2,
520,
298,
6610,
13,
24,
401,
1039,
298,
1418,
2,
520,
1526,
12,
1039,
298,
15436,
2,
520,
298,
10344,
401,
1039,
298,
1246,
422,
2,
520,
298,
86,
19,
401,
1039,
298,
6215,
2,
520,
298,
8527,
1367,
6785,
2114,
12664,
401,
1039,
298,
3489,
2327,
71,
2,
520,
298,
16,
401,
1039,
298,
85,
2,
520,
3367,
69,
2470,
63,
633,
12,
1039,
298,
374,
15199,
2,
520,
298,
3910,
401,
1039,
298,
13239,
63,
751,
2,
520,
298,
16,
401,
1039,
298,
2886,
466,
2,
520,
298,
7196,
8880,
401,
1039,
298,
681,
2886,
2,
520,
298,
1866,
401,
1039,
298,
4712,
600,
2,
520,
4873,
1039,
298,
5286,
63,
1529,
2,
520,
298,
265,
401,
1039,
298,
802,
1907,
63,
2886,
521,
2,
520,
298,
709,
8507,
19,
401,
1039,
298,
3058,
2,
520,
298,
1708,
14,
3691,
363,
2352,
1533,
363,
290,
21,
6271,
17,
401,
1039,
298,
2105,
2,
520,
298,
3250,
13,
9631,
2,
1128,
789,
1128,
2963,
576,
275,
4011,
14,
1122,
14,
10738,
8,
1932,
576,
9,
1128,
2963,
576,
275,
2963,
576,
14,
2143,
360,
1624,
13,
24,
358,
1128,
372,
2963,
576,
2999,
199,
318,
6668,
38,
1214,
52,
1873,
2470,
8,
576,
304,
1128,
666,
275,
666,
14,
2708,
360,
1624,
13,
24,
358,
1128,
289,
1214,
63,
280,
2871,
305,
275,
295,
14,
6452,
4827,
65,
1021,
628,
74,
63,
10044,
29746,
63,
5029,
21575,
29746,
63,
5029,
2,
4369,
628,
28149,
9,
6,
5282,
297,
576,
9,
1128,
372,
289,
1214,
63,
280,
2871,
305,
2999,
199,
318,
6668,
52,
1533,
8,
576,
304,
1128,
666,
275,
666,
14,
2708,
360,
1624,
13,
24,
358,
1128,
862,
26,
8428,
198,
84,
1533,
275,
295,
14,
6452,
14088,
84,
1533,
2,
520,
298,
2961,
87,
20415,
297,
576,
2788,
16,
61,
8428,
198,
829,
275,
295,
14,
6452,
14088,
829,
2,
520,
7340,
11198,
32691,
576,
2788,
16,
61,
8428,
198,
9430,
275,
295,
14,
6452,
14088,
9430,
2,
520,
298,
2961,
68,
20415,
297,
576,
2788,
16,
61,
1128,
871,
26,
1039,
307,
1533,
275,
2125,
1039,
4775,
275,
2125,
1039,
8289,
275,
2125,
1128,
2070,
576,
275,
469,
1675,
283,
84,
1533,
356,
307,
1533,
12,
1675,
283,
374,
63,
2930,
7,
520,
413,
12,
1675,
283,
9430,
7,
520,
8289,
1675,
789,
1128,
2070,
576,
275,
4011,
14,
1122,
14,
10738,
8,
1037,
576,
9,
1128,
2070,
576,
275,
8720,
829,
22078,
829,
4786,
6,
6828,
1037,
576,
1128,
372,
2070,
576,
2999,
199,
318,
6632,
52,
1873,
2470,
8,
30763,
63,
280,
2871,
305,
304,
1128,
367,
289,
1214,
63,
23958,
2470,
315,
289,
1214,
63,
280,
2871,
305,
26,
1039,
2648,
275,
6516,
11981,
8,
4078,
14,
1122,
14,
17755,
8,
23958,
2470,
63,
633,
12,
30763,
63,
23958,
2470,
430,
1039,
666,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
4341,
2963,
576,
275,
6668,
52,
1533,
8,
576,
9,
1039,
1166,
275,
4011,
14,
1122,
14,
17755,
8,
1037,
63,
633,
12,
1932,
576,
9,
1039,
2648,
275,
6516,
11981,
8,
633,
9,
1039,
666,
275,
16088,
14,
1490,
8,
2103,
680,
739,
342,
4341,
3085,
275,
2022,
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,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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
] |
rogerthat-platform/gae-plugin-framework
|
src/framework/server/framework/bizz/session.py
|
1
|
2118
|
# -*- coding: utf-8 -*-
# Copyright 2017 GIG Technology NV
#
# 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.
#
# @@license_version:1.3@@
from framework.consts import SESSION_TIMEOUT
from framework.models.session import Session
from framework.utils import now, chunks, guid
from google.appengine.ext import ndb, deferred
def create_session(user_id, scopes, jwt, secret=None):
secret = secret or guid().replace('-', '')
timeout = now() + SESSION_TIMEOUT
session = Session(key=Session.create_key(secret),
user_id=user_id,
timeout=timeout,
scopes=scopes,
jwt=jwt)
session.put()
return secret, session
def drop_session(session):
session.key.delete()
def drop_sessions_of_user(user_id):
sessions = list(Session.query(Session.user_id == user_id))
for chunk in chunks(sessions, 200):
ndb.delete_multi(chunk)
def validate_session(secret):
session = Session.create_key(secret).get()
if not session:
return None, None
if session.timeout < now():
session.key.delete()
return None, None
if session.timeout < now() + (SESSION_TIMEOUT / 2):
deferred.defer(_update_session_timeout, secret)
return session, session.user_id
def is_valid_session(session):
return session and session.timeout > now()
@ndb.transactional()
def _update_session_timeout(secret):
session = Session.create_key(secret).get()
if session and session.timeout < now() + (SESSION_TIMEOUT / 2):
session.timeout = now() + SESSION_TIMEOUT
session.put()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
9708,
598,
1277,
21580,
653,
54,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
13365,
1682,
63,
1023,
26,
17,
14,
19,
7492,
199,
199,
504,
10059,
14,
20473,
492,
428,
9577,
63,
8899,
199,
504,
10059,
14,
992,
14,
1730,
492,
8596,
199,
504,
10059,
14,
1208,
492,
3063,
12,
8291,
12,
15593,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
12,
12309,
421,
199,
318,
1218,
63,
1730,
8,
751,
63,
344,
12,
14570,
12,
1335,
9115,
12,
7565,
29,
403,
304,
272,
7565,
275,
7565,
503,
15593,
1252,
1814,
13858,
4074,
272,
2653,
275,
3063,
342,
435,
428,
9577,
63,
8899,
272,
2351,
275,
8596,
8,
498,
29,
4434,
14,
981,
63,
498,
8,
4731,
395,
1993,
922,
63,
344,
29,
751,
63,
344,
12,
1993,
2653,
29,
2593,
12,
1993,
14570,
29,
14129,
12,
1993,
1335,
9115,
29,
30033,
9,
272,
2351,
14,
524,
342,
272,
372,
7565,
12,
2351,
421,
199,
318,
5978,
63,
1730,
8,
1730,
304,
272,
2351,
14,
498,
14,
1807,
342,
421,
199,
318,
5978,
63,
11676,
63,
1618,
63,
751,
8,
751,
63,
344,
304,
272,
12184,
275,
769,
8,
4434,
14,
1131,
8,
4434,
14,
751,
63,
344,
508,
922,
63,
344,
430,
272,
367,
3728,
315,
8291,
8,
11676,
12,
1926,
304,
267,
23788,
14,
1807,
63,
3029,
8,
4604,
9,
421,
199,
318,
4107,
63,
1730,
8,
4731,
304,
272,
2351,
275,
8596,
14,
981,
63,
498,
8,
4731,
680,
362,
342,
272,
340,
440,
2351,
26,
267,
372,
488,
12,
488,
272,
340,
2351,
14,
2593,
665,
3063,
837,
267,
2351,
14,
498,
14,
1807,
342,
267,
372,
488,
12,
488,
272,
340,
2351,
14,
2593,
665,
3063,
342,
435,
334,
12763,
63,
8899,
1182,
499,
304,
267,
12309,
14,
11610,
1547,
873,
63,
1730,
63,
2593,
12,
7565,
9,
272,
372,
2351,
12,
2351,
14,
751,
63,
344,
421,
199,
318,
365,
63,
1078,
63,
1730,
8,
1730,
304,
272,
372,
2351,
436,
2351,
14,
2593,
690,
3063,
342,
421,
199,
32,
78,
697,
14,
5945,
279,
342,
199,
318,
485,
873,
63,
1730,
63,
2593,
8,
4731,
304,
272,
2351,
275,
8596,
14,
981,
63,
498,
8,
4731,
680,
362,
342,
272,
340,
2351,
436,
2351,
14,
2593,
665,
3063,
342,
435,
334,
12763,
63,
8899,
1182,
499,
304,
267,
2351,
14,
2593,
275,
3063,
342,
435,
428,
9577,
63,
8899,
267,
2351,
14,
524,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
9708,
598,
1277,
21580,
653,
54,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
13365,
1682,
63,
1023,
26,
17,
14,
19,
7492,
199,
199,
504,
10059,
14,
20473,
492,
428,
9577,
63,
8899,
199,
504,
10059,
14,
992,
14,
1730,
492,
8596,
199,
504,
10059,
14,
1208,
492,
3063,
12,
8291,
12,
15593,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
12,
12309,
421,
199,
318,
1218,
63,
1730,
8,
751,
63,
344,
12,
14570,
12,
1335,
9115,
12,
7565,
29,
403,
304,
272,
7565,
275,
7565,
503,
15593,
1252,
1814,
13858,
4074,
272,
2653,
275,
3063,
342,
435,
428,
9577,
63,
8899,
272,
2351,
275,
8596,
8,
498,
29,
4434,
14,
981,
63,
498,
8,
4731,
395,
1993,
922,
63,
344,
29,
751,
63,
344,
12,
1993,
2653,
29,
2593,
12,
1993,
14570,
29,
14129,
12,
1993,
1335,
9115,
29,
30033,
9,
272,
2351,
14,
524,
342,
272,
372,
7565,
12,
2351,
421,
199,
318,
5978,
63,
1730,
8,
1730,
304,
272,
2351,
14,
498,
14,
1807,
342,
421,
199,
318,
5978,
63,
11676,
63,
1618,
63,
751,
8,
751,
63,
344,
304,
272,
12184,
275,
769,
8,
4434,
14,
1131,
8,
4434,
14,
751,
63,
344,
508,
922,
63,
344,
430,
272,
367,
3728,
315,
8291,
8,
11676,
12,
1926,
304,
267,
23788,
14,
1807,
63,
3029,
8,
4604,
9,
421,
199,
318,
4107,
63,
1730,
8,
4731,
304,
272,
2351,
275,
8596,
14,
981,
63,
498,
8,
4731,
680,
362,
342,
272,
340,
440,
2351,
26,
267,
372,
488,
12,
488,
272,
340,
2351,
14,
2593,
665,
3063,
837,
267,
2351,
14,
498,
14,
1807,
342,
267,
372,
488,
12,
488,
272,
340,
2351,
14,
2593,
665,
3063,
342,
435,
334,
12763,
63,
8899,
1182,
499,
304,
267,
12309,
14,
11610,
1547,
873,
63,
1730,
63,
2593,
12,
7565,
9,
272,
372,
2351,
12,
2351,
14,
751,
63,
344,
421,
199,
318,
365,
63,
1078,
63,
1730,
8,
1730,
304,
272,
372,
2351,
436,
2351,
14,
2593,
690,
3063,
342,
421,
199,
32,
78,
697,
14,
5945,
279,
342,
199,
318,
485,
873,
63,
1730,
63,
2593,
8,
4731,
304,
272,
2351,
275,
8596,
14,
981,
63,
498,
8,
4731,
680,
362,
342,
272,
340,
2351,
436,
2351,
14,
2593,
665,
3063,
342,
435,
334,
12763,
63,
8899,
1182,
499,
304,
267,
2351,
14,
2593,
275,
3063,
342,
435,
428,
9577,
63,
8899,
267,
2351,
14,
524,
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,
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
] |
MyTunesFreeMusic/privacy-policy
|
beetsplug/edit.py
|
11
|
13723
|
# -*- coding: utf-8 -*-
# This file is part of beets.
# Copyright 2016
#
# 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.
"""Open metadata information in a text editor to let the user edit it.
"""
from __future__ import division, absolute_import, print_function
from beets import plugins
from beets import util
from beets import ui
from beets.dbcore import types
from beets.importer import action
from beets.ui.commands import _do_query, PromptChoice
from copy import deepcopy
import codecs
import subprocess
import yaml
from tempfile import NamedTemporaryFile
import os
import six
# These "safe" types can avoid the format/parse cycle that most fields go
# through: they are safe to edit with native YAML types.
SAFE_TYPES = (types.Float, types.Integer, types.Boolean)
class ParseError(Exception):
"""The modified file is unreadable. The user should be offered a chance to
fix the error.
"""
def edit(filename, log):
"""Open `filename` in a text editor.
"""
cmd = util.shlex_split(util.editor_command())
cmd.append(filename)
log.debug(u'invoking editor command: {!r}', cmd)
try:
subprocess.call(cmd)
except OSError as exc:
raise ui.UserError(u'could not run editor command {!r}: {}'.format(
cmd[0], exc
))
def dump(arg):
"""Dump a sequence of dictionaries as YAML for editing.
"""
return yaml.safe_dump_all(
arg,
allow_unicode=True,
default_flow_style=False,
)
def load(s):
"""Read a sequence of YAML documents back to a list of dictionaries
with string keys.
Can raise a `ParseError`.
"""
try:
out = []
for d in yaml.load_all(s):
if not isinstance(d, dict):
raise ParseError(
u'each entry must be a dictionary; found {}'.format(
type(d).__name__
)
)
# Convert all keys to strings. They started out as strings,
# but the user may have inadvertently messed this up.
out.append({six.text_type(k): v for k, v in d.items()})
except yaml.YAMLError as e:
raise ParseError(u'invalid YAML: {}'.format(e))
return out
def _safe_value(obj, key, value):
"""Check whether the `value` is safe to represent in YAML and trust as
returned from parsed YAML.
This ensures that values do not change their type when the user edits their
YAML representation.
"""
typ = obj._type(key)
return isinstance(typ, SAFE_TYPES) and isinstance(value, typ.model_type)
def flatten(obj, fields):
"""Represent `obj`, a `dbcore.Model` object, as a dictionary for
serialization. Only include the given `fields` if provided;
otherwise, include everything.
The resulting dictionary's keys are strings and the values are
safely YAML-serializable types.
"""
# Format each value.
d = {}
for key in obj.keys():
value = obj[key]
if _safe_value(obj, key, value):
# A safe value that is faithfully representable in YAML.
d[key] = value
else:
# A value that should be edited as a string.
d[key] = obj.formatted()[key]
# Possibly filter field names.
if fields:
return {k: v for k, v in d.items() if k in fields}
else:
return d
def apply_(obj, data):
"""Set the fields of a `dbcore.Model` object according to a
dictionary.
This is the opposite of `flatten`. The `data` dictionary should have
strings as values.
"""
for key, value in data.items():
if _safe_value(obj, key, value):
# A safe value *stayed* represented as a safe type. Assign it
# directly.
obj[key] = value
else:
# Either the field was stringified originally or the user changed
# it from a safe type to an unsafe one. Parse it as a string.
obj.set_parse(key, six.text_type(value))
class EditPlugin(plugins.BeetsPlugin):
def __init__(self):
super(EditPlugin, self).__init__()
self.config.add({
# The default fields to edit.
'albumfields': 'album albumartist',
'itemfields': 'track title artist album',
# Silently ignore any changes to these fields.
'ignore_fields': 'id path',
})
self.register_listener('before_choose_candidate',
self.before_choose_candidate_listener)
def commands(self):
edit_command = ui.Subcommand(
'edit',
help=u'interactively edit metadata'
)
edit_command.parser.add_option(
u'-f', u'--field',
metavar='FIELD',
action='append',
help=u'edit this field also',
)
edit_command.parser.add_option(
u'--all',
action='store_true', dest='all',
help=u'edit all fields',
)
edit_command.parser.add_album_option()
edit_command.func = self._edit_command
return [edit_command]
def _edit_command(self, lib, opts, args):
"""The CLI command function for the `beet edit` command.
"""
# Get the objects to edit.
query = ui.decargs(args)
items, albums = _do_query(lib, query, opts.album, False)
objs = albums if opts.album else items
if not objs:
ui.print_(u'Nothing to edit.')
return
# Get the fields to edit.
if opts.all:
fields = None
else:
fields = self._get_fields(opts.album, opts.field)
self.edit(opts.album, objs, fields)
def _get_fields(self, album, extra):
"""Get the set of fields to edit.
"""
# Start with the configured base fields.
if album:
fields = self.config['albumfields'].as_str_seq()
else:
fields = self.config['itemfields'].as_str_seq()
# Add the requested extra fields.
if extra:
fields += extra
# Ensure we always have the `id` field for identification.
fields.append('id')
return set(fields)
def edit(self, album, objs, fields):
"""The core editor function.
- `album`: A flag indicating whether we're editing Items or Albums.
- `objs`: The `Item`s or `Album`s to edit.
- `fields`: The set of field names to edit (or None to edit
everything).
"""
# Present the YAML to the user and let her change it.
success = self.edit_objects(objs, fields)
# Save the new data.
if success:
self.save_changes(objs)
def edit_objects(self, objs, fields):
"""Dump a set of Model objects to a file as text, ask the user
to edit it, and apply any changes to the objects.
Return a boolean indicating whether the edit succeeded.
"""
# Get the content to edit as raw data structures.
old_data = [flatten(o, fields) for o in objs]
# Set up a temporary file with the initial data for editing.
if six.PY2:
new = NamedTemporaryFile(mode='w', suffix='.yaml', delete=False)
else:
new = NamedTemporaryFile(mode='w', suffix='.yaml', delete=False,
encoding='utf-8')
old_str = dump(old_data)
new.write(old_str)
if six.PY2:
old_str = old_str.decode('utf-8')
new.close()
# Loop until we have parseable data and the user confirms.
try:
while True:
# Ask the user to edit the data.
edit(new.name, self._log)
# Read the data back after editing and check whether anything
# changed.
with codecs.open(new.name, encoding='utf-8') as f:
new_str = f.read()
if new_str == old_str:
ui.print_(u"No changes; aborting.")
return False
# Parse the updated data.
try:
new_data = load(new_str)
except ParseError as e:
ui.print_(u"Could not read data: {}".format(e))
if ui.input_yn(u"Edit again to fix? (Y/n)", True):
continue
else:
return False
# Show the changes.
# If the objects are not on the DB yet, we need a copy of their
# original state for show_model_changes.
objs_old = [deepcopy(obj) if not obj._db else None
for obj in objs]
self.apply_data(objs, old_data, new_data)
changed = False
for obj, obj_old in zip(objs, objs_old):
changed |= ui.show_model_changes(obj, obj_old)
if not changed:
ui.print_(u'No changes to apply.')
return False
# Confirm the changes.
choice = ui.input_options(
(u'continue Editing', u'apply', u'cancel')
)
if choice == u'a': # Apply.
return True
elif choice == u'c': # Cancel.
return False
elif choice == u'e': # Keep editing.
# Reset the temporary changes to the objects.
for obj in objs:
obj.read()
continue
# Remove the temporary file before returning.
finally:
os.remove(new.name)
def apply_data(self, objs, old_data, new_data):
"""Take potentially-updated data and apply it to a set of Model
objects.
The objects are not written back to the database, so the changes
are temporary.
"""
if len(old_data) != len(new_data):
self._log.warning(u'number of objects changed from {} to {}',
len(old_data), len(new_data))
obj_by_id = {o.id: o for o in objs}
ignore_fields = self.config['ignore_fields'].as_str_seq()
for old_dict, new_dict in zip(old_data, new_data):
# Prohibit any changes to forbidden fields to avoid
# clobbering `id` and such by mistake.
forbidden = False
for key in ignore_fields:
if old_dict.get(key) != new_dict.get(key):
self._log.warning(u'ignoring object whose {} changed', key)
forbidden = True
break
if forbidden:
continue
id_ = int(old_dict['id'])
apply_(obj_by_id[id_], new_dict)
def save_changes(self, objs):
"""Save a list of updated Model objects to the database.
"""
# Save to the database and possibly write tags.
for ob in objs:
if ob._dirty:
self._log.debug(u'saving changes to {}', ob)
ob.try_sync(ui.should_write(), ui.should_move())
# Methods for interactive importer execution.
def before_choose_candidate_listener(self, session, task):
"""Append an "Edit" choice and an "edit Candidates" choice (if
there are candidates) to the interactive importer prompt.
"""
choices = [PromptChoice('d', 'eDit', self.importer_edit)]
if task.candidates:
choices.append(PromptChoice('c', 'edit Candidates',
self.importer_edit_candidate))
return choices
def importer_edit(self, session, task):
"""Callback for invoking the functionality during an interactive
import session on the *original* item tags.
"""
# Assign temporary ids to the Items.
for i, obj in enumerate(task.items):
obj.id = i + 1
# Present the YAML to the user and let her change it.
fields = self._get_fields(album=False, extra=[])
success = self.edit_objects(task.items, fields)
# Remove temporary ids.
for obj in task.items:
obj.id = None
# Save the new data.
if success:
# Return action.RETAG, which makes the importer write the tags
# to the files if needed without re-applying metadata.
return action.RETAG
else:
# Edit cancelled / no edits made. Revert changes.
for obj in task.items:
obj.read()
def importer_edit_candidate(self, session, task):
"""Callback for invoking the functionality during an interactive
import session on a *candidate*. The candidate's metadata is
applied to the original items.
"""
# Prompt the user for a candidate.
sel = ui.input_options([], numrange=(1, len(task.candidates)))
# Force applying the candidate on the items.
task.match = task.candidates[sel - 1]
task.apply_metadata()
return self.importer_edit(session, task)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1777,
402,
506,
8716,
14,
199,
3,
1898,
7800,
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,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
624,
4299,
3341,
2556,
315,
282,
1318,
8823,
370,
4691,
314,
922,
5283,
652,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
504,
506,
8716,
492,
8963,
199,
504,
506,
8716,
492,
4884,
199,
504,
506,
8716,
492,
8574,
199,
504,
506,
8716,
14,
697,
1018,
492,
2943,
199,
504,
506,
8716,
14,
12138,
492,
1595,
199,
504,
506,
8716,
14,
1907,
14,
4405,
492,
485,
1117,
63,
1131,
12,
2165,
4787,
9054,
199,
504,
1331,
492,
14800,
199,
646,
6010,
199,
646,
3873,
199,
646,
8864,
199,
504,
5549,
492,
31825,
199,
646,
747,
199,
646,
3816,
421,
199,
3,
5723,
298,
3489,
2,
2943,
883,
5126,
314,
1475,
15,
1122,
8643,
626,
4750,
1504,
2621,
199,
3,
4012,
26,
2985,
787,
5048,
370,
5283,
543,
5438,
18916,
2943,
14,
199,
27657,
63,
7893,
275,
334,
1313,
14,
5136,
12,
2943,
14,
2674,
12,
2943,
14,
4082,
9,
421,
199,
533,
21743,
8,
1726,
304,
272,
408,
1918,
6042,
570,
365,
625,
11875,
14,
710,
922,
1077,
506,
402,
22941,
282,
22044,
370,
272,
5325,
314,
1125,
14,
272,
408,
421,
199,
318,
5283,
8,
1501,
12,
943,
304,
272,
408,
4299,
658,
1501,
64,
315,
282,
1318,
8823,
14,
272,
408,
272,
2088,
275,
4884,
14,
32507,
63,
1294,
8,
1974,
14,
7515,
63,
1531,
1012,
272,
2088,
14,
740,
8,
1501,
9,
272,
943,
14,
1757,
8,
85,
7,
5350,
17967,
8823,
1414,
26,
18776,
82,
7293,
2088,
9,
272,
862,
26,
267,
3873,
14,
1250,
8,
1760,
9,
272,
871,
6440,
465,
3178,
26,
267,
746,
8574,
14,
1899,
547,
8,
85,
7,
15153,
440,
1255,
8823,
1414,
18776,
82,
9160,
9499,
908,
8,
288,
2088,
59,
16,
467,
3178,
267,
5082,
421,
199,
318,
5461,
8,
1273,
304,
272,
408,
11772,
282,
3414,
402,
11196,
465,
18916,
367,
20401,
14,
272,
408,
272,
372,
8864,
14,
3489,
63,
2724,
63,
452,
8,
267,
1680,
12,
267,
2040,
63,
2975,
29,
549,
12,
267,
849,
63,
1659,
63,
2487,
29,
797,
12,
272,
776,
421,
199,
318,
2248,
8,
83,
304,
272,
408,
3284,
282,
3414,
402,
18916,
8247,
1771,
370,
282,
769,
402,
11196,
272,
543,
1059,
2883,
14,
339,
6855,
746,
282,
658,
9123,
2313,
272,
408,
272,
862,
26,
267,
734,
275,
942,
267,
367,
366,
315,
8864,
14,
912,
63,
452,
8,
83,
304,
288,
340,
440,
1228,
8,
68,
12,
1211,
304,
355,
746,
21743,
8,
490,
399,
7,
10885,
2397,
1471,
506,
282,
2600,
27,
1911,
9499,
908,
8,
717,
730,
8,
68,
2843,
354,
363,
490,
776,
355,
776,
953,
327,
7905,
1006,
2883,
370,
3326,
14,
9322,
8239,
734,
465,
3326,
12,
288,
327,
1325,
314,
922,
1443,
1172,
315,
350,
422,
767,
590,
26560,
939,
642,
1536,
14,
288,
734,
14,
740,
2561,
4174,
14,
505,
63,
466,
8,
75,
304,
373,
367,
1022,
12,
373,
315,
366,
14,
1744,
22804,
339,
871,
8864,
14,
23103,
547,
465,
325,
26,
267,
746,
21743,
8,
85,
7,
3197,
18916,
26,
9499,
908,
8,
69,
430,
272,
372,
734,
421,
199,
318,
485,
3489,
63,
585,
8,
1113,
12,
790,
12,
574,
304,
272,
408,
1799,
3775,
314,
658,
585,
64,
365,
5048,
370,
2954,
315,
18916,
436,
16822,
465,
272,
2138,
687,
4565,
18916,
14,
339,
961,
15620,
626,
1338,
886,
440,
1570,
3932,
730,
1380,
314,
922,
7860,
1086,
3932,
272,
18916,
6025,
14,
272,
408,
272,
6211,
275,
1559,
423,
466,
8,
498,
9,
272,
372,
1228,
8,
9749,
12,
13950,
5100,
63,
7893,
9,
436,
1228,
8,
585,
12,
6211,
14,
1238,
63,
466,
9,
421,
199,
318,
9378,
8,
1113,
12,
1504,
304,
272,
408,
10755,
658,
1113,
3559,
282,
658,
697,
1018,
14,
1685,
64,
909,
12,
465,
282,
2600,
367,
272,
16953,
14,
5972,
2387,
314,
1627,
658,
955,
64,
340,
2741,
27,
272,
4257,
12,
2387,
8137,
14,
339,
710,
9183,
2600,
1159,
2883,
787,
3326,
436,
314,
1338,
787,
272,
19353,
18916,
13,
2171,
14065,
2943,
14,
272,
408,
272,
327,
9701,
1924,
574,
14,
272,
366,
275,
1052,
272,
367,
790,
315,
1559,
14,
1612,
837,
267,
574,
275,
1559,
59,
498,
61,
267,
340,
485,
3489,
63,
585,
8,
1113,
12,
790,
12,
574,
304,
288,
327,
437,
5048,
574,
626,
365,
1433,
448,
5836,
2954,
461,
315,
18916,
14,
288,
366,
59,
498,
61,
275,
574,
267,
587,
26,
288,
327,
437,
574,
626,
1077,
506,
21062,
465,
282,
1059,
14,
288,
366,
59,
498,
61,
275,
1559,
14,
15317,
3430,
498,
61,
339,
327,
25987,
9312,
2457,
901,
1561,
14,
272,
340,
1504,
26,
267,
372,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
366,
14,
1744,
342,
340,
1022,
315,
1504,
93,
272,
587,
26,
267,
372,
366,
421,
199,
318,
4838,
2531,
1113,
12,
666,
304,
272,
408,
1084,
314,
1504,
402,
282,
658,
697,
1018,
14,
1685,
64,
909,
7182,
370,
282,
272,
2600,
14,
339,
961,
365,
314,
26912,
402,
658,
8487,
2313,
710,
658,
576,
64,
2600,
1077,
1172,
272,
3326,
465,
1338,
14,
272,
408,
272,
367,
790,
12,
574,
315,
666,
14,
1744,
837,
267,
340,
485,
3489,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
961,
570,
365,
1777,
402,
506,
8716,
14,
199,
3,
1898,
7800,
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,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
624,
4299,
3341,
2556,
315,
282,
1318,
8823,
370,
4691,
314,
922,
5283,
652,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
504,
506,
8716,
492,
8963,
199,
504,
506,
8716,
492,
4884,
199,
504,
506,
8716,
492,
8574,
199,
504,
506,
8716,
14,
697,
1018,
492,
2943,
199,
504,
506,
8716,
14,
12138,
492,
1595,
199,
504,
506,
8716,
14,
1907,
14,
4405,
492,
485,
1117,
63,
1131,
12,
2165,
4787,
9054,
199,
504,
1331,
492,
14800,
199,
646,
6010,
199,
646,
3873,
199,
646,
8864,
199,
504,
5549,
492,
31825,
199,
646,
747,
199,
646,
3816,
421,
199,
3,
5723,
298,
3489,
2,
2943,
883,
5126,
314,
1475,
15,
1122,
8643,
626,
4750,
1504,
2621,
199,
3,
4012,
26,
2985,
787,
5048,
370,
5283,
543,
5438,
18916,
2943,
14,
199,
27657,
63,
7893,
275,
334,
1313,
14,
5136,
12,
2943,
14,
2674,
12,
2943,
14,
4082,
9,
421,
199,
533,
21743,
8,
1726,
304,
272,
408,
1918,
6042,
570,
365,
625,
11875,
14,
710,
922,
1077,
506,
402,
22941,
282,
22044,
370,
272,
5325,
314,
1125,
14,
272,
408,
421,
199,
318,
5283,
8,
1501,
12,
943,
304,
272,
408,
4299,
658,
1501,
64,
315,
282,
1318,
8823,
14,
272,
408,
272,
2088,
275,
4884,
14,
32507,
63,
1294,
8,
1974,
14,
7515,
63,
1531,
1012,
272,
2088,
14,
740,
8,
1501,
9,
272,
943,
14,
1757,
8,
85,
7,
5350,
17967,
8823,
1414,
26,
18776,
82,
7293,
2088,
9,
272,
862,
26,
267,
3873,
14,
1250,
8,
1760,
9,
272,
871,
6440,
465,
3178,
26,
267,
746,
8574,
14,
1899,
547,
8,
85,
7,
15153,
440,
1255,
8823,
1414,
18776,
82,
9160,
9499,
908,
8,
288,
2088,
59,
16,
467,
3178,
267,
5082,
421,
199,
318,
5461,
8,
1273,
304,
272,
408,
11772,
282,
3414,
402,
11196,
465,
18916,
367,
20401,
14,
272,
408,
272,
372,
8864,
14,
3489,
63,
2724,
63,
452,
8,
267,
1680,
12,
267,
2040,
63,
2975,
29,
549,
12,
267,
849,
63,
1659,
63,
2487,
29,
797,
12,
272,
776,
421,
199,
318,
2248,
8,
83,
304,
272,
408,
3284,
282,
3414,
402,
18916,
8247,
1771,
370,
282,
769,
402,
11196,
272,
543,
1059,
2883,
14,
339,
6855,
746,
282,
658,
9123,
2313,
272,
408,
272,
862,
26,
267,
734,
275,
942,
267,
367,
366,
315,
8864,
14,
912,
63,
452,
8,
83,
304,
288,
340,
440,
1228,
8,
68,
12,
1211,
304,
355,
746,
21743,
8,
490,
399,
7,
10885,
2397,
1471,
506,
282,
2600,
27,
1911,
9499,
908,
8,
717,
730,
8,
68,
2843,
354,
363,
490,
776,
355,
776,
953,
327,
7905,
1006,
2883,
370,
3326,
14,
9322,
8239,
734,
465,
3326,
12,
288,
327,
1325,
314,
922,
1443,
1172,
315,
350,
422,
767,
590,
26560,
939,
642,
1536,
14,
288,
734,
14,
740,
2561,
4174,
14,
505,
63,
466,
8,
75,
304,
373,
367,
1022,
12,
373,
315,
366,
14,
1744,
22804,
339,
871,
8864,
14,
23103,
547,
465,
325,
26,
267,
746,
21743,
8,
85,
7,
3197,
18916,
26,
9499,
908,
8,
69,
430,
272,
372,
734,
421,
199,
318,
485,
3489,
63,
585,
8,
1113,
12,
790,
12,
574,
304,
272,
408,
1799,
3775,
314,
658,
585,
64,
365,
5048,
370,
2954,
315,
18916,
436,
16822,
465,
272,
2138,
687,
4565,
18916,
14,
339,
961,
15620,
626,
1338,
886,
440,
1570,
3932,
730,
1380,
314,
922,
7860,
1086,
3932,
272,
18916,
6025,
14,
272,
408,
272,
6211,
275,
1559,
423,
466,
8,
498,
9,
272,
372,
1228,
8,
9749,
12,
13950,
5100,
63,
7893,
9,
436,
1228,
8,
585,
12,
6211,
14,
1238,
63,
466,
9,
421,
199,
318,
9378,
8,
1113,
12,
1504,
304,
272,
408,
10755,
658,
1113,
3559,
282,
658,
697,
1018,
14,
1685,
64,
909,
12,
465,
282,
2600,
367,
272,
16953,
14,
5972,
2387,
314,
1627,
658,
955,
64,
340,
2741,
27,
272,
4257,
12,
2387,
8137,
14,
339,
710,
9183,
2600,
1159,
2883,
787,
3326,
436,
314,
1338,
787,
272,
19353,
18916,
13,
2171,
14065,
2943,
14,
272,
408,
272,
327,
9701,
1924,
574,
14,
272,
366,
275,
1052,
272,
367,
790,
315,
1559,
14,
1612,
837,
267,
574,
275,
1559,
59,
498,
61,
267,
340,
485,
3489,
63,
585,
8,
1113,
12,
790,
12,
574,
304,
288,
327,
437,
5048,
574,
626,
365,
1433,
448,
5836,
2954,
461,
315,
18916,
14,
288,
366,
59,
498,
61,
275,
574,
267,
587,
26,
288,
327,
437,
574,
626,
1077,
506,
21062,
465,
282,
1059,
14,
288,
366,
59,
498,
61,
275,
1559,
14,
15317,
3430,
498,
61,
339,
327,
25987,
9312,
2457,
901,
1561,
14,
272,
340,
1504,
26,
267,
372,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
366,
14,
1744,
342,
340,
1022,
315,
1504,
93,
272,
587,
26,
267,
372,
366,
421,
199,
318,
4838,
2531,
1113,
12,
666,
304,
272,
408,
1084,
314,
1504,
402,
282,
658,
697,
1018,
14,
1685,
64,
909,
7182,
370,
282,
272,
2600,
14,
339,
961,
365,
314,
26912,
402,
658,
8487,
2313,
710,
658,
576,
64,
2600,
1077,
1172,
272,
3326,
465,
1338,
14,
272,
408,
272,
367,
790,
12,
574,
315,
666,
14,
1744,
837,
267,
340,
485,
3489,
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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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
] |
ColumbiaCMB/kid_readout
|
kid_readout/equipment/agilent_33220.py
|
1
|
2243
|
"""
Agilent 33220A Function generator
"""
import socket
import time
class FunctionGenerator(object):
def __init__(self,addr=('192.168.1.135', 5025)):
self.addr = addr
def set_load_ohms(self,ohms):
self.send("OUTPUT:LOAD %d" % ohms)
def set_dc_voltage(self,volts):
self.send("APPLY:DC DEF, DEF, %f" % volts)
def enable_output(self,on):
if on:
self.send("OUTPUT ON")
else:
self.send("OUTPUT OFF")
def set_square_wave(self,freq,high_level,low_level=0,duty_cycle_percent=50.0):
self.enable_output(False)
self.send("FUNC SQUARE")
self.send("FREQ %f" % freq)
self.send("VOLT:HIGH %f" % high_level)
self.send("VOLT:LOW %f" % low_level)
self.send("FUNC:SQUARE:DCYCLE %f" % (duty_cycle_percent))
time.sleep(1)
print "waveform ready, remember to enable output."
def set_pulse(self,period,width,high_level,low_level=0):
if width >= period:
raise ValueError("Width must be less than Period")
self.enable_output(False)
self.send("FUNC PULSE")
self.send("FUNC:PULSE:HOLD WIDTH")
time.sleep(2)
self.send("PULSE:PERIOD %f" % period)
time.sleep(0.3)
self.send("PULSE:WIDTH %f" % width)
time.sleep(0.3)
self.send("VOLT:HIGH %f" % high_level)
self.send("VOLT:LOW %f" % low_level)
time.sleep(1) # this sleep is required so that the output can be enabled immediately after, otherwise it
# seems to ignore the enable request
print "waveform ready, remember to enable output"
def send_get(self,cmd,timeout=1):
result = None
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(self.addr)
s.settimeout(timeout)
s.send(cmd+'\n')
result = s.recv(1024)
finally:
s.close()
return result
def send(self,cmd):
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(self.addr)
s.send(cmd+'\n')
time.sleep(0.2)
finally:
s.close()
|
bsd-2-clause
|
[
624,
199,
5676,
441,
343,
650,
708,
1165,
33,
6801,
4306,
199,
624,
199,
646,
2838,
199,
646,
900,
199,
199,
533,
6801,
7599,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2697,
7782,
5756,
14,
6568,
14,
17,
14,
8312,
297,
5238,
821,
2298,
267,
291,
14,
2697,
275,
5552,
5493,
347,
663,
63,
912,
63,
19194,
706,
8,
277,
12,
19194,
706,
304,
267,
291,
14,
2254,
480,
8414,
26,
7405,
450,
68,
2,
450,
312,
72,
706,
9,
5493,
347,
663,
63,
3833,
63,
27543,
8,
277,
12,
5650,
1086,
304,
267,
291,
14,
2254,
480,
1282,
31370,
26,
5196,
23566,
12,
23566,
12,
450,
70,
2,
450,
5236,
1086,
9,
5493,
347,
4756,
63,
1199,
8,
277,
12,
265,
304,
267,
340,
641,
26,
288,
291,
14,
2254,
480,
8414,
5258,
531,
267,
587,
26,
288,
291,
14,
2254,
480,
8414,
32633,
531,
339,
347,
663,
63,
9646,
63,
10024,
8,
277,
12,
5646,
12,
6260,
63,
1896,
12,
674,
63,
1896,
29,
16,
12,
68,
19974,
63,
7612,
63,
7045,
29,
1400,
14,
16,
304,
267,
291,
14,
4296,
63,
1199,
8,
797,
9,
267,
291,
14,
2254,
480,
19587,
15300,
531,
267,
291,
14,
2254,
480,
38,
14583,
450,
70,
2,
450,
9220,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
17624,
450,
70,
2,
450,
4721,
63,
1896,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
5896,
450,
70,
2,
450,
6465,
63,
1896,
9,
267,
291,
14,
2254,
480,
19587,
26,
51,
14424,
26,
5196,
57,
12507,
450,
70,
2,
450,
334,
68,
19974,
63,
7612,
63,
7045,
430,
267,
900,
14,
4532,
8,
17,
9,
267,
870,
298,
10024,
964,
10144,
12,
21027,
370,
4756,
1072,
2122,
339,
347,
663,
63,
19538,
8,
277,
12,
5191,
12,
2063,
12,
6260,
63,
1896,
12,
674,
63,
1896,
29,
16,
304,
267,
340,
3462,
2356,
6247,
26,
288,
746,
1722,
480,
6216,
1471,
506,
6656,
2419,
16532,
531,
267,
291,
14,
4296,
63,
1199,
8,
797,
9,
267,
291,
14,
2254,
480,
19587,
510,
1293,
899,
531,
267,
291,
14,
2254,
480,
19587,
26,
48,
1293,
899,
26,
40,
5104,
644,
998,
2080,
531,
267,
900,
14,
4532,
8,
18,
9,
267,
291,
14,
2254,
480,
48,
1293,
899,
26,
27081,
450,
70,
2,
450,
6247,
9,
267,
900,
14,
4532,
8,
16,
14,
19,
9,
267,
291,
14,
2254,
480,
48,
1293,
899,
26,
11139,
450,
70,
2,
450,
3462,
9,
267,
900,
14,
4532,
8,
16,
14,
19,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
17624,
450,
70,
2,
450,
4721,
63,
1896,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
5896,
450,
70,
2,
450,
6465,
63,
1896,
9,
267,
900,
14,
4532,
8,
17,
9,
221,
327,
642,
9435,
365,
1415,
880,
626,
314,
1072,
883,
506,
5223,
9939,
2410,
12,
4257,
652,
267,
327,
12237,
370,
3686,
314,
4756,
1056,
267,
870,
298,
10024,
964,
10144,
12,
21027,
370,
4756,
1072,
2,
5493,
347,
3222,
63,
362,
8,
277,
12,
1760,
12,
2593,
29,
17,
304,
267,
754,
275,
488,
267,
862,
26,
288,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
3450,
14,
9469,
63,
9484,
9,
288,
308,
14,
2242,
8,
277,
14,
2697,
9,
288,
308,
14,
24630,
8,
2593,
9,
288,
308,
14,
2254,
8,
1760,
19192,
78,
358,
288,
754,
275,
308,
14,
7637,
8,
7727,
9,
267,
3753,
26,
288,
308,
14,
1600,
342,
267,
372,
754,
2286,
347,
3222,
8,
277,
12,
1760,
304,
267,
862,
26,
288,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
3450,
14,
9469,
63,
9484,
9,
288,
308,
14,
2242,
8,
277,
14,
2697,
9,
288,
308,
14,
2254,
8,
1760,
19192,
78,
358,
288,
900,
14,
4532,
8,
16,
14,
18,
9,
267,
3753,
26,
288,
308,
14,
1600,
342,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
5676,
441,
343,
650,
708,
1165,
33,
6801,
4306,
199,
624,
199,
646,
2838,
199,
646,
900,
199,
199,
533,
6801,
7599,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2697,
7782,
5756,
14,
6568,
14,
17,
14,
8312,
297,
5238,
821,
2298,
267,
291,
14,
2697,
275,
5552,
5493,
347,
663,
63,
912,
63,
19194,
706,
8,
277,
12,
19194,
706,
304,
267,
291,
14,
2254,
480,
8414,
26,
7405,
450,
68,
2,
450,
312,
72,
706,
9,
5493,
347,
663,
63,
3833,
63,
27543,
8,
277,
12,
5650,
1086,
304,
267,
291,
14,
2254,
480,
1282,
31370,
26,
5196,
23566,
12,
23566,
12,
450,
70,
2,
450,
5236,
1086,
9,
5493,
347,
4756,
63,
1199,
8,
277,
12,
265,
304,
267,
340,
641,
26,
288,
291,
14,
2254,
480,
8414,
5258,
531,
267,
587,
26,
288,
291,
14,
2254,
480,
8414,
32633,
531,
339,
347,
663,
63,
9646,
63,
10024,
8,
277,
12,
5646,
12,
6260,
63,
1896,
12,
674,
63,
1896,
29,
16,
12,
68,
19974,
63,
7612,
63,
7045,
29,
1400,
14,
16,
304,
267,
291,
14,
4296,
63,
1199,
8,
797,
9,
267,
291,
14,
2254,
480,
19587,
15300,
531,
267,
291,
14,
2254,
480,
38,
14583,
450,
70,
2,
450,
9220,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
17624,
450,
70,
2,
450,
4721,
63,
1896,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
5896,
450,
70,
2,
450,
6465,
63,
1896,
9,
267,
291,
14,
2254,
480,
19587,
26,
51,
14424,
26,
5196,
57,
12507,
450,
70,
2,
450,
334,
68,
19974,
63,
7612,
63,
7045,
430,
267,
900,
14,
4532,
8,
17,
9,
267,
870,
298,
10024,
964,
10144,
12,
21027,
370,
4756,
1072,
2122,
339,
347,
663,
63,
19538,
8,
277,
12,
5191,
12,
2063,
12,
6260,
63,
1896,
12,
674,
63,
1896,
29,
16,
304,
267,
340,
3462,
2356,
6247,
26,
288,
746,
1722,
480,
6216,
1471,
506,
6656,
2419,
16532,
531,
267,
291,
14,
4296,
63,
1199,
8,
797,
9,
267,
291,
14,
2254,
480,
19587,
510,
1293,
899,
531,
267,
291,
14,
2254,
480,
19587,
26,
48,
1293,
899,
26,
40,
5104,
644,
998,
2080,
531,
267,
900,
14,
4532,
8,
18,
9,
267,
291,
14,
2254,
480,
48,
1293,
899,
26,
27081,
450,
70,
2,
450,
6247,
9,
267,
900,
14,
4532,
8,
16,
14,
19,
9,
267,
291,
14,
2254,
480,
48,
1293,
899,
26,
11139,
450,
70,
2,
450,
3462,
9,
267,
900,
14,
4532,
8,
16,
14,
19,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
17624,
450,
70,
2,
450,
4721,
63,
1896,
9,
267,
291,
14,
2254,
480,
12209,
52,
26,
5896,
450,
70,
2,
450,
6465,
63,
1896,
9,
267,
900,
14,
4532,
8,
17,
9,
221,
327,
642,
9435,
365,
1415,
880,
626,
314,
1072,
883,
506,
5223,
9939,
2410,
12,
4257,
652,
267,
327,
12237,
370,
3686,
314,
4756,
1056,
267,
870,
298,
10024,
964,
10144,
12,
21027,
370,
4756,
1072,
2,
5493,
347,
3222,
63,
362,
8,
277,
12,
1760,
12,
2593,
29,
17,
304,
267,
754,
275,
488,
267,
862,
26,
288,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
3450,
14,
9469,
63,
9484,
9,
288,
308,
14,
2242,
8,
277,
14,
2697,
9,
288,
308,
14,
24630,
8,
2593,
9,
288,
308,
14,
2254,
8,
1760,
19192,
78,
358,
288,
754,
275,
308,
14,
7637,
8,
7727,
9,
267,
3753,
26,
288,
308,
14,
1600,
342,
267,
372,
754,
2286,
347,
3222,
8,
277,
12,
1760,
304,
267,
862,
26,
288,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
3450,
14,
9469,
63,
9484,
9,
288,
308,
14,
2242,
8,
277,
14,
2697,
9,
288,
308,
14,
2254,
8,
1760,
19192,
78,
358,
288,
900,
14,
4532,
8,
16,
14,
18,
9,
267,
3753,
26,
288,
308,
14,
1600,
342,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
ikvk/imap_tools
|
tests/messages_data/rfc2822/example06.py
|
1
|
1239
|
import datetime
DATA = dict(
subject='Re: Saying Hello',
from_='mary@example.net',
to=('jdoe@machine.example',),
cc=(),
bcc=(),
reply_to=('smith@home.example',),
date=datetime.datetime(1997, 11, 21, 10, 1, 10, tzinfo=datetime.timezone(datetime.timedelta(-1, 64800))),
date_str='Fri, 21 Nov 1997 10:01:10 -0600',
text='This is a reply to your hello.\r\n',
html='',
headers={'from': ('Mary Smith <mary@example.net>',), 'to': ('John Doe <jdoe@machine.example>',), 'reply-to': ('"Mary Smith: Personal Account" <smith@home.example>',), 'subject': ('Re: Saying Hello',), 'date': ('Fri, 21 Nov 1997 10:01:10 -0600',), 'message-id': ('<3456@example.net>',), 'in-reply-to': ('<1234@local.machine.example>',), 'references': ('<1234@local.machine.example>',)},
attachments=[],
from_values={'email': 'mary@example.net', 'name': 'Mary Smith', 'full': 'Mary Smith <mary@example.net>'},
to_values=({'email': 'jdoe@machine.example', 'name': 'John Doe', 'full': 'John Doe <jdoe@machine.example>'},),
cc_values=(),
bcc_values=(),
reply_to_values=({'email': 'smith@home.example', 'name': 'Mary Smith: Personal Account', 'full': 'Mary Smith: Personal Account <smith@home.example>'},),
)
|
apache-2.0
|
[
646,
2197,
1362,
199,
3998,
275,
1211,
8,
272,
5420,
534,
497,
26,
428,
1187,
316,
23833,
297,
272,
687,
7993,
1694,
32,
2694,
14,
846,
297,
272,
370,
7782,
74,
1117,
69,
32,
6744,
14,
2694,
5529,
272,
7429,
16729,
272,
330,
2055,
16729,
272,
9351,
63,
475,
7782,
3300,
448,
32,
4219,
14,
2694,
5529,
272,
1434,
29,
2083,
14,
2083,
8,
7155,
23,
12,
4119,
12,
7829,
12,
1616,
12,
413,
12,
1616,
12,
10313,
29,
2083,
14,
7145,
8,
2083,
14,
7473,
2801,
17,
12,
5049,
6718,
11508,
272,
1434,
63,
495,
534,
22533,
12,
7829,
3091,
86,
9013,
23,
1616,
26,
614,
26,
709,
446,
1690,
383,
297,
272,
1318,
534,
2765,
365,
282,
9351,
370,
2195,
16509,
3134,
82,
60,
78,
297,
272,
3517,
4581,
272,
2323,
3713,
504,
356,
661,
45,
695,
25924,
665,
1694,
32,
2694,
14,
846,
4206,
395,
283,
475,
356,
661,
12923,
30795,
665,
74,
1117,
69,
32,
6744,
14,
2694,
4206,
395,
283,
8102,
13,
475,
356,
661,
2,
45,
695,
25924,
26,
8028,
279,
9973,
2,
665,
3300,
448,
32,
4219,
14,
2694,
4206,
395,
283,
5875,
356,
661,
497,
26,
428,
1187,
316,
23833,
5529,
283,
602,
356,
661,
22533,
12,
7829,
3091,
86,
9013,
23,
1616,
26,
614,
26,
709,
446,
1690,
383,
5529,
283,
1188,
13,
344,
356,
19990,
1082,
1367,
32,
2694,
14,
846,
4206,
395,
283,
262,
13,
8102,
13,
475,
356,
19990,
4321,
32,
1832,
14,
6744,
14,
2694,
4206,
395,
283,
12635,
356,
19990,
4321,
32,
1832,
14,
6744,
14,
2694,
4206,
16658,
272,
18912,
6034,
272,
687,
63,
1459,
3713,
2123,
356,
283,
1694,
32,
2694,
14,
846,
297,
283,
354,
356,
283,
45,
695,
25924,
297,
283,
2861,
356,
283,
45,
695,
25924,
665,
1694,
32,
2694,
14,
846,
30,
2267,
272,
370,
63,
1459,
2687,
1445,
2123,
356,
283,
74,
1117,
69,
32,
6744,
14,
2694,
297,
283,
354,
356,
283,
12923,
30795,
297,
283,
2861,
356,
283,
12923,
30795,
665,
74,
1117,
69,
32,
6744,
14,
2694,
30,
2267,
395,
272,
7429,
63,
1459,
16729,
272,
330,
2055,
63,
1459,
16729,
272,
9351,
63,
475,
63,
1459,
2687,
1445,
2123,
356,
283,
3300,
448,
32,
4219,
14,
2694,
297,
283,
354,
356,
283,
45,
695,
25924,
26,
8028,
279,
9973,
297,
283,
2861,
356,
283,
45,
695,
25924,
26,
8028,
279,
9973,
665,
3300,
448,
32,
4219,
14,
2694,
30,
2267,
395,
199,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2197,
1362,
199,
3998,
275,
1211,
8,
272,
5420,
534,
497,
26,
428,
1187,
316,
23833,
297,
272,
687,
7993,
1694,
32,
2694,
14,
846,
297,
272,
370,
7782,
74,
1117,
69,
32,
6744,
14,
2694,
5529,
272,
7429,
16729,
272,
330,
2055,
16729,
272,
9351,
63,
475,
7782,
3300,
448,
32,
4219,
14,
2694,
5529,
272,
1434,
29,
2083,
14,
2083,
8,
7155,
23,
12,
4119,
12,
7829,
12,
1616,
12,
413,
12,
1616,
12,
10313,
29,
2083,
14,
7145,
8,
2083,
14,
7473,
2801,
17,
12,
5049,
6718,
11508,
272,
1434,
63,
495,
534,
22533,
12,
7829,
3091,
86,
9013,
23,
1616,
26,
614,
26,
709,
446,
1690,
383,
297,
272,
1318,
534,
2765,
365,
282,
9351,
370,
2195,
16509,
3134,
82,
60,
78,
297,
272,
3517,
4581,
272,
2323,
3713,
504,
356,
661,
45,
695,
25924,
665,
1694,
32,
2694,
14,
846,
4206,
395,
283,
475,
356,
661,
12923,
30795,
665,
74,
1117,
69,
32,
6744,
14,
2694,
4206,
395,
283,
8102,
13,
475,
356,
661,
2,
45,
695,
25924,
26,
8028,
279,
9973,
2,
665,
3300,
448,
32,
4219,
14,
2694,
4206,
395,
283,
5875,
356,
661,
497,
26,
428,
1187,
316,
23833,
5529,
283,
602,
356,
661,
22533,
12,
7829,
3091,
86,
9013,
23,
1616,
26,
614,
26,
709,
446,
1690,
383,
5529,
283,
1188,
13,
344,
356,
19990,
1082,
1367,
32,
2694,
14,
846,
4206,
395,
283,
262,
13,
8102,
13,
475,
356,
19990,
4321,
32,
1832,
14,
6744,
14,
2694,
4206,
395,
283,
12635,
356,
19990,
4321,
32,
1832,
14,
6744,
14,
2694,
4206,
16658,
272,
18912,
6034,
272,
687,
63,
1459,
3713,
2123,
356,
283,
1694,
32,
2694,
14,
846,
297,
283,
354,
356,
283,
45,
695,
25924,
297,
283,
2861,
356,
283,
45,
695,
25924,
665,
1694,
32,
2694,
14,
846,
30,
2267,
272,
370,
63,
1459,
2687,
1445,
2123,
356,
283,
74,
1117,
69,
32,
6744,
14,
2694,
297,
283,
354,
356,
283,
12923,
30795,
297,
283,
2861,
356,
283,
12923,
30795,
665,
74,
1117,
69,
32,
6744,
14,
2694,
30,
2267,
395,
272,
7429,
63,
1459,
16729,
272,
330,
2055,
63,
1459,
16729,
272,
9351,
63,
475,
63,
1459,
2687,
1445,
2123,
356,
283,
3300,
448,
32,
4219,
14,
2694,
297,
283,
354,
356,
283,
45,
695,
25924,
26,
8028,
279,
9973,
297,
283,
2861,
356,
283,
45,
695,
25924,
26,
8028,
279,
9973,
665,
3300,
448,
32,
4219,
14,
2694,
30,
2267,
395,
199,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
gvaf/breakpad
|
src/testing/scripts/upload.py
|
2511
|
51024
|
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tool for uploading diffs from a version control system to the codereview app.
Usage summary: upload.py [options] [-- diff_options]
Diff options are passed to the diff command of the underlying system.
Supported version control systems:
Git
Mercurial
Subversion
It is important for Git/Mercurial users to specify a tree/node/branch to diff
against by using the '--rev' option.
"""
# This code is derived from appcfg.py in the App Engine SDK (open source),
# and from ASPN recipe #146306.
import cookielib
import getpass
import logging
import md5
import mimetypes
import optparse
import os
import re
import socket
import subprocess
import sys
import urllib
import urllib2
import urlparse
try:
import readline
except ImportError:
pass
# The logging verbosity:
# 0: Errors only.
# 1: Status messages.
# 2: Info logs.
# 3: Debug logs.
verbosity = 1
# Max size of patch or base file.
MAX_UPLOAD_SIZE = 900 * 1024
def GetEmail(prompt):
"""Prompts the user for their email address and returns it.
The last used email address is saved to a file and offered up as a suggestion
to the user. If the user presses enter without typing in anything the last
used email address is used. If the user enters a new address, it is saved
for next time we prompt.
"""
last_email_file_name = os.path.expanduser("~/.last_codereview_email_address")
last_email = ""
if os.path.exists(last_email_file_name):
try:
last_email_file = open(last_email_file_name, "r")
last_email = last_email_file.readline().strip("\n")
last_email_file.close()
prompt += " [%s]" % last_email
except IOError, e:
pass
email = raw_input(prompt + ": ").strip()
if email:
try:
last_email_file = open(last_email_file_name, "w")
last_email_file.write(email)
last_email_file.close()
except IOError, e:
pass
else:
email = last_email
return email
def StatusUpdate(msg):
"""Print a status message to stdout.
If 'verbosity' is greater than 0, print the message.
Args:
msg: The string to print.
"""
if verbosity > 0:
print msg
def ErrorExit(msg):
"""Print an error message to stderr and exit."""
print >>sys.stderr, msg
sys.exit(1)
class ClientLoginError(urllib2.HTTPError):
"""Raised to indicate there was an error authenticating with ClientLogin."""
def __init__(self, url, code, msg, headers, args):
urllib2.HTTPError.__init__(self, url, code, msg, headers, None)
self.args = args
self.reason = args["Error"]
class AbstractRpcServer(object):
"""Provides a common interface for a simple RPC server."""
def __init__(self, host, auth_function, host_override=None, extra_headers={},
save_cookies=False):
"""Creates a new HttpRpcServer.
Args:
host: The host to send requests to.
auth_function: A function that takes no arguments and returns an
(email, password) tuple when called. Will be called if authentication
is required.
host_override: The host header to send to the server (defaults to host).
extra_headers: A dict of extra headers to append to every request.
save_cookies: If True, save the authentication cookies to local disk.
If False, use an in-memory cookiejar instead. Subclasses must
implement this functionality. Defaults to False.
"""
self.host = host
self.host_override = host_override
self.auth_function = auth_function
self.authenticated = False
self.extra_headers = extra_headers
self.save_cookies = save_cookies
self.opener = self._GetOpener()
if self.host_override:
logging.info("Server: %s; Host: %s", self.host, self.host_override)
else:
logging.info("Server: %s", self.host)
def _GetOpener(self):
"""Returns an OpenerDirector for making HTTP requests.
Returns:
A urllib2.OpenerDirector object.
"""
raise NotImplementedError()
def _CreateRequest(self, url, data=None):
"""Creates a new urllib request."""
logging.debug("Creating request for: '%s' with payload:\n%s", url, data)
req = urllib2.Request(url, data=data)
if self.host_override:
req.add_header("Host", self.host_override)
for key, value in self.extra_headers.iteritems():
req.add_header(key, value)
return req
def _GetAuthToken(self, email, password):
"""Uses ClientLogin to authenticate the user, returning an auth token.
Args:
email: The user's email address
password: The user's password
Raises:
ClientLoginError: If there was an error authenticating with ClientLogin.
HTTPError: If there was some other form of HTTP error.
Returns:
The authentication token returned by ClientLogin.
"""
account_type = "GOOGLE"
if self.host.endswith(".google.com"):
# Needed for use inside Google.
account_type = "HOSTED"
req = self._CreateRequest(
url="https://www.google.com/accounts/ClientLogin",
data=urllib.urlencode({
"Email": email,
"Passwd": password,
"service": "ah",
"source": "rietveld-codereview-upload",
"accountType": account_type,
}),
)
try:
response = self.opener.open(req)
response_body = response.read()
response_dict = dict(x.split("=")
for x in response_body.split("\n") if x)
return response_dict["Auth"]
except urllib2.HTTPError, e:
if e.code == 403:
body = e.read()
response_dict = dict(x.split("=", 1) for x in body.split("\n") if x)
raise ClientLoginError(req.get_full_url(), e.code, e.msg,
e.headers, response_dict)
else:
raise
def _GetAuthCookie(self, auth_token):
"""Fetches authentication cookies for an authentication token.
Args:
auth_token: The authentication token returned by ClientLogin.
Raises:
HTTPError: If there was an error fetching the authentication cookies.
"""
# This is a dummy value to allow us to identify when we're successful.
continue_location = "http://localhost/"
args = {"continue": continue_location, "auth": auth_token}
req = self._CreateRequest("http://%s/_ah/login?%s" %
(self.host, urllib.urlencode(args)))
try:
response = self.opener.open(req)
except urllib2.HTTPError, e:
response = e
if (response.code != 302 or
response.info()["location"] != continue_location):
raise urllib2.HTTPError(req.get_full_url(), response.code, response.msg,
response.headers, response.fp)
self.authenticated = True
def _Authenticate(self):
"""Authenticates the user.
The authentication process works as follows:
1) We get a username and password from the user
2) We use ClientLogin to obtain an AUTH token for the user
(see http://code.google.com/apis/accounts/AuthForInstalledApps.html).
3) We pass the auth token to /_ah/login on the server to obtain an
authentication cookie. If login was successful, it tries to redirect
us to the URL we provided.
If we attempt to access the upload API without first obtaining an
authentication cookie, it returns a 401 response and directs us to
authenticate ourselves with ClientLogin.
"""
for i in range(3):
credentials = self.auth_function()
try:
auth_token = self._GetAuthToken(credentials[0], credentials[1])
except ClientLoginError, e:
if e.reason == "BadAuthentication":
print >>sys.stderr, "Invalid username or password."
continue
if e.reason == "CaptchaRequired":
print >>sys.stderr, (
"Please go to\n"
"https://www.google.com/accounts/DisplayUnlockCaptcha\n"
"and verify you are a human. Then try again.")
break
if e.reason == "NotVerified":
print >>sys.stderr, "Account not verified."
break
if e.reason == "TermsNotAgreed":
print >>sys.stderr, "User has not agreed to TOS."
break
if e.reason == "AccountDeleted":
print >>sys.stderr, "The user account has been deleted."
break
if e.reason == "AccountDisabled":
print >>sys.stderr, "The user account has been disabled."
break
if e.reason == "ServiceDisabled":
print >>sys.stderr, ("The user's access to the service has been "
"disabled.")
break
if e.reason == "ServiceUnavailable":
print >>sys.stderr, "The service is not available; try again later."
break
raise
self._GetAuthCookie(auth_token)
return
def Send(self, request_path, payload=None,
content_type="application/octet-stream",
timeout=None,
**kwargs):
"""Sends an RPC and returns the response.
Args:
request_path: The path to send the request to, eg /api/appversion/create.
payload: The body of the request, or None to send an empty request.
content_type: The Content-Type header to use.
timeout: timeout in seconds; default None i.e. no timeout.
(Note: for large requests on OS X, the timeout doesn't work right.)
kwargs: Any keyword arguments are converted into query string parameters.
Returns:
The response body, as a string.
"""
# TODO: Don't require authentication. Let the server say
# whether it is necessary.
if not self.authenticated:
self._Authenticate()
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
tries = 0
while True:
tries += 1
args = dict(kwargs)
url = "http://%s%s" % (self.host, request_path)
if args:
url += "?" + urllib.urlencode(args)
req = self._CreateRequest(url=url, data=payload)
req.add_header("Content-Type", content_type)
try:
f = self.opener.open(req)
response = f.read()
f.close()
return response
except urllib2.HTTPError, e:
if tries > 3:
raise
elif e.code == 401:
self._Authenticate()
## elif e.code >= 500 and e.code < 600:
## # Server Error - try again.
## continue
else:
raise
finally:
socket.setdefaulttimeout(old_timeout)
class HttpRpcServer(AbstractRpcServer):
"""Provides a simplified RPC-style interface for HTTP requests."""
def _Authenticate(self):
"""Save the cookie jar after authentication."""
super(HttpRpcServer, self)._Authenticate()
if self.save_cookies:
StatusUpdate("Saving authentication cookies to %s" % self.cookie_file)
self.cookie_jar.save()
def _GetOpener(self):
"""Returns an OpenerDirector that supports cookies and ignores redirects.
Returns:
A urllib2.OpenerDirector object.
"""
opener = urllib2.OpenerDirector()
opener.add_handler(urllib2.ProxyHandler())
opener.add_handler(urllib2.UnknownHandler())
opener.add_handler(urllib2.HTTPHandler())
opener.add_handler(urllib2.HTTPDefaultErrorHandler())
opener.add_handler(urllib2.HTTPSHandler())
opener.add_handler(urllib2.HTTPErrorProcessor())
if self.save_cookies:
self.cookie_file = os.path.expanduser("~/.codereview_upload_cookies")
self.cookie_jar = cookielib.MozillaCookieJar(self.cookie_file)
if os.path.exists(self.cookie_file):
try:
self.cookie_jar.load()
self.authenticated = True
StatusUpdate("Loaded authentication cookies from %s" %
self.cookie_file)
except (cookielib.LoadError, IOError):
# Failed to load cookies - just ignore them.
pass
else:
# Create an empty cookie file with mode 600
fd = os.open(self.cookie_file, os.O_CREAT, 0600)
os.close(fd)
# Always chmod the cookie file
os.chmod(self.cookie_file, 0600)
else:
# Don't save cookies across runs of update.py.
self.cookie_jar = cookielib.CookieJar()
opener.add_handler(urllib2.HTTPCookieProcessor(self.cookie_jar))
return opener
parser = optparse.OptionParser(usage="%prog [options] [-- diff_options]")
parser.add_option("-y", "--assume_yes", action="store_true",
dest="assume_yes", default=False,
help="Assume that the answer to yes/no questions is 'yes'.")
# Logging
group = parser.add_option_group("Logging options")
group.add_option("-q", "--quiet", action="store_const", const=0,
dest="verbose", help="Print errors only.")
group.add_option("-v", "--verbose", action="store_const", const=2,
dest="verbose", default=1,
help="Print info level logs (default).")
group.add_option("--noisy", action="store_const", const=3,
dest="verbose", help="Print all logs.")
# Review server
group = parser.add_option_group("Review server options")
group.add_option("-s", "--server", action="store", dest="server",
default="codereview.appspot.com",
metavar="SERVER",
help=("The server to upload to. The format is host[:port]. "
"Defaults to 'codereview.appspot.com'."))
group.add_option("-e", "--email", action="store", dest="email",
metavar="EMAIL", default=None,
help="The username to use. Will prompt if omitted.")
group.add_option("-H", "--host", action="store", dest="host",
metavar="HOST", default=None,
help="Overrides the Host header sent with all RPCs.")
group.add_option("--no_cookies", action="store_false",
dest="save_cookies", default=True,
help="Do not save authentication cookies to local disk.")
# Issue
group = parser.add_option_group("Issue options")
group.add_option("-d", "--description", action="store", dest="description",
metavar="DESCRIPTION", default=None,
help="Optional description when creating an issue.")
group.add_option("-f", "--description_file", action="store",
dest="description_file", metavar="DESCRIPTION_FILE",
default=None,
help="Optional path of a file that contains "
"the description when creating an issue.")
group.add_option("-r", "--reviewers", action="store", dest="reviewers",
metavar="REVIEWERS", default=None,
help="Add reviewers (comma separated email addresses).")
group.add_option("--cc", action="store", dest="cc",
metavar="CC", default=None,
help="Add CC (comma separated email addresses).")
# Upload options
group = parser.add_option_group("Patch options")
group.add_option("-m", "--message", action="store", dest="message",
metavar="MESSAGE", default=None,
help="A message to identify the patch. "
"Will prompt if omitted.")
group.add_option("-i", "--issue", type="int", action="store",
metavar="ISSUE", default=None,
help="Issue number to which to add. Defaults to new issue.")
group.add_option("--download_base", action="store_true",
dest="download_base", default=False,
help="Base files will be downloaded by the server "
"(side-by-side diffs may not work on files with CRs).")
group.add_option("--rev", action="store", dest="revision",
metavar="REV", default=None,
help="Branch/tree/revision to diff against (used by DVCS).")
group.add_option("--send_mail", action="store_true",
dest="send_mail", default=False,
help="Send notification email to reviewers.")
def GetRpcServer(options):
"""Returns an instance of an AbstractRpcServer.
Returns:
A new AbstractRpcServer, on which RPC calls can be made.
"""
rpc_server_class = HttpRpcServer
def GetUserCredentials():
"""Prompts the user for a username and password."""
email = options.email
if email is None:
email = GetEmail("Email (login for uploading to %s)" % options.server)
password = getpass.getpass("Password for %s: " % email)
return (email, password)
# If this is the dev_appserver, use fake authentication.
host = (options.host or options.server).lower()
if host == "localhost" or host.startswith("localhost:"):
email = options.email
if email is None:
email = "test@example.com"
logging.info("Using debug user %s. Override with --email" % email)
server = rpc_server_class(
options.server,
lambda: (email, "password"),
host_override=options.host,
extra_headers={"Cookie":
'dev_appserver_login="%s:False"' % email},
save_cookies=options.save_cookies)
# Don't try to talk to ClientLogin.
server.authenticated = True
return server
return rpc_server_class(options.server, GetUserCredentials,
host_override=options.host,
save_cookies=options.save_cookies)
def EncodeMultipartFormData(fields, files):
"""Encode form fields for multipart/form-data.
Args:
fields: A sequence of (name, value) elements for regular form fields.
files: A sequence of (name, filename, value) elements for data to be
uploaded as files.
Returns:
(content_type, body) ready for httplib.HTTP instance.
Source:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306
"""
BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
CRLF = '\r\n'
lines = []
for (key, value) in fields:
lines.append('--' + BOUNDARY)
lines.append('Content-Disposition: form-data; name="%s"' % key)
lines.append('')
lines.append(value)
for (key, filename, value) in files:
lines.append('--' + BOUNDARY)
lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' %
(key, filename))
lines.append('Content-Type: %s' % GetContentType(filename))
lines.append('')
lines.append(value)
lines.append('--' + BOUNDARY + '--')
lines.append('')
body = CRLF.join(lines)
content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
return content_type, body
def GetContentType(filename):
"""Helper to guess the content-type from the filename."""
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
# Use a shell for subcommands on Windows to get a PATH search.
use_shell = sys.platform.startswith("win")
def RunShellWithReturnCode(command, print_output=False,
universal_newlines=True):
"""Executes a command and returns the output from stdout and the return code.
Args:
command: Command to execute.
print_output: If True, the output is printed to stdout.
If False, both stdout and stderr are ignored.
universal_newlines: Use universal_newlines flag (default: True).
Returns:
Tuple (output, return code)
"""
logging.info("Running %s", command)
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=use_shell, universal_newlines=universal_newlines)
if print_output:
output_array = []
while True:
line = p.stdout.readline()
if not line:
break
print line.strip("\n")
output_array.append(line)
output = "".join(output_array)
else:
output = p.stdout.read()
p.wait()
errout = p.stderr.read()
if print_output and errout:
print >>sys.stderr, errout
p.stdout.close()
p.stderr.close()
return output, p.returncode
def RunShell(command, silent_ok=False, universal_newlines=True,
print_output=False):
data, retcode = RunShellWithReturnCode(command, print_output,
universal_newlines)
if retcode:
ErrorExit("Got error status from %s:\n%s" % (command, data))
if not silent_ok and not data:
ErrorExit("No output from %s" % command)
return data
class VersionControlSystem(object):
"""Abstract base class providing an interface to the VCS."""
def __init__(self, options):
"""Constructor.
Args:
options: Command line options.
"""
self.options = options
def GenerateDiff(self, args):
"""Return the current diff as a string.
Args:
args: Extra arguments to pass to the diff command.
"""
raise NotImplementedError(
"abstract method -- subclass %s must override" % self.__class__)
def GetUnknownFiles(self):
"""Return a list of files unknown to the VCS."""
raise NotImplementedError(
"abstract method -- subclass %s must override" % self.__class__)
def CheckForUnknownFiles(self):
"""Show an "are you sure?" prompt if there are unknown files."""
unknown_files = self.GetUnknownFiles()
if unknown_files:
print "The following files are not added to version control:"
for line in unknown_files:
print line
prompt = "Are you sure to continue?(y/N) "
answer = raw_input(prompt).strip()
if answer != "y":
ErrorExit("User aborted")
def GetBaseFile(self, filename):
"""Get the content of the upstream version of a file.
Returns:
A tuple (base_content, new_content, is_binary, status)
base_content: The contents of the base file.
new_content: For text files, this is empty. For binary files, this is
the contents of the new file, since the diff output won't contain
information to reconstruct the current file.
is_binary: True iff the file is binary.
status: The status of the file.
"""
raise NotImplementedError(
"abstract method -- subclass %s must override" % self.__class__)
def GetBaseFiles(self, diff):
"""Helper that calls GetBase file for each file in the patch.
Returns:
A dictionary that maps from filename to GetBaseFile's tuple. Filenames
are retrieved based on lines that start with "Index:" or
"Property changes on:".
"""
files = {}
for line in diff.splitlines(True):
if line.startswith('Index:') or line.startswith('Property changes on:'):
unused, filename = line.split(':', 1)
# On Windows if a file has property changes its filename uses '\'
# instead of '/'.
filename = filename.strip().replace('\\', '/')
files[filename] = self.GetBaseFile(filename)
return files
def UploadBaseFiles(self, issue, rpc_server, patch_list, patchset, options,
files):
"""Uploads the base files (and if necessary, the current ones as well)."""
def UploadFile(filename, file_id, content, is_binary, status, is_base):
"""Uploads a file to the server."""
file_too_large = False
if is_base:
type = "base"
else:
type = "current"
if len(content) > MAX_UPLOAD_SIZE:
print ("Not uploading the %s file for %s because it's too large." %
(type, filename))
file_too_large = True
content = ""
checksum = md5.new(content).hexdigest()
if options.verbose > 0 and not file_too_large:
print "Uploading %s file for %s" % (type, filename)
url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
form_fields = [("filename", filename),
("status", status),
("checksum", checksum),
("is_binary", str(is_binary)),
("is_current", str(not is_base)),
]
if file_too_large:
form_fields.append(("file_too_large", "1"))
if options.email:
form_fields.append(("user", options.email))
ctype, body = EncodeMultipartFormData(form_fields,
[("data", filename, content)])
response_body = rpc_server.Send(url, body,
content_type=ctype)
if not response_body.startswith("OK"):
StatusUpdate(" --> %s" % response_body)
sys.exit(1)
patches = dict()
[patches.setdefault(v, k) for k, v in patch_list]
for filename in patches.keys():
base_content, new_content, is_binary, status = files[filename]
file_id_str = patches.get(filename)
if file_id_str.find("nobase") != -1:
base_content = None
file_id_str = file_id_str[file_id_str.rfind("_") + 1:]
file_id = int(file_id_str)
if base_content != None:
UploadFile(filename, file_id, base_content, is_binary, status, True)
if new_content != None:
UploadFile(filename, file_id, new_content, is_binary, status, False)
def IsImage(self, filename):
"""Returns true if the filename has an image extension."""
mimetype = mimetypes.guess_type(filename)[0]
if not mimetype:
return False
return mimetype.startswith("image/")
class SubversionVCS(VersionControlSystem):
"""Implementation of the VersionControlSystem interface for Subversion."""
def __init__(self, options):
super(SubversionVCS, self).__init__(options)
if self.options.revision:
match = re.match(r"(\d+)(:(\d+))?", self.options.revision)
if not match:
ErrorExit("Invalid Subversion revision %s." % self.options.revision)
self.rev_start = match.group(1)
self.rev_end = match.group(3)
else:
self.rev_start = self.rev_end = None
# Cache output from "svn list -r REVNO dirname".
# Keys: dirname, Values: 2-tuple (ouput for start rev and end rev).
self.svnls_cache = {}
# SVN base URL is required to fetch files deleted in an older revision.
# Result is cached to not guess it over and over again in GetBaseFile().
required = self.options.download_base or self.options.revision is not None
self.svn_base = self._GuessBase(required)
def GuessBase(self, required):
"""Wrapper for _GuessBase."""
return self.svn_base
def _GuessBase(self, required):
"""Returns the SVN base URL.
Args:
required: If true, exits if the url can't be guessed, otherwise None is
returned.
"""
info = RunShell(["svn", "info"])
for line in info.splitlines():
words = line.split()
if len(words) == 2 and words[0] == "URL:":
url = words[1]
scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
username, netloc = urllib.splituser(netloc)
if username:
logging.info("Removed username from base URL")
if netloc.endswith("svn.python.org"):
if netloc == "svn.python.org":
if path.startswith("/projects/"):
path = path[9:]
elif netloc != "pythondev@svn.python.org":
ErrorExit("Unrecognized Python URL: %s" % url)
base = "http://svn.python.org/view/*checkout*%s/" % path
logging.info("Guessed Python base = %s", base)
elif netloc.endswith("svn.collab.net"):
if path.startswith("/repos/"):
path = path[6:]
base = "http://svn.collab.net/viewvc/*checkout*%s/" % path
logging.info("Guessed CollabNet base = %s", base)
elif netloc.endswith(".googlecode.com"):
path = path + "/"
base = urlparse.urlunparse(("http", netloc, path, params,
query, fragment))
logging.info("Guessed Google Code base = %s", base)
else:
path = path + "/"
base = urlparse.urlunparse((scheme, netloc, path, params,
query, fragment))
logging.info("Guessed base = %s", base)
return base
if required:
ErrorExit("Can't find URL in output from svn info")
return None
def GenerateDiff(self, args):
cmd = ["svn", "diff"]
if self.options.revision:
cmd += ["-r", self.options.revision]
cmd.extend(args)
data = RunShell(cmd)
count = 0
for line in data.splitlines():
if line.startswith("Index:") or line.startswith("Property changes on:"):
count += 1
logging.info(line)
if not count:
ErrorExit("No valid patches found in output from svn diff")
return data
def _CollapseKeywords(self, content, keyword_str):
"""Collapses SVN keywords."""
# svn cat translates keywords but svn diff doesn't. As a result of this
# behavior patching.PatchChunks() fails with a chunk mismatch error.
# This part was originally written by the Review Board development team
# who had the same problem (http://reviews.review-board.org/r/276/).
# Mapping of keywords to known aliases
svn_keywords = {
# Standard keywords
'Date': ['Date', 'LastChangedDate'],
'Revision': ['Revision', 'LastChangedRevision', 'Rev'],
'Author': ['Author', 'LastChangedBy'],
'HeadURL': ['HeadURL', 'URL'],
'Id': ['Id'],
# Aliases
'LastChangedDate': ['LastChangedDate', 'Date'],
'LastChangedRevision': ['LastChangedRevision', 'Rev', 'Revision'],
'LastChangedBy': ['LastChangedBy', 'Author'],
'URL': ['URL', 'HeadURL'],
}
def repl(m):
if m.group(2):
return "$%s::%s$" % (m.group(1), " " * len(m.group(3)))
return "$%s$" % m.group(1)
keywords = [keyword
for name in keyword_str.split(" ")
for keyword in svn_keywords.get(name, [])]
return re.sub(r"\$(%s):(:?)([^\$]+)\$" % '|'.join(keywords), repl, content)
def GetUnknownFiles(self):
status = RunShell(["svn", "status", "--ignore-externals"], silent_ok=True)
unknown_files = []
for line in status.split("\n"):
if line and line[0] == "?":
unknown_files.append(line)
return unknown_files
def ReadFile(self, filename):
"""Returns the contents of a file."""
file = open(filename, 'rb')
result = ""
try:
result = file.read()
finally:
file.close()
return result
def GetStatus(self, filename):
"""Returns the status of a file."""
if not self.options.revision:
status = RunShell(["svn", "status", "--ignore-externals", filename])
if not status:
ErrorExit("svn status returned no output for %s" % filename)
status_lines = status.splitlines()
# If file is in a cl, the output will begin with
# "\n--- Changelist 'cl_name':\n". See
# http://svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
if (len(status_lines) == 3 and
not status_lines[0] and
status_lines[1].startswith("--- Changelist")):
status = status_lines[2]
else:
status = status_lines[0]
# If we have a revision to diff against we need to run "svn list"
# for the old and the new revision and compare the results to get
# the correct status for a file.
else:
dirname, relfilename = os.path.split(filename)
if dirname not in self.svnls_cache:
cmd = ["svn", "list", "-r", self.rev_start, dirname or "."]
out, returncode = RunShellWithReturnCode(cmd)
if returncode:
ErrorExit("Failed to get status for %s." % filename)
old_files = out.splitlines()
args = ["svn", "list"]
if self.rev_end:
args += ["-r", self.rev_end]
cmd = args + [dirname or "."]
out, returncode = RunShellWithReturnCode(cmd)
if returncode:
ErrorExit("Failed to run command %s" % cmd)
self.svnls_cache[dirname] = (old_files, out.splitlines())
old_files, new_files = self.svnls_cache[dirname]
if relfilename in old_files and relfilename not in new_files:
status = "D "
elif relfilename in old_files and relfilename in new_files:
status = "M "
else:
status = "A "
return status
def GetBaseFile(self, filename):
status = self.GetStatus(filename)
base_content = None
new_content = None
# If a file is copied its status will be "A +", which signifies
# "addition-with-history". See "svn st" for more information. We need to
# upload the original file or else diff parsing will fail if the file was
# edited.
if status[0] == "A" and status[3] != "+":
# We'll need to upload the new content if we're adding a binary file
# since diff's output won't contain it.
mimetype = RunShell(["svn", "propget", "svn:mime-type", filename],
silent_ok=True)
base_content = ""
is_binary = mimetype and not mimetype.startswith("text/")
if is_binary and self.IsImage(filename):
new_content = self.ReadFile(filename)
elif (status[0] in ("M", "D", "R") or
(status[0] == "A" and status[3] == "+") or # Copied file.
(status[0] == " " and status[1] == "M")): # Property change.
args = []
if self.options.revision:
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
else:
# Don't change filename, it's needed later.
url = filename
args += ["-r", "BASE"]
cmd = ["svn"] + args + ["propget", "svn:mime-type", url]
mimetype, returncode = RunShellWithReturnCode(cmd)
if returncode:
# File does not exist in the requested revision.
# Reset mimetype, it contains an error message.
mimetype = ""
get_base = False
is_binary = mimetype and not mimetype.startswith("text/")
if status[0] == " ":
# Empty base content just to force an upload.
base_content = ""
elif is_binary:
if self.IsImage(filename):
get_base = True
if status[0] == "M":
if not self.rev_end:
new_content = self.ReadFile(filename)
else:
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_end)
new_content = RunShell(["svn", "cat", url],
universal_newlines=True, silent_ok=True)
else:
base_content = ""
else:
get_base = True
if get_base:
if is_binary:
universal_newlines = False
else:
universal_newlines = True
if self.rev_start:
# "svn cat -r REV delete_file.txt" doesn't work. cat requires
# the full URL with "@REV" appended instead of using "-r" option.
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
base_content = RunShell(["svn", "cat", url],
universal_newlines=universal_newlines,
silent_ok=True)
else:
base_content = RunShell(["svn", "cat", filename],
universal_newlines=universal_newlines,
silent_ok=True)
if not is_binary:
args = []
if self.rev_start:
url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
else:
url = filename
args += ["-r", "BASE"]
cmd = ["svn"] + args + ["propget", "svn:keywords", url]
keywords, returncode = RunShellWithReturnCode(cmd)
if keywords and not returncode:
base_content = self._CollapseKeywords(base_content, keywords)
else:
StatusUpdate("svn status returned unexpected output: %s" % status)
sys.exit(1)
return base_content, new_content, is_binary, status[0:5]
class GitVCS(VersionControlSystem):
"""Implementation of the VersionControlSystem interface for Git."""
def __init__(self, options):
super(GitVCS, self).__init__(options)
# Map of filename -> hash of base file.
self.base_hashes = {}
def GenerateDiff(self, extra_args):
# This is more complicated than svn's GenerateDiff because we must convert
# the diff output to include an svn-style "Index:" line as well as record
# the hashes of the base files, so we can upload them along with our diff.
if self.options.revision:
extra_args = [self.options.revision] + extra_args
gitdiff = RunShell(["git", "diff", "--full-index"] + extra_args)
svndiff = []
filecount = 0
filename = None
for line in gitdiff.splitlines():
match = re.match(r"diff --git a/(.*) b/.*$", line)
if match:
filecount += 1
filename = match.group(1)
svndiff.append("Index: %s\n" % filename)
else:
# The "index" line in a git diff looks like this (long hashes elided):
# index 82c0d44..b2cee3f 100755
# We want to save the left hash, as that identifies the base file.
match = re.match(r"index (\w+)\.\.", line)
if match:
self.base_hashes[filename] = match.group(1)
svndiff.append(line + "\n")
if not filecount:
ErrorExit("No valid patches found in output from git diff")
return "".join(svndiff)
def GetUnknownFiles(self):
status = RunShell(["git", "ls-files", "--exclude-standard", "--others"],
silent_ok=True)
return status.splitlines()
def GetBaseFile(self, filename):
hash = self.base_hashes[filename]
base_content = None
new_content = None
is_binary = False
if hash == "0" * 40: # All-zero hash indicates no base file.
status = "A"
base_content = ""
else:
status = "M"
base_content, returncode = RunShellWithReturnCode(["git", "show", hash])
if returncode:
ErrorExit("Got error status from 'git show %s'" % hash)
return (base_content, new_content, is_binary, status)
class MercurialVCS(VersionControlSystem):
"""Implementation of the VersionControlSystem interface for Mercurial."""
def __init__(self, options, repo_dir):
super(MercurialVCS, self).__init__(options)
# Absolute path to repository (we can be in a subdir)
self.repo_dir = os.path.normpath(repo_dir)
# Compute the subdir
cwd = os.path.normpath(os.getcwd())
assert cwd.startswith(self.repo_dir)
self.subdir = cwd[len(self.repo_dir):].lstrip(r"\/")
if self.options.revision:
self.base_rev = self.options.revision
else:
self.base_rev = RunShell(["hg", "parent", "-q"]).split(':')[1].strip()
def _GetRelPath(self, filename):
"""Get relative path of a file according to the current directory,
given its logical path in the repo."""
assert filename.startswith(self.subdir), filename
return filename[len(self.subdir):].lstrip(r"\/")
def GenerateDiff(self, extra_args):
# If no file specified, restrict to the current subdir
extra_args = extra_args or ["."]
cmd = ["hg", "diff", "--git", "-r", self.base_rev] + extra_args
data = RunShell(cmd, silent_ok=True)
svndiff = []
filecount = 0
for line in data.splitlines():
m = re.match("diff --git a/(\S+) b/(\S+)", line)
if m:
# Modify line to make it look like as it comes from svn diff.
# With this modification no changes on the server side are required
# to make upload.py work with Mercurial repos.
# NOTE: for proper handling of moved/copied files, we have to use
# the second filename.
filename = m.group(2)
svndiff.append("Index: %s" % filename)
svndiff.append("=" * 67)
filecount += 1
logging.info(line)
else:
svndiff.append(line)
if not filecount:
ErrorExit("No valid patches found in output from hg diff")
return "\n".join(svndiff) + "\n"
def GetUnknownFiles(self):
"""Return a list of files unknown to the VCS."""
args = []
status = RunShell(["hg", "status", "--rev", self.base_rev, "-u", "."],
silent_ok=True)
unknown_files = []
for line in status.splitlines():
st, fn = line.split(" ", 1)
if st == "?":
unknown_files.append(fn)
return unknown_files
def GetBaseFile(self, filename):
# "hg status" and "hg cat" both take a path relative to the current subdir
# rather than to the repo root, but "hg diff" has given us the full path
# to the repo root.
base_content = ""
new_content = None
is_binary = False
oldrelpath = relpath = self._GetRelPath(filename)
# "hg status -C" returns two lines for moved/copied files, one otherwise
out = RunShell(["hg", "status", "-C", "--rev", self.base_rev, relpath])
out = out.splitlines()
# HACK: strip error message about missing file/directory if it isn't in
# the working copy
if out[0].startswith('%s: ' % relpath):
out = out[1:]
if len(out) > 1:
# Moved/copied => considered as modified, use old filename to
# retrieve base contents
oldrelpath = out[1].strip()
status = "M"
else:
status, _ = out[0].split(' ', 1)
if status != "A":
base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
silent_ok=True)
is_binary = "\0" in base_content # Mercurial's heuristic
if status != "R":
new_content = open(relpath, "rb").read()
is_binary = is_binary or "\0" in new_content
if is_binary and base_content:
# Fetch again without converting newlines
base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
silent_ok=True, universal_newlines=False)
if not is_binary or not self.IsImage(relpath):
new_content = None
return base_content, new_content, is_binary, status
# NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync.
def SplitPatch(data):
"""Splits a patch into separate pieces for each file.
Args:
data: A string containing the output of svn diff.
Returns:
A list of 2-tuple (filename, text) where text is the svn diff output
pertaining to filename.
"""
patches = []
filename = None
diff = []
for line in data.splitlines(True):
new_filename = None
if line.startswith('Index:'):
unused, new_filename = line.split(':', 1)
new_filename = new_filename.strip()
elif line.startswith('Property changes on:'):
unused, temp_filename = line.split(':', 1)
# When a file is modified, paths use '/' between directories, however
# when a property is modified '\' is used on Windows. Make them the same
# otherwise the file shows up twice.
temp_filename = temp_filename.strip().replace('\\', '/')
if temp_filename != filename:
# File has property changes but no modifications, create a new diff.
new_filename = temp_filename
if new_filename:
if filename and diff:
patches.append((filename, ''.join(diff)))
filename = new_filename
diff = [line]
continue
if diff is not None:
diff.append(line)
if filename and diff:
patches.append((filename, ''.join(diff)))
return patches
def UploadSeparatePatches(issue, rpc_server, patchset, data, options):
"""Uploads a separate patch for each file in the diff output.
Returns a list of [patch_key, filename] for each file.
"""
patches = SplitPatch(data)
rv = []
for patch in patches:
if len(patch[1]) > MAX_UPLOAD_SIZE:
print ("Not uploading the patch for " + patch[0] +
" because the file is too large.")
continue
form_fields = [("filename", patch[0])]
if not options.download_base:
form_fields.append(("content_upload", "1"))
files = [("data", "data.diff", patch[1])]
ctype, body = EncodeMultipartFormData(form_fields, files)
url = "/%d/upload_patch/%d" % (int(issue), int(patchset))
print "Uploading patch for " + patch[0]
response_body = rpc_server.Send(url, body, content_type=ctype)
lines = response_body.splitlines()
if not lines or lines[0] != "OK":
StatusUpdate(" --> %s" % response_body)
sys.exit(1)
rv.append([lines[1], patch[0]])
return rv
def GuessVCS(options):
"""Helper to guess the version control system.
This examines the current directory, guesses which VersionControlSystem
we're using, and returns an instance of the appropriate class. Exit with an
error if we can't figure it out.
Returns:
A VersionControlSystem instance. Exits if the VCS can't be guessed.
"""
# Mercurial has a command to get the base directory of a repository
# Try running it, but don't die if we don't have hg installed.
# NOTE: we try Mercurial first as it can sit on top of an SVN working copy.
try:
out, returncode = RunShellWithReturnCode(["hg", "root"])
if returncode == 0:
return MercurialVCS(options, out.strip())
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have hg installed.
raise
# Subversion has a .svn in all working directories.
if os.path.isdir('.svn'):
logging.info("Guessed VCS = Subversion")
return SubversionVCS(options)
# Git has a command to test if you're in a git tree.
# Try running it, but don't die if we don't have git installed.
try:
out, returncode = RunShellWithReturnCode(["git", "rev-parse",
"--is-inside-work-tree"])
if returncode == 0:
return GitVCS(options)
except OSError, (errno, message):
if errno != 2: # ENOENT -- they don't have git installed.
raise
ErrorExit(("Could not guess version control system. "
"Are you in a working copy directory?"))
def RealMain(argv, data=None):
"""The real main function.
Args:
argv: Command line arguments.
data: Diff contents. If None (default) the diff is generated by
the VersionControlSystem implementation returned by GuessVCS().
Returns:
A 2-tuple (issue id, patchset id).
The patchset id is None if the base files are not uploaded by this
script (applies only to SVN checkouts).
"""
logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
"%(lineno)s %(message)s "))
os.environ['LC_ALL'] = 'C'
options, args = parser.parse_args(argv[1:])
global verbosity
verbosity = options.verbose
if verbosity >= 3:
logging.getLogger().setLevel(logging.DEBUG)
elif verbosity >= 2:
logging.getLogger().setLevel(logging.INFO)
vcs = GuessVCS(options)
if isinstance(vcs, SubversionVCS):
# base field is only allowed for Subversion.
# Note: Fetching base files may become deprecated in future releases.
base = vcs.GuessBase(options.download_base)
else:
base = None
if not base and options.download_base:
options.download_base = True
logging.info("Enabled upload of base file")
if not options.assume_yes:
vcs.CheckForUnknownFiles()
if data is None:
data = vcs.GenerateDiff(args)
files = vcs.GetBaseFiles(data)
if verbosity >= 1:
print "Upload server:", options.server, "(change with -s/--server)"
if options.issue:
prompt = "Message describing this patch set: "
else:
prompt = "New issue subject: "
message = options.message or raw_input(prompt).strip()
if not message:
ErrorExit("A non-empty message is required")
rpc_server = GetRpcServer(options)
form_fields = [("subject", message)]
if base:
form_fields.append(("base", base))
if options.issue:
form_fields.append(("issue", str(options.issue)))
if options.email:
form_fields.append(("user", options.email))
if options.reviewers:
for reviewer in options.reviewers.split(','):
if "@" in reviewer and not reviewer.split("@")[1].count(".") == 1:
ErrorExit("Invalid email address: %s" % reviewer)
form_fields.append(("reviewers", options.reviewers))
if options.cc:
for cc in options.cc.split(','):
if "@" in cc and not cc.split("@")[1].count(".") == 1:
ErrorExit("Invalid email address: %s" % cc)
form_fields.append(("cc", options.cc))
description = options.description
if options.description_file:
if options.description:
ErrorExit("Can't specify description and description_file")
file = open(options.description_file, 'r')
description = file.read()
file.close()
if description:
form_fields.append(("description", description))
# Send a hash of all the base file so the server can determine if a copy
# already exists in an earlier patchset.
base_hashes = ""
for file, info in files.iteritems():
if not info[0] is None:
checksum = md5.new(info[0]).hexdigest()
if base_hashes:
base_hashes += "|"
base_hashes += checksum + ":" + file
form_fields.append(("base_hashes", base_hashes))
# If we're uploading base files, don't send the email before the uploads, so
# that it contains the file status.
if options.send_mail and options.download_base:
form_fields.append(("send_mail", "1"))
if not options.download_base:
form_fields.append(("content_upload", "1"))
if len(data) > MAX_UPLOAD_SIZE:
print "Patch is large, so uploading file patches separately."
uploaded_diff_file = []
form_fields.append(("separate_patches", "1"))
else:
uploaded_diff_file = [("data", "data.diff", data)]
ctype, body = EncodeMultipartFormData(form_fields, uploaded_diff_file)
response_body = rpc_server.Send("/upload", body, content_type=ctype)
patchset = None
if not options.download_base or not uploaded_diff_file:
lines = response_body.splitlines()
if len(lines) >= 2:
msg = lines[0]
patchset = lines[1].strip()
patches = [x.split(" ", 1) for x in lines[2:]]
else:
msg = response_body
else:
msg = response_body
StatusUpdate(msg)
if not response_body.startswith("Issue created.") and \
not response_body.startswith("Issue updated."):
sys.exit(0)
issue = msg[msg.rfind("/")+1:]
if not uploaded_diff_file:
result = UploadSeparatePatches(issue, rpc_server, patchset, data, options)
if not options.download_base:
patches = result
if not options.download_base:
vcs.UploadBaseFiles(issue, rpc_server, patches, patchset, options, files)
if options.send_mail:
rpc_server.Send("/" + issue + "/mail", payload="")
return issue, patchset
def main():
try:
RealMain(sys.argv)
except KeyboardInterrupt:
print
StatusUpdate("Interrupted.")
sys.exit(1)
if __name__ == "__main__":
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
5157,
367,
24349,
14981,
687,
282,
1015,
3304,
2656,
370,
314,
1233,
8578,
1145,
14,
199,
199,
7692,
6212,
26,
5802,
14,
647,
359,
1419,
61,
19344,
3915,
63,
1419,
61,
199,
199,
10746,
1511,
787,
3032,
370,
314,
3915,
1414,
402,
314,
8793,
2656,
14,
199,
199,
10682,
1015,
3304,
10460,
26,
523,
12579,
523,
30522,
523,
31098,
199,
199,
7940,
365,
11012,
367,
12579,
15,
16797,
18977,
4390,
370,
4165,
282,
3123,
15,
932,
15,
4694,
370,
3915,
199,
17777,
701,
1808,
314,
2850,
4964,
7,
945,
14,
199,
624,
199,
3,
961,
1233,
365,
7131,
687,
1145,
4128,
14,
647,
315,
314,
4693,
12580,
15610,
334,
1490,
1350,
395,
199,
3,
436,
687,
4319,
9060,
17121,
327,
11432,
11363,
14,
199,
199,
646,
26234,
199,
646,
18354,
199,
646,
2050,
199,
646,
6128,
21,
199,
646,
13290,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
2838,
199,
646,
3873,
199,
646,
984,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
893,
26,
523,
492,
14441,
199,
2590,
3545,
26,
523,
986,
199,
199,
3,
710,
2050,
8661,
26,
199,
3,
221,
378,
26,
20456,
1454,
14,
199,
3,
221,
413,
26,
9795,
3788,
14,
199,
3,
221,
499,
26,
10332,
9610,
14,
199,
3,
221,
650,
26,
14245,
9610,
14,
199,
9833,
275,
413,
199,
199,
3,
8228,
1568,
402,
3371,
503,
1300,
570,
14,
199,
4283,
63,
16418,
63,
4305,
275,
27151,
627,
6619,
421,
199,
318,
2372,
7035,
8,
7650,
304,
523,
408,
919,
311,
1086,
314,
922,
367,
3932,
3031,
2287,
436,
2529,
652,
14,
819,
710,
2061,
1202,
3031,
2287,
365,
6290,
370,
282,
570,
436,
402,
22941,
1536,
465,
282,
18453,
1636,
523,
370,
314,
922,
14,
982,
314,
922,
299,
4357,
9509,
1928,
14090,
315,
7003,
314,
2061,
523,
1202,
3031,
2287,
365,
1202,
14,
982,
314,
922,
655,
878,
282,
892,
2287,
12,
652,
365,
6290,
523,
367,
2163,
900,
781,
8457,
14,
819,
408,
523,
2061,
63,
2123,
63,
493,
63,
354,
275,
747,
14,
515,
14,
12131,
20793,
8083,
2019,
63,
600,
8578,
63,
2123,
63,
1562,
531,
523,
2061,
63,
2123,
275,
3087,
523,
340,
747,
14,
515,
14,
2444,
8,
2019,
63,
2123,
63,
493,
63,
354,
304,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
82,
531,
489,
2061,
63,
2123,
275,
2061,
63,
2123,
63,
493,
14,
6407,
1252,
1913,
4582,
78,
531,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
489,
8457,
847,
298,
8978,
83,
8480,
450,
2061,
63,
2123,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
3031,
275,
3066,
63,
1210,
8,
7650,
435,
7244,
298,
680,
1913,
342,
523,
340,
3031,
26,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
87,
531,
489,
2061,
63,
2123,
63,
493,
14,
952,
8,
2123,
9,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
587,
26,
272,
3031,
275,
2061,
63,
2123,
523,
372,
3031,
421,
199,
318,
9795,
4152,
8,
1328,
304,
523,
408,
5375,
282,
2004,
1245,
370,
3839,
14,
819,
982,
283,
9833,
7,
365,
8932,
2419,
378,
12,
870,
314,
1245,
14,
819,
3033,
26,
272,
1499,
26,
710,
1059,
370,
870,
14,
523,
408,
523,
340,
8661,
690,
378,
26,
272,
870,
1499,
421,
199,
318,
28379,
8,
1328,
304,
523,
408,
5375,
376,
1125,
1245,
370,
4635,
436,
4458,
1041,
523,
870,
4331,
1274,
14,
3083,
12,
1499,
523,
984,
14,
2224,
8,
17,
9,
421,
199,
533,
6810,
8880,
547,
8,
4078,
18,
14,
12815,
304,
523,
408,
16894,
370,
6623,
2337,
1990,
376,
1125,
28532,
1958,
543,
6810,
8880,
1041,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
1249,
304,
272,
4011,
18,
14,
12815,
855,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
488,
9,
272,
291,
14,
589,
275,
1249,
272,
291,
14,
5764,
275,
1249,
905,
547,
937,
421,
199,
533,
11836,
30980,
8,
785,
304,
523,
408,
17473,
282,
2863,
3217,
367,
282,
3486,
11785,
1654,
1041,
819,
347,
636,
826,
721,
277,
12,
1591,
12,
1790,
63,
1593,
12,
1591,
63,
4415,
29,
403,
12,
2402,
63,
2139,
10324,
2049,
3354,
63,
7792,
29,
797,
304,
272,
408,
10607,
282,
892,
4760,
30980,
14,
339,
3033,
26,
489,
1591,
26,
710,
1591,
370,
3222,
4145,
370,
14,
489,
1790,
63,
1593,
26,
437,
805,
626,
6181,
949,
2368,
436,
2529,
376,
267,
334,
2123,
12,
2505,
9,
2008,
1380,
2797,
14,
12823,
506,
2797,
340,
6299,
267,
365,
1415,
14,
489,
1591,
63,
4415,
26,
710,
1591,
1406,
370,
3222,
370,
314,
1654,
334,
4322,
370,
1591,
680,
489,
2402,
63,
2139,
26,
437,
1211,
402,
2402,
2323,
370,
5666,
370,
4036,
1056,
14,
489,
3354,
63,
7792,
26,
982,
715,
12,
3354,
314,
6299,
10049,
370,
2257,
4543,
14,
267,
982,
756,
12,
675,
376,
315,
13,
4844,
29038,
3140,
14,
221,
20196,
1471,
267,
5669,
642,
9330,
14,
221,
7827,
370,
756,
14,
272,
408
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
5157,
367,
24349,
14981,
687,
282,
1015,
3304,
2656,
370,
314,
1233,
8578,
1145,
14,
199,
199,
7692,
6212,
26,
5802,
14,
647,
359,
1419,
61,
19344,
3915,
63,
1419,
61,
199,
199,
10746,
1511,
787,
3032,
370,
314,
3915,
1414,
402,
314,
8793,
2656,
14,
199,
199,
10682,
1015,
3304,
10460,
26,
523,
12579,
523,
30522,
523,
31098,
199,
199,
7940,
365,
11012,
367,
12579,
15,
16797,
18977,
4390,
370,
4165,
282,
3123,
15,
932,
15,
4694,
370,
3915,
199,
17777,
701,
1808,
314,
2850,
4964,
7,
945,
14,
199,
624,
199,
3,
961,
1233,
365,
7131,
687,
1145,
4128,
14,
647,
315,
314,
4693,
12580,
15610,
334,
1490,
1350,
395,
199,
3,
436,
687,
4319,
9060,
17121,
327,
11432,
11363,
14,
199,
199,
646,
26234,
199,
646,
18354,
199,
646,
2050,
199,
646,
6128,
21,
199,
646,
13290,
199,
646,
8691,
199,
646,
747,
199,
646,
295,
199,
646,
2838,
199,
646,
3873,
199,
646,
984,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
893,
26,
523,
492,
14441,
199,
2590,
3545,
26,
523,
986,
199,
199,
3,
710,
2050,
8661,
26,
199,
3,
221,
378,
26,
20456,
1454,
14,
199,
3,
221,
413,
26,
9795,
3788,
14,
199,
3,
221,
499,
26,
10332,
9610,
14,
199,
3,
221,
650,
26,
14245,
9610,
14,
199,
9833,
275,
413,
199,
199,
3,
8228,
1568,
402,
3371,
503,
1300,
570,
14,
199,
4283,
63,
16418,
63,
4305,
275,
27151,
627,
6619,
421,
199,
318,
2372,
7035,
8,
7650,
304,
523,
408,
919,
311,
1086,
314,
922,
367,
3932,
3031,
2287,
436,
2529,
652,
14,
819,
710,
2061,
1202,
3031,
2287,
365,
6290,
370,
282,
570,
436,
402,
22941,
1536,
465,
282,
18453,
1636,
523,
370,
314,
922,
14,
982,
314,
922,
299,
4357,
9509,
1928,
14090,
315,
7003,
314,
2061,
523,
1202,
3031,
2287,
365,
1202,
14,
982,
314,
922,
655,
878,
282,
892,
2287,
12,
652,
365,
6290,
523,
367,
2163,
900,
781,
8457,
14,
819,
408,
523,
2061,
63,
2123,
63,
493,
63,
354,
275,
747,
14,
515,
14,
12131,
20793,
8083,
2019,
63,
600,
8578,
63,
2123,
63,
1562,
531,
523,
2061,
63,
2123,
275,
3087,
523,
340,
747,
14,
515,
14,
2444,
8,
2019,
63,
2123,
63,
493,
63,
354,
304,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
82,
531,
489,
2061,
63,
2123,
275,
2061,
63,
2123,
63,
493,
14,
6407,
1252,
1913,
4582,
78,
531,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
489,
8457,
847,
298,
8978,
83,
8480,
450,
2061,
63,
2123,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
3031,
275,
3066,
63,
1210,
8,
7650,
435,
7244,
298,
680,
1913,
342,
523,
340,
3031,
26,
272,
862,
26,
489,
2061,
63,
2123,
63,
493,
275,
1551,
8,
2019,
63,
2123,
63,
493,
63,
354,
12,
298,
87,
531,
489,
2061,
63,
2123,
63,
493,
14,
952,
8,
2123,
9,
489,
2061,
63,
2123,
63,
493,
14,
1600,
342,
272,
871,
5925,
12,
325,
26,
489,
986,
523,
587,
26,
272,
3031,
275,
2061,
63,
2123,
523,
372,
3031,
421,
199,
318,
9795,
4152,
8,
1328,
304,
523,
408,
5375,
282,
2004,
1245,
370,
3839,
14,
819,
982,
283,
9833,
7,
365,
8932,
2419,
378,
12,
870,
314,
1245,
14,
819,
3033,
26,
272,
1499,
26,
710,
1059,
370,
870,
14,
523,
408,
523,
340,
8661,
690,
378,
26,
272,
870,
1499,
421,
199,
318,
28379,
8,
1328,
304,
523,
408,
5375,
376,
1125,
1245,
370,
4635,
436,
4458,
1041,
523,
870,
4331,
1274,
14,
3083,
12,
1499,
523,
984,
14,
2224,
8,
17,
9,
421,
199,
533,
6810,
8880,
547,
8,
4078,
18,
14,
12815,
304,
523,
408,
16894,
370,
6623,
2337,
1990,
376,
1125,
28532,
1958,
543,
6810,
8880,
1041,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
1249,
304,
272,
4011,
18,
14,
12815,
855,
826,
721,
277,
12,
1166,
12,
1233,
12,
1499,
12,
2323,
12,
488,
9,
272,
291,
14,
589,
275,
1249,
272,
291,
14,
5764,
275,
1249,
905,
547,
937,
421,
199,
533,
11836,
30980,
8,
785,
304,
523,
408,
17473,
282,
2863,
3217,
367,
282,
3486,
11785,
1654,
1041,
819,
347,
636,
826,
721,
277,
12,
1591,
12,
1790,
63,
1593,
12,
1591,
63,
4415,
29,
403,
12,
2402,
63,
2139,
10324,
2049,
3354,
63,
7792,
29,
797,
304,
272,
408,
10607,
282,
892,
4760,
30980,
14,
339,
3033,
26,
489,
1591,
26,
710,
1591,
370,
3222,
4145,
370,
14,
489,
1790,
63,
1593,
26,
437,
805,
626,
6181,
949,
2368,
436,
2529,
376,
267,
334,
2123,
12,
2505,
9,
2008,
1380,
2797,
14,
12823,
506,
2797,
340,
6299,
267,
365,
1415,
14,
489,
1591,
63,
4415,
26,
710,
1591,
1406,
370,
3222,
370,
314,
1654,
334,
4322,
370,
1591,
680,
489,
2402,
63,
2139,
26,
437,
1211,
402,
2402,
2323,
370,
5666,
370,
4036,
1056,
14,
489,
3354,
63,
7792,
26,
982,
715,
12,
3354,
314,
6299,
10049,
370,
2257,
4543,
14,
267,
982,
756,
12,
675,
376,
315,
13,
4844,
29038,
3140,
14,
221,
20196,
1471,
267,
5669,
642,
9330,
14,
221,
7827,
370,
756,
14,
272,
408,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
barachka/odoo
|
addons/hr_payroll/report/__init__.py
|
427
|
1161
|
#-*- coding:utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# d$
#
# 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 report_payslip
import report_payslip_details
import report_contribution_register
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
199,
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,
2900,
5924,
5702,
199,
3,
259,
366,
4,
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,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
3622,
63,
25854,
199,
646,
3622,
63,
25854,
63,
5087,
199,
646,
3622,
63,
388,
15980,
63,
2683,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
199,
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,
2900,
5924,
5702,
199,
3,
259,
366,
4,
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,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
3622,
63,
25854,
199,
646,
3622,
63,
25854,
63,
5087,
199,
646,
3622,
63,
388,
15980,
63,
2683,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
herove/dotfiles
|
sublime/Packages/SublimeCodeIntel/libs/textinfo.py
|
2
|
82250
|
#!/usr/bin/env python
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (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.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is Komodo code.
#
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
#
# Contributor(s):
# ActiveState Software Inc
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
r"""Determine information about text files.
This module efficiently determines the encoding of text files (see
_classify_encoding for details), accurately identifies binary files, and
provides detailed meta information of text files.
>>> import textinfo
>>> path = __file__
>>> if path.endswith(".pyc"): path = path[:-1]
>>> ti = textinfo.textinfo_from_path(path)
>>> ti.__class__
<class 'textinfo.TextInfo'>
>>> ti.encoding
'utf-8'
>>> ti.file_type_name
'regular file'
>>> ti.is_text
True
>>> ti.lang
'Python'
>>> ti.langinfo
<Python LangInfo>
...plus a number of other useful information gleaned from the file. To see
a list of all useful attributes see
>> list(ti.as_dict().keys())
['encoding', 'file_type', ...]
Note: This module requires at least Python 2.5 to use
`codecs.lookup(<encname>).name`.
"""
_cmdln_doc = """Determine information about text files.
"""
# TODO:
# - [high prio] prefs integration
# - aggegrate "is there an explicit encoding decl in this file" from XML, HTML,
# lang-specific, emacs and vi vars decls (as discussed with Shane)
# - fix ti with unicode paths Windows (check on Linux too)
# - '-L|--dereference' option a la `file` and `ls`
# - See: http://webblaze.cs.berkeley.edu/2009/content-sniffing/
# - Shift-JIS encoding is not detected for
# http://public.activestate.com/pub/apc/perl-current/lib/Pod/Simple/t/corpus/s2763_sjis.txt
# [Jan wrote]
# > While the document isn't identified by filename extension as POD,
# > it does contain POD and a corresponding =encoding directive.
# Could potentially have a content heuristic check for POD.
#
# ----------------
# Current Komodo (4.2) Encoding Determination Notes (used for reference,
# but not absolutely followed):
#
# Working through koDocumentBase._detectEncoding:
# encoding_name = pref:encodingDefault (on first start is set
# to encoding from locale.getdefaultlocale() typically,
# fallback to iso8859-1; default locale typically ends up being:
# Windows: cp1252
# Mac OS X: mac-roman
# (modern) Linux: UTF-8)
# encoding = the python name for this
# tryencoding = pref:encoding (no default, explicitly set
# encoding) -- i.e. if there are doc prefs for this
# path, then give this encoding a try. If not given,
# then utf-8 for XML/XSLT/VisualBasic and
# pref:encodingDefault for others (though this is
# all prefable via the 'languages' pref struct).
# tryxmldecl
# trymeta (HTML meta)
# trymodeline
# autodetect (whether to try at all)
#
# if autodetect or tryencoding:
# koUnicodeEncoding.autoDetectEncoding()
# else:
# if encoding.startswith('utf'): # note this is pref:encodingDefault
# check bom
# presume encoding is right (give up if conversion fails)
# else:
# presume encoding is right (given up if fails)
#
# Working through koUnicodeEncoding.autoDetectEncoding:
# if tryxmldecl: ...
# if tryhtmlmeta: ...
# if trymodeline: ...
# use bom: ...
# ----------------
__version_info__ = (0, 1, 0)
__version__ = '.'.join(map(str, __version_info__))
import os
from os.path import join, dirname, abspath, basename, exists
import sys
import re
from pprint import pprint
import traceback
import warnings
import logging
import optparse
import codecs
import locale
import langinfo
#---- exceptions and warnings
class TextInfoError(Exception):
pass
class TextInfoConfigError(TextInfoError):
pass
class ChardetImportWarning(ImportWarning):
pass
warnings.simplefilter("once", ChardetImportWarning)
#---- globals
log = logging.getLogger("textinfo")
# For debugging:
DEBUG_CHARDET_INFO = False # gather chardet info
#---- module API
def textinfo_from_filename(path):
"""Determine test info for the given path **using the filename only**.
No attempt is made to stat or read the file.
"""
return TextInfo.init_from_filename(path)
def textinfo_from_path(path, encoding=None, follow_symlinks=False,
quick_determine_lang=False):
"""Determine text info for the given path.
This raises EnvironmentError if the path doesn't not exist or could
not be read.
"""
return TextInfo.init_from_path(path, encoding=encoding,
follow_symlinks=follow_symlinks,
quick_determine_lang=quick_determine_lang)
#---- main TextInfo class
class TextInfo(object):
path = None
file_type_name = None # e.g. "regular file", "directory", ...
file_type = None # stat.S_IFMT(os.stat(path).st_mode)
file_mode = None # stat.S_IMODE(os.stat(path).st_mode)
is_text = None
encoding = None
has_bom = None # whether the text has a BOM (Byte Order Marker)
encoding_bozo = False
encoding_bozo_reasons = None
lang = None # e.g. "Python", "Perl", ...
langinfo = None # langinfo.LangInfo instance or None
# Enable chardet-based heuristic guessing of encoding as a last
# resort for file types known to not be binary.
CHARDET_ENABLED = True
CHARDET_THRESHHOLD = 0.9 # >=90% confidence to avoid false positives.
@classmethod
def init_from_filename(cls, path, lidb=None):
"""Create an instance using only the filename to initialize."""
if lidb is None:
lidb = langinfo.get_default_database()
self = cls()
self.path = path
self._classify_from_filename(lidb)
return self
@classmethod
def init_from_path(cls, path, encoding=None, lidb=None,
follow_symlinks=False,
quick_determine_lang=False,
env=None):
"""Create an instance using the filename and stat/read info
from the given path to initialize.
@param follow_symlinks {boolean} can be set to True to have
the textinfo returned for a symlink be for linked-to file. By
default the textinfo is for the symlink itself.
@param quick_determine_lang {boolean} can be set to True to have
processing stop as soon as the language has been determined.
Note that this means some fields will not be populated.
@param env {runtime environment} A "runtime environment" class
whose behaviour is used to influence processing. Currently
it is just used to provide a hook for lang determination
by filename (for Komodo).
"""
if lidb is None:
lidb = langinfo.get_default_database()
self = cls()
self.path = path
self._accessor = PathAccessor(path, follow_symlinks=follow_symlinks)
try:
# TODO: pref: Is a preference specified for this path?
self._classify_from_stat(lidb)
if self.file_type_name != "regular file":
# Don't continue if not a regular file.
return self
# TODO: add 'pref:treat_as_text' a la TextMate (or
# perhaps that is handled in _classify_from_filename())
self._classify_from_filename(lidb, env)
if self.is_text is False:
return self
if self.lang and quick_determine_lang:
return self
if not self.lang:
self._classify_from_magic(lidb)
if self.is_text is False:
return self
if self.lang and quick_determine_lang:
return self
self._classify_encoding(lidb, suggested_encoding=encoding)
if self.is_text is None and self.encoding:
self.is_text = True
if self.is_text is False:
return self
self.text = self._accessor.text
if self.text: # No `self.text' with current UTF-32 hack.
self._classify_from_content(lidb)
return self
finally:
# Free the memory used by the accessor.
del self._accessor
def __repr__(self):
if self.path:
return "<TextInfo %r>" % self.path
else:
return "<TextInfo %r>"\
% _one_line_summary_from_text(self.content, 30)
def as_dict(self):
return dict((k, v) for k, v in self.__dict__.items()
if not k.startswith('_'))
def as_summary(self):
"""One-liner string summary of text info."""
d = self.as_dict()
info = []
if self.file_type_name and self.file_type_name != "regular file":
info.append(self.file_type_name)
else:
info.append(self.lang or "???")
if not self.is_text:
info.append("binary")
elif self.encoding:
enc = self.encoding
if self.has_bom:
enc += " (bom)"
info.append(enc)
if DEBUG_CHARDET_INFO and hasattr(self, "chardet_info") \
and self.chardet_info["encoding"]:
info.append("chardet:%s/%.1f%%"
% (self.chardet_info["encoding"],
self.chardet_info["confidence"] * 100.0))
return "%s: %s" % (self.path, ', '.join(info))
def _classify_from_content(self, lidb):
# TODO: Plan:
# - eol_* attrs (test cases for this!)
head = self.text[:self._accessor.HEAD_SIZE]
tail = self.text[-self._accessor.TAIL_SIZE:]
# If lang is unknown, attempt to guess from XML prolog or
# shebang now that we've successfully decoded the buffer.
if self.langinfo is None:
(self.has_xml_prolog, xml_version,
xml_encoding) = self._get_xml_prolog_info(head)
if self.has_xml_prolog:
self.xml_version = xml_version
self.xml_encoding = xml_encoding
self.langinfo = lidb.langinfo_from_lang("XML")
self.lang = self.langinfo.name
elif self.text.startswith("#!"):
li = lidb.langinfo_from_magic(self.text, shebang_only=True)
if li:
self.langinfo = li
self.lang = li.name
# Extract Emacs local vars and Vi(m) modeline info and, if the
# lang is still unknown, attempt to use them to determine it.
self.emacs_vars = self._get_emacs_head_vars(head)
self.emacs_vars.update(self._get_emacs_tail_vars(tail))
self.vi_vars = self._get_vi_vars(head)
if not self.vi_vars:
self.vi_vars = self._get_vi_vars(tail)
if self.langinfo is None and "mode" in self.emacs_vars:
li = lidb.langinfo_from_emacs_mode(self.emacs_vars["mode"])
if li:
self.langinfo = li
self.lang = li.name
if self.langinfo is None and "filetype" in self.vi_vars \
or "ft" in self.vi_vars:
vi_filetype = self.vi_vars.get(
"filetype") or self.vi_vars.get("ft")
li = lidb.langinfo_from_vi_filetype(vi_filetype)
if li:
self.langinfo = li
self.lang = li.name
if self.langinfo is not None:
if self.langinfo.conforms_to("XML"):
if not hasattr(self, "has_xml_prolog"):
(self.has_xml_prolog, self.xml_version,
self.xml_encoding) = self._get_xml_prolog_info(head)
(self.has_doctype_decl, self.doctype_decl,
self.doctype_name, self.doctype_public_id,
self.doctype_system_id) = self._get_doctype_decl_info(head)
# If this is just plain XML, we try to use the doctype
# decl to choose a more specific XML lang.
if self.lang == "XML" and self.has_doctype_decl:
li = lidb.langinfo_from_doctype(
public_id=self.doctype_public_id,
system_id=self.doctype_system_id)
if li and li.name != "XML":
self.langinfo = li
self.lang = li.name
elif self.langinfo.conforms_to("HTML"):
(self.has_doctype_decl, self.doctype_decl,
self.doctype_name, self.doctype_public_id,
self.doctype_system_id) = self._get_doctype_decl_info(head)
# Allow promotion to XHTML (or other HTML flavours) based
# on doctype.
if self.lang == "HTML" and self.has_doctype_decl:
li = lidb.langinfo_from_doctype(
public_id=self.doctype_public_id,
system_id=self.doctype_system_id)
if li and li.name != "HTML":
self.langinfo = li
self.lang = li.name
# Look for XML prolog and promote HTML -> XHTML if it
# exists. Note that this wins over a plain HTML doctype.
(self.has_xml_prolog, xml_version,
xml_encoding) = self._get_xml_prolog_info(head)
if self.has_xml_prolog:
self.xml_version = xml_version
self.xml_encoding = xml_encoding
if self.lang == "HTML":
li = lidb.langinfo_from_lang("XHTML")
self.langinfo = li
self.lang = li.name
# Attempt to specialize the lang.
if self.langinfo is not None:
li = lidb.specialized_langinfo_from_content(
self.langinfo, self.text)
if li:
self.langinfo = li
self.lang = li.name
def _classify_from_magic(self, lidb):
"""Attempt to classify from the file's magic number/shebang
line, doctype, etc.
Note that this is done before determining the encoding, so we are
working with the *bytes*, not chars.
"""
self.has_bom, bom, bom_encoding = self._get_bom_info()
if self.has_bom:
# If this file has a BOM then, unless something funny is
# happening, this will be a text file encoded with
# `bom_encoding`. We leave that to `_classify_encoding()`.
return
# Without a BOM we assume this is an 8-bit encoding, for the
# purposes of looking at, e.g. a shebang line.
#
# UTF-16 and UTF-32 without a BOM is rare; we won't pick up on,
# e.g. Python encoded as UCS-2 or UCS-4 here (but
# `_classify_encoding()` should catch most of those cases).
head_bytes = self._accessor.head_bytes
li = lidb.langinfo_from_magic(head_bytes)
if li:
log.debug("lang from magic: %s", li.name)
self.langinfo = li
self.lang = li.name
self.is_text = li.is_text
return
(has_doctype_decl, doctype_decl, doctype_name, doctype_public_id,
doctype_system_id) = self._get_doctype_decl_info(head_bytes)
if has_doctype_decl:
li = lidb.langinfo_from_doctype(public_id=doctype_public_id,
system_id=doctype_system_id)
if li:
log.debug("lang from doctype: %s", li.name)
self.langinfo = li
self.lang = li.name
self.is_text = li.is_text
return
def _classify_encoding(self, lidb, suggested_encoding=None):
"""To classify from the content we need to separate text from
binary, and figure out the encoding. This is an imperfect task.
The algorithm here is to go through the following heroics to attempt
to determine an encoding that works to decode the content. If all
such attempts fail, we presume it is binary.
1. Use the BOM, if it has one.
2. Try the given suggested encoding (if any).
3. Check for EBCDIC encoding.
4. Lang-specific (if we know the lang already):
* if this is Python, look for coding: decl and try that
* if this is Perl, look for use encoding decl and try that
* ...
5. XML: According to the XML spec the rule is the XML prolog
specifies the encoding, or it is UTF-8.
6. HTML: Attempt to use Content-Type meta tag. Try the given
charset, if any.
7. Emacs-style "coding" local var.
8. Vi[m]-style "fileencoding" local var.
9. Heuristic checks for UTF-16 without BOM.
10. Give UTF-8 a try, it is a pretty common fallback.
We must do this before a possible 8-bit
`locale.getpreferredencoding()` because any UTF-8 encoded
document will decode with an 8-bit encoding (i.e. will decode,
just with bogus characters).
11. Lang-specific fallback. E.g., UTF-8 for XML, ascii for Python.
12. chardet (http://chardet.feedparser.org/), if CHARDET_ENABLED == True
13. locale.getpreferredencoding()
14. iso8859-1 (in case `locale.getpreferredencoding()` is UTF-8
we must have an 8-bit encoding attempt).
TODO: Is there a worry for a lot of false-positives for
binary files.
Notes:
- A la Universal Feed Parser, if some
supposed-to-be-authoritative encoding indicator is wrong (e.g.
the BOM, the Python 'coding:' decl for Python),
`self.encoding_bozo` is set True and a reason is appended to
the `self.encoding_bozo_reasons` list.
"""
# 1. Try the BOM.
if self.has_bom is not False: # Was set in `_classify_from_magic()`.
self.has_bom, bom, bom_encoding = self._get_bom_info()
if self.has_bom:
self._accessor.strip_bom(bom)
# Python doesn't currently include a UTF-32 codec. For now
# we'll *presume* that a UTF-32 BOM is correct. The
# limitation is that `self.text' will NOT get set
# because we cannot decode it.
if bom_encoding in ("utf-32-le", "utf-32-be") \
or self._accessor.decode(bom_encoding):
log.debug("encoding: encoding from BOM: %r", bom_encoding)
self.encoding = bom_encoding
return
else:
log.debug("encoding: BOM encoding (%r) was *wrong*",
bom_encoding)
self._encoding_bozo(
u"BOM encoding (%s) could not decode %s"
% (bom_encoding, self._accessor))
head_bytes = self._accessor.head_bytes
if DEBUG_CHARDET_INFO:
sys.path.insert(0, os.path.expanduser(
"~/tm/check/contrib/chardet"))
import chardet
del sys.path[0]
self.chardet_info = chardet.detect(head_bytes)
# 2. Try the suggested encoding.
if suggested_encoding is not None:
norm_suggested_encoding = _norm_encoding(suggested_encoding)
if self._accessor.decode(suggested_encoding):
self.encoding = norm_suggested_encoding
return
else:
log.debug("encoding: suggested %r encoding didn't work for %s",
suggested_encoding, self._accessor)
# 3. Check for EBCDIC.
# TODO: Not sure this should be included, chardet may be better
# at this given different kinds of EBCDIC.
EBCDIC_MAGIC = '\x4c\x6f\xa7\x94'
if self._accessor.head_4_bytes == EBCDIC_MAGIC:
# This is EBCDIC, but I don't know if there are multiple kinds
# of EBCDIC. Python has a 'ebcdic-cp-us' codec. We'll use
# that for now.
norm_ebcdic_encoding = _norm_encoding("ebcdic-cp-us")
if self._accessor.decode(norm_ebcdic_encoding):
log.debug("EBCDIC encoding: %r", norm_ebcdic_encoding)
self.encoding = norm_ebcdic_encoding
return
else:
log.debug("EBCDIC encoding didn't work for %s",
self._accessor)
# 4. Lang-specific (if we know the lang already).
if self.langinfo and self.langinfo.conformant_attr("encoding_decl_pattern"):
m = self.langinfo.conformant_attr("encoding_decl_pattern") \
.search(head_bytes)
if m:
lang_encoding = m.group("encoding")
norm_lang_encoding = _norm_encoding(lang_encoding)
if self._accessor.decode(norm_lang_encoding):
log.debug("encoding: encoding from lang-spec: %r",
norm_lang_encoding)
self.encoding = norm_lang_encoding
return
else:
log.debug("encoding: lang-spec encoding (%r) was *wrong*",
lang_encoding)
self._encoding_bozo(
u"lang-spec encoding (%s) could not decode %s"
% (lang_encoding, self._accessor))
# 5. XML prolog
if self.langinfo and self.langinfo.conforms_to("XML"):
has_xml_prolog, xml_version, xml_encoding \
= self._get_xml_prolog_info(head_bytes)
if xml_encoding is not None:
norm_xml_encoding = _norm_encoding(xml_encoding)
if self._accessor.decode(norm_xml_encoding):
log.debug("encoding: encoding from XML prolog: %r",
norm_xml_encoding)
self.encoding = norm_xml_encoding
return
else:
log.debug("encoding: XML prolog encoding (%r) was *wrong*",
norm_xml_encoding)
self._encoding_bozo(
u"XML prolog encoding (%s) could not decode %s"
% (norm_xml_encoding, self._accessor))
# 6. HTML: Attempt to use Content-Type meta tag.
if self.langinfo and self.langinfo.conforms_to("HTML"):
has_http_content_type_info, http_content_type, http_encoding \
= self._get_http_content_type_info(head_bytes)
if has_http_content_type_info and http_encoding:
norm_http_encoding = _norm_encoding(http_encoding)
if self._accessor.decode(norm_http_encoding):
log.debug("encoding: encoding from HTTP content-type: %r",
norm_http_encoding)
self.encoding = norm_http_encoding
return
else:
log.debug(
"encoding: HTTP content-type encoding (%r) was *wrong*",
norm_http_encoding)
self._encoding_bozo(
u"HTML content-type encoding (%s) could not decode %s"
% (norm_http_encoding, self._accessor))
# 7. Emacs-style local vars.
emacs_head_vars = self._get_emacs_head_vars(head_bytes)
emacs_encoding = emacs_head_vars.get("coding")
if not emacs_encoding:
tail_bytes = self._accessor.tail_bytes
emacs_tail_vars = self._get_emacs_tail_vars(tail_bytes)
emacs_encoding = emacs_tail_vars.get("coding")
if emacs_encoding:
norm_emacs_encoding = _norm_encoding(emacs_encoding)
if self._accessor.decode(norm_emacs_encoding):
log.debug("encoding: encoding from Emacs coding var: %r",
norm_emacs_encoding)
self.encoding = norm_emacs_encoding
return
else:
log.debug("encoding: Emacs coding var (%r) was *wrong*",
norm_emacs_encoding)
self._encoding_bozo(
u"Emacs coding var (%s) could not decode %s"
% (norm_emacs_encoding, self._accessor))
# 8. Vi[m]-style local vars.
vi_vars = self._get_vi_vars(head_bytes)
vi_encoding = vi_vars.get("fileencoding") or vi_vars.get("fenc")
if not vi_encoding:
vi_vars = self._get_vi_vars(self._accessor.tail_bytes)
vi_encoding = vi_vars.get("fileencoding") or vi_vars.get("fenc")
if vi_encoding:
norm_vi_encoding = _norm_encoding(vi_encoding)
if self._accessor.decode(norm_vi_encoding):
log.debug("encoding: encoding from Vi[m] coding var: %r",
norm_vi_encoding)
self.encoding = norm_vi_encoding
return
else:
log.debug("encoding: Vi[m] coding var (%r) was *wrong*",
norm_vi_encoding)
self._encoding_bozo(
u"Vi[m] coding var (%s) could not decode %s"
% (norm_vi_encoding, self._accessor))
# 9. Heuristic checks for UTF-16 without BOM.
utf16_encoding = None
head_odd_bytes = head_bytes[0::2]
head_even_bytes = head_bytes[1::2]
head_markers = ["<?xml", "#!"]
for head_marker in head_markers:
length = len(head_marker)
if head_odd_bytes.startswith(head_marker) \
and head_even_bytes[0:length] == '\x00'*length:
utf16_encoding = "utf-16-le"
break
elif head_even_bytes.startswith(head_marker) \
and head_odd_bytes[0:length] == '\x00'*length:
utf16_encoding = "utf-16-be"
break
internal_markers = ["coding"]
for internal_marker in internal_markers:
length = len(internal_marker)
try:
idx = head_odd_bytes.index(internal_marker)
except ValueError:
pass
else:
if head_even_bytes[idx:idx+length] == '\x00'*length:
utf16_encoding = "utf-16-le"
try:
idx = head_even_bytes.index(internal_marker)
except ValueError:
pass
else:
if head_odd_bytes[idx:idx+length] == '\x00'*length:
utf16_encoding = "utf-16-be"
if utf16_encoding:
if self._accessor.decode(utf16_encoding):
log.debug("encoding: guessed encoding: %r", utf16_encoding)
self.encoding = utf16_encoding
return
# 10. Give UTF-8 a try.
norm_utf8_encoding = _norm_encoding("utf-8")
if self._accessor.decode(norm_utf8_encoding):
log.debug("UTF-8 encoding: %r", norm_utf8_encoding)
self.encoding = norm_utf8_encoding
return
# 11. Lang-specific fallback (e.g. XML -> utf-8, Python -> ascii, ...).
# Note: A potential problem here is that a fallback encoding here that
# is a pre-Unicode Single-Byte encoding (like iso8859-1) always "works"
# so the subsequent heuristics never get tried.
fallback_encoding = None
fallback_lang = None
if self.langinfo:
fallback_lang = self.langinfo.name
fallback_encoding = self.langinfo.conformant_attr(
"default_encoding")
if fallback_encoding:
if self._accessor.decode(fallback_encoding):
log.debug("encoding: fallback encoding for %s: %r",
fallback_lang, fallback_encoding)
self.encoding = fallback_encoding
return
else:
log.debug("encoding: %s fallback encoding (%r) was *wrong*",
fallback_lang, fallback_encoding)
self._encoding_bozo(
u"%s fallback encoding (%s) could not decode %s"
% (fallback_lang, fallback_encoding, self._accessor))
# 12. chardet (http://chardet.feedparser.org/)
# Note: I'm leary of using this b/c (a) it's a sizeable perf
# hit and (b) false positives -- for example, the first 8kB of
# /usr/bin/php on Mac OS X 10.4.10 is ISO-8859-2 with 44%
# confidence. :)
# Solution: (a) Only allow for content we know is not binary
# (from langinfo association); and (b) can be disabled via
# CHARDET_ENABLED class attribute.
if self.CHARDET_ENABLED and self.langinfo and self.langinfo.is_text:
try:
import chardet
except ImportError:
warnings.warn("no chardet module to aid in guessing encoding",
ChardetImportWarning)
else:
chardet_info = chardet.detect(head_bytes)
if chardet_info["encoding"] \
and chardet_info["confidence"] > self.CHARDET_THRESHHOLD:
chardet_encoding = chardet_info["encoding"]
norm_chardet_encoding = _norm_encoding(chardet_encoding)
if self._accessor.decode(norm_chardet_encoding):
log.debug("chardet encoding: %r", chardet_encoding)
self.encoding = norm_chardet_encoding
return
# 13. locale.getpreferredencoding()
# Typical values for this:
# Windows: cp1252 (aka windows-1252)
# Mac OS X: mac-roman
# Linux: UTF-8 (modern Linux anyway)
# Solaris 8: 464 (aka ASCII)
locale_encoding = locale.getpreferredencoding()
if locale_encoding:
norm_locale_encoding = _norm_encoding(locale_encoding)
if self._accessor.decode(norm_locale_encoding):
log.debug("encoding: locale preferred encoding: %r",
locale_encoding)
self.encoding = norm_locale_encoding
return
# 14. iso8859-1
norm_fallback8bit_encoding = _norm_encoding("iso8859-1")
if self._accessor.decode(norm_fallback8bit_encoding):
log.debug(
"fallback 8-bit encoding: %r", norm_fallback8bit_encoding)
self.encoding = norm_fallback8bit_encoding
return
# We couldn't find an encoding that works. Give up and presume
# this is binary content.
self.is_text = False
def _encoding_bozo(self, reason):
self.encoding_bozo = True
if self.encoding_bozo_reasons is None:
self.encoding_bozo_reasons = []
self.encoding_bozo_reasons.append(reason)
# c.f. http://www.xml.com/axml/target.html#NT-prolog
_xml_prolog_pat = re.compile(
r'''<\?xml
( # strict ordering is reqd but we'll be liberal here
\s+version=['"](?P<ver>.*?)['"]
| \s+encoding=['"](?P<enc>.*?)['"]
)+
.*? # other possible junk
\s*\?>
''',
re.VERBOSE | re.DOTALL
)
def _get_xml_prolog_info(self, head_bytes):
"""Parse out info from the '<?xml version=...' prolog, if any.
Returns (<has-xml-prolog>, <xml-version>, <xml-encoding>). Examples:
(False, None, None)
(True, "1.0", None)
(True, "1.0", "UTF-16")
"""
# Presuming an 8-bit encoding. If it is UTF-16 or UTF-32, then
# that should have been picked up by an earlier BOM check or via
# the subsequent heuristic check for UTF-16 without a BOM.
if not head_bytes.startswith("<?xml"):
return (False, None, None)
# Try to extract more info from the prolog.
match = self._xml_prolog_pat.match(head_bytes)
if not match:
if log.isEnabledFor(logging.DEBUG):
log.debug("`%s': could not match XML prolog: '%s'", self.path,
_one_line_summary_from_text(head_bytes, 40))
return (False, None, None)
xml_version = match.group("ver")
xml_encoding = match.group("enc")
return (True, xml_version, xml_encoding)
_html_meta_tag_pat = re.compile("""
(<meta
(?:\s+[\w-]+\s*=\s*(?:".*?"|'.*?'))+ # attributes
\s*/?>)
""",
re.IGNORECASE | re.VERBOSE
)
_html_attr_pat = re.compile(
# Currently requiring XML attrs (i.e. quoted value).
'''(?:\s+([\w-]+)\s*=\s*(".*?"|'.*?'))'''
)
_http_content_type_splitter = re.compile(";\s*")
def _get_http_content_type_info(self, head_bytes):
"""Returns info extracted from an HTML content-type meta tag if any.
Returns (<has-http-content-type-info>, <content-type>, <charset>).
For example:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
yields:
(True, "text/html", "utf-8")
"""
# Presuming an 8-bit encoding. If it is UTF-16 or UTF-32, then
# that should have been picked up by an earlier BOM check.
# Otherwise we rely on `chardet` to cover us.
# Parse out '<meta ...>' tags, then the attributes in them.
for meta_tag in self._html_meta_tag_pat.findall(head_bytes):
meta = dict((k.lower(), v[1:-1])
for k, v in self._html_attr_pat.findall(meta_tag))
if "http-equiv" in meta \
and meta["http-equiv"].lower() == "content-type":
content = meta.get("content", "")
break
else:
return (False, None, None)
# We found a http-equiv="Content-Type" tag, parse its content
# attribute value.
parts = [
p.strip() for p in self._http_content_type_splitter.split(content)]
if not parts:
return (False, None, None)
content_type = parts[0] or None
for p in parts[1:]:
if p.lower().startswith("charset="):
charset = p[len("charset="):]
if charset and charset[0] in ('"', "'"):
charset = charset[1:]
if charset and charset[-1] in ('"', "'"):
charset = charset[:-1]
break
else:
charset = None
return (True, content_type, charset)
# TODO: Note that this isn't going to catch the current HTML 5
# doctype: '<!DOCTYPE html>'
_doctype_decl_re = re.compile(r'''
<!DOCTYPE
\s+(?P<name>[a-zA-Z_:][\w:.-]*)
\s+(?:
SYSTEM\s+(["'])(?P<system_id_a>.*?)\2
|
PUBLIC
\s+(["'])(?P<public_id_b>.*?)\4
# HTML 3.2 and 2.0 doctypes don't include a system-id.
(?:\s+(["'])(?P<system_id_b>.*?)\6)?
)
(\s*\[.*?\])?
\s*>
''', re.IGNORECASE | re.DOTALL | re.UNICODE | re.VERBOSE)
def _get_doctype_decl_info(self, head):
"""Parse out DOCTYPE info from the given XML or HTML content.
Returns a tuple of the form:
(<has-doctype-decl>, <doctype-decl>,
<name>, <public-id>, <system-id>)
The <public-id> is normalized as per this comment in the XML 1.0
spec:
Before a match is attempted, all strings of white space in the
public identifier must be normalized to single space
characters (#x20), and leading and trailing white space must
be removed.
Examples:
(False, None, None, None, None)
(True, '<!DOCTYPE greeting SYSTEM "hello.dtd">',
'greeting', None, 'hello.dtd'),
(True,
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
'html',
'-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd')
Here is the spec for DOCTYPE decls in XML:
http://www.xml.com/axml/target.html#NT-doctypedecl
We loosely follow this to allow for some decls in HTML that isn't
proper XML. As well, we are only parsing out decls that reference
an external ID, as opposed to those that define entities locally.
"""
if "<!DOCTYPE" not in head: # quick out
return (False, None, None, None, None)
m = self._doctype_decl_re.search(head)
if not m:
return (False, None, None, None, None)
d = m.groupdict()
name = d.get("name")
system_id = d.get("system_id_a") or d.get("system_id_b")
public_id = d.get("public_id_b")
if public_id:
public_id = re.sub("\s+", ' ', public_id.strip()) # normalize
return (True, m.group(0), name, public_id, system_id)
_emacs_vars_head_pat = re.compile("-\*-\s*(.*?)\s*-\*-")
_emacs_head_vars_cache = None
def _get_emacs_head_vars(self, head_bytes):
"""Return a dictionary of emacs-style local variables in the head.
"Head" emacs vars on the ones in the '-*- ... -*-' one-liner.
Parsing is done loosely according to this spec (and according to
some in-practice deviations from this):
http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables
"""
# Presuming an 8-bit encoding. If it is UTF-16 or UTF-32, then
# that should have been picked up by an earlier BOM check.
# Otherwise we rely on `chardet` to cover us.
if self._emacs_head_vars_cache is not None:
return self._emacs_head_vars_cache
# Search the head for a '-*-'-style one-liner of variables.
emacs_vars = {}
if "-*-" in head_bytes:
match = self._emacs_vars_head_pat.search(head_bytes)
if match:
emacs_vars_str = match.group(1)
if '\n' in emacs_vars_str:
raise ValueError("local variables error: -*- not "
"terminated before end of line")
emacs_var_strs = [s.strip() for s in emacs_vars_str.split(';')
if s.strip()]
if len(emacs_var_strs) == 1 and ':' not in emacs_var_strs[0]:
# While not in the spec, this form is allowed by emacs:
# -*- Tcl -*-
# where the implied "variable" is "mode". This form
# is only allowed if there are no other variables.
emacs_vars["mode"] = emacs_var_strs[0].strip()
else:
for emacs_var_str in emacs_var_strs:
try:
variable, value = emacs_var_str.strip().split(
':', 1)
except ValueError:
log.debug("emacs variables error: malformed -*- "
"line: %r", emacs_var_str)
continue
# Lowercase the variable name because Emacs allows "Mode"
# or "mode" or "MoDe", etc.
emacs_vars[variable.lower()] = value.strip()
# Unquote values.
for var, val in emacs_vars.items():
if len(val) > 1 and (val.startswith('"') and val.endswith('"')
or val.startswith('"') and val.endswith('"')):
emacs_vars[var] = val[1:-1]
self._emacs_head_vars_cache = emacs_vars
return emacs_vars
# This regular expression is intended to match blocks like this:
# PREFIX Local Variables: SUFFIX
# PREFIX mode: Tcl SUFFIX
# PREFIX End: SUFFIX
# Some notes:
# - "[ \t]" is used instead of "\s" to specifically exclude newlines
# - "(\r\n|\n|\r)" is used instead of "$" because the sre engine does
# not like anything other than Unix-style line terminators.
_emacs_vars_tail_pat = re.compile(r"""^
(?P<prefix>(?:[^\r\n|\n|\r])*?)
[\ \t]*Local\ Variables:[\ \t]*
(?P<suffix>.*?)(?:\r\n|\n|\r)
(?P<content>.*?\1End:)
""", re.IGNORECASE | re.MULTILINE | re.DOTALL | re.VERBOSE)
_emacs_tail_vars_cache = None
def _get_emacs_tail_vars(self, tail_bytes):
r"""Return a dictionary of emacs-style local variables in the tail.
"Tail" emacs vars on the ones in the multi-line "Local
Variables:" block.
>>> TextInfo()._get_emacs_tail_vars('# Local Variables:\n# foo: bar\n# End:')
{'foo': 'bar'}
>>> TextInfo()._get_emacs_tail_vars('# Local Variables:\n# foo: bar\\\n# baz\n# End:')
{'foo': 'bar baz'}
>>> TextInfo()._get_emacs_tail_vars('# Local Variables:\n# quoted: "bar "\n# End:')
{'quoted': 'bar '}
Parsing is done according to this spec (and according to some
in-practice deviations from this):
http://www.gnu.org/software/emacs/manual/html_chapter/emacs_33.html#SEC485
"""
# Presuming an 8-bit encoding. If it is UTF-16 or UTF-32, then
# that should have been picked up by an earlier BOM check.
# Otherwise we rely on `chardet` to cover us.
if self._emacs_tail_vars_cache is not None:
return self._emacs_tail_vars_cache
emacs_vars = {}
if "Local Variables" not in tail_bytes:
self._emacs_tail_vars_cache = emacs_vars
return emacs_vars
match = self._emacs_vars_tail_pat.search(tail_bytes)
if match:
prefix = match.group("prefix")
suffix = match.group("suffix")
lines = match.group("content").splitlines(0)
# print "prefix=%r, suffix=%r, content=%r, lines: %s"\
# % (prefix, suffix, match.group("content"), lines)
# Validate the Local Variables block: proper prefix and suffix
# usage.
for i, line in enumerate(lines):
if not line.startswith(prefix):
log.debug("emacs variables error: line '%s' "
"does not use proper prefix '%s'"
% (line, prefix))
return {}
# Don't validate suffix on last line. Emacs doesn't care,
# neither should we.
if i != len(lines)-1 and not line.endswith(suffix):
log.debug("emacs variables error: line '%s' "
"does not use proper suffix '%s'"
% (line, suffix))
return {}
# Parse out one emacs var per line.
continued_for = None
for line in lines[:-1]: # no var on the last line ("PREFIX End:")
if prefix:
line = line[len(prefix):] # strip prefix
if suffix:
line = line[:-len(suffix)] # strip suffix
line = line.strip()
if continued_for:
variable = continued_for
if line.endswith('\\'):
line = line[:-1].rstrip()
else:
continued_for = None
emacs_vars[variable] += ' ' + line
else:
try:
variable, value = line.split(':', 1)
except ValueError:
log.debug("local variables error: missing colon "
"in local variables entry: '%s'" % line)
continue
# Do NOT lowercase the variable name, because Emacs only
# allows "mode" (and not "Mode", "MoDe", etc.) in this
# block.
value = value.strip()
if value.endswith('\\'):
value = value[:-1].rstrip()
continued_for = variable
else:
continued_for = None
emacs_vars[variable] = value
# Unquote values.
for var, val in emacs_vars.items():
if len(val) > 1 and (val.startswith('"') and val.endswith('"')
or val.startswith('"') and val.endswith('"')):
emacs_vars[var] = val[1:-1]
self._emacs_tail_vars_cache = emacs_vars
return emacs_vars
# Note: It might nice if parser also gave which of 'vi, vim, ex' and
# the range in the accessor.
_vi_vars_pats_and_splitters = [
(re.compile(r'[ \t]+(vi|vim([<>=]?\d{3})?|ex):\s*set? (?P<rhs>.*?)(?<!\\):', re.M),
re.compile(r'[ \t]+')),
(re.compile(r'[ \t]+(vi|vim([<>=]?\d{3})?|ex):\s*(?P<rhs>.*?)$', re.M),
re.compile(r'[ \t:]+')),
(re.compile(r'^(vi|vim([<>=]?\d{3})?):\s*set? (?P<rhs>.*?)(?<!\\):', re.M),
re.compile(r'[ \t]+')),
]
_vi_vars_cache = None
def _get_vi_vars(self, bytes):
r"""Return a dict of Vi[m] modeline vars.
See ":help modeline" in Vim for a spec.
>>> TextInfo()._get_vi_vars("/* vim: set ai tw=75: */")
{'ai': None, 'tw': 75}
>>> TextInfo()._get_vi_vars("vim: set ai tw=75: bar")
{'ai': None, 'tw': 75}
>>> TextInfo()._get_vi_vars("vi: set foo:bar")
{'foo': None}
>>> TextInfo()._get_vi_vars(" vi: se foo:bar")
{'foo': None}
>>> TextInfo()._get_vi_vars(" ex: se foo:bar")
{'foo': None}
>>> TextInfo()._get_vi_vars(" vi:noai:sw=3 tw=75")
{'tw': 75, 'sw': 3, 'noai': None}
>>> TextInfo()._get_vi_vars(" vi:noai:sw=3 tw=75")
{'tw': 75, 'sw': 3, 'noai': None}
>>> TextInfo()._get_vi_vars("ex: se foo:bar")
{}
Some edge cases:
>>> TextInfo()._get_vi_vars(r"/* vi:set dir=c\:\tmp: */")
{'dir': 'c:\\tmp'}
"""
# Presume 8-bit encoding... yada yada.
if self._vi_vars_cache is not None:
return self._vi_vars_cache
vi_vars = {}
# TODO: Consider reducing support to just "vi:" for speed. This
# function takes way too much time.
if "vi:" not in bytes and "ex:" not in bytes and "vim:" not in bytes:
self._vi_vars_cache = vi_vars
return vi_vars
for pat, splitter in self._vi_vars_pats_and_splitters:
match = pat.search(bytes)
if match:
for var_str in splitter.split(match.group("rhs")):
if '=' in var_str:
name, value = var_str.split('=', 1)
try:
vi_vars[name] = int(value)
except ValueError:
vi_vars[name] = value.replace('\\:', ':')
else:
vi_vars[var_str] = None
break
self._vi_vars_cache = vi_vars
return vi_vars
def _get_bom_info(self):
r"""Returns (<has-bom>, <bom>, <bom-encoding>). Examples:
(True, '\xef\xbb\xbf', "utf-8")
(True, '\xff\xfe', "utf-16-le")
(False, None, None)
"""
boms_and_encodings = [ # in order from longest to shortest
(codecs.BOM_UTF32_LE, "utf-32-le"),
(codecs.BOM_UTF32_BE, "utf-32-be"),
(codecs.BOM_UTF8, "utf-8"),
(codecs.BOM_UTF16_LE, "utf-16-le"),
(codecs.BOM_UTF16_BE, "utf-16-be"),
]
head_4 = self._accessor.head_4_bytes
for bom, encoding in boms_and_encodings:
if head_4.startswith(bom):
return (True, bom, encoding)
break
else:
return (False, None, None)
def _classify_from_filename(self, lidb, env):
"""Classify from the path *filename* only.
Sets `lang' and `langinfo', if can be determined.
"""
filename = basename(self.path)
if env is not None:
li = env.langinfo_from_filename(filename)
if li:
log.debug("lang from env: `%s' -> `%s'", filename, li.name)
self.langinfo = li
self.lang = li.name
self.is_text = li.is_text
return
# ...from the ext
idx = 0
while True:
idx = filename.find('.', idx)
if idx == -1:
break
ext = filename[idx:]
li = lidb.langinfo_from_ext(ext)
if li:
log.debug("lang from ext: `%s' -> `%s'", ext, li.name)
self.langinfo = li
self.lang = li.name
self.is_text = li.is_text
return
idx += 1
# ...from file basename
li = lidb.langinfo_from_filename(filename)
if li:
log.debug("lang from filename: `%s' -> `%s'", filename, li.name)
self.langinfo = li
self.lang = li.name
self.is_text = li.is_text
return
def _classify_from_stat(self, lidb):
"""Set some `file_*' attributes from stat mode."""
from stat import S_ISREG, S_ISDIR, S_ISLNK, S_ISFIFO, S_ISSOCK, \
S_ISBLK, S_ISCHR, S_IMODE, S_IFMT
stat = self._accessor.stat
st_mode = stat.st_mode
self.file_type = S_IFMT(st_mode)
self.file_mode = S_IMODE(st_mode)
self.file_stat = stat
if S_ISREG(st_mode):
self.file_type_name = "regular file"
elif S_ISDIR(st_mode):
self.file_type_name = "directory"
elif S_ISLNK(st_mode):
self.file_type_name = "symbolic link"
elif S_ISFIFO(st_mode):
self.file_type_name = "fifo"
elif S_ISSOCK(st_mode):
self.file_type_name = "socket"
elif S_ISBLK(st_mode):
self.file_type_name = "block special"
elif S_ISCHR(st_mode):
self.file_type_name = "character special"
def _norm_encoding(encoding):
"""Normalize the encoding name -- where "normalized" is what
Python's codec's module calls it.
Interesting link:
The IANA-registered set of character sets.
http://www.iana.org/assignments/character-sets
"""
try:
# This requires Python >=2.5.
return codecs.lookup(encoding).name
except LookupError:
return encoding
#---- accessor API
# The idea here is to abstract accessing the text file content being
# classified to allow, e.g. classifying content without a file, from
# a Komodo buffer, etc.
class Accessor(object):
"""Virtual base class defining Accessor API for accessing
text content.
"""
# API:
# prop head_bytes -> head 8k bytes
# prop head_4_bytes -> head 4 bytes (useful for BOM detection)
# prop tail_bytes -> tail 8k bytes
# def bytes_range(start, end) -> bytes in that range
HEAD_SIZE = pow(2, 13) # 8k
TAIL_SIZE = pow(2, 13) # 8k
encoding = None
text = None
_unsuccessful_encodings = None
def decode(self, encoding):
"""Decodes bytes with the given encoding and, if successful,
sets `self.text` with the decoded result and returns True.
Otherwise, returns False.
Side-effects: On success, sets `self.text` and `self.encoding`.
Optimization: First an attempt is made to decode
`self.head_bytes` instead of all of `self.bytes`. This allows
for the normal usage in `TextInfo._classify_encoding()` to *not*
bother fully reading binary files that could not be decoded.
Optimization: Decoding attempts are cached to not bother
attempting a failed decode twice.
"""
if self._unsuccessful_encodings is None:
self._unsuccessful_encodings = set()
if encoding in self._unsuccessful_encodings:
return False
elif encoding == self.encoding:
return True
head_bytes = self.head_bytes
try:
head_bytes.decode(encoding, 'strict')
except LookupError, ex:
log.debug("encoding lookup error: %r", encoding)
self._unsuccessful_encodings.add(encoding)
return False
except UnicodeError, ex:
# If the decode failed in the last few bytes, it might be
# because a multi-surrogate was cutoff by the head. Ignore
# the error here, if it is truly not of this encoding, the
# full file decode will fail.
if ex.start >= self.HEAD_SIZE - 5:
# '5' because the max num bytes to encode a single char
# in any encoding is 6 bytes (in UTF-8).
pass
else:
self._unsuccessful_encodings.add(encoding)
return False
try:
self.text = self.bytes.decode(encoding, 'strict')
except UnicodeError, ex:
self._unsuccessful_encodings.add(encoding)
return False
self.encoding = encoding
return True
class PathAccessor(Accessor):
"""Accessor API for a path."""
(READ_NONE, # _file==None, file not opened yet
READ_HEAD, # _bytes==<head bytes>
READ_TAIL, # _bytes==<head>, _bytes_tail==<tail>
READ_ALL) = range(4) # _bytes==<all>, _bytes_tail==None, _file closed
_read_state = READ_NONE # one of the READ_* states
_file = None
_bytes = None
_bytes_tail = None
def __init__(self, path, follow_symlinks=False):
self.path = path
self.follow_symlinks = follow_symlinks
def __str__(self):
return "path `%s'" % self.path
_stat_cache = None
@property
def stat(self):
if self._stat_cache is None:
if self.follow_symlinks:
self._stat_cache = os.stat(self.path)
else:
self._stat_cache = os.lstat(self.path)
return self._stat_cache
@property
def size(self):
return self.stat.st_size
def __del__(self):
self.close()
def close(self):
if self._file and not self._file.closed:
self._file.close()
def _read(self, state):
"""Read up to at least `state`."""
# TODO: If `follow_symlinks` is False and this is a symlink we
# must use os.readlink() here.
# It is the job of the caller to only call _read() if necessary.
assert self._read_state < state
try:
if self._read_state == self.READ_NONE:
assert self._file is None and self._bytes is None
self._file = open(self.path, 'rb')
if state == self.READ_HEAD:
self._bytes = self._file.read(self.HEAD_SIZE)
self._read_state = (self.size <= self.HEAD_SIZE
and self.READ_ALL or self.READ_HEAD)
elif state == self.READ_TAIL:
if self.size <= self.HEAD_SIZE + self.TAIL_SIZE:
self._bytes = self._file.read()
self._read_state = self.READ_ALL
else:
self._bytes = self._file.read(self.HEAD_SIZE)
self._file.seek(
-self.TAIL_SIZE, 2) # 2 == relative to end
self._bytes_tail = self._file.read(self.TAIL_SIZE)
self._read_state = self.READ_TAIL
elif state == self.READ_ALL:
self._bytes = self._file.read()
self._read_state = self.READ_ALL
elif self._read_state == self.READ_HEAD:
if state == self.READ_TAIL:
if self.size <= self.HEAD_SIZE + self.TAIL_SIZE:
self._bytes += self._file.read()
self._read_state = self.READ_ALL
else:
self._file.seek(
-self.TAIL_SIZE, 2) # 2 == relative to end
self._bytes_tail = self._file.read(self.TAIL_SIZE)
self._read_state = self.READ_TAIL
elif state == self.READ_ALL:
self._bytes += self._file.read()
self._read_state = self.READ_ALL
elif self._read_state == self.READ_TAIL:
assert state == self.READ_ALL
self._file.seek(self.HEAD_SIZE, 0) # 0 == relative to start
remaining_size = self.size - self.HEAD_SIZE - self.TAIL_SIZE
assert remaining_size > 0, \
"negative remaining bytes to read from '%s': %d" \
% (self.path, self.size)
self._bytes += self._file.read(remaining_size)
self._bytes += self._bytes_tail
self._bytes_tail = None
self._read_state = self.READ_ALL
if self._read_state == self.READ_ALL:
self.close()
except Exception, ex:
log.warn("Could not read file: %r due to: %r", self.path, ex)
raise
def strip_bom(self, bom):
"""This should be called by the user of this class to strip a
detected BOM from the bytes for subsequent decoding and
analysis.
"""
assert self._bytes[:len(bom)] == bom
self._bytes = self._bytes[len(bom):]
@property
def head_bytes(self):
"""The first 8k raw bytes of the document."""
if self._read_state < self.READ_HEAD:
self._read(self.READ_HEAD)
return self._bytes[:self.HEAD_SIZE]
@property
def head_4_bytes(self):
if self._read_state < self.READ_HEAD:
self._read(self.READ_HEAD)
return self._bytes[:4]
@property
def tail_bytes(self):
if self._read_state < self.READ_TAIL:
self._read(self.READ_TAIL)
if self._read_state == self.READ_ALL:
return self._bytes[-self.TAIL_SIZE:]
else:
return self._bytes_tail
def bytes_range(self, start, end):
if self._read_state < self.READ_ALL:
self._read(self.READ_ALL)
return self._bytes[start:end]
@property
def bytes(self):
if self._read_state < self.READ_ALL:
self._read(self.READ_ALL)
return self._bytes
#---- internal support stuff
# Recipe: regex_from_encoded_pattern (1.0)
def _regex_from_encoded_pattern(s):
"""'foo' -> re.compile(re.escape('foo'))
'/foo/' -> re.compile('foo')
'/foo/i' -> re.compile('foo', re.I)
"""
if s.startswith('/') and s.rfind('/') != 0:
# Parse it: /PATTERN/FLAGS
idx = s.rfind('/')
pattern, flags_str = s[1:idx], s[idx+1:]
flag_from_char = {
"i": re.IGNORECASE,
"l": re.LOCALE,
"s": re.DOTALL,
"m": re.MULTILINE,
"u": re.UNICODE,
}
flags = 0
for char in flags_str:
try:
flags |= flag_from_char[char]
except KeyError:
raise ValueError("unsupported regex flag: '%s' in '%s' "
"(must be one of '%s')"
% (char, s, ''.join(flag_from_char.keys())))
return re.compile(s[1:idx], flags)
else: # not an encoded regex
return re.compile(re.escape(s))
# Recipe: text_escape (0.2)
def _escaped_text_from_text(text, escapes="eol"):
r"""Return escaped version of text.
"escapes" is either a mapping of chars in the source text to
replacement text for each such char or one of a set of
strings identifying a particular escape style:
eol
replace EOL chars with '\r' and '\n', maintain the actual
EOLs though too
whitespace
replace EOL chars as above, tabs with '\t' and spaces
with periods ('.')
eol-one-line
replace EOL chars with '\r' and '\n'
whitespace-one-line
replace EOL chars as above, tabs with '\t' and spaces
with periods ('.')
"""
# TODO:
# - Add 'c-string' style.
# - Add _escaped_html_from_text() with a similar call sig.
import re
if isinstance(escapes, basestring):
if escapes == "eol":
escapes = {'\r\n': "\\r\\n\r\n", '\n': "\\n\n", '\r': "\\r\r"}
elif escapes == "whitespace":
escapes = {'\r\n': "\\r\\n\r\n", '\n': "\\n\n", '\r': "\\r\r",
'\t': "\\t", ' ': "."}
elif escapes == "eol-one-line":
escapes = {'\n': "\\n", '\r': "\\r"}
elif escapes == "whitespace-one-line":
escapes = {'\n': "\\n", '\r': "\\r", '\t': "\\t", ' ': '.'}
else:
raise ValueError("unknown text escape style: %r" % escapes)
# Sort longer replacements first to allow, e.g. '\r\n' to beat '\r' and
# '\n'.
escapes_keys = escapes.keys()
try:
escapes_keys.sort(key=lambda a: len(a), reverse=True)
except TypeError:
# Python 2.3 support: sort() takes no keyword arguments
escapes_keys.sort(lambda a, b: cmp(len(a), len(b)))
escapes_keys.reverse()
def repl(match):
val = escapes[match.group(0)]
return val
escaped = re.sub("(%s)" % '|'.join([re.escape(k) for k in escapes_keys]),
repl,
text)
return escaped
def _one_line_summary_from_text(text, length=78,
escapes={'\n': "\\n", '\r': "\\r", '\t': "\\t"}):
r"""Summarize the given text with one line of the given length.
"text" is the text to summarize
"length" (default 78) is the max length for the summary
"escapes" is a mapping of chars in the source text to
replacement text for each such char. By default '\r', '\n'
and '\t' are escaped with their '\'-escaped repr.
"""
if len(text) > length:
head = text[:length-3]
else:
head = text
escaped = _escaped_text_from_text(head, escapes)
if len(text) > length:
summary = escaped[:length-3] + "..."
else:
summary = escaped
return summary
# Recipe: paths_from_path_patterns (0.5)
def _should_include_path(path, includes, excludes):
"""Return True iff the given path should be included."""
from os.path import basename
from fnmatch import fnmatch
base = basename(path)
if includes:
for include in includes:
if fnmatch(base, include):
try:
log.debug("include `%s' (matches `%s')", path, include)
except (NameError, AttributeError):
pass
break
else:
try:
log.debug("exclude `%s' (matches no includes)", path)
except (NameError, AttributeError):
pass
return False
for exclude in excludes:
if fnmatch(base, exclude):
try:
log.debug("exclude `%s' (matches `%s')", path, exclude)
except (NameError, AttributeError):
pass
return False
return True
def _walk(top, topdown=True, onerror=None, follow_symlinks=False):
"""A version of `os.walk()` with a couple differences regarding symlinks.
1. follow_symlinks=False (the default): A symlink to a dir is
returned as a *non*-dir. In `os.walk()`, a symlink to a dir is
returned in the *dirs* list, but it is not recursed into.
2. follow_symlinks=True: A symlink to a dir is returned in the
*dirs* list (as with `os.walk()`) but it *is conditionally*
recursed into (unlike `os.walk()`).
A symlinked dir is only recursed into if it is to a deeper dir
within the same tree. This is my understanding of how `find -L
DIR` works.
TODO: put as a separate recipe
"""
from os.path import join, isdir, islink, abspath
# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains. os.path.walk
# always suppressed the exception then, rather than blow up for a
# minor reason when (say) a thousand readable directories are still
# left to visit. That logic is copied here.
try:
names = os.listdir(top)
except OSError, err:
if onerror is not None:
onerror(err)
return
dirs, nondirs = [], []
if follow_symlinks:
for name in names:
if isdir(join(top, name)):
dirs.append(name)
else:
nondirs.append(name)
else:
for name in names:
path = join(top, name)
if islink(path):
nondirs.append(name)
elif isdir(path):
dirs.append(name)
else:
nondirs.append(name)
if topdown:
yield top, dirs, nondirs
for name in dirs:
path = join(top, name)
if follow_symlinks and islink(path):
# Only walk this path if it links deeper in the same tree.
top_abs = abspath(top)
link_abs = abspath(join(top, os.readlink(path)))
if not link_abs.startswith(top_abs + os.sep):
continue
for x in _walk(path, topdown, onerror, follow_symlinks=follow_symlinks):
yield x
if not topdown:
yield top, dirs, nondirs
_NOT_SPECIFIED = ("NOT", "SPECIFIED")
def _paths_from_path_patterns(path_patterns, files=True, dirs="never",
recursive=True, includes=[], excludes=[],
skip_dupe_dirs=False,
follow_symlinks=False,
on_error=_NOT_SPECIFIED):
"""_paths_from_path_patterns([<path-patterns>, ...]) -> file paths
Generate a list of paths (files and/or dirs) represented by the given path
patterns.
"path_patterns" is a list of paths optionally using the '*', '?' and
'[seq]' glob patterns.
"files" is boolean (default True) indicating if file paths
should be yielded
"dirs" is string indicating under what conditions dirs are
yielded. It must be one of:
never (default) never yield dirs
always yield all dirs matching given patterns
if-not-recursive only yield dirs for invocations when
recursive=False
See use cases below for more details.
"recursive" is boolean (default True) indicating if paths should
be recursively yielded under given dirs.
"includes" is a list of file patterns to include in recursive
searches.
"excludes" is a list of file and dir patterns to exclude.
(Note: This is slightly different than GNU grep's --exclude
option which only excludes *files*. I.e. you cannot exclude
a ".svn" dir.)
"skip_dupe_dirs" can be set True to watch for and skip
descending into a dir that has already been yielded. Note
that this currently does not dereference symlinks.
"follow_symlinks" is a boolean indicating whether to follow
symlinks (default False). To guard against infinite loops
with circular dir symlinks, only dir symlinks to *deeper*
are followed.
"on_error" is an error callback called when a given path pattern
matches nothing:
on_error(PATH_PATTERN)
If not specified, the default is look for a "log" global and
call:
log.error("`%s': No such file or directory")
Specify None to do nothing.
Typically this is useful for a command-line tool that takes a list
of paths as arguments. (For Unix-heads: the shell on Windows does
NOT expand glob chars, that is left to the app.)
Use case #1: like `grep -r`
{files=True, dirs='never', recursive=(if '-r' in opts)}
script FILE # yield FILE, else call on_error(FILE)
script DIR # yield nothing
script PATH* # yield all files matching PATH*; if none,
# call on_error(PATH*) callback
script -r DIR # yield files (not dirs) recursively under DIR
script -r PATH* # yield files matching PATH* and files recursively
# under dirs matching PATH*; if none, call
# on_error(PATH*) callback
Use case #2: like `file -r` (if it had a recursive option)
{files=True, dirs='if-not-recursive', recursive=(if '-r' in opts)}
script FILE # yield FILE, else call on_error(FILE)
script DIR # yield DIR, else call on_error(DIR)
script PATH* # yield all files and dirs matching PATH*; if none,
# call on_error(PATH*) callback
script -r DIR # yield files (not dirs) recursively under DIR
script -r PATH* # yield files matching PATH* and files recursively
# under dirs matching PATH*; if none, call
# on_error(PATH*) callback
Use case #3: kind of like `find .`
{files=True, dirs='always', recursive=(if '-r' in opts)}
script FILE # yield FILE, else call on_error(FILE)
script DIR # yield DIR, else call on_error(DIR)
script PATH* # yield all files and dirs matching PATH*; if none,
# call on_error(PATH*) callback
script -r DIR # yield files and dirs recursively under DIR
# (including DIR)
script -r PATH* # yield files and dirs matching PATH* and recursively
# under dirs; if none, call on_error(PATH*)
# callback
TODO: perf improvements (profile, stat just once)
"""
from os.path import basename, exists, isdir, join, normpath, abspath, \
lexists, islink, realpath
from glob import glob
assert not isinstance(path_patterns, basestring), \
"'path_patterns' must be a sequence, not a string: %r" % path_patterns
GLOB_CHARS = '*?['
if skip_dupe_dirs:
searched_dirs = set()
for path_pattern in path_patterns:
# Determine the set of paths matching this path_pattern.
for glob_char in GLOB_CHARS:
if glob_char in path_pattern:
paths = glob(path_pattern)
break
else:
if follow_symlinks:
paths = exists(path_pattern) and [path_pattern] or []
else:
paths = lexists(path_pattern) and [path_pattern] or []
if not paths:
if on_error is None:
pass
elif on_error is _NOT_SPECIFIED:
try:
log.error("`%s': No such file or directory", path_pattern)
except (NameError, AttributeError):
pass
else:
on_error(path_pattern)
for path in paths:
if (follow_symlinks or not islink(path)) and isdir(path):
if skip_dupe_dirs:
canon_path = normpath(abspath(path))
if follow_symlinks:
canon_path = realpath(canon_path)
if canon_path in searched_dirs:
continue
else:
searched_dirs.add(canon_path)
# 'includes' SHOULD affect whether a dir is yielded.
if (dirs == "always"
or (dirs == "if-not-recursive" and not recursive)
) and _should_include_path(path, includes, excludes):
yield path
# However, if recursive, 'includes' should NOT affect
# whether a dir is recursed into. Otherwise you could
# not:
# script -r --include="*.py" DIR
if recursive and _should_include_path(path, [], excludes):
for dirpath, dirnames, filenames in _walk(path,
follow_symlinks=follow_symlinks):
dir_indeces_to_remove = []
for i, dirname in enumerate(dirnames):
d = join(dirpath, dirname)
if skip_dupe_dirs:
canon_d = normpath(abspath(d))
if follow_symlinks:
canon_d = realpath(canon_d)
if canon_d in searched_dirs:
dir_indeces_to_remove.append(i)
continue
else:
searched_dirs.add(canon_d)
if dirs == "always" \
and _should_include_path(d, includes, excludes):
yield d
if not _should_include_path(d, [], excludes):
dir_indeces_to_remove.append(i)
for i in reversed(dir_indeces_to_remove):
del dirnames[i]
if files:
for filename in sorted(filenames):
f = join(dirpath, filename)
if _should_include_path(f, includes, excludes):
yield f
elif files and _should_include_path(path, includes, excludes):
yield path
class _NoReflowFormatter(optparse.IndentedHelpFormatter):
"""An optparse formatter that does NOT reflow the description."""
def format_description(self, description):
return description or ""
# Recipe: pretty_logging (0.1) in C:\trentm\tm\recipes\cookbook
class _PerLevelFormatter(logging.Formatter):
"""Allow multiple format string -- depending on the log level.
A "fmtFromLevel" optional arg is added to the constructor. It can be
a dictionary mapping a log record level to a format string. The
usual "fmt" argument acts as the default.
"""
def __init__(self, fmt=None, datefmt=None, fmtFromLevel=None):
logging.Formatter.__init__(self, fmt, datefmt)
if fmtFromLevel is None:
self.fmtFromLevel = {}
else:
self.fmtFromLevel = fmtFromLevel
def format(self, record):
record.lowerlevelname = record.levelname.lower()
if record.levelno in self.fmtFromLevel:
# XXX This is a non-threadsafe HACK. Really the base Formatter
# class should provide a hook accessor for the _fmt
# attribute. *Could* add a lock guard here (overkill?).
_saved_fmt = self._fmt
self._fmt = self.fmtFromLevel[record.levelno]
try:
return logging.Formatter.format(self, record)
finally:
self._fmt = _saved_fmt
else:
return logging.Formatter.format(self, record)
def _setup_logging(stream=None):
"""Do logging setup:
We want a prettier default format:
do: level: ...
Spacing. Lower case. Skip " level:" if INFO-level.
"""
hdlr = logging.StreamHandler(stream)
defaultFmt = "%(name)s: %(levelname)s: %(message)s"
infoFmt = "%(name)s: %(message)s"
fmtr = _PerLevelFormatter(fmt=defaultFmt,
fmtFromLevel={logging.INFO: infoFmt})
hdlr.setFormatter(fmtr)
logging.root.addHandler(hdlr)
log.setLevel(logging.INFO)
#---- mainline
def main(argv):
usage = "usage: %prog PATHS..."
version = "%prog "+__version__
parser = optparse.OptionParser(usage=usage,
version=version, description=_cmdln_doc,
formatter=_NoReflowFormatter())
parser.add_option("-v", "--verbose", dest="log_level",
action="store_const", const=logging.DEBUG,
help="more verbose output")
parser.add_option("-q", "--quiet", dest="log_level",
action="store_const", const=logging.WARNING,
help="quieter output")
parser.add_option("-r", "--recursive", action="store_true",
help="recursively descend into given paths")
parser.add_option("-L", "--dereference", dest="follow_symlinks",
action="store_true",
help="follow symlinks, i.e. show info about linked-to "
"files and descend into linked dirs when recursive")
parser.add_option("-Q", "--quick-determine-lang", action="store_true",
help="Skip some processing to attempt to determine "
"language. Things like specialization, emacs/vi "
"local vars, full decoding, are skipped.")
parser.add_option("--encoding", help="suggested encoding for input files")
parser.add_option("-f", "--format",
help="format of output: summary (default), dict")
parser.add_option("-x", "--exclude", dest="excludes", action="append",
metavar="PATTERN",
help="path pattern to exclude for recursive search (by default SCC "
"control dirs are skipped)")
parser.set_defaults(log_level=logging.INFO, encoding=None, recursive=False,
follow_symlinks=False, format="summary",
excludes=[".svn", "CVS", ".hg", ".git", ".bzr"],
quick_determine_lang=False)
opts, args = parser.parse_args()
log.setLevel(opts.log_level)
if opts.log_level > logging.INFO:
warnings.simplefilter("ignore", ChardetImportWarning)
if args:
path_patterns = args
elif sys.stdin.isatty():
parser.print_help()
return 0
else:
def args_from_stdin():
for line in sys.stdin:
yield line.rstrip("\r\n")
path_patterns = args_from_stdin()
for path in _paths_from_path_patterns(
path_patterns, excludes=opts.excludes,
recursive=opts.recursive,
dirs="if-not-recursive",
follow_symlinks=opts.follow_symlinks):
try:
ti = textinfo_from_path(path, encoding=opts.encoding,
follow_symlinks=opts.follow_symlinks,
quick_determine_lang=opts.quick_determine_lang)
except OSError, ex:
log.error("%s: %s", path, ex)
continue
if opts.format == "summary":
print ti.as_summary()
elif opts.format == "dict":
d = ti.as_dict()
if "text" in d:
del d["text"]
pprint(d)
else:
raise TextInfoError("unknown output format: %r" % opts.format)
if __name__ == "__main__":
_setup_logging()
try:
if "--self-test" in sys.argv:
import doctest
retval = doctest.testmod()[0]
else:
retval = main(sys.argv)
except SystemExit:
pass
except KeyboardInterrupt:
sys.exit(1)
except:
exc_info = sys.exc_info()
if log.isEnabledFor(logging.DEBUG):
import traceback
print
traceback.print_exception(*exc_info)
else:
if hasattr(exc_info[0], "__name__"):
# log.error("%s: %s", exc_info[0].__name__, exc_info[1])
log.error(exc_info[1])
else: # string exception
log.error(exc_info[0])
sys.exit(1)
else:
sys.exit(retval)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1011,
9153,
16427,
5113,
8068,
1011,
9153,
199,
3,
3394,
26,
28481,
413,
14,
17,
15,
12006,
499,
14,
16,
15,
44,
12006,
499,
14,
17,
199,
3,
199,
3,
710,
4072,
402,
642,
570,
787,
5420,
370,
314,
17728,
1684,
844,
199,
3,
3394,
413,
14,
17,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
199,
3,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
199,
3,
199,
3,
2290,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
199,
3,
5597,
12,
2428,
3408,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
4481,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
3,
710,
12769,
5495,
365,
1804,
676,
19657,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
23241,
2223,
2290,
3277,
14,
199,
3,
20825,
2737,
701,
23241,
2223,
2290,
3277,
787,
1898,
334,
35,
9,
12293,
13,
9488,
199,
3,
23241,
2223,
2290,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
23241,
2223,
2290,
3277,
199,
3,
199,
3,
26776,
12,
314,
4072,
402,
642,
570,
1443,
506,
1202,
1334,
314,
2895,
402,
199,
3,
1902,
314,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
1288,
503,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
1288,
199,
3,
315,
1314,
1930,
314,
1727,
1356,
402,
314,
14629,
503,
314,
32426,
787,
3964,
3140,
199,
3,
402,
5204,
3432,
14,
982,
1265,
13809,
370,
2040,
675,
402,
2195,
1015,
402,
642,
570,
1454,
199,
3,
1334,
314,
2895,
402,
1902,
314,
14629,
503,
314,
32426,
12,
436,
440,
370,
2040,
11789,
370,
199,
3,
675,
2195,
1015,
402,
642,
570,
1334,
314,
2895,
402,
314,
28481,
12,
6623,
2195,
199,
3,
14692,
701,
13794,
314,
1727,
1356,
3432,
436,
3350,
3062,
543,
314,
4245,
199,
3,
436,
1163,
1727,
1356,
1415,
701,
314,
14629,
503,
314,
32426,
14,
982,
1265,
886,
440,
3145,
199,
3,
314,
1727,
1356,
3432,
12,
282,
10318,
1443,
675,
2195,
1015,
402,
642,
570,
1334,
199,
3,
314,
2895,
402,
1263,
1373,
402,
314,
28481,
12,
314,
14629,
503,
314,
32426,
14,
199,
3,
199,
3,
1011,
9153,
7729,
5113,
8068,
1011,
9153,
199,
199,
82,
624,
21767,
2556,
3595,
1318,
1584,
14,
199,
199,
2765,
859,
30427,
16756,
314,
2644,
402,
1318,
1584,
334,
3239,
199,
63,
12334,
1399,
63,
2991,
367,
2436,
395,
1066,
895,
13824,
22975,
3366,
1584,
12,
436,
199,
20121,
16212,
3404,
2556,
402,
1318,
1584,
14,
339,
1306,
492,
1318,
815,
272,
1306,
931,
275,
636,
493,
363,
272,
1306,
340,
931,
14,
4130,
9520,
11357,
2349,
931,
275,
931,
4439,
17,
61,
272,
1306,
3367,
275,
1318,
815,
14,
505,
815,
63,
504,
63,
515,
8,
515,
9,
272,
1306,
3367,
855,
533,
363,
272,
665,
533,
283,
505,
815,
14,
1872,
2354,
8423,
272,
1306,
3367,
14,
2991,
272,
283,
1624,
13,
24,
7,
272,
1306,
3367,
14,
493,
63,
466,
63,
354,
272,
283,
7898,
570,
7,
272,
1306,
3367,
14,
374,
63,
505,
272,
715,
272,
1306,
3367,
14,
4159,
272,
283,
4718,
7,
272,
1306,
3367,
14,
4159,
815,
272,
665,
4718,
491,
621,
2354,
30,
199,
199,
1396,
6666,
282,
1329,
402,
1163,
2997,
2556,
486,
1270,
379,
687,
314,
570,
14,
4005,
1937,
199,
65,
769,
402,
1006,
2997,
3004,
1937,
339,
4331,
769,
8,
280,
14,
305,
63,
807,
1252,
1612,
1012,
272,
788,
2991,
297,
283,
493,
63,
466,
297,
21214,
199,
199,
7443,
26,
961,
859,
5074,
737,
5210,
2018,
499,
14,
21,
370,
675,
199,
64,
8933,
14,
3892,
27530,
10945,
354,
10121,
354,
2313,
199,
624,
199,
199,
63,
1760,
6066,
63,
1301,
275,
408,
21767,
2556,
3595,
1318,
1584,
14,
199,
624,
199,
199,
3,
3254,
26,
199,
3,
446,
359,
6260,
20449,
61,
28516,
13150,
199,
3,
446,
1839,
303,
14841,
298,
374,
2337,
376,
5027,
2644,
15021,
315,
642,
570,
2,
687,
4692,
12,
4163,
12,
199,
3,
257,
6339,
13,
6100,
12,
325,
19309,
436,
1321,
6802,
477,
1886,
334,
305,
4339,
527,
939,
543,
5244,
5865,
9,
199,
3,
446,
5325,
3367,
543,
2649,
3792,
5417,
334,
1074,
641,
10130,
4634,
9,
199,
3,
446,
2475,
44,
92,
306,
27915,
7,
945,
282,
1127,
658,
493,
64,
436,
658,
478,
64,
199,
3,
446,
1666,
26,
1455,
921,
1129,
2501,
416,
806,
14,
1259,
14,
605,
415,
15515,
14,
8654,
15,
8664,
15,
1317,
13,
5167,
15126,
316,
15,
199,
3,
446,
29800,
13,
22290,
2644,
365,
440,
10501,
367,
199,
3,
257,
1455,
921,
3455,
14,
32595,
14,
957,
15,
5645,
15,
439,
67,
15,
22805,
13,
1818,
15,
773,
15,
25928,
15,
3184,
15,
84,
15,
16780,
15,
83,
1465,
2766,
63,
83,
18941,
14,
2424,
199,
3,
257,
359,
19825,
336,
22665,
61,
199,
3,
257,
690,
22117,
314,
2213,
5712,
1133,
15836,
701,
1788,
3329,
465,
3625,
36,
12,
199,
3,
257,
690,
652,
1630,
1395,
3625,
36,
436,
282,
5226,
275,
2991,
13613,
14,
199,
3,
257,
18615,
18994,
1172,
282,
1564,
25332,
1104,
367,
3625,
36,
14,
199,
3,
199,
199,
3,
10652,
199,
3,
9338,
1804,
676,
19657,
334,
20,
14,
18,
9,
19694,
1487,
20667,
8144,
334,
2972,
367,
3659,
12,
199,
3,
1325,
440,
3679,
590,
9437,
304,
199,
3,
199,
3,
9361,
316,
4012,
20817,
5564,
1563,
423,
13552,
7630,
26,
199,
3,
257,
2644,
63,
354,
275,
20491,
26,
2991,
2698,
334,
265,
1642,
1343,
365,
663,
199,
3,
755,
370,
2644,
687,
5867,
14,
362,
885,
5508,
342,
13609,
12,
199,
3,
755,
9567,
370,
11601,
4830,
13,
17,
27,
849,
5867,
13609,
11187,
1536,
3769,
26,
199,
3,
3698,
5417,
26,
7667,
19364,
199,
3,
3698,
10444,
4403,
1323,
26,
4497,
13
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1011,
9153,
16427,
5113,
8068,
1011,
9153,
199,
3,
3394,
26,
28481,
413,
14,
17,
15,
12006,
499,
14,
16,
15,
44,
12006,
499,
14,
17,
199,
3,
199,
3,
710,
4072,
402,
642,
570,
787,
5420,
370,
314,
17728,
1684,
844,
199,
3,
3394,
413,
14,
17,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
199,
3,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
1455,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
199,
3,
199,
3,
2290,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
199,
3,
5597,
12,
2428,
3408,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
4481,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
3,
710,
12769,
5495,
365,
1804,
676,
19657,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
23241,
2223,
2290,
3277,
14,
199,
3,
20825,
2737,
701,
23241,
2223,
2290,
3277,
787,
1898,
334,
35,
9,
12293,
13,
9488,
199,
3,
23241,
2223,
2290,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
23241,
2223,
2290,
3277,
199,
3,
199,
3,
26776,
12,
314,
4072,
402,
642,
570,
1443,
506,
1202,
1334,
314,
2895,
402,
199,
3,
1902,
314,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
1288,
503,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
1288,
199,
3,
315,
1314,
1930,
314,
1727,
1356,
402,
314,
14629,
503,
314,
32426,
787,
3964,
3140,
199,
3,
402,
5204,
3432,
14,
982,
1265,
13809,
370,
2040,
675,
402,
2195,
1015,
402,
642,
570,
1454,
199,
3,
1334,
314,
2895,
402,
1902,
314,
14629,
503,
314,
32426,
12,
436,
440,
370,
2040,
11789,
370,
199,
3,
675,
2195,
1015,
402,
642,
570,
1334,
314,
2895,
402,
314,
28481,
12,
6623,
2195,
199,
3,
14692,
701,
13794,
314,
1727,
1356,
3432,
436,
3350,
3062,
543,
314,
4245,
199,
3,
436,
1163,
1727,
1356,
1415,
701,
314,
14629,
503,
314,
32426,
14,
982,
1265,
886,
440,
3145,
199,
3,
314,
1727,
1356,
3432,
12,
282,
10318,
1443,
675,
2195,
1015,
402,
642,
570,
1334,
199,
3,
314,
2895,
402,
1263,
1373,
402,
314,
28481,
12,
314,
14629,
503,
314,
32426,
14,
199,
3,
199,
3,
1011,
9153,
7729,
5113,
8068,
1011,
9153,
199,
199,
82,
624,
21767,
2556,
3595,
1318,
1584,
14,
199,
199,
2765,
859,
30427,
16756,
314,
2644,
402,
1318,
1584,
334,
3239,
199,
63,
12334,
1399,
63,
2991,
367,
2436,
395,
1066,
895,
13824,
22975,
3366,
1584,
12,
436,
199,
20121,
16212,
3404,
2556,
402,
1318,
1584,
14,
339,
1306,
492,
1318,
815,
272,
1306,
931,
275,
636,
493,
363,
272,
1306,
340,
931,
14,
4130,
9520,
11357,
2349,
931,
275,
931,
4439,
17,
61,
272,
1306,
3367,
275,
1318,
815,
14,
505,
815,
63,
504,
63,
515,
8,
515,
9,
272,
1306,
3367,
855,
533,
363,
272,
665,
533,
283,
505,
815,
14,
1872,
2354,
8423,
272,
1306,
3367,
14,
2991,
272,
283,
1624,
13,
24,
7,
272,
1306,
3367,
14,
493,
63,
466,
63,
354,
272,
283,
7898,
570,
7,
272,
1306,
3367,
14,
374,
63,
505,
272,
715,
272,
1306,
3367,
14,
4159,
272,
283,
4718,
7,
272,
1306,
3367,
14,
4159,
815,
272,
665,
4718,
491,
621,
2354,
30,
199,
199,
1396,
6666,
282,
1329,
402,
1163,
2997,
2556,
486,
1270,
379,
687,
314,
570,
14,
4005,
1937,
199,
65,
769,
402,
1006,
2997,
3004,
1937,
339,
4331,
769,
8,
280,
14,
305,
63,
807,
1252,
1612,
1012,
272,
788,
2991,
297,
283,
493,
63,
466,
297,
21214,
199,
199,
7443,
26,
961,
859,
5074,
737,
5210,
2018,
499,
14,
21,
370,
675,
199,
64,
8933,
14,
3892,
27530,
10945,
354,
10121,
354,
2313,
199,
624,
199,
199,
63,
1760,
6066,
63,
1301,
275,
408,
21767,
2556,
3595,
1318,
1584,
14,
199,
624,
199,
199,
3,
3254,
26,
199,
3,
446,
359,
6260,
20449,
61,
28516,
13150,
199,
3,
446,
1839,
303,
14841,
298,
374,
2337,
376,
5027,
2644,
15021,
315,
642,
570,
2,
687,
4692,
12,
4163,
12,
199,
3,
257,
6339,
13,
6100,
12,
325,
19309,
436,
1321,
6802,
477,
1886,
334,
305,
4339,
527,
939,
543,
5244,
5865,
9,
199,
3,
446,
5325,
3367,
543,
2649,
3792,
5417,
334,
1074,
641,
10130,
4634,
9,
199,
3,
446,
2475,
44,
92,
306,
27915,
7,
945,
282,
1127,
658,
493,
64,
436,
658,
478,
64,
199,
3,
446,
1666,
26,
1455,
921,
1129,
2501,
416,
806,
14,
1259,
14,
605,
415,
15515,
14,
8654,
15,
8664,
15,
1317,
13,
5167,
15126,
316,
15,
199,
3,
446,
29800,
13,
22290,
2644,
365,
440,
10501,
367,
199,
3,
257,
1455,
921,
3455,
14,
32595,
14,
957,
15,
5645,
15,
439,
67,
15,
22805,
13,
1818,
15,
773,
15,
25928,
15,
3184,
15,
84,
15,
16780,
15,
83,
1465,
2766,
63,
83,
18941,
14,
2424,
199,
3,
257,
359,
19825,
336,
22665,
61,
199,
3,
257,
690,
22117,
314,
2213,
5712,
1133,
15836,
701,
1788,
3329,
465,
3625,
36,
12,
199,
3,
257,
690,
652,
1630,
1395,
3625,
36,
436,
282,
5226,
275,
2991,
13613,
14,
199,
3,
257,
18615,
18994,
1172,
282,
1564,
25332,
1104,
367,
3625,
36,
14,
199,
3,
199,
199,
3,
10652,
199,
3,
9338,
1804,
676,
19657,
334,
20,
14,
18,
9,
19694,
1487,
20667,
8144,
334,
2972,
367,
3659,
12,
199,
3,
1325,
440,
3679,
590,
9437,
304,
199,
3,
199,
3,
9361,
316,
4012,
20817,
5564,
1563,
423,
13552,
7630,
26,
199,
3,
257,
2644,
63,
354,
275,
20491,
26,
2991,
2698,
334,
265,
1642,
1343,
365,
663,
199,
3,
755,
370,
2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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
] |
jose36/plugin.video.Jmdl1
|
servers/userporn.py
|
33
|
4917
|
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# pelisalacarta - XBMC Plugin
# Conector para userporn
# http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/
#------------------------------------------------------------
import os,re
import base64
from core import scrapertools
from core import logger
from core import config
HOSTER_KEY="NTI2NzI5Cgo="
# Returns an array of possible video url's from the page_url
def get_video_url( page_url , premium = False , user="" , password="", video_password="" ):
logger.info("[userporn.py] get_video_url(page_url='%s')" % page_url)
video_urls = []
# Espera un poco como hace el player flash
logger.info("[userporn.py] waiting 3 secs")
import time
time.sleep(3)
# Obtiene el id
code = Extract_id(page_url)
# Descarga el json con los detalles del vídeo
#http://www.userporn.com/player_control/settings.php?v=dvthddkC7l4J&em=TRUE&fv=v1.1.45
controluri = "http://userporn.com/player_control/settings.php?v=" + code + "&em=TRUE&fv=v1.1.45"
datajson = scrapertools.cachePage(controluri)
#logger.info("response="+datajson);
# Convierte el json en un diccionario
datajson = datajson.replace("false","False").replace("true","True")
datajson = datajson.replace("null","None")
datadict = eval("("+datajson+")")
# Formatos
formatos = datadict["settings"]["res"]
for formato in formatos:
uri = base64.decodestring(formato["u"])
resolucion = formato["l"]
import videobb
video_url = videobb.build_url(uri,HOSTER_KEY,datajson)
video_urls.append( ["%s [userporn]" % resolucion , video_url.replace(":80","") ])
for video_url in video_urls:
logger.info("[userporn.py] %s - %s" % (video_url[0],video_url[1]))
return video_urls
def Extract_id(url):
_VALID_URL = r'^((?:http://)?(?:\w+\.)?userporn\.com/(?:(?:(?:e/)|(?:video/))|(?:(?:flash/)|(?:f/)))?)?([0-9A-Za-z_-]+)(?(1).+)?$'
# Extract video id from URL
mobj = re.match(_VALID_URL, url)
if mobj is None:
logger.info('[userporn.py] ERROR: URL invalida: %s' % url)
return ""
id = mobj.group(2)
logger.info("[userporn.py] extracted code="+id)
return id
# Encuentra vídeos del servidor en el texto pasado
def find_videos(data):
encontrados = set()
devuelve = []
#Enlace estricto a userporn")
#userporn tipo "http://www.userporn.com/f/szIwlZD8ewaH.swf"
patronvideos = 'userporn.com\/f\/([A-Z0-9a-z]{12}).swf'
logger.info("[userporn.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos).findall(data)
for match in matches:
titulo = "[userporn]"
url = "http://www.userporn.com/video/"+match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'userporn' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
#logger.info ("1) Enlace estricto a userporn")
#userporn tipo "http://www.userporn.com/video/ZIeb370iuHE4"
patronvideos = 'userporn.com\/video\/([A-Z0-9a-z]{12})'
logger.info("[userporn.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos).findall(data)
for match in matches:
titulo = "[userporn]"
url = "http://www.userporn.com/video/"+match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'userporn' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
#logger.info ("2) Enlace estricto a userporn")
#userporn tipo "http://www.userporn.com/e/LLqVzhw5ft7T"
patronvideos = 'userporn.com\/e\/([A-Z0-9a-z]{12})'
logger.info("[userporn.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos).findall(data)
for match in matches:
titulo = "[userporn]"
url = "http://www.userporn.com/video/"+match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'userporn' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
patronvideos = "http\:\/\/(?:www\.)?userporn.com\/(?:(?:e/|flash/)|(?:(?:video/|f/)))?([a-zA-Z0-9]{0,12})"
logger.info("[userporn.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos,re.DOTALL).findall(data)
#print data
for match in matches:
titulo = "[Userporn]"
url = "http://www.userporn.com/video/"+match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'userporn' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
return devuelve
|
apache-2.0
|
[
172,
120,
124,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
17807,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
12665,
922,
80,
6161,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
17807,
4559,
199,
199,
646,
747,
12,
264,
199,
646,
1300,
772,
199,
199,
504,
6170,
492,
28348,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
1101,
199,
5449,
540,
63,
3078,
628,
12460,
41,
18,
23406,
41,
21,
35,
1939,
628,
199,
3,
1803,
376,
1625,
402,
3962,
3991,
1166,
1159,
687,
314,
2034,
63,
633,
199,
318,
664,
63,
3722,
63,
633,
8,
2034,
63,
633,
2360,
876,
23481,
275,
756,
2360,
922,
9287,
2360,
2505,
8772,
3991,
63,
2060,
9287,
3461,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
664,
63,
3722,
63,
633,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
339,
3991,
63,
3603,
275,
942,
272,
327,
662,
83,
529,
65,
625,
1115,
331,
512,
573,
394,
7984,
579,
7748,
14775,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
10923,
650,
20091,
531,
272,
492,
900,
272,
900,
14,
4532,
8,
19,
9,
2286,
327,
17985,
280,
6349,
579,
1305,
272,
1233,
275,
12892,
63,
344,
8,
1606,
63,
633,
9,
2286,
327,
8055,
67,
1273,
65,
579,
2022,
406,
16406,
20894,
279,
2978,
2150,
373,
13676,
2172,
272,
327,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
6147,
63,
2785,
15,
1751,
14,
8624,
31,
86,
29,
8398,
273,
617,
75,
35,
23,
76,
20,
42,
6,
5633,
29,
15064,
6,
13692,
29,
86,
17,
14,
17,
14,
2322,
272,
3304,
2302,
275,
298,
1014,
921,
751,
80,
6161,
14,
957,
15,
6147,
63,
2785,
15,
1751,
14,
8624,
31,
86,
628,
435,
1233,
435,
11746,
5633,
29,
15064,
6,
13692,
29,
86,
17,
14,
17,
14,
2322,
2,
272,
666,
1001,
275,
28348,
14,
1637,
3276,
8,
2785,
2302,
9,
272,
327,
2921,
14,
815,
480,
1310,
16368,
576,
1001,
2736,
339,
327,
1448,
26645,
266,
579,
2022,
655,
625,
12219,
9718,
6936,
272,
666,
1001,
275,
666,
1001,
14,
1814,
480,
3910,
2266,
797,
3471,
1814,
480,
2052,
2266,
549,
531,
272,
666,
1001,
275,
666,
1001,
14,
1814,
480,
2307,
2266,
403,
531,
272,
666,
807,
275,
3468,
480,
28819,
576,
1001,
21425,
531,
2286,
327,
9701,
736,
272,
1475,
736,
275,
666,
807,
905,
1751,
6611,
470,
937,
2286,
367,
1475,
79,
315,
1475,
736,
26,
267,
5108,
275,
1300,
772,
14,
2708,
875,
8,
908,
79,
905,
85,
3135,
267,
17416,
85,
9718,
275,
1475,
79,
905,
76,
937,
267,
492,
3991,
2501,
267,
3991,
63,
633,
275,
3991,
2501,
14,
1506,
63,
633,
8,
2302,
12,
5449,
540,
63,
3078,
12,
576,
1001,
9,
267,
3991,
63,
3603,
14,
740,
8,
28585,
83,
359,
751,
80,
6161,
8480,
450,
17416,
85,
9718,
2360,
3991,
63,
633,
14,
1814,
20308,
1257,
401,
7230,
4794,
339,
367,
3991,
63,
633,
315,
3991,
63,
3603,
26,
267,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
450,
83,
446,
450,
83,
2,
450,
334,
3722,
63,
633,
59,
16,
467,
3722,
63,
633,
59,
17,
2459,
339,
372,
3991,
63,
3603,
199,
199,
318,
12892,
63,
344,
8,
633,
304,
272,
485,
5600,
63,
2632,
275,
519,
4289,
17304,
26,
1014,
921,
5547,
15840,
87,
11,
20316,
751,
80,
6161,
4537,
957,
32576,
5169,
5169,
69,
15,
8636,
5169,
3722,
15,
430,
92,
5169,
5169,
11331,
15,
8636,
5169,
70,
15,
1724,
31,
5547,
779,
16,
13,
25,
33,
13,
13163,
13,
90,
32069,
11896,
2229,
8,
17,
680,
19544,
12913,
272,
327,
12892,
3991,
1305,
687,
2851,
272,
14208,
275,
295,
14,
1431,
1547,
5600,
63,
2632,
12,
1166,
9,
272,
340,
14208,
365,
488,
26,
267,
2512,
14,
815,
11894,
751,
80,
6161,
14,
647,
61,
12539,
26,
2851,
3866,
65,
26,
450,
83,
7,
450,
1166,
9,
267,
372,
3087,
272,
1305,
275,
14208,
14,
923,
8,
18,
9,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
12509,
1233,
16368,
344,
9,
272,
372,
1305,
199,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
2150,
8926,
5017,
269,
655,
579,
1318,
79,
19099,
5129,
199,
318,
2342,
63,
11418,
8,
576,
304,
272,
655,
17926,
18339,
275,
663,
342,
272,
4866,
13086,
432,
275,
942,
339,
327,
1327,
1071,
325,
4768,
79,
282,
922,
80,
6161,
531,
272,
327,
751,
80,
6161,
3367,
555,
298,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
70,
15,
11803,
41,
20159,
58,
36,
24,
546,
65,
40,
14,
20426,
2,
272,
32500,
11418,
275,
283,
751,
80,
6161,
14,
957,
19814,
70,
19814,
779,
33,
13,
58,
16,
13,
25,
65,
13,
90,
8194,
713,
21385,
20426,
7,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
680,
6452,
8,
576,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
751,
80,
6161,
8480,
267,
1166,
275,
298,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
3722,
25976,
1431,
398,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
751,
80,
6161,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
288,
272,
327,
2921,
14,
815,
1689,
17,
9,
3447,
1071,
325,
4768,
79,
282,
922,
80,
6161,
531,
272,
327,
751,
80,
6161,
3367,
555,
298,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
3722,
15,
58,
41,
2871,
13812,
73,
85,
1645,
20,
2,
272,
32500,
11418,
275,
283,
751,
80,
6161,
14,
957,
19814,
3722,
19814,
779,
33
] |
[
120,
124,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
17807,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
12665,
922,
80,
6161,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
17807,
4559,
199,
199,
646,
747,
12,
264,
199,
646,
1300,
772,
199,
199,
504,
6170,
492,
28348,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
1101,
199,
5449,
540,
63,
3078,
628,
12460,
41,
18,
23406,
41,
21,
35,
1939,
628,
199,
3,
1803,
376,
1625,
402,
3962,
3991,
1166,
1159,
687,
314,
2034,
63,
633,
199,
318,
664,
63,
3722,
63,
633,
8,
2034,
63,
633,
2360,
876,
23481,
275,
756,
2360,
922,
9287,
2360,
2505,
8772,
3991,
63,
2060,
9287,
3461,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
664,
63,
3722,
63,
633,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
339,
3991,
63,
3603,
275,
942,
272,
327,
662,
83,
529,
65,
625,
1115,
331,
512,
573,
394,
7984,
579,
7748,
14775,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
10923,
650,
20091,
531,
272,
492,
900,
272,
900,
14,
4532,
8,
19,
9,
2286,
327,
17985,
280,
6349,
579,
1305,
272,
1233,
275,
12892,
63,
344,
8,
1606,
63,
633,
9,
2286,
327,
8055,
67,
1273,
65,
579,
2022,
406,
16406,
20894,
279,
2978,
2150,
373,
13676,
2172,
272,
327,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
6147,
63,
2785,
15,
1751,
14,
8624,
31,
86,
29,
8398,
273,
617,
75,
35,
23,
76,
20,
42,
6,
5633,
29,
15064,
6,
13692,
29,
86,
17,
14,
17,
14,
2322,
272,
3304,
2302,
275,
298,
1014,
921,
751,
80,
6161,
14,
957,
15,
6147,
63,
2785,
15,
1751,
14,
8624,
31,
86,
628,
435,
1233,
435,
11746,
5633,
29,
15064,
6,
13692,
29,
86,
17,
14,
17,
14,
2322,
2,
272,
666,
1001,
275,
28348,
14,
1637,
3276,
8,
2785,
2302,
9,
272,
327,
2921,
14,
815,
480,
1310,
16368,
576,
1001,
2736,
339,
327,
1448,
26645,
266,
579,
2022,
655,
625,
12219,
9718,
6936,
272,
666,
1001,
275,
666,
1001,
14,
1814,
480,
3910,
2266,
797,
3471,
1814,
480,
2052,
2266,
549,
531,
272,
666,
1001,
275,
666,
1001,
14,
1814,
480,
2307,
2266,
403,
531,
272,
666,
807,
275,
3468,
480,
28819,
576,
1001,
21425,
531,
2286,
327,
9701,
736,
272,
1475,
736,
275,
666,
807,
905,
1751,
6611,
470,
937,
2286,
367,
1475,
79,
315,
1475,
736,
26,
267,
5108,
275,
1300,
772,
14,
2708,
875,
8,
908,
79,
905,
85,
3135,
267,
17416,
85,
9718,
275,
1475,
79,
905,
76,
937,
267,
492,
3991,
2501,
267,
3991,
63,
633,
275,
3991,
2501,
14,
1506,
63,
633,
8,
2302,
12,
5449,
540,
63,
3078,
12,
576,
1001,
9,
267,
3991,
63,
3603,
14,
740,
8,
28585,
83,
359,
751,
80,
6161,
8480,
450,
17416,
85,
9718,
2360,
3991,
63,
633,
14,
1814,
20308,
1257,
401,
7230,
4794,
339,
367,
3991,
63,
633,
315,
3991,
63,
3603,
26,
267,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
450,
83,
446,
450,
83,
2,
450,
334,
3722,
63,
633,
59,
16,
467,
3722,
63,
633,
59,
17,
2459,
339,
372,
3991,
63,
3603,
199,
199,
318,
12892,
63,
344,
8,
633,
304,
272,
485,
5600,
63,
2632,
275,
519,
4289,
17304,
26,
1014,
921,
5547,
15840,
87,
11,
20316,
751,
80,
6161,
4537,
957,
32576,
5169,
5169,
69,
15,
8636,
5169,
3722,
15,
430,
92,
5169,
5169,
11331,
15,
8636,
5169,
70,
15,
1724,
31,
5547,
779,
16,
13,
25,
33,
13,
13163,
13,
90,
32069,
11896,
2229,
8,
17,
680,
19544,
12913,
272,
327,
12892,
3991,
1305,
687,
2851,
272,
14208,
275,
295,
14,
1431,
1547,
5600,
63,
2632,
12,
1166,
9,
272,
340,
14208,
365,
488,
26,
267,
2512,
14,
815,
11894,
751,
80,
6161,
14,
647,
61,
12539,
26,
2851,
3866,
65,
26,
450,
83,
7,
450,
1166,
9,
267,
372,
3087,
272,
1305,
275,
14208,
14,
923,
8,
18,
9,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
12509,
1233,
16368,
344,
9,
272,
372,
1305,
199,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
2150,
8926,
5017,
269,
655,
579,
1318,
79,
19099,
5129,
199,
318,
2342,
63,
11418,
8,
576,
304,
272,
655,
17926,
18339,
275,
663,
342,
272,
4866,
13086,
432,
275,
942,
339,
327,
1327,
1071,
325,
4768,
79,
282,
922,
80,
6161,
531,
272,
327,
751,
80,
6161,
3367,
555,
298,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
70,
15,
11803,
41,
20159,
58,
36,
24,
546,
65,
40,
14,
20426,
2,
272,
32500,
11418,
275,
283,
751,
80,
6161,
14,
957,
19814,
70,
19814,
779,
33,
13,
58,
16,
13,
25,
65,
13,
90,
8194,
713,
21385,
20426,
7,
272,
2512,
14,
815,
10994,
751,
80,
6161,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
680,
6452,
8,
576,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
751,
80,
6161,
8480,
267,
1166,
275,
298,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
3722,
25976,
1431,
398,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
751,
80,
6161,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
288,
272,
327,
2921,
14,
815,
1689,
17,
9,
3447,
1071,
325,
4768,
79,
282,
922,
80,
6161,
531,
272,
327,
751,
80,
6161,
3367,
555,
298,
1014,
921,
1544,
14,
751,
80,
6161,
14,
957,
15,
3722,
15,
58,
41,
2871,
13812,
73,
85,
1645,
20,
2,
272,
32500,
11418,
275,
283,
751,
80,
6161,
14,
957,
19814,
3722,
19814,
779,
33,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
unnikrishnankgs/va
|
annotator/models.py
|
1
|
2852
|
from django.db import models
from django.contrib.staticfiles import finders
class Video(models.Model):
annotation = models.TextField(blank=True,
help_text="A JSON blob containing all user annotation sent from client.")
source = models.CharField(max_length=1048, blank=True,
help_text=("Name of video source or type, for easier grouping/searching of videos."
"This field is not used by BeaverDam and only facilitates querying on videos by type."))
filename = models.CharField(max_length=100, blank=True,
help_text=("Name of the video file."
"The video should be publically accessible by at <host><filename>."))
image_list = models.TextField(blank=True,
help_text=("List of filenames of images to be used as video frames, in JSON format."
"When present, image list is assumed and <filename> is ignored."))
host = models.CharField(max_length=1048, blank=True,
help_text="Path to prepend to filenames to form the url for this video or the images in `image_list`.")
verified = models.BooleanField(default=False, help_text="Verified as correct by expert.")
rejected = models.BooleanField(default=False, help_text="Rejected by expert.")
@classmethod
def from_list(cls, path_to_list, *, source, host, filename_prefix=''):
created = []
for line in open(path_to_list, 'r'):
if line:
video = cls(source=source, filename=filename_prefix + line.strip(), host=host)
video.save()
created.append(video)
return created
def __str__(self):
return '/video/{}'.format(self.id)
@property
def url(self):
if self.image_list:
return 'Image List'
elif finders.find('videos/{}.mp4'.format(self.id)):
return '/static/videos/{}.mp4'.format(self.id)
elif self.filename and self.host:
return self.host + self.filename
else:
raise Exception('Video {0} does not have a filename, host or image_list. Possible fixes: \n1) Place {0}.mp4 into static/videos to serve locally. \n2) Update the filename & host fields of the Video with id={0}'.format(self.id)) + self.filename
def count_keyframes(self, at_time=None):
if at_time is None:
return self.annotation.count('"frame"')
else:
return self.annotation.count('"frame": {}'.format(at_time))
class Label(models.Model):
"""The classes available for workers to choose from for each object."""
id = models.AutoField(primary_key=True)
name = models.CharField(blank=True, max_length=100, unique=True,
help_text="Name of class label option.")
color = models.CharField(blank=True, max_length=6,
help_text="6 digit hex.")
def __str__(self):
return self.name
|
bsd-2-clause
|
[
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
18373,
492,
2583,
7735,
199,
199,
533,
15709,
8,
992,
14,
1685,
304,
272,
11262,
275,
1709,
14,
6254,
8,
2500,
29,
549,
12,
267,
1720,
63,
505,
628,
33,
4840,
9182,
3035,
1006,
922,
11262,
4847,
687,
1890,
2685,
272,
1350,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
2006,
12,
4596,
29,
549,
12,
267,
1720,
63,
505,
15387,
985,
402,
3991,
1350,
503,
730,
12,
367,
14905,
17786,
15,
1733,
316,
402,
22010,
2122,
288,
298,
2765,
901,
365,
440,
1202,
701,
13787,
422,
36,
455,
436,
1454,
30242,
1051,
2335,
27405,
641,
22010,
701,
730,
13853,
272,
1788,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
4596,
29,
549,
12,
267,
1720,
63,
505,
15387,
985,
402,
314,
3991,
570,
2122,
288,
298,
1918,
3991,
1077,
506,
4575,
1183,
17909,
701,
737,
665,
1102,
2535,
1501,
30,
13853,
272,
1834,
63,
513,
275,
1709,
14,
6254,
8,
2500,
29,
549,
12,
267,
1720,
63,
505,
15387,
1296,
402,
6203,
402,
5935,
370,
506,
1202,
465,
3991,
11223,
12,
315,
4840,
1475,
2122,
288,
298,
11423,
3451,
12,
1834,
769,
365,
10826,
436,
665,
1501,
30,
365,
5525,
13853,
272,
1591,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
2006,
12,
4596,
29,
549,
12,
267,
1720,
63,
505,
628,
2042,
370,
18213,
370,
6203,
370,
1824,
314,
1166,
367,
642,
3991,
503,
314,
5935,
315,
658,
1569,
63,
513,
2313,
531,
272,
16317,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
628,
3673,
4541,
465,
3211,
701,
444,
28621,
2685,
272,
18935,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
628,
497,
8553,
701,
444,
28621,
2685,
339,
768,
3744,
272,
347,
687,
63,
513,
8,
1886,
12,
931,
63,
475,
63,
513,
12,
9889,
1350,
12,
1591,
12,
1788,
63,
1861,
9280,
267,
2737,
275,
942,
267,
367,
1004,
315,
1551,
8,
515,
63,
475,
63,
513,
12,
283,
82,
735,
288,
340,
1004,
26,
355,
3991,
275,
843,
8,
1365,
29,
1365,
12,
1788,
29,
1501,
63,
1861,
435,
1004,
14,
1913,
1062,
1591,
29,
1102,
9,
355,
3991,
14,
2117,
342,
355,
2737,
14,
740,
8,
3722,
9,
267,
372,
2737,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1994,
3722,
30837,
908,
8,
277,
14,
344,
9,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
340,
291,
14,
1569,
63,
513,
26,
288,
372,
283,
3491,
3820,
7,
267,
916,
2583,
7735,
14,
1623,
360,
11418,
14698,
14,
311,
20,
1370,
908,
8,
277,
14,
344,
2298,
288,
372,
1994,
1986,
15,
11418,
14698,
14,
311,
20,
1370,
908,
8,
277,
14,
344,
9,
267,
916,
291,
14,
1501,
436,
291,
14,
1102,
26,
288,
372,
291,
14,
1102,
435,
291,
14,
1501,
267,
587,
26,
288,
746,
2186,
360,
9166,
469,
16,
93,
1630,
440,
1172,
282,
1788,
12,
1591,
503,
1834,
63,
513,
14,
18558,
25079,
26,
971,
78,
17,
9,
10902,
469,
16,
5565,
311,
20,
1901,
2955,
15,
11418,
370,
14062,
17738,
14,
971,
78,
18,
9,
6162,
314,
1788,
1253,
1591,
1504,
402,
314,
15709,
543,
1305,
3126,
16,
5285,
908,
8,
277,
14,
344,
430,
435,
291,
14,
1501,
339,
347,
2338,
63,
498,
8444,
8,
277,
12,
737,
63,
521,
29,
403,
304,
267,
340,
737,
63,
521,
365,
488,
26,
288,
372,
291,
14,
9340,
14,
835,
14088,
1943,
9008,
267,
587,
26,
288,
372,
291,
14,
9340,
14,
835,
14088,
1943,
582,
9499,
908,
8,
292,
63,
521,
430,
199,
199,
533,
10354,
8,
992,
14,
1685,
304,
272,
408,
1918,
3992,
2808,
367,
14123,
370,
11496,
687,
367,
1924,
909,
1041,
272,
1305,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
536,
275,
1709,
14,
2183,
8,
2500,
29,
549,
12,
1390,
63,
1267,
29,
1960,
12,
3747,
29,
549,
12,
267,
1720,
63,
505,
628,
985,
402,
1021,
1768,
945,
2685,
272,
3164,
275,
1709,
14,
2183,
8,
2500,
29,
549,
12,
1390,
63,
1267,
29,
22,
12,
267,
1720,
63,
505,
628,
22,
10964,
6318,
2685,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
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
] |
[
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
2828,
14,
18373,
492,
2583,
7735,
199,
199,
533,
15709,
8,
992,
14,
1685,
304,
272,
11262,
275,
1709,
14,
6254,
8,
2500,
29,
549,
12,
267,
1720,
63,
505,
628,
33,
4840,
9182,
3035,
1006,
922,
11262,
4847,
687,
1890,
2685,
272,
1350,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
2006,
12,
4596,
29,
549,
12,
267,
1720,
63,
505,
15387,
985,
402,
3991,
1350,
503,
730,
12,
367,
14905,
17786,
15,
1733,
316,
402,
22010,
2122,
288,
298,
2765,
901,
365,
440,
1202,
701,
13787,
422,
36,
455,
436,
1454,
30242,
1051,
2335,
27405,
641,
22010,
701,
730,
13853,
272,
1788,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
12,
4596,
29,
549,
12,
267,
1720,
63,
505,
15387,
985,
402,
314,
3991,
570,
2122,
288,
298,
1918,
3991,
1077,
506,
4575,
1183,
17909,
701,
737,
665,
1102,
2535,
1501,
30,
13853,
272,
1834,
63,
513,
275,
1709,
14,
6254,
8,
2500,
29,
549,
12,
267,
1720,
63,
505,
15387,
1296,
402,
6203,
402,
5935,
370,
506,
1202,
465,
3991,
11223,
12,
315,
4840,
1475,
2122,
288,
298,
11423,
3451,
12,
1834,
769,
365,
10826,
436,
665,
1501,
30,
365,
5525,
13853,
272,
1591,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
709,
2006,
12,
4596,
29,
549,
12,
267,
1720,
63,
505,
628,
2042,
370,
18213,
370,
6203,
370,
1824,
314,
1166,
367,
642,
3991,
503,
314,
5935,
315,
658,
1569,
63,
513,
2313,
531,
272,
16317,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
628,
3673,
4541,
465,
3211,
701,
444,
28621,
2685,
272,
18935,
275,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
628,
497,
8553,
701,
444,
28621,
2685,
339,
768,
3744,
272,
347,
687,
63,
513,
8,
1886,
12,
931,
63,
475,
63,
513,
12,
9889,
1350,
12,
1591,
12,
1788,
63,
1861,
9280,
267,
2737,
275,
942,
267,
367,
1004,
315,
1551,
8,
515,
63,
475,
63,
513,
12,
283,
82,
735,
288,
340,
1004,
26,
355,
3991,
275,
843,
8,
1365,
29,
1365,
12,
1788,
29,
1501,
63,
1861,
435,
1004,
14,
1913,
1062,
1591,
29,
1102,
9,
355,
3991,
14,
2117,
342,
355,
2737,
14,
740,
8,
3722,
9,
267,
372,
2737,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1994,
3722,
30837,
908,
8,
277,
14,
344,
9,
339,
768,
1829,
272,
347,
1166,
8,
277,
304,
267,
340,
291,
14,
1569,
63,
513,
26,
288,
372,
283,
3491,
3820,
7,
267,
916,
2583,
7735,
14,
1623,
360,
11418,
14698,
14,
311,
20,
1370,
908,
8,
277,
14,
344,
2298,
288,
372,
1994,
1986,
15,
11418,
14698,
14,
311,
20,
1370,
908,
8,
277,
14,
344,
9,
267,
916,
291,
14,
1501,
436,
291,
14,
1102,
26,
288,
372,
291,
14,
1102,
435,
291,
14,
1501,
267,
587,
26,
288,
746,
2186,
360,
9166,
469,
16,
93,
1630,
440,
1172,
282,
1788,
12,
1591,
503,
1834,
63,
513,
14,
18558,
25079,
26,
971,
78,
17,
9,
10902,
469,
16,
5565,
311,
20,
1901,
2955,
15,
11418,
370,
14062,
17738,
14,
971,
78,
18,
9,
6162,
314,
1788,
1253,
1591,
1504,
402,
314,
15709,
543,
1305,
3126,
16,
5285,
908,
8,
277,
14,
344,
430,
435,
291,
14,
1501,
339,
347,
2338,
63,
498,
8444,
8,
277,
12,
737,
63,
521,
29,
403,
304,
267,
340,
737,
63,
521,
365,
488,
26,
288,
372,
291,
14,
9340,
14,
835,
14088,
1943,
9008,
267,
587,
26,
288,
372,
291,
14,
9340,
14,
835,
14088,
1943,
582,
9499,
908,
8,
292,
63,
521,
430,
199,
199,
533,
10354,
8,
992,
14,
1685,
304,
272,
408,
1918,
3992,
2808,
367,
14123,
370,
11496,
687,
367,
1924,
909,
1041,
272,
1305,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
536,
275,
1709,
14,
2183,
8,
2500,
29,
549,
12,
1390,
63,
1267,
29,
1960,
12,
3747,
29,
549,
12,
267,
1720,
63,
505,
628,
985,
402,
1021,
1768,
945,
2685,
272,
3164,
275,
1709,
14,
2183,
8,
2500,
29,
549,
12,
1390,
63,
1267,
29,
22,
12,
267,
1720,
63,
505,
628,
22,
10964,
6318,
2685,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
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,
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,
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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,
0,
0
] |
ninuxorg/nodeshot
|
nodeshot/interop/sync/migrations/0001_initial.py
|
5
|
2393
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django_hstore.fields
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='LayerExternal',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('layer', models.OneToOneField(parent_link=True, related_name='external', verbose_name='layer', to='layers.Layer')),
('synchronizer_path', models.CharField(default=b'None', max_length=128, verbose_name='synchronizer', choices=[(b'None', 'None'), (b'nodeshot.interop.sync.synchronizers.Nodeshot', b'Nodeshot (RESTful translator)'), (b'nodeshot.interop.sync.synchronizers.GeoJson', b'GeoJSON (periodic sync)'), (b'nodeshot.interop.sync.synchronizers.GeoRss', b'GeoRSS (periodic sync)'), (b'nodeshot.interop.sync.synchronizers.OpenWisp', b'OpenWisp (periodic sync)'), (b'nodeshot.interop.sync.synchronizers.Cnml', b'CNML (periodic sync)')])),
('config', django_hstore.fields.DictionaryField(help_text='Synchronizer specific configuration (eg: API URL, auth info, ecc)', verbose_name='configuration', null=True, editable=False, blank=True)),
],
options={
'db_table': 'layers_external',
'verbose_name': 'external layer',
'verbose_name_plural': 'external layer info',
},
),
migrations.CreateModel(
name='NodeExternal',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('node', models.OneToOneField(parent_link=True, related_name='external', verbose_name='node', to='nodes.Node')),
('external_id', models.CharField(help_text='ID of this node on the external layer, might be a hash or an integer\n or whatever other format the external application uses to store IDs', max_length=255, verbose_name='external id', blank=True)),
],
options={
'db_table': 'nodes_external',
'verbose_name': 'external node',
'verbose_name_plural': 'external node info',
},
),
]
|
gpl-3.0
|
[
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,
199,
646,
1639,
63,
72,
1617,
14,
955,
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,
5003,
11389,
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,
1897,
297,
1709,
14,
14298,
8,
1708,
63,
1073,
29,
549,
12,
4048,
63,
354,
534,
5159,
297,
3376,
63,
354,
534,
1897,
297,
370,
534,
4359,
14,
5003,
3855,
355,
661,
16473,
1793,
63,
515,
297,
1709,
14,
2183,
8,
885,
29,
66,
7,
403,
297,
1390,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
16473,
1793,
297,
3415,
17497,
66,
7,
403,
297,
283,
403,
659,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
1716,
2782,
297,
330,
7,
1716,
2782,
334,
15740,
1893,
32034,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
10748,
9653,
297,
330,
7,
10748,
6243,
334,
20339,
7604,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
10748,
50,
385,
297,
330,
7,
10748,
22786,
334,
20339,
7604,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
4299,
55,
27474,
297,
330,
7,
4299,
55,
27474,
334,
20339,
7604,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
35,
78,
757,
297,
330,
7,
12874,
1698,
334,
20339,
7604,
9,
2023,
395,
355,
661,
888,
297,
1639,
63,
72,
1617,
14,
955,
14,
11728,
792,
8,
3437,
63,
505,
534,
21814,
1793,
2488,
2897,
334,
5902,
26,
3261,
2851,
12,
1790,
2256,
12,
325,
2055,
3196,
3376,
63,
354,
534,
4758,
297,
2973,
29,
549,
12,
14783,
29,
797,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
697,
63,
1224,
356,
283,
4359,
63,
5159,
297,
355,
283,
3832,
63,
354,
356,
283,
5159,
4045,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
5159,
4045,
2256,
297,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
1716,
11389,
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,
932,
297,
1709,
14,
14298,
8,
1708,
63,
1073,
29,
549,
12,
4048,
63,
354,
534,
5159,
297,
3376,
63,
354,
534,
932,
297,
370,
534,
2415,
14,
1716,
3855,
355,
661,
5159,
63,
344,
297,
1709,
14,
2183,
8,
3437,
63,
505,
534,
998,
402,
642,
1031,
641,
314,
5957,
4045,
12,
5594,
506,
282,
2631,
503,
376,
3000,
60,
78,
2476,
5185,
503,
15685,
1163,
1475,
314,
5957,
4223,
4440,
370,
3877,
11449,
297,
1390,
63,
1267,
29,
2299,
12,
3376,
63,
354,
534,
5159,
1305,
297,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
697,
63,
1224,
356,
283,
2415,
63,
5159,
297,
355,
283,
3832,
63,
354,
356,
283,
5159,
1031,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
5159,
1031,
2256,
297,
288,
1660,
267,
2318,
272,
1622,
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
] |
[
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,
199,
646,
1639,
63,
72,
1617,
14,
955,
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,
5003,
11389,
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,
1897,
297,
1709,
14,
14298,
8,
1708,
63,
1073,
29,
549,
12,
4048,
63,
354,
534,
5159,
297,
3376,
63,
354,
534,
1897,
297,
370,
534,
4359,
14,
5003,
3855,
355,
661,
16473,
1793,
63,
515,
297,
1709,
14,
2183,
8,
885,
29,
66,
7,
403,
297,
1390,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
16473,
1793,
297,
3415,
17497,
66,
7,
403,
297,
283,
403,
659,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
1716,
2782,
297,
330,
7,
1716,
2782,
334,
15740,
1893,
32034,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
10748,
9653,
297,
330,
7,
10748,
6243,
334,
20339,
7604,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
10748,
50,
385,
297,
330,
7,
10748,
22786,
334,
20339,
7604,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
4299,
55,
27474,
297,
330,
7,
4299,
55,
27474,
334,
20339,
7604,
11218,
334,
66,
7,
932,
2782,
14,
5707,
2675,
14,
5186,
14,
16473,
6315,
14,
35,
78,
757,
297,
330,
7,
12874,
1698,
334,
20339,
7604,
9,
2023,
395,
355,
661,
888,
297,
1639,
63,
72,
1617,
14,
955,
14,
11728,
792,
8,
3437,
63,
505,
534,
21814,
1793,
2488,
2897,
334,
5902,
26,
3261,
2851,
12,
1790,
2256,
12,
325,
2055,
3196,
3376,
63,
354,
534,
4758,
297,
2973,
29,
549,
12,
14783,
29,
797,
12,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
697,
63,
1224,
356,
283,
4359,
63,
5159,
297,
355,
283,
3832,
63,
354,
356,
283,
5159,
4045,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
5159,
4045,
2256,
297,
288,
1660,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
1716,
11389,
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,
932,
297,
1709,
14,
14298,
8,
1708,
63,
1073,
29,
549,
12,
4048,
63,
354,
534,
5159,
297,
3376,
63,
354,
534,
932,
297,
370,
534,
2415,
14,
1716,
3855,
355,
661,
5159,
63,
344,
297,
1709,
14,
2183,
8,
3437,
63,
505,
534,
998,
402,
642,
1031,
641,
314,
5957,
4045,
12,
5594,
506,
282,
2631,
503,
376,
3000,
60,
78,
2476,
5185,
503,
15685,
1163,
1475,
314,
5957,
4223,
4440,
370,
3877,
11449,
297,
1390,
63,
1267,
29,
2299,
12,
3376,
63,
354,
534,
5159,
1305,
297,
4596,
29,
549,
1826,
288,
2156,
288,
1511,
3126,
355,
283,
697,
63,
1224,
356,
283,
2415,
63,
5159,
297,
355,
283,
3832,
63,
354,
356,
283,
5159,
1031,
297,
355,
283,
3832,
63,
354,
63,
10019,
356,
283,
5159,
1031,
2256,
297,
288,
1660,
267,
2318,
272,
1622,
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,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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
] |
SIFTeam/enigma2
|
lib/python/SIFTeam/Preferences.py
|
2
|
1786
|
from Screens.Screen import Screen
from Plugins.Plugin import PluginDescriptor
from Components.SystemInfo import SystemInfo
from Components.ConfigList import ConfigListScreen
from Components.config import getConfigListEntry, config, ConfigBoolean
from Components.ActionMap import ActionMap
from Components.Button import Button
class Preferences(Screen, ConfigListScreen):
def __init__(self, session):
Screen.__init__(self, session)
self.list = [
getConfigListEntry(_("Start emulator at:"), config.sifteam.emudelay),
getConfigListEntry(_("Skin developer mode:"), config.sifteam.skindevelopermode),
getConfigListEntry(_("Video green switch enable 4:3 letterbox:"), config.sifteam.switch_4_3_letterbox),
getConfigListEntry(_("Video green switch enable 4:3 panscan:"), config.sifteam.switch_4_3_panscan),
getConfigListEntry(_("Video green switch enable 16:9:"), config.sifteam.switch_16_9),
getConfigListEntry(_("Video green switch enable 16:9 always:"), config.sifteam.switch_16_9_always),
getConfigListEntry(_("Video green switch enable 16:9 letterbox:"), config.sifteam.switch_16_9_letterbox),
getConfigListEntry(_("Video green switch enable 16:10 letterbox:"), config.sifteam.switch_16_10_letterbox),
getConfigListEntry(_("Video green switch enable 16:10 panscan:"), config.sifteam.switch_16_10_panscan)
]
ConfigListScreen.__init__(self, self.list, session = session)
self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
{
"red": self.ok,
#"green": self.green,
"blue": self.keyCancel,
"cancel": self.keyCancel,
}, -2)
self["key_green"] = Button("")
self["key_red"] = Button(_("Ok"))
self["key_blue"] = Button(_("Exit"))
self["key_yellow"] = Button("")
def ok(self):
self.keySave()
|
gpl-2.0
|
[
504,
29372,
14,
9616,
492,
17804,
199,
504,
30317,
14,
5061,
492,
11349,
4311,
199,
504,
17823,
14,
3989,
2354,
492,
6187,
2354,
199,
504,
17823,
14,
2028,
1296,
492,
4094,
1296,
9616,
199,
504,
17823,
14,
888,
492,
664,
2028,
16934,
12,
1101,
12,
4094,
4082,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
199,
504,
17823,
14,
4259,
492,
16005,
199,
199,
533,
5543,
4023,
8,
9616,
12,
4094,
1296,
9616,
304,
199,
198,
318,
636,
826,
721,
277,
12,
2351,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
277,
14,
513,
275,
359,
686,
198,
27988,
16934,
6115,
3162,
17423,
707,
737,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5633,
3786,
817,
395,
686,
198,
27988,
16934,
6115,
14194,
262,
15030,
818,
26,
1288,
1101,
14,
338,
70,
5969,
14,
16409,
11071,
632,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
841,
26,
19,
8082,
1977,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
20,
63,
19,
63,
9269,
1977,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
841,
26,
19,
21379,
6282,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
20,
63,
19,
63,
10384,
6282,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
25,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
25,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
25,
3544,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
25,
63,
9223,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
25,
8082,
1977,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
25,
63,
9269,
1977,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
709,
8082,
1977,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
709,
63,
9269,
1977,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
709,
21379,
6282,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
709,
63,
10384,
6282,
9,
507,
198,
61,
6319,
507,
198,
2028,
1296,
9616,
855,
826,
721,
277,
12,
291,
14,
513,
12,
2351,
275,
2351,
9,
9068,
198,
277,
905,
3723,
937,
275,
10033,
2956,
5234,
11622,
9083,
9303,
401,
298,
4117,
9303,
2255,
1585,
198,
91,
1871,
198,
2,
581,
582,
291,
14,
745,
12,
1871,
198,
23662,
7731,
582,
291,
14,
7731,
12,
1871,
198,
2,
6304,
582,
291,
14,
498,
9083,
12,
1871,
198,
2,
6406,
582,
291,
14,
498,
9083,
12,
1585,
198,
1386,
446,
18,
9,
1871,
507,
198,
277,
905,
498,
63,
7731,
937,
275,
16005,
10804,
507,
198,
277,
905,
498,
63,
581,
937,
275,
16005,
6115,
11622,
2237,
507,
198,
277,
905,
498,
63,
6304,
937,
275,
16005,
6115,
6699,
2237,
507,
198,
277,
905,
498,
63,
14514,
937,
275,
16005,
10804,
18118,
198,
318,
4112,
8,
277,
304,
507,
198,
277,
14,
498,
8229,
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
] |
[
29372,
14,
9616,
492,
17804,
199,
504,
30317,
14,
5061,
492,
11349,
4311,
199,
504,
17823,
14,
3989,
2354,
492,
6187,
2354,
199,
504,
17823,
14,
2028,
1296,
492,
4094,
1296,
9616,
199,
504,
17823,
14,
888,
492,
664,
2028,
16934,
12,
1101,
12,
4094,
4082,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
199,
504,
17823,
14,
4259,
492,
16005,
199,
199,
533,
5543,
4023,
8,
9616,
12,
4094,
1296,
9616,
304,
199,
198,
318,
636,
826,
721,
277,
12,
2351,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
277,
14,
513,
275,
359,
686,
198,
27988,
16934,
6115,
3162,
17423,
707,
737,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5633,
3786,
817,
395,
686,
198,
27988,
16934,
6115,
14194,
262,
15030,
818,
26,
1288,
1101,
14,
338,
70,
5969,
14,
16409,
11071,
632,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
841,
26,
19,
8082,
1977,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
20,
63,
19,
63,
9269,
1977,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
841,
26,
19,
21379,
6282,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
20,
63,
19,
63,
10384,
6282,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
25,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
25,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
25,
3544,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
25,
63,
9223,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
25,
8082,
1977,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
25,
63,
9269,
1977,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
709,
8082,
1977,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
709,
63,
9269,
1977,
395,
686,
198,
27988,
16934,
6115,
9166,
12431,
6258,
4756,
3193,
26,
709,
21379,
6282,
26,
1288,
1101,
14,
338,
70,
5969,
14,
5656,
63,
975,
63,
709,
63,
10384,
6282,
9,
507,
198,
61,
6319,
507,
198,
2028,
1296,
9616,
855,
826,
721,
277,
12,
291,
14,
513,
12,
2351,
275,
2351,
9,
9068,
198,
277,
905,
3723,
937,
275,
10033,
2956,
5234,
11622,
9083,
9303,
401,
298,
4117,
9303,
2255,
1585,
198,
91,
1871,
198,
2,
581,
582,
291,
14,
745,
12,
1871,
198,
23662,
7731,
582,
291,
14,
7731,
12,
1871,
198,
2,
6304,
582,
291,
14,
498,
9083,
12,
1871,
198,
2,
6406,
582,
291,
14,
498,
9083,
12,
1585,
198,
1386,
446,
18,
9,
1871,
507,
198,
277,
905,
498,
63,
7731,
937,
275,
16005,
10804,
507,
198,
277,
905,
498,
63,
581,
937,
275,
16005,
6115,
11622,
2237,
507,
198,
277,
905,
498,
63,
6304,
937,
275,
16005,
6115,
6699,
2237,
507,
198,
277,
905,
498,
63,
14514,
937,
275,
16005,
10804,
18118,
198,
318,
4112,
8,
277,
304,
507,
198,
277,
14,
498,
8229,
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,
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,
0
] |
pietern/kubernetes
|
examples/cluster-dns/images/frontend/client.py
|
468
|
1227
|
#!/usr/bin/env python
# Copyright 2015 The Kubernetes 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.
import argparse
import requests
import socket
from urlparse import urlparse
def CheckServiceAddress(address):
hostname = urlparse(address).hostname
service_address = socket.gethostbyname(hostname)
print service_address
def GetServerResponse(address):
print 'Send request to:', address
response = requests.get(address)
print response
print response.content
def Main():
parser = argparse.ArgumentParser()
parser.add_argument('address')
args = parser.parse_args()
CheckServiceAddress(args.address)
GetServerResponse(args.address)
if __name__ == "__main__":
Main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
7534,
199,
646,
4145,
199,
646,
2838,
199,
199,
504,
7097,
492,
7097,
421,
199,
318,
2670,
3167,
1476,
8,
1562,
304,
523,
6246,
275,
7097,
8,
1562,
680,
4269,
523,
2435,
63,
1562,
275,
2838,
14,
20256,
24810,
8,
4269,
9,
523,
870,
2435,
63,
1562,
421,
199,
318,
2372,
3120,
2364,
8,
1562,
304,
523,
870,
283,
6795,
1056,
370,
6536,
2287,
523,
1177,
275,
4145,
14,
362,
8,
1562,
9,
523,
870,
1177,
523,
870,
1177,
14,
1317,
421,
199,
318,
11298,
837,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
360,
1562,
358,
523,
1249,
275,
1798,
14,
1122,
63,
589,
342,
523,
2670,
3167,
1476,
8,
589,
14,
1562,
9,
523,
2372,
3120,
2364,
8,
589,
14,
1562,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
11298,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
7534,
199,
646,
4145,
199,
646,
2838,
199,
199,
504,
7097,
492,
7097,
421,
199,
318,
2670,
3167,
1476,
8,
1562,
304,
523,
6246,
275,
7097,
8,
1562,
680,
4269,
523,
2435,
63,
1562,
275,
2838,
14,
20256,
24810,
8,
4269,
9,
523,
870,
2435,
63,
1562,
421,
199,
318,
2372,
3120,
2364,
8,
1562,
304,
523,
870,
283,
6795,
1056,
370,
6536,
2287,
523,
1177,
275,
4145,
14,
362,
8,
1562,
9,
523,
870,
1177,
523,
870,
1177,
14,
1317,
421,
199,
318,
11298,
837,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
360,
1562,
358,
523,
1249,
275,
1798,
14,
1122,
63,
589,
342,
523,
2670,
3167,
1476,
8,
589,
14,
1562,
9,
523,
2372,
3120,
2364,
8,
589,
14,
1562,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
11298,
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,
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,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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
] |
jchodera/cclib
|
src/cclib/parser/qchemparser.py
|
3
|
61059
|
# -*- coding: utf-8 -*-
#
# This file is part of cclib (http://cclib.github.io), a library for parsing
# and interpreting the results of computational chemistry packages.
#
# Copyright (C) 2014-2015, the cclib development team
#
# The library is free software, distributed under the terms of
# the GNU Lesser General Public version 2.1 or later. You should have
# received a copy of the license along with cclib. You can also access
# the full license online at http://www.gnu.org/copyleft/lgpl.html.
"""Parser for Q-Chem output files"""
from __future__ import print_function
import re
import numpy
import itertools
from . import logfileparser
from . import utils
class QChem(logfileparser.Logfile):
"""A Q-Chem 4 log file."""
def __init__(self, *args, **kwargs):
# Call the __init__ method of the superclass
super(QChem, self).__init__(logname="QChem", *args, **kwargs)
def __str__(self):
"""Return a string representation of the object."""
return "QChem log file %s" % (self.filename)
def __repr__(self):
"""Return a representation of the object."""
return 'QChem("%s")' % (self.filename)
def normalisesym(self, label):
"""Q-Chem does not require normalizing symmetry labels."""
def before_parsing(self):
# Keep track of whether or not we're performing an
# (un)restricted calculation.
self.unrestricted = False
self.is_rohf = False
# Compile the dashes-and-or-spaces-only regex.
self.re_dashes_and_spaces = re.compile('^[\s-]+$')
# Compile the regex for extracting the atomic index from an
# aoname.
self.re_atomindex = re.compile('(\d+)_')
# A maximum of 6 columns per block when printing matrices.
self.ncolsblock = 6
# By default, when asked to print orbitals via
# `scf_print`/`scf_final_print` and/or `print_orbitals`,
# Q-Chem will print all occupieds and the first 5 virtuals.
#
# When the number is set for `print_orbitals`, that section of
# the output will display (NOcc + that many virtual) MOs, but
# any other sections present due to
# `scf_print`/`scf_final_print` will still only display (NOcc
# + 5) MOs.
#
# Note that the density matrix is always (NBasis * NBasis)!
self.norbdisp_alpha = self.norbdisp_beta = 5
self.norbdisp_alpha_aonames = self.norbdisp_beta_aonames = 5
self.norbdisp_set = False
self.alpha_mo_coefficient_headers = (
'RESTRICTED (RHF) MOLECULAR ORBITAL COEFFICIENTS',
'ALPHA MOLECULAR ORBITAL COEFFICIENTS'
)
def after_parsing(self):
# If parsing a fragment job, each of the geometries appended to
# `atomcoords` may be of different lengths, which will prevent
# conversion from a list to NumPy array.
# Take the length of the first geometry as correct, and remove
# all others with different lengths.
if len(self.atomcoords) > 1:
correctlen = len(self.atomcoords[0])
self.atomcoords[:] = [coords for coords in self.atomcoords
if len(coords) == correctlen]
# At the moment, there is no similar correction for other properties!
# QChem does not print all MO coefficients by default, but rather
# up to HOMO+5. So, fill up the missing values with NaNs. If there are
# other cases where coefficient are missing, but different ones, this
# general afterthought might not be appropriate and the fix will
# need to be done while parsing.
if hasattr(self, 'mocoeffs'):
for im in range(len(self.mocoeffs)):
_nmo, _nbasis = self.mocoeffs[im].shape
if (_nmo, _nbasis) != (self.nmo, self.nbasis):
coeffs = numpy.empty((self.nmo, self.nbasis))
coeffs[:] = numpy.nan
coeffs[0:_nmo, 0:_nbasis] = self.mocoeffs[im]
self.mocoeffs[im] = coeffs
# When parsing the 'MOLECULAR ORBITAL COEFFICIENTS' block for
# `aonames`, Q-Chem doesn't print the principal quantum number
# for each shell; this needs to be added.
if hasattr(self, 'aonames') and hasattr(self, 'atombasis'):
angmom = ('', 'S', 'P', 'D', 'F', 'G', 'H', 'I')
for atom in self.atombasis:
bfcounts = dict()
for bfindex in atom:
atomname, bfname = self.aonames[bfindex].split('_')
# Keep track of how many times each shell type has
# appeared.
if bfname in bfcounts:
bfcounts[bfname] += 1
else:
# Make sure the starting number for type of
# angular momentum begins at the appropriate
# principal quantum number (1S, 2P, 3D, 4F,
# ...).
bfcounts[bfname] = angmom.index(bfname[0])
newbfname = '{}{}'.format(bfcounts[bfname], bfname)
self.aonames[bfindex] = '_'.join([atomname, newbfname])
def extract(self, inputfile, line):
"""Extract information from the file object inputfile."""
# If the input section is repeated back, parse the $rem and
# $molecule sections.
if line[0:11] == 'User input:':
self.skip_line(inputfile, 'd')
while list(set(line.strip())) != ['-']:
if '$rem' in line:
while '$end' not in line:
line = next(inputfile)
if 'print_orbitals' in line.lower():
# Stay with the default value if a number isn't
# specified.
if line.split()[-1].lower() in ('true', 'false'):
continue
else:
norbdisp_aonames = int(line.split()[-1])
self.norbdisp_alpha_aonames = norbdisp_aonames
self.norbdisp_beta_aonames = norbdisp_aonames
self.norbdisp_set = True
# Charge and multiplicity are present in the input file, which is generally
# printed once at the beginning. However, it is also prined for fragment
# calculations, so make sure we parse only the first occurance.
if '$molecule' in line:
line = next(inputfile)
charge, mult = map(int, line.split())
if not hasattr(self, 'charge'):
self.set_attribute('charge', charge)
if not hasattr(self, 'mult'):
self.set_attribute('mult', mult)
line = next(inputfile)
# Parse the general basis for `gbasis`, in the style used by
# Gaussian.
if 'Basis set in general basis input format:' in line:
self.skip_lines(inputfile, ['d', '$basis'])
line = next(inputfile)
if not hasattr(self, 'gbasis'):
self.gbasis = []
# The end of the general basis block.
while '$end' not in line:
atom = []
# 1. Contains element symbol and atomic index of
# basis functions; if 0, applies to all atoms of
# same element.
assert len(line.split()) == 2
line = next(inputfile)
# The end of each atomic block.
while '****' not in line:
# 2. Contains the type of basis function {S, SP,
# P, D, F, G, H, ...}, the number of primitives,
# and the weight of the final contracted function.
bfsplitline = line.split()
assert len(bfsplitline) == 3
bftype = bfsplitline[0]
nprim = int(bfsplitline[1])
line = next(inputfile)
# 3. The primitive basis functions that compose
# the contracted basis function; there are `nprim`
# of them. The first value is the exponent, and
# the second value is the contraction
# coefficient. If `bftype == 'SP'`, the primitives
# are for both S- and P-type basis functions but
# with separate contraction coefficients,
# resulting in three columns.
if bftype == 'SP':
primitives_S = []
primitives_P = []
else:
primitives = []
# For each primitive in the contracted basis
# function...
for iprim in range(nprim):
primsplitline = line.split()
exponent = float(primsplitline[0])
if bftype == 'SP':
assert len(primsplitline) == 3
coefficient_S = float(primsplitline[1])
coefficient_P = float(primsplitline[2])
primitives_S.append((exponent, coefficient_S))
primitives_P.append((exponent, coefficient_P))
else:
assert len(primsplitline) == 2
coefficient = float(primsplitline[1])
primitives.append((exponent, coefficient))
line = next(inputfile)
if bftype == 'SP':
bf_S = ('S', primitives_S)
bf_P = ('P', primitives_P)
atom.append(bf_S)
atom.append(bf_P)
else:
bf = (bftype, primitives)
atom.append(bf)
# Move to the next contracted basis function
# as long as we don't hit the '****' atom
# delimiter.
self.gbasis.append(atom)
line = next(inputfile)
# Extract the atomic numbers and coordinates of the atoms.
if 'Standard Nuclear Orientation (Angstroms)' in line:
if not hasattr(self, 'atomcoords'):
self.atomcoords = []
self.skip_lines(inputfile, ['cols', 'dashes'])
atomelements = []
atomcoords = []
line = next(inputfile)
while list(set(line.strip())) != ['-']:
entry = line.split()
atomelements.append(entry[1])
atomcoords.append(list(map(float, entry[2:])))
line = next(inputfile)
self.atomcoords.append(atomcoords)
if not hasattr(self, 'atomnos'):
self.atomnos = []
self.atomelements = []
for atomelement in atomelements:
self.atomelements.append(atomelement)
if atomelement == 'GH':
self.atomnos.append(0)
else:
self.atomnos.append(utils.PeriodicTable().number[atomelement])
self.natom = len(self.atomnos)
self.atommap = self.generate_atom_map()
self.formula_histogram = self.generate_formula_histogram()
# Number of electrons.
# Useful for determining the number of occupied/virtual orbitals.
if 'Nuclear Repulsion Energy' in line:
if not hasattr(self, 'nalpha'):
line = next(inputfile)
nelec_re_string = 'There are(\s+[0-9]+) alpha and(\s+[0-9]+) beta electrons'
match = re.findall(nelec_re_string, line.strip())
self.nalpha = int(match[0][0].strip())
self.nbeta = int(match[0][1].strip())
self.norbdisp_alpha += self.nalpha
self.norbdisp_alpha_aonames += self.nalpha
self.norbdisp_beta += self.nbeta
self.norbdisp_beta_aonames += self.nbeta
# Number of basis functions.
# Because Q-Chem's integral recursion scheme is defined using
# Cartesian basis functions, there is often a distinction between the
# two in the output. We only parse for *pure* functions.
# Examples:
# Only one type:
# There are 30 shells and 60 basis functions
# Both Cartesian and pure:
# ...
if 'basis functions' in line:
if not hasattr(self, 'nbasis'):
self.set_attribute('nbasis', int(line.split()[-3]))
# Check for whether or not we're peforming an
# (un)restricted calculation.
if 'calculation will be' in line:
if ' restricted' in line:
self.unrestricted = False
if 'unrestricted' in line:
self.unrestricted = True
if hasattr(self, 'nalpha') and hasattr(self, 'nbeta'):
if self.nalpha != self.nbeta:
self.unrestricted = True
self.is_rohf = True
# Section with SCF iterations goes like this:
#
# SCF converges when DIIS error is below 1.0E-05
# ---------------------------------------
# Cycle Energy DIIS Error
# ---------------------------------------
# 1 -381.9238072190 1.39E-01
# 2 -382.2937212775 3.10E-03
# 3 -382.2939780242 3.37E-03
# ...
#
scf_success_messages = (
'Convergence criterion met',
'corrected energy'
)
scf_failure_messages = (
'SCF failed to converge',
'Convergence failure'
)
if 'SCF converges when ' in line:
if not hasattr(self, 'scftargets'):
self.scftargets = []
target = float(line.split()[-1])
self.scftargets.append([target])
# We should have the header between dashes now,
# but sometimes there are lines before the first dashes.
while not 'Cycle Energy' in line:
line = next(inputfile)
self.skip_line(inputfile, 'd')
values = []
iter_counter = 1
line = next(inputfile)
while not any(message in line for message in scf_success_messages):
# Some trickery to avoid a lot of printing that can occur
# between each SCF iteration.
entry = line.split()
if len(entry) > 0:
if entry[0] == str(iter_counter):
# Q-Chem only outputs one error metric.
error = float(entry[2])
values.append([error])
iter_counter += 1
line = next(inputfile)
# We've converged, but still need the last iteration.
if any(message in line for message in scf_success_messages):
entry = line.split()
error = float(entry[2])
values.append([error])
iter_counter += 1
# This is printed in regression QChem4.2/dvb_sp_unconverged.out
# so use it to bail out when convergence fails.
if any(message in line for message in scf_failure_messages):
break
if not hasattr(self, 'scfvalues'):
self.scfvalues = []
self.scfvalues.append(numpy.array(values))
# Molecular orbital coefficients.
# Try parsing them from this block (which comes from
# `scf_final_print = 2``) rather than the combined
# aonames/mocoeffs/moenergies block (which comes from
# `print_orbitals = true`).
if 'Final Alpha MO Coefficients' in line:
if not hasattr(self, 'mocoeffs'):
self.mocoeffs = []
mocoeffs = numpy.empty(shape=(self.nbasis, self.norbdisp_alpha))
self.parse_matrix(inputfile, mocoeffs)
self.mocoeffs.append(mocoeffs.transpose())
if 'Final Beta MO Coefficients' in line:
mocoeffs = numpy.empty(shape=(self.nbasis, self.norbdisp_beta))
self.parse_matrix(inputfile, mocoeffs)
self.mocoeffs.append(mocoeffs.transpose())
if 'Total energy in the final basis set' in line:
if not hasattr(self, 'scfenergies'):
self.scfenergies = []
scfenergy = float(line.split()[-1])
self.scfenergies.append(utils.convertor(scfenergy, 'hartree', 'eV'))
# Geometry optimization.
if 'Maximum Tolerance Cnvgd?' in line:
line_g = list(map(float, next(inputfile).split()[1:3]))
line_d = list(map(float, next(inputfile).split()[1:3]))
line_e = next(inputfile).split()[2:4]
if not hasattr(self, 'geotargets'):
self.geotargets = [line_g[1], line_d[1], self.float(line_e[1])]
if not hasattr(self, 'geovalues'):
self.geovalues = []
try:
ediff = abs(self.float(line_e[0]))
except ValueError:
ediff = numpy.nan
geovalues = [line_g[0], line_d[0], ediff]
self.geovalues.append(geovalues)
if '** OPTIMIZATION CONVERGED **' in line:
if not hasattr(self, 'optdone'):
self.optdone = []
self.optdone.append(len(self.atomcoords))
if '** MAXIMUM OPTIMIZATION CYCLES REACHED **' in line:
if not hasattr(self, 'optdone'):
self.optdone = []
# Moller-Plesset corrections.
# There are multiple modules in Q-Chem for calculating MPn energies:
# cdman, ccman, and ccman2, all with different output.
#
# MP2, RI-MP2, and local MP2 all default to cdman, which has a simple
# block of output after the regular SCF iterations.
#
# MP3 is handled by ccman2.
#
# MP4 and variants are handled by ccman.
# This is the MP2/cdman case.
if 'MP2 total energy' in line:
if not hasattr(self, 'mpenergies'):
self.mpenergies = []
mp2energy = float(line.split()[4])
mp2energy = utils.convertor(mp2energy, 'hartree', 'eV')
self.mpenergies.append([mp2energy])
# This is the MP3/ccman2 case.
if line[1:11] == 'MP2 energy' and line[12:19] != 'read as':
if not hasattr(self, 'mpenergies'):
self.mpenergies = []
mpenergies = []
mp2energy = float(line.split()[3])
mpenergies.append(mp2energy)
line = next(inputfile)
line = next(inputfile)
# Just a safe check.
if 'MP3 energy' in line:
mp3energy = float(line.split()[3])
mpenergies.append(mp3energy)
mpenergies = [utils.convertor(mpe, 'hartree', 'eV')
for mpe in mpenergies]
self.mpenergies.append(mpenergies)
# This is the MP4/ccman case.
if 'EHF' in line:
if not hasattr(self, 'mpenergies'):
self.mpenergies = []
mpenergies = []
while list(set(line.strip())) != ['-']:
if 'EMP2' in line:
mp2energy = float(line.split()[2])
mpenergies.append(mp2energy)
if 'EMP3' in line:
mp3energy = float(line.split()[2])
mpenergies.append(mp3energy)
if 'EMP4SDQ' in line:
mp4sdqenergy = float(line.split()[2])
mpenergies.append(mp4sdqenergy)
# This is really MP4SD(T)Q.
if 'EMP4 ' in line:
mp4sdtqenergy = float(line.split()[2])
mpenergies.append(mp4sdtqenergy)
line = next(inputfile)
mpenergies = [utils.convertor(mpe, 'hartree', 'eV')
for mpe in mpenergies]
self.mpenergies.append(mpenergies)
# Coupled cluster corrections.
# Hopefully we only have to deal with ccman2 here.
if 'CCD total energy' in line:
if not hasattr(self, 'ccenergies'):
self.ccenergies = []
ccdenergy = float(line.split()[-1])
ccdenergy = utils.convertor(ccdenergy, 'hartree', 'eV')
self.ccenergies.append(ccdenergy)
if 'CCSD total energy' in line:
has_triples = False
if not hasattr(self, 'ccenergies'):
self.ccenergies = []
ccsdenergy = float(line.split()[-1])
# Make sure we aren't actually doing CCSD(T).
line = next(inputfile)
line = next(inputfile)
if 'CCSD(T) total energy' in line:
has_triples = True
ccsdtenergy = float(line.split()[-1])
ccsdtenergy = utils.convertor(ccsdtenergy, 'hartree', 'eV')
self.ccenergies.append(ccsdtenergy)
if not has_triples:
ccsdenergy = utils.convertor(ccsdenergy, 'hartree', 'eV')
self.ccenergies.append(ccsdenergy)
# Electronic transitions. Works for both CIS and TDDFT.
if 'Excitation Energies' in line:
# Restricted:
# ---------------------------------------------------
# TDDFT/TDA Excitation Energies
# ---------------------------------------------------
#
# Excited state 1: excitation energy (eV) = 3.6052
# Total energy for state 1: -382.167872200685
# Multiplicity: Triplet
# Trans. Mom.: 0.0000 X 0.0000 Y 0.0000 Z
# Strength : 0.0000
# D( 33) --> V( 3) amplitude = 0.2618
# D( 34) --> V( 2) amplitude = 0.2125
# D( 35) --> V( 1) amplitude = 0.9266
#
# Unrestricted:
# Excited state 2: excitation energy (eV) = 2.3156
# Total energy for state 2: -381.980177630969
# <S**2> : 0.7674
# Trans. Mom.: -2.7680 X -0.1089 Y 0.0000 Z
# Strength : 0.4353
# S( 1) --> V( 1) amplitude = -0.3105 alpha
# D( 34) --> S( 1) amplitude = 0.9322 beta
self.skip_lines(inputfile, ['dashes', 'blank'])
line = next(inputfile)
etenergies = []
etsyms = []
etoscs = []
etsecs = []
spinmap = {'alpha': 0, 'beta': 1}
while list(set(line.strip())) != ['-']:
# Take the total energy for the state and subtract from the
# ground state energy, rather than just the EE;
# this will be more accurate.
if 'Total energy for state' in line:
energy = utils.convertor(float(line.split()[-1]), 'hartree', 'cm-1')
etenergy = energy - utils.convertor(self.scfenergies[-1], 'eV', 'cm-1')
etenergies.append(etenergy)
# if 'excitation energy' in line:
# etenergy = utils.convertor(float(line.split()[-1]), 'eV', 'cm-1')
# etenergies.append(etenergy)
if 'Multiplicity' in line:
etsym = line.split()[1]
etsyms.append(etsym)
if 'Strength' in line:
strength = float(line.split()[-1])
etoscs.append(strength)
# This is the list of transitions.
if 'amplitude' in line:
sec = []
while line.strip() != '':
if self.unrestricted:
spin = spinmap[line[42:47].strip()]
else:
spin = 0
# There is a subtle difference between TDA and RPA calcs,
# because in the latter case each transition line is
# preceeded by the type of vector: X or Y, name excitation
# or deexcitation (see #154 for details). For deexcitations,
# we will need to reverse the MO indices. Note also that Q-Chem
# starts reindexing virtual orbitals at 1.
if line[5] == '(':
ttype = 'X'
startidx = int(line[6:9]) - 1
endidx = int(line[17:20]) - 1 + self.nalpha
contrib = float(line[34:41].strip())
else:
assert line[5] == ":"
ttype = line[4]
startidx = int(line[9:12]) - 1
endidx = int(line[20:23]) - 1 + self.nalpha
contrib = float(line[37:44].strip())
start = (startidx, spin)
end = (endidx, spin)
if ttype == 'X':
sec.append([start, end, contrib])
elif ttype == 'Y':
sec.append([end, start, contrib])
else:
raise ValueError('Unknown transition type: %s' % ttype)
line = next(inputfile)
etsecs.append(sec)
line = next(inputfile)
self.set_attribute('etenergies', etenergies)
self.set_attribute('etsyms', etsyms)
self.set_attribute('etoscs', etoscs)
self.set_attribute('etsecs', etsecs)
# Molecular orbital energies and symmetries.
if 'Orbital Energies (a.u.) and Symmetries' in line:
# --------------------------------------------------------------
# Orbital Energies (a.u.) and Symmetries
# --------------------------------------------------------------
#
# Alpha MOs, Restricted
# -- Occupied --
# -10.018 -10.018 -10.008 -10.008 -10.007 -10.007 -10.006 -10.005
# 1 Bu 1 Ag 2 Bu 2 Ag 3 Bu 3 Ag 4 Bu 4 Ag
# -9.992 -9.992 -0.818 -0.755 -0.721 -0.704 -0.670 -0.585
# 5 Ag 5 Bu 6 Ag 6 Bu 7 Ag 7 Bu 8 Bu 8 Ag
# -0.561 -0.532 -0.512 -0.462 -0.439 -0.410 -0.400 -0.397
# 9 Ag 9 Bu 10 Ag 11 Ag 10 Bu 11 Bu 12 Bu 12 Ag
# -0.376 -0.358 -0.349 -0.330 -0.305 -0.295 -0.281 -0.263
# 13 Bu 14 Bu 13 Ag 1 Au 15 Bu 14 Ag 15 Ag 1 Bg
# -0.216 -0.198 -0.160
# 2 Au 2 Bg 3 Bg
# -- Virtual --
# 0.050 0.091 0.116 0.181 0.280 0.319 0.330 0.365
# 3 Au 4 Au 4 Bg 5 Au 5 Bg 16 Ag 16 Bu 17 Bu
# 0.370 0.413 0.416 0.422 0.446 0.469 0.496 0.539
# 17 Ag 18 Bu 18 Ag 19 Bu 19 Ag 20 Bu 20 Ag 21 Ag
# 0.571 0.587 0.610 0.627 0.646 0.693 0.743 0.806
# 21 Bu 22 Ag 22 Bu 23 Bu 23 Ag 24 Ag 24 Bu 25 Ag
# 0.816
# 25 Bu
#
# Beta MOs, Restricted
# -- Occupied --
# -10.018 -10.018 -10.008 -10.008 -10.007 -10.007 -10.006 -10.005
# 1 Bu 1 Ag 2 Bu 2 Ag 3 Bu 3 Ag 4 Bu 4 Ag
# -9.992 -9.992 -0.818 -0.755 -0.721 -0.704 -0.670 -0.585
# 5 Ag 5 Bu 6 Ag 6 Bu 7 Ag 7 Bu 8 Bu 8 Ag
# -0.561 -0.532 -0.512 -0.462 -0.439 -0.410 -0.400 -0.397
# 9 Ag 9 Bu 10 Ag 11 Ag 10 Bu 11 Bu 12 Bu 12 Ag
# -0.376 -0.358 -0.349 -0.330 -0.305 -0.295 -0.281 -0.263
# 13 Bu 14 Bu 13 Ag 1 Au 15 Bu 14 Ag 15 Ag 1 Bg
# -0.216 -0.198 -0.160
# 2 Au 2 Bg 3 Bg
# -- Virtual --
# 0.050 0.091 0.116 0.181 0.280 0.319 0.330 0.365
# 3 Au 4 Au 4 Bg 5 Au 5 Bg 16 Ag 16 Bu 17 Bu
# 0.370 0.413 0.416 0.422 0.446 0.469 0.496 0.539
# 17 Ag 18 Bu 18 Ag 19 Bu 19 Ag 20 Bu 20 Ag 21 Ag
# 0.571 0.587 0.610 0.627 0.646 0.693 0.743 0.806
# 21 Bu 22 Ag 22 Bu 23 Bu 23 Ag 24 Ag 24 Bu 25 Ag
# 0.816
# 25 Bu
# --------------------------------------------------------------
self.skip_line(inputfile, 'dashes')
line = next(inputfile)
# Sometimes Q-Chem gets a little confused...
while 'Warning : Irrep of orbital' in line:
line = next(inputfile)
line = next(inputfile)
energies_alpha = []
symbols_alpha = []
if self.unrestricted:
energies_beta = []
symbols_beta = []
line = next(inputfile)
# The end of the block is either a blank line or only dashes.
while not self.re_dashes_and_spaces.search(line):
if 'Occupied' in line or 'Virtual' in line:
# A nice trick to find where the HOMO is.
if 'Virtual' in line:
self.homos = [len(energies_alpha)-1]
line = next(inputfile)
# Parse the energies and symmetries in pairs of lines.
# energies = [utils.convertor(energy, 'hartree', 'eV')
# for energy in map(float, line.split())]
# This convoluted bit handles '*******' when present.
energies = []
energy_line = line.split()
for e in energy_line:
try:
energy = utils.convertor(self.float(e), 'hartree', 'eV')
except ValueError:
energy = numpy.nan
energies.append(energy)
energies_alpha.extend(energies)
line = next(inputfile)
symbols = line.split()[1::2]
symbols_alpha.extend(symbols)
line = next(inputfile)
line = next(inputfile)
# Only look at the second block if doing an unrestricted calculation.
# This might be a problem for ROHF/ROKS.
if self.unrestricted:
assert 'Beta MOs' in line
self.skip_line(inputfile, '-- Occupied --')
line = next(inputfile)
while not self.re_dashes_and_spaces.search(line):
if 'Occupied' in line or 'Virtual' in line:
# This will definitely exist, thanks to the above block.
if 'Virtual' in line:
if len(self.homos) == 1:
self.homos.append(len(energies_beta)-1)
line = next(inputfile)
energies = []
energy_line = line.split()
for e in energy_line:
try:
energy = utils.convertor(self.float(e), 'hartree', 'eV')
except ValueError:
energy = numpy.nan
energies.append(energy)
energies_beta.extend(energies)
line = next(inputfile)
symbols = line.split()[1::2]
symbols_beta.extend(symbols)
line = next(inputfile)
# For now, only keep the last set of MO energies, even though it is
# printed at every step of geometry optimizations and fragment jobs.
self.moenergies = [[]]
self.mosyms = [[]]
self.moenergies[0] = numpy.array(energies_alpha)
self.mosyms[0] = symbols_alpha
if self.unrestricted:
self.moenergies.append([])
self.mosyms.append([])
self.moenergies[1] = numpy.array(energies_beta)
self.mosyms[1] = symbols_beta
self.set_attribute('nmo', len(self.moenergies[0]))
# Molecular orbital energies, no symmetries.
if line.strip() == 'Orbital Energies (a.u.)':
# In the case of no orbital symmetries, the beta spin block is not
# present for restricted calculations.
# --------------------------------------------------------------
# Orbital Energies (a.u.)
# --------------------------------------------------------------
#
# Alpha MOs
# -- Occupied --
# ******* -38.595 -34.580 -34.579 -34.578 -19.372 -19.372 -19.364
# -19.363 -19.362 -19.362 -4.738 -3.252 -3.250 -3.250 -1.379
# -1.371 -1.369 -1.365 -1.364 -1.362 -0.859 -0.855 -0.849
# -0.846 -0.840 -0.836 -0.810 -0.759 -0.732 -0.729 -0.704
# -0.701 -0.621 -0.610 -0.595 -0.587 -0.584 -0.578 -0.411
# -0.403 -0.355 -0.354 -0.352
# -- Virtual --
# -0.201 -0.117 -0.099 -0.086 0.020 0.031 0.055 0.067
# 0.075 0.082 0.086 0.092 0.096 0.105 0.114 0.148
#
# Beta MOs
# -- Occupied --
# ******* -38.561 -34.550 -34.549 -34.549 -19.375 -19.375 -19.367
# -19.367 -19.365 -19.365 -4.605 -3.105 -3.103 -3.102 -1.385
# -1.376 -1.376 -1.371 -1.370 -1.368 -0.863 -0.858 -0.853
# -0.849 -0.843 -0.839 -0.818 -0.765 -0.738 -0.737 -0.706
# -0.702 -0.624 -0.613 -0.600 -0.591 -0.588 -0.585 -0.291
# -0.291 -0.288 -0.275
# -- Virtual --
# -0.139 -0.122 -0.103 0.003 0.014 0.049 0.049 0.059
# 0.061 0.070 0.076 0.081 0.086 0.090 0.098 0.106
# 0.138
# --------------------------------------------------------------
self.skip_lines(inputfile, ['dashes', 'blank'])
line = next(inputfile)
energies_alpha = []
if self.unrestricted:
energies_beta = []
line = next(inputfile)
# The end of the block is either a blank line or only dashes.
while not self.re_dashes_and_spaces.search(line):
if 'Occupied' in line or 'Virtual' in line:
# A nice trick to find where the HOMO is.
if 'Virtual' in line:
self.homos = [len(energies_alpha)-1]
line = next(inputfile)
energies = []
energy_line = line.split()
for e in energy_line:
try:
energy = utils.convertor(self.float(e), 'hartree', 'eV')
except ValueError:
energy = numpy.nan
energies.append(energy)
energies_alpha.extend(energies)
line = next(inputfile)
line = next(inputfile)
# Only look at the second block if doing an unrestricted calculation.
# This might be a problem for ROHF/ROKS.
if self.unrestricted:
assert 'Beta MOs' in line
self.skip_line(inputfile, '-- Occupied --')
line = next(inputfile)
while not self.re_dashes_and_spaces.search(line):
if 'Occupied' in line or 'Virtual' in line:
# This will definitely exist, thanks to the above block.
if 'Virtual' in line:
if len(self.homos) == 1:
self.homos.append(len(energies_beta)-1)
line = next(inputfile)
energies = []
energy_line = line.split()
for e in energy_line:
try:
energy = utils.convertor(self.float(e), 'hartree', 'eV')
except ValueError:
energy = numpy.nan
energies.append(energy)
energies_beta.extend(energies)
line = next(inputfile)
# For now, only keep the last set of MO energies, even though it is
# printed at every step of geometry optimizations and fragment jobs.
self.moenergies = [[]]
self.moenergies[0] = numpy.array(energies_alpha)
if self.unrestricted:
self.moenergies.append([])
self.moenergies[1] = numpy.array(energies_beta)
self.set_attribute('nmo', len(self.moenergies[0]))
# If we've asked to display more virtual orbitals than there
# are MOs present in the molecule, fix that now.
if hasattr(self, 'nmo') and hasattr(self, 'nalpha') and hasattr(self, 'nbeta'):
if self.norbdisp_alpha_aonames > self.nmo:
self.norbdisp_alpha_aonames = self.nmo
if self.norbdisp_beta_aonames > self.nmo:
self.norbdisp_beta_aonames = self.nmo
# Molecular orbital coefficients.
# This block comes from `print_orbitals = true/{int}`. Less
# precision than `scf_final_print >= 2` for `mocoeffs`, but
# important for `aonames` and `atombasis`.
if any(header in line
for header in self.alpha_mo_coefficient_headers):
if not hasattr(self, 'mocoeffs'):
self.mocoeffs = []
if not hasattr(self, 'atombasis'):
self.atombasis = []
for n in range(self.natom):
self.atombasis.append([])
if not hasattr(self, 'aonames'):
self.aonames = []
# We could also attempt to parse `moenergies` here, but
# nothing is gained by it.
mocoeffs = numpy.empty(shape=(self.nbasis, self.norbdisp_alpha_aonames))
self.parse_matrix_aonames(inputfile, mocoeffs)
# Only use these MO coefficients if we don't have them
# from `scf_final_print`.
if len(self.mocoeffs) == 0:
self.mocoeffs.append(mocoeffs.transpose())
# Go back through `aonames` to create `atombasis`.
assert len(self.aonames) == self.nbasis
for aoindex, aoname in enumerate(self.aonames):
atomindex = int(self.re_atomindex.search(aoname).groups()[0]) - 1
self.atombasis[atomindex].append(aoindex)
assert len(self.atombasis) == len(self.atomnos)
if 'BETA MOLECULAR ORBITAL COEFFICIENTS' in line:
mocoeffs = numpy.empty(shape=(self.nbasis, self.norbdisp_beta_aonames))
self.parse_matrix_aonames(inputfile, mocoeffs)
if len(self.mocoeffs) == 1:
self.mocoeffs.append(mocoeffs.transpose())
# Population analysis.
if 'Ground-State Mulliken Net Atomic Charges' in line:
self.parse_charge_section(inputfile, 'mulliken')
if 'Hirshfeld Atomic Charges' in line:
self.parse_charge_section(inputfile, 'hirshfeld')
if 'Ground-State ChElPG Net Atomic Charges' in line:
self.parse_charge_section(inputfile, 'chelpg')
# Multipole moments are not printed in lexicographical order,
# so we need to parse and sort them. The units seem OK, but there
# is some uncertainty about the reference point and whether it
# can be changed.
#
# Notice how the letter/coordinate labels change to coordinate ranks
# after hexadecapole moments, and need to be translated. Additionally,
# after 9-th order moments the ranks are not necessarily single digits
# and so there are spaces between them.
#
# -----------------------------------------------------------------
# Cartesian Multipole Moments
# LMN = < X^L Y^M Z^N >
# -----------------------------------------------------------------
# Charge (ESU x 10^10)
# 0.0000
# Dipole Moment (Debye)
# X 0.0000 Y 0.0000 Z 0.0000
# Tot 0.0000
# Quadrupole Moments (Debye-Ang)
# XX -50.9647 XY -0.1100 YY -50.1441
# XZ 0.0000 YZ 0.0000 ZZ -58.5742
# ...
# 5th-Order Moments (Debye-Ang^4)
# 500 0.0159 410 -0.0010 320 0.0005
# 230 0.0000 140 0.0005 050 0.0012
# ...
# -----------------------------------------------------------------
#
if "Cartesian Multipole Moments" in line:
# This line appears not by default, but only when
# `multipole_order` > 4:
line = inputfile.next()
if 'LMN = < X^L Y^M Z^N >' in line:
line = inputfile.next()
# The reference point is always the origin, although normally the molecule
# is moved so that the center of charge is at the origin.
self.reference = [0.0, 0.0, 0.0]
self.moments = [self.reference]
# Watch out! This charge is in statcoulombs without the exponent!
# We should expect very good agreement, however Q-Chem prints
# the charge only with 5 digits, so expect 1e-4 accuracy.
charge_header = inputfile.next()
assert charge_header.split()[0] == "Charge"
charge = float(inputfile.next().strip())
charge = utils.convertor(charge, 'statcoulomb', 'e') * 1e-10
# Allow this to change until fragment jobs are properly implemented.
# assert abs(charge - self.charge) < 1e-4
# This will make sure Debyes are used (not sure if it can be changed).
line = inputfile.next()
assert line.strip() == "Dipole Moment (Debye)"
while "-----" not in line:
# The current multipole element will be gathered here.
multipole = []
line = inputfile.next()
while ("-----" not in line) and ("Moment" not in line):
cols = line.split()
# The total (norm) is printed for dipole but not other multipoles.
if cols[0] == 'Tot':
line = inputfile.next()
continue
# Find and replace any 'stars' with NaN before moving on.
for i in range(len(cols)):
if '***' in cols[i]:
cols[i] = numpy.nan
# The moments come in pairs (label followed by value) up to the 9-th order,
# although above hexadecapoles the labels are digits representing the rank
# in each coordinate. Above the 9-th order, ranks are not always single digits,
# so there are spaces between them, which means moments come in quartets.
if len(self.moments) < 5:
for i in range(len(cols)//2):
lbl = cols[2*i]
m = cols[2*i + 1]
multipole.append([lbl, m])
elif len(self.moments) < 10:
for i in range(len(cols)//2):
lbl = cols[2*i]
lbl = 'X'*int(lbl[0]) + 'Y'*int(lbl[1]) + 'Z'*int(lbl[2])
m = cols[2*i + 1]
multipole.append([lbl, m])
else:
for i in range(len(cols)//4):
lbl = 'X'*int(cols[4*i]) + 'Y'*int(cols[4*i + 1]) + 'Z'*int(cols[4*i + 2])
m = cols[4*i + 3]
multipole.append([lbl, m])
line = inputfile.next()
# Sort should use the first element when sorting lists,
# so this should simply work, and afterwards we just need
# to extract the second element in each list (the actual moment).
multipole.sort()
multipole = [m[1] for m in multipole]
self.moments.append(multipole)
# For `method = force` or geometry optimizations,
# the gradient is printed.
if 'Gradient of SCF Energy' in line:
if not hasattr(self, 'grads'):
self.grads = []
grad = numpy.empty(shape=(3, self.natom))
self.parse_matrix(inputfile, grad)
self.grads.append(grad.T)
# For IR-related jobs, the Hessian is printed (dim: 3*natom, 3*natom).
# Note that this is *not* the mass-weighted Hessian.
if 'Hessian of the SCF Energy' in line:
if not hasattr(self, 'hessian'):
dim = 3*self.natom
self.hessian = numpy.empty(shape=(dim, dim))
self.parse_matrix(inputfile, self.hessian)
# Start of the IR/Raman frequency section.
if 'VIBRATIONAL ANALYSIS' in line:
while 'STANDARD THERMODYNAMIC QUANTITIES' not in line:
## IR, optional Raman:
# **********************************************************************
# ** **
# ** VIBRATIONAL ANALYSIS **
# ** -------------------- **
# ** **
# ** VIBRATIONAL FREQUENCIES (CM**-1) AND NORMAL MODES **
# ** FORCE CONSTANTS (mDYN/ANGSTROM) AND REDUCED MASSES (AMU) **
# ** INFRARED INTENSITIES (KM/MOL) **
##** RAMAN SCATTERING ACTIVITIES (A**4/AMU) AND DEPOLARIZATION RATIOS **
# ** **
# **********************************************************************
# Mode: 1 2 3
# Frequency: -106.88 -102.91 161.77
# Force Cnst: 0.0185 0.0178 0.0380
# Red. Mass: 2.7502 2.8542 2.4660
# IR Active: NO YES YES
# IR Intens: 0.000 0.000 0.419
# Raman Active: YES NO NO
##Raman Intens: 2.048 0.000 0.000
##Depolar: 0.750 0.000 0.000
# X Y Z X Y Z X Y Z
# C 0.000 0.000 -0.100 -0.000 0.000 -0.070 -0.000 -0.000 -0.027
# C 0.000 0.000 0.045 -0.000 0.000 -0.074 0.000 -0.000 -0.109
# C 0.000 0.000 0.148 -0.000 -0.000 -0.074 0.000 0.000 -0.121
# C 0.000 0.000 0.100 -0.000 -0.000 -0.070 0.000 0.000 -0.027
# C 0.000 0.000 -0.045 0.000 -0.000 -0.074 -0.000 -0.000 -0.109
# C 0.000 0.000 -0.148 0.000 0.000 -0.074 -0.000 -0.000 -0.121
# H -0.000 0.000 0.086 -0.000 0.000 -0.082 0.000 -0.000 -0.102
# H 0.000 0.000 0.269 -0.000 -0.000 -0.091 0.000 0.000 -0.118
# H 0.000 0.000 -0.086 0.000 -0.000 -0.082 -0.000 0.000 -0.102
# H -0.000 0.000 -0.269 0.000 0.000 -0.091 -0.000 -0.000 -0.118
# C 0.000 -0.000 0.141 -0.000 -0.000 -0.062 -0.000 0.000 0.193
# C -0.000 -0.000 -0.160 0.000 0.000 0.254 -0.000 0.000 0.043
# H 0.000 -0.000 0.378 -0.000 0.000 -0.289 0.000 0.000 0.519
# H -0.000 -0.000 -0.140 0.000 0.000 0.261 -0.000 -0.000 0.241
# H -0.000 -0.000 -0.422 0.000 0.000 0.499 -0.000 0.000 -0.285
# C 0.000 -0.000 -0.141 0.000 0.000 -0.062 -0.000 -0.000 0.193
# C -0.000 -0.000 0.160 -0.000 -0.000 0.254 0.000 0.000 0.043
# H 0.000 -0.000 -0.378 0.000 -0.000 -0.289 -0.000 0.000 0.519
# H -0.000 -0.000 0.140 -0.000 -0.000 0.261 0.000 0.000 0.241
# H -0.000 -0.000 0.422 -0.000 -0.000 0.499 0.000 0.000 -0.285
# TransDip 0.000 -0.000 -0.000 0.000 -0.000 -0.000 -0.000 0.000 0.021
# Mode: 4 5 6
# ...
# There isn't any symmetry information for normal modes present
# in Q-Chem.
# if not hasattr(self, 'vibsyms'):
# self.vibsyms = []
if 'Frequency:' in line:
if not hasattr(self, 'vibfreqs'):
self.vibfreqs = []
vibfreqs = map(float, line.split()[1:])
self.vibfreqs.extend(vibfreqs)
if 'IR Intens:' in line:
if not hasattr(self, 'vibirs'):
self.vibirs = []
vibirs = map(float, line.split()[2:])
self.vibirs.extend(vibirs)
if 'Raman Intens:' in line:
if not hasattr(self, 'vibramans'):
self.vibramans = []
vibramans = map(float, line.split()[2:])
self.vibramans.extend(vibramans)
# This is the start of the displacement block.
if line.split()[0:3] == ['X', 'Y', 'Z']:
if not hasattr(self, 'vibdisps'):
self.vibdisps = []
disps = []
for k in range(self.natom):
line = next(inputfile)
numbers = list(map(float, line.split()[1:]))
N = len(numbers) // 3
if not disps:
for n in range(N):
disps.append([])
for n in range(N):
disps[n].append(numbers[3*n:(3*n)+3])
self.vibdisps.extend(disps)
line = next(inputfile)
# Anharmonic vibrational analysis.
# Q-Chem includes 3 theories: VPT2, TOSH, and VCI.
# For now, just take the VPT2 results.
# if 'VIBRATIONAL ANHARMONIC ANALYSIS' in line:
# while list(set(line.strip())) != ['=']:
# if 'VPT2' in line:
# if not hasattr(self, 'vibanharms'):
# self.vibanharms = []
# self.vibanharms.append(float(line.split()[-1]))
# line = next(inputfile)
if 'STANDARD THERMODYNAMIC QUANTITIES AT' in line:
if not hasattr(self, 'temperature'):
self.temperature = float(line.split()[4])
# Not supported yet.
if not hasattr(self, 'pressure'):
self.pressure = float(line.split()[7])
self.skip_lines(inputfile, ['blank', 'Imaginary'])
line = next(inputfile)
# Not supported yet.
if 'Zero point vibrational energy' in line:
if not hasattr(self, 'zpe'):
# Convert from kcal/mol to Hartree/particle.
self.zpe = utils.convertor(float(line.split()[4]),
'kcal', 'hartree')
atommasses = []
while 'Archival summary' not in line:
if 'Has Mass' in line:
atommass = float(line.split()[6])
atommasses.append(atommass)
if 'Total Enthalpy' in line:
if not hasattr(self, 'enthalpy'):
enthalpy = float(line.split()[2])
self.enthalpy = utils.convertor(enthalpy,
'kcal', 'hartree')
if 'Total Entropy' in line:
if not hasattr(self, 'entropy'):
entropy = float(line.split()[2]) * self.temperature / 1000
# This is the *temperature dependent* entropy.
self.entropy = utils.convertor(entropy,
'kcal', 'hartree')
if not hasattr(self, 'freeenergy'):
self.freeenergy = self.enthalpy - self.entropy
line = next(inputfile)
if not hasattr(self, 'atommasses'):
self.atommasses = numpy.array(atommasses)
# TODO:
# 'enthalpy' (incorrect)
# 'entropy' (incorrect)
# 'freeenergy' (incorrect)
# 'nocoeffs'
# 'nooccnos'
# 'vibanharms'
def parse_charge_section(self, inputfile, chargetype):
"""Parse the population analysis charge block."""
self.skip_line(inputfile, 'blank')
line = next(inputfile)
has_spins = False
if 'Spin' in line:
if not hasattr(self, 'atomspins'):
self.atomspins = dict()
has_spins = True
spins = []
self.skip_line(inputfile, 'dashes')
if not hasattr(self, 'atomcharges'):
self.atomcharges = dict()
charges = []
line = next(inputfile)
while list(set(line.strip())) != ['-']:
elements = line.split()
charge = self.float(elements[2])
charges.append(charge)
if has_spins:
spin = self.float(elements[3])
spins.append(spin)
line = next(inputfile)
self.atomcharges[chargetype] = numpy.array(charges)
if has_spins:
self.atomspins[chargetype] = numpy.array(spins)
def parse_matrix(self, inputfile, nparray):
"""Q-Chem prints most matrices in a standard format; parse the matrix
into a preallocated NumPy array of the appropriate shape.
"""
nrows, ncols = nparray.shape
line = next(inputfile)
assert len(line.split()) == min(self.ncolsblock, ncols)
colcounter = 0
while colcounter < ncols:
# If the line is just the column header (indices)...
if line[:5].strip() == '':
line = next(inputfile)
rowcounter = 0
while rowcounter < nrows:
row = list(map(float, line.split()[1:]))
assert len(row) == min(self.ncolsblock, (ncols - colcounter))
nparray[rowcounter][colcounter:colcounter + self.ncolsblock] = row
line = next(inputfile)
rowcounter += 1
colcounter += self.ncolsblock
def parse_matrix_aonames(self, inputfile, nparray):
"""Q-Chem prints most matrices in a standard format; parse the matrix
into a preallocated NumPy array of the appropriate shape.
Rather than have one routine for parsing all general matrices
and the 'MOLECULAR ORBITAL COEFFICIENTS' block, use a second
which handles `aonames`.
"""
bigmom = ('d', 'f', 'g', 'h')
nrows, ncols = nparray.shape
line = next(inputfile)
assert len(line.split()) == min(self.ncolsblock, ncols)
colcounter = 0
while colcounter < ncols:
# If the line is just the column header (indices)...
if line[:5].strip() == '':
line = next(inputfile)
# Do nothing for now.
if 'eigenvalues' in line:
line = next(inputfile)
rowcounter = 0
while rowcounter < nrows:
row = line.split()
# Only take the AO names on the first time through.
if colcounter == 0:
if len(self.aonames) != self.nbasis:
# Apply the offset for rows where there is
# more than one atom of any element in the
# molecule.
offset = int(self.formula_histogram[row[1]] != 1)
if offset:
name = self.atommap.get(row[1] + str(row[2]))
else:
name = self.atommap.get(row[1] + '1')
# For l > 1, there is a space between l and
# m_l when using spherical functions.
shell = row[2 + offset]
if shell in bigmom:
shell = ''.join([shell, row[3 + offset]])
aoname = ''.join([name, '_', shell.upper()])
self.aonames.append(aoname)
row = list(map(float, row[-min(self.ncolsblock, (ncols - colcounter)):]))
nparray[rowcounter][colcounter:colcounter + self.ncolsblock] = row
line = next(inputfile)
rowcounter += 1
colcounter += self.ncolsblock
def generate_atom_map(self):
"""Generate the map to go from Q-Chem atom numbering:
'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'H1', 'H2', 'H3', 'H4', 'C7', ...
to cclib atom numbering:
'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'H7', 'H8', 'H9', 'H10', 'C11', ...
for later use.
"""
# Generate the desired order.
order_proper = [element + str(num)
for element, num in zip(self.atomelements,
itertools.count(start=1))]
# We need separate counters for each element.
element_counters = {element: itertools.count(start=1)
for element in set(self.atomelements)}
# Generate the Q-Chem printed order.
order_qchem = [element + str(next(element_counters[element]))
for element in self.atomelements]
# Combine the orders into a mapping.
atommap = {k:v for k, v, in zip(order_qchem, order_proper)}
return atommap
def generate_formula_histogram(self):
"""From the atomnos, generate a histogram that represents the
molecular formula.
"""
histogram = dict()
for element in self.atomelements:
if element in histogram.keys():
histogram[element] += 1
else:
histogram[element] = 1
return histogram
if __name__ == '__main__':
import sys
import doctest, qchemparser
if len(sys.argv) == 1:
doctest.testmod(qchemparser, verbose=False)
if len(sys.argv) == 2:
parser = qchemparser.QChem(sys.argv[1])
data = parser.parse()
if len(sys.argv) > 2:
for i in range(len(sys.argv[2:])):
if hasattr(data, sys.argv[2 + i]):
print(getattr(data, sys.argv[2 + i]))
|
lgpl-2.1
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
7429,
773,
334,
1014,
921,
2055,
773,
14,
5031,
14,
2308,
395,
282,
3555,
367,
6057,
199,
3,
436,
6421,
1337,
314,
2058,
402,
28319,
6279,
17546,
2664,
27723,
6117,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
12,
314,
7429,
773,
16367,
8099,
199,
3,
199,
3,
710,
3555,
365,
2867,
2032,
12,
1854,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
1015,
499,
14,
17,
503,
2945,
14,
2047,
1077,
1172,
199,
3,
3086,
282,
1331,
402,
314,
4190,
3180,
543,
7429,
773,
14,
2047,
883,
2597,
2879,
199,
3,
314,
2615,
4190,
18470,
737,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
1574,
3039,
15,
9783,
1168,
14,
1360,
14,
199,
199,
624,
2842,
367,
1413,
13,
20335,
77,
1072,
1584,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
295,
199,
646,
2680,
199,
646,
7975,
199,
199,
504,
1275,
492,
17251,
2087,
199,
504,
1275,
492,
3778,
421,
199,
533,
1413,
20335,
77,
8,
12804,
2087,
14,
2445,
493,
304,
272,
408,
33,
1413,
13,
20335,
77,
841,
943,
570,
1041,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
327,
6523,
314,
636,
826,
363,
1083,
402,
314,
17035,
267,
1613,
8,
49,
20335,
77,
12,
291,
2843,
826,
721,
793,
354,
628,
49,
20335,
77,
401,
627,
589,
12,
1011,
958,
9,
339,
347,
636,
495,
721,
277,
304,
267,
408,
1767,
282,
1059,
6025,
402,
314,
909,
1041,
267,
372,
298,
49,
20335,
77,
943,
570,
450,
83,
2,
450,
334,
277,
14,
1501,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
1767,
282,
6025,
402,
314,
909,
1041,
267,
372,
283,
49,
20335,
77,
3647,
83,
32292,
450,
334,
277,
14,
1501,
9,
339,
347,
3293,
1388,
12828,
8,
277,
12,
1768,
304,
267,
408,
49,
13,
20335,
77,
1630,
440,
4409,
3293,
9147,
30246,
3628,
1041,
339,
347,
2544,
63,
11059,
8,
277,
304,
398,
327,
14797,
4426,
402,
3775,
503,
440,
781,
3984,
19203,
376,
267,
327,
334,
324,
9,
17973,
15232,
14,
267,
291,
14,
324,
17973,
275,
756,
267,
291,
14,
374,
63,
293,
9188,
275,
756,
398,
327,
24562,
314,
21106,
13,
460,
13,
269,
13,
10749,
13,
2118,
5163,
14,
267,
291,
14,
264,
63,
6760,
397,
63,
460,
63,
10749,
275,
295,
14,
2014,
9097,
7023,
83,
20253,
9988,
398,
327,
24562,
314,
5163,
367,
30137,
314,
15374,
1478,
687,
376,
267,
327,
282,
32203,
14,
267,
291,
14,
264,
63,
4188,
1080,
275,
295,
14,
2014,
360,
2961,
68,
8771,
15452,
398,
327,
437,
5696,
402,
1227,
4362,
1126,
1853,
1380,
16116,
12627,
14,
267,
291,
14,
78,
4574,
1457,
275,
1227,
398,
327,
4885,
849,
12,
1380,
20864,
370,
870,
503,
2075,
2551,
4799,
267,
327,
658,
27441,
63,
1361,
64,
15,
64,
27441,
63,
5094,
63,
1361,
64,
436,
15,
269,
658,
1361,
63,
28043,
2551,
3559,
267,
327,
1413,
13,
20335,
77,
911,
870,
1006,
26182,
5299,
83,
436,
314,
1642,
959,
5791,
83,
14,
267,
327,
267,
327,
3979,
314,
1329,
365,
663,
367,
658,
1361,
63,
28043,
2551,
3559,
626,
3420,
402,
267,
327,
314,
1072,
911,
2929,
334,
2826,
2055,
435,
626,
5002,
5791,
9,
10362,
83,
12,
1325,
267,
327,
1263,
1163,
10189,
3451,
7037,
370,
267,
327,
658,
27441,
63,
1361,
64,
15,
64,
27441,
63,
5094,
63,
1361,
64,
911,
5139,
1454,
2929,
334,
2826,
2055,
267,
327,
435,
959,
9,
10362,
83,
14,
267,
327,
267,
327,
3390,
626,
314,
13650,
3634,
365,
3544,
334,
16170,
4864,
627,
25377,
4864,
9,
1,
267,
291,
14,
6505,
66,
13654,
63,
4468,
275,
291,
14,
6505,
66,
13654,
63,
5683,
275,
959,
267,
291,
14,
6505,
66,
13654,
63,
4468,
63,
65,
265,
14015,
275,
291,
14,
6505,
66,
13654,
63,
5683,
63,
65,
265,
14015,
275,
959,
267,
291,
14,
6505,
66,
13654,
63,
409,
275,
756,
398,
291,
14,
4468,
63,
573,
63,
21329,
63,
2139,
275,
334,
288,
283,
15740,
50,
6196,
1149,
334,
50,
25500,
9,
10362,
906,
35,
3038,
1549,
11970,
748,
5099,
29512,
948,
25451,
51,
297,
288,
283,
18554,
10362,
906,
35,
3038,
1549,
11970,
748,
5099,
29512,
948,
25451,
51,
7,
267,
776,
339,
347,
2410,
63,
11059,
8,
277,
304,
398,
327,
982,
6057,
282,
7956,
3906,
12,
1924,
402,
314,
24883,
11544,
370,
267,
327,
658,
4188,
8032,
64,
1443,
506,
402,
3365,
17464,
12,
1314,
911,
7981,
267,
327,
8603,
687,
282,
769,
370,
20602,
1625,
14,
267,
327,
18146,
314,
2582,
402,
314,
1642,
3400,
465,
3211,
12,
436,
2813,
267,
327,
1006,
11789,
543,
3365,
17464,
14,
267,
340,
822,
8,
277,
14,
4188,
8032,
9,
690,
413,
26,
288,
3211,
552,
275,
822,
8,
277,
14,
4188,
8032,
59,
16,
566,
288,
291,
14,
4188,
8032,
5873,
275,
359,
8032,
367,
13259,
315,
291,
14,
4188,
8032,
3303,
340,
822,
8,
8032,
9,
508,
3211,
552,
61,
267,
327,
2854,
314,
12427,
12,
2337,
365,
949,
8545,
21940,
367,
1163,
4382,
1,
398,
327,
1413,
20335,
77,
1630,
440,
870,
1006,
10362,
12343,
701,
849,
12,
1325,
7830,
267,
327,
1536,
370,
7781,
2679,
11,
21,
14,
2002,
12,
5554,
1536,
314,
4124,
1338,
543,
31930,
14,
982,
2337,
787,
267,
327,
1163,
5560,
2382,
9421,
787,
4124,
12,
1325,
3365,
7869,
12,
642,
267,
327,
8605,
2410,
273,
20816,
5594,
440,
506,
5827,
436,
314,
5325,
911,
267,
327,
1929,
370,
506,
4224,
1830,
6057,
14,
267,
340,
2688,
8,
277,
12,
283,
573,
15958,
735,
288,
367,
3416,
315,
1425,
8,
552,
8,
277,
14,
573,
15958,
2298,
355,
485,
78,
573,
12,
485,
4994,
4864,
275,
291,
14,
573,
15958,
59,
1017,
1055,
1392,
355,
340,
6110,
78,
573,
12,
485,
4994,
4864,
9,
1137,
334,
277,
14,
78,
573,
12,
291,
14,
4994,
4864,
304,
490,
29868,
275,
2680,
14,
1667,
1332,
277,
14,
78,
573,
12,
291,
14,
4994,
4864,
430,
490,
29868,
5873
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
7429,
773,
334,
1014,
921,
2055,
773,
14,
5031,
14,
2308,
395,
282,
3555,
367,
6057,
199,
3,
436,
6421,
1337,
314,
2058,
402,
28319,
6279,
17546,
2664,
27723,
6117,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
12,
314,
7429,
773,
16367,
8099,
199,
3,
199,
3,
710,
3555,
365,
2867,
2032,
12,
1854,
1334,
314,
2895,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
1015,
499,
14,
17,
503,
2945,
14,
2047,
1077,
1172,
199,
3,
3086,
282,
1331,
402,
314,
4190,
3180,
543,
7429,
773,
14,
2047,
883,
2597,
2879,
199,
3,
314,
2615,
4190,
18470,
737,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
1574,
3039,
15,
9783,
1168,
14,
1360,
14,
199,
199,
624,
2842,
367,
1413,
13,
20335,
77,
1072,
1584,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
295,
199,
646,
2680,
199,
646,
7975,
199,
199,
504,
1275,
492,
17251,
2087,
199,
504,
1275,
492,
3778,
421,
199,
533,
1413,
20335,
77,
8,
12804,
2087,
14,
2445,
493,
304,
272,
408,
33,
1413,
13,
20335,
77,
841,
943,
570,
1041,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
327,
6523,
314,
636,
826,
363,
1083,
402,
314,
17035,
267,
1613,
8,
49,
20335,
77,
12,
291,
2843,
826,
721,
793,
354,
628,
49,
20335,
77,
401,
627,
589,
12,
1011,
958,
9,
339,
347,
636,
495,
721,
277,
304,
267,
408,
1767,
282,
1059,
6025,
402,
314,
909,
1041,
267,
372,
298,
49,
20335,
77,
943,
570,
450,
83,
2,
450,
334,
277,
14,
1501,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
408,
1767,
282,
6025,
402,
314,
909,
1041,
267,
372,
283,
49,
20335,
77,
3647,
83,
32292,
450,
334,
277,
14,
1501,
9,
339,
347,
3293,
1388,
12828,
8,
277,
12,
1768,
304,
267,
408,
49,
13,
20335,
77,
1630,
440,
4409,
3293,
9147,
30246,
3628,
1041,
339,
347,
2544,
63,
11059,
8,
277,
304,
398,
327,
14797,
4426,
402,
3775,
503,
440,
781,
3984,
19203,
376,
267,
327,
334,
324,
9,
17973,
15232,
14,
267,
291,
14,
324,
17973,
275,
756,
267,
291,
14,
374,
63,
293,
9188,
275,
756,
398,
327,
24562,
314,
21106,
13,
460,
13,
269,
13,
10749,
13,
2118,
5163,
14,
267,
291,
14,
264,
63,
6760,
397,
63,
460,
63,
10749,
275,
295,
14,
2014,
9097,
7023,
83,
20253,
9988,
398,
327,
24562,
314,
5163,
367,
30137,
314,
15374,
1478,
687,
376,
267,
327,
282,
32203,
14,
267,
291,
14,
264,
63,
4188,
1080,
275,
295,
14,
2014,
360,
2961,
68,
8771,
15452,
398,
327,
437,
5696,
402,
1227,
4362,
1126,
1853,
1380,
16116,
12627,
14,
267,
291,
14,
78,
4574,
1457,
275,
1227,
398,
327,
4885,
849,
12,
1380,
20864,
370,
870,
503,
2075,
2551,
4799,
267,
327,
658,
27441,
63,
1361,
64,
15,
64,
27441,
63,
5094,
63,
1361,
64,
436,
15,
269,
658,
1361,
63,
28043,
2551,
3559,
267,
327,
1413,
13,
20335,
77,
911,
870,
1006,
26182,
5299,
83,
436,
314,
1642,
959,
5791,
83,
14,
267,
327,
267,
327,
3979,
314,
1329,
365,
663,
367,
658,
1361,
63,
28043,
2551,
3559,
626,
3420,
402,
267,
327,
314,
1072,
911,
2929,
334,
2826,
2055,
435,
626,
5002,
5791,
9,
10362,
83,
12,
1325,
267,
327,
1263,
1163,
10189,
3451,
7037,
370,
267,
327,
658,
27441,
63,
1361,
64,
15,
64,
27441,
63,
5094,
63,
1361,
64,
911,
5139,
1454,
2929,
334,
2826,
2055,
267,
327,
435,
959,
9,
10362,
83,
14,
267,
327,
267,
327,
3390,
626,
314,
13650,
3634,
365,
3544,
334,
16170,
4864,
627,
25377,
4864,
9,
1,
267,
291,
14,
6505,
66,
13654,
63,
4468,
275,
291,
14,
6505,
66,
13654,
63,
5683,
275,
959,
267,
291,
14,
6505,
66,
13654,
63,
4468,
63,
65,
265,
14015,
275,
291,
14,
6505,
66,
13654,
63,
5683,
63,
65,
265,
14015,
275,
959,
267,
291,
14,
6505,
66,
13654,
63,
409,
275,
756,
398,
291,
14,
4468,
63,
573,
63,
21329,
63,
2139,
275,
334,
288,
283,
15740,
50,
6196,
1149,
334,
50,
25500,
9,
10362,
906,
35,
3038,
1549,
11970,
748,
5099,
29512,
948,
25451,
51,
297,
288,
283,
18554,
10362,
906,
35,
3038,
1549,
11970,
748,
5099,
29512,
948,
25451,
51,
7,
267,
776,
339,
347,
2410,
63,
11059,
8,
277,
304,
398,
327,
982,
6057,
282,
7956,
3906,
12,
1924,
402,
314,
24883,
11544,
370,
267,
327,
658,
4188,
8032,
64,
1443,
506,
402,
3365,
17464,
12,
1314,
911,
7981,
267,
327,
8603,
687,
282,
769,
370,
20602,
1625,
14,
267,
327,
18146,
314,
2582,
402,
314,
1642,
3400,
465,
3211,
12,
436,
2813,
267,
327,
1006,
11789,
543,
3365,
17464,
14,
267,
340,
822,
8,
277,
14,
4188,
8032,
9,
690,
413,
26,
288,
3211,
552,
275,
822,
8,
277,
14,
4188,
8032,
59,
16,
566,
288,
291,
14,
4188,
8032,
5873,
275,
359,
8032,
367,
13259,
315,
291,
14,
4188,
8032,
3303,
340,
822,
8,
8032,
9,
508,
3211,
552,
61,
267,
327,
2854,
314,
12427,
12,
2337,
365,
949,
8545,
21940,
367,
1163,
4382,
1,
398,
327,
1413,
20335,
77,
1630,
440,
870,
1006,
10362,
12343,
701,
849,
12,
1325,
7830,
267,
327,
1536,
370,
7781,
2679,
11,
21,
14,
2002,
12,
5554,
1536,
314,
4124,
1338,
543,
31930,
14,
982,
2337,
787,
267,
327,
1163,
5560,
2382,
9421,
787,
4124,
12,
1325,
3365,
7869,
12,
642,
267,
327,
8605,
2410,
273,
20816,
5594,
440,
506,
5827,
436,
314,
5325,
911,
267,
327,
1929,
370,
506,
4224,
1830,
6057,
14,
267,
340,
2688,
8,
277,
12,
283,
573,
15958,
735,
288,
367,
3416,
315,
1425,
8,
552,
8,
277,
14,
573,
15958,
2298,
355,
485,
78,
573,
12,
485,
4994,
4864,
275,
291,
14,
573,
15958,
59,
1017,
1055,
1392,
355,
340,
6110,
78,
573,
12,
485,
4994,
4864,
9,
1137,
334,
277,
14,
78,
573,
12,
291,
14,
4994,
4864,
304,
490,
29868,
275,
2680,
14,
1667,
1332,
277,
14,
78,
573,
12,
291,
14,
4994,
4864,
430,
490,
29868,
5873,
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,
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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
] |
gemini-testing/selenium
|
py/selenium/webdriver/remote/command.py
|
5
|
5508
|
#!/usr/bin/python
#
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC 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.
class Command(object):
"""
Defines constants for the standard WebDriver commands.
While these constants have no meaning in and of themselves, they are
used to marshal commands through a service that implements WebDriver's
remote wire protocol:
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
"""
# Keep in sync with org.openqa.selenium.remote.DriverCommand
STATUS = "status"
NEW_SESSION = "newSession"
GET_ALL_SESSIONS = "getAllSessions"
DELETE_SESSION = "deleteSession"
CLOSE = "close"
QUIT = "quit"
GET = "get"
GO_BACK = "goBack"
GO_FORWARD = "goForward"
REFRESH = "refresh"
ADD_COOKIE = "addCookie"
GET_COOKIE = "getCookie"
GET_ALL_COOKIES = "getCookies"
DELETE_COOKIE = "deleteCookie"
DELETE_ALL_COOKIES = "deleteAllCookies"
FIND_ELEMENT = "findElement"
FIND_ELEMENTS = "findElements"
FIND_CHILD_ELEMENT = "findChildElement"
FIND_CHILD_ELEMENTS = "findChildElements"
CLEAR_ELEMENT = "clearElement"
CLICK_ELEMENT = "clickElement"
SEND_KEYS_TO_ELEMENT = "sendKeysToElement"
SEND_KEYS_TO_ACTIVE_ELEMENT = "sendKeysToActiveElement"
SUBMIT_ELEMENT = "submitElement"
UPLOAD_FILE = "uploadFile"
GET_CURRENT_WINDOW_HANDLE = "getCurrentWindowHandle"
GET_WINDOW_HANDLES = "getWindowHandles"
GET_WINDOW_SIZE = "getWindowSize"
GET_WINDOW_POSITION = "getWindowPosition"
SET_WINDOW_SIZE = "setWindowSize"
SET_WINDOW_POSITION = "setWindowPosition"
SWITCH_TO_WINDOW = "switchToWindow"
SWITCH_TO_FRAME = "switchToFrame"
SWITCH_TO_PARENT_FRAME = "switchToParentFrame"
GET_ACTIVE_ELEMENT = "getActiveElement"
GET_CURRENT_URL = "getCurrentUrl"
GET_PAGE_SOURCE = "getPageSource"
GET_TITLE = "getTitle"
EXECUTE_SCRIPT = "executeScript"
GET_ELEMENT_TEXT = "getElementText"
GET_ELEMENT_VALUE = "getElementValue"
GET_ELEMENT_TAG_NAME = "getElementTagName"
SET_ELEMENT_SELECTED = "setElementSelected"
IS_ELEMENT_SELECTED = "isElementSelected"
IS_ELEMENT_ENABLED = "isElementEnabled"
IS_ELEMENT_DISPLAYED = "isElementDisplayed"
GET_ELEMENT_LOCATION = "getElementLocation"
GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW = "getElementLocationOnceScrolledIntoView"
GET_ELEMENT_SIZE = "getElementSize"
GET_ELEMENT_RECT = "getElementRect"
GET_ELEMENT_ATTRIBUTE = "getElementAttribute"
GET_ELEMENT_VALUE_OF_CSS_PROPERTY = "getElementValueOfCssProperty"
ELEMENT_EQUALS = "elementEquals"
SCREENSHOT = "screenshot"
IMPLICIT_WAIT = "implicitlyWait"
EXECUTE_ASYNC_SCRIPT = "executeAsyncScript"
SET_SCRIPT_TIMEOUT = "setScriptTimeout"
SET_TIMEOUTS = "setTimeouts"
MAXIMIZE_WINDOW = "windowMaximize"
GET_LOG = "getLog"
GET_AVAILABLE_LOG_TYPES = "getAvailableLogTypes"
#Alerts
DISMISS_ALERT = "dismissAlert"
ACCEPT_ALERT = "acceptAlert"
SET_ALERT_VALUE = "setAlertValue"
GET_ALERT_TEXT = "getAlertText"
# Advanced user interactions
CLICK = "mouseClick"
DOUBLE_CLICK = "mouseDoubleClick"
MOUSE_DOWN = "mouseButtonDown"
MOUSE_UP = "mouseButtonUp"
MOVE_TO = "mouseMoveTo"
# Screen Orientation
SET_SCREEN_ORIENTATION = "setScreenOrientation"
GET_SCREEN_ORIENTATION = "getScreenOrientation"
# Touch Actions
SINGLE_TAP = "touchSingleTap"
TOUCH_DOWN = "touchDown"
TOUCH_UP = "touchUp"
TOUCH_MOVE = "touchMove"
TOUCH_SCROLL = "touchScroll"
DOUBLE_TAP = "touchDoubleTap"
LONG_PRESS = "touchLongPress"
FLICK = "touchFlick"
#HTML 5
EXECUTE_SQL = "executeSql"
GET_LOCATION = "getLocation"
SET_LOCATION = "setLocation"
GET_APP_CACHE = "getAppCache"
GET_APP_CACHE_STATUS = "getAppCacheStatus"
CLEAR_APP_CACHE = "clearAppCache"
GET_LOCAL_STORAGE_ITEM = "getLocalStorageItem"
REMOVE_LOCAL_STORAGE_ITEM = "removeLocalStorageItem"
GET_LOCAL_STORAGE_KEYS = "getLocalStorageKeys"
SET_LOCAL_STORAGE_ITEM = "setLocalStorageItem"
CLEAR_LOCAL_STORAGE = "clearLocalStorage"
GET_LOCAL_STORAGE_SIZE = "getLocalStorageSize"
GET_SESSION_STORAGE_ITEM = "getSessionStorageItem"
REMOVE_SESSION_STORAGE_ITEM = "removeSessionStorageItem"
GET_SESSION_STORAGE_KEYS = "getSessionStorageKeys"
SET_SESSION_STORAGE_ITEM = "setSessionStorageItem"
CLEAR_SESSION_STORAGE = "clearSessionStorage"
GET_SESSION_STORAGE_SIZE = "getSessionStorageSize"
# Mobile
GET_NETWORK_CONNECTION = "getNetworkConnection"
SET_NETWORK_CONNECTION = "setNetworkConnection"
CURRENT_CONTEXT_HANDLE = "getCurrentContextHandle"
CONTEXT_HANDLES = "getContextHandles"
SWITCH_TO_CONTEXT = "switchToContext"
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
3909,
370,
314,
2290,
481,
3798,
676,
1448,
7297,
9844,
334,
51,
4161,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
428,
4161,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
533,
5817,
8,
785,
304,
272,
408,
272,
25022,
5262,
367,
314,
4465,
27104,
3718,
14,
339,
22117,
3520,
5262,
1172,
949,
11150,
315,
436,
402,
17279,
12,
2985,
787,
272,
1202,
370,
21985,
3718,
4012,
282,
2435,
626,
9031,
27104,
1159,
272,
3982,
11799,
4113,
26,
398,
4178,
921,
5031,
14,
957,
15,
31315,
27497,
15,
15041,
15,
6797,
15,
9653,
25791,
3658,
339,
408,
339,
327,
14797,
315,
7604,
543,
5981,
14,
1490,
7096,
14,
15041,
14,
3846,
14,
6158,
3110,
339,
18460,
275,
298,
1205,
2,
272,
18689,
63,
12763,
275,
298,
1222,
4434,
2,
272,
9576,
63,
1761,
63,
51,
1608,
2823,
275,
298,
31359,
51,
30414,
2,
272,
15137,
63,
12763,
275,
298,
1807,
4434,
2,
272,
445,
1484,
899,
275,
298,
1600,
2,
272,
7813,
649,
275,
298,
10589,
2,
272,
9576,
275,
298,
362,
2,
272,
598,
47,
63,
7111,
275,
298,
1939,
4540,
2,
272,
598,
47,
63,
29700,
275,
298,
1939,
12984,
2,
272,
5363,
38,
15098,
275,
298,
6635,
2,
272,
21380,
63,
13665,
275,
298,
525,
7810,
2,
272,
9576,
63,
13665,
275,
298,
362,
7810,
2,
272,
9576,
63,
1761,
63,
12189,
2563,
275,
298,
362,
967,
5635,
2,
272,
15137,
63,
13665,
275,
298,
1807,
7810,
2,
272,
15137,
63,
1761,
63,
12189,
2563,
275,
298,
1807,
2422,
967,
5635,
2,
272,
481,
3192,
63,
12535,
275,
298,
1623,
2162,
2,
272,
481,
3192,
63,
12535,
51,
275,
298,
1623,
6255,
2,
272,
481,
3192,
63,
30460,
63,
12535,
275,
298,
1623,
3493,
2162,
2,
272,
481,
3192,
63,
30460,
63,
12535,
51,
275,
298,
1623,
3493,
6255,
2,
272,
445,
906,
689,
63,
12535,
275,
298,
3584,
2162,
2,
272,
445,
2507,
43,
63,
12535,
275,
298,
4891,
2162,
2,
272,
428,
3902,
63,
17434,
63,
2566,
63,
12535,
275,
298,
2254,
6340,
1378,
2162,
2,
272,
428,
3902,
63,
17434,
63,
2566,
63,
10401,
63,
12535,
275,
298,
2254,
6340,
1378,
7472,
2162,
2,
272,
7605,
13965,
63,
12535,
275,
298,
7275,
2162,
2,
272,
7215,
7405,
63,
3817,
275,
298,
5064,
1173,
2,
272,
9576,
63,
14211,
63,
15480,
63,
15885,
275,
298,
16662,
4301,
5940,
2,
272,
9576,
63,
15480,
63,
10854,
11344,
275,
298,
362,
4301,
23555,
2,
272,
9576,
63,
15480,
63,
4305,
275,
298,
362,
4301,
2320,
2,
272,
9576,
63,
15480,
63,
15717,
275,
298,
362,
4301,
5625,
2,
272,
11543,
63,
15480,
63,
4305,
275,
298,
25666,
2320,
2,
272,
11543,
63,
15480,
63,
15717,
275,
298,
25666,
5625,
2,
272,
17548,
15894,
63,
2566,
63,
15480,
275,
298,
5656,
1378,
4301,
2,
272,
17548,
15894,
63,
2566,
63,
12683,
275,
298,
5656,
1378,
3160,
2,
272,
17548,
15894,
63,
2566,
63,
20562,
63,
12683,
275,
298,
5656,
1378,
6652,
3160,
2,
272,
9576,
63,
10401,
63,
12535,
275,
298,
362,
7472,
2162,
2,
272,
9576,
63,
14211,
63,
2632,
275,
298,
16662,
6417,
2,
272,
9576,
63,
12898,
63,
10187,
275,
298,
27275,
2980,
2,
272,
9576,
63,
19091,
275,
298,
362,
6888,
2,
272,
3651,
4220,
4586,
63,
10484,
275,
298,
2526,
5229,
2,
272,
9576,
63,
12535,
63,
3876,
275,
298,
21720,
1872,
2,
272,
9576,
63,
12535,
63,
7041,
275,
298,
21720,
1110,
2,
272,
9576,
63,
12535,
63,
6967,
63,
2339,
275,
298,
21720,
12902,
2,
272,
11543,
63,
12535,
63,
32525,
275,
298,
409,
2162,
12461,
2,
272,
2281,
63,
12535,
63,
32525,
275,
298,
374,
2162,
12461,
2,
272,
2281,
63,
12535,
63,
15704,
275,
298,
374,
2162,
6589,
2,
272,
2281,
63,
12535,
63,
20993,
1149,
275,
298,
374,
2162,
7687,
379,
2,
272,
9576,
63,
12535,
63,
16575,
275,
298,
21720,
6592,
2,
272,
9576,
63,
12535,
63,
16575,
63,
615,
2089,
63,
5153,
6245,
5290,
63,
568,
2566,
63,
12058,
275,
298,
21720,
6592,
25690,
29145,
19448,
2768,
2,
272,
9576,
63,
12535,
63,
4305,
275,
298,
21720,
2320,
2,
272,
9576,
63,
12535,
63,
4168,
275,
298,
21720,
8252,
2,
272,
9576,
63,
12535,
63,
17075,
275,
298,
21720,
1646,
2,
272,
9576,
63,
12535,
63,
7041,
63,
3359,
63,
14391,
63,
25091,
275,
298,
21720,
1110,
3466,
35,
385,
3697,
2,
272,
662,
10320,
63,
16352,
51,
275,
298,
2108,
13317,
2,
272,
428,
5798,
742,
25041,
275,
298,
23269,
2,
272,
5025,
14365,
63,
12458,
275,
298,
31120,
7536,
2,
272,
3651,
4220,
4586,
63,
26222,
6389,
63,
10484,
275,
298,
2526,
12807,
5229,
2,
272,
11543,
63,
10484,
63,
8899,
275,
298,
409,
5229,
6372,
2,
272,
11543,
63,
8899,
51,
275,
298,
409,
6372,
83,
2,
272,
9141,
1469,
11025,
63,
15480,
275,
298,
3806,
4261,
11807,
2,
272,
9576,
63,
4947,
275,
298,
362,
2445,
2,
272,
9576,
63,
17377,
63,
4947,
63,
7893,
275,
298,
362,
11464,
2445,
4100,
2,
339,
327,
33,
16676,
272,
7587,
24513,
63,
748,
5397,
275,
298,
32439,
18758,
2,
272,
28538,
63,
748,
5397,
275,
298,
5694,
18758,
2,
272,
11543,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
3909,
370,
314,
2290,
481,
3798,
676,
1448,
7297,
9844,
334,
51,
4161,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
428,
4161,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
533,
5817,
8,
785,
304,
272,
408,
272,
25022,
5262,
367,
314,
4465,
27104,
3718,
14,
339,
22117,
3520,
5262,
1172,
949,
11150,
315,
436,
402,
17279,
12,
2985,
787,
272,
1202,
370,
21985,
3718,
4012,
282,
2435,
626,
9031,
27104,
1159,
272,
3982,
11799,
4113,
26,
398,
4178,
921,
5031,
14,
957,
15,
31315,
27497,
15,
15041,
15,
6797,
15,
9653,
25791,
3658,
339,
408,
339,
327,
14797,
315,
7604,
543,
5981,
14,
1490,
7096,
14,
15041,
14,
3846,
14,
6158,
3110,
339,
18460,
275,
298,
1205,
2,
272,
18689,
63,
12763,
275,
298,
1222,
4434,
2,
272,
9576,
63,
1761,
63,
51,
1608,
2823,
275,
298,
31359,
51,
30414,
2,
272,
15137,
63,
12763,
275,
298,
1807,
4434,
2,
272,
445,
1484,
899,
275,
298,
1600,
2,
272,
7813,
649,
275,
298,
10589,
2,
272,
9576,
275,
298,
362,
2,
272,
598,
47,
63,
7111,
275,
298,
1939,
4540,
2,
272,
598,
47,
63,
29700,
275,
298,
1939,
12984,
2,
272,
5363,
38,
15098,
275,
298,
6635,
2,
272,
21380,
63,
13665,
275,
298,
525,
7810,
2,
272,
9576,
63,
13665,
275,
298,
362,
7810,
2,
272,
9576,
63,
1761,
63,
12189,
2563,
275,
298,
362,
967,
5635,
2,
272,
15137,
63,
13665,
275,
298,
1807,
7810,
2,
272,
15137,
63,
1761,
63,
12189,
2563,
275,
298,
1807,
2422,
967,
5635,
2,
272,
481,
3192,
63,
12535,
275,
298,
1623,
2162,
2,
272,
481,
3192,
63,
12535,
51,
275,
298,
1623,
6255,
2,
272,
481,
3192,
63,
30460,
63,
12535,
275,
298,
1623,
3493,
2162,
2,
272,
481,
3192,
63,
30460,
63,
12535,
51,
275,
298,
1623,
3493,
6255,
2,
272,
445,
906,
689,
63,
12535,
275,
298,
3584,
2162,
2,
272,
445,
2507,
43,
63,
12535,
275,
298,
4891,
2162,
2,
272,
428,
3902,
63,
17434,
63,
2566,
63,
12535,
275,
298,
2254,
6340,
1378,
2162,
2,
272,
428,
3902,
63,
17434,
63,
2566,
63,
10401,
63,
12535,
275,
298,
2254,
6340,
1378,
7472,
2162,
2,
272,
7605,
13965,
63,
12535,
275,
298,
7275,
2162,
2,
272,
7215,
7405,
63,
3817,
275,
298,
5064,
1173,
2,
272,
9576,
63,
14211,
63,
15480,
63,
15885,
275,
298,
16662,
4301,
5940,
2,
272,
9576,
63,
15480,
63,
10854,
11344,
275,
298,
362,
4301,
23555,
2,
272,
9576,
63,
15480,
63,
4305,
275,
298,
362,
4301,
2320,
2,
272,
9576,
63,
15480,
63,
15717,
275,
298,
362,
4301,
5625,
2,
272,
11543,
63,
15480,
63,
4305,
275,
298,
25666,
2320,
2,
272,
11543,
63,
15480,
63,
15717,
275,
298,
25666,
5625,
2,
272,
17548,
15894,
63,
2566,
63,
15480,
275,
298,
5656,
1378,
4301,
2,
272,
17548,
15894,
63,
2566,
63,
12683,
275,
298,
5656,
1378,
3160,
2,
272,
17548,
15894,
63,
2566,
63,
20562,
63,
12683,
275,
298,
5656,
1378,
6652,
3160,
2,
272,
9576,
63,
10401,
63,
12535,
275,
298,
362,
7472,
2162,
2,
272,
9576,
63,
14211,
63,
2632,
275,
298,
16662,
6417,
2,
272,
9576,
63,
12898,
63,
10187,
275,
298,
27275,
2980,
2,
272,
9576,
63,
19091,
275,
298,
362,
6888,
2,
272,
3651,
4220,
4586,
63,
10484,
275,
298,
2526,
5229,
2,
272,
9576,
63,
12535,
63,
3876,
275,
298,
21720,
1872,
2,
272,
9576,
63,
12535,
63,
7041,
275,
298,
21720,
1110,
2,
272,
9576,
63,
12535,
63,
6967,
63,
2339,
275,
298,
21720,
12902,
2,
272,
11543,
63,
12535,
63,
32525,
275,
298,
409,
2162,
12461,
2,
272,
2281,
63,
12535,
63,
32525,
275,
298,
374,
2162,
12461,
2,
272,
2281,
63,
12535,
63,
15704,
275,
298,
374,
2162,
6589,
2,
272,
2281,
63,
12535,
63,
20993,
1149,
275,
298,
374,
2162,
7687,
379,
2,
272,
9576,
63,
12535,
63,
16575,
275,
298,
21720,
6592,
2,
272,
9576,
63,
12535,
63,
16575,
63,
615,
2089,
63,
5153,
6245,
5290,
63,
568,
2566,
63,
12058,
275,
298,
21720,
6592,
25690,
29145,
19448,
2768,
2,
272,
9576,
63,
12535,
63,
4305,
275,
298,
21720,
2320,
2,
272,
9576,
63,
12535,
63,
4168,
275,
298,
21720,
8252,
2,
272,
9576,
63,
12535,
63,
17075,
275,
298,
21720,
1646,
2,
272,
9576,
63,
12535,
63,
7041,
63,
3359,
63,
14391,
63,
25091,
275,
298,
21720,
1110,
3466,
35,
385,
3697,
2,
272,
662,
10320,
63,
16352,
51,
275,
298,
2108,
13317,
2,
272,
428,
5798,
742,
25041,
275,
298,
23269,
2,
272,
5025,
14365,
63,
12458,
275,
298,
31120,
7536,
2,
272,
3651,
4220,
4586,
63,
26222,
6389,
63,
10484,
275,
298,
2526,
12807,
5229,
2,
272,
11543,
63,
10484,
63,
8899,
275,
298,
409,
5229,
6372,
2,
272,
11543,
63,
8899,
51,
275,
298,
409,
6372,
83,
2,
272,
9141,
1469,
11025,
63,
15480,
275,
298,
3806,
4261,
11807,
2,
272,
9576,
63,
4947,
275,
298,
362,
2445,
2,
272,
9576,
63,
17377,
63,
4947,
63,
7893,
275,
298,
362,
11464,
2445,
4100,
2,
339,
327,
33,
16676,
272,
7587,
24513,
63,
748,
5397,
275,
298,
32439,
18758,
2,
272,
28538,
63,
748,
5397,
275,
298,
5694,
18758,
2,
272,
11543,
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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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
] |
apache/airflow
|
airflow/api_connexion/schemas/plugin_schema.py
|
3
|
1754
|
# 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 typing import List, NamedTuple
from marshmallow import Schema, fields
class PluginSchema(Schema):
"""Plugin schema"""
number = fields.Int()
name = fields.String()
hooks = fields.List(fields.String())
executors = fields.List(fields.String())
macros = fields.List(fields.String())
flask_blueprints = fields.List(fields.String())
appbuilder_views = fields.List(fields.String())
appbuilder_menu_items = fields.List(fields.Dict())
global_operator_extra_links = fields.List(fields.String())
operator_extra_links = fields.List(fields.String())
source = fields.String()
class PluginCollection(NamedTuple):
"""Plugin List"""
plugins: List
total_entries: int
class PluginCollectionSchema(Schema):
"""Plugin Collection List"""
plugins = fields.List(fields.Nested(PluginSchema))
total_entries = fields.Int()
plugin_schema = PluginSchema()
plugin_collection_schema = PluginCollectionSchema()
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
14090,
492,
3820,
12,
16198,
7075,
199,
199,
504,
7557,
609,
2174,
674,
492,
13268,
12,
1504,
421,
199,
533,
11349,
6700,
8,
6700,
304,
272,
408,
5061,
4177,
624,
339,
1329,
275,
1504,
14,
3241,
342,
272,
536,
275,
1504,
14,
1558,
342,
272,
12604,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
2146,
6622,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
16954,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
7209,
63,
15918,
83,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
1145,
5649,
63,
4196,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
1145,
5649,
63,
4470,
63,
1744,
275,
1504,
14,
1296,
8,
955,
14,
2141,
1012,
272,
2288,
63,
3856,
63,
2911,
63,
4614,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
4182,
63,
2911,
63,
4614,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
1350,
275,
1504,
14,
1558,
342,
421,
199,
533,
11349,
7768,
8,
7989,
7075,
304,
272,
408,
5061,
3820,
624,
339,
8963,
26,
3820,
272,
3141,
63,
3189,
26,
1109,
421,
199,
533,
11349,
7768,
6700,
8,
6700,
304,
272,
408,
5061,
18003,
3820,
624,
339,
8963,
275,
1504,
14,
1296,
8,
955,
14,
13029,
8,
5061,
6700,
430,
272,
3141,
63,
3189,
275,
1504,
14,
3241,
342,
421,
199,
2718,
63,
3629,
275,
11349,
6700,
342,
199,
2718,
63,
3627,
63,
3629,
275,
11349,
7768,
6700,
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
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
14090,
492,
3820,
12,
16198,
7075,
199,
199,
504,
7557,
609,
2174,
674,
492,
13268,
12,
1504,
421,
199,
533,
11349,
6700,
8,
6700,
304,
272,
408,
5061,
4177,
624,
339,
1329,
275,
1504,
14,
3241,
342,
272,
536,
275,
1504,
14,
1558,
342,
272,
12604,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
2146,
6622,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
16954,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
7209,
63,
15918,
83,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
1145,
5649,
63,
4196,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
1145,
5649,
63,
4470,
63,
1744,
275,
1504,
14,
1296,
8,
955,
14,
2141,
1012,
272,
2288,
63,
3856,
63,
2911,
63,
4614,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
4182,
63,
2911,
63,
4614,
275,
1504,
14,
1296,
8,
955,
14,
1558,
1012,
272,
1350,
275,
1504,
14,
1558,
342,
421,
199,
533,
11349,
7768,
8,
7989,
7075,
304,
272,
408,
5061,
3820,
624,
339,
8963,
26,
3820,
272,
3141,
63,
3189,
26,
1109,
421,
199,
533,
11349,
7768,
6700,
8,
6700,
304,
272,
408,
5061,
18003,
3820,
624,
339,
8963,
275,
1504,
14,
1296,
8,
955,
14,
13029,
8,
5061,
6700,
430,
272,
3141,
63,
3189,
275,
1504,
14,
3241,
342,
421,
199,
2718,
63,
3629,
275,
11349,
6700,
342,
199,
2718,
63,
3627,
63,
3629,
275,
11349,
7768,
6700,
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,
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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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
] |
santod/NuK3rn3l_m7_sense_lollipop
|
scripts/gcc-wrapper.py
|
104
|
3924
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Code Aurora nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Invoke gcc, looking for warnings, and causing a failure if there are
# non-whitelisted warnings.
import errno
import re
import os
import sys
import subprocess
# Note that gcc uses unicode, which may depend on the locale. TODO:
# force LANG to be set to en_US.UTF-8 to get consistent warnings.
allowed_warnings = set([
"alignment.c:327",
"mmu.c:602",
"return_address.c:62",
"swab.h:49",
"SemaLambda.cpp:946",
"CGObjCGNU.cpp:1414",
"BugReporter.h:146",
"RegionStore.cpp:1904",
"SymbolManager.cpp:484",
"RewriteObjCFoundationAPI.cpp:737",
"RewriteObjCFoundationAPI.cpp:696",
"CommentParser.cpp:394",
"CommentParser.cpp:391",
"CommentParser.cpp:356",
"LegalizeDAG.cpp:3646",
"IRBuilder.h:844",
"DataLayout.cpp:193",
"transport.c:653",
"xt_socket.c:307",
"xt_socket.c:161",
"inet_hashtables.h:356",
"xc4000.c:1049",
"xc4000.c:1063",
])
# Capture the name of the object file, can find it.
ofile = None
warning_re = re.compile(r'''(.*/|)([^/]+\.[a-z]+:\d+):(\d+:)? warning:''')
def interpret_warning(line):
"""Decode the message from gcc. The messages we care about have a filename, and a warning"""
line = line.rstrip('\n')
m = warning_re.match(line)
if m and m.group(2) not in allowed_warnings:
print "error, forbidden warning:", m.group(2)
# If there is a warning, remove any object if it exists.
if ofile:
try:
os.remove(ofile)
except OSError:
pass
sys.exit(1)
def run_gcc():
args = sys.argv[1:]
# Look for -o
try:
i = args.index('-o')
global ofile
ofile = args[i+1]
except (ValueError, IndexError):
pass
compiler = sys.argv[0]
try:
proc = subprocess.Popen(args, stderr=subprocess.PIPE)
for line in proc.stderr:
print line,
interpret_warning(line)
result = proc.wait()
except OSError as e:
result = e.errno
if result == errno.ENOENT:
print args[0] + ':',e.strerror
print 'Is your PATH set correctly?'
else:
print ' '.join(args), str(e)
return result
if __name__ == '__main__':
status = run_gcc()
sys.exit(status)
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7760,
13,
7409,
12,
5495,
437,
300,
11131,
2104,
453,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
5495,
437,
300,
11131,
6590,
199,
3,
755,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
3,
755,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
755,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
11214,
13,
12799,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
31049,
19443,
12,
10023,
367,
3598,
12,
436,
25498,
282,
5988,
340,
2337,
787,
199,
3,
2222,
13,
7510,
15023,
3598,
14,
199,
199,
646,
7554,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
199,
3,
3390,
626,
19443,
4440,
2649,
12,
1314,
1443,
11687,
641,
314,
5867,
14,
221,
3254,
26,
199,
3,
3542,
25029,
370,
506,
663,
370,
655,
63,
1668,
14,
6610,
13,
24,
370,
664,
12137,
3598,
14,
199,
199,
6541,
63,
5451,
275,
663,
779,
272,
298,
13699,
14,
67,
26,
11754,
401,
272,
298,
596,
85,
14,
67,
26,
28384,
401,
272,
298,
1107,
63,
1562,
14,
67,
26,
2789,
401,
199,
198,
2,
3519,
371,
14,
72,
26,
1887,
401,
2043,
298,
1513,
391,
21350,
14,
5910,
26,
30626,
401,
2043,
298,
4064,
5665,
4064,
1440,
14,
5910,
26,
1079,
1079,
401,
2043,
298,
17545,
15891,
14,
72,
26,
11432,
401,
2043,
298,
10708,
5502,
14,
5910,
26,
1167,
966,
401,
2043,
298,
8169,
2988,
14,
5910,
26,
29618,
401,
2043,
298,
497,
952,
5665,
35,
30216,
3735,
14,
5910,
26,
29045,
401,
2043,
298,
497,
952,
5665,
35,
30216,
3735,
14,
5910,
26,
15154,
401,
2043,
298,
7488,
2842,
14,
5910,
26,
13549,
401,
2043,
298,
7488,
2842,
14,
5910,
26,
16959,
401,
2043,
298,
7488,
2842,
14,
5910,
26,
13251,
401,
2043,
298,
13257,
279,
794,
28211,
14,
5910,
26,
19,
11387,
401,
2043,
298,
3927,
6437,
14,
72,
26,
16042,
401,
2043,
298,
1451,
4798,
14,
5910,
26,
13015,
401,
2043,
298,
5545,
14,
67,
26,
25401,
401,
2043,
298,
400,
63,
3450,
14,
67,
26,
11516,
401,
2043,
298,
400,
63,
3450,
14,
67,
26,
12285,
401,
2043,
298,
10811,
63,
1989,
517,
5921,
14,
72,
26,
13251,
401,
2043,
298,
1812,
23641,
14,
67,
26,
709,
1887,
401,
2043,
298,
1812,
23641,
14,
67,
26,
709,
2766,
401,
198,
199,
4794,
199,
199,
3,
29828,
314,
536,
402,
314,
909,
570,
12,
883,
2342,
652,
14,
199,
79,
493,
275,
488,
199,
199,
3764,
63,
264,
275,
295,
14,
2014,
8,
82,
2344,
19276,
15,
92,
9,
7059,
15251,
27658,
65,
13,
90,
2807,
3427,
68,
11,
304,
2961,
68,
11,
26,
5547,
5721,
26,
12310,
199,
318,
15579,
63,
3764,
8,
604,
304,
272,
408,
9400,
314,
1245,
687,
19443,
14,
221,
710,
3788,
781,
10296,
3595,
1172,
282,
1788,
12,
436,
282,
5721,
624,
272,
1004,
275,
1004,
14,
6735,
2258,
78,
358,
272,
333,
275,
5721,
63,
264,
14,
1431,
8,
604,
9,
272,
340,
333,
436,
333,
14,
923,
8,
18,
9,
440,
315,
4370,
63,
5451,
26,
267,
870,
298,
705,
12,
24786,
5721,
6783,
333,
14,
923,
8,
18,
9,
398,
327,
982,
2337,
365,
282,
5721,
12,
2813,
1263,
909,
340,
652,
3495,
14,
267,
340,
312,
493,
26,
288,
862,
26,
355,
747,
14,
2168,
8,
79,
493,
9,
288,
871,
6440,
26,
355,
986,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
1255,
63,
13112,
837,
272,
1249,
275,
984,
14,
3020,
59,
17,
2938,
272,
327,
12077,
367,
446,
79,
272,
862,
26,
267,
284,
275,
1249,
14,
1080,
3654,
79,
358,
267,
2288,
312,
493,
267,
312,
493,
275,
1249,
59,
73,
11,
17,
61,
272,
871,
334,
3393,
12,
7888,
304,
267,
986,
339,
6365,
275,
984,
14,
3020,
59,
16,
61,
339,
862,
26,
267,
6499,
275,
3873,
14,
7942,
8,
589,
12,
4635,
29,
5781,
14,
6089,
9,
267,
367,
1004,
315,
6499,
14,
3083,
26,
288,
870,
1004,
12,
288,
15579,
63,
3764,
8,
604,
9,
398,
754,
275,
6499,
14,
2573,
342,
272,
871,
6440,
465,
325,
26,
267,
754,
275,
325,
14,
7931,
267,
340,
754,
508,
7554,
14,
20465,
26,
288,
870,
1249,
59,
16,
61,
435,
25475,
69,
14,
20395,
288,
870,
283,
1831,
2195,
15097,
663,
6657,
14069,
267,
587,
26,
288,
870,
283,
1987,
904,
8,
589,
395,
620,
8,
69,
9,
339,
372,
754,
199,
199
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7760,
13,
7409,
12,
5495,
437,
300,
11131,
2104,
453,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
5495,
437,
300,
11131,
6590,
199,
3,
755,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
3,
755,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
3,
755,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
11214,
13,
12799,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
3,
31049,
19443,
12,
10023,
367,
3598,
12,
436,
25498,
282,
5988,
340,
2337,
787,
199,
3,
2222,
13,
7510,
15023,
3598,
14,
199,
199,
646,
7554,
199,
646,
295,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
199,
3,
3390,
626,
19443,
4440,
2649,
12,
1314,
1443,
11687,
641,
314,
5867,
14,
221,
3254,
26,
199,
3,
3542,
25029,
370,
506,
663,
370,
655,
63,
1668,
14,
6610,
13,
24,
370,
664,
12137,
3598,
14,
199,
199,
6541,
63,
5451,
275,
663,
779,
272,
298,
13699,
14,
67,
26,
11754,
401,
272,
298,
596,
85,
14,
67,
26,
28384,
401,
272,
298,
1107,
63,
1562,
14,
67,
26,
2789,
401,
199,
198,
2,
3519,
371,
14,
72,
26,
1887,
401,
2043,
298,
1513,
391,
21350,
14,
5910,
26,
30626,
401,
2043,
298,
4064,
5665,
4064,
1440,
14,
5910,
26,
1079,
1079,
401,
2043,
298,
17545,
15891,
14,
72,
26,
11432,
401,
2043,
298,
10708,
5502,
14,
5910,
26,
1167,
966,
401,
2043,
298,
8169,
2988,
14,
5910,
26,
29618,
401,
2043,
298,
497,
952,
5665,
35,
30216,
3735,
14,
5910,
26,
29045,
401,
2043,
298,
497,
952,
5665,
35,
30216,
3735,
14,
5910,
26,
15154,
401,
2043,
298,
7488,
2842,
14,
5910,
26,
13549,
401,
2043,
298,
7488,
2842,
14,
5910,
26,
16959,
401,
2043,
298,
7488,
2842,
14,
5910,
26,
13251,
401,
2043,
298,
13257,
279,
794,
28211,
14,
5910,
26,
19,
11387,
401,
2043,
298,
3927,
6437,
14,
72,
26,
16042,
401,
2043,
298,
1451,
4798,
14,
5910,
26,
13015,
401,
2043,
298,
5545,
14,
67,
26,
25401,
401,
2043,
298,
400,
63,
3450,
14,
67,
26,
11516,
401,
2043,
298,
400,
63,
3450,
14,
67,
26,
12285,
401,
2043,
298,
10811,
63,
1989,
517,
5921,
14,
72,
26,
13251,
401,
2043,
298,
1812,
23641,
14,
67,
26,
709,
1887,
401,
2043,
298,
1812,
23641,
14,
67,
26,
709,
2766,
401,
198,
199,
4794,
199,
199,
3,
29828,
314,
536,
402,
314,
909,
570,
12,
883,
2342,
652,
14,
199,
79,
493,
275,
488,
199,
199,
3764,
63,
264,
275,
295,
14,
2014,
8,
82,
2344,
19276,
15,
92,
9,
7059,
15251,
27658,
65,
13,
90,
2807,
3427,
68,
11,
304,
2961,
68,
11,
26,
5547,
5721,
26,
12310,
199,
318,
15579,
63,
3764,
8,
604,
304,
272,
408,
9400,
314,
1245,
687,
19443,
14,
221,
710,
3788,
781,
10296,
3595,
1172,
282,
1788,
12,
436,
282,
5721,
624,
272,
1004,
275,
1004,
14,
6735,
2258,
78,
358,
272,
333,
275,
5721,
63,
264,
14,
1431,
8,
604,
9,
272,
340,
333,
436,
333,
14,
923,
8,
18,
9,
440,
315,
4370,
63,
5451,
26,
267,
870,
298,
705,
12,
24786,
5721,
6783,
333,
14,
923,
8,
18,
9,
398,
327,
982,
2337,
365,
282,
5721,
12,
2813,
1263,
909,
340,
652,
3495,
14,
267,
340,
312,
493,
26,
288,
862,
26,
355,
747,
14,
2168,
8,
79,
493,
9,
288,
871,
6440,
26,
355,
986,
267,
984,
14,
2224,
8,
17,
9,
199,
199,
318,
1255,
63,
13112,
837,
272,
1249,
275,
984,
14,
3020,
59,
17,
2938,
272,
327,
12077,
367,
446,
79,
272,
862,
26,
267,
284,
275,
1249,
14,
1080,
3654,
79,
358,
267,
2288,
312,
493,
267,
312,
493,
275,
1249,
59,
73,
11,
17,
61,
272,
871,
334,
3393,
12,
7888,
304,
267,
986,
339,
6365,
275,
984,
14,
3020,
59,
16,
61,
339,
862,
26,
267,
6499,
275,
3873,
14,
7942,
8,
589,
12,
4635,
29,
5781,
14,
6089,
9,
267,
367,
1004,
315,
6499,
14,
3083,
26,
288,
870,
1004,
12,
288,
15579,
63,
3764,
8,
604,
9,
398,
754,
275,
6499,
14,
2573,
342,
272,
871,
6440,
465,
325,
26,
267,
754,
275,
325,
14,
7931,
267,
340,
754,
508,
7554,
14,
20465,
26,
288,
870,
1249,
59,
16,
61,
435,
25475,
69,
14,
20395,
288,
870,
283,
1831,
2195,
15097,
663,
6657,
14069,
267,
587,
26,
288,
870,
283,
1987,
904,
8,
589,
395,
620,
8,
69,
9,
339,
372,
754,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
FokkeZB/titanium_mobile
|
support/iphone/compiler.py
|
14
|
26463
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Project Compiler
#
import os, sys, re, shutil, time, run, sgmllib, codecs, tempfile, subprocess
template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
sys.path.append(os.path.abspath(os.path.join(template_dir,'..')))
sys.path.append(os.path.abspath(os.path.join(template_dir,'..', 'common')))
from tiapp import *
import jspacker
from csspacker import CSSPacker
import traceback
try:
import json
except:
import simplejson as json
ignoreFiles = ['.gitignore', '.cvsignore', '.DS_Store', '_svn'];
ignoreDirs = ['iphone', 'android', 'mobileweb', '.git', '.svn', 'CVS'];
HEADER = """/**
* Appcelerator Titanium Mobile
* This is generated code. Do not modify. Your changes *will* be lost.
* Generated code is Copyright (c) 2009-2012 by Appcelerator, Inc.
* All Rights Reserved.
*/
#import <Foundation/Foundation.h>
"""
INTERFACE_HEADER= """
@interface ApplicationRouting : NSObject {
}
+ (NSData*) resolveAppAsset:(NSString*)path;
"""
IMPL_HEADER= """#import "ApplicationRouting.h"
extern NSData* filterDataInRange(NSData* thedata, NSRange range);
@implementation ApplicationRouting
"""
FOOTER ="""
@end
"""
MODULE_IMPL_HEADER = """#import "ApplicationMods.h"
@implementation ApplicationMods
+ (NSArray*) compiledMods
{
NSMutableArray *modules = [NSMutableArray array];
"""
class HTMLParser(sgmllib.SGMLParser):
def parse(self, s):
self.feed(s)
self.close()
def __init__(self, verbose=0):
sgmllib.SGMLParser.__init__(self, verbose)
self.scripts = []
def start_script(self, attributes):
for name, value in attributes:
if name == "src":
self.scripts.append(value)
def get_scripts(self):
return self.scripts
def read_module_properties(dir):
file = os.path.join(dir,'manifest')
dict = {}
if os.path.exists(file):
contents = open(file).read()
for line in contents.splitlines(True):
if line[0:1]=='#': continue
idx = line.find(':')
if idx==-1: continue
k=line[0:idx]
v=line[idx+1:].strip()
dict[k]=v
return dict
#Convert non-unicode obj to unicode encoded in utf-8.
def to_unicode_or_not(obj, encoding='utf-8'):
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
return obj
# Need to pre-parse xcconfig files to mangle variable names, and then
# dump them into a map so that we can re-assemble them later
def parse_xcconfig(xcconfig, moduleId, variables):
module_xcconfig = open(xcconfig)
new_xcconfig = ''
local_variables = {}
prefix = moduleId.upper().replace('.','_')
for line in module_xcconfig:
# Strip comments
comment = line.find('//')
if comment != -1:
line = line[0:comment]
# Generate new varname / value pairings
# The regular expression parses a valid line into components
# <var>=<value>
# <var>[<key>=<keyvalue>]=<value>
# e.g.
# OTHER_LDFLAGS=-framework EventKit
# OTHER_LDFLAGS[sdk=iphoneos4*]=-liconv
splitline = re.split('(([^\[=]+)(\[[^\]]+\])?) *=? *(.+)', line)
if len(splitline) >= 5:
varname = splitline[1]
value = splitline[4]
name = prefix + '_' + varname.strip()
name = re.sub(r'[^\w]', '_', name)
local_variables[varname] = name
new_xcconfig += name + '=' + value + '\n'
module_xcconfig.close()
# Update any local variable references with new varname
# and add variables to the global variables map
for (varname, name) in local_variables.iteritems():
source = '$(%s)' % varname
target = '$(%s)' % name
new_xcconfig = new_xcconfig.replace(source,target)
# Add new varname to the list
if not varname in variables:
variables[varname] = [name]
else:
variables[varname].append(name)
new_xcconfig += '\n'
return new_xcconfig
def softlink_resources(source,target,use_ignoreDirs=True):
if not os.path.exists(target):
os.makedirs(target)
for file in os.listdir(source):
if (use_ignoreDirs and (file in ignoreDirs)) or (file in ignoreFiles):
continue
from_ = to_unicode_or_not(os.path.join(source, file))
to_ = to_unicode_or_not(os.path.join(target, file))
if os.path.isdir(from_):
print "[DEBUG] creating: %s" % (to_)
softlink_resources(from_,to_,use_ignoreDirs)
else:
print "[DEBUG] linking: %s to %s" % (from_,to_)
if os.path.exists(to_):
if os.path.islink(to_):
os.remove(to_)
os.symlink(from_, to_)
else:
os.symlink(from_, to_)
def clear_application_routing(classes_dir):
impf = open(os.path.join(classes_dir,'ApplicationRouting.m'),'w+')
impf.write(HEADER)
impf.write(IMPL_HEADER)
impf.write("+ (NSData*) resolveAppAsset:(NSString*)path;\n{\n")
impf.write(" return nil;\n")
impf.write('}\n')
impf.write(FOOTER)
impf.close()
def softlink_for_simulator(project_dir,app_dir):
resources_dir = os.path.join(project_dir,'Resources')
iphone_resources_dir = os.path.join(resources_dir,'iphone')
iphone_platform_dir = os.path.join(project_dir,'platform','iphone')
softlink_resources(resources_dir,app_dir)
if(os.path.exists(iphone_resources_dir)):
softlink_resources(iphone_resources_dir,app_dir,False)
dest_mod_dir = os.path.join(app_dir,'modules')
src_mod_dir = os.path.join(project_dir,'modules')
if(os.path.exists(src_mod_dir)):
softlink_resources(src_mod_dir,dest_mod_dir)
src_mod_iphone_dir = os.path.join(src_mod_dir,'iphone')
if(os.path.exists(src_mod_iphone_dir)):
softlink_resources(os.path.join(project_dir,'modules','iphone'),dest_mod_dir,False)
iphone_classes_dir = os.path.join(project_dir,'build','iphone','Classes')
clear_application_routing(iphone_classes_dir)
#
# TODO/FIXME
#
# - encryptor
#
class Compiler(object):
def __init__(self, project_dir, appid, name, deploytype):
self.deploytype = deploytype
self.project_dir = project_dir
self.project_name = name
self.appid = appid
if deploytype != 'export-build' and deploytype != 'commonjs':
self.iphone_dir = os.path.join(project_dir,'build','iphone')
else:
self.iphone_dir = project_dir
self.classes_dir = os.path.join(self.iphone_dir,'Classes')
self.assets_dir = os.path.join(self.iphone_dir,'assets')
self.modules = []
self.modules_metadata = []
self.exports = []
# for now, these are required
self.defines = ['USE_TI_ANALYTICS','USE_TI_NETWORK','USE_TI_PLATFORM','USE_TI_UI', 'USE_TI_API']
def compileProject(self,xcode=False,devicefamily='ios',iphone_version='iphoneos',silent=False,sdk=None):
tiapp_xml = os.path.join(self.project_dir,'tiapp.xml')
ti = TiAppXML(tiapp_xml)
if sdk is None:
sdk_version = os.path.basename(os.path.abspath(os.path.join(template_dir,'../')))
else:
sdk_version = sdk
if xcode:
app_name = os.environ['FULL_PRODUCT_NAME']
app_dir = os.path.join(os.environ['TARGET_BUILD_DIR'],os.environ['CONTENTS_FOLDER_PATH'])
else:
target = 'Debug'
if self.deploytype == 'production':
target = 'Release'
app_name = self.project_name+'.app'
app_folder_name = '%s-iphoneos' % target
app_dir = os.path.abspath(os.path.join(self.iphone_dir,'build',app_folder_name,app_name))
if not silent:
print "[INFO] Titanium SDK version: %s" % sdk_version
print "[INFO] iPhone Device family: %s" % devicefamily
print "[INFO] iPhone SDK version: %s" % iphone_version
if self.deploytype != 'export-build':
main_template_file = os.path.join(template_dir,'main.m')
main_template = codecs.open(main_template_file, encoding='utf-8').read()
main_template = main_template.replace('__PROJECT_NAME__',self.project_name)
main_template = main_template.replace('__PROJECT_ID__',self.appid)
main_template = main_template.replace('__DEPLOYTYPE__',self.deploytype)
main_template = main_template.replace('__APP_ID__',self.appid)
main_template = main_template.replace('__APP_ANALYTICS__',ti.properties['analytics'])
main_template = main_template.replace('__APP_PUBLISHER__',ti.properties['publisher'])
main_template = main_template.replace('__APP_URL__',ti.properties['url'])
main_template = main_template.replace('__APP_NAME__',ti.properties['name'])
main_template = main_template.replace('__APP_VERSION__',ti.properties['version'])
main_template = main_template.replace('__APP_DESCRIPTION__',ti.properties['description'])
main_template = main_template.replace('__APP_COPYRIGHT__',ti.properties['copyright'])
main_template = main_template.replace('__APP_GUID__',ti.properties['guid'])
main_template = main_template.replace('__APP_RESOURCE_DIR__','')
main_template_out = os.path.join(self.iphone_dir,'main.m')
main_file = codecs.open(main_template_out,'w+',encoding='utf-8')
main_file_contents = main_file.read()
if main_file_contents!=main_template:
main_file.write(main_template)
main_file.close()
resources_dir = os.path.join(self.project_dir,'Resources')
iphone_resources_dir = os.path.join(resources_dir,'iphone')
iphone_platform_dir = os.path.join(self.project_dir,'platform','iphone')
# copy in any resources in our module like icons
# NOTE: This means that any JS-only modules in the local project
# are hashed up and dumped into the export.
has_modules = False
missing_modules, modules, module_js = ([], [], [])
module_js_dir = os.path.join(self.project_dir,'modules')
if os.path.exists(module_js_dir):
for file in os.listdir(module_js_dir):
if file.endswith('.js'):
module_js.append({'from':os.path.join(module_js_dir,file),'to':os.path.join(app_dir,file),'path':'modules/'+file})
if self.deploytype != 'export-build':
# Have to load the module detection here, in order to
# prevent distributing even MORE stuff in export/transport
sys.path.append(os.path.join(template_dir,'../module'))
from module import ModuleDetector
detector = ModuleDetector(self.project_dir)
missing_modules, modules = detector.find_app_modules(ti, 'iphone', self.deploytype)
# we have to copy these even in simulator given the path difference
if os.path.exists(app_dir):
self.copy_resources([iphone_resources_dir],app_dir,False)
if os.path.exists(app_dir):
self.copy_resources([iphone_platform_dir],app_dir,False)
# generate the includes for all compiled modules
xcconfig_c = "// this is a generated file - DO NOT EDIT\n\n"
if len(modules) > 0:
mods = open(os.path.join(self.classes_dir,'ApplicationMods.m'),'w+')
variables = {}
mods.write(MODULE_IMPL_HEADER)
for module in modules:
if module.js:
# CommonJS module
module_js.append({'from': module.js, 'path': 'modules/' + os.path.basename(module.js)})
module_id = module.manifest.moduleid.lower()
module_name = module.manifest.name.lower()
module_version = module.manifest.version
module_guid = ''
module_licensekey = ''
if module.manifest.has_property('guid'):
module_guid = module.manifest.guid
if module.manifest.has_property('licensekey'):
module_licensekey = module.manifest.licensekey
self.modules_metadata.append({'guid':module_guid,'name':module_name,'id':module_id,'dir':module.path,'version':module_version,'licensekey':module_licensekey})
xcfile = module.get_resource('module.xcconfig')
if os.path.exists(xcfile):
xcconfig_contents = parse_xcconfig(xcfile, module_id, variables)
xcconfig_c += xcconfig_contents
xcfile = os.path.join(self.project_dir,'modules','iphone',"%s.xcconfig" % module_name)
if os.path.exists(xcfile):
xcconfig_contents = parse_xcconfig(xcfile, module_id, variables)
xcconfig_c += xcconfig_contents
mods.write(" [modules addObject:[NSDictionary dictionaryWithObjectsAndKeys:@\"%s\",@\"name\",@\"%s\",@\"moduleid\",@\"%s\",@\"version\",@\"%s\",@\"guid\",@\"%s\",@\"licensekey\",nil]];\n" % (module_name,module_id,module_version,module_guid,module_licensekey));
# Load export symbols from modules...
metadata_path = os.path.join(module.path, 'metadata.json')
if os.path.exists(metadata_path):
self.load_metadata(metadata_path)
mods.write(" return modules;\n")
mods.write("}\n")
mods.write(FOOTER)
mods.close()
for (name, values) in variables.iteritems():
xcconfig_c += name + '=$(inherited) '
for value in values:
xcconfig_c += '$(%s) ' % value
xcconfig_c += '\n'
has_modules = True
xcconfig = os.path.join(self.iphone_dir,"module.xcconfig")
make_xcc = True
if os.path.exists(xcconfig):
existing_xcc = open(xcconfig).read()
# only copy if different so we don't trigger re-compile in xcode
make_xcc = existing_xcc!=xcconfig_c
if make_xcc:
xcconfig = open(xcconfig,'w')
xcconfig.write(xcconfig_c)
xcconfig.close()
#endif deploytype != 'export-build'
else:
# ... And for exported projects, load export symbols from
# the 'metadata' dir.
metadata_dir = os.path.join(self.iphone_dir, 'metadata')
if os.path.isdir(metadata_dir):
for file in os.listdir(metadata_dir):
self.load_metadata(os.path.join(metadata_dir,file))
if self.deploytype=='simulator' or self.deploytype=='export':
shutil.copy(os.path.join(template_dir,'Classes','defines.h'),os.path.join(self.classes_dir,'defines.h'))
if self.deploytype!='development' or has_modules:
if os.path.exists(app_dir) and self.deploytype != 'development':
self.copy_resources([resources_dir],app_dir,self.deploytype != 'test',module_js)
if self.deploytype == 'production':
debugger_plist = os.path.join(app_dir,'debugger.plist')
if os.path.exists(debugger_plist):
os.remove(debugger_plist)
if self.deploytype!='development' and self.deploytype!='export':
defines_file = os.path.join(self.classes_dir, 'defines.h')
defines_header = open(defines_file,'w+')
defines_content = "// Warning: this is generated file. Do not modify!\n\n"
defines_content+= "#define TI_VERSION %s\n"%sdk_version
for sym in self.defines:
defines_content+="#define %s\n" % sym
if defines_content!=defines_header.read():
defines_header.write(defines_content)
defines_header.close()
# deploy any module image files
for module in self.modules:
img_dir = os.path.join(template_dir,'modules',module.lower(),'images')
print "[DEBUG] module image = %s" % img_dir
if not os.path.exists(img_dir): continue
dest_img_dir = os.path.join(app_dir,'modules',module.lower(),'images')
if not os.path.exists(dest_img_dir):
os.makedirs(dest_img_dir)
self.copy_resources([img_dir],dest_img_dir,False)
if self.deploytype!='development' and os.path.exists(app_dir):
# optimize PNGs - since we don't include them in the Resources of the xcodeproj
# the ones we copy in won't get optimized so we need to run it manually
# we can skip this on the simulator but should do it on device
dev_path = "/Developer"
# we need to ask xcode where the root path is
path = run.run(["/usr/bin/xcode-select","-print-path"],True,False)
if path:
dev_path = path.strip()
run.run(["%s/Platforms/iPhoneOS.platform/Developer/usr/bin/iphoneos-optimize"%dev_path,app_dir],False)
# remove empty directories
os.chdir(app_dir)
os.system("find . -type d -empty -delete")
else:
print "[INFO] Skipping JS compile, running from simulator"
if self.deploytype=='development':
softlink_for_simulator(self.project_dir,app_dir)
def compile_module(self):
module_properties = read_module_properties(self.project_dir)
appid_js_file = os.path.join(self.assets_dir, self.appid+'.js')
if not os.path.exists(appid_js_file):
appid_js_file = os.path.join(self.project_dir, '..', 'assets', self.appid+'.js')
root_asset = self.compile_commonjs_file(self.appid+'.js', appid_js_file)
js_files = []
for root, dirs, files in os.walk(self.assets_dir, True, None, True):
for file in [f for f in files if os.path.splitext(f)[1] == '.js']:
full_path = os.path.join(root, file)
self.compile_js_file(os.path.relpath(full_path, self.assets_dir), full_path, js_files)
template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
titanium_prep = os.path.abspath(os.path.join(template_dir,'titanium_prep'))
cmdinputfile = tempfile.TemporaryFile()
cmdinputfile.write('\n'.join(js_files))
cmdinputfile.seek(0)
module_assets = subprocess.Popen([titanium_prep, self.appid, self.assets_dir, module_properties['guid']], stdin=cmdinputfile,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).communicate()[0]
cmdinputfile.close()
# Clean up the generated assets
for file in js_files:
os.remove(os.path.join(self.assets_dir, file))
return (root_asset, module_assets)
def load_metadata(self, file):
module_metadata = open(file,'r')
metadata = json.load(module_metadata)
module_metadata.close()
for symbol in metadata['exports']:
self.add_symbol(symbol)
def add_symbol(self,api):
print "[DEBUG] detected symbol: %s" % api
curtoken = ''
tokens = api.split(".")
try:
self.modules.index(tokens[0])
except:
self.modules.append(tokens[0])
for token in tokens:
curtoken+=token+"."
symbol = 'USE_TI_%s' % (curtoken.replace('.create','').replace('.','').replace('-','_').upper())
try:
self.defines.index(symbol)
except:
self.defines.append(symbol)
def extract_tokens(self,sym,line):
# sloppy joe parsing coooode
# could be prettier and faster but it works and rather reliable
c = 0
tokens = []
search = sym + "."
size = len(search)
while True:
i = line.find(search,c)
if i < 0:
break
found = False
buf = ''
x = 0
for n in line[i+size:]:
# look for a terminal - this could probably be easier
if n in ['(',')','{','}','=',',',' ',':','!','[',']','+','*','/','~','^','%','\n','\t','\r']:
found = True
break
buf+=n
x+=1
tokens.append(buf)
if found:
c = i + x + 1
continue
break
return sorted(set(tokens))
def compile_js(self,file_contents):
for line in file_contents.split(';'):
for symbol in ('Titanium','Ti'):
for sym in self.extract_tokens(symbol,line):
self.add_symbol(sym)
self.exports.append(sym)
def process_html_files(self,data,source_root):
compile = []
if data.has_key('.js'):
for entry in data['.html']:
html_file = entry['from']
file_contents = open(os.path.expanduser(html_file)).read()
parser = HTMLParser()
parser.parse(file_contents)
# extract all our scripts that are dependencies and we
# don't compile these
scripts = parser.get_scripts()
if len(scripts) > 0:
js_files = data['.js']
for script in scripts:
# if a remote script, ignore
if script.startswith('http:') or script.startswith('https:'):
continue
if script.startswith('app://'):
script = script[6:]
# build a file relative to the html file
fullpath = os.path.abspath(os.path.join(os.path.dirname(html_file),script))
# remove this script from being compiled
for f in js_files:
if f['from']==fullpath:
# target it to be compiled
compile.append(f)
js_files.remove(f)
break
return compile
def compile_js_asset_file(self,path,file):
file_contents = open(os.path.expanduser(file)).read()
if self.deploytype == 'production' or self.deploytype == 'commonjs':
file_contents = jspacker.jsmin(file_contents)
file_contents = file_contents.replace('Titanium.','Ti.')
self.compile_js(file_contents)
path = os.path.join(self.assets_dir,path)
dir = os.path.dirname(path)
if not os.path.exists(dir):
os.makedirs(dir)
tfile = open(path,'w+')
tfile.write(file_contents)
tfile.close()
# TODO: We should remove this when we can "safely" say we no longer support
# versions prior to 2.1, and also change the module loader code in iOS to
# no longer check for moduleAsset.
def compile_commonjs_file(self,path,from_):
js_files = []
self.compile_js_file(path, from_, js_files)
template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
titanium_prep = os.path.abspath(os.path.join(template_dir,'titanium_prep'))
cmdinputfile = tempfile.TemporaryFile()
cmdinputfile.write('\n'.join(js_files))
cmdinputfile.seek(0)
so = subprocess.Popen([titanium_prep, self.appid, self.assets_dir], stdin=cmdinputfile,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).communicate()[0]
cmdinputfile.close()
return so
def compile_js_file(self, path, from_, js_files):
print "[DEBUG] compiling: %s" % from_
path = path.replace('.','_')
self.compile_js_asset_file(path,from_)
js_files.append(path);
def copy_resources(self,sources,target,write_routing=True,module_js=[]):
js_files = []
if write_routing:
intf = open(os.path.join(self.classes_dir,'ApplicationRouting.h'),'w+')
impf = open(os.path.join(self.classes_dir,'ApplicationRouting.m'),'w+')
intf.write(HEADER)
intf.write(INTERFACE_HEADER)
impf.write(HEADER)
impf.write(IMPL_HEADER)
impf.write("+ (NSData*) resolveAppAsset:(NSString*)path;\n{\n")
if not os.path.exists(os.path.expanduser(target)):
os.makedirs(os.path.expanduser(target))
if not os.path.exists(self.assets_dir):
os.makedirs(self.assets_dir)
def compile_js_file(path,from_):
year, month, day, hour, minute, second, weekday, yearday, daylight = time.localtime(time.time())
print "[DEBUG] (%02d:%02d:%02d) compiling: %s" % (hour, minute, second, from_)
path = path.replace('.','_')
self.compile_js_asset_file(path,from_)
js_files.append(path);
def compile_js_files():
year, month, day, hour, minute, second, weekday, yearday, daylight = time.localtime(time.time())
print "[DEBUG] (%02d:%02d:%02d) packaging javascript" % (hour, minute, second)
template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
titanium_prep = os.path.abspath(os.path.join(template_dir,'titanium_prep'))
cmdinputfile = tempfile.TemporaryFile()
cmdinputfile.write('\n'.join(js_files))
cmdinputfile.seek(0)
so = subprocess.Popen([titanium_prep, self.appid, self.assets_dir], stdin=cmdinputfile,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).communicate()[0]
cmdinputfile.close()
impf.write(so)
year, month, day, hour, minute, second, weekday, yearday, daylight = time.localtime(time.time())
print "[DEBUG] (%02d:%02d:%02d) packaging finished" % (hour, minute, second)
def add_compiled_resources(source,target):
print "[DEBUG] copy resources from %s to %s" % (source,target)
compiled_targets = {}
for root, dirs, files in os.walk(source, True, None, True):
for name in ignoreDirs:
if name in dirs:
dirs.remove(name) # don't visit ignored directories
for file in files:
if file in ignoreFiles:
continue
prefix = root[len(source):]
from_ = to_unicode_or_not(os.path.join(root, file))
to_ = os.path.expanduser(from_.replace(source, target, 1))
to_directory = os.path.expanduser(os.path.split(to_)[0])
if not os.path.exists(to_directory):
os.makedirs(to_directory)
fp = os.path.splitext(file)
ext = fp[1]
if ext == '.jss': continue
if len(fp)>1 and ext in ['.html','.js','.css']:
path = prefix + os.sep + file
path = path[1:]
entry = {'path':path,'from':from_,'to':to_}
if compiled_targets.has_key(ext):
compiled_targets[ext].append(entry)
else:
compiled_targets[ext]=[entry]
if not (write_routing and len(fp)>1 and ext in ['.html','.js','.css']):
# only copy if different filesize or doesn't exist
if not os.path.exists(to_) or os.path.getsize(from_)!=os.path.getsize(to_):
print "[DEBUG] copying: %s to %s" % (from_,to_)
shutil.copyfile(from_, to_)
if compiled_targets.has_key('.html'):
compiled = self.process_html_files(compiled_targets,source)
if len(compiled) > 0:
for c in compiled:
from_ = c['from']
to_ = c['to']
path = c['path']
print "[DEBUG] copying: %s to %s" % (from_,to_)
file_contents = open(from_).read()
file_contents = jspacker.jsmin(file_contents)
file_contents = file_contents.replace('Titanium.','Ti.')
to = open(to_,'w')
to.write(file_contents)
to.close()
for ext in ('.css','.html'):
if compiled_targets.has_key(ext):
for css_file in compiled_targets[ext]:
from_ = css_file['from']
to_ = css_file['to']
print "[DEBUG] copying: %s to %s" % (from_,to_)
if path.endswith('.css'):
file_contents = open(from_).read()
packer = CSSPacker(file_contents)
file_contents = packer.pack()
to = open(to_,'w')
to.write(file_contents)
to.close()
else:
shutil.copyfile(from_, to_)
if compiled_targets.has_key('.js'):
for js_file in compiled_targets['.js']:
path = js_file['path']
from_ = js_file['from']
compile_js_file(path, from_)
# copy in any module assets
for metadata in self.modules_metadata:
tp_dir = os.path.join(metadata['dir'],'assets')
if not os.path.exists(tp_dir): continue
tp_id = metadata['id']
t = '%s/modules/%s' %(target,tp_id)
add_compiled_resources(tp_dir,t)
for source in sources:
add_compiled_resources(source,target)
for js_file in module_js:
compile_js_file(js_file['path'], js_file['from'])
if write_routing:
compile_js_files();
impf.write("\tNSNumber *index = [map objectForKey:path];\n")
impf.write("\tif (index == nil) { return nil; }\n")
impf.write("\treturn filterDataInRange([NSData dataWithBytesNoCopy:data length:sizeof(data) freeWhenDone:NO], ranges[index.integerValue]);\n")
impf.write('}\n')
intf.write(FOOTER)
impf.write(FOOTER)
intf.close()
impf.close()
if __name__ == "__main__":
argv = sys.argv
if len(argv) < 3:
print "[USAGE] %s <dir> <deploytype> [devicetype] [ios_version] [sdk_version]" % argv[0]
exit(1)
project_dir = argv[1]
deploytype = argv[2]
if deploytype == 'export-build':
xcode = True
else:
xcode = False
if len(argv) >= 4:
devicefamily = argv[3]
else:
devicefamily = 'unknown'
if len(argv) >= 5:
ios = argv[4]
else:
ios = 'unknown'
if len(argv) >= 6:
sdk = argv[5]
else:
sdk = None
tiapp_xml = os.path.join(project_dir,'tiapp.xml')
ti = TiAppXML(tiapp_xml)
appid = ti.properties['id']
name = ti.properties['name']
c = Compiler(project_dir,appid,name,deploytype)
c.compileProject(xcode,devicefamily,ios,sdk=sdk)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
7290,
27154,
199,
3,
199,
199,
646,
747,
12,
984,
12,
295,
12,
5145,
12,
900,
12,
1255,
12,
12578,
25598,
12,
6010,
12,
5549,
12,
3873,
199,
199,
1160,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
1274,
423,
20912,
8,
16,
680,
70,
63,
600,
14,
331,
63,
1501,
430,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1160,
63,
694,
2584,
703,
7058,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1160,
63,
694,
2584,
703,
297,
283,
2330,
7058,
199,
199,
504,
3367,
571,
492,
627,
199,
646,
8586,
1389,
281,
199,
504,
11431,
1389,
281,
492,
15750,
2305,
281,
199,
646,
5190,
199,
199,
893,
26,
199,
198,
646,
2022,
199,
2590,
26,
199,
198,
646,
13804,
465,
2022,
199,
199,
4247,
5535,
275,
18953,
71,
5277,
7160,
297,
1987,
5107,
1037,
720,
297,
1987,
3177,
63,
5502,
297,
2513,
6836,
418,
27,
199,
4247,
17051,
275,
788,
28303,
297,
283,
6238,
297,
283,
11375,
2520,
297,
1987,
3187,
297,
1987,
6836,
297,
283,
35,
7428,
418,
27,
199,
199,
7311,
275,
408,
15,
538,
199,
627,
4693,
27139,
377,
390,
290,
5170,
29724,
199,
627,
961,
365,
4046,
1233,
14,
4226,
440,
2811,
14,
19519,
4493,
627,
14117,
10,
506,
14669,
14,
199,
627,
17065,
1233,
365,
1898,
334,
67,
9,
8937,
13,
7409,
701,
4693,
27139,
12,
3277,
14,
199,
627,
2900,
5924,
5702,
14,
199,
11589,
199,
3,
646,
665,
30216,
15,
30216,
14,
72,
30,
199,
624,
199,
199,
17598,
63,
7311,
29,
408,
199,
32,
3266,
13515,
8056,
520,
9380,
1692,
469,
199,
93,
199,
11,
334,
2709,
1451,
13278,
7512,
2640,
19979,
20334,
2709,
1558,
13278,
515,
27,
199,
624,
199,
199,
26312,
63,
7311,
29,
408,
3,
646,
298,
5039,
8056,
14,
72,
2,
199,
199,
18587,
9380,
1451,
10,
2457,
1451,
607,
4709,
8,
2709,
1451,
10,
314,
576,
12,
9380,
4709,
1425,
2736,
199,
199,
32,
12236,
13515,
8056,
199,
199,
624,
199,
199,
13046,
1157,
275,
624,
199,
32,
500,
199,
624,
199,
199,
10001,
63,
26312,
63,
7311,
275,
408,
3,
646,
298,
5039,
9871,
83,
14,
72,
2,
199,
199,
32,
12236,
13515,
9871,
83,
199,
199,
11,
334,
2709,
3836,
13278,
10311,
9871,
83,
199,
91,
199,
198,
2709,
17707,
3836,
627,
3112,
275,
359,
2709,
17707,
3836,
1625,
11566,
199,
624,
199,
199,
533,
24581,
8,
1226,
25598,
14,
4254,
1698,
2842,
304,
339,
347,
2198,
8,
277,
12,
308,
304,
267,
291,
14,
3871,
8,
83,
9,
267,
291,
14,
1600,
342,
339,
347,
636,
826,
721,
277,
12,
3376,
29,
16,
304,
267,
12578,
25598,
14,
4254,
1698,
2842,
855,
826,
721,
277,
12,
3376,
9,
267,
291,
14,
6429,
275,
942,
339,
347,
1343,
63,
1579,
8,
277,
12,
3004,
304,
267,
367,
536,
12,
574,
315,
3004,
26,
288,
340,
536,
508,
298,
2164,
582,
355,
291,
14,
6429,
14,
740,
8,
585,
9,
339,
347,
664,
63,
6429,
8,
277,
304,
267,
372,
291,
14,
6429,
199,
199,
318,
1586,
63,
578,
63,
3282,
8,
694,
304,
199,
198,
493,
275,
747,
14,
515,
14,
904,
8,
694,
2584,
6418,
358,
199,
198,
807,
275,
1052,
199,
198,
692,
747,
14,
515,
14,
2444,
8,
493,
304,
507,
198,
4407,
275,
1551,
8,
493,
680,
739,
342,
507,
198,
509,
1004,
315,
4072,
14,
7644,
8,
549,
304,
686,
198,
692,
1004,
59,
16,
26,
17,
22954,
24397,
1980,
686,
198,
2996,
275,
1004,
14,
1623,
11633,
686,
198,
692,
4280,
389,
13,
17,
26,
1980,
686,
198,
75,
29,
604,
59,
16,
26,
2996,
61,
686,
198,
86,
29,
604,
59,
2996,
11,
17,
11455,
1913,
342,
686,
198,
807,
59,
75,
10404,
86,
199,
198,
1107,
1211,
199,
199,
3,
7306,
2222,
13,
2975,
1559,
370,
2649,
5737,
315,
2774,
13,
24,
14,
199,
318,
370,
63,
2975,
63,
269,
63,
1397,
8,
1113,
12,
2644,
534,
1624,
13,
24,
735,
199,
198,
692,
1228,
8,
1113,
12,
7116,
304,
507,
198,
692,
440,
1228,
8,
1113,
12,
2649,
304,
686,
198,
1113,
275,
2649,
8,
1113,
12,
2644,
9,
199,
198,
1107,
1559,
199,
199,
3,
14012,
370,
876,
13,
1122,
20399,
888,
1584,
370,
333,
4593,
1750,
1561,
12,
436,
2066,
199,
3,
5461,
3062,
1901,
282,
2341,
880,
626,
781,
883,
295,
13,
21263,
3062,
2945,
199,
318,
2198,
63,
1812,
888,
8,
1812,
888,
12,
859,
1304,
12,
2860,
304,
199,
198,
578,
63,
1812,
888,
275,
1551,
8,
1812,
888,
9,
199,
198,
1222,
63,
1812,
888,
275,
2125,
199,
198,
1832,
63,
3669,
275,
1052,
421,
198,
1861,
275,
859,
1304,
14,
4142,
1252,
1814,
5175,
1673,
15452,
199,
198,
509,
1004,
315,
859,
63,
1812,
888,
26,
507,
198,
3,
19828,
6786,
507,
198,
3349,
275,
1004,
14,
1623,
15079,
358,
507,
198,
692,
3721,
1137,
446,
17,
26,
686,
198,
604,
275,
1004,
59,
16,
26,
3349,
61,
2742,
198,
3,
7958,
892,
22071,
1182,
574,
4092,
780,
507,
198,
3,
710,
5578,
3965,
19953,
282,
1686,
1004,
1901,
7323,
507,
198,
3,
257,
665,
1391,
8119,
28,
585,
30,
507,
198,
3,
257,
665,
1391,
9514,
28,
498,
8119,
28,
498,
585,
30,
10404,
28,
585,
30,
507,
198,
3,
257,
325,
14,
71,
14,
507,
198,
3,
258,
5010,
63,
22328,
4022,
4857,
6763,
14591,
507,
198,
3,
258,
5010,
63,
22328,
59,
9277,
29,
28303,
736,
20,
30431,
4022,
317,
5598,
507,
198,
1294,
604,
275,
295,
14,
1294,
14097,
21690,
59,
29,
2807,
10127,
59,
16045,
2677,
7896,
566,
17076,
9000,
31,
26534,
6977,
3196,
1004,
9,
2742,
198,
692,
822,
8,
1294,
604,
9,
2356,
959,
26,
686,
198,
16043,
275,
3715,
604,
59,
17,
61,
686,
198,
585,
275,
3715,
604,
59,
20,
61,
6319,
198,
354,
275,
2403,
435,
14135,
435,
22071,
14,
1913
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
7290,
27154,
199,
3,
199,
199,
646,
747,
12,
984,
12,
295,
12,
5145,
12,
900,
12,
1255,
12,
12578,
25598,
12,
6010,
12,
5549,
12,
3873,
199,
199,
1160,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
1274,
423,
20912,
8,
16,
680,
70,
63,
600,
14,
331,
63,
1501,
430,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1160,
63,
694,
2584,
703,
7058,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
1160,
63,
694,
2584,
703,
297,
283,
2330,
7058,
199,
199,
504,
3367,
571,
492,
627,
199,
646,
8586,
1389,
281,
199,
504,
11431,
1389,
281,
492,
15750,
2305,
281,
199,
646,
5190,
199,
199,
893,
26,
199,
198,
646,
2022,
199,
2590,
26,
199,
198,
646,
13804,
465,
2022,
199,
199,
4247,
5535,
275,
18953,
71,
5277,
7160,
297,
1987,
5107,
1037,
720,
297,
1987,
3177,
63,
5502,
297,
2513,
6836,
418,
27,
199,
4247,
17051,
275,
788,
28303,
297,
283,
6238,
297,
283,
11375,
2520,
297,
1987,
3187,
297,
1987,
6836,
297,
283,
35,
7428,
418,
27,
199,
199,
7311,
275,
408,
15,
538,
199,
627,
4693,
27139,
377,
390,
290,
5170,
29724,
199,
627,
961,
365,
4046,
1233,
14,
4226,
440,
2811,
14,
19519,
4493,
627,
14117,
10,
506,
14669,
14,
199,
627,
17065,
1233,
365,
1898,
334,
67,
9,
8937,
13,
7409,
701,
4693,
27139,
12,
3277,
14,
199,
627,
2900,
5924,
5702,
14,
199,
11589,
199,
3,
646,
665,
30216,
15,
30216,
14,
72,
30,
199,
624,
199,
199,
17598,
63,
7311,
29,
408,
199,
32,
3266,
13515,
8056,
520,
9380,
1692,
469,
199,
93,
199,
11,
334,
2709,
1451,
13278,
7512,
2640,
19979,
20334,
2709,
1558,
13278,
515,
27,
199,
624,
199,
199,
26312,
63,
7311,
29,
408,
3,
646,
298,
5039,
8056,
14,
72,
2,
199,
199,
18587,
9380,
1451,
10,
2457,
1451,
607,
4709,
8,
2709,
1451,
10,
314,
576,
12,
9380,
4709,
1425,
2736,
199,
199,
32,
12236,
13515,
8056,
199,
199,
624,
199,
199,
13046,
1157,
275,
624,
199,
32,
500,
199,
624,
199,
199,
10001,
63,
26312,
63,
7311,
275,
408,
3,
646,
298,
5039,
9871,
83,
14,
72,
2,
199,
199,
32,
12236,
13515,
9871,
83,
199,
199,
11,
334,
2709,
3836,
13278,
10311,
9871,
83,
199,
91,
199,
198,
2709,
17707,
3836,
627,
3112,
275,
359,
2709,
17707,
3836,
1625,
11566,
199,
624,
199,
199,
533,
24581,
8,
1226,
25598,
14,
4254,
1698,
2842,
304,
339,
347,
2198,
8,
277,
12,
308,
304,
267,
291,
14,
3871,
8,
83,
9,
267,
291,
14,
1600,
342,
339,
347,
636,
826,
721,
277,
12,
3376,
29,
16,
304,
267,
12578,
25598,
14,
4254,
1698,
2842,
855,
826,
721,
277,
12,
3376,
9,
267,
291,
14,
6429,
275,
942,
339,
347,
1343,
63,
1579,
8,
277,
12,
3004,
304,
267,
367,
536,
12,
574,
315,
3004,
26,
288,
340,
536,
508,
298,
2164,
582,
355,
291,
14,
6429,
14,
740,
8,
585,
9,
339,
347,
664,
63,
6429,
8,
277,
304,
267,
372,
291,
14,
6429,
199,
199,
318,
1586,
63,
578,
63,
3282,
8,
694,
304,
199,
198,
493,
275,
747,
14,
515,
14,
904,
8,
694,
2584,
6418,
358,
199,
198,
807,
275,
1052,
199,
198,
692,
747,
14,
515,
14,
2444,
8,
493,
304,
507,
198,
4407,
275,
1551,
8,
493,
680,
739,
342,
507,
198,
509,
1004,
315,
4072,
14,
7644,
8,
549,
304,
686,
198,
692,
1004,
59,
16,
26,
17,
22954,
24397,
1980,
686,
198,
2996,
275,
1004,
14,
1623,
11633,
686,
198,
692,
4280,
389,
13,
17,
26,
1980,
686,
198,
75,
29,
604,
59,
16,
26,
2996,
61,
686,
198,
86,
29,
604,
59,
2996,
11,
17,
11455,
1913,
342,
686,
198,
807,
59,
75,
10404,
86,
199,
198,
1107,
1211,
199,
199,
3,
7306,
2222,
13,
2975,
1559,
370,
2649,
5737,
315,
2774,
13,
24,
14,
199,
318,
370,
63,
2975,
63,
269,
63,
1397,
8,
1113,
12,
2644,
534,
1624,
13,
24,
735,
199,
198,
692,
1228,
8,
1113,
12,
7116,
304,
507,
198,
692,
440,
1228,
8,
1113,
12,
2649,
304,
686,
198,
1113,
275,
2649,
8,
1113,
12,
2644,
9,
199,
198,
1107,
1559,
199,
199,
3,
14012,
370,
876,
13,
1122,
20399,
888,
1584,
370,
333,
4593,
1750,
1561,
12,
436,
2066,
199,
3,
5461,
3062,
1901,
282,
2341,
880,
626,
781,
883,
295,
13,
21263,
3062,
2945,
199,
318,
2198,
63,
1812,
888,
8,
1812,
888,
12,
859,
1304,
12,
2860,
304,
199,
198,
578,
63,
1812,
888,
275,
1551,
8,
1812,
888,
9,
199,
198,
1222,
63,
1812,
888,
275,
2125,
199,
198,
1832,
63,
3669,
275,
1052,
421,
198,
1861,
275,
859,
1304,
14,
4142,
1252,
1814,
5175,
1673,
15452,
199,
198,
509,
1004,
315,
859,
63,
1812,
888,
26,
507,
198,
3,
19828,
6786,
507,
198,
3349,
275,
1004,
14,
1623,
15079,
358,
507,
198,
692,
3721,
1137,
446,
17,
26,
686,
198,
604,
275,
1004,
59,
16,
26,
3349,
61,
2742,
198,
3,
7958,
892,
22071,
1182,
574,
4092,
780,
507,
198,
3,
710,
5578,
3965,
19953,
282,
1686,
1004,
1901,
7323,
507,
198,
3,
257,
665,
1391,
8119,
28,
585,
30,
507,
198,
3,
257,
665,
1391,
9514,
28,
498,
8119,
28,
498,
585,
30,
10404,
28,
585,
30,
507,
198,
3,
257,
325,
14,
71,
14,
507,
198,
3,
258,
5010,
63,
22328,
4022,
4857,
6763,
14591,
507,
198,
3,
258,
5010,
63,
22328,
59,
9277,
29,
28303,
736,
20,
30431,
4022,
317,
5598,
507,
198,
1294,
604,
275,
295,
14,
1294,
14097,
21690,
59,
29,
2807,
10127,
59,
16045,
2677,
7896,
566,
17076,
9000,
31,
26534,
6977,
3196,
1004,
9,
2742,
198,
692,
822,
8,
1294,
604,
9,
2356,
959,
26,
686,
198,
16043,
275,
3715,
604,
59,
17,
61,
686,
198,
585,
275,
3715,
604,
59,
20,
61,
6319,
198,
354,
275,
2403,
435,
14135,
435,
22071,
14,
1913,
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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>
#
# This file is part of EditXT, a programmer's text editor for Mac OS X,
# which can be found at http://editxt.org/.
#
# EditXT 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.
#
# EditXT 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 EditXT. If not, see <http://www.gnu.org/licenses/>.
import sys
from importlib import import_module
from logging import StreamHandler as console_log_handler
def init(platform, use_pdb):
modules = [
"constants",
"logging",
"main",
"kvo",
"alert",
"app",
"font",
"document",
"events",
"fileref",
"markdown",
"pasteboard",
"text",
"ui.findpanel",
"views",
"window",
]
import_module("{}.{}".format(__name__, platform))
main = import_module("{}.{}.main".format(__name__, platform))
main.init(use_pdb)
self = sys.modules[__name__]
for name in modules:
module = import_module("{}.{}.{}".format(__name__, platform, name))
sys.modules[__name__ + "." + name] = module
setattr(self, name, module)
if not sys.stderr.isatty():
self.console_log_handler = self.logging.PlatformLogHandler
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
16407,
18926,
199,
3,
1898,
10219,
13,
6965,
24747,
14769,
603,
19576,
665,
77,
19576,
2374,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
16407,
18926,
12,
282,
2240,
2626,
1159,
1318,
8823,
367,
10444,
4403,
1323,
12,
199,
3,
1314,
883,
506,
1911,
737,
1455,
921,
3773,
400,
14,
1308,
8083,
199,
3,
199,
3,
16407,
18926,
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,
16407,
18926,
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,
16407,
18926,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
646,
984,
199,
504,
14802,
492,
492,
63,
578,
199,
504,
2050,
492,
8271,
2461,
465,
8559,
63,
793,
63,
2232,
421,
199,
318,
4205,
8,
3246,
12,
675,
63,
10511,
304,
272,
4621,
275,
359,
267,
298,
5559,
401,
267,
298,
4806,
401,
267,
298,
973,
401,
267,
298,
75,
2392,
401,
398,
298,
9241,
401,
267,
298,
571,
401,
267,
298,
4246,
401,
267,
298,
3554,
401,
267,
298,
4368,
401,
267,
298,
493,
1121,
401,
267,
298,
15653,
401,
267,
298,
16586,
3576,
401,
267,
298,
505,
401,
267,
298,
1907,
14,
1623,
7885,
401,
267,
298,
4196,
401,
267,
298,
3806,
401,
272,
1622,
339,
492,
63,
578,
20794,
14,
13536,
908,
3460,
354,
3108,
4298,
430,
272,
2446,
275,
492,
63,
578,
20794,
14,
31270,
973,
1674,
908,
3460,
354,
3108,
4298,
430,
272,
2446,
14,
826,
8,
1180,
63,
10511,
9,
339,
291,
275,
984,
14,
3112,
28894,
354,
22705,
272,
367,
536,
315,
4621,
26,
267,
859,
275,
492,
63,
578,
20794,
14,
31270,
13536,
908,
3460,
354,
3108,
4298,
12,
536,
430,
267,
984,
14,
3112,
28894,
354,
363,
435,
14530,
435,
536,
61,
275,
859,
267,
5371,
8,
277,
12,
536,
12,
859,
9,
339,
340,
440,
984,
14,
3083,
14,
21122,
837,
267,
291,
14,
6614,
63,
793,
63,
2232,
275,
291,
14,
4806,
14,
10397,
2445,
2461,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
16407,
18926,
199,
3,
1898,
10219,
13,
6965,
24747,
14769,
603,
19576,
665,
77,
19576,
2374,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
16407,
18926,
12,
282,
2240,
2626,
1159,
1318,
8823,
367,
10444,
4403,
1323,
12,
199,
3,
1314,
883,
506,
1911,
737,
1455,
921,
3773,
400,
14,
1308,
8083,
199,
3,
199,
3,
16407,
18926,
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,
16407,
18926,
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,
16407,
18926,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
646,
984,
199,
504,
14802,
492,
492,
63,
578,
199,
504,
2050,
492,
8271,
2461,
465,
8559,
63,
793,
63,
2232,
421,
199,
318,
4205,
8,
3246,
12,
675,
63,
10511,
304,
272,
4621,
275,
359,
267,
298,
5559,
401,
267,
298,
4806,
401,
267,
298,
973,
401,
267,
298,
75,
2392,
401,
398,
298,
9241,
401,
267,
298,
571,
401,
267,
298,
4246,
401,
267,
298,
3554,
401,
267,
298,
4368,
401,
267,
298,
493,
1121,
401,
267,
298,
15653,
401,
267,
298,
16586,
3576,
401,
267,
298,
505,
401,
267,
298,
1907,
14,
1623,
7885,
401,
267,
298,
4196,
401,
267,
298,
3806,
401,
272,
1622,
339,
492,
63,
578,
20794,
14,
13536,
908,
3460,
354,
3108,
4298,
430,
272,
2446,
275,
492,
63,
578,
20794,
14,
31270,
973,
1674,
908,
3460,
354,
3108,
4298,
430,
272,
2446,
14,
826,
8,
1180,
63,
10511,
9,
339,
291,
275,
984,
14,
3112,
28894,
354,
22705,
272,
367,
536,
315,
4621,
26,
267,
859,
275,
492,
63,
578,
20794,
14,
31270,
13536,
908,
3460,
354,
3108,
4298,
12,
536,
430,
267,
984,
14,
3112,
28894,
354,
363,
435,
14530,
435,
536,
61,
275,
859,
267,
5371,
8,
277,
12,
536,
12,
859,
9,
339,
340,
440,
984,
14,
3083,
14,
21122,
837,
267,
291,
14,
6614,
63,
793,
63,
2232,
275,
291,
14,
4806,
14,
10397,
2445,
2461,
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,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0,
0,
0,
0,
0,
0,
0,
0
] |
cpn18/track-chart
|
gps-pi/combolog4_fft.py
|
1
|
4482
|
#!/usr/bin/python
import gps
import math
import datetime
import threading
#import the adxl345 module
import adxl345
import time
import greatcircle
import numpy as np
import scipy.fftpack
lock = threading.Lock()
gpstime = ""
def gps_logger():
global inSync,gpstime
logging = False
# feet
threshold = 25
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
lastlon=9999
lastlat=9999
d = datetime.datetime.utcnow()
lasttime=d.strftime("%Y-%m-%dT%H:%M:%S.000Z")
x=0
y=0
z=9.807
count=0
while True:
try:
# GPS
report = session.next()
# Wait for a 'TPV' report and display the current time
# To see all report data, uncomment the line below
#print report
systime = time.time()
if report['class'] == 'TPV':
if hasattr(report, 'lat') and hasattr(report, 'lon') and hasattr(report, 'time'):
gpstime = report.time
inSync=1
if lastlon == 9999:
lastlon = report.lon
lastlat = report.lat
lasttime = report.time
logging = True
lastsystime = systime
d = greatcircle.distance(lastlon,lastlat,report.lon,report.lat) * 0.621371 * 5280
if (lastsystime != systime):
speed = d / (systime - lastsystime)
else:
speed = 0
b = math.degrees(greatcircle.bearing(lastlon,lastlat,report.lon,report.lat))
if b < 0:
b += 360.0
if hasattr(report, 'alt'):
a = report.alt * 3.28084
else:
a = 0
if (count % 60 == 0 or d >= threshold) and logging == True:
lock.acquire()
print ( "%f %s G % 02.6f % 03.6f %03f %01.3f %01.3f %03.1f *" % (systime,report.time,report.lat,report.lon,a,d,speed,b))
lock.release()
lastlon = report.lon
lastlat = report.lat
lasttime = report.time
count = 0
count += 1
except KeyError:
pass
except KeyboardInterrupt:
quit()
except StopIteration:
session = None
print "GPSD has terminated"
def fft(xa,xv,N,T):
yf = scipy.fftpack.fft(np.array(xv))
py = 2.0/N * np.abs(yf[:N//2])
xf = np.linspace(0.0,1.0/(2.0*T),N/2)
a = np.argmax(py)
return (xf[a],py[a])
def accel_logger():
global inSync,gpstime
#create ADXL345 object
accel = adxl345.ADXL345()
xv = []
yv = []
zv = []
x0 = x1 = x2 = 0
y0 = y1 = y2 = 0
z0 = z1 = z2 = 0
c = 0
lasttime=""
while True:
try:
if inSync == 0:
time.sleep(5)
continue
#get axes as g
#axes = accel.getAxes(True)
# to get axes as ms^2 use
axes = accel.getAxes(False)
#put the axes into variables
x = axes['x']
xv.append(x)
y = axes['y']
yv.append(y)
z = axes['z']
zv.append(z)
x1 += x
y1 += y
z1 += z
if x > x2:
x2 = x
if y > y2:
y2 = y
if z > z2:
z2 = z
if x < x0:
x0 = x
if y < y0:
y0 = y
if z < z0:
z0 = z
c += 1
d = datetime.datetime.utcnow()
now=d.strftime("%Y-%m-%dT%H:%M:%S.000Z")
if now != lasttime:
lasttime=now
if c > 1:
N = c
T = 1.0 / N
ls = np.linspace(0.0,1.0,N)
(ax1,ay1) = fft(ls,xv,N,T)
(ax2,ay2) = fft(ls,yv,N,T)
(ax3,ay3) = fft(ls,zv,N,T)
lock.acquire()
print "%f %s R %d %f %f %f %f %f %f *" % (time.time(),gpstime,c,ax1,ay1,ax2,ay2,ax3,ay3)
lock.release()
x1 = x1/c
y1 = y1/c
z1 = z1/c
lock.acquire()
#print ("%f %s A %d % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f *" % (time.time(),gpstime,c,x0,x1,x2,y0,y1,y2,z0,z1,z2))
lock.release()
x2 = -10
x0 = 10
y2 = -10
y0 = 10
z2 = -10
z0 = 10
c = 0
xv = []
except KeyboardInterrupt:
quit()
# MAIN START
inSync=0
print ""
print "#v4"
try:
t1 = threading.Thread(target=gps_logger, args=())
t1.start()
t2 = threading.Thread(target=accel_logger, args=())
t2.start()
except:
print "Error: unable to start thread"
exit
t1.join()
t2.join()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
486,
1190,
199,
646,
3473,
199,
646,
2197,
199,
646,
5796,
199,
3,
646,
314,
1503,
15455,
9908,
859,
199,
646,
1503,
15455,
9908,
199,
646,
900,
199,
646,
27254,
11001,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
9996,
1389,
199,
199,
831,
275,
5796,
14,
6432,
342,
199,
4927,
7696,
275,
3087,
199,
199,
318,
486,
1190,
63,
2921,
837,
523,
2288,
315,
10878,
12,
4927,
7696,
523,
2050,
275,
756,
819,
327,
1964,
386,
523,
8765,
275,
5661,
819,
327,
491,
7938,
641,
1844,
7349,
2417,
334,
25556,
68,
9,
402,
11667,
523,
2351,
275,
486,
1190,
14,
25556,
480,
5967,
401,
298,
1398,
2417,
531,
523,
2351,
14,
1745,
8,
25556,
14,
55,
8078,
63,
8898,
1204,
486,
1190,
14,
55,
8078,
63,
11365,
18466,
9,
819,
2061,
5298,
29,
5008,
523,
2061,
4452,
29,
5008,
523,
366,
275,
2197,
14,
2083,
14,
10779,
342,
523,
2061,
521,
29,
68,
14,
6205,
3647,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
14,
1493,
58,
531,
523,
671,
29,
16,
523,
612,
29,
16,
523,
1315,
29,
25,
14,
11369,
523,
2338,
29,
16,
523,
1830,
715,
26,
272,
862,
26,
267,
327,
598,
5067,
1362,
198,
3070,
275,
2351,
14,
2184,
342,
507,
198,
3,
13144,
367,
282,
283,
6495,
54,
7,
3622,
436,
2929,
314,
1453,
900,
507,
198,
3,
4005,
1937,
1006,
3622,
666,
12,
625,
3349,
314,
1004,
5084,
199,
198,
3,
1361,
3622,
267,
1847,
7696,
275,
900,
14,
521,
342,
398,
340,
3622,
459,
533,
418,
508,
283,
6495,
54,
356,
288,
340,
2688,
8,
3070,
12,
283,
4452,
358,
436,
2688,
8,
3070,
12,
283,
5298,
358,
436,
2688,
8,
3070,
12,
283,
521,
735,
355,
15852,
7696,
275,
3622,
14,
521,
355,
315,
10878,
29,
17,
507,
198,
692,
2061,
5298,
508,
221,
5008,
26,
686,
198,
2019,
5298,
275,
3622,
14,
5298,
686,
198,
2019,
4452,
275,
3622,
14,
4452,
717,
2061,
521,
275,
3622,
14,
521,
717,
2050,
275,
715,
717,
2061,
1786,
7696,
275,
1847,
7696,
2742,
198,
68,
275,
27254,
11001,
14,
5590,
8,
2019,
5298,
12,
2019,
4452,
12,
3070,
14,
5298,
12,
3070,
14,
4452,
9,
627,
378,
14,
2789,
969,
3172,
627,
14589,
1257,
355,
340,
334,
2019,
1786,
7696,
1137,
1847,
7696,
304,
2116,
8112,
275,
366,
1182,
334,
1786,
7696,
446,
2061,
1786,
7696,
9,
355,
587,
26,
2116,
8112,
275,
378,
2234,
330,
275,
3473,
14,
20251,
8,
71,
8319,
11001,
14,
1235,
9332,
8,
2019,
5298,
12,
2019,
4452,
12,
3070,
14,
5298,
12,
3070,
14,
4452,
430,
355,
340,
330,
665,
378,
26,
717,
330,
847,
19434,
14,
16,
2234,
340,
2688,
8,
3070,
12,
283,
4478,
735,
29294,
282,
275,
3622,
14,
4478,
627,
650,
14,
18520,
1349,
355,
587,
26,
2116,
282,
275,
378,
2234,
340,
334,
835,
450,
5212,
508,
378,
503,
366,
2356,
8765,
9,
436,
2050,
508,
715,
26,
717,
4650,
14,
8174,
342,
326,
198,
1361,
334,
2071,
70,
450,
83,
598,
450,
12497,
14,
22,
70,
450,
30569,
14,
22,
70,
450,
1644,
70,
450,
614,
14,
19,
70,
450,
614,
14,
19,
70,
450,
1644,
14,
17,
70,
14390,
450,
334,
1786,
7696,
12,
3070,
14,
521,
12,
3070,
14,
4452,
12,
3070,
14,
5298,
12,
65,
12,
68,
12,
7625,
12,
66,
430,
717,
4650,
14,
3221,
342,
686,
198,
2019,
5298,
275,
3622,
14,
5298,
686,
198,
2019,
4452,
275,
3622,
14,
4452,
717,
2061,
521,
275,
3622,
14,
521,
717,
2338,
275,
378,
355,
2338,
847,
413,
339,
871,
4067,
26,
507,
198,
1529,
272,
871,
13483,
26,
507,
198,
10589,
342,
272,
871,
10852,
26,
507,
198,
1730,
275,
488,
507,
198,
1361,
298,
8225,
3693,
965,
15745,
2,
199,
199,
318,
18160,
8,
1800,
12,
25466,
12,
46,
12,
52,
304,
523,
612,
70,
275,
7026,
14,
9996,
1389,
14,
9996,
8,
1590,
14,
1144,
8,
25466,
430,
523,
1134,
275,
499,
14,
16,
15,
46,
627,
980,
14,
2101,
8,
89,
70,
1491,
46,
501,
18,
566,
523,
27366,
275,
980,
14,
11649,
8,
16,
14,
16,
12,
17,
14,
16,
7985,
18,
14,
16,
10,
52,
395,
46,
15,
18,
9,
523,
282,
221,
275,
980,
14,
16383,
8,
647,
9,
523,
372,
334,
1949,
59,
65,
467,
647,
59,
65,
566,
199,
199,
318,
1066,
6067,
63,
2921,
837,
523,
2288,
315,
10878,
12,
4927,
7696,
523,
327,
981,
16271,
25774,
9908,
909,
523,
1066,
6067,
275,
1503,
15455,
9908,
14,
1554,
25774,
9908,
342,
819,
671,
86,
275,
942,
523,
612,
86,
275,
942,
523,
1315,
86,
275,
942,
819,
671,
16,
275,
671,
17,
275,
671,
18,
275,
378,
16421,
612,
16,
275,
612,
17,
275,
612,
18,
275,
378,
523,
1315,
16,
275,
1315,
17,
275,
1315,
18,
275,
378,
523,
286,
275,
378,
523,
2061,
521,
9287,
523,
1830,
715,
26,
272,
862,
26,
489,
340,
315,
10878,
508,
378,
26,
267,
900,
14,
4532,
8,
21,
9,
267,
1980,
2541,
327,
362,
7824,
465,
486,
489,
327,
6402,
275,
1066,
6067,
14,
362,
20386,
8,
549,
9,
2541,
327,
370,
664,
7824,
465,
6605,
62,
18,
675,
489,
7824,
275,
1066,
6067,
14,
362,
20386,
8,
797,
9,
2541,
327,
524,
314,
7824,
1901,
2860,
489,
671,
275,
7824,
459,
88,
418,
489,
671,
86,
14,
740,
8,
88,
9,
489,
612,
275,
7824,
459,
89,
418,
489,
612,
86,
14,
740,
8,
89,
9,
489,
1315,
275,
7824,
459,
90,
418,
489,
1315,
86,
14,
740,
8,
90,
9,
489,
671,
17,
847,
671,
489,
612,
17,
847,
612,
489,
1315,
17,
847,
1315,
489,
340,
671,
690,
671,
18,
26,
267,
671,
18,
275,
671,
489,
340,
612,
690,
612,
18,
26,
267,
612,
18,
275,
612,
489,
340,
1315,
690,
1315,
18,
26,
267,
1315,
18,
275,
1315,
489,
340,
671,
665,
671,
16,
26,
267,
671,
16,
275,
671,
489,
340,
612,
665,
612,
16,
26,
267,
612,
16,
275,
612,
489,
340,
1315,
665,
1315,
16,
26,
267,
1315,
16,
275,
1315
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
486,
1190,
199,
646,
3473,
199,
646,
2197,
199,
646,
5796,
199,
3,
646,
314,
1503,
15455,
9908,
859,
199,
646,
1503,
15455,
9908,
199,
646,
900,
199,
646,
27254,
11001,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
9996,
1389,
199,
199,
831,
275,
5796,
14,
6432,
342,
199,
4927,
7696,
275,
3087,
199,
199,
318,
486,
1190,
63,
2921,
837,
523,
2288,
315,
10878,
12,
4927,
7696,
523,
2050,
275,
756,
819,
327,
1964,
386,
523,
8765,
275,
5661,
819,
327,
491,
7938,
641,
1844,
7349,
2417,
334,
25556,
68,
9,
402,
11667,
523,
2351,
275,
486,
1190,
14,
25556,
480,
5967,
401,
298,
1398,
2417,
531,
523,
2351,
14,
1745,
8,
25556,
14,
55,
8078,
63,
8898,
1204,
486,
1190,
14,
55,
8078,
63,
11365,
18466,
9,
819,
2061,
5298,
29,
5008,
523,
2061,
4452,
29,
5008,
523,
366,
275,
2197,
14,
2083,
14,
10779,
342,
523,
2061,
521,
29,
68,
14,
6205,
3647,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
14,
1493,
58,
531,
523,
671,
29,
16,
523,
612,
29,
16,
523,
1315,
29,
25,
14,
11369,
523,
2338,
29,
16,
523,
1830,
715,
26,
272,
862,
26,
267,
327,
598,
5067,
1362,
198,
3070,
275,
2351,
14,
2184,
342,
507,
198,
3,
13144,
367,
282,
283,
6495,
54,
7,
3622,
436,
2929,
314,
1453,
900,
507,
198,
3,
4005,
1937,
1006,
3622,
666,
12,
625,
3349,
314,
1004,
5084,
199,
198,
3,
1361,
3622,
267,
1847,
7696,
275,
900,
14,
521,
342,
398,
340,
3622,
459,
533,
418,
508,
283,
6495,
54,
356,
288,
340,
2688,
8,
3070,
12,
283,
4452,
358,
436,
2688,
8,
3070,
12,
283,
5298,
358,
436,
2688,
8,
3070,
12,
283,
521,
735,
355,
15852,
7696,
275,
3622,
14,
521,
355,
315,
10878,
29,
17,
507,
198,
692,
2061,
5298,
508,
221,
5008,
26,
686,
198,
2019,
5298,
275,
3622,
14,
5298,
686,
198,
2019,
4452,
275,
3622,
14,
4452,
717,
2061,
521,
275,
3622,
14,
521,
717,
2050,
275,
715,
717,
2061,
1786,
7696,
275,
1847,
7696,
2742,
198,
68,
275,
27254,
11001,
14,
5590,
8,
2019,
5298,
12,
2019,
4452,
12,
3070,
14,
5298,
12,
3070,
14,
4452,
9,
627,
378,
14,
2789,
969,
3172,
627,
14589,
1257,
355,
340,
334,
2019,
1786,
7696,
1137,
1847,
7696,
304,
2116,
8112,
275,
366,
1182,
334,
1786,
7696,
446,
2061,
1786,
7696,
9,
355,
587,
26,
2116,
8112,
275,
378,
2234,
330,
275,
3473,
14,
20251,
8,
71,
8319,
11001,
14,
1235,
9332,
8,
2019,
5298,
12,
2019,
4452,
12,
3070,
14,
5298,
12,
3070,
14,
4452,
430,
355,
340,
330,
665,
378,
26,
717,
330,
847,
19434,
14,
16,
2234,
340,
2688,
8,
3070,
12,
283,
4478,
735,
29294,
282,
275,
3622,
14,
4478,
627,
650,
14,
18520,
1349,
355,
587,
26,
2116,
282,
275,
378,
2234,
340,
334,
835,
450,
5212,
508,
378,
503,
366,
2356,
8765,
9,
436,
2050,
508,
715,
26,
717,
4650,
14,
8174,
342,
326,
198,
1361,
334,
2071,
70,
450,
83,
598,
450,
12497,
14,
22,
70,
450,
30569,
14,
22,
70,
450,
1644,
70,
450,
614,
14,
19,
70,
450,
614,
14,
19,
70,
450,
1644,
14,
17,
70,
14390,
450,
334,
1786,
7696,
12,
3070,
14,
521,
12,
3070,
14,
4452,
12,
3070,
14,
5298,
12,
65,
12,
68,
12,
7625,
12,
66,
430,
717,
4650,
14,
3221,
342,
686,
198,
2019,
5298,
275,
3622,
14,
5298,
686,
198,
2019,
4452,
275,
3622,
14,
4452,
717,
2061,
521,
275,
3622,
14,
521,
717,
2338,
275,
378,
355,
2338,
847,
413,
339,
871,
4067,
26,
507,
198,
1529,
272,
871,
13483,
26,
507,
198,
10589,
342,
272,
871,
10852,
26,
507,
198,
1730,
275,
488,
507,
198,
1361,
298,
8225,
3693,
965,
15745,
2,
199,
199,
318,
18160,
8,
1800,
12,
25466,
12,
46,
12,
52,
304,
523,
612,
70,
275,
7026,
14,
9996,
1389,
14,
9996,
8,
1590,
14,
1144,
8,
25466,
430,
523,
1134,
275,
499,
14,
16,
15,
46,
627,
980,
14,
2101,
8,
89,
70,
1491,
46,
501,
18,
566,
523,
27366,
275,
980,
14,
11649,
8,
16,
14,
16,
12,
17,
14,
16,
7985,
18,
14,
16,
10,
52,
395,
46,
15,
18,
9,
523,
282,
221,
275,
980,
14,
16383,
8,
647,
9,
523,
372,
334,
1949,
59,
65,
467,
647,
59,
65,
566,
199,
199,
318,
1066,
6067,
63,
2921,
837,
523,
2288,
315,
10878,
12,
4927,
7696,
523,
327,
981,
16271,
25774,
9908,
909,
523,
1066,
6067,
275,
1503,
15455,
9908,
14,
1554,
25774,
9908,
342,
819,
671,
86,
275,
942,
523,
612,
86,
275,
942,
523,
1315,
86,
275,
942,
819,
671,
16,
275,
671,
17,
275,
671,
18,
275,
378,
16421,
612,
16,
275,
612,
17,
275,
612,
18,
275,
378,
523,
1315,
16,
275,
1315,
17,
275,
1315,
18,
275,
378,
523,
286,
275,
378,
523,
2061,
521,
9287,
523,
1830,
715,
26,
272,
862,
26,
489,
340,
315,
10878,
508,
378,
26,
267,
900,
14,
4532,
8,
21,
9,
267,
1980,
2541,
327,
362,
7824,
465,
486,
489,
327,
6402,
275,
1066,
6067,
14,
362,
20386,
8,
549,
9,
2541,
327,
370,
664,
7824,
465,
6605,
62,
18,
675,
489,
7824,
275,
1066,
6067,
14,
362,
20386,
8,
797,
9,
2541,
327,
524,
314,
7824,
1901,
2860,
489,
671,
275,
7824,
459,
88,
418,
489,
671,
86,
14,
740,
8,
88,
9,
489,
612,
275,
7824,
459,
89,
418,
489,
612,
86,
14,
740,
8,
89,
9,
489,
1315,
275,
7824,
459,
90,
418,
489,
1315,
86,
14,
740,
8,
90,
9,
489,
671,
17,
847,
671,
489,
612,
17,
847,
612,
489,
1315,
17,
847,
1315,
489,
340,
671,
690,
671,
18,
26,
267,
671,
18,
275,
671,
489,
340,
612,
690,
612,
18,
26,
267,
612,
18,
275,
612,
489,
340,
1315,
690,
1315,
18,
26,
267,
1315,
18,
275,
1315,
489,
340,
671,
665,
671,
16,
26,
267,
671,
16,
275,
671,
489,
340,
612,
665,
612,
16,
26,
267,
612,
16,
275,
612,
489,
340,
1315,
665,
1315,
16,
26,
267,
1315,
16,
275,
1315,
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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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
] |
surengrig/Milstone-XT720-kernel-upgrade
|
scripts/rt-tester/rt-tester.py
|
904
|
5366
|
#!/usr/bin/env python
#
# rt-mutex tester
#
# (C) 2006 Thomas Gleixner <tglx@linutronix.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
import os
import sys
import getopt
import shutil
import string
# Globals
quiet = 0
test = 0
comments = 0
sysfsprefix = "/sys/devices/system/rttest/rttest"
statusfile = "/status"
commandfile = "/command"
# Command opcodes
cmd_opcodes = {
"schedother" : "1",
"schedfifo" : "2",
"lock" : "3",
"locknowait" : "4",
"lockint" : "5",
"lockintnowait" : "6",
"lockcont" : "7",
"unlock" : "8",
"lockbkl" : "9",
"unlockbkl" : "10",
"signal" : "11",
"resetevent" : "98",
"reset" : "99",
}
test_opcodes = {
"prioeq" : ["P" , "eq" , None],
"priolt" : ["P" , "lt" , None],
"priogt" : ["P" , "gt" , None],
"nprioeq" : ["N" , "eq" , None],
"npriolt" : ["N" , "lt" , None],
"npriogt" : ["N" , "gt" , None],
"unlocked" : ["M" , "eq" , 0],
"trylock" : ["M" , "eq" , 1],
"blocked" : ["M" , "eq" , 2],
"blockedwake" : ["M" , "eq" , 3],
"locked" : ["M" , "eq" , 4],
"opcodeeq" : ["O" , "eq" , None],
"opcodelt" : ["O" , "lt" , None],
"opcodegt" : ["O" , "gt" , None],
"eventeq" : ["E" , "eq" , None],
"eventlt" : ["E" , "lt" , None],
"eventgt" : ["E" , "gt" , None],
}
# Print usage information
def usage():
print "rt-tester.py <-c -h -q -t> <testfile>"
print " -c display comments after first command"
print " -h help"
print " -q quiet mode"
print " -t test mode (syntax check)"
print " testfile: read test specification from testfile"
print " otherwise from stdin"
return
# Print progress when not in quiet mode
def progress(str):
if not quiet:
print str
# Analyse a status value
def analyse(val, top, arg):
intval = int(val)
if top[0] == "M":
intval = intval / (10 ** int(arg))
intval = intval % 10
argval = top[2]
elif top[0] == "O":
argval = int(cmd_opcodes.get(arg, arg))
else:
argval = int(arg)
# progress("%d %s %d" %(intval, top[1], argval))
if top[1] == "eq" and intval == argval:
return 1
if top[1] == "lt" and intval < argval:
return 1
if top[1] == "gt" and intval > argval:
return 1
return 0
# Parse the commandline
try:
(options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
except getopt.GetoptError, ex:
usage()
sys.exit(1)
# Parse commandline options
for option, value in options:
if option == "-c":
comments = 1
elif option == "-q":
quiet = 1
elif option == "-t":
test = 1
elif option == '-h':
usage()
sys.exit(0)
# Select the input source
if arguments:
try:
fd = open(arguments[0])
except Exception,ex:
sys.stderr.write("File not found %s\n" %(arguments[0]))
sys.exit(1)
else:
fd = sys.stdin
linenr = 0
# Read the test patterns
while 1:
linenr = linenr + 1
line = fd.readline()
if not len(line):
break
line = line.strip()
parts = line.split(":")
if not parts or len(parts) < 1:
continue
if len(parts[0]) == 0:
continue
if parts[0].startswith("#"):
if comments > 1:
progress(line)
continue
if comments == 1:
comments = 2
progress(line)
cmd = parts[0].strip().lower()
opc = parts[1].strip().lower()
tid = parts[2].strip()
dat = parts[3].strip()
try:
# Test or wait for a status value
if cmd == "t" or cmd == "w":
testop = test_opcodes[opc]
fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
if test:
print fname
continue
while 1:
query = 1
fsta = open(fname, 'r')
status = fsta.readline().strip()
fsta.close()
stat = status.split(",")
for s in stat:
s = s.strip()
if s.startswith(testop[0]):
# Seperate status value
val = s[2:].strip()
query = analyse(val, testop, dat)
break
if query or cmd == "t":
break
progress(" " + status)
if not query:
sys.stderr.write("Test failed in line %d\n" %(linenr))
sys.exit(1)
# Issue a command to the tester
elif cmd == "c":
cmdnr = cmd_opcodes[opc]
# Build command string and sys filename
cmdstr = "%s:%s" %(cmdnr, dat)
fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
if test:
print fname
continue
fcmd = open(fname, 'w')
fcmd.write(cmdstr)
fcmd.close()
except Exception,ex:
sys.stderr.write(str(ex))
sys.stderr.write("\nSyntax error in line %d\n" %(linenr))
if not test:
fd.close()
sys.exit(1)
# Normal exit pass
print "Pass"
sys.exit(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
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,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
831,
66,
9503,
2,
755,
520,
298,
25,
401,
272,
298,
17966,
66,
9503,
2,
258,
520,
298,
709,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
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,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
831,
66,
9503,
2,
755,
520,
298,
25,
401,
272,
298,
17966,
66,
9503,
2,
258,
520,
298,
709,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3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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
] |
wido/cloudstack
|
test/integration/smoke/test_password_server.py
|
4
|
13527
|
# 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.
# Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import (stopVirtualMachine,
stopRouter,
startRouter)
from marvin.lib.utils import (cleanup_resources,
get_process_status)
from marvin.lib.base import (ServiceOffering,
VirtualMachine,
Account,
ServiceOffering,
NATRule,
NetworkACL,
FireWallRule,
PublicIPAddress,
NetworkOffering,
Network,
Router)
from marvin.lib.common import (get_zone,
get_test_template,
get_domain,
list_virtual_machines,
list_networks,
list_configurations,
list_routers,
list_nat_rules,
list_publicIP,
list_firewall_rules,
list_hosts)
# Import System modules
import time
import logging
class TestIsolatedNetworksPasswdServer(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.logger = logging.getLogger('TestIsolatedNetworksPasswdServer')
cls.stream_handler = logging.StreamHandler()
cls.logger.setLevel(logging.DEBUG)
cls.logger.addHandler(cls.stream_handler)
cls.testClient = super(TestIsolatedNetworksPasswdServer, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__
cls.services = cls.testClient.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.hypervisor = cls.testClient.getHypervisorInfo()
cls.services['mode'] = cls.zone.networktype
template = get_test_template(
cls.api_client,
cls.zone.id,
cls.hypervisor
)
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.logger.debug("Creating Admin Account for domain %s on zone %s" % (cls.domain.id, cls.zone.id))
# Create an account, network, VM and IP addresses
cls.account = Account.create(
cls.api_client,
cls.services["account"],
admin=True,
domainid=cls.domain.id
)
cls.logger.debug("Creating Service Offering on zone %s" % (cls.zone.id))
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
cls.services["isolated_network_offering"]["egress_policy"] = "true"
cls.logger.debug("Creating Network Offering on zone %s" % (cls.zone.id))
cls.network_offering = NetworkOffering.create(cls.api_client,
cls.services["isolated_network_offering"],
conservemode=True)
cls.network_offering.update(cls.api_client, state='Enabled')
cls.logger.debug("Creating Network for Account %s using offering %s" % (cls.account.name, cls.network_offering.id))
cls.network = Network.create(cls.api_client,
cls.services["network"],
accountid=cls.account.name,
domainid=cls.account.domainid,
networkofferingid=cls.network_offering.id,
zoneid=cls.zone.id)
cls.logger.debug("Creating VM1 for Account %s using offering %s" % (cls.account.name, cls.service_offering.id))
cls.vm_1 = VirtualMachine.create(cls.api_client,
cls.services["virtual_machine"],
templateid=template.id,
accountid=cls.account.name,
domainid=cls.domain.id,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network.id)])
cls.logger.debug("Creating VM2 for Account %s using offering %s" % (cls.account.name, cls.service_offering.id))
cls.vm_2 = VirtualMachine.create(cls.api_client,
cls.services["virtual_machine"],
templateid=template.id,
accountid=cls.account.name,
domainid=cls.domain.id,
serviceofferingid=cls.service_offering.id,
networkids=[str(cls.network.id)])
cls.services["natrule1"] = {
"privateport": 22,
"publicport": 222,
"protocol": "TCP"
}
cls.services["natrule2"] = {
"privateport": 22,
"publicport": 223,
"protocol": "TCP"
}
cls.services["configurableData"] = {
"host": {
"port": 22
},
"input": "INPUT",
"forward": "FORWARD"
}
cls._cleanup = [
cls.vm_1,
cls.vm_2,
cls.network,
cls.network_offering,
cls.service_offering,
cls.account
]
return
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
return
def test_ssh_command(self, vm, nat_rule, rule_label):
result = 'failed'
try:
ssh_command = "ping -c 3 8.8.8.8"
self.logger.debug("SSH into VM with IP: %s" % nat_rule.ipaddress)
ssh = vm.get_ssh_client(ipaddress=nat_rule.ipaddress, port=self.services[rule_label]["publicport"], retries=5)
result = str(ssh.execute(ssh_command))
self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count(" 0% packet loss")))
except:
self.fail("Failed to SSH into VM - %s" % (nat_rule.ipaddress))
self.assertEqual(
result.count(" 0% packet loss"),
1,
"Ping to outside world from VM should be successful"
)
def test_password_file_not_empty(self, vm, router):
hosts = list_hosts(
self.apiclient,
id=router.hostid)
self.assertEqual(
isinstance(hosts, list),
True,
"Check for list hosts response return valid data")
host = hosts[0]
host.user = self.hostConfig['username']
host.passwd = self.hostConfig['password']
host.port = self.services["configurableData"]["host"]["port"]
if self.hypervisor.lower() in ('vmware', 'hyperv'):
result = get_process_status(
self.apiclient.connection.mgtSvr,
22,
self.apiclient.connection.user,
self.apiclient.connection.passwd,
router.linklocalip,
"cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}'" % (vm.nic[0].gateway, vm.nic[0].ipaddress),
hypervisor=self.hypervisor
)
else:
try:
result = get_process_status(
host.ipaddress,
host.port,
host.user,
host.passwd,
router.linklocalip,
"cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}'" % (vm.nic[0].gateway, vm.nic[0].ipaddress))
except KeyError:
self.skipTest(
"Provide a marvin config file with host\
credentials to run %s" %
self._testMethodName)
self.logger.debug("cat /var/cache/cloud/passwords-%s | grep %s | sed 's/=/ /g' | awk '{print $1}' RESULT IS ==> %s" % (vm.nic[0].gateway, vm.nic[0].ipaddress, result))
self.assertTrue(vm.nic[0].ipaddress in result, "Password file is empty or doesn't exist!")
@attr(tags=["advanced", "advancedns", "ssh"], required_hardware="true")
def test_isolate_network_password_server(self):
"""Check the password file in the Router VM"""
self.logger.debug("Starting test_isolate_network_password_server...")
routers = list_routers(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid
)
self.assertEqual(
isinstance(routers, list),
True,
"Check for list routers response return valid data"
)
self.assertNotEqual(
len(routers),
0,
"Check list router response"
)
router = routers[0]
self.assertEqual(
router.state,
'Running',
"Check list router response for router state"
)
public_ips = list_publicIP(
self.apiclient,
account=self.account.name,
domainid=self.account.domainid,
zoneid=self.zone.id
)
self.assertEqual(
isinstance(public_ips, list),
True,
"Check for list public IPs response return valid data"
)
public_ip = public_ips[0]
self.logger.debug("Creating Firewall rule for VM ID: %s" % self.vm_1.id)
FireWallRule.create(
self.apiclient,
ipaddressid=public_ip.id,
protocol=self.services["natrule1"]["protocol"],
cidrlist=['0.0.0.0/0'],
startport=self.services["natrule1"]["publicport"],
endport=self.services["natrule1"]["publicport"]
)
self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm_1.id)
# Create NAT rule
nat_rule1 = NATRule.create(
self.apiclient,
self.vm_1,
self.services["natrule1"],
public_ip.id
)
self.logger.debug("Creating Firewall rule for VM ID: %s" % self.vm_2.id)
FireWallRule.create(
self.apiclient,
ipaddressid=public_ip.id,
protocol=self.services["natrule2"]["protocol"],
cidrlist=['0.0.0.0/0'],
startport=self.services["natrule2"]["publicport"],
endport=self.services["natrule2"]["publicport"]
)
self.logger.debug("Creating NAT rule for VM ID: %s" % self.vm_2.id)
# Create NAT rule
nat_rule2 = NATRule.create(
self.apiclient,
self.vm_2,
self.services["natrule2"],
public_ip.id
)
nat_rules = list_nat_rules(
self.apiclient,
id=nat_rule1.id
)
self.assertEqual(
isinstance(nat_rules, list),
True,
"Check for list NAT rules response return valid data"
)
self.assertEqual(
nat_rules[0].state,
'Active',
"Check list port forwarding rules"
)
nat_rules = list_nat_rules(
self.apiclient,
id=nat_rule2.id
)
self.assertEqual(
isinstance(nat_rules, list),
True,
"Check for list NAT rules response return valid data"
)
self.assertEqual(
nat_rules[0].state,
'Active',
"Check list port forwarding rules"
)
self.test_ssh_command(self.vm_1, nat_rule1, "natrule1")
self.test_ssh_command(self.vm_2, nat_rule2, "natrule2")
self.test_password_file_not_empty(self.vm_1, router)
self.test_password_file_not_empty(self.vm_2, router)
return
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
3,
3161,
10111,
18167,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
7557,
11908,
14,
4091,
2340,
1746,
492,
8002,
2340,
1746,
199,
504,
7557,
11908,
14,
4091,
2340,
3735,
492,
334,
2379,
29863,
12,
3303,
3631,
11691,
12,
3303,
1343,
11691,
9,
199,
504,
7557,
11908,
14,
773,
14,
1208,
492,
334,
7661,
63,
4435,
12,
2892,
664,
63,
1412,
63,
1205,
9,
199,
504,
7557,
11908,
14,
773,
14,
1095,
492,
334,
3167,
22154,
316,
12,
2490,
13311,
8412,
12,
2490,
9973,
12,
2490,
7591,
22154,
316,
12,
2490,
31363,
5065,
12,
2490,
7220,
18765,
12,
2490,
15967,
18018,
5065,
12,
2490,
1684,
14955,
12,
2490,
7220,
22154,
316,
12,
2490,
7220,
12,
2490,
22708,
9,
199,
504,
7557,
11908,
14,
773,
14,
2330,
492,
334,
362,
63,
2619,
12,
3044,
664,
63,
396,
63,
1160,
12,
3044,
664,
63,
2261,
12,
3044,
769,
63,
2065,
63,
26489,
12,
3044,
769,
63,
7642,
12,
3044,
769,
63,
10057,
12,
3044,
769,
63,
17292,
12,
3044,
769,
63,
9468,
63,
4423,
12,
3044,
769,
63,
3455,
1772,
12,
3044,
769,
63,
10794,
63,
4423,
12,
3044,
769,
63,
5146,
9,
199,
199,
3,
3161,
6187,
4621,
199,
646,
900,
199,
646,
2050,
421,
199,
533,
1379,
1831,
12918,
30551,
4986,
2989,
3120,
8,
4091,
2340,
1746,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
398,
843,
14,
2921,
275,
2050,
14,
5572,
360,
774,
1831,
12918,
30551,
4986,
2989,
3120,
358,
267,
843,
14,
1745,
63,
2232,
275,
2050,
14,
22482,
342,
267,
843,
14,
2921,
14,
13548,
8,
4806,
14,
5287,
9,
267,
843,
14,
2921,
14,
18826,
8,
1886,
14,
1745,
63,
2232,
9,
398,
843,
14,
396,
3041,
275,
1613,
8,
774,
1831,
12918,
30551,
4986,
2989,
3120,
12,
843,
680,
362,
24342,
774,
3041,
342,
267,
843,
14,
1246,
63,
1258,
275,
843,
14,
396,
3041,
14,
362,
7394,
3041,
342,
398,
843,
14,
1102,
2028,
275,
843,
14,
888,
855,
807,
363,
905,
13325,
9210,
16,
17979,
807,
363,
905,
12656,
83,
9210,
16,
17979,
807,
363,
905,
9170,
9210,
16,
17979,
807,
363,
905,
5146,
9210,
16,
17979,
807,
363,
267,
843,
14,
5950,
275,
843,
14,
396,
3041,
14,
362,
1262,
939,
16550,
2028,
342,
267,
327,
2372,
22518,
12,
14061,
436,
7009,
267,
843,
14,
2261,
275,
664,
63,
2261,
8,
1886,
14,
1246,
63,
1258,
9,
267,
843,
14,
2619,
275,
664,
63,
2619,
8,
1886,
14,
1246,
63,
1258,
12,
843,
14,
396,
3041,
14,
362,
11860,
1858,
2925,
1012,
267,
843,
14,
18237,
275,
843,
14,
396,
3041,
14,
362,
18727,
8286,
2354,
342,
267,
843,
14,
5950,
459,
632,
418,
275,
843,
14,
2619,
14,
1200,
466,
267,
1978,
275,
664,
63,
396,
63,
1160,
8,
288,
843,
14,
1246,
63,
1258,
12,
288,
843,
14,
2619,
14,
344,
12,
288,
843,
14,
18237,
267,
776,
398,
843,
14,
5950,
905,
2065,
63,
6744,
6611,
2619,
344,
937,
275,
843,
14,
2619,
14,
344,
398,
843,
14,
2921,
14,
1757,
480,
14380,
9516,
9973,
367,
2881,
450,
83,
641,
5718,
450,
83,
2,
450,
334,
1886,
14,
2261,
14,
344,
12,
843,
14,
2619,
14,
344,
430,
267,
327,
2790,
376,
2933,
12,
2784,
12,
7525,
436,
3531,
7149,
267,
843,
14,
2048,
275,
9973,
14,
981,
8,
288,
843,
14,
1246,
63,
1258,
12,
288,
843,
14,
5950,
905,
2048,
2255,
288,
4628,
29,
549,
12,
288,
2881,
344,
29,
1886,
14,
2261,
14,
344,
267,
776,
398,
843,
14,
2921,
14,
1757,
480,
14380,
7591,
593,
1260,
316,
641,
5718,
450,
83,
2,
450,
334,
1886,
14,
2619,
14,
344,
430,
267,
843,
14,
1364,
63,
19501,
275,
7591,
22154,
316,
14,
981,
8,
288,
843,
14,
1246,
63,
1258,
12,
288,
843,
14,
5950,
905,
1364,
63,
19501,
937,
267,
776,
398,
843,
14,
5950,
905,
21748,
63,
1200,
63,
19501,
6611,
24518,
63,
3185,
937,
275,
298,
2052,
2,
398,
843,
14,
2921,
14,
1757,
480,
14380,
7220,
593,
1260,
316,
641,
5718,
450,
83,
2,
450,
334,
1886,
14,
2619,
14,
344,
430,
267,
843,
14,
1200,
63,
19501,
275,
7220,
22154,
316,
14,
981,
8,
1886,
14,
1246,
63,
1258,
12,
10940,
843,
14,
5950,
905,
21748,
63,
1200,
63,
19501,
2255,
10940,
406,
4909,
632,
29,
549,
9,
398,
843,
14,
1200,
63,
19501,
14,
873,
8,
1886,
14,
1246,
63,
1258,
12,
1174,
534,
6589,
358,
398,
843,
14,
2921,
14,
1757,
480,
14380,
7220,
367,
9973,
450,
83,
1808,
2331,
15663,
450,
83,
2,
450,
334,
1886,
14,
2048,
14,
354,
12,
843,
14,
1200,
63,
19501,
14,
344,
430,
267,
843,
14,
1200,
275,
7220,
14,
981,
8,
1886,
14,
1246,
63,
1258,
12,
4228,
843,
14,
5950,
905,
1200,
2255,
4228,
1066,
3094,
5700,
29,
1886,
14,
2048,
14,
354,
12,
4228,
2881,
344,
29,
1886,
14,
2048,
14,
2261,
344,
12,
4228,
2784,
19501,
344,
29,
1886,
14,
1200,
63,
19501,
14,
344,
12,
4228,
5718,
344,
29,
1886,
14,
2619,
14
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
3,
3161,
10111,
18167,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
504,
7557,
11908,
14,
4091,
2340,
1746,
492,
8002,
2340,
1746,
199,
504,
7557,
11908,
14,
4091,
2340,
3735,
492,
334,
2379,
29863,
12,
3303,
3631,
11691,
12,
3303,
1343,
11691,
9,
199,
504,
7557,
11908,
14,
773,
14,
1208,
492,
334,
7661,
63,
4435,
12,
2892,
664,
63,
1412,
63,
1205,
9,
199,
504,
7557,
11908,
14,
773,
14,
1095,
492,
334,
3167,
22154,
316,
12,
2490,
13311,
8412,
12,
2490,
9973,
12,
2490,
7591,
22154,
316,
12,
2490,
31363,
5065,
12,
2490,
7220,
18765,
12,
2490,
15967,
18018,
5065,
12,
2490,
1684,
14955,
12,
2490,
7220,
22154,
316,
12,
2490,
7220,
12,
2490,
22708,
9,
199,
504,
7557,
11908,
14,
773,
14,
2330,
492,
334,
362,
63,
2619,
12,
3044,
664,
63,
396,
63,
1160,
12,
3044,
664,
63,
2261,
12,
3044,
769,
63,
2065,
63,
26489,
12,
3044,
769,
63,
7642,
12,
3044,
769,
63,
10057,
12,
3044,
769,
63,
17292,
12,
3044,
769,
63,
9468,
63,
4423,
12,
3044,
769,
63,
3455,
1772,
12,
3044,
769,
63,
10794,
63,
4423,
12,
3044,
769,
63,
5146,
9,
199,
199,
3,
3161,
6187,
4621,
199,
646,
900,
199,
646,
2050,
421,
199,
533,
1379,
1831,
12918,
30551,
4986,
2989,
3120,
8,
4091,
2340,
1746,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
398,
843,
14,
2921,
275,
2050,
14,
5572,
360,
774,
1831,
12918,
30551,
4986,
2989,
3120,
358,
267,
843,
14,
1745,
63,
2232,
275,
2050,
14,
22482,
342,
267,
843,
14,
2921,
14,
13548,
8,
4806,
14,
5287,
9,
267,
843,
14,
2921,
14,
18826,
8,
1886,
14,
1745,
63,
2232,
9,
398,
843,
14,
396,
3041,
275,
1613,
8,
774,
1831,
12918,
30551,
4986,
2989,
3120,
12,
843,
680,
362,
24342,
774,
3041,
342,
267,
843,
14,
1246,
63,
1258,
275,
843,
14,
396,
3041,
14,
362,
7394,
3041,
342,
398,
843,
14,
1102,
2028,
275,
843,
14,
888,
855,
807,
363,
905,
13325,
9210,
16,
17979,
807,
363,
905,
12656,
83,
9210,
16,
17979,
807,
363,
905,
9170,
9210,
16,
17979,
807,
363,
905,
5146,
9210,
16,
17979,
807,
363,
267,
843,
14,
5950,
275,
843,
14,
396,
3041,
14,
362,
1262,
939,
16550,
2028,
342,
267,
327,
2372,
22518,
12,
14061,
436,
7009,
267,
843,
14,
2261,
275,
664,
63,
2261,
8,
1886,
14,
1246,
63,
1258,
9,
267,
843,
14,
2619,
275,
664,
63,
2619,
8,
1886,
14,
1246,
63,
1258,
12,
843,
14,
396,
3041,
14,
362,
11860,
1858,
2925,
1012,
267,
843,
14,
18237,
275,
843,
14,
396,
3041,
14,
362,
18727,
8286,
2354,
342,
267,
843,
14,
5950,
459,
632,
418,
275,
843,
14,
2619,
14,
1200,
466,
267,
1978,
275,
664,
63,
396,
63,
1160,
8,
288,
843,
14,
1246,
63,
1258,
12,
288,
843,
14,
2619,
14,
344,
12,
288,
843,
14,
18237,
267,
776,
398,
843,
14,
5950,
905,
2065,
63,
6744,
6611,
2619,
344,
937,
275,
843,
14,
2619,
14,
344,
398,
843,
14,
2921,
14,
1757,
480,
14380,
9516,
9973,
367,
2881,
450,
83,
641,
5718,
450,
83,
2,
450,
334,
1886,
14,
2261,
14,
344,
12,
843,
14,
2619,
14,
344,
430,
267,
327,
2790,
376,
2933,
12,
2784,
12,
7525,
436,
3531,
7149,
267,
843,
14,
2048,
275,
9973,
14,
981,
8,
288,
843,
14,
1246,
63,
1258,
12,
288,
843,
14,
5950,
905,
2048,
2255,
288,
4628,
29,
549,
12,
288,
2881,
344,
29,
1886,
14,
2261,
14,
344,
267,
776,
398,
843,
14,
2921,
14,
1757,
480,
14380,
7591,
593,
1260,
316,
641,
5718,
450,
83,
2,
450,
334,
1886,
14,
2619,
14,
344,
430,
267,
843,
14,
1364,
63,
19501,
275,
7591,
22154,
316,
14,
981,
8,
288,
843,
14,
1246,
63,
1258,
12,
288,
843,
14,
5950,
905,
1364,
63,
19501,
937,
267,
776,
398,
843,
14,
5950,
905,
21748,
63,
1200,
63,
19501,
6611,
24518,
63,
3185,
937,
275,
298,
2052,
2,
398,
843,
14,
2921,
14,
1757,
480,
14380,
7220,
593,
1260,
316,
641,
5718,
450,
83,
2,
450,
334,
1886,
14,
2619,
14,
344,
430,
267,
843,
14,
1200,
63,
19501,
275,
7220,
22154,
316,
14,
981,
8,
1886,
14,
1246,
63,
1258,
12,
10940,
843,
14,
5950,
905,
21748,
63,
1200,
63,
19501,
2255,
10940,
406,
4909,
632,
29,
549,
9,
398,
843,
14,
1200,
63,
19501,
14,
873,
8,
1886,
14,
1246,
63,
1258,
12,
1174,
534,
6589,
358,
398,
843,
14,
2921,
14,
1757,
480,
14380,
7220,
367,
9973,
450,
83,
1808,
2331,
15663,
450,
83,
2,
450,
334,
1886,
14,
2048,
14,
354,
12,
843,
14,
1200,
63,
19501,
14,
344,
430,
267,
843,
14,
1200,
275,
7220,
14,
981,
8,
1886,
14,
1246,
63,
1258,
12,
4228,
843,
14,
5950,
905,
1200,
2255,
4228,
1066,
3094,
5700,
29,
1886,
14,
2048,
14,
354,
12,
4228,
2881,
344,
29,
1886,
14,
2048,
14,
2261,
344,
12,
4228,
2784,
19501,
344,
29,
1886,
14,
1200,
63,
19501,
14,
344,
12,
4228,
5718,
344,
29,
1886,
14,
2619,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vit2/vit-e2
|
e2reactor.py
|
29
|
5262
|
# enigma2 reactor: based on pollreactor, which is
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Maintainer: U{Felix Domke<mailto:tmbinc@elitedvb.net>}
"""
# System imports
import select, errno, sys
# Twisted imports
from twisted.python import log, failure
from twisted.internet import main, posixbase, error
#from twisted.internet.pollreactor import PollReactor, poller
from enigma import getApplication
# globals
reads = {}
writes = {}
selectables = {}
POLL_DISCONNECTED = (select.POLLHUP | select.POLLERR | select.POLLNVAL)
class E2SharedPoll:
def __init__(self):
self.dict = { }
self.eApp = getApplication()
def register(self, fd, eventmask = select.POLLIN | select.POLLERR | select.POLLOUT):
self.dict[fd] = eventmask
def unregister(self, fd):
del self.dict[fd]
def poll(self, timeout = None):
try:
r = self.eApp.poll(timeout, self.dict)
except KeyboardInterrupt:
return None
return r
poller = E2SharedPoll()
class PollReactor(posixbase.PosixReactorBase):
"""A reactor that uses poll(2)."""
def _updateRegistration(self, fd):
"""Register/unregister an fd with the poller."""
try:
poller.unregister(fd)
except KeyError:
pass
mask = 0
if reads.has_key(fd): mask = mask | select.POLLIN
if writes.has_key(fd): mask = mask | select.POLLOUT
if mask != 0:
poller.register(fd, mask)
else:
if selectables.has_key(fd): del selectables[fd]
poller.eApp.interruptPoll()
def _dictRemove(self, selectable, mdict):
try:
# the easy way
fd = selectable.fileno()
# make sure the fd is actually real. In some situations we can get
# -1 here.
mdict[fd]
except:
# the hard way: necessary because fileno() may disappear at any
# moment, thanks to python's underlying sockets impl
for fd, fdes in selectables.items():
if selectable is fdes:
break
else:
# Hmm, maybe not the right course of action? This method can't
# fail, because it happens inside error detection...
return
if mdict.has_key(fd):
del mdict[fd]
self._updateRegistration(fd)
def addReader(self, reader):
"""Add a FileDescriptor for notification of data available to read.
"""
fd = reader.fileno()
if not reads.has_key(fd):
selectables[fd] = reader
reads[fd] = 1
self._updateRegistration(fd)
def addWriter(self, writer, writes=writes, selectables=selectables):
"""Add a FileDescriptor for notification of data available to write.
"""
fd = writer.fileno()
if not writes.has_key(fd):
selectables[fd] = writer
writes[fd] = 1
self._updateRegistration(fd)
def removeReader(self, reader, reads=reads):
"""Remove a Selectable for notification of data available to read.
"""
return self._dictRemove(reader, reads)
def removeWriter(self, writer, writes=writes):
"""Remove a Selectable for notification of data available to write.
"""
return self._dictRemove(writer, writes)
def removeAll(self, reads=reads, writes=writes, selectables=selectables):
"""Remove all selectables, and return a list of them."""
if self.waker is not None:
self.removeReader(self.waker)
result = selectables.values()
fds = selectables.keys()
reads.clear()
writes.clear()
selectables.clear()
for fd in fds:
poller.unregister(fd)
if self.waker is not None:
self.addReader(self.waker)
return result
def doPoll(self, timeout,
reads=reads,
writes=writes,
selectables=selectables,
select=select,
log=log,
POLLIN=select.POLLIN,
POLLOUT=select.POLLOUT):
"""Poll the poller for new events."""
if timeout is not None:
timeout = int(timeout * 1000) # convert seconds to milliseconds
try:
l = poller.poll(timeout)
if l is None:
if self.running:
self.stop()
l = [ ]
except select.error, e:
if e[0] == errno.EINTR:
return
else:
raise
_drdw = self._doReadOrWrite
for fd, event in l:
try:
selectable = selectables[fd]
except KeyError:
# Handles the infrequent case where one selectable's
# handler disconnects another.
continue
log.callWithLogger(selectable, _drdw, selectable, fd, event, POLLIN, POLLOUT, log)
doIteration = doPoll
def _doReadOrWrite(self, selectable, fd, event, POLLIN, POLLOUT, log,
faildict={
error.ConnectionDone: failure.Failure(error.ConnectionDone()),
error.ConnectionLost: failure.Failure(error.ConnectionLost())
}):
why = None
inRead = False
if event & POLL_DISCONNECTED and not (event & POLLIN):
why = main.CONNECTION_LOST
else:
try:
if event & POLLIN:
why = selectable.doRead()
inRead = True
if not why and event & POLLOUT:
why = selectable.doWrite()
inRead = False
if not selectable.fileno() == fd:
why = error.ConnectionFdescWentAway('Filedescriptor went away')
inRead = False
except:
log.deferr()
why = sys.exc_info()[1]
if why:
self._disconnectSelectable(selectable, why, inRead)
def callLater(self, *args, **kwargs):
poller.eApp.interruptPoll()
return posixbase.PosixReactorBase.callLater(self, *args, **kwargs)
def install():
"""Install the poll() reactor."""
p = PollReactor()
main.installReactor(p)
__all__ = ["PollReactor", "install"]
|
gpl-2.0
|
[
3,
655,
27021,
18,
9655,
26,
4079,
641,
11271,
13544,
12,
1314,
365,
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
11903,
8368,
281,
26,
738,
91,
3456,
20528,
577,
676,
415,
28,
26206,
26,
84,
887,
6559,
32,
18865,
471,
18708,
14,
846,
23307,
199,
624,
199,
199,
3,
6187,
8925,
199,
646,
3504,
12,
7554,
12,
984,
199,
199,
3,
17078,
8925,
199,
504,
7390,
14,
1548,
492,
943,
12,
5988,
199,
504,
7390,
14,
4901,
492,
2446,
12,
10694,
1095,
12,
1125,
199,
3,
504,
7390,
14,
4901,
14,
6843,
13544,
492,
25306,
15860,
12,
28073,
199,
199,
504,
655,
27021,
492,
664,
5039,
199,
199,
3,
7992,
199,
15656,
275,
1052,
199,
16334,
275,
1052,
199,
2416,
5921,
275,
1052,
199,
199,
16428,
63,
6178,
14657,
1149,
275,
334,
2416,
14,
16428,
40,
2160,
1204,
3504,
14,
16428,
2666,
1204,
3504,
14,
16428,
46,
3204,
9,
199,
199,
533,
662,
18,
12197,
24022,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
807,
275,
469,
789,
507,
198,
277,
14,
69,
2640,
275,
664,
5039,
342,
421,
198,
318,
2274,
8,
277,
12,
6111,
12,
1566,
2629,
275,
3504,
14,
16428,
568,
1204,
3504,
14,
16428,
2666,
1204,
3504,
14,
32713,
1484,
934,
304,
507,
198,
277,
14,
807,
59,
2592,
61,
275,
1566,
2629,
8299,
198,
318,
24369,
8,
277,
12,
6111,
304,
507,
198,
2264,
291,
14,
807,
59,
2592,
61,
8299,
198,
318,
11271,
8,
277,
12,
2653,
275,
488,
304,
507,
198,
893,
26,
686,
198,
82,
275,
291,
14,
69,
2640,
14,
6843,
8,
2593,
12,
291,
14,
807,
9,
507,
198,
2590,
13483,
26,
686,
198,
1107,
488,
507,
198,
1107,
519,
199,
199,
26746,
275,
662,
18,
12197,
24022,
342,
199,
199,
533,
25306,
15860,
8,
9228,
1095,
14,
1575,
4174,
15860,
1563,
304,
199,
198,
624,
33,
9655,
626,
4440,
11271,
8,
18,
10477,
421,
198,
318,
485,
873,
11757,
8,
277,
12,
6111,
304,
507,
198,
624,
7099,
15,
18408,
376,
6111,
543,
314,
28073,
1041,
507,
198,
893,
26,
686,
198,
26746,
14,
18408,
8,
2592,
9,
507,
198,
2590,
4067,
26,
686,
198,
1529,
2742,
198,
2629,
275,
378,
507,
198,
692,
11597,
14,
1989,
63,
498,
8,
2592,
304,
3656,
275,
3656,
1204,
3504,
14,
16428,
568,
507,
198,
692,
14511,
14,
1989,
63,
498,
8,
2592,
304,
3656,
275,
3656,
1204,
3504,
14,
32713,
1484,
934,
507,
198,
692,
3656,
1137,
378,
26,
686,
198,
26746,
14,
2683,
8,
2592,
12,
3656,
9,
507,
198,
2836,
26,
686,
198,
692,
3504,
5921,
14,
1989,
63,
498,
8,
2592,
304,
2150,
3504,
5921,
59,
2592,
61,
686,
9068,
198,
26746,
14,
69,
2640,
14,
20172,
24022,
342,
421,
198,
318,
485,
807,
5587,
8,
277,
12,
23378,
12,
333,
807,
304,
507,
198,
893,
26,
686,
198,
3,
314,
8837,
4340,
686,
198,
2592,
275,
23378,
14,
9843,
342,
686,
198,
3,
1852,
3238,
314,
6111,
365,
5965,
3363,
14,
221,
1010,
2005,
24325,
781,
883,
664,
686,
198,
3,
446,
17,
2348,
14,
686,
198,
77,
807,
59,
2592,
61,
507,
198,
2590,
26,
686,
198,
3,
314,
7508,
4340,
26,
5784,
2952,
25255,
342,
1443,
2153,
27307,
737,
1263,
686,
198,
3,
12427,
12,
2419,
6080,
370,
2366,
1159,
8793,
18772,
11512,
686,
198,
509,
6111,
12,
289,
3424,
315,
3504,
5921,
14,
1744,
837,
1585,
198,
692,
23378,
365,
289,
3424,
26,
1871,
198,
4785,
686,
198,
2836,
26,
1585,
198,
3,
869,
596,
12,
11703,
440,
314,
2451,
2518,
402,
1595,
31,
221,
961,
1083,
883,
1133,
1585,
198,
3,
2449,
12,
2952,
652,
10986,
6272,
1125,
15212,
1396,
1585,
198,
1107,
507,
198,
692,
333,
807,
14,
1989,
63,
498,
8,
2592,
304,
686,
198,
2264,
333,
807,
59,
2592,
61,
686,
198,
277,
423,
873,
11757,
8,
2592,
9,
421,
198,
318,
1050,
5929,
8,
277,
12,
7002,
304,
507,
198,
624,
1123,
282,
3814,
4311,
367,
6955,
402,
666,
2808,
370,
1586,
14,
507,
198,
624,
507,
198,
2592,
275,
7002,
14,
9843,
342,
507,
198,
692,
440,
11597,
14,
1989,
63,
498,
8,
2592,
304,
686,
198,
2416,
5921,
59,
2592,
61,
275,
7002,
686,
198,
15656,
59,
2592,
61,
275,
221,
413,
686,
198,
277,
423,
873,
11757,
8,
2592,
9,
421,
198,
318,
1050,
6261,
8,
277,
12,
7060,
12,
14511,
29,
16334,
12,
3504,
5921,
29,
2416,
5921,
304,
507,
198,
624,
1123,
282,
3814,
4311,
367,
6955,
402,
666,
2808,
370,
2218,
14,
507,
198,
624,
507,
198,
2592,
275,
7060,
14,
9843,
342,
507,
198,
692,
440,
14511,
14,
1989,
63,
498,
8,
2592,
304,
686,
198,
2416,
5921,
59,
2592,
61,
275,
7060,
686,
198,
16334,
59,
2592,
61,
275,
221,
413,
686,
198,
277,
423,
873,
11757,
8,
2592,
9,
421,
198,
318,
2813,
5929,
8,
277,
12,
7002,
12,
11597,
29,
15656,
304,
507,
198,
624,
5587,
282,
9496,
461,
367,
6955,
402,
666,
2808,
370,
1586,
14,
507,
198,
624,
507,
198,
1107,
291,
423,
807,
5587,
8,
5503,
12,
11597,
9,
421,
198,
318,
2813,
6261,
8,
277,
12,
7060,
12,
14511,
29,
16334,
304,
507,
198,
624,
5587,
282,
9496,
461,
367,
6955,
402,
666,
2808,
370,
2218,
14,
507,
198,
624,
507,
198,
1107,
291,
423,
807,
5587,
8,
5491,
12,
14511,
9,
421,
198,
318,
2813,
2422,
8,
277,
12,
11597,
29,
15656,
12,
14511,
29,
16334,
12,
3504,
5921,
29,
2416,
5921,
304,
507,
198,
624,
5587,
1006,
3504,
5921,
12,
436,
372,
282,
769,
402,
3062,
1041,
507,
198,
692,
291,
14,
758,
2570,
365,
440,
488,
26,
686,
198,
277,
14,
2168,
5929,
8,
277,
14,
758,
2570,
9,
507,
198,
1099,
275,
3504,
5921,
14,
1459,
342,
507,
198,
14240,
275,
3504,
5921,
14,
1612,
342,
507,
198,
15656,
14,
3584,
342,
507,
198,
16334,
14,
3584,
342,
507,
198,
2416,
5921,
14,
3584,
342,
507,
198,
509,
6111,
315,
289,
795,
26,
686,
198,
26746,
14,
18408,
8,
2592,
9,
1585,
507
] |
[
655,
27021,
18,
9655,
26,
4079,
641,
11271,
13544,
12,
1314,
365,
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
11903,
8368,
281,
26,
738,
91,
3456,
20528,
577,
676,
415,
28,
26206,
26,
84,
887,
6559,
32,
18865,
471,
18708,
14,
846,
23307,
199,
624,
199,
199,
3,
6187,
8925,
199,
646,
3504,
12,
7554,
12,
984,
199,
199,
3,
17078,
8925,
199,
504,
7390,
14,
1548,
492,
943,
12,
5988,
199,
504,
7390,
14,
4901,
492,
2446,
12,
10694,
1095,
12,
1125,
199,
3,
504,
7390,
14,
4901,
14,
6843,
13544,
492,
25306,
15860,
12,
28073,
199,
199,
504,
655,
27021,
492,
664,
5039,
199,
199,
3,
7992,
199,
15656,
275,
1052,
199,
16334,
275,
1052,
199,
2416,
5921,
275,
1052,
199,
199,
16428,
63,
6178,
14657,
1149,
275,
334,
2416,
14,
16428,
40,
2160,
1204,
3504,
14,
16428,
2666,
1204,
3504,
14,
16428,
46,
3204,
9,
199,
199,
533,
662,
18,
12197,
24022,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
807,
275,
469,
789,
507,
198,
277,
14,
69,
2640,
275,
664,
5039,
342,
421,
198,
318,
2274,
8,
277,
12,
6111,
12,
1566,
2629,
275,
3504,
14,
16428,
568,
1204,
3504,
14,
16428,
2666,
1204,
3504,
14,
32713,
1484,
934,
304,
507,
198,
277,
14,
807,
59,
2592,
61,
275,
1566,
2629,
8299,
198,
318,
24369,
8,
277,
12,
6111,
304,
507,
198,
2264,
291,
14,
807,
59,
2592,
61,
8299,
198,
318,
11271,
8,
277,
12,
2653,
275,
488,
304,
507,
198,
893,
26,
686,
198,
82,
275,
291,
14,
69,
2640,
14,
6843,
8,
2593,
12,
291,
14,
807,
9,
507,
198,
2590,
13483,
26,
686,
198,
1107,
488,
507,
198,
1107,
519,
199,
199,
26746,
275,
662,
18,
12197,
24022,
342,
199,
199,
533,
25306,
15860,
8,
9228,
1095,
14,
1575,
4174,
15860,
1563,
304,
199,
198,
624,
33,
9655,
626,
4440,
11271,
8,
18,
10477,
421,
198,
318,
485,
873,
11757,
8,
277,
12,
6111,
304,
507,
198,
624,
7099,
15,
18408,
376,
6111,
543,
314,
28073,
1041,
507,
198,
893,
26,
686,
198,
26746,
14,
18408,
8,
2592,
9,
507,
198,
2590,
4067,
26,
686,
198,
1529,
2742,
198,
2629,
275,
378,
507,
198,
692,
11597,
14,
1989,
63,
498,
8,
2592,
304,
3656,
275,
3656,
1204,
3504,
14,
16428,
568,
507,
198,
692,
14511,
14,
1989,
63,
498,
8,
2592,
304,
3656,
275,
3656,
1204,
3504,
14,
32713,
1484,
934,
507,
198,
692,
3656,
1137,
378,
26,
686,
198,
26746,
14,
2683,
8,
2592,
12,
3656,
9,
507,
198,
2836,
26,
686,
198,
692,
3504,
5921,
14,
1989,
63,
498,
8,
2592,
304,
2150,
3504,
5921,
59,
2592,
61,
686,
9068,
198,
26746,
14,
69,
2640,
14,
20172,
24022,
342,
421,
198,
318,
485,
807,
5587,
8,
277,
12,
23378,
12,
333,
807,
304,
507,
198,
893,
26,
686,
198,
3,
314,
8837,
4340,
686,
198,
2592,
275,
23378,
14,
9843,
342,
686,
198,
3,
1852,
3238,
314,
6111,
365,
5965,
3363,
14,
221,
1010,
2005,
24325,
781,
883,
664,
686,
198,
3,
446,
17,
2348,
14,
686,
198,
77,
807,
59,
2592,
61,
507,
198,
2590,
26,
686,
198,
3,
314,
7508,
4340,
26,
5784,
2952,
25255,
342,
1443,
2153,
27307,
737,
1263,
686,
198,
3,
12427,
12,
2419,
6080,
370,
2366,
1159,
8793,
18772,
11512,
686,
198,
509,
6111,
12,
289,
3424,
315,
3504,
5921,
14,
1744,
837,
1585,
198,
692,
23378,
365,
289,
3424,
26,
1871,
198,
4785,
686,
198,
2836,
26,
1585,
198,
3,
869,
596,
12,
11703,
440,
314,
2451,
2518,
402,
1595,
31,
221,
961,
1083,
883,
1133,
1585,
198,
3,
2449,
12,
2952,
652,
10986,
6272,
1125,
15212,
1396,
1585,
198,
1107,
507,
198,
692,
333,
807,
14,
1989,
63,
498,
8,
2592,
304,
686,
198,
2264,
333,
807,
59,
2592,
61,
686,
198,
277,
423,
873,
11757,
8,
2592,
9,
421,
198,
318,
1050,
5929,
8,
277,
12,
7002,
304,
507,
198,
624,
1123,
282,
3814,
4311,
367,
6955,
402,
666,
2808,
370,
1586,
14,
507,
198,
624,
507,
198,
2592,
275,
7002,
14,
9843,
342,
507,
198,
692,
440,
11597,
14,
1989,
63,
498,
8,
2592,
304,
686,
198,
2416,
5921,
59,
2592,
61,
275,
7002,
686,
198,
15656,
59,
2592,
61,
275,
221,
413,
686,
198,
277,
423,
873,
11757,
8,
2592,
9,
421,
198,
318,
1050,
6261,
8,
277,
12,
7060,
12,
14511,
29,
16334,
12,
3504,
5921,
29,
2416,
5921,
304,
507,
198,
624,
1123,
282,
3814,
4311,
367,
6955,
402,
666,
2808,
370,
2218,
14,
507,
198,
624,
507,
198,
2592,
275,
7060,
14,
9843,
342,
507,
198,
692,
440,
14511,
14,
1989,
63,
498,
8,
2592,
304,
686,
198,
2416,
5921,
59,
2592,
61,
275,
7060,
686,
198,
16334,
59,
2592,
61,
275,
221,
413,
686,
198,
277,
423,
873,
11757,
8,
2592,
9,
421,
198,
318,
2813,
5929,
8,
277,
12,
7002,
12,
11597,
29,
15656,
304,
507,
198,
624,
5587,
282,
9496,
461,
367,
6955,
402,
666,
2808,
370,
1586,
14,
507,
198,
624,
507,
198,
1107,
291,
423,
807,
5587,
8,
5503,
12,
11597,
9,
421,
198,
318,
2813,
6261,
8,
277,
12,
7060,
12,
14511,
29,
16334,
304,
507,
198,
624,
5587,
282,
9496,
461,
367,
6955,
402,
666,
2808,
370,
2218,
14,
507,
198,
624,
507,
198,
1107,
291,
423,
807,
5587,
8,
5491,
12,
14511,
9,
421,
198,
318,
2813,
2422,
8,
277,
12,
11597,
29,
15656,
12,
14511,
29,
16334,
12,
3504,
5921,
29,
2416,
5921,
304,
507,
198,
624,
5587,
1006,
3504,
5921,
12,
436,
372,
282,
769,
402,
3062,
1041,
507,
198,
692,
291,
14,
758,
2570,
365,
440,
488,
26,
686,
198,
277,
14,
2168,
5929,
8,
277,
14,
758,
2570,
9,
507,
198,
1099,
275,
3504,
5921,
14,
1459,
342,
507,
198,
14240,
275,
3504,
5921,
14,
1612,
342,
507,
198,
15656,
14,
3584,
342,
507,
198,
16334,
14,
3584,
342,
507,
198,
2416,
5921,
14,
3584,
342,
507,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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
] |
jayantk/pnp
|
experiments/dipart/scripts/visualize/generate_heatmap.py
|
1
|
1411
|
#!/usr/bin/python
# Generate heatmap of points
import numpy as np
import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
from heatmap_data import *
# image_name=
# im = plt.imread(image_name);
# implot = plt.imshow(im);
# Load the example flights dataset and conver to long-form
# flights_long = sns.load_dataset("flights")
# flights = flights_long.pivot("month", "year", "passengers")
def sample_kde_data(data):
u = np.exp(data)
z = np.sum(u)
p = (u / z) * 1000
xs = []
ys = []
for yind in xrange(len(p)):
for xind in xrange(len(p[yind])):
c = int(p[yind][xind])
xs += [xind] * c
ys += [NUM_POINTS - yind] * c
return (np.array(xs), np.array(ys))
NUM_POINTS=25
def plot_kde(data, cmap):
(xs, ys) = sample_kde_data(data)
print len(xs)
sns.kdeplot(xs, ys, cmap=cmap, shade=True, shade_lowest=False, clip=[[0,NUM_POINTS], [0, NUM_POINTS]], alpha=0.5)
# img = plt.imread("data/dqa_parts_v1/fighter-jet/fighter-jet_0000.png")
img = plt.imread("data/dqa_parts_v1/antelope/antelope_0000.png")
fig, ax = plt.subplots()
ax.imshow(img, extent=[0, NUM_POINTS, 0, NUM_POINTS])
plot_kde(neck_data3, "Blues")
# plot_kde(leg_data2, "Reds")
# plot_kde(tail_data2, "Greens")
plt.axis('off')
plt.show()
# Draw a heatmap with the numeric values in each cell
# sns.heatmap(data, cbar=False, cmap="coolwarm")
# plt.show()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
7958,
20408,
1130,
402,
4501,
199,
199,
646,
2680,
465,
980,
199,
646,
542,
371,
6161,
465,
308,
561,
199,
83,
561,
14,
409,
342,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
504,
20408,
1130,
63,
576,
492,
627,
199,
199,
3,
1834,
63,
354,
29,
199,
3,
3416,
275,
4488,
14,
1017,
739,
8,
1569,
63,
354,
2736,
199,
3,
1742,
1653,
275,
4488,
14,
20413,
8,
1017,
2736,
199,
199,
3,
7190,
314,
2893,
289,
27227,
4789,
436,
3818,
370,
1846,
13,
964,
199,
3,
289,
27227,
63,
2809,
275,
308,
561,
14,
912,
63,
5214,
480,
70,
27227,
531,
199,
3,
289,
27227,
275,
289,
27227,
63,
2809,
14,
21558,
480,
4482,
401,
298,
3403,
401,
298,
15534,
23444,
83,
531,
421,
199,
318,
2690,
63,
29461,
63,
576,
8,
576,
304,
272,
399,
275,
980,
14,
1474,
8,
576,
9,
272,
1315,
275,
980,
14,
1838,
8,
85,
9,
272,
299,
275,
334,
85,
1182,
1315,
9,
627,
5198,
339,
12965,
275,
942,
272,
19205,
275,
942,
272,
367,
612,
688,
315,
4945,
8,
552,
8,
80,
2298,
267,
367,
671,
688,
315,
4945,
8,
552,
8,
80,
59,
89,
688,
18710,
288,
286,
275,
1109,
8,
80,
59,
89,
688,
1527,
88,
688,
566,
288,
12965,
847,
359,
88,
688,
61,
627,
286,
288,
19205,
847,
359,
7125,
63,
7217,
51,
446,
612,
688,
61,
627,
286,
339,
372,
334,
1590,
14,
1144,
8,
7977,
395,
980,
14,
1144,
8,
588,
430,
421,
199,
7125,
63,
7217,
51,
29,
821,
199,
318,
5137,
63,
29461,
8,
576,
12,
14920,
304,
272,
334,
7977,
12,
19205,
9,
275,
2690,
63,
29461,
63,
576,
8,
576,
9,
272,
870,
822,
8,
7977,
9,
272,
308,
561,
14,
75,
2601,
1653,
8,
7977,
12,
19205,
12,
14920,
29,
16513,
12,
32250,
29,
549,
12,
32250,
63,
674,
597,
29,
797,
12,
11353,
16025,
16,
12,
7125,
63,
7217,
51,
467,
359,
16,
12,
11576,
63,
7217,
51,
2365,
5131,
29,
16,
14,
21,
9,
421,
199,
3,
6050,
275,
4488,
14,
1017,
739,
480,
576,
15,
68,
7096,
63,
4181,
63,
86,
17,
15,
592,
72,
351,
13,
74,
386,
15,
592,
72,
351,
13,
74,
386,
63,
993,
14,
4524,
531,
199,
4060,
275,
4488,
14,
1017,
739,
480,
576,
15,
68,
7096,
63,
4181,
63,
86,
17,
15,
8949,
14363,
15,
8949,
14363,
63,
993,
14,
4524,
531,
199,
199,
592,
12,
2185,
275,
4488,
14,
21430,
342,
199,
1219,
14,
20413,
8,
4060,
12,
13675,
1524,
16,
12,
11576,
63,
7217,
51,
12,
378,
12,
11576,
63,
7217,
51,
566,
199,
199,
2798,
63,
29461,
8,
685,
346,
63,
576,
19,
12,
298,
24613,
10138,
531,
199,
3,
5137,
63,
29461,
8,
4170,
63,
576,
18,
12,
298,
50,
5923,
531,
199,
3,
5137,
63,
29461,
8,
1521,
63,
576,
18,
12,
298,
19456,
83,
531,
199,
199,
6003,
14,
3127,
360,
1997,
358,
199,
6003,
14,
2384,
342,
199,
199,
3,
17813,
282,
20408,
1130,
543,
314,
8950,
1338,
315,
1924,
4917,
199,
3,
308,
561,
14,
16614,
1130,
8,
576,
12,
286,
1700,
29,
797,
12,
14920,
628,
18499,
10669,
531,
199,
3,
4488,
14,
2384,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
7958,
20408,
1130,
402,
4501,
199,
199,
646,
2680,
465,
980,
199,
646,
542,
371,
6161,
465,
308,
561,
199,
83,
561,
14,
409,
342,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
504,
20408,
1130,
63,
576,
492,
627,
199,
199,
3,
1834,
63,
354,
29,
199,
3,
3416,
275,
4488,
14,
1017,
739,
8,
1569,
63,
354,
2736,
199,
3,
1742,
1653,
275,
4488,
14,
20413,
8,
1017,
2736,
199,
199,
3,
7190,
314,
2893,
289,
27227,
4789,
436,
3818,
370,
1846,
13,
964,
199,
3,
289,
27227,
63,
2809,
275,
308,
561,
14,
912,
63,
5214,
480,
70,
27227,
531,
199,
3,
289,
27227,
275,
289,
27227,
63,
2809,
14,
21558,
480,
4482,
401,
298,
3403,
401,
298,
15534,
23444,
83,
531,
421,
199,
318,
2690,
63,
29461,
63,
576,
8,
576,
304,
272,
399,
275,
980,
14,
1474,
8,
576,
9,
272,
1315,
275,
980,
14,
1838,
8,
85,
9,
272,
299,
275,
334,
85,
1182,
1315,
9,
627,
5198,
339,
12965,
275,
942,
272,
19205,
275,
942,
272,
367,
612,
688,
315,
4945,
8,
552,
8,
80,
2298,
267,
367,
671,
688,
315,
4945,
8,
552,
8,
80,
59,
89,
688,
18710,
288,
286,
275,
1109,
8,
80,
59,
89,
688,
1527,
88,
688,
566,
288,
12965,
847,
359,
88,
688,
61,
627,
286,
288,
19205,
847,
359,
7125,
63,
7217,
51,
446,
612,
688,
61,
627,
286,
339,
372,
334,
1590,
14,
1144,
8,
7977,
395,
980,
14,
1144,
8,
588,
430,
421,
199,
7125,
63,
7217,
51,
29,
821,
199,
318,
5137,
63,
29461,
8,
576,
12,
14920,
304,
272,
334,
7977,
12,
19205,
9,
275,
2690,
63,
29461,
63,
576,
8,
576,
9,
272,
870,
822,
8,
7977,
9,
272,
308,
561,
14,
75,
2601,
1653,
8,
7977,
12,
19205,
12,
14920,
29,
16513,
12,
32250,
29,
549,
12,
32250,
63,
674,
597,
29,
797,
12,
11353,
16025,
16,
12,
7125,
63,
7217,
51,
467,
359,
16,
12,
11576,
63,
7217,
51,
2365,
5131,
29,
16,
14,
21,
9,
421,
199,
3,
6050,
275,
4488,
14,
1017,
739,
480,
576,
15,
68,
7096,
63,
4181,
63,
86,
17,
15,
592,
72,
351,
13,
74,
386,
15,
592,
72,
351,
13,
74,
386,
63,
993,
14,
4524,
531,
199,
4060,
275,
4488,
14,
1017,
739,
480,
576,
15,
68,
7096,
63,
4181,
63,
86,
17,
15,
8949,
14363,
15,
8949,
14363,
63,
993,
14,
4524,
531,
199,
199,
592,
12,
2185,
275,
4488,
14,
21430,
342,
199,
1219,
14,
20413,
8,
4060,
12,
13675,
1524,
16,
12,
11576,
63,
7217,
51,
12,
378,
12,
11576,
63,
7217,
51,
566,
199,
199,
2798,
63,
29461,
8,
685,
346,
63,
576,
19,
12,
298,
24613,
10138,
531,
199,
3,
5137,
63,
29461,
8,
4170,
63,
576,
18,
12,
298,
50,
5923,
531,
199,
3,
5137,
63,
29461,
8,
1521,
63,
576,
18,
12,
298,
19456,
83,
531,
199,
199,
6003,
14,
3127,
360,
1997,
358,
199,
6003,
14,
2384,
342,
199,
199,
3,
17813,
282,
20408,
1130,
543,
314,
8950,
1338,
315,
1924,
4917,
199,
3,
308,
561,
14,
16614,
1130,
8,
576,
12,
286,
1700,
29,
797,
12,
14920,
628,
18499,
10669,
531,
199,
3,
4488,
14,
2384,
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,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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lukeroge/CloudBot
|
cloudbot/reloader.py
|
33
|
2824
|
import asyncio
import os.path
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
class PluginReloader(object):
def __init__(self, bot):
"""
:type bot: cloudbot.bot.CloudBot
"""
self.observer = Observer()
self.bot = bot
self.reloading = set()
self.event_handler = PluginEventHandler(self, patterns=["*.py"])
def start(self, module_path):
"""Starts the plugin reloader
:type module_path: str
"""
self.observer.schedule(self.event_handler, module_path, recursive=False)
self.observer.start()
def stop(self):
"""Stops the plugin reloader"""
self.observer.stop()
def reload(self, path):
"""
Loads or reloads a module, given its file path. Thread safe.
:type path: str
"""
if not os.path.isfile(path):
# we check if the file still exists here because some programs modify a file before deleting
return
if isinstance(path, bytes):
path = path.decode()
self.bot.loop.call_soon_threadsafe(lambda: asyncio.async(self._reload(path), loop=self.bot.loop))
def unload(self, path):
"""
Unloads a module, given its file path. Thread safe.
:type path: str
"""
if isinstance(path, bytes):
path = path.decode()
self.bot.loop.call_soon_threadsafe(lambda: asyncio.async(self._unload(path), loop=self.bot.loop))
@asyncio.coroutine
def _reload(self, path):
if path in self.reloading:
# we already have a coroutine reloading
return
self.reloading.add(path)
# we don't want to reload more than once every 200 milliseconds, so wait that long to make sure there
# are no other file changes in that time.
yield from asyncio.sleep(0.2)
self.reloading.remove(path)
yield from self.bot.plugin_manager.load_plugin(path)
@asyncio.coroutine
def _unload(self, path):
yield from self.bot.plugin_manager.unload_plugin(path)
class PluginEventHandler(PatternMatchingEventHandler):
def __init__(self, loader, *args, **kwargs):
"""
:type loader: PluginReloader
"""
super().__init__(*args, **kwargs)
self.loader = loader
def on_created(self, event):
self.loader.reload(event.src_path)
def on_deleted(self, event):
self.loader.unload(event.src_path)
def on_modified(self, event):
self.loader.reload(event.src_path)
def on_moved(self, event):
# only load if it's moved to a .py file
if event.dest_path.endswith(".py" if isinstance(event.dest_path, str) else b".py"):
self.loader.reload(event.dest_path)
|
gpl-3.0
|
[
646,
16195,
199,
646,
747,
14,
515,
199,
199,
504,
9626,
13889,
14,
2873,
5871,
492,
17985,
1000,
199,
504,
9626,
13889,
14,
4368,
492,
27019,
14215,
2390,
2461,
421,
199,
533,
11349,
497,
3422,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
5888,
304,
267,
408,
267,
520,
466,
5888,
26,
2463,
8301,
357,
14,
3018,
14,
9089,
14026,
267,
408,
267,
291,
14,
23968,
275,
17985,
1000,
342,
267,
291,
14,
3018,
275,
5888,
267,
291,
14,
264,
8786,
275,
663,
342,
267,
291,
14,
1430,
63,
2232,
275,
11349,
2390,
2461,
8,
277,
12,
7970,
6270,
4856,
647,
3135,
339,
347,
1343,
8,
277,
12,
859,
63,
515,
304,
267,
408,
32142,
314,
3589,
295,
3422,
267,
520,
466,
859,
63,
515,
26,
620,
267,
408,
267,
291,
14,
23968,
14,
7211,
8,
277,
14,
1430,
63,
2232,
12,
859,
63,
515,
12,
9133,
29,
797,
9,
267,
291,
14,
23968,
14,
928,
342,
339,
347,
3631,
8,
277,
304,
267,
408,
933,
1483,
314,
3589,
295,
3422,
624,
267,
291,
14,
23968,
14,
2379,
342,
339,
347,
13101,
8,
277,
12,
931,
304,
267,
408,
267,
30367,
503,
295,
3640,
282,
859,
12,
1627,
2399,
570,
931,
14,
11086,
5048,
14,
398,
520,
466,
931,
26,
620,
267,
408,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
327,
781,
1104,
340,
314,
570,
5139,
3495,
2348,
2952,
2005,
18572,
2811,
282,
570,
2544,
13794,
288,
372,
398,
340,
1228,
8,
515,
12,
2783,
304,
288,
931,
275,
931,
14,
2708,
342,
267,
291,
14,
3018,
14,
3813,
14,
1250,
63,
1152,
265,
63,
2671,
3489,
8,
2734,
26,
16195,
14,
4146,
8,
277,
423,
9233,
8,
515,
395,
4438,
29,
277,
14,
3018,
14,
3813,
430,
339,
347,
625,
912,
8,
277,
12,
931,
304,
267,
408,
267,
1910,
3640,
282,
859,
12,
1627,
2399,
570,
931,
14,
11086,
5048,
14,
398,
520,
466,
931,
26,
620,
267,
408,
267,
340,
1228,
8,
515,
12,
2783,
304,
288,
931,
275,
931,
14,
2708,
342,
267,
291,
14,
3018,
14,
3813,
14,
1250,
63,
1152,
265,
63,
2671,
3489,
8,
2734,
26,
16195,
14,
4146,
8,
277,
423,
25477,
8,
515,
395,
4438,
29,
277,
14,
3018,
14,
3813,
430,
2378,
768,
19343,
14,
16675,
272,
347,
485,
9233,
8,
277,
12,
931,
304,
267,
340,
931,
315,
291,
14,
264,
8786,
26,
288,
327,
781,
2575,
1172,
282,
1970,
13242,
295,
8786,
288,
372,
267,
291,
14,
264,
8786,
14,
525,
8,
515,
9,
267,
327,
781,
2793,
1133,
2934,
370,
13101,
1655,
2419,
5403,
4036,
1926,
21131,
12,
880,
3618,
626,
1846,
370,
1852,
3238,
2337,
267,
327,
787,
949,
1163,
570,
4493,
315,
626,
900,
14,
267,
1995,
687,
16195,
14,
4532,
8,
16,
14,
18,
9,
267,
291,
14,
264,
8786,
14,
2168,
8,
515,
9,
267,
1995,
687,
291,
14,
3018,
14,
2718,
63,
2609,
14,
912,
63,
2718,
8,
515,
9,
2378,
768,
19343,
14,
16675,
272,
347,
485,
25477,
8,
277,
12,
931,
304,
267,
1995,
687,
291,
14,
3018,
14,
2718,
63,
2609,
14,
25477,
63,
2718,
8,
515,
9,
421,
199,
533,
11349,
2390,
2461,
8,
9959,
14215,
2390,
2461,
304,
272,
347,
636,
826,
721,
277,
12,
5077,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
520,
466,
5077,
26,
11349,
497,
3422,
267,
408,
267,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
3422,
275,
5077,
339,
347,
641,
63,
3966,
8,
277,
12,
1566,
304,
267,
291,
14,
3422,
14,
9233,
8,
1430,
14,
2164,
63,
515,
9,
339,
347,
641,
63,
6062,
8,
277,
12,
1566,
304,
267,
291,
14,
3422,
14,
25477,
8,
1430,
14,
2164,
63,
515,
9,
339,
347,
641,
63,
5540,
8,
277,
12,
1566,
304,
267,
291,
14,
3422,
14,
9233,
8,
1430,
14,
2164,
63,
515,
9,
339,
347,
641,
63,
3539,
8,
277,
12,
1566,
304,
267,
327,
1454,
2248,
340,
652,
1159,
12155,
370,
282,
1275,
647,
570,
267,
340,
1566,
14,
2614,
63,
515,
14,
4130,
9520,
647,
2,
340,
1228,
8,
1430,
14,
2614,
63,
515,
12,
620,
9,
587,
330,
1674,
647,
2349,
288,
291,
14,
3422,
14,
9233,
8,
1430,
14,
2614,
63,
515,
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
] |
[
16195,
199,
646,
747,
14,
515,
199,
199,
504,
9626,
13889,
14,
2873,
5871,
492,
17985,
1000,
199,
504,
9626,
13889,
14,
4368,
492,
27019,
14215,
2390,
2461,
421,
199,
533,
11349,
497,
3422,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
5888,
304,
267,
408,
267,
520,
466,
5888,
26,
2463,
8301,
357,
14,
3018,
14,
9089,
14026,
267,
408,
267,
291,
14,
23968,
275,
17985,
1000,
342,
267,
291,
14,
3018,
275,
5888,
267,
291,
14,
264,
8786,
275,
663,
342,
267,
291,
14,
1430,
63,
2232,
275,
11349,
2390,
2461,
8,
277,
12,
7970,
6270,
4856,
647,
3135,
339,
347,
1343,
8,
277,
12,
859,
63,
515,
304,
267,
408,
32142,
314,
3589,
295,
3422,
267,
520,
466,
859,
63,
515,
26,
620,
267,
408,
267,
291,
14,
23968,
14,
7211,
8,
277,
14,
1430,
63,
2232,
12,
859,
63,
515,
12,
9133,
29,
797,
9,
267,
291,
14,
23968,
14,
928,
342,
339,
347,
3631,
8,
277,
304,
267,
408,
933,
1483,
314,
3589,
295,
3422,
624,
267,
291,
14,
23968,
14,
2379,
342,
339,
347,
13101,
8,
277,
12,
931,
304,
267,
408,
267,
30367,
503,
295,
3640,
282,
859,
12,
1627,
2399,
570,
931,
14,
11086,
5048,
14,
398,
520,
466,
931,
26,
620,
267,
408,
267,
340,
440,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
327,
781,
1104,
340,
314,
570,
5139,
3495,
2348,
2952,
2005,
18572,
2811,
282,
570,
2544,
13794,
288,
372,
398,
340,
1228,
8,
515,
12,
2783,
304,
288,
931,
275,
931,
14,
2708,
342,
267,
291,
14,
3018,
14,
3813,
14,
1250,
63,
1152,
265,
63,
2671,
3489,
8,
2734,
26,
16195,
14,
4146,
8,
277,
423,
9233,
8,
515,
395,
4438,
29,
277,
14,
3018,
14,
3813,
430,
339,
347,
625,
912,
8,
277,
12,
931,
304,
267,
408,
267,
1910,
3640,
282,
859,
12,
1627,
2399,
570,
931,
14,
11086,
5048,
14,
398,
520,
466,
931,
26,
620,
267,
408,
267,
340,
1228,
8,
515,
12,
2783,
304,
288,
931,
275,
931,
14,
2708,
342,
267,
291,
14,
3018,
14,
3813,
14,
1250,
63,
1152,
265,
63,
2671,
3489,
8,
2734,
26,
16195,
14,
4146,
8,
277,
423,
25477,
8,
515,
395,
4438,
29,
277,
14,
3018,
14,
3813,
430,
2378,
768,
19343,
14,
16675,
272,
347,
485,
9233,
8,
277,
12,
931,
304,
267,
340,
931,
315,
291,
14,
264,
8786,
26,
288,
327,
781,
2575,
1172,
282,
1970,
13242,
295,
8786,
288,
372,
267,
291,
14,
264,
8786,
14,
525,
8,
515,
9,
267,
327,
781,
2793,
1133,
2934,
370,
13101,
1655,
2419,
5403,
4036,
1926,
21131,
12,
880,
3618,
626,
1846,
370,
1852,
3238,
2337,
267,
327,
787,
949,
1163,
570,
4493,
315,
626,
900,
14,
267,
1995,
687,
16195,
14,
4532,
8,
16,
14,
18,
9,
267,
291,
14,
264,
8786,
14,
2168,
8,
515,
9,
267,
1995,
687,
291,
14,
3018,
14,
2718,
63,
2609,
14,
912,
63,
2718,
8,
515,
9,
2378,
768,
19343,
14,
16675,
272,
347,
485,
25477,
8,
277,
12,
931,
304,
267,
1995,
687,
291,
14,
3018,
14,
2718,
63,
2609,
14,
25477,
63,
2718,
8,
515,
9,
421,
199,
533,
11349,
2390,
2461,
8,
9959,
14215,
2390,
2461,
304,
272,
347,
636,
826,
721,
277,
12,
5077,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
520,
466,
5077,
26,
11349,
497,
3422,
267,
408,
267,
1613,
11027,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
3422,
275,
5077,
339,
347,
641,
63,
3966,
8,
277,
12,
1566,
304,
267,
291,
14,
3422,
14,
9233,
8,
1430,
14,
2164,
63,
515,
9,
339,
347,
641,
63,
6062,
8,
277,
12,
1566,
304,
267,
291,
14,
3422,
14,
25477,
8,
1430,
14,
2164,
63,
515,
9,
339,
347,
641,
63,
5540,
8,
277,
12,
1566,
304,
267,
291,
14,
3422,
14,
9233,
8,
1430,
14,
2164,
63,
515,
9,
339,
347,
641,
63,
3539,
8,
277,
12,
1566,
304,
267,
327,
1454,
2248,
340,
652,
1159,
12155,
370,
282,
1275,
647,
570,
267,
340,
1566,
14,
2614,
63,
515,
14,
4130,
9520,
647,
2,
340,
1228,
8,
1430,
14,
2614,
63,
515,
12,
620,
9,
587,
330,
1674,
647,
2349,
288,
291,
14,
3422,
14,
9233,
8,
1430,
14,
2614,
63,
515,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
actframework/FrameworkBenchmarks
|
toolset/benchmark/framework_test.py
|
2
|
7268
|
import os
import traceback
from requests import ConnectionError
from toolset.utils.output_helper import log
# Cross-platform colored text
from colorama import Fore, Style
class FrameworkTest:
def __init__(self, name, directory, benchmarker, runTests,
args):
'''
Constructor
'''
self.name = name
self.directory = directory
self.benchmarker = benchmarker
self.runTests = runTests
self.approach = ""
self.classification = ""
self.database = ""
self.framework = ""
self.language = ""
self.orm = ""
self.platform = ""
self.webserver = ""
self.os = ""
self.database_os = ""
self.display_name = ""
self.notes = ""
self.port = ""
self.versus = ""
self.__dict__.update(args)
##########################################################################################
# Public Methods
##########################################################################################
def start(self):
'''
Start the test implementation
'''
test_log_dir = os.path.join(self.benchmarker.results.directory, self.name.lower())
build_log_dir = os.path.join(test_log_dir, 'build')
run_log_dir = os.path.join(test_log_dir, 'run')
try:
os.makedirs(build_log_dir)
except OSError:
pass
try:
os.makedirs(run_log_dir)
except OSError:
pass
result = self.benchmarker.docker_helper.build(self, build_log_dir)
if result != 0:
return None
return self.benchmarker.docker_helper.run(self, run_log_dir)
def is_accepting_requests(self):
'''
Determines whether this test implementation is up and accepting
requests.
'''
test_type = None
for any_type in self.runTests:
test_type = any_type
break
url = "http://%s:%s%s" % (self.benchmarker.config.server_host,
self.port,
self.runTests[test_type].get_url())
return self.benchmarker.docker_helper.test_client_connection(url)
def verify_urls(self):
'''
Verifys each of the URLs for this test. This will simply curl the URL and
check for it's return status. For each url, a flag will be set on this
object for whether or not it passed.
Returns True if all verifications succeeded
'''
log_path = os.path.join(self.benchmarker.results.directory, self.name.lower())
result = True
def verify_type(test_type):
verificationPath = os.path.join(log_path, test_type)
try:
os.makedirs(verificationPath)
except OSError:
pass
with open(os.path.join(verificationPath, 'verification.txt'),
'w') as verification:
test = self.runTests[test_type]
log("VERIFYING %s" % test_type.upper(),
file=verification,
border='-',
color=Fore.WHITE + Style.BRIGHT)
base_url = "http://%s:%s" % (
self.benchmarker.config.server_host, self.port)
try:
# Verifies headers from the server. This check is made from the
# App Server using Pythons requests module. Will do a second check from
# the client to make sure the server isn't only accepting connections
# from localhost on a multi-machine setup.
results = test.verify(base_url)
# Now verify that the url is reachable from the client machine, unless
# we're already failing
if not any(result == 'fail'
for (result, reason, url) in results):
self.benchmarker.docker_helper.test_client_connection(
base_url + test.get_url())
except ConnectionError as e:
results = [('fail', "Server did not respond to request",
base_url)]
log("Verifying test %s for %s caused an exception: %s" %
(test_type, self.name, e),
color=Fore.RED)
except Exception as e:
results = [('fail', """Caused Exception in TFB
This almost certainly means your return value is incorrect,
but also that you have found a bug. Please submit an issue
including this message: %s\n%s""" % (e, traceback.format_exc()),
base_url)]
log("Verifying test %s for %s caused an exception: %s" %
(test_type, self.name, e),
color=Fore.RED)
traceback.format_exc()
test.failed = any(
result == 'fail' for (result, reason, url) in results)
test.warned = any(
result == 'warn' for (result, reason, url) in results)
test.passed = all(
result == 'pass' for (result, reason, url) in results)
def output_result(result, reason, url):
specific_rules_url = "http://frameworkbenchmarks.readthedocs.org/en/latest/Project-Information/Framework-Tests/#specific-test-requirements"
color = Fore.GREEN
if result.upper() == "WARN":
color = Fore.YELLOW
elif result.upper() == "FAIL":
color = Fore.RED
log(" {!s}{!s}{!s} for {!s}".format(
color, result.upper(), Style.RESET_ALL, url),
file=verification)
if reason is not None and len(reason) != 0:
for line in reason.splitlines():
log(" " + line, file=verification)
if not test.passed:
log(" See {!s}".format(specific_rules_url),
file=verification)
[output_result(r1, r2, url) for (r1, r2, url) in results]
if test.failed:
test.output_headers_and_body()
self.benchmarker.results.report_verify_results(self, test_type, 'fail')
elif test.warned:
test.output_headers_and_body()
self.benchmarker.results.report_verify_results(self, test_type, 'warn')
elif test.passed:
self.benchmarker.results.report_verify_results(self, test_type, 'pass')
else:
raise Exception(
"Unknown error - test did not pass,warn,or fail")
result = True
for test_type in self.runTests:
verify_type(test_type)
if self.runTests[test_type].failed:
result = False
return result
|
bsd-3-clause
|
[
646,
747,
199,
646,
5190,
199,
504,
4145,
492,
25417,
199,
199,
504,
20070,
14,
1208,
14,
1199,
63,
3676,
492,
943,
199,
199,
3,
28965,
13,
3246,
32076,
1318,
199,
504,
3164,
14541,
492,
21684,
12,
19442,
421,
199,
533,
22545,
774,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2082,
12,
26456,
4211,
12,
1255,
2925,
12,
326,
1249,
304,
267,
1449,
267,
20297,
267,
1449,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3619,
275,
2082,
267,
291,
14,
16571,
4211,
275,
26456,
4211,
267,
291,
14,
1065,
2925,
275,
1255,
2925,
267,
291,
14,
11227,
1225,
275,
3087,
267,
291,
14,
14368,
275,
3087,
267,
291,
14,
4659,
275,
3087,
267,
291,
14,
4857,
275,
3087,
267,
291,
14,
3671,
275,
3087,
267,
291,
14,
1025,
275,
3087,
267,
291,
14,
3246,
275,
3087,
267,
291,
14,
29819,
275,
3087,
267,
291,
14,
736,
275,
3087,
267,
291,
14,
4659,
63,
736,
275,
3087,
267,
291,
14,
2918,
63,
354,
275,
3087,
267,
291,
14,
5983,
275,
3087,
267,
291,
14,
719,
275,
3087,
267,
291,
14,
14895,
527,
275,
3087,
398,
291,
855,
807,
4343,
873,
8,
589,
9,
339,
15779,
6565,
309,
272,
327,
1684,
17653,
272,
15779,
6565,
309,
339,
347,
1343,
8,
277,
304,
267,
1449,
267,
7707,
314,
511,
4514,
267,
1449,
267,
511,
63,
793,
63,
694,
275,
747,
14,
515,
14,
904,
8,
277,
14,
16571,
4211,
14,
2604,
14,
3619,
12,
291,
14,
354,
14,
2325,
1012,
267,
1900,
63,
793,
63,
694,
275,
747,
14,
515,
14,
904,
8,
396,
63,
793,
63,
694,
12,
283,
1506,
358,
267,
1255,
63,
793,
63,
694,
275,
747,
14,
515,
14,
904,
8,
396,
63,
793,
63,
694,
12,
283,
1065,
358,
398,
862,
26,
288,
747,
14,
8347,
8,
1506,
63,
793,
63,
694,
9,
267,
871,
6440,
26,
288,
986,
267,
862,
26,
288,
747,
14,
8347,
8,
1065,
63,
793,
63,
694,
9,
267,
871,
6440,
26,
288,
986,
398,
754,
275,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
1506,
8,
277,
12,
1900,
63,
793,
63,
694,
9,
267,
340,
754,
1137,
378,
26,
288,
372,
488,
398,
372,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
1065,
8,
277,
12,
1255,
63,
793,
63,
694,
9,
339,
347,
365,
63,
5694,
316,
63,
6615,
8,
277,
304,
267,
1449,
267,
22391,
3775,
642,
511,
4514,
365,
1536,
436,
32163,
267,
4145,
14,
267,
1449,
267,
511,
63,
466,
275,
488,
267,
367,
1263,
63,
466,
315,
291,
14,
1065,
2925,
26,
288,
511,
63,
466,
275,
1263,
63,
466,
288,
2059,
398,
1166,
275,
298,
1014,
13827,
83,
2689,
83,
5,
83,
2,
450,
334,
277,
14,
16571,
4211,
14,
888,
14,
1000,
63,
1102,
12,
3303,
291,
14,
719,
12,
3303,
291,
14,
1065,
2925,
59,
396,
63,
466,
1055,
362,
63,
633,
1012,
398,
372,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
396,
63,
1258,
63,
2105,
8,
633,
9,
339,
347,
4911,
63,
3603,
8,
277,
304,
267,
1449,
267,
5444,
692,
588,
1924,
402,
314,
10867,
367,
642,
511,
14,
961,
911,
9329,
26145,
314,
2851,
436,
267,
1104,
367,
652,
1159,
372,
2004,
14,
2104,
1924,
1166,
12,
282,
3305,
911,
506,
663,
641,
642,
267,
909,
367,
3775,
503,
440,
652,
3032,
14,
267,
1803,
715,
340,
1006,
14786,
83,
19268,
267,
1449,
267,
943,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
16571,
4211,
14,
2604,
14,
3619,
12,
291,
14,
354,
14,
2325,
1012,
267,
754,
275,
715,
398,
347,
4911,
63,
466,
8,
396,
63,
466,
304,
288,
14786,
2042,
275,
747,
14,
515,
14,
904,
8,
793,
63,
515,
12,
511,
63,
466,
9,
288,
862,
26,
355,
747,
14,
8347,
8,
16257,
2042,
9,
288,
871,
6440,
26,
355,
986,
288,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
16257,
2042,
12,
283,
16257,
14,
2424,
659,
1993,
283,
87,
358,
465,
14786,
26,
355,
511,
275,
291,
14,
1065,
2925,
59,
396,
63,
466,
61,
355,
943,
480,
22443,
1206,
450,
83,
2,
450,
511,
63,
466,
14,
4142,
1062,
490,
570,
29,
16257,
12,
490,
9162,
534,
14382,
490,
3164,
29,
13099,
14,
18817,
435,
19442,
14,
30976,
9,
2234,
1300,
63,
633,
275,
298,
1014,
13827,
83,
2689,
83,
2,
450,
334,
490,
291,
14,
16571,
4211,
14,
888,
14,
1000,
63,
1102,
12,
291,
14,
719,
9,
2234,
862,
26,
490,
327,
26114,
2323,
687,
314,
1654,
14,
961,
1104,
365,
6326,
687,
314,
490,
327,
4693,
7146,
1808,
2018,
83,
4145,
859,
14,
12823,
886,
282,
3499,
1104,
687,
490,
327,
314,
1890,
370,
1852,
3238,
314,
1654,
5712,
1133,
1454,
32163,
6947,
490,
327,
687,
11667,
641,
282,
3510,
13,
6744,
3272,
14,
490,
2058,
275,
511,
14,
4712,
8,
1095,
63,
633,
9,
4951,
327,
7356,
4911,
626,
314,
1166,
365,
29542,
687,
314,
1890,
6844,
12,
7444,
490,
327,
781,
3984,
2575,
18648,
490,
340,
440,
1263,
8,
1099,
508,
283,
1633,
7,
3044,
367,
334,
1099,
12,
4499,
12,
1166,
9,
315,
2058,
304,
717,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
396,
63,
1258,
63,
2105,
8,
1169,
1300,
63,
633,
435,
511,
14,
362,
63,
633,
1012,
355,
871,
25417,
465,
325,
26,
490,
2058,
275,
4274,
1633,
297,
298,
3120,
8103,
440,
22722,
370,
1056,
401,
1816,
1300,
63,
633,
1874,
490,
943,
480,
7496,
316,
511,
450,
83,
367,
450,
83,
18104,
376,
1919,
26,
450,
83,
2,
450,
717,
334,
396,
63,
466,
12,
291,
14,
354,
12,
325,
395,
717,
3164,
29,
13099,
14,
7387,
9,
355,
871,
2186,
465,
325,
26,
490,
2058,
275,
4274,
1633,
297,
408,
3630,
2972,
2186,
315,
377,
8223,
288,
961,
18871,
9842,
590,
4910,
2195,
372,
574,
365,
8927,
12,
288,
1325,
2597,
626,
1265,
1172,
1911,
282,
6519,
14,
7754,
11482,
376,
4976,
288,
5893,
642,
1245,
26,
450,
83,
60,
78,
5,
83,
624,
450,
334,
69,
12,
5190,
14,
908,
63,
2804,
4000,
1816,
1300,
63,
633,
1874
] |
[
747,
199,
646,
5190,
199,
504,
4145,
492,
25417,
199,
199,
504,
20070,
14,
1208,
14,
1199,
63,
3676,
492,
943,
199,
199,
3,
28965,
13,
3246,
32076,
1318,
199,
504,
3164,
14541,
492,
21684,
12,
19442,
421,
199,
533,
22545,
774,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2082,
12,
26456,
4211,
12,
1255,
2925,
12,
326,
1249,
304,
267,
1449,
267,
20297,
267,
1449,
267,
291,
14,
354,
275,
536,
267,
291,
14,
3619,
275,
2082,
267,
291,
14,
16571,
4211,
275,
26456,
4211,
267,
291,
14,
1065,
2925,
275,
1255,
2925,
267,
291,
14,
11227,
1225,
275,
3087,
267,
291,
14,
14368,
275,
3087,
267,
291,
14,
4659,
275,
3087,
267,
291,
14,
4857,
275,
3087,
267,
291,
14,
3671,
275,
3087,
267,
291,
14,
1025,
275,
3087,
267,
291,
14,
3246,
275,
3087,
267,
291,
14,
29819,
275,
3087,
267,
291,
14,
736,
275,
3087,
267,
291,
14,
4659,
63,
736,
275,
3087,
267,
291,
14,
2918,
63,
354,
275,
3087,
267,
291,
14,
5983,
275,
3087,
267,
291,
14,
719,
275,
3087,
267,
291,
14,
14895,
527,
275,
3087,
398,
291,
855,
807,
4343,
873,
8,
589,
9,
339,
15779,
6565,
309,
272,
327,
1684,
17653,
272,
15779,
6565,
309,
339,
347,
1343,
8,
277,
304,
267,
1449,
267,
7707,
314,
511,
4514,
267,
1449,
267,
511,
63,
793,
63,
694,
275,
747,
14,
515,
14,
904,
8,
277,
14,
16571,
4211,
14,
2604,
14,
3619,
12,
291,
14,
354,
14,
2325,
1012,
267,
1900,
63,
793,
63,
694,
275,
747,
14,
515,
14,
904,
8,
396,
63,
793,
63,
694,
12,
283,
1506,
358,
267,
1255,
63,
793,
63,
694,
275,
747,
14,
515,
14,
904,
8,
396,
63,
793,
63,
694,
12,
283,
1065,
358,
398,
862,
26,
288,
747,
14,
8347,
8,
1506,
63,
793,
63,
694,
9,
267,
871,
6440,
26,
288,
986,
267,
862,
26,
288,
747,
14,
8347,
8,
1065,
63,
793,
63,
694,
9,
267,
871,
6440,
26,
288,
986,
398,
754,
275,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
1506,
8,
277,
12,
1900,
63,
793,
63,
694,
9,
267,
340,
754,
1137,
378,
26,
288,
372,
488,
398,
372,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
1065,
8,
277,
12,
1255,
63,
793,
63,
694,
9,
339,
347,
365,
63,
5694,
316,
63,
6615,
8,
277,
304,
267,
1449,
267,
22391,
3775,
642,
511,
4514,
365,
1536,
436,
32163,
267,
4145,
14,
267,
1449,
267,
511,
63,
466,
275,
488,
267,
367,
1263,
63,
466,
315,
291,
14,
1065,
2925,
26,
288,
511,
63,
466,
275,
1263,
63,
466,
288,
2059,
398,
1166,
275,
298,
1014,
13827,
83,
2689,
83,
5,
83,
2,
450,
334,
277,
14,
16571,
4211,
14,
888,
14,
1000,
63,
1102,
12,
3303,
291,
14,
719,
12,
3303,
291,
14,
1065,
2925,
59,
396,
63,
466,
1055,
362,
63,
633,
1012,
398,
372,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
396,
63,
1258,
63,
2105,
8,
633,
9,
339,
347,
4911,
63,
3603,
8,
277,
304,
267,
1449,
267,
5444,
692,
588,
1924,
402,
314,
10867,
367,
642,
511,
14,
961,
911,
9329,
26145,
314,
2851,
436,
267,
1104,
367,
652,
1159,
372,
2004,
14,
2104,
1924,
1166,
12,
282,
3305,
911,
506,
663,
641,
642,
267,
909,
367,
3775,
503,
440,
652,
3032,
14,
267,
1803,
715,
340,
1006,
14786,
83,
19268,
267,
1449,
267,
943,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
16571,
4211,
14,
2604,
14,
3619,
12,
291,
14,
354,
14,
2325,
1012,
267,
754,
275,
715,
398,
347,
4911,
63,
466,
8,
396,
63,
466,
304,
288,
14786,
2042,
275,
747,
14,
515,
14,
904,
8,
793,
63,
515,
12,
511,
63,
466,
9,
288,
862,
26,
355,
747,
14,
8347,
8,
16257,
2042,
9,
288,
871,
6440,
26,
355,
986,
288,
543,
1551,
8,
736,
14,
515,
14,
904,
8,
16257,
2042,
12,
283,
16257,
14,
2424,
659,
1993,
283,
87,
358,
465,
14786,
26,
355,
511,
275,
291,
14,
1065,
2925,
59,
396,
63,
466,
61,
355,
943,
480,
22443,
1206,
450,
83,
2,
450,
511,
63,
466,
14,
4142,
1062,
490,
570,
29,
16257,
12,
490,
9162,
534,
14382,
490,
3164,
29,
13099,
14,
18817,
435,
19442,
14,
30976,
9,
2234,
1300,
63,
633,
275,
298,
1014,
13827,
83,
2689,
83,
2,
450,
334,
490,
291,
14,
16571,
4211,
14,
888,
14,
1000,
63,
1102,
12,
291,
14,
719,
9,
2234,
862,
26,
490,
327,
26114,
2323,
687,
314,
1654,
14,
961,
1104,
365,
6326,
687,
314,
490,
327,
4693,
7146,
1808,
2018,
83,
4145,
859,
14,
12823,
886,
282,
3499,
1104,
687,
490,
327,
314,
1890,
370,
1852,
3238,
314,
1654,
5712,
1133,
1454,
32163,
6947,
490,
327,
687,
11667,
641,
282,
3510,
13,
6744,
3272,
14,
490,
2058,
275,
511,
14,
4712,
8,
1095,
63,
633,
9,
4951,
327,
7356,
4911,
626,
314,
1166,
365,
29542,
687,
314,
1890,
6844,
12,
7444,
490,
327,
781,
3984,
2575,
18648,
490,
340,
440,
1263,
8,
1099,
508,
283,
1633,
7,
3044,
367,
334,
1099,
12,
4499,
12,
1166,
9,
315,
2058,
304,
717,
291,
14,
16571,
4211,
14,
9991,
63,
3676,
14,
396,
63,
1258,
63,
2105,
8,
1169,
1300,
63,
633,
435,
511,
14,
362,
63,
633,
1012,
355,
871,
25417,
465,
325,
26,
490,
2058,
275,
4274,
1633,
297,
298,
3120,
8103,
440,
22722,
370,
1056,
401,
1816,
1300,
63,
633,
1874,
490,
943,
480,
7496,
316,
511,
450,
83,
367,
450,
83,
18104,
376,
1919,
26,
450,
83,
2,
450,
717,
334,
396,
63,
466,
12,
291,
14,
354,
12,
325,
395,
717,
3164,
29,
13099,
14,
7387,
9,
355,
871,
2186,
465,
325,
26,
490,
2058,
275,
4274,
1633,
297,
408,
3630,
2972,
2186,
315,
377,
8223,
288,
961,
18871,
9842,
590,
4910,
2195,
372,
574,
365,
8927,
12,
288,
1325,
2597,
626,
1265,
1172,
1911,
282,
6519,
14,
7754,
11482,
376,
4976,
288,
5893,
642,
1245,
26,
450,
83,
60,
78,
5,
83,
624,
450,
334,
69,
12,
5190,
14,
908,
63,
2804,
4000,
1816,
1300,
63,
633,
1874,
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
] |
untitaker/vdirsyncer
|
docs/conf.py
|
1
|
2718
|
# -*- coding: utf-8 -*-
import datetime
import os
import setuptools_scm
extensions = ['sphinx.ext.autodoc']
templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
project = u'vdirsyncer'
copyright = (u'2014-{}, Markus Unterwaditzer & contributors'
.format(datetime.date.today().strftime('%Y')))
release = setuptools_scm.get_version(root='..', relative_to=__file__)
version = '.'.join(release.split('.')[:2]) # The short X.Y version.
rst_epilog = '.. |vdirsyncer_version| replace:: %s' % release
exclude_patterns = ['_build']
pygments_style = 'sphinx'
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
try:
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
except ImportError:
html_theme = 'default'
if not on_rtd:
print('-' * 74)
print('Warning: sphinx-rtd-theme not installed, building with default '
'theme.')
print('-' * 74)
html_static_path = ['_static']
htmlhelp_basename = 'vdirsyncerdoc'
latex_elements = {}
latex_documents = [
('index', 'vdirsyncer.tex', u'vdirsyncer Documentation',
u'Markus Unterwaditzer', 'manual'),
]
man_pages = [
('index', 'vdirsyncer', u'vdirsyncer Documentation',
[u'Markus Unterwaditzer'], 1)
]
texinfo_documents = [
('index', 'vdirsyncer', u'vdirsyncer Documentation',
u'Markus Unterwaditzer', 'vdirsyncer',
'Synchronize calendars and contacts.', 'Miscellaneous'),
]
def github_issue_role(name, rawtext, text, lineno, inliner,
options={}, content=()): # noqa: B006
try:
issue_num = int(text)
if issue_num <= 0:
raise ValueError()
except ValueError:
msg = inliner.reporter.error('Invalid GitHub issue: {}'.format(text),
line=lineno)
prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg]
from docutils import nodes
PROJECT_HOME = 'https://github.com/pimutils/vdirsyncer'
link = '{}/{}/{}'.format(PROJECT_HOME,
'issues' if name == 'gh' else 'pull',
issue_num)
linktext = ('issue #{}' if name == 'gh'
else 'pull request #{}').format(issue_num)
node = nodes.reference(rawtext, linktext, refuri=link,
**options)
return [node], []
def setup(app):
from sphinx.domains.python import PyObject
app.add_object_type('storage', 'storage', 'pair: %s; storage',
doc_field_types=PyObject.doc_field_types)
app.add_role('gh', github_issue_role)
app.add_role('ghpr', github_issue_role)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2197,
199,
646,
747,
199,
199,
646,
9116,
63,
17143,
199,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
418,
199,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
1715,
275,
399,
7,
86,
3220,
1870,
281,
7,
199,
7307,
275,
334,
85,
7,
7280,
24185,
1386,
7173,
527,
1910,
351,
758,
1741,
2282,
1253,
8417,
7,
1467,
1275,
908,
8,
2083,
14,
602,
14,
8136,
1252,
6205,
3508,
57,
7058,
199,
199,
3221,
275,
9116,
63,
17143,
14,
362,
63,
1023,
8,
1231,
534,
703,
297,
3847,
63,
475,
18971,
493,
3368,
199,
1023,
275,
15671,
904,
8,
3221,
14,
1294,
7563,
1491,
18,
566,
221,
327,
710,
3974,
1323,
14,
57,
1015,
14,
199,
199,
8332,
63,
28349,
275,
11541,
1204,
86,
3220,
1870,
281,
63,
1023,
92,
3350,
447,
450,
83,
7,
450,
4683,
199,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
265,
63,
29048,
275,
747,
14,
2314,
14,
362,
360,
5670,
2080,
1149,
47,
3298,
297,
488,
9,
508,
283,
549,
7,
199,
199,
893,
26,
272,
492,
15882,
63,
29048,
63,
7915,
272,
3517,
63,
7915,
275,
283,
8008,
63,
29048,
63,
7915,
7,
272,
3517,
63,
7915,
63,
515,
275,
359,
8008,
63,
29048,
63,
7915,
14,
362,
63,
1360,
63,
7915,
63,
515,
5106,
199,
2590,
3545,
26,
272,
3517,
63,
7915,
275,
283,
885,
7,
272,
340,
440,
641,
63,
29048,
26,
267,
870,
3654,
7,
627,
9720,
9,
267,
870,
360,
3849,
26,
15882,
13,
29048,
13,
7915,
440,
4903,
12,
10015,
543,
849,
283,
1598,
283,
7915,
2659,
267,
870,
3654,
7,
627,
9720,
9,
199,
199,
1360,
63,
1986,
63,
515,
275,
4044,
1986,
418,
199,
29505,
63,
4846,
275,
283,
86,
3220,
1870,
281,
1301,
7,
199,
199,
7572,
63,
5527,
275,
1052,
199,
7572,
63,
12233,
275,
359,
272,
661,
1080,
297,
283,
86,
3220,
1870,
281,
14,
3858,
297,
399,
7,
86,
3220,
1870,
281,
15249,
297,
1362,
399,
7,
6470,
527,
1910,
351,
758,
1741,
2282,
297,
283,
9285,
659,
199,
61,
199,
199,
1237,
63,
5856,
275,
359,
272,
661,
1080,
297,
283,
86,
3220,
1870,
281,
297,
399,
7,
86,
3220,
1870,
281,
15249,
297,
1362,
359,
85,
7,
6470,
527,
1910,
351,
758,
1741,
2282,
995,
413,
9,
199,
61,
199,
199,
18556,
63,
12233,
275,
359,
272,
661,
1080,
297,
283,
86,
3220,
1870,
281,
297,
399,
7,
86,
3220,
1870,
281,
15249,
297,
1362,
399,
7,
6470,
527,
1910,
351,
758,
1741,
2282,
297,
283,
86,
3220,
1870,
281,
297,
1362,
283,
21814,
794,
1704,
31276,
436,
27989,
3130,
283,
30248,
659,
199,
61,
421,
199,
318,
12869,
63,
5237,
63,
3756,
8,
354,
12,
3066,
505,
12,
1318,
12,
5874,
12,
315,
31338,
12,
1993,
1511,
10324,
1564,
23603,
221,
327,
8151,
26,
699,
8010,
272,
862,
26,
267,
4976,
63,
1507,
275,
1109,
8,
505,
9,
267,
340,
4976,
63,
1507,
2695,
378,
26,
288,
746,
1722,
342,
272,
871,
1722,
26,
267,
1499,
275,
315,
31338,
14,
12222,
14,
705,
360,
3364,
25141,
4976,
26,
9499,
908,
8,
505,
395,
3660,
1004,
29,
3469,
9,
267,
299,
4848,
275,
315,
31338,
14,
496,
31197,
8,
1773,
505,
12,
3066,
505,
12,
1499,
9,
267,
372,
359,
2700,
66,
467,
359,
1328,
61,
339,
687,
18382,
492,
3380,
339,
21915,
63,
9524,
275,
283,
2859,
921,
5031,
14,
957,
15,
80,
1017,
1208,
15,
86,
3220,
1870,
281,
7,
272,
2142,
275,
9005,
19655,
11123,
908,
8,
10797,
63,
9524,
12,
2490,
283,
10115,
7,
340,
536,
508,
283,
3561,
7,
587,
283,
9302,
297,
2490,
4976,
63,
1507,
9,
272,
2142,
505,
275,
661,
5237,
327,
2440,
7,
340,
536,
508,
283,
3561,
7,
355,
587,
283,
9302,
1056,
327,
2440,
1959,
908,
8,
5237,
63,
1507,
9,
272,
1031,
275,
3380,
14,
4443,
8,
1773,
505,
12,
2142,
505,
12,
2984,
2302,
29,
1073,
12,
2574,
1011,
1419,
9,
272,
372,
359,
932,
467,
942,
421,
199,
318,
3272,
8,
571,
304,
272,
687,
15882,
14,
9756,
14,
1548,
492,
24106,
272,
1145,
14,
525,
63,
785,
63,
466,
360,
3494,
297,
283,
3494,
297,
283,
3852,
26,
450,
83,
27,
4887,
297,
717,
1382,
63,
698,
63,
1313,
29,
19999,
14,
1301,
63,
698,
63,
1313,
9,
272,
1145,
14,
525,
63,
3756,
360,
3561,
297,
12869,
63,
5237,
63,
3756,
9,
272,
1145,
14,
525,
63,
3756,
360,
3561,
2700,
297,
12869,
63,
5237,
63,
3756,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
2197,
199,
646,
747,
199,
199,
646,
9116,
63,
17143,
199,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
418,
199,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
1715,
275,
399,
7,
86,
3220,
1870,
281,
7,
199,
7307,
275,
334,
85,
7,
7280,
24185,
1386,
7173,
527,
1910,
351,
758,
1741,
2282,
1253,
8417,
7,
1467,
1275,
908,
8,
2083,
14,
602,
14,
8136,
1252,
6205,
3508,
57,
7058,
199,
199,
3221,
275,
9116,
63,
17143,
14,
362,
63,
1023,
8,
1231,
534,
703,
297,
3847,
63,
475,
18971,
493,
3368,
199,
1023,
275,
15671,
904,
8,
3221,
14,
1294,
7563,
1491,
18,
566,
221,
327,
710,
3974,
1323,
14,
57,
1015,
14,
199,
199,
8332,
63,
28349,
275,
11541,
1204,
86,
3220,
1870,
281,
63,
1023,
92,
3350,
447,
450,
83,
7,
450,
4683,
199,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
265,
63,
29048,
275,
747,
14,
2314,
14,
362,
360,
5670,
2080,
1149,
47,
3298,
297,
488,
9,
508,
283,
549,
7,
199,
199,
893,
26,
272,
492,
15882,
63,
29048,
63,
7915,
272,
3517,
63,
7915,
275,
283,
8008,
63,
29048,
63,
7915,
7,
272,
3517,
63,
7915,
63,
515,
275,
359,
8008,
63,
29048,
63,
7915,
14,
362,
63,
1360,
63,
7915,
63,
515,
5106,
199,
2590,
3545,
26,
272,
3517,
63,
7915,
275,
283,
885,
7,
272,
340,
440,
641,
63,
29048,
26,
267,
870,
3654,
7,
627,
9720,
9,
267,
870,
360,
3849,
26,
15882,
13,
29048,
13,
7915,
440,
4903,
12,
10015,
543,
849,
283,
1598,
283,
7915,
2659,
267,
870,
3654,
7,
627,
9720,
9,
199,
199,
1360,
63,
1986,
63,
515,
275,
4044,
1986,
418,
199,
29505,
63,
4846,
275,
283,
86,
3220,
1870,
281,
1301,
7,
199,
199,
7572,
63,
5527,
275,
1052,
199,
7572,
63,
12233,
275,
359,
272,
661,
1080,
297,
283,
86,
3220,
1870,
281,
14,
3858,
297,
399,
7,
86,
3220,
1870,
281,
15249,
297,
1362,
399,
7,
6470,
527,
1910,
351,
758,
1741,
2282,
297,
283,
9285,
659,
199,
61,
199,
199,
1237,
63,
5856,
275,
359,
272,
661,
1080,
297,
283,
86,
3220,
1870,
281,
297,
399,
7,
86,
3220,
1870,
281,
15249,
297,
1362,
359,
85,
7,
6470,
527,
1910,
351,
758,
1741,
2282,
995,
413,
9,
199,
61,
199,
199,
18556,
63,
12233,
275,
359,
272,
661,
1080,
297,
283,
86,
3220,
1870,
281,
297,
399,
7,
86,
3220,
1870,
281,
15249,
297,
1362,
399,
7,
6470,
527,
1910,
351,
758,
1741,
2282,
297,
283,
86,
3220,
1870,
281,
297,
1362,
283,
21814,
794,
1704,
31276,
436,
27989,
3130,
283,
30248,
659,
199,
61,
421,
199,
318,
12869,
63,
5237,
63,
3756,
8,
354,
12,
3066,
505,
12,
1318,
12,
5874,
12,
315,
31338,
12,
1993,
1511,
10324,
1564,
23603,
221,
327,
8151,
26,
699,
8010,
272,
862,
26,
267,
4976,
63,
1507,
275,
1109,
8,
505,
9,
267,
340,
4976,
63,
1507,
2695,
378,
26,
288,
746,
1722,
342,
272,
871,
1722,
26,
267,
1499,
275,
315,
31338,
14,
12222,
14,
705,
360,
3364,
25141,
4976,
26,
9499,
908,
8,
505,
395,
3660,
1004,
29,
3469,
9,
267,
299,
4848,
275,
315,
31338,
14,
496,
31197,
8,
1773,
505,
12,
3066,
505,
12,
1499,
9,
267,
372,
359,
2700,
66,
467,
359,
1328,
61,
339,
687,
18382,
492,
3380,
339,
21915,
63,
9524,
275,
283,
2859,
921,
5031,
14,
957,
15,
80,
1017,
1208,
15,
86,
3220,
1870,
281,
7,
272,
2142,
275,
9005,
19655,
11123,
908,
8,
10797,
63,
9524,
12,
2490,
283,
10115,
7,
340,
536,
508,
283,
3561,
7,
587,
283,
9302,
297,
2490,
4976,
63,
1507,
9,
272,
2142,
505,
275,
661,
5237,
327,
2440,
7,
340,
536,
508,
283,
3561,
7,
355,
587,
283,
9302,
1056,
327,
2440,
1959,
908,
8,
5237,
63,
1507,
9,
272,
1031,
275,
3380,
14,
4443,
8,
1773,
505,
12,
2142,
505,
12,
2984,
2302,
29,
1073,
12,
2574,
1011,
1419,
9,
272,
372,
359,
932,
467,
942,
421,
199,
318,
3272,
8,
571,
304,
272,
687,
15882,
14,
9756,
14,
1548,
492,
24106,
272,
1145,
14,
525,
63,
785,
63,
466,
360,
3494,
297,
283,
3494,
297,
283,
3852,
26,
450,
83,
27,
4887,
297,
717,
1382,
63,
698,
63,
1313,
29,
19999,
14,
1301,
63,
698,
63,
1313,
9,
272,
1145,
14,
525,
63,
3756,
360,
3561,
297,
12869,
63,
5237,
63,
3756,
9,
272,
1145,
14,
525,
63,
3756,
360,
3561,
2700,
297,
12869,
63,
5237,
63,
3756,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mjwestcott/projecteuler
|
python/problem68.py
|
1
|
2098
|
"""
problem68.py
https://projecteuler.net/problem=68
What is the maximum 16-digit string for a 'magic' 5-gon ring?
"""
from itertools import chain
flatten = chain.from_iterable
def five_gon_rings(n):
"""Return list of solutions to the 'magic' 5-gon ring problem, each line
summing to n. The empty list will be returned if there are no solutions."""
rings = [([a, b, c], [d, c, e], [f, e, g], [h, g, i], [j, i, b])
for a in range(1, 10+1)
for b in range(1, 10+1) if b != a
for c in range(1, 10+1) if c not in [a, b]
if a + b + c == n
for d in range(1, 10+1) if d not in [a, b, c]
for e in range(1, 10+1) if e not in [a, b, c, d]
if d + c + e == n
for f in range(1, 10+1) if f not in [a, b, c, d, e]
for g in range(1, 10+1) if g not in [a, b, c, d, e, f]
if f + e + g == n
for h in range(1, 10+1) if h not in [a, b, c, d, e, f, g]
for i in range(1, 10+1) if i not in [a, b, c, d, e, f, g, h]
if h + g + i == n
for j in range(1, 10+1) if j not in [a, b, c, d, e, f, g, h, i]
if j + i + b == n
if a < min(d, f, h, j)]
# Each solution can be described uniquely starting from the group of three
# with the numerically lowest external node and working clockwise.
# So we specified at the end that a < min(d, f, h, j)
return rings
def problem68():
START = 6 # each line cannot sum to less than 6 (1+2+3)
END = 27+1 # or greater than 27 (8+9+10)
# Collect solution candidates, flattening into one array of solutions.
rings = flatten(five_gon_rings(n) for n in range(START, END))
# Filter out the empty lists
rings = filter(bool, rings)
# Transform each solution tuple into a string of digits.
rings = [''.join(str(x) for x in flatten(solution)) for solution in rings]
# Find the max 16-digit string.
return int(max(solution for solution in rings if len(solution) == 16))
if __name__ == "__main__":
print(problem68())
|
mit
|
[
624,
199,
6462,
2333,
14,
647,
199,
199,
2859,
921,
5468,
825,
266,
19345,
14,
846,
15,
6462,
29,
2333,
199,
199,
21015,
365,
314,
5696,
3193,
13,
8573,
1059,
367,
282,
283,
11523,
7,
959,
13,
27719,
12133,
31,
199,
624,
199,
504,
7975,
492,
6036,
199,
199,
8487,
275,
6036,
14,
504,
63,
8147,
199,
199,
318,
24187,
63,
27719,
63,
25182,
8,
78,
304,
272,
408,
1767,
769,
402,
24886,
370,
314,
283,
11523,
7,
959,
13,
27719,
12133,
5160,
12,
1924,
1004,
272,
3089,
14566,
370,
302,
14,
710,
2701,
769,
911,
506,
2138,
340,
2337,
787,
949,
24886,
1041,
272,
519,
780,
275,
359,
779,
65,
12,
330,
12,
286,
467,
359,
68,
12,
286,
12,
325,
467,
359,
70,
12,
325,
12,
486,
467,
359,
72,
12,
486,
12,
284,
467,
359,
74,
12,
284,
12,
330,
566,
1467,
367,
282,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
1467,
367,
330,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
330,
1137,
282,
1467,
367,
286,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
286,
440,
315,
359,
65,
12,
330,
61,
1467,
340,
282,
435,
330,
435,
286,
508,
302,
1467,
367,
366,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
366,
440,
315,
359,
65,
12,
330,
12,
286,
61,
1467,
367,
325,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
325,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
61,
1467,
340,
366,
435,
286,
435,
325,
508,
302,
1467,
367,
289,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
289,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
61,
1467,
367,
486,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
486,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
61,
1467,
340,
289,
435,
325,
435,
486,
508,
302,
1467,
367,
394,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
394,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
12,
486,
61,
1467,
367,
284,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
284,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
12,
486,
12,
394,
61,
1467,
340,
394,
435,
486,
435,
284,
508,
302,
1467,
367,
1335,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
1335,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
12,
486,
12,
394,
12,
284,
61,
1467,
340,
1335,
435,
284,
435,
330,
508,
302,
1467,
340,
282,
665,
1748,
8,
68,
12,
289,
12,
394,
12,
1335,
1874,
272,
327,
7048,
8744,
883,
506,
11736,
28727,
6617,
687,
314,
1572,
402,
7795,
272,
327,
543,
314,
8950,
1183,
18966,
5957,
1031,
436,
6449,
12516,
2605,
14,
272,
327,
2002,
781,
2013,
737,
314,
1284,
626,
282,
665,
1748,
8,
68,
12,
289,
12,
394,
12,
1335,
9,
272,
372,
519,
780,
199,
199,
318,
5160,
2333,
837,
272,
13910,
275,
1227,
257,
327,
1924,
1004,
3913,
3089,
370,
6656,
2419,
1227,
334,
17,
11,
18,
11,
19,
9,
272,
7729,
275,
8087,
11,
17,
221,
327,
503,
8932,
2419,
8087,
334,
24,
11,
25,
11,
709,
9,
339,
327,
19649,
8744,
15101,
12,
9378,
316,
1901,
1373,
1625,
402,
24886,
14,
272,
519,
780,
275,
9378,
8,
23702,
63,
27719,
63,
25182,
8,
78,
9,
367,
302,
315,
1425,
8,
7363,
12,
7729,
430,
272,
327,
9388,
734,
314,
2701,
5548,
272,
519,
780,
275,
2457,
8,
2245,
12,
519,
780,
9,
272,
327,
19463,
1924,
8744,
2008,
1901,
282,
1059,
402,
7576,
14,
272,
519,
780,
275,
788,
1370,
904,
8,
495,
8,
88,
9,
367,
671,
315,
9378,
8,
14458,
430,
367,
8744,
315,
519,
780,
61,
272,
327,
6668,
314,
1390,
3193,
13,
8573,
1059,
14,
272,
372,
1109,
8,
988,
8,
14458,
367,
8744,
315,
519,
780,
340,
822,
8,
14458,
9,
508,
3193,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
870,
8,
6462,
2333,
1012,
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
] |
[
199,
6462,
2333,
14,
647,
199,
199,
2859,
921,
5468,
825,
266,
19345,
14,
846,
15,
6462,
29,
2333,
199,
199,
21015,
365,
314,
5696,
3193,
13,
8573,
1059,
367,
282,
283,
11523,
7,
959,
13,
27719,
12133,
31,
199,
624,
199,
504,
7975,
492,
6036,
199,
199,
8487,
275,
6036,
14,
504,
63,
8147,
199,
199,
318,
24187,
63,
27719,
63,
25182,
8,
78,
304,
272,
408,
1767,
769,
402,
24886,
370,
314,
283,
11523,
7,
959,
13,
27719,
12133,
5160,
12,
1924,
1004,
272,
3089,
14566,
370,
302,
14,
710,
2701,
769,
911,
506,
2138,
340,
2337,
787,
949,
24886,
1041,
272,
519,
780,
275,
359,
779,
65,
12,
330,
12,
286,
467,
359,
68,
12,
286,
12,
325,
467,
359,
70,
12,
325,
12,
486,
467,
359,
72,
12,
486,
12,
284,
467,
359,
74,
12,
284,
12,
330,
566,
1467,
367,
282,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
1467,
367,
330,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
330,
1137,
282,
1467,
367,
286,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
286,
440,
315,
359,
65,
12,
330,
61,
1467,
340,
282,
435,
330,
435,
286,
508,
302,
1467,
367,
366,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
366,
440,
315,
359,
65,
12,
330,
12,
286,
61,
1467,
367,
325,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
325,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
61,
1467,
340,
366,
435,
286,
435,
325,
508,
302,
1467,
367,
289,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
289,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
61,
1467,
367,
486,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
486,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
61,
1467,
340,
289,
435,
325,
435,
486,
508,
302,
1467,
367,
394,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
394,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
12,
486,
61,
1467,
367,
284,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
284,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
12,
486,
12,
394,
61,
1467,
340,
394,
435,
486,
435,
284,
508,
302,
1467,
367,
1335,
315,
1425,
8,
17,
12,
1616,
11,
17,
9,
340,
1335,
440,
315,
359,
65,
12,
330,
12,
286,
12,
366,
12,
325,
12,
289,
12,
486,
12,
394,
12,
284,
61,
1467,
340,
1335,
435,
284,
435,
330,
508,
302,
1467,
340,
282,
665,
1748,
8,
68,
12,
289,
12,
394,
12,
1335,
1874,
272,
327,
7048,
8744,
883,
506,
11736,
28727,
6617,
687,
314,
1572,
402,
7795,
272,
327,
543,
314,
8950,
1183,
18966,
5957,
1031,
436,
6449,
12516,
2605,
14,
272,
327,
2002,
781,
2013,
737,
314,
1284,
626,
282,
665,
1748,
8,
68,
12,
289,
12,
394,
12,
1335,
9,
272,
372,
519,
780,
199,
199,
318,
5160,
2333,
837,
272,
13910,
275,
1227,
257,
327,
1924,
1004,
3913,
3089,
370,
6656,
2419,
1227,
334,
17,
11,
18,
11,
19,
9,
272,
7729,
275,
8087,
11,
17,
221,
327,
503,
8932,
2419,
8087,
334,
24,
11,
25,
11,
709,
9,
339,
327,
19649,
8744,
15101,
12,
9378,
316,
1901,
1373,
1625,
402,
24886,
14,
272,
519,
780,
275,
9378,
8,
23702,
63,
27719,
63,
25182,
8,
78,
9,
367,
302,
315,
1425,
8,
7363,
12,
7729,
430,
272,
327,
9388,
734,
314,
2701,
5548,
272,
519,
780,
275,
2457,
8,
2245,
12,
519,
780,
9,
272,
327,
19463,
1924,
8744,
2008,
1901,
282,
1059,
402,
7576,
14,
272,
519,
780,
275,
788,
1370,
904,
8,
495,
8,
88,
9,
367,
671,
315,
9378,
8,
14458,
430,
367,
8744,
315,
519,
780,
61,
272,
327,
6668,
314,
1390,
3193,
13,
8573,
1059,
14,
272,
372,
1109,
8,
988,
8,
14458,
367,
8744,
315,
519,
780,
340,
822,
8,
14458,
9,
508,
3193,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
870,
8,
6462,
2333,
1012,
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,
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,
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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
] |
ioannistsanaktsidis/inspire-next
|
inspire/modules/workflows/tasks/matching.py
|
1
|
7191
|
# -*- coding: utf-8 -*-
#
## This file is part of INSPIRE.
## Copyright (C) 2014 CERN.
##
## INSPIRE 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.
##
## INSPIRE 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 INSPIRE. If not, see <http://www.gnu.org/licenses/>.
##
## In applying this license, CERN does not waive the privileges and immunities
## granted to it by virtue of its status as an Intergovernmental Organization
## or submit itself to any jurisdiction.
"""Contains task to check if incoming record already exist."""
import os
import requests
import traceback
from functools import wraps
from invenio.base.globals import cfg
from invenio.modules.deposit.models import Deposition
def match_record_arxiv_remote(arxiv_id):
"""Look on the remote server if the record exists using arXiv id."""
if arxiv_id:
arxiv_id = arxiv_id.lower().replace('arxiv:', '')
params = dict(p="035:oai:arXiv.org:%s" % arxiv_id, of="id")
r = requests.get(cfg["WORKFLOWS_MATCH_REMOTE_SERVER_URL"], params=params)
response = r.json()
return response
return {}
def match_record_arxiv_remote_oaiharvest(obj, eng):
"""Look on the remote server if the record exists using arXiv id."""
report_numbers = obj.get_data().get('report_number', [])
for number in report_numbers:
if number.get("source", "").lower() == "arxiv":
arxiv_id = number.get("primary")
try:
response = match_record_arxiv_remote(arxiv_id)
if response:
obj.extra_data['recid'] = response[0]
obj.extra_data['url'] = os.path.join(
cfg["CFG_ROBOTUPLOAD_SUBMISSION_BASEURL"],
'record',
str(response[0])
)
return True
except requests.ConnectionError:
obj.log.error("Error connecting to remote server:\n {0}".format(
traceback.format_exc()
))
return False
def match_record_arxiv_remote_deposit(obj, eng):
"""Look on the remote server if the record exists using arXiv id."""
d = Deposition(obj)
sip = d.get_latest_sip(sealed=False)
arxiv_id = sip.metadata.get('arxiv_id')
try:
response = match_record_arxiv_remote(arxiv_id)
if response:
obj.extra_data['recid'] = response[0]
obj.extra_data['url'] = os.path.join(
cfg["CFG_ROBOTUPLOAD_SUBMISSION_BASEURL"],
'record',
str(response[0])
)
return True
except requests.ConnectionError:
obj.log.error("Error connecting to remote server:\n {0}".format(
traceback.format_exc()
))
return False
def match_record_doi_remote(doi):
"""Look on the remote server if the record exists using doi."""
if doi:
params = dict(p="0247:%s" % doi, of="id")
r = requests.get(cfg["WORKFLOWS_MATCH_REMOTE_SERVER_URL"], params=params)
response = r.json()
if response:
return response
return False
def match_record_doi_remote_deposit(obj, eng):
"""Look on the remote server if the record exists using doi."""
d = Deposition(obj)
sip = d.get_latest_sip(sealed=False)
doi = sip.metadata.get('doi')
response = match_record_doi_remote(doi)
if not response:
return False
else:
obj.extra_data['recid'] = response[0]
obj.extra_data['url'] = os.path.join(
cfg["CFG_ROBOTUPLOAD_SUBMISSION_BASEURL"],
'record',
str(response[0])
)
return True
def match_record_remote_deposit(obj, eng):
"""Look on the remote server if the record exists using doi and arxiv_id."""
return match_record_arxiv_remote_deposit(obj, eng) or\
match_record_doi_remote_deposit(obj, eng)
def match_record_remote_oaiharvest(obj, eng):
"""Look on the remote server if the record exists using doi and arxiv_id."""
return match_record_arxiv_remote_deposit(obj, eng) or\
match_record_doi_remote_deposit(obj, eng)
def save_identifiers_oaiharvest(kb_name):
"""Save the record identifiers into a KB."""
@wraps(save_identifiers_oaiharvest)
def _save_identifiers_oaiharvest(obj, eng):
from inspire.utils.knowledge import save_keys_to_kb
identifiers = []
report_numbers = obj.get_data().get('report_number', [])
for number in report_numbers:
if number.get("source", "").lower() == "arxiv":
arxiv_id = number.get("primary")
identifiers.append(arxiv_id)
save_keys_to_kb(kb_name, identifiers, obj.id)
return _save_identifiers_oaiharvest
def match_record_HP_oaiharvest(kb_name):
"""Check if a oaiharvest record exists in HP."""
@wraps(match_record_HP_oaiharvest)
def _match_record_HP_oaiharvest(obj, eng):
from inspire.utils.knowledge import check_keys
identifiers = []
report_numbers = obj.get_data().get('report_number', [])
for number in report_numbers:
if number.get("source", "").lower() == "arxiv":
arxiv_id = number.get("primary")
identifiers.append(arxiv_id)
return check_keys(kb_name, identifiers)
return _match_record_HP_oaiharvest
def delete_self_and_stop_processing(obj, eng):
"""Delete both versions of itself and stops the workflow."""
from invenio.modules.workflows.models import BibWorkflowObject
# delete snapshot created with original data
initial_obj = BibWorkflowObject.query.filter(
BibWorkflowObject.id_parent == obj.id
).one()
BibWorkflowObject.delete(initial_obj.id)
# delete self
BibWorkflowObject.delete(obj.id)
eng.skipToken()
def update_old_object(kb_name):
"""Update the data of the old object with the new data."""
@wraps(update_old_object)
def _update_old_object(obj, eng):
from inspire.utils.knowledge import get_value
from invenio.modules.workflows.models import BibWorkflowObject
identifiers = []
report_numbers = obj.get_data().get('report_number', [])
for number in report_numbers:
if number.get("source", "").lower() == "arxiv":
arxiv_id = number.get("primary")
identifiers.append(arxiv_id)
object_id = get_value(kb_name, identifiers)
if object_id:
old_object = BibWorkflowObject.query.get(object_id)
if old_object:
# record waiting approval
old_object.set_data(obj.get_data())
old_object.save()
return _update_old_object
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
309,
961,
570,
365,
1777,
402,
1621,
20495,
907,
14,
199,
309,
1898,
334,
35,
9,
6927,
24354,
14,
199,
309,
199,
309,
1621,
20495,
907,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
1621,
20495,
907,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
1621,
20495,
907,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
309,
1010,
18876,
642,
4190,
12,
24354,
1630,
440,
14442,
1912,
314,
20001,
436,
25531,
22047,
199,
309,
10009,
370,
652,
701,
12043,
310,
402,
2399,
2004,
465,
376,
6551,
71,
27639,
279,
18863,
199,
309,
503,
11482,
6337,
370,
1263,
1335,
17656,
26382,
14,
199,
199,
624,
6906,
2120,
370,
1104,
340,
12467,
2777,
2575,
2187,
1041,
199,
199,
646,
747,
199,
646,
4145,
199,
646,
5190,
199,
199,
504,
9143,
492,
14018,
199,
199,
504,
13640,
14,
1095,
14,
8473,
492,
4810,
199,
504,
13640,
14,
3112,
14,
271,
21759,
14,
992,
492,
1487,
3124,
421,
199,
318,
1336,
63,
3059,
63,
27290,
63,
3846,
8,
27290,
63,
344,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
601,
56,
1003,
1305,
1041,
272,
340,
601,
25034,
63,
344,
26,
267,
601,
25034,
63,
344,
275,
601,
25034,
63,
344,
14,
2325,
1252,
1814,
360,
27290,
6536,
4074,
267,
1862,
275,
1211,
8,
80,
628,
21088,
26,
28475,
26,
285,
56,
1003,
14,
1308,
2689,
83,
2,
450,
601,
25034,
63,
344,
12,
402,
628,
344,
531,
267,
519,
275,
4145,
14,
362,
8,
4128,
905,
8406,
38,
1484,
5035,
63,
14747,
63,
16058,
63,
6613,
63,
2632,
2255,
1862,
29,
1162,
9,
267,
1177,
275,
519,
14,
1001,
342,
267,
372,
1177,
272,
372,
1052,
421,
199,
318,
1336,
63,
3059,
63,
27290,
63,
3846,
63,
28475,
32222,
8,
1113,
12,
20171,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
601,
56,
1003,
1305,
1041,
272,
3622,
63,
10548,
275,
1559,
14,
362,
63,
576,
1252,
362,
360,
3070,
63,
1955,
297,
3073,
272,
367,
1329,
315,
3622,
63,
10548,
26,
267,
340,
1329,
14,
362,
480,
1365,
401,
25354,
2325,
342,
508,
298,
27290,
582,
288,
601,
25034,
63,
344,
275,
1329,
14,
362,
480,
3327,
531,
288,
862,
26,
355,
1177,
275,
1336,
63,
3059,
63,
27290,
63,
3846,
8,
27290,
63,
344,
9,
355,
340,
1177,
26,
490,
1559,
14,
2911,
63,
576,
459,
17532,
418,
275,
1177,
59,
16,
61,
490,
1559,
14,
2911,
63,
576,
459,
633,
418,
275,
747,
14,
515,
14,
904,
8,
717,
4810,
905,
10118,
63,
1092,
11372,
16418,
63,
6348,
22320,
63,
5825,
2632,
2255,
717,
283,
3059,
297,
717,
620,
8,
1310,
59,
16,
566,
490,
776,
490,
372,
715,
288,
871,
4145,
14,
20349,
26,
355,
1559,
14,
793,
14,
705,
480,
547,
18170,
370,
3982,
1654,
3427,
78,
469,
16,
5469,
908,
8,
490,
5190,
14,
908,
63,
2804,
342,
355,
5082,
272,
372,
756,
421,
199,
318,
1336,
63,
3059,
63,
27290,
63,
3846,
63,
271,
21759,
8,
1113,
12,
20171,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
601,
56,
1003,
1305,
1041,
272,
366,
275,
1487,
3124,
8,
1113,
9,
272,
25342,
275,
366,
14,
362,
63,
7410,
63,
17839,
8,
27590,
1146,
29,
797,
9,
272,
601,
25034,
63,
344,
275,
25342,
14,
2343,
14,
362,
360,
27290,
63,
344,
358,
272,
862,
26,
267,
1177,
275,
1336,
63,
3059,
63,
27290,
63,
3846,
8,
27290,
63,
344,
9,
267,
340,
1177,
26,
288,
1559,
14,
2911,
63,
576,
459,
17532,
418,
275,
1177,
59,
16,
61,
288,
1559,
14,
2911,
63,
576,
459,
633,
418,
275,
747,
14,
515,
14,
904,
8,
355,
4810,
905,
10118,
63,
1092,
11372,
16418,
63,
6348,
22320,
63,
5825,
2632,
2255,
355,
283,
3059,
297,
355,
620,
8,
1310,
59,
16,
566,
288,
776,
288,
372,
715,
272,
871,
4145,
14,
20349,
26,
267,
1559,
14,
793,
14,
705,
480,
547,
18170,
370,
3982,
1654,
3427,
78,
469,
16,
5469,
908,
8,
288,
5190,
14,
908,
63,
2804,
342,
267,
5082,
272,
372,
756,
421,
199,
318,
1336,
63,
3059,
63,
27334,
63,
3846,
8,
27334,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
886,
73,
1041,
272,
340,
886,
73,
26,
267,
1862,
275,
1211,
8,
80,
628,
996,
2417,
2689,
83,
2,
450,
886,
73,
12,
402,
628,
344,
531,
267,
519,
275,
4145,
14,
362,
8,
4128,
905,
8406,
38,
1484,
5035,
63,
14747,
63,
16058,
63,
6613,
63,
2632,
2255,
1862,
29,
1162,
9,
267,
1177,
275,
519,
14,
1001,
342,
267,
340,
1177,
26,
288,
372,
1177,
272,
372,
756,
421,
199,
318,
1336,
63,
3059,
63,
27334,
63,
3846,
63,
271,
21759,
8,
1113,
12,
20171,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
886,
73,
1041,
272,
366,
275,
1487,
3124,
8,
1113,
9,
272,
25342,
275,
366,
14,
362,
63,
7410,
63,
17839,
8,
27590,
1146,
29,
797,
9,
272,
886,
73,
275,
25342,
14,
2343,
14,
362,
360,
27334,
358,
272,
1177,
275,
1336,
63,
3059,
63,
27334,
63,
3846,
8,
27334,
9,
272,
340,
440,
1177,
26,
267,
372,
756,
272,
587,
26,
267,
1559,
14,
2911,
63,
576,
459,
17532,
418,
275,
1177,
59,
16,
61,
267,
1559,
14,
2911,
63,
576,
459,
633,
418,
275
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
309,
961,
570,
365,
1777,
402,
1621,
20495,
907,
14,
199,
309,
1898,
334,
35,
9,
6927,
24354,
14,
199,
309,
199,
309,
1621,
20495,
907,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
1621,
20495,
907,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
1621,
20495,
907,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
309,
1010,
18876,
642,
4190,
12,
24354,
1630,
440,
14442,
1912,
314,
20001,
436,
25531,
22047,
199,
309,
10009,
370,
652,
701,
12043,
310,
402,
2399,
2004,
465,
376,
6551,
71,
27639,
279,
18863,
199,
309,
503,
11482,
6337,
370,
1263,
1335,
17656,
26382,
14,
199,
199,
624,
6906,
2120,
370,
1104,
340,
12467,
2777,
2575,
2187,
1041,
199,
199,
646,
747,
199,
646,
4145,
199,
646,
5190,
199,
199,
504,
9143,
492,
14018,
199,
199,
504,
13640,
14,
1095,
14,
8473,
492,
4810,
199,
504,
13640,
14,
3112,
14,
271,
21759,
14,
992,
492,
1487,
3124,
421,
199,
318,
1336,
63,
3059,
63,
27290,
63,
3846,
8,
27290,
63,
344,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
601,
56,
1003,
1305,
1041,
272,
340,
601,
25034,
63,
344,
26,
267,
601,
25034,
63,
344,
275,
601,
25034,
63,
344,
14,
2325,
1252,
1814,
360,
27290,
6536,
4074,
267,
1862,
275,
1211,
8,
80,
628,
21088,
26,
28475,
26,
285,
56,
1003,
14,
1308,
2689,
83,
2,
450,
601,
25034,
63,
344,
12,
402,
628,
344,
531,
267,
519,
275,
4145,
14,
362,
8,
4128,
905,
8406,
38,
1484,
5035,
63,
14747,
63,
16058,
63,
6613,
63,
2632,
2255,
1862,
29,
1162,
9,
267,
1177,
275,
519,
14,
1001,
342,
267,
372,
1177,
272,
372,
1052,
421,
199,
318,
1336,
63,
3059,
63,
27290,
63,
3846,
63,
28475,
32222,
8,
1113,
12,
20171,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
601,
56,
1003,
1305,
1041,
272,
3622,
63,
10548,
275,
1559,
14,
362,
63,
576,
1252,
362,
360,
3070,
63,
1955,
297,
3073,
272,
367,
1329,
315,
3622,
63,
10548,
26,
267,
340,
1329,
14,
362,
480,
1365,
401,
25354,
2325,
342,
508,
298,
27290,
582,
288,
601,
25034,
63,
344,
275,
1329,
14,
362,
480,
3327,
531,
288,
862,
26,
355,
1177,
275,
1336,
63,
3059,
63,
27290,
63,
3846,
8,
27290,
63,
344,
9,
355,
340,
1177,
26,
490,
1559,
14,
2911,
63,
576,
459,
17532,
418,
275,
1177,
59,
16,
61,
490,
1559,
14,
2911,
63,
576,
459,
633,
418,
275,
747,
14,
515,
14,
904,
8,
717,
4810,
905,
10118,
63,
1092,
11372,
16418,
63,
6348,
22320,
63,
5825,
2632,
2255,
717,
283,
3059,
297,
717,
620,
8,
1310,
59,
16,
566,
490,
776,
490,
372,
715,
288,
871,
4145,
14,
20349,
26,
355,
1559,
14,
793,
14,
705,
480,
547,
18170,
370,
3982,
1654,
3427,
78,
469,
16,
5469,
908,
8,
490,
5190,
14,
908,
63,
2804,
342,
355,
5082,
272,
372,
756,
421,
199,
318,
1336,
63,
3059,
63,
27290,
63,
3846,
63,
271,
21759,
8,
1113,
12,
20171,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
601,
56,
1003,
1305,
1041,
272,
366,
275,
1487,
3124,
8,
1113,
9,
272,
25342,
275,
366,
14,
362,
63,
7410,
63,
17839,
8,
27590,
1146,
29,
797,
9,
272,
601,
25034,
63,
344,
275,
25342,
14,
2343,
14,
362,
360,
27290,
63,
344,
358,
272,
862,
26,
267,
1177,
275,
1336,
63,
3059,
63,
27290,
63,
3846,
8,
27290,
63,
344,
9,
267,
340,
1177,
26,
288,
1559,
14,
2911,
63,
576,
459,
17532,
418,
275,
1177,
59,
16,
61,
288,
1559,
14,
2911,
63,
576,
459,
633,
418,
275,
747,
14,
515,
14,
904,
8,
355,
4810,
905,
10118,
63,
1092,
11372,
16418,
63,
6348,
22320,
63,
5825,
2632,
2255,
355,
283,
3059,
297,
355,
620,
8,
1310,
59,
16,
566,
288,
776,
288,
372,
715,
272,
871,
4145,
14,
20349,
26,
267,
1559,
14,
793,
14,
705,
480,
547,
18170,
370,
3982,
1654,
3427,
78,
469,
16,
5469,
908,
8,
288,
5190,
14,
908,
63,
2804,
342,
267,
5082,
272,
372,
756,
421,
199,
318,
1336,
63,
3059,
63,
27334,
63,
3846,
8,
27334,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
886,
73,
1041,
272,
340,
886,
73,
26,
267,
1862,
275,
1211,
8,
80,
628,
996,
2417,
2689,
83,
2,
450,
886,
73,
12,
402,
628,
344,
531,
267,
519,
275,
4145,
14,
362,
8,
4128,
905,
8406,
38,
1484,
5035,
63,
14747,
63,
16058,
63,
6613,
63,
2632,
2255,
1862,
29,
1162,
9,
267,
1177,
275,
519,
14,
1001,
342,
267,
340,
1177,
26,
288,
372,
1177,
272,
372,
756,
421,
199,
318,
1336,
63,
3059,
63,
27334,
63,
3846,
63,
271,
21759,
8,
1113,
12,
20171,
304,
272,
408,
20926,
641,
314,
3982,
1654,
340,
314,
2777,
3495,
1808,
886,
73,
1041,
272,
366,
275,
1487,
3124,
8,
1113,
9,
272,
25342,
275,
366,
14,
362,
63,
7410,
63,
17839,
8,
27590,
1146,
29,
797,
9,
272,
886,
73,
275,
25342,
14,
2343,
14,
362,
360,
27334,
358,
272,
1177,
275,
1336,
63,
3059,
63,
27334,
63,
3846,
8,
27334,
9,
272,
340,
440,
1177,
26,
267,
372,
756,
272,
587,
26,
267,
1559,
14,
2911,
63,
576,
459,
17532,
418,
275,
1177,
59,
16,
61,
267,
1559,
14,
2911,
63,
576,
459,
633,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
HBEE/odoo-addons
|
partner_school/partner.py
|
8
|
1816
|
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import fields, models, api
class partner(models.Model):
""""""
_inherit = 'res.partner'
course_average_classrooms = fields.Integer(
string='Average Classrooms per Course')
classrooms_average_students = fields.Integer(
string='Average Students per Classroom')
course_ids = fields.Many2many(
'res.partner.course',
'res_partner_course_rel',
'partner_id',
'course_id',
string='Courses')
@api.one
@api.depends(
'course_ids',
'classrooms_average_students',
'course_average_classrooms')
def _get_totals(self):
courses_total = len(self.course_ids)
classrooms_total = courses_total * self.course_average_classrooms or 0
classrooms_average_students = self.classrooms_average_students
students_total = classrooms_total * classrooms_average_students or 0
self.courses_total = courses_total
self.classrooms_total = classrooms_total
self.students_total = students_total
courses_total = fields.Integer(
compute='_get_totals',
string='Courses Total',
readonly=True,
store=True,)
classrooms_total = fields.Integer(
compute='_get_totals',
string='Classrooms total',
readonly=True,
store=True)
students_total = fields.Integer(
compute='_get_totals',
string='Students total',
readonly=True,
store=True)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
2104,
4248,
436,
4190,
949,
7724,
12,
1937,
636,
11267,
4343,
647,
570,
315,
859,
1738,
199,
3,
2082,
199,
4605,
199,
504,
5166,
492,
1504,
12,
1709,
12,
2986,
421,
199,
533,
5854,
8,
992,
14,
1685,
304,
339,
408,
624,
339,
485,
6486,
275,
283,
470,
14,
3899,
7,
339,
2518,
63,
8536,
63,
533,
29191,
275,
1504,
14,
2674,
8,
267,
1059,
534,
17400,
8089,
29191,
1126,
5531,
358,
272,
1021,
29191,
63,
8536,
63,
17921,
275,
1504,
14,
2674,
8,
267,
1059,
534,
17400,
17246,
83,
1126,
8089,
11245,
358,
272,
2518,
63,
1580,
275,
1504,
14,
4089,
18,
3479,
8,
267,
283,
470,
14,
3899,
14,
1972,
297,
267,
283,
470,
63,
3899,
63,
1972,
63,
3369,
297,
267,
283,
3899,
63,
344,
297,
267,
283,
1972,
63,
344,
297,
267,
1059,
534,
35,
567,
874,
358,
339,
768,
1246,
14,
368,
272,
768,
1246,
14,
8912,
8,
267,
283,
1972,
63,
1580,
297,
267,
283,
533,
29191,
63,
8536,
63,
17921,
297,
267,
283,
1972,
63,
8536,
63,
533,
29191,
358,
272,
347,
485,
362,
63,
17552,
8,
277,
304,
267,
13588,
63,
2923,
275,
822,
8,
277,
14,
1972,
63,
1580,
9,
267,
1021,
29191,
63,
2923,
275,
13588,
63,
2923,
627,
291,
14,
1972,
63,
8536,
63,
533,
29191,
503,
378,
267,
1021,
29191,
63,
8536,
63,
17921,
275,
291,
14,
533,
29191,
63,
8536,
63,
17921,
267,
18557,
63,
2923,
275,
1021,
29191,
63,
2923,
627,
1021,
29191,
63,
8536,
63,
17921,
503,
378,
267,
291,
14,
11653,
63,
2923,
275,
13588,
63,
2923,
267,
291,
14,
533,
29191,
63,
2923,
275,
1021,
29191,
63,
2923,
267,
291,
14,
17921,
63,
2923,
275,
18557,
63,
2923,
339,
13588,
63,
2923,
275,
1504,
14,
2674,
8,
267,
4526,
17574,
362,
63,
17552,
297,
267,
1059,
534,
35,
567,
874,
19271,
297,
267,
6863,
29,
549,
12,
267,
3877,
29,
549,
4258,
272,
1021,
29191,
63,
2923,
275,
1504,
14,
2674,
8,
267,
4526,
17574,
362,
63,
17552,
297,
267,
1059,
534,
2543,
29191,
3141,
297,
267,
6863,
29,
549,
12,
267,
3877,
29,
549,
9,
272,
18557,
63,
2923,
275,
1504,
14,
2674,
8,
267,
4526,
17574,
362,
63,
17552,
297,
267,
1059,
534,
18086,
83,
3141,
297,
267,
6863,
29,
549,
12,
267,
3877,
29,
549,
9,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2104,
4248,
436,
4190,
949,
7724,
12,
1937,
636,
11267,
4343,
647,
570,
315,
859,
1738,
199,
3,
2082,
199,
4605,
199,
504,
5166,
492,
1504,
12,
1709,
12,
2986,
421,
199,
533,
5854,
8,
992,
14,
1685,
304,
339,
408,
624,
339,
485,
6486,
275,
283,
470,
14,
3899,
7,
339,
2518,
63,
8536,
63,
533,
29191,
275,
1504,
14,
2674,
8,
267,
1059,
534,
17400,
8089,
29191,
1126,
5531,
358,
272,
1021,
29191,
63,
8536,
63,
17921,
275,
1504,
14,
2674,
8,
267,
1059,
534,
17400,
17246,
83,
1126,
8089,
11245,
358,
272,
2518,
63,
1580,
275,
1504,
14,
4089,
18,
3479,
8,
267,
283,
470,
14,
3899,
14,
1972,
297,
267,
283,
470,
63,
3899,
63,
1972,
63,
3369,
297,
267,
283,
3899,
63,
344,
297,
267,
283,
1972,
63,
344,
297,
267,
1059,
534,
35,
567,
874,
358,
339,
768,
1246,
14,
368,
272,
768,
1246,
14,
8912,
8,
267,
283,
1972,
63,
1580,
297,
267,
283,
533,
29191,
63,
8536,
63,
17921,
297,
267,
283,
1972,
63,
8536,
63,
533,
29191,
358,
272,
347,
485,
362,
63,
17552,
8,
277,
304,
267,
13588,
63,
2923,
275,
822,
8,
277,
14,
1972,
63,
1580,
9,
267,
1021,
29191,
63,
2923,
275,
13588,
63,
2923,
627,
291,
14,
1972,
63,
8536,
63,
533,
29191,
503,
378,
267,
1021,
29191,
63,
8536,
63,
17921,
275,
291,
14,
533,
29191,
63,
8536,
63,
17921,
267,
18557,
63,
2923,
275,
1021,
29191,
63,
2923,
627,
1021,
29191,
63,
8536,
63,
17921,
503,
378,
267,
291,
14,
11653,
63,
2923,
275,
13588,
63,
2923,
267,
291,
14,
533,
29191,
63,
2923,
275,
1021,
29191,
63,
2923,
267,
291,
14,
17921,
63,
2923,
275,
18557,
63,
2923,
339,
13588,
63,
2923,
275,
1504,
14,
2674,
8,
267,
4526,
17574,
362,
63,
17552,
297,
267,
1059,
534,
35,
567,
874,
19271,
297,
267,
6863,
29,
549,
12,
267,
3877,
29,
549,
4258,
272,
1021,
29191,
63,
2923,
275,
1504,
14,
2674,
8,
267,
4526,
17574,
362,
63,
17552,
297,
267,
1059,
534,
2543,
29191,
3141,
297,
267,
6863,
29,
549,
12,
267,
3877,
29,
549,
9,
272,
18557,
63,
2923,
275,
1504,
14,
2674,
8,
267,
4526,
17574,
362,
63,
17552,
297,
267,
1059,
534,
18086,
83,
3141,
297,
267,
6863,
29,
549,
12,
267,
3877,
29,
549,
9,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
mupi/tecsaladeaula
|
timtec/settings_local_testec.py
|
1
|
3024
|
# -*- coding: utf-8 -*-
# configurations for the production server
# https://docs.djangoproject.com/en/dev/ref/settings/
DEBUG = False
TEMPLATE_DEBUG = DEBUG
TIMTEC_THEME = 'tecsaladeaula'
SITE_HOME = '/'
SITE_DOMAIN = 'teste.tecsaladeaula.com.br'
SITE_URL = 'https://teste.tecsaladeaula.com.br'
ALLOWED_HOSTS = [
'teste.tecsaladeaula.com.br',
]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'timtec-production',
'USER': 'timtec-production',
}
}
MEDIA_ROOT = "/home/testec/webfiles/media/"
STATIC_ROOT = "/home/testec/webfiles/static/"
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_SUBJECT_PREFIX = '[tecsaladeaula]'
DEFAULT_FROM_EMAIL = 'suporte@mupi.me'
CONTACT_RECIPIENT_LIST = ['suporte@mupi.me', ]
# COLOCAR SENHA
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'contato@mupi.me'
EMAIL_HOST_PASSWORD =
EMAIL_PORT = 587
EMAIL_USE_TLS = True
ACCOUNT_EMAIL_VERIFICATION = 'optional'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'logfile': {
'level': 'WARN',
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/home/testec/django.log',
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'verbose',
},
},
'loggers': {
'django': {
'handlers': ['logfile'],
'propagate': True,
'level': 'WARN',
},
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# SECURITY CONFIGURATION
# ------------------------------------------------------------------------------
# See https://docs.djangoproject.com/en/1.9/ref/middleware/#module-django.middleware.security
# and https://docs.djangoproject.com/ja/1.9/howto/deployment/checklist/#run-manage-py-check-deploy
# set this to 60 seconds and then to 518400 when you can prove it works
# SECURE_HSTS_SECONDS = 60
# SECURE_HSTS_INCLUDE_SUBDOMAINS =True
# SECURE_CONTENT_TYPE_NOSNIFF = True
# SECURE_BROWSER_XSS_FILTER = True
# SESSION_COOKIE_SECURE = True
# SESSION_COOKIE_HTTPONLY = True
# SECURE_SSL_REDIRECT = True
# CSRF_COOKIE_SECURE = True
# CSRF_COOKIE_HTTPONLY = False
# X_FRAME_OPTIONS = 'DENY'
try:
# THIS FILE SETS PRODUCTION SPECIFIC
# SENSITIVY VALUES (SUCH AS GOOGLE ANALYTICS KEY)
from .settings_production import *
except ImportError:
pass
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
13422,
367,
314,
9920,
1654,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
15,
199,
5287,
275,
756,
199,
7433,
63,
5287,
275,
10990,
199,
199,
11342,
3727,
35,
63,
18061,
3635,
275,
283,
266,
1259,
279,
9587,
65,
7586,
7,
199,
199,
7917,
63,
9524,
275,
7324,
199,
7917,
63,
7378,
275,
283,
744,
266,
14,
266,
1259,
279,
9587,
65,
7586,
14,
957,
14,
3289,
7,
199,
7917,
63,
2632,
275,
283,
2859,
921,
744,
266,
14,
266,
1259,
279,
9587,
65,
7586,
14,
957,
14,
3289,
7,
199,
17350,
63,
23775,
275,
359,
272,
283,
744,
266,
14,
266,
1259,
279,
9587,
65,
7586,
14,
957,
14,
3289,
297,
199,
61,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
15437,
63,
20270,
18,
297,
267,
283,
2339,
356,
283,
2906,
266,
67,
13,
10777,
297,
267,
283,
3791,
356,
283,
2906,
266,
67,
13,
10777,
297,
272,
789,
199,
93,
199,
199,
13669,
63,
5441,
275,
3286,
4219,
15,
744,
266,
67,
15,
2520,
1725,
15,
4603,
6687,
199,
10449,
63,
5441,
275,
3286,
4219,
15,
744,
266,
67,
15,
2520,
1725,
15,
1986,
6687,
199,
199,
10089,
63,
18145,
275,
283,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
15592,
14,
7035,
8447,
7,
199,
10089,
63,
6348,
5550,
63,
6351,
275,
6730,
266,
1259,
279,
9587,
65,
7586,
6616,
199,
3472,
63,
12491,
63,
10089,
275,
283,
1961,
269,
266,
32,
77,
384,
73,
14,
278,
7,
199,
5801,
3036,
63,
9481,
1772,
25451,
63,
4924,
275,
788,
1961,
269,
266,
32,
77,
384,
73,
14,
278,
297,
1622,
199,
199,
3,
5099,
5752,
689,
428,
742,
6294,
199,
10089,
63,
5449,
275,
283,
15592,
14,
6799,
14,
957,
7,
199,
10089,
63,
5449,
63,
3791,
275,
283,
11096,
11318,
32,
77,
384,
73,
14,
278,
7,
199,
10089,
63,
5449,
63,
9032,
275,
221,
199,
10089,
63,
3657,
275,
959,
1555,
199,
10089,
63,
4701,
63,
10224,
275,
715,
199,
199,
18928,
63,
10089,
63,
2111,
14456,
2594,
275,
283,
4144,
7,
199,
199,
27896,
275,
469,
272,
283,
1023,
356,
413,
12,
272,
283,
5993,
63,
5952,
63,
22771,
356,
756,
12,
272,
283,
4273,
356,
469,
267,
283,
4365,
63,
1757,
63,
3910,
356,
469,
288,
283,
342,
356,
283,
1176,
14,
1208,
14,
793,
14,
13902,
7084,
797,
7,
267,
789,
272,
1660,
272,
283,
24270,
356,
469,
267,
283,
3832,
356,
469,
288,
283,
908,
356,
9487,
20056,
9,
83,
2818,
18331,
9,
83,
2818,
578,
9,
83,
2818,
1412,
9,
68,
2818,
2671,
9,
68,
2818,
1188,
9,
83,
7,
267,
1660,
272,
1660,
272,
283,
5586,
356,
469,
267,
283,
1198,
63,
23121,
356,
469,
288,
283,
1896,
356,
283,
3170,
297,
288,
283,
4273,
356,
788,
4365,
63,
1757,
63,
3910,
995,
288,
283,
533,
356,
283,
1176,
14,
1208,
14,
793,
14,
4880,
7035,
2461,
7,
267,
1660,
267,
283,
12804,
356,
469,
288,
283,
1896,
356,
283,
17449,
297,
288,
283,
533,
356,
283,
4806,
14,
5586,
14,
14728,
1958,
21982,
297,
288,
283,
1501,
356,
1994,
4219,
15,
744,
266,
67,
15,
1176,
14,
793,
297,
288,
283,
988,
5571,
356,
959,
993,
12,
288,
283,
5751,
2353,
356,
499,
12,
288,
283,
8911,
356,
283,
3832,
297,
267,
1660,
272,
1660,
272,
283,
22771,
356,
469,
267,
283,
1176,
356,
469,
288,
283,
5586,
356,
788,
12804,
995,
288,
283,
19432,
356,
715,
12,
288,
283,
1896,
356,
283,
17449,
297,
267,
1660,
267,
283,
1176,
14,
1069,
356,
469,
288,
283,
5586,
356,
788,
1198,
63,
23121,
995,
288,
283,
1896,
356,
283,
3170,
297,
288,
283,
19432,
356,
715,
12,
267,
1660,
272,
789,
199,
93,
199,
199,
3,
24143,
3942,
63,
20026,
63,
5413,
63,
7311,
275,
661,
2856,
63,
56,
63,
22371,
8280,
63,
7459,
297,
283,
2859,
358,
199,
199,
3,
24143,
32712,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
25,
15,
1121,
15,
5754,
12645,
578,
13,
1176,
14,
5754,
14,
4416,
199,
3,
436,
4178,
921,
4757,
14,
14013,
14,
957,
15,
3387,
15,
17,
14,
25,
15,
21232,
15,
13605,
15,
1074,
513,
12645,
1065,
13,
9053,
13,
647,
13,
1074,
13,
11060,
199,
199,
3,
663,
642,
370,
5212,
4696,
436,
2066,
370,
959,
1085,
5303,
1380,
1265,
883,
557,
432,
652,
5419,
199,
3,
24143,
3942,
63,
40,
840,
51,
63,
23319,
275,
5212,
199,
3,
24143,
3942,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
275,
549,
199,
3,
24143,
3942,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
275,
715,
199,
3,
24143,
3942,
63,
31956,
3279,
63,
56,
2300,
63,
9905,
275,
715,
199,
3,
428,
9577,
63,
13665,
63,
20696,
275,
715,
199,
3,
428,
9577,
63,
13665,
63,
2856,
10452,
275,
715,
199,
3,
24143,
3942,
63,
5413,
63,
19747,
275,
715,
199,
3,
22468,
63,
13665,
63,
20696,
275,
715,
199,
3,
22468,
63,
13665,
63,
2856,
10452,
275,
756,
199,
3,
1323,
63,
12683,
63,
8808,
275,
283,
23282,
57,
7,
199,
199,
893,
26,
272,
327,
5749,
13024,
11543,
51,
3611,
4980,
5430,
428,
7236,
23380,
272,
327,
428,
8456,
649,
6882,
57,
13992,
334,
6195,
1244,
4319,
9173,
12827,
1261,
748,
28267,
21174,
9301,
9,
272,
687,
1275,
1751,
63,
10777,
492,
627,
199,
2590,
3545,
26,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
13422,
367,
314,
9920,
1654,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
1751,
15,
199,
5287,
275,
756,
199,
7433,
63,
5287,
275,
10990,
199,
199,
11342,
3727,
35,
63,
18061,
3635,
275,
283,
266,
1259,
279,
9587,
65,
7586,
7,
199,
199,
7917,
63,
9524,
275,
7324,
199,
7917,
63,
7378,
275,
283,
744,
266,
14,
266,
1259,
279,
9587,
65,
7586,
14,
957,
14,
3289,
7,
199,
7917,
63,
2632,
275,
283,
2859,
921,
744,
266,
14,
266,
1259,
279,
9587,
65,
7586,
14,
957,
14,
3289,
7,
199,
17350,
63,
23775,
275,
359,
272,
283,
744,
266,
14,
266,
1259,
279,
9587,
65,
7586,
14,
957,
14,
3289,
297,
199,
61,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
15437,
63,
20270,
18,
297,
267,
283,
2339,
356,
283,
2906,
266,
67,
13,
10777,
297,
267,
283,
3791,
356,
283,
2906,
266,
67,
13,
10777,
297,
272,
789,
199,
93,
199,
199,
13669,
63,
5441,
275,
3286,
4219,
15,
744,
266,
67,
15,
2520,
1725,
15,
4603,
6687,
199,
10449,
63,
5441,
275,
3286,
4219,
15,
744,
266,
67,
15,
2520,
1725,
15,
1986,
6687,
199,
199,
10089,
63,
18145,
275,
283,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
15592,
14,
7035,
8447,
7,
199,
10089,
63,
6348,
5550,
63,
6351,
275,
6730,
266,
1259,
279,
9587,
65,
7586,
6616,
199,
3472,
63,
12491,
63,
10089,
275,
283,
1961,
269,
266,
32,
77,
384,
73,
14,
278,
7,
199,
5801,
3036,
63,
9481,
1772,
25451,
63,
4924,
275,
788,
1961,
269,
266,
32,
77,
384,
73,
14,
278,
297,
1622,
199,
199,
3,
5099,
5752,
689,
428,
742,
6294,
199,
10089,
63,
5449,
275,
283,
15592,
14,
6799,
14,
957,
7,
199,
10089,
63,
5449,
63,
3791,
275,
283,
11096,
11318,
32,
77,
384,
73,
14,
278,
7,
199,
10089,
63,
5449,
63,
9032,
275,
221,
199,
10089,
63,
3657,
275,
959,
1555,
199,
10089,
63,
4701,
63,
10224,
275,
715,
199,
199,
18928,
63,
10089,
63,
2111,
14456,
2594,
275,
283,
4144,
7,
199,
199,
27896,
275,
469,
272,
283,
1023,
356,
413,
12,
272,
283,
5993,
63,
5952,
63,
22771,
356,
756,
12,
272,
283,
4273,
356,
469,
267,
283,
4365,
63,
1757,
63,
3910,
356,
469,
288,
283,
342,
356,
283,
1176,
14,
1208,
14,
793,
14,
13902,
7084,
797,
7,
267,
789,
272,
1660,
272,
283,
24270,
356,
469,
267,
283,
3832,
356,
469,
288,
283,
908,
356,
9487,
20056,
9,
83,
2818,
18331,
9,
83,
2818,
578,
9,
83,
2818,
1412,
9,
68,
2818,
2671,
9,
68,
2818,
1188,
9,
83,
7,
267,
1660,
272,
1660,
272,
283,
5586,
356,
469,
267,
283,
1198,
63,
23121,
356,
469,
288,
283,
1896,
356,
283,
3170,
297,
288,
283,
4273,
356,
788,
4365,
63,
1757,
63,
3910,
995,
288,
283,
533,
356,
283,
1176,
14,
1208,
14,
793,
14,
4880,
7035,
2461,
7,
267,
1660,
267,
283,
12804,
356,
469,
288,
283,
1896,
356,
283,
17449,
297,
288,
283,
533,
356,
283,
4806,
14,
5586,
14,
14728,
1958,
21982,
297,
288,
283,
1501,
356,
1994,
4219,
15,
744,
266,
67,
15,
1176,
14,
793,
297,
288,
283,
988,
5571,
356,
959,
993,
12,
288,
283,
5751,
2353,
356,
499,
12,
288,
283,
8911,
356,
283,
3832,
297,
267,
1660,
272,
1660,
272,
283,
22771,
356,
469,
267,
283,
1176,
356,
469,
288,
283,
5586,
356,
788,
12804,
995,
288,
283,
19432,
356,
715,
12,
288,
283,
1896,
356,
283,
17449,
297,
267,
1660,
267,
283,
1176,
14,
1069,
356,
469,
288,
283,
5586,
356,
788,
1198,
63,
23121,
995,
288,
283,
1896,
356,
283,
3170,
297,
288,
283,
19432,
356,
715,
12,
267,
1660,
272,
789,
199,
93,
199,
199,
3,
24143,
3942,
63,
20026,
63,
5413,
63,
7311,
275,
661,
2856,
63,
56,
63,
22371,
8280,
63,
7459,
297,
283,
2859,
358,
199,
199,
3,
24143,
32712,
15869,
15301,
199,
3,
5620,
10965,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
25,
15,
1121,
15,
5754,
12645,
578,
13,
1176,
14,
5754,
14,
4416,
199,
3,
436,
4178,
921,
4757,
14,
14013,
14,
957,
15,
3387,
15,
17,
14,
25,
15,
21232,
15,
13605,
15,
1074,
513,
12645,
1065,
13,
9053,
13,
647,
13,
1074,
13,
11060,
199,
199,
3,
663,
642,
370,
5212,
4696,
436,
2066,
370,
959,
1085,
5303,
1380,
1265,
883,
557,
432,
652,
5419,
199,
3,
24143,
3942,
63,
40,
840,
51,
63,
23319,
275,
5212,
199,
3,
24143,
3942,
63,
40,
840,
51,
63,
18171,
63,
6348,
7378,
51,
275,
549,
199,
3,
24143,
3942,
63,
9663,
63,
2711,
63,
2826,
8199,
24150,
275,
715,
199,
3,
24143,
3942,
63,
31956,
3279,
63,
56,
2300,
63,
9905,
275,
715,
199,
3,
428,
9577,
63,
13665,
63,
20696,
275,
715,
199,
3,
428,
9577,
63,
13665,
63,
2856,
10452,
275,
715,
199,
3,
24143,
3942,
63,
5413,
63,
19747,
275,
715,
199,
3,
22468,
63,
13665,
63,
20696,
275,
715,
199,
3,
22468,
63,
13665,
63,
2856,
10452,
275,
756,
199,
3,
1323,
63,
12683,
63,
8808,
275,
283,
23282,
57,
7,
199,
199,
893,
26,
272,
327,
5749,
13024,
11543,
51,
3611,
4980,
5430,
428,
7236,
23380,
272,
327,
428,
8456,
649,
6882,
57,
13992,
334,
6195,
1244,
4319,
9173,
12827,
1261,
748,
28267,
21174,
9301,
9,
272,
687,
1275,
1751,
63,
10777,
492,
627,
199,
2590,
3545,
26,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nicolasmoreau/NodeSoftware
|
nodes/topbase/node/models.py
|
2
|
9206
|
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# Feel free to rename the models, but don't rename db_table values or field names.
#
# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]'
# into your database.
from django.db import models
import logging
log=logging.getLogger('vamdc.tap')
class Unit(models.Model):
id = models.IntegerField(primary_key=True)
value = models.CharField(unique=True, max_length=60)
class Meta:
db_table = u't_unit'
class Sourcecategory(models.Model):
id = models.IntegerField(primary_key=True)
value = models.CharField(unique=True, max_length=45)
class Meta:
db_table = u't_sourcecategory'
class Source(models.Model):
id = models.IntegerField(primary_key=True)
sourcecategory = models.ForeignKey(Sourcecategory, db_column='sourcecategoryid', on_delete=models.DO_NOTHING)
title = models.TextField(null=True)
year = models.IntegerField(null=True)
volume = models.IntegerField(null=True)
uri = models.CharField(max_length=150, null=True, db_column='url')
bibcode = models.CharField(max_length=19, null=True)
sourcename = models.CharField(max_length=100)
pagebegin = models.IntegerField(null=True)
pageend = models.IntegerField(null=True)
doi = models.CharField(max_length=50, null=True)
def authornames(self):
names = []
authors = Authorsource.objects.filter(source=self)
for author in authors:
names.append(author.name)
return names
class Meta:
db_table = u't_source'
class Chemicalelement(models.Model):
id = models.IntegerField(primary_key=True)
elementsymbol = models.CharField(unique=True, max_length=9)
nuclearcharge = models.IntegerField(unique=True)
class Meta:
db_table = u't_chemicalelement'
class Isotope(models.Model):
id = models.IntegerField(primary_key=True)
chemicalelement = models.ForeignKey(Chemicalelement, db_column='chemicalelementid', on_delete=models.DO_NOTHING)
massnumber = models.IntegerField(unique=True)
mass = models.FloatField()
massunitid = models.ForeignKey(Unit, db_column='massunitid', on_delete=models.DO_NOTHING)
class Meta:
db_table = u't_isotope'
class Atomicion(models.Model):
id = models.IntegerField(primary_key=True)
isotope = models.ForeignKey(Isotope, null=True, db_column='isotopeid', blank=True, on_delete=models.DO_NOTHING)
ioncharge = models.IntegerField()
inchi = models.CharField(max_length=100)
inchikey = models.CharField(max_length=27)
isoelectronicsequence = models.CharField(max_length=30)
class Meta:
db_table = u't_atomicion'
class Version(models.Model):
id = models.IntegerField(primary_key=True)
atomicion = models.ForeignKey(Atomicion, null=True, db_column='atomicionid', blank=True, on_delete=models.DO_NOTHING)
ionversion = models.IntegerField(unique=True)
creationdate = models.DateField()
class Meta:
db_table = u't_version'
managed = False
class Parity(models.Model):
id = models.IntegerField(primary_key=True)
value = models.CharField(unique=True, max_length=30)
class Meta:
db_table = u't_parity'
class Mixingclass(models.Model):
id = models.IntegerField(primary_key=True)
value = models.CharField(unique=True, max_length=30)
class Meta:
db_table = u't_mixingclass'
class Atomicstate(models.Model):
id = models.IntegerField(primary_key=True)
version = models.ForeignKey(Version, db_column='versionid', on_delete=models.DO_NOTHING)
totalangularmomentum = models.FloatField()
lifetime = models.FloatField()
#lifetimeunit = models.ForeignKey(Unit, db_column='lifetimeunitid', related_name='+')
lifetimeunit = models.CharField(max_length=8)
stateenergy = models.FloatField()
#stateenergyunit = models.ForeignKey(Unit, db_column='stateenergyunitid', related_name='+')
stateenergyunit = models.CharField(max_length=8)
ionizationenergy = models.FloatField(null=True, blank=True)
#ionizationenergyunit = models.ForeignKey(Unit, db_column='ionizationenergyunitid', related_name='+')
ionizationenergyunit = models.CharField(max_length=8)
statisticalweight = models.IntegerField()
#statisticalweightunit = models.ForeignKey(Unit, db_column='statisticalweightunitid', related_name='+')
statisticalweightunit = models.CharField(max_length=8)
parity = models.ForeignKey(Parity, db_column='parityid', on_delete=models.DO_NOTHING)
xdata = models.TextField(null=True)
ydata = models.TextField(null=True)
xdataunit = models.CharField(max_length=8)
ydataunit = models.CharField(max_length=8)
class Meta:
db_table = u't_atomicstate'
def xdata_count(self):
return len(self.xdata.split(" "))
def ydata_count(self):
return len(self.ydata.split(" "))
class Atomicstatesource(models.Model):
id = models.IntegerField(primary_key=True)
atomicstate = models.ForeignKey(Atomicstate, db_column='atomicstateid', on_delete=models.DO_NOTHING)
source = models.ForeignKey(Source, db_column='sourceid', on_delete=models.DO_NOTHING)
class Meta:
db_table = u't_atomicstatesource'
class Radiativetransition(models.Model):
id = models.IntegerField(primary_key=True)
version = models.ForeignKey(Version, db_column='versionid', on_delete=models.DO_NOTHING)
#~ version_int = models.IntegerField(db_column='versionid')
atomicion = models.IntegerField(db_column='atomicionid')
elementsymbol = models.CharField(max_length=9)
nuclearcharge = models.IntegerField()
ioncharge = models.IntegerField()
oscillatorstrength = models.FloatField()
weightedoscillatorstrength = models.FloatField()
transitionprobability = models.IntegerField()
wavelength = models.FloatField()
wavelengthunit = models.CharField(max_length=8)
upperatomicstate = models.ForeignKey(Atomicstate, db_column='upperatomicstateid', related_name='+', on_delete=models.DO_NOTHING)
#~ upperatomicstate_int = models.IntegerField(db_column='upperatomicstateid')
loweratomicstate = models.ForeignKey(Atomicstate, db_column='loweratomicstateid', related_name='+', on_delete=models.DO_NOTHING)
#~ loweratomicstate_int = models.IntegerField(db_column='loweratomicstateid')
inchikey = models.CharField(max_length=27)
collider = models.CharField(max_length=8, default="photon")
def abs_weightedoscillatorstrength(self):
return abs(self.weightedoscillatorstrength)
class Meta:
db_table = u'c_recommendedradiativetransition'
class Versionsource(models.Model):
id = models.IntegerField(primary_key=True)
version = models.ForeignKey(Atomicstate, db_column='versionid', on_delete=models.DO_NOTHING)
source = models.ForeignKey(Source, db_column='sourceid', on_delete=models.DO_NOTHING)
class Meta:
db_table = u't_versionsource'
class Atomiccomponent(models.Model):
id = models.IntegerField(primary_key=True)
atomicstate = models.ForeignKey(Atomicstate, db_column='atomicstateid', related_name='atomiccomponent', on_delete=models.DO_NOTHING)
mixingcoefficient = models.FloatField()
mixingclass = models.ForeignKey(Mixingclass, db_column='mixingclassid', on_delete=models.DO_NOTHING)
termlabel = models.CharField(max_length=30)
configuration = models.CharField(max_length=40)
class Meta:
db_table = u't_atomiccomponent'
class Author(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=20)
address = models.TextField(null=True)
class Meta:
db_table = u't_author'
class Authorsource(models.Model):
id = models.IntegerField(primary_key=True)
author = models.ForeignKey(Author, db_column='authorid', on_delete=models.DO_NOTHING)
source = models.ForeignKey(Source, db_column='sourceid', on_delete=models.DO_NOTHING)
rank = models.IntegerField()
class Meta:
db_table = u't_authorsource'
class Dataset(models.Model):
id = models.IntegerField(primary_key=True)
creationdate = models.DateField()
isrecommended = models.IntegerField()
class Meta:
db_table = u't_dataset'
class DatasetVersion(models.Model):
datasetid = models.ForeignKey(Dataset, db_column='datasetid', on_delete=models.DO_NOTHING)
versionid = models.ForeignKey(Version, db_column='versionid', on_delete=models.DO_NOTHING)
class Meta:
db_table = u't_dataseVersion'
class Lscoupling(models.Model):
id = models.IntegerField(primary_key=True)
atomiccomponent = models.ForeignKey(Atomiccomponent, db_column='atomiccomponentid', on_delete=models.DO_NOTHING)
l = models.IntegerField()
s = models.FloatField()
multiplicity = models.IntegerField()
class Meta:
db_table = u't_lscoupling'
|
gpl-3.0
|
[
3,
961,
365,
376,
2599,
13,
10176,
5634,
1402,
859,
14,
199,
3,
2047,
7171,
1172,
370,
886,
314,
2569,
10250,
370,
3633,
642,
1536,
26,
199,
3,
258,
627,
799,
285,
1842,
1709,
7,
1865,
199,
3,
258,
627,
4155,
3238,
1924,
1402,
965,
1373,
901,
543,
5062,
63,
498,
29,
549,
199,
3,
7949,
352,
2867,
370,
11441,
314,
1709,
12,
1325,
2793,
1133,
11441,
1592,
63,
1224,
1338,
503,
901,
1561,
14,
199,
3,
199,
3,
6121,
5317,
26,
2047,
7171,
1172,
370,
5518,
314,
1072,
402,
283,
1176,
13,
2113,
14,
647,
3875,
4229,
359,
21653,
6616,
199,
3,
1901,
2195,
3050,
14,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
646,
2050,
199,
793,
29,
4806,
14,
5572,
360,
86,
455,
3833,
14,
16609,
358,
199,
199,
533,
12008,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2259,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
3248,
7,
268,
268,
199,
533,
5800,
3710,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2322,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
1365,
3710,
7,
268,
268,
268,
199,
533,
5800,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
1350,
3710,
275,
1709,
14,
3190,
8,
2980,
3710,
12,
1592,
63,
2301,
534,
1365,
3710,
344,
297,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
2538,
275,
1709,
14,
6254,
8,
2307,
29,
549,
9,
272,
5361,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
272,
3301,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
14821,
5108,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8251,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
633,
358,
272,
11314,
600,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1167,
12,
2973,
29,
549,
9,
272,
308,
567,
25869,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
2034,
5037,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
14821,
2034,
500,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
14821,
886,
73,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
12,
2973,
29,
549,
9,
257,
2286,
347,
4132,
1247,
8,
277,
304,
267,
1561,
275,
942,
267,
11462,
275,
6529,
1365,
14,
1462,
14,
1541,
8,
1365,
29,
277,
9,
267,
367,
4132,
315,
11462,
26,
288,
1561,
14,
740,
8,
2502,
14,
354,
9,
267,
372,
1561,
268,
268,
2126,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
1365,
7,
421,
199,
533,
445,
426,
15003,
1895,
968,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
1819,
5155,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
25,
9,
272,
302,
947,
274,
1047,
4430,
275,
1709,
14,
3901,
8,
3235,
29,
549,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
595,
15003,
1895,
968,
7,
260,
199,
199,
533,
6596,
3459,
321,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
17546,
15003,
1895,
968,
275,
1709,
14,
3190,
8,
20335,
15003,
1895,
968,
12,
1592,
63,
2301,
534,
595,
15003,
1895,
274,
1410,
5700,
297,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
12250,
1955,
275,
1709,
14,
3901,
8,
3235,
29,
549,
9,
272,
12250,
275,
1709,
14,
13019,
342,
272,
12250,
324,
5277,
68,
275,
1709,
14,
3190,
8,
5072,
12,
1592,
63,
2301,
534,
11535,
324,
5277,
68,
297,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
374,
3459,
321,
7,
421,
199,
533,
18840,
530,
1636,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
365,
3459,
321,
275,
1709,
14,
3190,
8,
1831,
3459,
321,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
374,
3459,
321,
344,
297,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
31709,
16441,
275,
1709,
14,
3901,
342,
272,
315,
13175,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
315,
13175,
498,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1465,
9,
272,
11601,
30169,
530,
4041,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
9,
23855,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
10910,
1636,
7,
523,
421,
199,
533,
3394,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
15374,
1636,
275,
1709,
14,
3190,
8,
31931,
1636,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
10910,
1636,
344,
297,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
31709,
1023,
275,
1709,
14,
3901,
8,
3235,
29,
549,
9,
272,
7143,
602,
275,
1709,
14,
14071,
342,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
1023,
7,
267,
12883,
275,
756,
421,
199,
533,
510,
7945,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
1216,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
462,
1209,
7,
268,
199,
533,
603,
1148,
316,
533,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
1216
] |
[
961,
365,
376,
2599,
13,
10176,
5634,
1402,
859,
14,
199,
3,
2047,
7171,
1172,
370,
886,
314,
2569,
10250,
370,
3633,
642,
1536,
26,
199,
3,
258,
627,
799,
285,
1842,
1709,
7,
1865,
199,
3,
258,
627,
4155,
3238,
1924,
1402,
965,
1373,
901,
543,
5062,
63,
498,
29,
549,
199,
3,
7949,
352,
2867,
370,
11441,
314,
1709,
12,
1325,
2793,
1133,
11441,
1592,
63,
1224,
1338,
503,
901,
1561,
14,
199,
3,
199,
3,
6121,
5317,
26,
2047,
7171,
1172,
370,
5518,
314,
1072,
402,
283,
1176,
13,
2113,
14,
647,
3875,
4229,
359,
21653,
6616,
199,
3,
1901,
2195,
3050,
14,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
646,
2050,
199,
793,
29,
4806,
14,
5572,
360,
86,
455,
3833,
14,
16609,
358,
199,
199,
533,
12008,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2259,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
3248,
7,
268,
268,
199,
533,
5800,
3710,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2322,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
1365,
3710,
7,
268,
268,
268,
199,
533,
5800,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
1350,
3710,
275,
1709,
14,
3190,
8,
2980,
3710,
12,
1592,
63,
2301,
534,
1365,
3710,
344,
297,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
2538,
275,
1709,
14,
6254,
8,
2307,
29,
549,
9,
272,
5361,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
272,
3301,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
14821,
5108,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8251,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
633,
358,
272,
11314,
600,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1167,
12,
2973,
29,
549,
9,
272,
308,
567,
25869,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
2034,
5037,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
14821,
2034,
500,
275,
1709,
14,
3901,
8,
2307,
29,
549,
9,
14821,
886,
73,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1400,
12,
2973,
29,
549,
9,
257,
2286,
347,
4132,
1247,
8,
277,
304,
267,
1561,
275,
942,
267,
11462,
275,
6529,
1365,
14,
1462,
14,
1541,
8,
1365,
29,
277,
9,
267,
367,
4132,
315,
11462,
26,
288,
1561,
14,
740,
8,
2502,
14,
354,
9,
267,
372,
1561,
268,
268,
2126,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
1365,
7,
421,
199,
533,
445,
426,
15003,
1895,
968,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
1819,
5155,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
25,
9,
272,
302,
947,
274,
1047,
4430,
275,
1709,
14,
3901,
8,
3235,
29,
549,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
595,
15003,
1895,
968,
7,
260,
199,
199,
533,
6596,
3459,
321,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
17546,
15003,
1895,
968,
275,
1709,
14,
3190,
8,
20335,
15003,
1895,
968,
12,
1592,
63,
2301,
534,
595,
15003,
1895,
274,
1410,
5700,
297,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
12250,
1955,
275,
1709,
14,
3901,
8,
3235,
29,
549,
9,
272,
12250,
275,
1709,
14,
13019,
342,
272,
12250,
324,
5277,
68,
275,
1709,
14,
3190,
8,
5072,
12,
1592,
63,
2301,
534,
11535,
324,
5277,
68,
297,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
374,
3459,
321,
7,
421,
199,
533,
18840,
530,
1636,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
365,
3459,
321,
275,
1709,
14,
3190,
8,
1831,
3459,
321,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
374,
3459,
321,
344,
297,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
31709,
16441,
275,
1709,
14,
3901,
342,
272,
315,
13175,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
315,
13175,
498,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1465,
9,
272,
11601,
30169,
530,
4041,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
9,
23855,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
10910,
1636,
7,
523,
421,
199,
533,
3394,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
15374,
1636,
275,
1709,
14,
3190,
8,
31931,
1636,
12,
2973,
29,
549,
12,
1592,
63,
2301,
534,
10910,
1636,
344,
297,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
1649,
63,
4609,
40,
1206,
9,
272,
31709,
1023,
275,
1709,
14,
3901,
8,
3235,
29,
549,
9,
272,
7143,
602,
275,
1709,
14,
14071,
342,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
1023,
7,
267,
12883,
275,
756,
421,
199,
533,
510,
7945,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
1216,
9,
272,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
399,
1133,
63,
462,
1209,
7,
268,
199,
533,
603,
1148,
316,
533,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
3901,
8,
3327,
63,
498,
29,
549,
9,
272,
574,
275,
1709,
14,
2183,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
1216,
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,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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
] |
scripnichenko/nova
|
nova/objects/agent.py
|
13
|
2919
|
# Copyright 2014 Red Hat, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import db
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
@base.NovaObjectRegistry.register
class Agent(base.NovaPersistentObject, base.NovaObject):
VERSION = '1.0'
fields = {
'id': fields.IntegerField(read_only=True),
'hypervisor': fields.StringField(),
'os': fields.StringField(),
'architecture': fields.StringField(),
'version': fields.StringField(),
'url': fields.StringField(),
'md5hash': fields.StringField(),
}
@staticmethod
def _from_db_object(context, agent, db_agent):
for name in agent.fields:
setattr(agent, name, db_agent[name])
agent._context = context
agent.obj_reset_changes()
return agent
@base.remotable_classmethod
def get_by_triple(cls, context, hypervisor, os, architecture):
db_agent = db.agent_build_get_by_triple(context, hypervisor,
os, architecture)
if not db_agent:
return None
return cls._from_db_object(context, objects.Agent(), db_agent)
@base.remotable
def create(self):
updates = self.obj_get_changes()
if 'id' in updates:
raise exception.ObjectActionError(action='create',
reason='Already Created')
db_agent = db.agent_build_create(self._context, updates)
self._from_db_object(self._context, self, db_agent)
@base.remotable
def destroy(self):
db.agent_build_destroy(self._context, self.id)
@base.remotable
def save(self):
updates = self.obj_get_changes()
db.agent_build_update(self._context, self.id, updates)
self.obj_reset_changes()
@base.NovaObjectRegistry.register
class AgentList(base.ObjectListBase, base.NovaObject):
VERSION = '1.0'
fields = {
'objects': fields.ListOfObjectsField('Agent'),
}
obj_relationships = {
'objects': [('1.0', '1.0')],
}
@base.remotable_classmethod
def get_all(cls, context, hypervisor=None):
db_agents = db.agent_build_get_all(context, hypervisor=hypervisor)
return base.obj_make_list(context, cls(), objects.Agent, db_agents)
|
apache-2.0
|
[
3,
259,
1898,
6927,
9572,
13002,
12,
3277,
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,
504,
5913,
492,
1592,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
1462,
492,
1300,
199,
504,
5913,
14,
1462,
492,
1504,
421,
199,
32,
1095,
14,
19884,
1692,
10899,
14,
2683,
199,
533,
19866,
8,
1095,
14,
19884,
31966,
1692,
12,
1300,
14,
19884,
1692,
304,
272,
15945,
275,
283,
17,
14,
16,
7,
339,
1504,
275,
469,
267,
283,
344,
356,
1504,
14,
3901,
8,
739,
63,
2118,
29,
549,
395,
267,
283,
18237,
356,
1504,
14,
14912,
1062,
267,
283,
736,
356,
1504,
14,
14912,
1062,
267,
283,
19134,
356,
1504,
14,
14912,
1062,
267,
283,
1023,
356,
1504,
14,
14912,
1062,
267,
283,
633,
356,
1504,
14,
14912,
1062,
267,
283,
1064,
21,
2227,
356,
1504,
14,
14912,
1062,
267,
789,
339,
768,
4639,
272,
347,
485,
504,
63,
697,
63,
785,
8,
1100,
12,
6631,
12,
1592,
63,
4054,
304,
267,
367,
536,
315,
6631,
14,
955,
26,
288,
5371,
8,
4054,
12,
536,
12,
1592,
63,
4054,
59,
354,
566,
267,
6631,
423,
1100,
275,
1067,
267,
6631,
14,
1113,
63,
3958,
63,
6627,
342,
267,
372,
6631,
339,
768,
1095,
14,
13179,
357,
461,
63,
3744,
272,
347,
664,
63,
991,
63,
19956,
8,
1886,
12,
1067,
12,
21724,
12,
747,
12,
15931,
304,
267,
1592,
63,
4054,
275,
1592,
14,
4054,
63,
1506,
63,
362,
63,
991,
63,
19956,
8,
1100,
12,
21724,
12,
6059,
747,
12,
15931,
9,
267,
340,
440,
1592,
63,
4054,
26,
288,
372,
488,
267,
372,
843,
423,
504,
63,
697,
63,
785,
8,
1100,
12,
2251,
14,
7788,
1062,
1592,
63,
4054,
9,
339,
768,
1095,
14,
13179,
357,
461,
272,
347,
1218,
8,
277,
304,
267,
7029,
275,
291,
14,
1113,
63,
362,
63,
6627,
342,
267,
340,
283,
344,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
1287,
534,
981,
297,
6343,
4499,
534,
16760,
18208,
358,
267,
1592,
63,
4054,
275,
1592,
14,
4054,
63,
1506,
63,
981,
8,
277,
423,
1100,
12,
7029,
9,
267,
291,
423,
504,
63,
697,
63,
785,
8,
277,
423,
1100,
12,
291,
12,
1592,
63,
4054,
9,
339,
768,
1095,
14,
13179,
357,
461,
272,
347,
11972,
8,
277,
304,
267,
1592,
14,
4054,
63,
1506,
63,
7237,
8,
277,
423,
1100,
12,
291,
14,
344,
9,
339,
768,
1095,
14,
13179,
357,
461,
272,
347,
3354,
8,
277,
304,
267,
7029,
275,
291,
14,
1113,
63,
362,
63,
6627,
342,
267,
1592,
14,
4054,
63,
1506,
63,
873,
8,
277,
423,
1100,
12,
291,
14,
344,
12,
7029,
9,
267,
291,
14,
1113,
63,
3958,
63,
6627,
342,
421,
199,
32,
1095,
14,
19884,
1692,
10899,
14,
2683,
199,
533,
19866,
1296,
8,
1095,
14,
1692,
1296,
1563,
12,
1300,
14,
19884,
1692,
304,
272,
15945,
275,
283,
17,
14,
16,
7,
339,
1504,
275,
469,
267,
283,
1462,
356,
1504,
14,
30210,
11188,
792,
360,
7788,
659,
267,
789,
272,
1559,
63,
24034,
275,
469,
267,
283,
1462,
356,
4274,
17,
14,
16,
297,
283,
17,
14,
16,
2665,
267,
789,
339,
768,
1095,
14,
13179,
357,
461,
63,
3744,
272,
347,
664,
63,
452,
8,
1886,
12,
1067,
12,
21724,
29,
403,
304,
267,
1592,
63,
14250,
275,
1592,
14,
4054,
63,
1506,
63,
362,
63,
452,
8,
1100,
12,
21724,
29,
18237,
9,
267,
372,
1300,
14,
1113,
63,
1875,
63,
513,
8,
1100,
12,
843,
1062,
2251,
14,
7788,
12,
1592,
63,
14250,
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
] |
[
259,
1898,
6927,
9572,
13002,
12,
3277,
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,
504,
5913,
492,
1592,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
14,
1462,
492,
1300,
199,
504,
5913,
14,
1462,
492,
1504,
421,
199,
32,
1095,
14,
19884,
1692,
10899,
14,
2683,
199,
533,
19866,
8,
1095,
14,
19884,
31966,
1692,
12,
1300,
14,
19884,
1692,
304,
272,
15945,
275,
283,
17,
14,
16,
7,
339,
1504,
275,
469,
267,
283,
344,
356,
1504,
14,
3901,
8,
739,
63,
2118,
29,
549,
395,
267,
283,
18237,
356,
1504,
14,
14912,
1062,
267,
283,
736,
356,
1504,
14,
14912,
1062,
267,
283,
19134,
356,
1504,
14,
14912,
1062,
267,
283,
1023,
356,
1504,
14,
14912,
1062,
267,
283,
633,
356,
1504,
14,
14912,
1062,
267,
283,
1064,
21,
2227,
356,
1504,
14,
14912,
1062,
267,
789,
339,
768,
4639,
272,
347,
485,
504,
63,
697,
63,
785,
8,
1100,
12,
6631,
12,
1592,
63,
4054,
304,
267,
367,
536,
315,
6631,
14,
955,
26,
288,
5371,
8,
4054,
12,
536,
12,
1592,
63,
4054,
59,
354,
566,
267,
6631,
423,
1100,
275,
1067,
267,
6631,
14,
1113,
63,
3958,
63,
6627,
342,
267,
372,
6631,
339,
768,
1095,
14,
13179,
357,
461,
63,
3744,
272,
347,
664,
63,
991,
63,
19956,
8,
1886,
12,
1067,
12,
21724,
12,
747,
12,
15931,
304,
267,
1592,
63,
4054,
275,
1592,
14,
4054,
63,
1506,
63,
362,
63,
991,
63,
19956,
8,
1100,
12,
21724,
12,
6059,
747,
12,
15931,
9,
267,
340,
440,
1592,
63,
4054,
26,
288,
372,
488,
267,
372,
843,
423,
504,
63,
697,
63,
785,
8,
1100,
12,
2251,
14,
7788,
1062,
1592,
63,
4054,
9,
339,
768,
1095,
14,
13179,
357,
461,
272,
347,
1218,
8,
277,
304,
267,
7029,
275,
291,
14,
1113,
63,
362,
63,
6627,
342,
267,
340,
283,
344,
7,
315,
7029,
26,
288,
746,
1919,
14,
1692,
3310,
547,
8,
1287,
534,
981,
297,
6343,
4499,
534,
16760,
18208,
358,
267,
1592,
63,
4054,
275,
1592,
14,
4054,
63,
1506,
63,
981,
8,
277,
423,
1100,
12,
7029,
9,
267,
291,
423,
504,
63,
697,
63,
785,
8,
277,
423,
1100,
12,
291,
12,
1592,
63,
4054,
9,
339,
768,
1095,
14,
13179,
357,
461,
272,
347,
11972,
8,
277,
304,
267,
1592,
14,
4054,
63,
1506,
63,
7237,
8,
277,
423,
1100,
12,
291,
14,
344,
9,
339,
768,
1095,
14,
13179,
357,
461,
272,
347,
3354,
8,
277,
304,
267,
7029,
275,
291,
14,
1113,
63,
362,
63,
6627,
342,
267,
1592,
14,
4054,
63,
1506,
63,
873,
8,
277,
423,
1100,
12,
291,
14,
344,
12,
7029,
9,
267,
291,
14,
1113,
63,
3958,
63,
6627,
342,
421,
199,
32,
1095,
14,
19884,
1692,
10899,
14,
2683,
199,
533,
19866,
1296,
8,
1095,
14,
1692,
1296,
1563,
12,
1300,
14,
19884,
1692,
304,
272,
15945,
275,
283,
17,
14,
16,
7,
339,
1504,
275,
469,
267,
283,
1462,
356,
1504,
14,
30210,
11188,
792,
360,
7788,
659,
267,
789,
272,
1559,
63,
24034,
275,
469,
267,
283,
1462,
356,
4274,
17,
14,
16,
297,
283,
17,
14,
16,
2665,
267,
789,
339,
768,
1095,
14,
13179,
357,
461,
63,
3744,
272,
347,
664,
63,
452,
8,
1886,
12,
1067,
12,
21724,
29,
403,
304,
267,
1592,
63,
14250,
275,
1592,
14,
4054,
63,
1506,
63,
362,
63,
452,
8,
1100,
12,
21724,
29,
18237,
9,
267,
372,
1300,
14,
1113,
63,
1875,
63,
513,
8,
1100,
12,
843,
1062,
2251,
14,
7788,
12,
1592,
63,
14250,
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,
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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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
] |
Jeff-Lewis/namebench
|
nb_third_party/dns/rdtypes/sigbase.py
|
235
|
6349
|
# Copyright (C) 2004-2007, 2009, 2010 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation 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 NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM 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.
import calendar
import struct
import time
import dns.dnssec
import dns.exception
import dns.rdata
import dns.rdatatype
class BadSigTime(dns.exception.DNSException):
"""Raised when a SIG or RRSIG RR's time cannot be parsed."""
pass
def sigtime_to_posixtime(what):
if len(what) != 14:
raise BadSigTime
year = int(what[0:4])
month = int(what[4:6])
day = int(what[6:8])
hour = int(what[8:10])
minute = int(what[10:12])
second = int(what[12:14])
return calendar.timegm((year, month, day, hour, minute, second,
0, 0, 0))
def posixtime_to_sigtime(what):
return time.strftime('%Y%m%d%H%M%S', time.gmtime(what))
class SIGBase(dns.rdata.Rdata):
"""SIG-like record base
@ivar type_covered: the rdata type this signature covers
@type type_covered: int
@ivar algorithm: the algorithm used for the sig
@type algorithm: int
@ivar labels: number of labels
@type labels: int
@ivar original_ttl: the original TTL
@type original_ttl: long
@ivar expiration: signature expiration time
@type expiration: long
@ivar inception: signature inception time
@type inception: long
@ivar key_tag: the key tag
@type key_tag: int
@ivar signer: the signer
@type signer: dns.name.Name object
@ivar signature: the signature
@type signature: string"""
__slots__ = ['type_covered', 'algorithm', 'labels', 'original_ttl',
'expiration', 'inception', 'key_tag', 'signer',
'signature']
def __init__(self, rdclass, rdtype, type_covered, algorithm, labels,
original_ttl, expiration, inception, key_tag, signer,
signature):
super(SIGBase, self).__init__(rdclass, rdtype)
self.type_covered = type_covered
self.algorithm = algorithm
self.labels = labels
self.original_ttl = original_ttl
self.expiration = expiration
self.inception = inception
self.key_tag = key_tag
self.signer = signer
self.signature = signature
def covers(self):
return self.type_covered
def to_text(self, origin=None, relativize=True, **kw):
return '%s %d %d %d %s %s %d %s %s' % (
dns.rdatatype.to_text(self.type_covered),
self.algorithm,
self.labels,
self.original_ttl,
posixtime_to_sigtime(self.expiration),
posixtime_to_sigtime(self.inception),
self.key_tag,
self.signer,
dns.rdata._base64ify(self.signature)
)
def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
type_covered = dns.rdatatype.from_text(tok.get_string())
algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
labels = tok.get_int()
original_ttl = tok.get_ttl()
expiration = sigtime_to_posixtime(tok.get_string())
inception = sigtime_to_posixtime(tok.get_string())
key_tag = tok.get_int()
signer = tok.get_name()
signer = signer.choose_relativity(origin, relativize)
chunks = []
while 1:
t = tok.get().unescape()
if t.is_eol_or_eof():
break
if not t.is_identifier():
raise dns.exception.SyntaxError
chunks.append(t.value)
b64 = ''.join(chunks)
signature = b64.decode('base64_codec')
return cls(rdclass, rdtype, type_covered, algorithm, labels,
original_ttl, expiration, inception, key_tag, signer,
signature)
from_text = classmethod(from_text)
def to_wire(self, file, compress = None, origin = None):
header = struct.pack('!HBBIIIH', self.type_covered,
self.algorithm, self.labels,
self.original_ttl, self.expiration,
self.inception, self.key_tag)
file.write(header)
self.signer.to_wire(file, None, origin)
file.write(self.signature)
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
header = struct.unpack('!HBBIIIH', wire[current : current + 18])
current += 18
rdlen -= 18
(signer, cused) = dns.name.from_wire(wire[: current + rdlen], current)
current += cused
rdlen -= cused
if not origin is None:
signer = signer.relativize(origin)
signature = wire[current : current + rdlen]
return cls(rdclass, rdtype, header[0], header[1], header[2],
header[3], header[4], header[5], header[6], signer,
signature)
from_wire = classmethod(from_wire)
def choose_relativity(self, origin = None, relativize = True):
self.signer = self.signer.choose_relativity(origin, relativize)
def _cmp(self, other):
hs = struct.pack('!HBBIIIH', self.type_covered,
self.algorithm, self.labels,
self.original_ttl, self.expiration,
self.inception, self.key_tag)
ho = struct.pack('!HBBIIIH', other.type_covered,
other.algorithm, other.labels,
other.original_ttl, other.expiration,
other.inception, other.key_tag)
v = cmp(hs, ho)
if v == 0:
v = cmp(self.signer, other.signer)
if v == 0:
v = cmp(self.signature, other.signature)
return v
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
8353,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
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,
4825,
4896,
2639,
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,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
11234,
199,
646,
2702,
199,
646,
900,
199,
199,
646,
6715,
14,
5797,
3321,
199,
646,
6715,
14,
1971,
199,
646,
6715,
14,
23203,
199,
646,
6715,
14,
82,
14184,
199,
199,
533,
8857,
11575,
1366,
8,
5797,
14,
1971,
14,
10872,
21686,
304,
272,
408,
16894,
1380,
282,
15522,
503,
27222,
7864,
27222,
1159,
900,
3913,
506,
4565,
1041,
272,
986,
199,
199,
318,
5259,
521,
63,
475,
63,
9228,
521,
8,
10058,
304,
272,
340,
822,
8,
10058,
9,
1137,
4329,
26,
267,
746,
8857,
11575,
1366,
272,
5361,
275,
1109,
8,
10058,
59,
16,
26,
20,
566,
272,
5794,
275,
1109,
8,
10058,
59,
20,
26,
22,
566,
272,
5382,
275,
1109,
8,
10058,
59,
22,
26,
24,
566,
272,
6925,
275,
1109,
8,
10058,
59,
24,
26,
709,
566,
272,
12709,
275,
1109,
8,
10058,
59,
709,
26,
713,
566,
272,
3499,
275,
1109,
8,
10058,
59,
713,
26,
1079,
566,
272,
372,
11234,
14,
521,
13844,
1332,
3403,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
12,
1169,
378,
12,
378,
12,
378,
430,
199,
199,
318,
10694,
521,
63,
475,
63,
4093,
521,
8,
10058,
304,
272,
372,
900,
14,
6205,
3508,
57,
5,
77,
5,
68,
5,
40,
5,
45,
5,
51,
297,
900,
14,
22227,
8,
10058,
430,
199,
199,
533,
15522,
1563,
8,
5797,
14,
23203,
14,
50,
576,
304,
272,
408,
7864,
13,
2930,
2777,
1300,
339,
768,
7725,
730,
63,
13560,
26,
314,
27020,
730,
642,
4955,
25858,
272,
768,
466,
730,
63,
13560,
26,
1109,
272,
768,
7725,
5563,
26,
314,
5563,
1202,
367,
314,
5259,
272,
768,
466,
5563,
26,
1109,
272,
768,
7725,
3628,
26,
1329,
402,
3628,
272,
768,
466,
3628,
26,
1109,
272,
768,
7725,
3379,
63,
12130,
26,
314,
3379,
30822,
272,
768,
466,
3379,
63,
12130,
26,
1846,
272,
768,
7725,
15399,
26,
4955,
15399,
900,
272,
768,
466,
15399,
26,
1846,
272,
768,
7725,
315,
814,
26,
4955,
315,
814,
900,
272,
768,
466,
315,
814,
26,
1846,
272,
768,
7725,
790,
63,
1450,
26,
314,
790,
1947,
272,
768,
466,
790,
63,
1450,
26,
1109,
272,
768,
7725,
24902,
26,
314,
24902,
272,
768,
466,
24902,
26,
6715,
14,
354,
14,
985,
909,
272,
768,
7725,
4955,
26,
314,
4955,
272,
768,
466,
4955,
26,
1059,
624,
339,
636,
7257,
363,
275,
788,
466,
63,
13560,
297,
283,
8833,
297,
283,
3512,
297,
283,
5043,
63,
12130,
297,
326,
283,
15469,
297,
283,
262,
814,
297,
283,
498,
63,
1450,
297,
283,
25399,
297,
326,
283,
5233,
418,
339,
347,
636,
826,
721,
277,
12,
29320,
12,
22764,
12,
730,
63,
13560,
12,
5563,
12,
3628,
12,
326,
3379,
63,
12130,
12,
15399,
12,
315,
814,
12,
790,
63,
1450,
12,
24902,
12,
326,
4955,
304,
267,
1613,
8,
7864,
1563,
12,
291,
2843,
826,
721,
30186,
12,
22764,
9,
267,
291,
14,
466,
63,
13560,
275,
730,
63,
13560,
267,
291,
14,
8833,
275,
5563,
267,
291,
14,
3512,
275,
3628,
267,
291,
14,
5043,
63,
12130,
275,
3379,
63,
12130,
267,
291,
14,
15469,
275,
15399,
267,
291,
14,
262,
814,
275,
315,
814,
267,
291,
14,
498,
63,
1450,
275,
790,
63,
1450,
267,
291,
14,
25399,
275,
24902,
267,
291,
14,
5233,
275,
4955,
339,
347,
25858,
8,
277,
304,
267,
372,
291,
14,
466,
63,
13560,
339,
347,
370,
63,
505,
8,
277,
12,
6330,
29,
403,
12,
13773,
29282,
29,
549,
12,
1011,
829,
304,
267,
372,
1543,
83,
450,
68,
450,
68,
450,
68,
450,
83,
450,
83,
450,
68,
450,
83,
450,
83,
7,
450,
334,
288,
6715,
14,
82,
14184,
14,
475,
63,
505,
8,
277,
14,
466,
63,
13560,
395,
288,
291,
14,
8833,
12,
288,
291,
14,
3512,
12,
288,
291,
14,
5043,
63,
12130,
12,
288,
10694,
521,
63,
475,
63,
4093,
521,
8,
277,
14,
15469,
395,
288,
10694,
521,
63,
475,
63,
4093,
521,
8,
277,
14,
262,
814,
395,
288,
291,
14,
498,
63,
1450,
12,
288,
291,
14,
25399,
12,
288,
6715,
14,
23203,
423,
1095,
772,
2021,
8,
277,
14,
5233,
9,
288,
776,
339,
347,
687,
63,
505,
8,
1886,
12,
29320,
12,
22764,
12,
8431,
12,
6330,
275,
488,
12,
13773,
29282,
275,
715,
304,
267,
730,
63,
13560,
275,
6715,
14,
82,
14184,
14,
504,
63,
505,
8,
9305,
14,
362,
63,
875,
1012,
267,
5563,
275,
6715,
14,
5797,
3321,
14,
8833,
63,
504,
63,
505,
8,
9305,
14,
362,
63,
875,
1012,
267,
3628,
275,
8431,
14,
362,
63,
442,
342,
267,
3379,
63,
12130,
275,
8431,
14,
362,
63,
12130,
342,
267,
15399,
275,
5259,
521,
63,
475,
63,
9228,
521,
8,
9305,
14,
362,
63,
875,
1012,
267,
315,
814,
275,
5259,
521,
63,
475,
63,
9228,
521,
8,
9305,
14,
362,
63,
875,
1012,
267,
790,
63,
1450,
275,
8431,
14,
362,
63,
442,
342,
267,
24902,
275,
8431,
14,
362,
63,
354,
342,
267,
24902,
275,
24902,
14,
16143
] |
[
1898,
334,
35,
9,
8353,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
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,
4825,
4896,
2639,
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,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
11234,
199,
646,
2702,
199,
646,
900,
199,
199,
646,
6715,
14,
5797,
3321,
199,
646,
6715,
14,
1971,
199,
646,
6715,
14,
23203,
199,
646,
6715,
14,
82,
14184,
199,
199,
533,
8857,
11575,
1366,
8,
5797,
14,
1971,
14,
10872,
21686,
304,
272,
408,
16894,
1380,
282,
15522,
503,
27222,
7864,
27222,
1159,
900,
3913,
506,
4565,
1041,
272,
986,
199,
199,
318,
5259,
521,
63,
475,
63,
9228,
521,
8,
10058,
304,
272,
340,
822,
8,
10058,
9,
1137,
4329,
26,
267,
746,
8857,
11575,
1366,
272,
5361,
275,
1109,
8,
10058,
59,
16,
26,
20,
566,
272,
5794,
275,
1109,
8,
10058,
59,
20,
26,
22,
566,
272,
5382,
275,
1109,
8,
10058,
59,
22,
26,
24,
566,
272,
6925,
275,
1109,
8,
10058,
59,
24,
26,
709,
566,
272,
12709,
275,
1109,
8,
10058,
59,
709,
26,
713,
566,
272,
3499,
275,
1109,
8,
10058,
59,
713,
26,
1079,
566,
272,
372,
11234,
14,
521,
13844,
1332,
3403,
12,
5794,
12,
5382,
12,
6925,
12,
12709,
12,
3499,
12,
1169,
378,
12,
378,
12,
378,
430,
199,
199,
318,
10694,
521,
63,
475,
63,
4093,
521,
8,
10058,
304,
272,
372,
900,
14,
6205,
3508,
57,
5,
77,
5,
68,
5,
40,
5,
45,
5,
51,
297,
900,
14,
22227,
8,
10058,
430,
199,
199,
533,
15522,
1563,
8,
5797,
14,
23203,
14,
50,
576,
304,
272,
408,
7864,
13,
2930,
2777,
1300,
339,
768,
7725,
730,
63,
13560,
26,
314,
27020,
730,
642,
4955,
25858,
272,
768,
466,
730,
63,
13560,
26,
1109,
272,
768,
7725,
5563,
26,
314,
5563,
1202,
367,
314,
5259,
272,
768,
466,
5563,
26,
1109,
272,
768,
7725,
3628,
26,
1329,
402,
3628,
272,
768,
466,
3628,
26,
1109,
272,
768,
7725,
3379,
63,
12130,
26,
314,
3379,
30822,
272,
768,
466,
3379,
63,
12130,
26,
1846,
272,
768,
7725,
15399,
26,
4955,
15399,
900,
272,
768,
466,
15399,
26,
1846,
272,
768,
7725,
315,
814,
26,
4955,
315,
814,
900,
272,
768,
466,
315,
814,
26,
1846,
272,
768,
7725,
790,
63,
1450,
26,
314,
790,
1947,
272,
768,
466,
790,
63,
1450,
26,
1109,
272,
768,
7725,
24902,
26,
314,
24902,
272,
768,
466,
24902,
26,
6715,
14,
354,
14,
985,
909,
272,
768,
7725,
4955,
26,
314,
4955,
272,
768,
466,
4955,
26,
1059,
624,
339,
636,
7257,
363,
275,
788,
466,
63,
13560,
297,
283,
8833,
297,
283,
3512,
297,
283,
5043,
63,
12130,
297,
326,
283,
15469,
297,
283,
262,
814,
297,
283,
498,
63,
1450,
297,
283,
25399,
297,
326,
283,
5233,
418,
339,
347,
636,
826,
721,
277,
12,
29320,
12,
22764,
12,
730,
63,
13560,
12,
5563,
12,
3628,
12,
326,
3379,
63,
12130,
12,
15399,
12,
315,
814,
12,
790,
63,
1450,
12,
24902,
12,
326,
4955,
304,
267,
1613,
8,
7864,
1563,
12,
291,
2843,
826,
721,
30186,
12,
22764,
9,
267,
291,
14,
466,
63,
13560,
275,
730,
63,
13560,
267,
291,
14,
8833,
275,
5563,
267,
291,
14,
3512,
275,
3628,
267,
291,
14,
5043,
63,
12130,
275,
3379,
63,
12130,
267,
291,
14,
15469,
275,
15399,
267,
291,
14,
262,
814,
275,
315,
814,
267,
291,
14,
498,
63,
1450,
275,
790,
63,
1450,
267,
291,
14,
25399,
275,
24902,
267,
291,
14,
5233,
275,
4955,
339,
347,
25858,
8,
277,
304,
267,
372,
291,
14,
466,
63,
13560,
339,
347,
370,
63,
505,
8,
277,
12,
6330,
29,
403,
12,
13773,
29282,
29,
549,
12,
1011,
829,
304,
267,
372,
1543,
83,
450,
68,
450,
68,
450,
68,
450,
83,
450,
83,
450,
68,
450,
83,
450,
83,
7,
450,
334,
288,
6715,
14,
82,
14184,
14,
475,
63,
505,
8,
277,
14,
466,
63,
13560,
395,
288,
291,
14,
8833,
12,
288,
291,
14,
3512,
12,
288,
291,
14,
5043,
63,
12130,
12,
288,
10694,
521,
63,
475,
63,
4093,
521,
8,
277,
14,
15469,
395,
288,
10694,
521,
63,
475,
63,
4093,
521,
8,
277,
14,
262,
814,
395,
288,
291,
14,
498,
63,
1450,
12,
288,
291,
14,
25399,
12,
288,
6715,
14,
23203,
423,
1095,
772,
2021,
8,
277,
14,
5233,
9,
288,
776,
339,
347,
687,
63,
505,
8,
1886,
12,
29320,
12,
22764,
12,
8431,
12,
6330,
275,
488,
12,
13773,
29282,
275,
715,
304,
267,
730,
63,
13560,
275,
6715,
14,
82,
14184,
14,
504,
63,
505,
8,
9305,
14,
362,
63,
875,
1012,
267,
5563,
275,
6715,
14,
5797,
3321,
14,
8833,
63,
504,
63,
505,
8,
9305,
14,
362,
63,
875,
1012,
267,
3628,
275,
8431,
14,
362,
63,
442,
342,
267,
3379,
63,
12130,
275,
8431,
14,
362,
63,
12130,
342,
267,
15399,
275,
5259,
521,
63,
475,
63,
9228,
521,
8,
9305,
14,
362,
63,
875,
1012,
267,
315,
814,
275,
5259,
521,
63,
475,
63,
9228,
521,
8,
9305,
14,
362,
63,
875,
1012,
267,
790,
63,
1450,
275,
8431,
14,
362,
63,
442,
342,
267,
24902,
275,
8431,
14,
362,
63,
354,
342,
267,
24902,
275,
24902,
14,
16143,
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,
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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
] |
Lh4cKg/sl4a
|
python/src/Lib/ctypes/test/__init__.py
|
90
|
7110
|
import os, sys, unittest, getopt, time
use_resources = []
class ResourceDenied(Exception):
"""Test skipped because it requested a disallowed resource.
This is raised when a test calls requires() for a resource that
has not be enabled. Resources are defined by test modules.
"""
def is_resource_enabled(resource):
"""Test whether a resource is enabled.
If the caller's module is __main__ then automatically return True."""
if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
return True
result = use_resources is not None and \
(resource in use_resources or "*" in use_resources)
if not result:
_unavail[resource] = None
return result
_unavail = {}
def requires(resource, msg=None):
"""Raise ResourceDenied if the specified resource is not available.
If the caller's module is __main__ then automatically return True."""
# see if the caller's module is __main__ - if so, treat as if
# the resource was set
if sys._getframe().f_back.f_globals.get("__name__") == "__main__":
return
if not is_resource_enabled(resource):
if msg is None:
msg = "Use of the `%s' resource not enabled" % resource
raise ResourceDenied(msg)
def find_package_modules(package, mask):
import fnmatch
if (hasattr(package, "__loader__") and
hasattr(package.__loader__, '_files')):
path = package.__name__.replace(".", os.path.sep)
mask = os.path.join(path, mask)
for fnm in package.__loader__._files.iterkeys():
if fnmatch.fnmatchcase(fnm, mask):
yield os.path.splitext(fnm)[0].replace(os.path.sep, ".")
else:
path = package.__path__[0]
for fnm in os.listdir(path):
if fnmatch.fnmatchcase(fnm, mask):
yield "%s.%s" % (package.__name__, os.path.splitext(fnm)[0])
def get_tests(package, mask, verbosity, exclude=()):
"""Return a list of skipped test modules, and a list of test cases."""
tests = []
skipped = []
for modname in find_package_modules(package, mask):
if modname.split(".")[-1] in exclude:
skipped.append(modname)
if verbosity > 1:
print >> sys.stderr, "Skipped %s: excluded" % modname
continue
try:
mod = __import__(modname, globals(), locals(), ['*'])
except ResourceDenied, detail:
skipped.append(modname)
if verbosity > 1:
print >> sys.stderr, "Skipped %s: %s" % (modname, detail)
continue
for name in dir(mod):
if name.startswith("_"):
continue
o = getattr(mod, name)
if type(o) is type(unittest.TestCase) and issubclass(o, unittest.TestCase):
tests.append(o)
return skipped, tests
def usage():
print __doc__
return 1
def test_with_refcounts(runner, verbosity, testcase):
"""Run testcase several times, tracking reference counts."""
import gc
import ctypes
ptc = ctypes._pointer_type_cache.copy()
cfc = ctypes._c_functype_cache.copy()
wfc = ctypes._win_functype_cache.copy()
# when searching for refcount leaks, we have to manually reset any
# caches that ctypes has.
def cleanup():
ctypes._pointer_type_cache = ptc.copy()
ctypes._c_functype_cache = cfc.copy()
ctypes._win_functype_cache = wfc.copy()
gc.collect()
test = unittest.makeSuite(testcase)
for i in range(5):
rc = sys.gettotalrefcount()
runner.run(test)
cleanup()
COUNT = 5
refcounts = [None] * COUNT
for i in range(COUNT):
rc = sys.gettotalrefcount()
runner.run(test)
cleanup()
refcounts[i] = sys.gettotalrefcount() - rc
if filter(None, refcounts):
print "%s leaks:\n\t" % testcase, refcounts
elif verbosity:
print "%s: ok." % testcase
class TestRunner(unittest.TextTestRunner):
def run(self, test, skipped):
"Run the given test case or test suite."
# Same as unittest.TextTestRunner.run, except that it reports
# skipped tests.
result = self._makeResult()
startTime = time.time()
test(result)
stopTime = time.time()
timeTaken = stopTime - startTime
result.printErrors()
self.stream.writeln(result.separator2)
run = result.testsRun
if _unavail: #skipped:
requested = _unavail.keys()
requested.sort()
self.stream.writeln("Ran %d test%s in %.3fs (%s module%s skipped)" %
(run, run != 1 and "s" or "", timeTaken,
len(skipped),
len(skipped) != 1 and "s" or ""))
self.stream.writeln("Unavailable resources: %s" % ", ".join(requested))
else:
self.stream.writeln("Ran %d test%s in %.3fs" %
(run, run != 1 and "s" or "", timeTaken))
self.stream.writeln()
if not result.wasSuccessful():
self.stream.write("FAILED (")
failed, errored = map(len, (result.failures, result.errors))
if failed:
self.stream.write("failures=%d" % failed)
if errored:
if failed: self.stream.write(", ")
self.stream.write("errors=%d" % errored)
self.stream.writeln(")")
else:
self.stream.writeln("OK")
return result
def main(*packages):
try:
opts, args = getopt.getopt(sys.argv[1:], "rqvu:x:")
except getopt.error:
return usage()
verbosity = 1
search_leaks = False
exclude = []
for flag, value in opts:
if flag == "-q":
verbosity -= 1
elif flag == "-v":
verbosity += 1
elif flag == "-r":
try:
sys.gettotalrefcount
except AttributeError:
print >> sys.stderr, "-r flag requires Python debug build"
return -1
search_leaks = True
elif flag == "-u":
use_resources.extend(value.split(","))
elif flag == "-x":
exclude.extend(value.split(","))
mask = "test_*.py"
if args:
mask = args[0]
for package in packages:
run_tests(package, mask, verbosity, search_leaks, exclude)
def run_tests(package, mask, verbosity, search_leaks, exclude):
skipped, testcases = get_tests(package, mask, verbosity, exclude)
runner = TestRunner(verbosity=verbosity)
suites = [unittest.makeSuite(o) for o in testcases]
suite = unittest.TestSuite(suites)
result = runner.run(suite, skipped)
if search_leaks:
# hunt for refcount leaks
runner = BasicTestRunner()
for t in testcases:
test_with_refcounts(runner, verbosity, t)
return bool(result.errors)
class BasicTestRunner:
def run(self, test):
result = unittest.TestResult()
test(result)
return result
|
apache-2.0
|
[
646,
747,
12,
984,
12,
2882,
12,
12733,
12,
900,
199,
199,
1180,
63,
4435,
275,
942,
199,
199,
533,
7337,
15729,
8,
1726,
304,
272,
408,
774,
9645,
2952,
652,
5839,
282,
30994,
2073,
14,
339,
961,
365,
4915,
1380,
282,
511,
4882,
5074,
342,
367,
282,
2073,
626,
272,
965,
440,
506,
5223,
14,
221,
26250,
787,
3247,
701,
511,
4621,
14,
272,
408,
199,
199,
318,
365,
63,
1927,
63,
3827,
8,
1927,
304,
272,
408,
774,
3775,
282,
2073,
365,
5223,
14,
339,
982,
314,
8025,
1159,
859,
365,
636,
973,
363,
2066,
5847,
372,
715,
1041,
272,
340,
984,
423,
20912,
1252,
70,
63,
894,
14,
70,
63,
8473,
14,
362,
16232,
354,
18617,
508,
4396,
973,
5727,
267,
372,
715,
272,
754,
275,
675,
63,
4435,
365,
440,
488,
436,
971,
1779,
334,
1927,
315,
675,
63,
4435,
503,
22423,
315,
675,
63,
4435,
9,
272,
340,
440,
754,
26,
267,
485,
324,
18961,
59,
1927,
61,
275,
488,
272,
372,
754,
199,
199,
63,
324,
18961,
275,
1052,
199,
318,
5074,
8,
1927,
12,
1499,
29,
403,
304,
272,
408,
18111,
7337,
15729,
340,
314,
2013,
2073,
365,
440,
2808,
14,
339,
982,
314,
8025,
1159,
859,
365,
636,
973,
363,
2066,
5847,
372,
715,
1041,
272,
327,
1937,
340,
314,
8025,
1159,
859,
365,
636,
973,
363,
446,
340,
880,
12,
14312,
465,
340,
272,
327,
314,
2073,
1990,
663,
272,
340,
984,
423,
20912,
1252,
70,
63,
894,
14,
70,
63,
8473,
14,
362,
16232,
354,
18617,
508,
4396,
973,
5727,
267,
372,
272,
340,
440,
365,
63,
1927,
63,
3827,
8,
1927,
304,
267,
340,
1499,
365,
488,
26,
288,
1499,
275,
298,
6119,
402,
314,
18633,
83,
7,
2073,
440,
5223,
2,
450,
2073,
267,
746,
7337,
15729,
8,
1328,
9,
199,
199,
318,
2342,
63,
2491,
63,
3112,
8,
2491,
12,
3656,
304,
272,
492,
15951,
272,
340,
334,
11161,
8,
2491,
12,
4396,
3422,
18617,
436,
288,
2688,
8,
2491,
855,
3422,
3108,
2513,
1725,
8109,
267,
931,
275,
2559,
855,
354,
4343,
1814,
30381,
747,
14,
515,
14,
4127,
9,
267,
3656,
275,
747,
14,
515,
14,
904,
8,
515,
12,
3656,
9,
267,
367,
4325,
77,
315,
2559,
855,
3422,
363,
423,
1725,
14,
16007,
837,
288,
340,
15951,
14,
15359,
2546,
8,
2324,
77,
12,
3656,
304,
355,
1995,
747,
14,
515,
14,
7973,
8,
2324,
77,
2788,
16,
1055,
1814,
8,
736,
14,
515,
14,
4127,
12,
298,
2685,
272,
587,
26,
267,
931,
275,
2559,
855,
515,
12298,
16,
61,
267,
367,
4325,
77,
315,
747,
14,
7374,
8,
515,
304,
288,
340,
15951,
14,
15359,
2546,
8,
2324,
77,
12,
3656,
304,
355,
1995,
2071,
83,
4111,
83,
2,
450,
334,
2491,
855,
354,
3108,
747,
14,
515,
14,
7973,
8,
2324,
77,
2788,
16,
566,
199,
199,
318,
664,
63,
2219,
8,
2491,
12,
3656,
12,
8661,
12,
5760,
23603,
272,
408,
1767,
282,
769,
402,
9645,
511,
4621,
12,
436,
282,
769,
402,
511,
5560,
1041,
272,
2295,
275,
942,
272,
9645,
275,
942,
272,
367,
13526,
315,
2342,
63,
2491,
63,
3112,
8,
2491,
12,
3656,
304,
267,
340,
13526,
14,
1294,
15857,
1988,
17,
61,
315,
5760,
26,
288,
9645,
14,
740,
8,
14789,
9,
288,
340,
8661,
690,
413,
26,
355,
870,
4331,
984,
14,
3083,
12,
298,
30472,
450,
83,
26,
8789,
2,
450,
13526,
288,
1980,
267,
862,
26,
288,
3413,
275,
636,
646,
721,
14789,
12,
7992,
1062,
9480,
1062,
788,
10,
1105,
267,
871,
7337,
15729,
12,
10093,
26,
288,
9645,
14,
740,
8,
14789,
9,
288,
340,
8661,
690,
413,
26,
355,
870,
4331,
984,
14,
3083,
12,
298,
30472,
450,
83,
26,
450,
83,
2,
450,
334,
14789,
12,
10093,
9,
288,
1980,
267,
367,
536,
315,
2935,
8,
1494,
304,
288,
340,
536,
14,
2460,
11008,
2349,
355,
1980,
288,
312,
275,
2519,
8,
1494,
12,
536,
9,
288,
340,
730,
8,
79,
9,
365,
730,
8,
2796,
14,
1746,
9,
436,
11602,
8,
79,
12,
2882,
14,
1746,
304,
355,
2295,
14,
740,
8,
79,
9,
272,
372,
9645,
12,
2295,
199,
199,
318,
4503,
837,
272,
870,
636,
1301,
363,
272,
372,
413,
199,
199,
318,
511,
63,
1045,
63,
1121,
6851,
8,
5933,
12,
8661,
12,
16228,
304,
272,
408,
2540,
16228,
9978,
5431,
12,
15161,
3659,
8242,
1041,
272,
492,
9486,
272,
492,
5577,
272,
299,
3641,
275,
5577,
423,
3929,
63,
466,
63,
1637,
14,
1574,
342,
272,
286,
3003,
275,
5577,
423,
67,
63,
7036,
3667,
63,
1637,
14,
1574,
342,
272,
336,
3003,
275,
5577,
423,
2676,
63,
7036,
3667,
63,
1637,
14,
1574,
342,
339,
327,
1380,
18112,
367,
2984,
835,
1026,
14631,
12,
781,
1172,
370,
10250,
5305,
1263,
272,
327,
18014,
626,
5577,
965,
14,
272,
347,
9058,
837,
267,
5577,
423,
3929,
63,
466,
63,
1637,
275,
299,
3641,
14,
1574,
342,
267,
5577,
423,
67,
63,
7036,
3667,
63,
1637,
275,
286,
3003,
14,
1574,
342,
267,
5577,
423,
2676,
63,
7036,
3667,
63,
1637,
275,
336,
3003,
14,
1574,
342,
267,
9486,
14,
7112,
342,
339,
511,
275,
2882,
14,
18275,
8,
10847,
9,
272,
367,
284,
315,
1425,
8,
21,
304,
267,
4819,
275,
984,
14,
362,
2923,
16497,
342,
267,
7876,
14,
1065,
8,
396,
9,
267,
9058,
342,
272,
24903,
275,
959,
272,
2984,
6851,
275,
359,
403,
61,
627,
24903,
272,
367,
284,
315,
1425,
8,
8760,
304,
267,
4819,
275,
984,
14,
362,
2923,
16497,
342,
267,
7876,
14,
1065,
8,
396,
9,
267,
9058,
342,
267,
2984,
6851,
59,
73,
61,
275,
984,
14,
362,
2923,
16497,
342,
446,
4819,
272,
340,
2457,
8,
403,
12,
2984,
6851,
304,
267,
870,
2071,
83,
1026,
14631,
3427,
78,
60,
84,
2,
450,
16228,
12,
2984,
6851,
272,
916,
8661,
26,
267,
870,
2071,
83,
26,
4112,
2122,
450,
16228,
199,
199,
533,
1379,
7446,
8,
2796,
14,
24285,
304,
272,
347,
1255,
8,
277,
12,
511,
12,
9645,
304,
267,
298,
2540,
314,
1627,
511,
1930,
503,
511,
5241,
2122,
267,
327,
14766,
465,
2882
] |
[
747,
12,
984,
12,
2882,
12,
12733,
12,
900,
199,
199,
1180,
63,
4435,
275,
942,
199,
199,
533,
7337,
15729,
8,
1726,
304,
272,
408,
774,
9645,
2952,
652,
5839,
282,
30994,
2073,
14,
339,
961,
365,
4915,
1380,
282,
511,
4882,
5074,
342,
367,
282,
2073,
626,
272,
965,
440,
506,
5223,
14,
221,
26250,
787,
3247,
701,
511,
4621,
14,
272,
408,
199,
199,
318,
365,
63,
1927,
63,
3827,
8,
1927,
304,
272,
408,
774,
3775,
282,
2073,
365,
5223,
14,
339,
982,
314,
8025,
1159,
859,
365,
636,
973,
363,
2066,
5847,
372,
715,
1041,
272,
340,
984,
423,
20912,
1252,
70,
63,
894,
14,
70,
63,
8473,
14,
362,
16232,
354,
18617,
508,
4396,
973,
5727,
267,
372,
715,
272,
754,
275,
675,
63,
4435,
365,
440,
488,
436,
971,
1779,
334,
1927,
315,
675,
63,
4435,
503,
22423,
315,
675,
63,
4435,
9,
272,
340,
440,
754,
26,
267,
485,
324,
18961,
59,
1927,
61,
275,
488,
272,
372,
754,
199,
199,
63,
324,
18961,
275,
1052,
199,
318,
5074,
8,
1927,
12,
1499,
29,
403,
304,
272,
408,
18111,
7337,
15729,
340,
314,
2013,
2073,
365,
440,
2808,
14,
339,
982,
314,
8025,
1159,
859,
365,
636,
973,
363,
2066,
5847,
372,
715,
1041,
272,
327,
1937,
340,
314,
8025,
1159,
859,
365,
636,
973,
363,
446,
340,
880,
12,
14312,
465,
340,
272,
327,
314,
2073,
1990,
663,
272,
340,
984,
423,
20912,
1252,
70,
63,
894,
14,
70,
63,
8473,
14,
362,
16232,
354,
18617,
508,
4396,
973,
5727,
267,
372,
272,
340,
440,
365,
63,
1927,
63,
3827,
8,
1927,
304,
267,
340,
1499,
365,
488,
26,
288,
1499,
275,
298,
6119,
402,
314,
18633,
83,
7,
2073,
440,
5223,
2,
450,
2073,
267,
746,
7337,
15729,
8,
1328,
9,
199,
199,
318,
2342,
63,
2491,
63,
3112,
8,
2491,
12,
3656,
304,
272,
492,
15951,
272,
340,
334,
11161,
8,
2491,
12,
4396,
3422,
18617,
436,
288,
2688,
8,
2491,
855,
3422,
3108,
2513,
1725,
8109,
267,
931,
275,
2559,
855,
354,
4343,
1814,
30381,
747,
14,
515,
14,
4127,
9,
267,
3656,
275,
747,
14,
515,
14,
904,
8,
515,
12,
3656,
9,
267,
367,
4325,
77,
315,
2559,
855,
3422,
363,
423,
1725,
14,
16007,
837,
288,
340,
15951,
14,
15359,
2546,
8,
2324,
77,
12,
3656,
304,
355,
1995,
747,
14,
515,
14,
7973,
8,
2324,
77,
2788,
16,
1055,
1814,
8,
736,
14,
515,
14,
4127,
12,
298,
2685,
272,
587,
26,
267,
931,
275,
2559,
855,
515,
12298,
16,
61,
267,
367,
4325,
77,
315,
747,
14,
7374,
8,
515,
304,
288,
340,
15951,
14,
15359,
2546,
8,
2324,
77,
12,
3656,
304,
355,
1995,
2071,
83,
4111,
83,
2,
450,
334,
2491,
855,
354,
3108,
747,
14,
515,
14,
7973,
8,
2324,
77,
2788,
16,
566,
199,
199,
318,
664,
63,
2219,
8,
2491,
12,
3656,
12,
8661,
12,
5760,
23603,
272,
408,
1767,
282,
769,
402,
9645,
511,
4621,
12,
436,
282,
769,
402,
511,
5560,
1041,
272,
2295,
275,
942,
272,
9645,
275,
942,
272,
367,
13526,
315,
2342,
63,
2491,
63,
3112,
8,
2491,
12,
3656,
304,
267,
340,
13526,
14,
1294,
15857,
1988,
17,
61,
315,
5760,
26,
288,
9645,
14,
740,
8,
14789,
9,
288,
340,
8661,
690,
413,
26,
355,
870,
4331,
984,
14,
3083,
12,
298,
30472,
450,
83,
26,
8789,
2,
450,
13526,
288,
1980,
267,
862,
26,
288,
3413,
275,
636,
646,
721,
14789,
12,
7992,
1062,
9480,
1062,
788,
10,
1105,
267,
871,
7337,
15729,
12,
10093,
26,
288,
9645,
14,
740,
8,
14789,
9,
288,
340,
8661,
690,
413,
26,
355,
870,
4331,
984,
14,
3083,
12,
298,
30472,
450,
83,
26,
450,
83,
2,
450,
334,
14789,
12,
10093,
9,
288,
1980,
267,
367,
536,
315,
2935,
8,
1494,
304,
288,
340,
536,
14,
2460,
11008,
2349,
355,
1980,
288,
312,
275,
2519,
8,
1494,
12,
536,
9,
288,
340,
730,
8,
79,
9,
365,
730,
8,
2796,
14,
1746,
9,
436,
11602,
8,
79,
12,
2882,
14,
1746,
304,
355,
2295,
14,
740,
8,
79,
9,
272,
372,
9645,
12,
2295,
199,
199,
318,
4503,
837,
272,
870,
636,
1301,
363,
272,
372,
413,
199,
199,
318,
511,
63,
1045,
63,
1121,
6851,
8,
5933,
12,
8661,
12,
16228,
304,
272,
408,
2540,
16228,
9978,
5431,
12,
15161,
3659,
8242,
1041,
272,
492,
9486,
272,
492,
5577,
272,
299,
3641,
275,
5577,
423,
3929,
63,
466,
63,
1637,
14,
1574,
342,
272,
286,
3003,
275,
5577,
423,
67,
63,
7036,
3667,
63,
1637,
14,
1574,
342,
272,
336,
3003,
275,
5577,
423,
2676,
63,
7036,
3667,
63,
1637,
14,
1574,
342,
339,
327,
1380,
18112,
367,
2984,
835,
1026,
14631,
12,
781,
1172,
370,
10250,
5305,
1263,
272,
327,
18014,
626,
5577,
965,
14,
272,
347,
9058,
837,
267,
5577,
423,
3929,
63,
466,
63,
1637,
275,
299,
3641,
14,
1574,
342,
267,
5577,
423,
67,
63,
7036,
3667,
63,
1637,
275,
286,
3003,
14,
1574,
342,
267,
5577,
423,
2676,
63,
7036,
3667,
63,
1637,
275,
336,
3003,
14,
1574,
342,
267,
9486,
14,
7112,
342,
339,
511,
275,
2882,
14,
18275,
8,
10847,
9,
272,
367,
284,
315,
1425,
8,
21,
304,
267,
4819,
275,
984,
14,
362,
2923,
16497,
342,
267,
7876,
14,
1065,
8,
396,
9,
267,
9058,
342,
272,
24903,
275,
959,
272,
2984,
6851,
275,
359,
403,
61,
627,
24903,
272,
367,
284,
315,
1425,
8,
8760,
304,
267,
4819,
275,
984,
14,
362,
2923,
16497,
342,
267,
7876,
14,
1065,
8,
396,
9,
267,
9058,
342,
267,
2984,
6851,
59,
73,
61,
275,
984,
14,
362,
2923,
16497,
342,
446,
4819,
272,
340,
2457,
8,
403,
12,
2984,
6851,
304,
267,
870,
2071,
83,
1026,
14631,
3427,
78,
60,
84,
2,
450,
16228,
12,
2984,
6851,
272,
916,
8661,
26,
267,
870,
2071,
83,
26,
4112,
2122,
450,
16228,
199,
199,
533,
1379,
7446,
8,
2796,
14,
24285,
304,
272,
347,
1255,
8,
277,
12,
511,
12,
9645,
304,
267,
298,
2540,
314,
1627,
511,
1930,
503,
511,
5241,
2122,
267,
327,
14766,
465,
2882,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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AssertEQ, AssertScreenCharsInRectEqual, AssertTrue, GetScreenSize, knownBug
from esctypes import Point, Rect
class DECDSRTests(object):
def getVTLevel(self):
esccmd.DA2()
params = escio.ReadCSI('c', expected_prefix='>')
vtLevel = params[0]
if vtLevel < 18:
return 2
elif vtLevel <= 24:
return 3
else:
return 4
# TODO: It looks like this code didn't exist until at least VT level 3 was
# introduced, so I'm not sure it makes sense to test it in a term that
# returns a lower VT level. I plan to go back and update all the tests for
# different VT level capabilities.
def test_DECDSR_DECXCPR(self):
"""DECXCPR reports the cursor position. Response is:
CSI ? Pl ; Pc ; Pr R
Pl - line
Pc - column
Pr - page"""
# First, get the VT level.
vtLevel = self.getVTLevel()
esccmd.CUP(Point(5, 6))
esccmd.DECDSR(esccmd.DECXCPR)
params = escio.ReadCSI('R', expected_prefix='?')
if vtLevel >= 4:
# VT400+
# Last arg is page, which is always 1 (at least in xterm, and I think
# that's reasonable in all modern terminals, which won't have a direct
# notion of a page.)
AssertEQ(params, [ 6, 5, 1 ])
else:
AssertEQ(params, [ 6, 5 ])
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRPrinterPort(self):
"""Requests printer status. The allowed responses are:
CSI ? Pn n
Where Pn is:
10 - Ready
11 - Not ready
13 - No printer
18 - Busy
19 - Assigned to other session.
There's no way for the test to know what the actual printer status is,
but the response should be legal."""
esccmd.DECDSR(esccmd.DSRPrinterPort)
params = escio.ReadCSI('n', expected_prefix='?')
AssertEQ(len(params), 1)
AssertTrue(params[0] in [ 10, 11, 13, 18, 19 ])
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRUDKLocked(self):
"""Tests if user-defined keys are locked or unlocked. The allowed repsonses are:
CSI ? Pn n
Where Pn is:
20 - Unlocked
21 - Locked
This test simply ensures the value is legal. It should be extended to
ensure that when locked UDKs are not settable, and when unlocked that UDKs
are settable."""
esccmd.DECDSR(esccmd.DSRUDKLocked)
params = escio.ReadCSI('n', expected_prefix='?')
AssertEQ(len(params), 1)
AssertTrue(params[0] in [ 20, 21 ])
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRKeyboard(self):
"""Gets info about the keyboard. The response is:
CSI ? 27; Pn; Pst; Ptyp n
Where
Pn - Keyboard language
0 - Not known
1 - North American
2...19, 22, 28, 29...31, 33, 35, 36, 38...40 - Various other legal values
Pst - Keyboard status - Per the VT 510 manual, this is level 4 only.
However, it is documented in "VT330/VT340 Programmer Reference Manual
Volume 1: Text Programming".
0 - Ready
3 - No keyboard
8 - Keyboard busy in other session
Ptyp - Keyboard type - VT level 4 only
0 - LK201 # DEC 420
1 - LK401 # DEC 420
4 - LK450 # DEC 510
5 - PCXAL # DEC 510"""
# First get the VT level with a DA2
vtLevel = self.getVTLevel()
esccmd.DECDSR(esccmd.DSRKeyboard)
params = escio.ReadCSI('n', expected_prefix='?')
if vtLevel <= 2:
# VT240 or earlier
AssertEQ(len(params), 2)
elif vtLevel == 3:
# VT340 or earlier
AssertEQ(len(params), 3)
else:
# VT420+
AssertEQ(len(params), 4)
AssertEQ(params[0], 27)
if len(params) > 1:
AssertTrue(params[1] in [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 28, 29, 30,
31, 33, 35, 36, 38, 39, 40 ])
if len(params) > 2:
AssertTrue(params[2] in [ 0, 3, 8 ])
if len(params) > 3:
AssertTrue(params[3] in [ 0, 1, 4, 5 ])
def doLocatorStatusTest(self, code):
"""I couldn't find docs on these codes outside xterm. 53 and 55 seem to be
the same. Returns 50 if no locator, 53 if available."""
esccmd.DECDSR(code)
params = escio.ReadCSI('n', expected_prefix='?')
AssertEQ(len(params), 1)
AssertTrue(params[0] in [ 50, 53, 55 ])
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRDECLocatorStatus(self):
self.doLocatorStatusTest(esccmd.DSRDECLocatorStatus)
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRXtermLocatorStatus(self):
self.doLocatorStatusTest(esccmd.DSRXtermLocatorStatus)
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_LocatorType(self):
"""Get the type of the locator (pointing device.)
0 - unknown (not documented)
1 - mouse
2 - tablet"""
esccmd.DECDSR(esccmd.DSRLocatorId)
params = escio.ReadCSI('n', expected_prefix='?')
AssertEQ(params[0], 57)
AssertTrue(params[1] in [ 0, 1, 2 ])
# 1 = mouse, 2 = tablet, pretty sure 1 is the only reasonable response.
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DECMSR(self):
"""Get space available for macros. This test assumes it's always 0."""
esccmd.DECDSR(esccmd.DECMSR)
params = escio.ReadCSI('*{')
# Assume the terminal being tested doesn't support macros. May need to add
# code some day for a more capable terminal.
AssertEQ(len(params), 1)
AssertEQ(params[0], 0)
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DECCKSR(self):
"""Get checksum of macros. This test assumes it's always 0."""
esccmd.DECDSR(Ps=esccmd.DECCKSR, Pid=123)
value = escio.ReadDCS()
AssertEQ(value, "123!~0000")
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRDataIntegrity(self):
"""Check for link errors. Should always report OK."""
esccmd.DECDSR(esccmd.DSRIntegrityReport)
params = escio.ReadCSI('n', expected_prefix='?')
AssertEQ(len(params), 1)
AssertEQ(params[0], 70)
@knownBug(terminal="iTerm2", reason="Not implemented.")
def test_DECDSR_DSRMultipleSessionStatus(self):
"""Checks on the status of multiple sessons. SSU refers to some proprietary
DEC technology that multilexes multiple sessions over a single link using
the "TDSMP" protocol. Lots of detail here:
http://paperlined.org/apps/terminals/control_characters/TDSMP.html
It's safe to assume TDSMP is dead and buried.
CSI ? 80 ; Ps2 n
Multiple sessions are operating using the session support utility (SSU)
and the current SSU state is enabled. Ps2 indicates the maximum number of
sessions available. Default: Ps2 = 2
CSI ? 81 ; Ps2 n
The terminal is currently configured for multiple sessions using SSU but
the current SSU state is pending. Ps2 indicates the maximum number of
sessions available. Default: Ps2 = 2
CSI ? 83 n
The terminal is not configured for multiple-session operation.
CSI ? 87 n
Multiple sessions are operating using a separate physical line for each
session, not SSU."""
esccmd.DECDSR(esccmd.DSRMultipleSessionStatus)
params = escio.ReadCSI('n', expected_prefix='?')
AssertEQ(len(params), 1)
# 83 and 87 both seem like reasonable responses for a terminal that
# supports tabs or windows.
AssertTrue(params[0] in [ 83, 87 ])
|
gpl-2.0
|
[
504,
14683,
492,
653,
1293,
199,
646,
14683,
1760,
199,
646,
14683,
2308,
199,
646,
14683,
793,
199,
504,
14683,
1974,
492,
10716,
17420,
12,
10716,
9616,
11229,
607,
8252,
591,
12,
10716,
549,
12,
2372,
9616,
2320,
12,
6040,
17545,
199,
504,
9455,
9798,
492,
7584,
12,
21536,
199,
199,
533,
31371,
3177,
50,
2925,
8,
785,
304,
523,
347,
664,
8156,
4670,
8,
277,
304,
272,
14683,
1760,
14,
8980,
18,
342,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
67,
297,
1420,
63,
1861,
534,
5971,
272,
18585,
4670,
275,
1862,
59,
16,
61,
272,
340,
18585,
4670,
665,
6155,
26,
489,
372,
499,
272,
916,
18585,
4670,
2695,
5504,
26,
489,
372,
650,
272,
587,
26,
489,
372,
841,
819,
327,
3254,
26,
2779,
10734,
2839,
642,
1233,
9980,
1133,
2187,
5133,
737,
5210,
812,
52,
2166,
650,
1990,
523,
327,
21399,
12,
880,
473,
6704,
440,
3238,
652,
7704,
12249,
370,
511,
652,
315,
282,
6707,
626,
523,
327,
2529,
282,
5117,
812,
52,
2166,
14,
473,
8683,
370,
2621,
1771,
436,
1678,
1006,
314,
2295,
367,
523,
327,
3365,
812,
52,
2166,
14918,
14,
523,
347,
511,
63,
16387,
3177,
50,
63,
16387,
56,
2890,
50,
8,
277,
304,
272,
408,
16387,
56,
2890,
50,
13924,
314,
3920,
3421,
14,
7232,
365,
26,
272,
445,
2684,
5805,
7497,
8700,
510,
67,
8700,
25716,
820,
489,
7497,
446,
1004,
489,
510,
67,
446,
2763,
489,
25716,
446,
2034,
624,
272,
327,
7758,
12,
664,
314,
812,
52,
2166,
14,
272,
18585,
4670,
275,
291,
14,
362,
8156,
4670,
342,
339,
14683,
1760,
14,
35,
2160,
8,
3428,
8,
21,
12,
1227,
430,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
16387,
56,
2890,
50,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
50,
297,
1420,
63,
1861,
534,
18478,
339,
340,
18585,
4670,
2356,
841,
26,
489,
327,
812,
52,
5303,
11,
489,
327,
15237,
1680,
365,
2034,
12,
1314,
365,
3544,
413,
334,
292,
5210,
315,
671,
5125,
12,
436,
473,
13516,
489,
327,
626,
1159,
23255,
315,
1006,
818,
11641,
5537,
2551,
12,
1314,
7859,
1133,
1172,
282,
4125,
489,
327,
949,
296,
402,
282,
2034,
4959,
489,
10716,
17420,
8,
1162,
12,
359,
1227,
12,
959,
12,
413,
4794,
272,
587,
26,
489,
10716,
17420,
8,
1162,
12,
359,
1227,
12,
959,
4794,
819,
768,
3159,
17545,
8,
12010,
628,
73,
21676,
18,
401,
4499,
628,
1763,
6366,
2685,
523,
347,
511,
63,
16387,
3177,
50,
63,
3177,
50,
14131,
4313,
8,
277,
304,
272,
408,
16272,
16639,
2004,
14,
710,
4370,
9320,
787,
26,
267,
445,
2684,
5805,
510,
78,
302,
489,
17685,
510,
78,
365,
26,
267,
1616,
446,
5574,
89,
267,
4119,
446,
2832,
10144,
267,
4944,
446,
3091,
16639,
267,
6155,
446,
18573,
89,
267,
5851,
446,
3709,
1737,
370,
1163,
2351,
14,
489,
6006,
1159,
949,
4340,
367,
314,
511,
370,
5715,
4052,
314,
3503,
16639,
2004,
365,
12,
489,
1325,
314,
1177,
1077,
506,
18393,
1041,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
3177,
50,
14131,
4313,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
78,
297,
1420,
63,
1861,
534,
18478,
272,
10716,
17420,
8,
552,
8,
1162,
395,
413,
9,
272,
10716,
549,
8,
1162,
59,
16,
61,
315,
359,
1616,
12,
4119,
12,
4944,
12,
6155,
12,
5851,
4794,
8330,
768,
3159,
17545,
8,
12010,
628,
73,
21676,
18,
401,
4499,
628,
1763,
6366,
2685,
523,
347,
511,
63,
16387,
3177,
50,
63,
3177,
50,
3383,
43,
22408,
8,
277,
304,
272,
408,
2925,
340,
922,
13,
4037,
2883,
787,
14233,
503,
625,
9325,
14,
710,
4370,
1833,
834,
874,
787,
26,
489,
445,
2684,
5805,
510,
78,
302,
272,
17685,
510,
78,
365,
26,
489,
3388,
446,
1910,
9325,
489,
7829,
446,
15536,
379,
272,
961,
511,
9329,
15620,
314,
574,
365,
18393,
14,
2779,
1077,
506,
9243,
370,
272,
4868,
626,
1380,
14233,
738,
10892,
83,
787,
440,
663,
1224,
12,
436,
1380,
625,
9325,
626,
738,
10892,
83,
272,
787,
663,
1224,
1041,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
3177,
50,
3383,
43,
22408,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
78,
297,
1420,
63,
1861,
534,
18478,
272,
10716,
17420,
8,
552,
8,
1162,
395,
413,
9,
272,
10716,
549,
8,
1162,
59,
16,
61,
315,
359,
3388,
12,
7829,
4794,
819,
768,
3159,
17545,
8,
12010,
628,
73,
21676,
18,
401,
4499,
628,
1763,
6366,
2685,
523,
347,
511,
63,
16387,
3177,
50,
63,
3177,
50,
28377,
8,
277,
304,
272,
408,
14426,
2256,
3595,
314,
18716,
14,
710,
1177,
365,
26,
489,
445,
2684,
5805,
8087,
27,
510,
78,
27,
510,
270,
27,
510,
9749,
302,
272,
17685,
489,
510,
78,
446,
2606,
3576,
2637,
267,
378,
446,
2832,
6040,
267,
413,
446,
653,
11297,
437,
278,
28775,
267,
499,
1396,
1167,
12,
6928,
12,
7294,
12,
7349,
1396,
2192,
12,
9404,
12,
8685,
12,
8780,
12,
10448,
1396,
2167,
446,
21107,
1785,
1163,
18393,
1338,
489,
510,
270,
446,
2606,
3576,
2004,
446,
3492,
314,
812,
52,
959,
709,
8722,
12,
642,
365,
2166,
841,
1454,
14,
288,
9738,
12,
652,
365,
22751,
315,
298,
8156,
14137,
15,
8156,
13424,
18841,
2626,
10944,
30247,
288,
15018,
413,
26,
4516,
2165,
9258,
1674,
267,
378,
446,
5574,
89,
267,
650,
446,
3091,
18716,
267,
1695,
446,
2606,
3576,
10414,
89,
315,
1163,
2351,
489,
510,
9749,
446,
2606,
3576,
730,
446,
812,
52,
2166,
841,
1454,
267,
378,
446,
491,
43,
1797,
221,
327,
31371,
841,
1165,
267,
413,
446,
491,
43,
8854,
221,
327,
31371,
841,
1165,
267,
841,
446,
491,
43,
24223,
221,
327,
31371,
959,
709,
267,
959,
446,
510,
26001,
748,
221,
327,
31371,
959,
709,
624,
272,
327,
7758,
664,
314,
812,
52,
2166,
543,
282,
577,
33,
18,
272,
18585,
4670,
275,
291,
14,
362,
8156,
4670,
342,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
3177,
50,
28377,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35
] |
[
14683,
492,
653,
1293,
199,
646,
14683,
1760,
199,
646,
14683,
2308,
199,
646,
14683,
793,
199,
504,
14683,
1974,
492,
10716,
17420,
12,
10716,
9616,
11229,
607,
8252,
591,
12,
10716,
549,
12,
2372,
9616,
2320,
12,
6040,
17545,
199,
504,
9455,
9798,
492,
7584,
12,
21536,
199,
199,
533,
31371,
3177,
50,
2925,
8,
785,
304,
523,
347,
664,
8156,
4670,
8,
277,
304,
272,
14683,
1760,
14,
8980,
18,
342,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
67,
297,
1420,
63,
1861,
534,
5971,
272,
18585,
4670,
275,
1862,
59,
16,
61,
272,
340,
18585,
4670,
665,
6155,
26,
489,
372,
499,
272,
916,
18585,
4670,
2695,
5504,
26,
489,
372,
650,
272,
587,
26,
489,
372,
841,
819,
327,
3254,
26,
2779,
10734,
2839,
642,
1233,
9980,
1133,
2187,
5133,
737,
5210,
812,
52,
2166,
650,
1990,
523,
327,
21399,
12,
880,
473,
6704,
440,
3238,
652,
7704,
12249,
370,
511,
652,
315,
282,
6707,
626,
523,
327,
2529,
282,
5117,
812,
52,
2166,
14,
473,
8683,
370,
2621,
1771,
436,
1678,
1006,
314,
2295,
367,
523,
327,
3365,
812,
52,
2166,
14918,
14,
523,
347,
511,
63,
16387,
3177,
50,
63,
16387,
56,
2890,
50,
8,
277,
304,
272,
408,
16387,
56,
2890,
50,
13924,
314,
3920,
3421,
14,
7232,
365,
26,
272,
445,
2684,
5805,
7497,
8700,
510,
67,
8700,
25716,
820,
489,
7497,
446,
1004,
489,
510,
67,
446,
2763,
489,
25716,
446,
2034,
624,
272,
327,
7758,
12,
664,
314,
812,
52,
2166,
14,
272,
18585,
4670,
275,
291,
14,
362,
8156,
4670,
342,
339,
14683,
1760,
14,
35,
2160,
8,
3428,
8,
21,
12,
1227,
430,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
16387,
56,
2890,
50,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
50,
297,
1420,
63,
1861,
534,
18478,
339,
340,
18585,
4670,
2356,
841,
26,
489,
327,
812,
52,
5303,
11,
489,
327,
15237,
1680,
365,
2034,
12,
1314,
365,
3544,
413,
334,
292,
5210,
315,
671,
5125,
12,
436,
473,
13516,
489,
327,
626,
1159,
23255,
315,
1006,
818,
11641,
5537,
2551,
12,
1314,
7859,
1133,
1172,
282,
4125,
489,
327,
949,
296,
402,
282,
2034,
4959,
489,
10716,
17420,
8,
1162,
12,
359,
1227,
12,
959,
12,
413,
4794,
272,
587,
26,
489,
10716,
17420,
8,
1162,
12,
359,
1227,
12,
959,
4794,
819,
768,
3159,
17545,
8,
12010,
628,
73,
21676,
18,
401,
4499,
628,
1763,
6366,
2685,
523,
347,
511,
63,
16387,
3177,
50,
63,
3177,
50,
14131,
4313,
8,
277,
304,
272,
408,
16272,
16639,
2004,
14,
710,
4370,
9320,
787,
26,
267,
445,
2684,
5805,
510,
78,
302,
489,
17685,
510,
78,
365,
26,
267,
1616,
446,
5574,
89,
267,
4119,
446,
2832,
10144,
267,
4944,
446,
3091,
16639,
267,
6155,
446,
18573,
89,
267,
5851,
446,
3709,
1737,
370,
1163,
2351,
14,
489,
6006,
1159,
949,
4340,
367,
314,
511,
370,
5715,
4052,
314,
3503,
16639,
2004,
365,
12,
489,
1325,
314,
1177,
1077,
506,
18393,
1041,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
3177,
50,
14131,
4313,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
78,
297,
1420,
63,
1861,
534,
18478,
272,
10716,
17420,
8,
552,
8,
1162,
395,
413,
9,
272,
10716,
549,
8,
1162,
59,
16,
61,
315,
359,
1616,
12,
4119,
12,
4944,
12,
6155,
12,
5851,
4794,
8330,
768,
3159,
17545,
8,
12010,
628,
73,
21676,
18,
401,
4499,
628,
1763,
6366,
2685,
523,
347,
511,
63,
16387,
3177,
50,
63,
3177,
50,
3383,
43,
22408,
8,
277,
304,
272,
408,
2925,
340,
922,
13,
4037,
2883,
787,
14233,
503,
625,
9325,
14,
710,
4370,
1833,
834,
874,
787,
26,
489,
445,
2684,
5805,
510,
78,
302,
272,
17685,
510,
78,
365,
26,
489,
3388,
446,
1910,
9325,
489,
7829,
446,
15536,
379,
272,
961,
511,
9329,
15620,
314,
574,
365,
18393,
14,
2779,
1077,
506,
9243,
370,
272,
4868,
626,
1380,
14233,
738,
10892,
83,
787,
440,
663,
1224,
12,
436,
1380,
625,
9325,
626,
738,
10892,
83,
272,
787,
663,
1224,
1041,
272,
14683,
1760,
14,
16387,
3177,
50,
8,
19303,
1760,
14,
3177,
50,
3383,
43,
22408,
9,
272,
1862,
275,
14683,
2308,
14,
3284,
35,
2684,
360,
78,
297,
1420,
63,
1861,
534,
18478,
272,
10716,
17420,
8,
552,
8,
1162,
395,
413,
9,
272,
10716,
549,
8,
1162,
59,
16,
61,
315,
359,
3388,
12,
7829,
4794,
819,
768,
3159,
17545,
8,
12010,
628,
73,
21676,
18,
401,
4499,
628,
1763,
6366,
2685,
523,
347,
511,
63,
16387,
3177,
50,
63,
3177,
50,
28377,
8,
277,
304,
272,
408,
14426,
2256,
3595,
314,
18716,
14,
710,
1177,
365,
26,
489,
445,
2684,
5805,
8087,
27,
510,
78,
27,
510,
270,
27,
510,
9749,
302,
272,
17685,
489,
510,
78,
446,
2606,
3576,
2637,
267,
378,
446,
2832,
6040,
267,
413,
446,
653,
11297,
437,
278,
28775,
267,
499,
1396,
1167,
12,
6928,
12,
7294,
12,
7349,
1396,
2192,
12,
9404,
12,
8685,
12,
8780,
12,
10448,
1396,
2167,
446,
21107,
1785,
1163,
18393,
1338,
489,
510,
270,
446,
2606,
3576,
2004,
446,
3492,
314,
812,
52,
959,
709,
8722,
12,
642,
365,
2166,
841,
1454,
14,
288,
9738,
12,
652,
365,
22751,
315,
298,
8156,
14137,
15,
8156,
13424,
18841,
2626,
10944,
30247,
288,
15018,
413,
26,
4516,
2165,
9258,
1674,
267,
378,
446,
5574,
89,
267,
650,
446,
3091,
18716,
267,
1695,
446,
2606,
3576,
10414,
89,
315,
1163,
2351,
489,
510,
9749,
446,
2606,
3576,
730,
446,
812,
52,
2166,
841,
1454,
267,
378,
446,
491,
43,
1797,
221,
327,
31371,
841,
1165,
267,
413,
446,
491,
43,
8854,
221,
327,
31371,
841,
1165,
267,
841,
446,
491,
43,
24223,
221,
327,
31371,
959,
709,
267,
959,
446,
510,
26001,
748,
221,
327,
31371,
959,
709,
624,
272,
327,
7758,
664,
314,
812,
52,
2166,
543,
282,
577,
33,
18,
272,
18585,
4670,
275,
291,
14,
362,
8156,
4670,
342,
272,
14683,
1760,
14,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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
] |
thodoris/djangoPharma
|
djangoPharma/env/Lib/site-packages/django/core/handlers/base.py
|
96
|
10769
|
from __future__ import unicode_literals
import logging
import sys
import types
import warnings
from django.conf import settings
from django.core import signals
from django.core.exceptions import ImproperlyConfigured, MiddlewareNotUsed
from django.db import connections, transaction
from django.urls import get_resolver, get_urlconf, set_urlconf
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.module_loading import import_string
from .exception import (
convert_exception_to_response, get_exception_response,
handle_uncaught_exception,
)
logger = logging.getLogger('django.request')
class BaseHandler(object):
def __init__(self):
self._request_middleware = None
self._view_middleware = None
self._template_response_middleware = None
self._response_middleware = None
self._exception_middleware = None
self._middleware_chain = None
def load_middleware(self):
"""
Populate middleware lists from settings.MIDDLEWARE (or the deprecated
MIDDLEWARE_CLASSES).
Must be called after the environment is fixed (see __call__ in subclasses).
"""
self._request_middleware = []
self._view_middleware = []
self._template_response_middleware = []
self._response_middleware = []
self._exception_middleware = []
if settings.MIDDLEWARE is None:
warnings.warn(
"Old-style middleware using settings.MIDDLEWARE_CLASSES is "
"deprecated. Update your middleware and use settings.MIDDLEWARE "
"instead.", RemovedInDjango20Warning
)
handler = convert_exception_to_response(self._legacy_get_response)
for middleware_path in settings.MIDDLEWARE_CLASSES:
mw_class = import_string(middleware_path)
try:
mw_instance = mw_class()
except MiddlewareNotUsed as exc:
if settings.DEBUG:
if six.text_type(exc):
logger.debug('MiddlewareNotUsed(%r): %s', middleware_path, exc)
else:
logger.debug('MiddlewareNotUsed: %r', middleware_path)
continue
if hasattr(mw_instance, 'process_request'):
self._request_middleware.append(mw_instance.process_request)
if hasattr(mw_instance, 'process_view'):
self._view_middleware.append(mw_instance.process_view)
if hasattr(mw_instance, 'process_template_response'):
self._template_response_middleware.insert(0, mw_instance.process_template_response)
if hasattr(mw_instance, 'process_response'):
self._response_middleware.insert(0, mw_instance.process_response)
if hasattr(mw_instance, 'process_exception'):
self._exception_middleware.insert(0, mw_instance.process_exception)
else:
handler = convert_exception_to_response(self._get_response)
for middleware_path in reversed(settings.MIDDLEWARE):
middleware = import_string(middleware_path)
try:
mw_instance = middleware(handler)
except MiddlewareNotUsed as exc:
if settings.DEBUG:
if six.text_type(exc):
logger.debug('MiddlewareNotUsed(%r): %s', middleware_path, exc)
else:
logger.debug('MiddlewareNotUsed: %r', middleware_path)
continue
if mw_instance is None:
raise ImproperlyConfigured(
'Middleware factory %s returned None.' % middleware_path
)
if hasattr(mw_instance, 'process_view'):
self._view_middleware.insert(0, mw_instance.process_view)
if hasattr(mw_instance, 'process_template_response'):
self._template_response_middleware.append(mw_instance.process_template_response)
if hasattr(mw_instance, 'process_exception'):
self._exception_middleware.append(mw_instance.process_exception)
handler = convert_exception_to_response(mw_instance)
# We only assign to this when initialization is complete as it is used
# as a flag for initialization being complete.
self._middleware_chain = handler
def make_view_atomic(self, view):
non_atomic_requests = getattr(view, '_non_atomic_requests', set())
for db in connections.all():
if db.settings_dict['ATOMIC_REQUESTS'] and db.alias not in non_atomic_requests:
view = transaction.atomic(using=db.alias)(view)
return view
def get_exception_response(self, request, resolver, status_code, exception):
return get_exception_response(request, resolver, status_code, exception, self.__class__)
def get_response(self, request):
"""Return an HttpResponse object for the given HttpRequest."""
# Setup default url resolver for this thread
set_urlconf(settings.ROOT_URLCONF)
response = self._middleware_chain(request)
# This block is only needed for legacy MIDDLEWARE_CLASSES; if
# MIDDLEWARE is used, self._response_middleware will be empty.
try:
# Apply response middleware, regardless of the response
for middleware_method in self._response_middleware:
response = middleware_method(request, response)
# Complain if the response middleware returned None (a common error).
if response is None:
raise ValueError(
"%s.process_response didn't return an "
"HttpResponse object. It returned None instead."
% (middleware_method.__self__.__class__.__name__))
except Exception: # Any exception should be gathered and handled
signals.got_request_exception.send(sender=self.__class__, request=request)
response = self.handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
response._closable_objects.append(request)
# If the exception handler returns a TemplateResponse that has not
# been rendered, force it to be rendered.
if not getattr(response, 'is_rendered', True) and callable(getattr(response, 'render', None)):
response = response.render()
if response.status_code == 404:
logger.warning(
'Not Found: %s', request.path,
extra={'status_code': 404, 'request': request},
)
return response
def _get_response(self, request):
"""
Resolve and call the view, then apply view, exception, and
template_response middleware. This method is everything that happens
inside the request/response middleware.
"""
response = None
if hasattr(request, 'urlconf'):
urlconf = request.urlconf
set_urlconf(urlconf)
resolver = get_resolver(urlconf)
else:
resolver = get_resolver()
resolver_match = resolver.resolve(request.path_info)
callback, callback_args, callback_kwargs = resolver_match
request.resolver_match = resolver_match
# Apply view middleware
for middleware_method in self._view_middleware:
response = middleware_method(request, callback, callback_args, callback_kwargs)
if response:
break
if response is None:
wrapped_callback = self.make_view_atomic(callback)
try:
response = wrapped_callback(request, *callback_args, **callback_kwargs)
except Exception as e:
response = self.process_exception_by_middleware(e, request)
# Complain if the view returned None (a common error).
if response is None:
if isinstance(callback, types.FunctionType): # FBV
view_name = callback.__name__
else: # CBV
view_name = callback.__class__.__name__ + '.__call__'
raise ValueError(
"The view %s.%s didn't return an HttpResponse object. It "
"returned None instead." % (callback.__module__, view_name)
)
# If the response supports deferred rendering, apply template
# response middleware and then render the response
elif hasattr(response, 'render') and callable(response.render):
for middleware_method in self._template_response_middleware:
response = middleware_method(request, response)
# Complain if the template response middleware returned None (a common error).
if response is None:
raise ValueError(
"%s.process_template_response didn't return an "
"HttpResponse object. It returned None instead."
% (middleware_method.__self__.__class__.__name__)
)
try:
response = response.render()
except Exception as e:
response = self.process_exception_by_middleware(e, request)
return response
def process_exception_by_middleware(self, exception, request):
"""
Pass the exception to the exception middleware. If no middleware
return a response for this exception, raise it.
"""
for middleware_method in self._exception_middleware:
response = middleware_method(request, exception)
if response:
return response
raise
def handle_uncaught_exception(self, request, resolver, exc_info):
"""Allow subclasses to override uncaught exception handling."""
return handle_uncaught_exception(request, resolver, exc_info)
def _legacy_get_response(self, request):
"""
Apply process_request() middleware and call the main _get_response(),
if needed. Used only for legacy MIDDLEWARE_CLASSES.
"""
response = None
# Apply request middleware
for middleware_method in self._request_middleware:
response = middleware_method(request)
if response:
break
if response is None:
response = self._get_response(request)
return response
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
646,
984,
199,
646,
2943,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
492,
10166,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
603,
3551,
1763,
9167,
199,
504,
1639,
14,
697,
492,
6947,
12,
6008,
199,
504,
1639,
14,
3603,
492,
664,
63,
7717,
12,
664,
63,
21801,
12,
663,
63,
21801,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
875,
199,
199,
504,
1275,
1971,
492,
334,
272,
3957,
63,
1971,
63,
475,
63,
1310,
12,
664,
63,
1971,
63,
1310,
12,
272,
2429,
63,
324,
24872,
63,
1971,
12,
199,
9,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1069,
358,
421,
199,
533,
3523,
2461,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1069,
63,
5754,
275,
488,
267,
291,
423,
1345,
63,
5754,
275,
488,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
488,
267,
291,
423,
1310,
63,
5754,
275,
488,
267,
291,
423,
1971,
63,
5754,
275,
488,
267,
291,
423,
5754,
63,
4429,
275,
488,
339,
347,
2248,
63,
5754,
8,
277,
304,
267,
408,
267,
31731,
10816,
5548,
687,
2202,
14,
19987,
334,
269,
314,
5906,
267,
30718,
63,
13748,
680,
398,
9498,
506,
2797,
2410,
314,
3734,
365,
6317,
334,
3239,
636,
1250,
363,
315,
9180,
680,
267,
408,
267,
291,
423,
1069,
63,
5754,
275,
942,
267,
291,
423,
1345,
63,
5754,
275,
942,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
942,
267,
291,
423,
1310,
63,
5754,
275,
942,
267,
291,
423,
1971,
63,
5754,
275,
942,
398,
340,
2202,
14,
19987,
365,
488,
26,
288,
3598,
14,
4050,
8,
355,
298,
16411,
13,
2487,
10816,
1808,
2202,
14,
19987,
63,
13748,
365,
298,
355,
298,
6667,
14,
6162,
2195,
10816,
436,
675,
2202,
14,
19987,
298,
355,
298,
23145,
4765,
23687,
1165,
3849,
288,
776,
288,
3016,
275,
3957,
63,
1971,
63,
475,
63,
1310,
8,
277,
423,
10000,
63,
362,
63,
1310,
9,
288,
367,
10816,
63,
515,
315,
2202,
14,
19987,
63,
13748,
26,
355,
23530,
63,
533,
275,
492,
63,
875,
8,
5754,
63,
515,
9,
355,
862,
26,
490,
23530,
63,
842,
275,
23530,
63,
533,
342,
355,
871,
603,
3551,
1763,
9167,
465,
3178,
26,
490,
340,
2202,
14,
5287,
26,
717,
340,
3816,
14,
505,
63,
466,
8,
2804,
304,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
4042,
82,
304,
450,
83,
297,
10816,
63,
515,
12,
3178,
9,
717,
587,
26,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
26,
450,
82,
297,
10816,
63,
515,
9,
490,
1980,
2234,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1069,
735,
490,
291,
423,
1069,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1069,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1345,
735,
490,
291,
423,
1345,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1345,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1160,
63,
1310,
735,
490,
291,
423,
1160,
63,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1160,
63,
1310,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1310,
735,
490,
291,
423,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1310,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1971,
735,
490,
291,
423,
1971,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1971,
9,
267,
587,
26,
288,
3016,
275,
3957,
63,
1971,
63,
475,
63,
1310,
8,
277,
423,
362,
63,
1310,
9,
288,
367,
10816,
63,
515,
315,
10822,
8,
1751,
14,
19987,
304,
355,
10816,
275,
492,
63,
875,
8,
5754,
63,
515,
9,
355,
862,
26,
490,
23530,
63,
842,
275,
10816,
8,
2232,
9,
355,
871,
603,
3551,
1763,
9167,
465,
3178,
26,
490,
340,
2202,
14,
5287,
26,
717,
340,
3816,
14,
505,
63,
466,
8,
2804,
304,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
4042,
82,
304,
450,
83,
297,
10816,
63,
515,
12,
3178,
9,
717,
587,
26,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
26,
450,
82,
297,
10816,
63,
515,
9,
490,
1980,
2234,
340,
23530,
63,
842,
365,
488,
26,
490,
746,
11897,
8,
717,
283,
6608,
6434,
450,
83,
2138,
488,
3530,
450,
10816,
63,
515,
490,
776,
2234,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1345,
735,
490,
291,
423,
1345,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1345,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1160,
63,
1310,
735,
490,
291,
423,
1160,
63,
1310,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1160,
63,
1310,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1971,
735,
490,
291,
423,
1971,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1971,
9,
2234,
3016,
275,
3957,
63,
1971,
63,
475,
63,
1310,
8,
14716,
63,
842,
9,
398,
327,
2136,
1454,
5090,
370,
642,
1380,
11097,
365,
4890,
465,
652,
365,
1202,
267,
327,
465,
282,
3305,
367,
11097,
3769,
4890,
14,
267,
291,
423,
5754,
63,
4429,
275,
3016,
339,
347,
1852,
63,
1345,
63,
10910,
8,
277,
12,
2455,
304,
267,
2222,
63,
10910,
63,
6615,
275,
2519,
8,
1345,
12,
2513,
2865,
63,
10910,
63,
6615,
297,
663,
1012,
267,
367,
1592,
315,
6947,
14,
452,
837,
288,
340,
1592,
14,
1751,
63,
807,
459,
22479,
948,
63,
6780,
51,
418,
436,
1592,
14,
3620,
440,
315,
2222,
63,
10910,
63,
6615,
26,
355,
2455,
275,
6008,
14,
10910,
8,
4941,
29,
697,
14,
3620,
5130,
1345,
9,
267,
372,
2455,
339,
347,
664,
63,
1971,
63,
1310,
8,
277
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2050,
199,
646,
984,
199,
646,
2943,
199,
646,
3598,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
492,
10166,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
12,
603,
3551,
1763,
9167,
199,
504,
1639,
14,
697,
492,
6947,
12,
6008,
199,
504,
1639,
14,
3603,
492,
664,
63,
7717,
12,
664,
63,
21801,
12,
663,
63,
21801,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
875,
199,
199,
504,
1275,
1971,
492,
334,
272,
3957,
63,
1971,
63,
475,
63,
1310,
12,
664,
63,
1971,
63,
1310,
12,
272,
2429,
63,
324,
24872,
63,
1971,
12,
199,
9,
199,
199,
2921,
275,
2050,
14,
5572,
360,
1176,
14,
1069,
358,
421,
199,
533,
3523,
2461,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1069,
63,
5754,
275,
488,
267,
291,
423,
1345,
63,
5754,
275,
488,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
488,
267,
291,
423,
1310,
63,
5754,
275,
488,
267,
291,
423,
1971,
63,
5754,
275,
488,
267,
291,
423,
5754,
63,
4429,
275,
488,
339,
347,
2248,
63,
5754,
8,
277,
304,
267,
408,
267,
31731,
10816,
5548,
687,
2202,
14,
19987,
334,
269,
314,
5906,
267,
30718,
63,
13748,
680,
398,
9498,
506,
2797,
2410,
314,
3734,
365,
6317,
334,
3239,
636,
1250,
363,
315,
9180,
680,
267,
408,
267,
291,
423,
1069,
63,
5754,
275,
942,
267,
291,
423,
1345,
63,
5754,
275,
942,
267,
291,
423,
1160,
63,
1310,
63,
5754,
275,
942,
267,
291,
423,
1310,
63,
5754,
275,
942,
267,
291,
423,
1971,
63,
5754,
275,
942,
398,
340,
2202,
14,
19987,
365,
488,
26,
288,
3598,
14,
4050,
8,
355,
298,
16411,
13,
2487,
10816,
1808,
2202,
14,
19987,
63,
13748,
365,
298,
355,
298,
6667,
14,
6162,
2195,
10816,
436,
675,
2202,
14,
19987,
298,
355,
298,
23145,
4765,
23687,
1165,
3849,
288,
776,
288,
3016,
275,
3957,
63,
1971,
63,
475,
63,
1310,
8,
277,
423,
10000,
63,
362,
63,
1310,
9,
288,
367,
10816,
63,
515,
315,
2202,
14,
19987,
63,
13748,
26,
355,
23530,
63,
533,
275,
492,
63,
875,
8,
5754,
63,
515,
9,
355,
862,
26,
490,
23530,
63,
842,
275,
23530,
63,
533,
342,
355,
871,
603,
3551,
1763,
9167,
465,
3178,
26,
490,
340,
2202,
14,
5287,
26,
717,
340,
3816,
14,
505,
63,
466,
8,
2804,
304,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
4042,
82,
304,
450,
83,
297,
10816,
63,
515,
12,
3178,
9,
717,
587,
26,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
26,
450,
82,
297,
10816,
63,
515,
9,
490,
1980,
2234,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1069,
735,
490,
291,
423,
1069,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1069,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1345,
735,
490,
291,
423,
1345,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1345,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1160,
63,
1310,
735,
490,
291,
423,
1160,
63,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1160,
63,
1310,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1310,
735,
490,
291,
423,
1310,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1310,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1971,
735,
490,
291,
423,
1971,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1971,
9,
267,
587,
26,
288,
3016,
275,
3957,
63,
1971,
63,
475,
63,
1310,
8,
277,
423,
362,
63,
1310,
9,
288,
367,
10816,
63,
515,
315,
10822,
8,
1751,
14,
19987,
304,
355,
10816,
275,
492,
63,
875,
8,
5754,
63,
515,
9,
355,
862,
26,
490,
23530,
63,
842,
275,
10816,
8,
2232,
9,
355,
871,
603,
3551,
1763,
9167,
465,
3178,
26,
490,
340,
2202,
14,
5287,
26,
717,
340,
3816,
14,
505,
63,
466,
8,
2804,
304,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
4042,
82,
304,
450,
83,
297,
10816,
63,
515,
12,
3178,
9,
717,
587,
26,
1169,
2512,
14,
1757,
360,
6608,
1763,
9167,
26,
450,
82,
297,
10816,
63,
515,
9,
490,
1980,
2234,
340,
23530,
63,
842,
365,
488,
26,
490,
746,
11897,
8,
717,
283,
6608,
6434,
450,
83,
2138,
488,
3530,
450,
10816,
63,
515,
490,
776,
2234,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1345,
735,
490,
291,
423,
1345,
63,
5754,
14,
3176,
8,
16,
12,
23530,
63,
842,
14,
1412,
63,
1345,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1160,
63,
1310,
735,
490,
291,
423,
1160,
63,
1310,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1160,
63,
1310,
9,
355,
340,
2688,
8,
14716,
63,
842,
12,
283,
1412,
63,
1971,
735,
490,
291,
423,
1971,
63,
5754,
14,
740,
8,
14716,
63,
842,
14,
1412,
63,
1971,
9,
2234,
3016,
275,
3957,
63,
1971,
63,
475,
63,
1310,
8,
14716,
63,
842,
9,
398,
327,
2136,
1454,
5090,
370,
642,
1380,
11097,
365,
4890,
465,
652,
365,
1202,
267,
327,
465,
282,
3305,
367,
11097,
3769,
4890,
14,
267,
291,
423,
5754,
63,
4429,
275,
3016,
339,
347,
1852,
63,
1345,
63,
10910,
8,
277,
12,
2455,
304,
267,
2222,
63,
10910,
63,
6615,
275,
2519,
8,
1345,
12,
2513,
2865,
63,
10910,
63,
6615,
297,
663,
1012,
267,
367,
1592,
315,
6947,
14,
452,
837,
288,
340,
1592,
14,
1751,
63,
807,
459,
22479,
948,
63,
6780,
51,
418,
436,
1592,
14,
3620,
440,
315,
2222,
63,
10910,
63,
6615,
26,
355,
2455,
275,
6008,
14,
10910,
8,
4941,
29,
697,
14,
3620,
5130,
1345,
9,
267,
372,
2455,
339,
347,
664,
63,
1971,
63,
1310,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
resmo/ansible
|
test/units/modules/network/fortios/test_fortios_vpn_ipsec_manualkey_interface.py
|
21
|
12459
|
# Copyright 2019 Fortinet, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <https://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
import pytest
from mock import ANY
from ansible.module_utils.network.fortios.fortios import FortiOSHandler
try:
from ansible.modules.network.fortios import fortios_vpn_ipsec_manualkey_interface
except ImportError:
pytest.skip("Could not load required modules for testing", allow_module_level=True)
@pytest.fixture(autouse=True)
def connection_mock(mocker):
connection_class_mock = mocker.patch('ansible.modules.network.fortios.fortios_vpn_ipsec_manualkey_interface.Connection')
return connection_class_mock
fos_instance = FortiOSHandler(connection_mock)
def test_vpn_ipsec_manualkey_interface_creation(mocker):
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
input_data = {
'username': 'admin',
'state': 'present',
'vpn_ipsec_manualkey_interface': {
'addr_type': '4',
'auth_alg': 'null',
'auth_key': 'test_value_5',
'enc_alg': 'null',
'enc_key': 'test_value_7',
'interface': 'test_value_8',
'ip_version': '4',
'local_gw': 'test_value_10',
'local_gw6': 'test_value_11',
'local_spi': 'test_value_12',
'name': 'default_name_13',
'remote_gw': 'test_value_14',
'remote_gw6': 'test_value_15',
'remote_spi': 'test_value_16'
},
'vdom': 'root'}
is_error, changed, response = fortios_vpn_ipsec_manualkey_interface.fortios_vpn_ipsec(input_data, fos_instance)
expected_data = {
'addr-type': '4',
'auth-alg': 'null',
'auth-key': 'test_value_5',
'enc-alg': 'null',
'enc-key': 'test_value_7',
'interface': 'test_value_8',
'ip-version': '4',
'local-gw': 'test_value_10',
'local-gw6': 'test_value_11',
'local-spi': 'test_value_12',
'name': 'default_name_13',
'remote-gw': 'test_value_14',
'remote-gw6': 'test_value_15',
'remote-spi': 'test_value_16'
}
set_method_mock.assert_called_with('vpn.ipsec', 'manualkey-interface', data=expected_data, vdom='root')
schema_method_mock.assert_not_called()
assert not is_error
assert changed
assert response['status'] == 'success'
assert response['http_status'] == 200
def test_vpn_ipsec_manualkey_interface_creation_fails(mocker):
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
set_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
input_data = {
'username': 'admin',
'state': 'present',
'vpn_ipsec_manualkey_interface': {
'addr_type': '4',
'auth_alg': 'null',
'auth_key': 'test_value_5',
'enc_alg': 'null',
'enc_key': 'test_value_7',
'interface': 'test_value_8',
'ip_version': '4',
'local_gw': 'test_value_10',
'local_gw6': 'test_value_11',
'local_spi': 'test_value_12',
'name': 'default_name_13',
'remote_gw': 'test_value_14',
'remote_gw6': 'test_value_15',
'remote_spi': 'test_value_16'
},
'vdom': 'root'}
is_error, changed, response = fortios_vpn_ipsec_manualkey_interface.fortios_vpn_ipsec(input_data, fos_instance)
expected_data = {
'addr-type': '4',
'auth-alg': 'null',
'auth-key': 'test_value_5',
'enc-alg': 'null',
'enc-key': 'test_value_7',
'interface': 'test_value_8',
'ip-version': '4',
'local-gw': 'test_value_10',
'local-gw6': 'test_value_11',
'local-spi': 'test_value_12',
'name': 'default_name_13',
'remote-gw': 'test_value_14',
'remote-gw6': 'test_value_15',
'remote-spi': 'test_value_16'
}
set_method_mock.assert_called_with('vpn.ipsec', 'manualkey-interface', data=expected_data, vdom='root')
schema_method_mock.assert_not_called()
assert is_error
assert not changed
assert response['status'] == 'error'
assert response['http_status'] == 500
def test_vpn_ipsec_manualkey_interface_removal(mocker):
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
delete_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
input_data = {
'username': 'admin',
'state': 'absent',
'vpn_ipsec_manualkey_interface': {
'addr_type': '4',
'auth_alg': 'null',
'auth_key': 'test_value_5',
'enc_alg': 'null',
'enc_key': 'test_value_7',
'interface': 'test_value_8',
'ip_version': '4',
'local_gw': 'test_value_10',
'local_gw6': 'test_value_11',
'local_spi': 'test_value_12',
'name': 'default_name_13',
'remote_gw': 'test_value_14',
'remote_gw6': 'test_value_15',
'remote_spi': 'test_value_16'
},
'vdom': 'root'}
is_error, changed, response = fortios_vpn_ipsec_manualkey_interface.fortios_vpn_ipsec(input_data, fos_instance)
delete_method_mock.assert_called_with('vpn.ipsec', 'manualkey-interface', mkey=ANY, vdom='root')
schema_method_mock.assert_not_called()
assert not is_error
assert changed
assert response['status'] == 'success'
assert response['http_status'] == 200
def test_vpn_ipsec_manualkey_interface_deletion_fails(mocker):
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
delete_method_result = {'status': 'error', 'http_method': 'POST', 'http_status': 500}
delete_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.delete', return_value=delete_method_result)
input_data = {
'username': 'admin',
'state': 'absent',
'vpn_ipsec_manualkey_interface': {
'addr_type': '4',
'auth_alg': 'null',
'auth_key': 'test_value_5',
'enc_alg': 'null',
'enc_key': 'test_value_7',
'interface': 'test_value_8',
'ip_version': '4',
'local_gw': 'test_value_10',
'local_gw6': 'test_value_11',
'local_spi': 'test_value_12',
'name': 'default_name_13',
'remote_gw': 'test_value_14',
'remote_gw6': 'test_value_15',
'remote_spi': 'test_value_16'
},
'vdom': 'root'}
is_error, changed, response = fortios_vpn_ipsec_manualkey_interface.fortios_vpn_ipsec(input_data, fos_instance)
delete_method_mock.assert_called_with('vpn.ipsec', 'manualkey-interface', mkey=ANY, vdom='root')
schema_method_mock.assert_not_called()
assert is_error
assert not changed
assert response['status'] == 'error'
assert response['http_status'] == 500
def test_vpn_ipsec_manualkey_interface_idempotent(mocker):
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
set_method_result = {'status': 'error', 'http_method': 'DELETE', 'http_status': 404}
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
input_data = {
'username': 'admin',
'state': 'present',
'vpn_ipsec_manualkey_interface': {
'addr_type': '4',
'auth_alg': 'null',
'auth_key': 'test_value_5',
'enc_alg': 'null',
'enc_key': 'test_value_7',
'interface': 'test_value_8',
'ip_version': '4',
'local_gw': 'test_value_10',
'local_gw6': 'test_value_11',
'local_spi': 'test_value_12',
'name': 'default_name_13',
'remote_gw': 'test_value_14',
'remote_gw6': 'test_value_15',
'remote_spi': 'test_value_16'
},
'vdom': 'root'}
is_error, changed, response = fortios_vpn_ipsec_manualkey_interface.fortios_vpn_ipsec(input_data, fos_instance)
expected_data = {
'addr-type': '4',
'auth-alg': 'null',
'auth-key': 'test_value_5',
'enc-alg': 'null',
'enc-key': 'test_value_7',
'interface': 'test_value_8',
'ip-version': '4',
'local-gw': 'test_value_10',
'local-gw6': 'test_value_11',
'local-spi': 'test_value_12',
'name': 'default_name_13',
'remote-gw': 'test_value_14',
'remote-gw6': 'test_value_15',
'remote-spi': 'test_value_16'
}
set_method_mock.assert_called_with('vpn.ipsec', 'manualkey-interface', data=expected_data, vdom='root')
schema_method_mock.assert_not_called()
assert not is_error
assert not changed
assert response['status'] == 'error'
assert response['http_status'] == 404
def test_vpn_ipsec_manualkey_interface_filter_foreign_attributes(mocker):
schema_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')
set_method_result = {'status': 'success', 'http_method': 'POST', 'http_status': 200}
set_method_mock = mocker.patch('ansible.module_utils.network.fortios.fortios.FortiOSHandler.set', return_value=set_method_result)
input_data = {
'username': 'admin',
'state': 'present',
'vpn_ipsec_manualkey_interface': {
'random_attribute_not_valid': 'tag',
'addr_type': '4',
'auth_alg': 'null',
'auth_key': 'test_value_5',
'enc_alg': 'null',
'enc_key': 'test_value_7',
'interface': 'test_value_8',
'ip_version': '4',
'local_gw': 'test_value_10',
'local_gw6': 'test_value_11',
'local_spi': 'test_value_12',
'name': 'default_name_13',
'remote_gw': 'test_value_14',
'remote_gw6': 'test_value_15',
'remote_spi': 'test_value_16'
},
'vdom': 'root'}
is_error, changed, response = fortios_vpn_ipsec_manualkey_interface.fortios_vpn_ipsec(input_data, fos_instance)
expected_data = {
'addr-type': '4',
'auth-alg': 'null',
'auth-key': 'test_value_5',
'enc-alg': 'null',
'enc-key': 'test_value_7',
'interface': 'test_value_8',
'ip-version': '4',
'local-gw': 'test_value_10',
'local-gw6': 'test_value_11',
'local-spi': 'test_value_12',
'name': 'default_name_13',
'remote-gw': 'test_value_14',
'remote-gw6': 'test_value_15',
'remote-spi': 'test_value_16'
}
set_method_mock.assert_called_with('vpn.ipsec', 'manualkey-interface', data=expected_data, vdom='root')
schema_method_mock.assert_not_called()
assert not is_error
assert changed
assert response['status'] == 'success'
assert response['http_status'] == 200
|
gpl-3.0
|
[
3,
1898,
20312,
30205,
10811,
12,
3277,
14,
199,
3,
199,
3,
961,
2240,
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,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
2859,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
4613,
199,
504,
1683,
492,
1821,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
492,
22913,
2461,
199,
199,
893,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
14551,
492,
19516,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
199,
2590,
3545,
26,
272,
4613,
14,
2759,
480,
6531,
440,
2248,
1415,
4621,
367,
5343,
401,
2040,
63,
578,
63,
1896,
29,
549,
9,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
1950,
63,
1805,
8,
27899,
304,
272,
1950,
63,
533,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
3112,
14,
1200,
14,
14551,
14,
14551,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
14,
3225,
358,
272,
372,
1950,
63,
533,
63,
1805,
421,
199,
545,
83,
63,
842,
275,
22913,
2461,
8,
2105,
63,
1805,
9,
421,
199,
318,
511,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
63,
8782,
8,
27899,
304,
272,
4177,
63,
765,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
14,
29089,
14,
3629,
358,
339,
663,
63,
765,
63,
1099,
275,
791,
1205,
356,
283,
3742,
297,
283,
1014,
63,
765,
356,
283,
4030,
297,
283,
1014,
63,
1205,
356,
1926,
93,
272,
663,
63,
765,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
14,
29089,
14,
409,
297,
372,
63,
585,
29,
409,
63,
765,
63,
1099,
9,
339,
1324,
63,
576,
275,
469,
267,
283,
2473,
356,
283,
2113,
297,
267,
283,
929,
356,
283,
1881,
297,
267,
283,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
356,
469,
288,
283,
2697,
63,
466,
356,
283,
20,
297,
288,
283,
1178,
63,
6731,
356,
283,
2307,
297,
288,
283,
1178,
63,
498,
356,
283,
396,
63,
585,
63,
21,
297,
288,
283,
10945,
63,
6731,
356,
283,
2307,
297,
288,
283,
10945,
63,
498,
356,
283,
396,
63,
585,
63,
23,
297,
288,
283,
3266,
356,
283,
396,
63,
585,
63,
24,
297,
288,
283,
711,
63,
1023,
356,
283,
20,
297,
288,
283,
1832,
63,
8392,
356,
283,
396,
63,
585,
63,
709,
297,
288,
283,
1832,
63,
8392,
22,
356,
283,
396,
63,
585,
63,
845,
297,
288,
283,
1832,
63,
8721,
356,
283,
396,
63,
585,
63,
713,
297,
288,
283,
354,
356,
283,
885,
63,
354,
63,
969,
297,
288,
283,
3846,
63,
8392,
356,
283,
396,
63,
585,
63,
1079,
297,
288,
283,
3846,
63,
8392,
22,
356,
283,
396,
63,
585,
63,
1046,
297,
288,
283,
3846,
63,
8721,
356,
283,
396,
63,
585,
63,
975,
7,
267,
1660,
267,
283,
23779,
356,
283,
1231,
936,
339,
365,
63,
705,
12,
2896,
12,
1177,
275,
19516,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
14,
14551,
63,
9702,
63,
19867,
8,
1210,
63,
576,
12,
15509,
63,
842,
9,
339,
1420,
63,
576,
275,
469,
267,
283,
2697,
13,
466,
356,
283,
20,
297,
267,
283,
1178,
13,
6731,
356,
283,
2307,
297,
267,
283,
1178,
13,
498,
356,
283,
396,
63,
585,
63,
21,
297,
267,
283,
10945,
13,
6731,
356,
283,
2307,
297,
267,
283,
10945,
13,
498,
356,
283,
396,
63,
585,
63,
23,
297,
267,
283,
3266,
356,
283,
396,
63,
585,
63,
24,
297,
267,
283,
711,
13,
1023,
356,
283,
20,
297,
267,
283,
1832,
13,
8392,
356,
283,
396,
63,
585,
63,
709,
297,
267,
283,
1832,
13,
8392,
22,
356,
283,
396,
63,
585,
63,
845,
297,
267,
283,
1832,
13,
8721,
356,
283,
396,
63,
585,
63,
713,
297,
267,
283,
354,
356,
283,
885,
63,
354,
63,
969,
297,
355,
283,
3846,
13,
8392,
356,
283,
396,
63,
585,
63,
1079,
297,
355,
283,
3846,
13,
8392,
22,
356,
283,
396,
63,
585,
63,
1046,
297,
355,
283,
3846,
13,
8721,
356,
283,
396,
63,
585,
63,
975,
7,
272,
789,
339,
663,
63,
765,
63,
1805,
14,
479,
63,
3527,
63,
1045,
360,
9702,
14,
19867,
297,
283,
9285,
498,
13,
3266,
297,
666,
29,
2062,
63,
576,
12,
20822,
534,
1231,
358,
272,
4177,
63,
765,
63,
1805,
14,
479,
63,
1397,
63,
3527,
342,
272,
702,
440,
365,
63,
705,
272,
702,
2896,
272,
702,
1177,
459,
1205,
418,
508,
283,
3742,
7,
272,
702,
1177,
459,
1014,
63,
1205,
418,
508,
1926,
421,
199,
318,
511,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
63,
8782,
63,
15762,
8,
27899,
304,
272,
4177,
63,
765,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
14,
29089,
14,
3629,
358,
339,
663,
63,
765,
63,
1099,
275,
791,
1205,
356,
283,
705,
297,
283,
1014,
63,
765,
356,
283,
4030,
297,
283,
1014,
63,
1205,
356,
6891,
93,
272,
663,
63,
765,
63,
1805,
275,
15981,
14
] |
[
1898,
20312,
30205,
10811,
12,
3277,
14,
199,
3,
199,
3,
961,
2240,
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,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
2859,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
2022,
199,
646,
4613,
199,
504,
1683,
492,
1821,
199,
504,
3242,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
492,
22913,
2461,
199,
199,
893,
26,
272,
687,
3242,
14,
3112,
14,
1200,
14,
14551,
492,
19516,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
199,
2590,
3545,
26,
272,
4613,
14,
2759,
480,
6531,
440,
2248,
1415,
4621,
367,
5343,
401,
2040,
63,
578,
63,
1896,
29,
549,
9,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
1950,
63,
1805,
8,
27899,
304,
272,
1950,
63,
533,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
3112,
14,
1200,
14,
14551,
14,
14551,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
14,
3225,
358,
272,
372,
1950,
63,
533,
63,
1805,
421,
199,
545,
83,
63,
842,
275,
22913,
2461,
8,
2105,
63,
1805,
9,
421,
199,
318,
511,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
63,
8782,
8,
27899,
304,
272,
4177,
63,
765,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
14,
29089,
14,
3629,
358,
339,
663,
63,
765,
63,
1099,
275,
791,
1205,
356,
283,
3742,
297,
283,
1014,
63,
765,
356,
283,
4030,
297,
283,
1014,
63,
1205,
356,
1926,
93,
272,
663,
63,
765,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,
1200,
14,
14551,
14,
14551,
14,
29089,
14,
409,
297,
372,
63,
585,
29,
409,
63,
765,
63,
1099,
9,
339,
1324,
63,
576,
275,
469,
267,
283,
2473,
356,
283,
2113,
297,
267,
283,
929,
356,
283,
1881,
297,
267,
283,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
356,
469,
288,
283,
2697,
63,
466,
356,
283,
20,
297,
288,
283,
1178,
63,
6731,
356,
283,
2307,
297,
288,
283,
1178,
63,
498,
356,
283,
396,
63,
585,
63,
21,
297,
288,
283,
10945,
63,
6731,
356,
283,
2307,
297,
288,
283,
10945,
63,
498,
356,
283,
396,
63,
585,
63,
23,
297,
288,
283,
3266,
356,
283,
396,
63,
585,
63,
24,
297,
288,
283,
711,
63,
1023,
356,
283,
20,
297,
288,
283,
1832,
63,
8392,
356,
283,
396,
63,
585,
63,
709,
297,
288,
283,
1832,
63,
8392,
22,
356,
283,
396,
63,
585,
63,
845,
297,
288,
283,
1832,
63,
8721,
356,
283,
396,
63,
585,
63,
713,
297,
288,
283,
354,
356,
283,
885,
63,
354,
63,
969,
297,
288,
283,
3846,
63,
8392,
356,
283,
396,
63,
585,
63,
1079,
297,
288,
283,
3846,
63,
8392,
22,
356,
283,
396,
63,
585,
63,
1046,
297,
288,
283,
3846,
63,
8721,
356,
283,
396,
63,
585,
63,
975,
7,
267,
1660,
267,
283,
23779,
356,
283,
1231,
936,
339,
365,
63,
705,
12,
2896,
12,
1177,
275,
19516,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
14,
14551,
63,
9702,
63,
19867,
8,
1210,
63,
576,
12,
15509,
63,
842,
9,
339,
1420,
63,
576,
275,
469,
267,
283,
2697,
13,
466,
356,
283,
20,
297,
267,
283,
1178,
13,
6731,
356,
283,
2307,
297,
267,
283,
1178,
13,
498,
356,
283,
396,
63,
585,
63,
21,
297,
267,
283,
10945,
13,
6731,
356,
283,
2307,
297,
267,
283,
10945,
13,
498,
356,
283,
396,
63,
585,
63,
23,
297,
267,
283,
3266,
356,
283,
396,
63,
585,
63,
24,
297,
267,
283,
711,
13,
1023,
356,
283,
20,
297,
267,
283,
1832,
13,
8392,
356,
283,
396,
63,
585,
63,
709,
297,
267,
283,
1832,
13,
8392,
22,
356,
283,
396,
63,
585,
63,
845,
297,
267,
283,
1832,
13,
8721,
356,
283,
396,
63,
585,
63,
713,
297,
267,
283,
354,
356,
283,
885,
63,
354,
63,
969,
297,
355,
283,
3846,
13,
8392,
356,
283,
396,
63,
585,
63,
1079,
297,
355,
283,
3846,
13,
8392,
22,
356,
283,
396,
63,
585,
63,
1046,
297,
355,
283,
3846,
13,
8721,
356,
283,
396,
63,
585,
63,
975,
7,
272,
789,
339,
663,
63,
765,
63,
1805,
14,
479,
63,
3527,
63,
1045,
360,
9702,
14,
19867,
297,
283,
9285,
498,
13,
3266,
297,
666,
29,
2062,
63,
576,
12,
20822,
534,
1231,
358,
272,
4177,
63,
765,
63,
1805,
14,
479,
63,
1397,
63,
3527,
342,
272,
702,
440,
365,
63,
705,
272,
702,
2896,
272,
702,
1177,
459,
1205,
418,
508,
283,
3742,
7,
272,
702,
1177,
459,
1014,
63,
1205,
418,
508,
1926,
421,
199,
318,
511,
63,
9702,
63,
19867,
63,
9285,
498,
63,
3266,
63,
8782,
63,
15762,
8,
27899,
304,
272,
4177,
63,
765,
63,
1805,
275,
15981,
14,
2068,
360,
4853,
14,
578,
63,
1208,
14,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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
] |
Tomcuzz/OctaHomeAutomation
|
OctaHomeSettings/views.py
|
1
|
14790
|
from django.conf import settings
import json
from OctaHomeCore.baseviews import *
from OctaHomeCore.models import *
from OctaHomeCore.OctaFiles.menus.base import *
from OctaHomeCore.weathermodels import *
from OctaHomeCore.helpers import *
from OctaHomeCore.authmodels import *
from OctaHomeAppInterface.models import *
class handleSettingsView(viewRequestHandler):
def getViewParameters(self):
parameters = {}
if self.Page == 'ActionGroups':
parameters = {'actionGroups':ActionGroup.objects.all()}
elif self.Page == 'AGConditions':
parameters = {'aGConditions':AGCondition.objects.all()}
elif self.Page == 'Actions':
parameters = {'actions':Action.objects.all()}
elif self.Page == 'Events':
parameters = {'events':TriggerEvent.objects.all()}
elif self.Page == 'EditUsers':
parameters = {'users':CustomUser.objects.all()}
elif self.Page == 'AddUser':
parameters = {'locations': WeatherLocations.objects.order_by('name').all()}
elif self.Page == 'AddEvent':
parameters = {'actiongroups': ActionGroup.objects.all()}
elif self.Page == 'AddActionGroup':
parameters = {'triggerEvents': TriggerEvent.objects.all(), 'aGConditions':AGCondition.objects.all(), 'actions':Action.objects.all()}
elif self.Page == 'AddAGCondition':
parameters = {'actiongroups':ActionGroup.objects.all()}
elif self.Page == 'AddAction':
parameters = {'types':getAllSubClasses(Action)}
elif self.Page == 'DeviceUsers':
parameters = {'devices':DeviceUser.objects.filter(User=self.Request.user)}
elif self.Page == 'AddDeviceUsersComplete':
if self.Post.has_key('name'):
device = DeviceUser.objects.create(Name=self.Post['name'], User=self.Request.user)
if self.Request.is_secure():
host = 'https://' + self.Request.get_host() + "/"
else:
host = 'http://' + self.Request.get_host() + "/"
items = device.createDeviceSetupToken(host)
parameters = {'title':'Add', 'credentials':items, 'deviceToken':json.dumps(items)}
elif self.Page == 'ResetDeviceUsers':
if self.Post.has_key('deviceId') and self.Post['deviceId'] != '':
device = DeviceUser.objects.get(pk=self.Post['deviceId'])
if device.User == self.Request.user or self.Request.user.is_superuser:
if self.Request.is_secure():
host = 'https://' + self.Request.get_host() + "/"
else:
host = 'http://' + self.Request.get_host() + "/"
items = device.createDeviceSetupToken(host)
parameters = {'title':'Reset', 'credentials':items, 'deviceToken':json.dumps(items)}
else:
parameters = {'title':'Reset'}
#else:
#return 'pages/Settings/EditUser'
return parameters
def getTemplate(self):
if self.Page == 'None':
return 'OctaHomeSettings/EditUser'
elif self.Page == 'Events':
return 'OctaHomeSettings/TriggerEvents'
elif self.Page == 'ActionGroups':
return 'OctaHomeSettings/ActionGroups'
elif self.Page == 'AGConditions':
return 'OctaHomeSettings/AGConditions'
elif self.Page == 'Actions':
return 'OctaHomeSettings/Actions'
elif self.Page == 'EditUsers':
return 'OctaHomeSettings/EditUsers'
elif self.Page == 'AddUser':
return 'OctaHomeSettings/AddUser'
elif self.Page == 'AddEvent':
return 'OctaHomeSettings/AddTriggerEvent'
elif self.Page == 'AddActionGroup':
return 'OctaHomeSettings/AddActionGroup'
elif self.Page == 'AddAGCondition':
return 'OctaHomeSettings/AddAGCondition'
elif self.Page == 'AddAction':
return 'OctaHomeSettings/AddAction'
elif self.Page == 'DeviceUsers':
return 'OctaHomeSettings/DeviceUsers'
elif self.Page == 'AddDeviceUsers':
return 'OctaHomeSettings/AddDeviceUsers'
elif self.Page == 'AddDeviceUsersComplete':
return 'OctaHomeSettings/SetupDeviceUsersComplete'
elif self.Page == 'ResetDeviceUsers':
return 'OctaHomeSettings/SetupDeviceUsersComplete'
else:
return 'OctaHomeSettings/EditUser'
def getSideBar(self):
links = [
{'title': 'Account', 'address': reverse('Settings'), 'active': self.getSideBarActiveState('None', self.Page)},
{'title': 'Events', 'address': reverse('SettingsPage', kwargs={'page':'Events'}), 'active': self.getSideBarActiveState('Events', self.Page)},
{'title': 'Action Groups', 'address': reverse('SettingsPage', kwargs={'page':'ActionGroups'}), 'active': self.getSideBarActiveState('ActionGroups', self.Page)},
{'title': 'Action Group Conditions', 'address': reverse('SettingsPage', kwargs={'page':'AGConditions'}), 'active': self.getSideBarActiveState('AGConditions', self.Page)},
{'title': 'Actions', 'address': reverse('SettingsPage', kwargs={'page':'Actions'}), 'active': self.getSideBarActiveState('Actions', self.Page)},
{'title': 'Device Logins', 'address': reverse('SettingsPage', kwargs={'page':'DeviceUsers'}), 'active': self.getSideBarActiveState('DeviceUsers', self.Page)}
]
if self.Request.user.is_superuser:
links.extend([
{'title': 'Edit Users', 'address': reverse('SettingsPage', kwargs={'page':'EditUsers'}), 'active': self.getSideBarActiveState('EditUsers', self.Page)},
{'title': 'Add User', 'address': reverse('SettingsPage', kwargs={'page':'AddUser'}), 'active': self.getSideBarActiveState('AddUser', self.Page)}
])
links.extend([
{'title': 'Log Out', 'address': reverse('LogOut'), 'active': self.getSideBarActiveState('LogOut', self.Page)}
])
return links
class handleSettingsCommand(commandRequestHandler):
def runCommand(self):
if self.Command == 'addUserComplete':
if not request.user.is_superuser:
return self.handleUserError('Privilege Authentication Failure')
if all (k in self.Post for k in ("username", "password", "email", "firstName", "surname", "activeState", "userLevel")):
if self.Post.has_key("userLoaction"):
location = self.Post['userLoaction']
else:
location = "310002"
user = CustomUser.objects.create_user(self.Post['email'], self.Post['firstName'], self.Post['surname'], self.Post['password'])
user.username = self.Post['username']
user.first_name = self.Post['firstName']
user.last_name = self.Post['surname']
user.home_location = location
if self.Post.has_key('activeState') and self.Post['activeState'] == "Active":
user.is_active = True
else:
user.is_active = False
if self.Post.has_key('userLevel') and self.Post['userLevel'] == "Admin":
user.is_superuser = True
else:
user.is_superuser = False
user.save()
return self.returnOk()
else:
return self.handleUserError('Not All Variable Given')
elif self.Command == 'addTwoFactorAuthentication':
if self.Request.user.authy_id == "":
if all (k in self.Post for k in ("email", "phone", "areacode")):
authy_api = AuthyApiClient(settings.AUTHY_API_KEY)
user = authy_api.users.create(self.Post['email'], self.Post['phone'], self.Post['areacode']) #email, cellphone, area_code
if user.ok():
self.Request.user.authy_id = user.id
self.Request.user.save()
return self.redirect(reverse('Settings')) #On page '/account/?page=TwoFactorAuthentication'
else:
return self.handleUserError(user.errors()) #On page 'pages/Account/AuthyAdmin.html'
else:
return self.handleUserError('Please Supply All Details') #On page 'pages/Account/AuthyAdmin.html'
else:
return self.handleUserError('User Already Has Authy Authentication') #On page 'pages/Account/AuthyAdmin.html'
elif self.Command == 'removeTwoFactorAuthentication':
authy_api = AuthyApiClient(settings.AUTHY_API_KEY)
if request.user.authy_id != "":
result = authy_api.users.post("/protected/json/users/delete/" + str(request.user.authy_id), {})
request.user.authy_id = ""
request.user.save()
return self.redirect(reverse('Settings')) #On page '/account/?page=TwoFactorAuthentication'
else:
return self.handleUserError('Authy Not Enabled')
elif self.Command == 'deleteUser':
if request.user.is_superuser:
if self.Post.has_key('user'):
u = CustomUser.objects.get(username__exact=self.Post['user'])
u.delete()
return self.returnOk()
else:
return self.handleUserError('An Error Has Occured, Please Try Again Later')
else:
return self.handleUserError('Authentication Error')
elif self.Command == 'changeUsername':
if self.Post.has_key('value'):
return self.handleUserError('No Email Entered')
if self.Post.has_key('user'):
if request.user.is_superuser:
u = CustomUser.objects.get(username__exact=self.Post['user'])
u.username = self.Post['value']
u.save()
return self.returnOk()
else:
return self.handleUserError('Authentication Error')
else:
u = request.user
u.username = newUsername
u.save()
return self.returnOk()
elif self.Command == 'changePassword':
if not self.Post.has_key('value'):
return self.handleUserError('No Password Entered')
if self.Post.has_key('user'):
if request.user.is_superuser:
u = CustomUser.objects.get(username__exact=self.Post['user'])
u.set_password(self.Post['value'])
u.save()
return self.returnOk()
else:
return self.handleUserError('An Error Has Occured, Please Try Again Later')
else:
u = request.user
u.set_password(self.Post['value'])
u.save()
return self.returnOk()
elif self.Command == 'changeFirstName':
if not self.Post.has_key('value'):
return self.handleUserError('No Name Entered')
if self.Post.has_key('user'):
if request.user.is_superuser:
u = CustomUser.objects.get(username__exact=self.Post['user'])
u.first_name = self.Post['value']
u.save()
return self.returnOk()
else:
return self.handleUserError('Authentication Error')
else:
u = request.user
u.first_name = self.Post['value']
u.save()
return self.returnOk()
elif self.Command == 'changeSecondName':
if not self.Post.has_key('value'):
return self.handleUserError('No Name Entered')
if self.Post.has_key('user'):
if request.user.is_superuser:
u = CustomUser.objects.get(username__exact=self.Post['user'])
u.last_name = self.Post['value']
u.save()
return self.returnOk()
else:
return self.handleUserError('Authentication Error')
else:
u = request.user
u.last_name = self.Post['value']
u.save()
return self.returnOk()
elif self.Command == 'changeEmail':
if not self.Post.has_key('value'):
return self.handleUserError('No Email Entered')
if self.Post.has_key('user'):
if request.user.is_superuser:
u = CustomUser.objects.get(username__exact=self.Post['user'])
u.email = self.Post['value']
u.save()
return self.returnOk()
else:
return self.handleUserError('Authentication Error')
else:
u = request.user
u.email = self.Post['value']
u.save()
return self.returnOk()
elif self.Command == 'changeAdminLevel':
if request.user.is_superuser:
if self.Post.has_key('value') and self.Post.has_key('user'):
u = CustomUser.objects.get(username__exact=self.Post['user'])
if self.Post['value'] == "2":
u.is_superuser = True
else:
u.is_superuser = False
u.save()
return self.returnOk()
else:
return self.handleUserError('Values Needed Not Given')
else:
return self.handleUserError('Authentication Error')
elif self.Command == 'changeActiveState':
if request.user.is_superuser:
if self.Post.has_key('value') and self.Post.has_key('user'):
u = CustomUser.objects.get(username__exact=self.Post['user'])
if self.Post['value'] == "1":
u.is_active = True
else:
u.is_active = False
u.save()
return self.returnOk()
else:
return self.handleUserError('Values Needed Not Given')
else:
return self.handleUserError('Authentication Error')
elif self.Command == 'addTriggerEventComplete':
if self.Post.has_key('name') and self.Post.has_key('actionGroups'):
name = self.Post['name']
actionGroups = self.Post['actionGroups']
NewTriggerEvent = TriggerEvent.objects.create(Name=name)
for actionGroupId in actionGroups.split(','):
actionGroup = ActionGroup.objects.get(pk=actionGroupId)
if actionGroup != None:
NewTriggerEvent.ActionGroups.add(actionGroup)
NewTriggerEvent.save()
return self.redirect(reverse('SettingsPage', kwargs={'page':'Events'}))
else:
return self.handleUserError('Not All Values Given')
elif self.Command == 'addActionGroupComplete':
if self.Post.has_key('name') and self.Post.has_key('triggerEvents') and self.Post.has_key('aGConditions') and self.Post.has_key('actions'):
name = self.Post['name']
triggerEventsIds = self.Post['triggerEvents']
aGConditionsIds = self.Post['aGConditions']
actionsIds = self.Post['actions']
NewActionGroup = ActionGroup.objects.create(Name=name)
for triggerEventId in triggerEventsIds.split(','):
triggerEvent = TriggerEvent.objects.get(pk=triggerEventId)
if triggerEvent != None:
NewActionGroup.TriggerEvents.add(triggerEvent)
for actionGroupId in aGConditionsIds.split(','):
actionGroup = AGCondition.objects.get(pk=actionGroupId)
if actionGroup != None:
NewActionGroup.AGCondition.add(actionGroup)
for actionGroupId in actionsIds.split(','):
actionGroup = Action.objects.get(pk=actionGroupId)
if actionGroup != None:
NewActionGroup.Actions.add(actionGroup)
NewActionGroup.save()
return self.redirect(reverse('SettingsPage', kwargs={'page':'ActionGroups'}))
else:
return self.handleUserError('Not All Values Given')
elif self.Command == 'addActionGroupConditionComplete':
if self.Post.has_key('name'):
name = self.Post['name']
AGCondition.objects.create(Name=name)
return self.redirect(reverse('SettingsPage', kwargs={'page':'AGConditions'}))
else:
return self.handleUserError('Not All Values Given')
elif self.Command == 'addActionComplete':
if self.Post.has_key('name'):
name = self.Post['name']
Action.objects.create(Name=name)
return self.redirect(reverse('SettingsPage', kwargs={'page':'Actions'}))
else:
return self.handleUserError('Not All Values Given')
elif self.Command == 'DeleteDeviceUsers':
if self.Post.has_key('deviceId') and self.Post['deviceId'] != '':
device = DeviceUser.objects.get(pk=self.Post['deviceId'])
if device.User == self.Request.user or self.Request.user.is_superuser:
device.delete()
return self.redirect(reverse('SettingsPage', kwargs={'page':'DeviceUsers'}))
else:
return self.handleUserError('Permissions Denied')
else:
return self.handleUserError('Command Not Found')
|
mit
|
[
504,
1639,
14,
2190,
492,
2202,
199,
646,
2022,
199,
199,
504,
18365,
65,
12054,
5402,
14,
1095,
4196,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
992,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
17584,
65,
5535,
14,
30969,
14,
1095,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
23026,
992,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
7546,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
1178,
992,
492,
627,
199,
504,
18365,
65,
12054,
2640,
4267,
14,
992,
492,
627,
199,
199,
533,
2429,
5268,
2768,
8,
1345,
11149,
304,
199,
198,
318,
664,
2768,
5976,
8,
277,
304,
507,
198,
3214,
275,
1052,
9068,
198,
692,
291,
14,
3276,
508,
283,
3310,
10177,
356,
686,
198,
3214,
275,
791,
1287,
10177,
356,
3310,
2448,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1254,
23107,
356,
686,
198,
3214,
275,
791,
65,
39,
23107,
356,
1254,
9558,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
9303,
356,
686,
198,
3214,
275,
791,
3723,
356,
3310,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
11770,
356,
686,
198,
3214,
275,
791,
4368,
356,
16276,
2390,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
4685,
12117,
356,
686,
198,
3214,
275,
791,
3707,
356,
31482,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1899,
356,
686,
198,
3214,
275,
791,
8022,
356,
2136,
7404,
27727,
14,
1462,
14,
1648,
63,
991,
360,
354,
1959,
452,
12737,
9068,
198,
4164,
291,
14,
3276,
508,
283,
1123,
2390,
356,
686,
198,
3214,
275,
791,
1287,
2634,
356,
10033,
2448,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
2448,
356,
686,
198,
3214,
275,
791,
7631,
11770,
356,
24015,
2390,
14,
1462,
14,
452,
1062,
283,
65,
39,
23107,
356,
1254,
9558,
14,
1462,
14,
452,
1062,
283,
3723,
356,
3310,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1254,
9558,
356,
686,
198,
3214,
275,
791,
1287,
2634,
356,
3310,
2448,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
356,
686,
198,
3214,
275,
791,
1313,
356,
31359,
2610,
15711,
8,
3310,
6769,
9068,
198,
4164,
291,
14,
3276,
508,
283,
2510,
12117,
356,
686,
198,
3214,
275,
791,
6410,
356,
2510,
1899,
14,
1462,
14,
1541,
8,
1899,
29,
277,
14,
2017,
14,
751,
6769,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
2510,
12117,
14175,
356,
686,
198,
692,
291,
14,
6564,
14,
1989,
63,
498,
360,
354,
735,
1585,
198,
1782,
275,
12272,
1899,
14,
1462,
14,
981,
8,
985,
29,
277,
14,
6564,
459,
354,
995,
2876,
29,
277,
14,
2017,
14,
751,
9,
1585,
198,
692,
291,
14,
2017,
14,
374,
63,
7817,
837,
1871,
198,
1102,
275,
283,
2859,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1585,
198,
2836,
26,
1871,
198,
1102,
275,
283,
1014,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1585,
198,
1744,
275,
2243,
14,
981,
2510,
8555,
3264,
8,
1102,
9,
1585,
198,
3214,
275,
791,
1213,
5242,
1123,
297,
283,
6942,
356,
1744,
12,
283,
1782,
3264,
356,
1001,
14,
4180,
8,
1744,
6769,
507,
198,
4164,
291,
14,
3276,
508,
283,
9637,
2510,
12117,
356,
686,
198,
692,
291,
14,
6564,
14,
1989,
63,
498,
360,
1782,
1304,
358,
436,
291,
14,
6564,
459,
1782,
1304,
418,
1137,
8061,
1585,
198,
1782,
275,
12272,
1899,
14,
1462,
14,
362,
8,
2051,
29,
277,
14,
6564,
459,
1782,
1304,
1105,
1585,
198,
692,
2243,
14,
1899,
508,
291,
14,
2017,
14,
751,
503,
291,
14,
2017,
14,
751,
14,
374,
63,
11434,
26,
1871,
198,
692,
291,
14,
2017,
14,
374,
63,
7817,
837,
4671,
198,
1102,
275,
283,
2859,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1871,
198,
2836,
26,
4671,
198,
1102,
275,
283,
1014,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1871,
198,
1744,
275,
2243,
14,
981,
2510,
8555,
3264,
8,
1102,
9,
1871,
198,
3214,
275,
791,
1213,
5242,
9637,
297,
283,
6942,
356,
1744,
12,
283,
1782,
3264,
356,
1001,
14,
4180,
8,
1744,
6769,
1585,
198,
2836,
26,
1871,
198,
3214,
275,
791,
1213,
5242,
9637,
936,
9068,
198,
3,
2836,
26,
686,
198,
3,
1107,
283,
5856,
15,
5268,
15,
4685,
1899,
7,
9068,
198,
1107,
2633,
18118,
198,
318,
664,
4231,
8,
277,
304,
507,
198,
692,
291,
14,
3276,
508,
283,
403,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
4685,
1899,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
11770,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
16276,
11770,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
3310,
10177,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
3310,
10177,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1254,
23107,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1254,
23107,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
9303,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
9303,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
4685,
12117,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
4685,
12117,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1899,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
1899,
7,
9068,
198,
4164,
291,
14,
3276,
508,
283,
1123,
2390,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
16276,
2390,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
2448,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
3310,
2448,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1254,
9558,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
1254,
9558,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
356,
686,
198,
1107,
283
] |
[
1639,
14,
2190,
492,
2202,
199,
646,
2022,
199,
199,
504,
18365,
65,
12054,
5402,
14,
1095,
4196,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
992,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
17584,
65,
5535,
14,
30969,
14,
1095,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
23026,
992,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
7546,
492,
627,
199,
504,
18365,
65,
12054,
5402,
14,
1178,
992,
492,
627,
199,
504,
18365,
65,
12054,
2640,
4267,
14,
992,
492,
627,
199,
199,
533,
2429,
5268,
2768,
8,
1345,
11149,
304,
199,
198,
318,
664,
2768,
5976,
8,
277,
304,
507,
198,
3214,
275,
1052,
9068,
198,
692,
291,
14,
3276,
508,
283,
3310,
10177,
356,
686,
198,
3214,
275,
791,
1287,
10177,
356,
3310,
2448,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1254,
23107,
356,
686,
198,
3214,
275,
791,
65,
39,
23107,
356,
1254,
9558,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
9303,
356,
686,
198,
3214,
275,
791,
3723,
356,
3310,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
11770,
356,
686,
198,
3214,
275,
791,
4368,
356,
16276,
2390,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
4685,
12117,
356,
686,
198,
3214,
275,
791,
3707,
356,
31482,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1899,
356,
686,
198,
3214,
275,
791,
8022,
356,
2136,
7404,
27727,
14,
1462,
14,
1648,
63,
991,
360,
354,
1959,
452,
12737,
9068,
198,
4164,
291,
14,
3276,
508,
283,
1123,
2390,
356,
686,
198,
3214,
275,
791,
1287,
2634,
356,
10033,
2448,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
2448,
356,
686,
198,
3214,
275,
791,
7631,
11770,
356,
24015,
2390,
14,
1462,
14,
452,
1062,
283,
65,
39,
23107,
356,
1254,
9558,
14,
1462,
14,
452,
1062,
283,
3723,
356,
3310,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1254,
9558,
356,
686,
198,
3214,
275,
791,
1287,
2634,
356,
3310,
2448,
14,
1462,
14,
452,
12737,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
356,
686,
198,
3214,
275,
791,
1313,
356,
31359,
2610,
15711,
8,
3310,
6769,
9068,
198,
4164,
291,
14,
3276,
508,
283,
2510,
12117,
356,
686,
198,
3214,
275,
791,
6410,
356,
2510,
1899,
14,
1462,
14,
1541,
8,
1899,
29,
277,
14,
2017,
14,
751,
6769,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
2510,
12117,
14175,
356,
686,
198,
692,
291,
14,
6564,
14,
1989,
63,
498,
360,
354,
735,
1585,
198,
1782,
275,
12272,
1899,
14,
1462,
14,
981,
8,
985,
29,
277,
14,
6564,
459,
354,
995,
2876,
29,
277,
14,
2017,
14,
751,
9,
1585,
198,
692,
291,
14,
2017,
14,
374,
63,
7817,
837,
1871,
198,
1102,
275,
283,
2859,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1585,
198,
2836,
26,
1871,
198,
1102,
275,
283,
1014,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1585,
198,
1744,
275,
2243,
14,
981,
2510,
8555,
3264,
8,
1102,
9,
1585,
198,
3214,
275,
791,
1213,
5242,
1123,
297,
283,
6942,
356,
1744,
12,
283,
1782,
3264,
356,
1001,
14,
4180,
8,
1744,
6769,
507,
198,
4164,
291,
14,
3276,
508,
283,
9637,
2510,
12117,
356,
686,
198,
692,
291,
14,
6564,
14,
1989,
63,
498,
360,
1782,
1304,
358,
436,
291,
14,
6564,
459,
1782,
1304,
418,
1137,
8061,
1585,
198,
1782,
275,
12272,
1899,
14,
1462,
14,
362,
8,
2051,
29,
277,
14,
6564,
459,
1782,
1304,
1105,
1585,
198,
692,
2243,
14,
1899,
508,
291,
14,
2017,
14,
751,
503,
291,
14,
2017,
14,
751,
14,
374,
63,
11434,
26,
1871,
198,
692,
291,
14,
2017,
14,
374,
63,
7817,
837,
4671,
198,
1102,
275,
283,
2859,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1871,
198,
2836,
26,
4671,
198,
1102,
275,
283,
1014,
22399,
435,
291,
14,
2017,
14,
362,
63,
1102,
342,
435,
10609,
1871,
198,
1744,
275,
2243,
14,
981,
2510,
8555,
3264,
8,
1102,
9,
1871,
198,
3214,
275,
791,
1213,
5242,
9637,
297,
283,
6942,
356,
1744,
12,
283,
1782,
3264,
356,
1001,
14,
4180,
8,
1744,
6769,
1585,
198,
2836,
26,
1871,
198,
3214,
275,
791,
1213,
5242,
9637,
936,
9068,
198,
3,
2836,
26,
686,
198,
3,
1107,
283,
5856,
15,
5268,
15,
4685,
1899,
7,
9068,
198,
1107,
2633,
18118,
198,
318,
664,
4231,
8,
277,
304,
507,
198,
692,
291,
14,
3276,
508,
283,
403,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
4685,
1899,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
11770,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
16276,
11770,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
3310,
10177,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
3310,
10177,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1254,
23107,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1254,
23107,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
9303,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
9303,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
4685,
12117,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
4685,
12117,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1899,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
1899,
7,
9068,
198,
4164,
291,
14,
3276,
508,
283,
1123,
2390,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
16276,
2390,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
2448,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
3310,
2448,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
1254,
9558,
356,
686,
198,
1107,
283,
17584,
65,
12054,
5268,
15,
1123,
1254,
9558,
7,
507,
198,
4164,
291,
14,
3276,
508,
283,
1123,
3310,
356,
686,
198,
1107,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
treycausey/scikit-learn
|
examples/linear_model/plot_ransac.py
|
250
|
1673
|
"""
===========================================
Robust linear model estimation using RANSAC
===========================================
In this example we see how to robustly fit a linear model to faulty data using
the RANSAC algorithm.
"""
import numpy as np
from matplotlib import pyplot as plt
from sklearn import linear_model, datasets
n_samples = 1000
n_outliers = 50
X, y, coef = datasets.make_regression(n_samples=n_samples, n_features=1,
n_informative=1, noise=10,
coef=True, random_state=0)
# Add outlier data
np.random.seed(0)
X[:n_outliers] = 3 + 0.5 * np.random.normal(size=(n_outliers, 1))
y[:n_outliers] = -3 + 10 * np.random.normal(size=n_outliers)
# Fit line using all data
model = linear_model.LinearRegression()
model.fit(X, y)
# Robustly fit linear model with RANSAC algorithm
model_ransac = linear_model.RANSACRegressor(linear_model.LinearRegression())
model_ransac.fit(X, y)
inlier_mask = model_ransac.inlier_mask_
outlier_mask = np.logical_not(inlier_mask)
# Predict data of estimated models
line_X = np.arange(-5, 5)
line_y = model.predict(line_X[:, np.newaxis])
line_y_ransac = model_ransac.predict(line_X[:, np.newaxis])
# Compare estimated coefficients
print("Estimated coefficients (true, normal, RANSAC):")
print(coef, model.coef_, model_ransac.estimator_.coef_)
plt.plot(X[inlier_mask], y[inlier_mask], '.g', label='Inliers')
plt.plot(X[outlier_mask], y[outlier_mask], '.r', label='Outliers')
plt.plot(line_X, line_y, '-k', label='Linear regressor')
plt.plot(line_X, line_y_ransac, '-b', label='RANSAC regressor')
plt.legend(loc='lower right')
plt.show()
|
bsd-3-clause
|
[
624,
199,
2486,
21326,
199,
3863,
15549,
7798,
1402,
27156,
1808,
820,
5622,
1348,
199,
2486,
21326,
199,
199,
607,
642,
2893,
781,
1937,
4212,
370,
23399,
590,
5542,
282,
7798,
1402,
370,
1433,
17323,
666,
1808,
199,
1589,
820,
5622,
1348,
5563,
14,
199,
199,
624,
199,
646,
2680,
465,
980,
199,
504,
8027,
492,
1134,
2798,
465,
4488,
199,
199,
504,
6357,
492,
7798,
63,
1238,
12,
13148,
421,
199,
78,
63,
3356,
275,
5198,
199,
78,
63,
28622,
275,
5238,
421,
199,
56,
12,
612,
12,
7355,
275,
13148,
14,
1875,
63,
12513,
8,
78,
63,
3356,
29,
78,
63,
3356,
12,
302,
63,
3179,
29,
17,
12,
4228,
302,
63,
27666,
29,
17,
12,
11145,
29,
709,
12,
4228,
7355,
29,
549,
12,
2196,
63,
929,
29,
16,
9,
199,
199,
3,
2654,
734,
5697,
666,
199,
1590,
14,
2355,
14,
5176,
8,
16,
9,
199,
56,
1491,
78,
63,
28622,
61,
275,
650,
435,
378,
14,
21,
627,
980,
14,
2355,
14,
3302,
8,
890,
2687,
78,
63,
28622,
12,
413,
430,
199,
89,
1491,
78,
63,
28622,
61,
275,
446,
19,
435,
1616,
627,
980,
14,
2355,
14,
3302,
8,
890,
29,
78,
63,
28622,
9,
199,
199,
3,
25971,
1004,
1808,
1006,
666,
199,
1238,
275,
7798,
63,
1238,
14,
10608,
13013,
342,
199,
1238,
14,
3269,
8,
56,
12,
612,
9,
199,
199,
3,
6848,
15549,
590,
5542,
7798,
1402,
543,
820,
5622,
1348,
5563,
199,
1238,
63,
1320,
645,
275,
7798,
63,
1238,
14,
50,
5622,
1348,
15155,
8,
6676,
63,
1238,
14,
10608,
13013,
1012,
199,
1238,
63,
1320,
645,
14,
3269,
8,
56,
12,
612,
9,
199,
262,
5697,
63,
2629,
275,
1402,
63,
1320,
645,
14,
262,
5697,
63,
2629,
63,
199,
548,
5697,
63,
2629,
275,
980,
14,
7954,
63,
1397,
8,
262,
5697,
63,
2629,
9,
199,
199,
3,
5543,
807,
666,
402,
20077,
1709,
199,
604,
63,
56,
275,
980,
14,
5605,
2801,
21,
12,
959,
9,
199,
604,
63,
89,
275,
1402,
14,
6892,
8,
604,
63,
56,
3981,
980,
14,
14483,
566,
199,
604,
63,
89,
63,
1320,
645,
275,
1402,
63,
1320,
645,
14,
6892,
8,
604,
63,
56,
3981,
980,
14,
14483,
566,
199,
199,
3,
18955,
20077,
12343,
199,
1361,
480,
9169,
12754,
12343,
334,
2052,
12,
3293,
12,
820,
5622,
1348,
304,
531,
199,
1361,
8,
8009,
12,
1402,
14,
8009,
3131,
1402,
63,
1320,
645,
14,
8627,
3754,
8009,
4602,
199,
199,
6003,
14,
2798,
8,
56,
59,
262,
5697,
63,
2629,
467,
612,
59,
262,
5697,
63,
2629,
467,
1987,
71,
297,
1768,
534,
607,
14035,
358,
199,
6003,
14,
2798,
8,
56,
59,
548,
5697,
63,
2629,
467,
612,
59,
548,
5697,
63,
2629,
467,
1987,
82,
297,
1768,
534,
2204,
14035,
358,
199,
6003,
14,
2798,
8,
604,
63,
56,
12,
1004,
63,
89,
12,
2475,
75,
297,
1768,
534,
10608,
1295,
11686,
358,
199,
6003,
14,
2798,
8,
604,
63,
56,
12,
1004,
63,
89,
63,
1320,
645,
12,
2475,
66,
297,
1768,
534,
50,
5622,
1348,
1295,
11686,
358,
199,
6003,
14,
10231,
8,
2102,
534,
2325,
2451,
358,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2486,
21326,
199,
3863,
15549,
7798,
1402,
27156,
1808,
820,
5622,
1348,
199,
2486,
21326,
199,
199,
607,
642,
2893,
781,
1937,
4212,
370,
23399,
590,
5542,
282,
7798,
1402,
370,
1433,
17323,
666,
1808,
199,
1589,
820,
5622,
1348,
5563,
14,
199,
199,
624,
199,
646,
2680,
465,
980,
199,
504,
8027,
492,
1134,
2798,
465,
4488,
199,
199,
504,
6357,
492,
7798,
63,
1238,
12,
13148,
421,
199,
78,
63,
3356,
275,
5198,
199,
78,
63,
28622,
275,
5238,
421,
199,
56,
12,
612,
12,
7355,
275,
13148,
14,
1875,
63,
12513,
8,
78,
63,
3356,
29,
78,
63,
3356,
12,
302,
63,
3179,
29,
17,
12,
4228,
302,
63,
27666,
29,
17,
12,
11145,
29,
709,
12,
4228,
7355,
29,
549,
12,
2196,
63,
929,
29,
16,
9,
199,
199,
3,
2654,
734,
5697,
666,
199,
1590,
14,
2355,
14,
5176,
8,
16,
9,
199,
56,
1491,
78,
63,
28622,
61,
275,
650,
435,
378,
14,
21,
627,
980,
14,
2355,
14,
3302,
8,
890,
2687,
78,
63,
28622,
12,
413,
430,
199,
89,
1491,
78,
63,
28622,
61,
275,
446,
19,
435,
1616,
627,
980,
14,
2355,
14,
3302,
8,
890,
29,
78,
63,
28622,
9,
199,
199,
3,
25971,
1004,
1808,
1006,
666,
199,
1238,
275,
7798,
63,
1238,
14,
10608,
13013,
342,
199,
1238,
14,
3269,
8,
56,
12,
612,
9,
199,
199,
3,
6848,
15549,
590,
5542,
7798,
1402,
543,
820,
5622,
1348,
5563,
199,
1238,
63,
1320,
645,
275,
7798,
63,
1238,
14,
50,
5622,
1348,
15155,
8,
6676,
63,
1238,
14,
10608,
13013,
1012,
199,
1238,
63,
1320,
645,
14,
3269,
8,
56,
12,
612,
9,
199,
262,
5697,
63,
2629,
275,
1402,
63,
1320,
645,
14,
262,
5697,
63,
2629,
63,
199,
548,
5697,
63,
2629,
275,
980,
14,
7954,
63,
1397,
8,
262,
5697,
63,
2629,
9,
199,
199,
3,
5543,
807,
666,
402,
20077,
1709,
199,
604,
63,
56,
275,
980,
14,
5605,
2801,
21,
12,
959,
9,
199,
604,
63,
89,
275,
1402,
14,
6892,
8,
604,
63,
56,
3981,
980,
14,
14483,
566,
199,
604,
63,
89,
63,
1320,
645,
275,
1402,
63,
1320,
645,
14,
6892,
8,
604,
63,
56,
3981,
980,
14,
14483,
566,
199,
199,
3,
18955,
20077,
12343,
199,
1361,
480,
9169,
12754,
12343,
334,
2052,
12,
3293,
12,
820,
5622,
1348,
304,
531,
199,
1361,
8,
8009,
12,
1402,
14,
8009,
3131,
1402,
63,
1320,
645,
14,
8627,
3754,
8009,
4602,
199,
199,
6003,
14,
2798,
8,
56,
59,
262,
5697,
63,
2629,
467,
612,
59,
262,
5697,
63,
2629,
467,
1987,
71,
297,
1768,
534,
607,
14035,
358,
199,
6003,
14,
2798,
8,
56,
59,
548,
5697,
63,
2629,
467,
612,
59,
548,
5697,
63,
2629,
467,
1987,
82,
297,
1768,
534,
2204,
14035,
358,
199,
6003,
14,
2798,
8,
604,
63,
56,
12,
1004,
63,
89,
12,
2475,
75,
297,
1768,
534,
10608,
1295,
11686,
358,
199,
6003,
14,
2798,
8,
604,
63,
56,
12,
1004,
63,
89,
63,
1320,
645,
12,
2475,
66,
297,
1768,
534,
50,
5622,
1348,
1295,
11686,
358,
199,
6003,
14,
10231,
8,
2102,
534,
2325,
2451,
358,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (c) 2014 Mozilla Corporation
import hjson
import os
from binascii import b2a_hex
import boto3
import datetime
import json
from ipwhois import IPWhois
from mozdef_util.utilities.logger import logger
from mozdef_util.utilities.toUTC import toUTC
class message(object):
def __init__(self):
'''
sends geomodel alert to SSO dashboard
'''
self.alert_classname = 'AlertGeomodel'
config_file_path = os.path.join(os.path.dirname(__file__), 'dashboard_geomodel.json')
json_obj = {}
with open(config_file_path, "r") as fd:
try:
json_obj = hjson.load(fd)
except ValueError:
logger.error("FAILED to open the configuration file" + str(config_file_path))
self.config = json_obj
self.connect_db()
self.registration = 'geomodel'
self.priority = 1
def connect_db(self):
boto_session = boto3.session.Session(
aws_access_key_id=self.config['aws_access_key_id'],
aws_secret_access_key=self.config['aws_secret_access_key'],
region_name=self.config['aws_region']
)
dynamodb_resource = boto_session.resource('dynamodb')
table = dynamodb_resource.Table(self.config['db_table'])
self.dynamodb = table
def write_db_entry(self, alert_record):
self.dynamodb.put_item(Item=alert_record)
def onMessage(self, message):
if 'details' not in message:
return message
if 'principal' not in message['details']:
return message
if 'category' not in message['details']:
return message
if message['details']['category'].lower() != 'newcountry':
return message
full_email = message['details']['principal']
username = full_email.split('@')[0]
auth_full_username = self.config['auth_id_prefix'] + username
if 'city' not in message['details']['locality_details']:
return message
if 'country' not in message['details']['locality_details']:
return message
if 'source_ip' not in message['details']:
return message
city = message['details']['locality_details']['city']
country = message['details']['locality_details']['country']
source_ip = message['details']['source_ip']
new_ip_info = ""
try:
whois = IPWhois(source_ip).lookup_whois()
whois_str = whois['nets'][0]['description']
source_ip_isp = whois_str.replace('\n', ', ').replace('\r', '')
new_ip_info = u'{} ({})'.format(source_ip, source_ip_isp)
except Exception:
new_ip_info = u'{}'.format(source_ip)
new_location_str = u""
if city.lower() == 'unknown':
new_location_str += u'{0}'.format(country)
else:
new_location_str += u'{0}, {1}'.format(city, country)
event_timestamp = toUTC(message['events'][0]['documentsource']['details']['event_time'])
event_day = event_timestamp.strftime('%B %d, %Y')
summary = u'On {0} (UTC), did you login from {1} ({2})?'.format(event_day, new_location_str, source_ip)
previous_city = message['details']['previous_locality_details']['city']
previous_country = message['details']['previous_locality_details']['country']
if previous_city.lower() == 'unknown':
previous_location_str = u'{0}'.format(previous_country)
else:
previous_location_str = u'{0}, {1}'.format(previous_city, previous_country)
alert_record = {
'alert_id': b2a_hex(os.urandom(15)),
'alert_code': b2a_hex(self.alert_classname),
'user_id': auth_full_username,
'risk': self.config['risk'],
'summary': summary,
'description': self.config['description'],
'date': str(datetime.date.today()),
'url': self.config['url'],
'url_title': self.config['url_title'],
'duplicate': self.config['duplicate'],
'alert_str_json': json.dumps(message),
'details': {
'Timestamp': event_timestamp.strftime('%A, %B %d %Y %H:%M UTC'),
'New Location': new_location_str,
'New IP': new_ip_info,
'Previous Location': previous_location_str
}
}
self.write_db_entry(alert_record)
return message
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
1898,
334,
67,
9,
6927,
17728,
11098,
199,
199,
646,
394,
1001,
199,
646,
747,
199,
504,
14755,
492,
330,
18,
65,
63,
4097,
199,
646,
6055,
19,
199,
646,
2197,
199,
646,
2022,
199,
504,
3384,
11345,
374,
492,
3531,
55,
526,
374,
199,
199,
504,
1303,
90,
318,
63,
1974,
14,
16355,
14,
2921,
492,
2512,
199,
504,
1303,
90,
318,
63,
1974,
14,
16355,
14,
475,
11288,
492,
370,
11288,
421,
199,
533,
1245,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1449,
267,
16178,
8509,
1238,
10459,
370,
428,
4118,
17216,
267,
1449,
267,
291,
14,
9241,
63,
19851,
275,
283,
18758,
10748,
1238,
7,
398,
1101,
63,
493,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
9743,
63,
6721,
1238,
14,
1001,
358,
267,
2022,
63,
1113,
275,
1052,
267,
543,
1551,
8,
888,
63,
493,
63,
515,
12,
298,
82,
531,
465,
6111,
26,
288,
862,
26,
355,
2022,
63,
1113,
275,
394,
1001,
14,
912,
8,
2592,
9,
288,
871,
1722,
26,
355,
2512,
14,
705,
480,
12299,
370,
1551,
314,
2897,
570,
2,
435,
620,
8,
888,
63,
493,
63,
515,
430,
267,
291,
14,
888,
275,
2022,
63,
1113,
398,
291,
14,
2242,
63,
697,
342,
398,
291,
14,
8054,
275,
283,
6721,
1238,
7,
267,
291,
14,
6693,
275,
413,
339,
347,
4907,
63,
697,
8,
277,
304,
267,
6055,
63,
1730,
275,
6055,
19,
14,
1730,
14,
4434,
8,
288,
11488,
63,
2732,
63,
498,
63,
344,
29,
277,
14,
888,
459,
7231,
63,
2732,
63,
498,
63,
344,
995,
288,
11488,
63,
4731,
63,
2732,
63,
498,
29,
277,
14,
888,
459,
7231,
63,
4731,
63,
2732,
63,
498,
995,
288,
4897,
63,
354,
29,
277,
14,
888,
459,
7231,
63,
4551,
418,
267,
776,
398,
31388,
13152,
63,
1927,
275,
6055,
63,
1730,
14,
1927,
360,
30001,
358,
267,
1817,
275,
31388,
13152,
63,
1927,
14,
3186,
8,
277,
14,
888,
459,
697,
63,
1224,
1105,
267,
291,
14,
30001,
275,
1817,
339,
347,
2218,
63,
697,
63,
2373,
8,
277,
12,
10459,
63,
3059,
304,
267,
291,
14,
30001,
14,
524,
63,
1053,
8,
2081,
29,
9241,
63,
3059,
9,
339,
347,
641,
2209,
8,
277,
12,
1245,
304,
267,
340,
283,
5087,
7,
440,
315,
1245,
26,
288,
372,
1245,
398,
340,
283,
19200,
7,
440,
315,
1245,
459,
5087,
2565,
288,
372,
1245,
398,
340,
283,
3710,
7,
440,
315,
1245,
459,
5087,
2565,
288,
372,
1245,
398,
340,
1245,
459,
5087,
2545,
3710,
2278,
2325,
342,
1137,
283,
1222,
6063,
356,
288,
372,
1245,
398,
2615,
63,
2123,
275,
1245,
459,
5087,
2545,
19200,
418,
267,
3434,
275,
2615,
63,
2123,
14,
1294,
16591,
5832,
16,
61,
267,
1790,
63,
2861,
63,
2473,
275,
291,
14,
888,
459,
1178,
63,
344,
63,
1861,
418,
435,
3434,
398,
340,
283,
3690,
7,
440,
315,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2565,
288,
372,
1245,
398,
340,
283,
6063,
7,
440,
315,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2565,
288,
372,
1245,
398,
340,
283,
1365,
63,
711,
7,
440,
315,
1245,
459,
5087,
2565,
288,
372,
1245,
398,
14492,
275,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2545,
3690,
418,
267,
9023,
275,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2545,
6063,
418,
267,
1350,
63,
711,
275,
1245,
459,
5087,
2545,
1365,
63,
711,
418,
398,
892,
63,
711,
63,
815,
275,
3087,
267,
862,
26,
288,
3963,
374,
275,
3531,
55,
526,
374,
8,
1365,
63,
711,
680,
3892,
63,
11345,
374,
342,
288,
3963,
374,
63,
495,
275,
3963,
374,
459,
20490,
3488,
16,
2733,
1802,
418,
288,
1350,
63,
711,
63,
27474,
275,
3963,
374,
63,
495,
14,
1814,
2258,
78,
297,
1656,
27274,
1814,
2258,
82,
297,
4074,
288,
892,
63,
711,
63,
815,
275,
399,
7,
2440,
11459,
25885,
908,
8,
1365,
63,
711,
12,
1350,
63,
711,
63,
27474,
9,
267,
871,
2186,
26,
288,
892,
63,
711,
63,
815,
275,
399,
7,
11123,
908,
8,
1365,
63,
711,
9,
398,
892,
63,
1985,
63,
495,
275,
399,
341,
267,
340,
14492,
14,
2325,
342,
508,
283,
5187,
356,
288,
892,
63,
1985,
63,
495,
847,
399,
16019,
16,
5285,
908,
8,
6063,
9,
267,
587,
26,
288,
892,
63,
1985,
63,
495,
847,
399,
16019,
16,
1386,
469,
17,
5285,
908,
8,
3690,
12,
9023,
9,
398,
1566,
63,
3954,
275,
370,
11288,
8,
1188,
459,
4368,
3488,
16,
2733,
3554,
1365,
2545,
5087,
2545,
1430,
63,
521,
1105,
267,
1566,
63,
2977,
275,
1566,
63,
3954,
14,
6205,
3508,
34,
450,
68,
12,
450,
57,
358,
267,
6212,
275,
399,
7,
3314,
469,
16,
93,
334,
11288,
395,
8103,
1265,
4676,
687,
469,
17,
93,
11459,
18,
1552,
31,
1370,
908,
8,
1430,
63,
2977,
12,
892,
63,
1985,
63,
495,
12,
1350,
63,
711,
9,
398,
4136,
63,
3690,
275,
1245,
459,
5087,
2545,
6352,
63,
1832,
1209,
63,
5087,
2545,
3690,
418,
267,
4136,
63,
6063,
275,
1245,
459,
5087,
2545,
6352,
63,
1832,
1209,
63,
5087,
2545,
6063,
418,
267,
340,
4136,
63,
3690,
14,
2325,
342,
508,
283,
5187,
356,
288,
4136,
63,
1985,
63,
495,
275,
399,
16019,
16,
5285,
908,
8,
6352,
63,
6063,
9,
267,
587,
26,
288,
4136,
63,
1985,
63,
495,
275,
399,
16019,
16,
1386,
469,
17,
5285,
908,
8,
6352,
63,
3690,
12,
4136,
63,
6063,
9,
398,
10459,
63,
3059,
275,
469,
288,
283,
9241,
63,
344,
356,
330,
18,
65,
63,
4097,
8,
736,
14,
22776,
8,
1046,
1826,
288,
283,
9241,
63,
600,
356,
330,
18,
65,
63,
4097,
8,
277,
14,
9241,
63,
19851,
395,
288,
283
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
3,
1898,
334,
67,
9,
6927,
17728,
11098,
199,
199,
646,
394,
1001,
199,
646,
747,
199,
504,
14755,
492,
330,
18,
65,
63,
4097,
199,
646,
6055,
19,
199,
646,
2197,
199,
646,
2022,
199,
504,
3384,
11345,
374,
492,
3531,
55,
526,
374,
199,
199,
504,
1303,
90,
318,
63,
1974,
14,
16355,
14,
2921,
492,
2512,
199,
504,
1303,
90,
318,
63,
1974,
14,
16355,
14,
475,
11288,
492,
370,
11288,
421,
199,
533,
1245,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1449,
267,
16178,
8509,
1238,
10459,
370,
428,
4118,
17216,
267,
1449,
267,
291,
14,
9241,
63,
19851,
275,
283,
18758,
10748,
1238,
7,
398,
1101,
63,
493,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
9743,
63,
6721,
1238,
14,
1001,
358,
267,
2022,
63,
1113,
275,
1052,
267,
543,
1551,
8,
888,
63,
493,
63,
515,
12,
298,
82,
531,
465,
6111,
26,
288,
862,
26,
355,
2022,
63,
1113,
275,
394,
1001,
14,
912,
8,
2592,
9,
288,
871,
1722,
26,
355,
2512,
14,
705,
480,
12299,
370,
1551,
314,
2897,
570,
2,
435,
620,
8,
888,
63,
493,
63,
515,
430,
267,
291,
14,
888,
275,
2022,
63,
1113,
398,
291,
14,
2242,
63,
697,
342,
398,
291,
14,
8054,
275,
283,
6721,
1238,
7,
267,
291,
14,
6693,
275,
413,
339,
347,
4907,
63,
697,
8,
277,
304,
267,
6055,
63,
1730,
275,
6055,
19,
14,
1730,
14,
4434,
8,
288,
11488,
63,
2732,
63,
498,
63,
344,
29,
277,
14,
888,
459,
7231,
63,
2732,
63,
498,
63,
344,
995,
288,
11488,
63,
4731,
63,
2732,
63,
498,
29,
277,
14,
888,
459,
7231,
63,
4731,
63,
2732,
63,
498,
995,
288,
4897,
63,
354,
29,
277,
14,
888,
459,
7231,
63,
4551,
418,
267,
776,
398,
31388,
13152,
63,
1927,
275,
6055,
63,
1730,
14,
1927,
360,
30001,
358,
267,
1817,
275,
31388,
13152,
63,
1927,
14,
3186,
8,
277,
14,
888,
459,
697,
63,
1224,
1105,
267,
291,
14,
30001,
275,
1817,
339,
347,
2218,
63,
697,
63,
2373,
8,
277,
12,
10459,
63,
3059,
304,
267,
291,
14,
30001,
14,
524,
63,
1053,
8,
2081,
29,
9241,
63,
3059,
9,
339,
347,
641,
2209,
8,
277,
12,
1245,
304,
267,
340,
283,
5087,
7,
440,
315,
1245,
26,
288,
372,
1245,
398,
340,
283,
19200,
7,
440,
315,
1245,
459,
5087,
2565,
288,
372,
1245,
398,
340,
283,
3710,
7,
440,
315,
1245,
459,
5087,
2565,
288,
372,
1245,
398,
340,
1245,
459,
5087,
2545,
3710,
2278,
2325,
342,
1137,
283,
1222,
6063,
356,
288,
372,
1245,
398,
2615,
63,
2123,
275,
1245,
459,
5087,
2545,
19200,
418,
267,
3434,
275,
2615,
63,
2123,
14,
1294,
16591,
5832,
16,
61,
267,
1790,
63,
2861,
63,
2473,
275,
291,
14,
888,
459,
1178,
63,
344,
63,
1861,
418,
435,
3434,
398,
340,
283,
3690,
7,
440,
315,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2565,
288,
372,
1245,
398,
340,
283,
6063,
7,
440,
315,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2565,
288,
372,
1245,
398,
340,
283,
1365,
63,
711,
7,
440,
315,
1245,
459,
5087,
2565,
288,
372,
1245,
398,
14492,
275,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2545,
3690,
418,
267,
9023,
275,
1245,
459,
5087,
2545,
1832,
1209,
63,
5087,
2545,
6063,
418,
267,
1350,
63,
711,
275,
1245,
459,
5087,
2545,
1365,
63,
711,
418,
398,
892,
63,
711,
63,
815,
275,
3087,
267,
862,
26,
288,
3963,
374,
275,
3531,
55,
526,
374,
8,
1365,
63,
711,
680,
3892,
63,
11345,
374,
342,
288,
3963,
374,
63,
495,
275,
3963,
374,
459,
20490,
3488,
16,
2733,
1802,
418,
288,
1350,
63,
711,
63,
27474,
275,
3963,
374,
63,
495,
14,
1814,
2258,
78,
297,
1656,
27274,
1814,
2258,
82,
297,
4074,
288,
892,
63,
711,
63,
815,
275,
399,
7,
2440,
11459,
25885,
908,
8,
1365,
63,
711,
12,
1350,
63,
711,
63,
27474,
9,
267,
871,
2186,
26,
288,
892,
63,
711,
63,
815,
275,
399,
7,
11123,
908,
8,
1365,
63,
711,
9,
398,
892,
63,
1985,
63,
495,
275,
399,
341,
267,
340,
14492,
14,
2325,
342,
508,
283,
5187,
356,
288,
892,
63,
1985,
63,
495,
847,
399,
16019,
16,
5285,
908,
8,
6063,
9,
267,
587,
26,
288,
892,
63,
1985,
63,
495,
847,
399,
16019,
16,
1386,
469,
17,
5285,
908,
8,
3690,
12,
9023,
9,
398,
1566,
63,
3954,
275,
370,
11288,
8,
1188,
459,
4368,
3488,
16,
2733,
3554,
1365,
2545,
5087,
2545,
1430,
63,
521,
1105,
267,
1566,
63,
2977,
275,
1566,
63,
3954,
14,
6205,
3508,
34,
450,
68,
12,
450,
57,
358,
267,
6212,
275,
399,
7,
3314,
469,
16,
93,
334,
11288,
395,
8103,
1265,
4676,
687,
469,
17,
93,
11459,
18,
1552,
31,
1370,
908,
8,
1430,
63,
2977,
12,
892,
63,
1985,
63,
495,
12,
1350,
63,
711,
9,
398,
4136,
63,
3690,
275,
1245,
459,
5087,
2545,
6352,
63,
1832,
1209,
63,
5087,
2545,
3690,
418,
267,
4136,
63,
6063,
275,
1245,
459,
5087,
2545,
6352,
63,
1832,
1209,
63,
5087,
2545,
6063,
418,
267,
340,
4136,
63,
3690,
14,
2325,
342,
508,
283,
5187,
356,
288,
4136,
63,
1985,
63,
495,
275,
399,
16019,
16,
5285,
908,
8,
6352,
63,
6063,
9,
267,
587,
26,
288,
4136,
63,
1985,
63,
495,
275,
399,
16019,
16,
1386,
469,
17,
5285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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
] |
c-base/libavg
|
src/test/PythonTest.py
|
1
|
8073
|
# -*- coding: utf-8 -*-
# libavg - Media Playback Engine.
# Copyright (C) 2003-2014 Ulrich von Zadow
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Current versions can be found at www.libavg.de
#
import os
import time
import tempfile
from libavg import geom, statemachine, persist
from testcase import *
def getTempFileName():
return os.path.join(tempfile.gettempdir(), 'libavg.%d' % time.time())
class PythonTestCase(AVGTestCase):
def __init__(self, testFuncName):
AVGTestCase.__init__(self, testFuncName)
def testRoundedRect(self):
def setPos():
self.rect.pos = (20.5, 3.5)
def setSize():
self.rect.size = (40, 20)
def setRadius(r):
self.rect.radius = r
def setFill():
self.rect.fillcolor = "0000FF"
self.rect.fillopacity = 0.5
def createDegenRect():
self.rect.unlink(True)
rect = geom.RoundedRect(parent=root, pos=(10.5,10.5), size=(10,10), radius=6,
fillopacity=0.5, color="FFFFFF")
self.assert_(rect.radius == 6)
root = self.loadEmptyScene()
self.rect = geom.RoundedRect(parent=root, pos=(2.5,2.5),
size=(64,64), radius=5, color="FF0000")
self.start(False,
(lambda: self.compareImage("testRoundedRect1"),
setPos,
lambda: self.compareImage("testRoundedRect2"),
setSize,
lambda: self.compareImage("testRoundedRect3"),
lambda: setRadius(10),
lambda: self.compareImage("testRoundedRect4"),
setFill,
lambda: self.compareImage("testRoundedRect5"),
createDegenRect,
lambda: self.compareImage("testRoundedRect6"),
))
def testPieSlice(self):
def changeAttrs():
self.pieSlice.startangle = -1
self.pieSlice.endangle = 3.14
self.pieSlice.radius = 50
self.pieSlice.pos = (80.5, 60.5)
self.pieSlice.fillcolor = "00FFFF"
self.pieSlice.fillopacity = 0.5
def makeSmall():
self.pieSlice.radius = 0.6
root = self.loadEmptyScene()
self.pieSlice = geom.PieSlice(parent=root, pos=(20.5,20.5),
radius=40, startangle=0, endangle=1.57, color="FF0000")
self.start(False,
(lambda: self.compareImage("testPieSlice1"),
changeAttrs,
lambda: self.compareImage("testPieSlice2"),
makeSmall,
lambda: self.compareImage("testPieSlice3"),
))
def testArc(self):
def changeAttrs():
self.arc.startangle = -1
self.arc.endangle = 3.14
self.arc.radius = 50
self.arc.pos = (80.5, 60.5)
root = self.loadEmptyScene()
self.arc = geom.Arc(parent=root, pos=(20.5,20.5),
radius=40, startangle=0, endangle=1.57, color="FF0000")
self.start(False,
(lambda: self.compareImage("testArc1"),
changeAttrs,
lambda: self.compareImage("testArc2"),
))
def btoa(self):
# Test for member function handling in StateMachine.
self.btoaCalled = True
def testStateMachine(self):
def atob(oldState, newState):
self.atobCalled = True
def btoc(dummy):
# Dummy argument so we can test handling of lambda expressions.
self.btocCalled = True
def aEntered():
self.aEnteredCalled = True
def aLeft():
self.aLeftCalled = True
self.atobCalled = False
self.btocCalled = False
self.btoaCalled = False
self.aLeftCalled = False
self.aEnteredCalled = False
machine = statemachine.StateMachine("testmachine", 'A')
machine.addState('A', {'B': atob, 'nostate': atob}, aEntered, aLeft)
machine.addState('B', {'C': lambda: btoc("dummy"), 'A': self.btoa})
machine.addState('C', {'A': None})
self.assertException(lambda: machine.addState('C', {'A': None}))
self.assertException(lambda: machine.changeState('C'))
self.assertException(lambda: machine.changeState('nostate'))
machine.changeState('B')
self.assert_(self.atobCalled)
self.assert_(self.aLeftCalled)
machine.changeState('A')
self.assert_(self.aEnteredCalled)
self.assert_(self.btoaCalled)
machine.changeState('B')
machine.changeState('C')
self.assert_(self.btocCalled)
machine.changeState('A')
self.assertEqual(machine.state, 'A')
# machine.dump()
self.assertException(lambda: machine.addState('illegal', {}))
# Create a machine without transition callbacks
machine = statemachine.StateMachine("testmachine", 'A')
machine.addState('A', ('B',), aEntered, aLeft)
machine.addState('B', ('C', 'A'))
machine.addState('C', ('A',))
machine.changeState('B')
# Make a machine with a transition to a nonexistent state.
kaputtMachine = statemachine.StateMachine("kaputt", 'A')
kaputtMachine.addState('A', {'B': None})
self.assertException(lambda: kaputtMachine.changeState('B'))
def testStateMachineDiagram(self):
def aEntered():
pass
if not(self._isCurrentDirWriteable()):
self.skip("Current dir not writeable")
return
machine = statemachine.StateMachine("testmachine", 'A')
machine.addState('A', {'B': None, 'nostate': None}, aEntered)
machine.addState('B', {'C': None, 'A': self.btoa})
machine.addState('C', {'A': None})
imageFName = AVGTestCase.imageResultDirectory + "/stateMachineGraphViz.png"
try:
machine.makeDiagram(imageFName)
except RuntimeError:
self.skip("graphviz not installed.")
def testPersistStore(self):
testFile = getTempFileName()
p = persist.Persist(testFile, {})
self.assertEqual(p.storeFile, testFile)
self.assertEqual(p.data, {})
p.data['test'] = 1
p.commit()
p = persist.Persist(testFile, {})
self.assert_('test' in p.data)
self.assertEqual(p.data['test'], 1)
os.unlink(testFile)
def testPersistCorrupted(self):
testFile = getTempFileName()
f = open(testFile, 'w')
f.write('garbage')
f.close()
p = persist.Persist(testFile, {})
self.assertEqual(p.data, {})
os.unlink(testFile)
def testPersistValidation(self):
testFile = getTempFileName()
p = persist.Persist(testFile, {'test': 1})
p.commit()
p = persist.Persist(testFile, [], validator=lambda v: isinstance(v, list))
self.assertEqual(p.data, [])
os.unlink(testFile)
def pythonTestSuite(tests):
availableTests = (
"testRoundedRect",
"testPieSlice",
"testArc",
"testStateMachine",
"testStateMachineDiagram",
"testPersistStore",
"testPersistCorrupted",
"testPersistValidation",
)
return createAVGTestSuite(availableTests, PythonTestCase, tests)
|
lgpl-2.1
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1973,
8595,
446,
12300,
16527,
894,
12580,
14,
199,
3,
1898,
334,
35,
9,
13004,
13,
7280,
738,
76,
10399,
373,
265,
3107,
8369,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
3,
9338,
5459,
883,
506,
1911,
737,
20732,
14,
773,
8595,
14,
271,
199,
3,
199,
199,
646,
747,
199,
646,
900,
199,
646,
5549,
199,
199,
504,
1973,
8595,
492,
9671,
12,
1174,
6744,
12,
22400,
199,
199,
504,
16228,
492,
627,
199,
199,
318,
664,
6530,
7733,
837,
272,
372,
747,
14,
515,
14,
904,
8,
17336,
14,
31572,
1062,
283,
773,
8595,
4111,
68,
7,
450,
900,
14,
521,
1012,
421,
199,
533,
2018,
1746,
8,
6087,
39,
1746,
304,
272,
347,
636,
826,
721,
277,
12,
511,
7465,
985,
304,
267,
437,
29355,
1746,
855,
826,
721,
277,
12,
511,
7465,
985,
9,
339,
347,
511,
3863,
4585,
8252,
8,
277,
304,
267,
347,
663,
6981,
837,
288,
291,
14,
1201,
14,
1712,
275,
334,
1165,
14,
21,
12,
650,
14,
21,
9,
398,
347,
663,
2320,
837,
288,
291,
14,
1201,
14,
890,
275,
334,
2167,
12,
3388,
9,
398,
347,
663,
19800,
8,
82,
304,
288,
291,
14,
1201,
14,
8017,
275,
519,
398,
347,
663,
12914,
837,
288,
291,
14,
1201,
14,
4498,
2326,
275,
298,
993,
1665,
2,
288,
291,
14,
1201,
14,
1289,
320,
6192,
275,
378,
14,
21,
398,
347,
1218,
872,
2268,
8252,
837,
288,
291,
14,
1201,
14,
7162,
8,
549,
9,
288,
8626,
275,
9671,
14,
3863,
4585,
8252,
8,
1708,
29,
1231,
12,
2086,
2687,
709,
14,
21,
12,
709,
14,
21,
395,
1568,
2687,
709,
12,
709,
395,
9362,
29,
22,
12,
15324,
1794,
320,
6192,
29,
16,
14,
21,
12,
3164,
628,
6968,
1665,
531,
288,
291,
14,
479,
2531,
1201,
14,
8017,
508,
1227,
9,
398,
1738,
275,
291,
14,
912,
4699,
14216,
342,
267,
291,
14,
1201,
275,
9671,
14,
3863,
4585,
8252,
8,
1708,
29,
1231,
12,
2086,
2687,
18,
14,
21,
12,
18,
14,
21,
395,
8892,
1568,
2687,
772,
12,
772,
395,
9362,
29,
21,
12,
3164,
628,
1665,
993,
531,
267,
291,
14,
928,
8,
797,
12,
355,
334,
2734,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
17,
1288,
326,
663,
6981,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
18,
1288,
326,
663,
2320,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
19,
1288,
326,
2400,
26,
663,
19800,
8,
709,
395,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
20,
1288,
326,
663,
12914,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
21,
1288,
326,
1218,
872,
2268,
8252,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
22,
1288,
355,
5082,
339,
347,
511,
48,
1873,
14034,
8,
277,
304,
267,
347,
1570,
21368,
837,
288,
291,
14,
9890,
14034,
14,
928,
4593,
275,
446,
17,
288,
291,
14,
9890,
14034,
14,
500,
4593,
275,
650,
14,
1079,
288,
291,
14,
9890,
14034,
14,
8017,
275,
5238,
288,
291,
14,
9890,
14034,
14,
1712,
275,
334,
1257,
14,
21,
12,
5212,
14,
21,
9,
288,
291,
14,
9890,
14034,
14,
4498,
2326,
275,
298,
383,
6968,
2,
288,
291,
14,
9890,
14034,
14,
1289,
320,
6192,
275,
378,
14,
21,
398,
347,
1852,
10712,
837,
288,
291,
14,
9890,
14034,
14,
8017,
275,
378,
14,
22,
398,
1738,
275,
291,
14,
912,
4699,
14216,
342,
267,
291,
14,
9890,
14034,
275,
9671,
14,
48,
1873,
14034,
8,
1708,
29,
1231,
12,
2086,
2687,
1165,
14,
21,
12,
1165,
14,
21,
395,
8892,
9362,
29,
2167,
12,
1343,
4593,
29,
16,
12,
1284,
4593,
29,
17,
14,
1641,
12,
3164,
628,
1665,
993,
531,
267,
267,
291,
14,
928,
8,
797,
12,
355,
334,
2734,
26,
291,
14,
5785,
3491,
480,
396,
48,
1873,
14034,
17,
1288,
326,
1570,
21368,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
48,
1873,
14034,
18,
1288,
326,
1852,
10712,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
48,
1873,
14034,
19,
1288,
355,
5082,
339,
347,
511,
27604,
8,
277,
304,
267,
347,
1570,
21368,
837,
288,
291,
14,
9912,
14,
928,
4593,
275,
446,
17,
288,
291,
14,
9912,
14,
500,
4593,
275,
650,
14,
1079,
288,
291,
14,
9912,
14,
8017,
275,
5238,
288,
291,
14,
9912,
14,
1712,
275,
334,
1257,
14,
21,
12,
5212,
14,
21,
9,
398,
1738,
275,
291,
14,
912,
4699,
14216,
342,
267,
291,
14,
9912,
275,
9671,
14,
27604,
8,
1708,
29,
1231,
12,
2086,
2687,
1165,
14,
21,
12,
1165,
14,
21,
395,
8892,
9362,
29,
2167,
12,
1343,
4593,
29,
16,
12,
1284,
4593,
29,
17,
14,
1641,
12,
3164,
628,
1665,
993,
531,
267,
267,
291,
14,
928,
8,
797,
12,
355,
334,
2734,
26,
291,
14,
5785,
3491,
480,
396,
27604,
17,
1288,
326,
1570,
21368,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
27604,
18,
1288,
355,
5082,
339,
347,
330,
475
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1973,
8595,
446,
12300,
16527,
894,
12580,
14,
199,
3,
1898,
334,
35,
9,
13004,
13,
7280,
738,
76,
10399,
373,
265,
3107,
8369,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
3,
9338,
5459,
883,
506,
1911,
737,
20732,
14,
773,
8595,
14,
271,
199,
3,
199,
199,
646,
747,
199,
646,
900,
199,
646,
5549,
199,
199,
504,
1973,
8595,
492,
9671,
12,
1174,
6744,
12,
22400,
199,
199,
504,
16228,
492,
627,
199,
199,
318,
664,
6530,
7733,
837,
272,
372,
747,
14,
515,
14,
904,
8,
17336,
14,
31572,
1062,
283,
773,
8595,
4111,
68,
7,
450,
900,
14,
521,
1012,
421,
199,
533,
2018,
1746,
8,
6087,
39,
1746,
304,
272,
347,
636,
826,
721,
277,
12,
511,
7465,
985,
304,
267,
437,
29355,
1746,
855,
826,
721,
277,
12,
511,
7465,
985,
9,
339,
347,
511,
3863,
4585,
8252,
8,
277,
304,
267,
347,
663,
6981,
837,
288,
291,
14,
1201,
14,
1712,
275,
334,
1165,
14,
21,
12,
650,
14,
21,
9,
398,
347,
663,
2320,
837,
288,
291,
14,
1201,
14,
890,
275,
334,
2167,
12,
3388,
9,
398,
347,
663,
19800,
8,
82,
304,
288,
291,
14,
1201,
14,
8017,
275,
519,
398,
347,
663,
12914,
837,
288,
291,
14,
1201,
14,
4498,
2326,
275,
298,
993,
1665,
2,
288,
291,
14,
1201,
14,
1289,
320,
6192,
275,
378,
14,
21,
398,
347,
1218,
872,
2268,
8252,
837,
288,
291,
14,
1201,
14,
7162,
8,
549,
9,
288,
8626,
275,
9671,
14,
3863,
4585,
8252,
8,
1708,
29,
1231,
12,
2086,
2687,
709,
14,
21,
12,
709,
14,
21,
395,
1568,
2687,
709,
12,
709,
395,
9362,
29,
22,
12,
15324,
1794,
320,
6192,
29,
16,
14,
21,
12,
3164,
628,
6968,
1665,
531,
288,
291,
14,
479,
2531,
1201,
14,
8017,
508,
1227,
9,
398,
1738,
275,
291,
14,
912,
4699,
14216,
342,
267,
291,
14,
1201,
275,
9671,
14,
3863,
4585,
8252,
8,
1708,
29,
1231,
12,
2086,
2687,
18,
14,
21,
12,
18,
14,
21,
395,
8892,
1568,
2687,
772,
12,
772,
395,
9362,
29,
21,
12,
3164,
628,
1665,
993,
531,
267,
291,
14,
928,
8,
797,
12,
355,
334,
2734,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
17,
1288,
326,
663,
6981,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
18,
1288,
326,
663,
2320,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
19,
1288,
326,
2400,
26,
663,
19800,
8,
709,
395,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
20,
1288,
326,
663,
12914,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
21,
1288,
326,
1218,
872,
2268,
8252,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
3863,
4585,
8252,
22,
1288,
355,
5082,
339,
347,
511,
48,
1873,
14034,
8,
277,
304,
267,
347,
1570,
21368,
837,
288,
291,
14,
9890,
14034,
14,
928,
4593,
275,
446,
17,
288,
291,
14,
9890,
14034,
14,
500,
4593,
275,
650,
14,
1079,
288,
291,
14,
9890,
14034,
14,
8017,
275,
5238,
288,
291,
14,
9890,
14034,
14,
1712,
275,
334,
1257,
14,
21,
12,
5212,
14,
21,
9,
288,
291,
14,
9890,
14034,
14,
4498,
2326,
275,
298,
383,
6968,
2,
288,
291,
14,
9890,
14034,
14,
1289,
320,
6192,
275,
378,
14,
21,
398,
347,
1852,
10712,
837,
288,
291,
14,
9890,
14034,
14,
8017,
275,
378,
14,
22,
398,
1738,
275,
291,
14,
912,
4699,
14216,
342,
267,
291,
14,
9890,
14034,
275,
9671,
14,
48,
1873,
14034,
8,
1708,
29,
1231,
12,
2086,
2687,
1165,
14,
21,
12,
1165,
14,
21,
395,
8892,
9362,
29,
2167,
12,
1343,
4593,
29,
16,
12,
1284,
4593,
29,
17,
14,
1641,
12,
3164,
628,
1665,
993,
531,
267,
267,
291,
14,
928,
8,
797,
12,
355,
334,
2734,
26,
291,
14,
5785,
3491,
480,
396,
48,
1873,
14034,
17,
1288,
326,
1570,
21368,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
48,
1873,
14034,
18,
1288,
326,
1852,
10712,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
48,
1873,
14034,
19,
1288,
355,
5082,
339,
347,
511,
27604,
8,
277,
304,
267,
347,
1570,
21368,
837,
288,
291,
14,
9912,
14,
928,
4593,
275,
446,
17,
288,
291,
14,
9912,
14,
500,
4593,
275,
650,
14,
1079,
288,
291,
14,
9912,
14,
8017,
275,
5238,
288,
291,
14,
9912,
14,
1712,
275,
334,
1257,
14,
21,
12,
5212,
14,
21,
9,
398,
1738,
275,
291,
14,
912,
4699,
14216,
342,
267,
291,
14,
9912,
275,
9671,
14,
27604,
8,
1708,
29,
1231,
12,
2086,
2687,
1165,
14,
21,
12,
1165,
14,
21,
395,
8892,
9362,
29,
2167,
12,
1343,
4593,
29,
16,
12,
1284,
4593,
29,
17,
14,
1641,
12,
3164,
628,
1665,
993,
531,
267,
267,
291,
14,
928,
8,
797,
12,
355,
334,
2734,
26,
291,
14,
5785,
3491,
480,
396,
27604,
17,
1288,
326,
1570,
21368,
12,
326,
2400,
26,
291,
14,
5785,
3491,
480,
396,
27604,
18,
1288,
355,
5082,
339,
347,
330,
475,
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,
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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
] |
devops2014/djangosite
|
django/contrib/gis/measure.py
|
118
|
12286
|
# Copyright (c) 2007, Robert Coup <robert.coup@onetrackmind.co.nz>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of Distance nor the names of its contributors may be used
# to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""
Distance and Area objects to allow for sensible and convenient calculation
and conversions.
Authors: Robert Coup, Justin Bronn, Riccardo Di Virgilio
Inspired by GeoPy (http://exogen.case.edu/projects/geopy/)
and Geoff Biggs' PhD work on dimensioned units for robotics.
"""
__all__ = ['A', 'Area', 'D', 'Distance']
from decimal import Decimal
from django.utils import six
from django.utils.functional import total_ordering
NUMERIC_TYPES = six.integer_types + (float, Decimal)
AREA_PREFIX = "sq_"
def pretty_name(obj):
return obj.__name__ if obj.__class__ == type else obj.__class__.__name__
@total_ordering
class MeasureBase(object):
STANDARD_UNIT = None
ALIAS = {}
UNITS = {}
LALIAS = {}
def __init__(self, default_unit=None, **kwargs):
value, self._default_unit = self.default_units(kwargs)
setattr(self, self.STANDARD_UNIT, value)
if default_unit and isinstance(default_unit, six.string_types):
self._default_unit = default_unit
def _get_standard(self):
return getattr(self, self.STANDARD_UNIT)
def _set_standard(self, value):
setattr(self, self.STANDARD_UNIT, value)
standard = property(_get_standard, _set_standard)
def __getattr__(self, name):
if name in self.UNITS:
return self.standard / self.UNITS[name]
else:
raise AttributeError('Unknown unit type: %s' % name)
def __repr__(self):
return '%s(%s=%s)' % (pretty_name(self), self._default_unit,
getattr(self, self._default_unit))
def __str__(self):
return '%s %s' % (getattr(self, self._default_unit), self._default_unit)
# **** Comparison methods ****
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.standard == other.standard
else:
return NotImplemented
def __lt__(self, other):
if isinstance(other, self.__class__):
return self.standard < other.standard
else:
return NotImplemented
# **** Operators methods ****
def __add__(self, other):
if isinstance(other, self.__class__):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard + other.standard)})
else:
raise TypeError('%(class)s must be added with %(class)s' % {"class": pretty_name(self)})
def __iadd__(self, other):
if isinstance(other, self.__class__):
self.standard += other.standard
return self
else:
raise TypeError('%(class)s must be added with %(class)s' % {"class": pretty_name(self)})
def __sub__(self, other):
if isinstance(other, self.__class__):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard - other.standard)})
else:
raise TypeError('%(class)s must be subtracted from %(class)s' % {"class": pretty_name(self)})
def __isub__(self, other):
if isinstance(other, self.__class__):
self.standard -= other.standard
return self
else:
raise TypeError('%(class)s must be subtracted from %(class)s' % {"class": pretty_name(self)})
def __mul__(self, other):
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard * other)})
else:
raise TypeError('%(class)s must be multiplied with number' % {"class": pretty_name(self)})
def __imul__(self, other):
if isinstance(other, NUMERIC_TYPES):
self.standard *= float(other)
return self
else:
raise TypeError('%(class)s must be multiplied with number' % {"class": pretty_name(self)})
def __rmul__(self, other):
return self * other
def __truediv__(self, other):
if isinstance(other, self.__class__):
return self.standard / other.standard
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided with number or %(class)s' % {"class": pretty_name(self)})
def __div__(self, other): # Python 2 compatibility
return type(self).__truediv__(self, other)
def __itruediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
self.standard /= float(other)
return self
else:
raise TypeError('%(class)s must be divided with number' % {"class": pretty_name(self)})
def __idiv__(self, other): # Python 2 compatibility
return type(self).__itruediv__(self, other)
def __bool__(self):
return bool(self.standard)
def __nonzero__(self): # Python 2 compatibility
return type(self).__bool__(self)
def default_units(self, kwargs):
"""
Return the unit value and the default units specified
from the given keyword arguments dictionary.
"""
val = 0.0
default_unit = self.STANDARD_UNIT
for unit, value in six.iteritems(kwargs):
if not isinstance(value, float):
value = float(value)
if unit in self.UNITS:
val += self.UNITS[unit] * value
default_unit = unit
elif unit in self.ALIAS:
u = self.ALIAS[unit]
val += self.UNITS[u] * value
default_unit = u
else:
lower = unit.lower()
if lower in self.UNITS:
val += self.UNITS[lower] * value
default_unit = lower
elif lower in self.LALIAS:
u = self.LALIAS[lower]
val += self.UNITS[u] * value
default_unit = u
else:
raise AttributeError('Unknown unit type: %s' % unit)
return val, default_unit
@classmethod
def unit_attname(cls, unit_str):
"""
Retrieves the unit attribute name for the given unit string.
For example, if the given unit string is 'metre', 'm' would be returned.
An exception is raised if an attribute cannot be found.
"""
lower = unit_str.lower()
if unit_str in cls.UNITS:
return unit_str
elif lower in cls.UNITS:
return lower
elif lower in cls.LALIAS:
return cls.LALIAS[lower]
else:
raise Exception('Could not find a unit keyword associated with "%s"' % unit_str)
class Distance(MeasureBase):
STANDARD_UNIT = "m"
UNITS = {
'chain': 20.1168,
'chain_benoit': 20.116782,
'chain_sears': 20.1167645,
'british_chain_benoit': 20.1167824944,
'british_chain_sears': 20.1167651216,
'british_chain_sears_truncated': 20.116756,
'cm': 0.01,
'british_ft': 0.304799471539,
'british_yd': 0.914398414616,
'clarke_ft': 0.3047972654,
'clarke_link': 0.201166195164,
'fathom': 1.8288,
'ft': 0.3048,
'german_m': 1.0000135965,
'gold_coast_ft': 0.304799710181508,
'indian_yd': 0.914398530744,
'inch': 0.0254,
'km': 1000.0,
'link': 0.201168,
'link_benoit': 0.20116782,
'link_sears': 0.20116765,
'm': 1.0,
'mi': 1609.344,
'mm': 0.001,
'nm': 1852.0,
'nm_uk': 1853.184,
'rod': 5.0292,
'sears_yd': 0.91439841,
'survey_ft': 0.304800609601,
'um': 0.000001,
'yd': 0.9144,
}
# Unit aliases for `UNIT` terms encountered in Spatial Reference WKT.
ALIAS = {
'centimeter': 'cm',
'foot': 'ft',
'inches': 'inch',
'kilometer': 'km',
'kilometre': 'km',
'meter': 'm',
'metre': 'm',
'micrometer': 'um',
'micrometre': 'um',
'millimeter': 'mm',
'millimetre': 'mm',
'mile': 'mi',
'yard': 'yd',
'British chain (Benoit 1895 B)': 'british_chain_benoit',
'British chain (Sears 1922)': 'british_chain_sears',
'British chain (Sears 1922 truncated)': 'british_chain_sears_truncated',
'British foot (Sears 1922)': 'british_ft',
'British foot': 'british_ft',
'British yard (Sears 1922)': 'british_yd',
'British yard': 'british_yd',
"Clarke's Foot": 'clarke_ft',
"Clarke's link": 'clarke_link',
'Chain (Benoit)': 'chain_benoit',
'Chain (Sears)': 'chain_sears',
'Foot (International)': 'ft',
'German legal metre': 'german_m',
'Gold Coast foot': 'gold_coast_ft',
'Indian yard': 'indian_yd',
'Link (Benoit)': 'link_benoit',
'Link (Sears)': 'link_sears',
'Nautical Mile': 'nm',
'Nautical Mile (UK)': 'nm_uk',
'US survey foot': 'survey_ft',
'U.S. Foot': 'survey_ft',
'Yard (Indian)': 'indian_yd',
'Yard (Sears)': 'sears_yd'
}
LALIAS = {k.lower(): v for k, v in ALIAS.items()}
def __mul__(self, other):
if isinstance(other, self.__class__):
return Area(default_unit=AREA_PREFIX + self._default_unit,
**{AREA_PREFIX + self.STANDARD_UNIT: (self.standard * other.standard)})
elif isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard * other)})
else:
raise TypeError('%(distance)s must be multiplied with number or %(distance)s' % {
"distance": pretty_name(self.__class__),
})
class Area(MeasureBase):
STANDARD_UNIT = AREA_PREFIX + Distance.STANDARD_UNIT
# Getting the square units values and the alias dictionary.
UNITS = {'%s%s' % (AREA_PREFIX, k): v ** 2 for k, v in Distance.UNITS.items()}
ALIAS = {k: '%s%s' % (AREA_PREFIX, v) for k, v in Distance.ALIAS.items()}
LALIAS = {k.lower(): v for k, v in ALIAS.items()}
def __truediv__(self, other):
if isinstance(other, NUMERIC_TYPES):
return self.__class__(default_unit=self._default_unit,
**{self.STANDARD_UNIT: (self.standard / other)})
else:
raise TypeError('%(class)s must be divided by a number' % {"class": pretty_name(self)})
def __div__(self, other): # Python 2 compatibility
return type(self).__truediv__(self, other)
# Shortcuts
D = Distance
A = Area
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
12,
6848,
12504,
1849,
384,
665,
293,
12504,
14,
331,
384,
32,
368,
3885,
77,
688,
14,
331,
14,
15291,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
257,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
257,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
420,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
257,
650,
14,
11443,
314,
536,
402,
21892,
6590,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
199,
3,
420,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
420,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
199,
3,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
624,
199,
10076,
436,
26280,
2251,
370,
2040,
367,
27962,
436,
22700,
15232,
199,
460,
24796,
14,
199,
199,
2817,
1384,
26,
6848,
12504,
1849,
384,
12,
13870,
262,
699,
2641,
78,
12,
820,
530,
5841,
79,
3757,
812,
723,
71,
23533,
199,
199,
13962,
1038,
581,
701,
8875,
2713,
334,
1014,
921,
23919,
287,
14,
2546,
14,
8654,
15,
6776,
15,
303,
927,
24793,
199,
460,
5346,
1997,
13123,
458,
7,
11308,
36,
1736,
641,
4408,
12308,
6204,
367,
882,
656,
7769,
14,
199,
624,
199,
363,
452,
363,
275,
788,
33,
297,
283,
11043,
297,
283,
36,
297,
283,
10076,
418,
199,
504,
6107,
492,
6345,
199,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15481,
492,
3141,
63,
7128,
199,
199,
28425,
63,
7893,
275,
3816,
14,
4115,
63,
1313,
435,
334,
1609,
12,
6345,
9,
199,
28591,
63,
6351,
275,
298,
3526,
12172,
421,
199,
318,
7268,
63,
354,
8,
1113,
304,
272,
372,
1559,
855,
354,
363,
340,
1559,
855,
533,
363,
508,
730,
587,
1559,
855,
533,
4914,
354,
363,
421,
199,
32,
2923,
63,
7128,
199,
533,
22933,
1563,
8,
785,
304,
272,
4384,
16938,
63,
15505,
275,
488,
272,
437,
2673,
1179,
275,
1052,
272,
6778,
5930,
275,
1052,
272,
491,
12644,
275,
1052,
339,
347,
636,
826,
721,
277,
12,
849,
63,
3248,
29,
403,
12,
1011,
958,
304,
267,
574,
12,
291,
423,
885,
63,
3248,
275,
291,
14,
885,
63,
5260,
8,
958,
9,
267,
5371,
8,
277,
12,
291,
14,
19547,
63,
15505,
12,
574,
9,
267,
340,
849,
63,
3248,
436,
1228,
8,
885,
63,
3248,
12,
3816,
14,
875,
63,
1313,
304,
288,
291,
423,
885,
63,
3248,
275,
849,
63,
3248,
339,
347,
485,
362,
63,
6807,
8,
277,
304,
267,
372,
2519,
8,
277,
12,
291,
14,
19547,
63,
15505,
9,
339,
347,
485,
409,
63,
6807,
8,
277,
12,
574,
304,
267,
5371,
8,
277,
12,
291,
14,
19547,
63,
15505,
12,
574,
9,
339,
4465,
275,
3324,
1547,
362,
63,
6807,
12,
485,
409,
63,
6807,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
340,
536,
315,
291,
14,
27522,
26,
288,
372,
291,
14,
6807,
1182,
291,
14,
27522,
59,
354,
61,
267,
587,
26,
288,
746,
4281,
360,
5912,
4137,
730,
26,
450,
83,
7,
450,
536,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
4042,
83,
2458,
83,
3171,
450,
334,
9118,
63,
354,
8,
277,
395,
291,
423,
885,
63,
3248,
12,
288,
2519,
8,
277,
12,
291,
423,
885,
63,
3248,
430,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
5675,
8,
277,
12,
291,
423,
885,
63,
3248,
395,
291,
423,
885,
63,
3248,
9,
339,
327,
1011,
538,
3599,
5447,
3102,
1011,
538,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
6807,
508,
1163,
14,
6807,
267,
587,
26,
288,
372,
3784,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
6807,
665,
1163,
14,
6807,
267,
587,
26,
288,
372,
3784,
339,
327,
1011,
538,
6654,
2750,
3102,
1011,
538,
339,
347,
636,
525,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
855,
533,
721,
885,
63,
3248,
29,
277,
423,
885,
63,
3248,
12,
355,
31159,
277,
14,
19547,
63,
15505,
26,
334,
277,
14,
6807,
435,
1163,
14,
6807,
11466,
267,
587,
26,
288,
746,
3146,
24713,
533,
9,
83,
1471,
506,
3483,
543,
2818,
533,
9,
83,
7,
450,
2420,
533,
582,
7268,
63,
354,
8,
277,
11466,
339,
347,
636,
28788,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
291,
14,
6807,
847,
1163,
14,
6807,
288,
372,
291,
267,
587,
26,
288,
746,
3146,
24713,
533,
9,
83,
1471
] |
[
1898,
334,
67,
9,
10219,
12,
6848,
12504,
1849,
384,
665,
293,
12504,
14,
331,
384,
32,
368,
3885,
77,
688,
14,
331,
14,
15291,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
257,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
257,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
420,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
257,
650,
14,
11443,
314,
536,
402,
21892,
6590,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
199,
3,
420,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
199,
3,
420,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
199,
3,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
624,
199,
10076,
436,
26280,
2251,
370,
2040,
367,
27962,
436,
22700,
15232,
199,
460,
24796,
14,
199,
199,
2817,
1384,
26,
6848,
12504,
1849,
384,
12,
13870,
262,
699,
2641,
78,
12,
820,
530,
5841,
79,
3757,
812,
723,
71,
23533,
199,
199,
13962,
1038,
581,
701,
8875,
2713,
334,
1014,
921,
23919,
287,
14,
2546,
14,
8654,
15,
6776,
15,
303,
927,
24793,
199,
460,
5346,
1997,
13123,
458,
7,
11308,
36,
1736,
641,
4408,
12308,
6204,
367,
882,
656,
7769,
14,
199,
624,
199,
363,
452,
363,
275,
788,
33,
297,
283,
11043,
297,
283,
36,
297,
283,
10076,
418,
199,
504,
6107,
492,
6345,
199,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15481,
492,
3141,
63,
7128,
199,
199,
28425,
63,
7893,
275,
3816,
14,
4115,
63,
1313,
435,
334,
1609,
12,
6345,
9,
199,
28591,
63,
6351,
275,
298,
3526,
12172,
421,
199,
318,
7268,
63,
354,
8,
1113,
304,
272,
372,
1559,
855,
354,
363,
340,
1559,
855,
533,
363,
508,
730,
587,
1559,
855,
533,
4914,
354,
363,
421,
199,
32,
2923,
63,
7128,
199,
533,
22933,
1563,
8,
785,
304,
272,
4384,
16938,
63,
15505,
275,
488,
272,
437,
2673,
1179,
275,
1052,
272,
6778,
5930,
275,
1052,
272,
491,
12644,
275,
1052,
339,
347,
636,
826,
721,
277,
12,
849,
63,
3248,
29,
403,
12,
1011,
958,
304,
267,
574,
12,
291,
423,
885,
63,
3248,
275,
291,
14,
885,
63,
5260,
8,
958,
9,
267,
5371,
8,
277,
12,
291,
14,
19547,
63,
15505,
12,
574,
9,
267,
340,
849,
63,
3248,
436,
1228,
8,
885,
63,
3248,
12,
3816,
14,
875,
63,
1313,
304,
288,
291,
423,
885,
63,
3248,
275,
849,
63,
3248,
339,
347,
485,
362,
63,
6807,
8,
277,
304,
267,
372,
2519,
8,
277,
12,
291,
14,
19547,
63,
15505,
9,
339,
347,
485,
409,
63,
6807,
8,
277,
12,
574,
304,
267,
5371,
8,
277,
12,
291,
14,
19547,
63,
15505,
12,
574,
9,
339,
4465,
275,
3324,
1547,
362,
63,
6807,
12,
485,
409,
63,
6807,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
340,
536,
315,
291,
14,
27522,
26,
288,
372,
291,
14,
6807,
1182,
291,
14,
27522,
59,
354,
61,
267,
587,
26,
288,
746,
4281,
360,
5912,
4137,
730,
26,
450,
83,
7,
450,
536,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
1543,
83,
4042,
83,
2458,
83,
3171,
450,
334,
9118,
63,
354,
8,
277,
395,
291,
423,
885,
63,
3248,
12,
288,
2519,
8,
277,
12,
291,
423,
885,
63,
3248,
430,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
450,
83,
7,
450,
334,
5675,
8,
277,
12,
291,
423,
885,
63,
3248,
395,
291,
423,
885,
63,
3248,
9,
339,
327,
1011,
538,
3599,
5447,
3102,
1011,
538,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
6807,
508,
1163,
14,
6807,
267,
587,
26,
288,
372,
3784,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
14,
6807,
665,
1163,
14,
6807,
267,
587,
26,
288,
372,
3784,
339,
327,
1011,
538,
6654,
2750,
3102,
1011,
538,
339,
347,
636,
525,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
372,
291,
855,
533,
721,
885,
63,
3248,
29,
277,
423,
885,
63,
3248,
12,
355,
31159,
277,
14,
19547,
63,
15505,
26,
334,
277,
14,
6807,
435,
1163,
14,
6807,
11466,
267,
587,
26,
288,
746,
3146,
24713,
533,
9,
83,
1471,
506,
3483,
543,
2818,
533,
9,
83,
7,
450,
2420,
533,
582,
7268,
63,
354,
8,
277,
11466,
339,
347,
636,
28788,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
291,
855,
533,
18580,
288,
291,
14,
6807,
847,
1163,
14,
6807,
288,
372,
291,
267,
587,
26,
288,
746,
3146,
24713,
533,
9,
83,
1471,
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,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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
] |
anubhav929/eden
|
static/scripts/Database_migration/migration_scripts.py
|
3
|
7058
|
# All the functions that does the migration have been added to migration_scripts file . migration_scripts file
# internally calls the functions of migration_helping_methods file too perform the migration . Thus in order to
# do the migration one just needs to import migration_scripts and call the method corresponding to the migration
# he wants . Also the user who wishes to do the migration in the db doesn't have to know the internal functioning
# of migration_script , thus the functions or the methods declared in migration_helping_methods file doesn't concern him.
#
#
# Tests
# Tests for each function has been made in order to call the tests just
# run the tests script using the following command as eden app being your parent directory
# python tests/dbmigration/test_migrations.py
#
# Choose from the menu whatever migration methos you want to test,
from migration_helping_methods import *
def list_field_to_reference(web2py_path, app , new_table_name , new_list_field , list_field_name , old_table_id_field , old_table):
"""
This method handles the migration in which a new table with a column for the
values they'll get from the list field is made and maybe some empty columns to be filled in later.
That new table has a foreign key reference back to the original table.
Then for each value in the list field for each record in the original table,
they create one record in the new table that points back to the original record.
Method of Calling
import migration_scripts
migration_scripts.list_field_to_reference(web2py_path,app,new_table_name , new_list_field , list_field_name , old_table_id_field , old_table)
@param web2py_path : The path to the web2py congaing the Eden app (i.e "/home/web2py")
@param app : The name of the eden application of whose database needs to be migrated (i.e "eden")
@param new_table_name : The name of the new table to which the list field needs to migrated
@param new_list_field : The name of the field in the new table which will hold the content of the list field
@param list_field_name : The name of the list field in the original table
@param old_table_id_field : The name of the id field in the original table
@param old_table : The name of the original table
"""
set_globals(web2py_path,app)
creating_new_table(new_table_name , new_list_field , list_field_name , old_table_id_field , old_table)
fill_the_new_table(new_table_name , new_list_field , list_field_name , old_table_id_field , old_table )
def migrating_to_unique_field(web2py_path, app ,field_to_update,changed_table , mapping_function , list_of_tables = None):
"""
Adding values to a new field and adding values according to the mappings given through the mapping_funation
- Method of Calling
import migration_scripts
import mapping_function
migration_scripts.migrating_to_unique_field( web2py_path, app ,field_to_update , changed_table ,mapping_function, list_of_tables)
@param web2py_path : The path to the web2py congaing the Eden app (i.e "/home/web2py")
@param app : The name of the eden application of whose database needs to be migrated (i.e "eden")
@param field_to_update : The name of the field to be updated according to the mapping
@param changed_table : The name of the original table in which the new unique field id added
@param list_of_tables : These contains the list of tables which the changed_tables references
"""
set_globals(web2py_path,app)
temp_db = adding_new_fields(field_to_update,changed_table)
set_db(adding_tables_temp_db(temp_db,list_of_tables))
update_with_mappings(changed_table,field_to_update,mapping_function)
def update_field_by_mapping(web2py_path, app ,field_to_update,changed_table , mapping_function ):
"""
Update the the values of an existing field according to the mappings given through the mapping_function
- Method of Calling
import migration_scripts
import mapping_function
migration_scripts.update_field_by_mapping( web2py_path, app ,field_to_update , changed_table ,mapping_function, list_of_tables)
@param web2py_path : The path to the web2py congaing the Eden app (i.e "/home/web2py")
@param app : The name of the eden application of whose database needs to be migrated (i.e "eden")
@param field_to_update : The name of the field to be updated according to the mapping
@param changed_table : The name of the original table in which the new unique field id added
@param list_of_tables : These contains the list of tables which the changed_tables references
"""
set_globals(web2py_path,app)
update_with_mappings(changed_table,field_to_update,mapping_function)
def migration_renaming_table(web2py_path, app ,old_table_name,new_table_name):
"""
Renaming a particular table , Thus if any fields references to that table it will be handled too.
- Method of Calling
import migration_scripts
migration_scripts.migration_renaming_table(web2py_path, app ,old_table_name,new_table_name)
Description of arguments
@param web2py_path : The path to the web2py congaing the Eden app (i.e "/home/web2py")
@param app : The name of the eden application of whose database needs to be migrated (i.e "eden")
@param old_table_name : The name of the original table before renaming
@param new_table_name : The name of the table after renaming
"""
set_globals(web2py_path,app)
renaming_table(old_table_name,new_table_name)
def migration_renaming_field(web2py_path, app ,table_name,old_field_name,new_field_name,attributes_to_copy = None):
"""
Renaming a particular field , while keeping the other properties of the field same.
Also if there are some index on that table that will be recreated and other constraints will remain unchanged too.
Method of Calling
import migration_scripts
migration_scripts.migration_renaming_field(web2py_path, app, old_table, old_field_name , new_field_name ,attributes_to_copy)
@param web2py_path : The path to the web2py congaing the Eden app (i.e "/home/web2py")
@param app : The name of the eden application of whose database needs to be migrated (i.e "eden")
@param old_table : The name of the table in which the field is renamed
@param old_field_name : The name of the original field before renaming
@param new_field_name : The name of the field after renaming
@param attributes_to_copy : The list of attributes which needs to be copied from the old_field to the new_field (needed only in sqlite)
"""
set_globals(web2py_path,app)
renaming_field(table_name,old_field_name,new_field_name,attributes_to_copy)
|
mit
|
[
199,
3,
2900,
314,
3423,
626,
1630,
314,
8367,
1172,
2757,
3483,
370,
8367,
63,
6429,
570,
1275,
8367,
63,
6429,
570,
221,
199,
3,
14448,
4882,
314,
3423,
402,
8367,
63,
3437,
316,
63,
2474,
570,
4634,
5147,
314,
8367,
1275,
20227,
315,
1865,
370,
199,
3,
221,
886,
314,
8367,
1373,
2951,
4839,
370,
492,
8367,
63,
6429,
436,
1240,
314,
1083,
5226,
370,
314,
8367,
221,
199,
3,
946,
15061,
1275,
221,
6121,
314,
922,
3963,
13809,
397,
370,
886,
314,
8367,
315,
314,
1592,
3181,
1133,
1172,
370,
5715,
314,
5007,
805,
316,
199,
3,
402,
8367,
63,
1579,
2360,
221,
12850,
314,
3423,
503,
314,
3102,
14290,
315,
8367,
63,
3437,
316,
63,
2474,
570,
3181,
1133,
406,
22082,
26457,
14,
199,
3,
199,
3,
199,
3,
6496,
221,
199,
3,
6496,
367,
1924,
805,
965,
2757,
6326,
315,
1865,
370,
1240,
314,
2295,
2951,
199,
3,
1255,
314,
2295,
2884,
1808,
314,
2569,
1414,
465,
325,
848,
1145,
3769,
2195,
1676,
2082,
199,
3,
2366,
2295,
15,
697,
8998,
15,
396,
63,
7685,
14,
647,
221,
199,
3,
221,
199,
3,
29826,
687,
314,
6269,
15685,
8367,
12750,
736,
1265,
2934,
370,
511,
12,
199,
199,
504,
8367,
63,
3437,
316,
63,
2474,
492,
627,
199,
199,
318,
769,
63,
698,
63,
475,
63,
4443,
8,
2520,
18,
647,
63,
515,
12,
1145,
2360,
892,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
304,
272,
408,
272,
961,
1083,
10022,
314,
8367,
315,
1314,
282,
892,
1817,
543,
282,
2763,
367,
314,
5591,
1338,
2985,
7171,
664,
687,
314,
769,
901,
365,
6326,
436,
11703,
2005,
2701,
4362,
370,
506,
13457,
315,
2945,
14,
5591,
10314,
892,
1817,
965,
282,
11608,
790,
3659,
1771,
370,
314,
3379,
1817,
14,
272,
9442,
367,
1924,
574,
315,
314,
769,
901,
367,
1924,
2777,
315,
314,
3379,
1817,
12,
5591,
2985,
1218,
1373,
2777,
315,
314,
892,
1817,
626,
4501,
1771,
370,
314,
3379,
2777,
14,
2043,
272,
9075,
402,
23892,
339,
492,
8367,
63,
6429,
272,
8367,
63,
6429,
14,
513,
63,
698,
63,
475,
63,
4443,
8,
2520,
18,
647,
63,
515,
12,
571,
12,
1222,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
9,
2286,
768,
635,
258,
3330,
18,
647,
63,
515,
263,
520,
259,
710,
931,
370,
314,
3330,
18,
647,
406,
5294,
316,
314,
662,
848,
1145,
334,
73,
14,
69,
3286,
4219,
15,
2520,
18,
647,
531,
272,
768,
635,
258,
1145,
4483,
520,
259,
710,
536,
402,
314,
325,
848,
4223,
402,
7447,
3050,
4839,
370,
506,
28322,
334,
73,
14,
69,
298,
69,
848,
531,
272,
768,
635,
258,
892,
63,
1224,
63,
354,
258,
520,
259,
710,
536,
402,
314,
892,
1817,
370,
1314,
314,
769,
901,
4839,
370,
28322,
272,
768,
635,
258,
892,
63,
513,
63,
698,
258,
520,
259,
710,
536,
402,
314,
901,
315,
314,
892,
1817,
1314,
911,
10266,
314,
1564,
402,
314,
769,
901,
272,
768,
635,
258,
769,
63,
698,
63,
354,
259,
520,
259,
710,
536,
402,
314,
769,
901,
315,
314,
3379,
1817,
272,
768,
635,
258,
2269,
63,
1224,
63,
344,
63,
698,
520,
259,
710,
536,
402,
314,
1305,
901,
315,
314,
3379,
1817,
272,
768,
635,
258,
2269,
63,
1224,
3515,
520,
259,
710,
536,
402,
314,
3379,
1817,
272,
408,
272,
663,
63,
8473,
8,
2520,
18,
647,
63,
515,
12,
571,
9,
272,
6425,
63,
1222,
63,
1224,
8,
1222,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
9,
272,
5554,
63,
1589,
63,
1222,
63,
1224,
8,
1222,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
776,
199,
199,
318,
3952,
10417,
63,
475,
63,
3235,
63,
698,
8,
2520,
18,
647,
63,
515,
12,
1145,
2360,
698,
63,
475,
63,
873,
12,
2489,
63,
1224,
2360,
4412,
63,
1593,
2360,
769,
63,
1618,
63,
5987,
275,
488,
304,
272,
408,
272,
12934,
1338,
370,
282,
892,
901,
436,
7791,
1338,
7182,
370,
314,
13546,
1627,
4012,
314,
4412,
63,
7036,
425,
2286,
446,
9075,
402,
23892,
339,
492,
8367,
63,
6429,
272,
492,
4412,
63,
1593,
272,
8367,
63,
6429,
14,
4071,
10417,
63,
475,
63,
3235,
63,
698,
8,
3330,
18,
647,
63,
515,
12,
1145,
2360,
698,
63,
475,
63,
873,
2360,
2896,
63,
1224,
2360,
4745,
63,
1593,
12,
769,
63,
1618,
63,
5987,
9,
1362,
339,
768,
635,
259,
3330,
18,
647,
63,
515,
258,
520,
259,
710,
931,
370,
314,
3330,
18,
647,
406,
5294,
316,
314,
662,
848,
1145,
334,
73,
14,
69,
3286,
4219,
15,
2520,
18,
647,
531,
272,
768,
635,
259,
1145,
3777,
520,
259,
710,
536,
402,
314,
325,
848,
4223,
402,
7447,
3050,
4839,
370,
506,
28322,
334,
73,
14,
69,
298,
69,
848,
531,
272,
768,
635,
259,
901,
63,
475,
63,
873,
520,
259,
710,
536,
402,
314,
901,
370,
506,
4588,
7182,
370,
314,
4412,
272,
768,
635,
259,
2896,
63,
1224,
257,
520,
259,
710,
536,
402,
314,
3379,
1817,
315,
1314,
314,
892,
3747,
901,
1305,
3483,
272,
768,
635,
259,
769,
63,
1618,
63,
5987,
221,
520,
259,
5723,
3509,
314,
769,
402,
6716,
1314,
314,
2896,
63,
5987,
6941,
339,
408,
272,
663,
63,
8473,
8,
2520,
18,
647,
63,
515,
12,
571,
9,
272,
2388,
63,
697,
275,
7791,
63,
1222,
63,
955,
8,
698,
63,
475,
63,
873,
12,
2489,
63,
1224,
9,
272,
663,
63,
697,
8,
4095,
63,
5987,
63,
808,
63,
697,
8,
808,
63,
697,
12,
513,
63,
1618,
63,
5987,
430,
272,
1678,
63,
1045,
63,
14632,
8,
2489,
63,
1224,
12,
698,
63,
475,
63,
873,
12,
4745,
63
] |
[
3,
2900,
314,
3423,
626,
1630,
314,
8367,
1172,
2757,
3483,
370,
8367,
63,
6429,
570,
1275,
8367,
63,
6429,
570,
221,
199,
3,
14448,
4882,
314,
3423,
402,
8367,
63,
3437,
316,
63,
2474,
570,
4634,
5147,
314,
8367,
1275,
20227,
315,
1865,
370,
199,
3,
221,
886,
314,
8367,
1373,
2951,
4839,
370,
492,
8367,
63,
6429,
436,
1240,
314,
1083,
5226,
370,
314,
8367,
221,
199,
3,
946,
15061,
1275,
221,
6121,
314,
922,
3963,
13809,
397,
370,
886,
314,
8367,
315,
314,
1592,
3181,
1133,
1172,
370,
5715,
314,
5007,
805,
316,
199,
3,
402,
8367,
63,
1579,
2360,
221,
12850,
314,
3423,
503,
314,
3102,
14290,
315,
8367,
63,
3437,
316,
63,
2474,
570,
3181,
1133,
406,
22082,
26457,
14,
199,
3,
199,
3,
199,
3,
6496,
221,
199,
3,
6496,
367,
1924,
805,
965,
2757,
6326,
315,
1865,
370,
1240,
314,
2295,
2951,
199,
3,
1255,
314,
2295,
2884,
1808,
314,
2569,
1414,
465,
325,
848,
1145,
3769,
2195,
1676,
2082,
199,
3,
2366,
2295,
15,
697,
8998,
15,
396,
63,
7685,
14,
647,
221,
199,
3,
221,
199,
3,
29826,
687,
314,
6269,
15685,
8367,
12750,
736,
1265,
2934,
370,
511,
12,
199,
199,
504,
8367,
63,
3437,
316,
63,
2474,
492,
627,
199,
199,
318,
769,
63,
698,
63,
475,
63,
4443,
8,
2520,
18,
647,
63,
515,
12,
1145,
2360,
892,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
304,
272,
408,
272,
961,
1083,
10022,
314,
8367,
315,
1314,
282,
892,
1817,
543,
282,
2763,
367,
314,
5591,
1338,
2985,
7171,
664,
687,
314,
769,
901,
365,
6326,
436,
11703,
2005,
2701,
4362,
370,
506,
13457,
315,
2945,
14,
5591,
10314,
892,
1817,
965,
282,
11608,
790,
3659,
1771,
370,
314,
3379,
1817,
14,
272,
9442,
367,
1924,
574,
315,
314,
769,
901,
367,
1924,
2777,
315,
314,
3379,
1817,
12,
5591,
2985,
1218,
1373,
2777,
315,
314,
892,
1817,
626,
4501,
1771,
370,
314,
3379,
2777,
14,
2043,
272,
9075,
402,
23892,
339,
492,
8367,
63,
6429,
272,
8367,
63,
6429,
14,
513,
63,
698,
63,
475,
63,
4443,
8,
2520,
18,
647,
63,
515,
12,
571,
12,
1222,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
9,
2286,
768,
635,
258,
3330,
18,
647,
63,
515,
263,
520,
259,
710,
931,
370,
314,
3330,
18,
647,
406,
5294,
316,
314,
662,
848,
1145,
334,
73,
14,
69,
3286,
4219,
15,
2520,
18,
647,
531,
272,
768,
635,
258,
1145,
4483,
520,
259,
710,
536,
402,
314,
325,
848,
4223,
402,
7447,
3050,
4839,
370,
506,
28322,
334,
73,
14,
69,
298,
69,
848,
531,
272,
768,
635,
258,
892,
63,
1224,
63,
354,
258,
520,
259,
710,
536,
402,
314,
892,
1817,
370,
1314,
314,
769,
901,
4839,
370,
28322,
272,
768,
635,
258,
892,
63,
513,
63,
698,
258,
520,
259,
710,
536,
402,
314,
901,
315,
314,
892,
1817,
1314,
911,
10266,
314,
1564,
402,
314,
769,
901,
272,
768,
635,
258,
769,
63,
698,
63,
354,
259,
520,
259,
710,
536,
402,
314,
769,
901,
315,
314,
3379,
1817,
272,
768,
635,
258,
2269,
63,
1224,
63,
344,
63,
698,
520,
259,
710,
536,
402,
314,
1305,
901,
315,
314,
3379,
1817,
272,
768,
635,
258,
2269,
63,
1224,
3515,
520,
259,
710,
536,
402,
314,
3379,
1817,
272,
408,
272,
663,
63,
8473,
8,
2520,
18,
647,
63,
515,
12,
571,
9,
272,
6425,
63,
1222,
63,
1224,
8,
1222,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
9,
272,
5554,
63,
1589,
63,
1222,
63,
1224,
8,
1222,
63,
1224,
63,
354,
2360,
892,
63,
513,
63,
698,
2360,
769,
63,
698,
63,
354,
2360,
2269,
63,
1224,
63,
344,
63,
698,
2360,
2269,
63,
1224,
776,
199,
199,
318,
3952,
10417,
63,
475,
63,
3235,
63,
698,
8,
2520,
18,
647,
63,
515,
12,
1145,
2360,
698,
63,
475,
63,
873,
12,
2489,
63,
1224,
2360,
4412,
63,
1593,
2360,
769,
63,
1618,
63,
5987,
275,
488,
304,
272,
408,
272,
12934,
1338,
370,
282,
892,
901,
436,
7791,
1338,
7182,
370,
314,
13546,
1627,
4012,
314,
4412,
63,
7036,
425,
2286,
446,
9075,
402,
23892,
339,
492,
8367,
63,
6429,
272,
492,
4412,
63,
1593,
272,
8367,
63,
6429,
14,
4071,
10417,
63,
475,
63,
3235,
63,
698,
8,
3330,
18,
647,
63,
515,
12,
1145,
2360,
698,
63,
475,
63,
873,
2360,
2896,
63,
1224,
2360,
4745,
63,
1593,
12,
769,
63,
1618,
63,
5987,
9,
1362,
339,
768,
635,
259,
3330,
18,
647,
63,
515,
258,
520,
259,
710,
931,
370,
314,
3330,
18,
647,
406,
5294,
316,
314,
662,
848,
1145,
334,
73,
14,
69,
3286,
4219,
15,
2520,
18,
647,
531,
272,
768,
635,
259,
1145,
3777,
520,
259,
710,
536,
402,
314,
325,
848,
4223,
402,
7447,
3050,
4839,
370,
506,
28322,
334,
73,
14,
69,
298,
69,
848,
531,
272,
768,
635,
259,
901,
63,
475,
63,
873,
520,
259,
710,
536,
402,
314,
901,
370,
506,
4588,
7182,
370,
314,
4412,
272,
768,
635,
259,
2896,
63,
1224,
257,
520,
259,
710,
536,
402,
314,
3379,
1817,
315,
1314,
314,
892,
3747,
901,
1305,
3483,
272,
768,
635,
259,
769,
63,
1618,
63,
5987,
221,
520,
259,
5723,
3509,
314,
769,
402,
6716,
1314,
314,
2896,
63,
5987,
6941,
339,
408,
272,
663,
63,
8473,
8,
2520,
18,
647,
63,
515,
12,
571,
9,
272,
2388,
63,
697,
275,
7791,
63,
1222,
63,
955,
8,
698,
63,
475,
63,
873,
12,
2489,
63,
1224,
9,
272,
663,
63,
697,
8,
4095,
63,
5987,
63,
808,
63,
697,
8,
808,
63,
697,
12,
513,
63,
1618,
63,
5987,
430,
272,
1678,
63,
1045,
63,
14632,
8,
2489,
63,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dsajkl/123
|
lms/djangoapps/instructor/tests/test_legacy_reset.py
|
6
|
2859
|
"""
View-level tests for resetting student state in legacy instructor dash.
"""
import json
from django.core.urlresolvers import reverse
from django.test.utils import override_settings
from courseware.tests.helpers import LoginEnrollmentTestCase
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from courseware.tests.modulestore_config import TEST_DATA_MONGO_MODULESTORE
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import UserFactory, AdminFactory, CourseEnrollmentFactory
from courseware.models import StudentModule
from submissions import api as sub_api
from student.models import anonymous_id_for_user
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class InstructorResetStudentStateTest(ModuleStoreTestCase, LoginEnrollmentTestCase):
"""
Reset student state from the legacy instructor dash.
"""
def setUp(self):
"""
Log in as an instructor, and create a course/student to reset.
"""
instructor = AdminFactory.create()
self.client.login(username=instructor.username, password='test')
self.student = UserFactory.create(username='test', email='test@example.com')
self.course = CourseFactory.create()
CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id)
def test_delete_student_state_resets_scores(self):
problem_location = self.course.id.make_usage_key('dummy', 'module')
# Create a student module for the user
StudentModule.objects.create(
student=self.student,
course_id=self.course.id,
module_state_key=problem_location,
state=json.dumps({})
)
# Create a submission and score for the student using the submissions API
student_item = {
'student_id': anonymous_id_for_user(self.student, self.course.id),
'course_id': self.course.id.to_deprecated_string(),
'item_id': problem_location.to_deprecated_string(),
'item_type': 'openassessment'
}
submission = sub_api.create_submission(student_item, 'test answer')
sub_api.set_score(submission['uuid'], 1, 2)
# Delete student state using the instructor dash
url = reverse('instructor_dashboard_legacy', kwargs={'course_id': self.course.id.to_deprecated_string()})
response = self.client.post(url, {
'action': 'Delete student state for module',
'unique_student_identifier': self.student.email,
'problem_for_student': problem_location.to_deprecated_string(),
})
self.assertEqual(response.status_code, 200)
# Verify that the student's scores have been reset in the submissions API
score = sub_api.get_score(student_item)
self.assertIs(score, None)
|
agpl-3.0
|
[
624,
199,
2768,
13,
1896,
2295,
367,
5305,
1337,
6474,
1174,
315,
12139,
17724,
11847,
14,
199,
624,
199,
199,
646,
2022,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
199,
504,
20736,
14,
2219,
14,
7546,
492,
16430,
13842,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
20736,
14,
2219,
14,
10012,
63,
888,
492,
7393,
63,
3998,
63,
45,
26477,
63,
27011,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
12,
9516,
2927,
12,
18946,
2927,
199,
199,
504,
20736,
14,
992,
492,
17246,
2377,
199,
199,
504,
30399,
492,
2986,
465,
1007,
63,
1246,
199,
504,
6474,
14,
992,
492,
16535,
63,
344,
63,
509,
63,
751,
421,
199,
32,
4415,
63,
1751,
8,
27011,
29,
2864,
63,
3998,
63,
45,
26477,
63,
27011,
9,
199,
533,
26150,
9637,
18086,
2223,
774,
8,
27863,
12,
16430,
13842,
1746,
304,
272,
408,
272,
15510,
6474,
1174,
687,
314,
12139,
17724,
11847,
14,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
5297,
315,
465,
376,
17724,
12,
436,
1218,
282,
2518,
15,
5500,
370,
5305,
14,
267,
408,
267,
17724,
275,
9516,
2927,
14,
981,
342,
267,
291,
14,
1258,
14,
2886,
8,
2473,
29,
14891,
14,
2473,
12,
2505,
534,
396,
358,
267,
291,
14,
5500,
275,
16047,
14,
981,
8,
2473,
534,
396,
297,
3031,
534,
396,
32,
2694,
14,
957,
358,
267,
291,
14,
1972,
275,
17862,
14,
981,
342,
267,
18946,
2927,
14,
981,
8,
751,
29,
277,
14,
5500,
12,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
9,
339,
347,
511,
63,
1807,
63,
5500,
63,
929,
63,
264,
2193,
63,
7107,
8,
277,
304,
267,
5160,
63,
1985,
275,
291,
14,
1972,
14,
344,
14,
1875,
63,
3807,
63,
498,
360,
5869,
297,
283,
578,
358,
398,
327,
2790,
282,
6474,
859,
367,
314,
922,
267,
17246,
2377,
14,
1462,
14,
981,
8,
288,
6474,
29,
277,
14,
5500,
12,
288,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
288,
859,
63,
929,
63,
498,
29,
6462,
63,
1985,
12,
288,
1174,
29,
1001,
14,
4180,
14079,
267,
776,
398,
327,
2790,
282,
13071,
436,
5396,
367,
314,
6474,
1808,
314,
30399,
3261,
267,
6474,
63,
1053,
275,
469,
288,
283,
5500,
63,
344,
356,
16535,
63,
344,
63,
509,
63,
751,
8,
277,
14,
5500,
12,
291,
14,
1972,
14,
344,
395,
288,
283,
1972,
63,
344,
356,
291,
14,
1972,
14,
344,
14,
475,
63,
6667,
63,
875,
1062,
288,
283,
1053,
63,
344,
356,
5160,
63,
1985,
14,
475,
63,
6667,
63,
875,
1062,
288,
283,
1053,
63,
466,
356,
283,
1490,
17452,
7,
267,
789,
267,
13071,
275,
1007,
63,
1246,
14,
981,
63,
12542,
8,
5500,
63,
1053,
12,
283,
396,
6385,
358,
267,
1007,
63,
1246,
14,
409,
63,
3397,
8,
12542,
459,
2580,
995,
413,
12,
499,
9,
398,
327,
8496,
6474,
1174,
1808,
314,
17724,
11847,
267,
1166,
275,
3837,
360,
14891,
63,
9743,
63,
10000,
297,
2074,
3713,
1972,
63,
344,
356,
291,
14,
1972,
14,
344,
14,
475,
63,
6667,
63,
875,
22804,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
469,
288,
283,
1287,
356,
283,
5392,
6474,
1174,
367,
859,
297,
288,
283,
3235,
63,
5500,
63,
5364,
356,
291,
14,
5500,
14,
2123,
12,
288,
283,
6462,
63,
509,
63,
5500,
356,
5160,
63,
1985,
14,
475,
63,
6667,
63,
875,
1062,
267,
3828,
398,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
7635,
626,
314,
6474,
1159,
9342,
1172,
2757,
5305,
315,
314,
30399,
3261,
267,
5396,
275,
1007,
63,
1246,
14,
362,
63,
3397,
8,
5500,
63,
1053,
9,
267,
291,
14,
3436,
8,
3397,
12,
488,
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
] |
[
199,
2768,
13,
1896,
2295,
367,
5305,
1337,
6474,
1174,
315,
12139,
17724,
11847,
14,
199,
624,
199,
199,
646,
2022,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
199,
504,
20736,
14,
2219,
14,
7546,
492,
16430,
13842,
1746,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
199,
504,
20736,
14,
2219,
14,
10012,
63,
888,
492,
7393,
63,
3998,
63,
45,
26477,
63,
27011,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
199,
504,
6474,
14,
2219,
14,
15406,
492,
16047,
12,
9516,
2927,
12,
18946,
2927,
199,
199,
504,
20736,
14,
992,
492,
17246,
2377,
199,
199,
504,
30399,
492,
2986,
465,
1007,
63,
1246,
199,
504,
6474,
14,
992,
492,
16535,
63,
344,
63,
509,
63,
751,
421,
199,
32,
4415,
63,
1751,
8,
27011,
29,
2864,
63,
3998,
63,
45,
26477,
63,
27011,
9,
199,
533,
26150,
9637,
18086,
2223,
774,
8,
27863,
12,
16430,
13842,
1746,
304,
272,
408,
272,
15510,
6474,
1174,
687,
314,
12139,
17724,
11847,
14,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
5297,
315,
465,
376,
17724,
12,
436,
1218,
282,
2518,
15,
5500,
370,
5305,
14,
267,
408,
267,
17724,
275,
9516,
2927,
14,
981,
342,
267,
291,
14,
1258,
14,
2886,
8,
2473,
29,
14891,
14,
2473,
12,
2505,
534,
396,
358,
267,
291,
14,
5500,
275,
16047,
14,
981,
8,
2473,
534,
396,
297,
3031,
534,
396,
32,
2694,
14,
957,
358,
267,
291,
14,
1972,
275,
17862,
14,
981,
342,
267,
18946,
2927,
14,
981,
8,
751,
29,
277,
14,
5500,
12,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
9,
339,
347,
511,
63,
1807,
63,
5500,
63,
929,
63,
264,
2193,
63,
7107,
8,
277,
304,
267,
5160,
63,
1985,
275,
291,
14,
1972,
14,
344,
14,
1875,
63,
3807,
63,
498,
360,
5869,
297,
283,
578,
358,
398,
327,
2790,
282,
6474,
859,
367,
314,
922,
267,
17246,
2377,
14,
1462,
14,
981,
8,
288,
6474,
29,
277,
14,
5500,
12,
288,
2518,
63,
344,
29,
277,
14,
1972,
14,
344,
12,
288,
859,
63,
929,
63,
498,
29,
6462,
63,
1985,
12,
288,
1174,
29,
1001,
14,
4180,
14079,
267,
776,
398,
327,
2790,
282,
13071,
436,
5396,
367,
314,
6474,
1808,
314,
30399,
3261,
267,
6474,
63,
1053,
275,
469,
288,
283,
5500,
63,
344,
356,
16535,
63,
344,
63,
509,
63,
751,
8,
277,
14,
5500,
12,
291,
14,
1972,
14,
344,
395,
288,
283,
1972,
63,
344,
356,
291,
14,
1972,
14,
344,
14,
475,
63,
6667,
63,
875,
1062,
288,
283,
1053,
63,
344,
356,
5160,
63,
1985,
14,
475,
63,
6667,
63,
875,
1062,
288,
283,
1053,
63,
466,
356,
283,
1490,
17452,
7,
267,
789,
267,
13071,
275,
1007,
63,
1246,
14,
981,
63,
12542,
8,
5500,
63,
1053,
12,
283,
396,
6385,
358,
267,
1007,
63,
1246,
14,
409,
63,
3397,
8,
12542,
459,
2580,
995,
413,
12,
499,
9,
398,
327,
8496,
6474,
1174,
1808,
314,
17724,
11847,
267,
1166,
275,
3837,
360,
14891,
63,
9743,
63,
10000,
297,
2074,
3713,
1972,
63,
344,
356,
291,
14,
1972,
14,
344,
14,
475,
63,
6667,
63,
875,
22804,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
633,
12,
469,
288,
283,
1287,
356,
283,
5392,
6474,
1174,
367,
859,
297,
288,
283,
3235,
63,
5500,
63,
5364,
356,
291,
14,
5500,
14,
2123,
12,
288,
283,
6462,
63,
509,
63,
5500,
356,
5160,
63,
1985,
14,
475,
63,
6667,
63,
875,
1062,
267,
3828,
398,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
7635,
626,
314,
6474,
1159,
9342,
1172,
2757,
5305,
315,
314,
30399,
3261,
267,
5396,
275,
1007,
63,
1246,
14,
362,
63,
3397,
8,
5500,
63,
1053,
9,
267,
291,
14,
3436,
8,
3397,
12,
488,
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,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gandreello/openthread
|
tests/scripts/thread-cert/Cert_8_2_02_JoinerRouter.py
|
3
|
4557
|
#!/usr/bin/env python
#
# Copyright (c) 2016, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
import time
import unittest
import config
import node
COMMISSIONER = 1
JOINER_ROUTER = 2
JOINER = 3
class Cert_8_2_02_JoinerRouter(unittest.TestCase):
def setUp(self):
self.simulator = config.create_default_simulator()
self.nodes = {}
for i in range(1,4):
self.nodes[i] = node.Node(i, simulator=self.simulator)
self.nodes[COMMISSIONER].set_panid(0xface)
self.nodes[COMMISSIONER].set_mode('rsdn')
self.nodes[COMMISSIONER].set_masterkey('deadbeefdeadbeefdeadbeefdeadbeef')
self.nodes[COMMISSIONER].enable_whitelist()
self.nodes[COMMISSIONER].set_router_selection_jitter(1)
self.nodes[JOINER_ROUTER].set_mode('rsdn')
self.nodes[JOINER_ROUTER].set_masterkey('00112233445566778899aabbccddeeff')
self.nodes[JOINER_ROUTER].enable_whitelist()
self.nodes[JOINER_ROUTER].set_router_selection_jitter(1)
self.nodes[JOINER].set_mode('rsdn')
self.nodes[JOINER].set_masterkey('00112233445566778899aabbccddeeff')
self.nodes[JOINER].enable_whitelist()
self.nodes[JOINER].set_router_selection_jitter(1)
def tearDown(self):
for node in list(self.nodes.values()):
node.stop()
node.destroy()
self.simulator.stop()
def test(self):
self.nodes[COMMISSIONER].interface_up()
self.nodes[COMMISSIONER].thread_start()
self.simulator.go(5)
self.assertEqual(self.nodes[COMMISSIONER].get_state(), 'leader')
self.nodes[COMMISSIONER].commissioner_start()
self.simulator.go(5)
self.nodes[COMMISSIONER].commissioner_add_joiner(self.nodes[JOINER_ROUTER].get_eui64(), 'OPENTHREAD')
self.nodes[COMMISSIONER].commissioner_add_joiner(self.nodes[JOINER].get_eui64(), 'OPENTHREAD2')
self.simulator.go(5)
self.nodes[COMMISSIONER].add_whitelist(self.nodes[JOINER_ROUTER].get_joiner_id())
self.nodes[JOINER_ROUTER].add_whitelist(self.nodes[COMMISSIONER].get_addr64())
self.nodes[JOINER_ROUTER].interface_up()
self.nodes[JOINER_ROUTER].joiner_start('OPENTHREAD')
self.simulator.go(10)
self.assertEqual(self.nodes[JOINER_ROUTER].get_masterkey(), self.nodes[COMMISSIONER].get_masterkey())
self.nodes[COMMISSIONER].add_whitelist(self.nodes[JOINER_ROUTER].get_addr64())
self.nodes[JOINER_ROUTER].thread_start()
self.simulator.go(5)
self.assertEqual(self.nodes[JOINER_ROUTER].get_state(), 'router')
self.nodes[JOINER_ROUTER].add_whitelist(self.nodes[JOINER].get_joiner_id())
self.nodes[JOINER].add_whitelist(self.nodes[JOINER_ROUTER].get_addr64())
self.nodes[JOINER].interface_up()
self.nodes[JOINER].joiner_start('2DAERHTNEPO')
self.simulator.go(10)
self.assertNotEqual(self.nodes[JOINER].get_masterkey(), self.nodes[COMMISSIONER].get_masterkey())
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
7800,
12,
710,
3232,
4436,
6642,
14,
199,
3,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
221,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
199,
3,
258,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
221,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
221,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
221,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
199,
3,
221,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
221,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
221,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
221,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
221,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
221,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
221,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
900,
199,
646,
2882,
199,
199,
646,
1101,
199,
646,
1031,
199,
199,
5378,
20291,
540,
275,
413,
199,
23321,
540,
63,
19281,
275,
499,
199,
23321,
540,
275,
650,
199,
199,
533,
11002,
84,
63,
24,
63,
18,
63,
996,
63,
13005,
281,
11691,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20125,
275,
1101,
14,
981,
63,
885,
63,
20125,
342,
398,
291,
14,
2415,
275,
1052,
267,
367,
284,
315,
1425,
8,
17,
12,
20,
304,
288,
291,
14,
2415,
59,
73,
61,
275,
1031,
14,
1716,
8,
73,
12,
15797,
29,
277,
14,
20125,
9,
398,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
10384,
344,
8,
16,
88,
1409,
9,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
632,
360,
2393,
4272,
358,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
4133,
498,
360,
10957,
19446,
70,
10957,
19446,
70,
10957,
19446,
70,
10957,
19446,
70,
358,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
4296,
63,
14189,
342,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
4995,
63,
5592,
63,
17676,
351,
8,
17,
9,
398,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
409,
63,
632,
360,
2393,
4272,
358,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
409,
63,
4133,
498,
360,
4587,
713,
1789,
10875,
1229,
1272,
1138,
1299,
1020,
65,
12198,
2055,
10282,
3609,
358,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
4296,
63,
14189,
342,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
409,
63,
4995,
63,
5592,
63,
17676,
351,
8,
17,
9,
398,
291,
14,
2415,
59,
23321,
540,
1055,
409,
63,
632,
360,
2393,
4272,
358,
267,
291,
14,
2415,
59,
23321,
540,
1055,
409,
63,
4133,
498,
360,
4587,
713,
1789,
10875,
1229,
1272,
1138,
1299,
1020,
65,
12198,
2055,
10282,
3609,
358,
267,
291,
14,
2415,
59,
23321,
540,
1055,
4296,
63,
14189,
342,
267,
291,
14,
2415,
59,
23321,
540,
1055,
409,
63,
4995,
63,
5592,
63,
17676,
351,
8,
17,
9,
339,
347,
6766,
8,
277,
304,
267,
367,
1031,
315,
769,
8,
277,
14,
2415,
14,
1459,
5109,
288,
1031,
14,
2379,
342,
288,
1031,
14,
7237,
342,
267,
291,
14,
20125,
14,
2379,
342,
339,
347,
511,
8,
277,
304,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
3266,
63,
384,
342,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
2671,
63,
928,
342,
267,
291,
14,
20125,
14,
1939,
8,
21,
9,
267,
291,
14,
629,
8,
277,
14,
2415,
59,
5378,
20291,
540,
1055,
362,
63,
929,
1062,
283,
18498,
358,
398,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
1404,
27973,
281,
63,
928,
342,
267,
291,
14,
20125,
14,
1939,
8,
21,
9,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
1404,
27973,
281,
63,
525,
63,
904,
281,
8,
277,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
362,
63,
69,
1907,
772,
1062,
283,
1938,
1309,
40,
5670,
358,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
1404,
27973,
281,
63,
525,
63,
904,
281,
8,
277,
14,
2415,
59,
23321,
540,
1055,
362,
63,
69,
1907,
772,
1062,
283,
1938,
1309,
40,
5670,
18,
358,
267,
291,
14,
20125,
14,
1939,
8,
21,
9,
398,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
525,
63,
14189,
8,
277,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
362,
63,
904,
281,
63,
344,
1012,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
525,
63,
14189,
8,
277,
14,
2415,
59,
5378,
20291,
540,
1055,
362,
63,
2697,
772,
1012,
398,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
3266,
63,
384,
342,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
904,
281,
63,
928,
360,
1938,
1309,
40,
5670,
358,
267,
291,
14,
20125,
14,
1939,
8,
709,
9,
267,
291,
14,
629,
8,
277,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
7800,
12,
710,
3232,
4436,
6642,
14,
199,
3,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
258,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
221,
650,
14,
11443,
314,
536,
402,
314,
4248,
16712,
6590,
314,
199,
3,
258,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
199,
3,
258,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
221,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
221,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
221,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
199,
3,
221,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
221,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
221,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
221,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
221,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
221,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
221,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
900,
199,
646,
2882,
199,
199,
646,
1101,
199,
646,
1031,
199,
199,
5378,
20291,
540,
275,
413,
199,
23321,
540,
63,
19281,
275,
499,
199,
23321,
540,
275,
650,
199,
199,
533,
11002,
84,
63,
24,
63,
18,
63,
996,
63,
13005,
281,
11691,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
20125,
275,
1101,
14,
981,
63,
885,
63,
20125,
342,
398,
291,
14,
2415,
275,
1052,
267,
367,
284,
315,
1425,
8,
17,
12,
20,
304,
288,
291,
14,
2415,
59,
73,
61,
275,
1031,
14,
1716,
8,
73,
12,
15797,
29,
277,
14,
20125,
9,
398,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
10384,
344,
8,
16,
88,
1409,
9,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
632,
360,
2393,
4272,
358,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
4133,
498,
360,
10957,
19446,
70,
10957,
19446,
70,
10957,
19446,
70,
10957,
19446,
70,
358,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
4296,
63,
14189,
342,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
409,
63,
4995,
63,
5592,
63,
17676,
351,
8,
17,
9,
398,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
409,
63,
632,
360,
2393,
4272,
358,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
409,
63,
4133,
498,
360,
4587,
713,
1789,
10875,
1229,
1272,
1138,
1299,
1020,
65,
12198,
2055,
10282,
3609,
358,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
4296,
63,
14189,
342,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
409,
63,
4995,
63,
5592,
63,
17676,
351,
8,
17,
9,
398,
291,
14,
2415,
59,
23321,
540,
1055,
409,
63,
632,
360,
2393,
4272,
358,
267,
291,
14,
2415,
59,
23321,
540,
1055,
409,
63,
4133,
498,
360,
4587,
713,
1789,
10875,
1229,
1272,
1138,
1299,
1020,
65,
12198,
2055,
10282,
3609,
358,
267,
291,
14,
2415,
59,
23321,
540,
1055,
4296,
63,
14189,
342,
267,
291,
14,
2415,
59,
23321,
540,
1055,
409,
63,
4995,
63,
5592,
63,
17676,
351,
8,
17,
9,
339,
347,
6766,
8,
277,
304,
267,
367,
1031,
315,
769,
8,
277,
14,
2415,
14,
1459,
5109,
288,
1031,
14,
2379,
342,
288,
1031,
14,
7237,
342,
267,
291,
14,
20125,
14,
2379,
342,
339,
347,
511,
8,
277,
304,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
3266,
63,
384,
342,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
2671,
63,
928,
342,
267,
291,
14,
20125,
14,
1939,
8,
21,
9,
267,
291,
14,
629,
8,
277,
14,
2415,
59,
5378,
20291,
540,
1055,
362,
63,
929,
1062,
283,
18498,
358,
398,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
1404,
27973,
281,
63,
928,
342,
267,
291,
14,
20125,
14,
1939,
8,
21,
9,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
1404,
27973,
281,
63,
525,
63,
904,
281,
8,
277,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
362,
63,
69,
1907,
772,
1062,
283,
1938,
1309,
40,
5670,
358,
267,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
1404,
27973,
281,
63,
525,
63,
904,
281,
8,
277,
14,
2415,
59,
23321,
540,
1055,
362,
63,
69,
1907,
772,
1062,
283,
1938,
1309,
40,
5670,
18,
358,
267,
291,
14,
20125,
14,
1939,
8,
21,
9,
398,
291,
14,
2415,
59,
5378,
20291,
540,
1055,
525,
63,
14189,
8,
277,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
362,
63,
904,
281,
63,
344,
1012,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
525,
63,
14189,
8,
277,
14,
2415,
59,
5378,
20291,
540,
1055,
362,
63,
2697,
772,
1012,
398,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
3266,
63,
384,
342,
267,
291,
14,
2415,
59,
23321,
540,
63,
19281,
1055,
904,
281,
63,
928,
360,
1938,
1309,
40,
5670,
358,
267,
291,
14,
20125,
14,
1939,
8,
709,
9,
267,
291,
14,
629,
8,
277,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
divegeek/keyczar
|
cpp/src/tools/swtoolkit/test/environment_tools_test.py
|
18
|
10313
|
#!/usr/bin/python2.4
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Test for environment_tools. These are SMALL and MEDIUM tests."""
import os
import unittest
import TestFramework
class EnvToolsTests(unittest.TestCase):
"""Tests for environment_tools module."""
def setUp(self):
"""Per-test setup."""
self.env = self.root_env.Clone()
def testFilterOut(self):
"""Test FilterOut()."""
env = self.env
env.Replace(
TEST1=['ant', 'bear', 'cat'],
TEST2=[1, 2, 3, 4],
)
# Simple filter
env.FilterOut(TEST1=['bear'])
self.assertEqual(env['TEST1'], ['ant', 'cat'])
# Filter multiple
env.FilterOut(TEST1=['ant'], TEST2=[1, 3])
self.assertEqual(env['TEST1'], ['cat'])
self.assertEqual(env['TEST2'], [2, 4])
# Filter doesn't care if the variable or value doesn't exist
env.FilterOut(TEST1=['dog'], TEST3=[2])
self.assertEqual(env['TEST1'], ['cat'])
self.assertEqual(env['TEST2'], [2, 4])
def testFilterOutRepeated(self):
"""Test FilterOut() filters all matches."""
env = self.env
env['TEST3'] = ['A', 'B', 'B', 'C']
env.FilterOut(TEST3=['B'])
self.assertEqual(env['TEST3'], ['A', 'C'])
def testFilterOutNested(self):
"""Test FilterOut on nested lists."""
env = self.env
# FilterOut does not currently flatten lists, nor remove values from
# sub-lists. This is related to not evaluating environment variables (see
# below).
env['TEST4'] = ['A', ['B', 'C'], 'D']
env.FilterOut(TEST4=['B'])
self.assertEqual(env['TEST4'], ['A', ['B', 'C'], 'D'])
# If you specify the entire sub-list, it will be filtered
env.FilterOut(TEST4=[['B', 'C']])
self.assertEqual(env['TEST4'], ['A', 'D'])
def testFilterOutNoEval(self):
"""Test FilterOut does not evaluate variables in the list."""
env = self.env
# FilterOut does not evaluate variables in the list. (Doing so would
# defeat much of the purpose of variables.) Note that this means it does
# not filter variables which evaluate partially or wholly to the filtered
# string. On the plus side, this means you CAN filter out variables.
env.Replace(
TEST5=['$V1', '$V2', '$V3', '$V4'],
V1='A',
# (V2 intentionally undefined at this point)
V3=['A', 'B'],
V4='C',
)
env.FilterOut(TEST5=['A', '$V4'])
self.assertEqual(env['TEST5'], ['$V1', '$V2', '$V3'])
def testOverlap(self):
"""Test Overlap()."""
env = self.env
env.Replace(
OLVAR='baz',
OLLIST=['2', '3', '4'],
)
# Simple string compares
self.assertEqual(env.Overlap('foo', 'foo'), ['foo'])
self.assertEqual(env.Overlap('foo', 'food'), [])
# String compare with variable substitution
self.assertEqual(env.Overlap('foobaz', 'foo$OLVAR'), ['foobaz'])
# Simple list overlap
# Need to use set() for comparison, since the order of entries in the
# output list is indeterminate
self.assertEqual(set(env.Overlap(['1', '2', '3'], ['2', '3', '4'])),
set(['2', '3']))
# Overlap removes duplicates
self.assertEqual(env.Overlap(['1', '2', '2'], ['2', '3', '2']), ['2'])
# List and string
self.assertEqual(env.Overlap('3', ['1', '2', '3']), ['3'])
self.assertEqual(env.Overlap('4', ['1', '2', '3']), [])
self.assertEqual(env.Overlap(['1', '$OLVAR', '3'], '$OLVAR'), ['baz'])
# Variable substitition will replace and flatten lists
self.assertEqual(set(env.Overlap(['1', '2', '3'], '$OLLIST')),
set(['2', '3']))
# Substitution flattens lists
self.assertEqual(set(env.Overlap([['1', '2'], '3'], ['2', ['3', '4']])),
set(['2', '3']))
def testSubstList2(self):
"""Test SubstList2()."""
env = self.env
# Empty args should return empty list
self.assertEqual(env.SubstList2(), [])
# Undefined variable also returns empty list
self.assertEqual(env.SubstList2('$NO_SUCH_VAR'), [])
# Simple substitution (recursively evaluates variables)
env['STR1'] = 'FOO$STR2'
env['STR2'] = 'BAR'
self.assertEqual(env.SubstList2('$STR1'), ['FOOBAR'])
# Simple list substitution
env['LIST1'] = ['A', 'B']
self.assertEqual(env.SubstList2('$LIST1'), ['A', 'B'])
# Nested lists
env['LIST2'] = ['C', '$LIST1']
self.assertEqual(env.SubstList2('$LIST2'), ['C', 'A', 'B'])
# Multiple variables in a single entry stay a single entry
self.assertEqual(env.SubstList2('$STR1 $STR2'), ['FOOBAR BAR'])
# Multiple args to command
self.assertEqual(env.SubstList2('$LIST2', '$STR2'), ['C', 'A', 'B', 'BAR'])
# Items in list are actually strings, not some subclass
self.assert_(type(env.SubstList2('$STR1')[0]) is str)
def testRelativePath(self):
"""Test RelativePath()."""
env = self.env
# Trivial cases - directory or file relative to itself
self.assertEqual(env.RelativePath('a', 'a'), '.')
self.assertEqual(env.RelativePath('a/b/c', 'a/b/c'), '.')
self.assertEqual(env.RelativePath('a', 'a', source_is_file=True), 'a')
self.assertEqual(env.RelativePath('a/b/c', 'a/b/c', source_is_file=True),
'c')
# Can pass in directory or file nodes
self.assertEqual(env.RelativePath(env.Dir('a'), env.File('b/c'), sep='/'),
'../b/c')
# Separator argument is respected
self.assertEqual(env.RelativePath('.', 'a/b/c', sep='BOOGA'),
'aBOOGAbBOOGAc')
# Default separator is os.sep
self.assertEqual(env.RelativePath('.', 'a/b'),
'a' + os.sep + 'b')
# No common dirs
self.assertEqual(env.RelativePath('a/b/c', 'd/e/f', sep='/'),
'../../../d/e/f')
self.assertEqual(
env.RelativePath('a/b/c', 'd/e/f', sep='/', source_is_file=True),
'../../d/e/f')
# Common dirs
self.assertEqual(env.RelativePath('a/b/c/d', 'a/b/e/f', sep='/'),
'../../e/f')
# Source or destination path is different length
self.assertEqual(env.RelativePath('a/b/c/d', 'a/b', sep='/'), '../..')
self.assertEqual(env.RelativePath('a/b', 'a/b/c/d', sep='/'), 'c/d')
# Current directory on either side
self.assertEqual(env.RelativePath('a/b/c', '.', sep='/'), '../../..')
self.assertEqual(env.RelativePath('.', 'a/b/c', sep='/'), 'a/b/c')
# Variables are evaluated
env.Replace(
DIR1='foo',
DIR2='bar',
)
self.assertEqual(env.RelativePath('foo/$DIR2/a', '$DIR1/bar/b', sep='/'),
'../b')
def testApplyBuildSConscript(self):
"""Test ApplySConscript() and BuildSConscript() (MEDIUM test)."""
env = self.env
env['SUB1'] = 'nougat'
# ApplySConscript() affects the calling environment
env.ApplySConscript('SConscript1')
self.assertEqual(env.get('SUB2'), 'orange')
# BuildSConscript() does not affect the calling environment
env.BuildSConscript('SConscript2')
self.assertEqual(env.get('SUB2'), 'orange')
# BuildSConscript finds build.scons in preference to SConscript
env.BuildSConscript('abs1')
# But does look for SConscript if there isn't build.scons
env.BuildSConscript('abs2')
def TestSConstruct(scons_globals):
"""Test SConstruct file.
Args:
scons_globals: Global variables dict from the SConscript file.
"""
# Get globals from SCons
Environment = scons_globals['Environment']
env = Environment(tools=['environment_tools'])
# Run unit tests
TestFramework.RunUnitTests(EnvToolsTests, root_env=env)
sconscript1_contents = """
Import('env')
if env.get('SUB1') != 'nougat':
raise ValueError('ApplySConscript() failure in sconscript1')
env['SUB2'] = 'orange'
"""
sconscript2_contents = """
Import('env')
if env.get('SUB1') != 'nougat':
raise ValueError('BuildSConscript() failure in sconscript2')
env['SUB2'] = 'pizza'
"""
sconscript3_contents = """
Import('env')
filename = '%s'
env.Execute(Touch(filename))
"""
def main():
test = TestFramework.TestFramework()
test.subdir('environment_tools')
base = 'environment_tools/'
test.WriteSConscript(base + 'SConstruct', TestSConstruct)
test.write(base + 'SConscript1', sconscript1_contents)
test.write(base + 'SConscript2', sconscript2_contents)
test.subdir(base + 'abs1')
test.write(base + 'abs1/build.scons', sconscript3_contents % 'yes1')
test.write(base + 'abs1/SConscript', sconscript3_contents % 'no')
test.subdir(base + 'abs2')
test.write(base + 'abs2/SConscript', sconscript3_contents % 'yes2')
# Ignore stderr since unittest prints its output there
test.run(chdir=base, stderr=None)
test.must_exist(base + 'abs1/yes1')
test.must_not_exist(base + 'abs1/no')
test.must_exist(base + 'abs2/yes2')
test.pass_test()
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
774,
367,
3734,
63,
2537,
14,
221,
5723,
787,
2516,
436,
22650,
2295,
1041,
421,
199,
646,
747,
199,
646,
2882,
199,
646,
1379,
16442,
421,
199,
533,
31543,
11654,
2925,
8,
2796,
14,
1746,
304,
523,
408,
2925,
367,
3734,
63,
2537,
859,
1041,
819,
347,
3613,
8,
277,
304,
272,
408,
2623,
13,
396,
3272,
1041,
272,
291,
14,
1813,
275,
291,
14,
1231,
63,
1813,
14,
21222,
342,
819,
347,
511,
4131,
2204,
8,
277,
304,
272,
408,
774,
9388,
2204,
20693,
272,
2589,
275,
291,
14,
1813,
272,
2589,
14,
11328,
8,
267,
7393,
17,
2968,
867,
297,
283,
31796,
297,
283,
3385,
995,
267,
7393,
18,
1524,
17,
12,
499,
12,
650,
12,
841,
467,
272,
776,
339,
327,
5870,
2457,
272,
2589,
14,
4131,
2204,
8,
2864,
17,
2968,
31796,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
17,
995,
788,
867,
297,
283,
3385,
1105,
339,
327,
9388,
3663,
272,
2589,
14,
4131,
2204,
8,
2864,
17,
2968,
867,
995,
7393,
18,
1524,
17,
12,
650,
566,
272,
291,
14,
629,
8,
1813,
459,
2864,
17,
995,
788,
3385,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
18,
995,
359,
18,
12,
841,
566,
339,
327,
9388,
3181,
1133,
10296,
340,
314,
1750,
503,
574,
3181,
1133,
2187,
272,
2589,
14,
4131,
2204,
8,
2864,
17,
2968,
13889,
995,
7393,
19,
1524,
18,
566,
272,
291,
14,
629,
8,
1813,
459,
2864,
17,
995,
788,
3385,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
18,
995,
359,
18,
12,
841,
566,
819,
347,
511,
4131,
2204,
19390,
8,
277,
304,
272,
408,
774,
9388,
2204,
342,
4766,
1006,
4450,
1041,
272,
2589,
275,
291,
14,
1813,
272,
2589,
459,
2864,
19,
418,
275,
788,
33,
297,
283,
34,
297,
283,
34,
297,
283,
35,
418,
272,
2589,
14,
4131,
2204,
8,
2864,
19,
2968,
34,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
19,
995,
788,
33,
297,
283,
35,
1105,
819,
347,
511,
4131,
2204,
13029,
8,
277,
304,
272,
408,
774,
9388,
2204,
641,
6032,
5548,
1041,
272,
2589,
275,
291,
14,
1813,
272,
327,
9388,
2204,
1630,
440,
5544,
9378,
5548,
12,
6590,
2813,
1338,
687,
272,
327,
1007,
13,
6717,
14,
221,
961,
365,
4048,
370,
440,
27083,
3734,
2860,
334,
3239,
272,
327,
5084,
680,
272,
2589,
459,
2864,
20,
418,
275,
788,
33,
297,
788,
34,
297,
283,
35,
995,
283,
36,
418,
272,
2589,
14,
4131,
2204,
8,
2864,
20,
2968,
34,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
20,
995,
788,
33,
297,
788,
34,
297,
283,
35,
995,
283,
36,
1105,
272,
327,
982,
1265,
4165,
314,
8039,
1007,
13,
513,
12,
652,
911,
506,
9806,
272,
2589,
14,
4131,
2204,
8,
2864,
20,
1524,
459,
34,
297,
283,
35,
12121,
272,
291,
14,
629,
8,
1813,
459,
2864,
20,
995,
788,
33,
297,
283,
36,
1105,
819,
347,
511,
4131,
2204,
1944,
10006,
8,
277,
304,
272,
408,
774,
9388,
2204,
1630,
440,
9352,
2860,
315,
314,
769,
1041,
272,
2589,
275,
291,
14,
1813,
272,
327,
9388,
2204,
1630,
440,
9352,
2860,
315,
314,
769,
14,
221,
334,
2585,
316,
880,
3955,
272,
327,
347,
69,
292,
8298,
402,
314,
12016,
402,
2860,
4959,
221,
3390,
626,
642,
4910,
652,
1630,
272,
327,
440,
2457,
2860,
1314,
9352,
25172,
503,
704,
393,
590,
370,
314,
9806,
272,
327,
1059,
14,
221,
4068,
314,
12254,
5366,
12,
642,
4910,
1265,
29661,
2457,
734,
2860,
14,
272,
2589,
14,
11328,
8,
267,
7393,
21,
2968,
4,
54,
17,
297,
4505,
54,
18,
297,
4505,
54,
19,
297,
4505,
54,
20,
995,
267,
812,
17,
534,
33,
297,
267,
327,
334,
54,
18,
32005,
10942,
737,
642,
2376,
9,
267,
812,
19,
2968,
33,
297,
283,
34,
995,
267,
812,
20,
534,
35,
297,
272,
776,
272,
2589,
14,
4131,
2204,
8,
2864,
21,
2968,
33,
297,
4505,
54,
20,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
21,
995,
788,
4,
54,
17,
297,
4505,
54,
18,
297,
4505,
54,
19,
1105,
819,
347,
511,
28709,
8,
277
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
774,
367,
3734,
63,
2537,
14,
221,
5723,
787,
2516,
436,
22650,
2295,
1041,
421,
199,
646,
747,
199,
646,
2882,
199,
646,
1379,
16442,
421,
199,
533,
31543,
11654,
2925,
8,
2796,
14,
1746,
304,
523,
408,
2925,
367,
3734,
63,
2537,
859,
1041,
819,
347,
3613,
8,
277,
304,
272,
408,
2623,
13,
396,
3272,
1041,
272,
291,
14,
1813,
275,
291,
14,
1231,
63,
1813,
14,
21222,
342,
819,
347,
511,
4131,
2204,
8,
277,
304,
272,
408,
774,
9388,
2204,
20693,
272,
2589,
275,
291,
14,
1813,
272,
2589,
14,
11328,
8,
267,
7393,
17,
2968,
867,
297,
283,
31796,
297,
283,
3385,
995,
267,
7393,
18,
1524,
17,
12,
499,
12,
650,
12,
841,
467,
272,
776,
339,
327,
5870,
2457,
272,
2589,
14,
4131,
2204,
8,
2864,
17,
2968,
31796,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
17,
995,
788,
867,
297,
283,
3385,
1105,
339,
327,
9388,
3663,
272,
2589,
14,
4131,
2204,
8,
2864,
17,
2968,
867,
995,
7393,
18,
1524,
17,
12,
650,
566,
272,
291,
14,
629,
8,
1813,
459,
2864,
17,
995,
788,
3385,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
18,
995,
359,
18,
12,
841,
566,
339,
327,
9388,
3181,
1133,
10296,
340,
314,
1750,
503,
574,
3181,
1133,
2187,
272,
2589,
14,
4131,
2204,
8,
2864,
17,
2968,
13889,
995,
7393,
19,
1524,
18,
566,
272,
291,
14,
629,
8,
1813,
459,
2864,
17,
995,
788,
3385,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
18,
995,
359,
18,
12,
841,
566,
819,
347,
511,
4131,
2204,
19390,
8,
277,
304,
272,
408,
774,
9388,
2204,
342,
4766,
1006,
4450,
1041,
272,
2589,
275,
291,
14,
1813,
272,
2589,
459,
2864,
19,
418,
275,
788,
33,
297,
283,
34,
297,
283,
34,
297,
283,
35,
418,
272,
2589,
14,
4131,
2204,
8,
2864,
19,
2968,
34,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
19,
995,
788,
33,
297,
283,
35,
1105,
819,
347,
511,
4131,
2204,
13029,
8,
277,
304,
272,
408,
774,
9388,
2204,
641,
6032,
5548,
1041,
272,
2589,
275,
291,
14,
1813,
272,
327,
9388,
2204,
1630,
440,
5544,
9378,
5548,
12,
6590,
2813,
1338,
687,
272,
327,
1007,
13,
6717,
14,
221,
961,
365,
4048,
370,
440,
27083,
3734,
2860,
334,
3239,
272,
327,
5084,
680,
272,
2589,
459,
2864,
20,
418,
275,
788,
33,
297,
788,
34,
297,
283,
35,
995,
283,
36,
418,
272,
2589,
14,
4131,
2204,
8,
2864,
20,
2968,
34,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
20,
995,
788,
33,
297,
788,
34,
297,
283,
35,
995,
283,
36,
1105,
272,
327,
982,
1265,
4165,
314,
8039,
1007,
13,
513,
12,
652,
911,
506,
9806,
272,
2589,
14,
4131,
2204,
8,
2864,
20,
1524,
459,
34,
297,
283,
35,
12121,
272,
291,
14,
629,
8,
1813,
459,
2864,
20,
995,
788,
33,
297,
283,
36,
1105,
819,
347,
511,
4131,
2204,
1944,
10006,
8,
277,
304,
272,
408,
774,
9388,
2204,
1630,
440,
9352,
2860,
315,
314,
769,
1041,
272,
2589,
275,
291,
14,
1813,
272,
327,
9388,
2204,
1630,
440,
9352,
2860,
315,
314,
769,
14,
221,
334,
2585,
316,
880,
3955,
272,
327,
347,
69,
292,
8298,
402,
314,
12016,
402,
2860,
4959,
221,
3390,
626,
642,
4910,
652,
1630,
272,
327,
440,
2457,
2860,
1314,
9352,
25172,
503,
704,
393,
590,
370,
314,
9806,
272,
327,
1059,
14,
221,
4068,
314,
12254,
5366,
12,
642,
4910,
1265,
29661,
2457,
734,
2860,
14,
272,
2589,
14,
11328,
8,
267,
7393,
21,
2968,
4,
54,
17,
297,
4505,
54,
18,
297,
4505,
54,
19,
297,
4505,
54,
20,
995,
267,
812,
17,
534,
33,
297,
267,
327,
334,
54,
18,
32005,
10942,
737,
642,
2376,
9,
267,
812,
19,
2968,
33,
297,
283,
34,
995,
267,
812,
20,
534,
35,
297,
272,
776,
272,
2589,
14,
4131,
2204,
8,
2864,
21,
2968,
33,
297,
4505,
54,
20,
1105,
272,
291,
14,
629,
8,
1813,
459,
2864,
21,
995,
788,
4,
54,
17,
297,
4505,
54,
18,
297,
4505,
54,
19,
1105,
819,
347,
511,
28709,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
manjunaths/tensorflow
|
tensorflow/contrib/framework/python/ops/arg_scope_test.py
|
115
|
7232
|
# 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.
# ==============================================================================
"""arg_scope tests."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.framework.python.ops import add_arg_scope
from tensorflow.contrib.framework.python.ops import arg_scope
from tensorflow.contrib.framework.python.ops import arg_scoped_arguments
from tensorflow.python.platform import test
@add_arg_scope
def func1(*args, **kwargs):
return (args, kwargs)
@add_arg_scope
def func2(*args, **kwargs):
return (args, kwargs)
@add_arg_scope
def func3(args, a=None, b=1, c=2):
"""Some cool doc string."""
return (args, a, b, c)
def _key_op(op):
return getattr(op, '_key_op', str(op))
class ArgScopeTest(test.TestCase):
def testEmptyArgScope(self):
with self.test_session():
with arg_scope([]) as sc:
self.assertEqual(sc, {})
def testClearArgScope(self):
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
key_op = _key_op(func1)
func1_scope = {key_op: func1_kwargs.copy()}
with self.test_session():
with arg_scope([func1], a=1, b=None, c=[1]) as sc1:
self.assertEqual(sc1, func1_scope)
with arg_scope({}) as sc2:
self.assertEqual(sc2, {})
with arg_scope([]) as current_arg_scope:
self.assertEqual(current_arg_scope, func1_scope)
def testNonDecorated(self):
def my_func(t, a=None):
return (t, a)
with self.assertRaises(ValueError):
with arg_scope([my_func], a=1):
pass
def testUnexpectedArg(self):
with self.assertRaises(TypeError):
with arg_scope([func3], d=1):
func3(1)
def testCurrentArgScope(self):
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
key_op = _key_op(func1)
current_scope = {key_op: func1_kwargs.copy()}
with self.test_session():
with arg_scope([func1], a=1, b=None, c=[1]) as scope:
self.assertDictEqual(scope, current_scope)
def testArgScopedArguments(self):
func3_kwargs = ('a', 'b', 'c')
self.assertEquals(arg_scoped_arguments(func3), func3_kwargs)
def testCurrentArgScopeNested(self):
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
func2_kwargs = {'b': 2, 'd': [2]}
key = _key_op
current_scope = {
key(func1): func1_kwargs.copy(),
key(func2): func2_kwargs.copy()
}
with self.test_session():
with arg_scope([func1], a=1, b=None, c=[1]):
with arg_scope([func2], b=2, d=[2]) as scope:
self.assertDictEqual(scope, current_scope)
def testReuseArgScope(self):
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
key_op = _key_op(func1)
current_scope = {key_op: func1_kwargs.copy()}
with self.test_session():
with arg_scope([func1], a=1, b=None, c=[1]) as scope1:
pass
with arg_scope(scope1) as scope:
self.assertDictEqual(scope, current_scope)
def testReuseArgScopeNested(self):
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
func2_kwargs = {'b': 2, 'd': [2]}
key = _key_op
current_scope1 = {key(func1): func1_kwargs.copy()}
current_scope2 = {
key(func1): func1_kwargs.copy(),
key(func2): func2_kwargs.copy()
}
with self.test_session():
with arg_scope([func1], a=1, b=None, c=[1]) as scope1:
with arg_scope([func2], b=2, d=[2]) as scope2:
pass
with arg_scope(scope1):
with arg_scope([]) as current_arg_scope:
self.assertDictEqual(current_arg_scope, current_scope1)
with arg_scope(scope2):
with arg_scope([]) as current_arg_scope:
self.assertDictEqual(current_arg_scope, current_scope2)
def testSimpleArgScope(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
with self.test_session():
with arg_scope([func1], a=1, b=None, c=[1]):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
def testSimpleArgScopeWithTuple(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
with self.test_session():
with arg_scope((func1,), a=1, b=None, c=[1]):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
def testOverwriteArgScope(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': 2, 'c': [1]}
with arg_scope([func1], a=1, b=None, c=[1]):
args, kwargs = func1(0, b=2)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
def testNestedArgScope(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
with arg_scope([func1], a=1, b=None, c=[1]):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
func1_kwargs['b'] = 2
with arg_scope([func1], b=2):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
def testSharedArgScope(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
with arg_scope([func1, func2], a=1, b=None, c=[1]):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
args, kwargs = func2(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
def testSharedArgScopeTuple(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
with arg_scope((func1, func2), a=1, b=None, c=[1]):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
args, kwargs = func2(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
def testPartiallySharedArgScope(self):
func1_args = (0,)
func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
func2_args = (1,)
func2_kwargs = {'a': 1, 'b': None, 'd': [2]}
with arg_scope([func1, func2], a=1, b=None):
with arg_scope([func1], c=[1]):
with arg_scope([func2], d=[2]):
args, kwargs = func1(0)
self.assertTupleEqual(args, func1_args)
self.assertDictEqual(kwargs, func1_kwargs)
args, kwargs = func2(1)
self.assertTupleEqual(args, func2_args)
self.assertDictEqual(kwargs, func2_kwargs)
def testDocString(self):
self.assertEqual(func3.__doc__, 'Some cool doc string.')
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,
1273,
63,
2645,
2295,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1050,
63,
1273,
63,
2645,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1680,
63,
2645,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1680,
63,
23254,
63,
4958,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
32,
525,
63,
1273,
63,
2645,
199,
318,
2562,
17,
2031,
589,
12,
1011,
958,
304,
523,
372,
334,
589,
12,
2074,
9,
421,
199,
32,
525,
63,
1273,
63,
2645,
199,
318,
2562,
18,
2031,
589,
12,
1011,
958,
304,
523,
372,
334,
589,
12,
2074,
9,
421,
199,
32,
525,
63,
1273,
63,
2645,
199,
318,
2562,
19,
8,
589,
12,
282,
29,
403,
12,
330,
29,
17,
12,
286,
29,
18,
304,
523,
408,
7700,
32268,
1382,
1059,
1041,
523,
372,
334,
589,
12,
282,
12,
330,
12,
286,
9,
421,
199,
318,
485,
498,
63,
411,
8,
411,
304,
523,
372,
2519,
8,
411,
12,
2513,
498,
63,
411,
297,
620,
8,
411,
430,
421,
199,
533,
29560,
7812,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
4699,
6373,
7812,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
4157,
465,
4061,
26,
267,
291,
14,
629,
8,
551,
12,
5009,
819,
347,
511,
9721,
6373,
7812,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
790,
63,
411,
275,
485,
498,
63,
411,
8,
1532,
17,
9,
272,
2562,
17,
63,
2645,
275,
469,
498,
63,
411,
26,
2562,
17,
63,
958,
14,
1574,
12737,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
17,
12,
330,
29,
403,
12,
286,
1524,
17,
566,
465,
4061,
17,
26,
267,
291,
14,
629,
8,
551,
17,
12,
2562,
17,
63,
2645,
9,
267,
543,
1680,
63,
2645,
14079,
465,
4061,
18,
26,
881,
291,
14,
629,
8,
551,
18,
12,
5009,
267,
543,
1680,
63,
2645,
4157,
465,
1453,
63,
1273,
63,
2645,
26,
881,
291,
14,
629,
8,
1818,
63,
1273,
63,
2645,
12,
2562,
17,
63,
2645,
9,
819,
347,
511,
6932,
8584,
269,
972,
8,
277,
304,
339,
347,
3002,
63,
1532,
8,
84,
12,
282,
29,
403,
304,
489,
372,
334,
84,
12,
282,
9,
339,
543,
291,
14,
1855,
8,
3393,
304,
489,
543,
1680,
63,
2645,
779,
1662,
63,
1532,
467,
282,
29,
17,
304,
267,
986,
819,
347,
511,
8708,
6373,
8,
277,
304,
272,
543,
291,
14,
1855,
8,
4333,
304,
489,
543,
1680,
63,
2645,
779,
1532,
19,
467,
366,
29,
17,
304,
267,
2562,
19,
8,
17,
9,
819,
347,
511,
5639,
6373,
7812,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
790,
63,
411,
275,
485,
498,
63,
411,
8,
1532,
17,
9,
272,
1453,
63,
2645,
275,
469,
498,
63,
411,
26,
2562,
17,
63,
958,
14,
1574,
12737,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
17,
12,
330,
29,
403,
12,
286,
1524,
17,
566,
465,
4194,
26,
267,
291,
14,
19512,
8,
2645,
12,
1453,
63,
2645,
9,
819,
347,
511,
6373,
7812,
68,
14517,
8,
277,
304,
272,
2562,
19,
63,
958,
275,
661,
65,
297,
283,
66,
297,
283,
67,
358,
272,
291,
14,
2947,
8,
1273,
63,
23254,
63,
4958,
8,
1532,
19,
395,
2562,
19,
63,
958,
9,
819,
347,
511,
5639,
6373,
7812,
13029,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
2562,
18,
63,
958,
275,
791,
66,
356,
499,
12,
283,
68,
356,
359,
18,
9420,
272,
790,
275,
485,
498,
63,
411,
272,
1453,
63,
2645,
275,
469,
267,
790,
8,
1532,
17,
304,
2562,
17,
63,
958,
14,
1574,
1062,
267,
790,
8,
1532,
18,
304,
2562,
18,
63,
958,
14,
1574,
342,
272,
789,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
17,
12,
330,
29,
403,
12,
286,
1524,
17,
4682,
267,
543,
1680,
63,
2645,
779,
1532,
18,
467,
330,
29,
18,
12,
366,
1524,
18,
566,
465,
4194,
26,
881,
291,
14,
19512,
8,
2645,
12,
1453,
63,
2645,
9,
819,
347,
511,
497,
1180,
6373,
7812,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
790,
63,
411,
275,
485,
498,
63,
411,
8,
1532,
17,
9,
272,
1453,
63,
2645,
275,
469,
498,
63,
411,
26,
2562,
17,
63,
958,
14,
1574,
12737,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29
] |
[
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,
1273,
63,
2645,
2295,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1050,
63,
1273,
63,
2645,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1680,
63,
2645,
199,
504,
3228,
14,
2828,
14,
4857,
14,
1548,
14,
1483,
492,
1680,
63,
23254,
63,
4958,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
32,
525,
63,
1273,
63,
2645,
199,
318,
2562,
17,
2031,
589,
12,
1011,
958,
304,
523,
372,
334,
589,
12,
2074,
9,
421,
199,
32,
525,
63,
1273,
63,
2645,
199,
318,
2562,
18,
2031,
589,
12,
1011,
958,
304,
523,
372,
334,
589,
12,
2074,
9,
421,
199,
32,
525,
63,
1273,
63,
2645,
199,
318,
2562,
19,
8,
589,
12,
282,
29,
403,
12,
330,
29,
17,
12,
286,
29,
18,
304,
523,
408,
7700,
32268,
1382,
1059,
1041,
523,
372,
334,
589,
12,
282,
12,
330,
12,
286,
9,
421,
199,
318,
485,
498,
63,
411,
8,
411,
304,
523,
372,
2519,
8,
411,
12,
2513,
498,
63,
411,
297,
620,
8,
411,
430,
421,
199,
533,
29560,
7812,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
4699,
6373,
7812,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
4157,
465,
4061,
26,
267,
291,
14,
629,
8,
551,
12,
5009,
819,
347,
511,
9721,
6373,
7812,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
790,
63,
411,
275,
485,
498,
63,
411,
8,
1532,
17,
9,
272,
2562,
17,
63,
2645,
275,
469,
498,
63,
411,
26,
2562,
17,
63,
958,
14,
1574,
12737,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
17,
12,
330,
29,
403,
12,
286,
1524,
17,
566,
465,
4061,
17,
26,
267,
291,
14,
629,
8,
551,
17,
12,
2562,
17,
63,
2645,
9,
267,
543,
1680,
63,
2645,
14079,
465,
4061,
18,
26,
881,
291,
14,
629,
8,
551,
18,
12,
5009,
267,
543,
1680,
63,
2645,
4157,
465,
1453,
63,
1273,
63,
2645,
26,
881,
291,
14,
629,
8,
1818,
63,
1273,
63,
2645,
12,
2562,
17,
63,
2645,
9,
819,
347,
511,
6932,
8584,
269,
972,
8,
277,
304,
339,
347,
3002,
63,
1532,
8,
84,
12,
282,
29,
403,
304,
489,
372,
334,
84,
12,
282,
9,
339,
543,
291,
14,
1855,
8,
3393,
304,
489,
543,
1680,
63,
2645,
779,
1662,
63,
1532,
467,
282,
29,
17,
304,
267,
986,
819,
347,
511,
8708,
6373,
8,
277,
304,
272,
543,
291,
14,
1855,
8,
4333,
304,
489,
543,
1680,
63,
2645,
779,
1532,
19,
467,
366,
29,
17,
304,
267,
2562,
19,
8,
17,
9,
819,
347,
511,
5639,
6373,
7812,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
790,
63,
411,
275,
485,
498,
63,
411,
8,
1532,
17,
9,
272,
1453,
63,
2645,
275,
469,
498,
63,
411,
26,
2562,
17,
63,
958,
14,
1574,
12737,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
17,
12,
330,
29,
403,
12,
286,
1524,
17,
566,
465,
4194,
26,
267,
291,
14,
19512,
8,
2645,
12,
1453,
63,
2645,
9,
819,
347,
511,
6373,
7812,
68,
14517,
8,
277,
304,
272,
2562,
19,
63,
958,
275,
661,
65,
297,
283,
66,
297,
283,
67,
358,
272,
291,
14,
2947,
8,
1273,
63,
23254,
63,
4958,
8,
1532,
19,
395,
2562,
19,
63,
958,
9,
819,
347,
511,
5639,
6373,
7812,
13029,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
2562,
18,
63,
958,
275,
791,
66,
356,
499,
12,
283,
68,
356,
359,
18,
9420,
272,
790,
275,
485,
498,
63,
411,
272,
1453,
63,
2645,
275,
469,
267,
790,
8,
1532,
17,
304,
2562,
17,
63,
958,
14,
1574,
1062,
267,
790,
8,
1532,
18,
304,
2562,
18,
63,
958,
14,
1574,
342,
272,
789,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
17,
12,
330,
29,
403,
12,
286,
1524,
17,
4682,
267,
543,
1680,
63,
2645,
779,
1532,
18,
467,
330,
29,
18,
12,
366,
1524,
18,
566,
465,
4194,
26,
881,
291,
14,
19512,
8,
2645,
12,
1453,
63,
2645,
9,
819,
347,
511,
497,
1180,
6373,
7812,
8,
277,
304,
272,
2562,
17,
63,
958,
275,
791,
65,
356,
413,
12,
283,
66,
356,
488,
12,
283,
67,
356,
359,
17,
9420,
272,
790,
63,
411,
275,
485,
498,
63,
411,
8,
1532,
17,
9,
272,
1453,
63,
2645,
275,
469,
498,
63,
411,
26,
2562,
17,
63,
958,
14,
1574,
12737,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
543,
1680,
63,
2645,
779,
1532,
17,
467,
282,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Pistachitos/Sick-Beard
|
lib/requests/auth.py
|
55
|
13225
|
# -*- coding: utf-8 -*-
"""
requests.auth
~~~~~~~~~~~~~
This module contains the authentication handlers for Requests.
"""
import os
import re
import time
import hashlib
import logging
from base64 import b64encode
from .compat import urlparse, str
from .utils import parse_dict_header
try:
from ._oauth import (Client, SIGNATURE_HMAC, SIGNATURE_TYPE_AUTH_HEADER, extract_params)
except (ImportError, SyntaxError):
SIGNATURE_HMAC = None
SIGNATURE_TYPE_AUTH_HEADER = None
try:
import kerberos as k
except ImportError as exc:
k = None
log = logging.getLogger(__name__)
CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
def _basic_auth_str(username, password):
"""Returns a Basic Auth string."""
return 'Basic ' + b64encode(('%s:%s' % (username, password)).encode('latin1')).strip().decode('latin1')
class AuthBase(object):
"""Base class that all auth implementations derive from"""
def __call__(self, r):
raise NotImplementedError('Auth hooks must be callable.')
class OAuth1(AuthBase):
"""Signs the request using OAuth 1 (RFC5849)"""
def __init__(self, client_key,
client_secret=None,
resource_owner_key=None,
resource_owner_secret=None,
callback_uri=None,
signature_method=SIGNATURE_HMAC,
signature_type=SIGNATURE_TYPE_AUTH_HEADER,
rsa_key=None, verifier=None):
try:
signature_type = signature_type.upper()
except AttributeError:
pass
self.client = Client(client_key, client_secret, resource_owner_key,
resource_owner_secret, callback_uri, signature_method,
signature_type, rsa_key, verifier)
def __call__(self, r):
"""Add OAuth parameters to the request.
Parameters may be included from the body if the content-type is
urlencoded, if no content type is set an educated guess is made.
"""
# split(";") because Content-Type may be "multipart/form-data; boundary=xxxxx"
contenttype = r.headers.get('Content-Type', '').split(";")[0].lower()
# extract_params will not give params unless the body is a properly
# formatted string, a dictionary or a list of 2-tuples.
decoded_body = extract_params(r.data)
# extract_params can only check the present r.data and does not know
# of r.files, thus an extra check is performed. We know that
# if files are present the request will not have
# Content-type: x-www-form-urlencoded. We guess it will have
# a mimetype of multipart/form-data and if this is not the case
# we assume the correct header will be set later.
_oauth_signed = True
if r.files and contenttype == CONTENT_TYPE_MULTI_PART:
# Omit body data in the signing and since it will always
# be empty (cant add paras to body if multipart) and we wish
# to preserve body.
r.url, r.headers, _ = self.client.sign(
unicode(r.full_url), unicode(r.method), None, r.headers)
elif decoded_body != None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):
# Normal signing
if not contenttype:
r.headers['Content-Type'] = CONTENT_TYPE_FORM_URLENCODED
r.url, r.headers, r.data = self.client.sign(
unicode(r.full_url), unicode(r.method), r.data, r.headers)
else:
_oauth_signed = False
if _oauth_signed:
# Both flows add params to the URL by using r.full_url,
# so this prevents adding it again later
r.params = {}
# Having the authorization header, key or value, in unicode will
# result in UnicodeDecodeErrors when the request is concatenated
# by httplib. This can easily be seen when attaching files.
# Note that simply encoding the value is not enough since Python
# saves the type of first key set. Thus we remove and re-add.
# >>> d = {u'a':u'foo'}
# >>> d['a'] = 'foo'
# >>> d
# { u'a' : 'foo' }
u_header = unicode('Authorization')
if u_header in r.headers:
auth_header = r.headers[u_header].encode('utf-8')
del r.headers[u_header]
r.headers['Authorization'] = auth_header
return r
class HTTPBasicAuth(AuthBase):
"""Attaches HTTP Basic Authentication to the given Request object."""
def __init__(self, username, password):
self.username = username
self.password = password
def __call__(self, r):
r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
return r
class HTTPProxyAuth(HTTPBasicAuth):
"""Attaches HTTP Proxy Authenetication to a given Request object."""
def __call__(self, r):
r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)
return r
class HTTPDigestAuth(AuthBase):
"""Attaches HTTP Digest Authentication to the given Request object."""
def __init__(self, username, password):
self.username = username
self.password = password
self.last_nonce = ''
self.nonce_count = 0
self.chal = {}
def build_digest_header(self, method, url):
realm = self.chal['realm']
nonce = self.chal['nonce']
qop = self.chal.get('qop')
algorithm = self.chal.get('algorithm', 'MD5')
opaque = self.chal.get('opaque', None)
algorithm = algorithm.upper()
# lambdas assume digest modules are imported at the top level
if algorithm == 'MD5':
def md5_utf8(x):
if isinstance(x, str):
x = x.encode('utf-8')
return hashlib.md5(x).hexdigest()
hash_utf8 = md5_utf8
elif algorithm == 'SHA':
def sha_utf8(x):
if isinstance(x, str):
x = x.encode('utf-8')
return hashlib.sha1(x).hexdigest()
hash_utf8 = sha_utf8
# XXX MD5-sess
KD = lambda s, d: hash_utf8("%s:%s" % (s, d))
if hash_utf8 is None:
return None
# XXX not implemented yet
entdig = None
p_parsed = urlparse(url)
path = p_parsed.path
if p_parsed.query:
path += '?' + p_parsed.query
A1 = '%s:%s:%s' % (self.username, realm, self.password)
A2 = '%s:%s' % (method, path)
if qop == 'auth':
if nonce == self.last_nonce:
self.nonce_count += 1
else:
self.nonce_count = 1
ncvalue = '%08x' % self.nonce_count
s = str(self.nonce_count).encode('utf-8')
s += nonce.encode('utf-8')
s += time.ctime().encode('utf-8')
s += os.urandom(8)
cnonce = (hashlib.sha1(s).hexdigest()[:16])
noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, hash_utf8(A2))
respdig = KD(hash_utf8(A1), noncebit)
elif qop is None:
respdig = KD(hash_utf8(A1), "%s:%s" % (nonce, hash_utf8(A2)))
else:
# XXX handle auth-int.
return None
self.last_nonce = nonce
# XXX should the partial digests be encoded too?
base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
'response="%s"' % (self.username, realm, nonce, path, respdig)
if opaque:
base += ', opaque="%s"' % opaque
if entdig:
base += ', digest="%s"' % entdig
base += ', algorithm="%s"' % algorithm
if qop:
base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce)
return 'Digest %s' % (base)
def handle_401(self, r):
"""Takes the given response and tries digest-auth, if needed."""
num_401_calls = r.request.hooks['response'].count(self.handle_401)
s_auth = r.headers.get('www-authenticate', '')
if 'digest' in s_auth.lower() and num_401_calls < 2:
self.chal = parse_dict_header(s_auth.replace('Digest ', ''))
# Consume content and release the original connection
# to allow our new request to reuse the same one.
r.content
r.raw.release_conn()
r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)
r.request.send(anyway=True)
_r = r.request.response
_r.history.append(r)
return _r
return r
def __call__(self, r):
# If we have a saved nonce, skip the 401
if self.last_nonce:
r.headers['Authorization'] = self.build_digest_header(r.method, r.url)
r.register_hook('response', self.handle_401)
return r
def _negotiate_value(r):
"""Extracts the gssapi authentication token from the appropriate header"""
authreq = r.headers.get('www-authenticate', None)
if authreq:
rx = re.compile('(?:.*,)*\s*Negotiate\s*([^,]*),?', re.I)
mo = rx.search(authreq)
if mo:
return mo.group(1)
return None
class HTTPKerberosAuth(AuthBase):
"""Attaches HTTP GSSAPI/Kerberos Authentication to the given Request object."""
def __init__(self, require_mutual_auth=True):
if k is None:
raise Exception("Kerberos libraries unavailable")
self.context = None
self.require_mutual_auth = require_mutual_auth
def generate_request_header(self, r):
"""Generates the gssapi authentication token with kerberos"""
host = urlparse(r.url).netloc
tail, _, head = host.rpartition(':')
domain = tail if tail else head
result, self.context = k.authGSSClientInit("HTTP@%s" % domain)
if result < 1:
raise Exception("authGSSClientInit failed")
result = k.authGSSClientStep(self.context, _negotiate_value(r))
if result < 0:
raise Exception("authGSSClientStep failed")
response = k.authGSSClientResponse(self.context)
return "Negotiate %s" % response
def authenticate_user(self, r):
"""Handles user authentication with gssapi/kerberos"""
auth_header = self.generate_request_header(r)
log.debug("authenticate_user(): Authorization header: %s" % auth_header)
r.request.headers['Authorization'] = auth_header
r.request.send(anyway=True)
_r = r.request.response
_r.history.append(r)
log.debug("authenticate_user(): returning %s" % _r)
return _r
def handle_401(self, r):
"""Handles 401's, attempts to use gssapi/kerberos authentication"""
log.debug("handle_401(): Handling: 401")
if _negotiate_value(r) is not None:
_r = self.authenticate_user(r)
log.debug("handle_401(): returning %s" % _r)
return _r
else:
log.debug("handle_401(): Kerberos is not supported")
log.debug("handle_401(): returning %s" % r)
return r
def handle_other(self, r):
"""Handles all responses with the exception of 401s.
This is necessary so that we can authenticate responses if requested"""
log.debug("handle_other(): Handling: %d" % r.status_code)
self.deregister(r)
if self.require_mutual_auth:
if _negotiate_value(r) is not None:
log.debug("handle_other(): Authenticating the server")
_r = self.authenticate_server(r)
log.debug("handle_other(): returning %s" % _r)
return _r
else:
log.error("handle_other(): Mutual authentication failed")
raise Exception("Mutual authentication failed")
else:
log.debug("handle_other(): returning %s" % r)
return r
def authenticate_server(self, r):
"""Uses GSSAPI to authenticate the server"""
log.debug("authenticate_server(): Authenticate header: %s" % _negotiate_value(r))
result = k.authGSSClientStep(self.context, _negotiate_value(r))
if result < 1:
raise Exception("authGSSClientStep failed")
_r = r.request.response
log.debug("authenticate_server(): returning %s" % _r)
return _r
def handle_response(self, r):
"""Takes the given response and tries kerberos-auth, as needed."""
if r.status_code == 401:
_r = self.handle_401(r)
log.debug("handle_response returning %s" % _r)
return _r
else:
_r = self.handle_other(r)
log.debug("handle_response returning %s" % _r)
return _r
log.debug("handle_response returning %s" % r)
return r
def deregister(self, r):
"""Deregisters the response handler"""
r.request.deregister_hook('response', self.handle_response)
def __call__(self, r):
r.register_hook('response', self.handle_response)
return r
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
6615,
14,
1178,
199,
22935,
94,
199,
199,
2765,
859,
3509,
314,
6299,
8297,
367,
20260,
14,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
900,
199,
646,
8337,
199,
646,
2050,
199,
199,
504,
1300,
772,
492,
330,
772,
2143,
199,
199,
504,
1275,
5819,
492,
7097,
12,
620,
199,
504,
1275,
1208,
492,
2198,
63,
807,
63,
1291,
199,
199,
893,
26,
272,
687,
13653,
6126,
492,
334,
3041,
12,
5056,
13214,
63,
23034,
12,
5056,
13214,
63,
2711,
63,
5580,
63,
7311,
12,
5536,
63,
1162,
9,
199,
199,
2590,
334,
17825,
12,
12053,
304,
272,
5056,
13214,
63,
23034,
275,
488,
272,
5056,
13214,
63,
2711,
63,
5580,
63,
7311,
275,
488,
199,
199,
893,
26,
272,
492,
4303,
23920,
465,
1022,
199,
2590,
3545,
465,
3178,
26,
272,
1022,
275,
488,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
9663,
63,
2711,
63,
3516,
63,
2632,
742,
6012,
36,
275,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
7,
199,
9663,
63,
2711,
63,
21389,
63,
14848,
275,
283,
10123,
15,
964,
13,
576,
7,
421,
199,
318,
485,
4316,
63,
1178,
63,
495,
8,
2473,
12,
2505,
304,
272,
408,
3407,
282,
10082,
3590,
1059,
1041,
339,
372,
283,
6845,
283,
435,
330,
772,
2143,
8,
3508,
83,
2689,
83,
7,
450,
334,
2473,
12,
2505,
4992,
2143,
360,
10378,
17,
11103,
1913,
1252,
2708,
360,
10378,
17,
358,
421,
199,
533,
3590,
1563,
8,
785,
304,
272,
408,
1563,
1021,
626,
1006,
1790,
12591,
23519,
687,
624,
339,
347,
636,
1250,
721,
277,
12,
519,
304,
267,
746,
4279,
360,
2817,
12604,
1471,
506,
4550,
2659,
421,
199,
533,
11715,
17,
8,
2817,
1563,
304,
272,
408,
11575,
561,
314,
1056,
1808,
11715,
413,
334,
14468,
12248,
25,
9471,
272,
347,
636,
826,
721,
277,
12,
1890,
63,
498,
12,
288,
1890,
63,
4731,
29,
403,
12,
288,
2073,
63,
4597,
63,
498,
29,
403,
12,
288,
2073,
63,
4597,
63,
4731,
29,
403,
12,
288,
3233,
63,
2302,
29,
403,
12,
288,
4955,
63,
765,
29,
26588,
63,
23034,
12,
288,
4955,
63,
466,
29,
26588,
63,
2711,
63,
5580,
63,
7311,
12,
288,
23609,
63,
498,
29,
403,
12,
25581,
29,
403,
304,
398,
862,
26,
288,
4955,
63,
466,
275,
4955,
63,
466,
14,
4142,
342,
267,
871,
4281,
26,
288,
986,
398,
291,
14,
1258,
275,
6810,
8,
1258,
63,
498,
12,
1890,
63,
4731,
12,
2073,
63,
4597,
63,
498,
12,
288,
2073,
63,
4597,
63,
4731,
12,
3233,
63,
2302,
12,
4955,
63,
765,
12,
288,
4955,
63,
466,
12,
23609,
63,
498,
12,
25581,
9,
339,
347,
636,
1250,
721,
277,
12,
519,
304,
267,
408,
1123,
11715,
2633,
370,
314,
1056,
14,
398,
3897,
1443,
506,
5120,
687,
314,
2396,
340,
314,
1564,
13,
466,
365,
267,
16511,
68,
12,
340,
949,
1564,
730,
365,
663,
376,
3988,
947,
972,
9519,
365,
6326,
14,
267,
408,
267,
327,
3715,
480,
15027,
2952,
6646,
13,
804,
1443,
506,
298,
10123,
15,
964,
13,
576,
27,
8424,
29,
5336,
88,
2,
267,
1564,
466,
275,
519,
14,
2139,
14,
362,
360,
2714,
13,
804,
297,
12548,
1294,
480,
27,
9981,
16,
1055,
2325,
342,
267,
327,
5536,
63,
1162,
911,
440,
8120,
1862,
7444,
314,
2396,
365,
282,
7684,
267,
327,
7871,
1059,
12,
282,
2600,
503,
282,
769,
402,
499,
13,
11760,
14,
267,
11203,
63,
2030,
275,
5536,
63,
1162,
8,
82,
14,
576,
9,
398,
327,
5536,
63,
1162,
883,
1454,
1104,
314,
3451,
519,
14,
576,
436,
1630,
440,
5715,
267,
327,
402,
519,
14,
1725,
12,
12850,
376,
2402,
1104,
365,
10585,
14,
2136,
5715,
626,
267,
327,
340,
1584,
787,
3451,
314,
1056,
911,
440,
1172,
267,
327,
6646,
13,
466,
26,
671,
13,
1544,
13,
964,
13,
21886,
14,
2136,
9519,
652,
911,
1172,
267,
327,
282,
12200,
402,
15193,
15,
964,
13,
576,
436,
340,
642,
365,
440,
314,
1930,
267,
327,
781,
5534,
314,
3211,
1406,
911,
506,
663,
2945,
14,
267,
485,
6126,
63,
1737,
275,
715,
267,
340,
519,
14,
1725,
436,
1564,
466,
508,
29417,
63,
2711,
63,
21389,
63,
14848,
26,
288,
327,
593,
1147,
2396,
666,
315,
314,
18057,
436,
3967,
652,
911,
3544,
288,
327,
506,
2701,
334,
67,
867,
1050,
623,
305,
370,
2396,
340,
15193,
9,
436,
781,
13809,
288,
327,
370,
11211,
2396,
14,
288,
519,
14,
633,
12,
519,
14,
2139,
12,
485,
275,
291,
14,
1258,
14,
1037,
8,
355,
2649,
8,
82,
14,
2861,
63,
633,
395,
2649,
8,
82,
14,
765,
395,
488,
12,
519,
14,
2139,
9,
267,
916,
11203,
63,
2030,
1137,
488,
436,
1564,
466,
315,
334,
9663,
63,
2711,
63,
3516,
63,
2632,
742,
6012,
36,
12,
21019,
288,
327,
11514,
18057,
288,
340,
440,
1564,
466,
26,
355,
519,
14,
2139,
459,
2714,
13,
804,
418,
275,
29417,
63,
2711,
63,
3516,
63,
2632,
742,
6012,
36,
288,
519,
14,
633,
12,
519,
14,
2139,
12,
519,
14,
576,
275,
291,
14,
1258,
14,
1037,
8,
355,
2649,
8,
82,
14,
2861,
63,
633,
395,
2649,
8,
82,
14,
765,
395,
519,
14,
576,
12,
519,
14,
2139,
9,
267,
587,
26,
288,
485,
6126,
63,
1737,
275,
756,
267,
340,
485,
6126,
63,
1737,
26,
288,
327,
17650,
30708,
1050,
1862,
370,
314,
2851,
701,
1808,
519,
14,
2861,
63,
633,
12,
288,
327,
880,
642,
21925,
7791,
652,
4020,
2945,
288,
519,
14,
1162,
275,
1052,
953,
327,
869,
5519,
314,
13448,
1406,
12,
790,
503,
574,
12,
315,
2649,
911,
288,
327,
754,
315,
6140,
9400,
9298,
1380,
314,
1056,
365,
26271,
288,
327,
701,
8809,
14,
961,
883,
16174,
506,
6775,
1380,
6554,
316,
1584,
14,
288,
327,
3390,
626,
9329,
2644,
314,
574,
365,
440,
8321,
3967,
2018,
288,
327,
23050,
314,
730,
402,
1642,
790,
663,
14,
20227,
781,
2813,
436,
295,
13,
525,
14,
288,
327,
1306,
366,
275,
469,
85,
7,
65,
356,
85,
7
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
6615,
14,
1178,
199,
22935,
94,
199,
199,
2765,
859,
3509,
314,
6299,
8297,
367,
20260,
14,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
900,
199,
646,
8337,
199,
646,
2050,
199,
199,
504,
1300,
772,
492,
330,
772,
2143,
199,
199,
504,
1275,
5819,
492,
7097,
12,
620,
199,
504,
1275,
1208,
492,
2198,
63,
807,
63,
1291,
199,
199,
893,
26,
272,
687,
13653,
6126,
492,
334,
3041,
12,
5056,
13214,
63,
23034,
12,
5056,
13214,
63,
2711,
63,
5580,
63,
7311,
12,
5536,
63,
1162,
9,
199,
199,
2590,
334,
17825,
12,
12053,
304,
272,
5056,
13214,
63,
23034,
275,
488,
272,
5056,
13214,
63,
2711,
63,
5580,
63,
7311,
275,
488,
199,
199,
893,
26,
272,
492,
4303,
23920,
465,
1022,
199,
2590,
3545,
465,
3178,
26,
272,
1022,
275,
488,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
9663,
63,
2711,
63,
3516,
63,
2632,
742,
6012,
36,
275,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
7,
199,
9663,
63,
2711,
63,
21389,
63,
14848,
275,
283,
10123,
15,
964,
13,
576,
7,
421,
199,
318,
485,
4316,
63,
1178,
63,
495,
8,
2473,
12,
2505,
304,
272,
408,
3407,
282,
10082,
3590,
1059,
1041,
339,
372,
283,
6845,
283,
435,
330,
772,
2143,
8,
3508,
83,
2689,
83,
7,
450,
334,
2473,
12,
2505,
4992,
2143,
360,
10378,
17,
11103,
1913,
1252,
2708,
360,
10378,
17,
358,
421,
199,
533,
3590,
1563,
8,
785,
304,
272,
408,
1563,
1021,
626,
1006,
1790,
12591,
23519,
687,
624,
339,
347,
636,
1250,
721,
277,
12,
519,
304,
267,
746,
4279,
360,
2817,
12604,
1471,
506,
4550,
2659,
421,
199,
533,
11715,
17,
8,
2817,
1563,
304,
272,
408,
11575,
561,
314,
1056,
1808,
11715,
413,
334,
14468,
12248,
25,
9471,
272,
347,
636,
826,
721,
277,
12,
1890,
63,
498,
12,
288,
1890,
63,
4731,
29,
403,
12,
288,
2073,
63,
4597,
63,
498,
29,
403,
12,
288,
2073,
63,
4597,
63,
4731,
29,
403,
12,
288,
3233,
63,
2302,
29,
403,
12,
288,
4955,
63,
765,
29,
26588,
63,
23034,
12,
288,
4955,
63,
466,
29,
26588,
63,
2711,
63,
5580,
63,
7311,
12,
288,
23609,
63,
498,
29,
403,
12,
25581,
29,
403,
304,
398,
862,
26,
288,
4955,
63,
466,
275,
4955,
63,
466,
14,
4142,
342,
267,
871,
4281,
26,
288,
986,
398,
291,
14,
1258,
275,
6810,
8,
1258,
63,
498,
12,
1890,
63,
4731,
12,
2073,
63,
4597,
63,
498,
12,
288,
2073,
63,
4597,
63,
4731,
12,
3233,
63,
2302,
12,
4955,
63,
765,
12,
288,
4955,
63,
466,
12,
23609,
63,
498,
12,
25581,
9,
339,
347,
636,
1250,
721,
277,
12,
519,
304,
267,
408,
1123,
11715,
2633,
370,
314,
1056,
14,
398,
3897,
1443,
506,
5120,
687,
314,
2396,
340,
314,
1564,
13,
466,
365,
267,
16511,
68,
12,
340,
949,
1564,
730,
365,
663,
376,
3988,
947,
972,
9519,
365,
6326,
14,
267,
408,
267,
327,
3715,
480,
15027,
2952,
6646,
13,
804,
1443,
506,
298,
10123,
15,
964,
13,
576,
27,
8424,
29,
5336,
88,
2,
267,
1564,
466,
275,
519,
14,
2139,
14,
362,
360,
2714,
13,
804,
297,
12548,
1294,
480,
27,
9981,
16,
1055,
2325,
342,
267,
327,
5536,
63,
1162,
911,
440,
8120,
1862,
7444,
314,
2396,
365,
282,
7684,
267,
327,
7871,
1059,
12,
282,
2600,
503,
282,
769,
402,
499,
13,
11760,
14,
267,
11203,
63,
2030,
275,
5536,
63,
1162,
8,
82,
14,
576,
9,
398,
327,
5536,
63,
1162,
883,
1454,
1104,
314,
3451,
519,
14,
576,
436,
1630,
440,
5715,
267,
327,
402,
519,
14,
1725,
12,
12850,
376,
2402,
1104,
365,
10585,
14,
2136,
5715,
626,
267,
327,
340,
1584,
787,
3451,
314,
1056,
911,
440,
1172,
267,
327,
6646,
13,
466,
26,
671,
13,
1544,
13,
964,
13,
21886,
14,
2136,
9519,
652,
911,
1172,
267,
327,
282,
12200,
402,
15193,
15,
964,
13,
576,
436,
340,
642,
365,
440,
314,
1930,
267,
327,
781,
5534,
314,
3211,
1406,
911,
506,
663,
2945,
14,
267,
485,
6126,
63,
1737,
275,
715,
267,
340,
519,
14,
1725,
436,
1564,
466,
508,
29417,
63,
2711,
63,
21389,
63,
14848,
26,
288,
327,
593,
1147,
2396,
666,
315,
314,
18057,
436,
3967,
652,
911,
3544,
288,
327,
506,
2701,
334,
67,
867,
1050,
623,
305,
370,
2396,
340,
15193,
9,
436,
781,
13809,
288,
327,
370,
11211,
2396,
14,
288,
519,
14,
633,
12,
519,
14,
2139,
12,
485,
275,
291,
14,
1258,
14,
1037,
8,
355,
2649,
8,
82,
14,
2861,
63,
633,
395,
2649,
8,
82,
14,
765,
395,
488,
12,
519,
14,
2139,
9,
267,
916,
11203,
63,
2030,
1137,
488,
436,
1564,
466,
315,
334,
9663,
63,
2711,
63,
3516,
63,
2632,
742,
6012,
36,
12,
21019,
288,
327,
11514,
18057,
288,
340,
440,
1564,
466,
26,
355,
519,
14,
2139,
459,
2714,
13,
804,
418,
275,
29417,
63,
2711,
63,
3516,
63,
2632,
742,
6012,
36,
288,
519,
14,
633,
12,
519,
14,
2139,
12,
519,
14,
576,
275,
291,
14,
1258,
14,
1037,
8,
355,
2649,
8,
82,
14,
2861,
63,
633,
395,
2649,
8,
82,
14,
765,
395,
519,
14,
576,
12,
519,
14,
2139,
9,
267,
587,
26,
288,
485,
6126,
63,
1737,
275,
756,
267,
340,
485,
6126,
63,
1737,
26,
288,
327,
17650,
30708,
1050,
1862,
370,
314,
2851,
701,
1808,
519,
14,
2861,
63,
633,
12,
288,
327,
880,
642,
21925,
7791,
652,
4020,
2945,
288,
519,
14,
1162,
275,
1052,
953,
327,
869,
5519,
314,
13448,
1406,
12,
790,
503,
574,
12,
315,
2649,
911,
288,
327,
754,
315,
6140,
9400,
9298,
1380,
314,
1056,
365,
26271,
288,
327,
701,
8809,
14,
961,
883,
16174,
506,
6775,
1380,
6554,
316,
1584,
14,
288,
327,
3390,
626,
9329,
2644,
314,
574,
365,
440,
8321,
3967,
2018,
288,
327,
23050,
314,
730,
402,
1642,
790,
663,
14,
20227,
781,
2813,
436,
295,
13,
525,
14,
288,
327,
1306,
366,
275,
469,
85,
7,
65,
356,
85,
7,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
xzturn/tensorflow
|
tensorflow/python/kernel_tests/ctc_decoder_ops_test.py
|
22
|
8909
|
# 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 tensorflow.ctc_ops.ctc_loss_op."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import itertools
import numpy as np
from six.moves import zip_longest
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import ctc_ops
from tensorflow.python.platform import test
def grouper(iterable, n, fillvalue=None):
"""Collect data into fixed-length chunks or blocks."""
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
args = [iter(iterable)] * n
return zip_longest(fillvalue=fillvalue, *args)
def flatten(list_of_lists):
"""Flatten one level of nesting."""
return itertools.chain.from_iterable(list_of_lists)
class CTCGreedyDecoderTest(test.TestCase):
def _testCTCDecoder(self,
decoder,
inputs,
seq_lens,
log_prob_truth,
decode_truth,
expected_err_re=None,
**decoder_args):
inputs_t = [ops.convert_to_tensor(x) for x in inputs]
# convert inputs_t into a [max_time x batch_size x depth] tensor
# from a len time python list of [batch_size x depth] tensors
inputs_t = array_ops.stack(inputs_t)
with self.cached_session(use_gpu=False) as sess:
decoded_list, log_probability = decoder(
inputs_t, sequence_length=seq_lens, **decoder_args)
decoded_unwrapped = list(
flatten([(st.indices, st.values, st.dense_shape) for st in
decoded_list]))
if expected_err_re is None:
outputs = sess.run(decoded_unwrapped + [log_probability])
# Group outputs into (ix, vals, shape) tuples
output_sparse_tensors = list(grouper(outputs[:-1], 3))
output_log_probability = outputs[-1]
# Check the number of decoded outputs (top_paths) match
self.assertEqual(len(output_sparse_tensors), len(decode_truth))
# For each SparseTensor tuple, compare (ix, vals, shape)
for out_st, truth_st, tf_st in zip(output_sparse_tensors, decode_truth,
decoded_list):
self.assertAllEqual(out_st[0], truth_st[0]) # ix
self.assertAllEqual(out_st[1], truth_st[1]) # vals
self.assertAllEqual(out_st[2], truth_st[2]) # shape
# Compare the shapes of the components with the truth. The
# `None` elements are not known statically.
self.assertEqual([None, truth_st[0].shape[1]],
tf_st.indices.get_shape().as_list())
self.assertEqual([None], tf_st.values.get_shape().as_list())
self.assertShapeEqual(truth_st[2], tf_st.dense_shape)
# Make sure decoded probabilities match
self.assertAllClose(output_log_probability, log_prob_truth, atol=1e-6)
else:
with self.assertRaisesOpError(expected_err_re):
sess.run(decoded_unwrapped + [log_probability])
@test_util.run_deprecated_v1
def testCTCGreedyDecoder(self):
"""Test two batch entries - best path decoder."""
max_time_steps = 6
# depth == 4
seq_len_0 = 4
input_prob_matrix_0 = np.asarray(
[[1.0, 0.0, 0.0, 0.0], # t=0
[0.0, 0.0, 0.4, 0.6], # t=1
[0.0, 0.0, 0.4, 0.6], # t=2
[0.0, 0.9, 0.1, 0.0], # t=3
[0.0, 0.0, 0.0, 0.0], # t=4 (ignored)
[0.0, 0.0, 0.0, 0.0]], # t=5 (ignored)
dtype=np.float32)
input_log_prob_matrix_0 = np.log(input_prob_matrix_0)
seq_len_1 = 5
# dimensions are time x depth
input_prob_matrix_1 = np.asarray(
[
[0.1, 0.9, 0.0, 0.0], # t=0
[0.0, 0.9, 0.1, 0.0], # t=1
[0.0, 0.0, 0.1, 0.9], # t=2
[0.0, 0.9, 0.1, 0.1], # t=3
[0.9, 0.1, 0.0, 0.0], # t=4
[0.0, 0.0, 0.0, 0.0]
], # t=5 (ignored)
dtype=np.float32)
input_log_prob_matrix_1 = np.log(input_prob_matrix_1)
# len max_time_steps array of batch_size x depth matrices
inputs = [
np.vstack(
[input_log_prob_matrix_0[t, :], input_log_prob_matrix_1[t, :]])
for t in range(max_time_steps)
]
# batch_size length vector of sequence_lengths
seq_lens = np.array([seq_len_0, seq_len_1], dtype=np.int32)
# batch_size length vector of negative log probabilities
log_prob_truth = np.array([
np.sum(-np.log([1.0, 0.6, 0.6, 0.9])),
np.sum(-np.log([0.9, 0.9, 0.9, 0.9, 0.9]))
], np.float32)[:, np.newaxis]
# decode_truth: one SparseTensor (ix, vals, shape)
decode_truth = [
(
np.array(
[
[0, 0], # batch 0, 2 outputs
[0, 1],
[1, 0], # batch 1, 3 outputs
[1, 1],
[1, 2]
],
dtype=np.int64),
np.array(
[
0,
1, # batch 0
1,
1,
0
], # batch 1
dtype=np.int64),
# shape is batch x max_decoded_length
np.array(
[2, 3], dtype=np.int64)),
]
self._testCTCDecoder(ctc_ops.ctc_greedy_decoder, inputs, seq_lens,
log_prob_truth, decode_truth)
@test_util.run_deprecated_v1
def testCTCDecoderBeamSearch(self):
"""Test one batch, two beams - hibernating beam search."""
# max_time_steps == 8
depth = 6
seq_len_0 = 5
input_prob_matrix_0 = np.asarray(
[
[0.30999, 0.309938, 0.0679938, 0.0673362, 0.0708352, 0.173908],
[0.215136, 0.439699, 0.0370931, 0.0393967, 0.0381581, 0.230517],
[0.199959, 0.489485, 0.0233221, 0.0251417, 0.0233289, 0.238763],
[0.279611, 0.452966, 0.0204795, 0.0209126, 0.0194803, 0.20655],
[0.51286, 0.288951, 0.0243026, 0.0220788, 0.0219297, 0.129878],
# Random entry added in at time=5
[0.155251, 0.164444, 0.173517, 0.176138, 0.169979, 0.160671]
],
dtype=np.float32)
# Add arbitrary offset - this is fine
input_prob_matrix_0 = input_prob_matrix_0 + 2.0
# len max_time_steps array of batch_size x depth matrices
inputs = ([
input_prob_matrix_0[t, :][np.newaxis, :] for t in range(seq_len_0)
] # Pad to max_time_steps = 8
+ 2 * [np.zeros(
(1, depth), dtype=np.float32)])
# batch_size length vector of sequence_lengths
seq_lens = np.array([seq_len_0], dtype=np.int32)
# batch_size length vector of log probabilities
log_prob_truth = np.array(
[
-5.811451, # output beam 0
-6.63339 # output beam 1
],
np.float32)[np.newaxis, :]
# decode_truth: two SparseTensors, (ix, values, shape)
decode_truth = [
# beam 0, batch 0, two outputs decoded
(np.array(
[[0, 0], [0, 1]], dtype=np.int64), np.array(
[1, 0], dtype=np.int64), np.array(
[1, 2], dtype=np.int64)),
# beam 1, batch 0, one output decoded
(np.array(
[[0, 0]], dtype=np.int64), np.array(
[1], dtype=np.int64), np.array(
[1, 1], dtype=np.int64)),
]
# Test correct decoding.
self._testCTCDecoder(
ctc_ops.ctc_beam_search_decoder,
inputs,
seq_lens,
log_prob_truth,
decode_truth,
beam_width=2,
top_paths=2)
# Requesting more paths than the beam width allows.
with self.assertRaisesRegexp(errors.InvalidArgumentError,
(".*requested more paths than the beam "
"width.*")):
self._testCTCDecoder(
ctc_ops.ctc_beam_search_decoder,
inputs,
seq_lens,
log_prob_truth,
decode_truth,
beam_width=2,
top_paths=3)
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,
3228,
14,
319,
67,
63,
1483,
14,
319,
67,
63,
4358,
63,
411,
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,
7975,
199,
199,
646,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
3482,
63,
20820,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
286,
3641,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
318,
1572,
281,
8,
8147,
12,
302,
12,
5554,
585,
29,
403,
304,
523,
408,
25023,
666,
1901,
6317,
13,
1267,
8291,
503,
5664,
1041,
523,
327,
1572,
281,
360,
22897,
297,
650,
12,
283,
88,
358,
10541,
17281,
23566,
598,
2154,
523,
1249,
275,
359,
1661,
8,
8147,
1874,
627,
302,
523,
372,
3482,
63,
20820,
8,
4498,
585,
29,
4498,
585,
12,
627,
589,
9,
421,
199,
318,
9378,
8,
513,
63,
1618,
63,
6717,
304,
523,
408,
29302,
1373,
2166,
402,
19500,
1041,
523,
372,
7975,
14,
4429,
14,
504,
63,
8147,
8,
513,
63,
1618,
63,
6717,
9,
421,
199,
533,
445,
22173,
24737,
8326,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
396,
1028,
35,
8326,
8,
277,
12,
1993,
10334,
12,
1993,
4153,
12,
1993,
5412,
63,
25057,
12,
1993,
943,
63,
6101,
63,
17167,
12,
1993,
4849,
63,
17167,
12,
1993,
1420,
63,
1508,
63,
264,
29,
403,
12,
1993,
1011,
8813,
63,
589,
304,
272,
4153,
63,
84,
275,
359,
1483,
14,
3916,
63,
475,
63,
3128,
8,
88,
9,
367,
671,
315,
4153,
61,
272,
327,
3957,
4153,
63,
84,
1901,
282,
359,
988,
63,
521,
671,
3522,
63,
890,
671,
5818,
61,
2345,
272,
327,
687,
282,
822,
900,
2366,
769,
402,
359,
2912,
63,
890,
671,
5818,
61,
10519,
272,
4153,
63,
84,
275,
1625,
63,
1483,
14,
2340,
8,
3711,
63,
84,
9,
339,
543,
291,
14,
5245,
63,
1730,
8,
1180,
63,
6477,
29,
797,
9,
465,
4043,
26,
489,
11203,
63,
513,
12,
943,
63,
17210,
275,
10334,
8,
881,
4153,
63,
84,
12,
3414,
63,
1267,
29,
3610,
63,
25057,
12,
1011,
8813,
63,
589,
9,
489,
11203,
63,
324,
9130,
275,
769,
8,
881,
9378,
7694,
270,
14,
4108,
12,
410,
14,
1459,
12,
410,
14,
7253,
63,
1392,
9,
367,
410,
315,
673,
11203,
63,
513,
2459,
2541,
340,
1420,
63,
1508,
63,
264,
365,
488,
26,
267,
4704,
275,
4043,
14,
1065,
8,
16167,
63,
324,
9130,
435,
359,
793,
63,
17210,
566,
398,
327,
5611,
4704,
1901,
334,
1148,
12,
5322,
12,
2215,
9,
6346,
267,
1072,
63,
4421,
63,
10206,
275,
769,
8,
923,
281,
8,
4467,
4439,
17,
467,
650,
430,
398,
1072,
63,
793,
63,
17210,
275,
4704,
1988,
17,
61,
398,
327,
2670,
314,
1329,
402,
11203,
4704,
334,
2119,
63,
3771,
9,
1336,
267,
291,
14,
629,
8,
552,
8,
1199,
63,
4421,
63,
10206,
395,
822,
8,
2708,
63,
17167,
430,
398,
327,
2104,
1924,
14531,
3861,
2008,
12,
6540,
334,
1148,
12,
5322,
12,
2215,
9,
267,
367,
734,
63,
270,
12,
16865,
63,
270,
12,
2833,
63,
270,
315,
3482,
8,
1199,
63,
4421,
63,
10206,
12,
4849,
63,
17167,
12,
5644,
11203,
63,
513,
304,
881,
291,
14,
7069,
8,
548,
63,
270,
59,
16,
467,
16865,
63,
270,
59,
16,
566,
221,
327,
20593,
881,
291,
14,
7069,
8,
548,
63,
270,
59,
17,
467,
16865,
63,
270,
59,
17,
566,
221,
327,
5322,
881,
291,
14,
7069,
8,
548,
63,
270,
59,
18,
467,
16865,
63,
270,
59,
18,
566,
221,
327,
2215,
881,
327,
18955,
314,
11751,
402,
314,
7323,
543,
314,
16865,
14,
710,
881,
327,
658,
403,
64,
4008,
787,
440,
6040,
2955,
1183,
14,
881,
291,
14,
629,
779,
403,
12,
16865,
63,
270,
59,
16,
1055,
1392,
59,
17,
2365,
2574,
2833,
63,
270,
14,
4108,
14,
362,
63,
1392,
1252,
305,
63,
513,
1012,
881,
291,
14,
629,
779,
403,
467,
2833,
63,
270,
14,
1459,
14,
362,
63,
1392,
1252,
305,
63,
513,
1012,
881,
291,
14,
479,
7238,
591,
8,
17167,
63,
270,
59,
18,
467,
2833,
63,
270,
14,
7253,
63,
1392,
9,
398,
327,
4155,
3238,
11203,
19555,
1336,
267,
291,
14,
7260,
8,
1199,
63,
793,
63,
17210,
12,
943,
63,
6101,
63,
17167,
12,
9543,
29,
17,
69,
13,
22,
9,
489,
587,
26,
267,
543,
291,
14,
26501,
8,
2062,
63,
1508,
63,
264,
304,
881,
4043,
14,
1065,
8,
16167,
63,
324,
9130,
435,
359,
793,
63,
17210,
566,
819,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
1028,
4064,
24737,
8326,
8,
277,
304,
272,
408,
774,
2877,
3522,
4811,
446,
5526,
931,
10334,
1041,
272,
1390,
63,
521,
63,
5895,
275,
1227,
272,
327,
5818,
508,
841,
339,
5412,
63,
552,
63,
16,
275,
841,
272,
1324,
63,
6101,
63,
3642,
63,
16,
275,
980,
14,
8748,
8,
267
] |
[
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,
3228,
14,
319,
67,
63,
1483,
14,
319,
67,
63,
4358,
63,
411,
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,
7975,
199,
199,
646,
2680,
465,
980,
199,
504,
3816,
14,
4912,
492,
3482,
63,
20820,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
286,
3641,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
318,
1572,
281,
8,
8147,
12,
302,
12,
5554,
585,
29,
403,
304,
523,
408,
25023,
666,
1901,
6317,
13,
1267,
8291,
503,
5664,
1041,
523,
327,
1572,
281,
360,
22897,
297,
650,
12,
283,
88,
358,
10541,
17281,
23566,
598,
2154,
523,
1249,
275,
359,
1661,
8,
8147,
1874,
627,
302,
523,
372,
3482,
63,
20820,
8,
4498,
585,
29,
4498,
585,
12,
627,
589,
9,
421,
199,
318,
9378,
8,
513,
63,
1618,
63,
6717,
304,
523,
408,
29302,
1373,
2166,
402,
19500,
1041,
523,
372,
7975,
14,
4429,
14,
504,
63,
8147,
8,
513,
63,
1618,
63,
6717,
9,
421,
199,
533,
445,
22173,
24737,
8326,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
396,
1028,
35,
8326,
8,
277,
12,
1993,
10334,
12,
1993,
4153,
12,
1993,
5412,
63,
25057,
12,
1993,
943,
63,
6101,
63,
17167,
12,
1993,
4849,
63,
17167,
12,
1993,
1420,
63,
1508,
63,
264,
29,
403,
12,
1993,
1011,
8813,
63,
589,
304,
272,
4153,
63,
84,
275,
359,
1483,
14,
3916,
63,
475,
63,
3128,
8,
88,
9,
367,
671,
315,
4153,
61,
272,
327,
3957,
4153,
63,
84,
1901,
282,
359,
988,
63,
521,
671,
3522,
63,
890,
671,
5818,
61,
2345,
272,
327,
687,
282,
822,
900,
2366,
769,
402,
359,
2912,
63,
890,
671,
5818,
61,
10519,
272,
4153,
63,
84,
275,
1625,
63,
1483,
14,
2340,
8,
3711,
63,
84,
9,
339,
543,
291,
14,
5245,
63,
1730,
8,
1180,
63,
6477,
29,
797,
9,
465,
4043,
26,
489,
11203,
63,
513,
12,
943,
63,
17210,
275,
10334,
8,
881,
4153,
63,
84,
12,
3414,
63,
1267,
29,
3610,
63,
25057,
12,
1011,
8813,
63,
589,
9,
489,
11203,
63,
324,
9130,
275,
769,
8,
881,
9378,
7694,
270,
14,
4108,
12,
410,
14,
1459,
12,
410,
14,
7253,
63,
1392,
9,
367,
410,
315,
673,
11203,
63,
513,
2459,
2541,
340,
1420,
63,
1508,
63,
264,
365,
488,
26,
267,
4704,
275,
4043,
14,
1065,
8,
16167,
63,
324,
9130,
435,
359,
793,
63,
17210,
566,
398,
327,
5611,
4704,
1901,
334,
1148,
12,
5322,
12,
2215,
9,
6346,
267,
1072,
63,
4421,
63,
10206,
275,
769,
8,
923,
281,
8,
4467,
4439,
17,
467,
650,
430,
398,
1072,
63,
793,
63,
17210,
275,
4704,
1988,
17,
61,
398,
327,
2670,
314,
1329,
402,
11203,
4704,
334,
2119,
63,
3771,
9,
1336,
267,
291,
14,
629,
8,
552,
8,
1199,
63,
4421,
63,
10206,
395,
822,
8,
2708,
63,
17167,
430,
398,
327,
2104,
1924,
14531,
3861,
2008,
12,
6540,
334,
1148,
12,
5322,
12,
2215,
9,
267,
367,
734,
63,
270,
12,
16865,
63,
270,
12,
2833,
63,
270,
315,
3482,
8,
1199,
63,
4421,
63,
10206,
12,
4849,
63,
17167,
12,
5644,
11203,
63,
513,
304,
881,
291,
14,
7069,
8,
548,
63,
270,
59,
16,
467,
16865,
63,
270,
59,
16,
566,
221,
327,
20593,
881,
291,
14,
7069,
8,
548,
63,
270,
59,
17,
467,
16865,
63,
270,
59,
17,
566,
221,
327,
5322,
881,
291,
14,
7069,
8,
548,
63,
270,
59,
18,
467,
16865,
63,
270,
59,
18,
566,
221,
327,
2215,
881,
327,
18955,
314,
11751,
402,
314,
7323,
543,
314,
16865,
14,
710,
881,
327,
658,
403,
64,
4008,
787,
440,
6040,
2955,
1183,
14,
881,
291,
14,
629,
779,
403,
12,
16865,
63,
270,
59,
16,
1055,
1392,
59,
17,
2365,
2574,
2833,
63,
270,
14,
4108,
14,
362,
63,
1392,
1252,
305,
63,
513,
1012,
881,
291,
14,
629,
779,
403,
467,
2833,
63,
270,
14,
1459,
14,
362,
63,
1392,
1252,
305,
63,
513,
1012,
881,
291,
14,
479,
7238,
591,
8,
17167,
63,
270,
59,
18,
467,
2833,
63,
270,
14,
7253,
63,
1392,
9,
398,
327,
4155,
3238,
11203,
19555,
1336,
267,
291,
14,
7260,
8,
1199,
63,
793,
63,
17210,
12,
943,
63,
6101,
63,
17167,
12,
9543,
29,
17,
69,
13,
22,
9,
489,
587,
26,
267,
543,
291,
14,
26501,
8,
2062,
63,
1508,
63,
264,
304,
881,
4043,
14,
1065,
8,
16167,
63,
324,
9130,
435,
359,
793,
63,
17210,
566,
819,
768,
396,
63,
1974,
14,
1065,
63,
6667,
63,
86,
17,
523,
347,
511,
1028,
4064,
24737,
8326,
8,
277,
304,
272,
408,
774,
2877,
3522,
4811,
446,
5526,
931,
10334,
1041,
272,
1390,
63,
521,
63,
5895,
275,
1227,
272,
327,
5818,
508,
841,
339,
5412,
63,
552,
63,
16,
275,
841,
272,
1324,
63,
6101,
63,
3642,
63,
16,
275,
980,
14,
8748,
8,
267,
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,
1
] |
Djabbz/wakatime
|
wakatime/packages/pygments_py3/pygments/formatters/rtf.py
|
73
|
5049
|
# -*- coding: utf-8 -*-
"""
pygments.formatters.rtf
~~~~~~~~~~~~~~~~~~~~~~~
A formatter that generates RTF files.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.formatter import Formatter
from pygments.util import get_int_opt, _surrogatepair
__all__ = ['RtfFormatter']
class RtfFormatter(Formatter):
"""
Format tokens as RTF markup. This formatter automatically outputs full RTF
documents with color information and other useful stuff. Perfect for Copy and
Paste into Microsoft(R) Word(R) documents.
Please note that ``encoding`` and ``outencoding`` options are ignored.
The RTF format is ASCII natively, but handles unicode characters correctly
thanks to escape sequences.
.. versionadded:: 0.6
Additional options accepted:
`style`
The style to use, can be a string or a Style subclass (default:
``'default'``).
`fontface`
The used font famliy, for example ``Bitstream Vera Sans``. Defaults to
some generic font which is supposed to have fixed width.
`fontsize`
Size of the font used. Size is specified in half points. The
default is 24 half-points, giving a size 12 font.
.. versionadded:: 2.0
"""
name = 'RTF'
aliases = ['rtf']
filenames = ['*.rtf']
def __init__(self, **options):
r"""
Additional options accepted:
``fontface``
Name of the font used. Could for example be ``'Courier New'``
to further specify the default which is ``'\fmodern'``. The RTF
specification claims that ``\fmodern`` are "Fixed-pitch serif
and sans serif fonts". Hope every RTF implementation thinks
the same about modern...
"""
Formatter.__init__(self, **options)
self.fontface = options.get('fontface') or ''
self.fontsize = get_int_opt(options, 'fontsize', 0)
def _escape(self, text):
return text.replace(u'\\', u'\\\\') \
.replace(u'{', u'\\{') \
.replace(u'}', u'\\}')
def _escape_text(self, text):
# empty strings, should give a small performance improvment
if not text:
return u''
# escape text
text = self._escape(text)
buf = []
for c in text:
cn = ord(c)
if cn < (2**7):
# ASCII character
buf.append(str(c))
elif (2**7) <= cn < (2**16):
# single unicode escape sequence
buf.append(u'{\\u%d}' % cn)
elif (2**16) <= cn:
# RTF limits unicode to 16 bits.
# Force surrogate pairs
buf.append(u'{\\u%d}{\\u%d}' % _surrogatepair(cn))
return u''.join(buf).replace(u'\n', u'\\par\n')
def format_unencoded(self, tokensource, outfile):
# rtf 1.8 header
outfile.write(u'{\\rtf1\\ansi\\uc0\\deff0'
u'{\\fonttbl{\\f0\\fmodern\\fprq1\\fcharset0%s;}}'
u'{\\colortbl;' % (self.fontface and
u' ' + self._escape(self.fontface) or
u''))
# convert colors and save them in a mapping to access them later.
color_mapping = {}
offset = 1
for _, style in self.style:
for color in style['color'], style['bgcolor'], style['border']:
if color and color not in color_mapping:
color_mapping[color] = offset
outfile.write(u'\\red%d\\green%d\\blue%d;' % (
int(color[0:2], 16),
int(color[2:4], 16),
int(color[4:6], 16)
))
offset += 1
outfile.write(u'}\\f0 ')
if self.fontsize:
outfile.write(u'\\fs%d' % (self.fontsize))
# highlight stream
for ttype, value in tokensource:
while not self.style.styles_token(ttype) and ttype.parent:
ttype = ttype.parent
style = self.style.style_for_token(ttype)
buf = []
if style['bgcolor']:
buf.append(u'\\cb%d' % color_mapping[style['bgcolor']])
if style['color']:
buf.append(u'\\cf%d' % color_mapping[style['color']])
if style['bold']:
buf.append(u'\\b')
if style['italic']:
buf.append(u'\\i')
if style['underline']:
buf.append(u'\\ul')
if style['border']:
buf.append(u'\\chbrdr\\chcfpat%d' %
color_mapping[style['border']])
start = u''.join(buf)
if start:
outfile.write(u'{%s ' % start)
outfile.write(self._escape_text(value))
if start:
outfile.write(u'}')
outfile.write(u'}')
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
14,
2591,
70,
272,
18294,
2878,
23597,
339,
437,
9698,
626,
12821,
820,
6145,
1584,
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,
504,
13277,
14,
8911,
492,
31084,
199,
504,
13277,
14,
1974,
492,
664,
63,
442,
63,
2992,
12,
485,
16380,
3852,
421,
199,
363,
452,
363,
275,
788,
50,
3249,
7772,
418,
421,
199,
533,
820,
3249,
7772,
8,
7772,
304,
272,
408,
272,
9701,
4645,
465,
820,
6145,
9189,
14,
961,
9698,
5847,
4704,
2615,
820,
6145,
272,
8247,
543,
3164,
2556,
436,
1163,
2997,
8292,
14,
31778,
449,
367,
11247,
436,
272,
510,
9209,
1901,
15332,
8,
50,
9,
14644,
8,
50,
9,
8247,
14,
339,
7754,
5317,
626,
1124,
2991,
1040,
436,
1124,
810,
28139,
1040,
1511,
787,
5525,
14,
272,
710,
820,
6145,
1475,
365,
10485,
302,
17330,
12,
1325,
10022,
2649,
4110,
6657,
272,
2419,
6080,
370,
4772,
8013,
14,
339,
2508,
7445,
447,
378,
14,
22,
339,
10961,
1511,
10226,
26,
339,
658,
2487,
64,
267,
710,
3449,
370,
675,
12,
883,
506,
282,
1059,
503,
282,
19442,
5516,
334,
885,
26,
267,
12692,
885,
14700,
680,
339,
658,
4246,
1409,
64,
267,
710,
1202,
5023,
21450,
317,
89,
12,
367,
2893,
1124,
4734,
1745,
5444,
65,
428,
796,
4345,
7827,
370,
267,
2005,
7809,
5023,
1314,
365,
20042,
370,
1172,
6317,
3462,
14,
339,
658,
22124,
64,
267,
14579,
402,
314,
5023,
1202,
14,
14579,
365,
2013,
315,
12995,
4501,
14,
710,
267,
849,
365,
5504,
12995,
13,
3438,
12,
15131,
282,
1568,
3144,
5023,
14,
398,
2508,
7445,
447,
499,
14,
16,
272,
408,
272,
536,
275,
283,
50,
6145,
7,
272,
5481,
275,
788,
2591,
70,
418,
272,
6203,
275,
17855,
2591,
70,
418,
339,
347,
636,
826,
721,
277,
12,
1011,
1419,
304,
267,
519,
624,
267,
10961,
1511,
10226,
26,
398,
1124,
4246,
1409,
1040,
288,
2812,
402,
314,
5023,
1202,
14,
18615,
367,
2893,
506,
12692,
35,
567,
4446,
7053,
14700,
288,
370,
9848,
4165,
314,
849,
1314,
365,
1124,
1154,
70,
632,
11641,
26809,
710,
820,
6145,
288,
8929,
6108,
11171,
626,
1124,
60,
70,
632,
11641,
1040,
787,
298,
9515,
13,
16966,
542,
20546,
288,
436,
308,
796,
542,
20546,
26219,
1674,
869,
13458,
4036,
820,
6145,
4514,
13516,
83,
288,
314,
2011,
3595,
818,
11641,
1396,
398,
408,
267,
31084,
855,
826,
721,
277,
12,
1011,
1419,
9,
267,
291,
14,
4246,
1409,
275,
1511,
14,
362,
360,
4246,
1409,
358,
503,
2125,
267,
291,
14,
22124,
275,
664,
63,
442,
63,
2992,
8,
1419,
12,
283,
22124,
297,
378,
9,
339,
347,
485,
3765,
8,
277,
12,
1318,
304,
267,
372,
1318,
14,
1814,
8,
85,
8124,
297,
399,
8124,
1103,
358,
971,
673,
1275,
1814,
8,
85,
16019,
297,
399,
8124,
91,
358,
971,
673,
1275,
1814,
8,
85,
936,
297,
399,
8124,
12216,
339,
347,
485,
3765,
63,
505,
8,
277,
12,
1318,
304,
267,
327,
2701,
3326,
12,
1077,
8120,
282,
7425,
10238,
1742,
293,
86,
434,
267,
340,
440,
1318,
26,
288,
372,
399,
891,
398,
327,
4772,
1318,
267,
1318,
275,
291,
423,
3765,
8,
505,
9,
398,
4123,
275,
942,
267,
367,
286,
315,
1318,
26,
288,
20087,
275,
6206,
8,
67,
9,
288,
340,
20087,
665,
334,
18,
538,
23,
304,
355,
327,
10485,
4528,
355,
4123,
14,
740,
8,
495,
8,
67,
430,
288,
916,
334,
18,
538,
23,
9,
2695,
20087,
665,
334,
18,
538,
975,
304,
355,
327,
2849,
2649,
4772,
3414,
355,
4123,
14,
740,
8,
85,
16019,
1103,
85,
5,
68,
6834,
450,
20087,
9,
288,
916,
334,
18,
538,
975,
9,
2695,
20087,
26,
355,
327,
820,
6145,
10976,
2649,
370,
3193,
5821,
14,
355,
327,
18771,
6296,
13095,
6342,
355,
4123,
14,
740,
8,
85,
16019,
1103,
85,
5,
68,
8847,
1103,
85,
5,
68,
6834,
450,
485,
16380,
3852,
8,
6413,
430,
398,
372,
399,
17067,
904,
8,
1436,
680,
1814,
8,
85,
1154,
78,
297,
399,
8124,
462,
60,
78,
358,
339,
347,
1475,
63,
324,
8167,
8,
277,
12,
1526,
1365,
12,
4386,
304,
267,
327,
519,
3249,
413,
14,
24,
1406,
267,
4386,
14,
952,
8,
85,
16019,
1103,
2591,
70,
17,
1103,
22204,
1103,
947,
16,
1103,
318,
70,
16,
7,
1993,
399,
16019,
1103,
4246,
14806,
26156,
70,
16,
1103,
70,
632,
11641,
1103,
70,
2700,
81,
17,
1103,
70,
6043,
16,
5,
83,
27,
4863,
7,
1993,
399,
16019,
1103,
761,
361,
3345,
8942,
450,
334,
277,
14,
4246,
1409,
436,
1460,
399,
7,
283,
435,
291,
423,
3765,
8,
277,
14,
4246,
1409,
9,
503,
1460,
399,
7,
1333,
398,
327,
3957,
9229,
436,
3354,
3062,
315,
282,
4412,
370,
2879,
3062,
2945,
14,
267,
3164,
63,
4745,
275,
1052,
267,
3268,
275,
413,
267,
367,
5501,
3449,
315,
291,
14,
2487,
26,
288,
367,
3164,
315,
3449,
459,
2326,
995,
3449,
459,
28710,
995,
3449,
459,
8665,
2565,
355,
340,
3164,
436,
3164,
440,
315,
3164,
63,
4745,
26,
490,
3164,
63,
4745,
59,
2326,
61,
275,
3268,
490,
4386,
14,
952,
8,
85,
8124,
581,
5,
68,
1103,
7731,
5,
68,
1103,
6304,
5,
68,
8942,
450,
334,
717,
1109,
8,
2326,
59,
16,
26,
18,
467,
3193,
395,
717,
1109,
8,
2326,
59,
18,
26,
20,
467,
3193,
395,
717,
1109,
8,
2326,
59,
20,
26,
22,
467,
3193,
9,
490,
5082,
490,
3268,
847,
413,
267,
4386,
14,
952,
8,
85,
936,
1103,
70,
16,
5320,
267,
340,
291,
14,
22124,
26,
288,
4386,
14,
952,
8,
85,
8124,
2319,
5,
68,
7,
450,
334,
277,
14,
22124,
430,
398,
327,
11850,
2547,
267,
367,
17860,
12,
574,
315,
1526,
1365,
26,
288,
1830,
440,
291,
14,
2487,
14,
12955,
63,
1418,
8,
21002,
9,
436,
17860,
14,
1708,
26,
355,
17860,
275,
17860,
14,
1708,
288,
3449,
275,
291,
14,
2487,
14,
2487,
63,
509,
63,
1418,
8,
21002,
9
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
14,
2591,
70,
272,
18294,
2878,
23597,
339,
437,
9698,
626,
12821,
820,
6145,
1584,
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,
504,
13277,
14,
8911,
492,
31084,
199,
504,
13277,
14,
1974,
492,
664,
63,
442,
63,
2992,
12,
485,
16380,
3852,
421,
199,
363,
452,
363,
275,
788,
50,
3249,
7772,
418,
421,
199,
533,
820,
3249,
7772,
8,
7772,
304,
272,
408,
272,
9701,
4645,
465,
820,
6145,
9189,
14,
961,
9698,
5847,
4704,
2615,
820,
6145,
272,
8247,
543,
3164,
2556,
436,
1163,
2997,
8292,
14,
31778,
449,
367,
11247,
436,
272,
510,
9209,
1901,
15332,
8,
50,
9,
14644,
8,
50,
9,
8247,
14,
339,
7754,
5317,
626,
1124,
2991,
1040,
436,
1124,
810,
28139,
1040,
1511,
787,
5525,
14,
272,
710,
820,
6145,
1475,
365,
10485,
302,
17330,
12,
1325,
10022,
2649,
4110,
6657,
272,
2419,
6080,
370,
4772,
8013,
14,
339,
2508,
7445,
447,
378,
14,
22,
339,
10961,
1511,
10226,
26,
339,
658,
2487,
64,
267,
710,
3449,
370,
675,
12,
883,
506,
282,
1059,
503,
282,
19442,
5516,
334,
885,
26,
267,
12692,
885,
14700,
680,
339,
658,
4246,
1409,
64,
267,
710,
1202,
5023,
21450,
317,
89,
12,
367,
2893,
1124,
4734,
1745,
5444,
65,
428,
796,
4345,
7827,
370,
267,
2005,
7809,
5023,
1314,
365,
20042,
370,
1172,
6317,
3462,
14,
339,
658,
22124,
64,
267,
14579,
402,
314,
5023,
1202,
14,
14579,
365,
2013,
315,
12995,
4501,
14,
710,
267,
849,
365,
5504,
12995,
13,
3438,
12,
15131,
282,
1568,
3144,
5023,
14,
398,
2508,
7445,
447,
499,
14,
16,
272,
408,
272,
536,
275,
283,
50,
6145,
7,
272,
5481,
275,
788,
2591,
70,
418,
272,
6203,
275,
17855,
2591,
70,
418,
339,
347,
636,
826,
721,
277,
12,
1011,
1419,
304,
267,
519,
624,
267,
10961,
1511,
10226,
26,
398,
1124,
4246,
1409,
1040,
288,
2812,
402,
314,
5023,
1202,
14,
18615,
367,
2893,
506,
12692,
35,
567,
4446,
7053,
14700,
288,
370,
9848,
4165,
314,
849,
1314,
365,
1124,
1154,
70,
632,
11641,
26809,
710,
820,
6145,
288,
8929,
6108,
11171,
626,
1124,
60,
70,
632,
11641,
1040,
787,
298,
9515,
13,
16966,
542,
20546,
288,
436,
308,
796,
542,
20546,
26219,
1674,
869,
13458,
4036,
820,
6145,
4514,
13516,
83,
288,
314,
2011,
3595,
818,
11641,
1396,
398,
408,
267,
31084,
855,
826,
721,
277,
12,
1011,
1419,
9,
267,
291,
14,
4246,
1409,
275,
1511,
14,
362,
360,
4246,
1409,
358,
503,
2125,
267,
291,
14,
22124,
275,
664,
63,
442,
63,
2992,
8,
1419,
12,
283,
22124,
297,
378,
9,
339,
347,
485,
3765,
8,
277,
12,
1318,
304,
267,
372,
1318,
14,
1814,
8,
85,
8124,
297,
399,
8124,
1103,
358,
971,
673,
1275,
1814,
8,
85,
16019,
297,
399,
8124,
91,
358,
971,
673,
1275,
1814,
8,
85,
936,
297,
399,
8124,
12216,
339,
347,
485,
3765,
63,
505,
8,
277,
12,
1318,
304,
267,
327,
2701,
3326,
12,
1077,
8120,
282,
7425,
10238,
1742,
293,
86,
434,
267,
340,
440,
1318,
26,
288,
372,
399,
891,
398,
327,
4772,
1318,
267,
1318,
275,
291,
423,
3765,
8,
505,
9,
398,
4123,
275,
942,
267,
367,
286,
315,
1318,
26,
288,
20087,
275,
6206,
8,
67,
9,
288,
340,
20087,
665,
334,
18,
538,
23,
304,
355,
327,
10485,
4528,
355,
4123,
14,
740,
8,
495,
8,
67,
430,
288,
916,
334,
18,
538,
23,
9,
2695,
20087,
665,
334,
18,
538,
975,
304,
355,
327,
2849,
2649,
4772,
3414,
355,
4123,
14,
740,
8,
85,
16019,
1103,
85,
5,
68,
6834,
450,
20087,
9,
288,
916,
334,
18,
538,
975,
9,
2695,
20087,
26,
355,
327,
820,
6145,
10976,
2649,
370,
3193,
5821,
14,
355,
327,
18771,
6296,
13095,
6342,
355,
4123,
14,
740,
8,
85,
16019,
1103,
85,
5,
68,
8847,
1103,
85,
5,
68,
6834,
450,
485,
16380,
3852,
8,
6413,
430,
398,
372,
399,
17067,
904,
8,
1436,
680,
1814,
8,
85,
1154,
78,
297,
399,
8124,
462,
60,
78,
358,
339,
347,
1475,
63,
324,
8167,
8,
277,
12,
1526,
1365,
12,
4386,
304,
267,
327,
519,
3249,
413,
14,
24,
1406,
267,
4386,
14,
952,
8,
85,
16019,
1103,
2591,
70,
17,
1103,
22204,
1103,
947,
16,
1103,
318,
70,
16,
7,
1993,
399,
16019,
1103,
4246,
14806,
26156,
70,
16,
1103,
70,
632,
11641,
1103,
70,
2700,
81,
17,
1103,
70,
6043,
16,
5,
83,
27,
4863,
7,
1993,
399,
16019,
1103,
761,
361,
3345,
8942,
450,
334,
277,
14,
4246,
1409,
436,
1460,
399,
7,
283,
435,
291,
423,
3765,
8,
277,
14,
4246,
1409,
9,
503,
1460,
399,
7,
1333,
398,
327,
3957,
9229,
436,
3354,
3062,
315,
282,
4412,
370,
2879,
3062,
2945,
14,
267,
3164,
63,
4745,
275,
1052,
267,
3268,
275,
413,
267,
367,
5501,
3449,
315,
291,
14,
2487,
26,
288,
367,
3164,
315,
3449,
459,
2326,
995,
3449,
459,
28710,
995,
3449,
459,
8665,
2565,
355,
340,
3164,
436,
3164,
440,
315,
3164,
63,
4745,
26,
490,
3164,
63,
4745,
59,
2326,
61,
275,
3268,
490,
4386,
14,
952,
8,
85,
8124,
581,
5,
68,
1103,
7731,
5,
68,
1103,
6304,
5,
68,
8942,
450,
334,
717,
1109,
8,
2326,
59,
16,
26,
18,
467,
3193,
395,
717,
1109,
8,
2326,
59,
18,
26,
20,
467,
3193,
395,
717,
1109,
8,
2326,
59,
20,
26,
22,
467,
3193,
9,
490,
5082,
490,
3268,
847,
413,
267,
4386,
14,
952,
8,
85,
936,
1103,
70,
16,
5320,
267,
340,
291,
14,
22124,
26,
288,
4386,
14,
952,
8,
85,
8124,
2319,
5,
68,
7,
450,
334,
277,
14,
22124,
430,
398,
327,
11850,
2547,
267,
367,
17860,
12,
574,
315,
1526,
1365,
26,
288,
1830,
440,
291,
14,
2487,
14,
12955,
63,
1418,
8,
21002,
9,
436,
17860,
14,
1708,
26,
355,
17860,
275,
17860,
14,
1708,
288,
3449,
275,
291,
14,
2487,
14,
2487,
63,
509,
63,
1418,
8,
21002,
9,
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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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
] |
JianyuWang/neutron
|
neutron/db/l3_agentschedulers_db.py
|
7
|
22800
|
# Copyright (c) 2013 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.
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_log import log as logging
import oslo_messaging
import six
import sqlalchemy as sa
from sqlalchemy import func
from sqlalchemy import or_
from sqlalchemy import orm
from sqlalchemy.orm import joinedload
from sqlalchemy import sql
from neutron.common import constants
from neutron.common import utils as n_utils
from neutron import context as n_ctx
from neutron.db import agents_db
from neutron.db import agentschedulers_db
from neutron.db import l3_attrs_db
from neutron.db import model_base
from neutron.extensions import l3agentscheduler
from neutron.i18n import _LE, _LI, _LW
from neutron import manager
from neutron.plugins.common import constants as service_constants
LOG = logging.getLogger(__name__)
L3_AGENTS_SCHEDULER_OPTS = [
cfg.StrOpt('router_scheduler_driver',
default='neutron.scheduler.l3_agent_scheduler.'
'LeastRoutersScheduler',
help=_('Driver to use for scheduling '
'router to a default L3 agent')),
cfg.BoolOpt('router_auto_schedule', default=True,
help=_('Allow auto scheduling of routers to L3 agent.')),
cfg.BoolOpt('allow_automatic_l3agent_failover', default=False,
help=_('Automatically reschedule routers from offline L3 '
'agents to online L3 agents.')),
]
cfg.CONF.register_opts(L3_AGENTS_SCHEDULER_OPTS)
class RouterL3AgentBinding(model_base.BASEV2):
"""Represents binding between neutron routers and L3 agents."""
router_id = sa.Column(sa.String(36),
sa.ForeignKey("routers.id", ondelete='CASCADE'),
primary_key=True)
l3_agent = orm.relation(agents_db.Agent)
l3_agent_id = sa.Column(sa.String(36),
sa.ForeignKey("agents.id", ondelete='CASCADE'),
primary_key=True)
class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
agentschedulers_db.AgentSchedulerDbMixin):
"""Mixin class to add l3 agent scheduler extension to plugins
using the l3 agent for routing.
"""
router_scheduler = None
def start_periodic_l3_agent_status_check(self):
if not cfg.CONF.allow_automatic_l3agent_failover:
LOG.info(_LI("Skipping period L3 agent status check because "
"automatic router rescheduling is disabled."))
return
self.setup_agent_status_check(
self.reschedule_routers_from_down_agents)
def reschedule_routers_from_down_agents(self):
"""Reschedule routers from down l3 agents if admin state is up."""
agent_dead_limit = self.agent_dead_limit_seconds()
self.wait_down_agents('L3', agent_dead_limit)
cutoff = self.get_cutoff_time(agent_dead_limit)
context = n_ctx.get_admin_context()
down_bindings = (
context.session.query(RouterL3AgentBinding).
join(agents_db.Agent).
filter(agents_db.Agent.heartbeat_timestamp < cutoff,
agents_db.Agent.admin_state_up).
outerjoin(l3_attrs_db.RouterExtraAttributes,
l3_attrs_db.RouterExtraAttributes.router_id ==
RouterL3AgentBinding.router_id).
filter(sa.or_(l3_attrs_db.RouterExtraAttributes.ha == sql.false(),
l3_attrs_db.RouterExtraAttributes.ha == sql.null())))
try:
for binding in down_bindings:
agent_mode = self._get_agent_mode(binding.l3_agent)
if agent_mode == constants.L3_AGENT_MODE_DVR:
# rescheduling from l3 dvr agent on compute node doesn't
# make sense. Router will be removed from that agent once
# there are no dvr serviceable ports on that compute node
LOG.warn(_LW('L3 DVR agent on node %(host)s is down. '
'Not rescheduling from agent in \'dvr\' '
'mode.'), {'host': binding.l3_agent.host})
continue
LOG.warn(_LW(
"Rescheduling router %(router)s from agent %(agent)s "
"because the agent did not report to the server in "
"the last %(dead_time)s seconds."),
{'router': binding.router_id,
'agent': binding.l3_agent_id,
'dead_time': agent_dead_limit})
try:
self.reschedule_router(context, binding.router_id)
except (l3agentscheduler.RouterReschedulingFailed,
oslo_messaging.RemoteError):
# Catch individual router rescheduling errors here
# so one broken one doesn't stop the iteration.
LOG.exception(_LE("Failed to reschedule router %s"),
binding.router_id)
except Exception:
# we want to be thorough and catch whatever is raised
# to avoid loop abortion
LOG.exception(_LE("Exception encountered during router "
"rescheduling."))
def _get_agent_mode(self, agent_db):
agent_conf = self.get_configuration_dict(agent_db)
return agent_conf.get(constants.L3_AGENT_MODE,
constants.L3_AGENT_MODE_LEGACY)
def validate_agent_router_combination(self, context, agent, router):
"""Validate if the router can be correctly assigned to the agent.
:raises: RouterL3AgentMismatch if attempting to assign DVR router
to legacy agent, or centralized router to compute's L3 agents.
:raises: InvalidL3Agent if attempting to assign router to an
unsuitable agent (disabled, type != L3, incompatible configuration)
:raises: DVRL3CannotAssignToDvrAgent if attempting to assign DVR
router from one DVR Agent to another.
"""
if agent['agent_type'] != constants.AGENT_TYPE_L3:
raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
is_distributed = router.get('distributed')
agent_mode = self._get_agent_mode(agent)
router_type = (
'distributed' if is_distributed else
'centralized')
is_agent_router_types_incompatible = (
agent_mode == constants.L3_AGENT_MODE_DVR and not is_distributed
or agent_mode == constants.L3_AGENT_MODE_LEGACY and is_distributed
)
if is_agent_router_types_incompatible:
raise l3agentscheduler.RouterL3AgentMismatch(
router_type=router_type, router_id=router['id'],
agent_mode=agent_mode, agent_id=agent['id'])
if agent_mode == constants.L3_AGENT_MODE_DVR and is_distributed:
raise l3agentscheduler.DVRL3CannotAssignToDvrAgent(
router_type=router_type, router_id=router['id'],
agent_id=agent['id'])
is_suitable_agent = (
agentschedulers_db.services_available(agent['admin_state_up']) and
(self.get_l3_agent_candidates(context, router,
[agent],
ignore_admin_state=True) or
self.get_snat_candidates(router, [agent]))
)
if not is_suitable_agent:
raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
def check_agent_router_scheduling_needed(self, context, agent, router):
"""Check if the router scheduling is needed.
:raises: RouterHostedByL3Agent if router is already assigned
to a different agent.
:returns: True if scheduling is needed, otherwise False
"""
router_id = router['id']
agent_id = agent['id']
query = context.session.query(RouterL3AgentBinding)
bindings = query.filter_by(router_id=router_id).all()
if not bindings:
return True
for binding in bindings:
if binding.l3_agent_id == agent_id:
# router already bound to the agent we need
return False
if router.get('ha'):
return True
# legacy router case: router is already bound to some agent
raise l3agentscheduler.RouterHostedByL3Agent(
router_id=router_id,
agent_id=bindings[0].l3_agent_id)
def create_router_to_agent_binding(self, context, agent, router):
"""Create router to agent binding."""
router_id = router['id']
agent_id = agent['id']
if self.router_scheduler:
try:
if router.get('ha'):
plugin = manager.NeutronManager.get_service_plugins().get(
service_constants.L3_ROUTER_NAT)
self.router_scheduler.create_ha_port_and_bind(
plugin, context, router['id'],
router['tenant_id'], agent)
else:
self.router_scheduler.bind_router(
context, router_id, agent)
except db_exc.DBError:
raise l3agentscheduler.RouterSchedulingFailed(
router_id=router_id, agent_id=agent_id)
def add_router_to_l3_agent(self, context, agent_id, router_id):
"""Add a l3 agent to host a router."""
with context.session.begin(subtransactions=True):
router = self.get_router(context, router_id)
agent = self._get_agent(context, agent_id)
self.validate_agent_router_combination(context, agent, router)
if self.check_agent_router_scheduling_needed(
context, agent, router):
self.create_router_to_agent_binding(context, agent, router)
else:
return
l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
if l3_notifier:
l3_notifier.router_added_to_agent(
context, [router_id], agent.host)
def remove_router_from_l3_agent(self, context, agent_id, router_id):
"""Remove the router from l3 agent.
After removal, the router will be non-hosted until there is update
which leads to re-schedule or be added to another agent manually.
"""
agent = self._get_agent(context, agent_id)
self._unbind_router(context, router_id, agent_id)
router = self.get_router(context, router_id)
if router.get('ha'):
plugin = manager.NeutronManager.get_service_plugins().get(
service_constants.L3_ROUTER_NAT)
plugin.delete_ha_interfaces_on_host(context, router_id, agent.host)
l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
if l3_notifier:
l3_notifier.router_removed_from_agent(
context, router_id, agent.host)
def _unbind_router(self, context, router_id, agent_id):
with context.session.begin(subtransactions=True):
query = context.session.query(RouterL3AgentBinding)
query = query.filter(
RouterL3AgentBinding.router_id == router_id,
RouterL3AgentBinding.l3_agent_id == agent_id)
query.delete()
def reschedule_router(self, context, router_id, candidates=None):
"""Reschedule router to a new l3 agent
Remove the router from the agent(s) currently hosting it and
schedule it again
"""
cur_agents = self.list_l3_agents_hosting_router(
context, router_id)['agents']
with context.session.begin(subtransactions=True):
for agent in cur_agents:
self._unbind_router(context, router_id, agent['id'])
new_agent = self.schedule_router(context, router_id,
candidates=candidates)
if not new_agent:
raise l3agentscheduler.RouterReschedulingFailed(
router_id=router_id)
l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
if l3_notifier:
for agent in cur_agents:
l3_notifier.router_removed_from_agent(
context, router_id, agent['host'])
l3_notifier.router_added_to_agent(
context, [router_id], new_agent.host)
def list_routers_on_l3_agent(self, context, agent_id):
query = context.session.query(RouterL3AgentBinding.router_id)
query = query.filter(RouterL3AgentBinding.l3_agent_id == agent_id)
router_ids = [item[0] for item in query]
if router_ids:
return {'routers':
self.get_routers(context, filters={'id': router_ids})}
else:
# Exception will be thrown if the requested agent does not exist.
self._get_agent(context, agent_id)
return {'routers': []}
def _get_active_l3_agent_routers_sync_data(self, context, host, agent,
router_ids):
if n_utils.is_extension_supported(self,
constants.L3_HA_MODE_EXT_ALIAS):
return self.get_ha_sync_data_for_host(context, host,
router_ids=router_ids,
active=True)
return self.get_sync_data(context, router_ids=router_ids, active=True)
def list_active_sync_routers_on_active_l3_agent(
self, context, host, router_ids):
agent = self._get_agent_by_type_and_host(
context, constants.AGENT_TYPE_L3, host)
if not agentschedulers_db.services_available(agent.admin_state_up):
return []
query = context.session.query(RouterL3AgentBinding.router_id)
query = query.filter(
RouterL3AgentBinding.l3_agent_id == agent.id)
if router_ids:
query = query.filter(
RouterL3AgentBinding.router_id.in_(router_ids))
router_ids = [item[0] for item in query]
if router_ids:
return self._get_active_l3_agent_routers_sync_data(context, host,
agent,
router_ids)
return []
def get_l3_agents_hosting_routers(self, context, router_ids,
admin_state_up=None,
active=None):
if not router_ids:
return []
query = context.session.query(RouterL3AgentBinding)
query = query.options(orm.contains_eager(
RouterL3AgentBinding.l3_agent))
query = query.join(RouterL3AgentBinding.l3_agent)
query = query.filter(RouterL3AgentBinding.router_id.in_(router_ids))
if admin_state_up is not None:
query = (query.filter(agents_db.Agent.admin_state_up ==
admin_state_up))
l3_agents = [binding.l3_agent for binding in query]
if active is not None:
l3_agents = [l3_agent for l3_agent in
l3_agents if not
agents_db.AgentDbMixin.is_agent_down(
l3_agent['heartbeat_timestamp'])]
return l3_agents
def _get_l3_bindings_hosting_routers(self, context, router_ids):
if not router_ids:
return []
query = context.session.query(RouterL3AgentBinding)
query = query.options(joinedload('l3_agent')).filter(
RouterL3AgentBinding.router_id.in_(router_ids))
return query.all()
def list_l3_agents_hosting_router(self, context, router_id):
with context.session.begin(subtransactions=True):
bindings = self._get_l3_bindings_hosting_routers(
context, [router_id])
return {'agents': [self._make_agent_dict(binding.l3_agent) for
binding in bindings]}
def get_l3_agents(self, context, active=None, filters=None):
query = context.session.query(agents_db.Agent)
query = query.filter(
agents_db.Agent.agent_type == constants.AGENT_TYPE_L3)
if active is not None:
query = (query.filter(agents_db.Agent.admin_state_up == active))
if filters:
for key, value in six.iteritems(filters):
column = getattr(agents_db.Agent, key, None)
if column:
if not value:
return []
query = query.filter(column.in_(value))
agent_modes = filters.get('agent_modes', [])
if agent_modes:
agent_mode_key = '\"agent_mode\": \"'
configuration_filter = (
[agents_db.Agent.configurations.contains('%s%s\"' %
(agent_mode_key, agent_mode))
for agent_mode in agent_modes])
query = query.filter(or_(*configuration_filter))
return [l3_agent
for l3_agent in query
if agentschedulers_db.AgentSchedulerDbMixin.is_eligible_agent(
active, l3_agent)]
def check_ports_exist_on_l3agent(self, context, l3_agent, router_id):
"""
This function checks for existence of dvr serviceable
ports on the host, running the input l3agent.
"""
subnet_ids = self.get_subnet_ids_on_router(context, router_id)
if not subnet_ids:
return False
core_plugin = manager.NeutronManager.get_plugin()
# NOTE(swami):Before checking for existence of dvr
# serviceable ports on the host managed by the l3
# agent, let's verify if at least one subnet has
# dhcp enabled. If so, then the host will have a
# dvr serviceable port, which is in fact the DHCP
# port.
# This optimization is valid assuming that the L3
# DVR_SNAT node will be the one hosting the DHCP
# Agent.
agent_mode = self._get_agent_mode(l3_agent)
for subnet_id in subnet_ids:
subnet_dict = core_plugin.get_subnet(context, subnet_id)
if (subnet_dict['enable_dhcp'] and (
agent_mode == constants.L3_AGENT_MODE_DVR_SNAT)):
return True
filter = {'fixed_ips': {'subnet_id': subnet_ids}}
ports = core_plugin.get_ports(context, filters=filter)
for port in ports:
if (n_utils.is_dvr_serviced(port['device_owner']) and
l3_agent['host'] == port['binding:host_id']):
return True
return False
def get_l3_agent_candidates(self, context, sync_router, l3_agents,
ignore_admin_state=False):
"""Get the valid l3 agents for the router from a list of l3_agents."""
candidates = []
for l3_agent in l3_agents:
if not ignore_admin_state and not l3_agent.admin_state_up:
# ignore_admin_state True comes from manual scheduling
# where admin_state_up judgement is already done.
continue
agent_conf = self.get_configuration_dict(l3_agent)
router_id = agent_conf.get('router_id', None)
use_namespaces = agent_conf.get('use_namespaces', True)
handle_internal_only_routers = agent_conf.get(
'handle_internal_only_routers', True)
gateway_external_network_id = agent_conf.get(
'gateway_external_network_id', None)
agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
constants.L3_AGENT_MODE_LEGACY)
if not use_namespaces and router_id != sync_router['id']:
continue
ex_net_id = (sync_router['external_gateway_info'] or {}).get(
'network_id')
if ((not ex_net_id and not handle_internal_only_routers) or
(ex_net_id and gateway_external_network_id and
ex_net_id != gateway_external_network_id)):
continue
is_router_distributed = sync_router.get('distributed', False)
if agent_mode in (
constants.L3_AGENT_MODE_LEGACY,
constants.L3_AGENT_MODE_DVR_SNAT) and (
not is_router_distributed):
candidates.append(l3_agent)
elif is_router_distributed and agent_mode.startswith(
constants.L3_AGENT_MODE_DVR) and (
self.check_ports_exist_on_l3agent(
context, l3_agent, sync_router['id'])):
candidates.append(l3_agent)
return candidates
def auto_schedule_routers(self, context, host, router_ids):
if self.router_scheduler:
return self.router_scheduler.auto_schedule_routers(
self, context, host, router_ids)
def schedule_router(self, context, router, candidates=None):
if self.router_scheduler:
return self.router_scheduler.schedule(
self, context, router, candidates=candidates)
def schedule_routers(self, context, routers):
"""Schedule the routers to l3 agents."""
for router in routers:
self.schedule_router(context, router, candidates=None)
def get_l3_agent_with_min_routers(self, context, agent_ids):
"""Return l3 agent with the least number of routers."""
if not agent_ids:
return None
query = context.session.query(
agents_db.Agent,
func.count(
RouterL3AgentBinding.router_id
).label('count')).outerjoin(RouterL3AgentBinding).group_by(
agents_db.Agent.id,
RouterL3AgentBinding.l3_agent_id).order_by('count')
res = query.filter(agents_db.Agent.id.in_(agent_ids)).first()
return res[0]
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6171,
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,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
697,
492,
1919,
465,
1592,
63,
2804,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
646,
11258,
63,
27782,
199,
646,
3816,
199,
646,
8335,
465,
2937,
199,
504,
8335,
492,
2562,
199,
504,
8335,
492,
503,
63,
199,
504,
8335,
492,
9813,
199,
504,
8335,
14,
1025,
492,
16538,
912,
199,
504,
8335,
492,
3875,
199,
199,
504,
8224,
14,
2330,
492,
5262,
199,
504,
8224,
14,
2330,
492,
3778,
465,
302,
63,
1208,
199,
504,
8224,
492,
1067,
465,
302,
63,
3799,
199,
504,
8224,
14,
697,
492,
22867,
63,
697,
199,
504,
8224,
14,
697,
492,
6631,
7211,
2393,
63,
697,
199,
504,
8224,
14,
697,
492,
634,
19,
63,
3288,
63,
697,
199,
504,
8224,
14,
697,
492,
1402,
63,
1095,
199,
504,
8224,
14,
5359,
492,
634,
19,
4054,
8874,
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,
5265,
14,
2330,
492,
5262,
465,
2435,
63,
5559,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
44,
19,
63,
14565,
51,
63,
27944,
1293,
540,
63,
25636,
275,
359,
272,
4810,
14,
19340,
360,
4995,
63,
8874,
63,
3090,
297,
2049,
849,
534,
10271,
14,
8874,
14,
76,
19,
63,
4054,
63,
8874,
3530,
2432,
283,
2553,
1810,
5407,
878,
11251,
297,
2049,
1720,
12397,
6158,
370,
675,
367,
23800,
283,
1993,
283,
4995,
370,
282,
849,
491,
19,
6631,
3855,
272,
4810,
14,
10349,
9985,
360,
4995,
63,
2495,
63,
7211,
297,
849,
29,
549,
12,
355,
1720,
12397,
7852,
2599,
23800,
402,
24464,
370,
491,
19,
6631,
2659,
395,
272,
4810,
14,
10349,
9985,
360,
3306,
63,
23292,
63,
76,
19,
4054,
63,
667,
23165,
297,
849,
29,
797,
12,
355,
1720,
12397,
3358,
17174,
522,
3082,
24464,
687,
26302,
491,
19,
283,
2432,
283,
14250,
370,
18470,
491,
19,
22867,
2659,
395,
199,
61,
199,
199,
4128,
14,
3103,
14,
2683,
63,
3291,
8,
44,
19,
63,
14565,
51,
63,
27944,
1293,
540,
63,
25636,
9,
421,
199,
533,
22708,
44,
19,
7788,
17490,
8,
1238,
63,
1095,
14,
5825,
54,
18,
304,
272,
408,
18089,
11696,
3382,
8224,
24464,
436,
491,
19,
22867,
1041,
339,
6197,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
395,
2079,
2937,
14,
3190,
480,
17292,
14,
344,
401,
16549,
534,
10855,
659,
2079,
5062,
63,
498,
29,
549,
9,
272,
634,
19,
63,
4054,
275,
9813,
14,
5690,
8,
14250,
63,
697,
14,
7788,
9,
272,
634,
19,
63,
4054,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
395,
1169,
2937,
14,
3190,
480,
14250,
14,
344,
401,
16549,
534,
10855,
659,
1169,
5062,
63,
498,
29,
549,
9,
421,
199,
533,
491,
19,
7788,
11251,
8882,
4256,
8,
76,
19,
4054,
8874,
14,
44,
19,
7788,
11251,
5061,
1563,
12,
2892,
6631,
7211,
2393,
63,
697,
14,
7788,
11251,
8882,
4256,
304,
272,
408,
4256,
1021,
370,
1050,
634,
19,
6631,
11899,
3329,
370,
8963,
272,
1808,
314,
634,
19,
6631,
367,
14870,
14,
272,
408,
339,
6197,
63,
8874,
275,
488,
339,
347,
1343,
63,
20339,
63,
76,
19,
63,
4054,
63,
1205,
63,
1074,
8,
277,
304,
267,
340,
440,
4810,
14,
3103,
14,
3306,
63,
23292,
63,
76,
19,
4054,
63,
667,
23165,
26,
288,
5051,
14,
815,
1547,
2673,
480,
18297,
6247,
491,
19,
6631,
2004,
1104,
2952,
298,
586,
298,
23292,
6197,
522,
1809,
15633,
365,
6980,
13853,
288,
372,
398,
291,
14,
2758,
63,
4054,
63,
1205,
63,
1074,
8,
288,
291,
14,
470,
3082,
63,
17292,
63,
504,
63,
2110,
63,
14250,
9,
339,
347,
522,
3082,
63,
17292,
63,
504,
63,
2110,
63,
14250,
8,
277,
304,
267,
408,
1322,
3082,
24464,
687,
3224,
634,
19,
22867,
340,
4628,
1174,
365,
1536,
1041,
267,
6631,
63,
10957,
63,
3097,
275,
291,
14,
4054,
63,
10957,
63,
3097,
63,
4515,
342,
267,
291,
14,
2573,
63,
2110,
63,
14250,
360,
44,
19,
297,
6631,
63,
10957,
63,
3097,
9,
267,
17875,
275,
291,
14,
362,
63,
17708,
63,
521,
8,
4054,
63,
10957,
63,
3097,
9,
398,
1067,
275,
302,
63,
3799,
14,
362,
63,
2113,
63,
1100,
342,
267,
3224,
63,
10880,
275,
334,
288,
1067,
14,
1730,
14,
1131,
8,
11691,
44,
19,
7788,
17490,
680,
288,
4263,
8,
14250,
63,
697,
14,
7788,
680,
288,
2457,
8,
14250,
63,
697,
14,
7788,
14,
22685,
63,
3954,
665,
17875,
12,
673,
22867,
63,
697,
14,
7788,
14,
2113,
63,
929,
63,
384,
680,
288,
6890,
904,
8,
76,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
12,
1993,
634,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
14,
4995,
63,
344,
508,
1993,
22708,
44,
19,
7788,
17490,
14,
4995,
63,
344,
680,
288,
2457,
8,
2231,
14,
269,
2531,
76,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
14,
2411,
508,
3875,
14,
3910,
1062,
2079,
634,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
14,
2411,
508,
3875,
14,
2307,
16890,
267,
862,
26,
288,
367,
11696
] |
[
1898,
334,
67,
9,
6171,
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,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
697,
492,
1919,
465,
1592,
63,
2804,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
646,
11258,
63,
27782,
199,
646,
3816,
199,
646,
8335,
465,
2937,
199,
504,
8335,
492,
2562,
199,
504,
8335,
492,
503,
63,
199,
504,
8335,
492,
9813,
199,
504,
8335,
14,
1025,
492,
16538,
912,
199,
504,
8335,
492,
3875,
199,
199,
504,
8224,
14,
2330,
492,
5262,
199,
504,
8224,
14,
2330,
492,
3778,
465,
302,
63,
1208,
199,
504,
8224,
492,
1067,
465,
302,
63,
3799,
199,
504,
8224,
14,
697,
492,
22867,
63,
697,
199,
504,
8224,
14,
697,
492,
6631,
7211,
2393,
63,
697,
199,
504,
8224,
14,
697,
492,
634,
19,
63,
3288,
63,
697,
199,
504,
8224,
14,
697,
492,
1402,
63,
1095,
199,
504,
8224,
14,
5359,
492,
634,
19,
4054,
8874,
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,
5265,
14,
2330,
492,
5262,
465,
2435,
63,
5559,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
44,
19,
63,
14565,
51,
63,
27944,
1293,
540,
63,
25636,
275,
359,
272,
4810,
14,
19340,
360,
4995,
63,
8874,
63,
3090,
297,
2049,
849,
534,
10271,
14,
8874,
14,
76,
19,
63,
4054,
63,
8874,
3530,
2432,
283,
2553,
1810,
5407,
878,
11251,
297,
2049,
1720,
12397,
6158,
370,
675,
367,
23800,
283,
1993,
283,
4995,
370,
282,
849,
491,
19,
6631,
3855,
272,
4810,
14,
10349,
9985,
360,
4995,
63,
2495,
63,
7211,
297,
849,
29,
549,
12,
355,
1720,
12397,
7852,
2599,
23800,
402,
24464,
370,
491,
19,
6631,
2659,
395,
272,
4810,
14,
10349,
9985,
360,
3306,
63,
23292,
63,
76,
19,
4054,
63,
667,
23165,
297,
849,
29,
797,
12,
355,
1720,
12397,
3358,
17174,
522,
3082,
24464,
687,
26302,
491,
19,
283,
2432,
283,
14250,
370,
18470,
491,
19,
22867,
2659,
395,
199,
61,
199,
199,
4128,
14,
3103,
14,
2683,
63,
3291,
8,
44,
19,
63,
14565,
51,
63,
27944,
1293,
540,
63,
25636,
9,
421,
199,
533,
22708,
44,
19,
7788,
17490,
8,
1238,
63,
1095,
14,
5825,
54,
18,
304,
272,
408,
18089,
11696,
3382,
8224,
24464,
436,
491,
19,
22867,
1041,
339,
6197,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
395,
2079,
2937,
14,
3190,
480,
17292,
14,
344,
401,
16549,
534,
10855,
659,
2079,
5062,
63,
498,
29,
549,
9,
272,
634,
19,
63,
4054,
275,
9813,
14,
5690,
8,
14250,
63,
697,
14,
7788,
9,
272,
634,
19,
63,
4054,
63,
344,
275,
2937,
14,
4547,
8,
2231,
14,
1558,
8,
1344,
395,
1169,
2937,
14,
3190,
480,
14250,
14,
344,
401,
16549,
534,
10855,
659,
1169,
5062,
63,
498,
29,
549,
9,
421,
199,
533,
491,
19,
7788,
11251,
8882,
4256,
8,
76,
19,
4054,
8874,
14,
44,
19,
7788,
11251,
5061,
1563,
12,
2892,
6631,
7211,
2393,
63,
697,
14,
7788,
11251,
8882,
4256,
304,
272,
408,
4256,
1021,
370,
1050,
634,
19,
6631,
11899,
3329,
370,
8963,
272,
1808,
314,
634,
19,
6631,
367,
14870,
14,
272,
408,
339,
6197,
63,
8874,
275,
488,
339,
347,
1343,
63,
20339,
63,
76,
19,
63,
4054,
63,
1205,
63,
1074,
8,
277,
304,
267,
340,
440,
4810,
14,
3103,
14,
3306,
63,
23292,
63,
76,
19,
4054,
63,
667,
23165,
26,
288,
5051,
14,
815,
1547,
2673,
480,
18297,
6247,
491,
19,
6631,
2004,
1104,
2952,
298,
586,
298,
23292,
6197,
522,
1809,
15633,
365,
6980,
13853,
288,
372,
398,
291,
14,
2758,
63,
4054,
63,
1205,
63,
1074,
8,
288,
291,
14,
470,
3082,
63,
17292,
63,
504,
63,
2110,
63,
14250,
9,
339,
347,
522,
3082,
63,
17292,
63,
504,
63,
2110,
63,
14250,
8,
277,
304,
267,
408,
1322,
3082,
24464,
687,
3224,
634,
19,
22867,
340,
4628,
1174,
365,
1536,
1041,
267,
6631,
63,
10957,
63,
3097,
275,
291,
14,
4054,
63,
10957,
63,
3097,
63,
4515,
342,
267,
291,
14,
2573,
63,
2110,
63,
14250,
360,
44,
19,
297,
6631,
63,
10957,
63,
3097,
9,
267,
17875,
275,
291,
14,
362,
63,
17708,
63,
521,
8,
4054,
63,
10957,
63,
3097,
9,
398,
1067,
275,
302,
63,
3799,
14,
362,
63,
2113,
63,
1100,
342,
267,
3224,
63,
10880,
275,
334,
288,
1067,
14,
1730,
14,
1131,
8,
11691,
44,
19,
7788,
17490,
680,
288,
4263,
8,
14250,
63,
697,
14,
7788,
680,
288,
2457,
8,
14250,
63,
697,
14,
7788,
14,
22685,
63,
3954,
665,
17875,
12,
673,
22867,
63,
697,
14,
7788,
14,
2113,
63,
929,
63,
384,
680,
288,
6890,
904,
8,
76,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
12,
1993,
634,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
14,
4995,
63,
344,
508,
1993,
22708,
44,
19,
7788,
17490,
14,
4995,
63,
344,
680,
288,
2457,
8,
2231,
14,
269,
2531,
76,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
14,
2411,
508,
3875,
14,
3910,
1062,
2079,
634,
19,
63,
3288,
63,
697,
14,
11691,
7426,
5379,
14,
2411,
508,
3875,
14,
2307,
16890,
267,
862,
26,
288,
367,
11696,
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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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
] |
ammarkhann/FinalSeniorCode
|
lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/ec.py
|
1
|
10656
|
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
InvalidSignature, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.openssl.utils import _truncate_digest
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import (
AsymmetricSignatureContext, AsymmetricVerificationContext, ec
)
def _truncate_digest_for_ecdsa(ec_key_cdata, digest, backend):
"""
This function truncates digests that are longer than a given elliptic
curve key's length so they can be signed. Since elliptic curve keys are
much shorter than RSA keys many digests (e.g. SHA-512) may require
truncation.
"""
_lib = backend._lib
_ffi = backend._ffi
group = _lib.EC_KEY_get0_group(ec_key_cdata)
with backend._tmp_bn_ctx() as bn_ctx:
order = _lib.BN_CTX_get(bn_ctx)
backend.openssl_assert(order != _ffi.NULL)
res = _lib.EC_GROUP_get_order(group, order, bn_ctx)
backend.openssl_assert(res == 1)
order_bits = _lib.BN_num_bits(order)
return _truncate_digest(digest, order_bits)
def _ec_key_curve_sn(backend, ec_key):
group = backend._lib.EC_KEY_get0_group(ec_key)
backend.openssl_assert(group != backend._ffi.NULL)
nid = backend._lib.EC_GROUP_get_curve_name(group)
# The following check is to find EC keys with unnamed curves and raise
# an error for now.
if nid == backend._lib.NID_undef:
raise NotImplementedError(
"ECDSA certificates with unnamed curves are unsupported "
"at this time"
)
curve_name = backend._lib.OBJ_nid2sn(nid)
backend.openssl_assert(curve_name != backend._ffi.NULL)
sn = backend._ffi.string(curve_name).decode('ascii')
return sn
def _mark_asn1_named_ec_curve(backend, ec_cdata):
"""
Set the named curve flag on the EC_KEY. This causes OpenSSL to
serialize EC keys along with their curve OID which makes
deserialization easier.
"""
backend._lib.EC_KEY_set_asn1_flag(
ec_cdata, backend._lib.OPENSSL_EC_NAMED_CURVE
)
def _sn_to_elliptic_curve(backend, sn):
try:
return ec._CURVE_TYPES[sn]()
except KeyError:
raise UnsupportedAlgorithm(
"{0} is not a supported elliptic curve".format(sn),
_Reasons.UNSUPPORTED_ELLIPTIC_CURVE
)
@utils.register_interface(AsymmetricSignatureContext)
class _ECDSASignatureContext(object):
def __init__(self, backend, private_key, algorithm):
self._backend = backend
self._private_key = private_key
self._digest = hashes.Hash(algorithm, backend)
def update(self, data):
self._digest.update(data)
def finalize(self):
ec_key = self._private_key._ec_key
digest = self._digest.finalize()
digest = _truncate_digest_for_ecdsa(ec_key, digest, self._backend)
max_size = self._backend._lib.ECDSA_size(ec_key)
self._backend.openssl_assert(max_size > 0)
sigbuf = self._backend._ffi.new("unsigned char[]", max_size)
siglen_ptr = self._backend._ffi.new("unsigned int[]", 1)
res = self._backend._lib.ECDSA_sign(
0,
digest,
len(digest),
sigbuf,
siglen_ptr,
ec_key
)
self._backend.openssl_assert(res == 1)
return self._backend._ffi.buffer(sigbuf)[:siglen_ptr[0]]
@utils.register_interface(AsymmetricVerificationContext)
class _ECDSAVerificationContext(object):
def __init__(self, backend, public_key, signature, algorithm):
self._backend = backend
self._public_key = public_key
self._signature = signature
self._digest = hashes.Hash(algorithm, backend)
def update(self, data):
self._digest.update(data)
def verify(self):
ec_key = self._public_key._ec_key
digest = self._digest.finalize()
digest = _truncate_digest_for_ecdsa(ec_key, digest, self._backend)
res = self._backend._lib.ECDSA_verify(
0,
digest,
len(digest),
self._signature,
len(self._signature),
ec_key
)
if res != 1:
self._backend._consume_errors()
raise InvalidSignature
return True
@utils.register_interface(ec.EllipticCurvePrivateKeyWithSerialization)
class _EllipticCurvePrivateKey(object):
def __init__(self, backend, ec_key_cdata, evp_pkey):
self._backend = backend
_mark_asn1_named_ec_curve(backend, ec_key_cdata)
self._ec_key = ec_key_cdata
self._evp_pkey = evp_pkey
sn = _ec_key_curve_sn(backend, ec_key_cdata)
self._curve = _sn_to_elliptic_curve(backend, sn)
curve = utils.read_only_property("_curve")
def signer(self, signature_algorithm):
if isinstance(signature_algorithm, ec.ECDSA):
return _ECDSASignatureContext(
self._backend, self, signature_algorithm.algorithm
)
else:
raise UnsupportedAlgorithm(
"Unsupported elliptic curve signature algorithm.",
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
def exchange(self, algorithm, peer_public_key):
if not (
self._backend.elliptic_curve_exchange_algorithm_supported(
algorithm, self.curve
)
):
raise UnsupportedAlgorithm(
"This backend does not support the ECDH algorithm.",
_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
)
if peer_public_key.curve.name != self.curve.name:
raise ValueError(
"peer_public_key and self are not on the same curve"
)
group = self._backend._lib.EC_KEY_get0_group(self._ec_key)
z_len = (self._backend._lib.EC_GROUP_get_degree(group) + 7) // 8
self._backend.openssl_assert(z_len > 0)
z_buf = self._backend._ffi.new("uint8_t[]", z_len)
peer_key = self._backend._lib.EC_KEY_get0_public_key(
peer_public_key._ec_key
)
r = self._backend._lib.ECDH_compute_key(
z_buf, z_len, peer_key, self._ec_key, self._backend._ffi.NULL
)
self._backend.openssl_assert(r > 0)
return self._backend._ffi.buffer(z_buf)[:z_len]
def public_key(self):
group = self._backend._lib.EC_KEY_get0_group(self._ec_key)
self._backend.openssl_assert(group != self._backend._ffi.NULL)
curve_nid = self._backend._lib.EC_GROUP_get_curve_name(group)
public_ec_key = self._backend._lib.EC_KEY_new_by_curve_name(curve_nid)
self._backend.openssl_assert(public_ec_key != self._backend._ffi.NULL)
public_ec_key = self._backend._ffi.gc(
public_ec_key, self._backend._lib.EC_KEY_free
)
point = self._backend._lib.EC_KEY_get0_public_key(self._ec_key)
self._backend.openssl_assert(point != self._backend._ffi.NULL)
res = self._backend._lib.EC_KEY_set_public_key(public_ec_key, point)
self._backend.openssl_assert(res == 1)
evp_pkey = self._backend._ec_cdata_to_evp_pkey(public_ec_key)
return _EllipticCurvePublicKey(self._backend, public_ec_key, evp_pkey)
def private_numbers(self):
bn = self._backend._lib.EC_KEY_get0_private_key(self._ec_key)
private_value = self._backend._bn_to_int(bn)
return ec.EllipticCurvePrivateNumbers(
private_value=private_value,
public_numbers=self.public_key().public_numbers()
)
def private_bytes(self, encoding, format, encryption_algorithm):
return self._backend._private_key_bytes(
encoding,
format,
encryption_algorithm,
self._evp_pkey,
self._ec_key
)
def sign(self, data, signature_algorithm):
signer = self.signer(signature_algorithm)
signer.update(data)
return signer.finalize()
@utils.register_interface(ec.EllipticCurvePublicKeyWithSerialization)
class _EllipticCurvePublicKey(object):
def __init__(self, backend, ec_key_cdata, evp_pkey):
self._backend = backend
_mark_asn1_named_ec_curve(backend, ec_key_cdata)
self._ec_key = ec_key_cdata
self._evp_pkey = evp_pkey
sn = _ec_key_curve_sn(backend, ec_key_cdata)
self._curve = _sn_to_elliptic_curve(backend, sn)
curve = utils.read_only_property("_curve")
def verifier(self, signature, signature_algorithm):
if not isinstance(signature, bytes):
raise TypeError("signature must be bytes.")
if isinstance(signature_algorithm, ec.ECDSA):
return _ECDSAVerificationContext(
self._backend, self, signature, signature_algorithm.algorithm
)
else:
raise UnsupportedAlgorithm(
"Unsupported elliptic curve signature algorithm.",
_Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM)
def public_numbers(self):
set_func, get_func, group = (
self._backend._ec_key_determine_group_get_set_funcs(self._ec_key)
)
point = self._backend._lib.EC_KEY_get0_public_key(self._ec_key)
self._backend.openssl_assert(point != self._backend._ffi.NULL)
with self._backend._tmp_bn_ctx() as bn_ctx:
bn_x = self._backend._lib.BN_CTX_get(bn_ctx)
bn_y = self._backend._lib.BN_CTX_get(bn_ctx)
res = get_func(group, point, bn_x, bn_y, bn_ctx)
self._backend.openssl_assert(res == 1)
x = self._backend._bn_to_int(bn_x)
y = self._backend._bn_to_int(bn_y)
return ec.EllipticCurvePublicNumbers(
x=x,
y=y,
curve=self._curve
)
def public_bytes(self, encoding, format):
if format is serialization.PublicFormat.PKCS1:
raise ValueError(
"EC public keys do not support PKCS1 serialization"
)
return self._backend._public_key_bytes(
encoding,
format,
self,
self._evp_pkey,
None
)
def verify(self, signature, data, signature_algorithm):
verifier = self.verifier(signature, signature_algorithm)
verifier.update(data)
verifier.verify()
|
mit
|
[
3,
961,
570,
365,
21164,
18233,
1334,
314,
2895,
402,
314,
3668,
844,
12,
3394,
199,
3,
499,
14,
16,
12,
436,
314,
6289,
844,
14,
1666,
314,
5113,
570,
315,
314,
1738,
402,
642,
7611,
199,
3,
367,
4890,
2436,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
504,
27617,
492,
3778,
199,
504,
27617,
14,
3924,
492,
334,
272,
6378,
10014,
12,
19022,
11570,
12,
485,
16148,
83,
199,
9,
199,
504,
27617,
14,
22133,
569,
14,
7765,
14,
14837,
14,
1208,
492,
485,
12517,
63,
5671,
199,
504,
27617,
14,
22133,
569,
14,
1359,
22337,
492,
14647,
12,
16953,
199,
504,
27617,
14,
22133,
569,
14,
1359,
22337,
14,
5660,
77,
5165,
492,
334,
272,
437,
18422,
10014,
2998,
12,
437,
18422,
22595,
2998,
12,
7062,
199,
9,
421,
199,
318,
485,
12517,
63,
5671,
63,
509,
63,
825,
24760,
8,
825,
63,
498,
63,
15892,
12,
10017,
12,
4865,
304,
272,
408,
272,
961,
805,
14547,
83,
10017,
83,
626,
787,
8088,
2419,
282,
1627,
16028,
764,
272,
15318,
790,
1159,
2582,
880,
2985,
883,
506,
10514,
14,
9336,
16028,
764,
15318,
2883,
787,
272,
8298,
18299,
2419,
18471,
2883,
5002,
10017,
83,
334,
69,
14,
71,
14,
12002,
13,
7736,
9,
1443,
4409,
272,
8181,
1063,
14,
272,
408,
339,
485,
773,
275,
4865,
423,
773,
272,
485,
11286,
275,
4865,
423,
11286,
339,
1572,
275,
485,
773,
14,
4220,
63,
3078,
63,
362,
16,
63,
923,
8,
825,
63,
498,
63,
15892,
9,
339,
543,
4865,
423,
2791,
63,
10472,
63,
3799,
342,
465,
21847,
63,
3799,
26,
267,
1865,
275,
485,
773,
14,
18273,
63,
21524,
63,
362,
8,
10472,
63,
3799,
9,
267,
4865,
14,
14837,
63,
479,
8,
1648,
1137,
485,
11286,
14,
8084,
9,
398,
522,
275,
485,
773,
14,
4220,
63,
7823,
63,
362,
63,
1648,
8,
923,
12,
1865,
12,
21847,
63,
3799,
9,
267,
4865,
14,
14837,
63,
479,
8,
470,
508,
413,
9,
398,
1865,
63,
5609,
275,
485,
773,
14,
18273,
63,
1507,
63,
5609,
8,
1648,
9,
339,
372,
485,
12517,
63,
5671,
8,
5671,
12,
1865,
63,
5609,
9,
421,
199,
318,
485,
825,
63,
498,
63,
11895,
63,
5167,
8,
4620,
12,
7062,
63,
498,
304,
272,
1572,
275,
4865,
423,
773,
14,
4220,
63,
3078,
63,
362,
16,
63,
923,
8,
825,
63,
498,
9,
272,
4865,
14,
14837,
63,
479,
8,
923,
1137,
4865,
423,
11286,
14,
8084,
9,
339,
302,
344,
275,
4865,
423,
773,
14,
4220,
63,
7823,
63,
362,
63,
11895,
63,
354,
8,
923,
9,
272,
327,
710,
2569,
1104,
365,
370,
2342,
15352,
2883,
543,
625,
4579,
1094,
2310,
436,
746,
272,
327,
376,
1125,
367,
3063,
14,
272,
340,
302,
344,
508,
4865,
423,
773,
14,
46,
998,
63,
25878,
26,
267,
746,
4279,
8,
288,
298,
4220,
23007,
14512,
543,
625,
4579,
1094,
2310,
787,
16313,
298,
288,
298,
292,
642,
900,
2,
267,
776,
339,
15318,
63,
354,
275,
4865,
423,
773,
14,
15862,
63,
30411,
18,
5167,
8,
30411,
9,
272,
4865,
14,
14837,
63,
479,
8,
11895,
63,
354,
1137,
4865,
423,
11286,
14,
8084,
9,
339,
6895,
275,
4865,
423,
11286,
14,
875,
8,
11895,
63,
354,
680,
2708,
360,
4371,
358,
272,
372,
6895,
421,
199,
318,
485,
1657,
63,
6228,
17,
63,
4579,
63,
825,
63,
11895,
8,
4620,
12,
7062,
63,
15892,
304,
272,
408,
272,
2494,
314,
4310,
15318,
3305,
641,
314,
15352,
63,
3078,
14,
961,
14486,
14296,
370,
272,
8437,
15352,
2883,
3180,
543,
3932,
15318,
593,
998,
1314,
7704,
272,
477,
12161,
14905,
14,
272,
408,
339,
4865,
423,
773,
14,
4220,
63,
3078,
63,
409,
63,
6228,
17,
63,
4173,
8,
267,
7062,
63,
15892,
12,
4865,
423,
773,
14,
9935,
5413,
63,
4220,
63,
7335,
1149,
63,
7013,
2524,
272,
776,
421,
199,
318,
485,
5167,
63,
475,
63,
16514,
764,
63,
11895,
8,
4620,
12,
6895,
304,
272,
862,
26,
267,
372,
7062,
423,
7013,
2524,
63,
7893,
59,
5167,
32702,
272,
871,
4067,
26,
267,
746,
19022,
11570,
8,
288,
5310,
16,
93,
365,
440,
282,
3748,
16028,
764,
15318,
1674,
908,
8,
5167,
395,
288,
485,
16148,
83,
14,
1734,
15925,
63,
14952,
4385,
948,
63,
7013,
2524,
267,
776,
421,
199,
32,
1208,
14,
2683,
63,
3266,
8,
33,
18422,
10014,
2998,
9,
199,
533,
485,
4220,
3177,
1179,
1030,
1463,
2998,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4865,
12,
5726,
63,
498,
12,
5563,
304,
267,
291,
423,
4620,
275,
4865,
267,
291,
423,
4239,
63,
498,
275,
5726,
63,
498,
267,
291,
423,
5671,
275,
14647,
14,
3476,
8,
8833,
12,
4865,
9,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
291,
423,
5671,
14,
873,
8,
576,
9,
339,
347,
17284,
8,
277,
304,
267,
7062,
63,
498,
275,
291,
423,
4239,
63,
498,
423,
825,
63,
498,
398,
10017,
275,
291,
423,
5671,
14,
14450,
342,
398,
10017,
275,
485,
12517,
63,
5671,
63,
509,
63,
825,
24760,
8,
825,
63,
498,
12,
10017,
12,
291,
423,
4620,
9,
398,
1390,
63,
890,
275,
291,
423,
4620,
423,
773,
14,
4220,
23007,
63,
890,
8,
825,
63,
498,
9,
267,
291,
423,
4620,
14,
14837,
63,
479,
8,
988,
63,
890,
690,
378,
9,
398,
5259,
1436,
275,
291,
423,
4620,
423,
11286,
14,
1222,
480,
2244,
1495,
20204,
1390,
63,
890,
9,
267,
5259,
552,
63,
4695,
275,
291,
423,
4620,
423,
11286,
14,
1222,
480,
2244,
1109,
20204,
413,
9,
267,
522,
275,
291,
423,
4620,
423,
773,
14,
4220,
23007,
63,
1037,
8,
288,
378,
12,
288,
10017,
12,
288,
822,
8,
5671,
395,
288,
5259,
1436,
12,
288,
5259,
552,
63,
4695,
12,
288,
7062,
63,
498,
267,
776,
267,
291,
423,
4620,
14,
14837,
63,
479,
8,
470,
508,
413,
9,
267,
372,
291,
423,
4620,
423,
11286,
14,
2738,
8,
4093,
1436,
18562,
4093,
552,
63,
4695,
59,
16,
2677,
421,
199,
32,
1208,
14,
2683,
63,
3266,
8,
33,
18422,
22595,
2998,
9
] |
[
961,
570,
365,
21164,
18233,
1334,
314,
2895,
402,
314,
3668,
844,
12,
3394,
199,
3,
499,
14,
16,
12,
436,
314,
6289,
844,
14,
1666,
314,
5113,
570,
315,
314,
1738,
402,
642,
7611,
199,
3,
367,
4890,
2436,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
504,
27617,
492,
3778,
199,
504,
27617,
14,
3924,
492,
334,
272,
6378,
10014,
12,
19022,
11570,
12,
485,
16148,
83,
199,
9,
199,
504,
27617,
14,
22133,
569,
14,
7765,
14,
14837,
14,
1208,
492,
485,
12517,
63,
5671,
199,
504,
27617,
14,
22133,
569,
14,
1359,
22337,
492,
14647,
12,
16953,
199,
504,
27617,
14,
22133,
569,
14,
1359,
22337,
14,
5660,
77,
5165,
492,
334,
272,
437,
18422,
10014,
2998,
12,
437,
18422,
22595,
2998,
12,
7062,
199,
9,
421,
199,
318,
485,
12517,
63,
5671,
63,
509,
63,
825,
24760,
8,
825,
63,
498,
63,
15892,
12,
10017,
12,
4865,
304,
272,
408,
272,
961,
805,
14547,
83,
10017,
83,
626,
787,
8088,
2419,
282,
1627,
16028,
764,
272,
15318,
790,
1159,
2582,
880,
2985,
883,
506,
10514,
14,
9336,
16028,
764,
15318,
2883,
787,
272,
8298,
18299,
2419,
18471,
2883,
5002,
10017,
83,
334,
69,
14,
71,
14,
12002,
13,
7736,
9,
1443,
4409,
272,
8181,
1063,
14,
272,
408,
339,
485,
773,
275,
4865,
423,
773,
272,
485,
11286,
275,
4865,
423,
11286,
339,
1572,
275,
485,
773,
14,
4220,
63,
3078,
63,
362,
16,
63,
923,
8,
825,
63,
498,
63,
15892,
9,
339,
543,
4865,
423,
2791,
63,
10472,
63,
3799,
342,
465,
21847,
63,
3799,
26,
267,
1865,
275,
485,
773,
14,
18273,
63,
21524,
63,
362,
8,
10472,
63,
3799,
9,
267,
4865,
14,
14837,
63,
479,
8,
1648,
1137,
485,
11286,
14,
8084,
9,
398,
522,
275,
485,
773,
14,
4220,
63,
7823,
63,
362,
63,
1648,
8,
923,
12,
1865,
12,
21847,
63,
3799,
9,
267,
4865,
14,
14837,
63,
479,
8,
470,
508,
413,
9,
398,
1865,
63,
5609,
275,
485,
773,
14,
18273,
63,
1507,
63,
5609,
8,
1648,
9,
339,
372,
485,
12517,
63,
5671,
8,
5671,
12,
1865,
63,
5609,
9,
421,
199,
318,
485,
825,
63,
498,
63,
11895,
63,
5167,
8,
4620,
12,
7062,
63,
498,
304,
272,
1572,
275,
4865,
423,
773,
14,
4220,
63,
3078,
63,
362,
16,
63,
923,
8,
825,
63,
498,
9,
272,
4865,
14,
14837,
63,
479,
8,
923,
1137,
4865,
423,
11286,
14,
8084,
9,
339,
302,
344,
275,
4865,
423,
773,
14,
4220,
63,
7823,
63,
362,
63,
11895,
63,
354,
8,
923,
9,
272,
327,
710,
2569,
1104,
365,
370,
2342,
15352,
2883,
543,
625,
4579,
1094,
2310,
436,
746,
272,
327,
376,
1125,
367,
3063,
14,
272,
340,
302,
344,
508,
4865,
423,
773,
14,
46,
998,
63,
25878,
26,
267,
746,
4279,
8,
288,
298,
4220,
23007,
14512,
543,
625,
4579,
1094,
2310,
787,
16313,
298,
288,
298,
292,
642,
900,
2,
267,
776,
339,
15318,
63,
354,
275,
4865,
423,
773,
14,
15862,
63,
30411,
18,
5167,
8,
30411,
9,
272,
4865,
14,
14837,
63,
479,
8,
11895,
63,
354,
1137,
4865,
423,
11286,
14,
8084,
9,
339,
6895,
275,
4865,
423,
11286,
14,
875,
8,
11895,
63,
354,
680,
2708,
360,
4371,
358,
272,
372,
6895,
421,
199,
318,
485,
1657,
63,
6228,
17,
63,
4579,
63,
825,
63,
11895,
8,
4620,
12,
7062,
63,
15892,
304,
272,
408,
272,
2494,
314,
4310,
15318,
3305,
641,
314,
15352,
63,
3078,
14,
961,
14486,
14296,
370,
272,
8437,
15352,
2883,
3180,
543,
3932,
15318,
593,
998,
1314,
7704,
272,
477,
12161,
14905,
14,
272,
408,
339,
4865,
423,
773,
14,
4220,
63,
3078,
63,
409,
63,
6228,
17,
63,
4173,
8,
267,
7062,
63,
15892,
12,
4865,
423,
773,
14,
9935,
5413,
63,
4220,
63,
7335,
1149,
63,
7013,
2524,
272,
776,
421,
199,
318,
485,
5167,
63,
475,
63,
16514,
764,
63,
11895,
8,
4620,
12,
6895,
304,
272,
862,
26,
267,
372,
7062,
423,
7013,
2524,
63,
7893,
59,
5167,
32702,
272,
871,
4067,
26,
267,
746,
19022,
11570,
8,
288,
5310,
16,
93,
365,
440,
282,
3748,
16028,
764,
15318,
1674,
908,
8,
5167,
395,
288,
485,
16148,
83,
14,
1734,
15925,
63,
14952,
4385,
948,
63,
7013,
2524,
267,
776,
421,
199,
32,
1208,
14,
2683,
63,
3266,
8,
33,
18422,
10014,
2998,
9,
199,
533,
485,
4220,
3177,
1179,
1030,
1463,
2998,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4865,
12,
5726,
63,
498,
12,
5563,
304,
267,
291,
423,
4620,
275,
4865,
267,
291,
423,
4239,
63,
498,
275,
5726,
63,
498,
267,
291,
423,
5671,
275,
14647,
14,
3476,
8,
8833,
12,
4865,
9,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
291,
423,
5671,
14,
873,
8,
576,
9,
339,
347,
17284,
8,
277,
304,
267,
7062,
63,
498,
275,
291,
423,
4239,
63,
498,
423,
825,
63,
498,
398,
10017,
275,
291,
423,
5671,
14,
14450,
342,
398,
10017,
275,
485,
12517,
63,
5671,
63,
509,
63,
825,
24760,
8,
825,
63,
498,
12,
10017,
12,
291,
423,
4620,
9,
398,
1390,
63,
890,
275,
291,
423,
4620,
423,
773,
14,
4220,
23007,
63,
890,
8,
825,
63,
498,
9,
267,
291,
423,
4620,
14,
14837,
63,
479,
8,
988,
63,
890,
690,
378,
9,
398,
5259,
1436,
275,
291,
423,
4620,
423,
11286,
14,
1222,
480,
2244,
1495,
20204,
1390,
63,
890,
9,
267,
5259,
552,
63,
4695,
275,
291,
423,
4620,
423,
11286,
14,
1222,
480,
2244,
1109,
20204,
413,
9,
267,
522,
275,
291,
423,
4620,
423,
773,
14,
4220,
23007,
63,
1037,
8,
288,
378,
12,
288,
10017,
12,
288,
822,
8,
5671,
395,
288,
5259,
1436,
12,
288,
5259,
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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
] |
shawnwanderson/cmput404-project
|
venv/lib/python2.7/site-packages/django/db/backends/sqlite3/creation.py
|
166
|
4846
|
import os
import shutil
import sys
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.base.creation import BaseDatabaseCreation
from django.utils.six.moves import input
class DatabaseCreation(BaseDatabaseCreation):
def _get_test_db_name(self):
test_database_name = self.connection.settings_dict['TEST']['NAME']
can_share_in_memory_db = self.connection.features.can_share_in_memory_db
if test_database_name and test_database_name != ':memory:':
if 'mode=memory' in test_database_name and not can_share_in_memory_db:
raise ImproperlyConfigured(
"Using a shared memory database with `mode=memory` in the "
"database name is not supported in your environment, "
"use `:memory:` instead."
)
return test_database_name
if can_share_in_memory_db:
return 'file:memorydb_%s?mode=memory&cache=shared' % self.connection.alias
return ':memory:'
def _create_test_db(self, verbosity, autoclobber, keepdb=False):
test_database_name = self._get_test_db_name()
if keepdb:
return test_database_name
if not self.connection.is_in_memory_db(test_database_name):
# Erase the old test database
if verbosity >= 1:
print("Destroying old test database for alias %s..." % (
self._get_database_display_str(verbosity, test_database_name),
))
if os.access(test_database_name, os.F_OK):
if not autoclobber:
confirm = input(
"Type 'yes' if you would like to try deleting the test "
"database '%s', or 'no' to cancel: " % test_database_name
)
if autoclobber or confirm == 'yes':
try:
os.remove(test_database_name)
except Exception as e:
sys.stderr.write("Got an error deleting the old test database: %s\n" % e)
sys.exit(2)
else:
print("Tests cancelled.")
sys.exit(1)
return test_database_name
def get_test_db_clone_settings(self, number):
orig_settings_dict = self.connection.settings_dict
source_database_name = orig_settings_dict['NAME']
if self.connection.is_in_memory_db(source_database_name):
return orig_settings_dict
else:
new_settings_dict = orig_settings_dict.copy()
root, ext = os.path.splitext(orig_settings_dict['NAME'])
new_settings_dict['NAME'] = '{}_{}.{}'.format(root, number, ext)
return new_settings_dict
def _clone_test_db(self, number, verbosity, keepdb=False):
source_database_name = self.connection.settings_dict['NAME']
target_database_name = self.get_test_db_clone_settings(number)['NAME']
# Forking automatically makes a copy of an in-memory database.
if not self.connection.is_in_memory_db(source_database_name):
# Erase the old test database
if os.access(target_database_name, os.F_OK):
if keepdb:
return
if verbosity >= 1:
print("Destroying old test database for alias %s..." % (
self._get_database_display_str(verbosity, target_database_name),
))
try:
os.remove(target_database_name)
except Exception as e:
sys.stderr.write("Got an error deleting the old test database: %s\n" % e)
sys.exit(2)
try:
shutil.copy(source_database_name, target_database_name)
except Exception as e:
sys.stderr.write("Got an error cloning the test database: %s\n" % e)
sys.exit(2)
def _destroy_test_db(self, test_database_name, verbosity):
if test_database_name and not self.connection.is_in_memory_db(test_database_name):
# Remove the SQLite database file
os.remove(test_database_name)
def test_db_signature(self):
"""
Returns a tuple that uniquely identifies a test database.
This takes into account the special cases of ":memory:" and "" for
SQLite since the databases will be distinct despite having the same
TEST NAME. See http://www.sqlite.org/inmemorydb.html
"""
test_database_name = self._get_test_db_name()
sig = [self.connection.settings_dict['NAME']]
if self.connection.is_in_memory_db(test_database_name):
sig.append(self.connection.alias)
return tuple(sig)
|
gpl-3.0
|
[
646,
747,
199,
646,
5145,
199,
646,
984,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
8782,
492,
29103,
13921,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1324,
421,
199,
533,
8692,
13921,
8,
1563,
7243,
13921,
304,
339,
347,
485,
362,
63,
396,
63,
697,
63,
354,
8,
277,
304,
267,
511,
63,
4659,
63,
354,
275,
291,
14,
2105,
14,
1751,
63,
807,
459,
2864,
2545,
2339,
418,
267,
883,
63,
6251,
63,
262,
63,
4844,
63,
697,
275,
291,
14,
2105,
14,
3179,
14,
2425,
63,
6251,
63,
262,
63,
4844,
63,
697,
267,
340,
511,
63,
4659,
63,
354,
436,
511,
63,
4659,
63,
354,
1137,
7596,
4844,
25156,
288,
340,
283,
632,
29,
4844,
7,
315,
511,
63,
4659,
63,
354,
436,
440,
883,
63,
6251,
63,
262,
63,
4844,
63,
697,
26,
355,
746,
11897,
8,
490,
298,
10369,
282,
5709,
4402,
3050,
543,
658,
632,
29,
4844,
64,
315,
314,
298,
490,
298,
4659,
536,
365,
440,
3748,
315,
2195,
3734,
12,
298,
490,
298,
1180,
658,
26,
4844,
1705,
3140,
2122,
355,
776,
288,
372,
511,
63,
4659,
63,
354,
267,
340,
883,
63,
6251,
63,
262,
63,
4844,
63,
697,
26,
288,
372,
283,
493,
26,
4844,
697,
4970,
83,
31,
632,
29,
4844,
6,
1637,
29,
5555,
7,
450,
291,
14,
2105,
14,
3620,
267,
372,
7596,
4844,
4881,
339,
347,
485,
981,
63,
396,
63,
697,
8,
277,
12,
8661,
12,
6384,
679,
22669,
12,
4215,
697,
29,
797,
304,
267,
511,
63,
4659,
63,
354,
275,
291,
423,
362,
63,
396,
63,
697,
63,
354,
342,
398,
340,
4215,
697,
26,
288,
372,
511,
63,
4659,
63,
354,
267,
340,
440,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
396,
63,
4659,
63,
354,
304,
288,
327,
662,
8062,
314,
2269,
511,
3050,
288,
340,
8661,
2356,
413,
26,
355,
870,
480,
14704,
316,
2269,
511,
3050,
367,
5162,
450,
83,
11500,
450,
334,
490,
291,
423,
362,
63,
4659,
63,
2918,
63,
495,
8,
9833,
12,
511,
63,
4659,
63,
354,
395,
355,
5082,
288,
340,
747,
14,
2732,
8,
396,
63,
4659,
63,
354,
12,
747,
14,
38,
63,
3593,
304,
355,
340,
440,
6384,
679,
22669,
26,
490,
12679,
275,
1324,
8,
717,
298,
804,
283,
5066,
7,
340,
1265,
3955,
2839,
370,
862,
13794,
314,
511,
298,
717,
298,
4659,
1543,
83,
297,
503,
283,
889,
7,
370,
9311,
26,
298,
450,
511,
63,
4659,
63,
354,
490,
776,
355,
340,
6384,
679,
22669,
503,
12679,
508,
283,
5066,
356,
490,
862,
26,
717,
747,
14,
2168,
8,
396,
63,
4659,
63,
354,
9,
490,
871,
2186,
465,
325,
26,
717,
984,
14,
3083,
14,
952,
480,
13662,
376,
1125,
13794,
314,
2269,
511,
3050,
26,
450,
83,
60,
78,
2,
450,
325,
9,
717,
984,
14,
2224,
8,
18,
9,
355,
587,
26,
490,
870,
480,
2925,
20115,
2685,
490,
984,
14,
2224,
8,
17,
9,
267,
372,
511,
63,
4659,
63,
354,
339,
347,
664,
63,
396,
63,
697,
63,
6311,
63,
1751,
8,
277,
12,
1329,
304,
267,
2306,
63,
1751,
63,
807,
275,
291,
14,
2105,
14,
1751,
63,
807,
267,
1350,
63,
4659,
63,
354,
275,
2306,
63,
1751,
63,
807,
459,
2339,
418,
267,
340,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
1365,
63,
4659,
63,
354,
304,
288,
372,
2306,
63,
1751,
63,
807,
267,
587,
26,
288,
892,
63,
1751,
63,
807,
275,
2306,
63,
1751,
63,
807,
14,
1574,
342,
288,
1738,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
2981,
63,
1751,
63,
807,
459,
2339,
1105,
288,
892,
63,
1751,
63,
807,
459,
2339,
418,
275,
9005,
24306,
14,
11123,
908,
8,
1231,
12,
1329,
12,
1599,
9,
288,
372,
892,
63,
1751,
63,
807,
339,
347,
485,
6311,
63,
396,
63,
697,
8,
277,
12,
1329,
12,
8661,
12,
4215,
697,
29,
797,
304,
267,
1350,
63,
4659,
63,
354,
275,
291,
14,
2105,
14,
1751,
63,
807,
459,
2339,
418,
267,
1347,
63,
4659,
63,
354,
275,
291,
14,
362,
63,
396,
63,
697,
63,
6311,
63,
1751,
8,
1955,
11820,
2339,
418,
267,
327,
2104,
17443,
5847,
7704,
282,
1331,
402,
376,
315,
13,
4844,
3050,
14,
267,
340,
440,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
1365,
63,
4659,
63,
354,
304,
288,
327,
662,
8062,
314,
2269,
511,
3050,
288,
340,
747,
14,
2732,
8,
1375,
63,
4659,
63,
354,
12,
747,
14,
38,
63,
3593,
304,
355,
340,
4215,
697,
26,
490,
372,
355,
340,
8661,
2356,
413,
26,
490,
870,
480,
14704,
316,
2269,
511,
3050,
367,
5162,
450,
83,
11500,
450,
334,
717,
291,
423,
362,
63,
4659,
63,
2918,
63,
495,
8,
9833,
12,
1347,
63,
4659,
63,
354,
395,
490,
5082,
355,
862,
26,
490,
747,
14,
2168,
8,
1375,
63,
4659,
63,
354,
9,
355,
871,
2186,
465,
325,
26,
490,
984,
14,
3083,
14,
952,
480,
13662,
376,
1125,
13794,
314,
2269,
511,
3050,
26,
450,
83,
60,
78,
2,
450,
325,
9,
490,
984,
14,
2224,
8,
18,
9,
288,
862,
26,
355,
5145,
14,
1574,
8,
1365,
63,
4659,
63,
354,
12,
1347,
63,
4659,
63,
354,
9,
288,
871,
2186,
465,
325,
26,
355,
984,
14,
3083,
14,
952,
480,
13662,
376,
1125,
824,
19718,
314,
511,
3050,
26,
450,
83,
60,
78,
2,
450,
325,
9,
355,
984,
14,
2224,
8,
18,
9,
339,
347,
485,
7237,
63,
396,
63,
697,
8,
277,
12,
511,
63,
4659,
63,
354,
12,
8661,
304,
267,
340,
511,
63,
4659,
63,
354,
436,
440,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
396,
63,
4659,
63,
354,
304,
288,
327,
5852,
314,
19245,
3050,
570,
288,
747,
14,
2168,
8,
396,
63,
4659,
63,
354,
9,
339,
347,
511,
63,
697,
63,
5233,
8,
277,
304,
267,
408,
267,
1803,
282,
2008,
626,
28727,
22975,
282,
511,
3050,
14,
398
] |
[
747,
199,
646,
5145,
199,
646,
984,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
8782,
492,
29103,
13921,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1324,
421,
199,
533,
8692,
13921,
8,
1563,
7243,
13921,
304,
339,
347,
485,
362,
63,
396,
63,
697,
63,
354,
8,
277,
304,
267,
511,
63,
4659,
63,
354,
275,
291,
14,
2105,
14,
1751,
63,
807,
459,
2864,
2545,
2339,
418,
267,
883,
63,
6251,
63,
262,
63,
4844,
63,
697,
275,
291,
14,
2105,
14,
3179,
14,
2425,
63,
6251,
63,
262,
63,
4844,
63,
697,
267,
340,
511,
63,
4659,
63,
354,
436,
511,
63,
4659,
63,
354,
1137,
7596,
4844,
25156,
288,
340,
283,
632,
29,
4844,
7,
315,
511,
63,
4659,
63,
354,
436,
440,
883,
63,
6251,
63,
262,
63,
4844,
63,
697,
26,
355,
746,
11897,
8,
490,
298,
10369,
282,
5709,
4402,
3050,
543,
658,
632,
29,
4844,
64,
315,
314,
298,
490,
298,
4659,
536,
365,
440,
3748,
315,
2195,
3734,
12,
298,
490,
298,
1180,
658,
26,
4844,
1705,
3140,
2122,
355,
776,
288,
372,
511,
63,
4659,
63,
354,
267,
340,
883,
63,
6251,
63,
262,
63,
4844,
63,
697,
26,
288,
372,
283,
493,
26,
4844,
697,
4970,
83,
31,
632,
29,
4844,
6,
1637,
29,
5555,
7,
450,
291,
14,
2105,
14,
3620,
267,
372,
7596,
4844,
4881,
339,
347,
485,
981,
63,
396,
63,
697,
8,
277,
12,
8661,
12,
6384,
679,
22669,
12,
4215,
697,
29,
797,
304,
267,
511,
63,
4659,
63,
354,
275,
291,
423,
362,
63,
396,
63,
697,
63,
354,
342,
398,
340,
4215,
697,
26,
288,
372,
511,
63,
4659,
63,
354,
267,
340,
440,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
396,
63,
4659,
63,
354,
304,
288,
327,
662,
8062,
314,
2269,
511,
3050,
288,
340,
8661,
2356,
413,
26,
355,
870,
480,
14704,
316,
2269,
511,
3050,
367,
5162,
450,
83,
11500,
450,
334,
490,
291,
423,
362,
63,
4659,
63,
2918,
63,
495,
8,
9833,
12,
511,
63,
4659,
63,
354,
395,
355,
5082,
288,
340,
747,
14,
2732,
8,
396,
63,
4659,
63,
354,
12,
747,
14,
38,
63,
3593,
304,
355,
340,
440,
6384,
679,
22669,
26,
490,
12679,
275,
1324,
8,
717,
298,
804,
283,
5066,
7,
340,
1265,
3955,
2839,
370,
862,
13794,
314,
511,
298,
717,
298,
4659,
1543,
83,
297,
503,
283,
889,
7,
370,
9311,
26,
298,
450,
511,
63,
4659,
63,
354,
490,
776,
355,
340,
6384,
679,
22669,
503,
12679,
508,
283,
5066,
356,
490,
862,
26,
717,
747,
14,
2168,
8,
396,
63,
4659,
63,
354,
9,
490,
871,
2186,
465,
325,
26,
717,
984,
14,
3083,
14,
952,
480,
13662,
376,
1125,
13794,
314,
2269,
511,
3050,
26,
450,
83,
60,
78,
2,
450,
325,
9,
717,
984,
14,
2224,
8,
18,
9,
355,
587,
26,
490,
870,
480,
2925,
20115,
2685,
490,
984,
14,
2224,
8,
17,
9,
267,
372,
511,
63,
4659,
63,
354,
339,
347,
664,
63,
396,
63,
697,
63,
6311,
63,
1751,
8,
277,
12,
1329,
304,
267,
2306,
63,
1751,
63,
807,
275,
291,
14,
2105,
14,
1751,
63,
807,
267,
1350,
63,
4659,
63,
354,
275,
2306,
63,
1751,
63,
807,
459,
2339,
418,
267,
340,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
1365,
63,
4659,
63,
354,
304,
288,
372,
2306,
63,
1751,
63,
807,
267,
587,
26,
288,
892,
63,
1751,
63,
807,
275,
2306,
63,
1751,
63,
807,
14,
1574,
342,
288,
1738,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
2981,
63,
1751,
63,
807,
459,
2339,
1105,
288,
892,
63,
1751,
63,
807,
459,
2339,
418,
275,
9005,
24306,
14,
11123,
908,
8,
1231,
12,
1329,
12,
1599,
9,
288,
372,
892,
63,
1751,
63,
807,
339,
347,
485,
6311,
63,
396,
63,
697,
8,
277,
12,
1329,
12,
8661,
12,
4215,
697,
29,
797,
304,
267,
1350,
63,
4659,
63,
354,
275,
291,
14,
2105,
14,
1751,
63,
807,
459,
2339,
418,
267,
1347,
63,
4659,
63,
354,
275,
291,
14,
362,
63,
396,
63,
697,
63,
6311,
63,
1751,
8,
1955,
11820,
2339,
418,
267,
327,
2104,
17443,
5847,
7704,
282,
1331,
402,
376,
315,
13,
4844,
3050,
14,
267,
340,
440,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
1365,
63,
4659,
63,
354,
304,
288,
327,
662,
8062,
314,
2269,
511,
3050,
288,
340,
747,
14,
2732,
8,
1375,
63,
4659,
63,
354,
12,
747,
14,
38,
63,
3593,
304,
355,
340,
4215,
697,
26,
490,
372,
355,
340,
8661,
2356,
413,
26,
490,
870,
480,
14704,
316,
2269,
511,
3050,
367,
5162,
450,
83,
11500,
450,
334,
717,
291,
423,
362,
63,
4659,
63,
2918,
63,
495,
8,
9833,
12,
1347,
63,
4659,
63,
354,
395,
490,
5082,
355,
862,
26,
490,
747,
14,
2168,
8,
1375,
63,
4659,
63,
354,
9,
355,
871,
2186,
465,
325,
26,
490,
984,
14,
3083,
14,
952,
480,
13662,
376,
1125,
13794,
314,
2269,
511,
3050,
26,
450,
83,
60,
78,
2,
450,
325,
9,
490,
984,
14,
2224,
8,
18,
9,
288,
862,
26,
355,
5145,
14,
1574,
8,
1365,
63,
4659,
63,
354,
12,
1347,
63,
4659,
63,
354,
9,
288,
871,
2186,
465,
325,
26,
355,
984,
14,
3083,
14,
952,
480,
13662,
376,
1125,
824,
19718,
314,
511,
3050,
26,
450,
83,
60,
78,
2,
450,
325,
9,
355,
984,
14,
2224,
8,
18,
9,
339,
347,
485,
7237,
63,
396,
63,
697,
8,
277,
12,
511,
63,
4659,
63,
354,
12,
8661,
304,
267,
340,
511,
63,
4659,
63,
354,
436,
440,
291,
14,
2105,
14,
374,
63,
262,
63,
4844,
63,
697,
8,
396,
63,
4659,
63,
354,
304,
288,
327,
5852,
314,
19245,
3050,
570,
288,
747,
14,
2168,
8,
396,
63,
4659,
63,
354,
9,
339,
347,
511,
63,
697,
63,
5233,
8,
277,
304,
267,
408,
267,
1803,
282,
2008,
626,
28727,
22975,
282,
511,
3050,
14,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mtambos/online-anomaly-detection
|
src/mgng/ring_buffer.py
|
2
|
2154
|
#!/usr/bin/env python
# ----------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
# ----------------------------------------------------------------------
'''
@author: Mario Tambos
'''
import numpy as np
class RingBuffer(np.ndarray):
'A multidimensional ring buffer.'
def __new__(cls, input_array):
obj = np.asarray(input_array).view(cls)
return obj
def __array_finalize__(self, obj):
if obj is None: return
def __array_wrap__(self, out_arr, context=None):
return np.ndarray.__array_wrap__(self, out_arr, context)
def extend(self, xs):
'Adds array xs to the ring buffer. If xs is longer than the ring '
'buffer, the last len(ring buffer) of xs are added the ring buffer.'
xs = np.asarray(xs)
if self.shape[1:] != xs.shape[1:]:
raise ValueError("Element's shape mismatch. RingBuffer.shape={}. "
"xs.shape={}".format(self.shape, xs.shape))
len_self = len(self)
len_xs = len(xs)
if len_self <= len_xs:
xs = xs[-len_self:]
len_xs = len(xs)
else:
self[:-len_xs] = self[len_xs:]
self[-len_xs:] = xs
def append(self, x):
'Adds element x to the ring buffer.'
x = np.asarray(x)
if self.shape[1:] != x.shape:
raise ValueError("Element's shape mismatch. RingBuffer.shape={}. "
"x.shape={}, x=".format(self.shape, x.shape, x))
len_self = len(self)
self[:-1] = self[1:]
self[-1] = x
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
20359,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
20359,
199,
2344,
199,
32,
2502,
26,
603,
6936,
377,
455,
656,
83,
199,
2344,
199,
646,
2680,
465,
980,
421,
199,
533,
820,
316,
3299,
8,
1590,
14,
8237,
304,
272,
283,
33,
3510,
13014,
12133,
3335,
3530,
2286,
347,
636,
1222,
721,
1886,
12,
1324,
63,
1144,
304,
267,
1559,
275,
980,
14,
8748,
8,
1210,
63,
1144,
680,
1345,
8,
1886,
9,
267,
372,
1559,
339,
347,
636,
1144,
63,
14450,
721,
277,
12,
1559,
304,
267,
340,
1559,
365,
488,
26,
372,
339,
347,
636,
1144,
63,
3823,
721,
277,
12,
734,
63,
5250,
12,
1067,
29,
403,
304,
267,
372,
980,
14,
8237,
855,
1144,
63,
3823,
721,
277,
12,
734,
63,
5250,
12,
1067,
9,
339,
347,
12247,
8,
277,
12,
12965,
304,
267,
283,
14995,
1625,
12965,
370,
314,
12133,
3335,
14,
982,
12965,
365,
8088,
2419,
314,
12133,
283,
267,
283,
2738,
12,
314,
2061,
822,
8,
5985,
3335,
9,
402,
12965,
787,
3483,
314,
12133,
3335,
3530,
267,
12965,
275,
980,
14,
8748,
8,
7977,
9,
267,
340,
291,
14,
1392,
59,
17,
2938,
1137,
12965,
14,
1392,
59,
17,
10688,
288,
746,
1722,
480,
2162,
1159,
2215,
15015,
14,
820,
316,
3299,
14,
1392,
7622,
14,
298,
2490,
298,
7977,
14,
1392,
7622,
1674,
908,
8,
277,
14,
1392,
12,
12965,
14,
1392,
430,
267,
822,
63,
277,
275,
822,
8,
277,
9,
267,
822,
63,
7977,
275,
822,
8,
7977,
9,
267,
340,
822,
63,
277,
2695,
822,
63,
7977,
26,
288,
12965,
275,
12965,
1988,
552,
63,
277,
2938,
288,
822,
63,
7977,
275,
822,
8,
7977,
9,
267,
587,
26,
288,
291,
4439,
552,
63,
7977,
61,
275,
291,
59,
552,
63,
7977,
2938,
267,
291,
1988,
552,
63,
7977,
2938,
275,
12965,
339,
347,
5666,
8,
277,
12,
671,
304,
267,
283,
14995,
1819,
671,
370,
314,
12133,
3335,
3530,
267,
671,
275,
980,
14,
8748,
8,
88,
9,
267,
340,
291,
14,
1392,
59,
17,
2938,
1137,
671,
14,
1392,
26,
288,
746,
1722,
480,
2162,
1159,
2215,
15015,
14,
820,
316,
3299,
14,
1392,
7622,
14,
298,
2490,
298,
88,
14,
1392,
10324,
671,
25356,
908,
8,
277,
14,
1392,
12,
671,
14,
1392,
12,
671,
430,
267,
822,
63,
277,
275,
822,
8,
277,
9,
267,
291,
4439,
17,
61,
275,
291,
59,
17,
2938,
267,
291,
1988,
17,
61,
275,
671,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
20359,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
20359,
199,
2344,
199,
32,
2502,
26,
603,
6936,
377,
455,
656,
83,
199,
2344,
199,
646,
2680,
465,
980,
421,
199,
533,
820,
316,
3299,
8,
1590,
14,
8237,
304,
272,
283,
33,
3510,
13014,
12133,
3335,
3530,
2286,
347,
636,
1222,
721,
1886,
12,
1324,
63,
1144,
304,
267,
1559,
275,
980,
14,
8748,
8,
1210,
63,
1144,
680,
1345,
8,
1886,
9,
267,
372,
1559,
339,
347,
636,
1144,
63,
14450,
721,
277,
12,
1559,
304,
267,
340,
1559,
365,
488,
26,
372,
339,
347,
636,
1144,
63,
3823,
721,
277,
12,
734,
63,
5250,
12,
1067,
29,
403,
304,
267,
372,
980,
14,
8237,
855,
1144,
63,
3823,
721,
277,
12,
734,
63,
5250,
12,
1067,
9,
339,
347,
12247,
8,
277,
12,
12965,
304,
267,
283,
14995,
1625,
12965,
370,
314,
12133,
3335,
14,
982,
12965,
365,
8088,
2419,
314,
12133,
283,
267,
283,
2738,
12,
314,
2061,
822,
8,
5985,
3335,
9,
402,
12965,
787,
3483,
314,
12133,
3335,
3530,
267,
12965,
275,
980,
14,
8748,
8,
7977,
9,
267,
340,
291,
14,
1392,
59,
17,
2938,
1137,
12965,
14,
1392,
59,
17,
10688,
288,
746,
1722,
480,
2162,
1159,
2215,
15015,
14,
820,
316,
3299,
14,
1392,
7622,
14,
298,
2490,
298,
7977,
14,
1392,
7622,
1674,
908,
8,
277,
14,
1392,
12,
12965,
14,
1392,
430,
267,
822,
63,
277,
275,
822,
8,
277,
9,
267,
822,
63,
7977,
275,
822,
8,
7977,
9,
267,
340,
822,
63,
277,
2695,
822,
63,
7977,
26,
288,
12965,
275,
12965,
1988,
552,
63,
277,
2938,
288,
822,
63,
7977,
275,
822,
8,
7977,
9,
267,
587,
26,
288,
291,
4439,
552,
63,
7977,
61,
275,
291,
59,
552,
63,
7977,
2938,
267,
291,
1988,
552,
63,
7977,
2938,
275,
12965,
339,
347,
5666,
8,
277,
12,
671,
304,
267,
283,
14995,
1819,
671,
370,
314,
12133,
3335,
3530,
267,
671,
275,
980,
14,
8748,
8,
88,
9,
267,
340,
291,
14,
1392,
59,
17,
2938,
1137,
671,
14,
1392,
26,
288,
746,
1722,
480,
2162,
1159,
2215,
15015,
14,
820,
316,
3299,
14,
1392,
7622,
14,
298,
2490,
298,
88,
14,
1392,
10324,
671,
25356,
908,
8,
277,
14,
1392,
12,
671,
14,
1392,
12,
671,
430,
267,
822,
63,
277,
275,
822,
8,
277,
9,
267,
291,
4439,
17,
61,
275,
291,
59,
17,
2938,
267,
291,
1988,
17,
61,
275,
671,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
patochectp/navitia
|
source/jormungandr/jormungandr/georef.py
|
2
|
5365
|
# Copyright (c) 2001-2014, Canal TP and/or its affiliates. All rights reserved.
#
# This file is part of Navitia,
# the software to build cool stuff with public transport.
#
# Hope you'll enjoy and contribute to this project,
# powered by Canal TP (www.canaltp.fr).
# Help us simplify mobility and open public transport:
# a non ending quest to the responsive locomotion way of traveling!
#
# LICENCE: 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/>.
#
# Stay tuned using
# twitter @navitia
# IRC #navitia on freenode
# https://groups.google.com/d/forum/navitia
# www.navitia.io
from __future__ import absolute_import, print_function, unicode_literals, division
from navitiacommon import request_pb2, response_pb2, type_pb2
import logging
from jormungandr import utils
class Kraken(object):
def __init__(self, instance):
self.instance = instance
def place(self, place):
req = request_pb2.Request()
req.requested_api = type_pb2.place_uri
req.place_uri.uri = place
req.place_uri.depth = 2
response = self.instance.send_and_receive(req)
if response.places:
return response.places[0]
if utils.is_coord(place):
# In some cases, the given "from" is not always a findable address by kraken
# we just forward the given coord and return a pt object
lon, lat = utils.get_lon_lat(place)
p = type_pb2.PtObject()
p.uri = place
p.embedded_type = type_pb2.ADDRESS
p.address.coord.lon = lon
p.address.coord.lat = lat
p.address.uri = place
return p
return None
def get_car_co2_emission_on_crow_fly(self, origin, destination):
logger = logging.getLogger(__name__)
req = request_pb2.Request()
req.requested_api = type_pb2.car_co2_emission
req.car_co2_emission.origin.place = origin
req.car_co2_emission.origin.access_duration = 0
req.car_co2_emission.destination.place = destination
req.car_co2_emission.destination.access_duration = 0
response = self.instance.send_and_receive(req)
if response.error and response.error.id == response_pb2.Error.error_id.Value('no_solution'):
logger.error("Cannot compute car co2 emission from {} to {}".format(origin, destination))
return None
return response.car_co2_emission
def get_crow_fly(self, origin, streetnetwork_mode, max_duration, max_nb_crowfly, **kwargs):
# Getting stop_points or stop_areas using crow fly
# the distance of crow fly is defined by the mode speed and max_duration
req = request_pb2.Request()
req.requested_api = type_pb2.places_nearby
req.places_nearby.uri = origin
req.places_nearby.distance = kwargs.get(streetnetwork_mode, kwargs.get("walking")) * max_duration
req.places_nearby.depth = 0
req.places_nearby.count = max_nb_crowfly
req.places_nearby.start_page = 0
req.disable_feedpublisher = True
# we are only interested in public transports
req.places_nearby.types.append(type_pb2.STOP_POINT)
res = self.instance.send_and_receive(req)
if len(res.feed_publishers) != 0:
logger = logging.getLogger(__name__)
logger.error("feed publisher not empty: expect performance regression!")
return res.places_nearby
def get_stop_points_for_stop_area(self, uri):
req = request_pb2.Request()
req.requested_api = type_pb2.PTREFERENTIAL
req.ptref.requested_type = type_pb2.STOP_POINT
req.ptref.count = 100
req.ptref.start_page = 0
req.ptref.depth = 0
req.ptref.filter = 'stop_area.uri = {uri}'.format(uri=uri)
result = self.instance.send_and_receive(req)
if not result.stop_points:
logging.getLogger(__name__).info(
'PtRef, Unable to find stop_point with filter {}'.format(req.ptref.filter)
)
return result.stop_points
def get_stop_points_from_uri(self, uri):
req = request_pb2.Request()
req.requested_api = type_pb2.PTREFERENTIAL
req.ptref.requested_type = type_pb2.STOP_POINT
req.ptref.count = 100
req.ptref.start_page = 0
req.ptref.depth = 0
req.ptref.filter = 'stop_point.uri = {uri}'.format(uri=uri)
result = self.instance.send_and_receive(req)
return result.stop_points
def get_odt_stop_points(self, coord):
req = request_pb2.Request()
req.requested_api = type_pb2.odt_stop_points
req.coord.lon = coord.lon
req.coord.lat = coord.lat
return self.instance.send_and_receive(req).stop_points
|
agpl-3.0
|
[
3,
221,
1898,
334,
67,
9,
12521,
13,
7280,
12,
6855,
279,
24328,
436,
15,
269,
2399,
29172,
2335,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
20721,
14037,
12,
199,
3,
258,
314,
2032,
370,
1900,
32268,
8292,
543,
4575,
7773,
14,
199,
3,
199,
3,
869,
13458,
1265,
7171,
655,
26729,
436,
28567,
370,
642,
2199,
12,
199,
3,
258,
13131,
16179,
701,
6855,
279,
24328,
334,
1544,
14,
2425,
279,
683,
14,
4391,
680,
199,
3,
15456,
2739,
15037,
1303,
3195,
436,
1551,
4575,
7773,
26,
199,
3,
258,
282,
2222,
13401,
221,
613,
370,
314,
9163,
3398,
560,
331,
15335,
4340,
402,
1468,
1090,
316,
1,
199,
3,
199,
3,
5059,
6013,
26,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
7083,
89,
15486,
379,
1808,
199,
3,
15811,
768,
15595,
14037,
199,
3,
473,
8205,
327,
15595,
14037,
641,
289,
3441,
380,
199,
3,
4178,
921,
2634,
14,
3098,
14,
957,
15,
68,
15,
10044,
15,
15595,
14037,
199,
3,
20732,
14,
15595,
14037,
14,
2308,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
12,
2649,
63,
5955,
12,
4629,
199,
504,
12670,
14037,
2330,
492,
1056,
63,
3317,
18,
12,
1177,
63,
3317,
18,
12,
730,
63,
3317,
18,
199,
646,
2050,
199,
504,
1335,
1025,
10335,
460,
82,
492,
3778,
421,
199,
533,
1804,
345,
917,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1256,
304,
267,
291,
14,
842,
275,
1256,
339,
347,
4192,
8,
277,
12,
4192,
304,
267,
2648,
275,
1056,
63,
3317,
18,
14,
2017,
342,
267,
2648,
14,
11151,
63,
1246,
275,
730,
63,
3317,
18,
14,
2778,
63,
2302,
267,
2648,
14,
2778,
63,
2302,
14,
2302,
275,
4192,
267,
2648,
14,
2778,
63,
2302,
14,
4631,
275,
499,
267,
1177,
275,
291,
14,
842,
14,
2254,
63,
460,
63,
9391,
8,
2103,
9,
267,
340,
1177,
14,
10696,
26,
288,
372,
1177,
14,
10696,
59,
16,
61,
267,
340,
3778,
14,
374,
63,
7988,
8,
2778,
304,
288,
327,
1010,
2005,
5560,
12,
314,
1627,
298,
504,
2,
365,
440,
3544,
282,
2342,
461,
2287,
701,
1022,
345,
917,
288,
327,
781,
2951,
7568,
314,
1627,
11021,
436,
372,
282,
10063,
909,
288,
6132,
12,
8396,
275,
3778,
14,
362,
63,
5298,
63,
4452,
8,
2778,
9,
288,
299,
275,
730,
63,
3317,
18,
14,
19886,
1692,
342,
288,
299,
14,
2302,
275,
4192,
288,
299,
14,
18757,
63,
466,
275,
730,
63,
3317,
18,
14,
12368,
288,
299,
14,
1562,
14,
7988,
14,
5298,
275,
6132,
288,
299,
14,
1562,
14,
7988,
14,
4452,
275,
8396,
288,
299,
14,
1562,
14,
2302,
275,
4192,
288,
372,
299,
267,
372,
488,
339,
347,
664,
63,
7007,
63,
331,
18,
63,
69,
2250,
63,
265,
63,
67,
1143,
63,
21600,
8,
277,
12,
6330,
12,
5724,
304,
267,
2512,
275,
2050,
14,
5572,
3460,
354,
3368,
267,
2648,
275,
1056,
63,
3317,
18,
14,
2017,
342,
267,
2648,
14,
11151,
63,
1246,
275,
730,
63,
3317,
18,
14,
7007,
63,
331,
18,
63,
69,
2250,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6493,
14,
2778,
275,
6330,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6493,
14,
2732,
63,
5553,
275,
378,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6881,
14,
2778,
275,
5724,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6881,
14,
2732,
63,
5553,
275,
378,
398,
1177,
275,
291,
14,
842,
14,
2254,
63,
460,
63,
9391,
8,
2103,
9,
267,
340,
1177,
14,
705,
436,
1177,
14,
705,
14,
344,
508,
1177,
63,
3317,
18,
14,
547,
14,
705,
63,
344,
14,
1110,
360,
889,
63,
14458,
735,
288,
2512,
14,
705,
480,
6612,
4526,
9590,
512,
18,
325,
2250,
687,
1052,
370,
8352,
908,
8,
6493,
12,
5724,
430,
288,
372,
488,
267,
372,
1177,
14,
7007,
63,
331,
18,
63,
69,
2250,
339,
347,
664,
63,
67,
1143,
63,
21600,
8,
277,
12,
6330,
12,
410,
7936,
1200,
63,
632,
12,
1390,
63,
5553,
12,
1390,
63,
4994,
63,
67,
1143,
21600,
12,
1011,
958,
304,
398,
327,
20703,
3631,
63,
3438,
503,
3631,
63,
32354,
1808,
286,
1143,
23158,
267,
327,
314,
6033,
402,
286,
1143,
23158,
365,
3247,
701,
314,
818,
8112,
436,
1390,
63,
5553,
267,
2648,
275,
1056,
63,
3317,
18,
14,
2017,
342,
267,
2648,
14,
11151,
63,
1246,
275,
730,
63,
3317,
18,
14,
10696,
63,
21078,
991,
267,
2648,
14,
10696,
63,
21078,
991,
14,
2302,
275,
6330,
267,
2648,
14,
10696,
63,
21078,
991,
14,
5590,
275,
2074,
14,
362,
8,
20451,
1200,
63,
632,
12,
2074,
14,
362,
480,
7757,
316,
2237,
627,
1390,
63,
5553,
267,
2648,
14,
10696,
63,
21078,
991,
14,
4631,
275,
378,
267,
2648,
14,
10696,
63,
21078,
991,
14,
835,
275,
1390,
63,
4994,
63,
67,
1143,
21600,
267,
2648,
14,
10696,
63,
21078,
991,
14,
928,
63,
1606,
275,
378,
267,
2648,
14,
5993,
63,
3871,
12789,
275,
715,
267,
327,
781,
787,
1454,
22201,
315,
4575,
7773,
83,
267,
2648,
14,
10696,
63,
21078,
991,
14,
1313,
14,
740,
8,
466,
63,
3317,
18,
14
] |
[
221,
1898,
334,
67,
9,
12521,
13,
7280,
12,
6855,
279,
24328,
436,
15,
269,
2399,
29172,
2335,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
20721,
14037,
12,
199,
3,
258,
314,
2032,
370,
1900,
32268,
8292,
543,
4575,
7773,
14,
199,
3,
199,
3,
869,
13458,
1265,
7171,
655,
26729,
436,
28567,
370,
642,
2199,
12,
199,
3,
258,
13131,
16179,
701,
6855,
279,
24328,
334,
1544,
14,
2425,
279,
683,
14,
4391,
680,
199,
3,
15456,
2739,
15037,
1303,
3195,
436,
1551,
4575,
7773,
26,
199,
3,
258,
282,
2222,
13401,
221,
613,
370,
314,
9163,
3398,
560,
331,
15335,
4340,
402,
1468,
1090,
316,
1,
199,
3,
199,
3,
5059,
6013,
26,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
7083,
89,
15486,
379,
1808,
199,
3,
15811,
768,
15595,
14037,
199,
3,
473,
8205,
327,
15595,
14037,
641,
289,
3441,
380,
199,
3,
4178,
921,
2634,
14,
3098,
14,
957,
15,
68,
15,
10044,
15,
15595,
14037,
199,
3,
20732,
14,
15595,
14037,
14,
2308,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
870,
63,
1593,
12,
2649,
63,
5955,
12,
4629,
199,
504,
12670,
14037,
2330,
492,
1056,
63,
3317,
18,
12,
1177,
63,
3317,
18,
12,
730,
63,
3317,
18,
199,
646,
2050,
199,
504,
1335,
1025,
10335,
460,
82,
492,
3778,
421,
199,
533,
1804,
345,
917,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1256,
304,
267,
291,
14,
842,
275,
1256,
339,
347,
4192,
8,
277,
12,
4192,
304,
267,
2648,
275,
1056,
63,
3317,
18,
14,
2017,
342,
267,
2648,
14,
11151,
63,
1246,
275,
730,
63,
3317,
18,
14,
2778,
63,
2302,
267,
2648,
14,
2778,
63,
2302,
14,
2302,
275,
4192,
267,
2648,
14,
2778,
63,
2302,
14,
4631,
275,
499,
267,
1177,
275,
291,
14,
842,
14,
2254,
63,
460,
63,
9391,
8,
2103,
9,
267,
340,
1177,
14,
10696,
26,
288,
372,
1177,
14,
10696,
59,
16,
61,
267,
340,
3778,
14,
374,
63,
7988,
8,
2778,
304,
288,
327,
1010,
2005,
5560,
12,
314,
1627,
298,
504,
2,
365,
440,
3544,
282,
2342,
461,
2287,
701,
1022,
345,
917,
288,
327,
781,
2951,
7568,
314,
1627,
11021,
436,
372,
282,
10063,
909,
288,
6132,
12,
8396,
275,
3778,
14,
362,
63,
5298,
63,
4452,
8,
2778,
9,
288,
299,
275,
730,
63,
3317,
18,
14,
19886,
1692,
342,
288,
299,
14,
2302,
275,
4192,
288,
299,
14,
18757,
63,
466,
275,
730,
63,
3317,
18,
14,
12368,
288,
299,
14,
1562,
14,
7988,
14,
5298,
275,
6132,
288,
299,
14,
1562,
14,
7988,
14,
4452,
275,
8396,
288,
299,
14,
1562,
14,
2302,
275,
4192,
288,
372,
299,
267,
372,
488,
339,
347,
664,
63,
7007,
63,
331,
18,
63,
69,
2250,
63,
265,
63,
67,
1143,
63,
21600,
8,
277,
12,
6330,
12,
5724,
304,
267,
2512,
275,
2050,
14,
5572,
3460,
354,
3368,
267,
2648,
275,
1056,
63,
3317,
18,
14,
2017,
342,
267,
2648,
14,
11151,
63,
1246,
275,
730,
63,
3317,
18,
14,
7007,
63,
331,
18,
63,
69,
2250,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6493,
14,
2778,
275,
6330,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6493,
14,
2732,
63,
5553,
275,
378,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6881,
14,
2778,
275,
5724,
267,
2648,
14,
7007,
63,
331,
18,
63,
69,
2250,
14,
6881,
14,
2732,
63,
5553,
275,
378,
398,
1177,
275,
291,
14,
842,
14,
2254,
63,
460,
63,
9391,
8,
2103,
9,
267,
340,
1177,
14,
705,
436,
1177,
14,
705,
14,
344,
508,
1177,
63,
3317,
18,
14,
547,
14,
705,
63,
344,
14,
1110,
360,
889,
63,
14458,
735,
288,
2512,
14,
705,
480,
6612,
4526,
9590,
512,
18,
325,
2250,
687,
1052,
370,
8352,
908,
8,
6493,
12,
5724,
430,
288,
372,
488,
267,
372,
1177,
14,
7007,
63,
331,
18,
63,
69,
2250,
339,
347,
664,
63,
67,
1143,
63,
21600,
8,
277,
12,
6330,
12,
410,
7936,
1200,
63,
632,
12,
1390,
63,
5553,
12,
1390,
63,
4994,
63,
67,
1143,
21600,
12,
1011,
958,
304,
398,
327,
20703,
3631,
63,
3438,
503,
3631,
63,
32354,
1808,
286,
1143,
23158,
267,
327,
314,
6033,
402,
286,
1143,
23158,
365,
3247,
701,
314,
818,
8112,
436,
1390,
63,
5553,
267,
2648,
275,
1056,
63,
3317,
18,
14,
2017,
342,
267,
2648,
14,
11151,
63,
1246,
275,
730,
63,
3317,
18,
14,
10696,
63,
21078,
991,
267,
2648,
14,
10696,
63,
21078,
991,
14,
2302,
275,
6330,
267,
2648,
14,
10696,
63,
21078,
991,
14,
5590,
275,
2074,
14,
362,
8,
20451,
1200,
63,
632,
12,
2074,
14,
362,
480,
7757,
316,
2237,
627,
1390,
63,
5553,
267,
2648,
14,
10696,
63,
21078,
991,
14,
4631,
275,
378,
267,
2648,
14,
10696,
63,
21078,
991,
14,
835,
275,
1390,
63,
4994,
63,
67,
1143,
21600,
267,
2648,
14,
10696,
63,
21078,
991,
14,
928,
63,
1606,
275,
378,
267,
2648,
14,
5993,
63,
3871,
12789,
275,
715,
267,
327,
781,
787,
1454,
22201,
315,
4575,
7773,
83,
267,
2648,
14,
10696,
63,
21078,
991,
14,
1313,
14,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Belval/pdf2image
|
pdf2image/parsers.py
|
1
|
1820
|
"""
pdf2image custom buffer parsers
"""
from io import BytesIO
from PIL import Image
def parse_buffer_to_ppm(data):
"""Parse PPM file bytes to Pillow Image"""
images = []
index = 0
while index < len(data):
code, size, rgb = tuple(data[index : index + 40].split(b"\n")[0:3])
size_x, size_y = tuple(size.split(b" "))
file_size = len(code) + len(size) + len(rgb) + 3 + int(size_x) * int(size_y) * 3
images.append(Image.open(BytesIO(data[index : index + file_size])))
index += file_size
return images
def parse_buffer_to_pgm(data):
"""Parse PGM file bytes to Pillow Image"""
images = []
index = 0
while index < len(data):
code, size, maxval = tuple(data[index : index + 40].split(b"\n")[0:3])
size_x, size_y = tuple(size.split(b" "))
file_size = len(code) + len(size) + len(maxval) + 3 + int(size_x) * int(size_y)
images.append(Image.open(BytesIO(data[index : index + file_size])))
index += file_size
return images
def parse_buffer_to_jpeg(data):
"""Parse JPEG file bytes to Pillow Image"""
return [
Image.open(BytesIO(image_data + b"\xff\xd9"))
for image_data in data.split(b"\xff\xd9")[
:-1
] # Last element is obviously empty
]
def parse_buffer_to_png(data):
"""Parse PNG file bytes to Pillow Image"""
images = []
c1 = 0
c2 = 0
data_len = len(data)
while c1 < data_len:
# IEND can appear in a PNG without being the actual end
if data[c2 : c2 + 4] == b"IEND" and (
c2 + 8 == data_len or data[c2 + 9 : c2 + 12] == b"PNG"
):
images.append(Image.open(BytesIO(data[c1 : c2 + 8])))
c1 = c2 + 8
c2 = c1
c2 += 1
return images
|
mit
|
[
624,
272,
11249,
18,
1569,
3537,
3335,
21295,
199,
624,
199,
199,
504,
5890,
492,
11808,
199,
199,
504,
14937,
492,
6047,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
802,
77,
8,
576,
304,
272,
408,
4003,
510,
10793,
570,
2783,
370,
18130,
674,
6047,
624,
339,
5935,
275,
942,
339,
1478,
275,
378,
339,
1830,
1478,
665,
822,
8,
576,
304,
267,
1233,
12,
1568,
12,
15180,
275,
2008,
8,
576,
59,
1080,
520,
1478,
435,
6335,
1055,
1294,
8,
66,
3212,
78,
9981,
16,
26,
19,
566,
267,
1568,
63,
88,
12,
1568,
63,
89,
275,
2008,
8,
890,
14,
1294,
8,
66,
2,
26725,
267,
570,
63,
890,
275,
822,
8,
600,
9,
435,
822,
8,
890,
9,
435,
822,
8,
10090,
9,
435,
650,
435,
1109,
8,
890,
63,
88,
9,
627,
1109,
8,
890,
63,
89,
9,
627,
650,
267,
5935,
14,
740,
8,
3491,
14,
1490,
8,
15466,
8,
576,
59,
1080,
520,
1478,
435,
570,
63,
890,
11845,
267,
1478,
847,
570,
63,
890,
339,
372,
5935,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
4198,
77,
8,
576,
304,
272,
408,
4003,
510,
22636,
570,
2783,
370,
18130,
674,
6047,
624,
339,
5935,
275,
942,
339,
1478,
275,
378,
339,
1830,
1478,
665,
822,
8,
576,
304,
267,
1233,
12,
1568,
12,
23291,
275,
2008,
8,
576,
59,
1080,
520,
1478,
435,
6335,
1055,
1294,
8,
66,
3212,
78,
9981,
16,
26,
19,
566,
267,
1568,
63,
88,
12,
1568,
63,
89,
275,
2008,
8,
890,
14,
1294,
8,
66,
2,
26725,
267,
570,
63,
890,
275,
822,
8,
600,
9,
435,
822,
8,
890,
9,
435,
822,
8,
30909,
9,
435,
650,
435,
1109,
8,
890,
63,
88,
9,
627,
1109,
8,
890,
63,
89,
9,
267,
5935,
14,
740,
8,
3491,
14,
1490,
8,
15466,
8,
576,
59,
1080,
520,
1478,
435,
570,
63,
890,
11845,
267,
1478,
847,
570,
63,
890,
339,
372,
5935,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
14230,
8,
576,
304,
272,
408,
4003,
1603,
17557,
570,
2783,
370,
18130,
674,
6047,
624,
339,
372,
359,
267,
6047,
14,
1490,
8,
15466,
8,
1569,
63,
576,
435,
330,
3212,
3581,
60,
2207,
25,
2237,
267,
367,
1834,
63,
576,
315,
666,
14,
1294,
8,
66,
3212,
3581,
60,
2207,
25,
9981,
288,
22901,
17,
267,
1622,
221,
327,
15237,
1819,
365,
25259,
590,
2701,
272,
1622,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
4524,
8,
576,
304,
272,
408,
4003,
26951,
570,
2783,
370,
18130,
674,
6047,
624,
339,
5935,
275,
942,
339,
286,
17,
275,
378,
272,
286,
18,
275,
378,
272,
666,
63,
552,
275,
822,
8,
576,
9,
272,
1830,
286,
17,
665,
666,
63,
552,
26,
267,
327,
473,
3902,
883,
7468,
315,
282,
26951,
1928,
3769,
314,
3503,
1284,
267,
340,
666,
59,
67,
18,
520,
286,
18,
435,
841,
61,
508,
330,
2,
41,
3902,
2,
436,
334,
288,
286,
18,
435,
1695,
508,
666,
63,
552,
503,
666,
59,
67,
18,
435,
1749,
520,
286,
18,
435,
3144,
61,
508,
330,
2,
24454,
2,
267,
3461,
288,
5935,
14,
740,
8,
3491,
14,
1490,
8,
15466,
8,
576,
59,
67,
17,
520,
286,
18,
435,
1695,
11845,
288,
286,
17,
275,
286,
18,
435,
1695,
288,
286,
18,
275,
286,
17,
267,
286,
18,
847,
413,
339,
372,
5935,
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
] |
[
272,
11249,
18,
1569,
3537,
3335,
21295,
199,
624,
199,
199,
504,
5890,
492,
11808,
199,
199,
504,
14937,
492,
6047,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
802,
77,
8,
576,
304,
272,
408,
4003,
510,
10793,
570,
2783,
370,
18130,
674,
6047,
624,
339,
5935,
275,
942,
339,
1478,
275,
378,
339,
1830,
1478,
665,
822,
8,
576,
304,
267,
1233,
12,
1568,
12,
15180,
275,
2008,
8,
576,
59,
1080,
520,
1478,
435,
6335,
1055,
1294,
8,
66,
3212,
78,
9981,
16,
26,
19,
566,
267,
1568,
63,
88,
12,
1568,
63,
89,
275,
2008,
8,
890,
14,
1294,
8,
66,
2,
26725,
267,
570,
63,
890,
275,
822,
8,
600,
9,
435,
822,
8,
890,
9,
435,
822,
8,
10090,
9,
435,
650,
435,
1109,
8,
890,
63,
88,
9,
627,
1109,
8,
890,
63,
89,
9,
627,
650,
267,
5935,
14,
740,
8,
3491,
14,
1490,
8,
15466,
8,
576,
59,
1080,
520,
1478,
435,
570,
63,
890,
11845,
267,
1478,
847,
570,
63,
890,
339,
372,
5935,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
4198,
77,
8,
576,
304,
272,
408,
4003,
510,
22636,
570,
2783,
370,
18130,
674,
6047,
624,
339,
5935,
275,
942,
339,
1478,
275,
378,
339,
1830,
1478,
665,
822,
8,
576,
304,
267,
1233,
12,
1568,
12,
23291,
275,
2008,
8,
576,
59,
1080,
520,
1478,
435,
6335,
1055,
1294,
8,
66,
3212,
78,
9981,
16,
26,
19,
566,
267,
1568,
63,
88,
12,
1568,
63,
89,
275,
2008,
8,
890,
14,
1294,
8,
66,
2,
26725,
267,
570,
63,
890,
275,
822,
8,
600,
9,
435,
822,
8,
890,
9,
435,
822,
8,
30909,
9,
435,
650,
435,
1109,
8,
890,
63,
88,
9,
627,
1109,
8,
890,
63,
89,
9,
267,
5935,
14,
740,
8,
3491,
14,
1490,
8,
15466,
8,
576,
59,
1080,
520,
1478,
435,
570,
63,
890,
11845,
267,
1478,
847,
570,
63,
890,
339,
372,
5935,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
14230,
8,
576,
304,
272,
408,
4003,
1603,
17557,
570,
2783,
370,
18130,
674,
6047,
624,
339,
372,
359,
267,
6047,
14,
1490,
8,
15466,
8,
1569,
63,
576,
435,
330,
3212,
3581,
60,
2207,
25,
2237,
267,
367,
1834,
63,
576,
315,
666,
14,
1294,
8,
66,
3212,
3581,
60,
2207,
25,
9981,
288,
22901,
17,
267,
1622,
221,
327,
15237,
1819,
365,
25259,
590,
2701,
272,
1622,
421,
199,
318,
2198,
63,
2738,
63,
475,
63,
4524,
8,
576,
304,
272,
408,
4003,
26951,
570,
2783,
370,
18130,
674,
6047,
624,
339,
5935,
275,
942,
339,
286,
17,
275,
378,
272,
286,
18,
275,
378,
272,
666,
63,
552,
275,
822,
8,
576,
9,
272,
1830,
286,
17,
665,
666,
63,
552,
26,
267,
327,
473,
3902,
883,
7468,
315,
282,
26951,
1928,
3769,
314,
3503,
1284,
267,
340,
666,
59,
67,
18,
520,
286,
18,
435,
841,
61,
508,
330,
2,
41,
3902,
2,
436,
334,
288,
286,
18,
435,
1695,
508,
666,
63,
552,
503,
666,
59,
67,
18,
435,
1749,
520,
286,
18,
435,
3144,
61,
508,
330,
2,
24454,
2,
267,
3461,
288,
5935,
14,
740,
8,
3491,
14,
1490,
8,
15466,
8,
576,
59,
67,
17,
520,
286,
18,
435,
1695,
11845,
288,
286,
17,
275,
286,
18,
435,
1695,
288,
286,
18,
275,
286,
17,
267,
286,
18,
847,
413,
339,
372,
5935,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
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ddatabases.py
|
11
|
31571
|
# -*- coding: utf-8 -*-
# Copyright (c)2012 Rackspace US, Inc.
# 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.
from functools import wraps
import six
from pyrax.client import BaseClient
import pyrax.exceptions as exc
from pyrax.manager import BaseManager
from pyrax.resource import BaseResource
import pyrax.utils as utils
def assure_instance(fnc):
@wraps(fnc)
def _wrapped(self, instance, *args, **kwargs):
if not isinstance(instance, CloudDatabaseInstance):
# Must be the ID
instance = self._manager.get(instance)
return fnc(self, instance, *args, **kwargs)
return _wrapped
class CloudDatabaseVolume(object):
instance = None
size = None
used = None
def __init__(self, instance, info):
self.instance = instance
for key, val in info.items():
setattr(self, key, val)
def resize(self, size):
"""
Resize the volume to the specified size (in GB).
"""
self.instance.resize_volume(size)
self.size = size
def get(self, att):
"""
For compatibility with regular resource objects.
"""
return getattr(self, att)
class CloudDatabaseManager(BaseManager):
"""
This class manages communication with Cloud Database instances.
"""
def get(self, item):
"""
This additional code is necessary to properly return the 'volume'
attribute of the instance as a CloudDatabaseVolume object instead of
a raw dict.
"""
resource = super(CloudDatabaseManager, self).get(item)
resource.volume = CloudDatabaseVolume(resource, resource.volume)
return resource
def _create_body(self, name, flavor=None, volume=None, databases=None,
users=None, version=None, type=None):
"""
Used to create the dict required to create a Cloud Database instance.
"""
if flavor is None:
flavor = 1
flavor_ref = self.api._get_flavor_ref(flavor)
if volume is None:
volume = 1
if databases is None:
databases = []
if users is None:
users = []
body = {"instance": {
"name": name,
"flavorRef": flavor_ref,
"volume": {"size": volume},
"databases": databases,
"users": users,
}}
if type is not None or version is not None:
required = (type, version)
if all(required):
body['instance']['datastore'] = {"type": type, "version": version}
else:
raise exc.MissingCloudDatabaseParameter("Specifying a datastore"
" requires both the datastore type as well as the version.")
return body
def create_backup(self, instance, name, description=None):
"""
Creates a backup of the specified instance, giving it the specified
name along with an optional description.
"""
body = {"backup": {
"instance": utils.get_id(instance),
"name": name,
}}
if description is not None:
body["backup"]["description"] = description
uri = "/backups"
resp, resp_body = self.api.method_post(uri, body=body)
mgr = self.api._backup_manager
return CloudDatabaseBackup(mgr, body.get("backup"))
def restore_backup(self, backup, name, flavor, volume):
"""
Restores a backup to a new database instance. You must supply a backup
(either the ID or a CloudDatabaseBackup object), a name for the new
instance, as well as a flavor and volume size (in GB) for the instance.
"""
flavor_ref = self.api._get_flavor_ref(flavor)
body = {"instance": {
"name": name,
"flavorRef": flavor_ref,
"volume": {"size": volume},
"restorePoint": {"backupRef": utils.get_id(backup)},
}}
uri = "/%s" % self.uri_base
resp, resp_body = self.api.method_post(uri, body=body)
return CloudDatabaseInstance(self, resp_body.get("instance", {}))
def list_backups(self, instance=None, marker=0, limit=20):
"""
Returns a paginated list of backups, or just for a particular
instance.
"""
return self.api._backup_manager.list(instance=instance, limit=limit,
marker=marker)
def _list_backups_for_instance(self, instance, marker=0, limit=20):
"""
Instance-specific backups are handled through the instance manager,
not the backup manager.
"""
uri = "/%s/%s/backups?limit=%d&marker=%d" % (self.uri_base,
utils.get_id(instance),
int(limit),
int(marker))
resp, resp_body = self.api.method_get(uri)
mgr = self.api._backup_manager
return [CloudDatabaseBackup(mgr, backup)
for backup in resp_body.get("backups")]
class CloudDatabaseDatabaseManager(BaseManager):
"""
This class manages communication with databases on Cloud Database instances.
"""
def _create_body(self, name, character_set=None, collate=None):
body = {"databases": [
{"name": name,
"character_set": character_set,
"collate": collate,
}]}
return body
class CloudDatabaseUserManager(BaseManager):
"""
This class handles operations on the users in a database on a Cloud
Database instance.
"""
def _create_body(self, name, password, databases=None, database_names=None,
host=None):
db_dicts = [{"name": db} for db in database_names]
body = {"users": [
{"name": name,
"password": password,
"databases": db_dicts,
}]}
if host:
body["users"][0]["host"] = host
return body
def _get_db_names(self, dbs, strict=True):
"""
Accepts a single db (name or object) or a list of dbs, and returns a
list of database names. If any of the supplied dbs do not exist, a
NoSuchDatabase exception will be raised, unless you pass strict=False.
"""
dbs = utils.coerce_to_list(dbs)
db_names = [utils.get_name(db) for db in dbs]
if strict:
good_dbs = self.instance.list_databases()
good_names = [utils.get_name(good_db) for good_db in good_dbs]
bad_names = [db_name for db_name in db_names
if db_name not in good_names]
if bad_names:
bad = ", ".join(bad_names)
raise exc.NoSuchDatabase("The following database(s) were not "
"found: %s" % bad)
return db_names
def change_user_password(self, user, new_pass):
"""
Changes the password for the user to the supplied value.
Returns None upon success; raises PasswordChangeFailed if the call
does not complete successfully.
"""
return self.update(user, password=new_pass)
def update(self, user, name=None, password=None, host=None):
"""
Allows you to change one or more of the user's username, password, or
host.
"""
if not any((name, password, host)):
raise exc.MissingDBUserParameters("You must supply at least one of "
"the following: new username, new password, or new host "
"specification.")
if not isinstance(user, CloudDatabaseUser):
# Must be the ID/name
user = self.get(user)
dct = {}
if name and (name != user.name):
dct["name"] = name
if host and (host != user.host):
dct["host"] = host
if password:
dct["password"] = password
if not dct:
raise exc.DBUpdateUnchanged("You must supply at least one changed "
"value when updating a user.")
uri = "/%s/%s" % (self.uri_base, user.name)
body = {"user": dct}
resp, resp_body = self.api.method_put(uri, body=body)
return None
def list_user_access(self, user):
"""
Returns a list of all database names for which the specified user
has access rights.
"""
user = utils.get_name(user)
uri = "/%s/%s/databases" % (self.uri_base, user)
try:
resp, resp_body = self.api.method_get(uri)
except exc.NotFound as e:
raise exc.NoSuchDatabaseUser("User '%s' does not exist." % user)
dbs = resp_body.get("databases", {})
return [CloudDatabaseDatabase(self, db) for db in dbs]
def grant_user_access(self, user, db_names, strict=True):
"""
Gives access to the databases listed in `db_names` to the user. You may
pass in either a single db or a list of dbs.
If any of the databases do not exist, a NoSuchDatabase exception will
be raised, unless you specify `strict=False` in the call.
"""
user = utils.get_name(user)
uri = "/%s/%s/databases" % (self.uri_base, user)
db_names = self._get_db_names(db_names, strict=strict)
dbs = [{"name": db_name} for db_name in db_names]
body = {"databases": dbs}
try:
resp, resp_body = self.api.method_put(uri, body=body)
except exc.NotFound as e:
raise exc.NoSuchDatabaseUser("User '%s' does not exist." % user)
def revoke_user_access(self, user, db_names, strict=True):
"""
Revokes access to the databases listed in `db_names` for the user.
If any of the databases do not exist, a NoSuchDatabase exception will
be raised, unless you specify `strict=False` in the call.
"""
user = utils.get_name(user)
db_names = self._get_db_names(db_names, strict=strict)
bad_names = []
for db_name in db_names:
uri = "/%s/%s/databases/%s" % (self.uri_base, user, db_name)
resp, resp_body = self.api.method_delete(uri)
class CloudDatabaseBackupManager(BaseManager):
"""
This class handles operations on backups for a Cloud Database instance.
"""
def _create_body(self, name, instance, description=None):
body = {"backup": {
"instance": utils.get_id(instance),
"name": name,
}}
if description is not None:
body["backup"]["description"] = description
return body
def list(self, instance=None, limit=20, marker=0):
"""
Return a paginated list of backups, or just for a particular
instance.
"""
if instance is None:
return super(CloudDatabaseBackupManager, self).list()
return self.api._manager._list_backups_for_instance(instance, limit=limit,
marker=marker)
class CloudDatabaseInstance(BaseResource):
"""
This class represents a MySQL instance in the cloud.
"""
def __init__(self, *args, **kwargs):
super(CloudDatabaseInstance, self).__init__(*args, **kwargs)
self._database_manager = CloudDatabaseDatabaseManager(self.manager.api,
resource_class=CloudDatabaseDatabase, response_key="database",
uri_base="instances/%s/databases" % self.id)
self._user_manager = CloudDatabaseUserManager(self.manager.api,
resource_class=CloudDatabaseUser, response_key="user",
uri_base="instances/%s/users" % self.id)
# Add references to the parent instance to the managers.
self._database_manager.instance = self._user_manager.instance = self
# Remove the lazy load
if not self.loaded:
self.get()
def get(self):
"""
Need to override the default get() behavior by making the 'volume'
attribute into a CloudDatabaseVolume object instead of the raw dict.
"""
super(CloudDatabaseInstance, self).get()
# Make the volume into an accessible object instead of a dict
self.volume = CloudDatabaseVolume(self, self.volume)
def list_databases(self, limit=None, marker=None):
"""Returns a list of the names of all databases for this instance."""
return self._database_manager.list(limit=limit, marker=marker)
def list_users(self, limit=None, marker=None):
"""Returns a list of the names of all users for this instance."""
return self._user_manager.list(limit=limit, marker=marker)
def get_user(self, name):
"""
Finds the user in this instance with the specified name, and
returns a CloudDatabaseUser object. If no match is found, a
NoSuchDatabaseUser exception is raised.
"""
try:
return self._user_manager.get(name)
except exc.NotFound:
raise exc.NoSuchDatabaseUser("No user by the name '%s' exists." %
name)
def get_database(self, name):
"""
Finds the database in this instance with the specified name, and
returns a CloudDatabaseDatabase object. If no match is found, a
NoSuchDatabase exception is raised.
"""
try:
return [db for db in self.list_databases()
if db.name == name][0]
except IndexError:
raise exc.NoSuchDatabase("No database by the name '%s' exists." %
name)
def create_database(self, name, character_set=None, collate=None):
"""
Creates a database with the specified name. If a database with
that name already exists, a BadRequest (400) exception will
be raised.
"""
if character_set is None:
character_set = "utf8"
if collate is None:
collate = "utf8_general_ci"
self._database_manager.create(name=name, character_set=character_set,
collate=collate, return_none=True)
# Since the API doesn't return the info for creating the database
# object, we have to do it manually.
return self._database_manager.find(name=name)
def create_user(self, name, password, database_names, host=None):
"""
Creates a user with the specified name and password, and gives that
user access to the specified database(s).
If a user with that name already exists, a BadRequest (400) exception
will be raised.
"""
if not isinstance(database_names, (list, tuple)):
database_names = [database_names]
# The API only accepts names, not DB objects
database_names = [db if isinstance(db, six.string_types) else db.name
for db in database_names]
self._user_manager.create(name=name, password=password,
database_names=database_names, host=host, return_none=True)
# Since the API doesn't return the info for creating the user object,
# we have to do it manually.
return self._user_manager.find(name=name)
def delete_database(self, name_or_obj):
"""
Deletes the specified database. If no database by that name
exists, no exception will be raised; instead, nothing at all
is done.
"""
name = utils.get_name(name_or_obj)
self._database_manager.delete(name)
def change_user_password(self, user, new_pass):
"""
Changes the password for the user to the supplied value.
Returns None upon success; raises PasswordChangeFailed if the call
does not complete successfully.
"""
return self._user_manager.change_user_password(user, new_pass)
def update_user(self, user, name=None, password=None, host=None):
"""
Allows you to change one or more of the user's username, password, or
host.
"""
return self._user_manager.update(user, name=name, password=password,
host=host)
def list_user_access(self, user):
"""
Returns a list of all database names for which the specified user
has access rights.
"""
return self._user_manager.list_user_access(user)
def grant_user_access(self, user, db_names, strict=True):
"""
Gives access to the databases listed in `db_names` to the user.
"""
return self._user_manager.grant_user_access(user, db_names,
strict=strict)
def revoke_user_access(self, user, db_names, strict=True):
"""
Revokes access to the databases listed in `db_names` for the user.
"""
return self._user_manager.revoke_user_access(user, db_names,
strict=strict)
def delete_user(self, user):
"""
Deletes the specified user. If no user by that name
exists, no exception will be raised; instead, nothing at all
is done.
"""
name = utils.get_name(user)
self._user_manager.delete(name)
def enable_root_user(self):
"""
Enables login from any host for the root user and provides
the user with a generated root password.
"""
uri = "/instances/%s/root" % self.id
resp, body = self.manager.api.method_post(uri)
return body["user"]["password"]
def root_user_status(self):
"""
Returns True or False, depending on whether the root user
for this instance has been enabled.
"""
uri = "/instances/%s/root" % self.id
resp, body = self.manager.api.method_get(uri)
return body["rootEnabled"]
def restart(self):
"""Restarts this instance."""
self.manager.action(self, "restart")
def resize(self, flavor):
"""Set the size of this instance to a different flavor."""
# We need the flavorRef, not the flavor or size.
flavorRef = self.manager.api._get_flavor_ref(flavor)
body = {"flavorRef": flavorRef}
self.manager.action(self, "resize", body=body)
def resize_volume(self, size):
"""Changes the size of the volume for this instance."""
curr_size = self.volume.size
if size <= curr_size:
raise exc.InvalidVolumeResize("The new volume size must be larger "
"than the current volume size of '%s'." % curr_size)
body = {"volume": {"size": size}}
self.manager.action(self, "resize", body=body)
def list_backups(self, limit=20, marker=0):
"""
Returns a paginated list of backups for this instance.
"""
return self.manager._list_backups_for_instance(self, limit=limit,
marker=marker)
def create_backup(self, name, description=None):
"""
Creates a backup of this instance, giving it the specified name along
with an optional description.
"""
return self.manager.create_backup(self, name, description=description)
def _get_flavor(self):
try:
ret = self._flavor
except AttributeError:
ret = self._flavor = CloudDatabaseFlavor(
self.manager.api._flavor_manager, {})
return ret
def _set_flavor(self, flavor):
if isinstance(flavor, dict):
self._flavor = CloudDatabaseFlavor(self.manager.api._flavor_manager,
flavor)
else:
# Must be an instance
self._flavor = flavor
flavor = property(_get_flavor, _set_flavor)
class CloudDatabaseDatabase(BaseResource):
"""
This class represents a database on a CloudDatabaseInstance. It is not
a true cloud entity, but a convenience object for dealing with databases
on instances.
"""
get_details = True
def delete(self):
"""This class doesn't have an 'id', so pass the name."""
self.manager.delete(self.name)
class CloudDatabaseUser(BaseResource):
"""
This class represents a user on a CloudDatabaseInstance. It is not
a true cloud entity, but a convenience object for dealing with users
for instances.
"""
get_details = False
name = None
host = None
def delete(self):
"""This class doesn't have an 'id', so pass the name."""
self.manager.delete(self.name)
def change_password(self, new_pass):
"""
Changes the password for this user to the supplied value.
Returns None upon success; raises PasswordChangeFailed if the call
does not complete successfully.
"""
self.manager.change_user_password(self, new_pass)
def update(self, name=None, password=None, host=None):
"""
Allows you to change one or more of the user's username, password, or
host.
"""
return self.manager.update(self, name=name, password=password,
host=host)
def list_user_access(self):
"""
Returns a list of all database names for which the specified user
has access rights.
"""
return self.manager.list_user_access(self)
def grant_user_access(self, db_names, strict=True):
"""
Gives access to the databases listed in `db_names` to the user.
"""
return self.manager.grant_user_access(self, db_names, strict=strict)
def revoke_user_access(self, db_names, strict=True):
"""
Revokes access to the databases listed in `db_names` for the user.
"""
return self.manager.revoke_user_access(self, db_names, strict=strict)
class CloudDatabaseFlavor(BaseResource):
"""
This class represents the available instance configurations, or 'flavors',
which you use to define the memory and CPU size of your instance. These
objects are read-only.
"""
get_details = True
_non_display = ["links"]
class CloudDatabaseBackup(BaseResource):
"""
This class represents a database backup.
"""
get_details = True
_non_display = ["locationRef"]
class CloudDatabaseClient(BaseClient):
"""
This is the primary class for interacting with Cloud Databases.
"""
name = "Cloud Databases"
def _configure_manager(self):
"""
Creates a manager to handle the instances, and another
to handle flavors.
"""
self._manager = CloudDatabaseManager(self,
resource_class=CloudDatabaseInstance, response_key="instance",
uri_base="instances")
self._flavor_manager = BaseManager(self,
resource_class=CloudDatabaseFlavor, response_key="flavor",
uri_base="flavors")
self._backup_manager = CloudDatabaseBackupManager(self,
resource_class=CloudDatabaseBackup, response_key="backup",
uri_base="backups")
@assure_instance
def list_databases(self, instance, limit=None, marker=None):
"""Returns all databases for the specified instance."""
return instance.list_databases(limit=limit, marker=marker)
@assure_instance
def create_database(self, instance, name, character_set=None,
collate=None):
"""Creates a database with the specified name on the given instance."""
return instance.create_database(name, character_set=character_set,
collate=collate)
@assure_instance
def get_database(self, instance, name):
"""
Finds the database in the given instance with the specified name, and
returns a CloudDatabaseDatabase object. If no match is found, a
NoSuchDatabase exception is raised.
"""
return instance.get_database(name)
@assure_instance
def delete_database(self, instance, name):
"""Deletes the database by name on the given instance."""
return instance.delete_database(name)
@assure_instance
def list_users(self, instance, limit=None, marker=None):
"""Returns all users for the specified instance."""
return instance.list_users(limit=limit, marker=marker)
@assure_instance
def create_user(self, instance, name, password, database_names, host=None):
"""
Creates a user with the specified name and password, and gives that
user access to the specified database(s).
"""
return instance.create_user(name=name, password=password,
database_names=database_names, host=host)
@assure_instance
def get_user(self, instance, name):
"""
Finds the user in the given instance with the specified name, and
returns a CloudDatabaseUser object. If no match is found, a
NoSuchUser exception is raised.
"""
return instance.get_user(name)
@assure_instance
def delete_user(self, instance, name):
"""Deletes the user by name on the given instance."""
return instance.delete_user(name)
@assure_instance
def change_user_password(self, instance, user, new_pass):
"""
Changes the password for the user of the specified instance to the
supplied value.
Returns None upon success; raises PasswordChangeFailed if the call
does not complete successfully.
"""
return instance.change_user_password(user, new_pass)
@assure_instance
def update_user(self, instance, user, name=None, password=None, host=None):
"""
Allows you to change one or more of the user's username, password, or
host.
"""
return instance.update_user(user, name=name, password=password,
host=host)
@assure_instance
def list_user_access(self, instance, user):
"""
Returns a list of all database names for which the specified user
has access rights on the specified instance.
"""
return instance.list_user_access(user)
@assure_instance
def grant_user_access(self, instance, user, db_names, strict=True):
"""
Gives access to the databases listed in `db_names` to the user
on the specified instance.
"""
return instance.grant_user_access(user, db_names, strict=strict)
@assure_instance
def revoke_user_access(self, instance, user, db_names, strict=True):
"""
Revokes access to the databases listed in `db_names` for the user
on the specified instance.
"""
return instance.revoke_user_access(user, db_names, strict=strict)
@assure_instance
def enable_root_user(self, instance):
"""
This enables login from any host for the root user and provides
the user with a generated root password.
"""
return instance.enable_root_user()
@assure_instance
def root_user_status(self, instance):
"""Returns True if the given instance is root-enabled."""
return instance.root_user_status()
@assure_instance
def restart(self, instance):
"""Restarts the instance."""
return instance.restart()
@assure_instance
def resize(self, instance, flavor):
"""Sets the size of the instance to a different flavor."""
return instance.resize(flavor)
def get_limits(self):
"""Not implemented in Cloud Databases."""
raise NotImplementedError("Limits are not available for Cloud Databases")
def list_flavors(self, limit=None, marker=None):
"""Returns a list of all available Flavors."""
return self._flavor_manager.list(limit=limit, marker=marker)
def get_flavor(self, flavor_id):
"""Returns a specific Flavor object by ID."""
return self._flavor_manager.get(flavor_id)
def _get_flavor_ref(self, flavor):
"""
Flavors are odd in that the API expects an href link, not an ID, as with
nearly every other resource. This method takes either a
CloudDatabaseFlavor object, a flavor ID, a RAM size, or a flavor name,
and uses that to determine the appropriate href.
"""
flavor_obj = None
if isinstance(flavor, CloudDatabaseFlavor):
flavor_obj = flavor
elif isinstance(flavor, int):
# They passed an ID or a size
try:
flavor_obj = self.get_flavor(flavor)
except exc.NotFound:
# Must be either a size or bad ID, which will
# be handled below
pass
if flavor_obj is None:
# Try flavor name
flavors = self.list_flavors()
try:
flavor_obj = [flav for flav in flavors
if flav.name == flavor][0]
except IndexError:
# No such name; try matching RAM
try:
flavor_obj = [flav for flav in flavors
if flav.ram == flavor][0]
except IndexError:
raise exc.FlavorNotFound("Could not determine flavor from "
"'%s'." % flavor)
# OK, we have a Flavor object. Get the href
href = [link["href"] for link in flavor_obj.links
if link["rel"] == "self"][0]
return href
def list_backups(self, instance=None, limit=20, marker=0):
"""
Returns a paginated list of backups by default, or just for a particular
instance.
"""
return self._backup_manager.list(instance=instance, limit=limit,
marker=marker)
def get_backup(self, backup):
"""
Returns the CloudDatabaseBackup instance for a given ID.
"""
return self._backup_manager.get(backup)
def delete_backup(self, backup):
"""
Deletes the CloudDatabaseBackup instance for a given ID.
"""
return self._backup_manager.delete(backup)
@assure_instance
def create_backup(self, instance, name, description=None):
"""
Creates a backup of the specified instance, giving it the specified
name along with an optional description.
"""
return instance.create_backup(name, description=description)
def restore_backup(self, backup, name, flavor, volume):
"""
Restores a backup to a new database instance. You must supply a backup
(either the ID or a CloudDatabaseBackup object), a name for the new
instance, as well as a flavor and size (in GB) for the instance.
"""
return self._manager.restore_backup(backup, name, flavor, volume)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7409,
32679,
19635,
12,
3277,
14,
199,
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,
504,
9143,
492,
14018,
199,
199,
646,
3816,
199,
199,
504,
23944,
14,
1258,
492,
3523,
3041,
199,
646,
23944,
14,
3924,
465,
3178,
199,
504,
23944,
14,
2609,
492,
3523,
2988,
199,
504,
23944,
14,
1927,
492,
3523,
4031,
199,
646,
23944,
14,
1208,
465,
3778,
421,
199,
318,
2661,
608,
63,
842,
8,
2324,
67,
304,
272,
768,
13582,
8,
2324,
67,
9,
272,
347,
485,
9130,
8,
277,
12,
1256,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
1228,
8,
842,
12,
8142,
7243,
3244,
304,
288,
327,
9498,
506,
314,
2870,
288,
1256,
275,
291,
423,
2609,
14,
362,
8,
842,
9,
267,
372,
4325,
67,
8,
277,
12,
1256,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
485,
9130,
4388,
199,
533,
8142,
7243,
6464,
8,
785,
304,
272,
1256,
275,
488,
272,
1568,
275,
488,
272,
1202,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1256,
12,
2256,
304,
267,
291,
14,
842,
275,
1256,
267,
367,
790,
12,
1139,
315,
2256,
14,
1744,
837,
288,
5371,
8,
277,
12,
790,
12,
1139,
9,
2378,
347,
15210,
8,
277,
12,
1568,
304,
267,
408,
267,
799,
890,
314,
3301,
370,
314,
2013,
1568,
334,
262,
18553,
680,
267,
408,
267,
291,
14,
842,
14,
8709,
63,
2405,
8,
890,
9,
267,
291,
14,
890,
275,
1568,
2378,
347,
664,
8,
277,
12,
15115,
304,
267,
408,
267,
2104,
7163,
543,
5578,
2073,
2251,
14,
267,
408,
267,
372,
2519,
8,
277,
12,
15115,
9,
4388,
199,
533,
8142,
7243,
2988,
8,
1563,
2988,
304,
272,
408,
272,
961,
1021,
31965,
23506,
543,
8142,
8692,
4454,
14,
272,
408,
272,
347,
664,
8,
277,
12,
1242,
304,
267,
408,
267,
961,
4722,
1233,
365,
5784,
370,
7684,
372,
314,
283,
2405,
7,
267,
2225,
402,
314,
1256,
465,
282,
8142,
7243,
6464,
909,
3140,
402,
267,
282,
3066,
1211,
14,
267,
408,
267,
2073,
275,
1613,
8,
9089,
7243,
2988,
12,
291,
680,
362,
8,
1053,
9,
267,
2073,
14,
2405,
275,
8142,
7243,
6464,
8,
1927,
12,
2073,
14,
2405,
9,
267,
372,
2073,
2378,
347,
485,
981,
63,
2030,
8,
277,
12,
536,
12,
8541,
29,
403,
12,
3301,
29,
403,
12,
16219,
29,
403,
12,
288,
4390,
29,
403,
12,
1015,
29,
403,
12,
730,
29,
403,
304,
267,
408,
267,
8051,
370,
1218,
314,
1211,
1415,
370,
1218,
282,
8142,
8692,
1256,
14,
267,
408,
267,
340,
8541,
365,
488,
26,
288,
8541,
275,
413,
267,
8541,
63,
1121,
275,
291,
14,
1246,
423,
362,
63,
6081,
63,
1121,
8,
6081,
9,
267,
340,
3301,
365,
488,
26,
288,
3301,
275,
413,
267,
340,
16219,
365,
488,
26,
288,
16219,
275,
942,
267,
340,
4390,
365,
488,
26,
288,
4390,
275,
942,
398,
2396,
275,
2420,
842,
582,
469,
355,
298,
354,
582,
536,
12,
355,
298,
6081,
2891,
582,
8541,
63,
1121,
12,
355,
298,
2405,
582,
2420,
890,
582,
3301,
1386,
355,
298,
17439,
582,
16219,
12,
355,
298,
3707,
582,
4390,
12,
355,
3586,
398,
340,
730,
365,
440,
488,
503,
1015,
365,
440,
488,
26,
288,
1415,
275,
334,
466,
12,
1015,
9,
288,
340,
1006,
8,
2427,
304,
355,
2396,
459,
842,
2545,
11450,
418,
275,
2420,
466,
582,
730,
12,
298,
1023,
582,
1015,
93,
288,
587,
26,
355,
746,
3178,
14,
7718,
9089,
7243,
4720,
480,
17768,
316,
282,
12007,
2,
490,
298,
5074,
3865,
314,
12007,
730,
465,
5521,
465,
314,
1015,
2685,
267,
372,
2396,
2378,
347,
1218,
63,
5751,
8,
277,
12,
1256,
12,
536,
12,
1369,
29,
403,
304,
267,
408,
267,
10560,
282,
6902,
402,
314,
2013,
1256,
12,
15131,
652,
314,
2013,
267,
536,
3180,
543,
376,
2716,
1369,
14,
267,
408,
267,
2396,
275,
2420,
5751,
582,
469,
355,
298,
842,
582,
3778,
14,
362,
63,
344,
8,
842,
395,
355,
298,
354,
582,
536,
12,
355,
3586,
267,
340,
1369,
365,
440,
488,
26,
288,
2396,
905,
5751,
6611,
1802,
937,
275,
1369,
267,
5108,
275,
3286,
27376,
2,
267,
3085,
12,
3085,
63,
2030,
275,
291,
14,
1246,
14,
765,
63,
1932,
8,
2302,
12,
2396,
29,
2030,
9,
267,
18137,
275,
291,
14,
1246,
423,
5751,
63,
2609,
267,
372,
8142,
7243,
16559,
8,
7755,
12,
2396,
14,
362,
480,
5751,
2237,
2378,
347,
9066,
63,
5751,
8,
277,
12,
6902,
12,
536,
12,
8541,
12,
3301,
304,
267,
408,
267,
799,
18958,
282,
6902,
370,
282,
892,
3050,
1256,
14,
2047,
1471,
17169,
282,
6902,
267,
334,
22051,
314,
2870,
503,
282,
8142,
7243,
16559,
909,
395,
282,
536,
367,
314,
892,
267,
1256,
12,
465,
5521,
465,
282,
8541,
436,
3301,
1568,
334,
262,
18553,
9,
367,
314,
1256,
14,
267,
408,
267,
8541,
63,
1121,
275,
291,
14,
1246,
423,
362,
63,
6081,
63,
1121,
8,
6081,
9,
267,
2396,
275,
2420,
842,
582,
469,
355,
298,
354,
582,
536,
12,
355,
298,
6081,
2891,
582,
8541,
63,
1121,
12,
355,
298,
2405,
582,
2420,
890,
582,
3301,
1386,
355,
298,
8011,
3428,
582,
2420,
5751,
2891,
582,
3778,
14,
362,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7409,
32679,
19635,
12,
3277,
14,
199,
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,
504,
9143,
492,
14018,
199,
199,
646,
3816,
199,
199,
504,
23944,
14,
1258,
492,
3523,
3041,
199,
646,
23944,
14,
3924,
465,
3178,
199,
504,
23944,
14,
2609,
492,
3523,
2988,
199,
504,
23944,
14,
1927,
492,
3523,
4031,
199,
646,
23944,
14,
1208,
465,
3778,
421,
199,
318,
2661,
608,
63,
842,
8,
2324,
67,
304,
272,
768,
13582,
8,
2324,
67,
9,
272,
347,
485,
9130,
8,
277,
12,
1256,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
1228,
8,
842,
12,
8142,
7243,
3244,
304,
288,
327,
9498,
506,
314,
2870,
288,
1256,
275,
291,
423,
2609,
14,
362,
8,
842,
9,
267,
372,
4325,
67,
8,
277,
12,
1256,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
485,
9130,
4388,
199,
533,
8142,
7243,
6464,
8,
785,
304,
272,
1256,
275,
488,
272,
1568,
275,
488,
272,
1202,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1256,
12,
2256,
304,
267,
291,
14,
842,
275,
1256,
267,
367,
790,
12,
1139,
315,
2256,
14,
1744,
837,
288,
5371,
8,
277,
12,
790,
12,
1139,
9,
2378,
347,
15210,
8,
277,
12,
1568,
304,
267,
408,
267,
799,
890,
314,
3301,
370,
314,
2013,
1568,
334,
262,
18553,
680,
267,
408,
267,
291,
14,
842,
14,
8709,
63,
2405,
8,
890,
9,
267,
291,
14,
890,
275,
1568,
2378,
347,
664,
8,
277,
12,
15115,
304,
267,
408,
267,
2104,
7163,
543,
5578,
2073,
2251,
14,
267,
408,
267,
372,
2519,
8,
277,
12,
15115,
9,
4388,
199,
533,
8142,
7243,
2988,
8,
1563,
2988,
304,
272,
408,
272,
961,
1021,
31965,
23506,
543,
8142,
8692,
4454,
14,
272,
408,
272,
347,
664,
8,
277,
12,
1242,
304,
267,
408,
267,
961,
4722,
1233,
365,
5784,
370,
7684,
372,
314,
283,
2405,
7,
267,
2225,
402,
314,
1256,
465,
282,
8142,
7243,
6464,
909,
3140,
402,
267,
282,
3066,
1211,
14,
267,
408,
267,
2073,
275,
1613,
8,
9089,
7243,
2988,
12,
291,
680,
362,
8,
1053,
9,
267,
2073,
14,
2405,
275,
8142,
7243,
6464,
8,
1927,
12,
2073,
14,
2405,
9,
267,
372,
2073,
2378,
347,
485,
981,
63,
2030,
8,
277,
12,
536,
12,
8541,
29,
403,
12,
3301,
29,
403,
12,
16219,
29,
403,
12,
288,
4390,
29,
403,
12,
1015,
29,
403,
12,
730,
29,
403,
304,
267,
408,
267,
8051,
370,
1218,
314,
1211,
1415,
370,
1218,
282,
8142,
8692,
1256,
14,
267,
408,
267,
340,
8541,
365,
488,
26,
288,
8541,
275,
413,
267,
8541,
63,
1121,
275,
291,
14,
1246,
423,
362,
63,
6081,
63,
1121,
8,
6081,
9,
267,
340,
3301,
365,
488,
26,
288,
3301,
275,
413,
267,
340,
16219,
365,
488,
26,
288,
16219,
275,
942,
267,
340,
4390,
365,
488,
26,
288,
4390,
275,
942,
398,
2396,
275,
2420,
842,
582,
469,
355,
298,
354,
582,
536,
12,
355,
298,
6081,
2891,
582,
8541,
63,
1121,
12,
355,
298,
2405,
582,
2420,
890,
582,
3301,
1386,
355,
298,
17439,
582,
16219,
12,
355,
298,
3707,
582,
4390,
12,
355,
3586,
398,
340,
730,
365,
440,
488,
503,
1015,
365,
440,
488,
26,
288,
1415,
275,
334,
466,
12,
1015,
9,
288,
340,
1006,
8,
2427,
304,
355,
2396,
459,
842,
2545,
11450,
418,
275,
2420,
466,
582,
730,
12,
298,
1023,
582,
1015,
93,
288,
587,
26,
355,
746,
3178,
14,
7718,
9089,
7243,
4720,
480,
17768,
316,
282,
12007,
2,
490,
298,
5074,
3865,
314,
12007,
730,
465,
5521,
465,
314,
1015,
2685,
267,
372,
2396,
2378,
347,
1218,
63,
5751,
8,
277,
12,
1256,
12,
536,
12,
1369,
29,
403,
304,
267,
408,
267,
10560,
282,
6902,
402,
314,
2013,
1256,
12,
15131,
652,
314,
2013,
267,
536,
3180,
543,
376,
2716,
1369,
14,
267,
408,
267,
2396,
275,
2420,
5751,
582,
469,
355,
298,
842,
582,
3778,
14,
362,
63,
344,
8,
842,
395,
355,
298,
354,
582,
536,
12,
355,
3586,
267,
340,
1369,
365,
440,
488,
26,
288,
2396,
905,
5751,
6611,
1802,
937,
275,
1369,
267,
5108,
275,
3286,
27376,
2,
267,
3085,
12,
3085,
63,
2030,
275,
291,
14,
1246,
14,
765,
63,
1932,
8,
2302,
12,
2396,
29,
2030,
9,
267,
18137,
275,
291,
14,
1246,
423,
5751,
63,
2609,
267,
372,
8142,
7243,
16559,
8,
7755,
12,
2396,
14,
362,
480,
5751,
2237,
2378,
347,
9066,
63,
5751,
8,
277,
12,
6902,
12,
536,
12,
8541,
12,
3301,
304,
267,
408,
267,
799,
18958,
282,
6902,
370,
282,
892,
3050,
1256,
14,
2047,
1471,
17169,
282,
6902,
267,
334,
22051,
314,
2870,
503,
282,
8142,
7243,
16559,
909,
395,
282,
536,
367,
314,
892,
267,
1256,
12,
465,
5521,
465,
282,
8541,
436,
3301,
1568,
334,
262,
18553,
9,
367,
314,
1256,
14,
267,
408,
267,
8541,
63,
1121,
275,
291,
14,
1246,
423,
362,
63,
6081,
63,
1121,
8,
6081,
9,
267,
2396,
275,
2420,
842,
582,
469,
355,
298,
354,
582,
536,
12,
355,
298,
6081,
2891,
582,
8541,
63,
1121,
12,
355,
298,
2405,
582,
2420,
890,
582,
3301,
1386,
355,
298,
8011,
3428,
582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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
erdc/proteus
|
proteus/tests/cylinder2D/ibm_method/cylinder_so.py
|
1
|
3701
|
from __future__ import absolute_import
import proteus.default_so
from importlib import reload
reload(proteus.default_so)
from proteus.default_so import *
try:
from . import cylinder
except:
import cylinder
reload(cylinder)
from proteus.SplitOperator import Sequential_FixedStep_Simple, defaultSystem
if cylinder.sedimentDynamics:
pnList = [("vos_p", "vos_n"),#0
("vof_p", "vof_n"),#1
("ls_p", "ls_n"),#2
("redist_p", "redist_n"),#3
("ls_consrv_p", "ls_consrv_n"),#4
("threep_navier_stokes_sed_p", "threep_navier_stokes_sed_n"),#5
("twp_navier_stokes_p", "twp_navier_stokes_n"),#6
("pressureincrement_p", "pressureincrement_n"),#7
("pressure_p", "pressure_n"),#8
("pressureInitial_p", "pressureInitial_n")]#9
cylinder.VOS_model=0
cylinder.VOF_model=1
cylinder.LS_model=2
cylinder.RD_model=3
cylinder.MCORR_model=4
cylinder.SED_model=5
cylinder.V_model=6
cylinder.PINC_model=7
cylinder.PRESSURE_model=8
cylinder.PINIT_model=9
else:
# pnList = [("vof_p", "vof_n"),#0
# ("ls_p", "ls_n"),#1
# ("redist_p", "redist_n"),#2
# ("ls_consrv_p", "ls_consrv_n"),#3
# ("twp_navier_stokes_p", "twp_navier_stokes_n"),#4
# ("pressureincrement_p", "pressureincrement_n"),#5
# ("pressure_p", "pressure_n"),#6
# ("pressureInitial_p", "pressureInitial_n")]#7
# cylinder.VOS_model=None
# cylinder.SED_model=None
# cylinder.VOF_model=0
# cylinder.LS_model=1
# cylinder.RD_model=2
# cylinder.MCORR_model=3
# cylinder.V_model=4
# cylinder.PINC_model=5
# cylinder.PRESSURE_model=6
# cylinder.PINIT_model=7
pnList = [("twp_navier_stokes_p", "twp_navier_stokes_n"),#0
("pressureincrement_p", "pressureincrement_n"),#1
("pressure_p", "pressure_n"),#2
("pressureInitial_p", "pressureInitial_n")]#3
cylinder.VOF_model=None
cylinder.VOS_model=None
cylinder.SED_model=None
cylinder.V_model=0
cylinder.PINC_model=1
cylinder.PRESSURE_model=2
cylinder.PINIT_model=3
if cylinder.useRANS > 0:
pnList.append(("kappa_p",
"kappa_n"))
pnList.append(("dissipation_p",
"dissipation_n"))
name = "cylinder"
soname=name
#modelSpinUpList = [cylinder.VOF_model, cylinder.LS_model, cylinder.V_model, cylinder.PINIT_model]
modelSpinUpList = [cylinder.PINIT_model]
# class Sequential_MinAdaptiveModelStepPS(Sequential_MinAdaptiveModelStep):
# def __init__(self,modelList,system=defaultSystem,stepExact=True):
# Sequential_MinAdaptiveModelStep.__init__(self,modelList,system,stepExact)
# self.modelList = modelList[:len(pnList)-1]
class Sequential_MinAdaptiveModelStepPS(Sequential_FixedStep):
def __init__(self,modelList,system=defaultSystem,stepExact=True):
Sequential_FixedStep.__init__(self,modelList,system,stepExact)
self.modelList = modelList[:len(pnList)-1]
dt_system_fixed = cylinder.dt_fixed
systemStepControllerType = Sequential_MinAdaptiveModelStepPS
# systemStepControllerType = Sequential_FixedStep #Sequential_FixedStep_Simple # uses time steps in so.tnList
# dt_system_fixed = 0.01;
systemStepExact=False
needEBQ_GLOBAL = False
needEBQ = False
# tnList = [0.0,cylinder.dt_init]+[i*cylinder.dt_fixed for i in range(1,cylinder.nDTout+1)]
tnList = cylinder.tnList
info = open("TimeList.txt","w")
#archiveFlag = ArchiveFlags.EVERY_SEQUENCE_STEP
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
557,
266,
527,
14,
885,
63,
1152,
199,
504,
14802,
492,
13101,
199,
9233,
8,
496,
266,
527,
14,
885,
63,
1152,
9,
199,
504,
557,
266,
527,
14,
885,
63,
1152,
492,
627,
199,
893,
26,
272,
687,
1275,
492,
6325,
24447,
199,
2590,
26,
272,
492,
6325,
24447,
199,
9233,
8,
1480,
24447,
9,
199,
199,
504,
557,
266,
527,
14,
8862,
7961,
492,
3240,
9092,
63,
9515,
7801,
63,
3184,
12,
849,
3989,
199,
199,
692,
6325,
24447,
14,
261,
328,
434,
36,
4019,
2932,
26,
272,
13631,
1296,
275,
10003,
86,
736,
63,
80,
401,
5185,
298,
86,
736,
63,
78,
1288,
3,
16,
1598,
1689,
86,
1618,
63,
80,
401,
5185,
298,
86,
1618,
63,
78,
1288,
3,
17,
1598,
1689,
478,
63,
80,
401,
4483,
298,
478,
63,
78,
1288,
3,
18,
1598,
1689,
264,
2686,
63,
80,
401,
3322,
298,
264,
2686,
63,
78,
1288,
3,
19,
1598,
1689,
478,
63,
388,
15165,
63,
80,
401,
260,
298,
478,
63,
388,
15165,
63,
78,
1288,
3,
20,
1598,
1689,
10480,
80,
63,
15595,
281,
63,
270,
22652,
63,
939,
63,
80,
401,
298,
10480,
80,
63,
15595,
281,
63,
270,
22652,
63,
939,
63,
78,
1288,
3,
21,
1598,
1689,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
80,
401,
298,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
78,
1288,
3,
22,
1598,
1689,
21999,
9728,
63,
80,
401,
298,
21999,
9728,
63,
78,
1288,
3,
23,
1598,
1689,
21999,
63,
80,
401,
298,
21999,
63,
78,
1288,
3,
24,
1598,
1689,
21999,
5733,
63,
80,
401,
298,
21999,
5733,
63,
78,
11323,
3,
25,
272,
6325,
24447,
14,
54,
3100,
63,
1238,
29,
16,
272,
6325,
24447,
14,
54,
3359,
63,
1238,
29,
17,
272,
6325,
24447,
14,
5296,
63,
1238,
29,
18,
272,
6325,
24447,
14,
15543,
63,
1238,
29,
19,
272,
6325,
24447,
14,
7608,
726,
50,
63,
1238,
29,
20,
272,
6325,
24447,
14,
10934,
63,
1238,
29,
21,
272,
6325,
24447,
14,
54,
63,
1238,
29,
22,
272,
6325,
24447,
14,
48,
25205,
63,
1238,
29,
23,
272,
6325,
24447,
14,
5786,
3942,
63,
1238,
29,
24,
272,
6325,
24447,
14,
48,
8727,
63,
1238,
29,
25,
199,
2836,
26,
199,
3,
258,
13631,
1296,
275,
10003,
86,
1618,
63,
80,
401,
5185,
298,
86,
1618,
63,
78,
1288,
3,
16,
199,
3,
5185,
1689,
478,
63,
80,
401,
4483,
298,
478,
63,
78,
1288,
3,
17,
199,
3,
5185,
1689,
264,
2686,
63,
80,
401,
3322,
298,
264,
2686,
63,
78,
1288,
3,
18,
199,
3,
5185,
1689,
478,
63,
388,
15165,
63,
80,
401,
260,
298,
478,
63,
388,
15165,
63,
78,
1288,
3,
19,
199,
3,
5185,
1689,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
80,
401,
298,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
78,
1288,
3,
20,
199,
3,
5185,
1689,
21999,
9728,
63,
80,
401,
298,
21999,
9728,
63,
78,
1288,
3,
21,
199,
3,
5185,
1689,
21999,
63,
80,
401,
298,
21999,
63,
78,
1288,
3,
22,
199,
3,
5185,
1689,
21999,
5733,
63,
80,
401,
298,
21999,
5733,
63,
78,
11323,
3,
23,
199,
3,
258,
6325,
24447,
14,
54,
3100,
63,
1238,
29,
403,
199,
3,
258,
6325,
24447,
14,
10934,
63,
1238,
29,
403,
199,
3,
258,
6325,
24447,
14,
54,
3359,
63,
1238,
29,
16,
199,
3,
258,
6325,
24447,
14,
5296,
63,
1238,
29,
17,
199,
3,
258,
6325,
24447,
14,
15543,
63,
1238,
29,
18,
199,
3,
258,
6325,
24447,
14,
7608,
726,
50,
63,
1238,
29,
19,
199,
3,
258,
6325,
24447,
14,
54,
63,
1238,
29,
20,
199,
3,
258,
6325,
24447,
14,
48,
25205,
63,
1238,
29,
21,
199,
3,
258,
6325,
24447,
14,
5786,
3942,
63,
1238,
29,
22,
199,
3,
258,
6325,
24447,
14,
48,
8727,
63,
1238,
29,
23,
2286,
13631,
1296,
275,
10003,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
80,
401,
298,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
78,
1288,
3,
16,
881,
1689,
21999,
9728,
63,
80,
401,
298,
21999,
9728,
63,
78,
1288,
3,
17,
881,
1689,
21999,
63,
80,
401,
298,
21999,
63,
78,
1288,
3,
18,
881,
1689,
21999,
5733,
63,
80,
401,
298,
21999,
5733,
63,
78,
11323,
3,
19,
20950,
6325,
24447,
14,
54,
3359,
63,
1238,
29,
403,
272,
6325,
24447,
14,
54,
3100,
63,
1238,
29,
403,
272,
6325,
24447,
14,
10934,
63,
1238,
29,
403,
272,
6325,
24447,
14,
54,
63,
1238,
29,
16,
272,
6325,
24447,
14,
48,
25205,
63,
1238,
29,
17,
272,
6325,
24447,
14,
5786,
3942,
63,
1238,
29,
18,
272,
6325,
24447,
14,
48,
8727,
63,
1238,
29,
19,
199,
199,
692,
6325,
24447,
14,
1180,
50,
5622,
690,
378,
26,
272,
13631,
1296,
14,
740,
9313,
31918,
63,
80,
401,
673,
298,
31918,
63,
78,
2237,
272,
13631,
1296,
14,
740,
9313,
2297,
338,
387,
296,
63,
80,
401,
673,
298,
2297,
338,
387,
296,
63,
78,
2237,
199,
354,
275,
298,
1480,
24447,
2,
199,
834,
313,
29,
354,
199,
3,
1238,
15519,
1721,
1296,
275,
359,
1480,
24447,
14,
54,
3359,
63,
1238,
12,
6325,
24447,
14,
5296,
63,
1238,
12,
6325,
24447,
14,
54,
63,
1238,
12,
6325,
24447,
14,
48,
8727,
63,
1238,
61,
199,
1238,
15519,
1721,
1296,
275,
359,
1480,
24447,
14,
48,
8727,
63,
1238,
61,
199,
199,
3,
1021,
3240,
9092,
63,
4649,
2767,
22430,
1685,
7801,
5067,
8,
18509,
63,
4649,
2767,
22430,
1685,
7801,
304,
199,
3,
258,
347,
636,
826,
721,
277,
12,
1238,
1296,
12,
2253,
29,
885,
3989,
12,
2926,
29751,
29,
549,
304,
199,
3,
260,
3240,
9092,
63,
4649,
2767,
22430,
1685,
7801,
855,
826,
721,
277,
12,
1238,
1296,
12,
2253,
12,
2926,
29751,
9,
199,
3,
260,
291,
14,
1238,
1296,
275,
1402,
1296,
1491,
552,
8,
4812,
1296,
7216,
17,
61,
421,
199,
533,
3240,
9092,
63,
4649,
2767,
22430,
1685,
7801,
5067,
8,
18509,
63,
9515,
7801,
304,
272,
347,
636,
826,
721,
277,
12
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
557,
266,
527,
14,
885,
63,
1152,
199,
504,
14802,
492,
13101,
199,
9233,
8,
496,
266,
527,
14,
885,
63,
1152,
9,
199,
504,
557,
266,
527,
14,
885,
63,
1152,
492,
627,
199,
893,
26,
272,
687,
1275,
492,
6325,
24447,
199,
2590,
26,
272,
492,
6325,
24447,
199,
9233,
8,
1480,
24447,
9,
199,
199,
504,
557,
266,
527,
14,
8862,
7961,
492,
3240,
9092,
63,
9515,
7801,
63,
3184,
12,
849,
3989,
199,
199,
692,
6325,
24447,
14,
261,
328,
434,
36,
4019,
2932,
26,
272,
13631,
1296,
275,
10003,
86,
736,
63,
80,
401,
5185,
298,
86,
736,
63,
78,
1288,
3,
16,
1598,
1689,
86,
1618,
63,
80,
401,
5185,
298,
86,
1618,
63,
78,
1288,
3,
17,
1598,
1689,
478,
63,
80,
401,
4483,
298,
478,
63,
78,
1288,
3,
18,
1598,
1689,
264,
2686,
63,
80,
401,
3322,
298,
264,
2686,
63,
78,
1288,
3,
19,
1598,
1689,
478,
63,
388,
15165,
63,
80,
401,
260,
298,
478,
63,
388,
15165,
63,
78,
1288,
3,
20,
1598,
1689,
10480,
80,
63,
15595,
281,
63,
270,
22652,
63,
939,
63,
80,
401,
298,
10480,
80,
63,
15595,
281,
63,
270,
22652,
63,
939,
63,
78,
1288,
3,
21,
1598,
1689,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
80,
401,
298,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
78,
1288,
3,
22,
1598,
1689,
21999,
9728,
63,
80,
401,
298,
21999,
9728,
63,
78,
1288,
3,
23,
1598,
1689,
21999,
63,
80,
401,
298,
21999,
63,
78,
1288,
3,
24,
1598,
1689,
21999,
5733,
63,
80,
401,
298,
21999,
5733,
63,
78,
11323,
3,
25,
272,
6325,
24447,
14,
54,
3100,
63,
1238,
29,
16,
272,
6325,
24447,
14,
54,
3359,
63,
1238,
29,
17,
272,
6325,
24447,
14,
5296,
63,
1238,
29,
18,
272,
6325,
24447,
14,
15543,
63,
1238,
29,
19,
272,
6325,
24447,
14,
7608,
726,
50,
63,
1238,
29,
20,
272,
6325,
24447,
14,
10934,
63,
1238,
29,
21,
272,
6325,
24447,
14,
54,
63,
1238,
29,
22,
272,
6325,
24447,
14,
48,
25205,
63,
1238,
29,
23,
272,
6325,
24447,
14,
5786,
3942,
63,
1238,
29,
24,
272,
6325,
24447,
14,
48,
8727,
63,
1238,
29,
25,
199,
2836,
26,
199,
3,
258,
13631,
1296,
275,
10003,
86,
1618,
63,
80,
401,
5185,
298,
86,
1618,
63,
78,
1288,
3,
16,
199,
3,
5185,
1689,
478,
63,
80,
401,
4483,
298,
478,
63,
78,
1288,
3,
17,
199,
3,
5185,
1689,
264,
2686,
63,
80,
401,
3322,
298,
264,
2686,
63,
78,
1288,
3,
18,
199,
3,
5185,
1689,
478,
63,
388,
15165,
63,
80,
401,
260,
298,
478,
63,
388,
15165,
63,
78,
1288,
3,
19,
199,
3,
5185,
1689,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
80,
401,
298,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
78,
1288,
3,
20,
199,
3,
5185,
1689,
21999,
9728,
63,
80,
401,
298,
21999,
9728,
63,
78,
1288,
3,
21,
199,
3,
5185,
1689,
21999,
63,
80,
401,
298,
21999,
63,
78,
1288,
3,
22,
199,
3,
5185,
1689,
21999,
5733,
63,
80,
401,
298,
21999,
5733,
63,
78,
11323,
3,
23,
199,
3,
258,
6325,
24447,
14,
54,
3100,
63,
1238,
29,
403,
199,
3,
258,
6325,
24447,
14,
10934,
63,
1238,
29,
403,
199,
3,
258,
6325,
24447,
14,
54,
3359,
63,
1238,
29,
16,
199,
3,
258,
6325,
24447,
14,
5296,
63,
1238,
29,
17,
199,
3,
258,
6325,
24447,
14,
15543,
63,
1238,
29,
18,
199,
3,
258,
6325,
24447,
14,
7608,
726,
50,
63,
1238,
29,
19,
199,
3,
258,
6325,
24447,
14,
54,
63,
1238,
29,
20,
199,
3,
258,
6325,
24447,
14,
48,
25205,
63,
1238,
29,
21,
199,
3,
258,
6325,
24447,
14,
5786,
3942,
63,
1238,
29,
22,
199,
3,
258,
6325,
24447,
14,
48,
8727,
63,
1238,
29,
23,
2286,
13631,
1296,
275,
10003,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
80,
401,
298,
8122,
80,
63,
15595,
281,
63,
270,
22652,
63,
78,
1288,
3,
16,
881,
1689,
21999,
9728,
63,
80,
401,
298,
21999,
9728,
63,
78,
1288,
3,
17,
881,
1689,
21999,
63,
80,
401,
298,
21999,
63,
78,
1288,
3,
18,
881,
1689,
21999,
5733,
63,
80,
401,
298,
21999,
5733,
63,
78,
11323,
3,
19,
20950,
6325,
24447,
14,
54,
3359,
63,
1238,
29,
403,
272,
6325,
24447,
14,
54,
3100,
63,
1238,
29,
403,
272,
6325,
24447,
14,
10934,
63,
1238,
29,
403,
272,
6325,
24447,
14,
54,
63,
1238,
29,
16,
272,
6325,
24447,
14,
48,
25205,
63,
1238,
29,
17,
272,
6325,
24447,
14,
5786,
3942,
63,
1238,
29,
18,
272,
6325,
24447,
14,
48,
8727,
63,
1238,
29,
19,
199,
199,
692,
6325,
24447,
14,
1180,
50,
5622,
690,
378,
26,
272,
13631,
1296,
14,
740,
9313,
31918,
63,
80,
401,
673,
298,
31918,
63,
78,
2237,
272,
13631,
1296,
14,
740,
9313,
2297,
338,
387,
296,
63,
80,
401,
673,
298,
2297,
338,
387,
296,
63,
78,
2237,
199,
354,
275,
298,
1480,
24447,
2,
199,
834,
313,
29,
354,
199,
3,
1238,
15519,
1721,
1296,
275,
359,
1480,
24447,
14,
54,
3359,
63,
1238,
12,
6325,
24447,
14,
5296,
63,
1238,
12,
6325,
24447,
14,
54,
63,
1238,
12,
6325,
24447,
14,
48,
8727,
63,
1238,
61,
199,
1238,
15519,
1721,
1296,
275,
359,
1480,
24447,
14,
48,
8727,
63,
1238,
61,
199,
199,
3,
1021,
3240,
9092,
63,
4649,
2767,
22430,
1685,
7801,
5067,
8,
18509,
63,
4649,
2767,
22430,
1685,
7801,
304,
199,
3,
258,
347,
636,
826,
721,
277,
12,
1238,
1296,
12,
2253,
29,
885,
3989,
12,
2926,
29751,
29,
549,
304,
199,
3,
260,
3240,
9092,
63,
4649,
2767,
22430,
1685,
7801,
855,
826,
721,
277,
12,
1238,
1296,
12,
2253,
12,
2926,
29751,
9,
199,
3,
260,
291,
14,
1238,
1296,
275,
1402,
1296,
1491,
552,
8,
4812,
1296,
7216,
17,
61,
421,
199,
533,
3240,
9092,
63,
4649,
2767,
22430,
1685,
7801,
5067,
8,
18509,
63,
9515,
7801,
304,
272,
347,
636,
826,
721,
277,
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,
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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
] |
hhLeo/ucore_lab
|
related_info/ostep/ostep13-vsfs.py
|
54
|
17070
|
#! /usr/bin/env python
import random
from optparse import OptionParser
DEBUG = False
def dprint(str):
if DEBUG:
print str
printOps = True
printState = True
printFinal = True
class bitmap:
def __init__(self, size):
self.size = size
self.bmap = []
for num in range(size):
self.bmap.append(0)
def alloc(self):
for num in range(len(self.bmap)):
if self.bmap[num] == 0:
self.bmap[num] = 1
return num
return -1
def free(self, num):
assert(self.bmap[num] == 1)
self.bmap[num] = 0
def markAllocated(self, num):
assert(self.bmap[num] == 0)
self.bmap[num] = 1
def dump(self):
s = ''
for i in range(len(self.bmap)):
s += str(self.bmap[i])
return s
class block:
def __init__(self, ftype):
assert(ftype == 'd' or ftype == 'f' or ftype == 'free')
self.ftype = ftype
# only for directories, properly a subclass but who cares
self.dirUsed = 0
self.maxUsed = 32
self.dirList = []
self.data = ''
def dump(self):
if self.ftype == 'free':
return '[]'
elif self.ftype == 'd':
rc = ''
for d in self.dirList:
# d is of the form ('name', inum)
short = '(%s,%s)' % (d[0], d[1])
if rc == '':
rc = short
else:
rc += ' ' + short
return '['+rc+']'
# return '%s' % self.dirList
else:
return '[%s]' % self.data
def setType(self, ftype):
assert(self.ftype == 'free')
self.ftype = ftype
def addData(self, data):
assert(self.ftype == 'f')
self.data = data
def getNumEntries(self):
assert(self.ftype == 'd')
return self.dirUsed
def getFreeEntries(self):
assert(self.ftype == 'd')
return self.maxUsed - self.dirUsed
def getEntry(self, num):
assert(self.ftype == 'd')
assert(num < self.dirUsed)
return self.dirList[num]
def addDirEntry(self, name, inum):
assert(self.ftype == 'd')
self.dirList.append((name, inum))
self.dirUsed += 1
assert(self.dirUsed <= self.maxUsed)
def delDirEntry(self, name):
assert(self.ftype == 'd')
tname = name.split('/')
dname = tname[len(tname) - 1]
for i in range(len(self.dirList)):
if self.dirList[i][0] == dname:
self.dirList.pop(i)
self.dirUsed -= 1
return
assert(1 == 0)
def dirEntryExists(self, name):
assert(self.ftype == 'd')
for d in self.dirList:
if name == d[0]:
return True
return False
def free(self):
assert(self.ftype != 'free')
if self.ftype == 'd':
# check for only dot, dotdot here
assert(self.dirUsed == 2)
self.dirUsed = 0
self.data = ''
self.ftype = 'free'
class inode:
def __init__(self, ftype='free', addr=-1, refCnt=1):
self.setAll(ftype, addr, refCnt)
def setAll(self, ftype, addr, refCnt):
assert(ftype == 'd' or ftype == 'f' or ftype == 'free')
self.ftype = ftype
self.addr = addr
self.refCnt = refCnt
def incRefCnt(self):
self.refCnt += 1
def decRefCnt(self):
self.refCnt -= 1
def getRefCnt(self):
return self.refCnt
def setType(self, ftype):
assert(ftype == 'd' or ftype == 'f' or ftype == 'free')
self.ftype = ftype
def setAddr(self, block):
self.addr = block
def getSize(self):
if self.addr == -1:
return 0
else:
return 1
def getAddr(self):
return self.addr
def getType(self):
return self.ftype
def free(self):
self.ftype = 'free'
self.addr = -1
class fs:
def __init__(self, numInodes, numData):
self.numInodes = numInodes
self.numData = numData
self.ibitmap = bitmap(self.numInodes)
self.inodes = []
for i in range(self.numInodes):
self.inodes.append(inode())
self.dbitmap = bitmap(self.numData)
self.data = []
for i in range(self.numData):
self.data.append(block('free'))
# root inode
self.ROOT = 0
# create root directory
self.ibitmap.markAllocated(self.ROOT)
self.inodes[self.ROOT].setAll('d', 0, 2)
self.dbitmap.markAllocated(self.ROOT)
self.data[0].setType('d')
self.data[0].addDirEntry('.', self.ROOT)
self.data[0].addDirEntry('..', self.ROOT)
# these is just for the fake workload generator
self.files = []
self.dirs = ['/']
self.nameToInum = {'/':self.ROOT}
def dump(self):
print 'inode bitmap ', self.ibitmap.dump()
print 'inodes ',
for i in range(0,self.numInodes):
ftype = self.inodes[i].getType()
if ftype == 'free':
print '[]',
else:
print '[%s a:%s r:%d]' % (ftype, self.inodes[i].getAddr(), self.inodes[i].getRefCnt()),
print ''
print 'data bitmap ', self.dbitmap.dump()
print 'data ',
for i in range(self.numData):
print self.data[i].dump(),
print ''
def makeName(self):
p = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
return p[int(random.random() * len(p))]
p = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 's', 't', 'v', 'w', 'x', 'y', 'z']
f = p[int(random.random() * len(p))]
p = ['a', 'e', 'i', 'o', 'u']
s = p[int(random.random() * len(p))]
p = ['b', 'c', 'd', 'f', 'g', 'j', 'k', 'l', 'm', 'n', 'p', 's', 't', 'v', 'w', 'x', 'y', 'z']
l = p[int(random.random() * len(p))]
return '%c%c%c' % (f, s, l)
def inodeAlloc(self):
return self.ibitmap.alloc()
def inodeFree(self, inum):
self.ibitmap.free(inum)
self.inodes[inum].free()
def dataAlloc(self):
return self.dbitmap.alloc()
def dataFree(self, bnum):
self.dbitmap.free(bnum)
self.data[bnum].free()
def getParent(self, name):
tmp = name.split('/')
if len(tmp) == 2:
return '/'
pname = ''
for i in range(1, len(tmp)-1):
pname = pname + '/' + tmp[i]
return pname
def deleteFile(self, tfile):
if printOps:
print 'unlink("%s");' % tfile
inum = self.nameToInum[tfile]
if self.inodes[inum].getRefCnt() == 1:
# free data blocks first
dblock = self.inodes[inum].getAddr()
if dblock != -1:
self.dataFree(dblock)
# then free inode
self.inodeFree(inum)
else:
self.inodes[inum].decRefCnt()
# remove from parent directory
parent = self.getParent(tfile)
# print '--> delete from parent', parent
pinum = self.nameToInum[parent]
# print '--> delete from parent inum', pinum
pblock = self.inodes[pinum].getAddr()
# FIXED BUG: DECREASE PARENT INODE REF COUNT! (thanks to Srinivasan Thirunarayanan)
self.inodes[pinum].decRefCnt()
# print '--> delete from parent addr', pblock
self.data[pblock].delDirEntry(tfile)
# finally, remove from files list
self.files.remove(tfile)
return 0
def createLink(self, target, newfile, parent):
# find info about parent
parentInum = self.nameToInum[parent]
# is there room in the parent directory?
pblock = self.inodes[parentInum].getAddr()
if self.data[pblock].getFreeEntries() <= 0:
dprint('*** createLink failed: no room in parent directory ***')
return -1
# print 'is %s in directory %d' % (newfile, pblock)
if self.data[pblock].dirEntryExists(newfile):
dprint('*** createLink failed: not a unique name ***')
return -1
# now, find inumber of target
tinum = self.nameToInum[target]
self.inodes[tinum].incRefCnt()
# inc parent ref count
self.inodes[parentInum].incRefCnt()
# now add to directory
tmp = newfile.split('/')
ename = tmp[len(tmp)-1]
self.data[pblock].addDirEntry(ename, tinum)
return tinum
def createFile(self, parent, newfile, ftype):
# find info about parent
parentInum = self.nameToInum[parent]
# is there room in the parent directory?
pblock = self.inodes[parentInum].getAddr()
if self.data[pblock].getFreeEntries() <= 0:
dprint('*** createFile failed: no room in parent directory ***')
return -1
# have to make sure file name is unique
block = self.inodes[parentInum].getAddr()
# print 'is %s in directory %d' % (newfile, block)
if self.data[block].dirEntryExists(newfile):
dprint('*** createFile failed: not a unique name ***')
return -1
# find free inode
inum = self.inodeAlloc()
if inum == -1:
dprint('*** createFile failed: no inodes left ***')
return -1
# if a directory, have to allocate directory block for basic (., ..) info
fblock = -1
if ftype == 'd':
refCnt = 2
fblock = self.dataAlloc()
if fblock == -1:
dprint('*** createFile failed: no data blocks left ***')
self.inodeFree(inum)
return -1
else:
self.data[fblock].setType('d')
self.data[fblock].addDirEntry('.', inum)
self.data[fblock].addDirEntry('..', parentInum)
else:
refCnt = 1
# now ok to init inode properly
self.inodes[inum].setAll(ftype, fblock, refCnt)
# inc parent ref count
self.inodes[parentInum].incRefCnt()
# and add to directory of parent
self.data[pblock].addDirEntry(newfile, inum)
return inum
def writeFile(self, tfile, data):
inum = self.nameToInum[tfile]
curSize = self.inodes[inum].getSize()
dprint('writeFile: inum:%d cursize:%d refcnt:%d' % (inum, curSize, self.inodes[inum].getRefCnt()))
if curSize == 1:
dprint('*** writeFile failed: file is full ***')
return -1
fblock = self.dataAlloc()
if fblock == -1:
dprint('*** writeFile failed: no data blocks left ***')
return -1
else:
self.data[fblock].setType('f')
self.data[fblock].addData(data)
self.inodes[inum].setAddr(fblock)
if printOps:
print 'fd=open("%s", O_WRONLY|O_APPEND); write(fd, buf, BLOCKSIZE); close(fd);' % tfile
return 0
def doDelete(self):
dprint('doDelete')
if len(self.files) == 0:
return -1
dfile = self.files[int(random.random() * len(self.files))]
dprint('try delete(%s)' % dfile)
return self.deleteFile(dfile)
def doLink(self):
dprint('doLink')
if len(self.files) == 0:
return -1
parent = self.dirs[int(random.random() * len(self.dirs))]
nfile = self.makeName()
# pick random target
target = self.files[int(random.random() * len(self.files))]
# get full name of newfile
if parent == '/':
fullName = parent + nfile
else:
fullName = parent + '/' + nfile
dprint('try createLink(%s %s %s)' % (target, nfile, parent))
inum = self.createLink(target, nfile, parent)
if inum >= 0:
self.files.append(fullName)
self.nameToInum[fullName] = inum
if printOps:
print 'link("%s", "%s");' % (target, fullName)
return 0
return -1
def doCreate(self, ftype):
dprint('doCreate')
parent = self.dirs[int(random.random() * len(self.dirs))]
nfile = self.makeName()
if ftype == 'd':
tlist = self.dirs
else:
tlist = self.files
if parent == '/':
fullName = parent + nfile
else:
fullName = parent + '/' + nfile
dprint('try createFile(%s %s %s)' % (parent, nfile, ftype))
inum = self.createFile(parent, nfile, ftype)
if inum >= 0:
tlist.append(fullName)
self.nameToInum[fullName] = inum
if parent == '/':
parent = ''
if ftype == 'd':
if printOps:
print 'mkdir("%s/%s");' % (parent, nfile)
else:
if printOps:
print 'creat("%s/%s");' % (parent, nfile)
return 0
return -1
def doAppend(self):
dprint('doAppend')
if len(self.files) == 0:
return -1
afile = self.files[int(random.random() * len(self.files))]
dprint('try writeFile(%s)' % afile)
data = chr(ord('a') + int(random.random() * 26))
rc = self.writeFile(afile, data)
return rc
def run(self, numRequests):
self.percentMkdir = 0.40
self.percentWrite = 0.40
self.percentDelete = 0.20
self.numRequests = 20
print 'Initial state'
print ''
self.dump()
print ''
for i in range(numRequests):
if printOps == False:
print 'Which operation took place?'
rc = -1
while rc == -1:
r = random.random()
if r < 0.3:
rc = self.doAppend()
dprint('doAppend rc:%d' % rc)
elif r < 0.5:
rc = self.doDelete()
dprint('doDelete rc:%d' % rc)
elif r < 0.7:
rc = self.doLink()
dprint('doLink rc:%d' % rc)
else:
if random.random() < 0.75:
rc = self.doCreate('f')
dprint('doCreate(f) rc:%d' % rc)
else:
rc = self.doCreate('d')
dprint('doCreate(d) rc:%d' % rc)
if printState == True:
print ''
self.dump()
print ''
else:
print ''
print ' State of file system (inode bitmap, inodes, data bitmap, data)?'
print ''
if printFinal:
print ''
print 'Summary of files, directories::'
print ''
print ' Files: ', self.files
print ' Directories:', self.dirs
print ''
#
# main program
#
parser = OptionParser()
parser.add_option('-s', '--seed', default=0, help='the random seed', action='store', type='int', dest='seed')
parser.add_option('-i', '--numInodes', default=8, help='number of inodes in file system', action='store', type='int', dest='numInodes')
parser.add_option('-d', '--numData', default=8, help='number of data blocks in file system', action='store', type='int', dest='numData')
parser.add_option('-n', '--numRequests', default=10, help='number of requests to simulate', action='store', type='int', dest='numRequests')
parser.add_option('-r', '--reverse', default=False, help='instead of printing state, print ops', action='store_true', dest='reverse')
parser.add_option('-p', '--printFinal', default=False, help='print the final set of files/dirs', action='store_true', dest='printFinal')
parser.add_option('-c', '--compute', default=False, help='compute answers for me', action='store_true', dest='solve')
(options, args) = parser.parse_args()
print 'ARG seed', options.seed
print 'ARG numInodes', options.numInodes
print 'ARG numData', options.numData
print 'ARG numRequests', options.numRequests
print 'ARG reverse', options.reverse
print 'ARG printFinal', options.printFinal
print ''
random.seed(options.seed)
if options.reverse:
printState = False
printOps = True
else:
printState = True
printOps = False
if options.solve:
printOps = True
printState = True
printFinal = options.printFinal
#
# have to generate RANDOM requests to the file system
# that are VALID!
#
f = fs(options.numInodes, options.numData)
#
# ops: mkdir rmdir : create delete : append write
#
f.run(options.numRequests)
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
2196,
199,
504,
8691,
492,
13491,
199,
199,
5287,
275,
756,
199,
199,
318,
366,
1361,
8,
495,
304,
272,
340,
10990,
26,
267,
870,
620,
199,
199,
1361,
16452,
420,
275,
715,
199,
1361,
2223,
259,
275,
715,
199,
1361,
12776,
259,
275,
715,
199,
199,
533,
20810,
26,
272,
347,
636,
826,
721,
277,
12,
1568,
304,
267,
291,
14,
890,
275,
1568,
267,
291,
14,
66,
1130,
275,
942,
267,
367,
1967,
315,
1425,
8,
890,
304,
288,
291,
14,
66,
1130,
14,
740,
8,
16,
9,
339,
347,
29447,
8,
277,
304,
267,
367,
1967,
315,
1425,
8,
552,
8,
277,
14,
66,
1130,
2298,
288,
340,
291,
14,
66,
1130,
59,
1507,
61,
508,
378,
26,
355,
291,
14,
66,
1130,
59,
1507,
61,
275,
413,
355,
372,
1967,
267,
372,
446,
17,
339,
347,
2867,
8,
277,
12,
1967,
304,
267,
702,
8,
277,
14,
66,
1130,
59,
1507,
61,
508,
413,
9,
267,
291,
14,
66,
1130,
59,
1507,
61,
275,
378,
339,
347,
2216,
2439,
13340,
8,
277,
12,
1967,
304,
267,
702,
8,
277,
14,
66,
1130,
59,
1507,
61,
508,
378,
9,
267,
291,
14,
66,
1130,
59,
1507,
61,
275,
413,
339,
347,
5461,
8,
277,
304,
267,
308,
275,
2125,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
66,
1130,
2298,
288,
308,
847,
620,
8,
277,
14,
66,
1130,
59,
73,
566,
267,
372,
308,
199,
199,
533,
1853,
26,
272,
347,
636,
826,
721,
277,
12,
8570,
304,
267,
702,
8,
10386,
508,
283,
68,
7,
503,
8570,
508,
283,
70,
7,
503,
8570,
508,
283,
4624,
358,
267,
291,
14,
10386,
275,
8570,
267,
327,
1454,
367,
6602,
12,
7684,
282,
5516,
1325,
3963,
1704,
470,
267,
291,
14,
694,
9167,
275,
378,
267,
291,
14,
988,
9167,
275,
4337,
267,
291,
14,
694,
1296,
275,
942,
267,
291,
14,
576,
259,
275,
2125,
339,
347,
5461,
8,
277,
304,
267,
340,
291,
14,
10386,
508,
283,
4624,
356,
288,
372,
6730,
6616,
267,
916,
291,
14,
10386,
508,
283,
68,
356,
288,
4819,
275,
2125,
288,
367,
366,
315,
291,
14,
694,
1296,
26,
355,
327,
366,
365,
402,
314,
1824,
661,
354,
297,
315,
453,
9,
355,
3974,
275,
25676,
83,
8719,
83,
3171,
450,
334,
68,
59,
16,
467,
366,
59,
17,
566,
355,
340,
4819,
508,
8061,
490,
4819,
275,
3974,
355,
587,
26,
490,
4819,
847,
283,
283,
435,
3974,
288,
372,
22640,
11,
1195,
11,
418,
7,
288,
327,
372,
1543,
83,
7,
450,
291,
14,
694,
1296,
267,
587,
26,
288,
372,
30423,
83,
6616,
450,
291,
14,
576,
339,
347,
663,
804,
8,
277,
12,
8570,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
4624,
358,
267,
291,
14,
10386,
275,
8570,
339,
347,
1050,
1451,
8,
277,
12,
666,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
70,
358,
267,
291,
14,
576,
275,
666,
339,
347,
664,
5667,
17816,
8,
277,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
372,
291,
14,
694,
9167,
339,
347,
664,
10146,
17816,
8,
277,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
372,
291,
14,
988,
9167,
446,
291,
14,
694,
9167,
339,
347,
664,
3900,
8,
277,
12,
1967,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
702,
8,
1507,
665,
291,
14,
694,
9167,
9,
267,
372,
291,
14,
694,
1296,
59,
1507,
61,
339,
347,
1050,
3567,
3900,
8,
277,
12,
536,
12,
315,
453,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
291,
14,
694,
1296,
14,
740,
1332,
354,
12,
315,
453,
430,
267,
291,
14,
694,
9167,
847,
413,
267,
702,
8,
277,
14,
694,
9167,
2695,
291,
14,
988,
9167,
9,
339,
347,
2150,
3567,
3900,
8,
277,
12,
536,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
307,
354,
275,
536,
14,
1294,
7825,
267,
366,
354,
275,
307,
354,
59,
552,
8,
31383,
9,
446,
413,
61,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
694,
1296,
2298,
288,
340,
291,
14,
694,
1296,
59,
73,
1527,
16,
61,
508,
366,
354,
26,
355,
291,
14,
694,
1296,
14,
1935,
8,
73,
9,
355,
291,
14,
694,
9167,
4862,
413,
355,
372,
267,
702,
8,
17,
508,
378,
9,
339,
347,
2935,
3900,
7965,
8,
277,
12,
536,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
367,
366,
315,
291,
14,
694,
1296,
26,
288,
340,
536,
508,
366,
59,
16,
2189,
355,
372,
715,
267,
372,
756,
339,
347,
2867,
8,
277,
304,
267,
702,
8,
277,
14,
10386,
1137,
283,
4624,
358,
267,
340,
291,
14,
10386,
508,
283,
68,
356,
288,
327,
1104,
367,
1454,
6308,
12,
6308,
3287,
2348,
288,
702,
8,
277,
14,
694,
9167,
508,
499,
9,
288,
291,
14,
694,
9167,
275,
378,
267,
291,
14,
576,
221,
275,
2125,
267,
291,
14,
10386,
275,
283,
4624,
7,
199,
199,
533,
25115,
26,
272,
347,
636,
826,
721,
277,
12,
8570,
534,
4624,
297,
5552,
4022,
17,
12,
2984,
31847,
29,
17,
304,
267,
291,
14,
409,
2422,
8,
10386,
12,
5552,
12,
2984,
31847,
9,
339,
347,
663,
2422,
8,
277,
12,
8570,
12,
5552,
12,
2984,
31847,
304,
267,
702,
8,
10386,
508,
283,
68,
7,
503,
8570,
508,
283,
70,
7,
503,
8570,
508,
283,
4624,
358,
267,
291,
14,
10386,
221,
275,
8570,
267,
291,
14,
2697,
257,
275,
5552,
267,
291,
14,
1121,
31847,
275,
2984,
31847,
339,
347,
12864,
2891,
31847,
8,
277,
304,
267,
291,
14,
1121,
31847,
847,
413,
339,
347,
9700,
2891,
31847,
8,
277,
304,
267,
291,
14,
1121,
31847,
4862,
413,
339,
347,
664,
2891,
31847,
8,
277,
304,
267,
372,
291,
14,
1121,
31847,
339,
347,
663,
804,
8,
277,
12,
8570,
304,
267,
702,
8,
10386,
508,
283,
68,
7,
503,
8570,
508,
283,
70,
7,
503,
8570,
508,
283,
4624,
358
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
2196,
199,
504,
8691,
492,
13491,
199,
199,
5287,
275,
756,
199,
199,
318,
366,
1361,
8,
495,
304,
272,
340,
10990,
26,
267,
870,
620,
199,
199,
1361,
16452,
420,
275,
715,
199,
1361,
2223,
259,
275,
715,
199,
1361,
12776,
259,
275,
715,
199,
199,
533,
20810,
26,
272,
347,
636,
826,
721,
277,
12,
1568,
304,
267,
291,
14,
890,
275,
1568,
267,
291,
14,
66,
1130,
275,
942,
267,
367,
1967,
315,
1425,
8,
890,
304,
288,
291,
14,
66,
1130,
14,
740,
8,
16,
9,
339,
347,
29447,
8,
277,
304,
267,
367,
1967,
315,
1425,
8,
552,
8,
277,
14,
66,
1130,
2298,
288,
340,
291,
14,
66,
1130,
59,
1507,
61,
508,
378,
26,
355,
291,
14,
66,
1130,
59,
1507,
61,
275,
413,
355,
372,
1967,
267,
372,
446,
17,
339,
347,
2867,
8,
277,
12,
1967,
304,
267,
702,
8,
277,
14,
66,
1130,
59,
1507,
61,
508,
413,
9,
267,
291,
14,
66,
1130,
59,
1507,
61,
275,
378,
339,
347,
2216,
2439,
13340,
8,
277,
12,
1967,
304,
267,
702,
8,
277,
14,
66,
1130,
59,
1507,
61,
508,
378,
9,
267,
291,
14,
66,
1130,
59,
1507,
61,
275,
413,
339,
347,
5461,
8,
277,
304,
267,
308,
275,
2125,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
66,
1130,
2298,
288,
308,
847,
620,
8,
277,
14,
66,
1130,
59,
73,
566,
267,
372,
308,
199,
199,
533,
1853,
26,
272,
347,
636,
826,
721,
277,
12,
8570,
304,
267,
702,
8,
10386,
508,
283,
68,
7,
503,
8570,
508,
283,
70,
7,
503,
8570,
508,
283,
4624,
358,
267,
291,
14,
10386,
275,
8570,
267,
327,
1454,
367,
6602,
12,
7684,
282,
5516,
1325,
3963,
1704,
470,
267,
291,
14,
694,
9167,
275,
378,
267,
291,
14,
988,
9167,
275,
4337,
267,
291,
14,
694,
1296,
275,
942,
267,
291,
14,
576,
259,
275,
2125,
339,
347,
5461,
8,
277,
304,
267,
340,
291,
14,
10386,
508,
283,
4624,
356,
288,
372,
6730,
6616,
267,
916,
291,
14,
10386,
508,
283,
68,
356,
288,
4819,
275,
2125,
288,
367,
366,
315,
291,
14,
694,
1296,
26,
355,
327,
366,
365,
402,
314,
1824,
661,
354,
297,
315,
453,
9,
355,
3974,
275,
25676,
83,
8719,
83,
3171,
450,
334,
68,
59,
16,
467,
366,
59,
17,
566,
355,
340,
4819,
508,
8061,
490,
4819,
275,
3974,
355,
587,
26,
490,
4819,
847,
283,
283,
435,
3974,
288,
372,
22640,
11,
1195,
11,
418,
7,
288,
327,
372,
1543,
83,
7,
450,
291,
14,
694,
1296,
267,
587,
26,
288,
372,
30423,
83,
6616,
450,
291,
14,
576,
339,
347,
663,
804,
8,
277,
12,
8570,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
4624,
358,
267,
291,
14,
10386,
275,
8570,
339,
347,
1050,
1451,
8,
277,
12,
666,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
70,
358,
267,
291,
14,
576,
275,
666,
339,
347,
664,
5667,
17816,
8,
277,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
372,
291,
14,
694,
9167,
339,
347,
664,
10146,
17816,
8,
277,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
372,
291,
14,
988,
9167,
446,
291,
14,
694,
9167,
339,
347,
664,
3900,
8,
277,
12,
1967,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
702,
8,
1507,
665,
291,
14,
694,
9167,
9,
267,
372,
291,
14,
694,
1296,
59,
1507,
61,
339,
347,
1050,
3567,
3900,
8,
277,
12,
536,
12,
315,
453,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
291,
14,
694,
1296,
14,
740,
1332,
354,
12,
315,
453,
430,
267,
291,
14,
694,
9167,
847,
413,
267,
702,
8,
277,
14,
694,
9167,
2695,
291,
14,
988,
9167,
9,
339,
347,
2150,
3567,
3900,
8,
277,
12,
536,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
307,
354,
275,
536,
14,
1294,
7825,
267,
366,
354,
275,
307,
354,
59,
552,
8,
31383,
9,
446,
413,
61,
267,
367,
284,
315,
1425,
8,
552,
8,
277,
14,
694,
1296,
2298,
288,
340,
291,
14,
694,
1296,
59,
73,
1527,
16,
61,
508,
366,
354,
26,
355,
291,
14,
694,
1296,
14,
1935,
8,
73,
9,
355,
291,
14,
694,
9167,
4862,
413,
355,
372,
267,
702,
8,
17,
508,
378,
9,
339,
347,
2935,
3900,
7965,
8,
277,
12,
536,
304,
267,
702,
8,
277,
14,
10386,
508,
283,
68,
358,
267,
367,
366,
315,
291,
14,
694,
1296,
26,
288,
340,
536,
508,
366,
59,
16,
2189,
355,
372,
715,
267,
372,
756,
339,
347,
2867,
8,
277,
304,
267,
702,
8,
277,
14,
10386,
1137,
283,
4624,
358,
267,
340,
291,
14,
10386,
508,
283,
68,
356,
288,
327,
1104,
367,
1454,
6308,
12,
6308,
3287,
2348,
288,
702,
8,
277,
14,
694,
9167,
508,
499,
9,
288,
291,
14,
694,
9167,
275,
378,
267,
291,
14,
576,
221,
275,
2125,
267,
291,
14,
10386,
275,
283,
4624,
7,
199,
199,
533,
25115,
26,
272,
347,
636,
826,
721,
277,
12,
8570,
534,
4624,
297,
5552,
4022,
17,
12,
2984,
31847,
29,
17,
304,
267,
291,
14,
409,
2422,
8,
10386,
12,
5552,
12,
2984,
31847,
9,
339,
347,
663,
2422,
8,
277,
12,
8570,
12,
5552,
12,
2984,
31847,
304,
267,
702,
8,
10386,
508,
283,
68,
7,
503,
8570,
508,
283,
70,
7,
503,
8570,
508,
283,
4624,
358,
267,
291,
14,
10386,
221,
275,
8570,
267,
291,
14,
2697,
257,
275,
5552,
267,
291,
14,
1121,
31847,
275,
2984,
31847,
339,
347,
12864,
2891,
31847,
8,
277,
304,
267,
291,
14,
1121,
31847,
847,
413,
339,
347,
9700,
2891,
31847,
8,
277,
304,
267,
291,
14,
1121,
31847,
4862,
413,
339,
347,
664,
2891,
31847,
8,
277,
304,
267,
372,
291,
14,
1121,
31847,
339,
347,
663,
804,
8,
277,
12,
8570,
304,
267,
702,
8,
10386,
508,
283,
68,
7,
503,
8570,
508,
283,
70,
7,
503,
8570,
508,
283,
4624,
358,
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,
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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
] |
Edgar-Bruno/Estudos_iniciais_Python
|
GTK/sudoku/OrdenadasVerificar.py
|
1
|
1348
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
# Verificação de repetição no eixo das abscissas
indexMatriz = 46 # Index da matriz passado no click
i = indexMatriz
dicOrdenadas = {} # Key é o index da listaMatriz, value é o existe ou não
listaMatriz = [6, 2, 4, 1, 5, 9, 7, 6, 8,
9, 7, 8, 2, 6, 3, 1, 9, 4,
5, 6, 2, 3, 8, 7, 4, 9, 1,
1, 5, 7, 8, 3, 4, 2, 6, 9,
4, 1, 1, 6, 7, 8, 5, 2, 3,
7, 8, 5, 9, 7, 2, 3, 7, 6,
3, 4, 9, 7, 2, 6, 8, 1, 5,
8, 3, 6, 5, 4, 1, 9, 7, 2,
2, 1, 3, 4, 9, 5, 6, 8, 7]
"""
[6, 2, 4, 1, 5, 9, 7, 6, 8,
9, 7, 8, 2, 6, 3, 1, 9, 4,
5, 6, 2, 3, 8, 7, 4, 9, 1,
1, 5, 7, 8, 3, 4, 2, 6, 9,
4, 9, 1, 6, 7, 8, 5, 2, 3,
7, 8, 5, 9, 7, 2, 3, 7, 6,
3, 4, 9, 7, 2, 6, 8, 1, 5,
8, 3, 6, 5, 4, 1, 9, 7, 2,
2, 1, 3, 4, 9, 5, 6, 8, 7]
"""
i = indexMatriz
while i >= 9:
i -= 9
listaOrdenadasTMP = listaMatriz[i::9] # lista da linha pesquisada. Index inicial = 0
print listaOrdenadasTMP
print "------------------------ "
for ii in range(9):
vaux = listaOrdenadasTMP[ii]
listaOrdenadasTMP[ii] = None
print listaOrdenadasTMP
if vaux in listaOrdenadasTMP:
dicOrdenadas[i] = True
else:
dicOrdenadas[i] = False
i += 9
listaOrdenadasTMP[ii] = vaux # Retorna o valor original
print dicOrdenadas
dicValid = [True, True, True]
if False in dicValid:
print "AQUI!!!!! "
print dicValid
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
199,
3,
5444,
1903,
696,
22723,
477,
6375,
280,
22723,
949,
325,
1148,
79,
366,
305,
2236,
551,
19857,
305,
199,
199,
1080,
14817,
322,
90,
275,
221,
12426,
327,
5499,
12927,
2530,
322,
90,
986,
5129,
949,
8968,
199,
199,
73,
275,
1478,
14817,
322,
90,
199,
199,
5000,
2844,
848,
350,
305,
275,
1052,
327,
2606,
26785,
312,
1478,
12927,
769,
65,
14817,
322,
90,
12,
574,
26785,
312,
444,
29729,
29934,
302,
16299,
199,
199,
513,
65,
14817,
322,
90,
275,
359,
22,
12,
499,
12,
841,
12,
413,
12,
959,
12,
1749,
12,
1520,
12,
1227,
12,
1695,
12,
199,
1749,
12,
1520,
12,
1695,
12,
499,
12,
1227,
12,
650,
12,
413,
12,
1749,
12,
841,
12,
199,
959,
12,
1227,
12,
499,
12,
650,
12,
1695,
12,
1520,
12,
841,
12,
1749,
12,
413,
12,
199,
413,
12,
959,
12,
1520,
12,
1695,
12,
650,
12,
841,
12,
499,
12,
1227,
12,
1749,
12,
199,
841,
12,
413,
12,
413,
12,
1227,
12,
1520,
12,
1695,
12,
959,
12,
499,
12,
650,
12,
199,
1520,
12,
1695,
12,
959,
12,
1749,
12,
1520,
12,
499,
12,
650,
12,
1520,
12,
1227,
12,
199,
650,
12,
841,
12,
1749,
12,
1520,
12,
499,
12,
1227,
12,
1695,
12,
413,
12,
959,
12,
199,
1695,
12,
650,
12,
1227,
12,
959,
12,
841,
12,
413,
12,
1749,
12,
1520,
12,
499,
12,
199,
499,
12,
413,
12,
650,
12,
841,
12,
1749,
12,
959,
12,
1227,
12,
1695,
12,
1520,
61,
199,
199,
624,
199,
59,
22,
12,
499,
12,
841,
12,
413,
12,
959,
12,
1749,
12,
1520,
12,
1227,
12,
1695,
12,
199,
1749,
12,
1520,
12,
1695,
12,
499,
12,
1227,
12,
650,
12,
413,
12,
1749,
12,
841,
12,
199,
959,
12,
1227,
12,
499,
12,
650,
12,
1695,
12,
1520,
12,
841,
12,
1749,
12,
413,
12,
199,
413,
12,
959,
12,
1520,
12,
1695,
12,
650,
12,
841,
12,
499,
12,
1227,
12,
1749,
12,
199,
841,
12,
1749,
12,
413,
12,
1227,
12,
1520,
12,
1695,
12,
959,
12,
499,
12,
650,
12,
199,
1520,
12,
1695,
12,
959,
12,
1749,
12,
1520,
12,
499,
12,
650,
12,
1520,
12,
1227,
12,
199,
650,
12,
841,
12,
1749,
12,
1520,
12,
499,
12,
1227,
12,
1695,
12,
413,
12,
959,
12,
199,
1695,
12,
650,
12,
1227,
12,
959,
12,
841,
12,
413,
12,
1749,
12,
1520,
12,
499,
12,
199,
499,
12,
413,
12,
650,
12,
841,
12,
1749,
12,
959,
12,
1227,
12,
1695,
12,
1520,
61,
199,
408,
199,
199,
73,
275,
1478,
14817,
322,
90,
199,
199,
6710,
284,
2356,
1749,
26,
199,
198,
73,
4862,
1749,
199,
199,
513,
65,
2844,
848,
350,
305,
17983,
275,
769,
65,
14817,
322,
90,
59,
73,
447,
25,
61,
327,
769,
65,
12927,
7403,
2411,
299,
397,
392,
374,
10641,
14,
5499,
315,
530,
2380,
275,
378,
199,
199,
1361,
769,
65,
2844,
848,
350,
305,
17983,
199,
1361,
298,
777,
518,
298,
199,
199,
509,
15393,
315,
1425,
8,
25,
304,
199,
198,
3042,
2521,
275,
769,
65,
2844,
848,
350,
305,
17983,
59,
5908,
61,
199,
198,
513,
65,
2844,
848,
350,
305,
17983,
59,
5908,
61,
275,
488,
421,
198,
1361,
769,
65,
2844,
848,
350,
305,
17983,
199,
198,
692,
373,
10962,
315,
769,
65,
2844,
848,
350,
305,
17983,
26,
507,
198,
5000,
2844,
848,
350,
305,
59,
73,
61,
275,
715,
421,
198,
2836,
26,
2742,
198,
5000,
2844,
848,
350,
305,
59,
73,
61,
275,
756,
421,
198,
73,
847,
1749,
421,
198,
513,
65,
2844,
848,
350,
305,
17983,
59,
5908,
61,
275,
373,
10962,
327,
8747,
269,
3540,
312,
1139,
269,
3379,
199,
199,
1361,
12219,
2844,
848,
350,
305,
507,
199,
5000,
3490,
275,
359,
549,
12,
715,
12,
715,
61,
199,
199,
692,
756,
315,
12219,
3490,
26,
199,
198,
1361,
298,
33,
2328,
41,
6386,
1,
298,
199,
1361,
12219,
3490,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
747,
199,
199,
3,
5444,
1903,
696,
22723,
477,
6375,
280,
22723,
949,
325,
1148,
79,
366,
305,
2236,
551,
19857,
305,
199,
199,
1080,
14817,
322,
90,
275,
221,
12426,
327,
5499,
12927,
2530,
322,
90,
986,
5129,
949,
8968,
199,
199,
73,
275,
1478,
14817,
322,
90,
199,
199,
5000,
2844,
848,
350,
305,
275,
1052,
327,
2606,
26785,
312,
1478,
12927,
769,
65,
14817,
322,
90,
12,
574,
26785,
312,
444,
29729,
29934,
302,
16299,
199,
199,
513,
65,
14817,
322,
90,
275,
359,
22,
12,
499,
12,
841,
12,
413,
12,
959,
12,
1749,
12,
1520,
12,
1227,
12,
1695,
12,
199,
1749,
12,
1520,
12,
1695,
12,
499,
12,
1227,
12,
650,
12,
413,
12,
1749,
12,
841,
12,
199,
959,
12,
1227,
12,
499,
12,
650,
12,
1695,
12,
1520,
12,
841,
12,
1749,
12,
413,
12,
199,
413,
12,
959,
12,
1520,
12,
1695,
12,
650,
12,
841,
12,
499,
12,
1227,
12,
1749,
12,
199,
841,
12,
413,
12,
413,
12,
1227,
12,
1520,
12,
1695,
12,
959,
12,
499,
12,
650,
12,
199,
1520,
12,
1695,
12,
959,
12,
1749,
12,
1520,
12,
499,
12,
650,
12,
1520,
12,
1227,
12,
199,
650,
12,
841,
12,
1749,
12,
1520,
12,
499,
12,
1227,
12,
1695,
12,
413,
12,
959,
12,
199,
1695,
12,
650,
12,
1227,
12,
959,
12,
841,
12,
413,
12,
1749,
12,
1520,
12,
499,
12,
199,
499,
12,
413,
12,
650,
12,
841,
12,
1749,
12,
959,
12,
1227,
12,
1695,
12,
1520,
61,
199,
199,
624,
199,
59,
22,
12,
499,
12,
841,
12,
413,
12,
959,
12,
1749,
12,
1520,
12,
1227,
12,
1695,
12,
199,
1749,
12,
1520,
12,
1695,
12,
499,
12,
1227,
12,
650,
12,
413,
12,
1749,
12,
841,
12,
199,
959,
12,
1227,
12,
499,
12,
650,
12,
1695,
12,
1520,
12,
841,
12,
1749,
12,
413,
12,
199,
413,
12,
959,
12,
1520,
12,
1695,
12,
650,
12,
841,
12,
499,
12,
1227,
12,
1749,
12,
199,
841,
12,
1749,
12,
413,
12,
1227,
12,
1520,
12,
1695,
12,
959,
12,
499,
12,
650,
12,
199,
1520,
12,
1695,
12,
959,
12,
1749,
12,
1520,
12,
499,
12,
650,
12,
1520,
12,
1227,
12,
199,
650,
12,
841,
12,
1749,
12,
1520,
12,
499,
12,
1227,
12,
1695,
12,
413,
12,
959,
12,
199,
1695,
12,
650,
12,
1227,
12,
959,
12,
841,
12,
413,
12,
1749,
12,
1520,
12,
499,
12,
199,
499,
12,
413,
12,
650,
12,
841,
12,
1749,
12,
959,
12,
1227,
12,
1695,
12,
1520,
61,
199,
408,
199,
199,
73,
275,
1478,
14817,
322,
90,
199,
199,
6710,
284,
2356,
1749,
26,
199,
198,
73,
4862,
1749,
199,
199,
513,
65,
2844,
848,
350,
305,
17983,
275,
769,
65,
14817,
322,
90,
59,
73,
447,
25,
61,
327,
769,
65,
12927,
7403,
2411,
299,
397,
392,
374,
10641,
14,
5499,
315,
530,
2380,
275,
378,
199,
199,
1361,
769,
65,
2844,
848,
350,
305,
17983,
199,
1361,
298,
777,
518,
298,
199,
199,
509,
15393,
315,
1425,
8,
25,
304,
199,
198,
3042,
2521,
275,
769,
65,
2844,
848,
350,
305,
17983,
59,
5908,
61,
199,
198,
513,
65,
2844,
848,
350,
305,
17983,
59,
5908,
61,
275,
488,
421,
198,
1361,
769,
65,
2844,
848,
350,
305,
17983,
199,
198,
692,
373,
10962,
315,
769,
65,
2844,
848,
350,
305,
17983,
26,
507,
198,
5000,
2844,
848,
350,
305,
59,
73,
61,
275,
715,
421,
198,
2836,
26,
2742,
198,
5000,
2844,
848,
350,
305,
59,
73,
61,
275,
756,
421,
198,
73,
847,
1749,
421,
198,
513,
65,
2844,
848,
350,
305,
17983,
59,
5908,
61,
275,
373,
10962,
327,
8747,
269,
3540,
312,
1139,
269,
3379,
199,
199,
1361,
12219,
2844,
848,
350,
305,
507,
199,
5000,
3490,
275,
359,
549,
12,
715,
12,
715,
61,
199,
199,
692,
756,
315,
12219,
3490,
26,
199,
198,
1361,
298,
33,
2328,
41,
6386,
1,
298,
199,
1361,
12219,
3490,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
2014c2g14/c2g14
|
exts/w2/static/Brython2.0.0-20140209-164925/Lib/string.py
|
734
|
9410
|
"""A collection of string constants.
Public module variables:
whitespace -- a string containing all ASCII whitespace
ascii_lowercase -- a string containing all ASCII lowercase letters
ascii_uppercase -- a string containing all ASCII uppercase letters
ascii_letters -- a string containing all ASCII letters
digits -- a string containing all ASCII decimal digits
hexdigits -- a string containing all ASCII hexadecimal digits
octdigits -- a string containing all ASCII octal digits
punctuation -- a string containing all ASCII punctuation characters
printable -- a string containing all ASCII characters considered printable
"""
import _string
# Some strings for ctype-style character classification
whitespace = ' \t\n\r\v\f'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_letters = ascii_lowercase + ascii_uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + ascii_letters + punctuation + whitespace
# Functions which aren't available as string methods.
# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
def capwords(s, sep=None):
"""capwords(s [,sep]) -> string
Split the argument into words using split, capitalize each
word using capitalize, and join the capitalized words using
join. If the optional second argument sep is absent or None,
runs of whitespace characters are replaced by a single space
and leading and trailing whitespace are removed, otherwise
sep is used to split and join the words.
"""
return (sep or ' ').join(x.capitalize() for x in s.split(sep))
####################################################################
import re as _re
from collections import ChainMap
class _TemplateMetaclass(type):
pattern = r"""
%(delim)s(?:
(?P<escaped>%(delim)s) | # Escape sequence of two delimiters
(?P<named>%(id)s) | # delimiter and a Python identifier
{(?P<braced>%(id)s)} | # delimiter and a braced identifier
(?P<invalid>) # Other ill-formed delimiter exprs
)
"""
def __init__(cls, name, bases, dct):
super(_TemplateMetaclass, cls).__init__(name, bases, dct)
if 'pattern' in dct:
pattern = cls.pattern
else:
pattern = _TemplateMetaclass.pattern % {
'delim' : _re.escape(cls.delimiter),
'id' : cls.idpattern,
}
cls.pattern = _re.compile(pattern, cls.flags | _re.VERBOSE)
class Template(metaclass=_TemplateMetaclass):
"""A string class for supporting $-substitutions."""
delimiter = '$'
idpattern = r'[_a-z][_a-z0-9]*'
flags = _re.IGNORECASE
def __init__(self, template):
self.template = template
# Search for $$, $identifier, ${identifier}, and any bare $'s
def _invalid(self, mo):
i = mo.start('invalid')
lines = self.template[:i].splitlines(keepends=True)
if not lines:
colno = 1
lineno = 1
else:
colno = i - len(''.join(lines[:-1]))
lineno = len(lines)
raise ValueError('Invalid placeholder in string: line %d, col %d' %
(lineno, colno))
def substitute(self, *args, **kws):
if len(args) > 1:
raise TypeError('Too many positional arguments')
if not args:
mapping = kws
elif kws:
mapping = ChainMap(kws, args[0])
else:
mapping = args[0]
# Helper function for .sub()
def convert(mo):
# Check the most common path first.
named = mo.group('named') or mo.group('braced')
if named is not None:
val = mapping[named]
# We use this idiom instead of str() because the latter will
# fail if val is a Unicode containing non-ASCII characters.
return '%s' % (val,)
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
self._invalid(mo)
raise ValueError('Unrecognized named group in pattern',
self.pattern)
return self.pattern.sub(convert, self.template)
def safe_substitute(self, *args, **kws):
if len(args) > 1:
raise TypeError('Too many positional arguments')
if not args:
mapping = kws
elif kws:
mapping = ChainMap(kws, args[0])
else:
mapping = args[0]
# Helper function for .sub()
def convert(mo):
named = mo.group('named') or mo.group('braced')
if named is not None:
try:
# We use this idiom instead of str() because the latter
# will fail if val is a Unicode containing non-ASCII
return '%s' % (mapping[named],)
except KeyError:
return mo.group()
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
return mo.group()
raise ValueError('Unrecognized named group in pattern',
self.pattern)
return self.pattern.sub(convert, self.template)
########################################################################
# the Formatter class
# see PEP 3101 for details and purpose of this class
# The hard parts are reused from the C implementation. They're exposed as "_"
# prefixed methods of str.
# The overall parser is implemented in _string.formatter_parser.
# The field name parser is implemented in _string.formatter_field_name_split
class Formatter:
def format(self, format_string, *args, **kwargs):
return self.vformat(format_string, args, kwargs)
def vformat(self, format_string, args, kwargs):
used_args = set()
result = self._vformat(format_string, args, kwargs, used_args, 2)
self.check_unused_args(used_args, args, kwargs)
return result
def _vformat(self, format_string, args, kwargs, used_args, recursion_depth):
if recursion_depth < 0:
raise ValueError('Max string recursion exceeded')
result = []
for literal_text, field_name, format_spec, conversion in \
self.parse(format_string):
# output the literal text
if literal_text:
result.append(literal_text)
# if there's a field, output it
if field_name is not None:
# this is some markup, find the object and do
# the formatting
# given the field_name, find the object it references
# and the argument it came from
obj, arg_used = self.get_field(field_name, args, kwargs)
used_args.add(arg_used)
# do any conversion on the resulting object
obj = self.convert_field(obj, conversion)
# expand the format spec, if needed
format_spec = self._vformat(format_spec, args, kwargs,
used_args, recursion_depth-1)
# format the object and append to the result
result.append(self.format_field(obj, format_spec))
return ''.join(result)
def get_value(self, key, args, kwargs):
if isinstance(key, int):
return args[key]
else:
return kwargs[key]
def check_unused_args(self, used_args, args, kwargs):
pass
def format_field(self, value, format_spec):
return format(value, format_spec)
def convert_field(self, value, conversion):
# do any conversion on the resulting object
if conversion is None:
return value
elif conversion == 's':
return str(value)
elif conversion == 'r':
return repr(value)
elif conversion == 'a':
return ascii(value)
raise ValueError("Unknown conversion specifier {0!s}".format(conversion))
# returns an iterable that contains tuples of the form:
# (literal_text, field_name, format_spec, conversion)
# literal_text can be zero length
# field_name can be None, in which case there's no
# object to format and output
# if field_name is not None, it is looked up, formatted
# with format_spec and conversion and then used
def parse(self, format_string):
return _string.formatter_parser(format_string)
# given a field_name, find the object it references.
# field_name: the field being looked up, e.g. "0.name"
# or "lookup[3]"
# used_args: a set of which args have been used
# args, kwargs: as passed in to vformat
def get_field(self, field_name, args, kwargs):
first, rest = _string.formatter_field_name_split(field_name)
obj = self.get_value(first, args, kwargs)
# loop through the rest of the field_name, doing
# getattr or getitem as needed
for is_attr, i in rest:
if is_attr:
obj = getattr(obj, i)
else:
obj = obj[i]
return obj, first
|
gpl-2.0
|
[
624,
33,
3245,
402,
1059,
5262,
14,
199,
199,
9885,
859,
2860,
26,
199,
199,
8506,
1553,
282,
1059,
3035,
1006,
10485,
8139,
199,
4371,
63,
21636,
1553,
282,
1059,
3035,
1006,
10485,
12141,
14435,
199,
4371,
63,
26831,
1553,
282,
1059,
3035,
1006,
10485,
22681,
14435,
199,
4371,
63,
16415,
1553,
282,
1059,
3035,
1006,
10485,
14435,
199,
7022,
1553,
282,
1059,
3035,
1006,
10485,
6107,
7576,
199,
4097,
7022,
1553,
282,
1059,
3035,
1006,
10485,
20379,
7576,
199,
15560,
7022,
1553,
282,
1059,
3035,
1006,
10485,
30100,
7576,
199,
25181,
1553,
282,
1059,
3035,
1006,
10485,
22929,
4110,
199,
20557,
1553,
282,
1059,
3035,
1006,
10485,
4110,
8652,
21834,
199,
199,
624,
199,
199,
646,
485,
875,
199,
199,
3,
6601,
3326,
367,
16360,
13,
2487,
4528,
12505,
199,
8506,
275,
283,
971,
84,
60,
78,
60,
82,
60,
86,
60,
70,
7,
199,
4371,
63,
21636,
275,
283,
23459,
7,
199,
4371,
63,
26831,
275,
283,
28114,
7,
199,
4371,
63,
16415,
275,
13294,
63,
21636,
435,
13294,
63,
26831,
199,
7022,
275,
283,
11371,
7,
199,
4097,
7022,
275,
7576,
435,
283,
10678,
7,
435,
283,
18820,
7,
199,
15560,
7022,
275,
283,
9461,
5308,
7,
199,
25181,
275,
408,
9539,
3,
22074,
6,
7,
25608,
11,
3057,
13186,
26,
27,
12932,
30,
31,
32,
7023,
61,
62,
28116,
91,
92,
93,
94,
624,
199,
20557,
275,
7576,
435,
13294,
63,
16415,
435,
22929,
435,
8139,
199,
199,
3,
17471,
1314,
10621,
1133,
2808,
465,
1059,
3102,
14,
199,
199,
3,
22516,
6910,
794,
314,
5932,
315,
282,
1059,
12,
325,
14,
71,
14,
298,
282,
34,
67,
221,
366,
29916,
298,
1035,
298,
30293,
11391,
1674,
199,
318,
4021,
3148,
8,
83,
12,
7375,
29,
403,
304,
272,
408,
2874,
3148,
8,
83,
359,
12,
4127,
566,
1035,
1059,
339,
11740,
314,
1423,
1901,
5932,
1808,
3715,
12,
17094,
794,
1924,
272,
4349,
1808,
17094,
794,
12,
436,
4263,
314,
17094,
1759,
5932,
1808,
272,
4263,
14,
221,
982,
314,
2716,
3499,
1423,
7375,
365,
9552,
503,
488,
12,
272,
7858,
402,
8139,
4110,
787,
8717,
701,
282,
2849,
4601,
272,
436,
9186,
436,
8520,
8139,
787,
4829,
12,
4257,
272,
7375,
365,
1202,
370,
3715,
436,
4263,
314,
5932,
14,
339,
408,
272,
372,
334,
4127,
503,
283,
27274,
904,
8,
88,
14,
18351,
342,
367,
671,
315,
308,
14,
1294,
8,
4127,
430,
421,
199,
3060,
381,
199,
646,
295,
465,
485,
264,
199,
504,
5055,
492,
25384,
2956,
199,
199,
533,
485,
4231,
29387,
8,
466,
304,
272,
3851,
275,
519,
624,
272,
2818,
15966,
9,
83,
5169,
489,
7558,
48,
28,
13572,
19418,
15966,
9,
83,
9,
1204,
257,
327,
21067,
3414,
402,
2877,
26968,
489,
7558,
48,
28,
4579,
19418,
344,
9,
83,
9,
420,
1204,
257,
327,
11172,
436,
282,
2018,
5148,
489,
469,
2229,
48,
28,
22359,
68,
19418,
344,
9,
83,
6769,
257,
1204,
257,
327,
11172,
436,
282,
23549,
68,
5148,
489,
7558,
48,
28,
3197,
18956,
4519,
327,
5439,
22907,
13,
6194,
11172,
23770,
272,
776,
272,
408,
339,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
16354,
304,
267,
1613,
1547,
4231,
29387,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
16354,
9,
267,
340,
283,
3401,
7,
315,
16354,
26,
288,
3851,
275,
843,
14,
3401,
267,
587,
26,
288,
3851,
275,
485,
4231,
29387,
14,
3401,
450,
469,
355,
283,
15966,
7,
520,
485,
264,
14,
3765,
8,
1886,
14,
15104,
395,
355,
283,
344,
7,
259,
520,
843,
14,
344,
3401,
12,
355,
789,
267,
843,
14,
3401,
275,
485,
264,
14,
2014,
8,
3401,
12,
843,
14,
2469,
1204,
485,
264,
14,
16075,
9,
421,
199,
533,
5458,
8,
6577,
3699,
4231,
29387,
304,
272,
408,
33,
1059,
1021,
367,
21038,
2672,
13,
14340,
8653,
1041,
339,
11172,
275,
25271,
272,
1305,
3401,
275,
519,
3894,
63,
65,
13,
90,
1527,
63,
65,
13,
90,
16,
13,
25,
3672,
7,
272,
3285,
275,
485,
264,
14,
15434,
339,
347,
636,
826,
721,
277,
12,
1978,
304,
267,
291,
14,
1160,
275,
1978,
339,
327,
8730,
367,
2672,
4,
12,
2672,
5364,
12,
10839,
5364,
1386,
436,
1263,
18753,
2672,
7,
83,
339,
347,
485,
3197,
8,
277,
12,
1303,
304,
267,
284,
275,
1303,
14,
928,
360,
3197,
358,
267,
2385,
275,
291,
14,
1160,
1491,
73,
1055,
7644,
8,
3250,
3198,
29,
549,
9,
267,
340,
440,
2385,
26,
288,
1048,
889,
275,
413,
288,
5874,
275,
413,
267,
587,
26,
288,
1048,
889,
275,
284,
446,
822,
17840,
904,
8,
1278,
4439,
17,
2459,
288,
5874,
275,
822,
8,
1278,
9,
267,
746,
1722,
360,
3364,
10069,
315,
1059,
26,
1004,
450,
68,
12,
1048,
450,
68,
7,
450,
586,
334,
3469,
12,
1048,
889,
430,
339,
347,
23080,
8,
277,
12,
627,
589,
12,
1011,
28769,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
3146,
360,
13749,
5002,
11333,
2368,
358,
267,
340,
440,
1249,
26,
288,
4412,
275,
4775,
83,
267,
916,
4775,
83,
26,
288,
4412,
275,
25384,
2956,
8,
28769,
12,
1249,
59,
16,
566,
267,
587,
26,
288,
4412,
275,
1249,
59,
16,
61,
267,
327,
11642,
805,
367,
1275,
954,
342,
267,
347,
3957,
8,
573,
304,
288,
327,
2670,
314,
4750,
2863,
931,
1642,
14,
288,
4310,
275,
1303,
14,
923,
360,
4579,
358,
503,
1303,
14,
923,
360,
22359,
68,
358,
288,
340,
4310,
365,
440,
488,
26,
355,
1139,
275,
4412,
59,
4579,
61,
355,
327,
2136,
675,
642,
284,
328,
676,
3140,
402,
620,
342,
2952,
314,
19045,
911,
355,
327,
2449,
340,
1139,
365,
282,
6140,
3035,
2222,
13,
12292,
4110,
14,
355,
372,
1543,
83,
7,
450,
334,
637,
4258,
288,
340,
1303,
14,
923,
360,
13572,
358,
365,
440,
488,
26,
355,
372,
291,
14,
15104,
288,
340,
1303,
14,
923,
360,
3197,
358,
365,
440,
488,
26,
355,
291,
423,
3197,
8,
573,
9,
288,
746,
1722,
360,
22517,
4310,
1572,
315,
3851,
297,
2490,
291,
14,
3401,
9,
267,
372,
291,
14,
3401,
14,
954,
8,
3916,
12,
291,
14
] |
[
33,
3245,
402,
1059,
5262,
14,
199,
199,
9885,
859,
2860,
26,
199,
199,
8506,
1553,
282,
1059,
3035,
1006,
10485,
8139,
199,
4371,
63,
21636,
1553,
282,
1059,
3035,
1006,
10485,
12141,
14435,
199,
4371,
63,
26831,
1553,
282,
1059,
3035,
1006,
10485,
22681,
14435,
199,
4371,
63,
16415,
1553,
282,
1059,
3035,
1006,
10485,
14435,
199,
7022,
1553,
282,
1059,
3035,
1006,
10485,
6107,
7576,
199,
4097,
7022,
1553,
282,
1059,
3035,
1006,
10485,
20379,
7576,
199,
15560,
7022,
1553,
282,
1059,
3035,
1006,
10485,
30100,
7576,
199,
25181,
1553,
282,
1059,
3035,
1006,
10485,
22929,
4110,
199,
20557,
1553,
282,
1059,
3035,
1006,
10485,
4110,
8652,
21834,
199,
199,
624,
199,
199,
646,
485,
875,
199,
199,
3,
6601,
3326,
367,
16360,
13,
2487,
4528,
12505,
199,
8506,
275,
283,
971,
84,
60,
78,
60,
82,
60,
86,
60,
70,
7,
199,
4371,
63,
21636,
275,
283,
23459,
7,
199,
4371,
63,
26831,
275,
283,
28114,
7,
199,
4371,
63,
16415,
275,
13294,
63,
21636,
435,
13294,
63,
26831,
199,
7022,
275,
283,
11371,
7,
199,
4097,
7022,
275,
7576,
435,
283,
10678,
7,
435,
283,
18820,
7,
199,
15560,
7022,
275,
283,
9461,
5308,
7,
199,
25181,
275,
408,
9539,
3,
22074,
6,
7,
25608,
11,
3057,
13186,
26,
27,
12932,
30,
31,
32,
7023,
61,
62,
28116,
91,
92,
93,
94,
624,
199,
20557,
275,
7576,
435,
13294,
63,
16415,
435,
22929,
435,
8139,
199,
199,
3,
17471,
1314,
10621,
1133,
2808,
465,
1059,
3102,
14,
199,
199,
3,
22516,
6910,
794,
314,
5932,
315,
282,
1059,
12,
325,
14,
71,
14,
298,
282,
34,
67,
221,
366,
29916,
298,
1035,
298,
30293,
11391,
1674,
199,
318,
4021,
3148,
8,
83,
12,
7375,
29,
403,
304,
272,
408,
2874,
3148,
8,
83,
359,
12,
4127,
566,
1035,
1059,
339,
11740,
314,
1423,
1901,
5932,
1808,
3715,
12,
17094,
794,
1924,
272,
4349,
1808,
17094,
794,
12,
436,
4263,
314,
17094,
1759,
5932,
1808,
272,
4263,
14,
221,
982,
314,
2716,
3499,
1423,
7375,
365,
9552,
503,
488,
12,
272,
7858,
402,
8139,
4110,
787,
8717,
701,
282,
2849,
4601,
272,
436,
9186,
436,
8520,
8139,
787,
4829,
12,
4257,
272,
7375,
365,
1202,
370,
3715,
436,
4263,
314,
5932,
14,
339,
408,
272,
372,
334,
4127,
503,
283,
27274,
904,
8,
88,
14,
18351,
342,
367,
671,
315,
308,
14,
1294,
8,
4127,
430,
421,
199,
3060,
381,
199,
646,
295,
465,
485,
264,
199,
504,
5055,
492,
25384,
2956,
199,
199,
533,
485,
4231,
29387,
8,
466,
304,
272,
3851,
275,
519,
624,
272,
2818,
15966,
9,
83,
5169,
489,
7558,
48,
28,
13572,
19418,
15966,
9,
83,
9,
1204,
257,
327,
21067,
3414,
402,
2877,
26968,
489,
7558,
48,
28,
4579,
19418,
344,
9,
83,
9,
420,
1204,
257,
327,
11172,
436,
282,
2018,
5148,
489,
469,
2229,
48,
28,
22359,
68,
19418,
344,
9,
83,
6769,
257,
1204,
257,
327,
11172,
436,
282,
23549,
68,
5148,
489,
7558,
48,
28,
3197,
18956,
4519,
327,
5439,
22907,
13,
6194,
11172,
23770,
272,
776,
272,
408,
339,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
16354,
304,
267,
1613,
1547,
4231,
29387,
12,
843,
2843,
826,
721,
354,
12,
9768,
12,
16354,
9,
267,
340,
283,
3401,
7,
315,
16354,
26,
288,
3851,
275,
843,
14,
3401,
267,
587,
26,
288,
3851,
275,
485,
4231,
29387,
14,
3401,
450,
469,
355,
283,
15966,
7,
520,
485,
264,
14,
3765,
8,
1886,
14,
15104,
395,
355,
283,
344,
7,
259,
520,
843,
14,
344,
3401,
12,
355,
789,
267,
843,
14,
3401,
275,
485,
264,
14,
2014,
8,
3401,
12,
843,
14,
2469,
1204,
485,
264,
14,
16075,
9,
421,
199,
533,
5458,
8,
6577,
3699,
4231,
29387,
304,
272,
408,
33,
1059,
1021,
367,
21038,
2672,
13,
14340,
8653,
1041,
339,
11172,
275,
25271,
272,
1305,
3401,
275,
519,
3894,
63,
65,
13,
90,
1527,
63,
65,
13,
90,
16,
13,
25,
3672,
7,
272,
3285,
275,
485,
264,
14,
15434,
339,
347,
636,
826,
721,
277,
12,
1978,
304,
267,
291,
14,
1160,
275,
1978,
339,
327,
8730,
367,
2672,
4,
12,
2672,
5364,
12,
10839,
5364,
1386,
436,
1263,
18753,
2672,
7,
83,
339,
347,
485,
3197,
8,
277,
12,
1303,
304,
267,
284,
275,
1303,
14,
928,
360,
3197,
358,
267,
2385,
275,
291,
14,
1160,
1491,
73,
1055,
7644,
8,
3250,
3198,
29,
549,
9,
267,
340,
440,
2385,
26,
288,
1048,
889,
275,
413,
288,
5874,
275,
413,
267,
587,
26,
288,
1048,
889,
275,
284,
446,
822,
17840,
904,
8,
1278,
4439,
17,
2459,
288,
5874,
275,
822,
8,
1278,
9,
267,
746,
1722,
360,
3364,
10069,
315,
1059,
26,
1004,
450,
68,
12,
1048,
450,
68,
7,
450,
586,
334,
3469,
12,
1048,
889,
430,
339,
347,
23080,
8,
277,
12,
627,
589,
12,
1011,
28769,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
3146,
360,
13749,
5002,
11333,
2368,
358,
267,
340,
440,
1249,
26,
288,
4412,
275,
4775,
83,
267,
916,
4775,
83,
26,
288,
4412,
275,
25384,
2956,
8,
28769,
12,
1249,
59,
16,
566,
267,
587,
26,
288,
4412,
275,
1249,
59,
16,
61,
267,
327,
11642,
805,
367,
1275,
954,
342,
267,
347,
3957,
8,
573,
304,
288,
327,
2670,
314,
4750,
2863,
931,
1642,
14,
288,
4310,
275,
1303,
14,
923,
360,
4579,
358,
503,
1303,
14,
923,
360,
22359,
68,
358,
288,
340,
4310,
365,
440,
488,
26,
355,
1139,
275,
4412,
59,
4579,
61,
355,
327,
2136,
675,
642,
284,
328,
676,
3140,
402,
620,
342,
2952,
314,
19045,
911,
355,
327,
2449,
340,
1139,
365,
282,
6140,
3035,
2222,
13,
12292,
4110,
14,
355,
372,
1543,
83,
7,
450,
334,
637,
4258,
288,
340,
1303,
14,
923,
360,
13572,
358,
365,
440,
488,
26,
355,
372,
291,
14,
15104,
288,
340,
1303,
14,
923,
360,
3197,
358,
365,
440,
488,
26,
355,
291,
423,
3197,
8,
573,
9,
288,
746,
1722,
360,
22517,
4310,
1572,
315,
3851,
297,
2490,
291,
14,
3401,
9,
267,
372,
291,
14,
3401,
14,
954,
8,
3916,
12,
291,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alihalabyah/ansible
|
lib/ansible/utils/module_docs_fragments/cloudstack.py
|
85
|
2161
|
# -*- coding: utf-8 -*-
# Copyright (c) 2015 René Moser <mail@renemoser.net>
#
# 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/>.
class ModuleDocFragment(object):
# Standard cloudstack documentation fragment
DOCUMENTATION = '''
options:
api_key:
description:
- API key of the CloudStack API.
required: false
default: null
api_secret:
description:
- Secret key of the CloudStack API.
required: false
default: null
api_url:
description:
- URL of the CloudStack API e.g. https://cloud.example.com/client/api.
required: false
default: null
api_http_method:
description:
- HTTP method used.
required: false
default: 'get'
choices: [ 'get', 'post' ]
api_timeout:
description:
- HTTP timeout.
required: false
default: 10
requirements:
- "python >= 2.6"
- cs
notes:
- Ansible uses the C(cs) library's configuration method if credentials are not
provided by the options C(api_url), C(api_key), C(api_secret).
Configuration is read from several locations, in the following order.
- The C(CLOUDSTACK_ENDPOINT), C(CLOUDSTACK_KEY), C(CLOUDSTACK_SECRET) and
C(CLOUDSTACK_METHOD). C(CLOUDSTACK_TIMEOUT) environment variables.
- A C(CLOUDSTACK_CONFIG) environment variable pointing to an C(.ini) file,
- A C(cloudstack.ini) file in the current working directory.
- A C(.cloudstack.ini) file in the users home directory.
See https://github.com/exoscale/cs for more information.
- This module supports check mode.
'''
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
6900,
10055,
5741,
3930,
332,
665,
1198,
32,
264,
685,
573,
332,
14,
846,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
9739,
8002,
2340,
3794,
7956,
272,
29970,
2594,
275,
1449,
199,
1419,
26,
523,
2986,
63,
498,
26,
272,
1369,
26,
489,
446,
3261,
790,
402,
314,
8142,
4851,
3261,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2986,
63,
4731,
26,
272,
1369,
26,
489,
446,
23580,
790,
402,
314,
8142,
4851,
3261,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2986,
63,
633,
26,
272,
1369,
26,
489,
446,
2851,
402,
314,
8142,
4851,
3261,
325,
14,
71,
14,
4178,
921,
4091,
14,
2694,
14,
957,
15,
1258,
15,
1246,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2986,
63,
1014,
63,
765,
26,
272,
1369,
26,
489,
446,
3101,
1083,
1202,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
362,
7,
272,
3415,
26,
359,
283,
362,
297,
283,
1932,
7,
1622,
523,
2986,
63,
2593,
26,
272,
1369,
26,
489,
446,
3101,
2653,
14,
272,
1415,
26,
3055,
272,
849,
26,
1616,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
7117,
199,
5983,
26,
523,
446,
2622,
4440,
314,
445,
8,
1259,
9,
3555,
1159,
2897,
1083,
340,
6235,
787,
440,
272,
2741,
701,
314,
1511,
445,
8,
1246,
63,
633,
395,
445,
8,
1246,
63,
498,
395,
445,
8,
1246,
63,
4731,
680,
272,
11595,
365,
1586,
687,
9978,
9918,
12,
315,
314,
2569,
1865,
14,
272,
446,
710,
445,
8,
29495,
17014,
63,
21054,
395,
445,
8,
29495,
17014,
63,
3078,
395,
445,
8,
29495,
17014,
63,
12961,
9,
436,
489,
445,
8,
29495,
17014,
63,
9977,
680,
445,
8,
29495,
17014,
63,
8899,
9,
3734,
2860,
14,
272,
446,
437,
445,
8,
29495,
17014,
63,
5569,
9,
3734,
1750,
20686,
370,
376,
445,
13417,
2730,
9,
570,
12,
272,
446,
437,
445,
8,
4091,
2340,
14,
2730,
9,
570,
315,
314,
1453,
6449,
2082,
14,
272,
446,
437,
445,
13417,
4091,
2340,
14,
2730,
9,
570,
315,
314,
4390,
5629,
2082,
14,
489,
1666,
4178,
921,
5031,
14,
957,
15,
476,
79,
3467,
15,
1259,
367,
1655,
2556,
14,
523,
446,
961,
859,
5171,
1104,
818,
14,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
6900,
10055,
5741,
3930,
332,
665,
1198,
32,
264,
685,
573,
332,
14,
846,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
9739,
8002,
2340,
3794,
7956,
272,
29970,
2594,
275,
1449,
199,
1419,
26,
523,
2986,
63,
498,
26,
272,
1369,
26,
489,
446,
3261,
790,
402,
314,
8142,
4851,
3261,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2986,
63,
4731,
26,
272,
1369,
26,
489,
446,
23580,
790,
402,
314,
8142,
4851,
3261,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2986,
63,
633,
26,
272,
1369,
26,
489,
446,
2851,
402,
314,
8142,
4851,
3261,
325,
14,
71,
14,
4178,
921,
4091,
14,
2694,
14,
957,
15,
1258,
15,
1246,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
2986,
63,
1014,
63,
765,
26,
272,
1369,
26,
489,
446,
3101,
1083,
1202,
14,
272,
1415,
26,
3055,
272,
849,
26,
283,
362,
7,
272,
3415,
26,
359,
283,
362,
297,
283,
1932,
7,
1622,
523,
2986,
63,
2593,
26,
272,
1369,
26,
489,
446,
3101,
2653,
14,
272,
1415,
26,
3055,
272,
849,
26,
1616,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
7117,
199,
5983,
26,
523,
446,
2622,
4440,
314,
445,
8,
1259,
9,
3555,
1159,
2897,
1083,
340,
6235,
787,
440,
272,
2741,
701,
314,
1511,
445,
8,
1246,
63,
633,
395,
445,
8,
1246,
63,
498,
395,
445,
8,
1246,
63,
4731,
680,
272,
11595,
365,
1586,
687,
9978,
9918,
12,
315,
314,
2569,
1865,
14,
272,
446,
710,
445,
8,
29495,
17014,
63,
21054,
395,
445,
8,
29495,
17014,
63,
3078,
395,
445,
8,
29495,
17014,
63,
12961,
9,
436,
489,
445,
8,
29495,
17014,
63,
9977,
680,
445,
8,
29495,
17014,
63,
8899,
9,
3734,
2860,
14,
272,
446,
437,
445,
8,
29495,
17014,
63,
5569,
9,
3734,
1750,
20686,
370,
376,
445,
13417,
2730,
9,
570,
12,
272,
446,
437,
445,
8,
4091,
2340,
14,
2730,
9,
570,
315,
314,
1453,
6449,
2082,
14,
272,
446,
437,
445,
13417,
4091,
2340,
14,
2730,
9,
570,
315,
314,
4390,
5629,
2082,
14,
489,
1666,
4178,
921,
5031,
14,
957,
15,
476,
79,
3467,
15,
1259,
367,
1655,
2556,
14,
523,
446,
961,
859,
5171,
1104,
818,
14,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
andrey-malets/web-page-replay
|
third_party/dns/ipv4.py
|
250
|
1365
|
# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation 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 NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM 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.
"""IPv4 helper functions."""
import socket
import sys
if sys.hexversion < 0x02030000 or sys.platform == 'win32':
#
# Some versions of Python 2.2 have an inet_aton which rejects
# the valid IP address '255.255.255.255'. It appears this
# problem is still present on the Win32 platform even in 2.3.
# We'll work around the problem.
#
def inet_aton(text):
if text == '255.255.255.255':
return '\xff' * 4
else:
return socket.inet_aton(text)
else:
inet_aton = socket.inet_aton
inet_ntoa = socket.inet_ntoa
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
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,
4825,
4896,
2639,
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,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
12179,
20,
5922,
3423,
1041,
199,
199,
646,
2838,
199,
646,
984,
199,
199,
692,
984,
14,
4097,
1023,
665,
378,
88,
996,
1644,
993,
503,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
327,
272,
327,
6601,
5459,
402,
2018,
499,
14,
18,
1172,
376,
17260,
63,
25685,
1314,
17100,
83,
272,
327,
314,
1686,
3531,
2287,
283,
2299,
14,
2299,
14,
2299,
14,
2299,
1370,
221,
2779,
11337,
642,
272,
327,
5160,
365,
5139,
3451,
641,
314,
13036,
708,
4298,
2755,
315,
499,
14,
19,
14,
272,
327,
2136,
7171,
1736,
6818,
314,
5160,
14,
272,
327,
272,
347,
17260,
63,
25685,
8,
505,
304,
267,
340,
1318,
508,
283,
2299,
14,
2299,
14,
2299,
14,
2299,
356,
288,
372,
1557,
3581,
7,
627,
841,
267,
587,
26,
288,
372,
2838,
14,
10811,
63,
25685,
8,
505,
9,
199,
2836,
26,
272,
17260,
63,
25685,
275,
2838,
14,
10811,
63,
25685,
199,
199,
10811,
63,
343,
20047,
275,
2838,
14,
10811,
63,
343,
20047,
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
] |
[
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
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,
4825,
4896,
2639,
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,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
12179,
20,
5922,
3423,
1041,
199,
199,
646,
2838,
199,
646,
984,
199,
199,
692,
984,
14,
4097,
1023,
665,
378,
88,
996,
1644,
993,
503,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
327,
272,
327,
6601,
5459,
402,
2018,
499,
14,
18,
1172,
376,
17260,
63,
25685,
1314,
17100,
83,
272,
327,
314,
1686,
3531,
2287,
283,
2299,
14,
2299,
14,
2299,
14,
2299,
1370,
221,
2779,
11337,
642,
272,
327,
5160,
365,
5139,
3451,
641,
314,
13036,
708,
4298,
2755,
315,
499,
14,
19,
14,
272,
327,
2136,
7171,
1736,
6818,
314,
5160,
14,
272,
327,
272,
347,
17260,
63,
25685,
8,
505,
304,
267,
340,
1318,
508,
283,
2299,
14,
2299,
14,
2299,
14,
2299,
356,
288,
372,
1557,
3581,
7,
627,
841,
267,
587,
26,
288,
372,
2838,
14,
10811,
63,
25685,
8,
505,
9,
199,
2836,
26,
272,
17260,
63,
25685,
275,
2838,
14,
10811,
63,
25685,
199,
199,
10811,
63,
343,
20047,
275,
2838,
14,
10811,
63,
343,
20047,
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,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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
] |
heran7/edx-platform
|
lms/djangoapps/courseware/features/common.py
|
9
|
6423
|
# pylint: disable=C0111
# pylint: disable=W0621
from __future__ import absolute_import
from lettuce import world, step
from django.contrib.auth.models import User
from student.models import CourseEnrollment
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.course_module import CourseDescriptor
from courseware.courses import get_course_by_id
from xmodule import seq_module, vertical_module
from logging import getLogger
logger = getLogger(__name__)
@step(u'The course "([^"]*)" exists$')
def create_course(_step, course):
# First clear the modulestore so we don't try to recreate
# the same course twice
# This also ensures that the necessary templates are loaded
world.clear_courses()
# Create the course
# We always use the same org and display name,
# but vary the course identifier (e.g. 600x or 191x)
world.scenario_dict['COURSE'] = world.CourseFactory.create(org='edx',
number=course,
display_name='Test Course')
# Add a section to the course to contain problems
world.scenario_dict['SECTION'] = world.ItemFactory.create(parent_location=world.scenario_dict['COURSE'].location,
display_name='Test Section')
world.ItemFactory.create(
parent_location=world.scenario_dict['SECTION'].location,
category='sequential',
display_name='Test Section')
@step(u'I am registered for the course "([^"]*)"$')
def i_am_registered_for_the_course(step, course):
# Create the course
create_course(step, course)
# Create the user
world.create_user('robot', 'test')
u = User.objects.get(username='robot')
# If the user is not already enrolled, enroll the user.
# TODO: change to factory
CourseEnrollment.enroll(u, course_id(course))
world.log_in(username='robot', password='test')
@step(u'The course "([^"]*)" has extra tab "([^"]*)"$')
def add_tab_to_course(_step, course, extra_tab_name):
world.ItemFactory.create(
parent_location=course_location(course),
category="static_tab",
display_name=str(extra_tab_name))
@step(u'I am in a course$')
def go_into_course(step):
step.given('I am registered for the course "6.002x"')
step.given('And I am logged in')
step.given('And I click on View Courseware')
def course_id(course_num):
return "%s/%s/%s" % (world.scenario_dict['COURSE'].org, course_num,
world.scenario_dict['COURSE'].display_name.replace(" ", "_"))
def course_location(course_num):
return Location(loc_or_tag="i4x",
org=world.scenario_dict['COURSE'].org,
course=course_num,
category='course',
name=world.scenario_dict['COURSE'].display_name.replace(" ", "_"))
def section_location(course_num):
return Location(loc_or_tag="i4x",
org=world.scenario_dict['COURSE'].org,
course=course_num,
category='sequential',
name=world.scenario_dict['SECTION'].display_name.replace(" ", "_"))
def get_courses():
'''
Returns dict of lists of courses available, keyed by course.org (ie university).
Courses are sorted by course.number.
'''
courses = [c for c in modulestore().get_courses()
if isinstance(c, CourseDescriptor)]
courses = sorted(courses, key=lambda course: course.number)
return courses
def get_courseware_with_tabs(course_id):
"""
Given a course_id (string), return a courseware array of dictionaries for the
top three levels of navigation. Same as get_courseware() except include
the tabs on the right hand main navigation page.
This hides the appropriate courseware as defined by the hide_from_toc field:
chapter.hide_from_toc
Example:
[{
'chapter_name': 'Overview',
'sections': [{
'clickable_tab_count': 0,
'section_name': 'Welcome',
'tab_classes': []
}, {
'clickable_tab_count': 1,
'section_name': 'System Usage Sequence',
'tab_classes': ['VerticalDescriptor']
}, {
'clickable_tab_count': 0,
'section_name': 'Lab0: Using the tools',
'tab_classes': ['HtmlDescriptor', 'HtmlDescriptor', 'CapaDescriptor']
}, {
'clickable_tab_count': 0,
'section_name': 'Circuit Sandbox',
'tab_classes': []
}]
}, {
'chapter_name': 'Week 1',
'sections': [{
'clickable_tab_count': 4,
'section_name': 'Administrivia and Circuit Elements',
'tab_classes': ['VerticalDescriptor', 'VerticalDescriptor', 'VerticalDescriptor', 'VerticalDescriptor']
}, {
'clickable_tab_count': 0,
'section_name': 'Basic Circuit Analysis',
'tab_classes': ['CapaDescriptor', 'CapaDescriptor', 'CapaDescriptor']
}, {
'clickable_tab_count': 0,
'section_name': 'Resistor Divider',
'tab_classes': []
}, {
'clickable_tab_count': 0,
'section_name': 'Week 1 Tutorials',
'tab_classes': []
}]
}, {
'chapter_name': 'Midterm Exam',
'sections': [{
'clickable_tab_count': 2,
'section_name': 'Midterm Exam',
'tab_classes': ['VerticalDescriptor', 'VerticalDescriptor']
}]
}]
"""
course = get_course_by_id(course_id)
chapters = [chapter for chapter in course.get_children() if not chapter.hide_from_toc]
courseware = [{'chapter_name': c.display_name_with_default,
'sections': [{'section_name': s.display_name_with_default,
'clickable_tab_count': len(s.get_children()) if (type(s) == seq_module.SequenceDescriptor) else 0,
'tabs': [{'children_count': len(t.get_children()) if (type(t) == vertical_module.VerticalDescriptor) else 0,
'class': t.__class__.__name__}
for t in s.get_children()]}
for s in c.get_children() if not s.hide_from_toc]}
for c in chapters]
return courseware
|
agpl-3.0
|
[
3,
4287,
26,
3507,
29,
35,
28107,
199,
3,
4287,
26,
3507,
29,
55,
1690,
2025,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
4691,
84,
3683,
492,
6701,
12,
3650,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
9872,
14,
10012,
492,
12625,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
63,
991,
63,
344,
199,
504,
9872,
492,
5412,
63,
578,
12,
13763,
63,
578,
199,
199,
504,
2050,
492,
28138,
199,
2921,
275,
28138,
3460,
354,
3368,
421,
199,
32,
2926,
8,
85,
7,
1918,
2518,
32397,
25952,
3495,
9988,
199,
318,
1218,
63,
1972,
1547,
2926,
12,
2518,
304,
339,
327,
7758,
5436,
314,
10996,
880,
781,
2793,
1133,
862,
370,
23959,
272,
327,
314,
2011,
2518,
13373,
272,
327,
961,
2597,
15620,
626,
314,
5784,
7009,
787,
6511,
272,
6701,
14,
3584,
63,
11653,
342,
339,
327,
2790,
314,
2518,
272,
327,
2136,
3544,
675,
314,
2011,
5981,
436,
2929,
536,
12,
272,
327,
1325,
17083,
314,
2518,
5148,
334,
69,
14,
71,
14,
11624,
88,
503,
413,
3328,
88,
9,
272,
6701,
14,
13444,
63,
807,
459,
15552,
418,
275,
6701,
14,
6979,
2927,
14,
981,
8,
1308,
534,
8268,
297,
3147,
1329,
29,
1972,
12,
3147,
2929,
63,
354,
534,
774,
5531,
358,
339,
327,
2654,
282,
3420,
370,
314,
2518,
370,
1395,
8826,
272,
6701,
14,
13444,
63,
807,
459,
13835,
418,
275,
6701,
14,
2081,
2927,
14,
981,
8,
1708,
63,
1985,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1985,
12,
4318,
2929,
63,
354,
534,
774,
15247,
358,
339,
6701,
14,
2081,
2927,
14,
981,
8,
267,
1676,
63,
1985,
29,
7617,
14,
13444,
63,
807,
459,
13835,
2278,
1985,
12,
267,
4637,
534,
16211,
297,
267,
2929,
63,
354,
534,
774,
15247,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
8140,
7264,
367,
314,
2518,
32397,
25952,
9988,
199,
318,
284,
63,
455,
63,
11616,
63,
509,
63,
1589,
63,
1972,
8,
2926,
12,
2518,
304,
272,
327,
2790,
314,
2518,
272,
1218,
63,
1972,
8,
2926,
12,
2518,
9,
339,
327,
2790,
314,
922,
272,
6701,
14,
981,
63,
751,
360,
9751,
297,
283,
396,
358,
272,
399,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
9751,
358,
339,
327,
982,
314,
922,
365,
440,
2575,
26802,
12,
26361,
314,
922,
14,
272,
327,
3254,
26,
1570,
370,
6434,
272,
18946,
14,
14695,
8,
85,
12,
2518,
63,
344,
8,
1972,
430,
339,
6701,
14,
793,
63,
262,
8,
2473,
534,
9751,
297,
2505,
534,
396,
358,
421,
199,
32,
2926,
8,
85,
7,
1918,
2518,
32397,
25952,
965,
2402,
5174,
32397,
25952,
9988,
199,
318,
1050,
63,
2902,
63,
475,
63,
1972,
1547,
2926,
12,
2518,
12,
2402,
63,
2902,
63,
354,
304,
272,
6701,
14,
2081,
2927,
14,
981,
8,
267,
1676,
63,
1985,
29,
1972,
63,
1985,
8,
1972,
395,
267,
4637,
628,
1986,
63,
2902,
401,
267,
2929,
63,
354,
29,
495,
8,
2911,
63,
2902,
63,
354,
430,
421,
199,
32,
2926,
8,
85,
7,
41,
8140,
315,
282,
2518,
9988,
199,
318,
2621,
63,
9924,
63,
1972,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
8140,
7264,
367,
314,
2518,
298,
22,
14,
7432,
88,
9008,
272,
3650,
14,
11809,
360,
3325,
473,
8140,
10367,
315,
358,
272,
3650,
14,
11809,
360,
3325,
473,
8968,
641,
10935,
5531,
1068,
358,
421,
199,
318,
2518,
63,
344,
8,
1972,
63,
1507,
304,
272,
372,
2071,
83,
3149,
83,
3149,
83,
2,
450,
334,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1308,
12,
2518,
63,
1507,
12,
586,
6701,
14,
13444,
63,
807,
459,
15552,
2278,
2918,
63,
354,
14,
1814,
480,
3872,
2668,
2237,
421,
199,
318,
2518,
63,
1985,
8,
1972,
63,
1507,
304,
272,
372,
12625,
8,
2102,
63,
269,
63,
1450,
628,
73,
20,
88,
401,
490,
5981,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1308,
12,
490,
2518,
29,
1972,
63,
1507,
12,
490,
4637,
534,
1972,
297,
490,
536,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
2918,
63,
354,
14,
1814,
480,
3872,
2668,
2237,
421,
199,
318,
3420,
63,
1985,
8,
1972,
63,
1507,
304,
272,
372,
12625,
8,
2102,
63,
269,
63,
1450,
628,
73,
20,
88,
401,
490,
5981,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1308,
12,
490,
2518,
29,
1972,
63,
1507,
12,
490,
4637,
534,
16211,
297,
490,
536,
29,
7617,
14,
13444,
63,
807,
459,
13835,
2278,
2918,
63,
354,
14,
1814,
480,
3872,
2668,
2237,
421,
199,
318,
664,
63,
11653,
837,
272,
1449,
272,
1803,
1211,
402,
5548,
402,
13588,
2808,
12,
19272,
701,
2518,
14,
1308,
334,
1873,
625,
14111,
680,
272,
445,
567,
874,
787,
3355,
701,
2518,
14,
1955,
14,
272,
1449,
272,
13588,
275,
359,
67,
367,
286,
315,
10996,
1252,
362,
63,
11653,
342,
2049,
340,
1228,
8,
67,
12,
5531,
4311,
1874,
272,
13588,
275,
3355,
8,
11653,
12,
790,
29,
2734,
2518,
26,
2518,
14,
1955,
9,
272,
372,
13588,
421,
199,
318,
664,
63,
17744,
63,
1045,
63,
8741,
8,
1972,
63,
344,
304,
272,
408,
272,
9138,
282,
2518,
63,
344,
334,
875,
395,
372,
282,
20736,
1625,
402,
11196,
367,
314,
272,
2746,
7795,
11106,
402,
19191,
14,
14766,
465,
664,
63,
17744,
342,
871,
2387,
272,
314,
12187,
641,
314,
2451,
4926,
2446,
19191,
2034,
14,
339,
961,
13714,
83,
314,
5827,
20736,
465,
3247,
701,
314,
13714,
63,
504,
63,
13255,
901,
26,
272,
17044,
14,
8191,
63,
504,
63,
13255,
339,
5679,
26,
339,
8910,
267,
283,
11316,
63,
354,
356,
283,
28077,
297,
267,
283,
7786,
356,
8910,
288,
283,
4891,
461,
63,
2902,
63,
835,
356,
378,
12,
288,
283,
2792,
63,
354,
356,
283,
24679,
297,
288,
283,
2902,
63,
2888,
356,
942,
267,
1660,
469,
288,
283,
4891,
461,
63,
2902,
63,
835,
356,
413,
12,
288
] |
[
4287,
26,
3507,
29,
35,
28107,
199,
3,
4287,
26,
3507,
29,
55,
1690,
2025,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
4691,
84,
3683,
492,
6701,
12,
3650,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
6474,
14,
992,
492,
18946,
199,
504,
9872,
14,
10012,
492,
12625,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
20736,
14,
11653,
492,
664,
63,
1972,
63,
991,
63,
344,
199,
504,
9872,
492,
5412,
63,
578,
12,
13763,
63,
578,
199,
199,
504,
2050,
492,
28138,
199,
2921,
275,
28138,
3460,
354,
3368,
421,
199,
32,
2926,
8,
85,
7,
1918,
2518,
32397,
25952,
3495,
9988,
199,
318,
1218,
63,
1972,
1547,
2926,
12,
2518,
304,
339,
327,
7758,
5436,
314,
10996,
880,
781,
2793,
1133,
862,
370,
23959,
272,
327,
314,
2011,
2518,
13373,
272,
327,
961,
2597,
15620,
626,
314,
5784,
7009,
787,
6511,
272,
6701,
14,
3584,
63,
11653,
342,
339,
327,
2790,
314,
2518,
272,
327,
2136,
3544,
675,
314,
2011,
5981,
436,
2929,
536,
12,
272,
327,
1325,
17083,
314,
2518,
5148,
334,
69,
14,
71,
14,
11624,
88,
503,
413,
3328,
88,
9,
272,
6701,
14,
13444,
63,
807,
459,
15552,
418,
275,
6701,
14,
6979,
2927,
14,
981,
8,
1308,
534,
8268,
297,
3147,
1329,
29,
1972,
12,
3147,
2929,
63,
354,
534,
774,
5531,
358,
339,
327,
2654,
282,
3420,
370,
314,
2518,
370,
1395,
8826,
272,
6701,
14,
13444,
63,
807,
459,
13835,
418,
275,
6701,
14,
2081,
2927,
14,
981,
8,
1708,
63,
1985,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1985,
12,
4318,
2929,
63,
354,
534,
774,
15247,
358,
339,
6701,
14,
2081,
2927,
14,
981,
8,
267,
1676,
63,
1985,
29,
7617,
14,
13444,
63,
807,
459,
13835,
2278,
1985,
12,
267,
4637,
534,
16211,
297,
267,
2929,
63,
354,
534,
774,
15247,
358,
421,
199,
32,
2926,
8,
85,
7,
41,
8140,
7264,
367,
314,
2518,
32397,
25952,
9988,
199,
318,
284,
63,
455,
63,
11616,
63,
509,
63,
1589,
63,
1972,
8,
2926,
12,
2518,
304,
272,
327,
2790,
314,
2518,
272,
1218,
63,
1972,
8,
2926,
12,
2518,
9,
339,
327,
2790,
314,
922,
272,
6701,
14,
981,
63,
751,
360,
9751,
297,
283,
396,
358,
272,
399,
275,
2876,
14,
1462,
14,
362,
8,
2473,
534,
9751,
358,
339,
327,
982,
314,
922,
365,
440,
2575,
26802,
12,
26361,
314,
922,
14,
272,
327,
3254,
26,
1570,
370,
6434,
272,
18946,
14,
14695,
8,
85,
12,
2518,
63,
344,
8,
1972,
430,
339,
6701,
14,
793,
63,
262,
8,
2473,
534,
9751,
297,
2505,
534,
396,
358,
421,
199,
32,
2926,
8,
85,
7,
1918,
2518,
32397,
25952,
965,
2402,
5174,
32397,
25952,
9988,
199,
318,
1050,
63,
2902,
63,
475,
63,
1972,
1547,
2926,
12,
2518,
12,
2402,
63,
2902,
63,
354,
304,
272,
6701,
14,
2081,
2927,
14,
981,
8,
267,
1676,
63,
1985,
29,
1972,
63,
1985,
8,
1972,
395,
267,
4637,
628,
1986,
63,
2902,
401,
267,
2929,
63,
354,
29,
495,
8,
2911,
63,
2902,
63,
354,
430,
421,
199,
32,
2926,
8,
85,
7,
41,
8140,
315,
282,
2518,
9988,
199,
318,
2621,
63,
9924,
63,
1972,
8,
2926,
304,
272,
3650,
14,
11809,
360,
41,
8140,
7264,
367,
314,
2518,
298,
22,
14,
7432,
88,
9008,
272,
3650,
14,
11809,
360,
3325,
473,
8140,
10367,
315,
358,
272,
3650,
14,
11809,
360,
3325,
473,
8968,
641,
10935,
5531,
1068,
358,
421,
199,
318,
2518,
63,
344,
8,
1972,
63,
1507,
304,
272,
372,
2071,
83,
3149,
83,
3149,
83,
2,
450,
334,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1308,
12,
2518,
63,
1507,
12,
586,
6701,
14,
13444,
63,
807,
459,
15552,
2278,
2918,
63,
354,
14,
1814,
480,
3872,
2668,
2237,
421,
199,
318,
2518,
63,
1985,
8,
1972,
63,
1507,
304,
272,
372,
12625,
8,
2102,
63,
269,
63,
1450,
628,
73,
20,
88,
401,
490,
5981,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1308,
12,
490,
2518,
29,
1972,
63,
1507,
12,
490,
4637,
534,
1972,
297,
490,
536,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
2918,
63,
354,
14,
1814,
480,
3872,
2668,
2237,
421,
199,
318,
3420,
63,
1985,
8,
1972,
63,
1507,
304,
272,
372,
12625,
8,
2102,
63,
269,
63,
1450,
628,
73,
20,
88,
401,
490,
5981,
29,
7617,
14,
13444,
63,
807,
459,
15552,
2278,
1308,
12,
490,
2518,
29,
1972,
63,
1507,
12,
490,
4637,
534,
16211,
297,
490,
536,
29,
7617,
14,
13444,
63,
807,
459,
13835,
2278,
2918,
63,
354,
14,
1814,
480,
3872,
2668,
2237,
421,
199,
318,
664,
63,
11653,
837,
272,
1449,
272,
1803,
1211,
402,
5548,
402,
13588,
2808,
12,
19272,
701,
2518,
14,
1308,
334,
1873,
625,
14111,
680,
272,
445,
567,
874,
787,
3355,
701,
2518,
14,
1955,
14,
272,
1449,
272,
13588,
275,
359,
67,
367,
286,
315,
10996,
1252,
362,
63,
11653,
342,
2049,
340,
1228,
8,
67,
12,
5531,
4311,
1874,
272,
13588,
275,
3355,
8,
11653,
12,
790,
29,
2734,
2518,
26,
2518,
14,
1955,
9,
272,
372,
13588,
421,
199,
318,
664,
63,
17744,
63,
1045,
63,
8741,
8,
1972,
63,
344,
304,
272,
408,
272,
9138,
282,
2518,
63,
344,
334,
875,
395,
372,
282,
20736,
1625,
402,
11196,
367,
314,
272,
2746,
7795,
11106,
402,
19191,
14,
14766,
465,
664,
63,
17744,
342,
871,
2387,
272,
314,
12187,
641,
314,
2451,
4926,
2446,
19191,
2034,
14,
339,
961,
13714,
83,
314,
5827,
20736,
465,
3247,
701,
314,
13714,
63,
504,
63,
13255,
901,
26,
272,
17044,
14,
8191,
63,
504,
63,
13255,
339,
5679,
26,
339,
8910,
267,
283,
11316,
63,
354,
356,
283,
28077,
297,
267,
283,
7786,
356,
8910,
288,
283,
4891,
461,
63,
2902,
63,
835,
356,
378,
12,
288,
283,
2792,
63,
354,
356,
283,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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
] |
xindus40223115/w16b_test
|
static/Brython3.1.1-20150328-091302/Lib/multiprocessing/pool.py
|
694
|
23263
|
#
# Module providing the `Pool` class for managing a process pool
#
# multiprocessing/pool.py
#
# Copyright (c) 2006-2008, R Oudkerk
# Licensed to PSF under a Contributor Agreement.
#
__all__ = ['Pool']
#
# Imports
#
import threading
import queue
import itertools
import collections
import time
from multiprocessing import Process, cpu_count, TimeoutError
from multiprocessing.util import Finalize, debug
#
# Constants representing the state of a pool
#
RUN = 0
CLOSE = 1
TERMINATE = 2
#
# Miscellaneous
#
job_counter = itertools.count()
def mapstar(args):
return list(map(*args))
def starmapstar(args):
return list(itertools.starmap(args[0], args[1]))
#
# Code run by worker processes
#
class MaybeEncodingError(Exception):
"""Wraps possible unpickleable errors, so they can be
safely sent through the socket."""
def __init__(self, exc, value):
self.exc = repr(exc)
self.value = repr(value)
super(MaybeEncodingError, self).__init__(self.exc, self.value)
def __str__(self):
return "Error sending result: '%s'. Reason: '%s'" % (self.value,
self.exc)
def __repr__(self):
return "<MaybeEncodingError: %s>" % str(self)
def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None):
assert maxtasks is None or (type(maxtasks) == int and maxtasks > 0)
put = outqueue.put
get = inqueue.get
if hasattr(inqueue, '_writer'):
inqueue._writer.close()
outqueue._reader.close()
if initializer is not None:
initializer(*initargs)
completed = 0
while maxtasks is None or (maxtasks and completed < maxtasks):
try:
task = get()
except (EOFError, IOError):
debug('worker got EOFError or IOError -- exiting')
break
if task is None:
debug('worker got sentinel -- exiting')
break
job, i, func, args, kwds = task
try:
result = (True, func(*args, **kwds))
except Exception as e:
result = (False, e)
try:
put((job, i, result))
except Exception as e:
wrapped = MaybeEncodingError(e, result[1])
debug("Possible encoding error while sending result: %s" % (
wrapped))
put((job, i, (False, wrapped)))
completed += 1
debug('worker exiting after %d tasks' % completed)
#
# Class representing a process pool
#
class Pool(object):
'''
Class which supports an async version of applying functions to arguments.
'''
Process = Process
def __init__(self, processes=None, initializer=None, initargs=(),
maxtasksperchild=None):
self._setup_queues()
self._taskqueue = queue.Queue()
self._cache = {}
self._state = RUN
self._maxtasksperchild = maxtasksperchild
self._initializer = initializer
self._initargs = initargs
if processes is None:
try:
processes = cpu_count()
except NotImplementedError:
processes = 1
if processes < 1:
raise ValueError("Number of processes must be at least 1")
if initializer is not None and not callable(initializer):
raise TypeError('initializer must be a callable')
self._processes = processes
self._pool = []
self._repopulate_pool()
self._worker_handler = threading.Thread(
target=Pool._handle_workers,
args=(self, )
)
self._worker_handler.daemon = True
self._worker_handler._state = RUN
self._worker_handler.start()
self._task_handler = threading.Thread(
target=Pool._handle_tasks,
args=(self._taskqueue, self._quick_put, self._outqueue, self._pool)
)
self._task_handler.daemon = True
self._task_handler._state = RUN
self._task_handler.start()
self._result_handler = threading.Thread(
target=Pool._handle_results,
args=(self._outqueue, self._quick_get, self._cache)
)
self._result_handler.daemon = True
self._result_handler._state = RUN
self._result_handler.start()
self._terminate = Finalize(
self, self._terminate_pool,
args=(self._taskqueue, self._inqueue, self._outqueue, self._pool,
self._worker_handler, self._task_handler,
self._result_handler, self._cache),
exitpriority=15
)
def _join_exited_workers(self):
"""Cleanup after any worker processes which have exited due to reaching
their specified lifetime. Returns True if any workers were cleaned up.
"""
cleaned = False
for i in reversed(range(len(self._pool))):
worker = self._pool[i]
if worker.exitcode is not None:
# worker exited
debug('cleaning up worker %d' % i)
worker.join()
cleaned = True
del self._pool[i]
return cleaned
def _repopulate_pool(self):
"""Bring the number of pool processes up to the specified number,
for use after reaping workers which have exited.
"""
for i in range(self._processes - len(self._pool)):
w = self.Process(target=worker,
args=(self._inqueue, self._outqueue,
self._initializer,
self._initargs, self._maxtasksperchild)
)
self._pool.append(w)
w.name = w.name.replace('Process', 'PoolWorker')
w.daemon = True
w.start()
debug('added worker')
def _maintain_pool(self):
"""Clean up any exited workers and start replacements for them.
"""
if self._join_exited_workers():
self._repopulate_pool()
def _setup_queues(self):
from .queues import SimpleQueue
self._inqueue = SimpleQueue()
self._outqueue = SimpleQueue()
self._quick_put = self._inqueue._writer.send
self._quick_get = self._outqueue._reader.recv
def apply(self, func, args=(), kwds={}):
'''
Equivalent of `func(*args, **kwds)`.
'''
assert self._state == RUN
return self.apply_async(func, args, kwds).get()
def map(self, func, iterable, chunksize=None):
'''
Apply `func` to each element in `iterable`, collecting the results
in a list that is returned.
'''
return self._map_async(func, iterable, mapstar, chunksize).get()
def starmap(self, func, iterable, chunksize=None):
'''
Like `map()` method but the elements of the `iterable` are expected to
be iterables as well and will be unpacked as arguments. Hence
`func` and (a, b) becomes func(a, b).
'''
return self._map_async(func, iterable, starmapstar, chunksize).get()
def starmap_async(self, func, iterable, chunksize=None, callback=None,
error_callback=None):
'''
Asynchronous version of `starmap()` method.
'''
return self._map_async(func, iterable, starmapstar, chunksize,
callback, error_callback)
def imap(self, func, iterable, chunksize=1):
'''
Equivalent of `map()` -- can be MUCH slower than `Pool.map()`.
'''
if self._state != RUN:
raise ValueError("Pool not running")
if chunksize == 1:
result = IMapIterator(self._cache)
self._taskqueue.put((((result._job, i, func, (x,), {})
for i, x in enumerate(iterable)), result._set_length))
return result
else:
assert chunksize > 1
task_batches = Pool._get_tasks(func, iterable, chunksize)
result = IMapIterator(self._cache)
self._taskqueue.put((((result._job, i, mapstar, (x,), {})
for i, x in enumerate(task_batches)), result._set_length))
return (item for chunk in result for item in chunk)
def imap_unordered(self, func, iterable, chunksize=1):
'''
Like `imap()` method but ordering of results is arbitrary.
'''
if self._state != RUN:
raise ValueError("Pool not running")
if chunksize == 1:
result = IMapUnorderedIterator(self._cache)
self._taskqueue.put((((result._job, i, func, (x,), {})
for i, x in enumerate(iterable)), result._set_length))
return result
else:
assert chunksize > 1
task_batches = Pool._get_tasks(func, iterable, chunksize)
result = IMapUnorderedIterator(self._cache)
self._taskqueue.put((((result._job, i, mapstar, (x,), {})
for i, x in enumerate(task_batches)), result._set_length))
return (item for chunk in result for item in chunk)
def apply_async(self, func, args=(), kwds={}, callback=None,
error_callback=None):
'''
Asynchronous version of `apply()` method.
'''
if self._state != RUN:
raise ValueError("Pool not running")
result = ApplyResult(self._cache, callback, error_callback)
self._taskqueue.put(([(result._job, None, func, args, kwds)], None))
return result
def map_async(self, func, iterable, chunksize=None, callback=None,
error_callback=None):
'''
Asynchronous version of `map()` method.
'''
return self._map_async(func, iterable, mapstar, chunksize, callback,
error_callback)
def _map_async(self, func, iterable, mapper, chunksize=None, callback=None,
error_callback=None):
'''
Helper function to implement map, starmap and their async counterparts.
'''
if self._state != RUN:
raise ValueError("Pool not running")
if not hasattr(iterable, '__len__'):
iterable = list(iterable)
if chunksize is None:
chunksize, extra = divmod(len(iterable), len(self._pool) * 4)
if extra:
chunksize += 1
if len(iterable) == 0:
chunksize = 0
task_batches = Pool._get_tasks(func, iterable, chunksize)
result = MapResult(self._cache, chunksize, len(iterable), callback,
error_callback=error_callback)
self._taskqueue.put((((result._job, i, mapper, (x,), {})
for i, x in enumerate(task_batches)), None))
return result
@staticmethod
def _handle_workers(pool):
thread = threading.current_thread()
# Keep maintaining workers until the cache gets drained, unless the pool
# is terminated.
while thread._state == RUN or (pool._cache and thread._state != TERMINATE):
pool._maintain_pool()
time.sleep(0.1)
# send sentinel to stop workers
pool._taskqueue.put(None)
debug('worker handler exiting')
@staticmethod
def _handle_tasks(taskqueue, put, outqueue, pool):
thread = threading.current_thread()
for taskseq, set_length in iter(taskqueue.get, None):
i = -1
for i, task in enumerate(taskseq):
if thread._state:
debug('task handler found thread._state != RUN')
break
try:
put(task)
except IOError:
debug('could not put task on queue')
break
else:
if set_length:
debug('doing set_length()')
set_length(i+1)
continue
break
else:
debug('task handler got sentinel')
try:
# tell result handler to finish when cache is empty
debug('task handler sending sentinel to result handler')
outqueue.put(None)
# tell workers there is no more work
debug('task handler sending sentinel to workers')
for p in pool:
put(None)
except IOError:
debug('task handler got IOError when sending sentinels')
debug('task handler exiting')
@staticmethod
def _handle_results(outqueue, get, cache):
thread = threading.current_thread()
while 1:
try:
task = get()
except (IOError, EOFError):
debug('result handler got EOFError/IOError -- exiting')
return
if thread._state:
assert thread._state == TERMINATE
debug('result handler found thread._state=TERMINATE')
break
if task is None:
debug('result handler got sentinel')
break
job, i, obj = task
try:
cache[job]._set(i, obj)
except KeyError:
pass
while cache and thread._state != TERMINATE:
try:
task = get()
except (IOError, EOFError):
debug('result handler got EOFError/IOError -- exiting')
return
if task is None:
debug('result handler ignoring extra sentinel')
continue
job, i, obj = task
try:
cache[job]._set(i, obj)
except KeyError:
pass
if hasattr(outqueue, '_reader'):
debug('ensuring that outqueue is not full')
# If we don't make room available in outqueue then
# attempts to add the sentinel (None) to outqueue may
# block. There is guaranteed to be no more than 2 sentinels.
try:
for i in range(10):
if not outqueue._reader.poll():
break
get()
except (IOError, EOFError):
pass
debug('result handler exiting: len(cache)=%s, thread._state=%s',
len(cache), thread._state)
@staticmethod
def _get_tasks(func, it, size):
it = iter(it)
while 1:
x = tuple(itertools.islice(it, size))
if not x:
return
yield (func, x)
def __reduce__(self):
raise NotImplementedError(
'pool objects cannot be passed between processes or pickled'
)
def close(self):
debug('closing pool')
if self._state == RUN:
self._state = CLOSE
self._worker_handler._state = CLOSE
def terminate(self):
debug('terminating pool')
self._state = TERMINATE
self._worker_handler._state = TERMINATE
self._terminate()
def join(self):
debug('joining pool')
assert self._state in (CLOSE, TERMINATE)
self._worker_handler.join()
self._task_handler.join()
self._result_handler.join()
for p in self._pool:
p.join()
@staticmethod
def _help_stuff_finish(inqueue, task_handler, size):
# task_handler may be blocked trying to put items on inqueue
debug('removing tasks from inqueue until task handler finished')
inqueue._rlock.acquire()
while task_handler.is_alive() and inqueue._reader.poll():
inqueue._reader.recv()
time.sleep(0)
@classmethod
def _terminate_pool(cls, taskqueue, inqueue, outqueue, pool,
worker_handler, task_handler, result_handler, cache):
# this is guaranteed to only be called once
debug('finalizing pool')
worker_handler._state = TERMINATE
task_handler._state = TERMINATE
debug('helping task handler/workers to finish')
cls._help_stuff_finish(inqueue, task_handler, len(pool))
assert result_handler.is_alive() or len(cache) == 0
result_handler._state = TERMINATE
outqueue.put(None) # sentinel
# We must wait for the worker handler to exit before terminating
# workers because we don't want workers to be restarted behind our back.
debug('joining worker handler')
if threading.current_thread() is not worker_handler:
worker_handler.join()
# Terminate workers which haven't already finished.
if pool and hasattr(pool[0], 'terminate'):
debug('terminating workers')
for p in pool:
if p.exitcode is None:
p.terminate()
debug('joining task handler')
if threading.current_thread() is not task_handler:
task_handler.join()
debug('joining result handler')
if threading.current_thread() is not result_handler:
result_handler.join()
if pool and hasattr(pool[0], 'terminate'):
debug('joining pool workers')
for p in pool:
if p.is_alive():
# worker has not yet exited
debug('cleaning up worker %d' % p.pid)
p.join()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.terminate()
#
# Class whose instances are returned by `Pool.apply_async()`
#
class ApplyResult(object):
def __init__(self, cache, callback, error_callback):
self._event = threading.Event()
self._job = next(job_counter)
self._cache = cache
self._callback = callback
self._error_callback = error_callback
cache[self._job] = self
def ready(self):
return self._event.is_set()
def successful(self):
assert self.ready()
return self._success
def wait(self, timeout=None):
self._event.wait(timeout)
def get(self, timeout=None):
self.wait(timeout)
if not self.ready():
raise TimeoutError
if self._success:
return self._value
else:
raise self._value
def _set(self, i, obj):
self._success, self._value = obj
if self._callback and self._success:
self._callback(self._value)
if self._error_callback and not self._success:
self._error_callback(self._value)
self._event.set()
del self._cache[self._job]
AsyncResult = ApplyResult # create alias -- see #17805
#
# Class whose instances are returned by `Pool.map_async()`
#
class MapResult(ApplyResult):
def __init__(self, cache, chunksize, length, callback, error_callback):
ApplyResult.__init__(self, cache, callback,
error_callback=error_callback)
self._success = True
self._value = [None] * length
self._chunksize = chunksize
if chunksize <= 0:
self._number_left = 0
self._event.set()
del cache[self._job]
else:
self._number_left = length//chunksize + bool(length % chunksize)
def _set(self, i, success_result):
success, result = success_result
if success:
self._value[i*self._chunksize:(i+1)*self._chunksize] = result
self._number_left -= 1
if self._number_left == 0:
if self._callback:
self._callback(self._value)
del self._cache[self._job]
self._event.set()
else:
self._success = False
self._value = result
if self._error_callback:
self._error_callback(self._value)
del self._cache[self._job]
self._event.set()
#
# Class whose instances are returned by `Pool.imap()`
#
class IMapIterator(object):
def __init__(self, cache):
self._cond = threading.Condition(threading.Lock())
self._job = next(job_counter)
self._cache = cache
self._items = collections.deque()
self._index = 0
self._length = None
self._unsorted = {}
cache[self._job] = self
def __iter__(self):
return self
def next(self, timeout=None):
self._cond.acquire()
try:
try:
item = self._items.popleft()
except IndexError:
if self._index == self._length:
raise StopIteration
self._cond.wait(timeout)
try:
item = self._items.popleft()
except IndexError:
if self._index == self._length:
raise StopIteration
raise TimeoutError
finally:
self._cond.release()
success, value = item
if success:
return value
raise value
__next__ = next # XXX
def _set(self, i, obj):
self._cond.acquire()
try:
if self._index == i:
self._items.append(obj)
self._index += 1
while self._index in self._unsorted:
obj = self._unsorted.pop(self._index)
self._items.append(obj)
self._index += 1
self._cond.notify()
else:
self._unsorted[i] = obj
if self._index == self._length:
del self._cache[self._job]
finally:
self._cond.release()
def _set_length(self, length):
self._cond.acquire()
try:
self._length = length
if self._index == self._length:
self._cond.notify()
del self._cache[self._job]
finally:
self._cond.release()
#
# Class whose instances are returned by `Pool.imap_unordered()`
#
class IMapUnorderedIterator(IMapIterator):
def _set(self, i, obj):
self._cond.acquire()
try:
self._items.append(obj)
self._index += 1
self._cond.notify()
if self._index == self._length:
del self._cache[self._job]
finally:
self._cond.release()
#
#
#
class ThreadPool(Pool):
from .dummy import Process
def __init__(self, processes=None, initializer=None, initargs=()):
Pool.__init__(self, processes, initializer, initargs)
def _setup_queues(self):
self._inqueue = queue.Queue()
self._outqueue = queue.Queue()
self._quick_put = self._inqueue.put
self._quick_get = self._outqueue.get
@staticmethod
def _help_stuff_finish(inqueue, task_handler, size):
# put sentinels at head of inqueue to make workers finish
inqueue.not_empty.acquire()
try:
inqueue.queue.clear()
inqueue.queue.extend([None] * size)
inqueue.not_empty.notify_all()
finally:
inqueue.not_empty.release()
|
gpl-3.0
|
[
3,
199,
3,
5673,
13070,
314,
658,
5453,
64,
1021,
367,
28453,
282,
2112,
4203,
199,
3,
199,
3,
12866,
15,
2293,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
8315,
13,
9300,
12,
820,
593,
1181,
2570,
75,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
3,
199,
199,
363,
452,
363,
275,
788,
5453,
418,
199,
199,
3,
199,
3,
24339,
199,
3,
199,
199,
646,
5796,
199,
646,
4126,
199,
646,
7975,
199,
646,
5055,
199,
646,
900,
199,
199,
504,
12866,
492,
7132,
12,
5033,
63,
835,
12,
31886,
199,
504,
12866,
14,
1974,
492,
21789,
794,
12,
3105,
199,
199,
3,
199,
3,
22296,
6144,
314,
1174,
402,
282,
4203,
199,
3,
199,
199,
9390,
275,
378,
199,
18219,
275,
413,
199,
28376,
1951,
275,
499,
199,
199,
3,
199,
3,
12481,
19549,
199,
3,
199,
199,
2423,
63,
5337,
275,
7975,
14,
835,
342,
199,
199,
318,
2341,
7848,
8,
589,
304,
272,
372,
769,
8,
1130,
2031,
589,
430,
199,
199,
318,
14664,
1130,
7848,
8,
589,
304,
272,
372,
769,
8,
17691,
14,
7848,
1130,
8,
589,
59,
16,
467,
1249,
59,
17,
2459,
199,
199,
3,
199,
3,
5495,
1255,
701,
7239,
10358,
199,
3,
199,
199,
533,
23038,
7630,
547,
8,
1726,
304,
272,
408,
55,
8146,
3962,
625,
8092,
461,
2552,
12,
880,
2985,
883,
506,
272,
19353,
4847,
4012,
314,
2838,
1041,
339,
347,
636,
826,
721,
277,
12,
3178,
12,
574,
304,
267,
291,
14,
2804,
275,
4700,
8,
2804,
9,
267,
291,
14,
585,
275,
4700,
8,
585,
9,
267,
1613,
8,
15586,
1235,
7630,
547,
12,
291,
2843,
826,
721,
277,
14,
2804,
12,
291,
14,
585,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
547,
10209,
754,
26,
1543,
83,
1370,
799,
2660,
26,
1543,
83,
4065,
450,
334,
277,
14,
585,
12,
18193,
291,
14,
2804,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
15586,
1235,
7630,
547,
26,
450,
83,
4335,
450,
620,
8,
277,
9,
421,
199,
318,
7239,
8,
262,
1825,
12,
734,
1825,
12,
11130,
29,
403,
12,
4205,
589,
16729,
610,
400,
813,
83,
29,
403,
304,
272,
702,
610,
400,
813,
83,
365,
488,
503,
334,
466,
8,
391,
400,
813,
83,
9,
508,
1109,
436,
610,
400,
813,
83,
690,
378,
9,
272,
5324,
275,
734,
1825,
14,
524,
272,
664,
275,
315,
1825,
14,
362,
272,
340,
2688,
8,
262,
1825,
12,
2513,
5491,
735,
267,
315,
1825,
423,
5491,
14,
1600,
342,
267,
734,
1825,
423,
5503,
14,
1600,
342,
339,
340,
11130,
365,
440,
488,
26,
267,
11130,
2031,
826,
589,
9,
339,
9709,
275,
378,
272,
1830,
610,
400,
813,
83,
365,
488,
503,
334,
391,
400,
813,
83,
436,
9709,
665,
610,
400,
813,
83,
304,
267,
862,
26,
288,
2120,
275,
664,
342,
267,
871,
334,
13178,
547,
12,
5925,
304,
288,
3105,
360,
6599,
4788,
21157,
503,
5925,
1553,
24234,
358,
288,
2059,
398,
340,
2120,
365,
488,
26,
288,
3105,
360,
6599,
4788,
13792,
1553,
24234,
358,
288,
2059,
398,
3906,
12,
284,
12,
2562,
12,
1249,
12,
16286,
275,
2120,
267,
862,
26,
288,
754,
275,
334,
549,
12,
2562,
2031,
589,
12,
1011,
10340,
430,
267,
871,
2186,
465,
325,
26,
288,
754,
275,
334,
797,
12,
325,
9,
267,
862,
26,
288,
5324,
1332,
2423,
12,
284,
12,
754,
430,
267,
871,
2186,
465,
325,
26,
288,
8072,
275,
23038,
7630,
547,
8,
69,
12,
754,
59,
17,
566,
288,
3105,
480,
28096,
2644,
1125,
1830,
10209,
754,
26,
450,
83,
2,
450,
334,
355,
8072,
430,
288,
5324,
1332,
2423,
12,
284,
12,
334,
797,
12,
8072,
1724,
267,
9709,
847,
413,
272,
3105,
360,
6599,
24234,
2410,
450,
68,
6527,
7,
450,
9709,
9,
199,
199,
3,
199,
3,
8089,
6144,
282,
2112,
4203,
199,
3,
199,
199,
533,
15553,
8,
785,
304,
272,
1449,
272,
8089,
1314,
5171,
376,
5316,
1015,
402,
18876,
3423,
370,
2368,
14,
272,
1449,
272,
7132,
275,
7132,
339,
347,
636,
826,
721,
277,
12,
10358,
29,
403,
12,
11130,
29,
403,
12,
4205,
589,
16729,
326,
610,
400,
813,
83,
529,
1739,
29,
403,
304,
267,
291,
423,
2758,
63,
18849,
342,
267,
291,
423,
1765,
1825,
275,
4126,
14,
3737,
342,
267,
291,
423,
1637,
275,
1052,
267,
291,
423,
929,
275,
21277,
267,
291,
423,
391,
400,
813,
83,
529,
1739,
275,
610,
400,
813,
83,
529,
1739,
267,
291,
423,
6498,
275,
11130,
267,
291,
423,
826,
589,
275,
4205,
589,
398,
340,
10358,
365,
488,
26,
288,
862,
26,
355,
10358,
275,
5033,
63,
835,
342,
288,
871,
4279,
26,
355,
10358,
275,
413,
267,
340,
10358,
665,
413,
26,
288,
746,
1722,
480,
3259,
402,
10358,
1471,
506,
737,
5210,
413,
531,
398,
340,
11130,
365,
440,
488,
436,
440,
4550,
8,
6498,
304,
288,
746,
3146,
360,
6498,
1471,
506,
282,
4550,
358,
398,
291,
423,
11816,
275,
10358,
267,
291,
423,
2293,
275,
942,
267,
291,
423,
1155,
411,
5434,
63,
2293,
342,
398,
291,
423,
6599,
63,
2232,
275,
5796,
14,
4436,
8,
288,
1347,
29,
5453,
423,
2479,
63,
11009,
12,
288,
1249,
2687,
277,
12,
776,
288,
776,
267,
291,
423,
6599,
63,
2232,
14,
10824,
275,
715,
267,
291,
423,
6599,
63,
2232,
423,
929,
275,
21277,
267,
291,
423,
6599,
63,
2232,
14,
928,
342,
7318,
291,
423,
1765,
63,
2232,
275,
5796,
14,
4436,
8,
288,
1347,
29,
5453,
423,
2479,
63,
5054,
12,
288,
1249,
2687,
277,
423,
1765,
1825,
12,
291,
423,
13239,
63,
524,
12,
291,
423,
548,
1825,
12,
291,
423,
2293,
9,
288,
776,
267,
291,
423,
1765,
63,
2232,
14,
10824,
275,
715,
267,
291,
423,
1765,
63,
2232,
423,
929,
275,
21277,
267,
291,
423,
1765,
63,
2232,
14,
928,
342,
398,
291,
423,
1099,
63,
2232,
275,
5796,
14,
4436,
8,
288,
1347,
29,
5453,
423,
2479,
63,
2604,
12,
288,
1249,
2687,
277,
423,
548,
1825,
12,
291,
423,
13239,
63,
362,
12,
291,
423,
1637,
9
] |
[
199,
3,
5673,
13070,
314,
658,
5453,
64,
1021,
367,
28453,
282,
2112,
4203,
199,
3,
199,
3,
12866,
15,
2293,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
8315,
13,
9300,
12,
820,
593,
1181,
2570,
75,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
3,
199,
199,
363,
452,
363,
275,
788,
5453,
418,
199,
199,
3,
199,
3,
24339,
199,
3,
199,
199,
646,
5796,
199,
646,
4126,
199,
646,
7975,
199,
646,
5055,
199,
646,
900,
199,
199,
504,
12866,
492,
7132,
12,
5033,
63,
835,
12,
31886,
199,
504,
12866,
14,
1974,
492,
21789,
794,
12,
3105,
199,
199,
3,
199,
3,
22296,
6144,
314,
1174,
402,
282,
4203,
199,
3,
199,
199,
9390,
275,
378,
199,
18219,
275,
413,
199,
28376,
1951,
275,
499,
199,
199,
3,
199,
3,
12481,
19549,
199,
3,
199,
199,
2423,
63,
5337,
275,
7975,
14,
835,
342,
199,
199,
318,
2341,
7848,
8,
589,
304,
272,
372,
769,
8,
1130,
2031,
589,
430,
199,
199,
318,
14664,
1130,
7848,
8,
589,
304,
272,
372,
769,
8,
17691,
14,
7848,
1130,
8,
589,
59,
16,
467,
1249,
59,
17,
2459,
199,
199,
3,
199,
3,
5495,
1255,
701,
7239,
10358,
199,
3,
199,
199,
533,
23038,
7630,
547,
8,
1726,
304,
272,
408,
55,
8146,
3962,
625,
8092,
461,
2552,
12,
880,
2985,
883,
506,
272,
19353,
4847,
4012,
314,
2838,
1041,
339,
347,
636,
826,
721,
277,
12,
3178,
12,
574,
304,
267,
291,
14,
2804,
275,
4700,
8,
2804,
9,
267,
291,
14,
585,
275,
4700,
8,
585,
9,
267,
1613,
8,
15586,
1235,
7630,
547,
12,
291,
2843,
826,
721,
277,
14,
2804,
12,
291,
14,
585,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
298,
547,
10209,
754,
26,
1543,
83,
1370,
799,
2660,
26,
1543,
83,
4065,
450,
334,
277,
14,
585,
12,
18193,
291,
14,
2804,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
15586,
1235,
7630,
547,
26,
450,
83,
4335,
450,
620,
8,
277,
9,
421,
199,
318,
7239,
8,
262,
1825,
12,
734,
1825,
12,
11130,
29,
403,
12,
4205,
589,
16729,
610,
400,
813,
83,
29,
403,
304,
272,
702,
610,
400,
813,
83,
365,
488,
503,
334,
466,
8,
391,
400,
813,
83,
9,
508,
1109,
436,
610,
400,
813,
83,
690,
378,
9,
272,
5324,
275,
734,
1825,
14,
524,
272,
664,
275,
315,
1825,
14,
362,
272,
340,
2688,
8,
262,
1825,
12,
2513,
5491,
735,
267,
315,
1825,
423,
5491,
14,
1600,
342,
267,
734,
1825,
423,
5503,
14,
1600,
342,
339,
340,
11130,
365,
440,
488,
26,
267,
11130,
2031,
826,
589,
9,
339,
9709,
275,
378,
272,
1830,
610,
400,
813,
83,
365,
488,
503,
334,
391,
400,
813,
83,
436,
9709,
665,
610,
400,
813,
83,
304,
267,
862,
26,
288,
2120,
275,
664,
342,
267,
871,
334,
13178,
547,
12,
5925,
304,
288,
3105,
360,
6599,
4788,
21157,
503,
5925,
1553,
24234,
358,
288,
2059,
398,
340,
2120,
365,
488,
26,
288,
3105,
360,
6599,
4788,
13792,
1553,
24234,
358,
288,
2059,
398,
3906,
12,
284,
12,
2562,
12,
1249,
12,
16286,
275,
2120,
267,
862,
26,
288,
754,
275,
334,
549,
12,
2562,
2031,
589,
12,
1011,
10340,
430,
267,
871,
2186,
465,
325,
26,
288,
754,
275,
334,
797,
12,
325,
9,
267,
862,
26,
288,
5324,
1332,
2423,
12,
284,
12,
754,
430,
267,
871,
2186,
465,
325,
26,
288,
8072,
275,
23038,
7630,
547,
8,
69,
12,
754,
59,
17,
566,
288,
3105,
480,
28096,
2644,
1125,
1830,
10209,
754,
26,
450,
83,
2,
450,
334,
355,
8072,
430,
288,
5324,
1332,
2423,
12,
284,
12,
334,
797,
12,
8072,
1724,
267,
9709,
847,
413,
272,
3105,
360,
6599,
24234,
2410,
450,
68,
6527,
7,
450,
9709,
9,
199,
199,
3,
199,
3,
8089,
6144,
282,
2112,
4203,
199,
3,
199,
199,
533,
15553,
8,
785,
304,
272,
1449,
272,
8089,
1314,
5171,
376,
5316,
1015,
402,
18876,
3423,
370,
2368,
14,
272,
1449,
272,
7132,
275,
7132,
339,
347,
636,
826,
721,
277,
12,
10358,
29,
403,
12,
11130,
29,
403,
12,
4205,
589,
16729,
326,
610,
400,
813,
83,
529,
1739,
29,
403,
304,
267,
291,
423,
2758,
63,
18849,
342,
267,
291,
423,
1765,
1825,
275,
4126,
14,
3737,
342,
267,
291,
423,
1637,
275,
1052,
267,
291,
423,
929,
275,
21277,
267,
291,
423,
391,
400,
813,
83,
529,
1739,
275,
610,
400,
813,
83,
529,
1739,
267,
291,
423,
6498,
275,
11130,
267,
291,
423,
826,
589,
275,
4205,
589,
398,
340,
10358,
365,
488,
26,
288,
862,
26,
355,
10358,
275,
5033,
63,
835,
342,
288,
871,
4279,
26,
355,
10358,
275,
413,
267,
340,
10358,
665,
413,
26,
288,
746,
1722,
480,
3259,
402,
10358,
1471,
506,
737,
5210,
413,
531,
398,
340,
11130,
365,
440,
488,
436,
440,
4550,
8,
6498,
304,
288,
746,
3146,
360,
6498,
1471,
506,
282,
4550,
358,
398,
291,
423,
11816,
275,
10358,
267,
291,
423,
2293,
275,
942,
267,
291,
423,
1155,
411,
5434,
63,
2293,
342,
398,
291,
423,
6599,
63,
2232,
275,
5796,
14,
4436,
8,
288,
1347,
29,
5453,
423,
2479,
63,
11009,
12,
288,
1249,
2687,
277,
12,
776,
288,
776,
267,
291,
423,
6599,
63,
2232,
14,
10824,
275,
715,
267,
291,
423,
6599,
63,
2232,
423,
929,
275,
21277,
267,
291,
423,
6599,
63,
2232,
14,
928,
342,
7318,
291,
423,
1765,
63,
2232,
275,
5796,
14,
4436,
8,
288,
1347,
29,
5453,
423,
2479,
63,
5054,
12,
288,
1249,
2687,
277,
423,
1765,
1825,
12,
291,
423,
13239,
63,
524,
12,
291,
423,
548,
1825,
12,
291,
423,
2293,
9,
288,
776,
267,
291,
423,
1765,
63,
2232,
14,
10824,
275,
715,
267,
291,
423,
1765,
63,
2232,
423,
929,
275,
21277,
267,
291,
423,
1765,
63,
2232,
14,
928,
342,
398,
291,
423,
1099,
63,
2232,
275,
5796,
14,
4436,
8,
288,
1347,
29,
5453,
423,
2479,
63,
2604,
12,
288,
1249,
2687,
277,
423,
548,
1825,
12,
291,
423,
13239,
63,
362,
12,
291,
423,
1637,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kenwmitchell/ansible-modules-core
|
cloud/rackspace/rax_clb_nodes.py
|
157
|
8616
|
#!/usr/bin/python
# 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_clb_nodes
short_description: add, modify and remove nodes from a Rackspace Cloud Load Balancer
description:
- Adds, modifies and removes nodes from a Rackspace Cloud Load Balancer
version_added: "1.4"
options:
address:
required: false
description:
- IP address or domain name of the node
condition:
required: false
choices:
- enabled
- disabled
- draining
description:
- Condition for the node, which determines its role within the load
balancer
load_balancer_id:
required: true
type: integer
description:
- Load balancer id
node_id:
required: false
type: integer
description:
- Node id
port:
required: false
type: integer
description:
- Port number of the load balanced service on the node
state:
required: false
default: "present"
choices:
- present
- absent
description:
- Indicate desired state of the node
type:
required: false
choices:
- primary
- secondary
description:
- Type of node
wait:
required: false
default: "no"
choices:
- "yes"
- "no"
description:
- Wait for the load balancer to become active before returning
wait_timeout:
required: false
type: integer
default: 30
description:
- How long to wait before giving up and returning an error
weight:
required: false
description:
- Weight of node
author: "Lukasz Kawczynski (@neuroid)"
extends_documentation_fragment: rackspace
'''
EXAMPLES = '''
# Add a new node to the load balancer
- local_action:
module: rax_clb_nodes
load_balancer_id: 71
address: 10.2.2.3
port: 80
condition: enabled
type: primary
wait: yes
credentials: /path/to/credentials
# Drain connections from a node
- local_action:
module: rax_clb_nodes
load_balancer_id: 71
node_id: 410
condition: draining
wait: yes
credentials: /path/to/credentials
# Remove a node from the load balancer
- local_action:
module: rax_clb_nodes
load_balancer_id: 71
node_id: 410
state: absent
wait: yes
credentials: /path/to/credentials
'''
try:
import pyrax
HAS_PYRAX = True
except ImportError:
HAS_PYRAX = False
def _activate_virtualenv(path):
path = os.path.expanduser(path)
activate_this = os.path.join(path, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
def _get_node(lb, node_id=None, address=None, port=None):
"""Return a matching node"""
for node in getattr(lb, 'nodes', []):
match_list = []
if node_id is not None:
match_list.append(getattr(node, 'id', None) == node_id)
if address is not None:
match_list.append(getattr(node, 'address', None) == address)
if port is not None:
match_list.append(getattr(node, 'port', None) == port)
if match_list and all(match_list):
return node
return None
def main():
argument_spec = rax_argument_spec()
argument_spec.update(
dict(
address=dict(),
condition=dict(choices=['enabled', 'disabled', 'draining']),
load_balancer_id=dict(required=True, type='int'),
node_id=dict(type='int'),
port=dict(type='int'),
state=dict(default='present', choices=['present', 'absent']),
type=dict(choices=['primary', 'secondary']),
virtualenv=dict(),
wait=dict(default=False, type='bool'),
wait_timeout=dict(default=30, type='int'),
weight=dict(type='int'),
)
)
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')
address = module.params['address']
condition = (module.params['condition'] and
module.params['condition'].upper())
load_balancer_id = module.params['load_balancer_id']
node_id = module.params['node_id']
port = module.params['port']
state = module.params['state']
typ = module.params['type'] and module.params['type'].upper()
virtualenv = module.params['virtualenv']
wait = module.params['wait']
wait_timeout = module.params['wait_timeout'] or 1
weight = module.params['weight']
if virtualenv:
try:
_activate_virtualenv(virtualenv)
except IOError, e:
module.fail_json(msg='Failed to activate virtualenv %s (%s)' % (
virtualenv, e))
setup_rax_module(module, pyrax)
if not pyrax.cloud_loadbalancers:
module.fail_json(msg='Failed to instantiate client. This '
'typically indicates an invalid region or an '
'incorrectly capitalized region name.')
try:
lb = pyrax.cloud_loadbalancers.get(load_balancer_id)
except pyrax.exc.PyraxException, e:
module.fail_json(msg='%s' % e.message)
node = _get_node(lb, node_id, address, port)
result = rax_clb_node_to_dict(node)
if state == 'absent':
if not node: # Removing a non-existent node
module.exit_json(changed=False, state=state)
try:
lb.delete_node(node)
result = {}
except pyrax.exc.NotFound:
module.exit_json(changed=False, state=state)
except pyrax.exc.PyraxException, e:
module.fail_json(msg='%s' % e.message)
else: # present
if not node:
if node_id: # Updating a non-existent node
msg = 'Node %d not found' % node_id
if lb.nodes:
msg += (' (available nodes: %s)' %
', '.join([str(x.id) for x in lb.nodes]))
module.fail_json(msg=msg)
else: # Creating a new node
try:
node = pyrax.cloudloadbalancers.Node(
address=address, port=port, condition=condition,
weight=weight, type=typ)
resp, body = lb.add_nodes([node])
result.update(body['nodes'][0])
except pyrax.exc.PyraxException, e:
module.fail_json(msg='%s' % e.message)
else: # Updating an existing node
mutable = {
'condition': condition,
'type': typ,
'weight': weight,
}
for name, value in mutable.items():
if value is None or value == getattr(node, name):
mutable.pop(name)
if not mutable:
module.exit_json(changed=False, state=state, node=result)
try:
# The diff has to be set explicitly to update node's weight and
# type; this should probably be fixed in pyrax
lb.update_node(node, diff=mutable)
result.update(mutable)
except pyrax.exc.PyraxException, e:
module.fail_json(msg='%s' % e.message)
if wait:
pyrax.utils.wait_until(lb, "status", "ACTIVE", interval=1,
attempts=wait_timeout)
if lb.status != 'ACTIVE':
module.fail_json(
msg='Load balancer not active after %ds (current status: %s)' %
(wait_timeout, lb.status.lower()))
kwargs = {'node': result} if result else {}
module.exit_json(changed=True, state=state, **kwargs)
# 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,
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,
2595,
199,
578,
26,
16937,
63,
429,
66,
63,
2415,
199,
3612,
63,
1802,
26,
1050,
12,
2811,
436,
2813,
3380,
687,
282,
32679,
8142,
7190,
23928,
7716,
199,
1802,
26,
523,
446,
15747,
12,
26473,
436,
14185,
3380,
687,
282,
32679,
8142,
7190,
23928,
7716,
199,
1023,
63,
3270,
26,
298,
17,
14,
20,
2,
199,
1419,
26,
523,
2287,
26,
272,
1415,
26,
3055,
272,
1369,
26,
489,
446,
3531,
2287,
503,
2881,
536,
402,
314,
1031,
523,
5558,
26,
272,
1415,
26,
3055,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
489,
446,
366,
6322,
316,
272,
1369,
26,
489,
446,
28401,
367,
314,
1031,
12,
1314,
16756,
2399,
4719,
4453,
314,
2248,
267,
17005,
523,
2248,
63,
11841,
63,
344,
26,
272,
1415,
26,
2549,
272,
730,
26,
3000,
272,
1369,
26,
489,
446,
7190,
17005,
1305,
523,
1031,
63,
344,
26,
272,
1415,
26,
3055,
272,
730,
26,
3000,
272,
1369,
26,
489,
446,
5013,
1305,
523,
1844,
26,
272,
1415,
26,
3055,
272,
730,
26,
3000,
272,
1369,
26,
489,
446,
10977,
1329,
402,
314,
2248,
14094,
68,
2435,
641,
314,
1031,
523,
1174,
26,
272,
1415,
26,
3055,
272,
849,
26,
298,
1881,
2,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
1031,
523,
730,
26,
272,
1415,
26,
3055,
272,
3415,
26,
489,
446,
5062,
489,
446,
13851,
272,
1369,
26,
489,
446,
2434,
402,
1031,
523,
3618,
26,
272,
1415,
26,
3055,
272,
849,
26,
298,
889,
2,
272,
3415,
26,
489,
446,
298,
5066,
2,
489,
446,
298,
889,
2,
272,
1369,
26,
489,
446,
13144,
367,
314,
2248,
17005,
370,
8649,
4702,
2544,
8152,
523,
3618,
63,
2593,
26,
272,
1415,
26,
3055,
272,
730,
26,
3000,
272,
849,
26,
4233,
272,
1369,
26,
489,
446,
7494,
1846,
370,
3618,
2544,
15131,
1536,
436,
8152,
376,
1125,
523,
5401,
26,
272,
1415,
26,
3055,
272,
1369,
26,
489,
446,
2136,
1070,
402,
1031,
199,
2502,
26,
298,
44,
3210,
305,
90,
1804,
10084,
67,
3605,
561,
8810,
8593,
685,
85,
3977,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2654,
282,
892,
1031,
370,
314,
2248,
17005,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
16937,
63,
429,
66,
63,
2415,
272,
2248,
63,
11841,
63,
344,
26,
17245,
272,
2287,
26,
1616,
14,
18,
14,
18,
14,
19,
272,
1844,
26,
5939,
272,
5558,
26,
5223,
272,
730,
26,
5062,
272,
3618,
26,
9456,
272,
6235,
26,
1182,
515,
15,
475,
15,
6942,
199,
199,
3,
577,
6322,
6947,
687,
282,
1031,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
16937,
63,
429,
66,
63,
2415,
272,
2248,
63,
11841,
63,
344,
26,
17245,
272,
1031,
63,
344,
26,
32321,
272,
5558,
26,
366,
6322,
316,
272,
3618,
26,
9456,
272,
6235,
26,
1182,
515,
15,
475,
15,
6942,
199,
199,
3,
5852,
282,
1031,
687,
314,
2248,
17005,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
16937,
63,
429,
66,
63,
2415,
272,
2248,
63,
11841,
63,
344,
26,
17245,
272,
1031,
63,
344,
26,
32321,
272,
1174,
26,
9552,
272,
3618,
26,
9456,
272,
6235,
26,
1182,
515,
15,
475,
15,
6942,
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,
485,
8222,
63,
21611,
8,
515,
304,
272,
931,
275,
747,
14,
515,
14,
12131,
8,
515,
9,
272,
15422,
63,
3749,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
1393,
297,
283,
8222,
63,
3749,
14,
647,
358,
272,
22711,
8,
8222,
63,
3749,
12,
1211,
3460,
493,
363,
29,
8222,
63,
3749,
430,
421,
199,
318,
485,
362,
63,
932,
8,
6374,
12,
1031,
63,
344,
29,
403,
12,
2287,
29,
403,
12,
1844,
29,
403,
304,
272,
408,
1767,
282,
4877,
1031,
624,
272,
367,
1031,
315,
2519,
8,
6374,
12,
283,
2415,
297,
12319,
267,
1336,
63,
513,
275,
942,
267,
340,
1031,
63,
344,
365,
440,
488,
26,
288,
1336,
63,
513,
14,
740,
8,
5675,
8,
932,
12,
283,
344,
297,
488,
9,
508,
1031,
63,
344,
9,
267,
340,
2287,
365,
440,
488,
26,
288,
1336,
63,
513,
14,
740,
8,
5675,
8,
932,
12,
283,
1562,
297,
488,
9,
508,
2287,
9,
267,
340,
1844,
365,
440,
488,
26,
288,
1336,
63,
513,
14,
740,
8,
5675,
8,
932,
12,
283,
719,
297,
488,
9,
508,
1844,
9,
398,
340,
1336,
63,
513,
436,
1006,
8,
1431,
63,
513,
304,
288,
372,
1031,
339,
372,
488,
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,
2287,
29,
807,
1062,
288,
5558
] |
[
2647,
15,
1393,
15,
1548,
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,
2595,
199,
578,
26,
16937,
63,
429,
66,
63,
2415,
199,
3612,
63,
1802,
26,
1050,
12,
2811,
436,
2813,
3380,
687,
282,
32679,
8142,
7190,
23928,
7716,
199,
1802,
26,
523,
446,
15747,
12,
26473,
436,
14185,
3380,
687,
282,
32679,
8142,
7190,
23928,
7716,
199,
1023,
63,
3270,
26,
298,
17,
14,
20,
2,
199,
1419,
26,
523,
2287,
26,
272,
1415,
26,
3055,
272,
1369,
26,
489,
446,
3531,
2287,
503,
2881,
536,
402,
314,
1031,
523,
5558,
26,
272,
1415,
26,
3055,
272,
3415,
26,
489,
446,
5223,
489,
446,
6980,
489,
446,
366,
6322,
316,
272,
1369,
26,
489,
446,
28401,
367,
314,
1031,
12,
1314,
16756,
2399,
4719,
4453,
314,
2248,
267,
17005,
523,
2248,
63,
11841,
63,
344,
26,
272,
1415,
26,
2549,
272,
730,
26,
3000,
272,
1369,
26,
489,
446,
7190,
17005,
1305,
523,
1031,
63,
344,
26,
272,
1415,
26,
3055,
272,
730,
26,
3000,
272,
1369,
26,
489,
446,
5013,
1305,
523,
1844,
26,
272,
1415,
26,
3055,
272,
730,
26,
3000,
272,
1369,
26,
489,
446,
10977,
1329,
402,
314,
2248,
14094,
68,
2435,
641,
314,
1031,
523,
1174,
26,
272,
1415,
26,
3055,
272,
849,
26,
298,
1881,
2,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
272,
1369,
26,
489,
446,
1010,
10188,
6387,
1174,
402,
314,
1031,
523,
730,
26,
272,
1415,
26,
3055,
272,
3415,
26,
489,
446,
5062,
489,
446,
13851,
272,
1369,
26,
489,
446,
2434,
402,
1031,
523,
3618,
26,
272,
1415,
26,
3055,
272,
849,
26,
298,
889,
2,
272,
3415,
26,
489,
446,
298,
5066,
2,
489,
446,
298,
889,
2,
272,
1369,
26,
489,
446,
13144,
367,
314,
2248,
17005,
370,
8649,
4702,
2544,
8152,
523,
3618,
63,
2593,
26,
272,
1415,
26,
3055,
272,
730,
26,
3000,
272,
849,
26,
4233,
272,
1369,
26,
489,
446,
7494,
1846,
370,
3618,
2544,
15131,
1536,
436,
8152,
376,
1125,
523,
5401,
26,
272,
1415,
26,
3055,
272,
1369,
26,
489,
446,
2136,
1070,
402,
1031,
199,
2502,
26,
298,
44,
3210,
305,
90,
1804,
10084,
67,
3605,
561,
8810,
8593,
685,
85,
3977,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
660,
346,
2638,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2654,
282,
892,
1031,
370,
314,
2248,
17005,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
16937,
63,
429,
66,
63,
2415,
272,
2248,
63,
11841,
63,
344,
26,
17245,
272,
2287,
26,
1616,
14,
18,
14,
18,
14,
19,
272,
1844,
26,
5939,
272,
5558,
26,
5223,
272,
730,
26,
5062,
272,
3618,
26,
9456,
272,
6235,
26,
1182,
515,
15,
475,
15,
6942,
199,
199,
3,
577,
6322,
6947,
687,
282,
1031,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
16937,
63,
429,
66,
63,
2415,
272,
2248,
63,
11841,
63,
344,
26,
17245,
272,
1031,
63,
344,
26,
32321,
272,
5558,
26,
366,
6322,
316,
272,
3618,
26,
9456,
272,
6235,
26,
1182,
515,
15,
475,
15,
6942,
199,
199,
3,
5852,
282,
1031,
687,
314,
2248,
17005,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
16937,
63,
429,
66,
63,
2415,
272,
2248,
63,
11841,
63,
344,
26,
17245,
272,
1031,
63,
344,
26,
32321,
272,
1174,
26,
9552,
272,
3618,
26,
9456,
272,
6235,
26,
1182,
515,
15,
475,
15,
6942,
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,
485,
8222,
63,
21611,
8,
515,
304,
272,
931,
275,
747,
14,
515,
14,
12131,
8,
515,
9,
272,
15422,
63,
3749,
275,
747,
14,
515,
14,
904,
8,
515,
12,
283,
1393,
297,
283,
8222,
63,
3749,
14,
647,
358,
272,
22711,
8,
8222,
63,
3749,
12,
1211,
3460,
493,
363,
29,
8222,
63,
3749,
430,
421,
199,
318,
485,
362,
63,
932,
8,
6374,
12,
1031,
63,
344,
29,
403,
12,
2287,
29,
403,
12,
1844,
29,
403,
304,
272,
408,
1767,
282,
4877,
1031,
624,
272,
367,
1031,
315,
2519,
8,
6374,
12,
283,
2415,
297,
12319,
267,
1336,
63,
513,
275,
942,
267,
340,
1031,
63,
344,
365,
440,
488,
26,
288,
1336,
63,
513,
14,
740,
8,
5675,
8,
932,
12,
283,
344,
297,
488,
9,
508,
1031,
63,
344,
9,
267,
340,
2287,
365,
440,
488,
26,
288,
1336,
63,
513,
14,
740,
8,
5675,
8,
932,
12,
283,
1562,
297,
488,
9,
508,
2287,
9,
267,
340,
1844,
365,
440,
488,
26,
288,
1336,
63,
513,
14,
740,
8,
5675,
8,
932,
12,
283,
719,
297,
488,
9,
508,
1844,
9,
398,
340,
1336,
63,
513,
436,
1006,
8,
1431,
63,
513,
304,
288,
372,
1031,
339,
372,
488,
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,
2287,
29,
807,
1062,
288,
5558,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
abarnert/pyinterval
|
test/__init__.py
|
1
|
2481
|
# Copyright (c) 2008, Stefano Taschini <taschini@ieee.org>
# All rights reserved.
# See LICENSE for details.
class app(object):
def __init__(self, doctests = None, docfiles = None):
self.doctests = doctests or []
self.docfiles = docfiles or []
def _import(self, name):
m = __import__(name)
for c in name.split('.')[1:]:
m = getattr(m, c)
return m
def suite(self):
import unittest, doctest, glob
import os.path as op
s = unittest.TestLoader().loadTestsFromModule(__import__(self.__module__))
prefix = op.dirname(__file__)
names = [m[len(prefix)+1:-3] for m in glob.glob(op.join(prefix, 'test*.py'))]
for m in names:
s.addTest(unittest.TestLoader().loadTestsFromModule(self._import('test.' + m)))
for m in self.doctests:
try:
m = self._import(m)
except ImportError:
pass
else:
s.addTest(doctest.DocTestSuite(m))
s.addTest(doctest.DocFileSuite(module_relative=False, *self.docfiles))
return s
def parse_cli(self, argv):
import optparse
parser = optparse.OptionParser(prog=argv[0])
parser.set_defaults(verbosity=[1])
parser.add_option("-v", "--verbose", dest='verbosity', action='append_const', const=+1, help="increase verbosity")
parser.add_option("-q", "--quiet", dest='verbosity', action='append_const', const=-1, help="decrease verbosity")
parser.add_option("-n", "--names", action='store_true', help="show test names instead of descriptions", default=False)
return parser.parse_args(argv[1:])
def main(self, argv=None):
import sys
(options, args) = self.parse_cli(argv or sys.argv)
import unittest
if args:
import re
s = unittest.TestSuite()
all = self.suite()
def visit(n, p):
try:
for c in n:
visit(c, p)
except:
if p.search(n.id()):
s.addTest(n)
for p in args:
visit(all, re.compile(p))
else:
s = self.suite()
return not unittest.TextTestRunner(verbosity=sum(options.verbosity), descriptions=not options.names).run(s).wasSuccessful()
if __name__ == '__main__':
import sys
sys.exit(app().main(sys.argv))
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
9079,
12,
17854,
70,
8143,
377,
305,
335,
2730,
665,
15520,
335,
2730,
32,
73,
18777,
14,
1308,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
533,
1145,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
26721,
275,
488,
12,
1382,
1725,
275,
488,
304,
267,
291,
14,
1301,
2219,
275,
26721,
503,
942,
267,
291,
14,
1301,
1725,
275,
1382,
1725,
503,
942,
339,
347,
485,
646,
8,
277,
12,
536,
304,
267,
333,
275,
636,
646,
721,
354,
9,
267,
367,
286,
315,
536,
14,
1294,
19237,
17,
10688,
288,
333,
275,
2519,
8,
77,
12,
286,
9,
267,
372,
333,
339,
347,
5241,
8,
277,
304,
267,
492,
2882,
12,
8868,
12,
5739,
267,
492,
747,
14,
515,
465,
1687,
267,
308,
275,
2882,
14,
15824,
1252,
12861,
2377,
3460,
646,
721,
277,
855,
578,
8964,
267,
2403,
275,
1687,
14,
3475,
3460,
493,
3368,
267,
1561,
275,
359,
77,
59,
552,
8,
1861,
6393,
17,
6809,
19,
61,
367,
333,
315,
5739,
14,
6463,
8,
411,
14,
904,
8,
1861,
12,
283,
396,
4856,
647,
27738,
267,
367,
333,
315,
1561,
26,
288,
308,
14,
15714,
8,
2796,
14,
15824,
1252,
12861,
2377,
8,
277,
423,
646,
360,
396,
3530,
435,
333,
1724,
267,
367,
333,
315,
291,
14,
1301,
2219,
26,
288,
862,
26,
355,
333,
275,
291,
423,
646,
8,
77,
9,
288,
871,
3545,
26,
355,
986,
288,
587,
26,
355,
308,
14,
15714,
8,
11390,
14,
3768,
10591,
8,
77,
430,
267,
308,
14,
15714,
8,
11390,
14,
3768,
1173,
6207,
8,
578,
63,
6188,
29,
797,
12,
627,
277,
14,
1301,
1725,
430,
267,
372,
308,
339,
347,
2198,
63,
2764,
8,
277,
12,
9238,
304,
267,
492,
8691,
267,
1798,
275,
8691,
14,
14553,
8,
6595,
29,
3020,
59,
16,
566,
267,
1798,
14,
409,
63,
4322,
8,
9833,
1524,
17,
566,
267,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
534,
9833,
297,
1595,
534,
740,
63,
1297,
297,
950,
29744,
17,
12,
1720,
628,
31687,
8661,
531,
267,
1798,
14,
525,
63,
1422,
6096,
81,
401,
4320,
10243,
401,
257,
2053,
534,
9833,
297,
1595,
534,
740,
63,
1297,
297,
950,
4022,
17,
12,
1720,
628,
271,
16772,
8661,
531,
267,
1798,
14,
525,
63,
1422,
6096,
78,
401,
4320,
1247,
401,
257,
1595,
534,
1617,
63,
2052,
297,
1720,
628,
2384,
511,
1561,
3140,
402,
18714,
401,
849,
29,
797,
9,
267,
372,
1798,
14,
1122,
63,
589,
8,
3020,
59,
17,
5728,
339,
347,
2446,
8,
277,
12,
9238,
29,
403,
304,
267,
492,
984,
267,
334,
1419,
12,
1249,
9,
275,
291,
14,
1122,
63,
2764,
8,
3020,
503,
984,
14,
3020,
9,
267,
492,
2882,
267,
340,
1249,
26,
288,
492,
295,
288,
308,
275,
2882,
14,
10591,
342,
288,
1006,
275,
291,
14,
5768,
342,
288,
347,
5684,
8,
78,
12,
299,
304,
355,
862,
26,
490,
367,
286,
315,
302,
26,
717,
5684,
8,
67,
12,
299,
9,
355,
871,
26,
490,
340,
299,
14,
1733,
8,
78,
14,
344,
5109,
717,
308,
14,
15714,
8,
78,
9,
288,
367,
299,
315,
1249,
26,
355,
5684,
8,
452,
12,
295,
14,
2014,
8,
80,
430,
267,
587,
26,
288,
308,
275,
291,
14,
5768,
342,
267,
372,
440,
2882,
14,
24285,
8,
9833,
29,
1838,
8,
1419,
14,
9833,
395,
18714,
29,
1397,
1511,
14,
1247,
680,
1065,
8,
83,
680,
10274,
20839,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
984,
14,
2224,
8,
571,
1252,
973,
8,
1274,
14,
3020,
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
] |
[
1898,
334,
67,
9,
9079,
12,
17854,
70,
8143,
377,
305,
335,
2730,
665,
15520,
335,
2730,
32,
73,
18777,
14,
1308,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
533,
1145,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
26721,
275,
488,
12,
1382,
1725,
275,
488,
304,
267,
291,
14,
1301,
2219,
275,
26721,
503,
942,
267,
291,
14,
1301,
1725,
275,
1382,
1725,
503,
942,
339,
347,
485,
646,
8,
277,
12,
536,
304,
267,
333,
275,
636,
646,
721,
354,
9,
267,
367,
286,
315,
536,
14,
1294,
19237,
17,
10688,
288,
333,
275,
2519,
8,
77,
12,
286,
9,
267,
372,
333,
339,
347,
5241,
8,
277,
304,
267,
492,
2882,
12,
8868,
12,
5739,
267,
492,
747,
14,
515,
465,
1687,
267,
308,
275,
2882,
14,
15824,
1252,
12861,
2377,
3460,
646,
721,
277,
855,
578,
8964,
267,
2403,
275,
1687,
14,
3475,
3460,
493,
3368,
267,
1561,
275,
359,
77,
59,
552,
8,
1861,
6393,
17,
6809,
19,
61,
367,
333,
315,
5739,
14,
6463,
8,
411,
14,
904,
8,
1861,
12,
283,
396,
4856,
647,
27738,
267,
367,
333,
315,
1561,
26,
288,
308,
14,
15714,
8,
2796,
14,
15824,
1252,
12861,
2377,
8,
277,
423,
646,
360,
396,
3530,
435,
333,
1724,
267,
367,
333,
315,
291,
14,
1301,
2219,
26,
288,
862,
26,
355,
333,
275,
291,
423,
646,
8,
77,
9,
288,
871,
3545,
26,
355,
986,
288,
587,
26,
355,
308,
14,
15714,
8,
11390,
14,
3768,
10591,
8,
77,
430,
267,
308,
14,
15714,
8,
11390,
14,
3768,
1173,
6207,
8,
578,
63,
6188,
29,
797,
12,
627,
277,
14,
1301,
1725,
430,
267,
372,
308,
339,
347,
2198,
63,
2764,
8,
277,
12,
9238,
304,
267,
492,
8691,
267,
1798,
275,
8691,
14,
14553,
8,
6595,
29,
3020,
59,
16,
566,
267,
1798,
14,
409,
63,
4322,
8,
9833,
1524,
17,
566,
267,
1798,
14,
525,
63,
1422,
6096,
86,
401,
4320,
3832,
401,
2053,
534,
9833,
297,
1595,
534,
740,
63,
1297,
297,
950,
29744,
17,
12,
1720,
628,
31687,
8661,
531,
267,
1798,
14,
525,
63,
1422,
6096,
81,
401,
4320,
10243,
401,
257,
2053,
534,
9833,
297,
1595,
534,
740,
63,
1297,
297,
950,
4022,
17,
12,
1720,
628,
271,
16772,
8661,
531,
267,
1798,
14,
525,
63,
1422,
6096,
78,
401,
4320,
1247,
401,
257,
1595,
534,
1617,
63,
2052,
297,
1720,
628,
2384,
511,
1561,
3140,
402,
18714,
401,
849,
29,
797,
9,
267,
372,
1798,
14,
1122,
63,
589,
8,
3020,
59,
17,
5728,
339,
347,
2446,
8,
277,
12,
9238,
29,
403,
304,
267,
492,
984,
267,
334,
1419,
12,
1249,
9,
275,
291,
14,
1122,
63,
2764,
8,
3020,
503,
984,
14,
3020,
9,
267,
492,
2882,
267,
340,
1249,
26,
288,
492,
295,
288,
308,
275,
2882,
14,
10591,
342,
288,
1006,
275,
291,
14,
5768,
342,
288,
347,
5684,
8,
78,
12,
299,
304,
355,
862,
26,
490,
367,
286,
315,
302,
26,
717,
5684,
8,
67,
12,
299,
9,
355,
871,
26,
490,
340,
299,
14,
1733,
8,
78,
14,
344,
5109,
717,
308,
14,
15714,
8,
78,
9,
288,
367,
299,
315,
1249,
26,
355,
5684,
8,
452,
12,
295,
14,
2014,
8,
80,
430,
267,
587,
26,
288,
308,
275,
291,
14,
5768,
342,
267,
372,
440,
2882,
14,
24285,
8,
9833,
29,
1838,
8,
1419,
14,
9833,
395,
18714,
29,
1397,
1511,
14,
1247,
680,
1065,
8,
83,
680,
10274,
20839,
342,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
984,
14,
2224,
8,
571,
1252,
973,
8,
1274,
14,
3020,
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,
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,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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
] |
sudosurootdev/external_chromium_org
|
tools/telemetry/telemetry/core/backends/chrome/ios_browser_finder.py
|
25
|
4184
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Finds iOS browsers that can be controlled by telemetry."""
import logging
import re
import subprocess
from telemetry import decorators
from telemetry.core import browser
from telemetry.core import platform
from telemetry.core import possible_browser
from telemetry.core.backends.chrome import inspector_backend
from telemetry.core.backends.chrome import ios_browser_backend
from telemetry.core.platform import ios_platform_backend
# Key matches output from ios-webkit-debug-proxy and the value is a readable
# description of the browser.
IOS_BROWSERS = {'CriOS': 'ios-chrome', 'Version': 'ios-safari'}
DEVICE_LIST_URL = 'http://127.0.0.1:9221/json'
IOS_WEBKIT_DEBUG_PROXY = 'ios_webkit_debug_proxy'
class PossibleIOSBrowser(possible_browser.PossibleBrowser):
"""A running iOS browser instance."""
def __init__(self, browser_type, finder_options):
super(PossibleIOSBrowser, self).__init__(browser_type, 'ios',
finder_options, True)
# TODO(baxley): Implement the following methods for iOS.
def Create(self):
backend = ios_browser_backend.IosBrowserBackend(
self.finder_options.browser_options)
return browser.Browser(backend,
self._platform_backend,
self._archive_path,
self._append_to_existing_wpr,
self._make_javascript_deterministic,
self._credentials_path)
def SupportsOptions(self, finder_options):
#TODO(baxley): Implement me.
return True
def UpdateExecutableIfNeeded(self):
#TODO(baxley): Implement me.
pass
def _InitPlatformIfNeeded(self):
if self._platform:
return
self._platform_backend = ios_platform_backend.IosPlatformBackend()
self._platform = platform.Platform(self._platform_backend)
def SelectDefaultBrowser(_):
return None # TODO(baxley): Implement me.
def CanFindAvailableBrowsers():
# TODO(baxley): Add support for all platforms possible. Probably Linux,
# probably not Windows.
return platform.GetHostPlatform().GetOSName() == 'mac'
def FindAllBrowserTypes(_):
return IOS_BROWSERS.values()
@decorators.Cache
def _IsIosDeviceAttached():
devices = subprocess.check_output('system_profiler SPUSBDataType', shell=True)
for line in devices.split('\n'):
if line and re.match('\s*(iPod|iPhone|iPad):', line):
return True
return False
def FindAllAvailableBrowsers(finder_options):
"""Find all running iOS browsers on connected devices."""
if not CanFindAvailableBrowsers():
return []
if not _IsIosDeviceAttached():
return []
options = finder_options.browser_options
options.browser_type = 'ios-chrome'
backend = ios_browser_backend.IosBrowserBackend(options)
host = platform.GetHostPlatform()
# TODO(baxley): Use idevice to wake up device or log debug statement.
if not host.IsApplicationRunning(IOS_WEBKIT_DEBUG_PROXY):
host.LaunchApplication(IOS_WEBKIT_DEBUG_PROXY)
if not host.IsApplicationRunning(IOS_WEBKIT_DEBUG_PROXY):
return []
device_urls = backend.GetDeviceUrls()
if not device_urls:
logging.debug('Could not find any devices over %s.'
% IOS_WEBKIT_DEBUG_PROXY)
return []
debug_urls = backend.GetWebSocketDebuggerUrls(device_urls)
# Get the userAgent for each UIWebView to find the browsers.
browser_pattern = ('\)\s(%s)\/(\d+[\.\d]*)\sMobile'
% '|'.join(IOS_BROWSERS.keys()))
browser_types = set()
for url in debug_urls:
context = {'webSocketDebuggerUrl':url , 'id':1}
inspector = inspector_backend.InspectorBackend(backend, context)
res = inspector.EvaluateJavaScript("navigator.userAgent")
match_browsers = re.search(browser_pattern, res)
if match_browsers:
browser_types.add(match_browsers.group(1))
browsers = []
for browser_type in browser_types:
browsers.append(PossibleIOSBrowser(IOS_BROWSERS[browser_type],
finder_options))
return list(browsers)
|
bsd-3-clause
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
30344,
284,
3100,
23776,
626,
883,
506,
22284,
701,
17298,
1041,
199,
199,
646,
2050,
199,
646,
295,
199,
646,
3873,
199,
199,
504,
17298,
492,
20419,
199,
504,
17298,
14,
1018,
492,
7042,
199,
504,
17298,
14,
1018,
492,
4298,
199,
504,
17298,
14,
1018,
492,
3962,
63,
5750,
199,
504,
17298,
14,
1018,
14,
7765,
14,
9887,
492,
5261,
15152,
63,
4620,
199,
504,
17298,
14,
1018,
14,
7765,
14,
9887,
492,
29516,
63,
5750,
63,
4620,
199,
504,
17298,
14,
1018,
14,
3246,
492,
29516,
63,
3246,
63,
4620,
421,
199,
3,
2606,
4450,
1072,
687,
29516,
13,
12554,
13,
1757,
13,
3280,
436,
314,
574,
365,
282,
12701,
199,
3,
1369,
402,
314,
7042,
14,
199,
13532,
63,
31956,
3279,
51,
275,
791,
35,
322,
3100,
356,
283,
9207,
13,
9887,
297,
283,
3353,
356,
283,
9207,
13,
2231,
70,
759,
936,
199,
10555,
63,
4924,
63,
2632,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
25,
11564,
15,
1001,
7,
199,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
275,
283,
9207,
63,
12554,
63,
1757,
63,
3280,
7,
421,
199,
533,
18558,
13532,
11930,
8,
13893,
63,
5750,
14,
28096,
11930,
304,
819,
408,
33,
3879,
284,
3100,
7042,
1256,
1041,
523,
347,
636,
826,
721,
277,
12,
7042,
63,
466,
12,
11569,
63,
1419,
304,
272,
1613,
8,
28096,
13532,
11930,
12,
291,
2843,
826,
721,
5750,
63,
466,
12,
283,
9207,
297,
267,
11569,
63,
1419,
12,
715,
9,
819,
327,
3254,
8,
66,
1219,
15515,
304,
22467,
314,
2569,
3102,
367,
284,
3100,
14,
523,
347,
2790,
8,
277,
304,
272,
4865,
275,
29516,
63,
5750,
63,
4620,
14,
28305,
11930,
8447,
8,
267,
291,
14,
11681,
63,
1419,
14,
5750,
63,
1419,
9,
272,
372,
7042,
14,
11930,
8,
4620,
12,
2574,
291,
423,
3246,
63,
4620,
12,
2574,
291,
423,
6404,
63,
515,
12,
2574,
291,
423,
740,
63,
475,
63,
5952,
63,
87,
2700,
12,
2574,
291,
423,
1875,
63,
9554,
63,
30709,
12,
2574,
291,
423,
6942,
63,
515,
9,
819,
347,
32090,
4558,
8,
277,
12,
11569,
63,
1419,
304,
272,
327,
11768,
8,
66,
1219,
15515,
304,
22467,
562,
14,
272,
372,
715,
819,
347,
6162,
18039,
3917,
21549,
8,
277,
304,
272,
327,
11768,
8,
66,
1219,
15515,
304,
22467,
562,
14,
272,
986,
819,
347,
485,
9346,
10397,
3917,
21549,
8,
277,
304,
272,
340,
291,
423,
3246,
26,
489,
372,
339,
291,
423,
3246,
63,
4620,
275,
29516,
63,
3246,
63,
4620,
14,
28305,
10397,
8447,
342,
272,
291,
423,
3246,
275,
4298,
14,
10397,
8,
277,
423,
3246,
63,
4620,
9,
199,
199,
318,
9496,
2698,
11930,
1547,
304,
523,
372,
488,
221,
327,
3254,
8,
66,
1219,
15515,
304,
22467,
562,
14,
421,
199,
318,
6855,
6591,
11464,
11930,
83,
837,
523,
327,
3254,
8,
66,
1219,
15515,
304,
2654,
2291,
367,
1006,
10677,
3962,
14,
22770,
6665,
10130,
12,
523,
327,
8646,
440,
5417,
14,
523,
372,
4298,
14,
1002,
4965,
10397,
1252,
1002,
3100,
985,
342,
508,
283,
3088,
7,
421,
199,
318,
6668,
2422,
11930,
4100,
1547,
304,
523,
372,
473,
3100,
63,
31956,
3279,
51,
14,
1459,
342,
421,
199,
32,
11582,
14,
4437,
199,
318,
485,
1831,
28305,
2510,
1271,
7159,
837,
523,
7256,
275,
3873,
14,
1074,
63,
1199,
360,
2253,
63,
20132,
6988,
19919,
23516,
297,
5218,
29,
549,
9,
523,
367,
1004,
315,
7256,
14,
1294,
2258,
78,
735,
272,
340,
1004,
436,
295,
14,
1431,
2258,
83,
5830,
73,
25928,
92,
73,
15199,
92,
73,
18584,
304,
297,
1004,
304,
489,
372,
715,
523,
372,
756,
421,
199,
318,
6668,
2422,
11464,
11930,
83,
8,
11681,
63,
1419,
304,
523,
408,
6591,
1006,
3879,
284,
3100,
23776,
641,
8539,
7256,
1041,
523,
340,
440,
6855,
6591,
11464,
11930,
83,
837,
272,
372,
942,
819,
340,
440,
485,
1831,
28305,
2510,
1271,
7159,
837,
272,
372,
942,
819,
1511,
275,
11569,
63,
1419,
14,
5750,
63,
1419,
819,
1511,
14,
5750,
63,
466,
275,
283,
9207,
13,
9887,
7,
523,
4865,
275,
29516,
63,
5750,
63,
4620,
14,
28305,
11930,
8447,
8,
1419,
9,
523,
1591,
275,
4298,
14,
1002,
4965,
10397,
342,
523,
327,
3254,
8,
66,
1219,
15515,
304,
3645,
284,
1782,
370,
21560,
1536,
2243,
503,
943,
3105,
5164,
14,
523,
340,
440,
1591,
14,
1831,
5039,
9602,
8,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
304,
272,
1591,
14,
18543,
5039,
8,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
9,
272,
340,
440,
1591,
14,
1831,
5039,
9602,
8,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
304,
489,
372,
942,
819,
2243,
63,
3603,
275,
4865,
14,
27654,
21867,
478,
342,
523,
340,
440,
2243,
63,
3603,
26,
272,
2050,
14,
1757,
360,
6531,
440,
2342,
1263,
7256,
1806,
450,
83,
3530,
2116,
450,
473,
3100,
63,
13166,
43,
649,
63,
5287,
63,
20026,
9,
272,
372,
942,
819,
3105,
63,
3603,
275,
4865,
14,
1002,
18477,
31521,
21867,
478,
8,
1782,
63,
3603,
9,
819,
327,
2372,
314,
922,
7788,
367,
1924,
14041,
5926,
2768,
370,
2342,
314,
23776,
14,
523,
7042,
63,
3401,
275,
661,
13670,
83,
4042,
83,
2862,
15,
2961,
68,
11,
7023,
3134,
68,
3672,
2862,
83,
27245,
7,
2151,
450,
21590,
904,
8,
13532,
63,
31956,
3279,
51,
14,
1612,
4059,
523,
7042,
63,
1313,
275,
663,
342,
523,
367,
1166,
315,
3105,
63,
3603,
26,
272,
1067,
275,
791,
2520,
3869,
31521,
6417,
356,
633,
2360,
283,
344,
356,
17,
93,
272,
5261,
15152,
275,
5261,
15152,
63,
4620,
14,
13962,
15152,
8447,
8,
4620,
12,
1067,
9,
272,
522,
275,
5261,
15152,
14,
25002,
21986,
480,
15595,
24934,
14,
751,
7788,
531,
272,
1336,
63,
5750,
83,
275,
295,
14,
1733,
8,
5750,
63,
3401,
12,
522,
9,
272,
340,
1336,
63,
5750
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
30344,
284,
3100,
23776,
626,
883,
506,
22284,
701,
17298,
1041,
199,
199,
646,
2050,
199,
646,
295,
199,
646,
3873,
199,
199,
504,
17298,
492,
20419,
199,
504,
17298,
14,
1018,
492,
7042,
199,
504,
17298,
14,
1018,
492,
4298,
199,
504,
17298,
14,
1018,
492,
3962,
63,
5750,
199,
504,
17298,
14,
1018,
14,
7765,
14,
9887,
492,
5261,
15152,
63,
4620,
199,
504,
17298,
14,
1018,
14,
7765,
14,
9887,
492,
29516,
63,
5750,
63,
4620,
199,
504,
17298,
14,
1018,
14,
3246,
492,
29516,
63,
3246,
63,
4620,
421,
199,
3,
2606,
4450,
1072,
687,
29516,
13,
12554,
13,
1757,
13,
3280,
436,
314,
574,
365,
282,
12701,
199,
3,
1369,
402,
314,
7042,
14,
199,
13532,
63,
31956,
3279,
51,
275,
791,
35,
322,
3100,
356,
283,
9207,
13,
9887,
297,
283,
3353,
356,
283,
9207,
13,
2231,
70,
759,
936,
199,
10555,
63,
4924,
63,
2632,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
25,
11564,
15,
1001,
7,
199,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
275,
283,
9207,
63,
12554,
63,
1757,
63,
3280,
7,
421,
199,
533,
18558,
13532,
11930,
8,
13893,
63,
5750,
14,
28096,
11930,
304,
819,
408,
33,
3879,
284,
3100,
7042,
1256,
1041,
523,
347,
636,
826,
721,
277,
12,
7042,
63,
466,
12,
11569,
63,
1419,
304,
272,
1613,
8,
28096,
13532,
11930,
12,
291,
2843,
826,
721,
5750,
63,
466,
12,
283,
9207,
297,
267,
11569,
63,
1419,
12,
715,
9,
819,
327,
3254,
8,
66,
1219,
15515,
304,
22467,
314,
2569,
3102,
367,
284,
3100,
14,
523,
347,
2790,
8,
277,
304,
272,
4865,
275,
29516,
63,
5750,
63,
4620,
14,
28305,
11930,
8447,
8,
267,
291,
14,
11681,
63,
1419,
14,
5750,
63,
1419,
9,
272,
372,
7042,
14,
11930,
8,
4620,
12,
2574,
291,
423,
3246,
63,
4620,
12,
2574,
291,
423,
6404,
63,
515,
12,
2574,
291,
423,
740,
63,
475,
63,
5952,
63,
87,
2700,
12,
2574,
291,
423,
1875,
63,
9554,
63,
30709,
12,
2574,
291,
423,
6942,
63,
515,
9,
819,
347,
32090,
4558,
8,
277,
12,
11569,
63,
1419,
304,
272,
327,
11768,
8,
66,
1219,
15515,
304,
22467,
562,
14,
272,
372,
715,
819,
347,
6162,
18039,
3917,
21549,
8,
277,
304,
272,
327,
11768,
8,
66,
1219,
15515,
304,
22467,
562,
14,
272,
986,
819,
347,
485,
9346,
10397,
3917,
21549,
8,
277,
304,
272,
340,
291,
423,
3246,
26,
489,
372,
339,
291,
423,
3246,
63,
4620,
275,
29516,
63,
3246,
63,
4620,
14,
28305,
10397,
8447,
342,
272,
291,
423,
3246,
275,
4298,
14,
10397,
8,
277,
423,
3246,
63,
4620,
9,
199,
199,
318,
9496,
2698,
11930,
1547,
304,
523,
372,
488,
221,
327,
3254,
8,
66,
1219,
15515,
304,
22467,
562,
14,
421,
199,
318,
6855,
6591,
11464,
11930,
83,
837,
523,
327,
3254,
8,
66,
1219,
15515,
304,
2654,
2291,
367,
1006,
10677,
3962,
14,
22770,
6665,
10130,
12,
523,
327,
8646,
440,
5417,
14,
523,
372,
4298,
14,
1002,
4965,
10397,
1252,
1002,
3100,
985,
342,
508,
283,
3088,
7,
421,
199,
318,
6668,
2422,
11930,
4100,
1547,
304,
523,
372,
473,
3100,
63,
31956,
3279,
51,
14,
1459,
342,
421,
199,
32,
11582,
14,
4437,
199,
318,
485,
1831,
28305,
2510,
1271,
7159,
837,
523,
7256,
275,
3873,
14,
1074,
63,
1199,
360,
2253,
63,
20132,
6988,
19919,
23516,
297,
5218,
29,
549,
9,
523,
367,
1004,
315,
7256,
14,
1294,
2258,
78,
735,
272,
340,
1004,
436,
295,
14,
1431,
2258,
83,
5830,
73,
25928,
92,
73,
15199,
92,
73,
18584,
304,
297,
1004,
304,
489,
372,
715,
523,
372,
756,
421,
199,
318,
6668,
2422,
11464,
11930,
83,
8,
11681,
63,
1419,
304,
523,
408,
6591,
1006,
3879,
284,
3100,
23776,
641,
8539,
7256,
1041,
523,
340,
440,
6855,
6591,
11464,
11930,
83,
837,
272,
372,
942,
819,
340,
440,
485,
1831,
28305,
2510,
1271,
7159,
837,
272,
372,
942,
819,
1511,
275,
11569,
63,
1419,
14,
5750,
63,
1419,
819,
1511,
14,
5750,
63,
466,
275,
283,
9207,
13,
9887,
7,
523,
4865,
275,
29516,
63,
5750,
63,
4620,
14,
28305,
11930,
8447,
8,
1419,
9,
523,
1591,
275,
4298,
14,
1002,
4965,
10397,
342,
523,
327,
3254,
8,
66,
1219,
15515,
304,
3645,
284,
1782,
370,
21560,
1536,
2243,
503,
943,
3105,
5164,
14,
523,
340,
440,
1591,
14,
1831,
5039,
9602,
8,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
304,
272,
1591,
14,
18543,
5039,
8,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
9,
272,
340,
440,
1591,
14,
1831,
5039,
9602,
8,
13532,
63,
13166,
43,
649,
63,
5287,
63,
20026,
304,
489,
372,
942,
819,
2243,
63,
3603,
275,
4865,
14,
27654,
21867,
478,
342,
523,
340,
440,
2243,
63,
3603,
26,
272,
2050,
14,
1757,
360,
6531,
440,
2342,
1263,
7256,
1806,
450,
83,
3530,
2116,
450,
473,
3100,
63,
13166,
43,
649,
63,
5287,
63,
20026,
9,
272,
372,
942,
819,
3105,
63,
3603,
275,
4865,
14,
1002,
18477,
31521,
21867,
478,
8,
1782,
63,
3603,
9,
819,
327,
2372,
314,
922,
7788,
367,
1924,
14041,
5926,
2768,
370,
2342,
314,
23776,
14,
523,
7042,
63,
3401,
275,
661,
13670,
83,
4042,
83,
2862,
15,
2961,
68,
11,
7023,
3134,
68,
3672,
2862,
83,
27245,
7,
2151,
450,
21590,
904,
8,
13532,
63,
31956,
3279,
51,
14,
1612,
4059,
523,
7042,
63,
1313,
275,
663,
342,
523,
367,
1166,
315,
3105,
63,
3603,
26,
272,
1067,
275,
791,
2520,
3869,
31521,
6417,
356,
633,
2360,
283,
344,
356,
17,
93,
272,
5261,
15152,
275,
5261,
15152,
63,
4620,
14,
13962,
15152,
8447,
8,
4620,
12,
1067,
9,
272,
522,
275,
5261,
15152,
14,
25002,
21986,
480,
15595,
24934,
14,
751,
7788,
531,
272,
1336,
63,
5750,
83,
275,
295,
14,
1733,
8,
5750,
63,
3401,
12,
522,
9,
272,
340,
1336,
63,
5750,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
apache/incubator-superset
|
superset/db_engine_specs/teradata.py
|
4
|
1793
|
# 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 superset.db_engine_specs.base import BaseEngineSpec, LimitMethod
class TeradataEngineSpec(BaseEngineSpec):
"""Dialect for Teradata DB."""
engine = "teradata"
engine_name = "Teradata"
limit_method = LimitMethod.WRAP_SQL
max_column_name_length = 30 # since 14.10 this is 128
_time_grain_expressions = {
None: "{col}",
"PT1M": "TRUNC(CAST({col} as DATE), 'MI')",
"PT1H": "TRUNC(CAST({col} as DATE), 'HH')",
"P1D": "TRUNC(CAST({col} as DATE), 'DDD')",
"P1W": "TRUNC(CAST({col} as DATE), 'WW')",
"P1M": "TRUNC(CAST({col} as DATE), 'MONTH')",
"P0.25Y": "TRUNC(CAST({col} as DATE), 'Q')",
"P1Y": "TRUNC(CAST({col} as DATE), 'YEAR')",
}
@classmethod
def epoch_to_dttm(cls) -> str:
return (
"CAST(((CAST(DATE '1970-01-01' + ({col} / 86400) AS TIMESTAMP(0) "
"AT 0)) AT 0) + (({col} MOD 86400) * INTERVAL '00:00:01' "
"HOUR TO SECOND) AS TIMESTAMP(0))"
)
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
504,
1613,
409,
14,
697,
63,
3908,
63,
7273,
14,
1095,
492,
3523,
8524,
5307,
12,
22672,
3767,
421,
199,
533,
13861,
1517,
8524,
5307,
8,
1563,
8524,
5307,
304,
272,
408,
22080,
367,
13861,
1517,
6249,
1041,
339,
6869,
275,
298,
2967,
576,
2,
272,
6869,
63,
354,
275,
298,
8600,
1517,
2,
272,
2304,
63,
765,
275,
22672,
3767,
14,
23824,
63,
4657,
272,
1390,
63,
2301,
63,
354,
63,
1267,
275,
4233,
221,
327,
3967,
4329,
14,
709,
642,
365,
7960,
339,
485,
521,
63,
926,
262,
63,
15264,
275,
469,
267,
488,
26,
5310,
761,
10750,
267,
298,
4189,
17,
45,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
10709,
18106,
267,
298,
4189,
17,
40,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
10213,
18106,
267,
298,
48,
17,
36,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
5745,
36,
18106,
267,
298,
48,
17,
55,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
11178,
18106,
267,
298,
48,
17,
45,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
16413,
18106,
267,
298,
48,
16,
14,
821,
57,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
49,
18106,
267,
298,
48,
17,
57,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
19216,
18106,
272,
789,
339,
768,
3744,
272,
347,
9463,
63,
475,
63,
3583,
7574,
8,
1886,
9,
1035,
620,
26,
267,
372,
334,
288,
298,
18898,
12925,
18898,
8,
5390,
283,
21740,
13,
614,
13,
614,
7,
435,
11459,
761,
93,
1182,
31200,
9,
4319,
32745,
8,
16,
9,
298,
288,
298,
619,
378,
430,
15059,
378,
9,
435,
334,
2561,
761,
93,
30920,
31200,
9,
627,
8729,
3204,
283,
383,
26,
383,
26,
614,
7,
298,
288,
298,
2979,
1230,
2296,
5795,
1864,
36,
9,
4319,
32745,
8,
16,
430,
2,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
504,
1613,
409,
14,
697,
63,
3908,
63,
7273,
14,
1095,
492,
3523,
8524,
5307,
12,
22672,
3767,
421,
199,
533,
13861,
1517,
8524,
5307,
8,
1563,
8524,
5307,
304,
272,
408,
22080,
367,
13861,
1517,
6249,
1041,
339,
6869,
275,
298,
2967,
576,
2,
272,
6869,
63,
354,
275,
298,
8600,
1517,
2,
272,
2304,
63,
765,
275,
22672,
3767,
14,
23824,
63,
4657,
272,
1390,
63,
2301,
63,
354,
63,
1267,
275,
4233,
221,
327,
3967,
4329,
14,
709,
642,
365,
7960,
339,
485,
521,
63,
926,
262,
63,
15264,
275,
469,
267,
488,
26,
5310,
761,
10750,
267,
298,
4189,
17,
45,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
10709,
18106,
267,
298,
4189,
17,
40,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
10213,
18106,
267,
298,
48,
17,
36,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
5745,
36,
18106,
267,
298,
48,
17,
55,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
11178,
18106,
267,
298,
48,
17,
45,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
16413,
18106,
267,
298,
48,
16,
14,
821,
57,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
49,
18106,
267,
298,
48,
17,
57,
582,
298,
22346,
8,
18898,
2561,
761,
93,
465,
30131,
395,
283,
19216,
18106,
272,
789,
339,
768,
3744,
272,
347,
9463,
63,
475,
63,
3583,
7574,
8,
1886,
9,
1035,
620,
26,
267,
372,
334,
288,
298,
18898,
12925,
18898,
8,
5390,
283,
21740,
13,
614,
13,
614,
7,
435,
11459,
761,
93,
1182,
31200,
9,
4319,
32745,
8,
16,
9,
298,
288,
298,
619,
378,
430,
15059,
378,
9,
435,
334,
2561,
761,
93,
30920,
31200,
9,
627,
8729,
3204,
283,
383,
26,
383,
26,
614,
7,
298,
288,
298,
2979,
1230,
2296,
5795,
1864,
36,
9,
4319,
32745,
8,
16,
430,
2,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
|
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import login as django_login, \
authenticate as django_authenticate, logout as django_logout, \
REDIRECT_FIELD_NAME
from google.appengine.api import users
# redirects to the google user api generated login url
def login(request, redirect_field_name=REDIRECT_FIELD_NAME):
redirect_to = request.REQUEST.get(redirect_field_name, '')
if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
redirect_to = '/'
return HttpResponseRedirect(users.create_login_url(
'%s?%s=%s' % (reverse('google_authenticate'), REDIRECT_FIELD_NAME,
redirect_to)))
# redirects to the google user api generated login url
def logout(request):
django_logout(request)
return HttpResponseRedirect(users.create_logout_url("/"))
def authenticate(request):
user = django_authenticate()
if user is not None:
django_login(request, user)
#redirect to valid logged page (preferably the user's request)
redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
redirect_to = '/'
return HttpResponseRedirect(redirect_to)
else:
# return invalid login page
return HttpResponseRedirect('/invalid')
|
apache-2.0
|
[
504,
1639,
14,
1014,
492,
14935,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
2828,
14,
1178,
492,
4676,
465,
1639,
63,
2886,
12,
971,
272,
12895,
465,
1639,
63,
13975,
12,
22079,
465,
1639,
63,
11646,
12,
971,
272,
820,
7458,
4168,
63,
8609,
63,
2339,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
4390,
421,
199,
3,
17784,
370,
314,
6233,
922,
2986,
4046,
4676,
1166,
199,
318,
4676,
8,
1069,
12,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
304,
272,
4660,
63,
475,
275,
1056,
14,
6780,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
4074,
272,
340,
440,
4660,
63,
475,
503,
18290,
7,
315,
4660,
63,
475,
503,
283,
283,
315,
4660,
63,
475,
26,
267,
4660,
63,
475,
275,
7324,
272,
372,
14935,
8,
3707,
14,
981,
63,
2886,
63,
633,
8,
288,
1543,
83,
25790,
83,
2458,
83,
7,
450,
334,
4471,
360,
3098,
63,
13975,
659,
820,
7458,
4168,
63,
8609,
63,
2339,
12,
2079,
4660,
63,
475,
1724,
421,
199,
3,
17784,
370,
314,
6233,
922,
2986,
4046,
4676,
1166,
199,
318,
22079,
8,
1069,
304,
272,
1639,
63,
11646,
8,
1069,
9,
272,
372,
14935,
8,
3707,
14,
981,
63,
11646,
63,
633,
4769,
2237,
421,
199,
318,
12895,
8,
1069,
304,
272,
922,
275,
1639,
63,
13975,
342,
272,
340,
922,
365,
440,
488,
26,
267,
1639,
63,
2886,
8,
1069,
12,
922,
9,
267,
327,
4876,
370,
1686,
10367,
2034,
334,
24283,
6665,
314,
922,
1159,
1056,
9,
267,
4660,
63,
475,
275,
1056,
14,
6780,
14,
362,
8,
19747,
63,
8609,
63,
2339,
12,
4074,
267,
340,
440,
4660,
63,
475,
503,
18290,
7,
315,
4660,
63,
475,
503,
283,
283,
315,
4660,
63,
475,
26,
288,
4660,
63,
475,
275,
7324,
267,
372,
14935,
8,
4876,
63,
475,
9,
272,
587,
26,
267,
327,
372,
3866,
4676,
2034,
267,
372,
14935,
2336,
3197,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1014,
492,
14935,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
2828,
14,
1178,
492,
4676,
465,
1639,
63,
2886,
12,
971,
272,
12895,
465,
1639,
63,
13975,
12,
22079,
465,
1639,
63,
11646,
12,
971,
272,
820,
7458,
4168,
63,
8609,
63,
2339,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
4390,
421,
199,
3,
17784,
370,
314,
6233,
922,
2986,
4046,
4676,
1166,
199,
318,
4676,
8,
1069,
12,
4660,
63,
698,
63,
354,
29,
19747,
63,
8609,
63,
2339,
304,
272,
4660,
63,
475,
275,
1056,
14,
6780,
14,
362,
8,
4876,
63,
698,
63,
354,
12,
4074,
272,
340,
440,
4660,
63,
475,
503,
18290,
7,
315,
4660,
63,
475,
503,
283,
283,
315,
4660,
63,
475,
26,
267,
4660,
63,
475,
275,
7324,
272,
372,
14935,
8,
3707,
14,
981,
63,
2886,
63,
633,
8,
288,
1543,
83,
25790,
83,
2458,
83,
7,
450,
334,
4471,
360,
3098,
63,
13975,
659,
820,
7458,
4168,
63,
8609,
63,
2339,
12,
2079,
4660,
63,
475,
1724,
421,
199,
3,
17784,
370,
314,
6233,
922,
2986,
4046,
4676,
1166,
199,
318,
22079,
8,
1069,
304,
272,
1639,
63,
11646,
8,
1069,
9,
272,
372,
14935,
8,
3707,
14,
981,
63,
11646,
63,
633,
4769,
2237,
421,
199,
318,
12895,
8,
1069,
304,
272,
922,
275,
1639,
63,
13975,
342,
272,
340,
922,
365,
440,
488,
26,
267,
1639,
63,
2886,
8,
1069,
12,
922,
9,
267,
327,
4876,
370,
1686,
10367,
2034,
334,
24283,
6665,
314,
922,
1159,
1056,
9,
267,
4660,
63,
475,
275,
1056,
14,
6780,
14,
362,
8,
19747,
63,
8609,
63,
2339,
12,
4074,
267,
340,
440,
4660,
63,
475,
503,
18290,
7,
315,
4660,
63,
475,
503,
283,
283,
315,
4660,
63,
475,
26,
288,
4660,
63,
475,
275,
7324,
267,
372,
14935,
8,
4876,
63,
475,
9,
272,
587,
26,
267,
327,
372,
3866,
4676,
2034,
267,
372,
14935,
2336,
3197,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
miyucy/oppia
|
extensions/objects/models/objects.py
|
1
|
13859
|
# coding: utf-8
#
# Copyright 2014 The Oppia 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.
"""Classes for interpreting typed objects in Oppia."""
__author__ = 'Sean Lip'
import base64
import copy
import os
import StringIO
import tarfile
import feconf
import schema_utils
import utils
class BaseObject(object):
"""Base object class.
This is the superclass for typed object specifications in Oppia, such as
SanitizedUrl and CoordTwoDim.
Typed objects are initialized from a raw Python object which is expected to
be derived from a JSON object. They are validated and normalized to basic
Python objects (primitive types combined via lists and dicts; no sets or
tuples).
"""
# These values should be overridden in subclasses.
description = ''
edit_html_filename = None
edit_js_filename = None
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object.
Returns:
a normalized Python object describing the Object specified by this
class.
Raises:
TypeError: if the Python object cannot be normalized.
"""
return schema_utils.normalize_against_schema(raw, cls._schema)
@classmethod
def has_editor_js_template(cls):
return cls.edit_js_filename is not None
@classmethod
def get_editor_js_template(cls):
if cls.edit_js_filename is None:
raise Exception(
'There is no editor template defined for objects of type %s' %
cls.__name__)
return utils.get_file_contents(os.path.join(
os.getcwd(), feconf.OBJECT_TEMPLATES_DIR,
'%s.js' % cls.edit_js_filename))
@classmethod
def get_editor_html_template(cls):
if cls.edit_html_filename is None:
raise Exception(
'There is no editor template defined for objects of type %s' %
cls.__name__)
return utils.get_file_contents(os.path.join(
os.getcwd(), feconf.OBJECT_TEMPLATES_DIR,
'%s.html' % cls.edit_html_filename))
class Null(BaseObject):
"""Class for a null object."""
description = 'A null object.'
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object."""
return None
class Boolean(BaseObject):
"""Class for booleans."""
description = 'A boolean.'
edit_html_filename = 'boolean_editor'
edit_js_filename = 'BooleanEditor'
_schema = {
'type': 'bool'
}
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object."""
if raw is None or raw == '':
raw = False
return schema_utils.normalize_against_schema(raw, cls._schema)
class Real(BaseObject):
"""Real number class."""
description = 'A real number.'
edit_html_filename = 'real_editor'
edit_js_filename = 'RealEditor'
_schema = {
'type': 'float'
}
class Int(BaseObject):
"""Integer class."""
description = 'An integer.'
edit_html_filename = 'int_editor'
edit_js_filename = 'IntEditor'
_schema = {
'type': 'int'
}
class NonnegativeInt(BaseObject):
"""Nonnegative integer class."""
description = 'A non-negative integer.'
edit_html_filename = 'nonnegative_int_editor'
edit_js_filename = 'NonnegativeIntEditor'
_schema = {
'type': 'int',
'post_normalizers': [{
'id': 'require_at_least',
'min_value': 0
}]
}
class CodeEvaluation(BaseObject):
"""Evaluation result of programming code."""
description = 'Code and its evaluation results.'
_schema = {
'type': 'dict',
'properties': {
'code': {
'type': 'unicode'
},
'output': {
'type': 'unicode'
},
'evaluation': {
'type': 'unicode'
},
'error': {
'type': 'unicode'
}
}
}
class CoordTwoDim(BaseObject):
"""2D coordinate class."""
description = 'A two-dimensional coordinate (a pair of reals).'
edit_html_filename = 'coord_two_dim_editor'
edit_js_filename = 'CoordTwoDimEditor'
_schema = {
'type': 'list',
'length': 2,
'items': {
'type': 'float'
}
}
class ListOfUnicodeString(BaseObject):
"""List class."""
description = 'A list.'
edit_html_filename = 'list_editor'
edit_js_filename = 'ListOfUnicodeStringEditor'
_schema = {
'type': 'list',
'items': {
'type': 'unicode'
}
}
class SetOfUnicodeString(BaseObject):
"""Class for sets of UnicodeStrings."""
description = 'A set (a list with unique elements) of unicode strings.'
edit_html_filename = 'list_editor'
edit_js_filename = 'SetOfUnicodeStringEditor'
_schema = {
'type': 'list',
'items': {
'type': 'unicode'
},
'post_normalizers': [{
'id': 'uniquify'
}]
}
class UnicodeString(BaseObject):
"""Unicode string class."""
description = 'A unicode string.'
edit_html_filename = 'unicode_string_editor'
edit_js_filename = 'UnicodeStringEditor'
_schema = {
'type': 'unicode',
}
class NormalizedString(BaseObject):
"""Unicode string with spaces collapsed."""
description = 'A unicode string with adjacent whitespace collapsed.'
edit_html_filename = 'unicode_string_editor'
edit_js_filename = 'NormalizedStringEditor'
_schema = {
'type': 'unicode',
'post_normalizers': [{
'id': 'normalize_spaces'
}]
}
class MathLatexString(BaseObject):
"""Math LaTeX string class"""
description = 'A LaTeX string.'
edit_html_filename = 'math_latex_string_editor'
edit_js_filename = 'MathLatexStringEditor'
_schema = {
'type': 'unicode',
}
class Html(BaseObject):
"""HTML string class."""
description = 'An HTML string.'
edit_html_filename = 'html_editor'
edit_js_filename = 'HtmlEditor'
_schema = {
'type': 'html',
}
class TabContent(BaseObject):
"""Class for editing the content of a single tab.
The object is described by a dict with two keys: 'title' and 'content'.
These have types UnicodeString and Html respectively.
"""
description = 'Content for a single tab.'
edit_html_filename = 'tab_content_editor'
edit_js_filename = 'TabContentEditor'
_schema = {
'type': 'dict',
'properties': {
'title': {
'type': 'unicode',
'post_normalizers': [{
'id': 'require_nonempty'
}]
},
'content': {
'type': 'html',
}
}
}
class ListOfTabContent(BaseObject):
"""Class for editing the content of a tabbed view.
The object is described by a list of dicts, each representing a TabContent
object.
"""
description = 'Content for a set of tabs.'
edit_html_filename = 'list_editor'
edit_js_filename = 'ListOfTabContentEditor'
_schema = {
'type': 'list',
'items': {
'type': 'dict',
'properties': {
'title': {
'type': 'unicode',
'post_normalizers': [{
'id': 'require_nonempty'
}]
},
'content': {
'type': 'html'
}
}
}
}
class SanitizedUrl(BaseObject):
"""HTTP or HTTPS url string class."""
description = 'An HTTP or HTTPS url.'
edit_html_filename = 'unicode_string_editor'
edit_js_filename = 'SanitizedUrlEditor'
_schema = {
'type': 'unicode',
'post_normalizers': [{
'id': 'sanitize_url'
}]
}
class MusicPhrase(BaseObject):
"""List of Objects that represent a musical phrase."""
description = ('A musical phrase that contains zero or more notes, rests, '
'and time signature.')
edit_html_filename = 'music_phrase_editor'
edit_js_filename = 'MusicPhraseEditor'
_schema = {
'type': 'list',
'items': {
'type': 'dict',
'properties': {
'readableNoteName': {
'type': 'unicode',
'post_normalizers': [{
'id': 'require_is_one_of',
'choices': [
'C4', 'D4', 'E4', 'F4', 'G4', 'A4', 'B4', 'C5',
'D5', 'E5', 'F5', 'G5', 'A5'
]
}]
},
'noteDuration': {
'type': 'dict',
'properties': {
'num': {
'type': 'int',
'post_normalizers': [{
'id': 'require_at_least',
'min_value': 1
}]
},
'den': {
'type': 'int',
'post_normalizers': [{
'id': 'require_at_least',
'min_value': 1
}]
}
}
},
}
}
}
class TarFileString(BaseObject):
"""A unicode string with the base64-encoded content of a tar file"""
description = 'A string with base64-encoded content of a tar file'
_schema = {
'type': 'unicode',
}
@classmethod
def normalize(cls, raw):
"""Reads `raw` as a unicode string representing a tar file and returns
the base64-encoded contents."""
raw = schema_utils.normalize_against_schema(raw, cls._schema)
raw = base64.b64decode(raw)
return tarfile.open(fileobj=StringIO.StringIO(raw), mode='r:gz')
class Filepath(BaseObject):
"""A string representing a filepath.
The path will be prefixed with '[exploration_id]/assets'.
"""
description = 'A string that represents a filepath'
edit_html_filename = 'filepath_editor'
edit_js_filename = 'FilepathEditor'
_schema = {
'type': 'unicode',
}
class CheckedProof(BaseObject):
"""A proof attempt and any errors it makes."""
description = 'A proof attempt and any errors it makes.'
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object."""
try:
assert isinstance(raw, dict)
assert isinstance(raw['assumptions_string'], basestring)
assert isinstance(raw['target_string'], basestring)
assert isinstance(raw['proof_string'], basestring)
assert raw['correct'] in [True, False]
if not raw['correct']:
assert isinstance(raw['error_category'], basestring)
assert isinstance(raw['error_code'], basestring)
assert isinstance(raw['error_message'], basestring)
assert isinstance(raw['error_line_number'], int)
return copy.deepcopy(raw)
except Exception:
raise TypeError('Cannot convert to checked proof %s' % raw)
class LogicQuestion(BaseObject):
"""A question giving a formula to prove"""
description = 'A question giving a formula to prove.'
edit_html_filename = 'logic_question_editor'
edit_js_filename = 'LogicQuestionEditor'
@classmethod
def normalize(cls, raw):
"""Validates and normalizes a raw Python object."""
def _validateExpression(expression):
assert isinstance(expression, dict)
assert isinstance(expression['top_kind_name'], basestring)
assert isinstance(expression['top_operator_name'], basestring)
_validateExpressionArray(expression['arguments'])
_validateExpressionArray(expression['dummies'])
def _validateExpressionArray(array):
assert isinstance(array, list)
for item in array:
_validateExpression(item)
try:
assert isinstance(raw, dict)
_validateExpressionArray(raw['assumptions'])
_validateExpressionArray(raw['results'])
assert isinstance(raw['default_proof_string'], basestring)
return copy.deepcopy(raw)
except Exception:
raise TypeError('Cannot convert to a logic question %s' % raw)
class LogicErrorCategory(BaseObject):
"""A string from a list of possible categories"""
description = 'One of the possible error categories of a logic proof.'
edit_html_filename = 'logic_error_category_editor'
edit_js_filename = 'LogicErrorCategoryEditor'
_schema = {
'type': 'unicode',
'post_normalizers': [{
'id': 'require_is_one_of',
'choices': [
'parsing', 'typing', 'line', 'layout', 'variables', 'logic',
'target', 'mistake'
]
}]
}
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
6927,
710,
593,
802,
4674,
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,
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,
13,
1311,
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,
624,
15711,
367,
6421,
1337,
20041,
2251,
315,
593,
802,
4674,
1041,
199,
199,
363,
2502,
363,
275,
283,
1513,
290,
491,
711,
7,
199,
199,
646,
1300,
772,
199,
646,
1331,
199,
646,
747,
199,
646,
5228,
199,
646,
13608,
199,
199,
646,
1964,
2190,
199,
646,
4177,
63,
1208,
199,
646,
3778,
421,
199,
533,
3523,
1692,
8,
785,
304,
272,
408,
1563,
909,
1021,
14,
339,
961,
365,
314,
17035,
367,
20041,
909,
28754,
315,
593,
802,
4674,
12,
4066,
465,
272,
428,
9385,
7068,
6417,
436,
1849,
2181,
11467,
19156,
14,
339,
31906,
2251,
787,
10038,
687,
282,
3066,
2018,
909,
1314,
365,
1420,
370,
272,
506,
7131,
687,
282,
4840,
909,
14,
9322,
787,
16468,
436,
9657,
370,
5678,
272,
2018,
2251,
334,
16161,
2943,
12149,
4799,
5548,
436,
10809,
27,
949,
5951,
503,
272,
6346,
680,
272,
408,
339,
327,
5723,
1338,
1077,
506,
10087,
315,
9180,
14,
272,
1369,
275,
2125,
272,
5283,
63,
1360,
63,
1501,
275,
488,
272,
5283,
63,
3596,
63,
1501,
275,
488,
339,
768,
3744,
272,
347,
7666,
8,
1886,
12,
3066,
304,
267,
408,
3490,
2335,
436,
3293,
6491,
282,
3066,
2018,
909,
14,
398,
1803,
26,
881,
282,
9657,
2018,
909,
13660,
314,
6935,
2013,
701,
642,
881,
1021,
14,
398,
6218,
26,
881,
3146,
26,
340,
314,
2018,
909,
3913,
506,
9657,
14,
267,
408,
267,
372,
4177,
63,
1208,
14,
7721,
63,
17777,
63,
3629,
8,
1773,
12,
843,
423,
3629,
9,
339,
768,
3744,
272,
347,
965,
63,
7515,
63,
3596,
63,
1160,
8,
1886,
304,
267,
372,
843,
14,
3773,
63,
3596,
63,
1501,
365,
440,
488,
339,
768,
3744,
272,
347,
664,
63,
7515,
63,
3596,
63,
1160,
8,
1886,
304,
267,
340,
843,
14,
3773,
63,
3596,
63,
1501,
365,
488,
26,
288,
746,
2186,
8,
355,
283,
10924,
365,
949,
8823,
1978,
3247,
367,
2251,
402,
730,
450,
83,
7,
450,
355,
843,
855,
354,
3368,
267,
372,
3778,
14,
362,
63,
493,
63,
4407,
8,
736,
14,
515,
14,
904,
8,
288,
747,
14,
9458,
1062,
1964,
2190,
14,
9868,
63,
25437,
63,
3022,
12,
288,
1543,
83,
14,
3596,
7,
450,
843,
14,
3773,
63,
3596,
63,
1501,
430,
339,
768,
3744,
272,
347,
664,
63,
7515,
63,
1360,
63,
1160,
8,
1886,
304,
267,
340,
843,
14,
3773,
63,
1360,
63,
1501,
365,
488,
26,
288,
746,
2186,
8,
355,
283,
10924,
365,
949,
8823,
1978,
3247,
367,
2251,
402,
730,
450,
83,
7,
450,
355,
843,
855,
354,
3368,
267,
372,
3778,
14,
362,
63,
493,
63,
4407,
8,
736,
14,
515,
14,
904,
8,
288,
747,
14,
9458,
1062,
1964,
2190,
14,
9868,
63,
25437,
63,
3022,
12,
288,
1543,
83,
14,
1360,
7,
450,
843,
14,
3773,
63,
1360,
63,
1501,
430,
421,
199,
533,
12119,
8,
1563,
1692,
304,
272,
408,
2543,
367,
282,
2973,
909,
1041,
339,
1369,
275,
283,
33,
2973,
909,
3530,
339,
768,
3744,
272,
347,
7666,
8,
1886,
12,
3066,
304,
267,
408,
3490,
2335,
436,
3293,
6491,
282,
3066,
2018,
909,
1041,
267,
372,
488,
421,
199,
533,
9411,
8,
1563,
1692,
304,
272,
408,
2543,
367,
1234,
16721,
796,
1041,
339,
1369,
275,
283,
33,
5046,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
4871,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
4082,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
2245,
7,
272,
789,
339,
768,
3744,
272,
347,
7666,
8,
1886,
12,
3066,
304,
267,
408,
3490,
2335,
436,
3293,
6491,
282,
3066,
2018,
909,
1041,
267,
340,
3066,
365,
488,
503,
3066,
508,
8061,
288,
3066,
275,
756,
398,
372,
4177,
63,
1208,
14,
7721,
63,
17777,
63,
3629,
8,
1773,
12,
843,
423,
3629,
9,
421,
199,
533,
14849,
8,
1563,
1692,
304,
272,
408,
10099,
1329,
1021,
1041,
339,
1369,
275,
283,
33,
3363,
1329,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
3093,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
10099,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
1609,
7,
272,
789,
421,
199,
533,
9805,
8,
1563,
1692,
304,
272,
408,
2674,
1021,
1041,
339,
1369,
275,
283,
2493,
3000,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
442,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
3241,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
442,
7,
272,
789,
421,
199,
533,
10172,
7371,
3241,
8,
1563,
1692,
304,
272,
408,
6932,
7371,
3000,
1021,
1041,
339,
1369,
275,
283,
33,
2222,
13,
7371,
3000,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
2865,
7371,
63,
442,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
6932,
7371,
3241,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
442,
297,
267,
283,
1932,
63,
3302,
6315,
356,
8910,
288,
283,
344,
356,
283,
4365,
63,
292,
63,
11790,
297,
288,
283,
827,
63,
585,
356,
378,
267,
14877,
272,
789,
421,
199,
533,
5495,
29786,
8,
1563,
1692,
304,
272,
408,
29786,
754,
402,
31768,
1233,
1041,
339,
1369,
275,
283,
3034
] |
[
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
6927,
710,
593,
802,
4674,
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,
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,
13,
1311,
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,
624,
15711,
367,
6421,
1337,
20041,
2251,
315,
593,
802,
4674,
1041,
199,
199,
363,
2502,
363,
275,
283,
1513,
290,
491,
711,
7,
199,
199,
646,
1300,
772,
199,
646,
1331,
199,
646,
747,
199,
646,
5228,
199,
646,
13608,
199,
199,
646,
1964,
2190,
199,
646,
4177,
63,
1208,
199,
646,
3778,
421,
199,
533,
3523,
1692,
8,
785,
304,
272,
408,
1563,
909,
1021,
14,
339,
961,
365,
314,
17035,
367,
20041,
909,
28754,
315,
593,
802,
4674,
12,
4066,
465,
272,
428,
9385,
7068,
6417,
436,
1849,
2181,
11467,
19156,
14,
339,
31906,
2251,
787,
10038,
687,
282,
3066,
2018,
909,
1314,
365,
1420,
370,
272,
506,
7131,
687,
282,
4840,
909,
14,
9322,
787,
16468,
436,
9657,
370,
5678,
272,
2018,
2251,
334,
16161,
2943,
12149,
4799,
5548,
436,
10809,
27,
949,
5951,
503,
272,
6346,
680,
272,
408,
339,
327,
5723,
1338,
1077,
506,
10087,
315,
9180,
14,
272,
1369,
275,
2125,
272,
5283,
63,
1360,
63,
1501,
275,
488,
272,
5283,
63,
3596,
63,
1501,
275,
488,
339,
768,
3744,
272,
347,
7666,
8,
1886,
12,
3066,
304,
267,
408,
3490,
2335,
436,
3293,
6491,
282,
3066,
2018,
909,
14,
398,
1803,
26,
881,
282,
9657,
2018,
909,
13660,
314,
6935,
2013,
701,
642,
881,
1021,
14,
398,
6218,
26,
881,
3146,
26,
340,
314,
2018,
909,
3913,
506,
9657,
14,
267,
408,
267,
372,
4177,
63,
1208,
14,
7721,
63,
17777,
63,
3629,
8,
1773,
12,
843,
423,
3629,
9,
339,
768,
3744,
272,
347,
965,
63,
7515,
63,
3596,
63,
1160,
8,
1886,
304,
267,
372,
843,
14,
3773,
63,
3596,
63,
1501,
365,
440,
488,
339,
768,
3744,
272,
347,
664,
63,
7515,
63,
3596,
63,
1160,
8,
1886,
304,
267,
340,
843,
14,
3773,
63,
3596,
63,
1501,
365,
488,
26,
288,
746,
2186,
8,
355,
283,
10924,
365,
949,
8823,
1978,
3247,
367,
2251,
402,
730,
450,
83,
7,
450,
355,
843,
855,
354,
3368,
267,
372,
3778,
14,
362,
63,
493,
63,
4407,
8,
736,
14,
515,
14,
904,
8,
288,
747,
14,
9458,
1062,
1964,
2190,
14,
9868,
63,
25437,
63,
3022,
12,
288,
1543,
83,
14,
3596,
7,
450,
843,
14,
3773,
63,
3596,
63,
1501,
430,
339,
768,
3744,
272,
347,
664,
63,
7515,
63,
1360,
63,
1160,
8,
1886,
304,
267,
340,
843,
14,
3773,
63,
1360,
63,
1501,
365,
488,
26,
288,
746,
2186,
8,
355,
283,
10924,
365,
949,
8823,
1978,
3247,
367,
2251,
402,
730,
450,
83,
7,
450,
355,
843,
855,
354,
3368,
267,
372,
3778,
14,
362,
63,
493,
63,
4407,
8,
736,
14,
515,
14,
904,
8,
288,
747,
14,
9458,
1062,
1964,
2190,
14,
9868,
63,
25437,
63,
3022,
12,
288,
1543,
83,
14,
1360,
7,
450,
843,
14,
3773,
63,
1360,
63,
1501,
430,
421,
199,
533,
12119,
8,
1563,
1692,
304,
272,
408,
2543,
367,
282,
2973,
909,
1041,
339,
1369,
275,
283,
33,
2973,
909,
3530,
339,
768,
3744,
272,
347,
7666,
8,
1886,
12,
3066,
304,
267,
408,
3490,
2335,
436,
3293,
6491,
282,
3066,
2018,
909,
1041,
267,
372,
488,
421,
199,
533,
9411,
8,
1563,
1692,
304,
272,
408,
2543,
367,
1234,
16721,
796,
1041,
339,
1369,
275,
283,
33,
5046,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
4871,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
4082,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
2245,
7,
272,
789,
339,
768,
3744,
272,
347,
7666,
8,
1886,
12,
3066,
304,
267,
408,
3490,
2335,
436,
3293,
6491,
282,
3066,
2018,
909,
1041,
267,
340,
3066,
365,
488,
503,
3066,
508,
8061,
288,
3066,
275,
756,
398,
372,
4177,
63,
1208,
14,
7721,
63,
17777,
63,
3629,
8,
1773,
12,
843,
423,
3629,
9,
421,
199,
533,
14849,
8,
1563,
1692,
304,
272,
408,
10099,
1329,
1021,
1041,
339,
1369,
275,
283,
33,
3363,
1329,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
3093,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
10099,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
1609,
7,
272,
789,
421,
199,
533,
9805,
8,
1563,
1692,
304,
272,
408,
2674,
1021,
1041,
339,
1369,
275,
283,
2493,
3000,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
442,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
3241,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
442,
7,
272,
789,
421,
199,
533,
10172,
7371,
3241,
8,
1563,
1692,
304,
272,
408,
6932,
7371,
3000,
1021,
1041,
339,
1369,
275,
283,
33,
2222,
13,
7371,
3000,
3530,
272,
5283,
63,
1360,
63,
1501,
275,
283,
2865,
7371,
63,
442,
63,
7515,
7,
272,
5283,
63,
3596,
63,
1501,
275,
283,
6932,
7371,
3241,
10423,
7,
339,
485,
3629,
275,
469,
267,
283,
466,
356,
283,
442,
297,
267,
283,
1932,
63,
3302,
6315,
356,
8910,
288,
283,
344,
356,
283,
4365,
63,
292,
63,
11790,
297,
288,
283,
827,
63,
585,
356,
378,
267,
14877,
272,
789,
421,
199,
533,
5495,
29786,
8,
1563,
1692,
304,
272,
408,
29786,
754,
402,
31768,
1233,
1041,
339,
1369,
275,
283,
3034,
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,
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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
] |
ssanderson/numpy
|
numpy/f2py/tests/test_callback.py
|
145
|
3040
|
from __future__ import division, absolute_import, print_function
import math
import textwrap
from numpy import array
from numpy.testing import run_module_suite, assert_, assert_equal, dec
import util
class TestF77Callback(util.F2PyTest):
code = """
subroutine t(fun,a)
integer a
cf2py intent(out) a
external fun
call fun(a)
end
subroutine func(a)
cf2py intent(in,out) a
integer a
a = a + 11
end
subroutine func0(a)
cf2py intent(out) a
integer a
a = 11
end
subroutine t2(a)
cf2py intent(callback) fun
integer a
cf2py intent(out) a
external fun
call fun(a)
end
subroutine string_callback(callback, a)
external callback
double precision callback
double precision a
character*1 r
cf2py intent(out) a
r = 'r'
a = callback(r)
end
"""
@dec.slow
def test_all(self):
for name in "t,t2".split(","):
self.check_function(name)
@dec.slow
def test_docstring(self):
expected = """
a = t(fun,[fun_extra_args])
Wrapper for ``t``.
Parameters
----------
fun : call-back function
Other Parameters
----------------
fun_extra_args : input tuple, optional
Default: ()
Returns
-------
a : int
Notes
-----
Call-back functions::
def fun(): return a
Return objects:
a : int
"""
assert_equal(self.module.t.__doc__, textwrap.dedent(expected).lstrip())
def check_function(self, name):
t = getattr(self.module, name)
r = t(lambda: 4)
assert_(r == 4, repr(r))
r = t(lambda a: 5, fun_extra_args=(6,))
assert_(r == 5, repr(r))
r = t(lambda a: a, fun_extra_args=(6,))
assert_(r == 6, repr(r))
r = t(lambda a: 5 + a, fun_extra_args=(7,))
assert_(r == 12, repr(r))
r = t(lambda a: math.degrees(a), fun_extra_args=(math.pi,))
assert_(r == 180, repr(r))
r = t(math.degrees, fun_extra_args=(math.pi,))
assert_(r == 180, repr(r))
r = t(self.module.func, fun_extra_args=(6,))
assert_(r == 17, repr(r))
r = t(self.module.func0)
assert_(r == 11, repr(r))
r = t(self.module.func0._cpointer)
assert_(r == 11, repr(r))
class A(object):
def __call__(self):
return 7
def mth(self):
return 9
a = A()
r = t(a)
assert_(r == 7, repr(r))
r = t(a.mth)
assert_(r == 9, repr(r))
def test_string_callback(self):
def callback(code):
if code == 'r':
return 0
else:
return 1
f = getattr(self.module, 'string_callback')
r = f(callback)
assert_(r == 0, repr(r))
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
3473,
199,
646,
13390,
199,
199,
504,
2680,
492,
1625,
199,
504,
2680,
14,
4776,
492,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
9700,
199,
646,
4884,
421,
199,
533,
1379,
38,
1138,
2806,
8,
1974,
14,
38,
18,
2713,
774,
304,
272,
1233,
275,
408,
2126,
1007,
17765,
307,
8,
7036,
12,
65,
9,
2126,
3000,
282,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
5957,
9627,
2126,
1240,
9627,
8,
65,
9,
2126,
1284,
10817,
1007,
17765,
2562,
8,
65,
9,
199,
2177,
18,
647,
221,
21020,
8,
262,
12,
548,
9,
282,
2126,
3000,
282,
2126,
282,
275,
282,
435,
4119,
2126,
1284,
10817,
1007,
17765,
2562,
16,
8,
65,
9,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
3000,
282,
2126,
282,
275,
4119,
2126,
1284,
10817,
1007,
17765,
307,
18,
8,
65,
9,
199,
2177,
18,
647,
221,
21020,
8,
3058,
9,
9627,
2126,
3000,
282,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
5957,
9627,
2126,
1240,
9627,
8,
65,
9,
2126,
1284,
10817,
1007,
17765,
1059,
63,
3058,
8,
3058,
12,
282,
9,
2126,
5957,
3233,
2126,
4270,
7151,
3233,
2126,
4270,
7151,
282,
2126,
4528,
10,
17,
519,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
519,
275,
283,
82,
7,
2126,
282,
275,
3233,
8,
82,
9,
2126,
1284,
339,
408,
339,
768,
7778,
14,
14362,
272,
347,
511,
63,
452,
8,
277,
304,
267,
367,
536,
315,
298,
84,
12,
84,
18,
1674,
1294,
8,
2266,
304,
288,
291,
14,
1074,
63,
1593,
8,
354,
9,
339,
768,
7778,
14,
14362,
272,
347,
511,
63,
12485,
8,
277,
304,
267,
1420,
275,
408,
267,
282,
275,
307,
8,
7036,
14343,
7036,
63,
2911,
63,
589,
566,
398,
21947,
367,
1124,
84,
4345,
398,
3897,
267,
4143,
267,
9627,
520,
1240,
13,
894,
805,
398,
5439,
3897,
267,
10652,
267,
9627,
63,
2911,
63,
589,
520,
1324,
2008,
12,
2716,
288,
3758,
26,
6248,
398,
1803,
267,
5514,
267,
282,
520,
1109,
398,
8144,
267,
9063,
267,
6523,
13,
894,
3423,
447,
8592,
347,
9627,
837,
372,
282,
881,
1432,
2251,
26,
288,
282,
520,
1109,
267,
408,
267,
702,
63,
1452,
8,
277,
14,
578,
14,
84,
855,
1301,
3108,
13390,
14,
14674,
8,
2062,
680,
10124,
1012,
339,
347,
1104,
63,
1593,
8,
277,
12,
536,
304,
267,
307,
275,
2519,
8,
277,
14,
578,
12,
536,
9,
267,
519,
275,
307,
8,
2734,
26,
841,
9,
267,
702,
2531,
82,
508,
841,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
959,
12,
9627,
63,
2911,
63,
589,
2687,
22,
4641,
267,
702,
2531,
82,
508,
959,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
282,
12,
9627,
63,
2911,
63,
589,
2687,
22,
4641,
267,
702,
2531,
82,
508,
1227,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
959,
435,
282,
12,
9627,
63,
2911,
63,
589,
2687,
23,
4641,
267,
702,
2531,
82,
508,
3144,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
3473,
14,
20251,
8,
65,
395,
9627,
63,
2911,
63,
589,
2687,
3442,
14,
1038,
4641,
267,
702,
2531,
82,
508,
13576,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
3442,
14,
20251,
12,
9627,
63,
2911,
63,
589,
2687,
3442,
14,
1038,
4641,
267,
702,
2531,
82,
508,
13576,
12,
4700,
8,
82,
430,
398,
519,
275,
307,
8,
277,
14,
578,
14,
1532,
12,
9627,
63,
2911,
63,
589,
2687,
22,
4641,
267,
702,
2531,
82,
508,
5557,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
277,
14,
578,
14,
1532,
16,
9,
267,
702,
2531,
82,
508,
4119,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
277,
14,
578,
14,
1532,
16,
423,
67,
3929,
9,
267,
702,
2531,
82,
508,
4119,
12,
4700,
8,
82,
430,
398,
1021,
437,
8,
785,
304,
953,
347,
636,
1250,
721,
277,
304,
355,
372,
1520,
953,
347,
333,
273,
8,
277,
304,
355,
372,
1749,
267,
282,
275,
437,
342,
267,
519,
275,
307,
8,
65,
9,
267,
702,
2531,
82,
508,
1520,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
65,
14,
77,
273,
9,
267,
702,
2531,
82,
508,
1749,
12,
4700,
8,
82,
430,
339,
347,
511,
63,
875,
63,
3058,
8,
277,
304,
398,
347,
3233,
8,
600,
304,
288,
340,
1233,
508,
283,
82,
356,
355,
372,
378,
288,
587,
26,
355,
372,
413,
398,
289,
275,
2519,
8,
277,
14,
578,
12,
283,
875,
63,
3058,
358,
267,
519,
275,
289,
8,
3058,
9,
267,
702,
2531,
82,
508,
378,
12,
4700,
8,
82,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
578,
63,
5768,
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
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
3473,
199,
646,
13390,
199,
199,
504,
2680,
492,
1625,
199,
504,
2680,
14,
4776,
492,
1255,
63,
578,
63,
5768,
12,
702,
3131,
702,
63,
1452,
12,
9700,
199,
646,
4884,
421,
199,
533,
1379,
38,
1138,
2806,
8,
1974,
14,
38,
18,
2713,
774,
304,
272,
1233,
275,
408,
2126,
1007,
17765,
307,
8,
7036,
12,
65,
9,
2126,
3000,
282,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
5957,
9627,
2126,
1240,
9627,
8,
65,
9,
2126,
1284,
10817,
1007,
17765,
2562,
8,
65,
9,
199,
2177,
18,
647,
221,
21020,
8,
262,
12,
548,
9,
282,
2126,
3000,
282,
2126,
282,
275,
282,
435,
4119,
2126,
1284,
10817,
1007,
17765,
2562,
16,
8,
65,
9,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
3000,
282,
2126,
282,
275,
4119,
2126,
1284,
10817,
1007,
17765,
307,
18,
8,
65,
9,
199,
2177,
18,
647,
221,
21020,
8,
3058,
9,
9627,
2126,
3000,
282,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
5957,
9627,
2126,
1240,
9627,
8,
65,
9,
2126,
1284,
10817,
1007,
17765,
1059,
63,
3058,
8,
3058,
12,
282,
9,
2126,
5957,
3233,
2126,
4270,
7151,
3233,
2126,
4270,
7151,
282,
2126,
4528,
10,
17,
519,
199,
2177,
18,
647,
221,
21020,
8,
548,
9,
282,
2126,
519,
275,
283,
82,
7,
2126,
282,
275,
3233,
8,
82,
9,
2126,
1284,
339,
408,
339,
768,
7778,
14,
14362,
272,
347,
511,
63,
452,
8,
277,
304,
267,
367,
536,
315,
298,
84,
12,
84,
18,
1674,
1294,
8,
2266,
304,
288,
291,
14,
1074,
63,
1593,
8,
354,
9,
339,
768,
7778,
14,
14362,
272,
347,
511,
63,
12485,
8,
277,
304,
267,
1420,
275,
408,
267,
282,
275,
307,
8,
7036,
14343,
7036,
63,
2911,
63,
589,
566,
398,
21947,
367,
1124,
84,
4345,
398,
3897,
267,
4143,
267,
9627,
520,
1240,
13,
894,
805,
398,
5439,
3897,
267,
10652,
267,
9627,
63,
2911,
63,
589,
520,
1324,
2008,
12,
2716,
288,
3758,
26,
6248,
398,
1803,
267,
5514,
267,
282,
520,
1109,
398,
8144,
267,
9063,
267,
6523,
13,
894,
3423,
447,
8592,
347,
9627,
837,
372,
282,
881,
1432,
2251,
26,
288,
282,
520,
1109,
267,
408,
267,
702,
63,
1452,
8,
277,
14,
578,
14,
84,
855,
1301,
3108,
13390,
14,
14674,
8,
2062,
680,
10124,
1012,
339,
347,
1104,
63,
1593,
8,
277,
12,
536,
304,
267,
307,
275,
2519,
8,
277,
14,
578,
12,
536,
9,
267,
519,
275,
307,
8,
2734,
26,
841,
9,
267,
702,
2531,
82,
508,
841,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
959,
12,
9627,
63,
2911,
63,
589,
2687,
22,
4641,
267,
702,
2531,
82,
508,
959,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
282,
12,
9627,
63,
2911,
63,
589,
2687,
22,
4641,
267,
702,
2531,
82,
508,
1227,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
959,
435,
282,
12,
9627,
63,
2911,
63,
589,
2687,
23,
4641,
267,
702,
2531,
82,
508,
3144,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
2734,
282,
26,
3473,
14,
20251,
8,
65,
395,
9627,
63,
2911,
63,
589,
2687,
3442,
14,
1038,
4641,
267,
702,
2531,
82,
508,
13576,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
3442,
14,
20251,
12,
9627,
63,
2911,
63,
589,
2687,
3442,
14,
1038,
4641,
267,
702,
2531,
82,
508,
13576,
12,
4700,
8,
82,
430,
398,
519,
275,
307,
8,
277,
14,
578,
14,
1532,
12,
9627,
63,
2911,
63,
589,
2687,
22,
4641,
267,
702,
2531,
82,
508,
5557,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
277,
14,
578,
14,
1532,
16,
9,
267,
702,
2531,
82,
508,
4119,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
277,
14,
578,
14,
1532,
16,
423,
67,
3929,
9,
267,
702,
2531,
82,
508,
4119,
12,
4700,
8,
82,
430,
398,
1021,
437,
8,
785,
304,
953,
347,
636,
1250,
721,
277,
304,
355,
372,
1520,
953,
347,
333,
273,
8,
277,
304,
355,
372,
1749,
267,
282,
275,
437,
342,
267,
519,
275,
307,
8,
65,
9,
267,
702,
2531,
82,
508,
1520,
12,
4700,
8,
82,
430,
267,
519,
275,
307,
8,
65,
14,
77,
273,
9,
267,
702,
2531,
82,
508,
1749,
12,
4700,
8,
82,
430,
339,
347,
511,
63,
875,
63,
3058,
8,
277,
304,
398,
347,
3233,
8,
600,
304,
288,
340,
1233,
508,
283,
82,
356,
355,
372,
378,
288,
587,
26,
355,
372,
413,
398,
289,
275,
2519,
8,
277,
14,
578,
12,
283,
875,
63,
3058,
358,
267,
519,
275,
289,
8,
3058,
9,
267,
702,
2531,
82,
508,
378,
12,
4700,
8,
82,
430,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
578,
63,
5768,
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,
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,
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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
] |
NoelMacwan/SXDTianchi
|
tools/perf/scripts/python/syscall-counts-by-pid.py
|
11180
|
1927
|
# system call counts, by pid
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts-by-pid.py [comm]\n";
for_comm = None
for_pid = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
try:
for_pid = int(sys.argv[1])
except:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if (for_comm and common_comm != for_comm) or \
(for_pid and common_pid != for_pid ):
return
try:
syscalls[common_comm][common_pid][id] += 1
except TypeError:
syscalls[common_comm][common_pid][id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events by comm/pid:\n\n",
print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
comm_keys = syscalls.keys()
for comm in comm_keys:
pid_keys = syscalls[comm].keys()
for pid in pid_keys:
print "\n%s [%d]\n" % (comm, pid),
id_keys = syscalls[comm][pid].keys()
for id, val in sorted(syscalls[comm][pid].iteritems(), \
key = lambda(k, v): (v, k), reverse = True):
print " %-38s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
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
] |
[
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
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,
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,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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
] |
AndrewGrossman/django
|
django/utils/crypto.py
|
452
|
6878
|
"""
Django's standard crypto functions and utilities.
"""
from __future__ import unicode_literals
import binascii
import hashlib
import hmac
import random
import struct
import time
from django.conf import settings
from django.utils import six
from django.utils.encoding import force_bytes
from django.utils.six.moves import range
# Use the system PRNG if possible
try:
random = random.SystemRandom()
using_sysrandom = True
except NotImplementedError:
import warnings
warnings.warn('A secure pseudo-random number generator is not available '
'on your system. Falling back to Mersenne Twister.')
using_sysrandom = False
def salted_hmac(key_salt, value, secret=None):
"""
Returns the HMAC-SHA1 of 'value', using a key generated from key_salt and a
secret (which defaults to settings.SECRET_KEY).
A different key_salt should be passed in for every application of HMAC.
"""
if secret is None:
secret = settings.SECRET_KEY
key_salt = force_bytes(key_salt)
secret = force_bytes(secret)
# We need to generate a derived key from our base key. We can do this by
# passing the key_salt and our base key through a pseudo-random function and
# SHA1 works nicely.
key = hashlib.sha1(key_salt + secret).digest()
# If len(key_salt + secret) > sha_constructor().block_size, the above
# line is redundant and could be replaced by key = key_salt + secret, since
# the hmac module does the same thing for keys longer than the block size.
# However, we need to ensure that we *always* do this.
return hmac.new(key, msg=force_bytes(value), digestmod=hashlib.sha1)
def get_random_string(length=12,
allowed_chars='abcdefghijklmnopqrstuvwxyz'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
"""
Returns a securely generated random string.
The default length of 12 with the a-z, A-Z, 0-9 character set returns
a 71-bit value. log_2((26+26+10)^12) =~ 71 bits
"""
if not using_sysrandom:
# This is ugly, and a hack, but it makes things better than
# the alternative of predictability. This re-seeds the PRNG
# using a value that is hard for an attacker to predict, every
# time a random string is required. This may change the
# properties of the chosen random sequence slightly, but this
# is better than absolute predictability.
random.seed(
hashlib.sha256(
("%s%s%s" % (
random.getstate(),
time.time(),
settings.SECRET_KEY)).encode('utf-8')
).digest())
return ''.join(random.choice(allowed_chars) for i in range(length))
if hasattr(hmac, "compare_digest"):
# Prefer the stdlib implementation, when available.
def constant_time_compare(val1, val2):
return hmac.compare_digest(force_bytes(val1), force_bytes(val2))
else:
def constant_time_compare(val1, val2):
"""
Returns True if the two strings are equal, False otherwise.
The time taken is independent of the number of characters that match.
For the sake of simplicity, this function executes in constant time only
when the two strings have the same length. It short-circuits when they
have different lengths. Since Django only uses it to compare hashes of
known expected length, this is acceptable.
"""
if len(val1) != len(val2):
return False
result = 0
if six.PY3 and isinstance(val1, bytes) and isinstance(val2, bytes):
for x, y in zip(val1, val2):
result |= x ^ y
else:
for x, y in zip(val1, val2):
result |= ord(x) ^ ord(y)
return result == 0
def _bin_to_long(x):
"""
Convert a binary string into a long integer
This is a clever optimization for fast xor vector math
"""
return int(binascii.hexlify(x), 16)
def _long_to_bin(x, hex_format_string):
"""
Convert a long integer into a binary string.
hex_format_string is like "%020x" for padding 10 characters.
"""
return binascii.unhexlify((hex_format_string % x).encode('ascii'))
if hasattr(hashlib, "pbkdf2_hmac"):
def pbkdf2(password, salt, iterations, dklen=0, digest=None):
"""
Implements PBKDF2 with the same API as Django's existing
implementation, using the stdlib.
This is used in Python 2.7.8+ and 3.4+.
"""
if digest is None:
digest = hashlib.sha256
if not dklen:
dklen = None
password = force_bytes(password)
salt = force_bytes(salt)
return hashlib.pbkdf2_hmac(
digest().name, password, salt, iterations, dklen)
else:
def pbkdf2(password, salt, iterations, dklen=0, digest=None):
"""
Implements PBKDF2 as defined in RFC 2898, section 5.2
HMAC+SHA256 is used as the default pseudo random function.
As of 2014, 100,000 iterations was the recommended default which took
100ms on a 2.7Ghz Intel i7 with an optimized implementation. This is
probably the bare minimum for security given 1000 iterations was
recommended in 2001. This code is very well optimized for CPython and
is about five times slower than OpenSSL's implementation. Look in
django.contrib.auth.hashers for the present default, it is lower than
the recommended 100,000 because of the performance difference between
this and an optimized implementation.
"""
assert iterations > 0
if not digest:
digest = hashlib.sha256
password = force_bytes(password)
salt = force_bytes(salt)
hlen = digest().digest_size
if not dklen:
dklen = hlen
if dklen > (2 ** 32 - 1) * hlen:
raise OverflowError('dklen too big')
l = -(-dklen // hlen)
r = dklen - (l - 1) * hlen
hex_format_string = "%%0%ix" % (hlen * 2)
inner, outer = digest(), digest()
if len(password) > inner.block_size:
password = digest(password).digest()
password += b'\x00' * (inner.block_size - len(password))
inner.update(password.translate(hmac.trans_36))
outer.update(password.translate(hmac.trans_5C))
def F(i):
u = salt + struct.pack(b'>I', i)
result = 0
for j in range(int(iterations)):
dig1, dig2 = inner.copy(), outer.copy()
dig1.update(u)
dig2.update(dig1.digest())
u = dig2.digest()
result ^= _bin_to_long(u)
return _long_to_bin(result, hex_format_string)
T = [F(x) for x in range(1, l)]
return b''.join(T) + F(l)[:r]
|
bsd-3-clause
|
[
624,
199,
9323,
1159,
4465,
13230,
3423,
436,
15841,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
14755,
199,
646,
8337,
199,
646,
20330,
199,
646,
2196,
199,
646,
2702,
199,
646,
900,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2394,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1425,
199,
199,
3,
3645,
314,
2656,
12218,
12259,
340,
3962,
199,
893,
26,
272,
2196,
275,
2196,
14,
3989,
3883,
342,
272,
1808,
63,
1274,
2355,
275,
715,
199,
2590,
4279,
26,
272,
492,
3598,
272,
3598,
14,
4050,
360,
33,
11153,
15984,
13,
2355,
1329,
4306,
365,
440,
2808,
283,
2116,
283,
265,
2195,
2656,
14,
481,
26039,
1771,
370,
18880,
2464,
685,
377,
87,
1429,
2659,
272,
1808,
63,
1274,
2355,
275,
756,
421,
199,
318,
18641,
471,
63,
18537,
8,
498,
63,
12597,
12,
574,
12,
7565,
29,
403,
304,
272,
408,
272,
1803,
314,
29817,
13,
8461,
17,
402,
283,
585,
297,
1808,
282,
790,
4046,
687,
790,
63,
12597,
436,
282,
272,
7565,
334,
6777,
4243,
370,
2202,
14,
12961,
63,
3078,
680,
339,
437,
3365,
790,
63,
12597,
1077,
506,
3032,
315,
367,
4036,
4223,
402,
29817,
14,
272,
408,
272,
340,
7565,
365,
488,
26,
267,
7565,
275,
2202,
14,
12961,
63,
3078,
339,
790,
63,
12597,
275,
3542,
63,
2394,
8,
498,
63,
12597,
9,
272,
7565,
275,
3542,
63,
2394,
8,
4731,
9,
339,
327,
2136,
1929,
370,
3550,
282,
7131,
790,
687,
4154,
1300,
790,
14,
221,
2136,
883,
886,
642,
701,
272,
327,
9476,
314,
790,
63,
12597,
436,
4154,
1300,
790,
4012,
282,
15984,
13,
2355,
805,
436,
272,
327,
12002,
17,
5419,
14213,
590,
14,
272,
790,
275,
8337,
14,
4835,
17,
8,
498,
63,
12597,
435,
7565,
680,
5671,
342,
339,
327,
982,
822,
8,
498,
63,
12597,
435,
7565,
9,
690,
7793,
63,
1880,
1252,
1457,
63,
890,
12,
314,
3432,
272,
327,
1004,
365,
22649,
436,
4293,
506,
8717,
701,
790,
275,
790,
63,
12597,
435,
7565,
12,
3967,
272,
327,
314,
20330,
859,
1630,
314,
2011,
8377,
367,
2883,
8088,
2419,
314,
1853,
1568,
14,
272,
327,
9738,
12,
781,
1929,
370,
4868,
626,
781,
627,
9223,
10,
886,
642,
14,
272,
372,
20330,
14,
1222,
8,
498,
12,
1499,
29,
3990,
63,
2394,
8,
585,
395,
10017,
1494,
29,
24722,
14,
4835,
17,
9,
421,
199,
318,
664,
63,
2355,
63,
875,
8,
1267,
29,
713,
12,
1993,
4370,
63,
6574,
534,
23459,
7,
2511,
283,
28114,
11371,
735,
272,
408,
272,
1803,
282,
11153,
590,
4046,
2196,
1059,
14,
339,
710,
849,
2582,
402,
3144,
543,
314,
282,
13,
90,
12,
437,
13,
58,
12,
378,
13,
25,
4528,
663,
2529,
272,
282,
17245,
13,
2075,
574,
14,
943,
63,
18,
1332,
1479,
11,
1479,
11,
709,
18979,
713,
9,
275,
94,
17245,
5821,
272,
408,
272,
340,
440,
1808,
63,
1274,
2355,
26,
267,
327,
961,
365,
23761,
12,
436,
282,
11176,
12,
1325,
652,
7704,
7645,
8034,
2419,
267,
327,
314,
13943,
402,
12610,
3616,
14,
961,
295,
13,
5176,
83,
314,
12218,
12259,
267,
327,
1808,
282,
574,
626,
365,
7508,
367,
376,
23326,
281,
370,
12610,
12,
4036,
267,
327,
900,
282,
2196,
1059,
365,
1415,
14,
961,
1443,
1570,
314,
267,
327,
4382,
402,
314,
12414,
2196,
3414,
18023,
12,
1325,
642,
267,
327,
365,
8034,
2419,
3679,
12610,
3616,
14,
267,
2196,
14,
5176,
8,
288,
8337,
14,
4835,
3912,
8,
355,
19426,
83,
5,
83,
5,
83,
2,
450,
334,
490,
2196,
14,
16011,
1062,
490,
900,
14,
521,
1062,
490,
2202,
14,
12961,
63,
3078,
4992,
2143,
360,
1624,
13,
24,
358,
288,
7092,
5671,
1012,
272,
372,
6522,
904,
8,
2355,
14,
5095,
8,
6541,
63,
6574,
9,
367,
284,
315,
1425,
8,
1267,
430,
421,
199,
692,
2688,
8,
18537,
12,
298,
5785,
63,
5671,
2349,
272,
327,
510,
21928,
314,
26678,
4514,
12,
1380,
2808,
14,
272,
347,
4413,
63,
521,
63,
5785,
8,
637,
17,
12,
1139,
18,
304,
267,
372,
20330,
14,
5785,
63,
5671,
8,
3990,
63,
2394,
8,
637,
17,
395,
3542,
63,
2394,
8,
637,
18,
430,
199,
2836,
26,
272,
347,
4413,
63,
521,
63,
5785,
8,
637,
17,
12,
1139,
18,
304,
267,
408,
267,
1803,
715,
340,
314,
2877,
3326,
787,
4472,
12,
756,
4257,
14,
398,
710,
900,
9394,
365,
12717,
402,
314,
1329,
402,
4110,
626,
1336,
14,
398,
2104,
314,
308,
1728,
402,
17553,
3690,
12,
642,
805,
24956,
315,
4413,
900,
1454,
267,
1380,
314,
2877,
3326,
1172,
314,
2011,
2582,
14,
2779,
3974,
13,
6092,
85,
1405,
1380,
2985,
267,
1172,
3365,
17464,
14,
9336,
5634,
1454,
4440,
652,
370,
6540,
14647,
402,
267,
6040,
1420,
2582,
12,
642,
365,
14712,
14,
267,
408,
267,
340,
822,
8,
637,
17,
9,
1137,
822,
8,
637,
18,
304,
288,
372,
756,
267,
754,
275,
378,
267,
340,
3816,
14,
4521,
19,
436,
1228,
8,
637,
17,
12,
2783,
9,
436,
1228,
8,
637,
18,
12,
2783,
304,
288,
367,
671,
12,
612,
315,
3482,
8,
637,
17,
12,
1139,
18,
304,
355,
754,
8901,
671,
7167,
612,
267,
587,
26,
288,
367,
671,
12,
612,
315,
3482,
8,
637,
17,
12,
1139,
18,
304,
355,
754,
8901,
6206,
8,
88,
9,
7167,
6206,
8,
89,
9,
267,
372,
754,
508,
378,
421,
199,
318,
485,
1393,
63,
475,
63,
2809,
8,
88,
304,
272,
408,
272,
7905,
282,
3366,
1059,
1901,
282,
1846,
3000,
339,
961,
365,
282,
15158,
422,
13712,
367,
7377,
31770,
5477,
3473,
272,
408,
272,
372,
1109,
8,
27460,
14,
20677,
8,
88,
395,
3193,
9,
421,
199,
318,
485,
2809,
63,
475,
63,
1393,
8,
88,
12,
6318,
63,
908,
63,
875,
304,
272,
408,
272,
7905,
282,
1846,
3000,
1901,
282,
3366,
1059,
14,
272,
6318,
63,
908,
63,
875,
365,
2839,
2071,
10173,
88,
2,
367,
6273,
1616,
4110,
14,
272,
408,
272,
372,
14755,
14,
324,
20677
] |
[
199,
9323,
1159,
4465,
13230,
3423,
436,
15841,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
14755,
199,
646,
8337,
199,
646,
20330,
199,
646,
2196,
199,
646,
2702,
199,
646,
900,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2394,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
1425,
199,
199,
3,
3645,
314,
2656,
12218,
12259,
340,
3962,
199,
893,
26,
272,
2196,
275,
2196,
14,
3989,
3883,
342,
272,
1808,
63,
1274,
2355,
275,
715,
199,
2590,
4279,
26,
272,
492,
3598,
272,
3598,
14,
4050,
360,
33,
11153,
15984,
13,
2355,
1329,
4306,
365,
440,
2808,
283,
2116,
283,
265,
2195,
2656,
14,
481,
26039,
1771,
370,
18880,
2464,
685,
377,
87,
1429,
2659,
272,
1808,
63,
1274,
2355,
275,
756,
421,
199,
318,
18641,
471,
63,
18537,
8,
498,
63,
12597,
12,
574,
12,
7565,
29,
403,
304,
272,
408,
272,
1803,
314,
29817,
13,
8461,
17,
402,
283,
585,
297,
1808,
282,
790,
4046,
687,
790,
63,
12597,
436,
282,
272,
7565,
334,
6777,
4243,
370,
2202,
14,
12961,
63,
3078,
680,
339,
437,
3365,
790,
63,
12597,
1077,
506,
3032,
315,
367,
4036,
4223,
402,
29817,
14,
272,
408,
272,
340,
7565,
365,
488,
26,
267,
7565,
275,
2202,
14,
12961,
63,
3078,
339,
790,
63,
12597,
275,
3542,
63,
2394,
8,
498,
63,
12597,
9,
272,
7565,
275,
3542,
63,
2394,
8,
4731,
9,
339,
327,
2136,
1929,
370,
3550,
282,
7131,
790,
687,
4154,
1300,
790,
14,
221,
2136,
883,
886,
642,
701,
272,
327,
9476,
314,
790,
63,
12597,
436,
4154,
1300,
790,
4012,
282,
15984,
13,
2355,
805,
436,
272,
327,
12002,
17,
5419,
14213,
590,
14,
272,
790,
275,
8337,
14,
4835,
17,
8,
498,
63,
12597,
435,
7565,
680,
5671,
342,
339,
327,
982,
822,
8,
498,
63,
12597,
435,
7565,
9,
690,
7793,
63,
1880,
1252,
1457,
63,
890,
12,
314,
3432,
272,
327,
1004,
365,
22649,
436,
4293,
506,
8717,
701,
790,
275,
790,
63,
12597,
435,
7565,
12,
3967,
272,
327,
314,
20330,
859,
1630,
314,
2011,
8377,
367,
2883,
8088,
2419,
314,
1853,
1568,
14,
272,
327,
9738,
12,
781,
1929,
370,
4868,
626,
781,
627,
9223,
10,
886,
642,
14,
272,
372,
20330,
14,
1222,
8,
498,
12,
1499,
29,
3990,
63,
2394,
8,
585,
395,
10017,
1494,
29,
24722,
14,
4835,
17,
9,
421,
199,
318,
664,
63,
2355,
63,
875,
8,
1267,
29,
713,
12,
1993,
4370,
63,
6574,
534,
23459,
7,
2511,
283,
28114,
11371,
735,
272,
408,
272,
1803,
282,
11153,
590,
4046,
2196,
1059,
14,
339,
710,
849,
2582,
402,
3144,
543,
314,
282,
13,
90,
12,
437,
13,
58,
12,
378,
13,
25,
4528,
663,
2529,
272,
282,
17245,
13,
2075,
574,
14,
943,
63,
18,
1332,
1479,
11,
1479,
11,
709,
18979,
713,
9,
275,
94,
17245,
5821,
272,
408,
272,
340,
440,
1808,
63,
1274,
2355,
26,
267,
327,
961,
365,
23761,
12,
436,
282,
11176,
12,
1325,
652,
7704,
7645,
8034,
2419,
267,
327,
314,
13943,
402,
12610,
3616,
14,
961,
295,
13,
5176,
83,
314,
12218,
12259,
267,
327,
1808,
282,
574,
626,
365,
7508,
367,
376,
23326,
281,
370,
12610,
12,
4036,
267,
327,
900,
282,
2196,
1059,
365,
1415,
14,
961,
1443,
1570,
314,
267,
327,
4382,
402,
314,
12414,
2196,
3414,
18023,
12,
1325,
642,
267,
327,
365,
8034,
2419,
3679,
12610,
3616,
14,
267,
2196,
14,
5176,
8,
288,
8337,
14,
4835,
3912,
8,
355,
19426,
83,
5,
83,
5,
83,
2,
450,
334,
490,
2196,
14,
16011,
1062,
490,
900,
14,
521,
1062,
490,
2202,
14,
12961,
63,
3078,
4992,
2143,
360,
1624,
13,
24,
358,
288,
7092,
5671,
1012,
272,
372,
6522,
904,
8,
2355,
14,
5095,
8,
6541,
63,
6574,
9,
367,
284,
315,
1425,
8,
1267,
430,
421,
199,
692,
2688,
8,
18537,
12,
298,
5785,
63,
5671,
2349,
272,
327,
510,
21928,
314,
26678,
4514,
12,
1380,
2808,
14,
272,
347,
4413,
63,
521,
63,
5785,
8,
637,
17,
12,
1139,
18,
304,
267,
372,
20330,
14,
5785,
63,
5671,
8,
3990,
63,
2394,
8,
637,
17,
395,
3542,
63,
2394,
8,
637,
18,
430,
199,
2836,
26,
272,
347,
4413,
63,
521,
63,
5785,
8,
637,
17,
12,
1139,
18,
304,
267,
408,
267,
1803,
715,
340,
314,
2877,
3326,
787,
4472,
12,
756,
4257,
14,
398,
710,
900,
9394,
365,
12717,
402,
314,
1329,
402,
4110,
626,
1336,
14,
398,
2104,
314,
308,
1728,
402,
17553,
3690,
12,
642,
805,
24956,
315,
4413,
900,
1454,
267,
1380,
314,
2877,
3326,
1172,
314,
2011,
2582,
14,
2779,
3974,
13,
6092,
85,
1405,
1380,
2985,
267,
1172,
3365,
17464,
14,
9336,
5634,
1454,
4440,
652,
370,
6540,
14647,
402,
267,
6040,
1420,
2582,
12,
642,
365,
14712,
14,
267,
408,
267,
340,
822,
8,
637,
17,
9,
1137,
822,
8,
637,
18,
304,
288,
372,
756,
267,
754,
275,
378,
267,
340,
3816,
14,
4521,
19,
436,
1228,
8,
637,
17,
12,
2783,
9,
436,
1228,
8,
637,
18,
12,
2783,
304,
288,
367,
671,
12,
612,
315,
3482,
8,
637,
17,
12,
1139,
18,
304,
355,
754,
8901,
671,
7167,
612,
267,
587,
26,
288,
367,
671,
12,
612,
315,
3482,
8,
637,
17,
12,
1139,
18,
304,
355,
754,
8901,
6206,
8,
88,
9,
7167,
6206,
8,
89,
9,
267,
372,
754,
508,
378,
421,
199,
318,
485,
1393,
63,
475,
63,
2809,
8,
88,
304,
272,
408,
272,
7905,
282,
3366,
1059,
1901,
282,
1846,
3000,
339,
961,
365,
282,
15158,
422,
13712,
367,
7377,
31770,
5477,
3473,
272,
408,
272,
372,
1109,
8,
27460,
14,
20677,
8,
88,
395,
3193,
9,
421,
199,
318,
485,
2809,
63,
475,
63,
1393,
8,
88,
12,
6318,
63,
908,
63,
875,
304,
272,
408,
272,
7905,
282,
1846,
3000,
1901,
282,
3366,
1059,
14,
272,
6318,
63,
908,
63,
875,
365,
2839,
2071,
10173,
88,
2,
367,
6273,
1616,
4110,
14,
272,
408,
272,
372,
14755,
14,
324,
20677,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kepstin/picard
|
picard/ui/ui_options_folksonomy.py
|
2
|
5901
|
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ui/options_folksonomy.ui'
#
# Created: Tue May 29 19:44:14 2012
# by: PyQt4 UI code generator 4.8.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_FolksonomyOptionsPage(object):
def setupUi(self, FolksonomyOptionsPage):
FolksonomyOptionsPage.setObjectName(_fromUtf8("FolksonomyOptionsPage"))
FolksonomyOptionsPage.resize(390, 304)
self.verticalLayout_2 = QtGui.QVBoxLayout(FolksonomyOptionsPage)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.rename_files_3 = QtGui.QGroupBox(FolksonomyOptionsPage)
self.rename_files_3.setObjectName(_fromUtf8("rename_files_3"))
self.verticalLayout = QtGui.QVBoxLayout(self.rename_files_3)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.ignore_tags_2 = QtGui.QLabel(self.rename_files_3)
self.ignore_tags_2.setObjectName(_fromUtf8("ignore_tags_2"))
self.verticalLayout.addWidget(self.ignore_tags_2)
self.ignore_tags = QtGui.QLineEdit(self.rename_files_3)
self.ignore_tags.setObjectName(_fromUtf8("ignore_tags"))
self.verticalLayout.addWidget(self.ignore_tags)
self.only_my_tags = QtGui.QCheckBox(self.rename_files_3)
self.only_my_tags.setObjectName(_fromUtf8("only_my_tags"))
self.verticalLayout.addWidget(self.only_my_tags)
self.hboxlayout = QtGui.QHBoxLayout()
self.hboxlayout.setSpacing(6)
self.hboxlayout.setMargin(0)
self.hboxlayout.setObjectName(_fromUtf8("hboxlayout"))
self.label_5 = QtGui.QLabel(self.rename_files_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_5.sizePolicy().hasHeightForWidth())
self.label_5.setSizePolicy(sizePolicy)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.hboxlayout.addWidget(self.label_5)
self.min_tag_usage = QtGui.QSpinBox(self.rename_files_3)
self.min_tag_usage.setMaximum(100)
self.min_tag_usage.setObjectName(_fromUtf8("min_tag_usage"))
self.hboxlayout.addWidget(self.min_tag_usage)
self.verticalLayout.addLayout(self.hboxlayout)
self.hboxlayout1 = QtGui.QHBoxLayout()
self.hboxlayout1.setSpacing(6)
self.hboxlayout1.setMargin(0)
self.hboxlayout1.setObjectName(_fromUtf8("hboxlayout1"))
self.label_6 = QtGui.QLabel(self.rename_files_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label_6.sizePolicy().hasHeightForWidth())
self.label_6.setSizePolicy(sizePolicy)
self.label_6.setObjectName(_fromUtf8("label_6"))
self.hboxlayout1.addWidget(self.label_6)
self.max_tags = QtGui.QSpinBox(self.rename_files_3)
self.max_tags.setMaximum(100)
self.max_tags.setObjectName(_fromUtf8("max_tags"))
self.hboxlayout1.addWidget(self.max_tags)
self.verticalLayout.addLayout(self.hboxlayout1)
self.hboxlayout2 = QtGui.QHBoxLayout()
self.hboxlayout2.setSpacing(6)
self.hboxlayout2.setMargin(0)
self.hboxlayout2.setObjectName(_fromUtf8("hboxlayout2"))
self.ignore_tags_4 = QtGui.QLabel(self.rename_files_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(4)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.ignore_tags_4.sizePolicy().hasHeightForWidth())
self.ignore_tags_4.setSizePolicy(sizePolicy)
self.ignore_tags_4.setObjectName(_fromUtf8("ignore_tags_4"))
self.hboxlayout2.addWidget(self.ignore_tags_4)
self.join_tags = QtGui.QComboBox(self.rename_files_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.join_tags.sizePolicy().hasHeightForWidth())
self.join_tags.setSizePolicy(sizePolicy)
self.join_tags.setEditable(True)
self.join_tags.setObjectName(_fromUtf8("join_tags"))
self.join_tags.addItem(_fromUtf8(""))
self.join_tags.setItemText(0, _fromUtf8(""))
self.join_tags.addItem(_fromUtf8(""))
self.join_tags.addItem(_fromUtf8(""))
self.hboxlayout2.addWidget(self.join_tags)
self.verticalLayout.addLayout(self.hboxlayout2)
self.verticalLayout_2.addWidget(self.rename_files_3)
spacerItem = QtGui.QSpacerItem(181, 31, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem)
self.label_5.setBuddy(self.min_tag_usage)
self.label_6.setBuddy(self.min_tag_usage)
self.retranslateUi(FolksonomyOptionsPage)
QtCore.QMetaObject.connectSlotsByName(FolksonomyOptionsPage)
def retranslateUi(self, FolksonomyOptionsPage):
self.rename_files_3.setTitle(_("Folksonomy Tags"))
self.ignore_tags_2.setText(_("Ignore tags:"))
self.only_my_tags.setText(_("Only use my tags"))
self.label_5.setText(_("Minimal tag usage:"))
self.min_tag_usage.setSuffix(_(" %"))
self.label_6.setText(_("Maximum number of tags:"))
self.ignore_tags_4.setText(_("Join multiple tags with:"))
self.join_tags.setItemText(1, _(" / "))
self.join_tags.setItemText(2, _(", "))
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
1907,
15,
1419,
63,
5900,
75,
834,
676,
89,
14,
1907,
7,
199,
3,
199,
3,
18208,
26,
377,
310,
10162,
7349,
5851,
26,
1602,
26,
1079,
6029,
199,
3,
420,
701,
26,
14084,
20,
14041,
1233,
4306,
841,
14,
24,
14,
19,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
893,
26,
272,
485,
12382,
24,
275,
10565,
14,
49,
1558,
14,
12382,
24,
199,
2590,
4281,
26,
272,
485,
12382,
24,
275,
2400,
308,
26,
308,
199,
199,
533,
32471,
63,
38,
393,
75,
834,
676,
89,
4558,
3276,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
481,
393,
75,
834,
676,
89,
4558,
3276,
304,
267,
481,
393,
75,
834,
676,
89,
4558,
3276,
14,
10376,
1547,
12382,
24,
480,
38,
393,
75,
834,
676,
89,
4558,
3276,
2237,
267,
481,
393,
75,
834,
676,
89,
4558,
3276,
14,
8709,
8,
12302,
12,
20398,
9,
267,
291,
14,
18656,
63,
18,
275,
5928,
14,
25527,
18536,
8,
38,
393,
75,
834,
676,
89,
4558,
3276,
9,
267,
291,
14,
18656,
63,
18,
14,
10376,
1547,
12382,
24,
480,
18656,
63,
18,
2237,
267,
291,
14,
8165,
63,
1725,
63,
19,
275,
5928,
14,
49,
2448,
3532,
8,
38,
393,
75,
834,
676,
89,
4558,
3276,
9,
267,
291,
14,
8165,
63,
1725,
63,
19,
14,
10376,
1547,
12382,
24,
480,
8165,
63,
1725,
63,
19,
2237,
267,
291,
14,
18656,
275,
5928,
14,
25527,
18536,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
18656,
14,
10376,
1547,
12382,
24,
480,
18656,
2237,
267,
291,
14,
4247,
63,
2969,
63,
18,
275,
5928,
14,
19890,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
4247,
63,
2969,
63,
18,
14,
10376,
1547,
12382,
24,
480,
4247,
63,
2969,
63,
18,
2237,
267,
291,
14,
18656,
14,
9475,
8,
277,
14,
4247,
63,
2969,
63,
18,
9,
267,
291,
14,
4247,
63,
2969,
275,
5928,
14,
32141,
4685,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
4247,
63,
2969,
14,
10376,
1547,
12382,
24,
480,
4247,
63,
2969,
2237,
267,
291,
14,
18656,
14,
9475,
8,
277,
14,
4247,
63,
2969,
9,
267,
291,
14,
2118,
63,
1662,
63,
2969,
275,
5928,
14,
49,
20530,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
2118,
63,
1662,
63,
2969,
14,
10376,
1547,
12382,
24,
480,
2118,
63,
1662,
63,
2969,
2237,
267,
291,
14,
18656,
14,
9475,
8,
277,
14,
2118,
63,
1662,
63,
2969,
9,
267,
291,
14,
21453,
4209,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
21453,
4209,
14,
409,
24052,
8,
22,
9,
267,
291,
14,
21453,
4209,
14,
409,
15182,
8,
16,
9,
267,
291,
14,
21453,
4209,
14,
10376,
1547,
12382,
24,
480,
21453,
4209,
2237,
267,
291,
14,
1302,
63,
21,
275,
5928,
14,
19890,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
12839,
316,
12,
5928,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
1302,
63,
21,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
291,
14,
1302,
63,
21,
14,
21735,
4845,
8,
890,
4845,
9,
267,
291,
14,
1302,
63,
21,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
21,
2237,
267,
291,
14,
21453,
4209,
14,
9475,
8,
277,
14,
1302,
63,
21,
9,
267,
291,
14,
827,
63,
1450,
63,
3807,
275,
5928,
14,
49,
27806,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
827,
63,
1450,
63,
3807,
14,
409,
10915,
8,
1960,
9,
267,
291,
14,
827,
63,
1450,
63,
3807,
14,
10376,
1547,
12382,
24,
480,
827,
63,
1450,
63,
3807,
2237,
267,
291,
14,
21453,
4209,
14,
9475,
8,
277,
14,
827,
63,
1450,
63,
3807,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
21453,
4209,
9,
267,
291,
14,
21453,
4209,
17,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
21453,
4209,
17,
14,
409,
24052,
8,
22,
9,
267,
291,
14,
21453,
4209,
17,
14,
409,
15182,
8,
16,
9,
267,
291,
14,
21453,
4209,
17,
14,
10376,
1547,
12382,
24,
480,
21453,
4209,
17,
2237,
267,
291,
14,
1302,
63,
22,
275,
5928,
14,
19890,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
12839,
316,
12,
5928,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
1302,
63,
22,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
291,
14,
1302,
63,
22,
14,
21735,
4845,
8,
890,
4845,
9,
267,
291,
14,
1302,
63,
22,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
22,
2237,
267,
291,
14,
21453,
4209,
17,
14,
9475,
8,
277,
14,
1302,
63,
22,
9,
267,
291,
14,
988,
63,
2969,
275,
5928,
14,
49,
27806,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
988,
63,
2969,
14,
409,
10915,
8,
1960,
9,
267,
291,
14,
988,
63,
2969,
14,
10376,
1547,
12382,
24,
480,
988,
63,
2969,
2237,
267,
291,
14,
21453,
4209,
17,
14,
9475,
8,
277,
14,
988,
63,
2969,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
21453,
4209,
17,
9,
267,
291,
14,
21453,
4209,
18,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
21453,
4209,
18,
14,
409,
24052,
8,
22,
9,
267,
291,
14,
21453,
4209,
18,
14,
409,
15182,
8,
16,
9,
267,
291,
14,
21453,
4209,
18,
14,
10376,
1547,
12382,
24,
480,
21453,
4209,
18,
2237,
267,
291,
14,
4247,
63,
2969,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
8204,
4514,
4046,
687,
7664,
8574,
570,
283,
1907,
15,
1419,
63,
5900,
75,
834,
676,
89,
14,
1907,
7,
199,
3,
199,
3,
18208,
26,
377,
310,
10162,
7349,
5851,
26,
1602,
26,
1079,
6029,
199,
3,
420,
701,
26,
14084,
20,
14041,
1233,
4306,
841,
14,
24,
14,
19,
199,
3,
199,
3,
14750,
1,
2900,
4493,
6326,
315,
642,
570,
911,
506,
14669,
1,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
199,
199,
893,
26,
272,
485,
12382,
24,
275,
10565,
14,
49,
1558,
14,
12382,
24,
199,
2590,
4281,
26,
272,
485,
12382,
24,
275,
2400,
308,
26,
308,
199,
199,
533,
32471,
63,
38,
393,
75,
834,
676,
89,
4558,
3276,
8,
785,
304,
272,
347,
3272,
18203,
8,
277,
12,
481,
393,
75,
834,
676,
89,
4558,
3276,
304,
267,
481,
393,
75,
834,
676,
89,
4558,
3276,
14,
10376,
1547,
12382,
24,
480,
38,
393,
75,
834,
676,
89,
4558,
3276,
2237,
267,
481,
393,
75,
834,
676,
89,
4558,
3276,
14,
8709,
8,
12302,
12,
20398,
9,
267,
291,
14,
18656,
63,
18,
275,
5928,
14,
25527,
18536,
8,
38,
393,
75,
834,
676,
89,
4558,
3276,
9,
267,
291,
14,
18656,
63,
18,
14,
10376,
1547,
12382,
24,
480,
18656,
63,
18,
2237,
267,
291,
14,
8165,
63,
1725,
63,
19,
275,
5928,
14,
49,
2448,
3532,
8,
38,
393,
75,
834,
676,
89,
4558,
3276,
9,
267,
291,
14,
8165,
63,
1725,
63,
19,
14,
10376,
1547,
12382,
24,
480,
8165,
63,
1725,
63,
19,
2237,
267,
291,
14,
18656,
275,
5928,
14,
25527,
18536,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
18656,
14,
10376,
1547,
12382,
24,
480,
18656,
2237,
267,
291,
14,
4247,
63,
2969,
63,
18,
275,
5928,
14,
19890,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
4247,
63,
2969,
63,
18,
14,
10376,
1547,
12382,
24,
480,
4247,
63,
2969,
63,
18,
2237,
267,
291,
14,
18656,
14,
9475,
8,
277,
14,
4247,
63,
2969,
63,
18,
9,
267,
291,
14,
4247,
63,
2969,
275,
5928,
14,
32141,
4685,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
4247,
63,
2969,
14,
10376,
1547,
12382,
24,
480,
4247,
63,
2969,
2237,
267,
291,
14,
18656,
14,
9475,
8,
277,
14,
4247,
63,
2969,
9,
267,
291,
14,
2118,
63,
1662,
63,
2969,
275,
5928,
14,
49,
20530,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
2118,
63,
1662,
63,
2969,
14,
10376,
1547,
12382,
24,
480,
2118,
63,
1662,
63,
2969,
2237,
267,
291,
14,
18656,
14,
9475,
8,
277,
14,
2118,
63,
1662,
63,
2969,
9,
267,
291,
14,
21453,
4209,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
21453,
4209,
14,
409,
24052,
8,
22,
9,
267,
291,
14,
21453,
4209,
14,
409,
15182,
8,
16,
9,
267,
291,
14,
21453,
4209,
14,
10376,
1547,
12382,
24,
480,
21453,
4209,
2237,
267,
291,
14,
1302,
63,
21,
275,
5928,
14,
19890,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
12839,
316,
12,
5928,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
1302,
63,
21,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
291,
14,
1302,
63,
21,
14,
21735,
4845,
8,
890,
4845,
9,
267,
291,
14,
1302,
63,
21,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
21,
2237,
267,
291,
14,
21453,
4209,
14,
9475,
8,
277,
14,
1302,
63,
21,
9,
267,
291,
14,
827,
63,
1450,
63,
3807,
275,
5928,
14,
49,
27806,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
827,
63,
1450,
63,
3807,
14,
409,
10915,
8,
1960,
9,
267,
291,
14,
827,
63,
1450,
63,
3807,
14,
10376,
1547,
12382,
24,
480,
827,
63,
1450,
63,
3807,
2237,
267,
291,
14,
21453,
4209,
14,
9475,
8,
277,
14,
827,
63,
1450,
63,
3807,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
21453,
4209,
9,
267,
291,
14,
21453,
4209,
17,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
21453,
4209,
17,
14,
409,
24052,
8,
22,
9,
267,
291,
14,
21453,
4209,
17,
14,
409,
15182,
8,
16,
9,
267,
291,
14,
21453,
4209,
17,
14,
10376,
1547,
12382,
24,
480,
21453,
4209,
17,
2237,
267,
291,
14,
1302,
63,
22,
275,
5928,
14,
19890,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
22789,
275,
5928,
14,
19934,
8,
10604,
14,
19934,
14,
12839,
316,
12,
5928,
14,
19934,
14,
29373,
9,
267,
22789,
14,
409,
19918,
21537,
8,
16,
9,
267,
22789,
14,
409,
19462,
21537,
8,
16,
9,
267,
22789,
14,
409,
8436,
1858,
6216,
8,
277,
14,
1302,
63,
22,
14,
890,
4845,
1252,
1989,
8436,
1858,
6216,
1012,
267,
291,
14,
1302,
63,
22,
14,
21735,
4845,
8,
890,
4845,
9,
267,
291,
14,
1302,
63,
22,
14,
10376,
1547,
12382,
24,
480,
1302,
63,
22,
2237,
267,
291,
14,
21453,
4209,
17,
14,
9475,
8,
277,
14,
1302,
63,
22,
9,
267,
291,
14,
988,
63,
2969,
275,
5928,
14,
49,
27806,
8,
277,
14,
8165,
63,
1725,
63,
19,
9,
267,
291,
14,
988,
63,
2969,
14,
409,
10915,
8,
1960,
9,
267,
291,
14,
988,
63,
2969,
14,
10376,
1547,
12382,
24,
480,
988,
63,
2969,
2237,
267,
291,
14,
21453,
4209,
17,
14,
9475,
8,
277,
14,
988,
63,
2969,
9,
267,
291,
14,
18656,
14,
30571,
8,
277,
14,
21453,
4209,
17,
9,
267,
291,
14,
21453,
4209,
18,
275,
5928,
14,
27088,
18536,
342,
267,
291,
14,
21453,
4209,
18,
14,
409,
24052,
8,
22,
9,
267,
291,
14,
21453,
4209,
18,
14,
409,
15182,
8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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
] |
ghislainp/iris
|
lib/iris/tests/unit/fileformats/ff/test_FF2PP.py
|
2
|
15777
|
# (C) British Crown Copyright 2013 - 2015, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris. If not, see <http://www.gnu.org/licenses/>.
"""Unit tests for the :class:`iris.fileformat.ff.FF2PP` class."""
from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
import six
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests
import contextlib
import copy
import numpy as np
import warnings
from iris.exceptions import NotYetImplementedError
import iris.fileformats.ff as ff
import iris.fileformats.pp as pp
from iris.fileformats.ff import FF2PP
from iris.tests import mock
class Test____iter__(tests.IrisTest):
@mock.patch('iris.fileformats.ff.FFHeader')
def test_call_structure(self, _FFHeader):
# Check that the iter method calls the two necessary utility
# functions
extract_result = mock.Mock()
interpret_patch = mock.patch('iris.fileformats.pp._interpret_fields',
autospec=True, return_value=iter([]))
extract_patch = mock.patch('iris.fileformats.ff.FF2PP._extract_field',
autospec=True, return_value=extract_result)
FF2PP_instance = ff.FF2PP('mock')
with interpret_patch as interpret, extract_patch as extract:
list(iter(FF2PP_instance))
interpret.assert_called_once_with(extract_result)
extract.assert_called_once_with(FF2PP_instance)
class Test__extract_field__LBC_format(tests.IrisTest):
@contextlib.contextmanager
def mock_for_extract_field(self, fields, x=None, y=None):
"""
A context manager to ensure FF2PP._extract_field gets a field
instance looking like the next one in the "fields" iterable from
the "make_pp_field" call.
"""
with mock.patch('iris.fileformats.ff.FFHeader'):
ff2pp = ff.FF2PP('mock')
ff2pp._ff_header.lookup_table = [0, 0, len(fields)]
# Fake level constants, with shape specifying just one model-level.
ff2pp._ff_header.level_dependent_constants = np.zeros(1)
grid = mock.Mock()
grid.vectors = mock.Mock(return_value=(x, y))
ff2pp._ff_header.grid = mock.Mock(return_value=grid)
if six.PY3:
open_func = 'builtins.open'
else:
open_func = '__builtin__.open'
with mock.patch('numpy.fromfile', return_value=[0]), \
mock.patch(open_func), \
mock.patch('struct.unpack_from', return_value=[4]), \
mock.patch('iris.fileformats.pp.make_pp_field',
side_effect=fields), \
mock.patch('iris.fileformats.ff.FF2PP._payload',
return_value=(0, 0)):
yield ff2pp
def _mock_lbc(self, **kwargs):
"""Return a Mock object representing an LBC field."""
# Default kwargs for a valid LBC field mapping just 1 model-level.
field_kwargs = dict(lbtim=0, lblev=7777, lbvc=0, lbhem=101)
# Apply provided args (replacing any defaults if specified).
field_kwargs.update(kwargs)
# Return a mock with just those properties pre-defined.
return mock.Mock(**field_kwargs)
def test_LBC_header(self):
bzx, bzy = -10, 15
# stash m01s00i001
lbuser = [None, None, 121416, 1, None, None, 1]
field = self._mock_lbc(lbegin=0,
lbrow=10, lbnpt=12,
bdx=1, bdy=1, bzx=bzx, bzy=bzy,
lbuser=lbuser)
with self.mock_for_extract_field([field]) as ff2pp:
ff2pp._ff_header.dataset_type = 5
result = list(ff2pp._extract_field())
self.assertEqual([field], result)
self.assertEqual(field.lbrow, 10 + 14 * 2)
self.assertEqual(field.lbnpt, 12 + 16 * 2)
name_mapping_dict = dict(rim_width=slice(4, 6), y_halo=slice(2, 4),
x_halo=slice(0, 2))
boundary_packing = pp.SplittableInt(121416, name_mapping_dict)
self.assertEqual(field.boundary_packing, boundary_packing)
self.assertEqual(field.bzy, bzy - boundary_packing.y_halo * field.bdy)
self.assertEqual(field.bzx, bzx - boundary_packing.x_halo * field.bdx)
def check_non_trivial_coordinate_warning(self, field):
field.lbegin = 0
field.lbrow = 10
field.lbnpt = 12
# stash m01s31i020
field.lbuser = [None, None, 121416, 20, None, None, 1]
orig_bdx, orig_bdy = field.bdx, field.bdy
x = np.array([1, 2, 6])
y = np.array([1, 2, 6])
with self.mock_for_extract_field([field], x, y) as ff2pp:
ff2pp._ff_header.dataset_type = 5
with mock.patch('warnings.warn') as warn:
list(ff2pp._extract_field())
# Check the values are unchanged.
self.assertEqual(field.bdy, orig_bdy)
self.assertEqual(field.bdx, orig_bdx)
# Check a warning was raised with a suitable message.
warn_error_tmplt = 'Unexpected warning message: {}'
non_trivial_coord_warn_msg = warn.call_args[0][0]
msg = ('The x or y coordinates of your boundary condition field may '
'be incorrect, not having taken into account the boundary '
'size.')
self.assertTrue(non_trivial_coord_warn_msg.startswith(msg),
warn_error_tmplt.format(non_trivial_coord_warn_msg))
def test_LBC_header_non_trivial_coords_both(self):
# Check a warning is raised when both bdx and bdy are bad.
field = self._mock_lbc(bdx=0, bdy=0, bzx=10, bzy=10)
self.check_non_trivial_coordinate_warning(field)
field.bdy = field.bdx = field.bmdi
self.check_non_trivial_coordinate_warning(field)
def test_LBC_header_non_trivial_coords_x(self):
# Check a warning is raised when bdx is bad.
field = self._mock_lbc(bdx=0, bdy=10, bzx=10, bzy=10)
self.check_non_trivial_coordinate_warning(field)
field.bdx = field.bmdi
self.check_non_trivial_coordinate_warning(field)
def test_LBC_header_non_trivial_coords_y(self):
# Check a warning is raised when bdy is bad.
field = self._mock_lbc(bdx=10, bdy=0, bzx=10, bzy=10)
self.check_non_trivial_coordinate_warning(field)
field.bdy = field.bmdi
self.check_non_trivial_coordinate_warning(field)
def test_negative_bdy(self):
# Check a warning is raised when bdy is negative,
# we don't yet know what "north" means in this case.
field = self._mock_lbc(bdx=10, bdy=-10, bzx=10, bzy=10, lbegin=0,
lbuser=[0, 0, 121416, 0, None, None, 0],
lbrow=10, lbnpt=12)
with self.mock_for_extract_field([field]) as ff2pp:
ff2pp._ff_header.dataset_type = 5
with mock.patch('warnings.warn') as warn:
list(ff2pp._extract_field())
msg = 'The LBC has a bdy less than 0.'
self.assertTrue(warn.call_args[0][0].startswith(msg),
'Northwards bdy warning not correctly raised.')
class Test__payload(tests.IrisTest):
def setUp(self):
# Patch FFHeader to produce a mock header instead of opening a file.
self.mock_ff_header = mock.Mock()
self.mock_ff = self.patch('iris.fileformats.ff.FFHeader',
return_value=self.mock_ff_header)
# Make it look like a 32-bit LBC file.
self.mock_ff_header.word_depth = 8
self.mock_ff_header.dataset_type = 5
# Create a mock LBC type PPField.
self.mock_field = mock.Mock()
field = self.mock_field
field.raw_lbpack = 0
field.lbuser = [0]
field.lblrec = 777
field.lbext = 222
field.lbnrec = 50
field.boundary_packing = None
def test__basic(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
data_depth, data_type = ff2pp._payload(field)
self.assertEqual(data_depth, 4440)
self.assertEqual(data_type, np.dtype('>f8'))
def test__word_depth(self):
ff2pp = FF2PP('dummy_filename', word_depth=4)
field = self.mock_field
data_depth, data_type = ff2pp._payload(field)
self.assertEqual(data_depth, 2220)
self.assertEqual(data_type, np.dtype('>f4'))
def test__lbpack_1(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
field.raw_lbpack = 1
data_depth, data_type = ff2pp._payload(field)
self.assertEqual(data_depth, 396)
self.assertEqual(data_type, np.dtype('>f4'))
def test__lbpack_2(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
field.raw_lbpack = 2
data_depth, data_type = ff2pp._payload(field)
self.assertEqual(data_depth, 2220)
self.assertEqual(data_type, np.dtype('>f4'))
def test__lbpack_unsupported(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
field.raw_lbpack = 1239
with self.assertRaisesRegexp(
NotYetImplementedError,
'PP fields with LBPACK of 1239 are not supported.'):
ff2pp._payload(field)
def test__lbpack_lbc_error(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
field.raw_lbpack = 1
field.boundary_packing = 0 # Anything not None will do here.
with self.assertRaisesRegexp(
ValueError,
'packed LBC data is not supported'):
ff2pp._payload(field)
class Test__det_border(tests.IrisTest):
def setUp(self):
_FFH_patch = mock.patch('iris.fileformats.ff.FFHeader')
_FFH_patch.start()
self.addCleanup(_FFH_patch.stop)
def test_unequal_spacing_eitherside(self):
# Ensure that we do not interpret the case where there is not the same
# spacing on the lower edge as the upper edge.
ff2pp = FF2PP('dummy')
field_x = np.array([1, 2, 10])
msg = ('The x or y coordinates of your boundary condition field may '
'be incorrect, not having taken into account the boundary '
'size.')
with mock.patch('warnings.warn') as warn:
result = ff2pp._det_border(field_x, None)
warn.assert_called_with(msg)
self.assertIs(result, field_x)
def test_increasing_field_values(self):
# Field where its values a increasing.
ff2pp = FF2PP('dummy')
field_x = np.array([1, 2, 3])
com = np.array([0, 1, 2, 3, 4])
result = ff2pp._det_border(field_x, 1)
self.assertArrayEqual(result, com)
def test_decreasing_field_values(self):
# Field where its values a decreasing.
ff2pp = FF2PP('dummy')
field_x = np.array([3, 2, 1])
com = np.array([4, 3, 2, 1, 0])
result = ff2pp._det_border(field_x, 1)
self.assertArrayEqual(result, com)
class Test__adjust_field_for_lbc(tests.IrisTest):
def setUp(self):
# Patch FFHeader to produce a mock header instead of opening a file.
self.mock_ff_header = mock.Mock()
self.mock_ff_header.dataset_type = 5
self.mock_ff = self.patch('iris.fileformats.ff.FFHeader',
return_value=self.mock_ff_header)
# Create a mock LBC type PPField.
self.mock_field = mock.Mock()
field = self.mock_field
field.lbtim = 0
field.lblev = 7777
field.lbvc = 0
field.lbnpt = 1001
field.lbrow = 2001
field.lbuser = (None, None, 80504)
field.lbpack = pp.SplittableInt(0)
field.boundary_packing = None
field.bdx = 1.0
field.bzx = 0.0
field.bdy = 1.0
field.bzy = 0.0
def test__basic(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
ff2pp._adjust_field_for_lbc(field)
self.assertEqual(field.lbtim, 11)
self.assertEqual(field.lbvc, 65)
self.assertEqual(field.boundary_packing.rim_width, 8)
self.assertEqual(field.boundary_packing.y_halo, 5)
self.assertEqual(field.boundary_packing.x_halo, 4)
self.assertEqual(field.lbnpt, 1009)
self.assertEqual(field.lbrow, 2011)
def test__bad_lbtim(self):
self.mock_field.lbtim = 717
ff2pp = FF2PP('dummy_filename')
with self.assertRaisesRegexp(ValueError,
'LBTIM of 717, expected only 0 or 11'):
ff2pp._adjust_field_for_lbc(self.mock_field)
def test__bad_lbvc(self):
self.mock_field.lbvc = 312
ff2pp = FF2PP('dummy_filename')
with self.assertRaisesRegexp(ValueError,
'LBVC of 312, expected only 0 or 65'):
ff2pp._adjust_field_for_lbc(self.mock_field)
class Test__fields_over_all_levels(tests.IrisTest):
def setUp(self):
# Patch FFHeader to produce a mock header instead of opening a file.
self.mock_ff_header = mock.Mock()
self.mock_ff_header.dataset_type = 5
# Fake the level constants to look like 3 model levels.
self.n_all_levels = 3
self.mock_ff_header.level_dependent_constants = \
np.zeros((self.n_all_levels))
self.mock_ff = self.patch('iris.fileformats.ff.FFHeader',
return_value=self.mock_ff_header)
# Create a simple mock for a test field.
self.mock_field = mock.Mock()
field = self.mock_field
field.lbhem = 103
self.original_lblev = mock.sentinel.untouched_lbev
field.lblev = self.original_lblev
def _check_expected_levels(self, results, n_levels):
if n_levels is 0:
self.assertEqual(len(results), 1)
self.assertEqual(results[0].lblev, self.original_lblev)
else:
self.assertEqual(len(results), n_levels)
self.assertEqual([fld.lblev for fld in results],
list(range(n_levels)))
def test__is_lbc(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
results = list(ff2pp._fields_over_all_levels(field))
self._check_expected_levels(results, 3)
def test__lbhem_too_small(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
field.lbhem = 100
with self.assertRaisesRegexp(
ValueError,
'hence >= 101'):
results = list(ff2pp._fields_over_all_levels(field))
def test__lbhem_too_large(self):
ff2pp = FF2PP('dummy_filename')
field = self.mock_field
field.lbhem = 105
with self.assertRaisesRegexp(
ValueError,
'more than the total number of levels in the file = 3'):
results = list(ff2pp._fields_over_all_levels(field))
if __name__ == "__main__":
tests.main()
|
gpl-3.0
|
[
3,
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
6171,
446,
6900,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
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,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
5072,
2295,
367,
314,
520,
533,
1705,
11885,
14,
493,
908,
14,
556,
14,
1665,
18,
7701,
64,
1021,
1041,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
646,
3816,
199,
199,
3,
3161,
12192,
14,
2219,
1642,
880,
626,
2005,
7645,
883,
506,
2536,
9096,
2544,
199,
3,
16306,
7003,
587,
14,
199,
646,
12192,
14,
2219,
465,
2295,
199,
199,
646,
15502,
199,
646,
1331,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
199,
504,
12192,
14,
3924,
492,
2832,
57,
386,
3500,
547,
199,
646,
12192,
14,
493,
6321,
14,
556,
465,
16328,
199,
646,
12192,
14,
493,
6321,
14,
802,
465,
11618,
199,
504,
12192,
14,
493,
6321,
14,
556,
492,
25046,
18,
7701,
199,
504,
12192,
14,
2219,
492,
1683,
421,
199,
533,
1379,
4741,
1661,
721,
2219,
14,
41,
5719,
774,
304,
272,
768,
1805,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
2567,
358,
272,
347,
511,
63,
1250,
63,
6976,
8,
277,
12,
485,
1665,
2567,
304,
267,
327,
2670,
626,
314,
2740,
1083,
4882,
314,
2877,
5784,
11420,
267,
327,
3423,
267,
5536,
63,
1099,
275,
1683,
14,
3346,
342,
267,
15579,
63,
2068,
275,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
802,
423,
21533,
63,
955,
297,
3660,
18052,
29,
549,
12,
372,
63,
585,
29,
1661,
26064,
267,
5536,
63,
2068,
275,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
18,
7701,
423,
5005,
63,
698,
297,
3521,
18052,
29,
549,
12,
372,
63,
585,
29,
5005,
63,
1099,
9,
398,
25046,
18,
7701,
63,
842,
275,
16328,
14,
1665,
18,
7701,
360,
1805,
358,
267,
543,
15579,
63,
2068,
465,
15579,
12,
5536,
63,
2068,
465,
5536,
26,
288,
769,
8,
1661,
8,
1665,
18,
7701,
63,
842,
430,
398,
15579,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
5005,
63,
1099,
9,
267,
5536,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1665,
18,
7701,
63,
842,
9,
421,
199,
533,
1379,
363,
5005,
63,
698,
363,
44,
6265,
63,
908,
8,
2219,
14,
41,
5719,
774,
304,
272,
768,
23464,
14,
14237,
272,
347,
1683,
63,
509,
63,
5005,
63,
698,
8,
277,
12,
1504,
12,
671,
29,
403,
12,
612,
29,
403,
304,
267,
408,
267,
437,
1067,
5256,
370,
4868,
25046,
18,
7701,
423,
5005,
63,
698,
7545,
282,
901,
267,
1256,
10023,
2839,
314,
2163,
1373,
315,
314,
298,
955,
2,
6076,
687,
267,
314,
298,
1875,
63,
802,
63,
698,
2,
1240,
14,
398,
408,
267,
543,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
2567,
735,
288,
16328,
18,
802,
275,
16328,
14,
1665,
18,
7701,
360,
1805,
358,
267,
16328,
18,
802,
423,
556,
63,
1291,
14,
3892,
63,
1224,
275,
359,
16,
12,
378,
12,
822,
8,
955,
1874,
267,
327,
7777,
2166,
5262,
12,
543,
2215,
9176,
2951,
1373,
1402,
13,
1896,
14,
267,
16328,
18,
802,
423,
556,
63,
1291,
14,
1896,
63,
7106,
63,
5559,
275,
980,
14,
4250,
8,
17,
9,
267,
6068,
275,
1683,
14,
3346,
342,
267,
6068,
14,
12280,
275,
1683,
14,
3346,
8,
1107,
63,
585,
2687,
88,
12,
612,
430,
267,
16328,
18,
802,
423,
556,
63,
1291,
14,
3825,
275,
1683,
14,
3346,
8,
1107,
63,
585,
29,
3825,
9,
398,
340,
3816,
14,
4521,
19,
26,
288,
1551,
63,
1532,
275,
283,
10372,
14,
1490,
7,
267,
587,
26,
288,
1551,
63,
1532,
275,
2560,
5351,
4343,
1490,
7,
267,
543,
1683,
14,
2068,
360,
4714,
14,
30717,
297,
372,
63,
585,
1524,
16,
2522,
971,
355,
1683,
14,
2068,
8,
1490,
63,
1532,
395,
971,
355,
1683,
14,
2068,
360,
1820,
14,
5301,
63,
504,
297,
372,
63,
585,
1524,
20,
2522,
971,
355,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
802,
14,
1875,
63,
802,
63,
698,
297,
2574,
5366,
63,
5881,
29,
955,
395,
971,
355,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
18,
7701,
423,
4749,
297,
2574,
372,
63,
585,
2687,
16,
12,
378,
2298,
288,
1995,
16328,
18,
802,
339,
347,
485,
1805,
63,
76,
3776,
8,
277,
12,
1011,
958,
304,
267,
408,
1767,
282,
4420,
909,
6144,
376,
491,
6265,
901,
1041,
267,
327,
3758,
2074,
367,
282,
1686,
491,
6265,
901,
4412,
2951,
413,
1402,
13,
1896,
14,
267,
901,
63,
958,
275,
1211,
8,
6374,
2906,
29,
16,
12,
634,
830,
86,
29,
16713,
12,
11104,
6737,
29,
16,
12,
11104,
27037,
29,
4893,
9,
267,
327,
14618,
2741,
1249,
334,
1155,
13121,
1263,
4243,
340,
2013,
680,
267,
901,
63,
958,
14,
873,
8,
958,
9,
267,
327,
1432,
282,
1683,
543,
2951,
5204,
4382,
876,
13,
4037,
14,
267,
372,
1683,
14,
3346,
3682,
698,
63,
958,
9,
339,
347
] |
[
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
6171,
446,
6900,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
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,
473,
5719,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
624,
5072,
2295,
367,
314,
520,
533,
1705,
11885,
14,
493,
908,
14,
556,
14,
1665,
18,
7701,
64,
1021,
1041,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
646,
3816,
199,
199,
3,
3161,
12192,
14,
2219,
1642,
880,
626,
2005,
7645,
883,
506,
2536,
9096,
2544,
199,
3,
16306,
7003,
587,
14,
199,
646,
12192,
14,
2219,
465,
2295,
199,
199,
646,
15502,
199,
646,
1331,
199,
646,
2680,
465,
980,
199,
646,
3598,
199,
199,
504,
12192,
14,
3924,
492,
2832,
57,
386,
3500,
547,
199,
646,
12192,
14,
493,
6321,
14,
556,
465,
16328,
199,
646,
12192,
14,
493,
6321,
14,
802,
465,
11618,
199,
504,
12192,
14,
493,
6321,
14,
556,
492,
25046,
18,
7701,
199,
504,
12192,
14,
2219,
492,
1683,
421,
199,
533,
1379,
4741,
1661,
721,
2219,
14,
41,
5719,
774,
304,
272,
768,
1805,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
2567,
358,
272,
347,
511,
63,
1250,
63,
6976,
8,
277,
12,
485,
1665,
2567,
304,
267,
327,
2670,
626,
314,
2740,
1083,
4882,
314,
2877,
5784,
11420,
267,
327,
3423,
267,
5536,
63,
1099,
275,
1683,
14,
3346,
342,
267,
15579,
63,
2068,
275,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
802,
423,
21533,
63,
955,
297,
3660,
18052,
29,
549,
12,
372,
63,
585,
29,
1661,
26064,
267,
5536,
63,
2068,
275,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
18,
7701,
423,
5005,
63,
698,
297,
3521,
18052,
29,
549,
12,
372,
63,
585,
29,
5005,
63,
1099,
9,
398,
25046,
18,
7701,
63,
842,
275,
16328,
14,
1665,
18,
7701,
360,
1805,
358,
267,
543,
15579,
63,
2068,
465,
15579,
12,
5536,
63,
2068,
465,
5536,
26,
288,
769,
8,
1661,
8,
1665,
18,
7701,
63,
842,
430,
398,
15579,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
5005,
63,
1099,
9,
267,
5536,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
1665,
18,
7701,
63,
842,
9,
421,
199,
533,
1379,
363,
5005,
63,
698,
363,
44,
6265,
63,
908,
8,
2219,
14,
41,
5719,
774,
304,
272,
768,
23464,
14,
14237,
272,
347,
1683,
63,
509,
63,
5005,
63,
698,
8,
277,
12,
1504,
12,
671,
29,
403,
12,
612,
29,
403,
304,
267,
408,
267,
437,
1067,
5256,
370,
4868,
25046,
18,
7701,
423,
5005,
63,
698,
7545,
282,
901,
267,
1256,
10023,
2839,
314,
2163,
1373,
315,
314,
298,
955,
2,
6076,
687,
267,
314,
298,
1875,
63,
802,
63,
698,
2,
1240,
14,
398,
408,
267,
543,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
2567,
735,
288,
16328,
18,
802,
275,
16328,
14,
1665,
18,
7701,
360,
1805,
358,
267,
16328,
18,
802,
423,
556,
63,
1291,
14,
3892,
63,
1224,
275,
359,
16,
12,
378,
12,
822,
8,
955,
1874,
267,
327,
7777,
2166,
5262,
12,
543,
2215,
9176,
2951,
1373,
1402,
13,
1896,
14,
267,
16328,
18,
802,
423,
556,
63,
1291,
14,
1896,
63,
7106,
63,
5559,
275,
980,
14,
4250,
8,
17,
9,
267,
6068,
275,
1683,
14,
3346,
342,
267,
6068,
14,
12280,
275,
1683,
14,
3346,
8,
1107,
63,
585,
2687,
88,
12,
612,
430,
267,
16328,
18,
802,
423,
556,
63,
1291,
14,
3825,
275,
1683,
14,
3346,
8,
1107,
63,
585,
29,
3825,
9,
398,
340,
3816,
14,
4521,
19,
26,
288,
1551,
63,
1532,
275,
283,
10372,
14,
1490,
7,
267,
587,
26,
288,
1551,
63,
1532,
275,
2560,
5351,
4343,
1490,
7,
267,
543,
1683,
14,
2068,
360,
4714,
14,
30717,
297,
372,
63,
585,
1524,
16,
2522,
971,
355,
1683,
14,
2068,
8,
1490,
63,
1532,
395,
971,
355,
1683,
14,
2068,
360,
1820,
14,
5301,
63,
504,
297,
372,
63,
585,
1524,
20,
2522,
971,
355,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
802,
14,
1875,
63,
802,
63,
698,
297,
2574,
5366,
63,
5881,
29,
955,
395,
971,
355,
1683,
14,
2068,
360,
11885,
14,
493,
6321,
14,
556,
14,
1665,
18,
7701,
423,
4749,
297,
2574,
372,
63,
585,
2687,
16,
12,
378,
2298,
288,
1995,
16328,
18,
802,
339,
347,
485,
1805,
63,
76,
3776,
8,
277,
12,
1011,
958,
304,
267,
408,
1767,
282,
4420,
909,
6144,
376,
491,
6265,
901,
1041,
267,
327,
3758,
2074,
367,
282,
1686,
491,
6265,
901,
4412,
2951,
413,
1402,
13,
1896,
14,
267,
901,
63,
958,
275,
1211,
8,
6374,
2906,
29,
16,
12,
634,
830,
86,
29,
16713,
12,
11104,
6737,
29,
16,
12,
11104,
27037,
29,
4893,
9,
267,
327,
14618,
2741,
1249,
334,
1155,
13121,
1263,
4243,
340,
2013,
680,
267,
901,
63,
958,
14,
873,
8,
958,
9,
267,
327,
1432,
282,
1683,
543,
2951,
5204,
4382,
876,
13,
4037,
14,
267,
372,
1683,
14,
3346,
3682,
698,
63,
958,
9,
339,
347,
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,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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
] |
ycaihua/kbengine
|
kbe/res/scripts/common/Lib/test/test_codecs.py
|
60
|
111483
|
import codecs
import contextlib
import io
import locale
import sys
import unittest
import warnings
import encodings
from test import support
if sys.platform == 'win32':
VISTA_OR_LATER = (sys.getwindowsversion().major >= 6)
else:
VISTA_OR_LATER = False
try:
import ctypes
except ImportError:
ctypes = None
SIZEOF_WCHAR_T = -1
else:
SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar)
def coding_checker(self, coder):
def check(input, expect):
self.assertEqual(coder(input), (expect, len(input)))
return check
class Queue(object):
"""
queue: write bytes at one end, read bytes from the other end
"""
def __init__(self, buffer):
self._buffer = buffer
def write(self, chars):
self._buffer += chars
def read(self, size=-1):
if size<0:
s = self._buffer
self._buffer = self._buffer[:0] # make empty
return s
else:
s = self._buffer[:size]
self._buffer = self._buffer[size:]
return s
class MixInCheckStateHandling:
def check_state_handling_decode(self, encoding, u, s):
for i in range(len(s)+1):
d = codecs.getincrementaldecoder(encoding)()
part1 = d.decode(s[:i])
state = d.getstate()
self.assertIsInstance(state[1], int)
# Check that the condition stated in the documentation for
# IncrementalDecoder.getstate() holds
if not state[1]:
# reset decoder to the default state without anything buffered
d.setstate((state[0][:0], 0))
# Feeding the previous input may not produce any output
self.assertTrue(not d.decode(state[0]))
# The decoder must return to the same state
self.assertEqual(state, d.getstate())
# Create a new decoder and set it to the state
# we extracted from the old one
d = codecs.getincrementaldecoder(encoding)()
d.setstate(state)
part2 = d.decode(s[i:], True)
self.assertEqual(u, part1+part2)
def check_state_handling_encode(self, encoding, u, s):
for i in range(len(u)+1):
d = codecs.getincrementalencoder(encoding)()
part1 = d.encode(u[:i])
state = d.getstate()
d = codecs.getincrementalencoder(encoding)()
d.setstate(state)
part2 = d.encode(u[i:], True)
self.assertEqual(s, part1+part2)
class ReadTest(MixInCheckStateHandling):
def check_partial(self, input, partialresults):
# get a StreamReader for the encoding and feed the bytestring version
# of input to the reader byte by byte. Read everything available from
# the StreamReader and check that the results equal the appropriate
# entries from partialresults.
q = Queue(b"")
r = codecs.getreader(self.encoding)(q)
result = ""
for (c, partialresult) in zip(input.encode(self.encoding), partialresults):
q.write(bytes([c]))
result += r.read()
self.assertEqual(result, partialresult)
# check that there's nothing left in the buffers
self.assertEqual(r.read(), "")
self.assertEqual(r.bytebuffer, b"")
# do the check again, this time using a incremental decoder
d = codecs.getincrementaldecoder(self.encoding)()
result = ""
for (c, partialresult) in zip(input.encode(self.encoding), partialresults):
result += d.decode(bytes([c]))
self.assertEqual(result, partialresult)
# check that there's nothing left in the buffers
self.assertEqual(d.decode(b"", True), "")
self.assertEqual(d.buffer, b"")
# Check whether the reset method works properly
d.reset()
result = ""
for (c, partialresult) in zip(input.encode(self.encoding), partialresults):
result += d.decode(bytes([c]))
self.assertEqual(result, partialresult)
# check that there's nothing left in the buffers
self.assertEqual(d.decode(b"", True), "")
self.assertEqual(d.buffer, b"")
# check iterdecode()
encoded = input.encode(self.encoding)
self.assertEqual(
input,
"".join(codecs.iterdecode([bytes([c]) for c in encoded], self.encoding))
)
def test_readline(self):
def getreader(input):
stream = io.BytesIO(input.encode(self.encoding))
return codecs.getreader(self.encoding)(stream)
def readalllines(input, keepends=True, size=None):
reader = getreader(input)
lines = []
while True:
line = reader.readline(size=size, keepends=keepends)
if not line:
break
lines.append(line)
return "|".join(lines)
s = "foo\nbar\r\nbaz\rspam\u2028eggs"
sexpected = "foo\n|bar\r\n|baz\r|spam\u2028|eggs"
sexpectednoends = "foo|bar|baz|spam|eggs"
self.assertEqual(readalllines(s, True), sexpected)
self.assertEqual(readalllines(s, False), sexpectednoends)
self.assertEqual(readalllines(s, True, 10), sexpected)
self.assertEqual(readalllines(s, False, 10), sexpectednoends)
lineends = ("\n", "\r\n", "\r", "\u2028")
# Test long lines (multiple calls to read() in readline())
vw = []
vwo = []
for (i, lineend) in enumerate(lineends):
vw.append((i*200+200)*"\u3042" + lineend)
vwo.append((i*200+200)*"\u3042")
self.assertEqual(readalllines("".join(vw), True), "|".join(vw))
self.assertEqual(readalllines("".join(vw), False), "|".join(vwo))
# Test lines where the first read might end with \r, so the
# reader has to look ahead whether this is a lone \r or a \r\n
for size in range(80):
for lineend in lineends:
s = 10*(size*"a" + lineend + "xxx\n")
reader = getreader(s)
for i in range(10):
self.assertEqual(
reader.readline(keepends=True),
size*"a" + lineend,
)
self.assertEqual(
reader.readline(keepends=True),
"xxx\n",
)
reader = getreader(s)
for i in range(10):
self.assertEqual(
reader.readline(keepends=False),
size*"a",
)
self.assertEqual(
reader.readline(keepends=False),
"xxx",
)
def test_mixed_readline_and_read(self):
lines = ["Humpty Dumpty sat on a wall,\n",
"Humpty Dumpty had a great fall.\r\n",
"All the king's horses and all the king's men\r",
"Couldn't put Humpty together again."]
data = ''.join(lines)
def getreader():
stream = io.BytesIO(data.encode(self.encoding))
return codecs.getreader(self.encoding)(stream)
# Issue #8260: Test readline() followed by read()
f = getreader()
self.assertEqual(f.readline(), lines[0])
self.assertEqual(f.read(), ''.join(lines[1:]))
self.assertEqual(f.read(), '')
# Issue #16636: Test readline() followed by readlines()
f = getreader()
self.assertEqual(f.readline(), lines[0])
self.assertEqual(f.readlines(), lines[1:])
self.assertEqual(f.read(), '')
# Test read() followed by read()
f = getreader()
self.assertEqual(f.read(size=40, chars=5), data[:5])
self.assertEqual(f.read(), data[5:])
self.assertEqual(f.read(), '')
# Issue #12446: Test read() followed by readlines()
f = getreader()
self.assertEqual(f.read(size=40, chars=5), data[:5])
self.assertEqual(f.readlines(), [lines[0][5:]] + lines[1:])
self.assertEqual(f.read(), '')
def test_bug1175396(self):
s = [
'<%!--===================================================\r\n',
' BLOG index page: show recent articles,\r\n',
' today\'s articles, or articles of a specific date.\r\n',
'========================================================--%>\r\n',
'<%@inputencoding="ISO-8859-1"%>\r\n',
'<%@pagetemplate=TEMPLATE.y%>\r\n',
'<%@import=import frog.util, frog%>\r\n',
'<%@import=import frog.objects%>\r\n',
'<%@import=from frog.storageerrors import StorageError%>\r\n',
'<%\r\n',
'\r\n',
'import logging\r\n',
'log=logging.getLogger("Snakelets.logger")\r\n',
'\r\n',
'\r\n',
'user=self.SessionCtx.user\r\n',
'storageEngine=self.SessionCtx.storageEngine\r\n',
'\r\n',
'\r\n',
'def readArticlesFromDate(date, count=None):\r\n',
' entryids=storageEngine.listBlogEntries(date)\r\n',
' entryids.reverse() # descending\r\n',
' if count:\r\n',
' entryids=entryids[:count]\r\n',
' try:\r\n',
' return [ frog.objects.BlogEntry.load(storageEngine, date, Id) for Id in entryids ]\r\n',
' except StorageError,x:\r\n',
' log.error("Error loading articles: "+str(x))\r\n',
' self.abort("cannot load articles")\r\n',
'\r\n',
'showdate=None\r\n',
'\r\n',
'arg=self.Request.getArg()\r\n',
'if arg=="today":\r\n',
' #-------------------- TODAY\'S ARTICLES\r\n',
' self.write("<h2>Today\'s articles</h2>")\r\n',
' showdate = frog.util.isodatestr() \r\n',
' entries = readArticlesFromDate(showdate)\r\n',
'elif arg=="active":\r\n',
' #-------------------- ACTIVE ARTICLES redirect\r\n',
' self.Yredirect("active.y")\r\n',
'elif arg=="login":\r\n',
' #-------------------- LOGIN PAGE redirect\r\n',
' self.Yredirect("login.y")\r\n',
'elif arg=="date":\r\n',
' #-------------------- ARTICLES OF A SPECIFIC DATE\r\n',
' showdate = self.Request.getParameter("date")\r\n',
' self.write("<h2>Articles written on %s</h2>"% frog.util.mediumdatestr(showdate))\r\n',
' entries = readArticlesFromDate(showdate)\r\n',
'else:\r\n',
' #-------------------- RECENT ARTICLES\r\n',
' self.write("<h2>Recent articles</h2>")\r\n',
' dates=storageEngine.listBlogEntryDates()\r\n',
' if dates:\r\n',
' entries=[]\r\n',
' SHOWAMOUNT=10\r\n',
' for showdate in dates:\r\n',
' entries.extend( readArticlesFromDate(showdate, SHOWAMOUNT-len(entries)) )\r\n',
' if len(entries)>=SHOWAMOUNT:\r\n',
' break\r\n',
' \r\n',
]
stream = io.BytesIO("".join(s).encode(self.encoding))
reader = codecs.getreader(self.encoding)(stream)
for (i, line) in enumerate(reader):
self.assertEqual(line, s[i])
def test_readlinequeue(self):
q = Queue(b"")
writer = codecs.getwriter(self.encoding)(q)
reader = codecs.getreader(self.encoding)(q)
# No lineends
writer.write("foo\r")
self.assertEqual(reader.readline(keepends=False), "foo")
writer.write("\nbar\r")
self.assertEqual(reader.readline(keepends=False), "")
self.assertEqual(reader.readline(keepends=False), "bar")
writer.write("baz")
self.assertEqual(reader.readline(keepends=False), "baz")
self.assertEqual(reader.readline(keepends=False), "")
# Lineends
writer.write("foo\r")
self.assertEqual(reader.readline(keepends=True), "foo\r")
writer.write("\nbar\r")
self.assertEqual(reader.readline(keepends=True), "\n")
self.assertEqual(reader.readline(keepends=True), "bar\r")
writer.write("baz")
self.assertEqual(reader.readline(keepends=True), "baz")
self.assertEqual(reader.readline(keepends=True), "")
writer.write("foo\r\n")
self.assertEqual(reader.readline(keepends=True), "foo\r\n")
def test_bug1098990_a(self):
s1 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\r\n"
s2 = "offending line: ladfj askldfj klasdj fskla dfzaskdj fasklfj laskd fjasklfzzzzaa%whereisthis!!!\r\n"
s3 = "next line.\r\n"
s = (s1+s2+s3).encode(self.encoding)
stream = io.BytesIO(s)
reader = codecs.getreader(self.encoding)(stream)
self.assertEqual(reader.readline(), s1)
self.assertEqual(reader.readline(), s2)
self.assertEqual(reader.readline(), s3)
self.assertEqual(reader.readline(), "")
def test_bug1098990_b(self):
s1 = "aaaaaaaaaaaaaaaaaaaaaaaa\r\n"
s2 = "bbbbbbbbbbbbbbbbbbbbbbbb\r\n"
s3 = "stillokay:bbbbxx\r\n"
s4 = "broken!!!!badbad\r\n"
s5 = "againokay.\r\n"
s = (s1+s2+s3+s4+s5).encode(self.encoding)
stream = io.BytesIO(s)
reader = codecs.getreader(self.encoding)(stream)
self.assertEqual(reader.readline(), s1)
self.assertEqual(reader.readline(), s2)
self.assertEqual(reader.readline(), s3)
self.assertEqual(reader.readline(), s4)
self.assertEqual(reader.readline(), s5)
self.assertEqual(reader.readline(), "")
ill_formed_sequence_replace = "\ufffd"
def test_lone_surrogates(self):
self.assertRaises(UnicodeEncodeError, "\ud800".encode, self.encoding)
self.assertEqual("[\uDC80]".encode(self.encoding, "backslashreplace"),
"[\\udc80]".encode(self.encoding))
self.assertEqual("[\uDC80]".encode(self.encoding, "xmlcharrefreplace"),
"[�]".encode(self.encoding))
self.assertEqual("[\uDC80]".encode(self.encoding, "ignore"),
"[]".encode(self.encoding))
self.assertEqual("[\uDC80]".encode(self.encoding, "replace"),
"[?]".encode(self.encoding))
bom = "".encode(self.encoding)
for before, after in [("\U00010fff", "A"), ("[", "]"),
("A", "\U00010fff")]:
before_sequence = before.encode(self.encoding)[len(bom):]
after_sequence = after.encode(self.encoding)[len(bom):]
test_string = before + "\uDC80" + after
test_sequence = (bom + before_sequence +
self.ill_formed_sequence + after_sequence)
self.assertRaises(UnicodeDecodeError, test_sequence.decode,
self.encoding)
self.assertEqual(test_string.encode(self.encoding,
"surrogatepass"),
test_sequence)
self.assertEqual(test_sequence.decode(self.encoding,
"surrogatepass"),
test_string)
self.assertEqual(test_sequence.decode(self.encoding, "ignore"),
before + after)
self.assertEqual(test_sequence.decode(self.encoding, "replace"),
before + self.ill_formed_sequence_replace + after)
class UTF32Test(ReadTest, unittest.TestCase):
encoding = "utf-32"
if sys.byteorder == 'little':
ill_formed_sequence = b"\x80\xdc\x00\x00"
else:
ill_formed_sequence = b"\x00\x00\xdc\x80"
spamle = (b'\xff\xfe\x00\x00'
b's\x00\x00\x00p\x00\x00\x00a\x00\x00\x00m\x00\x00\x00'
b's\x00\x00\x00p\x00\x00\x00a\x00\x00\x00m\x00\x00\x00')
spambe = (b'\x00\x00\xfe\xff'
b'\x00\x00\x00s\x00\x00\x00p\x00\x00\x00a\x00\x00\x00m'
b'\x00\x00\x00s\x00\x00\x00p\x00\x00\x00a\x00\x00\x00m')
def test_only_one_bom(self):
_,_,reader,writer = codecs.lookup(self.encoding)
# encode some stream
s = io.BytesIO()
f = writer(s)
f.write("spam")
f.write("spam")
d = s.getvalue()
# check whether there is exactly one BOM in it
self.assertTrue(d == self.spamle or d == self.spambe)
# try to read it back
s = io.BytesIO(d)
f = reader(s)
self.assertEqual(f.read(), "spamspam")
def test_badbom(self):
s = io.BytesIO(4*b"\xff")
f = codecs.getreader(self.encoding)(s)
self.assertRaises(UnicodeError, f.read)
s = io.BytesIO(8*b"\xff")
f = codecs.getreader(self.encoding)(s)
self.assertRaises(UnicodeError, f.read)
def test_partial(self):
self.check_partial(
"\x00\xff\u0100\uffff\U00010000",
[
"", # first byte of BOM read
"", # second byte of BOM read
"", # third byte of BOM read
"", # fourth byte of BOM read => byteorder known
"",
"",
"",
"\x00",
"\x00",
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff",
"\x00\xff",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff\U00010000",
]
)
def test_handlers(self):
self.assertEqual(('\ufffd', 1),
codecs.utf_32_decode(b'\x01', 'replace', True))
self.assertEqual(('', 1),
codecs.utf_32_decode(b'\x01', 'ignore', True))
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_32_decode,
b"\xff", "strict", True)
def test_decoder_state(self):
self.check_state_handling_decode(self.encoding,
"spamspam", self.spamle)
self.check_state_handling_decode(self.encoding,
"spamspam", self.spambe)
def test_issue8941(self):
# Issue #8941: insufficient result allocation when decoding into
# surrogate pairs on UCS-2 builds.
encoded_le = b'\xff\xfe\x00\x00' + b'\x00\x00\x01\x00' * 1024
self.assertEqual('\U00010000' * 1024,
codecs.utf_32_decode(encoded_le)[0])
encoded_be = b'\x00\x00\xfe\xff' + b'\x00\x01\x00\x00' * 1024
self.assertEqual('\U00010000' * 1024,
codecs.utf_32_decode(encoded_be)[0])
class UTF32LETest(ReadTest, unittest.TestCase):
encoding = "utf-32-le"
ill_formed_sequence = b"\x80\xdc\x00\x00"
def test_partial(self):
self.check_partial(
"\x00\xff\u0100\uffff\U00010000",
[
"",
"",
"",
"\x00",
"\x00",
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff",
"\x00\xff",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff\U00010000",
]
)
def test_simple(self):
self.assertEqual("\U00010203".encode(self.encoding), b"\x03\x02\x01\x00")
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_32_le_decode,
b"\xff", "strict", True)
def test_issue8941(self):
# Issue #8941: insufficient result allocation when decoding into
# surrogate pairs on UCS-2 builds.
encoded = b'\x00\x00\x01\x00' * 1024
self.assertEqual('\U00010000' * 1024,
codecs.utf_32_le_decode(encoded)[0])
class UTF32BETest(ReadTest, unittest.TestCase):
encoding = "utf-32-be"
ill_formed_sequence = b"\x00\x00\xdc\x80"
def test_partial(self):
self.check_partial(
"\x00\xff\u0100\uffff\U00010000",
[
"",
"",
"",
"\x00",
"\x00",
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff",
"\x00\xff",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff\U00010000",
]
)
def test_simple(self):
self.assertEqual("\U00010203".encode(self.encoding), b"\x00\x01\x02\x03")
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_32_be_decode,
b"\xff", "strict", True)
def test_issue8941(self):
# Issue #8941: insufficient result allocation when decoding into
# surrogate pairs on UCS-2 builds.
encoded = b'\x00\x01\x00\x00' * 1024
self.assertEqual('\U00010000' * 1024,
codecs.utf_32_be_decode(encoded)[0])
class UTF16Test(ReadTest, unittest.TestCase):
encoding = "utf-16"
if sys.byteorder == 'little':
ill_formed_sequence = b"\x80\xdc"
else:
ill_formed_sequence = b"\xdc\x80"
spamle = b'\xff\xfes\x00p\x00a\x00m\x00s\x00p\x00a\x00m\x00'
spambe = b'\xfe\xff\x00s\x00p\x00a\x00m\x00s\x00p\x00a\x00m'
def test_only_one_bom(self):
_,_,reader,writer = codecs.lookup(self.encoding)
# encode some stream
s = io.BytesIO()
f = writer(s)
f.write("spam")
f.write("spam")
d = s.getvalue()
# check whether there is exactly one BOM in it
self.assertTrue(d == self.spamle or d == self.spambe)
# try to read it back
s = io.BytesIO(d)
f = reader(s)
self.assertEqual(f.read(), "spamspam")
def test_badbom(self):
s = io.BytesIO(b"\xff\xff")
f = codecs.getreader(self.encoding)(s)
self.assertRaises(UnicodeError, f.read)
s = io.BytesIO(b"\xff\xff\xff\xff")
f = codecs.getreader(self.encoding)(s)
self.assertRaises(UnicodeError, f.read)
def test_partial(self):
self.check_partial(
"\x00\xff\u0100\uffff\U00010000",
[
"", # first byte of BOM read
"", # second byte of BOM read => byteorder known
"",
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff\U00010000",
]
)
def test_handlers(self):
self.assertEqual(('\ufffd', 1),
codecs.utf_16_decode(b'\x01', 'replace', True))
self.assertEqual(('', 1),
codecs.utf_16_decode(b'\x01', 'ignore', True))
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_16_decode,
b"\xff", "strict", True)
def test_decoder_state(self):
self.check_state_handling_decode(self.encoding,
"spamspam", self.spamle)
self.check_state_handling_decode(self.encoding,
"spamspam", self.spambe)
def test_bug691291(self):
# Files are always opened in binary mode, even if no binary mode was
# specified. This means that no automatic conversion of '\n' is done
# on reading and writing.
s1 = 'Hello\r\nworld\r\n'
s = s1.encode(self.encoding)
self.addCleanup(support.unlink, support.TESTFN)
with open(support.TESTFN, 'wb') as fp:
fp.write(s)
with support.check_warnings(('', DeprecationWarning)):
reader = codecs.open(support.TESTFN, 'U', encoding=self.encoding)
with reader:
self.assertEqual(reader.read(), s1)
class UTF16LETest(ReadTest, unittest.TestCase):
encoding = "utf-16-le"
ill_formed_sequence = b"\x80\xdc"
def test_partial(self):
self.check_partial(
"\x00\xff\u0100\uffff\U00010000",
[
"",
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff\U00010000",
]
)
def test_errors(self):
tests = [
(b'\xff', '\ufffd'),
(b'A\x00Z', 'A\ufffd'),
(b'A\x00B\x00C\x00D\x00Z', 'ABCD\ufffd'),
(b'\x00\xd8', '\ufffd'),
(b'\x00\xd8A', '\ufffd'),
(b'\x00\xd8A\x00', '\ufffdA'),
(b'\x00\xdcA\x00', '\ufffdA'),
]
for raw, expected in tests:
self.assertRaises(UnicodeDecodeError, codecs.utf_16_le_decode,
raw, 'strict', True)
self.assertEqual(raw.decode('utf-16le', 'replace'), expected)
def test_nonbmp(self):
self.assertEqual("\U00010203".encode(self.encoding),
b'\x00\xd8\x03\xde')
self.assertEqual(b'\x00\xd8\x03\xde'.decode(self.encoding),
"\U00010203")
class UTF16BETest(ReadTest, unittest.TestCase):
encoding = "utf-16-be"
ill_formed_sequence = b"\xdc\x80"
def test_partial(self):
self.check_partial(
"\x00\xff\u0100\uffff\U00010000",
[
"",
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff\u0100",
"\x00\xff\u0100",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff",
"\x00\xff\u0100\uffff\U00010000",
]
)
def test_errors(self):
tests = [
(b'\xff', '\ufffd'),
(b'\x00A\xff', 'A\ufffd'),
(b'\x00A\x00B\x00C\x00DZ', 'ABCD\ufffd'),
(b'\xd8\x00', '\ufffd'),
(b'\xd8\x00\xdc', '\ufffd'),
(b'\xd8\x00\x00A', '\ufffdA'),
(b'\xdc\x00\x00A', '\ufffdA'),
]
for raw, expected in tests:
self.assertRaises(UnicodeDecodeError, codecs.utf_16_be_decode,
raw, 'strict', True)
self.assertEqual(raw.decode('utf-16be', 'replace'), expected)
def test_nonbmp(self):
self.assertEqual("\U00010203".encode(self.encoding),
b'\xd8\x00\xde\x03')
self.assertEqual(b'\xd8\x00\xde\x03'.decode(self.encoding),
"\U00010203")
class UTF8Test(ReadTest, unittest.TestCase):
encoding = "utf-8"
ill_formed_sequence = b"\xed\xb2\x80"
ill_formed_sequence_replace = "\ufffd" * 3
def test_partial(self):
self.check_partial(
"\x00\xff\u07ff\u0800\uffff\U00010000",
[
"\x00",
"\x00",
"\x00\xff",
"\x00\xff",
"\x00\xff\u07ff",
"\x00\xff\u07ff",
"\x00\xff\u07ff",
"\x00\xff\u07ff\u0800",
"\x00\xff\u07ff\u0800",
"\x00\xff\u07ff\u0800",
"\x00\xff\u07ff\u0800\uffff",
"\x00\xff\u07ff\u0800\uffff",
"\x00\xff\u07ff\u0800\uffff",
"\x00\xff\u07ff\u0800\uffff",
"\x00\xff\u07ff\u0800\uffff\U00010000",
]
)
def test_decoder_state(self):
u = "\x00\x7f\x80\xff\u0100\u07ff\u0800\uffff\U0010ffff"
self.check_state_handling_decode(self.encoding,
u, u.encode(self.encoding))
def test_lone_surrogates(self):
super().test_lone_surrogates()
# not sure if this is making sense for
# UTF-16 and UTF-32
self.assertEqual("[\uDC80]".encode('utf-8', "surrogateescape"),
b'[\x80]')
def test_surrogatepass_handler(self):
self.assertEqual("abc\ud800def".encode("utf-8", "surrogatepass"),
b"abc\xed\xa0\x80def")
self.assertEqual(b"abc\xed\xa0\x80def".decode("utf-8", "surrogatepass"),
"abc\ud800def")
self.assertEqual("\U00010fff\uD800".encode("utf-8", "surrogatepass"),
b"\xf0\x90\xbf\xbf\xed\xa0\x80")
self.assertEqual(b"\xf0\x90\xbf\xbf\xed\xa0\x80".decode("utf-8", "surrogatepass"),
"\U00010fff\uD800")
self.assertTrue(codecs.lookup_error("surrogatepass"))
with self.assertRaises(UnicodeDecodeError):
b"abc\xed\xa0".decode("utf-8", "surrogatepass")
with self.assertRaises(UnicodeDecodeError):
b"abc\xed\xa0z".decode("utf-8", "surrogatepass")
@unittest.skipUnless(sys.platform == 'win32',
'cp65001 is a Windows-only codec')
class CP65001Test(ReadTest, unittest.TestCase):
encoding = "cp65001"
def test_encode(self):
tests = [
('abc', 'strict', b'abc'),
('\xe9\u20ac', 'strict', b'\xc3\xa9\xe2\x82\xac'),
('\U0010ffff', 'strict', b'\xf4\x8f\xbf\xbf'),
]
if VISTA_OR_LATER:
tests.extend((
('\udc80', 'strict', None),
('\udc80', 'ignore', b''),
('\udc80', 'replace', b'?'),
('\udc80', 'backslashreplace', b'\\udc80'),
('\udc80', 'surrogatepass', b'\xed\xb2\x80'),
))
else:
tests.append(('\udc80', 'strict', b'\xed\xb2\x80'))
for text, errors, expected in tests:
if expected is not None:
try:
encoded = text.encode('cp65001', errors)
except UnicodeEncodeError as err:
self.fail('Unable to encode %a to cp65001 with '
'errors=%r: %s' % (text, errors, err))
self.assertEqual(encoded, expected,
'%a.encode("cp65001", %r)=%a != %a'
% (text, errors, encoded, expected))
else:
self.assertRaises(UnicodeEncodeError,
text.encode, "cp65001", errors)
def test_decode(self):
tests = [
(b'abc', 'strict', 'abc'),
(b'\xc3\xa9\xe2\x82\xac', 'strict', '\xe9\u20ac'),
(b'\xf4\x8f\xbf\xbf', 'strict', '\U0010ffff'),
(b'\xef\xbf\xbd', 'strict', '\ufffd'),
(b'[\xc3\xa9]', 'strict', '[\xe9]'),
# invalid bytes
(b'[\xff]', 'strict', None),
(b'[\xff]', 'ignore', '[]'),
(b'[\xff]', 'replace', '[\ufffd]'),
(b'[\xff]', 'surrogateescape', '[\udcff]'),
]
if VISTA_OR_LATER:
tests.extend((
(b'[\xed\xb2\x80]', 'strict', None),
(b'[\xed\xb2\x80]', 'ignore', '[]'),
(b'[\xed\xb2\x80]', 'replace', '[\ufffd\ufffd\ufffd]'),
))
else:
tests.extend((
(b'[\xed\xb2\x80]', 'strict', '[\udc80]'),
))
for raw, errors, expected in tests:
if expected is not None:
try:
decoded = raw.decode('cp65001', errors)
except UnicodeDecodeError as err:
self.fail('Unable to decode %a from cp65001 with '
'errors=%r: %s' % (raw, errors, err))
self.assertEqual(decoded, expected,
'%a.decode("cp65001", %r)=%a != %a'
% (raw, errors, decoded, expected))
else:
self.assertRaises(UnicodeDecodeError,
raw.decode, 'cp65001', errors)
@unittest.skipUnless(VISTA_OR_LATER, 'require Windows Vista or later')
def test_lone_surrogates(self):
self.assertRaises(UnicodeEncodeError, "\ud800".encode, "cp65001")
self.assertRaises(UnicodeDecodeError, b"\xed\xa0\x80".decode, "cp65001")
self.assertEqual("[\uDC80]".encode("cp65001", "backslashreplace"),
b'[\\udc80]')
self.assertEqual("[\uDC80]".encode("cp65001", "xmlcharrefreplace"),
b'[�]')
self.assertEqual("[\uDC80]".encode("cp65001", "surrogateescape"),
b'[\x80]')
self.assertEqual("[\uDC80]".encode("cp65001", "ignore"),
b'[]')
self.assertEqual("[\uDC80]".encode("cp65001", "replace"),
b'[?]')
@unittest.skipUnless(VISTA_OR_LATER, 'require Windows Vista or later')
def test_surrogatepass_handler(self):
self.assertEqual("abc\ud800def".encode("cp65001", "surrogatepass"),
b"abc\xed\xa0\x80def")
self.assertEqual(b"abc\xed\xa0\x80def".decode("cp65001", "surrogatepass"),
"abc\ud800def")
self.assertEqual("\U00010fff\uD800".encode("cp65001", "surrogatepass"),
b"\xf0\x90\xbf\xbf\xed\xa0\x80")
self.assertEqual(b"\xf0\x90\xbf\xbf\xed\xa0\x80".decode("cp65001", "surrogatepass"),
"\U00010fff\uD800")
self.assertTrue(codecs.lookup_error("surrogatepass"))
def test_readline(self):
self.skipTest("issue #20571: code page 65001 codec does not "
"support partial decoder yet")
class UTF7Test(ReadTest, unittest.TestCase):
encoding = "utf-7"
def test_partial(self):
self.check_partial(
'a+-b\x00c\x80d\u0100e\U00010000f',
[
'a',
'a',
'a+',
'a+-',
'a+-b',
'a+-b',
'a+-b',
'a+-b',
'a+-b',
'a+-b\x00',
'a+-b\x00c',
'a+-b\x00c',
'a+-b\x00c',
'a+-b\x00c',
'a+-b\x00c',
'a+-b\x00c\x80',
'a+-b\x00c\x80d',
'a+-b\x00c\x80d',
'a+-b\x00c\x80d',
'a+-b\x00c\x80d',
'a+-b\x00c\x80d',
'a+-b\x00c\x80d\u0100',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e',
'a+-b\x00c\x80d\u0100e\U00010000',
'a+-b\x00c\x80d\u0100e\U00010000f',
]
)
def test_errors(self):
tests = [
(b'a\xffb', 'a\ufffdb'),
(b'a+IK', 'a\ufffd'),
(b'a+IK-b', 'a\ufffdb'),
(b'a+IK,b', 'a\ufffdb'),
(b'a+IKx', 'a\u20ac\ufffd'),
(b'a+IKx-b', 'a\u20ac\ufffdb'),
(b'a+IKwgr', 'a\u20ac\ufffd'),
(b'a+IKwgr-b', 'a\u20ac\ufffdb'),
(b'a+IKwgr,', 'a\u20ac\ufffd'),
(b'a+IKwgr,-b', 'a\u20ac\ufffd-b'),
(b'a+IKwgrB', 'a\u20ac\u20ac\ufffd'),
(b'a+IKwgrB-b', 'a\u20ac\u20ac\ufffdb'),
(b'a+/,+IKw-b', 'a\ufffd\u20acb'),
(b'a+//,+IKw-b', 'a\ufffd\u20acb'),
(b'a+///,+IKw-b', 'a\uffff\ufffd\u20acb'),
(b'a+////,+IKw-b', 'a\uffff\ufffd\u20acb'),
]
for raw, expected in tests:
with self.subTest(raw=raw):
self.assertRaises(UnicodeDecodeError, codecs.utf_7_decode,
raw, 'strict', True)
self.assertEqual(raw.decode('utf-7', 'replace'), expected)
def test_nonbmp(self):
self.assertEqual('\U000104A0'.encode(self.encoding), b'+2AHcoA-')
self.assertEqual('\ud801\udca0'.encode(self.encoding), b'+2AHcoA-')
self.assertEqual(b'+2AHcoA-'.decode(self.encoding), '\U000104A0')
test_lone_surrogates = None
class UTF16ExTest(unittest.TestCase):
def test_errors(self):
self.assertRaises(UnicodeDecodeError, codecs.utf_16_ex_decode, b"\xff", "strict", 0, True)
def test_bad_args(self):
self.assertRaises(TypeError, codecs.utf_16_ex_decode)
class ReadBufferTest(unittest.TestCase):
def test_array(self):
import array
self.assertEqual(
codecs.readbuffer_encode(array.array("b", b"spam")),
(b"spam", 4)
)
def test_empty(self):
self.assertEqual(codecs.readbuffer_encode(""), (b"", 0))
def test_bad_args(self):
self.assertRaises(TypeError, codecs.readbuffer_encode)
self.assertRaises(TypeError, codecs.readbuffer_encode, 42)
class UTF8SigTest(UTF8Test, unittest.TestCase):
encoding = "utf-8-sig"
def test_partial(self):
self.check_partial(
"\ufeff\x00\xff\u07ff\u0800\uffff\U00010000",
[
"",
"",
"", # First BOM has been read and skipped
"",
"",
"\ufeff", # Second BOM has been read and emitted
"\ufeff\x00", # "\x00" read and emitted
"\ufeff\x00", # First byte of encoded "\xff" read
"\ufeff\x00\xff", # Second byte of encoded "\xff" read
"\ufeff\x00\xff", # First byte of encoded "\u07ff" read
"\ufeff\x00\xff\u07ff", # Second byte of encoded "\u07ff" read
"\ufeff\x00\xff\u07ff",
"\ufeff\x00\xff\u07ff",
"\ufeff\x00\xff\u07ff\u0800",
"\ufeff\x00\xff\u07ff\u0800",
"\ufeff\x00\xff\u07ff\u0800",
"\ufeff\x00\xff\u07ff\u0800\uffff",
"\ufeff\x00\xff\u07ff\u0800\uffff",
"\ufeff\x00\xff\u07ff\u0800\uffff",
"\ufeff\x00\xff\u07ff\u0800\uffff",
"\ufeff\x00\xff\u07ff\u0800\uffff\U00010000",
]
)
def test_bug1601501(self):
# SF bug #1601501: check that the codec works with a buffer
self.assertEqual(str(b"\xef\xbb\xbf", "utf-8-sig"), "")
def test_bom(self):
d = codecs.getincrementaldecoder("utf-8-sig")()
s = "spam"
self.assertEqual(d.decode(s.encode("utf-8-sig")), s)
def test_stream_bom(self):
unistring = "ABC\u00A1\u2200XYZ"
bytestring = codecs.BOM_UTF8 + b"ABC\xC2\xA1\xE2\x88\x80XYZ"
reader = codecs.getreader("utf-8-sig")
for sizehint in [None] + list(range(1, 11)) + \
[64, 128, 256, 512, 1024]:
istream = reader(io.BytesIO(bytestring))
ostream = io.StringIO()
while 1:
if sizehint is not None:
data = istream.read(sizehint)
else:
data = istream.read()
if not data:
break
ostream.write(data)
got = ostream.getvalue()
self.assertEqual(got, unistring)
def test_stream_bare(self):
unistring = "ABC\u00A1\u2200XYZ"
bytestring = b"ABC\xC2\xA1\xE2\x88\x80XYZ"
reader = codecs.getreader("utf-8-sig")
for sizehint in [None] + list(range(1, 11)) + \
[64, 128, 256, 512, 1024]:
istream = reader(io.BytesIO(bytestring))
ostream = io.StringIO()
while 1:
if sizehint is not None:
data = istream.read(sizehint)
else:
data = istream.read()
if not data:
break
ostream.write(data)
got = ostream.getvalue()
self.assertEqual(got, unistring)
class EscapeDecodeTest(unittest.TestCase):
def test_empty(self):
self.assertEqual(codecs.escape_decode(b""), (b"", 0))
def test_raw(self):
decode = codecs.escape_decode
for b in range(256):
b = bytes([b])
if b != b'\\':
self.assertEqual(decode(b + b'0'), (b + b'0', 2))
def test_escape(self):
decode = codecs.escape_decode
check = coding_checker(self, decode)
check(b"[\\\n]", b"[]")
check(br'[\"]', b'["]')
check(br"[\']", b"[']")
check(br"[\\]", br"[\]")
check(br"[\a]", b"[\x07]")
check(br"[\b]", b"[\x08]")
check(br"[\t]", b"[\x09]")
check(br"[\n]", b"[\x0a]")
check(br"[\v]", b"[\x0b]")
check(br"[\f]", b"[\x0c]")
check(br"[\r]", b"[\x0d]")
check(br"[\7]", b"[\x07]")
check(br"[\8]", br"[\8]")
check(br"[\78]", b"[\x078]")
check(br"[\41]", b"[!]")
check(br"[\418]", b"[!8]")
check(br"[\101]", b"[A]")
check(br"[\1010]", b"[A0]")
check(br"[\501]", b"[A]")
check(br"[\x41]", b"[A]")
check(br"[\X41]", br"[\X41]")
check(br"[\x410]", b"[A0]")
for b in range(256):
if b not in b'\n"\'\\abtnvfr01234567x':
b = bytes([b])
check(b'\\' + b, b'\\' + b)
def test_errors(self):
decode = codecs.escape_decode
self.assertRaises(ValueError, decode, br"\x")
self.assertRaises(ValueError, decode, br"[\x]")
self.assertEqual(decode(br"[\x]\x", "ignore"), (b"[]", 6))
self.assertEqual(decode(br"[\x]\x", "replace"), (b"[?]?", 6))
self.assertRaises(ValueError, decode, br"\x0")
self.assertRaises(ValueError, decode, br"[\x0]")
self.assertEqual(decode(br"[\x0]\x0", "ignore"), (b"[]", 8))
self.assertEqual(decode(br"[\x0]\x0", "replace"), (b"[?]?", 8))
class RecodingTest(unittest.TestCase):
def test_recoding(self):
f = io.BytesIO()
f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
f2.write("a")
f2.close()
# Python used to crash on this at exit because of a refcount
# bug in _codecsmodule.c
# From RFC 3492
punycode_testcases = [
# A Arabic (Egyptian):
("\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644"
"\u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F",
b"egbpdaj6bu4bxfgehfvwxn"),
# B Chinese (simplified):
("\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587",
b"ihqwcrb4cv8a8dqg056pqjye"),
# C Chinese (traditional):
("\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587",
b"ihqwctvzc91f659drss3x8bo0yb"),
# D Czech: Pro<ccaron>prost<ecaron>nemluv<iacute><ccaron>esky
("\u0050\u0072\u006F\u010D\u0070\u0072\u006F\u0073\u0074"
"\u011B\u006E\u0065\u006D\u006C\u0075\u0076\u00ED\u010D"
"\u0065\u0073\u006B\u0079",
b"Proprostnemluvesky-uyb24dma41a"),
# E Hebrew:
("\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8"
"\u05DC\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2"
"\u05D1\u05E8\u05D9\u05EA",
b"4dbcagdahymbxekheh6e0a7fei0b"),
# F Hindi (Devanagari):
("\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D"
"\u0926\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939"
"\u0940\u0902\u092C\u094B\u0932\u0938\u0915\u0924\u0947"
"\u0939\u0948\u0902",
b"i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd"),
#(G) Japanese (kanji and hiragana):
("\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092"
"\u8A71\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B",
b"n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa"),
# (H) Korean (Hangul syllables):
("\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774"
"\uD55C\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74"
"\uC5BC\uB9C8\uB098\uC88B\uC744\uAE4C",
b"989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5j"
b"psd879ccm6fea98c"),
# (I) Russian (Cyrillic):
("\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E"
"\u043D\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440"
"\u044F\u0442\u043F\u043E\u0440\u0443\u0441\u0441\u043A"
"\u0438",
b"b1abfaaepdrnnbgefbaDotcwatmq2g4l"),
# (J) Spanish: Porqu<eacute>nopuedensimplementehablarenEspa<ntilde>ol
("\u0050\u006F\u0072\u0071\u0075\u00E9\u006E\u006F\u0070"
"\u0075\u0065\u0064\u0065\u006E\u0073\u0069\u006D\u0070"
"\u006C\u0065\u006D\u0065\u006E\u0074\u0065\u0068\u0061"
"\u0062\u006C\u0061\u0072\u0065\u006E\u0045\u0073\u0070"
"\u0061\u00F1\u006F\u006C",
b"PorqunopuedensimplementehablarenEspaol-fmd56a"),
# (K) Vietnamese:
# T<adotbelow>isaoh<odotbelow>kh<ocirc>ngth<ecirchookabove>ch\
# <ihookabove>n<oacute>iti<ecircacute>ngVi<ecircdotbelow>t
("\u0054\u1EA1\u0069\u0073\u0061\u006F\u0068\u1ECD\u006B"
"\u0068\u00F4\u006E\u0067\u0074\u0068\u1EC3\u0063\u0068"
"\u1EC9\u006E\u00F3\u0069\u0074\u0069\u1EBF\u006E\u0067"
"\u0056\u0069\u1EC7\u0074",
b"TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g"),
#(L) 3<nen>B<gumi><kinpachi><sensei>
("\u0033\u5E74\u0042\u7D44\u91D1\u516B\u5148\u751F",
b"3B-ww4c5e180e575a65lsy2b"),
# (M) <amuro><namie>-with-SUPER-MONKEYS
("\u5B89\u5BA4\u5948\u7F8E\u6075\u002D\u0077\u0069\u0074"
"\u0068\u002D\u0053\u0055\u0050\u0045\u0052\u002D\u004D"
"\u004F\u004E\u004B\u0045\u0059\u0053",
b"-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n"),
# (N) Hello-Another-Way-<sorezore><no><basho>
("\u0048\u0065\u006C\u006C\u006F\u002D\u0041\u006E\u006F"
"\u0074\u0068\u0065\u0072\u002D\u0057\u0061\u0079\u002D"
"\u305D\u308C\u305E\u308C\u306E\u5834\u6240",
b"Hello-Another-Way--fc4qua05auwb3674vfr0b"),
# (O) <hitotsu><yane><no><shita>2
("\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B\u0032",
b"2-u9tlzr9756bt3uc0v"),
# (P) Maji<de>Koi<suru>5<byou><mae>
("\u004D\u0061\u006A\u0069\u3067\u004B\u006F\u0069\u3059"
"\u308B\u0035\u79D2\u524D",
b"MajiKoi5-783gue6qz075azm5e"),
# (Q) <pafii>de<runba>
("\u30D1\u30D5\u30A3\u30FC\u0064\u0065\u30EB\u30F3\u30D0",
b"de-jg4avhby1noc0d"),
# (R) <sono><supiido><de>
("\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067",
b"d9juau41awczczp"),
# (S) -> $1.00 <-
("\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020"
"\u003C\u002D",
b"-> $1.00 <--")
]
for i in punycode_testcases:
if len(i)!=2:
print(repr(i))
class PunycodeTest(unittest.TestCase):
def test_encode(self):
for uni, puny in punycode_testcases:
# Need to convert both strings to lower case, since
# some of the extended encodings use upper case, but our
# code produces only lower case. Converting just puny to
# lower is also insufficient, since some of the input characters
# are upper case.
self.assertEqual(
str(uni.encode("punycode"), "ascii").lower(),
str(puny, "ascii").lower()
)
def test_decode(self):
for uni, puny in punycode_testcases:
self.assertEqual(uni, puny.decode("punycode"))
puny = puny.decode("ascii").encode("ascii")
self.assertEqual(uni, puny.decode("punycode"))
class UnicodeInternalTest(unittest.TestCase):
@unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t')
def test_bug1251300(self):
# Decoding with unicode_internal used to not correctly handle "code
# points" above 0x10ffff on UCS-4 builds.
ok = [
(b"\x00\x10\xff\xff", "\U0010ffff"),
(b"\x00\x00\x01\x01", "\U00000101"),
(b"", ""),
]
not_ok = [
b"\x7f\xff\xff\xff",
b"\x80\x00\x00\x00",
b"\x81\x00\x00\x00",
b"\x00",
b"\x00\x00\x00\x00\x00",
]
for internal, uni in ok:
if sys.byteorder == "little":
internal = bytes(reversed(internal))
with support.check_warnings():
self.assertEqual(uni, internal.decode("unicode_internal"))
for internal in not_ok:
if sys.byteorder == "little":
internal = bytes(reversed(internal))
with support.check_warnings(('unicode_internal codec has been '
'deprecated', DeprecationWarning)):
self.assertRaises(UnicodeDecodeError, internal.decode,
"unicode_internal")
if sys.byteorder == "little":
invalid = b"\x00\x00\x11\x00"
else:
invalid = b"\x00\x11\x00\x00"
with support.check_warnings():
self.assertRaises(UnicodeDecodeError,
invalid.decode, "unicode_internal")
with support.check_warnings():
self.assertEqual(invalid.decode("unicode_internal", "replace"),
'\ufffd')
@unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t')
def test_decode_error_attributes(self):
try:
with support.check_warnings(('unicode_internal codec has been '
'deprecated', DeprecationWarning)):
b"\x00\x00\x00\x00\x00\x11\x11\x00".decode("unicode_internal")
except UnicodeDecodeError as ex:
self.assertEqual("unicode_internal", ex.encoding)
self.assertEqual(b"\x00\x00\x00\x00\x00\x11\x11\x00", ex.object)
self.assertEqual(4, ex.start)
self.assertEqual(8, ex.end)
else:
self.fail()
@unittest.skipUnless(SIZEOF_WCHAR_T == 4, 'specific to 32-bit wchar_t')
def test_decode_callback(self):
codecs.register_error("UnicodeInternalTest", codecs.ignore_errors)
decoder = codecs.getdecoder("unicode_internal")
with support.check_warnings(('unicode_internal codec has been '
'deprecated', DeprecationWarning)):
ab = "ab".encode("unicode_internal").decode()
ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]),
"ascii"),
"UnicodeInternalTest")
self.assertEqual(("ab", 12), ignored)
def test_encode_length(self):
with support.check_warnings(('unicode_internal codec has been '
'deprecated', DeprecationWarning)):
# Issue 3739
encoder = codecs.getencoder("unicode_internal")
self.assertEqual(encoder("a")[1], 1)
self.assertEqual(encoder("\xe9\u0142")[1], 2)
self.assertEqual(codecs.escape_encode(br'\x00')[1], 4)
# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
nameprep_tests = [
# 3.1 Map to nothing.
(b'foo\xc2\xad\xcd\x8f\xe1\xa0\x86\xe1\xa0\x8bbar'
b'\xe2\x80\x8b\xe2\x81\xa0baz\xef\xb8\x80\xef\xb8\x88\xef'
b'\xb8\x8f\xef\xbb\xbf',
b'foobarbaz'),
# 3.2 Case folding ASCII U+0043 U+0041 U+0046 U+0045.
(b'CAFE',
b'cafe'),
# 3.3 Case folding 8bit U+00DF (german sharp s).
# The original test case is bogus; it says \xc3\xdf
(b'\xc3\x9f',
b'ss'),
# 3.4 Case folding U+0130 (turkish capital I with dot).
(b'\xc4\xb0',
b'i\xcc\x87'),
# 3.5 Case folding multibyte U+0143 U+037A.
(b'\xc5\x83\xcd\xba',
b'\xc5\x84 \xce\xb9'),
# 3.6 Case folding U+2121 U+33C6 U+1D7BB.
# XXX: skip this as it fails in UCS-2 mode
#('\xe2\x84\xa1\xe3\x8f\x86\xf0\x9d\x9e\xbb',
# 'telc\xe2\x88\x95kg\xcf\x83'),
(None, None),
# 3.7 Normalization of U+006a U+030c U+00A0 U+00AA.
(b'j\xcc\x8c\xc2\xa0\xc2\xaa',
b'\xc7\xb0 a'),
# 3.8 Case folding U+1FB7 and normalization.
(b'\xe1\xbe\xb7',
b'\xe1\xbe\xb6\xce\xb9'),
# 3.9 Self-reverting case folding U+01F0 and normalization.
# The original test case is bogus, it says `\xc7\xf0'
(b'\xc7\xb0',
b'\xc7\xb0'),
# 3.10 Self-reverting case folding U+0390 and normalization.
(b'\xce\x90',
b'\xce\x90'),
# 3.11 Self-reverting case folding U+03B0 and normalization.
(b'\xce\xb0',
b'\xce\xb0'),
# 3.12 Self-reverting case folding U+1E96 and normalization.
(b'\xe1\xba\x96',
b'\xe1\xba\x96'),
# 3.13 Self-reverting case folding U+1F56 and normalization.
(b'\xe1\xbd\x96',
b'\xe1\xbd\x96'),
# 3.14 ASCII space character U+0020.
(b' ',
b' '),
# 3.15 Non-ASCII 8bit space character U+00A0.
(b'\xc2\xa0',
b' '),
# 3.16 Non-ASCII multibyte space character U+1680.
(b'\xe1\x9a\x80',
None),
# 3.17 Non-ASCII multibyte space character U+2000.
(b'\xe2\x80\x80',
b' '),
# 3.18 Zero Width Space U+200b.
(b'\xe2\x80\x8b',
b''),
# 3.19 Non-ASCII multibyte space character U+3000.
(b'\xe3\x80\x80',
b' '),
# 3.20 ASCII control characters U+0010 U+007F.
(b'\x10\x7f',
b'\x10\x7f'),
# 3.21 Non-ASCII 8bit control character U+0085.
(b'\xc2\x85',
None),
# 3.22 Non-ASCII multibyte control character U+180E.
(b'\xe1\xa0\x8e',
None),
# 3.23 Zero Width No-Break Space U+FEFF.
(b'\xef\xbb\xbf',
b''),
# 3.24 Non-ASCII control character U+1D175.
(b'\xf0\x9d\x85\xb5',
None),
# 3.25 Plane 0 private use character U+F123.
(b'\xef\x84\xa3',
None),
# 3.26 Plane 15 private use character U+F1234.
(b'\xf3\xb1\x88\xb4',
None),
# 3.27 Plane 16 private use character U+10F234.
(b'\xf4\x8f\x88\xb4',
None),
# 3.28 Non-character code point U+8FFFE.
(b'\xf2\x8f\xbf\xbe',
None),
# 3.29 Non-character code point U+10FFFF.
(b'\xf4\x8f\xbf\xbf',
None),
# 3.30 Surrogate code U+DF42.
(b'\xed\xbd\x82',
None),
# 3.31 Non-plain text character U+FFFD.
(b'\xef\xbf\xbd',
None),
# 3.32 Ideographic description character U+2FF5.
(b'\xe2\xbf\xb5',
None),
# 3.33 Display property character U+0341.
(b'\xcd\x81',
b'\xcc\x81'),
# 3.34 Left-to-right mark U+200E.
(b'\xe2\x80\x8e',
None),
# 3.35 Deprecated U+202A.
(b'\xe2\x80\xaa',
None),
# 3.36 Language tagging character U+E0001.
(b'\xf3\xa0\x80\x81',
None),
# 3.37 Language tagging character U+E0042.
(b'\xf3\xa0\x81\x82',
None),
# 3.38 Bidi: RandALCat character U+05BE and LCat characters.
(b'foo\xd6\xbebar',
None),
# 3.39 Bidi: RandALCat character U+FD50 and LCat characters.
(b'foo\xef\xb5\x90bar',
None),
# 3.40 Bidi: RandALCat character U+FB38 and LCat characters.
(b'foo\xef\xb9\xb6bar',
b'foo \xd9\x8ebar'),
# 3.41 Bidi: RandALCat without trailing RandALCat U+0627 U+0031.
(b'\xd8\xa71',
None),
# 3.42 Bidi: RandALCat character U+0627 U+0031 U+0628.
(b'\xd8\xa71\xd8\xa8',
b'\xd8\xa71\xd8\xa8'),
# 3.43 Unassigned code point U+E0002.
# Skip this test as we allow unassigned
#(b'\xf3\xa0\x80\x82',
# None),
(None, None),
# 3.44 Larger test (shrinking).
# Original test case reads \xc3\xdf
(b'X\xc2\xad\xc3\x9f\xc4\xb0\xe2\x84\xa1j\xcc\x8c\xc2\xa0\xc2'
b'\xaa\xce\xb0\xe2\x80\x80',
b'xssi\xcc\x87tel\xc7\xb0 a\xce\xb0 '),
# 3.45 Larger test (expanding).
# Original test case reads \xc3\x9f
(b'X\xc3\x9f\xe3\x8c\x96\xc4\xb0\xe2\x84\xa1\xe2\x92\x9f\xe3\x8c'
b'\x80',
b'xss\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3'
b'\x83\x88\xe3\x83\xabi\xcc\x87tel\x28d\x29\xe3\x82'
b'\xa2\xe3\x83\x91\xe3\x83\xbc\xe3\x83\x88')
]
class NameprepTest(unittest.TestCase):
def test_nameprep(self):
from encodings.idna import nameprep
for pos, (orig, prepped) in enumerate(nameprep_tests):
if orig is None:
# Skipped
continue
# The Unicode strings are given in UTF-8
orig = str(orig, "utf-8", "surrogatepass")
if prepped is None:
# Input contains prohibited characters
self.assertRaises(UnicodeError, nameprep, orig)
else:
prepped = str(prepped, "utf-8", "surrogatepass")
try:
self.assertEqual(nameprep(orig), prepped)
except Exception as e:
raise support.TestFailed("Test 3.%d: %s" % (pos+1, str(e)))
class IDNACodecTest(unittest.TestCase):
def test_builtin_decode(self):
self.assertEqual(str(b"python.org", "idna"), "python.org")
self.assertEqual(str(b"python.org.", "idna"), "python.org.")
self.assertEqual(str(b"xn--pythn-mua.org", "idna"), "pyth\xf6n.org")
self.assertEqual(str(b"xn--pythn-mua.org.", "idna"), "pyth\xf6n.org.")
def test_builtin_encode(self):
self.assertEqual("python.org".encode("idna"), b"python.org")
self.assertEqual("python.org.".encode("idna"), b"python.org.")
self.assertEqual("pyth\xf6n.org".encode("idna"), b"xn--pythn-mua.org")
self.assertEqual("pyth\xf6n.org.".encode("idna"), b"xn--pythn-mua.org.")
def test_stream(self):
r = codecs.getreader("idna")(io.BytesIO(b"abc"))
r.read(3)
self.assertEqual(r.read(), "")
def test_incremental_decode(self):
self.assertEqual(
"".join(codecs.iterdecode((bytes([c]) for c in b"python.org"), "idna")),
"python.org"
)
self.assertEqual(
"".join(codecs.iterdecode((bytes([c]) for c in b"python.org."), "idna")),
"python.org."
)
self.assertEqual(
"".join(codecs.iterdecode((bytes([c]) for c in b"xn--pythn-mua.org."), "idna")),
"pyth\xf6n.org."
)
self.assertEqual(
"".join(codecs.iterdecode((bytes([c]) for c in b"xn--pythn-mua.org."), "idna")),
"pyth\xf6n.org."
)
decoder = codecs.getincrementaldecoder("idna")()
self.assertEqual(decoder.decode(b"xn--xam", ), "")
self.assertEqual(decoder.decode(b"ple-9ta.o", ), "\xe4xample.")
self.assertEqual(decoder.decode(b"rg"), "")
self.assertEqual(decoder.decode(b"", True), "org")
decoder.reset()
self.assertEqual(decoder.decode(b"xn--xam", ), "")
self.assertEqual(decoder.decode(b"ple-9ta.o", ), "\xe4xample.")
self.assertEqual(decoder.decode(b"rg."), "org.")
self.assertEqual(decoder.decode(b"", True), "")
def test_incremental_encode(self):
self.assertEqual(
b"".join(codecs.iterencode("python.org", "idna")),
b"python.org"
)
self.assertEqual(
b"".join(codecs.iterencode("python.org.", "idna")),
b"python.org."
)
self.assertEqual(
b"".join(codecs.iterencode("pyth\xf6n.org.", "idna")),
b"xn--pythn-mua.org."
)
self.assertEqual(
b"".join(codecs.iterencode("pyth\xf6n.org.", "idna")),
b"xn--pythn-mua.org."
)
encoder = codecs.getincrementalencoder("idna")()
self.assertEqual(encoder.encode("\xe4x"), b"")
self.assertEqual(encoder.encode("ample.org"), b"xn--xample-9ta.")
self.assertEqual(encoder.encode("", True), b"org")
encoder.reset()
self.assertEqual(encoder.encode("\xe4x"), b"")
self.assertEqual(encoder.encode("ample.org."), b"xn--xample-9ta.org.")
self.assertEqual(encoder.encode("", True), b"")
class CodecsModuleTest(unittest.TestCase):
def test_decode(self):
self.assertEqual(codecs.decode(b'\xe4\xf6\xfc', 'latin-1'),
'\xe4\xf6\xfc')
self.assertRaises(TypeError, codecs.decode)
self.assertEqual(codecs.decode(b'abc'), 'abc')
self.assertRaises(UnicodeDecodeError, codecs.decode, b'\xff', 'ascii')
def test_encode(self):
self.assertEqual(codecs.encode('\xe4\xf6\xfc', 'latin-1'),
b'\xe4\xf6\xfc')
self.assertRaises(TypeError, codecs.encode)
self.assertRaises(LookupError, codecs.encode, "foo", "__spam__")
self.assertEqual(codecs.encode('abc'), b'abc')
self.assertRaises(UnicodeEncodeError, codecs.encode, '\xffff', 'ascii')
def test_register(self):
self.assertRaises(TypeError, codecs.register)
self.assertRaises(TypeError, codecs.register, 42)
def test_lookup(self):
self.assertRaises(TypeError, codecs.lookup)
self.assertRaises(LookupError, codecs.lookup, "__spam__")
self.assertRaises(LookupError, codecs.lookup, " ")
def test_getencoder(self):
self.assertRaises(TypeError, codecs.getencoder)
self.assertRaises(LookupError, codecs.getencoder, "__spam__")
def test_getdecoder(self):
self.assertRaises(TypeError, codecs.getdecoder)
self.assertRaises(LookupError, codecs.getdecoder, "__spam__")
def test_getreader(self):
self.assertRaises(TypeError, codecs.getreader)
self.assertRaises(LookupError, codecs.getreader, "__spam__")
def test_getwriter(self):
self.assertRaises(TypeError, codecs.getwriter)
self.assertRaises(LookupError, codecs.getwriter, "__spam__")
def test_lookup_issue1813(self):
# Issue #1813: under Turkish locales, lookup of some codecs failed
# because 'I' is lowercased as "ı" (dotless i)
oldlocale = locale.setlocale(locale.LC_CTYPE)
self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
try:
locale.setlocale(locale.LC_CTYPE, 'tr_TR')
except locale.Error:
# Unsupported locale on this system
self.skipTest('test needs Turkish locale')
c = codecs.lookup('ASCII')
self.assertEqual(c.name, 'ascii')
class StreamReaderTest(unittest.TestCase):
def setUp(self):
self.reader = codecs.getreader('utf-8')
self.stream = io.BytesIO(b'\xed\x95\x9c\n\xea\xb8\x80')
def test_readlines(self):
f = self.reader(self.stream)
self.assertEqual(f.readlines(), ['\ud55c\n', '\uae00'])
class EncodedFileTest(unittest.TestCase):
def test_basic(self):
f = io.BytesIO(b'\xed\x95\x9c\n\xea\xb8\x80')
ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8')
self.assertEqual(ef.read(), b'\\\xd5\n\x00\x00\xae')
f = io.BytesIO()
ef = codecs.EncodedFile(f, 'utf-8', 'latin-1')
ef.write(b'\xc3\xbc')
self.assertEqual(f.getvalue(), b'\xfc')
all_unicode_encodings = [
"ascii",
"big5",
"big5hkscs",
"charmap",
"cp037",
"cp1006",
"cp1026",
"cp1125",
"cp1140",
"cp1250",
"cp1251",
"cp1252",
"cp1253",
"cp1254",
"cp1255",
"cp1256",
"cp1257",
"cp1258",
"cp424",
"cp437",
"cp500",
"cp720",
"cp737",
"cp775",
"cp850",
"cp852",
"cp855",
"cp856",
"cp857",
"cp858",
"cp860",
"cp861",
"cp862",
"cp863",
"cp864",
"cp865",
"cp866",
"cp869",
"cp874",
"cp875",
"cp932",
"cp949",
"cp950",
"euc_jis_2004",
"euc_jisx0213",
"euc_jp",
"euc_kr",
"gb18030",
"gb2312",
"gbk",
"hp_roman8",
"hz",
"idna",
"iso2022_jp",
"iso2022_jp_1",
"iso2022_jp_2",
"iso2022_jp_2004",
"iso2022_jp_3",
"iso2022_jp_ext",
"iso2022_kr",
"iso8859_1",
"iso8859_10",
"iso8859_11",
"iso8859_13",
"iso8859_14",
"iso8859_15",
"iso8859_16",
"iso8859_2",
"iso8859_3",
"iso8859_4",
"iso8859_5",
"iso8859_6",
"iso8859_7",
"iso8859_8",
"iso8859_9",
"johab",
"koi8_r",
"koi8_u",
"latin_1",
"mac_cyrillic",
"mac_greek",
"mac_iceland",
"mac_latin2",
"mac_roman",
"mac_turkish",
"palmos",
"ptcp154",
"punycode",
"raw_unicode_escape",
"shift_jis",
"shift_jis_2004",
"shift_jisx0213",
"tis_620",
"unicode_escape",
"unicode_internal",
"utf_16",
"utf_16_be",
"utf_16_le",
"utf_7",
"utf_8",
]
if hasattr(codecs, "mbcs_encode"):
all_unicode_encodings.append("mbcs")
# The following encoding is not tested, because it's not supposed
# to work:
# "undefined"
# The following encodings don't work in stateful mode
broken_unicode_with_streams = [
"punycode",
"unicode_internal"
]
broken_incremental_coders = broken_unicode_with_streams + [
"idna",
]
class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
def test_basics(self):
s = "abc123" # all codecs should be able to encode these
for encoding in all_unicode_encodings:
name = codecs.lookup(encoding).name
if encoding.endswith("_codec"):
name += "_codec"
elif encoding == "latin_1":
name = "latin_1"
self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-"))
with support.check_warnings():
# unicode-internal has been deprecated
(b, size) = codecs.getencoder(encoding)(s)
self.assertEqual(size, len(s), "encoding=%r" % encoding)
(chars, size) = codecs.getdecoder(encoding)(b)
self.assertEqual(chars, s, "encoding=%r" % encoding)
if encoding not in broken_unicode_with_streams:
# check stream reader/writer
q = Queue(b"")
writer = codecs.getwriter(encoding)(q)
encodedresult = b""
for c in s:
writer.write(c)
chunk = q.read()
self.assertTrue(type(chunk) is bytes, type(chunk))
encodedresult += chunk
q = Queue(b"")
reader = codecs.getreader(encoding)(q)
decodedresult = ""
for c in encodedresult:
q.write(bytes([c]))
decodedresult += reader.read()
self.assertEqual(decodedresult, s, "encoding=%r" % encoding)
if encoding not in broken_incremental_coders:
# check incremental decoder/encoder and iterencode()/iterdecode()
try:
encoder = codecs.getincrementalencoder(encoding)()
except LookupError: # no IncrementalEncoder
pass
else:
# check incremental decoder/encoder
encodedresult = b""
for c in s:
encodedresult += encoder.encode(c)
encodedresult += encoder.encode("", True)
decoder = codecs.getincrementaldecoder(encoding)()
decodedresult = ""
for c in encodedresult:
decodedresult += decoder.decode(bytes([c]))
decodedresult += decoder.decode(b"", True)
self.assertEqual(decodedresult, s,
"encoding=%r" % encoding)
# check iterencode()/iterdecode()
result = "".join(codecs.iterdecode(
codecs.iterencode(s, encoding), encoding))
self.assertEqual(result, s, "encoding=%r" % encoding)
# check iterencode()/iterdecode() with empty string
result = "".join(codecs.iterdecode(
codecs.iterencode("", encoding), encoding))
self.assertEqual(result, "")
if encoding not in ("idna", "mbcs"):
# check incremental decoder/encoder with errors argument
try:
encoder = codecs.getincrementalencoder(encoding)("ignore")
except LookupError: # no IncrementalEncoder
pass
else:
encodedresult = b"".join(encoder.encode(c) for c in s)
decoder = codecs.getincrementaldecoder(encoding)("ignore")
decodedresult = "".join(decoder.decode(bytes([c]))
for c in encodedresult)
self.assertEqual(decodedresult, s,
"encoding=%r" % encoding)
@support.cpython_only
def test_basics_capi(self):
from _testcapi import codec_incrementalencoder, codec_incrementaldecoder
s = "abc123" # all codecs should be able to encode these
for encoding in all_unicode_encodings:
if encoding not in broken_incremental_coders:
# check incremental decoder/encoder (fetched via the C API)
try:
cencoder = codec_incrementalencoder(encoding)
except LookupError: # no IncrementalEncoder
pass
else:
# check C API
encodedresult = b""
for c in s:
encodedresult += cencoder.encode(c)
encodedresult += cencoder.encode("", True)
cdecoder = codec_incrementaldecoder(encoding)
decodedresult = ""
for c in encodedresult:
decodedresult += cdecoder.decode(bytes([c]))
decodedresult += cdecoder.decode(b"", True)
self.assertEqual(decodedresult, s,
"encoding=%r" % encoding)
if encoding not in ("idna", "mbcs"):
# check incremental decoder/encoder with errors argument
try:
cencoder = codec_incrementalencoder(encoding, "ignore")
except LookupError: # no IncrementalEncoder
pass
else:
encodedresult = b"".join(cencoder.encode(c) for c in s)
cdecoder = codec_incrementaldecoder(encoding, "ignore")
decodedresult = "".join(cdecoder.decode(bytes([c]))
for c in encodedresult)
self.assertEqual(decodedresult, s,
"encoding=%r" % encoding)
def test_seek(self):
# all codecs should be able to encode these
s = "%s\n%s\n" % (100*"abc123", 100*"def456")
for encoding in all_unicode_encodings:
if encoding == "idna": # FIXME: See SF bug #1163178
continue
if encoding in broken_unicode_with_streams:
continue
reader = codecs.getreader(encoding)(io.BytesIO(s.encode(encoding)))
for t in range(5):
# Test that calling seek resets the internal codec state and buffers
reader.seek(0, 0)
data = reader.read()
self.assertEqual(s, data)
def test_bad_decode_args(self):
for encoding in all_unicode_encodings:
decoder = codecs.getdecoder(encoding)
self.assertRaises(TypeError, decoder)
if encoding not in ("idna", "punycode"):
self.assertRaises(TypeError, decoder, 42)
def test_bad_encode_args(self):
for encoding in all_unicode_encodings:
encoder = codecs.getencoder(encoding)
with support.check_warnings():
# unicode-internal has been deprecated
self.assertRaises(TypeError, encoder)
def test_encoding_map_type_initialized(self):
from encodings import cp1140
# This used to crash, we are only verifying there's no crash.
table_type = type(cp1140.encoding_table)
self.assertEqual(table_type, table_type)
def test_decoder_state(self):
# Check that getstate() and setstate() handle the state properly
u = "abc123"
for encoding in all_unicode_encodings:
if encoding not in broken_incremental_coders:
self.check_state_handling_decode(encoding, u, u.encode(encoding))
self.check_state_handling_encode(encoding, u, u.encode(encoding))
class CharmapTest(unittest.TestCase):
def test_decode_with_string_map(self):
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict", "abc"),
("abc", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict", "\U0010FFFFbc"),
("\U0010FFFFbc", 3)
)
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict", "ab"
)
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict", "ab\ufffe"
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab"),
("ab\ufffd", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace", "ab\ufffe"),
("ab\ufffd", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore", "ab"),
("ab", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore", "ab\ufffe"),
("ab", 3)
)
allbytes = bytes(range(256))
self.assertEqual(
codecs.charmap_decode(allbytes, "ignore", ""),
("", len(allbytes))
)
def test_decode_with_int2str_map(self):
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: 'a', 1: 'b', 2: 'c'}),
("abc", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: 'Aa', 1: 'Bb', 2: 'Cc'}),
("AaBbCc", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: '\U0010FFFF', 1: 'b', 2: 'c'}),
("\U0010FFFFbc", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: 'a', 1: 'b', 2: ''}),
("ab", 3)
)
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict",
{0: 'a', 1: 'b'}
)
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict",
{0: 'a', 1: 'b', 2: None}
)
# Issue #14850
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict",
{0: 'a', 1: 'b', 2: '\ufffe'}
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: 'a', 1: 'b'}),
("ab\ufffd", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: 'a', 1: 'b', 2: None}),
("ab\ufffd", 3)
)
# Issue #14850
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: 'a', 1: 'b', 2: '\ufffe'}),
("ab\ufffd", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: 'a', 1: 'b'}),
("ab", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: 'a', 1: 'b', 2: None}),
("ab", 3)
)
# Issue #14850
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: 'a', 1: 'b', 2: '\ufffe'}),
("ab", 3)
)
allbytes = bytes(range(256))
self.assertEqual(
codecs.charmap_decode(allbytes, "ignore", {}),
("", len(allbytes))
)
def test_decode_with_int2int_map(self):
a = ord('a')
b = ord('b')
c = ord('c')
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: a, 1: b, 2: c}),
("abc", 3)
)
# Issue #15379
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: 0x10FFFF, 1: b, 2: c}),
("\U0010FFFFbc", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "strict",
{0: sys.maxunicode, 1: b, 2: c}),
(chr(sys.maxunicode) + "bc", 3)
)
self.assertRaises(TypeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict",
{0: sys.maxunicode + 1, 1: b, 2: c}
)
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict",
{0: a, 1: b},
)
self.assertRaises(UnicodeDecodeError,
codecs.charmap_decode, b"\x00\x01\x02", "strict",
{0: a, 1: b, 2: 0xFFFE},
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: a, 1: b}),
("ab\ufffd", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "replace",
{0: a, 1: b, 2: 0xFFFE}),
("ab\ufffd", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: a, 1: b}),
("ab", 3)
)
self.assertEqual(
codecs.charmap_decode(b"\x00\x01\x02", "ignore",
{0: a, 1: b, 2: 0xFFFE}),
("ab", 3)
)
class WithStmtTest(unittest.TestCase):
def test_encodedfile(self):
f = io.BytesIO(b"\xc3\xbc")
with codecs.EncodedFile(f, "latin-1", "utf-8") as ef:
self.assertEqual(ef.read(), b"\xfc")
def test_streamreaderwriter(self):
f = io.BytesIO(b"\xc3\xbc")
info = codecs.lookup("utf-8")
with codecs.StreamReaderWriter(f, info.streamreader,
info.streamwriter, 'strict') as srw:
self.assertEqual(srw.read(), "\xfc")
class TypesTest(unittest.TestCase):
def test_decode_unicode(self):
# Most decoders don't accept unicode input
decoders = [
codecs.utf_7_decode,
codecs.utf_8_decode,
codecs.utf_16_le_decode,
codecs.utf_16_be_decode,
codecs.utf_16_ex_decode,
codecs.utf_32_decode,
codecs.utf_32_le_decode,
codecs.utf_32_be_decode,
codecs.utf_32_ex_decode,
codecs.latin_1_decode,
codecs.ascii_decode,
codecs.charmap_decode,
]
if hasattr(codecs, "mbcs_decode"):
decoders.append(codecs.mbcs_decode)
for decoder in decoders:
self.assertRaises(TypeError, decoder, "xxx")
def test_unicode_escape(self):
# Escape-decoding an unicode string is supported ang gives the same
# result as decoding the equivalent ASCII bytes string.
self.assertEqual(codecs.unicode_escape_decode(r"\u1234"), ("\u1234", 6))
self.assertEqual(codecs.unicode_escape_decode(br"\u1234"), ("\u1234", 6))
self.assertEqual(codecs.raw_unicode_escape_decode(r"\u1234"), ("\u1234", 6))
self.assertEqual(codecs.raw_unicode_escape_decode(br"\u1234"), ("\u1234", 6))
self.assertRaises(UnicodeDecodeError, codecs.unicode_escape_decode, br"\U00110000")
self.assertEqual(codecs.unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
self.assertRaises(UnicodeDecodeError, codecs.raw_unicode_escape_decode, br"\U00110000")
self.assertEqual(codecs.raw_unicode_escape_decode(r"\U00110000", "replace"), ("\ufffd", 10))
class UnicodeEscapeTest(unittest.TestCase):
def test_empty(self):
self.assertEqual(codecs.unicode_escape_encode(""), (b"", 0))
self.assertEqual(codecs.unicode_escape_decode(b""), ("", 0))
def test_raw_encode(self):
encode = codecs.unicode_escape_encode
for b in range(32, 127):
if b != b'\\'[0]:
self.assertEqual(encode(chr(b)), (bytes([b]), 1))
def test_raw_decode(self):
decode = codecs.unicode_escape_decode
for b in range(256):
if b != b'\\'[0]:
self.assertEqual(decode(bytes([b]) + b'0'), (chr(b) + '0', 2))
def test_escape_encode(self):
encode = codecs.unicode_escape_encode
check = coding_checker(self, encode)
check('\t', br'\t')
check('\n', br'\n')
check('\r', br'\r')
check('\\', br'\\')
for b in range(32):
if chr(b) not in '\t\n\r':
check(chr(b), ('\\x%02x' % b).encode())
for b in range(127, 256):
check(chr(b), ('\\x%02x' % b).encode())
check('\u20ac', br'\u20ac')
check('\U0001d120', br'\U0001d120')
def test_escape_decode(self):
decode = codecs.unicode_escape_decode
check = coding_checker(self, decode)
check(b"[\\\n]", "[]")
check(br'[\"]', '["]')
check(br"[\']", "[']")
check(br"[\\]", r"[\]")
check(br"[\a]", "[\x07]")
check(br"[\b]", "[\x08]")
check(br"[\t]", "[\x09]")
check(br"[\n]", "[\x0a]")
check(br"[\v]", "[\x0b]")
check(br"[\f]", "[\x0c]")
check(br"[\r]", "[\x0d]")
check(br"[\7]", "[\x07]")
check(br"[\8]", r"[\8]")
check(br"[\78]", "[\x078]")
check(br"[\41]", "[!]")
check(br"[\418]", "[!8]")
check(br"[\101]", "[A]")
check(br"[\1010]", "[A0]")
check(br"[\x41]", "[A]")
check(br"[\x410]", "[A0]")
check(br"\u20ac", "\u20ac")
check(br"\U0001d120", "\U0001d120")
for b in range(256):
if b not in b'\n"\'\\abtnvfr01234567xuUN':
check(b'\\' + bytes([b]), '\\' + chr(b))
def test_decode_errors(self):
decode = codecs.unicode_escape_decode
for c, d in (b'x', 2), (b'u', 4), (b'U', 4):
for i in range(d):
self.assertRaises(UnicodeDecodeError, decode,
b"\\" + c + b"0"*i)
self.assertRaises(UnicodeDecodeError, decode,
b"[\\" + c + b"0"*i + b"]")
data = b"[\\" + c + b"0"*i + b"]\\" + c + b"0"*i
self.assertEqual(decode(data, "ignore"), ("[]", len(data)))
self.assertEqual(decode(data, "replace"),
("[\ufffd]\ufffd", len(data)))
self.assertRaises(UnicodeDecodeError, decode, br"\U00110000")
self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10))
self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10))
class RawUnicodeEscapeTest(unittest.TestCase):
def test_empty(self):
self.assertEqual(codecs.raw_unicode_escape_encode(""), (b"", 0))
self.assertEqual(codecs.raw_unicode_escape_decode(b""), ("", 0))
def test_raw_encode(self):
encode = codecs.raw_unicode_escape_encode
for b in range(256):
self.assertEqual(encode(chr(b)), (bytes([b]), 1))
def test_raw_decode(self):
decode = codecs.raw_unicode_escape_decode
for b in range(256):
self.assertEqual(decode(bytes([b]) + b'0'), (chr(b) + '0', 2))
def test_escape_encode(self):
encode = codecs.raw_unicode_escape_encode
check = coding_checker(self, encode)
for b in range(256):
if b not in b'uU':
check('\\' + chr(b), b'\\' + bytes([b]))
check('\u20ac', br'\u20ac')
check('\U0001d120', br'\U0001d120')
def test_escape_decode(self):
decode = codecs.raw_unicode_escape_decode
check = coding_checker(self, decode)
for b in range(256):
if b not in b'uU':
check(b'\\' + bytes([b]), '\\' + chr(b))
check(br"\u20ac", "\u20ac")
check(br"\U0001d120", "\U0001d120")
def test_decode_errors(self):
decode = codecs.raw_unicode_escape_decode
for c, d in (b'u', 4), (b'U', 4):
for i in range(d):
self.assertRaises(UnicodeDecodeError, decode,
b"\\" + c + b"0"*i)
self.assertRaises(UnicodeDecodeError, decode,
b"[\\" + c + b"0"*i + b"]")
data = b"[\\" + c + b"0"*i + b"]\\" + c + b"0"*i
self.assertEqual(decode(data, "ignore"), ("[]", len(data)))
self.assertEqual(decode(data, "replace"),
("[\ufffd]\ufffd", len(data)))
self.assertRaises(UnicodeDecodeError, decode, br"\U00110000")
self.assertEqual(decode(br"\U00110000", "ignore"), ("", 10))
self.assertEqual(decode(br"\U00110000", "replace"), ("\ufffd", 10))
class SurrogateEscapeTest(unittest.TestCase):
def test_utf8(self):
# Bad byte
self.assertEqual(b"foo\x80bar".decode("utf-8", "surrogateescape"),
"foo\udc80bar")
self.assertEqual("foo\udc80bar".encode("utf-8", "surrogateescape"),
b"foo\x80bar")
# bad-utf-8 encoded surrogate
self.assertEqual(b"\xed\xb0\x80".decode("utf-8", "surrogateescape"),
"\udced\udcb0\udc80")
self.assertEqual("\udced\udcb0\udc80".encode("utf-8", "surrogateescape"),
b"\xed\xb0\x80")
def test_ascii(self):
# bad byte
self.assertEqual(b"foo\x80bar".decode("ascii", "surrogateescape"),
"foo\udc80bar")
self.assertEqual("foo\udc80bar".encode("ascii", "surrogateescape"),
b"foo\x80bar")
def test_charmap(self):
# bad byte: \xa5 is unmapped in iso-8859-3
self.assertEqual(b"foo\xa5bar".decode("iso-8859-3", "surrogateescape"),
"foo\udca5bar")
self.assertEqual("foo\udca5bar".encode("iso-8859-3", "surrogateescape"),
b"foo\xa5bar")
def test_latin1(self):
# Issue6373
self.assertEqual("\udce4\udceb\udcef\udcf6\udcfc".encode("latin-1", "surrogateescape"),
b"\xe4\xeb\xef\xf6\xfc")
class BomTest(unittest.TestCase):
def test_seek0(self):
data = "1234567890"
tests = ("utf-16",
"utf-16-le",
"utf-16-be",
"utf-32",
"utf-32-le",
"utf-32-be")
self.addCleanup(support.unlink, support.TESTFN)
for encoding in tests:
# Check if the BOM is written only once
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
f.write(data)
f.write(data)
f.seek(0)
self.assertEqual(f.read(), data * 2)
f.seek(0)
self.assertEqual(f.read(), data * 2)
# Check that the BOM is written after a seek(0)
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
f.write(data[0])
self.assertNotEqual(f.tell(), 0)
f.seek(0)
f.write(data)
f.seek(0)
self.assertEqual(f.read(), data)
# (StreamWriter) Check that the BOM is written after a seek(0)
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
f.writer.write(data[0])
self.assertNotEqual(f.writer.tell(), 0)
f.writer.seek(0)
f.writer.write(data)
f.seek(0)
self.assertEqual(f.read(), data)
# Check that the BOM is not written after a seek() at a position
# different than the start
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
f.write(data)
f.seek(f.tell())
f.write(data)
f.seek(0)
self.assertEqual(f.read(), data * 2)
# (StreamWriter) Check that the BOM is not written after a seek()
# at a position different than the start
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:
f.writer.write(data)
f.writer.seek(f.writer.tell())
f.writer.write(data)
f.seek(0)
self.assertEqual(f.read(), data * 2)
bytes_transform_encodings = [
"base64_codec",
"uu_codec",
"quopri_codec",
"hex_codec",
]
transform_aliases = {
"base64_codec": ["base64", "base_64"],
"uu_codec": ["uu"],
"quopri_codec": ["quopri", "quoted_printable", "quotedprintable"],
"hex_codec": ["hex"],
"rot_13": ["rot13"],
}
try:
import zlib
except ImportError:
zlib = None
else:
bytes_transform_encodings.append("zlib_codec")
transform_aliases["zlib_codec"] = ["zip", "zlib"]
try:
import bz2
except ImportError:
pass
else:
bytes_transform_encodings.append("bz2_codec")
transform_aliases["bz2_codec"] = ["bz2"]
class TransformCodecTest(unittest.TestCase):
def test_basics(self):
binput = bytes(range(256))
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
# generic codecs interface
(o, size) = codecs.getencoder(encoding)(binput)
self.assertEqual(size, len(binput))
(i, size) = codecs.getdecoder(encoding)(o)
self.assertEqual(size, len(o))
self.assertEqual(i, binput)
def test_read(self):
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
sin = codecs.encode(b"\x80", encoding)
reader = codecs.getreader(encoding)(io.BytesIO(sin))
sout = reader.read()
self.assertEqual(sout, b"\x80")
def test_readline(self):
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
sin = codecs.encode(b"\x80", encoding)
reader = codecs.getreader(encoding)(io.BytesIO(sin))
sout = reader.readline()
self.assertEqual(sout, b"\x80")
def test_buffer_api_usage(self):
# We check all the transform codecs accept memoryview input
# for encoding and decoding
# and also that they roundtrip correctly
original = b"12345\x80"
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
data = original
view = memoryview(data)
data = codecs.encode(data, encoding)
view_encoded = codecs.encode(view, encoding)
self.assertEqual(view_encoded, data)
view = memoryview(data)
data = codecs.decode(data, encoding)
self.assertEqual(data, original)
view_decoded = codecs.decode(view, encoding)
self.assertEqual(view_decoded, data)
def test_text_to_binary_blacklists_binary_transforms(self):
# Check binary -> binary codecs give a good error for str input
bad_input = "bad input type"
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
fmt = ( "{!r} is not a text encoding; "
"use codecs.encode\(\) to handle arbitrary codecs")
msg = fmt.format(encoding)
with self.assertRaisesRegex(LookupError, msg) as failure:
bad_input.encode(encoding)
self.assertIsNone(failure.exception.__cause__)
def test_text_to_binary_blacklists_text_transforms(self):
# Check str.encode gives a good error message for str -> str codecs
msg = (r"^'rot_13' is not a text encoding; "
"use codecs.encode\(\) to handle arbitrary codecs")
with self.assertRaisesRegex(LookupError, msg):
"just an example message".encode("rot_13")
def test_binary_to_text_blacklists_binary_transforms(self):
# Check bytes.decode and bytearray.decode give a good error
# message for binary -> binary codecs
data = b"encode first to ensure we meet any format restrictions"
for encoding in bytes_transform_encodings:
with self.subTest(encoding=encoding):
encoded_data = codecs.encode(data, encoding)
fmt = (r"{!r} is not a text encoding; "
"use codecs.decode\(\) to handle arbitrary codecs")
msg = fmt.format(encoding)
with self.assertRaisesRegex(LookupError, msg):
encoded_data.decode(encoding)
with self.assertRaisesRegex(LookupError, msg):
bytearray(encoded_data).decode(encoding)
def test_binary_to_text_blacklists_text_transforms(self):
# Check str -> str codec gives a good error for binary input
for bad_input in (b"immutable", bytearray(b"mutable")):
with self.subTest(bad_input=bad_input):
msg = (r"^'rot_13' is not a text encoding; "
"use codecs.decode\(\) to handle arbitrary codecs")
with self.assertRaisesRegex(LookupError, msg) as failure:
bad_input.decode("rot_13")
self.assertIsNone(failure.exception.__cause__)
@unittest.skipUnless(zlib, "Requires zlib support")
def test_custom_zlib_error_is_wrapped(self):
# Check zlib codec gives a good error for malformed input
msg = "^decoding with 'zlib_codec' codec failed"
with self.assertRaisesRegex(Exception, msg) as failure:
codecs.decode(b"hello", "zlib_codec")
self.assertIsInstance(failure.exception.__cause__,
type(failure.exception))
def test_custom_hex_error_is_wrapped(self):
# Check hex codec gives a good error for malformed input
msg = "^decoding with 'hex_codec' codec failed"
with self.assertRaisesRegex(Exception, msg) as failure:
codecs.decode(b"hello", "hex_codec")
self.assertIsInstance(failure.exception.__cause__,
type(failure.exception))
# Unfortunately, the bz2 module throws OSError, which the codec
# machinery currently can't wrap :(
# Ensure codec aliases from http://bugs.python.org/issue7475 work
def test_aliases(self):
for codec_name, aliases in transform_aliases.items():
expected_name = codecs.lookup(codec_name).name
for alias in aliases:
with self.subTest(alias=alias):
info = codecs.lookup(alias)
self.assertEqual(info.name, expected_name)
# The codec system tries to wrap exceptions in order to ensure the error
# mentions the operation being performed and the codec involved. We
# currently *only* want this to happen for relatively stateless
# exceptions, where the only significant information they contain is their
# type and a single str argument.
# Use a local codec registry to avoid appearing to leak objects when
# registering multiple seach functions
_TEST_CODECS = {}
def _get_test_codec(codec_name):
return _TEST_CODECS.get(codec_name)
codecs.register(_get_test_codec) # Returns None, not usable as a decorator
try:
# Issue #22166: Also need to clear the internal cache in CPython
from _codecs import _forget_codec
except ImportError:
def _forget_codec(codec_name):
pass
class ExceptionChainingTest(unittest.TestCase):
def setUp(self):
# There's no way to unregister a codec search function, so we just
# ensure we render this one fairly harmless after the test
# case finishes by using the test case repr as the codec name
# The codecs module normalizes codec names, although this doesn't
# appear to be formally documented...
# We also make sure we use a truly unique id for the custom codec
# to avoid issues with the codec cache when running these tests
# multiple times (e.g. when hunting for refleaks)
unique_id = repr(self) + str(id(self))
self.codec_name = encodings.normalize_encoding(unique_id).lower()
# We store the object to raise on the instance because of a bad
# interaction between the codec caching (which means we can't
# recreate the codec entry) and regrtest refleak hunting (which
# runs the same test instance multiple times). This means we
# need to ensure the codecs call back in to the instance to find
# out which exception to raise rather than binding them in a
# closure to an object that may change on the next run
self.obj_to_raise = RuntimeError
def tearDown(self):
_TEST_CODECS.pop(self.codec_name, None)
# Issue #22166: Also pop from caches to avoid appearance of ref leaks
encodings._cache.pop(self.codec_name, None)
try:
_forget_codec(self.codec_name)
except KeyError:
pass
def set_codec(self, encode, decode):
codec_info = codecs.CodecInfo(encode, decode,
name=self.codec_name)
_TEST_CODECS[self.codec_name] = codec_info
@contextlib.contextmanager
def assertWrapped(self, operation, exc_type, msg):
full_msg = r"{} with {!r} codec failed \({}: {}\)".format(
operation, self.codec_name, exc_type.__name__, msg)
with self.assertRaisesRegex(exc_type, full_msg) as caught:
yield caught
self.assertIsInstance(caught.exception.__cause__, exc_type)
self.assertIsNotNone(caught.exception.__cause__.__traceback__)
def raise_obj(self, *args, **kwds):
# Helper to dynamically change the object raised by a test codec
raise self.obj_to_raise
def check_wrapped(self, obj_to_raise, msg, exc_type=RuntimeError):
self.obj_to_raise = obj_to_raise
self.set_codec(self.raise_obj, self.raise_obj)
with self.assertWrapped("encoding", exc_type, msg):
"str_input".encode(self.codec_name)
with self.assertWrapped("encoding", exc_type, msg):
codecs.encode("str_input", self.codec_name)
with self.assertWrapped("decoding", exc_type, msg):
b"bytes input".decode(self.codec_name)
with self.assertWrapped("decoding", exc_type, msg):
codecs.decode(b"bytes input", self.codec_name)
def test_raise_by_type(self):
self.check_wrapped(RuntimeError, "")
def test_raise_by_value(self):
msg = "This should be wrapped"
self.check_wrapped(RuntimeError(msg), msg)
def test_raise_grandchild_subclass_exact_size(self):
msg = "This should be wrapped"
class MyRuntimeError(RuntimeError):
__slots__ = ()
self.check_wrapped(MyRuntimeError(msg), msg, MyRuntimeError)
def test_raise_subclass_with_weakref_support(self):
msg = "This should be wrapped"
class MyRuntimeError(RuntimeError):
pass
self.check_wrapped(MyRuntimeError(msg), msg, MyRuntimeError)
def check_not_wrapped(self, obj_to_raise, msg):
def raise_obj(*args, **kwds):
raise obj_to_raise
self.set_codec(raise_obj, raise_obj)
with self.assertRaisesRegex(RuntimeError, msg):
"str input".encode(self.codec_name)
with self.assertRaisesRegex(RuntimeError, msg):
codecs.encode("str input", self.codec_name)
with self.assertRaisesRegex(RuntimeError, msg):
b"bytes input".decode(self.codec_name)
with self.assertRaisesRegex(RuntimeError, msg):
codecs.decode(b"bytes input", self.codec_name)
def test_init_override_is_not_wrapped(self):
class CustomInit(RuntimeError):
def __init__(self):
pass
self.check_not_wrapped(CustomInit, "")
def test_new_override_is_not_wrapped(self):
class CustomNew(RuntimeError):
def __new__(cls):
return super().__new__(cls)
self.check_not_wrapped(CustomNew, "")
def test_instance_attribute_is_not_wrapped(self):
msg = "This should NOT be wrapped"
exc = RuntimeError(msg)
exc.attr = 1
self.check_not_wrapped(exc, "^{}$".format(msg))
def test_non_str_arg_is_not_wrapped(self):
self.check_not_wrapped(RuntimeError(1), "1")
def test_multiple_args_is_not_wrapped(self):
msg_re = r"^\('a', 'b', 'c'\)$"
self.check_not_wrapped(RuntimeError('a', 'b', 'c'), msg_re)
# http://bugs.python.org/issue19609
def test_codec_lookup_failure_not_wrapped(self):
msg = "^unknown encoding: {}$".format(self.codec_name)
# The initial codec lookup should not be wrapped
with self.assertRaisesRegex(LookupError, msg):
"str input".encode(self.codec_name)
with self.assertRaisesRegex(LookupError, msg):
codecs.encode("str input", self.codec_name)
with self.assertRaisesRegex(LookupError, msg):
b"bytes input".decode(self.codec_name)
with self.assertRaisesRegex(LookupError, msg):
codecs.decode(b"bytes input", self.codec_name)
def test_unflagged_non_text_codec_handling(self):
# The stdlib non-text codecs are now marked so they're
# pre-emptively skipped by the text model related methods
# However, third party codecs won't be flagged, so we still make
# sure the case where an inappropriate output type is produced is
# handled appropriately
def encode_to_str(*args, **kwds):
return "not bytes!", 0
def decode_to_bytes(*args, **kwds):
return b"not str!", 0
self.set_codec(encode_to_str, decode_to_bytes)
# No input or output type checks on the codecs module functions
encoded = codecs.encode(None, self.codec_name)
self.assertEqual(encoded, "not bytes!")
decoded = codecs.decode(None, self.codec_name)
self.assertEqual(decoded, b"not str!")
# Text model methods should complain
fmt = (r"^{!r} encoder returned 'str' instead of 'bytes'; "
"use codecs.encode\(\) to encode to arbitrary types$")
msg = fmt.format(self.codec_name)
with self.assertRaisesRegex(TypeError, msg):
"str_input".encode(self.codec_name)
fmt = (r"^{!r} decoder returned 'bytes' instead of 'str'; "
"use codecs.decode\(\) to decode to arbitrary types$")
msg = fmt.format(self.codec_name)
with self.assertRaisesRegex(TypeError, msg):
b"bytes input".decode(self.codec_name)
@unittest.skipUnless(sys.platform == 'win32',
'code pages are specific to Windows')
class CodePageTest(unittest.TestCase):
# CP_UTF8 is already tested by CP65001Test
CP_UTF8 = 65001
def test_invalid_code_page(self):
self.assertRaises(ValueError, codecs.code_page_encode, -1, 'a')
self.assertRaises(ValueError, codecs.code_page_decode, -1, b'a')
self.assertRaises(OSError, codecs.code_page_encode, 123, 'a')
self.assertRaises(OSError, codecs.code_page_decode, 123, b'a')
def test_code_page_name(self):
self.assertRaisesRegex(UnicodeEncodeError, 'cp932',
codecs.code_page_encode, 932, '\xff')
self.assertRaisesRegex(UnicodeDecodeError, 'cp932',
codecs.code_page_decode, 932, b'\x81\x00')
self.assertRaisesRegex(UnicodeDecodeError, 'CP_UTF8',
codecs.code_page_decode, self.CP_UTF8, b'\xff')
def check_decode(self, cp, tests):
for raw, errors, expected in tests:
if expected is not None:
try:
decoded = codecs.code_page_decode(cp, raw, errors)
except UnicodeDecodeError as err:
self.fail('Unable to decode %a from "cp%s" with '
'errors=%r: %s' % (raw, cp, errors, err))
self.assertEqual(decoded[0], expected,
'%a.decode("cp%s", %r)=%a != %a'
% (raw, cp, errors, decoded[0], expected))
# assert 0 <= decoded[1] <= len(raw)
self.assertGreaterEqual(decoded[1], 0)
self.assertLessEqual(decoded[1], len(raw))
else:
self.assertRaises(UnicodeDecodeError,
codecs.code_page_decode, cp, raw, errors)
def check_encode(self, cp, tests):
for text, errors, expected in tests:
if expected is not None:
try:
encoded = codecs.code_page_encode(cp, text, errors)
except UnicodeEncodeError as err:
self.fail('Unable to encode %a to "cp%s" with '
'errors=%r: %s' % (text, cp, errors, err))
self.assertEqual(encoded[0], expected,
'%a.encode("cp%s", %r)=%a != %a'
% (text, cp, errors, encoded[0], expected))
self.assertEqual(encoded[1], len(text))
else:
self.assertRaises(UnicodeEncodeError,
codecs.code_page_encode, cp, text, errors)
def test_cp932(self):
self.check_encode(932, (
('abc', 'strict', b'abc'),
('\uff44\u9a3e', 'strict', b'\x82\x84\xe9\x80'),
# test error handlers
('\xff', 'strict', None),
('[\xff]', 'ignore', b'[]'),
('[\xff]', 'replace', b'[y]'),
('[\u20ac]', 'replace', b'[?]'),
('[\xff]', 'backslashreplace', b'[\\xff]'),
('[\xff]', 'xmlcharrefreplace', b'[ÿ]'),
))
self.check_decode(932, (
(b'abc', 'strict', 'abc'),
(b'\x82\x84\xe9\x80', 'strict', '\uff44\u9a3e'),
# invalid bytes
(b'[\xff]', 'strict', None),
(b'[\xff]', 'ignore', '[]'),
(b'[\xff]', 'replace', '[\ufffd]'),
(b'[\xff]', 'surrogateescape', '[\udcff]'),
(b'\x81\x00abc', 'strict', None),
(b'\x81\x00abc', 'ignore', '\x00abc'),
(b'\x81\x00abc', 'replace', '\ufffd\x00abc'),
))
def test_cp1252(self):
self.check_encode(1252, (
('abc', 'strict', b'abc'),
('\xe9\u20ac', 'strict', b'\xe9\x80'),
('\xff', 'strict', b'\xff'),
('\u0141', 'strict', None),
('\u0141', 'ignore', b''),
('\u0141', 'replace', b'L'),
))
self.check_decode(1252, (
(b'abc', 'strict', 'abc'),
(b'\xe9\x80', 'strict', '\xe9\u20ac'),
(b'\xff', 'strict', '\xff'),
))
def test_cp_utf7(self):
cp = 65000
self.check_encode(cp, (
('abc', 'strict', b'abc'),
('\xe9\u20ac', 'strict', b'+AOkgrA-'),
('\U0010ffff', 'strict', b'+2//f/w-'),
('\udc80', 'strict', b'+3IA-'),
('\ufffd', 'strict', b'+//0-'),
))
self.check_decode(cp, (
(b'abc', 'strict', 'abc'),
(b'+AOkgrA-', 'strict', '\xe9\u20ac'),
(b'+2//f/w-', 'strict', '\U0010ffff'),
(b'+3IA-', 'strict', '\udc80'),
(b'+//0-', 'strict', '\ufffd'),
# invalid bytes
(b'[+/]', 'strict', '[]'),
(b'[\xff]', 'strict', '[\xff]'),
))
def test_multibyte_encoding(self):
self.check_decode(932, (
(b'\x84\xe9\x80', 'ignore', '\u9a3e'),
(b'\x84\xe9\x80', 'replace', '\ufffd\u9a3e'),
))
self.check_decode(self.CP_UTF8, (
(b'\xff\xf4\x8f\xbf\xbf', 'ignore', '\U0010ffff'),
(b'\xff\xf4\x8f\xbf\xbf', 'replace', '\ufffd\U0010ffff'),
))
if VISTA_OR_LATER:
self.check_encode(self.CP_UTF8, (
('[\U0010ffff\uDC80]', 'ignore', b'[\xf4\x8f\xbf\xbf]'),
('[\U0010ffff\uDC80]', 'replace', b'[\xf4\x8f\xbf\xbf?]'),
))
def test_incremental(self):
decoded = codecs.code_page_decode(932, b'\x82', 'strict', False)
self.assertEqual(decoded, ('', 0))
decoded = codecs.code_page_decode(932,
b'\xe9\x80\xe9', 'strict',
False)
self.assertEqual(decoded, ('\u9a3e', 2))
decoded = codecs.code_page_decode(932,
b'\xe9\x80\xe9\x80', 'strict',
False)
self.assertEqual(decoded, ('\u9a3e\u9a3e', 4))
decoded = codecs.code_page_decode(932,
b'abc', 'strict',
False)
self.assertEqual(decoded, ('abc', 3))
if __name__ == "__main__":
unittest.main()
|
lgpl-3.0
|
[
646,
6010,
199,
646,
15502,
199,
646,
5890,
199,
646,
5867,
199,
646,
984,
199,
646,
2882,
199,
646,
3598,
199,
646,
14134,
199,
199,
504,
511,
492,
2291,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
812,
6225,
33,
63,
726,
63,
44,
10447,
275,
334,
1274,
14,
362,
8258,
1023,
1252,
8452,
2356,
1227,
9,
199,
2836,
26,
272,
812,
6225,
33,
63,
726,
63,
44,
10447,
275,
756,
199,
199,
893,
26,
272,
492,
5577,
199,
2590,
3545,
26,
272,
5577,
275,
488,
272,
32289,
3359,
63,
55,
5901,
63,
52,
275,
446,
17,
199,
2836,
26,
272,
32289,
3359,
63,
55,
5901,
63,
52,
275,
5577,
14,
12590,
8,
9798,
14,
67,
63,
23118,
9,
199,
199,
318,
2803,
63,
6743,
8,
277,
12,
1233,
82,
304,
272,
347,
1104,
8,
1210,
12,
4282,
304,
267,
291,
14,
629,
8,
2693,
8,
1210,
395,
334,
4921,
12,
822,
8,
1210,
1724,
272,
372,
1104,
199,
199,
533,
10703,
8,
785,
304,
272,
408,
272,
4126,
26,
2218,
2783,
737,
1373,
1284,
12,
1586,
2783,
687,
314,
1163,
1284,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3335,
304,
267,
291,
423,
2738,
275,
3335,
339,
347,
2218,
8,
277,
12,
8365,
304,
267,
291,
423,
2738,
847,
8365,
339,
347,
1586,
8,
277,
12,
1568,
4022,
17,
304,
267,
340,
1568,
28,
16,
26,
288,
308,
275,
291,
423,
2738,
288,
291,
423,
2738,
275,
291,
423,
2738,
1491,
16,
61,
327,
1852,
2701,
288,
372,
308,
267,
587,
26,
288,
308,
275,
291,
423,
2738,
1491,
890,
61,
288,
291,
423,
2738,
275,
291,
423,
2738,
59,
890,
2938,
288,
372,
308,
199,
199,
533,
603,
1148,
607,
1799,
2223,
26443,
26,
272,
347,
1104,
63,
929,
63,
22273,
63,
2708,
8,
277,
12,
2644,
12,
399,
12,
308,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
83,
6393,
17,
304,
288,
366,
275,
6010,
14,
362,
23760,
8813,
8,
2991,
16315,
288,
1777,
17,
275,
366,
14,
2708,
8,
83,
1491,
73,
566,
288,
1174,
275,
366,
14,
16011,
342,
288,
291,
14,
6926,
8,
929,
59,
17,
467,
1109,
9,
288,
327,
2670,
626,
314,
5558,
410,
972,
315,
314,
3794,
367,
288,
327,
24385,
14,
16011,
342,
15164,
288,
340,
440,
1174,
59,
17,
2189,
355,
327,
5305,
10334,
370,
314,
849,
1174,
1928,
7003,
20224,
355,
366,
14,
17212,
1332,
929,
59,
16,
19663,
16,
467,
378,
430,
355,
327,
16261,
316,
314,
4136,
1324,
1443,
440,
7389,
1263,
1072,
355,
291,
14,
1815,
8,
1397,
366,
14,
2708,
8,
929,
59,
16,
2459,
355,
327,
710,
10334,
1471,
372,
370,
314,
2011,
1174,
355,
291,
14,
629,
8,
929,
12,
366,
14,
16011,
1012,
288,
327,
2790,
282,
892,
10334,
436,
663,
652,
370,
314,
1174,
288,
327,
781,
12509,
687,
314,
2269,
1373,
288,
366,
275,
6010,
14,
362,
23760,
8813,
8,
2991,
16315,
288,
366,
14,
17212,
8,
929,
9,
288,
1777,
18,
275,
366,
14,
2708,
8,
83,
59,
73,
8429,
715,
9,
288,
291,
14,
629,
8,
85,
12,
1777,
17,
11,
2064,
18,
9,
339,
347,
1104,
63,
929,
63,
22273,
63,
2143,
8,
277,
12,
2644,
12,
399,
12,
308,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
85,
6393,
17,
304,
288,
366,
275,
6010,
14,
362,
9728,
24080,
8,
2991,
16315,
288,
1777,
17,
275,
366,
14,
2143,
8,
85,
1491,
73,
566,
288,
1174,
275,
366,
14,
16011,
342,
288,
366,
275,
6010,
14,
362,
9728,
24080,
8,
2991,
16315,
288,
366,
14,
17212,
8,
929,
9,
288,
1777,
18,
275,
366,
14,
2143,
8,
85,
59,
73,
8429,
715,
9,
288,
291,
14,
629,
8,
83,
12,
1777,
17,
11,
2064,
18,
9,
199,
199,
533,
5574,
774,
8,
26527,
1799,
2223,
26443,
304,
272,
347,
1104,
63,
6672,
8,
277,
12,
1324,
12,
7417,
2604,
304,
267,
327,
664,
282,
22970,
367,
314,
2644,
436,
4733,
314,
23888,
1015,
267,
327,
402,
1324,
370,
314,
7002,
3696,
701,
3696,
14,
5574,
8137,
2808,
687,
267,
327,
314,
22970,
436,
1104,
626,
314,
2058,
4472,
314,
5827,
267,
327,
4811,
687,
7417,
2604,
14,
267,
1894,
275,
10703,
8,
66,
7230,
267,
519,
275,
6010,
14,
362,
5503,
8,
277,
14,
2991,
5130,
81,
9,
267,
754,
275,
3087,
267,
367,
334,
67,
12,
7417,
1099,
9,
315,
3482,
8,
1210,
14,
2143,
8,
277,
14,
2991,
395,
7417,
2604,
304,
288,
1894,
14,
952,
8,
2394,
779,
67,
2459,
288,
754,
847,
519,
14,
739,
342,
288,
291,
14,
629,
8,
1099,
12,
7417,
1099,
9,
267,
327,
1104,
626,
2337,
1159,
6548,
3602,
315,
314,
19383,
267,
291,
14,
629,
8,
82,
14,
739,
1062,
6899,
267,
291,
14,
629,
8,
82,
14,
4414,
2738,
12,
330,
7230,
398,
327,
886,
314,
1104,
4020,
12,
642,
900,
1808,
282,
16316,
10334,
267,
366,
275,
6010,
14,
362,
23760,
8813,
8,
277,
14,
2991,
16315,
267,
754,
275,
3087,
267,
367,
334,
67,
12,
7417,
1099,
9,
315,
3482,
8,
1210,
14,
2143,
8,
277,
14,
2991,
395,
7417,
2604,
304,
288,
754,
847,
366,
14,
2708,
8,
2394,
779,
67,
2459,
288,
291,
14,
629,
8,
1099,
12,
7417,
1099,
9,
267,
327,
1104,
626,
2337,
1159,
6548,
3602,
315,
314,
19383,
267,
291,
14,
629,
8,
68,
14,
2708,
8,
66,
5151,
715,
395,
6899,
267,
291,
14,
629,
8,
68,
14,
2738,
12,
330,
7230,
398,
327,
2670,
3775,
314,
5305,
1083,
5419,
7684,
267,
366,
14,
3958,
342,
267,
754,
275,
3087,
267,
367,
334,
67,
12,
7417,
1099,
9,
315,
3482,
8,
1210,
14,
2143,
8,
277,
14,
2991,
395,
7417,
2604,
304,
288,
754,
847,
366,
14,
2708,
8,
2394,
779,
67,
2459,
288,
291,
14,
629,
8,
1099,
12,
7417,
1099,
9,
267,
327,
1104,
626,
2337,
1159,
6548,
3602,
315,
314,
19383,
267,
291,
14,
629,
8,
68,
14,
2708,
8,
66,
5151,
715,
395,
6899,
267,
291,
14,
629,
8,
68,
14,
2738,
12,
330,
7230,
398,
327,
1104,
2740,
2708,
342,
267,
5737,
275,
1324,
14
] |
[
6010,
199,
646,
15502,
199,
646,
5890,
199,
646,
5867,
199,
646,
984,
199,
646,
2882,
199,
646,
3598,
199,
646,
14134,
199,
199,
504,
511,
492,
2291,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
812,
6225,
33,
63,
726,
63,
44,
10447,
275,
334,
1274,
14,
362,
8258,
1023,
1252,
8452,
2356,
1227,
9,
199,
2836,
26,
272,
812,
6225,
33,
63,
726,
63,
44,
10447,
275,
756,
199,
199,
893,
26,
272,
492,
5577,
199,
2590,
3545,
26,
272,
5577,
275,
488,
272,
32289,
3359,
63,
55,
5901,
63,
52,
275,
446,
17,
199,
2836,
26,
272,
32289,
3359,
63,
55,
5901,
63,
52,
275,
5577,
14,
12590,
8,
9798,
14,
67,
63,
23118,
9,
199,
199,
318,
2803,
63,
6743,
8,
277,
12,
1233,
82,
304,
272,
347,
1104,
8,
1210,
12,
4282,
304,
267,
291,
14,
629,
8,
2693,
8,
1210,
395,
334,
4921,
12,
822,
8,
1210,
1724,
272,
372,
1104,
199,
199,
533,
10703,
8,
785,
304,
272,
408,
272,
4126,
26,
2218,
2783,
737,
1373,
1284,
12,
1586,
2783,
687,
314,
1163,
1284,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3335,
304,
267,
291,
423,
2738,
275,
3335,
339,
347,
2218,
8,
277,
12,
8365,
304,
267,
291,
423,
2738,
847,
8365,
339,
347,
1586,
8,
277,
12,
1568,
4022,
17,
304,
267,
340,
1568,
28,
16,
26,
288,
308,
275,
291,
423,
2738,
288,
291,
423,
2738,
275,
291,
423,
2738,
1491,
16,
61,
327,
1852,
2701,
288,
372,
308,
267,
587,
26,
288,
308,
275,
291,
423,
2738,
1491,
890,
61,
288,
291,
423,
2738,
275,
291,
423,
2738,
59,
890,
2938,
288,
372,
308,
199,
199,
533,
603,
1148,
607,
1799,
2223,
26443,
26,
272,
347,
1104,
63,
929,
63,
22273,
63,
2708,
8,
277,
12,
2644,
12,
399,
12,
308,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
83,
6393,
17,
304,
288,
366,
275,
6010,
14,
362,
23760,
8813,
8,
2991,
16315,
288,
1777,
17,
275,
366,
14,
2708,
8,
83,
1491,
73,
566,
288,
1174,
275,
366,
14,
16011,
342,
288,
291,
14,
6926,
8,
929,
59,
17,
467,
1109,
9,
288,
327,
2670,
626,
314,
5558,
410,
972,
315,
314,
3794,
367,
288,
327,
24385,
14,
16011,
342,
15164,
288,
340,
440,
1174,
59,
17,
2189,
355,
327,
5305,
10334,
370,
314,
849,
1174,
1928,
7003,
20224,
355,
366,
14,
17212,
1332,
929,
59,
16,
19663,
16,
467,
378,
430,
355,
327,
16261,
316,
314,
4136,
1324,
1443,
440,
7389,
1263,
1072,
355,
291,
14,
1815,
8,
1397,
366,
14,
2708,
8,
929,
59,
16,
2459,
355,
327,
710,
10334,
1471,
372,
370,
314,
2011,
1174,
355,
291,
14,
629,
8,
929,
12,
366,
14,
16011,
1012,
288,
327,
2790,
282,
892,
10334,
436,
663,
652,
370,
314,
1174,
288,
327,
781,
12509,
687,
314,
2269,
1373,
288,
366,
275,
6010,
14,
362,
23760,
8813,
8,
2991,
16315,
288,
366,
14,
17212,
8,
929,
9,
288,
1777,
18,
275,
366,
14,
2708,
8,
83,
59,
73,
8429,
715,
9,
288,
291,
14,
629,
8,
85,
12,
1777,
17,
11,
2064,
18,
9,
339,
347,
1104,
63,
929,
63,
22273,
63,
2143,
8,
277,
12,
2644,
12,
399,
12,
308,
304,
267,
367,
284,
315,
1425,
8,
552,
8,
85,
6393,
17,
304,
288,
366,
275,
6010,
14,
362,
9728,
24080,
8,
2991,
16315,
288,
1777,
17,
275,
366,
14,
2143,
8,
85,
1491,
73,
566,
288,
1174,
275,
366,
14,
16011,
342,
288,
366,
275,
6010,
14,
362,
9728,
24080,
8,
2991,
16315,
288,
366,
14,
17212,
8,
929,
9,
288,
1777,
18,
275,
366,
14,
2143,
8,
85,
59,
73,
8429,
715,
9,
288,
291,
14,
629,
8,
83,
12,
1777,
17,
11,
2064,
18,
9,
199,
199,
533,
5574,
774,
8,
26527,
1799,
2223,
26443,
304,
272,
347,
1104,
63,
6672,
8,
277,
12,
1324,
12,
7417,
2604,
304,
267,
327,
664,
282,
22970,
367,
314,
2644,
436,
4733,
314,
23888,
1015,
267,
327,
402,
1324,
370,
314,
7002,
3696,
701,
3696,
14,
5574,
8137,
2808,
687,
267,
327,
314,
22970,
436,
1104,
626,
314,
2058,
4472,
314,
5827,
267,
327,
4811,
687,
7417,
2604,
14,
267,
1894,
275,
10703,
8,
66,
7230,
267,
519,
275,
6010,
14,
362,
5503,
8,
277,
14,
2991,
5130,
81,
9,
267,
754,
275,
3087,
267,
367,
334,
67,
12,
7417,
1099,
9,
315,
3482,
8,
1210,
14,
2143,
8,
277,
14,
2991,
395,
7417,
2604,
304,
288,
1894,
14,
952,
8,
2394,
779,
67,
2459,
288,
754,
847,
519,
14,
739,
342,
288,
291,
14,
629,
8,
1099,
12,
7417,
1099,
9,
267,
327,
1104,
626,
2337,
1159,
6548,
3602,
315,
314,
19383,
267,
291,
14,
629,
8,
82,
14,
739,
1062,
6899,
267,
291,
14,
629,
8,
82,
14,
4414,
2738,
12,
330,
7230,
398,
327,
886,
314,
1104,
4020,
12,
642,
900,
1808,
282,
16316,
10334,
267,
366,
275,
6010,
14,
362,
23760,
8813,
8,
277,
14,
2991,
16315,
267,
754,
275,
3087,
267,
367,
334,
67,
12,
7417,
1099,
9,
315,
3482,
8,
1210,
14,
2143,
8,
277,
14,
2991,
395,
7417,
2604,
304,
288,
754,
847,
366,
14,
2708,
8,
2394,
779,
67,
2459,
288,
291,
14,
629,
8,
1099,
12,
7417,
1099,
9,
267,
327,
1104,
626,
2337,
1159,
6548,
3602,
315,
314,
19383,
267,
291,
14,
629,
8,
68,
14,
2708,
8,
66,
5151,
715,
395,
6899,
267,
291,
14,
629,
8,
68,
14,
2738,
12,
330,
7230,
398,
327,
2670,
3775,
314,
5305,
1083,
5419,
7684,
267,
366,
14,
3958,
342,
267,
754,
275,
3087,
267,
367,
334,
67,
12,
7417,
1099,
9,
315,
3482,
8,
1210,
14,
2143,
8,
277,
14,
2991,
395,
7417,
2604,
304,
288,
754,
847,
366,
14,
2708,
8,
2394,
779,
67,
2459,
288,
291,
14,
629,
8,
1099,
12,
7417,
1099,
9,
267,
327,
1104,
626,
2337,
1159,
6548,
3602,
315,
314,
19383,
267,
291,
14,
629,
8,
68,
14,
2708,
8,
66,
5151,
715,
395,
6899,
267,
291,
14,
629,
8,
68,
14,
2738,
12,
330,
7230,
398,
327,
1104,
2740,
2708,
342,
267,
5737,
275,
1324,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
schlos/eden
|
modules/s3db/msg.py
|
7
|
91452
|
# -*- coding: utf-8 -*-
""" Sahana Eden Messaging Model
@copyright: 2009-2015 (c) Sahana Software Foundation
@license: MIT
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.
"""
__all__ = ("S3ChannelModel",
"S3MessageModel",
"S3MessageAttachmentModel",
"S3EmailModel",
"S3FacebookModel",
"S3MCommonsModel",
"S3ParsingModel",
"S3RSSModel",
"S3SMSModel",
"S3SMSOutboundModel",
"S3TropoModel",
"S3TwilioModel",
"S3TwitterModel",
"S3TwitterSearchModel",
"S3XFormsModel",
"S3BaseStationModel",
)
from gluon import *
from gluon.storage import Storage
from ..s3 import *
# Compact JSON encoding
SEPARATORS = (",", ":")
# =============================================================================
class S3ChannelModel(S3Model):
"""
Messaging Channels
- all Inbound & Outbound channels for messages are instances of this
super-entity
"""
names = ("msg_channel",
"msg_channel_limit",
"msg_channel_status",
"msg_channel_id",
"msg_channel_enable",
"msg_channel_disable",
"msg_channel_enable_interactive",
"msg_channel_disable_interactive",
"msg_channel_onaccept",
)
def model(self):
T = current.T
db = current.db
define_table = self.define_table
#----------------------------------------------------------------------
# Super entity: msg_channel
#
channel_types = Storage(msg_email_channel = T("Email (Inbound)"),
msg_facebook_channel = T("Facebook"),
msg_mcommons_channel = T("Mobile Commons (Inbound)"),
msg_rss_channel = T("RSS Feed"),
msg_sms_modem_channel = T("SMS Modem"),
msg_sms_webapi_channel = T("SMS WebAPI (Outbound)"),
msg_sms_smtp_channel = T("SMS via SMTP (Outbound)"),
msg_tropo_channel = T("Tropo"),
msg_twilio_channel = T("Twilio (Inbound)"),
msg_twitter_channel = T("Twitter"),
)
tablename = "msg_channel"
self.super_entity(tablename, "channel_id",
channel_types,
Field("name",
#label = T("Name"),
),
Field("description",
#label = T("Description"),
),
Field("enabled", "boolean",
default = True,
#label = T("Enabled?")
#represent = s3_yes_no_represent,
),
# @ToDo: Indicate whether channel can be used for Inbound or Outbound
#Field("inbound", "boolean",
# label = T("Inbound?")),
#Field("outbound", "boolean",
# label = T("Outbound?")),
)
# @todo: make lazy_table
table = db[tablename]
table.instance_type.readable = True
# Reusable Field
channel_id = S3ReusableField("channel_id", "reference %s" % tablename,
label = T("Channel"),
ondelete = "SET NULL",
represent = S3Represent(lookup=tablename),
requires = IS_EMPTY_OR(
IS_ONE_OF_EMPTY(db, "msg_channel.id")),
)
self.add_components(tablename,
msg_channel_status = "channel_id",
)
# ---------------------------------------------------------------------
# Channel Limit
# Used to limit the number of emails sent from the system
# - works by simply recording an entry for the timestamp to be checked against
#
# - currently just used by msg.send_email()
#
tablename = "msg_channel_limit"
define_table(tablename,
# @ToDo: Make it per-channel
#channel_id(),
*s3_timestamp())
# ---------------------------------------------------------------------
# Channel Status
# Used to record errors encountered in the Channel
#
tablename = "msg_channel_status"
define_table(tablename,
channel_id(),
Field("status",
#label = T("Status"),
#represent = s3_yes_no_represent,
represent = lambda v: v or current.messages["NONE"],
),
*s3_meta_fields())
# ---------------------------------------------------------------------
return dict(msg_channel_id = channel_id,
msg_channel_enable = self.channel_enable,
msg_channel_disable = self.channel_disable,
msg_channel_enable_interactive = self.channel_enable_interactive,
msg_channel_disable_interactive = self.channel_disable_interactive,
msg_channel_onaccept = self.channel_onaccept,
msg_channel_poll = self.channel_poll,
)
# -------------------------------------------------------------------------
@staticmethod
def channel_enable(tablename, channel_id):
"""
Enable a Channel
- Schedule a Poll for new messages
- Enable all associated Parsers
CLI API for shell scripts & to be called by S3Method
"""
db = current.db
s3db = current.s3db
table = s3db.table(tablename)
record = db(table.channel_id == channel_id).select(table.id, # needed for update_record
table.enabled,
limitby=(0, 1),
).first()
if not record.enabled:
# Flag it as enabled
# Update Instance
record.update_record(enabled = True)
# Update Super
s3db.update_super(table, record)
# Enable all Parser tasks on this channel
ptable = s3db.msg_parser
query = (ptable.channel_id == channel_id) & \
(ptable.deleted == False)
parsers = db(query).select(ptable.id)
for parser in parsers:
s3db.msg_parser_enable(parser.id)
# Do we have an existing Task?
ttable = db.scheduler_task
args = '["%s", %s]' % (tablename, channel_id)
query = ((ttable.function_name == "msg_poll") & \
(ttable.args == args) & \
(ttable.status.belongs(["RUNNING", "QUEUED", "ALLOCATED"])))
exists = db(query).select(ttable.id,
limitby=(0, 1)).first()
if exists:
return "Channel already enabled"
else:
current.s3task.schedule_task("msg_poll",
args = [tablename, channel_id],
period = 300, # seconds
timeout = 300, # seconds
repeats = 0 # unlimited
)
return "Channel enabled"
# -------------------------------------------------------------------------
@staticmethod
def channel_enable_interactive(r, **attr):
"""
Enable a Channel
- Schedule a Poll for new messages
S3Method for interactive requests
"""
tablename = r.tablename
result = current.s3db.msg_channel_enable(tablename, r.record.channel_id)
current.session.confirmation = result
fn = tablename.split("_", 1)[1]
redirect(URL(f=fn))
# -------------------------------------------------------------------------
@staticmethod
def channel_disable(tablename, channel_id):
"""
Disable a Channel
- Remove schedule for Polling for new messages
- Disable all associated Parsers
CLI API for shell scripts & to be called by S3Method
"""
db = current.db
s3db = current.s3db
table = s3db.table(tablename)
record = db(table.channel_id == channel_id).select(table.id, # needed for update_record
table.enabled,
limitby=(0, 1),
).first()
if record.enabled:
# Flag it as disabled
# Update Instance
record.update_record(enabled = False)
# Update Super
s3db.update_super(table, record)
# Disable all Parser tasks on this channel
ptable = s3db.msg_parser
parsers = db(ptable.channel_id == channel_id).select(ptable.id)
for parser in parsers:
s3db.msg_parser_disable(parser.id)
# Do we have an existing Task?
ttable = db.scheduler_task
args = '["%s", %s]' % (tablename, channel_id)
query = ((ttable.function_name == "msg_poll") & \
(ttable.args == args) & \
(ttable.status.belongs(["RUNNING", "QUEUED", "ALLOCATED"])))
exists = db(query).select(ttable.id,
limitby=(0, 1)).first()
if exists:
# Disable all
db(query).update(status="STOPPED")
return "Channel disabled"
else:
return "Channel already disabled"
# --------------------------------------------------------------------------
@staticmethod
def channel_disable_interactive(r, **attr):
"""
Disable a Channel
- Remove schedule for Polling for new messages
S3Method for interactive requests
"""
tablename = r.tablename
result = current.s3db.msg_channel_disable(tablename, r.record.channel_id)
current.session.confirmation = result
fn = tablename.split("_", 1)[1]
redirect(URL(f=fn))
# -------------------------------------------------------------------------
@staticmethod
def channel_onaccept(form):
"""
Process the Enabled Flag
"""
if form.record:
# Update form
# Process if changed
if form.record.enabled and not form.vars.enabled:
current.s3db.msg_channel_disable(form.table._tablename,
form.vars.channel_id)
elif form.vars.enabled and not form.record.enabled:
current.s3db.msg_channel_enable(form.table._tablename,
form.vars.channel_id)
else:
# Create form
# Process only if enabled
if form.vars.enabled:
current.s3db.msg_channel_enable(form.table._tablename,
form.vars.channel_id)
# -------------------------------------------------------------------------
@staticmethod
def channel_poll(r, **attr):
"""
Poll a Channel for new messages
S3Method for interactive requests
"""
tablename = r.tablename
current.s3task.async("msg_poll", args=[tablename, r.record.channel_id])
current.session.confirmation = \
current.T("The poll request has been submitted, so new messages should appear shortly - refresh to see them")
if tablename == "msg_email_channel":
fn = "email_inbox"
elif tablename == "msg_mcommons_channel":
fn = "sms_inbox"
elif tablename == "msg_rss_channel":
fn = "rss"
elif tablename == "msg_twilio_channel":
fn = "sms_inbox"
elif tablename == "msg_twitter_channel":
fn = "twitter_inbox"
else:
return "Unsupported channel: %s" % tablename
redirect(URL(f=fn))
# =============================================================================
class S3MessageModel(S3Model):
"""
Messages
"""
names = ("msg_message",
"msg_message_id",
"msg_message_represent",
"msg_outbox",
)
def model(self):
T = current.T
db = current.db
UNKNOWN_OPT = current.messages.UNKNOWN_OPT
configure = self.configure
define_table = self.define_table
# Message priority
msg_priority_opts = {3 : T("High"),
2 : T("Medium"),
1 : T("Low"),
}
# ---------------------------------------------------------------------
# Message Super Entity - all Inbound & Outbound Messages
#
message_types = Storage(msg_email = T("Email"),
msg_facebook = T("Facebook"),
msg_rss = T("RSS"),
msg_sms = T("SMS"),
msg_twitter = T("Twitter"),
msg_twitter_result = T("Twitter Search Results"),
)
tablename = "msg_message"
self.super_entity(tablename, "message_id",
message_types,
# Knowing which Channel Incoming Messages
# came in on allows correlation to Outbound
# messages (campaign_message, deployment_alert, etc)
self.msg_channel_id(),
s3_datetime(default="now"),
Field("body", "text",
label = T("Message"),
),
Field("from_address",
label = T("From"),
),
Field("to_address",
label = T("To"),
),
Field("inbound", "boolean",
default = False,
label = T("Direction"),
represent = lambda direction: \
(direction and [T("In")] or \
[T("Out")])[0],
),
)
# @todo: make lazy_table
table = db[tablename]
table.instance_type.readable = True
table.instance_type.writable = True
configure(tablename,
list_fields = ["instance_type",
"from_address",
"to_address",
"body",
"inbound",
],
)
# Reusable Field
message_represent = S3Represent(lookup=tablename, fields=["body"])
message_id = S3ReusableField("message_id", "reference %s" % tablename,
ondelete = "RESTRICT",
represent = message_represent,
requires = IS_EMPTY_OR(
IS_ONE_OF_EMPTY(db, "msg_message.id")),
)
self.add_components(tablename,
msg_attachment = "message_id",
deploy_response = "message_id",
)
# ---------------------------------------------------------------------
# Outbound Messages
#
# Show only the supported messaging methods
MSG_CONTACT_OPTS = current.msg.MSG_CONTACT_OPTS
# Maximum number of retries to send a message
MAX_SEND_RETRIES = current.deployment_settings.get_msg_max_send_retries()
# Valid message outbox statuses
MSG_STATUS_OPTS = {1 : T("Unsent"),
2 : T("Sent"),
3 : T("Draft"),
4 : T("Invalid"),
5 : T("Failed"),
}
opt_msg_status = S3ReusableField("status", "integer",
notnull=True,
requires = IS_IN_SET(MSG_STATUS_OPTS,
zero=None),
default = 1,
label = T("Status"),
represent = lambda opt: \
MSG_STATUS_OPTS.get(opt,
UNKNOWN_OPT))
# Outbox - needs to be separate to Message since a single message
# sent needs different outbox entries for each recipient
tablename = "msg_outbox"
define_table(tablename,
# FK not instance
message_id(),
# Person/Group to send the message out to:
self.super_link("pe_id", "pr_pentity"),
# If set used instead of picking up from pe_id:
Field("address"),
Field("contact_method", length=32,
default = "EMAIL",
label = T("Contact Method"),
represent = lambda opt: \
MSG_CONTACT_OPTS.get(opt, UNKNOWN_OPT),
requires = IS_IN_SET(MSG_CONTACT_OPTS,
zero=None),
),
opt_msg_status(),
# Used to loop through a PE to get it's members
Field("system_generated", "boolean",
default = False,
),
# Give up if we can't send after MAX_RETRIES
Field("retries", "integer",
default = MAX_SEND_RETRIES,
readable = False,
writable = False,
),
*s3_meta_fields())
configure(tablename,
list_fields = ["id",
"message_id",
"pe_id",
"status",
],
orderby = "msg_outbox.created_on desc",
)
# ---------------------------------------------------------------------
# Pass names back to global scope (s3.*)
return dict(msg_message_id = message_id,
msg_message_represent = message_represent,
)
# -------------------------------------------------------------------------
@staticmethod
def defaults():
"""
Return safe defaults in case the model has been deactivated.
"""
dummy = S3ReusableField("dummy_id", "integer",
readable = False,
writable = False)
return dict(msg_message_id = lambda **attr: dummy("message_id"),
)
# =============================================================================
class S3MessageAttachmentModel(S3Model):
"""
Message Attachments
- link table between msg_message & doc_document
"""
names = ("msg_attachment",)
def model(self):
# ---------------------------------------------------------------------
#
tablename = "msg_attachment"
self.define_table(tablename,
# FK not instance
self.msg_message_id(ondelete="CASCADE"),
self.doc_document_id(),
*s3_meta_fields())
# ---------------------------------------------------------------------
# Pass names back to global scope (s3.*)
return {}
# =============================================================================
class S3EmailModel(S3ChannelModel):
"""
Email
InBound Channels
Outbound Email is currently handled via deployment_settings
InBox/OutBox
"""
names = ("msg_email_channel",
"msg_email",
)
def model(self):
T = current.T
configure = self.configure
define_table = self.define_table
set_method = self.set_method
super_link = self.super_link
# ---------------------------------------------------------------------
# Email Inbound Channels
#
tablename = "msg_email_channel"
define_table(tablename,
# Instance
super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("enabled", "boolean",
default = True,
label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("server"),
Field("protocol",
requires = IS_IN_SET(["imap", "pop3"],
zero=None),
),
Field("use_ssl", "boolean"),
Field("port", "integer"),
Field("username"),
Field("password", "password", length=64,
readable = False,
requires = IS_NOT_EMPTY(),
),
# Set true to delete messages from the remote
# inbox after fetching them.
Field("delete_from_server", "boolean"),
*s3_meta_fields())
configure(tablename,
onaccept = self.msg_channel_onaccept,
super_entity = "msg_channel",
)
set_method("msg", "email_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "email_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
set_method("msg", "email_channel",
method = "poll",
action = self.msg_channel_poll)
# ---------------------------------------------------------------------
# Email Messages: InBox & Outbox
#
sender = current.deployment_settings.get_mail_sender()
tablename = "msg_email"
define_table(tablename,
# Instance
super_link("message_id", "msg_message"),
self.msg_channel_id(),
s3_datetime(default = "now"),
Field("subject", length=78, # RFC 2822
label = T("Subject"),
),
Field("body", "text",
label = T("Message"),
),
Field("from_address", #notnull=True,
default = sender,
label = T("Sender"),
requires = IS_EMAIL(),
),
Field("to_address",
label = T("To"),
requires = IS_EMAIL(),
),
Field("raw", "text",
label = T("Message Source"),
readable = False,
writable = False,
),
Field("inbound", "boolean",
default = False,
label = T("Direction"),
represent = lambda direction: \
(direction and [T("In")] or [T("Out")])[0],
),
*s3_meta_fields())
configure(tablename,
orderby = "msg_email.date desc",
super_entity = "msg_message",
)
# Components
self.add_components(tablename,
# Used to link to custom tab deploy_response_select_mission:
deploy_mission = {"name": "select",
"link": "deploy_response",
"joinby": "message_id",
"key": "mission_id",
"autodelete": False,
},
)
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3FacebookModel(S3ChannelModel):
"""
Facebook
Channels
InBox/OutBox
https://developers.facebook.com/docs/graph-api
"""
names = ("msg_facebook_channel",
"msg_facebook",
"msg_facebook_login",
)
def model(self):
T = current.T
configure = self.configure
define_table = self.define_table
set_method = self.set_method
super_link = self.super_link
# ---------------------------------------------------------------------
# Facebook Channels
#
tablename = "msg_facebook_channel"
define_table(tablename,
# Instance
super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("enabled", "boolean",
default = True,
label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("login", "boolean",
default = False,
label = T("Use for Login?"),
represent = s3_yes_no_represent,
),
Field("app_id", "bigint",
requires = IS_INT_IN_RANGE(0, +1e16)
),
Field("app_secret", "password", length=64,
readable = False,
requires = IS_NOT_EMPTY(),
),
# Optional
Field("page_id", "bigint",
requires = IS_INT_IN_RANGE(0, +1e16)
),
Field("page_access_token"),
*s3_meta_fields())
configure(tablename,
onaccept = self.msg_facebook_channel_onaccept,
super_entity = "msg_channel",
)
set_method("msg", "facebook_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "facebook_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
#set_method("msg", "facebook_channel",
# method = "poll",
# action = self.msg_channel_poll)
# ---------------------------------------------------------------------
# Facebook Messages: InBox & Outbox
#
tablename = "msg_facebook"
define_table(tablename,
# Instance
super_link("message_id", "msg_message"),
self.msg_channel_id(),
s3_datetime(default = "now"),
Field("body", "text",
label = T("Message"),
),
# @ToDo: Are from_address / to_address relevant in Facebook?
Field("from_address", #notnull=True,
#default = sender,
label = T("Sender"),
),
Field("to_address",
label = T("To"),
),
Field("inbound", "boolean",
default = False,
label = T("Direction"),
represent = lambda direction: \
(direction and [T("In")] or [T("Out")])[0],
),
*s3_meta_fields())
configure(tablename,
orderby = "msg_facebook.date desc",
super_entity = "msg_message",
)
# ---------------------------------------------------------------------
return dict(msg_facebook_login = self.msg_facebook_login,
)
# -------------------------------------------------------------------------
@staticmethod
def defaults():
""" Safe defaults for model-global names if module is disabled """
return dict(msg_facebook_login = lambda: False,
)
# -------------------------------------------------------------------------
@staticmethod
def msg_facebook_channel_onaccept(form):
if form.vars.login:
# Ensure only a single account used for Login
current.db(current.s3db.msg_facebook_channel.id != form.vars.id).update(login = False)
# Normal onaccept processing
S3ChannelModel.channel_onaccept(form)
# -------------------------------------------------------------------------
@staticmethod
def msg_facebook_login():
table = current.s3db.msg_facebook_channel
query = (table.login == True) & \
(table.deleted == False)
c = current.db(query).select(table.app_id,
table.app_secret,
limitby=(0, 1)
).first()
return c
# =============================================================================
class S3MCommonsModel(S3ChannelModel):
"""
Mobile Commons Inbound SMS Settings
- Outbound can use Web API
"""
names = ("msg_mcommons_channel",)
def model(self):
#T = current.T
define_table = self.define_table
set_method = self.set_method
# ---------------------------------------------------------------------
tablename = "msg_mcommons_channel"
define_table(tablename,
self.super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("enabled", "boolean",
default = True,
#label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("campaign_id", length=128, unique=True,
requires = IS_NOT_EMPTY(),
),
Field("url",
default = \
"https://secure.mcommons.com/api/messages",
requires = IS_URL()
),
Field("username",
requires = IS_NOT_EMPTY(),
),
Field("password", "password",
readable = False,
requires = IS_NOT_EMPTY(),
),
Field("query"),
Field("timestmp", "datetime",
writable = False,
),
*s3_meta_fields())
self.configure(tablename,
onaccept = self.msg_channel_onaccept,
super_entity = "msg_channel",
)
set_method("msg", "mcommons_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "mcommons_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
set_method("msg", "mcommons_channel",
method = "poll",
action = self.msg_channel_poll)
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3ParsingModel(S3Model):
"""
Message Parsing Model
"""
names = ("msg_parser",
"msg_parsing_status",
"msg_session",
"msg_keyword",
"msg_sender",
"msg_parser_enabled",
"msg_parser_enable",
"msg_parser_disable",
"msg_parser_enable_interactive",
"msg_parser_disable_interactive",
)
def model(self):
T = current.T
define_table = self.define_table
set_method = self.set_method
channel_id = self.msg_channel_id
message_id = self.msg_message_id
# ---------------------------------------------------------------------
# Link between Message Channels and Parsers in parser.py
#
tablename = "msg_parser"
define_table(tablename,
# Source
channel_id(ondelete = "CASCADE"),
Field("function_name",
label = T("Parser"),
),
Field("enabled", "boolean",
default = True,
label = T("Enabled?"),
represent = s3_yes_no_represent,
),
*s3_meta_fields())
self.configure(tablename,
onaccept = self.msg_parser_onaccept,
)
set_method("msg", "parser",
method = "enable",
action = self.parser_enable_interactive)
set_method("msg", "parser",
method = "disable",
action = self.parser_disable_interactive)
set_method("msg", "parser",
method = "parse",
action = self.parser_parse)
# ---------------------------------------------------------------------
# Message parsing status
# - component to core msg_message table
#
tablename = "msg_parsing_status"
define_table(tablename,
# Component, not Instance
message_id(ondelete = "CASCADE"),
# Source
channel_id(ondelete = "CASCADE"),
Field("is_parsed", "boolean",
default = False,
label = T("Parsing Status"),
represent = lambda parsed: \
(parsed and [T("Parsed")] or \
[T("Not Parsed")])[0],
),
message_id("reply_id",
label = T("Reply"),
ondelete = "CASCADE",
),
*s3_meta_fields())
# ---------------------------------------------------------------------
# Login sessions for Message Parsing
# - links a from_address with a login until expiry
#
tablename = "msg_session"
define_table(tablename,
Field("from_address"),
Field("email"),
Field("created_datetime", "datetime",
default = current.request.utcnow,
),
Field("expiration_time", "integer"),
Field("is_expired", "boolean",
default = False,
),
*s3_meta_fields())
# ---------------------------------------------------------------------
# Keywords for Message Parsing
#
tablename = "msg_keyword"
define_table(tablename,
Field("keyword",
label = T("Keyword"),
),
# @ToDo: Move this to a link table
self.event_incident_type_id(),
*s3_meta_fields())
# ---------------------------------------------------------------------
# Senders for Message Parsing
# - whitelist / blacklist / prioritise
#
tablename = "msg_sender"
define_table(tablename,
Field("sender",
label = T("Sender"),
),
# @ToDo: Make pe_id work for this
#self.super_link("pe_id", "pr_pentity"),
Field("priority", "integer",
label = T("Priority"),
),
*s3_meta_fields())
# ---------------------------------------------------------------------
return dict(msg_parser_enabled = self.parser_enabled,
msg_parser_enable = self.parser_enable,
msg_parser_disable = self.parser_disable,
)
# -----------------------------------------------------------------------------
@staticmethod
def parser_parse(r, **attr):
"""
Parse unparsed messages
S3Method for interactive requests
"""
record = r.record
current.s3task.async("msg_parse", args=[record.channel_id, record.function_name])
current.session.confirmation = \
current.T("The parse request has been submitted")
redirect(URL(f="parser"))
# -------------------------------------------------------------------------
@staticmethod
def parser_enabled(channel_id):
"""
Helper function to see if there is a Parser connected to a Channel
- used to determine whether to populate the msg_parsing_status table
"""
table = current.s3db.msg_parser
record = current.db(table.channel_id == channel_id).select(table.enabled,
limitby=(0, 1),
).first()
if record and record.enabled:
return True
else:
return False
# -------------------------------------------------------------------------
@staticmethod
def parser_enable(id):
"""
Enable a Parser
- Connect a Parser to a Channel
CLI API for shell scripts & to be called by S3Method
@ToDo: Ensure only 1 Parser is connected to any Channel at a time
"""
db = current.db
s3db = current.s3db
table = s3db.msg_parser
record = db(table.id == id).select(table.id, # needed for update_record
table.enabled,
table.channel_id,
table.function_name,
limitby=(0, 1),
).first()
if not record.enabled:
# Flag it as enabled
record.update_record(enabled = True)
channel_id = record.channel_id
function_name = record.function_name
# Do we have an existing Task?
ttable = db.scheduler_task
args = '[%s, "%s"]' % (channel_id, function_name)
query = ((ttable.function_name == "msg_parse") & \
(ttable.args == args) & \
(ttable.status.belongs(["RUNNING", "QUEUED", "ALLOCATED"])))
exists = db(query).select(ttable.id,
limitby=(0, 1)).first()
if exists:
return "Parser already enabled"
else:
current.s3task.schedule_task("msg_parse",
args = [channel_id, function_name],
period = 300, # seconds
timeout = 300, # seconds
repeats = 0 # unlimited
)
return "Parser enabled"
# -------------------------------------------------------------------------
@staticmethod
def parser_enable_interactive(r, **attr):
"""
Enable a Parser
- Connect a Parser to a Channel
S3Method for interactive requests
"""
result = current.s3db.msg_parser_enable(r.id)
current.session.confirmation = result
redirect(URL(f="parser"))
# -------------------------------------------------------------------------
@staticmethod
def parser_disable(id):
"""
Disable a Parser
- Disconnect a Parser from a Channel
CLI API for shell scripts & to be called by S3Method
"""
db = current.db
s3db = current.s3db
table = s3db.msg_parser
record = db(table.id == id).select(table.id, # needed for update_record
table.enabled,
table.channel_id,
table.function_name,
limitby=(0, 1),
).first()
if record.enabled:
# Flag it as disabled
record.update_record(enabled = False)
# Do we have an existing Task?
ttable = db.scheduler_task
args = '[%s, "%s"]' % (record.channel_id, record.function_name)
query = ((ttable.function_name == "msg_parse") & \
(ttable.args == args) & \
(ttable.status.belongs(["RUNNING", "QUEUED", "ALLOCATED"])))
exists = db(query).select(ttable.id,
limitby=(0, 1)).first()
if exists:
# Disable all
db(query).update(status="STOPPED")
return "Parser disabled"
else:
return "Parser already disabled"
# -------------------------------------------------------------------------
@staticmethod
def parser_disable_interactive(r, **attr):
"""
Disable a Parser
- Disconnect a Parser from a Channel
S3Method for interactive requests
"""
result = current.s3db.msg_parser_disable(r.id)
current.session.confirmation = result
redirect(URL(f="parser"))
# -------------------------------------------------------------------------
@staticmethod
def msg_parser_onaccept(form):
"""
Process the Enabled Flag
"""
if form.record:
# Update form
# process of changed
if form.record.enabled and not form.vars.enabled:
current.s3db.msg_parser_disable(form.vars.id)
elif form.vars.enabled and not form.record.enabled:
current.s3db.msg_parser_enable(form.vars.id)
else:
# Create form
# Process only if enabled
if form.vars.enabled:
current.s3db.msg_parser_enable(form.vars.id)
# =============================================================================
class S3RSSModel(S3ChannelModel):
"""
RSS channel
"""
names = ("msg_rss_channel",
"msg_rss",
)
def model(self):
T = current.T
define_table = self.define_table
set_method = self.set_method
super_link = self.super_link
# ---------------------------------------------------------------------
# RSS Settings for an account
#
tablename = "msg_rss_channel"
define_table(tablename,
# Instance
super_link("channel_id", "msg_channel"),
Field("name", length=255, unique=True,
label = T("Name"),
),
Field("description",
label = T("Description"),
),
Field("enabled", "boolean",
default = True,
label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("url",
label = T("URL"),
requires = IS_URL(),
),
s3_datetime(label = T("Last Polled"),
writable = False,
),
Field("etag",
label = T("ETag"),
writable = False
),
*s3_meta_fields())
self.configure(tablename,
list_fields = ["name",
"description",
"enabled",
"url",
"date",
"channel_status.status",
],
onaccept = self.msg_channel_onaccept,
super_entity = "msg_channel",
)
set_method("msg", "rss_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "rss_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
set_method("msg", "rss_channel",
method = "poll",
action = self.msg_channel_poll)
# ---------------------------------------------------------------------
# RSS Feed Posts
#
tablename = "msg_rss"
define_table(tablename,
# Instance
super_link("message_id", "msg_message"),
self.msg_channel_id(),
s3_datetime(default="now",
label = T("Published on"),
),
Field("title",
label = T("Title"),
),
Field("body", "text",
label = T("Content"),
),
Field("from_address",
label = T("Link"),
),
# http://pythonhosted.org/feedparser/reference-feed-author_detail.html
Field("author",
label = T("Author"),
),
# http://pythonhosted.org/feedparser/reference-entry-tags.html
Field("tags", "list:string",
label = T("Tags"),
),
self.gis_location_id(),
# Just present for Super Entity
Field("inbound", "boolean",
default = True,
readable = False,
writable = False,
),
*s3_meta_fields())
self.configure(tablename,
deduplicate = self.msg_rss_duplicate,
list_fields = ["channel_id",
"title",
"from_address",
"date",
"body"
],
super_entity = current.s3db.msg_message,
)
# ---------------------------------------------------------------------
return {}
# ---------------------------------------------------------------------
@staticmethod
def msg_rss_duplicate(item):
"""
Import item deduplication, match by link (from_address)
@param item: the S3ImportItem instance
"""
from_address = item.data.get("from_address")
table = item.table
query = (table.from_address == from_address)
duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
if duplicate:
item.id = duplicate.id
item.method = item.METHOD.UPDATE
# =============================================================================
class S3SMSModel(S3Model):
"""
SMS: Short Message Service
These can be received through a number of different gateways
- MCommons
- Modem (@ToDo: Restore this)
- Tropo
- Twilio
"""
names = ("msg_sms",)
def model(self):
#T = current.T
user = current.auth.user
if user and user.organisation_id:
# SMS Messages need to be tagged to their org so that they can be sent through the correct gateway
default = user.organisation_id
else:
default = None
# ---------------------------------------------------------------------
# SMS Messages: InBox & Outbox
#
tablename = "msg_sms"
self.define_table(tablename,
# Instance
self.super_link("message_id", "msg_message"),
self.msg_channel_id(),
self.org_organisation_id(default = default),
s3_datetime(default="now"),
Field("body", "text",
# Allow multi-part SMS
#length = 160,
#label = T("Message"),
),
Field("from_address",
#label = T("Sender"),
),
Field("to_address",
#label = T("To"),
),
Field("inbound", "boolean",
default = False,
#represent = lambda direction: \
# (direction and [T("In")] or \
# [T("Out")])[0],
#label = T("Direction")),
),
# Used e.g. for Clickatell
Field("remote_id",
#label = T("Remote ID"),
),
*s3_meta_fields())
self.configure(tablename,
super_entity = "msg_message",
)
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3SMSOutboundModel(S3Model):
"""
SMS: Short Message Service
- Outbound Channels
These can be sent through a number of different gateways
- Modem
- SMTP
- Tropo
- Web API (inc Clickatell, MCommons, mVaayoo)
"""
names = ("msg_sms_outbound_gateway",
"msg_sms_modem_channel",
"msg_sms_smtp_channel",
"msg_sms_webapi_channel",
)
def model(self):
#T = current.T
configure = self.configure
define_table = self.define_table
settings = current.deployment_settings
# ---------------------------------------------------------------------
# SMS Outbound Gateway
# - select which gateway is in active use for which Organisation/Branch
#
country_code = settings.get_L10n_default_country_code()
tablename = "msg_sms_outbound_gateway"
define_table(tablename,
self.msg_channel_id(
requires = IS_ONE_OF(current.db, "msg_channel.channel_id",
S3Represent(lookup="msg_channel"),
instance_types = ("msg_sms_modem_channel",
"msg_sms_webapi_channel",
"msg_sms_smtp_channel",
),
sort = True,
),
),
#Field("outgoing_sms_handler", length=32,
# requires = IS_IN_SET(current.msg.GATEWAY_OPTS,
# zero = None),
# ),
# Allow selection of different gateways based on Organisation/Branch
self.org_organisation_id(),
# @ToDo: Allow selection of different gateways based on destination Location
#self.gis_location_id(),
Field("default_country_code", "integer",
default = country_code,
),
*s3_meta_fields())
# ---------------------------------------------------------------------
# SMS Modem Channel
#
tablename = "msg_sms_modem_channel"
define_table(tablename,
self.super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("modem_port"),
Field("modem_baud", "integer",
default = 115200,
),
Field("enabled", "boolean",
default = True,
),
Field("max_length", "integer",
default = 160,
),
*s3_meta_fields())
configure(tablename,
super_entity = "msg_channel",
)
# ---------------------------------------------------------------------
# SMS via SMTP Channel
#
tablename = "msg_sms_smtp_channel"
define_table(tablename,
self.super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("address", length=64,
requires = IS_NOT_EMPTY(),
),
Field("subject", length=64),
Field("enabled", "boolean",
default = True,
),
Field("max_length", "integer",
default = 160,
),
*s3_meta_fields())
configure(tablename,
super_entity = "msg_channel",
)
# ---------------------------------------------------------------------
# Settings for Web API services
#
# @ToDo: Simplified dropdown of services which prepopulates entries & provides nice prompts for the config options
# + Advanced mode for raw access to real fields
#
# https://www.twilio.com/docs/api/rest/sending-messages
#
tablename = "msg_sms_webapi_channel"
define_table(tablename,
self.super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("url",
#default = "http://sms1.cardboardfish.com:9001/HTTPSMS?", # Cardboardfish
default = "https://api.clickatell.com/http/sendmsg", # Clickatell
#default = "https://secure.mcommons.com/api/send_message", # Mobile Commons
#default = "https://www.textmagic.com/app/api", # Text Magic
#default = "https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Messages", # Twilio (Untested)
requires = IS_URL(),
),
Field("parameters",
#default = "S=H&UN=yourusername&P=yourpassword&SA=Sahana", # Cardboardfish
default = "user=yourusername&password=yourpassword&api_id=yourapiid", # Clickatell
#default = "campaign_id=yourid", # Mobile Commons
#default = "username=yourusername&password=yourpassword&cmd=send&unicode=1", # Text Magic
#default = "From={RegisteredTelNumber}", # Twilio (Untested)
),
Field("message_variable", "string",
#default = "M", # Cardboardfish
default = "text", # Clickatell, Text Magic
#default = "body", # Mobile Commons
#default = "Body", # Twilio (Untested)
requires = IS_NOT_EMPTY(),
),
Field("to_variable", "string",
#default = "DA", # Cardboardfish
default = "to", # Clickatell
#default = "phone_number", # Mobile Commons
#default = "phone", # Text Magic
#default = "To", # Twilio (Untested)
requires = IS_NOT_EMPTY(),
),
Field("max_length", "integer",
default = 480, # Clickatell concat 3
),
# If using HTTP Auth (e.g. Mobile Commons)
Field("username"),
Field("password"),
Field("enabled", "boolean",
default = True,
),
*s3_meta_fields())
configure(tablename,
super_entity = "msg_channel",
)
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3TropoModel(S3Model):
"""
Tropo can be used to send & receive SMS, Twitter & XMPP
https://www.tropo.com
"""
names = ("msg_tropo_channel",
"msg_tropo_scratch",
)
def model(self):
#T = current.T
define_table = self.define_table
set_method = self.set_method
# ---------------------------------------------------------------------
# Tropo Channels
#
tablename = "msg_tropo_channel"
define_table(tablename,
self.super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("enabled", "boolean",
default = True,
#label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("token_messaging"),
#Field("token_voice"),
*s3_meta_fields())
self.configure(tablename,
super_entity = "msg_channel",
)
set_method("msg", "tropo_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "tropo_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
set_method("msg", "tropo_channel",
method = "poll",
action = self.msg_channel_poll)
# ---------------------------------------------------------------------
# Tropo Scratch pad for outbound messaging
#
tablename = "msg_tropo_scratch"
define_table(tablename,
Field("row_id", "integer"),
Field("message_id", "integer"),
Field("recipient"),
Field("message"),
Field("network"),
)
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3TwilioModel(S3ChannelModel):
"""
Twilio Inbound SMS channel
- for Outbound, use Web API
"""
names = ("msg_twilio_channel",
"msg_twilio_sid",
)
def model(self):
#T = current.T
define_table = self.define_table
set_method = self.set_method
# ---------------------------------------------------------------------
# Twilio Channels
#
tablename = "msg_twilio_channel"
define_table(tablename,
# Instance
self.super_link("channel_id", "msg_channel"),
Field("name"),
Field("description"),
Field("enabled", "boolean",
default = True,
#label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("account_name", length=255, unique=True),
Field("url",
default = \
"https://api.twilio.com/2010-04-01/Accounts"
),
Field("account_sid", length=64,
requires = IS_NOT_EMPTY(),
),
Field("auth_token", "password", length=64,
readable = False,
requires = IS_NOT_EMPTY(),
),
*s3_meta_fields())
self.configure(tablename,
onaccept = self.msg_channel_onaccept,
super_entity = "msg_channel",
)
set_method("msg", "twilio_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "twilio_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
set_method("msg", "twilio_channel",
method = "poll",
action = self.msg_channel_poll)
# ---------------------------------------------------------------------
# Twilio Message extensions
# - store message sid to know which ones we've already downloaded
#
tablename = "msg_twilio_sid"
define_table(tablename,
# Component not Instance
self.msg_message_id(ondelete = "CASCADE"),
Field("sid"),
*s3_meta_fields())
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3TwitterModel(S3Model):
names = ("msg_twitter_channel",
"msg_twitter",
)
def model(self):
T = current.T
db = current.db
configure = self.configure
define_table = self.define_table
set_method = self.set_method
# ---------------------------------------------------------------------
# Twitter Channel
#
password_widget = S3PasswordWidget()
tablename = "msg_twitter_channel"
define_table(tablename,
#Instance
self.super_link("channel_id", "msg_channel"),
# @ToDo: Allow different Twitter accounts for different PEs (Orgs / Teams)
#self.pr_pe_id(),
Field("name",
label = T("Name"),
),
Field("description",
label = T("Description"),
),
Field("enabled", "boolean",
default = True,
label = T("Enabled?"),
represent = s3_yes_no_represent,
),
Field("login", "boolean",
default = False,
label = T("Use for Login?"),
represent = s3_yes_no_represent,
),
Field("twitter_account",
label = T("Twitter Account"),
),
# Get these from https://apps.twitter.com
Field("consumer_key", "password",
label = T("Consumer Key"),
widget = password_widget,
),
Field("consumer_secret", "password",
label = T("Consumer Secret"),
widget = password_widget,
),
Field("access_token", "password",
label = T("Access Token"),
widget = password_widget,
),
Field("access_token_secret", "password",
label = T("Access Token Secret"),
widget = password_widget,
),
*s3_meta_fields())
configure(tablename,
onaccept = self.twitter_channel_onaccept,
#onvalidation = self.twitter_channel_onvalidation
super_entity = "msg_channel",
)
set_method("msg", "twitter_channel",
method = "enable",
action = self.msg_channel_enable_interactive)
set_method("msg", "twitter_channel",
method = "disable",
action = self.msg_channel_disable_interactive)
set_method("msg", "twitter_channel",
method = "poll",
action = self.msg_channel_poll)
# ---------------------------------------------------------------------
# Twitter Messages: InBox & Outbox
#
tablename = "msg_twitter"
define_table(tablename,
# Instance
self.super_link("message_id", "msg_message"),
self.msg_channel_id(),
s3_datetime(default = "now",
label = T("Posted on"),
),
Field("body", length=140,
label = T("Message"),
),
Field("from_address", #notnull=True,
label = T("From"),
represent = self.twitter_represent,
requires = IS_NOT_EMPTY(),
),
Field("to_address",
label = T("To"),
represent = self.twitter_represent,
),
Field("inbound", "boolean",
default = False,
label = T("Direction"),
represent = lambda direction: \
(direction and [T("In")] or \
[T("Out")])[0],
),
Field("msg_id", # Twitter Message ID
readable = False,
writable = False,
),
*s3_meta_fields())
configure(tablename,
list_fields = ["id",
#"priority",
#"category",
"body",
"from_address",
"date",
#"location_id",
],
#orderby = ~table.priority,
super_entity = "msg_message",
)
# ---------------------------------------------------------------------
return {}
# -------------------------------------------------------------------------
@staticmethod
def twitter_represent(nickname, show_link=True):
"""
Represent a Twitter account
"""
if not nickname:
return current.messages["NONE"]
db = current.db
s3db = current.s3db
table = s3db.pr_contact
query = (table.contact_method == "TWITTER") & \
(table.value == nickname)
row = db(query).select(table.pe_id,
limitby=(0, 1)).first()
if row:
repr = s3db.pr_pentity_represent(row.pe_id)
if show_link:
# Assume person
ptable = s3db.pr_person
row = db(ptable.pe_id == row.pe_id).select(ptable.id,
limitby=(0, 1)).first()
if row:
link = URL(c="pr", f="person", args=[row.id])
return A(repr, _href=link)
return repr
else:
return nickname
# -------------------------------------------------------------------------
@staticmethod
def twitter_channel_onaccept(form):
if form.vars.login:
# Ensure only a single account used for Login
current.db(current.s3db.msg_twitter_channel.id != form.vars.id).update(login = False)
# Normal onaccept processing
S3ChannelModel.channel_onaccept(form)
# -------------------------------------------------------------------------
@staticmethod
def twitter_channel_onvalidation(form):
"""
Complete oauth: take tokens from session + pin from form,
and do the 2nd API call to Twitter
"""
T = current.T
session = current.session
settings = current.deployment_settings.msg
s3 = session.s3
form_vars = form.vars
if form_vars.pin and s3.twitter_request_key and s3.twitter_request_secret:
try:
import tweepy
except:
raise HTTP(501, body=T("Can't import tweepy"))
oauth = tweepy.OAuthHandler(settings.twitter_oauth_consumer_key,
settings.twitter_oauth_consumer_secret)
oauth.set_request_token(s3.twitter_request_key,
s3.twitter_request_secret)
try:
oauth.get_access_token(form_vars.pin)
form_vars.oauth_key = oauth.access_token.key
form_vars.oauth_secret = oauth.access_token.secret
twitter = tweepy.API(oauth)
form_vars.twitter_account = twitter.me().screen_name
form_vars.pin = "" # we won't need it anymore
return
except tweepy.TweepError:
session.error = T("Settings were reset because authenticating with Twitter failed")
# Either user asked to reset, or error - clear everything
for k in ["oauth_key", "oauth_secret", "twitter_account"]:
form_vars[k] = None
for k in ["twitter_request_key", "twitter_request_secret"]:
s3[k] = ""
# =============================================================================
class S3TwitterSearchModel(S3ChannelModel):
"""
Twitter Searches
- results can be fed to KeyGraph
https://dev.twitter.com/docs/api/1.1/get/search/tweets
"""
names = ("msg_twitter_search",
"msg_twitter_result",
)
def model(self):
T = current.T
db = current.db
configure = self.configure
define_table = self.define_table
set_method = self.set_method
# ---------------------------------------------------------------------
# Twitter Search Query
#
tablename = "msg_twitter_search"
define_table(tablename,
Field("keywords", "text",
label = T("Keywords"),
),
# @ToDo: Allow setting a Point & Radius for filtering by geocode
#self.gis_location_id(),
Field("lang",
# Set in controller
#default = current.response.s3.language,
label = T("Language"),
),
Field("count", "integer",
default = 100,
label = T("# Results per query"),
),
Field("include_entities", "boolean",
default = False,
label = T("Include Entity Information?"),
represent = s3_yes_no_represent,
comment = DIV(_class="tooltip",
_title="%s|%s" % (T("Entity Information"),
T("This is required if analyzing with KeyGraph."))),
),
# @ToDo: Rename or even move to Component Table
Field("is_processed", "boolean",
default = False,
label = T("Processed with KeyGraph?"),
represent = s3_yes_no_represent,
),
Field("is_searched", "boolean",
default = False,
label = T("Searched?"),
represent = s3_yes_no_represent,
),
*s3_meta_fields())
configure(tablename,
list_fields = ["keywords",
"lang",
"count",
#"include_entities",
],
)
# Reusable Query ID
represent = S3Represent(lookup=tablename, fields=["keywords"])
search_id = S3ReusableField("search_id", "reference %s" % tablename,
label = T("Search Query"),
ondelete = "CASCADE",
represent = represent,
requires = IS_EMPTY_OR(
IS_ONE_OF_EMPTY(db, "msg_twitter_search.id")
),
)
set_method("msg", "twitter_search",
method = "poll",
action = self.twitter_search_poll)
set_method("msg", "twitter_search",
method = "keygraph",
action = self.twitter_keygraph)
set_method("msg", "twitter_result",
method = "timeline",
action = self.twitter_timeline)
# ---------------------------------------------------------------------
# Twitter Search Results
#
# @ToDo: Store the places mentioned in the Tweet as linked Locations
#
tablename = "msg_twitter_result"
define_table(tablename,
# Instance
self.super_link("message_id", "msg_message"),
# Just present for Super Entity
#self.msg_channel_id(),
search_id(),
s3_datetime(default="now",
label = T("Tweeted on"),
),
Field("tweet_id",
label = T("Tweet ID")),
Field("lang",
label = T("Language")),
Field("from_address",
label = T("Tweeted by")),
Field("body",
label = T("Tweet")),
# @ToDo: Populate from Parser
#Field("category",
# writable = False,
# label = T("Category"),
# ),
#Field("priority", "integer",
# writable = False,
# label = T("Priority"),
# ),
self.gis_location_id(),
# Just present for Super Entity
#Field("inbound", "boolean",
# default = True,
# readable = False,
# writable = False,
# ),
*s3_meta_fields())
configure(tablename,
list_fields = [#"category",
#"priority",
"body",
"from_address",
"date",
"location_id",
],
#orderby=~table.priority,
super_entity = "msg_message",
)
# ---------------------------------------------------------------------
return {}
# -----------------------------------------------------------------------------
@staticmethod
def twitter_search_poll(r, **attr):
"""
Perform a Search of Twitter
S3Method for interactive requests
"""
id = r.id
tablename = r.tablename
current.s3task.async("msg_twitter_search", args=[id])
current.session.confirmation = \
current.T("The search request has been submitted, so new messages should appear shortly - refresh to see them")
# Filter results to this Search
redirect(URL(f="twitter_result",
vars={"~.search_id": id}))
# -----------------------------------------------------------------------------
@staticmethod
def twitter_keygraph(r, **attr):
"""
Prcoess Search Results with KeyGraph
S3Method for interactive requests
"""
tablename = r.tablename
current.s3task.async("msg_process_keygraph", args=[r.id])
current.session.confirmation = \
current.T("The search results are now being processed with KeyGraph")
# @ToDo: Link to KeyGraph results
redirect(URL(f="twitter_result"))
# =============================================================================
@staticmethod
def twitter_timeline(r, **attr):
"""
Display the Tweets on a Simile Timeline
http://www.simile-widgets.org/wiki/Reference_Documentation_for_Timeline
"""
if r.representation == "html" and r.name == "twitter_result":
response = current.response
s3 = response.s3
appname = r.application
# Add core Simile Code
s3.scripts.append("/%s/static/scripts/simile/timeline/timeline-api.js" % appname)
# Add our control script
if s3.debug:
s3.scripts.append("/%s/static/scripts/S3/s3.timeline.js" % appname)
else:
s3.scripts.append("/%s/static/scripts/S3/s3.timeline.min.js" % appname)
# Add our data
# @ToDo: Make this the initial data & then collect extra via REST with a stylesheet
# add in JS using S3.timeline.eventSource.addMany(events) where events is a []
if r.record:
# Single record
rows = [r.record]
else:
# Multiple records
# @ToDo: Load all records & sort to closest in time
# http://stackoverflow.com/questions/7327689/how-to-generate-a-sequence-of-future-datetimes-in-python-and-determine-nearest-d
rows = r.resource.select(["date", "body"], limit=2000, as_rows=True)
data = {"dateTimeFormat": "iso8601",
}
now = r.utcnow
tl_start = tl_end = now
events = []
import re
for row in rows:
# Dates
start = row.date or ""
if start:
if start < tl_start:
tl_start = start
if start > tl_end:
tl_end = start
start = start.isoformat()
title = (re.sub(r"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9]+)|RT", "", row.body))
if len(title) > 30:
title = title[:30]
events.append({"start": start,
"title": title,
"description": row.body,
})
data["events"] = events
data = json.dumps(data, separators=SEPARATORS)
code = "".join((
'''S3.timeline.data=''', data, '''
S3.timeline.tl_start="''', tl_start.isoformat(), '''"
S3.timeline.tl_end="''', tl_end.isoformat(), '''"
S3.timeline.now="''', now.isoformat(), '''"
'''))
# Control our code in static/scripts/S3/s3.timeline.js
s3.js_global.append(code)
# Create the DIV
item = DIV(_id="s3timeline", _class="s3-timeline")
output = dict(item=item)
# Maintain RHeader for consistency
if attr.get("rheader"):
rheader = attr["rheader"](r)
if rheader:
output["rheader"] = rheader
output["title"] = current.T("Twitter Timeline")
response.view = "timeline.html"
return output
else:
r.error(405, current.ERROR.BAD_METHOD)
# =============================================================================
class S3XFormsModel(S3Model):
"""
XForms are used by the ODK Collect mobile client
http://eden.sahanafoundation.org/wiki/BluePrint/Mobile#Android
"""
names = ("msg_xforms_store",)
def model(self):
#T = current.T
# ---------------------------------------------------------------------
# SMS store for persistence and scratch pad for combining incoming xform chunks
tablename = "msg_xforms_store"
self.define_table(tablename,
Field("sender", length=20),
Field("fileno", "integer"),
Field("totalno", "integer"),
Field("partno", "integer"),
Field("message", length=160)
)
# ---------------------------------------------------------------------
return {}
# =============================================================================
class S3BaseStationModel(S3Model):
"""
Base Stations (Cell Towers) are a type of Site
@ToDo: Calculate Coverage from Antenna Height, Radio Power and Terrain
- see RadioMobile
"""
names = ("msg_basestation",)
def model(self):
T = current.T
# ---------------------------------------------------------------------
# Base Stations (Cell Towers)
#
if current.deployment_settings.get_msg_basestation_code_unique():
db = current.db
code_unique = IS_EMPTY_OR(IS_NOT_IN_DB(db, "msg_basestation.code"))
else:
code_unique = None
tablename = "msg_basestation"
self.define_table(tablename,
self.super_link("site_id", "org_site"),
Field("name", notnull=True,
length=64, # Mayon Compatibility
label = T("Name"),
),
Field("code", length=10, # Mayon compatibility
label = T("Code"),
requires = code_unique,
),
self.org_organisation_id(
label = T("Operator"),
requires = self.org_organisation_requires(required=True,
updateable=True),
#widget=S3OrganisationAutocompleteWidget(default_from_profile=True),
),
self.gis_location_id(),
s3_comments(),
*s3_meta_fields())
# CRUD strings
current.response.s3.crud_strings[tablename] = Storage(
label_create=T("Create Base Station"),
title_display=T("Base Station Details"),
title_list=T("Base Stations"),
title_update=T("Edit Base Station"),
title_upload=T("Import Base Stations"),
title_map=T("Map of Base Stations"),
label_list_button=T("List Base Stations"),
label_delete_button=T("Delete Base Station"),
msg_record_created=T("Base Station added"),
msg_record_modified=T("Base Station updated"),
msg_record_deleted=T("Base Station deleted"),
msg_list_empty=T("No Base Stations currently registered"))
self.configure(tablename,
deduplicate = self.msg_basestation_duplicate,
super_entity = "org_site",
)
# ---------------------------------------------------------------------
# Pass names back to global scope (s3.*)
#
return {}
# ---------------------------------------------------------------------
@staticmethod
def msg_basestation_duplicate(item):
"""
Import item deduplication, match by name
(Adding location_id doesn't seem to be a good idea)
@param item: the S3ImportItem instance
"""
name = item.data.get("name")
table = item.table
query = (table.name.lower() == name.lower())
#location_id = None
# if "location_id" in item.data:
# location_id = item.data.location_id
## This doesn't find deleted records:
# query = query & (table.location_id == location_id)
duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
# if duplicate is None and location_id:
## Search for deleted basestations with this name
# query = (table.name.lower() == name.lower()) & \
# (table.deleted == True)
# row = db(query).select(table.id, table.deleted_fk,
# limitby=(0, 1)).first()
# if row:
# fkeys = json.loads(row.deleted_fk)
# if "location_id" in fkeys and \
# str(fkeys["location_id"]) == str(location_id):
# duplicate = row
if duplicate:
item.id = duplicate.id
item.method = item.METHOD.UPDATE
# END =========================================================================
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
428,
11326,
6738,
662,
848,
3194,
385,
7407,
5822,
339,
768,
7307,
26,
8937,
13,
7806,
334,
67,
9,
428,
11326,
6738,
2290,
2752,
272,
768,
1682,
26,
10697,
339,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
272,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
272,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
272,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
272,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
272,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
272,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
272,
3704,
26,
339,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
272,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
339,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
272,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
272,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
272,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
272,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
272,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
272,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
272,
5010,
13198,
1621,
2334,
4141,
14,
199,
624,
199,
199,
363,
452,
363,
275,
1689,
51,
19,
5358,
1685,
401,
1779,
298,
51,
19,
2209,
1685,
401,
1779,
298,
51,
19,
2209,
22662,
1685,
401,
1779,
298,
51,
19,
7035,
1685,
401,
1779,
298,
51,
19,
13414,
2706,
1685,
401,
1779,
298,
51,
19,
45,
5150,
4654,
1685,
401,
1779,
298,
51,
19,
17412,
1685,
401,
1779,
298,
51,
19,
22786,
1685,
401,
1779,
298,
51,
19,
51,
3053,
1685,
401,
1779,
298,
51,
19,
51,
3053,
2204,
3556,
1685,
401,
1779,
298,
51,
19,
52,
293,
555,
1685,
401,
1779,
298,
51,
19,
22879,
23533,
1685,
401,
1779,
298,
51,
19,
24540,
1685,
401,
1779,
298,
51,
19,
24540,
5278,
1685,
401,
1779,
298,
51,
19,
56,
26028,
1685,
401,
1779,
298,
51,
19,
1563,
8517,
1685,
401,
1779,
776,
199,
199,
504,
26752,
492,
627,
199,
504,
26752,
14,
3494,
492,
10533,
199,
504,
2508,
83,
19,
492,
627,
199,
199,
3,
3599,
2442,
4840,
2644,
199,
899,
4014,
19033,
275,
334,
401,
401,
7244,
531,
199,
199,
3,
26237,
199,
533,
428,
19,
5358,
1685,
8,
51,
19,
1685,
304,
272,
408,
267,
3194,
385,
7407,
17270,
83,
267,
446,
1006,
1010,
3556,
1253,
6219,
3556,
9245,
367,
3788,
787,
4454,
402,
642,
881,
1613,
13,
4502,
272,
408,
339,
1561,
275,
1689,
1328,
63,
2775,
401,
1467,
298,
1328,
63,
2775,
63,
3097,
401,
1467,
298,
1328,
63,
2775,
63,
1205,
401,
1467,
298,
1328,
63,
2775,
63,
344,
401,
1467,
298,
1328,
63,
2775,
63,
4296,
401,
1467,
298,
1328,
63,
2775,
63,
5993,
401,
1467,
298,
1328,
63,
2775,
63,
4296,
63,
13543,
401,
1467,
298,
1328,
63,
2775,
63,
5993,
63,
13543,
401,
1467,
298,
1328,
63,
2775,
63,
265,
5694,
401,
1467,
776,
339,
347,
1402,
8,
277,
304,
398,
377,
275,
1453,
14,
52,
267,
1592,
275,
1453,
14,
697,
398,
5627,
63,
1224,
275,
291,
14,
4640,
63,
1224,
398,
22526,
267,
327,
17897,
4642,
26,
1499,
63,
2775,
267,
327,
267,
3623,
63,
1313,
275,
10533,
8,
1328,
63,
2123,
63,
2775,
275,
377,
480,
7035,
334,
607,
3556,
13185,
1816,
1499,
63,
16652,
63,
2775,
275,
377,
480,
13414,
2706,
1288,
1816,
1499,
63,
77,
2330,
83,
63,
2775,
275,
377,
480,
27245,
7046,
4654,
334,
607,
3556,
13185,
1816,
1499,
63,
13614,
63,
2775,
275,
377,
480,
22786,
16261,
1288,
1816,
1499,
63,
18751,
63,
31576,
63,
2775,
275,
377,
480,
51,
3053,
4900,
77,
1288,
1816,
1499,
63,
18751,
63,
2520,
1246,
63,
2775,
275,
377,
480,
51,
3053,
6001,
3735,
334,
2204,
3556,
13185,
1816,
1499,
63,
18751,
63,
15592,
63,
2775,
275,
377,
480,
51,
3053,
4799,
19810,
334,
2204,
3556,
13185,
1816,
1499,
63,
1374,
555,
63,
2775,
275,
377,
480,
52,
293,
555,
1288,
1816,
1499,
63,
8122,
23533,
63,
2775,
275,
377,
480,
22879,
23533,
334,
607,
3556,
13185,
1816,
1499,
63,
13746,
63,
2775,
275,
377,
480,
24540,
1288,
1816,
776,
398,
20283,
275,
298,
1328,
63,
2775,
2,
267,
291,
14,
4792,
63,
4502,
8,
10983,
12,
298,
2775,
63,
344,
401,
2079,
3623,
63,
1313,
12,
2079,
5024,
480,
354,
401,
1816,
327,
1302,
275,
377,
480,
985,
1288,
1816,
2318,
2079,
5024,
480,
1802,
401,
1816,
327,
1302,
275,
377,
480,
5831,
1288,
1816,
2318,
2079,
5024,
480,
3827,
401,
298,
4871,
401,
1816,
849,
275,
715,
12,
1816,
327,
1302,
275,
377,
480,
6589,
18582,
1816,
327,
13063,
275,
308,
19,
63,
5066,
63,
889,
63,
13063,
12,
1816,
2318,
2079,
327,
768,
1378,
2585,
26,
1010,
10188,
3775,
3623,
883,
506,
1202,
367,
1010,
3556,
503,
6219,
3556,
2079,
327,
792,
480,
26108,
401,
298,
4871,
401,
2079,
327,
420,
1768,
275,
377,
480,
607,
3556,
31,
8150,
2079,
327,
792,
480,
548,
3556,
401,
298,
4871,
401,
2079,
327,
420,
1768,
275,
377,
480,
2204,
3556,
31,
8150,
2079,
776,
398,
327,
768,
11396,
26,
1852,
9617,
63,
1224,
267,
1817,
275,
1592,
59,
10983,
61,
267,
1817,
14,
842,
63,
466,
14,
11875,
275,
715,
398,
327,
799,
14418,
5024,
267,
3623,
63,
344,
275,
428,
19,
497,
14418,
792,
480,
2775,
63,
344,
401,
298,
4443,
450,
83,
2,
450,
20283,
12,
3660,
1768,
275,
377,
480,
5358,
1288,
3660,
16549,
275,
298,
3597,
5962,
401,
3660,
2954,
275,
428,
19,
10755,
8,
3892,
29,
10983,
395,
3660,
5074,
275,
2281,
63,
13993,
63,
726,
8,
3147,
2281,
63,
4817,
63,
3359,
63,
13993,
8,
697,
12,
298,
1328,
63,
2775,
14,
344,
8150,
3660,
776,
398,
291,
14,
525,
63,
4608,
8,
10983,
12,
1169,
1499,
63,
2775,
63,
1205
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
428,
11326,
6738,
662,
848,
3194,
385,
7407,
5822,
339,
768,
7307,
26,
8937,
13,
7806,
334,
67,
9,
428,
11326,
6738,
2290,
2752,
272,
768,
1682,
26,
10697,
339,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
272,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
272,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
272,
10588,
12,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
272,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
272,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
272,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
272,
3704,
26,
339,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
272,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
339,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
272,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
272,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
272,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
272,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
272,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
272,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
272,
5010,
13198,
1621,
2334,
4141,
14,
199,
624,
199,
199,
363,
452,
363,
275,
1689,
51,
19,
5358,
1685,
401,
1779,
298,
51,
19,
2209,
1685,
401,
1779,
298,
51,
19,
2209,
22662,
1685,
401,
1779,
298,
51,
19,
7035,
1685,
401,
1779,
298,
51,
19,
13414,
2706,
1685,
401,
1779,
298,
51,
19,
45,
5150,
4654,
1685,
401,
1779,
298,
51,
19,
17412,
1685,
401,
1779,
298,
51,
19,
22786,
1685,
401,
1779,
298,
51,
19,
51,
3053,
1685,
401,
1779,
298,
51,
19,
51,
3053,
2204,
3556,
1685,
401,
1779,
298,
51,
19,
52,
293,
555,
1685,
401,
1779,
298,
51,
19,
22879,
23533,
1685,
401,
1779,
298,
51,
19,
24540,
1685,
401,
1779,
298,
51,
19,
24540,
5278,
1685,
401,
1779,
298,
51,
19,
56,
26028,
1685,
401,
1779,
298,
51,
19,
1563,
8517,
1685,
401,
1779,
776,
199,
199,
504,
26752,
492,
627,
199,
504,
26752,
14,
3494,
492,
10533,
199,
504,
2508,
83,
19,
492,
627,
199,
199,
3,
3599,
2442,
4840,
2644,
199,
899,
4014,
19033,
275,
334,
401,
401,
7244,
531,
199,
199,
3,
26237,
199,
533,
428,
19,
5358,
1685,
8,
51,
19,
1685,
304,
272,
408,
267,
3194,
385,
7407,
17270,
83,
267,
446,
1006,
1010,
3556,
1253,
6219,
3556,
9245,
367,
3788,
787,
4454,
402,
642,
881,
1613,
13,
4502,
272,
408,
339,
1561,
275,
1689,
1328,
63,
2775,
401,
1467,
298,
1328,
63,
2775,
63,
3097,
401,
1467,
298,
1328,
63,
2775,
63,
1205,
401,
1467,
298,
1328,
63,
2775,
63,
344,
401,
1467,
298,
1328,
63,
2775,
63,
4296,
401,
1467,
298,
1328,
63,
2775,
63,
5993,
401,
1467,
298,
1328,
63,
2775,
63,
4296,
63,
13543,
401,
1467,
298,
1328,
63,
2775,
63,
5993,
63,
13543,
401,
1467,
298,
1328,
63,
2775,
63,
265,
5694,
401,
1467,
776,
339,
347,
1402,
8,
277,
304,
398,
377,
275,
1453,
14,
52,
267,
1592,
275,
1453,
14,
697,
398,
5627,
63,
1224,
275,
291,
14,
4640,
63,
1224,
398,
22526,
267,
327,
17897,
4642,
26,
1499,
63,
2775,
267,
327,
267,
3623,
63,
1313,
275,
10533,
8,
1328,
63,
2123,
63,
2775,
275,
377,
480,
7035,
334,
607,
3556,
13185,
1816,
1499,
63,
16652,
63,
2775,
275,
377,
480,
13414,
2706,
1288,
1816,
1499,
63,
77,
2330,
83,
63,
2775,
275,
377,
480,
27245,
7046,
4654,
334,
607,
3556,
13185,
1816,
1499,
63,
13614,
63,
2775,
275,
377,
480,
22786,
16261,
1288,
1816,
1499,
63,
18751,
63,
31576,
63,
2775,
275,
377,
480,
51,
3053,
4900,
77,
1288,
1816,
1499,
63,
18751,
63,
2520,
1246,
63,
2775,
275,
377,
480,
51,
3053,
6001,
3735,
334,
2204,
3556,
13185,
1816,
1499,
63,
18751,
63,
15592,
63,
2775,
275,
377,
480,
51,
3053,
4799,
19810,
334,
2204,
3556,
13185,
1816,
1499,
63,
1374,
555,
63,
2775,
275,
377,
480,
52,
293,
555,
1288,
1816,
1499,
63,
8122,
23533,
63,
2775,
275,
377,
480,
22879,
23533,
334,
607,
3556,
13185,
1816,
1499,
63,
13746,
63,
2775,
275,
377,
480,
24540,
1288,
1816,
776,
398,
20283,
275,
298,
1328,
63,
2775,
2,
267,
291,
14,
4792,
63,
4502,
8,
10983,
12,
298,
2775,
63,
344,
401,
2079,
3623,
63,
1313,
12,
2079,
5024,
480,
354,
401,
1816,
327,
1302,
275,
377,
480,
985,
1288,
1816,
2318,
2079,
5024,
480,
1802,
401,
1816,
327,
1302,
275,
377,
480,
5831,
1288,
1816,
2318,
2079,
5024,
480,
3827,
401,
298,
4871,
401,
1816,
849,
275,
715,
12,
1816,
327,
1302,
275,
377,
480,
6589,
18582,
1816,
327,
13063,
275,
308,
19,
63,
5066,
63,
889,
63,
13063,
12,
1816,
2318,
2079,
327,
768,
1378,
2585,
26,
1010,
10188,
3775,
3623,
883,
506,
1202,
367,
1010,
3556,
503,
6219,
3556,
2079,
327,
792,
480,
26108,
401,
298,
4871,
401,
2079,
327,
420,
1768,
275,
377,
480,
607,
3556,
31,
8150,
2079,
327,
792,
480,
548,
3556,
401,
298,
4871,
401,
2079,
327,
420,
1768,
275,
377,
480,
2204,
3556,
31,
8150,
2079,
776,
398,
327,
768,
11396,
26,
1852,
9617,
63,
1224,
267,
1817,
275,
1592,
59,
10983,
61,
267,
1817,
14,
842,
63,
466,
14,
11875,
275,
715,
398,
327,
799,
14418,
5024,
267,
3623,
63,
344,
275,
428,
19,
497,
14418,
792,
480,
2775,
63,
344,
401,
298,
4443,
450,
83,
2,
450,
20283,
12,
3660,
1768,
275,
377,
480,
5358,
1288,
3660,
16549,
275,
298,
3597,
5962,
401,
3660,
2954,
275,
428,
19,
10755,
8,
3892,
29,
10983,
395,
3660,
5074,
275,
2281,
63,
13993,
63,
726,
8,
3147,
2281,
63,
4817,
63,
3359,
63,
13993,
8,
697,
12,
298,
1328,
63,
2775,
14,
344,
8150,
3660,
776,
398,
291,
14,
525,
63,
4608,
8,
10983,
12,
1169,
1499,
63,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
1,
1,
1,
1,
1,
1
] |
liamgh/liamgreenhughes-sl4a-tf101
|
python/src/Modules/cgen.py
|
44
|
15363
|
########################################################################
# Copyright (c) 2000, BeOpen.com.
# Copyright (c) 1995-2000, Corporation for National Research Initiatives.
# Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
# All rights reserved.
#
# See the file "Misc/COPYRIGHT" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
########################################################################
# Python script to parse cstubs file for gl and generate C stubs.
# usage: python cgen.py <cstubs >glmodule.c
#
# NOTE: You must first make a python binary without the "GL" option
# before you can run this, when building Python for the first time.
# See comments in the Makefile.
#
# XXX BUG return arrays generate wrong code
# XXX need to change error returns into gotos to free mallocked arrays
from warnings import warnpy3k
warnpy3k("the cgen module has been removed in Python 3.0", stacklevel=2)
del warnpy3k
import string
import sys
# Function to print to stderr
#
def err(*args):
savestdout = sys.stdout
try:
sys.stdout = sys.stderr
for i in args:
print i,
print
finally:
sys.stdout = savestdout
# The set of digits that form a number
#
digits = '0123456789'
# Function to extract a string of digits from the front of the string.
# Returns the leading string of digits and the remaining string.
# If no number is found, returns '' and the original string.
#
def getnum(s):
n = ''
while s and s[0] in digits:
n = n + s[0]
s = s[1:]
return n, s
# Function to check if a string is a number
#
def isnum(s):
if not s: return False
for c in s:
if not c in digits: return False
return True
# Allowed function return types
#
return_types = ['void', 'short', 'long']
# Allowed function argument types
#
arg_types = ['char', 'string', 'short', 'u_short', 'float', 'long', 'double']
# Need to classify arguments as follows
# simple input variable
# simple output variable
# input array
# output array
# input giving size of some array
#
# Array dimensions can be specified as follows
# constant
# argN
# constant * argN
# retval
# constant * retval
#
# The dimensions given as constants * something are really
# arrays of points where points are 2- 3- or 4-tuples
#
# We have to consider three lists:
# python input arguments
# C stub arguments (in & out)
# python output arguments (really return values)
#
# There is a mapping from python input arguments to the input arguments
# of the C stub, and a further mapping from C stub arguments to the
# python return values
# Exception raised by checkarg() and generate()
#
arg_error = 'bad arg'
# Function to check one argument.
# Arguments: the type and the arg "name" (really mode plus subscript).
# Raises arg_error if something's wrong.
# Return type, mode, factor, rest of subscript; factor and rest may be empty.
#
def checkarg(type, arg):
#
# Turn "char *x" into "string x".
#
if type == 'char' and arg[0] == '*':
type = 'string'
arg = arg[1:]
#
# Check that the type is supported.
#
if type not in arg_types:
raise arg_error, ('bad type', type)
if type[:2] == 'u_':
type = 'unsigned ' + type[2:]
#
# Split it in the mode (first character) and the rest.
#
mode, rest = arg[:1], arg[1:]
#
# The mode must be 's' for send (= input) or 'r' for return argument.
#
if mode not in ('r', 's'):
raise arg_error, ('bad arg mode', mode)
#
# Is it a simple argument: if so, we are done.
#
if not rest:
return type, mode, '', ''
#
# Not a simple argument; must be an array.
# The 'rest' must be a subscript enclosed in [ and ].
# The subscript must be one of the following forms,
# otherwise we don't handle it (where N is a number):
# N
# argN
# retval
# N*argN
# N*retval
#
if rest[:1] <> '[' or rest[-1:] <> ']':
raise arg_error, ('subscript expected', rest)
sub = rest[1:-1]
#
# Is there a leading number?
#
num, sub = getnum(sub)
if num:
# There is a leading number
if not sub:
# The subscript is just a number
return type, mode, num, ''
if sub[:1] == '*':
# There is a factor prefix
sub = sub[1:]
else:
raise arg_error, ('\'*\' expected', sub)
if sub == 'retval':
# size is retval -- must be a reply argument
if mode <> 'r':
raise arg_error, ('non-r mode with [retval]', mode)
elif not isnum(sub) and (sub[:3] <> 'arg' or not isnum(sub[3:])):
raise arg_error, ('bad subscript', sub)
#
return type, mode, num, sub
# List of functions for which we have generated stubs
#
functions = []
# Generate the stub for the given function, using the database of argument
# information build by successive calls to checkarg()
#
def generate(type, func, database):
#
# Check that we can handle this case:
# no variable size reply arrays yet
#
n_in_args = 0
n_out_args = 0
#
for a_type, a_mode, a_factor, a_sub in database:
if a_mode == 's':
n_in_args = n_in_args + 1
elif a_mode == 'r':
n_out_args = n_out_args + 1
else:
# Can't happen
raise arg_error, ('bad a_mode', a_mode)
if (a_mode == 'r' and a_sub) or a_sub == 'retval':
err('Function', func, 'too complicated:',
a_type, a_mode, a_factor, a_sub)
print '/* XXX Too complicated to generate code for */'
return
#
functions.append(func)
#
# Stub header
#
print
print 'static PyObject *'
print 'gl_' + func + '(self, args)'
print '\tPyObject *self;'
print '\tPyObject *args;'
print '{'
#
# Declare return value if any
#
if type <> 'void':
print '\t' + type, 'retval;'
#
# Declare arguments
#
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
print '\t' + a_type,
brac = ket = ''
if a_sub and not isnum(a_sub):
if a_factor:
brac = '('
ket = ')'
print brac + '*',
print 'arg' + repr(i+1) + ket,
if a_sub and isnum(a_sub):
print '[', a_sub, ']',
if a_factor:
print '[', a_factor, ']',
print ';'
#
# Find input arguments derived from array sizes
#
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
if a_mode == 's' and a_sub[:3] == 'arg' and isnum(a_sub[3:]):
# Sending a variable-length array
n = eval(a_sub[3:])
if 1 <= n <= len(database):
b_type, b_mode, b_factor, b_sub = database[n-1]
if b_mode == 's':
database[n-1] = b_type, 'i', a_factor, repr(i)
n_in_args = n_in_args - 1
#
# Assign argument positions in the Python argument list
#
in_pos = []
i_in = 0
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
if a_mode == 's':
in_pos.append(i_in)
i_in = i_in + 1
else:
in_pos.append(-1)
#
# Get input arguments
#
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
if a_type[:9] == 'unsigned ':
xtype = a_type[9:]
else:
xtype = a_type
if a_mode == 'i':
#
# Implicit argument;
# a_factor is divisor if present,
# a_sub indicates which arg (`database index`)
#
j = eval(a_sub)
print '\tif',
print '(!geti' + xtype + 'arraysize(args,',
print repr(n_in_args) + ',',
print repr(in_pos[j]) + ',',
if xtype <> a_type:
print '('+xtype+' *)',
print '&arg' + repr(i+1) + '))'
print '\t\treturn NULL;'
if a_factor:
print '\targ' + repr(i+1),
print '= arg' + repr(i+1),
print '/', a_factor + ';'
elif a_mode == 's':
if a_sub and not isnum(a_sub):
# Allocate memory for varsize array
print '\tif ((arg' + repr(i+1), '=',
if a_factor:
print '('+a_type+'(*)['+a_factor+'])',
print 'PyMem_NEW(' + a_type, ',',
if a_factor:
print a_factor, '*',
print a_sub, ')) == NULL)'
print '\t\treturn PyErr_NoMemory();'
print '\tif',
if a_factor or a_sub: # Get a fixed-size array array
print '(!geti' + xtype + 'array(args,',
print repr(n_in_args) + ',',
print repr(in_pos[i]) + ',',
if a_factor: print a_factor,
if a_factor and a_sub: print '*',
if a_sub: print a_sub,
print ',',
if (a_sub and a_factor) or xtype <> a_type:
print '('+xtype+' *)',
print 'arg' + repr(i+1) + '))'
else: # Get a simple variable
print '(!geti' + xtype + 'arg(args,',
print repr(n_in_args) + ',',
print repr(in_pos[i]) + ',',
if xtype <> a_type:
print '('+xtype+' *)',
print '&arg' + repr(i+1) + '))'
print '\t\treturn NULL;'
#
# Begin of function call
#
if type <> 'void':
print '\tretval =', func + '(',
else:
print '\t' + func + '(',
#
# Argument list
#
for i in range(len(database)):
if i > 0: print ',',
a_type, a_mode, a_factor, a_sub = database[i]
if a_mode == 'r' and not a_factor:
print '&',
print 'arg' + repr(i+1),
#
# End of function call
#
print ');'
#
# Free varsize arrays
#
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
if a_mode == 's' and a_sub and not isnum(a_sub):
print '\tPyMem_DEL(arg' + repr(i+1) + ');'
#
# Return
#
if n_out_args:
#
# Multiple return values -- construct a tuple
#
if type <> 'void':
n_out_args = n_out_args + 1
if n_out_args == 1:
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
if a_mode == 'r':
break
else:
raise arg_error, 'expected r arg not found'
print '\treturn',
print mkobject(a_type, 'arg' + repr(i+1)) + ';'
else:
print '\t{ PyObject *v = PyTuple_New(',
print n_out_args, ');'
print '\t if (v == NULL) return NULL;'
i_out = 0
if type <> 'void':
print '\t PyTuple_SetItem(v,',
print repr(i_out) + ',',
print mkobject(type, 'retval') + ');'
i_out = i_out + 1
for i in range(len(database)):
a_type, a_mode, a_factor, a_sub = database[i]
if a_mode == 'r':
print '\t PyTuple_SetItem(v,',
print repr(i_out) + ',',
s = mkobject(a_type, 'arg' + repr(i+1))
print s + ');'
i_out = i_out + 1
print '\t return v;'
print '\t}'
else:
#
# Simple function return
# Return None or return value
#
if type == 'void':
print '\tPy_INCREF(Py_None);'
print '\treturn Py_None;'
else:
print '\treturn', mkobject(type, 'retval') + ';'
#
# Stub body closing brace
#
print '}'
# Subroutine to return a function call to mknew<type>object(<arg>)
#
def mkobject(type, arg):
if type[:9] == 'unsigned ':
type = type[9:]
return 'mknew' + type + 'object((' + type + ') ' + arg + ')'
return 'mknew' + type + 'object(' + arg + ')'
defined_archs = []
# usage: cgen [ -Dmach ... ] [ file ]
for arg in sys.argv[1:]:
if arg[:2] == '-D':
defined_archs.append(arg[2:])
else:
# Open optional file argument
sys.stdin = open(arg, 'r')
# Input line number
lno = 0
# Input is divided in two parts, separated by a line containing '%%'.
# <part1> -- literally copied to stdout
# <part2> -- stub definitions
# Variable indicating the current input part.
#
part = 1
# Main loop over the input
#
while 1:
try:
line = raw_input()
except EOFError:
break
#
lno = lno+1
words = string.split(line)
#
if part == 1:
#
# In part 1, copy everything literally
# except look for a line of just '%%'
#
if words == ['%%']:
part = part + 1
else:
#
# Look for names of manually written
# stubs: a single percent followed by the name
# of the function in Python.
# The stub name is derived by prefixing 'gl_'.
#
if words and words[0][0] == '%':
func = words[0][1:]
if (not func) and words[1:]:
func = words[1]
if func:
functions.append(func)
else:
print line
continue
if not words:
continue # skip empty line
elif words[0] == 'if':
# if XXX rest
# if !XXX rest
if words[1][0] == '!':
if words[1][1:] in defined_archs:
continue
elif words[1] not in defined_archs:
continue
words = words[2:]
if words[0] == '#include':
print line
elif words[0][:1] == '#':
pass # ignore comment
elif words[0] not in return_types:
err('Line', lno, ': bad return type :', words[0])
elif len(words) < 2:
err('Line', lno, ': no funcname :', line)
else:
if len(words) % 2 <> 0:
err('Line', lno, ': odd argument list :', words[2:])
else:
database = []
try:
for i in range(2, len(words), 2):
x = checkarg(words[i], words[i+1])
database.append(x)
print
print '/*',
for w in words: print w,
print '*/'
generate(words[0], words[1], database)
except arg_error, msg:
err('Line', lno, ':', msg)
print
print 'static struct PyMethodDef gl_methods[] = {'
for func in functions:
print '\t{"' + func + '", gl_' + func + '},'
print '\t{NULL, NULL} /* Sentinel */'
print '};'
print
print 'void'
print 'initgl()'
print '{'
print '\t(void) Py_InitModule("gl", gl_methods);'
print '}'
|
apache-2.0
|
[
3949,
199,
3,
1898,
334,
67,
9,
12293,
12,
6423,
4299,
14,
957,
14,
199,
3,
1898,
334,
67,
9,
9013,
21,
13,
8269,
12,
11098,
367,
20548,
26993,
21412,
10661,
14,
199,
3,
1898,
334,
67,
9,
9013,
16,
13,
7155,
21,
12,
428,
280,
335,
1337,
16593,
24508,
280,
15820,
445,
18626,
453,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
1666,
314,
570,
298,
29926,
15,
32324,
5716,
2,
367,
2556,
641,
4503,
436,
199,
3,
295,
4972,
402,
642,
570,
12,
436,
367,
282,
8990,
540,
1634,
11727,
2990,
14,
199,
3949,
199,
199,
3,
2018,
2884,
370,
2198,
286,
8957,
570,
367,
6482,
436,
3550,
445,
22312,
14,
199,
3,
4503,
26,
2366,
286,
2268,
14,
647,
665,
67,
8957,
690,
3528,
578,
14,
67,
199,
3,
199,
3,
6944,
26,
2047,
221,
1471,
1642,
1852,
282,
2366,
3366,
1928,
314,
298,
2226,
2,
945,
199,
3,
755,
2544,
1265,
883,
1255,
642,
12,
1380,
10015,
2018,
367,
314,
1642,
900,
14,
199,
3,
755,
1666,
6786,
315,
314,
20618,
14,
199,
3,
199,
3,
5787,
699,
10134,
372,
6572,
3550,
6835,
1233,
199,
3,
5787,
1929,
370,
1570,
1125,
2529,
1901,
4788,
736,
370,
2867,
333,
279,
9325,
6572,
199,
504,
3598,
492,
7987,
647,
19,
75,
199,
4050,
647,
19,
75,
480,
1589,
286,
2268,
859,
965,
2757,
4829,
315,
2018,
650,
14,
16,
401,
13232,
29,
18,
9,
199,
2264,
7987,
647,
19,
75,
421,
199,
646,
1059,
199,
646,
984,
421,
199,
3,
6801,
370,
870,
370,
4635,
199,
3,
199,
318,
2329,
2031,
589,
304,
272,
3354,
2703,
275,
984,
14,
2703,
272,
862,
26,
267,
984,
14,
2703,
275,
984,
14,
3083,
267,
367,
284,
315,
1249,
26,
288,
870,
284,
12,
267,
870,
272,
3753,
26,
267,
984,
14,
2703,
275,
3354,
2703,
421,
199,
3,
710,
663,
402,
7576,
626,
1824,
282,
1329,
199,
3,
199,
7022,
275,
283,
11371,
7,
421,
199,
3,
6801,
370,
5536,
282,
1059,
402,
7576,
687,
314,
13738,
402,
314,
1059,
14,
199,
3,
1803,
314,
9186,
1059,
402,
7576,
436,
314,
7971,
1059,
14,
199,
3,
982,
949,
1329,
365,
1911,
12,
2529,
2125,
436,
314,
3379,
1059,
14,
199,
3,
199,
318,
664,
1507,
8,
83,
304,
272,
302,
275,
2125,
272,
1830,
308,
436,
308,
59,
16,
61,
315,
7576,
26,
267,
302,
275,
302,
435,
308,
59,
16,
61,
267,
308,
275,
308,
59,
17,
2938,
272,
372,
302,
12,
308,
421,
199,
3,
6801,
370,
1104,
340,
282,
1059,
365,
282,
1329,
199,
3,
199,
318,
365,
1507,
8,
83,
304,
272,
340,
440,
308,
26,
372,
756,
272,
367,
286,
315,
308,
26,
267,
340,
440,
286,
315,
7576,
26,
372,
756,
272,
372,
715,
421,
199,
3,
27301,
805,
372,
2943,
199,
3,
199,
1107,
63,
1313,
275,
788,
1647,
297,
283,
3612,
297,
283,
2809,
418,
421,
199,
3,
27301,
805,
1423,
2943,
199,
3,
199,
1273,
63,
1313,
275,
788,
1560,
297,
283,
875,
297,
283,
3612,
297,
283,
85,
63,
3612,
297,
283,
1609,
297,
283,
2809,
297,
283,
3157,
418,
421,
199,
3,
14012,
370,
28837,
2368,
465,
11924,
199,
3,
755,
3486,
1324,
1750,
199,
3,
755,
3486,
1072,
1750,
199,
3,
755,
1324,
1625,
199,
3,
755,
1072,
1625,
199,
3,
755,
1324,
15131,
1568,
402,
2005,
1625,
199,
3,
199,
3,
8725,
7365,
883,
506,
2013,
465,
11924,
199,
3,
755,
4413,
199,
3,
755,
1680,
46,
199,
3,
755,
4413,
627,
1680,
46,
199,
3,
755,
9151,
199,
3,
755,
4413,
627,
9151,
199,
3,
199,
3,
710,
7365,
1627,
465,
5262,
627,
6020,
787,
7710,
199,
3,
6572,
402,
4501,
2382,
4501,
787,
499,
13,
650,
13,
503,
841,
13,
11760,
199,
3,
199,
3,
2136,
1172,
370,
11201,
7795,
5548,
26,
199,
3,
755,
2366,
1324,
2368,
199,
3,
755,
445,
10098,
2368,
334,
262,
1253,
734,
9,
199,
3,
755,
2366,
1072,
2368,
334,
29428,
372,
1338,
9,
199,
3,
199,
3,
6006,
365,
282,
4412,
687,
2366,
1324,
2368,
370,
314,
1324,
2368,
199,
3,
402,
314,
445,
10098,
12,
436,
282,
9848,
4412,
687,
445,
10098,
2368,
370,
314,
199,
3,
2366,
372,
1338,
421,
199,
3,
2186,
4915,
701,
1104,
1273,
342,
436,
3550,
342,
199,
3,
199,
1273,
63,
705,
275,
283,
4087,
1680,
7,
421,
199,
3,
6801,
370,
1104,
1373,
1423,
14,
199,
3,
7628,
26,
314,
730,
436,
314,
1680,
298,
354,
2,
334,
29428,
818,
12254,
1007,
1579,
680,
199,
3,
6218,
1680,
63,
705,
340,
6020,
1159,
6835,
14,
199,
3,
1432,
730,
12,
818,
12,
6535,
12,
4618,
402,
1007,
1579,
27,
6535,
436,
4618,
1443,
506,
2701,
14,
199,
3,
199,
318,
1104,
1273,
8,
466,
12,
1680,
304,
272,
327,
272,
327,
16147,
298,
1560,
627,
88,
2,
1901,
298,
875,
671,
1674,
272,
327,
272,
340,
730,
508,
283,
1560,
7,
436,
1680,
59,
16,
61,
508,
22969,
267,
730,
275,
283,
875,
7,
267,
1680,
275,
1680,
59,
17,
2938,
272,
327,
272,
327,
2670,
626,
314,
730,
365,
3748,
14,
272,
327,
272,
340,
730,
440,
315,
1680,
63,
1313,
26,
267,
746,
1680,
63,
705,
12,
661,
4087,
730,
297,
730,
9,
272,
340,
730,
1491,
18,
61,
508,
283,
85,
63,
356,
267,
730,
275,
283,
2244,
283,
435,
730,
59,
18,
2938,
272,
327,
272,
327,
11740,
652,
315,
314,
818,
334,
2246,
4528,
9,
436,
314,
4618,
14,
272,
327,
272,
818,
12,
4618,
275,
1680,
1491,
17,
467,
1680,
59,
17,
2938,
272,
327,
272,
327,
710,
818,
1471,
506,
283,
83,
7,
367,
3222,
24649,
1324,
9,
503,
283,
82,
7,
367,
372,
1423,
14,
272,
327,
272,
340,
818,
440,
315,
661,
82,
297,
283,
83,
735,
267,
746,
1680,
63,
705,
12,
661,
4087,
1680,
818,
297,
818,
9,
272,
327,
272,
327,
6596,
652,
282,
3486,
1423,
26,
340,
880,
12,
781,
787,
4224,
14,
272,
327,
272,
340,
440,
4618,
26,
267,
372,
730,
12,
818,
12,
3260,
2125,
272,
327,
272,
327,
2832,
282,
3486,
1423,
27,
1471
] |
[
199,
3,
1898,
334,
67,
9,
12293,
12,
6423,
4299,
14,
957,
14,
199,
3,
1898,
334,
67,
9,
9013,
21,
13,
8269,
12,
11098,
367,
20548,
26993,
21412,
10661,
14,
199,
3,
1898,
334,
67,
9,
9013,
16,
13,
7155,
21,
12,
428,
280,
335,
1337,
16593,
24508,
280,
15820,
445,
18626,
453,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
1666,
314,
570,
298,
29926,
15,
32324,
5716,
2,
367,
2556,
641,
4503,
436,
199,
3,
295,
4972,
402,
642,
570,
12,
436,
367,
282,
8990,
540,
1634,
11727,
2990,
14,
199,
3949,
199,
199,
3,
2018,
2884,
370,
2198,
286,
8957,
570,
367,
6482,
436,
3550,
445,
22312,
14,
199,
3,
4503,
26,
2366,
286,
2268,
14,
647,
665,
67,
8957,
690,
3528,
578,
14,
67,
199,
3,
199,
3,
6944,
26,
2047,
221,
1471,
1642,
1852,
282,
2366,
3366,
1928,
314,
298,
2226,
2,
945,
199,
3,
755,
2544,
1265,
883,
1255,
642,
12,
1380,
10015,
2018,
367,
314,
1642,
900,
14,
199,
3,
755,
1666,
6786,
315,
314,
20618,
14,
199,
3,
199,
3,
5787,
699,
10134,
372,
6572,
3550,
6835,
1233,
199,
3,
5787,
1929,
370,
1570,
1125,
2529,
1901,
4788,
736,
370,
2867,
333,
279,
9325,
6572,
199,
504,
3598,
492,
7987,
647,
19,
75,
199,
4050,
647,
19,
75,
480,
1589,
286,
2268,
859,
965,
2757,
4829,
315,
2018,
650,
14,
16,
401,
13232,
29,
18,
9,
199,
2264,
7987,
647,
19,
75,
421,
199,
646,
1059,
199,
646,
984,
421,
199,
3,
6801,
370,
870,
370,
4635,
199,
3,
199,
318,
2329,
2031,
589,
304,
272,
3354,
2703,
275,
984,
14,
2703,
272,
862,
26,
267,
984,
14,
2703,
275,
984,
14,
3083,
267,
367,
284,
315,
1249,
26,
288,
870,
284,
12,
267,
870,
272,
3753,
26,
267,
984,
14,
2703,
275,
3354,
2703,
421,
199,
3,
710,
663,
402,
7576,
626,
1824,
282,
1329,
199,
3,
199,
7022,
275,
283,
11371,
7,
421,
199,
3,
6801,
370,
5536,
282,
1059,
402,
7576,
687,
314,
13738,
402,
314,
1059,
14,
199,
3,
1803,
314,
9186,
1059,
402,
7576,
436,
314,
7971,
1059,
14,
199,
3,
982,
949,
1329,
365,
1911,
12,
2529,
2125,
436,
314,
3379,
1059,
14,
199,
3,
199,
318,
664,
1507,
8,
83,
304,
272,
302,
275,
2125,
272,
1830,
308,
436,
308,
59,
16,
61,
315,
7576,
26,
267,
302,
275,
302,
435,
308,
59,
16,
61,
267,
308,
275,
308,
59,
17,
2938,
272,
372,
302,
12,
308,
421,
199,
3,
6801,
370,
1104,
340,
282,
1059,
365,
282,
1329,
199,
3,
199,
318,
365,
1507,
8,
83,
304,
272,
340,
440,
308,
26,
372,
756,
272,
367,
286,
315,
308,
26,
267,
340,
440,
286,
315,
7576,
26,
372,
756,
272,
372,
715,
421,
199,
3,
27301,
805,
372,
2943,
199,
3,
199,
1107,
63,
1313,
275,
788,
1647,
297,
283,
3612,
297,
283,
2809,
418,
421,
199,
3,
27301,
805,
1423,
2943,
199,
3,
199,
1273,
63,
1313,
275,
788,
1560,
297,
283,
875,
297,
283,
3612,
297,
283,
85,
63,
3612,
297,
283,
1609,
297,
283,
2809,
297,
283,
3157,
418,
421,
199,
3,
14012,
370,
28837,
2368,
465,
11924,
199,
3,
755,
3486,
1324,
1750,
199,
3,
755,
3486,
1072,
1750,
199,
3,
755,
1324,
1625,
199,
3,
755,
1072,
1625,
199,
3,
755,
1324,
15131,
1568,
402,
2005,
1625,
199,
3,
199,
3,
8725,
7365,
883,
506,
2013,
465,
11924,
199,
3,
755,
4413,
199,
3,
755,
1680,
46,
199,
3,
755,
4413,
627,
1680,
46,
199,
3,
755,
9151,
199,
3,
755,
4413,
627,
9151,
199,
3,
199,
3,
710,
7365,
1627,
465,
5262,
627,
6020,
787,
7710,
199,
3,
6572,
402,
4501,
2382,
4501,
787,
499,
13,
650,
13,
503,
841,
13,
11760,
199,
3,
199,
3,
2136,
1172,
370,
11201,
7795,
5548,
26,
199,
3,
755,
2366,
1324,
2368,
199,
3,
755,
445,
10098,
2368,
334,
262,
1253,
734,
9,
199,
3,
755,
2366,
1072,
2368,
334,
29428,
372,
1338,
9,
199,
3,
199,
3,
6006,
365,
282,
4412,
687,
2366,
1324,
2368,
370,
314,
1324,
2368,
199,
3,
402,
314,
445,
10098,
12,
436,
282,
9848,
4412,
687,
445,
10098,
2368,
370,
314,
199,
3,
2366,
372,
1338,
421,
199,
3,
2186,
4915,
701,
1104,
1273,
342,
436,
3550,
342,
199,
3,
199,
1273,
63,
705,
275,
283,
4087,
1680,
7,
421,
199,
3,
6801,
370,
1104,
1373,
1423,
14,
199,
3,
7628,
26,
314,
730,
436,
314,
1680,
298,
354,
2,
334,
29428,
818,
12254,
1007,
1579,
680,
199,
3,
6218,
1680,
63,
705,
340,
6020,
1159,
6835,
14,
199,
3,
1432,
730,
12,
818,
12,
6535,
12,
4618,
402,
1007,
1579,
27,
6535,
436,
4618,
1443,
506,
2701,
14,
199,
3,
199,
318,
1104,
1273,
8,
466,
12,
1680,
304,
272,
327,
272,
327,
16147,
298,
1560,
627,
88,
2,
1901,
298,
875,
671,
1674,
272,
327,
272,
340,
730,
508,
283,
1560,
7,
436,
1680,
59,
16,
61,
508,
22969,
267,
730,
275,
283,
875,
7,
267,
1680,
275,
1680,
59,
17,
2938,
272,
327,
272,
327,
2670,
626,
314,
730,
365,
3748,
14,
272,
327,
272,
340,
730,
440,
315,
1680,
63,
1313,
26,
267,
746,
1680,
63,
705,
12,
661,
4087,
730,
297,
730,
9,
272,
340,
730,
1491,
18,
61,
508,
283,
85,
63,
356,
267,
730,
275,
283,
2244,
283,
435,
730,
59,
18,
2938,
272,
327,
272,
327,
11740,
652,
315,
314,
818,
334,
2246,
4528,
9,
436,
314,
4618,
14,
272,
327,
272,
818,
12,
4618,
275,
1680,
1491,
17,
467,
1680,
59,
17,
2938,
272,
327,
272,
327,
710,
818,
1471,
506,
283,
83,
7,
367,
3222,
24649,
1324,
9,
503,
283,
82,
7,
367,
372,
1423,
14,
272,
327,
272,
340,
818,
440,
315,
661,
82,
297,
283,
83,
735,
267,
746,
1680,
63,
705,
12,
661,
4087,
1680,
818,
297,
818,
9,
272,
327,
272,
327,
6596,
652,
282,
3486,
1423,
26,
340,
880,
12,
781,
787,
4224,
14,
272,
327,
272,
340,
440,
4618,
26,
267,
372,
730,
12,
818,
12,
3260,
2125,
272,
327,
272,
327,
2832,
282,
3486,
1423,
27,
1471,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
robertnishihara/ray
|
python/ray/tune/integration/keras.py
|
3
|
10398
|
from collections import Counter
from typing import Dict, List, Union
from tensorflow.keras.callbacks import Callback
from ray import tune
import os
class TuneCallback(Callback):
"""Base class for Tune's Keras callbacks."""
_allowed = [
"batch_begin",
"batch_end",
"epoch_begin",
"epoch_end",
"train_batch_begin",
"train_batch_end",
"test_batch_begin",
"test_batch_end",
"predict_batch_begin",
"predict_batch_end",
"train_begin",
"train_end",
"test_begin",
"test_end",
"predict_begin",
"predict_end",
]
def __init__(self, on: Union[str, List[str]] = "validation_end"):
super(TuneCallback, self).__init__()
if not isinstance(on, list):
on = [on]
if any(w not in self._allowed for w in on):
raise ValueError(
"Invalid trigger time selected: {}. Must be one of {}".format(
on, self._allowed))
self._on = on
def _handle(self, logs: Dict, when: str):
raise NotImplementedError
def on_batch_begin(self, batch, logs=None):
if "batch_begin" in self._on:
self._handle(logs, "batch_begin")
def on_batch_end(self, batch, logs=None):
if "batch_end" in self._on:
self._handle(logs, "batch_end")
def on_epoch_begin(self, epoch, logs=None):
if "epoch_begin" in self._on:
self._handle(logs, "epoch_begin")
def on_epoch_end(self, epoch, logs=None):
if "epoch_end" in self._on:
self._handle(logs, "epoch_end")
def on_train_batch_begin(self, batch, logs=None):
if "train_batch_begin" in self._on:
self._handle(logs, "train_batch_begin")
def on_train_batch_end(self, batch, logs=None):
if "train_batch_end" in self._on:
self._handle(logs, "train_batch_end")
def on_test_batch_begin(self, batch, logs=None):
if "test_batch_begin" in self._on:
self._handle(logs, "test_batch_begin")
def on_test_batch_end(self, batch, logs=None):
if "test_batch_end" in self._on:
self._handle(logs, "test_batch_end")
def on_predict_batch_begin(self, batch, logs=None):
if "predict_batch_begin" in self._on:
self._handle(logs, "predict_batch_begin")
def on_predict_batch_end(self, batch, logs=None):
if "predict_batch_end" in self._on:
self._handle(logs, "predict_batch_end")
def on_train_begin(self, logs=None):
if "train_begin" in self._on:
self._handle(logs, "train_begin")
def on_train_end(self, logs=None):
if "train_end" in self._on:
self._handle(logs, "train_end")
def on_test_begin(self, logs=None):
if "test_begin" in self._on:
self._handle(logs, "test_begin")
def on_test_end(self, logs=None):
if "test_end" in self._on:
self._handle(logs, "test_end")
def on_predict_begin(self, logs=None):
if "predict_begin" in self._on:
self._handle(logs, "predict_begin")
def on_predict_end(self, logs=None):
if "predict_end" in self._on:
self._handle(logs, "predict_end")
class TuneReportCallback(TuneCallback):
"""Keras to Ray Tune reporting callback
Reports metrics to Ray Tune.
Args:
metrics (str|list|dict): Metrics to report to Tune. If this is a list,
each item describes the metric key reported to Keras,
and it will reported under the same name to Tune. If this is a
dict, each key will be the name reported to Tune and the respective
value will be the metric key reported to Keras. If this is None,
all Keras logs will be reported.
on (str|list): When to trigger checkpoint creations. Must be one of
the Keras event hooks (less the ``on_``), e.g.
"train_start", or "predict_end". Defaults to "epoch_end".
Example:
.. code-block:: python
from ray.tune.integration.keras import TuneReportCallback
# Report accuracy to Tune after each epoch:
model.fit(
x_train,
y_train,
batch_size=batch_size,
epochs=epochs,
verbose=0,
validation_data=(x_test, y_test),
callbacks=[TuneReportCallback(
{"mean_accuracy": "accuracy"}, on="epoch_end")])
"""
def __init__(self,
metrics: Union[None, str, List[str], Dict[str, str]] = None,
on: Union[str, List[str]] = "epoch_end"):
super(TuneReportCallback, self).__init__(on)
if isinstance(metrics, str):
metrics = [metrics]
self._metrics = metrics
def _handle(self, logs: Dict, when: str = None):
if not self._metrics:
report_dict = logs
else:
report_dict = {}
for key in self._metrics:
if isinstance(self._metrics, dict):
metric = self._metrics[key]
else:
metric = key
report_dict[key] = logs[metric]
tune.report(**report_dict)
class _TuneCheckpointCallback(TuneCallback):
"""Keras checkpoint callback
Saves checkpoints after each validation step.
Checkpoint are currently not registered if no ``tune.report()`` call
is made afterwards. Consider using ``TuneReportCheckpointCallback``
instead.
Args:
filename (str): Filename of the checkpoint within the checkpoint
directory. Defaults to "checkpoint".
frequency (int|list): Checkpoint frequency. If this is an integer `n`,
checkpoints are saved every `n` times each hook was called. If
this is a list, it specifies the checkpoint frequencies for each
hook individually.
on (str|list): When to trigger checkpoint creations. Must be one of
the Keras event hooks (less the ``on_``), e.g.
"train_start", or "predict_end". Defaults to "epoch_end".
"""
def __init__(self,
filename: str = "checkpoint",
frequency: Union[int, List[int]] = 1,
on: Union[str, List[str]] = "epoch_end"):
if isinstance(frequency, list):
if not isinstance(on, list) or len(frequency) != len(on):
raise ValueError(
"If you pass a list for checkpoint frequencies, the `on` "
"parameter has to be a list with the same length.")
self._frequency = frequency
super(_TuneCheckpointCallback, self).__init__(on)
self._filename = filename
self._counter = Counter()
self._cp_count = 0 # Has to be monotonically increasing
def _handle(self, logs: Dict, when: str = None):
self._counter[when] += 1
if isinstance(self._frequency, list):
index = self._on.index(when)
freq = self._frequency[index]
else:
freq = self._frequency
if self._counter[when] % freq == 0:
with tune.checkpoint_dir(step=self._cp_count) as checkpoint_dir:
self.model.save(
os.path.join(checkpoint_dir, self._filename),
overwrite=True)
self._cp_count += 1
class TuneReportCheckpointCallback(TuneCallback):
"""Keras report and checkpoint callback
Saves checkpoints after each validation step. Also reports metrics to Tune,
which is needed for checkpoint registration.
Use this callback to register saved checkpoints with Ray Tune. This means
that checkpoints will be manages by the `CheckpointManager` and can be
used for advanced scheduling and search algorithms, like
Population Based Training.
The ``tf.keras.callbacks.ModelCheckpoint`` callback also saves checkpoints,
but doesn't register them with Ray Tune.
Args:
metrics (str|list|dict): Metrics to report to Tune. If this is a list,
each item describes the metric key reported to Keras,
and it will reported under the same name to Tune. If this is a
dict, each key will be the name reported to Tune and the respective
value will be the metric key reported to Keras. If this is None,
all Keras logs will be reported.
filename (str): Filename of the checkpoint within the checkpoint
directory. Defaults to "checkpoint".
frequency (int|list): Checkpoint frequency. If this is an integer `n`,
checkpoints are saved every `n` times each hook was called. If
this is a list, it specifies the checkpoint frequencies for each
hook individually.
on (str|list): When to trigger checkpoint creations. Must be one of
the Keras event hooks (less the ``on_``), e.g.
"train_start", or "predict_end". Defaults to "epoch_end".
Example:
.. code-block:: python
from ray.tune.integration.keras import TuneReportCheckpointCallback
# Save checkpoint and report accuracy to Tune after each epoch:
model.fit(
x_train,
y_train,
batch_size=batch_size,
epochs=epochs,
verbose=0,
validation_data=(x_test, y_test),
callbacks=[TuneReportCheckpointCallback(
metrics={"mean_accuracy": "accuracy"},
filename="model",
on="epoch_end")])
"""
def __init__(self,
metrics: Union[None, str, List[str], Dict[str, str]] = None,
filename: str = "checkpoint",
frequency: Union[int, List[int]] = 1,
on: Union[str, List[str]] = "epoch_end"):
super(TuneReportCheckpointCallback, self).__init__(on)
self._checkpoint = _TuneCheckpointCallback(filename, frequency, on)
self._report = TuneReportCallback(metrics, on)
def _handle(self, logs: Dict, when: str = None):
self._checkpoint._handle(logs, when)
self._report._handle(logs, when)
def set_model(self, model):
# Pass through for the checkpoint callback to set model
self._checkpoint.set_model(model)
self._report.set_model(model)
|
apache-2.0
|
[
504,
5055,
492,
14427,
199,
504,
14090,
492,
7448,
12,
3820,
12,
15961,
199,
199,
504,
3228,
14,
8811,
14,
11948,
492,
17555,
199,
504,
22059,
492,
307,
11474,
199,
199,
646,
747,
421,
199,
533,
377,
11474,
2806,
8,
2806,
304,
272,
408,
1563,
1021,
367,
377,
11474,
1159,
1804,
30037,
13484,
1041,
272,
485,
6541,
275,
359,
267,
298,
2912,
63,
5037,
401,
267,
298,
2912,
63,
500,
401,
267,
298,
7367,
63,
5037,
401,
267,
298,
7367,
63,
500,
401,
267,
298,
2834,
63,
2912,
63,
5037,
401,
267,
298,
2834,
63,
2912,
63,
500,
401,
267,
298,
396,
63,
2912,
63,
5037,
401,
267,
298,
396,
63,
2912,
63,
500,
401,
267,
298,
6892,
63,
2912,
63,
5037,
401,
267,
298,
6892,
63,
2912,
63,
500,
401,
267,
298,
2834,
63,
5037,
401,
267,
298,
2834,
63,
500,
401,
267,
298,
396,
63,
5037,
401,
267,
298,
396,
63,
500,
401,
267,
298,
6892,
63,
5037,
401,
267,
298,
6892,
63,
500,
401,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
641,
26,
15961,
59,
495,
12,
3820,
59,
495,
2677,
275,
298,
6136,
63,
500,
2349,
267,
1613,
8,
52,
11474,
2806,
12,
291,
2843,
826,
4533,
398,
340,
440,
1228,
8,
265,
12,
769,
304,
288,
641,
275,
359,
265,
61,
267,
340,
1263,
8,
87,
440,
315,
291,
423,
6541,
367,
336,
315,
641,
304,
288,
746,
1722,
8,
355,
298,
3364,
6804,
900,
4895,
26,
30332,
9498,
506,
1373,
402,
8352,
908,
8,
490,
641,
12,
291,
423,
6541,
430,
267,
291,
423,
265,
275,
641,
339,
347,
485,
2479,
8,
277,
12,
9610,
26,
7448,
12,
1380,
26,
620,
304,
267,
746,
4279,
339,
347,
641,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2912,
63,
5037,
531,
339,
347,
641,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2912,
63,
500,
531,
339,
347,
641,
63,
7367,
63,
5037,
8,
277,
12,
9463,
12,
9610,
29,
403,
304,
267,
340,
298,
7367,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
7367,
63,
5037,
531,
339,
347,
641,
63,
7367,
63,
500,
8,
277,
12,
9463,
12,
9610,
29,
403,
304,
267,
340,
298,
7367,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
7367,
63,
500,
531,
339,
347,
641,
63,
2834,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
2912,
63,
5037,
531,
339,
347,
641,
63,
2834,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
2912,
63,
500,
531,
339,
347,
641,
63,
396,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
2912,
63,
5037,
531,
339,
347,
641,
63,
396,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
2912,
63,
500,
531,
339,
347,
641,
63,
6892,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
2912,
63,
5037,
531,
339,
347,
641,
63,
6892,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
2912,
63,
500,
531,
339,
347,
641,
63,
2834,
63,
5037,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
5037,
531,
339,
347,
641,
63,
2834,
63,
500,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
500,
531,
339,
347,
641,
63,
396,
63,
5037,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
5037,
531,
339,
347,
641,
63,
396,
63,
500,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
500,
531,
339,
347,
641,
63,
6892,
63,
5037,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
5037,
531,
339,
347,
641,
63,
6892,
63,
500,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
500,
531,
421,
199,
533,
377,
11474,
7457,
2806,
8,
52,
11474,
2806,
304,
272,
408,
43,
30037,
370,
30703,
377,
11474,
17290,
3233,
339,
799,
5203,
7186,
370,
30703,
377,
11474,
14,
339,
3033,
26,
267,
7186,
334,
495,
92,
513,
92,
807,
304,
10072,
11818,
370,
3622,
370,
377,
11474,
14,
982,
642,
365,
282,
769,
12,
288,
1924,
1242,
23369,
314,
6370,
790,
14581,
370,
1804,
30037,
12,
288,
436,
652,
911,
14581,
1334,
314,
2011
] |
[
5055,
492,
14427,
199,
504,
14090,
492,
7448,
12,
3820,
12,
15961,
199,
199,
504,
3228,
14,
8811,
14,
11948,
492,
17555,
199,
504,
22059,
492,
307,
11474,
199,
199,
646,
747,
421,
199,
533,
377,
11474,
2806,
8,
2806,
304,
272,
408,
1563,
1021,
367,
377,
11474,
1159,
1804,
30037,
13484,
1041,
272,
485,
6541,
275,
359,
267,
298,
2912,
63,
5037,
401,
267,
298,
2912,
63,
500,
401,
267,
298,
7367,
63,
5037,
401,
267,
298,
7367,
63,
500,
401,
267,
298,
2834,
63,
2912,
63,
5037,
401,
267,
298,
2834,
63,
2912,
63,
500,
401,
267,
298,
396,
63,
2912,
63,
5037,
401,
267,
298,
396,
63,
2912,
63,
500,
401,
267,
298,
6892,
63,
2912,
63,
5037,
401,
267,
298,
6892,
63,
2912,
63,
500,
401,
267,
298,
2834,
63,
5037,
401,
267,
298,
2834,
63,
500,
401,
267,
298,
396,
63,
5037,
401,
267,
298,
396,
63,
500,
401,
267,
298,
6892,
63,
5037,
401,
267,
298,
6892,
63,
500,
401,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
641,
26,
15961,
59,
495,
12,
3820,
59,
495,
2677,
275,
298,
6136,
63,
500,
2349,
267,
1613,
8,
52,
11474,
2806,
12,
291,
2843,
826,
4533,
398,
340,
440,
1228,
8,
265,
12,
769,
304,
288,
641,
275,
359,
265,
61,
267,
340,
1263,
8,
87,
440,
315,
291,
423,
6541,
367,
336,
315,
641,
304,
288,
746,
1722,
8,
355,
298,
3364,
6804,
900,
4895,
26,
30332,
9498,
506,
1373,
402,
8352,
908,
8,
490,
641,
12,
291,
423,
6541,
430,
267,
291,
423,
265,
275,
641,
339,
347,
485,
2479,
8,
277,
12,
9610,
26,
7448,
12,
1380,
26,
620,
304,
267,
746,
4279,
339,
347,
641,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2912,
63,
5037,
531,
339,
347,
641,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2912,
63,
500,
531,
339,
347,
641,
63,
7367,
63,
5037,
8,
277,
12,
9463,
12,
9610,
29,
403,
304,
267,
340,
298,
7367,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
7367,
63,
5037,
531,
339,
347,
641,
63,
7367,
63,
500,
8,
277,
12,
9463,
12,
9610,
29,
403,
304,
267,
340,
298,
7367,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
7367,
63,
500,
531,
339,
347,
641,
63,
2834,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
2912,
63,
5037,
531,
339,
347,
641,
63,
2834,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
2912,
63,
500,
531,
339,
347,
641,
63,
396,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
2912,
63,
5037,
531,
339,
347,
641,
63,
396,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
2912,
63,
500,
531,
339,
347,
641,
63,
6892,
63,
2912,
63,
5037,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
2912,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
2912,
63,
5037,
531,
339,
347,
641,
63,
6892,
63,
2912,
63,
500,
8,
277,
12,
3522,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
2912,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
2912,
63,
500,
531,
339,
347,
641,
63,
2834,
63,
5037,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
5037,
531,
339,
347,
641,
63,
2834,
63,
500,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
2834,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
2834,
63,
500,
531,
339,
347,
641,
63,
396,
63,
5037,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
5037,
531,
339,
347,
641,
63,
396,
63,
500,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
396,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
396,
63,
500,
531,
339,
347,
641,
63,
6892,
63,
5037,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
5037,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
5037,
531,
339,
347,
641,
63,
6892,
63,
500,
8,
277,
12,
9610,
29,
403,
304,
267,
340,
298,
6892,
63,
500,
2,
315,
291,
423,
265,
26,
288,
291,
423,
2479,
8,
7270,
12,
298,
6892,
63,
500,
531,
421,
199,
533,
377,
11474,
7457,
2806,
8,
52,
11474,
2806,
304,
272,
408,
43,
30037,
370,
30703,
377,
11474,
17290,
3233,
339,
799,
5203,
7186,
370,
30703,
377,
11474,
14,
339,
3033,
26,
267,
7186,
334,
495,
92,
513,
92,
807,
304,
10072,
11818,
370,
3622,
370,
377,
11474,
14,
982,
642,
365,
282,
769,
12,
288,
1924,
1242,
23369,
314,
6370,
790,
14581,
370,
1804,
30037,
12,
288,
436,
652,
911,
14581,
1334,
314,
2011,
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
] |
ApplauseAQI/androguard
|
androguard/decompiler/dad/decompile.py
|
6
|
17011
|
# This file is part of Androguard.
#
# Copyright (c) 2012 Geoffroy Gueguen <geoffroy.gueguen@gmail.com>
# 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 sys
sys.path.append('./')
import logging
import struct
from collections import defaultdict
import androguard.core.androconf as androconf
import androguard.decompiler.dad.util as util
from androguard.core.analysis import analysis
from androguard.core.bytecodes import apk, dvm
from androguard.decompiler.dad.ast import (JSONWriter, parse_descriptor,
literal_string, literal_null, literal_int, literal_long, literal_float,
literal_double, literal_bool, literal_hex_int, dummy)
from androguard.decompiler.dad.control_flow import identify_structures
from androguard.decompiler.dad.dataflow import (build_def_use,
place_declarations,
dead_code_elimination,
register_propagation,
split_variables)
from androguard.decompiler.dad.graph import construct, simplify, split_if_nodes
from androguard.decompiler.dad.instruction import Param, ThisParam
from androguard.decompiler.dad.writer import Writer
from androguard.util import read
def auto_vm(filename):
ret = androconf.is_android(filename)
if ret == 'APK':
return dvm.DalvikVMFormat(apk.APK(filename).get_dex())
elif ret == 'DEX':
return dvm.DalvikVMFormat(read(filename))
elif ret == 'ODEX':
return dvm.DalvikOdexVMFormat(read(filename))
return None
# No seperate DvField class currently
def get_field_ast(field):
triple = field.get_class_name()[1:-1], field.get_name(), field.get_descriptor()
expr = None
if field.init_value:
val = field.init_value.value
expr = dummy(str(val))
if val is not None:
if field.get_descriptor() == 'Ljava/lang/String;':
expr = literal_string(val)
elif field.proto == 'B':
expr = literal_hex_int(struct.unpack('<b', val)[0])
return {
'triple': triple,
'type': parse_descriptor(field.get_descriptor()),
'flags': util.get_access_field(field.get_access_flags()),
'expr': expr,
}
class DvMethod(object):
def __init__(self, methanalysis):
method = methanalysis.get_method()
self.method = method
self.start_block = next(methanalysis.get_basic_blocks().get(), None)
self.cls_name = method.get_class_name()
self.name = method.get_name()
self.lparams = []
self.var_to_name = defaultdict()
self.writer = None
self.graph = None
self.ast = None
self.access = util.get_access_method(method.get_access_flags())
desc = method.get_descriptor()
self.type = desc.split(')')[-1]
self.params_type = util.get_params_type(desc)
self.triple = method.get_triple()
self.exceptions = methanalysis.exceptions.exceptions
code = method.get_code()
if code is None:
logger.debug('No code : %s %s', self.name, self.cls_name)
else:
start = code.registers_size - code.ins_size
if 'static' not in self.access:
self.var_to_name[start] = ThisParam(start, self.cls_name)
self.lparams.append(start)
start += 1
num_param = 0
for ptype in self.params_type:
param = start + num_param
self.lparams.append(param)
self.var_to_name[param] = Param(param, ptype)
num_param += util.get_type_size(ptype)
if not __debug__:
from androguard.core import bytecode
bytecode.method2png('/tmp/dad/graphs/%s#%s.png' % \
(self.cls_name.split('/')[-1][:-1], self.name), methanalysis)
def process(self, doAST=False):
logger.debug('METHOD : %s', self.name)
# Native methods... no blocks.
if self.start_block is None:
logger.debug('Native Method.')
if doAST:
self.ast = JSONWriter(None, self).get_ast()
else:
self.writer = Writer(None, self)
self.writer.write_method()
return
graph = construct(self.start_block, self.var_to_name, self.exceptions)
self.graph = graph
if not __debug__:
util.create_png(self.cls_name, self.name, graph, '/tmp/dad/blocks')
use_defs, def_uses = build_def_use(graph, self.lparams)
split_variables(graph, self.var_to_name, def_uses, use_defs)
dead_code_elimination(graph, def_uses, use_defs)
register_propagation(graph, def_uses, use_defs)
place_declarations(graph, self.var_to_name, def_uses, use_defs)
del def_uses, use_defs
# After the DCE pass, some nodes may be empty, so we can simplify the
# graph to delete these nodes.
# We start by restructuring the graph by spliting the conditional nodes
# into a pre-header and a header part.
split_if_nodes(graph)
# We then simplify the graph by merging multiple statement nodes into
# a single statement node when possible. This also delete empty nodes.
simplify(graph)
graph.compute_rpo()
if not __debug__:
util.create_png(self.cls_name, self.name, graph,
'/tmp/dad/pre-structured')
identify_structures(graph, graph.immediate_dominators())
if not __debug__:
util.create_png(self.cls_name, self.name, graph,
'/tmp/dad/structured')
if doAST:
self.ast = JSONWriter(graph, self).get_ast()
else:
self.writer = Writer(graph, self)
self.writer.write_method()
def get_ast(self):
return self.ast
def show_source(self):
print self.get_source()
def get_source(self):
if self.writer:
return '%s' % self.writer
return ''
def get_source_ext(self):
if self.writer:
return self.writer.str_ext()
return []
def __repr__(self):
#return 'Method %s' % self.name
return 'class DvMethod(object): %s' % self.name
class DvClass(object):
def __init__(self, dvclass, vma):
name = dvclass.get_name()
if name.find('/') > 0:
pckg, name = name.rsplit('/', 1)
else:
pckg, name = '', name
self.package = pckg[1:].replace('/', '.')
self.name = name[:-1]
self.vma = vma
self.methods = dvclass.get_methods()
self.fields = dvclass.get_fields()
self.subclasses = {}
self.code = []
self.inner = False
access = dvclass.get_access_flags()
# If interface we remove the class and abstract keywords
if 0x200 & access:
prototype = '%s %s'
if access & 0x400:
access -= 0x400
else:
prototype = '%s class %s'
self.access = util.get_access_class(access)
self.prototype = prototype % (' '.join(self.access), self.name)
self.interfaces = dvclass.get_interfaces()
self.superclass = dvclass.get_superclassname()
self.thisclass = dvclass.get_name()
logger.info('Class : %s', self.name)
logger.info('Methods added :')
for meth in self.methods:
logger.info('%s (%s, %s)', meth.get_method_idx(), self.name, meth.name)
logger.info('')
def add_subclass(self, innername, dvclass):
self.subclasses[innername] = dvclass
dvclass.inner = True
def get_methods(self):
return self.methods
def process_method(self, num, doAST=False):
method = self.methods[num]
if not isinstance(method, DvMethod):
method.set_instructions([i for i in method.get_instructions()])
self.methods[num] = DvMethod(self.vma.get_method(method))
self.methods[num].process(doAST=doAST)
method.set_instructions([])
else:
method.process(doAST=doAST)
def process(self, doAST=False):
for klass in self.subclasses.values():
klass.process(doAST=doAST)
for i in range(len(self.methods)):
self.process_method(i, doAST=doAST)
def get_ast(self):
fields = [get_field_ast(f) for f in self.fields]
methods = [m.get_ast() for m in self.methods if m.ast is not None]
isInterface = 'interface' in self.access
return {
'rawname': self.thisclass[1:-1],
'name': parse_descriptor(self.thisclass),
'super': parse_descriptor(self.superclass),
'flags': self.access,
'isInterface': isInterface,
'interfaces': map(parse_descriptor, self.interfaces),
'fields': fields,
'methods': methods,
}
def get_source(self):
source = []
if not self.inner and self.package:
source.append('package %s;\n' % self.package)
superclass, prototype = self.superclass, self.prototype
if superclass is not None and superclass != 'Ljava/lang/Object;':
superclass = superclass[1:-1].replace('/', '.')
prototype += ' extends %s' % superclass
if len(self.interfaces) > 0:
prototype += ' implements %s' % ', '.join(
[n[1:-1].replace('/', '.') for n in self.interfaces])
source.append('%s {\n' % prototype)
for field in self.fields:
name = field.get_name()
access = util.get_access_field(field.get_access_flags())
f_type = util.get_type(field.get_descriptor())
source.append(' ')
if access:
source.append(' '.join(access))
source.append(' ')
if field.init_value:
value = field.init_value.value
if f_type == 'String':
value = '"%s"' % value
elif field.proto == 'B':
value = '0x%x' % struct.unpack('b', value)[0]
source.append('%s %s = %s;\n' % (f_type, name, value))
else:
source.append('%s %s;\n' % (f_type, name))
for klass in self.subclasses.values():
source.append(klass.get_source())
for method in self.methods:
if isinstance(method, DvMethod):
source.append(method.get_source())
source.append('}\n')
return ''.join(source)
def get_source_ext(self):
source = []
if not self.inner and self.package:
source.append(
('PACKAGE', [('PACKAGE_START', 'package '),
('NAME_PACKAGE', '%s' % self.package),
('PACKAGE_END', ';\n')]))
list_proto = []
list_proto.append(
('PROTOTYPE_ACCESS', '%s class ' % ' '.join(self.access)))
list_proto.append(('NAME_PROTOTYPE', '%s' % self.name, self.package))
superclass = self.superclass
if superclass is not None and superclass != 'Ljava/lang/Object;':
superclass = superclass[1:-1].replace('/', '.')
list_proto.append(('EXTEND', ' extends '))
list_proto.append(('NAME_SUPERCLASS', '%s' % superclass))
if len(self.interfaces) > 0:
list_proto.append(('IMPLEMENTS', ' implements '))
for i, interface in enumerate(self.interfaces):
if i != 0:
list_proto.append(('COMMA', ', '))
list_proto.append(
('NAME_INTERFACE', interface[1:-1].replace('/', '.')))
list_proto.append(('PROTOTYPE_END', ' {\n'))
source.append(("PROTOTYPE", list_proto))
for field in self.fields:
field_access_flags = field.get_access_flags()
access = [util.ACCESS_FLAGS_FIELDS[flag] for flag in
util.ACCESS_FLAGS_FIELDS if flag & field_access_flags]
f_type = util.get_type(field.get_descriptor())
name = field.get_name()
if access:
access_str = ' %s ' % ' '.join(access)
else:
access_str = ' '
source.append(
('FIELD', [('FIELD_ACCESS', access_str),
('FIELD_TYPE', '%s' % f_type),
('SPACE', ' '),
('NAME_FIELD', '%s' % name, f_type, field),
('FIELD_END', ';\n')]))
#TODO: call get_source_ext for each subclass?
for klass in self.subclasses.values():
source.append((klass, klass.get_source()))
for method in self.methods:
if isinstance(method, DvMethod):
source.append(("METHOD", method.get_source_ext()))
source.append(("CLASS_END", [('CLASS_END', '}\n')]))
return source
def show_source(self):
print self.get_source()
def __repr__(self):
if not self.subclasses:
return 'Class(%s)' % self.name
return 'Class(%s) -- Subclasses(%s)' % (self.name, self.subclasses)
class DvMachine(object):
def __init__(self, name):
vm = auto_vm(name)
if vm is None:
raise ValueError('Format not recognised: %s' % name)
self.vma = analysis.uVMAnalysis(vm)
self.classes = dict((dvclass.get_name(), dvclass)
for dvclass in vm.get_classes())
#util.merge_inner(self.classes)
def get_classes(self):
return self.classes.keys()
def get_class(self, class_name):
for name, klass in self.classes.iteritems():
if class_name in name:
if isinstance(klass, DvClass):
return klass
dvclass = self.classes[name] = DvClass(klass, self.vma)
return dvclass
def process(self):
for name, klass in self.classes.iteritems():
logger.info('Processing class: %s', name)
if isinstance(klass, DvClass):
klass.process()
else:
dvclass = self.classes[name] = DvClass(klass, self.vma)
dvclass.process()
def show_source(self):
for klass in self.classes.values():
klass.show_source()
def process_and_show(self):
for name, klass in sorted(self.classes.iteritems()):
logger.info('Processing class: %s', name)
if not isinstance(klass, DvClass):
klass = DvClass(klass, self.vma)
klass.process()
klass.show_source()
logger = logging.getLogger('dad')
sys.setrecursionlimit(5000)
def main():
# logger.setLevel(logging.DEBUG) for debugging output
# comment the line to disable the logging.
logger.setLevel(logging.INFO)
console_hdlr = logging.StreamHandler(sys.stdout)
console_hdlr.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
logger.addHandler(console_hdlr)
default_file = 'examples/android/TestsAndroguard/bin/TestActivity.apk'
if len(sys.argv) > 1:
machine = DvMachine(sys.argv[1])
else:
machine = DvMachine(default_file)
logger.info('========================')
logger.info('Classes:')
for class_name in sorted(machine.get_classes()):
logger.info(' %s', class_name)
logger.info('========================')
cls_name = raw_input('Choose a class: ')
if cls_name == '*':
machine.process_and_show()
else:
cls = machine.get_class(cls_name)
if cls is None:
logger.error('%s not found.', cls_name)
else:
logger.info('======================')
for i, method in enumerate(cls.get_methods()):
logger.info('%d: %s', i, method.name)
logger.info('======================')
meth = raw_input('Method: ')
if meth == '*':
logger.info('CLASS = %s', cls)
cls.process()
else:
cls.process_method(int(meth))
logger.info('Source:')
logger.info('===========================')
cls.show_source()
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3,
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
6029,
5346,
1997,
4813,
598,
310,
6051,
287,
665,
303,
1997,
4813,
14,
71,
310,
6051,
287,
32,
6799,
14,
957,
30,
199,
3,
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,
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,
13,
1311,
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,
646,
984,
199,
1274,
14,
515,
14,
740,
5175,
6217,
199,
199,
646,
2050,
199,
646,
2702,
199,
504,
5055,
492,
10018,
199,
646,
436,
293,
15606,
14,
1018,
14,
460,
293,
2190,
465,
436,
293,
2190,
199,
646,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
1974,
465,
4884,
199,
504,
436,
293,
15606,
14,
1018,
14,
10466,
492,
11284,
199,
504,
436,
293,
15606,
14,
1018,
14,
4414,
6021,
492,
31528,
12,
366,
2611,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
1810,
492,
334,
6243,
6261,
12,
2198,
63,
4120,
12,
272,
8785,
63,
875,
12,
8785,
63,
2307,
12,
8785,
63,
442,
12,
8785,
63,
2809,
12,
8785,
63,
1609,
12,
272,
8785,
63,
3157,
12,
8785,
63,
2245,
12,
8785,
63,
4097,
63,
442,
12,
7283,
9,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
2785,
63,
1659,
492,
10405,
63,
13547,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
576,
1659,
492,
334,
1506,
63,
318,
63,
1180,
12,
6059,
4192,
63,
21200,
12,
6059,
12314,
63,
600,
63,
69,
13769,
425,
12,
6059,
2274,
63,
13535,
12,
6059,
3715,
63,
3669,
9,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
2180,
492,
6982,
12,
15037,
12,
3715,
63,
692,
63,
2415,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
22880,
492,
12608,
12,
961,
4098,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
5491,
492,
24441,
199,
504,
436,
293,
15606,
14,
1974,
492,
1586,
421,
199,
318,
2599,
63,
2611,
8,
1501,
304,
272,
2203,
275,
436,
293,
2190,
14,
374,
63,
6238,
8,
1501,
9,
272,
340,
2203,
508,
283,
1282,
43,
356,
267,
372,
366,
2611,
14,
36,
279,
433,
75,
6849,
3484,
8,
23582,
14,
1282,
43,
8,
1501,
680,
362,
63,
731,
1012,
272,
916,
2203,
508,
283,
7746,
356,
267,
372,
366,
2611,
14,
36,
279,
433,
75,
6849,
3484,
8,
739,
8,
1501,
430,
272,
916,
2203,
508,
283,
47,
7746,
356,
267,
372,
366,
2611,
14,
36,
279,
433,
75,
47,
731,
6849,
3484,
8,
739,
8,
1501,
430,
272,
372,
488,
199,
199,
3,
3091,
542,
529,
323,
577,
86,
792,
1021,
5544,
199,
318,
664,
63,
698,
63,
1810,
8,
698,
304,
272,
19671,
275,
901,
14,
362,
63,
533,
63,
354,
3430,
17,
6809,
17,
467,
901,
14,
362,
63,
354,
1062,
901,
14,
362,
63,
4120,
342,
339,
5348,
275,
488,
272,
340,
901,
14,
826,
63,
585,
26,
267,
1139,
275,
901,
14,
826,
63,
585,
14,
585,
267,
5348,
275,
7283,
8,
495,
8,
637,
430,
398,
340,
1139,
365,
440,
488,
26,
288,
340,
901,
14,
362,
63,
4120,
342,
508,
283,
24457,
15,
4159,
15,
1558,
6015,
355,
5348,
275,
8785,
63,
875,
8,
637,
9,
288,
916,
901,
14,
2625,
508,
283,
34,
356,
355,
5348,
275,
8785,
63,
4097,
63,
442,
8,
1820,
14,
5301,
4827,
66,
297,
1139,
2788,
16,
566,
339,
372,
469,
267,
283,
19956,
356,
19671,
12,
267,
283,
466,
356,
2198,
63,
4120,
8,
698,
14,
362,
63,
4120,
4000,
267,
283,
2469,
356,
4884,
14,
362,
63,
2732,
63,
698,
8,
698,
14,
362,
63,
2732,
63,
2469,
4000,
267,
283,
3684,
356,
5348,
12,
272,
789,
199,
199,
533,
577,
86,
3767,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
12750,
10466,
304,
267,
1083,
275,
12750,
10466,
14,
362,
63,
765,
342,
267,
291,
14,
765,
275,
1083,
267,
291,
14,
928,
63,
1457,
275,
2163,
8,
5247,
10466,
14,
362,
63,
4316,
63,
4166,
1252,
362,
1062,
488,
9,
267,
291,
14,
1886,
63,
354,
275,
1083,
14,
362,
63,
533,
63,
354,
342,
267,
291,
14,
354,
275,
1083,
14,
362,
63,
354,
342,
267,
291,
14,
76,
1162,
275,
942,
267,
291,
14,
1391,
63,
475,
63,
354,
275,
10018,
342,
267,
291,
14,
5491,
275,
488,
267,
291,
14,
2180,
275,
488,
267,
291,
14,
1810,
275,
488,
398,
291,
14,
2732,
275,
4884,
14,
362,
63,
2732,
63,
765,
8,
765,
14,
362,
63,
2732,
63,
2469,
1012,
398,
4328,
275,
1083,
14,
362,
63,
4120,
342,
267,
291,
14,
466,
275,
4328,
14,
1294,
15938,
358,
1988,
17,
61,
267,
291,
14,
1162,
63,
466,
275,
4884,
14,
362,
63,
1162,
63,
466,
8,
3257,
9,
267,
291,
14,
19956,
275,
1083,
14,
362,
63,
19956,
342,
398,
291,
14,
3924,
275,
12750,
10466,
14,
3924,
14,
3924,
398,
1233,
275,
1083,
14,
362,
63,
600,
342,
267,
340,
1233,
365,
488,
26,
288,
2512,
14,
1757,
360,
1944,
1233,
520,
450,
83,
450,
83,
297,
291,
14,
354,
12,
291,
14,
1886,
63,
354,
9,
267,
587,
26,
288,
1343,
275,
1233,
14,
30792,
63,
890,
446,
1233,
14,
3617,
63,
890,
288,
340,
283,
1986,
7,
440,
315,
291,
14,
2732,
26,
355,
291,
14,
1391,
63,
475,
63,
354,
59,
928,
61,
275,
961,
4098,
8,
928,
12,
291,
14,
1886
] |
[
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
6029,
5346,
1997,
4813,
598,
310,
6051,
287,
665,
303,
1997,
4813,
14,
71,
310,
6051,
287,
32,
6799,
14,
957,
30,
199,
3,
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,
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,
13,
1311,
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,
646,
984,
199,
1274,
14,
515,
14,
740,
5175,
6217,
199,
199,
646,
2050,
199,
646,
2702,
199,
504,
5055,
492,
10018,
199,
646,
436,
293,
15606,
14,
1018,
14,
460,
293,
2190,
465,
436,
293,
2190,
199,
646,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
1974,
465,
4884,
199,
504,
436,
293,
15606,
14,
1018,
14,
10466,
492,
11284,
199,
504,
436,
293,
15606,
14,
1018,
14,
4414,
6021,
492,
31528,
12,
366,
2611,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
1810,
492,
334,
6243,
6261,
12,
2198,
63,
4120,
12,
272,
8785,
63,
875,
12,
8785,
63,
2307,
12,
8785,
63,
442,
12,
8785,
63,
2809,
12,
8785,
63,
1609,
12,
272,
8785,
63,
3157,
12,
8785,
63,
2245,
12,
8785,
63,
4097,
63,
442,
12,
7283,
9,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
2785,
63,
1659,
492,
10405,
63,
13547,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
576,
1659,
492,
334,
1506,
63,
318,
63,
1180,
12,
6059,
4192,
63,
21200,
12,
6059,
12314,
63,
600,
63,
69,
13769,
425,
12,
6059,
2274,
63,
13535,
12,
6059,
3715,
63,
3669,
9,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
2180,
492,
6982,
12,
15037,
12,
3715,
63,
692,
63,
2415,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
22880,
492,
12608,
12,
961,
4098,
199,
504,
436,
293,
15606,
14,
271,
5772,
14,
25805,
14,
5491,
492,
24441,
199,
504,
436,
293,
15606,
14,
1974,
492,
1586,
421,
199,
318,
2599,
63,
2611,
8,
1501,
304,
272,
2203,
275,
436,
293,
2190,
14,
374,
63,
6238,
8,
1501,
9,
272,
340,
2203,
508,
283,
1282,
43,
356,
267,
372,
366,
2611,
14,
36,
279,
433,
75,
6849,
3484,
8,
23582,
14,
1282,
43,
8,
1501,
680,
362,
63,
731,
1012,
272,
916,
2203,
508,
283,
7746,
356,
267,
372,
366,
2611,
14,
36,
279,
433,
75,
6849,
3484,
8,
739,
8,
1501,
430,
272,
916,
2203,
508,
283,
47,
7746,
356,
267,
372,
366,
2611,
14,
36,
279,
433,
75,
47,
731,
6849,
3484,
8,
739,
8,
1501,
430,
272,
372,
488,
199,
199,
3,
3091,
542,
529,
323,
577,
86,
792,
1021,
5544,
199,
318,
664,
63,
698,
63,
1810,
8,
698,
304,
272,
19671,
275,
901,
14,
362,
63,
533,
63,
354,
3430,
17,
6809,
17,
467,
901,
14,
362,
63,
354,
1062,
901,
14,
362,
63,
4120,
342,
339,
5348,
275,
488,
272,
340,
901,
14,
826,
63,
585,
26,
267,
1139,
275,
901,
14,
826,
63,
585,
14,
585,
267,
5348,
275,
7283,
8,
495,
8,
637,
430,
398,
340,
1139,
365,
440,
488,
26,
288,
340,
901,
14,
362,
63,
4120,
342,
508,
283,
24457,
15,
4159,
15,
1558,
6015,
355,
5348,
275,
8785,
63,
875,
8,
637,
9,
288,
916,
901,
14,
2625,
508,
283,
34,
356,
355,
5348,
275,
8785,
63,
4097,
63,
442,
8,
1820,
14,
5301,
4827,
66,
297,
1139,
2788,
16,
566,
339,
372,
469,
267,
283,
19956,
356,
19671,
12,
267,
283,
466,
356,
2198,
63,
4120,
8,
698,
14,
362,
63,
4120,
4000,
267,
283,
2469,
356,
4884,
14,
362,
63,
2732,
63,
698,
8,
698,
14,
362,
63,
2732,
63,
2469,
4000,
267,
283,
3684,
356,
5348,
12,
272,
789,
199,
199,
533,
577,
86,
3767,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
12750,
10466,
304,
267,
1083,
275,
12750,
10466,
14,
362,
63,
765,
342,
267,
291,
14,
765,
275,
1083,
267,
291,
14,
928,
63,
1457,
275,
2163,
8,
5247,
10466,
14,
362,
63,
4316,
63,
4166,
1252,
362,
1062,
488,
9,
267,
291,
14,
1886,
63,
354,
275,
1083,
14,
362,
63,
533,
63,
354,
342,
267,
291,
14,
354,
275,
1083,
14,
362,
63,
354,
342,
267,
291,
14,
76,
1162,
275,
942,
267,
291,
14,
1391,
63,
475,
63,
354,
275,
10018,
342,
267,
291,
14,
5491,
275,
488,
267,
291,
14,
2180,
275,
488,
267,
291,
14,
1810,
275,
488,
398,
291,
14,
2732,
275,
4884,
14,
362,
63,
2732,
63,
765,
8,
765,
14,
362,
63,
2732,
63,
2469,
1012,
398,
4328,
275,
1083,
14,
362,
63,
4120,
342,
267,
291,
14,
466,
275,
4328,
14,
1294,
15938,
358,
1988,
17,
61,
267,
291,
14,
1162,
63,
466,
275,
4884,
14,
362,
63,
1162,
63,
466,
8,
3257,
9,
267,
291,
14,
19956,
275,
1083,
14,
362,
63,
19956,
342,
398,
291,
14,
3924,
275,
12750,
10466,
14,
3924,
14,
3924,
398,
1233,
275,
1083,
14,
362,
63,
600,
342,
267,
340,
1233,
365,
488,
26,
288,
2512,
14,
1757,
360,
1944,
1233,
520,
450,
83,
450,
83,
297,
291,
14,
354,
12,
291,
14,
1886,
63,
354,
9,
267,
587,
26,
288,
1343,
275,
1233,
14,
30792,
63,
890,
446,
1233,
14,
3617,
63,
890,
288,
340,
283,
1986,
7,
440,
315,
291,
14,
2732,
26,
355,
291,
14,
1391,
63,
475,
63,
354,
59,
928,
61,
275,
961,
4098,
8,
928,
12,
291,
14,
1886,
0
] |
[
1,
1,
1,
1,
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ashrn.github.io
|
node_modules/pygmentize-bundled/vendor/pygments/pygments/lexers/_postgres_builtins.py
|
269
|
9648
|
# -*- coding: utf-8 -*-
"""
pygments.lexers._postgres_builtins
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Self-updating data files for PostgreSQL lexer.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import urllib
# One man's constant is another man's variable.
SOURCE_URL = 'https://github.com/postgres/postgres/raw/master'
KEYWORDS_URL = SOURCE_URL + '/doc/src/sgml/keywords.sgml'
DATATYPES_URL = SOURCE_URL + '/doc/src/sgml/datatype.sgml'
def update_myself():
data_file = list(fetch(DATATYPES_URL))
datatypes = parse_datatypes(data_file)
pseudos = parse_pseudos(data_file)
keywords = parse_keywords(fetch(KEYWORDS_URL))
update_consts(__file__, 'DATATYPES', datatypes)
update_consts(__file__, 'PSEUDO_TYPES', pseudos)
update_consts(__file__, 'KEYWORDS', keywords)
def parse_keywords(f):
kw = []
for m in re.finditer(
r'\s*<entry><token>([^<]+)</token></entry>\s*'
r'<entry>([^<]+)</entry>', f.read()):
kw.append(m.group(1))
if not kw:
raise ValueError('no keyword found')
kw.sort()
return kw
def parse_datatypes(f):
dt = set()
for line in f:
if '<sect1' in line:
break
if '<entry><type>' not in line:
continue
# Parse a string such as
# time [ (<replaceable>p</replaceable>) ] [ without time zone ]
# into types "time" and "without time zone"
# remove all the tags
line = re.sub("<replaceable>[^<]+</replaceable>", "", line)
line = re.sub("<[^>]+>", "", line)
# Drop the parts containing braces
for tmp in [t for tmp in line.split('[')
for t in tmp.split(']') if "(" not in t]:
for t in tmp.split(','):
t = t.strip()
if not t: continue
dt.add(" ".join(t.split()))
dt = list(dt)
dt.sort()
return dt
def parse_pseudos(f):
dt = []
re_start = re.compile(r'\s*<table id="datatype-pseudotypes-table">')
re_entry = re.compile(r'\s*<entry><type>([^<]+)</></entry>')
re_end = re.compile(r'\s*</table>')
f = iter(f)
for line in f:
if re_start.match(line) is not None:
break
else:
raise ValueError('pseudo datatypes table not found')
for line in f:
m = re_entry.match(line)
if m is not None:
dt.append(m.group(1))
if re_end.match(line) is not None:
break
else:
raise ValueError('end of pseudo datatypes table not found')
if not dt:
raise ValueError('pseudo datatypes not found')
return dt
def fetch(url):
return urllib.urlopen(url)
def update_consts(filename, constname, content):
f = open(filename)
lines = f.readlines()
f.close()
# Line to start/end inserting
re_start = re.compile(r'^%s\s*=\s*\[\s*$' % constname)
re_end = re.compile(r'^\s*\]\s*$')
start = [ n for n, l in enumerate(lines) if re_start.match(l) ]
if not start:
raise ValueError("couldn't find line containing '%s = ['" % constname)
if len(start) > 1:
raise ValueError("too many lines containing '%s = ['" % constname)
start = start[0] + 1
end = [ n for n, l in enumerate(lines) if n >= start and re_end.match(l) ]
if not end:
raise ValueError("couldn't find line containing ']' after %s " % constname)
end = end[0]
# Pack the new content in lines not too long
content = [repr(item) for item in content ]
new_lines = [[]]
for item in content:
if sum(map(len, new_lines[-1])) + 2 * len(new_lines[-1]) + len(item) + 4 > 75:
new_lines.append([])
new_lines[-1].append(item)
lines[start:end] = [ " %s,\n" % ", ".join(items) for items in new_lines ]
f = open(filename, 'w')
f.write(''.join(lines))
f.close()
# Autogenerated: please edit them if you like wasting your time.
KEYWORDS = [
'ABORT', 'ABSOLUTE', 'ACCESS', 'ACTION', 'ADD', 'ADMIN', 'AFTER',
'AGGREGATE', 'ALL', 'ALSO', 'ALTER', 'ALWAYS', 'ANALYSE', 'ANALYZE',
'AND', 'ANY', 'ARRAY', 'AS', 'ASC', 'ASSERTION', 'ASSIGNMENT',
'ASYMMETRIC', 'AT', 'ATTRIBUTE', 'AUTHORIZATION', 'BACKWARD', 'BEFORE',
'BEGIN', 'BETWEEN', 'BIGINT', 'BINARY', 'BIT', 'BOOLEAN', 'BOTH', 'BY',
'CACHE', 'CALLED', 'CASCADE', 'CASCADED', 'CASE', 'CAST', 'CATALOG',
'CHAIN', 'CHAR', 'CHARACTER', 'CHARACTERISTICS', 'CHECK', 'CHECKPOINT',
'CLASS', 'CLOSE', 'CLUSTER', 'COALESCE', 'COLLATE', 'COLLATION',
'COLUMN', 'COMMENT', 'COMMENTS', 'COMMIT', 'COMMITTED', 'CONCURRENTLY',
'CONFIGURATION', 'CONNECTION', 'CONSTRAINT', 'CONSTRAINTS', 'CONTENT',
'CONTINUE', 'CONVERSION', 'COPY', 'COST', 'CREATE', 'CROSS', 'CSV',
'CURRENT', 'CURRENT_CATALOG', 'CURRENT_DATE', 'CURRENT_ROLE',
'CURRENT_SCHEMA', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'CURRENT_USER',
'CURSOR', 'CYCLE', 'DATA', 'DATABASE', 'DAY', 'DEALLOCATE', 'DEC',
'DECIMAL', 'DECLARE', 'DEFAULT', 'DEFAULTS', 'DEFERRABLE', 'DEFERRED',
'DEFINER', 'DELETE', 'DELIMITER', 'DELIMITERS', 'DESC', 'DICTIONARY',
'DISABLE', 'DISCARD', 'DISTINCT', 'DO', 'DOCUMENT', 'DOMAIN', 'DOUBLE',
'DROP', 'EACH', 'ELSE', 'ENABLE', 'ENCODING', 'ENCRYPTED', 'END',
'ENUM', 'ESCAPE', 'EXCEPT', 'EXCLUDE', 'EXCLUDING', 'EXCLUSIVE',
'EXECUTE', 'EXISTS', 'EXPLAIN', 'EXTENSION', 'EXTERNAL', 'EXTRACT',
'FALSE', 'FAMILY', 'FETCH', 'FIRST', 'FLOAT', 'FOLLOWING', 'FOR',
'FORCE', 'FOREIGN', 'FORWARD', 'FREEZE', 'FROM', 'FULL', 'FUNCTION',
'FUNCTIONS', 'GLOBAL', 'GRANT', 'GRANTED', 'GREATEST', 'GROUP',
'HANDLER', 'HAVING', 'HEADER', 'HOLD', 'HOUR', 'IDENTITY', 'IF',
'ILIKE', 'IMMEDIATE', 'IMMUTABLE', 'IMPLICIT', 'IN', 'INCLUDING',
'INCREMENT', 'INDEX', 'INDEXES', 'INHERIT', 'INHERITS', 'INITIALLY',
'INLINE', 'INNER', 'INOUT', 'INPUT', 'INSENSITIVE', 'INSERT', 'INSTEAD',
'INT', 'INTEGER', 'INTERSECT', 'INTERVAL', 'INTO', 'INVOKER', 'IS',
'ISNULL', 'ISOLATION', 'JOIN', 'KEY', 'LABEL', 'LANGUAGE', 'LARGE',
'LAST', 'LC_COLLATE', 'LC_CTYPE', 'LEADING', 'LEAST', 'LEFT', 'LEVEL',
'LIKE', 'LIMIT', 'LISTEN', 'LOAD', 'LOCAL', 'LOCALTIME',
'LOCALTIMESTAMP', 'LOCATION', 'LOCK', 'MAPPING', 'MATCH', 'MAXVALUE',
'MINUTE', 'MINVALUE', 'MODE', 'MONTH', 'MOVE', 'NAME', 'NAMES',
'NATIONAL', 'NATURAL', 'NCHAR', 'NEXT', 'NO', 'NONE', 'NOT', 'NOTHING',
'NOTIFY', 'NOTNULL', 'NOWAIT', 'NULL', 'NULLIF', 'NULLS', 'NUMERIC',
'OBJECT', 'OF', 'OFF', 'OFFSET', 'OIDS', 'ON', 'ONLY', 'OPERATOR',
'OPTION', 'OPTIONS', 'OR', 'ORDER', 'OUT', 'OUTER', 'OVER', 'OVERLAPS',
'OVERLAY', 'OWNED', 'OWNER', 'PARSER', 'PARTIAL', 'PARTITION',
'PASSING', 'PASSWORD', 'PLACING', 'PLANS', 'POSITION', 'PRECEDING',
'PRECISION', 'PREPARE', 'PREPARED', 'PRESERVE', 'PRIMARY', 'PRIOR',
'PRIVILEGES', 'PROCEDURAL', 'PROCEDURE', 'QUOTE', 'RANGE', 'READ',
'REAL', 'REASSIGN', 'RECHECK', 'RECURSIVE', 'REF', 'REFERENCES',
'REINDEX', 'RELATIVE', 'RELEASE', 'RENAME', 'REPEATABLE', 'REPLACE',
'REPLICA', 'RESET', 'RESTART', 'RESTRICT', 'RETURNING', 'RETURNS',
'REVOKE', 'RIGHT', 'ROLE', 'ROLLBACK', 'ROW', 'ROWS', 'RULE',
'SAVEPOINT', 'SCHEMA', 'SCROLL', 'SEARCH', 'SECOND', 'SECURITY',
'SELECT', 'SEQUENCE', 'SEQUENCES', 'SERIALIZABLE', 'SERVER', 'SESSION',
'SESSION_USER', 'SET', 'SETOF', 'SHARE', 'SHOW', 'SIMILAR', 'SIMPLE',
'SMALLINT', 'SOME', 'STABLE', 'STANDALONE', 'START', 'STATEMENT',
'STATISTICS', 'STDIN', 'STDOUT', 'STORAGE', 'STRICT', 'STRIP',
'SUBSTRING', 'SYMMETRIC', 'SYSID', 'SYSTEM', 'TABLE', 'TABLES',
'TABLESPACE', 'TEMP', 'TEMPLATE', 'TEMPORARY', 'TEXT', 'THEN', 'TIME',
'TIMESTAMP', 'TO', 'TRAILING', 'TRANSACTION', 'TREAT', 'TRIGGER',
'TRIM', 'TRUE', 'TRUNCATE', 'TRUSTED', 'TYPE', 'UNBOUNDED',
'UNCOMMITTED', 'UNENCRYPTED', 'UNION', 'UNIQUE', 'UNKNOWN', 'UNLISTEN',
'UNLOGGED', 'UNTIL', 'UPDATE', 'USER', 'USING', 'VACUUM', 'VALID',
'VALIDATE', 'VALIDATOR', 'VALUE', 'VALUES', 'VARCHAR', 'VARIADIC',
'VARYING', 'VERBOSE', 'VERSION', 'VIEW', 'VOLATILE', 'WHEN', 'WHERE',
'WHITESPACE', 'WINDOW', 'WITH', 'WITHOUT', 'WORK', 'WRAPPER', 'WRITE',
'XML', 'XMLATTRIBUTES', 'XMLCONCAT', 'XMLELEMENT', 'XMLEXISTS',
'XMLFOREST', 'XMLPARSE', 'XMLPI', 'XMLROOT', 'XMLSERIALIZE', 'YEAR',
'YES', 'ZONE',
]
DATATYPES = [
'bigint', 'bigserial', 'bit', 'bit varying', 'bool', 'boolean', 'box',
'bytea', 'char', 'character', 'character varying', 'cidr', 'circle',
'date', 'decimal', 'double precision', 'float4', 'float8', 'inet',
'int', 'int2', 'int4', 'int8', 'integer', 'interval', 'json', 'line',
'lseg', 'macaddr', 'money', 'numeric', 'path', 'point', 'polygon',
'real', 'serial', 'serial2', 'serial4', 'serial8', 'smallint',
'smallserial', 'text', 'time', 'timestamp', 'timestamptz', 'timetz',
'tsquery', 'tsvector', 'txid_snapshot', 'uuid', 'varbit', 'varchar',
'with time zone', 'without time zone', 'xml',
]
PSEUDO_TYPES = [
'any', 'anyelement', 'anyarray', 'anynonarray', 'anyenum', 'anyrange',
'cstring', 'internal', 'language_handler', 'fdw_handler', 'record',
'trigger', 'void', 'opaque',
]
# Remove 'trigger' from types
PSEUDO_TYPES = sorted(set(PSEUDO_TYPES) - set(map(str.lower, KEYWORDS)))
PLPGSQL_KEYWORDS = [
'ALIAS', 'CONSTANT', 'DIAGNOSTICS', 'ELSIF', 'EXCEPTION', 'EXIT',
'FOREACH', 'GET', 'LOOP', 'NOTICE', 'OPEN', 'PERFORM', 'QUERY', 'RAISE',
'RETURN', 'REVERSE', 'SQLSTATE', 'WHILE',
]
if __name__ == '__main__':
update_myself()
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
423,
10675,
63,
10372,
272,
18294,
9753,
1714,
339,
23820,
13,
28669,
666,
1584,
367,
20175,
10426,
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,
646,
4011,
199,
199,
3,
7309,
2169,
1159,
4413,
365,
4573,
2169,
1159,
1750,
14,
199,
10187,
63,
2632,
275,
283,
2859,
921,
5031,
14,
957,
15,
10675,
15,
10675,
15,
1773,
15,
4133,
7,
199,
32187,
63,
2632,
275,
25470,
63,
2632,
435,
1994,
1301,
15,
2164,
15,
1226,
757,
15,
7511,
14,
1226,
757,
7,
199,
6521,
619,
24583,
63,
2632,
275,
25470,
63,
2632,
435,
1994,
1301,
15,
2164,
15,
1226,
757,
15,
14184,
14,
1226,
757,
7,
199,
199,
318,
1678,
63,
1662,
277,
837,
272,
666,
63,
493,
275,
769,
8,
3535,
8,
6521,
619,
24583,
63,
2632,
430,
272,
16048,
83,
275,
2198,
63,
14184,
83,
8,
576,
63,
493,
9,
272,
299,
261,
1181,
736,
275,
2198,
63,
80,
261,
1181,
736,
8,
576,
63,
493,
9,
339,
7681,
275,
2198,
63,
7511,
8,
3535,
8,
32187,
63,
2632,
430,
272,
1678,
63,
20473,
3460,
493,
3108,
283,
6521,
619,
24583,
297,
16048,
83,
9,
272,
1678,
63,
20473,
3460,
493,
3108,
283,
48,
899,
53,
1649,
63,
7893,
297,
299,
261,
1181,
736,
9,
272,
1678,
63,
20473,
3460,
493,
3108,
283,
32187,
297,
7681,
9,
199,
199,
318,
2198,
63,
7511,
8,
70,
304,
272,
4775,
275,
942,
272,
367,
333,
315,
295,
14,
19373,
8,
288,
519,
1154,
83,
10,
28,
2373,
2535,
1418,
30,
31204,
11896,
1108,
1418,
2957,
2373,
3072,
83,
10223,
288,
519,
7601,
2373,
30,
31204,
11896,
1108,
2373,
4206,
289,
14,
739,
5109,
267,
4775,
14,
740,
8,
77,
14,
923,
8,
17,
430,
339,
340,
440,
4775,
26,
267,
746,
1722,
360,
889,
4252,
1911,
358,
339,
4775,
14,
3191,
342,
272,
372,
4775,
199,
199,
318,
2198,
63,
14184,
83,
8,
70,
304,
272,
4487,
275,
663,
342,
272,
367,
1004,
315,
289,
26,
267,
340,
2650,
8519,
17,
7,
315,
1004,
26,
288,
2059,
267,
340,
2650,
2373,
2535,
466,
3524,
440,
315,
1004,
26,
288,
1980,
398,
327,
6077,
282,
1059,
4066,
465,
267,
327,
900,
359,
8642,
1814,
461,
30,
80,
1108,
1814,
461,
18956,
1622,
359,
1928,
900,
5718,
1622,
267,
327,
1901,
2943,
298,
521,
2,
436,
298,
7395,
900,
5718,
2,
398,
327,
2813,
1006,
314,
3762,
267,
1004,
275,
295,
14,
954,
6757,
1814,
461,
13489,
28,
2807,
1108,
1814,
461,
7166,
4873,
1004,
9,
267,
1004,
275,
295,
14,
954,
6757,
25524,
7166,
4873,
1004,
9,
398,
327,
18110,
314,
4184,
3035,
27158,
267,
367,
3529,
315,
359,
84,
367,
3529,
315,
1004,
14,
1294,
11894,
358,
490,
367,
307,
315,
3529,
14,
1294,
360,
10374,
340,
26054,
440,
315,
307,
2189,
288,
367,
307,
315,
3529,
14,
1294,
25908,
355,
307,
275,
307,
14,
1913,
342,
355,
340,
440,
307,
26,
1980,
355,
4487,
14,
525,
480,
3680,
904,
8,
84,
14,
1294,
4059,
339,
4487,
275,
769,
8,
3583,
9,
272,
4487,
14,
3191,
342,
272,
372,
4487,
199,
199,
318,
2198,
63,
80,
261,
1181,
736,
8,
70,
304,
272,
4487,
275,
942,
272,
295,
63,
928,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
28,
1224,
1305,
628,
14184,
13,
80,
261,
1181,
27760,
13,
1224,
1743,
358,
272,
295,
63,
2373,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
28,
2373,
2535,
466,
30,
31204,
11896,
1108,
2957,
2373,
5971,
272,
295,
63,
500,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
1108,
1224,
5971,
339,
289,
275,
2740,
8,
70,
9,
272,
367,
1004,
315,
289,
26,
267,
340,
295,
63,
928,
14,
1431,
8,
604,
9,
365,
440,
488,
26,
288,
2059,
272,
587,
26,
267,
746,
1722,
360,
22490,
16048,
83,
1817,
440,
1911,
358,
339,
367,
1004,
315,
289,
26,
267,
333,
275,
295,
63,
2373,
14,
1431,
8,
604,
9,
267,
340,
333,
365,
440,
488,
26,
288,
4487,
14,
740,
8,
77,
14,
923,
8,
17,
430,
398,
340,
295,
63,
500,
14,
1431,
8,
604,
9,
365,
440,
488,
26,
288,
2059,
272,
587,
26,
267,
746,
1722,
360,
500,
402,
15984,
16048,
83,
1817,
440,
1911,
358,
339,
340,
440,
4487,
26,
267,
746,
1722,
360,
22490,
16048,
83,
440,
1911,
358,
339,
372,
4487,
199,
199,
318,
5267,
8,
633,
304,
272,
372,
4011,
14,
10890,
8,
633,
9,
199,
199,
318,
1678,
63,
20473,
8,
1501,
12,
950,
354,
12,
1564,
304,
272,
289,
275,
1551,
8,
1501,
9,
272,
2385,
275,
289,
14,
9684,
342,
272,
289,
14,
1600,
342,
339,
327,
7030,
370,
1343,
15,
500,
28498,
272,
295,
63,
928,
275,
295,
14,
2014,
8,
82,
4289,
5,
83,
60,
83,
23440,
83,
7590,
7023,
83,
10,
12913,
450,
950,
354,
9,
272,
295,
63,
500,
275,
295,
14,
2014,
8,
82,
15542,
83,
7590,
7272,
83,
10,
9988,
272,
1343,
275,
359,
302,
367,
302,
12,
634,
315,
3874,
8,
1278,
9,
340,
295,
63,
928,
14,
1431,
8,
76,
9,
1622,
272,
340,
440,
1343,
26,
267,
746,
1722,
480,
15153,
78,
1133,
2342,
1004,
3035,
1543,
83,
275,
788,
2,
450,
950,
354,
9,
272,
340,
822,
8,
928,
9,
690,
413,
26,
267,
746,
1722,
480,
7354,
5002,
2385,
3035,
1543,
83,
275,
788,
2,
450,
950,
354,
9,
272,
1343,
275,
1343,
59,
16,
61,
435,
413,
339,
1284,
275,
359,
302,
367,
302,
12,
634,
315,
3874,
8,
1278,
9,
340,
302,
2356,
1343,
436,
295,
63,
500,
14,
1431,
8,
76,
9,
1622,
272,
340,
440,
1284,
26,
267,
746,
1722,
480,
15153,
78,
1133,
2342,
1004,
3035,
24840,
2410,
450,
83,
298,
450,
950,
354,
9,
272,
1284,
275,
1284,
59,
16,
61,
339,
327,
9954,
314,
892,
1564,
315,
2385,
440,
4634,
1846,
272,
1564,
275,
359,
2722,
8,
1053,
9,
367,
1242
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
423,
10675,
63,
10372,
272,
18294,
9753,
1714,
339,
23820,
13,
28669,
666,
1584,
367,
20175,
10426,
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,
646,
4011,
199,
199,
3,
7309,
2169,
1159,
4413,
365,
4573,
2169,
1159,
1750,
14,
199,
10187,
63,
2632,
275,
283,
2859,
921,
5031,
14,
957,
15,
10675,
15,
10675,
15,
1773,
15,
4133,
7,
199,
32187,
63,
2632,
275,
25470,
63,
2632,
435,
1994,
1301,
15,
2164,
15,
1226,
757,
15,
7511,
14,
1226,
757,
7,
199,
6521,
619,
24583,
63,
2632,
275,
25470,
63,
2632,
435,
1994,
1301,
15,
2164,
15,
1226,
757,
15,
14184,
14,
1226,
757,
7,
199,
199,
318,
1678,
63,
1662,
277,
837,
272,
666,
63,
493,
275,
769,
8,
3535,
8,
6521,
619,
24583,
63,
2632,
430,
272,
16048,
83,
275,
2198,
63,
14184,
83,
8,
576,
63,
493,
9,
272,
299,
261,
1181,
736,
275,
2198,
63,
80,
261,
1181,
736,
8,
576,
63,
493,
9,
339,
7681,
275,
2198,
63,
7511,
8,
3535,
8,
32187,
63,
2632,
430,
272,
1678,
63,
20473,
3460,
493,
3108,
283,
6521,
619,
24583,
297,
16048,
83,
9,
272,
1678,
63,
20473,
3460,
493,
3108,
283,
48,
899,
53,
1649,
63,
7893,
297,
299,
261,
1181,
736,
9,
272,
1678,
63,
20473,
3460,
493,
3108,
283,
32187,
297,
7681,
9,
199,
199,
318,
2198,
63,
7511,
8,
70,
304,
272,
4775,
275,
942,
272,
367,
333,
315,
295,
14,
19373,
8,
288,
519,
1154,
83,
10,
28,
2373,
2535,
1418,
30,
31204,
11896,
1108,
1418,
2957,
2373,
3072,
83,
10223,
288,
519,
7601,
2373,
30,
31204,
11896,
1108,
2373,
4206,
289,
14,
739,
5109,
267,
4775,
14,
740,
8,
77,
14,
923,
8,
17,
430,
339,
340,
440,
4775,
26,
267,
746,
1722,
360,
889,
4252,
1911,
358,
339,
4775,
14,
3191,
342,
272,
372,
4775,
199,
199,
318,
2198,
63,
14184,
83,
8,
70,
304,
272,
4487,
275,
663,
342,
272,
367,
1004,
315,
289,
26,
267,
340,
2650,
8519,
17,
7,
315,
1004,
26,
288,
2059,
267,
340,
2650,
2373,
2535,
466,
3524,
440,
315,
1004,
26,
288,
1980,
398,
327,
6077,
282,
1059,
4066,
465,
267,
327,
900,
359,
8642,
1814,
461,
30,
80,
1108,
1814,
461,
18956,
1622,
359,
1928,
900,
5718,
1622,
267,
327,
1901,
2943,
298,
521,
2,
436,
298,
7395,
900,
5718,
2,
398,
327,
2813,
1006,
314,
3762,
267,
1004,
275,
295,
14,
954,
6757,
1814,
461,
13489,
28,
2807,
1108,
1814,
461,
7166,
4873,
1004,
9,
267,
1004,
275,
295,
14,
954,
6757,
25524,
7166,
4873,
1004,
9,
398,
327,
18110,
314,
4184,
3035,
27158,
267,
367,
3529,
315,
359,
84,
367,
3529,
315,
1004,
14,
1294,
11894,
358,
490,
367,
307,
315,
3529,
14,
1294,
360,
10374,
340,
26054,
440,
315,
307,
2189,
288,
367,
307,
315,
3529,
14,
1294,
25908,
355,
307,
275,
307,
14,
1913,
342,
355,
340,
440,
307,
26,
1980,
355,
4487,
14,
525,
480,
3680,
904,
8,
84,
14,
1294,
4059,
339,
4487,
275,
769,
8,
3583,
9,
272,
4487,
14,
3191,
342,
272,
372,
4487,
199,
199,
318,
2198,
63,
80,
261,
1181,
736,
8,
70,
304,
272,
4487,
275,
942,
272,
295,
63,
928,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
28,
1224,
1305,
628,
14184,
13,
80,
261,
1181,
27760,
13,
1224,
1743,
358,
272,
295,
63,
2373,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
28,
2373,
2535,
466,
30,
31204,
11896,
1108,
2957,
2373,
5971,
272,
295,
63,
500,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
1108,
1224,
5971,
339,
289,
275,
2740,
8,
70,
9,
272,
367,
1004,
315,
289,
26,
267,
340,
295,
63,
928,
14,
1431,
8,
604,
9,
365,
440,
488,
26,
288,
2059,
272,
587,
26,
267,
746,
1722,
360,
22490,
16048,
83,
1817,
440,
1911,
358,
339,
367,
1004,
315,
289,
26,
267,
333,
275,
295,
63,
2373,
14,
1431,
8,
604,
9,
267,
340,
333,
365,
440,
488,
26,
288,
4487,
14,
740,
8,
77,
14,
923,
8,
17,
430,
398,
340,
295,
63,
500,
14,
1431,
8,
604,
9,
365,
440,
488,
26,
288,
2059,
272,
587,
26,
267,
746,
1722,
360,
500,
402,
15984,
16048,
83,
1817,
440,
1911,
358,
339,
340,
440,
4487,
26,
267,
746,
1722,
360,
22490,
16048,
83,
440,
1911,
358,
339,
372,
4487,
199,
199,
318,
5267,
8,
633,
304,
272,
372,
4011,
14,
10890,
8,
633,
9,
199,
199,
318,
1678,
63,
20473,
8,
1501,
12,
950,
354,
12,
1564,
304,
272,
289,
275,
1551,
8,
1501,
9,
272,
2385,
275,
289,
14,
9684,
342,
272,
289,
14,
1600,
342,
339,
327,
7030,
370,
1343,
15,
500,
28498,
272,
295,
63,
928,
275,
295,
14,
2014,
8,
82,
4289,
5,
83,
60,
83,
23440,
83,
7590,
7023,
83,
10,
12913,
450,
950,
354,
9,
272,
295,
63,
500,
275,
295,
14,
2014,
8,
82,
15542,
83,
7590,
7272,
83,
10,
9988,
272,
1343,
275,
359,
302,
367,
302,
12,
634,
315,
3874,
8,
1278,
9,
340,
295,
63,
928,
14,
1431,
8,
76,
9,
1622,
272,
340,
440,
1343,
26,
267,
746,
1722,
480,
15153,
78,
1133,
2342,
1004,
3035,
1543,
83,
275,
788,
2,
450,
950,
354,
9,
272,
340,
822,
8,
928,
9,
690,
413,
26,
267,
746,
1722,
480,
7354,
5002,
2385,
3035,
1543,
83,
275,
788,
2,
450,
950,
354,
9,
272,
1343,
275,
1343,
59,
16,
61,
435,
413,
339,
1284,
275,
359,
302,
367,
302,
12,
634,
315,
3874,
8,
1278,
9,
340,
302,
2356,
1343,
436,
295,
63,
500,
14,
1431,
8,
76,
9,
1622,
272,
340,
440,
1284,
26,
267,
746,
1722,
480,
15153,
78,
1133,
2342,
1004,
3035,
24840,
2410,
450,
83,
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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
] |
sarielsaz/sarielsaz
|
test/functional/test_framework/test_framework.py
|
1
|
20268
|
#!/usr/bin/env python3
# Copyright (c) 2014-2016 The Sarielsaz Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Base class for RPC testing."""
from collections import deque
from enum import Enum
import logging
import optparse
import os
import pdb
import shutil
import sys
import tempfile
import time
import traceback
from .authproxy import JSONRPCException
from . import coverage
from .test_node import TestNode
from .util import (
MAX_NODES,
PortSeed,
assert_equal,
check_json_precision,
connect_nodes_bi,
disconnect_nodes,
initialize_datadir,
log_filename,
p2p_port,
set_node_times,
sync_blocks,
sync_mempools,
)
class TestStatus(Enum):
PASSED = 1
FAILED = 2
SKIPPED = 3
TEST_EXIT_PASSED = 0
TEST_EXIT_FAILED = 1
TEST_EXIT_SKIPPED = 77
class SarielsazTestFramework():
"""Base class for a sarielsaz test script.
Individual sarielsaz test scripts should subclass this class and override the set_test_params() and run_test() methods.
Individual tests can also override the following methods to customize the test setup:
- add_options()
- setup_chain()
- setup_network()
- setup_nodes()
The __init__() and main() methods should not be overridden.
This class also contains various public and private helper methods."""
def __init__(self):
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
self.setup_clean_chain = False
self.nodes = []
self.mocktime = 0
self.set_test_params()
assert hasattr(self, "num_nodes"), "Test must set self.num_nodes in set_test_params()"
def main(self):
"""Main function. This should not be overridden by the subclass test scripts."""
parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
help="Leave sarielsazds and test.* datadir on exit or error")
parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true",
help="Don't stop sarielsazds after the test execution")
parser.add_option("--srcdir", dest="srcdir", default=os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../../../src"),
help="Source directory containing sarielsazd/sarielsaz-cli (default: %default)")
parser.add_option("--cachedir", dest="cachedir", default=os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
help="Directory for caching pregenerated datadirs")
parser.add_option("--tmpdir", dest="tmpdir", help="Root directory for datadirs")
parser.add_option("-l", "--loglevel", dest="loglevel", default="INFO",
help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory.")
parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true",
help="Print out all RPC calls as they are made")
parser.add_option("--portseed", dest="port_seed", default=os.getpid(), type='int',
help="The seed to use for assigning port numbers (default: current process id)")
parser.add_option("--coveragedir", dest="coveragedir",
help="Write tested RPC commands into this directory")
parser.add_option("--configfile", dest="configfile",
help="Location of the test framework config file")
parser.add_option("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
help="Attach a python debugger if test fails")
self.add_options(parser)
(self.options, self.args) = parser.parse_args()
PortSeed.n = self.options.port_seed
os.environ['PATH'] = self.options.srcdir + ":" + self.options.srcdir + "/qt:" + os.environ['PATH']
check_json_precision()
# Set up temp directory and start logging
if self.options.tmpdir:
os.makedirs(self.options.tmpdir, exist_ok=False)
else:
self.options.tmpdir = tempfile.mkdtemp(prefix="test")
self._start_logging()
success = TestStatus.FAILED
try:
self.setup_chain()
self.setup_network()
self.run_test()
success = TestStatus.PASSED
except JSONRPCException as e:
self.log.exception("JSONRPC error")
except SkipTest as e:
self.log.warning("Test Skipped: %s" % e.message)
success = TestStatus.SKIPPED
except AssertionError as e:
self.log.exception("Assertion failed")
except KeyError as e:
self.log.exception("Key error")
except Exception as e:
self.log.exception("Unexpected exception caught during testing")
except KeyboardInterrupt as e:
self.log.warning("Exiting after keyboard interrupt")
if success == TestStatus.FAILED and self.options.pdbonfailure:
print("Testcase failed. Attaching python debugger. Enter ? for help")
pdb.set_trace()
if not self.options.noshutdown:
self.log.info("Stopping nodes")
if self.nodes:
self.stop_nodes()
else:
self.log.info("Note: sarielsazds were not stopped and may still be running")
if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED:
self.log.info("Cleaning up")
shutil.rmtree(self.options.tmpdir)
else:
self.log.warning("Not cleaning up dir %s" % self.options.tmpdir)
if os.getenv("PYTHON_DEBUG", ""):
# Dump the end of the debug logs, to aid in debugging rare
# travis failures.
import glob
filenames = [self.options.tmpdir + "/test_framework.log"]
filenames += glob.glob(self.options.tmpdir + "/node*/regtest/debug.log")
MAX_LINES_TO_PRINT = 1000
for fn in filenames:
try:
with open(fn, 'r') as f:
print("From", fn, ":")
print("".join(deque(f, MAX_LINES_TO_PRINT)))
except OSError:
print("Opening file %s failed." % fn)
traceback.print_exc()
if success == TestStatus.PASSED:
self.log.info("Tests successful")
sys.exit(TEST_EXIT_PASSED)
elif success == TestStatus.SKIPPED:
self.log.info("Test skipped")
sys.exit(TEST_EXIT_SKIPPED)
else:
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
logging.shutdown()
sys.exit(TEST_EXIT_FAILED)
# Methods to override in subclass test scripts.
def set_test_params(self):
"""Tests must this method to change default values for number of nodes, topology, etc"""
raise NotImplementedError
def add_options(self, parser):
"""Override this method to add command-line options to the test"""
pass
def setup_chain(self):
"""Override this method to customize blockchain setup"""
self.log.info("Initializing test directory " + self.options.tmpdir)
if self.setup_clean_chain:
self._initialize_chain_clean()
else:
self._initialize_chain()
def setup_network(self):
"""Override this method to customize test network topology"""
self.setup_nodes()
# Connect the nodes as a "chain". This allows us
# to split the network between nodes 1 and 2 to get
# two halves that can work on competing chains.
for i in range(self.num_nodes - 1):
connect_nodes_bi(self.nodes, i, i + 1)
self.sync_all()
def setup_nodes(self):
"""Override this method to customize test node setup"""
extra_args = None
if hasattr(self, "extra_args"):
extra_args = self.extra_args
self.add_nodes(self.num_nodes, extra_args)
self.start_nodes()
def run_test(self):
"""Tests must override this method to define test logic"""
raise NotImplementedError
# Public helper methods. These can be accessed by the subclass test scripts.
def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
"""Instantiate TestNode objects"""
if extra_args is None:
extra_args = [[]] * num_nodes
if binary is None:
binary = [None] * num_nodes
assert_equal(len(extra_args), num_nodes)
assert_equal(len(binary), num_nodes)
for i in range(num_nodes):
self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir))
def start_node(self, i, extra_args=None, stderr=None):
"""Start a sarielsazd"""
node = self.nodes[i]
node.start(extra_args, stderr)
node.wait_for_rpc_connection()
if self.options.coveragedir is not None:
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
def start_nodes(self, extra_args=None):
"""Start multiple sarielsazds"""
if extra_args is None:
extra_args = [None] * self.num_nodes
assert_equal(len(extra_args), self.num_nodes)
try:
for i, node in enumerate(self.nodes):
node.start(extra_args[i])
for node in self.nodes:
node.wait_for_rpc_connection()
except:
# If one node failed to start, stop the others
self.stop_nodes()
raise
if self.options.coveragedir is not None:
for node in self.nodes:
coverage.write_all_rpc_commands(self.options.coveragedir, node.rpc)
def stop_node(self, i):
"""Stop a sarielsazd test node"""
self.nodes[i].stop_node()
self.nodes[i].wait_until_stopped()
def stop_nodes(self):
"""Stop multiple sarielsazd test nodes"""
for node in self.nodes:
# Issue RPC to stop nodes
node.stop_node()
for node in self.nodes:
# Wait for nodes to stop
node.wait_until_stopped()
def restart_node(self, i, extra_args=None):
"""Stop and start a test node"""
self.stop_node(i)
self.start_node(i, extra_args)
def assert_start_raises_init_error(self, i, extra_args=None, expected_msg=None):
with tempfile.SpooledTemporaryFile(max_size=2**16) as log_stderr:
try:
self.start_node(i, extra_args, stderr=log_stderr)
self.stop_node(i)
except Exception as e:
assert 'sarielsazd exited' in str(e) # node must have shutdown
self.nodes[i].running = False
self.nodes[i].process = None
if expected_msg is not None:
log_stderr.seek(0)
stderr = log_stderr.read().decode('utf-8')
if expected_msg not in stderr:
raise AssertionError("Expected error \"" + expected_msg + "\" not found in:\n" + stderr)
else:
if expected_msg is None:
assert_msg = "sarielsazd should have exited with an error"
else:
assert_msg = "sarielsazd should have exited with expected error " + expected_msg
raise AssertionError(assert_msg)
def wait_for_node_exit(self, i, timeout):
self.nodes[i].process.wait(timeout)
def split_network(self):
"""
Split the network of four nodes into nodes 0/1 and 2/3.
"""
disconnect_nodes(self.nodes[1], 2)
disconnect_nodes(self.nodes[2], 1)
self.sync_all([self.nodes[:2], self.nodes[2:]])
def join_network(self):
"""
Join the (previously split) network halves together.
"""
connect_nodes_bi(self.nodes, 1, 2)
self.sync_all()
def sync_all(self, node_groups=None):
if not node_groups:
node_groups = [self.nodes]
for group in node_groups:
sync_blocks(group)
sync_mempools(group)
def enable_mocktime(self):
"""Enable mocktime for the script.
mocktime may be needed for scripts that use the cached version of the
blockchain. If the cached version of the blockchain is used without
mocktime then the mempools will not sync due to IBD.
For backwared compatibility of the python scripts with previous
versions of the cache, this helper function sets mocktime to Jan 1,
2014 + (201 * 10 * 60)"""
self.mocktime = 1388534400 + (201 * 10 * 60)
def disable_mocktime(self):
self.mocktime = 0
# Private helper methods. These should not be accessed by the subclass test scripts.
def _start_logging(self):
# Add logger and logging handlers
self.log = logging.getLogger('TestFramework')
self.log.setLevel(logging.DEBUG)
# Create file handler to log all messages
fh = logging.FileHandler(self.options.tmpdir + '/test_framework.log')
fh.setLevel(logging.DEBUG)
# Create console handler to log messages to stderr. By default this logs only error messages, but can be configured with --loglevel.
ch = logging.StreamHandler(sys.stdout)
# User can provide log level as a number or string (eg DEBUG). loglevel was caught as a string, so try to convert it to an int
ll = int(self.options.loglevel) if self.options.loglevel.isdigit() else self.options.loglevel.upper()
ch.setLevel(ll)
# Format logs the same as sarielsazd's debug.log with microprecision (so log files can be concatenated and sorted)
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d000 %(name)s (%(levelname)s): %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
formatter.converter = time.gmtime
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
self.log.addHandler(fh)
self.log.addHandler(ch)
if self.options.trace_rpc:
rpc_logger = logging.getLogger("SarielsazRPC")
rpc_logger.setLevel(logging.DEBUG)
rpc_handler = logging.StreamHandler(sys.stdout)
rpc_handler.setLevel(logging.DEBUG)
rpc_logger.addHandler(rpc_handler)
def _initialize_chain(self):
"""Initialize a pre-mined blockchain for use by the test.
Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
Afterward, create num_nodes copies from the cache."""
assert self.num_nodes <= MAX_NODES
create_cache = False
for i in range(MAX_NODES):
if not os.path.isdir(os.path.join(self.options.cachedir, 'node' + str(i))):
create_cache = True
break
if create_cache:
self.log.debug("Creating data directories from cached datadir")
# find and delete old cache directories if any exist
for i in range(MAX_NODES):
if os.path.isdir(os.path.join(self.options.cachedir, "node" + str(i))):
shutil.rmtree(os.path.join(self.options.cachedir, "node" + str(i)))
# Create cache directories, run sarielsazds:
for i in range(MAX_NODES):
datadir = initialize_datadir(self.options.cachedir, i)
args = [os.getenv("SARIELSAZD", "sarielsazd"), "-server", "-keypool=1", "-datadir=" + datadir, "-discover=0"]
if i > 0:
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
self.nodes[i].args = args
self.start_node(i)
# Wait for RPC connections to be ready
for node in self.nodes:
node.wait_for_rpc_connection()
# Create a 200-block-long chain; each of the 4 first nodes
# gets 25 mature blocks and 25 immature.
# Note: To preserve compatibility with older versions of
# initialize_chain, only 4 nodes will generate coins.
#
# blocks are created with timestamps 10 minutes apart
# starting from 2010 minutes in the past
self.enable_mocktime()
block_time = self.mocktime - (201 * 10 * 60)
for i in range(2):
for peer in range(4):
for j in range(25):
set_node_times(self.nodes, block_time)
self.nodes[peer].generate(1)
block_time += 10 * 60
# Must sync before next peer starts generating blocks
sync_blocks(self.nodes)
# Shut them down, and clean up cache directories:
self.stop_nodes()
self.nodes = []
self.disable_mocktime()
for i in range(MAX_NODES):
os.remove(log_filename(self.options.cachedir, i, "debug.log"))
os.remove(log_filename(self.options.cachedir, i, "db.log"))
os.remove(log_filename(self.options.cachedir, i, "peers.dat"))
os.remove(log_filename(self.options.cachedir, i, "fee_estimates.dat"))
for i in range(self.num_nodes):
from_dir = os.path.join(self.options.cachedir, "node" + str(i))
to_dir = os.path.join(self.options.tmpdir, "node" + str(i))
shutil.copytree(from_dir, to_dir)
initialize_datadir(self.options.tmpdir, i) # Overwrite port/rpcport in sarielsaz.conf
def _initialize_chain_clean(self):
"""Initialize empty blockchain for use by the test.
Create an empty blockchain and num_nodes wallets.
Useful if a test case wants complete control over initialization."""
for i in range(self.num_nodes):
initialize_datadir(self.options.tmpdir, i)
class ComparisonTestFramework(SarielsazTestFramework):
"""Test framework for doing p2p comparison testing
Sets up some sarielsazd binaries:
- 1 binary: test binary
- 2 binaries: 1 test binary, 1 ref binary
- n>2 binaries: 1 test binary, n-1 ref binaries"""
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
def add_options(self, parser):
parser.add_option("--testbinary", dest="testbinary",
default=os.getenv("SARIELSAZD", "sarielsazd"),
help="sarielsazd binary to test")
parser.add_option("--refbinary", dest="refbinary",
default=os.getenv("SARIELSAZD", "sarielsazd"),
help="sarielsazd binary to use for reference nodes (if any)")
def setup_network(self):
extra_args = [['-whitelist=127.0.0.1']] * self.num_nodes
if hasattr(self, "extra_args"):
extra_args = self.extra_args
self.add_nodes(self.num_nodes, extra_args,
binary=[self.options.testbinary] +
[self.options.refbinary] * (self.num_nodes - 1))
self.start_nodes()
class SkipTest(Exception):
"""This exception is raised to skip a test"""
def __init__(self, message):
self.message = message
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6927,
13,
9261,
710,
428,
759,
352,
2231,
90,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
1563,
1021,
367,
11785,
5343,
1041,
199,
199,
504,
5055,
492,
15782,
199,
504,
4952,
492,
11305,
199,
646,
2050,
199,
646,
8691,
199,
646,
747,
199,
646,
10543,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
900,
199,
646,
5190,
199,
199,
504,
1275,
1178,
3280,
492,
4840,
8171,
1726,
199,
504,
1275,
492,
11745,
199,
504,
1275,
396,
63,
932,
492,
1379,
1716,
199,
504,
1275,
1974,
492,
334,
272,
9141,
63,
2826,
4448,
12,
272,
10977,
19554,
12,
272,
702,
63,
1452,
12,
272,
1104,
63,
1001,
63,
6833,
12,
272,
4907,
63,
2415,
63,
4492,
12,
272,
17639,
63,
2415,
12,
272,
8265,
63,
18259,
12,
272,
943,
63,
1501,
12,
272,
299,
18,
80,
63,
719,
12,
272,
663,
63,
932,
63,
4508,
12,
272,
7604,
63,
4166,
12,
272,
7604,
63,
278,
311,
5998,
12,
199,
9,
199,
199,
533,
1379,
3694,
8,
5081,
304,
272,
510,
32032,
275,
413,
272,
26892,
275,
499,
272,
27885,
19359,
275,
650,
199,
199,
2864,
63,
17219,
63,
48,
32032,
275,
378,
199,
2864,
63,
17219,
63,
12299,
275,
413,
199,
2864,
63,
17219,
63,
13525,
19359,
275,
8375,
199,
199,
533,
428,
759,
352,
2231,
90,
26203,
837,
272,
408,
1563,
1021,
367,
282,
308,
759,
352,
2231,
90,
511,
2884,
14,
339,
1010,
15067,
308,
759,
352,
2231,
90,
511,
10554,
1077,
5516,
642,
1021,
436,
4278,
314,
663,
63,
396,
63,
1162,
342,
436,
1255,
63,
396,
342,
3102,
14,
339,
1010,
15067,
2295,
883,
2597,
4278,
314,
2569,
3102,
370,
17551,
314,
511,
3272,
26,
339,
446,
1050,
63,
1419,
342,
272,
446,
3272,
63,
4429,
342,
272,
446,
3272,
63,
1200,
342,
272,
446,
3272,
63,
2415,
342,
339,
710,
636,
826,
4533,
436,
2446,
342,
3102,
1077,
440,
506,
10087,
14,
339,
961,
1021,
2597,
3509,
7750,
4575,
436,
5726,
5922,
3102,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
408,
9899,
511,
10059,
4243,
14,
4226,
440,
4278,
642,
1083,
14,
15345,
12,
4278,
314,
663,
63,
396,
63,
1162,
342,
1083,
624,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
756,
267,
291,
14,
2415,
275,
942,
267,
291,
14,
1805,
521,
275,
378,
267,
291,
14,
409,
63,
396,
63,
1162,
342,
398,
702,
2688,
8,
277,
12,
298,
1507,
63,
2415,
1288,
298,
774,
1471,
663,
291,
14,
1507,
63,
2415,
315,
663,
63,
396,
63,
1162,
16493,
339,
347,
2446,
8,
277,
304,
267,
408,
6756,
805,
14,
961,
1077,
440,
506,
10087,
701,
314,
5516,
511,
10554,
1041,
398,
1798,
275,
8691,
14,
14553,
8,
3807,
5961,
6595,
359,
1419,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
23507,
1270,
384,
401,
2053,
628,
23507,
1270,
384,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
23679,
308,
759,
352,
2231,
90,
795,
436,
511,
2795,
666,
694,
641,
4458,
503,
1125,
531,
267,
1798,
14,
525,
63,
1422,
6739,
889,
8831,
401,
2053,
628,
889,
8831,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
16932,
1133,
3631,
308,
759,
352,
2231,
90,
795,
2410,
314,
511,
6451,
531,
267,
1798,
14,
525,
63,
1422,
6739,
17878,
401,
2053,
628,
17878,
401,
849,
29,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
435,
3286,
29866,
2164,
1288,
2079,
1720,
628,
2980,
2082,
3035,
308,
759,
352,
2231,
23670,
15,
83,
759,
352,
2231,
90,
13,
2764,
334,
885,
26,
450,
885,
6320,
267,
1798,
14,
525,
63,
1422,
6739,
1637,
694,
401,
2053,
628,
1637,
694,
401,
849,
29,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
435,
3286,
9707,
1637,
1288,
2079,
1720,
628,
6231,
367,
13627,
876,
10176,
666,
3220,
531,
267,
1798,
14,
525,
63,
1422,
6739,
8616,
401,
2053,
628,
8616,
401,
1720,
628,
6405,
2082,
367,
666,
3220,
531,
267,
1798,
14,
525,
63,
1422,
6096,
76,
401,
4320,
26629,
401,
2053,
628,
26629,
401,
849,
628,
4531,
401,
2079,
1720,
628,
793,
4474,
737,
642,
2166,
436,
10948,
370,
314,
8559,
14,
6855,
506,
663,
370,
10990,
12,
24008,
12,
14750,
12,
12539,
503,
17101,
19223,
14,
31755,
1553,
26629,
10990,
911,
1072,
1006,
9610,
370,
8559,
14,
3390,
626,
9610,
737,
1006,
11106,
787,
3544,
5313,
370,
314,
511,
63,
4857,
14,
793,
570,
315,
314,
7937,
511,
2082,
2685,
267,
1798,
14,
525,
63,
1422,
6739,
16825,
2352,
401,
2053,
628,
3446,
63,
4354,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
5375,
734,
1006,
11785,
4882,
465,
2985,
787,
6326,
531,
267,
1798,
14,
525,
63,
1422,
6739,
719,
5176,
401,
2053,
628,
719,
63,
5176,
401,
849,
29,
736,
14,
17829,
1062,
730,
534,
442,
297,
2079,
1720,
628,
1918,
6347,
370,
675,
367,
26694,
1844,
5579,
334,
885,
26,
1453,
2112,
1305,
6320,
267,
1798,
14,
525,
63,
1422,
6739,
10828,
694,
401,
2053,
628,
10828,
694,
401,
2079,
1720,
628,
3534,
12470,
11785,
3718,
1901,
642,
2082,
531,
267,
1798,
14,
525,
63,
1422,
6739,
29217,
401,
2053,
628,
29217,
401,
2079,
1720,
628,
6592,
402,
314,
511,
10059,
1101,
570,
531,
267,
1798,
14,
525,
63,
1422,
6739,
10511,
265,
5328,
401,
2053,
628,
10511,
265,
5328,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
13240,
282,
2366,
14958,
340,
511,
6918,
531,
267,
291,
14,
525,
63,
1419,
8,
2087,
9,
267,
334,
277,
14,
1419,
12,
291,
14,
589,
9,
275,
1798,
14,
1122,
63,
589,
342,
398,
10977,
19554,
14,
78,
275,
291,
14,
1419,
14,
719,
63,
5176,
398,
747
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6927,
13,
9261,
710,
428,
759,
352,
2231,
90,
11672,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
624,
1563,
1021,
367,
11785,
5343,
1041,
199,
199,
504,
5055,
492,
15782,
199,
504,
4952,
492,
11305,
199,
646,
2050,
199,
646,
8691,
199,
646,
747,
199,
646,
10543,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
646,
900,
199,
646,
5190,
199,
199,
504,
1275,
1178,
3280,
492,
4840,
8171,
1726,
199,
504,
1275,
492,
11745,
199,
504,
1275,
396,
63,
932,
492,
1379,
1716,
199,
504,
1275,
1974,
492,
334,
272,
9141,
63,
2826,
4448,
12,
272,
10977,
19554,
12,
272,
702,
63,
1452,
12,
272,
1104,
63,
1001,
63,
6833,
12,
272,
4907,
63,
2415,
63,
4492,
12,
272,
17639,
63,
2415,
12,
272,
8265,
63,
18259,
12,
272,
943,
63,
1501,
12,
272,
299,
18,
80,
63,
719,
12,
272,
663,
63,
932,
63,
4508,
12,
272,
7604,
63,
4166,
12,
272,
7604,
63,
278,
311,
5998,
12,
199,
9,
199,
199,
533,
1379,
3694,
8,
5081,
304,
272,
510,
32032,
275,
413,
272,
26892,
275,
499,
272,
27885,
19359,
275,
650,
199,
199,
2864,
63,
17219,
63,
48,
32032,
275,
378,
199,
2864,
63,
17219,
63,
12299,
275,
413,
199,
2864,
63,
17219,
63,
13525,
19359,
275,
8375,
199,
199,
533,
428,
759,
352,
2231,
90,
26203,
837,
272,
408,
1563,
1021,
367,
282,
308,
759,
352,
2231,
90,
511,
2884,
14,
339,
1010,
15067,
308,
759,
352,
2231,
90,
511,
10554,
1077,
5516,
642,
1021,
436,
4278,
314,
663,
63,
396,
63,
1162,
342,
436,
1255,
63,
396,
342,
3102,
14,
339,
1010,
15067,
2295,
883,
2597,
4278,
314,
2569,
3102,
370,
17551,
314,
511,
3272,
26,
339,
446,
1050,
63,
1419,
342,
272,
446,
3272,
63,
4429,
342,
272,
446,
3272,
63,
1200,
342,
272,
446,
3272,
63,
2415,
342,
339,
710,
636,
826,
4533,
436,
2446,
342,
3102,
1077,
440,
506,
10087,
14,
339,
961,
1021,
2597,
3509,
7750,
4575,
436,
5726,
5922,
3102,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
408,
9899,
511,
10059,
4243,
14,
4226,
440,
4278,
642,
1083,
14,
15345,
12,
4278,
314,
663,
63,
396,
63,
1162,
342,
1083,
624,
267,
291,
14,
2758,
63,
3118,
63,
4429,
275,
756,
267,
291,
14,
2415,
275,
942,
267,
291,
14,
1805,
521,
275,
378,
267,
291,
14,
409,
63,
396,
63,
1162,
342,
398,
702,
2688,
8,
277,
12,
298,
1507,
63,
2415,
1288,
298,
774,
1471,
663,
291,
14,
1507,
63,
2415,
315,
663,
63,
396,
63,
1162,
16493,
339,
347,
2446,
8,
277,
304,
267,
408,
6756,
805,
14,
961,
1077,
440,
506,
10087,
701,
314,
5516,
511,
10554,
1041,
398,
1798,
275,
8691,
14,
14553,
8,
3807,
5961,
6595,
359,
1419,
12523,
267,
1798,
14,
525,
63,
1422,
6739,
23507,
1270,
384,
401,
2053,
628,
23507,
1270,
384,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
23679,
308,
759,
352,
2231,
90,
795,
436,
511,
2795,
666,
694,
641,
4458,
503,
1125,
531,
267,
1798,
14,
525,
63,
1422,
6739,
889,
8831,
401,
2053,
628,
889,
8831,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
16932,
1133,
3631,
308,
759,
352,
2231,
90,
795,
2410,
314,
511,
6451,
531,
267,
1798,
14,
525,
63,
1422,
6739,
17878,
401,
2053,
628,
17878,
401,
849,
29,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
435,
3286,
29866,
2164,
1288,
2079,
1720,
628,
2980,
2082,
3035,
308,
759,
352,
2231,
23670,
15,
83,
759,
352,
2231,
90,
13,
2764,
334,
885,
26,
450,
885,
6320,
267,
1798,
14,
525,
63,
1422,
6739,
1637,
694,
401,
2053,
628,
1637,
694,
401,
849,
29,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
435,
3286,
9707,
1637,
1288,
2079,
1720,
628,
6231,
367,
13627,
876,
10176,
666,
3220,
531,
267,
1798,
14,
525,
63,
1422,
6739,
8616,
401,
2053,
628,
8616,
401,
1720,
628,
6405,
2082,
367,
666,
3220,
531,
267,
1798,
14,
525,
63,
1422,
6096,
76,
401,
4320,
26629,
401,
2053,
628,
26629,
401,
849,
628,
4531,
401,
2079,
1720,
628,
793,
4474,
737,
642,
2166,
436,
10948,
370,
314,
8559,
14,
6855,
506,
663,
370,
10990,
12,
24008,
12,
14750,
12,
12539,
503,
17101,
19223,
14,
31755,
1553,
26629,
10990,
911,
1072,
1006,
9610,
370,
8559,
14,
3390,
626,
9610,
737,
1006,
11106,
787,
3544,
5313,
370,
314,
511,
63,
4857,
14,
793,
570,
315,
314,
7937,
511,
2082,
2685,
267,
1798,
14,
525,
63,
1422,
6739,
16825,
2352,
401,
2053,
628,
3446,
63,
4354,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
5375,
734,
1006,
11785,
4882,
465,
2985,
787,
6326,
531,
267,
1798,
14,
525,
63,
1422,
6739,
719,
5176,
401,
2053,
628,
719,
63,
5176,
401,
849,
29,
736,
14,
17829,
1062,
730,
534,
442,
297,
2079,
1720,
628,
1918,
6347,
370,
675,
367,
26694,
1844,
5579,
334,
885,
26,
1453,
2112,
1305,
6320,
267,
1798,
14,
525,
63,
1422,
6739,
10828,
694,
401,
2053,
628,
10828,
694,
401,
2079,
1720,
628,
3534,
12470,
11785,
3718,
1901,
642,
2082,
531,
267,
1798,
14,
525,
63,
1422,
6739,
29217,
401,
2053,
628,
29217,
401,
2079,
1720,
628,
6592,
402,
314,
511,
10059,
1101,
570,
531,
267,
1798,
14,
525,
63,
1422,
6739,
10511,
265,
5328,
401,
2053,
628,
10511,
265,
5328,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
2079,
1720,
628,
13240,
282,
2366,
14958,
340,
511,
6918,
531,
267,
291,
14,
525,
63,
1419,
8,
2087,
9,
267,
334,
277,
14,
1419,
12,
291,
14,
589,
9,
275,
1798,
14,
1122,
63,
589,
342,
398,
10977,
19554,
14,
78,
275,
291,
14,
1419,
14,
719,
63,
5176,
398,
747,
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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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
] |
cgstudiomap/cgstudiomap
|
main/parts/odoo/openerp/addons/base/tests/test_menu.py
|
501
|
1450
|
import openerp.tests.common as common
class test_menu(common.TransactionCase):
def setUp(self):
super(test_menu,self).setUp()
self.Menus = self.registry('ir.ui.menu')
def test_00_menu_deletion(self):
"""Verify that menu deletion works properly when there are child menus, and those
are indeed made orphans"""
cr, uid, Menus = self.cr, self.uid, self.Menus
# Generic trick necessary for search() calls to avoid hidden menus
ctx = {'ir.ui.menu.full_list': True}
root_id = Menus.create(cr, uid, {'name': 'Test root'})
child1_id = Menus.create(cr, uid, {'name': 'Test child 1', 'parent_id': root_id})
child2_id = Menus.create(cr, uid, {'name': 'Test child 2', 'parent_id': root_id})
child21_id = Menus.create(cr, uid, {'name': 'Test child 2-1', 'parent_id': child2_id})
all_ids = [root_id, child1_id, child2_id, child21_id]
# delete and check that direct children are promoted to top-level
# cfr. explanation in menu.unlink()
Menus.unlink(cr, uid, [root_id])
remaining_ids = Menus.search(cr, uid, [('id', 'in', all_ids)], order="id", context=ctx)
self.assertEqual([child1_id, child2_id, child21_id], remaining_ids)
orphan_ids = Menus.search(cr, uid, [('id', 'in', all_ids), ('parent_id', '=', False)], order="id", context=ctx)
self.assertEqual([child1_id, child2_id], orphan_ids)
|
agpl-3.0
|
[
646,
5166,
14,
2219,
14,
2330,
465,
2863,
199,
199,
533,
511,
63,
4470,
8,
2330,
14,
10161,
1538,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
396,
63,
4470,
12,
277,
680,
5996,
342,
267,
291,
14,
29230,
527,
275,
291,
14,
5189,
360,
723,
14,
1907,
14,
4470,
358,
339,
347,
511,
63,
383,
63,
4470,
63,
14281,
8,
277,
304,
267,
408,
7496,
626,
6269,
14068,
5419,
7684,
1380,
2337,
787,
1982,
27906,
12,
436,
5204,
1779,
787,
31043,
379,
6326,
503,
838,
796,
624,
267,
2467,
12,
1747,
12,
603,
287,
527,
275,
291,
14,
1556,
12,
291,
14,
1535,
12,
291,
14,
29230,
527,
398,
327,
8307,
20907,
5784,
367,
2754,
342,
4882,
370,
5126,
8752,
27906,
4960,
4027,
275,
791,
723,
14,
1907,
14,
4470,
14,
2861,
63,
513,
356,
715,
93,
398,
1738,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1738,
3071,
267,
1982,
17,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1982,
413,
297,
283,
1708,
63,
344,
356,
1738,
63,
344,
1552,
267,
1982,
18,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1982,
499,
297,
283,
1708,
63,
344,
356,
1738,
63,
344,
1552,
267,
1982,
2025,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1982,
499,
13,
17,
297,
283,
1708,
63,
344,
356,
1982,
18,
63,
344,
1552,
398,
1006,
63,
1580,
275,
359,
1231,
63,
344,
12,
1982,
17,
63,
344,
12,
1982,
18,
63,
344,
12,
1982,
2025,
63,
344,
61,
398,
327,
3145,
436,
1104,
626,
4125,
4978,
787,
8023,
5731,
370,
2746,
13,
1896,
267,
327,
3980,
82,
14,
17531,
315,
6269,
14,
7162,
342,
267,
603,
287,
527,
14,
7162,
8,
1556,
12,
1747,
12,
359,
1231,
63,
344,
566,
398,
7971,
63,
1580,
275,
603,
287,
527,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
344,
297,
283,
262,
297,
1006,
63,
1580,
4360,
1865,
628,
344,
401,
1067,
29,
3799,
9,
267,
291,
14,
629,
779,
1739,
17,
63,
344,
12,
1982,
18,
63,
344,
12,
1982,
2025,
63,
344,
467,
7971,
63,
1580,
9,
398,
23237,
63,
1580,
275,
221,
603,
287,
527,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
344,
297,
283,
262,
297,
1006,
63,
1580,
395,
661,
1708,
63,
344,
297,
6291,
756,
4360,
1865,
628,
344,
401,
1067,
29,
3799,
9,
267,
291,
14,
629,
779,
1739,
17,
63,
344,
12,
1982,
18,
63,
344,
467,
23237,
63,
1580,
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
] |
[
5166,
14,
2219,
14,
2330,
465,
2863,
199,
199,
533,
511,
63,
4470,
8,
2330,
14,
10161,
1538,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
396,
63,
4470,
12,
277,
680,
5996,
342,
267,
291,
14,
29230,
527,
275,
291,
14,
5189,
360,
723,
14,
1907,
14,
4470,
358,
339,
347,
511,
63,
383,
63,
4470,
63,
14281,
8,
277,
304,
267,
408,
7496,
626,
6269,
14068,
5419,
7684,
1380,
2337,
787,
1982,
27906,
12,
436,
5204,
1779,
787,
31043,
379,
6326,
503,
838,
796,
624,
267,
2467,
12,
1747,
12,
603,
287,
527,
275,
291,
14,
1556,
12,
291,
14,
1535,
12,
291,
14,
29230,
527,
398,
327,
8307,
20907,
5784,
367,
2754,
342,
4882,
370,
5126,
8752,
27906,
4960,
4027,
275,
791,
723,
14,
1907,
14,
4470,
14,
2861,
63,
513,
356,
715,
93,
398,
1738,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1738,
3071,
267,
1982,
17,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1982,
413,
297,
283,
1708,
63,
344,
356,
1738,
63,
344,
1552,
267,
1982,
18,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1982,
499,
297,
283,
1708,
63,
344,
356,
1738,
63,
344,
1552,
267,
1982,
2025,
63,
344,
275,
603,
287,
527,
14,
981,
8,
1556,
12,
1747,
12,
791,
354,
356,
283,
774,
1982,
499,
13,
17,
297,
283,
1708,
63,
344,
356,
1982,
18,
63,
344,
1552,
398,
1006,
63,
1580,
275,
359,
1231,
63,
344,
12,
1982,
17,
63,
344,
12,
1982,
18,
63,
344,
12,
1982,
2025,
63,
344,
61,
398,
327,
3145,
436,
1104,
626,
4125,
4978,
787,
8023,
5731,
370,
2746,
13,
1896,
267,
327,
3980,
82,
14,
17531,
315,
6269,
14,
7162,
342,
267,
603,
287,
527,
14,
7162,
8,
1556,
12,
1747,
12,
359,
1231,
63,
344,
566,
398,
7971,
63,
1580,
275,
603,
287,
527,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
344,
297,
283,
262,
297,
1006,
63,
1580,
4360,
1865,
628,
344,
401,
1067,
29,
3799,
9,
267,
291,
14,
629,
779,
1739,
17,
63,
344,
12,
1982,
18,
63,
344,
12,
1982,
2025,
63,
344,
467,
7971,
63,
1580,
9,
398,
23237,
63,
1580,
275,
221,
603,
287,
527,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
344,
297,
283,
262,
297,
1006,
63,
1580,
395,
661,
1708,
63,
344,
297,
6291,
756,
4360,
1865,
628,
344,
401,
1067,
29,
3799,
9,
267,
291,
14,
629,
779,
1739,
17,
63,
344,
12,
1982,
18,
63,
344,
467,
23237,
63,
1580,
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,
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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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
] |
alinelena/quill
|
tests/testrunner.py
|
4
|
49478
|
#!/usr/bin/env python
############################################################################
##
## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
## Contact: Alexander Bokovoy <alexander.bokovoy@nokia.com>
##
## This file is part of the Quill package.
##
## Commercial Usage
## Licensees holding valid Qt Commercial licenses may use this file in
## accordance with the Qt Commercial License Agreement provided with the
## Software or, alternatively, in accordance with the terms contained in
## a written agreement between you and Nokia.
##
## GNU Lesser General Public License Usage
## Alternatively, this file may be used under the terms of the GNU Lesser
## General Public License version 2.1 as published by the Free Software
## Foundation and appearing in the file LICENSE.LGPL included in the
## packaging of this file. Please review the following information to
## ensure the GNU Lesser General Public License version 2.1 requirements
## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
##
## In addition, as a special exception, Nokia gives you certain
## additional rights. These rights are described in the Nokia Qt LGPL
## Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
## package.
##
## GNU General Public License Usage
## Alternatively, this file may be used under the terms of the GNU
## General Public License version 3.0 as published by the Free Software
## Foundation and appearing in the file LICENSE.GPL included in the
## packaging of this file. Please review the following information to
## ensure the GNU General Public License version 3.0 requirements will be
## met: http://www.gnu.org/copyleft/gpl.html.
##
## If you are unsure which license is appropriate for your use, please
## contact the sales department at qt-sales@nokia.com.
##
############################################################################
import os
import subprocess
import time
import threading
import datetime
import sys
import signal
import logging as log
import getopt
import zipfile
import pprint
from xml.etree.ElementTree import parse
import xml.etree.ElementTree as ET
from exceptions import Exception
TEST_DEFINITION_PATH = '/usr/share' #default path to test definition file
TEST_RESULTS_PATH = '/tmp'
TEST_INPUT_FILE = None #Optional input and output files, specified from the command prompt
TEST_OUTPUT_FILE = None
TEST_OUTPUT_LOGFILE = None
COLLECT_LOGS_FROM_DIR = '/tmp/logs/'
environment="hardware"
DEFAULT_TIMEOUT = 90.0
MIN_TIMEOUT = 5.0
KILL_TIMER = 5.0
STATUS_NOT_STARTED = "not-started"
STATUS_STARTED = "started"
STATUS_TIMEOUT = "timeout"
STATUS_TERMINATED = "terminated"
STATUS_OK = "ok"
PRINT_OUT_EXECUTION = False
EXEC_ONLY_AUTOMATIC = False
TEST_RESULT_VALUES = {'p' : 'Passed', 'f' : 'Failed', 'n' : 'Not executed'}
LOG_FORMAT = '[%(levelname)s] %(asctime)s %(message)s'
LOG_DATE_FORMAT = '%H:%M:%S'
log.basicConfig(level=log.DEBUG, format=LOG_FORMAT, datefmt=LOG_DATE_FORMAT, stream=sys.stdout)
# Custom exceptions:
class NoTestCaseCommandSpecifiedError(Exception):
pass
class NoTestCaseIdSpecifiedError(Exception):
pass
class NoTestCaseSpecifiedError(Exception):
pass
class NoTestCaseHeaderInfoAvailable(Exception):
pass
class TestCase(object):
"""A data structure class for a test case"""
def __init__(self, name = None, requirements = None, command_parameters=[], timeout = DEFAULT_TIMEOUT, description = None, steps = None, expected_results=[], testset=None, subfeature=None, case_type=None):
# unique test case name inside the test package
self.name = name
self.requirements = requirements
#Combine command and parameters as a list for subprocess to process them
self.command_parameters=command_parameters
self.timeout = timeout
self.description = description
self.steps = steps
self.expected_results=expected_results
#to indicate to which test set this test case belongs
self.testset=testset
self.subfeature=subfeature
self.type = case_type
class TestSet(object):
"""A data structure class for a test set"""
def __init__(self, name = None, description = None, feature = None, timeout = None, set_type = None, CI = True):
self.name=name
self.description=description
self.feature=feature
self.timeout=timeout
self.set_type=set_type
# CI is set as True by default
self.CI=CI
class TestRun(object):
"""
A testcase specific testrun class. Constructor takes test_case object as a parameter.
run() executes the testcase.
"""
def __init__(self, test_case):
self.test_case = test_case
self.process = None
# to store a bunch of stdout and stderr in case there are multiple steps in test case
self.stdout = []
self.stderr = []
self.return_code = []
self.status = STATUS_NOT_STARTED
self.execution_time = 0.0
self.started_on = None
self.end_on = None
# indicate the final result of test case execution
self.result = None
# indicate the result step by step in test case
self.resultcode=[]
self.lastIndex = 0
if not self.test_case:
log.error('No TestCase specified for TestRun!')
else:
log.info('New TestRun (test_case_requirement = %s)' % self.test_case.requirements)
def run(self):
if not self.test_case:
raise NoTestCaseSpecifiedError
#in case no command is specified, lets skip this function
if not self.test_case.command_parameters:
self.status = STATUS_OK
stdout=''
self.stdout.append(stdout)
stderr=''
self.stderr.append(stderr)
self.return_code.append(1)
self.resultcode.append(-1)
self.started_on = time.strftime("%Y-%m-%d %H:%M:%S")
return
self.started_on = time.strftime("%Y-%m-%d %H:%M:%S")
log.info('Starting test run for test case with name "%s" at %s' % (self.test_case.name, str(self.started_on)))
starting_time = time.time()
index=0; # variable index used to position the expected result for each pair of cmd_param in the test case
#each pair of command and its parameters are passed in as a string to subprocess for processing
for command_and_params in self.test_case.command_parameters:
if PRINT_OUT_EXECUTION:
print ' '.join(command_and_params)
try:
self.process = subprocess.Popen(command_and_params,
preexec_fn = os.setsid,
stdin = None,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
close_fds = True,
shell=True)
except Exception, e:
error = 'Error with command:' + command_and_params+ ' Error: '+ str(e)
log.error(error)
self.status = STATUS_OK
stdout = ''
self.stdout.append(stdout)
stderr = ''
self.stderr.append(stderr)
self.return_code.append(1)
self.lastIndex=index
self.resultcode.append(-1)
return
self.status = STATUS_STARTED
stdout=''
stderr=''
# wait for completion of command execution and get its output or error info.
stdout,stderr = self.process.communicate()
self.stdout.append(stdout)
self.stderr.append(stderr)
if PRINT_OUT_EXECUTION:
print stdout
return_code = self.process.returncode
self.return_code.append(return_code)
# In case there are multiple commands in one test case and one of them fails to execute, it's treated as a failure of the test case as a whole.
if self.test_case.expected_results[index] != None:
if return_code != int(self.test_case.expected_results[index]):
self.lastIndex=index
self.resultcode.append(-1)
break
# if no expected result is defined, 0 is taken as the default value
elif return_code != 0:
self.lastIndex = index
self.resultcode.append(-1)
break
self.resultcode.append(0)
self.lastIndex=index
index+=1
# Keep the execution_time attribute as it might turn out to be useful later
self.execution_time = time.time() - starting_time
self.end_on = time.strftime("%Y-%m-%d %H:%M:%S")
self.status = STATUS_OK
log.info('Finished test run, return code = %d, execution time = %f' % (self.return_code[self.lastIndex], self.execution_time))
class PrestepRun(object):
"""This class runs the commands if any found inside pre_steps tag in the test definition file"""
def __init__(self, prestepCmd):
self.timeout_timer = None
self.kill_timer = None
self.prestepCmd=prestepCmd
self.process=None
self.return_code=[]
# record 'daemon' process, if any
self.subprocesses=[]
def _timeout_callback(self, test_run):
if not test_run.process:
self.timeout_timer = None
return
if test_run.status == STATUS_OK:
self.timeout_timer = None
return
os.kill(test_run.process.pid, signal.SIGTERM)
test_run.state = STATUS_TIMEOUT
self.kill_timer = threading.Timer(KILL_TIMER, self._kill_callback, [test_run])
self.timeout_timer = None
log.info('Timeout occurred! Trying to terminate the process ...')
def _kill_callback(self, test_run):
os.kill(test_run.process.pid, signal.SIGKILL)
test_run.state = STATUS_TERMINATED
self.kill_timer = None
log.info('Kill timer expired! Killed the process forcefully ...')
def run(self):
if not self.prestepCmd:
self.return_code.append(1)
return
for cmd_parameters in self.prestepCmd:
# check whether is it required to run in background
if cmd_parameters.find('&') != -1:
# in case there are multiple commands in one step, split them by ';'
command_list = cmd_parameters.split(";")
for single_command in command_list:
# daemon process execution
if single_command.find('&') != -1:
try:
process = subprocess.Popen(single_command,
preexec_fn = os.setsid,
stdin = None,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
close_fds = True,
shell=True)
# store this child process object for future reference
self.subprocesses.append(process)
except Exception, e:
error = 'Error with pre-step command:' + cmd_parameters+' Error: '+str(e)
log.error(error)
return
log.info("Pre-step has been executed.")
# non-daemon process execution
else:
try:
self.process = subprocess.Popen(single_command,
preexec_fn = os.setsid,
stdin = None,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
close_fds = True,
shell=True)
except Exception, e:
error = 'Error with pre-step command:' + cmd_parameters+ ' Error: '+ str(e)
log.error(error)
self.return_code.append(1)
return
# Todo, maybe needed in future
stdout=""
stderr=""
stdout, stderr = self.process.communicate()
#return_code = self.process.returncode
#self.return_code.append(return_code)
log.info("Pre-step has been implemented...")
# normal test environment construction in pre-steps
else:
try:
self.process = subprocess.Popen(cmd_parameters,
preexec_fn = os.setsid,
stdin = None,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
close_fds = True,
shell=True)
except Exception, e:
error = 'Error with pre-step command:' + cmd_parameters+ ' Error: '+ str(e)
log.error(error)
self.return_code.append(1)
return
stdout=""
stderr=""
stdout, stderr = self.process.communicate()
return_code = self.process.returncode
self.return_code.append(return_code)
log.info("Pre-step has been implemented.")
class TestParser(object):
"""All the parse work of test definition file is conducted in this class"""
def __init__(self, statistics, testinputfile, testoutputfile=None):
self.test_cases = []
self.testcase_ids = []
# additional files if any to be fetched
self.additionalFiles = []
# a dict to store all the info of test sets inside the suite
self.testset = dict()
# a dict to store all the potential pre-step commands, its key is the set index while the value is the command list
self.prestepCmd = dict()
#setIndex is used to index each test set inside a test package
self.setIndex=0
# indicate whether to collect statistics from test cases
self.statistics = statistics
# stack potential 'daemon' process from pre-steps in a test set
self.child_process = []
self.testinputfile = testinputfile
self.testoutputfile = testoutputfile
#headerinfo for final results
#self.headerinfo = {'name':'', 'version':'', 'comment':'',
# 'usedhardware':''}
self.headerinfo = {'name':'', 'version':'', 'domain':'', 'type':'', 'timeout':'', 'CI':''}
def start_parsing(self):
if self.testinputfile:
#if TEST_INPUT_FILE: #if user-specified input file is used, otherwise use all files from the TEST_DEFINITION_PATH
# check the condition whether it is to collect statistics or to execute test cases
if self.statistics:
self._collect_statistics(self.testinputfile, self.testoutputfile)
else:
try:
self._parse_test_cases(self.testinputfile, environment)
except Exception, e:
log.error('Error while opening file ' + self.testinputfile + ' ' + str(e))
sys.exit(1)
else:
self._parse_test_files()
def _parse_test_files(self):
files = [f for f in os.listdir(TEST_DEFINITION_PATH) if f.endswith('.xml')]
log.info('Found test definition files: %s' % ' '.join(files))
for f in files:
self._parse_test_cases(TEST_DEFINITION_PATH + os.sep + f, environment)
# Fetch all the attributes of a tag
def _xml_element_get_items(self, element):
values = element.items()
#pprint.pprint(values)
items = {}
for key, value in values:
items[key] = value
return items
# return a value of attribute from case, set or suite where value from case is perferred over the one from set while the value in suite has the least priority.
def _get_value_from_case_or_set(self, key, case, set, subset):
if case.has_key(key):
return case[key]
elif subset.has_key(key):
return subset[key]
elif set.has_key(key):
return set[key]
elif self.headerinfo.has_key(key):
return self.headerinfo[key]
else:
return None
# Parse the environment tags in definition file and compare it with that passed from command line.
# Return the value of test environment or None if unmatched.
def _parse_environment_tags(self, setNode, pattern, environment):
testenvironment=""
# find search pattern from node set
environmentsList = setNode.findall(pattern)
if environmentsList:
for env in environmentsList:
flag=0
for envelement in env:
if envelement.tag == environment:
# set test environment if it is labeled as true or None if false otherwise
if envelement.text == 'true':
testenvironment = environment
else:
testenvironment = None
flag=1
break
# if the specified environment is not in the list of environments in exceptional case, set it as None
if flag == 0:
testenvironment = None
# test set is assumed to be executed in every environment by default
else:
testenvironment = environment
return testenvironment
# Parse the get tags in definition file
# Return the list of files to be fetched
def _parse_get_tags(self, getNode):
fileList=[]
for fileNode in getNode.getchildren():
getFileName=fileNode.text
# add the file inside a set to list, file check will be done later
fileList.append(getFileName)
return fileList
# parse pre steps tags
# Return the list of pre-step commands as strings
def _parse_presteps_tags(self, prestepNode):
prestepcmd=[]
for stepNode in prestepNode.getchildren():
stepcmd=stepNode.text
prestepcmd.extend([stepcmd])
return prestepcmd
# pre-steps setup
def _setup_presteps(self, prestepRun):
#prestepRun.timeout_timer = threading.Timer(DEFAULT_TIMEOUT, prestepRun._timeout_callback, [prestepRun])
#prestepRun.timeout_timer.start()
prestepRun.run()
# potential 'daemon' process that needs to be terminated after test execution
if prestepRun.subprocesses:
self.child_process = prestepRun.subprocesses
#if prestepRun.kill_timer:
# prestepRun.kill_timer.cancel()
# prestepRun.kill_timer = None
#if prestepRun.timeout_timer: # cancel timer after execution in case it is still running
# prestepRun.timeout_timer.cancel()
# configure the headerinfo by fetching attributes from suite tag
def _config_headerinfo(self, suite):
name=suite.get('name')
if name==None:
log.error ("Name could not be extracted from the XML's suite level. Please correct syntax.")
raise NoTestCaseHeaderInfoAvailable
self.headerinfo['name']=name
if suite.get('domain'): self.headerinfo['domain']=suite.get('domain')
if suite.get('type'): self.headerinfo['type']=suite.get('type')
if suite.get('timeout'): self.headerinfo['timeout']=suite.get('timeout')
if suite.get('CI'): self.headerinfo['CI']=suite.get('CI')
# configure the set info by fetching attributes from set tag
def _config_setinfo(self, setNode, setIndex, set_values):
# Store each test set's info in a dict
self.testset[setIndex]=TestSet()
self.testset[setIndex].name=set_values['name']
self.testset[setIndex].description= 'description' #set_values['description']
if set_values.has_key('feature'): self.testset[setIndex].feature=set_values['feature']
if set_values.has_key('type'): self.testset[setIndex].set_type=set_values['type']
if set_values.has_key('timeout'): self.testset[setIndex].timeout=set_values['timeout']
# Function to parse test cases in the definition file
def _parse_test_cases(self, filename, environment):
f=open(filename, "r")
parser = ET.XMLParser() #some parameters to set to get \n marks to lines??
xml = parse(f, parser)
f.close()
root = xml.getroot()
version = root.get('version')
if version==None:
log.error ("Version couldn't be extracted from the XML's root level. Please correct syntax.")
raise NoTestCaseHeaderInfoAvailable
self.headerinfo['version'] = version
# prepare for pre-steps setup if any
suite_presteps=[]
set_presteps=[]
for suite in root.getchildren():
# config headerinfo according to the attribute values fetched from suite tag
self._config_headerinfo(suite)
# evaluate CI attribute value in suite tag and ignore all tests if CI is set as false
if not self.headerinfo['CI'] == 'false':
for set in suite.getchildren():
if set.tag == 'pre_steps':
suite_presteps = self._parse_presteps_tags(set)
# execute pre steps
prestepSuite = PrestepRun(suite_presteps)
self._setup_presteps(prestepSuite)
elif set.tag == 'set':
set_values = self._xml_element_get_items(set)
# store the test environment value in dictionary set_values
set_values['environment'] = self._parse_environment_tags(set,"environments", environment)
# skip the entire test set if its test environment does not match the one from command line
if set_values['environment'] == environment:
# evaluate CI attribute value in set tag
test_set_CI = None
if set_values.has_key('CI'): test_set_CI = set_values['CI']
if not test_set_CI == 'false':
# increment the index of test set
self.setIndex+=1
# config each set's info according to the manually defined set index
self._config_setinfo(set, self.setIndex, set_values)
for element in set.getchildren(): #check all the following test cases in this set
if element.tag == 'pre_steps':
set_presteps = self._parse_presteps_tags(element)
# create a new entry in dict for the pre-steps commands
self.prestepCmd[self.setIndex]=set_presteps
# reset the list for the next iteration
set_presteps=[]
elif element.tag == 'case':
case_values = self._xml_element_get_items(element)
# evaluate CI attribute value in case tag
test_case_CI = None
if case_values.has_key('CI'): test_case_CI = case_values['CI']
if not test_case_CI == 'false':
cmd_params_list=[]
expected_results=[]
for step in element.getchildren():
expected_results.append(step.get('expected_result'))
cmd_param=step.text
# add each command as a string to the list
cmd_params_list.extend([cmd_param])
case_values['command_parameters']=cmd_params_list
case_values['expected_results']=expected_results
case_values['set_No']=self.setIndex
self._create_testcase(case_values, set_values)
# environments tags are neglected since they were processed before
elif element.tag == "environments":
pass
# parse get tag if any and add files to the global list of files
elif element.tag == "get":
getFiles=self._parse_get_tags(element)
self.additionalFiles.extend(getFiles)
else:
log.error('Incorrect tag in the XML: '+ element.tag)
#Changed the test case creation function to suit new format
def _create_testcase(self, case_values, set_values, subset_values={}):
testcase = TestCase()
testcase.name = case_values['name'].strip()
testcase.requirements = self._get_value_from_case_or_set('requirement', case_values, set_values, subset_values)
testcase.command_parameters=self._get_value_from_case_or_set('command_parameters',case_values, set_values, subset_values)
testcase.timeout = self._get_value_from_case_or_set('timeout', case_values, set_values, subset_values)
testcase.description = self._get_value_from_case_or_set('description', case_values, set_values, subset_values)
testcase.steps = self._get_value_from_case_or_set('steps', case_values, set_values, subset_values)
testcase.expected_results=self._get_value_from_case_or_set("expected_results", case_values, set_values, subset_values)
# this attribute relates the specific test case to its test set for grouping purpose
testcase.testset=self._get_value_from_case_or_set("set_No", case_values,set_values,subset_values)
testcase.subfeature=self._get_value_from_case_or_set("subfeature", case_values, set_values, subset_values)
if case_values.has_key("type"):
testcase.type=self._get_value_from_case_or_set("type", case_values, set_values, subset_values)
#do some checkings, could be done in more clever way also...
#if there are multiple requirements in one test case, they are separated by ','
if testcase.requirements:
testcase.requirements = testcase.requirements.split(',')
# specify the test case execution timeout, defaults to 90.0 if it is not specified explicitly
try:
testcase.timeout = float(testcase.timeout)
except:
testcase.timeout = DEFAULT_TIMEOUT
if testcase.name not in self.testcase_ids:
self.test_cases.append(testcase)
self.testcase_ids.append(testcase.name)
else:
log.error('There is a duplicate test case with name:' + testcase.name )
sys.exit(1)
# function to collect test cases information
def _collect_statistics(self, readfilename, writefilename):
pass
class TestRunner(object):
"""TestRunner class handles the whole testrunning process"""
def __init__(self, test_input_file, test_output_file):
self.timeout_timer = None
self.kill_timer = None
self.testinputfile = test_input_file
self.testoutputfile = test_output_file
self.test_execution_info_text = ' '.join([v.upper() + ' (' + r + ')' for v,r in TEST_RESULT_VALUES.iteritems()])
self.totalcounter = 0 #calc executed testcase amount
self.counters = {} #for counting results for a "simple" summary. Next line sets proper counters to zero
for k in TEST_RESULT_VALUES.keys(): self.counters[k] = 0
def _timeout_callback(self, test_run):
if not test_run.process:
self.timeout_timer = None
return
if test_run.status == STATUS_OK:
self.timeout_timer = None
return
os.kill(test_run.process.pid, signal.SIGTERM)
test_run.state = STATUS_TIMEOUT
self.kill_timer = threading.Timer(KILL_TIMER, self._kill_callback, [test_run])
self.timeout_timer = None
log.info('Timeout occurred! Trying to terminate the process ...')
def _kill_callback(self, test_run):
os.kill(test_run.process.pid, signal.SIGKILL)
test_run.state = STATUS_TERMINATED
self.kill_timer = None
log.info('Kill timer expired! Killed the process forcefully ...')
def _write_temporary_result(self, test_run, parsedTest):
# group test cases results according to their corresponding test set ID
filename = TEST_RESULTS_PATH + os.sep + parsedTest.headerinfo['name']+os.sep+str(test_run.test_case.testset)+os.sep+str(test_run.test_case.name)+'.tmp'
try:
file = open(filename, 'w')
except:
test_results_path = TEST_RESULTS_PATH+os.sep+parsedTest.headerinfo['name']+os.sep+str(test_run.test_case.testset)
if not os.path.isdir(TEST_RESULTS_PATH+os.sep+parsedTest.headerinfo['name']):
try:
os.mkdir(TEST_RESULTS_PATH+os.sep+parsedTest.headerinfo['name'])
except:
log.error("Cannot create directory "+TEST_RESULTS_PATH+os.sep+parsedTest.headerinfo['name'])
os.mkdir(test_results_path)
file=open(filename, 'w')
# start to build the xml file with ET
root = ET.Element("case")
root.set("name", test_run.test_case.name)
if test_run.test_case.subfeature:
root.set("subfeature", str(test_run.test_case.subfeature))
if test_run.test_case.type:
root.set("type", str(test_run.test_case.type))
if test_run.resultcode[test_run.lastIndex] != 0:
root.set("result", "FAIL")
else:
root.set("result", "PASS")
if test_run.test_case.description != None:
root.set("description", test_run.test_case.description)
else:
root.set("description", "")
if test_run.test_case.requirements != None:
root.set("requirement", str(test_run.test_case.requirements))
else:
root.set("requirement", "")
i=0
# start to build the step tag one by one. It won't stop until it encounters the last index of step executed by the subprocess
while i<=test_run.lastIndex:
step = ET.SubElement(root, "step")
# build step command that is constructed in a list
step.set("command", test_run.test_case.command_parameters[i])
if test_run.resultcode[i] != 0:
step.set("result", "FAIL")
else:
step.set("result", "PASS")
expect_result=ET.SubElement(step, "expected_result")
if len(test_run.test_case.expected_results) != 0:
expect_result.text=test_run.test_case.expected_results[i]
else:
expect_result.text=""
return_code=ET.SubElement(step, "return_code")
return_code.text=str(test_run.return_code[i])
# todo, the start and end time are now counted as the entire execution time of a test case.
started_on=ET.SubElement(step, "start")
started_on.text=str(test_run.started_on)
end_on=ET.SubElement(step, "end")
end_on.text=str(test_run.end_on)
# Uncomment the following two lines if execution time needs to be shown in the result file
# execution_time=ET.SubElement(step, "execution_time")
# execution_time.text=str(test_run.execution_time)
stdout=ET.SubElement(step,"stdout")
stdout.text=test_run.stdout[i]
stderr=ET.SubElement(step,"stderr")
stderr.text=test_run.stderr[i]
i+=1
tree=ET.ElementTree(root)
tree.write(filename)
file.close()
def _get_file_contents(self, filename):
file = open(filename, 'r')
contents = file.read()
file.close()
return contents
def _write_final_result(self, parsedTest):
test_results_path=TEST_RESULTS_PATH+os.sep+parsedTest.headerinfo['name']
temp_results=""
# Variable sindex positions the test sets. It starts from the first set in the test package.
sindex=1
# Loop through each test set and group the test results according to test set
while sindex != parsedTest.setIndex+1:
firstoccurrance=0
for f in os.listdir(test_results_path+os.sep+str(sindex)):
if(firstoccurrance==0):
temp_results+='<set name="'
#temp_results+= parsedTest.testset_name[sindex]
temp_results+= parsedTest.testset[sindex].name
temp_results+='" description="'
#temp_results+=parsedTest.testset_description[sindex]
temp_results+= parsedTest.testset[sindex].description
if parsedTest.testset[sindex].feature:
temp_results+='" feature="'
temp_results+=parsedTest.testset[sindex].feature
if parsedTest.testset[sindex].set_type:
temp_results+='" type="'
temp_results+=parsedTest.testset[sindex].set_type
temp_results+='" environment="'
temp_results+=environment
temp_results+='">'
temp_results+="\n"
firstoccurrance=1
temp_results+=self._get_file_contents(test_results_path + os.sep +str(sindex)+os.sep+ f)
temp_results+="\n</set>\n"
sindex+=1
# prepare header info
header = ''
header1 = ''
header += ' ' + 'version' + '="' + str(parsedTest.headerinfo['version']) + '"'
header1 += ' ' + 'name' + '="' + str(parsedTest.headerinfo['name']) + '"'
if parsedTest.headerinfo['domain']: header1+=' '+ 'domain'+'="'+str(parsedTest.headerinfo['domain'])+'"'
if parsedTest.headerinfo['type']: header1+=' '+'type'+'="'+str(parsedTest.headerinfo['type'])+'"'
if self.testoutputfile:
outputfile = self.testoutputfile
else:
# Hard-coded result file name if user does not specify an output file name
outputfile = test_results_path + os.sep + 'tatam_xml_testrunner_output_results.xml'
# Fetch the directory name of the output file.
result_path = os.path.dirname(outputfile)
# Try to create the directory if it is not existent
if not os.path.exists(result_path) and result_path != '':
try:
os.mkdir(result_path)
except:
log.error("Cannot create directory "+result_path)
file = open(outputfile, 'w')
file.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n')
# file.write('<?xml-stylesheet type="text/xsl" href="http://cita.research.nokia.com/static/testrunner_results.xsl"?>')
file.write('<testresults'+header+'>\n')
file.write('<suite'+header1+'>\n')
file.write(temp_results)
file.write('</suite>\n')
file.write('</testresults>\n')
file.close()
log.info('Results were written to: ' + outputfile)
#delete temporary files and directories
while parsedTest.setIndex > 0:
temp_results_files = [f for f in os.listdir(test_results_path+os.sep+str(parsedTest.setIndex)) if f.endswith('.tmp')]
for f in temp_results_files:
os.unlink(test_results_path + os.sep + str(parsedTest.setIndex)+ os.sep + f)
os.rmdir(test_results_path + os.sep + str(parsedTest.setIndex))
parsedTest.setIndex-=1
self._collect_logs_to_zipfile()
self._print_total_counters()
def _print_total_counters(self):
log.info('Executed ' +str(self.totalcounter) +' cases where '+ ' '.join([TEST_RESULT_VALUES[k]+':' + str(v) for k, v in self.counters.iteritems()]))
def _collect_logs_to_zipfile(self):
if not os.path.isdir(COLLECT_LOGS_FROM_DIR):
#log.info('No logs to collect from ' + COLLECT_LOGS_FROM_DIR)
return
if TEST_OUTPUT_LOGFILE:
zipfilename = TEST_OUTPUT_LOGFILE
else:
zipfilename = TEST_RESULTS_PATH + os.sep + 'results_log.zip'
log.info('Copying log files from '+ COLLECT_LOGS_FROM_DIR +' to a zip file: '+zipfilename)
zfile = zipfile.ZipFile(zipfilename, 'w')
for root, dirs, files in os.walk(COLLECT_LOGS_FROM_DIR):
for fileName in files:
zfile.write(os.path.join(root,fileName))
zfile.close()
# Fetch all the additional files if any
def _fetch_get_files(self, parsedTest):
# check the existence of target directory, in case it is not existent, create it.
result_path = os.path.dirname(self.testoutputfile)
if not os.path.isdir(result_path) and result_path != '':
try:
os.mkdir(result_path)
except:
log.error("Cannot create directory "+result_path)
# copy additional files, if any, to designated directory
if parsedTest.additionalFiles:
#targetDir="/tmp/"+parsedTest.headerinfo['name']
targetDir = result_path
for eachFile in parsedTest.additionalFiles:
# evaluate the existance of files in the list
#if os.path.isfile(eachFile):
try:
subprocess.call("cp" + " "+eachFile+" "+targetDir, shell = True)
except OSError, e:
print >>sys.stderr, "Copy file "+eachFile+" failed:", e
def run_single_case(self, test_case, parsedTest):
if not test_case:
raise NoTestCaseSpecifiedError
r = TestRun(test_case)
self.timeout_timer = threading.Timer(test_case.timeout, self._timeout_callback, [r])
self.timeout_timer.start()
r.run()
if self.kill_timer:
self.kill_timer.cancel()
self.kill_timer = None
if self.timeout_timer: #Cancel timer after execution in case it is still running.
self.timeout_timer.cancel()
#If there is no final result available, analyze result. In case manual exec, this analysis will be overidden in next step
if not r.result:
r.result = self._analyze_result(r)
self._write_temporary_result(r, parsedTest)
return r.result
def run_all_cases(self):
log.info('Starting to run tests ...')
#log.info('(Not implemented) Clearing log directory ' + COLLECT_LOGS_FROM_DIR)
# Inside test runner, there is absolutely no opportuniry to collect test cases statistics
parsedTest = TestParser(False, self.testinputfile)
parsedTest.start_parsing()
setCount=1
while setCount != parsedTest.setIndex+1:
# to check whether the specific test set has any pre-steps commands to be executed first
if parsedTest.prestepCmd.has_key(setCount):
set_presteps=parsedTest.prestepCmd[setCount]
prestepSet=PrestepRun(set_presteps)
parsedTest._setup_presteps(prestepSet)
# execute test cases in this test set followingly
for case in parsedTest.test_cases:
if case.testset == setCount:
result = self.run_single_case(case, parsedTest)
self.counters[result] += 1
self.totalcounter += 1
# terminate any 'daemon' process
if parsedTest.child_process:
for each_child in parsedTest.child_process:
#print each_child.pid
os.kill(each_child.pid, signal.SIGTERM)
# reset the list of child process for next test set that has such 'daemon' process
parsedTest.child_process = []
setCount+=1
if parsedTest.test_cases:
self._write_final_result(parsedTest)
log.info('Finished!')
# finally, fetch all the additional result files if any to designated directory
self._fetch_get_files(parsedTest)
def ask_result(self, t):
#ask result from the user in case of manual test execution
print 'Description: ', t.description, os.linesep
print 'Steps:'
#pprint.pprint( t.steps)
parsedsteps = str(t.steps).replace('#', os.linesep).replace('\n', os.linesep).replace(';', os.linesep).replace('\\n', os.linesep).replace('\\t', '\t').split(os.linesep)
for line in parsedsteps:
print ' ' + line
print 'Please enter result. ' + self.test_execution_info_text +' (The case doesn\'t matter)'
resp = raw_input("What is the result? ")
while(self._check_user_input(resp)):
resp = raw_input("Error in the input, What is the result? ")
return str(resp).lower()
def ask_verbal_input(self):
resp = raw_input("Comment test run (if needed): ")
return str(resp)
#In manual execution, check user input.
def _check_user_input(self, i):
accepted_inputs = TEST_RESULT_VALUES.keys()
try:
if i.lower() in accepted_inputs:
return 0
else:
return 1
except:
return 1
return 0
#analyze automated test execution result
def _analyze_result(self, r):
# the premise for the evaluation on the result of test case execution is that it is treated as pass only when all the steps have been successfully executed. In all the other conditions, it is treated as fail. So it only checks the execution status of last step in the test case.
if r.resultcode[r.lastIndex] == 0:
return 'p'
return 'f'
if __name__ == '__main__':
def usage():
print "The usage of this script is as follows."
print "Use option -v to print out execution output during execution"
print "Use -f option to define input test xml file."
print "Use -o option to define output file for the results."
print "Use -s option to collect statistics about test cases info. (This will not start executing test cases though.)"
print "Use -e option to define the environment. (hardware/scratchbox etc.) Default is hardware."
print "Use -z option to define output file for the zipped logs file. Otherwise logs will be written to ./result directory."
# print "Use -a option to execute only automated test cases"
# testing environment defaults to 'hardware'
environment="hardware"
try:
# options that can be recognized by the script
# If -s or --statistics is present, only parsed test cases information will be provided, but test cases will not be executed
opts, args = getopt.getopt(sys.argv[1:], "hsf:o:z:e:va", ["help", "statistics", "file=", "output=", "zip=", "environment="])
except getopt.GetoptError, err:
# print help information and exit
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
verbose = False
statistics = False
for o, a in opts:
if o == "-v":
PRINT_OUT_EXECUTION = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-s", "--statistics"):
statistics = True
print "Collecting statistics now..."
elif o in ("-f", "--file"):
TEST_INPUT_FILE = a
#in case input file is specified and no outputfile specified in opts, outputfile will be named according to it as inputname_results.xml
# if not TEST_OUTPUT_FILE:
# TEST_OUTPUT_FILE = TEST_RESULTS_PATH + os.sep + os.path.basename(a).strip('.xml') + '_results.xml'
# if not TEST_OUTPUT_LOGFILE:
# TEST_OUTPUT_LOGFILE = TEST_RESULTS_PATH + os.sep + os.path.basename(a).strip('.xml') + '_logs.zip'
elif o in ("-o", "--output"):
TEST_OUTPUT_FILE = a
# try:
# file = open(TEST_OUTPUT_FILE, 'a') #do not overwrite here, will be overwritten later anyway..
# file.close()
# except Exception, e:
# log.error('Output file name ' + a + ' is not valid ' + str(e))
elif o in ("-z", "--zip"):
TEST_OUTPUT_LOGFILE = a
try:
file = open(TEST_OUTPUT_LOGFILE, 'a') #do not overwrite here, will be overwritten later anyway..
file.close()
except Exception, e:
log.error('Zip output file name ' + a + ' is not valid ' + str(e))
elif o == "-a":
EXEC_ONLY_AUTOMATIC = True
elif o in ("-e", "--environment"):
environment=a
else:
assert False, "unhandled option"
if not (TEST_OUTPUT_FILE and TEST_INPUT_FILE): # make input and output file parameters mandatory:
usage()
sys.exit(-1)
# Run according to the new test package definition if test definition xml is found:
if os.path.isfile(TEST_INPUT_FILE):
if statistics:
testparser = TestParser(statistics, TEST_INPUT_FILE, TEST_OUTPUT_FILE)
testparser.start_parsing()
else:
tr = TestRunner(TEST_INPUT_FILE, TEST_OUTPUT_FILE)
try:
tr.run_all_cases()
except (KeyboardInterrupt, SystemExit):
#if user exists, write out the results anyway to the file. Let's save what can be saved.
log.error('Process interrupted. Previous test results were written to the file.')
parseTest= TestParser(False, TEST_INPUT_FILE, TEST_OUTPUT_FILE)
parseTest.start_parsing()
tr._write_final_result(parseTest)
sys.exit(1)
# Try to find runtests.sh and run the old style test package
elif os.path.isfile(TEST_INPUT_FILE.replace("tests.xml", "runtests.sh")):
log.info("Package seems to use the old test package format. Executing runtests.sh.")
log.info("Please consider moving to new xml based testpackages.")
log.info("More info can be found at: https://projects.maemo.org/trac/testautomation/wiki/MaemoTestDefinition")
sys.exit(subprocess.call(TEST_INPUT_FILE.replace("tests.xml", "runtests.sh"), shell=True))
# Else fail the test
else:
log.info("Couln't find tests.xml or runtests.sh.")
sys.exit(-1)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3949,
381,
199,
309,
199,
309,
1898,
334,
35,
9,
8937,
653,
745,
4674,
11098,
436,
15,
269,
2399,
1007,
338,
328,
695,
2801,
1500,
680,
199,
309,
18684,
26,
22986,
11438,
699,
745,
31445,
89,
665,
24421,
11438,
14,
656,
7697,
2392,
89,
32,
78,
745,
4674,
14,
957,
30,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
314,
5843,
778,
2559,
14,
199,
309,
199,
309,
5429,
23012,
11028,
199,
309,
844,
397,
17573,
1686,
3959,
5429,
23012,
12378,
1443,
675,
642,
570,
315,
199,
309,
1066,
1577,
554,
543,
314,
3959,
5429,
23012,
844,
28629,
2741,
543,
314,
199,
309,
2290,
503,
12,
8679,
17330,
12,
315,
1066,
1577,
554,
543,
314,
2895,
10470,
315,
199,
309,
282,
5313,
25025,
3382,
1265,
436,
653,
745,
4674,
14,
199,
309,
199,
309,
1664,
6401,
1696,
1684,
844,
11028,
199,
309,
26776,
12,
642,
570,
1443,
506,
1202,
1334,
314,
2895,
402,
314,
1664,
6401,
199,
309,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
314,
2868,
2290,
199,
309,
2752,
436,
7468,
316,
315,
314,
570,
5113,
14,
44,
12006,
5120,
315,
314,
199,
309,
27369,
402,
642,
570,
14,
221,
7754,
11248,
314,
2569,
2556,
370,
199,
309,
4868,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
9760,
199,
309,
911,
506,
7647,
26,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
1753,
13,
2383,
15,
9783,
1168,
13,
18,
14,
17,
14,
1360,
14,
199,
309,
199,
309,
1010,
10234,
12,
465,
282,
4539,
1919,
12,
653,
745,
4674,
10557,
1265,
9842,
199,
309,
4722,
4481,
14,
5723,
4481,
787,
11736,
315,
314,
653,
745,
4674,
3959,
32426,
199,
309,
2186,
1015,
413,
14,
16,
12,
5120,
315,
314,
570,
32426,
63,
15375,
14,
2424,
315,
642,
199,
309,
2559,
14,
199,
309,
199,
309,
1664,
1696,
1684,
844,
11028,
199,
309,
26776,
12,
642,
570,
1443,
506,
1202,
1334,
314,
2895,
402,
314,
1664,
199,
309,
1696,
1684,
844,
1015,
650,
14,
16,
465,
3267,
701,
314,
2868,
2290,
199,
309,
2752,
436,
7468,
316,
315,
314,
570,
5113,
14,
12006,
5120,
315,
314,
199,
309,
27369,
402,
642,
570,
14,
221,
7754,
11248,
314,
2569,
2556,
370,
199,
309,
4868,
314,
1664,
1696,
1684,
844,
1015,
650,
14,
16,
9760,
911,
506,
199,
309,
7647,
26,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
1574,
3039,
15,
11692,
14,
1360,
14,
199,
309,
199,
309,
982,
1265,
787,
625,
3253,
1314,
4190,
365,
5827,
367,
2195,
675,
12,
8749,
199,
309,
8966,
314,
21702,
27669,
737,
19227,
13,
16175,
32,
78,
745,
4674,
14,
957,
14,
199,
309,
199,
3949,
381,
199,
199,
646,
747,
199,
646,
3873,
199,
646,
900,
199,
646,
5796,
199,
646,
2197,
199,
646,
984,
199,
646,
4673,
199,
646,
2050,
465,
943,
199,
646,
12733,
199,
646,
10392,
199,
646,
10933,
199,
199,
504,
2748,
14,
9464,
14,
15325,
492,
2198,
199,
646,
2748,
14,
9464,
14,
15325,
465,
12265,
199,
504,
4967,
492,
2186,
199,
199,
2864,
63,
5638,
8727,
1075,
63,
3243,
275,
1994,
2647,
15,
6251,
7,
327,
885,
931,
370,
511,
5492,
570,
199,
2864,
63,
23545,
63,
3243,
275,
1994,
2791,
7,
199,
2864,
63,
7321,
63,
3817,
275,
488,
327,
7012,
1324,
436,
1072,
1584,
12,
2013,
687,
314,
1414,
8457,
199,
2864,
63,
8414,
63,
3817,
275,
488,
199,
2864,
63,
8414,
63,
4947,
3817,
275,
488,
199,
23037,
63,
4947,
51,
63,
12491,
63,
3022,
275,
1994,
2791,
15,
7270,
4805,
199,
199,
5418,
628,
16529,
2,
199,
199,
3472,
63,
8899,
275,
9137,
14,
16,
199,
4896,
63,
8899,
275,
959,
14,
16,
199,
30691,
63,
29108,
275,
959,
14,
16,
199,
199,
6305,
63,
4609,
63,
32385,
275,
298,
1397,
13,
8924,
2,
199,
6305,
63,
32385,
275,
298,
8924,
2,
199,
6305,
63,
8899,
275,
298,
2593,
2,
199,
6305,
63,
28376,
6989,
275,
298,
18375,
2,
199,
6305,
63,
3593,
275,
298,
745,
2,
199,
21754,
63,
1877,
63,
18074,
1075,
275,
756,
199,
10276,
63,
10452,
63,
10774,
7474,
619,
948,
275,
756,
199,
199,
2864,
63,
9517,
63,
15514,
275,
791,
80,
7,
520,
283,
48,
2744,
297,
283,
70,
7,
520,
283,
4276,
297,
283,
78,
7,
520,
283,
1763,
7934,
936,
199,
199,
4947,
63,
4807,
275,
6730,
2840,
20056,
9,
83,
61,
2818,
18331,
9,
83,
2818,
1188,
9,
83,
7,
199,
4947,
63,
5390,
63,
4807,
275,
1543,
40,
2689,
45,
2689,
51,
7,
199,
793,
14,
19602,
8,
1896,
29,
793,
14,
5287,
12,
1475,
29,
4947,
63,
4807,
12,
1434,
5045,
29,
4947,
63,
5390,
63,
4807,
12,
2547,
29,
1274,
14,
2703,
9,
421,
199,
3,
8388,
4967,
26,
199,
533,
3091,
1746,
3110,
6154,
1290,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
3091,
1746,
1304,
6154,
1290,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
3091,
1746,
6154,
1290,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
3091,
1746,
2567,
2354,
11464,
8,
1726,
304,
272,
986,
6905,
199,
533,
7640,
8,
785,
304,
272,
408,
33,
666,
5523,
1021,
367,
282,
511,
1930,
624,
272,
347,
636,
826,
721,
277,
12,
536,
275,
488,
12,
9760,
275,
488,
12,
1414,
63,
3214,
6034,
2653,
275,
6186,
63,
8899,
12,
1369,
275,
488,
12,
7124,
275,
488,
12,
1420,
63,
2604,
6034,
511,
409,
29,
403,
12,
1007,
4445,
29,
403,
12,
1930,
63,
466,
29,
403,
304,
267,
327,
3747,
511,
1930,
536,
6272,
314,
511,
2559,
267,
291,
14,
354,
275,
536,
2728,
291,
14,
7538,
275,
9760,
398,
327,
23163,
1414,
436,
2633,
465,
282,
769,
367,
3873,
370,
2112,
3062,
267,
291,
14,
1531,
63,
3214,
29,
1531,
63,
3214,
398,
291,
14,
2593,
275,
2653,
267,
291,
14,
1802,
275,
1369,
267,
291,
14,
5895,
275,
7124,
267,
291,
14,
2062,
63,
2604,
29,
2062,
63,
2604,
398,
327,
475,
6623,
370,
1314,
511,
663,
642,
511,
1930,
15006,
267,
291,
14,
396,
409,
29,
396,
409,
2728,
291,
14,
954,
4445,
29,
954,
4445
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3949,
381,
199,
309,
199,
309,
1898,
334,
35,
9,
8937,
653,
745,
4674,
11098,
436,
15,
269,
2399,
1007,
338,
328,
695,
2801,
1500,
680,
199,
309,
18684,
26,
22986,
11438,
699,
745,
31445,
89,
665,
24421,
11438,
14,
656,
7697,
2392,
89,
32,
78,
745,
4674,
14,
957,
30,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
314,
5843,
778,
2559,
14,
199,
309,
199,
309,
5429,
23012,
11028,
199,
309,
844,
397,
17573,
1686,
3959,
5429,
23012,
12378,
1443,
675,
642,
570,
315,
199,
309,
1066,
1577,
554,
543,
314,
3959,
5429,
23012,
844,
28629,
2741,
543,
314,
199,
309,
2290,
503,
12,
8679,
17330,
12,
315,
1066,
1577,
554,
543,
314,
2895,
10470,
315,
199,
309,
282,
5313,
25025,
3382,
1265,
436,
653,
745,
4674,
14,
199,
309,
199,
309,
1664,
6401,
1696,
1684,
844,
11028,
199,
309,
26776,
12,
642,
570,
1443,
506,
1202,
1334,
314,
2895,
402,
314,
1664,
6401,
199,
309,
1696,
1684,
844,
1015,
499,
14,
17,
465,
3267,
701,
314,
2868,
2290,
199,
309,
2752,
436,
7468,
316,
315,
314,
570,
5113,
14,
44,
12006,
5120,
315,
314,
199,
309,
27369,
402,
642,
570,
14,
221,
7754,
11248,
314,
2569,
2556,
370,
199,
309,
4868,
314,
1664,
6401,
1696,
1684,
844,
1015,
499,
14,
17,
9760,
199,
309,
911,
506,
7647,
26,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
1753,
13,
2383,
15,
9783,
1168,
13,
18,
14,
17,
14,
1360,
14,
199,
309,
199,
309,
1010,
10234,
12,
465,
282,
4539,
1919,
12,
653,
745,
4674,
10557,
1265,
9842,
199,
309,
4722,
4481,
14,
5723,
4481,
787,
11736,
315,
314,
653,
745,
4674,
3959,
32426,
199,
309,
2186,
1015,
413,
14,
16,
12,
5120,
315,
314,
570,
32426,
63,
15375,
14,
2424,
315,
642,
199,
309,
2559,
14,
199,
309,
199,
309,
1664,
1696,
1684,
844,
11028,
199,
309,
26776,
12,
642,
570,
1443,
506,
1202,
1334,
314,
2895,
402,
314,
1664,
199,
309,
1696,
1684,
844,
1015,
650,
14,
16,
465,
3267,
701,
314,
2868,
2290,
199,
309,
2752,
436,
7468,
316,
315,
314,
570,
5113,
14,
12006,
5120,
315,
314,
199,
309,
27369,
402,
642,
570,
14,
221,
7754,
11248,
314,
2569,
2556,
370,
199,
309,
4868,
314,
1664,
1696,
1684,
844,
1015,
650,
14,
16,
9760,
911,
506,
199,
309,
7647,
26,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
1574,
3039,
15,
11692,
14,
1360,
14,
199,
309,
199,
309,
982,
1265,
787,
625,
3253,
1314,
4190,
365,
5827,
367,
2195,
675,
12,
8749,
199,
309,
8966,
314,
21702,
27669,
737,
19227,
13,
16175,
32,
78,
745,
4674,
14,
957,
14,
199,
309,
199,
3949,
381,
199,
199,
646,
747,
199,
646,
3873,
199,
646,
900,
199,
646,
5796,
199,
646,
2197,
199,
646,
984,
199,
646,
4673,
199,
646,
2050,
465,
943,
199,
646,
12733,
199,
646,
10392,
199,
646,
10933,
199,
199,
504,
2748,
14,
9464,
14,
15325,
492,
2198,
199,
646,
2748,
14,
9464,
14,
15325,
465,
12265,
199,
504,
4967,
492,
2186,
199,
199,
2864,
63,
5638,
8727,
1075,
63,
3243,
275,
1994,
2647,
15,
6251,
7,
327,
885,
931,
370,
511,
5492,
570,
199,
2864,
63,
23545,
63,
3243,
275,
1994,
2791,
7,
199,
2864,
63,
7321,
63,
3817,
275,
488,
327,
7012,
1324,
436,
1072,
1584,
12,
2013,
687,
314,
1414,
8457,
199,
2864,
63,
8414,
63,
3817,
275,
488,
199,
2864,
63,
8414,
63,
4947,
3817,
275,
488,
199,
23037,
63,
4947,
51,
63,
12491,
63,
3022,
275,
1994,
2791,
15,
7270,
4805,
199,
199,
5418,
628,
16529,
2,
199,
199,
3472,
63,
8899,
275,
9137,
14,
16,
199,
4896,
63,
8899,
275,
959,
14,
16,
199,
30691,
63,
29108,
275,
959,
14,
16,
199,
199,
6305,
63,
4609,
63,
32385,
275,
298,
1397,
13,
8924,
2,
199,
6305,
63,
32385,
275,
298,
8924,
2,
199,
6305,
63,
8899,
275,
298,
2593,
2,
199,
6305,
63,
28376,
6989,
275,
298,
18375,
2,
199,
6305,
63,
3593,
275,
298,
745,
2,
199,
21754,
63,
1877,
63,
18074,
1075,
275,
756,
199,
10276,
63,
10452,
63,
10774,
7474,
619,
948,
275,
756,
199,
199,
2864,
63,
9517,
63,
15514,
275,
791,
80,
7,
520,
283,
48,
2744,
297,
283,
70,
7,
520,
283,
4276,
297,
283,
78,
7,
520,
283,
1763,
7934,
936,
199,
199,
4947,
63,
4807,
275,
6730,
2840,
20056,
9,
83,
61,
2818,
18331,
9,
83,
2818,
1188,
9,
83,
7,
199,
4947,
63,
5390,
63,
4807,
275,
1543,
40,
2689,
45,
2689,
51,
7,
199,
793,
14,
19602,
8,
1896,
29,
793,
14,
5287,
12,
1475,
29,
4947,
63,
4807,
12,
1434,
5045,
29,
4947,
63,
5390,
63,
4807,
12,
2547,
29,
1274,
14,
2703,
9,
421,
199,
3,
8388,
4967,
26,
199,
533,
3091,
1746,
3110,
6154,
1290,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
3091,
1746,
1304,
6154,
1290,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
3091,
1746,
6154,
1290,
547,
8,
1726,
304,
272,
986,
199,
199,
533,
3091,
1746,
2567,
2354,
11464,
8,
1726,
304,
272,
986,
6905,
199,
533,
7640,
8,
785,
304,
272,
408,
33,
666,
5523,
1021,
367,
282,
511,
1930,
624,
272,
347,
636,
826,
721,
277,
12,
536,
275,
488,
12,
9760,
275,
488,
12,
1414,
63,
3214,
6034,
2653,
275,
6186,
63,
8899,
12,
1369,
275,
488,
12,
7124,
275,
488,
12,
1420,
63,
2604,
6034,
511,
409,
29,
403,
12,
1007,
4445,
29,
403,
12,
1930,
63,
466,
29,
403,
304,
267,
327,
3747,
511,
1930,
536,
6272,
314,
511,
2559,
267,
291,
14,
354,
275,
536,
2728,
291,
14,
7538,
275,
9760,
398,
327,
23163,
1414,
436,
2633,
465,
282,
769,
367,
3873,
370,
2112,
3062,
267,
291,
14,
1531,
63,
3214,
29,
1531,
63,
3214,
398,
291,
14,
2593,
275,
2653,
267,
291,
14,
1802,
275,
1369,
267,
291,
14,
5895,
275,
7124,
267,
291,
14,
2062,
63,
2604,
29,
2062,
63,
2604,
398,
327,
475,
6623,
370,
1314,
511,
663,
642,
511,
1930,
15006,
267,
291,
14,
396,
409,
29,
396,
409,
2728,
291,
14,
954,
4445,
29,
954,
4445,
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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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
] |
puzan/ansible
|
test/units/module_utils/basic/test_deprecate_warn.py
|
50
|
2719
|
# -*- coding: utf-8 -*-
#
# 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/>.
import json
import sys
from ansible.compat.tests import unittest
from units.mock.procenv import swap_stdin_and_argv, swap_stdout
import ansible.module_utils.basic
class TestAnsibleModuleWarnDeprecate(unittest.TestCase):
"""Test the AnsibleModule Warn Method"""
def test_warn(self):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}))
with swap_stdin_and_argv(stdin_data=args):
with swap_stdout():
ansible.module_utils.basic._ANSIBLE_ARGS = None
am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(),
)
am._name = 'unittest'
am.warn('warning1')
with self.assertRaises(SystemExit):
am.exit_json(warnings=['warning2'])
self.assertEquals(json.loads(sys.stdout.getvalue())['warnings'], ['warning1', 'warning2'])
def test_deprecate(self):
args = json.dumps(dict(ANSIBLE_MODULE_ARGS={}))
with swap_stdin_and_argv(stdin_data=args):
with swap_stdout():
ansible.module_utils.basic._ANSIBLE_ARGS = None
am = ansible.module_utils.basic.AnsibleModule(
argument_spec = dict(),
)
am._name = 'unittest'
am.deprecate('deprecation1')
am.deprecate('deprecation2', '2.3')
with self.assertRaises(SystemExit):
am.exit_json(deprecations=['deprecation3', ('deprecation4', '2.4')])
output = json.loads(sys.stdout.getvalue())
self.assertTrue('warnings' not in output or output['warnings'] == [])
self.assertEquals(output['deprecations'], [
{u'msg': u'deprecation1', u'version': None},
{u'msg': u'deprecation2', u'version': '2.3'},
{u'msg': u'deprecation3', u'version': None},
{u'msg': u'deprecation4', u'version': '2.4'},
])
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2022,
199,
646,
984,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
6204,
14,
1805,
14,
4687,
1813,
492,
11413,
63,
6626,
63,
460,
63,
3020,
12,
11413,
63,
2703,
199,
199,
646,
3242,
14,
578,
63,
1208,
14,
4316,
421,
199,
533,
1379,
10047,
2377,
22673,
872,
21826,
8,
2796,
14,
1746,
304,
272,
408,
774,
314,
6953,
644,
1060,
9075,
624,
339,
347,
511,
63,
4050,
8,
277,
304,
267,
1249,
275,
2022,
14,
4180,
8,
807,
8,
8490,
63,
10001,
63,
13990,
7622,
430,
267,
543,
11413,
63,
6626,
63,
460,
63,
3020,
8,
6626,
63,
576,
29,
589,
304,
288,
543,
11413,
63,
2703,
837,
2234,
3242,
14,
578,
63,
1208,
14,
4316,
423,
8490,
63,
13990,
275,
488,
355,
8140,
275,
3242,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
8,
490,
1423,
63,
1650,
275,
1211,
1062,
355,
776,
355,
8140,
423,
354,
275,
283,
2796,
7,
2234,
8140,
14,
4050,
360,
3764,
17,
358,
2234,
543,
291,
14,
1855,
8,
24738,
304,
490,
8140,
14,
2224,
63,
1001,
8,
5451,
2968,
3764,
18,
1105,
355,
291,
14,
2947,
8,
1001,
14,
3640,
8,
1274,
14,
2703,
14,
7150,
1012,
459,
5451,
995,
788,
3764,
17,
297,
283,
3764,
18,
1105,
339,
347,
511,
63,
27891,
8,
277,
304,
267,
1249,
275,
2022,
14,
4180,
8,
807,
8,
8490,
63,
10001,
63,
13990,
7622,
430,
267,
543,
11413,
63,
6626,
63,
460,
63,
3020,
8,
6626,
63,
576,
29,
589,
304,
288,
543,
11413,
63,
2703,
837,
2234,
3242,
14,
578,
63,
1208,
14,
4316,
423,
8490,
63,
13990,
275,
488,
355,
8140,
275,
3242,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
8,
490,
1423,
63,
1650,
275,
1211,
1062,
355,
776,
355,
8140,
423,
354,
275,
283,
2796,
7,
2234,
8140,
14,
27891,
360,
15383,
17,
358,
355,
8140,
14,
27891,
360,
15383,
18,
297,
283,
18,
14,
19,
358,
2234,
543,
291,
14,
1855,
8,
24738,
304,
490,
8140,
14,
2224,
63,
1001,
8,
15383,
83,
2968,
15383,
19,
297,
661,
15383,
20,
297,
283,
18,
14,
20,
2023,
355,
1072,
275,
2022,
14,
3640,
8,
1274,
14,
2703,
14,
7150,
1012,
355,
291,
14,
1815,
360,
5451,
7,
440,
315,
1072,
503,
1072,
459,
5451,
418,
508,
3073,
355,
291,
14,
2947,
8,
1199,
459,
15383,
83,
995,
359,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
17,
297,
399,
9064,
82,
438,
356,
488,
1386,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
18,
297,
399,
9064,
82,
438,
356,
283,
18,
14,
19,
2267,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
19,
297,
399,
9064,
82,
438,
356,
488,
1386,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
20,
297,
399,
9064,
82,
438,
356,
283,
18,
14,
20,
2267,
355,
4794,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2022,
199,
646,
984,
199,
199,
504,
3242,
14,
5819,
14,
2219,
492,
2882,
199,
504,
6204,
14,
1805,
14,
4687,
1813,
492,
11413,
63,
6626,
63,
460,
63,
3020,
12,
11413,
63,
2703,
199,
199,
646,
3242,
14,
578,
63,
1208,
14,
4316,
421,
199,
533,
1379,
10047,
2377,
22673,
872,
21826,
8,
2796,
14,
1746,
304,
272,
408,
774,
314,
6953,
644,
1060,
9075,
624,
339,
347,
511,
63,
4050,
8,
277,
304,
267,
1249,
275,
2022,
14,
4180,
8,
807,
8,
8490,
63,
10001,
63,
13990,
7622,
430,
267,
543,
11413,
63,
6626,
63,
460,
63,
3020,
8,
6626,
63,
576,
29,
589,
304,
288,
543,
11413,
63,
2703,
837,
2234,
3242,
14,
578,
63,
1208,
14,
4316,
423,
8490,
63,
13990,
275,
488,
355,
8140,
275,
3242,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
8,
490,
1423,
63,
1650,
275,
1211,
1062,
355,
776,
355,
8140,
423,
354,
275,
283,
2796,
7,
2234,
8140,
14,
4050,
360,
3764,
17,
358,
2234,
543,
291,
14,
1855,
8,
24738,
304,
490,
8140,
14,
2224,
63,
1001,
8,
5451,
2968,
3764,
18,
1105,
355,
291,
14,
2947,
8,
1001,
14,
3640,
8,
1274,
14,
2703,
14,
7150,
1012,
459,
5451,
995,
788,
3764,
17,
297,
283,
3764,
18,
1105,
339,
347,
511,
63,
27891,
8,
277,
304,
267,
1249,
275,
2022,
14,
4180,
8,
807,
8,
8490,
63,
10001,
63,
13990,
7622,
430,
267,
543,
11413,
63,
6626,
63,
460,
63,
3020,
8,
6626,
63,
576,
29,
589,
304,
288,
543,
11413,
63,
2703,
837,
2234,
3242,
14,
578,
63,
1208,
14,
4316,
423,
8490,
63,
13990,
275,
488,
355,
8140,
275,
3242,
14,
578,
63,
1208,
14,
4316,
14,
10047,
2377,
8,
490,
1423,
63,
1650,
275,
1211,
1062,
355,
776,
355,
8140,
423,
354,
275,
283,
2796,
7,
2234,
8140,
14,
27891,
360,
15383,
17,
358,
355,
8140,
14,
27891,
360,
15383,
18,
297,
283,
18,
14,
19,
358,
2234,
543,
291,
14,
1855,
8,
24738,
304,
490,
8140,
14,
2224,
63,
1001,
8,
15383,
83,
2968,
15383,
19,
297,
661,
15383,
20,
297,
283,
18,
14,
20,
2023,
355,
1072,
275,
2022,
14,
3640,
8,
1274,
14,
2703,
14,
7150,
1012,
355,
291,
14,
1815,
360,
5451,
7,
440,
315,
1072,
503,
1072,
459,
5451,
418,
508,
3073,
355,
291,
14,
2947,
8,
1199,
459,
15383,
83,
995,
359,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
17,
297,
399,
9064,
82,
438,
356,
488,
1386,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
18,
297,
399,
9064,
82,
438,
356,
283,
18,
14,
19,
2267,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
19,
297,
399,
9064,
82,
438,
356,
488,
1386,
490,
469,
85,
6704,
1226,
356,
399,
5121,
69,
6444,
20,
297,
399,
9064,
82,
438,
356,
283,
18,
14,
20,
2267,
355,
4794,
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,
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,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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
] |
capveg/ONL
|
components/all/vendor-config/qemu/src/python/qemu/__init__.py
|
9
|
1313
|
#!/usr/bin/python
############################################################
# <bsn.cl fy=2013 v=onl>
#
# Copyright 2013, 2014 Big Switch Networks, Inc.
#
# Licensed under the Eclipse Public License, Version 1.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.eclipse.org/legal/epl-v10.html
#
# 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.
#
# </bsn.cl>
############################################################
#
# OpenNetworkPlatform support for QEMU Platforms.
#
############################################################
from onl.platform.base import OpenNetworkPlatformBase, sysinfo
import struct
import time
class OpenNetworkPlatformQEMU(OpenNetworkPlatformBase):
def manufacturer(self):
return "QEMU"
def _sys_info_dict(self):
return {
sysinfo.MAGIC : 0,
sysinfo.PRODUCT_NAME : "QEMU Emulation",
sysinfo.PART_NUMBER : "QEMU"
}
|
epl-1.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
26207,
381,
199,
3,
665,
1533,
78,
14,
429,
289,
89,
29,
6965,
373,
29,
265,
76,
30,
199,
3,
221,
199,
3,
263,
1898,
6171,
12,
6927,
13123,
17711,
17138,
12,
3277,
14,
263,
199,
3,
221,
199,
3,
3909,
1334,
314,
662,
7548,
261,
1684,
844,
12,
3394,
413,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
221,
199,
3,
263,
1455,
921,
1544,
14,
825,
3587,
261,
14,
1308,
15,
9666,
15,
69,
1168,
13,
86,
709,
14,
1360,
199,
3,
221,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
199,
3,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
199,
3,
844,
14,
199,
3,
221,
199,
3,
3068,
1533,
78,
14,
429,
30,
199,
26207,
381,
199,
3,
199,
3,
3232,
4491,
10397,
2291,
367,
1413,
2769,
53,
510,
4452,
3351,
14,
221,
199,
3,
199,
26207,
381,
199,
504,
641,
76,
14,
3246,
14,
1095,
492,
3232,
4491,
10397,
1563,
12,
984,
815,
199,
646,
2702,
199,
646,
900,
199,
199,
533,
3232,
4491,
10397,
49,
2769,
53,
8,
4299,
4491,
10397,
1563,
304,
339,
347,
2169,
21087,
8,
277,
304,
267,
372,
298,
49,
2769,
53,
2,
339,
347,
485,
1274,
63,
815,
63,
807,
8,
277,
304,
398,
372,
469,
288,
984,
815,
14,
19973,
520,
378,
12,
7205,
984,
815,
14,
14853,
63,
2339,
520,
298,
49,
2769,
53,
662,
7720,
401,
7205,
984,
815,
14,
14848,
63,
9190,
520,
298,
49,
2769,
53,
2,
288,
789,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
26207,
381,
199,
3,
665,
1533,
78,
14,
429,
289,
89,
29,
6965,
373,
29,
265,
76,
30,
199,
3,
221,
199,
3,
263,
1898,
6171,
12,
6927,
13123,
17711,
17138,
12,
3277,
14,
263,
199,
3,
221,
199,
3,
3909,
1334,
314,
662,
7548,
261,
1684,
844,
12,
3394,
413,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
221,
199,
3,
263,
1455,
921,
1544,
14,
825,
3587,
261,
14,
1308,
15,
9666,
15,
69,
1168,
13,
86,
709,
14,
1360,
199,
3,
221,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
199,
3,
1902,
4056,
503,
2478,
14,
1666,
314,
844,
367,
314,
2488,
199,
3,
2637,
4210,
3443,
436,
4204,
1334,
314,
199,
3,
844,
14,
199,
3,
221,
199,
3,
3068,
1533,
78,
14,
429,
30,
199,
26207,
381,
199,
3,
199,
3,
3232,
4491,
10397,
2291,
367,
1413,
2769,
53,
510,
4452,
3351,
14,
221,
199,
3,
199,
26207,
381,
199,
504,
641,
76,
14,
3246,
14,
1095,
492,
3232,
4491,
10397,
1563,
12,
984,
815,
199,
646,
2702,
199,
646,
900,
199,
199,
533,
3232,
4491,
10397,
49,
2769,
53,
8,
4299,
4491,
10397,
1563,
304,
339,
347,
2169,
21087,
8,
277,
304,
267,
372,
298,
49,
2769,
53,
2,
339,
347,
485,
1274,
63,
815,
63,
807,
8,
277,
304,
398,
372,
469,
288,
984,
815,
14,
19973,
520,
378,
12,
7205,
984,
815,
14,
14853,
63,
2339,
520,
298,
49,
2769,
53,
662,
7720,
401,
7205,
984,
815,
14,
14848,
63,
9190,
520,
298,
49,
2769,
53,
2,
288,
789,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
egabancho/invenio
|
invenio/modules/indexer/tokenizers/BibIndexDOITokenizer.py
|
2
|
2014
|
# -*- coding:utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2013 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
from invenio.modules.indexer.tokenizers.BibIndexFilteringTokenizer import BibIndexFilteringTokenizer
class BibIndexDOITokenizer(BibIndexFilteringTokenizer):
"""
Filtering tokenizer which tokenizes DOI tag (0247_a)
only if "0247_2" tag is present and its value equals "DOI"
and 909C4a tag without any constraints.
"""
def __init__(self, stemming_language=None, remove_stopwords=False, remove_html_markup=False, remove_latex_markup=False):
self.rules = (('0247_a', '2', 'DOI'), ('909C4a', '', ''))
def get_tokenizing_function(self, wordtable_type):
"""Returns proper tokenizing function"""
return self.tokenize
def tokenize_via_recjson(self, recID):
"""
Nonmarc version of tokenize function for DOI.
Note: with nonmarc we don't need to filter anymore.
We just need to take value from record because we
use bibfield here.
"""
rec = get_record(recID)
values = rec.get('doi', [])
return values
def get_nonmarc_tokenizing_function(self, table_type):
"""
Returns proper tokenizing function for non-marc records.
"""
return self.tokenize_via_recjson
|
gpl-2.0
|
[
3,
1882,
2803,
26,
1624,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6171,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
504,
13640,
14,
3112,
14,
15615,
14,
1418,
6315,
14,
25217,
2681,
4131,
316,
21782,
492,
21949,
2681,
4131,
316,
21782,
421,
199,
533,
21949,
2681,
1649,
649,
2858,
1793,
8,
25217,
2681,
4131,
316,
21782,
304,
272,
408,
267,
9388,
316,
14803,
1314,
1526,
6491,
3506,
41,
1947,
334,
996,
2417,
63,
65,
9,
267,
1454,
340,
298,
996,
2417,
63,
18,
2,
1947,
365,
3451,
436,
2399,
574,
18527,
298,
1649,
41,
2,
267,
436,
1749,
1643,
35,
20,
65,
1947,
1928,
1263,
9565,
14,
272,
408,
2378,
347,
636,
826,
721,
277,
12,
17408,
14566,
63,
3671,
29,
403,
12,
2813,
63,
2379,
3148,
29,
797,
12,
2813,
63,
1360,
63,
10131,
29,
797,
12,
2813,
63,
7572,
63,
10131,
29,
797,
304,
267,
291,
14,
4423,
275,
13636,
996,
2417,
63,
65,
297,
283,
18,
297,
283,
1649,
41,
659,
661,
26578,
35,
20,
65,
297,
3260,
12381,
2378,
347,
664,
63,
1418,
9147,
63,
1593,
8,
277,
12,
4349,
1224,
63,
466,
304,
267,
408,
3407,
5576,
1526,
9147,
805,
624,
267,
372,
291,
14,
15246,
339,
347,
13343,
63,
12897,
63,
2761,
1001,
8,
277,
12,
6488,
998,
304,
267,
408,
267,
10172,
30342,
1015,
402,
13343,
805,
367,
3506,
41,
14,
267,
3390,
26,
543,
2222,
30342,
781,
2793,
1133,
1929,
370,
2457,
20827,
14,
267,
2136,
2951,
1929,
370,
5452,
574,
687,
2777,
2952,
781,
267,
675,
11314,
698,
2348,
14,
267,
408,
267,
6488,
275,
664,
63,
3059,
8,
2761,
998,
9,
267,
1338,
275,
6488,
14,
362,
360,
27334,
297,
3073,
267,
372,
1338,
339,
347,
664,
63,
2865,
30342,
63,
1418,
9147,
63,
1593,
8,
277,
12,
1817,
63,
466,
304,
267,
408,
267,
1803,
5576,
1526,
9147,
805,
367,
2222,
13,
30342,
5767,
14,
267,
408,
267,
372,
291,
14,
15246,
63,
12897,
63,
2761,
1001,
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
] |
[
1882,
2803,
26,
1624,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6171,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
504,
13640,
14,
3112,
14,
15615,
14,
1418,
6315,
14,
25217,
2681,
4131,
316,
21782,
492,
21949,
2681,
4131,
316,
21782,
421,
199,
533,
21949,
2681,
1649,
649,
2858,
1793,
8,
25217,
2681,
4131,
316,
21782,
304,
272,
408,
267,
9388,
316,
14803,
1314,
1526,
6491,
3506,
41,
1947,
334,
996,
2417,
63,
65,
9,
267,
1454,
340,
298,
996,
2417,
63,
18,
2,
1947,
365,
3451,
436,
2399,
574,
18527,
298,
1649,
41,
2,
267,
436,
1749,
1643,
35,
20,
65,
1947,
1928,
1263,
9565,
14,
272,
408,
2378,
347,
636,
826,
721,
277,
12,
17408,
14566,
63,
3671,
29,
403,
12,
2813,
63,
2379,
3148,
29,
797,
12,
2813,
63,
1360,
63,
10131,
29,
797,
12,
2813,
63,
7572,
63,
10131,
29,
797,
304,
267,
291,
14,
4423,
275,
13636,
996,
2417,
63,
65,
297,
283,
18,
297,
283,
1649,
41,
659,
661,
26578,
35,
20,
65,
297,
3260,
12381,
2378,
347,
664,
63,
1418,
9147,
63,
1593,
8,
277,
12,
4349,
1224,
63,
466,
304,
267,
408,
3407,
5576,
1526,
9147,
805,
624,
267,
372,
291,
14,
15246,
339,
347,
13343,
63,
12897,
63,
2761,
1001,
8,
277,
12,
6488,
998,
304,
267,
408,
267,
10172,
30342,
1015,
402,
13343,
805,
367,
3506,
41,
14,
267,
3390,
26,
543,
2222,
30342,
781,
2793,
1133,
1929,
370,
2457,
20827,
14,
267,
2136,
2951,
1929,
370,
5452,
574,
687,
2777,
2952,
781,
267,
675,
11314,
698,
2348,
14,
267,
408,
267,
6488,
275,
664,
63,
3059,
8,
2761,
998,
9,
267,
1338,
275,
6488,
14,
362,
360,
27334,
297,
3073,
267,
372,
1338,
339,
347,
664,
63,
2865,
30342,
63,
1418,
9147,
63,
1593,
8,
277,
12,
1817,
63,
466,
304,
267,
408,
267,
1803,
5576,
1526,
9147,
805,
367,
2222,
13,
30342,
5767,
14,
267,
408,
267,
372,
291,
14,
15246,
63,
12897,
63,
2761,
1001,
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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