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
|
|---|---|---|---|---|---|---|---|---|
vipins/ccccms
|
env/Lib/site-packages/html5lib/constants.py
|
100
|
88603
|
import string, gettext
_ = gettext.gettext
try:
frozenset
except NameError:
# Import from the sets module for python 2.3
from sets import Set as set
from sets import ImmutableSet as frozenset
EOF = None
E = {
"null-character":
_(u"Null character in input stream, replaced with U+FFFD."),
"invalid-codepoint":
_(u"Invalid codepoint in stream."),
"incorrectly-placed-solidus":
_(u"Solidus (/) incorrectly placed in tag."),
"incorrect-cr-newline-entity":
_(u"Incorrect CR newline entity, replaced with LF."),
"illegal-windows-1252-entity":
_(u"Entity used with illegal number (windows-1252 reference)."),
"cant-convert-numeric-entity":
_(u"Numeric entity couldn't be converted to character "
u"(codepoint U+%(charAsInt)08x)."),
"illegal-codepoint-for-numeric-entity":
_(u"Numeric entity represents an illegal codepoint: "
u"U+%(charAsInt)08x."),
"numeric-entity-without-semicolon":
_(u"Numeric entity didn't end with ';'."),
"expected-numeric-entity-but-got-eof":
_(u"Numeric entity expected. Got end of file instead."),
"expected-numeric-entity":
_(u"Numeric entity expected but none found."),
"named-entity-without-semicolon":
_(u"Named entity didn't end with ';'."),
"expected-named-entity":
_(u"Named entity expected. Got none."),
"attributes-in-end-tag":
_(u"End tag contains unexpected attributes."),
'self-closing-flag-on-end-tag':
_(u"End tag contains unexpected self-closing flag."),
"expected-tag-name-but-got-right-bracket":
_(u"Expected tag name. Got '>' instead."),
"expected-tag-name-but-got-question-mark":
_(u"Expected tag name. Got '?' instead. (HTML doesn't "
u"support processing instructions.)"),
"expected-tag-name":
_(u"Expected tag name. Got something else instead"),
"expected-closing-tag-but-got-right-bracket":
_(u"Expected closing tag. Got '>' instead. Ignoring '</>'."),
"expected-closing-tag-but-got-eof":
_(u"Expected closing tag. Unexpected end of file."),
"expected-closing-tag-but-got-char":
_(u"Expected closing tag. Unexpected character '%(data)s' found."),
"eof-in-tag-name":
_(u"Unexpected end of file in the tag name."),
"expected-attribute-name-but-got-eof":
_(u"Unexpected end of file. Expected attribute name instead."),
"eof-in-attribute-name":
_(u"Unexpected end of file in attribute name."),
"invalid-character-in-attribute-name":
_(u"Invalid chracter in attribute name"),
"duplicate-attribute":
_(u"Dropped duplicate attribute on tag."),
"expected-end-of-tag-name-but-got-eof":
_(u"Unexpected end of file. Expected = or end of tag."),
"expected-attribute-value-but-got-eof":
_(u"Unexpected end of file. Expected attribute value."),
"expected-attribute-value-but-got-right-bracket":
_(u"Expected attribute value. Got '>' instead."),
'equals-in-unquoted-attribute-value':
_(u"Unexpected = in unquoted attribute"),
'unexpected-character-in-unquoted-attribute-value':
_(u"Unexpected character in unquoted attribute"),
"invalid-character-after-attribute-name":
_(u"Unexpected character after attribute name."),
"unexpected-character-after-attribute-value":
_(u"Unexpected character after attribute value."),
"eof-in-attribute-value-double-quote":
_(u"Unexpected end of file in attribute value (\")."),
"eof-in-attribute-value-single-quote":
_(u"Unexpected end of file in attribute value (')."),
"eof-in-attribute-value-no-quotes":
_(u"Unexpected end of file in attribute value."),
"unexpected-EOF-after-solidus-in-tag":
_(u"Unexpected end of file in tag. Expected >"),
"unexpected-character-after-soldius-in-tag":
_(u"Unexpected character after / in tag. Expected >"),
"expected-dashes-or-doctype":
_(u"Expected '--' or 'DOCTYPE'. Not found."),
"unexpected-bang-after-double-dash-in-comment":
_(u"Unexpected ! after -- in comment"),
"unexpected-space-after-double-dash-in-comment":
_(u"Unexpected space after -- in comment"),
"incorrect-comment":
_(u"Incorrect comment."),
"eof-in-comment":
_(u"Unexpected end of file in comment."),
"eof-in-comment-end-dash":
_(u"Unexpected end of file in comment (-)"),
"unexpected-dash-after-double-dash-in-comment":
_(u"Unexpected '-' after '--' found in comment."),
"eof-in-comment-double-dash":
_(u"Unexpected end of file in comment (--)."),
"eof-in-comment-end-space-state":
_(u"Unexpected end of file in comment."),
"eof-in-comment-end-bang-state":
_(u"Unexpected end of file in comment."),
"unexpected-char-in-comment":
_(u"Unexpected character in comment found."),
"need-space-after-doctype":
_(u"No space after literal string 'DOCTYPE'."),
"expected-doctype-name-but-got-right-bracket":
_(u"Unexpected > character. Expected DOCTYPE name."),
"expected-doctype-name-but-got-eof":
_(u"Unexpected end of file. Expected DOCTYPE name."),
"eof-in-doctype-name":
_(u"Unexpected end of file in DOCTYPE name."),
"eof-in-doctype":
_(u"Unexpected end of file in DOCTYPE."),
"expected-space-or-right-bracket-in-doctype":
_(u"Expected space or '>'. Got '%(data)s'"),
"unexpected-end-of-doctype":
_(u"Unexpected end of DOCTYPE."),
"unexpected-char-in-doctype":
_(u"Unexpected character in DOCTYPE."),
"eof-in-innerhtml":
_(u"XXX innerHTML EOF"),
"unexpected-doctype":
_(u"Unexpected DOCTYPE. Ignored."),
"non-html-root":
_(u"html needs to be the first start tag."),
"expected-doctype-but-got-eof":
_(u"Unexpected End of file. Expected DOCTYPE."),
"unknown-doctype":
_(u"Erroneous DOCTYPE."),
"expected-doctype-but-got-chars":
_(u"Unexpected non-space characters. Expected DOCTYPE."),
"expected-doctype-but-got-start-tag":
_(u"Unexpected start tag (%(name)s). Expected DOCTYPE."),
"expected-doctype-but-got-end-tag":
_(u"Unexpected end tag (%(name)s). Expected DOCTYPE."),
"end-tag-after-implied-root":
_(u"Unexpected end tag (%(name)s) after the (implied) root element."),
"expected-named-closing-tag-but-got-eof":
_(u"Unexpected end of file. Expected end tag (%(name)s)."),
"two-heads-are-not-better-than-one":
_(u"Unexpected start tag head in existing head. Ignored."),
"unexpected-end-tag":
_(u"Unexpected end tag (%(name)s). Ignored."),
"unexpected-start-tag-out-of-my-head":
_(u"Unexpected start tag (%(name)s) that can be in head. Moved."),
"unexpected-start-tag":
_(u"Unexpected start tag (%(name)s)."),
"missing-end-tag":
_(u"Missing end tag (%(name)s)."),
"missing-end-tags":
_(u"Missing end tags (%(name)s)."),
"unexpected-start-tag-implies-end-tag":
_(u"Unexpected start tag (%(startName)s) "
u"implies end tag (%(endName)s)."),
"unexpected-start-tag-treated-as":
_(u"Unexpected start tag (%(originalName)s). Treated as %(newName)s."),
"deprecated-tag":
_(u"Unexpected start tag %(name)s. Don't use it!"),
"unexpected-start-tag-ignored":
_(u"Unexpected start tag %(name)s. Ignored."),
"expected-one-end-tag-but-got-another":
_(u"Unexpected end tag (%(gotName)s). "
u"Missing end tag (%(expectedName)s)."),
"end-tag-too-early":
_(u"End tag (%(name)s) seen too early. Expected other end tag."),
"end-tag-too-early-named":
_(u"Unexpected end tag (%(gotName)s). Expected end tag (%(expectedName)s)."),
"end-tag-too-early-ignored":
_(u"End tag (%(name)s) seen too early. Ignored."),
"adoption-agency-1.1":
_(u"End tag (%(name)s) violates step 1, "
u"paragraph 1 of the adoption agency algorithm."),
"adoption-agency-1.2":
_(u"End tag (%(name)s) violates step 1, "
u"paragraph 2 of the adoption agency algorithm."),
"adoption-agency-1.3":
_(u"End tag (%(name)s) violates step 1, "
u"paragraph 3 of the adoption agency algorithm."),
"unexpected-end-tag-treated-as":
_(u"Unexpected end tag (%(originalName)s). Treated as %(newName)s."),
"no-end-tag":
_(u"This element (%(name)s) has no end tag."),
"unexpected-implied-end-tag-in-table":
_(u"Unexpected implied end tag (%(name)s) in the table phase."),
"unexpected-implied-end-tag-in-table-body":
_(u"Unexpected implied end tag (%(name)s) in the table body phase."),
"unexpected-char-implies-table-voodoo":
_(u"Unexpected non-space characters in "
u"table context caused voodoo mode."),
"unexpected-hidden-input-in-table":
_(u"Unexpected input with type hidden in table context."),
"unexpected-form-in-table":
_(u"Unexpected form in table context."),
"unexpected-start-tag-implies-table-voodoo":
_(u"Unexpected start tag (%(name)s) in "
u"table context caused voodoo mode."),
"unexpected-end-tag-implies-table-voodoo":
_(u"Unexpected end tag (%(name)s) in "
u"table context caused voodoo mode."),
"unexpected-cell-in-table-body":
_(u"Unexpected table cell start tag (%(name)s) "
u"in the table body phase."),
"unexpected-cell-end-tag":
_(u"Got table cell end tag (%(name)s) "
u"while required end tags are missing."),
"unexpected-end-tag-in-table-body":
_(u"Unexpected end tag (%(name)s) in the table body phase. Ignored."),
"unexpected-implied-end-tag-in-table-row":
_(u"Unexpected implied end tag (%(name)s) in the table row phase."),
"unexpected-end-tag-in-table-row":
_(u"Unexpected end tag (%(name)s) in the table row phase. Ignored."),
"unexpected-select-in-select":
_(u"Unexpected select start tag in the select phase "
u"treated as select end tag."),
"unexpected-input-in-select":
_(u"Unexpected input start tag in the select phase."),
"unexpected-start-tag-in-select":
_(u"Unexpected start tag token (%(name)s in the select phase. "
u"Ignored."),
"unexpected-end-tag-in-select":
_(u"Unexpected end tag (%(name)s) in the select phase. Ignored."),
"unexpected-table-element-start-tag-in-select-in-table":
_(u"Unexpected table element start tag (%(name)s) in the select in table phase."),
"unexpected-table-element-end-tag-in-select-in-table":
_(u"Unexpected table element end tag (%(name)s) in the select in table phase."),
"unexpected-char-after-body":
_(u"Unexpected non-space characters in the after body phase."),
"unexpected-start-tag-after-body":
_(u"Unexpected start tag token (%(name)s)"
u" in the after body phase."),
"unexpected-end-tag-after-body":
_(u"Unexpected end tag token (%(name)s)"
u" in the after body phase."),
"unexpected-char-in-frameset":
_(u"Unepxected characters in the frameset phase. Characters ignored."),
"unexpected-start-tag-in-frameset":
_(u"Unexpected start tag token (%(name)s)"
u" in the frameset phase. Ignored."),
"unexpected-frameset-in-frameset-innerhtml":
_(u"Unexpected end tag token (frameset) "
u"in the frameset phase (innerHTML)."),
"unexpected-end-tag-in-frameset":
_(u"Unexpected end tag token (%(name)s)"
u" in the frameset phase. Ignored."),
"unexpected-char-after-frameset":
_(u"Unexpected non-space characters in the "
u"after frameset phase. Ignored."),
"unexpected-start-tag-after-frameset":
_(u"Unexpected start tag (%(name)s)"
u" in the after frameset phase. Ignored."),
"unexpected-end-tag-after-frameset":
_(u"Unexpected end tag (%(name)s)"
u" in the after frameset phase. Ignored."),
"unexpected-end-tag-after-body-innerhtml":
_(u"Unexpected end tag after body(innerHtml)"),
"expected-eof-but-got-char":
_(u"Unexpected non-space characters. Expected end of file."),
"expected-eof-but-got-start-tag":
_(u"Unexpected start tag (%(name)s)"
u". Expected end of file."),
"expected-eof-but-got-end-tag":
_(u"Unexpected end tag (%(name)s)"
u". Expected end of file."),
"eof-in-table":
_(u"Unexpected end of file. Expected table content."),
"eof-in-select":
_(u"Unexpected end of file. Expected select content."),
"eof-in-frameset":
_(u"Unexpected end of file. Expected frameset content."),
"eof-in-script-in-script":
_(u"Unexpected end of file. Expected script content."),
"eof-in-foreign-lands":
_(u"Unexpected end of file. Expected foreign content"),
"non-void-element-with-trailing-solidus":
_(u"Trailing solidus not allowed on element %(name)s"),
"unexpected-html-element-in-foreign-content":
_(u"Element %(name)s not allowed in a non-html context"),
"unexpected-end-tag-before-html":
_(u"Unexpected end tag (%(name)s) before html."),
"XXX-undefined-error":
(u"Undefined error (this sucks and should be fixed)"),
}
namespaces = {
"html":"http://www.w3.org/1999/xhtml",
"mathml":"http://www.w3.org/1998/Math/MathML",
"svg":"http://www.w3.org/2000/svg",
"xlink":"http://www.w3.org/1999/xlink",
"xml":"http://www.w3.org/XML/1998/namespace",
"xmlns":"http://www.w3.org/2000/xmlns/"
}
scopingElements = frozenset((
(namespaces["html"], "applet"),
(namespaces["html"], "caption"),
(namespaces["html"], "html"),
(namespaces["html"], "marquee"),
(namespaces["html"], "object"),
(namespaces["html"], "table"),
(namespaces["html"], "td"),
(namespaces["html"], "th"),
(namespaces["mathml"], "mi"),
(namespaces["mathml"], "mo"),
(namespaces["mathml"], "mn"),
(namespaces["mathml"], "ms"),
(namespaces["mathml"], "mtext"),
(namespaces["mathml"], "annotation-xml"),
(namespaces["svg"], "foreignObject"),
(namespaces["svg"], "desc"),
(namespaces["svg"], "title"),
))
formattingElements = frozenset((
(namespaces["html"], "a"),
(namespaces["html"], "b"),
(namespaces["html"], "big"),
(namespaces["html"], "code"),
(namespaces["html"], "em"),
(namespaces["html"], "font"),
(namespaces["html"], "i"),
(namespaces["html"], "nobr"),
(namespaces["html"], "s"),
(namespaces["html"], "small"),
(namespaces["html"], "strike"),
(namespaces["html"], "strong"),
(namespaces["html"], "tt"),
(namespaces["html"], "u")
))
specialElements = frozenset((
(namespaces["html"], "address"),
(namespaces["html"], "applet"),
(namespaces["html"], "area"),
(namespaces["html"], "article"),
(namespaces["html"], "aside"),
(namespaces["html"], "base"),
(namespaces["html"], "basefont"),
(namespaces["html"], "bgsound"),
(namespaces["html"], "blockquote"),
(namespaces["html"], "body"),
(namespaces["html"], "br"),
(namespaces["html"], "button"),
(namespaces["html"], "caption"),
(namespaces["html"], "center"),
(namespaces["html"], "col"),
(namespaces["html"], "colgroup"),
(namespaces["html"], "command"),
(namespaces["html"], "dd"),
(namespaces["html"], "details"),
(namespaces["html"], "dir"),
(namespaces["html"], "div"),
(namespaces["html"], "dl"),
(namespaces["html"], "dt"),
(namespaces["html"], "embed"),
(namespaces["html"], "fieldset"),
(namespaces["html"], "figure"),
(namespaces["html"], "footer"),
(namespaces["html"], "form"),
(namespaces["html"], "frame"),
(namespaces["html"], "frameset"),
(namespaces["html"], "h1"),
(namespaces["html"], "h2"),
(namespaces["html"], "h3"),
(namespaces["html"], "h4"),
(namespaces["html"], "h5"),
(namespaces["html"], "h6"),
(namespaces["html"], "head"),
(namespaces["html"], "header"),
(namespaces["html"], "hr"),
(namespaces["html"], "html"),
(namespaces["html"], "iframe"),
# Note that image is commented out in the spec as "this isn't an
# element that can end up on the stack, so it doesn't matter,"
(namespaces["html"], "image"),
(namespaces["html"], "img"),
(namespaces["html"], "input"),
(namespaces["html"], "isindex"),
(namespaces["html"], "li"),
(namespaces["html"], "link"),
(namespaces["html"], "listing"),
(namespaces["html"], "marquee"),
(namespaces["html"], "menu"),
(namespaces["html"], "meta"),
(namespaces["html"], "nav"),
(namespaces["html"], "noembed"),
(namespaces["html"], "noframes"),
(namespaces["html"], "noscript"),
(namespaces["html"], "object"),
(namespaces["html"], "ol"),
(namespaces["html"], "p"),
(namespaces["html"], "param"),
(namespaces["html"], "plaintext"),
(namespaces["html"], "pre"),
(namespaces["html"], "script"),
(namespaces["html"], "section"),
(namespaces["html"], "select"),
(namespaces["html"], "style"),
(namespaces["html"], "table"),
(namespaces["html"], "tbody"),
(namespaces["html"], "td"),
(namespaces["html"], "textarea"),
(namespaces["html"], "tfoot"),
(namespaces["html"], "th"),
(namespaces["html"], "thead"),
(namespaces["html"], "title"),
(namespaces["html"], "tr"),
(namespaces["html"], "ul"),
(namespaces["html"], "wbr"),
(namespaces["html"], "xmp"),
(namespaces["svg"], "foreignObject")
))
htmlIntegrationPointElements = frozenset((
(namespaces["mathml"], "annotaion-xml"),
(namespaces["svg"], "foreignObject"),
(namespaces["svg"], "desc"),
(namespaces["svg"], "title")
))
mathmlTextIntegrationPointElements = frozenset((
(namespaces["mathml"], "mi"),
(namespaces["mathml"], "mo"),
(namespaces["mathml"], "mn"),
(namespaces["mathml"], "ms"),
(namespaces["mathml"], "mtext")
))
spaceCharacters = frozenset((
u"\t",
u"\n",
u"\u000C",
u" ",
u"\r"
))
tableInsertModeElements = frozenset((
"table",
"tbody",
"tfoot",
"thead",
"tr"
))
asciiLowercase = frozenset(string.ascii_lowercase)
asciiUppercase = frozenset(string.ascii_uppercase)
asciiLetters = frozenset(string.ascii_letters)
digits = frozenset(string.digits)
hexDigits = frozenset(string.hexdigits)
asciiUpper2Lower = dict([(ord(c),ord(c.lower()))
for c in string.ascii_uppercase])
# Heading elements need to be ordered
headingElements = (
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
)
voidElements = frozenset((
"base",
"command",
"event-source",
"link",
"meta",
"hr",
"br",
"img",
"embed",
"param",
"area",
"col",
"input",
"source",
"track"
))
cdataElements = frozenset(('title', 'textarea'))
rcdataElements = frozenset((
'style',
'script',
'xmp',
'iframe',
'noembed',
'noframes',
'noscript'
))
booleanAttributes = {
"": frozenset(("irrelevant",)),
"style": frozenset(("scoped",)),
"img": frozenset(("ismap",)),
"audio": frozenset(("autoplay","controls")),
"video": frozenset(("autoplay","controls")),
"script": frozenset(("defer", "async")),
"details": frozenset(("open",)),
"datagrid": frozenset(("multiple", "disabled")),
"command": frozenset(("hidden", "disabled", "checked", "default")),
"hr": frozenset(("noshade")),
"menu": frozenset(("autosubmit",)),
"fieldset": frozenset(("disabled", "readonly")),
"option": frozenset(("disabled", "readonly", "selected")),
"optgroup": frozenset(("disabled", "readonly")),
"button": frozenset(("disabled", "autofocus")),
"input": frozenset(("disabled", "readonly", "required", "autofocus", "checked", "ismap")),
"select": frozenset(("disabled", "readonly", "autofocus", "multiple")),
"output": frozenset(("disabled", "readonly")),
}
# entitiesWindows1252 has to be _ordered_ and needs to have an index. It
# therefore can't be a frozenset.
entitiesWindows1252 = (
8364, # 0x80 0x20AC EURO SIGN
65533, # 0x81 UNDEFINED
8218, # 0x82 0x201A SINGLE LOW-9 QUOTATION MARK
402, # 0x83 0x0192 LATIN SMALL LETTER F WITH HOOK
8222, # 0x84 0x201E DOUBLE LOW-9 QUOTATION MARK
8230, # 0x85 0x2026 HORIZONTAL ELLIPSIS
8224, # 0x86 0x2020 DAGGER
8225, # 0x87 0x2021 DOUBLE DAGGER
710, # 0x88 0x02C6 MODIFIER LETTER CIRCUMFLEX ACCENT
8240, # 0x89 0x2030 PER MILLE SIGN
352, # 0x8A 0x0160 LATIN CAPITAL LETTER S WITH CARON
8249, # 0x8B 0x2039 SINGLE LEFT-POINTING ANGLE QUOTATION MARK
338, # 0x8C 0x0152 LATIN CAPITAL LIGATURE OE
65533, # 0x8D UNDEFINED
381, # 0x8E 0x017D LATIN CAPITAL LETTER Z WITH CARON
65533, # 0x8F UNDEFINED
65533, # 0x90 UNDEFINED
8216, # 0x91 0x2018 LEFT SINGLE QUOTATION MARK
8217, # 0x92 0x2019 RIGHT SINGLE QUOTATION MARK
8220, # 0x93 0x201C LEFT DOUBLE QUOTATION MARK
8221, # 0x94 0x201D RIGHT DOUBLE QUOTATION MARK
8226, # 0x95 0x2022 BULLET
8211, # 0x96 0x2013 EN DASH
8212, # 0x97 0x2014 EM DASH
732, # 0x98 0x02DC SMALL TILDE
8482, # 0x99 0x2122 TRADE MARK SIGN
353, # 0x9A 0x0161 LATIN SMALL LETTER S WITH CARON
8250, # 0x9B 0x203A SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
339, # 0x9C 0x0153 LATIN SMALL LIGATURE OE
65533, # 0x9D UNDEFINED
382, # 0x9E 0x017E LATIN SMALL LETTER Z WITH CARON
376 # 0x9F 0x0178 LATIN CAPITAL LETTER Y WITH DIAERESIS
)
xmlEntities = frozenset(('lt;', 'gt;', 'amp;', 'apos;', 'quot;'))
entities = {
"AElig": u"\xc6",
"AElig;": u"\xc6",
"AMP": u"&",
"AMP;": u"&",
"Aacute": u"\xc1",
"Aacute;": u"\xc1",
"Abreve;": u"\u0102",
"Acirc": u"\xc2",
"Acirc;": u"\xc2",
"Acy;": u"\u0410",
"Afr;": u"\U0001d504",
"Agrave": u"\xc0",
"Agrave;": u"\xc0",
"Alpha;": u"\u0391",
"Amacr;": u"\u0100",
"And;": u"\u2a53",
"Aogon;": u"\u0104",
"Aopf;": u"\U0001d538",
"ApplyFunction;": u"\u2061",
"Aring": u"\xc5",
"Aring;": u"\xc5",
"Ascr;": u"\U0001d49c",
"Assign;": u"\u2254",
"Atilde": u"\xc3",
"Atilde;": u"\xc3",
"Auml": u"\xc4",
"Auml;": u"\xc4",
"Backslash;": u"\u2216",
"Barv;": u"\u2ae7",
"Barwed;": u"\u2306",
"Bcy;": u"\u0411",
"Because;": u"\u2235",
"Bernoullis;": u"\u212c",
"Beta;": u"\u0392",
"Bfr;": u"\U0001d505",
"Bopf;": u"\U0001d539",
"Breve;": u"\u02d8",
"Bscr;": u"\u212c",
"Bumpeq;": u"\u224e",
"CHcy;": u"\u0427",
"COPY": u"\xa9",
"COPY;": u"\xa9",
"Cacute;": u"\u0106",
"Cap;": u"\u22d2",
"CapitalDifferentialD;": u"\u2145",
"Cayleys;": u"\u212d",
"Ccaron;": u"\u010c",
"Ccedil": u"\xc7",
"Ccedil;": u"\xc7",
"Ccirc;": u"\u0108",
"Cconint;": u"\u2230",
"Cdot;": u"\u010a",
"Cedilla;": u"\xb8",
"CenterDot;": u"\xb7",
"Cfr;": u"\u212d",
"Chi;": u"\u03a7",
"CircleDot;": u"\u2299",
"CircleMinus;": u"\u2296",
"CirclePlus;": u"\u2295",
"CircleTimes;": u"\u2297",
"ClockwiseContourIntegral;": u"\u2232",
"CloseCurlyDoubleQuote;": u"\u201d",
"CloseCurlyQuote;": u"\u2019",
"Colon;": u"\u2237",
"Colone;": u"\u2a74",
"Congruent;": u"\u2261",
"Conint;": u"\u222f",
"ContourIntegral;": u"\u222e",
"Copf;": u"\u2102",
"Coproduct;": u"\u2210",
"CounterClockwiseContourIntegral;": u"\u2233",
"Cross;": u"\u2a2f",
"Cscr;": u"\U0001d49e",
"Cup;": u"\u22d3",
"CupCap;": u"\u224d",
"DD;": u"\u2145",
"DDotrahd;": u"\u2911",
"DJcy;": u"\u0402",
"DScy;": u"\u0405",
"DZcy;": u"\u040f",
"Dagger;": u"\u2021",
"Darr;": u"\u21a1",
"Dashv;": u"\u2ae4",
"Dcaron;": u"\u010e",
"Dcy;": u"\u0414",
"Del;": u"\u2207",
"Delta;": u"\u0394",
"Dfr;": u"\U0001d507",
"DiacriticalAcute;": u"\xb4",
"DiacriticalDot;": u"\u02d9",
"DiacriticalDoubleAcute;": u"\u02dd",
"DiacriticalGrave;": u"`",
"DiacriticalTilde;": u"\u02dc",
"Diamond;": u"\u22c4",
"DifferentialD;": u"\u2146",
"Dopf;": u"\U0001d53b",
"Dot;": u"\xa8",
"DotDot;": u"\u20dc",
"DotEqual;": u"\u2250",
"DoubleContourIntegral;": u"\u222f",
"DoubleDot;": u"\xa8",
"DoubleDownArrow;": u"\u21d3",
"DoubleLeftArrow;": u"\u21d0",
"DoubleLeftRightArrow;": u"\u21d4",
"DoubleLeftTee;": u"\u2ae4",
"DoubleLongLeftArrow;": u"\u27f8",
"DoubleLongLeftRightArrow;": u"\u27fa",
"DoubleLongRightArrow;": u"\u27f9",
"DoubleRightArrow;": u"\u21d2",
"DoubleRightTee;": u"\u22a8",
"DoubleUpArrow;": u"\u21d1",
"DoubleUpDownArrow;": u"\u21d5",
"DoubleVerticalBar;": u"\u2225",
"DownArrow;": u"\u2193",
"DownArrowBar;": u"\u2913",
"DownArrowUpArrow;": u"\u21f5",
"DownBreve;": u"\u0311",
"DownLeftRightVector;": u"\u2950",
"DownLeftTeeVector;": u"\u295e",
"DownLeftVector;": u"\u21bd",
"DownLeftVectorBar;": u"\u2956",
"DownRightTeeVector;": u"\u295f",
"DownRightVector;": u"\u21c1",
"DownRightVectorBar;": u"\u2957",
"DownTee;": u"\u22a4",
"DownTeeArrow;": u"\u21a7",
"Downarrow;": u"\u21d3",
"Dscr;": u"\U0001d49f",
"Dstrok;": u"\u0110",
"ENG;": u"\u014a",
"ETH": u"\xd0",
"ETH;": u"\xd0",
"Eacute": u"\xc9",
"Eacute;": u"\xc9",
"Ecaron;": u"\u011a",
"Ecirc": u"\xca",
"Ecirc;": u"\xca",
"Ecy;": u"\u042d",
"Edot;": u"\u0116",
"Efr;": u"\U0001d508",
"Egrave": u"\xc8",
"Egrave;": u"\xc8",
"Element;": u"\u2208",
"Emacr;": u"\u0112",
"EmptySmallSquare;": u"\u25fb",
"EmptyVerySmallSquare;": u"\u25ab",
"Eogon;": u"\u0118",
"Eopf;": u"\U0001d53c",
"Epsilon;": u"\u0395",
"Equal;": u"\u2a75",
"EqualTilde;": u"\u2242",
"Equilibrium;": u"\u21cc",
"Escr;": u"\u2130",
"Esim;": u"\u2a73",
"Eta;": u"\u0397",
"Euml": u"\xcb",
"Euml;": u"\xcb",
"Exists;": u"\u2203",
"ExponentialE;": u"\u2147",
"Fcy;": u"\u0424",
"Ffr;": u"\U0001d509",
"FilledSmallSquare;": u"\u25fc",
"FilledVerySmallSquare;": u"\u25aa",
"Fopf;": u"\U0001d53d",
"ForAll;": u"\u2200",
"Fouriertrf;": u"\u2131",
"Fscr;": u"\u2131",
"GJcy;": u"\u0403",
"GT": u">",
"GT;": u">",
"Gamma;": u"\u0393",
"Gammad;": u"\u03dc",
"Gbreve;": u"\u011e",
"Gcedil;": u"\u0122",
"Gcirc;": u"\u011c",
"Gcy;": u"\u0413",
"Gdot;": u"\u0120",
"Gfr;": u"\U0001d50a",
"Gg;": u"\u22d9",
"Gopf;": u"\U0001d53e",
"GreaterEqual;": u"\u2265",
"GreaterEqualLess;": u"\u22db",
"GreaterFullEqual;": u"\u2267",
"GreaterGreater;": u"\u2aa2",
"GreaterLess;": u"\u2277",
"GreaterSlantEqual;": u"\u2a7e",
"GreaterTilde;": u"\u2273",
"Gscr;": u"\U0001d4a2",
"Gt;": u"\u226b",
"HARDcy;": u"\u042a",
"Hacek;": u"\u02c7",
"Hat;": u"^",
"Hcirc;": u"\u0124",
"Hfr;": u"\u210c",
"HilbertSpace;": u"\u210b",
"Hopf;": u"\u210d",
"HorizontalLine;": u"\u2500",
"Hscr;": u"\u210b",
"Hstrok;": u"\u0126",
"HumpDownHump;": u"\u224e",
"HumpEqual;": u"\u224f",
"IEcy;": u"\u0415",
"IJlig;": u"\u0132",
"IOcy;": u"\u0401",
"Iacute": u"\xcd",
"Iacute;": u"\xcd",
"Icirc": u"\xce",
"Icirc;": u"\xce",
"Icy;": u"\u0418",
"Idot;": u"\u0130",
"Ifr;": u"\u2111",
"Igrave": u"\xcc",
"Igrave;": u"\xcc",
"Im;": u"\u2111",
"Imacr;": u"\u012a",
"ImaginaryI;": u"\u2148",
"Implies;": u"\u21d2",
"Int;": u"\u222c",
"Integral;": u"\u222b",
"Intersection;": u"\u22c2",
"InvisibleComma;": u"\u2063",
"InvisibleTimes;": u"\u2062",
"Iogon;": u"\u012e",
"Iopf;": u"\U0001d540",
"Iota;": u"\u0399",
"Iscr;": u"\u2110",
"Itilde;": u"\u0128",
"Iukcy;": u"\u0406",
"Iuml": u"\xcf",
"Iuml;": u"\xcf",
"Jcirc;": u"\u0134",
"Jcy;": u"\u0419",
"Jfr;": u"\U0001d50d",
"Jopf;": u"\U0001d541",
"Jscr;": u"\U0001d4a5",
"Jsercy;": u"\u0408",
"Jukcy;": u"\u0404",
"KHcy;": u"\u0425",
"KJcy;": u"\u040c",
"Kappa;": u"\u039a",
"Kcedil;": u"\u0136",
"Kcy;": u"\u041a",
"Kfr;": u"\U0001d50e",
"Kopf;": u"\U0001d542",
"Kscr;": u"\U0001d4a6",
"LJcy;": u"\u0409",
"LT": u"<",
"LT;": u"<",
"Lacute;": u"\u0139",
"Lambda;": u"\u039b",
"Lang;": u"\u27ea",
"Laplacetrf;": u"\u2112",
"Larr;": u"\u219e",
"Lcaron;": u"\u013d",
"Lcedil;": u"\u013b",
"Lcy;": u"\u041b",
"LeftAngleBracket;": u"\u27e8",
"LeftArrow;": u"\u2190",
"LeftArrowBar;": u"\u21e4",
"LeftArrowRightArrow;": u"\u21c6",
"LeftCeiling;": u"\u2308",
"LeftDoubleBracket;": u"\u27e6",
"LeftDownTeeVector;": u"\u2961",
"LeftDownVector;": u"\u21c3",
"LeftDownVectorBar;": u"\u2959",
"LeftFloor;": u"\u230a",
"LeftRightArrow;": u"\u2194",
"LeftRightVector;": u"\u294e",
"LeftTee;": u"\u22a3",
"LeftTeeArrow;": u"\u21a4",
"LeftTeeVector;": u"\u295a",
"LeftTriangle;": u"\u22b2",
"LeftTriangleBar;": u"\u29cf",
"LeftTriangleEqual;": u"\u22b4",
"LeftUpDownVector;": u"\u2951",
"LeftUpTeeVector;": u"\u2960",
"LeftUpVector;": u"\u21bf",
"LeftUpVectorBar;": u"\u2958",
"LeftVector;": u"\u21bc",
"LeftVectorBar;": u"\u2952",
"Leftarrow;": u"\u21d0",
"Leftrightarrow;": u"\u21d4",
"LessEqualGreater;": u"\u22da",
"LessFullEqual;": u"\u2266",
"LessGreater;": u"\u2276",
"LessLess;": u"\u2aa1",
"LessSlantEqual;": u"\u2a7d",
"LessTilde;": u"\u2272",
"Lfr;": u"\U0001d50f",
"Ll;": u"\u22d8",
"Lleftarrow;": u"\u21da",
"Lmidot;": u"\u013f",
"LongLeftArrow;": u"\u27f5",
"LongLeftRightArrow;": u"\u27f7",
"LongRightArrow;": u"\u27f6",
"Longleftarrow;": u"\u27f8",
"Longleftrightarrow;": u"\u27fa",
"Longrightarrow;": u"\u27f9",
"Lopf;": u"\U0001d543",
"LowerLeftArrow;": u"\u2199",
"LowerRightArrow;": u"\u2198",
"Lscr;": u"\u2112",
"Lsh;": u"\u21b0",
"Lstrok;": u"\u0141",
"Lt;": u"\u226a",
"Map;": u"\u2905",
"Mcy;": u"\u041c",
"MediumSpace;": u"\u205f",
"Mellintrf;": u"\u2133",
"Mfr;": u"\U0001d510",
"MinusPlus;": u"\u2213",
"Mopf;": u"\U0001d544",
"Mscr;": u"\u2133",
"Mu;": u"\u039c",
"NJcy;": u"\u040a",
"Nacute;": u"\u0143",
"Ncaron;": u"\u0147",
"Ncedil;": u"\u0145",
"Ncy;": u"\u041d",
"NegativeMediumSpace;": u"\u200b",
"NegativeThickSpace;": u"\u200b",
"NegativeThinSpace;": u"\u200b",
"NegativeVeryThinSpace;": u"\u200b",
"NestedGreaterGreater;": u"\u226b",
"NestedLessLess;": u"\u226a",
"NewLine;": u"\n",
"Nfr;": u"\U0001d511",
"NoBreak;": u"\u2060",
"NonBreakingSpace;": u"\xa0",
"Nopf;": u"\u2115",
"Not;": u"\u2aec",
"NotCongruent;": u"\u2262",
"NotCupCap;": u"\u226d",
"NotDoubleVerticalBar;": u"\u2226",
"NotElement;": u"\u2209",
"NotEqual;": u"\u2260",
"NotEqualTilde;": u"\u2242\u0338",
"NotExists;": u"\u2204",
"NotGreater;": u"\u226f",
"NotGreaterEqual;": u"\u2271",
"NotGreaterFullEqual;": u"\u2267\u0338",
"NotGreaterGreater;": u"\u226b\u0338",
"NotGreaterLess;": u"\u2279",
"NotGreaterSlantEqual;": u"\u2a7e\u0338",
"NotGreaterTilde;": u"\u2275",
"NotHumpDownHump;": u"\u224e\u0338",
"NotHumpEqual;": u"\u224f\u0338",
"NotLeftTriangle;": u"\u22ea",
"NotLeftTriangleBar;": u"\u29cf\u0338",
"NotLeftTriangleEqual;": u"\u22ec",
"NotLess;": u"\u226e",
"NotLessEqual;": u"\u2270",
"NotLessGreater;": u"\u2278",
"NotLessLess;": u"\u226a\u0338",
"NotLessSlantEqual;": u"\u2a7d\u0338",
"NotLessTilde;": u"\u2274",
"NotNestedGreaterGreater;": u"\u2aa2\u0338",
"NotNestedLessLess;": u"\u2aa1\u0338",
"NotPrecedes;": u"\u2280",
"NotPrecedesEqual;": u"\u2aaf\u0338",
"NotPrecedesSlantEqual;": u"\u22e0",
"NotReverseElement;": u"\u220c",
"NotRightTriangle;": u"\u22eb",
"NotRightTriangleBar;": u"\u29d0\u0338",
"NotRightTriangleEqual;": u"\u22ed",
"NotSquareSubset;": u"\u228f\u0338",
"NotSquareSubsetEqual;": u"\u22e2",
"NotSquareSuperset;": u"\u2290\u0338",
"NotSquareSupersetEqual;": u"\u22e3",
"NotSubset;": u"\u2282\u20d2",
"NotSubsetEqual;": u"\u2288",
"NotSucceeds;": u"\u2281",
"NotSucceedsEqual;": u"\u2ab0\u0338",
"NotSucceedsSlantEqual;": u"\u22e1",
"NotSucceedsTilde;": u"\u227f\u0338",
"NotSuperset;": u"\u2283\u20d2",
"NotSupersetEqual;": u"\u2289",
"NotTilde;": u"\u2241",
"NotTildeEqual;": u"\u2244",
"NotTildeFullEqual;": u"\u2247",
"NotTildeTilde;": u"\u2249",
"NotVerticalBar;": u"\u2224",
"Nscr;": u"\U0001d4a9",
"Ntilde": u"\xd1",
"Ntilde;": u"\xd1",
"Nu;": u"\u039d",
"OElig;": u"\u0152",
"Oacute": u"\xd3",
"Oacute;": u"\xd3",
"Ocirc": u"\xd4",
"Ocirc;": u"\xd4",
"Ocy;": u"\u041e",
"Odblac;": u"\u0150",
"Ofr;": u"\U0001d512",
"Ograve": u"\xd2",
"Ograve;": u"\xd2",
"Omacr;": u"\u014c",
"Omega;": u"\u03a9",
"Omicron;": u"\u039f",
"Oopf;": u"\U0001d546",
"OpenCurlyDoubleQuote;": u"\u201c",
"OpenCurlyQuote;": u"\u2018",
"Or;": u"\u2a54",
"Oscr;": u"\U0001d4aa",
"Oslash": u"\xd8",
"Oslash;": u"\xd8",
"Otilde": u"\xd5",
"Otilde;": u"\xd5",
"Otimes;": u"\u2a37",
"Ouml": u"\xd6",
"Ouml;": u"\xd6",
"OverBar;": u"\u203e",
"OverBrace;": u"\u23de",
"OverBracket;": u"\u23b4",
"OverParenthesis;": u"\u23dc",
"PartialD;": u"\u2202",
"Pcy;": u"\u041f",
"Pfr;": u"\U0001d513",
"Phi;": u"\u03a6",
"Pi;": u"\u03a0",
"PlusMinus;": u"\xb1",
"Poincareplane;": u"\u210c",
"Popf;": u"\u2119",
"Pr;": u"\u2abb",
"Precedes;": u"\u227a",
"PrecedesEqual;": u"\u2aaf",
"PrecedesSlantEqual;": u"\u227c",
"PrecedesTilde;": u"\u227e",
"Prime;": u"\u2033",
"Product;": u"\u220f",
"Proportion;": u"\u2237",
"Proportional;": u"\u221d",
"Pscr;": u"\U0001d4ab",
"Psi;": u"\u03a8",
"QUOT": u"\"",
"QUOT;": u"\"",
"Qfr;": u"\U0001d514",
"Qopf;": u"\u211a",
"Qscr;": u"\U0001d4ac",
"RBarr;": u"\u2910",
"REG": u"\xae",
"REG;": u"\xae",
"Racute;": u"\u0154",
"Rang;": u"\u27eb",
"Rarr;": u"\u21a0",
"Rarrtl;": u"\u2916",
"Rcaron;": u"\u0158",
"Rcedil;": u"\u0156",
"Rcy;": u"\u0420",
"Re;": u"\u211c",
"ReverseElement;": u"\u220b",
"ReverseEquilibrium;": u"\u21cb",
"ReverseUpEquilibrium;": u"\u296f",
"Rfr;": u"\u211c",
"Rho;": u"\u03a1",
"RightAngleBracket;": u"\u27e9",
"RightArrow;": u"\u2192",
"RightArrowBar;": u"\u21e5",
"RightArrowLeftArrow;": u"\u21c4",
"RightCeiling;": u"\u2309",
"RightDoubleBracket;": u"\u27e7",
"RightDownTeeVector;": u"\u295d",
"RightDownVector;": u"\u21c2",
"RightDownVectorBar;": u"\u2955",
"RightFloor;": u"\u230b",
"RightTee;": u"\u22a2",
"RightTeeArrow;": u"\u21a6",
"RightTeeVector;": u"\u295b",
"RightTriangle;": u"\u22b3",
"RightTriangleBar;": u"\u29d0",
"RightTriangleEqual;": u"\u22b5",
"RightUpDownVector;": u"\u294f",
"RightUpTeeVector;": u"\u295c",
"RightUpVector;": u"\u21be",
"RightUpVectorBar;": u"\u2954",
"RightVector;": u"\u21c0",
"RightVectorBar;": u"\u2953",
"Rightarrow;": u"\u21d2",
"Ropf;": u"\u211d",
"RoundImplies;": u"\u2970",
"Rrightarrow;": u"\u21db",
"Rscr;": u"\u211b",
"Rsh;": u"\u21b1",
"RuleDelayed;": u"\u29f4",
"SHCHcy;": u"\u0429",
"SHcy;": u"\u0428",
"SOFTcy;": u"\u042c",
"Sacute;": u"\u015a",
"Sc;": u"\u2abc",
"Scaron;": u"\u0160",
"Scedil;": u"\u015e",
"Scirc;": u"\u015c",
"Scy;": u"\u0421",
"Sfr;": u"\U0001d516",
"ShortDownArrow;": u"\u2193",
"ShortLeftArrow;": u"\u2190",
"ShortRightArrow;": u"\u2192",
"ShortUpArrow;": u"\u2191",
"Sigma;": u"\u03a3",
"SmallCircle;": u"\u2218",
"Sopf;": u"\U0001d54a",
"Sqrt;": u"\u221a",
"Square;": u"\u25a1",
"SquareIntersection;": u"\u2293",
"SquareSubset;": u"\u228f",
"SquareSubsetEqual;": u"\u2291",
"SquareSuperset;": u"\u2290",
"SquareSupersetEqual;": u"\u2292",
"SquareUnion;": u"\u2294",
"Sscr;": u"\U0001d4ae",
"Star;": u"\u22c6",
"Sub;": u"\u22d0",
"Subset;": u"\u22d0",
"SubsetEqual;": u"\u2286",
"Succeeds;": u"\u227b",
"SucceedsEqual;": u"\u2ab0",
"SucceedsSlantEqual;": u"\u227d",
"SucceedsTilde;": u"\u227f",
"SuchThat;": u"\u220b",
"Sum;": u"\u2211",
"Sup;": u"\u22d1",
"Superset;": u"\u2283",
"SupersetEqual;": u"\u2287",
"Supset;": u"\u22d1",
"THORN": u"\xde",
"THORN;": u"\xde",
"TRADE;": u"\u2122",
"TSHcy;": u"\u040b",
"TScy;": u"\u0426",
"Tab;": u"\t",
"Tau;": u"\u03a4",
"Tcaron;": u"\u0164",
"Tcedil;": u"\u0162",
"Tcy;": u"\u0422",
"Tfr;": u"\U0001d517",
"Therefore;": u"\u2234",
"Theta;": u"\u0398",
"ThickSpace;": u"\u205f\u200a",
"ThinSpace;": u"\u2009",
"Tilde;": u"\u223c",
"TildeEqual;": u"\u2243",
"TildeFullEqual;": u"\u2245",
"TildeTilde;": u"\u2248",
"Topf;": u"\U0001d54b",
"TripleDot;": u"\u20db",
"Tscr;": u"\U0001d4af",
"Tstrok;": u"\u0166",
"Uacute": u"\xda",
"Uacute;": u"\xda",
"Uarr;": u"\u219f",
"Uarrocir;": u"\u2949",
"Ubrcy;": u"\u040e",
"Ubreve;": u"\u016c",
"Ucirc": u"\xdb",
"Ucirc;": u"\xdb",
"Ucy;": u"\u0423",
"Udblac;": u"\u0170",
"Ufr;": u"\U0001d518",
"Ugrave": u"\xd9",
"Ugrave;": u"\xd9",
"Umacr;": u"\u016a",
"UnderBar;": u"_",
"UnderBrace;": u"\u23df",
"UnderBracket;": u"\u23b5",
"UnderParenthesis;": u"\u23dd",
"Union;": u"\u22c3",
"UnionPlus;": u"\u228e",
"Uogon;": u"\u0172",
"Uopf;": u"\U0001d54c",
"UpArrow;": u"\u2191",
"UpArrowBar;": u"\u2912",
"UpArrowDownArrow;": u"\u21c5",
"UpDownArrow;": u"\u2195",
"UpEquilibrium;": u"\u296e",
"UpTee;": u"\u22a5",
"UpTeeArrow;": u"\u21a5",
"Uparrow;": u"\u21d1",
"Updownarrow;": u"\u21d5",
"UpperLeftArrow;": u"\u2196",
"UpperRightArrow;": u"\u2197",
"Upsi;": u"\u03d2",
"Upsilon;": u"\u03a5",
"Uring;": u"\u016e",
"Uscr;": u"\U0001d4b0",
"Utilde;": u"\u0168",
"Uuml": u"\xdc",
"Uuml;": u"\xdc",
"VDash;": u"\u22ab",
"Vbar;": u"\u2aeb",
"Vcy;": u"\u0412",
"Vdash;": u"\u22a9",
"Vdashl;": u"\u2ae6",
"Vee;": u"\u22c1",
"Verbar;": u"\u2016",
"Vert;": u"\u2016",
"VerticalBar;": u"\u2223",
"VerticalLine;": u"|",
"VerticalSeparator;": u"\u2758",
"VerticalTilde;": u"\u2240",
"VeryThinSpace;": u"\u200a",
"Vfr;": u"\U0001d519",
"Vopf;": u"\U0001d54d",
"Vscr;": u"\U0001d4b1",
"Vvdash;": u"\u22aa",
"Wcirc;": u"\u0174",
"Wedge;": u"\u22c0",
"Wfr;": u"\U0001d51a",
"Wopf;": u"\U0001d54e",
"Wscr;": u"\U0001d4b2",
"Xfr;": u"\U0001d51b",
"Xi;": u"\u039e",
"Xopf;": u"\U0001d54f",
"Xscr;": u"\U0001d4b3",
"YAcy;": u"\u042f",
"YIcy;": u"\u0407",
"YUcy;": u"\u042e",
"Yacute": u"\xdd",
"Yacute;": u"\xdd",
"Ycirc;": u"\u0176",
"Ycy;": u"\u042b",
"Yfr;": u"\U0001d51c",
"Yopf;": u"\U0001d550",
"Yscr;": u"\U0001d4b4",
"Yuml;": u"\u0178",
"ZHcy;": u"\u0416",
"Zacute;": u"\u0179",
"Zcaron;": u"\u017d",
"Zcy;": u"\u0417",
"Zdot;": u"\u017b",
"ZeroWidthSpace;": u"\u200b",
"Zeta;": u"\u0396",
"Zfr;": u"\u2128",
"Zopf;": u"\u2124",
"Zscr;": u"\U0001d4b5",
"aacute": u"\xe1",
"aacute;": u"\xe1",
"abreve;": u"\u0103",
"ac;": u"\u223e",
"acE;": u"\u223e\u0333",
"acd;": u"\u223f",
"acirc": u"\xe2",
"acirc;": u"\xe2",
"acute": u"\xb4",
"acute;": u"\xb4",
"acy;": u"\u0430",
"aelig": u"\xe6",
"aelig;": u"\xe6",
"af;": u"\u2061",
"afr;": u"\U0001d51e",
"agrave": u"\xe0",
"agrave;": u"\xe0",
"alefsym;": u"\u2135",
"aleph;": u"\u2135",
"alpha;": u"\u03b1",
"amacr;": u"\u0101",
"amalg;": u"\u2a3f",
"amp": u"&",
"amp;": u"&",
"and;": u"\u2227",
"andand;": u"\u2a55",
"andd;": u"\u2a5c",
"andslope;": u"\u2a58",
"andv;": u"\u2a5a",
"ang;": u"\u2220",
"ange;": u"\u29a4",
"angle;": u"\u2220",
"angmsd;": u"\u2221",
"angmsdaa;": u"\u29a8",
"angmsdab;": u"\u29a9",
"angmsdac;": u"\u29aa",
"angmsdad;": u"\u29ab",
"angmsdae;": u"\u29ac",
"angmsdaf;": u"\u29ad",
"angmsdag;": u"\u29ae",
"angmsdah;": u"\u29af",
"angrt;": u"\u221f",
"angrtvb;": u"\u22be",
"angrtvbd;": u"\u299d",
"angsph;": u"\u2222",
"angst;": u"\xc5",
"angzarr;": u"\u237c",
"aogon;": u"\u0105",
"aopf;": u"\U0001d552",
"ap;": u"\u2248",
"apE;": u"\u2a70",
"apacir;": u"\u2a6f",
"ape;": u"\u224a",
"apid;": u"\u224b",
"apos;": u"'",
"approx;": u"\u2248",
"approxeq;": u"\u224a",
"aring": u"\xe5",
"aring;": u"\xe5",
"ascr;": u"\U0001d4b6",
"ast;": u"*",
"asymp;": u"\u2248",
"asympeq;": u"\u224d",
"atilde": u"\xe3",
"atilde;": u"\xe3",
"auml": u"\xe4",
"auml;": u"\xe4",
"awconint;": u"\u2233",
"awint;": u"\u2a11",
"bNot;": u"\u2aed",
"backcong;": u"\u224c",
"backepsilon;": u"\u03f6",
"backprime;": u"\u2035",
"backsim;": u"\u223d",
"backsimeq;": u"\u22cd",
"barvee;": u"\u22bd",
"barwed;": u"\u2305",
"barwedge;": u"\u2305",
"bbrk;": u"\u23b5",
"bbrktbrk;": u"\u23b6",
"bcong;": u"\u224c",
"bcy;": u"\u0431",
"bdquo;": u"\u201e",
"becaus;": u"\u2235",
"because;": u"\u2235",
"bemptyv;": u"\u29b0",
"bepsi;": u"\u03f6",
"bernou;": u"\u212c",
"beta;": u"\u03b2",
"beth;": u"\u2136",
"between;": u"\u226c",
"bfr;": u"\U0001d51f",
"bigcap;": u"\u22c2",
"bigcirc;": u"\u25ef",
"bigcup;": u"\u22c3",
"bigodot;": u"\u2a00",
"bigoplus;": u"\u2a01",
"bigotimes;": u"\u2a02",
"bigsqcup;": u"\u2a06",
"bigstar;": u"\u2605",
"bigtriangledown;": u"\u25bd",
"bigtriangleup;": u"\u25b3",
"biguplus;": u"\u2a04",
"bigvee;": u"\u22c1",
"bigwedge;": u"\u22c0",
"bkarow;": u"\u290d",
"blacklozenge;": u"\u29eb",
"blacksquare;": u"\u25aa",
"blacktriangle;": u"\u25b4",
"blacktriangledown;": u"\u25be",
"blacktriangleleft;": u"\u25c2",
"blacktriangleright;": u"\u25b8",
"blank;": u"\u2423",
"blk12;": u"\u2592",
"blk14;": u"\u2591",
"blk34;": u"\u2593",
"block;": u"\u2588",
"bne;": u"=\u20e5",
"bnequiv;": u"\u2261\u20e5",
"bnot;": u"\u2310",
"bopf;": u"\U0001d553",
"bot;": u"\u22a5",
"bottom;": u"\u22a5",
"bowtie;": u"\u22c8",
"boxDL;": u"\u2557",
"boxDR;": u"\u2554",
"boxDl;": u"\u2556",
"boxDr;": u"\u2553",
"boxH;": u"\u2550",
"boxHD;": u"\u2566",
"boxHU;": u"\u2569",
"boxHd;": u"\u2564",
"boxHu;": u"\u2567",
"boxUL;": u"\u255d",
"boxUR;": u"\u255a",
"boxUl;": u"\u255c",
"boxUr;": u"\u2559",
"boxV;": u"\u2551",
"boxVH;": u"\u256c",
"boxVL;": u"\u2563",
"boxVR;": u"\u2560",
"boxVh;": u"\u256b",
"boxVl;": u"\u2562",
"boxVr;": u"\u255f",
"boxbox;": u"\u29c9",
"boxdL;": u"\u2555",
"boxdR;": u"\u2552",
"boxdl;": u"\u2510",
"boxdr;": u"\u250c",
"boxh;": u"\u2500",
"boxhD;": u"\u2565",
"boxhU;": u"\u2568",
"boxhd;": u"\u252c",
"boxhu;": u"\u2534",
"boxminus;": u"\u229f",
"boxplus;": u"\u229e",
"boxtimes;": u"\u22a0",
"boxuL;": u"\u255b",
"boxuR;": u"\u2558",
"boxul;": u"\u2518",
"boxur;": u"\u2514",
"boxv;": u"\u2502",
"boxvH;": u"\u256a",
"boxvL;": u"\u2561",
"boxvR;": u"\u255e",
"boxvh;": u"\u253c",
"boxvl;": u"\u2524",
"boxvr;": u"\u251c",
"bprime;": u"\u2035",
"breve;": u"\u02d8",
"brvbar": u"\xa6",
"brvbar;": u"\xa6",
"bscr;": u"\U0001d4b7",
"bsemi;": u"\u204f",
"bsim;": u"\u223d",
"bsime;": u"\u22cd",
"bsol;": u"\\",
"bsolb;": u"\u29c5",
"bsolhsub;": u"\u27c8",
"bull;": u"\u2022",
"bullet;": u"\u2022",
"bump;": u"\u224e",
"bumpE;": u"\u2aae",
"bumpe;": u"\u224f",
"bumpeq;": u"\u224f",
"cacute;": u"\u0107",
"cap;": u"\u2229",
"capand;": u"\u2a44",
"capbrcup;": u"\u2a49",
"capcap;": u"\u2a4b",
"capcup;": u"\u2a47",
"capdot;": u"\u2a40",
"caps;": u"\u2229\ufe00",
"caret;": u"\u2041",
"caron;": u"\u02c7",
"ccaps;": u"\u2a4d",
"ccaron;": u"\u010d",
"ccedil": u"\xe7",
"ccedil;": u"\xe7",
"ccirc;": u"\u0109",
"ccups;": u"\u2a4c",
"ccupssm;": u"\u2a50",
"cdot;": u"\u010b",
"cedil": u"\xb8",
"cedil;": u"\xb8",
"cemptyv;": u"\u29b2",
"cent": u"\xa2",
"cent;": u"\xa2",
"centerdot;": u"\xb7",
"cfr;": u"\U0001d520",
"chcy;": u"\u0447",
"check;": u"\u2713",
"checkmark;": u"\u2713",
"chi;": u"\u03c7",
"cir;": u"\u25cb",
"cirE;": u"\u29c3",
"circ;": u"\u02c6",
"circeq;": u"\u2257",
"circlearrowleft;": u"\u21ba",
"circlearrowright;": u"\u21bb",
"circledR;": u"\xae",
"circledS;": u"\u24c8",
"circledast;": u"\u229b",
"circledcirc;": u"\u229a",
"circleddash;": u"\u229d",
"cire;": u"\u2257",
"cirfnint;": u"\u2a10",
"cirmid;": u"\u2aef",
"cirscir;": u"\u29c2",
"clubs;": u"\u2663",
"clubsuit;": u"\u2663",
"colon;": u":",
"colone;": u"\u2254",
"coloneq;": u"\u2254",
"comma;": u",",
"commat;": u"@",
"comp;": u"\u2201",
"compfn;": u"\u2218",
"complement;": u"\u2201",
"complexes;": u"\u2102",
"cong;": u"\u2245",
"congdot;": u"\u2a6d",
"conint;": u"\u222e",
"copf;": u"\U0001d554",
"coprod;": u"\u2210",
"copy": u"\xa9",
"copy;": u"\xa9",
"copysr;": u"\u2117",
"crarr;": u"\u21b5",
"cross;": u"\u2717",
"cscr;": u"\U0001d4b8",
"csub;": u"\u2acf",
"csube;": u"\u2ad1",
"csup;": u"\u2ad0",
"csupe;": u"\u2ad2",
"ctdot;": u"\u22ef",
"cudarrl;": u"\u2938",
"cudarrr;": u"\u2935",
"cuepr;": u"\u22de",
"cuesc;": u"\u22df",
"cularr;": u"\u21b6",
"cularrp;": u"\u293d",
"cup;": u"\u222a",
"cupbrcap;": u"\u2a48",
"cupcap;": u"\u2a46",
"cupcup;": u"\u2a4a",
"cupdot;": u"\u228d",
"cupor;": u"\u2a45",
"cups;": u"\u222a\ufe00",
"curarr;": u"\u21b7",
"curarrm;": u"\u293c",
"curlyeqprec;": u"\u22de",
"curlyeqsucc;": u"\u22df",
"curlyvee;": u"\u22ce",
"curlywedge;": u"\u22cf",
"curren": u"\xa4",
"curren;": u"\xa4",
"curvearrowleft;": u"\u21b6",
"curvearrowright;": u"\u21b7",
"cuvee;": u"\u22ce",
"cuwed;": u"\u22cf",
"cwconint;": u"\u2232",
"cwint;": u"\u2231",
"cylcty;": u"\u232d",
"dArr;": u"\u21d3",
"dHar;": u"\u2965",
"dagger;": u"\u2020",
"daleth;": u"\u2138",
"darr;": u"\u2193",
"dash;": u"\u2010",
"dashv;": u"\u22a3",
"dbkarow;": u"\u290f",
"dblac;": u"\u02dd",
"dcaron;": u"\u010f",
"dcy;": u"\u0434",
"dd;": u"\u2146",
"ddagger;": u"\u2021",
"ddarr;": u"\u21ca",
"ddotseq;": u"\u2a77",
"deg": u"\xb0",
"deg;": u"\xb0",
"delta;": u"\u03b4",
"demptyv;": u"\u29b1",
"dfisht;": u"\u297f",
"dfr;": u"\U0001d521",
"dharl;": u"\u21c3",
"dharr;": u"\u21c2",
"diam;": u"\u22c4",
"diamond;": u"\u22c4",
"diamondsuit;": u"\u2666",
"diams;": u"\u2666",
"die;": u"\xa8",
"digamma;": u"\u03dd",
"disin;": u"\u22f2",
"div;": u"\xf7",
"divide": u"\xf7",
"divide;": u"\xf7",
"divideontimes;": u"\u22c7",
"divonx;": u"\u22c7",
"djcy;": u"\u0452",
"dlcorn;": u"\u231e",
"dlcrop;": u"\u230d",
"dollar;": u"$",
"dopf;": u"\U0001d555",
"dot;": u"\u02d9",
"doteq;": u"\u2250",
"doteqdot;": u"\u2251",
"dotminus;": u"\u2238",
"dotplus;": u"\u2214",
"dotsquare;": u"\u22a1",
"doublebarwedge;": u"\u2306",
"downarrow;": u"\u2193",
"downdownarrows;": u"\u21ca",
"downharpoonleft;": u"\u21c3",
"downharpoonright;": u"\u21c2",
"drbkarow;": u"\u2910",
"drcorn;": u"\u231f",
"drcrop;": u"\u230c",
"dscr;": u"\U0001d4b9",
"dscy;": u"\u0455",
"dsol;": u"\u29f6",
"dstrok;": u"\u0111",
"dtdot;": u"\u22f1",
"dtri;": u"\u25bf",
"dtrif;": u"\u25be",
"duarr;": u"\u21f5",
"duhar;": u"\u296f",
"dwangle;": u"\u29a6",
"dzcy;": u"\u045f",
"dzigrarr;": u"\u27ff",
"eDDot;": u"\u2a77",
"eDot;": u"\u2251",
"eacute": u"\xe9",
"eacute;": u"\xe9",
"easter;": u"\u2a6e",
"ecaron;": u"\u011b",
"ecir;": u"\u2256",
"ecirc": u"\xea",
"ecirc;": u"\xea",
"ecolon;": u"\u2255",
"ecy;": u"\u044d",
"edot;": u"\u0117",
"ee;": u"\u2147",
"efDot;": u"\u2252",
"efr;": u"\U0001d522",
"eg;": u"\u2a9a",
"egrave": u"\xe8",
"egrave;": u"\xe8",
"egs;": u"\u2a96",
"egsdot;": u"\u2a98",
"el;": u"\u2a99",
"elinters;": u"\u23e7",
"ell;": u"\u2113",
"els;": u"\u2a95",
"elsdot;": u"\u2a97",
"emacr;": u"\u0113",
"empty;": u"\u2205",
"emptyset;": u"\u2205",
"emptyv;": u"\u2205",
"emsp13;": u"\u2004",
"emsp14;": u"\u2005",
"emsp;": u"\u2003",
"eng;": u"\u014b",
"ensp;": u"\u2002",
"eogon;": u"\u0119",
"eopf;": u"\U0001d556",
"epar;": u"\u22d5",
"eparsl;": u"\u29e3",
"eplus;": u"\u2a71",
"epsi;": u"\u03b5",
"epsilon;": u"\u03b5",
"epsiv;": u"\u03f5",
"eqcirc;": u"\u2256",
"eqcolon;": u"\u2255",
"eqsim;": u"\u2242",
"eqslantgtr;": u"\u2a96",
"eqslantless;": u"\u2a95",
"equals;": u"=",
"equest;": u"\u225f",
"equiv;": u"\u2261",
"equivDD;": u"\u2a78",
"eqvparsl;": u"\u29e5",
"erDot;": u"\u2253",
"erarr;": u"\u2971",
"escr;": u"\u212f",
"esdot;": u"\u2250",
"esim;": u"\u2242",
"eta;": u"\u03b7",
"eth": u"\xf0",
"eth;": u"\xf0",
"euml": u"\xeb",
"euml;": u"\xeb",
"euro;": u"\u20ac",
"excl;": u"!",
"exist;": u"\u2203",
"expectation;": u"\u2130",
"exponentiale;": u"\u2147",
"fallingdotseq;": u"\u2252",
"fcy;": u"\u0444",
"female;": u"\u2640",
"ffilig;": u"\ufb03",
"fflig;": u"\ufb00",
"ffllig;": u"\ufb04",
"ffr;": u"\U0001d523",
"filig;": u"\ufb01",
"fjlig;": u"fj",
"flat;": u"\u266d",
"fllig;": u"\ufb02",
"fltns;": u"\u25b1",
"fnof;": u"\u0192",
"fopf;": u"\U0001d557",
"forall;": u"\u2200",
"fork;": u"\u22d4",
"forkv;": u"\u2ad9",
"fpartint;": u"\u2a0d",
"frac12": u"\xbd",
"frac12;": u"\xbd",
"frac13;": u"\u2153",
"frac14": u"\xbc",
"frac14;": u"\xbc",
"frac15;": u"\u2155",
"frac16;": u"\u2159",
"frac18;": u"\u215b",
"frac23;": u"\u2154",
"frac25;": u"\u2156",
"frac34": u"\xbe",
"frac34;": u"\xbe",
"frac35;": u"\u2157",
"frac38;": u"\u215c",
"frac45;": u"\u2158",
"frac56;": u"\u215a",
"frac58;": u"\u215d",
"frac78;": u"\u215e",
"frasl;": u"\u2044",
"frown;": u"\u2322",
"fscr;": u"\U0001d4bb",
"gE;": u"\u2267",
"gEl;": u"\u2a8c",
"gacute;": u"\u01f5",
"gamma;": u"\u03b3",
"gammad;": u"\u03dd",
"gap;": u"\u2a86",
"gbreve;": u"\u011f",
"gcirc;": u"\u011d",
"gcy;": u"\u0433",
"gdot;": u"\u0121",
"ge;": u"\u2265",
"gel;": u"\u22db",
"geq;": u"\u2265",
"geqq;": u"\u2267",
"geqslant;": u"\u2a7e",
"ges;": u"\u2a7e",
"gescc;": u"\u2aa9",
"gesdot;": u"\u2a80",
"gesdoto;": u"\u2a82",
"gesdotol;": u"\u2a84",
"gesl;": u"\u22db\ufe00",
"gesles;": u"\u2a94",
"gfr;": u"\U0001d524",
"gg;": u"\u226b",
"ggg;": u"\u22d9",
"gimel;": u"\u2137",
"gjcy;": u"\u0453",
"gl;": u"\u2277",
"glE;": u"\u2a92",
"gla;": u"\u2aa5",
"glj;": u"\u2aa4",
"gnE;": u"\u2269",
"gnap;": u"\u2a8a",
"gnapprox;": u"\u2a8a",
"gne;": u"\u2a88",
"gneq;": u"\u2a88",
"gneqq;": u"\u2269",
"gnsim;": u"\u22e7",
"gopf;": u"\U0001d558",
"grave;": u"`",
"gscr;": u"\u210a",
"gsim;": u"\u2273",
"gsime;": u"\u2a8e",
"gsiml;": u"\u2a90",
"gt": u">",
"gt;": u">",
"gtcc;": u"\u2aa7",
"gtcir;": u"\u2a7a",
"gtdot;": u"\u22d7",
"gtlPar;": u"\u2995",
"gtquest;": u"\u2a7c",
"gtrapprox;": u"\u2a86",
"gtrarr;": u"\u2978",
"gtrdot;": u"\u22d7",
"gtreqless;": u"\u22db",
"gtreqqless;": u"\u2a8c",
"gtrless;": u"\u2277",
"gtrsim;": u"\u2273",
"gvertneqq;": u"\u2269\ufe00",
"gvnE;": u"\u2269\ufe00",
"hArr;": u"\u21d4",
"hairsp;": u"\u200a",
"half;": u"\xbd",
"hamilt;": u"\u210b",
"hardcy;": u"\u044a",
"harr;": u"\u2194",
"harrcir;": u"\u2948",
"harrw;": u"\u21ad",
"hbar;": u"\u210f",
"hcirc;": u"\u0125",
"hearts;": u"\u2665",
"heartsuit;": u"\u2665",
"hellip;": u"\u2026",
"hercon;": u"\u22b9",
"hfr;": u"\U0001d525",
"hksearow;": u"\u2925",
"hkswarow;": u"\u2926",
"hoarr;": u"\u21ff",
"homtht;": u"\u223b",
"hookleftarrow;": u"\u21a9",
"hookrightarrow;": u"\u21aa",
"hopf;": u"\U0001d559",
"horbar;": u"\u2015",
"hscr;": u"\U0001d4bd",
"hslash;": u"\u210f",
"hstrok;": u"\u0127",
"hybull;": u"\u2043",
"hyphen;": u"\u2010",
"iacute": u"\xed",
"iacute;": u"\xed",
"ic;": u"\u2063",
"icirc": u"\xee",
"icirc;": u"\xee",
"icy;": u"\u0438",
"iecy;": u"\u0435",
"iexcl": u"\xa1",
"iexcl;": u"\xa1",
"iff;": u"\u21d4",
"ifr;": u"\U0001d526",
"igrave": u"\xec",
"igrave;": u"\xec",
"ii;": u"\u2148",
"iiiint;": u"\u2a0c",
"iiint;": u"\u222d",
"iinfin;": u"\u29dc",
"iiota;": u"\u2129",
"ijlig;": u"\u0133",
"imacr;": u"\u012b",
"image;": u"\u2111",
"imagline;": u"\u2110",
"imagpart;": u"\u2111",
"imath;": u"\u0131",
"imof;": u"\u22b7",
"imped;": u"\u01b5",
"in;": u"\u2208",
"incare;": u"\u2105",
"infin;": u"\u221e",
"infintie;": u"\u29dd",
"inodot;": u"\u0131",
"int;": u"\u222b",
"intcal;": u"\u22ba",
"integers;": u"\u2124",
"intercal;": u"\u22ba",
"intlarhk;": u"\u2a17",
"intprod;": u"\u2a3c",
"iocy;": u"\u0451",
"iogon;": u"\u012f",
"iopf;": u"\U0001d55a",
"iota;": u"\u03b9",
"iprod;": u"\u2a3c",
"iquest": u"\xbf",
"iquest;": u"\xbf",
"iscr;": u"\U0001d4be",
"isin;": u"\u2208",
"isinE;": u"\u22f9",
"isindot;": u"\u22f5",
"isins;": u"\u22f4",
"isinsv;": u"\u22f3",
"isinv;": u"\u2208",
"it;": u"\u2062",
"itilde;": u"\u0129",
"iukcy;": u"\u0456",
"iuml": u"\xef",
"iuml;": u"\xef",
"jcirc;": u"\u0135",
"jcy;": u"\u0439",
"jfr;": u"\U0001d527",
"jmath;": u"\u0237",
"jopf;": u"\U0001d55b",
"jscr;": u"\U0001d4bf",
"jsercy;": u"\u0458",
"jukcy;": u"\u0454",
"kappa;": u"\u03ba",
"kappav;": u"\u03f0",
"kcedil;": u"\u0137",
"kcy;": u"\u043a",
"kfr;": u"\U0001d528",
"kgreen;": u"\u0138",
"khcy;": u"\u0445",
"kjcy;": u"\u045c",
"kopf;": u"\U0001d55c",
"kscr;": u"\U0001d4c0",
"lAarr;": u"\u21da",
"lArr;": u"\u21d0",
"lAtail;": u"\u291b",
"lBarr;": u"\u290e",
"lE;": u"\u2266",
"lEg;": u"\u2a8b",
"lHar;": u"\u2962",
"lacute;": u"\u013a",
"laemptyv;": u"\u29b4",
"lagran;": u"\u2112",
"lambda;": u"\u03bb",
"lang;": u"\u27e8",
"langd;": u"\u2991",
"langle;": u"\u27e8",
"lap;": u"\u2a85",
"laquo": u"\xab",
"laquo;": u"\xab",
"larr;": u"\u2190",
"larrb;": u"\u21e4",
"larrbfs;": u"\u291f",
"larrfs;": u"\u291d",
"larrhk;": u"\u21a9",
"larrlp;": u"\u21ab",
"larrpl;": u"\u2939",
"larrsim;": u"\u2973",
"larrtl;": u"\u21a2",
"lat;": u"\u2aab",
"latail;": u"\u2919",
"late;": u"\u2aad",
"lates;": u"\u2aad\ufe00",
"lbarr;": u"\u290c",
"lbbrk;": u"\u2772",
"lbrace;": u"{",
"lbrack;": u"[",
"lbrke;": u"\u298b",
"lbrksld;": u"\u298f",
"lbrkslu;": u"\u298d",
"lcaron;": u"\u013e",
"lcedil;": u"\u013c",
"lceil;": u"\u2308",
"lcub;": u"{",
"lcy;": u"\u043b",
"ldca;": u"\u2936",
"ldquo;": u"\u201c",
"ldquor;": u"\u201e",
"ldrdhar;": u"\u2967",
"ldrushar;": u"\u294b",
"ldsh;": u"\u21b2",
"le;": u"\u2264",
"leftarrow;": u"\u2190",
"leftarrowtail;": u"\u21a2",
"leftharpoondown;": u"\u21bd",
"leftharpoonup;": u"\u21bc",
"leftleftarrows;": u"\u21c7",
"leftrightarrow;": u"\u2194",
"leftrightarrows;": u"\u21c6",
"leftrightharpoons;": u"\u21cb",
"leftrightsquigarrow;": u"\u21ad",
"leftthreetimes;": u"\u22cb",
"leg;": u"\u22da",
"leq;": u"\u2264",
"leqq;": u"\u2266",
"leqslant;": u"\u2a7d",
"les;": u"\u2a7d",
"lescc;": u"\u2aa8",
"lesdot;": u"\u2a7f",
"lesdoto;": u"\u2a81",
"lesdotor;": u"\u2a83",
"lesg;": u"\u22da\ufe00",
"lesges;": u"\u2a93",
"lessapprox;": u"\u2a85",
"lessdot;": u"\u22d6",
"lesseqgtr;": u"\u22da",
"lesseqqgtr;": u"\u2a8b",
"lessgtr;": u"\u2276",
"lesssim;": u"\u2272",
"lfisht;": u"\u297c",
"lfloor;": u"\u230a",
"lfr;": u"\U0001d529",
"lg;": u"\u2276",
"lgE;": u"\u2a91",
"lhard;": u"\u21bd",
"lharu;": u"\u21bc",
"lharul;": u"\u296a",
"lhblk;": u"\u2584",
"ljcy;": u"\u0459",
"ll;": u"\u226a",
"llarr;": u"\u21c7",
"llcorner;": u"\u231e",
"llhard;": u"\u296b",
"lltri;": u"\u25fa",
"lmidot;": u"\u0140",
"lmoust;": u"\u23b0",
"lmoustache;": u"\u23b0",
"lnE;": u"\u2268",
"lnap;": u"\u2a89",
"lnapprox;": u"\u2a89",
"lne;": u"\u2a87",
"lneq;": u"\u2a87",
"lneqq;": u"\u2268",
"lnsim;": u"\u22e6",
"loang;": u"\u27ec",
"loarr;": u"\u21fd",
"lobrk;": u"\u27e6",
"longleftarrow;": u"\u27f5",
"longleftrightarrow;": u"\u27f7",
"longmapsto;": u"\u27fc",
"longrightarrow;": u"\u27f6",
"looparrowleft;": u"\u21ab",
"looparrowright;": u"\u21ac",
"lopar;": u"\u2985",
"lopf;": u"\U0001d55d",
"loplus;": u"\u2a2d",
"lotimes;": u"\u2a34",
"lowast;": u"\u2217",
"lowbar;": u"_",
"loz;": u"\u25ca",
"lozenge;": u"\u25ca",
"lozf;": u"\u29eb",
"lpar;": u"(",
"lparlt;": u"\u2993",
"lrarr;": u"\u21c6",
"lrcorner;": u"\u231f",
"lrhar;": u"\u21cb",
"lrhard;": u"\u296d",
"lrm;": u"\u200e",
"lrtri;": u"\u22bf",
"lsaquo;": u"\u2039",
"lscr;": u"\U0001d4c1",
"lsh;": u"\u21b0",
"lsim;": u"\u2272",
"lsime;": u"\u2a8d",
"lsimg;": u"\u2a8f",
"lsqb;": u"[",
"lsquo;": u"\u2018",
"lsquor;": u"\u201a",
"lstrok;": u"\u0142",
"lt": u"<",
"lt;": u"<",
"ltcc;": u"\u2aa6",
"ltcir;": u"\u2a79",
"ltdot;": u"\u22d6",
"lthree;": u"\u22cb",
"ltimes;": u"\u22c9",
"ltlarr;": u"\u2976",
"ltquest;": u"\u2a7b",
"ltrPar;": u"\u2996",
"ltri;": u"\u25c3",
"ltrie;": u"\u22b4",
"ltrif;": u"\u25c2",
"lurdshar;": u"\u294a",
"luruhar;": u"\u2966",
"lvertneqq;": u"\u2268\ufe00",
"lvnE;": u"\u2268\ufe00",
"mDDot;": u"\u223a",
"macr": u"\xaf",
"macr;": u"\xaf",
"male;": u"\u2642",
"malt;": u"\u2720",
"maltese;": u"\u2720",
"map;": u"\u21a6",
"mapsto;": u"\u21a6",
"mapstodown;": u"\u21a7",
"mapstoleft;": u"\u21a4",
"mapstoup;": u"\u21a5",
"marker;": u"\u25ae",
"mcomma;": u"\u2a29",
"mcy;": u"\u043c",
"mdash;": u"\u2014",
"measuredangle;": u"\u2221",
"mfr;": u"\U0001d52a",
"mho;": u"\u2127",
"micro": u"\xb5",
"micro;": u"\xb5",
"mid;": u"\u2223",
"midast;": u"*",
"midcir;": u"\u2af0",
"middot": u"\xb7",
"middot;": u"\xb7",
"minus;": u"\u2212",
"minusb;": u"\u229f",
"minusd;": u"\u2238",
"minusdu;": u"\u2a2a",
"mlcp;": u"\u2adb",
"mldr;": u"\u2026",
"mnplus;": u"\u2213",
"models;": u"\u22a7",
"mopf;": u"\U0001d55e",
"mp;": u"\u2213",
"mscr;": u"\U0001d4c2",
"mstpos;": u"\u223e",
"mu;": u"\u03bc",
"multimap;": u"\u22b8",
"mumap;": u"\u22b8",
"nGg;": u"\u22d9\u0338",
"nGt;": u"\u226b\u20d2",
"nGtv;": u"\u226b\u0338",
"nLeftarrow;": u"\u21cd",
"nLeftrightarrow;": u"\u21ce",
"nLl;": u"\u22d8\u0338",
"nLt;": u"\u226a\u20d2",
"nLtv;": u"\u226a\u0338",
"nRightarrow;": u"\u21cf",
"nVDash;": u"\u22af",
"nVdash;": u"\u22ae",
"nabla;": u"\u2207",
"nacute;": u"\u0144",
"nang;": u"\u2220\u20d2",
"nap;": u"\u2249",
"napE;": u"\u2a70\u0338",
"napid;": u"\u224b\u0338",
"napos;": u"\u0149",
"napprox;": u"\u2249",
"natur;": u"\u266e",
"natural;": u"\u266e",
"naturals;": u"\u2115",
"nbsp": u"\xa0",
"nbsp;": u"\xa0",
"nbump;": u"\u224e\u0338",
"nbumpe;": u"\u224f\u0338",
"ncap;": u"\u2a43",
"ncaron;": u"\u0148",
"ncedil;": u"\u0146",
"ncong;": u"\u2247",
"ncongdot;": u"\u2a6d\u0338",
"ncup;": u"\u2a42",
"ncy;": u"\u043d",
"ndash;": u"\u2013",
"ne;": u"\u2260",
"neArr;": u"\u21d7",
"nearhk;": u"\u2924",
"nearr;": u"\u2197",
"nearrow;": u"\u2197",
"nedot;": u"\u2250\u0338",
"nequiv;": u"\u2262",
"nesear;": u"\u2928",
"nesim;": u"\u2242\u0338",
"nexist;": u"\u2204",
"nexists;": u"\u2204",
"nfr;": u"\U0001d52b",
"ngE;": u"\u2267\u0338",
"nge;": u"\u2271",
"ngeq;": u"\u2271",
"ngeqq;": u"\u2267\u0338",
"ngeqslant;": u"\u2a7e\u0338",
"nges;": u"\u2a7e\u0338",
"ngsim;": u"\u2275",
"ngt;": u"\u226f",
"ngtr;": u"\u226f",
"nhArr;": u"\u21ce",
"nharr;": u"\u21ae",
"nhpar;": u"\u2af2",
"ni;": u"\u220b",
"nis;": u"\u22fc",
"nisd;": u"\u22fa",
"niv;": u"\u220b",
"njcy;": u"\u045a",
"nlArr;": u"\u21cd",
"nlE;": u"\u2266\u0338",
"nlarr;": u"\u219a",
"nldr;": u"\u2025",
"nle;": u"\u2270",
"nleftarrow;": u"\u219a",
"nleftrightarrow;": u"\u21ae",
"nleq;": u"\u2270",
"nleqq;": u"\u2266\u0338",
"nleqslant;": u"\u2a7d\u0338",
"nles;": u"\u2a7d\u0338",
"nless;": u"\u226e",
"nlsim;": u"\u2274",
"nlt;": u"\u226e",
"nltri;": u"\u22ea",
"nltrie;": u"\u22ec",
"nmid;": u"\u2224",
"nopf;": u"\U0001d55f",
"not": u"\xac",
"not;": u"\xac",
"notin;": u"\u2209",
"notinE;": u"\u22f9\u0338",
"notindot;": u"\u22f5\u0338",
"notinva;": u"\u2209",
"notinvb;": u"\u22f7",
"notinvc;": u"\u22f6",
"notni;": u"\u220c",
"notniva;": u"\u220c",
"notnivb;": u"\u22fe",
"notnivc;": u"\u22fd",
"npar;": u"\u2226",
"nparallel;": u"\u2226",
"nparsl;": u"\u2afd\u20e5",
"npart;": u"\u2202\u0338",
"npolint;": u"\u2a14",
"npr;": u"\u2280",
"nprcue;": u"\u22e0",
"npre;": u"\u2aaf\u0338",
"nprec;": u"\u2280",
"npreceq;": u"\u2aaf\u0338",
"nrArr;": u"\u21cf",
"nrarr;": u"\u219b",
"nrarrc;": u"\u2933\u0338",
"nrarrw;": u"\u219d\u0338",
"nrightarrow;": u"\u219b",
"nrtri;": u"\u22eb",
"nrtrie;": u"\u22ed",
"nsc;": u"\u2281",
"nsccue;": u"\u22e1",
"nsce;": u"\u2ab0\u0338",
"nscr;": u"\U0001d4c3",
"nshortmid;": u"\u2224",
"nshortparallel;": u"\u2226",
"nsim;": u"\u2241",
"nsime;": u"\u2244",
"nsimeq;": u"\u2244",
"nsmid;": u"\u2224",
"nspar;": u"\u2226",
"nsqsube;": u"\u22e2",
"nsqsupe;": u"\u22e3",
"nsub;": u"\u2284",
"nsubE;": u"\u2ac5\u0338",
"nsube;": u"\u2288",
"nsubset;": u"\u2282\u20d2",
"nsubseteq;": u"\u2288",
"nsubseteqq;": u"\u2ac5\u0338",
"nsucc;": u"\u2281",
"nsucceq;": u"\u2ab0\u0338",
"nsup;": u"\u2285",
"nsupE;": u"\u2ac6\u0338",
"nsupe;": u"\u2289",
"nsupset;": u"\u2283\u20d2",
"nsupseteq;": u"\u2289",
"nsupseteqq;": u"\u2ac6\u0338",
"ntgl;": u"\u2279",
"ntilde": u"\xf1",
"ntilde;": u"\xf1",
"ntlg;": u"\u2278",
"ntriangleleft;": u"\u22ea",
"ntrianglelefteq;": u"\u22ec",
"ntriangleright;": u"\u22eb",
"ntrianglerighteq;": u"\u22ed",
"nu;": u"\u03bd",
"num;": u"#",
"numero;": u"\u2116",
"numsp;": u"\u2007",
"nvDash;": u"\u22ad",
"nvHarr;": u"\u2904",
"nvap;": u"\u224d\u20d2",
"nvdash;": u"\u22ac",
"nvge;": u"\u2265\u20d2",
"nvgt;": u">\u20d2",
"nvinfin;": u"\u29de",
"nvlArr;": u"\u2902",
"nvle;": u"\u2264\u20d2",
"nvlt;": u"<\u20d2",
"nvltrie;": u"\u22b4\u20d2",
"nvrArr;": u"\u2903",
"nvrtrie;": u"\u22b5\u20d2",
"nvsim;": u"\u223c\u20d2",
"nwArr;": u"\u21d6",
"nwarhk;": u"\u2923",
"nwarr;": u"\u2196",
"nwarrow;": u"\u2196",
"nwnear;": u"\u2927",
"oS;": u"\u24c8",
"oacute": u"\xf3",
"oacute;": u"\xf3",
"oast;": u"\u229b",
"ocir;": u"\u229a",
"ocirc": u"\xf4",
"ocirc;": u"\xf4",
"ocy;": u"\u043e",
"odash;": u"\u229d",
"odblac;": u"\u0151",
"odiv;": u"\u2a38",
"odot;": u"\u2299",
"odsold;": u"\u29bc",
"oelig;": u"\u0153",
"ofcir;": u"\u29bf",
"ofr;": u"\U0001d52c",
"ogon;": u"\u02db",
"ograve": u"\xf2",
"ograve;": u"\xf2",
"ogt;": u"\u29c1",
"ohbar;": u"\u29b5",
"ohm;": u"\u03a9",
"oint;": u"\u222e",
"olarr;": u"\u21ba",
"olcir;": u"\u29be",
"olcross;": u"\u29bb",
"oline;": u"\u203e",
"olt;": u"\u29c0",
"omacr;": u"\u014d",
"omega;": u"\u03c9",
"omicron;": u"\u03bf",
"omid;": u"\u29b6",
"ominus;": u"\u2296",
"oopf;": u"\U0001d560",
"opar;": u"\u29b7",
"operp;": u"\u29b9",
"oplus;": u"\u2295",
"or;": u"\u2228",
"orarr;": u"\u21bb",
"ord;": u"\u2a5d",
"order;": u"\u2134",
"orderof;": u"\u2134",
"ordf": u"\xaa",
"ordf;": u"\xaa",
"ordm": u"\xba",
"ordm;": u"\xba",
"origof;": u"\u22b6",
"oror;": u"\u2a56",
"orslope;": u"\u2a57",
"orv;": u"\u2a5b",
"oscr;": u"\u2134",
"oslash": u"\xf8",
"oslash;": u"\xf8",
"osol;": u"\u2298",
"otilde": u"\xf5",
"otilde;": u"\xf5",
"otimes;": u"\u2297",
"otimesas;": u"\u2a36",
"ouml": u"\xf6",
"ouml;": u"\xf6",
"ovbar;": u"\u233d",
"par;": u"\u2225",
"para": u"\xb6",
"para;": u"\xb6",
"parallel;": u"\u2225",
"parsim;": u"\u2af3",
"parsl;": u"\u2afd",
"part;": u"\u2202",
"pcy;": u"\u043f",
"percnt;": u"%",
"period;": u".",
"permil;": u"\u2030",
"perp;": u"\u22a5",
"pertenk;": u"\u2031",
"pfr;": u"\U0001d52d",
"phi;": u"\u03c6",
"phiv;": u"\u03d5",
"phmmat;": u"\u2133",
"phone;": u"\u260e",
"pi;": u"\u03c0",
"pitchfork;": u"\u22d4",
"piv;": u"\u03d6",
"planck;": u"\u210f",
"planckh;": u"\u210e",
"plankv;": u"\u210f",
"plus;": u"+",
"plusacir;": u"\u2a23",
"plusb;": u"\u229e",
"pluscir;": u"\u2a22",
"plusdo;": u"\u2214",
"plusdu;": u"\u2a25",
"pluse;": u"\u2a72",
"plusmn": u"\xb1",
"plusmn;": u"\xb1",
"plussim;": u"\u2a26",
"plustwo;": u"\u2a27",
"pm;": u"\xb1",
"pointint;": u"\u2a15",
"popf;": u"\U0001d561",
"pound": u"\xa3",
"pound;": u"\xa3",
"pr;": u"\u227a",
"prE;": u"\u2ab3",
"prap;": u"\u2ab7",
"prcue;": u"\u227c",
"pre;": u"\u2aaf",
"prec;": u"\u227a",
"precapprox;": u"\u2ab7",
"preccurlyeq;": u"\u227c",
"preceq;": u"\u2aaf",
"precnapprox;": u"\u2ab9",
"precneqq;": u"\u2ab5",
"precnsim;": u"\u22e8",
"precsim;": u"\u227e",
"prime;": u"\u2032",
"primes;": u"\u2119",
"prnE;": u"\u2ab5",
"prnap;": u"\u2ab9",
"prnsim;": u"\u22e8",
"prod;": u"\u220f",
"profalar;": u"\u232e",
"profline;": u"\u2312",
"profsurf;": u"\u2313",
"prop;": u"\u221d",
"propto;": u"\u221d",
"prsim;": u"\u227e",
"prurel;": u"\u22b0",
"pscr;": u"\U0001d4c5",
"psi;": u"\u03c8",
"puncsp;": u"\u2008",
"qfr;": u"\U0001d52e",
"qint;": u"\u2a0c",
"qopf;": u"\U0001d562",
"qprime;": u"\u2057",
"qscr;": u"\U0001d4c6",
"quaternions;": u"\u210d",
"quatint;": u"\u2a16",
"quest;": u"?",
"questeq;": u"\u225f",
"quot": u"\"",
"quot;": u"\"",
"rAarr;": u"\u21db",
"rArr;": u"\u21d2",
"rAtail;": u"\u291c",
"rBarr;": u"\u290f",
"rHar;": u"\u2964",
"race;": u"\u223d\u0331",
"racute;": u"\u0155",
"radic;": u"\u221a",
"raemptyv;": u"\u29b3",
"rang;": u"\u27e9",
"rangd;": u"\u2992",
"range;": u"\u29a5",
"rangle;": u"\u27e9",
"raquo": u"\xbb",
"raquo;": u"\xbb",
"rarr;": u"\u2192",
"rarrap;": u"\u2975",
"rarrb;": u"\u21e5",
"rarrbfs;": u"\u2920",
"rarrc;": u"\u2933",
"rarrfs;": u"\u291e",
"rarrhk;": u"\u21aa",
"rarrlp;": u"\u21ac",
"rarrpl;": u"\u2945",
"rarrsim;": u"\u2974",
"rarrtl;": u"\u21a3",
"rarrw;": u"\u219d",
"ratail;": u"\u291a",
"ratio;": u"\u2236",
"rationals;": u"\u211a",
"rbarr;": u"\u290d",
"rbbrk;": u"\u2773",
"rbrace;": u"}",
"rbrack;": u"]",
"rbrke;": u"\u298c",
"rbrksld;": u"\u298e",
"rbrkslu;": u"\u2990",
"rcaron;": u"\u0159",
"rcedil;": u"\u0157",
"rceil;": u"\u2309",
"rcub;": u"}",
"rcy;": u"\u0440",
"rdca;": u"\u2937",
"rdldhar;": u"\u2969",
"rdquo;": u"\u201d",
"rdquor;": u"\u201d",
"rdsh;": u"\u21b3",
"real;": u"\u211c",
"realine;": u"\u211b",
"realpart;": u"\u211c",
"reals;": u"\u211d",
"rect;": u"\u25ad",
"reg": u"\xae",
"reg;": u"\xae",
"rfisht;": u"\u297d",
"rfloor;": u"\u230b",
"rfr;": u"\U0001d52f",
"rhard;": u"\u21c1",
"rharu;": u"\u21c0",
"rharul;": u"\u296c",
"rho;": u"\u03c1",
"rhov;": u"\u03f1",
"rightarrow;": u"\u2192",
"rightarrowtail;": u"\u21a3",
"rightharpoondown;": u"\u21c1",
"rightharpoonup;": u"\u21c0",
"rightleftarrows;": u"\u21c4",
"rightleftharpoons;": u"\u21cc",
"rightrightarrows;": u"\u21c9",
"rightsquigarrow;": u"\u219d",
"rightthreetimes;": u"\u22cc",
"ring;": u"\u02da",
"risingdotseq;": u"\u2253",
"rlarr;": u"\u21c4",
"rlhar;": u"\u21cc",
"rlm;": u"\u200f",
"rmoust;": u"\u23b1",
"rmoustache;": u"\u23b1",
"rnmid;": u"\u2aee",
"roang;": u"\u27ed",
"roarr;": u"\u21fe",
"robrk;": u"\u27e7",
"ropar;": u"\u2986",
"ropf;": u"\U0001d563",
"roplus;": u"\u2a2e",
"rotimes;": u"\u2a35",
"rpar;": u")",
"rpargt;": u"\u2994",
"rppolint;": u"\u2a12",
"rrarr;": u"\u21c9",
"rsaquo;": u"\u203a",
"rscr;": u"\U0001d4c7",
"rsh;": u"\u21b1",
"rsqb;": u"]",
"rsquo;": u"\u2019",
"rsquor;": u"\u2019",
"rthree;": u"\u22cc",
"rtimes;": u"\u22ca",
"rtri;": u"\u25b9",
"rtrie;": u"\u22b5",
"rtrif;": u"\u25b8",
"rtriltri;": u"\u29ce",
"ruluhar;": u"\u2968",
"rx;": u"\u211e",
"sacute;": u"\u015b",
"sbquo;": u"\u201a",
"sc;": u"\u227b",
"scE;": u"\u2ab4",
"scap;": u"\u2ab8",
"scaron;": u"\u0161",
"sccue;": u"\u227d",
"sce;": u"\u2ab0",
"scedil;": u"\u015f",
"scirc;": u"\u015d",
"scnE;": u"\u2ab6",
"scnap;": u"\u2aba",
"scnsim;": u"\u22e9",
"scpolint;": u"\u2a13",
"scsim;": u"\u227f",
"scy;": u"\u0441",
"sdot;": u"\u22c5",
"sdotb;": u"\u22a1",
"sdote;": u"\u2a66",
"seArr;": u"\u21d8",
"searhk;": u"\u2925",
"searr;": u"\u2198",
"searrow;": u"\u2198",
"sect": u"\xa7",
"sect;": u"\xa7",
"semi;": u";",
"seswar;": u"\u2929",
"setminus;": u"\u2216",
"setmn;": u"\u2216",
"sext;": u"\u2736",
"sfr;": u"\U0001d530",
"sfrown;": u"\u2322",
"sharp;": u"\u266f",
"shchcy;": u"\u0449",
"shcy;": u"\u0448",
"shortmid;": u"\u2223",
"shortparallel;": u"\u2225",
"shy": u"\xad",
"shy;": u"\xad",
"sigma;": u"\u03c3",
"sigmaf;": u"\u03c2",
"sigmav;": u"\u03c2",
"sim;": u"\u223c",
"simdot;": u"\u2a6a",
"sime;": u"\u2243",
"simeq;": u"\u2243",
"simg;": u"\u2a9e",
"simgE;": u"\u2aa0",
"siml;": u"\u2a9d",
"simlE;": u"\u2a9f",
"simne;": u"\u2246",
"simplus;": u"\u2a24",
"simrarr;": u"\u2972",
"slarr;": u"\u2190",
"smallsetminus;": u"\u2216",
"smashp;": u"\u2a33",
"smeparsl;": u"\u29e4",
"smid;": u"\u2223",
"smile;": u"\u2323",
"smt;": u"\u2aaa",
"smte;": u"\u2aac",
"smtes;": u"\u2aac\ufe00",
"softcy;": u"\u044c",
"sol;": u"/",
"solb;": u"\u29c4",
"solbar;": u"\u233f",
"sopf;": u"\U0001d564",
"spades;": u"\u2660",
"spadesuit;": u"\u2660",
"spar;": u"\u2225",
"sqcap;": u"\u2293",
"sqcaps;": u"\u2293\ufe00",
"sqcup;": u"\u2294",
"sqcups;": u"\u2294\ufe00",
"sqsub;": u"\u228f",
"sqsube;": u"\u2291",
"sqsubset;": u"\u228f",
"sqsubseteq;": u"\u2291",
"sqsup;": u"\u2290",
"sqsupe;": u"\u2292",
"sqsupset;": u"\u2290",
"sqsupseteq;": u"\u2292",
"squ;": u"\u25a1",
"square;": u"\u25a1",
"squarf;": u"\u25aa",
"squf;": u"\u25aa",
"srarr;": u"\u2192",
"sscr;": u"\U0001d4c8",
"ssetmn;": u"\u2216",
"ssmile;": u"\u2323",
"sstarf;": u"\u22c6",
"star;": u"\u2606",
"starf;": u"\u2605",
"straightepsilon;": u"\u03f5",
"straightphi;": u"\u03d5",
"strns;": u"\xaf",
"sub;": u"\u2282",
"subE;": u"\u2ac5",
"subdot;": u"\u2abd",
"sube;": u"\u2286",
"subedot;": u"\u2ac3",
"submult;": u"\u2ac1",
"subnE;": u"\u2acb",
"subne;": u"\u228a",
"subplus;": u"\u2abf",
"subrarr;": u"\u2979",
"subset;": u"\u2282",
"subseteq;": u"\u2286",
"subseteqq;": u"\u2ac5",
"subsetneq;": u"\u228a",
"subsetneqq;": u"\u2acb",
"subsim;": u"\u2ac7",
"subsub;": u"\u2ad5",
"subsup;": u"\u2ad3",
"succ;": u"\u227b",
"succapprox;": u"\u2ab8",
"succcurlyeq;": u"\u227d",
"succeq;": u"\u2ab0",
"succnapprox;": u"\u2aba",
"succneqq;": u"\u2ab6",
"succnsim;": u"\u22e9",
"succsim;": u"\u227f",
"sum;": u"\u2211",
"sung;": u"\u266a",
"sup1": u"\xb9",
"sup1;": u"\xb9",
"sup2": u"\xb2",
"sup2;": u"\xb2",
"sup3": u"\xb3",
"sup3;": u"\xb3",
"sup;": u"\u2283",
"supE;": u"\u2ac6",
"supdot;": u"\u2abe",
"supdsub;": u"\u2ad8",
"supe;": u"\u2287",
"supedot;": u"\u2ac4",
"suphsol;": u"\u27c9",
"suphsub;": u"\u2ad7",
"suplarr;": u"\u297b",
"supmult;": u"\u2ac2",
"supnE;": u"\u2acc",
"supne;": u"\u228b",
"supplus;": u"\u2ac0",
"supset;": u"\u2283",
"supseteq;": u"\u2287",
"supseteqq;": u"\u2ac6",
"supsetneq;": u"\u228b",
"supsetneqq;": u"\u2acc",
"supsim;": u"\u2ac8",
"supsub;": u"\u2ad4",
"supsup;": u"\u2ad6",
"swArr;": u"\u21d9",
"swarhk;": u"\u2926",
"swarr;": u"\u2199",
"swarrow;": u"\u2199",
"swnwar;": u"\u292a",
"szlig": u"\xdf",
"szlig;": u"\xdf",
"target;": u"\u2316",
"tau;": u"\u03c4",
"tbrk;": u"\u23b4",
"tcaron;": u"\u0165",
"tcedil;": u"\u0163",
"tcy;": u"\u0442",
"tdot;": u"\u20db",
"telrec;": u"\u2315",
"tfr;": u"\U0001d531",
"there4;": u"\u2234",
"therefore;": u"\u2234",
"theta;": u"\u03b8",
"thetasym;": u"\u03d1",
"thetav;": u"\u03d1",
"thickapprox;": u"\u2248",
"thicksim;": u"\u223c",
"thinsp;": u"\u2009",
"thkap;": u"\u2248",
"thksim;": u"\u223c",
"thorn": u"\xfe",
"thorn;": u"\xfe",
"tilde;": u"\u02dc",
"times": u"\xd7",
"times;": u"\xd7",
"timesb;": u"\u22a0",
"timesbar;": u"\u2a31",
"timesd;": u"\u2a30",
"tint;": u"\u222d",
"toea;": u"\u2928",
"top;": u"\u22a4",
"topbot;": u"\u2336",
"topcir;": u"\u2af1",
"topf;": u"\U0001d565",
"topfork;": u"\u2ada",
"tosa;": u"\u2929",
"tprime;": u"\u2034",
"trade;": u"\u2122",
"triangle;": u"\u25b5",
"triangledown;": u"\u25bf",
"triangleleft;": u"\u25c3",
"trianglelefteq;": u"\u22b4",
"triangleq;": u"\u225c",
"triangleright;": u"\u25b9",
"trianglerighteq;": u"\u22b5",
"tridot;": u"\u25ec",
"trie;": u"\u225c",
"triminus;": u"\u2a3a",
"triplus;": u"\u2a39",
"trisb;": u"\u29cd",
"tritime;": u"\u2a3b",
"trpezium;": u"\u23e2",
"tscr;": u"\U0001d4c9",
"tscy;": u"\u0446",
"tshcy;": u"\u045b",
"tstrok;": u"\u0167",
"twixt;": u"\u226c",
"twoheadleftarrow;": u"\u219e",
"twoheadrightarrow;": u"\u21a0",
"uArr;": u"\u21d1",
"uHar;": u"\u2963",
"uacute": u"\xfa",
"uacute;": u"\xfa",
"uarr;": u"\u2191",
"ubrcy;": u"\u045e",
"ubreve;": u"\u016d",
"ucirc": u"\xfb",
"ucirc;": u"\xfb",
"ucy;": u"\u0443",
"udarr;": u"\u21c5",
"udblac;": u"\u0171",
"udhar;": u"\u296e",
"ufisht;": u"\u297e",
"ufr;": u"\U0001d532",
"ugrave": u"\xf9",
"ugrave;": u"\xf9",
"uharl;": u"\u21bf",
"uharr;": u"\u21be",
"uhblk;": u"\u2580",
"ulcorn;": u"\u231c",
"ulcorner;": u"\u231c",
"ulcrop;": u"\u230f",
"ultri;": u"\u25f8",
"umacr;": u"\u016b",
"uml": u"\xa8",
"uml;": u"\xa8",
"uogon;": u"\u0173",
"uopf;": u"\U0001d566",
"uparrow;": u"\u2191",
"updownarrow;": u"\u2195",
"upharpoonleft;": u"\u21bf",
"upharpoonright;": u"\u21be",
"uplus;": u"\u228e",
"upsi;": u"\u03c5",
"upsih;": u"\u03d2",
"upsilon;": u"\u03c5",
"upuparrows;": u"\u21c8",
"urcorn;": u"\u231d",
"urcorner;": u"\u231d",
"urcrop;": u"\u230e",
"uring;": u"\u016f",
"urtri;": u"\u25f9",
"uscr;": u"\U0001d4ca",
"utdot;": u"\u22f0",
"utilde;": u"\u0169",
"utri;": u"\u25b5",
"utrif;": u"\u25b4",
"uuarr;": u"\u21c8",
"uuml": u"\xfc",
"uuml;": u"\xfc",
"uwangle;": u"\u29a7",
"vArr;": u"\u21d5",
"vBar;": u"\u2ae8",
"vBarv;": u"\u2ae9",
"vDash;": u"\u22a8",
"vangrt;": u"\u299c",
"varepsilon;": u"\u03f5",
"varkappa;": u"\u03f0",
"varnothing;": u"\u2205",
"varphi;": u"\u03d5",
"varpi;": u"\u03d6",
"varpropto;": u"\u221d",
"varr;": u"\u2195",
"varrho;": u"\u03f1",
"varsigma;": u"\u03c2",
"varsubsetneq;": u"\u228a\ufe00",
"varsubsetneqq;": u"\u2acb\ufe00",
"varsupsetneq;": u"\u228b\ufe00",
"varsupsetneqq;": u"\u2acc\ufe00",
"vartheta;": u"\u03d1",
"vartriangleleft;": u"\u22b2",
"vartriangleright;": u"\u22b3",
"vcy;": u"\u0432",
"vdash;": u"\u22a2",
"vee;": u"\u2228",
"veebar;": u"\u22bb",
"veeeq;": u"\u225a",
"vellip;": u"\u22ee",
"verbar;": u"|",
"vert;": u"|",
"vfr;": u"\U0001d533",
"vltri;": u"\u22b2",
"vnsub;": u"\u2282\u20d2",
"vnsup;": u"\u2283\u20d2",
"vopf;": u"\U0001d567",
"vprop;": u"\u221d",
"vrtri;": u"\u22b3",
"vscr;": u"\U0001d4cb",
"vsubnE;": u"\u2acb\ufe00",
"vsubne;": u"\u228a\ufe00",
"vsupnE;": u"\u2acc\ufe00",
"vsupne;": u"\u228b\ufe00",
"vzigzag;": u"\u299a",
"wcirc;": u"\u0175",
"wedbar;": u"\u2a5f",
"wedge;": u"\u2227",
"wedgeq;": u"\u2259",
"weierp;": u"\u2118",
"wfr;": u"\U0001d534",
"wopf;": u"\U0001d568",
"wp;": u"\u2118",
"wr;": u"\u2240",
"wreath;": u"\u2240",
"wscr;": u"\U0001d4cc",
"xcap;": u"\u22c2",
"xcirc;": u"\u25ef",
"xcup;": u"\u22c3",
"xdtri;": u"\u25bd",
"xfr;": u"\U0001d535",
"xhArr;": u"\u27fa",
"xharr;": u"\u27f7",
"xi;": u"\u03be",
"xlArr;": u"\u27f8",
"xlarr;": u"\u27f5",
"xmap;": u"\u27fc",
"xnis;": u"\u22fb",
"xodot;": u"\u2a00",
"xopf;": u"\U0001d569",
"xoplus;": u"\u2a01",
"xotime;": u"\u2a02",
"xrArr;": u"\u27f9",
"xrarr;": u"\u27f6",
"xscr;": u"\U0001d4cd",
"xsqcup;": u"\u2a06",
"xuplus;": u"\u2a04",
"xutri;": u"\u25b3",
"xvee;": u"\u22c1",
"xwedge;": u"\u22c0",
"yacute": u"\xfd",
"yacute;": u"\xfd",
"yacy;": u"\u044f",
"ycirc;": u"\u0177",
"ycy;": u"\u044b",
"yen": u"\xa5",
"yen;": u"\xa5",
"yfr;": u"\U0001d536",
"yicy;": u"\u0457",
"yopf;": u"\U0001d56a",
"yscr;": u"\U0001d4ce",
"yucy;": u"\u044e",
"yuml": u"\xff",
"yuml;": u"\xff",
"zacute;": u"\u017a",
"zcaron;": u"\u017e",
"zcy;": u"\u0437",
"zdot;": u"\u017c",
"zeetrf;": u"\u2128",
"zeta;": u"\u03b6",
"zfr;": u"\U0001d537",
"zhcy;": u"\u0436",
"zigrarr;": u"\u21dd",
"zopf;": u"\U0001d56b",
"zscr;": u"\U0001d4cf",
"zwj;": u"\u200d",
"zwnj;": u"\u200c",
}
replacementCharacters = {
0x0:u"\uFFFD",
0x0d:u"\u000D",
0x80:u"\u20AC",
0x81:u"\u0081",
0x81:u"\u0081",
0x82:u"\u201A",
0x83:u"\u0192",
0x84:u"\u201E",
0x85:u"\u2026",
0x86:u"\u2020",
0x87:u"\u2021",
0x88:u"\u02C6",
0x89:u"\u2030",
0x8A:u"\u0160",
0x8B:u"\u2039",
0x8C:u"\u0152",
0x8D:u"\u008D",
0x8E:u"\u017D",
0x8F:u"\u008F",
0x90:u"\u0090",
0x91:u"\u2018",
0x92:u"\u2019",
0x93:u"\u201C",
0x94:u"\u201D",
0x95:u"\u2022",
0x96:u"\u2013",
0x97:u"\u2014",
0x98:u"\u02DC",
0x99:u"\u2122",
0x9A:u"\u0161",
0x9B:u"\u203A",
0x9C:u"\u0153",
0x9D:u"\u009D",
0x9E:u"\u017E",
0x9F:u"\u0178",
}
encodings = {
'437': 'cp437',
'850': 'cp850',
'852': 'cp852',
'855': 'cp855',
'857': 'cp857',
'860': 'cp860',
'861': 'cp861',
'862': 'cp862',
'863': 'cp863',
'865': 'cp865',
'866': 'cp866',
'869': 'cp869',
'ansix341968': 'ascii',
'ansix341986': 'ascii',
'arabic': 'iso8859-6',
'ascii': 'ascii',
'asmo708': 'iso8859-6',
'big5': 'big5',
'big5hkscs': 'big5hkscs',
'chinese': 'gbk',
'cp037': 'cp037',
'cp1026': 'cp1026',
'cp154': 'ptcp154',
'cp367': 'ascii',
'cp424': 'cp424',
'cp437': 'cp437',
'cp500': 'cp500',
'cp775': 'cp775',
'cp819': 'windows-1252',
'cp850': 'cp850',
'cp852': 'cp852',
'cp855': 'cp855',
'cp857': 'cp857',
'cp860': 'cp860',
'cp861': 'cp861',
'cp862': 'cp862',
'cp863': 'cp863',
'cp864': 'cp864',
'cp865': 'cp865',
'cp866': 'cp866',
'cp869': 'cp869',
'cp936': 'gbk',
'cpgr': 'cp869',
'cpis': 'cp861',
'csascii': 'ascii',
'csbig5': 'big5',
'cseuckr': 'cp949',
'cseucpkdfmtjapanese': 'euc_jp',
'csgb2312': 'gbk',
'cshproman8': 'hp-roman8',
'csibm037': 'cp037',
'csibm1026': 'cp1026',
'csibm424': 'cp424',
'csibm500': 'cp500',
'csibm855': 'cp855',
'csibm857': 'cp857',
'csibm860': 'cp860',
'csibm861': 'cp861',
'csibm863': 'cp863',
'csibm864': 'cp864',
'csibm865': 'cp865',
'csibm866': 'cp866',
'csibm869': 'cp869',
'csiso2022jp': 'iso2022_jp',
'csiso2022jp2': 'iso2022_jp_2',
'csiso2022kr': 'iso2022_kr',
'csiso58gb231280': 'gbk',
'csisolatin1': 'windows-1252',
'csisolatin2': 'iso8859-2',
'csisolatin3': 'iso8859-3',
'csisolatin4': 'iso8859-4',
'csisolatin5': 'windows-1254',
'csisolatin6': 'iso8859-10',
'csisolatinarabic': 'iso8859-6',
'csisolatincyrillic': 'iso8859-5',
'csisolatingreek': 'iso8859-7',
'csisolatinhebrew': 'iso8859-8',
'cskoi8r': 'koi8-r',
'csksc56011987': 'cp949',
'cspc775baltic': 'cp775',
'cspc850multilingual': 'cp850',
'cspc862latinhebrew': 'cp862',
'cspc8codepage437': 'cp437',
'cspcp852': 'cp852',
'csptcp154': 'ptcp154',
'csshiftjis': 'shift_jis',
'csunicode11utf7': 'utf-7',
'cyrillic': 'iso8859-5',
'cyrillicasian': 'ptcp154',
'ebcdiccpbe': 'cp500',
'ebcdiccpca': 'cp037',
'ebcdiccpch': 'cp500',
'ebcdiccphe': 'cp424',
'ebcdiccpnl': 'cp037',
'ebcdiccpus': 'cp037',
'ebcdiccpwt': 'cp037',
'ecma114': 'iso8859-6',
'ecma118': 'iso8859-7',
'elot928': 'iso8859-7',
'eucjp': 'euc_jp',
'euckr': 'cp949',
'extendedunixcodepackedformatforjapanese': 'euc_jp',
'gb18030': 'gb18030',
'gb2312': 'gbk',
'gb231280': 'gbk',
'gbk': 'gbk',
'greek': 'iso8859-7',
'greek8': 'iso8859-7',
'hebrew': 'iso8859-8',
'hproman8': 'hp-roman8',
'hzgb2312': 'hz',
'ibm037': 'cp037',
'ibm1026': 'cp1026',
'ibm367': 'ascii',
'ibm424': 'cp424',
'ibm437': 'cp437',
'ibm500': 'cp500',
'ibm775': 'cp775',
'ibm819': 'windows-1252',
'ibm850': 'cp850',
'ibm852': 'cp852',
'ibm855': 'cp855',
'ibm857': 'cp857',
'ibm860': 'cp860',
'ibm861': 'cp861',
'ibm862': 'cp862',
'ibm863': 'cp863',
'ibm864': 'cp864',
'ibm865': 'cp865',
'ibm866': 'cp866',
'ibm869': 'cp869',
'iso2022jp': 'iso2022_jp',
'iso2022jp2': 'iso2022_jp_2',
'iso2022kr': 'iso2022_kr',
'iso646irv1991': 'ascii',
'iso646us': 'ascii',
'iso88591': 'windows-1252',
'iso885910': 'iso8859-10',
'iso8859101992': 'iso8859-10',
'iso885911987': 'windows-1252',
'iso885913': 'iso8859-13',
'iso885914': 'iso8859-14',
'iso8859141998': 'iso8859-14',
'iso885915': 'iso8859-15',
'iso885916': 'iso8859-16',
'iso8859162001': 'iso8859-16',
'iso88592': 'iso8859-2',
'iso885921987': 'iso8859-2',
'iso88593': 'iso8859-3',
'iso885931988': 'iso8859-3',
'iso88594': 'iso8859-4',
'iso885941988': 'iso8859-4',
'iso88595': 'iso8859-5',
'iso885951988': 'iso8859-5',
'iso88596': 'iso8859-6',
'iso885961987': 'iso8859-6',
'iso88597': 'iso8859-7',
'iso885971987': 'iso8859-7',
'iso88598': 'iso8859-8',
'iso885981988': 'iso8859-8',
'iso88599': 'windows-1254',
'iso885991989': 'windows-1254',
'isoceltic': 'iso8859-14',
'isoir100': 'windows-1252',
'isoir101': 'iso8859-2',
'isoir109': 'iso8859-3',
'isoir110': 'iso8859-4',
'isoir126': 'iso8859-7',
'isoir127': 'iso8859-6',
'isoir138': 'iso8859-8',
'isoir144': 'iso8859-5',
'isoir148': 'windows-1254',
'isoir149': 'cp949',
'isoir157': 'iso8859-10',
'isoir199': 'iso8859-14',
'isoir226': 'iso8859-16',
'isoir58': 'gbk',
'isoir6': 'ascii',
'koi8r': 'koi8-r',
'koi8u': 'koi8-u',
'korean': 'cp949',
'ksc5601': 'cp949',
'ksc56011987': 'cp949',
'ksc56011989': 'cp949',
'l1': 'windows-1252',
'l10': 'iso8859-16',
'l2': 'iso8859-2',
'l3': 'iso8859-3',
'l4': 'iso8859-4',
'l5': 'windows-1254',
'l6': 'iso8859-10',
'l8': 'iso8859-14',
'latin1': 'windows-1252',
'latin10': 'iso8859-16',
'latin2': 'iso8859-2',
'latin3': 'iso8859-3',
'latin4': 'iso8859-4',
'latin5': 'windows-1254',
'latin6': 'iso8859-10',
'latin8': 'iso8859-14',
'latin9': 'iso8859-15',
'ms936': 'gbk',
'mskanji': 'shift_jis',
'pt154': 'ptcp154',
'ptcp154': 'ptcp154',
'r8': 'hp-roman8',
'roman8': 'hp-roman8',
'shiftjis': 'shift_jis',
'tis620': 'cp874',
'unicode11utf7': 'utf-7',
'us': 'ascii',
'usascii': 'ascii',
'utf16': 'utf-16',
'utf16be': 'utf-16-be',
'utf16le': 'utf-16-le',
'utf8': 'utf-8',
'windows1250': 'cp1250',
'windows1251': 'cp1251',
'windows1252': 'cp1252',
'windows1253': 'cp1253',
'windows1254': 'cp1254',
'windows1255': 'cp1255',
'windows1256': 'cp1256',
'windows1257': 'cp1257',
'windows1258': 'cp1258',
'windows936': 'gbk',
'x-x-big5': 'big5'}
tokenTypes = {
"Doctype":0,
"Characters":1,
"SpaceCharacters":2,
"StartTag":3,
"EndTag":4,
"EmptyTag":5,
"Comment":6,
"ParseError":7
}
tagTokenTypes = frozenset((tokenTypes["StartTag"], tokenTypes["EndTag"],
tokenTypes["EmptyTag"]))
prefixes = dict([(v,k) for k,v in namespaces.iteritems()])
prefixes["http://www.w3.org/1998/Math/MathML"] = "math"
class DataLossWarning(UserWarning):
pass
class ReparseException(Exception):
pass
|
bsd-3-clause
|
[
646,
1059,
12,
9796,
199,
63,
275,
9796,
14,
5152,
199,
199,
893,
26,
272,
9522,
199,
2590,
12746,
26,
272,
327,
3161,
687,
314,
5951,
859,
367,
2366,
499,
14,
19,
272,
687,
5951,
492,
2494,
465,
663,
272,
687,
5951,
492,
25609,
1084,
465,
9522,
199,
199,
13178,
275,
488,
199,
199,
37,
275,
469,
272,
298,
2307,
13,
10856,
582,
28872,
12561,
85,
2,
8849,
4528,
315,
1324,
2547,
12,
8717,
543,
738,
11,
28050,
7651,
272,
298,
3197,
13,
19300,
582,
28872,
12561,
85,
2,
3364,
1233,
1403,
315,
2547,
7651,
272,
298,
15448,
590,
13,
2778,
68,
13,
18533,
527,
582,
2126,
12561,
85,
2,
5158,
7401,
527,
334,
24793,
22743,
15090,
315,
1947,
7651,
272,
298,
15448,
13,
1556,
13,
12210,
13,
4502,
582,
2126,
12561,
85,
2,
18298,
17101,
8057,
4642,
12,
8717,
543,
491,
38,
7651,
272,
298,
23375,
13,
8258,
13,
19364,
13,
4502,
582,
2126,
12561,
85,
2,
7302,
1202,
543,
20282,
1329,
334,
8258,
13,
19364,
3659,
680,
1288,
272,
298,
67,
867,
13,
3916,
13,
6677,
13,
4502,
582,
2126,
12561,
85,
2,
14687,
4642,
21554,
1133,
506,
6702,
370,
4528,
298,
268,
399,
26507,
19300,
738,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
680,
1288,
272,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
582,
2126,
12561,
85,
2,
14687,
4642,
8469,
376,
20282,
1233,
1403,
26,
298,
268,
399,
2,
53,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
7651,
272,
298,
6677,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
2126,
12561,
85,
2,
14687,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
6677,
13,
4502,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
14687,
4642,
1420,
14,
24734,
1284,
402,
570,
3140,
7651,
272,
298,
2062,
13,
6677,
13,
4502,
582,
2126,
12561,
85,
2,
14687,
4642,
1420,
1325,
7179,
1911,
7651,
272,
298,
4579,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
2126,
12561,
85,
2,
7989,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
4579,
13,
4502,
582,
2126,
12561,
85,
2,
7989,
4642,
1420,
14,
24734,
7179,
7651,
272,
298,
2987,
13,
262,
13,
500,
13,
1450,
582,
2126,
12561,
85,
2,
3005,
1947,
3509,
10537,
3004,
7651,
272,
283,
277,
13,
11707,
13,
4173,
13,
265,
13,
500,
13,
1450,
356,
267,
12561,
85,
2,
3005,
1947,
3509,
10537,
291,
13,
11707,
3305,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
2126,
12561,
85,
2,
6964,
1947,
536,
14,
24734,
21770,
3140,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
4790,
13,
1657,
582,
2126,
12561,
85,
2,
6964,
1947,
536,
14,
24734,
15539,
3140,
14,
334,
4943,
3181,
1133,
298,
268,
399,
2,
4058,
6661,
15794,
4959,
1288,
272,
298,
2062,
13,
1450,
13,
354,
582,
2126,
12561,
85,
2,
6964,
1947,
536,
14,
24734,
6020,
587,
3140,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
2126,
12561,
85,
2,
6964,
11261,
1947,
14,
24734,
21770,
3140,
14,
20489,
6854,
11936,
22936,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
6964,
11261,
1947,
14,
25345,
1284,
402,
570,
7651,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1560,
582,
2126,
12561,
85,
2,
6964,
11261,
1947,
14,
25345,
4528,
9487,
576,
9,
83,
7,
1911,
7651,
272,
298,
11670,
13,
262,
13,
1450,
13,
354,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
314,
1947,
536,
7651,
272,
298,
2062,
13,
3215,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
14,
13796,
2225,
536,
3140,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
354,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
536,
7651,
272,
298,
3197,
13,
10856,
13,
262,
13,
3215,
13,
354,
582,
267,
12561,
85,
2,
3364,
682,
6457,
351,
315,
2225,
536,
1288,
272,
298,
11081,
13,
3215,
582,
2126,
12561,
85,
2,
11070,
1915,
9250,
2225,
641,
1947,
7651,
272,
298,
2062,
13,
500,
13,
1618,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
14,
13796,
275,
503,
1284,
402,
1947,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
14,
13796,
2225,
574,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
2126,
12561,
85,
2,
6964,
2225,
574,
14,
24734,
21770,
3140,
7651,
272,
283,
11332,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
12561,
85,
2,
8708,
275,
315,
31791,
2225,
1288,
272,
283,
8953,
13,
10856,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
12561,
85,
2,
8708,
4528,
315,
31791,
2225,
1288,
272,
298,
3197,
13,
10856,
13,
4399,
13,
3215,
13,
354,
582,
2126,
12561,
85,
2,
8708,
4528,
2410,
2225,
536,
7651,
272,
298,
8953,
13,
10856,
13,
4399,
13,
3215,
13,
585,
582,
2126,
12561,
85,
2,
8708,
4528,
2410,
2225,
574,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
3157,
13,
3513,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
574,
14749,
3471,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
4780,
13,
3513,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
574,
334,
1959,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
889,
13,
14005,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
574,
7651,
272,
298,
8953,
13,
13178,
13,
4399,
13,
18533,
527,
13,
262,
13,
1450,
582,
267,
12561,
85,
2,
8708,
1284,
402,
570,
315,
1947,
14,
13796,
690,
1288,
272,
298,
8953,
13,
10856,
13,
4399,
13,
7873,
5231,
13,
262,
13,
1450,
582,
267,
12561,
85,
2,
8708,
4528,
2410,
1182,
315,
1947,
14,
13796,
690,
1288,
272,
298
] |
[
1059,
12,
9796,
199,
63,
275,
9796,
14,
5152,
199,
199,
893,
26,
272,
9522,
199,
2590,
12746,
26,
272,
327,
3161,
687,
314,
5951,
859,
367,
2366,
499,
14,
19,
272,
687,
5951,
492,
2494,
465,
663,
272,
687,
5951,
492,
25609,
1084,
465,
9522,
199,
199,
13178,
275,
488,
199,
199,
37,
275,
469,
272,
298,
2307,
13,
10856,
582,
28872,
12561,
85,
2,
8849,
4528,
315,
1324,
2547,
12,
8717,
543,
738,
11,
28050,
7651,
272,
298,
3197,
13,
19300,
582,
28872,
12561,
85,
2,
3364,
1233,
1403,
315,
2547,
7651,
272,
298,
15448,
590,
13,
2778,
68,
13,
18533,
527,
582,
2126,
12561,
85,
2,
5158,
7401,
527,
334,
24793,
22743,
15090,
315,
1947,
7651,
272,
298,
15448,
13,
1556,
13,
12210,
13,
4502,
582,
2126,
12561,
85,
2,
18298,
17101,
8057,
4642,
12,
8717,
543,
491,
38,
7651,
272,
298,
23375,
13,
8258,
13,
19364,
13,
4502,
582,
2126,
12561,
85,
2,
7302,
1202,
543,
20282,
1329,
334,
8258,
13,
19364,
3659,
680,
1288,
272,
298,
67,
867,
13,
3916,
13,
6677,
13,
4502,
582,
2126,
12561,
85,
2,
14687,
4642,
21554,
1133,
506,
6702,
370,
4528,
298,
268,
399,
26507,
19300,
738,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
680,
1288,
272,
298,
23375,
13,
19300,
13,
509,
13,
6677,
13,
4502,
582,
2126,
12561,
85,
2,
14687,
4642,
8469,
376,
20282,
1233,
1403,
26,
298,
268,
399,
2,
53,
11,
2840,
1560,
2822,
3241,
9,
2036,
88,
7651,
272,
298,
6677,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
2126,
12561,
85,
2,
14687,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
6677,
13,
4502,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
14687,
4642,
1420,
14,
24734,
1284,
402,
570,
3140,
7651,
272,
298,
2062,
13,
6677,
13,
4502,
582,
2126,
12561,
85,
2,
14687,
4642,
1420,
1325,
7179,
1911,
7651,
272,
298,
4579,
13,
4502,
13,
7395,
13,
19290,
12167,
582,
2126,
12561,
85,
2,
7989,
4642,
9980,
1133,
1284,
543,
30955,
1288,
272,
298,
2062,
13,
4579,
13,
4502,
582,
2126,
12561,
85,
2,
7989,
4642,
1420,
14,
24734,
7179,
7651,
272,
298,
2987,
13,
262,
13,
500,
13,
1450,
582,
2126,
12561,
85,
2,
3005,
1947,
3509,
10537,
3004,
7651,
272,
283,
277,
13,
11707,
13,
4173,
13,
265,
13,
500,
13,
1450,
356,
267,
12561,
85,
2,
3005,
1947,
3509,
10537,
291,
13,
11707,
3305,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
2126,
12561,
85,
2,
6964,
1947,
536,
14,
24734,
21770,
3140,
7651,
272,
298,
2062,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
4790,
13,
1657,
582,
2126,
12561,
85,
2,
6964,
1947,
536,
14,
24734,
15539,
3140,
14,
334,
4943,
3181,
1133,
298,
268,
399,
2,
4058,
6661,
15794,
4959,
1288,
272,
298,
2062,
13,
1450,
13,
354,
582,
2126,
12561,
85,
2,
6964,
1947,
536,
14,
24734,
6020,
587,
3140,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
2126,
12561,
85,
2,
6964,
11261,
1947,
14,
24734,
21770,
3140,
14,
20489,
6854,
11936,
22936,
1288,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
6964,
11261,
1947,
14,
25345,
1284,
402,
570,
7651,
272,
298,
2062,
13,
11707,
13,
1450,
13,
7911,
13,
7808,
13,
1560,
582,
2126,
12561,
85,
2,
6964,
11261,
1947,
14,
25345,
4528,
9487,
576,
9,
83,
7,
1911,
7651,
272,
298,
11670,
13,
262,
13,
1450,
13,
354,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
314,
1947,
536,
7651,
272,
298,
2062,
13,
3215,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
14,
13796,
2225,
536,
3140,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
354,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
536,
7651,
272,
298,
3197,
13,
10856,
13,
262,
13,
3215,
13,
354,
582,
267,
12561,
85,
2,
3364,
682,
6457,
351,
315,
2225,
536,
1288,
272,
298,
11081,
13,
3215,
582,
2126,
12561,
85,
2,
11070,
1915,
9250,
2225,
641,
1947,
7651,
272,
298,
2062,
13,
500,
13,
1618,
13,
1450,
13,
354,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
14,
13796,
275,
503,
1284,
402,
1947,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
11670,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
14,
13796,
2225,
574,
7651,
272,
298,
2062,
13,
3215,
13,
585,
13,
7911,
13,
7808,
13,
1019,
13,
14594,
582,
2126,
12561,
85,
2,
6964,
2225,
574,
14,
24734,
21770,
3140,
7651,
272,
283,
11332,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
12561,
85,
2,
8708,
275,
315,
31791,
2225,
1288,
272,
283,
8953,
13,
10856,
13,
262,
13,
324,
9888,
13,
3215,
13,
585,
356,
267,
12561,
85,
2,
8708,
4528,
315,
31791,
2225,
1288,
272,
298,
3197,
13,
10856,
13,
4399,
13,
3215,
13,
354,
582,
2126,
12561,
85,
2,
8708,
4528,
2410,
2225,
536,
7651,
272,
298,
8953,
13,
10856,
13,
4399,
13,
3215,
13,
585,
582,
2126,
12561,
85,
2,
8708,
4528,
2410,
2225,
574,
7651,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
3157,
13,
3513,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
574,
14749,
3471,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
4780,
13,
3513,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
574,
334,
1959,
1288,
272,
298,
11670,
13,
262,
13,
3215,
13,
585,
13,
889,
13,
14005,
582,
2126,
12561,
85,
2,
8708,
1284,
402,
570,
315,
2225,
574,
7651,
272,
298,
8953,
13,
13178,
13,
4399,
13,
18533,
527,
13,
262,
13,
1450,
582,
267,
12561,
85,
2,
8708,
1284,
402,
570,
315,
1947,
14,
13796,
690,
1288,
272,
298,
8953,
13,
10856,
13,
4399,
13,
7873,
5231,
13,
262,
13,
1450,
582,
267,
12561,
85,
2,
8708,
4528,
2410,
1182,
315,
1947,
14,
13796,
690,
1288,
272,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tuomas2/serviceform
|
serviceform/serviceform/models/participation.py
|
1
|
4015
|
# -*- coding: utf-8 -*-
# (c) 2017 Tuomas Airaksinen
#
# This file is part of Serviceform.
#
# Serviceform 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.
#
# Serviceform 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 Serviceform. If not, see <http://www.gnu.org/licenses/>.
from typing import Sequence, TYPE_CHECKING
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.functional import cached_property
from .. import utils
if TYPE_CHECKING:
from .people import Participant
class ParticipantLog(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
participant = models.ForeignKey('serviceform.Participant', on_delete=models.CASCADE)
writer_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
writer_id = models.PositiveIntegerField()
# Can be either responsible or django user
written_by = GenericForeignKey('writer_type', 'writer_id')
message = models.TextField()
class ParticipationActivity(models.Model):
class Meta:
unique_together = (('participant', 'activity'),)
ordering = (
'activity__category__category__order', 'activity__category__order', 'activity__order',)
participant = models.ForeignKey('serviceform.Participant', on_delete=models.CASCADE)
activity = models.ForeignKey('serviceform.Activity', on_delete=models.CASCADE)
additional_info = models.CharField(max_length=1024, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, null=True)
@cached_property
def cached_participant(self) -> 'Participant':
return utils.get_participant(self.participant_id)
def __str__(self):
return '%s for %s' % (self.activity, self.participant)
@property
def choices(self) -> 'Sequence[ParticipationActivityChoice]':
return self.choices_set.select_related('activity_choice')
@property
def additional_info_display(self) -> str:
return self.additional_info or '-'
class ParticipationActivityChoice(models.Model):
class Meta:
unique_together = (('activity', 'activity_choice'),)
ordering = ('activity_choice__order',)
activity = models.ForeignKey(ParticipationActivity, related_name='choices_set',
on_delete=models.CASCADE)
activity_choice = models.ForeignKey('serviceform.ActivityChoice', on_delete=models.CASCADE)
additional_info = models.CharField(max_length=1024, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True, null=True)
@cached_property
def cached_participant(self) -> 'Participant':
return utils.get_participant(self.activity.participant_id)
def __str__(self):
return '%s for %s' % (self.activity_choice, self.activity.participant)
@property
def additional_info_display(self) -> str:
return self.additional_info or '-'
class QuestionAnswer(models.Model):
participant = models.ForeignKey('serviceform.Participant', on_delete=models.CASCADE)
question = models.ForeignKey('serviceform.Question', on_delete=models.CASCADE)
answer = models.TextField()
created_at = models.DateTimeField(auto_now_add=True, null=True)
class Meta:
ordering = ('question__order',)
@cached_property
def cached_participant(self) -> 'Participant':
return utils.get_participant(self.participant_id)
def __str__(self):
return '%s: %s' % (self.question.question, self.answer)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
334,
67,
9,
9708,
377,
7519,
305,
437,
20936,
75,
5911,
287,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
7591,
964,
14,
199,
3,
199,
3,
7591,
964,
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,
7591,
964,
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,
7591,
964,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
14090,
492,
10975,
12,
11511,
63,
8936,
1206,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
955,
492,
8307,
3190,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
2508,
492,
3778,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
687,
1275,
13562,
492,
2235,
16448,
199,
199,
533,
2235,
16448,
2445,
8,
992,
14,
1685,
304,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
623,
16448,
275,
1709,
14,
3190,
360,
1364,
964,
14,
1262,
16448,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
7060,
63,
466,
275,
1709,
14,
3190,
8,
11282,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
7060,
63,
344,
275,
1709,
14,
8591,
342,
272,
327,
6855,
506,
1902,
17845,
503,
1639,
922,
272,
5313,
63,
991,
275,
8307,
3190,
360,
5491,
63,
466,
297,
283,
5491,
63,
344,
358,
272,
1245,
275,
1709,
14,
6254,
342,
421,
199,
533,
2235,
31089,
387,
296,
14350,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
13636,
29253,
297,
283,
8240,
659,
9,
267,
7794,
275,
334,
267,
283,
8240,
363,
3710,
363,
3710,
363,
1648,
297,
283,
8240,
363,
3710,
363,
1648,
297,
283,
8240,
363,
1648,
9538,
339,
623,
16448,
275,
1709,
14,
3190,
360,
1364,
964,
14,
1262,
16448,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
10679,
275,
1709,
14,
3190,
360,
1364,
964,
14,
14350,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
4722,
63,
815,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
2973,
29,
549,
9,
339,
768,
5245,
63,
1829,
272,
347,
6328,
63,
29253,
8,
277,
9,
1035,
283,
1262,
16448,
356,
267,
372,
3778,
14,
362,
63,
29253,
8,
277,
14,
29253,
63,
344,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
367,
450,
83,
7,
450,
334,
277,
14,
8240,
12,
291,
14,
29253,
9,
339,
768,
1829,
272,
347,
3415,
8,
277,
9,
1035,
283,
5826,
59,
1262,
31089,
387,
296,
14350,
9054,
61,
356,
267,
372,
291,
14,
4577,
63,
409,
14,
2416,
63,
2407,
360,
8240,
63,
5095,
358,
339,
768,
1829,
272,
347,
4722,
63,
815,
63,
2918,
8,
277,
9,
1035,
620,
26,
267,
372,
291,
14,
8460,
63,
815,
503,
10791,
421,
199,
533,
2235,
31089,
387,
296,
14350,
9054,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
13636,
8240,
297,
283,
8240,
63,
5095,
659,
9,
267,
7794,
275,
661,
8240,
63,
5095,
363,
1648,
9538,
339,
10679,
275,
1709,
14,
3190,
8,
1262,
31089,
387,
296,
14350,
12,
4048,
63,
354,
534,
4577,
63,
409,
297,
639,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
10679,
63,
5095,
275,
1709,
14,
3190,
360,
1364,
964,
14,
14350,
9054,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
4722,
63,
815,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
2973,
29,
549,
9,
339,
768,
5245,
63,
1829,
272,
347,
6328,
63,
29253,
8,
277,
9,
1035,
283,
1262,
16448,
356,
267,
372,
3778,
14,
362,
63,
29253,
8,
277,
14,
8240,
14,
29253,
63,
344,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
367,
450,
83,
7,
450,
334,
277,
14,
8240,
63,
5095,
12,
291,
14,
8240,
14,
29253,
9,
339,
768,
1829,
272,
347,
4722,
63,
815,
63,
2918,
8,
277,
9,
1035,
620,
26,
267,
372,
291,
14,
8460,
63,
815,
503,
10791,
421,
199,
533,
21421,
19104,
8,
992,
14,
1685,
304,
272,
623,
16448,
275,
1709,
14,
3190,
360,
1364,
964,
14,
1262,
16448,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
7894,
275,
1709,
14,
3190,
360,
1364,
964,
14,
16778,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
6385,
275,
1709,
14,
6254,
342,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
2973,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
4790,
363,
1648,
9538,
339,
768,
5245,
63,
1829,
272,
347,
6328,
63,
29253,
8,
277,
9,
1035,
283,
1262,
16448,
356,
267,
372,
3778,
14,
362,
63,
29253,
8,
277,
14,
29253,
63,
344,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
26,
450,
83,
7,
450,
334,
277,
14,
4790,
14,
4790,
12,
291,
14,
5934,
9,
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,
334,
67,
9,
9708,
377,
7519,
305,
437,
20936,
75,
5911,
287,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
7591,
964,
14,
199,
3,
199,
3,
7591,
964,
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,
7591,
964,
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,
7591,
964,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
14090,
492,
10975,
12,
11511,
63,
8936,
1206,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
955,
492,
8307,
3190,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
2508,
492,
3778,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
687,
1275,
13562,
492,
2235,
16448,
199,
199,
533,
2235,
16448,
2445,
8,
992,
14,
1685,
304,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
623,
16448,
275,
1709,
14,
3190,
360,
1364,
964,
14,
1262,
16448,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
7060,
63,
466,
275,
1709,
14,
3190,
8,
11282,
12,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
7060,
63,
344,
275,
1709,
14,
8591,
342,
272,
327,
6855,
506,
1902,
17845,
503,
1639,
922,
272,
5313,
63,
991,
275,
8307,
3190,
360,
5491,
63,
466,
297,
283,
5491,
63,
344,
358,
272,
1245,
275,
1709,
14,
6254,
342,
421,
199,
533,
2235,
31089,
387,
296,
14350,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
13636,
29253,
297,
283,
8240,
659,
9,
267,
7794,
275,
334,
267,
283,
8240,
363,
3710,
363,
3710,
363,
1648,
297,
283,
8240,
363,
3710,
363,
1648,
297,
283,
8240,
363,
1648,
9538,
339,
623,
16448,
275,
1709,
14,
3190,
360,
1364,
964,
14,
1262,
16448,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
10679,
275,
1709,
14,
3190,
360,
1364,
964,
14,
14350,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
4722,
63,
815,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
2973,
29,
549,
9,
339,
768,
5245,
63,
1829,
272,
347,
6328,
63,
29253,
8,
277,
9,
1035,
283,
1262,
16448,
356,
267,
372,
3778,
14,
362,
63,
29253,
8,
277,
14,
29253,
63,
344,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
367,
450,
83,
7,
450,
334,
277,
14,
8240,
12,
291,
14,
29253,
9,
339,
768,
1829,
272,
347,
3415,
8,
277,
9,
1035,
283,
5826,
59,
1262,
31089,
387,
296,
14350,
9054,
61,
356,
267,
372,
291,
14,
4577,
63,
409,
14,
2416,
63,
2407,
360,
8240,
63,
5095,
358,
339,
768,
1829,
272,
347,
4722,
63,
815,
63,
2918,
8,
277,
9,
1035,
620,
26,
267,
372,
291,
14,
8460,
63,
815,
503,
10791,
421,
199,
533,
2235,
31089,
387,
296,
14350,
9054,
8,
992,
14,
1685,
304,
272,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
13636,
8240,
297,
283,
8240,
63,
5095,
659,
9,
267,
7794,
275,
661,
8240,
63,
5095,
363,
1648,
9538,
339,
10679,
275,
1709,
14,
3190,
8,
1262,
31089,
387,
296,
14350,
12,
4048,
63,
354,
534,
4577,
63,
409,
297,
639,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
10679,
63,
5095,
275,
1709,
14,
3190,
360,
1364,
964,
14,
14350,
9054,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
4722,
63,
815,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
2973,
29,
549,
9,
339,
768,
5245,
63,
1829,
272,
347,
6328,
63,
29253,
8,
277,
9,
1035,
283,
1262,
16448,
356,
267,
372,
3778,
14,
362,
63,
29253,
8,
277,
14,
8240,
14,
29253,
63,
344,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
367,
450,
83,
7,
450,
334,
277,
14,
8240,
63,
5095,
12,
291,
14,
8240,
14,
29253,
9,
339,
768,
1829,
272,
347,
4722,
63,
815,
63,
2918,
8,
277,
9,
1035,
620,
26,
267,
372,
291,
14,
8460,
63,
815,
503,
10791,
421,
199,
533,
21421,
19104,
8,
992,
14,
1685,
304,
272,
623,
16448,
275,
1709,
14,
3190,
360,
1364,
964,
14,
1262,
16448,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
7894,
275,
1709,
14,
3190,
360,
1364,
964,
14,
16778,
297,
641,
63,
1807,
29,
992,
14,
10855,
9,
272,
6385,
275,
1709,
14,
6254,
342,
272,
2737,
63,
292,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
2973,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
4790,
363,
1648,
9538,
339,
768,
5245,
63,
1829,
272,
347,
6328,
63,
29253,
8,
277,
9,
1035,
283,
1262,
16448,
356,
267,
372,
3778,
14,
362,
63,
29253,
8,
277,
14,
29253,
63,
344,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
26,
450,
83,
7,
450,
334,
277,
14,
4790,
14,
4790,
12,
291,
14,
5934,
9,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
cryptickp/heat
|
heat/tests/aws/test_volume.py
|
4
|
27952
|
#
# 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 copy
from cinderclient import exceptions as cinder_exp
import mock
import mox
from oslo_config import cfg
import six
from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import cinder
from heat.engine.clients.os import nova
from heat.engine.resources.aws.ec2 import instance
from heat.engine.resources.aws.ec2 import volume as aws_vol
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.cinder import test_volume_utils as vt_base
from heat.tests.nova import fakes as fakes_nova
from heat.tests import utils
volume_template = '''
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Volume Test",
"Parameters" : {},
"Resources" : {
"WikiDatabase": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId" : "foo",
"InstanceType" : "m1.large",
"KeyName" : "test",
"UserData" : "some data"
}
},
"DataVolume" : {
"Type" : "AWS::EC2::Volume",
"Properties" : {
"Size" : "1",
"AvailabilityZone" : {"Fn::GetAtt": ["WikiDatabase",
"AvailabilityZone"]},
"Tags" : [{ "Key" : "Usage", "Value" : "Wiki Data Volume" }]
}
},
"MountPoint" : {
"Type" : "AWS::EC2::VolumeAttachment",
"Properties" : {
"InstanceId" : { "Ref" : "WikiDatabase" },
"VolumeId" : { "Ref" : "DataVolume" },
"Device" : "/dev/vdc"
}
}
}
}
'''
class VolumeTest(vt_base.BaseVolumeTest):
def setUp(self):
super(VolumeTest, self).setUp()
self.t = template_format.parse(volume_template)
self.use_cinder = False
def _mock_create_volume(self, fv, stack_name, final_status='available'):
cinder.CinderClientPlugin._create().MultipleTimes().AndReturn(
self.cinder_fc)
vol_name = utils.PhysName(stack_name, 'DataVolume')
self.cinder_fc.volumes.create(
size=1, availability_zone='nova',
description=vol_name,
name=vol_name,
metadata={u'Usage': u'Wiki Data Volume'}).AndReturn(
vt_base.FakeVolume(fv))
self.cinder_fc.volumes.get(fv.id).AndReturn(fv)
fv_ready = vt_base.FakeVolume(final_status, id=fv.id)
self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready)
return fv_ready
def test_volume(self):
stack_name = 'test_volume_create_stack'
# create script
fv = self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
# failed delete due to in-use script
self.cinder_fc.volumes.get(fv.id).AndReturn(
vt_base.FakeVolume('in-use'))
# delete script
self._mock_delete_volume(fv)
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
rsrc = self.create_volume(self.t, stack, 'DataVolume')
ex = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.destroy))
self.assertIn("Volume in use", six.text_type(ex))
scheduler.TaskRunner(rsrc.destroy)()
self.m.VerifyAll()
def test_volume_default_az(self):
fv = vt_base.FakeVolume('creating')
stack_name = 'test_volume_defaultaz_stack'
# create script
nova.NovaClientPlugin._create().AndReturn(self.fc)
self.m.StubOutWithMock(instance.Instance, 'handle_create')
self.m.StubOutWithMock(instance.Instance, 'check_create_complete')
self.m.StubOutWithMock(instance.Instance, '_resolve_attribute')
self.m.StubOutWithMock(aws_vol.VolumeAttachment,
'handle_create')
self.m.StubOutWithMock(aws_vol.VolumeAttachment,
'check_create_complete')
instance.Instance.handle_create().AndReturn(None)
instance.Instance.check_create_complete(None).AndReturn(True)
instance.Instance._resolve_attribute(
'AvailabilityZone').MultipleTimes().AndReturn(None)
cinder.CinderClientPlugin._create().AndReturn(
self.cinder_fc)
self.stub_ImageConstraint_validate()
self.stub_ServerConstraint_validate()
self.stub_VolumeConstraint_validate()
vol_name = utils.PhysName(stack_name, 'DataVolume')
self.cinder_fc.volumes.create(
size=1, availability_zone=None,
description=vol_name,
name=vol_name,
metadata={u'Usage': u'Wiki Data Volume'}).AndReturn(fv)
self.cinder_fc.volumes.get(fv.id).AndReturn(fv)
fv_ready = vt_base.FakeVolume('available', id=fv.id)
self.cinder_fc.volumes.get(fv.id).AndReturn(fv_ready)
aws_vol.VolumeAttachment.handle_create().AndReturn(None)
aws_vol.VolumeAttachment.check_create_complete(
None).AndReturn(True)
# delete script
self.m.StubOutWithMock(instance.Instance, 'handle_delete')
self.m.StubOutWithMock(aws_vol.VolumeAttachment, 'handle_delete')
self.m.StubOutWithMock(aws_vol.VolumeAttachment,
'check_delete_complete')
instance.Instance.handle_delete().AndReturn(None)
self.cinder_fc.volumes.get('vol-123').AndRaise(
cinder_exp.NotFound('Not found'))
cookie = object()
aws_vol.VolumeAttachment.handle_delete().AndReturn(cookie)
aws_vol.VolumeAttachment.check_delete_complete(cookie).AndReturn(True)
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
rsrc = stack['DataVolume']
self.assertIsNone(rsrc.validate())
scheduler.TaskRunner(stack.create)()
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
scheduler.TaskRunner(stack.delete)()
self.m.VerifyAll()
def test_volume_create_error(self):
fv = vt_base.FakeVolume('creating')
stack_name = 'test_volume_create_error_stack'
cfg.CONF.set_override('action_retry_limit', 0)
self._mock_create_volume(fv, stack_name, final_status='error')
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
ex = self.assertRaises(exception.ResourceFailure,
self.create_volume, self.t, stack, 'DataVolume')
self.assertIn('Went to status error due to "Unknown"',
six.text_type(ex))
self.m.VerifyAll()
def test_volume_bad_tags(self):
stack_name = 'test_volume_bad_tags_stack'
self.t['Resources']['DataVolume']['Properties'][
'Tags'] = [{'Foo': 'bar'}]
stack = utils.parse_stack(self.t, stack_name=stack_name)
ex = self.assertRaises(exception.StackValidationFailed,
self.create_volume, self.t, stack, 'DataVolume')
self.assertEqual("Property error: "
"Resources.DataVolume.Properties.Tags[0]: "
"Unknown Property Foo", six.text_type(ex))
self.m.VerifyAll()
def test_volume_attachment_error(self):
stack_name = 'test_volume_attach_error_stack'
self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
self._mock_create_server_volume_script(
vt_base.FakeVolume('attaching'), final_status='error')
self.stub_VolumeConstraint_validate()
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
ex = self.assertRaises(exception.ResourceFailure,
self.create_attachment,
self.t, stack, 'MountPoint')
self.assertIn("Volume attachment failed - Unknown status error",
six.text_type(ex))
self.m.VerifyAll()
def test_volume_attachment(self):
stack_name = 'test_volume_attach_stack'
self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
fva = self._mock_create_server_volume_script(
vt_base.FakeVolume('attaching'))
self.stub_VolumeConstraint_validate()
# delete script
fva = vt_base.FakeVolume('in-use')
self.fc.volumes.get_server_volume(u'WikiDatabase',
'vol-123').AndReturn(fva)
self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
self.fc.volumes.delete_server_volume(
'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('detaching', id=fva.id))
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('available', id=fva.id))
self.fc.volumes.get_server_volume(u'WikiDatabase',
'vol-123').AndReturn(fva)
self.fc.volumes.get_server_volume(
u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
scheduler.TaskRunner(rsrc.delete)()
self.m.VerifyAll()
def test_volume_detachment_err(self):
stack_name = 'test_volume_detach_err_stack'
self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
fva = self._mock_create_server_volume_script(
vt_base.FakeVolume('attaching'))
self.stub_VolumeConstraint_validate()
# delete script
fva = vt_base.FakeVolume('in-use')
self.fc.volumes.get_server_volume(u'WikiDatabase',
'vol-123').AndReturn(fva)
self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
self.fc.volumes.delete_server_volume(
'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception(400))
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('available', id=fva.id))
self.fc.volumes.get_server_volume(u'WikiDatabase',
'vol-123').AndReturn(fva)
self.fc.volumes.get_server_volume(
u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
scheduler.TaskRunner(rsrc.delete)()
self.m.VerifyAll()
def test_volume_detach_non_exist(self):
fv = vt_base.FakeVolume('creating')
fva = vt_base.FakeVolume('in-use')
stack_name = 'test_volume_detach_nonexist_stack'
self._mock_create_volume(fv, stack_name)
self._mock_create_server_volume_script(fva)
self.stub_VolumeConstraint_validate()
# delete script
self.fc.volumes.delete_server_volume(u'WikiDatabase',
'vol-123').AndReturn(None)
self.cinder_fc.volumes.get(fva.id).AndRaise(
cinder_exp.NotFound('Not found'))
self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123'
).AndRaise(
fakes_nova.fake_exception())
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
scheduler.TaskRunner(rsrc.delete)()
self.m.VerifyAll()
def test_volume_detach_deleting_volume(self):
fv = vt_base.FakeVolume('creating')
fva = vt_base.FakeVolume('deleting')
stack_name = 'test_volume_detach_deleting_volume_stack'
self._mock_create_volume(fv, stack_name)
self._mock_create_server_volume_script(fva)
self.stub_VolumeConstraint_validate()
# delete script
self.fc.volumes.delete_server_volume(u'WikiDatabase',
'vol-123').AndReturn(None)
self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
self.fc.volumes.get_server_volume(u'WikiDatabase', 'vol-123'
).AndRaise(
fakes_nova.fake_exception())
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
scheduler.TaskRunner(rsrc.delete)()
self.m.VerifyAll()
def test_volume_detach_with_latency(self):
stack_name = 'test_volume_detach_latency_stack'
self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
fva = self._mock_create_server_volume_script(
vt_base.FakeVolume('attaching'))
self.stub_VolumeConstraint_validate()
# delete script
self.fc.volumes.get_server_volume(u'WikiDatabase',
'vol-123').AndReturn(fva)
self.cinder_fc.volumes.get(fva.id).AndReturn(fva)
self.fc.volumes.delete_server_volume(
'WikiDatabase', 'vol-123').MultipleTimes().AndReturn(None)
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('in-use', id=fva.id))
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('detaching', id=fva.id))
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('available', id=fva.id))
self.fc.volumes.get_server_volume(u'WikiDatabase',
'vol-123').AndReturn(fva)
self.fc.volumes.get_server_volume(
u'WikiDatabase', 'vol-123').AndRaise(fakes_nova.fake_exception())
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
scheduler.TaskRunner(rsrc.delete)()
self.m.VerifyAll()
def test_volume_detach_with_error(self):
stack_name = 'test_volume_detach_werr_stack'
self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
fva = self._mock_create_server_volume_script(
vt_base.FakeVolume('attaching'))
self.stub_VolumeConstraint_validate()
# delete script
fva = vt_base.FakeVolume('in-use')
self.fc.volumes.delete_server_volume(
'WikiDatabase', 'vol-123').AndReturn(None)
self.cinder_fc.volumes.get(fva.id).AndReturn(
vt_base.FakeVolume('error', id=fva.id))
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
detach_task = scheduler.TaskRunner(rsrc.delete)
ex = self.assertRaises(exception.ResourceFailure, detach_task)
self.assertIn('Volume detachment failed - Unknown status error',
six.text_type(ex))
self.m.VerifyAll()
def test_volume_delete(self):
stack_name = 'test_volume_delete_stack'
fv = vt_base.FakeVolume('creating')
self._mock_create_volume(fv, stack_name)
self.m.ReplayAll()
self.t['Resources']['DataVolume']['DeletionPolicy'] = 'Delete'
stack = utils.parse_stack(self.t, stack_name=stack_name)
rsrc = self.create_volume(self.t, stack, 'DataVolume')
self.m.StubOutWithMock(rsrc, "handle_delete")
rsrc.handle_delete().AndReturn(None)
self.m.StubOutWithMock(rsrc, "check_delete_complete")
rsrc.check_delete_complete(None).AndReturn(True)
self.m.ReplayAll()
scheduler.TaskRunner(rsrc.destroy)()
self.m.VerifyAll()
def test_volume_deleting_delete(self):
fv = vt_base.FakeVolume('creating')
stack_name = 'test_volume_deleting_stack'
fv = self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
self.cinder_fc.volumes.get(fv.id).AndReturn(
vt_base.FakeVolume('deleting'))
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
rsrc = self.create_volume(self.t, stack, 'DataVolume')
scheduler.TaskRunner(rsrc.destroy)()
self.m.VerifyAll()
def test_volume_update_not_supported(self):
stack_name = 'test_volume_updnotsup_stack'
fv = vt_base.FakeVolume('creating')
self._mock_create_volume(fv, stack_name)
self.m.ReplayAll()
t = template_format.parse(volume_template)
stack = utils.parse_stack(t, stack_name=stack_name)
rsrc = self.create_volume(t, stack, 'DataVolume')
props = copy.deepcopy(rsrc.properties.data)
props['Size'] = 2
props['Tags'] = None
props['AvailabilityZone'] = 'other'
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
updater = scheduler.TaskRunner(rsrc.update, after)
ex = self.assertRaises(exception.ResourceFailure, updater)
self.assertIn("NotSupported: resources.DataVolume: "
"Update to properties "
"AvailabilityZone, Size, Tags of DataVolume "
"(AWS::EC2::Volume) is not supported",
six.text_type(ex))
self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state)
def test_volume_check(self):
stack = utils.parse_stack(self.t, stack_name='volume_check')
res = stack['DataVolume']
fake_volume = vt_base.FakeVolume('available')
cinder = mock.Mock()
cinder.volumes.get.return_value = fake_volume
self.patchobject(res, 'client', return_value=cinder)
scheduler.TaskRunner(res.check)()
self.assertEqual((res.CHECK, res.COMPLETE), res.state)
fake_volume = vt_base.FakeVolume('in-use')
res.client().volumes.get.return_value = fake_volume
scheduler.TaskRunner(res.check)()
self.assertEqual((res.CHECK, res.COMPLETE), res.state)
def test_volume_check_not_available(self):
stack = utils.parse_stack(self.t, stack_name='volume_check_na')
res = stack['DataVolume']
cinder = mock.Mock()
fake_volume = vt_base.FakeVolume('foobar')
cinder.volumes.get.return_value = fake_volume
self.patchobject(res, 'client', return_value=cinder)
self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(res.check))
self.assertEqual((res.CHECK, res.FAILED), res.state)
self.assertIn('foobar', res.status_reason)
def test_volume_check_fail(self):
stack = utils.parse_stack(self.t, stack_name='volume_check_fail')
res = stack['DataVolume']
cinder = mock.Mock()
cinder.volumes.get.side_effect = Exception('boom')
self.patchobject(res, 'client', return_value=cinder)
self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(res.check))
self.assertEqual((res.CHECK, res.FAILED), res.state)
self.assertIn('boom', res.status_reason)
def test_snapshot(self):
stack_name = 'test_volume_snapshot_stack'
fv = self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
# snapshot script
self.m.StubOutWithMock(self.cinder_fc.backups, 'create')
self.m.StubOutWithMock(self.cinder_fc.backups, 'get')
fb = vt_base.FakeBackup('available')
self.cinder_fc.backups.create(fv.id).AndReturn(fb)
self.cinder_fc.backups.get(fb.id).AndReturn(fb)
self.cinder_fc.volumes.get(fv.id).AndReturn(fv)
self._mock_delete_volume(fv)
self.m.ReplayAll()
self.t['Resources']['DataVolume']['DeletionPolicy'] = 'Snapshot'
stack = utils.parse_stack(self.t, stack_name=stack_name)
rsrc = self.create_volume(self.t, stack, 'DataVolume')
scheduler.TaskRunner(rsrc.destroy)()
self.m.VerifyAll()
def test_snapshot_error(self):
stack_name = 'test_volume_snapshot_err_stack'
fv = self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name)
# snapshot script
self.m.StubOutWithMock(self.cinder_fc.backups, 'create')
self.m.StubOutWithMock(self.cinder_fc.backups, 'get')
fb = vt_base.FakeBackup('error')
self.cinder_fc.backups.create(fv.id).AndReturn(fb)
self.cinder_fc.backups.get(fb.id).AndReturn(fb)
self.m.ReplayAll()
self.t['Resources']['DataVolume']['DeletionPolicy'] = 'Snapshot'
stack = utils.parse_stack(self.t, stack_name=stack_name)
rsrc = self.create_volume(self.t, stack, 'DataVolume')
ex = self.assertRaises(exception.ResourceFailure,
scheduler.TaskRunner(rsrc.destroy))
self.assertIn('Unknown status error', six.text_type(ex))
self.m.VerifyAll()
def test_snapshot_no_volume(self):
"""Test that backup does not start for failed resource."""
stack_name = 'test_volume_snapshot_novol_stack'
cfg.CONF.set_override('action_retry_limit', 0)
fv = self._mock_create_volume(vt_base.FakeVolume('creating'),
stack_name,
final_status='error')
self._mock_delete_volume(fv)
self.m.ReplayAll()
self.t['Resources']['DataVolume']['DeletionPolicy'] = 'Snapshot'
self.t['Resources']['DataVolume']['Properties'][
'AvailabilityZone'] = 'nova'
stack = utils.parse_stack(self.t, stack_name=stack_name)
resource_defns = stack.t.resource_definitions(stack)
rsrc = aws_vol.Volume('DataVolume',
resource_defns['DataVolume'],
stack)
create = scheduler.TaskRunner(rsrc.create)
ex = self.assertRaises(exception.ResourceFailure, create)
self.assertIn('Went to status error due to "Unknown"',
six.text_type(ex))
scheduler.TaskRunner(rsrc.destroy)()
self.m.VerifyAll()
def test_create_from_snapshot(self):
stack_name = 'test_volume_create_from_snapshot_stack'
fv = vt_base.FakeVolume('restoring-backup')
fvbr = vt_base.FakeBackupRestore('vol-123')
# create script
cinder.CinderClientPlugin._create().AndReturn(
self.cinder_fc)
self.patchobject(self.cinder_fc.backups, 'get')
self.m.StubOutWithMock(self.cinder_fc.restores, 'restore')
self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr)
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
vol_name = utils.PhysName(stack_name, 'DataVolume')
self.cinder_fc.volumes.update('vol-123',
description=vol_name, name=vol_name)
fv.status = 'available'
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
self.m.ReplayAll()
self.t['Resources']['DataVolume']['Properties'][
'SnapshotId'] = 'backup-123'
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
self.m.VerifyAll()
def test_create_from_snapshot_error(self):
stack_name = 'test_volume_create_from_snap_err_stack'
cfg.CONF.set_override('action_retry_limit', 0)
fv = vt_base.FakeVolume('restoring-backup')
fvbr = vt_base.FakeBackupRestore('vol-123')
# create script
cinder.CinderClientPlugin._create().AndReturn(
self.cinder_fc)
self.patchobject(self.cinder_fc.backups, 'get')
self.m.StubOutWithMock(self.cinder_fc.restores, 'restore')
self.cinder_fc.restores.restore('backup-123').AndReturn(fvbr)
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
vol_name = utils.PhysName(stack_name, 'DataVolume')
self.cinder_fc.volumes.update(fv.id,
description=vol_name, name=vol_name)
fv.status = 'error'
self.cinder_fc.volumes.get('vol-123').AndReturn(fv)
self.m.ReplayAll()
self.t['Resources']['DataVolume']['Properties'][
'SnapshotId'] = 'backup-123'
stack = utils.parse_stack(self.t, stack_name=stack_name)
ex = self.assertRaises(exception.ResourceFailure,
self.create_volume, self.t, stack, 'DataVolume')
self.assertIn('Went to status error due to "Unknown"',
six.text_type(ex))
self.m.VerifyAll()
def test_volume_size_constraint(self):
self.t['Resources']['DataVolume']['Properties']['Size'] = '0'
stack = utils.parse_stack(self.t)
error = self.assertRaises(exception.StackValidationFailed,
self.create_volume,
self.t, stack, 'DataVolume')
self.assertEqual(
"Property error: Resources.DataVolume.Properties.Size: "
"0 is out of range (min: 1, max: None)", six.text_type(error))
def test_volume_attachment_updates_not_supported(self):
self.m.StubOutWithMock(nova.NovaClientPlugin, 'get_server')
nova.NovaClientPlugin.get_server(mox.IgnoreArg()).AndReturn(
mox.MockAnything())
fv = vt_base.FakeVolume('creating')
fva = vt_base.FakeVolume('attaching')
stack_name = 'test_volume_attach_updnotsup_stack'
self._mock_create_volume(fv, stack_name)
self._mock_create_server_volume_script(fva)
self.stub_VolumeConstraint_validate()
self.m.ReplayAll()
stack = utils.parse_stack(self.t, stack_name=stack_name)
self.create_volume(self.t, stack, 'DataVolume')
rsrc = self.create_attachment(self.t, stack, 'MountPoint')
props = copy.deepcopy(rsrc.properties.data)
props['InstanceId'] = 'some_other_instance_id'
props['VolumeId'] = 'some_other_volume_id'
props['Device'] = '/dev/vdz'
after = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
update_task = scheduler.TaskRunner(rsrc.update, after)
ex = self.assertRaises(exception.ResourceFailure, update_task)
self.assertIn('NotSupported: resources.MountPoint: '
'Update to properties Device, InstanceId, '
'VolumeId of MountPoint (AWS::EC2::VolumeAttachment)',
six.text_type(ex))
self.assertEqual((rsrc.UPDATE, rsrc.FAILED), rsrc.state)
self.m.VerifyAll()
|
apache-2.0
|
[
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
199,
504,
13069,
1258,
492,
4967,
465,
13069,
63,
1474,
199,
646,
1683,
199,
646,
18610,
199,
504,
11258,
63,
888,
492,
4810,
199,
646,
3816,
199,
199,
504,
20408,
14,
2330,
492,
1919,
199,
504,
20408,
14,
2330,
492,
1978,
63,
908,
199,
504,
20408,
14,
3908,
14,
14555,
14,
736,
492,
13069,
199,
504,
20408,
14,
3908,
14,
14555,
14,
736,
492,
5913,
199,
504,
20408,
14,
3908,
14,
4435,
14,
7231,
14,
825,
18,
492,
1256,
199,
504,
20408,
14,
3908,
14,
4435,
14,
7231,
14,
825,
18,
492,
3301,
465,
11488,
63,
5650,
199,
504,
20408,
14,
3908,
492,
519,
2164,
63,
27950,
199,
504,
20408,
14,
3908,
492,
11899,
199,
504,
20408,
14,
2219,
14,
12372,
492,
511,
63,
2405,
63,
1208,
465,
18585,
63,
1095,
199,
504,
20408,
14,
2219,
14,
6765,
492,
14063,
465,
14063,
63,
6765,
199,
504,
20408,
14,
2219,
492,
3778,
421,
199,
2405,
63,
1160,
275,
1449,
199,
91,
523,
298,
15088,
840,
3051,
3484,
3353,
2,
520,
298,
6542,
13,
1643,
13,
1643,
401,
523,
298,
5831,
2,
520,
298,
6464,
1379,
401,
523,
298,
5976,
2,
520,
5479,
523,
298,
13745,
2,
520,
469,
272,
298,
26198,
7243,
582,
469,
489,
298,
804,
582,
298,
13226,
447,
4220,
18,
447,
3244,
401,
489,
298,
8516,
582,
469,
267,
298,
3491,
1304,
2,
520,
298,
1421,
401,
267,
298,
3244,
804,
2,
257,
520,
298,
77,
17,
14,
9629,
401,
267,
298,
1197,
985,
2,
263,
520,
298,
396,
401,
267,
298,
1899,
1451,
2,
755,
520,
298,
3972,
666,
2,
489,
789,
272,
1660,
272,
298,
1451,
6464,
2,
520,
469,
489,
298,
804,
2,
520,
298,
13226,
447,
4220,
18,
447,
6464,
401,
489,
298,
8516,
2,
520,
469,
267,
298,
2320,
2,
520,
298,
17,
401,
267,
298,
26462,
11860,
2,
520,
2420,
9656,
447,
1002,
1271,
84,
582,
2097,
26198,
7243,
401,
6163,
298,
26462,
11860,
19057,
267,
298,
9440,
2,
520,
8910,
298,
1197,
2,
520,
298,
7692,
401,
298,
1110,
2,
520,
298,
26198,
3918,
15018,
2,
14877,
489,
789,
272,
1660,
272,
298,
24467,
3428,
2,
520,
469,
489,
298,
804,
2,
520,
298,
13226,
447,
4220,
18,
447,
6464,
22662,
401,
489,
298,
8516,
2,
520,
469,
267,
298,
3244,
1304,
2,
520,
469,
298,
2891,
2,
520,
298,
26198,
7243,
2,
1660,
267,
298,
6464,
1304,
2,
221,
520,
469,
298,
2891,
2,
520,
298,
1451,
6464,
2,
1660,
267,
298,
2510,
2,
520,
3286,
2374,
15,
86,
3833,
2,
489,
789,
272,
789,
523,
789,
199,
93,
199,
2344,
421,
199,
533,
15018,
774,
8,
5941,
63,
1095,
14,
1563,
6464,
774,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
6464,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
84,
275,
1978,
63,
908,
14,
1122,
8,
2405,
63,
1160,
9,
267,
291,
14,
1180,
63,
12372,
275,
756,
339,
347,
485,
1805,
63,
981,
63,
2405,
8,
277,
12,
289,
86,
12,
3464,
63,
354,
12,
4242,
63,
1205,
534,
4561,
735,
267,
13069,
14,
35,
5755,
3041,
5061,
423,
981,
1252,
8433,
17687,
1252,
8572,
8,
288,
291,
14,
12372,
63,
3003,
9,
267,
5236,
63,
354,
275,
3778,
14,
5663,
588,
985,
8,
2340,
63,
354,
12,
283,
1451,
6464,
358,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
981,
8,
288,
1568,
29,
17,
12,
14962,
63,
2619,
534,
6765,
297,
288,
1369,
29,
5650,
63,
354,
12,
288,
536,
29,
5650,
63,
354,
12,
288,
3341,
3126,
85,
7,
7692,
356,
399,
7,
26198,
3918,
15018,
936,
680,
8572,
8,
355,
18585,
63,
1095,
14,
8249,
6464,
8,
13692,
430,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
362,
8,
13692,
14,
344,
680,
8572,
8,
13692,
9,
267,
289,
86,
63,
2179,
275,
18585,
63,
1095,
14,
8249,
6464,
8,
5094,
63,
1205,
12,
1305,
29,
13692,
14,
344,
9,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
362,
8,
13692,
14,
344,
680,
8572,
8,
13692,
63,
2179,
9,
267,
372,
289,
86,
63,
2179,
339,
347,
511,
63,
2405,
8,
277,
304,
267,
3464,
63,
354,
275,
283,
396,
63,
2405,
63,
981,
63,
2340,
7,
398,
327,
1218,
2884,
267,
289,
86,
275,
291,
423,
1805,
63,
981,
63,
2405,
8,
5941,
63,
1095,
14,
8249,
6464,
360,
20358,
659,
4228,
3464,
63,
354,
9,
267,
327,
3405,
3145,
7037,
370,
315,
13,
1180,
2884,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
362,
8,
13692,
14,
344,
680,
8572,
8,
288,
18585,
63,
1095,
14,
8249,
6464,
360,
262,
13,
1180,
1333,
267,
327,
3145,
2884,
267,
291,
423,
1805,
63,
1807,
63,
2405,
8,
13692,
9,
398,
291,
14,
77,
14,
12982,
342,
398,
3464,
275,
3778,
14,
1122,
63,
2340,
8,
277,
14,
84,
12,
3464,
63,
354,
29,
2340,
63,
354,
9,
398,
519,
2164,
275,
291,
14,
981,
63,
2405,
8,
277,
14,
84,
12,
3464,
12,
283,
1451,
6464,
358,
398,
444,
275,
291,
14,
1855,
8,
1971,
14,
4031,
6782,
12,
3044,
11899,
14,
4476,
7446,
8,
30842,
14,
7237,
430,
267,
291,
14,
4080,
480,
6464,
315,
675,
401,
3816,
14,
505,
63,
466,
8,
476,
430,
398,
11899,
14,
4476,
7446,
8,
30842,
14
] |
[
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
199,
504,
13069,
1258,
492,
4967,
465,
13069,
63,
1474,
199,
646,
1683,
199,
646,
18610,
199,
504,
11258,
63,
888,
492,
4810,
199,
646,
3816,
199,
199,
504,
20408,
14,
2330,
492,
1919,
199,
504,
20408,
14,
2330,
492,
1978,
63,
908,
199,
504,
20408,
14,
3908,
14,
14555,
14,
736,
492,
13069,
199,
504,
20408,
14,
3908,
14,
14555,
14,
736,
492,
5913,
199,
504,
20408,
14,
3908,
14,
4435,
14,
7231,
14,
825,
18,
492,
1256,
199,
504,
20408,
14,
3908,
14,
4435,
14,
7231,
14,
825,
18,
492,
3301,
465,
11488,
63,
5650,
199,
504,
20408,
14,
3908,
492,
519,
2164,
63,
27950,
199,
504,
20408,
14,
3908,
492,
11899,
199,
504,
20408,
14,
2219,
14,
12372,
492,
511,
63,
2405,
63,
1208,
465,
18585,
63,
1095,
199,
504,
20408,
14,
2219,
14,
6765,
492,
14063,
465,
14063,
63,
6765,
199,
504,
20408,
14,
2219,
492,
3778,
421,
199,
2405,
63,
1160,
275,
1449,
199,
91,
523,
298,
15088,
840,
3051,
3484,
3353,
2,
520,
298,
6542,
13,
1643,
13,
1643,
401,
523,
298,
5831,
2,
520,
298,
6464,
1379,
401,
523,
298,
5976,
2,
520,
5479,
523,
298,
13745,
2,
520,
469,
272,
298,
26198,
7243,
582,
469,
489,
298,
804,
582,
298,
13226,
447,
4220,
18,
447,
3244,
401,
489,
298,
8516,
582,
469,
267,
298,
3491,
1304,
2,
520,
298,
1421,
401,
267,
298,
3244,
804,
2,
257,
520,
298,
77,
17,
14,
9629,
401,
267,
298,
1197,
985,
2,
263,
520,
298,
396,
401,
267,
298,
1899,
1451,
2,
755,
520,
298,
3972,
666,
2,
489,
789,
272,
1660,
272,
298,
1451,
6464,
2,
520,
469,
489,
298,
804,
2,
520,
298,
13226,
447,
4220,
18,
447,
6464,
401,
489,
298,
8516,
2,
520,
469,
267,
298,
2320,
2,
520,
298,
17,
401,
267,
298,
26462,
11860,
2,
520,
2420,
9656,
447,
1002,
1271,
84,
582,
2097,
26198,
7243,
401,
6163,
298,
26462,
11860,
19057,
267,
298,
9440,
2,
520,
8910,
298,
1197,
2,
520,
298,
7692,
401,
298,
1110,
2,
520,
298,
26198,
3918,
15018,
2,
14877,
489,
789,
272,
1660,
272,
298,
24467,
3428,
2,
520,
469,
489,
298,
804,
2,
520,
298,
13226,
447,
4220,
18,
447,
6464,
22662,
401,
489,
298,
8516,
2,
520,
469,
267,
298,
3244,
1304,
2,
520,
469,
298,
2891,
2,
520,
298,
26198,
7243,
2,
1660,
267,
298,
6464,
1304,
2,
221,
520,
469,
298,
2891,
2,
520,
298,
1451,
6464,
2,
1660,
267,
298,
2510,
2,
520,
3286,
2374,
15,
86,
3833,
2,
489,
789,
272,
789,
523,
789,
199,
93,
199,
2344,
421,
199,
533,
15018,
774,
8,
5941,
63,
1095,
14,
1563,
6464,
774,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
6464,
774,
12,
291,
680,
5996,
342,
267,
291,
14,
84,
275,
1978,
63,
908,
14,
1122,
8,
2405,
63,
1160,
9,
267,
291,
14,
1180,
63,
12372,
275,
756,
339,
347,
485,
1805,
63,
981,
63,
2405,
8,
277,
12,
289,
86,
12,
3464,
63,
354,
12,
4242,
63,
1205,
534,
4561,
735,
267,
13069,
14,
35,
5755,
3041,
5061,
423,
981,
1252,
8433,
17687,
1252,
8572,
8,
288,
291,
14,
12372,
63,
3003,
9,
267,
5236,
63,
354,
275,
3778,
14,
5663,
588,
985,
8,
2340,
63,
354,
12,
283,
1451,
6464,
358,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
981,
8,
288,
1568,
29,
17,
12,
14962,
63,
2619,
534,
6765,
297,
288,
1369,
29,
5650,
63,
354,
12,
288,
536,
29,
5650,
63,
354,
12,
288,
3341,
3126,
85,
7,
7692,
356,
399,
7,
26198,
3918,
15018,
936,
680,
8572,
8,
355,
18585,
63,
1095,
14,
8249,
6464,
8,
13692,
430,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
362,
8,
13692,
14,
344,
680,
8572,
8,
13692,
9,
267,
289,
86,
63,
2179,
275,
18585,
63,
1095,
14,
8249,
6464,
8,
5094,
63,
1205,
12,
1305,
29,
13692,
14,
344,
9,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
362,
8,
13692,
14,
344,
680,
8572,
8,
13692,
63,
2179,
9,
267,
372,
289,
86,
63,
2179,
339,
347,
511,
63,
2405,
8,
277,
304,
267,
3464,
63,
354,
275,
283,
396,
63,
2405,
63,
981,
63,
2340,
7,
398,
327,
1218,
2884,
267,
289,
86,
275,
291,
423,
1805,
63,
981,
63,
2405,
8,
5941,
63,
1095,
14,
8249,
6464,
360,
20358,
659,
4228,
3464,
63,
354,
9,
267,
327,
3405,
3145,
7037,
370,
315,
13,
1180,
2884,
267,
291,
14,
12372,
63,
3003,
14,
8838,
14,
362,
8,
13692,
14,
344,
680,
8572,
8,
288,
18585,
63,
1095,
14,
8249,
6464,
360,
262,
13,
1180,
1333,
267,
327,
3145,
2884,
267,
291,
423,
1805,
63,
1807,
63,
2405,
8,
13692,
9,
398,
291,
14,
77,
14,
12982,
342,
398,
3464,
275,
3778,
14,
1122,
63,
2340,
8,
277,
14,
84,
12,
3464,
63,
354,
29,
2340,
63,
354,
9,
398,
519,
2164,
275,
291,
14,
981,
63,
2405,
8,
277,
14,
84,
12,
3464,
12,
283,
1451,
6464,
358,
398,
444,
275,
291,
14,
1855,
8,
1971,
14,
4031,
6782,
12,
3044,
11899,
14,
4476,
7446,
8,
30842,
14,
7237,
430,
267,
291,
14,
4080,
480,
6464,
315,
675,
401,
3816,
14,
505,
63,
466,
8,
476,
430,
398,
11899,
14,
4476,
7446,
8,
30842,
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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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
] |
steedos/odoo7
|
openerp/addons/warning/__openerp__.py
|
63
|
1680
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Warning Messages and Alerts',
'version': '1.0',
'category': 'Tools',
'description': """
Module to trigger warnings in OpenERP objects.
==============================================
Warning messages can be displayed for objects like sale order, purchase order,
picking and invoice. The message is triggered by the form's onchange event.
""",
'author': 'OpenERP SA',
'depends': ['base', 'sale', 'purchase'],
'data': ['warning_view.xml'],
'demo': [],
'installable': True,
'auto_install': False,
'images': ['images/customers_warnings.jpeg','images/sale_order_warning.jpeg'],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
3849,
27377,
436,
437,
16676,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
2377,
370,
6804,
3598,
315,
7653,
2251,
14,
199,
2486,
17224,
199,
199,
3849,
3788,
883,
506,
9080,
367,
2251,
2839,
13590,
1865,
12,
15932,
1865,
12,
199,
11463,
436,
8485,
14,
710,
1245,
365,
15572,
701,
314,
1824,
1159,
20258,
1566,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
1095,
297,
283,
8515,
297,
283,
9533,
995,
272,
283,
576,
356,
788,
3764,
63,
1345,
14,
1652,
995,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
4782,
356,
788,
4782,
15,
67,
28078,
63,
5451,
14,
14230,
1673,
4782,
15,
8515,
63,
1648,
63,
3764,
14,
14230,
995,
199,
93,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
3849,
27377,
436,
437,
16676,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
2377,
370,
6804,
3598,
315,
7653,
2251,
14,
199,
2486,
17224,
199,
199,
3849,
3788,
883,
506,
9080,
367,
2251,
2839,
13590,
1865,
12,
15932,
1865,
12,
199,
11463,
436,
8485,
14,
710,
1245,
365,
15572,
701,
314,
1824,
1159,
20258,
1566,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
1095,
297,
283,
8515,
297,
283,
9533,
995,
272,
283,
576,
356,
788,
3764,
63,
1345,
14,
1652,
995,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
4782,
356,
788,
4782,
15,
67,
28078,
63,
5451,
14,
14230,
1673,
4782,
15,
8515,
63,
1648,
63,
3764,
14,
14230,
995,
199,
93,
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,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mhlechner/psi4
|
psi4/share/psi4/fsapt/copy_pymol.py
|
3
|
1373
|
#!/usr/bin/env python
#
# @BEGIN LICENSE
#
# Psi4: an open-source quantum chemistry software package
#
# Copyright (c) 2007-2017 The Psi4 Developers.
#
# The copyrights for code used from other parties are included in
# the corresponding files.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# @END LICENSE
#
import sys, os
root = os.path.dirname(os.path.realpath(__file__))
# => Driver Code <= #
if __name__ == '__main__':
# > Working Dirname < #
if len(sys.argv) == 1:
dirname = '.'
elif len(sys.argv) == 2:
dirname = sys.argv[1]
else:
raise Exception('Usage: fsapt.py [dirname]')
# > Copy Files < #
os.system('cp %s/pymol/*pymol %s' % (root, dirname))
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
199,
3,
768,
15947,
5113,
199,
3,
199,
3,
510,
338,
20,
26,
376,
1551,
13,
1365,
15381,
453,
17546,
2664,
27723,
2032,
2559,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
13,
10680,
710,
510,
338,
20,
23493,
14,
199,
3,
199,
3,
710,
4248,
83,
367,
1233,
1202,
687,
1163,
623,
1417,
787,
5120,
315,
199,
3,
314,
5226,
1584,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
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,
3180,
199,
3,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
768,
3902,
5113,
199,
3,
199,
199,
646,
984,
12,
747,
199,
199,
1231,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
199,
199,
3,
9265,
19447,
5495,
2695,
327,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
327,
690,
9361,
316,
25866,
354,
665,
327,
339,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
26,
267,
9017,
275,
7815,
272,
916,
822,
8,
1274,
14,
3020,
9,
508,
499,
26,
267,
9017,
275,
984,
14,
3020,
59,
17,
61,
272,
587,
26,
267,
746,
2186,
360,
7692,
26,
7449,
6182,
14,
647,
359,
3475,
10374,
339,
327,
690,
11247,
16920,
665,
327,
339,
747,
14,
2253,
360,
1850,
450,
83,
15,
647,
16924,
6331,
647,
16924,
450,
83,
7,
450,
334,
1231,
12,
9017,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
199,
3,
768,
15947,
5113,
199,
3,
199,
3,
510,
338,
20,
26,
376,
1551,
13,
1365,
15381,
453,
17546,
2664,
27723,
2032,
2559,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
13,
10680,
710,
510,
338,
20,
23493,
14,
199,
3,
199,
3,
710,
4248,
83,
367,
1233,
1202,
687,
1163,
623,
1417,
787,
5120,
315,
199,
3,
314,
5226,
1584,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
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,
3180,
199,
3,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
768,
3902,
5113,
199,
3,
199,
199,
646,
984,
12,
747,
199,
199,
1231,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
199,
199,
3,
9265,
19447,
5495,
2695,
327,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
339,
327,
690,
9361,
316,
25866,
354,
665,
327,
339,
340,
822,
8,
1274,
14,
3020,
9,
508,
413,
26,
267,
9017,
275,
7815,
272,
916,
822,
8,
1274,
14,
3020,
9,
508,
499,
26,
267,
9017,
275,
984,
14,
3020,
59,
17,
61,
272,
587,
26,
267,
746,
2186,
360,
7692,
26,
7449,
6182,
14,
647,
359,
3475,
10374,
339,
327,
690,
11247,
16920,
665,
327,
339,
747,
14,
2253,
360,
1850,
450,
83,
15,
647,
16924,
6331,
647,
16924,
450,
83,
7,
450,
334,
1231,
12,
9017,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ShySec/scrimmage-scoreboard
|
web2py/gluon/contrib/pg8000/six.py
|
31
|
20969
|
"""Utilities for writing code that runs on Python 2 and 3"""
# Copyright (c) 2010-2013 Benjamin Peterson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from __future__ import absolute_import
import operator
import sys
import types
__author__ = "Benjamin Peterson <benjamin@python.org>"
__version__ = "1.4.1"
# Useful for very coarse version differentiation.
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
PRE_26 = PY2 and sys.version_info[1] < 6
IS_JYTHON = sys.platform.lower().count('java') > 0
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
MAXSIZE = sys.maxsize
else:
string_types = basestring, # noqa
integer_types = (int, long) # noqa
class_types = (type, types.ClassType)
text_type = unicode # noqa
binary_type = str
if sys.platform.startswith("java"):
# Jython always uses 32 bits.
MAXSIZE = int((1 << 31) - 1)
else:
# It's possible to have sizeof(long) != sizeof(Py_ssize_t).
class X(object):
def __len__(self):
return 1 << 31
try:
len(X())
except OverflowError:
# 32-bit
MAXSIZE = int((1 << 31) - 1)
else:
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
def _add_doc(func, doc):
"""Add documentation to a function."""
func.__doc__ = doc
def _import_module(name):
"""Import module, returning the module after the last dot."""
__import__(name)
return sys.modules[name]
class _LazyDescr(object):
def __init__(self, name):
self.name = name
def __get__(self, obj, tp):
result = self._resolve()
setattr(obj, self.name, result)
# This is a bit ugly, but it avoids running this again.
delattr(tp, self.name)
return result
class MovedModule(_LazyDescr):
def __init__(self, name, old, new=None):
super(MovedModule, self).__init__(name)
if PY3:
if new is None:
new = name
self.mod = new
else:
self.mod = old
def _resolve(self):
return _import_module(self.mod)
class MovedAttribute(_LazyDescr):
def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None):
super(MovedAttribute, self).__init__(name)
if PY3:
if new_mod is None:
new_mod = name
self.mod = new_mod
if new_attr is None:
if old_attr is None:
new_attr = name
else:
new_attr = old_attr
self.attr = new_attr
else:
self.mod = old_mod
if old_attr is None:
old_attr = name
self.attr = old_attr
def _resolve(self):
module = _import_module(self.mod)
return getattr(module, self.attr)
class _MovedItems(types.ModuleType):
"""Lazy loading of moved objects"""
_moved_attributes = [
MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"),
MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"),
MovedAttribute(
"filterfalse", "itertools", "itertools", "ifilterfalse",
"filterfalse"),
MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"),
MovedAttribute("map", "itertools", "builtins", "imap", "map"),
MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("reload_module", "__builtin__", "imp", "reload"),
MovedAttribute("reduce", "__builtin__", "functools"),
MovedAttribute("StringIO", "StringIO", "io"),
MovedAttribute("UserString", "UserString", "collections"),
MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"),
MovedAttribute("zip", "itertools", "builtins", "izip", "zip"),
MovedAttribute(
"zip_longest", "itertools", "itertools", "izip_longest",
"zip_longest"),
MovedModule("builtins", "__builtin__"),
MovedModule("configparser", "ConfigParser"),
MovedModule("copyreg", "copy_reg"),
MovedModule("http_cookiejar", "cookielib", "http.cookiejar"),
MovedModule("http_cookies", "Cookie", "http.cookies"),
MovedModule("html_entities", "htmlentitydefs", "html.entities"),
MovedModule("html_parser", "HTMLParser", "html.parser"),
MovedModule("http_client", "httplib", "http.client"),
MovedModule(
"email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"),
MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"),
MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"),
MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"),
MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"),
MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"),
MovedModule("cPickle", "cPickle", "pickle"),
MovedModule("queue", "Queue"),
MovedModule("reprlib", "repr"),
MovedModule("socketserver", "SocketServer"),
MovedModule("tkinter", "Tkinter"),
MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"),
MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"),
MovedModule(
"tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"),
MovedModule(
"tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"),
MovedModule("tkinter_tix", "Tix", "tkinter.tix"),
MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"),
MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"),
MovedModule("tkinter_colorchooser", "tkColorChooser",
"tkinter.colorchooser"),
MovedModule("tkinter_commondialog", "tkCommonDialog",
"tkinter.commondialog"),
MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"),
MovedModule("tkinter_font", "tkFont", "tkinter.font"),
MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"),
MovedModule(
"tkinter_tksimpledialog", "tkSimpleDialog", "tkinter.simpledialog"),
MovedModule(
"urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"),
MovedModule(
"urllib_error", __name__ + ".moves.urllib_error", "urllib.error"),
MovedModule(
"urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"),
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"),
MovedModule("winreg", "_winreg"),
]
for attr in _moved_attributes:
setattr(_MovedItems, attr.name, attr)
del attr
moves = sys.modules[__name__ + ".moves"] = _MovedItems(__name__ + ".moves")
class Module_six_moves_urllib_parse(types.ModuleType):
"""Lazy loading of moved objects in six.moves.urllib_parse"""
_urllib_parse_moved_attributes = [
MovedAttribute("ParseResult", "urlparse", "urllib.parse"),
MovedAttribute("parse_qs", "urlparse", "urllib.parse"),
MovedAttribute("parse_qsl", "urlparse", "urllib.parse"),
MovedAttribute("urldefrag", "urlparse", "urllib.parse"),
MovedAttribute("urljoin", "urlparse", "urllib.parse"),
MovedAttribute("urlparse", "urlparse", "urllib.parse"),
MovedAttribute("urlsplit", "urlparse", "urllib.parse"),
MovedAttribute("urlunparse", "urlparse", "urllib.parse"),
MovedAttribute("urlunsplit", "urlparse", "urllib.parse"),
MovedAttribute("quote", "urllib", "urllib.parse"),
MovedAttribute("quote_plus", "urllib", "urllib.parse"),
MovedAttribute("unquote", "urllib", "urllib.parse"),
MovedAttribute("unquote_plus", "urllib", "urllib.parse"),
MovedAttribute("urlencode", "urllib", "urllib.parse"),
]
for attr in _urllib_parse_moved_attributes:
setattr(Module_six_moves_urllib_parse, attr.name, attr)
del attr
sys.modules[__name__ + ".moves.urllib_parse"] = Module_six_moves_urllib_parse(
__name__ + ".moves.urllib_parse")
sys.modules[__name__ + ".moves.urllib.parse"] = Module_six_moves_urllib_parse(
__name__ + ".moves.urllib.parse")
class Module_six_moves_urllib_error(types.ModuleType):
"""Lazy loading of moved objects in six.moves.urllib_error"""
_urllib_error_moved_attributes = [
MovedAttribute("URLError", "urllib2", "urllib.error"),
MovedAttribute("HTTPError", "urllib2", "urllib.error"),
MovedAttribute("ContentTooShortError", "urllib", "urllib.error"),
]
for attr in _urllib_error_moved_attributes:
setattr(Module_six_moves_urllib_error, attr.name, attr)
del attr
sys.modules[__name__ + ".moves.urllib_error"] = Module_six_moves_urllib_error(
__name__ + ".moves.urllib_error")
sys.modules[__name__ + ".moves.urllib.error"] = Module_six_moves_urllib_error(
__name__ + ".moves.urllib.error")
class Module_six_moves_urllib_request(types.ModuleType):
"""Lazy loading of moved objects in six.moves.urllib_request"""
_urllib_request_moved_attributes = [
MovedAttribute("urlopen", "urllib2", "urllib.request"),
MovedAttribute("install_opener", "urllib2", "urllib.request"),
MovedAttribute("build_opener", "urllib2", "urllib.request"),
MovedAttribute("pathname2url", "urllib", "urllib.request"),
MovedAttribute("url2pathname", "urllib", "urllib.request"),
MovedAttribute("getproxies", "urllib", "urllib.request"),
MovedAttribute("Request", "urllib2", "urllib.request"),
MovedAttribute("OpenerDirector", "urllib2", "urllib.request"),
MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"),
MovedAttribute("ProxyHandler", "urllib2", "urllib.request"),
MovedAttribute("BaseHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"),
MovedAttribute(
"HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"),
MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"),
MovedAttribute("FileHandler", "urllib2", "urllib.request"),
MovedAttribute("FTPHandler", "urllib2", "urllib.request"),
MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"),
MovedAttribute("UnknownHandler", "urllib2", "urllib.request"),
MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"),
MovedAttribute("urlretrieve", "urllib", "urllib.request"),
MovedAttribute("urlcleanup", "urllib", "urllib.request"),
MovedAttribute("URLopener", "urllib", "urllib.request"),
MovedAttribute("FancyURLopener", "urllib", "urllib.request"),
]
for attr in _urllib_request_moved_attributes:
setattr(Module_six_moves_urllib_request, attr.name, attr)
del attr
sys.modules[__name__ + ".moves.urllib_request"] = \
Module_six_moves_urllib_request(__name__ + ".moves.urllib_request")
sys.modules[__name__ + ".moves.urllib.request"] = \
Module_six_moves_urllib_request(__name__ + ".moves.urllib.request")
class Module_six_moves_urllib_response(types.ModuleType):
"""Lazy loading of moved objects in six.moves.urllib_response"""
_urllib_response_moved_attributes = [
MovedAttribute("addbase", "urllib", "urllib.response"),
MovedAttribute("addclosehook", "urllib", "urllib.response"),
MovedAttribute("addinfo", "urllib", "urllib.response"),
MovedAttribute("addinfourl", "urllib", "urllib.response"),
]
for attr in _urllib_response_moved_attributes:
setattr(Module_six_moves_urllib_response, attr.name, attr)
del attr
sys.modules[__name__ + ".moves.urllib_response"] = \
Module_six_moves_urllib_response(__name__ + ".moves.urllib_response")
sys.modules[__name__ + ".moves.urllib.response"] = \
Module_six_moves_urllib_response(__name__ + ".moves.urllib.response")
class Module_six_moves_urllib_robotparser(types.ModuleType):
"""Lazy loading of moved objects in six.moves.urllib_robotparser"""
_urllib_robotparser_moved_attributes = [
MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"),
]
for attr in _urllib_robotparser_moved_attributes:
setattr(Module_six_moves_urllib_robotparser, attr.name, attr)
del attr
sys.modules[__name__ + ".moves.urllib_robotparser"] = \
Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib_robotparser")
sys.modules[__name__ + ".moves.urllib.robotparser"] = \
Module_six_moves_urllib_robotparser(
__name__ + ".moves.urllib.robotparser")
class Module_six_moves_urllib(types.ModuleType):
"""Create a six.moves.urllib namespace that resembles the Python 3
namespace"""
parse = sys.modules[__name__ + ".moves.urllib_parse"]
error = sys.modules[__name__ + ".moves.urllib_error"]
request = sys.modules[__name__ + ".moves.urllib_request"]
response = sys.modules[__name__ + ".moves.urllib_response"]
robotparser = sys.modules[__name__ + ".moves.urllib_robotparser"]
sys.modules[__name__ + ".moves.urllib"] = Module_six_moves_urllib(
__name__ + ".moves.urllib")
def add_move(move):
"""Add an item to six.moves."""
setattr(_MovedItems, move.name, move)
def remove_move(name):
"""Remove item from six.moves."""
try:
delattr(_MovedItems, name)
except AttributeError:
try:
del moves.__dict__[name]
except KeyError:
raise AttributeError("no such move, %r" % (name,))
if PY3:
_meth_func = "__func__"
_meth_self = "__self__"
_func_closure = "__closure__"
_func_code = "__code__"
_func_defaults = "__defaults__"
_func_globals = "__globals__"
_iterkeys = "keys"
_itervalues = "values"
_iteritems = "items"
_iterlists = "lists"
else:
_meth_func = "im_func"
_meth_self = "im_self"
_func_closure = "func_closure"
_func_code = "func_code"
_func_defaults = "func_defaults"
_func_globals = "func_globals"
_iterkeys = "iterkeys"
_itervalues = "itervalues"
_iteritems = "iteritems"
_iterlists = "iterlists"
try:
advance_iterator = next
except NameError:
def advance_iterator(it):
return it.next()
next = advance_iterator
try:
callable = callable
except NameError:
def callable(obj):
return any("__call__" in klass.__dict__ for klass in type(obj).__mro__)
if PY3:
def get_unbound_function(unbound):
return unbound
create_bound_method = types.MethodType
Iterator = object
else:
def get_unbound_function(unbound):
return unbound.im_func
def create_bound_method(func, obj):
return types.MethodType(func, obj, obj.__class__)
class Iterator(object):
def next(self):
return type(self).__next__(self)
callable = callable
_add_doc(get_unbound_function,
"""Get the function out of a possibly unbound function""")
get_method_function = operator.attrgetter(_meth_func)
get_method_self = operator.attrgetter(_meth_self)
get_function_closure = operator.attrgetter(_func_closure)
get_function_code = operator.attrgetter(_func_code)
get_function_defaults = operator.attrgetter(_func_defaults)
get_function_globals = operator.attrgetter(_func_globals)
def iterkeys(d, **kw):
"""Return an iterator over the keys of a dictionary."""
return iter(getattr(d, _iterkeys)(**kw))
def itervalues(d, **kw):
"""Return an iterator over the values of a dictionary."""
return iter(getattr(d, _itervalues)(**kw))
def iteritems(d, **kw):
"""Return an iterator over the (key, value) pairs of a dictionary."""
return iter(getattr(d, _iteritems)(**kw))
def iterlists(d, **kw):
"""Return an iterator over the (key, [values]) pairs of a dictionary."""
return iter(getattr(d, _iterlists)(**kw))
if PY3:
def b(s):
return s.encode("latin-1")
def u(s):
return s
unichr = chr
if sys.version_info[1] <= 1:
def int2byte(i):
return bytes((i,))
else:
# This is about 2x faster than the implementation above on 3.2+
int2byte = operator.methodcaller("to_bytes", 1, "big")
byte2int = operator.itemgetter(0)
indexbytes = operator.getitem
iterbytes = iter
import io
StringIO = io.StringIO
BytesIO = io.BytesIO
else:
def b(s):
return s
def u(s):
return unicode(s, "unicode_escape") # noqa
unichr = unichr
int2byte = chr
def byte2int(bs):
return ord(bs[0])
def indexbytes(buf, i):
return ord(buf[i])
def iterbytes(buf):
return (ord(byte) for byte in buf)
import StringIO
StringIO = BytesIO = StringIO.StringIO
_add_doc(b, """Byte literal""")
_add_doc(u, """Text literal""")
if PY3:
import builtins
exec_ = getattr(builtins, "exec")
def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value
print_ = getattr(builtins, "print")
del builtins
else:
def exec_(_code_, _globs_=None, _locs_=None):
"""Execute code in a namespace."""
if _globs_ is None:
frame = sys._getframe(1)
_globs_ = frame.f_globals
if _locs_ is None:
_locs_ = frame.f_locals
del frame
elif _locs_ is None:
_locs_ = _globs_
exec("""exec _code_ in _globs_, _locs_""")
exec_("""def reraise(tp, value, tb=None):
raise tp, value, tb
""")
def print_(*args, **kwargs):
"""The new-style print function."""
fp = kwargs.pop("file", sys.stdout)
if fp is None:
return
def write(data):
if not isinstance(data, basestring): # noqa
data = str(data)
fp.write(data)
want_unicode = False
sep = kwargs.pop("sep", None)
if sep is not None:
if isinstance(sep, unicode): # noqa
want_unicode = True
elif not isinstance(sep, str):
raise TypeError("sep must be None or a string")
end = kwargs.pop("end", None)
if end is not None:
if isinstance(end, unicode): # noqa
want_unicode = True
elif not isinstance(end, str):
raise TypeError("end must be None or a string")
if kwargs:
raise TypeError("invalid keyword arguments to print()")
if not want_unicode:
for arg in args:
if isinstance(arg, unicode): # noqa
want_unicode = True
break
if want_unicode:
newline = unicode("\n") # noqa
space = unicode(" ") # noqa
else:
newline = "\n"
space = " "
if sep is None:
sep = space
if end is None:
end = newline
for i, arg in enumerate(args):
if i:
write(sep)
write(arg)
write(end)
_add_doc(reraise, """Reraise an exception.""")
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
return meta("NewBase", bases, {})
def add_metaclass(metaclass):
"""Class decorator for creating a class with a metaclass."""
def wrapper(cls):
orig_vars = cls.__dict__.copy()
orig_vars.pop('__dict__', None)
orig_vars.pop('__weakref__', None)
for slots_var in orig_vars.get('__slots__', ()):
orig_vars.pop(slots_var)
return metaclass(cls.__name__, cls.__bases__, orig_vars)
return wrapper
|
gpl-2.0
|
[
624,
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
1898,
334,
67,
9,
7129,
13,
6965,
26844,
16997,
262,
22912,
834,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
20,
14,
17,
2,
421,
199,
3,
18491,
367,
7437,
512,
30672,
1015,
26796,
425,
14,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
4225,
63,
1479,
275,
7843,
18,
436,
984,
14,
1023,
63,
815,
59,
17,
61,
665,
1227,
199,
199,
1311,
63,
42,
57,
8472,
275,
984,
14,
3246,
14,
2325,
1252,
835,
360,
6138,
358,
690,
378,
421,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
221,
327,
8151,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
221,
327,
8151,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
221,
327,
8151,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
267,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
683,
12,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
421,
199,
533,
8863,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
63,
1494,
12,
892,
63,
1494,
12,
2269,
63,
962,
29,
403,
12,
892,
63,
962,
29,
403,
304,
267,
1613,
8,
20774,
1646,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
63,
1494,
365,
488,
26,
355,
892,
63,
1494,
275,
536,
288,
291,
14,
1494,
275,
892,
63,
1494,
288,
340,
892,
63,
962,
365,
488,
26,
355,
340,
2269,
63,
962,
365,
488,
26,
490,
892,
63,
962,
275,
536,
355,
587,
26,
490,
892,
63,
962,
275,
2269,
63,
962,
288,
291,
14,
962,
275,
892,
63,
962,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
63,
1494,
288,
340,
2269,
63,
962,
365,
488,
26,
355,
2269,
63,
962,
275,
536,
288,
291,
14,
962,
275,
2269,
63,
962,
339,
347,
485,
6983,
8,
277,
304,
267,
859,
275,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
267,
372,
2519,
8,
578,
12,
291,
14,
962,
9,
421,
199,
533,
485,
20774
] |
[
22905,
367,
3575,
1233,
626,
7858,
641,
2018,
499,
436,
650,
624,
199,
199,
3,
1898,
334,
67,
9,
7129,
13,
6965,
26844,
16997,
262,
22912,
834,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
4182,
199,
646,
984,
199,
646,
2943,
199,
199,
363,
2502,
363,
275,
298,
31231,
16997,
262,
22912,
834,
665,
18486,
16997,
262,
32,
1548,
14,
1308,
4335,
199,
363,
1023,
363,
275,
298,
17,
14,
20,
14,
17,
2,
421,
199,
3,
18491,
367,
7437,
512,
30672,
1015,
26796,
425,
14,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
4225,
63,
1479,
275,
7843,
18,
436,
984,
14,
1023,
63,
815,
59,
17,
61,
665,
1227,
199,
199,
1311,
63,
42,
57,
8472,
275,
984,
14,
3246,
14,
2325,
1252,
835,
360,
6138,
358,
690,
378,
421,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
272,
3000,
63,
1313,
275,
1109,
12,
272,
1021,
63,
1313,
275,
730,
12,
272,
1318,
63,
466,
275,
620,
272,
3366,
63,
466,
275,
2783,
339,
9141,
4305,
275,
984,
14,
13634,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
221,
327,
8151,
272,
3000,
63,
1313,
275,
334,
442,
12,
1846,
9,
221,
327,
8151,
272,
1021,
63,
1313,
275,
334,
466,
12,
2943,
14,
31165,
9,
272,
1318,
63,
466,
275,
2649,
221,
327,
8151,
272,
3366,
63,
466,
275,
620,
339,
340,
984,
14,
3246,
14,
2460,
480,
6138,
2349,
267,
327,
25333,
3544,
4440,
4337,
5821,
14,
267,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
272,
587,
26,
267,
327,
2779,
1159,
3962,
370,
1172,
13855,
8,
2809,
9,
1137,
13855,
8,
2713,
63,
30104,
63,
84,
680,
267,
1021,
1323,
8,
785,
304,
288,
347,
636,
552,
721,
277,
304,
355,
372,
413,
5213,
7105,
267,
862,
26,
288,
822,
8,
56,
1012,
267,
871,
23870,
26,
288,
327,
4337,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
7105,
9,
446,
413,
9,
267,
587,
26,
288,
327,
5049,
13,
2075,
288,
9141,
4305,
275,
1109,
1332,
17,
5213,
13668,
9,
446,
413,
9,
267,
2150,
1323,
421,
199,
318,
485,
525,
63,
1301,
8,
1532,
12,
1382,
304,
272,
408,
1123,
3794,
370,
282,
805,
1041,
272,
2562,
855,
1301,
363,
275,
1382,
421,
199,
318,
485,
646,
63,
578,
8,
354,
304,
272,
408,
6295,
859,
12,
8152,
314,
859,
2410,
314,
2061,
6308,
1041,
272,
636,
646,
721,
354,
9,
272,
372,
984,
14,
3112,
59,
354,
61,
421,
199,
533,
485,
14269,
28782,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
636,
362,
721,
277,
12,
1559,
12,
9253,
304,
267,
754,
275,
291,
423,
6983,
342,
267,
5371,
8,
1113,
12,
291,
14,
354,
12,
754,
9,
267,
327,
961,
365,
282,
4546,
23761,
12,
1325,
652,
23674,
3879,
642,
4020,
14,
267,
24358,
8,
683,
12,
291,
14,
354,
9,
267,
372,
754,
421,
199,
533,
11147,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
12,
892,
29,
403,
304,
267,
1613,
8,
20774,
2377,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
365,
488,
26,
355,
892,
275,
536,
288,
291,
14,
1494,
275,
892,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
339,
347,
485,
6983,
8,
277,
304,
267,
372,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
421,
199,
533,
8863,
1547,
14269,
28782,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2269,
63,
1494,
12,
892,
63,
1494,
12,
2269,
63,
962,
29,
403,
12,
892,
63,
962,
29,
403,
304,
267,
1613,
8,
20774,
1646,
12,
291,
2843,
826,
721,
354,
9,
267,
340,
7843,
19,
26,
288,
340,
892,
63,
1494,
365,
488,
26,
355,
892,
63,
1494,
275,
536,
288,
291,
14,
1494,
275,
892,
63,
1494,
288,
340,
892,
63,
962,
365,
488,
26,
355,
340,
2269,
63,
962,
365,
488,
26,
490,
892,
63,
962,
275,
536,
355,
587,
26,
490,
892,
63,
962,
275,
2269,
63,
962,
288,
291,
14,
962,
275,
892,
63,
962,
267,
587,
26,
288,
291,
14,
1494,
275,
2269,
63,
1494,
288,
340,
2269,
63,
962,
365,
488,
26,
355,
2269,
63,
962,
275,
536,
288,
291,
14,
962,
275,
2269,
63,
962,
339,
347,
485,
6983,
8,
277,
304,
267,
859,
275,
485,
646,
63,
578,
8,
277,
14,
1494,
9,
267,
372,
2519,
8,
578,
12,
291,
14,
962,
9,
421,
199,
533,
485,
20774,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dsbrown/FreeCAD
|
src/Mod/Test/Gui/qtunittest.py
|
29
|
9305
|
# Qt Unit test module
# (c) 2006 Werner Mayer
#
#***************************************************************************
#* (c) Werner Mayer <werner.wm.mayer@gmx.de> 2006 *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#* Werner Mayer 2006 *
#***************************************************************************/
__author__ = "Werner Mayer (werner.wm.mayer@gmx.de)"
import string
import traceback
# Cannot import this file in case Python is not prepared for Tk.
# Copy the needed classes instead.
#import unittestgui
import unittest
import sys
import traceback
import string
##############################################################################
# GUI framework classes
# The classes BaseGUITestRunner, GUITestResult and RollbackImporter are
# taken from the PyUnit framework written by Steve Purcell.
# For more details see also http://pyunit.sourceforge.net.
##############################################################################
class BaseGUITestRunner:
"""Subclass this class to create a GUI TestRunner that uses a specific
windowing toolkit. The class takes care of running tests in the correct
manner, and making callbacks to the derived class to obtain information
or signal that events have occurred.
"""
def __init__(self, *args, **kwargs):
self.currentResult = None
self.running = 0
self.__rollbackImporter = None
apply(self.initGUI, args, kwargs)
def getSelectedTestName(self):
"Override to return the name of the test selected to be run"
pass
def errorDialog(self, title, message):
"Override to display an error arising from GUI usage"
pass
def runClicked(self):
"To be called in response to user choosing to run a test"
if self.running: return
testName = self.getSelectedTestName()
if not testName:
self.errorDialog("Test name entry", "You must enter a test name")
return
if self.__rollbackImporter:
self.__rollbackImporter.rollbackImports()
self.__rollbackImporter = RollbackImporter()
try:
test = unittest.defaultTestLoader.loadTestsFromName(testName)
except:
exc_type, exc_value, exc_tb = sys.exc_info()
apply(traceback.print_exception,sys.exc_info())
self.errorDialog("Unable to run test '%s'" % testName,
"Error loading specified test: %s, %s" % \
(exc_type, exc_value))
return
self.currentResult = GUITestResult(self)
self.totalTests = test.countTestCases()
self.running = 1
self.notifyRunning()
test.run(self.currentResult)
self.running = 0
self.notifyStopped()
def stopClicked(self):
"To be called in response to user stopping the running of a test"
if self.currentResult:
self.currentResult.stop()
# Required callbacks
def notifyRunning(self):
"Override to set GUI in 'running' mode, enabling 'stop' button etc."
pass
def notifyStopped(self):
"Override to set GUI in 'stopped' mode, enabling 'run' button etc."
pass
def notifyTestFailed(self, test, err):
"Override to indicate that a test has just failed"
pass
def notifyTestErrored(self, test, err):
"Override to indicate that a test has just errored"
pass
def notifyTestStarted(self, test):
"Override to indicate that a test is about to run"
pass
def notifyTestFinished(self, test):
"""Override to indicate that a test has finished (it may already have
failed or errored)"""
pass
class GUITestResult(unittest.TestResult):
"""A TestResult that makes callbacks to its associated GUI TestRunner.
Used by BaseGUITestRunner. Need not be created directly.
"""
def __init__(self, callback):
unittest.TestResult.__init__(self)
self.callback = callback
def addError(self, test, err):
unittest.TestResult.addError(self, test, err)
self.callback.notifyTestErrored(test, err)
def addFailure(self, test, err):
unittest.TestResult.addFailure(self, test, err)
self.callback.notifyTestFailed(test, err)
def stopTest(self, test):
unittest.TestResult.stopTest(self, test)
self.callback.notifyTestFinished(test)
def startTest(self, test):
unittest.TestResult.startTest(self, test)
self.callback.notifyTestStarted(test)
class RollbackImporter:
"""This tricky little class is used to make sure that modules under test
will be reloaded the next time they are imported.
"""
def __init__(self):
self.previousModules = sys.modules.copy()
def rollbackImports(self):
for modname in sys.modules.keys():
if not self.previousModules.has_key(modname):
# Force reload when modname next imported
del(sys.modules[modname])
#---------------------------------------------------------------------------
# Subclass of BaseGUITestRunner using Qt dialog
#---------------------------------------------------------------------------
class QtTestRunner(BaseGUITestRunner):
"""An implementation of BaseGUITestRunner using Qt.
"""
def initGUI(self, root, initialTestName):
"""Set up the GUI inside the given root window. The test name entry
field will be pre-filled with the given initialTestName.
"""
self.root = root
# Set up values that will be tied to widgets
import QtUnitGui
self.gui=QtUnitGui.UnitTest()
self.gui.setStatusText("Idle")
self.runCountVar = 0
self.failCountVar = 0
self.errorCountVar = 0
self.remainingCountVar = 0
def getSelectedTestName(self):
return self.gui.getUnitTest()
def errorDialog(self, title, message):
return self.gui.errorDialog(title, message)
def notifyRunning(self):
self.runCountVar=0
self.gui.setRunCount(0)
self.failCountVar=0
self.gui.setFailCount(0)
self.errorCountVar=0
self.gui.setErrorCount(0)
self.remainingCountVar=self.totalTests
self.gui.setRemainCount(self.totalTests)
self.errorInfo = []
self.gui.clearErrorList()
self.gui.setProgressFraction(0.0)
self.gui.updateGUI()
def notifyStopped(self):
self.gui.setStatusText("Idle")
def notifyTestStarted(self, test):
self.gui.setStatusText(str(test))
self.gui.updateGUI()
def notifyTestFailed(self, test, err):
self.failCountVar=self.failCountVar+1
self.gui.setFailCount(self.failCountVar)
tracebackLines = apply(traceback.format_exception, err + (10,))
tracebackText = string.join(tracebackLines,'')
self.gui.insertError("Failure: %s" % test,tracebackText)
self.errorInfo.append((test,err))
def notifyTestErrored(self, test, err):
self.errorCountVar=self.errorCountVar+1
self.gui.setErrorCount(self.errorCountVar)
tracebackLines = apply(traceback.format_exception, err + (10,))
tracebackText = string.join(tracebackLines,'')
self.gui.insertError("Error: %s" % test,tracebackText)
self.errorInfo.append((test,err))
def notifyTestFinished(self, test):
self.remainingCountVar=self.remainingCountVar-1
self.gui.setRemainCount(self.remainingCountVar)
self.runCountVar=self.runCountVar+1
self.gui.setRunCount(self.runCountVar)
fractionDone = float(self.runCountVar)/float(self.totalTests)
fillColor = len(self.errorInfo) and "red" or "green"
self.gui.setProgressFraction(fractionDone, fillColor)
|
lgpl-2.1
|
[
3,
3959,
12008,
511,
859,
199,
3,
334,
67,
9,
8315,
644,
281,
1372,
10162,
281,
199,
3,
199,
199,
3,
17623,
199,
15002,
257,
334,
67,
9,
644,
281,
1372,
10162,
281,
665,
2135,
1372,
14,
16240,
14,
7551,
281,
32,
71,
9457,
14,
271,
30,
8315,
12788,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
570,
365,
1777,
402,
314,
20914,
7240,
88,
16367,
2656,
14,
4519,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
199,
15002,
17997,
627,
199,
15002,
257,
20914,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
3322,
627,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
199,
15002,
257,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8295,
627,
199,
15002,
17997,
627,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
199,
15002,
257,
844,
3180,
543,
20914,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
263,
627,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
199,
15002,
257,
8217,
6208,
257,
627,
199,
15002,
17997,
627,
199,
15002,
257,
644,
281,
1372,
10162,
281,
8315,
2476,
9326,
627,
199,
3,
17623,
15,
199,
199,
363,
2502,
363,
275,
298,
55,
281,
1372,
10162,
281,
334,
2135,
1372,
14,
16240,
14,
7551,
281,
32,
71,
9457,
14,
271,
2924,
199,
199,
646,
1059,
199,
646,
5190,
199,
199,
3,
18435,
492,
642,
570,
315,
1930,
2018,
365,
440,
16318,
367,
12435,
14,
199,
3,
11247,
314,
4346,
3992,
3140,
14,
199,
3,
646,
2882,
5885,
199,
199,
646,
2882,
199,
646,
984,
199,
646,
5190,
199,
646,
1059,
421,
199,
4605,
199,
3,
17160,
10059,
3992,
199,
3,
710,
3992,
3523,
17188,
649,
597,
7446,
12,
598,
28666,
597,
2889,
436,
820,
14385,
894,
18484,
787,
199,
3,
9394,
687,
314,
1611,
5072,
10059,
5313,
701,
17854,
432,
23177,
3890,
14,
199,
3,
2104,
1655,
2436,
1937,
2597,
1455,
921,
647,
3248,
14,
22943,
14,
846,
14,
199,
4605,
199,
199,
533,
3523,
17188,
649,
597,
7446,
26,
272,
408,
23636,
642,
1021,
370,
1218,
282,
17160,
1379,
7446,
626,
4440,
282,
2488,
272,
4353,
316,
4744,
6065,
14,
710,
1021,
6181,
10296,
402,
3879,
2295,
315,
314,
3211,
272,
30800,
12,
436,
10663,
13484,
370,
314,
7131,
1021,
370,
3332,
2556,
272,
503,
4673,
626,
4474,
1172,
8920,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
1818,
2889,
275,
488,
267,
291,
14,
5720,
275,
378,
267,
291,
855,
10437,
18484,
275,
488,
267,
4838,
8,
277,
14,
826,
14438,
12,
1249,
12,
2074,
9,
339,
347,
664,
12461,
774,
985,
8,
277,
304,
267,
298,
11954,
370,
372,
314,
536,
402,
314,
511,
4895,
370,
506,
1255,
2,
267,
986,
339,
347,
1125,
5619,
8,
277,
12,
2538,
12,
1245,
304,
267,
298,
11954,
370,
2929,
376,
1125,
14554,
1044,
687,
17160,
4503,
2,
267,
986,
339,
347,
1255,
31483,
8,
277,
304,
267,
298,
1378,
506,
2797,
315,
1177,
370,
922,
2468,
26056,
370,
1255,
282,
511,
2,
267,
340,
291,
14,
5720,
26,
372,
267,
511,
985,
275,
291,
14,
362,
12461,
774,
985,
342,
267,
340,
440,
511,
985,
26,
288,
291,
14,
705,
5619,
480,
774,
536,
2397,
401,
298,
5556,
1471,
9509,
282,
511,
536,
531,
288,
372,
267,
340,
291,
855,
10437,
18484,
26,
288,
291,
855,
10437,
18484,
14,
10437,
32447,
342,
267,
291,
855,
10437,
18484,
275,
820,
14385,
894,
18484,
342,
267,
862,
26,
288,
511,
275,
2882,
14,
885,
15824,
14,
25998,
8,
396,
985,
9,
267,
871,
26,
288,
3178,
63,
466,
12,
3178,
63,
585,
12,
3178,
63,
5842,
275,
984,
14,
2804,
63,
815,
342,
288,
4838,
8,
6894,
14,
1361,
63,
1971,
12,
1274,
14,
2804,
63,
815,
1012,
288,
291,
14,
705,
5619,
480,
6005,
370,
1255,
511,
1543,
83,
4065,
450,
511,
985,
12,
2490,
298,
547,
8697,
2013,
511,
26,
450,
83,
12,
450,
83,
2,
450,
971,
2490,
334,
2804,
63,
466,
12,
3178,
63,
585,
430,
288,
372,
267,
291,
14,
1818,
2889,
275,
598,
28666,
597,
2889,
8,
277,
9,
267,
291,
14,
2923,
2925,
275,
511,
14,
835,
19346,
342,
267,
291,
14,
5720,
275,
413,
267,
291,
14,
6814,
9602,
342,
267,
511,
14,
1065,
8,
277,
14,
1818,
2889,
9,
267,
291,
14,
5720,
275,
378,
267,
291,
14,
6814,
28500,
342,
339,
347,
3631,
31483,
8,
277,
304,
267,
298,
1378,
506,
2797,
315,
1177,
370,
922,
23599,
314,
3879,
402,
282,
511,
2,
267,
340,
291,
14,
1818,
2889,
26,
288,
291,
14,
1818,
2889,
14,
2379,
342,
339,
327,
11105,
13484,
339,
347,
11705,
9602,
8,
277,
304,
267,
298,
11954,
370,
663,
17160,
315,
283,
5720,
7,
818,
12,
29310,
283,
2379,
7,
5528,
5423,
2122,
267,
986,
339,
347,
11705,
28500,
8,
277,
304,
267,
298,
11954,
370,
663,
17160,
315,
283,
14661,
7,
818,
12,
29310,
283,
1065,
7,
5528,
5423,
2122,
267,
986,
339,
347,
11705,
774,
4276,
8,
277,
12,
511,
12,
2329,
304,
267,
298,
11954,
370,
6623,
626,
282,
511,
965,
2951,
3405,
2,
267,
986,
339,
347,
11705,
774,
539,
20878,
8,
277,
12,
511,
12,
2329,
304,
267,
298,
11954,
370,
6623,
626,
282,
511,
965,
2951,
9266,
20878,
2,
267,
986,
339,
347,
11705,
774,
21031,
8,
277,
12
] |
[
3959,
12008,
511,
859,
199,
3,
334,
67,
9,
8315,
644,
281,
1372,
10162,
281,
199,
3,
199,
199,
3,
17623,
199,
15002,
257,
334,
67,
9,
644,
281,
1372,
10162,
281,
665,
2135,
1372,
14,
16240,
14,
7551,
281,
32,
71,
9457,
14,
271,
30,
8315,
12788,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
570,
365,
1777,
402,
314,
20914,
7240,
88,
16367,
2656,
14,
4519,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
199,
15002,
17997,
627,
199,
15002,
257,
20914,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
3322,
627,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
199,
15002,
257,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8295,
627,
199,
15002,
17997,
627,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
199,
15002,
257,
844,
3180,
543,
20914,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
263,
627,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
199,
15002,
257,
8217,
6208,
257,
627,
199,
15002,
17997,
627,
199,
15002,
257,
644,
281,
1372,
10162,
281,
8315,
2476,
9326,
627,
199,
3,
17623,
15,
199,
199,
363,
2502,
363,
275,
298,
55,
281,
1372,
10162,
281,
334,
2135,
1372,
14,
16240,
14,
7551,
281,
32,
71,
9457,
14,
271,
2924,
199,
199,
646,
1059,
199,
646,
5190,
199,
199,
3,
18435,
492,
642,
570,
315,
1930,
2018,
365,
440,
16318,
367,
12435,
14,
199,
3,
11247,
314,
4346,
3992,
3140,
14,
199,
3,
646,
2882,
5885,
199,
199,
646,
2882,
199,
646,
984,
199,
646,
5190,
199,
646,
1059,
421,
199,
4605,
199,
3,
17160,
10059,
3992,
199,
3,
710,
3992,
3523,
17188,
649,
597,
7446,
12,
598,
28666,
597,
2889,
436,
820,
14385,
894,
18484,
787,
199,
3,
9394,
687,
314,
1611,
5072,
10059,
5313,
701,
17854,
432,
23177,
3890,
14,
199,
3,
2104,
1655,
2436,
1937,
2597,
1455,
921,
647,
3248,
14,
22943,
14,
846,
14,
199,
4605,
199,
199,
533,
3523,
17188,
649,
597,
7446,
26,
272,
408,
23636,
642,
1021,
370,
1218,
282,
17160,
1379,
7446,
626,
4440,
282,
2488,
272,
4353,
316,
4744,
6065,
14,
710,
1021,
6181,
10296,
402,
3879,
2295,
315,
314,
3211,
272,
30800,
12,
436,
10663,
13484,
370,
314,
7131,
1021,
370,
3332,
2556,
272,
503,
4673,
626,
4474,
1172,
8920,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
1818,
2889,
275,
488,
267,
291,
14,
5720,
275,
378,
267,
291,
855,
10437,
18484,
275,
488,
267,
4838,
8,
277,
14,
826,
14438,
12,
1249,
12,
2074,
9,
339,
347,
664,
12461,
774,
985,
8,
277,
304,
267,
298,
11954,
370,
372,
314,
536,
402,
314,
511,
4895,
370,
506,
1255,
2,
267,
986,
339,
347,
1125,
5619,
8,
277,
12,
2538,
12,
1245,
304,
267,
298,
11954,
370,
2929,
376,
1125,
14554,
1044,
687,
17160,
4503,
2,
267,
986,
339,
347,
1255,
31483,
8,
277,
304,
267,
298,
1378,
506,
2797,
315,
1177,
370,
922,
2468,
26056,
370,
1255,
282,
511,
2,
267,
340,
291,
14,
5720,
26,
372,
267,
511,
985,
275,
291,
14,
362,
12461,
774,
985,
342,
267,
340,
440,
511,
985,
26,
288,
291,
14,
705,
5619,
480,
774,
536,
2397,
401,
298,
5556,
1471,
9509,
282,
511,
536,
531,
288,
372,
267,
340,
291,
855,
10437,
18484,
26,
288,
291,
855,
10437,
18484,
14,
10437,
32447,
342,
267,
291,
855,
10437,
18484,
275,
820,
14385,
894,
18484,
342,
267,
862,
26,
288,
511,
275,
2882,
14,
885,
15824,
14,
25998,
8,
396,
985,
9,
267,
871,
26,
288,
3178,
63,
466,
12,
3178,
63,
585,
12,
3178,
63,
5842,
275,
984,
14,
2804,
63,
815,
342,
288,
4838,
8,
6894,
14,
1361,
63,
1971,
12,
1274,
14,
2804,
63,
815,
1012,
288,
291,
14,
705,
5619,
480,
6005,
370,
1255,
511,
1543,
83,
4065,
450,
511,
985,
12,
2490,
298,
547,
8697,
2013,
511,
26,
450,
83,
12,
450,
83,
2,
450,
971,
2490,
334,
2804,
63,
466,
12,
3178,
63,
585,
430,
288,
372,
267,
291,
14,
1818,
2889,
275,
598,
28666,
597,
2889,
8,
277,
9,
267,
291,
14,
2923,
2925,
275,
511,
14,
835,
19346,
342,
267,
291,
14,
5720,
275,
413,
267,
291,
14,
6814,
9602,
342,
267,
511,
14,
1065,
8,
277,
14,
1818,
2889,
9,
267,
291,
14,
5720,
275,
378,
267,
291,
14,
6814,
28500,
342,
339,
347,
3631,
31483,
8,
277,
304,
267,
298,
1378,
506,
2797,
315,
1177,
370,
922,
23599,
314,
3879,
402,
282,
511,
2,
267,
340,
291,
14,
1818,
2889,
26,
288,
291,
14,
1818,
2889,
14,
2379,
342,
339,
327,
11105,
13484,
339,
347,
11705,
9602,
8,
277,
304,
267,
298,
11954,
370,
663,
17160,
315,
283,
5720,
7,
818,
12,
29310,
283,
2379,
7,
5528,
5423,
2122,
267,
986,
339,
347,
11705,
28500,
8,
277,
304,
267,
298,
11954,
370,
663,
17160,
315,
283,
14661,
7,
818,
12,
29310,
283,
1065,
7,
5528,
5423,
2122,
267,
986,
339,
347,
11705,
774,
4276,
8,
277,
12,
511,
12,
2329,
304,
267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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mancoast/CPythonPyc_test
|
fail/301_test_urllib2_localnet.py
|
1
|
17211
|
#!/usr/bin/env python
import email
import threading
import urllib.parse
import urllib.request
import http.server
import unittest
import hashlib
from test import support
# Loopback http server infrastructure
class LoopbackHttpServer(http.server.HTTPServer):
"""HTTP server w/ a few modifications that make it useful for
loopback testing purposes.
"""
def __init__(self, server_address, RequestHandlerClass):
http.server.HTTPServer.__init__(self,
server_address,
RequestHandlerClass)
# Set the timeout of our listening socket really low so
# that we can stop the server easily.
self.socket.settimeout(1.0)
def get_request(self):
"""HTTPServer method, overridden."""
request, client_address = self.socket.accept()
# It's a loopback connection, so setting the timeout
# really low shouldn't affect anything, but should make
# deadlocks less likely to occur.
request.settimeout(10.0)
return (request, client_address)
class LoopbackHttpServerThread(threading.Thread):
"""Stoppable thread that runs a loopback http server."""
def __init__(self, request_handler):
threading.Thread.__init__(self)
self._stop_server = False
self.ready = threading.Event()
request_handler.protocol_version = "HTTP/1.0"
self.httpd = LoopbackHttpServer(("127.0.0.1", 0),
request_handler)
#print "Serving HTTP on %s port %s" % (self.httpd.server_name,
# self.httpd.server_port)
self.port = self.httpd.server_port
def stop(self):
"""Stops the webserver if it's currently running."""
# Set the stop flag.
self._stop_server = True
self.join()
def run(self):
self.ready.set()
while not self._stop_server:
self.httpd.handle_request()
# Authentication infrastructure
class DigestAuthHandler:
"""Handler for performing digest authentication."""
def __init__(self):
self._request_num = 0
self._nonces = []
self._users = {}
self._realm_name = "Test Realm"
self._qop = "auth"
def set_qop(self, qop):
self._qop = qop
def set_users(self, users):
assert isinstance(users, dict)
self._users = users
def set_realm(self, realm):
self._realm_name = realm
def _generate_nonce(self):
self._request_num += 1
nonce = hashlib.md5(str(self._request_num).encode("ascii")).hexdigest()
self._nonces.append(nonce)
return nonce
def _create_auth_dict(self, auth_str):
first_space_index = auth_str.find(" ")
auth_str = auth_str[first_space_index+1:]
parts = auth_str.split(",")
auth_dict = {}
for part in parts:
name, value = part.split("=")
name = name.strip()
if value[0] == '"' and value[-1] == '"':
value = value[1:-1]
else:
value = value.strip()
auth_dict[name] = value
return auth_dict
def _validate_auth(self, auth_dict, password, method, uri):
final_dict = {}
final_dict.update(auth_dict)
final_dict["password"] = password
final_dict["method"] = method
final_dict["uri"] = uri
HA1_str = "%(username)s:%(realm)s:%(password)s" % final_dict
HA1 = hashlib.md5(HA1_str.encode("ascii")).hexdigest()
HA2_str = "%(method)s:%(uri)s" % final_dict
HA2 = hashlib.md5(HA2_str.encode("ascii")).hexdigest()
final_dict["HA1"] = HA1
final_dict["HA2"] = HA2
response_str = "%(HA1)s:%(nonce)s:%(nc)s:" \
"%(cnonce)s:%(qop)s:%(HA2)s" % final_dict
response = hashlib.md5(response_str.encode("ascii")).hexdigest()
return response == auth_dict["response"]
def _return_auth_challenge(self, request_handler):
request_handler.send_response(407, "Proxy Authentication Required")
request_handler.send_header("Content-Type", "text/html")
request_handler.send_header(
'Proxy-Authenticate', 'Digest realm="%s", '
'qop="%s",'
'nonce="%s", ' % \
(self._realm_name, self._qop, self._generate_nonce()))
# XXX: Not sure if we're supposed to add this next header or
# not.
#request_handler.send_header('Connection', 'close')
request_handler.end_headers()
request_handler.wfile.write(b"Proxy Authentication Required.")
return False
def handle_request(self, request_handler):
"""Performs digest authentication on the given HTTP request
handler. Returns True if authentication was successful, False
otherwise.
If no users have been set, then digest auth is effectively
disabled and this method will always return True.
"""
if len(self._users) == 0:
return True
if "Proxy-Authorization" not in request_handler.headers:
return self._return_auth_challenge(request_handler)
else:
auth_dict = self._create_auth_dict(
request_handler.headers["Proxy-Authorization"]
)
if auth_dict["username"] in self._users:
password = self._users[ auth_dict["username"] ]
else:
return self._return_auth_challenge(request_handler)
if not auth_dict.get("nonce") in self._nonces:
return self._return_auth_challenge(request_handler)
else:
self._nonces.remove(auth_dict["nonce"])
auth_validated = False
# MSIE uses short_path in its validation, but Python's
# urllib2 uses the full path, so we're going to see if
# either of them works here.
for path in [request_handler.path, request_handler.short_path]:
if self._validate_auth(auth_dict,
password,
request_handler.command,
path):
auth_validated = True
if not auth_validated:
return self._return_auth_challenge(request_handler)
return True
# Proxy test infrastructure
class FakeProxyHandler(http.server.BaseHTTPRequestHandler):
"""This is a 'fake proxy' that makes it look like the entire
internet has gone down due to a sudden zombie invasion. It main
utility is in providing us with authentication support for
testing.
"""
digest_auth_handler = DigestAuthHandler()
def log_message(self, format, *args):
# Uncomment the next line for debugging.
# sys.stderr.write(format % args)
pass
def do_GET(self):
(scm, netloc, path, params, query, fragment) = urllib.parse.urlparse(
self.path, "http")
self.short_path = path
if self.digest_auth_handler.handle_request(self):
self.send_response(200, "OK")
self.send_header("Content-Type", "text/html")
self.end_headers()
self.wfile.write(bytes("You've reached %s!<BR>" % self.path,
"ascii"))
self.wfile.write(b"Our apologies, but our server is down due to "
b"a sudden zombie invasion.")
# Test cases
class ProxyAuthTests(unittest.TestCase):
URL = "http://localhost"
USER = "tester"
PASSWD = "test123"
REALM = "TestRealm"
def setUp(self):
FakeProxyHandler.digest_auth_handler.set_users({
self.USER : self.PASSWD
})
FakeProxyHandler.digest_auth_handler.set_realm(self.REALM)
self.server = LoopbackHttpServerThread(FakeProxyHandler)
self.server.start()
self.server.ready.wait()
proxy_url = "http://127.0.0.1:%d" % self.server.port
handler = urllib.request.ProxyHandler({"http" : proxy_url})
self._digest_auth_handler = urllib.request.ProxyDigestAuthHandler()
self.opener = urllib.request.build_opener(
handler, self._digest_auth_handler)
def tearDown(self):
self.server.stop()
def test_proxy_with_bad_password_raises_httperror(self):
self._digest_auth_handler.add_password(self.REALM, self.URL,
self.USER, self.PASSWD+"bad")
FakeProxyHandler.digest_auth_handler.set_qop("auth")
self.assertRaises(urllib.error.HTTPError,
self.opener.open,
self.URL)
def test_proxy_with_no_password_raises_httperror(self):
FakeProxyHandler.digest_auth_handler.set_qop("auth")
self.assertRaises(urllib.error.HTTPError,
self.opener.open,
self.URL)
def test_proxy_qop_auth_works(self):
self._digest_auth_handler.add_password(self.REALM, self.URL,
self.USER, self.PASSWD)
FakeProxyHandler.digest_auth_handler.set_qop("auth")
result = self.opener.open(self.URL)
while result.read():
pass
result.close()
def test_proxy_qop_auth_int_works_or_throws_urlerror(self):
self._digest_auth_handler.add_password(self.REALM, self.URL,
self.USER, self.PASSWD)
FakeProxyHandler.digest_auth_handler.set_qop("auth-int")
try:
result = self.opener.open(self.URL)
except urllib.error.URLError:
# It's okay if we don't support auth-int, but we certainly
# shouldn't receive any kind of exception here other than
# a URLError.
result = None
if result:
while result.read():
pass
result.close()
def GetRequestHandler(responses):
class FakeHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
server_version = "TestHTTP/"
requests = []
headers_received = []
port = 80
def do_GET(self):
body = self.send_head()
if body:
self.wfile.write(body)
def do_POST(self):
content_length = self.headers["Content-Length"]
post_data = self.rfile.read(int(content_length))
self.do_GET()
self.requests.append(post_data)
def send_head(self):
FakeHTTPRequestHandler.headers_received = self.headers
self.requests.append(self.path)
response_code, headers, body = responses.pop(0)
self.send_response(response_code)
for (header, value) in headers:
self.send_header(header, value % {'port':self.port})
if body:
self.send_header("Content-type", "text/plain")
self.end_headers()
return body
self.end_headers()
def log_message(self, *args):
pass
return FakeHTTPRequestHandler
class TestUrlopen(unittest.TestCase):
"""Tests urllib2.urlopen using the network.
These tests are not exhaustive. Assuming that testing using files does a
good job overall of some of the basic interface features. There are no
tests exercising the optional 'data' and 'proxies' arguments. No tests
for transparent redirection have been written.
"""
def setUp(self):
self.server = None
def tearDown(self):
if self.server is not None:
self.server.stop()
def urlopen(self, url, data=None):
l = []
f = urllib.request.urlopen(url, data)
try:
# Exercise various methods
l.extend(f.readlines(200))
l.append(f.readline())
l.append(f.read(1024))
l.append(f.read())
finally:
f.close()
return b"".join(l)
def start_server(self, responses=None):
if responses is None:
responses = [(200, [], b"we don't care")]
handler = GetRequestHandler(responses)
self.server = LoopbackHttpServerThread(handler)
self.server.start()
self.server.ready.wait()
port = self.server.port
handler.port = port
return handler
def test_redirection(self):
expected_response = b"We got here..."
responses = [
(302, [("Location", "http://localhost:%(port)s/somewhere_else")],
""),
(200, [], expected_response)
]
handler = self.start_server(responses)
data = self.urlopen("http://localhost:%s/" % handler.port)
self.assertEquals(data, expected_response)
self.assertEquals(handler.requests, ["/", "/somewhere_else"])
def test_chunked(self):
expected_response = b"hello world"
chunked_start = (
b'a\r\n'
b'hello worl\r\n'
b'1\r\n'
b'd\r\n'
b'0\r\n'
)
response = [(200, [("Transfer-Encoding", "chunked")], chunked_start)]
handler = self.start_server(response)
data = self.urlopen("http://localhost:%s/" % handler.port)
self.assertEquals(data, expected_response)
def test_404(self):
expected_response = b"Bad bad bad..."
handler = self.start_server([(404, [], expected_response)])
try:
self.urlopen("http://localhost:%s/weeble" % handler.port)
except urllib.error.URLError as f:
data = f.read()
f.close()
else:
self.fail("404 should raise URLError")
self.assertEquals(data, expected_response)
self.assertEquals(handler.requests, ["/weeble"])
def test_200(self):
expected_response = b"pycon 2008..."
handler = self.start_server([(200, [], expected_response)])
data = self.urlopen("http://localhost:%s/bizarre" % handler.port)
self.assertEquals(data, expected_response)
self.assertEquals(handler.requests, ["/bizarre"])
def test_200_with_parameters(self):
expected_response = b"pycon 2008..."
handler = self.start_server([(200, [], expected_response)])
data = self.urlopen("http://localhost:%s/bizarre" % handler.port,
b"get=with_feeling")
self.assertEquals(data, expected_response)
self.assertEquals(handler.requests, ["/bizarre", b"get=with_feeling"])
def test_sending_headers(self):
handler = self.start_server()
req = urllib.request.Request("http://localhost:%s/" % handler.port,
headers={"Range": "bytes=20-39"})
urllib.request.urlopen(req)
self.assertEqual(handler.headers_received["Range"], "bytes=20-39")
def test_basic(self):
handler = self.start_server()
open_url = urllib.request.urlopen("http://localhost:%s" % handler.port)
for attr in ("read", "close", "info", "geturl"):
self.assert_(hasattr(open_url, attr), "object returned from "
"urlopen lacks the %s attribute" % attr)
try:
self.assert_(open_url.read(), "calling 'read' failed")
finally:
open_url.close()
def test_info(self):
handler = self.start_server()
try:
open_url = urllib.request.urlopen(
"http://localhost:%s" % handler.port)
info_obj = open_url.info()
self.assert_(isinstance(info_obj, email.message.Message),
"object returned by 'info' is not an instance of "
"email.message.Message")
self.assertEqual(info_obj.get_content_subtype(), "plain")
finally:
self.server.stop()
def test_geturl(self):
# Make sure same URL as opened is returned by geturl.
handler = self.start_server()
open_url = urllib.request.urlopen("http://localhost:%s" % handler.port)
url = open_url.geturl()
self.assertEqual(url, "http://localhost:%s" % handler.port)
def test_bad_address(self):
# Make sure proper exception is raised when connecting to a bogus
# address.
self.assertRaises(IOError,
# SF patch 809915: In Sep 2003, VeriSign started
# highjacking invalid .com and .net addresses to
# boost traffic to their own site. This test
# started failing then. One hopes the .invalid
# domain will be spared to serve its defined
# purpose.
urllib.request.urlopen,
"http://sadflkjsasf.i.nvali.d/")
def test_main():
support.run_unittest(ProxyAuthTests)
support.run_unittest(TestUrlopen)
if __name__ == "__main__":
test_main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
3031,
199,
646,
5796,
199,
646,
4011,
14,
1122,
199,
646,
4011,
14,
1069,
199,
646,
1455,
14,
1000,
199,
646,
2882,
199,
646,
8337,
199,
504,
511,
492,
2291,
199,
199,
3,
18175,
894,
1455,
1654,
28890,
6976,
199,
199,
533,
18175,
894,
5779,
3120,
8,
1014,
14,
1000,
14,
14938,
304,
272,
408,
2856,
1654,
336,
15,
282,
9284,
23070,
626,
1852,
652,
2997,
367,
272,
4438,
894,
5343,
12901,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1654,
63,
1562,
12,
4784,
2461,
2543,
304,
267,
1455,
14,
1000,
14,
14938,
855,
826,
721,
277,
12,
3147,
1654,
63,
1562,
12,
3147,
4784,
2461,
2543,
9,
398,
327,
2494,
314,
2653,
402,
4154,
22721,
2838,
7710,
6465,
880,
267,
327,
626,
781,
883,
3631,
314,
1654,
16174,
14,
267,
291,
14,
3450,
14,
24630,
8,
17,
14,
16,
9,
339,
347,
664,
63,
1069,
8,
277,
304,
267,
408,
14938,
1083,
12,
10087,
1041,
398,
1056,
12,
1890,
63,
1562,
275,
291,
14,
3450,
14,
5694,
342,
398,
327,
2779,
1159,
282,
4438,
894,
1950,
12,
880,
4260,
314,
2653,
267,
327,
7710,
6465,
9296,
1133,
12787,
7003,
12,
1325,
1077,
1852,
267,
327,
12314,
20218,
6656,
12060,
370,
4781,
14,
267,
1056,
14,
24630,
8,
709,
14,
16,
9,
398,
372,
334,
1069,
12,
1890,
63,
1562,
9,
199,
199,
533,
18175,
894,
5779,
3120,
4436,
8,
12562,
14,
4436,
304,
272,
408,
6293,
80,
461,
2462,
626,
7858,
282,
4438,
894,
1455,
1654,
1041,
339,
347,
636,
826,
721,
277,
12,
1056,
63,
2232,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
423,
2379,
63,
1000,
275,
756,
267,
291,
14,
2179,
275,
5796,
14,
2390,
342,
267,
1056,
63,
2232,
14,
3922,
63,
1023,
275,
298,
2856,
15,
17,
14,
16,
2,
267,
291,
14,
21594,
275,
18175,
894,
5779,
3120,
9313,
4195,
14,
16,
14,
16,
14,
17,
401,
378,
395,
3147,
1056,
63,
2232,
9,
267,
327,
1361,
298,
1505,
4007,
3101,
641,
450,
83,
1844,
450,
83,
2,
450,
334,
277,
14,
21594,
14,
1000,
63,
354,
12,
267,
327,
32543,
291,
14,
21594,
14,
1000,
63,
719,
9,
267,
291,
14,
719,
275,
291,
14,
21594,
14,
1000,
63,
719,
339,
347,
3631,
8,
277,
304,
267,
408,
933,
1483,
314,
3330,
1000,
340,
652,
1159,
5544,
3879,
1041,
398,
327,
2494,
314,
3631,
3305,
14,
267,
291,
423,
2379,
63,
1000,
275,
715,
398,
291,
14,
904,
342,
339,
347,
1255,
8,
277,
304,
267,
291,
14,
2179,
14,
409,
342,
267,
1830,
440,
291,
423,
2379,
63,
1000,
26,
288,
291,
14,
21594,
14,
2479,
63,
1069,
342,
199,
199,
3,
15995,
28890,
6976,
199,
199,
533,
3757,
3199,
21547,
26,
272,
408,
2461,
367,
19203,
10017,
6299,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1069,
63,
1507,
275,
378,
267,
291,
423,
2865,
823,
275,
942,
267,
291,
423,
3707,
275,
1052,
267,
291,
423,
7728,
63,
354,
275,
298,
774,
27715,
2,
267,
291,
423,
81,
411,
275,
298,
1178,
2,
339,
347,
663,
63,
81,
411,
8,
277,
12,
1894,
411,
304,
267,
291,
423,
81,
411,
275,
1894,
411,
339,
347,
663,
63,
3707,
8,
277,
12,
4390,
304,
267,
702,
1228,
8,
3707,
12,
1211,
9,
267,
291,
423,
3707,
275,
4390,
339,
347,
663,
63,
7728,
8,
277,
12,
10482,
304,
267,
291,
423,
7728,
63,
354,
275,
10482,
339,
347,
485,
4208,
63,
10667,
8,
277,
304,
267,
291,
423,
1069,
63,
1507,
847,
413,
267,
13711,
275,
8337,
14,
1064,
21,
8,
495,
8,
277,
423,
1069,
63,
1507,
680,
2143,
480,
4371,
21688,
11453,
342,
267,
291,
423,
2865,
823,
14,
740,
8,
10667,
9,
267,
372,
13711,
339,
347,
485,
981,
63,
1178,
63,
807,
8,
277,
12,
1790,
63,
495,
304,
267,
1642,
63,
2638,
63,
1080,
275,
1790,
63,
495,
14,
1623,
480,
6099,
267,
1790,
63,
495,
275,
1790,
63,
495,
59,
2246,
63,
2638,
63,
1080,
11,
17,
2938,
398,
4184,
275,
1790,
63,
495,
14,
1294,
20324,
398,
1790,
63,
807,
275,
1052,
267,
367,
1777,
315,
4184,
26,
288,
536,
12,
574,
275,
1777,
14,
1294,
480,
23758,
288,
536,
275,
536,
14,
1913,
342,
288,
340,
574,
59,
16,
61,
508,
14788,
436,
574,
1988,
17,
61,
508,
24536,
355,
574,
275,
574,
59,
17,
6809,
17,
61,
288,
587,
26,
355,
574,
275,
574,
14,
1913,
342,
288,
1790,
63,
807,
59,
354,
61,
275,
574,
267,
372,
1790,
63,
807,
339,
347,
485,
3502,
63,
1178,
8,
277,
12,
1790,
63,
807,
12,
2505,
12,
1083,
12,
5108,
304,
267,
4242,
63,
807,
275,
1052,
267,
4242,
63,
807,
14,
873,
8,
1178,
63,
807,
9,
267,
4242,
63,
807,
905,
2060,
937,
275,
2505,
267,
4242,
63,
807,
905,
765,
937,
275,
1083,
267,
4242,
63,
807,
905,
2302,
937,
275,
5108,
267,
16100,
17,
63,
495,
275,
11792,
2473,
9,
83,
19648,
7728,
9,
83,
19648,
2060,
9,
83,
2,
450,
4242,
63,
807,
267,
16100,
17,
275,
8337,
14,
1064,
21,
8,
6294,
17,
63,
495,
14,
2143,
480,
4371,
21688,
11453,
342,
267,
16100,
18,
63,
495,
275,
11792,
765,
9,
83,
19648,
2302,
9,
83,
2,
450,
4242,
63,
807,
267,
16100,
18,
275,
8337,
14,
1064,
21,
8,
6294,
18,
63,
495,
14,
2143,
480,
4371,
21688,
11453,
342,
267,
4242,
63,
807,
905,
6294,
17,
937,
275,
16100,
17,
267,
4242,
63,
807,
905,
6294,
18,
937,
275,
16100,
18,
267,
1177,
63,
495,
275,
11792,
6294,
17,
9,
83,
19648,
10667,
9,
83,
19648,
7966,
9,
83,
5424,
971,
2432,
11792,
67,
10667,
9,
83,
19648,
81,
411,
9,
83,
19648,
6294,
18,
9,
83,
2,
450,
4242,
63,
807,
267,
1177,
275,
8337,
14,
1064,
21,
8,
1310,
63,
495,
14,
2143,
480,
4371,
21688,
11453,
342,
398,
372,
1177,
508,
1790,
63,
807,
905,
1310,
937,
339,
347,
485,
1107,
63,
1178,
63,
13911,
8,
277,
12,
1056,
63,
2232,
304,
267,
1056
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
3031,
199,
646,
5796,
199,
646,
4011,
14,
1122,
199,
646,
4011,
14,
1069,
199,
646,
1455,
14,
1000,
199,
646,
2882,
199,
646,
8337,
199,
504,
511,
492,
2291,
199,
199,
3,
18175,
894,
1455,
1654,
28890,
6976,
199,
199,
533,
18175,
894,
5779,
3120,
8,
1014,
14,
1000,
14,
14938,
304,
272,
408,
2856,
1654,
336,
15,
282,
9284,
23070,
626,
1852,
652,
2997,
367,
272,
4438,
894,
5343,
12901,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1654,
63,
1562,
12,
4784,
2461,
2543,
304,
267,
1455,
14,
1000,
14,
14938,
855,
826,
721,
277,
12,
3147,
1654,
63,
1562,
12,
3147,
4784,
2461,
2543,
9,
398,
327,
2494,
314,
2653,
402,
4154,
22721,
2838,
7710,
6465,
880,
267,
327,
626,
781,
883,
3631,
314,
1654,
16174,
14,
267,
291,
14,
3450,
14,
24630,
8,
17,
14,
16,
9,
339,
347,
664,
63,
1069,
8,
277,
304,
267,
408,
14938,
1083,
12,
10087,
1041,
398,
1056,
12,
1890,
63,
1562,
275,
291,
14,
3450,
14,
5694,
342,
398,
327,
2779,
1159,
282,
4438,
894,
1950,
12,
880,
4260,
314,
2653,
267,
327,
7710,
6465,
9296,
1133,
12787,
7003,
12,
1325,
1077,
1852,
267,
327,
12314,
20218,
6656,
12060,
370,
4781,
14,
267,
1056,
14,
24630,
8,
709,
14,
16,
9,
398,
372,
334,
1069,
12,
1890,
63,
1562,
9,
199,
199,
533,
18175,
894,
5779,
3120,
4436,
8,
12562,
14,
4436,
304,
272,
408,
6293,
80,
461,
2462,
626,
7858,
282,
4438,
894,
1455,
1654,
1041,
339,
347,
636,
826,
721,
277,
12,
1056,
63,
2232,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
423,
2379,
63,
1000,
275,
756,
267,
291,
14,
2179,
275,
5796,
14,
2390,
342,
267,
1056,
63,
2232,
14,
3922,
63,
1023,
275,
298,
2856,
15,
17,
14,
16,
2,
267,
291,
14,
21594,
275,
18175,
894,
5779,
3120,
9313,
4195,
14,
16,
14,
16,
14,
17,
401,
378,
395,
3147,
1056,
63,
2232,
9,
267,
327,
1361,
298,
1505,
4007,
3101,
641,
450,
83,
1844,
450,
83,
2,
450,
334,
277,
14,
21594,
14,
1000,
63,
354,
12,
267,
327,
32543,
291,
14,
21594,
14,
1000,
63,
719,
9,
267,
291,
14,
719,
275,
291,
14,
21594,
14,
1000,
63,
719,
339,
347,
3631,
8,
277,
304,
267,
408,
933,
1483,
314,
3330,
1000,
340,
652,
1159,
5544,
3879,
1041,
398,
327,
2494,
314,
3631,
3305,
14,
267,
291,
423,
2379,
63,
1000,
275,
715,
398,
291,
14,
904,
342,
339,
347,
1255,
8,
277,
304,
267,
291,
14,
2179,
14,
409,
342,
267,
1830,
440,
291,
423,
2379,
63,
1000,
26,
288,
291,
14,
21594,
14,
2479,
63,
1069,
342,
199,
199,
3,
15995,
28890,
6976,
199,
199,
533,
3757,
3199,
21547,
26,
272,
408,
2461,
367,
19203,
10017,
6299,
1041,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1069,
63,
1507,
275,
378,
267,
291,
423,
2865,
823,
275,
942,
267,
291,
423,
3707,
275,
1052,
267,
291,
423,
7728,
63,
354,
275,
298,
774,
27715,
2,
267,
291,
423,
81,
411,
275,
298,
1178,
2,
339,
347,
663,
63,
81,
411,
8,
277,
12,
1894,
411,
304,
267,
291,
423,
81,
411,
275,
1894,
411,
339,
347,
663,
63,
3707,
8,
277,
12,
4390,
304,
267,
702,
1228,
8,
3707,
12,
1211,
9,
267,
291,
423,
3707,
275,
4390,
339,
347,
663,
63,
7728,
8,
277,
12,
10482,
304,
267,
291,
423,
7728,
63,
354,
275,
10482,
339,
347,
485,
4208,
63,
10667,
8,
277,
304,
267,
291,
423,
1069,
63,
1507,
847,
413,
267,
13711,
275,
8337,
14,
1064,
21,
8,
495,
8,
277,
423,
1069,
63,
1507,
680,
2143,
480,
4371,
21688,
11453,
342,
267,
291,
423,
2865,
823,
14,
740,
8,
10667,
9,
267,
372,
13711,
339,
347,
485,
981,
63,
1178,
63,
807,
8,
277,
12,
1790,
63,
495,
304,
267,
1642,
63,
2638,
63,
1080,
275,
1790,
63,
495,
14,
1623,
480,
6099,
267,
1790,
63,
495,
275,
1790,
63,
495,
59,
2246,
63,
2638,
63,
1080,
11,
17,
2938,
398,
4184,
275,
1790,
63,
495,
14,
1294,
20324,
398,
1790,
63,
807,
275,
1052,
267,
367,
1777,
315,
4184,
26,
288,
536,
12,
574,
275,
1777,
14,
1294,
480,
23758,
288,
536,
275,
536,
14,
1913,
342,
288,
340,
574,
59,
16,
61,
508,
14788,
436,
574,
1988,
17,
61,
508,
24536,
355,
574,
275,
574,
59,
17,
6809,
17,
61,
288,
587,
26,
355,
574,
275,
574,
14,
1913,
342,
288,
1790,
63,
807,
59,
354,
61,
275,
574,
267,
372,
1790,
63,
807,
339,
347,
485,
3502,
63,
1178,
8,
277,
12,
1790,
63,
807,
12,
2505,
12,
1083,
12,
5108,
304,
267,
4242,
63,
807,
275,
1052,
267,
4242,
63,
807,
14,
873,
8,
1178,
63,
807,
9,
267,
4242,
63,
807,
905,
2060,
937,
275,
2505,
267,
4242,
63,
807,
905,
765,
937,
275,
1083,
267,
4242,
63,
807,
905,
2302,
937,
275,
5108,
267,
16100,
17,
63,
495,
275,
11792,
2473,
9,
83,
19648,
7728,
9,
83,
19648,
2060,
9,
83,
2,
450,
4242,
63,
807,
267,
16100,
17,
275,
8337,
14,
1064,
21,
8,
6294,
17,
63,
495,
14,
2143,
480,
4371,
21688,
11453,
342,
267,
16100,
18,
63,
495,
275,
11792,
765,
9,
83,
19648,
2302,
9,
83,
2,
450,
4242,
63,
807,
267,
16100,
18,
275,
8337,
14,
1064,
21,
8,
6294,
18,
63,
495,
14,
2143,
480,
4371,
21688,
11453,
342,
267,
4242,
63,
807,
905,
6294,
17,
937,
275,
16100,
17,
267,
4242,
63,
807,
905,
6294,
18,
937,
275,
16100,
18,
267,
1177,
63,
495,
275,
11792,
6294,
17,
9,
83,
19648,
10667,
9,
83,
19648,
7966,
9,
83,
5424,
971,
2432,
11792,
67,
10667,
9,
83,
19648,
81,
411,
9,
83,
19648,
6294,
18,
9,
83,
2,
450,
4242,
63,
807,
267,
1177,
275,
8337,
14,
1064,
21,
8,
1310,
63,
495,
14,
2143,
480,
4371,
21688,
11453,
342,
398,
372,
1177,
508,
1790,
63,
807,
905,
1310,
937,
339,
347,
485,
1107,
63,
1178,
63,
13911,
8,
277,
12,
1056,
63,
2232,
304,
267,
1056,
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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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
] |
darkwing/kuma
|
vendor/packages/translate/storage/xml_extract/misc.py
|
24
|
2936
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2008 Zuza Software Foundation
#
# This file is part of the Translate Toolkit.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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 re
# Python 3 compatibility
try:
unicode
except NameError:
unicode = str
def reduce_tree(f, parent_unit_node, unit_node, get_children, *state):
"""Enumerate a tree, applying f to in a pre-order fashion to each node.
parent_unit_node contains the parent of unit_node. For the root of the tree,
parent_unit_node == unit_node.
get_children is a single argument function applied to a unit_node to
get a list/iterator to its children.
state is used by f to modify state information relating to whatever f does
to the tree.
"""
def as_tuple(x):
if isinstance(x, tuple):
return x
else:
return (x,)
state = f(parent_unit_node, unit_node, *state)
for child_unit_node in get_children(unit_node):
state = reduce_tree(f, unit_node, child_unit_node, get_children, *as_tuple(state))
return state
def compose_mappings(left, right):
"""Given two mappings left: A -> B and right: B -> C, create a
hash result_map: A -> C. Only values in left (i.e. things from B)
which have corresponding keys in right will have their keys mapped
to values in right. """
result_map = {}
for left_key, left_val in left.items():
try:
result_map[left_key] = right[left_val]
except KeyError:
pass
return result_map
tag_pattern = re.compile('({(?P<namespace>(\w|[-:./])*)})?(?P<tag>(\w|[-])*)')
def parse_tag(full_tag):
"""
>>> parse_tag('{urn:oasis:names:tc:opendocument:xmlns:office:1.0}document-content')
('urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'document-content')
>>> parse_tag('document-content')
('', 'document-content')
"""
match = tag_pattern.match(full_tag)
if match is not None:
# Slightly hacky way of supporting 2+3
ret = []
for k in ("namespace", "tag"):
value = match.groupdict()[k] or ""
if not isinstance(value, unicode):
value = unicode(value, encoding="utf-8")
ret.append(value)
return ret[0], ret[1]
else:
raise Exception('Passed an invalid tag')
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9079,
3107,
85,
8076,
2290,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
314,
25540,
15650,
6065,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
295,
421,
199,
3,
2018,
650,
7163,
199,
893,
26,
272,
2649,
199,
2590,
12746,
26,
272,
2649,
275,
620,
421,
199,
318,
7114,
63,
2350,
8,
70,
12,
1676,
63,
3248,
63,
932,
12,
4137,
63,
932,
12,
664,
63,
3223,
12,
627,
929,
304,
272,
408,
28858,
1866,
282,
3123,
12,
18876,
289,
370,
315,
282,
876,
13,
1648,
32285,
370,
1924,
1031,
14,
339,
1676,
63,
3248,
63,
932,
3509,
314,
1676,
402,
4137,
63,
932,
14,
2104,
314,
1738,
402,
314,
3123,
12,
272,
1676,
63,
3248,
63,
932,
508,
4137,
63,
932,
14,
339,
664,
63,
3223,
365,
282,
2849,
1423,
805,
6781,
370,
282,
4137,
63,
932,
370,
272,
664,
282,
769,
15,
5778,
370,
2399,
4978,
14,
339,
1174,
365,
1202,
701,
289,
370,
2811,
1174,
2556,
4668,
1958,
370,
15685,
289,
1630,
272,
370,
314,
3123,
14,
272,
408,
339,
347,
465,
63,
2960,
8,
88,
304,
267,
340,
1228,
8,
88,
12,
2008,
304,
288,
372,
671,
267,
587,
26,
288,
372,
334,
88,
4258,
339,
1174,
275,
289,
8,
1708,
63,
3248,
63,
932,
12,
4137,
63,
932,
12,
627,
929,
9,
272,
367,
1982,
63,
3248,
63,
932,
315,
664,
63,
3223,
8,
3248,
63,
932,
304,
267,
1174,
275,
7114,
63,
2350,
8,
70,
12,
4137,
63,
932,
12,
1982,
63,
3248,
63,
932,
12,
664,
63,
3223,
12,
627,
305,
63,
2960,
8,
929,
430,
272,
372,
1174,
421,
199,
318,
23366,
63,
14632,
8,
3039,
12,
2451,
304,
272,
408,
13735,
2877,
13546,
3602,
26,
437,
1035,
699,
436,
2451,
26,
699,
1035,
445,
12,
1218,
282,
272,
2631,
754,
63,
1130,
26,
437,
1035,
445,
14,
5972,
1338,
315,
3602,
334,
73,
14,
69,
14,
7645,
687,
699,
9,
272,
1314,
1172,
5226,
2883,
315,
2451,
911,
1172,
3932,
2883,
9994,
272,
370,
1338,
315,
2451,
14,
408,
272,
754,
63,
1130,
275,
1052,
272,
367,
3602,
63,
498,
12,
3602,
63,
637,
315,
3602,
14,
1744,
837,
267,
862,
26,
288,
754,
63,
1130,
59,
3039,
63,
498,
61,
275,
2451,
59,
3039,
63,
637,
61,
267,
871,
4067,
26,
288,
986,
272,
372,
754,
63,
1130,
421,
199,
1450,
63,
3401,
275,
295,
14,
2014,
360,
2561,
2229,
48,
28,
3251,
30,
2961,
87,
92,
1988,
26,
13186,
19100,
11466,
31,
2229,
48,
28,
1450,
30,
2961,
87,
92,
1988,
19100,
5942,
421,
199,
318,
2198,
63,
1450,
8,
2861,
63,
1450,
304,
272,
408,
272,
1306,
2198,
63,
1450,
11117,
349,
26,
28930,
26,
1247,
26,
3641,
26,
411,
500,
679,
760,
26,
13991,
26,
18812,
26,
17,
14,
16,
93,
3554,
13,
1317,
358,
272,
661,
349,
26,
28930,
26,
1247,
26,
3641,
26,
411,
500,
679,
760,
26,
13991,
26,
18812,
26,
17,
14,
16,
297,
283,
3554,
13,
1317,
358,
272,
1306,
2198,
63,
1450,
360,
3554,
13,
1317,
358,
272,
13134,
283,
3554,
13,
1317,
358,
272,
408,
272,
1336,
275,
1947,
63,
3401,
14,
1431,
8,
2861,
63,
1450,
9,
272,
340,
1336,
365,
440,
488,
26,
267,
327,
428,
4040,
590,
11176,
89,
4340,
402,
21038,
499,
11,
19,
267,
2203,
275,
942,
267,
367,
1022,
315,
1689,
3251,
401,
298,
1450,
2349,
288,
574,
275,
1336,
14,
20567,
3430,
75,
61,
503,
3087,
288,
340,
440,
1228,
8,
585,
12,
2649,
304,
355,
574,
275,
2649,
8,
585,
12,
2644,
628,
1624,
13,
24,
531,
288,
2203,
14,
740,
8,
585,
9,
267,
372,
2203,
59,
16,
467,
2203,
59,
17,
61,
272,
587,
26,
267,
746,
2186,
360,
48,
2744,
376,
3866,
1947,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9079,
3107,
85,
8076,
2290,
2752,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
314,
25540,
15650,
6065,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
295,
421,
199,
3,
2018,
650,
7163,
199,
893,
26,
272,
2649,
199,
2590,
12746,
26,
272,
2649,
275,
620,
421,
199,
318,
7114,
63,
2350,
8,
70,
12,
1676,
63,
3248,
63,
932,
12,
4137,
63,
932,
12,
664,
63,
3223,
12,
627,
929,
304,
272,
408,
28858,
1866,
282,
3123,
12,
18876,
289,
370,
315,
282,
876,
13,
1648,
32285,
370,
1924,
1031,
14,
339,
1676,
63,
3248,
63,
932,
3509,
314,
1676,
402,
4137,
63,
932,
14,
2104,
314,
1738,
402,
314,
3123,
12,
272,
1676,
63,
3248,
63,
932,
508,
4137,
63,
932,
14,
339,
664,
63,
3223,
365,
282,
2849,
1423,
805,
6781,
370,
282,
4137,
63,
932,
370,
272,
664,
282,
769,
15,
5778,
370,
2399,
4978,
14,
339,
1174,
365,
1202,
701,
289,
370,
2811,
1174,
2556,
4668,
1958,
370,
15685,
289,
1630,
272,
370,
314,
3123,
14,
272,
408,
339,
347,
465,
63,
2960,
8,
88,
304,
267,
340,
1228,
8,
88,
12,
2008,
304,
288,
372,
671,
267,
587,
26,
288,
372,
334,
88,
4258,
339,
1174,
275,
289,
8,
1708,
63,
3248,
63,
932,
12,
4137,
63,
932,
12,
627,
929,
9,
272,
367,
1982,
63,
3248,
63,
932,
315,
664,
63,
3223,
8,
3248,
63,
932,
304,
267,
1174,
275,
7114,
63,
2350,
8,
70,
12,
4137,
63,
932,
12,
1982,
63,
3248,
63,
932,
12,
664,
63,
3223,
12,
627,
305,
63,
2960,
8,
929,
430,
272,
372,
1174,
421,
199,
318,
23366,
63,
14632,
8,
3039,
12,
2451,
304,
272,
408,
13735,
2877,
13546,
3602,
26,
437,
1035,
699,
436,
2451,
26,
699,
1035,
445,
12,
1218,
282,
272,
2631,
754,
63,
1130,
26,
437,
1035,
445,
14,
5972,
1338,
315,
3602,
334,
73,
14,
69,
14,
7645,
687,
699,
9,
272,
1314,
1172,
5226,
2883,
315,
2451,
911,
1172,
3932,
2883,
9994,
272,
370,
1338,
315,
2451,
14,
408,
272,
754,
63,
1130,
275,
1052,
272,
367,
3602,
63,
498,
12,
3602,
63,
637,
315,
3602,
14,
1744,
837,
267,
862,
26,
288,
754,
63,
1130,
59,
3039,
63,
498,
61,
275,
2451,
59,
3039,
63,
637,
61,
267,
871,
4067,
26,
288,
986,
272,
372,
754,
63,
1130,
421,
199,
1450,
63,
3401,
275,
295,
14,
2014,
360,
2561,
2229,
48,
28,
3251,
30,
2961,
87,
92,
1988,
26,
13186,
19100,
11466,
31,
2229,
48,
28,
1450,
30,
2961,
87,
92,
1988,
19100,
5942,
421,
199,
318,
2198,
63,
1450,
8,
2861,
63,
1450,
304,
272,
408,
272,
1306,
2198,
63,
1450,
11117,
349,
26,
28930,
26,
1247,
26,
3641,
26,
411,
500,
679,
760,
26,
13991,
26,
18812,
26,
17,
14,
16,
93,
3554,
13,
1317,
358,
272,
661,
349,
26,
28930,
26,
1247,
26,
3641,
26,
411,
500,
679,
760,
26,
13991,
26,
18812,
26,
17,
14,
16,
297,
283,
3554,
13,
1317,
358,
272,
1306,
2198,
63,
1450,
360,
3554,
13,
1317,
358,
272,
13134,
283,
3554,
13,
1317,
358,
272,
408,
272,
1336,
275,
1947,
63,
3401,
14,
1431,
8,
2861,
63,
1450,
9,
272,
340,
1336,
365,
440,
488,
26,
267,
327,
428,
4040,
590,
11176,
89,
4340,
402,
21038,
499,
11,
19,
267,
2203,
275,
942,
267,
367,
1022,
315,
1689,
3251,
401,
298,
1450,
2349,
288,
574,
275,
1336,
14,
20567,
3430,
75,
61,
503,
3087,
288,
340,
440,
1228,
8,
585,
12,
2649,
304,
355,
574,
275,
2649,
8,
585,
12,
2644,
628,
1624,
13,
24,
531,
288,
2203,
14,
740,
8,
585,
9,
267,
372,
2203,
59,
16,
467,
2203,
59,
17,
61,
272,
587,
26,
267,
746,
2186,
360,
48,
2744,
376,
3866,
1947,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
thermokarst/qiime2
|
qiime2/core/type/tests/test_parse.py
|
1
|
4541
|
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2020, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import unittest
from qiime2.core.type.parse import ast_to_type, string_to_ast
from qiime2.core.testing.type import Foo, Bar, C1, C2
from qiime2.plugin import (Int, Float, Str, Bool, Range, Choices, TypeMap,
Properties, List, Set, Visualization, Metadata,
MetadataColumn, Categorical, Numeric)
class TestParsing(unittest.TestCase):
def assert_roundtrip(self, type):
ast = string_to_ast(repr(type))
type1 = ast_to_type(ast)
type2 = ast_to_type(type1.to_ast())
self.assertEqual(type, type1)
self.assertEqual(ast, type1.to_ast())
self.assertEqual(type1, type2)
def test_simple_semantic_type(self):
self.assert_roundtrip(Foo)
self.assert_roundtrip(Bar)
self.assert_roundtrip(C1[Foo])
def test_union_semantic_type(self):
self.assert_roundtrip(Foo | Bar)
self.assert_roundtrip(C1[Foo | Bar])
def test_complicated_semantic_type(self):
self.assert_roundtrip(C2[C1[Foo % Properties(["A", "B"]) | Bar],
Foo % Properties("A")
] % Properties(exclude=["B", "C"]))
def test_collection_semantic_type(self):
self.assert_roundtrip(List[Foo | Bar])
self.assert_roundtrip(Set[Bar])
def test_visualization(self):
self.assert_roundtrip(Visualization)
def test_primitive_simple(self):
self.assert_roundtrip(Int)
self.assert_roundtrip(Float)
self.assert_roundtrip(Str)
self.assert_roundtrip(Bool)
def test_primitive_predicate(self):
self.assert_roundtrip(Int % Range(0, 10))
self.assert_roundtrip(
Int % (Range(0, 10) | Range(50, 100, inclusive_end=True)))
self.assert_roundtrip(Float % Range(None, 10))
self.assert_roundtrip(Float % Range(0, None))
self.assert_roundtrip(Str % Choices("A"))
self.assert_roundtrip(Str % Choices(["A"]))
self.assert_roundtrip(Str % Choices("A", "B"))
self.assert_roundtrip(Str % Choices(["A", "B"]))
self.assert_roundtrip(Bool % Choices(True))
self.assert_roundtrip(Bool % Choices(False))
def test_collection_primitive(self):
self.assert_roundtrip(Set[Str % Choices('A', 'B', 'C')])
self.assert_roundtrip(List[Int % Range(1, 3, inclusive_end=True)
| Str % Choices('A', 'B', 'C')])
def test_metadata_primitive(self):
self.assert_roundtrip(Metadata)
self.assert_roundtrip(MetadataColumn[Numeric])
self.assert_roundtrip(MetadataColumn[Categorical])
self.assert_roundtrip(MetadataColumn[Numeric | Categorical])
def test_typevars(self):
T, U, V, W, X = TypeMap({
(Foo, Bar, Str % Choices('A', 'B')): (C1[Foo], C1[Bar]),
(Foo | Bar, Foo, Str): (C1[Bar], C1[Foo])
})
scope = {}
T1 = ast_to_type(T.to_ast(), scope=scope)
U1 = ast_to_type(U.to_ast(), scope=scope)
V1 = ast_to_type(V.to_ast(), scope=scope)
W1 = ast_to_type(W.to_ast(), scope=scope)
X1 = ast_to_type(X.to_ast(), scope=scope)
self.assertEqual(len(scope), 1)
self.assertEqual(scope[id(T.mapping)], [T1, U1, V1, W1, X1])
self.assertEqual(T1.mapping.lifted, T.mapping.lifted)
self.assertIs(T1.mapping, U1.mapping)
self.assertIs(U1.mapping, V1.mapping)
self.assertIs(V1.mapping, W1.mapping)
self.assertIs(W1.mapping, X1.mapping)
def test_syntax_error(self):
with self.assertRaisesRegex(ValueError, "could not be parsed"):
string_to_ast('$')
def test_bad_juju(self):
with self.assertRaisesRegex(ValueError, "one type expression"):
string_to_ast('import os; os.rmdir("something-important")')
def test_more_bad(self):
with self.assertRaisesRegex(ValueError, "Unknown expression"):
string_to_ast('lambda x: x')
def test_weird(self):
with self.assertRaisesRegex(ValueError, "Unknown literal"):
string_to_ast('FeatureTable(Foo + Bar)')
if __name__ == '__main__':
unittest.main()
|
bsd-3-clause
|
[
3,
27103,
199,
3,
1898,
334,
67,
9,
7800,
13,
13934,
12,
1413,
41,
3465,
499,
16367,
8099,
14,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
12,
1854,
543,
642,
2032,
14,
199,
3,
27103,
199,
199,
646,
2882,
199,
199,
504,
31402,
1036,
18,
14,
1018,
14,
466,
14,
1122,
492,
6073,
63,
475,
63,
466,
12,
1059,
63,
475,
63,
1810,
199,
504,
31402,
1036,
18,
14,
1018,
14,
4776,
14,
466,
492,
8024,
12,
12377,
12,
445,
17,
12,
445,
18,
199,
504,
31402,
1036,
18,
14,
2718,
492,
334,
3241,
12,
11140,
12,
8303,
12,
19287,
12,
13114,
12,
8802,
2370,
12,
2434,
2956,
12,
2574,
19329,
12,
3820,
12,
2494,
12,
14702,
2072,
12,
16160,
12,
2574,
16160,
4547,
12,
31227,
12,
19378,
9,
421,
199,
533,
1379,
17412,
8,
2796,
14,
1746,
304,
272,
347,
702,
63,
25920,
8,
277,
12,
730,
304,
267,
6073,
275,
1059,
63,
475,
63,
1810,
8,
2722,
8,
466,
430,
267,
730,
17,
275,
6073,
63,
475,
63,
466,
8,
1810,
9,
267,
730,
18,
275,
6073,
63,
475,
63,
466,
8,
466,
17,
14,
475,
63,
1810,
1012,
398,
291,
14,
629,
8,
466,
12,
730,
17,
9,
267,
291,
14,
629,
8,
1810,
12,
730,
17,
14,
475,
63,
1810,
1012,
267,
291,
14,
629,
8,
466,
17,
12,
730,
18,
9,
339,
347,
511,
63,
4129,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
5686,
9,
267,
291,
14,
479,
63,
25920,
8,
5281,
9,
267,
291,
14,
479,
63,
25920,
8,
35,
17,
59,
5686,
566,
339,
347,
511,
63,
8888,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
5686,
1204,
12377,
9,
267,
291,
14,
479,
63,
25920,
8,
35,
17,
59,
5686,
1204,
12377,
566,
339,
347,
511,
63,
863,
16209,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
35,
18,
59,
35,
17,
59,
5686,
450,
19329,
5234,
33,
401,
298,
34,
3135,
1204,
12377,
467,
639,
8024,
450,
19329,
480,
33,
531,
639,
1622,
450,
19329,
8,
5473,
6270,
34,
401,
298,
35,
13045,
339,
347,
511,
63,
3627,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
1296,
59,
5686,
1204,
12377,
566,
267,
291,
14,
479,
63,
25920,
8,
1084,
59,
5281,
566,
339,
347,
511,
63,
16948,
2072,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
15039,
2072,
9,
339,
347,
511,
63,
16161,
63,
4129,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
3241,
9,
267,
291,
14,
479,
63,
25920,
8,
5136,
9,
267,
291,
14,
479,
63,
25920,
8,
2848,
9,
267,
291,
14,
479,
63,
25920,
8,
10349,
9,
339,
347,
511,
63,
16161,
63,
14463,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
3241,
450,
13114,
8,
16,
12,
1616,
430,
267,
291,
14,
479,
63,
25920,
8,
288,
9805,
450,
334,
4709,
8,
16,
12,
1616,
9,
1204,
13114,
8,
1400,
12,
2948,
12,
20728,
63,
500,
29,
549,
1724,
267,
291,
14,
479,
63,
25920,
8,
5136,
450,
13114,
8,
403,
12,
1616,
430,
267,
291,
14,
479,
63,
25920,
8,
5136,
450,
13114,
8,
16,
12,
488,
430,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
480,
33,
2237,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
5234,
33,
13045,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
480,
33,
401,
298,
34,
2237,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
5234,
33,
401,
298,
34,
13045,
267,
291,
14,
479,
63,
25920,
8,
10349,
450,
8802,
2370,
8,
549,
430,
267,
291,
14,
479,
63,
25920,
8,
10349,
450,
8802,
2370,
8,
797,
430,
339,
347,
511,
63,
3627,
63,
16161,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
1084,
59,
2848,
450,
8802,
2370,
360,
33,
297,
283,
34,
297,
283,
35,
2023,
267,
291,
14,
479,
63,
25920,
8,
1296,
59,
3241,
450,
13114,
8,
17,
12,
650,
12,
20728,
63,
500,
29,
549,
9,
3521,
1204,
8303,
450,
8802,
2370,
360,
33,
297,
283,
34,
297,
283,
35,
2023,
339,
347,
511,
63,
2343,
63,
16161,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
5142,
9,
267,
291,
14,
479,
63,
25920,
8,
5142,
4547,
59,
14687,
566,
267,
291,
14,
479,
63,
25920,
8,
5142,
4547,
59,
23306,
566,
267,
291,
14,
479,
63,
25920,
8,
5142,
4547,
59,
14687,
1204,
31227,
566,
339,
347,
511,
63,
466,
2936,
8,
277,
304,
267,
377,
12,
738,
12,
812,
12,
644,
12,
1323,
275,
2434,
2956,
2561,
288,
334,
5686,
12,
12377,
12,
8303,
450,
8802,
2370,
360,
33,
297,
283,
34,
8109,
334,
35,
17,
59,
5686,
467,
445,
17,
59,
5281,
2522,
288,
334,
5686,
1204,
12377,
12,
8024,
12,
8303,
304,
334,
35,
17,
59,
5281,
467,
445,
17,
59,
5686,
566,
267,
3828,
398,
4194,
275,
1052,
267,
377,
17,
275,
6073,
63,
475,
63,
466,
8,
52,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
738,
17,
275,
6073,
63,
475,
63,
466,
8,
53,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
812,
17,
275,
6073,
63,
475,
63,
466,
8,
54,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
644,
17,
275,
6073,
63,
475,
63,
466,
8,
55,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
1323,
17,
275,
6073,
63,
475,
63,
466,
8,
56,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
398,
291,
14,
629,
8,
552,
8,
2645,
395,
413,
9,
267,
291,
14,
629,
8,
2645,
59,
344,
8,
52,
14,
4745,
4360,
359,
52,
17,
12,
738,
17,
12,
812,
17,
12,
644,
17,
12,
1323,
17,
566,
398,
291,
14,
629,
8,
52,
17,
14,
4745,
14,
853,
471,
12,
377,
14,
4745,
14,
853,
471
] |
[
27103,
199,
3,
1898,
334,
67,
9,
7800,
13,
13934,
12,
1413,
41,
3465,
499,
16367,
8099,
14,
199,
3,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
3,
199,
3,
710,
2615,
4190,
365,
315,
314,
570,
5113,
12,
1854,
543,
642,
2032,
14,
199,
3,
27103,
199,
199,
646,
2882,
199,
199,
504,
31402,
1036,
18,
14,
1018,
14,
466,
14,
1122,
492,
6073,
63,
475,
63,
466,
12,
1059,
63,
475,
63,
1810,
199,
504,
31402,
1036,
18,
14,
1018,
14,
4776,
14,
466,
492,
8024,
12,
12377,
12,
445,
17,
12,
445,
18,
199,
504,
31402,
1036,
18,
14,
2718,
492,
334,
3241,
12,
11140,
12,
8303,
12,
19287,
12,
13114,
12,
8802,
2370,
12,
2434,
2956,
12,
2574,
19329,
12,
3820,
12,
2494,
12,
14702,
2072,
12,
16160,
12,
2574,
16160,
4547,
12,
31227,
12,
19378,
9,
421,
199,
533,
1379,
17412,
8,
2796,
14,
1746,
304,
272,
347,
702,
63,
25920,
8,
277,
12,
730,
304,
267,
6073,
275,
1059,
63,
475,
63,
1810,
8,
2722,
8,
466,
430,
267,
730,
17,
275,
6073,
63,
475,
63,
466,
8,
1810,
9,
267,
730,
18,
275,
6073,
63,
475,
63,
466,
8,
466,
17,
14,
475,
63,
1810,
1012,
398,
291,
14,
629,
8,
466,
12,
730,
17,
9,
267,
291,
14,
629,
8,
1810,
12,
730,
17,
14,
475,
63,
1810,
1012,
267,
291,
14,
629,
8,
466,
17,
12,
730,
18,
9,
339,
347,
511,
63,
4129,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
5686,
9,
267,
291,
14,
479,
63,
25920,
8,
5281,
9,
267,
291,
14,
479,
63,
25920,
8,
35,
17,
59,
5686,
566,
339,
347,
511,
63,
8888,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
5686,
1204,
12377,
9,
267,
291,
14,
479,
63,
25920,
8,
35,
17,
59,
5686,
1204,
12377,
566,
339,
347,
511,
63,
863,
16209,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
35,
18,
59,
35,
17,
59,
5686,
450,
19329,
5234,
33,
401,
298,
34,
3135,
1204,
12377,
467,
639,
8024,
450,
19329,
480,
33,
531,
639,
1622,
450,
19329,
8,
5473,
6270,
34,
401,
298,
35,
13045,
339,
347,
511,
63,
3627,
63,
261,
23127,
63,
466,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
1296,
59,
5686,
1204,
12377,
566,
267,
291,
14,
479,
63,
25920,
8,
1084,
59,
5281,
566,
339,
347,
511,
63,
16948,
2072,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
15039,
2072,
9,
339,
347,
511,
63,
16161,
63,
4129,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
3241,
9,
267,
291,
14,
479,
63,
25920,
8,
5136,
9,
267,
291,
14,
479,
63,
25920,
8,
2848,
9,
267,
291,
14,
479,
63,
25920,
8,
10349,
9,
339,
347,
511,
63,
16161,
63,
14463,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
3241,
450,
13114,
8,
16,
12,
1616,
430,
267,
291,
14,
479,
63,
25920,
8,
288,
9805,
450,
334,
4709,
8,
16,
12,
1616,
9,
1204,
13114,
8,
1400,
12,
2948,
12,
20728,
63,
500,
29,
549,
1724,
267,
291,
14,
479,
63,
25920,
8,
5136,
450,
13114,
8,
403,
12,
1616,
430,
267,
291,
14,
479,
63,
25920,
8,
5136,
450,
13114,
8,
16,
12,
488,
430,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
480,
33,
2237,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
5234,
33,
13045,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
480,
33,
401,
298,
34,
2237,
267,
291,
14,
479,
63,
25920,
8,
2848,
450,
8802,
2370,
5234,
33,
401,
298,
34,
13045,
267,
291,
14,
479,
63,
25920,
8,
10349,
450,
8802,
2370,
8,
549,
430,
267,
291,
14,
479,
63,
25920,
8,
10349,
450,
8802,
2370,
8,
797,
430,
339,
347,
511,
63,
3627,
63,
16161,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
1084,
59,
2848,
450,
8802,
2370,
360,
33,
297,
283,
34,
297,
283,
35,
2023,
267,
291,
14,
479,
63,
25920,
8,
1296,
59,
3241,
450,
13114,
8,
17,
12,
650,
12,
20728,
63,
500,
29,
549,
9,
3521,
1204,
8303,
450,
8802,
2370,
360,
33,
297,
283,
34,
297,
283,
35,
2023,
339,
347,
511,
63,
2343,
63,
16161,
8,
277,
304,
267,
291,
14,
479,
63,
25920,
8,
5142,
9,
267,
291,
14,
479,
63,
25920,
8,
5142,
4547,
59,
14687,
566,
267,
291,
14,
479,
63,
25920,
8,
5142,
4547,
59,
23306,
566,
267,
291,
14,
479,
63,
25920,
8,
5142,
4547,
59,
14687,
1204,
31227,
566,
339,
347,
511,
63,
466,
2936,
8,
277,
304,
267,
377,
12,
738,
12,
812,
12,
644,
12,
1323,
275,
2434,
2956,
2561,
288,
334,
5686,
12,
12377,
12,
8303,
450,
8802,
2370,
360,
33,
297,
283,
34,
8109,
334,
35,
17,
59,
5686,
467,
445,
17,
59,
5281,
2522,
288,
334,
5686,
1204,
12377,
12,
8024,
12,
8303,
304,
334,
35,
17,
59,
5281,
467,
445,
17,
59,
5686,
566,
267,
3828,
398,
4194,
275,
1052,
267,
377,
17,
275,
6073,
63,
475,
63,
466,
8,
52,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
738,
17,
275,
6073,
63,
475,
63,
466,
8,
53,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
812,
17,
275,
6073,
63,
475,
63,
466,
8,
54,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
644,
17,
275,
6073,
63,
475,
63,
466,
8,
55,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
267,
1323,
17,
275,
6073,
63,
475,
63,
466,
8,
56,
14,
475,
63,
1810,
1062,
4194,
29,
2645,
9,
398,
291,
14,
629,
8,
552,
8,
2645,
395,
413,
9,
267,
291,
14,
629,
8,
2645,
59,
344,
8,
52,
14,
4745,
4360,
359,
52,
17,
12,
738,
17,
12,
812,
17,
12,
644,
17,
12,
1323,
17,
566,
398,
291,
14,
629,
8,
52,
17,
14,
4745,
14,
853,
471,
12,
377,
14,
4745,
14,
853,
471,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
tesidroni/mp
|
Lib/distutils/command/bdist_rpm.py
|
104
|
20408
|
"""distutils.command.bdist_rpm
Implements the Distutils 'bdist_rpm' command (create RPM source and binary
distributions)."""
__revision__ = "$Id$"
import sys
import os
import string
from distutils.core import Command
from distutils.debug import DEBUG
from distutils.file_util import write_file
from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
DistutilsFileError, DistutilsExecError)
from distutils import log
class bdist_rpm (Command):
description = "create an RPM distribution"
user_options = [
('bdist-base=', None,
"base directory for creating built distributions"),
('rpm-base=', None,
"base directory for creating RPMs (defaults to \"rpm\" under "
"--bdist-base; must be specified for RPM 2)"),
('dist-dir=', 'd',
"directory to put final RPM files in "
"(and .spec files if --spec-only)"),
('python=', None,
"path to Python interpreter to hard-code in the .spec file "
"(default: \"python\")"),
('fix-python', None,
"hard-code the exact path to the current Python interpreter in "
"the .spec file"),
('spec-only', None,
"only regenerate spec file"),
('source-only', None,
"only generate source RPM"),
('binary-only', None,
"only generate binary RPM"),
('use-bzip2', None,
"use bzip2 instead of gzip to create source distribution"),
# More meta-data: too RPM-specific to put in the setup script,
# but needs to go in the .spec file -- so we make these options
# to "bdist_rpm". The idea is that packagers would put this
# info in setup.cfg, although they are of course free to
# supply it on the command line.
('distribution-name=', None,
"name of the (Linux) distribution to which this "
"RPM applies (*not* the name of the module distribution!)"),
('group=', None,
"package classification [default: \"Development/Libraries\"]"),
('release=', None,
"RPM release number"),
('serial=', None,
"RPM serial number"),
('vendor=', None,
"RPM \"vendor\" (eg. \"Joe Blow <joe@example.com>\") "
"[default: maintainer or author from setup script]"),
('packager=', None,
"RPM packager (eg. \"Jane Doe <jane@example.net>\")"
"[default: vendor]"),
('doc-files=', None,
"list of documentation files (space or comma-separated)"),
('changelog=', None,
"RPM changelog"),
('icon=', None,
"name of icon file"),
('provides=', None,
"capabilities provided by this package"),
('requires=', None,
"capabilities required by this package"),
('conflicts=', None,
"capabilities which conflict with this package"),
('build-requires=', None,
"capabilities required to build this package"),
('obsoletes=', None,
"capabilities made obsolete by this package"),
('no-autoreq', None,
"do not automatically calculate dependencies"),
# Actions to take when building RPM
('keep-temp', 'k',
"don't clean up RPM build directory"),
('no-keep-temp', None,
"clean up RPM build directory [default]"),
('use-rpm-opt-flags', None,
"compile with RPM_OPT_FLAGS when building from source RPM"),
('no-rpm-opt-flags', None,
"do not pass any RPM CFLAGS to compiler"),
('rpm3-mode', None,
"RPM 3 compatibility mode (default)"),
('rpm2-mode', None,
"RPM 2 compatibility mode"),
# Add the hooks necessary for specifying custom scripts
('prep-script=', None,
"Specify a script for the PREP phase of RPM building"),
('build-script=', None,
"Specify a script for the BUILD phase of RPM building"),
('pre-install=', None,
"Specify a script for the pre-INSTALL phase of RPM building"),
('install-script=', None,
"Specify a script for the INSTALL phase of RPM building"),
('post-install=', None,
"Specify a script for the post-INSTALL phase of RPM building"),
('pre-uninstall=', None,
"Specify a script for the pre-UNINSTALL phase of RPM building"),
('post-uninstall=', None,
"Specify a script for the post-UNINSTALL phase of RPM building"),
('clean-script=', None,
"Specify a script for the CLEAN phase of RPM building"),
('verify-script=', None,
"Specify a script for the VERIFY phase of the RPM build"),
# Allow a packager to explicitly force an architecture
('force-arch=', None,
"Force an architecture onto the RPM build process"),
('quiet', 'q',
"Run the INSTALL phase of RPM building in quiet mode"),
]
boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode',
'no-autoreq', 'quiet']
negative_opt = {'no-keep-temp': 'keep-temp',
'no-rpm-opt-flags': 'use-rpm-opt-flags',
'rpm2-mode': 'rpm3-mode'}
def initialize_options (self):
self.bdist_base = None
self.rpm_base = None
self.dist_dir = None
self.python = None
self.fix_python = None
self.spec_only = None
self.binary_only = None
self.source_only = None
self.use_bzip2 = None
self.distribution_name = None
self.group = None
self.release = None
self.serial = None
self.vendor = None
self.packager = None
self.doc_files = None
self.changelog = None
self.icon = None
self.prep_script = None
self.build_script = None
self.install_script = None
self.clean_script = None
self.verify_script = None
self.pre_install = None
self.post_install = None
self.pre_uninstall = None
self.post_uninstall = None
self.prep = None
self.provides = None
self.requires = None
self.conflicts = None
self.build_requires = None
self.obsoletes = None
self.keep_temp = 0
self.use_rpm_opt_flags = 1
self.rpm3_mode = 1
self.no_autoreq = 0
self.force_arch = None
self.quiet = 0
# initialize_options()
def finalize_options (self):
self.set_undefined_options('bdist', ('bdist_base', 'bdist_base'))
if self.rpm_base is None:
if not self.rpm3_mode:
raise DistutilsOptionError, \
"you must specify --rpm-base in RPM 2 mode"
self.rpm_base = os.path.join(self.bdist_base, "rpm")
if self.python is None:
if self.fix_python:
self.python = sys.executable
else:
self.python = "python"
elif self.fix_python:
raise DistutilsOptionError, \
"--python and --fix-python are mutually exclusive options"
if os.name != 'posix':
raise DistutilsPlatformError, \
("don't know how to create RPM "
"distributions on platform %s" % os.name)
if self.binary_only and self.source_only:
raise DistutilsOptionError, \
"cannot supply both '--source-only' and '--binary-only'"
# don't pass CFLAGS to pure python distributions
if not self.distribution.has_ext_modules():
self.use_rpm_opt_flags = 0
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
self.finalize_package_data()
# finalize_options()
def finalize_package_data (self):
self.ensure_string('group', "Development/Libraries")
self.ensure_string('vendor',
"%s <%s>" % (self.distribution.get_contact(),
self.distribution.get_contact_email()))
self.ensure_string('packager')
self.ensure_string_list('doc_files')
if isinstance(self.doc_files, list):
for readme in ('README', 'README.txt'):
if os.path.exists(readme) and readme not in self.doc_files:
self.doc_files.append(readme)
self.ensure_string('release', "1")
self.ensure_string('serial') # should it be an int?
self.ensure_string('distribution_name')
self.ensure_string('changelog')
# Format changelog correctly
self.changelog = self._format_changelog(self.changelog)
self.ensure_filename('icon')
self.ensure_filename('prep_script')
self.ensure_filename('build_script')
self.ensure_filename('install_script')
self.ensure_filename('clean_script')
self.ensure_filename('verify_script')
self.ensure_filename('pre_install')
self.ensure_filename('post_install')
self.ensure_filename('pre_uninstall')
self.ensure_filename('post_uninstall')
# XXX don't forget we punted on summaries and descriptions -- they
# should be handled here eventually!
# Now *this* is some meta-data that belongs in the setup script...
self.ensure_string_list('provides')
self.ensure_string_list('requires')
self.ensure_string_list('conflicts')
self.ensure_string_list('build_requires')
self.ensure_string_list('obsoletes')
self.ensure_string('force_arch')
# finalize_package_data ()
def run (self):
if DEBUG:
print "before _get_package_data():"
print "vendor =", self.vendor
print "packager =", self.packager
print "doc_files =", self.doc_files
print "changelog =", self.changelog
# make directories
if self.spec_only:
spec_dir = self.dist_dir
self.mkpath(spec_dir)
else:
rpm_dir = {}
for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
rpm_dir[d] = os.path.join(self.rpm_base, d)
self.mkpath(rpm_dir[d])
spec_dir = rpm_dir['SPECS']
# Spec file goes into 'dist_dir' if '--spec-only specified',
# build/rpm.<plat> otherwise.
spec_path = os.path.join(spec_dir,
"%s.spec" % self.distribution.get_name())
self.execute(write_file,
(spec_path,
self._make_spec_file()),
"writing '%s'" % spec_path)
if self.spec_only: # stop if requested
return
# Make a source distribution and copy to SOURCES directory with
# optional icon.
saved_dist_files = self.distribution.dist_files[:]
sdist = self.reinitialize_command('sdist')
if self.use_bzip2:
sdist.formats = ['bztar']
else:
sdist.formats = ['gztar']
self.run_command('sdist')
self.distribution.dist_files = saved_dist_files
source = sdist.get_archive_files()[0]
source_dir = rpm_dir['SOURCES']
self.copy_file(source, source_dir)
if self.icon:
if os.path.exists(self.icon):
self.copy_file(self.icon, source_dir)
else:
raise DistutilsFileError, \
"icon file '%s' does not exist" % self.icon
# build package
log.info("building RPMs")
rpm_cmd = ['rpm']
if os.path.exists('/usr/bin/rpmbuild') or \
os.path.exists('/bin/rpmbuild'):
rpm_cmd = ['rpmbuild']
if self.source_only: # what kind of RPMs?
rpm_cmd.append('-bs')
elif self.binary_only:
rpm_cmd.append('-bb')
else:
rpm_cmd.append('-ba')
if self.rpm3_mode:
rpm_cmd.extend(['--define',
'_topdir %s' % os.path.abspath(self.rpm_base)])
if not self.keep_temp:
rpm_cmd.append('--clean')
if self.quiet:
rpm_cmd.append('--quiet')
rpm_cmd.append(spec_path)
# Determine the binary rpm names that should be built out of this spec
# file
# Note that some of these may not be really built (if the file
# list is empty)
nvr_string = "%{name}-%{version}-%{release}"
src_rpm = nvr_string + ".src.rpm"
non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
src_rpm, non_src_rpm, spec_path)
out = os.popen(q_cmd)
try:
binary_rpms = []
source_rpm = None
while 1:
line = out.readline()
if not line:
break
l = string.split(string.strip(line))
assert(len(l) == 2)
binary_rpms.append(l[1])
# The source rpm is named after the first entry in the spec file
if source_rpm is None:
source_rpm = l[0]
status = out.close()
if status:
raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))
finally:
out.close()
self.spawn(rpm_cmd)
if not self.dry_run:
if not self.binary_only:
srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
assert(os.path.exists(srpm))
self.move_file(srpm, self.dist_dir)
if not self.source_only:
for rpm in binary_rpms:
rpm = os.path.join(rpm_dir['RPMS'], rpm)
if os.path.exists(rpm):
self.move_file(rpm, self.dist_dir)
# run()
def _dist_path(self, path):
return os.path.join(self.dist_dir, os.path.basename(path))
def _make_spec_file(self):
"""Generate the text of an RPM spec file and return it as a
list of strings (one per line).
"""
# definitions and headers
spec_file = [
'%define name ' + self.distribution.get_name(),
'%define version ' + self.distribution.get_version().replace('-','_'),
'%define unmangled_version ' + self.distribution.get_version(),
'%define release ' + self.release.replace('-','_'),
'',
'Summary: ' + self.distribution.get_description(),
]
# put locale summaries into spec file
# XXX not supported for now (hard to put a dictionary
# in a config file -- arg!)
#for locale in self.summaries.keys():
# spec_file.append('Summary(%s): %s' % (locale,
# self.summaries[locale]))
spec_file.extend([
'Name: %{name}',
'Version: %{version}',
'Release: %{release}',])
# XXX yuck! this filename is available from the "sdist" command,
# but only after it has run: and we create the spec file before
# running "sdist", in case of --spec-only.
if self.use_bzip2:
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.bz2')
else:
spec_file.append('Source0: %{name}-%{unmangled_version}.tar.gz')
spec_file.extend([
'License: ' + self.distribution.get_license(),
'Group: ' + self.group,
'BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot',
'Prefix: %{_prefix}', ])
if not self.force_arch:
# noarch if no extension modules
if not self.distribution.has_ext_modules():
spec_file.append('BuildArch: noarch')
else:
spec_file.append( 'BuildArch: %s' % self.force_arch )
for field in ('Vendor',
'Packager',
'Provides',
'Requires',
'Conflicts',
'Obsoletes',
):
val = getattr(self, string.lower(field))
if isinstance(val, list):
spec_file.append('%s: %s' % (field, string.join(val)))
elif val is not None:
spec_file.append('%s: %s' % (field, val))
if self.distribution.get_url() != 'UNKNOWN':
spec_file.append('Url: ' + self.distribution.get_url())
if self.distribution_name:
spec_file.append('Distribution: ' + self.distribution_name)
if self.build_requires:
spec_file.append('BuildRequires: ' +
string.join(self.build_requires))
if self.icon:
spec_file.append('Icon: ' + os.path.basename(self.icon))
if self.no_autoreq:
spec_file.append('AutoReq: 0')
spec_file.extend([
'',
'%description',
self.distribution.get_long_description()
])
# put locale descriptions into spec file
# XXX again, suppressed because config file syntax doesn't
# easily support this ;-(
#for locale in self.descriptions.keys():
# spec_file.extend([
# '',
# '%description -l ' + locale,
# self.descriptions[locale],
# ])
# rpm scripts
# figure out default build script
def_setup_call = "%s %s" % (self.python,os.path.basename(sys.argv[0]))
def_build = "%s build" % def_setup_call
if self.use_rpm_opt_flags:
def_build = 'env CFLAGS="$RPM_OPT_FLAGS" ' + def_build
# insert contents of files
# XXX this is kind of misleading: user-supplied options are files
# that we open and interpolate into the spec file, but the defaults
# are just text that we drop in as-is. Hmmm.
install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT '
'--record=INSTALLED_FILES') % def_setup_call
script_options = [
('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"),
('build', 'build_script', def_build),
('install', 'install_script', install_cmd),
('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"),
('verifyscript', 'verify_script', None),
('pre', 'pre_install', None),
('post', 'post_install', None),
('preun', 'pre_uninstall', None),
('postun', 'post_uninstall', None),
]
for (rpm_opt, attr, default) in script_options:
# Insert contents of file referred to, if no file is referred to
# use 'default' as contents of script
val = getattr(self, attr)
if val or default:
spec_file.extend([
'',
'%' + rpm_opt,])
if val:
spec_file.extend(string.split(open(val, 'r').read(), '\n'))
else:
spec_file.append(default)
# files section
spec_file.extend([
'',
'%files -f INSTALLED_FILES',
'%defattr(-,root,root)',
])
if self.doc_files:
spec_file.append('%doc ' + string.join(self.doc_files))
if self.changelog:
spec_file.extend([
'',
'%changelog',])
spec_file.extend(self.changelog)
return spec_file
# _make_spec_file ()
def _format_changelog(self, changelog):
"""Format the changelog correctly and convert it to a list of strings
"""
if not changelog:
return changelog
new_changelog = []
for line in string.split(string.strip(changelog), '\n'):
line = string.strip(line)
if line[0] == '*':
new_changelog.extend(['', line])
elif line[0] == '-':
new_changelog.append(line)
else:
new_changelog.append(' ' + line)
# strip trailing newline inserted by first changelog entry
if not new_changelog[0]:
del new_changelog[0]
return new_changelog
# _format_changelog()
# class bdist_rpm
|
gpl-3.0
|
[
624,
13350,
14,
1531,
14,
17403,
63,
14191,
199,
199,
29452,
314,
12577,
283,
17403,
63,
14191,
7,
1414,
334,
981,
820,
10793,
1350,
436,
3366,
199,
5613,
10477,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
747,
199,
646,
1059,
199,
199,
504,
7065,
14,
1018,
492,
5817,
199,
504,
7065,
14,
1757,
492,
10990,
199,
504,
7065,
14,
493,
63,
1974,
492,
2218,
63,
493,
199,
504,
7065,
14,
2550,
492,
334,
12012,
1208,
16546,
12,
12577,
10397,
547,
12,
2892,
12577,
25212,
12,
12577,
4858,
547,
9,
199,
504,
7065,
492,
943,
199,
199,
533,
26308,
63,
14191,
334,
3110,
304,
339,
1369,
275,
298,
981,
376,
820,
10793,
4084,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
17403,
13,
1095,
4009,
488,
12,
268,
298,
1095,
2082,
367,
6425,
6137,
10208,
1288,
267,
661,
14191,
13,
1095,
4009,
488,
12,
268,
298,
1095,
2082,
367,
6425,
820,
10793,
83,
334,
4322,
370,
8441,
14191,
4451,
1334,
298,
268,
4320,
17403,
13,
1095,
27,
1471,
506,
2013,
367,
820,
10793,
499,
13185,
267,
661,
2686,
13,
694,
4009,
283,
68,
297,
268,
298,
3619,
370,
5324,
4242,
820,
10793,
1584,
315,
298,
268,
7340,
460,
1275,
1650,
1584,
340,
1553,
1650,
13,
2118,
13185,
267,
661,
1548,
4009,
488,
12,
268,
298,
515,
370,
2018,
12693,
370,
7508,
13,
600,
315,
314,
1275,
1650,
570,
298,
268,
7340,
885,
26,
8441,
1548,
60,
531,
1288,
267,
661,
970,
13,
1548,
297,
488,
12,
268,
298,
8726,
13,
600,
314,
5835,
931,
370,
314,
1453,
2018,
12693,
315,
298,
268,
298,
1589,
1275,
1650,
570,
1288,
267,
661,
1650,
13,
2118,
297,
488,
12,
268,
298,
2118,
30943,
3158,
570,
1288,
267,
661,
1365,
13,
2118,
297,
488,
12,
268,
298,
2118,
3550,
1350,
820,
10793,
1288,
267,
661,
3008,
13,
2118,
297,
488,
12,
268,
298,
2118,
3550,
3366,
820,
10793,
1288,
267,
661,
1180,
13,
66,
3065,
18,
297,
488,
12,
268,
298,
1180,
330,
3065,
18,
3140,
402,
11756,
370,
1218,
1350,
4084,
1288,
398,
327,
16917,
3404,
13,
576,
26,
4634,
820,
10793,
13,
6100,
370,
5324,
315,
314,
3272,
2884,
12,
267,
327,
1325,
4839,
370,
2621,
315,
314,
1275,
1650,
570,
1553,
880,
781,
1852,
3520,
1511,
267,
327,
370,
298,
17403,
63,
14191,
1674,
221,
710,
16819,
365,
626,
1706,
10246,
3955,
5324,
642,
267,
327,
2256,
315,
3272,
14,
4128,
12,
22160,
2985,
787,
402,
2518,
2867,
370,
267,
327,
17169,
652,
641,
314,
1414,
1004,
14,
267,
661,
4972,
13,
354,
4009,
488,
12,
268,
298,
354,
402,
314,
334,
14091,
9,
4084,
370,
1314,
642,
298,
268,
298,
32067,
12966,
19943,
1397,
10,
314,
536,
402,
314,
859,
4084,
1,
13185,
267,
661,
923,
4009,
488,
12,
268,
298,
2491,
12505,
359,
885,
26,
8441,
23753,
15,
23624,
60,
937,
1288,
267,
661,
3221,
4009,
488,
12,
268,
298,
32067,
4683,
1329,
1288,
267,
661,
2171,
4009,
488,
12,
268,
298,
32067,
3012,
1329,
1288,
267,
661,
9884,
4009,
488,
12,
268,
298,
32067,
8441,
9884,
4451,
334,
5902,
14,
8441,
5691,
69,
699,
674,
665,
20241,
32,
2694,
14,
957,
3072,
531,
298,
268,
7369,
885,
26,
11075,
281,
503,
4132,
687,
3272,
2884,
31937,
267,
661,
1389,
1456,
4009,
488,
12,
268,
298,
32067,
1706,
1456,
334,
5902,
14,
8441,
42,
5865,
30795,
665,
74,
5865,
32,
2694,
14,
846,
3072,
531,
2,
268,
7369,
885,
26,
20868,
31937,
267,
661,
1301,
13,
1725,
4009,
488,
12,
268,
298,
513,
402,
3794,
1584,
334,
2638,
503,
10029,
13,
12794,
13185,
267,
661,
23436,
4009,
488,
12,
268,
298,
32067,
1570,
793,
1288,
267,
661,
4677,
4009,
488,
12,
268,
298,
354,
402,
7016,
570,
1288,
267,
661,
20121,
4009,
488,
12,
268,
298,
10732,
2741,
701,
642,
2559,
1288,
267,
661,
6537,
4009,
488,
12,
268,
298,
10732,
1415,
701,
642,
2559,
1288,
267,
661,
22654,
4009,
488,
12,
268,
298,
10732,
1314,
12395,
543,
642,
2559,
1288,
267,
661,
1506,
13,
6537,
4009,
488,
12,
268,
298,
10732,
1415,
370,
1900,
642,
2559,
1288,
267,
661,
2873,
31750,
4009,
488,
12,
268,
298,
10732,
6326,
24985,
701,
642,
2559,
1288,
267,
661,
889,
13,
27082,
81,
297,
488,
12,
268,
298,
1117,
440,
5847,
8671,
5124,
1288,
398,
327,
24367,
370,
5452,
1380,
10015,
820,
10793,
267,
661,
3250,
13,
808,
297,
283,
75,
297,
268,
298,
13196,
1133,
3633,
1536,
820,
10793,
1900,
2082,
1288,
267,
661,
889,
13,
3250,
13,
808,
297,
488,
12,
268,
298,
3118,
1536,
820,
10793,
1900,
2082,
359,
885,
31937,
267,
661,
1180,
13,
14191,
13,
2992,
13,
2469,
297,
488,
12,
268,
298,
2014,
543,
820,
10793,
63,
5123,
63,
4831,
1380,
10015,
687,
1350,
820,
10793,
1288,
267,
661,
889,
13,
14191,
13,
2992,
13,
2469,
297,
488,
12,
268,
298,
1117,
440,
986,
1263,
820,
10793,
25149,
370,
6365,
1288,
267,
661,
14191,
19,
13,
632,
297,
488,
12,
268,
298,
32067,
650,
7163,
818,
334,
885,
13185,
267,
661,
14191,
18,
13,
632,
297,
488,
12,
268,
298,
32067,
499,
7163,
818,
1288,
398,
327,
2654,
314,
12604,
5784,
367,
9176,
3537,
10554,
267,
661,
10837,
13,
1579,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
19924,
48,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
1506,
13,
1579,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
22974,
7669,
402,
820,
10793,
10015,
1288,
398,
661,
657,
13,
3174,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
876,
13,
16811,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
3174,
13,
1579,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
20514,
1761,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
1932,
13,
3174,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
2963,
13,
16811,
7669,
402,
820,
10793,
10015,
1288,
398,
661,
657,
13,
19502,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
876,
13,
1734,
16811,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
1932,
13,
19502,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
2963
] |
[
13350,
14,
1531,
14,
17403,
63,
14191,
199,
199,
29452,
314,
12577,
283,
17403,
63,
14191,
7,
1414,
334,
981,
820,
10793,
1350,
436,
3366,
199,
5613,
10477,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
984,
199,
646,
747,
199,
646,
1059,
199,
199,
504,
7065,
14,
1018,
492,
5817,
199,
504,
7065,
14,
1757,
492,
10990,
199,
504,
7065,
14,
493,
63,
1974,
492,
2218,
63,
493,
199,
504,
7065,
14,
2550,
492,
334,
12012,
1208,
16546,
12,
12577,
10397,
547,
12,
2892,
12577,
25212,
12,
12577,
4858,
547,
9,
199,
504,
7065,
492,
943,
199,
199,
533,
26308,
63,
14191,
334,
3110,
304,
339,
1369,
275,
298,
981,
376,
820,
10793,
4084,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
17403,
13,
1095,
4009,
488,
12,
268,
298,
1095,
2082,
367,
6425,
6137,
10208,
1288,
267,
661,
14191,
13,
1095,
4009,
488,
12,
268,
298,
1095,
2082,
367,
6425,
820,
10793,
83,
334,
4322,
370,
8441,
14191,
4451,
1334,
298,
268,
4320,
17403,
13,
1095,
27,
1471,
506,
2013,
367,
820,
10793,
499,
13185,
267,
661,
2686,
13,
694,
4009,
283,
68,
297,
268,
298,
3619,
370,
5324,
4242,
820,
10793,
1584,
315,
298,
268,
7340,
460,
1275,
1650,
1584,
340,
1553,
1650,
13,
2118,
13185,
267,
661,
1548,
4009,
488,
12,
268,
298,
515,
370,
2018,
12693,
370,
7508,
13,
600,
315,
314,
1275,
1650,
570,
298,
268,
7340,
885,
26,
8441,
1548,
60,
531,
1288,
267,
661,
970,
13,
1548,
297,
488,
12,
268,
298,
8726,
13,
600,
314,
5835,
931,
370,
314,
1453,
2018,
12693,
315,
298,
268,
298,
1589,
1275,
1650,
570,
1288,
267,
661,
1650,
13,
2118,
297,
488,
12,
268,
298,
2118,
30943,
3158,
570,
1288,
267,
661,
1365,
13,
2118,
297,
488,
12,
268,
298,
2118,
3550,
1350,
820,
10793,
1288,
267,
661,
3008,
13,
2118,
297,
488,
12,
268,
298,
2118,
3550,
3366,
820,
10793,
1288,
267,
661,
1180,
13,
66,
3065,
18,
297,
488,
12,
268,
298,
1180,
330,
3065,
18,
3140,
402,
11756,
370,
1218,
1350,
4084,
1288,
398,
327,
16917,
3404,
13,
576,
26,
4634,
820,
10793,
13,
6100,
370,
5324,
315,
314,
3272,
2884,
12,
267,
327,
1325,
4839,
370,
2621,
315,
314,
1275,
1650,
570,
1553,
880,
781,
1852,
3520,
1511,
267,
327,
370,
298,
17403,
63,
14191,
1674,
221,
710,
16819,
365,
626,
1706,
10246,
3955,
5324,
642,
267,
327,
2256,
315,
3272,
14,
4128,
12,
22160,
2985,
787,
402,
2518,
2867,
370,
267,
327,
17169,
652,
641,
314,
1414,
1004,
14,
267,
661,
4972,
13,
354,
4009,
488,
12,
268,
298,
354,
402,
314,
334,
14091,
9,
4084,
370,
1314,
642,
298,
268,
298,
32067,
12966,
19943,
1397,
10,
314,
536,
402,
314,
859,
4084,
1,
13185,
267,
661,
923,
4009,
488,
12,
268,
298,
2491,
12505,
359,
885,
26,
8441,
23753,
15,
23624,
60,
937,
1288,
267,
661,
3221,
4009,
488,
12,
268,
298,
32067,
4683,
1329,
1288,
267,
661,
2171,
4009,
488,
12,
268,
298,
32067,
3012,
1329,
1288,
267,
661,
9884,
4009,
488,
12,
268,
298,
32067,
8441,
9884,
4451,
334,
5902,
14,
8441,
5691,
69,
699,
674,
665,
20241,
32,
2694,
14,
957,
3072,
531,
298,
268,
7369,
885,
26,
11075,
281,
503,
4132,
687,
3272,
2884,
31937,
267,
661,
1389,
1456,
4009,
488,
12,
268,
298,
32067,
1706,
1456,
334,
5902,
14,
8441,
42,
5865,
30795,
665,
74,
5865,
32,
2694,
14,
846,
3072,
531,
2,
268,
7369,
885,
26,
20868,
31937,
267,
661,
1301,
13,
1725,
4009,
488,
12,
268,
298,
513,
402,
3794,
1584,
334,
2638,
503,
10029,
13,
12794,
13185,
267,
661,
23436,
4009,
488,
12,
268,
298,
32067,
1570,
793,
1288,
267,
661,
4677,
4009,
488,
12,
268,
298,
354,
402,
7016,
570,
1288,
267,
661,
20121,
4009,
488,
12,
268,
298,
10732,
2741,
701,
642,
2559,
1288,
267,
661,
6537,
4009,
488,
12,
268,
298,
10732,
1415,
701,
642,
2559,
1288,
267,
661,
22654,
4009,
488,
12,
268,
298,
10732,
1314,
12395,
543,
642,
2559,
1288,
267,
661,
1506,
13,
6537,
4009,
488,
12,
268,
298,
10732,
1415,
370,
1900,
642,
2559,
1288,
267,
661,
2873,
31750,
4009,
488,
12,
268,
298,
10732,
6326,
24985,
701,
642,
2559,
1288,
267,
661,
889,
13,
27082,
81,
297,
488,
12,
268,
298,
1117,
440,
5847,
8671,
5124,
1288,
398,
327,
24367,
370,
5452,
1380,
10015,
820,
10793,
267,
661,
3250,
13,
808,
297,
283,
75,
297,
268,
298,
13196,
1133,
3633,
1536,
820,
10793,
1900,
2082,
1288,
267,
661,
889,
13,
3250,
13,
808,
297,
488,
12,
268,
298,
3118,
1536,
820,
10793,
1900,
2082,
359,
885,
31937,
267,
661,
1180,
13,
14191,
13,
2992,
13,
2469,
297,
488,
12,
268,
298,
2014,
543,
820,
10793,
63,
5123,
63,
4831,
1380,
10015,
687,
1350,
820,
10793,
1288,
267,
661,
889,
13,
14191,
13,
2992,
13,
2469,
297,
488,
12,
268,
298,
1117,
440,
986,
1263,
820,
10793,
25149,
370,
6365,
1288,
267,
661,
14191,
19,
13,
632,
297,
488,
12,
268,
298,
32067,
650,
7163,
818,
334,
885,
13185,
267,
661,
14191,
18,
13,
632,
297,
488,
12,
268,
298,
32067,
499,
7163,
818,
1288,
398,
327,
2654,
314,
12604,
5784,
367,
9176,
3537,
10554,
267,
661,
10837,
13,
1579,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
19924,
48,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
1506,
13,
1579,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
22974,
7669,
402,
820,
10793,
10015,
1288,
398,
661,
657,
13,
3174,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
876,
13,
16811,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
3174,
13,
1579,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
20514,
1761,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
1932,
13,
3174,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
2963,
13,
16811,
7669,
402,
820,
10793,
10015,
1288,
398,
661,
657,
13,
19502,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
876,
13,
1734,
16811,
7669,
402,
820,
10793,
10015,
1288,
267,
661,
1932,
13,
19502,
4009,
488,
12,
268,
298,
17768,
282,
2884,
367,
314,
2963,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Alucard24/Alucard-Kernel-jfltexx
|
tools/perf/scripts/python/netdev-times.py
|
11271
|
15048
|
# Display a process of packets and processed time.
# It helps us to investigate networking or network device.
#
# options
# tx: show only tx chart
# rx: show only rx chart
# dev=: show only thing related to specified device
# debug: work with debug mode. It shows buffer status.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import *
all_event_list = []; # insert all tracepoint event related with this script
irq_dic = {}; # key is cpu and value is a list which stacks irqs
# which raise NET_RX softirq
net_rx_dic = {}; # key is cpu and value include time of NET_RX softirq-entry
# and a list which stacks receive
receive_hunk_list = []; # a list which include a sequence of receive events
rx_skb_list = []; # received packet list for matching
# skb_copy_datagram_iovec
buffer_budget = 65536; # the budget of rx_skb_list, tx_queue_list and
# tx_xmit_list
of_count_rx_skb_list = 0; # overflow count
tx_queue_list = []; # list of packets which pass through dev_queue_xmit
of_count_tx_queue_list = 0; # overflow count
tx_xmit_list = []; # list of packets which pass through dev_hard_start_xmit
of_count_tx_xmit_list = 0; # overflow count
tx_free_list = []; # list of packets which is freed
# options
show_tx = 0;
show_rx = 0;
dev = 0; # store a name of device specified by option "dev="
debug = 0;
# indices of event_info tuple
EINFO_IDX_NAME= 0
EINFO_IDX_CONTEXT=1
EINFO_IDX_CPU= 2
EINFO_IDX_TIME= 3
EINFO_IDX_PID= 4
EINFO_IDX_COMM= 5
# Calculate a time interval(msec) from src(nsec) to dst(nsec)
def diff_msec(src, dst):
return (dst - src) / 1000000.0
# Display a process of transmitting a packet
def print_transmit(hunk):
if dev != 0 and hunk['dev'].find(dev) < 0:
return
print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \
(hunk['dev'], hunk['len'],
nsecs_secs(hunk['queue_t']),
nsecs_nsecs(hunk['queue_t'])/1000,
diff_msec(hunk['queue_t'], hunk['xmit_t']),
diff_msec(hunk['xmit_t'], hunk['free_t']))
# Format for displaying rx packet processing
PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)"
PF_SOFT_ENTRY=" softirq_entry(+%.3fmsec)"
PF_NAPI_POLL= " napi_poll_exit(+%.3fmsec %s)"
PF_JOINT= " |"
PF_WJOINT= " | |"
PF_NET_RECV= " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)"
PF_NET_RX= " |---netif_rx(+%.3fmsec skb=%x)"
PF_CPY_DGRAM= " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)"
PF_KFREE_SKB= " | kfree_skb(+%.3fmsec location=%x)"
PF_CONS_SKB= " | consume_skb(+%.3fmsec)"
# Display a process of received packets and interrputs associated with
# a NET_RX softirq
def print_receive(hunk):
show_hunk = 0
irq_list = hunk['irq_list']
cpu = irq_list[0]['cpu']
base_t = irq_list[0]['irq_ent_t']
# check if this hunk should be showed
if dev != 0:
for i in range(len(irq_list)):
if irq_list[i]['name'].find(dev) >= 0:
show_hunk = 1
break
else:
show_hunk = 1
if show_hunk == 0:
return
print "%d.%06dsec cpu=%d" % \
(nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)
for i in range(len(irq_list)):
print PF_IRQ_ENTRY % \
(diff_msec(base_t, irq_list[i]['irq_ent_t']),
irq_list[i]['irq'], irq_list[i]['name'])
print PF_JOINT
irq_event_list = irq_list[i]['event_list']
for j in range(len(irq_event_list)):
irq_event = irq_event_list[j]
if irq_event['event'] == 'netif_rx':
print PF_NET_RX % \
(diff_msec(base_t, irq_event['time']),
irq_event['skbaddr'])
print PF_JOINT
print PF_SOFT_ENTRY % \
diff_msec(base_t, hunk['sirq_ent_t'])
print PF_JOINT
event_list = hunk['event_list']
for i in range(len(event_list)):
event = event_list[i]
if event['event_name'] == 'napi_poll':
print PF_NAPI_POLL % \
(diff_msec(base_t, event['event_t']), event['dev'])
if i == len(event_list) - 1:
print ""
else:
print PF_JOINT
else:
print PF_NET_RECV % \
(diff_msec(base_t, event['event_t']), event['skbaddr'],
event['len'])
if 'comm' in event.keys():
print PF_WJOINT
print PF_CPY_DGRAM % \
(diff_msec(base_t, event['comm_t']),
event['pid'], event['comm'])
elif 'handle' in event.keys():
print PF_WJOINT
if event['handle'] == "kfree_skb":
print PF_KFREE_SKB % \
(diff_msec(base_t,
event['comm_t']),
event['location'])
elif event['handle'] == "consume_skb":
print PF_CONS_SKB % \
diff_msec(base_t,
event['comm_t'])
print PF_JOINT
def trace_begin():
global show_tx
global show_rx
global dev
global debug
for i in range(len(sys.argv)):
if i == 0:
continue
arg = sys.argv[i]
if arg == 'tx':
show_tx = 1
elif arg =='rx':
show_rx = 1
elif arg.find('dev=',0, 4) >= 0:
dev = arg[4:]
elif arg == 'debug':
debug = 1
if show_tx == 0 and show_rx == 0:
show_tx = 1
show_rx = 1
def trace_end():
# order all events in time
all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME],
b[EINFO_IDX_TIME]))
# process all events
for i in range(len(all_event_list)):
event_info = all_event_list[i]
name = event_info[EINFO_IDX_NAME]
if name == 'irq__softirq_exit':
handle_irq_softirq_exit(event_info)
elif name == 'irq__softirq_entry':
handle_irq_softirq_entry(event_info)
elif name == 'irq__softirq_raise':
handle_irq_softirq_raise(event_info)
elif name == 'irq__irq_handler_entry':
handle_irq_handler_entry(event_info)
elif name == 'irq__irq_handler_exit':
handle_irq_handler_exit(event_info)
elif name == 'napi__napi_poll':
handle_napi_poll(event_info)
elif name == 'net__netif_receive_skb':
handle_netif_receive_skb(event_info)
elif name == 'net__netif_rx':
handle_netif_rx(event_info)
elif name == 'skb__skb_copy_datagram_iovec':
handle_skb_copy_datagram_iovec(event_info)
elif name == 'net__net_dev_queue':
handle_net_dev_queue(event_info)
elif name == 'net__net_dev_xmit':
handle_net_dev_xmit(event_info)
elif name == 'skb__kfree_skb':
handle_kfree_skb(event_info)
elif name == 'skb__consume_skb':
handle_consume_skb(event_info)
# display receive hunks
if show_rx:
for i in range(len(receive_hunk_list)):
print_receive(receive_hunk_list[i])
# display transmit hunks
if show_tx:
print " dev len Qdisc " \
" netdevice free"
for i in range(len(tx_free_list)):
print_transmit(tx_free_list[i])
if debug:
print "debug buffer status"
print "----------------------------"
print "xmit Qdisc:remain:%d overflow:%d" % \
(len(tx_queue_list), of_count_tx_queue_list)
print "xmit netdevice:remain:%d overflow:%d" % \
(len(tx_xmit_list), of_count_tx_xmit_list)
print "receive:remain:%d overflow:%d" % \
(len(rx_skb_list), of_count_rx_skb_list)
# called from perf, when it finds a correspoinding event
def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_exit(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__softirq_raise(name, context, cpu, sec, nsec, pid, comm, vec):
if symbol_str("irq__softirq_entry", "vec", vec) != "NET_RX":
return
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, vec)
all_event_list.append(event_info)
def irq__irq_handler_entry(name, context, cpu, sec, nsec, pid, comm,
irq, irq_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
irq, irq_name)
all_event_list.append(event_info)
def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, irq, ret):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret)
all_event_list.append(event_info)
def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, napi, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
napi, dev_name)
all_event_list.append(event_info)
def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__netif_rx(name, context, cpu, sec, nsec, pid, comm, skbaddr,
skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_queue(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, dev_name)
all_event_list.append(event_info)
def net__net_dev_xmit(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen, rc, dev_name):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen, rc ,dev_name)
all_event_list.append(event_info)
def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm,
skbaddr, protocol, location):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, protocol, location)
all_event_list.append(event_info)
def skb__consume_skb(name, context, cpu, sec, nsec, pid, comm, skbaddr):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr)
all_event_list.append(event_info)
def skb__skb_copy_datagram_iovec(name, context, cpu, sec, nsec, pid, comm,
skbaddr, skblen):
event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm,
skbaddr, skblen)
all_event_list.append(event_info)
def handle_irq_handler_entry(event_info):
(name, context, cpu, time, pid, comm, irq, irq_name) = event_info
if cpu not in irq_dic.keys():
irq_dic[cpu] = []
irq_record = {'irq':irq, 'name':irq_name, 'cpu':cpu, 'irq_ent_t':time}
irq_dic[cpu].append(irq_record)
def handle_irq_handler_exit(event_info):
(name, context, cpu, time, pid, comm, irq, ret) = event_info
if cpu not in irq_dic.keys():
return
irq_record = irq_dic[cpu].pop()
if irq != irq_record['irq']:
return
irq_record.update({'irq_ext_t':time})
# if an irq doesn't include NET_RX softirq, drop.
if 'event_list' in irq_record.keys():
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_raise(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'sirq_raise'})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_irq_softirq_entry(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
net_rx_dic[cpu] = {'sirq_ent_t':time, 'event_list':[]}
def handle_irq_softirq_exit(event_info):
(name, context, cpu, time, pid, comm, vec) = event_info
irq_list = []
event_list = 0
if cpu in irq_dic.keys():
irq_list = irq_dic[cpu]
del irq_dic[cpu]
if cpu in net_rx_dic.keys():
sirq_ent_t = net_rx_dic[cpu]['sirq_ent_t']
event_list = net_rx_dic[cpu]['event_list']
del net_rx_dic[cpu]
if irq_list == [] or event_list == 0:
return
rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time,
'irq_list':irq_list, 'event_list':event_list}
# merge information realted to a NET_RX softirq
receive_hunk_list.append(rec_data)
def handle_napi_poll(event_info):
(name, context, cpu, time, pid, comm, napi, dev_name) = event_info
if cpu in net_rx_dic.keys():
event_list = net_rx_dic[cpu]['event_list']
rec_data = {'event_name':'napi_poll',
'dev':dev_name, 'event_t':time}
event_list.append(rec_data)
def handle_netif_rx(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu not in irq_dic.keys() \
or len(irq_dic[cpu]) == 0:
return
irq_record = irq_dic[cpu].pop()
if 'event_list' in irq_record.keys():
irq_event_list = irq_record['event_list']
else:
irq_event_list = []
irq_event_list.append({'time':time, 'event':'netif_rx',
'skbaddr':skbaddr, 'skblen':skblen, 'dev_name':dev_name})
irq_record.update({'event_list':irq_event_list})
irq_dic[cpu].append(irq_record)
def handle_netif_receive_skb(event_info):
global of_count_rx_skb_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
if cpu in net_rx_dic.keys():
rec_data = {'event_name':'netif_receive_skb',
'event_t':time, 'skbaddr':skbaddr, 'len':skblen}
event_list = net_rx_dic[cpu]['event_list']
event_list.append(rec_data)
rx_skb_list.insert(0, rec_data)
if len(rx_skb_list) > buffer_budget:
rx_skb_list.pop()
of_count_rx_skb_list += 1
def handle_net_dev_queue(event_info):
global of_count_tx_queue_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, dev_name) = event_info
skb = {'dev':dev_name, 'skbaddr':skbaddr, 'len':skblen, 'queue_t':time}
tx_queue_list.insert(0, skb)
if len(tx_queue_list) > buffer_budget:
tx_queue_list.pop()
of_count_tx_queue_list += 1
def handle_net_dev_xmit(event_info):
global of_count_tx_xmit_list
(name, context, cpu, time, pid, comm,
skbaddr, skblen, rc, dev_name) = event_info
if rc == 0: # NETDEV_TX_OK
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
skb['xmit_t'] = time
tx_xmit_list.insert(0, skb)
del tx_queue_list[i]
if len(tx_xmit_list) > buffer_budget:
tx_xmit_list.pop()
of_count_tx_xmit_list += 1
return
def handle_kfree_skb(event_info):
(name, context, cpu, time, pid, comm,
skbaddr, protocol, location) = event_info
for i in range(len(tx_queue_list)):
skb = tx_queue_list[i]
if skb['skbaddr'] == skbaddr:
del tx_queue_list[i]
return
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if rec_data['skbaddr'] == skbaddr:
rec_data.update({'handle':"kfree_skb",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
def handle_consume_skb(event_info):
(name, context, cpu, time, pid, comm, skbaddr) = event_info
for i in range(len(tx_xmit_list)):
skb = tx_xmit_list[i]
if skb['skbaddr'] == skbaddr:
skb['free_t'] = time
tx_free_list.append(skb)
del tx_xmit_list[i]
return
def handle_skb_copy_datagram_iovec(event_info):
(name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info
for i in range(len(rx_skb_list)):
rec_data = rx_skb_list[i]
if skbaddr == rec_data['skbaddr']:
rec_data.update({'handle':"skb_copy_datagram_iovec",
'comm':comm, 'pid':pid, 'comm_t':time})
del rx_skb_list[i]
return
|
gpl-2.0
|
[
3,
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,
198,
3,
1104,
340,
642,
19988,
1077,
506,
2498,
379,
199,
198,
692,
4866,
1137,
378,
26,
507,
198,
509,
284,
315,
1425,
8,
552,
8,
7277,
63,
513,
2298,
686,
198,
692,
10476,
63,
513
] |
[
12175,
282,
2112,
402,
14593,
436,
7686,
900,
14,
199,
3,
2779,
22577,
2739,
370,
315,
27174,
323,
2784,
316,
503,
2784,
2243,
14,
199,
3,
199,
3,
1511,
199,
3,
4773,
26,
2498,
1454,
4773,
10943,
199,
3,
12951,
26,
2498,
1454,
12951,
10943,
199,
3,
4866,
29,
26,
2498,
1454,
8377,
4048,
370,
2013,
2243,
199,
3,
3105,
26,
1736,
543,
3105,
818,
14,
2779,
13703,
3335,
2004,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
627,
199,
199,
452,
63,
1430,
63,
513,
275,
22750,
327,
5518,
1006,
3307,
1403,
1566,
4048,
543,
642,
2884,
199,
7277,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
365,
282,
769,
1314,
26733,
10476,
83,
1598,
327,
1314,
746,
18340,
63,
15361,
880,
15493,
199,
846,
63,
6872,
63,
5000,
275,
27978,
327,
790,
365,
5033,
436,
574,
2387,
900,
402,
18340,
63,
15361,
880,
15493,
13,
2373,
686,
327,
436,
282,
769,
1314,
26733,
9128,
199,
9391,
63,
17428,
63,
513,
275,
22750,
327,
282,
769,
1314,
2387,
282,
3414,
402,
9128,
4474,
199,
6872,
63,
6852,
63,
513,
275,
22750,
327,
3086,
3644,
769,
367,
4877,
686,
755,
327,
11448,
63,
1574,
63,
25443,
63,
30463,
199,
199,
2738,
63,
16501,
275,
25980,
27,
327,
314,
1032,
14080,
402,
12951,
63,
6852,
63,
513,
12,
4773,
63,
1825,
63,
513,
436,
686,
755,
327,
4773,
63,
14217,
63,
513,
199,
1618,
63,
835,
63,
6872,
63,
6852,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
1825,
63,
513,
275,
22750,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
1825,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
1825,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
14217,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
986,
4012,
4866,
63,
8726,
63,
928,
63,
14217,
199,
1618,
63,
835,
63,
2347,
63,
14217,
63,
513,
275,
378,
27,
327,
15784,
2338,
199,
199,
2347,
63,
4624,
63,
513,
275,
22750,
221,
327,
769,
402,
14593,
1314,
365,
23694,
199,
199,
3,
1511,
199,
2384,
63,
2347,
275,
378,
27,
199,
2384,
63,
6872,
275,
378,
27,
199,
2374,
275,
378,
27,
327,
3877,
282,
536,
402,
2243,
2013,
701,
945,
298,
2374,
628,
199,
1757,
275,
378,
27,
199,
199,
3,
4918,
402,
1566,
63,
815,
2008,
199,
26556,
63,
20037,
63,
2339,
29,
257,
378,
199,
26556,
63,
20037,
63,
9059,
29,
17,
199,
26556,
63,
20037,
63,
11011,
29,
259,
499,
199,
26556,
63,
20037,
63,
4961,
29,
257,
650,
199,
26556,
63,
20037,
63,
16098,
29,
259,
841,
199,
26556,
63,
20037,
63,
5378,
29,
257,
959,
199,
199,
3,
12707,
282,
900,
6252,
8,
19764,
9,
687,
2928,
8,
78,
3321,
9,
370,
5042,
8,
78,
3321,
9,
199,
318,
3915,
63,
19764,
8,
2164,
12,
5042,
304,
199,
198,
1107,
334,
5119,
446,
2928,
9,
1182,
19492,
14,
16,
199,
199,
3,
12175,
282,
2112,
402,
27754,
1337,
282,
3644,
199,
318,
870,
63,
31399,
8,
17428,
304,
199,
198,
692,
4866,
1137,
378,
436,
19988,
459,
2374,
2278,
1623,
8,
2374,
9,
665,
378,
26,
507,
198,
1107,
199,
198,
1361,
2071,
23,
83,
450,
21,
68,
450,
22,
68,
4111,
1690,
68,
3321,
450,
713,
14,
19,
25154,
420,
450,
713,
14,
19,
25154,
2,
450,
971,
507,
198,
8,
17428,
459,
2374,
995,
19988,
459,
552,
995,
507,
198,
9618,
63,
4855,
8,
17428,
459,
1825,
63,
84,
3815,
507,
198,
9618,
63,
9618,
8,
17428,
459,
1825,
63,
84,
1105,
15,
5279,
12,
507,
198,
3028,
63,
19764,
8,
17428,
459,
1825,
63,
84,
995,
19988,
459,
14217,
63,
84,
3815,
507,
198,
3028,
63,
19764,
8,
17428,
459,
14217,
63,
84,
995,
19988,
459,
4624,
63,
84,
5156,
199,
199,
3,
9701,
367,
20589,
12951,
3644,
6661,
199,
10966,
63,
3927,
49,
63,
7285,
29,
298,
221,
10476,
63,
2373,
28643,
19,
25154,
10476,
2458,
68,
2689,
83,
2924,
199,
10966,
63,
26999,
63,
7285,
628,
221,
880,
15493,
63,
2373,
28643,
19,
25154,
2924,
199,
10966,
63,
46,
3735,
63,
16428,
29,
298,
221,
302,
1246,
63,
6843,
63,
2224,
28643,
19,
25154,
450,
83,
2924,
199,
10966,
63,
24931,
29,
258,
298,
260,
1204,
2,
199,
10966,
63,
55,
24931,
29,
259,
298,
260,
1204,
3322,
1204,
2,
199,
10966,
63,
7278,
63,
9481,
54,
29,
221,
298,
260,
1204,
2595,
20869,
63,
9391,
63,
6852,
28643,
19,
25154,
11448,
2458,
88,
822,
2458,
68,
2924,
199,
10966,
63,
7278,
63,
15361,
29,
259,
298,
260,
1204,
2595,
20869,
63,
6872,
28643,
19,
25154,
11448,
2458,
88,
2924,
199,
10966,
63,
2890,
57,
63,
25351,
29,
298,
260,
1204,
420,
11448,
63,
1574,
63,
25443,
63,
30463,
28643,
19,
25154,
450,
68,
2689,
83,
2924,
199,
10966,
63,
17706,
5271,
63,
8656,
34,
29,
298,
260,
1204,
420,
1022,
4624,
63,
6852,
28643,
19,
25154,
2909,
2458,
88,
2924,
199,
10966,
63,
1864,
51,
63,
8656,
34,
29,
221,
298,
260,
1204,
420,
9451,
63,
6852,
28643,
19,
25154,
2924,
199,
199,
3,
12175,
282,
2112,
402,
3086,
14593,
436,
1640,
82,
524,
83,
4568,
543,
199,
3,
282,
18340,
63,
15361,
880,
15493,
199,
318,
870,
63,
9391,
8,
17428,
304,
199,
198,
2384,
63,
17428,
275,
378,
199,
198,
7277,
63,
513,
275,
19988,
459,
7277,
63,
513,
418,
199,
198,
3541,
275,
10476,
63,
513,
59,
16,
2733,
3541,
418,
199,
198,
1095,
63,
84,
275,
10476,
63,
513,
59,
16,
2733,
7277,
63,
484,
63,
84,
418,
199,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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
] |
waytai/django
|
django/template/backends/dummy.py
|
480
|
2037
|
# Since this package contains a "django" module, this is required on Python 2.
from __future__ import absolute_import
import errno
import io
import string
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.template import Origin, TemplateDoesNotExist
from django.utils.html import conditional_escape
from .base import BaseEngine
from .utils import csrf_input_lazy, csrf_token_lazy
class TemplateStrings(BaseEngine):
app_dirname = 'template_strings'
def __init__(self, params):
params = params.copy()
options = params.pop('OPTIONS').copy()
if options:
raise ImproperlyConfigured(
"Unknown options: {}".format(", ".join(options)))
super(TemplateStrings, self).__init__(params)
def from_string(self, template_code):
return Template(template_code)
def get_template(self, template_name):
tried = []
for template_file in self.iter_template_filenames(template_name):
try:
with io.open(template_file, encoding=settings.FILE_CHARSET) as fp:
template_code = fp.read()
except IOError as e:
if e.errno == errno.ENOENT:
tried.append((
Origin(template_file, template_name, self),
'Source does not exist',
))
continue
raise
return Template(template_code)
else:
raise TemplateDoesNotExist(template_name, tried=tried, backend=self)
class Template(string.Template):
def render(self, context=None, request=None):
if context is None:
context = {}
else:
context = {k: conditional_escape(v) for k, v in context.items()}
if request is not None:
context['csrf_input'] = csrf_input_lazy(request)
context['csrf_token'] = csrf_token_lazy(request)
return self.safe_substitute(context)
|
bsd-3-clause
|
[
3,
9336,
642,
2559,
3509,
282,
298,
1176,
2,
859,
12,
642,
365,
1415,
641,
2018,
499,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
7554,
199,
646,
5890,
199,
646,
1059,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1160,
492,
31534,
12,
27193,
199,
504,
1639,
14,
1208,
14,
1360,
492,
12303,
63,
3765,
199,
199,
504,
1275,
1095,
492,
3523,
8524,
199,
504,
1275,
1208,
492,
19213,
63,
1210,
63,
6395,
12,
19213,
63,
1418,
63,
6395,
421,
199,
533,
5458,
12672,
8,
1563,
8524,
304,
339,
1145,
63,
3475,
275,
283,
1160,
63,
5465,
7,
339,
347,
636,
826,
721,
277,
12,
1862,
304,
267,
1862,
275,
1862,
14,
1574,
342,
267,
1511,
275,
1862,
14,
1935,
360,
8808,
1959,
1574,
342,
267,
340,
1511,
26,
288,
746,
11897,
8,
355,
298,
5912,
1511,
26,
8352,
908,
11854,
3680,
904,
8,
1419,
1724,
267,
1613,
8,
4231,
12672,
12,
291,
2843,
826,
721,
1162,
9,
339,
347,
687,
63,
875,
8,
277,
12,
1978,
63,
600,
304,
267,
372,
5458,
8,
1160,
63,
600,
9,
339,
347,
664,
63,
1160,
8,
277,
12,
1978,
63,
354,
304,
267,
16416,
275,
942,
267,
367,
1978,
63,
493,
315,
291,
14,
1661,
63,
1160,
63,
10309,
8,
1160,
63,
354,
304,
288,
862,
26,
355,
543,
5890,
14,
1490,
8,
1160,
63,
493,
12,
2644,
29,
1751,
14,
3817,
63,
23969,
9,
465,
4090,
26,
490,
1978,
63,
600,
275,
4090,
14,
739,
342,
288,
871,
5925,
465,
325,
26,
355,
340,
325,
14,
7931,
508,
7554,
14,
20465,
26,
490,
16416,
14,
740,
1332,
717,
31534,
8,
1160,
63,
493,
12,
1978,
63,
354,
12,
291,
395,
717,
283,
2980,
1630,
440,
2187,
297,
490,
5082,
490,
1980,
355,
746,
953,
372,
5458,
8,
1160,
63,
600,
9,
398,
587,
26,
288,
746,
27193,
8,
1160,
63,
354,
12,
16416,
29,
599,
379,
12,
4865,
29,
277,
9,
421,
199,
533,
5458,
8,
875,
14,
4231,
304,
339,
347,
3795,
8,
277,
12,
1067,
29,
403,
12,
1056,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
587,
26,
288,
1067,
275,
469,
75,
26,
12303,
63,
3765,
8,
86,
9,
367,
1022,
12,
373,
315,
1067,
14,
1744,
12737,
267,
340,
1056,
365,
440,
488,
26,
288,
1067,
459,
10088,
63,
1210,
418,
275,
19213,
63,
1210,
63,
6395,
8,
1069,
9,
288,
1067,
459,
10088,
63,
1418,
418,
275,
19213,
63,
1418,
63,
6395,
8,
1069,
9,
267,
372,
291,
14,
3489,
63,
20374,
8,
1100,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9336,
642,
2559,
3509,
282,
298,
1176,
2,
859,
12,
642,
365,
1415,
641,
2018,
499,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
7554,
199,
646,
5890,
199,
646,
1059,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1160,
492,
31534,
12,
27193,
199,
504,
1639,
14,
1208,
14,
1360,
492,
12303,
63,
3765,
199,
199,
504,
1275,
1095,
492,
3523,
8524,
199,
504,
1275,
1208,
492,
19213,
63,
1210,
63,
6395,
12,
19213,
63,
1418,
63,
6395,
421,
199,
533,
5458,
12672,
8,
1563,
8524,
304,
339,
1145,
63,
3475,
275,
283,
1160,
63,
5465,
7,
339,
347,
636,
826,
721,
277,
12,
1862,
304,
267,
1862,
275,
1862,
14,
1574,
342,
267,
1511,
275,
1862,
14,
1935,
360,
8808,
1959,
1574,
342,
267,
340,
1511,
26,
288,
746,
11897,
8,
355,
298,
5912,
1511,
26,
8352,
908,
11854,
3680,
904,
8,
1419,
1724,
267,
1613,
8,
4231,
12672,
12,
291,
2843,
826,
721,
1162,
9,
339,
347,
687,
63,
875,
8,
277,
12,
1978,
63,
600,
304,
267,
372,
5458,
8,
1160,
63,
600,
9,
339,
347,
664,
63,
1160,
8,
277,
12,
1978,
63,
354,
304,
267,
16416,
275,
942,
267,
367,
1978,
63,
493,
315,
291,
14,
1661,
63,
1160,
63,
10309,
8,
1160,
63,
354,
304,
288,
862,
26,
355,
543,
5890,
14,
1490,
8,
1160,
63,
493,
12,
2644,
29,
1751,
14,
3817,
63,
23969,
9,
465,
4090,
26,
490,
1978,
63,
600,
275,
4090,
14,
739,
342,
288,
871,
5925,
465,
325,
26,
355,
340,
325,
14,
7931,
508,
7554,
14,
20465,
26,
490,
16416,
14,
740,
1332,
717,
31534,
8,
1160,
63,
493,
12,
1978,
63,
354,
12,
291,
395,
717,
283,
2980,
1630,
440,
2187,
297,
490,
5082,
490,
1980,
355,
746,
953,
372,
5458,
8,
1160,
63,
600,
9,
398,
587,
26,
288,
746,
27193,
8,
1160,
63,
354,
12,
16416,
29,
599,
379,
12,
4865,
29,
277,
9,
421,
199,
533,
5458,
8,
875,
14,
4231,
304,
339,
347,
3795,
8,
277,
12,
1067,
29,
403,
12,
1056,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
587,
26,
288,
1067,
275,
469,
75,
26,
12303,
63,
3765,
8,
86,
9,
367,
1022,
12,
373,
315,
1067,
14,
1744,
12737,
267,
340,
1056,
365,
440,
488,
26,
288,
1067,
459,
10088,
63,
1210,
418,
275,
19213,
63,
1210,
63,
6395,
8,
1069,
9,
288,
1067,
459,
10088,
63,
1418,
418,
275,
19213,
63,
1418,
63,
6395,
8,
1069,
9,
267,
372,
291,
14,
3489,
63,
20374,
8,
1100,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
mflu/openvstorage_centos
|
ovs/extensions/storage/volatile/dummystore.py
|
2
|
3090
|
# Copyright 2014 CloudFounders 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.
"""
Dummy volatile module
"""
import time
import json
class DummyVolatileStore(object):
"""
This is a dummy volatile store that makes use of a local json file
"""
_path = '/tmp/dummyvolatile.json'
_storage = {}
_timeout = {}
@staticmethod
def clean():
"""
Empties the store
"""
import os
try:
os.remove(DummyVolatileStore._path)
except OSError:
pass
def _read(self):
"""
Reads the local json file
"""
try:
f = open(self._path, 'r')
data = json.loads(f.read())
f.close()
except IOError:
data = {'t': {}, 's': {}}
return data
def get(self, key, default=None):
"""
Retrieves a certain value for a given key
"""
data = self._read()
if key in data['t'] and data['t'][key] > time.time():
value = data['s'].get(key)
if 'ovs_primarykeys_' in key:
value[0] = set(value[0])
return value
return default
def set(self, key, value, timeout=99999999):
"""
Sets the value for a key to a given value
"""
if 'ovs_primarykeys_' in key:
value[0] = list(value[0])
data = self._read()
data['s'][key] = value
data['t'][key] = time.time() + timeout
self._save(data)
def add(self, key, value, timeout=99999999):
"""
Adds a given key to the store, expecting the key does not exists yet
"""
data = self._read()
if key not in data['s']:
self.set(key, value, timeout)
return True
else:
return False
def delete(self, key):
"""
Deletes a given key from the store
"""
data = self._read()
if key in data['s']:
del data['s'][key]
del data['t'][key]
self._save(data)
def incr(self, key, delta=1):
"""
Increments the value of the key, expecting it exists
"""
data = self._read()
if key in data['s']:
data['s'][key] += delta
self._save(data)
return True
return False
def _save(self, data):
"""
Saves the local json file
"""
rawdata = json.dumps(data, sort_keys=True, indent=2)
f = open(self._path, 'w+')
f.write(rawdata)
f.close()
|
apache-2.0
|
[
3,
1898,
6927,
8142,
15563,
7138,
83,
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,
199,
624,
199,
11324,
5236,
23590,
859,
199,
624,
199,
646,
900,
199,
646,
2022,
421,
199,
533,
9762,
16969,
23590,
5502,
8,
785,
304,
272,
408,
272,
961,
365,
282,
7283,
5236,
23590,
3877,
626,
7704,
675,
402,
282,
2257,
2022,
570,
272,
408,
272,
485,
515,
275,
1994,
2791,
15,
5869,
32059,
14,
1001,
7,
272,
485,
3494,
275,
1052,
272,
485,
2593,
275,
1052,
339,
768,
4639,
272,
347,
3633,
837,
267,
408,
267,
662,
311,
1417,
314,
3877,
267,
408,
267,
492,
747,
398,
862,
26,
288,
747,
14,
2168,
8,
11324,
16969,
23590,
5502,
423,
515,
9,
267,
871,
6440,
26,
288,
986,
339,
347,
485,
739,
8,
277,
304,
267,
408,
267,
26129,
314,
2257,
2022,
570,
267,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
277,
423,
515,
12,
283,
82,
358,
288,
666,
275,
2022,
14,
3640,
8,
70,
14,
739,
1012,
288,
289,
14,
1600,
342,
267,
871,
5925,
26,
288,
666,
275,
791,
84,
356,
5479,
283,
83,
356,
24312,
267,
372,
666,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
267,
27940,
282,
9842,
574,
367,
282,
1627,
790,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
315,
666,
459,
84,
418,
436,
666,
459,
84,
3488,
498,
61,
690,
900,
14,
521,
837,
288,
574,
275,
666,
459,
83,
2278,
362,
8,
498,
9,
288,
340,
283,
22409,
63,
3327,
1612,
8650,
315,
790,
26,
355,
574,
59,
16,
61,
275,
663,
8,
585,
59,
16,
566,
288,
372,
574,
267,
372,
849,
339,
347,
663,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
13453,
304,
267,
408,
267,
10729,
314,
574,
367,
282,
790,
370,
282,
1627,
574,
267,
408,
267,
340,
283,
22409,
63,
3327,
1612,
8650,
315,
790,
26,
288,
574,
59,
16,
61,
275,
769,
8,
585,
59,
16,
566,
267,
666,
275,
291,
423,
739,
342,
267,
666,
459,
83,
3488,
498,
61,
275,
574,
267,
666,
459,
84,
3488,
498,
61,
275,
900,
14,
521,
342,
435,
2653,
267,
291,
423,
2117,
8,
576,
9,
339,
347,
1050,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
13453,
304,
267,
408,
267,
15747,
282,
1627,
790,
370,
314,
3877,
12,
21055,
314,
790,
1630,
440,
3495,
5966,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
440,
315,
666,
459,
83,
2565,
288,
291,
14,
409,
8,
498,
12,
574,
12,
2653,
9,
288,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
3145,
8,
277,
12,
790,
304,
267,
408,
267,
28382,
282,
1627,
790,
687,
314,
3877,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
315,
666,
459,
83,
2565,
288,
2150,
666,
459,
83,
3488,
498,
61,
288,
2150,
666,
459,
84,
3488,
498,
61,
288,
291,
423,
2117,
8,
576,
9,
339,
347,
315,
1556,
8,
277,
12,
790,
12,
5762,
29,
17,
304,
267,
408,
267,
1010,
1353,
1470,
314,
574,
402,
314,
790,
12,
21055,
652,
3495,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
315,
666,
459,
83,
2565,
288,
666,
459,
83,
3488,
498,
61,
847,
5762,
288,
291,
423,
2117,
8,
576,
9,
288,
372,
715,
267,
372,
756,
339,
347,
485,
2117,
8,
277,
12,
666,
304,
267,
408,
267,
428,
7047,
314,
2257,
2022,
570,
267,
408,
267,
15705,
275,
2022,
14,
4180,
8,
576,
12,
4069,
63,
1612,
29,
549,
12,
4363,
29,
18,
9,
267,
289,
275,
1551,
8,
277,
423,
515,
12,
283,
87,
13854,
267,
289,
14,
952,
8,
14901,
9,
267,
289,
14,
1600,
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
] |
[
1898,
6927,
8142,
15563,
7138,
83,
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,
199,
624,
199,
11324,
5236,
23590,
859,
199,
624,
199,
646,
900,
199,
646,
2022,
421,
199,
533,
9762,
16969,
23590,
5502,
8,
785,
304,
272,
408,
272,
961,
365,
282,
7283,
5236,
23590,
3877,
626,
7704,
675,
402,
282,
2257,
2022,
570,
272,
408,
272,
485,
515,
275,
1994,
2791,
15,
5869,
32059,
14,
1001,
7,
272,
485,
3494,
275,
1052,
272,
485,
2593,
275,
1052,
339,
768,
4639,
272,
347,
3633,
837,
267,
408,
267,
662,
311,
1417,
314,
3877,
267,
408,
267,
492,
747,
398,
862,
26,
288,
747,
14,
2168,
8,
11324,
16969,
23590,
5502,
423,
515,
9,
267,
871,
6440,
26,
288,
986,
339,
347,
485,
739,
8,
277,
304,
267,
408,
267,
26129,
314,
2257,
2022,
570,
267,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
277,
423,
515,
12,
283,
82,
358,
288,
666,
275,
2022,
14,
3640,
8,
70,
14,
739,
1012,
288,
289,
14,
1600,
342,
267,
871,
5925,
26,
288,
666,
275,
791,
84,
356,
5479,
283,
83,
356,
24312,
267,
372,
666,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
267,
27940,
282,
9842,
574,
367,
282,
1627,
790,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
315,
666,
459,
84,
418,
436,
666,
459,
84,
3488,
498,
61,
690,
900,
14,
521,
837,
288,
574,
275,
666,
459,
83,
2278,
362,
8,
498,
9,
288,
340,
283,
22409,
63,
3327,
1612,
8650,
315,
790,
26,
355,
574,
59,
16,
61,
275,
663,
8,
585,
59,
16,
566,
288,
372,
574,
267,
372,
849,
339,
347,
663,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
13453,
304,
267,
408,
267,
10729,
314,
574,
367,
282,
790,
370,
282,
1627,
574,
267,
408,
267,
340,
283,
22409,
63,
3327,
1612,
8650,
315,
790,
26,
288,
574,
59,
16,
61,
275,
769,
8,
585,
59,
16,
566,
267,
666,
275,
291,
423,
739,
342,
267,
666,
459,
83,
3488,
498,
61,
275,
574,
267,
666,
459,
84,
3488,
498,
61,
275,
900,
14,
521,
342,
435,
2653,
267,
291,
423,
2117,
8,
576,
9,
339,
347,
1050,
8,
277,
12,
790,
12,
574,
12,
2653,
29,
13453,
304,
267,
408,
267,
15747,
282,
1627,
790,
370,
314,
3877,
12,
21055,
314,
790,
1630,
440,
3495,
5966,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
440,
315,
666,
459,
83,
2565,
288,
291,
14,
409,
8,
498,
12,
574,
12,
2653,
9,
288,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
3145,
8,
277,
12,
790,
304,
267,
408,
267,
28382,
282,
1627,
790,
687,
314,
3877,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
315,
666,
459,
83,
2565,
288,
2150,
666,
459,
83,
3488,
498,
61,
288,
2150,
666,
459,
84,
3488,
498,
61,
288,
291,
423,
2117,
8,
576,
9,
339,
347,
315,
1556,
8,
277,
12,
790,
12,
5762,
29,
17,
304,
267,
408,
267,
1010,
1353,
1470,
314,
574,
402,
314,
790,
12,
21055,
652,
3495,
267,
408,
267,
666,
275,
291,
423,
739,
342,
267,
340,
790,
315,
666,
459,
83,
2565,
288,
666,
459,
83,
3488,
498,
61,
847,
5762,
288,
291,
423,
2117,
8,
576,
9,
288,
372,
715,
267,
372,
756,
339,
347,
485,
2117,
8,
277,
12,
666,
304,
267,
408,
267,
428,
7047,
314,
2257,
2022,
570,
267,
408,
267,
15705,
275,
2022,
14,
4180,
8,
576,
12,
4069,
63,
1612,
29,
549,
12,
4363,
29,
18,
9,
267,
289,
275,
1551,
8,
277,
423,
515,
12,
283,
87,
13854,
267,
289,
14,
952,
8,
14901,
9,
267,
289,
14,
1600,
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,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
karthik-suresh/horizon
|
openstack_dashboard/dashboards/identity/users/tables.py
|
4
|
9272
|
# 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 django.core import exceptions as django_exceptions
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import exceptions as horizon_exceptions
from horizon import forms
from horizon import messages
from horizon import tables
from openstack_dashboard import api
from openstack_dashboard import policy
ENABLE = 0
DISABLE = 1
KEYSTONE_V2_ENABLED = api.keystone.VERSIONS.active < 3
class CreateUserLink(tables.LinkAction):
name = "create"
verbose_name = _("Create User")
url = "horizon:identity:users:create"
classes = ("ajax-modal",)
icon = "plus"
policy_rules = (('identity', 'identity:create_grant'),
("identity", "identity:create_user"),
("identity", "identity:list_roles"),
("identity", "identity:list_projects"),)
def allowed(self, request, user):
return api.keystone.keystone_can_edit_user()
class EditUserLink(policy.PolicyTargetMixin, tables.LinkAction):
name = "edit"
verbose_name = _("Edit")
url = "horizon:identity:users:update"
classes = ("ajax-modal",)
icon = "pencil"
policy_rules = (("identity", "identity:update_user"),
("identity", "identity:list_projects"),)
policy_target_attrs = (("user_id", "id"),)
def allowed(self, request, user):
return api.keystone.keystone_can_edit_user()
class ChangePasswordLink(policy.PolicyTargetMixin, tables.LinkAction):
name = "change_password"
verbose_name = _("Change Password")
url = "horizon:identity:users:change_password"
classes = ("ajax-modal",)
icon = "key"
policy_rules = (("identity", "identity:change_password"),)
policy_target_attrs = (("user_id", "id"),)
def allowed(self, request, user):
return api.keystone.keystone_can_edit_user()
class ToggleEnabled(policy.PolicyTargetMixin, tables.BatchAction):
name = "toggle"
@staticmethod
def action_present(count):
return (
ungettext_lazy(
u"Enable User",
u"Enable Users",
count
),
ungettext_lazy(
u"Disable User",
u"Disable Users",
count
),
)
@staticmethod
def action_past(count):
return (
ungettext_lazy(
u"Enabled User",
u"Enabled Users",
count
),
ungettext_lazy(
u"Disabled User",
u"Disabled Users",
count
),
)
classes = ("btn-toggle",)
policy_rules = (("identity", "identity:update_user"),)
policy_target_attrs = (("user_id", "id"),)
def allowed(self, request, user=None):
if not api.keystone.keystone_can_edit_user():
return False
self.enabled = True
if not user:
return self.enabled
self.enabled = user.enabled
if self.enabled:
self.current_present_action = DISABLE
else:
self.current_present_action = ENABLE
return True
def update(self, request, user=None):
super(ToggleEnabled, self).update(request, user)
if user and user.id == request.user.id:
self.attrs["disabled"] = "disabled"
def action(self, request, obj_id):
if obj_id == request.user.id:
messages.info(request, _('You cannot disable the user you are '
'currently logged in as.'))
return
if self.enabled:
api.keystone.user_update_enabled(request, obj_id, False)
self.current_past_action = DISABLE
else:
api.keystone.user_update_enabled(request, obj_id, True)
self.current_past_action = ENABLE
class DeleteUsersAction(tables.DeleteAction):
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete User",
u"Delete Users",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted User",
u"Deleted Users",
count
)
policy_rules = (("identity", "identity:delete_user"),)
def allowed(self, request, datum):
if not api.keystone.keystone_can_edit_user() or \
(datum and datum.id == request.user.id):
return False
return True
def delete(self, request, obj_id):
api.keystone.user_delete(request, obj_id)
class UserFilterAction(tables.FilterAction):
def filter(self, table, users, filter_string):
"""Naive case-insensitive search."""
q = filter_string.lower()
return [user for user in users
if q in user.name.lower()
or q in (getattr(user, 'email', None) or '').lower()]
class UpdateRow(tables.Row):
ajax = True
def get_data(self, request, user_id):
user_info = api.keystone.user_get(request, user_id, admin=True)
return user_info
class UpdateCell(tables.UpdateAction):
def allowed(self, request, user, cell):
return api.keystone.keystone_can_edit_user() and \
policy.check((("identity", "identity:update_user"),),
request)
def update_cell(self, request, datum, user_id,
cell_name, new_cell_value):
try:
user_obj = datum
setattr(user_obj, cell_name, new_cell_value)
kwargs = {}
attr_to_keyword_map = {
'name': 'name',
'description': 'description',
'email': 'email',
'enabled': 'enabled',
'project_id': 'project'
}
for key in attr_to_keyword_map:
value = getattr(user_obj, key, None)
keyword_name = attr_to_keyword_map[key]
if value is not None:
kwargs[keyword_name] = value
api.keystone.user_update(request, user_obj, **kwargs)
except horizon_exceptions.Conflict:
message = _("This name is already taken.")
messages.warning(request, message)
raise django_exceptions.ValidationError(message)
except Exception:
horizon_exceptions.handle(request, ignore=True)
return False
return True
class UsersTable(tables.DataTable):
STATUS_CHOICES = (
("true", True),
("false", False)
)
name = tables.Column('name',
link="horizon:identity:users:detail",
verbose_name=_('User Name'),
form_field=forms.CharField(),
update_action=UpdateCell)
description = tables.Column(lambda obj: getattr(obj, 'description', None),
verbose_name=_('Description'),
hidden=KEYSTONE_V2_ENABLED,
form_field=forms.CharField(
widget=forms.Textarea(attrs={'rows': 4}),
required=False),
update_action=UpdateCell)
email = tables.Column('email', verbose_name=_('Email'),
form_field=forms.EmailField(required=False),
update_action=UpdateCell,
filters=(lambda v: defaultfilters
.default_if_none(v, ""),
defaultfilters.escape,
defaultfilters.urlize)
)
# Default tenant is not returned from Keystone currently.
# default_tenant = tables.Column('default_tenant',
# verbose_name=_('Default Project'))
id = tables.Column('id', verbose_name=_('User ID'),
attrs={'data-type': 'uuid'})
enabled = tables.Column('enabled', verbose_name=_('Enabled'),
status=True,
status_choices=STATUS_CHOICES,
filters=(defaultfilters.yesno,
defaultfilters.capfirst),
empty_value="False")
class Meta(object):
name = "users"
verbose_name = _("Users")
row_actions = (EditUserLink, ChangePasswordLink, ToggleEnabled,
DeleteUsersAction)
table_actions = (UserFilterAction, CreateUserLink, DeleteUsersAction)
row_class = UpdateRow
|
apache-2.0
|
[
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
492,
4967,
465,
1639,
63,
3924,
199,
504,
1639,
14,
1160,
492,
849,
4273,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
6893,
492,
26843,
63,
6395,
199,
199,
504,
21726,
492,
4967,
465,
21726,
63,
3924,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
199,
504,
21726,
492,
6716,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
492,
4592,
199,
199,
8898,
275,
378,
199,
13052,
275,
413,
199,
3078,
840,
4817,
63,
54,
18,
63,
15704,
275,
2986,
14,
19143,
14,
26358,
14,
2682,
665,
650,
421,
199,
533,
2790,
1899,
3834,
8,
5987,
14,
3834,
3310,
304,
272,
536,
275,
298,
981,
2,
272,
3376,
63,
354,
275,
3824,
2499,
2876,
531,
272,
1166,
275,
298,
16561,
26,
5582,
26,
3707,
26,
981,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
26360,
272,
7016,
275,
298,
6666,
2,
272,
4592,
63,
4423,
275,
13636,
5582,
297,
283,
5582,
26,
981,
63,
17362,
659,
490,
1689,
5582,
401,
298,
5582,
26,
981,
63,
751,
1288,
490,
1689,
5582,
401,
298,
5582,
26,
513,
63,
8050,
1288,
490,
1689,
5582,
401,
298,
5582,
26,
513,
63,
6776,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
304,
267,
372,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
342,
421,
199,
533,
16407,
1899,
3834,
8,
3185,
14,
4845,
4277,
4256,
12,
6716,
14,
3834,
3310,
304,
272,
536,
275,
298,
3773,
2,
272,
3376,
63,
354,
275,
3824,
4685,
531,
272,
1166,
275,
298,
16561,
26,
5582,
26,
3707,
26,
873,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
26360,
272,
7016,
275,
298,
897,
24707,
2,
272,
4592,
63,
4423,
275,
19110,
5582,
401,
298,
5582,
26,
873,
63,
751,
1288,
490,
1689,
5582,
401,
298,
5582,
26,
513,
63,
6776,
1288,
9,
272,
4592,
63,
1375,
63,
3288,
275,
19110,
751,
63,
344,
401,
298,
344,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
304,
267,
372,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
342,
421,
199,
533,
7743,
6139,
3834,
8,
3185,
14,
4845,
4277,
4256,
12,
6716,
14,
3834,
3310,
304,
272,
536,
275,
298,
1461,
63,
2060,
2,
272,
3376,
63,
354,
275,
3824,
4001,
13635,
531,
272,
1166,
275,
298,
16561,
26,
5582,
26,
3707,
26,
1461,
63,
2060,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
26360,
272,
7016,
275,
298,
498,
2,
272,
4592,
63,
4423,
275,
19110,
5582,
401,
298,
5582,
26,
1461,
63,
2060,
1288,
9,
272,
4592,
63,
1375,
63,
3288,
275,
19110,
751,
63,
344,
401,
298,
344,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
304,
267,
372,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
342,
421,
199,
533,
377,
19403,
6589,
8,
3185,
14,
4845,
4277,
4256,
12,
6716,
14,
8842,
3310,
304,
272,
536,
275,
298,
13396,
2,
339,
768,
4639,
272,
347,
1595,
63,
1881,
8,
835,
304,
267,
372,
334,
288,
26843,
63,
6395,
8,
355,
399,
2,
6476,
2876,
401,
355,
399,
2,
6476,
20123,
401,
355,
2338,
288,
2318,
288,
26843,
63,
6395,
8,
355,
399,
2,
13707,
2876,
401,
355,
399,
2,
13707,
20123,
401,
355,
2338,
288,
2318,
267,
776,
339,
768,
4639,
272,
347,
1595,
63,
18597,
8,
835,
304,
267,
372,
334,
288,
26843,
63,
6395,
8,
355,
399,
2,
6589,
2876,
401,
355,
399,
2,
6589,
20123,
401,
355,
2338,
288,
2318,
288,
26843,
63,
6395,
8,
355,
399,
2,
15049,
2876,
401,
355,
399,
2,
15049,
20123,
401,
355,
2338,
288,
2318,
267,
776,
272,
3992,
275,
1689,
9633,
13,
13396,
26360,
272,
4592,
63,
4423,
275,
19110,
5582,
401,
298,
5582,
26,
873,
63,
751,
1288,
9,
272,
4592,
63,
1375,
63,
3288,
275,
19110,
751,
63,
344,
401,
298,
344,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
29,
403,
304,
267,
340,
440,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
837,
288,
372,
756,
398,
291,
14,
3827,
275,
715,
267,
340,
440,
922,
26,
288,
372,
291,
14,
3827,
267,
291,
14,
3827,
275,
922,
14,
3827,
267,
340,
291,
14,
3827,
26,
288,
291,
14,
1818,
63,
1881,
63,
1287,
275,
32147,
267,
587,
26,
288,
291,
14,
1818,
63,
1881,
63,
1287,
275,
27926,
267,
372,
715,
339,
347,
1678,
8,
277,
12,
1056,
12,
922,
29,
403,
304,
267,
1613,
8,
24743,
6589,
12,
291,
680,
873,
8,
1069,
12,
922,
9,
267,
340,
922,
436,
922,
14,
344,
508,
1056,
14,
751,
14,
344,
26,
288,
291,
14,
3288,
905,
7011,
937,
275,
298,
7011,
2,
339,
347,
1595,
8,
277,
12,
1056,
12,
1559,
63,
344,
304,
267,
340,
1559,
63,
344,
508,
1056,
14,
751,
14,
344,
26,
288,
3788,
14,
815,
8,
1069,
12,
4018,
5556,
3913,
3507,
314,
922,
1265,
787,
283,
3660,
283,
19767,
10367,
315,
465,
12459,
288,
372,
267,
340,
291,
14,
3827,
26,
288,
2986,
14,
19143,
14,
751,
63,
873,
63,
3827,
8,
1069,
12,
1559,
63,
344,
12,
756,
9,
288,
291,
14,
1818,
63,
18597,
63,
1287,
275,
32147,
267,
587,
26,
288,
2986,
14,
19143,
14,
751,
63,
873,
63,
3827
] |
[
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
1018,
492,
4967,
465,
1639,
63,
3924,
199,
504,
1639,
14,
1160,
492,
849,
4273,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
6893,
492,
26843,
63,
6395,
199,
199,
504,
21726,
492,
4967,
465,
21726,
63,
3924,
199,
504,
21726,
492,
4513,
199,
504,
21726,
492,
3788,
199,
504,
21726,
492,
6716,
199,
504,
13869,
63,
9743,
492,
2986,
199,
504,
13869,
63,
9743,
492,
4592,
199,
199,
8898,
275,
378,
199,
13052,
275,
413,
199,
3078,
840,
4817,
63,
54,
18,
63,
15704,
275,
2986,
14,
19143,
14,
26358,
14,
2682,
665,
650,
421,
199,
533,
2790,
1899,
3834,
8,
5987,
14,
3834,
3310,
304,
272,
536,
275,
298,
981,
2,
272,
3376,
63,
354,
275,
3824,
2499,
2876,
531,
272,
1166,
275,
298,
16561,
26,
5582,
26,
3707,
26,
981,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
26360,
272,
7016,
275,
298,
6666,
2,
272,
4592,
63,
4423,
275,
13636,
5582,
297,
283,
5582,
26,
981,
63,
17362,
659,
490,
1689,
5582,
401,
298,
5582,
26,
981,
63,
751,
1288,
490,
1689,
5582,
401,
298,
5582,
26,
513,
63,
8050,
1288,
490,
1689,
5582,
401,
298,
5582,
26,
513,
63,
6776,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
304,
267,
372,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
342,
421,
199,
533,
16407,
1899,
3834,
8,
3185,
14,
4845,
4277,
4256,
12,
6716,
14,
3834,
3310,
304,
272,
536,
275,
298,
3773,
2,
272,
3376,
63,
354,
275,
3824,
4685,
531,
272,
1166,
275,
298,
16561,
26,
5582,
26,
3707,
26,
873,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
26360,
272,
7016,
275,
298,
897,
24707,
2,
272,
4592,
63,
4423,
275,
19110,
5582,
401,
298,
5582,
26,
873,
63,
751,
1288,
490,
1689,
5582,
401,
298,
5582,
26,
513,
63,
6776,
1288,
9,
272,
4592,
63,
1375,
63,
3288,
275,
19110,
751,
63,
344,
401,
298,
344,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
304,
267,
372,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
342,
421,
199,
533,
7743,
6139,
3834,
8,
3185,
14,
4845,
4277,
4256,
12,
6716,
14,
3834,
3310,
304,
272,
536,
275,
298,
1461,
63,
2060,
2,
272,
3376,
63,
354,
275,
3824,
4001,
13635,
531,
272,
1166,
275,
298,
16561,
26,
5582,
26,
3707,
26,
1461,
63,
2060,
2,
272,
3992,
275,
1689,
12774,
13,
17713,
26360,
272,
7016,
275,
298,
498,
2,
272,
4592,
63,
4423,
275,
19110,
5582,
401,
298,
5582,
26,
1461,
63,
2060,
1288,
9,
272,
4592,
63,
1375,
63,
3288,
275,
19110,
751,
63,
344,
401,
298,
344,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
304,
267,
372,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
342,
421,
199,
533,
377,
19403,
6589,
8,
3185,
14,
4845,
4277,
4256,
12,
6716,
14,
8842,
3310,
304,
272,
536,
275,
298,
13396,
2,
339,
768,
4639,
272,
347,
1595,
63,
1881,
8,
835,
304,
267,
372,
334,
288,
26843,
63,
6395,
8,
355,
399,
2,
6476,
2876,
401,
355,
399,
2,
6476,
20123,
401,
355,
2338,
288,
2318,
288,
26843,
63,
6395,
8,
355,
399,
2,
13707,
2876,
401,
355,
399,
2,
13707,
20123,
401,
355,
2338,
288,
2318,
267,
776,
339,
768,
4639,
272,
347,
1595,
63,
18597,
8,
835,
304,
267,
372,
334,
288,
26843,
63,
6395,
8,
355,
399,
2,
6589,
2876,
401,
355,
399,
2,
6589,
20123,
401,
355,
2338,
288,
2318,
288,
26843,
63,
6395,
8,
355,
399,
2,
15049,
2876,
401,
355,
399,
2,
15049,
20123,
401,
355,
2338,
288,
2318,
267,
776,
272,
3992,
275,
1689,
9633,
13,
13396,
26360,
272,
4592,
63,
4423,
275,
19110,
5582,
401,
298,
5582,
26,
873,
63,
751,
1288,
9,
272,
4592,
63,
1375,
63,
3288,
275,
19110,
751,
63,
344,
401,
298,
344,
1288,
9,
339,
347,
4370,
8,
277,
12,
1056,
12,
922,
29,
403,
304,
267,
340,
440,
2986,
14,
19143,
14,
19143,
63,
2425,
63,
3773,
63,
751,
837,
288,
372,
756,
398,
291,
14,
3827,
275,
715,
267,
340,
440,
922,
26,
288,
372,
291,
14,
3827,
267,
291,
14,
3827,
275,
922,
14,
3827,
267,
340,
291,
14,
3827,
26,
288,
291,
14,
1818,
63,
1881,
63,
1287,
275,
32147,
267,
587,
26,
288,
291,
14,
1818,
63,
1881,
63,
1287,
275,
27926,
267,
372,
715,
339,
347,
1678,
8,
277,
12,
1056,
12,
922,
29,
403,
304,
267,
1613,
8,
24743,
6589,
12,
291,
680,
873,
8,
1069,
12,
922,
9,
267,
340,
922,
436,
922,
14,
344,
508,
1056,
14,
751,
14,
344,
26,
288,
291,
14,
3288,
905,
7011,
937,
275,
298,
7011,
2,
339,
347,
1595,
8,
277,
12,
1056,
12,
1559,
63,
344,
304,
267,
340,
1559,
63,
344,
508,
1056,
14,
751,
14,
344,
26,
288,
3788,
14,
815,
8,
1069,
12,
4018,
5556,
3913,
3507,
314,
922,
1265,
787,
283,
3660,
283,
19767,
10367,
315,
465,
12459,
288,
372,
267,
340,
291,
14,
3827,
26,
288,
2986,
14,
19143,
14,
751,
63,
873,
63,
3827,
8,
1069,
12,
1559,
63,
344,
12,
756,
9,
288,
291,
14,
1818,
63,
18597,
63,
1287,
275,
32147,
267,
587,
26,
288,
2986,
14,
19143,
14,
751,
63,
873,
63,
3827,
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,
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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
] |
williamthegrey/swift
|
swift/common/ring/builder.py
|
2
|
73487
|
# Copyright (c) 2010-2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import errno
import itertools
import logging
import math
import random
import six.moves.cPickle as pickle
from copy import deepcopy
from contextlib import contextmanager
from array import array
from collections import defaultdict
import six
from six.moves import range
from time import time
from swift.common import exceptions
from swift.common.ring import RingData
from swift.common.ring.utils import tiers_for_dev, build_tier_tree, \
validate_and_normalize_address
# we can't store None's in the replica2part2dev array, so we high-jack
# the max value for magic to represent the part is not currently
# assigned to any device.
NONE_DEV = 2 ** 16 - 1
MAX_BALANCE = 999.99
MAX_BALANCE_GATHER_COUNT = 3
class RingValidationWarning(Warning):
pass
try:
# python 2.7+
from logging import NullHandler
except ImportError:
# python 2.6
class NullHandler(logging.Handler):
def emit(self, *a, **kw):
pass
class RingBuilder(object):
"""
Used to build swift.common.ring.RingData instances to be written to disk
and used with swift.common.ring.Ring instances. See bin/swift-ring-builder
for example usage.
The instance variable devs_changed indicates if the device information has
changed since the last balancing. This can be used by tools to know whether
a rebalance request is an isolated request or due to added, changed, or
removed devices.
:param part_power: number of partitions = 2**part_power.
:param replicas: number of replicas for each partition
:param min_part_hours: minimum number of hours between partition changes
"""
def __init__(self, part_power, replicas, min_part_hours):
if part_power > 32:
raise ValueError("part_power must be at most 32 (was %d)"
% (part_power,))
if replicas < 1:
raise ValueError("replicas must be at least 1 (was %.6f)"
% (replicas,))
if min_part_hours < 0:
raise ValueError("min_part_hours must be non-negative (was %d)"
% (min_part_hours,))
self.part_power = part_power
self.replicas = replicas
self.min_part_hours = min_part_hours
self.parts = 2 ** self.part_power
self.devs = []
self.devs_changed = False
self.version = 0
self.overload = 0.0
# _replica2part2dev maps from replica number to partition number to
# device id. So, for a three replica, 2**23 ring, it's an array of
# three 2**23 arrays of device ids (unsigned shorts). This can work a
# bit faster than the 2**23 array of triplet arrays of device ids in
# many circumstances. Making one big 2**23 * 3 array didn't seem to
# have any speed change; though you're welcome to try it again (it was
# a while ago, code-wise, when I last tried it).
self._replica2part2dev = None
# _last_part_moves is an array of unsigned bytes representing
# the number of hours since a given partition was last moved.
# This is used to guarantee we don't move a partition twice
# within a given number of hours (24 is my usual test). Removing
# a device overrides this behavior as it's assumed that's only
# done because of device failure.
self._last_part_moves = None
# _last_part_moves_epoch indicates the time the offsets in
# _last_part_moves is based on.
self._last_part_moves_epoch = 0
self._last_part_gather_start = 0
self._dispersion_graph = {}
self.dispersion = 0.0
self._remove_devs = []
self._ring = None
self.logger = logging.getLogger("swift.ring.builder")
if not self.logger.handlers:
self.logger.disabled = True
# silence "no handler for X" error messages
self.logger.addHandler(NullHandler())
@contextmanager
def debug(self):
"""
Temporarily enables debug logging, useful in tests, e.g.
with rb.debug():
rb.rebalance()
"""
self.logger.disabled = False
try:
yield
finally:
self.logger.disabled = True
@property
def min_part_seconds_left(self):
"""Get the total seconds until a rebalance can be performed"""
elapsed_seconds = int(time() - self._last_part_moves_epoch)
return max((self.min_part_hours * 3600) - elapsed_seconds, 0)
def weight_of_one_part(self):
"""
Returns the weight of each partition as calculated from the
total weight of all the devices.
"""
try:
return self.parts * self.replicas / \
sum(d['weight'] for d in self._iter_devs())
except ZeroDivisionError:
raise exceptions.EmptyRingError('There are no devices in this '
'ring, or all devices have been '
'deleted')
@classmethod
def from_dict(cls, builder_data):
b = cls(1, 1, 1) # Dummy values
b.copy_from(builder_data)
return b
def copy_from(self, builder):
"""
Reinitializes this RingBuilder instance from data obtained from the
builder dict given. Code example::
b = RingBuilder(1, 1, 1) # Dummy values
b.copy_from(builder)
This is to restore a RingBuilder that has had its b.to_dict()
previously saved.
"""
if hasattr(builder, 'devs'):
self.part_power = builder.part_power
self.replicas = builder.replicas
self.min_part_hours = builder.min_part_hours
self.parts = builder.parts
self.devs = builder.devs
self.devs_changed = builder.devs_changed
self.overload = builder.overload
self.version = builder.version
self._replica2part2dev = builder._replica2part2dev
self._last_part_moves_epoch = builder._last_part_moves_epoch
self._last_part_moves = builder._last_part_moves
self._last_part_gather_start = builder._last_part_gather_start
self._remove_devs = builder._remove_devs
else:
self.part_power = builder['part_power']
self.replicas = builder['replicas']
self.min_part_hours = builder['min_part_hours']
self.parts = builder['parts']
self.devs = builder['devs']
self.devs_changed = builder['devs_changed']
self.overload = builder.get('overload', 0.0)
self.version = builder['version']
self._replica2part2dev = builder['_replica2part2dev']
self._last_part_moves_epoch = builder['_last_part_moves_epoch']
self._last_part_moves = builder['_last_part_moves']
self._last_part_gather_start = builder['_last_part_gather_start']
self._dispersion_graph = builder.get('_dispersion_graph', {})
self.dispersion = builder.get('dispersion')
self._remove_devs = builder['_remove_devs']
self._ring = None
# Old builders may not have a region defined for their devices, in
# which case we default it to 1.
for dev in self._iter_devs():
dev.setdefault("region", 1)
if not self._last_part_moves_epoch:
self._last_part_moves_epoch = 0
def __deepcopy__(self, memo):
return type(self).from_dict(deepcopy(self.to_dict(), memo))
def to_dict(self):
"""
Returns a dict that can be used later with copy_from to
restore a RingBuilder. swift-ring-builder uses this to
pickle.dump the dict to a file and later load that dict into
copy_from.
"""
return {'part_power': self.part_power,
'replicas': self.replicas,
'min_part_hours': self.min_part_hours,
'parts': self.parts,
'devs': self.devs,
'devs_changed': self.devs_changed,
'version': self.version,
'overload': self.overload,
'_replica2part2dev': self._replica2part2dev,
'_last_part_moves_epoch': self._last_part_moves_epoch,
'_last_part_moves': self._last_part_moves,
'_last_part_gather_start': self._last_part_gather_start,
'_dispersion_graph': self._dispersion_graph,
'dispersion': self.dispersion,
'_remove_devs': self._remove_devs}
def change_min_part_hours(self, min_part_hours):
"""
Changes the value used to decide if a given partition can be moved
again. This restriction is to give the overall system enough time to
settle a partition to its new location before moving it to yet another
location. While no data would be lost if a partition is moved several
times quickly, it could make that data unreachable for a short period
of time.
This should be set to at least the average full partition replication
time. Starting it at 24 hours and then lowering it to what the
replicator reports as the longest partition cycle is best.
:param min_part_hours: new value for min_part_hours
"""
self.min_part_hours = min_part_hours
def set_replicas(self, new_replica_count):
"""
Changes the number of replicas in this ring.
If the new replica count is sufficiently different that
self._replica2part2dev will change size, sets
self.devs_changed. This is so tools like
bin/swift-ring-builder can know to write out the new ring
rather than bailing out due to lack of balance change.
"""
old_slots_used = int(self.parts * self.replicas)
new_slots_used = int(self.parts * new_replica_count)
if old_slots_used != new_slots_used:
self.devs_changed = True
self.replicas = new_replica_count
def set_overload(self, overload):
self.overload = overload
def get_ring(self):
"""
Get the ring, or more specifically, the swift.common.ring.RingData.
This ring data is the minimum required for use of the ring. The ring
builder itself keeps additional data such as when partitions were last
moved.
"""
# We cache the self._ring value so multiple requests for it don't build
# it multiple times. Be sure to set self._ring = None whenever the ring
# will need to be rebuilt.
if not self._ring:
# Make devs list (with holes for deleted devices) and not including
# builder-specific extra attributes.
devs = [None] * len(self.devs)
for dev in self._iter_devs():
devs[dev['id']] = dict((k, v) for k, v in dev.items()
if k not in ('parts', 'parts_wanted'))
# Copy over the replica+partition->device assignments, the device
# information, and the part_shift value (the number of bits to
# shift an unsigned int >I right to obtain the partition for the
# int).
if not self._replica2part2dev:
self._ring = RingData([], devs, 32 - self.part_power)
else:
self._ring = \
RingData([array('H', p2d) for p2d in
self._replica2part2dev],
devs, 32 - self.part_power)
return self._ring
def add_dev(self, dev):
"""
Add a device to the ring. This device dict should have a minimum of the
following keys:
====== ===============================================================
id unique integer identifier amongst devices. Defaults to the next
id if the 'id' key is not provided in the dict
weight a float of the relative weight of this device as compared to
others; this indicates how many partitions the builder will try
to assign to this device
region integer indicating which region the device is in
zone integer indicating which zone the device is in; a given
partition will not be assigned to multiple devices within the
same (region, zone) pair if there is any alternative
ip the ip address of the device
port the tcp port of the device
device the device's name on disk (sdb1, for example)
meta general use 'extra' field; for example: the online date, the
hardware description
====== ===============================================================
.. note::
This will not rebalance the ring immediately as you may want to
make multiple changes for a single rebalance.
:param dev: device dict
:returns: id of device (not used in the tree anymore, but unknown
users may depend on it)
"""
if 'id' not in dev:
dev['id'] = 0
if self.devs:
try:
dev['id'] = self.devs.index(None)
except ValueError:
dev['id'] = len(self.devs)
if dev['id'] < len(self.devs) and self.devs[dev['id']] is not None:
raise exceptions.DuplicateDeviceError(
'Duplicate device id: %d' % dev['id'])
# Add holes to self.devs to ensure self.devs[dev['id']] will be the dev
while dev['id'] >= len(self.devs):
self.devs.append(None)
dev['weight'] = float(dev['weight'])
dev['parts'] = 0
self.devs[dev['id']] = dev
self.devs_changed = True
self.version += 1
return dev['id']
def set_dev_weight(self, dev_id, weight):
"""
Set the weight of a device. This should be called rather than just
altering the weight key in the device dict directly, as the builder
will need to rebuild some internal state to reflect the change.
.. note::
This will not rebalance the ring immediately as you may want to
make multiple changes for a single rebalance.
:param dev_id: device id
:param weight: new weight for device
"""
if any(dev_id == d['id'] for d in self._remove_devs):
raise ValueError("Can not set weight of dev_id %s because it "
"is marked for removal" % (dev_id,))
self.devs[dev_id]['weight'] = weight
self.devs_changed = True
self.version += 1
def remove_dev(self, dev_id):
"""
Remove a device from the ring.
.. note::
This will not rebalance the ring immediately as you may want to
make multiple changes for a single rebalance.
:param dev_id: device id
"""
dev = self.devs[dev_id]
dev['weight'] = 0
self._remove_devs.append(dev)
self.devs_changed = True
self.version += 1
def rebalance(self, seed=None):
"""
Rebalance the ring.
This is the main work function of the builder, as it will assign and
reassign partitions to devices in the ring based on weights, distinct
zones, recent reassignments, etc.
The process doesn't always perfectly assign partitions (that'd take a
lot more analysis and therefore a lot more time -- I had code that did
that before). Because of this, it keeps rebalancing until the device
skew (number of partitions a device wants compared to what it has) gets
below 1% or doesn't change by more than 1% (only happens with ring that
can't be balanced no matter what).
:returns: (number_of_partitions_altered, resulting_balance,
number_of_removed_devices)
"""
# count up the devs, and cache some stuff
num_devices = 0
for dev in self._iter_devs():
dev['tiers'] = tiers_for_dev(dev)
if dev['weight'] > 0:
num_devices += 1
if num_devices < self.replicas:
raise exceptions.RingValidationError(
"Replica count of %(replicas)s requires more "
"than %(num_devices)s devices" % {
'replicas': self.replicas,
'num_devices': num_devices,
})
if seed is not None:
random.seed(seed)
self._ring = None
old_replica2part2dev = copy.deepcopy(self._replica2part2dev)
if self._last_part_moves is None:
self.logger.debug("New builder; performing initial balance")
self._last_part_moves = array('B', itertools.repeat(0, self.parts))
self._update_last_part_moves()
replica_plan = self._build_replica_plan()
self._set_parts_wanted(replica_plan)
assign_parts = defaultdict(list)
# gather parts from replica count adjustment
self._adjust_replica2part2dev_size(assign_parts)
# gather parts from failed devices
removed_devs = self._gather_parts_from_failed_devices(assign_parts)
# gather parts for dispersion (N.B. this only picks up parts that
# *must* disperse according to the replica plan)
self._gather_parts_for_dispersion(assign_parts, replica_plan)
# we'll gather a few times, or until we archive the plan
for gather_count in range(MAX_BALANCE_GATHER_COUNT):
self._gather_parts_for_balance(assign_parts, replica_plan)
if not assign_parts:
# most likely min part hours
finish_status = 'Unable to finish'
break
assign_parts_list = list(assign_parts.items())
# shuffle the parts to be reassigned, we have no preference on the
# order in which the replica plan is fulfilled.
random.shuffle(assign_parts_list)
# reset assign_parts map for next iteration
assign_parts = defaultdict(list)
num_part_replicas = sum(len(r) for p, r in assign_parts_list)
self.logger.debug("Gathered %d parts", num_part_replicas)
self._reassign_parts(assign_parts_list, replica_plan)
self.logger.debug("Assigned %d parts", num_part_replicas)
if not sum(d['parts_wanted'] < 0 for d in
self._iter_devs()):
finish_status = 'Finished'
break
else:
finish_status = 'Unable to finish'
self.logger.debug('%s rebalance plan after %s attempts' % (
finish_status, gather_count + 1))
self.devs_changed = False
self.version += 1
changed_parts = self._build_dispersion_graph(old_replica2part2dev)
# clean up the cache
for dev in self._iter_devs():
dev.pop('tiers', None)
return changed_parts, self.get_balance(), removed_devs
def _build_dispersion_graph(self, old_replica2part2dev=None):
"""
Build a dict of all tiers in the cluster to a list of the number of
parts with a replica count at each index. The values of the dict will
be lists of length the maximum whole replica + 1 so that the
graph[tier][3] is the number of parts with in the tier with 3 replicas
and graph [tier][0] is the number of parts not assigned in this tier.
i.e.
{
<tier>: [
<number_of_parts_with_0_replicas>,
<number_of_parts_with_1_replicas>,
...
<number_of_parts_with_n_replicas>,
],
...
}
:param old_replica2part2dev: if called from rebalance, the
old_replica2part2dev can be used to count moved moved parts.
:returns: number of parts with different assignments than
old_replica2part2dev if provided
"""
# Since we're going to loop over every replica of every part we'll
# also count up changed_parts if old_replica2part2dev is passed in
old_replica2part2dev = old_replica2part2dev or []
# Compare the partition allocation before and after the rebalance
# Only changed device ids are taken into account; devices might be
# "touched" during the rebalance, but actually not really moved
changed_parts = 0
int_replicas = int(math.ceil(self.replicas))
max_allowed_replicas = self._build_max_replicas_by_tier()
parts_at_risk = 0
dispersion_graph = {}
# go over all the devices holding each replica part by part
for part_id, dev_ids in enumerate(
six.moves.zip(*self._replica2part2dev)):
# count the number of replicas of this part for each tier of each
# device, some devices may have overlapping tiers!
replicas_at_tier = defaultdict(int)
for rep_id, dev in enumerate(iter(
self.devs[dev_id] for dev_id in dev_ids)):
for tier in (dev.get('tiers') or tiers_for_dev(dev)):
replicas_at_tier[tier] += 1
# IndexErrors will be raised if the replicas are increased or
# decreased, and that actually means the partition has changed
try:
old_device = old_replica2part2dev[rep_id][part_id]
except IndexError:
changed_parts += 1
continue
if old_device != dev['id']:
changed_parts += 1
part_at_risk = False
# update running totals for each tiers' number of parts with a
# given replica count
for tier, replicas in replicas_at_tier.items():
if tier not in dispersion_graph:
dispersion_graph[tier] = [self.parts] + [0] * int_replicas
dispersion_graph[tier][0] -= 1
dispersion_graph[tier][replicas] += 1
if replicas > max_allowed_replicas[tier]:
part_at_risk = True
# this part may be at risk in multiple tiers, but we only count it
# as at_risk once
if part_at_risk:
parts_at_risk += 1
self._dispersion_graph = dispersion_graph
self.dispersion = 100.0 * parts_at_risk / self.parts
return changed_parts
def validate(self, stats=False):
"""
Validate the ring.
This is a safety function to try to catch any bugs in the building
process. It ensures partitions have been assigned to real devices,
aren't doubly assigned, etc. It can also optionally check the even
distribution of partitions across devices.
:param stats: if True, check distribution of partitions across devices
:returns: if stats is True, a tuple of (device_usage, worst_stat), else
(None, None). device_usage[dev_id] will equal the number of
partitions assigned to that device. worst_stat will equal the
number of partitions the worst device is skewed from the
number it should have.
:raises RingValidationError: problem was found with the ring.
"""
# "len" showed up in profiling, so it's just computed once.
dev_len = len(self.devs)
parts_on_devs = sum(d['parts'] for d in self._iter_devs())
if not self._replica2part2dev:
raise exceptions.RingValidationError(
'_replica2part2dev empty; did you forget to rebalance?')
parts_in_map = sum(len(p2d) for p2d in self._replica2part2dev)
if parts_on_devs != parts_in_map:
raise exceptions.RingValidationError(
'All partitions are not double accounted for: %d != %d' %
(parts_on_devs, parts_in_map))
if stats:
# dev_usage[dev_id] will equal the number of partitions assigned to
# that device.
dev_usage = array('I', (0 for _junk in range(dev_len)))
for part2dev in self._replica2part2dev:
for dev_id in part2dev:
dev_usage[dev_id] += 1
for dev in self._iter_devs():
if not isinstance(dev['port'], int):
raise exceptions.RingValidationError(
"Device %d has port %r, which is not an integer." %
(dev['id'], dev['port']))
int_replicas = int(math.ceil(self.replicas))
rep2part_len = map(len, self._replica2part2dev)
# check the assignments of each part's replicas
for part in range(self.parts):
devs_for_part = []
for replica, part_len in enumerate(rep2part_len):
if part_len <= part:
# last replica may be short on parts because of floating
# replica count
if replica + 1 < int_replicas:
raise exceptions.RingValidationError(
"The partition assignments of replica %r were "
"shorter than expected (%s < %s) - this should "
"only happen for the last replica" % (
replica,
len(self._replica2part2dev[replica]),
self.parts,
))
break
dev_id = self._replica2part2dev[replica][part]
if dev_id >= dev_len or not self.devs[dev_id]:
raise exceptions.RingValidationError(
"Partition %d, replica %d was not allocated "
"to a device." %
(part, replica))
devs_for_part.append(dev_id)
if len(devs_for_part) != len(set(devs_for_part)):
raise exceptions.RingValidationError(
"The partition %s has been assigned to "
"duplicate devices %r" % (
part, devs_for_part))
if stats:
weight_of_one_part = self.weight_of_one_part()
worst = 0
for dev in self._iter_devs():
if not dev['weight']:
if dev_usage[dev['id']]:
# If a device has no weight, but has partitions, then
# its overage is considered "infinity" and therefore
# always the worst possible. We show MAX_BALANCE for
# convenience.
worst = MAX_BALANCE
break
continue
skew = abs(100.0 * dev_usage[dev['id']] /
(dev['weight'] * weight_of_one_part) - 100.0)
if skew > worst:
worst = skew
return dev_usage, worst
return None, None
def _build_balance_per_dev(self):
"""
Build a map of <device_id> => <balance> where <balance> is a float
representing the percentage difference from the desired amount of
partitions a given device wants and the amount it has.
N.B. this method only considers a device's weight and the parts
assigned, not the parts wanted according to the replica plan.
"""
weight_of_one_part = self.weight_of_one_part()
balance_per_dev = {}
for dev in self._iter_devs():
if not dev['weight']:
if dev['parts']:
# If a device has no weight, but has partitions, then its
# overage is considered "infinity" and therefore always the
# worst possible. We show MAX_BALANCE for convenience.
balance = MAX_BALANCE
else:
balance = 0
else:
balance = 100.0 * dev['parts'] / (
dev['weight'] * weight_of_one_part) - 100.0
balance_per_dev[dev['id']] = balance
return balance_per_dev
def get_balance(self):
"""
Get the balance of the ring. The balance value is the highest
percentage off the desired amount of partitions a given device
wants. For instance, if the "worst" device wants (based on its
weight relative to the sum of all the devices' weights) 123
partitions and it has 124 partitions, the balance value would
be 0.83 (1 extra / 123 wanted * 100 for percentage).
:returns: balance of the ring
"""
balance_per_dev = self._build_balance_per_dev()
return max(abs(b) for b in balance_per_dev.values())
def get_required_overload(self, weighted=None, wanted=None):
"""
Returns the minimum overload value required to make the ring maximally
dispersed.
The required overload is the largest percentage change of any single
device from its weighted replicanth to its wanted replicanth (note
under weighted devices have a negative percentage change) to archive
dispersion - that is to say a single device that must be overloaded by
5% is worse than 5 devices in a single tier overloaded by 1%.
"""
weighted = weighted or self._build_weighted_replicas_by_tier()
wanted = wanted or self._build_wanted_replicas_by_tier()
max_overload = 0.0
for dev in self._iter_devs():
tier = (dev['region'], dev['zone'], dev['ip'], dev['id'])
if not dev['weight']:
if tier not in wanted or not wanted[tier]:
continue
raise exceptions.RingValidationError(
'Device %s has zero weight and '
'should not want any replicas' % (tier,))
required = (wanted[tier] - weighted[tier]) / weighted[tier]
self.logger.debug('%s wants %s and is weighted for %s so '
'therefore requires %s overload' % (
tier, wanted[tier], weighted[tier],
required))
if required > max_overload:
max_overload = required
return max_overload
def pretend_min_part_hours_passed(self):
"""
Override min_part_hours by marking all partitions as having been moved
255 hours ago and last move epoch to 'the beginning of time'. This can
be used to force a full rebalance on the next call to rebalance.
"""
for part in range(self.parts):
self._last_part_moves[part] = 0xff
self._last_part_moves_epoch = 0
def get_part_devices(self, part):
"""
Get the devices that are responsible for the partition,
filtering out duplicates.
:param part: partition to get devices for
:returns: list of device dicts
"""
devices = []
for dev in self._devs_for_part(part):
if dev not in devices:
devices.append(dev)
return devices
def _iter_devs(self):
"""
Returns an iterator all the non-None devices in the ring. Note that
this means list(b._iter_devs())[some_id] may not equal b.devs[some_id];
you will have to check the 'id' key of each device to obtain its
dev_id.
"""
for dev in self.devs:
if dev is not None:
yield dev
def _build_tier2children(self):
"""
Wrap helper build_tier_tree so exclude zero-weight devices.
"""
return build_tier_tree(d for d in self._iter_devs() if d['weight'])
def _set_parts_wanted(self, replica_plan):
"""
Sets the parts_wanted key for each of the devices to the number of
partitions the device wants based on its relative weight. This key is
used to sort the devices according to "most wanted" during rebalancing
to best distribute partitions. A negative parts_wanted indicates the
device is "overweight" and wishes to give partitions away if possible.
:param replica_plan: a dict of dicts, as returned from
_build_replica_plan, that that maps
each tier to it's target replicanths.
"""
tier2children = self._build_tier2children()
parts_by_tier = defaultdict(int)
def place_parts(tier, parts):
parts_by_tier[tier] = parts
sub_tiers = sorted(tier2children[tier])
if not sub_tiers:
return
to_place = defaultdict(int)
for t in sub_tiers:
to_place[t] = int(math.floor(
replica_plan[t]['target'] * self.parts))
parts -= to_place[t]
# if there's some parts left over, just throw 'em about
sub_tier_gen = itertools.cycle(sorted(
sub_tiers, key=lambda t: replica_plan[t]['target']))
while parts:
t = next(sub_tier_gen)
to_place[t] += 1
parts -= 1
for t, p in to_place.items():
place_parts(t, p)
total_parts = int(self.replicas * self.parts)
place_parts((), total_parts)
# belts & suspenders/paranoia - at every level, the sum of
# parts_by_tier should be total_parts for the ring
tiers = ['cluster', 'regions', 'zones', 'servers', 'devices']
for i, tier_name in enumerate(tiers):
parts_at_tier = sum(parts_by_tier[t] for t in parts_by_tier
if len(t) == i)
if parts_at_tier != total_parts:
raise exceptions.RingValidationError(
'%s != %s at tier %s' % (
parts_at_tier, total_parts, tier_name))
for dev in self._iter_devs():
if not dev['weight']:
# With no weight, that means we wish to "drain" the device. So
# we set the parts_wanted to a really large negative number to
# indicate its strong desire to give up everything it has.
dev['parts_wanted'] = -self.parts * self.replicas
else:
tier = (dev['region'], dev['zone'], dev['ip'], dev['id'])
dev['parts_wanted'] = parts_by_tier[tier] - dev['parts']
def _update_last_part_moves(self):
"""
Updates how many hours ago each partition was moved based on the
current time. The builder won't move a partition that has been moved
more recently than min_part_hours.
"""
elapsed_hours = int(time() - self._last_part_moves_epoch) / 3600
if elapsed_hours <= 0:
return
for part in range(self.parts):
# The "min(self._last_part_moves[part] + elapsed_hours, 0xff)"
# which was here showed up in profiling, so it got inlined.
last_plus_elapsed = self._last_part_moves[part] + elapsed_hours
if last_plus_elapsed < 0xff:
self._last_part_moves[part] = last_plus_elapsed
else:
self._last_part_moves[part] = 0xff
self._last_part_moves_epoch = int(time())
def _gather_parts_from_failed_devices(self, assign_parts):
"""
Update the map of partition => [replicas] to be reassigned from
removed devices.
"""
# First we gather partitions from removed devices. Since removed
# devices usually indicate device failures, we have no choice but to
# reassign these partitions. However, we mark them as moved so later
# choices will skip other replicas of the same partition if possible.
if self._remove_devs:
dev_ids = [d['id'] for d in self._remove_devs if d['parts']]
if dev_ids:
for part, replica in self._each_part_replica():
dev_id = self._replica2part2dev[replica][part]
if dev_id in dev_ids:
self._replica2part2dev[replica][part] = NONE_DEV
self._last_part_moves[part] = 0
assign_parts[part].append(replica)
self.logger.debug(
"Gathered %d/%d from dev %d [dev removed]",
part, replica, dev_id)
removed_devs = 0
while self._remove_devs:
remove_dev_id = self._remove_devs.pop()['id']
self.logger.debug("Removing dev %d", remove_dev_id)
self.devs[remove_dev_id] = None
removed_devs += 1
return removed_devs
def _adjust_replica2part2dev_size(self, to_assign):
"""
Make sure that the lengths of the arrays in _replica2part2dev
are correct for the current value of self.replicas.
Example:
self.part_power = 8
self.replicas = 2.25
self._replica2part2dev will contain 3 arrays: the first 2 of
length 256 (2**8), and the last of length 64 (0.25 * 2**8).
Update the mapping of partition => [replicas] that need assignment.
"""
fractional_replicas, whole_replicas = math.modf(self.replicas)
whole_replicas = int(whole_replicas)
removed_parts = 0
new_parts = 0
desired_lengths = [self.parts] * whole_replicas
if fractional_replicas:
desired_lengths.append(int(self.parts * fractional_replicas))
if self._replica2part2dev is not None:
# If we crossed an integer threshold (say, 4.1 --> 4),
# we'll have a partial extra replica clinging on here. Clean
# up any such extra stuff.
for part2dev in self._replica2part2dev[len(desired_lengths):]:
for dev_id in part2dev:
dev_losing_part = self.devs[dev_id]
dev_losing_part['parts'] -= 1
removed_parts -= 1
self._replica2part2dev = \
self._replica2part2dev[:len(desired_lengths)]
else:
self._replica2part2dev = []
for replica, desired_length in enumerate(desired_lengths):
if replica < len(self._replica2part2dev):
part2dev = self._replica2part2dev[replica]
if len(part2dev) < desired_length:
# Not long enough: needs to be extended and the
# newly-added pieces assigned to devices.
for part in range(len(part2dev), desired_length):
to_assign[part].append(replica)
part2dev.append(NONE_DEV)
new_parts += 1
elif len(part2dev) > desired_length:
# Too long: truncate this mapping.
for part in range(desired_length, len(part2dev)):
dev_losing_part = self.devs[part2dev[part]]
dev_losing_part['parts'] -= 1
removed_parts -= 1
self._replica2part2dev[replica] = part2dev[:desired_length]
else:
# Mapping not present at all: make one up and assign
# all of it.
for part in range(desired_length):
to_assign[part].append(replica)
new_parts += 1
self._replica2part2dev.append(
array('H', itertools.repeat(NONE_DEV, desired_length)))
self.logger.debug(
"%d new parts and %d removed parts from replica-count change",
new_parts, removed_parts)
def _gather_parts_for_dispersion(self, assign_parts, replica_plan):
"""
Update the map of partition => [replicas] to be reassigned from
insufficiently-far-apart replicas.
"""
# Now we gather partitions that are "at risk" because they aren't
# currently sufficient spread out across the cluster.
for part in range(self.parts):
if self._last_part_moves[part] < self.min_part_hours:
continue
# First, add up the count of replicas at each tier for each
# partition.
replicas_at_tier = defaultdict(int)
for dev in self._devs_for_part(part):
for tier in dev['tiers']:
replicas_at_tier[tier] += 1
# Now, look for partitions not yet spread out enough.
undispersed_dev_replicas = []
for replica in self._replicas_for_part(part):
dev_id = self._replica2part2dev[replica][part]
if dev_id == NONE_DEV:
continue
dev = self.devs[dev_id]
if all(replicas_at_tier[tier] <=
replica_plan[tier]['max']
for tier in dev['tiers']):
continue
undispersed_dev_replicas.append((dev, replica))
if not undispersed_dev_replicas:
continue
undispersed_dev_replicas.sort(
key=lambda dr: dr[0]['parts_wanted'])
for dev, replica in undispersed_dev_replicas:
# the min part hour check is ignored iff a device has more
# than one replica of a part assigned to it - which would have
# only been possible on rings built with older version of code
if (self._last_part_moves[part] < self.min_part_hours and
not replicas_at_tier[dev['tiers'][-1]] > 1):
continue
dev['parts_wanted'] += 1
dev['parts'] -= 1
assign_parts[part].append(replica)
self.logger.debug(
"Gathered %d/%d from dev %d [dispersion]",
part, replica, dev['id'])
self._replica2part2dev[replica][part] = NONE_DEV
for tier in dev['tiers']:
replicas_at_tier[tier] -= 1
self._last_part_moves[part] = 0
def _gather_parts_for_balance_can_disperse(self, assign_parts, start,
replica_plan):
"""
Update the map of partition => [replicas] to be reassigned from
overweight drives where the replicas can be better dispersed to
another failure domain.
:param assign_parts: the map of partition => [replica] to update
:param start: offset into self.parts to begin search
:param replica_plan: replicanth targets for tiers
"""
# Last, we gather partitions from devices that are "overweight" because
# they have more partitions than their parts_wanted.
for offset in range(self.parts):
part = (start + offset) % self.parts
if self._last_part_moves[part] < self.min_part_hours:
continue
# For each part we'll look at the devices holding those parts and
# see if any are overweight, keeping track of replicas_at_tier as
# we go
overweight_dev_replica = []
replicas_at_tier = defaultdict(int)
for replica in self._replicas_for_part(part):
dev_id = self._replica2part2dev[replica][part]
if dev_id == NONE_DEV:
continue
dev = self.devs[dev_id]
for tier in dev['tiers']:
replicas_at_tier[tier] += 1
if dev['parts_wanted'] < 0:
overweight_dev_replica.append((dev, replica))
if not overweight_dev_replica:
continue
overweight_dev_replica.sort(
key=lambda dr: dr[0]['parts_wanted'])
for dev, replica in overweight_dev_replica:
if self._last_part_moves[part] < self.min_part_hours:
break
if any(replica_plan[tier]['min'] <=
replicas_at_tier[tier] <
replica_plan[tier]['max']
for tier in dev['tiers']):
continue
# this is the most overweight_device holding a replica
# of this part that can shed it according to the plan
dev['parts_wanted'] += 1
dev['parts'] -= 1
assign_parts[part].append(replica)
self.logger.debug(
"Gathered %d/%d from dev %d [weight disperse]",
part, replica, dev['id'])
self._replica2part2dev[replica][part] = NONE_DEV
for tier in dev['tiers']:
replicas_at_tier[tier] -= 1
self._last_part_moves[part] = 0
def _gather_parts_for_balance(self, assign_parts, replica_plan):
"""
Gather parts that look like they should move for balance reasons.
A simple gather of parts that looks dispersible normally works out,
we'll switch strategies if things don't be seem to moving...
"""
# pick a random starting point on the other side of the ring
quarter_turn = (self.parts // 4)
random_half = random.randint(0, self.parts / 2)
start = (self._last_part_gather_start + quarter_turn +
random_half) % self.parts
self.logger.debug('Gather start is %s '
'(Last start was %s)' % (
start, self._last_part_gather_start))
self._last_part_gather_start = start
self._gather_parts_for_balance_can_disperse(
assign_parts, start, replica_plan)
if not assign_parts:
self._gather_parts_for_balance_forced(assign_parts, start)
def _gather_parts_for_balance_forced(self, assign_parts, start, **kwargs):
"""
Update the map of partition => [replicas] to be reassigned from
overweight drives without restriction, parts gathered from this method
may be placed back onto devices that are no better (or worse) than the
device from which they are gathered.
This method allows devices to flop around enough to unlock replicas
that would have otherwise potentially been locked because of
dispersion - it should be used as a last resort.
:param assign_parts: the map of partition => [replica] to update
:param start: offset into self.parts to begin search
"""
for offset in range(self.parts):
part = (start + offset) % self.parts
if self._last_part_moves[part] < self.min_part_hours:
continue
overweight_dev_replica = []
for replica in self._replicas_for_part(part):
dev_id = self._replica2part2dev[replica][part]
if dev_id == NONE_DEV:
continue
dev = self.devs[dev_id]
if dev['parts_wanted'] < 0:
overweight_dev_replica.append((dev, replica))
if not overweight_dev_replica:
continue
overweight_dev_replica.sort(
key=lambda dr: dr[0]['parts_wanted'])
for dev, replica in overweight_dev_replica:
if self._last_part_moves[part] < self.min_part_hours:
break
# this is the most overweight_device holding a replica of this
# part we don't know where it's going to end up - but we'll
# pick it up and hope for the best.
dev['parts_wanted'] += 1
dev['parts'] -= 1
assign_parts[part].append(replica)
self.logger.debug(
"Gathered %d/%d from dev %d [weight forced]",
part, replica, dev['id'])
self._replica2part2dev[replica][part] = NONE_DEV
self._last_part_moves[part] = 0
def _reassign_parts(self, reassign_parts, replica_plan):
"""
For an existing ring data set, partitions are reassigned similarly to
the initial assignment.
The devices are ordered by how many partitions they still want and
kept in that order throughout the process.
The gathered partitions are iterated through, assigning them to
devices according to the "most wanted" while keeping the replicas as
"far apart" as possible.
Two different regions are considered the farthest-apart things,
followed by zones, then different ip within a zone; the
least-far-apart things are different devices with the same ip in the
same zone.
:param reassign_parts: An iterable of (part, replicas_to_replace)
pairs. replicas_to_replace is an iterable of the
replica (an int) to replace for that partition.
replicas_to_replace may be shared for multiple
partitions, so be sure you do not modify it.
"""
parts_available_in_tier = defaultdict(int)
for dev in self._iter_devs():
dev['sort_key'] = self._sort_key_for(dev)
# Note: this represents how many partitions may be assigned to a
# given tier (region/zone/server/disk). It does not take into
# account how many partitions a given tier wants to shed.
#
# If we did not do this, we could have a zone where, at some
# point during assignment, number-of-parts-to-gain equals
# number-of-parts-to-shed. At that point, no further placement
# into that zone would occur since its parts_available_in_tier
# would be 0. This would happen any time a zone had any device
# with partitions to shed, which is any time a device is being
# removed, which is a pretty frequent operation.
wanted = max(dev['parts_wanted'], 0)
for tier in dev['tiers']:
parts_available_in_tier[tier] += wanted
available_devs = \
sorted((d for d in self._iter_devs() if d['weight']),
key=lambda x: x['sort_key'])
tier2devs = defaultdict(list)
tier2sort_key = defaultdict(tuple)
tier2dev_sort_key = defaultdict(list)
max_tier_depth = 0
for dev in available_devs:
for tier in dev['tiers']:
tier2devs[tier].append(dev) # <-- starts out sorted!
tier2dev_sort_key[tier].append(dev['sort_key'])
tier2sort_key[tier] = dev['sort_key']
if len(tier) > max_tier_depth:
max_tier_depth = len(tier)
tier2children_sets = build_tier_tree(available_devs)
tier2children = defaultdict(list)
tier2children_sort_key = {}
tiers_list = [()]
depth = 1
while depth <= max_tier_depth:
new_tiers_list = []
for tier in tiers_list:
child_tiers = list(tier2children_sets[tier])
child_tiers.sort(key=tier2sort_key.__getitem__)
tier2children[tier] = child_tiers
tier2children_sort_key[tier] = map(
tier2sort_key.__getitem__, child_tiers)
new_tiers_list.extend(child_tiers)
tiers_list = new_tiers_list
depth += 1
for part, replace_replicas in reassign_parts:
# always update part_moves for min_part_hours
self._last_part_moves[part] = 0
# count up where these replicas be
replicas_at_tier = defaultdict(int)
for dev in self._devs_for_part(part):
for tier in dev['tiers']:
replicas_at_tier[tier] += 1
for replica in replace_replicas:
# Find a new home for this replica
tier = ()
# This used to be a cute, recursive function, but it's been
# unrolled for performance.
depth = 1
while depth <= max_tier_depth:
# Choose the roomiest tier among those that don't
# already have their max replicas assigned according
# to the replica_plan.
candidates = [t for t in tier2children[tier] if
replicas_at_tier[t] <
replica_plan[t]['max']]
if not candidates:
raise Exception('no home for %s/%s %s' % (
part, replica, {t: (
replicas_at_tier[t],
replica_plan[t]['max'],
) for t in tier2children[tier]}))
tier = max(candidates, key=lambda t:
parts_available_in_tier[t])
depth += 1
dev = tier2devs[tier][-1]
dev['parts_wanted'] -= 1
dev['parts'] += 1
for tier in dev['tiers']:
parts_available_in_tier[tier] -= 1
replicas_at_tier[tier] += 1
self._replica2part2dev[replica][part] = dev['id']
self.logger.debug(
"Placed %d/%d onto dev %d", part, replica, dev['id'])
# Just to save memory and keep from accidental reuse.
for dev in self._iter_devs():
del dev['sort_key']
@staticmethod
def _sort_key_for(dev):
return (dev['parts_wanted'], random.randint(0, 0xFFFF), dev['id'])
def _build_max_replicas_by_tier(self, bound=math.ceil):
"""
Returns a defaultdict of (tier: replica_count) for all tiers in the
ring excluding zero weight devices.
There will always be a () entry as the root of the structure, whose
replica_count will equal the ring's replica_count.
Then there will be (region,) entries for each region, indicating the
maximum number of replicas the region might have for any given
partition.
Next there will be (region, zone) entries for each zone, indicating
the maximum number of replicas in a given region and zone. Anything
greater than 1 indicates a partition at slightly elevated risk, as if
that zone were to fail multiple replicas of that partition would be
unreachable.
Next there will be (region, zone, ip_port) entries for each node,
indicating the maximum number of replicas stored on a node in a given
region and zone. Anything greater than 1 indicates a partition at
elevated risk, as if that ip_port were to fail multiple replicas of
that partition would be unreachable.
Last there will be (region, zone, ip_port, device) entries for each
device, indicating the maximum number of replicas the device shares
with other devices on the same node for any given partition.
Anything greater than 1 indicates a partition at serious risk, as the
data on that partition will not be stored distinctly at the ring's
replica_count.
Example return dict for the common SAIO setup::
{(): 3.0,
(1,): 3.0,
(1, 1): 1.0,
(1, 1, '127.0.0.1:6010'): 1.0,
(1, 1, '127.0.0.1:6010', 0): 1.0,
(1, 2): 1.0,
(1, 2, '127.0.0.1:6020'): 1.0,
(1, 2, '127.0.0.1:6020', 1): 1.0,
(1, 3): 1.0,
(1, 3, '127.0.0.1:6030'): 1.0,
(1, 3, '127.0.0.1:6030', 2): 1.0,
(1, 4): 1.0,
(1, 4, '127.0.0.1:6040'): 1.0,
(1, 4, '127.0.0.1:6040', 3): 1.0}
"""
# Used by walk_tree to know what entries to create for each recursive
# call.
tier2children = self._build_tier2children()
def walk_tree(tier, replica_count):
if len(tier) == 4:
# special case for device, it's not recursive
replica_count = min(1, replica_count)
mr = {tier: replica_count}
if tier in tier2children:
subtiers = tier2children[tier]
for subtier in subtiers:
submax = bound(float(replica_count) / len(subtiers))
mr.update(walk_tree(subtier, submax))
return mr
mr = defaultdict(float)
mr.update(walk_tree((), self.replicas))
return mr
def _build_weighted_replicas_by_tier(self):
"""
Returns a dict mapping <tier> => replicanths for all tiers in
the ring based on their weights.
"""
weight_of_one_part = self.weight_of_one_part()
# assign each device some replicanths by weight (can't be > 1)
weighted_replicas_for_dev = {}
devices_with_room = []
for dev in self._iter_devs():
if not dev['weight']:
continue
weighted_replicas = (
dev['weight'] * weight_of_one_part / self.parts)
if weighted_replicas < 1:
devices_with_room.append(dev['id'])
else:
weighted_replicas = 1
weighted_replicas_for_dev[dev['id']] = weighted_replicas
while True:
remaining = self.replicas - sum(weighted_replicas_for_dev.values())
if remaining < 1e-10:
break
devices_with_room = [d for d in devices_with_room if
weighted_replicas_for_dev[d] < 1]
rel_weight = remaining / sum(
weighted_replicas_for_dev[d] for d in devices_with_room)
for d in devices_with_room:
weighted_replicas_for_dev[d] = min(
1, weighted_replicas_for_dev[d] * (rel_weight + 1))
weighted_replicas_by_tier = defaultdict(float)
for dev in self._iter_devs():
if not dev['weight']:
continue
assigned_replicanths = weighted_replicas_for_dev[dev['id']]
dev_tier = (dev['region'], dev['zone'], dev['ip'], dev['id'])
for i in range(len(dev_tier) + 1):
tier = dev_tier[:i]
weighted_replicas_by_tier[tier] += assigned_replicanths
# belts & suspenders/paranoia - at every level, the sum of
# weighted_replicas should be very close to the total number of
# replicas for the ring
tiers = ['cluster', 'regions', 'zones', 'servers', 'devices']
for i, tier_name in enumerate(tiers):
replicas_at_tier = sum(weighted_replicas_by_tier[t] for t in
weighted_replicas_by_tier if len(t) == i)
if abs(self.replicas - replicas_at_tier) > 1e-10:
raise exceptions.RingValidationError(
'%s != %s at tier %s' % (
replicas_at_tier, self.replicas, tier_name))
return weighted_replicas_by_tier
def _build_wanted_replicas_by_tier(self):
"""
Returns a defaultdict of (tier: replicanths) for all tiers in the ring
based on unique-as-possible (full dispersion) with respect to their
weights and device counts.
N.B. _build_max_replicas_by_tier calculates the upper bound on the
replicanths each tier may hold irrespective of the weights of the
tier; this method will calculate the minimum replicanth <=
max_replicas[tier] that will still solve dispersion. However it is
not guaranteed to return a fully dispersed solution if failure domains
are over-weighted for their device count.
"""
weighted_replicas = self._build_weighted_replicas_by_tier()
dispersed_replicas = {
t: {
'min': math.floor(r),
'max': math.ceil(r),
} for (t, r) in
self._build_max_replicas_by_tier(bound=float).items()
}
# watch out for device limited tiers
num_devices = defaultdict(int)
for d in self._iter_devs():
if d['weight'] <= 0:
continue
for t in (d.get('tiers') or tiers_for_dev(d)):
num_devices[t] += 1
num_devices[()] += 1
tier2children = self._build_tier2children()
wanted_replicas = defaultdict(float)
def place_replicas(tier, replicanths):
if replicanths > num_devices[tier]:
raise exceptions.RingValidationError(
'More than replicanths (%s) than devices (%s) '
'in tier (%s)' % (replicanths, num_devices[tier], tier))
wanted_replicas[tier] = replicanths
sub_tiers = sorted(tier2children[tier])
if not sub_tiers:
return
to_place = defaultdict(float)
remaining = replicanths
tiers_to_spread = sub_tiers
device_limited = False
while True:
rel_weight = remaining / sum(weighted_replicas[t]
for t in tiers_to_spread)
for t in tiers_to_spread:
replicas = to_place[t] + (
weighted_replicas[t] * rel_weight)
if replicas < dispersed_replicas[t]['min']:
replicas = dispersed_replicas[t]['min']
elif (replicas > dispersed_replicas[t]['max'] and
not device_limited):
replicas = dispersed_replicas[t]['max']
if replicas > num_devices[t]:
replicas = num_devices[t]
to_place[t] = replicas
remaining = replicanths - sum(to_place.values())
if remaining < -1e-10:
tiers_to_spread = [
t for t in sub_tiers
if to_place[t] > dispersed_replicas[t]['min']
]
elif remaining > 1e-10:
tiers_to_spread = [
t for t in sub_tiers
if (num_devices[t] > to_place[t] <
dispersed_replicas[t]['max'])
]
if not tiers_to_spread:
device_limited = True
tiers_to_spread = [
t for t in sub_tiers
if to_place[t] < num_devices[t]
]
else:
# remaining is "empty"
break
for t in sub_tiers:
self.logger.debug('Planning %s on %s',
to_place[t], t)
place_replicas(t, to_place[t])
# place all replicas in the cluster tier
place_replicas((), self.replicas)
# belts & suspenders/paranoia - at every level, the sum of
# wanted_replicas should be very close to the total number of
# replicas for the ring
tiers = ['cluster', 'regions', 'zones', 'servers', 'devices']
for i, tier_name in enumerate(tiers):
replicas_at_tier = sum(wanted_replicas[t] for t in
wanted_replicas if len(t) == i)
if abs(self.replicas - replicas_at_tier) > 1e-10:
raise exceptions.RingValidationError(
'%s != %s at tier %s' % (
replicas_at_tier, self.replicas, tier_name))
return wanted_replicas
def _build_target_replicas_by_tier(self):
"""
Build a map of <tier> => <target_replicas> accounting for device
weights, unique-as-possible dispersion and overload.
<tier> - a tuple, describing each tier in the ring topology
<target_replicas> - a float, the target replicanths at the tier
"""
weighted_replicas = self._build_weighted_replicas_by_tier()
wanted_replicas = self._build_wanted_replicas_by_tier()
max_overload = self.get_required_overload(weighted=weighted_replicas,
wanted=wanted_replicas)
if max_overload <= 0.0:
return wanted_replicas
else:
overload = min(self.overload, max_overload)
self.logger.debug("Using effective overload of %f", overload)
target_replicas = defaultdict(float)
for tier, weighted in weighted_replicas.items():
m = (wanted_replicas[tier] - weighted) / max_overload
target_replicas[tier] = m * overload + weighted
# belts & suspenders/paranoia - at every level, the sum of
# target_replicas should be very close to the total number
# of replicas for the ring
tiers = ['cluster', 'regions', 'zones', 'servers', 'devices']
for i, tier_name in enumerate(tiers):
replicas_at_tier = sum(target_replicas[t] for t in
target_replicas if len(t) == i)
if abs(self.replicas - replicas_at_tier) > 1e-10:
raise exceptions.RingValidationError(
'%s != %s at tier %s' % (
replicas_at_tier, self.replicas, tier_name))
return target_replicas
def _build_replica_plan(self):
"""
Wraps return value of _build_target_replicas_by_tier to include
pre-calculated min and max values for each tier.
:returns: a dict, mapping <tier> => <replica_plan>, where
<replica_plan> is itself a dict
<replica_plan> include at least the following keys:
min - the minimum number of replicas at the tier
target - the target replicanths at the tier
max - the maximum number of replicas at the tier
"""
# replica part-y planner!
target_replicas = self._build_target_replicas_by_tier()
replica_plan = defaultdict(
lambda: {'min': 0, 'target': 0, 'max': 0})
replica_plan.update({
t: {
'min': math.floor(r + 1e-10),
'target': r,
'max': math.ceil(r - 1e-10),
} for (t, r) in
target_replicas.items()
})
return replica_plan
def _devs_for_part(self, part):
"""
Returns a list of devices for a specified partition.
Deliberately includes duplicates.
"""
if self._replica2part2dev is None:
return []
devs = []
for part2dev in self._replica2part2dev:
if part >= len(part2dev):
continue
dev_id = part2dev[part]
if dev_id == NONE_DEV:
continue
devs.append(self.devs[dev_id])
return devs
def _replicas_for_part(self, part):
"""
Returns a list of replicas for a specified partition.
These can be used as indices into self._replica2part2dev
without worrying about IndexErrors.
"""
return [replica for replica, part2dev
in enumerate(self._replica2part2dev)
if part < len(part2dev)]
def _each_part_replica(self):
"""
Generator yielding every (partition, replica) pair in the ring.
"""
for replica, part2dev in enumerate(self._replica2part2dev):
for part in range(len(part2dev)):
yield (part, replica)
@classmethod
def load(cls, builder_file, open=open):
"""
Obtain RingBuilder instance of the provided builder file
:param builder_file: path to builder file to load
:return: RingBuilder instance
"""
try:
fp = open(builder_file, 'rb')
except IOError as e:
if e.errno == errno.ENOENT:
raise exceptions.FileNotFoundError(
'Ring Builder file does not exist: %s' % builder_file)
elif e.errno in [errno.EPERM, errno.EACCES]:
raise exceptions.PermissionError(
'Ring Builder file cannot be accessed: %s' % builder_file)
else:
raise
else:
with fp:
try:
builder = pickle.load(fp)
except Exception:
# raise error during unpickling as UnPicklingError
raise exceptions.UnPicklingError(
'Ring Builder file is invalid: %s' % builder_file)
if not hasattr(builder, 'devs'):
builder_dict = builder
builder = RingBuilder(1, 1, 1)
builder.copy_from(builder_dict)
for dev in builder.devs:
# really old rings didn't have meta keys
if dev and 'meta' not in dev:
dev['meta'] = ''
# NOTE(akscram): An old ring builder file don't contain
# replication parameters.
if dev:
if 'ip' in dev:
dev.setdefault('replication_ip', dev['ip'])
if 'port' in dev:
dev.setdefault('replication_port', dev['port'])
return builder
def save(self, builder_file):
"""Serialize this RingBuilder instance to disk.
:param builder_file: path to builder file to save
"""
with open(builder_file, 'wb') as f:
pickle.dump(self.to_dict(), f, protocol=2)
def search_devs(self, search_values):
"""Search devices by parameters.
:param search_values: a dictionary with search values to filter
devices, supported parameters are id,
region, zone, ip, port, replication_ip,
replication_port, device, weight, meta
:returns: list of device dicts
"""
matched_devs = []
for dev in self.devs:
if not dev:
continue
matched = True
for key in ('id', 'region', 'zone', 'ip', 'port', 'replication_ip',
'replication_port', 'device', 'weight', 'meta'):
if key in search_values:
value = search_values.get(key)
if value is not None:
if key == 'meta':
if value not in dev.get(key):
matched = False
elif key == 'ip' or key == 'replication_ip':
cdev = ''
try:
cdev = validate_and_normalize_address(
dev.get(key, ''))
except ValueError:
pass
if cdev != value:
matched = False
elif dev.get(key) != value:
matched = False
if matched:
matched_devs.append(dev)
return matched_devs
def increase_partition_power(self):
""" Increases ring partition power by one.
Devices will be assigned to partitions like this:
OLD: 0, 3, 7, 5, 2, 1, ...
NEW: 0, 0, 3, 3, 7, 7, 5, 5, 2, 2, 1, 1, ...
"""
new_replica2part2dev = []
for replica in self._replica2part2dev:
new_replica = array('H')
for device in replica:
new_replica.append(device)
new_replica.append(device) # append device a second time
new_replica2part2dev.append(new_replica)
self._replica2part2dev = new_replica2part2dev
for device in self._iter_devs():
device['parts'] *= 2
# We need to update the time when a partition has been moved the last
# time. Since this is an array of all partitions, we need to double it
# two
new_last_part_moves = []
for partition in self._last_part_moves:
new_last_part_moves.append(partition)
new_last_part_moves.append(partition)
self._last_part_moves = new_last_part_moves
self.part_power += 1
self.parts *= 2
self.version += 1
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7129,
13,
7409,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
646,
7554,
199,
646,
7975,
199,
646,
2050,
199,
646,
3473,
199,
646,
2196,
199,
646,
3816,
14,
4912,
14,
67,
12755,
465,
5927,
199,
504,
1331,
492,
14800,
199,
504,
15502,
492,
27608,
199,
199,
504,
1625,
492,
1625,
199,
504,
5055,
492,
10018,
199,
646,
3816,
199,
504,
3816,
14,
4912,
492,
1425,
199,
504,
900,
492,
900,
199,
199,
504,
16275,
14,
2330,
492,
4967,
199,
504,
16275,
14,
2330,
14,
5985,
492,
820,
316,
1451,
199,
504,
16275,
14,
2330,
14,
5985,
14,
1208,
492,
3367,
1192,
63,
509,
63,
2374,
12,
1900,
63,
13949,
63,
2350,
12,
971,
272,
4107,
63,
460,
63,
7721,
63,
1562,
199,
199,
3,
781,
883,
1133,
3877,
488,
1159,
315,
314,
16234,
18,
2064,
18,
2374,
1625,
12,
880,
781,
4721,
13,
19193,
199,
3,
314,
1390,
574,
367,
10628,
370,
2954,
314,
1777,
365,
440,
5544,
199,
3,
7943,
370,
1263,
2243,
14,
199,
9185,
63,
13260,
275,
499,
1011,
3193,
446,
413,
199,
4283,
63,
31232,
7140,
275,
22291,
14,
1020,
199,
4283,
63,
31232,
7140,
63,
39,
619,
3452,
63,
8760,
275,
650,
421,
199,
533,
820,
316,
13816,
3849,
8,
3849,
304,
272,
986,
421,
199,
893,
26,
272,
327,
2366,
499,
14,
23,
11,
272,
687,
2050,
492,
12119,
2461,
199,
2590,
3545,
26,
272,
327,
2366,
499,
14,
22,
272,
1021,
12119,
2461,
8,
4806,
14,
2461,
304,
267,
347,
8689,
8,
277,
12,
627,
65,
12,
1011,
829,
304,
288,
986,
421,
199,
533,
820,
316,
6437,
8,
785,
304,
272,
408,
272,
8051,
370,
1900,
16275,
14,
2330,
14,
5985,
14,
15420,
1451,
4454,
370,
506,
5313,
370,
4543,
272,
436,
1202,
543,
16275,
14,
2330,
14,
5985,
14,
15420,
4454,
14,
1666,
2517,
15,
13215,
13,
5985,
13,
5649,
272,
367,
2893,
4503,
14,
339,
710,
1256,
1750,
477,
3122,
63,
2489,
9126,
340,
314,
2243,
2556,
965,
272,
2896,
3967,
314,
2061,
29300,
14,
961,
883,
506,
1202,
701,
7249,
370,
5715,
3775,
272,
282,
295,
7358,
1056,
365,
376,
23348,
1056,
503,
7037,
370,
3483,
12,
2896,
12,
503,
272,
4829,
7256,
14,
339,
520,
635,
1777,
63,
5652,
26,
1329,
402,
16394,
275,
499,
538,
2064,
63,
5652,
14,
272,
520,
635,
22413,
26,
1329,
402,
22413,
367,
1924,
6484,
272,
520,
635,
1748,
63,
2064,
63,
8419,
26,
7481,
1329,
402,
10857,
3382,
6484,
4493,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1777,
63,
5652,
12,
22413,
12,
1748,
63,
2064,
63,
8419,
304,
267,
340,
1777,
63,
5652,
690,
4337,
26,
288,
746,
1722,
480,
2064,
63,
5652,
1471,
506,
737,
4750,
4337,
334,
10274,
450,
68,
2924,
2490,
450,
334,
2064,
63,
5652,
4641,
267,
340,
22413,
665,
413,
26,
288,
746,
1722,
480,
16755,
1471,
506,
737,
5210,
413,
334,
10274,
10536,
22,
70,
2924,
2490,
450,
334,
16755,
4641,
267,
340,
1748,
63,
2064,
63,
8419,
665,
378,
26,
288,
746,
1722,
480,
827,
63,
2064,
63,
8419,
1471,
506,
2222,
13,
7371,
334,
10274,
450,
68,
2924,
2490,
450,
334,
827,
63,
2064,
63,
8419,
4641,
398,
291,
14,
2064,
63,
5652,
275,
1777,
63,
5652,
267,
291,
14,
16755,
275,
22413,
267,
291,
14,
827,
63,
2064,
63,
8419,
275,
1748,
63,
2064,
63,
8419,
267,
291,
14,
4181,
275,
499,
1011,
291,
14,
2064,
63,
5652,
267,
291,
14,
18804,
275,
942,
267,
291,
14,
18804,
63,
2489,
275,
756,
267,
291,
14,
1023,
275,
378,
267,
291,
14,
1883,
912,
275,
378,
14,
16,
398,
327,
485,
12317,
18,
2064,
18,
2374,
9033,
687,
16234,
1329,
370,
6484,
1329,
370,
267,
327,
2243,
1305,
14,
2002,
12,
367,
282,
7795,
16234,
12,
499,
538,
1789,
12133,
12,
652,
1159,
376,
1625,
402,
267,
327,
7795,
499,
538,
1789,
6572,
402,
2243,
2762,
334,
2244,
3974,
83,
680,
961,
883,
1736,
282,
267,
327,
4546,
12930,
2419,
314,
499,
538,
1789,
1625,
402,
18038,
2723,
6572,
402,
2243,
2762,
315,
267,
327,
5002,
27027,
611,
83,
14,
32269,
1373,
7282,
499,
538,
1789,
627,
650,
1625,
9980,
1133,
17021,
370,
267,
327,
1172,
1263,
8112,
1570,
27,
10617,
1265,
3984,
336,
14628,
370,
862,
652,
4020,
334,
390,
1990,
267,
327,
282,
1830,
20313,
12,
1233,
13,
2605,
12,
1380,
473,
2061,
16416,
652,
680,
267,
291,
423,
12317,
18,
2064,
18,
2374,
275,
488,
398,
327,
485,
2019,
63,
2064,
63,
4912,
365,
376,
1625,
402,
7381,
2783,
6144,
267,
327,
314,
1329,
402,
10857,
3967,
282,
1627,
6484,
1990,
2061,
12155,
14,
267,
327,
961,
365,
1202,
370,
24197,
781,
2793,
1133,
4057,
282,
6484,
13373,
267,
327,
4453,
282,
1627,
1329,
402,
10857,
334,
1194,
365,
3002,
20195,
511,
680,
29343,
267,
327,
282,
2243,
10580,
642,
5953,
465,
652,
1159,
10826,
626,
1159,
1454,
267,
327,
4224,
2952,
402,
2243,
5988,
14,
267,
291,
423,
2019,
63,
2064,
63,
4912,
275,
488,
267,
327,
485,
2019,
63,
2064,
63,
4912,
63,
7367,
9126,
314,
900,
314,
15340,
315,
267,
327,
485,
2019,
63,
2064,
63,
4912,
365,
4079,
641,
14,
267,
291,
423,
2019,
63,
2064,
63,
4912,
63,
7367,
275,
378,
398,
291,
423,
2019,
63,
2064,
63,
13737,
63,
928,
275,
378,
398,
291,
423,
2297,
529
] |
[
1898,
334,
67,
9,
7129,
13,
7409,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
646,
7554,
199,
646,
7975,
199,
646,
2050,
199,
646,
3473,
199,
646,
2196,
199,
646,
3816,
14,
4912,
14,
67,
12755,
465,
5927,
199,
504,
1331,
492,
14800,
199,
504,
15502,
492,
27608,
199,
199,
504,
1625,
492,
1625,
199,
504,
5055,
492,
10018,
199,
646,
3816,
199,
504,
3816,
14,
4912,
492,
1425,
199,
504,
900,
492,
900,
199,
199,
504,
16275,
14,
2330,
492,
4967,
199,
504,
16275,
14,
2330,
14,
5985,
492,
820,
316,
1451,
199,
504,
16275,
14,
2330,
14,
5985,
14,
1208,
492,
3367,
1192,
63,
509,
63,
2374,
12,
1900,
63,
13949,
63,
2350,
12,
971,
272,
4107,
63,
460,
63,
7721,
63,
1562,
199,
199,
3,
781,
883,
1133,
3877,
488,
1159,
315,
314,
16234,
18,
2064,
18,
2374,
1625,
12,
880,
781,
4721,
13,
19193,
199,
3,
314,
1390,
574,
367,
10628,
370,
2954,
314,
1777,
365,
440,
5544,
199,
3,
7943,
370,
1263,
2243,
14,
199,
9185,
63,
13260,
275,
499,
1011,
3193,
446,
413,
199,
4283,
63,
31232,
7140,
275,
22291,
14,
1020,
199,
4283,
63,
31232,
7140,
63,
39,
619,
3452,
63,
8760,
275,
650,
421,
199,
533,
820,
316,
13816,
3849,
8,
3849,
304,
272,
986,
421,
199,
893,
26,
272,
327,
2366,
499,
14,
23,
11,
272,
687,
2050,
492,
12119,
2461,
199,
2590,
3545,
26,
272,
327,
2366,
499,
14,
22,
272,
1021,
12119,
2461,
8,
4806,
14,
2461,
304,
267,
347,
8689,
8,
277,
12,
627,
65,
12,
1011,
829,
304,
288,
986,
421,
199,
533,
820,
316,
6437,
8,
785,
304,
272,
408,
272,
8051,
370,
1900,
16275,
14,
2330,
14,
5985,
14,
15420,
1451,
4454,
370,
506,
5313,
370,
4543,
272,
436,
1202,
543,
16275,
14,
2330,
14,
5985,
14,
15420,
4454,
14,
1666,
2517,
15,
13215,
13,
5985,
13,
5649,
272,
367,
2893,
4503,
14,
339,
710,
1256,
1750,
477,
3122,
63,
2489,
9126,
340,
314,
2243,
2556,
965,
272,
2896,
3967,
314,
2061,
29300,
14,
961,
883,
506,
1202,
701,
7249,
370,
5715,
3775,
272,
282,
295,
7358,
1056,
365,
376,
23348,
1056,
503,
7037,
370,
3483,
12,
2896,
12,
503,
272,
4829,
7256,
14,
339,
520,
635,
1777,
63,
5652,
26,
1329,
402,
16394,
275,
499,
538,
2064,
63,
5652,
14,
272,
520,
635,
22413,
26,
1329,
402,
22413,
367,
1924,
6484,
272,
520,
635,
1748,
63,
2064,
63,
8419,
26,
7481,
1329,
402,
10857,
3382,
6484,
4493,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1777,
63,
5652,
12,
22413,
12,
1748,
63,
2064,
63,
8419,
304,
267,
340,
1777,
63,
5652,
690,
4337,
26,
288,
746,
1722,
480,
2064,
63,
5652,
1471,
506,
737,
4750,
4337,
334,
10274,
450,
68,
2924,
2490,
450,
334,
2064,
63,
5652,
4641,
267,
340,
22413,
665,
413,
26,
288,
746,
1722,
480,
16755,
1471,
506,
737,
5210,
413,
334,
10274,
10536,
22,
70,
2924,
2490,
450,
334,
16755,
4641,
267,
340,
1748,
63,
2064,
63,
8419,
665,
378,
26,
288,
746,
1722,
480,
827,
63,
2064,
63,
8419,
1471,
506,
2222,
13,
7371,
334,
10274,
450,
68,
2924,
2490,
450,
334,
827,
63,
2064,
63,
8419,
4641,
398,
291,
14,
2064,
63,
5652,
275,
1777,
63,
5652,
267,
291,
14,
16755,
275,
22413,
267,
291,
14,
827,
63,
2064,
63,
8419,
275,
1748,
63,
2064,
63,
8419,
267,
291,
14,
4181,
275,
499,
1011,
291,
14,
2064,
63,
5652,
267,
291,
14,
18804,
275,
942,
267,
291,
14,
18804,
63,
2489,
275,
756,
267,
291,
14,
1023,
275,
378,
267,
291,
14,
1883,
912,
275,
378,
14,
16,
398,
327,
485,
12317,
18,
2064,
18,
2374,
9033,
687,
16234,
1329,
370,
6484,
1329,
370,
267,
327,
2243,
1305,
14,
2002,
12,
367,
282,
7795,
16234,
12,
499,
538,
1789,
12133,
12,
652,
1159,
376,
1625,
402,
267,
327,
7795,
499,
538,
1789,
6572,
402,
2243,
2762,
334,
2244,
3974,
83,
680,
961,
883,
1736,
282,
267,
327,
4546,
12930,
2419,
314,
499,
538,
1789,
1625,
402,
18038,
2723,
6572,
402,
2243,
2762,
315,
267,
327,
5002,
27027,
611,
83,
14,
32269,
1373,
7282,
499,
538,
1789,
627,
650,
1625,
9980,
1133,
17021,
370,
267,
327,
1172,
1263,
8112,
1570,
27,
10617,
1265,
3984,
336,
14628,
370,
862,
652,
4020,
334,
390,
1990,
267,
327,
282,
1830,
20313,
12,
1233,
13,
2605,
12,
1380,
473,
2061,
16416,
652,
680,
267,
291,
423,
12317,
18,
2064,
18,
2374,
275,
488,
398,
327,
485,
2019,
63,
2064,
63,
4912,
365,
376,
1625,
402,
7381,
2783,
6144,
267,
327,
314,
1329,
402,
10857,
3967,
282,
1627,
6484,
1990,
2061,
12155,
14,
267,
327,
961,
365,
1202,
370,
24197,
781,
2793,
1133,
4057,
282,
6484,
13373,
267,
327,
4453,
282,
1627,
1329,
402,
10857,
334,
1194,
365,
3002,
20195,
511,
680,
29343,
267,
327,
282,
2243,
10580,
642,
5953,
465,
652,
1159,
10826,
626,
1159,
1454,
267,
327,
4224,
2952,
402,
2243,
5988,
14,
267,
291,
423,
2019,
63,
2064,
63,
4912,
275,
488,
267,
327,
485,
2019,
63,
2064,
63,
4912,
63,
7367,
9126,
314,
900,
314,
15340,
315,
267,
327,
485,
2019,
63,
2064,
63,
4912,
365,
4079,
641,
14,
267,
291,
423,
2019,
63,
2064,
63,
4912,
63,
7367,
275,
378,
398,
291,
423,
2019,
63,
2064,
63,
13737,
63,
928,
275,
378,
398,
291,
423,
2297,
529,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bennytheshap/ouimeaux
|
ouimeaux/subscribe.py
|
4
|
3676
|
from collections import defaultdict
import logging
from xml.etree import cElementTree
from functools import partial
import gevent
from gevent.wsgi import WSGIServer
from ouimeaux.utils import get_ip_address, requests_request
from ouimeaux.device.insight import Insight
from ouimeaux.device.maker import Maker
from ouimeaux.signals import subscription
from random import randint
log = logging.getLogger(__name__)
NS = "{urn:schemas-upnp-org:event-1-0}"
SUCCESS = '<html><body><h1>200 OK</h1></body></html>'
class SubscriptionRegistry(object):
def __init__(self):
self._devices = {}
self._callbacks = defaultdict(list)
self.port = randint(8300, 8990)
def register(self, device):
if not device:
log.error("Received an invalid device: %r", device)
return
log.info("Subscribing to basic events from %r", device)
# Provide a function to register a callback when the device changes
# state
device.register_listener = partial(self.on, device, 'BinaryState')
self._devices[device.host] = device
self._resubscribe(device.basicevent.eventSubURL)
def _resubscribe(self, url, sid=None):
headers = {'TIMEOUT': 'Second-%d' % 1800}
if sid is not None:
headers['SID'] = sid
else:
host = get_ip_address()
headers.update({
"CALLBACK": '<http://%s:%d>'%(host, self.port),
"NT": "upnp:event"
})
response = requests_request(method="SUBSCRIBE", url=url,
headers=headers)
if response.status_code == 412 and sid:
# Invalid subscription ID. Send an UNSUBSCRIBE for safety and
# start over.
requests_request(method='UNSUBSCRIBE', url=url,
headers={'SID': sid})
return self._resubscribe(url)
timeout = int(response.headers.get('timeout', '1801').replace(
'Second-', ''))
sid = response.headers.get('sid', sid)
gevent.spawn_later(int(timeout * 0.75), self._resubscribe, url, sid)
def _handle(self, environ, start_response):
device = self._devices.get(environ['REMOTE_ADDR'])
if device is not None:
data = environ['wsgi.input'].read()
# trim garbage from end, if any
data = data.split("\n\n")[0]
doc = cElementTree.fromstring(data)
for propnode in doc.findall('./{0}property'.format(NS)):
for property_ in propnode.getchildren():
text = property_.text
if isinstance(device, Insight) and property_.tag=='BinaryState':
text = text.split('|')[0]
subscription.send(device, type=property_.tag, value=text)
self._event(device, property_.tag, text)
start_response('200 OK', [
('Content-Type', 'text/html'),
('Content-Length', len(SUCCESS)),
('Connection', 'close')
])
yield SUCCESS
def _event(self, device, type_, value):
for t, callback in self._callbacks.get(device, ()):
if t == type_:
callback(value)
def on(self, device, type, callback):
self._callbacks[device].append((type, callback))
@property
def server(self):
"""
UDP server to listen for responses.
"""
server = getattr(self, "_server", None)
if server is None:
server = WSGIServer(('', self.port), self._handle, log=None)
self._server = server
return server
|
bsd-3-clause
|
[
504,
5055,
492,
10018,
199,
646,
2050,
199,
504,
2748,
14,
9464,
492,
286,
15325,
199,
504,
9143,
492,
7417,
199,
199,
646,
23386,
199,
504,
23386,
14,
6508,
492,
644,
28732,
199,
199,
504,
29934,
1036,
10962,
14,
1208,
492,
664,
63,
711,
63,
1562,
12,
4145,
63,
1069,
199,
504,
29934,
1036,
10962,
14,
1782,
14,
262,
22727,
492,
1010,
22727,
199,
504,
29934,
1036,
10962,
14,
1782,
14,
14367,
492,
603,
12630,
199,
504,
29934,
1036,
10962,
14,
10458,
492,
9966,
199,
199,
504,
2196,
492,
29722,
4388,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
2709,
275,
5310,
349,
26,
9482,
13,
384,
1590,
13,
1308,
26,
1430,
13,
17,
13,
16,
7063,
199,
12779,
275,
2650,
1360,
2535,
2030,
2535,
72,
17,
30,
1840,
9949,
1108,
72,
17,
2957,
2030,
2957,
1360,
3524,
421,
199,
533,
29763,
10899,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
6410,
275,
1052,
267,
291,
423,
11948,
275,
10018,
8,
513,
9,
267,
291,
14,
719,
275,
29722,
8,
2658,
383,
12,
1695,
16166,
9,
2378,
347,
2274,
8,
277,
12,
2243,
304,
267,
340,
440,
2243,
26,
288,
943,
14,
705,
480,
9392,
376,
3866,
2243,
26,
450,
82,
401,
2243,
9,
288,
372,
267,
943,
14,
815,
480,
2610,
729,
10911,
370,
5678,
4474,
687,
450,
82,
401,
2243,
9,
267,
327,
22896,
282,
805,
370,
2274,
282,
3233,
1380,
314,
2243,
4493,
267,
327,
1174,
267,
2243,
14,
2683,
63,
9799,
275,
7417,
8,
277,
14,
265,
12,
2243,
12,
283,
6636,
2223,
358,
267,
291,
423,
6410,
59,
1782,
14,
1102,
61,
275,
2243,
267,
291,
423,
470,
456,
5355,
8,
1782,
14,
31917,
1885,
782,
14,
1430,
2610,
2632,
9,
339,
347,
485,
470,
456,
5355,
8,
277,
12,
1166,
12,
15764,
29,
403,
304,
267,
2323,
275,
791,
8899,
356,
283,
11906,
3295,
68,
7,
450,
6155,
383,
93,
267,
340,
15764,
365,
440,
488,
26,
288,
2323,
459,
19514,
418,
275,
15764,
267,
587,
26,
288,
1591,
275,
664,
63,
711,
63,
1562,
342,
288,
2323,
14,
873,
2561,
355,
298,
28100,
582,
2650,
1014,
13827,
83,
2689,
68,
3524,
2840,
1102,
12,
291,
14,
719,
395,
355,
298,
12460,
582,
298,
384,
1590,
26,
1430,
2,
288,
3828,
267,
1177,
275,
4145,
63,
1069,
8,
765,
628,
6348,
51,
27448,
37,
401,
1166,
29,
633,
12,
2511,
2323,
29,
2139,
9,
267,
340,
1177,
14,
1205,
63,
600,
508,
841,
713,
436,
15764,
26,
288,
327,
6378,
9966,
2870,
14,
10217,
376,
32708,
2533,
51,
27448,
37,
367,
30261,
436,
288,
327,
1343,
1806,
14,
288,
4145,
63,
1069,
8,
765,
534,
1734,
6348,
51,
27448,
37,
297,
1166,
29,
633,
12,
2490,
2323,
3713,
19514,
356,
15764,
1552,
288,
372,
291,
423,
470,
456,
5355,
8,
633,
9,
267,
2653,
275,
1109,
8,
1310,
14,
2139,
14,
362,
360,
2593,
297,
283,
1085,
614,
1959,
1814,
8,
288,
283,
11906,
14382,
12381,
267,
15764,
275,
1177,
14,
2139,
14,
362,
360,
4148,
297,
15764,
9,
267,
23386,
14,
10212,
63,
18103,
8,
442,
8,
2593,
627,
378,
14,
2194,
395,
291,
423,
470,
456,
5355,
12,
1166,
12,
15764,
9,
339,
347,
485,
2479,
8,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
2243,
275,
291,
423,
6410,
14,
362,
8,
2314,
459,
16058,
63,
7803,
1105,
267,
340,
2243,
365,
440,
488,
26,
288,
666,
275,
6160,
459,
6508,
14,
1210,
2278,
739,
342,
288,
327,
11639,
17516,
687,
1284,
12,
340,
1263,
288,
666,
275,
666,
14,
1294,
4582,
78,
60,
78,
9981,
16,
61,
288,
1382,
275,
286,
15325,
14,
13521,
8,
576,
9,
288,
367,
5931,
932,
315,
1382,
14,
6452,
5175,
5321,
16,
93,
1829,
1370,
908,
8,
2709,
2298,
355,
367,
3324,
63,
315,
5931,
932,
14,
362,
3223,
837,
490,
1318,
275,
3324,
3754,
505,
490,
340,
1228,
8,
1782,
12,
1010,
22727,
9,
436,
3324,
3754,
1450,
6803,
6636,
2223,
356,
717,
1318,
275,
1318,
14,
1294,
20137,
5832,
16,
61,
490,
9966,
14,
2254,
8,
1782,
12,
730,
29,
1829,
3754,
1450,
12,
574,
29,
505,
9,
490,
291,
423,
1430,
8,
1782,
12,
3324,
3754,
1450,
12,
1318,
9,
267,
1343,
63,
1310,
360,
1840,
9949,
297,
359,
288,
661,
2714,
13,
804,
297,
283,
505,
15,
1360,
659,
288,
661,
2714,
13,
4625,
297,
822,
8,
12779,
1826,
288,
661,
3225,
297,
283,
1600,
358,
267,
4794,
267,
1995,
28364,
339,
347,
485,
1430,
8,
277,
12,
2243,
12,
730,
3131,
574,
304,
267,
367,
307,
12,
3233,
315,
291,
423,
11948,
14,
362,
8,
1782,
12,
334,
2298,
288,
340,
307,
508,
730,
10388,
355,
3233,
8,
585,
9,
339,
347,
641,
8,
277,
12,
2243,
12,
730,
12,
3233,
304,
267,
291,
423,
11948,
59,
1782,
1055,
740,
1332,
466,
12,
3233,
430,
339,
768,
1829,
272,
347,
1654,
8,
277,
304,
267,
408,
267,
21802,
1654,
370,
6938,
367,
9320,
14,
267,
408,
267,
1654,
275,
2519,
8,
277,
12,
2668,
1000,
401,
488,
9,
267,
340,
1654,
365,
488,
26,
288,
1654,
275,
644,
28732,
4725,
297,
291,
14,
719,
395,
291,
423,
2479,
12,
943,
29,
403,
9,
288,
291,
423,
1000,
275,
1654,
267,
372,
1654,
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
] |
[
5055,
492,
10018,
199,
646,
2050,
199,
504,
2748,
14,
9464,
492,
286,
15325,
199,
504,
9143,
492,
7417,
199,
199,
646,
23386,
199,
504,
23386,
14,
6508,
492,
644,
28732,
199,
199,
504,
29934,
1036,
10962,
14,
1208,
492,
664,
63,
711,
63,
1562,
12,
4145,
63,
1069,
199,
504,
29934,
1036,
10962,
14,
1782,
14,
262,
22727,
492,
1010,
22727,
199,
504,
29934,
1036,
10962,
14,
1782,
14,
14367,
492,
603,
12630,
199,
504,
29934,
1036,
10962,
14,
10458,
492,
9966,
199,
199,
504,
2196,
492,
29722,
4388,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
2709,
275,
5310,
349,
26,
9482,
13,
384,
1590,
13,
1308,
26,
1430,
13,
17,
13,
16,
7063,
199,
12779,
275,
2650,
1360,
2535,
2030,
2535,
72,
17,
30,
1840,
9949,
1108,
72,
17,
2957,
2030,
2957,
1360,
3524,
421,
199,
533,
29763,
10899,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
6410,
275,
1052,
267,
291,
423,
11948,
275,
10018,
8,
513,
9,
267,
291,
14,
719,
275,
29722,
8,
2658,
383,
12,
1695,
16166,
9,
2378,
347,
2274,
8,
277,
12,
2243,
304,
267,
340,
440,
2243,
26,
288,
943,
14,
705,
480,
9392,
376,
3866,
2243,
26,
450,
82,
401,
2243,
9,
288,
372,
267,
943,
14,
815,
480,
2610,
729,
10911,
370,
5678,
4474,
687,
450,
82,
401,
2243,
9,
267,
327,
22896,
282,
805,
370,
2274,
282,
3233,
1380,
314,
2243,
4493,
267,
327,
1174,
267,
2243,
14,
2683,
63,
9799,
275,
7417,
8,
277,
14,
265,
12,
2243,
12,
283,
6636,
2223,
358,
267,
291,
423,
6410,
59,
1782,
14,
1102,
61,
275,
2243,
267,
291,
423,
470,
456,
5355,
8,
1782,
14,
31917,
1885,
782,
14,
1430,
2610,
2632,
9,
339,
347,
485,
470,
456,
5355,
8,
277,
12,
1166,
12,
15764,
29,
403,
304,
267,
2323,
275,
791,
8899,
356,
283,
11906,
3295,
68,
7,
450,
6155,
383,
93,
267,
340,
15764,
365,
440,
488,
26,
288,
2323,
459,
19514,
418,
275,
15764,
267,
587,
26,
288,
1591,
275,
664,
63,
711,
63,
1562,
342,
288,
2323,
14,
873,
2561,
355,
298,
28100,
582,
2650,
1014,
13827,
83,
2689,
68,
3524,
2840,
1102,
12,
291,
14,
719,
395,
355,
298,
12460,
582,
298,
384,
1590,
26,
1430,
2,
288,
3828,
267,
1177,
275,
4145,
63,
1069,
8,
765,
628,
6348,
51,
27448,
37,
401,
1166,
29,
633,
12,
2511,
2323,
29,
2139,
9,
267,
340,
1177,
14,
1205,
63,
600,
508,
841,
713,
436,
15764,
26,
288,
327,
6378,
9966,
2870,
14,
10217,
376,
32708,
2533,
51,
27448,
37,
367,
30261,
436,
288,
327,
1343,
1806,
14,
288,
4145,
63,
1069,
8,
765,
534,
1734,
6348,
51,
27448,
37,
297,
1166,
29,
633,
12,
2490,
2323,
3713,
19514,
356,
15764,
1552,
288,
372,
291,
423,
470,
456,
5355,
8,
633,
9,
267,
2653,
275,
1109,
8,
1310,
14,
2139,
14,
362,
360,
2593,
297,
283,
1085,
614,
1959,
1814,
8,
288,
283,
11906,
14382,
12381,
267,
15764,
275,
1177,
14,
2139,
14,
362,
360,
4148,
297,
15764,
9,
267,
23386,
14,
10212,
63,
18103,
8,
442,
8,
2593,
627,
378,
14,
2194,
395,
291,
423,
470,
456,
5355,
12,
1166,
12,
15764,
9,
339,
347,
485,
2479,
8,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
2243,
275,
291,
423,
6410,
14,
362,
8,
2314,
459,
16058,
63,
7803,
1105,
267,
340,
2243,
365,
440,
488,
26,
288,
666,
275,
6160,
459,
6508,
14,
1210,
2278,
739,
342,
288,
327,
11639,
17516,
687,
1284,
12,
340,
1263,
288,
666,
275,
666,
14,
1294,
4582,
78,
60,
78,
9981,
16,
61,
288,
1382,
275,
286,
15325,
14,
13521,
8,
576,
9,
288,
367,
5931,
932,
315,
1382,
14,
6452,
5175,
5321,
16,
93,
1829,
1370,
908,
8,
2709,
2298,
355,
367,
3324,
63,
315,
5931,
932,
14,
362,
3223,
837,
490,
1318,
275,
3324,
3754,
505,
490,
340,
1228,
8,
1782,
12,
1010,
22727,
9,
436,
3324,
3754,
1450,
6803,
6636,
2223,
356,
717,
1318,
275,
1318,
14,
1294,
20137,
5832,
16,
61,
490,
9966,
14,
2254,
8,
1782,
12,
730,
29,
1829,
3754,
1450,
12,
574,
29,
505,
9,
490,
291,
423,
1430,
8,
1782,
12,
3324,
3754,
1450,
12,
1318,
9,
267,
1343,
63,
1310,
360,
1840,
9949,
297,
359,
288,
661,
2714,
13,
804,
297,
283,
505,
15,
1360,
659,
288,
661,
2714,
13,
4625,
297,
822,
8,
12779,
1826,
288,
661,
3225,
297,
283,
1600,
358,
267,
4794,
267,
1995,
28364,
339,
347,
485,
1430,
8,
277,
12,
2243,
12,
730,
3131,
574,
304,
267,
367,
307,
12,
3233,
315,
291,
423,
11948,
14,
362,
8,
1782,
12,
334,
2298,
288,
340,
307,
508,
730,
10388,
355,
3233,
8,
585,
9,
339,
347,
641,
8,
277,
12,
2243,
12,
730,
12,
3233,
304,
267,
291,
423,
11948,
59,
1782,
1055,
740,
1332,
466,
12,
3233,
430,
339,
768,
1829,
272,
347,
1654,
8,
277,
304,
267,
408,
267,
21802,
1654,
370,
6938,
367,
9320,
14,
267,
408,
267,
1654,
275,
2519,
8,
277,
12,
2668,
1000,
401,
488,
9,
267,
340,
1654,
365,
488,
26,
288,
1654,
275,
644,
28732,
4725,
297,
291,
14,
719,
395,
291,
423,
2479,
12,
943,
29,
403,
9,
288,
291,
423,
1000,
275,
1654,
267,
372,
1654,
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,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jainanisha90/WeVoteServer
|
import_export_wikipedia/views_admin.py
|
2
|
3836
|
# import_export_wikipedia/views_admin.py
# Brought to you by We Vote. Be good.
# -*- coding: UTF-8 -*-
from .controllers import retrieve_all_organizations_logos_from_wikipedia, \
retrieve_organization_logo_from_wikipedia_page, retrieve_wikipedia_page_from_wikipedia
from admin_tools.views import redirect_to_sign_in_page
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from organization.models import OrganizationManager
from voter.models import voter_has_authority
import wevote_functions.admin
from wevote_functions.functions import positive_value_exists
logger = wevote_functions.admin.get_logger(__name__)
@login_required
def import_organization_logo_from_wikipedia_view(request, organization_id):
authority_required = {'admin'} # admin, verified_volunteer
if not voter_has_authority(request, authority_required):
return redirect_to_sign_in_page(request, authority_required)
logo_found = False
organization_manager = OrganizationManager()
results = organization_manager.retrieve_organization(organization_id)
if not results['organization_found']:
messages.add_message(request, messages.INFO, results['status'])
return HttpResponseRedirect(reverse('organization:organization_edit', args=(organization_id,)))
organization = results['organization']
# When looking up logos one at a time, we want to force a retrieve
force_retrieve = True
organization_results = retrieve_wikipedia_page_from_wikipedia(organization, force_retrieve)
if organization_results['wikipedia_page_found']:
wikipedia_page = organization_results['wikipedia_page']
logo_results = retrieve_organization_logo_from_wikipedia_page(organization, wikipedia_page, force_retrieve)
if logo_results['logo_found']:
logo_found = True
if positive_value_exists(force_retrieve):
if 'image_options' in logo_results:
for one_image in logo_results['image_options']:
link_to_image = "<a href='{one_image}' target='_blank'>{one_image}</a>".format(one_image=one_image)
messages.add_message(request, messages.INFO, link_to_image)
if not logo_results['success']:
messages.add_message(request, messages.ERROR, logo_results['status'])
else:
messages.add_message(request, messages.ERROR, "Wikipedia page not found. " + organization_results['status'])
if logo_found:
messages.add_message(request, messages.INFO, "Wikipedia logo retrieved.")
else:
messages.add_message(request, messages.ERROR, "Wikipedia logo not retrieved.")
return HttpResponseRedirect(reverse('organization:organization_position_list', args=(organization_id,)))
@login_required
def retrieve_all_organizations_logos_from_wikipedia_view(request):
authority_required = {'admin'} # admin, verified_volunteer
if not voter_has_authority(request, authority_required):
return redirect_to_sign_in_page(request, authority_required)
organization_state_code = request.GET.get('organization_state', '')
results = retrieve_all_organizations_logos_from_wikipedia(organization_state_code)
if not results['success']:
messages.add_message(request, messages.INFO, results['status'])
else:
logos_found = results['logos_found']
messages.add_message(request, messages.INFO, "Wikipedia logos retrieved. "
"Logos found: {logos_found}".format(logos_found=logos_found))
return HttpResponseRedirect(reverse('organization:organization_list', args=()) +
"?organization_state=" + organization_state_code)
|
mit
|
[
3,
492,
63,
3790,
63,
13961,
15,
4196,
63,
2113,
14,
647,
199,
3,
699,
7930,
913,
370,
1265,
701,
2136,
812,
1583,
14,
6423,
6954,
14,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
504,
1275,
20531,
492,
8044,
63,
452,
63,
19916,
12270,
63,
793,
736,
63,
504,
63,
13961,
12,
971,
272,
8044,
63,
9071,
63,
9733,
63,
504,
63,
13961,
63,
1606,
12,
8044,
63,
13961,
63,
1606,
63,
504,
63,
13961,
199,
504,
4628,
63,
2537,
14,
4196,
492,
4660,
63,
475,
63,
1037,
63,
262,
63,
1606,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
13237,
14,
992,
492,
18863,
2988,
199,
504,
14164,
351,
14,
992,
492,
14164,
351,
63,
1989,
63,
23635,
199,
646,
781,
14317,
63,
5777,
14,
2113,
199,
504,
781,
14317,
63,
5777,
14,
5777,
492,
7317,
63,
585,
63,
2444,
199,
199,
2921,
275,
781,
14317,
63,
5777,
14,
2113,
14,
362,
63,
2921,
3460,
354,
3368,
421,
199,
32,
2886,
63,
2427,
199,
318,
492,
63,
9071,
63,
9733,
63,
504,
63,
13961,
63,
1345,
8,
1069,
12,
13237,
63,
344,
304,
272,
18330,
63,
2427,
275,
791,
2113,
936,
221,
327,
4628,
12,
16317,
63,
5650,
27929,
272,
340,
440,
14164,
351,
63,
1989,
63,
23635,
8,
1069,
12,
18330,
63,
2427,
304,
267,
372,
4660,
63,
475,
63,
1037,
63,
262,
63,
1606,
8,
1069,
12,
18330,
63,
2427,
9,
339,
23623,
63,
4214,
275,
756,
339,
13237,
63,
2609,
275,
18863,
2988,
342,
272,
2058,
275,
13237,
63,
2609,
14,
14270,
63,
9071,
8,
9071,
63,
344,
9,
339,
340,
440,
2058,
459,
9071,
63,
4214,
2565,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
2058,
459,
1205,
1105,
267,
372,
14935,
8,
4471,
360,
9071,
26,
9071,
63,
3773,
297,
1249,
2687,
9071,
63,
344,
20097,
339,
13237,
275,
2058,
459,
9071,
418,
339,
327,
3979,
10023,
1536,
943,
736,
1373,
737,
282,
900,
12,
781,
2934,
370,
3542,
282,
8044,
272,
3542,
63,
14270,
275,
715,
272,
13237,
63,
2604,
275,
8044,
63,
13961,
63,
1606,
63,
504,
63,
13961,
8,
9071,
12,
3542,
63,
14270,
9,
339,
340,
13237,
63,
2604,
459,
13961,
63,
1606,
63,
4214,
2565,
267,
336,
29386,
63,
1606,
275,
13237,
63,
2604,
459,
13961,
63,
1606,
418,
398,
23623,
63,
2604,
275,
8044,
63,
9071,
63,
9733,
63,
504,
63,
13961,
63,
1606,
8,
9071,
12,
336,
29386,
63,
1606,
12,
3542,
63,
14270,
9,
267,
340,
23623,
63,
2604,
459,
9733,
63,
4214,
2565,
288,
23623,
63,
4214,
275,
715,
398,
340,
7317,
63,
585,
63,
2444,
8,
3990,
63,
14270,
304,
288,
340,
283,
1569,
63,
1419,
7,
315,
23623,
63,
2604,
26,
355,
367,
1373,
63,
1569,
315,
23623,
63,
2604,
459,
1569,
63,
1419,
2565,
490,
2142,
63,
475,
63,
1569,
275,
3886,
65,
4369,
32134,
368,
63,
1569,
6834,
1347,
17574,
2500,
8423,
91,
368,
63,
1569,
17890,
65,
23167,
908,
8,
368,
63,
1569,
29,
368,
63,
1569,
9,
490,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
2142,
63,
475,
63,
1569,
9,
398,
340,
440,
23623,
63,
2604,
459,
3742,
2565,
288,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
3170,
12,
23623,
63,
2604,
459,
1205,
1105,
272,
587,
26,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
3170,
12,
298,
55,
29386,
2034,
440,
1911,
14,
298,
435,
13237,
63,
2604,
459,
1205,
1105,
339,
340,
23623,
63,
4214,
26,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
298,
55,
29386,
23623,
12396,
2685,
272,
587,
26,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
3170,
12,
298,
55,
29386,
23623,
440,
12396,
2685,
339,
372,
14935,
8,
4471,
360,
9071,
26,
9071,
63,
3124,
63,
513,
297,
1249,
2687,
9071,
63,
344,
20097,
421,
199,
32,
2886,
63,
2427,
199,
318,
8044,
63,
452,
63,
19916,
12270,
63,
793,
736,
63,
504,
63,
13961,
63,
1345,
8,
1069,
304,
272,
18330,
63,
2427,
275,
791,
2113,
936,
221,
327,
4628,
12,
16317,
63,
5650,
27929,
272,
340,
440,
14164,
351,
63,
1989,
63,
23635,
8,
1069,
12,
18330,
63,
2427,
304,
267,
372,
4660,
63,
475,
63,
1037,
63,
262,
63,
1606,
8,
1069,
12,
18330,
63,
2427,
9,
339,
13237,
63,
929,
63,
600,
275,
1056,
14,
2970,
14,
362,
360,
9071,
63,
929,
297,
4074,
339,
2058,
275,
8044,
63,
452,
63,
19916,
12270,
63,
793,
736,
63,
504,
63,
13961,
8,
9071,
63,
929,
63,
600,
9,
339,
340,
440,
2058,
459,
3742,
2565,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
2058,
459,
1205,
1105,
272,
587,
26,
267,
943,
736,
63,
4214,
275,
2058,
459,
793,
736,
63,
4214,
418,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
298,
55,
29386,
943,
736,
12396,
14,
298,
9349,
298,
2445,
736,
1911,
26,
469,
793,
736,
63,
4214,
5469,
908,
8,
793,
736,
63,
4214,
29,
793,
736,
63,
4214,
430,
339,
372,
14935,
8,
4471,
360,
9071,
26,
9071,
63,
513,
297,
1249,
29,
1012,
435,
1816,
23665,
9071,
63,
929,
628,
435,
13237,
63,
929,
63,
600,
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
] |
[
492,
63,
3790,
63,
13961,
15,
4196,
63,
2113,
14,
647,
199,
3,
699,
7930,
913,
370,
1265,
701,
2136,
812,
1583,
14,
6423,
6954,
14,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
504,
1275,
20531,
492,
8044,
63,
452,
63,
19916,
12270,
63,
793,
736,
63,
504,
63,
13961,
12,
971,
272,
8044,
63,
9071,
63,
9733,
63,
504,
63,
13961,
63,
1606,
12,
8044,
63,
13961,
63,
1606,
63,
504,
63,
13961,
199,
504,
4628,
63,
2537,
14,
4196,
492,
4660,
63,
475,
63,
1037,
63,
262,
63,
1606,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
13237,
14,
992,
492,
18863,
2988,
199,
504,
14164,
351,
14,
992,
492,
14164,
351,
63,
1989,
63,
23635,
199,
646,
781,
14317,
63,
5777,
14,
2113,
199,
504,
781,
14317,
63,
5777,
14,
5777,
492,
7317,
63,
585,
63,
2444,
199,
199,
2921,
275,
781,
14317,
63,
5777,
14,
2113,
14,
362,
63,
2921,
3460,
354,
3368,
421,
199,
32,
2886,
63,
2427,
199,
318,
492,
63,
9071,
63,
9733,
63,
504,
63,
13961,
63,
1345,
8,
1069,
12,
13237,
63,
344,
304,
272,
18330,
63,
2427,
275,
791,
2113,
936,
221,
327,
4628,
12,
16317,
63,
5650,
27929,
272,
340,
440,
14164,
351,
63,
1989,
63,
23635,
8,
1069,
12,
18330,
63,
2427,
304,
267,
372,
4660,
63,
475,
63,
1037,
63,
262,
63,
1606,
8,
1069,
12,
18330,
63,
2427,
9,
339,
23623,
63,
4214,
275,
756,
339,
13237,
63,
2609,
275,
18863,
2988,
342,
272,
2058,
275,
13237,
63,
2609,
14,
14270,
63,
9071,
8,
9071,
63,
344,
9,
339,
340,
440,
2058,
459,
9071,
63,
4214,
2565,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
2058,
459,
1205,
1105,
267,
372,
14935,
8,
4471,
360,
9071,
26,
9071,
63,
3773,
297,
1249,
2687,
9071,
63,
344,
20097,
339,
13237,
275,
2058,
459,
9071,
418,
339,
327,
3979,
10023,
1536,
943,
736,
1373,
737,
282,
900,
12,
781,
2934,
370,
3542,
282,
8044,
272,
3542,
63,
14270,
275,
715,
272,
13237,
63,
2604,
275,
8044,
63,
13961,
63,
1606,
63,
504,
63,
13961,
8,
9071,
12,
3542,
63,
14270,
9,
339,
340,
13237,
63,
2604,
459,
13961,
63,
1606,
63,
4214,
2565,
267,
336,
29386,
63,
1606,
275,
13237,
63,
2604,
459,
13961,
63,
1606,
418,
398,
23623,
63,
2604,
275,
8044,
63,
9071,
63,
9733,
63,
504,
63,
13961,
63,
1606,
8,
9071,
12,
336,
29386,
63,
1606,
12,
3542,
63,
14270,
9,
267,
340,
23623,
63,
2604,
459,
9733,
63,
4214,
2565,
288,
23623,
63,
4214,
275,
715,
398,
340,
7317,
63,
585,
63,
2444,
8,
3990,
63,
14270,
304,
288,
340,
283,
1569,
63,
1419,
7,
315,
23623,
63,
2604,
26,
355,
367,
1373,
63,
1569,
315,
23623,
63,
2604,
459,
1569,
63,
1419,
2565,
490,
2142,
63,
475,
63,
1569,
275,
3886,
65,
4369,
32134,
368,
63,
1569,
6834,
1347,
17574,
2500,
8423,
91,
368,
63,
1569,
17890,
65,
23167,
908,
8,
368,
63,
1569,
29,
368,
63,
1569,
9,
490,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
2142,
63,
475,
63,
1569,
9,
398,
340,
440,
23623,
63,
2604,
459,
3742,
2565,
288,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
3170,
12,
23623,
63,
2604,
459,
1205,
1105,
272,
587,
26,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
3170,
12,
298,
55,
29386,
2034,
440,
1911,
14,
298,
435,
13237,
63,
2604,
459,
1205,
1105,
339,
340,
23623,
63,
4214,
26,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
298,
55,
29386,
23623,
12396,
2685,
272,
587,
26,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
3170,
12,
298,
55,
29386,
23623,
440,
12396,
2685,
339,
372,
14935,
8,
4471,
360,
9071,
26,
9071,
63,
3124,
63,
513,
297,
1249,
2687,
9071,
63,
344,
20097,
421,
199,
32,
2886,
63,
2427,
199,
318,
8044,
63,
452,
63,
19916,
12270,
63,
793,
736,
63,
504,
63,
13961,
63,
1345,
8,
1069,
304,
272,
18330,
63,
2427,
275,
791,
2113,
936,
221,
327,
4628,
12,
16317,
63,
5650,
27929,
272,
340,
440,
14164,
351,
63,
1989,
63,
23635,
8,
1069,
12,
18330,
63,
2427,
304,
267,
372,
4660,
63,
475,
63,
1037,
63,
262,
63,
1606,
8,
1069,
12,
18330,
63,
2427,
9,
339,
13237,
63,
929,
63,
600,
275,
1056,
14,
2970,
14,
362,
360,
9071,
63,
929,
297,
4074,
339,
2058,
275,
8044,
63,
452,
63,
19916,
12270,
63,
793,
736,
63,
504,
63,
13961,
8,
9071,
63,
929,
63,
600,
9,
339,
340,
440,
2058,
459,
3742,
2565,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
2058,
459,
1205,
1105,
272,
587,
26,
267,
943,
736,
63,
4214,
275,
2058,
459,
793,
736,
63,
4214,
418,
267,
3788,
14,
525,
63,
1188,
8,
1069,
12,
3788,
14,
4531,
12,
298,
55,
29386,
943,
736,
12396,
14,
298,
9349,
298,
2445,
736,
1911,
26,
469,
793,
736,
63,
4214,
5469,
908,
8,
793,
736,
63,
4214,
29,
793,
736,
63,
4214,
430,
339,
372,
14935,
8,
4471,
360,
9071,
26,
9071,
63,
513,
297,
1249,
29,
1012,
435,
1816,
23665,
9071,
63,
929,
628,
435,
13237,
63,
929,
63,
600,
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,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
owwlo/Courier
|
src/courier/app/CourierService.py
|
1
|
5234
|
'''
Created on Jan 17, 2015
@author: owwlo
'''
from PyQt5 import QtGui, QtCore, QtQml, QtQuick
from PyQt5.QtCore import QObject, QUrl, Qt, QVariant, QMetaObject, Q_ARG
import threading
import websocket
import json
import logging
from time import sleep
import coloredlogs
WS_URL = "ws://localhost:8888/computer"
RECONNECT_INTERVAL = 5
logger = logging.getLogger("CourierApp")
coloredlogs.install(level = logging.DEBUG, show_hostname = False, show_timestamps = False)
class CourierService(threading.Thread, QObject):
class WebSocketHandler():
def __init__(self, service):
self.__service = service
def onMessage(self, ws, message):
self.__service.onMessage(message)
def onError(self, ws, error):
logger.debug("onError " + str(error))
def onClose(self, ws):
logger.debug("onCLose")
self.__service.ws = None
def onOpen(self, ws):
logger.debug("onOpen")
self.__service.ws = ws
self.__service.token = None
fetchThread = threading.Thread(target=self.__service.fetchToken)
fetchThread.start()
# fetchThread.join()
onTokenFetched = QtCore.pyqtSignal([str])
onNewMessage = QtCore.pyqtSignal([dict])
def __init__(self, app):
threading.Thread.__init__(self)
QObject.__init__(self, app)
self.__app = app
self.handler = self.WebSocketHandler(self)
self.token = None
# Initialize callback lists for
self.__callbacksOnNewMessageFromDevice = []
self.__callbacksOnTokenFetched = []
self.__callbacksOnDeviceConnected = []
def run(self):
while(True):
ws = websocket.WebSocketApp(WS_URL,
on_message=self.handler.onMessage,
on_error=self.handler.onError,
on_close=self.handler.onClose,
on_open=self.handler.onOpen)
ws.run_forever()
logger.error("Lost connection, will try again in %d seconds." % RECONNECT_INTERVAL)
sleep(RECONNECT_INTERVAL)
def fetchToken(self):
MAX_RETRY_CNT = 5
cnt = MAX_RETRY_CNT
while cnt > 0 and self.token == None:
if cnt != MAX_RETRY_CNT:
logger.warn(
"Connect failed, reconnecting... trying count remains: %d" % cnt)
self.sendHash(self.getTokenRequestPackage())
sleep(5)
cnt -= 1
if self.token == None:
logger.error("Cannot connect to server")
# else:
# self.on
def getTokenRequestPackage(self):
return {"type": "operation", "command": "request_token"}
def getReplyRequestPackage(self, cId, replyText):
return {"type": "reply", "cId": str(cId), "content": replyText}
def sendReply(self, cId, replyText):
pkg = self.getReplyRequestPackage(cId, replyText)
self.sendHash(pkg)
def parseMessage(self, message):
parsed = None
try:
parsed = json.loads(message)
except Exception as e:
logger.warn(str(e))
return None
return parsed
def sendHash(self, h):
if self.token:
h["token"] = self.token
j = json.dumps(h)
self.send(j)
def send(self, message):
if self.ws != None:
self.ws.send(message)
else:
logger.error("Socket Failed.")
def onMessage(self, message):
logger.debug("Raw Message from Server: " + message)
msg = self.parseMessage(message)
if msg == None:
return
mtype = msg["type"]
if mtype == "new_msg":
self.onNewMessageFromDevice(msg)
elif mtype == "token_response":
self.onTokenResponse(msg)
elif mtype == "info_paired":
self.onDeviceConnected(msg)
def onTokenResponse(self, message):
logger.debug("Get token from server: " + message["token"])
self.token = message["token"]
for fn in self.__callbacksOnTokenFetched:
fn(self.token)
self.onTokenFetched.emit(self.token)
def onNewMessageFromDevice(self, message):
for fn in self.__callbacksOnNewMessageFromDevice:
fn(message)
self.onNewMessage.emit(message)
def onDeviceConnected(self, message):
for fn in self.__callbacksOnDeviceConnected:
fn(message)
def addOnNewMessageFromDevice(self, callback):
self.__callbacksOnNewMessageFromDevice.append(callback)
def removeOnNewMessageFromDevice(self, callback):
self.__callbacksOnNewMessageFromDevice.remove(callback)
def addOnTokenFetched(self, callback):
self.__callbacksOnTokenFetched.append(callback)
def removeOnTokenFetched(self, callback):
self.__callbacksOnTokenFetched.remove(callback)
def addOnDeviceConnected(self, callback):
self.__callbacksOnDeviceConnected.append(callback)
def removeOnDeviceConnected(self, callback):
self.__callbacksOnDeviceConnected.remove(callback)
|
mit
|
[
2344,
199,
10502,
641,
17474,
5557,
12,
6900,
199,
199,
32,
2502,
26,
312,
978,
320,
199,
2344,
199,
199,
504,
14084,
21,
4519,
492,
5928,
12,
10565,
12,
3959,
49,
757,
12,
3959,
19684,
199,
504,
14084,
21,
14,
10901,
755,
492,
1413,
1692,
12,
1413,
6417,
12,
3959,
12,
27875,
12,
1413,
3396,
1692,
12,
1413,
63,
11611,
199,
646,
5796,
199,
646,
24897,
199,
646,
2022,
199,
646,
2050,
199,
504,
900,
492,
9435,
199,
646,
32076,
7270,
199,
199,
5035,
63,
2632,
275,
298,
3569,
921,
5967,
26,
14871,
15,
23805,
2,
199,
199,
907,
14657,
63,
17359,
275,
959,
199,
199,
2921,
275,
2050,
14,
5572,
480,
35,
567,
4446,
2640,
531,
199,
331,
21252,
7270,
14,
3174,
8,
1896,
275,
2050,
14,
5287,
12,
2498,
63,
4269,
275,
756,
12,
2498,
63,
25430,
275,
756,
9,
199,
199,
533,
445,
567,
4446,
3167,
8,
12562,
14,
4436,
12,
1413,
1692,
304,
339,
1021,
18846,
2461,
837,
398,
347,
636,
826,
721,
277,
12,
2435,
304,
288,
291,
855,
1364,
275,
2435,
398,
347,
641,
2209,
8,
277,
12,
10900,
12,
1245,
304,
288,
291,
855,
1364,
14,
265,
2209,
8,
1188,
9,
398,
347,
641,
547,
8,
277,
12,
10900,
12,
1125,
304,
288,
2512,
14,
1757,
480,
265,
547,
298,
435,
620,
8,
705,
430,
398,
347,
641,
4724,
8,
277,
12,
10900,
304,
288,
2512,
14,
1757,
480,
265,
1981,
3362,
531,
288,
291,
855,
1364,
14,
3569,
275,
488,
398,
347,
641,
4299,
8,
277,
12,
10900,
304,
288,
2512,
14,
1757,
480,
265,
4299,
531,
288,
291,
855,
1364,
14,
3569,
275,
10900,
288,
291,
855,
1364,
14,
1418,
275,
488,
953,
5267,
4436,
275,
5796,
14,
4436,
8,
1375,
29,
277,
855,
1364,
14,
3535,
3264,
9,
288,
5267,
4436,
14,
928,
342,
288,
327,
5267,
4436,
14,
904,
342,
339,
641,
3264,
38,
13534,
275,
10565,
14,
24835,
11274,
779,
495,
566,
272,
641,
4665,
2209,
275,
10565,
14,
24835,
11274,
779,
807,
566,
339,
347,
636,
826,
721,
277,
12,
1145,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
1413,
1692,
855,
826,
721,
277,
12,
1145,
9,
398,
291,
855,
571,
275,
1145,
267,
291,
14,
2232,
275,
291,
14,
18477,
2461,
8,
277,
9,
267,
291,
14,
1418,
275,
488,
398,
327,
11578,
3233,
5548,
367,
4960,
291,
855,
11948,
3314,
4665,
2209,
2532,
2510,
275,
942,
267,
291,
855,
11948,
3314,
3264,
38,
13534,
275,
942,
267,
291,
855,
11948,
3314,
2510,
16382,
275,
942,
339,
347,
1255,
8,
277,
304,
267,
1830,
8,
549,
304,
288,
10900,
275,
24897,
14,
18477,
2640,
8,
5035,
63,
2632,
12,
2511,
641,
63,
1188,
29,
277,
14,
2232,
14,
265,
2209,
12,
2511,
641,
63,
705,
29,
277,
14,
2232,
14,
265,
547,
12,
2511,
641,
63,
1600,
29,
277,
14,
2232,
14,
265,
4724,
12,
2511,
641,
63,
1490,
29,
277,
14,
2232,
14,
265,
4299,
9,
288,
10900,
14,
1065,
63,
21327,
342,
288,
2512,
14,
705,
480,
14074,
1950,
12,
911,
862,
4020,
315,
450,
68,
4696,
2122,
450,
5363,
14657,
63,
17359,
9,
288,
9435,
8,
907,
14657,
63,
17359,
9,
339,
347,
5267,
3264,
8,
277,
304,
267,
9141,
63,
27778,
63,
35,
12460,
275,
959,
267,
12703,
275,
9141,
63,
27778,
63,
35,
12460,
267,
1830,
12703,
690,
378,
436,
291,
14,
1418,
508,
488,
26,
288,
340,
12703,
1137,
9141,
63,
27778,
63,
35,
12460,
26,
355,
2512,
14,
4050,
8,
490,
298,
8631,
3405,
12,
30882,
316,
1396,
9936,
2338,
25803,
26,
450,
68,
2,
450,
12703,
9,
288,
291,
14,
2254,
3476,
8,
277,
14,
362,
3264,
2017,
8599,
1012,
288,
9435,
8,
21,
9,
288,
12703,
4862,
413,
267,
340,
291,
14,
1418,
508,
488,
26,
288,
2512,
14,
705,
480,
6612,
4907,
370,
1654,
531,
267,
327,
587,
26,
267,
327,
258,
291,
14,
265,
339,
347,
664,
3264,
2017,
8599,
8,
277,
304,
267,
372,
2420,
466,
582,
298,
5735,
401,
298,
1531,
582,
298,
1069,
63,
1418,
3570,
339,
347,
664,
14166,
2017,
8599,
8,
277,
12,
286,
1304,
12,
9351,
1872,
304,
267,
372,
2420,
466,
582,
298,
8102,
401,
298,
67,
1304,
582,
620,
8,
67,
1304,
395,
298,
1317,
582,
9351,
1872,
93,
339,
347,
3222,
14166,
8,
277,
12,
286,
1304,
12,
9351,
1872,
304,
267,
5496,
275,
291,
14,
362,
14166,
2017,
8599,
8,
67,
1304,
12,
9351,
1872,
9,
267,
291,
14,
2254,
3476,
8,
4600,
9,
339,
347,
2198,
2209,
8,
277,
12,
1245,
304,
267,
4565,
275,
488,
267,
862,
26,
288,
4565,
275,
2022,
14,
3640,
8,
1188,
9,
267,
871,
2186,
465,
325,
26,
288,
2512,
14,
4050,
8,
495,
8,
69,
430,
288,
372,
488,
267,
372,
4565,
339,
347,
3222,
3476,
8,
277,
12,
394,
304,
267,
340,
291,
14,
1418,
26,
288,
394,
905,
1418,
937,
275,
291,
14,
1418,
267,
1335,
275,
2022,
14,
4180,
8,
72,
9,
267,
291,
14,
2254,
8,
74,
9,
339,
347,
3222,
8,
277,
12,
1245,
304,
267,
340,
291,
14,
3569,
1137,
488,
26,
288,
291,
14,
3569,
14,
2254,
8,
1188,
9,
267,
587,
26,
288,
2512,
14,
705,
480,
3869,
16277,
2685,
339,
347,
641,
2209,
8,
277,
12,
1245,
304,
267,
2512,
14,
1757,
480,
7963,
6430,
687,
7146,
26,
298,
435,
1245,
9,
267,
1499,
275,
291,
14,
1122,
2209,
8,
1188,
9,
267,
340,
1499,
508,
488,
26,
288,
372,
267,
21021,
275,
1499,
905,
466,
937,
267,
340,
21021,
508,
298,
1222,
63,
1328,
582,
288,
291,
14,
265,
4665,
2209,
2532,
2510,
8,
1328,
9,
267,
916,
21021,
508,
298,
1418,
63,
1310,
582,
288,
291,
14,
265,
3264,
2364,
8,
1328,
9,
267,
916,
21021,
508,
298,
815,
63,
29796,
582,
288,
291,
14,
265,
2510,
16382,
8,
1328,
9,
339,
347,
641,
3264,
2364,
8,
277,
12,
1245,
304,
267,
2512,
14,
1757,
480,
1002,
1526,
687,
1654,
26,
298,
435,
1245,
905,
1418,
3135,
267,
291,
14,
1418,
275,
1245,
905,
1418,
937,
267,
367,
4325,
315,
291,
855,
11948,
3314,
3264,
38
] |
[
199,
10502,
641,
17474,
5557,
12,
6900,
199,
199,
32,
2502,
26,
312,
978,
320,
199,
2344,
199,
199,
504,
14084,
21,
4519,
492,
5928,
12,
10565,
12,
3959,
49,
757,
12,
3959,
19684,
199,
504,
14084,
21,
14,
10901,
755,
492,
1413,
1692,
12,
1413,
6417,
12,
3959,
12,
27875,
12,
1413,
3396,
1692,
12,
1413,
63,
11611,
199,
646,
5796,
199,
646,
24897,
199,
646,
2022,
199,
646,
2050,
199,
504,
900,
492,
9435,
199,
646,
32076,
7270,
199,
199,
5035,
63,
2632,
275,
298,
3569,
921,
5967,
26,
14871,
15,
23805,
2,
199,
199,
907,
14657,
63,
17359,
275,
959,
199,
199,
2921,
275,
2050,
14,
5572,
480,
35,
567,
4446,
2640,
531,
199,
331,
21252,
7270,
14,
3174,
8,
1896,
275,
2050,
14,
5287,
12,
2498,
63,
4269,
275,
756,
12,
2498,
63,
25430,
275,
756,
9,
199,
199,
533,
445,
567,
4446,
3167,
8,
12562,
14,
4436,
12,
1413,
1692,
304,
339,
1021,
18846,
2461,
837,
398,
347,
636,
826,
721,
277,
12,
2435,
304,
288,
291,
855,
1364,
275,
2435,
398,
347,
641,
2209,
8,
277,
12,
10900,
12,
1245,
304,
288,
291,
855,
1364,
14,
265,
2209,
8,
1188,
9,
398,
347,
641,
547,
8,
277,
12,
10900,
12,
1125,
304,
288,
2512,
14,
1757,
480,
265,
547,
298,
435,
620,
8,
705,
430,
398,
347,
641,
4724,
8,
277,
12,
10900,
304,
288,
2512,
14,
1757,
480,
265,
1981,
3362,
531,
288,
291,
855,
1364,
14,
3569,
275,
488,
398,
347,
641,
4299,
8,
277,
12,
10900,
304,
288,
2512,
14,
1757,
480,
265,
4299,
531,
288,
291,
855,
1364,
14,
3569,
275,
10900,
288,
291,
855,
1364,
14,
1418,
275,
488,
953,
5267,
4436,
275,
5796,
14,
4436,
8,
1375,
29,
277,
855,
1364,
14,
3535,
3264,
9,
288,
5267,
4436,
14,
928,
342,
288,
327,
5267,
4436,
14,
904,
342,
339,
641,
3264,
38,
13534,
275,
10565,
14,
24835,
11274,
779,
495,
566,
272,
641,
4665,
2209,
275,
10565,
14,
24835,
11274,
779,
807,
566,
339,
347,
636,
826,
721,
277,
12,
1145,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
1413,
1692,
855,
826,
721,
277,
12,
1145,
9,
398,
291,
855,
571,
275,
1145,
267,
291,
14,
2232,
275,
291,
14,
18477,
2461,
8,
277,
9,
267,
291,
14,
1418,
275,
488,
398,
327,
11578,
3233,
5548,
367,
4960,
291,
855,
11948,
3314,
4665,
2209,
2532,
2510,
275,
942,
267,
291,
855,
11948,
3314,
3264,
38,
13534,
275,
942,
267,
291,
855,
11948,
3314,
2510,
16382,
275,
942,
339,
347,
1255,
8,
277,
304,
267,
1830,
8,
549,
304,
288,
10900,
275,
24897,
14,
18477,
2640,
8,
5035,
63,
2632,
12,
2511,
641,
63,
1188,
29,
277,
14,
2232,
14,
265,
2209,
12,
2511,
641,
63,
705,
29,
277,
14,
2232,
14,
265,
547,
12,
2511,
641,
63,
1600,
29,
277,
14,
2232,
14,
265,
4724,
12,
2511,
641,
63,
1490,
29,
277,
14,
2232,
14,
265,
4299,
9,
288,
10900,
14,
1065,
63,
21327,
342,
288,
2512,
14,
705,
480,
14074,
1950,
12,
911,
862,
4020,
315,
450,
68,
4696,
2122,
450,
5363,
14657,
63,
17359,
9,
288,
9435,
8,
907,
14657,
63,
17359,
9,
339,
347,
5267,
3264,
8,
277,
304,
267,
9141,
63,
27778,
63,
35,
12460,
275,
959,
267,
12703,
275,
9141,
63,
27778,
63,
35,
12460,
267,
1830,
12703,
690,
378,
436,
291,
14,
1418,
508,
488,
26,
288,
340,
12703,
1137,
9141,
63,
27778,
63,
35,
12460,
26,
355,
2512,
14,
4050,
8,
490,
298,
8631,
3405,
12,
30882,
316,
1396,
9936,
2338,
25803,
26,
450,
68,
2,
450,
12703,
9,
288,
291,
14,
2254,
3476,
8,
277,
14,
362,
3264,
2017,
8599,
1012,
288,
9435,
8,
21,
9,
288,
12703,
4862,
413,
267,
340,
291,
14,
1418,
508,
488,
26,
288,
2512,
14,
705,
480,
6612,
4907,
370,
1654,
531,
267,
327,
587,
26,
267,
327,
258,
291,
14,
265,
339,
347,
664,
3264,
2017,
8599,
8,
277,
304,
267,
372,
2420,
466,
582,
298,
5735,
401,
298,
1531,
582,
298,
1069,
63,
1418,
3570,
339,
347,
664,
14166,
2017,
8599,
8,
277,
12,
286,
1304,
12,
9351,
1872,
304,
267,
372,
2420,
466,
582,
298,
8102,
401,
298,
67,
1304,
582,
620,
8,
67,
1304,
395,
298,
1317,
582,
9351,
1872,
93,
339,
347,
3222,
14166,
8,
277,
12,
286,
1304,
12,
9351,
1872,
304,
267,
5496,
275,
291,
14,
362,
14166,
2017,
8599,
8,
67,
1304,
12,
9351,
1872,
9,
267,
291,
14,
2254,
3476,
8,
4600,
9,
339,
347,
2198,
2209,
8,
277,
12,
1245,
304,
267,
4565,
275,
488,
267,
862,
26,
288,
4565,
275,
2022,
14,
3640,
8,
1188,
9,
267,
871,
2186,
465,
325,
26,
288,
2512,
14,
4050,
8,
495,
8,
69,
430,
288,
372,
488,
267,
372,
4565,
339,
347,
3222,
3476,
8,
277,
12,
394,
304,
267,
340,
291,
14,
1418,
26,
288,
394,
905,
1418,
937,
275,
291,
14,
1418,
267,
1335,
275,
2022,
14,
4180,
8,
72,
9,
267,
291,
14,
2254,
8,
74,
9,
339,
347,
3222,
8,
277,
12,
1245,
304,
267,
340,
291,
14,
3569,
1137,
488,
26,
288,
291,
14,
3569,
14,
2254,
8,
1188,
9,
267,
587,
26,
288,
2512,
14,
705,
480,
3869,
16277,
2685,
339,
347,
641,
2209,
8,
277,
12,
1245,
304,
267,
2512,
14,
1757,
480,
7963,
6430,
687,
7146,
26,
298,
435,
1245,
9,
267,
1499,
275,
291,
14,
1122,
2209,
8,
1188,
9,
267,
340,
1499,
508,
488,
26,
288,
372,
267,
21021,
275,
1499,
905,
466,
937,
267,
340,
21021,
508,
298,
1222,
63,
1328,
582,
288,
291,
14,
265,
4665,
2209,
2532,
2510,
8,
1328,
9,
267,
916,
21021,
508,
298,
1418,
63,
1310,
582,
288,
291,
14,
265,
3264,
2364,
8,
1328,
9,
267,
916,
21021,
508,
298,
815,
63,
29796,
582,
288,
291,
14,
265,
2510,
16382,
8,
1328,
9,
339,
347,
641,
3264,
2364,
8,
277,
12,
1245,
304,
267,
2512,
14,
1757,
480,
1002,
1526,
687,
1654,
26,
298,
435,
1245,
905,
1418,
3135,
267,
291,
14,
1418,
275,
1245,
905,
1418,
937,
267,
367,
4325,
315,
291,
855,
11948,
3314,
3264,
38,
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
] |
popazerty/beyonwiz-4.1
|
lib/python/Screens/TaskList.py
|
7
|
3028
|
# -*- coding: utf-8 -*-
# taken from mytube plugin
from enigma import eTimer
from Screens.Screen import Screen
from Components.ActionMap import ActionMap
from Components.Button import Button
from Components.Label import Label
from Components.Sources.List import List
from Components.MultiContent import MultiContentEntryText
from Components.Task import job_manager
class TaskListScreen(Screen):
skin = """
<screen name="TaskListScreen" position="center,center" size="720,576" title="Task list" >
<widget source="tasklist" render="Listbox" position="10,10" size="690,490" zPosition="7" scrollbarMode="showOnDemand">
<convert type="TemplatedMultiContent">
{"template": [
MultiContentEntryText(pos = (5, 1), size = (675, 24), font=1, flags = RT_HALIGN_LEFT, text = 1), # name
MultiContentEntryText(pos = (5, 25), size = (150, 24), font=1, flags = RT_HALIGN_LEFT, text = 2), # state
MultiContentEntryProgress(pos = (160, 25), size = (390, 20), percent = -3), # progress
MultiContentEntryText(pos = (560, 25), size = (100, 24), font=1, flags = RT_HALIGN_RIGHT, text = 4), # percentage
],
"fonts": [gFont("Regular", 22),gFont("Regular", 18)],
"itemHeight": 50
}
</convert>
</widget>
<ePixmap position="10,530" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
<widget name="key_red" position="10,530" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1"/>
</screen>"""
def __init__(self, session, tasklist):
Screen.__init__(self, session)
self.session = session
self.tasklist = tasklist
self["tasklist"] = List(self.tasklist)
self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions", "MediaPlayerActions"],
{
"ok": self.keyOK,
"back": self.keyCancel,
"red": self.keyCancel,
}, -1)
self["key_red"] = Button(_("Close"))
self.onLayoutFinish.append(self.layoutFinished)
self.onShown.append(self.setWindowTitle)
self.onClose.append(self.__onClose)
self.Timer = eTimer()
self.Timer.callback.append(self.TimerFire)
def __onClose(self):
del self.Timer
def layoutFinished(self):
self.Timer.startLongTimer(2)
def TimerFire(self):
self.Timer.stop()
self.rebuildTaskList()
def rebuildTaskList(self):
self.tasklist = []
for job in job_manager.getPendingJobs():
self.tasklist.append((job,job.name,job.getStatustext(),int(100*job.progress/float(job.end)) ,str(100*job.progress/float(job.end)) + "%" ))
self['tasklist'].setList(self.tasklist)
self['tasklist'].updateList(self.tasklist)
self.Timer.startLongTimer(2)
def setWindowTitle(self):
self.setTitle(_("Task list"))
def keyOK(self):
current = self["tasklist"].getCurrent()
print current
if current:
job = current[0]
from Screens.TaskView import JobView
self.session.openWithCallback(self.JobViewCB, JobView, job)
def JobViewCB(self, why):
print "WHY---",why
def keyCancel(self):
self.close()
def keySave(self):
self.close()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
9394,
687,
3002,
84,
3375,
3589,
199,
199,
504,
655,
27021,
492,
325,
7929,
199,
504,
29372,
14,
9616,
492,
17804,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
199,
504,
17823,
14,
4259,
492,
16005,
199,
504,
17823,
14,
4314,
492,
10354,
199,
504,
17823,
14,
13959,
14,
1296,
492,
3820,
199,
504,
17823,
14,
3947,
2714,
492,
6879,
2714,
3900,
1872,
199,
504,
17823,
14,
4476,
492,
3906,
63,
2609,
421,
199,
533,
8495,
1296,
9616,
8,
9616,
304,
199,
198,
16409,
275,
408,
507,
198,
28,
5410,
536,
628,
4476,
1296,
9616,
2,
3421,
628,
4218,
12,
4218,
2,
1568,
628,
18386,
12,
12255,
2,
2538,
628,
4476,
769,
2,
690,
686,
198,
28,
3440,
1350,
628,
1765,
513,
2,
3795,
628,
1296,
1977,
2,
3421,
628,
709,
12,
709,
2,
1568,
628,
24495,
12,
26410,
2,
1315,
5625,
628,
23,
2,
13704,
1700,
1385,
628,
2384,
3314,
872,
10333,
1743,
1585,
198,
28,
3916,
730,
628,
6530,
1776,
3947,
2714,
1743,
1871,
198,
6641,
1160,
582,
359,
5264,
198,
3947,
2714,
3900,
1872,
8,
1712,
275,
334,
21,
12,
413,
395,
1568,
275,
334,
19895,
12,
5504,
395,
5023,
29,
17,
12,
3285,
275,
24090,
63,
40,
15255,
63,
9894,
12,
1318,
275,
413,
395,
327,
536,
5264,
198,
3947,
2714,
3900,
1872,
8,
1712,
275,
334,
21,
12,
5661,
395,
1568,
275,
334,
8251,
12,
5504,
395,
5023,
29,
17,
12,
3285,
275,
24090,
63,
40,
15255,
63,
9894,
12,
1318,
275,
499,
395,
327,
1174,
5264,
198,
3947,
2714,
3900,
11504,
8,
1712,
275,
334,
8488,
12,
5661,
395,
1568,
275,
334,
12302,
12,
3388,
395,
8878,
275,
446,
19,
395,
327,
6696,
5264,
198,
3947,
2714,
3900,
1872,
8,
1712,
275,
334,
15789,
12,
5661,
395,
1568,
275,
334,
1960,
12,
5504,
395,
5023,
29,
17,
12,
3285,
275,
24090,
63,
40,
15255,
63,
12811,
12,
1318,
275,
841,
395,
327,
16327,
4671,
198,
467,
1871,
198,
2,
19864,
582,
359,
71,
6986,
480,
16038,
401,
6928,
395,
71,
6986,
480,
16038,
401,
6155,
4360,
1871,
198,
2,
1053,
8436,
582,
5238,
1871,
198,
93,
1585,
198,
1108,
3916,
30,
686,
198,
1108,
3440,
30,
686,
198,
28,
69,
16049,
3421,
628,
709,
12,
27030,
2,
1568,
628,
10037,
12,
2167,
2,
29876,
628,
16409,
63,
885,
15,
15687,
15,
581,
14,
4524,
2,
17265,
628,
17,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
3440,
536,
628,
498,
63,
581,
2,
3421,
628,
709,
12,
27030,
2,
1315,
5625,
628,
21,
2,
1568,
628,
10037,
12,
2167,
2,
27554,
628,
4218,
2,
394,
5743,
628,
4218,
2,
5023,
628,
16038,
27,
2025,
2,
17265,
628,
17,
7897,
507,
198,
1108,
5410,
11193,
421,
198,
318,
636,
826,
721,
277,
12,
2351,
12,
2120,
513,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
277,
14,
1730,
275,
2351,
507,
198,
277,
14,
1765,
513,
275,
2120,
513,
507,
198,
277,
905,
1765,
513,
937,
275,
3820,
8,
277,
14,
1765,
513,
9,
2742,
198,
277,
905,
17469,
937,
275,
10033,
2956,
5234,
28301,
9303,
401,
298,
20120,
9303,
401,
298,
11398,
10921,
9303,
2255,
507,
198,
91,
686,
198,
2,
745,
582,
291,
14,
498,
3593,
12,
686,
198,
2,
894,
582,
291,
14,
498,
9083,
12,
686,
198,
2,
581,
582,
291,
14,
498,
9083,
12,
507,
198,
1386,
446,
17,
9,
2742,
198,
277,
905,
498,
63,
581,
937,
275,
16005,
6115,
4724,
2237,
2742,
198,
277,
14,
265,
4798,
22084,
14,
740,
8,
277,
14,
4209,
13430,
9,
507,
198,
277,
14,
265,
6824,
78,
14,
740,
8,
277,
14,
30601,
9,
507,
198,
277,
14,
265,
4724,
14,
740,
8,
277,
855,
265,
4724,
9,
507,
198,
277,
14,
7929,
275,
325,
7929,
342,
507,
198,
277,
14,
7929,
14,
3058,
14,
740,
8,
277,
14,
7929,
13081,
9,
421,
198,
318,
636,
265,
4724,
8,
277,
304,
507,
198,
2264,
291,
14,
7929,
421,
198,
318,
7054,
13430,
8,
277,
304,
507,
198,
277,
14,
7929,
14,
928,
9551,
7929,
8,
18,
9,
421,
198,
318,
22287,
13081,
8,
277,
304,
507,
198,
277,
14,
7929,
14,
2379,
342,
507,
198,
277,
14,
19278,
4476,
1296,
342,
421,
198,
318,
22110,
4476,
1296,
8,
277,
304,
507,
198,
277,
14,
1765,
513,
275,
942,
507,
198,
509,
3906,
315,
3906,
63,
2609,
14,
362,
15960,
20578,
837,
686,
198,
277,
14,
1765,
513,
14,
740,
1332,
2423,
12,
2423,
14,
354,
12,
2423,
14,
362,
3694,
505,
1062,
442,
8,
1960,
10,
2423,
14,
5734,
15,
1609,
8,
2423,
14,
500,
430,
2360,
495,
8,
1960,
10,
2423,
14,
5734,
15,
1609,
8,
2423,
14,
500,
430,
435,
2071,
2,
5082,
507,
198,
277,
459,
1765,
513,
2278,
409,
1296,
8,
277,
14,
1765,
513,
9,
507,
198,
277,
459,
1765,
513,
2278,
873,
1296,
8,
277,
14,
1765,
513,
9,
507,
198,
277,
14,
7929,
14,
928,
9551,
7929,
8,
18,
9,
421,
198,
318,
663,
4301,
6888,
8,
277,
304,
507,
198,
277,
14,
31675,
6115,
4476,
769,
2237,
421,
198,
318,
790,
3593,
8,
277,
304,
507,
198,
1818,
275,
291,
905,
1765,
513,
4140,
16662,
342,
507,
198,
1361,
1453,
507,
198,
692,
1453,
26,
686,
198,
2423,
275,
1453,
59,
16,
61,
686,
198,
504,
29372,
14,
4476,
2768,
492,
15057,
2768,
686,
198,
277,
14,
1730,
14,
30913,
8,
277,
14,
6694,
2768,
9956,
12,
15057,
2768,
12,
3906,
9,
421,
198,
318,
15057,
2768,
9956,
8,
277,
12,
10842,
304,
507,
198,
1361,
298,
9792,
57,
2595,
401,
26460,
421,
198,
318,
790,
9083,
8,
277,
304,
507,
198,
277,
14,
1600,
342,
421,
198,
318,
790,
8229,
8,
277,
304,
507,
198,
277,
14,
1600,
342,
523,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
9394,
687,
3002,
84,
3375,
3589,
199,
199,
504,
655,
27021,
492,
325,
7929,
199,
504,
29372,
14,
9616,
492,
17804,
199,
504,
17823,
14,
3310,
2956,
492,
10033,
2956,
199,
504,
17823,
14,
4259,
492,
16005,
199,
504,
17823,
14,
4314,
492,
10354,
199,
504,
17823,
14,
13959,
14,
1296,
492,
3820,
199,
504,
17823,
14,
3947,
2714,
492,
6879,
2714,
3900,
1872,
199,
504,
17823,
14,
4476,
492,
3906,
63,
2609,
421,
199,
533,
8495,
1296,
9616,
8,
9616,
304,
199,
198,
16409,
275,
408,
507,
198,
28,
5410,
536,
628,
4476,
1296,
9616,
2,
3421,
628,
4218,
12,
4218,
2,
1568,
628,
18386,
12,
12255,
2,
2538,
628,
4476,
769,
2,
690,
686,
198,
28,
3440,
1350,
628,
1765,
513,
2,
3795,
628,
1296,
1977,
2,
3421,
628,
709,
12,
709,
2,
1568,
628,
24495,
12,
26410,
2,
1315,
5625,
628,
23,
2,
13704,
1700,
1385,
628,
2384,
3314,
872,
10333,
1743,
1585,
198,
28,
3916,
730,
628,
6530,
1776,
3947,
2714,
1743,
1871,
198,
6641,
1160,
582,
359,
5264,
198,
3947,
2714,
3900,
1872,
8,
1712,
275,
334,
21,
12,
413,
395,
1568,
275,
334,
19895,
12,
5504,
395,
5023,
29,
17,
12,
3285,
275,
24090,
63,
40,
15255,
63,
9894,
12,
1318,
275,
413,
395,
327,
536,
5264,
198,
3947,
2714,
3900,
1872,
8,
1712,
275,
334,
21,
12,
5661,
395,
1568,
275,
334,
8251,
12,
5504,
395,
5023,
29,
17,
12,
3285,
275,
24090,
63,
40,
15255,
63,
9894,
12,
1318,
275,
499,
395,
327,
1174,
5264,
198,
3947,
2714,
3900,
11504,
8,
1712,
275,
334,
8488,
12,
5661,
395,
1568,
275,
334,
12302,
12,
3388,
395,
8878,
275,
446,
19,
395,
327,
6696,
5264,
198,
3947,
2714,
3900,
1872,
8,
1712,
275,
334,
15789,
12,
5661,
395,
1568,
275,
334,
1960,
12,
5504,
395,
5023,
29,
17,
12,
3285,
275,
24090,
63,
40,
15255,
63,
12811,
12,
1318,
275,
841,
395,
327,
16327,
4671,
198,
467,
1871,
198,
2,
19864,
582,
359,
71,
6986,
480,
16038,
401,
6928,
395,
71,
6986,
480,
16038,
401,
6155,
4360,
1871,
198,
2,
1053,
8436,
582,
5238,
1871,
198,
93,
1585,
198,
1108,
3916,
30,
686,
198,
1108,
3440,
30,
686,
198,
28,
69,
16049,
3421,
628,
709,
12,
27030,
2,
1568,
628,
10037,
12,
2167,
2,
29876,
628,
16409,
63,
885,
15,
15687,
15,
581,
14,
4524,
2,
17265,
628,
17,
2,
9797,
27126,
628,
265,
2,
7082,
686,
198,
28,
3440,
536,
628,
498,
63,
581,
2,
3421,
628,
709,
12,
27030,
2,
1315,
5625,
628,
21,
2,
1568,
628,
10037,
12,
2167,
2,
27554,
628,
4218,
2,
394,
5743,
628,
4218,
2,
5023,
628,
16038,
27,
2025,
2,
17265,
628,
17,
7897,
507,
198,
1108,
5410,
11193,
421,
198,
318,
636,
826,
721,
277,
12,
2351,
12,
2120,
513,
304,
507,
198,
9616,
855,
826,
721,
277,
12,
2351,
9,
507,
198,
277,
14,
1730,
275,
2351,
507,
198,
277,
14,
1765,
513,
275,
2120,
513,
507,
198,
277,
905,
1765,
513,
937,
275,
3820,
8,
277,
14,
1765,
513,
9,
2742,
198,
277,
905,
17469,
937,
275,
10033,
2956,
5234,
28301,
9303,
401,
298,
20120,
9303,
401,
298,
11398,
10921,
9303,
2255,
507,
198,
91,
686,
198,
2,
745,
582,
291,
14,
498,
3593,
12,
686,
198,
2,
894,
582,
291,
14,
498,
9083,
12,
686,
198,
2,
581,
582,
291,
14,
498,
9083,
12,
507,
198,
1386,
446,
17,
9,
2742,
198,
277,
905,
498,
63,
581,
937,
275,
16005,
6115,
4724,
2237,
2742,
198,
277,
14,
265,
4798,
22084,
14,
740,
8,
277,
14,
4209,
13430,
9,
507,
198,
277,
14,
265,
6824,
78,
14,
740,
8,
277,
14,
30601,
9,
507,
198,
277,
14,
265,
4724,
14,
740,
8,
277,
855,
265,
4724,
9,
507,
198,
277,
14,
7929,
275,
325,
7929,
342,
507,
198,
277,
14,
7929,
14,
3058,
14,
740,
8,
277,
14,
7929,
13081,
9,
421,
198,
318,
636,
265,
4724,
8,
277,
304,
507,
198,
2264,
291,
14,
7929,
421,
198,
318,
7054,
13430,
8,
277,
304,
507,
198,
277,
14,
7929,
14,
928,
9551,
7929,
8,
18,
9,
421,
198,
318,
22287,
13081,
8,
277,
304,
507,
198,
277,
14,
7929,
14,
2379,
342,
507,
198,
277,
14,
19278,
4476,
1296,
342,
421,
198,
318,
22110,
4476,
1296,
8,
277,
304,
507,
198,
277,
14,
1765,
513,
275,
942,
507,
198,
509,
3906,
315,
3906,
63,
2609,
14,
362,
15960,
20578,
837,
686,
198,
277,
14,
1765,
513,
14,
740,
1332,
2423,
12,
2423,
14,
354,
12,
2423,
14,
362,
3694,
505,
1062,
442,
8,
1960,
10,
2423,
14,
5734,
15,
1609,
8,
2423,
14,
500,
430,
2360,
495,
8,
1960,
10,
2423,
14,
5734,
15,
1609,
8,
2423,
14,
500,
430,
435,
2071,
2,
5082,
507,
198,
277,
459,
1765,
513,
2278,
409,
1296,
8,
277,
14,
1765,
513,
9,
507,
198,
277,
459,
1765,
513,
2278,
873,
1296,
8,
277,
14,
1765,
513,
9,
507,
198,
277,
14,
7929,
14,
928,
9551,
7929,
8,
18,
9,
421,
198,
318,
663,
4301,
6888,
8,
277,
304,
507,
198,
277,
14,
31675,
6115,
4476,
769,
2237,
421,
198,
318,
790,
3593,
8,
277,
304,
507,
198,
1818,
275,
291,
905,
1765,
513,
4140,
16662,
342,
507,
198,
1361,
1453,
507,
198,
692,
1453,
26,
686,
198,
2423,
275,
1453,
59,
16,
61,
686,
198,
504,
29372,
14,
4476,
2768,
492,
15057,
2768,
686,
198,
277,
14,
1730,
14,
30913,
8,
277,
14,
6694,
2768,
9956,
12,
15057,
2768,
12,
3906,
9,
421,
198,
318,
15057,
2768,
9956,
8,
277,
12,
10842,
304,
507,
198,
1361,
298,
9792,
57,
2595,
401,
26460,
421,
198,
318,
790,
9083,
8,
277,
304,
507,
198,
277,
14,
1600,
342,
421,
198,
318,
790,
8229,
8,
277,
304,
507,
198,
277,
14,
1600,
342,
523,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
philhassey/zanthor
|
zanthor/explode.py
|
2
|
4998
|
import pygame
from pygame.locals import *
import random
from pgu import timer
rr = random.randrange
class Part:
def __init__(self,pos):
self.pos = pygame.Rect(pos[0],pos[1],1,1)
self._pos = pygame.Rect(self.pos)
self.frame = 0
SIZE = 16 #32 is original
class Effect:
def __init__(self,total,add):
if not hasattr(Effect,'init'):
Effect._init(self)
self.total = total
self._total = 0
self.add = add
self.parts = []
self.frame = 0
def _init(self):
Effect.init = True
Effect.colors = colors = []
for r in xrange(0,32):
if r < 8:
rr = r-0
c = (255,255,255-rr*8)
elif r < 16:
rr = r-8
c = (255,255-rr*16,255-(rr+8)*8)
else:
rr = r-16
c = (255-rr*8,128-rr*8,128-rr*8)
colors.append(c)
Effect.images = images = []
for v in xrange(0,32):
r = max(1,v*SIZE/32)
img = pygame.Surface((r*2,r*2)).convert()
img.fill((255,0,255))
img.set_colorkey((255,0,255))
img.set_alpha(255-v*8)
if v < 8:
rr = v-0
c = (255,255,255-rr*8)
elif v < 16:
rr = v-8
c = (255,255-rr*16,255-(rr+8)*8)
else:
rr = v-16
c = (255-rr*8,128-rr*8,128-rr*8)
#print c
pygame.draw.circle(img,c,(r,r),max(1,r/2))
#pygame.draw.circle(img,(255-r*8,255-r*8,255-r*8),(r,r),r)
images.append(img)
def paint(self,screen,origin):
if self.frame > 16: return
_screen = screen
center = self.center
sz = 240*SIZE/32
screen = pygame.Surface((sz,sz)).convert()
screen.fill((80,0,0))
screen.set_colorkey((80,0,0))
f = max(0,self.frame-8)
screen.set_alpha(255-f*32)
adj = (sz/2-center[0],sz/2-center[1])
center = self.center
todo = [[] for n in xrange(0,32)]
for part in self.parts:
p,_p = part.pos,part._pos
xx,yy = abs(center[0]-p.x),abs(center[1]-p.y)
#f = self.frame*2
#r = ( abs((xx*xx+yy*yy) - (f*f)))/256
r = (xx*xx+yy*yy) / (256*SIZE/32)
#dx,dy = p.x-_p.x,p.y-_p.y
#r = ((xx*xx+yy*yy)*(dx*dx+dy*dy))/16384
if r >= 0 and r < 32: todo[r].append((_p,p))
ox,oy = adj
for v in xrange(31,-1,-1):
img = Effect.images[v]
c = Effect.colors[v]
#v = 255-r*8
#c = (v,v,v)
#c = (255,255,255,v)
r = img.get_width()/2 #max(1,v*SIZE/32)
sz = max(1,((32-v)/3+1)*SIZE/32)
for _p,p in todo[v]:
#pygame.draw.circle(screen,c,(p.x+pos[0],p.y+pos[1]),r+3)
#screen.blit(img,(p.x-r+pos[0],p.y-r+pos[1]))
dx,dy = p.x-_p.x,p.y-_p.y
#sz = self.frame
pygame.draw.line(screen,c,(ox+_p.x-dx*1,oy+_p.y-dy*1),(ox+p.x,oy+p.y),sz)
screen.blit(img,(p.x-r+adj[0],p.y-r+adj[1]))
_screen.blit(screen,(-origin[0]+center[0]-screen.get_width()/2,-origin[1]+center[1]-screen.get_height()/2))
def loop(self,pos):
if self.frame > 20: return
self.frame += 1
self.center = pos
parts = self.parts
if self._total < self.total:
for n in xrange(0,self.add):
part = Part((pos[0]+rr(-12*SIZE/32,13*SIZE/32),pos[1]+rr(-12*SIZE/32,13*SIZE/32)))
part._pos.x,part._pos.y = pos[0],pos[1]
parts.append(part)
self._total += 1
l = len(parts)
rm = []
for part in self.parts:
p,_p = part.pos,part._pos
dx,dy = p.x-_p.x,p.y-_p.y
_p.x,_p.y = p.x,p.y
p.x += dx
p.y += dy
if __name__ == '__main__':
screen = pygame.display.set_mode((640,480))
#ss = [((rr(160,640),rr(160,480)),Effect(256,64)) for n in xrange(0,1)]
ss = []
t = timer.Timer(40)
f = 0
_quit = False
while not _quit:
for e in pygame.event.get():
if e.type is QUIT: _quit = True
if e.type is KEYDOWN and e.key == K_ESCAPE: _quit = True
screen.fill((0,0,0))
for pos,s in ss:
s.loop(pos)
s.paint(screen,(0,0))
pygame.display.flip()
if f%20 == 0:
ss = [((rr(160,480),rr(160,320)),Effect(512,128))]
f += 1
t.tick()
|
gpl-2.0
|
[
646,
9193,
199,
504,
9193,
14,
9350,
492,
627,
199,
646,
2196,
199,
199,
504,
299,
6051,
492,
9715,
199,
199,
9734,
275,
2196,
14,
20539,
199,
199,
533,
14320,
26,
272,
347,
636,
826,
721,
277,
12,
1712,
304,
267,
291,
14,
1712,
275,
9193,
14,
8252,
8,
1712,
59,
16,
467,
1712,
59,
17,
467,
17,
12,
17,
9,
267,
291,
423,
1712,
275,
9193,
14,
8252,
8,
277,
14,
1712,
9,
267,
291,
14,
1943,
275,
378,
199,
199,
4305,
275,
3193,
327,
708,
365,
3379,
199,
199,
533,
662,
5551,
26,
272,
347,
636,
826,
721,
277,
12,
2923,
12,
525,
304,
2728,
340,
440,
2688,
8,
21339,
2584,
826,
735,
288,
662,
5551,
423,
826,
8,
277,
9,
2728,
291,
14,
2923,
275,
3141,
267,
291,
423,
2923,
275,
378,
267,
291,
14,
525,
275,
1050,
2728,
291,
14,
4181,
275,
942,
2728,
291,
14,
1943,
275,
378,
5493,
347,
485,
826,
8,
277,
304,
267,
662,
5551,
14,
826,
275,
715,
267,
662,
5551,
14,
7120,
275,
9229,
275,
942,
267,
367,
519,
315,
4945,
8,
16,
12,
708,
304,
288,
340,
519,
665,
1695,
26,
8892,
17615,
275,
519,
13,
16,
355,
286,
275,
334,
2299,
12,
2299,
12,
2299,
13,
9734,
10,
24,
9,
288,
916,
519,
665,
3193,
26,
355,
17615,
275,
519,
13,
24,
355,
286,
275,
334,
2299,
12,
2299,
13,
9734,
10,
975,
12,
2299,
15426,
9734,
11,
24,
3342,
24,
9,
288,
587,
26,
355,
17615,
275,
519,
13,
975,
355,
286,
275,
334,
2299,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
9,
24850,
9229,
14,
740,
8,
67,
9,
10631,
662,
5551,
14,
4782,
275,
5935,
275,
942,
267,
367,
373,
315,
4945,
8,
16,
12,
708,
304,
288,
519,
275,
1390,
8,
17,
12,
86,
10,
4305,
15,
708,
9,
288,
6050,
275,
9193,
14,
16923,
1332,
82,
10,
18,
12,
82,
10,
18,
4992,
3916,
342,
288,
6050,
14,
4498,
1332,
2299,
12,
16,
12,
2299,
430,
288,
6050,
14,
409,
63,
2326,
498,
1332,
2299,
12,
16,
12,
2299,
430,
288,
6050,
14,
409,
63,
4468,
8,
2299,
13,
86,
10,
24,
9,
7846,
340,
373,
665,
1695,
26,
8892,
17615,
275,
373,
13,
16,
355,
286,
275,
334,
2299,
12,
2299,
12,
2299,
13,
9734,
10,
24,
9,
288,
916,
373,
665,
3193,
26,
355,
17615,
275,
373,
13,
24,
355,
286,
275,
334,
2299,
12,
2299,
13,
9734,
10,
975,
12,
2299,
15426,
9734,
11,
24,
3342,
24,
9,
288,
587,
26,
355,
17615,
275,
373,
13,
975,
355,
286,
275,
334,
2299,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
9,
288,
327,
1361,
286,
288,
9193,
14,
5485,
14,
11001,
8,
4060,
12,
67,
12803,
82,
12,
82,
395,
988,
8,
17,
12,
82,
15,
18,
430,
288,
327,
22278,
14,
5485,
14,
11001,
8,
4060,
12803,
2299,
13,
82,
10,
24,
12,
2299,
13,
82,
10,
24,
12,
2299,
13,
82,
10,
24,
11865,
82,
12,
82,
395,
82,
9,
288,
5935,
14,
740,
8,
4060,
9,
199,
5493,
347,
32055,
8,
277,
12,
5410,
12,
6493,
304,
267,
340,
291,
14,
1943,
690,
3193,
26,
372,
2728,
485,
5410,
275,
6426,
2728,
8126,
275,
291,
14,
4218,
267,
17176,
275,
21883,
10,
4305,
15,
708,
267,
6426,
275,
9193,
14,
16923,
1332,
11803,
12,
11803,
4992,
3916,
342,
4960,
6426,
14,
4498,
1332,
1257,
12,
16,
12,
16,
430,
267,
6426,
14,
409,
63,
2326,
498,
1332,
1257,
12,
16,
12,
16,
430,
267,
289,
275,
1390,
8,
16,
12,
277,
14,
1943,
13,
24,
9,
267,
6426,
14,
409,
63,
4468,
8,
2299,
13,
70,
10,
708,
9,
267,
14510,
275,
334,
11803,
15,
18,
13,
4218,
59,
16,
467,
11803,
15,
18,
13,
4218,
59,
17,
566,
2728,
8126,
275,
291,
14,
4218,
398,
11386,
275,
3474,
61,
367,
302,
315,
4945,
8,
16,
12,
708,
1874,
2728,
367,
1777,
315,
291,
14,
4181,
26,
288,
299,
16987,
80,
275,
1777,
14,
1712,
12,
2064,
423,
1712,
288,
19379,
12,
7566,
275,
2853,
8,
4218,
59,
16,
11285,
80,
14,
88,
395,
2101,
8,
4218,
59,
17,
11285,
80,
14,
89,
9,
288,
327,
70,
275,
291,
14,
1943,
10,
18,
288,
327,
82,
275,
334,
2853,
1332,
2154,
10,
2154,
11,
7566,
10,
7566,
9,
446,
334,
70,
10,
70,
1724,
15,
3912,
288,
519,
275,
221,
334,
2154,
10,
2154,
11,
7566,
10,
7566,
9,
1182,
334,
3912,
10,
4305,
15,
708,
9,
288,
327,
8373,
12,
8161,
275,
299,
14,
88,
13,
63,
80,
14,
88,
12,
80,
14,
89,
13,
63,
80,
14,
89,
288,
327,
82,
275,
3666,
2154,
10,
2154,
11,
7566,
10,
7566,
14397,
8373,
10,
8373,
11,
8161,
10,
8161,
13342,
975,
8188,
288,
340,
519,
2356,
378,
436,
519,
665,
4337,
26,
11386,
59,
82,
1055,
740,
1332,
63,
80,
12,
80,
430,
10631,
312,
88,
12,
79,
89,
275,
14510,
267,
367,
373,
315,
4945,
8,
2192,
3057,
17,
3057,
17,
304,
288,
6050,
275,
662,
5551,
14,
4782,
59,
86,
61,
288,
286,
275,
662,
5551,
14,
7120,
59,
86,
61,
288,
327,
86,
275,
5450,
13,
82,
10,
24,
288,
327,
67,
275,
334,
86,
12,
86,
12,
86,
9,
288,
327,
67,
275,
334,
2299,
12,
2299,
12,
2299,
12,
86,
9,
288,
519,
275,
6050,
14,
362,
63,
2063,
29728,
18,
327,
988,
8,
17,
12,
86,
10,
4305,
15,
708,
9,
288,
17176,
275,
1390,
8,
17,
12,
1332,
708,
13,
86,
2447,
19,
11,
17,
3342,
4305,
15,
708,
9,
288,
367,
485,
80,
12,
80,
315,
11386,
59,
86,
2189,
355,
327,
22278,
14,
5485,
14,
11001,
8,
5410,
12,
67,
12803,
80,
14,
88,
11,
1712,
59,
16,
467,
80,
14,
89,
11,
1712,
59,
17,
2522,
82,
11,
19,
9,
355,
327,
5410,
14,
15574,
8,
4060,
12803,
80,
14,
88,
13,
82,
11,
1712,
59,
16,
467,
80,
14,
89,
13,
82,
11,
1712,
59,
17,
2459,
14977,
11868,
12,
8161,
275
] |
[
9193,
199,
504,
9193,
14,
9350,
492,
627,
199,
646,
2196,
199,
199,
504,
299,
6051,
492,
9715,
199,
199,
9734,
275,
2196,
14,
20539,
199,
199,
533,
14320,
26,
272,
347,
636,
826,
721,
277,
12,
1712,
304,
267,
291,
14,
1712,
275,
9193,
14,
8252,
8,
1712,
59,
16,
467,
1712,
59,
17,
467,
17,
12,
17,
9,
267,
291,
423,
1712,
275,
9193,
14,
8252,
8,
277,
14,
1712,
9,
267,
291,
14,
1943,
275,
378,
199,
199,
4305,
275,
3193,
327,
708,
365,
3379,
199,
199,
533,
662,
5551,
26,
272,
347,
636,
826,
721,
277,
12,
2923,
12,
525,
304,
2728,
340,
440,
2688,
8,
21339,
2584,
826,
735,
288,
662,
5551,
423,
826,
8,
277,
9,
2728,
291,
14,
2923,
275,
3141,
267,
291,
423,
2923,
275,
378,
267,
291,
14,
525,
275,
1050,
2728,
291,
14,
4181,
275,
942,
2728,
291,
14,
1943,
275,
378,
5493,
347,
485,
826,
8,
277,
304,
267,
662,
5551,
14,
826,
275,
715,
267,
662,
5551,
14,
7120,
275,
9229,
275,
942,
267,
367,
519,
315,
4945,
8,
16,
12,
708,
304,
288,
340,
519,
665,
1695,
26,
8892,
17615,
275,
519,
13,
16,
355,
286,
275,
334,
2299,
12,
2299,
12,
2299,
13,
9734,
10,
24,
9,
288,
916,
519,
665,
3193,
26,
355,
17615,
275,
519,
13,
24,
355,
286,
275,
334,
2299,
12,
2299,
13,
9734,
10,
975,
12,
2299,
15426,
9734,
11,
24,
3342,
24,
9,
288,
587,
26,
355,
17615,
275,
519,
13,
975,
355,
286,
275,
334,
2299,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
9,
24850,
9229,
14,
740,
8,
67,
9,
10631,
662,
5551,
14,
4782,
275,
5935,
275,
942,
267,
367,
373,
315,
4945,
8,
16,
12,
708,
304,
288,
519,
275,
1390,
8,
17,
12,
86,
10,
4305,
15,
708,
9,
288,
6050,
275,
9193,
14,
16923,
1332,
82,
10,
18,
12,
82,
10,
18,
4992,
3916,
342,
288,
6050,
14,
4498,
1332,
2299,
12,
16,
12,
2299,
430,
288,
6050,
14,
409,
63,
2326,
498,
1332,
2299,
12,
16,
12,
2299,
430,
288,
6050,
14,
409,
63,
4468,
8,
2299,
13,
86,
10,
24,
9,
7846,
340,
373,
665,
1695,
26,
8892,
17615,
275,
373,
13,
16,
355,
286,
275,
334,
2299,
12,
2299,
12,
2299,
13,
9734,
10,
24,
9,
288,
916,
373,
665,
3193,
26,
355,
17615,
275,
373,
13,
24,
355,
286,
275,
334,
2299,
12,
2299,
13,
9734,
10,
975,
12,
2299,
15426,
9734,
11,
24,
3342,
24,
9,
288,
587,
26,
355,
17615,
275,
373,
13,
975,
355,
286,
275,
334,
2299,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
12,
3933,
13,
9734,
10,
24,
9,
288,
327,
1361,
286,
288,
9193,
14,
5485,
14,
11001,
8,
4060,
12,
67,
12803,
82,
12,
82,
395,
988,
8,
17,
12,
82,
15,
18,
430,
288,
327,
22278,
14,
5485,
14,
11001,
8,
4060,
12803,
2299,
13,
82,
10,
24,
12,
2299,
13,
82,
10,
24,
12,
2299,
13,
82,
10,
24,
11865,
82,
12,
82,
395,
82,
9,
288,
5935,
14,
740,
8,
4060,
9,
199,
5493,
347,
32055,
8,
277,
12,
5410,
12,
6493,
304,
267,
340,
291,
14,
1943,
690,
3193,
26,
372,
2728,
485,
5410,
275,
6426,
2728,
8126,
275,
291,
14,
4218,
267,
17176,
275,
21883,
10,
4305,
15,
708,
267,
6426,
275,
9193,
14,
16923,
1332,
11803,
12,
11803,
4992,
3916,
342,
4960,
6426,
14,
4498,
1332,
1257,
12,
16,
12,
16,
430,
267,
6426,
14,
409,
63,
2326,
498,
1332,
1257,
12,
16,
12,
16,
430,
267,
289,
275,
1390,
8,
16,
12,
277,
14,
1943,
13,
24,
9,
267,
6426,
14,
409,
63,
4468,
8,
2299,
13,
70,
10,
708,
9,
267,
14510,
275,
334,
11803,
15,
18,
13,
4218,
59,
16,
467,
11803,
15,
18,
13,
4218,
59,
17,
566,
2728,
8126,
275,
291,
14,
4218,
398,
11386,
275,
3474,
61,
367,
302,
315,
4945,
8,
16,
12,
708,
1874,
2728,
367,
1777,
315,
291,
14,
4181,
26,
288,
299,
16987,
80,
275,
1777,
14,
1712,
12,
2064,
423,
1712,
288,
19379,
12,
7566,
275,
2853,
8,
4218,
59,
16,
11285,
80,
14,
88,
395,
2101,
8,
4218,
59,
17,
11285,
80,
14,
89,
9,
288,
327,
70,
275,
291,
14,
1943,
10,
18,
288,
327,
82,
275,
334,
2853,
1332,
2154,
10,
2154,
11,
7566,
10,
7566,
9,
446,
334,
70,
10,
70,
1724,
15,
3912,
288,
519,
275,
221,
334,
2154,
10,
2154,
11,
7566,
10,
7566,
9,
1182,
334,
3912,
10,
4305,
15,
708,
9,
288,
327,
8373,
12,
8161,
275,
299,
14,
88,
13,
63,
80,
14,
88,
12,
80,
14,
89,
13,
63,
80,
14,
89,
288,
327,
82,
275,
3666,
2154,
10,
2154,
11,
7566,
10,
7566,
14397,
8373,
10,
8373,
11,
8161,
10,
8161,
13342,
975,
8188,
288,
340,
519,
2356,
378,
436,
519,
665,
4337,
26,
11386,
59,
82,
1055,
740,
1332,
63,
80,
12,
80,
430,
10631,
312,
88,
12,
79,
89,
275,
14510,
267,
367,
373,
315,
4945,
8,
2192,
3057,
17,
3057,
17,
304,
288,
6050,
275,
662,
5551,
14,
4782,
59,
86,
61,
288,
286,
275,
662,
5551,
14,
7120,
59,
86,
61,
288,
327,
86,
275,
5450,
13,
82,
10,
24,
288,
327,
67,
275,
334,
86,
12,
86,
12,
86,
9,
288,
327,
67,
275,
334,
2299,
12,
2299,
12,
2299,
12,
86,
9,
288,
519,
275,
6050,
14,
362,
63,
2063,
29728,
18,
327,
988,
8,
17,
12,
86,
10,
4305,
15,
708,
9,
288,
17176,
275,
1390,
8,
17,
12,
1332,
708,
13,
86,
2447,
19,
11,
17,
3342,
4305,
15,
708,
9,
288,
367,
485,
80,
12,
80,
315,
11386,
59,
86,
2189,
355,
327,
22278,
14,
5485,
14,
11001,
8,
5410,
12,
67,
12803,
80,
14,
88,
11,
1712,
59,
16,
467,
80,
14,
89,
11,
1712,
59,
17,
2522,
82,
11,
19,
9,
355,
327,
5410,
14,
15574,
8,
4060,
12803,
80,
14,
88,
13,
82,
11,
1712,
59,
16,
467,
80,
14,
89,
13,
82,
11,
1712,
59,
17,
2459,
14977,
11868,
12,
8161,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
githubmlai/numpy
|
numpy/tests/test_matlib.py
|
70
|
1595
|
from __future__ import division, absolute_import, print_function
import numpy as np
import numpy.matlib
from numpy.testing import assert_array_equal, assert_, run_module_suite
def test_empty():
x = np.matlib.empty((2,))
assert_(isinstance(x, np.matrix))
assert_(x.shape, (1, 2))
def test_ones():
assert_array_equal(np.matlib.ones((2, 3)),
np.matrix([[ 1., 1., 1.],
[ 1., 1., 1.]]))
assert_array_equal(np.matlib.ones(2), np.matrix([[ 1., 1.]]))
def test_zeros():
assert_array_equal(np.matlib.zeros((2, 3)),
np.matrix([[ 0., 0., 0.],
[ 0., 0., 0.]]))
assert_array_equal(np.matlib.zeros(2), np.matrix([[ 0., 0.]]))
def test_identity():
x = np.matlib.identity(2, dtype=np.int)
assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))
def test_eye():
x = np.matlib.eye(3, k=1, dtype=int)
assert_array_equal(x, np.matrix([[ 0, 1, 0],
[ 0, 0, 1],
[ 0, 0, 0]]))
def test_rand():
x = np.matlib.rand(3)
# check matrix type, array would have shape (3,)
assert_(x.ndim == 2)
def test_randn():
x = np.matlib.randn(3)
# check matrix type, array would have shape (3,)
assert_(x.ndim == 2)
def test_repmat():
a1 = np.arange(4)
x = np.matlib.repmat(a1, 2, 2)
y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],
[0, 1, 2, 3, 0, 1, 2, 3]])
assert_array_equal(x, y)
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,
2680,
465,
980,
199,
646,
2680,
14,
569,
773,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
1452,
12,
702,
3131,
1255,
63,
578,
63,
5768,
199,
199,
318,
511,
63,
1667,
837,
272,
671,
275,
980,
14,
569,
773,
14,
1667,
1332,
18,
4641,
272,
702,
2531,
6074,
8,
88,
12,
980,
14,
3642,
430,
272,
702,
2531,
88,
14,
1392,
12,
334,
17,
12,
499,
430,
199,
199,
318,
511,
63,
4548,
837,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4548,
1332,
18,
12,
650,
1826,
2432,
980,
14,
3642,
4038,
413,
2020,
221,
413,
2020,
221,
413,
8333,
639,
359,
413,
2020,
221,
413,
2020,
221,
413,
14,
17723,
339,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4548,
8,
18,
395,
980,
14,
3642,
4038,
413,
2020,
221,
413,
14,
17723,
199,
199,
318,
511,
63,
4250,
837,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4250,
1332,
18,
12,
650,
1826,
2432,
980,
14,
3642,
4038,
378,
2020,
221,
378,
2020,
221,
378,
8333,
639,
359,
378,
2020,
221,
378,
2020,
221,
378,
14,
17723,
339,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4250,
8,
18,
395,
980,
14,
3642,
4038,
378,
2020,
221,
378,
14,
17723,
199,
199,
318,
511,
63,
5582,
837,
272,
671,
275,
980,
14,
569,
773,
14,
5582,
8,
18,
12,
2152,
29,
1590,
14,
442,
9,
272,
702,
63,
1144,
63,
1452,
8,
88,
12,
980,
14,
3642,
4038,
17,
12,
378,
467,
359,
16,
12,
413,
17723,
199,
199,
318,
511,
63,
15240,
837,
272,
671,
275,
980,
14,
569,
773,
14,
15240,
8,
19,
12,
1022,
29,
17,
12,
2152,
29,
442,
9,
272,
702,
63,
1144,
63,
1452,
8,
88,
12,
980,
14,
3642,
4038,
378,
12,
221,
413,
12,
221,
378,
467,
3660,
359,
378,
12,
221,
378,
12,
221,
413,
467,
3660,
359,
378,
12,
221,
378,
12,
221,
378,
17723,
199,
199,
318,
511,
63,
3759,
837,
272,
671,
275,
980,
14,
569,
773,
14,
3759,
8,
19,
9,
272,
327,
1104,
3634,
730,
12,
1625,
3955,
1172,
2215,
334,
19,
4258,
272,
702,
2531,
88,
14,
8322,
508,
499,
9,
199,
199,
318,
511,
63,
10843,
837,
272,
671,
275,
980,
14,
569,
773,
14,
10843,
8,
19,
9,
272,
327,
1104,
3634,
730,
12,
1625,
3955,
1172,
2215,
334,
19,
4258,
272,
702,
2531,
88,
14,
8322,
508,
499,
9,
199,
199,
318,
511,
63,
1155,
569,
837,
272,
282,
17,
275,
980,
14,
5605,
8,
20,
9,
272,
671,
275,
980,
14,
569,
773,
14,
1155,
569,
8,
65,
17,
12,
499,
12,
499,
9,
272,
612,
275,
980,
14,
1144,
4038,
16,
12,
413,
12,
499,
12,
650,
12,
378,
12,
413,
12,
499,
12,
650,
467,
2116,
359,
16,
12,
413,
12,
499,
12,
650,
12,
378,
12,
413,
12,
499,
12,
650,
3934,
272,
702,
63,
1144,
63,
1452,
8,
88,
12,
612,
9,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2680,
465,
980,
199,
646,
2680,
14,
569,
773,
199,
504,
2680,
14,
4776,
492,
702,
63,
1144,
63,
1452,
12,
702,
3131,
1255,
63,
578,
63,
5768,
199,
199,
318,
511,
63,
1667,
837,
272,
671,
275,
980,
14,
569,
773,
14,
1667,
1332,
18,
4641,
272,
702,
2531,
6074,
8,
88,
12,
980,
14,
3642,
430,
272,
702,
2531,
88,
14,
1392,
12,
334,
17,
12,
499,
430,
199,
199,
318,
511,
63,
4548,
837,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4548,
1332,
18,
12,
650,
1826,
2432,
980,
14,
3642,
4038,
413,
2020,
221,
413,
2020,
221,
413,
8333,
639,
359,
413,
2020,
221,
413,
2020,
221,
413,
14,
17723,
339,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4548,
8,
18,
395,
980,
14,
3642,
4038,
413,
2020,
221,
413,
14,
17723,
199,
199,
318,
511,
63,
4250,
837,
272,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4250,
1332,
18,
12,
650,
1826,
2432,
980,
14,
3642,
4038,
378,
2020,
221,
378,
2020,
221,
378,
8333,
639,
359,
378,
2020,
221,
378,
2020,
221,
378,
14,
17723,
339,
702,
63,
1144,
63,
1452,
8,
1590,
14,
569,
773,
14,
4250,
8,
18,
395,
980,
14,
3642,
4038,
378,
2020,
221,
378,
14,
17723,
199,
199,
318,
511,
63,
5582,
837,
272,
671,
275,
980,
14,
569,
773,
14,
5582,
8,
18,
12,
2152,
29,
1590,
14,
442,
9,
272,
702,
63,
1144,
63,
1452,
8,
88,
12,
980,
14,
3642,
4038,
17,
12,
378,
467,
359,
16,
12,
413,
17723,
199,
199,
318,
511,
63,
15240,
837,
272,
671,
275,
980,
14,
569,
773,
14,
15240,
8,
19,
12,
1022,
29,
17,
12,
2152,
29,
442,
9,
272,
702,
63,
1144,
63,
1452,
8,
88,
12,
980,
14,
3642,
4038,
378,
12,
221,
413,
12,
221,
378,
467,
3660,
359,
378,
12,
221,
378,
12,
221,
413,
467,
3660,
359,
378,
12,
221,
378,
12,
221,
378,
17723,
199,
199,
318,
511,
63,
3759,
837,
272,
671,
275,
980,
14,
569,
773,
14,
3759,
8,
19,
9,
272,
327,
1104,
3634,
730,
12,
1625,
3955,
1172,
2215,
334,
19,
4258,
272,
702,
2531,
88,
14,
8322,
508,
499,
9,
199,
199,
318,
511,
63,
10843,
837,
272,
671,
275,
980,
14,
569,
773,
14,
10843,
8,
19,
9,
272,
327,
1104,
3634,
730,
12,
1625,
3955,
1172,
2215,
334,
19,
4258,
272,
702,
2531,
88,
14,
8322,
508,
499,
9,
199,
199,
318,
511,
63,
1155,
569,
837,
272,
282,
17,
275,
980,
14,
5605,
8,
20,
9,
272,
671,
275,
980,
14,
569,
773,
14,
1155,
569,
8,
65,
17,
12,
499,
12,
499,
9,
272,
612,
275,
980,
14,
1144,
4038,
16,
12,
413,
12,
499,
12,
650,
12,
378,
12,
413,
12,
499,
12,
650,
467,
2116,
359,
16,
12,
413,
12,
499,
12,
650,
12,
378,
12,
413,
12,
499,
12,
650,
3934,
272,
702,
63,
1144,
63,
1452,
8,
88,
12,
612,
9,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
tankca/store
|
store/dummy_data/orders.py
|
1
|
1720
|
"""Order dummy data."""
from store.orders.models import Order
# from store.orders.models import OrderConsistsOf
# Orders
o1 = Order('cid1')
o2 = Order('cid2')
o3 = Order('cid3')
o4 = Order('cid4')
o5 = Order('cid5')
o6 = Order('cid6')
o7 = Order('cid7')
o8 = Order('cid8')
o9 = Order('cid9')
o10 = Order('cid10')
o11 = Order('cid1')
o12 = Order('cid1')
o13 = Order('cid1')
o14 = Order('cid2')
o15 = Order('cid7')
o16 = Order('cid7')
o17 = Order('cid7')
o18 = Order('cid3')
# oco1 = OrderConsistsOf(o1.id'9780439139595', 3)
# oco2 = OrderConsistsOf(o2.id'9780345803498', 5)
# oco3 = OrderConsistsOf(o3.id'9780345803498', 1)
# oco4 = OrderConsistsOf(o4.id'9780345803481', 2)
# oco5 = OrderConsistsOf(o5.id'9780545139700', 5)
# oco6 = OrderConsistsOf(o6.id'9780439358071', 4)
# oco7 = OrderConsistsOf(o7.id'9780439139595', 5)
# oco8 = OrderConsistsOf(o8.id'9780439784542', 3)
# oco9 = OrderConsistsOf(o9.id'9780439784542', 5)
# oco10 = OrderConsistsOf(o10.id'9780439784542', 15)
sample_list = []
# Orders
sample_list.append(o1)
sample_list.append(o2)
sample_list.append(o3)
sample_list.append(o4)
sample_list.append(o5)
sample_list.append(o6)
sample_list.append(o7)
sample_list.append(o8)
sample_list.append(o9)
sample_list.append(o10)
sample_list.append(o11)
sample_list.append(o12)
sample_list.append(o13)
sample_list.append(o14)
sample_list.append(o15)
sample_list.append(o16)
sample_list.append(o17)
sample_list.append(o18)
# OrderConsistsOf
# sample_list.append(oco1)
# sample_list.append(oco2)
# sample_list.append(oco3)
# sample_list.append(oco4)
# sample_list.append(oco5)
# sample_list.append(oco6)
# sample_list.append(oco7)
# sample_list.append(oco8)
# sample_list.append(oco9)
# sample_list.append(oco10)
|
bsd-3-clause
|
[
624,
4738,
7283,
666,
1041,
199,
199,
504,
3877,
14,
14387,
14,
992,
492,
9240,
199,
3,
687,
3877,
14,
14387,
14,
992,
492,
9240,
714,
338,
10329,
3466,
421,
199,
3,
4236,
7735,
199,
79,
17,
275,
9240,
360,
7504,
17,
358,
199,
79,
18,
275,
9240,
360,
7504,
18,
358,
199,
79,
19,
275,
9240,
360,
7504,
19,
358,
199,
79,
20,
275,
9240,
360,
7504,
20,
358,
199,
79,
21,
275,
9240,
360,
7504,
21,
358,
199,
79,
22,
275,
9240,
360,
7504,
22,
358,
199,
79,
23,
275,
9240,
360,
7504,
23,
358,
199,
79,
24,
275,
9240,
360,
7504,
24,
358,
199,
79,
25,
275,
9240,
360,
7504,
25,
358,
199,
79,
709,
275,
9240,
360,
7504,
709,
358,
199,
79,
845,
275,
9240,
360,
7504,
17,
358,
199,
79,
713,
275,
9240,
360,
7504,
17,
358,
199,
79,
969,
275,
9240,
360,
7504,
17,
358,
199,
79,
1079,
275,
9240,
360,
7504,
18,
358,
199,
79,
1046,
275,
9240,
360,
7504,
23,
358,
199,
79,
975,
275,
9240,
360,
7504,
23,
358,
199,
79,
1196,
275,
9240,
360,
7504,
23,
358,
199,
79,
1085,
275,
9240,
360,
7504,
19,
358,
421,
199,
3,
312,
331,
17,
275,
9240,
714,
338,
10329,
3466,
8,
79,
17,
14,
344,
7,
28690,
966,
1355,
7491,
16447,
297,
650,
9,
199,
3,
312,
331,
18,
275,
9240,
714,
338,
10329,
3466,
8,
79,
18,
14,
344,
7,
2576,
1257,
9908,
1257,
1082,
2905,
297,
959,
9,
199,
3,
312,
331,
19,
275,
9240,
714,
338,
10329,
3466,
8,
79,
19,
14,
344,
7,
2576,
1257,
9908,
1257,
1082,
2905,
297,
413,
9,
199,
3,
312,
331,
20,
275,
9240,
714,
338,
10329,
3466,
8,
79,
20,
14,
344,
7,
2576,
1257,
9908,
1257,
1082,
2835,
297,
499,
9,
199,
3,
312,
331,
21,
275,
9240,
714,
338,
10329,
3466,
8,
79,
21,
14,
344,
7,
2576,
1257,
16981,
969,
2576,
383,
297,
959,
9,
199,
3,
312,
331,
22,
275,
9240,
714,
338,
10329,
3466,
8,
79,
22,
14,
344,
7,
28690,
966,
1355,
1276,
1257,
3172,
297,
841,
9,
199,
3,
312,
331,
23,
275,
9240,
714,
338,
10329,
3466,
8,
79,
23,
14,
344,
7,
28690,
966,
1355,
7491,
16447,
297,
959,
9,
199,
3,
312,
331,
24,
275,
9240,
714,
338,
10329,
3466,
8,
79,
24,
14,
344,
7,
28690,
966,
13145,
1349,
19861,
297,
650,
9,
199,
3,
312,
331,
25,
275,
9240,
714,
338,
10329,
3466,
8,
79,
25,
14,
344,
7,
28690,
966,
13145,
1349,
19861,
297,
959,
9,
199,
3,
312,
331,
709,
275,
9240,
714,
338,
10329,
3466,
8,
79,
709,
14,
344,
7,
28690,
966,
13145,
1349,
19861,
297,
4114,
9,
421,
199,
3271,
63,
513,
275,
942,
199,
3,
4236,
7735,
199,
3271,
63,
513,
14,
740,
8,
79,
17,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
18,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
19,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
20,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
21,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
22,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
23,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
24,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
25,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
709,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
845,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
713,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
969,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1079,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1046,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
975,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1196,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1085,
9,
199,
3,
9240,
714,
338,
10329,
3466,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
17,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
18,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
19,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
20,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
21,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
22,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
23,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
24,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
25,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
709,
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
] |
[
4738,
7283,
666,
1041,
199,
199,
504,
3877,
14,
14387,
14,
992,
492,
9240,
199,
3,
687,
3877,
14,
14387,
14,
992,
492,
9240,
714,
338,
10329,
3466,
421,
199,
3,
4236,
7735,
199,
79,
17,
275,
9240,
360,
7504,
17,
358,
199,
79,
18,
275,
9240,
360,
7504,
18,
358,
199,
79,
19,
275,
9240,
360,
7504,
19,
358,
199,
79,
20,
275,
9240,
360,
7504,
20,
358,
199,
79,
21,
275,
9240,
360,
7504,
21,
358,
199,
79,
22,
275,
9240,
360,
7504,
22,
358,
199,
79,
23,
275,
9240,
360,
7504,
23,
358,
199,
79,
24,
275,
9240,
360,
7504,
24,
358,
199,
79,
25,
275,
9240,
360,
7504,
25,
358,
199,
79,
709,
275,
9240,
360,
7504,
709,
358,
199,
79,
845,
275,
9240,
360,
7504,
17,
358,
199,
79,
713,
275,
9240,
360,
7504,
17,
358,
199,
79,
969,
275,
9240,
360,
7504,
17,
358,
199,
79,
1079,
275,
9240,
360,
7504,
18,
358,
199,
79,
1046,
275,
9240,
360,
7504,
23,
358,
199,
79,
975,
275,
9240,
360,
7504,
23,
358,
199,
79,
1196,
275,
9240,
360,
7504,
23,
358,
199,
79,
1085,
275,
9240,
360,
7504,
19,
358,
421,
199,
3,
312,
331,
17,
275,
9240,
714,
338,
10329,
3466,
8,
79,
17,
14,
344,
7,
28690,
966,
1355,
7491,
16447,
297,
650,
9,
199,
3,
312,
331,
18,
275,
9240,
714,
338,
10329,
3466,
8,
79,
18,
14,
344,
7,
2576,
1257,
9908,
1257,
1082,
2905,
297,
959,
9,
199,
3,
312,
331,
19,
275,
9240,
714,
338,
10329,
3466,
8,
79,
19,
14,
344,
7,
2576,
1257,
9908,
1257,
1082,
2905,
297,
413,
9,
199,
3,
312,
331,
20,
275,
9240,
714,
338,
10329,
3466,
8,
79,
20,
14,
344,
7,
2576,
1257,
9908,
1257,
1082,
2835,
297,
499,
9,
199,
3,
312,
331,
21,
275,
9240,
714,
338,
10329,
3466,
8,
79,
21,
14,
344,
7,
2576,
1257,
16981,
969,
2576,
383,
297,
959,
9,
199,
3,
312,
331,
22,
275,
9240,
714,
338,
10329,
3466,
8,
79,
22,
14,
344,
7,
28690,
966,
1355,
1276,
1257,
3172,
297,
841,
9,
199,
3,
312,
331,
23,
275,
9240,
714,
338,
10329,
3466,
8,
79,
23,
14,
344,
7,
28690,
966,
1355,
7491,
16447,
297,
959,
9,
199,
3,
312,
331,
24,
275,
9240,
714,
338,
10329,
3466,
8,
79,
24,
14,
344,
7,
28690,
966,
13145,
1349,
19861,
297,
650,
9,
199,
3,
312,
331,
25,
275,
9240,
714,
338,
10329,
3466,
8,
79,
25,
14,
344,
7,
28690,
966,
13145,
1349,
19861,
297,
959,
9,
199,
3,
312,
331,
709,
275,
9240,
714,
338,
10329,
3466,
8,
79,
709,
14,
344,
7,
28690,
966,
13145,
1349,
19861,
297,
4114,
9,
421,
199,
3271,
63,
513,
275,
942,
199,
3,
4236,
7735,
199,
3271,
63,
513,
14,
740,
8,
79,
17,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
18,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
19,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
20,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
21,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
22,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
23,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
24,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
25,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
709,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
845,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
713,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
969,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1079,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1046,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
975,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1196,
9,
199,
3271,
63,
513,
14,
740,
8,
79,
1085,
9,
199,
3,
9240,
714,
338,
10329,
3466,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
17,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
18,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
19,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
20,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
21,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
22,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
23,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
24,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
25,
9,
199,
3,
2690,
63,
513,
14,
740,
8,
79,
331,
709,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Captain-Coder/tribler
|
Tribler/Test/Core/Libtorrent/test_libtorrent_mgr.py
|
1
|
19035
|
import binascii
import os
import shutil
import tempfile
from libtorrent import bencode
from twisted.internet.task import deferLater
from Tribler.Test.tools import trial_timeout
from twisted.internet.defer import inlineCallbacks, Deferred
from twisted.internet import reactor
from Tribler.Core.CacheDB.Notifier import Notifier
from Tribler.Core.Libtorrent.LibtorrentDownloadImpl import LibtorrentDownloadImpl
from Tribler.Core.Libtorrent.LibtorrentMgr import LibtorrentMgr
from Tribler.Core.exceptions import TorrentFileException
from Tribler.Test.Core.base_test import MockObject
from Tribler.Test.test_as_server import AbstractServer
class TestLibtorrentMgr(AbstractServer):
FILE_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
LIBTORRENT_FILES_DIR = os.path.abspath(os.path.join(FILE_DIR, u"../data/libtorrent/"))
@inlineCallbacks
def setUp(self):
yield super(TestLibtorrentMgr, self).setUp()
self.tribler_session = MockObject()
self.tribler_session.lm = MockObject()
self.tribler_session.notifier = Notifier()
self.tribler_session.state_dir = self.session_base_dir
self.tribler_session.trustchain_keypair = MockObject()
self.tribler_session.trustchain_keypair.key_to_hash = lambda: 'a' * 20
self.tribler_session.notify_shutdown_state = lambda _: None
self.tribler_session.config = MockObject()
self.tribler_session.config.get_libtorrent_utp = lambda: True
self.tribler_session.config.get_libtorrent_proxy_settings = lambda: (0, None, None)
self.tribler_session.config.get_anon_proxy_settings = lambda: (2, ('127.0.0.1', [1338]), None)
self.tribler_session.config.get_libtorrent_port = lambda: 1337
self.tribler_session.config.get_anon_listen_port = lambda: 1338
self.tribler_session.config.get_state_dir = lambda: self.session_base_dir
self.tribler_session.config.set_listen_port_runtime = lambda: None
self.tribler_session.config.get_libtorrent_max_upload_rate = lambda: 100
self.tribler_session.config.get_libtorrent_max_download_rate = lambda: 120
self.tribler_session.config.get_libtorrent_dht_enabled = lambda: False
self.tribler_session.config.set_libtorrent_port_runtime = lambda _: None
self.ltmgr = LibtorrentMgr(self.tribler_session)
@inlineCallbacks
def tearDown(self):
self.ltmgr.shutdown(timeout=0)
self.assertTrue(os.path.exists(os.path.join(self.session_base_dir, 'lt.state')))
yield super(TestLibtorrentMgr, self).tearDown()
def test_get_session_zero_hops(self):
self.ltmgr.initialize()
ltsession = self.ltmgr.get_session(0)
self.assertTrue(ltsession)
def test_get_session_one_hop(self):
self.ltmgr.initialize()
ltsession = self.ltmgr.get_session(1)
self.assertTrue(ltsession)
def test_get_session_zero_hops_corrupt_lt_state(self):
file = open(os.path.join(self.session_base_dir, 'lt.state'), "w")
file.write("Lorem ipsum")
file.close()
self.ltmgr.initialize()
ltsession = self.ltmgr.get_session(0)
self.assertTrue(ltsession)
def test_get_session_zero_hops_working_lt_state(self):
shutil.copy(os.path.join(self.LIBTORRENT_FILES_DIR, 'lt.state'),
os.path.join(self.session_base_dir, 'lt.state'))
self.ltmgr.initialize()
ltsession = self.ltmgr.get_session(0)
self.assertTrue(ltsession)
def test_get_metainfo_not_ready(self):
"""
Testing the metainfo fetching method when the DHT is not ready
"""
self.ltmgr.initialize()
self.assertFalse(self.ltmgr.get_metainfo("a" * 20, None))
@trial_timeout(20)
def test_get_metainfo(self):
"""
Testing the metainfo fetching method
"""
test_deferred = Deferred()
def metainfo_cb(metainfo):
self.assertEqual(metainfo, {'info': {'pieces': ['a']}, 'leechers': 0,
'nodes': [], 'seeders': 0, 'initial peers': []})
test_deferred.callback(None)
infohash = "a" * 20
self.ltmgr.initialize()
torrent_info = MockObject()
torrent_info.metadata = lambda: bencode({'pieces': ['a']})
torrent_info.trackers = lambda: []
fake_handle = MockObject()
fake_handle.is_valid = lambda: True
fake_handle.has_metadata = lambda: True
fake_handle.get_peer_info = lambda: []
fake_handle.torrent_file = lambda: torrent_info
self.ltmgr.ltsession_metainfo.add_torrent = lambda *_: fake_handle
self.ltmgr.ltsession_metainfo.remove_torrent = lambda *_: None
fake_alert = type('lt.metadata_received_alert', (object,), dict(handle=fake_handle))
self.ltmgr.ltsession_metainfo.pop_alerts = lambda: [fake_alert]
self.ltmgr.is_dht_ready = lambda: True
self.ltmgr.get_metainfo(infohash.decode('hex'), metainfo_cb)
return test_deferred
@trial_timeout(20)
def test_get_metainfo_cache(self):
"""
Testing metainfo caching
"""
test_deferred = Deferred()
def metainfo_cb(metainfo):
self.assertEqual(metainfo, "test")
test_deferred.callback(None)
self.ltmgr.initialize()
self.ltmgr.is_dht_ready = lambda: True
self.ltmgr.metainfo_cache[("a" * 20).encode('hex')] = {'meta_info': 'test'}
self.ltmgr.get_metainfo("a" * 20, metainfo_cb)
return test_deferred
@trial_timeout(20)
def test_got_metainfo(self):
"""
Testing whether the callback is correctly invoked when we received metainfo
"""
test_deferred = Deferred()
self.ltmgr.initialize()
def metainfo_cb(metainfo):
self.assertDictEqual(metainfo, {'info': {'pieces': ['a']}, 'leechers': 0,
'nodes': [], 'seeders': 0, 'initial peers': []})
test_deferred.callback(None)
fake_handle = MockObject()
torrent_info = MockObject()
torrent_info.metadata = lambda: bencode({'pieces': ['a']})
torrent_info.trackers = lambda: []
fake_handle.get_peer_info = lambda: []
fake_handle.torrent_file = lambda: torrent_info
self.ltmgr.ltsession_metainfo.remove_torrent = lambda *_: None
self.ltmgr.metainfo_requests['a' * 20] = {
'handle': fake_handle,
'timeout_callbacks': [],
'callbacks': [metainfo_cb],
'notify': False
}
self.ltmgr.got_metainfo("a" * 20)
return test_deferred
@trial_timeout(20)
def test_got_metainfo_timeout(self):
"""
Testing whether the callback is correctly invoked when we received metainfo after timeout
"""
test_deferred = Deferred()
def metainfo_timeout_cb(metainfo):
self.assertEqual(metainfo, 'a' * 20)
test_deferred.callback(None)
fake_handle = MockObject()
self.ltmgr.initialize()
self.ltmgr.metainfo_requests[('a' * 20).encode('hex')] = {'handle': fake_handle,
'timeout_callbacks': [metainfo_timeout_cb],
'callbacks': [],
'notify': True}
self.ltmgr.ltsession_metainfo.remove_torrent = lambda _dummy1, _dummy2: None
self.ltmgr.got_metainfo(('a' * 20).encode('hex'), timeout=True)
return test_deferred
@trial_timeout(20)
def test_get_metainfo_with_already_added_torrent(self):
"""
Testing metainfo fetching for a torrent which is already in session.
got_metainfo() should be called with timeout=False.
"""
magnet_link = "magnet:?xt=urn:btih:f72636475a375653083e49d501601675ce3e6619&dn=ubuntu-16.04.3-server-i386.iso"
test_deferred = Deferred()
def fake_got_metainfo(_, timeout):
self.assertFalse(timeout, "Timeout should not be True")
test_deferred.callback(None)
mock_handle = MockObject()
mock_handle.info_hash = lambda: 'a' * 20
mock_handle.is_valid = lambda: True
mock_handle.has_metadata = lambda: True
mock_ltsession = MockObject()
mock_ltsession.add_torrent = lambda _: mock_handle
mock_ltsession.find_torrent = lambda _: mock_handle
mock_ltsession.get_torrents = lambda: []
mock_ltsession.start_upnp = lambda: None
mock_ltsession.stop_upnp = lambda: None
mock_ltsession.save_state = lambda: None
self.ltmgr.ltsession_metainfo = mock_ltsession
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
self.ltmgr.is_dht_ready = lambda: True
self.ltmgr.got_metainfo = fake_got_metainfo
self.ltmgr.get_metainfo(magnet_link, lambda _: None)
return test_deferred
@trial_timeout(20)
def test_add_torrent(self):
"""
Testing the addition of a torrent to the libtorrent manager
"""
test_deferred = Deferred()
mock_handle = MockObject()
mock_handle.info_hash = lambda: 'a' * 20
mock_handle.is_valid = lambda: False
mock_error = MockObject()
mock_error.value = lambda: None
mock_alert = type('add_torrent_alert', (object,), dict(handle=mock_handle, error=mock_error))()
mock_ltsession = MockObject()
mock_ltsession.async_add_torrent = lambda _: reactor.callLater(0.1, self.ltmgr.process_alert, mock_alert)
mock_ltsession.find_torrent = lambda _: mock_handle
mock_ltsession.get_torrents = lambda: []
mock_ltsession.stop_upnp = lambda: None
mock_ltsession.save_state = lambda: None
self.ltmgr.get_session = lambda *_: mock_ltsession
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
infohash = MockObject()
infohash.info_hash = lambda: 'a' * 20
mock_download = MockObject()
mock_download.deferred_added = Deferred()
def cb_torrent_added(handle):
self.assertEqual(handle, mock_handle)
test_deferred.callback(None)
self.ltmgr.add_torrent(mock_download, {'ti': infohash}).addCallback(cb_torrent_added)
return test_deferred
@trial_timeout(20)
def test_add_torrent_desync(self):
"""
Testing the addition of a torrent to the libtorrent manager, if it already exists in the session.
"""
mock_handle = MockObject()
mock_handle.info_hash = lambda: 'a' * 20
mock_handle.is_valid = lambda: True
mock_alert = type('add_torrent_alert', (object,), dict(handle=mock_handle))
mock_ltsession = MockObject()
mock_ltsession.async_add_torrent = lambda _: self.ltmgr.process_alert(mock_alert)
mock_ltsession.find_torrent = lambda _: mock_handle
mock_ltsession.get_torrents = lambda: [mock_handle]
mock_ltsession.stop_upnp = lambda: None
mock_ltsession.save_state = lambda: None
self.ltmgr.get_session = lambda *_: mock_ltsession
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
infohash = MockObject()
infohash.info_hash = lambda: 'a' * 20
mock_download = MockObject()
mock_download.deferred_added = Deferred()
return self.ltmgr.add_torrent(mock_download, {'ti': infohash}).addCallback(
lambda handle: self.assertEqual(handle, mock_handle)
)
def test_remove_invalid_torrent(self):
"""
Tests a successful removal status of torrents without a handle
"""
self.ltmgr.initialize()
mock_dl = MockObject()
mock_dl.handle = None
self.assertTrue(self.ltmgr.remove_torrent(mock_dl).called)
def test_remove_invalid_handle_torrent(self):
"""
Tests a successful removal status of torrents with an invalid handle
"""
self.ltmgr.initialize()
mock_handle = MockObject()
mock_handle.is_valid = lambda: False
mock_dl = MockObject()
mock_dl.handle = mock_handle
self.assertTrue(self.ltmgr.remove_torrent(mock_dl).called)
def test_remove_unregistered_torrent(self):
"""
Tests a successful removal status of torrents which aren't known
"""
self.ltmgr.initialize()
mock_handle = MockObject()
mock_handle.is_valid = lambda: False
alert = type('torrent_removed_alert', (object, ), dict(handle=mock_handle, info_hash='0'*20))
self.ltmgr.process_alert(alert())
self.assertNotIn('0'*20, self.ltmgr.torrents)
def test_start_download_corrupt(self):
"""
Testing whether starting the download of a corrupt torrent file raises an exception
"""
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
corrupt_file = os.path.join(self.LIBTORRENT_FILES_DIR, 'corrupt_torrent.torrent')
self.assertRaises(TorrentFileException, self.ltmgr.start_download, torrentfilename=corrupt_file)
def test_start_download_duplicate(self):
"""
Test the starting of a download when there are no new trackers
"""
mock_tdef = MockObject()
mock_tdef.get_infohash = lambda: 'a' * 20
mock_tdef.get_trackers_as_single_tuple = lambda: tuple()
mock_download = MockObject()
mock_download.get_def = lambda: mock_tdef
mock_download.get_credit_mining = lambda: False
self.tribler_session.get_download = lambda _: mock_download
self.tribler_session.start_download_from_tdef = lambda tdef, _: MockObject()
self.ltmgr.tribler_session = self.tribler_session
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
self.ltmgr.start_download(infohash='a' * 20, tdef=mock_tdef)
def test_set_proxy_settings(self):
"""
Test setting the proxy settings
"""
def on_proxy_set(settings):
self.assertTrue(settings)
self.assertEqual(settings.hostname, 'a')
self.assertEqual(settings.port, 1234)
self.assertEqual(settings.username, 'abc')
self.assertEqual(settings.password, 'def')
def on_set_settings(settings):
self.assertTrue(settings)
self.assertEqual(settings['proxy_hostname'], 'a')
self.assertEqual(settings['proxy_port'], 1234)
self.assertEqual(settings['proxy_username'], 'abc')
self.assertEqual(settings['proxy_password'], 'def')
self.assertEqual(settings['proxy_peer_connections'], True)
self.assertEqual(settings['proxy_hostnames'], True)
mock_lt_session = MockObject()
mock_lt_session.get_settings = lambda: {}
mock_lt_session.set_settings = on_set_settings
mock_lt_session.set_proxy = on_proxy_set # Libtorrent < 1.1.0 uses set_proxy to set proxy settings
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
self.ltmgr.set_proxy_settings(mock_lt_session, 0, ('a', "1234"), ('abc', 'def'))
def test_save_resume_preresolved_magnet(self):
"""
Test whether a magnet link correctly writes save-resume data before it is resolved.
This can happen when a magnet link is added when the user does not have internet.
"""
self.ltmgr.initialize()
self.ltmgr.trsession = self.tribler_session
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
mock_tdef = MockObject()
mock_tdef.get_infohash = lambda: 'a' * 20
self.tribler_session.get_download = lambda _: None
self.tribler_session.get_downloads_pstate_dir = lambda: self.ltmgr.metadata_tmpdir
mock_lm = MockObject()
mock_lm.ltmgr = self.ltmgr
mock_lm.tunnel_community = None
self.tribler_session.lm = mock_lm
def dl_from_tdef(tdef, _):
dl = LibtorrentDownloadImpl(self.tribler_session, tdef)
dl.setup()
dl.cancel_all_pending_tasks()
return dl
self.tribler_session.start_download_from_tdef = dl_from_tdef
download = self.ltmgr.start_download_from_magnet("magnet:?xt=urn:btih:" + ('1'*40))
basename = binascii.hexlify(download.get_def().get_infohash()) + '.state'
filename = os.path.join(download.session.get_downloads_pstate_dir(), basename)
self.assertTrue(os.path.isfile(filename))
@trial_timeout(5)
def test_callback_on_alert(self):
"""
Test whether the alert callback is called when a libtorrent alert is posted
"""
self.ltmgr.default_alert_mask = 0xffffffff
test_deferred = Deferred()
def callback(*args):
self.ltmgr.alert_callback = None
test_deferred.callback(None)
callback.called = False
self.ltmgr.alert_callback = callback
self.ltmgr.initialize()
self.ltmgr._task_process_alerts()
return test_deferred
def test_payout_on_disconnect(self):
"""
Test whether a payout is initialized when a peer disconnects
"""
class peer_disconnected_alert(object):
def __init__(self):
self.pid = MockObject()
self.pid.to_string = lambda: 'a' * 20
def mocked_do_payout(mid):
self.assertEqual(mid, 'a' * 20)
mocked_do_payout.called = True
mocked_do_payout.called = False
disconnect_alert = peer_disconnected_alert()
self.ltmgr.tribler_session.lm.payout_manager = MockObject()
self.ltmgr.tribler_session.lm.payout_manager.do_payout = mocked_do_payout
self.ltmgr.initialize()
self.ltmgr.get_session(0).pop_alerts = lambda: [disconnect_alert]
self.ltmgr._task_process_alerts()
self.assertTrue(mocked_do_payout.called)
def test_post_session_stats(self):
"""
Test whether post_session_stats actually updates the state of libtorrent readiness for clean shutdown.
"""
def check_if_session_shutdown_is_ready():
self.ltmgr._task_process_alerts()
self.assertTrue(self.ltmgr.lt_session_shutdown_ready[0])
self.ltmgr.default_alert_mask = 0xffffffff
self.ltmgr.initialize()
# Zero hop session should be initialized
self.assertFalse(self.ltmgr.lt_session_shutdown_ready[0])
# Check for status with session stats alert
self.ltmgr.post_session_stats(hops=0)
# Wait sometime to get the alert and check the status
return deferLater(reactor, 0.01, check_if_session_shutdown_is_ready)
|
lgpl-3.0
|
[
646,
14755,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
199,
504,
1973,
14101,
492,
330,
2143,
199,
199,
504,
7390,
14,
4901,
14,
1765,
492,
10133,
22028,
199,
199,
504,
12480,
830,
82,
14,
774,
14,
2537,
492,
16324,
63,
2593,
199,
504,
7390,
14,
4901,
14,
11610,
492,
8308,
17958,
12,
17448,
199,
504,
7390,
14,
4901,
492,
9655,
199,
199,
504,
12480,
830,
82,
14,
5402,
14,
4437,
2846,
14,
26884,
492,
3091,
11612,
199,
504,
12480,
830,
82,
14,
5402,
14,
4728,
14101,
14,
4728,
14101,
11950,
4748,
492,
8003,
14101,
11950,
4748,
199,
504,
12480,
830,
82,
14,
5402,
14,
4728,
14101,
14,
4728,
14101,
20752,
492,
8003,
14101,
20752,
199,
504,
12480,
830,
82,
14,
5402,
14,
3924,
492,
29659,
640,
1173,
1726,
199,
504,
12480,
830,
82,
14,
774,
14,
5402,
14,
1095,
63,
396,
492,
4420,
1692,
199,
504,
12480,
830,
82,
14,
774,
14,
396,
63,
305,
63,
1000,
492,
11836,
3120,
421,
199,
533,
1379,
4728,
14101,
20752,
8,
8458,
3120,
304,
339,
13024,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
29658,
272,
25764,
52,
726,
11574,
63,
9472,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3817,
63,
3022,
12,
399,
2,
5093,
576,
15,
773,
14101,
15,
2237,
339,
768,
24813,
272,
347,
3613,
8,
277,
304,
267,
1995,
1613,
8,
774,
4728,
14101,
20752,
12,
291,
680,
5996,
342,
398,
291,
14,
599,
830,
82,
63,
1730,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
14344,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
18031,
275,
3091,
11612,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
929,
63,
694,
275,
291,
14,
1730,
63,
1095,
63,
694,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
15756,
4429,
63,
19263,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
15756,
4429,
63,
19263,
14,
498,
63,
475,
63,
2227,
275,
2400,
26,
283,
65,
7,
627,
3388,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
6814,
63,
8831,
63,
929,
275,
2400,
24700,
488,
398,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
337,
80,
275,
2400,
26,
715,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
3280,
63,
1751,
275,
2400,
26,
334,
16,
12,
488,
12,
488,
9,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
21009,
63,
3280,
63,
1751,
275,
2400,
26,
334,
18,
12,
661,
4195,
14,
16,
14,
16,
14,
17,
297,
359,
969,
1703,
2522,
488,
9,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
719,
275,
2400,
26,
413,
11062,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
21009,
63,
5859,
63,
719,
275,
2400,
26,
413,
13744,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
929,
63,
694,
275,
2400,
26,
291,
14,
1730,
63,
1095,
63,
694,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
409,
63,
5859,
63,
719,
63,
7726,
275,
2400,
26,
488,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
988,
63,
5064,
63,
1866,
275,
2400,
26,
2948,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
988,
63,
4249,
63,
1866,
275,
2400,
26,
13960,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
68,
517,
63,
3827,
275,
2400,
26,
756,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
409,
63,
773,
14101,
63,
719,
63,
7726,
275,
2400,
24700,
488,
398,
291,
14,
4116,
7755,
275,
8003,
14101,
20752,
8,
277,
14,
599,
830,
82,
63,
1730,
9,
339,
768,
24813,
272,
347,
6766,
8,
277,
304,
267,
291,
14,
4116,
7755,
14,
8831,
8,
2593,
29,
16,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1730,
63,
1095,
63,
694,
12,
283,
4116,
14,
929,
7058,
267,
1995,
1613,
8,
774,
4728,
14101,
20752,
12,
291,
680,
12336,
342,
339,
347,
511,
63,
362,
63,
1730,
63,
4262,
63,
72,
1483,
8,
277,
304,
267,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
7755,
14,
362,
63,
1730,
8,
16,
9,
267,
291,
14,
1815,
8,
4116,
1730,
9,
339,
347,
511,
63,
362,
63,
1730,
63,
368,
63,
13376,
8,
277,
304,
267,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
7755,
14,
362,
63,
1730,
8,
17,
9,
267,
291,
14,
1815,
8,
4116,
1730,
9,
339,
347,
511,
63,
362,
63,
1730,
63,
4262,
63,
72,
1483,
63,
989,
6987,
63,
4116,
63,
929,
8,
277,
304,
267,
570,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1730,
63,
1095,
63,
694,
12,
283,
4116,
14,
929,
659,
298,
87,
531,
267,
570,
14,
952,
480,
44,
720,
77,
15017,
453,
531,
267,
570,
14,
1600,
342,
398,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
7755,
14,
362,
63,
1730,
8,
16,
9,
267,
291,
14,
1815,
8,
4116,
1730,
9,
339,
347,
511,
63,
362,
63,
1730,
63,
4262,
63,
72,
1483,
63,
9818,
63,
4116,
63,
929,
8,
277,
304,
267,
5145,
14,
1574,
8,
736,
14,
515,
14,
904,
8,
277,
14,
5617,
52,
726,
11574,
63,
9472,
63,
3022,
12,
283,
4116,
14,
929,
659,
490,
747,
14,
515,
14,
904,
8,
277,
14,
1730,
63,
1095,
63,
694,
12,
283,
4116,
14,
929,
1333,
267,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116
] |
[
14755,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
199,
504,
1973,
14101,
492,
330,
2143,
199,
199,
504,
7390,
14,
4901,
14,
1765,
492,
10133,
22028,
199,
199,
504,
12480,
830,
82,
14,
774,
14,
2537,
492,
16324,
63,
2593,
199,
504,
7390,
14,
4901,
14,
11610,
492,
8308,
17958,
12,
17448,
199,
504,
7390,
14,
4901,
492,
9655,
199,
199,
504,
12480,
830,
82,
14,
5402,
14,
4437,
2846,
14,
26884,
492,
3091,
11612,
199,
504,
12480,
830,
82,
14,
5402,
14,
4728,
14101,
14,
4728,
14101,
11950,
4748,
492,
8003,
14101,
11950,
4748,
199,
504,
12480,
830,
82,
14,
5402,
14,
4728,
14101,
14,
4728,
14101,
20752,
492,
8003,
14101,
20752,
199,
504,
12480,
830,
82,
14,
5402,
14,
3924,
492,
29659,
640,
1173,
1726,
199,
504,
12480,
830,
82,
14,
774,
14,
5402,
14,
1095,
63,
396,
492,
4420,
1692,
199,
504,
12480,
830,
82,
14,
774,
14,
396,
63,
305,
63,
1000,
492,
11836,
3120,
421,
199,
533,
1379,
4728,
14101,
20752,
8,
8458,
3120,
304,
339,
13024,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
11091,
3460,
493,
29658,
272,
25764,
52,
726,
11574,
63,
9472,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3817,
63,
3022,
12,
399,
2,
5093,
576,
15,
773,
14101,
15,
2237,
339,
768,
24813,
272,
347,
3613,
8,
277,
304,
267,
1995,
1613,
8,
774,
4728,
14101,
20752,
12,
291,
680,
5996,
342,
398,
291,
14,
599,
830,
82,
63,
1730,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
14344,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
18031,
275,
3091,
11612,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
929,
63,
694,
275,
291,
14,
1730,
63,
1095,
63,
694,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
15756,
4429,
63,
19263,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
15756,
4429,
63,
19263,
14,
498,
63,
475,
63,
2227,
275,
2400,
26,
283,
65,
7,
627,
3388,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
6814,
63,
8831,
63,
929,
275,
2400,
24700,
488,
398,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
275,
4420,
1692,
342,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
337,
80,
275,
2400,
26,
715,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
3280,
63,
1751,
275,
2400,
26,
334,
16,
12,
488,
12,
488,
9,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
21009,
63,
3280,
63,
1751,
275,
2400,
26,
334,
18,
12,
661,
4195,
14,
16,
14,
16,
14,
17,
297,
359,
969,
1703,
2522,
488,
9,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
719,
275,
2400,
26,
413,
11062,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
21009,
63,
5859,
63,
719,
275,
2400,
26,
413,
13744,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
929,
63,
694,
275,
2400,
26,
291,
14,
1730,
63,
1095,
63,
694,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
409,
63,
5859,
63,
719,
63,
7726,
275,
2400,
26,
488,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
988,
63,
5064,
63,
1866,
275,
2400,
26,
2948,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
988,
63,
4249,
63,
1866,
275,
2400,
26,
13960,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
362,
63,
773,
14101,
63,
68,
517,
63,
3827,
275,
2400,
26,
756,
267,
291,
14,
599,
830,
82,
63,
1730,
14,
888,
14,
409,
63,
773,
14101,
63,
719,
63,
7726,
275,
2400,
24700,
488,
398,
291,
14,
4116,
7755,
275,
8003,
14101,
20752,
8,
277,
14,
599,
830,
82,
63,
1730,
9,
339,
768,
24813,
272,
347,
6766,
8,
277,
304,
267,
291,
14,
4116,
7755,
14,
8831,
8,
2593,
29,
16,
9,
267,
291,
14,
1815,
8,
736,
14,
515,
14,
2444,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1730,
63,
1095,
63,
694,
12,
283,
4116,
14,
929,
7058,
267,
1995,
1613,
8,
774,
4728,
14101,
20752,
12,
291,
680,
12336,
342,
339,
347,
511,
63,
362,
63,
1730,
63,
4262,
63,
72,
1483,
8,
277,
304,
267,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
7755,
14,
362,
63,
1730,
8,
16,
9,
267,
291,
14,
1815,
8,
4116,
1730,
9,
339,
347,
511,
63,
362,
63,
1730,
63,
368,
63,
13376,
8,
277,
304,
267,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
7755,
14,
362,
63,
1730,
8,
17,
9,
267,
291,
14,
1815,
8,
4116,
1730,
9,
339,
347,
511,
63,
362,
63,
1730,
63,
4262,
63,
72,
1483,
63,
989,
6987,
63,
4116,
63,
929,
8,
277,
304,
267,
570,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
277,
14,
1730,
63,
1095,
63,
694,
12,
283,
4116,
14,
929,
659,
298,
87,
531,
267,
570,
14,
952,
480,
44,
720,
77,
15017,
453,
531,
267,
570,
14,
1600,
342,
398,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
7755,
14,
362,
63,
1730,
8,
16,
9,
267,
291,
14,
1815,
8,
4116,
1730,
9,
339,
347,
511,
63,
362,
63,
1730,
63,
4262,
63,
72,
1483,
63,
9818,
63,
4116,
63,
929,
8,
277,
304,
267,
5145,
14,
1574,
8,
736,
14,
515,
14,
904,
8,
277,
14,
5617,
52,
726,
11574,
63,
9472,
63,
3022,
12,
283,
4116,
14,
929,
659,
490,
747,
14,
515,
14,
904,
8,
277,
14,
1730,
63,
1095,
63,
694,
12,
283,
4116,
14,
929,
1333,
267,
291,
14,
4116,
7755,
14,
8489,
342,
267,
22146,
1730,
275,
291,
14,
4116,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
vFense/vFenseAgent-nix
|
agent/deps/rpm/Python-2.7.5/lib/python2.7/idlelib/MultiCall.py
|
43
|
17483
|
"""
MultiCall - a class which inherits its methods from a Tkinter widget (Text, for
example), but enables multiple calls of functions per virtual event - all
matching events will be called, not only the most specific one. This is done
by wrapping the event functions - event_add, event_delete and event_info.
MultiCall recognizes only a subset of legal event sequences. Sequences which
are not recognized are treated by the original Tk handling mechanism. A
more-specific event will be called before a less-specific event.
The recognized sequences are complete one-event sequences (no emacs-style
Ctrl-X Ctrl-C, no shortcuts like <3>), for all types of events.
Key/Button Press/Release events can have modifiers.
The recognized modifiers are Shift, Control, Option and Command for Mac, and
Control, Alt, Shift, Meta/M for other platforms.
For all events which were handled by MultiCall, a new member is added to the
event instance passed to the binded functions - mc_type. This is one of the
event type constants defined in this module (such as MC_KEYPRESS).
For Key/Button events (which are handled by MultiCall and may receive
modifiers), another member is added - mc_state. This member gives the state
of the recognized modifiers, as a combination of the modifier constants
also defined in this module (for example, MC_SHIFT).
Using these members is absolutely portable.
The order by which events are called is defined by these rules:
1. A more-specific event will be called before a less-specific event.
2. A recently-binded event will be called before a previously-binded event,
unless this conflicts with the first rule.
Each function will be called at most once for each event.
"""
import sys
import string
import re
import Tkinter
from idlelib import macosxSupport
# the event type constants, which define the meaning of mc_type
MC_KEYPRESS=0; MC_KEYRELEASE=1; MC_BUTTONPRESS=2; MC_BUTTONRELEASE=3;
MC_ACTIVATE=4; MC_CIRCULATE=5; MC_COLORMAP=6; MC_CONFIGURE=7;
MC_DEACTIVATE=8; MC_DESTROY=9; MC_ENTER=10; MC_EXPOSE=11; MC_FOCUSIN=12;
MC_FOCUSOUT=13; MC_GRAVITY=14; MC_LEAVE=15; MC_MAP=16; MC_MOTION=17;
MC_MOUSEWHEEL=18; MC_PROPERTY=19; MC_REPARENT=20; MC_UNMAP=21; MC_VISIBILITY=22;
# the modifier state constants, which define the meaning of mc_state
MC_SHIFT = 1<<0; MC_CONTROL = 1<<2; MC_ALT = 1<<3; MC_META = 1<<5
MC_OPTION = 1<<6; MC_COMMAND = 1<<7
# define the list of modifiers, to be used in complex event types.
if macosxSupport.runningAsOSXApp():
_modifiers = (("Shift",), ("Control",), ("Option",), ("Command",))
_modifier_masks = (MC_SHIFT, MC_CONTROL, MC_OPTION, MC_COMMAND)
else:
_modifiers = (("Control",), ("Alt",), ("Shift",), ("Meta", "M"))
_modifier_masks = (MC_CONTROL, MC_ALT, MC_SHIFT, MC_META)
# a dictionary to map a modifier name into its number
_modifier_names = dict([(name, number)
for number in range(len(_modifiers))
for name in _modifiers[number]])
# A binder is a class which binds functions to one type of event. It has two
# methods: bind and unbind, which get a function and a parsed sequence, as
# returned by _parse_sequence(). There are two types of binders:
# _SimpleBinder handles event types with no modifiers and no detail.
# No Python functions are called when no events are binded.
# _ComplexBinder handles event types with modifiers and a detail.
# A Python function is called each time an event is generated.
class _SimpleBinder:
def __init__(self, type, widget, widgetinst):
self.type = type
self.sequence = '<'+_types[type][0]+'>'
self.widget = widget
self.widgetinst = widgetinst
self.bindedfuncs = []
self.handlerid = None
def bind(self, triplet, func):
if not self.handlerid:
def handler(event, l = self.bindedfuncs, mc_type = self.type):
event.mc_type = mc_type
wascalled = {}
for i in range(len(l)-1, -1, -1):
func = l[i]
if func not in wascalled:
wascalled[func] = True
r = func(event)
if r:
return r
self.handlerid = self.widget.bind(self.widgetinst,
self.sequence, handler)
self.bindedfuncs.append(func)
def unbind(self, triplet, func):
self.bindedfuncs.remove(func)
if not self.bindedfuncs:
self.widget.unbind(self.widgetinst, self.sequence, self.handlerid)
self.handlerid = None
def __del__(self):
if self.handlerid:
self.widget.unbind(self.widgetinst, self.sequence, self.handlerid)
# An int in range(1 << len(_modifiers)) represents a combination of modifiers
# (if the least significent bit is on, _modifiers[0] is on, and so on).
# _state_subsets gives for each combination of modifiers, or *state*,
# a list of the states which are a subset of it. This list is ordered by the
# number of modifiers is the state - the most specific state comes first.
_states = range(1 << len(_modifiers))
_state_names = [''.join(m[0]+'-'
for i, m in enumerate(_modifiers)
if (1 << i) & s)
for s in _states]
def expand_substates(states):
'''For each item of states return a list containing all combinations of
that item with individual bits reset, sorted by the number of set bits.
'''
def nbits(n):
"number of bits set in n base 2"
nb = 0
while n:
n, rem = divmod(n, 2)
nb += rem
return nb
statelist = []
for state in states:
substates = list(set(state & x for x in states))
substates.sort(key=nbits, reverse=True)
statelist.append(substates)
return statelist
_state_subsets = expand_substates(_states)
# _state_codes gives for each state, the portable code to be passed as mc_state
_state_codes = []
for s in _states:
r = 0
for i in range(len(_modifiers)):
if (1 << i) & s:
r |= _modifier_masks[i]
_state_codes.append(r)
class _ComplexBinder:
# This class binds many functions, and only unbinds them when it is deleted.
# self.handlerids is the list of seqs and ids of binded handler functions.
# The binded functions sit in a dictionary of lists of lists, which maps
# a detail (or None) and a state into a list of functions.
# When a new detail is discovered, handlers for all the possible states
# are binded.
def __create_handler(self, lists, mc_type, mc_state):
def handler(event, lists = lists,
mc_type = mc_type, mc_state = mc_state,
ishandlerrunning = self.ishandlerrunning,
doafterhandler = self.doafterhandler):
ishandlerrunning[:] = [True]
event.mc_type = mc_type
event.mc_state = mc_state
wascalled = {}
r = None
for l in lists:
for i in range(len(l)-1, -1, -1):
func = l[i]
if func not in wascalled:
wascalled[func] = True
r = l[i](event)
if r:
break
if r:
break
ishandlerrunning[:] = []
# Call all functions in doafterhandler and remove them from list
for f in doafterhandler:
f()
doafterhandler[:] = []
if r:
return r
return handler
def __init__(self, type, widget, widgetinst):
self.type = type
self.typename = _types[type][0]
self.widget = widget
self.widgetinst = widgetinst
self.bindedfuncs = {None: [[] for s in _states]}
self.handlerids = []
# we don't want to change the lists of functions while a handler is
# running - it will mess up the loop and anyway, we usually want the
# change to happen from the next event. So we have a list of functions
# for the handler to run after it finishes calling the binded functions.
# It calls them only once.
# ishandlerrunning is a list. An empty one means no, otherwise - yes.
# this is done so that it would be mutable.
self.ishandlerrunning = []
self.doafterhandler = []
for s in _states:
lists = [self.bindedfuncs[None][i] for i in _state_subsets[s]]
handler = self.__create_handler(lists, type, _state_codes[s])
seq = '<'+_state_names[s]+self.typename+'>'
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
seq, handler)))
def bind(self, triplet, func):
if triplet[2] not in self.bindedfuncs:
self.bindedfuncs[triplet[2]] = [[] for s in _states]
for s in _states:
lists = [ self.bindedfuncs[detail][i]
for detail in (triplet[2], None)
for i in _state_subsets[s] ]
handler = self.__create_handler(lists, self.type,
_state_codes[s])
seq = "<%s%s-%s>"% (_state_names[s], self.typename, triplet[2])
self.handlerids.append((seq, self.widget.bind(self.widgetinst,
seq, handler)))
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].append(func)
if not self.ishandlerrunning:
doit()
else:
self.doafterhandler.append(doit)
def unbind(self, triplet, func):
doit = lambda: self.bindedfuncs[triplet[2]][triplet[0]].remove(func)
if not self.ishandlerrunning:
doit()
else:
self.doafterhandler.append(doit)
def __del__(self):
for seq, id in self.handlerids:
self.widget.unbind(self.widgetinst, seq, id)
# define the list of event types to be handled by MultiEvent. the order is
# compatible with the definition of event type constants.
_types = (
("KeyPress", "Key"), ("KeyRelease",), ("ButtonPress", "Button"),
("ButtonRelease",), ("Activate",), ("Circulate",), ("Colormap",),
("Configure",), ("Deactivate",), ("Destroy",), ("Enter",), ("Expose",),
("FocusIn",), ("FocusOut",), ("Gravity",), ("Leave",), ("Map",),
("Motion",), ("MouseWheel",), ("Property",), ("Reparent",), ("Unmap",),
("Visibility",),
)
# which binder should be used for every event type?
_binder_classes = (_ComplexBinder,) * 4 + (_SimpleBinder,) * (len(_types)-4)
# A dictionary to map a type name into its number
_type_names = dict([(name, number)
for number in range(len(_types))
for name in _types[number]])
_keysym_re = re.compile(r"^\w+$")
_button_re = re.compile(r"^[1-5]$")
def _parse_sequence(sequence):
"""Get a string which should describe an event sequence. If it is
successfully parsed as one, return a tuple containing the state (as an int),
the event type (as an index of _types), and the detail - None if none, or a
string if there is one. If the parsing is unsuccessful, return None.
"""
if not sequence or sequence[0] != '<' or sequence[-1] != '>':
return None
words = string.split(sequence[1:-1], '-')
modifiers = 0
while words and words[0] in _modifier_names:
modifiers |= 1 << _modifier_names[words[0]]
del words[0]
if words and words[0] in _type_names:
type = _type_names[words[0]]
del words[0]
else:
return None
if _binder_classes[type] is _SimpleBinder:
if modifiers or words:
return None
else:
detail = None
else:
# _ComplexBinder
if type in [_type_names[s] for s in ("KeyPress", "KeyRelease")]:
type_re = _keysym_re
else:
type_re = _button_re
if not words:
detail = None
elif len(words) == 1 and type_re.match(words[0]):
detail = words[0]
else:
return None
return modifiers, type, detail
def _triplet_to_sequence(triplet):
if triplet[2]:
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'-'+ \
triplet[2]+'>'
else:
return '<'+_state_names[triplet[0]]+_types[triplet[1]][0]+'>'
_multicall_dict = {}
def MultiCallCreator(widget):
"""Return a MultiCall class which inherits its methods from the
given widget class (for example, Tkinter.Text). This is used
instead of a templating mechanism.
"""
if widget in _multicall_dict:
return _multicall_dict[widget]
class MultiCall (widget):
assert issubclass(widget, Tkinter.Misc)
def __init__(self, *args, **kwargs):
widget.__init__(self, *args, **kwargs)
# a dictionary which maps a virtual event to a tuple with:
# 0. the function binded
# 1. a list of triplets - the sequences it is binded to
self.__eventinfo = {}
self.__binders = [_binder_classes[i](i, widget, self)
for i in range(len(_types))]
def bind(self, sequence=None, func=None, add=None):
#print "bind(%s, %s, %s) called." % (sequence, func, add)
if type(sequence) is str and len(sequence) > 2 and \
sequence[:2] == "<<" and sequence[-2:] == ">>":
if sequence in self.__eventinfo:
ei = self.__eventinfo[sequence]
if ei[0] is not None:
for triplet in ei[1]:
self.__binders[triplet[1]].unbind(triplet, ei[0])
ei[0] = func
if ei[0] is not None:
for triplet in ei[1]:
self.__binders[triplet[1]].bind(triplet, func)
else:
self.__eventinfo[sequence] = [func, []]
return widget.bind(self, sequence, func, add)
def unbind(self, sequence, funcid=None):
if type(sequence) is str and len(sequence) > 2 and \
sequence[:2] == "<<" and sequence[-2:] == ">>" and \
sequence in self.__eventinfo:
func, triplets = self.__eventinfo[sequence]
if func is not None:
for triplet in triplets:
self.__binders[triplet[1]].unbind(triplet, func)
self.__eventinfo[sequence][0] = None
return widget.unbind(self, sequence, funcid)
def event_add(self, virtual, *sequences):
#print "event_add(%s,%s) was called"%(repr(virtual),repr(sequences))
if virtual not in self.__eventinfo:
self.__eventinfo[virtual] = [None, []]
func, triplets = self.__eventinfo[virtual]
for seq in sequences:
triplet = _parse_sequence(seq)
if triplet is None:
#print >> sys.stderr, "Seq. %s was added by Tkinter."%seq
widget.event_add(self, virtual, seq)
else:
if func is not None:
self.__binders[triplet[1]].bind(triplet, func)
triplets.append(triplet)
def event_delete(self, virtual, *sequences):
if virtual not in self.__eventinfo:
return
func, triplets = self.__eventinfo[virtual]
for seq in sequences:
triplet = _parse_sequence(seq)
if triplet is None:
#print >> sys.stderr, "Seq. %s was deleted by Tkinter."%seq
widget.event_delete(self, virtual, seq)
else:
if func is not None:
self.__binders[triplet[1]].unbind(triplet, func)
triplets.remove(triplet)
def event_info(self, virtual=None):
if virtual is None or virtual not in self.__eventinfo:
return widget.event_info(self, virtual)
else:
return tuple(map(_triplet_to_sequence,
self.__eventinfo[virtual][1])) + \
widget.event_info(self, virtual)
def __del__(self):
for virtual in self.__eventinfo:
func, triplets = self.__eventinfo[virtual]
if func:
for triplet in triplets:
self.__binders[triplet[1]].unbind(triplet, func)
_multicall_dict[widget] = MultiCall
return MultiCall
if __name__ == "__main__":
# Test
root = Tkinter.Tk()
text = MultiCallCreator(Tkinter.Text)(root)
text.pack()
def bindseq(seq, n=[0]):
def handler(event):
print seq
text.bind("<<handler%d>>"%n[0], handler)
text.event_add("<<handler%d>>"%n[0], seq)
n[0] += 1
bindseq("<Key>")
bindseq("<Control-Key>")
bindseq("<Alt-Key-a>")
bindseq("<Control-Key-a>")
bindseq("<Alt-Control-Key-a>")
bindseq("<Key-b>")
bindseq("<Control-Button-1>")
bindseq("<Alt-Button-1>")
bindseq("<FocusOut>")
bindseq("<Enter>")
bindseq("<Leave>")
root.mainloop()
|
lgpl-3.0
|
[
624,
199,
3947,
2176,
446,
282,
1021,
1314,
21592,
2399,
3102,
687,
282,
16826,
3938,
334,
1872,
12,
367,
199,
2694,
395,
1325,
22741,
3663,
4882,
402,
3423,
1126,
5791,
1566,
446,
1006,
199,
9467,
4474,
911,
506,
2797,
12,
440,
1454,
314,
4750,
2488,
1373,
14,
961,
365,
4224,
199,
991,
19696,
314,
1566,
3423,
446,
1566,
63,
525,
12,
1566,
63,
1807,
436,
1566,
63,
815,
14,
199,
3947,
2176,
17319,
6491,
1454,
282,
10026,
402,
18393,
1566,
8013,
14,
3240,
6227,
1314,
199,
1530,
440,
18054,
787,
10184,
701,
314,
3379,
12435,
7252,
14729,
14,
437,
199,
6878,
13,
6100,
1566,
911,
506,
2797,
2544,
282,
6656,
13,
6100,
1566,
14,
199,
199,
1918,
18054,
8013,
787,
4890,
1373,
13,
1430,
8013,
334,
889,
325,
19309,
13,
2487,
199,
9778,
13,
56,
445,
7245,
13,
35,
12,
949,
3974,
12946,
2839,
665,
19,
27359,
367,
1006,
2943,
402,
4474,
14,
199,
1197,
15,
4259,
23583,
15,
9625,
4474,
883,
1172,
9933,
14,
199,
1918,
18054,
9933,
787,
29800,
12,
8612,
12,
3207,
436,
5817,
367,
10444,
12,
436,
199,
3717,
12,
437,
4116,
12,
29800,
12,
6288,
15,
45,
367,
1163,
10677,
14,
199,
199,
1858,
1006,
4474,
1314,
4898,
8860,
701,
6879,
2176,
12,
282,
892,
3653,
365,
3483,
370,
314,
199,
1430,
1256,
3032,
370,
314,
2517,
770,
3423,
446,
16377,
63,
466,
14,
961,
365,
1373,
402,
314,
199,
1430,
730,
5262,
3247,
315,
642,
859,
334,
10180,
465,
32685,
63,
3078,
5786,
680,
199,
1858,
2606,
15,
4259,
4474,
334,
6777,
787,
8860,
701,
6879,
2176,
436,
1443,
9128,
199,
17431,
395,
4573,
3653,
365,
3483,
446,
16377,
63,
929,
14,
961,
3653,
10557,
314,
1174,
199,
1618,
314,
18054,
9933,
12,
465,
282,
14665,
402,
314,
17880,
5262,
199,
12344,
3247,
315,
642,
859,
334,
509,
2893,
12,
32685,
63,
18013,
680,
199,
10369,
3520,
7556,
365,
3679,
590,
1844,
461,
14,
199,
199,
1918,
1865,
701,
1314,
4474,
787,
2797,
365,
3247,
701,
3520,
4713,
26,
199,
17,
14,
437,
1655,
13,
6100,
1566,
911,
506,
2797,
2544,
282,
6656,
13,
6100,
1566,
14,
199,
18,
14,
437,
23568,
13,
1393,
770,
1566,
911,
506,
2797,
2544,
282,
10889,
13,
1393,
770,
1566,
12,
2043,
7444,
642,
18511,
543,
314,
1642,
2332,
14,
199,
22321,
805,
911,
506,
2797,
737,
4750,
5403,
367,
1924,
1566,
14,
199,
624,
199,
199,
646,
984,
199,
646,
1059,
199,
646,
295,
199,
646,
16826,
199,
504,
15072,
773,
492,
610,
24751,
11532,
199,
199,
3,
314,
1566,
730,
5262,
12,
1314,
5627,
314,
11150,
402,
16377,
63,
466,
199,
7608,
63,
3078,
5786,
29,
16,
27,
32685,
63,
3078,
19736,
29,
17,
27,
32685,
63,
13272,
5786,
29,
18,
27,
32685,
63,
13272,
19736,
29,
19,
27,
199,
7608,
63,
20425,
1951,
29,
20,
27,
32685,
63,
31749,
1293,
1951,
29,
21,
27,
32685,
63,
7134,
5443,
29,
22,
27,
32685,
63,
5569,
3942,
29,
23,
27,
199,
7608,
63,
1093,
20425,
1951,
29,
24,
27,
32685,
63,
19374,
1092,
57,
29,
25,
27,
32685,
63,
12533,
29,
709,
27,
32685,
63,
1438,
3064,
29,
845,
27,
32685,
63,
3230,
35,
1668,
568,
29,
713,
27,
199,
7608,
63,
3230,
35,
1668,
1877,
29,
969,
27,
32685,
63,
18583,
54,
1922,
29,
1079,
27,
32685,
63,
906,
26907,
29,
1046,
27,
32685,
63,
5443,
29,
975,
27,
32685,
63,
27235,
1075,
29,
1196,
27,
199,
7608,
63,
25571,
31588,
2901,
29,
1085,
27,
32685,
63,
25091,
29,
1167,
27,
32685,
63,
907,
20562,
29,
1165,
27,
32685,
63,
1734,
5443,
29,
2025,
27,
32685,
63,
11793,
9002,
29,
1081,
27,
199,
3,
314,
17880,
1174,
5262,
12,
1314,
5627,
314,
11150,
402,
16377,
63,
929,
199,
7608,
63,
18013,
275,
413,
8999,
16,
27,
32685,
63,
13060,
275,
413,
8999,
18,
27,
32685,
63,
19600,
275,
413,
8999,
19,
27,
32685,
63,
10614,
275,
413,
8999,
21,
199,
7608,
63,
13352,
275,
413,
8999,
22,
27,
32685,
63,
10761,
275,
413,
8999,
23,
199,
199,
3,
5627,
314,
769,
402,
9933,
12,
370,
506,
1202,
315,
6114,
1566,
2943,
14,
199,
692,
610,
24751,
11532,
14,
5720,
2822,
25160,
2640,
837,
272,
485,
17431,
275,
19110,
14379,
18529,
1689,
3717,
18529,
1689,
2602,
18529,
1689,
3110,
401,
430,
272,
485,
18156,
63,
25768,
275,
334,
7608,
63,
18013,
12,
32685,
63,
13060,
12,
32685,
63,
13352,
12,
32685,
63,
10761,
9,
199,
2836,
26,
272,
485,
17431,
275,
19110,
3717,
18529,
1689,
16985,
18529,
1689,
14379,
18529,
1689,
3396,
401,
298,
45,
2237,
272,
485,
18156,
63,
25768,
275,
334,
7608,
63,
13060,
12,
32685,
63,
19600,
12,
32685,
63,
18013,
12,
32685,
63,
10614,
9,
199,
199,
3,
282,
2600,
370,
2341,
282,
17880,
536,
1901,
2399,
1329,
199,
63,
18156,
63,
1247,
275,
1211,
7694,
354,
12,
1329,
9,
586,
367,
1329,
315,
1425,
8,
552,
1547,
17431,
430,
586,
367,
536,
315,
485,
17431,
59,
1955,
3934,
199,
199,
3,
437,
2517,
424,
365,
282,
1021,
1314,
5398,
83,
3423,
370,
1373,
730,
402,
1566,
14,
2779,
965,
2877,
199,
3,
3102,
26,
5398,
436,
625,
3409,
12,
1314,
664,
282,
805,
436,
282,
4565,
3414,
12,
465,
199,
3,
2138,
701,
485,
1122,
63,
4041,
1252,
6006,
787,
2877,
2943,
402,
2517,
7735,
26,
199,
3,
485,
3184,
34,
5755,
10022,
1566,
2943,
543,
949,
9933,
436,
949,
10093,
14,
199,
3,
3091,
2018,
3423,
787,
2797,
1380,
949,
4474,
787,
2517,
770,
14,
199,
3,
485,
6600,
8094,
5755,
10022,
1566,
2943,
543,
9933,
436,
282,
10093,
14,
199,
3,
437,
2018,
805,
365,
2797,
1924,
900,
376,
1566,
365,
4046,
14,
199,
199,
533,
485,
3184,
34,
5755,
26,
272,
347,
636,
826,
721,
277,
12,
730,
12,
3938,
12,
3938,
3615,
304,
267,
291,
14,
466,
275,
730,
267,
291,
14,
4041,
275,
24958,
6416,
1313,
59,
466,
1527,
16,
28012,
3524,
267,
291,
14,
3440,
275,
3938,
267,
291,
14,
3440,
3615,
275,
3938,
3615,
267,
291,
14,
1393,
770,
9204,
275,
942,
267,
291,
14,
2479,
1677,
275,
488,
339,
347,
5398,
8,
277,
12,
18038,
2723,
12,
2562
] |
[
199,
3947,
2176,
446,
282,
1021,
1314,
21592,
2399,
3102,
687,
282,
16826,
3938,
334,
1872,
12,
367,
199,
2694,
395,
1325,
22741,
3663,
4882,
402,
3423,
1126,
5791,
1566,
446,
1006,
199,
9467,
4474,
911,
506,
2797,
12,
440,
1454,
314,
4750,
2488,
1373,
14,
961,
365,
4224,
199,
991,
19696,
314,
1566,
3423,
446,
1566,
63,
525,
12,
1566,
63,
1807,
436,
1566,
63,
815,
14,
199,
3947,
2176,
17319,
6491,
1454,
282,
10026,
402,
18393,
1566,
8013,
14,
3240,
6227,
1314,
199,
1530,
440,
18054,
787,
10184,
701,
314,
3379,
12435,
7252,
14729,
14,
437,
199,
6878,
13,
6100,
1566,
911,
506,
2797,
2544,
282,
6656,
13,
6100,
1566,
14,
199,
199,
1918,
18054,
8013,
787,
4890,
1373,
13,
1430,
8013,
334,
889,
325,
19309,
13,
2487,
199,
9778,
13,
56,
445,
7245,
13,
35,
12,
949,
3974,
12946,
2839,
665,
19,
27359,
367,
1006,
2943,
402,
4474,
14,
199,
1197,
15,
4259,
23583,
15,
9625,
4474,
883,
1172,
9933,
14,
199,
1918,
18054,
9933,
787,
29800,
12,
8612,
12,
3207,
436,
5817,
367,
10444,
12,
436,
199,
3717,
12,
437,
4116,
12,
29800,
12,
6288,
15,
45,
367,
1163,
10677,
14,
199,
199,
1858,
1006,
4474,
1314,
4898,
8860,
701,
6879,
2176,
12,
282,
892,
3653,
365,
3483,
370,
314,
199,
1430,
1256,
3032,
370,
314,
2517,
770,
3423,
446,
16377,
63,
466,
14,
961,
365,
1373,
402,
314,
199,
1430,
730,
5262,
3247,
315,
642,
859,
334,
10180,
465,
32685,
63,
3078,
5786,
680,
199,
1858,
2606,
15,
4259,
4474,
334,
6777,
787,
8860,
701,
6879,
2176,
436,
1443,
9128,
199,
17431,
395,
4573,
3653,
365,
3483,
446,
16377,
63,
929,
14,
961,
3653,
10557,
314,
1174,
199,
1618,
314,
18054,
9933,
12,
465,
282,
14665,
402,
314,
17880,
5262,
199,
12344,
3247,
315,
642,
859,
334,
509,
2893,
12,
32685,
63,
18013,
680,
199,
10369,
3520,
7556,
365,
3679,
590,
1844,
461,
14,
199,
199,
1918,
1865,
701,
1314,
4474,
787,
2797,
365,
3247,
701,
3520,
4713,
26,
199,
17,
14,
437,
1655,
13,
6100,
1566,
911,
506,
2797,
2544,
282,
6656,
13,
6100,
1566,
14,
199,
18,
14,
437,
23568,
13,
1393,
770,
1566,
911,
506,
2797,
2544,
282,
10889,
13,
1393,
770,
1566,
12,
2043,
7444,
642,
18511,
543,
314,
1642,
2332,
14,
199,
22321,
805,
911,
506,
2797,
737,
4750,
5403,
367,
1924,
1566,
14,
199,
624,
199,
199,
646,
984,
199,
646,
1059,
199,
646,
295,
199,
646,
16826,
199,
504,
15072,
773,
492,
610,
24751,
11532,
199,
199,
3,
314,
1566,
730,
5262,
12,
1314,
5627,
314,
11150,
402,
16377,
63,
466,
199,
7608,
63,
3078,
5786,
29,
16,
27,
32685,
63,
3078,
19736,
29,
17,
27,
32685,
63,
13272,
5786,
29,
18,
27,
32685,
63,
13272,
19736,
29,
19,
27,
199,
7608,
63,
20425,
1951,
29,
20,
27,
32685,
63,
31749,
1293,
1951,
29,
21,
27,
32685,
63,
7134,
5443,
29,
22,
27,
32685,
63,
5569,
3942,
29,
23,
27,
199,
7608,
63,
1093,
20425,
1951,
29,
24,
27,
32685,
63,
19374,
1092,
57,
29,
25,
27,
32685,
63,
12533,
29,
709,
27,
32685,
63,
1438,
3064,
29,
845,
27,
32685,
63,
3230,
35,
1668,
568,
29,
713,
27,
199,
7608,
63,
3230,
35,
1668,
1877,
29,
969,
27,
32685,
63,
18583,
54,
1922,
29,
1079,
27,
32685,
63,
906,
26907,
29,
1046,
27,
32685,
63,
5443,
29,
975,
27,
32685,
63,
27235,
1075,
29,
1196,
27,
199,
7608,
63,
25571,
31588,
2901,
29,
1085,
27,
32685,
63,
25091,
29,
1167,
27,
32685,
63,
907,
20562,
29,
1165,
27,
32685,
63,
1734,
5443,
29,
2025,
27,
32685,
63,
11793,
9002,
29,
1081,
27,
199,
3,
314,
17880,
1174,
5262,
12,
1314,
5627,
314,
11150,
402,
16377,
63,
929,
199,
7608,
63,
18013,
275,
413,
8999,
16,
27,
32685,
63,
13060,
275,
413,
8999,
18,
27,
32685,
63,
19600,
275,
413,
8999,
19,
27,
32685,
63,
10614,
275,
413,
8999,
21,
199,
7608,
63,
13352,
275,
413,
8999,
22,
27,
32685,
63,
10761,
275,
413,
8999,
23,
199,
199,
3,
5627,
314,
769,
402,
9933,
12,
370,
506,
1202,
315,
6114,
1566,
2943,
14,
199,
692,
610,
24751,
11532,
14,
5720,
2822,
25160,
2640,
837,
272,
485,
17431,
275,
19110,
14379,
18529,
1689,
3717,
18529,
1689,
2602,
18529,
1689,
3110,
401,
430,
272,
485,
18156,
63,
25768,
275,
334,
7608,
63,
18013,
12,
32685,
63,
13060,
12,
32685,
63,
13352,
12,
32685,
63,
10761,
9,
199,
2836,
26,
272,
485,
17431,
275,
19110,
3717,
18529,
1689,
16985,
18529,
1689,
14379,
18529,
1689,
3396,
401,
298,
45,
2237,
272,
485,
18156,
63,
25768,
275,
334,
7608,
63,
13060,
12,
32685,
63,
19600,
12,
32685,
63,
18013,
12,
32685,
63,
10614,
9,
199,
199,
3,
282,
2600,
370,
2341,
282,
17880,
536,
1901,
2399,
1329,
199,
63,
18156,
63,
1247,
275,
1211,
7694,
354,
12,
1329,
9,
586,
367,
1329,
315,
1425,
8,
552,
1547,
17431,
430,
586,
367,
536,
315,
485,
17431,
59,
1955,
3934,
199,
199,
3,
437,
2517,
424,
365,
282,
1021,
1314,
5398,
83,
3423,
370,
1373,
730,
402,
1566,
14,
2779,
965,
2877,
199,
3,
3102,
26,
5398,
436,
625,
3409,
12,
1314,
664,
282,
805,
436,
282,
4565,
3414,
12,
465,
199,
3,
2138,
701,
485,
1122,
63,
4041,
1252,
6006,
787,
2877,
2943,
402,
2517,
7735,
26,
199,
3,
485,
3184,
34,
5755,
10022,
1566,
2943,
543,
949,
9933,
436,
949,
10093,
14,
199,
3,
3091,
2018,
3423,
787,
2797,
1380,
949,
4474,
787,
2517,
770,
14,
199,
3,
485,
6600,
8094,
5755,
10022,
1566,
2943,
543,
9933,
436,
282,
10093,
14,
199,
3,
437,
2018,
805,
365,
2797,
1924,
900,
376,
1566,
365,
4046,
14,
199,
199,
533,
485,
3184,
34,
5755,
26,
272,
347,
636,
826,
721,
277,
12,
730,
12,
3938,
12,
3938,
3615,
304,
267,
291,
14,
466,
275,
730,
267,
291,
14,
4041,
275,
24958,
6416,
1313,
59,
466,
1527,
16,
28012,
3524,
267,
291,
14,
3440,
275,
3938,
267,
291,
14,
3440,
3615,
275,
3938,
3615,
267,
291,
14,
1393,
770,
9204,
275,
942,
267,
291,
14,
2479,
1677,
275,
488,
339,
347,
5398,
8,
277,
12,
18038,
2723,
12,
2562,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mikewiebe-ansible/ansible
|
test/units/modules/network/netvisor/test_pn_ipv6security_raguard.py
|
23
|
3119
|
# Copyright: (c) 2018, Pluribus Networks
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from units.compat.mock import patch
from ansible.modules.network.netvisor import pn_ipv6security_raguard
from units.modules.utils import set_module_args
from .nvos_module import TestNvosModule
class TestIPV6SecurityRaguardModule(TestNvosModule):
module = pn_ipv6security_raguard
def setUp(self):
self.mock_run_nvos_commands = patch('ansible.modules.network.netvisor.pn_ipv6security_raguard.run_cli')
self.run_nvos_commands = self.mock_run_nvos_commands.start()
self.mock_run_check_cli = patch('ansible.modules.network.netvisor.pn_ipv6security_raguard.check_cli')
self.run_check_cli = self.mock_run_check_cli.start()
def tearDown(self):
self.mock_run_nvos_commands.stop()
def run_cli_patch(self, module, cli, state_map):
if state_map['present'] == 'ipv6security-raguard-create':
results = dict(
changed=True,
cli_cmd=cli
)
elif state_map['absent'] == 'ipv6security-raguard-delete':
results = dict(
changed=True,
cli_cmd=cli
)
elif state_map['update'] == 'ipv6security-raguard-modify':
results = dict(
changed=True,
cli_cmd=cli
)
module.exit_json(**results)
def load_fixtures(self, commands=None, state=None, transport='cli'):
self.run_nvos_commands.side_effect = self.run_cli_patch
if state == 'present':
self.run_check_cli.return_value = False
if state == 'absent':
self.run_check_cli.return_value = True
if state == 'update':
self.run_check_cli.return_value = True
def test_ipv6security_raguard_create(self):
set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'foo',
'pn_device': 'host'})
result = self.execute_module(changed=True, state='present')
expected_cmd = ' switch sw01 ipv6security-raguard-create name foo device host'
self.assertEqual(result['cli_cmd'], expected_cmd)
def test_ipv6security_raguard_delete(self):
set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'foo',
'state': 'absent'})
result = self.execute_module(changed=True, state='absent')
expected_cmd = ' switch sw01 ipv6security-raguard-delete name foo '
self.assertEqual(result['cli_cmd'], expected_cmd)
def test_ipv6security_raguard_modify(self):
set_module_args({'pn_cliswitch': 'sw01', 'pn_name': 'foo',
'pn_device': 'router', 'pn_router_priority': 'medium', 'state': 'update'})
result = self.execute_module(changed=True, state='absent')
expected_cmd = ' switch sw01 ipv6security-raguard-modify name foo device router router-priority medium'
self.assertEqual(result['cli_cmd'], expected_cmd)
|
gpl-3.0
|
[
3,
1898,
26,
334,
67,
9,
14894,
12,
7497,
2302,
5610,
17138,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
846,
8286,
492,
13631,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
15969,
736,
63,
578,
492,
1379,
46,
86,
736,
2377,
421,
199,
533,
1379,
11253,
22,
7676,
50,
643,
85,
1005,
2377,
8,
774,
46,
86,
736,
2377,
304,
339,
859,
275,
13631,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1805,
63,
1065,
63,
15969,
736,
63,
4405,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
846,
8286,
14,
4812,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
14,
1065,
63,
2764,
358,
267,
291,
14,
1065,
63,
15969,
736,
63,
4405,
275,
291,
14,
1805,
63,
1065,
63,
15969,
736,
63,
4405,
14,
928,
342,
398,
291,
14,
1805,
63,
1065,
63,
1074,
63,
2764,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
846,
8286,
14,
4812,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
14,
1074,
63,
2764,
358,
267,
291,
14,
1065,
63,
1074,
63,
2764,
275,
291,
14,
1805,
63,
1065,
63,
1074,
63,
2764,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
1805,
63,
1065,
63,
15969,
736,
63,
4405,
14,
2379,
342,
339,
347,
1255,
63,
2764,
63,
2068,
8,
277,
12,
859,
12,
5053,
12,
1174,
63,
1130,
304,
267,
340,
1174,
63,
1130,
459,
1881,
418,
508,
283,
4774,
22,
4416,
13,
2527,
85,
1005,
13,
981,
356,
288,
2058,
275,
1211,
8,
355,
2896,
29,
549,
12,
355,
5053,
63,
1760,
29,
2764,
288,
776,
267,
916,
1174,
63,
1130,
459,
5575,
418,
508,
283,
4774,
22,
4416,
13,
2527,
85,
1005,
13,
1807,
356,
288,
2058,
275,
1211,
8,
355,
2896,
29,
549,
12,
355,
5053,
63,
1760,
29,
2764,
288,
776,
267,
916,
1174,
63,
1130,
459,
873,
418,
508,
283,
4774,
22,
4416,
13,
2527,
85,
1005,
13,
8951,
356,
288,
2058,
275,
1211,
8,
355,
2896,
29,
549,
12,
355,
5053,
63,
1760,
29,
2764,
288,
776,
267,
859,
14,
2224,
63,
1001,
3682,
2604,
9,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
1174,
29,
403,
12,
7773,
534,
2764,
735,
267,
291,
14,
1065,
63,
15969,
736,
63,
4405,
14,
2441,
63,
5881,
275,
291,
14,
1065,
63,
2764,
63,
2068,
267,
340,
1174,
508,
283,
1881,
356,
288,
291,
14,
1065,
63,
1074,
63,
2764,
14,
1107,
63,
585,
275,
756,
267,
340,
1174,
508,
283,
5575,
356,
288,
291,
14,
1065,
63,
1074,
63,
2764,
14,
1107,
63,
585,
275,
715,
267,
340,
1174,
508,
283,
873,
356,
288,
291,
14,
1065,
63,
1074,
63,
2764,
14,
1107,
63,
585,
275,
715,
339,
347,
511,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
63,
981,
8,
277,
304,
267,
663,
63,
578,
63,
589,
3252,
4812,
63,
2764,
5656,
356,
283,
3519,
614,
297,
283,
4812,
63,
354,
356,
283,
1421,
297,
586,
283,
4812,
63,
1782,
356,
283,
1102,
3071,
267,
754,
275,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
1174,
534,
1881,
358,
267,
1420,
63,
1760,
275,
283,
6258,
5584,
614,
3278,
22,
4416,
13,
2527,
85,
1005,
13,
981,
536,
3925,
221,
2243,
1591,
7,
267,
291,
14,
629,
8,
1099,
459,
2764,
63,
1760,
995,
1420,
63,
1760,
9,
339,
347,
511,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
63,
1807,
8,
277,
304,
267,
663,
63,
578,
63,
589,
3252,
4812,
63,
2764,
5656,
356,
283,
3519,
614,
297,
283,
4812,
63,
354,
356,
283,
1421,
297,
586,
283,
929,
356,
283,
5575,
3071,
267,
754,
275,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
1174,
534,
5575,
358,
267,
1420,
63,
1760,
275,
283,
6258,
5584,
614,
3278,
22,
4416,
13,
2527,
85,
1005,
13,
1807,
536,
3925,
283,
267,
291,
14,
629,
8,
1099,
459,
2764,
63,
1760,
995,
1420,
63,
1760,
9,
339,
347,
511,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
63,
8951,
8,
277,
304,
267,
663,
63,
578,
63,
589,
3252,
4812,
63,
2764,
5656,
356,
283,
3519,
614,
297,
283,
4812,
63,
354,
356,
283,
1421,
297,
586,
283,
4812,
63,
1782,
356,
283,
4995,
297,
283,
4812,
63,
4995,
63,
6693,
356,
283,
14345,
297,
283,
929,
356,
283,
873,
3071,
267,
754,
275,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
1174,
534,
5575,
358,
267,
1420,
63,
1760,
275,
283,
6258,
5584,
614,
3278,
22,
4416,
13,
2527,
85,
1005,
13,
8951,
536,
3925,
221,
2243,
6197,
6197,
13,
6693,
21576,
7,
267,
291,
14,
629,
8,
1099,
459,
2764,
63,
1760,
995,
1420,
63,
1760,
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
] |
[
1898,
26,
334,
67,
9,
14894,
12,
7497,
2302,
5610,
17138,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
846,
8286,
492,
13631,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
199,
504,
1275,
15969,
736,
63,
578,
492,
1379,
46,
86,
736,
2377,
421,
199,
533,
1379,
11253,
22,
7676,
50,
643,
85,
1005,
2377,
8,
774,
46,
86,
736,
2377,
304,
339,
859,
275,
13631,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1805,
63,
1065,
63,
15969,
736,
63,
4405,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
846,
8286,
14,
4812,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
14,
1065,
63,
2764,
358,
267,
291,
14,
1065,
63,
15969,
736,
63,
4405,
275,
291,
14,
1805,
63,
1065,
63,
15969,
736,
63,
4405,
14,
928,
342,
398,
291,
14,
1805,
63,
1065,
63,
1074,
63,
2764,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
846,
8286,
14,
4812,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
14,
1074,
63,
2764,
358,
267,
291,
14,
1065,
63,
1074,
63,
2764,
275,
291,
14,
1805,
63,
1065,
63,
1074,
63,
2764,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
1805,
63,
1065,
63,
15969,
736,
63,
4405,
14,
2379,
342,
339,
347,
1255,
63,
2764,
63,
2068,
8,
277,
12,
859,
12,
5053,
12,
1174,
63,
1130,
304,
267,
340,
1174,
63,
1130,
459,
1881,
418,
508,
283,
4774,
22,
4416,
13,
2527,
85,
1005,
13,
981,
356,
288,
2058,
275,
1211,
8,
355,
2896,
29,
549,
12,
355,
5053,
63,
1760,
29,
2764,
288,
776,
267,
916,
1174,
63,
1130,
459,
5575,
418,
508,
283,
4774,
22,
4416,
13,
2527,
85,
1005,
13,
1807,
356,
288,
2058,
275,
1211,
8,
355,
2896,
29,
549,
12,
355,
5053,
63,
1760,
29,
2764,
288,
776,
267,
916,
1174,
63,
1130,
459,
873,
418,
508,
283,
4774,
22,
4416,
13,
2527,
85,
1005,
13,
8951,
356,
288,
2058,
275,
1211,
8,
355,
2896,
29,
549,
12,
355,
5053,
63,
1760,
29,
2764,
288,
776,
267,
859,
14,
2224,
63,
1001,
3682,
2604,
9,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
12,
1174,
29,
403,
12,
7773,
534,
2764,
735,
267,
291,
14,
1065,
63,
15969,
736,
63,
4405,
14,
2441,
63,
5881,
275,
291,
14,
1065,
63,
2764,
63,
2068,
267,
340,
1174,
508,
283,
1881,
356,
288,
291,
14,
1065,
63,
1074,
63,
2764,
14,
1107,
63,
585,
275,
756,
267,
340,
1174,
508,
283,
5575,
356,
288,
291,
14,
1065,
63,
1074,
63,
2764,
14,
1107,
63,
585,
275,
715,
267,
340,
1174,
508,
283,
873,
356,
288,
291,
14,
1065,
63,
1074,
63,
2764,
14,
1107,
63,
585,
275,
715,
339,
347,
511,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
63,
981,
8,
277,
304,
267,
663,
63,
578,
63,
589,
3252,
4812,
63,
2764,
5656,
356,
283,
3519,
614,
297,
283,
4812,
63,
354,
356,
283,
1421,
297,
586,
283,
4812,
63,
1782,
356,
283,
1102,
3071,
267,
754,
275,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
1174,
534,
1881,
358,
267,
1420,
63,
1760,
275,
283,
6258,
5584,
614,
3278,
22,
4416,
13,
2527,
85,
1005,
13,
981,
536,
3925,
221,
2243,
1591,
7,
267,
291,
14,
629,
8,
1099,
459,
2764,
63,
1760,
995,
1420,
63,
1760,
9,
339,
347,
511,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
63,
1807,
8,
277,
304,
267,
663,
63,
578,
63,
589,
3252,
4812,
63,
2764,
5656,
356,
283,
3519,
614,
297,
283,
4812,
63,
354,
356,
283,
1421,
297,
586,
283,
929,
356,
283,
5575,
3071,
267,
754,
275,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
1174,
534,
5575,
358,
267,
1420,
63,
1760,
275,
283,
6258,
5584,
614,
3278,
22,
4416,
13,
2527,
85,
1005,
13,
1807,
536,
3925,
283,
267,
291,
14,
629,
8,
1099,
459,
2764,
63,
1760,
995,
1420,
63,
1760,
9,
339,
347,
511,
63,
4774,
22,
4416,
63,
2527,
85,
1005,
63,
8951,
8,
277,
304,
267,
663,
63,
578,
63,
589,
3252,
4812,
63,
2764,
5656,
356,
283,
3519,
614,
297,
283,
4812,
63,
354,
356,
283,
1421,
297,
586,
283,
4812,
63,
1782,
356,
283,
4995,
297,
283,
4812,
63,
4995,
63,
6693,
356,
283,
14345,
297,
283,
929,
356,
283,
873,
3071,
267,
754,
275,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
1174,
534,
5575,
358,
267,
1420,
63,
1760,
275,
283,
6258,
5584,
614,
3278,
22,
4416,
13,
2527,
85,
1005,
13,
8951,
536,
3925,
221,
2243,
6197,
6197,
13,
6693,
21576,
7,
267,
291,
14,
629,
8,
1099,
459,
2764,
63,
1760,
995,
1420,
63,
1760,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
autokey-py3/autokey
|
lib/autokey/qtui/popupmenu.py
|
4
|
6205
|
# Copyright (C) 2011 Chris Dekter
# Copyright (C) 2018 Thomas Hess
#
# 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/>.
from typing import List, Union
import logging
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMenu, QAction, QWidget
from autokey import configmanager as cm
import autokey.model
import autokey.service
FolderList = List[autokey.model.Folder]
Item = Union[autokey.model.Script, autokey.model.Phrase]
_logger = logging.getLogger("phrase-menu")
class PopupMenu(QMenu):
def __init__(self,
service: autokey.service.Service,
folders: FolderList=None,
items: List[Item]=None,
on_desktop: bool=True,
title: str=None,
parent=None):
super(PopupMenu, self).__init__(parent)
if items is None:
items = []
if folders is None:
folders = []
self.setFocusPolicy(Qt.StrongFocus)
self.service = service
self._on_desktop = on_desktop
if title is not None:
self.setTitle(title)
if cm.ConfigManager.SETTINGS[cm.SORT_BY_USAGE_COUNT]:
_logger.debug("Sorting phrase menu by usage count")
folders.sort(key=lambda obj: obj.usageCount, reverse=True)
items.sort(key=lambda obj: obj.usageCount, reverse=True)
else:
_logger.debug("Sorting phrase menu by item name/title")
folders.sort(key=lambda obj: str(obj))
items.sort(key=lambda obj: str(obj))
if len(folders) == 1 and len(items) == 0 and on_desktop:
# Only one folder - create menu with just its folders and items
self.setTitle(folders[0].title)
for folder in folders[0].folders:
sub_menu_item = SubMenu(
self._getMnemonic(folder.title),
self,
service,
folder.folders,
folder.items,
False
)
self.addAction(sub_menu_item)
if folders[0].folders:
self.addSeparator()
self._add_items_to_self(folders[0].items, on_desktop)
else:
# Create folder section
for folder in folders:
sub_menu_item = SubMenu(
self._getMnemonic(folder.title),
self,
service,
folder.folders,
folder.items,
False
)
self.addAction(sub_menu_item)
if folders:
self.addSeparator()
self._add_items_to_self(items, on_desktop)
def _add_item(self, description, item):
action = ItemAction(self, self._getMnemonic(description), item, self.service.item_selected)
self.addAction(action)
def _add_items_to_self(self, items, on_desktop):
# Create item (script/phrase) section
if cm.ConfigManager.SETTINGS[cm.SORT_BY_USAGE_COUNT]:
items.sort(key=lambda obj: obj.usageCount, reverse=True)
else:
items.sort(key=lambda obj: str(obj))
for item in items:
if on_desktop:
self._add_item(item.get_description(self.service.lastStackState), item)
else:
self._add_item(item.description, item)
def _getMnemonic(self, desc):
#if 1 < 10 and '&' not in desc and self._onDesktop:
# ret = "&%d - %s" % (self.__i, desc)
# self.__i += 1
# return ret
#else:
# FIXME - menu does not get keyboard focus, so mnemonic is useless
return desc
class SubMenu(QAction):
"""
This QAction is used to create submenu in the popup menu.
It gets used when a folder with a sub-folder has a
hotkey assigned, to recursively show subfolder contents.
"""
def __init__(self,
title: str,
parent: PopupMenu,
service,
folders: FolderList=None,
items: List[Item]=None,
on_desktop: bool=True):
icon = QIcon.fromTheme("folder")
super(SubMenu, self).__init__(icon, title, parent)
self.setMenu(PopupMenu(service, folders, items, on_desktop, title, parent))
def setParent(self, parent: QWidget=None):
super(SubMenu, self).setParent(parent)
self.menu().setParent(parent)
class ItemAction(QAction):
action_sig = pyqtSignal([autokey.model.AbstractHotkey], name="action_sig")
def __init__(self, parent: QWidget, description: str, item: Item, target):
icon = ItemAction._icon_for_item(item)
super(ItemAction, self).__init__(icon, description, parent)
self.item = item
self.triggered.connect(lambda: self.action_sig.emit(self.item))
self.action_sig.connect(target)
@staticmethod
def _icon_for_item(item: Item) -> QIcon:
if isinstance(item, autokey.model.Script):
return QIcon.fromTheme("text-x-python")
elif isinstance(item, autokey.model.Phrase):
return QIcon.fromTheme("text-x-generic")
else:
error_msg = "ItemAction got unknown item. Expected Union[autokey.model.Script, autokey.model.Phrase], " \
"got '{}'".format(str(type(item)))
_logger.error(error_msg)
raise ValueError(error_msg)
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
7760,
2799,
5719,
1487,
75,
351,
199,
3,
1898,
334,
35,
9,
14894,
27864,
5311,
385,
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,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
14090,
492,
3820,
12,
15961,
199,
199,
646,
2050,
199,
504,
14084,
21,
14,
10901,
492,
3959,
12,
27149,
11274,
199,
504,
14084,
21,
14,
10604,
492,
1413,
8954,
199,
504,
14084,
21,
14,
29081,
492,
1413,
5977,
12,
1413,
3310,
12,
1413,
3339,
421,
199,
504,
2599,
498,
492,
1101,
2609,
465,
6904,
199,
646,
2599,
498,
14,
1238,
199,
646,
2599,
498,
14,
1364,
199,
199,
7850,
1296,
275,
3820,
59,
2495,
498,
14,
1238,
14,
7850,
61,
199,
2081,
275,
15961,
59,
2495,
498,
14,
1238,
14,
5229,
12,
2599,
498,
14,
1238,
14,
5663,
8062,
61,
199,
63,
2921,
275,
2050,
14,
5572,
480,
10906,
13,
4470,
531,
421,
199,
533,
13244,
384,
5977,
8,
49,
5977,
304,
2286,
347,
636,
826,
721,
277,
12,
326,
2435,
26,
2599,
498,
14,
1364,
14,
3167,
12,
326,
16533,
26,
29121,
1296,
29,
403,
12,
326,
2974,
26,
3820,
59,
2081,
10404,
403,
12,
326,
641,
63,
14487,
26,
2155,
29,
549,
12,
326,
2538,
26,
620,
29,
403,
12,
326,
1676,
29,
403,
304,
267,
1613,
8,
26168,
5977,
12,
291,
2843,
826,
721,
1708,
9,
398,
340,
2974,
365,
488,
26,
288,
2974,
275,
942,
267,
340,
16533,
365,
488,
26,
288,
16533,
275,
942,
398,
291,
14,
409,
17310,
4845,
8,
4238,
14,
2848,
951,
17310,
9,
267,
291,
14,
1364,
275,
2435,
267,
291,
423,
265,
63,
14487,
275,
641,
63,
14487,
2728,
340,
2538,
365,
440,
488,
26,
288,
291,
14,
31675,
8,
1213,
9,
2728,
340,
6904,
14,
2028,
2988,
14,
13931,
59,
4400,
14,
23447,
63,
8285,
63,
20274,
63,
8760,
2189,
288,
485,
2921,
14,
1757,
480,
14376,
316,
21621,
6269,
701,
4503,
2338,
531,
288,
16533,
14,
3191,
8,
498,
29,
2734,
1559,
26,
1559,
14,
3807,
2353,
12,
3837,
29,
549,
9,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
1559,
14,
3807,
2353,
12,
3837,
29,
549,
9,
267,
587,
26,
288,
485,
2921,
14,
1757,
480,
14376,
316,
21621,
6269,
701,
1242,
536,
15,
1213,
531,
288,
16533,
14,
3191,
8,
498,
29,
2734,
1559,
26,
620,
8,
1113,
430,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
620,
8,
1113,
430,
755,
2728,
340,
822,
8,
15171,
9,
508,
413,
436,
822,
8,
1744,
9,
508,
378,
436,
641,
63,
14487,
26,
288,
327,
5972,
1373,
4922,
446,
1218,
6269,
543,
2951,
2399,
16533,
436,
2974,
288,
291,
14,
31675,
8,
15171,
59,
16,
1055,
1213,
9,
288,
367,
4922,
315,
16533,
59,
16,
1055,
15171,
26,
355,
1007,
63,
4470,
63,
1053,
275,
4804,
5977,
8,
490,
291,
423,
362,
45,
685,
16082,
8,
3741,
14,
1213,
395,
490,
291,
12,
490,
2435,
12,
490,
4922,
14,
15171,
12,
490,
4922,
14,
1744,
12,
490,
756,
355,
776,
355,
291,
14,
19006,
8,
954,
63,
4470,
63,
1053,
9,
1362,
288,
340,
16533,
59,
16,
1055,
15171,
26,
355,
291,
14,
525,
23344,
342,
7846,
291,
423,
525,
63,
1744,
63,
475,
63,
277,
8,
15171,
59,
16,
1055,
1744,
12,
641,
63,
14487,
9,
2728,
587,
26,
288,
327,
2790,
4922,
3420,
288,
367,
4922,
315,
16533,
26,
355,
1007,
63,
4470,
63,
1053,
275,
4804,
5977,
8,
490,
291,
423,
362,
45,
685,
16082,
8,
3741,
14,
1213,
395,
490,
291,
12,
490,
2435,
12,
490,
4922,
14,
15171,
12,
490,
4922,
14,
1744,
12,
490,
756,
355,
776,
355,
291,
14,
19006,
8,
954,
63,
4470,
63,
1053,
9,
1362,
288,
340,
16533,
26,
355,
291,
14,
525,
23344,
342,
1362,
288,
291,
423,
525,
63,
1744,
63,
475,
63,
277,
8,
1744,
12,
641,
63,
14487,
9,
5493,
347,
485,
525,
63,
1053,
8,
277,
12,
1369,
12,
1242,
304,
267,
1595,
275,
7020,
3310,
8,
277,
12,
291,
423,
362,
45,
685,
16082,
8,
1802,
395,
1242,
12,
291,
14,
1364,
14,
1053,
63,
5511,
9,
267,
291,
14,
19006,
8,
1287,
9,
5493,
347,
485,
525,
63,
1744,
63,
475,
63,
277,
8,
277,
12,
2974,
12,
641,
63,
14487,
304,
267,
327,
2790,
1242,
334,
1579,
15,
10906,
9,
3420,
267,
340,
6904,
14,
2028,
2988,
14,
13931,
59,
4400,
14,
23447,
63,
8285,
63,
20274,
63,
8760,
2189,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
1559,
14,
3807,
2353,
12,
3837,
29,
549,
9,
267,
587,
26,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
620,
8,
1113,
430,
10631,
367,
1242,
315,
2974,
26,
288,
340,
641,
63,
14487,
26,
355,
291,
423,
525,
63,
1053,
8,
1053,
14,
362,
63,
1802,
8,
277,
14,
1364,
14,
2019,
4851,
2223,
395,
1242,
9,
288,
587,
26,
355,
291,
423,
525,
63,
1053,
8,
1053,
14,
1802,
12,
1242,
9,
339,
347,
485,
362,
45,
685,
16082,
8,
277,
12,
4328,
304,
267,
327,
692,
413,
665,
1616,
436,
29285,
440,
315,
4328,
436,
291,
423,
265,
20436,
26,
267,
327,
259,
2203,
275,
11746,
5,
68,
446,
450,
83,
2,
450,
334,
277,
855,
73,
12,
4328,
9,
267,
327,
259,
291,
855,
73,
847
] |
[
1898,
334,
35,
9,
7760,
2799,
5719,
1487,
75,
351,
199,
3,
1898,
334,
35,
9,
14894,
27864,
5311,
385,
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,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
14090,
492,
3820,
12,
15961,
199,
199,
646,
2050,
199,
504,
14084,
21,
14,
10901,
492,
3959,
12,
27149,
11274,
199,
504,
14084,
21,
14,
10604,
492,
1413,
8954,
199,
504,
14084,
21,
14,
29081,
492,
1413,
5977,
12,
1413,
3310,
12,
1413,
3339,
421,
199,
504,
2599,
498,
492,
1101,
2609,
465,
6904,
199,
646,
2599,
498,
14,
1238,
199,
646,
2599,
498,
14,
1364,
199,
199,
7850,
1296,
275,
3820,
59,
2495,
498,
14,
1238,
14,
7850,
61,
199,
2081,
275,
15961,
59,
2495,
498,
14,
1238,
14,
5229,
12,
2599,
498,
14,
1238,
14,
5663,
8062,
61,
199,
63,
2921,
275,
2050,
14,
5572,
480,
10906,
13,
4470,
531,
421,
199,
533,
13244,
384,
5977,
8,
49,
5977,
304,
2286,
347,
636,
826,
721,
277,
12,
326,
2435,
26,
2599,
498,
14,
1364,
14,
3167,
12,
326,
16533,
26,
29121,
1296,
29,
403,
12,
326,
2974,
26,
3820,
59,
2081,
10404,
403,
12,
326,
641,
63,
14487,
26,
2155,
29,
549,
12,
326,
2538,
26,
620,
29,
403,
12,
326,
1676,
29,
403,
304,
267,
1613,
8,
26168,
5977,
12,
291,
2843,
826,
721,
1708,
9,
398,
340,
2974,
365,
488,
26,
288,
2974,
275,
942,
267,
340,
16533,
365,
488,
26,
288,
16533,
275,
942,
398,
291,
14,
409,
17310,
4845,
8,
4238,
14,
2848,
951,
17310,
9,
267,
291,
14,
1364,
275,
2435,
267,
291,
423,
265,
63,
14487,
275,
641,
63,
14487,
2728,
340,
2538,
365,
440,
488,
26,
288,
291,
14,
31675,
8,
1213,
9,
2728,
340,
6904,
14,
2028,
2988,
14,
13931,
59,
4400,
14,
23447,
63,
8285,
63,
20274,
63,
8760,
2189,
288,
485,
2921,
14,
1757,
480,
14376,
316,
21621,
6269,
701,
4503,
2338,
531,
288,
16533,
14,
3191,
8,
498,
29,
2734,
1559,
26,
1559,
14,
3807,
2353,
12,
3837,
29,
549,
9,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
1559,
14,
3807,
2353,
12,
3837,
29,
549,
9,
267,
587,
26,
288,
485,
2921,
14,
1757,
480,
14376,
316,
21621,
6269,
701,
1242,
536,
15,
1213,
531,
288,
16533,
14,
3191,
8,
498,
29,
2734,
1559,
26,
620,
8,
1113,
430,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
620,
8,
1113,
430,
755,
2728,
340,
822,
8,
15171,
9,
508,
413,
436,
822,
8,
1744,
9,
508,
378,
436,
641,
63,
14487,
26,
288,
327,
5972,
1373,
4922,
446,
1218,
6269,
543,
2951,
2399,
16533,
436,
2974,
288,
291,
14,
31675,
8,
15171,
59,
16,
1055,
1213,
9,
288,
367,
4922,
315,
16533,
59,
16,
1055,
15171,
26,
355,
1007,
63,
4470,
63,
1053,
275,
4804,
5977,
8,
490,
291,
423,
362,
45,
685,
16082,
8,
3741,
14,
1213,
395,
490,
291,
12,
490,
2435,
12,
490,
4922,
14,
15171,
12,
490,
4922,
14,
1744,
12,
490,
756,
355,
776,
355,
291,
14,
19006,
8,
954,
63,
4470,
63,
1053,
9,
1362,
288,
340,
16533,
59,
16,
1055,
15171,
26,
355,
291,
14,
525,
23344,
342,
7846,
291,
423,
525,
63,
1744,
63,
475,
63,
277,
8,
15171,
59,
16,
1055,
1744,
12,
641,
63,
14487,
9,
2728,
587,
26,
288,
327,
2790,
4922,
3420,
288,
367,
4922,
315,
16533,
26,
355,
1007,
63,
4470,
63,
1053,
275,
4804,
5977,
8,
490,
291,
423,
362,
45,
685,
16082,
8,
3741,
14,
1213,
395,
490,
291,
12,
490,
2435,
12,
490,
4922,
14,
15171,
12,
490,
4922,
14,
1744,
12,
490,
756,
355,
776,
355,
291,
14,
19006,
8,
954,
63,
4470,
63,
1053,
9,
1362,
288,
340,
16533,
26,
355,
291,
14,
525,
23344,
342,
1362,
288,
291,
423,
525,
63,
1744,
63,
475,
63,
277,
8,
1744,
12,
641,
63,
14487,
9,
5493,
347,
485,
525,
63,
1053,
8,
277,
12,
1369,
12,
1242,
304,
267,
1595,
275,
7020,
3310,
8,
277,
12,
291,
423,
362,
45,
685,
16082,
8,
1802,
395,
1242,
12,
291,
14,
1364,
14,
1053,
63,
5511,
9,
267,
291,
14,
19006,
8,
1287,
9,
5493,
347,
485,
525,
63,
1744,
63,
475,
63,
277,
8,
277,
12,
2974,
12,
641,
63,
14487,
304,
267,
327,
2790,
1242,
334,
1579,
15,
10906,
9,
3420,
267,
340,
6904,
14,
2028,
2988,
14,
13931,
59,
4400,
14,
23447,
63,
8285,
63,
20274,
63,
8760,
2189,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
1559,
14,
3807,
2353,
12,
3837,
29,
549,
9,
267,
587,
26,
288,
2974,
14,
3191,
8,
498,
29,
2734,
1559,
26,
620,
8,
1113,
430,
10631,
367,
1242,
315,
2974,
26,
288,
340,
641,
63,
14487,
26,
355,
291,
423,
525,
63,
1053,
8,
1053,
14,
362,
63,
1802,
8,
277,
14,
1364,
14,
2019,
4851,
2223,
395,
1242,
9,
288,
587,
26,
355,
291,
423,
525,
63,
1053,
8,
1053,
14,
1802,
12,
1242,
9,
339,
347,
485,
362,
45,
685,
16082,
8,
277,
12,
4328,
304,
267,
327,
692,
413,
665,
1616,
436,
29285,
440,
315,
4328,
436,
291,
423,
265,
20436,
26,
267,
327,
259,
2203,
275,
11746,
5,
68,
446,
450,
83,
2,
450,
334,
277,
855,
73,
12,
4328,
9,
267,
327,
259,
291,
855,
73,
847,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
usc-isi/nova
|
nova/tests/network/test_quantumv2.py
|
1
|
26589
|
# Copyright 2012 OpenStack LLC.
# 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.
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import mox
from nova import context
from nova import exception
from nova.network import model
from nova.network import quantumv2
from nova.network.quantumv2 import api as quantumapi
from nova.openstack.common import cfg
from nova import test
from nova import utils
from quantumclient.v2_0 import client
FLAGS = cfg.CONF
#NOTE: Quantum client raises Exception which is discouraged by HACKING.
# We set this variable here and use it for assertions below to avoid
# the hacking checks until we can make quantum client throw a custom
# exception class instead.
QUANTUM_CLIENT_EXCEPTION = Exception
class MyComparator(mox.Comparator):
def __init__(self, lhs):
self.lhs = lhs
def _com_dict(self, lhs, rhs):
if len(lhs) != len(rhs):
return False
for key, value in lhs.iteritems():
if key not in rhs:
return False
rhs_value = rhs[key]
if not self._com(value, rhs_value):
return False
return True
def _com_list(self, lhs, rhs):
if len(lhs) != len(rhs):
return False
for lhs_value in lhs:
if lhs_value not in rhs:
return False
return True
def _com(self, lhs, rhs):
if lhs is None:
return rhs is None
if isinstance(lhs, dict):
if not isinstance(rhs, dict):
return False
return self._com_dict(lhs, rhs)
if isinstance(lhs, list):
if not isinstance(rhs, list):
return False
return self._com_list(lhs, rhs)
if isinstance(lhs, tuple):
if not isinstance(rhs, tuple):
return False
return self._com_list(lhs, rhs)
return lhs == rhs
def equals(self, rhs):
return self._com(self.lhs, rhs)
def __repr__(self):
return str(self.lhs)
class TestQuantumClient(test.TestCase):
def test_withtoken(self):
self.flags(quantum_url='http://anyhost/')
self.flags(quantum_url_timeout=30)
my_context = context.RequestContext('userid',
'my_tenantid',
auth_token='token')
self.mox.StubOutWithMock(client.Client, "__init__")
client.Client.__init__(
endpoint_url=FLAGS.quantum_url,
token=my_context.auth_token,
timeout=FLAGS.quantum_url_timeout).AndReturn(None)
self.mox.ReplayAll()
quantumv2.get_client(my_context)
def test_withouttoken_keystone_connection_error(self):
self.flags(quantum_auth_strategy='keystone')
self.flags(quantum_url='http://anyhost/')
my_context = context.RequestContext('userid', 'my_tenantid')
self.assertRaises(QUANTUM_CLIENT_EXCEPTION,
quantumv2.get_client,
my_context)
def test_withouttoken_keystone_not_auth(self):
# self.flags(quantum_auth_strategy=None) fail to work
old_quantum_auth_strategy = FLAGS.quantum_auth_strategy
setattr(FLAGS, 'quantum_auth_strategy', None)
self.flags(quantum_url='http://anyhost/')
self.flags(quantum_url_timeout=30)
my_context = context.RequestContext('userid', 'my_tenantid')
self.mox.StubOutWithMock(client.Client, "__init__")
client.Client.__init__(
endpoint_url=FLAGS.quantum_url,
auth_strategy=None,
timeout=FLAGS.quantum_url_timeout).AndReturn(None)
self.mox.ReplayAll()
try:
quantumv2.get_client(my_context)
finally:
setattr(FLAGS, 'quantum_auth_strategy',
old_quantum_auth_strategy)
class TestQuantumv2(test.TestCase):
def setUp(self):
super(TestQuantumv2, self).setUp()
self.mox.StubOutWithMock(quantumv2, 'get_client')
self.moxed_client = self.mox.CreateMock(client.Client)
quantumv2.get_client(mox.IgnoreArg()).MultipleTimes().AndReturn(
self.moxed_client)
self.context = context.RequestContext('userid', 'my_tenantid')
setattr(self.context,
'auth_token',
'bff4a5a6b9eb4ea2a6efec6eefb77936')
self.instance = {'project_id': '9d049e4b60b64716978ab415e6fbd5c0',
'uuid': str(utils.gen_uuid()),
'display_name': 'test_instance',
'security_groups': []}
self.nets1 = [{'id': 'my_netid1',
'name': 'my_netname1',
'tenant_id': 'my_tenantid'}]
self.nets2 = []
self.nets2.append(self.nets1[0])
self.nets2.append({'id': 'my_netid2',
'name': 'my_netname2',
'tenant_id': 'my_tenantid'})
self.nets3 = self.nets2 + [{'id': 'my_netid3',
'name': 'my_netname3',
'tenant_id': 'my_tenantid'}]
self.nets4 = [{'id': 'his_netid4',
'name': 'his_netname4',
'tenant_id': 'his_tenantid'}]
self.nets = [self.nets1, self.nets2, self.nets3, self.nets4]
self.port_address = '10.0.1.2'
self.port_data1 = [{'network_id': 'my_netid1',
'device_id': 'device_id1',
'device_owner': 'compute:nova',
'id': 'my_portid1',
'fixed_ips': [{'ip_address': self.port_address,
'subnet_id': 'my_subid1'}],
'mac_address': 'my_mac1', }]
self.dhcp_port_data1 = [{'fixed_ips': [{'ip_address': '10.0.1.9',
'subnet_id': 'my_subid1'}]}]
self.port_data2 = []
self.port_data2.append(self.port_data1[0])
self.port_data2.append({'network_id': 'my_netid2',
'device_id': 'device_id2',
'device_owner': 'compute:nova',
'id': 'my_portid2',
'fixed_ips': [{'ip_address': '10.0.2.2',
'subnet_id': 'my_subid2'}],
'mac_address': 'my_mac2', })
self.port_data3 = [{'network_id': 'my_netid1',
'device_id': 'device_id3',
'device_owner': 'compute:nova',
'id': 'my_portid3',
'fixed_ips': [], # no fixed ip
'mac_address': 'my_mac3', }]
self.subnet_data1 = [{'id': 'my_subid1',
'cidr': '10.0.1.0/24',
'network_id': 'my_netid1',
'gateway_ip': '10.0.1.1',
'dns_nameservers': ['8.8.1.1', '8.8.1.2']}]
self.subnet_data2 = []
self.subnet_data2.append({'id': 'my_subid2',
'cidr': '10.0.2.0/24',
'network_id': 'my_netid2',
'gateway_ip': '10.0.2.1',
'dns_nameservers': ['8.8.2.1', '8.8.2.2']})
def tearDown(self):
try:
self.mox.UnsetStubs()
self.mox.VerifyAll()
finally:
FLAGS.reset()
def _verify_nw_info(self, nw_inf, index=0):
id_suffix = index + 1
self.assertEquals('10.0.%s.2' % id_suffix,
nw_inf.fixed_ips()[index]['address'])
self.assertEquals('my_netname%s' % id_suffix,
nw_inf[index]['network']['label'])
self.assertEquals('my_portid%s' % id_suffix, nw_inf[index]['id'])
self.assertEquals('my_mac%s' % id_suffix, nw_inf[index]['address'])
self.assertEquals('10.0.%s.0/24' % id_suffix,
nw_inf[index]['network']['subnets'][0]['cidr'])
self.assertTrue(model.IP(address='8.8.%s.1' % id_suffix) in
nw_inf[index]['network']['subnets'][0]['dns'])
def _get_instance_nw_info(self, number):
api = quantumapi.API()
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
api.db.instance_info_cache_update(mox.IgnoreArg(),
self.instance['uuid'],
mox.IgnoreArg())
port_data = number == 1 and self.port_data1 or self.port_data2
self.moxed_client.list_ports(
tenant_id=self.instance['project_id'],
device_id=self.instance['uuid']).AndReturn(
{'ports': port_data})
nets = number == 1 and self.nets1 or self.nets2
self.moxed_client.list_networks(
tenant_id=self.instance['project_id'],
shared=False).AndReturn({'networks': nets})
self.moxed_client.list_networks(
shared=True).AndReturn({'networks': []})
for i in xrange(1, number + 1):
subnet_data = i == 1 and self.subnet_data1 or self.subnet_data2
self.moxed_client.list_subnets(
id=mox.SameElementsAs(['my_subid%s' % i])).AndReturn(
{'subnets': subnet_data})
self.moxed_client.list_ports(
network_id=subnet_data[0]['network_id'],
device_owner='network:dhcp').AndReturn(
{'ports': []})
self.mox.ReplayAll()
nw_inf = api.get_instance_nw_info(self.context, self.instance)
for i in xrange(0, number):
self._verify_nw_info(nw_inf, i)
def test_get_instance_nw_info_1(self):
"""Test to get one port in one network and subnet."""
self._get_instance_nw_info(1)
def test_get_instance_nw_info_2(self):
"""Test to get one port in each of two networks and subnets."""
self._get_instance_nw_info(2)
def test_get_instance_nw_info_with_nets(self):
"""Test get instance_nw_info with networks passed in."""
api = quantumapi.API()
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
api.db.instance_info_cache_update(
mox.IgnoreArg(),
self.instance['uuid'], mox.IgnoreArg())
self.moxed_client.list_ports(
tenant_id=self.instance['project_id'],
device_id=self.instance['uuid']).AndReturn(
{'ports': self.port_data1})
self.moxed_client.list_subnets(
id=mox.SameElementsAs(['my_subid1'])).AndReturn(
{'subnets': self.subnet_data1})
self.moxed_client.list_ports(
network_id='my_netid1',
device_owner='network:dhcp').AndReturn(
{'ports': self.dhcp_port_data1})
self.mox.ReplayAll()
nw_inf = api.get_instance_nw_info(self.context,
self.instance,
networks=self.nets1)
self._verify_nw_info(nw_inf, 0)
def test_get_instance_nw_info_without_subnet(self):
"""Test get instance_nw_info for a port without subnet."""
api = quantumapi.API()
self.mox.StubOutWithMock(api.db, 'instance_info_cache_update')
api.db.instance_info_cache_update(
mox.IgnoreArg(),
self.instance['uuid'], mox.IgnoreArg())
self.moxed_client.list_ports(
tenant_id=self.instance['project_id'],
device_id=self.instance['uuid']).AndReturn(
{'ports': self.port_data3})
self.moxed_client.list_networks(
shared=False,
tenant_id=self.instance['project_id']).AndReturn(
{'networks': self.nets1})
self.moxed_client.list_networks(
shared=True).AndReturn({'networks': []})
self.mox.ReplayAll()
nw_inf = api.get_instance_nw_info(self.context,
self.instance)
id_suffix = 3
self.assertEquals(0, len(nw_inf.fixed_ips()))
self.assertEquals('my_netname1', nw_inf[0]['network']['label'])
self.assertEquals('my_portid%s' % id_suffix, nw_inf[0]['id'])
self.assertEquals('my_mac%s' % id_suffix, nw_inf[0]['address'])
self.assertEquals(0, len(nw_inf[0]['network']['subnets']))
def _allocate_for_instance(self, net_idx=1, **kwargs):
api = quantumapi.API()
self.mox.StubOutWithMock(api, 'get_instance_nw_info')
# Net idx is 1-based for compatibility with existing unit tests
nets = self.nets[net_idx - 1]
api.get_instance_nw_info(mox.IgnoreArg(),
self.instance,
networks=nets).AndReturn(None)
ports = {}
fixed_ips = {}
req_net_ids = []
if 'requested_networks' in kwargs:
for id, fixed_ip, port_id in kwargs['requested_networks']:
if port_id:
self.moxed_client.show_port(port_id).AndReturn(
{'port': {'id': 'my_portid1',
'network_id': 'my_netid1'}})
req_net_ids.append('my_netid1')
ports['my_netid1'] = self.port_data1[0]
id = 'my_netid1'
else:
fixed_ips[id] = fixed_ip
req_net_ids.append(id)
search_ids = [net['id'] for net in nets if net['id'] in req_net_ids]
mox_list_network_params = dict(tenant_id=self.instance['project_id'],
shared=False)
if search_ids:
mox_list_network_params['id'] = search_ids
self.moxed_client.list_networks(
**mox_list_network_params).AndReturn({'networks': nets})
mox_list_network_params = dict(shared=True)
if search_ids:
mox_list_network_params['id'] = search_ids
self.moxed_client.list_networks(
**mox_list_network_params).AndReturn({'networks': []})
for network in nets:
port_req_body = {
'port': {
'device_id': self.instance['uuid'],
'device_owner': 'compute:nova',
},
}
port = ports.get(network['id'], None)
if port:
port_id = port['id']
self.moxed_client.update_port(port_id,
MyComparator(port_req_body)
).AndReturn(
{'port': port})
else:
fixed_ip = fixed_ips.get(network['id'])
if fixed_ip:
port_req_body['port']['fixed_ip'] = fixed_ip
port_req_body['port']['network_id'] = network['id']
port_req_body['port']['admin_state_up'] = True
port_req_body['port']['tenant_id'] = \
self.instance['project_id']
res_port = {'port': {'id': 'fake'}}
self.moxed_client.create_port(
MyComparator(port_req_body)).AndReturn(res_port)
self.mox.ReplayAll()
api.allocate_for_instance(self.context, self.instance, **kwargs)
def test_allocate_for_instance_1(self):
"""Allocate one port in one network env."""
self._allocate_for_instance(1)
def test_allocate_for_instance_2(self):
"""Allocate one port in two networks env."""
self._allocate_for_instance(2)
def test_allocate_for_instance_with_requested_networks(self):
# specify only first and last network
requested_networks = [(net['id'], None, None)
for net in (self.nets3[0], self.nets3[-1])]
self._allocate_for_instance(net_idx=3,
requested_networks=requested_networks)
def test_allocate_for_instance_with_requested_networks_with_fixedip(self):
# specify only first and last network
requested_networks = [(self.nets1[0]['id'], '10.0.1.0/24', None)]
self._allocate_for_instance(net_idx=1,
requested_networks=requested_networks)
def test_allocate_for_instance_with_requested_networks_with_port(self):
# specify only first and last network
requested_networks = [(None, None, 'myportid1')]
self._allocate_for_instance(net_idx=1,
requested_networks=requested_networks)
def test_allocate_for_instance_ex1(self):
"""verify we will delete created ports
if we fail to allocate all net resources.
Mox to raise exception when creating a second port.
In this case, the code should delete the first created port.
"""
api = quantumapi.API()
self.moxed_client.list_networks(
tenant_id=self.instance['project_id'],
shared=False).AndReturn(
{'networks': self.nets2})
self.moxed_client.list_networks(shared=True).AndReturn(
{'networks': []})
index = 0
for network in self.nets2:
port_req_body = {
'port': {
'network_id': network['id'],
'admin_state_up': True,
'device_id': self.instance['uuid'],
'device_owner': 'compute:nova',
'tenant_id': self.instance['project_id'],
},
}
port = {'id': 'portid_' + network['id']}
if index == 0:
self.moxed_client.create_port(
MyComparator(port_req_body)).AndReturn({'port': port})
else:
self.moxed_client.create_port(
MyComparator(port_req_body)).AndRaise(
Exception("fail to create port"))
index += 1
self.moxed_client.delete_port('portid_' + self.nets2[0]['id'])
self.mox.ReplayAll()
self.assertRaises(QUANTUM_CLIENT_EXCEPTION, api.allocate_for_instance,
self.context, self.instance)
def test_allocate_for_instance_ex2(self):
"""verify we have no port to delete
if we fail to allocate the first net resource.
Mox to raise exception when creating the first port.
In this case, the code should not delete any ports.
"""
api = quantumapi.API()
self.moxed_client.list_networks(
tenant_id=self.instance['project_id'],
shared=False).AndReturn(
{'networks': self.nets2})
self.moxed_client.list_networks(shared=True).AndReturn(
{'networks': []})
port_req_body = {
'port': {
'network_id': self.nets2[0]['id'],
'admin_state_up': True,
'device_id': self.instance['uuid'],
'tenant_id': self.instance['project_id'],
},
}
self.moxed_client.create_port(
MyComparator(port_req_body)).AndRaise(
Exception("fail to create port"))
self.mox.ReplayAll()
self.assertRaises(QUANTUM_CLIENT_EXCEPTION, api.allocate_for_instance,
self.context, self.instance)
def _deallocate_for_instance(self, number):
port_data = number == 1 and self.port_data1 or self.port_data2
self.moxed_client.list_ports(
device_id=self.instance['uuid']).AndReturn(
{'ports': port_data})
for port in port_data:
self.moxed_client.delete_port(port['id'])
self.mox.ReplayAll()
api = quantumapi.API()
api.deallocate_for_instance(self.context, self.instance)
def test_deallocate_for_instance_1(self):
"""Test to deallocate in one port env."""
self._deallocate_for_instance(1)
def test_deallocate_for_instance_2(self):
"""Test to deallocate in two ports env."""
self._deallocate_for_instance(2)
def test_validate_networks(self):
requested_networks = [('my_netid1', 'test', None),
('my_netid2', 'test2', None)]
self.moxed_client.list_networks(
id=mox.SameElementsAs(['my_netid1', 'my_netid2']),
tenant_id=self.context.project_id,
shared=False).AndReturn(
{'networks': self.nets2})
self.moxed_client.list_networks(
id=mox.SameElementsAs(['my_netid1', 'my_netid2']),
shared=True).AndReturn(
{'networks': []})
self.mox.ReplayAll()
api = quantumapi.API()
api.validate_networks(self.context, requested_networks)
def test_validate_networks_ex_1(self):
requested_networks = [('my_netid1', 'test', None),
('my_netid2', 'test2', None)]
self.moxed_client.list_networks(
id=mox.SameElementsAs(['my_netid1', 'my_netid2']),
tenant_id=self.context.project_id,
shared=False).AndReturn(
{'networks': self.nets1})
self.moxed_client.list_networks(
id=mox.SameElementsAs(['my_netid1', 'my_netid2']),
shared=True).AndReturn(
{'networks': []})
self.mox.ReplayAll()
api = quantumapi.API()
try:
api.validate_networks(self.context, requested_networks)
except exception.NetworkNotFound as ex:
self.assertTrue("my_netid2" in str(ex))
def test_validate_networks_ex_2(self):
requested_networks = [('my_netid1', 'test', None),
('my_netid2', 'test2', None),
('my_netid3', 'test3', None)]
self.moxed_client.list_networks(
id=mox.SameElementsAs(['my_netid1', 'my_netid2', 'my_netid3']),
tenant_id=self.context.project_id,
shared=False).AndReturn(
{'networks': self.nets1})
self.moxed_client.list_networks(
id=mox.SameElementsAs(['my_netid1', 'my_netid2', 'my_netid3']),
shared=True).AndReturn(
{'networks': []})
self.mox.ReplayAll()
api = quantumapi.API()
try:
api.validate_networks(self.context, requested_networks)
except exception.NetworkNotFound as ex:
self.assertTrue("my_netid2, my_netid3" in str(ex))
def _mock_list_ports(self, port_data=None):
if port_data is None:
port_data = self.port_data2
address = self.port_address
self.moxed_client.list_ports(
fixed_ips=MyComparator('ip_address=%s' % address)).AndReturn(
{'ports': port_data})
self.mox.ReplayAll()
return address
def test_get_instance_uuids_by_ip_filter(self):
self._mock_list_ports()
filters = {'ip': '^10\\.0\\.1\\.2$'}
api = quantumapi.API()
result = api.get_instance_uuids_by_ip_filter(self.context, filters)
self.assertEquals('device_id1', result[0]['instance_uuid'])
self.assertEquals('device_id2', result[1]['instance_uuid'])
def test_get_fixed_ip_by_address_fails_for_no_ports(self):
address = self._mock_list_ports(port_data=[])
api = quantumapi.API()
self.assertRaises(exception.FixedIpNotFoundForAddress,
api.get_fixed_ip_by_address,
self.context, address)
def test_get_fixed_ip_by_address_succeeds_for_1_port(self):
address = self._mock_list_ports(port_data=self.port_data1)
api = quantumapi.API()
result = api.get_fixed_ip_by_address(self.context, address)
self.assertEquals('device_id1', result['instance_uuid'])
def test_get_fixed_ip_by_address_fails_for_more_than_1_port(self):
address = self._mock_list_ports()
api = quantumapi.API()
self.assertRaises(exception.FixedIpAssociatedWithMultipleInstances,
api.get_fixed_ip_by_address,
self.context, address)
def _get_available_networks(self, prv_nets, pub_nets, req_ids=None):
api = quantumapi.API()
nets = prv_nets + pub_nets
mox_list_network_params = dict(tenant_id=self.instance['project_id'],
shared=False)
if req_ids:
mox_list_network_params['id'] = req_ids
self.moxed_client.list_networks(
**mox_list_network_params).AndReturn({'networks': prv_nets})
mox_list_network_params = dict(shared=True)
if req_ids:
mox_list_network_params['id'] = req_ids
self.moxed_client.list_networks(
**mox_list_network_params).AndReturn({'networks': pub_nets})
self.mox.ReplayAll()
rets = api._get_available_networks(self.context,
self.instance['project_id'],
req_ids)
self.assertEqual(rets, nets)
def test_get_available_networks_all_private(self):
self._get_available_networks(prv_nets=self.nets2, pub_nets=[])
def test_get_available_networks_all_public(self):
self._get_available_networks(prv_nets=[], pub_nets=self.nets2)
def test_get_available_networks_private_and_public(self):
self._get_available_networks(prv_nets=self.nets1, pub_nets=self.nets4)
def test_get_available_networks_with_network_ids(self):
prv_nets = [self.nets3[0]]
pub_nets = [self.nets3[-1]]
# specify only first and last network
req_ids = [net['id'] for net in (self.nets3[0], self.nets3[-1])]
self._get_available_networks(prv_nets, pub_nets, req_ids)
|
apache-2.0
|
[
3,
1898,
6029,
14260,
20376,
14,
199,
3,
2900,
5924,
5702,
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,
3,
199,
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
646,
18610,
199,
199,
504,
5913,
492,
1067,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
1200,
492,
1402,
199,
504,
5913,
14,
1200,
492,
15381,
453,
86,
18,
199,
504,
5913,
14,
1200,
14,
25999,
86,
18,
492,
2986,
465,
15381,
85,
391,
1038,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4810,
199,
504,
5913,
492,
511,
199,
504,
5913,
492,
3778,
199,
504,
15381,
453,
1258,
14,
86,
18,
63,
16,
492,
1890,
421,
199,
4831,
275,
4810,
14,
3103,
199,
3,
19855,
26,
5843,
867,
453,
1890,
6534,
2186,
1314,
365,
2153,
25715,
6028,
701,
31697,
1206,
14,
199,
3,
420,
2136,
663,
642,
1750,
2348,
436,
675,
652,
367,
22835,
5084,
370,
5126,
199,
3,
420,
314,
11176,
316,
5920,
5133,
781,
883,
1852,
15381,
453,
1890,
7978,
282,
3537,
199,
3,
420,
1919,
1021,
3140,
14,
199,
2328,
1441,
2639,
63,
9901,
63,
15375,
275,
2186,
421,
199,
533,
4932,
26636,
8,
6625,
14,
26636,
304,
272,
347,
636,
826,
721,
277,
12,
13180,
304,
267,
291,
14,
12697,
275,
13180,
339,
347,
485,
957,
63,
807,
8,
277,
12,
13180,
12,
9085,
304,
267,
340,
822,
8,
12697,
9,
1137,
822,
8,
12071,
304,
288,
372,
756,
267,
367,
790,
12,
574,
315,
13180,
14,
4611,
837,
288,
340,
790,
440,
315,
9085,
26,
355,
372,
756,
288,
9085,
63,
585,
275,
9085,
59,
498,
61,
288,
340,
440,
291,
423,
957,
8,
585,
12,
9085,
63,
585,
304,
355,
372,
756,
267,
372,
715,
339,
347,
485,
957,
63,
513,
8,
277,
12,
13180,
12,
9085,
304,
267,
340,
822,
8,
12697,
9,
1137,
822,
8,
12071,
304,
288,
372,
756,
267,
367,
13180,
63,
585,
315,
13180,
26,
288,
340,
13180,
63,
585,
440,
315,
9085,
26,
355,
372,
756,
267,
372,
715,
339,
347,
485,
957,
8,
277,
12,
13180,
12,
9085,
304,
267,
340,
13180,
365,
488,
26,
288,
372,
9085,
365,
488,
267,
340,
1228,
8,
12697,
12,
1211,
304,
288,
340,
440,
1228,
8,
12071,
12,
1211,
304,
355,
372,
756,
288,
372,
291,
423,
957,
63,
807,
8,
12697,
12,
9085,
9,
267,
340,
1228,
8,
12697,
12,
769,
304,
288,
340,
440,
1228,
8,
12071,
12,
769,
304,
355,
372,
756,
288,
372,
291,
423,
957,
63,
513,
8,
12697,
12,
9085,
9,
267,
340,
1228,
8,
12697,
12,
2008,
304,
288,
340,
440,
1228,
8,
12071,
12,
2008,
304,
355,
372,
756,
288,
372,
291,
423,
957,
63,
513,
8,
12697,
12,
9085,
9,
267,
372,
13180,
508,
9085,
339,
347,
18527,
8,
277,
12,
9085,
304,
267,
372,
291,
423,
957,
8,
277,
14,
12697,
12,
9085,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
12697,
9,
421,
199,
533,
1379,
2371,
867,
453,
3041,
8,
396,
14,
1746,
304,
272,
347,
511,
63,
1045,
1418,
8,
277,
304,
267,
291,
14,
2469,
8,
25999,
63,
633,
534,
1014,
921,
1629,
1102,
6217,
267,
291,
14,
2469,
8,
25999,
63,
633,
63,
2593,
29,
1216,
9,
267,
3002,
63,
1100,
275,
1067,
14,
17679,
360,
19737,
297,
4490,
283,
1662,
63,
724,
4466,
68,
297,
4490,
1790,
63,
1418,
534,
1418,
358,
267,
291,
14,
6625,
14,
12088,
8,
1258,
14,
3041,
12,
4396,
826,
18617,
267,
1890,
14,
3041,
855,
826,
721,
288,
6037,
63,
633,
29,
4831,
14,
25999,
63,
633,
12,
288,
1526,
29,
1662,
63,
1100,
14,
1178,
63,
1418,
12,
288,
2653,
29,
4831,
14,
25999,
63,
633,
63,
2593,
680,
8572,
8,
403,
9,
267,
291,
14,
6625,
14,
12982,
342,
267,
15381,
453,
86,
18,
14,
362,
63,
1258,
8,
1662,
63,
1100,
9,
339,
347,
511,
63,
7395,
1418,
63,
19143,
63,
2105,
63,
705,
8,
277,
304,
267,
291,
14,
2469,
8,
25999,
63,
1178,
63,
8590,
534,
19143,
358,
267,
291,
14,
2469,
8,
25999,
63,
633,
534,
1014,
921,
1629,
1102,
6217,
267,
3002,
63,
1100,
275,
1067,
14,
17679,
360,
19737,
297,
283,
1662,
63,
724,
4466,
68,
358,
267,
291,
14,
1855,
8,
2328,
1441,
2639,
63,
9901,
63,
15375,
12,
2079,
15381,
453,
86,
18,
14,
362,
63,
1258,
12,
2079,
3002,
63,
1100,
9,
339,
347,
511,
63,
7395,
1418,
63,
19143,
63,
1397,
63,
1178,
8,
277,
304,
267,
327,
291,
14,
2469,
8,
25999,
63,
1178,
63,
8590,
29,
403,
9,
2449,
370,
1736,
267,
2269,
63,
25999,
63,
1178,
63,
8590,
275,
12846,
14,
25999,
63,
1178,
63,
8590,
267,
5371,
8,
4831,
12,
283,
25999,
63,
1178,
63,
8590,
297,
488,
9,
267,
291,
14,
2469,
8,
25999,
63,
633,
534,
1014,
921,
1629,
1102,
6217,
267,
291,
14,
2469,
8,
25999,
63,
633,
63,
2593,
29,
1216,
9,
267,
3002,
63,
1100,
275,
1067,
14,
17679,
360,
19737,
297,
283,
1662,
63,
724,
4466,
68,
358,
267,
291,
14,
6625,
14,
12088,
8,
1258,
14,
3041,
12,
4396,
826,
18617,
267,
1890,
14,
3041,
855,
826,
721,
288,
6037,
63,
633,
29,
4831,
14,
25999,
63,
633,
12,
288,
1790,
63,
8590,
29,
403,
12,
288,
2653,
29,
4831,
14,
25999,
63,
633
] |
[
1898,
6029,
14260,
20376,
14,
199,
3,
2900,
5924,
5702,
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,
3,
199,
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
646,
18610,
199,
199,
504,
5913,
492,
1067,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
1200,
492,
1402,
199,
504,
5913,
14,
1200,
492,
15381,
453,
86,
18,
199,
504,
5913,
14,
1200,
14,
25999,
86,
18,
492,
2986,
465,
15381,
85,
391,
1038,
199,
504,
5913,
14,
8512,
14,
2330,
492,
4810,
199,
504,
5913,
492,
511,
199,
504,
5913,
492,
3778,
199,
504,
15381,
453,
1258,
14,
86,
18,
63,
16,
492,
1890,
421,
199,
4831,
275,
4810,
14,
3103,
199,
3,
19855,
26,
5843,
867,
453,
1890,
6534,
2186,
1314,
365,
2153,
25715,
6028,
701,
31697,
1206,
14,
199,
3,
420,
2136,
663,
642,
1750,
2348,
436,
675,
652,
367,
22835,
5084,
370,
5126,
199,
3,
420,
314,
11176,
316,
5920,
5133,
781,
883,
1852,
15381,
453,
1890,
7978,
282,
3537,
199,
3,
420,
1919,
1021,
3140,
14,
199,
2328,
1441,
2639,
63,
9901,
63,
15375,
275,
2186,
421,
199,
533,
4932,
26636,
8,
6625,
14,
26636,
304,
272,
347,
636,
826,
721,
277,
12,
13180,
304,
267,
291,
14,
12697,
275,
13180,
339,
347,
485,
957,
63,
807,
8,
277,
12,
13180,
12,
9085,
304,
267,
340,
822,
8,
12697,
9,
1137,
822,
8,
12071,
304,
288,
372,
756,
267,
367,
790,
12,
574,
315,
13180,
14,
4611,
837,
288,
340,
790,
440,
315,
9085,
26,
355,
372,
756,
288,
9085,
63,
585,
275,
9085,
59,
498,
61,
288,
340,
440,
291,
423,
957,
8,
585,
12,
9085,
63,
585,
304,
355,
372,
756,
267,
372,
715,
339,
347,
485,
957,
63,
513,
8,
277,
12,
13180,
12,
9085,
304,
267,
340,
822,
8,
12697,
9,
1137,
822,
8,
12071,
304,
288,
372,
756,
267,
367,
13180,
63,
585,
315,
13180,
26,
288,
340,
13180,
63,
585,
440,
315,
9085,
26,
355,
372,
756,
267,
372,
715,
339,
347,
485,
957,
8,
277,
12,
13180,
12,
9085,
304,
267,
340,
13180,
365,
488,
26,
288,
372,
9085,
365,
488,
267,
340,
1228,
8,
12697,
12,
1211,
304,
288,
340,
440,
1228,
8,
12071,
12,
1211,
304,
355,
372,
756,
288,
372,
291,
423,
957,
63,
807,
8,
12697,
12,
9085,
9,
267,
340,
1228,
8,
12697,
12,
769,
304,
288,
340,
440,
1228,
8,
12071,
12,
769,
304,
355,
372,
756,
288,
372,
291,
423,
957,
63,
513,
8,
12697,
12,
9085,
9,
267,
340,
1228,
8,
12697,
12,
2008,
304,
288,
340,
440,
1228,
8,
12071,
12,
2008,
304,
355,
372,
756,
288,
372,
291,
423,
957,
63,
513,
8,
12697,
12,
9085,
9,
267,
372,
13180,
508,
9085,
339,
347,
18527,
8,
277,
12,
9085,
304,
267,
372,
291,
423,
957,
8,
277,
14,
12697,
12,
9085,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
620,
8,
277,
14,
12697,
9,
421,
199,
533,
1379,
2371,
867,
453,
3041,
8,
396,
14,
1746,
304,
272,
347,
511,
63,
1045,
1418,
8,
277,
304,
267,
291,
14,
2469,
8,
25999,
63,
633,
534,
1014,
921,
1629,
1102,
6217,
267,
291,
14,
2469,
8,
25999,
63,
633,
63,
2593,
29,
1216,
9,
267,
3002,
63,
1100,
275,
1067,
14,
17679,
360,
19737,
297,
4490,
283,
1662,
63,
724,
4466,
68,
297,
4490,
1790,
63,
1418,
534,
1418,
358,
267,
291,
14,
6625,
14,
12088,
8,
1258,
14,
3041,
12,
4396,
826,
18617,
267,
1890,
14,
3041,
855,
826,
721,
288,
6037,
63,
633,
29,
4831,
14,
25999,
63,
633,
12,
288,
1526,
29,
1662,
63,
1100,
14,
1178,
63,
1418,
12,
288,
2653,
29,
4831,
14,
25999,
63,
633,
63,
2593,
680,
8572,
8,
403,
9,
267,
291,
14,
6625,
14,
12982,
342,
267,
15381,
453,
86,
18,
14,
362,
63,
1258,
8,
1662,
63,
1100,
9,
339,
347,
511,
63,
7395,
1418,
63,
19143,
63,
2105,
63,
705,
8,
277,
304,
267,
291,
14,
2469,
8,
25999,
63,
1178,
63,
8590,
534,
19143,
358,
267,
291,
14,
2469,
8,
25999,
63,
633,
534,
1014,
921,
1629,
1102,
6217,
267,
3002,
63,
1100,
275,
1067,
14,
17679,
360,
19737,
297,
283,
1662,
63,
724,
4466,
68,
358,
267,
291,
14,
1855,
8,
2328,
1441,
2639,
63,
9901,
63,
15375,
12,
2079,
15381,
453,
86,
18,
14,
362,
63,
1258,
12,
2079,
3002,
63,
1100,
9,
339,
347,
511,
63,
7395,
1418,
63,
19143,
63,
1397,
63,
1178,
8,
277,
304,
267,
327,
291,
14,
2469,
8,
25999,
63,
1178,
63,
8590,
29,
403,
9,
2449,
370,
1736,
267,
2269,
63,
25999,
63,
1178,
63,
8590,
275,
12846,
14,
25999,
63,
1178,
63,
8590,
267,
5371,
8,
4831,
12,
283,
25999,
63,
1178,
63,
8590,
297,
488,
9,
267,
291,
14,
2469,
8,
25999,
63,
633,
534,
1014,
921,
1629,
1102,
6217,
267,
291,
14,
2469,
8,
25999,
63,
633,
63,
2593,
29,
1216,
9,
267,
3002,
63,
1100,
275,
1067,
14,
17679,
360,
19737,
297,
283,
1662,
63,
724,
4466,
68,
358,
267,
291,
14,
6625,
14,
12088,
8,
1258,
14,
3041,
12,
4396,
826,
18617,
267,
1890,
14,
3041,
855,
826,
721,
288,
6037,
63,
633,
29,
4831,
14,
25999,
63,
633,
12,
288,
1790,
63,
8590,
29,
403,
12,
288,
2653,
29,
4831,
14,
25999,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,
1,
1,
1,
1
] |
FreekingDean/home-assistant
|
tests/components/emulated_hue/test_init.py
|
4
|
1598
|
from unittest.mock import patch
from homeassistant.components.emulated_hue import Config, _LOGGER
def test_config_google_home_entity_id_to_number():
"""Test config adheres to the type."""
conf = Config({
'type': 'google_home'
})
number = conf.entity_id_to_number('light.test')
assert number == '1'
number = conf.entity_id_to_number('light.test')
assert number == '1'
number = conf.entity_id_to_number('light.test2')
assert number == '2'
entity_id = conf.number_to_entity_id('1')
assert entity_id == 'light.test'
def test_config_alexa_entity_id_to_number():
"""Test config adheres to the type."""
conf = Config({
'type': 'alexa'
})
number = conf.entity_id_to_number('light.test')
assert number == 'light.test'
number = conf.entity_id_to_number('light.test')
assert number == 'light.test'
number = conf.entity_id_to_number('light.test2')
assert number == 'light.test2'
entity_id = conf.number_to_entity_id('light.test')
assert entity_id == 'light.test'
def test_warning_config_google_home_listen_port():
"""Test we warn when non-default port is used for Google Home."""
with patch.object(_LOGGER, 'warning') as mock_warn:
Config({
'type': 'google_home',
'host_ip': '123.123.123.123',
'listen_port': 8300
})
assert mock_warn.called
assert mock_warn.mock_calls[0][1][0] == \
"When targetting Google Home, listening port has to be port 80"
|
mit
|
[
504,
2882,
14,
1805,
492,
3371,
2999,
199,
504,
8846,
14,
4608,
14,
29809,
972,
63,
25016,
492,
4094,
12,
485,
10186,
8065,
199,
318,
511,
63,
888,
63,
3098,
63,
4219,
63,
4502,
63,
344,
63,
475,
63,
1955,
837,
1128,
408,
774,
1101,
1503,
426,
470,
370,
314,
730,
1041,
1128,
3743,
275,
4094,
2561,
1039,
283,
466,
356,
283,
3098,
63,
4219,
7,
1128,
3828,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
17,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
17,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
18,
358,
1128,
702,
1329,
508,
283,
18,
7,
2958,
4642,
63,
344,
275,
3743,
14,
1955,
63,
475,
63,
4502,
63,
344,
360,
17,
358,
1128,
702,
4642,
63,
344,
508,
283,
4040,
14,
396,
7,
8065,
199,
318,
511,
63,
888,
63,
1895,
1800,
63,
4502,
63,
344,
63,
475,
63,
1955,
837,
1128,
408,
774,
1101,
1503,
426,
470,
370,
314,
730,
1041,
1128,
3743,
275,
4094,
2561,
1039,
283,
466,
356,
283,
1895,
1800,
7,
1128,
3828,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
4040,
14,
396,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
4040,
14,
396,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
18,
358,
1128,
702,
1329,
508,
283,
4040,
14,
396,
18,
7,
2958,
4642,
63,
344,
275,
3743,
14,
1955,
63,
475,
63,
4502,
63,
344,
360,
4040,
14,
396,
358,
1128,
702,
4642,
63,
344,
508,
283,
4040,
14,
396,
7,
8065,
199,
318,
511,
63,
3764,
63,
888,
63,
3098,
63,
4219,
63,
5859,
63,
719,
837,
1128,
408,
774,
781,
7987,
1380,
2222,
13,
885,
1844,
365,
1202,
367,
4475,
14621,
1041,
1128,
543,
3371,
14,
785,
1547,
10186,
12,
283,
3764,
358,
465,
1683,
63,
4050,
26,
1039,
4094,
2561,
1675,
283,
466,
356,
283,
3098,
63,
4219,
297,
1675,
283,
1102,
63,
711,
356,
283,
4288,
14,
4288,
14,
4288,
14,
4288,
297,
1675,
283,
5859,
63,
719,
356,
1695,
5863,
1039,
3828,
4341,
702,
1683,
63,
4050,
14,
3527,
1039,
702,
1683,
63,
4050,
14,
1805,
63,
5352,
59,
16,
1527,
17,
1527,
16,
61,
508,
971,
1675,
298,
11423,
1347,
1337,
4475,
14621,
12,
22721,
1844,
965,
370,
506,
1844,
5939,
2,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
14,
1805,
492,
3371,
2999,
199,
504,
8846,
14,
4608,
14,
29809,
972,
63,
25016,
492,
4094,
12,
485,
10186,
8065,
199,
318,
511,
63,
888,
63,
3098,
63,
4219,
63,
4502,
63,
344,
63,
475,
63,
1955,
837,
1128,
408,
774,
1101,
1503,
426,
470,
370,
314,
730,
1041,
1128,
3743,
275,
4094,
2561,
1039,
283,
466,
356,
283,
3098,
63,
4219,
7,
1128,
3828,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
17,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
17,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
18,
358,
1128,
702,
1329,
508,
283,
18,
7,
2958,
4642,
63,
344,
275,
3743,
14,
1955,
63,
475,
63,
4502,
63,
344,
360,
17,
358,
1128,
702,
4642,
63,
344,
508,
283,
4040,
14,
396,
7,
8065,
199,
318,
511,
63,
888,
63,
1895,
1800,
63,
4502,
63,
344,
63,
475,
63,
1955,
837,
1128,
408,
774,
1101,
1503,
426,
470,
370,
314,
730,
1041,
1128,
3743,
275,
4094,
2561,
1039,
283,
466,
356,
283,
1895,
1800,
7,
1128,
3828,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
4040,
14,
396,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
358,
1128,
702,
1329,
508,
283,
4040,
14,
396,
7,
2958,
1329,
275,
3743,
14,
4502,
63,
344,
63,
475,
63,
1955,
360,
4040,
14,
396,
18,
358,
1128,
702,
1329,
508,
283,
4040,
14,
396,
18,
7,
2958,
4642,
63,
344,
275,
3743,
14,
1955,
63,
475,
63,
4502,
63,
344,
360,
4040,
14,
396,
358,
1128,
702,
4642,
63,
344,
508,
283,
4040,
14,
396,
7,
8065,
199,
318,
511,
63,
3764,
63,
888,
63,
3098,
63,
4219,
63,
5859,
63,
719,
837,
1128,
408,
774,
781,
7987,
1380,
2222,
13,
885,
1844,
365,
1202,
367,
4475,
14621,
1041,
1128,
543,
3371,
14,
785,
1547,
10186,
12,
283,
3764,
358,
465,
1683,
63,
4050,
26,
1039,
4094,
2561,
1675,
283,
466,
356,
283,
3098,
63,
4219,
297,
1675,
283,
1102,
63,
711,
356,
283,
4288,
14,
4288,
14,
4288,
14,
4288,
297,
1675,
283,
5859,
63,
719,
356,
1695,
5863,
1039,
3828,
4341,
702,
1683,
63,
4050,
14,
3527,
1039,
702,
1683,
63,
4050,
14,
1805,
63,
5352,
59,
16,
1527,
17,
1527,
16,
61,
508,
971,
1675,
298,
11423,
1347,
1337,
4475,
14621,
12,
22721,
1844,
965,
370,
506,
1844,
5939,
2,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
tlakshman26/cinder-new-branch
|
cinder/db/sqlalchemy/migrate_repo/versions/002_quota_class.py
|
20
|
5291
|
# Copyright 2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from migrate import ForeignKeyConstraint
from sqlalchemy import Boolean, Column, DateTime
from sqlalchemy import MetaData, Integer, String, Table, ForeignKey
def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
# New table
quota_classes = Table('quota_classes', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Boolean(create_constraint=True,
name=None)),
Column('id', Integer(), primary_key=True),
Column('class_name',
String(length=255),
index=True),
Column('resource',
String(length=255)),
Column('hard_limit', Integer(), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
quota_classes.create()
quota_usages = Table('quota_usages', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Boolean(create_constraint=True,
name=None)),
Column('id', Integer(), primary_key=True),
Column('project_id',
String(length=255),
index=True),
Column('resource',
String(length=255)),
Column('in_use', Integer(), nullable=False),
Column('reserved', Integer(), nullable=False),
Column('until_refresh', Integer(), nullable=True),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
quota_usages.create()
reservations = Table('reservations', meta,
Column('created_at', DateTime(timezone=False)),
Column('updated_at', DateTime(timezone=False)),
Column('deleted_at', DateTime(timezone=False)),
Column('deleted', Boolean(create_constraint=True,
name=None)),
Column('id', Integer(), primary_key=True),
Column('uuid',
String(length=36),
nullable=False),
Column('usage_id',
Integer(),
ForeignKey('quota_usages.id'),
nullable=False),
Column('project_id',
String(length=255),
index=True),
Column('resource',
String(length=255)),
Column('delta', Integer(), nullable=False),
Column('expire', DateTime(timezone=False)),
mysql_engine='InnoDB',
mysql_charset='utf8',
)
reservations.create()
def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
fk_name = None
if migrate_engine.name == 'mysql':
fk_name = 'reservations_ibfk_1'
elif migrate_engine.name == 'postgresql':
fk_name = 'reservations_usage_id_fkey'
# NOTE: MySQL and PostgreSQL Cannot drop the quota_usages table
# until the foreign key is removed. We remove the foreign key first,
# and then we drop the table.
table = Table('reservations', meta, autoload=True)
ref_table = Table('reservations', meta, autoload=True)
params = {'columns': [table.c['usage_id']],
'refcolumns': [ref_table.c['id']],
'name': fk_name}
if fk_name:
fkey = ForeignKeyConstraint(**params)
fkey.drop()
quota_classes = Table('quota_classes', meta, autoload=True)
quota_classes.drop()
quota_usages = Table('quota_usages', meta, autoload=True)
quota_usages.drop()
reservations = Table('reservations', meta, autoload=True)
reservations.drop()
|
apache-2.0
|
[
3,
1898,
6029,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
12810,
492,
12718,
8463,
199,
504,
8335,
492,
9411,
12,
4996,
12,
13686,
199,
504,
8335,
492,
24905,
12,
7225,
12,
2624,
12,
6957,
12,
12718,
421,
199,
318,
10754,
8,
8462,
63,
3908,
304,
272,
3404,
275,
24905,
342,
272,
3404,
14,
3409,
275,
12810,
63,
3908,
339,
327,
7053,
1817,
272,
12132,
63,
2888,
275,
6957,
360,
8848,
63,
2888,
297,
3404,
12,
2079,
4996,
360,
3966,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
2079,
4996,
360,
5334,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
2079,
4996,
360,
6062,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
2079,
4996,
360,
6062,
297,
9411,
8,
981,
63,
5631,
29,
549,
12,
8105,
536,
29,
403,
1826,
2079,
4996,
360,
344,
297,
7225,
1062,
5062,
63,
498,
29,
549,
395,
2079,
4996,
360,
533,
63,
354,
297,
639,
2624,
8,
1267,
29,
2299,
395,
639,
1478,
29,
549,
395,
2079,
4996,
360,
1927,
297,
639,
2624,
8,
1267,
29,
2299,
1826,
2079,
4996,
360,
8726,
63,
3097,
297,
7225,
1062,
7854,
29,
549,
395,
2079,
12896,
63,
3908,
534,
607,
889,
2846,
297,
2079,
12896,
63,
6043,
534,
1624,
24,
297,
2079,
776,
339,
12132,
63,
2888,
14,
981,
342,
339,
12132,
63,
21503,
275,
6957,
360,
8848,
63,
21503,
297,
3404,
12,
586,
4996,
360,
3966,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
5334,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
297,
9411,
8,
981,
63,
5631,
29,
549,
12,
8962,
536,
29,
403,
1826,
586,
4996,
360,
344,
297,
7225,
1062,
5062,
63,
498,
29,
549,
395,
586,
4996,
360,
1715,
63,
344,
297,
1816,
2624,
8,
1267,
29,
2299,
395,
1816,
1478,
29,
549,
395,
586,
4996,
360,
1927,
297,
1816,
2624,
8,
1267,
29,
2299,
1826,
586,
4996,
360,
262,
63,
1180,
297,
7225,
1062,
7854,
29,
797,
395,
586,
4996,
360,
10421,
297,
7225,
1062,
7854,
29,
797,
395,
586,
4996,
360,
8111,
63,
6635,
297,
7225,
1062,
7854,
29,
549,
395,
586,
12896,
63,
3908,
534,
607,
889,
2846,
297,
586,
12896,
63,
6043,
534,
1624,
24,
297,
586,
776,
339,
12132,
63,
21503,
14,
981,
342,
339,
31494,
275,
6957,
360,
264,
12225,
297,
3404,
12,
586,
4996,
360,
3966,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
5334,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
297,
9411,
8,
981,
63,
5631,
29,
549,
12,
8962,
536,
29,
403,
1826,
586,
4996,
360,
344,
297,
7225,
1062,
5062,
63,
498,
29,
549,
395,
586,
4996,
360,
2580,
297,
1816,
2624,
8,
1267,
29,
1344,
395,
1816,
7854,
29,
797,
395,
586,
4996,
360,
3807,
63,
344,
297,
1816,
7225,
1062,
1816,
12718,
360,
8848,
63,
21503,
14,
344,
659,
1816,
7854,
29,
797,
395,
586,
4996,
360,
1715,
63,
344,
297,
1816,
2624,
8,
1267,
29,
2299,
395,
1816,
1478,
29,
549,
395,
586,
4996,
360,
1927,
297,
1816,
2624,
8,
1267,
29,
2299,
1826,
586,
4996,
360,
3136,
297,
7225,
1062,
7854,
29,
797,
395,
586,
4996,
360,
14691,
297,
13686,
8,
7145,
29,
797,
1826,
586,
12896,
63,
3908,
534,
607,
889,
2846,
297,
586,
12896,
63,
6043,
534,
1624,
24,
297,
586,
776,
339,
31494,
14,
981,
342,
421,
199,
318,
32498,
8,
8462,
63,
3908,
304,
272,
3404,
275,
24905,
342,
272,
3404,
14,
3409,
275,
12810,
63,
3908,
339,
14830,
63,
354,
275,
488,
339,
340,
12810,
63,
3908,
14,
354,
508,
283,
8644,
356,
267,
14830,
63,
354,
275,
283,
264,
12225,
63,
1892,
9010,
63,
17,
7,
272,
916,
12810,
63,
3908,
14,
354,
508,
283,
15437,
356,
267,
14830,
63,
354,
275,
283,
264,
12225,
63,
3807,
63,
344,
63,
70,
498,
7,
339,
327,
6944,
26,
11200,
436,
20175,
18435,
5978,
314,
12132,
63,
21503,
1817,
272,
327,
5133,
314,
11608,
790,
365,
4829,
14,
221,
2136,
2813,
314,
11608,
790,
1642,
12,
272,
327,
436,
2066,
781,
5978,
314,
1817,
14,
272,
1817,
275,
6957,
360,
264,
12225,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
2984,
63,
1224,
275,
6957,
360,
264,
12225,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
1862,
275,
791,
3406,
356,
359,
1224,
14,
67,
459,
3807,
63,
344,
2157,
1598,
283,
1121,
3406,
356,
359,
1121,
63,
1224,
14,
67,
459,
344,
2157,
1598,
283,
354,
356,
14830,
63,
354,
93,
339,
340,
14830,
63,
354,
26,
267,
289,
498,
275,
12718,
8463,
3682,
1162,
9,
267,
289,
498,
14,
4824,
342,
339,
12132,
63,
2888,
275,
6957,
360,
8848,
63,
2888,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
12132,
63,
2888,
14,
4824,
342,
339,
12132,
63,
21503,
275,
6957,
360,
8848,
63,
21503,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
12132,
63,
21503,
14,
4824,
342,
339,
31494,
275,
6957,
360,
264,
12225,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
31494,
14,
4824,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6029,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
12810,
492,
12718,
8463,
199,
504,
8335,
492,
9411,
12,
4996,
12,
13686,
199,
504,
8335,
492,
24905,
12,
7225,
12,
2624,
12,
6957,
12,
12718,
421,
199,
318,
10754,
8,
8462,
63,
3908,
304,
272,
3404,
275,
24905,
342,
272,
3404,
14,
3409,
275,
12810,
63,
3908,
339,
327,
7053,
1817,
272,
12132,
63,
2888,
275,
6957,
360,
8848,
63,
2888,
297,
3404,
12,
2079,
4996,
360,
3966,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
2079,
4996,
360,
5334,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
2079,
4996,
360,
6062,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
2079,
4996,
360,
6062,
297,
9411,
8,
981,
63,
5631,
29,
549,
12,
8105,
536,
29,
403,
1826,
2079,
4996,
360,
344,
297,
7225,
1062,
5062,
63,
498,
29,
549,
395,
2079,
4996,
360,
533,
63,
354,
297,
639,
2624,
8,
1267,
29,
2299,
395,
639,
1478,
29,
549,
395,
2079,
4996,
360,
1927,
297,
639,
2624,
8,
1267,
29,
2299,
1826,
2079,
4996,
360,
8726,
63,
3097,
297,
7225,
1062,
7854,
29,
549,
395,
2079,
12896,
63,
3908,
534,
607,
889,
2846,
297,
2079,
12896,
63,
6043,
534,
1624,
24,
297,
2079,
776,
339,
12132,
63,
2888,
14,
981,
342,
339,
12132,
63,
21503,
275,
6957,
360,
8848,
63,
21503,
297,
3404,
12,
586,
4996,
360,
3966,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
5334,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
297,
9411,
8,
981,
63,
5631,
29,
549,
12,
8962,
536,
29,
403,
1826,
586,
4996,
360,
344,
297,
7225,
1062,
5062,
63,
498,
29,
549,
395,
586,
4996,
360,
1715,
63,
344,
297,
1816,
2624,
8,
1267,
29,
2299,
395,
1816,
1478,
29,
549,
395,
586,
4996,
360,
1927,
297,
1816,
2624,
8,
1267,
29,
2299,
1826,
586,
4996,
360,
262,
63,
1180,
297,
7225,
1062,
7854,
29,
797,
395,
586,
4996,
360,
10421,
297,
7225,
1062,
7854,
29,
797,
395,
586,
4996,
360,
8111,
63,
6635,
297,
7225,
1062,
7854,
29,
549,
395,
586,
12896,
63,
3908,
534,
607,
889,
2846,
297,
586,
12896,
63,
6043,
534,
1624,
24,
297,
586,
776,
339,
12132,
63,
21503,
14,
981,
342,
339,
31494,
275,
6957,
360,
264,
12225,
297,
3404,
12,
586,
4996,
360,
3966,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
5334,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
63,
292,
297,
13686,
8,
7145,
29,
797,
1826,
586,
4996,
360,
6062,
297,
9411,
8,
981,
63,
5631,
29,
549,
12,
8962,
536,
29,
403,
1826,
586,
4996,
360,
344,
297,
7225,
1062,
5062,
63,
498,
29,
549,
395,
586,
4996,
360,
2580,
297,
1816,
2624,
8,
1267,
29,
1344,
395,
1816,
7854,
29,
797,
395,
586,
4996,
360,
3807,
63,
344,
297,
1816,
7225,
1062,
1816,
12718,
360,
8848,
63,
21503,
14,
344,
659,
1816,
7854,
29,
797,
395,
586,
4996,
360,
1715,
63,
344,
297,
1816,
2624,
8,
1267,
29,
2299,
395,
1816,
1478,
29,
549,
395,
586,
4996,
360,
1927,
297,
1816,
2624,
8,
1267,
29,
2299,
1826,
586,
4996,
360,
3136,
297,
7225,
1062,
7854,
29,
797,
395,
586,
4996,
360,
14691,
297,
13686,
8,
7145,
29,
797,
1826,
586,
12896,
63,
3908,
534,
607,
889,
2846,
297,
586,
12896,
63,
6043,
534,
1624,
24,
297,
586,
776,
339,
31494,
14,
981,
342,
421,
199,
318,
32498,
8,
8462,
63,
3908,
304,
272,
3404,
275,
24905,
342,
272,
3404,
14,
3409,
275,
12810,
63,
3908,
339,
14830,
63,
354,
275,
488,
339,
340,
12810,
63,
3908,
14,
354,
508,
283,
8644,
356,
267,
14830,
63,
354,
275,
283,
264,
12225,
63,
1892,
9010,
63,
17,
7,
272,
916,
12810,
63,
3908,
14,
354,
508,
283,
15437,
356,
267,
14830,
63,
354,
275,
283,
264,
12225,
63,
3807,
63,
344,
63,
70,
498,
7,
339,
327,
6944,
26,
11200,
436,
20175,
18435,
5978,
314,
12132,
63,
21503,
1817,
272,
327,
5133,
314,
11608,
790,
365,
4829,
14,
221,
2136,
2813,
314,
11608,
790,
1642,
12,
272,
327,
436,
2066,
781,
5978,
314,
1817,
14,
272,
1817,
275,
6957,
360,
264,
12225,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
2984,
63,
1224,
275,
6957,
360,
264,
12225,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
1862,
275,
791,
3406,
356,
359,
1224,
14,
67,
459,
3807,
63,
344,
2157,
1598,
283,
1121,
3406,
356,
359,
1121,
63,
1224,
14,
67,
459,
344,
2157,
1598,
283,
354,
356,
14830,
63,
354,
93,
339,
340,
14830,
63,
354,
26,
267,
289,
498,
275,
12718,
8463,
3682,
1162,
9,
267,
289,
498,
14,
4824,
342,
339,
12132,
63,
2888,
275,
6957,
360,
8848,
63,
2888,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
12132,
63,
2888,
14,
4824,
342,
339,
12132,
63,
21503,
275,
6957,
360,
8848,
63,
21503,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
12132,
63,
21503,
14,
4824,
342,
339,
31494,
275,
6957,
360,
264,
12225,
297,
3404,
12,
2599,
912,
29,
549,
9,
272,
31494,
14,
4824,
342,
199,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tquilian/exeNext
|
exe/engine/lom/lom.py
|
9
|
560188
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated Fri May 10 13:36:48 2013 by generateDS.py version 2.9a.
#
import sys
import getopt
import re as re_
import base64
from datetime import datetime, tzinfo, timedelta
from twisted.spread.jelly import Unjellyable
etree_ = None
Verbose_import_ = False
( XMLParser_import_none, XMLParser_import_lxml,
XMLParser_import_elementtree
) = range(3)
XMLParser_import_library = None
try:
# lxml
from lxml import etree as etree_
XMLParser_import_library = XMLParser_import_lxml
if Verbose_import_:
print("running with lxml.etree")
except ImportError:
try:
# cElementTree from Python 2.5+
import xml.etree.cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree on Python 2.5+")
except ImportError:
try:
# ElementTree from Python 2.5+
import xml.etree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree on Python 2.5+")
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with cElementTree")
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree_
XMLParser_import_library = XMLParser_import_elementtree
if Verbose_import_:
print("running with ElementTree")
except ImportError:
raise ImportError(
"Failed to import ElementTree from any known place")
def parsexml_(*args, **kwargs):
if (XMLParser_import_library == XMLParser_import_lxml and
'parser' not in kwargs):
# Use the lxml ElementTree compatible parser so that, e.g.,
# we ignore comments.
kwargs['parser'] = etree_.ETCompatXMLParser()
doc = etree_.parse(*args, **kwargs)
return doc
#
# User methods
#
# Calls to the methods in these classes are generated by generateDS.py.
# You can replace these methods by re-implementing the following class
# in a module named generatedssuper.py.
try:
from generatedssuper import GeneratedsSuper
except ImportError, exp:
from twisted.spread.jelly import Jellyable, Unjellyable
class GeneratedsSuper(object, Jellyable, Unjellyable):
tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$')
class _FixedOffsetTZ(tzinfo):
def __init__(self, offset, name):
self.__offset = timedelta(minutes = offset)
self.__name = name
def utcoffset(self, dt):
return self.__offset
def tzname(self, dt):
return self.__name
def dst(self, dt):
return None
def gds_format_string(self, input_data, input_name=''):
return input_data
def gds_validate_string(self, input_data, node, input_name=''):
return input_data
def gds_format_base64(self, input_data, input_name=''):
return base64.b64encode(input_data)
def gds_validate_base64(self, input_data, node, input_name=''):
return input_data
def gds_format_integer(self, input_data, input_name=''):
return '%d' % input_data
def gds_validate_integer(self, input_data, node, input_name=''):
return input_data
def gds_format_integer_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_integer_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
fvalue = float(value)
except (TypeError, ValueError), exp:
raise_parse_error(node, 'Requires sequence of integers')
return input_data
def gds_format_float(self, input_data, input_name=''):
return '%f' % input_data
def gds_validate_float(self, input_data, node, input_name=''):
return input_data
def gds_format_float_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_float_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
fvalue = float(value)
except (TypeError, ValueError), exp:
raise_parse_error(node, 'Requires sequence of floats')
return input_data
def gds_format_double(self, input_data, input_name=''):
return '%e' % input_data
def gds_validate_double(self, input_data, node, input_name=''):
return input_data
def gds_format_double_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_double_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
try:
fvalue = float(value)
except (TypeError, ValueError), exp:
raise_parse_error(node, 'Requires sequence of doubles')
return input_data
def gds_format_boolean(self, input_data, input_name=''):
return ('%s' % input_data).lower()
def gds_validate_boolean(self, input_data, node, input_name=''):
return input_data
def gds_format_boolean_list(self, input_data, input_name=''):
return '%s' % input_data
def gds_validate_boolean_list(self, input_data, node, input_name=''):
values = input_data.split()
for value in values:
if value not in ('true', '1', 'false', '0', ):
raise_parse_error(node,
'Requires sequence of booleans '
'("true", "1", "false", "0")')
return input_data
def gds_validate_datetime(self, input_data, node, input_name=''):
return input_data
def gds_format_datetime(self, input_data, input_name=''):
if input_data.microsecond == 0:
_svalue = input_data.strftime('%Y-%m-%dT%H:%M:%S')
else:
_svalue = input_data.strftime('%Y-%m-%dT%H:%M:%S.%f')
if input_data.tzinfo is not None:
tzoff = input_data.tzinfo.utcoffset(input_data)
if tzoff is not None:
total_seconds = tzoff.seconds + (86400 * tzoff.days)
if total_seconds == 0:
_svalue += 'Z'
else:
if total_seconds < 0:
_svalue += '-'
total_seconds *= -1
else:
_svalue += '+'
hours = total_seconds // 3600
minutes = (total_seconds - (hours * 3600)) // 60
_svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
return _svalue
def gds_parse_datetime(self, input_data, node, input_name=''):
tz = None
if input_data[-1] == 'Z':
tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
input_data = input_data[:-1]
else:
results = GeneratedsSuper.tzoff_pattern.search(input_data)
if results is not None:
tzoff_parts = results.group(2).split(':')
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
if results.group(1) == '-':
tzoff *= -1
tz = GeneratedsSuper._FixedOffsetTZ(
tzoff, results.group(0))
input_data = input_data[:-6]
if len(input_data.split('.')) > 1:
dt = datetime.strptime(
input_data, '%Y-%m-%dT%H:%M:%S.%f')
else:
dt = datetime.strptime(
input_data, '%Y-%m-%dT%H:%M:%S')
return dt.replace(tzinfo = tz)
def gds_validate_date(self, input_data, node, input_name=''):
return input_data
def gds_format_date(self, input_data, input_name=''):
_svalue = input_data.strftime('%Y-%m-%d')
if input_data.tzinfo is not None:
tzoff = input_data.tzinfo.utcoffset(input_data)
if tzoff is not None:
total_seconds = tzoff.seconds + (86400 * tzoff.days)
if total_seconds == 0:
_svalue += 'Z'
else:
if total_seconds < 0:
_svalue += '-'
total_seconds *= -1
else:
_svalue += '+'
hours = total_seconds // 3600
minutes = (total_seconds - (hours * 3600)) // 60
_svalue += '{0:02d}:{1:02d}'.format(hours, minutes)
return _svalue
def gds_parse_date(self, input_data, node, input_name=''):
tz = None
if input_data[-1] == 'Z':
tz = GeneratedsSuper._FixedOffsetTZ(0, 'GMT')
input_data = input_data[:-1]
else:
results = GeneratedsSuper.tzoff_pattern.search(input_data)
if results is not None:
tzoff_parts = results.group(2).split(':')
tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])
if results.group(1) == '-':
tzoff *= -1
tz = GeneratedsSuper._FixedOffsetTZ(
tzoff, results.group(0))
input_data = input_data[:-6]
return datetime.strptime(input_data,
'%Y-%m-%d').replace(tzinfo = tz)
def gds_str_lower(self, instring):
return instring.lower()
def get_path_(self, node):
path_list = []
self.get_path_list_(node, path_list)
path_list.reverse()
path = '/'.join(path_list)
return path
Tag_strip_pattern_ = re_.compile(r'\{.*\}')
def get_path_list_(self, node, path_list):
if node is None:
return
tag = GeneratedsSuper.Tag_strip_pattern_.sub('', node.tag)
if tag:
path_list.append(tag)
self.get_path_list_(node.getparent(), path_list)
def get_class_obj_(self, node, default_class=None):
class_obj1 = default_class
if 'xsi' in node.nsmap:
classname = node.get('{%s}type' % node.nsmap['xsi'])
if classname is not None:
names = classname.split(':')
if len(names) == 2:
classname = names[1]
class_obj2 = globals().get(classname)
if class_obj2 is not None:
class_obj1 = class_obj2
return class_obj1
def gds_build_any(self, node, type_name=None):
return None
#
# If you have installed IPython you can uncomment and use the following.
# IPython is available from http://ipython.scipy.org/.
#
## from IPython.Shell import IPShellEmbed
## args = ''
## ipshell = IPShellEmbed(args,
## banner = 'Dropping into IPython',
## exit_msg = 'Leaving Interpreter, back to program.')
# Then use the following line where and when you want to drop into the
# IPython shell:
# ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit')
#
# Globals
#
ExternalEncoding = 'UTF-8'
Tag_pattern_ = re_.compile(r'({.*})?(.*)')
String_cleanup_pat_ = re_.compile(r"[\n\r\s]+")
Namespace_extract_pat_ = re_.compile(r'{(.*)}(.*)')
#
# Support/utility functions.
#
def showIndent(outfile, level, pretty_print=True):
if pretty_print:
for idx in range(level):
outfile.write(' ')
def quote_xml(inStr):
if not inStr:
return ''
s1 = (isinstance(inStr, basestring) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
return s1
def quote_attrib(inStr):
s1 = (isinstance(inStr, basestring) and inStr or
'%s' % inStr)
s1 = s1.replace('&', '&')
s1 = s1.replace('<', '<')
s1 = s1.replace('>', '>')
if '"' in s1:
if "'" in s1:
s1 = '"%s"' % s1.replace('"', """)
else:
s1 = "'%s'" % s1
else:
s1 = '"%s"' % s1
return s1
def quote_python(inStr):
s1 = inStr
if s1.find("'") == -1:
if s1.find('\n') == -1:
return "'%s'" % s1
else:
return "'''%s'''" % s1
else:
if s1.find('"') != -1:
s1 = s1.replace('"', '\\"')
if s1.find('\n') == -1:
return '"%s"' % s1
else:
return '"""%s"""' % s1
def get_all_text_(node):
if node.text is not None:
text = node.text
else:
text = ''
for child in node:
if child.tail is not None:
text += child.tail
return text
def find_attr_value_(attr_name, node):
attrs = node.attrib
attr_parts = attr_name.split(':')
value = None
if len(attr_parts) == 1:
value = attrs.get(attr_name)
elif len(attr_parts) == 2:
prefix, name = attr_parts
namespace = node.nsmap.get(prefix)
if namespace is not None:
value = attrs.get('{%s}%s' % (namespace, name, ))
return value
class GDSParseError(Exception):
pass
def raise_parse_error(node, msg):
if XMLParser_import_library == XMLParser_import_lxml:
msg = '%s (element %s/line %d)' % (
msg, node.tag, node.sourceline, )
else:
msg = '%s (element %s)' % (msg, node.tag, )
raise GDSParseError(msg)
class MixedContainer:
# Constants for category:
CategoryNone = 0
CategoryText = 1
CategorySimple = 2
CategoryComplex = 3
# Constants for content_type:
TypeNone = 0
TypeText = 1
TypeString = 2
TypeInteger = 3
TypeFloat = 4
TypeDecimal = 5
TypeDouble = 6
TypeBoolean = 7
TypeBase64 = 8
def __init__(self, category, content_type, name, value):
self.category = category
self.content_type = content_type
self.name = name
self.value = value
def getCategory(self):
return self.category
def getContenttype(self, content_type):
return self.content_type
def getValue(self):
return self.value
def getName(self):
return self.name
def export(self, outfile, level, name, namespace, pretty_print=True):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
outfile.write(self.value)
elif self.category == MixedContainer.CategorySimple:
self.exportSimple(outfile, level, name)
else: # category == MixedContainer.CategoryComplex
self.value.export(outfile, level, namespace, name, pretty_print)
def exportSimple(self, outfile, level, name):
if self.content_type == MixedContainer.TypeString:
outfile.write('<%s>%s</%s>' %
(self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeInteger or \
self.content_type == MixedContainer.TypeBoolean:
outfile.write('<%s>%d</%s>' %
(self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeFloat or \
self.content_type == MixedContainer.TypeDecimal:
outfile.write('<%s>%f</%s>' %
(self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeDouble:
outfile.write('<%s>%g</%s>' %
(self.name, self.value, self.name))
elif self.content_type == MixedContainer.TypeBase64:
outfile.write('<%s>%s</%s>' %
(self.name, base64.b64encode(self.value), self.name))
def to_etree(self, element):
if self.category == MixedContainer.CategoryText:
# Prevent exporting empty content as empty lines.
if self.value.strip():
if len(element) > 0:
if element[-1].tail is None:
element[-1].tail = self.value
else:
element[-1].tail += self.value
else:
if element.text is None:
element.text = self.value
else:
element.text += self.value
elif self.category == MixedContainer.CategorySimple:
subelement = etree_.SubElement(element, '%s' % self.name)
subelement.text = self.to_etree_simple()
else: # category == MixedContainer.CategoryComplex
self.value.to_etree(element)
def to_etree_simple(self):
if self.content_type == MixedContainer.TypeString:
text = self.value
elif (self.content_type == MixedContainer.TypeInteger or
self.content_type == MixedContainer.TypeBoolean):
text = '%d' % self.value
elif (self.content_type == MixedContainer.TypeFloat or
self.content_type == MixedContainer.TypeDecimal):
text = '%f' % self.value
elif self.content_type == MixedContainer.TypeDouble:
text = '%g' % self.value
elif self.content_type == MixedContainer.TypeBase64:
text = '%s' % base64.b64encode(self.value)
return text
def exportLiteral(self, outfile, level, name):
if self.category == MixedContainer.CategoryText:
showIndent(outfile, level)
outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n'
% (self.category, self.content_type, self.name, self.value))
elif self.category == MixedContainer.CategorySimple:
showIndent(outfile, level)
outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n'
% (self.category, self.content_type, self.name, self.value))
else: # category == MixedContainer.CategoryComplex
showIndent(outfile, level)
outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \
(self.category, self.content_type, self.name,))
self.value.exportLiteral(outfile, level + 1)
showIndent(outfile, level)
outfile.write(')\n')
class MemberSpec_(object):
def __init__(self, name='', data_type='', container=0):
self.name = name
self.data_type = data_type
self.container = container
def set_name(self, name): self.name = name
def get_name(self): return self.name
def set_data_type(self, data_type): self.data_type = data_type
def get_data_type_chain(self): return self.data_type
def get_data_type(self):
if isinstance(self.data_type, list):
if len(self.data_type) > 0:
return self.data_type[-1]
else:
return 'xs:string'
else:
return self.data_type
def set_container(self, container): self.container = container
def get_container(self): return self.container
def _cast(typ, value):
if typ is None or value is None:
return value
return typ(value)
#
# Data representation classes.
#
class LanguageId(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, valueOf_=None, extensiontype_=None):
self.valueOf_ = valueOf_
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if LanguageId.subclass:
return LanguageId.subclass(*args_, **kwargs_)
else:
return LanguageId(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='LanguageId', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='LanguageId')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='LanguageId'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='LanguageId', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='LanguageId'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class LanguageId
class VCard(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, valueOf_=None, extensiontype_=None):
self.valueOf_ = valueOf_
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if VCard.subclass:
return VCard.subclass(*args_, **kwargs_)
else:
return VCard(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='VCard', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='VCard')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='VCard'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='VCard', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='VCard'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class VCard
class LanguageString(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, string=None, extensiontype_=None):
if string is None:
self.string = []
else:
self.string = string
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if LanguageString.subclass:
return LanguageString.subclass(*args_, **kwargs_)
else:
return LanguageString(*args_, **kwargs_)
factory = staticmethod(factory)
def get_string(self): return self.string
def set_string(self, string): self.string = string
def add_string(self, value): self.string.append(value)
def insert_string(self, index, value): self.string[index] = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.string
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='LanguageString', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='LanguageString')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='LanguageString'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='LanguageString', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
for string_ in self.string:
string_.export(outfile, level, namespace_, name_='string', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='LanguageString'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write('string=[\n')
level += 1
for string_ in self.string:
showIndent(outfile, level)
outfile.write('model_.LangString(\n')
string_.exportLiteral(outfile, level, name_='LangString')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'string':
obj_ = LangString.factory()
obj_.build(child_)
self.string.append(obj_)
# end class LanguageString
class LangString(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, language=None, valueOf_=None):
self.language = _cast(None, language)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if LangString.subclass:
return LangString.subclass(*args_, **kwargs_)
else:
return LangString(*args_, **kwargs_)
factory = staticmethod(factory)
def get_language(self): return self.language
def set_language(self, language): self.language = language
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='LangString', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='LangString')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='LangString'):
if self.language is not None and 'language' not in already_processed:
already_processed.add('language')
outfile.write(' language=%s' % (self.gds_format_string(quote_attrib(self.language).encode(ExternalEncoding), input_name='language'), ))
def exportChildren(self, outfile, level, namespace_='', name_='LangString', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='LangString'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.language is not None and 'language' not in already_processed:
already_processed.add('language')
showIndent(outfile, level)
outfile.write('language = "%s",\n' % (self.language,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('language', node)
if value is not None and 'language' not in already_processed:
already_processed.add('language')
self.language = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class LangString
class DateTime(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, dateTime=None, description=None, extensiontype_=None):
self.dateTime = dateTime
self.description = description
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if DateTime.subclass:
return DateTime.subclass(*args_, **kwargs_)
else:
return DateTime(*args_, **kwargs_)
factory = staticmethod(factory)
def get_dateTime(self): return self.dateTime
def set_dateTime(self, dateTime): self.dateTime = dateTime
def get_description(self): return self.description
def set_description(self, description): self.description = description
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.dateTime is not None or
self.description is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='DateTime', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='DateTime')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='DateTime'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='DateTime', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.dateTime is not None:
self.dateTime.export(outfile, level, namespace_, name_='dateTime', pretty_print=pretty_print)
if self.description is not None:
self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='DateTime'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.dateTime is not None:
showIndent(outfile, level)
outfile.write('dateTime=model_.DateTimeValue(\n')
self.dateTime.exportLiteral(outfile, level, name_='dateTime')
showIndent(outfile, level)
outfile.write('),\n')
if self.description is not None:
showIndent(outfile, level)
outfile.write('description=model_.description(\n')
self.description.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'dateTime':
obj_ = DateTimeValue.factory()
obj_.build(child_)
self.set_dateTime(obj_)
elif nodeName_ == 'description':
obj_ = description.factory()
obj_.build(child_)
self.set_description(obj_)
# end class DateTime
class DateTimeValue(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if DateTimeValue.subclass:
return DateTimeValue.subclass(*args_, **kwargs_)
else:
return DateTimeValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='DateTimeValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='DateTimeValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='DateTimeValue'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='DateTimeValue', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='DateTimeValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class DateTimeValue
class Duration(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, duration=None, description=None, extensiontype_=None):
self.duration = duration
self.description = description
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if Duration.subclass:
return Duration.subclass(*args_, **kwargs_)
else:
return Duration(*args_, **kwargs_)
factory = staticmethod(factory)
def get_duration(self): return self.duration
def set_duration(self, duration): self.duration = duration
def get_description(self): return self.description
def set_description(self, description): self.description = description
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.duration is not None or
self.description is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='Duration', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='Duration')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='Duration'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='Duration', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.duration is not None:
self.duration.export(outfile, level, namespace_, name_='duration', pretty_print=pretty_print)
if self.description is not None:
self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='Duration'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.duration is not None:
showIndent(outfile, level)
outfile.write('duration=model_.DurationValue(\n')
self.duration.exportLiteral(outfile, level, name_='duration')
showIndent(outfile, level)
outfile.write('),\n')
if self.description is not None:
showIndent(outfile, level)
outfile.write('description=model_.description(\n')
self.description.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'duration':
obj_ = DurationValue.factory()
obj_.build(child_)
self.set_duration(obj_)
elif nodeName_ == 'description':
obj_ = description.factory()
obj_.build(child_)
self.set_description(obj_)
# end class Duration
class DurationValue(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if DurationValue.subclass:
return DurationValue.subclass(*args_, **kwargs_)
else:
return DurationValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='DurationValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='DurationValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='DurationValue'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='DurationValue', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='DurationValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class DurationValue
class lom(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, general=None, lifeCycle=None, metaMetadata=None, technical=None, educational=None, rights=None, relation=None, annotation=None, classification=None):
self.general = general
self.lifeCycle = lifeCycle
self.metaMetadata = metaMetadata
self.technical = technical
if educational is None:
self.educational = []
else:
self.educational = educational
self.rights = rights
if relation is None:
self.relation = []
else:
self.relation = relation
if annotation is None:
self.annotation = []
else:
self.annotation = annotation
if classification is None:
self.classification = []
else:
self.classification = classification
def factory(*args_, **kwargs_):
if lom.subclass:
return lom.subclass(*args_, **kwargs_)
else:
return lom(*args_, **kwargs_)
factory = staticmethod(factory)
def get_general(self): return self.general
def set_general(self, general): self.general = general
def get_lifeCycle(self): return self.lifeCycle
def set_lifeCycle(self, lifeCycle): self.lifeCycle = lifeCycle
def get_metaMetadata(self): return self.metaMetadata
def set_metaMetadata(self, metaMetadata): self.metaMetadata = metaMetadata
def get_technical(self): return self.technical
def set_technical(self, technical): self.technical = technical
def get_educational(self): return self.educational
def set_educational(self, educational): self.educational = educational
def add_educational(self, value): self.educational.append(value)
def insert_educational(self, index, value): self.educational[index] = value
def get_rights(self): return self.rights
def set_rights(self, rights): self.rights = rights
def get_relation(self): return self.relation
def set_relation(self, relation): self.relation = relation
def add_relation(self, value): self.relation.append(value)
def insert_relation(self, index, value): self.relation[index] = value
def get_annotation(self): return self.annotation
def set_annotation(self, annotation): self.annotation = annotation
def add_annotation(self, value): self.annotation.append(value)
def insert_annotation(self, index, value): self.annotation[index] = value
def get_classification(self): return self.classification
def set_classification(self, classification): self.classification = classification
def add_classification(self, value): self.classification.append(value)
def insert_classification(self, index, value): self.classification[index] = value
def hasContent_(self):
if (
self.general is not None or
self.lifeCycle is not None or
self.metaMetadata is not None or
self.technical is not None or
self.educational or
self.rights is not None or
self.relation or
self.annotation or
self.classification
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='lom', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='lom')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='lom'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='lom', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.general is not None:
self.general.export(outfile, level, namespace_, name_='general', pretty_print=pretty_print)
if self.lifeCycle is not None:
self.lifeCycle.export(outfile, level, namespace_, name_='lifeCycle', pretty_print=pretty_print)
if self.metaMetadata is not None:
self.metaMetadata.export(outfile, level, namespace_, name_='metaMetadata', pretty_print=pretty_print)
if self.technical is not None:
self.technical.export(outfile, level, namespace_, name_='technical', pretty_print=pretty_print)
for educational_ in self.educational:
educational_.export(outfile, level, namespace_, name_='educational', pretty_print=pretty_print)
if self.rights is not None:
self.rights.export(outfile, level, namespace_, name_='rights', pretty_print=pretty_print)
for relation_ in self.relation:
relation_.export(outfile, level, namespace_, name_='relation', pretty_print=pretty_print)
for annotation_ in self.annotation:
annotation_.export(outfile, level, namespace_, name_='annotation', pretty_print=pretty_print)
for classification_ in self.classification:
classification_.export(outfile, level, namespace_, name_='classification', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='lom'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.general is not None:
showIndent(outfile, level)
outfile.write('general=model_.general(\n')
self.general.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.lifeCycle is not None:
showIndent(outfile, level)
outfile.write('lifeCycle=model_.lifeCycle(\n')
self.lifeCycle.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.metaMetadata is not None:
showIndent(outfile, level)
outfile.write('metaMetadata=model_.metaMetadata(\n')
self.metaMetadata.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.technical is not None:
showIndent(outfile, level)
outfile.write('technical=model_.technical(\n')
self.technical.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('educational=[\n')
level += 1
for educational_ in self.educational:
showIndent(outfile, level)
outfile.write('model_.educational(\n')
educational_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.rights is not None:
showIndent(outfile, level)
outfile.write('rights=model_.rights(\n')
self.rights.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('relation=[\n')
level += 1
for relation_ in self.relation:
showIndent(outfile, level)
outfile.write('model_.relation(\n')
relation_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('annotation=[\n')
level += 1
for annotation_ in self.annotation:
showIndent(outfile, level)
outfile.write('model_.annotation(\n')
annotation_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('classification=[\n')
level += 1
for classification_ in self.classification:
showIndent(outfile, level)
outfile.write('model_.classification(\n')
classification_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'general':
obj_ = general.factory()
obj_.build(child_)
self.set_general(obj_)
elif nodeName_ == 'lifeCycle':
obj_ = lifeCycle.factory()
obj_.build(child_)
self.set_lifeCycle(obj_)
elif nodeName_ == 'metaMetadata':
obj_ = metaMetadata.factory()
obj_.build(child_)
self.set_metaMetadata(obj_)
elif nodeName_ == 'technical':
obj_ = technical.factory()
obj_.build(child_)
self.set_technical(obj_)
elif nodeName_ == 'educational':
obj_ = educational.factory()
obj_.build(child_)
self.educational.append(obj_)
elif nodeName_ == 'rights':
obj_ = rights.factory()
obj_.build(child_)
self.set_rights(obj_)
elif nodeName_ == 'relation':
obj_ = relation.factory()
obj_.build(child_)
self.relation.append(obj_)
elif nodeName_ == 'annotation':
obj_ = annotation.factory()
obj_.build(child_)
self.annotation.append(obj_)
elif nodeName_ == 'classification':
obj_ = classification.factory()
obj_.build(child_)
self.classification.append(obj_)
# end class lom
class general(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, identifier=None, title=None, language=None, description=None, keyword=None, coverage=None, structure=None, aggregationLevel=None):
self.uniqueElementName = _cast(None, uniqueElementName)
if identifier is None:
self.identifier = []
else:
self.identifier = identifier
self.title = title
if language is None:
self.language = []
else:
self.language = language
if description is None:
self.description = []
else:
self.description = description
if keyword is None:
self.keyword = []
else:
self.keyword = keyword
if coverage is None:
self.coverage = []
else:
self.coverage = coverage
self.structure = structure
self.aggregationLevel = aggregationLevel
def factory(*args_, **kwargs_):
if general.subclass:
return general.subclass(*args_, **kwargs_)
else:
return general(*args_, **kwargs_)
factory = staticmethod(factory)
def get_identifier(self): return self.identifier
def set_identifier(self, identifier): self.identifier = identifier
def add_identifier(self, value): self.identifier.append(value)
def insert_identifier(self, index, value): self.identifier[index] = value
def get_title(self): return self.title
def set_title(self, title): self.title = title
def get_language(self): return self.language
def set_language(self, language): self.language = language
def add_language(self, value): self.language.append(value)
def insert_language(self, index, value): self.language[index] = value
def get_description(self): return self.description
def set_description(self, description): self.description = description
def add_description(self, value): self.description.append(value)
def insert_description(self, index, value): self.description[index] = value
def get_keyword(self): return self.keyword
def set_keyword(self, keyword): self.keyword = keyword
def add_keyword(self, value): self.keyword.append(value)
def insert_keyword(self, index, value): self.keyword[index] = value
def get_coverage(self): return self.coverage
def set_coverage(self, coverage): self.coverage = coverage
def add_coverage(self, value): self.coverage.append(value)
def insert_coverage(self, index, value): self.coverage[index] = value
def get_structure(self): return self.structure
def set_structure(self, structure): self.structure = structure
def get_aggregationLevel(self): return self.aggregationLevel
def set_aggregationLevel(self, aggregationLevel): self.aggregationLevel = aggregationLevel
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.identifier or
self.title is not None or
self.language or
self.description or
self.keyword or
self.coverage or
self.structure is not None or
self.aggregationLevel is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='general', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='general')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='general'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='general', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
for identifier_ in self.identifier:
identifier_.export(outfile, level, namespace_, name_='identifier', pretty_print=pretty_print)
if self.title is not None:
self.title.export(outfile, level, namespace_, name_='title', pretty_print=pretty_print)
for language_ in self.language:
language_.export(outfile, level, namespace_, name_='language', pretty_print=pretty_print)
for description_ in self.description:
description_.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
for keyword_ in self.keyword:
keyword_.export(outfile, level, namespace_, name_='keyword', pretty_print=pretty_print)
for coverage_ in self.coverage:
coverage_.export(outfile, level, namespace_, name_='coverage', pretty_print=pretty_print)
if self.structure is not None:
self.structure.export(outfile, level, namespace_, name_='structure', pretty_print=pretty_print)
if self.aggregationLevel is not None:
self.aggregationLevel.export(outfile, level, namespace_, name_='aggregationLevel', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='general'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write('identifier=[\n')
level += 1
for identifier_ in self.identifier:
showIndent(outfile, level)
outfile.write('model_.identifier(\n')
identifier_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.title is not None:
showIndent(outfile, level)
outfile.write('title=model_.title(\n')
self.title.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('language=[\n')
level += 1
for language_ in self.language:
showIndent(outfile, level)
outfile.write('model_.LanguageId(\n')
language_.exportLiteral(outfile, level, name_='LanguageId')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('description=[\n')
level += 1
for description_ in self.description:
showIndent(outfile, level)
outfile.write('model_.LanguageString(\n')
description_.exportLiteral(outfile, level, name_='LanguageString')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('keyword=[\n')
level += 1
for keyword_ in self.keyword:
showIndent(outfile, level)
outfile.write('model_.keyword(\n')
keyword_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('coverage=[\n')
level += 1
for coverage_ in self.coverage:
showIndent(outfile, level)
outfile.write('model_.coverage(\n')
coverage_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.structure is not None:
showIndent(outfile, level)
outfile.write('structure=model_.structure(\n')
self.structure.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.aggregationLevel is not None:
showIndent(outfile, level)
outfile.write('aggregationLevel=model_.aggregationLevel(\n')
self.aggregationLevel.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'identifier':
obj_ = identifier.factory()
obj_.build(child_)
self.identifier.append(obj_)
elif nodeName_ == 'title':
obj_ = title.factory()
obj_.build(child_)
self.set_title(obj_)
elif nodeName_ == 'language':
class_obj_ = self.get_class_obj_(child_, LanguageId)
obj_ = class_obj_.factory()
obj_.build(child_)
self.language.append(obj_)
elif nodeName_ == 'description':
class_obj_ = self.get_class_obj_(child_, LanguageString)
obj_ = class_obj_.factory()
obj_.build(child_)
self.description.append(obj_)
elif nodeName_ == 'keyword':
obj_ = keyword.factory()
obj_.build(child_)
self.keyword.append(obj_)
elif nodeName_ == 'coverage':
obj_ = coverage.factory()
obj_.build(child_)
self.coverage.append(obj_)
elif nodeName_ == 'structure':
class_obj_ = self.get_class_obj_(child_, structure)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_structure(obj_)
elif nodeName_ == 'aggregationLevel':
class_obj_ = self.get_class_obj_(child_, aggregationLevel)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_aggregationLevel(obj_)
# end class general
class identifier(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, catalog=None, entry=None):
self.catalog = catalog
self.entry = entry
def factory(*args_, **kwargs_):
if identifier.subclass:
return identifier.subclass(*args_, **kwargs_)
else:
return identifier(*args_, **kwargs_)
factory = staticmethod(factory)
def get_catalog(self): return self.catalog
def set_catalog(self, catalog): self.catalog = catalog
def get_entry(self): return self.entry
def set_entry(self, entry): self.entry = entry
def hasContent_(self):
if (
self.catalog is not None or
self.entry is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='identifier', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='identifier')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='identifier'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='identifier', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.catalog is not None:
self.catalog.export(outfile, level, namespace_, name_='catalog', pretty_print=pretty_print)
if self.entry is not None:
self.entry.export(outfile, level, namespace_, name_='entry', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='identifier'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.catalog is not None:
showIndent(outfile, level)
outfile.write('catalog=model_.catalog(\n')
self.catalog.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.entry is not None:
showIndent(outfile, level)
outfile.write('entry=model_.entry(\n')
self.entry.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'catalog':
obj_ = catalog.factory()
obj_.build(child_)
self.set_catalog(obj_)
elif nodeName_ == 'entry':
obj_ = entry.factory()
obj_.build(child_)
self.set_entry(obj_)
# end class identifier
class catalog(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if catalog.subclass:
return catalog.subclass(*args_, **kwargs_)
else:
return catalog(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='catalog', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='catalog')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='catalog'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='catalog', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='catalog'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class catalog
class entry(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if entry.subclass:
return entry.subclass(*args_, **kwargs_)
else:
return entry(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='entry', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='entry')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='entry'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='entry', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='entry'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class entry
class title(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None, uniqueElementName=None):
super(title, self).__init__(string, )
self.uniqueElementName = _cast(None, uniqueElementName)
pass
def factory(*args_, **kwargs_):
if title.subclass:
return title.subclass(*args_, **kwargs_)
else:
return title(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(title, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='title', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='title')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='title'):
super(title, self).exportAttributes(outfile, level, already_processed, namespace_, name_='title')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='title', fromsubclass_=False, pretty_print=True):
super(title, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='title'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(title, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(title, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(title, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(title, self).buildChildren(child_, node, nodeName_, True)
pass
# end class title
class language(LanguageId):
subclass = None
superclass = LanguageId
def __init__(self, valueOf_=None):
super(language, self).__init__(valueOf_, )
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if language.subclass:
return language.subclass(*args_, **kwargs_)
else:
return language(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(language, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='language', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='language')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='language'):
super(language, self).exportAttributes(outfile, level, already_processed, namespace_, name_='language')
def exportChildren(self, outfile, level, namespace_='', name_='language', fromsubclass_=False, pretty_print=True):
super(language, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
pass
def exportLiteral(self, outfile, level, name_='language'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(language, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(language, self).exportLiteralChildren(outfile, level, name_)
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(language, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class language
class keyword(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None):
super(keyword, self).__init__(string, )
pass
def factory(*args_, **kwargs_):
if keyword.subclass:
return keyword.subclass(*args_, **kwargs_)
else:
return keyword(*args_, **kwargs_)
factory = staticmethod(factory)
def hasContent_(self):
if (
super(keyword, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='keyword', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='keyword')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='keyword'):
super(keyword, self).exportAttributes(outfile, level, already_processed, namespace_, name_='keyword')
def exportChildren(self, outfile, level, namespace_='', name_='keyword', fromsubclass_=False, pretty_print=True):
super(keyword, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='keyword'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(keyword, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(keyword, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(keyword, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(keyword, self).buildChildren(child_, node, nodeName_, True)
pass
# end class keyword
class coverage(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None):
super(coverage, self).__init__(string, )
pass
def factory(*args_, **kwargs_):
if coverage.subclass:
return coverage.subclass(*args_, **kwargs_)
else:
return coverage(*args_, **kwargs_)
factory = staticmethod(factory)
def hasContent_(self):
if (
super(coverage, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='coverage', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='coverage')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='coverage'):
super(coverage, self).exportAttributes(outfile, level, already_processed, namespace_, name_='coverage')
def exportChildren(self, outfile, level, namespace_='', name_='coverage', fromsubclass_=False, pretty_print=True):
super(coverage, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='coverage'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(coverage, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(coverage, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(coverage, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(coverage, self).buildChildren(child_, node, nodeName_, True)
pass
# end class coverage
class lifeCycle(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, version=None, status=None, contribute=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.version = version
self.status = status
if contribute is None:
self.contribute = []
else:
self.contribute = contribute
def factory(*args_, **kwargs_):
if lifeCycle.subclass:
return lifeCycle.subclass(*args_, **kwargs_)
else:
return lifeCycle(*args_, **kwargs_)
factory = staticmethod(factory)
def get_version(self): return self.version
def set_version(self, version): self.version = version
def get_status(self): return self.status
def set_status(self, status): self.status = status
def get_contribute(self): return self.contribute
def set_contribute(self, contribute): self.contribute = contribute
def add_contribute(self, value): self.contribute.append(value)
def insert_contribute(self, index, value): self.contribute[index] = value
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.version is not None or
self.status is not None or
self.contribute
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='lifeCycle', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='lifeCycle')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='lifeCycle'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='lifeCycle', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.version is not None:
self.version.export(outfile, level, namespace_, name_='version', pretty_print=pretty_print)
if self.status is not None:
self.status.export(outfile, level, namespace_, name_='status', pretty_print=pretty_print)
for contribute_ in self.contribute:
contribute_.export(outfile, level, namespace_, name_='contribute', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='lifeCycle'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
if self.version is not None:
showIndent(outfile, level)
outfile.write('version=model_.version(\n')
self.version.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.status is not None:
showIndent(outfile, level)
outfile.write('status=model_.status(\n')
self.status.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('contribute=[\n')
level += 1
for contribute_ in self.contribute:
showIndent(outfile, level)
outfile.write('model_.contribute(\n')
contribute_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'version':
obj_ = version.factory()
obj_.build(child_)
self.set_version(obj_)
elif nodeName_ == 'status':
class_obj_ = self.get_class_obj_(child_, status)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_status(obj_)
elif nodeName_ == 'contribute':
obj_ = contribute.factory()
obj_.build(child_)
self.contribute.append(obj_)
# end class lifeCycle
class version(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None, uniqueElementName=None):
super(version, self).__init__(string, )
self.uniqueElementName = _cast(None, uniqueElementName)
pass
def factory(*args_, **kwargs_):
if version.subclass:
return version.subclass(*args_, **kwargs_)
else:
return version(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(version, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='version', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='version')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='version'):
super(version, self).exportAttributes(outfile, level, already_processed, namespace_, name_='version')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='version', fromsubclass_=False, pretty_print=True):
super(version, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='version'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(version, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(version, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(version, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(version, self).buildChildren(child_, node, nodeName_, True)
pass
# end class version
class contribute(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, role=None, entity=None, date=None):
self.role = role
if entity is None:
self.entity = []
else:
self.entity = entity
self.date = date
def factory(*args_, **kwargs_):
if contribute.subclass:
return contribute.subclass(*args_, **kwargs_)
else:
return contribute(*args_, **kwargs_)
factory = staticmethod(factory)
def get_role(self): return self.role
def set_role(self, role): self.role = role
def get_entity(self): return self.entity
def set_entity(self, entity): self.entity = entity
def add_entity(self, value): self.entity.append(value)
def insert_entity(self, index, value): self.entity[index] = value
def get_date(self): return self.date
def set_date(self, date): self.date = date
def hasContent_(self):
if (
self.role is not None or
self.entity or
self.date is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='contribute', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='contribute')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='contribute'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='contribute', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.role is not None:
self.role.export(outfile, level, namespace_, name_='role', pretty_print=pretty_print)
for entity_ in self.entity:
entity_.export(outfile, level, namespace_, name_='entity', pretty_print=pretty_print)
if self.date is not None:
self.date.export(outfile, level, namespace_, name_='date', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='contribute'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.role is not None:
showIndent(outfile, level)
outfile.write('role=model_.role(\n')
self.role.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('entity=[\n')
level += 1
for entity_ in self.entity:
showIndent(outfile, level)
outfile.write('model_.VCard(\n')
entity_.exportLiteral(outfile, level, name_='VCard')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.date is not None:
showIndent(outfile, level)
outfile.write('date=model_.date(\n')
self.date.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'role':
class_obj_ = self.get_class_obj_(child_, role)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_role(obj_)
elif nodeName_ == 'entity':
class_obj_ = self.get_class_obj_(child_, VCard)
obj_ = class_obj_.factory()
obj_.build(child_)
self.entity.append(obj_)
elif nodeName_ == 'date':
obj_ = date.factory()
obj_.build(child_)
self.set_date(obj_)
# end class contribute
class date(DateTime):
subclass = None
superclass = DateTime
def __init__(self, dateTime=None, description=None, uniqueElementName=None, valueOf_=None):
super(date, self).__init__(dateTime, description, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if date.subclass:
return date.subclass(*args_, **kwargs_)
else:
return date(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(date, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='date', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='date')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='date'):
super(date, self).exportAttributes(outfile, level, already_processed, namespace_, name_='date')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='date', fromsubclass_=False, pretty_print=True):
super(date, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='date'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(date, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(date, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(date, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(date, self).buildChildren(child_, node, nodeName_, True)
pass
# end class date
class metaMetadata(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, identifier=None, contribute=None, metadataSchema=None, language=None):
self.uniqueElementName = _cast(None, uniqueElementName)
if identifier is None:
self.identifier = []
else:
self.identifier = identifier
if contribute is None:
self.contribute = []
else:
self.contribute = contribute
if metadataSchema is None:
self.metadataSchema = []
else:
self.metadataSchema = metadataSchema
self.language = language
def factory(*args_, **kwargs_):
if metaMetadata.subclass:
return metaMetadata.subclass(*args_, **kwargs_)
else:
return metaMetadata(*args_, **kwargs_)
factory = staticmethod(factory)
def get_identifier(self): return self.identifier
def set_identifier(self, identifier): self.identifier = identifier
def add_identifier(self, value): self.identifier.append(value)
def insert_identifier(self, index, value): self.identifier[index] = value
def get_contribute(self): return self.contribute
def set_contribute(self, contribute): self.contribute = contribute
def add_contribute(self, value): self.contribute.append(value)
def insert_contribute(self, index, value): self.contribute[index] = value
def get_metadataSchema(self): return self.metadataSchema
def set_metadataSchema(self, metadataSchema): self.metadataSchema = metadataSchema
def add_metadataSchema(self, value): self.metadataSchema.append(value)
def insert_metadataSchema(self, index, value): self.metadataSchema[index] = value
def get_language(self): return self.language
def set_language(self, language): self.language = language
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.identifier or
self.contribute or
self.metadataSchema or
self.language is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='metaMetadata', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='metaMetadata')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='metaMetadata'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='metaMetadata', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
for identifier_ in self.identifier:
identifier_.export(outfile, level, namespace_, name_='identifier', pretty_print=pretty_print)
for contribute_ in self.contribute:
contribute_.export(outfile, level, namespace_, name_='contribute', pretty_print=pretty_print)
for metadataSchema_ in self.metadataSchema:
metadataSchema_.export(outfile, level, namespace_, name_='metadataSchema', pretty_print=pretty_print)
if self.language is not None:
self.language.export(outfile, level, namespace_, name_='language', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='metaMetadata'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write('identifier=[\n')
level += 1
for identifier_ in self.identifier:
showIndent(outfile, level)
outfile.write('model_.identifier(\n')
identifier_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('contribute=[\n')
level += 1
for contribute_ in self.contribute:
showIndent(outfile, level)
outfile.write('model_.contributeMeta(\n')
contribute_.exportLiteral(outfile, level, name_='contributeMeta')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('metadataSchema=[\n')
level += 1
for metadataSchema_ in self.metadataSchema:
showIndent(outfile, level)
outfile.write('model_.metadataSchema(\n')
metadataSchema_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.language is not None:
showIndent(outfile, level)
outfile.write('language=model_.LanguageId(\n')
self.language.exportLiteral(outfile, level, name_='language')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'identifier':
obj_ = identifier.factory()
obj_.build(child_)
self.identifier.append(obj_)
elif nodeName_ == 'contribute':
obj_ = contributeMeta.factory()
obj_.build(child_)
self.contribute.append(obj_)
elif nodeName_ == 'metadataSchema':
obj_ = metadataSchema.factory()
obj_.build(child_)
self.metadataSchema.append(obj_)
elif nodeName_ == 'language':
class_obj_ = self.get_class_obj_(child_, LanguageId)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_language(obj_)
# end class metaMetadata
class contributeMeta(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, role=None, entity=None, date=None):
self.role = role
if entity is None:
self.entity = []
else:
self.entity = entity
self.date = date
def factory(*args_, **kwargs_):
if contributeMeta.subclass:
return contributeMeta.subclass(*args_, **kwargs_)
else:
return contributeMeta(*args_, **kwargs_)
factory = staticmethod(factory)
def get_role(self): return self.role
def set_role(self, role): self.role = role
def get_entity(self): return self.entity
def set_entity(self, entity): self.entity = entity
def add_entity(self, value): self.entity.append(value)
def insert_entity(self, index, value): self.entity[index] = value
def get_date(self): return self.date
def set_date(self, date): self.date = date
def hasContent_(self):
if (
self.role is not None or
self.entity or
self.date is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='contributeMeta', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='contributeMeta')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='contributeMeta'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='contributeMeta', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.role is not None:
self.role.export(outfile, level, namespace_, name_='role', pretty_print=pretty_print)
for entity_ in self.entity:
entity_.export(outfile, level, namespace_, name_='entity', pretty_print=pretty_print)
if self.date is not None:
self.date.export(outfile, level, namespace_, name_='date', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='contributeMeta'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.role is not None:
showIndent(outfile, level)
outfile.write('role=model_.roleMeta(\n')
self.role.exportLiteral(outfile, level, name_='role')
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('entity=[\n')
level += 1
for entity_ in self.entity:
showIndent(outfile, level)
outfile.write('model_.VCard(\n')
entity_.exportLiteral(outfile, level, name_='VCard')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.date is not None:
showIndent(outfile, level)
outfile.write('date=model_.date(\n')
self.date.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'role':
class_obj_ = self.get_class_obj_(child_, roleMeta)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_role(obj_)
elif nodeName_ == 'entity':
class_obj_ = self.get_class_obj_(child_, VCard)
obj_ = class_obj_.factory()
obj_.build(child_)
self.entity.append(obj_)
elif nodeName_ == 'date':
obj_ = date.factory()
obj_.build(child_)
self.set_date(obj_)
# end class contributeMeta
class metadataSchema(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, valueOf_=None):
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if metadataSchema.subclass:
return metadataSchema.subclass(*args_, **kwargs_)
else:
return metadataSchema(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='metadataSchema', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='metadataSchema')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='metadataSchema'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='metadataSchema', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='metadataSchema'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class metadataSchema
class technical(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, format=None, size=None, location=None, requirement=None, installationRemarks=None, otherPlatformRequirements=None, duration=None):
self.uniqueElementName = _cast(None, uniqueElementName)
if format is None:
self.format = []
else:
self.format = format
self.size = size
if location is None:
self.location = []
else:
self.location = location
if requirement is None:
self.requirement = []
else:
self.requirement = requirement
self.installationRemarks = installationRemarks
self.otherPlatformRequirements = otherPlatformRequirements
self.duration = duration
def factory(*args_, **kwargs_):
if technical.subclass:
return technical.subclass(*args_, **kwargs_)
else:
return technical(*args_, **kwargs_)
factory = staticmethod(factory)
def get_format(self): return self.format
def set_format(self, format): self.format = format
def add_format(self, value): self.format.append(value)
def insert_format(self, index, value): self.format[index] = value
def get_size(self): return self.size
def set_size(self, size): self.size = size
def get_location(self): return self.location
def set_location(self, location): self.location = location
def add_location(self, value): self.location.append(value)
def insert_location(self, index, value): self.location[index] = value
def get_requirement(self): return self.requirement
def set_requirement(self, requirement): self.requirement = requirement
def add_requirement(self, value): self.requirement.append(value)
def insert_requirement(self, index, value): self.requirement[index] = value
def get_installationRemarks(self): return self.installationRemarks
def set_installationRemarks(self, installationRemarks): self.installationRemarks = installationRemarks
def get_otherPlatformRequirements(self): return self.otherPlatformRequirements
def set_otherPlatformRequirements(self, otherPlatformRequirements): self.otherPlatformRequirements = otherPlatformRequirements
def get_duration(self): return self.duration
def set_duration(self, duration): self.duration = duration
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.format or
self.size is not None or
self.location or
self.requirement or
self.installationRemarks is not None or
self.otherPlatformRequirements is not None or
self.duration is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='technical', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='technical')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='technical'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='technical', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
for format_ in self.format:
format_.export(outfile, level, namespace_, name_='format', pretty_print=pretty_print)
if self.size is not None:
self.size.export(outfile, level, namespace_, name_='size', pretty_print=pretty_print)
for location_ in self.location:
location_.export(outfile, level, namespace_, name_='location', pretty_print=pretty_print)
for requirement_ in self.requirement:
requirement_.export(outfile, level, namespace_, name_='requirement', pretty_print=pretty_print)
if self.installationRemarks is not None:
self.installationRemarks.export(outfile, level, namespace_, name_='installationRemarks', pretty_print=pretty_print)
if self.otherPlatformRequirements is not None:
self.otherPlatformRequirements.export(outfile, level, namespace_, name_='otherPlatformRequirements', pretty_print=pretty_print)
if self.duration is not None:
self.duration.export(outfile, level, namespace_, name_='duration', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='technical'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write('format=[\n')
level += 1
for format_ in self.format:
showIndent(outfile, level)
outfile.write('model_.format(\n')
format_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.size is not None:
showIndent(outfile, level)
outfile.write('size=model_.size(\n')
self.size.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('location=[\n')
level += 1
for location_ in self.location:
showIndent(outfile, level)
outfile.write('model_.location(\n')
location_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('requirement=[\n')
level += 1
for requirement_ in self.requirement:
showIndent(outfile, level)
outfile.write('model_.requirement(\n')
requirement_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.installationRemarks is not None:
showIndent(outfile, level)
outfile.write('installationRemarks=model_.installationRemarks(\n')
self.installationRemarks.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.otherPlatformRequirements is not None:
showIndent(outfile, level)
outfile.write('otherPlatformRequirements=model_.otherPlatformRequirements(\n')
self.otherPlatformRequirements.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.duration is not None:
showIndent(outfile, level)
outfile.write('duration=model_.duration(\n')
self.duration.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'format':
obj_ = format.factory()
obj_.build(child_)
self.format.append(obj_)
elif nodeName_ == 'size':
obj_ = size.factory()
obj_.build(child_)
self.set_size(obj_)
elif nodeName_ == 'location':
obj_ = location.factory()
obj_.build(child_)
self.location.append(obj_)
elif nodeName_ == 'requirement':
obj_ = requirement.factory()
obj_.build(child_)
self.requirement.append(obj_)
elif nodeName_ == 'installationRemarks':
obj_ = installationRemarks.factory()
obj_.build(child_)
self.set_installationRemarks(obj_)
elif nodeName_ == 'otherPlatformRequirements':
obj_ = otherPlatformRequirements.factory()
obj_.build(child_)
self.set_otherPlatformRequirements(obj_)
elif nodeName_ == 'duration':
obj_ = duration.factory()
obj_.build(child_)
self.set_duration(obj_)
# end class technical
class format(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, valueOf_=None):
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if format.subclass:
return format.subclass(*args_, **kwargs_)
else:
return format(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='format', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='format')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='format'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='format', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='format'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class format
class size(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if size.subclass:
return size.subclass(*args_, **kwargs_)
else:
return size(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='size', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='size')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='size'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='size', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='size'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class size
class location(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, valueOf_=None):
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if location.subclass:
return location.subclass(*args_, **kwargs_)
else:
return location(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='location', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='location')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='location'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='location', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='location'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class location
class requirement(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, orComposite=None):
if orComposite is None:
self.orComposite = []
else:
self.orComposite = orComposite
def factory(*args_, **kwargs_):
if requirement.subclass:
return requirement.subclass(*args_, **kwargs_)
else:
return requirement(*args_, **kwargs_)
factory = staticmethod(factory)
def get_orComposite(self): return self.orComposite
def set_orComposite(self, orComposite): self.orComposite = orComposite
def add_orComposite(self, value): self.orComposite.append(value)
def insert_orComposite(self, index, value): self.orComposite[index] = value
def hasContent_(self):
if (
self.orComposite
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='requirement', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='requirement')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='requirement'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='requirement', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
for orComposite_ in self.orComposite:
orComposite_.export(outfile, level, namespace_, name_='orComposite', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='requirement'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
showIndent(outfile, level)
outfile.write('orComposite=[\n')
level += 1
for orComposite_ in self.orComposite:
showIndent(outfile, level)
outfile.write('model_.orComposite(\n')
orComposite_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'orComposite':
obj_ = orComposite.factory()
obj_.build(child_)
self.orComposite.append(obj_)
# end class requirement
class orComposite(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, type_=None, name=None, minimumVersion=None, maximumVersion=None):
self.type_ = type_
self.name = name
self.minimumVersion = minimumVersion
self.maximumVersion = maximumVersion
def factory(*args_, **kwargs_):
if orComposite.subclass:
return orComposite.subclass(*args_, **kwargs_)
else:
return orComposite(*args_, **kwargs_)
factory = staticmethod(factory)
def get_type(self): return self.type_
def set_type(self, type_): self.type_ = type_
def get_name(self): return self.name
def set_name(self, name): self.name = name
def get_minimumVersion(self): return self.minimumVersion
def set_minimumVersion(self, minimumVersion): self.minimumVersion = minimumVersion
def get_maximumVersion(self): return self.maximumVersion
def set_maximumVersion(self, maximumVersion): self.maximumVersion = maximumVersion
def hasContent_(self):
if (
self.type_ is not None or
self.name is not None or
self.minimumVersion is not None or
self.maximumVersion is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='orComposite', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='orComposite')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='orComposite'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='orComposite', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.type_ is not None:
self.type_.export(outfile, level, namespace_, name_='type', pretty_print=pretty_print)
if self.name is not None:
self.name.export(outfile, level, namespace_, name_='name', pretty_print=pretty_print)
if self.minimumVersion is not None:
self.minimumVersion.export(outfile, level, namespace_, name_='minimumVersion', pretty_print=pretty_print)
if self.maximumVersion is not None:
self.maximumVersion.export(outfile, level, namespace_, name_='maximumVersion', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='orComposite'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.type_ is not None:
showIndent(outfile, level)
outfile.write('type_=model_.type_(\n')
self.type_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.name is not None:
showIndent(outfile, level)
outfile.write('name=model_.name(\n')
self.name.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.minimumVersion is not None:
showIndent(outfile, level)
outfile.write('minimumVersion=model_.minimumVersion(\n')
self.minimumVersion.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.maximumVersion is not None:
showIndent(outfile, level)
outfile.write('maximumVersion=model_.maximumVersion(\n')
self.maximumVersion.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'type':
obj_ = type_.factory()
obj_.build(child_)
self.set_type(obj_)
elif nodeName_ == 'name':
class_obj_ = self.get_class_obj_(child_, name)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_name(obj_)
elif nodeName_ == 'minimumVersion':
obj_ = minimumVersion.factory()
obj_.build(child_)
self.set_minimumVersion(obj_)
elif nodeName_ == 'maximumVersion':
obj_ = maximumVersion.factory()
obj_.build(child_)
self.set_maximumVersion(obj_)
# end class orComposite
class minimumVersion(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if minimumVersion.subclass:
return minimumVersion.subclass(*args_, **kwargs_)
else:
return minimumVersion(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='minimumVersion', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='minimumVersion')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='minimumVersion'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='minimumVersion', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='minimumVersion'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class minimumVersion
class maximumVersion(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if maximumVersion.subclass:
return maximumVersion.subclass(*args_, **kwargs_)
else:
return maximumVersion(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='maximumVersion', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='maximumVersion')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='maximumVersion'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='maximumVersion', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='maximumVersion'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class maximumVersion
class installationRemarks(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None, uniqueElementName=None):
super(installationRemarks, self).__init__(string, )
self.uniqueElementName = _cast(None, uniqueElementName)
pass
def factory(*args_, **kwargs_):
if installationRemarks.subclass:
return installationRemarks.subclass(*args_, **kwargs_)
else:
return installationRemarks(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(installationRemarks, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='installationRemarks', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='installationRemarks')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='installationRemarks'):
super(installationRemarks, self).exportAttributes(outfile, level, already_processed, namespace_, name_='installationRemarks')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='installationRemarks', fromsubclass_=False, pretty_print=True):
super(installationRemarks, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='installationRemarks'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(installationRemarks, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(installationRemarks, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(installationRemarks, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(installationRemarks, self).buildChildren(child_, node, nodeName_, True)
pass
# end class installationRemarks
class otherPlatformRequirements(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None):
super(otherPlatformRequirements, self).__init__(string, )
pass
def factory(*args_, **kwargs_):
if otherPlatformRequirements.subclass:
return otherPlatformRequirements.subclass(*args_, **kwargs_)
else:
return otherPlatformRequirements(*args_, **kwargs_)
factory = staticmethod(factory)
def hasContent_(self):
if (
super(otherPlatformRequirements, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='otherPlatformRequirements', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='otherPlatformRequirements')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='otherPlatformRequirements'):
super(otherPlatformRequirements, self).exportAttributes(outfile, level, already_processed, namespace_, name_='otherPlatformRequirements')
def exportChildren(self, outfile, level, namespace_='', name_='otherPlatformRequirements', fromsubclass_=False, pretty_print=True):
super(otherPlatformRequirements, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='otherPlatformRequirements'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(otherPlatformRequirements, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(otherPlatformRequirements, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(otherPlatformRequirements, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(otherPlatformRequirements, self).buildChildren(child_, node, nodeName_, True)
pass
# end class otherPlatformRequirements
class duration(Duration):
subclass = None
superclass = Duration
def __init__(self, durationf=None, description=None, uniqueElementName=None, valueOf_=None):
super(duration, self).__init__(durationf, description, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if duration.subclass:
return duration.subclass(*args_, **kwargs_)
else:
return duration(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(duration, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='duration', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='duration')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='duration'):
super(duration, self).exportAttributes(outfile, level, already_processed, namespace_, name_='duration')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='duration', fromsubclass_=False, pretty_print=True):
super(duration, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='duration'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(duration, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(duration, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(duration, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(duration, self).buildChildren(child_, node, nodeName_, True)
pass
# end class duration
class educational(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, interactivityType=None, learningResourceType=None, interactivityLevel=None, semanticDensity=None, intendedEndUserRole=None, context=None, typicalAgeRange=None, difficulty=None, typicalLearningTime=None, description=None, language=None, cognitiveProcess=None):
self.interactivityType = interactivityType
if learningResourceType is None:
self.learningResourceType = []
else:
self.learningResourceType = learningResourceType
self.interactivityLevel = interactivityLevel
self.semanticDensity = semanticDensity
if intendedEndUserRole is None:
self.intendedEndUserRole = []
else:
self.intendedEndUserRole = intendedEndUserRole
if context is None:
self.context = []
else:
self.context = context
if typicalAgeRange is None:
self.typicalAgeRange = []
else:
self.typicalAgeRange = typicalAgeRange
self.difficulty = difficulty
self.typicalLearningTime = typicalLearningTime
if description is None:
self.description = []
else:
self.description = description
if language is None:
self.language = []
else:
self.language = language
if cognitiveProcess is None:
self.cognitiveProcess = []
else:
self.cognitiveProcess = cognitiveProcess
def factory(*args_, **kwargs_):
if educational.subclass:
return educational.subclass(*args_, **kwargs_)
else:
return educational(*args_, **kwargs_)
factory = staticmethod(factory)
def get_interactivityType(self): return self.interactivityType
def set_interactivityType(self, interactivityType): self.interactivityType = interactivityType
def get_learningResourceType(self): return self.learningResourceType
def set_learningResourceType(self, learningResourceType): self.learningResourceType = learningResourceType
def add_learningResourceType(self, value): self.learningResourceType.append(value)
def insert_learningResourceType(self, index, value): self.learningResourceType[index] = value
def get_interactivityLevel(self): return self.interactivityLevel
def set_interactivityLevel(self, interactivityLevel): self.interactivityLevel = interactivityLevel
def get_semanticDensity(self): return self.semanticDensity
def set_semanticDensity(self, semanticDensity): self.semanticDensity = semanticDensity
def get_intendedEndUserRole(self): return self.intendedEndUserRole
def set_intendedEndUserRole(self, intendedEndUserRole): self.intendedEndUserRole = intendedEndUserRole
def add_intendedEndUserRole(self, value): self.intendedEndUserRole.append(value)
def insert_intendedEndUserRole(self, index, value): self.intendedEndUserRole[index] = value
def get_context(self): return self.context
def set_context(self, context): self.context = context
def add_context(self, value): self.context.append(value)
def insert_context(self, index, value): self.context[index] = value
def get_typicalAgeRange(self): return self.typicalAgeRange
def set_typicalAgeRange(self, typicalAgeRange): self.typicalAgeRange = typicalAgeRange
def add_typicalAgeRange(self, value): self.typicalAgeRange.append(value)
def insert_typicalAgeRange(self, index, value): self.typicalAgeRange[index] = value
def get_difficulty(self): return self.difficulty
def set_difficulty(self, difficulty): self.difficulty = difficulty
def get_typicalLearningTime(self): return self.typicalLearningTime
def set_typicalLearningTime(self, typicalLearningTime): self.typicalLearningTime = typicalLearningTime
def get_description(self): return self.description
def set_description(self, description): self.description = description
def add_description(self, value): self.description.append(value)
def insert_description(self, index, value): self.description[index] = value
def get_language(self): return self.language
def set_language(self, language): self.language = language
def add_language(self, value): self.language.append(value)
def insert_language(self, index, value): self.language[index] = value
def get_cognitiveProcess(self): return self.cognitiveProcess
def set_cognitiveProcess(self, cognitiveProcess): self.cognitiveProcess = cognitiveProcess
def add_cognitiveProcess(self, value): self.cognitiveProcess.append(value)
def insert_cognitiveProcess(self, index, value): self.cognitiveProcess[index] = value
def hasContent_(self):
if (
self.interactivityType is not None or
self.learningResourceType or
self.interactivityLevel is not None or
self.semanticDensity is not None or
self.intendedEndUserRole or
self.context or
self.typicalAgeRange or
self.difficulty is not None or
self.typicalLearningTime is not None or
self.description or
self.language or
self.cognitiveProcess
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='educational', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='educational')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='educational'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='educational', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.interactivityType is not None:
self.interactivityType.export(outfile, level, namespace_, name_='interactivityType', pretty_print=pretty_print)
for learningResourceType_ in self.learningResourceType:
learningResourceType_.export(outfile, level, namespace_, name_='learningResourceType', pretty_print=pretty_print)
if self.interactivityLevel is not None:
self.interactivityLevel.export(outfile, level, namespace_, name_='interactivityLevel', pretty_print=pretty_print)
if self.semanticDensity is not None:
self.semanticDensity.export(outfile, level, namespace_, name_='semanticDensity', pretty_print=pretty_print)
for intendedEndUserRole_ in self.intendedEndUserRole:
intendedEndUserRole_.export(outfile, level, namespace_, name_='intendedEndUserRole', pretty_print=pretty_print)
for context_ in self.context:
context_.export(outfile, level, namespace_, name_='context', pretty_print=pretty_print)
for typicalAgeRange_ in self.typicalAgeRange:
typicalAgeRange_.export(outfile, level, namespace_, name_='typicalAgeRange', pretty_print=pretty_print)
if self.difficulty is not None:
self.difficulty.export(outfile, level, namespace_, name_='difficulty', pretty_print=pretty_print)
if self.typicalLearningTime is not None:
self.typicalLearningTime.export(outfile, level, namespace_, name_='typicalLearningTime', pretty_print=pretty_print)
for description_ in self.description:
description_.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
for language_ in self.language:
language_.export(outfile, level, namespace_, name_='language', pretty_print=pretty_print)
for cognitiveProcess_ in self.cognitiveProcess:
cognitiveProcess_.export(outfile, level, namespace_, name_='cognitiveProcess', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='educational'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.interactivityType is not None:
showIndent(outfile, level)
outfile.write('interactivityType=model_.interactivityType(\n')
self.interactivityType.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('learningResourceType=[\n')
level += 1
for learningResourceType_ in self.learningResourceType:
showIndent(outfile, level)
outfile.write('model_.learningResourceType(\n')
learningResourceType_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.interactivityLevel is not None:
showIndent(outfile, level)
outfile.write('interactivityLevel=model_.interactivityLevel(\n')
self.interactivityLevel.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.semanticDensity is not None:
showIndent(outfile, level)
outfile.write('semanticDensity=model_.semanticDensity(\n')
self.semanticDensity.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('intendedEndUserRole=[\n')
level += 1
for intendedEndUserRole_ in self.intendedEndUserRole:
showIndent(outfile, level)
outfile.write('model_.intendedEndUserRole(\n')
intendedEndUserRole_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('context=[\n')
level += 1
for context_ in self.context:
showIndent(outfile, level)
outfile.write('model_.context(\n')
context_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('typicalAgeRange=[\n')
level += 1
for typicalAgeRange_ in self.typicalAgeRange:
showIndent(outfile, level)
outfile.write('model_.typicalAgeRange(\n')
typicalAgeRange_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.difficulty is not None:
showIndent(outfile, level)
outfile.write('difficulty=model_.difficulty(\n')
self.difficulty.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.typicalLearningTime is not None:
showIndent(outfile, level)
outfile.write('typicalLearningTime=model_.typicalLearningTime(\n')
self.typicalLearningTime.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('description=[\n')
level += 1
for description_ in self.description:
showIndent(outfile, level)
outfile.write('model_.LanguageString(\n')
description_.exportLiteral(outfile, level, name_='LanguageString')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('language=[\n')
level += 1
for language_ in self.language:
showIndent(outfile, level)
outfile.write('model_.LanguageId(\n')
language_.exportLiteral(outfile, level, name_='LanguageId')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
showIndent(outfile, level)
outfile.write('cognitiveProcess=[\n')
level += 1
for cognitiveProcess_ in self.cognitiveProcess:
showIndent(outfile, level)
outfile.write('model_.cognitiveProcess(\n')
cognitiveProcess_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'interactivityType':
class_obj_ = self.get_class_obj_(child_, interactivityType)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_interactivityType(obj_)
elif nodeName_ == 'learningResourceType':
class_obj_ = self.get_class_obj_(child_, learningResourceType)
obj_ = class_obj_.factory()
obj_.build(child_)
self.learningResourceType.append(obj_)
elif nodeName_ == 'interactivityLevel':
class_obj_ = self.get_class_obj_(child_, interactivityLevel)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_interactivityLevel(obj_)
elif nodeName_ == 'semanticDensity':
class_obj_ = self.get_class_obj_(child_, semanticDensity)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_semanticDensity(obj_)
elif nodeName_ == 'intendedEndUserRole':
class_obj_ = self.get_class_obj_(child_, intendedEndUserRole)
obj_ = class_obj_.factory()
obj_.build(child_)
self.intendedEndUserRole.append(obj_)
elif nodeName_ == 'context':
class_obj_ = self.get_class_obj_(child_, context)
obj_ = class_obj_.factory()
obj_.build(child_)
self.context.append(obj_)
elif nodeName_ == 'typicalAgeRange':
obj_ = typicalAgeRange.factory()
obj_.build(child_)
self.typicalAgeRange.append(obj_)
elif nodeName_ == 'difficulty':
class_obj_ = self.get_class_obj_(child_, difficulty)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_difficulty(obj_)
elif nodeName_ == 'typicalLearningTime':
obj_ = typicalLearningTime.factory()
obj_.build(child_)
self.set_typicalLearningTime(obj_)
elif nodeName_ == 'description':
class_obj_ = self.get_class_obj_(child_, LanguageString)
obj_ = class_obj_.factory()
obj_.build(child_)
self.description.append(obj_)
elif nodeName_ == 'language':
class_obj_ = self.get_class_obj_(child_, LanguageId)
obj_ = class_obj_.factory()
obj_.build(child_)
self.language.append(obj_)
elif nodeName_ == 'cognitiveProcess':
class_obj_ = self.get_class_obj_(child_, cognitiveProcess)
obj_ = class_obj_.factory()
obj_.build(child_)
self.cognitiveProcess.append(obj_)
# end class educational
class typicalAgeRange(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None):
super(typicalAgeRange, self).__init__(string, )
pass
def factory(*args_, **kwargs_):
if typicalAgeRange.subclass:
return typicalAgeRange.subclass(*args_, **kwargs_)
else:
return typicalAgeRange(*args_, **kwargs_)
factory = staticmethod(factory)
def hasContent_(self):
if (
super(typicalAgeRange, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='typicalAgeRange', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='typicalAgeRange')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='typicalAgeRange'):
super(typicalAgeRange, self).exportAttributes(outfile, level, already_processed, namespace_, name_='typicalAgeRange')
def exportChildren(self, outfile, level, namespace_='', name_='typicalAgeRange', fromsubclass_=False, pretty_print=True):
super(typicalAgeRange, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='typicalAgeRange'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(typicalAgeRange, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(typicalAgeRange, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(typicalAgeRange, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(typicalAgeRange, self).buildChildren(child_, node, nodeName_, True)
pass
# end class typicalAgeRange
class typicalLearningTime(Duration):
subclass = None
superclass = Duration
def __init__(self, duration=None, description=None, uniqueElementName=None):
super(typicalLearningTime, self).__init__(duration, description, )
self.uniqueElementName = _cast(None, uniqueElementName)
pass
def factory(*args_, **kwargs_):
if typicalLearningTime.subclass:
return typicalLearningTime.subclass(*args_, **kwargs_)
else:
return typicalLearningTime(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(typicalLearningTime, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='typicalLearningTime', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='typicalLearningTime')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='typicalLearningTime'):
super(typicalLearningTime, self).exportAttributes(outfile, level, already_processed, namespace_, name_='typicalLearningTime')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='typicalLearningTime', fromsubclass_=False, pretty_print=True):
super(typicalLearningTime, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='typicalLearningTime'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(typicalLearningTime, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(typicalLearningTime, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(typicalLearningTime, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(typicalLearningTime, self).buildChildren(child_, node, nodeName_, True)
pass
# end class typicalLearningTime
class rights(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, cost=None, copyrightAndOtherRestrictions=None, description=None, access=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.cost = cost
self.copyrightAndOtherRestrictions = copyrightAndOtherRestrictions
self.description = description
self.access = access
def factory(*args_, **kwargs_):
if rights.subclass:
return rights.subclass(*args_, **kwargs_)
else:
return rights(*args_, **kwargs_)
factory = staticmethod(factory)
def get_cost(self): return self.cost
def set_cost(self, cost): self.cost = cost
def get_copyrightAndOtherRestrictions(self): return self.copyrightAndOtherRestrictions
def set_copyrightAndOtherRestrictions(self, copyrightAndOtherRestrictions): self.copyrightAndOtherRestrictions = copyrightAndOtherRestrictions
def get_description(self): return self.description
def set_description(self, description): self.description = description
def get_access(self): return self.access
def set_access(self, access): self.access = access
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.cost is not None or
self.copyrightAndOtherRestrictions is not None or
self.description is not None or
self.access is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='rights', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='rights')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='rights'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='rights', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.cost is not None:
self.cost.export(outfile, level, namespace_, name_='cost', pretty_print=pretty_print)
if self.copyrightAndOtherRestrictions is not None:
self.copyrightAndOtherRestrictions.export(outfile, level, namespace_, name_='copyrightAndOtherRestrictions', pretty_print=pretty_print)
if self.description is not None:
self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
if self.access is not None:
self.access.export(outfile, level, namespace_, name_='access', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='rights'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
if self.cost is not None:
showIndent(outfile, level)
outfile.write('cost=model_.cost(\n')
self.cost.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.copyrightAndOtherRestrictions is not None:
showIndent(outfile, level)
outfile.write('copyrightAndOtherRestrictions=model_.copyrightAndOtherRestrictions(\n')
self.copyrightAndOtherRestrictions.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.description is not None:
showIndent(outfile, level)
outfile.write('description=model_.description(\n')
self.description.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.access is not None:
showIndent(outfile, level)
outfile.write('access=model_.access(\n')
self.access.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'cost':
class_obj_ = self.get_class_obj_(child_, cost)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_cost(obj_)
elif nodeName_ == 'copyrightAndOtherRestrictions':
class_obj_ = self.get_class_obj_(child_, copyrightAndOtherRestrictions)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_copyrightAndOtherRestrictions(obj_)
elif nodeName_ == 'description':
obj_ = description.factory()
obj_.build(child_)
self.set_description(obj_)
elif nodeName_ == 'access':
obj_ = access.factory()
obj_.build(child_)
self.set_access(obj_)
# end class rights
class description(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None):
super(description, self).__init__(string, )
pass
def factory(*args_, **kwargs_):
if description.subclass:
return description.subclass(*args_, **kwargs_)
else:
return description(*args_, **kwargs_)
factory = staticmethod(factory)
def hasContent_(self):
if (
super(description, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='description', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='description')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='description'):
super(description, self).exportAttributes(outfile, level, already_processed, namespace_, name_='description')
def exportChildren(self, outfile, level, namespace_='', name_='description', fromsubclass_=False, pretty_print=True):
super(description, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='description'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(description, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(description, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(description, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(description, self).buildChildren(child_, node, nodeName_, True)
pass
# end class description
class access(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, accessType=None, description=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.accessType = accessType
self.description = description
def factory(*args_, **kwargs_):
if access.subclass:
return access.subclass(*args_, **kwargs_)
else:
return access(*args_, **kwargs_)
factory = staticmethod(factory)
def get_accessType(self): return self.accessType
def set_accessType(self, accessType): self.accessType = accessType
def get_description(self): return self.description
def set_description(self, description): self.description = description
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.accessType is not None or
self.description is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='access', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='access')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='access'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='access', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.accessType is not None:
self.accessType.export(outfile, level, namespace_, name_='accessType', pretty_print=pretty_print)
if self.description is not None:
self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='access'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
if self.accessType is not None:
showIndent(outfile, level)
outfile.write('accessType=model_.accessType(\n')
self.accessType.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.description is not None:
showIndent(outfile, level)
outfile.write('description=model_.description(\n')
self.description.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'accessType':
class_obj_ = self.get_class_obj_(child_, accessType)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_accessType(obj_)
elif nodeName_ == 'description':
obj_ = description.factory()
obj_.build(child_)
self.set_description(obj_)
# end class access
class relation(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, kind=None, resource=None):
self.kind = kind
self.resource = resource
def factory(*args_, **kwargs_):
if relation.subclass:
return relation.subclass(*args_, **kwargs_)
else:
return relation(*args_, **kwargs_)
factory = staticmethod(factory)
def get_kind(self): return self.kind
def set_kind(self, kind): self.kind = kind
def get_resource(self): return self.resource
def set_resource(self, resource): self.resource = resource
def hasContent_(self):
if (
self.kind is not None or
self.resource is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='relation', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='relation')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='relation'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='relation', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.kind is not None:
self.kind.export(outfile, level, namespace_, name_='kind', pretty_print=pretty_print)
if self.resource is not None:
self.resource.export(outfile, level, namespace_, name_='resource', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='relation'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.kind is not None:
showIndent(outfile, level)
outfile.write('kind=model_.kind(\n')
self.kind.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.resource is not None:
showIndent(outfile, level)
outfile.write('resource=model_.resource(\n')
self.resource.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'kind':
class_obj_ = self.get_class_obj_(child_, kind)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_kind(obj_)
elif nodeName_ == 'resource':
obj_ = resource.factory()
obj_.build(child_)
self.set_resource(obj_)
# end class relation
class resource(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, identifier=None, description=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.identifier = identifier
if description is None:
self.description = []
else:
self.description = description
def factory(*args_, **kwargs_):
if resource.subclass:
return resource.subclass(*args_, **kwargs_)
else:
return resource(*args_, **kwargs_)
factory = staticmethod(factory)
def get_identifier(self): return self.identifier
def set_identifier(self, identifier): self.identifier = identifier
def get_description(self): return self.description
def set_description(self, description): self.description = description
def add_description(self, value): self.description.append(value)
def insert_description(self, index, value): self.description[index] = value
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
self.identifier is not None or
self.description
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='resource', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='resource')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='resource'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='resource', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.identifier is not None:
self.identifier.export(outfile, level, namespace_, name_='identifier', pretty_print=pretty_print)
for description_ in self.description:
description_.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='resource'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
if self.identifier is not None:
showIndent(outfile, level)
outfile.write('identifier=model_.identifier(\n')
self.identifier.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('description=[\n')
level += 1
for description_ in self.description:
showIndent(outfile, level)
outfile.write('model_.LanguageString(\n')
description_.exportLiteral(outfile, level, name_='LanguageString')
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'identifier':
obj_ = identifier.factory()
obj_.build(child_)
self.set_identifier(obj_)
elif nodeName_ == 'description':
class_obj_ = self.get_class_obj_(child_, LanguageString)
obj_ = class_obj_.factory()
obj_.build(child_)
self.description.append(obj_)
# end class resource
class annotation(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, entity=None, date=None, description=None):
self.entity = entity
self.date = date
self.description = description
def factory(*args_, **kwargs_):
if annotation.subclass:
return annotation.subclass(*args_, **kwargs_)
else:
return annotation(*args_, **kwargs_)
factory = staticmethod(factory)
def get_entity(self): return self.entity
def set_entity(self, entity): self.entity = entity
def get_date(self): return self.date
def set_date(self, date): self.date = date
def get_description(self): return self.description
def set_description(self, description): self.description = description
def hasContent_(self):
if (
self.entity is not None or
self.date is not None or
self.description is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='annotation', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='annotation')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='annotation'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='annotation', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.entity is not None:
self.entity.export(outfile, level, namespace_, name_='entity', pretty_print=pretty_print)
if self.date is not None:
self.date.export(outfile, level, namespace_, name_='date', pretty_print=pretty_print)
if self.description is not None:
self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='annotation'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.entity is not None:
showIndent(outfile, level)
outfile.write('entity=model_.entity(\n')
self.entity.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.date is not None:
showIndent(outfile, level)
outfile.write('date=model_.date(\n')
self.date.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.description is not None:
showIndent(outfile, level)
outfile.write('description=model_.description(\n')
self.description.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'entity':
obj_ = entity.factory()
obj_.build(child_)
self.set_entity(obj_)
elif nodeName_ == 'date':
obj_ = date.factory()
obj_.build(child_)
self.set_date(obj_)
elif nodeName_ == 'description':
obj_ = description.factory()
obj_.build(child_)
self.set_description(obj_)
# end class annotation
class entity(VCard):
subclass = None
superclass = VCard
def __init__(self, valueOf_=None):
super(entity, self).__init__(valueOf_, )
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if entity.subclass:
return entity.subclass(*args_, **kwargs_)
else:
return entity(*args_, **kwargs_)
factory = staticmethod(factory)
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(entity, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='entity', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='entity')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='entity'):
super(entity, self).exportAttributes(outfile, level, already_processed, namespace_, name_='entity')
def exportChildren(self, outfile, level, namespace_='', name_='entity', fromsubclass_=False, pretty_print=True):
super(entity, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
pass
def exportLiteral(self, outfile, level, name_='entity'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(entity, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(entity, self).exportLiteralChildren(outfile, level, name_)
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
super(entity, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class entity
class classification(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, purpose=None, taxonPath=None, description=None, keyword=None):
self.purpose = purpose
if taxonPath is None:
self.taxonPath = []
else:
self.taxonPath = taxonPath
self.description = description
if keyword is None:
self.keyword = []
else:
self.keyword = keyword
def factory(*args_, **kwargs_):
if classification.subclass:
return classification.subclass(*args_, **kwargs_)
else:
return classification(*args_, **kwargs_)
factory = staticmethod(factory)
def get_purpose(self): return self.purpose
def set_purpose(self, purpose): self.purpose = purpose
def get_taxonPath(self): return self.taxonPath
def set_taxonPath(self, taxonPath): self.taxonPath = taxonPath
def add_taxonPath(self, value): self.taxonPath.append(value)
def insert_taxonPath(self, index, value): self.taxonPath[index] = value
def get_description(self): return self.description
def set_description(self, description): self.description = description
def get_keyword(self): return self.keyword
def set_keyword(self, keyword): self.keyword = keyword
def add_keyword(self, value): self.keyword.append(value)
def insert_keyword(self, index, value): self.keyword[index] = value
def hasContent_(self):
if (
self.purpose is not None or
self.taxonPath or
self.description is not None or
self.keyword
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='classification', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='classification')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='classification'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='classification', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.purpose is not None:
self.purpose.export(outfile, level, namespace_, name_='purpose', pretty_print=pretty_print)
for taxonPath_ in self.taxonPath:
taxonPath_.export(outfile, level, namespace_, name_='taxonPath', pretty_print=pretty_print)
if self.description is not None:
self.description.export(outfile, level, namespace_, name_='description', pretty_print=pretty_print)
for keyword_ in self.keyword:
keyword_.export(outfile, level, namespace_, name_='keyword', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='classification'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.purpose is not None:
showIndent(outfile, level)
outfile.write('purpose=model_.purpose(\n')
self.purpose.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('taxonPath=[\n')
level += 1
for taxonPath_ in self.taxonPath:
showIndent(outfile, level)
outfile.write('model_.taxonPath(\n')
taxonPath_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
if self.description is not None:
showIndent(outfile, level)
outfile.write('description=model_.description(\n')
self.description.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('keyword=[\n')
level += 1
for keyword_ in self.keyword:
showIndent(outfile, level)
outfile.write('model_.keyword(\n')
keyword_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'purpose':
class_obj_ = self.get_class_obj_(child_, purpose)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_purpose(obj_)
elif nodeName_ == 'taxonPath':
obj_ = taxonPath.factory()
obj_.build(child_)
self.taxonPath.append(obj_)
elif nodeName_ == 'description':
obj_ = description.factory()
obj_.build(child_)
self.set_description(obj_)
elif nodeName_ == 'keyword':
obj_ = keyword.factory()
obj_.build(child_)
self.keyword.append(obj_)
# end class classification
class taxonPath(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, taxon=None):
self.source = source
if taxon is None:
self.taxon = []
else:
self.taxon = taxon
def factory(*args_, **kwargs_):
if taxonPath.subclass:
return taxonPath.subclass(*args_, **kwargs_)
else:
return taxonPath(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_taxon(self): return self.taxon
def set_taxon(self, taxon): self.taxon = taxon
def add_taxon(self, value): self.taxon.append(value)
def insert_taxon(self, index, value): self.taxon[index] = value
def hasContent_(self):
if (
self.source is not None or
self.taxon
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='taxonPath', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='taxonPath')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='taxonPath'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='taxonPath', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
for taxon_ in self.taxon:
taxon_.export(outfile, level, namespace_, name_='taxon', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='taxonPath'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.source(\n')
self.source.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
showIndent(outfile, level)
outfile.write('taxon=[\n')
level += 1
for taxon_ in self.taxon:
showIndent(outfile, level)
outfile.write('model_.taxon(\n')
taxon_.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
level -= 1
showIndent(outfile, level)
outfile.write('],\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
class_obj_ = self.get_class_obj_(child_, source)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'taxon':
obj_ = taxon.factory()
obj_.build(child_)
self.taxon.append(obj_)
# end class taxonPath
class source(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None, uniqueElementName=None, extensiontype_=None):
super(source, self).__init__(string, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if source.subclass:
return source.subclass(*args_, **kwargs_)
else:
return source(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(source, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='source', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='source')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='source'):
super(source, self).exportAttributes(outfile, level, already_processed, namespace_, name_='source')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='source', fromsubclass_=False, pretty_print=True):
super(source, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='source'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(source, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(source, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(source, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(source, self).buildChildren(child_, node, nodeName_, True)
pass
# end class source
class taxon(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, id=None, entry=None):
self.id = id
self.entry = entry
def factory(*args_, **kwargs_):
if taxon.subclass:
return taxon.subclass(*args_, **kwargs_)
else:
return taxon(*args_, **kwargs_)
factory = staticmethod(factory)
def get_id(self): return self.id
def set_id(self, id): self.id = id
def get_entry(self): return self.entry
def set_entry(self, entry): self.entry = entry
def hasContent_(self):
if (
self.id is not None or
self.entry is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='taxon', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='taxon')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='taxon'):
pass
def exportChildren(self, outfile, level, namespace_='', name_='taxon', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.id is not None:
self.id.export(outfile, level, namespace_, name_='id', pretty_print=pretty_print)
if self.entry is not None:
self.entry.export(outfile, level, namespace_, name_='entry', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='taxon'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.id is not None:
showIndent(outfile, level)
outfile.write('id=model_.id(\n')
self.id.exportLiteral(outfile, level)
showIndent(outfile, level)
outfile.write('),\n')
if self.entry is not None:
showIndent(outfile, level)
outfile.write('entry=model_.LanguageString(\n')
self.entry.exportLiteral(outfile, level, name_='entry')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'id':
obj_ = id.factory()
obj_.build(child_)
self.set_id(obj_)
elif nodeName_ == 'entry':
class_obj_ = self.get_class_obj_(child_, LanguageString)
obj_ = class_obj_.factory()
obj_.build(child_)
self.set_entry(obj_)
# end class taxon
class id(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, uniqueElementName=None, valueOf_=None):
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if id.subclass:
return id.subclass(*args_, **kwargs_)
else:
return id(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='id', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='id')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='id'):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
# outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='id', fromsubclass_=False, pretty_print=True):
pass
def exportLiteral(self, outfile, level, name_='id'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
def exportLiteralChildren(self, outfile, level, name_):
pass
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class id
class entryTaxon(LanguageString):
subclass = None
superclass = LanguageString
def __init__(self, string=None, uniqueElementName=None):
super(entryTaxon, self).__init__(string, )
self.uniqueElementName = _cast(None, uniqueElementName)
pass
def factory(*args_, **kwargs_):
if entryTaxon.subclass:
return entryTaxon.subclass(*args_, **kwargs_)
else:
return entryTaxon(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def hasContent_(self):
if (
super(entryTaxon, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='entryTaxon', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='entryTaxon')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='entryTaxon'):
super(entryTaxon, self).exportAttributes(outfile, level, already_processed, namespace_, name_='entryTaxon')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
# outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='entryTaxon', fromsubclass_=False, pretty_print=True):
super(entryTaxon, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='entryTaxon'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(entryTaxon, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(entryTaxon, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(entryTaxon, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(entryTaxon, self).buildChildren(child_, node, nodeName_, True)
pass
# end class entryTaxon
class sourceValue(source):
subclass = None
superclass = source
def __init__(self, string=None, uniqueElementName=None, valueOf_=None):
super(sourceValue, self).__init__(string, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if sourceValue.subclass:
return sourceValue.subclass(*args_, **kwargs_)
else:
return sourceValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(sourceValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='sourceValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='sourceValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='sourceValue'):
super(sourceValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='sourceValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='sourceValue', fromsubclass_=False, pretty_print=True):
super(sourceValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='sourceValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(sourceValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(sourceValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(sourceValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class sourceValue
class structureVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if structureVocab.subclass:
return structureVocab.subclass(*args_, **kwargs_)
else:
return structureVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='structureVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='structureVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='structureVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='structureVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='structureVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.structureValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = structureValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class structureVocab
class aggregationLevelVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if aggregationLevelVocab.subclass:
return aggregationLevelVocab.subclass(*args_, **kwargs_)
else:
return aggregationLevelVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='aggregationLevelVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='aggregationLevelVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='aggregationLevelVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='aggregationLevelVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='aggregationLevelVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.aggregationLevelValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = aggregationLevelValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class aggregationLevelVocab
class statusVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if statusVocab.subclass:
return statusVocab.subclass(*args_, **kwargs_)
else:
return statusVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='statusVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='statusVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='statusVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='statusVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='statusVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.statusValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = statusValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class statusVocab
class roleVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if roleVocab.subclass:
return roleVocab.subclass(*args_, **kwargs_)
else:
return roleVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='roleVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='roleVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='roleVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='roleVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='roleVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.roleValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = roleValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class roleVocab
class roleMetaVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if roleMetaVocab.subclass:
return roleMetaVocab.subclass(*args_, **kwargs_)
else:
return roleMetaVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='roleMetaVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='roleMetaVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='roleMetaVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='roleMetaVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='roleMetaVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.roleMetaValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = roleMetaValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class roleMetaVocab
class typeVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if typeVocab.subclass:
return typeVocab.subclass(*args_, **kwargs_)
else:
return typeVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='typeVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='typeVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='typeVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='typeVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='typeVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.typeValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = typeValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class typeVocab
class nameVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if nameVocab.subclass:
return nameVocab.subclass(*args_, **kwargs_)
else:
return nameVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='nameVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='nameVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='nameVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='nameVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='nameVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.nameValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = nameValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class nameVocab
class interactivityTypeVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if interactivityTypeVocab.subclass:
return interactivityTypeVocab.subclass(*args_, **kwargs_)
else:
return interactivityTypeVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='interactivityTypeVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityTypeVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='interactivityTypeVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='interactivityTypeVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='interactivityTypeVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.interactivityTypeValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = interactivityTypeValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class interactivityTypeVocab
class learningResourceTypeVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if learningResourceTypeVocab.subclass:
return learningResourceTypeVocab.subclass(*args_, **kwargs_)
else:
return learningResourceTypeVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='learningResourceTypeVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='learningResourceTypeVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='learningResourceTypeVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='learningResourceTypeVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='learningResourceTypeVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.learningResourceTypeValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = learningResourceTypeValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class learningResourceTypeVocab
class interactivityLevelVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if interactivityLevelVocab.subclass:
return interactivityLevelVocab.subclass(*args_, **kwargs_)
else:
return interactivityLevelVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='interactivityLevelVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityLevelVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='interactivityLevelVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='interactivityLevelVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='interactivityLevelVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.interactivityLevelValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = interactivityLevelValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class interactivityLevelVocab
class semanticDensityVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if semanticDensityVocab.subclass:
return semanticDensityVocab.subclass(*args_, **kwargs_)
else:
return semanticDensityVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='semanticDensityVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='semanticDensityVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='semanticDensityVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='semanticDensityVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='semanticDensityVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.semanticDensityValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = semanticDensityValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class semanticDensityVocab
class intendedEndUserRoleVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if intendedEndUserRoleVocab.subclass:
return intendedEndUserRoleVocab.subclass(*args_, **kwargs_)
else:
return intendedEndUserRoleVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='intendedEndUserRoleVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='intendedEndUserRoleVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='intendedEndUserRoleVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='intendedEndUserRoleVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='intendedEndUserRoleVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.intendedEndUserRoleValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = intendedEndUserRoleValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class intendedEndUserRoleVocab
class contextVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if contextVocab.subclass:
return contextVocab.subclass(*args_, **kwargs_)
else:
return contextVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='contextVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='contextVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='contextVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='contextVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='contextVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.contextValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = contextValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class contextVocab
class difficultyVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if difficultyVocab.subclass:
return difficultyVocab.subclass(*args_, **kwargs_)
else:
return difficultyVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='difficultyVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='difficultyVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='difficultyVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='difficultyVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='difficultyVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.difficultyValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = difficultyValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class difficultyVocab
class cognitiveProcessVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if cognitiveProcessVocab.subclass:
return cognitiveProcessVocab.subclass(*args_, **kwargs_)
else:
return cognitiveProcessVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='cognitiveProcessVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='cognitiveProcessVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='cognitiveProcessVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='cognitiveProcessVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='cognitiveProcessVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.cognitiveProcessValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = cognitiveProcessValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class cognitiveProcessVocab
class costVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if costVocab.subclass:
return costVocab.subclass(*args_, **kwargs_)
else:
return costVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='costVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='costVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='costVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='costVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='costVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.costValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = costValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class costVocab
class copyrightAndOtherRestrictionsVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if copyrightAndOtherRestrictionsVocab.subclass:
return copyrightAndOtherRestrictionsVocab.subclass(*args_, **kwargs_)
else:
return copyrightAndOtherRestrictionsVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='copyrightAndOtherRestrictionsVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='copyrightAndOtherRestrictionsVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='copyrightAndOtherRestrictionsVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='copyrightAndOtherRestrictionsVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='copyrightAndOtherRestrictionsVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.copyrightAndOtherRestrictionsValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = copyrightAndOtherRestrictionsValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class copyrightAndOtherRestrictionsVocab
class accessTypeVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if accessTypeVocab.subclass:
return accessTypeVocab.subclass(*args_, **kwargs_)
else:
return accessTypeVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='accessTypeVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='accessTypeVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='accessTypeVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='accessTypeVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='accessTypeVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.accessTypeValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = accessTypeValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class accessTypeVocab
class kindVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if kindVocab.subclass:
return kindVocab.subclass(*args_, **kwargs_)
else:
return kindVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='kindVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='kindVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='kindVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='kindVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='kindVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.kindValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = kindValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class kindVocab
class purposeVocab(GeneratedsSuper):
subclass = None
superclass = None
def __init__(self, source=None, value=None, extensiontype_=None):
self.source = source
self.value = value
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if purposeVocab.subclass:
return purposeVocab.subclass(*args_, **kwargs_)
else:
return purposeVocab(*args_, **kwargs_)
factory = staticmethod(factory)
def get_source(self): return self.source
def set_source(self, source): self.source = source
def get_value(self): return self.value
def set_value(self, value): self.value = value
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
self.source is not None or
self.value is not None
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='purposeVocab', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='purposeVocab')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='purposeVocab'):
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
pass
def exportChildren(self, outfile, level, namespace_='', name_='purposeVocab', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
if self.source is not None:
self.source.export(outfile, level, namespace_, name_='source', pretty_print=pretty_print)
if self.value is not None:
self.value.export(outfile, level, namespace_, name_='value', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='purposeVocab'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
pass
def exportLiteralChildren(self, outfile, level, name_):
if self.source is not None:
showIndent(outfile, level)
outfile.write('source=model_.sourceValue(\n')
self.source.exportLiteral(outfile, level, name_='source')
showIndent(outfile, level)
outfile.write('),\n')
if self.value is not None:
showIndent(outfile, level)
outfile.write('value=model_.purposeValue(\n')
self.value.exportLiteral(outfile, level, name_='value')
showIndent(outfile, level)
outfile.write('),\n')
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'source':
obj_ = sourceValue.factory()
obj_.build(child_)
self.set_source(obj_)
elif nodeName_ == 'value':
obj_ = purposeValue.factory()
obj_.build(child_)
self.set_value(obj_)
# end class purposeVocab
class purpose(purposeVocab):
subclass = None
superclass = purposeVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(purpose, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if purpose.subclass:
return purpose.subclass(*args_, **kwargs_)
else:
return purpose(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(purpose, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='purpose', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='purpose')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='purpose'):
super(purpose, self).exportAttributes(outfile, level, already_processed, namespace_, name_='purpose')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='purpose', fromsubclass_=False, pretty_print=True):
super(purpose, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='purpose'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(purpose, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(purpose, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(purpose, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(purpose, self).buildChildren(child_, node, nodeName_, True)
pass
# end class purpose
class kind(kindVocab):
subclass = None
superclass = kindVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(kind, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if kind.subclass:
return kind.subclass(*args_, **kwargs_)
else:
return kind(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(kind, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='kind', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='kind')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='kind'):
super(kind, self).exportAttributes(outfile, level, already_processed, namespace_, name_='kind')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='kind', fromsubclass_=False, pretty_print=True):
super(kind, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='kind'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(kind, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(kind, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(kind, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(kind, self).buildChildren(child_, node, nodeName_, True)
pass
# end class kind
class accessType(accessTypeVocab):
subclass = None
superclass = accessTypeVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(accessType, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if accessType.subclass:
return accessType.subclass(*args_, **kwargs_)
else:
return accessType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(accessType, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='accessType', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='accessType')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='accessType'):
super(accessType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='accessType')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='accessType', fromsubclass_=False, pretty_print=True):
super(accessType, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='accessType'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(accessType, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(accessType, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(accessType, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(accessType, self).buildChildren(child_, node, nodeName_, True)
pass
# end class accessType
class copyrightAndOtherRestrictions(copyrightAndOtherRestrictionsVocab):
subclass = None
superclass = copyrightAndOtherRestrictionsVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(copyrightAndOtherRestrictions, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if copyrightAndOtherRestrictions.subclass:
return copyrightAndOtherRestrictions.subclass(*args_, **kwargs_)
else:
return copyrightAndOtherRestrictions(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(copyrightAndOtherRestrictions, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='copyrightAndOtherRestrictions', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='copyrightAndOtherRestrictions')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='copyrightAndOtherRestrictions'):
super(copyrightAndOtherRestrictions, self).exportAttributes(outfile, level, already_processed, namespace_, name_='copyrightAndOtherRestrictions')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='copyrightAndOtherRestrictions', fromsubclass_=False, pretty_print=True):
super(copyrightAndOtherRestrictions, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='copyrightAndOtherRestrictions'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(copyrightAndOtherRestrictions, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(copyrightAndOtherRestrictions, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(copyrightAndOtherRestrictions, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(copyrightAndOtherRestrictions, self).buildChildren(child_, node, nodeName_, True)
pass
# end class copyrightAndOtherRestrictions
class cost(costVocab):
subclass = None
superclass = costVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(cost, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if cost.subclass:
return cost.subclass(*args_, **kwargs_)
else:
return cost(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(cost, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='cost', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='cost')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='cost'):
super(cost, self).exportAttributes(outfile, level, already_processed, namespace_, name_='cost')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='cost', fromsubclass_=False, pretty_print=True):
super(cost, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='cost'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(cost, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(cost, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(cost, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(cost, self).buildChildren(child_, node, nodeName_, True)
pass
# end class cost
class cognitiveProcess(cognitiveProcessVocab):
subclass = None
superclass = cognitiveProcessVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(cognitiveProcess, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if cognitiveProcess.subclass:
return cognitiveProcess.subclass(*args_, **kwargs_)
else:
return cognitiveProcess(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(cognitiveProcess, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='cognitiveProcess', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='cognitiveProcess')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='cognitiveProcess'):
super(cognitiveProcess, self).exportAttributes(outfile, level, already_processed, namespace_, name_='cognitiveProcess')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='cognitiveProcess', fromsubclass_=False, pretty_print=True):
super(cognitiveProcess, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='cognitiveProcess'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(cognitiveProcess, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(cognitiveProcess, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(cognitiveProcess, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(cognitiveProcess, self).buildChildren(child_, node, nodeName_, True)
pass
# end class cognitiveProcess
class difficulty(difficultyVocab):
subclass = None
superclass = difficultyVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(difficulty, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if difficulty.subclass:
return difficulty.subclass(*args_, **kwargs_)
else:
return difficulty(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(difficulty, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='difficulty', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='difficulty')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='difficulty'):
super(difficulty, self).exportAttributes(outfile, level, already_processed, namespace_, name_='difficulty')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='difficulty', fromsubclass_=False, pretty_print=True):
super(difficulty, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='difficulty'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(difficulty, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(difficulty, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(difficulty, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(difficulty, self).buildChildren(child_, node, nodeName_, True)
pass
# end class difficulty
class context(contextVocab):
subclass = None
superclass = contextVocab
def __init__(self, source=None, value=None, extensiontype_=None):
super(context, self).__init__(source, value, extensiontype_, )
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if context.subclass:
return context.subclass(*args_, **kwargs_)
else:
return context(*args_, **kwargs_)
factory = staticmethod(factory)
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(context, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='context', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='context')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='context'):
super(context, self).exportAttributes(outfile, level, already_processed, namespace_, name_='context')
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='context', fromsubclass_=False, pretty_print=True):
super(context, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='context'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(context, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(context, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(context, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(context, self).buildChildren(child_, node, nodeName_, True)
pass
# end class context
class intendedEndUserRole(intendedEndUserRoleVocab):
subclass = None
superclass = intendedEndUserRoleVocab
def __init__(self, source=None, value=None, extensiontype_=None):
super(intendedEndUserRole, self).__init__(source, value, extensiontype_, )
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if intendedEndUserRole.subclass:
return intendedEndUserRole.subclass(*args_, **kwargs_)
else:
return intendedEndUserRole(*args_, **kwargs_)
factory = staticmethod(factory)
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(intendedEndUserRole, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='intendedEndUserRole', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='intendedEndUserRole')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='intendedEndUserRole'):
super(intendedEndUserRole, self).exportAttributes(outfile, level, already_processed, namespace_, name_='intendedEndUserRole')
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='intendedEndUserRole', fromsubclass_=False, pretty_print=True):
super(intendedEndUserRole, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='intendedEndUserRole'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(intendedEndUserRole, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(intendedEndUserRole, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(intendedEndUserRole, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(intendedEndUserRole, self).buildChildren(child_, node, nodeName_, True)
pass
# end class intendedEndUserRole
class semanticDensity(semanticDensityVocab):
subclass = None
superclass = semanticDensityVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(semanticDensity, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if semanticDensity.subclass:
return semanticDensity.subclass(*args_, **kwargs_)
else:
return semanticDensity(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(semanticDensity, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='semanticDensity', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='semanticDensity')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='semanticDensity'):
super(semanticDensity, self).exportAttributes(outfile, level, already_processed, namespace_, name_='semanticDensity')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='semanticDensity', fromsubclass_=False, pretty_print=True):
super(semanticDensity, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='semanticDensity'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(semanticDensity, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(semanticDensity, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(semanticDensity, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(semanticDensity, self).buildChildren(child_, node, nodeName_, True)
pass
# end class semanticDensity
class interactivityLevel(interactivityLevelVocab):
subclass = None
superclass = interactivityLevelVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(interactivityLevel, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if interactivityLevel.subclass:
return interactivityLevel.subclass(*args_, **kwargs_)
else:
return interactivityLevel(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(interactivityLevel, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='interactivityLevel', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityLevel')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='interactivityLevel'):
super(interactivityLevel, self).exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityLevel')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='interactivityLevel', fromsubclass_=False, pretty_print=True):
super(interactivityLevel, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='interactivityLevel'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(interactivityLevel, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(interactivityLevel, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(interactivityLevel, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(interactivityLevel, self).buildChildren(child_, node, nodeName_, True)
pass
# end class interactivityLevel
class learningResourceType(learningResourceTypeVocab):
subclass = None
superclass = learningResourceTypeVocab
def __init__(self, source=None, value=None, extensiontype_=None):
super(learningResourceType, self).__init__(source, value, extensiontype_, )
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if learningResourceType.subclass:
return learningResourceType.subclass(*args_, **kwargs_)
else:
return learningResourceType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(learningResourceType, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='learningResourceType', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='learningResourceType')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='learningResourceType'):
super(learningResourceType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='learningResourceType')
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='learningResourceType', fromsubclass_=False, pretty_print=True):
super(learningResourceType, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='learningResourceType'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
super(learningResourceType, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(learningResourceType, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(learningResourceType, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(learningResourceType, self).buildChildren(child_, node, nodeName_, True)
pass
# end class learningResourceType
class interactivityType(interactivityTypeVocab):
subclass = None
superclass = interactivityTypeVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(interactivityType, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if interactivityType.subclass:
return interactivityType.subclass(*args_, **kwargs_)
else:
return interactivityType(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(interactivityType, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='interactivityType', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityType')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='interactivityType'):
super(interactivityType, self).exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityType')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='interactivityType', fromsubclass_=False, pretty_print=True):
super(interactivityType, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='interactivityType'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(interactivityType, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(interactivityType, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(interactivityType, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(interactivityType, self).buildChildren(child_, node, nodeName_, True)
pass
# end class interactivityType
class name(nameVocab):
subclass = None
superclass = nameVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(name, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if name.subclass:
return name.subclass(*args_, **kwargs_)
else:
return name(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(name, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='name', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='name')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='name'):
super(name, self).exportAttributes(outfile, level, already_processed, namespace_, name_='name')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='name', fromsubclass_=False, pretty_print=True):
super(name, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='name'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(name, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(name, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(name, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(name, self).buildChildren(child_, node, nodeName_, True)
pass
# end class name
class type_(typeVocab):
subclass = None
superclass = typeVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(type_, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if type_.subclass:
return type_.subclass(*args_, **kwargs_)
else:
return type_(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(type_, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='type', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='type')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='type'):
super(type_, self).exportAttributes(outfile, level, already_processed, namespace_, name_='type')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='type', fromsubclass_=False, pretty_print=True):
super(type_, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='type'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(type_, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(type_, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(type_, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(type_, self).buildChildren(child_, node, nodeName_, True)
pass
# end class type_
class roleMeta(roleMetaVocab):
subclass = None
superclass = roleMetaVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(roleMeta, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if roleMeta.subclass:
return roleMeta.subclass(*args_, **kwargs_)
else:
return roleMeta(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(roleMeta, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='roleMeta', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='roleMeta')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='roleMeta'):
super(roleMeta, self).exportAttributes(outfile, level, already_processed, namespace_, name_='roleMeta')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='roleMeta', fromsubclass_=False, pretty_print=True):
super(roleMeta, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='roleMeta'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(roleMeta, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(roleMeta, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(roleMeta, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(roleMeta, self).buildChildren(child_, node, nodeName_, True)
pass
# end class roleMeta
class role(roleVocab):
subclass = None
superclass = roleVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(role, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if role.subclass:
return role.subclass(*args_, **kwargs_)
else:
return role(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(role, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='role', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='role')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='role'):
super(role, self).exportAttributes(outfile, level, already_processed, namespace_, name_='role')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='role', fromsubclass_=False, pretty_print=True):
super(role, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='role'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(role, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(role, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(role, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(role, self).buildChildren(child_, node, nodeName_, True)
pass
# end class role
class status(statusVocab):
subclass = None
superclass = statusVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(status, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if status.subclass:
return status.subclass(*args_, **kwargs_)
else:
return status(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(status, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='status', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='status')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='status'):
super(status, self).exportAttributes(outfile, level, already_processed, namespace_, name_='status')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='status', fromsubclass_=False, pretty_print=True):
super(status, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='status'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(status, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(status, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(status, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(status, self).buildChildren(child_, node, nodeName_, True)
pass
# end class status
class aggregationLevel(aggregationLevelVocab):
subclass = None
superclass = aggregationLevelVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(aggregationLevel, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if aggregationLevel.subclass:
return aggregationLevel.subclass(*args_, **kwargs_)
else:
return aggregationLevel(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(aggregationLevel, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='aggregationLevel', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='aggregationLevel')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='aggregationLevel'):
super(aggregationLevel, self).exportAttributes(outfile, level, already_processed, namespace_, name_='aggregationLevel')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='aggregationLevel', fromsubclass_=False, pretty_print=True):
super(aggregationLevel, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='aggregationLevel'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(aggregationLevel, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(aggregationLevel, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(aggregationLevel, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(aggregationLevel, self).buildChildren(child_, node, nodeName_, True)
pass
# end class aggregationLevel
class structure(structureVocab):
subclass = None
superclass = structureVocab
def __init__(self, source=None, value=None, uniqueElementName=None, extensiontype_=None):
super(structure, self).__init__(source, value, extensiontype_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.extensiontype_ = extensiontype_
def factory(*args_, **kwargs_):
if structure.subclass:
return structure.subclass(*args_, **kwargs_)
else:
return structure(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_extensiontype_(self): return self.extensiontype_
def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
def hasContent_(self):
if (
super(structure, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='structure', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='structure')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='structure'):
super(structure, self).exportAttributes(outfile, level, already_processed, namespace_, name_='structure')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
outfile.write(' xsi:type="%s"' % self.extensiontype_)
def exportChildren(self, outfile, level, namespace_='', name_='structure', fromsubclass_=False, pretty_print=True):
super(structure, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='structure'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(structure, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(structure, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
value = find_attr_value_('xsi:type', node)
if value is not None and 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
self.extensiontype_ = value
super(structure, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
super(structure, self).buildChildren(child_, node, nodeName_, True)
pass
# end class structure
class purposeValue(purpose):
subclass = None
superclass = purpose
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(purposeValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if purposeValue.subclass:
return purposeValue.subclass(*args_, **kwargs_)
else:
return purposeValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(purposeValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='purposeValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='purposeValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='purposeValue'):
super(purposeValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='purposeValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='purposeValue', fromsubclass_=False, pretty_print=True):
super(purposeValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='purposeValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(purposeValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(purposeValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(purposeValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class purposeValue
class kindValue(kind):
subclass = None
superclass = kind
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(kindValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if kindValue.subclass:
return kindValue.subclass(*args_, **kwargs_)
else:
return kindValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(kindValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='kindValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='kindValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='kindValue'):
super(kindValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='kindValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='kindValue', fromsubclass_=False, pretty_print=True):
super(kindValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='kindValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(kindValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(kindValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(kindValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class kindValue
class accessTypeValue(accessType):
subclass = None
superclass = accessType
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(accessTypeValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if accessTypeValue.subclass:
return accessTypeValue.subclass(*args_, **kwargs_)
else:
return accessTypeValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(accessTypeValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='accessTypeValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='accessTypeValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='accessTypeValue'):
super(accessTypeValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='accessTypeValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='accessTypeValue', fromsubclass_=False, pretty_print=True):
super(accessTypeValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='accessTypeValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(accessTypeValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(accessTypeValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(accessTypeValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class accessTypeValue
class copyrightAndOtherRestrictionsValue(copyrightAndOtherRestrictions):
subclass = None
superclass = copyrightAndOtherRestrictions
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(copyrightAndOtherRestrictionsValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if copyrightAndOtherRestrictionsValue.subclass:
return copyrightAndOtherRestrictionsValue.subclass(*args_, **kwargs_)
else:
return copyrightAndOtherRestrictionsValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(copyrightAndOtherRestrictionsValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='copyrightAndOtherRestrictionsValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='copyrightAndOtherRestrictionsValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='copyrightAndOtherRestrictionsValue'):
super(copyrightAndOtherRestrictionsValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='copyrightAndOtherRestrictionsValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='copyrightAndOtherRestrictionsValue', fromsubclass_=False, pretty_print=True):
super(copyrightAndOtherRestrictionsValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='copyrightAndOtherRestrictionsValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(copyrightAndOtherRestrictionsValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(copyrightAndOtherRestrictionsValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(copyrightAndOtherRestrictionsValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class copyrightAndOtherRestrictionsValue
class costValue(cost):
subclass = None
superclass = cost
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(costValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if costValue.subclass:
return costValue.subclass(*args_, **kwargs_)
else:
return costValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(costValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='costValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='costValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='costValue'):
super(costValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='costValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='costValue', fromsubclass_=False, pretty_print=True):
super(costValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='costValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(costValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(costValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(costValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class costValue
class cognitiveProcessValue(cognitiveProcess):
subclass = None
superclass = cognitiveProcess
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(cognitiveProcessValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if cognitiveProcessValue.subclass:
return cognitiveProcessValue.subclass(*args_, **kwargs_)
else:
return cognitiveProcessValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(cognitiveProcessValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='cognitiveProcessValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='cognitiveProcessValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='cognitiveProcessValue'):
super(cognitiveProcessValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='cognitiveProcessValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='cognitiveProcessValue', fromsubclass_=False, pretty_print=True):
super(cognitiveProcessValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='cognitiveProcessValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(cognitiveProcessValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(cognitiveProcessValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(cognitiveProcessValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class cognitiveProcessValue
class difficultyValue(difficulty):
subclass = None
superclass = difficulty
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(difficultyValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if difficultyValue.subclass:
return difficultyValue.subclass(*args_, **kwargs_)
else:
return difficultyValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(difficultyValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='difficultyValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='difficultyValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='difficultyValue'):
super(difficultyValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='difficultyValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='difficultyValue', fromsubclass_=False, pretty_print=True):
super(difficultyValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='difficultyValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(difficultyValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(difficultyValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(difficultyValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class difficultyValue
class contextValue(context):
subclass = None
superclass = context
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(contextValue, self).__init__(source, value, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if contextValue.subclass:
return contextValue.subclass(*args_, **kwargs_)
else:
return contextValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(contextValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='contextValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='contextValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='contextValue'):
super(contextValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='contextValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='contextValue', fromsubclass_=False, pretty_print=True):
super(contextValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='contextValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(contextValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(contextValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(contextValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class contextValue
class intendedEndUserRoleValue(intendedEndUserRole):
subclass = None
superclass = intendedEndUserRole
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(intendedEndUserRoleValue, self).__init__(source, value, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if intendedEndUserRoleValue.subclass:
return intendedEndUserRoleValue.subclass(*args_, **kwargs_)
else:
return intendedEndUserRoleValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(intendedEndUserRoleValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='intendedEndUserRoleValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='intendedEndUserRoleValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='intendedEndUserRoleValue'):
super(intendedEndUserRoleValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='intendedEndUserRoleValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='intendedEndUserRoleValue', fromsubclass_=False, pretty_print=True):
super(intendedEndUserRoleValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='intendedEndUserRoleValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(intendedEndUserRoleValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(intendedEndUserRoleValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(intendedEndUserRoleValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class intendedEndUserRoleValue
class semanticDensityValue(semanticDensity):
subclass = None
superclass = semanticDensity
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(semanticDensityValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if semanticDensityValue.subclass:
return semanticDensityValue.subclass(*args_, **kwargs_)
else:
return semanticDensityValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(semanticDensityValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='semanticDensityValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='semanticDensityValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='semanticDensityValue'):
super(semanticDensityValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='semanticDensityValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='semanticDensityValue', fromsubclass_=False, pretty_print=True):
super(semanticDensityValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='semanticDensityValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(semanticDensityValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(semanticDensityValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(semanticDensityValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class semanticDensityValue
class interactivityLevelValue(interactivityLevel):
subclass = None
superclass = interactivityLevel
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(interactivityLevelValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if interactivityLevelValue.subclass:
return interactivityLevelValue.subclass(*args_, **kwargs_)
else:
return interactivityLevelValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(interactivityLevelValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='interactivityLevelValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityLevelValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='interactivityLevelValue'):
super(interactivityLevelValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityLevelValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='interactivityLevelValue', fromsubclass_=False, pretty_print=True):
super(interactivityLevelValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='interactivityLevelValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(interactivityLevelValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(interactivityLevelValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(interactivityLevelValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class interactivityLevelValue
class learningResourceTypeValue(learningResourceType):
subclass = None
superclass = learningResourceType
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(learningResourceTypeValue, self).__init__(source, value, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if learningResourceTypeValue.subclass:
return learningResourceTypeValue.subclass(*args_, **kwargs_)
else:
return learningResourceTypeValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(learningResourceTypeValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='learningResourceTypeValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='learningResourceTypeValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='learningResourceTypeValue'):
super(learningResourceTypeValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='learningResourceTypeValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='learningResourceTypeValue', fromsubclass_=False, pretty_print=True):
super(learningResourceTypeValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='learningResourceTypeValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(learningResourceTypeValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(learningResourceTypeValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(learningResourceTypeValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class learningResourceTypeValue
class interactivityTypeValue(interactivityType):
subclass = None
superclass = interactivityType
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(interactivityTypeValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if interactivityTypeValue.subclass:
return interactivityTypeValue.subclass(*args_, **kwargs_)
else:
return interactivityTypeValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(interactivityTypeValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='interactivityTypeValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityTypeValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='interactivityTypeValue'):
super(interactivityTypeValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='interactivityTypeValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='interactivityTypeValue', fromsubclass_=False, pretty_print=True):
super(interactivityTypeValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='interactivityTypeValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(interactivityTypeValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(interactivityTypeValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(interactivityTypeValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class interactivityTypeValue
class nameValue(name):
subclass = None
superclass = name
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(nameValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if nameValue.subclass:
return nameValue.subclass(*args_, **kwargs_)
else:
return nameValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(nameValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='nameValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='nameValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='nameValue'):
super(nameValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='nameValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='nameValue', fromsubclass_=False, pretty_print=True):
super(nameValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='nameValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(nameValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(nameValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(nameValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class nameValue
class typeValue(type_):
subclass = None
superclass = type_
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(typeValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if typeValue.subclass:
return typeValue.subclass(*args_, **kwargs_)
else:
return typeValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(typeValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='typeValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='typeValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='typeValue'):
super(typeValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='typeValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='typeValue', fromsubclass_=False, pretty_print=True):
super(typeValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='typeValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(typeValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(typeValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(typeValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class typeValue
class roleMetaValue(roleMeta):
subclass = None
superclass = roleMeta
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(roleMetaValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if roleMetaValue.subclass:
return roleMetaValue.subclass(*args_, **kwargs_)
else:
return roleMetaValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(roleMetaValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='roleMetaValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='roleMetaValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='roleMetaValue'):
super(roleMetaValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='roleMetaValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='roleMetaValue', fromsubclass_=False, pretty_print=True):
super(roleMetaValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='roleMetaValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(roleMetaValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(roleMetaValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(roleMetaValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class roleMetaValue
class roleValue(role):
subclass = None
superclass = role
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(roleValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if roleValue.subclass:
return roleValue.subclass(*args_, **kwargs_)
else:
return roleValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(roleValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='roleValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='roleValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='roleValue'):
super(roleValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='roleValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='roleValue', fromsubclass_=False, pretty_print=True):
super(roleValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='roleValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(roleValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(roleValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(roleValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class roleValue
class statusValue(status):
subclass = None
superclass = status
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(statusValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if statusValue.subclass:
return statusValue.subclass(*args_, **kwargs_)
else:
return statusValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(statusValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='statusValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='statusValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='statusValue'):
super(statusValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='statusValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='statusValue', fromsubclass_=False, pretty_print=True):
super(statusValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='statusValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(statusValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(statusValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(statusValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class statusValue
class aggregationLevelValue(aggregationLevel):
subclass = None
superclass = aggregationLevel
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(aggregationLevelValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if aggregationLevelValue.subclass:
return aggregationLevelValue.subclass(*args_, **kwargs_)
else:
return aggregationLevelValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(aggregationLevelValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='aggregationLevelValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='aggregationLevelValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='aggregationLevelValue'):
super(aggregationLevelValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='aggregationLevelValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='aggregationLevelValue', fromsubclass_=False, pretty_print=True):
super(aggregationLevelValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='aggregationLevelValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(aggregationLevelValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(aggregationLevelValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(aggregationLevelValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class aggregationLevelValue
class structureValue(structure):
subclass = None
superclass = structure
def __init__(self, source=None, value=None, uniqueElementName=None, valueOf_=None):
super(structureValue, self).__init__(source, value, uniqueElementName, valueOf_, )
self.uniqueElementName = _cast(None, uniqueElementName)
self.valueOf_ = valueOf_
def factory(*args_, **kwargs_):
if structureValue.subclass:
return structureValue.subclass(*args_, **kwargs_)
else:
return structureValue(*args_, **kwargs_)
factory = staticmethod(factory)
def get_uniqueElementName(self): return self.uniqueElementName
def set_uniqueElementName(self, uniqueElementName): self.uniqueElementName = uniqueElementName
def get_valueOf_(self): return self.valueOf_
def set_valueOf_(self, valueOf_): self.valueOf_ = valueOf_
def hasContent_(self):
if (
self.valueOf_ or
super(structureValue, self).hasContent_()
):
return True
else:
return False
def export(self, outfile, level, namespace_='', name_='structureValue', namespacedef_='', pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
self.exportAttributes(outfile, level, already_processed, namespace_, name_='structureValue')
if self.hasContent_():
outfile.write('>')
outfile.write(str(self.valueOf_).encode(ExternalEncoding))
self.exportChildren(outfile, level + 1, namespace_, name_, pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespace_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='structureValue'):
super(structureValue, self).exportAttributes(outfile, level, already_processed, namespace_, name_='structureValue')
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
outfile.write(' uniqueElementName=%s' % (self.gds_format_string(quote_attrib(self.uniqueElementName).encode(ExternalEncoding), input_name='uniqueElementName'), ))
def exportChildren(self, outfile, level, namespace_='', name_='structureValue', fromsubclass_=False, pretty_print=True):
super(structureValue, self).exportChildren(outfile, level, namespace_, name_, True, pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='structureValue'):
level += 1
already_processed = set()
self.exportLiteralAttributes(outfile, level, already_processed, name_)
if self.hasContent_():
self.exportLiteralChildren(outfile, level, name_)
showIndent(outfile, level)
outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,))
def exportLiteralAttributes(self, outfile, level, already_processed, name_):
if self.uniqueElementName is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
showIndent(outfile, level)
outfile.write('uniqueElementName = "%s",\n' % (self.uniqueElementName,))
super(structureValue, self).exportLiteralAttributes(outfile, level, already_processed, name_)
def exportLiteralChildren(self, outfile, level, name_):
super(structureValue, self).exportLiteralChildren(outfile, level, name_)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
self.valueOf_ = get_all_text_(node)
for child in node:
nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
self.buildChildren(child, node, nodeName_)
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('uniqueElementName', node)
if value is not None and 'uniqueElementName' not in already_processed:
already_processed.add('uniqueElementName')
self.uniqueElementName = value
super(structureValue, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
pass
# end class structureValue
GDSClassesMapping = {
'description': LanguageString,
'language': LanguageId,
'contribute': contributeMeta,
'value': purposeValue,
'entity': VCard,
'source': sourceValue,
'role': roleMeta,
'duration': DurationValue,
'entry': LanguageString,
'dateTime': DateTimeValue,
'string': LangString,
}
USAGE_TEXT = """
Usage: python <Parser>.py [ -s ] <in_xml_file>
"""
def usage():
print USAGE_TEXT
sys.exit(1)
def get_root_tag(node):
tag = Tag_pattern_.match(node.tag).groups()[-1]
rootClass = GDSClassesMapping.get(tag)
if rootClass is None:
rootClass = globals().get(tag)
return tag, rootClass
def parse(inFileName):
doc = parsexml_(inFileName)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'lom'
rootClass = lom
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
sys.stdout.write('<?xml version="1.0" ?>\n')
rootObj.export(sys.stdout, 0, name_=rootTag,
namespacedef_='',
pretty_print=True)
return rootObj
def parseEtree(inFileName):
doc = parsexml_(inFileName)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'lom'
rootClass = lom
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
rootElement = rootObj.to_etree(None, name_=rootTag)
content = etree_.tostring(rootElement, pretty_print=True,
xml_declaration=True, encoding="utf-8")
sys.stdout.write(content)
sys.stdout.write('\n')
return rootObj, rootElement
def parseString(inString):
from StringIO import StringIO
doc = parsexml_(StringIO(inString))
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'lom'
rootClass = lom
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
sys.stdout.write('<?xml version="1.0" ?>\n')
rootObj.export(sys.stdout, 0, name_="lom",
namespacedef_='')
return rootObj
def parseLiteral(inFileName):
doc = parsexml_(inFileName)
rootNode = doc.getroot()
rootTag, rootClass = get_root_tag(rootNode)
if rootClass is None:
rootTag = 'lom'
rootClass = lom
rootObj = rootClass.factory()
rootObj.build(rootNode)
# Enable Python to collect the space used by the DOM.
doc = None
sys.stdout.write('#from lom import *\n\n')
sys.stdout.write('from datetime import datetime as datetime_\n\n')
sys.stdout.write('import lom as model_\n\n')
sys.stdout.write('rootObj = model_.rootTag(\n')
rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
sys.stdout.write(')\n')
return rootObj
def main():
args = sys.argv[1:]
if len(args) == 1:
parse(args[0])
else:
usage()
if __name__ == '__main__':
#import pdb; pdb.set_trace()
main()
__all__ = [
"DateTime",
"DateTimeValue",
"Duration",
"DurationValue",
"LangString",
"LanguageId",
"LanguageString",
"VCard",
"access",
"accessType",
"accessTypeValue",
"accessTypeVocab",
"aggregationLevel",
"aggregationLevelValue",
"aggregationLevelVocab",
"annotation",
"catalog",
"classification",
"cognitiveProcess",
"cognitiveProcessValue",
"cognitiveProcessVocab",
"context",
"contextValue",
"contextVocab",
"contribute",
"contributeMeta",
"copyrightAndOtherRestrictions",
"copyrightAndOtherRestrictionsValue",
"copyrightAndOtherRestrictionsVocab",
"cost",
"costValue",
"costVocab",
"coverage",
"date",
"description",
"difficulty",
"difficultyValue",
"difficultyVocab",
"duration",
"educational",
"entity",
"entry",
"entryTaxon",
"format",
"general",
"id",
"identifier",
"installationRemarks",
"intendedEndUserRole",
"intendedEndUserRoleValue",
"intendedEndUserRoleVocab",
"interactivityLevel",
"interactivityLevelValue",
"interactivityLevelVocab",
"interactivityType",
"interactivityTypeValue",
"interactivityTypeVocab",
"keyword",
"kind",
"kindValue",
"kindVocab",
"language",
"learningResourceType",
"learningResourceTypeValue",
"learningResourceTypeVocab",
"lifeCycle",
"location",
"lom",
"maximumVersion",
"metaMetadata",
"metadataSchema",
"minimumVersion",
"name",
"nameValue",
"nameVocab",
"orComposite",
"otherPlatformRequirements",
"purpose",
"purposeValue",
"purposeVocab",
"relation",
"requirement",
"resource",
"rights",
"role",
"roleMeta",
"roleMetaValue",
"roleMetaVocab",
"roleValue",
"roleVocab",
"semanticDensity",
"semanticDensityValue",
"semanticDensityVocab",
"size",
"source",
"sourceValue",
"status",
"statusValue",
"statusVocab",
"structure",
"structureValue",
"structureVocab",
"taxon",
"taxonPath",
"technical",
"title",
"typeValue",
"typeVocab",
"type_",
"typicalAgeRange",
"typicalLearningTime",
"version"
]
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
199,
3,
17065,
31712,
10162,
1616,
4944,
26,
1344,
26,
2006,
6171,
701,
3550,
3177,
14,
647,
1015,
499,
14,
25,
65,
14,
199,
3,
199,
199,
646,
984,
199,
646,
12733,
199,
646,
295,
465,
295,
63,
199,
646,
1300,
772,
199,
504,
2197,
492,
2197,
12,
10313,
12,
6871,
199,
504,
7390,
14,
29889,
14,
74,
29051,
492,
1910,
74,
29051,
461,
199,
199,
9464,
63,
275,
488,
199,
21879,
63,
646,
63,
275,
756,
199,
8,
257,
4692,
2842,
63,
646,
63,
3592,
12,
4692,
2842,
63,
646,
63,
22899,
12,
272,
4692,
2842,
63,
646,
63,
2108,
2350,
272,
776,
275,
1425,
8,
19,
9,
199,
4317,
2842,
63,
646,
63,
4342,
275,
488,
199,
893,
26,
272,
327,
14490,
272,
687,
14490,
492,
7559,
465,
7559,
63,
272,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
22899,
272,
340,
5444,
2220,
63,
646,
10388,
267,
870,
480,
5720,
543,
14490,
14,
9464,
531,
199,
2590,
3545,
26,
272,
862,
26,
267,
327,
286,
15325,
687,
2018,
499,
14,
21,
11,
267,
492,
2748,
14,
9464,
14,
67,
15325,
465,
7559,
63,
267,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
267,
340,
5444,
2220,
63,
646,
10388,
288,
870,
480,
5720,
543,
286,
15325,
641,
2018,
499,
14,
21,
21425,
272,
871,
3545,
26,
267,
862,
26,
288,
327,
13139,
687,
2018,
499,
14,
21,
11,
288,
492,
2748,
14,
9464,
14,
15325,
465,
7559,
63,
288,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
288,
340,
5444,
2220,
63,
646,
10388,
355,
870,
480,
5720,
543,
13139,
641,
2018,
499,
14,
21,
21425,
267,
871,
3545,
26,
288,
862,
26,
355,
327,
3293,
286,
15325,
3907,
355,
492,
286,
15325,
465,
7559,
63,
355,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
355,
340,
5444,
2220,
63,
646,
10388,
490,
870,
480,
5720,
543,
286,
15325,
531,
288,
871,
3545,
26,
355,
862,
26,
490,
327,
3293,
13139,
3907,
490,
492,
1819,
2350,
14,
15325,
465,
7559,
63,
490,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
490,
340,
5444,
2220,
63,
646,
10388,
717,
870,
480,
5720,
543,
13139,
531,
355,
871,
3545,
26,
490,
746,
3545,
8,
717,
298,
4276,
370,
492,
13139,
687,
1263,
6040,
4192,
531,
199,
199,
318,
2198,
1652,
63,
2031,
589,
12,
1011,
958,
304,
272,
340,
334,
4317,
2842,
63,
646,
63,
4342,
508,
4692,
2842,
63,
646,
63,
22899,
436,
267,
283,
2087,
7,
440,
315,
2074,
304,
267,
327,
3645,
314,
14490,
13139,
9025,
1798,
880,
626,
12,
325,
14,
71,
2020,
267,
327,
257,
781,
3686,
6786,
14,
267,
2074,
459,
2087,
418,
275,
7559,
3754,
775,
2404,
292,
4317,
2842,
342,
272,
1382,
275,
7559,
3754,
1122,
2031,
589,
12,
1011,
958,
9,
272,
372,
1382,
199,
199,
3,
199,
3,
2876,
3102,
199,
3,
199,
3,
28055,
370,
314,
3102,
315,
3520,
3992,
787,
4046,
701,
3550,
3177,
14,
647,
14,
199,
3,
2047,
883,
3350,
3520,
3102,
701,
295,
13,
21463,
316,
314,
2569,
1021,
199,
3,
257,
315,
282,
859,
4310,
4046,
385,
27951,
14,
647,
14,
199,
199,
893,
26,
272,
687,
4046,
385,
27951,
492,
7958,
795,
11823,
199,
2590,
3545,
12,
1437,
26,
272,
687,
7390,
14,
29889,
14,
74,
29051,
492,
1603,
29051,
461,
12,
1910,
74,
29051,
461,
339,
1021,
7958,
795,
11823,
8,
785,
12,
1603,
29051,
461,
12,
1910,
74,
29051,
461,
304,
267,
5823,
1997,
63,
3401,
275,
295,
3754,
2014,
8,
82,
13445,
21449,
13,
9,
1332,
16,
60,
68,
92,
17,
59,
16,
13,
19,
4682,
59,
16,
13,
21,
7272,
68,
92,
1079,
26,
383,
9,
9988,
267,
1021,
485,
9515,
6397,
14226,
8,
9374,
304,
288,
347,
636,
826,
721,
277,
12,
3268,
12,
536,
304,
355,
291,
855,
2743,
275,
6871,
8,
10430,
275,
3268,
9,
355,
291,
855,
354,
275,
536,
288,
347,
11430,
18102,
8,
277,
12,
4487,
304,
355,
372,
291,
855,
2743,
288,
347,
28054,
8,
277,
12,
4487,
304,
355,
372,
291,
855,
354,
288,
347,
5042,
8,
277,
12,
4487,
304,
355,
372,
488,
267,
347,
486,
795,
63,
908,
63,
875,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
3502,
63,
875,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
1095,
772,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1300,
772,
14,
66,
772,
2143,
8,
1210,
63,
576,
9,
267,
347,
486,
795,
63,
3502,
63,
1095,
772,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
4115,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1543,
68,
7,
450,
1324,
63,
576,
267,
347,
486,
795,
63,
3502,
63,
4115,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
4115,
63,
513,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1543,
83,
7,
450,
1324,
63,
576,
267,
347,
486,
795,
63,
3502,
63,
4115,
63,
513,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
1338,
275,
1324,
63,
576,
14,
1294,
342,
288,
367,
574,
315,
1338,
26,
355,
862,
26,
490,
289,
585,
275,
2069,
8,
585,
9,
355,
871,
334,
4333,
12,
1722,
395,
1437,
26,
490,
746,
63,
1122,
63,
705,
8,
932,
12,
283,
18153,
3414,
402,
9446,
358,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
1609,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
199,
3,
17065,
31712,
10162,
1616,
4944,
26,
1344,
26,
2006,
6171,
701,
3550,
3177,
14,
647,
1015,
499,
14,
25,
65,
14,
199,
3,
199,
199,
646,
984,
199,
646,
12733,
199,
646,
295,
465,
295,
63,
199,
646,
1300,
772,
199,
504,
2197,
492,
2197,
12,
10313,
12,
6871,
199,
504,
7390,
14,
29889,
14,
74,
29051,
492,
1910,
74,
29051,
461,
199,
199,
9464,
63,
275,
488,
199,
21879,
63,
646,
63,
275,
756,
199,
8,
257,
4692,
2842,
63,
646,
63,
3592,
12,
4692,
2842,
63,
646,
63,
22899,
12,
272,
4692,
2842,
63,
646,
63,
2108,
2350,
272,
776,
275,
1425,
8,
19,
9,
199,
4317,
2842,
63,
646,
63,
4342,
275,
488,
199,
893,
26,
272,
327,
14490,
272,
687,
14490,
492,
7559,
465,
7559,
63,
272,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
22899,
272,
340,
5444,
2220,
63,
646,
10388,
267,
870,
480,
5720,
543,
14490,
14,
9464,
531,
199,
2590,
3545,
26,
272,
862,
26,
267,
327,
286,
15325,
687,
2018,
499,
14,
21,
11,
267,
492,
2748,
14,
9464,
14,
67,
15325,
465,
7559,
63,
267,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
267,
340,
5444,
2220,
63,
646,
10388,
288,
870,
480,
5720,
543,
286,
15325,
641,
2018,
499,
14,
21,
21425,
272,
871,
3545,
26,
267,
862,
26,
288,
327,
13139,
687,
2018,
499,
14,
21,
11,
288,
492,
2748,
14,
9464,
14,
15325,
465,
7559,
63,
288,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
288,
340,
5444,
2220,
63,
646,
10388,
355,
870,
480,
5720,
543,
13139,
641,
2018,
499,
14,
21,
21425,
267,
871,
3545,
26,
288,
862,
26,
355,
327,
3293,
286,
15325,
3907,
355,
492,
286,
15325,
465,
7559,
63,
355,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
355,
340,
5444,
2220,
63,
646,
10388,
490,
870,
480,
5720,
543,
286,
15325,
531,
288,
871,
3545,
26,
355,
862,
26,
490,
327,
3293,
13139,
3907,
490,
492,
1819,
2350,
14,
15325,
465,
7559,
63,
490,
4692,
2842,
63,
646,
63,
4342,
275,
4692,
2842,
63,
646,
63,
2108,
2350,
490,
340,
5444,
2220,
63,
646,
10388,
717,
870,
480,
5720,
543,
13139,
531,
355,
871,
3545,
26,
490,
746,
3545,
8,
717,
298,
4276,
370,
492,
13139,
687,
1263,
6040,
4192,
531,
199,
199,
318,
2198,
1652,
63,
2031,
589,
12,
1011,
958,
304,
272,
340,
334,
4317,
2842,
63,
646,
63,
4342,
508,
4692,
2842,
63,
646,
63,
22899,
436,
267,
283,
2087,
7,
440,
315,
2074,
304,
267,
327,
3645,
314,
14490,
13139,
9025,
1798,
880,
626,
12,
325,
14,
71,
2020,
267,
327,
257,
781,
3686,
6786,
14,
267,
2074,
459,
2087,
418,
275,
7559,
3754,
775,
2404,
292,
4317,
2842,
342,
272,
1382,
275,
7559,
3754,
1122,
2031,
589,
12,
1011,
958,
9,
272,
372,
1382,
199,
199,
3,
199,
3,
2876,
3102,
199,
3,
199,
3,
28055,
370,
314,
3102,
315,
3520,
3992,
787,
4046,
701,
3550,
3177,
14,
647,
14,
199,
3,
2047,
883,
3350,
3520,
3102,
701,
295,
13,
21463,
316,
314,
2569,
1021,
199,
3,
257,
315,
282,
859,
4310,
4046,
385,
27951,
14,
647,
14,
199,
199,
893,
26,
272,
687,
4046,
385,
27951,
492,
7958,
795,
11823,
199,
2590,
3545,
12,
1437,
26,
272,
687,
7390,
14,
29889,
14,
74,
29051,
492,
1603,
29051,
461,
12,
1910,
74,
29051,
461,
339,
1021,
7958,
795,
11823,
8,
785,
12,
1603,
29051,
461,
12,
1910,
74,
29051,
461,
304,
267,
5823,
1997,
63,
3401,
275,
295,
3754,
2014,
8,
82,
13445,
21449,
13,
9,
1332,
16,
60,
68,
92,
17,
59,
16,
13,
19,
4682,
59,
16,
13,
21,
7272,
68,
92,
1079,
26,
383,
9,
9988,
267,
1021,
485,
9515,
6397,
14226,
8,
9374,
304,
288,
347,
636,
826,
721,
277,
12,
3268,
12,
536,
304,
355,
291,
855,
2743,
275,
6871,
8,
10430,
275,
3268,
9,
355,
291,
855,
354,
275,
536,
288,
347,
11430,
18102,
8,
277,
12,
4487,
304,
355,
372,
291,
855,
2743,
288,
347,
28054,
8,
277,
12,
4487,
304,
355,
372,
291,
855,
354,
288,
347,
5042,
8,
277,
12,
4487,
304,
355,
372,
488,
267,
347,
486,
795,
63,
908,
63,
875,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
3502,
63,
875,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
1095,
772,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1300,
772,
14,
66,
772,
2143,
8,
1210,
63,
576,
9,
267,
347,
486,
795,
63,
3502,
63,
1095,
772,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
4115,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1543,
68,
7,
450,
1324,
63,
576,
267,
347,
486,
795,
63,
3502,
63,
4115,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
372,
1324,
63,
576,
267,
347,
486,
795,
63,
908,
63,
4115,
63,
513,
8,
277,
12,
1324,
63,
576,
12,
1324,
63,
354,
9280,
288,
372,
1543,
83,
7,
450,
1324,
63,
576,
267,
347,
486,
795,
63,
3502,
63,
4115,
63,
513,
8,
277,
12,
1324,
63,
576,
12,
1031,
12,
1324,
63,
354,
9280,
288,
1338,
275,
1324,
63,
576,
14,
1294,
342,
288,
367,
574,
315,
1338,
26,
355,
862,
26,
490,
289,
585,
275,
2069,
8,
585,
9,
355,
871,
334,
4333,
12,
1722,
395,
1437,
26,
490,
746,
63,
1122,
63,
705,
8,
932,
12,
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,
1,
1,
1,
1,
1,
1,
1,
1
] |
ryfeus/lambda-packs
|
Tensorflow_Pandas_Numpy/source3.6/tensorflow/python/keras/applications/inception_v3/__init__.py
|
74
|
1161
|
# 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.
# ==============================================================================
"""Inception V3 Keras application."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.keras._impl.keras.applications.inception_v3 import decode_predictions
from tensorflow.python.keras._impl.keras.applications.inception_v3 import InceptionV3
from tensorflow.python.keras._impl.keras.applications.inception_v3 import preprocess_input
del absolute_import
del division
del print_function
|
mit
|
[
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,
607,
814,
812,
19,
1804,
30037,
4223,
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,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
15853,
14,
262,
814,
63,
86,
19,
492,
4849,
63,
9869,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
15853,
14,
262,
814,
63,
86,
19,
492,
1010,
814,
54,
19,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
15853,
14,
262,
814,
63,
86,
19,
492,
23351,
63,
1210,
199,
199,
2264,
3679,
63,
646,
199,
2264,
4629,
199,
2264,
870,
63,
1593,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
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,
607,
814,
812,
19,
1804,
30037,
4223,
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,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
15853,
14,
262,
814,
63,
86,
19,
492,
4849,
63,
9869,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
15853,
14,
262,
814,
63,
86,
19,
492,
1010,
814,
54,
19,
199,
504,
3228,
14,
1548,
14,
8811,
423,
5472,
14,
8811,
14,
15853,
14,
262,
814,
63,
86,
19,
492,
23351,
63,
1210,
199,
199,
2264,
3679,
63,
646,
199,
2264,
4629,
199,
2264,
870,
63,
1593,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mdakin/engine
|
build/protoc_java.py
|
78
|
2330
|
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Generate java source files from protobuf files.
This is a helper file for the genproto_java action in protoc_java.gypi.
It performs the following steps:
1. Deletes all old sources (ensures deleted classes are not part of new jars).
2. Creates source directory.
3. Generates Java files using protoc (output into either --java-out-dir or
--srcjar).
4. Creates a new stamp file.
"""
import os
import optparse
import shutil
import subprocess
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "android", "gyp"))
from util import build_utils
def main(argv):
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option("--protoc", help="Path to protoc binary.")
parser.add_option("--proto-path", help="Path to proto directory.")
parser.add_option("--java-out-dir",
help="Path to output directory for java files.")
parser.add_option("--srcjar", help="Path to output srcjar.")
parser.add_option("--stamp", help="File to touch on success.")
options, args = parser.parse_args(argv)
build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
if not options.java_out_dir and not options.srcjar:
print 'One of --java-out-dir or --srcjar must be specified.'
return 1
with build_utils.TempDir() as temp_dir:
# Specify arguments to the generator.
generator_args = ['optional_field_style=reftypes',
'store_unknown_fields=true']
out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + temp_dir
# Generate Java files using protoc.
build_utils.CheckOutput(
[options.protoc, '--proto_path', options.proto_path, out_arg]
+ args)
if options.java_out_dir:
build_utils.DeleteDirectory(options.java_out_dir)
shutil.copytree(temp_dir, options.java_out_dir)
else:
build_utils.ZipDir(options.srcjar, temp_dir)
if options.depfile:
build_utils.WriteDepfile(
options.depfile,
args + [options.protoc] + build_utils.GetPythonDependencies())
if options.stamp:
build_utils.Touch(options.stamp)
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
6864,
12120,
1350,
1584,
687,
25886,
1584,
14,
199,
199,
2765,
365,
282,
5922,
570,
367,
314,
3805,
2625,
63,
6138,
1595,
315,
4104,
67,
63,
6138,
14,
4312,
1038,
14,
199,
199,
7940,
18628,
314,
2569,
7124,
26,
199,
17,
14,
28382,
1006,
2269,
5274,
334,
8764,
1482,
5463,
3992,
787,
440,
1777,
402,
892,
1335,
4291,
680,
199,
18,
14,
10560,
1350,
2082,
14,
199,
19,
14,
21687,
9586,
1584,
1808,
4104,
67,
334,
1199,
1901,
1902,
1553,
6138,
13,
548,
13,
694,
503,
2043,
1553,
2164,
7338,
680,
199,
20,
14,
10560,
282,
892,
16206,
570,
14,
199,
624,
199,
199,
646,
747,
199,
646,
8691,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
6238,
401,
298,
6179,
2237,
199,
504,
4884,
492,
1900,
63,
1208,
199,
199,
318,
2446,
8,
3020,
304,
523,
1798,
275,
8691,
14,
14553,
342,
523,
1900,
63,
1208,
14,
1123,
8598,
493,
2602,
8,
2087,
9,
523,
1798,
14,
525,
63,
1422,
6739,
16311,
401,
1720,
628,
2042,
370,
4104,
67,
3366,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
2625,
13,
515,
401,
1720,
628,
2042,
370,
4104,
2082,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
6138,
13,
548,
13,
694,
401,
489,
1720,
628,
2042,
370,
1072,
2082,
367,
12120,
1584,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
2164,
7338,
401,
1720,
628,
2042,
370,
1072,
2928,
7338,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
2359,
401,
1720,
628,
1173,
370,
12943,
641,
3182,
2685,
523,
1511,
12,
1249,
275,
1798,
14,
1122,
63,
589,
8,
3020,
9,
819,
1900,
63,
1208,
14,
1799,
4558,
8,
1419,
12,
1798,
12,
788,
16311,
297,
283,
2625,
63,
515,
1105,
523,
340,
440,
1511,
14,
6138,
63,
548,
63,
694,
436,
440,
1511,
14,
2164,
7338,
26,
272,
870,
283,
4395,
402,
1553,
6138,
13,
548,
13,
694,
503,
1553,
2164,
7338,
1471,
506,
2013,
3530,
272,
372,
413,
819,
543,
1900,
63,
1208,
14,
29008,
342,
465,
2388,
63,
694,
26,
272,
327,
13327,
2368,
370,
314,
4306,
14,
272,
4306,
63,
589,
275,
788,
4144,
63,
698,
63,
2487,
29,
1121,
1313,
297,
1993,
283,
1617,
63,
5187,
63,
955,
29,
2052,
418,
272,
734,
63,
1273,
275,
2850,
30738,
290,
8143,
63,
548,
534,
435,
12814,
904,
8,
4679,
63,
589,
9,
435,
10871,
435,
2388,
63,
694,
272,
327,
7958,
9586,
1584,
1808,
4104,
67,
14,
272,
1900,
63,
1208,
14,
1799,
2959,
8,
267,
359,
1419,
14,
16311,
12,
2850,
2625,
63,
515,
297,
1511,
14,
2625,
63,
515,
12,
734,
63,
1273,
61,
267,
435,
1249,
9,
339,
340,
1511,
14,
6138,
63,
548,
63,
694,
26,
489,
1900,
63,
1208,
14,
5392,
6231,
8,
1419,
14,
6138,
63,
548,
63,
694,
9,
489,
5145,
14,
29296,
8,
808,
63,
694,
12,
1511,
14,
6138,
63,
548,
63,
694,
9,
272,
587,
26,
489,
1900,
63,
1208,
14,
8674,
3567,
8,
1419,
14,
2164,
7338,
12,
2388,
63,
694,
9,
819,
340,
1511,
14,
2601,
493,
26,
272,
1900,
63,
1208,
14,
3534,
8598,
493,
8,
267,
1511,
14,
2601,
493,
12,
267,
1249,
435,
359,
1419,
14,
16311,
61,
435,
1900,
63,
1208,
14,
1002,
4718,
11927,
1012,
819,
340,
1511,
14,
2359,
26,
272,
1900,
63,
1208,
14,
52,
13087,
8,
1419,
14,
2359,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
59,
17,
16720,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
6864,
12120,
1350,
1584,
687,
25886,
1584,
14,
199,
199,
2765,
365,
282,
5922,
570,
367,
314,
3805,
2625,
63,
6138,
1595,
315,
4104,
67,
63,
6138,
14,
4312,
1038,
14,
199,
199,
7940,
18628,
314,
2569,
7124,
26,
199,
17,
14,
28382,
1006,
2269,
5274,
334,
8764,
1482,
5463,
3992,
787,
440,
1777,
402,
892,
1335,
4291,
680,
199,
18,
14,
10560,
1350,
2082,
14,
199,
19,
14,
21687,
9586,
1584,
1808,
4104,
67,
334,
1199,
1901,
1902,
1553,
6138,
13,
548,
13,
694,
503,
2043,
1553,
2164,
7338,
680,
199,
20,
14,
10560,
282,
892,
16206,
570,
14,
199,
624,
199,
199,
646,
747,
199,
646,
8691,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
6238,
401,
298,
6179,
2237,
199,
504,
4884,
492,
1900,
63,
1208,
199,
199,
318,
2446,
8,
3020,
304,
523,
1798,
275,
8691,
14,
14553,
342,
523,
1900,
63,
1208,
14,
1123,
8598,
493,
2602,
8,
2087,
9,
523,
1798,
14,
525,
63,
1422,
6739,
16311,
401,
1720,
628,
2042,
370,
4104,
67,
3366,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
2625,
13,
515,
401,
1720,
628,
2042,
370,
4104,
2082,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
6138,
13,
548,
13,
694,
401,
489,
1720,
628,
2042,
370,
1072,
2082,
367,
12120,
1584,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
2164,
7338,
401,
1720,
628,
2042,
370,
1072,
2928,
7338,
2685,
523,
1798,
14,
525,
63,
1422,
6739,
2359,
401,
1720,
628,
1173,
370,
12943,
641,
3182,
2685,
523,
1511,
12,
1249,
275,
1798,
14,
1122,
63,
589,
8,
3020,
9,
819,
1900,
63,
1208,
14,
1799,
4558,
8,
1419,
12,
1798,
12,
788,
16311,
297,
283,
2625,
63,
515,
1105,
523,
340,
440,
1511,
14,
6138,
63,
548,
63,
694,
436,
440,
1511,
14,
2164,
7338,
26,
272,
870,
283,
4395,
402,
1553,
6138,
13,
548,
13,
694,
503,
1553,
2164,
7338,
1471,
506,
2013,
3530,
272,
372,
413,
819,
543,
1900,
63,
1208,
14,
29008,
342,
465,
2388,
63,
694,
26,
272,
327,
13327,
2368,
370,
314,
4306,
14,
272,
4306,
63,
589,
275,
788,
4144,
63,
698,
63,
2487,
29,
1121,
1313,
297,
1993,
283,
1617,
63,
5187,
63,
955,
29,
2052,
418,
272,
734,
63,
1273,
275,
2850,
30738,
290,
8143,
63,
548,
534,
435,
12814,
904,
8,
4679,
63,
589,
9,
435,
10871,
435,
2388,
63,
694,
272,
327,
7958,
9586,
1584,
1808,
4104,
67,
14,
272,
1900,
63,
1208,
14,
1799,
2959,
8,
267,
359,
1419,
14,
16311,
12,
2850,
2625,
63,
515,
297,
1511,
14,
2625,
63,
515,
12,
734,
63,
1273,
61,
267,
435,
1249,
9,
339,
340,
1511,
14,
6138,
63,
548,
63,
694,
26,
489,
1900,
63,
1208,
14,
5392,
6231,
8,
1419,
14,
6138,
63,
548,
63,
694,
9,
489,
5145,
14,
29296,
8,
808,
63,
694,
12,
1511,
14,
6138,
63,
548,
63,
694,
9,
272,
587,
26,
489,
1900,
63,
1208,
14,
8674,
3567,
8,
1419,
14,
2164,
7338,
12,
2388,
63,
694,
9,
819,
340,
1511,
14,
2601,
493,
26,
272,
1900,
63,
1208,
14,
3534,
8598,
493,
8,
267,
1511,
14,
2601,
493,
12,
267,
1249,
435,
359,
1419,
14,
16311,
61,
435,
1900,
63,
1208,
14,
1002,
4718,
11927,
1012,
819,
340,
1511,
14,
2359,
26,
272,
1900,
63,
1208,
14,
52,
13087,
8,
1419,
14,
2359,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
984,
14,
2224,
8,
973,
8,
1274,
14,
3020,
59,
17,
16720,
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,
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,
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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
] |
intgr/django-cms
|
cms/test_utils/testcases.py
|
4
|
15135
|
# -*- coding: utf-8 -*-
import sys
import json
from cms.compat import get_user_model
from cms.models import Page
from cms.test_utils.util.context_managers import (UserLoginContext,
SettingsOverride)
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, Permission
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.template.context import Context
from django.test import testcases
from django.test.client import RequestFactory
from django.utils.translation import activate
from menus.menu_pool import menu_pool
from cms.utils.compat.urls import urljoin, unquote
import warnings
from cms.utils.permissions import set_current_user
URL_CMS_PAGE = "/en/admin/cms/page/"
URL_CMS_PAGE_ADD = urljoin(URL_CMS_PAGE, "add/")
URL_CMS_PAGE_CHANGE = urljoin(URL_CMS_PAGE, "%d/")
URL_CMS_PAGE_ADVANCED_CHANGE = urljoin(URL_CMS_PAGE, "%d/advanced-settings/")
URL_CMS_PAGE_PERMISSION_CHANGE = urljoin(URL_CMS_PAGE, "%d/permission-settings/")
URL_CMS_PAGE_CHANGE_LANGUAGE = URL_CMS_PAGE_CHANGE + "?language=%s"
URL_CMS_PAGE_CHANGE_TEMPLATE = URL_CMS_PAGE_CHANGE + "change_template/"
URL_CMS_PAGE_PUBLISH = URL_CMS_PAGE_CHANGE + "%s/publish/"
URL_CMS_PAGE_DELETE = urljoin(URL_CMS_PAGE_CHANGE, "delete/")
URL_CMS_PLUGIN_ADD = urljoin(URL_CMS_PAGE, "add-plugin/")
URL_CMS_PLUGIN_EDIT = urljoin(URL_CMS_PAGE, "edit-plugin/")
URL_CMS_PLUGIN_MOVE = urljoin(URL_CMS_PAGE, "move-plugin/")
URL_CMS_PLUGIN_REMOVE = urljoin(URL_CMS_PAGE, "delete-plugin/")
URL_CMS_TRANSLATION_DELETE = urljoin(URL_CMS_PAGE_CHANGE, "delete-translation/")
URL_CMS_PAGE_HISTORY = urljoin(URL_CMS_PAGE_CHANGE, "history/%d/")
URL_CMS_PLUGIN_HISTORY_EDIT = urljoin(URL_CMS_PAGE_HISTORY, "edit-plugin/")
class _Warning(object):
def __init__(self, message, category, filename, lineno):
self.message = message
self.category = category
self.filename = filename
self.lineno = lineno
def _collectWarnings(observeWarning, f, *args, **kwargs):
def showWarning(message, category, filename, lineno, file=None, line=None):
assert isinstance(message, Warning)
observeWarning(_Warning(
message.args[0], category, filename, lineno))
# Disable the per-module cache for every module otherwise if the warning
# which the caller is expecting us to collect was already emitted it won't
# be re-emitted by the call to f which happens below.
for v in sys.modules.values():
if v is not None:
try:
v.__warningregistry__ = None
except:
# Don't specify a particular exception type to handle in case
# some wacky object raises some wacky exception in response to
# the setattr attempt.
pass
origFilters = warnings.filters[:]
origShow = warnings.showwarning
warnings.simplefilter('always')
try:
warnings.showwarning = showWarning
result = f(*args, **kwargs)
finally:
warnings.filters[:] = origFilters
warnings.showwarning = origShow
return result
class BaseCMSTestCase(object):
counter = 1
def _fixture_setup(self):
super(BaseCMSTestCase, self)._fixture_setup()
self.create_fixtures()
activate("en")
def create_fixtures(self):
pass
def _post_teardown(self):
# Needed to clean the menu keys cache, see menu.menu_pool.clear()
menu_pool.clear()
cache.clear()
super(BaseCMSTestCase, self)._post_teardown()
set_current_user(None)
def login_user_context(self, user):
return UserLoginContext(self, user)
def _create_user(self, username, is_staff=False, is_superuser=False,
is_active=True, add_default_permissions=False, permissions=None):
"""
Use this method to create users.
Default permissions on page and text plugin are added if creating a
non-superuser and `add_default_permissions` is set.
Set `permissions` parameter to an iterable of permission codes to add
custom permissios.
"""
User = get_user_model()
fields = dict(email=username + '@django-cms.org',
is_staff=is_staff, is_active=is_active, is_superuser=is_superuser
)
# Check for special case where email is used as username
if (get_user_model().USERNAME_FIELD != 'email'):
fields[get_user_model().USERNAME_FIELD] = username
user = User(**fields)
user.set_password(getattr(user, get_user_model().USERNAME_FIELD))
user.save()
if is_staff and not is_superuser and add_default_permissions:
user.user_permissions.add(Permission.objects.get(codename='add_text'))
user.user_permissions.add(Permission.objects.get(codename='delete_text'))
user.user_permissions.add(Permission.objects.get(codename='change_text'))
user.user_permissions.add(Permission.objects.get(codename='publish_page'))
user.user_permissions.add(Permission.objects.get(codename='add_page'))
user.user_permissions.add(Permission.objects.get(codename='change_page'))
user.user_permissions.add(Permission.objects.get(codename='delete_page'))
if is_staff and not is_superuser and permissions:
for permission in permissions:
user.user_permissions.add(Permission.objects.get(codename=permission))
return user
def get_superuser(self):
try:
query = dict()
if get_user_model().USERNAME_FIELD != "email":
query[get_user_model().USERNAME_FIELD] = "admin"
else:
query[get_user_model().USERNAME_FIELD] = "admin@django-cms.org"
admin = get_user_model().objects.get(**query)
except get_user_model().DoesNotExist:
admin = self._create_user("admin", is_staff=True, is_superuser=True)
return admin
def get_staff_user_with_no_permissions(self):
"""
Used in security tests
"""
staff = self._create_user("staff", is_staff=True, is_superuser=False)
return staff
def get_staff_user_with_std_permissions(self):
"""
This is a non superuser staff
"""
staff = self._create_user("staff", is_staff=True, is_superuser=False,
add_permissions=True)
return staff
def get_new_page_data(self, parent_id=''):
page_data = {
'title': 'test page %d' % self.counter,
'slug': 'test-page-%d' % self.counter,
'language': settings.LANGUAGES[0][0],
'template': 'nav_playground.html',
'parent': parent_id,
'site': 1,
'pagepermission_set-TOTAL_FORMS': 0,
'pagepermission_set-INITIAL_FORMS': 0,
'pagepermission_set-MAX_NUM_FORMS': 0,
'pagepermission_set-2-TOTAL_FORMS': 0,
'pagepermission_set-2-INITIAL_FORMS': 0,
'pagepermission_set-2-MAX_NUM_FORMS': 0
}
# required only if user haves can_change_permission
self.counter += 1
return page_data
def get_new_page_data_dbfields(self, parent=None, site=None,
language=None,
template='nav_playground.html', ):
page_data = {
'title': 'test page %d' % self.counter,
'slug': 'test-page-%d' % self.counter,
'language': settings.LANGUAGES[0][0] if not language else language,
'template': template,
'parent': parent if parent else None,
'site': site if site else Site.objects.get_current(),
}
self.counter = self.counter + 1
return page_data
def get_pagedata_from_dbfields(self, page_data):
"""Converts data created by get_new_page_data_dbfields to data
created from get_new_page_data so you can switch between test cases
in api.create_page and client.post"""
page_data['site'] = page_data['site'].id
page_data['parent'] = page_data['parent'].id if page_data['parent'] else ''
# required only if user haves can_change_permission
page_data['pagepermission_set-TOTAL_FORMS'] = 0
page_data['pagepermission_set-INITIAL_FORMS'] = 0
page_data['pagepermission_set-MAX_NUM_FORMS'] = 0
page_data['pagepermission_set-2-TOTAL_FORMS'] = 0
page_data['pagepermission_set-2-INITIAL_FORMS'] = 0
page_data['pagepermission_set-2-MAX_NUM_FORMS'] = 0
return page_data
def print_page_structure(self, qs):
"""Just a helper to see the page struct.
"""
for page in qs.order_by('tree_id', 'lft'):
ident = " " * page.level
print(u"%s%s (%s), lft: %s, rght: %s, tree_id: %s" % (ident, page,
page.pk, page.lft, page.rght, page.tree_id))
def print_node_structure(self, nodes, *extra):
def _rec(nodes, level=0):
ident = level * ' '
for node in nodes:
raw_attrs = [(bit, getattr(node, bit, node.attr.get(bit, "unknown"))) for bit in extra]
attrs = ', '.join(['%s: %r' % data for data in raw_attrs])
print(u"%s%s: %s" % (ident, node.title, attrs))
_rec(node.children, level + 1)
_rec(nodes)
def assertObjectExist(self, qs, **filter):
try:
return qs.get(**filter)
except ObjectDoesNotExist:
pass
raise self.failureException("ObjectDoesNotExist raised for filter %s" % filter)
def assertObjectDoesNotExist(self, qs, **filter):
try:
qs.get(**filter)
except ObjectDoesNotExist:
return
raise self.failureException("ObjectDoesNotExist not raised for filter %s" % filter)
def copy_page(self, page, target_page):
from cms.utils.page import get_available_slug
data = {
'position': 'last-child',
'target': target_page.pk,
'site': 1,
'copy_permissions': 'on',
'copy_moderation': 'on',
}
response = self.client.post(URL_CMS_PAGE + "%d/copy-page/" % page.pk, data)
self.assertEqual(response.status_code, 200)
# Altered to reflect the new django-js jsonified response messages
expected = {"status": 200, "content": "ok"}
self.assertEqual(json.loads(response.content.decode('utf8')), expected)
title = page.title_set.all()[0]
copied_slug = get_available_slug(title)
copied_page = self.assertObjectExist(Page.objects, title_set__slug=copied_slug, parent=target_page)
return copied_page
def move_page(self, page, target_page, position="first-child"):
page.move_page(target_page, position)
return self.reload_page(page)
def reload_page(self, page):
"""
Returns a fresh instance of the page from the database
"""
return self.reload(page)
def reload(self, obj):
return obj.__class__.objects.get(pk=obj.pk)
def get_pages_root(self):
return unquote(reverse("pages-root"))
def get_context(self, path=None, page=None):
if not path:
path = self.get_pages_root()
context = {}
request = self.get_request(path, page=page)
context['request'] = request
return Context(context)
def get_request(self, path=None, language=None, post_data=None, enforce_csrf_checks=False, page=None):
factory = RequestFactory()
if not path:
path = self.get_pages_root()
if not language:
if settings.USE_I18N:
language = settings.LANGUAGES[0][0]
else:
language = settings.LANGUAGE_CODE
if post_data:
request = factory.post(path, post_data)
else:
request = factory.get(path)
request.session = self.client.session
request.user = getattr(self, 'user', AnonymousUser())
request.LANGUAGE_CODE = language
request._dont_enforce_csrf_checks = not enforce_csrf_checks
if page:
request.current_page = page
else:
request.current_page = None
class MockStorage(object):
def __len__(self):
return 0
def __iter__(self):
return iter([])
def add(self, level, message, extra_tags=''):
pass
def update(self, response):
pass
request._messages = MockStorage()
return request
def check_published_page_attributes(self, page):
public_page = page.publisher_public
if page.parent:
self.assertEqual(page.parent_id, public_page.parent.publisher_draft.id)
self.assertEqual(page.level, public_page.level)
# TODO: add check for siblings
draft_siblings = list(page.get_siblings(True).filter(
publisher_is_draft=True
).order_by('tree_id', 'parent', 'lft'))
public_siblings = list(public_page.get_siblings(True).filter(
publisher_is_draft=False
).order_by('tree_id', 'parent', 'lft'))
skip = 0
for i, sibling in enumerate(draft_siblings):
if not sibling.publisher_public_id:
skip += 1
continue
self.assertEqual(sibling.id,
public_siblings[i - skip].publisher_draft.id)
def failUnlessWarns(self, category, message, f, *args, **kwargs):
warningsShown = []
result = _collectWarnings(warningsShown.append, f, *args, **kwargs)
if not warningsShown:
self.fail("No warnings emitted")
first = warningsShown[0]
for other in warningsShown[1:]:
if ((other.message, other.category)
!= (first.message, first.category)):
self.fail("Can't handle different warnings")
self.assertEqual(first.message, message)
self.assertTrue(first.category is category)
return result
assertWarns = failUnlessWarns
class CMSTestCase(BaseCMSTestCase, testcases.TestCase):
pass
class TransactionCMSTestCase(BaseCMSTestCase, testcases.TransactionTestCase):
pass
class SettingsOverrideTestCase(CMSTestCase):
settings_overrides = {}
def _pre_setup(self):
self._enter_settings_override()
super(SettingsOverrideTestCase, self)._pre_setup()
def _enter_settings_override(self):
self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
self._settings_ctx_manager.__enter__()
def _post_teardown(self):
super(SettingsOverrideTestCase, self)._post_teardown()
self._exit_settings_override()
def _exit_settings_override(self):
self._settings_ctx_manager.__exit__(None, None, None)
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
984,
199,
646,
2022,
199,
199,
504,
19240,
14,
5819,
492,
664,
63,
751,
63,
1238,
199,
504,
19240,
14,
992,
492,
10331,
199,
504,
19240,
14,
396,
63,
1208,
14,
1974,
14,
1100,
63,
16259,
492,
334,
1899,
8880,
2998,
12,
272,
13303,
11954,
9,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
12,
8779,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1160,
14,
1100,
492,
9470,
199,
504,
1639,
14,
396,
492,
511,
9403,
199,
504,
1639,
14,
396,
14,
1258,
492,
18638,
199,
504,
1639,
14,
1208,
14,
6893,
492,
15422,
199,
504,
27906,
14,
4470,
63,
2293,
492,
6269,
63,
2293,
199,
504,
19240,
14,
1208,
14,
5819,
14,
3603,
492,
20818,
12,
14342,
199,
646,
3598,
199,
504,
19240,
14,
1208,
14,
6060,
492,
663,
63,
1818,
63,
751,
421,
199,
2632,
63,
17834,
63,
12898,
275,
3286,
287,
15,
2113,
15,
10781,
15,
1606,
6687,
199,
2632,
63,
17834,
63,
12898,
63,
9732,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
525,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
16062,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
2071,
68,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
1554,
54,
879,
25927,
63,
16062,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
2071,
68,
15,
14652,
13,
1751,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
4227,
22320,
63,
16062,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
2071,
68,
15,
5693,
13,
1751,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
16062,
63,
13947,
275,
2851,
63,
17834,
63,
12898,
63,
16062,
435,
23665,
3671,
2458,
83,
2,
199,
2632,
63,
17834,
63,
12898,
63,
16062,
63,
7433,
275,
2851,
63,
17834,
63,
12898,
63,
16062,
435,
298,
1461,
63,
1160,
6687,
199,
2632,
63,
17834,
63,
12898,
63,
30266,
13898,
275,
2851,
63,
17834,
63,
12898,
63,
16062,
435,
2071,
83,
15,
4763,
6687,
199,
2632,
63,
17834,
63,
12898,
63,
7014,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
16062,
12,
298,
1807,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
9732,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
525,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
17929,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
3773,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
16207,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
1185,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
25856,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
1807,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
26376,
2594,
63,
7014,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
16062,
12,
298,
1807,
13,
6893,
13589,
199,
199,
2632,
63,
17834,
63,
12898,
63,
30895,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
16062,
12,
298,
5570,
3149,
68,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
30895,
63,
17929,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
30895,
12,
298,
3773,
13,
2718,
13589,
421,
199,
533,
485,
3849,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1245,
12,
4637,
12,
1788,
12,
5874,
304,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
3710,
275,
4637,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
5874,
421,
199,
318,
485,
7112,
15921,
8,
2873,
4909,
3849,
12,
289,
12,
627,
589,
12,
1011,
958,
304,
272,
347,
2498,
3849,
8,
1188,
12,
4637,
12,
1788,
12,
5874,
12,
570,
29,
403,
12,
1004,
29,
403,
304,
267,
702,
1228,
8,
1188,
12,
15902,
9,
267,
2607,
4909,
3849,
1547,
3849,
8,
288,
1245,
14,
589,
59,
16,
467,
4637,
12,
1788,
12,
5874,
430,
339,
327,
17534,
314,
1126,
13,
578,
2581,
367,
4036,
859,
4257,
340,
314,
5721,
272,
327,
1314,
314,
8025,
365,
21055,
2739,
370,
8775,
1990,
2575,
19515,
652,
7859,
1133,
272,
327,
506,
295,
13,
69,
4485,
701,
314,
1240,
370,
289,
1314,
10986,
5084,
14,
272,
367,
373,
315,
984,
14,
3112,
14,
1459,
837,
267,
340,
373,
365,
440,
488,
26,
288,
862,
26,
355,
373,
855,
3764,
5189,
363,
275,
488,
288,
871,
26,
355,
327,
7529,
1133,
4165,
282,
6770,
1919,
730,
370,
2429,
315,
1930,
355,
327,
2005,
336,
564,
89,
909,
6534,
2005,
336,
564,
89,
1919,
315,
1177,
370,
355,
327,
314,
5371,
7427,
14,
355,
986,
339,
2306,
18053,
275,
3598,
14,
4273,
5873,
272,
2306,
6824,
275,
3598,
14,
29109,
272,
3598,
14,
18815,
360,
9223,
358,
272,
862,
26,
267,
3598,
14,
29109,
275,
2498,
3849,
267,
754,
275,
289,
2031,
589,
12,
1011,
958,
9,
272,
3753,
26,
267,
3598,
14,
4273,
5873,
275,
2306,
18053,
267,
3598,
14,
29109,
275,
2306,
6824,
272,
372,
754,
421,
199,
533,
3523,
17834,
1746,
8,
785,
304,
272,
7055,
275,
413,
339,
347,
485,
5997,
63,
2758,
8,
277,
304,
267,
1613,
8,
1563,
17834,
1746,
12,
291,
10445,
5997,
63,
2758,
342,
267,
291,
14,
981,
63,
8769,
342,
267,
15422,
480,
287,
531,
2378,
347,
1218,
63,
8769,
8,
277,
304,
267,
986,
339,
347,
485,
1932,
63,
15236,
8,
277,
304,
267,
327,
28196,
370,
3633,
314,
6269,
2883,
2581,
12,
1937,
6269,
14,
4470,
63,
2293,
14,
3584,
342,
267,
6269,
63,
2293,
14,
3584,
342,
267,
2581,
14,
3584,
342,
267,
1613,
8,
1563,
17834,
1746,
12,
291,
10445,
1932,
63,
15236,
342,
267,
663,
63,
1818,
63,
751,
8,
403,
9,
339,
347,
4676,
63,
751,
63,
1100,
8,
277,
12,
922,
304,
267,
372,
2876,
8880,
2998,
8,
277,
12,
922,
9,
339,
347,
485,
981,
63,
751,
8,
277,
12,
3434,
12,
365,
63,
7018,
29,
797,
12,
365,
63,
11434,
29,
797,
12,
2151,
365,
63,
2682,
29,
549,
12,
1050
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
984,
199,
646,
2022,
199,
199,
504,
19240,
14,
5819,
492,
664,
63,
751,
63,
1238,
199,
504,
19240,
14,
992,
492,
10331,
199,
504,
19240,
14,
396,
63,
1208,
14,
1974,
14,
1100,
63,
16259,
492,
334,
1899,
8880,
2998,
12,
272,
13303,
11954,
9,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
12,
8779,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
1018,
14,
1637,
492,
2581,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1160,
14,
1100,
492,
9470,
199,
504,
1639,
14,
396,
492,
511,
9403,
199,
504,
1639,
14,
396,
14,
1258,
492,
18638,
199,
504,
1639,
14,
1208,
14,
6893,
492,
15422,
199,
504,
27906,
14,
4470,
63,
2293,
492,
6269,
63,
2293,
199,
504,
19240,
14,
1208,
14,
5819,
14,
3603,
492,
20818,
12,
14342,
199,
646,
3598,
199,
504,
19240,
14,
1208,
14,
6060,
492,
663,
63,
1818,
63,
751,
421,
199,
2632,
63,
17834,
63,
12898,
275,
3286,
287,
15,
2113,
15,
10781,
15,
1606,
6687,
199,
2632,
63,
17834,
63,
12898,
63,
9732,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
525,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
16062,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
2071,
68,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
1554,
54,
879,
25927,
63,
16062,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
2071,
68,
15,
14652,
13,
1751,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
4227,
22320,
63,
16062,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
2071,
68,
15,
5693,
13,
1751,
13589,
199,
2632,
63,
17834,
63,
12898,
63,
16062,
63,
13947,
275,
2851,
63,
17834,
63,
12898,
63,
16062,
435,
23665,
3671,
2458,
83,
2,
199,
2632,
63,
17834,
63,
12898,
63,
16062,
63,
7433,
275,
2851,
63,
17834,
63,
12898,
63,
16062,
435,
298,
1461,
63,
1160,
6687,
199,
2632,
63,
17834,
63,
12898,
63,
30266,
13898,
275,
2851,
63,
17834,
63,
12898,
63,
16062,
435,
2071,
83,
15,
4763,
6687,
199,
2632,
63,
17834,
63,
12898,
63,
7014,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
16062,
12,
298,
1807,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
9732,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
525,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
17929,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
3773,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
16207,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
1185,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
25856,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
12,
298,
1807,
13,
2718,
13589,
199,
2632,
63,
17834,
63,
26376,
2594,
63,
7014,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
16062,
12,
298,
1807,
13,
6893,
13589,
199,
199,
2632,
63,
17834,
63,
12898,
63,
30895,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
16062,
12,
298,
5570,
3149,
68,
13589,
199,
2632,
63,
17834,
63,
19108,
63,
30895,
63,
17929,
275,
20818,
8,
2632,
63,
17834,
63,
12898,
63,
30895,
12,
298,
3773,
13,
2718,
13589,
421,
199,
533,
485,
3849,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1245,
12,
4637,
12,
1788,
12,
5874,
304,
267,
291,
14,
1188,
275,
1245,
267,
291,
14,
3710,
275,
4637,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
3469,
275,
5874,
421,
199,
318,
485,
7112,
15921,
8,
2873,
4909,
3849,
12,
289,
12,
627,
589,
12,
1011,
958,
304,
272,
347,
2498,
3849,
8,
1188,
12,
4637,
12,
1788,
12,
5874,
12,
570,
29,
403,
12,
1004,
29,
403,
304,
267,
702,
1228,
8,
1188,
12,
15902,
9,
267,
2607,
4909,
3849,
1547,
3849,
8,
288,
1245,
14,
589,
59,
16,
467,
4637,
12,
1788,
12,
5874,
430,
339,
327,
17534,
314,
1126,
13,
578,
2581,
367,
4036,
859,
4257,
340,
314,
5721,
272,
327,
1314,
314,
8025,
365,
21055,
2739,
370,
8775,
1990,
2575,
19515,
652,
7859,
1133,
272,
327,
506,
295,
13,
69,
4485,
701,
314,
1240,
370,
289,
1314,
10986,
5084,
14,
272,
367,
373,
315,
984,
14,
3112,
14,
1459,
837,
267,
340,
373,
365,
440,
488,
26,
288,
862,
26,
355,
373,
855,
3764,
5189,
363,
275,
488,
288,
871,
26,
355,
327,
7529,
1133,
4165,
282,
6770,
1919,
730,
370,
2429,
315,
1930,
355,
327,
2005,
336,
564,
89,
909,
6534,
2005,
336,
564,
89,
1919,
315,
1177,
370,
355,
327,
314,
5371,
7427,
14,
355,
986,
339,
2306,
18053,
275,
3598,
14,
4273,
5873,
272,
2306,
6824,
275,
3598,
14,
29109,
272,
3598,
14,
18815,
360,
9223,
358,
272,
862,
26,
267,
3598,
14,
29109,
275,
2498,
3849,
267,
754,
275,
289,
2031,
589,
12,
1011,
958,
9,
272,
3753,
26,
267,
3598,
14,
4273,
5873,
275,
2306,
18053,
267,
3598,
14,
29109,
275,
2306,
6824,
272,
372,
754,
421,
199,
533,
3523,
17834,
1746,
8,
785,
304,
272,
7055,
275,
413,
339,
347,
485,
5997,
63,
2758,
8,
277,
304,
267,
1613,
8,
1563,
17834,
1746,
12,
291,
10445,
5997,
63,
2758,
342,
267,
291,
14,
981,
63,
8769,
342,
267,
15422,
480,
287,
531,
2378,
347,
1218,
63,
8769,
8,
277,
304,
267,
986,
339,
347,
485,
1932,
63,
15236,
8,
277,
304,
267,
327,
28196,
370,
3633,
314,
6269,
2883,
2581,
12,
1937,
6269,
14,
4470,
63,
2293,
14,
3584,
342,
267,
6269,
63,
2293,
14,
3584,
342,
267,
2581,
14,
3584,
342,
267,
1613,
8,
1563,
17834,
1746,
12,
291,
10445,
1932,
63,
15236,
342,
267,
663,
63,
1818,
63,
751,
8,
403,
9,
339,
347,
4676,
63,
751,
63,
1100,
8,
277,
12,
922,
304,
267,
372,
2876,
8880,
2998,
8,
277,
12,
922,
9,
339,
347,
485,
981,
63,
751,
8,
277,
12,
3434,
12,
365,
63,
7018,
29,
797,
12,
365,
63,
11434,
29,
797,
12,
2151,
365,
63,
2682,
29,
549,
12,
1050,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
cognitiveclass/edx-platform
|
common/djangoapps/terrain/stubs/comments.py
|
85
|
5565
|
"""
Stub implementation of cs_comments_service for acceptance tests
"""
import re
import urlparse
from .http import StubHttpRequestHandler, StubHttpService
class StubCommentsServiceHandler(StubHttpRequestHandler):
@property
def _params(self):
return urlparse.parse_qs(urlparse.urlparse(self.path).query)
def do_GET(self):
pattern_handlers = {
"/api/v1/users/(?P<user_id>\\d+)/active_threads$": self.do_user_profile,
"/api/v1/users/(?P<user_id>\\d+)$": self.do_user,
"/api/v1/search/threads$": self.do_search_threads,
"/api/v1/threads$": self.do_threads,
"/api/v1/threads/(?P<thread_id>\\w+)$": self.do_thread,
"/api/v1/comments/(?P<comment_id>\\w+)$": self.do_comment,
"/api/v1/(?P<commentable_id>\\w+)/threads$": self.do_commentable,
}
if self.match_pattern(pattern_handlers):
return
self.send_response(404, content="404 Not Found")
def match_pattern(self, pattern_handlers):
path = urlparse.urlparse(self.path).path
for pattern in pattern_handlers:
match = re.match(pattern, path)
if match:
pattern_handlers[pattern](**match.groupdict())
return True
return None
def do_PUT(self):
if self.path.startswith('/set_config'):
return StubHttpRequestHandler.do_PUT(self)
pattern_handlers = {
"/api/v1/users/(?P<user_id>\\d+)$": self.do_put_user,
}
if self.match_pattern(pattern_handlers):
return
self.send_response(204, "")
def do_put_user(self, user_id):
self.server.config['default_sort_key'] = self.post_dict.get("default_sort_key", "date")
self.send_json_response({'username': self.post_dict.get("username"), 'external_id': self.post_dict.get("external_id")})
def do_DELETE(self):
pattern_handlers = {
"/api/v1/comments/(?P<comment_id>\\w+)$": self.do_delete_comment
}
if self.match_pattern(pattern_handlers):
return
self.send_json_response({})
def do_user(self, user_id):
response = {
"id": user_id,
"default_sort_key": self.server.config.get("default_sort_key", "date"),
"upvoted_ids": [],
"downvoted_ids": [],
"subscribed_thread_ids": [],
}
if 'course_id' in self._params:
response.update({
"threads_count": 1,
"comments_count": 2
})
self.send_json_response(response)
def do_user_profile(self, user_id):
if 'active_threads' in self.server.config:
user_threads = self.server.config['active_threads'][:]
params = self._params
page = int(params.get("page", ["1"])[0])
per_page = int(params.get("per_page", ["20"])[0])
num_pages = max(len(user_threads) - 1, 1) / per_page + 1
user_threads = user_threads[(page - 1) * per_page:page * per_page]
self.send_json_response({
"collection": user_threads,
"page": page,
"num_pages": num_pages
})
else:
self.send_response(404, content="404 Not Found")
def do_thread(self, thread_id):
if thread_id in self.server.config.get('threads', {}):
thread = self.server.config['threads'][thread_id].copy()
params = urlparse.parse_qs(urlparse.urlparse(self.path).query)
if "recursive" in params and params["recursive"][0] == "True":
thread.setdefault('children', [])
resp_total = thread.setdefault('resp_total', len(thread['children']))
resp_skip = int(params.get("resp_skip", ["0"])[0])
resp_limit = int(params.get("resp_limit", ["10000"])[0])
thread['children'] = thread['children'][resp_skip:(resp_skip + resp_limit)]
self.send_json_response(thread)
else:
self.send_response(404, content="404 Not Found")
def do_threads(self):
threads = self.server.config.get('threads', {})
threads_data = [val for key, val in threads.items()]
self.send_json_response({"collection": threads_data, "page": 1, "num_pages": 1})
def do_search_threads(self):
self.send_json_response(self.server.config.get('search_result', {}))
def do_comment(self, comment_id):
# django_comment_client calls GET comment before doing a DELETE, so that's what this is here to support.
if comment_id in self.server.config.get('comments', {}):
comment = self.server.config['comments'][comment_id]
self.send_json_response(comment)
def do_delete_comment(self, comment_id):
"""Handle comment deletion. Returns a JSON representation of the
deleted comment."""
if comment_id in self.server.config.get('comments', {}):
comment = self.server.config['comments'][comment_id]
self.send_json_response(comment)
def do_commentable(self, commentable_id):
self.send_json_response({
"collection": [
thread
for thread in self.server.config.get('threads', {}).values()
if thread.get('commentable_id') == commentable_id
],
"page": 1,
"num_pages": 1,
})
class StubCommentsService(StubHttpService):
HANDLER_CLASS = StubCommentsServiceHandler
|
agpl-3.0
|
[
624,
199,
8067,
4514,
402,
7117,
63,
6223,
63,
1364,
367,
4729,
554,
2295,
199,
624,
199,
199,
646,
295,
199,
646,
7097,
199,
504,
1275,
1014,
492,
23429,
10441,
2461,
12,
23429,
5779,
3167,
421,
199,
533,
23429,
18929,
3167,
2461,
8,
8067,
10441,
2461,
304,
339,
768,
1829,
272,
347,
485,
1162,
8,
277,
304,
267,
372,
7097,
14,
1122,
63,
6177,
8,
10290,
14,
10290,
8,
277,
14,
515,
680,
1131,
9,
339,
347,
886,
63,
2970,
8,
277,
304,
267,
3851,
63,
5586,
275,
469,
288,
3286,
1246,
15,
86,
17,
15,
3707,
9448,
48,
28,
751,
63,
344,
30,
1103,
68,
18830,
2682,
63,
6962,
4,
582,
291,
14,
1117,
63,
751,
63,
2913,
12,
288,
3286,
1246,
15,
86,
17,
15,
3707,
9448,
48,
28,
751,
63,
344,
30,
1103,
68,
8771,
4,
582,
291,
14,
1117,
63,
751,
12,
288,
3286,
1246,
15,
86,
17,
15,
1733,
15,
6962,
4,
582,
291,
14,
1117,
63,
1733,
63,
6962,
12,
288,
3286,
1246,
15,
86,
17,
15,
6962,
4,
582,
291,
14,
1117,
63,
6962,
12,
288,
3286,
1246,
15,
86,
17,
15,
6962,
9448,
48,
28,
2671,
63,
344,
30,
1103,
87,
8771,
4,
582,
291,
14,
1117,
63,
2671,
12,
288,
3286,
1246,
15,
86,
17,
15,
6223,
9448,
48,
28,
3349,
63,
344,
30,
1103,
87,
8771,
4,
582,
291,
14,
1117,
63,
3349,
12,
288,
3286,
1246,
15,
86,
17,
9448,
48,
28,
3349,
461,
63,
344,
30,
1103,
87,
18830,
6962,
4,
582,
291,
14,
1117,
63,
3349,
461,
12,
267,
789,
267,
340,
291,
14,
1431,
63,
3401,
8,
3401,
63,
5586,
304,
288,
372,
398,
291,
14,
2254,
63,
1310,
8,
5188,
12,
1564,
628,
5188,
2832,
2643,
531,
339,
347,
1336,
63,
3401,
8,
277,
12,
3851,
63,
5586,
304,
267,
931,
275,
7097,
14,
10290,
8,
277,
14,
515,
680,
515,
267,
367,
3851,
315,
3851,
63,
5586,
26,
288,
1336,
275,
295,
14,
1431,
8,
3401,
12,
931,
9,
288,
340,
1336,
26,
355,
3851,
63,
5586,
59,
3401,
61,
3682,
1431,
14,
20567,
1012,
355,
372,
715,
267,
372,
488,
339,
347,
886,
63,
4013,
8,
277,
304,
267,
340,
291,
14,
515,
14,
2460,
2336,
409,
63,
888,
735,
288,
372,
23429,
10441,
2461,
14,
1117,
63,
4013,
8,
277,
9,
267,
3851,
63,
5586,
275,
469,
288,
3286,
1246,
15,
86,
17,
15,
3707,
9448,
48,
28,
751,
63,
344,
30,
1103,
68,
8771,
4,
582,
291,
14,
1117,
63,
524,
63,
751,
12,
267,
789,
267,
340,
291,
14,
1431,
63,
3401,
8,
3401,
63,
5586,
304,
288,
372,
267,
291,
14,
2254,
63,
1310,
8,
6686,
12,
6899,
339,
347,
886,
63,
524,
63,
751,
8,
277,
12,
922,
63,
344,
304,
267,
291,
14,
1000,
14,
888,
459,
885,
63,
3191,
63,
498,
418,
275,
291,
14,
1932,
63,
807,
14,
362,
480,
885,
63,
3191,
63,
498,
401,
298,
602,
531,
267,
291,
14,
2254,
63,
1001,
63,
1310,
3252,
2473,
356,
291,
14,
1932,
63,
807,
14,
362,
480,
2473,
1288,
283,
5159,
63,
344,
356,
291,
14,
1932,
63,
807,
14,
362,
480,
5159,
63,
344,
531,
1552,
339,
347,
886,
63,
7014,
8,
277,
304,
267,
3851,
63,
5586,
275,
469,
288,
3286,
1246,
15,
86,
17,
15,
6223,
9448,
48,
28,
3349,
63,
344,
30,
1103,
87,
8771,
4,
582,
291,
14,
1117,
63,
1807,
63,
3349,
267,
789,
267,
340,
291,
14,
1431,
63,
3401,
8,
3401,
63,
5586,
304,
288,
372,
267,
291,
14,
2254,
63,
1001,
63,
1310,
14079,
339,
347,
886,
63,
751,
8,
277,
12,
922,
63,
344,
304,
267,
1177,
275,
469,
288,
298,
344,
582,
922,
63,
344,
12,
288,
298,
885,
63,
3191,
63,
498,
582,
291,
14,
1000,
14,
888,
14,
362,
480,
885,
63,
3191,
63,
498,
401,
298,
602,
1288,
288,
298,
384,
2392,
471,
63,
1580,
582,
990,
288,
298,
2110,
2392,
471,
63,
1580,
582,
990,
288,
298,
23178,
63,
2671,
63,
1580,
582,
990,
267,
789,
267,
340,
283,
1972,
63,
344,
7,
315,
291,
423,
1162,
26,
288,
1177,
14,
873,
2561,
355,
298,
6962,
63,
835,
582,
413,
12,
355,
298,
6223,
63,
835,
582,
499,
288,
3828,
267,
291,
14,
2254,
63,
1001,
63,
1310,
8,
1310,
9,
339,
347,
886,
63,
751,
63,
2913,
8,
277,
12,
922,
63,
344,
304,
267,
340,
283,
2682,
63,
6962,
7,
315,
291,
14,
1000,
14,
888,
26,
288,
922,
63,
6962,
275,
291,
14,
1000,
14,
888,
459,
2682,
63,
6962,
418,
5873,
288,
1862,
275,
291,
423,
1162,
288,
2034,
275,
1109,
8,
1162,
14,
362,
480,
1606,
401,
2097,
17,
3135,
59,
16,
566,
288,
1126,
63,
1606,
275,
1109,
8,
1162,
14,
362,
480,
529,
63,
1606,
401,
2097,
1165,
3135,
59,
16,
566,
288,
1967,
63,
5856,
275,
1390,
8,
552,
8,
751,
63,
6962,
9,
446,
413,
12,
413,
9,
1182,
1126,
63,
1606,
435,
413,
288,
922,
63,
6962,
275,
922,
63,
6962,
7528,
1606,
446,
413,
9,
627,
1126,
63,
1606,
26,
1606,
627,
1126,
63,
1606,
61,
288,
291,
14,
2254,
63,
1001,
63,
1310,
2561,
355,
298,
3627,
582,
922,
63,
6962,
12,
355,
298,
1606,
582,
2034,
12,
355,
298,
1507,
63,
5856,
582,
1967,
63,
5856,
288,
3828,
267,
587,
26,
288,
291,
14,
2254,
63,
1310,
8,
5188,
12,
1564,
628,
5188,
2832,
2643,
531,
339,
347,
886,
63,
2671,
8,
277,
12,
2462,
63,
344,
304,
267,
340,
2462,
63,
344,
315,
291,
14,
1000,
14,
888,
14,
362,
360,
6962,
297,
1052,
304,
288,
2462,
275,
291,
14,
1000,
14,
888,
459,
6962,
3488,
2671,
63,
344,
1055,
1574,
342,
288,
1862,
275,
7097,
14,
1122,
63,
6177,
8,
10290,
14,
10290,
8,
277,
14,
515,
680,
1131,
9,
288,
340,
298,
9931,
2,
315,
1862,
436,
1862,
905,
9931,
9210,
16,
61,
508,
298,
549,
582,
355,
2462,
14,
5486,
360,
3223,
297,
3073,
355,
3085,
63,
2923,
275,
2462,
14,
5486,
360,
4518,
63,
2923,
297,
822,
8,
2671,
459,
3223,
5156,
355,
3085,
63
] |
[
199,
8067,
4514,
402,
7117,
63,
6223,
63,
1364,
367,
4729,
554,
2295,
199,
624,
199,
199,
646,
295,
199,
646,
7097,
199,
504,
1275,
1014,
492,
23429,
10441,
2461,
12,
23429,
5779,
3167,
421,
199,
533,
23429,
18929,
3167,
2461,
8,
8067,
10441,
2461,
304,
339,
768,
1829,
272,
347,
485,
1162,
8,
277,
304,
267,
372,
7097,
14,
1122,
63,
6177,
8,
10290,
14,
10290,
8,
277,
14,
515,
680,
1131,
9,
339,
347,
886,
63,
2970,
8,
277,
304,
267,
3851,
63,
5586,
275,
469,
288,
3286,
1246,
15,
86,
17,
15,
3707,
9448,
48,
28,
751,
63,
344,
30,
1103,
68,
18830,
2682,
63,
6962,
4,
582,
291,
14,
1117,
63,
751,
63,
2913,
12,
288,
3286,
1246,
15,
86,
17,
15,
3707,
9448,
48,
28,
751,
63,
344,
30,
1103,
68,
8771,
4,
582,
291,
14,
1117,
63,
751,
12,
288,
3286,
1246,
15,
86,
17,
15,
1733,
15,
6962,
4,
582,
291,
14,
1117,
63,
1733,
63,
6962,
12,
288,
3286,
1246,
15,
86,
17,
15,
6962,
4,
582,
291,
14,
1117,
63,
6962,
12,
288,
3286,
1246,
15,
86,
17,
15,
6962,
9448,
48,
28,
2671,
63,
344,
30,
1103,
87,
8771,
4,
582,
291,
14,
1117,
63,
2671,
12,
288,
3286,
1246,
15,
86,
17,
15,
6223,
9448,
48,
28,
3349,
63,
344,
30,
1103,
87,
8771,
4,
582,
291,
14,
1117,
63,
3349,
12,
288,
3286,
1246,
15,
86,
17,
9448,
48,
28,
3349,
461,
63,
344,
30,
1103,
87,
18830,
6962,
4,
582,
291,
14,
1117,
63,
3349,
461,
12,
267,
789,
267,
340,
291,
14,
1431,
63,
3401,
8,
3401,
63,
5586,
304,
288,
372,
398,
291,
14,
2254,
63,
1310,
8,
5188,
12,
1564,
628,
5188,
2832,
2643,
531,
339,
347,
1336,
63,
3401,
8,
277,
12,
3851,
63,
5586,
304,
267,
931,
275,
7097,
14,
10290,
8,
277,
14,
515,
680,
515,
267,
367,
3851,
315,
3851,
63,
5586,
26,
288,
1336,
275,
295,
14,
1431,
8,
3401,
12,
931,
9,
288,
340,
1336,
26,
355,
3851,
63,
5586,
59,
3401,
61,
3682,
1431,
14,
20567,
1012,
355,
372,
715,
267,
372,
488,
339,
347,
886,
63,
4013,
8,
277,
304,
267,
340,
291,
14,
515,
14,
2460,
2336,
409,
63,
888,
735,
288,
372,
23429,
10441,
2461,
14,
1117,
63,
4013,
8,
277,
9,
267,
3851,
63,
5586,
275,
469,
288,
3286,
1246,
15,
86,
17,
15,
3707,
9448,
48,
28,
751,
63,
344,
30,
1103,
68,
8771,
4,
582,
291,
14,
1117,
63,
524,
63,
751,
12,
267,
789,
267,
340,
291,
14,
1431,
63,
3401,
8,
3401,
63,
5586,
304,
288,
372,
267,
291,
14,
2254,
63,
1310,
8,
6686,
12,
6899,
339,
347,
886,
63,
524,
63,
751,
8,
277,
12,
922,
63,
344,
304,
267,
291,
14,
1000,
14,
888,
459,
885,
63,
3191,
63,
498,
418,
275,
291,
14,
1932,
63,
807,
14,
362,
480,
885,
63,
3191,
63,
498,
401,
298,
602,
531,
267,
291,
14,
2254,
63,
1001,
63,
1310,
3252,
2473,
356,
291,
14,
1932,
63,
807,
14,
362,
480,
2473,
1288,
283,
5159,
63,
344,
356,
291,
14,
1932,
63,
807,
14,
362,
480,
5159,
63,
344,
531,
1552,
339,
347,
886,
63,
7014,
8,
277,
304,
267,
3851,
63,
5586,
275,
469,
288,
3286,
1246,
15,
86,
17,
15,
6223,
9448,
48,
28,
3349,
63,
344,
30,
1103,
87,
8771,
4,
582,
291,
14,
1117,
63,
1807,
63,
3349,
267,
789,
267,
340,
291,
14,
1431,
63,
3401,
8,
3401,
63,
5586,
304,
288,
372,
267,
291,
14,
2254,
63,
1001,
63,
1310,
14079,
339,
347,
886,
63,
751,
8,
277,
12,
922,
63,
344,
304,
267,
1177,
275,
469,
288,
298,
344,
582,
922,
63,
344,
12,
288,
298,
885,
63,
3191,
63,
498,
582,
291,
14,
1000,
14,
888,
14,
362,
480,
885,
63,
3191,
63,
498,
401,
298,
602,
1288,
288,
298,
384,
2392,
471,
63,
1580,
582,
990,
288,
298,
2110,
2392,
471,
63,
1580,
582,
990,
288,
298,
23178,
63,
2671,
63,
1580,
582,
990,
267,
789,
267,
340,
283,
1972,
63,
344,
7,
315,
291,
423,
1162,
26,
288,
1177,
14,
873,
2561,
355,
298,
6962,
63,
835,
582,
413,
12,
355,
298,
6223,
63,
835,
582,
499,
288,
3828,
267,
291,
14,
2254,
63,
1001,
63,
1310,
8,
1310,
9,
339,
347,
886,
63,
751,
63,
2913,
8,
277,
12,
922,
63,
344,
304,
267,
340,
283,
2682,
63,
6962,
7,
315,
291,
14,
1000,
14,
888,
26,
288,
922,
63,
6962,
275,
291,
14,
1000,
14,
888,
459,
2682,
63,
6962,
418,
5873,
288,
1862,
275,
291,
423,
1162,
288,
2034,
275,
1109,
8,
1162,
14,
362,
480,
1606,
401,
2097,
17,
3135,
59,
16,
566,
288,
1126,
63,
1606,
275,
1109,
8,
1162,
14,
362,
480,
529,
63,
1606,
401,
2097,
1165,
3135,
59,
16,
566,
288,
1967,
63,
5856,
275,
1390,
8,
552,
8,
751,
63,
6962,
9,
446,
413,
12,
413,
9,
1182,
1126,
63,
1606,
435,
413,
288,
922,
63,
6962,
275,
922,
63,
6962,
7528,
1606,
446,
413,
9,
627,
1126,
63,
1606,
26,
1606,
627,
1126,
63,
1606,
61,
288,
291,
14,
2254,
63,
1001,
63,
1310,
2561,
355,
298,
3627,
582,
922,
63,
6962,
12,
355,
298,
1606,
582,
2034,
12,
355,
298,
1507,
63,
5856,
582,
1967,
63,
5856,
288,
3828,
267,
587,
26,
288,
291,
14,
2254,
63,
1310,
8,
5188,
12,
1564,
628,
5188,
2832,
2643,
531,
339,
347,
886,
63,
2671,
8,
277,
12,
2462,
63,
344,
304,
267,
340,
2462,
63,
344,
315,
291,
14,
1000,
14,
888,
14,
362,
360,
6962,
297,
1052,
304,
288,
2462,
275,
291,
14,
1000,
14,
888,
459,
6962,
3488,
2671,
63,
344,
1055,
1574,
342,
288,
1862,
275,
7097,
14,
1122,
63,
6177,
8,
10290,
14,
10290,
8,
277,
14,
515,
680,
1131,
9,
288,
340,
298,
9931,
2,
315,
1862,
436,
1862,
905,
9931,
9210,
16,
61,
508,
298,
549,
582,
355,
2462,
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
] |
carlthome/librosa
|
librosa/feature/utils.py
|
1
|
8078
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Feature manipulation utilities"""
from warnings import warn
import numpy as np
import scipy.signal
from .._cache import cache
from ..util.exceptions import ParameterError
__all__ = ['delta', 'stack_memory']
@cache(level=40)
def delta(data, width=9, order=1, axis=-1, mode='interp', **kwargs):
r'''Compute delta features: local estimate of the derivative
of the input data along the selected axis.
Delta features are computed Savitsky-Golay filtering.
Parameters
----------
data : np.ndarray
the input data matrix (eg, spectrogram)
width : int, positive, odd [scalar]
Number of frames over which to compute the delta features.
Cannot exceed the length of `data` along the specified axis.
If `mode='interp'`, then `width` must be at least `data.shape[axis]`.
order : int > 0 [scalar]
the order of the difference operator.
1 for first derivative, 2 for second, etc.
axis : int [scalar]
the axis along which to compute deltas.
Default is -1 (columns).
mode : str, {'interp', 'nearest', 'mirror', 'constant', 'wrap'}
Padding mode for estimating differences at the boundaries.
kwargs : additional keyword arguments
See `scipy.signal.savgol_filter`
Returns
-------
delta_data : np.ndarray [shape=(d, t)]
delta matrix of `data` at specified order
Notes
-----
This function caches at level 40.
See Also
--------
scipy.signal.savgol_filter
Examples
--------
Compute MFCC deltas, delta-deltas
>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> mfcc = librosa.feature.mfcc(y=y, sr=sr)
>>> mfcc_delta = librosa.feature.delta(mfcc)
>>> mfcc_delta
array([[ 1.666e+01, 1.666e+01, ..., 1.869e-15, 1.869e-15],
[ 1.784e+01, 1.784e+01, ..., 6.085e-31, 6.085e-31],
...,
[ 7.262e-01, 7.262e-01, ..., 9.259e-31, 9.259e-31],
[ 6.578e-01, 6.578e-01, ..., 7.597e-31, 7.597e-31]])
>>> mfcc_delta2 = librosa.feature.delta(mfcc, order=2)
>>> mfcc_delta2
array([[ -1.703e+01, -1.703e+01, ..., 3.834e-14, 3.834e-14],
[ -1.108e+01, -1.108e+01, ..., -1.068e-30, -1.068e-30],
...,
[ 4.075e-01, 4.075e-01, ..., -1.565e-30, -1.565e-30],
[ 1.676e-01, 1.676e-01, ..., -2.104e-30, -2.104e-30]])
>>> import matplotlib.pyplot as plt
>>> plt.subplot(3, 1, 1)
>>> librosa.display.specshow(mfcc)
>>> plt.title('MFCC')
>>> plt.colorbar()
>>> plt.subplot(3, 1, 2)
>>> librosa.display.specshow(mfcc_delta)
>>> plt.title(r'MFCC-$\Delta$')
>>> plt.colorbar()
>>> plt.subplot(3, 1, 3)
>>> librosa.display.specshow(mfcc_delta2, x_axis='time')
>>> plt.title(r'MFCC-$\Delta^2$')
>>> plt.colorbar()
>>> plt.tight_layout()
>>> plt.show()
'''
data = np.atleast_1d(data)
if mode == 'interp' and width > data.shape[axis]:
raise ParameterError("when mode='interp', width={} "
"cannot exceed data.shape[axis]={}".format(width, data.shape[axis]))
if width < 3 or np.mod(width, 2) != 1:
raise ParameterError('width must be an odd integer >= 3')
if order <= 0 or not isinstance(order, int):
raise ParameterError('order must be a positive integer')
kwargs.pop('deriv', None)
kwargs.setdefault('polyorder', order)
return scipy.signal.savgol_filter(data, width,
deriv=order,
axis=axis,
mode=mode,
**kwargs)
@cache(level=40)
def stack_memory(data, n_steps=2, delay=1, **kwargs):
"""Short-term history embedding: vertically concatenate a data
vector or matrix with delayed copies of itself.
Each column `data[:, i]` is mapped to::
data[:, i] -> [data[:, i],
data[:, i - delay],
...
data[:, i - (n_steps-1)*delay]]
For columns `i < (n_steps - 1) * delay` , the data will be padded.
By default, the data is padded with zeros, but this behavior can be
overridden by supplying additional keyword arguments which are passed
to `np.pad()`.
Parameters
----------
data : np.ndarray [shape=(t,) or (d, t)]
Input data matrix. If `data` is a vector (`data.ndim == 1`),
it will be interpreted as a row matrix and reshaped to `(1, t)`.
n_steps : int > 0 [scalar]
embedding dimension, the number of steps back in time to stack
delay : int != 0 [scalar]
the number of columns to step.
Positive values embed from the past (previous columns).
Negative values embed from the future (subsequent columns).
kwargs : additional keyword arguments
Additional arguments to pass to `np.pad`.
Returns
-------
data_history : np.ndarray [shape=(m * d, t)]
data augmented with lagged copies of itself,
where `m == n_steps - 1`.
Notes
-----
This function caches at level 40.
Examples
--------
Keep two steps (current and previous)
>>> data = np.arange(-3, 3)
>>> librosa.feature.stack_memory(data)
array([[-3, -2, -1, 0, 1, 2],
[ 0, -3, -2, -1, 0, 1]])
Or three steps
>>> librosa.feature.stack_memory(data, n_steps=3)
array([[-3, -2, -1, 0, 1, 2],
[ 0, -3, -2, -1, 0, 1],
[ 0, 0, -3, -2, -1, 0]])
Use reflection padding instead of zero-padding
>>> librosa.feature.stack_memory(data, n_steps=3, mode='reflect')
array([[-3, -2, -1, 0, 1, 2],
[-2, -3, -2, -1, 0, 1],
[-1, -2, -3, -2, -1, 0]])
Or pad with edge-values, and delay by 2
>>> librosa.feature.stack_memory(data, n_steps=3, delay=2, mode='edge')
array([[-3, -2, -1, 0, 1, 2],
[-3, -3, -3, -2, -1, 0],
[-3, -3, -3, -3, -3, -2]])
Stack time-lagged beat-synchronous chroma edge padding
>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> chroma = librosa.feature.chroma_stft(y=y, sr=sr)
>>> tempo, beats = librosa.beat.beat_track(y=y, sr=sr, hop_length=512)
>>> beats = librosa.util.fix_frames(beats, x_min=0, x_max=chroma.shape[1])
>>> chroma_sync = librosa.util.sync(chroma, beats)
>>> chroma_lag = librosa.feature.stack_memory(chroma_sync, n_steps=3,
... mode='edge')
Plot the result
>>> import matplotlib.pyplot as plt
>>> beat_times = librosa.frames_to_time(beats, sr=sr, hop_length=512)
>>> librosa.display.specshow(chroma_lag, y_axis='chroma', x_axis='time',
... x_coords=beat_times)
>>> plt.yticks([0, 12, 24], ['Lag=0', 'Lag=1', 'Lag=2'])
>>> plt.title('Time-lagged chroma')
>>> plt.colorbar()
>>> plt.tight_layout()
>>> plt.show()
"""
if n_steps < 1:
raise ParameterError('n_steps must be a positive integer')
if delay == 0:
raise ParameterError('delay must be a non-zero integer')
data = np.atleast_2d(data)
t = data.shape[1]
kwargs.setdefault('mode', 'constant')
if kwargs['mode'] == 'constant':
kwargs.setdefault('constant_values', [0])
# Pad the end with zeros, which will roll to the front below
if delay > 0:
padding = (int((n_steps - 1) * delay), 0)
else:
padding = (0, int((n_steps - 1) * -delay))
data = np.pad(data, [(0, 0), padding], **kwargs)
history = data
# TODO: this could be more efficient
for i in range(1, n_steps):
history = np.vstack([np.roll(data, -i * delay, axis=1), history])
# Trim to original width
if delay > 0:
history = history[:, :t]
else:
history = history[:, -t:]
# Make contiguous
return np.asfortranarray(history)
|
isc
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
5968,
26212,
15841,
624,
199,
199,
504,
3598,
492,
7987,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4653,
199,
199,
504,
1275,
423,
1637,
492,
2581,
199,
504,
2508,
1974,
14,
3924,
492,
12009,
547,
199,
363,
452,
363,
275,
788,
3136,
297,
283,
2340,
63,
4844,
418,
421,
199,
32,
1637,
8,
1896,
29,
2167,
9,
199,
318,
5762,
8,
576,
12,
3462,
29,
25,
12,
1865,
29,
17,
12,
3114,
4022,
17,
12,
818,
534,
14252,
297,
1011,
958,
304,
272,
519,
2344,
8564,
5762,
4534,
26,
2257,
14497,
402,
314,
18883,
272,
402,
314,
1324,
666,
3180,
314,
4895,
3114,
14,
339,
18464,
502,
4534,
787,
9235,
428,
1214,
390,
12267,
13,
39,
393,
1187,
14545,
14,
339,
3897,
272,
4143,
272,
666,
420,
520,
980,
14,
8237,
267,
314,
1324,
666,
3634,
334,
5902,
12,
30900,
293,
1679,
9,
339,
3462,
258,
520,
1109,
12,
7317,
12,
16699,
359,
7033,
61,
267,
4860,
402,
11223,
1806,
1314,
370,
4526,
314,
5762,
4534,
14,
267,
18435,
24068,
314,
2582,
402,
658,
576,
64,
3180,
314,
2013,
3114,
14,
267,
982,
658,
632,
534,
14252,
7,
3559,
2066,
658,
2063,
64,
1471,
506,
737,
5210,
658,
576,
14,
1392,
59,
3127,
20336,
339,
1865,
258,
520,
1109,
690,
378,
359,
7033,
61,
267,
314,
1865,
402,
314,
8865,
4182,
14,
267,
413,
367,
1642,
18883,
12,
499,
367,
3499,
12,
5423,
14,
339,
3114,
420,
520,
1109,
359,
7033,
61,
267,
314,
3114,
3180,
1314,
370,
4526,
27446,
14,
267,
3758,
365,
446,
17,
334,
3406,
680,
339,
818,
520,
620,
12,
791,
14252,
297,
283,
16615,
297,
283,
12324,
297,
283,
4083,
297,
283,
3823,
936,
267,
510,
4095,
818,
367,
4347,
3969,
316,
15109,
737,
314,
18135,
14,
339,
2074,
520,
4722,
4252,
2368,
267,
1666,
658,
14248,
14,
4653,
14,
83,
8595,
393,
63,
1541,
64,
339,
1803,
272,
5514,
272,
5762,
63,
576,
257,
520,
980,
14,
8237,
359,
1392,
2687,
68,
12,
307,
1874,
267,
5762,
3634,
402,
658,
576,
64,
737,
2013,
1865,
339,
8144,
272,
9063,
272,
961,
805,
18014,
737,
2166,
6335,
14,
339,
1666,
6121,
272,
3001,
272,
7026,
14,
4653,
14,
83,
8595,
393,
63,
1541,
339,
6058,
272,
3001,
272,
8354,
603,
38,
2571,
27446,
12,
5762,
13,
25446,
339,
1306,
612,
12,
11483,
275,
1973,
293,
2231,
14,
912,
8,
773,
293,
2231,
14,
1974,
14,
2694,
63,
8130,
63,
493,
1012,
272,
1306,
19751,
2055,
275,
1973,
293,
2231,
14,
4445,
14,
11821,
2055,
8,
89,
29,
89,
12,
11483,
29,
5474,
9,
272,
1306,
19751,
2055,
63,
3136,
275,
1973,
293,
2231,
14,
4445,
14,
3136,
8,
11821,
2055,
9,
272,
1306,
19751,
2055,
63,
3136,
272,
1625,
4038,
221,
413,
14,
11829,
69,
11,
614,
12,
257,
413,
14,
11829,
69,
11,
614,
12,
14263,
257,
413,
14,
13254,
69,
13,
1046,
12,
257,
413,
14,
13254,
69,
13,
1046,
467,
1779,
359,
221,
413,
14,
28394,
69,
11,
614,
12,
257,
413,
14,
28394,
69,
11,
614,
12,
14263,
257,
1227,
14,
17494,
69,
13,
2192,
12,
257,
1227,
14,
17494,
69,
13,
2192,
467,
1779,
14263,
1779,
359,
221,
1520,
14,
14820,
69,
13,
614,
12,
257,
1520,
14,
14820,
69,
13,
614,
12,
14263,
257,
1749,
14,
11990,
69,
13,
2192,
12,
257,
1749,
14,
11990,
69,
13,
2192,
467,
1779,
359,
221,
1227,
14,
14992,
69,
13,
614,
12,
257,
1227,
14,
14992,
69,
13,
614,
12,
14263,
257,
1520,
14,
15459,
69,
13,
2192,
12,
257,
1520,
14,
15459,
69,
13,
2192,
3934,
339,
1306,
19751,
2055,
63,
3136,
18,
275,
1973,
293,
2231,
14,
4445,
14,
3136,
8,
11821,
2055,
12,
1865,
29,
18,
9,
272,
1306,
19751,
2055,
63,
3136,
18,
272,
1625,
4038,
446,
17,
14,
23,
1644,
69,
11,
614,
12,
221,
446,
17,
14,
23,
1644,
69,
11,
614,
12,
14263,
257,
650,
14,
31230,
69,
13,
1079,
12,
257,
650,
14,
31230,
69,
13,
1079,
467,
1779,
359,
446,
17,
14,
8079,
69,
11,
614,
12,
221,
446,
17,
14,
8079,
69,
11,
614,
12,
14263,
221,
446,
17,
14,
19846,
69,
13,
1216,
12,
221,
446,
17,
14,
19846,
69,
13,
1216,
467,
1779,
14263,
1779,
359,
221,
841,
14,
19339,
69,
13,
614,
12,
257,
841,
14,
19339,
69,
13,
614,
12,
14263,
221,
446,
17,
14,
15670,
69,
13,
1216,
12,
221,
446,
17,
14,
15670,
69,
13,
1216,
467,
1779,
359,
221,
413,
14,
19087,
69,
13,
614,
12,
257,
413,
14,
19087,
69,
13,
614,
12,
14263,
221,
446,
18,
14,
6785,
69,
13,
1216,
12,
221,
446,
18,
14,
6785,
69,
13,
1216,
3934,
339,
1306,
492,
8027,
14,
13563,
465,
4488,
272,
1306,
4488,
14,
13334,
8,
19,
12,
413,
12,
413,
9,
272,
1306,
1973,
293,
2231,
14,
2918,
14,
1650,
2384,
8,
11821,
2055,
9,
272,
1306,
4488,
14,
1213,
360,
13463,
2571,
358,
272,
1306,
4488,
14,
30995,
342,
272,
1306,
4488,
14,
13334,
8,
19,
12,
413,
12,
499,
9,
272,
1306,
1973,
293,
2231,
14,
2918,
14,
1650,
2384,
8,
11821,
2055,
63,
3136,
9,
272,
1306,
4488,
14,
1213,
8,
82,
7,
13463,
2571,
13,
16827,
13411,
9988,
272,
1306,
4488,
14,
30995,
342,
272,
1306,
4488,
14,
13334,
8,
19,
12,
413,
12,
650,
9,
272,
1306,
1973,
293,
2231,
14,
2918,
14,
1650,
2384,
8,
11821,
2055,
63,
3136,
18,
12,
671,
63,
3127,
534,
521,
358,
272,
1306,
4488,
14,
1213,
8,
82,
7,
13463,
2571,
13,
16827,
13411,
62,
18,
9988,
272,
1306,
4488,
14,
30995,
342,
272,
1306,
4488,
14,
23787,
63,
4209,
342,
272,
1306,
4488,
14,
2384,
342,
339,
1449,
339,
666,
275,
980,
14,
22900,
63,
17,
68,
8,
576,
9,
339,
340,
818,
508,
283,
14252,
7,
436,
3462,
690,
666,
14,
1392,
59,
3127,
2189,
267,
746,
12009,
547,
480,
6526,
818,
534,
14252,
297,
3462,
7622,
298,
2490,
298,
11250,
24068,
666,
14,
1392,
59,
3127,
61,
7622,
1674,
908,
8,
2063
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
5968,
26212,
15841,
624,
199,
199,
504,
3598,
492,
7987,
199,
646,
2680,
465,
980,
199,
646,
7026,
14,
4653,
199,
199,
504,
1275,
423,
1637,
492,
2581,
199,
504,
2508,
1974,
14,
3924,
492,
12009,
547,
199,
363,
452,
363,
275,
788,
3136,
297,
283,
2340,
63,
4844,
418,
421,
199,
32,
1637,
8,
1896,
29,
2167,
9,
199,
318,
5762,
8,
576,
12,
3462,
29,
25,
12,
1865,
29,
17,
12,
3114,
4022,
17,
12,
818,
534,
14252,
297,
1011,
958,
304,
272,
519,
2344,
8564,
5762,
4534,
26,
2257,
14497,
402,
314,
18883,
272,
402,
314,
1324,
666,
3180,
314,
4895,
3114,
14,
339,
18464,
502,
4534,
787,
9235,
428,
1214,
390,
12267,
13,
39,
393,
1187,
14545,
14,
339,
3897,
272,
4143,
272,
666,
420,
520,
980,
14,
8237,
267,
314,
1324,
666,
3634,
334,
5902,
12,
30900,
293,
1679,
9,
339,
3462,
258,
520,
1109,
12,
7317,
12,
16699,
359,
7033,
61,
267,
4860,
402,
11223,
1806,
1314,
370,
4526,
314,
5762,
4534,
14,
267,
18435,
24068,
314,
2582,
402,
658,
576,
64,
3180,
314,
2013,
3114,
14,
267,
982,
658,
632,
534,
14252,
7,
3559,
2066,
658,
2063,
64,
1471,
506,
737,
5210,
658,
576,
14,
1392,
59,
3127,
20336,
339,
1865,
258,
520,
1109,
690,
378,
359,
7033,
61,
267,
314,
1865,
402,
314,
8865,
4182,
14,
267,
413,
367,
1642,
18883,
12,
499,
367,
3499,
12,
5423,
14,
339,
3114,
420,
520,
1109,
359,
7033,
61,
267,
314,
3114,
3180,
1314,
370,
4526,
27446,
14,
267,
3758,
365,
446,
17,
334,
3406,
680,
339,
818,
520,
620,
12,
791,
14252,
297,
283,
16615,
297,
283,
12324,
297,
283,
4083,
297,
283,
3823,
936,
267,
510,
4095,
818,
367,
4347,
3969,
316,
15109,
737,
314,
18135,
14,
339,
2074,
520,
4722,
4252,
2368,
267,
1666,
658,
14248,
14,
4653,
14,
83,
8595,
393,
63,
1541,
64,
339,
1803,
272,
5514,
272,
5762,
63,
576,
257,
520,
980,
14,
8237,
359,
1392,
2687,
68,
12,
307,
1874,
267,
5762,
3634,
402,
658,
576,
64,
737,
2013,
1865,
339,
8144,
272,
9063,
272,
961,
805,
18014,
737,
2166,
6335,
14,
339,
1666,
6121,
272,
3001,
272,
7026,
14,
4653,
14,
83,
8595,
393,
63,
1541,
339,
6058,
272,
3001,
272,
8354,
603,
38,
2571,
27446,
12,
5762,
13,
25446,
339,
1306,
612,
12,
11483,
275,
1973,
293,
2231,
14,
912,
8,
773,
293,
2231,
14,
1974,
14,
2694,
63,
8130,
63,
493,
1012,
272,
1306,
19751,
2055,
275,
1973,
293,
2231,
14,
4445,
14,
11821,
2055,
8,
89,
29,
89,
12,
11483,
29,
5474,
9,
272,
1306,
19751,
2055,
63,
3136,
275,
1973,
293,
2231,
14,
4445,
14,
3136,
8,
11821,
2055,
9,
272,
1306,
19751,
2055,
63,
3136,
272,
1625,
4038,
221,
413,
14,
11829,
69,
11,
614,
12,
257,
413,
14,
11829,
69,
11,
614,
12,
14263,
257,
413,
14,
13254,
69,
13,
1046,
12,
257,
413,
14,
13254,
69,
13,
1046,
467,
1779,
359,
221,
413,
14,
28394,
69,
11,
614,
12,
257,
413,
14,
28394,
69,
11,
614,
12,
14263,
257,
1227,
14,
17494,
69,
13,
2192,
12,
257,
1227,
14,
17494,
69,
13,
2192,
467,
1779,
14263,
1779,
359,
221,
1520,
14,
14820,
69,
13,
614,
12,
257,
1520,
14,
14820,
69,
13,
614,
12,
14263,
257,
1749,
14,
11990,
69,
13,
2192,
12,
257,
1749,
14,
11990,
69,
13,
2192,
467,
1779,
359,
221,
1227,
14,
14992,
69,
13,
614,
12,
257,
1227,
14,
14992,
69,
13,
614,
12,
14263,
257,
1520,
14,
15459,
69,
13,
2192,
12,
257,
1520,
14,
15459,
69,
13,
2192,
3934,
339,
1306,
19751,
2055,
63,
3136,
18,
275,
1973,
293,
2231,
14,
4445,
14,
3136,
8,
11821,
2055,
12,
1865,
29,
18,
9,
272,
1306,
19751,
2055,
63,
3136,
18,
272,
1625,
4038,
446,
17,
14,
23,
1644,
69,
11,
614,
12,
221,
446,
17,
14,
23,
1644,
69,
11,
614,
12,
14263,
257,
650,
14,
31230,
69,
13,
1079,
12,
257,
650,
14,
31230,
69,
13,
1079,
467,
1779,
359,
446,
17,
14,
8079,
69,
11,
614,
12,
221,
446,
17,
14,
8079,
69,
11,
614,
12,
14263,
221,
446,
17,
14,
19846,
69,
13,
1216,
12,
221,
446,
17,
14,
19846,
69,
13,
1216,
467,
1779,
14263,
1779,
359,
221,
841,
14,
19339,
69,
13,
614,
12,
257,
841,
14,
19339,
69,
13,
614,
12,
14263,
221,
446,
17,
14,
15670,
69,
13,
1216,
12,
221,
446,
17,
14,
15670,
69,
13,
1216,
467,
1779,
359,
221,
413,
14,
19087,
69,
13,
614,
12,
257,
413,
14,
19087,
69,
13,
614,
12,
14263,
221,
446,
18,
14,
6785,
69,
13,
1216,
12,
221,
446,
18,
14,
6785,
69,
13,
1216,
3934,
339,
1306,
492,
8027,
14,
13563,
465,
4488,
272,
1306,
4488,
14,
13334,
8,
19,
12,
413,
12,
413,
9,
272,
1306,
1973,
293,
2231,
14,
2918,
14,
1650,
2384,
8,
11821,
2055,
9,
272,
1306,
4488,
14,
1213,
360,
13463,
2571,
358,
272,
1306,
4488,
14,
30995,
342,
272,
1306,
4488,
14,
13334,
8,
19,
12,
413,
12,
499,
9,
272,
1306,
1973,
293,
2231,
14,
2918,
14,
1650,
2384,
8,
11821,
2055,
63,
3136,
9,
272,
1306,
4488,
14,
1213,
8,
82,
7,
13463,
2571,
13,
16827,
13411,
9988,
272,
1306,
4488,
14,
30995,
342,
272,
1306,
4488,
14,
13334,
8,
19,
12,
413,
12,
650,
9,
272,
1306,
1973,
293,
2231,
14,
2918,
14,
1650,
2384,
8,
11821,
2055,
63,
3136,
18,
12,
671,
63,
3127,
534,
521,
358,
272,
1306,
4488,
14,
1213,
8,
82,
7,
13463,
2571,
13,
16827,
13411,
62,
18,
9988,
272,
1306,
4488,
14,
30995,
342,
272,
1306,
4488,
14,
23787,
63,
4209,
342,
272,
1306,
4488,
14,
2384,
342,
339,
1449,
339,
666,
275,
980,
14,
22900,
63,
17,
68,
8,
576,
9,
339,
340,
818,
508,
283,
14252,
7,
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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
] |
krafczyk/root-5.34.09-ams
|
cint/reflex/python/genreflex/genreflex.py
|
4
|
18641
|
# Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose is hereby granted without fee, provided that this copyright and
# permissions notice appear in all copies and derivatives.
#
# This software is provided "as is" without express or implied warranty.
import sys, os, gendict, selclass, gencapa, genrootmap, string, getopt, subprocess
class genreflex:
#----------------------------------------------------------------------------------
def __init__(self):
self.files = []
self.output = None
self.outputDir = None
self.outputFile = None
self.capabilities = None
self.rootmap = None
self.rootmaplib = None
self.select = None
self.cppopt = ''
self.deep = False
self.opts = {}
self.gccxmlpath = None
self.gccxmlpost = ''
self.gccxmlopt = ''
self.gccxmlvers = '[UNKNOWN]'
self.selector = None
self.gccxml = ''
self.quiet = False
#----------------------------------------------------------------------------------
def usage(self, status = 1) :
print 'Usage:'
print ' genreflex headerfile1.h [headerfile2.h] [options] [preprocesor options]'
print 'Try "genreflex --help" for more information.'
sys.exit(status)
#----------------------------------------------------------------------------------
def help(self) :
print """Generates the LCG dictionary file for each header file\n
Usage:
genreflex headerfile1.h [headerfile2.h] [options] [preprocesor options]\n
Options:
-s <file>, --selection_file=<file>
Class selection file to specify for which classes the dictionary
will be generated
Format (XML):
<lcgdict>
[<selection>]
<class [name="classname"] [pattern="wildname"]
[file_name="filename"] [file_pattern="wildname"]
[id="xxxx"] [type="vector"]/>
<class name="classname" >
<field name="m_transient" transient="true"/>
<field name="m_anothertransient" transient="true"/>
<properties prop1="value1" [prop2="value2"]/>
</class>
<function [name="funcname"] [pattern="wildname"] />
<enum [name="enumname"] [pattern="wildname"] />
<variable [name="varname"] [pattern="wildname"] />
[</selection>]
<exclusion>
<class [name="classname"] [pattern="wildname"] />
<method name="unwanted" />
</class>
...
</lcgdict>\n
-o <file>, --output <file>
Output file name. If an existing directory is specified instead of a file,
then a filename will be build using the name of the input file and will
be placed in the given directory. <headerfile>_rflx.cpp \n
--pool, --dataonly
Generate minimal dictionary required for POOL persistency\n
--interpreteronly
Generate minimal dictionary required for interpreter\n
--deep
Generate dictionary for all dependend classes\n
--split=[classdef]
Generate a separate file for the given dictionary parts, currently supported part: classdef implementations.\n
--reflex (OBSOLETE)
Generate Reflex dictionaries.\n
--comments
Add end-of-line comments in data and functions members as a property called "comment" \n
--iocomments
Add end-of-line comments in data and functions members as a property called "comment", but only for comments relevant for ROOT I/O \n
--no_membertypedefs
Disable the definition of class member typedefs \n
--no_templatetypedefs
Disable resolving of typedefs in template parameters for selection names. E.g. std::vector<MYINT>.\n
--fail_on_warnings
The genreflex command fails (retuns the value 1) if any warning message is issued \n
--gccxmlpath=<path>
Path path where the gccxml tool is installed.
If not defined the standard PATH environ variable is used\n
--gccxmlopt=<gccxmlopt>
Options to be passed directly to gccxml\n
--gccxmlpost=<xmlfile>
Instead of invoking GCCXML process the xmlfile generated by GCCXML. Mainly useful for debugging.\n
-c <file>, --capabilities=<file>
Generate the capabilities file to be used by the SEAL Plugin Manager. This file
lists the names of all classes for which the reflection is formation is provided.\n
--rootmap=<file>
Generate the rootmap file to be used by ROOT/CINT. This file lists the names of
all classes for which the reflection is formation is provided.\n
--rootmap-lib=<library>
Library name for the rootmap file.\n
--debug
Print extra debug information while processing. Keep intermediate files\n
--quiet
Do not print informational messages\n
-h, --help
Print this help\n
"""
sys.exit()
#----------------------------------------------------------------------------------
def parse_args(self, argv = sys.argv) :
options = []
#----Ontain the list of files to process------------
for a in argv[1:] :
if a[0] != '-' :
self.files.append(a)
else :
options = argv[argv.index(a):]
break
#----Process options--------------------------------
try:
opts, args = getopt.getopt(options, 'ho:s:c:I:U:D:PC', \
['help','debug=', 'output=','selection_file=','pool','dataonly','interpreteronly','deep','gccxmlpath=',
'capabilities=','rootmap=','rootmap-lib=','comments','iocomments','no_membertypedefs',
'fail_on_warnings', 'quiet', 'gccxmlopt=', 'reflex', 'split=','no_templatetypedefs','gccxmlpost='])
except getopt.GetoptError, e:
print "--->> genreflex: ERROR:",e
self.usage(2)
self.output = '.'
self.select = None
self.gccxmlpath = None
self.cppopt = ''
self.pool = 0
self.interpreter = 0
for o, a in opts:
if o in ('-h', '--help'):
self.help()
if o in ('--no_templatetypedefs',):
self.opts['resolvettd'] = 0
if o in ('--debug',):
self.opts['debug'] = a
if o in ('-o', '--output'):
self.output = a
if o in ('-s', '--selection_file'):
self.select = a
if o in ('--pool',):
self.opts['pool'] = True
if o in ('--dataonly',):
self.opts['pool'] = True
if o in ('--interpreteronly',):
self.opts['interpreter'] = True
if o in ('--deep',):
self.deep = True
if o in ('--split',):
if self.opts.has_key('split') :
self.opts['split'] += ':' + a.lower()
else :
self.opts['split'] = a
if o in ('--reflex',):
print '--->> genreflex: WARNING: --reflex option is obsolete'
if o in ('--comments',):
self.opts['comments'] = True
if o in ('--iocomments',):
self.opts['iocomments'] = True
if o in ('--no_membertypedefs',):
self.opts['no_membertypedefs'] = True
if o in ('--fail_on_warnings',):
self.opts['fail_on_warnings'] = True
if o in ('--quiet',):
self.opts['quiet'] = True
self.quiet = True
if o in ('--gccxmlpath',):
self.gccxmlpath = a
if o in ('--gccxmlopt',):
self.gccxmlopt += a +' '
if o in ('--gccxmlpost',):
self.gccxmlpost = a
if o in ('-c', '--capabilities'):
self.capabilities = a
if o in ('--rootmap',):
self.rootmap = a
if o in ('--rootmap-lib',):
self.rootmaplib = a
if o in ('-I', '-U', '-D', '-P', '-C') :
# escape quotes; we need to use " because of windows cmd
poseq = a.find('=')
if poseq > 0 and a[poseq + 1] == '"' and a[-1] == '"' :
a = a[0:poseq + 1] + '\\' + a[poseq+1:-1] + '\\"'
self.cppopt += '"' + o + a + '" '
#----------------------------------------------------------------------------------
def check_files_dirs(self):
#---Check existance of input files--------------------
if self.files :
for f in self.files :
if not os.path.exists(f) :
print '--->> genreflex: ERROR: C++ file "' + f + '" not found'
self.usage()
else:
if self.gccxmlpost == '' :
print '--->> genreflex: ERROR: No input file specified'
self.usage()
else:
self.files = ['GCCXML_postproc_' + self.gccxmlpost]
#---Check existance of output directory----------------
if os.path.isdir(self.output) :
self.outputDir = self.output
self.outputFile = None
else :
self.outputDir, self.outputFile = os.path.split(self.output)
if self.outputDir and not os.path.isdir(self.outputDir) :
print '--->> genreflex: ERROR: Output directory ', self.outputDir, ' not found'
self.usage()
#---Hande selection class file-------------------------
classes = []
if self.select :
if not os.path.exists(self.select) :
print '--->> genreflex: ERROR: Class selection file "' + self.select + '" not found'
self.usage()
for l in open(self.select).readlines() : classes.append(l[:-1])
#----------GCCXML command------------------------------
self.gccxml = ''
if not self.gccxmlpath:
try:
import gccxmlpath
self.gccxmlpath = gccxmlpath.gccxmlpath
except:
pass
if self.gccxmlpath :
if sys.platform == 'win32' :
self.gccxml = self.gccxmlpath + os.sep + 'gccxml.exe'
else :
self.gccxml = self.gccxmlpath + os.sep + 'gccxml'
if not os.path.isfile(self.gccxml) :
print '--->> genreflex: ERROR: Path to gccxml given, but no executable found at', self.gccxml
self.gccxml = ''
if len(self.gccxml) == 0 :
if self.which('gccxml') :
self.gccxml = 'gccxml'
print '--->> genreflex: INFO: Using gccxml from', self.which('gccxml')
else :
print '--->> genreflex: ERROR: Cannot find gccxml executable, aborting!'
sys.exit(1)
#---------------Open selection file-------------------
try :
if self.select : self.selector = selclass.selClass(self.select,parse=1)
else : self.selector = None
except :
sys.exit(1)
#----------------------------------------------------------------------------------
def genGccxmlInfo(self):
s = ''
p = subprocess.Popen('"' + self.gccxml + '" --print', shell=True,
bufsize=-1, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds = (sys.platform != 'win32'))
(inp, out, err) = (p.stdin, p.stdout, p.stderr)
sout = out.read()
serr = err.read()
if serr :
print '--->> genreflex: WARNING: Could not invoke %s --print' % self.gccxml
print '--->> genreflex: WARNING: %s' % serr
return s
self.gccxmlvers = sout.split('\n')[0].split()[-1]
recommendedvers = ( '0.7.0_20070615', '0.9.' )
foundgoodvers = filter(lambda c: self.gccxmlvers.startswith(c), recommendedvers)
if len(foundgoodvers) == 0:
plural = ''
if len(recommendedvers) > 1 : plural = 's'
print '--->> genreflex: WARNING: gccxml versions differ. Used version: %s. Recommended version%s: %s ' \
% ( self.gccxmlvers, plural, ', '.join(recommendedvers) )
print '--->> genreflex: WARNING: gccxml binary used: %s' % ( self.gccxml )
s += sout
compiler = ''
for l in sout.split('\n'):
ll = l.split('"')
if ll[0].find('GCCXML_COMPILER') != -1 :
compiler = ll[1]
break
bcomp = os.path.basename(compiler)
vopt = ''
if bcomp in ('msvc7','msvc71','msvc8') : return s
elif bcomp in ('gcc','g++','c++') : vopt = '--version'
elif bcomp in ('cl.exe','cl') : vopt = '' # there is no option to print only the version with cl
else :
print '--->> genreflex: WARNING: While trying to retrieve compiler version, found unknown compiler %s' % compiler
return s
p = subprocess.Popen('"%s" %s'%(compiler,vopt), shell=True, bufsize=-1,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=(sys.platform != 'win32'))
(inp,out,err) = (p.stdin, p.stdout, p.stderr)
serr = err.read()
# cl puts its version into cerr!
if serr:
if bcomp in ('cl.exe','cl') and serr.find('is not recognized') == -1:
s += '\nCompiler info:\n' + serr
return s
else:
print '--->> genreflex: WARNING: While trying to retrieve compiler information. Cannot invoke %s %s' % (compiler,vopt)
print '--->> genreflex: WARNING: %s' % serr
return s
s += '\nCompiler info:\n' + out.read()
return s
#----------------------------------------------------------------------------------
def process_files(self):
total_errors = 0
total_warnings = 0
file_extension = '_rflx.cpp'
#----------Loop oover all the input files--------------
gccxmlinfo = self.genGccxmlInfo()
for source in self.files :
path, fullname = os.path.split(source)
name = fullname[:fullname.find('.')]
xmlfile = os.path.join(self.outputDir,name+'_gccxmlout.xml')
if( self.outputFile ) :
dicfile = os.path.join(self.outputDir,self.outputFile)
else :
dicfile = os.path.join(self.outputDir,name+file_extension)
if self.gccxmlpost == '' :
#---------------Parse the header file with GCC_XML
if sys.platform == 'win32' :
cmd = '"%s" %s "%s" -fxml=%s %s -D__REFLEX__' %(self.gccxml, self.gccxmlopt, source, xmlfile, self.cppopt)
else :
cmd = '%s %s "%s" -fxml=%s %s -D__REFLEX__' %(self.gccxml, self.gccxmlopt, source, xmlfile, self.cppopt)
if 'debug' in self.opts : print '--->> genreflex: INFO: invoking ', cmd
if not self.quiet : print '--->> genreflex: INFO: Parsing file %s with GCC_XML' % source,
if sys.platform == 'win32' :
# bug http://bugs.python.org/issue1524: os.system fails if the
# command is quoted and something else in the command is quoted.
# Workaround: prepend "call ":
cmd = "call " + cmd
status = os.system(cmd)
if status :
print '\n--->> genreflex: ERROR: processing file with gccxml. genreflex command failed.'
total_errors += 1
continue
else:
if not self.quiet : print 'OK'
else:
if not self.quiet : print '--->> genreflex: INFO: Postprocessing GCC_XML output file', self.gccxmlpost
xmlfile = self.gccxmlpost
#---------------Generate the dictionary---------------
if not self.quiet : print '--->> genreflex: INFO: Generating Reflex Dictionary'
dg = gendict.genDictionary(source, self.opts, self.gccxmlvers)
dg.parse(xmlfile)
classes = dg.selclasses(self.selector, self.deep)
functions = dg.selfunctions(self.selector)
enums = dg.selenums(self.selector)
variables = dg.selvariables(self.selector)
try:
if self.selector :
cnames, warnings, errors = dg.generate(dicfile, classes, functions, enums, variables, gccxmlinfo,
self.selector.io_read_rules, self.selector.io_readraw_rules )
else :
cnames, warnings, errors = dg.generate(dicfile, classes, functions, enums, variables, gccxmlinfo)
if errors or (warnings and self.opts.get('fail_on_warnings', False)): os.remove(dicfile)
except:
# remove output file even if evil things happened
os.remove(dicfile)
raise
total_errors += errors
total_warnings += warnings
#------------Produce Seal Capabilities source file------
if self.capabilities :
if os.path.isdir(self.capabilities) :
capfile = os.path.join(self.capabilities, 'capabilities.cpp')
else :
capfile = os.path.join(self.outputDir, self.capabilities)
gencapa.genCapabilities(capfile, name, cnames)
#------------Produce rootmap file-----------------------
if self.rootmap :
if os.path.isdir(self.rootmap) :
mapfile = os.path.join(self.rootmap, 'rootmap')
else :
mapfile = os.path.join(self.outputDir, self.rootmap)
if not self.rootmaplib : self.rootmaplib = 'lib'+name+'.so'
for td in dg.typedefs_for_usr:
# Autoload entries are classes by default. Only include non-free typedefs
# such that CINT gets notified that they are not classes when their enclosed
# scope's dictionary is set up.
# Scoped names have name != fullname; ensure that the typedef's scope is
# part of the dictionary, too.
if td['fullname'] != td['name'] \
and len(td['fullname']) > 3 \
and td['fullname'][0:-len(td['name']) - 2] in cnames:
cnames += [ td['fullname'] ]
classes+= dg.typedefs_for_usr
genrootmap.genRootMap(mapfile, name, self.rootmaplib, cnames, classes)
#------------Delete intermediate files------------------
if 'debug' not in self.opts and self.gccxmlpost == '':
os.remove(xmlfile)
#------------Report unused class selections in selection
if self.selector :
total_warnings += self.selector.reportUnusedClasses()
#------------Exit with status if errors ----------------
if total_errors:
sys.exit(1)
#------------Exit with status if warnings --------------
if total_warnings and self.opts.get('fail_on_warnings',False) :
os.remove(dicfile)
print '--->> genreflex: ERROR: Exiting with error due to %d warnings ( --fail_on_warnings enabled )' % total_warnings
sys.exit(1)
#---------------------------------------------------------------------
def which(self, name) :
if 'PATH' in os.environ :
if sys.platform == 'win32' : name += '.exe'
for p in os.environ['PATH'].split(os.pathsep) :
path = os.path.join(p,name)
if os.path.exists(path) : return path
return None
#---------------------------------------------------------------------
if __name__ == "__main__":
l = genreflex()
l.parse_args()
l.check_files_dirs()
l.process_files()
|
lgpl-2.1
|
[
3,
1898,
24354,
12,
6624,
13,
713,
845,
598,
6349,
3042,
6546,
12,
8353,
13,
7968,
12,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
365,
11882,
10009,
1928,
14751,
12,
2741,
626,
642,
4248,
436,
199,
3,
3443,
4245,
7468,
315,
1006,
6866,
436,
28059,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
298,
305,
365,
2,
1928,
4056,
503,
2478,
3750,
14,
199,
199,
646,
984,
12,
747,
12,
3805,
807,
12,
13680,
533,
12,
3805,
18182,
12,
3805,
1231,
1130,
12,
1059,
12,
12733,
12,
3873,
199,
199,
533,
3805,
1121,
3113,
26,
199,
7656,
777,
306,
523,
347,
636,
826,
721,
277,
304,
272,
291,
14,
1725,
3698,
275,
942,
272,
291,
14,
1199,
3515,
275,
488,
272,
291,
14,
1199,
3567,
755,
275,
488,
272,
291,
14,
1199,
1173,
420,
275,
488,
272,
291,
14,
10732,
259,
275,
488,
272,
291,
14,
1231,
1130,
260,
275,
488,
272,
291,
14,
1231,
1130,
773,
420,
275,
488,
272,
291,
14,
2416,
3515,
275,
488,
272,
291,
14,
5910,
2992,
3515,
275,
2125,
272,
291,
14,
16131,
3322,
275,
756,
272,
291,
14,
3291,
3322,
275,
1052,
272,
291,
14,
13112,
1652,
515,
420,
275,
488,
272,
291,
14,
13112,
1652,
1932,
420,
275,
2125,
272,
291,
14,
13112,
10198,
30379,
755,
275,
2125,
272,
291,
14,
13112,
1652,
14895,
420,
275,
6730,
11588,
6616,
272,
291,
14,
6662,
263,
275,
488,
272,
291,
14,
13112,
1652,
3515,
275,
2125,
272,
291,
14,
10243,
3698,
275,
756,
199,
7656,
777,
306,
523,
347,
4503,
8,
277,
12,
2004,
275,
413,
9,
520,
272,
870,
283,
7692,
4881,
272,
870,
283,
221,
3805,
1121,
3113,
1406,
493,
17,
14,
72,
359,
1291,
493,
18,
14,
72,
61,
359,
1419,
61,
359,
657,
496,
823,
269,
1511,
6616,
272,
870,
283,
12357,
298,
2268,
1121,
3113,
1553,
3437,
2,
367,
1655,
2556,
3530,
272,
984,
14,
2224,
8,
1205,
9,
199,
7656,
777,
306,
523,
347,
1720,
8,
277,
9,
520,
272,
870,
408,
20551,
314,
491,
4064,
2600,
570,
367,
1924,
1406,
570,
60,
78,
272,
11028,
26,
489,
3805,
1121,
3113,
1406,
493,
17,
14,
72,
359,
1291,
493,
18,
14,
72,
61,
359,
1419,
61,
359,
657,
496,
823,
269,
1511,
7272,
78,
14821,
8394,
26,
489,
446,
83,
665,
493,
6244,
1553,
5592,
63,
493,
18987,
493,
30,
268,
8089,
7267,
570,
370,
4165,
367,
1314,
3992,
314,
2600,
268,
911,
506,
4046,
268,
9701,
334,
4317,
304,
1779,
665,
10181,
71,
807,
30,
1779,
24936,
5592,
19109,
1467,
665,
533,
359,
354,
628,
19851,
937,
359,
3401,
628,
87,
668,
354,
937,
15324,
359,
493,
63,
354,
628,
1501,
937,
359,
493,
63,
3401,
628,
87,
668,
354,
937,
15324,
359,
344,
628,
5336,
937,
359,
466,
628,
4106,
937,
3133,
1467,
665,
533,
536,
628,
19851,
2,
690,
2049,
665,
698,
536,
628,
77,
63,
23387,
2,
7115,
14928,
628,
2052,
7897,
2049,
665,
698,
536,
628,
77,
63,
13565,
23387,
2,
7115,
14928,
628,
2052,
7897,
2049,
665,
3282,
5931,
17,
628,
585,
17,
2,
359,
4469,
18,
628,
585,
18,
937,
3133,
1467,
3068,
533,
30,
1467,
665,
1593,
359,
354,
628,
29577,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
1467,
665,
4869,
359,
354,
628,
4869,
354,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
1467,
665,
1975,
359,
354,
628,
16043,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
1779,
359,
1108,
5592,
19109,
1779,
665,
476,
10248,
30,
1467,
665,
533,
359,
354,
628,
19851,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
2049,
665,
765,
536,
628,
324,
19361,
2,
7082,
1467,
3068,
533,
30,
1779,
2263,
1779,
3068,
10181,
71,
807,
3072,
78,
489,
446,
79,
665,
493,
6244,
1553,
1199,
665,
493,
30,
268,
7242,
570,
536,
14,
982,
376,
3411,
2082,
365,
2013,
3140,
402,
282,
570,
12,
268,
2066,
282,
1788,
911,
506,
1900,
1808,
314,
536,
402,
314,
1324,
570,
436,
911,
268,
506,
15090,
315,
314,
1627,
2082,
14,
665,
1291,
493,
30,
63,
82,
2327,
88,
14,
5910,
971,
78,
489,
1553,
2293,
12,
1553,
576,
2118,
268,
7958,
13460,
2600,
1415,
367,
3625,
2228,
1126,
10398,
60,
78,
489,
1553,
20244,
2118,
268,
7958,
13460,
2600,
1415,
367,
12693,
60,
78,
489,
1553,
16131,
268,
7958,
2600,
367,
1006,
477,
2230,
68,
3992,
60,
78,
489,
1553,
1294,
1524,
533,
318,
61,
268,
7958,
282,
7396,
570,
367,
314,
1627,
2600,
4184,
12,
5544,
3748,
1777,
26,
1021,
318,
12591,
3134,
78,
489,
1553,
1121,
3113,
221,
334,
5488,
15096,
5248,
9,
268,
7958,
799,
14759,
11196,
3134,
78,
489,
1553,
6223,
268,
2654,
1284,
13,
1618,
13,
604,
6786,
315,
666,
436,
3423,
7556,
465,
282,
3324,
2797,
298,
3349,
2,
971,
78,
489,
1553,
2308,
6223,
268,
2654,
1284,
13,
1618,
13,
604,
6786,
315,
666,
436,
3423,
7556,
465,
282,
3324,
2797,
298,
3349,
401,
1325,
1454,
367,
6786,
12082,
367,
16547,
473,
15,
47,
971,
78,
489,
1553,
889,
63,
1114,
466,
8710,
268,
17534,
314,
5492,
402,
1021,
3653,
730,
8710,
971,
78,
489,
1553,
889,
63,
1160,
466,
8710,
268,
17534,
30685,
402,
730,
8710,
315,
1978,
2633,
367,
7267,
1561,
14,
662,
14,
71,
14,
2418,
447,
4106,
28,
12339,
2919,
30,
3134,
78,
489,
1553,
1633,
63,
265,
63,
5451,
268,
710,
3805,
1121,
3113,
1414,
6918,
334,
3292,
324,
83,
314,
574,
413,
9,
340,
1263,
5721,
1245,
365,
21117,
971,
78,
489,
1553,
13112,
1652,
515,
18987,
515,
30,
268,
6912,
931,
2382,
314,
19443,
1652,
4744,
365,
4903,
14,
268,
982,
440,
3247,
314,
4465,
15097,
6160,
1750,
365,
1202,
60,
78,
489,
1553,
13112,
10198,
30379,
18987,
13112,
10198,
30379,
30,
268,
8394,
370,
506,
3032,
5370,
370,
19443,
1652,
60,
78,
489,
1553,
13112,
1652,
1932,
18987,
10198,
12059,
30,
268,
15345,
402,
26750,
598,
2571,
4317,
2112,
314,
17725,
12059,
4046,
701,
598,
2571,
4317,
14,
11298,
590,
2997,
367,
10201,
3134,
78,
489,
446,
67
] |
[
1898,
24354,
12,
6624,
13,
713,
845,
598,
6349,
3042,
6546,
12,
8353,
13,
7968,
12,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
365,
11882,
10009,
1928,
14751,
12,
2741,
626,
642,
4248,
436,
199,
3,
3443,
4245,
7468,
315,
1006,
6866,
436,
28059,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
298,
305,
365,
2,
1928,
4056,
503,
2478,
3750,
14,
199,
199,
646,
984,
12,
747,
12,
3805,
807,
12,
13680,
533,
12,
3805,
18182,
12,
3805,
1231,
1130,
12,
1059,
12,
12733,
12,
3873,
199,
199,
533,
3805,
1121,
3113,
26,
199,
7656,
777,
306,
523,
347,
636,
826,
721,
277,
304,
272,
291,
14,
1725,
3698,
275,
942,
272,
291,
14,
1199,
3515,
275,
488,
272,
291,
14,
1199,
3567,
755,
275,
488,
272,
291,
14,
1199,
1173,
420,
275,
488,
272,
291,
14,
10732,
259,
275,
488,
272,
291,
14,
1231,
1130,
260,
275,
488,
272,
291,
14,
1231,
1130,
773,
420,
275,
488,
272,
291,
14,
2416,
3515,
275,
488,
272,
291,
14,
5910,
2992,
3515,
275,
2125,
272,
291,
14,
16131,
3322,
275,
756,
272,
291,
14,
3291,
3322,
275,
1052,
272,
291,
14,
13112,
1652,
515,
420,
275,
488,
272,
291,
14,
13112,
1652,
1932,
420,
275,
2125,
272,
291,
14,
13112,
10198,
30379,
755,
275,
2125,
272,
291,
14,
13112,
1652,
14895,
420,
275,
6730,
11588,
6616,
272,
291,
14,
6662,
263,
275,
488,
272,
291,
14,
13112,
1652,
3515,
275,
2125,
272,
291,
14,
10243,
3698,
275,
756,
199,
7656,
777,
306,
523,
347,
4503,
8,
277,
12,
2004,
275,
413,
9,
520,
272,
870,
283,
7692,
4881,
272,
870,
283,
221,
3805,
1121,
3113,
1406,
493,
17,
14,
72,
359,
1291,
493,
18,
14,
72,
61,
359,
1419,
61,
359,
657,
496,
823,
269,
1511,
6616,
272,
870,
283,
12357,
298,
2268,
1121,
3113,
1553,
3437,
2,
367,
1655,
2556,
3530,
272,
984,
14,
2224,
8,
1205,
9,
199,
7656,
777,
306,
523,
347,
1720,
8,
277,
9,
520,
272,
870,
408,
20551,
314,
491,
4064,
2600,
570,
367,
1924,
1406,
570,
60,
78,
272,
11028,
26,
489,
3805,
1121,
3113,
1406,
493,
17,
14,
72,
359,
1291,
493,
18,
14,
72,
61,
359,
1419,
61,
359,
657,
496,
823,
269,
1511,
7272,
78,
14821,
8394,
26,
489,
446,
83,
665,
493,
6244,
1553,
5592,
63,
493,
18987,
493,
30,
268,
8089,
7267,
570,
370,
4165,
367,
1314,
3992,
314,
2600,
268,
911,
506,
4046,
268,
9701,
334,
4317,
304,
1779,
665,
10181,
71,
807,
30,
1779,
24936,
5592,
19109,
1467,
665,
533,
359,
354,
628,
19851,
937,
359,
3401,
628,
87,
668,
354,
937,
15324,
359,
493,
63,
354,
628,
1501,
937,
359,
493,
63,
3401,
628,
87,
668,
354,
937,
15324,
359,
344,
628,
5336,
937,
359,
466,
628,
4106,
937,
3133,
1467,
665,
533,
536,
628,
19851,
2,
690,
2049,
665,
698,
536,
628,
77,
63,
23387,
2,
7115,
14928,
628,
2052,
7897,
2049,
665,
698,
536,
628,
77,
63,
13565,
23387,
2,
7115,
14928,
628,
2052,
7897,
2049,
665,
3282,
5931,
17,
628,
585,
17,
2,
359,
4469,
18,
628,
585,
18,
937,
3133,
1467,
3068,
533,
30,
1467,
665,
1593,
359,
354,
628,
29577,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
1467,
665,
4869,
359,
354,
628,
4869,
354,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
1467,
665,
1975,
359,
354,
628,
16043,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
1779,
359,
1108,
5592,
19109,
1779,
665,
476,
10248,
30,
1467,
665,
533,
359,
354,
628,
19851,
937,
359,
3401,
628,
87,
668,
354,
937,
7082,
2049,
665,
765,
536,
628,
324,
19361,
2,
7082,
1467,
3068,
533,
30,
1779,
2263,
1779,
3068,
10181,
71,
807,
3072,
78,
489,
446,
79,
665,
493,
6244,
1553,
1199,
665,
493,
30,
268,
7242,
570,
536,
14,
982,
376,
3411,
2082,
365,
2013,
3140,
402,
282,
570,
12,
268,
2066,
282,
1788,
911,
506,
1900,
1808,
314,
536,
402,
314,
1324,
570,
436,
911,
268,
506,
15090,
315,
314,
1627,
2082,
14,
665,
1291,
493,
30,
63,
82,
2327,
88,
14,
5910,
971,
78,
489,
1553,
2293,
12,
1553,
576,
2118,
268,
7958,
13460,
2600,
1415,
367,
3625,
2228,
1126,
10398,
60,
78,
489,
1553,
20244,
2118,
268,
7958,
13460,
2600,
1415,
367,
12693,
60,
78,
489,
1553,
16131,
268,
7958,
2600,
367,
1006,
477,
2230,
68,
3992,
60,
78,
489,
1553,
1294,
1524,
533,
318,
61,
268,
7958,
282,
7396,
570,
367,
314,
1627,
2600,
4184,
12,
5544,
3748,
1777,
26,
1021,
318,
12591,
3134,
78,
489,
1553,
1121,
3113,
221,
334,
5488,
15096,
5248,
9,
268,
7958,
799,
14759,
11196,
3134,
78,
489,
1553,
6223,
268,
2654,
1284,
13,
1618,
13,
604,
6786,
315,
666,
436,
3423,
7556,
465,
282,
3324,
2797,
298,
3349,
2,
971,
78,
489,
1553,
2308,
6223,
268,
2654,
1284,
13,
1618,
13,
604,
6786,
315,
666,
436,
3423,
7556,
465,
282,
3324,
2797,
298,
3349,
401,
1325,
1454,
367,
6786,
12082,
367,
16547,
473,
15,
47,
971,
78,
489,
1553,
889,
63,
1114,
466,
8710,
268,
17534,
314,
5492,
402,
1021,
3653,
730,
8710,
971,
78,
489,
1553,
889,
63,
1160,
466,
8710,
268,
17534,
30685,
402,
730,
8710,
315,
1978,
2633,
367,
7267,
1561,
14,
662,
14,
71,
14,
2418,
447,
4106,
28,
12339,
2919,
30,
3134,
78,
489,
1553,
1633,
63,
265,
63,
5451,
268,
710,
3805,
1121,
3113,
1414,
6918,
334,
3292,
324,
83,
314,
574,
413,
9,
340,
1263,
5721,
1245,
365,
21117,
971,
78,
489,
1553,
13112,
1652,
515,
18987,
515,
30,
268,
6912,
931,
2382,
314,
19443,
1652,
4744,
365,
4903,
14,
268,
982,
440,
3247,
314,
4465,
15097,
6160,
1750,
365,
1202,
60,
78,
489,
1553,
13112,
10198,
30379,
18987,
13112,
10198,
30379,
30,
268,
8394,
370,
506,
3032,
5370,
370,
19443,
1652,
60,
78,
489,
1553,
13112,
1652,
1932,
18987,
10198,
12059,
30,
268,
15345,
402,
26750,
598,
2571,
4317,
2112,
314,
17725,
12059,
4046,
701,
598,
2571,
4317,
14,
11298,
590,
2997,
367,
10201,
3134,
78,
489,
446,
67,
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
] |
ivelum/graphql-py
|
tests/test_lexer.py
|
1
|
4421
|
from decimal import Decimal
from unittest import TestCase
from graphql.lexer import GraphQLLexer
from graphql.exceptions import LexerError
class GraphQLLexerTest(TestCase):
lexer = GraphQLLexer()
def assert_output(self, lexer, expected):
actual = list(lexer)
len_actual = len(actual)
len_expected = len(expected)
self.assertEqual(
len_actual,
len_expected,
'Actual output length %s does not match expected length %s\n'
'Actual: %s\n'
'Expected: %s' % (len_actual, len_expected, actual, expected)
)
for i, token in enumerate(actual):
self.assertEqual(token.type, expected[i][0])
self.assertEqual(token.value, expected[i][1])
def test_punctuator(self):
self.assert_output(self.lexer.input('!'), [('BANG', '!')])
self.assert_output(self.lexer.input('$'), [('DOLLAR', '$')])
self.assert_output(self.lexer.input('('), [('PAREN_L', '(')])
self.assert_output(self.lexer.input(')'), [('PAREN_R', ')')])
self.assert_output(self.lexer.input(':'), [('COLON', ':')])
self.assert_output(self.lexer.input('='), [('EQUALS', '=')])
self.assert_output(self.lexer.input('@'), [('AT', '@')])
self.assert_output(self.lexer.input('['), [('BRACKET_L', '[')])
self.assert_output(self.lexer.input(']'), [('BRACKET_R', ']')])
self.assert_output(self.lexer.input('{'), [('BRACE_L', '{')])
self.assert_output(self.lexer.input('}'), [('BRACE_R', '}')])
self.assert_output(self.lexer.input('...'), [('SPREAD', '...')])
def test_name(self):
for name in ('a', 'myVar_42', '__LOL__', '_', '_0'):
self.assert_output(self.lexer.input(name), [('NAME', name)])
def test_reserved_words(self):
reserved = ('fragment', 'query', 'mutation', 'on')
for word in reserved:
self.assert_output(self.lexer.input(word), [(word.upper(), word)])
# A word made of reserved words should be treated as a name
for word in ('queryType', 'mutation42', 'on_fragment'):
self.assert_output(self.lexer.input(word), [('NAME', word)])
def test_true(self):
self.assert_output(self.lexer.input('true'), [('TRUE', True)])
self.assert_output(self.lexer.input('True'), [('NAME', 'True')])
def test_false(self):
self.assert_output(self.lexer.input('false'), [('FALSE', False)])
self.assert_output(self.lexer.input('False'), [('NAME', 'False')])
def test_null(self):
self.assert_output(self.lexer.input('null'), [('NULL', None)])
self.assert_output(self.lexer.input('Null'), [('NAME', 'Null')])
def test_int(self):
for val in ('0', '-0', '42', '-42'):
self.assert_output(
self.lexer.input(val),
[('INT_VALUE', int(val))],
)
def test_float(self):
for val in ('-0.5e+42', '42.0', '2E64', '2.71e-0002'):
self.assert_output(
self.lexer.input(val),
[('FLOAT_VALUE', Decimal(val))],
)
def test_string(self):
for s in ('""', u'""', '"42"', r'"\t\n\u0042 ^"'):
self.assert_output(
self.lexer.input(s),
[('STRING_VALUE', s.strip('"'))]
)
def test_comment(self):
lexer = self.lexer.input("""
42 # lol this is a number. But this -> 9000 is not.
"" # lol this is a string. But this -> "gav" is not.
# lol the whole line commented
#
""")
self.assert_output(lexer, [('INT_VALUE', 42), ('STRING_VALUE', '')])
def test_illegal_chars(self):
for s in ('"', '^'):
try:
list(self.lexer.input(s))
self.fail('Illegal char exception not raised for %s' % repr(s))
except LexerError as e:
self.assertEqual(1, e.line)
self.assertEqual(1, e.column)
self.assertTrue(
str(e).startswith('Line 1, col 1: Illegal character')
)
self.assertEqual(s, e.value)
def test_positional_info(self):
for i, t in enumerate(self.lexer.input('1\n 3\n 5\n')):
self.assertEqual(i + 1, t.lineno)
self.assertEqual(i * 2 + 1, self.lexer.find_column(t))
|
mit
|
[
504,
6107,
492,
6345,
199,
504,
2882,
492,
7640,
199,
199,
504,
3343,
1710,
14,
11729,
492,
11513,
2940,
5838,
199,
504,
3343,
1710,
14,
3924,
492,
21125,
547,
421,
199,
533,
11513,
2940,
5838,
774,
8,
1746,
304,
272,
10426,
275,
11513,
2940,
5838,
342,
339,
347,
702,
63,
1199,
8,
277,
12,
10426,
12,
1420,
304,
267,
3503,
275,
769,
8,
11729,
9,
267,
822,
63,
6514,
275,
822,
8,
6514,
9,
267,
822,
63,
2062,
275,
822,
8,
2062,
9,
267,
291,
14,
629,
8,
288,
822,
63,
6514,
12,
288,
822,
63,
2062,
12,
288,
283,
30141,
1072,
2582,
450,
83,
1630,
440,
1336,
1420,
2582,
450,
83,
60,
78,
7,
288,
283,
30141,
26,
450,
83,
60,
78,
7,
288,
283,
6964,
26,
450,
83,
7,
450,
334,
552,
63,
6514,
12,
822,
63,
2062,
12,
3503,
12,
1420,
9,
267,
776,
267,
367,
284,
12,
1526,
315,
3874,
8,
6514,
304,
288,
291,
14,
629,
8,
1418,
14,
466,
12,
1420,
59,
73,
1527,
16,
566,
288,
291,
14,
629,
8,
1418,
14,
585,
12,
1420,
59,
73,
1527,
17,
566,
339,
347,
511,
63,
27003,
16530,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
15659,
4274,
34,
3986,
297,
14597,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
14676,
659,
4274,
1649,
4464,
689,
297,
4505,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
14097,
659,
4274,
22169,
63,
44,
297,
8189,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
15938,
659,
4274,
22169,
63,
50,
297,
5320,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
6176,
659,
4274,
3978,
615,
297,
7596,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
26800,
659,
4274,
16352,
51,
297,
26143,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
16591,
659,
4274,
619,
297,
10267,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
11894,
659,
4274,
25950,
63,
44,
297,
6730,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
26987,
4274,
25950,
63,
50,
297,
24710,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
11117,
659,
4274,
29246,
63,
44,
297,
5041,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
93,
659,
4274,
29246,
63,
50,
297,
28544,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
1396,
659,
4274,
51,
4225,
1554,
297,
24352,
2023,
339,
347,
511,
63,
354,
8,
277,
304,
267,
367,
536,
315,
661,
65,
297,
283,
1662,
5894,
63,
2260,
297,
2560,
1484,
44,
7500,
25469,
2513,
16,
735,
288,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
8,
354,
395,
4274,
2339,
297,
536,
3948,
339,
347,
511,
63,
10421,
63,
3148,
8,
277,
304,
267,
4644,
275,
661,
7677,
297,
283,
1131,
297,
283,
11627,
297,
283,
265,
358,
267,
367,
4349,
315,
4644,
26,
288,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
8,
1027,
395,
3842,
1027,
14,
4142,
1062,
4349,
3948,
267,
327,
437,
4349,
6326,
402,
4644,
5932,
1077,
506,
10184,
465,
282,
536,
267,
367,
4349,
315,
661,
1131,
804,
297,
283,
11627,
2260,
297,
283,
265,
63,
7677,
735,
288,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
8,
1027,
395,
4274,
2339,
297,
4349,
3948,
339,
347,
511,
63,
2052,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
2052,
659,
4274,
15064,
297,
715,
3948,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
549,
659,
4274,
2339,
297,
283,
549,
2023,
339,
347,
511,
63,
3910,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
3910,
659,
4274,
19823,
297,
756,
3948,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
797,
659,
4274,
2339,
297,
283,
797,
2023,
339,
347,
511,
63,
2307,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
2307,
659,
4274,
8084,
297,
488,
3948,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
8849,
659,
4274,
2339,
297,
283,
8849,
2023,
339,
347,
511,
63,
442,
8,
277,
304,
267,
367,
1139,
315,
661,
16,
297,
2475,
16,
297,
283,
2260,
297,
2475,
2260,
735,
288,
291,
14,
479,
63,
1199,
8,
355,
291,
14,
11729,
14,
1210,
8,
637,
395,
355,
4274,
2919,
63,
7041,
297,
1109,
8,
637,
25106,
288,
776,
339,
347,
511,
63,
1609,
8,
277,
304,
267,
367,
1139,
315,
12291,
16,
14,
21,
69,
11,
2260,
297,
283,
2260,
14,
16,
297,
283,
18,
37,
772,
297,
283,
18,
14,
3172,
69,
13,
9425,
735,
288,
291,
14,
479,
63,
1199,
8,
355,
291,
14,
11729,
14,
1210,
8,
637,
395,
355,
4274,
11783,
63,
7041,
297,
6345,
8,
637,
25106,
288,
776,
339,
347,
511,
63,
875,
8,
277,
304,
267,
367,
308,
315,
661,
341,
297,
399,
7,
341,
297,
5522,
2260,
6949,
519,
7,
3212,
84,
60,
78,
60,
85,
32728,
7167,
2,
735,
288,
291,
14,
479,
63,
1199,
8,
355,
291,
14,
11729,
14,
1210,
8,
83,
395,
355,
4274,
5353,
63,
7041,
297,
308,
14,
1913,
14088,
27738,
288,
776,
339,
347,
511,
63,
3349,
8,
277,
304,
267,
10426,
275,
291,
14,
11729,
14,
1210,
4852,
288,
5685,
327,
560,
76,
642,
365,
282,
1329,
14,
11017,
642,
1035,
1749,
1493,
365,
440,
14,
288,
3087,
327,
560,
76,
642,
365,
282,
1059,
14,
11017,
642,
1035,
298,
71,
1214,
2,
365,
440,
14,
288,
327,
560,
76,
314,
8852,
1004,
21804,
288,
327,
267,
7857,
267,
291,
14,
479,
63,
1199,
8,
11729,
12,
4274,
2919,
63,
7041,
297,
5685,
395,
661,
5353,
63,
7041,
297,
283,
2023,
339,
347,
511,
63,
23375,
63,
6574,
8
] |
[
6107,
492,
6345,
199,
504,
2882,
492,
7640,
199,
199,
504,
3343,
1710,
14,
11729,
492,
11513,
2940,
5838,
199,
504,
3343,
1710,
14,
3924,
492,
21125,
547,
421,
199,
533,
11513,
2940,
5838,
774,
8,
1746,
304,
272,
10426,
275,
11513,
2940,
5838,
342,
339,
347,
702,
63,
1199,
8,
277,
12,
10426,
12,
1420,
304,
267,
3503,
275,
769,
8,
11729,
9,
267,
822,
63,
6514,
275,
822,
8,
6514,
9,
267,
822,
63,
2062,
275,
822,
8,
2062,
9,
267,
291,
14,
629,
8,
288,
822,
63,
6514,
12,
288,
822,
63,
2062,
12,
288,
283,
30141,
1072,
2582,
450,
83,
1630,
440,
1336,
1420,
2582,
450,
83,
60,
78,
7,
288,
283,
30141,
26,
450,
83,
60,
78,
7,
288,
283,
6964,
26,
450,
83,
7,
450,
334,
552,
63,
6514,
12,
822,
63,
2062,
12,
3503,
12,
1420,
9,
267,
776,
267,
367,
284,
12,
1526,
315,
3874,
8,
6514,
304,
288,
291,
14,
629,
8,
1418,
14,
466,
12,
1420,
59,
73,
1527,
16,
566,
288,
291,
14,
629,
8,
1418,
14,
585,
12,
1420,
59,
73,
1527,
17,
566,
339,
347,
511,
63,
27003,
16530,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
15659,
4274,
34,
3986,
297,
14597,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
14676,
659,
4274,
1649,
4464,
689,
297,
4505,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
14097,
659,
4274,
22169,
63,
44,
297,
8189,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
15938,
659,
4274,
22169,
63,
50,
297,
5320,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
6176,
659,
4274,
3978,
615,
297,
7596,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
26800,
659,
4274,
16352,
51,
297,
26143,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
16591,
659,
4274,
619,
297,
10267,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
11894,
659,
4274,
25950,
63,
44,
297,
6730,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
26987,
4274,
25950,
63,
50,
297,
24710,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
11117,
659,
4274,
29246,
63,
44,
297,
5041,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
93,
659,
4274,
29246,
63,
50,
297,
28544,
2023,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
1396,
659,
4274,
51,
4225,
1554,
297,
24352,
2023,
339,
347,
511,
63,
354,
8,
277,
304,
267,
367,
536,
315,
661,
65,
297,
283,
1662,
5894,
63,
2260,
297,
2560,
1484,
44,
7500,
25469,
2513,
16,
735,
288,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
8,
354,
395,
4274,
2339,
297,
536,
3948,
339,
347,
511,
63,
10421,
63,
3148,
8,
277,
304,
267,
4644,
275,
661,
7677,
297,
283,
1131,
297,
283,
11627,
297,
283,
265,
358,
267,
367,
4349,
315,
4644,
26,
288,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
8,
1027,
395,
3842,
1027,
14,
4142,
1062,
4349,
3948,
267,
327,
437,
4349,
6326,
402,
4644,
5932,
1077,
506,
10184,
465,
282,
536,
267,
367,
4349,
315,
661,
1131,
804,
297,
283,
11627,
2260,
297,
283,
265,
63,
7677,
735,
288,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
8,
1027,
395,
4274,
2339,
297,
4349,
3948,
339,
347,
511,
63,
2052,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
2052,
659,
4274,
15064,
297,
715,
3948,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
549,
659,
4274,
2339,
297,
283,
549,
2023,
339,
347,
511,
63,
3910,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
3910,
659,
4274,
19823,
297,
756,
3948,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
797,
659,
4274,
2339,
297,
283,
797,
2023,
339,
347,
511,
63,
2307,
8,
277,
304,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
2307,
659,
4274,
8084,
297,
488,
3948,
267,
291,
14,
479,
63,
1199,
8,
277,
14,
11729,
14,
1210,
360,
8849,
659,
4274,
2339,
297,
283,
8849,
2023,
339,
347,
511,
63,
442,
8,
277,
304,
267,
367,
1139,
315,
661,
16,
297,
2475,
16,
297,
283,
2260,
297,
2475,
2260,
735,
288,
291,
14,
479,
63,
1199,
8,
355,
291,
14,
11729,
14,
1210,
8,
637,
395,
355,
4274,
2919,
63,
7041,
297,
1109,
8,
637,
25106,
288,
776,
339,
347,
511,
63,
1609,
8,
277,
304,
267,
367,
1139,
315,
12291,
16,
14,
21,
69,
11,
2260,
297,
283,
2260,
14,
16,
297,
283,
18,
37,
772,
297,
283,
18,
14,
3172,
69,
13,
9425,
735,
288,
291,
14,
479,
63,
1199,
8,
355,
291,
14,
11729,
14,
1210,
8,
637,
395,
355,
4274,
11783,
63,
7041,
297,
6345,
8,
637,
25106,
288,
776,
339,
347,
511,
63,
875,
8,
277,
304,
267,
367,
308,
315,
661,
341,
297,
399,
7,
341,
297,
5522,
2260,
6949,
519,
7,
3212,
84,
60,
78,
60,
85,
32728,
7167,
2,
735,
288,
291,
14,
479,
63,
1199,
8,
355,
291,
14,
11729,
14,
1210,
8,
83,
395,
355,
4274,
5353,
63,
7041,
297,
308,
14,
1913,
14088,
27738,
288,
776,
339,
347,
511,
63,
3349,
8,
277,
304,
267,
10426,
275,
291,
14,
11729,
14,
1210,
4852,
288,
5685,
327,
560,
76,
642,
365,
282,
1329,
14,
11017,
642,
1035,
1749,
1493,
365,
440,
14,
288,
3087,
327,
560,
76,
642,
365,
282,
1059,
14,
11017,
642,
1035,
298,
71,
1214,
2,
365,
440,
14,
288,
327,
560,
76,
314,
8852,
1004,
21804,
288,
327,
267,
7857,
267,
291,
14,
479,
63,
1199,
8,
11729,
12,
4274,
2919,
63,
7041,
297,
5685,
395,
661,
5353,
63,
7041,
297,
283,
2023,
339,
347,
511,
63,
23375,
63,
6574,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Generated from FHIR 1.0.2.7202 on 2016-06-23.
# 2016, SMART Health IT.
import io
import json
import os
import unittest
from . import familymemberhistory
from .fhirdate import FHIRDate
class FamilyMemberHistoryTests(unittest.TestCase):
def instantiate_from(self, filename):
datadir = os.environ.get('FHIR_UNITTEST_DATADIR') or ''
with io.open(os.path.join(datadir, filename), 'r', encoding='utf-8') as handle:
js = json.load(handle)
self.assertEqual("FamilyMemberHistory", js["resourceType"])
return familymemberhistory.FamilyMemberHistory(js)
def testFamilyMemberHistory1(self):
inst = self.instantiate_from("familymemberhistory-example-mother.json")
self.assertIsNotNone(inst, "Must have instantiated a FamilyMemberHistory instance")
self.implFamilyMemberHistory1(inst)
js = inst.as_json()
self.assertEqual("FamilyMemberHistory", js["resourceType"])
inst2 = familymemberhistory.FamilyMemberHistory(js)
self.implFamilyMemberHistory1(inst2)
def implFamilyMemberHistory1(self, inst):
self.assertEqual(inst.condition[0].code.coding[0].code, "371041009")
self.assertEqual(inst.condition[0].code.coding[0].display, "Embolic Stroke")
self.assertEqual(inst.condition[0].code.coding[0].system, "http://snomed.info/sct")
self.assertEqual(inst.condition[0].code.text, "Stroke")
self.assertEqual(inst.condition[0].onsetQuantity.system, "http://unitsofmeasure.org")
self.assertEqual(inst.condition[0].onsetQuantity.unit, "a")
self.assertEqual(inst.condition[0].onsetQuantity.value, 56)
self.assertEqual(inst.id, "mother")
self.assertEqual(inst.relationship.coding[0].code, "mother")
self.assertEqual(inst.relationship.coding[0].system, "http://hl7.org/fhir/familial-relationship")
self.assertEqual(inst.status, "completed")
self.assertEqual(inst.text.div, "<div>Mother died of a stroke aged 56</div>")
self.assertEqual(inst.text.status, "generated")
def testFamilyMemberHistory2(self):
inst = self.instantiate_from("familymemberhistory-example.json")
self.assertIsNotNone(inst, "Must have instantiated a FamilyMemberHistory instance")
self.implFamilyMemberHistory2(inst)
js = inst.as_json()
self.assertEqual("FamilyMemberHistory", js["resourceType"])
inst2 = familymemberhistory.FamilyMemberHistory(js)
self.implFamilyMemberHistory2(inst2)
def implFamilyMemberHistory2(self, inst):
self.assertEqual(inst.condition[0].code.coding[0].code, "315619001")
self.assertEqual(inst.condition[0].code.coding[0].display, "Myocardial Infarction")
self.assertEqual(inst.condition[0].code.coding[0].system, "http://snomed.info/sct")
self.assertEqual(inst.condition[0].code.text, "Heart Attack")
self.assertEqual(inst.condition[0].note.text, "Was fishing at the time. At least he went doing someting he loved.")
self.assertEqual(inst.condition[0].onsetQuantity.system, "http://unitsofmeasure.org")
self.assertEqual(inst.condition[0].onsetQuantity.unit, "a")
self.assertEqual(inst.condition[0].onsetQuantity.value, 74)
self.assertEqual(inst.date.date, FHIRDate("2011-03-18").date)
self.assertEqual(inst.date.as_json(), "2011-03-18")
self.assertEqual(inst.id, "father")
self.assertEqual(inst.relationship.coding[0].code, "father")
self.assertEqual(inst.relationship.coding[0].system, "http://hl7.org/fhir/familial-relationship")
self.assertEqual(inst.status, "completed")
self.assertEqual(inst.text.div, "<div>Father died of a heart attack aged 74</div>")
self.assertEqual(inst.text.status, "generated")
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
17065,
687,
481,
40,
3927,
413,
14,
16,
14,
18,
14,
2819,
996,
641,
7800,
13,
1690,
13,
1789,
14,
199,
3,
221,
7800,
12,
2389,
2294,
5311,
6130,
473,
52,
14,
421,
199,
646,
5890,
199,
646,
2022,
199,
646,
747,
199,
646,
2882,
199,
199,
504,
1275,
492,
9614,
1114,
5570,
199,
504,
1275,
12853,
723,
602,
492,
481,
40,
3927,
2506,
421,
199,
533,
481,
4632,
7021,
12114,
2925,
8,
2796,
14,
1746,
304,
272,
347,
17321,
63,
504,
8,
277,
12,
1788,
304,
267,
666,
694,
275,
747,
14,
2314,
14,
362,
360,
32259,
3927,
63,
15505,
2864,
63,
6521,
1554,
3927,
358,
503,
2125,
267,
543,
5890,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
18259,
12,
1788,
395,
283,
82,
297,
2644,
534,
1624,
13,
24,
358,
465,
2429,
26,
288,
8586,
275,
2022,
14,
912,
8,
2479,
9,
288,
291,
14,
629,
480,
16345,
7021,
12114,
401,
8586,
905,
1927,
804,
3135,
267,
372,
9614,
1114,
5570,
14,
16345,
7021,
12114,
8,
3596,
9,
2286,
347,
511,
16345,
7021,
12114,
17,
8,
277,
304,
267,
2727,
275,
291,
14,
3615,
18973,
63,
504,
480,
6606,
1114,
5570,
13,
2694,
13,
573,
728,
14,
1001,
531,
267,
291,
14,
10389,
8,
3615,
12,
298,
13757,
1172,
17544,
282,
481,
4632,
7021,
12114,
1256,
531,
267,
291,
14,
5472,
16345,
7021,
12114,
17,
8,
3615,
9,
2728,
8586,
275,
2727,
14,
305,
63,
1001,
342,
267,
291,
14,
629,
480,
16345,
7021,
12114,
401,
8586,
905,
1927,
804,
3135,
267,
2727,
18,
275,
9614,
1114,
5570,
14,
16345,
7021,
12114,
8,
3596,
9,
267,
291,
14,
5472,
16345,
7021,
12114,
17,
8,
3615,
18,
9,
2286,
347,
11512,
16345,
7021,
12114,
17,
8,
277,
12,
2727,
304,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
600,
12,
298,
1401,
6785,
1960,
25,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2918,
12,
298,
37,
77,
9670,
428,
1374,
415,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
83,
889,
3594,
14,
815,
15,
83,
319,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
505,
12,
298,
32492,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
2253,
12,
298,
1014,
921,
3248,
1152,
70,
9580,
14,
1308,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
3248,
12,
298,
65,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
585,
12,
12001,
9,
267,
291,
14,
629,
8,
3615,
14,
344,
12,
298,
573,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
600,
12,
298,
573,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
15544,
23,
14,
1308,
15,
12853,
723,
15,
18493,
1638,
279,
13,
11704,
531,
267,
291,
14,
629,
8,
3615,
14,
1205,
12,
298,
12634,
531,
267,
291,
14,
629,
8,
3615,
14,
505,
14,
3015,
12,
3886,
3015,
30,
45,
1848,
487,
379,
402,
282,
22824,
282,
3046,
12001,
1108,
3015,
9579,
267,
291,
14,
629,
8,
3615,
14,
505,
14,
1205,
12,
298,
10176,
531,
2286,
347,
511,
16345,
7021,
12114,
18,
8,
277,
304,
267,
2727,
275,
291,
14,
3615,
18973,
63,
504,
480,
6606,
1114,
5570,
13,
2694,
14,
1001,
531,
267,
291,
14,
10389,
8,
3615,
12,
298,
13757,
1172,
17544,
282,
481,
4632,
7021,
12114,
1256,
531,
267,
291,
14,
5472,
16345,
7021,
12114,
18,
8,
3615,
9,
2728,
8586,
275,
2727,
14,
305,
63,
1001,
342,
267,
291,
14,
629,
480,
16345,
7021,
12114,
401,
8586,
905,
1927,
804,
3135,
267,
2727,
18,
275,
9614,
1114,
5570,
14,
16345,
7021,
12114,
8,
3596,
9,
267,
291,
14,
5472,
16345,
7021,
12114,
18,
8,
3615,
18,
9,
2286,
347,
11512,
16345,
7021,
12114,
18,
8,
277,
12,
2727,
304,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
600,
12,
298,
9927,
30270,
4587,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2918,
12,
298,
5713,
679,
18980,
279,
1010,
15315,
414,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
83,
889,
3594,
14,
815,
15,
83,
319,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
505,
12,
298,
1966,
580,
2854,
13058,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
4610,
14,
505,
12,
298,
55,
305,
289,
2453,
316,
737,
314,
900,
14,
2854,
5210,
946,
22396,
9689,
2005,
1337,
946,
560,
1354,
2685,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
2253,
12,
298,
1014,
921,
3248,
1152,
70,
9580,
14,
1308,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
3248,
12,
298,
65,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
585,
12,
9720,
9,
267,
291,
14,
629,
8,
3615,
14,
602,
14,
602,
12,
481,
40,
3927,
2506,
480,
8128,
13,
1644,
13,
1085,
3471,
602,
9,
267,
291,
14,
629,
8,
3615,
14,
602,
14,
305,
63,
1001,
1062,
298,
8128,
13,
1644,
13,
1085,
531,
267,
291,
14,
629,
8,
3615,
14,
344,
12,
298,
667,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
600,
12,
298,
667,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
15544,
23,
14,
1308,
15,
12853,
723,
15
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
17065,
687,
481,
40,
3927,
413,
14,
16,
14,
18,
14,
2819,
996,
641,
7800,
13,
1690,
13,
1789,
14,
199,
3,
221,
7800,
12,
2389,
2294,
5311,
6130,
473,
52,
14,
421,
199,
646,
5890,
199,
646,
2022,
199,
646,
747,
199,
646,
2882,
199,
199,
504,
1275,
492,
9614,
1114,
5570,
199,
504,
1275,
12853,
723,
602,
492,
481,
40,
3927,
2506,
421,
199,
533,
481,
4632,
7021,
12114,
2925,
8,
2796,
14,
1746,
304,
272,
347,
17321,
63,
504,
8,
277,
12,
1788,
304,
267,
666,
694,
275,
747,
14,
2314,
14,
362,
360,
32259,
3927,
63,
15505,
2864,
63,
6521,
1554,
3927,
358,
503,
2125,
267,
543,
5890,
14,
1490,
8,
736,
14,
515,
14,
904,
8,
18259,
12,
1788,
395,
283,
82,
297,
2644,
534,
1624,
13,
24,
358,
465,
2429,
26,
288,
8586,
275,
2022,
14,
912,
8,
2479,
9,
288,
291,
14,
629,
480,
16345,
7021,
12114,
401,
8586,
905,
1927,
804,
3135,
267,
372,
9614,
1114,
5570,
14,
16345,
7021,
12114,
8,
3596,
9,
2286,
347,
511,
16345,
7021,
12114,
17,
8,
277,
304,
267,
2727,
275,
291,
14,
3615,
18973,
63,
504,
480,
6606,
1114,
5570,
13,
2694,
13,
573,
728,
14,
1001,
531,
267,
291,
14,
10389,
8,
3615,
12,
298,
13757,
1172,
17544,
282,
481,
4632,
7021,
12114,
1256,
531,
267,
291,
14,
5472,
16345,
7021,
12114,
17,
8,
3615,
9,
2728,
8586,
275,
2727,
14,
305,
63,
1001,
342,
267,
291,
14,
629,
480,
16345,
7021,
12114,
401,
8586,
905,
1927,
804,
3135,
267,
2727,
18,
275,
9614,
1114,
5570,
14,
16345,
7021,
12114,
8,
3596,
9,
267,
291,
14,
5472,
16345,
7021,
12114,
17,
8,
3615,
18,
9,
2286,
347,
11512,
16345,
7021,
12114,
17,
8,
277,
12,
2727,
304,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
600,
12,
298,
1401,
6785,
1960,
25,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2918,
12,
298,
37,
77,
9670,
428,
1374,
415,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
83,
889,
3594,
14,
815,
15,
83,
319,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
505,
12,
298,
32492,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
2253,
12,
298,
1014,
921,
3248,
1152,
70,
9580,
14,
1308,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
3248,
12,
298,
65,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
585,
12,
12001,
9,
267,
291,
14,
629,
8,
3615,
14,
344,
12,
298,
573,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
600,
12,
298,
573,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
15544,
23,
14,
1308,
15,
12853,
723,
15,
18493,
1638,
279,
13,
11704,
531,
267,
291,
14,
629,
8,
3615,
14,
1205,
12,
298,
12634,
531,
267,
291,
14,
629,
8,
3615,
14,
505,
14,
3015,
12,
3886,
3015,
30,
45,
1848,
487,
379,
402,
282,
22824,
282,
3046,
12001,
1108,
3015,
9579,
267,
291,
14,
629,
8,
3615,
14,
505,
14,
1205,
12,
298,
10176,
531,
2286,
347,
511,
16345,
7021,
12114,
18,
8,
277,
304,
267,
2727,
275,
291,
14,
3615,
18973,
63,
504,
480,
6606,
1114,
5570,
13,
2694,
14,
1001,
531,
267,
291,
14,
10389,
8,
3615,
12,
298,
13757,
1172,
17544,
282,
481,
4632,
7021,
12114,
1256,
531,
267,
291,
14,
5472,
16345,
7021,
12114,
18,
8,
3615,
9,
2728,
8586,
275,
2727,
14,
305,
63,
1001,
342,
267,
291,
14,
629,
480,
16345,
7021,
12114,
401,
8586,
905,
1927,
804,
3135,
267,
2727,
18,
275,
9614,
1114,
5570,
14,
16345,
7021,
12114,
8,
3596,
9,
267,
291,
14,
5472,
16345,
7021,
12114,
18,
8,
3615,
18,
9,
2286,
347,
11512,
16345,
7021,
12114,
18,
8,
277,
12,
2727,
304,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
600,
12,
298,
9927,
30270,
4587,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2918,
12,
298,
5713,
679,
18980,
279,
1010,
15315,
414,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
83,
889,
3594,
14,
815,
15,
83,
319,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
600,
14,
505,
12,
298,
1966,
580,
2854,
13058,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
4610,
14,
505,
12,
298,
55,
305,
289,
2453,
316,
737,
314,
900,
14,
2854,
5210,
946,
22396,
9689,
2005,
1337,
946,
560,
1354,
2685,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
2253,
12,
298,
1014,
921,
3248,
1152,
70,
9580,
14,
1308,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
3248,
12,
298,
65,
531,
267,
291,
14,
629,
8,
3615,
14,
5394,
59,
16,
1055,
265,
409,
19703,
14,
585,
12,
9720,
9,
267,
291,
14,
629,
8,
3615,
14,
602,
14,
602,
12,
481,
40,
3927,
2506,
480,
8128,
13,
1644,
13,
1085,
3471,
602,
9,
267,
291,
14,
629,
8,
3615,
14,
602,
14,
305,
63,
1001,
1062,
298,
8128,
13,
1644,
13,
1085,
531,
267,
291,
14,
629,
8,
3615,
14,
344,
12,
298,
667,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
600,
12,
298,
667,
728,
531,
267,
291,
14,
629,
8,
3615,
14,
11704,
14,
1523,
59,
16,
1055,
2253,
12,
298,
1014,
921,
15544,
23,
14,
1308,
15,
12853,
723,
15,
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,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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
] |
gregmuellegger/django-rest-framework
|
rest_framework/routers.py
|
14
|
11625
|
"""
Routers provide a convenient and consistent way of automatically
determining the URL conf for your API.
They are used by simply instantiating a Router class, and then registering
all the required ViewSets with that router.
For example, you might have a `urls.py` that looks something like this:
router = routers.DefaultRouter()
router.register('users', UserViewSet, 'user')
router.register('accounts', AccountViewSet, 'account')
urlpatterns = router.urls
"""
from __future__ import unicode_literals
import itertools
from collections import OrderedDict, namedtuple
from django.conf.urls import url
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import NoReverseMatch
from rest_framework import views
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns
Route = namedtuple('Route', ['url', 'mapping', 'name', 'initkwargs'])
DynamicDetailRoute = namedtuple('DynamicDetailRoute', ['url', 'name', 'initkwargs'])
DynamicListRoute = namedtuple('DynamicListRoute', ['url', 'name', 'initkwargs'])
def replace_methodname(format_string, methodname):
"""
Partially format a format_string, swapping out any
'{methodname}' or '{methodnamehyphen}' components.
"""
methodnamehyphen = methodname.replace('_', '-')
ret = format_string
ret = ret.replace('{methodname}', methodname)
ret = ret.replace('{methodnamehyphen}', methodnamehyphen)
return ret
def flatten(list_of_lists):
"""
Takes an iterable of iterables, returns a single iterable containing all items
"""
return itertools.chain(*list_of_lists)
class BaseRouter(object):
def __init__(self):
self.registry = []
def register(self, prefix, viewset, base_name=None):
if base_name is None:
base_name = self.get_default_base_name(viewset)
self.registry.append((prefix, viewset, base_name))
def get_default_base_name(self, viewset):
"""
If `base_name` is not specified, attempt to automatically determine
it from the viewset.
"""
raise NotImplementedError('get_default_base_name must be overridden')
def get_urls(self):
"""
Return a list of URL patterns, given the registered viewsets.
"""
raise NotImplementedError('get_urls must be overridden')
@property
def urls(self):
if not hasattr(self, '_urls'):
self._urls = self.get_urls()
return self._urls
class SimpleRouter(BaseRouter):
routes = [
# List route.
Route(
url=r'^{prefix}{trailing_slash}$',
mapping={
'get': 'list',
'post': 'create'
},
name='{basename}-list',
initkwargs={'suffix': 'List'}
),
# Dynamically generated list routes.
# Generated using @list_route decorator
# on methods of the viewset.
DynamicListRoute(
url=r'^{prefix}/{methodname}{trailing_slash}$',
name='{basename}-{methodnamehyphen}',
initkwargs={}
),
# Detail route.
Route(
url=r'^{prefix}/{lookup}{trailing_slash}$',
mapping={
'get': 'retrieve',
'put': 'update',
'patch': 'partial_update',
'delete': 'destroy'
},
name='{basename}-detail',
initkwargs={'suffix': 'Instance'}
),
# Dynamically generated detail routes.
# Generated using @detail_route decorator on methods of the viewset.
DynamicDetailRoute(
url=r'^{prefix}/{lookup}/{methodname}{trailing_slash}$',
name='{basename}-{methodnamehyphen}',
initkwargs={}
),
]
def __init__(self, trailing_slash=True):
self.trailing_slash = trailing_slash and '/' or ''
super(SimpleRouter, self).__init__()
def get_default_base_name(self, viewset):
"""
If `base_name` is not specified, attempt to automatically determine
it from the viewset.
"""
queryset = getattr(viewset, 'queryset', None)
assert queryset is not None, '`base_name` argument not specified, and could ' \
'not automatically determine the name from the viewset, as ' \
'it does not have a `.queryset` attribute.'
return queryset.model._meta.object_name.lower()
def get_routes(self, viewset):
"""
Augment `self.routes` with any dynamically generated routes.
Returns a list of the Route namedtuple.
"""
known_actions = flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)])
# Determine any `@detail_route` or `@list_route` decorated methods on the viewset
detail_routes = []
list_routes = []
for methodname in dir(viewset):
attr = getattr(viewset, methodname)
httpmethods = getattr(attr, 'bind_to_methods', None)
detail = getattr(attr, 'detail', True)
if httpmethods:
if methodname in known_actions:
raise ImproperlyConfigured('Cannot use @detail_route or @list_route '
'decorators on method "%s" '
'as it is an existing route' % methodname)
httpmethods = [method.lower() for method in httpmethods]
if detail:
detail_routes.append((httpmethods, methodname))
else:
list_routes.append((httpmethods, methodname))
def _get_dynamic_routes(route, dynamic_routes):
ret = []
for httpmethods, methodname in dynamic_routes:
method_kwargs = getattr(viewset, methodname).kwargs
initkwargs = route.initkwargs.copy()
initkwargs.update(method_kwargs)
url_path = initkwargs.pop("url_path", None) or methodname
ret.append(Route(
url=replace_methodname(route.url, url_path),
mapping={httpmethod: methodname for httpmethod in httpmethods},
name=replace_methodname(route.name, url_path),
initkwargs=initkwargs,
))
return ret
ret = []
for route in self.routes:
if isinstance(route, DynamicDetailRoute):
# Dynamic detail routes (@detail_route decorator)
ret += _get_dynamic_routes(route, detail_routes)
elif isinstance(route, DynamicListRoute):
# Dynamic list routes (@list_route decorator)
ret += _get_dynamic_routes(route, list_routes)
else:
# Standard route
ret.append(route)
return ret
def get_method_map(self, viewset, method_map):
"""
Given a viewset, and a mapping of http methods to actions,
return a new mapping which only includes any mappings that
are actually implemented by the viewset.
"""
bound_methods = {}
for method, action in method_map.items():
if hasattr(viewset, action):
bound_methods[method] = action
return bound_methods
def get_lookup_regex(self, viewset, lookup_prefix=''):
"""
Given a viewset, return the portion of URL regex that is used
to match against a single instance.
Note that lookup_prefix is not used directly inside REST rest_framework
itself, but is required in order to nicely support nested router
implementations, such as drf-nested-routers.
https://github.com/alanjds/drf-nested-routers
"""
base_regex = '(?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})'
# Use `pk` as default field, unset set. Default regex should not
# consume `.json` style suffixes and should break at '/' boundaries.
lookup_field = getattr(viewset, 'lookup_field', 'pk')
lookup_url_kwarg = getattr(viewset, 'lookup_url_kwarg', None) or lookup_field
lookup_value = getattr(viewset, 'lookup_value_regex', '[^/.]+')
return base_regex.format(
lookup_prefix=lookup_prefix,
lookup_url_kwarg=lookup_url_kwarg,
lookup_value=lookup_value
)
def get_urls(self):
"""
Use the registered viewsets to generate a list of URL patterns.
"""
ret = []
for prefix, viewset, basename in self.registry:
lookup = self.get_lookup_regex(viewset)
routes = self.get_routes(viewset)
for route in routes:
# Only actions which actually exist on the viewset will be bound
mapping = self.get_method_map(viewset, route.mapping)
if not mapping:
continue
# Build the url pattern
regex = route.url.format(
prefix=prefix,
lookup=lookup,
trailing_slash=self.trailing_slash
)
view = viewset.as_view(mapping, **route.initkwargs)
name = route.name.format(basename=basename)
ret.append(url(regex, view, name=name))
return ret
class DefaultRouter(SimpleRouter):
"""
The default router extends the SimpleRouter, but also adds in a default
API root view, and adds format suffix patterns to the URLs.
"""
include_root_view = True
include_format_suffixes = True
root_view_name = 'api-root'
def get_api_root_view(self):
"""
Return a view to use as the API root.
"""
api_root_dict = OrderedDict()
list_name = self.routes[0].name
for prefix, viewset, basename in self.registry:
api_root_dict[prefix] = list_name.format(basename=basename)
class APIRoot(views.APIView):
_ignore_model_permissions = True
def get(self, request, *args, **kwargs):
ret = OrderedDict()
namespace = request.resolver_match.namespace
for key, url_name in api_root_dict.items():
if namespace:
url_name = namespace + ':' + url_name
try:
ret[key] = reverse(
url_name,
args=args,
kwargs=kwargs,
request=request,
format=kwargs.get('format', None)
)
except NoReverseMatch:
# Don't bail out if eg. no list routes exist, only detail routes.
continue
return Response(ret)
return APIRoot.as_view()
def get_urls(self):
"""
Generate the list of URL patterns, including a default root view
for the API, and appending `.json` style format suffixes.
"""
urls = []
if self.include_root_view:
root_url = url(r'^$', self.get_api_root_view(), name=self.root_view_name)
urls.append(root_url)
default_urls = super(DefaultRouter, self).get_urls()
urls.extend(default_urls)
if self.include_format_suffixes:
urls = format_suffix_patterns(urls)
return urls
|
bsd-2-clause
|
[
624,
199,
5407,
878,
5647,
282,
22700,
436,
12137,
4340,
402,
5847,
199,
17061,
316,
314,
2851,
3743,
367,
2195,
3261,
14,
199,
199,
1918,
89,
787,
1202,
701,
9329,
9034,
1958,
282,
22708,
1021,
12,
436,
2066,
2274,
316,
199,
452,
314,
1415,
10935,
9899,
543,
626,
6197,
14,
199,
199,
1858,
2893,
12,
1265,
5594,
1172,
282,
658,
3603,
14,
647,
64,
626,
10734,
6020,
2839,
642,
26,
339,
6197,
275,
24464,
14,
2698,
11691,
342,
272,
6197,
14,
2683,
360,
3707,
297,
2876,
21902,
12,
283,
751,
358,
272,
6197,
14,
2683,
360,
8370,
297,
9973,
21902,
12,
283,
2048,
358,
339,
26177,
275,
6197,
14,
3603,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
7975,
199,
504,
5055,
492,
8773,
12,
12863,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
16522,
492,
32036,
199,
199,
504,
4618,
63,
4857,
492,
6858,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
504,
4618,
63,
4857,
14,
4471,
492,
3837,
199,
504,
4618,
63,
4857,
14,
20050,
492,
1475,
63,
4511,
63,
7435,
199,
199,
7161,
275,
12863,
360,
7161,
297,
788,
633,
297,
283,
4745,
297,
283,
354,
297,
283,
826,
958,
1105,
199,
14451,
8064,
7161,
275,
12863,
360,
14451,
8064,
7161,
297,
788,
633,
297,
283,
354,
297,
283,
826,
958,
1105,
199,
14451,
1296,
7161,
275,
12863,
360,
14451,
1296,
7161,
297,
788,
633,
297,
283,
354,
297,
283,
826,
958,
1105,
421,
199,
318,
3350,
63,
765,
354,
8,
908,
63,
875,
12,
28009,
304,
272,
408,
272,
2235,
9406,
1475,
282,
1475,
63,
875,
12,
5584,
3262,
734,
1263,
272,
5041,
765,
354,
6834,
503,
5041,
765,
354,
30215,
6834,
7323,
14,
272,
408,
272,
28009,
30215,
275,
28009,
14,
1814,
20928,
26942,
272,
2203,
275,
1475,
63,
875,
272,
2203,
275,
2203,
14,
1814,
11117,
765,
354,
7293,
28009,
9,
272,
2203,
275,
2203,
14,
1814,
11117,
765,
354,
30215,
7293,
28009,
30215,
9,
272,
372,
2203,
421,
199,
318,
9378,
8,
513,
63,
1618,
63,
6717,
304,
272,
408,
272,
17415,
376,
6076,
402,
6076,
83,
12,
2529,
282,
2849,
6076,
3035,
1006,
2974,
272,
408,
272,
372,
7975,
14,
4429,
2031,
513,
63,
1618,
63,
6717,
9,
421,
199,
533,
3523,
11691,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
5189,
275,
942,
339,
347,
2274,
8,
277,
12,
2403,
12,
2455,
409,
12,
1300,
63,
354,
29,
403,
304,
267,
340,
1300,
63,
354,
365,
488,
26,
288,
1300,
63,
354,
275,
291,
14,
362,
63,
885,
63,
1095,
63,
354,
8,
1345,
409,
9,
267,
291,
14,
5189,
14,
740,
1332,
1861,
12,
2455,
409,
12,
1300,
63,
354,
430,
339,
347,
664,
63,
885,
63,
1095,
63,
354,
8,
277,
12,
2455,
409,
304,
267,
408,
267,
982,
658,
1095,
63,
354,
64,
365,
440,
2013,
12,
7427,
370,
5847,
6705,
267,
652,
687,
314,
2455,
409,
14,
267,
408,
267,
746,
4279,
360,
362,
63,
885,
63,
1095,
63,
354,
1471,
506,
10087,
358,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
408,
267,
1432,
282,
769,
402,
2851,
7970,
12,
1627,
314,
7264,
2455,
2193,
14,
267,
408,
267,
746,
4279,
360,
362,
63,
3603,
1471,
506,
10087,
358,
339,
768,
1829,
272,
347,
8187,
8,
277,
304,
267,
340,
440,
2688,
8,
277,
12,
2513,
3603,
735,
288,
291,
423,
3603,
275,
291,
14,
362,
63,
3603,
342,
267,
372,
291,
423,
3603,
421,
199,
533,
5870,
11691,
8,
1563,
11691,
304,
272,
15777,
275,
359,
267,
327,
3820,
7475,
14,
267,
24244,
8,
288,
1166,
29,
82,
4289,
91,
1861,
8847,
15910,
63,
7001,
19204,
288,
4412,
3126,
355,
283,
362,
356,
283,
513,
297,
355,
283,
1932,
356,
283,
981,
7,
288,
1660,
288,
536,
32134,
4846,
17063,
513,
297,
288,
4205,
958,
3713,
4511,
356,
283,
1296,
936,
267,
2318,
267,
327,
21907,
1183,
4046,
769,
15777,
14,
267,
327,
17065,
1808,
768,
513,
63,
4449,
7531,
267,
327,
641,
3102,
402,
314,
2455,
409,
14,
267,
21907,
1296,
7161,
8,
288,
1166,
29,
82,
4289,
91,
1861,
16152,
765,
354,
8847,
15910,
63,
7001,
19204,
288,
536,
32134,
4846,
30289,
765,
354,
30215,
7293,
288,
4205,
958,
7622,
267,
2318,
267,
327,
13302,
7475,
14,
267,
24244,
8,
288,
1166,
29,
82,
4289,
91,
1861,
16152,
3892,
8847,
15910,
63,
7001,
19204,
288,
4412,
3126,
355,
283,
362,
356,
283,
14270,
297,
355,
283,
524,
356,
283,
873,
297,
355,
283,
2068,
356,
283,
6672,
63,
873,
297,
355,
283,
1807,
356,
283,
7237,
7,
288,
1660,
288,
536,
32134,
4846,
17063,
5506,
297,
288,
4205,
958,
3713,
4511,
356,
283,
3244,
936,
267,
2318,
267,
327,
21907,
1183,
4046,
10093,
15777,
14,
267,
327,
17065,
1808,
768,
5506,
63,
4449,
7531,
641,
3102,
402,
314,
2455,
409,
14,
267,
21907,
8064,
7161,
8,
288,
1166,
29,
82,
4289,
91,
1861,
16152,
3892,
16152,
765,
354,
8847,
15910,
63,
7001,
19204,
288,
536,
32134,
4846,
30289,
765,
354,
30215,
7293,
288,
4205,
958,
7622,
267,
2318,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
8520,
63,
7001,
29,
549,
304,
267,
291,
14,
15910,
63,
7001,
275,
8520,
63,
7001,
436,
7324,
503,
2125,
267,
1613,
8,
3184,
11691,
12,
291,
2843,
826,
4533,
339,
347,
664,
63,
885,
63,
1095,
63,
354,
8,
277,
12,
2455,
409,
304,
267,
408,
267,
982,
658,
1095,
63,
354,
64,
365,
440,
2013,
12,
7427,
370,
5847,
6705,
267,
652,
687,
314,
2455,
409,
14,
267,
408,
267,
7594,
275,
2519,
8,
1345,
409,
12,
283,
7924,
297,
488,
9,
398,
702,
7594,
365,
440,
488,
12,
26144,
1095,
63,
354,
64,
1423,
440,
2013,
12,
436,
4293,
283,
971,
288,
283,
1397,
5847,
6705,
314,
536,
687,
314,
2455,
409,
12,
465,
283,
971,
288,
283,
390,
1630,
440,
1172,
282,
19853,
7924,
64,
2225,
3530,
398,
372,
7594,
14,
1238,
423,
2024,
14,
785,
63,
354,
14,
2325,
342,
339,
347,
664
] |
[
199,
5407,
878,
5647,
282,
22700,
436,
12137,
4340,
402,
5847,
199,
17061,
316,
314,
2851,
3743,
367,
2195,
3261,
14,
199,
199,
1918,
89,
787,
1202,
701,
9329,
9034,
1958,
282,
22708,
1021,
12,
436,
2066,
2274,
316,
199,
452,
314,
1415,
10935,
9899,
543,
626,
6197,
14,
199,
199,
1858,
2893,
12,
1265,
5594,
1172,
282,
658,
3603,
14,
647,
64,
626,
10734,
6020,
2839,
642,
26,
339,
6197,
275,
24464,
14,
2698,
11691,
342,
272,
6197,
14,
2683,
360,
3707,
297,
2876,
21902,
12,
283,
751,
358,
272,
6197,
14,
2683,
360,
8370,
297,
9973,
21902,
12,
283,
2048,
358,
339,
26177,
275,
6197,
14,
3603,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
7975,
199,
504,
5055,
492,
8773,
12,
12863,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
16522,
492,
32036,
199,
199,
504,
4618,
63,
4857,
492,
6858,
199,
504,
4618,
63,
4857,
14,
1310,
492,
7232,
199,
504,
4618,
63,
4857,
14,
4471,
492,
3837,
199,
504,
4618,
63,
4857,
14,
20050,
492,
1475,
63,
4511,
63,
7435,
199,
199,
7161,
275,
12863,
360,
7161,
297,
788,
633,
297,
283,
4745,
297,
283,
354,
297,
283,
826,
958,
1105,
199,
14451,
8064,
7161,
275,
12863,
360,
14451,
8064,
7161,
297,
788,
633,
297,
283,
354,
297,
283,
826,
958,
1105,
199,
14451,
1296,
7161,
275,
12863,
360,
14451,
1296,
7161,
297,
788,
633,
297,
283,
354,
297,
283,
826,
958,
1105,
421,
199,
318,
3350,
63,
765,
354,
8,
908,
63,
875,
12,
28009,
304,
272,
408,
272,
2235,
9406,
1475,
282,
1475,
63,
875,
12,
5584,
3262,
734,
1263,
272,
5041,
765,
354,
6834,
503,
5041,
765,
354,
30215,
6834,
7323,
14,
272,
408,
272,
28009,
30215,
275,
28009,
14,
1814,
20928,
26942,
272,
2203,
275,
1475,
63,
875,
272,
2203,
275,
2203,
14,
1814,
11117,
765,
354,
7293,
28009,
9,
272,
2203,
275,
2203,
14,
1814,
11117,
765,
354,
30215,
7293,
28009,
30215,
9,
272,
372,
2203,
421,
199,
318,
9378,
8,
513,
63,
1618,
63,
6717,
304,
272,
408,
272,
17415,
376,
6076,
402,
6076,
83,
12,
2529,
282,
2849,
6076,
3035,
1006,
2974,
272,
408,
272,
372,
7975,
14,
4429,
2031,
513,
63,
1618,
63,
6717,
9,
421,
199,
533,
3523,
11691,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
5189,
275,
942,
339,
347,
2274,
8,
277,
12,
2403,
12,
2455,
409,
12,
1300,
63,
354,
29,
403,
304,
267,
340,
1300,
63,
354,
365,
488,
26,
288,
1300,
63,
354,
275,
291,
14,
362,
63,
885,
63,
1095,
63,
354,
8,
1345,
409,
9,
267,
291,
14,
5189,
14,
740,
1332,
1861,
12,
2455,
409,
12,
1300,
63,
354,
430,
339,
347,
664,
63,
885,
63,
1095,
63,
354,
8,
277,
12,
2455,
409,
304,
267,
408,
267,
982,
658,
1095,
63,
354,
64,
365,
440,
2013,
12,
7427,
370,
5847,
6705,
267,
652,
687,
314,
2455,
409,
14,
267,
408,
267,
746,
4279,
360,
362,
63,
885,
63,
1095,
63,
354,
1471,
506,
10087,
358,
339,
347,
664,
63,
3603,
8,
277,
304,
267,
408,
267,
1432,
282,
769,
402,
2851,
7970,
12,
1627,
314,
7264,
2455,
2193,
14,
267,
408,
267,
746,
4279,
360,
362,
63,
3603,
1471,
506,
10087,
358,
339,
768,
1829,
272,
347,
8187,
8,
277,
304,
267,
340,
440,
2688,
8,
277,
12,
2513,
3603,
735,
288,
291,
423,
3603,
275,
291,
14,
362,
63,
3603,
342,
267,
372,
291,
423,
3603,
421,
199,
533,
5870,
11691,
8,
1563,
11691,
304,
272,
15777,
275,
359,
267,
327,
3820,
7475,
14,
267,
24244,
8,
288,
1166,
29,
82,
4289,
91,
1861,
8847,
15910,
63,
7001,
19204,
288,
4412,
3126,
355,
283,
362,
356,
283,
513,
297,
355,
283,
1932,
356,
283,
981,
7,
288,
1660,
288,
536,
32134,
4846,
17063,
513,
297,
288,
4205,
958,
3713,
4511,
356,
283,
1296,
936,
267,
2318,
267,
327,
21907,
1183,
4046,
769,
15777,
14,
267,
327,
17065,
1808,
768,
513,
63,
4449,
7531,
267,
327,
641,
3102,
402,
314,
2455,
409,
14,
267,
21907,
1296,
7161,
8,
288,
1166,
29,
82,
4289,
91,
1861,
16152,
765,
354,
8847,
15910,
63,
7001,
19204,
288,
536,
32134,
4846,
30289,
765,
354,
30215,
7293,
288,
4205,
958,
7622,
267,
2318,
267,
327,
13302,
7475,
14,
267,
24244,
8,
288,
1166,
29,
82,
4289,
91,
1861,
16152,
3892,
8847,
15910,
63,
7001,
19204,
288,
4412,
3126,
355,
283,
362,
356,
283,
14270,
297,
355,
283,
524,
356,
283,
873,
297,
355,
283,
2068,
356,
283,
6672,
63,
873,
297,
355,
283,
1807,
356,
283,
7237,
7,
288,
1660,
288,
536,
32134,
4846,
17063,
5506,
297,
288,
4205,
958,
3713,
4511,
356,
283,
3244,
936,
267,
2318,
267,
327,
21907,
1183,
4046,
10093,
15777,
14,
267,
327,
17065,
1808,
768,
5506,
63,
4449,
7531,
641,
3102,
402,
314,
2455,
409,
14,
267,
21907,
8064,
7161,
8,
288,
1166,
29,
82,
4289,
91,
1861,
16152,
3892,
16152,
765,
354,
8847,
15910,
63,
7001,
19204,
288,
536,
32134,
4846,
30289,
765,
354,
30215,
7293,
288,
4205,
958,
7622,
267,
2318,
272,
1622,
339,
347,
636,
826,
721,
277,
12,
8520,
63,
7001,
29,
549,
304,
267,
291,
14,
15910,
63,
7001,
275,
8520,
63,
7001,
436,
7324,
503,
2125,
267,
1613,
8,
3184,
11691,
12,
291,
2843,
826,
4533,
339,
347,
664,
63,
885,
63,
1095,
63,
354,
8,
277,
12,
2455,
409,
304,
267,
408,
267,
982,
658,
1095,
63,
354,
64,
365,
440,
2013,
12,
7427,
370,
5847,
6705,
267,
652,
687,
314,
2455,
409,
14,
267,
408,
267,
7594,
275,
2519,
8,
1345,
409,
12,
283,
7924,
297,
488,
9,
398,
702,
7594,
365,
440,
488,
12,
26144,
1095,
63,
354,
64,
1423,
440,
2013,
12,
436,
4293,
283,
971,
288,
283,
1397,
5847,
6705,
314,
536,
687,
314,
2455,
409,
12,
465,
283,
971,
288,
283,
390,
1630,
440,
1172,
282,
19853,
7924,
64,
2225,
3530,
398,
372,
7594,
14,
1238,
423,
2024,
14,
785,
63,
354,
14,
2325,
342,
339,
347,
664,
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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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
] |
bdero/edx-platform
|
common/djangoapps/terrain/stubs/tests/test_http.py
|
49
|
3845
|
"""
Unit tests for stub HTTP server base class.
"""
import unittest
import requests
import json
from terrain.stubs.http import StubHttpService, StubHttpRequestHandler, require_params
class StubHttpServiceTest(unittest.TestCase):
def setUp(self):
self.server = StubHttpService()
self.addCleanup(self.server.shutdown)
self.url = "http://127.0.0.1:{0}/set_config".format(self.server.port)
def test_configure(self):
"""
All HTTP stub servers have an end-point that allows
clients to configure how the server responds.
"""
params = {
'test_str': 'This is only a test',
'test_empty': '',
'test_int': 12345,
'test_float': 123.45,
'test_dict': { 'test_key': 'test_val' },
'test_empty_dict': {},
'test_unicode': u'\u2603 the snowman',
'test_none': None,
'test_boolean': False
}
for key, val in params.iteritems():
# JSON-encode each parameter
post_params = {key: json.dumps(val)}
response = requests.put(self.url, data=post_params)
self.assertEqual(response.status_code, 200)
# Check that the expected values were set in the configuration
for key, val in params.iteritems():
self.assertEqual(self.server.config.get(key), val)
def test_bad_json(self):
response = requests.put(self.url, data="{,}")
self.assertEqual(response.status_code, 400)
def test_no_post_data(self):
response = requests.put(self.url, data={})
self.assertEqual(response.status_code, 200)
def test_unicode_non_json(self):
# Send unicode without json-encoding it
response = requests.put(self.url, data={'test_unicode': u'\u2603 the snowman'})
self.assertEqual(response.status_code, 400)
def test_unknown_path(self):
response = requests.put(
"http://127.0.0.1:{0}/invalid_url".format(self.server.port),
data="{}"
)
self.assertEqual(response.status_code, 404)
class RequireRequestHandler(StubHttpRequestHandler):
@require_params('GET', 'test_param')
def do_GET(self):
self.send_response(200)
@require_params('POST', 'test_param')
def do_POST(self):
self.send_response(200)
class RequireHttpService(StubHttpService):
HANDLER_CLASS = RequireRequestHandler
class RequireParamTest(unittest.TestCase):
"""
Test the decorator for requiring parameters.
"""
def setUp(self):
self.server = RequireHttpService()
self.addCleanup(self.server.shutdown)
self.url = "http://127.0.0.1:{port}".format(port=self.server.port)
def test_require_get_param(self):
# Expect success when we provide the required param
response = requests.get(self.url, params={"test_param": 2})
self.assertEqual(response.status_code, 200)
# Expect failure when we do not proivde the param
response = requests.get(self.url)
self.assertEqual(response.status_code, 400)
# Expect failure when we provide an empty param
response = requests.get(self.url + "?test_param=")
self.assertEqual(response.status_code, 400)
def test_require_post_param(self):
# Expect success when we provide the required param
response = requests.post(self.url, data={"test_param": 2})
self.assertEqual(response.status_code, 200)
# Expect failure when we do not proivde the param
response = requests.post(self.url)
self.assertEqual(response.status_code, 400)
# Expect failure when we provide an empty param
response = requests.post(self.url, data={"test_param": None})
self.assertEqual(response.status_code, 400)
|
agpl-3.0
|
[
624,
199,
5072,
2295,
367,
10098,
3101,
1654,
1300,
1021,
14,
199,
624,
199,
199,
646,
2882,
199,
646,
4145,
199,
646,
2022,
199,
504,
2044,
6322,
14,
8957,
14,
1014,
492,
23429,
5779,
3167,
12,
23429,
10441,
2461,
12,
4409,
63,
1162,
421,
199,
533,
23429,
5779,
3167,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1000,
275,
23429,
5779,
3167,
342,
267,
291,
14,
12808,
8,
277,
14,
1000,
14,
8831,
9,
267,
291,
14,
633,
275,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5995,
409,
63,
888,
1674,
908,
8,
277,
14,
1000,
14,
719,
9,
339,
347,
511,
63,
6472,
8,
277,
304,
267,
408,
267,
2900,
3101,
10098,
8037,
1172,
376,
1284,
13,
1403,
626,
6127,
267,
13431,
370,
7908,
4212,
314,
1654,
9163,
795,
14,
267,
408,
267,
1862,
275,
469,
288,
283,
396,
63,
495,
356,
283,
2765,
365,
1454,
282,
511,
297,
288,
283,
396,
63,
1667,
356,
3260,
288,
283,
396,
63,
442,
356,
25538,
12,
288,
283,
396,
63,
1609,
356,
11869,
14,
2322,
12,
288,
283,
396,
63,
807,
356,
469,
283,
396,
63,
498,
356,
283,
396,
63,
637,
7,
1660,
288,
283,
396,
63,
1667,
63,
807,
356,
5479,
288,
283,
396,
63,
2975,
356,
399,
1154,
85,
1479,
1644,
314,
308,
2131,
1237,
297,
288,
283,
396,
63,
3592,
356,
488,
12,
288,
283,
396,
63,
4871,
356,
756,
267,
789,
398,
367,
790,
12,
1139,
315,
1862,
14,
4611,
837,
953,
327,
4840,
13,
2143,
1924,
2725,
288,
2963,
63,
1162,
275,
469,
498,
26,
2022,
14,
4180,
8,
637,
6769,
288,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
29,
1932,
63,
1162,
9,
288,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
2670,
626,
314,
1420,
1338,
4898,
663,
315,
314,
2897,
267,
367,
790,
12,
1139,
315,
1862,
14,
4611,
837,
288,
291,
14,
629,
8,
277,
14,
1000,
14,
888,
14,
362,
8,
498,
395,
1139,
9,
339,
347,
511,
63,
4087,
63,
1001,
8,
277,
304,
267,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
18448,
12,
15412,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
889,
63,
1932,
63,
576,
8,
277,
304,
267,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
21146,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2975,
63,
2865,
63,
1001,
8,
277,
304,
267,
327,
10217,
2649,
1928,
2022,
13,
2991,
652,
267,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
3713,
396,
63,
2975,
356,
399,
1154,
85,
1479,
1644,
314,
308,
2131,
1237,
3071,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
5187,
63,
515,
8,
277,
304,
267,
1177,
275,
4145,
14,
524,
8,
288,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5995,
3197,
63,
633,
1674,
908,
8,
277,
14,
1000,
14,
719,
395,
288,
666,
32053,
2,
267,
776,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
421,
199,
533,
18513,
11149,
8,
8067,
10441,
2461,
304,
272,
768,
4365,
63,
1162,
360,
2970,
297,
283,
396,
63,
635,
358,
272,
347,
886,
63,
2970,
8,
277,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
339,
768,
4365,
63,
1162,
360,
4030,
297,
283,
396,
63,
635,
358,
272,
347,
886,
63,
4030,
8,
277,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
421,
199,
533,
18513,
5779,
3167,
8,
8067,
5779,
3167,
304,
272,
23276,
19650,
63,
6885,
275,
18513,
11149,
421,
199,
533,
18513,
26680,
8,
2796,
14,
1746,
304,
272,
408,
272,
1379,
314,
7531,
367,
29963,
2633,
14,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1000,
275,
18513,
5779,
3167,
342,
267,
291,
14,
12808,
8,
277,
14,
1000,
14,
8831,
9,
267,
291,
14,
633,
275,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
719,
5469,
908,
8,
719,
29,
277,
14,
1000,
14,
719,
9,
339,
347,
511,
63,
4365,
63,
362,
63,
635,
8,
277,
304,
398,
327,
15100,
3182,
1380,
781,
5647,
314,
1415,
1215,
267,
1177,
275,
4145,
14,
362,
8,
277,
14,
633,
12,
1862,
8871,
396,
63,
635,
582,
499,
1552,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
15100,
5988,
1380,
781,
886,
440,
557,
1003,
271,
314,
1215,
267,
1177,
275,
4145,
14,
362,
8,
277,
14,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
398,
327,
15100,
5988,
1380,
781,
5647,
376,
2701,
1215,
267,
1177,
275,
4145,
14,
362,
8,
277,
14,
633,
435,
23665,
396,
63,
635,
23758,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
4365,
63,
1932,
63,
635,
8,
277,
304,
398,
327,
15100,
3182,
1380,
781,
5647,
314,
1415,
1215,
267,
1177,
275,
4145,
14,
1932,
8,
277,
14,
633,
12,
666,
8871,
396,
63,
635,
582,
499,
1552,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
15100,
5988,
1380,
781,
886,
440,
557,
1003,
271,
314,
1215,
267,
1177,
275,
4145,
14,
1932,
8,
277,
14,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
398,
327,
15100,
5988,
1380,
781,
5647,
376,
2701,
1215,
267,
1177,
275,
4145,
14,
1932,
8,
277,
14,
633,
12,
666,
8871,
396,
63,
635,
582,
488,
1552,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
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
] |
[
199,
5072,
2295,
367,
10098,
3101,
1654,
1300,
1021,
14,
199,
624,
199,
199,
646,
2882,
199,
646,
4145,
199,
646,
2022,
199,
504,
2044,
6322,
14,
8957,
14,
1014,
492,
23429,
5779,
3167,
12,
23429,
10441,
2461,
12,
4409,
63,
1162,
421,
199,
533,
23429,
5779,
3167,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1000,
275,
23429,
5779,
3167,
342,
267,
291,
14,
12808,
8,
277,
14,
1000,
14,
8831,
9,
267,
291,
14,
633,
275,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5995,
409,
63,
888,
1674,
908,
8,
277,
14,
1000,
14,
719,
9,
339,
347,
511,
63,
6472,
8,
277,
304,
267,
408,
267,
2900,
3101,
10098,
8037,
1172,
376,
1284,
13,
1403,
626,
6127,
267,
13431,
370,
7908,
4212,
314,
1654,
9163,
795,
14,
267,
408,
267,
1862,
275,
469,
288,
283,
396,
63,
495,
356,
283,
2765,
365,
1454,
282,
511,
297,
288,
283,
396,
63,
1667,
356,
3260,
288,
283,
396,
63,
442,
356,
25538,
12,
288,
283,
396,
63,
1609,
356,
11869,
14,
2322,
12,
288,
283,
396,
63,
807,
356,
469,
283,
396,
63,
498,
356,
283,
396,
63,
637,
7,
1660,
288,
283,
396,
63,
1667,
63,
807,
356,
5479,
288,
283,
396,
63,
2975,
356,
399,
1154,
85,
1479,
1644,
314,
308,
2131,
1237,
297,
288,
283,
396,
63,
3592,
356,
488,
12,
288,
283,
396,
63,
4871,
356,
756,
267,
789,
398,
367,
790,
12,
1139,
315,
1862,
14,
4611,
837,
953,
327,
4840,
13,
2143,
1924,
2725,
288,
2963,
63,
1162,
275,
469,
498,
26,
2022,
14,
4180,
8,
637,
6769,
288,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
29,
1932,
63,
1162,
9,
288,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
2670,
626,
314,
1420,
1338,
4898,
663,
315,
314,
2897,
267,
367,
790,
12,
1139,
315,
1862,
14,
4611,
837,
288,
291,
14,
629,
8,
277,
14,
1000,
14,
888,
14,
362,
8,
498,
395,
1139,
9,
339,
347,
511,
63,
4087,
63,
1001,
8,
277,
304,
267,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
18448,
12,
15412,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
889,
63,
1932,
63,
576,
8,
277,
304,
267,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
21146,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
339,
347,
511,
63,
2975,
63,
2865,
63,
1001,
8,
277,
304,
267,
327,
10217,
2649,
1928,
2022,
13,
2991,
652,
267,
1177,
275,
4145,
14,
524,
8,
277,
14,
633,
12,
666,
3713,
396,
63,
2975,
356,
399,
1154,
85,
1479,
1644,
314,
308,
2131,
1237,
3071,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
5187,
63,
515,
8,
277,
304,
267,
1177,
275,
4145,
14,
524,
8,
288,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
16,
5995,
3197,
63,
633,
1674,
908,
8,
277,
14,
1000,
14,
719,
395,
288,
666,
32053,
2,
267,
776,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
7901,
9,
421,
199,
533,
18513,
11149,
8,
8067,
10441,
2461,
304,
272,
768,
4365,
63,
1162,
360,
2970,
297,
283,
396,
63,
635,
358,
272,
347,
886,
63,
2970,
8,
277,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
339,
768,
4365,
63,
1162,
360,
4030,
297,
283,
396,
63,
635,
358,
272,
347,
886,
63,
4030,
8,
277,
304,
267,
291,
14,
2254,
63,
1310,
8,
1840,
9,
421,
199,
533,
18513,
5779,
3167,
8,
8067,
5779,
3167,
304,
272,
23276,
19650,
63,
6885,
275,
18513,
11149,
421,
199,
533,
18513,
26680,
8,
2796,
14,
1746,
304,
272,
408,
272,
1379,
314,
7531,
367,
29963,
2633,
14,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
1000,
275,
18513,
5779,
3167,
342,
267,
291,
14,
12808,
8,
277,
14,
1000,
14,
8831,
9,
267,
291,
14,
633,
275,
298,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
719,
5469,
908,
8,
719,
29,
277,
14,
1000,
14,
719,
9,
339,
347,
511,
63,
4365,
63,
362,
63,
635,
8,
277,
304,
398,
327,
15100,
3182,
1380,
781,
5647,
314,
1415,
1215,
267,
1177,
275,
4145,
14,
362,
8,
277,
14,
633,
12,
1862,
8871,
396,
63,
635,
582,
499,
1552,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
15100,
5988,
1380,
781,
886,
440,
557,
1003,
271,
314,
1215,
267,
1177,
275,
4145,
14,
362,
8,
277,
14,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
398,
327,
15100,
5988,
1380,
781,
5647,
376,
2701,
1215,
267,
1177,
275,
4145,
14,
362,
8,
277,
14,
633,
435,
23665,
396,
63,
635,
23758,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
339,
347,
511,
63,
4365,
63,
1932,
63,
635,
8,
277,
304,
398,
327,
15100,
3182,
1380,
781,
5647,
314,
1415,
1215,
267,
1177,
275,
4145,
14,
1932,
8,
277,
14,
633,
12,
666,
8871,
396,
63,
635,
582,
499,
1552,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
1926,
9,
398,
327,
15100,
5988,
1380,
781,
886,
440,
557,
1003,
271,
314,
1215,
267,
1177,
275,
4145,
14,
1932,
8,
277,
14,
633,
9,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
9,
398,
327,
15100,
5988,
1380,
781,
5647,
376,
2701,
1215,
267,
1177,
275,
4145,
14,
1932,
8,
277,
14,
633,
12,
666,
8871,
396,
63,
635,
582,
488,
1552,
267,
291,
14,
629,
8,
1310,
14,
1205,
63,
600,
12,
8290,
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,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
felixfontein/ansible
|
test/units/galaxy/test_api.py
|
13
|
47350
|
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
import os
import re
import pytest
import stat
import tarfile
import tempfile
import time
from io import BytesIO, StringIO
from units.compat.mock import MagicMock
import ansible.constants as C
from ansible import context
from ansible.errors import AnsibleError
from ansible.galaxy import api as galaxy_api
from ansible.galaxy.api import CollectionVersionMetadata, GalaxyAPI, GalaxyError
from ansible.galaxy.token import BasicAuthToken, GalaxyToken, KeycloakToken
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.six.moves.urllib import error as urllib_error
from ansible.utils import context_objects as co
from ansible.utils.display import Display
@pytest.fixture(autouse='function')
def reset_cli_args():
co.GlobalCLIArgs._Singleton__instance = None
# Required to initialise the GalaxyAPI object
context.CLIARGS._store = {'ignore_certs': False}
yield
co.GlobalCLIArgs._Singleton__instance = None
@pytest.fixture()
def collection_artifact(tmp_path_factory):
''' Creates a collection artifact tarball that is ready to be published '''
output_dir = to_text(tmp_path_factory.mktemp('test-ÅÑŚÌβŁÈ Output'))
tar_path = os.path.join(output_dir, 'namespace-collection-v1.0.0.tar.gz')
with tarfile.open(tar_path, 'w:gz') as tfile:
b_io = BytesIO(b"\x00\x01\x02\x03")
tar_info = tarfile.TarInfo('test')
tar_info.size = 4
tar_info.mode = 0o0644
tfile.addfile(tarinfo=tar_info, fileobj=b_io)
yield tar_path
@pytest.fixture()
def cache_dir(tmp_path_factory, monkeypatch):
cache_dir = to_text(tmp_path_factory.mktemp('Test ÅÑŚÌβŁÈ Galaxy Cache'))
monkeypatch.setitem(C.config._base_defs, 'GALAXY_CACHE_DIR', {'default': cache_dir})
yield cache_dir
def get_test_galaxy_api(url, version, token_ins=None, token_value=None, no_cache=True):
token_value = token_value or "my token"
token_ins = token_ins or GalaxyToken(token_value)
api = GalaxyAPI(None, "test", url, no_cache=no_cache)
# Warning, this doesn't test g_connect() because _availabe_api_versions is set here. That means
# that urls for v2 servers have to append '/api/' themselves in the input data.
api._available_api_versions = {version: '%s' % version}
api.token = token_ins
return api
def get_collection_versions(namespace='namespace', name='collection'):
base_url = 'https://galaxy.server.com/api/v2/collections/{0}/{1}/'.format(namespace, name)
versions_url = base_url + 'versions/'
# Response for collection info
responses = [
{
"id": 1000,
"href": base_url,
"name": name,
"namespace": {
"id": 30000,
"href": "https://galaxy.ansible.com/api/v1/namespaces/30000/",
"name": namespace,
},
"versions_url": versions_url,
"latest_version": {
"version": "1.0.5",
"href": versions_url + "1.0.5/"
},
"deprecated": False,
"created": "2021-02-09T16:55:42.749915-05:00",
"modified": "2021-02-09T16:55:42.749915-05:00",
}
]
# Paginated responses for versions
page_versions = (('1.0.0', '1.0.1',), ('1.0.2', '1.0.3',), ('1.0.4', '1.0.5'),)
last_page = None
for page in range(1, len(page_versions) + 1):
if page < len(page_versions):
next_page = versions_url + '?page={0}'.format(page + 1)
else:
next_page = None
version_results = []
for version in page_versions[int(page - 1)]:
version_results.append(
{'version': version, 'href': versions_url + '{0}/'.format(version)}
)
responses.append(
{
'count': 6,
'next': next_page,
'previous': last_page,
'results': version_results,
}
)
last_page = page
return responses
def test_api_no_auth():
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/")
actual = {}
api._add_auth_token(actual, "")
assert actual == {}
def test_api_no_auth_but_required():
expected = "No access token or username set. A token can be set with --api-key or at "
with pytest.raises(AnsibleError, match=expected):
GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/")._add_auth_token({}, "", required=True)
def test_api_token_auth():
token = GalaxyToken(token=u"my_token")
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
actual = {}
api._add_auth_token(actual, "", required=True)
assert actual == {'Authorization': 'Token my_token'}
def test_api_token_auth_with_token_type(monkeypatch):
token = KeycloakToken(auth_url='https://api.test/')
mock_token_get = MagicMock()
mock_token_get.return_value = 'my_token'
monkeypatch.setattr(token, 'get', mock_token_get)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
actual = {}
api._add_auth_token(actual, "", token_type="Bearer", required=True)
assert actual == {'Authorization': 'Bearer my_token'}
def test_api_token_auth_with_v3_url(monkeypatch):
token = KeycloakToken(auth_url='https://api.test/')
mock_token_get = MagicMock()
mock_token_get.return_value = 'my_token'
monkeypatch.setattr(token, 'get', mock_token_get)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
actual = {}
api._add_auth_token(actual, "https://galaxy.ansible.com/api/v3/resource/name", required=True)
assert actual == {'Authorization': 'Bearer my_token'}
def test_api_token_auth_with_v2_url():
token = GalaxyToken(token=u"my_token")
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
actual = {}
# Add v3 to random part of URL but response should only see the v2 as the full URI path segment.
api._add_auth_token(actual, "https://galaxy.ansible.com/api/v2/resourcev3/name", required=True)
assert actual == {'Authorization': 'Token my_token'}
def test_api_basic_auth_password():
token = BasicAuthToken(username=u"user", password=u"pass")
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
actual = {}
api._add_auth_token(actual, "", required=True)
assert actual == {'Authorization': 'Basic dXNlcjpwYXNz'}
def test_api_basic_auth_no_password():
token = BasicAuthToken(username=u"user")
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
actual = {}
api._add_auth_token(actual, "", required=True)
assert actual == {'Authorization': 'Basic dXNlcjo='}
def test_api_dont_override_auth_header():
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/")
actual = {'Authorization': 'Custom token'}
api._add_auth_token(actual, "", required=True)
assert actual == {'Authorization': 'Custom token'}
def test_initialise_galaxy(monkeypatch):
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"token":"my token"}'),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/")
actual = api.authenticate("github_token")
assert len(api.available_api_versions) == 2
assert api.available_api_versions['v1'] == u'v1/'
assert api.available_api_versions['v2'] == u'v2/'
assert actual == {u'token': u'my token'}
assert mock_open.call_count == 2
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.ansible.com/api/'
assert 'ansible-galaxy' in mock_open.mock_calls[0][2]['http_agent']
assert mock_open.mock_calls[1][1][0] == 'https://galaxy.ansible.com/api/v1/tokens/'
assert 'ansible-galaxy' in mock_open.mock_calls[1][2]['http_agent']
assert mock_open.mock_calls[1][2]['data'] == 'github_token=github_token'
def test_initialise_galaxy_with_auth(monkeypatch):
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/"}}'),
StringIO(u'{"token":"my token"}'),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=GalaxyToken(token='my_token'))
actual = api.authenticate("github_token")
assert len(api.available_api_versions) == 2
assert api.available_api_versions['v1'] == u'v1/'
assert api.available_api_versions['v2'] == u'v2/'
assert actual == {u'token': u'my token'}
assert mock_open.call_count == 2
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.ansible.com/api/'
assert 'ansible-galaxy' in mock_open.mock_calls[0][2]['http_agent']
assert mock_open.mock_calls[1][1][0] == 'https://galaxy.ansible.com/api/v1/tokens/'
assert 'ansible-galaxy' in mock_open.mock_calls[1][2]['http_agent']
assert mock_open.mock_calls[1][2]['data'] == 'github_token=github_token'
def test_initialise_automation_hub(monkeypatch):
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(u'{"available_versions":{"v2": "v2/", "v3":"v3/"}}'),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
token = KeycloakToken(auth_url='https://api.test/')
mock_token_get = MagicMock()
mock_token_get.return_value = 'my_token'
monkeypatch.setattr(token, 'get', mock_token_get)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=token)
assert len(api.available_api_versions) == 2
assert api.available_api_versions['v2'] == u'v2/'
assert api.available_api_versions['v3'] == u'v3/'
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.ansible.com/api/'
assert 'ansible-galaxy' in mock_open.mock_calls[0][2]['http_agent']
assert mock_open.mock_calls[0][2]['headers'] == {'Authorization': 'Bearer my_token'}
def test_initialise_unknown(monkeypatch):
mock_open = MagicMock()
mock_open.side_effect = [
urllib_error.HTTPError('https://galaxy.ansible.com/api/', 500, 'msg', {}, StringIO(u'{"msg":"raw error"}')),
urllib_error.HTTPError('https://galaxy.ansible.com/api/api/', 500, 'msg', {}, StringIO(u'{"msg":"raw error"}')),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/", token=GalaxyToken(token='my_token'))
expected = "Error when finding available api versions from test (%s) (HTTP Code: 500, Message: msg)" \
% api.api_server
with pytest.raises(AnsibleError, match=re.escape(expected)):
api.authenticate("github_token")
def test_get_available_api_versions(monkeypatch):
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(u'{"available_versions":{"v1":"v1/","v2":"v2/"}}'),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
api = GalaxyAPI(None, "test", "https://galaxy.ansible.com/api/")
actual = api.available_api_versions
assert len(actual) == 2
assert actual['v1'] == u'v1/'
assert actual['v2'] == u'v2/'
assert mock_open.call_count == 1
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.ansible.com/api/'
assert 'ansible-galaxy' in mock_open.mock_calls[0][2]['http_agent']
def test_publish_collection_missing_file():
fake_path = u'/fake/ÅÑŚÌβŁÈ/path'
expected = to_native("The collection path specified '%s' does not exist." % fake_path)
api = get_test_galaxy_api("https://galaxy.ansible.com/api/", "v2")
with pytest.raises(AnsibleError, match=expected):
api.publish_collection(fake_path)
def test_publish_collection_not_a_tarball():
expected = "The collection path specified '{0}' is not a tarball, use 'ansible-galaxy collection build' to " \
"create a proper release artifact."
api = get_test_galaxy_api("https://galaxy.ansible.com/api/", "v2")
with tempfile.NamedTemporaryFile(prefix=u'ÅÑŚÌβŁÈ') as temp_file:
temp_file.write(b"\x00")
temp_file.flush()
with pytest.raises(AnsibleError, match=expected.format(to_native(temp_file.name))):
api.publish_collection(temp_file.name)
def test_publish_collection_unsupported_version():
expected = "Galaxy action publish_collection requires API versions 'v2, v3' but only 'v1' are available on test " \
"https://galaxy.ansible.com/api/"
api = get_test_galaxy_api("https://galaxy.ansible.com/api/", "v1")
with pytest.raises(AnsibleError, match=expected):
api.publish_collection("path")
@pytest.mark.parametrize('api_version, collection_url', [
('v2', 'collections'),
('v3', 'artifacts/collections'),
])
def test_publish_collection(api_version, collection_url, collection_artifact, monkeypatch):
api = get_test_galaxy_api("https://galaxy.ansible.com/api/", api_version)
mock_call = MagicMock()
mock_call.return_value = {'task': 'http://task.url/'}
monkeypatch.setattr(api, '_call_galaxy', mock_call)
actual = api.publish_collection(collection_artifact)
assert actual == 'http://task.url/'
assert mock_call.call_count == 1
assert mock_call.mock_calls[0][1][0] == 'https://galaxy.ansible.com/api/%s/%s/' % (api_version, collection_url)
assert mock_call.mock_calls[0][2]['headers']['Content-length'] == len(mock_call.mock_calls[0][2]['args'])
assert mock_call.mock_calls[0][2]['headers']['Content-type'].startswith(
'multipart/form-data; boundary=')
assert mock_call.mock_calls[0][2]['args'].startswith(b'--')
assert mock_call.mock_calls[0][2]['method'] == 'POST'
assert mock_call.mock_calls[0][2]['auth_required'] is True
@pytest.mark.parametrize('api_version, collection_url, response, expected', [
('v2', 'collections', {},
'Error when publishing collection to test (%s) (HTTP Code: 500, Message: msg Code: Unknown)'),
('v2', 'collections', {
'message': u'Galaxy error messäge',
'code': 'GWE002',
}, u'Error when publishing collection to test (%s) (HTTP Code: 500, Message: Galaxy error messäge Code: GWE002)'),
('v3', 'artifact/collections', {},
'Error when publishing collection to test (%s) (HTTP Code: 500, Message: msg Code: Unknown)'),
('v3', 'artifact/collections', {
'errors': [
{
'code': 'conflict.collection_exists',
'detail': 'Collection "mynamespace-mycollection-4.1.1" already exists.',
'title': 'Conflict.',
'status': '400',
},
{
'code': 'quantum_improbability',
'title': u'Rändom(?) quantum improbability.',
'source': {'parameter': 'the_arrow_of_time'},
'meta': {'remediation': 'Try again before'},
},
],
}, u'Error when publishing collection to test (%s) (HTTP Code: 500, Message: Collection '
u'"mynamespace-mycollection-4.1.1" already exists. Code: conflict.collection_exists), (HTTP Code: 500, '
u'Message: Rändom(?) quantum improbability. Code: quantum_improbability)')
])
def test_publish_failure(api_version, collection_url, response, expected, collection_artifact, monkeypatch):
api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version)
expected_url = '%s/api/%s/%s' % (api.api_server, api_version, collection_url)
mock_open = MagicMock()
mock_open.side_effect = urllib_error.HTTPError(expected_url, 500, 'msg', {},
StringIO(to_text(json.dumps(response))))
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
with pytest.raises(GalaxyError, match=re.escape(to_native(expected % api.api_server))):
api.publish_collection(collection_artifact)
@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
('https://galaxy.server.com/api', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234/'),
('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
def test_wait_import_task(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.return_value = StringIO(u'{"state":"success","finished_at":"time"}')
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
mock_display = MagicMock()
monkeypatch.setattr(Display, 'display', mock_display)
api.wait_import_task(import_uri)
assert mock_open.call_count == 1
assert mock_open.mock_calls[0][1][0] == full_import_uri
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_display.call_count == 1
assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234/'),
('https://galaxy.server.com/api/automation-hub', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
def test_wait_import_task_multiple_requests(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(u'{"state":"test"}'),
StringIO(u'{"state":"success","finished_at":"time"}'),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
mock_display = MagicMock()
monkeypatch.setattr(Display, 'display', mock_display)
mock_vvv = MagicMock()
monkeypatch.setattr(Display, 'vvv', mock_vvv)
monkeypatch.setattr(time, 'sleep', MagicMock())
api.wait_import_task(import_uri)
assert mock_open.call_count == 2
assert mock_open.mock_calls[0][1][0] == full_import_uri
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_open.mock_calls[1][1][0] == full_import_uri
assert mock_open.mock_calls[1][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_display.call_count == 1
assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
assert mock_vvv.call_count == 1
assert mock_vvv.mock_calls[0][1][0] == \
'Galaxy import process has a status of test, wait 2 seconds before trying again'
@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri,', [
('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234/'),
('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
def test_wait_import_task_with_failure(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(to_text(json.dumps({
'finished_at': 'some_time',
'state': 'failed',
'error': {
'code': 'GW001',
'description': u'Becäuse I said so!',
},
'messages': [
{
'level': 'error',
'message': u'Somé error',
},
{
'level': 'warning',
'message': u'Some wärning',
},
{
'level': 'info',
'message': u'Somé info',
},
],
}))),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
mock_display = MagicMock()
monkeypatch.setattr(Display, 'display', mock_display)
mock_vvv = MagicMock()
monkeypatch.setattr(Display, 'vvv', mock_vvv)
mock_warn = MagicMock()
monkeypatch.setattr(Display, 'warning', mock_warn)
mock_err = MagicMock()
monkeypatch.setattr(Display, 'error', mock_err)
expected = to_native(u'Galaxy import process failed: Becäuse I said so! (Code: GW001)')
with pytest.raises(AnsibleError, match=re.escape(expected)):
api.wait_import_task(import_uri)
assert mock_open.call_count == 1
assert mock_open.mock_calls[0][1][0] == full_import_uri
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_display.call_count == 1
assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
assert mock_vvv.call_count == 1
assert mock_vvv.mock_calls[0][1][0] == u'Galaxy import message: info - Somé info'
assert mock_warn.call_count == 1
assert mock_warn.mock_calls[0][1][0] == u'Galaxy import warning message: Some wärning'
assert mock_err.call_count == 1
assert mock_err.mock_calls[0][1][0] == u'Galaxy import error message: Somé error'
@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my_token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234/'),
('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
def test_wait_import_task_with_failure_no_error(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(to_text(json.dumps({
'finished_at': 'some_time',
'state': 'failed',
'error': {},
'messages': [
{
'level': 'error',
'message': u'Somé error',
},
{
'level': 'warning',
'message': u'Some wärning',
},
{
'level': 'info',
'message': u'Somé info',
},
],
}))),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
mock_display = MagicMock()
monkeypatch.setattr(Display, 'display', mock_display)
mock_vvv = MagicMock()
monkeypatch.setattr(Display, 'vvv', mock_vvv)
mock_warn = MagicMock()
monkeypatch.setattr(Display, 'warning', mock_warn)
mock_err = MagicMock()
monkeypatch.setattr(Display, 'error', mock_err)
expected = 'Galaxy import process failed: Unknown error, see %s for more details \\(Code: UNKNOWN\\)' % full_import_uri
with pytest.raises(AnsibleError, match=expected):
api.wait_import_task(import_uri)
assert mock_open.call_count == 1
assert mock_open.mock_calls[0][1][0] == full_import_uri
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_display.call_count == 1
assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
assert mock_vvv.call_count == 1
assert mock_vvv.mock_calls[0][1][0] == u'Galaxy import message: info - Somé info'
assert mock_warn.call_count == 1
assert mock_warn.mock_calls[0][1][0] == u'Galaxy import warning message: Some wärning'
assert mock_err.call_count == 1
assert mock_err.mock_calls[0][1][0] == u'Galaxy import error message: Somé error'
@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
('https://galaxy.server.com/api', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234/'),
('https://galaxy.server.com/api/automation-hub', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
def test_wait_import_task_timeout(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
def return_response(*args, **kwargs):
return StringIO(u'{"state":"waiting"}')
mock_open = MagicMock()
mock_open.side_effect = return_response
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
mock_display = MagicMock()
monkeypatch.setattr(Display, 'display', mock_display)
mock_vvv = MagicMock()
monkeypatch.setattr(Display, 'vvv', mock_vvv)
monkeypatch.setattr(time, 'sleep', MagicMock())
expected = "Timeout while waiting for the Galaxy import process to finish, check progress at '%s'" % full_import_uri
with pytest.raises(AnsibleError, match=expected):
api.wait_import_task(import_uri, 1)
assert mock_open.call_count > 1
assert mock_open.mock_calls[0][1][0] == full_import_uri
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_open.mock_calls[1][1][0] == full_import_uri
assert mock_open.mock_calls[1][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_display.call_count == 1
assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
# expected_wait_msg = 'Galaxy import process has a status of waiting, wait {0} seconds before trying again'
assert mock_vvv.call_count > 9 # 1st is opening Galaxy token file.
# FIXME:
# assert mock_vvv.mock_calls[1][1][0] == expected_wait_msg.format(2)
# assert mock_vvv.mock_calls[2][1][0] == expected_wait_msg.format(3)
# assert mock_vvv.mock_calls[3][1][0] == expected_wait_msg.format(4)
# assert mock_vvv.mock_calls[4][1][0] == expected_wait_msg.format(6)
# assert mock_vvv.mock_calls[5][1][0] == expected_wait_msg.format(10)
# assert mock_vvv.mock_calls[6][1][0] == expected_wait_msg.format(15)
# assert mock_vvv.mock_calls[7][1][0] == expected_wait_msg.format(22)
# assert mock_vvv.mock_calls[8][1][0] == expected_wait_msg.format(30)
@pytest.mark.parametrize('api_version, token_type, version, token_ins', [
('v2', None, 'v2.1.13', None),
('v3', 'Bearer', 'v1.0.0', KeycloakToken(auth_url='https://api.test/api/automation-hub/')),
])
def test_get_collection_version_metadata_no_version(api_version, token_type, version, token_ins, monkeypatch):
api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(to_text(json.dumps({
'download_url': 'https://downloadme.com',
'artifact': {
'sha256': 'ac47b6fac117d7c171812750dacda655b04533cf56b31080b82d1c0db3c9d80f',
},
'namespace': {
'name': 'namespace',
},
'collection': {
'name': 'collection',
},
'version': version,
'metadata': {
'dependencies': {},
}
}))),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
actual = api.get_collection_version_metadata('namespace', 'collection', version)
assert isinstance(actual, CollectionVersionMetadata)
assert actual.namespace == u'namespace'
assert actual.name == u'collection'
assert actual.download_url == u'https://downloadme.com'
assert actual.artifact_sha256 == u'ac47b6fac117d7c171812750dacda655b04533cf56b31080b82d1c0db3c9d80f'
assert actual.version == version
assert actual.dependencies == {}
assert mock_open.call_count == 1
assert mock_open.mock_calls[0][1][0] == '%s%s/collections/namespace/collection/versions/%s/' \
% (api.api_server, api_version, version)
# v2 calls dont need auth, so no authz header or token_type
if token_type:
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
@pytest.mark.parametrize('api_version, token_type, token_ins, response', [
('v2', None, None, {
'count': 2,
'next': None,
'previous': None,
'results': [
{
'version': '1.0.0',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.0',
},
{
'version': '1.0.1',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.1',
},
],
}),
# TODO: Verify this once Automation Hub is actually out
('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'), {
'count': 2,
'next': None,
'previous': None,
'data': [
{
'version': '1.0.0',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.0',
},
{
'version': '1.0.1',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.1',
},
],
}),
])
def test_get_collection_versions(api_version, token_type, token_ins, response, monkeypatch):
api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.side_effect = [
StringIO(to_text(json.dumps(response))),
]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
actual = api.get_collection_versions('namespace', 'collection')
assert actual == [u'1.0.0', u'1.0.1']
page_query = '?limit=100' if api_version == 'v3' else '?page_size=100'
assert mock_open.call_count == 1
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.server.com/api/%s/collections/namespace/collection/' \
'versions/%s' % (api_version, page_query)
if token_ins:
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
@pytest.mark.parametrize('api_version, token_type, token_ins, responses', [
('v2', None, None, [
{
'count': 6,
'next': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/?page=2&page_size=100',
'previous': None,
'results': [ # Pay no mind, using more manageable results than page_size would indicate
{
'version': '1.0.0',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.0',
},
{
'version': '1.0.1',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.1',
},
],
},
{
'count': 6,
'next': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/?page=3&page_size=100',
'previous': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions',
'results': [
{
'version': '1.0.2',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.2',
},
{
'version': '1.0.3',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.3',
},
],
},
{
'count': 6,
'next': None,
'previous': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/?page=2&page_size=100',
'results': [
{
'version': '1.0.4',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.4',
},
{
'version': '1.0.5',
'href': 'https://galaxy.server.com/api/v2/collections/namespace/collection/versions/1.0.5',
},
],
},
]),
('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'), [
{
'count': 6,
'links': {
# v3 links are relative and the limit is included during pagination
'next': '/api/v3/collections/namespace/collection/versions/?limit=100&offset=100',
'previous': None,
},
'data': [
{
'version': '1.0.0',
'href': '/api/v3/collections/namespace/collection/versions/1.0.0',
},
{
'version': '1.0.1',
'href': '/api/v3/collections/namespace/collection/versions/1.0.1',
},
],
},
{
'count': 6,
'links': {
'next': '/api/v3/collections/namespace/collection/versions/?limit=100&offset=200',
'previous': '/api/v3/collections/namespace/collection/versions',
},
'data': [
{
'version': '1.0.2',
'href': '/api/v3/collections/namespace/collection/versions/1.0.2',
},
{
'version': '1.0.3',
'href': '/api/v3/collections/namespace/collection/versions/1.0.3',
},
],
},
{
'count': 6,
'links': {
'next': None,
'previous': '/api/v3/collections/namespace/collection/versions/?limit=100&offset=100',
},
'data': [
{
'version': '1.0.4',
'href': '/api/v3/collections/namespace/collection/versions/1.0.4',
},
{
'version': '1.0.5',
'href': '/api/v3/collections/namespace/collection/versions/1.0.5',
},
],
},
]),
])
def test_get_collection_versions_pagination(api_version, token_type, token_ins, responses, monkeypatch):
api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
mock_token_get.return_value = 'my token'
monkeypatch.setattr(token_ins, 'get', mock_token_get)
mock_open = MagicMock()
mock_open.side_effect = [StringIO(to_text(json.dumps(r))) for r in responses]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
actual = api.get_collection_versions('namespace', 'collection')
assert actual == [u'1.0.0', u'1.0.1', u'1.0.2', u'1.0.3', u'1.0.4', u'1.0.5']
assert mock_open.call_count == 3
if api_version == 'v3':
query_1 = 'limit=100'
query_2 = 'limit=100&offset=100'
query_3 = 'limit=100&offset=200'
else:
query_1 = 'page_size=100'
query_2 = 'page=2&page_size=100'
query_3 = 'page=3&page_size=100'
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.server.com/api/%s/collections/namespace/collection/' \
'versions/?%s' % (api_version, query_1)
assert mock_open.mock_calls[1][1][0] == 'https://galaxy.server.com/api/%s/collections/namespace/collection/' \
'versions/?%s' % (api_version, query_2)
assert mock_open.mock_calls[2][1][0] == 'https://galaxy.server.com/api/%s/collections/namespace/collection/' \
'versions/?%s' % (api_version, query_3)
if token_type:
assert mock_open.mock_calls[0][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_open.mock_calls[1][2]['headers']['Authorization'] == '%s my token' % token_type
assert mock_open.mock_calls[2][2]['headers']['Authorization'] == '%s my token' % token_type
@pytest.mark.parametrize('responses', [
[
{
'count': 2,
'results': [{'name': '3.5.1', }, {'name': '3.5.2'}],
'next_link': None,
'next': None,
'previous_link': None,
'previous': None
},
],
[
{
'count': 2,
'results': [{'name': '3.5.1'}],
'next_link': '/api/v1/roles/432/versions/?page=2&page_size=50',
'next': '/roles/432/versions/?page=2&page_size=50',
'previous_link': None,
'previous': None
},
{
'count': 2,
'results': [{'name': '3.5.2'}],
'next_link': None,
'next': None,
'previous_link': '/api/v1/roles/432/versions/?&page_size=50',
'previous': '/roles/432/versions/?page_size=50',
},
]
])
def test_get_role_versions_pagination(monkeypatch, responses):
api = get_test_galaxy_api('https://galaxy.com/api/', 'v1')
mock_open = MagicMock()
mock_open.side_effect = [StringIO(to_text(json.dumps(r))) for r in responses]
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
actual = api.fetch_role_related('versions', 432)
assert actual == [{'name': '3.5.1'}, {'name': '3.5.2'}]
assert mock_open.call_count == len(responses)
assert mock_open.mock_calls[0][1][0] == 'https://galaxy.com/api/v1/roles/432/versions/?page_size=50'
if len(responses) == 2:
assert mock_open.mock_calls[1][1][0] == 'https://galaxy.com/api/v1/roles/432/versions/?page=2&page_size=50'
def test_missing_cache_dir(cache_dir):
os.rmdir(cache_dir)
GalaxyAPI(None, "test", 'https://galaxy.ansible.com/', no_cache=False)
assert os.path.isdir(cache_dir)
assert stat.S_IMODE(os.stat(cache_dir).st_mode) == 0o700
cache_file = os.path.join(cache_dir, 'api.json')
with open(cache_file) as fd:
actual_cache = fd.read()
assert actual_cache == '{"version": 1}'
assert stat.S_IMODE(os.stat(cache_file).st_mode) == 0o600
def test_existing_cache(cache_dir):
cache_file = os.path.join(cache_dir, 'api.json')
cache_file_contents = '{"version": 1, "test": "json"}'
with open(cache_file, mode='w') as fd:
fd.write(cache_file_contents)
os.chmod(cache_file, 0o655)
GalaxyAPI(None, "test", 'https://galaxy.ansible.com/', no_cache=False)
assert os.path.isdir(cache_dir)
with open(cache_file) as fd:
actual_cache = fd.read()
assert actual_cache == cache_file_contents
assert stat.S_IMODE(os.stat(cache_file).st_mode) == 0o655
@pytest.mark.parametrize('content', [
'',
'value',
'{"de" "finit" "ely" [\'invalid"]}',
'[]',
'{"version": 2, "test": "json"}',
'{"version": 2, "key": "ÅÑŚÌβŁÈ"}',
])
def test_cache_invalid_cache_content(content, cache_dir):
cache_file = os.path.join(cache_dir, 'api.json')
with open(cache_file, mode='w') as fd:
fd.write(content)
os.chmod(cache_file, 0o664)
GalaxyAPI(None, "test", 'https://galaxy.ansible.com/', no_cache=False)
with open(cache_file) as fd:
actual_cache = fd.read()
assert actual_cache == '{"version": 1}'
assert stat.S_IMODE(os.stat(cache_file).st_mode) == 0o664
def test_cache_complete_pagination(cache_dir, monkeypatch):
responses = get_collection_versions()
cache_file = os.path.join(cache_dir, 'api.json')
api = get_test_galaxy_api('https://galaxy.server.com/api/', 'v2', no_cache=False)
mock_open = MagicMock(
side_effect=[
StringIO(to_text(json.dumps(r)))
for r in responses
]
)
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
actual_versions = api.get_collection_versions('namespace', 'collection')
assert actual_versions == [u'1.0.0', u'1.0.1', u'1.0.2', u'1.0.3', u'1.0.4', u'1.0.5']
with open(cache_file) as fd:
final_cache = json.loads(fd.read())
cached_server = final_cache['galaxy.server.com:']
cached_collection = cached_server['/api/v2/collections/namespace/collection/versions/']
cached_versions = [r['version'] for r in cached_collection['results']]
assert final_cache == api._cache
assert cached_versions == actual_versions
def test_cache_flaky_pagination(cache_dir, monkeypatch):
responses = get_collection_versions()
cache_file = os.path.join(cache_dir, 'api.json')
api = get_test_galaxy_api('https://galaxy.server.com/api/', 'v2', no_cache=False)
# First attempt, fail midway through
mock_open = MagicMock(
side_effect=[
StringIO(to_text(json.dumps(responses[0]))),
StringIO(to_text(json.dumps(responses[1]))),
urllib_error.HTTPError(responses[1]['next'], 500, 'Error', {}, StringIO()),
StringIO(to_text(json.dumps(responses[3]))),
]
)
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
expected = (
r'Error when getting available collection versions for namespace\.collection '
r'from test \(https://galaxy\.server\.com/api/\) '
r'\(HTTP Code: 500, Message: Error Code: Unknown\)'
)
with pytest.raises(GalaxyError, match=expected):
api.get_collection_versions('namespace', 'collection')
with open(cache_file) as fd:
final_cache = json.loads(fd.read())
assert final_cache == {
'version': 1,
'galaxy.server.com:': {
'modified': {
'namespace.collection': responses[0]['modified']
}
}
}
# Reset API
api = get_test_galaxy_api('https://galaxy.server.com/api/', 'v2', no_cache=False)
# Second attempt is successful so cache should be populated
mock_open = MagicMock(
side_effect=[
StringIO(to_text(json.dumps(r)))
for r in responses
]
)
monkeypatch.setattr(galaxy_api, 'open_url', mock_open)
actual_versions = api.get_collection_versions('namespace', 'collection')
assert actual_versions == [u'1.0.0', u'1.0.1', u'1.0.2', u'1.0.3', u'1.0.4', u'1.0.5']
with open(cache_file) as fd:
final_cache = json.loads(fd.read())
cached_server = final_cache['galaxy.server.com:']
cached_collection = cached_server['/api/v2/collections/namespace/collection/versions/']
cached_versions = [r['version'] for r in cached_collection['results']]
assert cached_versions == actual_versions
def test_world_writable_cache(cache_dir, monkeypatch):
mock_warning = MagicMock()
monkeypatch.setattr(Display, 'warning', mock_warning)
cache_file = os.path.join(cache_dir, 'api.json')
with open(cache_file, mode='w') as fd:
fd.write('{"version": 2}')
os.chmod(cache_file, 0o666)
api = GalaxyAPI(None, "test", 'https://galaxy.ansible.com/', no_cache=False)
assert api._cache is None
with open(cache_file) as fd:
actual_cache = fd.read()
assert actual_cache == '{"version": 2}'
assert stat.S_IMODE(os.stat(cache_file).st_mode) == 0o666
assert mock_warning.call_count == 1
assert mock_warning.call_args[0][0] == \
'Galaxy cache has world writable access (%s), ignoring it as a cache source.' % cache_file
def test_no_cache(cache_dir):
cache_file = os.path.join(cache_dir, 'api.json')
with open(cache_file, mode='w') as fd:
fd.write('random')
api = GalaxyAPI(None, "test", 'https://galaxy.ansible.com/')
assert api._cache is None
with open(cache_file) as fd:
actual_cache = fd.read()
assert actual_cache == 'random'
def test_clear_cache_with_no_cache(cache_dir):
cache_file = os.path.join(cache_dir, 'api.json')
with open(cache_file, mode='w') as fd:
fd.write('{"version": 1, "key": "value"}')
GalaxyAPI(None, "test", 'https://galaxy.ansible.com/', clear_response_cache=True)
assert not os.path.exists(cache_file)
def test_clear_cache(cache_dir):
cache_file = os.path.join(cache_dir, 'api.json')
with open(cache_file, mode='w') as fd:
fd.write('{"version": 1, "key": "value"}')
GalaxyAPI(None, "test", 'https://galaxy.ansible.com/', clear_response_cache=True, no_cache=False)
with open(cache_file) as fd:
actual_cache = fd.read()
assert actual_cache == '{"version": 1}'
assert stat.S_IMODE(os.stat(cache_file).st_mode) == 0o600
@pytest.mark.parametrize(['url', 'expected'], [
('http://hostname/path', 'hostname:'),
('http://hostname:80/path', 'hostname:80'),
('https://testing.com:invalid', 'testing.com:'),
('https://testing.com:1234', 'testing.com:1234'),
('https://username:password@testing.com/path', 'testing.com:'),
('https://username:password@testing.com:443/path', 'testing.com:443'),
])
def test_cache_id(url, expected):
actual = galaxy_api.get_cache_id(url)
assert actual == expected
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
26,
334,
67,
9,
20312,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
2022,
199,
646,
747,
199,
646,
295,
199,
646,
4613,
199,
646,
5672,
199,
646,
13608,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
5890,
492,
11808,
12,
5228,
199,
504,
6204,
14,
5819,
14,
1805,
492,
10079,
199,
199,
646,
3242,
14,
5559,
465,
445,
199,
504,
3242,
492,
1067,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
24806,
492,
2986,
465,
486,
15914,
63,
1246,
199,
504,
3242,
14,
24806,
14,
1246,
492,
18003,
3353,
5142,
12,
598,
15914,
3735,
12,
598,
15914,
547,
199,
504,
3242,
14,
24806,
14,
1418,
492,
10082,
2817,
3264,
12,
598,
15914,
3264,
12,
2606,
1251,
1151,
3264,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
12,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
492,
1125,
465,
4011,
63,
705,
199,
504,
3242,
14,
1208,
492,
1067,
63,
1462,
465,
512,
199,
504,
3242,
14,
1208,
14,
2918,
492,
12175,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
534,
1593,
358,
199,
318,
5305,
63,
2764,
63,
589,
837,
272,
512,
14,
7025,
7802,
6213,
423,
28456,
363,
842,
275,
488,
272,
327,
11105,
370,
2536,
572,
314,
598,
15914,
3735,
909,
272,
1067,
14,
7802,
13990,
423,
1617,
275,
791,
4247,
63,
8356,
356,
756,
93,
272,
1995,
272,
512,
14,
7025,
7802,
6213,
423,
28456,
363,
842,
275,
488,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
3245,
63,
16154,
8,
2791,
63,
515,
63,
3702,
304,
272,
1449,
10560,
282,
3245,
18115,
17641,
626,
365,
10144,
370,
506,
3267,
1449,
272,
1072,
63,
694,
275,
370,
63,
505,
8,
2791,
63,
515,
63,
3702,
14,
22136,
360,
396,
13,
128,
228,
128,
240,
130,
249,
128,
235,
139,
111,
130,
224,
128,
231,
7242,
1333,
339,
5330,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1199,
63,
694,
12,
283,
3251,
13,
3627,
13,
86,
17,
14,
16,
14,
16,
14,
5369,
14,
6838,
358,
272,
543,
13608,
14,
1490,
8,
5369,
63,
515,
12,
283,
87,
26,
6838,
358,
465,
307,
493,
26,
267,
330,
63,
2308,
275,
11808,
8,
66,
3212,
88,
383,
60,
88,
614,
60,
88,
996,
60,
88,
1644,
531,
267,
5330,
63,
815,
275,
13608,
14,
24818,
2354,
360,
396,
358,
267,
5330,
63,
815,
14,
890,
275,
841,
267,
5330,
63,
815,
14,
632,
275,
378,
79,
16,
10893,
267,
307,
493,
14,
525,
493,
8,
16874,
29,
5369,
63,
815,
12,
11099,
29,
66,
63,
2308,
9,
339,
1995,
5330,
63,
515,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
2581,
63,
694,
8,
2791,
63,
515,
63,
3702,
12,
17309,
304,
272,
2581,
63,
694,
275,
370,
63,
505,
8,
2791,
63,
515,
63,
3702,
14,
22136,
360,
774,
13333,
228,
128,
240,
130,
249,
128,
235,
139,
111,
130,
224,
128,
231,
598,
15914,
11977,
1333,
272,
17309,
14,
8617,
8,
35,
14,
888,
423,
1095,
63,
8710,
12,
283,
39,
26674,
8195,
63,
8677,
63,
3022,
297,
791,
885,
356,
2581,
63,
694,
1552,
339,
1995,
2581,
63,
694,
421,
199,
318,
664,
63,
396,
63,
24806,
63,
1246,
8,
633,
12,
1015,
12,
1526,
63,
3617,
29,
403,
12,
1526,
63,
585,
29,
403,
12,
949,
63,
1637,
29,
549,
304,
272,
1526,
63,
585,
275,
1526,
63,
585,
503,
298,
1662,
1526,
2,
272,
1526,
63,
3617,
275,
1526,
63,
3617,
503,
598,
15914,
3264,
8,
1418,
63,
585,
9,
272,
2986,
275,
598,
15914,
3735,
8,
403,
12,
298,
396,
401,
1166,
12,
949,
63,
1637,
29,
889,
63,
1637,
9,
272,
327,
15902,
12,
642,
3181,
1133,
511,
486,
63,
2242,
342,
2952,
485,
18961,
7570,
63,
1246,
63,
6234,
365,
663,
2348,
14,
221,
10314,
4910,
272,
327,
626,
8187,
367,
373,
18,
8037,
1172,
370,
5666,
1994,
1246,
4805,
17279,
315,
314,
1324,
666,
14,
272,
2986,
423,
4561,
63,
1246,
63,
6234,
275,
469,
1023,
26,
1543,
83,
7,
450,
1015,
93,
272,
2986,
14,
1418,
275,
1526,
63,
3617,
339,
372,
2986,
421,
199,
318,
664,
63,
3627,
63,
6234,
8,
3251,
534,
3251,
297,
536,
534,
3627,
735,
272,
1300,
63,
633,
275,
283,
2859,
921,
24806,
14,
1000,
14,
957,
15,
1246,
15,
86,
18,
15,
7882,
5321,
16,
16152,
17,
5995,
1370,
908,
8,
3251,
12,
536,
9,
272,
5459,
63,
633,
275,
1300,
63,
633,
435,
283,
6234,
4805,
339,
327,
7232,
367,
3245,
2256,
272,
9320,
275,
359,
267,
469,
288,
298,
344,
582,
5198,
12,
288,
298,
6399,
582,
1300,
63,
633,
12,
288,
298,
354,
582,
536,
12,
288,
298,
3251,
582,
469,
355,
298,
344,
582,
650,
993,
12,
355,
298,
6399,
582,
298,
2859,
921,
24806,
14,
4853,
14,
957,
15,
1246,
15,
86,
17,
15,
9247,
15,
19,
993,
10665,
355,
298,
354,
582,
3231,
12,
288,
1660,
288,
298,
6234,
63,
633,
582,
5459,
63,
633,
12,
288,
298,
7410,
63,
1023,
582,
469,
355,
298,
1023,
582,
298,
17,
14,
16,
14,
21,
401,
355,
298,
6399,
582,
5459,
63,
633,
435,
298,
17,
14,
16,
14,
21,
6687,
288,
1660,
288,
298,
6667,
582,
756,
12,
288,
298,
3966,
582,
298,
22150,
13,
996,
13,
1643,
52,
975,
26,
1229,
26,
2260,
14,
1342,
1020,
1046,
13,
1717,
26,
383,
401,
288,
298,
5540,
582,
298,
22150,
13,
996,
13,
1643,
52,
975,
26,
1229,
26,
2260,
14,
1342,
1020,
1046,
13,
1717,
26,
383,
401,
267,
789,
272,
1622,
339,
327,
28006,
23831,
9320,
367,
5459,
272,
2034,
63,
6234
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
26,
334,
67,
9,
20312,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
2022,
199,
646,
747,
199,
646,
295,
199,
646,
4613,
199,
646,
5672,
199,
646,
13608,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
5890,
492,
11808,
12,
5228,
199,
504,
6204,
14,
5819,
14,
1805,
492,
10079,
199,
199,
646,
3242,
14,
5559,
465,
445,
199,
504,
3242,
492,
1067,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
24806,
492,
2986,
465,
486,
15914,
63,
1246,
199,
504,
3242,
14,
24806,
14,
1246,
492,
18003,
3353,
5142,
12,
598,
15914,
3735,
12,
598,
15914,
547,
199,
504,
3242,
14,
24806,
14,
1418,
492,
10082,
2817,
3264,
12,
598,
15914,
3264,
12,
2606,
1251,
1151,
3264,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
6106,
12,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
14,
4078,
492,
1125,
465,
4011,
63,
705,
199,
504,
3242,
14,
1208,
492,
1067,
63,
1462,
465,
512,
199,
504,
3242,
14,
1208,
14,
2918,
492,
12175,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
534,
1593,
358,
199,
318,
5305,
63,
2764,
63,
589,
837,
272,
512,
14,
7025,
7802,
6213,
423,
28456,
363,
842,
275,
488,
272,
327,
11105,
370,
2536,
572,
314,
598,
15914,
3735,
909,
272,
1067,
14,
7802,
13990,
423,
1617,
275,
791,
4247,
63,
8356,
356,
756,
93,
272,
1995,
272,
512,
14,
7025,
7802,
6213,
423,
28456,
363,
842,
275,
488,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
3245,
63,
16154,
8,
2791,
63,
515,
63,
3702,
304,
272,
1449,
10560,
282,
3245,
18115,
17641,
626,
365,
10144,
370,
506,
3267,
1449,
272,
1072,
63,
694,
275,
370,
63,
505,
8,
2791,
63,
515,
63,
3702,
14,
22136,
360,
396,
13,
128,
228,
128,
240,
130,
249,
128,
235,
139,
111,
130,
224,
128,
231,
7242,
1333,
339,
5330,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1199,
63,
694,
12,
283,
3251,
13,
3627,
13,
86,
17,
14,
16,
14,
16,
14,
5369,
14,
6838,
358,
272,
543,
13608,
14,
1490,
8,
5369,
63,
515,
12,
283,
87,
26,
6838,
358,
465,
307,
493,
26,
267,
330,
63,
2308,
275,
11808,
8,
66,
3212,
88,
383,
60,
88,
614,
60,
88,
996,
60,
88,
1644,
531,
267,
5330,
63,
815,
275,
13608,
14,
24818,
2354,
360,
396,
358,
267,
5330,
63,
815,
14,
890,
275,
841,
267,
5330,
63,
815,
14,
632,
275,
378,
79,
16,
10893,
267,
307,
493,
14,
525,
493,
8,
16874,
29,
5369,
63,
815,
12,
11099,
29,
66,
63,
2308,
9,
339,
1995,
5330,
63,
515,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
2581,
63,
694,
8,
2791,
63,
515,
63,
3702,
12,
17309,
304,
272,
2581,
63,
694,
275,
370,
63,
505,
8,
2791,
63,
515,
63,
3702,
14,
22136,
360,
774,
13333,
228,
128,
240,
130,
249,
128,
235,
139,
111,
130,
224,
128,
231,
598,
15914,
11977,
1333,
272,
17309,
14,
8617,
8,
35,
14,
888,
423,
1095,
63,
8710,
12,
283,
39,
26674,
8195,
63,
8677,
63,
3022,
297,
791,
885,
356,
2581,
63,
694,
1552,
339,
1995,
2581,
63,
694,
421,
199,
318,
664,
63,
396,
63,
24806,
63,
1246,
8,
633,
12,
1015,
12,
1526,
63,
3617,
29,
403,
12,
1526,
63,
585,
29,
403,
12,
949,
63,
1637,
29,
549,
304,
272,
1526,
63,
585,
275,
1526,
63,
585,
503,
298,
1662,
1526,
2,
272,
1526,
63,
3617,
275,
1526,
63,
3617,
503,
598,
15914,
3264,
8,
1418,
63,
585,
9,
272,
2986,
275,
598,
15914,
3735,
8,
403,
12,
298,
396,
401,
1166,
12,
949,
63,
1637,
29,
889,
63,
1637,
9,
272,
327,
15902,
12,
642,
3181,
1133,
511,
486,
63,
2242,
342,
2952,
485,
18961,
7570,
63,
1246,
63,
6234,
365,
663,
2348,
14,
221,
10314,
4910,
272,
327,
626,
8187,
367,
373,
18,
8037,
1172,
370,
5666,
1994,
1246,
4805,
17279,
315,
314,
1324,
666,
14,
272,
2986,
423,
4561,
63,
1246,
63,
6234,
275,
469,
1023,
26,
1543,
83,
7,
450,
1015,
93,
272,
2986,
14,
1418,
275,
1526,
63,
3617,
339,
372,
2986,
421,
199,
318,
664,
63,
3627,
63,
6234,
8,
3251,
534,
3251,
297,
536,
534,
3627,
735,
272,
1300,
63,
633,
275,
283,
2859,
921,
24806,
14,
1000,
14,
957,
15,
1246,
15,
86,
18,
15,
7882,
5321,
16,
16152,
17,
5995,
1370,
908,
8,
3251,
12,
536,
9,
272,
5459,
63,
633,
275,
1300,
63,
633,
435,
283,
6234,
4805,
339,
327,
7232,
367,
3245,
2256,
272,
9320,
275,
359,
267,
469,
288,
298,
344,
582,
5198,
12,
288,
298,
6399,
582,
1300,
63,
633,
12,
288,
298,
354,
582,
536,
12,
288,
298,
3251,
582,
469,
355,
298,
344,
582,
650,
993,
12,
355,
298,
6399,
582,
298,
2859,
921,
24806,
14,
4853,
14,
957,
15,
1246,
15,
86,
17,
15,
9247,
15,
19,
993,
10665,
355,
298,
354,
582,
3231,
12,
288,
1660,
288,
298,
6234,
63,
633,
582,
5459,
63,
633,
12,
288,
298,
7410,
63,
1023,
582,
469,
355,
298,
1023,
582,
298,
17,
14,
16,
14,
21,
401,
355,
298,
6399,
582,
5459,
63,
633,
435,
298,
17,
14,
16,
14,
21,
6687,
288,
1660,
288,
298,
6667,
582,
756,
12,
288,
298,
3966,
582,
298,
22150,
13,
996,
13,
1643,
52,
975,
26,
1229,
26,
2260,
14,
1342,
1020,
1046,
13,
1717,
26,
383,
401,
288,
298,
5540,
582,
298,
22150,
13,
996,
13,
1643,
52,
975,
26,
1229,
26,
2260,
14,
1342,
1020,
1046,
13,
1717,
26,
383,
401,
267,
789,
272,
1622,
339,
327,
28006,
23831,
9320,
367,
5459,
272,
2034,
63,
6234,
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,
1
] |
JimCircadian/ansible
|
lib/ansible/modules/cloud/cloudstack/cs_staticnat.py
|
29
|
7371
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (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/>.
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: cs_staticnat
short_description: Manages static NATs on Apache CloudStack based clouds.
description:
- Create, update and remove static NATs.
version_added: '2.0'
author: "René Moser (@resmo)"
options:
ip_address:
description:
- Public IP address the static NAT is assigned to.
required: true
vm:
description:
- Name of virtual machine which we make the static NAT for.
- Required if C(state=present).
vm_guest_ip:
description:
- VM guest NIC secondary IP address for the static NAT.
type: bool
default: 'no'
network:
description:
- Network the IP address is related to.
version_added: "2.2"
vpc:
description:
- VPC the network related to.
version_added: "2.3"
state:
description:
- State of the static NAT.
default: 'present'
choices: [ 'present', 'absent' ]
domain:
description:
- Domain the static NAT is related to.
account:
description:
- Account the static NAT is related to.
project:
description:
- Name of the project the static NAT is related to.
zone:
description:
- Name of the zone in which the virtual machine is in.
- If not set, default zone is used.
poll_async:
description:
- Poll async jobs until job has finished.
type: bool
default: 'yes'
extends_documentation_fragment: cloudstack
'''
EXAMPLES = '''
# create a static NAT: 1.2.3.4 -> web01
- local_action:
module: cs_staticnat
ip_address: 1.2.3.4
vm: web01
# remove a static NAT
- local_action:
module: cs_staticnat
ip_address: 1.2.3.4
state: absent
'''
RETURN = '''
---
id:
description: UUID of the ip_address.
returned: success
type: string
sample: a6f7a5fc-43f8-11e5-a151-feff819cdc9f
ip_address:
description: Public IP address.
returned: success
type: string
sample: 1.2.3.4
vm_name:
description: Name of the virtual machine.
returned: success
type: string
sample: web-01
vm_display_name:
description: Display name of the virtual machine.
returned: success
type: string
sample: web-01
vm_guest_ip:
description: IP of the virtual machine.
returned: success
type: string
sample: 10.101.65.152
zone:
description: Name of zone the static NAT is related to.
returned: success
type: string
sample: ch-gva-2
project:
description: Name of project the static NAT is related to.
returned: success
type: string
sample: Production
account:
description: Account the static NAT is related to.
returned: success
type: string
sample: example account
domain:
description: Domain the static NAT is related to.
returned: success
type: string
sample: example domain
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.cloudstack import (
AnsibleCloudStack,
cs_argument_spec,
cs_required_together,
)
class AnsibleCloudStackStaticNat(AnsibleCloudStack):
def __init__(self, module):
super(AnsibleCloudStackStaticNat, self).__init__(module)
self.returns = {
'virtualmachinedisplayname': 'vm_display_name',
'virtualmachinename': 'vm_name',
'ipaddress': 'ip_address',
'vmipaddress': 'vm_guest_ip',
}
def create_static_nat(self, ip_address):
self.result['changed'] = True
args = {
'virtualmachineid': self.get_vm(key='id'),
'ipaddressid': ip_address['id'],
'vmguestip': self.get_vm_guest_ip(),
'networkid': self.get_network(key='id')
}
if not self.module.check_mode:
self.query_api('enableStaticNat', **args)
# reset ip address and query new values
self.ip_address = None
ip_address = self.get_ip_address()
return ip_address
def update_static_nat(self, ip_address):
args = {
'virtualmachineid': self.get_vm(key='id'),
'ipaddressid': ip_address['id'],
'vmguestip': self.get_vm_guest_ip(),
'networkid': self.get_network(key='id')
}
# make an alias, so we can use has_changed()
ip_address['vmguestip'] = ip_address['vmipaddress']
if self.has_changed(args, ip_address, ['vmguestip', 'virtualmachineid']):
self.result['changed'] = True
if not self.module.check_mode:
res = self.query_api('disableStaticNat', ipaddressid=ip_address['id'])
self.poll_job(res, 'staticnat')
self.query_api('enableStaticNat', **args)
# reset ip address and query new values
self.ip_address = None
ip_address = self.get_ip_address()
return ip_address
def present_static_nat(self):
ip_address = self.get_ip_address()
if not ip_address['isstaticnat']:
ip_address = self.create_static_nat(ip_address)
else:
ip_address = self.update_static_nat(ip_address)
return ip_address
def absent_static_nat(self):
ip_address = self.get_ip_address()
if ip_address['isstaticnat']:
self.result['changed'] = True
if not self.module.check_mode:
res = self.query_api('disableStaticNat', ipaddressid=ip_address['id'])
poll_async = self.module.params.get('poll_async')
if poll_async:
self.poll_job(res, 'staticnat')
return ip_address
def main():
argument_spec = cs_argument_spec()
argument_spec.update(dict(
ip_address=dict(required=True),
vm=dict(),
vm_guest_ip=dict(),
network=dict(),
vpc=dict(),
state=dict(choices=['present', 'absent'], default='present'),
zone=dict(),
domain=dict(),
account=dict(),
project=dict(),
poll_async=dict(type='bool', default=True),
))
module = AnsibleModule(
argument_spec=argument_spec,
required_together=cs_required_together(),
supports_check_mode=True
)
acs_static_nat = AnsibleCloudStackStaticNat(module)
state = module.params.get('state')
if state in ['absent']:
ip_address = acs_static_nat.absent_static_nat()
else:
ip_address = acs_static_nat.present_static_nat()
result = acs_static_nat.get_result(ip_address)
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
6900,
12,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
7117,
63,
1986,
9468,
199,
3612,
63,
1802,
26,
21612,
2955,
31363,
83,
641,
3668,
8142,
4851,
4079,
2463,
14577,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
2813,
2955,
31363,
83,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
2502,
26,
298,
5349,
5741,
3930,
332,
8593,
470,
573,
2924,
199,
1419,
26,
523,
3384,
63,
1562,
26,
272,
1369,
26,
489,
446,
1684,
3531,
2287,
314,
2955,
31363,
365,
7943,
370,
14,
272,
1415,
26,
2549,
523,
4169,
26,
272,
1369,
26,
489,
446,
2812,
402,
5791,
6844,
1314,
781,
1852,
314,
2955,
31363,
367,
14,
489,
446,
11105,
340,
445,
8,
929,
29,
1881,
680,
523,
4169,
63,
10409,
63,
711,
26,
272,
1369,
26,
489,
446,
7525,
13980,
31265,
13851,
3531,
2287,
367,
314,
2955,
31363,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
2784,
26,
272,
1369,
26,
489,
446,
7220,
314,
3531,
2287,
365,
4048,
370,
14,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
12830,
26,
272,
1369,
26,
489,
446,
19209,
314,
2784,
4048,
370,
14,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
402,
314,
2955,
31363,
14,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
523,
2881,
26,
272,
1369,
26,
489,
446,
14061,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2933,
26,
272,
1369,
26,
489,
446,
9973,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2199,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2199,
314,
2955,
31363,
365,
4048,
370,
14,
523,
5718,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5718,
315,
1314,
314,
5791,
6844,
365,
315,
14,
489,
446,
982,
440,
663,
12,
849,
5718,
365,
1202,
14,
523,
11271,
63,
4146,
26,
272,
1369,
26,
489,
446,
25306,
5316,
9643,
5133,
3906,
965,
9158,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
199,
11036,
63,
9970,
63,
7677,
26,
8002,
2340,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
1218,
282,
2955,
31363,
26,
413,
14,
18,
14,
19,
14,
20,
1035,
3330,
614,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
1986,
9468,
272,
3384,
63,
1562,
26,
413,
14,
18,
14,
19,
14,
20,
272,
4169,
26,
3330,
614,
199,
199,
3,
2813,
282,
2955,
31363,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
1986,
9468,
272,
3384,
63,
1562,
26,
413,
14,
18,
14,
19,
14,
20,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2595,
199,
344,
26,
523,
1369,
26,
11134,
402,
314,
3384,
63,
1562,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
282,
22,
70,
23,
65,
21,
3003,
13,
2824,
70,
24,
13,
845,
69,
21,
13,
65,
12768,
13,
771,
556,
27763,
25193,
25,
70,
199,
711,
63,
1562,
26,
523,
1369,
26,
1684,
3531,
2287,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
413,
14,
18,
14,
19,
14,
20,
199,
2611,
63,
354,
26,
523,
1369,
26,
2812,
402,
314,
5791,
6844,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3330,
13,
614,
199,
2611,
63,
2918,
63,
354,
26,
523,
1369,
26,
12175,
536,
402,
314,
5791,
6844,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3330,
13,
614,
199,
2611,
63,
10409,
63,
711,
26,
523,
1369,
26,
3531,
402,
314,
5791,
6844,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
4893,
14,
2182,
14,
11024,
199,
2619,
26,
523,
1369,
26,
2812,
402,
5718,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
682,
13,
71,
3042,
13,
18,
199,
1715,
26,
523,
1369,
26,
2812,
402,
2199,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
24114,
199,
2048,
26,
523,
1369,
26,
9973,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
2893,
2933,
199,
2261,
26,
523,
1369,
26,
14061,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
2893,
2881,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
4091,
2340,
492,
334,
272,
2622,
24404,
12,
272,
7117,
63,
2094,
63,
1650,
12,
272,
7117,
63,
2427,
63,
6314,
12,
199,
9,
421,
199,
533,
2622,
24404,
9278,
23604,
8
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
334,
67,
9,
6900,
12,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
7117,
63,
1986,
9468,
199,
3612,
63,
1802,
26,
21612,
2955,
31363,
83,
641,
3668,
8142,
4851,
4079,
2463,
14577,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
436,
2813,
2955,
31363,
83,
14,
199,
1023,
63,
3270,
26,
283,
18,
14,
16,
7,
199,
2502,
26,
298,
5349,
5741,
3930,
332,
8593,
470,
573,
2924,
199,
1419,
26,
523,
3384,
63,
1562,
26,
272,
1369,
26,
489,
446,
1684,
3531,
2287,
314,
2955,
31363,
365,
7943,
370,
14,
272,
1415,
26,
2549,
523,
4169,
26,
272,
1369,
26,
489,
446,
2812,
402,
5791,
6844,
1314,
781,
1852,
314,
2955,
31363,
367,
14,
489,
446,
11105,
340,
445,
8,
929,
29,
1881,
680,
523,
4169,
63,
10409,
63,
711,
26,
272,
1369,
26,
489,
446,
7525,
13980,
31265,
13851,
3531,
2287,
367,
314,
2955,
31363,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
889,
7,
523,
2784,
26,
272,
1369,
26,
489,
446,
7220,
314,
3531,
2287,
365,
4048,
370,
14,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
12830,
26,
272,
1369,
26,
489,
446,
19209,
314,
2784,
4048,
370,
14,
272,
1015,
63,
3270,
26,
298,
18,
14,
19,
2,
523,
1174,
26,
272,
1369,
26,
489,
446,
8511,
402,
314,
2955,
31363,
14,
272,
849,
26,
283,
1881,
7,
272,
3415,
26,
359,
283,
1881,
297,
283,
5575,
7,
1622,
523,
2881,
26,
272,
1369,
26,
489,
446,
14061,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2933,
26,
272,
1369,
26,
489,
446,
9973,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2199,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
2199,
314,
2955,
31363,
365,
4048,
370,
14,
523,
5718,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
5718,
315,
1314,
314,
5791,
6844,
365,
315,
14,
489,
446,
982,
440,
663,
12,
849,
5718,
365,
1202,
14,
523,
11271,
63,
4146,
26,
272,
1369,
26,
489,
446,
25306,
5316,
9643,
5133,
3906,
965,
9158,
14,
272,
730,
26,
2155,
272,
849,
26,
283,
5066,
7,
199,
11036,
63,
9970,
63,
7677,
26,
8002,
2340,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
1218,
282,
2955,
31363,
26,
413,
14,
18,
14,
19,
14,
20,
1035,
3330,
614,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
1986,
9468,
272,
3384,
63,
1562,
26,
413,
14,
18,
14,
19,
14,
20,
272,
4169,
26,
3330,
614,
199,
199,
3,
2813,
282,
2955,
31363,
199,
13,
2257,
63,
1287,
26,
272,
859,
26,
7117,
63,
1986,
9468,
272,
3384,
63,
1562,
26,
413,
14,
18,
14,
19,
14,
20,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2595,
199,
344,
26,
523,
1369,
26,
11134,
402,
314,
3384,
63,
1562,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
282,
22,
70,
23,
65,
21,
3003,
13,
2824,
70,
24,
13,
845,
69,
21,
13,
65,
12768,
13,
771,
556,
27763,
25193,
25,
70,
199,
711,
63,
1562,
26,
523,
1369,
26,
1684,
3531,
2287,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
413,
14,
18,
14,
19,
14,
20,
199,
2611,
63,
354,
26,
523,
1369,
26,
2812,
402,
314,
5791,
6844,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3330,
13,
614,
199,
2611,
63,
2918,
63,
354,
26,
523,
1369,
26,
12175,
536,
402,
314,
5791,
6844,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
3330,
13,
614,
199,
2611,
63,
10409,
63,
711,
26,
523,
1369,
26,
3531,
402,
314,
5791,
6844,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
1616,
14,
4893,
14,
2182,
14,
11024,
199,
2619,
26,
523,
1369,
26,
2812,
402,
5718,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
682,
13,
71,
3042,
13,
18,
199,
1715,
26,
523,
1369,
26,
2812,
402,
2199,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
24114,
199,
2048,
26,
523,
1369,
26,
9973,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
2893,
2933,
199,
2261,
26,
523,
1369,
26,
14061,
314,
2955,
31363,
365,
4048,
370,
14,
523,
2138,
26,
3182,
523,
730,
26,
1059,
523,
2690,
26,
2893,
2881,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
4091,
2340,
492,
334,
272,
2622,
24404,
12,
272,
7117,
63,
2094,
63,
1650,
12,
272,
7117,
63,
2427,
63,
6314,
12,
199,
9,
421,
199,
533,
2622,
24404,
9278,
23604,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ests/test_jinja2.py
|
9
|
1588
|
from __future__ import absolute_import, unicode_literals
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.template import engines
from django.test import TestCase
from wagtail.wagtailcore.models import PAGE_TEMPLATE_VAR, Page, Site
class TestCoreJinja(TestCase):
def setUp(self):
self.engine = engines['jinja2']
self.user = get_user_model().objects.create_superuser(
username='test',
email='test@email.com',
password='password'
)
self.homepage = Page.objects.get(id=2)
def render(self, string, context=None, request_context=True):
if context is None:
context = {}
template = self.engine.from_string(string)
return template.render(context)
def dummy_request(self, user=None):
site = Site.objects.get(is_default_site=True)
request = self.client.get('/')
request.site = site
request.user = user or AnonymousUser()
return request
def test_userbar(self):
content = self.render('{{ wagtailuserbar() }}', {
PAGE_TEMPLATE_VAR: self.homepage,
'request': self.dummy_request(self.user)})
self.assertIn("<!-- Wagtail user bar embed code -->", content)
def test_userbar_anonymous_user(self):
content = self.render('{{ wagtailuserbar() }}', {
PAGE_TEMPLATE_VAR: self.homepage,
'request': self.dummy_request()})
# Make sure nothing was rendered
self.assertEqual(content, '')
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
199,
504,
1639,
14,
1160,
492,
28156,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
7328,
14,
31439,
14,
992,
492,
510,
2962,
63,
7433,
63,
5568,
12,
10331,
12,
11666,
421,
199,
533,
1379,
5402,
42,
4135,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3908,
275,
28156,
459,
12264,
18,
418,
398,
291,
14,
751,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
11434,
8,
288,
3434,
534,
396,
297,
288,
3031,
534,
396,
32,
2123,
14,
957,
297,
288,
2505,
534,
2060,
7,
267,
776,
267,
291,
14,
25539,
275,
10331,
14,
1462,
14,
362,
8,
344,
29,
18,
9,
339,
347,
3795,
8,
277,
12,
1059,
12,
1067,
29,
403,
12,
1056,
63,
1100,
29,
549,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
398,
1978,
275,
291,
14,
3908,
14,
504,
63,
875,
8,
875,
9,
267,
372,
1978,
14,
3352,
8,
1100,
9,
339,
347,
7283,
63,
1069,
8,
277,
12,
922,
29,
403,
304,
267,
4770,
275,
11666,
14,
1462,
14,
362,
8,
374,
63,
885,
63,
2124,
29,
549,
9,
398,
1056,
275,
291,
14,
1258,
14,
362,
7825,
267,
1056,
14,
2124,
275,
4770,
267,
1056,
14,
751,
275,
922,
503,
29952,
342,
267,
372,
1056,
339,
347,
511,
63,
751,
1700,
8,
277,
304,
267,
1564,
275,
291,
14,
3352,
18976,
7328,
751,
1700,
342,
23688,
469,
288,
510,
2962,
63,
7433,
63,
5568,
26,
291,
14,
25539,
12,
288,
283,
1069,
356,
291,
14,
5869,
63,
1069,
8,
277,
14,
751,
11466,
267,
291,
14,
4080,
6757,
17722,
644,
6396,
922,
4681,
6441,
1233,
1553,
7166,
1564,
9,
339,
347,
511,
63,
751,
1700,
63,
12628,
63,
751,
8,
277,
304,
267,
1564,
275,
291,
14,
3352,
18976,
7328,
751,
1700,
342,
23688,
469,
288,
510,
2962,
63,
7433,
63,
5568,
26,
291,
14,
25539,
12,
288,
283,
1069,
356,
291,
14,
5869,
63,
1069,
22804,
398,
327,
4155,
3238,
6548,
1990,
8018,
267,
291,
14,
629,
8,
1317,
12,
4074,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
199,
504,
1639,
14,
1160,
492,
28156,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
7328,
14,
31439,
14,
992,
492,
510,
2962,
63,
7433,
63,
5568,
12,
10331,
12,
11666,
421,
199,
533,
1379,
5402,
42,
4135,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3908,
275,
28156,
459,
12264,
18,
418,
398,
291,
14,
751,
275,
664,
63,
751,
63,
1238,
1252,
1462,
14,
981,
63,
11434,
8,
288,
3434,
534,
396,
297,
288,
3031,
534,
396,
32,
2123,
14,
957,
297,
288,
2505,
534,
2060,
7,
267,
776,
267,
291,
14,
25539,
275,
10331,
14,
1462,
14,
362,
8,
344,
29,
18,
9,
339,
347,
3795,
8,
277,
12,
1059,
12,
1067,
29,
403,
12,
1056,
63,
1100,
29,
549,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
398,
1978,
275,
291,
14,
3908,
14,
504,
63,
875,
8,
875,
9,
267,
372,
1978,
14,
3352,
8,
1100,
9,
339,
347,
7283,
63,
1069,
8,
277,
12,
922,
29,
403,
304,
267,
4770,
275,
11666,
14,
1462,
14,
362,
8,
374,
63,
885,
63,
2124,
29,
549,
9,
398,
1056,
275,
291,
14,
1258,
14,
362,
7825,
267,
1056,
14,
2124,
275,
4770,
267,
1056,
14,
751,
275,
922,
503,
29952,
342,
267,
372,
1056,
339,
347,
511,
63,
751,
1700,
8,
277,
304,
267,
1564,
275,
291,
14,
3352,
18976,
7328,
751,
1700,
342,
23688,
469,
288,
510,
2962,
63,
7433,
63,
5568,
26,
291,
14,
25539,
12,
288,
283,
1069,
356,
291,
14,
5869,
63,
1069,
8,
277,
14,
751,
11466,
267,
291,
14,
4080,
6757,
17722,
644,
6396,
922,
4681,
6441,
1233,
1553,
7166,
1564,
9,
339,
347,
511,
63,
751,
1700,
63,
12628,
63,
751,
8,
277,
304,
267,
1564,
275,
291,
14,
3352,
18976,
7328,
751,
1700,
342,
23688,
469,
288,
510,
2962,
63,
7433,
63,
5568,
26,
291,
14,
25539,
12,
288,
283,
1069,
356,
291,
14,
5869,
63,
1069,
22804,
398,
327,
4155,
3238,
6548,
1990,
8018,
267,
291,
14,
629,
8,
1317,
12,
4074,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
LEPT-Development/android_kernel_lge_f6mt
|
tools/perf/util/setup.py
|
4998
|
1330
|
#!/usr/bin/python2
from distutils.core import setup, Extension
from os import getenv
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.install_lib import install_lib as _install_lib
class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
self.build_lib = build_lib
self.build_temp = build_tmp
class install_lib(_install_lib):
def finalize_options(self):
_install_lib.finalize_options(self)
self.build_dir = build_lib
cflags = ['-fno-strict-aliasing', '-Wno-write-strings']
cflags += getenv('CFLAGS', '').split()
build_lib = getenv('PYTHON_EXTBUILD_LIB')
build_tmp = getenv('PYTHON_EXTBUILD_TMP')
ext_sources = [f.strip() for f in file('util/python-ext-sources')
if len(f.strip()) > 0 and f[0] != '#']
perf = Extension('perf',
sources = ext_sources,
include_dirs = ['util/include'],
extra_compile_args = cflags,
)
setup(name='perf',
version='0.1',
description='Interface with the Linux profiling infrastructure',
author='Arnaldo Carvalho de Melo',
author_email='acme@redhat.com',
license='GPLv2',
url='http://perf.wiki.kernel.org',
ext_modules=[perf],
cmdclass={'build_ext': build_ext, 'install_lib': install_lib})
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
199,
199,
504,
7065,
14,
1018,
492,
3272,
12,
13282,
199,
504,
747,
492,
29626,
199,
199,
504,
7065,
14,
1531,
14,
1506,
63,
832,
257,
492,
1900,
63,
832,
257,
465,
485,
1506,
63,
832,
199,
504,
7065,
14,
1531,
14,
3174,
63,
773,
492,
3907,
63,
773,
465,
485,
3174,
63,
773,
199,
199,
533,
1900,
63,
832,
1547,
1506,
63,
832,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
773,
221,
275,
1900,
63,
773,
267,
291,
14,
1506,
63,
808,
275,
1900,
63,
2791,
199,
199,
533,
3907,
63,
773,
1547,
3174,
63,
773,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
3174,
63,
773,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
694,
275,
1900,
63,
773,
421,
199,
14002,
275,
11573,
70,
889,
13,
4768,
13,
3620,
316,
297,
2475,
55,
889,
13,
952,
13,
5465,
418,
199,
14002,
847,
29626,
360,
14804,
297,
12548,
1294,
342,
199,
199,
1506,
63,
773,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
5617,
358,
199,
1506,
63,
2791,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
17983,
358,
199,
199,
832,
63,
4553,
275,
359,
70,
14,
1913,
342,
367,
289,
315,
570,
360,
1974,
15,
1548,
13,
832,
13,
4553,
358,
1585,
198,
692,
822,
8,
70,
14,
1913,
1012,
690,
378,
436,
289,
59,
16,
61,
1137,
3943,
418,
199,
199,
9452,
275,
13282,
360,
9452,
297,
29294,
5274,
275,
1599,
63,
4553,
12,
29294,
2387,
63,
3220,
275,
788,
1974,
15,
2613,
995,
29294,
2402,
63,
2014,
63,
589,
275,
13426,
12,
326,
776,
199,
199,
2758,
8,
354,
534,
9452,
297,
489,
1015,
534,
16,
14,
17,
297,
489,
1369,
534,
4267,
543,
314,
10130,
30238,
28890,
6976,
297,
489,
4132,
534,
20498,
279,
1117,
14243,
637,
526,
477,
3194,
320,
297,
489,
4132,
63,
2123,
534,
18107,
32,
17164,
14,
957,
297,
489,
4190,
534,
28863,
18,
297,
489,
1166,
534,
1014,
921,
9452,
14,
6797,
14,
4989,
14,
1308,
297,
489,
1599,
63,
3112,
1524,
9452,
467,
489,
2088,
533,
3713,
1506,
63,
832,
356,
1900,
63,
832,
12,
283,
3174,
63,
773,
356,
3907,
63,
773,
1552,
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
] |
[
2647,
15,
1393,
15,
1548,
18,
199,
199,
504,
7065,
14,
1018,
492,
3272,
12,
13282,
199,
504,
747,
492,
29626,
199,
199,
504,
7065,
14,
1531,
14,
1506,
63,
832,
257,
492,
1900,
63,
832,
257,
465,
485,
1506,
63,
832,
199,
504,
7065,
14,
1531,
14,
3174,
63,
773,
492,
3907,
63,
773,
465,
485,
3174,
63,
773,
199,
199,
533,
1900,
63,
832,
1547,
1506,
63,
832,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
773,
221,
275,
1900,
63,
773,
267,
291,
14,
1506,
63,
808,
275,
1900,
63,
2791,
199,
199,
533,
3907,
63,
773,
1547,
3174,
63,
773,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
3174,
63,
773,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
694,
275,
1900,
63,
773,
421,
199,
14002,
275,
11573,
70,
889,
13,
4768,
13,
3620,
316,
297,
2475,
55,
889,
13,
952,
13,
5465,
418,
199,
14002,
847,
29626,
360,
14804,
297,
12548,
1294,
342,
199,
199,
1506,
63,
773,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
5617,
358,
199,
1506,
63,
2791,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
17983,
358,
199,
199,
832,
63,
4553,
275,
359,
70,
14,
1913,
342,
367,
289,
315,
570,
360,
1974,
15,
1548,
13,
832,
13,
4553,
358,
1585,
198,
692,
822,
8,
70,
14,
1913,
1012,
690,
378,
436,
289,
59,
16,
61,
1137,
3943,
418,
199,
199,
9452,
275,
13282,
360,
9452,
297,
29294,
5274,
275,
1599,
63,
4553,
12,
29294,
2387,
63,
3220,
275,
788,
1974,
15,
2613,
995,
29294,
2402,
63,
2014,
63,
589,
275,
13426,
12,
326,
776,
199,
199,
2758,
8,
354,
534,
9452,
297,
489,
1015,
534,
16,
14,
17,
297,
489,
1369,
534,
4267,
543,
314,
10130,
30238,
28890,
6976,
297,
489,
4132,
534,
20498,
279,
1117,
14243,
637,
526,
477,
3194,
320,
297,
489,
4132,
63,
2123,
534,
18107,
32,
17164,
14,
957,
297,
489,
4190,
534,
28863,
18,
297,
489,
1166,
534,
1014,
921,
9452,
14,
6797,
14,
4989,
14,
1308,
297,
489,
1599,
63,
3112,
1524,
9452,
467,
489,
2088,
533,
3713,
1506,
63,
832,
356,
1900,
63,
832,
12,
283,
3174,
63,
773,
356,
3907,
63,
773,
1552,
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,
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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
] |
CamelBackNotation/CarnotKE
|
jyhton/lib-python/2.7/test/test_zlib.py
|
45
|
22321
|
import unittest
from test.test_support import TESTFN, run_unittest, import_module, unlink, requires
import binascii
import random
from test.test_support import precisionbigmemtest, _1G, _4G
import sys
try:
import mmap
except ImportError:
mmap = None
zlib = import_module('zlib')
class ChecksumTestCase(unittest.TestCase):
# checksum test cases
def test_crc32start(self):
self.assertEqual(zlib.crc32(""), zlib.crc32("", 0))
self.assertTrue(zlib.crc32("abc", 0xffffffff))
def test_crc32empty(self):
self.assertEqual(zlib.crc32("", 0), 0)
self.assertEqual(zlib.crc32("", 1), 1)
self.assertEqual(zlib.crc32("", 432), 432)
def test_adler32start(self):
self.assertEqual(zlib.adler32(""), zlib.adler32("", 1))
self.assertTrue(zlib.adler32("abc", 0xffffffff))
def test_adler32empty(self):
self.assertEqual(zlib.adler32("", 0), 0)
self.assertEqual(zlib.adler32("", 1), 1)
self.assertEqual(zlib.adler32("", 432), 432)
def assertEqual32(self, seen, expected):
# 32-bit values masked -- checksums on 32- vs 64- bit machines
# This is important if bit 31 (0x08000000L) is set.
self.assertEqual(seen & 0x0FFFFFFFFL, expected & 0x0FFFFFFFFL)
def test_penguins(self):
self.assertEqual32(zlib.crc32("penguin", 0), 0x0e5c1a120L)
self.assertEqual32(zlib.crc32("penguin", 1), 0x43b6aa94)
self.assertEqual32(zlib.adler32("penguin", 0), 0x0bcf02f6)
self.assertEqual32(zlib.adler32("penguin", 1), 0x0bd602f7)
self.assertEqual(zlib.crc32("penguin"), zlib.crc32("penguin", 0))
self.assertEqual(zlib.adler32("penguin"),zlib.adler32("penguin",1))
def test_abcdefghijklmnop(self):
"""test issue1202 compliance: signed crc32, adler32 in 2.x"""
foo = 'abcdefghijklmnop'
# explicitly test signed behavior
self.assertEqual(zlib.crc32(foo), -1808088941)
self.assertEqual(zlib.crc32('spam'), 1138425661)
self.assertEqual(zlib.adler32(foo+foo), -721416943)
self.assertEqual(zlib.adler32('spam'), 72286642)
def test_same_as_binascii_crc32(self):
foo = 'abcdefghijklmnop'
self.assertEqual(binascii.crc32(foo), zlib.crc32(foo))
self.assertEqual(binascii.crc32('spam'), zlib.crc32('spam'))
def test_negative_crc_iv_input(self):
# The range of valid input values for the crc state should be
# -2**31 through 2**32-1 to allow inputs artifically constrained
# to a signed 32-bit integer.
self.assertEqual(zlib.crc32('ham', -1), zlib.crc32('ham', 0xffffffffL))
self.assertEqual(zlib.crc32('spam', -3141593),
zlib.crc32('spam', 0xffd01027L))
self.assertEqual(zlib.crc32('spam', -(2**31)),
zlib.crc32('spam', (2**31)))
class ExceptionTestCase(unittest.TestCase):
# make sure we generate some expected errors
def test_badlevel(self):
# specifying compression level out of range causes an error
# (but -1 is Z_DEFAULT_COMPRESSION and apparently the zlib
# accepts 0 too)
self.assertRaises(zlib.error, zlib.compress, 'ERROR', 10)
def test_badcompressobj(self):
# verify failure on building compress object with bad params
self.assertRaises(ValueError, zlib.compressobj, 1, zlib.DEFLATED, 0)
# specifying total bits too large causes an error
self.assertRaises(ValueError,
zlib.compressobj, 1, zlib.DEFLATED, zlib.MAX_WBITS + 1)
def test_baddecompressobj(self):
# verify failure on building decompress object with bad params
self.assertRaises(ValueError, zlib.decompressobj, -1)
def test_decompressobj_badflush(self):
# verify failure on calling decompressobj.flush with bad params
self.assertRaises(ValueError, zlib.decompressobj().flush, 0)
self.assertRaises(ValueError, zlib.decompressobj().flush, -1)
class BaseCompressTestCase(object):
def check_big_compress_buffer(self, size, compress_func):
_1M = 1024 * 1024
fmt = "%%0%dx" % (2 * _1M)
# Generate 10MB worth of random, and expand it by repeating it.
# The assumption is that zlib's memory is not big enough to exploit
# such spread out redundancy.
data = ''.join([binascii.a2b_hex(fmt % random.getrandbits(8 * _1M))
for i in range(10)])
data = data * (size // len(data) + 1)
try:
compress_func(data)
finally:
# Release memory
data = None
def check_big_decompress_buffer(self, size, decompress_func):
data = 'x' * size
try:
compressed = zlib.compress(data, 1)
finally:
# Release memory
data = None
data = decompress_func(compressed)
# Sanity check
try:
self.assertEqual(len(data), size)
self.assertEqual(len(data.strip('x')), 0)
finally:
data = None
class CompressTestCase(BaseCompressTestCase, unittest.TestCase):
# Test compression in one go (whole message compression)
def test_speech(self):
x = zlib.compress(HAMLET_SCENE)
self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
def test_speech128(self):
# compress more data
data = HAMLET_SCENE * 128
x = zlib.compress(data)
self.assertEqual(zlib.decompress(x), data)
def test_incomplete_stream(self):
# An useful error message is given
x = zlib.compress(HAMLET_SCENE)
self.assertRaisesRegexp(zlib.error,
"Error -5 while decompressing data: incomplete or truncated stream",
zlib.decompress, x[:-1])
# Memory use of the following functions takes into account overallocation
@precisionbigmemtest(size=_1G + 1024 * 1024, memuse=3)
def test_big_compress_buffer(self, size):
compress = lambda s: zlib.compress(s, 1)
self.check_big_compress_buffer(size, compress)
@precisionbigmemtest(size=_1G + 1024 * 1024, memuse=2)
def test_big_decompress_buffer(self, size):
self.check_big_decompress_buffer(size, zlib.decompress)
class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
# Test compression object
def test_pair(self):
# straightforward compress/decompress objects
data = HAMLET_SCENE * 128
co = zlib.compressobj()
x1 = co.compress(data)
x2 = co.flush()
self.assertRaises(zlib.error, co.flush) # second flush should not work
dco = zlib.decompressobj()
y1 = dco.decompress(x1 + x2)
y2 = dco.flush()
self.assertEqual(data, y1 + y2)
def test_compressoptions(self):
# specify lots of options to compressobj()
level = 2
method = zlib.DEFLATED
wbits = -12
memlevel = 9
strategy = zlib.Z_FILTERED
co = zlib.compressobj(level, method, wbits, memlevel, strategy)
x1 = co.compress(HAMLET_SCENE)
x2 = co.flush()
dco = zlib.decompressobj(wbits)
y1 = dco.decompress(x1 + x2)
y2 = dco.flush()
self.assertEqual(HAMLET_SCENE, y1 + y2)
def test_compressincremental(self):
# compress object in steps, decompress object as one-shot
data = HAMLET_SCENE * 128
co = zlib.compressobj()
bufs = []
for i in range(0, len(data), 256):
bufs.append(co.compress(data[i:i+256]))
bufs.append(co.flush())
combuf = ''.join(bufs)
dco = zlib.decompressobj()
y1 = dco.decompress(''.join(bufs))
y2 = dco.flush()
self.assertEqual(data, y1 + y2)
def test_decompinc(self, flush=False, source=None, cx=256, dcx=64):
# compress object in steps, decompress object in steps
source = source or HAMLET_SCENE
data = source * 128
co = zlib.compressobj()
bufs = []
for i in range(0, len(data), cx):
bufs.append(co.compress(data[i:i+cx]))
bufs.append(co.flush())
combuf = ''.join(bufs)
self.assertEqual(data, zlib.decompress(combuf))
dco = zlib.decompressobj()
bufs = []
for i in range(0, len(combuf), dcx):
bufs.append(dco.decompress(combuf[i:i+dcx]))
self.assertEqual('', dco.unconsumed_tail, ########
"(A) uct should be '': not %d long" %
len(dco.unconsumed_tail))
if flush:
bufs.append(dco.flush())
else:
while True:
chunk = dco.decompress('')
if chunk:
bufs.append(chunk)
else:
break
self.assertEqual('', dco.unconsumed_tail, ########
"(B) uct should be '': not %d long" %
len(dco.unconsumed_tail))
self.assertEqual(data, ''.join(bufs))
# Failure means: "decompressobj with init options failed"
def test_decompincflush(self):
self.test_decompinc(flush=True)
def test_decompimax(self, source=None, cx=256, dcx=64):
# compress in steps, decompress in length-restricted steps
source = source or HAMLET_SCENE
# Check a decompression object with max_length specified
data = source * 128
co = zlib.compressobj()
bufs = []
for i in range(0, len(data), cx):
bufs.append(co.compress(data[i:i+cx]))
bufs.append(co.flush())
combuf = ''.join(bufs)
self.assertEqual(data, zlib.decompress(combuf),
'compressed data failure')
dco = zlib.decompressobj()
bufs = []
cb = combuf
while cb:
#max_length = 1 + len(cb)//10
chunk = dco.decompress(cb, dcx)
self.assertFalse(len(chunk) > dcx,
'chunk too big (%d>%d)' % (len(chunk), dcx))
bufs.append(chunk)
cb = dco.unconsumed_tail
bufs.append(dco.flush())
self.assertEqual(data, ''.join(bufs), 'Wrong data retrieved')
def test_decompressmaxlen(self, flush=False):
# Check a decompression object with max_length specified
data = HAMLET_SCENE * 128
co = zlib.compressobj()
bufs = []
for i in range(0, len(data), 256):
bufs.append(co.compress(data[i:i+256]))
bufs.append(co.flush())
combuf = ''.join(bufs)
self.assertEqual(data, zlib.decompress(combuf),
'compressed data failure')
dco = zlib.decompressobj()
bufs = []
cb = combuf
while cb:
max_length = 1 + len(cb)//10
chunk = dco.decompress(cb, max_length)
self.assertFalse(len(chunk) > max_length,
'chunk too big (%d>%d)' % (len(chunk),max_length))
bufs.append(chunk)
cb = dco.unconsumed_tail
if flush:
bufs.append(dco.flush())
else:
while chunk:
chunk = dco.decompress('', max_length)
self.assertFalse(len(chunk) > max_length,
'chunk too big (%d>%d)' % (len(chunk),max_length))
bufs.append(chunk)
self.assertEqual(data, ''.join(bufs), 'Wrong data retrieved')
def test_decompressmaxlenflush(self):
self.test_decompressmaxlen(flush=True)
def test_maxlenmisc(self):
# Misc tests of max_length
dco = zlib.decompressobj()
self.assertRaises(ValueError, dco.decompress, "", -1)
self.assertEqual('', dco.unconsumed_tail)
def test_clear_unconsumed_tail(self):
# Issue #12050: calling decompress() without providing max_length
# should clear the unconsumed_tail attribute.
cdata = "x\x9cKLJ\x06\x00\x02M\x01" # "abc"
dco = zlib.decompressobj()
ddata = dco.decompress(cdata, 1)
ddata += dco.decompress(dco.unconsumed_tail)
self.assertEqual(dco.unconsumed_tail, "")
def test_flushes(self):
# Test flush() with the various options, using all the
# different levels in order to provide more variations.
sync_opt = ['Z_NO_FLUSH', 'Z_SYNC_FLUSH', 'Z_FULL_FLUSH']
sync_opt = [getattr(zlib, opt) for opt in sync_opt
if hasattr(zlib, opt)]
data = HAMLET_SCENE * 8
for sync in sync_opt:
for level in range(10):
obj = zlib.compressobj( level )
a = obj.compress( data[:3000] )
b = obj.flush( sync )
c = obj.compress( data[3000:] )
d = obj.flush()
self.assertEqual(zlib.decompress(''.join([a,b,c,d])),
data, ("Decompress failed: flush "
"mode=%i, level=%i") % (sync, level))
del obj
def test_odd_flush(self):
# Test for odd flushing bugs noted in 2.0, and hopefully fixed in 2.1
import random
if hasattr(zlib, 'Z_SYNC_FLUSH'):
# Testing on 17K of "random" data
# Create compressor and decompressor objects
co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
dco = zlib.decompressobj()
# Try 17K of data
# generate random data stream
try:
# In 2.3 and later, WichmannHill is the RNG of the bug report
gen = random.WichmannHill()
except AttributeError:
try:
# 2.2 called it Random
gen = random.Random()
except AttributeError:
# others might simply have a single RNG
gen = random
gen.seed(1)
data = genblock(1, 17 * 1024, generator=gen)
# compress, sync-flush, and decompress
first = co.compress(data)
second = co.flush(zlib.Z_SYNC_FLUSH)
expanded = dco.decompress(first + second)
# if decompressed data is different from the input data, choke.
self.assertEqual(expanded, data, "17K random source doesn't match")
def test_empty_flush(self):
# Test that calling .flush() on unused objects works.
# (Bug #1083110 -- calling .flush() on decompress objects
# caused a core dump.)
co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
self.assertTrue(co.flush()) # Returns a zlib header
dco = zlib.decompressobj()
self.assertEqual(dco.flush(), "") # Returns nothing
def test_decompress_incomplete_stream(self):
# This is 'foo', deflated
x = 'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E'
# For the record
self.assertEqual(zlib.decompress(x), 'foo')
self.assertRaises(zlib.error, zlib.decompress, x[:-5])
# Omitting the stream end works with decompressor objects
# (see issue #8672).
dco = zlib.decompressobj()
y = dco.decompress(x[:-5])
y += dco.flush()
self.assertEqual(y, 'foo')
def test_flush_with_freed_input(self):
# Issue #16411: decompressor accesses input to last decompress() call
# in flush(), even if this object has been freed in the meanwhile.
input1 = 'abcdefghijklmnopqrstuvwxyz'
input2 = 'QWERTYUIOPASDFGHJKLZXCVBNM'
data = zlib.compress(input1)
dco = zlib.decompressobj()
dco.decompress(data, 1)
del data
data = zlib.compress(input2)
self.assertEqual(dco.flush(), input1[1:])
if hasattr(zlib.compressobj(), "copy"):
def test_compresscopy(self):
# Test copying a compression object
data0 = HAMLET_SCENE
data1 = HAMLET_SCENE.swapcase()
c0 = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
bufs0 = []
bufs0.append(c0.compress(data0))
c1 = c0.copy()
bufs1 = bufs0[:]
bufs0.append(c0.compress(data0))
bufs0.append(c0.flush())
s0 = ''.join(bufs0)
bufs1.append(c1.compress(data1))
bufs1.append(c1.flush())
s1 = ''.join(bufs1)
self.assertEqual(zlib.decompress(s0),data0+data0)
self.assertEqual(zlib.decompress(s1),data0+data1)
def test_badcompresscopy(self):
# Test copying a compression object in an inconsistent state
c = zlib.compressobj()
c.compress(HAMLET_SCENE)
c.flush()
self.assertRaises(ValueError, c.copy)
def test_decompress_unused_data(self):
# Repeated calls to decompress() after EOF should accumulate data in
# dco.unused_data, instead of just storing the arg to the last call.
source = b'abcdefghijklmnopqrstuvwxyz'
remainder = b'0123456789'
y = zlib.compress(source)
x = y + remainder
for maxlen in 0, 1000:
for step in 1, 2, len(y), len(x):
dco = zlib.decompressobj()
data = b''
for i in range(0, len(x), step):
if i < len(y):
self.assertEqual(dco.unused_data, b'')
if maxlen == 0:
data += dco.decompress(x[i : i + step])
self.assertEqual(dco.unconsumed_tail, b'')
else:
data += dco.decompress(
dco.unconsumed_tail + x[i : i + step], maxlen)
data += dco.flush()
self.assertEqual(data, source)
self.assertEqual(dco.unconsumed_tail, b'')
self.assertEqual(dco.unused_data, remainder)
if hasattr(zlib.decompressobj(), "copy"):
def test_decompresscopy(self):
# Test copying a decompression object
data = HAMLET_SCENE
comp = zlib.compress(data)
d0 = zlib.decompressobj()
bufs0 = []
bufs0.append(d0.decompress(comp[:32]))
d1 = d0.copy()
bufs1 = bufs0[:]
bufs0.append(d0.decompress(comp[32:]))
s0 = ''.join(bufs0)
bufs1.append(d1.decompress(comp[32:]))
s1 = ''.join(bufs1)
self.assertEqual(s0,s1)
self.assertEqual(s0,data)
def test_baddecompresscopy(self):
# Test copying a compression object in an inconsistent state
data = zlib.compress(HAMLET_SCENE)
d = zlib.decompressobj()
d.decompress(data)
d.flush()
self.assertRaises(ValueError, d.copy)
# Memory use of the following functions takes into account overallocation
@precisionbigmemtest(size=_1G + 1024 * 1024, memuse=3)
def test_big_compress_buffer(self, size):
c = zlib.compressobj(1)
compress = lambda s: c.compress(s) + c.flush()
self.check_big_compress_buffer(size, compress)
@precisionbigmemtest(size=_1G + 1024 * 1024, memuse=2)
def test_big_decompress_buffer(self, size):
d = zlib.decompressobj()
decompress = lambda s: d.decompress(s) + d.flush()
self.check_big_decompress_buffer(size, decompress)
def genblock(seed, length, step=1024, generator=random):
"""length-byte stream of random data from a seed (in step-byte blocks)."""
if seed is not None:
generator.seed(seed)
randint = generator.randint
if length < step or step < 2:
step = length
blocks = []
for i in range(0, length, step):
blocks.append(''.join([chr(randint(0,255))
for x in range(step)]))
return ''.join(blocks)[:length]
def choose_lines(source, number, seed=None, generator=random):
"""Return a list of number lines randomly chosen from the source"""
if seed is not None:
generator.seed(seed)
sources = source.split('\n')
return [generator.choice(sources) for n in range(number)]
HAMLET_SCENE = """
LAERTES
O, fear me not.
I stay too long: but here my father comes.
Enter POLONIUS
A double blessing is a double grace,
Occasion smiles upon a second leave.
LORD POLONIUS
Yet here, Laertes! aboard, aboard, for shame!
The wind sits in the shoulder of your sail,
And you are stay'd for. There; my blessing with thee!
And these few precepts in thy memory
See thou character. Give thy thoughts no tongue,
Nor any unproportioned thought his act.
Be thou familiar, but by no means vulgar.
Those friends thou hast, and their adoption tried,
Grapple them to thy soul with hoops of steel;
But do not dull thy palm with entertainment
Of each new-hatch'd, unfledged comrade. Beware
Of entrance to a quarrel, but being in,
Bear't that the opposed may beware of thee.
Give every man thy ear, but few thy voice;
Take each man's censure, but reserve thy judgment.
Costly thy habit as thy purse can buy,
But not express'd in fancy; rich, not gaudy;
For the apparel oft proclaims the man,
And they in France of the best rank and station
Are of a most select and generous chief in that.
Neither a borrower nor a lender be;
For loan oft loses both itself and friend,
And borrowing dulls the edge of husbandry.
This above all: to thine ownself be true,
And it must follow, as the night the day,
Thou canst not then be false to any man.
Farewell: my blessing season this in thee!
LAERTES
Most humbly do I take my leave, my lord.
LORD POLONIUS
The time invites you; go; your servants tend.
LAERTES
Farewell, Ophelia; and remember well
What I have said to you.
OPHELIA
'Tis in my memory lock'd,
And you yourself shall keep the key of it.
LAERTES
Farewell.
"""
def test_main():
run_unittest(
ChecksumTestCase,
ExceptionTestCase,
CompressTestCase,
CompressObjectTestCase
)
if __name__ == "__main__":
test_main()
|
apache-2.0
|
[
646,
2882,
199,
504,
511,
14,
396,
63,
4058,
492,
25788,
12,
1255,
63,
2796,
12,
492,
63,
578,
12,
17002,
12,
5074,
199,
646,
14755,
199,
646,
2196,
199,
504,
511,
14,
396,
63,
4058,
492,
7151,
5076,
5286,
396,
12,
485,
17,
39,
12,
485,
20,
39,
199,
646,
984,
199,
199,
893,
26,
272,
492,
21991,
199,
2590,
3545,
26,
272,
21991,
275,
488,
199,
199,
15371,
275,
492,
63,
578,
360,
15371,
358,
421,
199,
533,
2670,
1838,
1746,
8,
2796,
14,
1746,
304,
272,
327,
9040,
511,
5560,
272,
347,
511,
63,
13258,
708,
928,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
11986,
395,
12472,
14,
13258,
708,
12398,
378,
430,
267,
291,
14,
1815,
8,
15371,
14,
13258,
708,
480,
3175,
401,
378,
21870,
430,
339,
347,
511,
63,
13258,
708,
1667,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
12398,
378,
395,
378,
9,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
12398,
413,
395,
413,
9,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
12398,
841,
708,
395,
841,
708,
9,
339,
347,
511,
63,
350,
1435,
708,
928,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
11986,
395,
12472,
14,
350,
1435,
708,
12398,
413,
430,
267,
291,
14,
1815,
8,
15371,
14,
350,
1435,
708,
480,
3175,
401,
378,
21870,
430,
339,
347,
511,
63,
350,
1435,
708,
1667,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
12398,
378,
395,
378,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
12398,
413,
395,
413,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
12398,
841,
708,
395,
841,
708,
9,
339,
347,
26400,
708,
8,
277,
12,
6775,
12,
1420,
304,
267,
327,
4337,
13,
2075,
1338,
9742,
1553,
9040,
83,
641,
4337,
13,
8118,
5049,
13,
4546,
20601,
267,
327,
961,
365,
11012,
340,
4546,
7105,
334,
16,
88,
2036,
3273,
44,
9,
365,
663,
14,
267,
291,
14,
629,
8,
8606,
1253,
378,
88,
16,
18073,
44,
12,
1420,
1253,
378,
88,
16,
18073,
44,
9,
339,
347,
511,
63,
897,
6051,
3617,
8,
277,
304,
267,
291,
14,
629,
708,
8,
15371,
14,
13258,
708,
480,
897,
6051,
262,
401,
378,
395,
378,
88,
16,
69,
21,
67,
17,
65,
6708,
44,
9,
267,
291,
14,
629,
708,
8,
15371,
14,
13258,
708,
480,
897,
6051,
262,
401,
413,
395,
378,
88,
2824,
66,
22,
2158,
2635,
9,
267,
291,
14,
629,
708,
8,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
401,
378,
395,
378,
88,
16,
66,
2177,
996,
70,
22,
9,
267,
291,
14,
629,
708,
8,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
401,
413,
395,
378,
88,
16,
3691,
28384,
70,
23,
9,
398,
291,
14,
629,
8,
15371,
14,
13258,
708,
480,
897,
6051,
262,
1288,
12472,
14,
13258,
708,
480,
897,
6051,
262,
401,
378,
430,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
1288,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
401,
17,
430,
339,
347,
511,
63,
22017,
8,
277,
304,
267,
408,
396,
4976,
713,
996,
4151,
26,
10514,
18080,
708,
12,
1503,
1435,
708,
315,
499,
14,
88,
624,
267,
3925,
275,
283,
22017,
7,
267,
327,
7662,
511,
10514,
5953,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
8,
1421,
395,
446,
7663,
1257,
1299,
30308,
9,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
8283,
659,
24073,
1349,
821,
19528,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
8,
1421,
11,
1421,
395,
446,
2819,
1079,
975,
28163,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
360,
8283,
659,
1520,
1081,
1184,
15463,
9,
339,
347,
511,
63,
7191,
63,
305,
63,
27460,
63,
13258,
708,
8,
277,
304,
267,
3925,
275,
283,
22017,
7,
267,
291,
14,
629,
8,
27460,
14,
13258,
708,
8,
1421,
395,
12472,
14,
13258,
708,
8,
1421,
430,
267,
291,
14,
629,
8,
27460,
14,
13258,
708,
360,
8283,
659,
12472,
14,
13258,
708,
360,
8283,
1333,
339,
347,
511,
63,
7371,
63,
13258,
63,
1003,
63,
1210,
8,
277,
304,
267,
327,
710,
1425,
402,
1686,
1324,
1338,
367,
314,
18080,
1174,
1077,
506,
267,
327,
446,
18,
538,
2192,
4012,
499,
538,
708,
13,
17,
370,
2040,
4153,
601,
22563,
1183,
28483,
267,
327,
370,
282,
10514,
4337,
13,
2075,
3000,
14,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
10670,
297,
446,
17,
395,
12472,
14,
13258,
708,
360,
10670,
297,
378,
21870,
44,
430,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
8283,
297,
446,
8988,
1046,
3129,
395,
586,
12472,
14,
13258,
708,
360,
8283,
297,
221,
378,
3581,
68,
614,
14218,
44,
430,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
8283,
297,
24953,
18,
538,
2192,
1826,
586,
12472,
14,
13258,
708,
360,
8283,
297,
221,
334,
18,
538,
2192,
1724,
421,
199,
533,
2186,
1746,
8,
2796,
14,
1746,
304,
272,
327,
1852,
3238,
781,
3550,
2005,
1420,
2552,
272,
347,
511,
63,
4087,
1896,
8,
277,
304,
267,
327,
9176,
10291,
2166,
734,
402,
1425,
14486,
376,
1125,
267,
327,
334,
7911,
446,
17,
365,
3107,
63,
3472,
63,
30193,
436,
27241,
590,
314,
12472,
267,
327,
11479,
378,
4634,
9,
267,
291,
14,
1855,
8,
15371,
14,
705,
12,
12472,
14,
6447,
12,
283,
3170,
297,
1616,
9,
339,
347,
511,
63,
4087,
6447,
1113,
8,
277,
304,
267,
327,
4911,
5988,
641,
10015,
11029,
909,
543,
4875,
1862,
267,
291,
14,
1855,
8,
3393,
12,
12472,
14,
6447,
1113,
12,
413,
12,
12472,
14,
28506,
12,
378,
9,
267,
327,
9176,
3141,
5821,
4634,
7031,
14486,
376,
1125,
267,
291,
14,
1855,
8,
3393,
12,
355,
12472,
14,
6447,
1113,
12,
413,
12,
12472,
14,
28506,
12,
12472,
14,
4283,
63,
55,
14662,
435,
413,
9,
339,
347,
511,
63,
4087,
14954,
1113,
8,
277,
304,
267,
327,
4911,
5988
] |
[
2882,
199,
504,
511,
14,
396,
63,
4058,
492,
25788,
12,
1255,
63,
2796,
12,
492,
63,
578,
12,
17002,
12,
5074,
199,
646,
14755,
199,
646,
2196,
199,
504,
511,
14,
396,
63,
4058,
492,
7151,
5076,
5286,
396,
12,
485,
17,
39,
12,
485,
20,
39,
199,
646,
984,
199,
199,
893,
26,
272,
492,
21991,
199,
2590,
3545,
26,
272,
21991,
275,
488,
199,
199,
15371,
275,
492,
63,
578,
360,
15371,
358,
421,
199,
533,
2670,
1838,
1746,
8,
2796,
14,
1746,
304,
272,
327,
9040,
511,
5560,
272,
347,
511,
63,
13258,
708,
928,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
11986,
395,
12472,
14,
13258,
708,
12398,
378,
430,
267,
291,
14,
1815,
8,
15371,
14,
13258,
708,
480,
3175,
401,
378,
21870,
430,
339,
347,
511,
63,
13258,
708,
1667,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
12398,
378,
395,
378,
9,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
12398,
413,
395,
413,
9,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
12398,
841,
708,
395,
841,
708,
9,
339,
347,
511,
63,
350,
1435,
708,
928,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
11986,
395,
12472,
14,
350,
1435,
708,
12398,
413,
430,
267,
291,
14,
1815,
8,
15371,
14,
350,
1435,
708,
480,
3175,
401,
378,
21870,
430,
339,
347,
511,
63,
350,
1435,
708,
1667,
8,
277,
304,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
12398,
378,
395,
378,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
12398,
413,
395,
413,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
12398,
841,
708,
395,
841,
708,
9,
339,
347,
26400,
708,
8,
277,
12,
6775,
12,
1420,
304,
267,
327,
4337,
13,
2075,
1338,
9742,
1553,
9040,
83,
641,
4337,
13,
8118,
5049,
13,
4546,
20601,
267,
327,
961,
365,
11012,
340,
4546,
7105,
334,
16,
88,
2036,
3273,
44,
9,
365,
663,
14,
267,
291,
14,
629,
8,
8606,
1253,
378,
88,
16,
18073,
44,
12,
1420,
1253,
378,
88,
16,
18073,
44,
9,
339,
347,
511,
63,
897,
6051,
3617,
8,
277,
304,
267,
291,
14,
629,
708,
8,
15371,
14,
13258,
708,
480,
897,
6051,
262,
401,
378,
395,
378,
88,
16,
69,
21,
67,
17,
65,
6708,
44,
9,
267,
291,
14,
629,
708,
8,
15371,
14,
13258,
708,
480,
897,
6051,
262,
401,
413,
395,
378,
88,
2824,
66,
22,
2158,
2635,
9,
267,
291,
14,
629,
708,
8,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
401,
378,
395,
378,
88,
16,
66,
2177,
996,
70,
22,
9,
267,
291,
14,
629,
708,
8,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
401,
413,
395,
378,
88,
16,
3691,
28384,
70,
23,
9,
398,
291,
14,
629,
8,
15371,
14,
13258,
708,
480,
897,
6051,
262,
1288,
12472,
14,
13258,
708,
480,
897,
6051,
262,
401,
378,
430,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
1288,
15371,
14,
350,
1435,
708,
480,
897,
6051,
262,
401,
17,
430,
339,
347,
511,
63,
22017,
8,
277,
304,
267,
408,
396,
4976,
713,
996,
4151,
26,
10514,
18080,
708,
12,
1503,
1435,
708,
315,
499,
14,
88,
624,
267,
3925,
275,
283,
22017,
7,
267,
327,
7662,
511,
10514,
5953,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
8,
1421,
395,
446,
7663,
1257,
1299,
30308,
9,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
8283,
659,
24073,
1349,
821,
19528,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
8,
1421,
11,
1421,
395,
446,
2819,
1079,
975,
28163,
9,
267,
291,
14,
629,
8,
15371,
14,
350,
1435,
708,
360,
8283,
659,
1520,
1081,
1184,
15463,
9,
339,
347,
511,
63,
7191,
63,
305,
63,
27460,
63,
13258,
708,
8,
277,
304,
267,
3925,
275,
283,
22017,
7,
267,
291,
14,
629,
8,
27460,
14,
13258,
708,
8,
1421,
395,
12472,
14,
13258,
708,
8,
1421,
430,
267,
291,
14,
629,
8,
27460,
14,
13258,
708,
360,
8283,
659,
12472,
14,
13258,
708,
360,
8283,
1333,
339,
347,
511,
63,
7371,
63,
13258,
63,
1003,
63,
1210,
8,
277,
304,
267,
327,
710,
1425,
402,
1686,
1324,
1338,
367,
314,
18080,
1174,
1077,
506,
267,
327,
446,
18,
538,
2192,
4012,
499,
538,
708,
13,
17,
370,
2040,
4153,
601,
22563,
1183,
28483,
267,
327,
370,
282,
10514,
4337,
13,
2075,
3000,
14,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
10670,
297,
446,
17,
395,
12472,
14,
13258,
708,
360,
10670,
297,
378,
21870,
44,
430,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
8283,
297,
446,
8988,
1046,
3129,
395,
586,
12472,
14,
13258,
708,
360,
8283,
297,
221,
378,
3581,
68,
614,
14218,
44,
430,
267,
291,
14,
629,
8,
15371,
14,
13258,
708,
360,
8283,
297,
24953,
18,
538,
2192,
1826,
586,
12472,
14,
13258,
708,
360,
8283,
297,
221,
334,
18,
538,
2192,
1724,
421,
199,
533,
2186,
1746,
8,
2796,
14,
1746,
304,
272,
327,
1852,
3238,
781,
3550,
2005,
1420,
2552,
272,
347,
511,
63,
4087,
1896,
8,
277,
304,
267,
327,
9176,
10291,
2166,
734,
402,
1425,
14486,
376,
1125,
267,
327,
334,
7911,
446,
17,
365,
3107,
63,
3472,
63,
30193,
436,
27241,
590,
314,
12472,
267,
327,
11479,
378,
4634,
9,
267,
291,
14,
1855,
8,
15371,
14,
705,
12,
12472,
14,
6447,
12,
283,
3170,
297,
1616,
9,
339,
347,
511,
63,
4087,
6447,
1113,
8,
277,
304,
267,
327,
4911,
5988,
641,
10015,
11029,
909,
543,
4875,
1862,
267,
291,
14,
1855,
8,
3393,
12,
12472,
14,
6447,
1113,
12,
413,
12,
12472,
14,
28506,
12,
378,
9,
267,
327,
9176,
3141,
5821,
4634,
7031,
14486,
376,
1125,
267,
291,
14,
1855,
8,
3393,
12,
355,
12472,
14,
6447,
1113,
12,
413,
12,
12472,
14,
28506,
12,
12472,
14,
4283,
63,
55,
14662,
435,
413,
9,
339,
347,
511,
63,
4087,
14954,
1113,
8,
277,
304,
267,
327,
4911,
5988,
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
] |
tomasy23/evertonkrosnodart
|
tools/addheader/addheader.py
|
6
|
2999
|
header="""\
/*************************************************************************/
/* $filename */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/*************************************************************************/
"""
f = open("files","rb")
fname = f.readline()
while (fname!=""):
fr = open(fname.strip(),"rb")
l = fr.readline()
bc=False
fsingle = fname.strip()
if (fsingle.find("/")!=-1):
fsingle=fsingle[fsingle.rfind("/")+1:]
rep_fl="$filename"
rep_fi=fsingle
len_fl=len(rep_fl)
len_fi=len(rep_fi)
if (len_fi<len_fl):
for x in range(len_fl-len_fi):
rep_fi+=" "
elif (len_fl<len_fi):
for x in range(len_fi-len_fl):
rep_fl+=" "
if (header.find(rep_fl)!=-1):
text=header.replace(rep_fl,rep_fi)
else:
text=header.replace("$filename",fsingle)
while (l!=""):
if ((l.find("//")!=0 and l.find("/*")!=0 and l.strip()!="") or bc):
text+=l
bc=True
l=fr.readline()
fr.close()
fr=open(fname.strip(),"wb")
fr.write(text)
fr.close()
#print(text)
fname=f.readline()
|
mit
|
[
1291,
11916,
60,
199,
15,
14355,
15870,
199,
6331,
221,
2672,
1501,
2476,
14960,
11589,
199,
15,
14355,
15870,
199,
6331,
9668,
961,
570,
365,
1777,
402,
26,
13235,
11589,
199,
6331,
13235,
598,
47,
13203,
5070,
14331,
13293,
11589,
199,
6331,
8540,
1455,
921,
1544,
14,
71,
19657,
724,
2598,
14,
1308,
12793,
11589,
199,
15,
14355,
15870,
199,
6331,
1898,
334,
67,
9,
10219,
13,
7280,
1603,
7856,
491,
2730,
386,
12267,
12,
31153,
352,
4688,
90,
300,
14,
463,
11589,
199,
6331,
6208,
755,
11589,
199,
6331,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
11589,
199,
6331,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
755,
11589,
199,
6331,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
257,
11589,
199,
6331,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
257,
11589,
199,
6331,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
259,
11589,
199,
6331,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
11589,
199,
6331,
314,
2569,
3704,
26,
2476,
3777,
11589,
199,
6331,
6208,
755,
11589,
199,
6331,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
263,
11589,
199,
6331,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
755,
11589,
199,
6331,
6208,
755,
11589,
199,
6331,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
755,
11589,
199,
6331,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
259,
11589,
199,
6331,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
2795,
15,
199,
6331,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
221,
11589,
199,
6331,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
221,
11589,
199,
6331,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
258,
11589,
199,
6331,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
4483,
11589,
199,
15,
14355,
15870,
199,
624,
199,
199,
70,
275,
1551,
480,
1725,
2266,
4848,
531,
199,
199,
5252,
275,
289,
14,
6407,
342,
199,
6710,
334,
5252,
1111,
341,
304,
819,
9513,
275,
1551,
8,
5252,
14,
1913,
1062,
2,
4848,
531,
523,
634,
275,
9513,
14,
6407,
342,
523,
16604,
29,
797,
523,
289,
4780,
275,
6748,
14,
1913,
342,
272,
523,
340,
334,
70,
4780,
14,
1623,
19031,
1111,
13,
17,
304,
272,
289,
4780,
29,
70,
4780,
59,
70,
4780,
14,
14542,
19031,
11,
17,
2938,
523,
1833,
63,
2327,
628,
4,
1501,
2,
523,
1833,
63,
329,
29,
70,
4780,
523,
822,
63,
2327,
29,
552,
8,
1155,
63,
2327,
9,
523,
822,
63,
329,
29,
552,
8,
1155,
63,
329,
9,
523,
340,
334,
552,
63,
329,
28,
552,
63,
2327,
304,
272,
367,
671,
315,
1425,
8,
552,
63,
2327,
13,
552,
63,
329,
304,
489,
1833,
63,
329,
11,
628,
298,
523,
916,
334,
552,
63,
2327,
28,
552,
63,
329,
304,
272,
367,
671,
315,
1425,
8,
552,
63,
329,
13,
552,
63,
2327,
304,
489,
1833,
63,
2327,
11,
628,
298,
523,
340,
334,
1291,
14,
1623,
8,
1155,
63,
2327,
9,
1111,
13,
17,
304,
420,
272,
1318,
29,
1291,
14,
1814,
8,
1155,
63,
2327,
12,
1155,
63,
329,
9,
523,
587,
26,
272,
1318,
29,
1291,
14,
1814,
21506,
1501,
401,
70,
4780,
9,
2043,
272,
523,
1830,
334,
76,
1111,
341,
304,
272,
340,
3666,
76,
14,
1623,
21816,
531,
1111,
16,
436,
221,
634,
14,
1623,
4769,
10,
531,
1111,
16,
436,
634,
14,
1913,
342,
1111,
7230,
503,
16604,
304,
489,
1318,
10365,
76,
489,
16604,
29,
549,
272,
634,
29,
4391,
14,
6407,
342,
819,
9513,
14,
1600,
342,
755,
523,
9513,
29,
1490,
8,
5252,
14,
1913,
1062,
2,
6603,
531,
523,
9513,
14,
952,
8,
505,
9,
523,
9513,
14,
1600,
342,
523,
327,
1361,
8,
505,
9,
523,
6748,
29,
70,
14,
6407,
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
] |
[
11916,
60,
199,
15,
14355,
15870,
199,
6331,
221,
2672,
1501,
2476,
14960,
11589,
199,
15,
14355,
15870,
199,
6331,
9668,
961,
570,
365,
1777,
402,
26,
13235,
11589,
199,
6331,
13235,
598,
47,
13203,
5070,
14331,
13293,
11589,
199,
6331,
8540,
1455,
921,
1544,
14,
71,
19657,
724,
2598,
14,
1308,
12793,
11589,
199,
15,
14355,
15870,
199,
6331,
1898,
334,
67,
9,
10219,
13,
7280,
1603,
7856,
491,
2730,
386,
12267,
12,
31153,
352,
4688,
90,
300,
14,
463,
11589,
199,
6331,
6208,
755,
11589,
199,
6331,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
11589,
199,
6331,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
755,
11589,
199,
6331,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
257,
11589,
199,
6331,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
257,
11589,
199,
6331,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
259,
11589,
199,
6331,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
11589,
199,
6331,
314,
2569,
3704,
26,
2476,
3777,
11589,
199,
6331,
6208,
755,
11589,
199,
6331,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
263,
11589,
199,
6331,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
755,
11589,
199,
6331,
6208,
755,
11589,
199,
6331,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
755,
11589,
199,
6331,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
259,
11589,
199,
6331,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
2795,
15,
199,
6331,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
221,
11589,
199,
6331,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
221,
11589,
199,
6331,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
258,
11589,
199,
6331,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
4483,
11589,
199,
15,
14355,
15870,
199,
624,
199,
199,
70,
275,
1551,
480,
1725,
2266,
4848,
531,
199,
199,
5252,
275,
289,
14,
6407,
342,
199,
6710,
334,
5252,
1111,
341,
304,
819,
9513,
275,
1551,
8,
5252,
14,
1913,
1062,
2,
4848,
531,
523,
634,
275,
9513,
14,
6407,
342,
523,
16604,
29,
797,
523,
289,
4780,
275,
6748,
14,
1913,
342,
272,
523,
340,
334,
70,
4780,
14,
1623,
19031,
1111,
13,
17,
304,
272,
289,
4780,
29,
70,
4780,
59,
70,
4780,
14,
14542,
19031,
11,
17,
2938,
523,
1833,
63,
2327,
628,
4,
1501,
2,
523,
1833,
63,
329,
29,
70,
4780,
523,
822,
63,
2327,
29,
552,
8,
1155,
63,
2327,
9,
523,
822,
63,
329,
29,
552,
8,
1155,
63,
329,
9,
523,
340,
334,
552,
63,
329,
28,
552,
63,
2327,
304,
272,
367,
671,
315,
1425,
8,
552,
63,
2327,
13,
552,
63,
329,
304,
489,
1833,
63,
329,
11,
628,
298,
523,
916,
334,
552,
63,
2327,
28,
552,
63,
329,
304,
272,
367,
671,
315,
1425,
8,
552,
63,
329,
13,
552,
63,
2327,
304,
489,
1833,
63,
2327,
11,
628,
298,
523,
340,
334,
1291,
14,
1623,
8,
1155,
63,
2327,
9,
1111,
13,
17,
304,
420,
272,
1318,
29,
1291,
14,
1814,
8,
1155,
63,
2327,
12,
1155,
63,
329,
9,
523,
587,
26,
272,
1318,
29,
1291,
14,
1814,
21506,
1501,
401,
70,
4780,
9,
2043,
272,
523,
1830,
334,
76,
1111,
341,
304,
272,
340,
3666,
76,
14,
1623,
21816,
531,
1111,
16,
436,
221,
634,
14,
1623,
4769,
10,
531,
1111,
16,
436,
634,
14,
1913,
342,
1111,
7230,
503,
16604,
304,
489,
1318,
10365,
76,
489,
16604,
29,
549,
272,
634,
29,
4391,
14,
6407,
342,
819,
9513,
14,
1600,
342,
755,
523,
9513,
29,
1490,
8,
5252,
14,
1913,
1062,
2,
6603,
531,
523,
9513,
14,
952,
8,
505,
9,
523,
9513,
14,
1600,
342,
523,
327,
1361,
8,
505,
9,
523,
6748,
29,
70,
14,
6407,
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,
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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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
] |
Carmezim/tensorflow
|
tensorflow/python/platform/flags_test.py
|
79
|
3046
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for our flags implementation."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import unittest
from tensorflow.python.platform import app
from tensorflow.python.platform import flags
flags.DEFINE_string("string_foo", "default_val", "HelpString")
flags.DEFINE_integer("int_foo", 42, "HelpString")
flags.DEFINE_float("float_foo", 42.0, "HelpString")
flags.DEFINE_boolean("bool_foo", True, "HelpString")
flags.DEFINE_boolean("bool_negation", True, "HelpString")
flags.DEFINE_boolean("bool-dash-negation", True, "HelpString")
flags.DEFINE_boolean("bool_a", False, "HelpString")
flags.DEFINE_boolean("bool_c", False, "HelpString")
flags.DEFINE_boolean("bool_d", True, "HelpString")
flags.DEFINE_bool("bool_e", True, "HelpString")
FLAGS = flags.FLAGS
class FlagsTest(unittest.TestCase):
def testString(self):
res = FLAGS.string_foo
self.assertEqual(res, "default_val")
FLAGS.string_foo = "bar"
self.assertEqual("bar", FLAGS.string_foo)
def testBool(self):
res = FLAGS.bool_foo
self.assertTrue(res)
FLAGS.bool_foo = False
self.assertFalse(FLAGS.bool_foo)
def testBoolCommandLines(self):
# Specified on command line with no args, sets to True,
# even if default is False.
self.assertEqual(True, FLAGS.bool_a)
# --no before the flag forces it to False, even if the
# default is True
self.assertEqual(False, FLAGS.bool_negation)
# --bool_flag=True sets to True
self.assertEqual(True, FLAGS.bool_c)
# --bool_flag=False sets to False
self.assertEqual(False, FLAGS.bool_d)
def testInt(self):
res = FLAGS.int_foo
self.assertEquals(res, 42)
FLAGS.int_foo = -1
self.assertEqual(-1, FLAGS.int_foo)
def testFloat(self):
res = FLAGS.float_foo
self.assertEquals(42.0, res)
FLAGS.float_foo = -1.0
self.assertEqual(-1.0, FLAGS.float_foo)
def main(_):
# unittest.main() tries to interpret the unknown flags, so use the
# direct functions instead.
runner = unittest.TextTestRunner()
itersuite = unittest.TestLoader().loadTestsFromTestCase(FlagsTest)
runner.run(itersuite)
if __name__ == "__main__":
# Test command lines
sys.argv.extend([
"--bool_a", "--nobool_negation", "--bool_c=True", "--bool_d=False",
"and_argument"
])
app.run()
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
4154,
3285,
4514,
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,
646,
984,
199,
646,
2882,
199,
199,
504,
3228,
14,
1548,
14,
3246,
492,
1145,
199,
504,
3228,
14,
1548,
14,
3246,
492,
3285,
199,
199,
2469,
14,
14603,
63,
875,
480,
875,
63,
1421,
401,
298,
885,
63,
637,
401,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4115,
480,
442,
63,
1421,
401,
5685,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
1609,
480,
1609,
63,
1421,
401,
5685,
14,
16,
12,
298,
8673,
1558,
531,
199,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
1421,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
685,
5360,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
13,
6760,
13,
685,
5360,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
65,
401,
756,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
67,
401,
756,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
68,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
2245,
480,
2245,
63,
69,
401,
715,
12,
298,
8673,
1558,
531,
199,
199,
4831,
275,
3285,
14,
4831,
421,
199,
533,
24870,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
1558,
8,
277,
304,
272,
522,
275,
12846,
14,
875,
63,
1421,
272,
291,
14,
629,
8,
470,
12,
298,
885,
63,
637,
531,
272,
12846,
14,
875,
63,
1421,
275,
298,
1700,
2,
272,
291,
14,
629,
480,
1700,
401,
12846,
14,
875,
63,
1421,
9,
819,
347,
511,
10349,
8,
277,
304,
272,
522,
275,
12846,
14,
2245,
63,
1421,
272,
291,
14,
1815,
8,
470,
9,
272,
12846,
14,
2245,
63,
1421,
275,
756,
272,
291,
14,
3334,
8,
4831,
14,
2245,
63,
1421,
9,
819,
347,
511,
10349,
3110,
9863,
8,
277,
304,
272,
327,
5367,
1290,
641,
1414,
1004,
543,
949,
1249,
12,
5951,
370,
715,
12,
272,
327,
2755,
340,
849,
365,
756,
14,
272,
291,
14,
629,
8,
549,
12,
12846,
14,
2245,
63,
65,
9,
339,
327,
1553,
889,
2544,
314,
3305,
25983,
652,
370,
756,
12,
2755,
340,
314,
272,
327,
849,
365,
715,
272,
291,
14,
629,
8,
797,
12,
12846,
14,
2245,
63,
685,
5360,
9,
339,
327,
1553,
2245,
63,
4173,
29,
549,
5951,
370,
715,
272,
291,
14,
629,
8,
549,
12,
12846,
14,
2245,
63,
67,
9,
339,
327,
1553,
2245,
63,
4173,
29,
797,
5951,
370,
756,
272,
291,
14,
629,
8,
797,
12,
12846,
14,
2245,
63,
68,
9,
819,
347,
511,
3241,
8,
277,
304,
272,
522,
275,
12846,
14,
442,
63,
1421,
272,
291,
14,
2947,
8,
470,
12,
5685,
9,
272,
12846,
14,
442,
63,
1421,
275,
446,
17,
272,
291,
14,
629,
2801,
17,
12,
12846,
14,
442,
63,
1421,
9,
819,
347,
511,
5136,
8,
277,
304,
272,
522,
275,
12846,
14,
1609,
63,
1421,
272,
291,
14,
2947,
8,
2260,
14,
16,
12,
522,
9,
272,
12846,
14,
1609,
63,
1421,
275,
446,
17,
14,
16,
272,
291,
14,
629,
2801,
17,
14,
16,
12,
12846,
14,
1609,
63,
1421,
9,
421,
199,
318,
2446,
1547,
304,
523,
327,
2882,
14,
973,
342,
11275,
370,
15579,
314,
5809,
3285,
12,
880,
675,
314,
523,
327,
4125,
3423,
3140,
14,
523,
7876,
275,
2882,
14,
24285,
342,
523,
284,
878,
2577,
275,
2882,
14,
15824,
1252,
26946,
8,
6381,
774,
9,
523,
7876,
14,
1065,
8,
15266,
2577,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
327,
1379,
1414,
2385,
523,
984,
14,
3020,
14,
2880,
779,
489,
4320,
2245,
63,
65,
401,
4320,
889,
2245,
63,
685,
5360,
401,
4320,
2245,
63,
67,
29,
549,
401,
4320,
2245,
63,
68,
29,
797,
401,
489,
298,
460,
63,
2094,
2,
523,
4794,
819,
1145,
14,
1065,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
4154,
3285,
4514,
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,
646,
984,
199,
646,
2882,
199,
199,
504,
3228,
14,
1548,
14,
3246,
492,
1145,
199,
504,
3228,
14,
1548,
14,
3246,
492,
3285,
199,
199,
2469,
14,
14603,
63,
875,
480,
875,
63,
1421,
401,
298,
885,
63,
637,
401,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4115,
480,
442,
63,
1421,
401,
5685,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
1609,
480,
1609,
63,
1421,
401,
5685,
14,
16,
12,
298,
8673,
1558,
531,
199,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
1421,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
685,
5360,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
13,
6760,
13,
685,
5360,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
65,
401,
756,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
67,
401,
756,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
4871,
480,
2245,
63,
68,
401,
715,
12,
298,
8673,
1558,
531,
199,
2469,
14,
14603,
63,
2245,
480,
2245,
63,
69,
401,
715,
12,
298,
8673,
1558,
531,
199,
199,
4831,
275,
3285,
14,
4831,
421,
199,
533,
24870,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
1558,
8,
277,
304,
272,
522,
275,
12846,
14,
875,
63,
1421,
272,
291,
14,
629,
8,
470,
12,
298,
885,
63,
637,
531,
272,
12846,
14,
875,
63,
1421,
275,
298,
1700,
2,
272,
291,
14,
629,
480,
1700,
401,
12846,
14,
875,
63,
1421,
9,
819,
347,
511,
10349,
8,
277,
304,
272,
522,
275,
12846,
14,
2245,
63,
1421,
272,
291,
14,
1815,
8,
470,
9,
272,
12846,
14,
2245,
63,
1421,
275,
756,
272,
291,
14,
3334,
8,
4831,
14,
2245,
63,
1421,
9,
819,
347,
511,
10349,
3110,
9863,
8,
277,
304,
272,
327,
5367,
1290,
641,
1414,
1004,
543,
949,
1249,
12,
5951,
370,
715,
12,
272,
327,
2755,
340,
849,
365,
756,
14,
272,
291,
14,
629,
8,
549,
12,
12846,
14,
2245,
63,
65,
9,
339,
327,
1553,
889,
2544,
314,
3305,
25983,
652,
370,
756,
12,
2755,
340,
314,
272,
327,
849,
365,
715,
272,
291,
14,
629,
8,
797,
12,
12846,
14,
2245,
63,
685,
5360,
9,
339,
327,
1553,
2245,
63,
4173,
29,
549,
5951,
370,
715,
272,
291,
14,
629,
8,
549,
12,
12846,
14,
2245,
63,
67,
9,
339,
327,
1553,
2245,
63,
4173,
29,
797,
5951,
370,
756,
272,
291,
14,
629,
8,
797,
12,
12846,
14,
2245,
63,
68,
9,
819,
347,
511,
3241,
8,
277,
304,
272,
522,
275,
12846,
14,
442,
63,
1421,
272,
291,
14,
2947,
8,
470,
12,
5685,
9,
272,
12846,
14,
442,
63,
1421,
275,
446,
17,
272,
291,
14,
629,
2801,
17,
12,
12846,
14,
442,
63,
1421,
9,
819,
347,
511,
5136,
8,
277,
304,
272,
522,
275,
12846,
14,
1609,
63,
1421,
272,
291,
14,
2947,
8,
2260,
14,
16,
12,
522,
9,
272,
12846,
14,
1609,
63,
1421,
275,
446,
17,
14,
16,
272,
291,
14,
629,
2801,
17,
14,
16,
12,
12846,
14,
1609,
63,
1421,
9,
421,
199,
318,
2446,
1547,
304,
523,
327,
2882,
14,
973,
342,
11275,
370,
15579,
314,
5809,
3285,
12,
880,
675,
314,
523,
327,
4125,
3423,
3140,
14,
523,
7876,
275,
2882,
14,
24285,
342,
523,
284,
878,
2577,
275,
2882,
14,
15824,
1252,
26946,
8,
6381,
774,
9,
523,
7876,
14,
1065,
8,
15266,
2577,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
327,
1379,
1414,
2385,
523,
984,
14,
3020,
14,
2880,
779,
489,
4320,
2245,
63,
65,
401,
4320,
889,
2245,
63,
685,
5360,
401,
4320,
2245,
63,
67,
29,
549,
401,
4320,
2245,
63,
68,
29,
797,
401,
489,
298,
460,
63,
2094,
2,
523,
4794,
819,
1145,
14,
1065,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kawamon/hue
|
desktop/core/ext-py/boto-2.46.1/boto/gs/connection.py
|
157
|
5478
|
# Copyright 2010 Google Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from boto.gs.bucket import Bucket
from boto.s3.connection import S3Connection
from boto.s3.connection import SubdomainCallingFormat
from boto.s3.connection import check_lowercase_bucketname
from boto.utils import get_utf8_value
class Location(object):
DEFAULT = 'US'
EU = 'EU'
class GSConnection(S3Connection):
DefaultHost = 'storage.googleapis.com'
QueryString = 'Signature=%s&Expires=%d&GoogleAccessId=%s'
def __init__(self, gs_access_key_id=None, gs_secret_access_key=None,
is_secure=True, port=None, proxy=None, proxy_port=None,
proxy_user=None, proxy_pass=None,
host=DefaultHost, debug=0, https_connection_factory=None,
calling_format=SubdomainCallingFormat(), path='/',
suppress_consec_slashes=True):
super(GSConnection, self).__init__(gs_access_key_id, gs_secret_access_key,
is_secure, port, proxy, proxy_port, proxy_user, proxy_pass,
host, debug, https_connection_factory, calling_format, path,
"google", Bucket,
suppress_consec_slashes=suppress_consec_slashes)
def create_bucket(self, bucket_name, headers=None,
location=Location.DEFAULT, policy=None,
storage_class='STANDARD'):
"""
Creates a new bucket. By default it's located in the USA. You can
pass Location.EU to create bucket in the EU. You can also pass
a LocationConstraint for where the bucket should be located, and
a StorageClass describing how the data should be stored.
:type bucket_name: string
:param bucket_name: The name of the new bucket.
:type headers: dict
:param headers: Additional headers to pass along with the request to GCS.
:type location: :class:`boto.gs.connection.Location`
:param location: The location of the new bucket.
:type policy: :class:`boto.gs.acl.CannedACLStrings`
:param policy: A canned ACL policy that will be applied to the new key
in GCS.
:type storage_class: string
:param storage_class: Either 'STANDARD' or 'DURABLE_REDUCED_AVAILABILITY'.
"""
check_lowercase_bucketname(bucket_name)
if policy:
if headers:
headers[self.provider.acl_header] = policy
else:
headers = {self.provider.acl_header : policy}
if not location:
location = Location.DEFAULT
location_elem = ('<LocationConstraint>%s</LocationConstraint>'
% location)
if storage_class:
storage_class_elem = ('<StorageClass>%s</StorageClass>'
% storage_class)
else:
storage_class_elem = ''
data = ('<CreateBucketConfiguration>%s%s</CreateBucketConfiguration>'
% (location_elem, storage_class_elem))
response = self.make_request(
'PUT', get_utf8_value(bucket_name), headers=headers,
data=get_utf8_value(data))
body = response.read()
if response.status == 409:
raise self.provider.storage_create_error(
response.status, response.reason, body)
if response.status == 200:
return self.bucket_class(self, bucket_name)
else:
raise self.provider.storage_response_error(
response.status, response.reason, body)
def get_bucket(self, bucket_name, validate=True, headers=None):
"""
Retrieves a bucket by name.
If the bucket does not exist, an ``S3ResponseError`` will be raised. If
you are unsure if the bucket exists or not, you can use the
``S3Connection.lookup`` method, which will either return a valid bucket
or ``None``.
:type bucket_name: string
:param bucket_name: The name of the bucket
:type headers: dict
:param headers: Additional headers to pass along with the request to
AWS.
:type validate: boolean
:param validate: If ``True``, it will try to fetch all keys within the
given bucket. (Default: ``True``)
"""
bucket = self.bucket_class(self, bucket_name)
if validate:
bucket.get_all_keys(headers, maxkeys=0)
return bucket
|
apache-2.0
|
[
3,
1898,
7129,
4475,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
504,
6055,
14,
458,
14,
4623,
492,
31479,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
428,
19,
3225,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
4804,
2261,
23796,
3484,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
1104,
63,
21636,
63,
4623,
354,
199,
504,
6055,
14,
1208,
492,
664,
63,
1624,
24,
63,
585,
199,
199,
533,
12625,
8,
785,
304,
272,
6186,
275,
283,
1668,
7,
272,
26007,
275,
283,
23539,
7,
199,
199,
533,
598,
51,
3225,
8,
51,
19,
3225,
304,
339,
3758,
4965,
275,
283,
3494,
14,
17533,
14,
957,
7,
272,
8133,
1558,
275,
283,
10014,
2458,
83,
6,
14000,
470,
2458,
68,
6,
13266,
3946,
1304,
2458,
83,
7,
339,
347,
636,
826,
721,
277,
12,
8763,
63,
2732,
63,
498,
63,
344,
29,
403,
12,
8763,
63,
4731,
63,
2732,
63,
498,
29,
403,
12,
326,
365,
63,
7817,
29,
549,
12,
1844,
29,
403,
12,
4566,
29,
403,
12,
4566,
63,
719,
29,
403,
12,
326,
4566,
63,
751,
29,
403,
12,
4566,
63,
1529,
29,
403,
12,
326,
1591,
29,
2698,
4965,
12,
3105,
29,
16,
12,
4178,
63,
2105,
63,
3702,
29,
403,
12,
326,
6358,
63,
908,
29,
2610,
2261,
23796,
3484,
1062,
931,
25412,
326,
15678,
63,
388,
3321,
63,
24032,
29,
549,
304,
267,
1613,
8,
8021,
3225,
12,
291,
2843,
826,
721,
458,
63,
2732,
63,
498,
63,
344,
12,
8763,
63,
4731,
63,
2732,
63,
498,
12,
326,
365,
63,
7817,
12,
1844,
12,
4566,
12,
4566,
63,
719,
12,
4566,
63,
751,
12,
4566,
63,
1529,
12,
326,
1591,
12,
3105,
12,
4178,
63,
2105,
63,
3702,
12,
6358,
63,
908,
12,
931,
12,
326,
298,
3098,
401,
31479,
12,
326,
15678,
63,
388,
3321,
63,
24032,
29,
17381,
63,
388,
3321,
63,
24032,
9,
339,
347,
1218,
63,
4623,
8,
277,
12,
5315,
63,
354,
12,
2323,
29,
403,
12,
1993,
2909,
29,
6592,
14,
3472,
12,
4592,
29,
403,
12,
1993,
4887,
63,
533,
534,
19547,
735,
267,
408,
267,
10560,
282,
892,
5315,
14,
4885,
849,
652,
1159,
16180,
315,
314,
8217,
14,
2047,
883,
267,
986,
12625,
14,
23539,
370,
1218,
5315,
315,
314,
26007,
14,
2047,
883,
2597,
986,
267,
282,
12625,
8463,
367,
2382,
314,
5315,
1077,
506,
16180,
12,
436,
267,
282,
10533,
2543,
13660,
4212,
314,
666,
1077,
506,
5489,
14,
398,
520,
466,
5315,
63,
354,
26,
1059,
267,
520,
635,
5315,
63,
354,
26,
710,
536,
402,
314,
892,
5315,
14,
398,
520,
466,
2323,
26,
1211,
267,
520,
635,
2323,
26,
10961,
2323,
370,
986,
3180,
543,
314,
1056,
370,
598,
3298,
14,
398,
520,
466,
2909,
26,
520,
533,
1705,
10914,
14,
458,
14,
2105,
14,
6592,
64,
267,
520,
635,
2909,
26,
710,
2909,
402,
314,
892,
5315,
14,
398,
520,
466,
4592,
26,
520,
533,
1705,
10914,
14,
458,
14,
5853,
14,
35,
9386,
18765,
12672,
64,
267,
520,
635,
4592,
26,
437,
883,
7439,
16543,
4592,
626,
911,
506,
6781,
370,
314,
892,
790,
2432,
315,
598,
3298,
14,
398,
520,
466,
4887,
63,
533,
26,
1059,
267,
520,
635,
4887,
63,
533,
26,
13083,
283,
19547,
7,
503,
283,
36,
1230,
2617,
63,
907,
4980,
25927,
63,
15004,
2477,
1370,
398,
408,
267,
1104,
63,
21636,
63,
4623,
354,
8,
4623,
63,
354,
9,
398,
340,
4592,
26,
288,
340,
2323,
26,
355,
2323,
59,
277,
14,
3780,
14,
5853,
63,
1291,
61,
275,
4592,
288,
587,
26,
355,
2323,
275,
469,
277,
14,
3780,
14,
5853,
63,
1291,
520,
4592,
93,
267,
340,
440,
2909,
26,
288,
2909,
275,
12625,
14,
3472,
267,
2909,
63,
6086,
275,
19990,
6592,
8463,
6598,
83,
1108,
6592,
8463,
3524,
586,
450,
2909,
9,
267,
340,
4887,
63,
533,
26,
288,
4887,
63,
533,
63,
6086,
275,
19990,
6408,
2543,
6598,
83,
1108,
6408,
2543,
3524,
3303,
450,
4887,
63,
533,
9,
267,
587,
26,
288,
4887,
63,
533,
63,
6086,
275,
2125,
267,
666,
275,
19990,
2499,
12311,
5688,
6598,
83,
5,
83,
1108,
2499,
12311,
5688,
3524,
326,
450,
334,
1985,
63,
6086,
12,
4887,
63,
533,
63,
6086,
430,
267,
1177,
275,
291,
14,
1875,
63,
1069,
8,
288,
283,
4013,
297,
664,
63,
1624,
24,
63,
585,
8,
4623,
63,
354,
395,
2323,
29,
2139,
12,
288,
666,
29,
362,
63,
1624,
24,
63,
585,
8,
576,
430,
267,
2396,
275,
1177,
14,
739,
342,
267,
340,
1177,
14,
1205,
508,
21292,
26,
288,
746,
291,
14,
3780,
14,
3494,
63,
981,
63,
705,
8,
355,
1177,
14,
1205,
12,
1177,
14,
5764,
12,
2396,
9,
267,
340,
1177,
14,
1205,
508,
1926
] |
[
1898,
7129,
4475,
3277,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
504,
6055,
14,
458,
14,
4623,
492,
31479,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
428,
19,
3225,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
4804,
2261,
23796,
3484,
199,
504,
6055,
14,
83,
19,
14,
2105,
492,
1104,
63,
21636,
63,
4623,
354,
199,
504,
6055,
14,
1208,
492,
664,
63,
1624,
24,
63,
585,
199,
199,
533,
12625,
8,
785,
304,
272,
6186,
275,
283,
1668,
7,
272,
26007,
275,
283,
23539,
7,
199,
199,
533,
598,
51,
3225,
8,
51,
19,
3225,
304,
339,
3758,
4965,
275,
283,
3494,
14,
17533,
14,
957,
7,
272,
8133,
1558,
275,
283,
10014,
2458,
83,
6,
14000,
470,
2458,
68,
6,
13266,
3946,
1304,
2458,
83,
7,
339,
347,
636,
826,
721,
277,
12,
8763,
63,
2732,
63,
498,
63,
344,
29,
403,
12,
8763,
63,
4731,
63,
2732,
63,
498,
29,
403,
12,
326,
365,
63,
7817,
29,
549,
12,
1844,
29,
403,
12,
4566,
29,
403,
12,
4566,
63,
719,
29,
403,
12,
326,
4566,
63,
751,
29,
403,
12,
4566,
63,
1529,
29,
403,
12,
326,
1591,
29,
2698,
4965,
12,
3105,
29,
16,
12,
4178,
63,
2105,
63,
3702,
29,
403,
12,
326,
6358,
63,
908,
29,
2610,
2261,
23796,
3484,
1062,
931,
25412,
326,
15678,
63,
388,
3321,
63,
24032,
29,
549,
304,
267,
1613,
8,
8021,
3225,
12,
291,
2843,
826,
721,
458,
63,
2732,
63,
498,
63,
344,
12,
8763,
63,
4731,
63,
2732,
63,
498,
12,
326,
365,
63,
7817,
12,
1844,
12,
4566,
12,
4566,
63,
719,
12,
4566,
63,
751,
12,
4566,
63,
1529,
12,
326,
1591,
12,
3105,
12,
4178,
63,
2105,
63,
3702,
12,
6358,
63,
908,
12,
931,
12,
326,
298,
3098,
401,
31479,
12,
326,
15678,
63,
388,
3321,
63,
24032,
29,
17381,
63,
388,
3321,
63,
24032,
9,
339,
347,
1218,
63,
4623,
8,
277,
12,
5315,
63,
354,
12,
2323,
29,
403,
12,
1993,
2909,
29,
6592,
14,
3472,
12,
4592,
29,
403,
12,
1993,
4887,
63,
533,
534,
19547,
735,
267,
408,
267,
10560,
282,
892,
5315,
14,
4885,
849,
652,
1159,
16180,
315,
314,
8217,
14,
2047,
883,
267,
986,
12625,
14,
23539,
370,
1218,
5315,
315,
314,
26007,
14,
2047,
883,
2597,
986,
267,
282,
12625,
8463,
367,
2382,
314,
5315,
1077,
506,
16180,
12,
436,
267,
282,
10533,
2543,
13660,
4212,
314,
666,
1077,
506,
5489,
14,
398,
520,
466,
5315,
63,
354,
26,
1059,
267,
520,
635,
5315,
63,
354,
26,
710,
536,
402,
314,
892,
5315,
14,
398,
520,
466,
2323,
26,
1211,
267,
520,
635,
2323,
26,
10961,
2323,
370,
986,
3180,
543,
314,
1056,
370,
598,
3298,
14,
398,
520,
466,
2909,
26,
520,
533,
1705,
10914,
14,
458,
14,
2105,
14,
6592,
64,
267,
520,
635,
2909,
26,
710,
2909,
402,
314,
892,
5315,
14,
398,
520,
466,
4592,
26,
520,
533,
1705,
10914,
14,
458,
14,
5853,
14,
35,
9386,
18765,
12672,
64,
267,
520,
635,
4592,
26,
437,
883,
7439,
16543,
4592,
626,
911,
506,
6781,
370,
314,
892,
790,
2432,
315,
598,
3298,
14,
398,
520,
466,
4887,
63,
533,
26,
1059,
267,
520,
635,
4887,
63,
533,
26,
13083,
283,
19547,
7,
503,
283,
36,
1230,
2617,
63,
907,
4980,
25927,
63,
15004,
2477,
1370,
398,
408,
267,
1104,
63,
21636,
63,
4623,
354,
8,
4623,
63,
354,
9,
398,
340,
4592,
26,
288,
340,
2323,
26,
355,
2323,
59,
277,
14,
3780,
14,
5853,
63,
1291,
61,
275,
4592,
288,
587,
26,
355,
2323,
275,
469,
277,
14,
3780,
14,
5853,
63,
1291,
520,
4592,
93,
267,
340,
440,
2909,
26,
288,
2909,
275,
12625,
14,
3472,
267,
2909,
63,
6086,
275,
19990,
6592,
8463,
6598,
83,
1108,
6592,
8463,
3524,
586,
450,
2909,
9,
267,
340,
4887,
63,
533,
26,
288,
4887,
63,
533,
63,
6086,
275,
19990,
6408,
2543,
6598,
83,
1108,
6408,
2543,
3524,
3303,
450,
4887,
63,
533,
9,
267,
587,
26,
288,
4887,
63,
533,
63,
6086,
275,
2125,
267,
666,
275,
19990,
2499,
12311,
5688,
6598,
83,
5,
83,
1108,
2499,
12311,
5688,
3524,
326,
450,
334,
1985,
63,
6086,
12,
4887,
63,
533,
63,
6086,
430,
267,
1177,
275,
291,
14,
1875,
63,
1069,
8,
288,
283,
4013,
297,
664,
63,
1624,
24,
63,
585,
8,
4623,
63,
354,
395,
2323,
29,
2139,
12,
288,
666,
29,
362,
63,
1624,
24,
63,
585,
8,
576,
430,
267,
2396,
275,
1177,
14,
739,
342,
267,
340,
1177,
14,
1205,
508,
21292,
26,
288,
746,
291,
14,
3780,
14,
3494,
63,
981,
63,
705,
8,
355,
1177,
14,
1205,
12,
1177,
14,
5764,
12,
2396,
9,
267,
340,
1177,
14,
1205,
508,
1926,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
bollu/sandhi
|
modules/gr36/gnuradio-core/src/examples/volk_benchmark/volk_math.py
|
18
|
5153
|
#!/usr/bin/env python
from gnuradio import gr
import argparse
from volk_test_funcs import *
def multiply_const_cc(N):
k = 3.3
op = gr.multiply_const_cc(k)
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_gr_complex, 1, 1)
return tb
######################################################################
def multiply_const_ff(N):
k = 3.3
op = gr.multiply_const_ff(k)
tb = helper(N, op, gr.sizeof_float, gr.sizeof_float, 1, 1)
return tb
######################################################################
def multiply_cc(N):
op = gr.multiply_cc(1)
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_gr_complex, 2, 1)
return tb
######################################################################
def multiply_ff(N):
op = gr.multiply_ff()
tb = helper(N, op, gr.sizeof_float, gr.sizeof_float, 2, 1)
return tb
######################################################################
def add_ff(N):
op = gr.add_ff()
tb = helper(N, op, gr.sizeof_float, gr.sizeof_float, 2, 1)
return tb
######################################################################
def conjugate_cc(N):
op = gr.conjugate_cc()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_gr_complex, 1, 1)
return tb
######################################################################
def multiply_conjugate_cc(N):
try:
op = gr.multiply_conjugate_cc()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_gr_complex, 2, 1)
return tb
except AttributeError:
class s(gr.hier_block2):
def __init__(self):
gr.hier_block2.__init__(self, "s",
gr.io_signature(2, 2, gr.sizeof_gr_complex),
gr.io_signature(1, 1, gr.sizeof_gr_complex))
conj = gr.conjugate_cc()
mult = gr.multiply_cc()
self.connect((self,0), (mult,0))
self.connect((self,1), conj, (mult,1))
self.connect(mult, self)
op = s()
tb = helper(N, op, gr.sizeof_gr_complex, gr.sizeof_gr_complex, 2, 1)
return tb
######################################################################
def run_tests(func, N, iters):
print("Running Test: {0}".format(func.__name__))
try:
tb = func(N)
t = timeit(tb, iters)
res = format_results(func.__name__, t)
return res
except AttributeError:
print "\tCould not run test. Skipping."
return None
def main():
avail_tests = [multiply_const_cc,
multiply_const_ff,
multiply_cc,
multiply_ff,
add_ff,
conjugate_cc,
multiply_conjugate_cc]
desc='Time an operation to compare with other implementations. \
This program runs a simple GNU Radio flowgraph to test a \
particular math function, mostly to compare the \
Volk-optimized implementation versus a regular \
implementation. The results are stored to an SQLite database \
that can then be read by volk_plot.py to plot the differences.'
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('-L', '--label', type=str,
required=True, default=None,
help='Label of database table [default: %(default)s]')
parser.add_argument('-D', '--database', type=str,
default="volk_results.db",
help='Database file to store data in [default: %(default)s]')
parser.add_argument('-N', '--nitems', type=float,
default=1e9,
help='Number of items per iterations [default: %(default)s]')
parser.add_argument('-I', '--iterations', type=int,
default=20,
help='Number of iterations [default: %(default)s]')
parser.add_argument('--tests', type=int, nargs='*',
choices=xrange(len(avail_tests)),
help='A list of tests to run; can be a single test or a \
space-separated list.')
parser.add_argument('--list', action='store_true',
help='List the available tests')
parser.add_argument('--all', action='store_true',
help='Run all tests')
args = parser.parse_args()
if(args.list):
print "Available Tests to Run:"
print "\n".join(["\t{0}: {1}".format(i,f.__name__) for i,f in enumerate(avail_tests)])
sys.exit(0)
N = int(args.nitems)
iters = args.iterations
label = args.label
conn = create_connection(args.database)
new_table(conn, label)
if args.all:
tests = xrange(len(avail_tests))
else:
tests = args.tests
for test in tests:
res = run_tests(avail_tests[test], N, iters)
if res is not None:
replace_results(conn, label, N, iters, res)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
24526,
492,
7192,
199,
646,
7534,
199,
504,
5236,
75,
63,
396,
63,
9204,
492,
627,
199,
199,
318,
21699,
63,
1297,
63,
2055,
8,
46,
304,
272,
1022,
275,
650,
14,
19,
272,
1687,
275,
7192,
14,
13710,
63,
1297,
63,
2055,
8,
75,
9,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
1297,
63,
556,
8,
46,
304,
272,
1022,
275,
650,
14,
19,
272,
1687,
275,
7192,
14,
13710,
63,
1297,
63,
556,
8,
75,
9,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
2055,
8,
46,
304,
272,
1687,
275,
7192,
14,
13710,
63,
2055,
8,
17,
9,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
499,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
556,
8,
46,
304,
272,
1687,
275,
7192,
14,
13710,
63,
556,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1609,
12,
499,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
1050,
63,
556,
8,
46,
304,
272,
1687,
275,
7192,
14,
525,
63,
556,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1609,
12,
499,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
27246,
63,
2055,
8,
46,
304,
272,
1687,
275,
7192,
14,
26000,
63,
2055,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
26000,
63,
2055,
8,
46,
304,
272,
862,
26,
267,
1687,
275,
7192,
14,
13710,
63,
26000,
63,
2055,
342,
267,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
499,
12,
413,
9,
267,
372,
7070,
339,
871,
4281,
26,
267,
1021,
308,
8,
2587,
14,
31184,
63,
1457,
18,
304,
288,
347,
636,
826,
721,
277,
304,
355,
7192,
14,
31184,
63,
1457,
18,
855,
826,
721,
277,
12,
298,
83,
401,
3147,
7192,
14,
2308,
63,
5233,
8,
18,
12,
499,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
395,
3147,
7192,
14,
2308,
63,
5233,
8,
17,
12,
413,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
430,
355,
14643,
275,
7192,
14,
26000,
63,
2055,
342,
355,
20861,
275,
7192,
14,
13710,
63,
2055,
342,
355,
291,
14,
2242,
1332,
277,
12,
16,
395,
334,
14699,
12,
16,
430,
355,
291,
14,
2242,
1332,
277,
12,
17,
395,
14643,
12,
334,
14699,
12,
17,
430,
355,
291,
14,
2242,
8,
14699,
12,
291,
9,
398,
1687,
275,
308,
342,
267,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
499,
12,
413,
9,
267,
372,
7070,
421,
199,
18022,
199,
199,
318,
1255,
63,
2219,
8,
1532,
12,
653,
12,
284,
878,
304,
272,
870,
480,
9602,
1379,
26,
469,
16,
5469,
908,
8,
1532,
855,
354,
8964,
272,
862,
26,
267,
7070,
275,
2562,
8,
46,
9,
267,
307,
275,
900,
390,
8,
5842,
12,
284,
878,
9,
267,
522,
275,
1475,
63,
2604,
8,
1532,
855,
354,
3108,
307,
9,
267,
372,
522,
272,
871,
4281,
26,
267,
870,
1867,
84,
6531,
440,
1255,
511,
14,
8232,
4073,
2122,
267,
372,
488,
199,
199,
318,
2446,
837,
272,
21006,
63,
2219,
275,
359,
13710,
63,
1297,
63,
2055,
12,
673,
21699,
63,
1297,
63,
556,
12,
673,
21699,
63,
2055,
12,
673,
21699,
63,
556,
12,
673,
1050,
63,
556,
12,
673,
27246,
63,
2055,
12,
673,
21699,
63,
26000,
63,
2055,
61,
339,
4328,
534,
1366,
376,
3439,
370,
6540,
543,
1163,
12591,
14,
971,
881,
961,
2240,
7858,
282,
3486,
1664,
13514,
6369,
2180,
370,
511,
282,
971,
881,
6770,
3473,
805,
12,
19762,
370,
6540,
314,
221,
971,
881,
16171,
75,
13,
25499,
4514,
809,
25253,
282,
5578,
971,
881,
4514,
14,
710,
2058,
787,
5489,
370,
376,
19245,
3050,
971,
881,
626,
883,
2066,
506,
1586,
701,
5236,
75,
63,
2798,
14,
647,
370,
5137,
314,
15109,
3530,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
3257,
9,
272,
1798,
14,
525,
63,
2094,
3654,
44,
297,
2850,
1302,
297,
730,
29,
495,
12,
717,
1415,
29,
549,
12,
849,
29,
403,
12,
717,
1720,
534,
4314,
402,
3050,
1817,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
3654,
36,
297,
2850,
4659,
297,
730,
29,
495,
12,
717,
849,
628,
5650,
75,
63,
2604,
14,
697,
401,
717,
1720,
534,
7243,
570,
370,
3877,
666,
315,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
3654,
46,
297,
2850,
78,
1744,
297,
730,
29,
1609,
12,
717,
849,
29,
17,
69,
25,
12,
717,
1720,
534,
3259,
402,
2974,
1126,
10615,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
3654,
41,
297,
2850,
13570,
297,
730,
29,
442,
12,
717,
849,
29,
1165,
12,
717,
1720,
534,
3259,
402,
10615,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
4517,
2219,
297,
730,
29,
442,
12,
9237,
534,
7693,
717,
3415,
29,
21120,
8,
552,
8,
18961,
63,
2219,
1826,
717,
1720,
534,
33,
769,
402,
2295,
370,
1255,
27,
883,
506,
282,
2849,
511,
503,
282,
971,
2892,
4601,
13,
12794,
769,
2659,
272,
1798
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
24526,
492,
7192,
199,
646,
7534,
199,
504,
5236,
75,
63,
396,
63,
9204,
492,
627,
199,
199,
318,
21699,
63,
1297,
63,
2055,
8,
46,
304,
272,
1022,
275,
650,
14,
19,
272,
1687,
275,
7192,
14,
13710,
63,
1297,
63,
2055,
8,
75,
9,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
1297,
63,
556,
8,
46,
304,
272,
1022,
275,
650,
14,
19,
272,
1687,
275,
7192,
14,
13710,
63,
1297,
63,
556,
8,
75,
9,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1609,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
2055,
8,
46,
304,
272,
1687,
275,
7192,
14,
13710,
63,
2055,
8,
17,
9,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
499,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
556,
8,
46,
304,
272,
1687,
275,
7192,
14,
13710,
63,
556,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1609,
12,
499,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
1050,
63,
556,
8,
46,
304,
272,
1687,
275,
7192,
14,
525,
63,
556,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
1609,
12,
7192,
14,
12590,
63,
1609,
12,
499,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
27246,
63,
2055,
8,
46,
304,
272,
1687,
275,
7192,
14,
26000,
63,
2055,
342,
272,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
413,
12,
413,
9,
272,
372,
7070,
199,
199,
18022,
199,
199,
318,
21699,
63,
26000,
63,
2055,
8,
46,
304,
272,
862,
26,
267,
1687,
275,
7192,
14,
13710,
63,
26000,
63,
2055,
342,
267,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
499,
12,
413,
9,
267,
372,
7070,
339,
871,
4281,
26,
267,
1021,
308,
8,
2587,
14,
31184,
63,
1457,
18,
304,
288,
347,
636,
826,
721,
277,
304,
355,
7192,
14,
31184,
63,
1457,
18,
855,
826,
721,
277,
12,
298,
83,
401,
3147,
7192,
14,
2308,
63,
5233,
8,
18,
12,
499,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
395,
3147,
7192,
14,
2308,
63,
5233,
8,
17,
12,
413,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
430,
355,
14643,
275,
7192,
14,
26000,
63,
2055,
342,
355,
20861,
275,
7192,
14,
13710,
63,
2055,
342,
355,
291,
14,
2242,
1332,
277,
12,
16,
395,
334,
14699,
12,
16,
430,
355,
291,
14,
2242,
1332,
277,
12,
17,
395,
14643,
12,
334,
14699,
12,
17,
430,
355,
291,
14,
2242,
8,
14699,
12,
291,
9,
398,
1687,
275,
308,
342,
267,
7070,
275,
5922,
8,
46,
12,
1687,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
7192,
14,
12590,
63,
2587,
63,
5254,
12,
499,
12,
413,
9,
267,
372,
7070,
421,
199,
18022,
199,
199,
318,
1255,
63,
2219,
8,
1532,
12,
653,
12,
284,
878,
304,
272,
870,
480,
9602,
1379,
26,
469,
16,
5469,
908,
8,
1532,
855,
354,
8964,
272,
862,
26,
267,
7070,
275,
2562,
8,
46,
9,
267,
307,
275,
900,
390,
8,
5842,
12,
284,
878,
9,
267,
522,
275,
1475,
63,
2604,
8,
1532,
855,
354,
3108,
307,
9,
267,
372,
522,
272,
871,
4281,
26,
267,
870,
1867,
84,
6531,
440,
1255,
511,
14,
8232,
4073,
2122,
267,
372,
488,
199,
199,
318,
2446,
837,
272,
21006,
63,
2219,
275,
359,
13710,
63,
1297,
63,
2055,
12,
673,
21699,
63,
1297,
63,
556,
12,
673,
21699,
63,
2055,
12,
673,
21699,
63,
556,
12,
673,
1050,
63,
556,
12,
673,
27246,
63,
2055,
12,
673,
21699,
63,
26000,
63,
2055,
61,
339,
4328,
534,
1366,
376,
3439,
370,
6540,
543,
1163,
12591,
14,
971,
881,
961,
2240,
7858,
282,
3486,
1664,
13514,
6369,
2180,
370,
511,
282,
971,
881,
6770,
3473,
805,
12,
19762,
370,
6540,
314,
221,
971,
881,
16171,
75,
13,
25499,
4514,
809,
25253,
282,
5578,
971,
881,
4514,
14,
710,
2058,
787,
5489,
370,
376,
19245,
3050,
971,
881,
626,
883,
2066,
506,
1586,
701,
5236,
75,
63,
2798,
14,
647,
370,
5137,
314,
15109,
3530,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
29,
3257,
9,
272,
1798,
14,
525,
63,
2094,
3654,
44,
297,
2850,
1302,
297,
730,
29,
495,
12,
717,
1415,
29,
549,
12,
849,
29,
403,
12,
717,
1720,
534,
4314,
402,
3050,
1817,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
3654,
36,
297,
2850,
4659,
297,
730,
29,
495,
12,
717,
849,
628,
5650,
75,
63,
2604,
14,
697,
401,
717,
1720,
534,
7243,
570,
370,
3877,
666,
315,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
3654,
46,
297,
2850,
78,
1744,
297,
730,
29,
1609,
12,
717,
849,
29,
17,
69,
25,
12,
717,
1720,
534,
3259,
402,
2974,
1126,
10615,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
3654,
41,
297,
2850,
13570,
297,
730,
29,
442,
12,
717,
849,
29,
1165,
12,
717,
1720,
534,
3259,
402,
10615,
359,
885,
26,
2818,
885,
9,
83,
10374,
272,
1798,
14,
525,
63,
2094,
4517,
2219,
297,
730,
29,
442,
12,
9237,
534,
7693,
717,
3415,
29,
21120,
8,
552,
8,
18961,
63,
2219,
1826,
717,
1720,
534,
33,
769,
402,
2295,
370,
1255,
27,
883,
506,
282,
2849,
511,
503,
282,
971,
2892,
4601,
13,
12794,
769,
2659,
272,
1798,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dataDogma/Computer-Science
|
Django-MVP-page/venv/Lib/site-packages/pip/_vendor/requests/packages/urllib3/contrib/appengine.py
|
154
|
7938
|
from __future__ import absolute_import
import logging
import os
import warnings
from ..exceptions import (
HTTPError,
HTTPWarning,
MaxRetryError,
ProtocolError,
TimeoutError,
SSLError
)
from ..packages.six import BytesIO
from ..request import RequestMethods
from ..response import HTTPResponse
from ..util.timeout import Timeout
from ..util.retry import Retry
try:
from google.appengine.api import urlfetch
except ImportError:
urlfetch = None
log = logging.getLogger(__name__)
class AppEnginePlatformWarning(HTTPWarning):
pass
class AppEnginePlatformError(HTTPError):
pass
class AppEngineManager(RequestMethods):
"""
Connection manager for Google App Engine sandbox applications.
This manager uses the URLFetch service directly instead of using the
emulated httplib, and is subject to URLFetch limitations as described in
the App Engine documentation here:
https://cloud.google.com/appengine/docs/python/urlfetch
Notably it will raise an AppEnginePlatformError if:
* URLFetch is not available.
* If you attempt to use this on GAEv2 (Managed VMs), as full socket
support is available.
* If a request size is more than 10 megabytes.
* If a response size is more than 32 megabtyes.
* If you use an unsupported request method such as OPTIONS.
Beyond those cases, it will raise normal urllib3 errors.
"""
def __init__(self, headers=None, retries=None, validate_certificate=True):
if not urlfetch:
raise AppEnginePlatformError(
"URLFetch is not available in this environment.")
if is_prod_appengine_mvms():
raise AppEnginePlatformError(
"Use normal urllib3.PoolManager instead of AppEngineManager"
"on Managed VMs, as using URLFetch is not necessary in "
"this environment.")
warnings.warn(
"urllib3 is using URLFetch on Google App Engine sandbox instead "
"of sockets. To use sockets directly instead of URLFetch see "
"https://urllib3.readthedocs.org/en/latest/contrib.html.",
AppEnginePlatformWarning)
RequestMethods.__init__(self, headers)
self.validate_certificate = validate_certificate
self.retries = retries or Retry.DEFAULT
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
# Return False to re-raise any potential exceptions
return False
def urlopen(self, method, url, body=None, headers=None,
retries=None, redirect=True, timeout=Timeout.DEFAULT_TIMEOUT,
**response_kw):
retries = self._get_retries(retries, redirect)
try:
response = urlfetch.fetch(
url,
payload=body,
method=method,
headers=headers or {},
allow_truncated=False,
follow_redirects=(
redirect and
retries.redirect != 0 and
retries.total),
deadline=self._get_absolute_timeout(timeout),
validate_certificate=self.validate_certificate,
)
except urlfetch.DeadlineExceededError as e:
raise TimeoutError(self, e)
except urlfetch.InvalidURLError as e:
if 'too large' in str(e):
raise AppEnginePlatformError(
"URLFetch request too large, URLFetch only "
"supports requests up to 10mb in size.", e)
raise ProtocolError(e)
except urlfetch.DownloadError as e:
if 'Too many redirects' in str(e):
raise MaxRetryError(self, url, reason=e)
raise ProtocolError(e)
except urlfetch.ResponseTooLargeError as e:
raise AppEnginePlatformError(
"URLFetch response too large, URLFetch only supports"
"responses up to 32mb in size.", e)
except urlfetch.SSLCertificateError as e:
raise SSLError(e)
except urlfetch.InvalidMethodError as e:
raise AppEnginePlatformError(
"URLFetch does not support method: %s" % method, e)
http_response = self._urlfetch_response_to_http_response(
response, **response_kw)
# Check for redirect response
if (http_response.get_redirect_location() and
retries.raise_on_redirect and redirect):
raise MaxRetryError(self, url, "too many redirects")
# Check if we should retry the HTTP response.
if retries.is_forced_retry(method, status_code=http_response.status):
retries = retries.increment(
method, url, response=http_response, _pool=self)
log.info("Forced retry: %s", url)
retries.sleep()
return self.urlopen(
method, url,
body=body, headers=headers,
retries=retries, redirect=redirect,
timeout=timeout, **response_kw)
return http_response
def _urlfetch_response_to_http_response(self, urlfetch_resp, **response_kw):
if is_prod_appengine():
# Production GAE handles deflate encoding automatically, but does
# not remove the encoding header.
content_encoding = urlfetch_resp.headers.get('content-encoding')
if content_encoding == 'deflate':
del urlfetch_resp.headers['content-encoding']
transfer_encoding = urlfetch_resp.headers.get('transfer-encoding')
# We have a full response's content,
# so let's make sure we don't report ourselves as chunked data.
if transfer_encoding == 'chunked':
encodings = transfer_encoding.split(",")
encodings.remove('chunked')
urlfetch_resp.headers['transfer-encoding'] = ','.join(encodings)
return HTTPResponse(
# In order for decoding to work, we must present the content as
# a file-like object.
body=BytesIO(urlfetch_resp.content),
headers=urlfetch_resp.headers,
status=urlfetch_resp.status_code,
**response_kw
)
def _get_absolute_timeout(self, timeout):
if timeout is Timeout.DEFAULT_TIMEOUT:
return 5 # 5s is the default timeout for URLFetch.
if isinstance(timeout, Timeout):
if timeout._read is not timeout._connect:
warnings.warn(
"URLFetch does not support granular timeout settings, "
"reverting to total timeout.", AppEnginePlatformWarning)
return timeout.total
return timeout
def _get_retries(self, retries, redirect):
if not isinstance(retries, Retry):
retries = Retry.from_int(
retries, redirect=redirect, default=self.retries)
if retries.connect or retries.read or retries.redirect:
warnings.warn(
"URLFetch only supports total retries and does not "
"recognize connect, read, or redirect retry parameters.",
AppEnginePlatformWarning)
return retries
def is_appengine():
return (is_local_appengine() or
is_prod_appengine() or
is_prod_appengine_mvms())
def is_appengine_sandbox():
return is_appengine() and not is_prod_appengine_mvms()
def is_local_appengine():
return ('APPENGINE_RUNTIME' in os.environ and
'Development/' in os.environ['SERVER_SOFTWARE'])
def is_prod_appengine():
return ('APPENGINE_RUNTIME' in os.environ and
'Google App Engine/' in os.environ['SERVER_SOFTWARE'] and
not is_prod_appengine_mvms())
def is_prod_appengine_mvms():
return os.environ.get('GAE_VM', False) == 'true'
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
2050,
199,
646,
747,
199,
646,
3598,
199,
199,
504,
2508,
3924,
492,
334,
272,
15050,
12,
272,
3101,
3849,
12,
272,
8228,
12989,
547,
12,
272,
30797,
12,
272,
31886,
12,
272,
7799,
547,
199,
9,
199,
199,
504,
2508,
5154,
14,
4174,
492,
11808,
199,
504,
2508,
1069,
492,
4784,
10385,
199,
504,
2508,
1310,
492,
29034,
199,
504,
2508,
1974,
14,
2593,
492,
12878,
199,
504,
2508,
1974,
14,
7154,
492,
20506,
199,
199,
893,
26,
272,
687,
6233,
14,
15358,
14,
1246,
492,
7629,
29429,
199,
2590,
3545,
26,
272,
7629,
29429,
275,
488,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
4693,
8524,
10397,
3849,
8,
2856,
3849,
304,
272,
986,
421,
199,
533,
4693,
8524,
10397,
547,
8,
12815,
304,
272,
986,
421,
199,
533,
4693,
8524,
2988,
8,
2017,
10385,
304,
272,
408,
272,
8113,
5256,
367,
4475,
4693,
12580,
19699,
13103,
14,
339,
961,
5256,
4440,
314,
2851,
11135,
2435,
5370,
3140,
402,
1808,
314,
272,
17423,
972,
8809,
12,
436,
365,
5420,
370,
2851,
11135,
4204,
465,
11736,
315,
272,
314,
4693,
12580,
3794,
2348,
26,
398,
4178,
921,
4091,
14,
3098,
14,
957,
15,
15358,
15,
4757,
15,
1548,
15,
300,
29429,
339,
2832,
6665,
652,
911,
746,
376,
4693,
8524,
10397,
547,
340,
26,
267,
627,
2851,
11135,
365,
440,
2808,
14,
267,
627,
982,
1265,
7427,
370,
675,
642,
641,
598,
12500,
86,
18,
334,
22625,
30641,
395,
465,
2615,
2838,
881,
2291,
365,
2808,
14,
267,
627,
982,
282,
1056,
1568,
365,
1655,
2419,
1616,
562,
71,
27601,
14,
267,
627,
982,
282,
1177,
1568,
365,
1655,
2419,
4337,
562,
71,
371,
369,
397,
14,
267,
627,
982,
1265,
675,
376,
16313,
1056,
1083,
4066,
465,
23860,
14,
339,
6423,
17666,
5204,
5560,
12,
652,
911,
746,
3293,
4011,
19,
2552,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
29,
403,
12,
10086,
29,
403,
12,
4107,
63,
6999,
29,
549,
304,
267,
340,
440,
7629,
29429,
26,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
2632,
11135,
365,
440,
2808,
315,
642,
3734,
2685,
398,
340,
365,
63,
8788,
63,
15358,
63,
12393,
706,
837,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
6119,
3293,
4011,
19,
14,
5453,
2988,
3140,
402,
4693,
8524,
2988,
2,
355,
298,
265,
4688,
6028,
30641,
12,
465,
1808,
2851,
11135,
365,
440,
5784,
315,
298,
355,
298,
3749,
3734,
2685,
398,
3598,
14,
4050,
8,
288,
298,
4078,
19,
365,
1808,
2851,
11135,
641,
4475,
4693,
12580,
19699,
3140,
298,
288,
298,
1618,
18772,
14,
4005,
675,
18772,
5370,
3140,
402,
2851,
11135,
1937,
298,
288,
298,
2859,
921,
4078,
19,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
2828,
14,
1360,
4765,
288,
4693,
8524,
10397,
3849,
9,
398,
4784,
10385,
855,
826,
721,
277,
12,
2323,
9,
267,
291,
14,
3502,
63,
6999,
275,
4107,
63,
6999,
398,
291,
14,
10937,
275,
10086,
503,
20506,
14,
3472,
339,
347,
636,
4200,
721,
277,
304,
267,
372,
291,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
327,
1432,
756,
370,
295,
13,
3730,
1263,
12330,
4967,
267,
372,
756,
339,
347,
18279,
8,
277,
12,
1083,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
355,
10086,
29,
403,
12,
4660,
29,
549,
12,
2653,
29,
6372,
14,
3472,
63,
8899,
12,
355,
1011,
1310,
63,
829,
304,
398,
10086,
275,
291,
423,
362,
63,
10937,
8,
10937,
12,
4660,
9,
398,
862,
26,
288,
1177,
275,
7629,
29429,
14,
3535,
8,
355,
1166,
12,
355,
4886,
29,
2030,
12,
355,
1083,
29,
765,
12,
355,
2323,
29,
2139,
503,
5479,
355,
2040,
63,
19347,
29,
797,
12,
355,
2035,
63,
13607,
2687,
490,
4660,
436,
490,
10086,
14,
4876,
1137,
378,
436,
490,
10086,
14,
2923,
395,
355,
23081,
29,
277,
423,
362,
63,
6116,
63,
2593,
8,
2593,
395,
355,
4107,
63,
6999,
29,
277,
14,
3502,
63,
6999,
12,
288,
776,
267,
871,
7629,
29429,
14,
22147,
604,
24748,
547,
465,
325,
26,
288,
746,
31886,
8,
277,
12,
325,
9,
398,
871,
7629,
29429,
14,
3364,
31475,
465,
325,
26,
288,
340,
283,
7354,
7031,
7,
315,
620,
8,
69,
304,
355,
746,
4693,
8524,
10397,
547,
8,
490,
298,
2632,
11135,
1056,
4634,
7031,
12,
2851,
11135,
1454,
298,
490,
298,
9823,
4145,
1536,
370,
1616,
887,
315,
1568,
4765,
325,
9,
288,
746,
30797,
8,
69,
9,
398,
871,
7629,
29429,
14,
11950,
547,
465,
325,
26,
288,
340,
283,
13749,
5002,
17784,
7,
315,
620,
8,
69,
304,
355,
746,
8228,
12989,
547,
8,
277,
12,
1166,
12,
4499,
29,
69,
9,
288,
746,
30797,
8,
69,
9,
398,
871,
7629,
29429,
14,
2364,
13749,
17149,
547,
465,
325,
26,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
2632,
11135,
1177,
4634,
7031,
12,
2851,
11135,
1454,
5171,
2,
355,
298,
10360,
1536,
370,
4337,
887,
315,
1568,
4765,
325,
9,
398,
871,
7629,
29429,
14,
5413,
11414,
547,
465,
325,
26,
288,
746,
7799,
547,
8,
69,
9,
398,
871,
7629,
29429,
14,
3364,
3767,
547,
465,
325,
26,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
2632,
11135,
1630,
440,
2291,
1083,
26,
450,
83,
2,
450,
1083,
12,
325,
9,
398,
1455,
63,
1310,
275,
291,
423,
300,
29429,
63,
1310,
63,
475,
63,
1014,
63,
1310,
8,
288,
1177,
12,
1011,
1310,
63,
829,
9,
398,
327,
2670,
367,
4660,
1177,
267,
340,
334,
1014,
63,
1310,
14,
362,
63,
4876,
63,
1985,
342,
436,
355,
10086,
14,
3730,
63,
265,
63,
4876,
436,
4660,
304,
288,
746,
8228,
12989,
547,
8,
277,
12,
1166,
12,
298,
7354,
5002,
17784,
531,
398,
327,
2670,
340,
781,
1077,
7269,
314,
3101,
1177,
14,
267,
340,
10086,
14,
374,
63,
28074,
63,
7154,
8,
765,
12,
2004,
63,
600,
29,
1014,
63,
1310,
14,
1205,
304,
288,
10086,
275,
10086,
14,
9728,
8,
355,
1083,
12
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
2050,
199,
646,
747,
199,
646,
3598,
199,
199,
504,
2508,
3924,
492,
334,
272,
15050,
12,
272,
3101,
3849,
12,
272,
8228,
12989,
547,
12,
272,
30797,
12,
272,
31886,
12,
272,
7799,
547,
199,
9,
199,
199,
504,
2508,
5154,
14,
4174,
492,
11808,
199,
504,
2508,
1069,
492,
4784,
10385,
199,
504,
2508,
1310,
492,
29034,
199,
504,
2508,
1974,
14,
2593,
492,
12878,
199,
504,
2508,
1974,
14,
7154,
492,
20506,
199,
199,
893,
26,
272,
687,
6233,
14,
15358,
14,
1246,
492,
7629,
29429,
199,
2590,
3545,
26,
272,
7629,
29429,
275,
488,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
4693,
8524,
10397,
3849,
8,
2856,
3849,
304,
272,
986,
421,
199,
533,
4693,
8524,
10397,
547,
8,
12815,
304,
272,
986,
421,
199,
533,
4693,
8524,
2988,
8,
2017,
10385,
304,
272,
408,
272,
8113,
5256,
367,
4475,
4693,
12580,
19699,
13103,
14,
339,
961,
5256,
4440,
314,
2851,
11135,
2435,
5370,
3140,
402,
1808,
314,
272,
17423,
972,
8809,
12,
436,
365,
5420,
370,
2851,
11135,
4204,
465,
11736,
315,
272,
314,
4693,
12580,
3794,
2348,
26,
398,
4178,
921,
4091,
14,
3098,
14,
957,
15,
15358,
15,
4757,
15,
1548,
15,
300,
29429,
339,
2832,
6665,
652,
911,
746,
376,
4693,
8524,
10397,
547,
340,
26,
267,
627,
2851,
11135,
365,
440,
2808,
14,
267,
627,
982,
1265,
7427,
370,
675,
642,
641,
598,
12500,
86,
18,
334,
22625,
30641,
395,
465,
2615,
2838,
881,
2291,
365,
2808,
14,
267,
627,
982,
282,
1056,
1568,
365,
1655,
2419,
1616,
562,
71,
27601,
14,
267,
627,
982,
282,
1177,
1568,
365,
1655,
2419,
4337,
562,
71,
371,
369,
397,
14,
267,
627,
982,
1265,
675,
376,
16313,
1056,
1083,
4066,
465,
23860,
14,
339,
6423,
17666,
5204,
5560,
12,
652,
911,
746,
3293,
4011,
19,
2552,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2323,
29,
403,
12,
10086,
29,
403,
12,
4107,
63,
6999,
29,
549,
304,
267,
340,
440,
7629,
29429,
26,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
2632,
11135,
365,
440,
2808,
315,
642,
3734,
2685,
398,
340,
365,
63,
8788,
63,
15358,
63,
12393,
706,
837,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
6119,
3293,
4011,
19,
14,
5453,
2988,
3140,
402,
4693,
8524,
2988,
2,
355,
298,
265,
4688,
6028,
30641,
12,
465,
1808,
2851,
11135,
365,
440,
5784,
315,
298,
355,
298,
3749,
3734,
2685,
398,
3598,
14,
4050,
8,
288,
298,
4078,
19,
365,
1808,
2851,
11135,
641,
4475,
4693,
12580,
19699,
3140,
298,
288,
298,
1618,
18772,
14,
4005,
675,
18772,
5370,
3140,
402,
2851,
11135,
1937,
298,
288,
298,
2859,
921,
4078,
19,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
2828,
14,
1360,
4765,
288,
4693,
8524,
10397,
3849,
9,
398,
4784,
10385,
855,
826,
721,
277,
12,
2323,
9,
267,
291,
14,
3502,
63,
6999,
275,
4107,
63,
6999,
398,
291,
14,
10937,
275,
10086,
503,
20506,
14,
3472,
339,
347,
636,
4200,
721,
277,
304,
267,
372,
291,
339,
347,
636,
2224,
721,
277,
12,
3178,
63,
466,
12,
3178,
63,
637,
12,
3178,
63,
5842,
304,
267,
327,
1432,
756,
370,
295,
13,
3730,
1263,
12330,
4967,
267,
372,
756,
339,
347,
18279,
8,
277,
12,
1083,
12,
1166,
12,
2396,
29,
403,
12,
2323,
29,
403,
12,
355,
10086,
29,
403,
12,
4660,
29,
549,
12,
2653,
29,
6372,
14,
3472,
63,
8899,
12,
355,
1011,
1310,
63,
829,
304,
398,
10086,
275,
291,
423,
362,
63,
10937,
8,
10937,
12,
4660,
9,
398,
862,
26,
288,
1177,
275,
7629,
29429,
14,
3535,
8,
355,
1166,
12,
355,
4886,
29,
2030,
12,
355,
1083,
29,
765,
12,
355,
2323,
29,
2139,
503,
5479,
355,
2040,
63,
19347,
29,
797,
12,
355,
2035,
63,
13607,
2687,
490,
4660,
436,
490,
10086,
14,
4876,
1137,
378,
436,
490,
10086,
14,
2923,
395,
355,
23081,
29,
277,
423,
362,
63,
6116,
63,
2593,
8,
2593,
395,
355,
4107,
63,
6999,
29,
277,
14,
3502,
63,
6999,
12,
288,
776,
267,
871,
7629,
29429,
14,
22147,
604,
24748,
547,
465,
325,
26,
288,
746,
31886,
8,
277,
12,
325,
9,
398,
871,
7629,
29429,
14,
3364,
31475,
465,
325,
26,
288,
340,
283,
7354,
7031,
7,
315,
620,
8,
69,
304,
355,
746,
4693,
8524,
10397,
547,
8,
490,
298,
2632,
11135,
1056,
4634,
7031,
12,
2851,
11135,
1454,
298,
490,
298,
9823,
4145,
1536,
370,
1616,
887,
315,
1568,
4765,
325,
9,
288,
746,
30797,
8,
69,
9,
398,
871,
7629,
29429,
14,
11950,
547,
465,
325,
26,
288,
340,
283,
13749,
5002,
17784,
7,
315,
620,
8,
69,
304,
355,
746,
8228,
12989,
547,
8,
277,
12,
1166,
12,
4499,
29,
69,
9,
288,
746,
30797,
8,
69,
9,
398,
871,
7629,
29429,
14,
2364,
13749,
17149,
547,
465,
325,
26,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
2632,
11135,
1177,
4634,
7031,
12,
2851,
11135,
1454,
5171,
2,
355,
298,
10360,
1536,
370,
4337,
887,
315,
1568,
4765,
325,
9,
398,
871,
7629,
29429,
14,
5413,
11414,
547,
465,
325,
26,
288,
746,
7799,
547,
8,
69,
9,
398,
871,
7629,
29429,
14,
3364,
3767,
547,
465,
325,
26,
288,
746,
4693,
8524,
10397,
547,
8,
355,
298,
2632,
11135,
1630,
440,
2291,
1083,
26,
450,
83,
2,
450,
1083,
12,
325,
9,
398,
1455,
63,
1310,
275,
291,
423,
300,
29429,
63,
1310,
63,
475,
63,
1014,
63,
1310,
8,
288,
1177,
12,
1011,
1310,
63,
829,
9,
398,
327,
2670,
367,
4660,
1177,
267,
340,
334,
1014,
63,
1310,
14,
362,
63,
4876,
63,
1985,
342,
436,
355,
10086,
14,
3730,
63,
265,
63,
4876,
436,
4660,
304,
288,
746,
8228,
12989,
547,
8,
277,
12,
1166,
12,
298,
7354,
5002,
17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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
] |
jkorell/PTVS
|
Python/Tests/TestData/VirtualEnv/env/Lib/encodings/palmos.py
|
96
|
3019
|
""" Python Character Mapping Codec for PalmOS 3.5.
Written by Sjoerd Mullender (sjoerd@acm.org); based on iso8859_15.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_map)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_map)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_map)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='palmos',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Map
decoding_map = codecs.make_identity_dict(range(256))
# The PalmOS character set is mostly iso-8859-1 with some differences.
decoding_map.update({
0x0080: 0x20ac, # EURO SIGN
0x0082: 0x201a, # SINGLE LOW-9 QUOTATION MARK
0x0083: 0x0192, # LATIN SMALL LETTER F WITH HOOK
0x0084: 0x201e, # DOUBLE LOW-9 QUOTATION MARK
0x0085: 0x2026, # HORIZONTAL ELLIPSIS
0x0086: 0x2020, # DAGGER
0x0087: 0x2021, # DOUBLE DAGGER
0x0088: 0x02c6, # MODIFIER LETTER CIRCUMFLEX ACCENT
0x0089: 0x2030, # PER MILLE SIGN
0x008a: 0x0160, # LATIN CAPITAL LETTER S WITH CARON
0x008b: 0x2039, # SINGLE LEFT-POINTING ANGLE QUOTATION MARK
0x008c: 0x0152, # LATIN CAPITAL LIGATURE OE
0x008d: 0x2666, # BLACK DIAMOND SUIT
0x008e: 0x2663, # BLACK CLUB SUIT
0x008f: 0x2665, # BLACK HEART SUIT
0x0090: 0x2660, # BLACK SPADE SUIT
0x0091: 0x2018, # LEFT SINGLE QUOTATION MARK
0x0092: 0x2019, # RIGHT SINGLE QUOTATION MARK
0x0093: 0x201c, # LEFT DOUBLE QUOTATION MARK
0x0094: 0x201d, # RIGHT DOUBLE QUOTATION MARK
0x0095: 0x2022, # BULLET
0x0096: 0x2013, # EN DASH
0x0097: 0x2014, # EM DASH
0x0098: 0x02dc, # SMALL TILDE
0x0099: 0x2122, # TRADE MARK SIGN
0x009a: 0x0161, # LATIN SMALL LETTER S WITH CARON
0x009c: 0x0153, # LATIN SMALL LIGATURE OE
0x009f: 0x0178, # LATIN CAPITAL LETTER Y WITH DIAERESIS
})
### Encoding Map
encoding_map = codecs.make_encoding_map(decoding_map)
|
apache-2.0
|
[
624,
2018,
17660,
12340,
13732,
367,
510,
279,
77,
3100,
650,
14,
21,
14,
2999,
199,
32329,
701,
428,
743,
281,
68,
22578,
24912,
334,
83,
743,
281,
68,
32,
645,
77,
14,
1308,
2736,
4079,
641,
11601,
4830,
63,
1046,
14,
647,
14,
2999,
199,
624,
23662,
2999,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
533,
13732,
8,
8933,
14,
8818,
304,
1128,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
2958,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1130,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
16703,
304,
1128,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1130,
2788,
16,
61,
2999,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
1128,
986,
2999,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
1128,
986,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
21516,
16908,
297,
1039,
3752,
29,
8818,
1252,
2143,
12,
1039,
4849,
29,
8818,
1252,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
2999,
199,
5680,
27368,
9672,
2999,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
2999,
199,
3,
710,
510,
279,
77,
3100,
4528,
663,
365,
19762,
11601,
13,
4830,
13,
17,
543,
2005,
15109,
14,
202,
199,
12796,
63,
1130,
14,
873,
2561,
1039,
378,
88,
23686,
26,
378,
88,
1165,
645,
12,
327,
755,
26007,
1092,
5056,
1039,
378,
88,
383,
2564,
26,
378,
88,
1797,
65,
12,
327,
755,
8655,
21359,
13,
25,
11830,
8132,
1039,
378,
88,
383,
2658,
26,
378,
88,
614,
2942,
12,
327,
755,
1948,
2516,
1578,
481,
1663,
7781,
3593,
1039,
378,
88,
30935,
26,
378,
88,
1797,
69,
12,
327,
755,
5681,
21359,
13,
25,
11830,
8132,
1039,
378,
88,
383,
2426,
26,
378,
88,
31171,
12,
327,
755,
8724,
662,
4464,
17772,
1039,
378,
88,
31743,
26,
378,
88,
13934,
12,
327,
755,
19666,
11784,
1039,
378,
88,
383,
1555,
26,
378,
88,
22150,
12,
327,
755,
5681,
19666,
11784,
1039,
378,
88,
31419,
26,
378,
88,
996,
67,
22,
12,
327,
755,
10362,
1914,
29315,
1578,
10040,
17175,
1039,
378,
88,
383,
1407,
26,
378,
88,
32235,
12,
327,
755,
13873,
603,
1193,
906,
5056,
1039,
378,
88,
8662,
65,
26,
378,
88,
32207,
12,
327,
755,
1948,
2678,
1578,
428,
1663,
17913,
1039,
378,
88,
8662,
66,
26,
378,
88,
1165,
1355,
12,
327,
755,
8655,
6578,
13,
18940,
18827,
11830,
8132,
1039,
378,
88,
8662,
67,
26,
378,
88,
614,
2528,
12,
327,
755,
1948,
2678,
27427,
593,
37,
1039,
378,
88,
8662,
68,
26,
378,
88,
9969,
22,
12,
327,
755,
26774,
5266,
1156,
615,
36,
5698,
649,
1039,
378,
88,
8662,
69,
26,
378,
88,
9969,
19,
12,
327,
755,
26774,
13354,
2533,
5698,
649,
1039,
378,
88,
8662,
70,
26,
378,
88,
9969,
21,
12,
327,
755,
26774,
8378,
2294,
5698,
649,
1039,
378,
88,
28875,
26,
378,
88,
9969,
16,
12,
327,
755,
26774,
6988,
33,
1093,
5698,
649,
1039,
378,
88,
383,
3328,
26,
378,
88,
12682,
12,
327,
755,
6578,
8655,
11830,
8132,
1039,
378,
88,
383,
2942,
26,
378,
88,
14982,
12,
327,
755,
7052,
8655,
11830,
8132,
1039,
378,
88,
383,
3129,
26,
378,
88,
1797,
67,
12,
327,
755,
6578,
5681,
11830,
8132,
1039,
378,
88,
383,
2635,
26,
378,
88,
1797,
68,
12,
327,
755,
7052,
5681,
11830,
8132,
1039,
378,
88,
383,
2720,
26,
378,
88,
13859,
12,
327,
755,
699,
32243,
1039,
378,
88,
383,
2534,
26,
378,
88,
6965,
12,
327,
755,
5070,
577,
8100,
1039,
378,
88,
383,
2576,
26,
378,
88,
7280,
12,
327,
755,
26512,
577,
8100,
1039,
378,
88,
383,
2905,
26,
378,
88,
996,
3833,
12,
327,
755,
2516,
14102,
1039,
378,
88,
29660,
26,
378,
88,
18,
7507,
12,
327,
755,
377,
2847,
1093,
8132,
5056,
1039,
378,
88,
8581,
65,
26,
378,
88,
27793,
12,
327,
755,
1948,
2516,
1578,
428,
1663,
17913,
1039,
378,
88,
8581,
67,
26,
378,
88,
614,
2481,
12,
327,
755,
1948,
2516,
27427,
593,
37,
1039,
378,
88,
8581,
70,
26,
378,
88,
614,
2277,
12,
327,
755,
1948,
2678,
1578,
1488,
1663,
9680,
202,
199,
1552,
2999,
199,
5680,
19694,
9672,
2999,
199,
2991,
63,
1130,
275,
6010,
14,
1875,
63,
2991,
63,
1130,
8,
12796,
63,
1130,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
17660,
12340,
13732,
367,
510,
279,
77,
3100,
650,
14,
21,
14,
2999,
199,
32329,
701,
428,
743,
281,
68,
22578,
24912,
334,
83,
743,
281,
68,
32,
645,
77,
14,
1308,
2736,
4079,
641,
11601,
4830,
63,
1046,
14,
647,
14,
2999,
199,
624,
23662,
2999,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
533,
13732,
8,
8933,
14,
8818,
304,
1128,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1130,
9,
2958,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1130,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1130,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
16703,
304,
1128,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1130,
2788,
16,
61,
2999,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
1128,
986,
2999,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
1128,
986,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
21516,
16908,
297,
1039,
3752,
29,
8818,
1252,
2143,
12,
1039,
4849,
29,
8818,
1252,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
2999,
199,
5680,
27368,
9672,
2999,
199,
12796,
63,
1130,
275,
6010,
14,
1875,
63,
5582,
63,
807,
8,
1842,
8,
3912,
430,
2999,
199,
3,
710,
510,
279,
77,
3100,
4528,
663,
365,
19762,
11601,
13,
4830,
13,
17,
543,
2005,
15109,
14,
202,
199,
12796,
63,
1130,
14,
873,
2561,
1039,
378,
88,
23686,
26,
378,
88,
1165,
645,
12,
327,
755,
26007,
1092,
5056,
1039,
378,
88,
383,
2564,
26,
378,
88,
1797,
65,
12,
327,
755,
8655,
21359,
13,
25,
11830,
8132,
1039,
378,
88,
383,
2658,
26,
378,
88,
614,
2942,
12,
327,
755,
1948,
2516,
1578,
481,
1663,
7781,
3593,
1039,
378,
88,
30935,
26,
378,
88,
1797,
69,
12,
327,
755,
5681,
21359,
13,
25,
11830,
8132,
1039,
378,
88,
383,
2426,
26,
378,
88,
31171,
12,
327,
755,
8724,
662,
4464,
17772,
1039,
378,
88,
31743,
26,
378,
88,
13934,
12,
327,
755,
19666,
11784,
1039,
378,
88,
383,
1555,
26,
378,
88,
22150,
12,
327,
755,
5681,
19666,
11784,
1039,
378,
88,
31419,
26,
378,
88,
996,
67,
22,
12,
327,
755,
10362,
1914,
29315,
1578,
10040,
17175,
1039,
378,
88,
383,
1407,
26,
378,
88,
32235,
12,
327,
755,
13873,
603,
1193,
906,
5056,
1039,
378,
88,
8662,
65,
26,
378,
88,
32207,
12,
327,
755,
1948,
2678,
1578,
428,
1663,
17913,
1039,
378,
88,
8662,
66,
26,
378,
88,
1165,
1355,
12,
327,
755,
8655,
6578,
13,
18940,
18827,
11830,
8132,
1039,
378,
88,
8662,
67,
26,
378,
88,
614,
2528,
12,
327,
755,
1948,
2678,
27427,
593,
37,
1039,
378,
88,
8662,
68,
26,
378,
88,
9969,
22,
12,
327,
755,
26774,
5266,
1156,
615,
36,
5698,
649,
1039,
378,
88,
8662,
69,
26,
378,
88,
9969,
19,
12,
327,
755,
26774,
13354,
2533,
5698,
649,
1039,
378,
88,
8662,
70,
26,
378,
88,
9969,
21,
12,
327,
755,
26774,
8378,
2294,
5698,
649,
1039,
378,
88,
28875,
26,
378,
88,
9969,
16,
12,
327,
755,
26774,
6988,
33,
1093,
5698,
649,
1039,
378,
88,
383,
3328,
26,
378,
88,
12682,
12,
327,
755,
6578,
8655,
11830,
8132,
1039,
378,
88,
383,
2942,
26,
378,
88,
14982,
12,
327,
755,
7052,
8655,
11830,
8132,
1039,
378,
88,
383,
3129,
26,
378,
88,
1797,
67,
12,
327,
755,
6578,
5681,
11830,
8132,
1039,
378,
88,
383,
2635,
26,
378,
88,
1797,
68,
12,
327,
755,
7052,
5681,
11830,
8132,
1039,
378,
88,
383,
2720,
26,
378,
88,
13859,
12,
327,
755,
699,
32243,
1039,
378,
88,
383,
2534,
26,
378,
88,
6965,
12,
327,
755,
5070,
577,
8100,
1039,
378,
88,
383,
2576,
26,
378,
88,
7280,
12,
327,
755,
26512,
577,
8100,
1039,
378,
88,
383,
2905,
26,
378,
88,
996,
3833,
12,
327,
755,
2516,
14102,
1039,
378,
88,
29660,
26,
378,
88,
18,
7507,
12,
327,
755,
377,
2847,
1093,
8132,
5056,
1039,
378,
88,
8581,
65,
26,
378,
88,
27793,
12,
327,
755,
1948,
2516,
1578,
428,
1663,
17913,
1039,
378,
88,
8581,
67,
26,
378,
88,
614,
2481,
12,
327,
755,
1948,
2516,
27427,
593,
37,
1039,
378,
88,
8581,
70,
26,
378,
88,
614,
2277,
12,
327,
755,
1948,
2678,
1578,
1488,
1663,
9680,
202,
199,
1552,
2999,
199,
5680,
19694,
9672,
2999,
199,
2991,
63,
1130,
275,
6010,
14,
1875,
63,
2991,
63,
1130,
8,
12796,
63,
1130,
9,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
chewxy/cu
|
cmd/gencudnn/parse.py
|
1
|
3705
|
from bs4 import BeautifulSoup
import requests
import re
import sys
import os
inputs ={}
outputs = {}
ios = {}
docs = {}
def get():
if os.path.isfile("cache/docs.html"):
with open("cache/docs.html", 'r') as f:
print("Using cache", file=sys.stderr)
return f.read()
r = requests.get("http://docs.nvidia.com/deeplearning/sdk/cudnn-developer-guide/index.html")
with open("cache/docs.html", 'w') as f:
f.write(r.text)
return r.text
def main():
txt = get()
soup = BeautifulSoup(txt, "html5lib")
contents = soup.find_all(id="api-introduction")
topics = contents[0].find_all(class_="topic concept nested1")
for topic in topics:
rawFnName = topic.find_all(class_='title topictitle2')[0].text
try:
fnName = re.search('cudnn.+$', rawFnName).group(0)
except AttributeError as e:
print("rawFnName: {}".format(rawFnName), file=sys.stderr)
continue
try:
paramsDL = topic.find_all(class_='dl')[0] # first definition list is params
except IndexError:
print("rawFnName: {} - topic has no dl class".format(fnName), file=sys.stderr)
continue
# check previous
if paramsDL.previous_sibling.previous_sibling.text != "Parameters":
print("rawFnName: {} has no params::: {}".format(fnName, paramsDL.previous_sibling), file=sys.stderr)
continue
params = paramsDL.find_all(class_='dt dlterm') # name
paramsDesc = paramsDL.find_all(class_='dd') # use type
paramUse = []
for d in paramsDesc:
try:
use = d.find_all(class_='ph i')[0].text
except IndexError as e:
use = "Input"
paramUse.append(use)
if len(params) != len(paramUse):
print("rawFnName: {} - differing params and use cases".format(fnName), file=sys.stderr)
continue
inputParams = [p.text.strip() for i, p in enumerate(params) if (paramUse[i].strip()=='Input') or (paramUse[i].strip()=="Inputs")]
outputParams = [p.text.strip() for i, p in enumerate(params) if (paramUse[i].strip()=='Output') or (paramUse[i].strip()=="Outputs")]
ioParams = [p.text.strip() for i, p in enumerate(params) if paramUse[i].strip()=='Input/Output']
inputs[fnName] = inputParams
outputs[fnName] = outputParams
ios[fnName] = ioParams
# extract docs
try:
docbody = topic.find_all(class_='body conbody')[0]
except IndexError:
print("fnName: {} - no body".format(fnName), file=sys.stderr)
continue
# clear is better than clever.
doc = docbody.find_all("p")[0].text
doc = doc.replace("\n", "")
doc = re.sub("\t+", " ", doc)
doc = re.sub("\s+", " ", doc)
doc = doc.replace('"', '`')
doc = doc.replace("This function", fnName)
doc = doc.replace("This routine", fnName)
doc = doc.replace("This", fnName)
doc = doc.strip()
docs[fnName] = doc
# write the go file
print("package main")
print("var inputParams = map[string][]string{")
for k, v in inputs.items():
if len(v) == 0: continue
print('"{}": {{ '.format(k), end="")
for inp in v :
split = inp.split(",")
for s in split:
print('"{}", '.format(s.strip()), end="")
print("},")
print("}")
print("var outputParams = map[string][]string{")
for k, v in outputs.items():
if len(v) == 0: continue
print('"{}": {{ '.format(k), end="")
for inp in v :
split = inp.split(",")
for s in split:
print('"{}", '.format(s.strip()), end="")
print("},")
print("}")
print("var ioParams = map[string][]string{")
for k, v in ios.items():
if len(v) == 0: continue
print('"{}": {{ '.format(k), end="")
for inp in v :
split = inp.split(",")
for s in split:
print('"{}", '.format(s.strip()), end="")
print("},")
print("}")
print("var docs = map[string]string{")
for k, v in docs.items():
print('"{}": "{}",'.format(k, v.strip()))
print("}")
main()
|
mit
|
[
504,
9922,
20,
492,
17132,
199,
646,
4145,
199,
646,
295,
199,
646,
984,
199,
646,
747,
199,
199,
3711,
275,
2440,
199,
4467,
275,
1052,
199,
9207,
275,
1052,
199,
4757,
275,
1052,
199,
199,
318,
664,
837,
199,
198,
692,
747,
14,
515,
14,
6292,
480,
1637,
15,
4757,
14,
1360,
2349,
507,
198,
1045,
1551,
480,
1637,
15,
4757,
14,
1360,
401,
283,
82,
358,
465,
289,
26,
686,
198,
1361,
480,
10369,
2581,
401,
570,
29,
1274,
14,
3083,
9,
686,
198,
1107,
289,
14,
739,
342,
199,
198,
82,
275,
4145,
14,
362,
480,
1014,
921,
4757,
14,
78,
433,
2391,
14,
957,
15,
16131,
10546,
15,
9277,
15,
27934,
13,
11071,
13,
17348,
15,
1080,
14,
1360,
531,
199,
198,
1045,
1551,
480,
1637,
15,
4757,
14,
1360,
401,
283,
87,
358,
465,
289,
26,
507,
198,
70,
14,
952,
8,
82,
14,
505,
9,
199,
198,
1107,
519,
14,
505,
199,
199,
318,
2446,
837,
199,
198,
2424,
275,
664,
342,
199,
198,
9317,
275,
17132,
8,
2424,
12,
298,
1360,
21,
773,
531,
199,
198,
4407,
275,
9108,
14,
1623,
63,
452,
8,
344,
628,
1246,
13,
18206,
5199,
531,
199,
198,
11299,
275,
4072,
59,
16,
1055,
1623,
63,
452,
8,
533,
63,
628,
5746,
19834,
6032,
17,
531,
199,
198,
509,
7482,
315,
17398,
26,
507,
198,
1773,
9656,
985,
275,
7482,
14,
1623,
63,
452,
8,
533,
7993,
1213,
7482,
1213,
18,
5832,
16,
1055,
505,
507,
198,
893,
26,
686,
198,
2324,
985,
275,
295,
14,
1733,
360,
27934,
6977,
4268,
3066,
9656,
985,
680,
923,
8,
16,
9,
507,
198,
2590,
4281,
465,
325,
26,
686,
198,
1361,
480,
1773,
9656,
985,
26,
8352,
908,
8,
1773,
9656,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
507,
198,
893,
26,
686,
198,
1162,
8045,
275,
7482,
14,
1623,
63,
452,
8,
533,
7993,
5030,
5832,
16,
61,
420,
327,
1642,
5492,
769,
365,
1862,
507,
198,
2590,
7888,
26,
686,
198,
1361,
480,
1773,
9656,
985,
26,
1052,
446,
7482,
965,
949,
15396,
1021,
1674,
908,
8,
2324,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
2742,
198,
3,
1104,
4136,
507,
198,
692,
1862,
8045,
14,
6352,
63,
17285,
14,
6352,
63,
17285,
14,
505,
1137,
298,
5976,
582,
686,
198,
1361,
480,
1773,
9656,
985,
26,
1052,
965,
949,
1862,
447,
26,
8352,
908,
8,
2324,
985,
12,
1862,
8045,
14,
6352,
63,
17285,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
2742,
198,
1162,
275,
1862,
8045,
14,
1623,
63,
452,
8,
533,
7993,
3583,
15396,
5125,
358,
327,
536,
11083,
198,
1162,
9921,
275,
1862,
8045,
14,
1623,
63,
452,
8,
533,
7993,
617,
358,
259,
327,
675,
730,
507,
198,
635,
6119,
275,
942,
507,
198,
509,
366,
315,
1862,
9921,
26,
686,
198,
893,
26,
1585,
198,
1180,
275,
366,
14,
1623,
63,
452,
8,
533,
7993,
838,
284,
5832,
16,
1055,
505,
686,
198,
2590,
7888,
465,
325,
26,
1585,
198,
1180,
275,
298,
3205,
2,
686,
198,
635,
6119,
14,
740,
8,
1180,
9,
421,
507,
198,
692,
822,
8,
1162,
9,
1137,
822,
8,
635,
6119,
304,
686,
198,
1361,
480,
1773,
9656,
985,
26,
1052,
446,
28488,
1862,
436,
675,
5560,
1674,
908,
8,
2324,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
2742,
198,
1210,
6007,
275,
359,
80,
14,
505,
14,
1913,
342,
367,
284,
12,
299,
315,
3874,
8,
1162,
9,
340,
334,
635,
6119,
59,
73,
1055,
1913,
342,
6803,
3205,
358,
503,
334,
635,
6119,
59,
73,
1055,
1913,
342,
11800,
15124,
11323,
507,
198,
1199,
6007,
275,
359,
80,
14,
505,
14,
1913,
342,
367,
284,
12,
299,
315,
3874,
8,
1162,
9,
340,
334,
635,
6119,
59,
73,
1055,
1913,
342,
6803,
2959,
358,
503,
334,
635,
6119,
59,
73,
1055,
1913,
342,
11800,
18669,
11323,
507,
198,
2308,
6007,
275,
359,
80,
14,
505,
14,
1913,
342,
367,
284,
12,
299,
315,
3874,
8,
1162,
9,
340,
1215,
6119,
59,
73,
1055,
1913,
342,
6803,
3205,
15,
2959,
418,
2742,
198,
3711,
59,
2324,
985,
61,
275,
1324,
6007,
507,
198,
4467,
59,
2324,
985,
61,
275,
1072,
6007,
507,
198,
9207,
59,
2324,
985,
61,
275,
5890,
6007,
2742,
198,
3,
5536,
9149,
507,
198,
893,
26,
686,
198,
1301,
2030,
275,
7482,
14,
1623,
63,
452,
8,
533,
7993,
2030,
406,
2030,
5832,
16,
61,
507,
198,
2590,
7888,
26,
686,
198,
1361,
480,
2324,
985,
26,
1052,
446,
949,
2396,
1674,
908,
8,
2324,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
507,
198,
3,
5436,
365,
8034,
2419,
15158,
422,
14,
11083,
198,
1301,
275,
1382,
2030,
14,
1623,
63,
452,
480,
80,
9981,
16,
1055,
505,
507,
198,
1301,
275,
1382,
14,
1814,
4582,
78,
401,
6899,
507,
198,
1301,
275,
295,
14,
954,
4582,
84,
22758,
298,
3872,
1382,
9,
507,
198,
1301,
275,
295,
14,
954,
4582,
83,
22758,
298,
3872,
1382,
9,
507,
198,
1301,
275,
1382,
14,
1814,
20630,
26144,
358,
507,
198,
1301,
275,
1382,
14,
1814,
480,
2765,
805,
401,
4325,
985,
9,
507,
198,
1301,
275,
1382,
14,
1814,
480,
2765,
12981,
401,
4325,
985,
9,
507,
198,
1301,
275,
1382,
14,
1814,
480,
2765,
401,
4325,
985,
9,
507,
198,
1301,
275,
1382,
14,
1913,
342,
507,
198,
4757,
59,
2324,
985,
61,
275,
1382,
421,
198,
3,
2218,
314,
2621,
570,
199,
198,
1361,
480,
2491,
2446,
531,
199,
198,
1361,
480,
1391,
1324,
6007,
275,
2341,
59,
875,
1527,
61,
875,
91,
531,
199,
198,
509,
1022,
12,
373,
315,
4153,
14,
1744,
837,
507,
198,
692,
822,
8,
86,
9,
508,
378,
26,
1980,
507,
198,
1361,
14088,
2440,
582,
8448,
1987,
908,
8,
75,
395,
1284,
18413,
507,
198,
509,
10702,
315,
373,
520,
686,
198,
1294,
275,
10702,
14,
1294,
20324,
686,
198,
509,
308,
315,
3715,
26,
1585,
198,
1361,
14088,
2440,
401,
1987,
908,
8,
83,
14,
1913,
4000,
1284,
18413,
507,
198,
1361,
480,
1386,
531,
199,
198
] |
[
9922,
20,
492,
17132,
199,
646,
4145,
199,
646,
295,
199,
646,
984,
199,
646,
747,
199,
199,
3711,
275,
2440,
199,
4467,
275,
1052,
199,
9207,
275,
1052,
199,
4757,
275,
1052,
199,
199,
318,
664,
837,
199,
198,
692,
747,
14,
515,
14,
6292,
480,
1637,
15,
4757,
14,
1360,
2349,
507,
198,
1045,
1551,
480,
1637,
15,
4757,
14,
1360,
401,
283,
82,
358,
465,
289,
26,
686,
198,
1361,
480,
10369,
2581,
401,
570,
29,
1274,
14,
3083,
9,
686,
198,
1107,
289,
14,
739,
342,
199,
198,
82,
275,
4145,
14,
362,
480,
1014,
921,
4757,
14,
78,
433,
2391,
14,
957,
15,
16131,
10546,
15,
9277,
15,
27934,
13,
11071,
13,
17348,
15,
1080,
14,
1360,
531,
199,
198,
1045,
1551,
480,
1637,
15,
4757,
14,
1360,
401,
283,
87,
358,
465,
289,
26,
507,
198,
70,
14,
952,
8,
82,
14,
505,
9,
199,
198,
1107,
519,
14,
505,
199,
199,
318,
2446,
837,
199,
198,
2424,
275,
664,
342,
199,
198,
9317,
275,
17132,
8,
2424,
12,
298,
1360,
21,
773,
531,
199,
198,
4407,
275,
9108,
14,
1623,
63,
452,
8,
344,
628,
1246,
13,
18206,
5199,
531,
199,
198,
11299,
275,
4072,
59,
16,
1055,
1623,
63,
452,
8,
533,
63,
628,
5746,
19834,
6032,
17,
531,
199,
198,
509,
7482,
315,
17398,
26,
507,
198,
1773,
9656,
985,
275,
7482,
14,
1623,
63,
452,
8,
533,
7993,
1213,
7482,
1213,
18,
5832,
16,
1055,
505,
507,
198,
893,
26,
686,
198,
2324,
985,
275,
295,
14,
1733,
360,
27934,
6977,
4268,
3066,
9656,
985,
680,
923,
8,
16,
9,
507,
198,
2590,
4281,
465,
325,
26,
686,
198,
1361,
480,
1773,
9656,
985,
26,
8352,
908,
8,
1773,
9656,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
507,
198,
893,
26,
686,
198,
1162,
8045,
275,
7482,
14,
1623,
63,
452,
8,
533,
7993,
5030,
5832,
16,
61,
420,
327,
1642,
5492,
769,
365,
1862,
507,
198,
2590,
7888,
26,
686,
198,
1361,
480,
1773,
9656,
985,
26,
1052,
446,
7482,
965,
949,
15396,
1021,
1674,
908,
8,
2324,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
2742,
198,
3,
1104,
4136,
507,
198,
692,
1862,
8045,
14,
6352,
63,
17285,
14,
6352,
63,
17285,
14,
505,
1137,
298,
5976,
582,
686,
198,
1361,
480,
1773,
9656,
985,
26,
1052,
965,
949,
1862,
447,
26,
8352,
908,
8,
2324,
985,
12,
1862,
8045,
14,
6352,
63,
17285,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
2742,
198,
1162,
275,
1862,
8045,
14,
1623,
63,
452,
8,
533,
7993,
3583,
15396,
5125,
358,
327,
536,
11083,
198,
1162,
9921,
275,
1862,
8045,
14,
1623,
63,
452,
8,
533,
7993,
617,
358,
259,
327,
675,
730,
507,
198,
635,
6119,
275,
942,
507,
198,
509,
366,
315,
1862,
9921,
26,
686,
198,
893,
26,
1585,
198,
1180,
275,
366,
14,
1623,
63,
452,
8,
533,
7993,
838,
284,
5832,
16,
1055,
505,
686,
198,
2590,
7888,
465,
325,
26,
1585,
198,
1180,
275,
298,
3205,
2,
686,
198,
635,
6119,
14,
740,
8,
1180,
9,
421,
507,
198,
692,
822,
8,
1162,
9,
1137,
822,
8,
635,
6119,
304,
686,
198,
1361,
480,
1773,
9656,
985,
26,
1052,
446,
28488,
1862,
436,
675,
5560,
1674,
908,
8,
2324,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
2742,
198,
1210,
6007,
275,
359,
80,
14,
505,
14,
1913,
342,
367,
284,
12,
299,
315,
3874,
8,
1162,
9,
340,
334,
635,
6119,
59,
73,
1055,
1913,
342,
6803,
3205,
358,
503,
334,
635,
6119,
59,
73,
1055,
1913,
342,
11800,
15124,
11323,
507,
198,
1199,
6007,
275,
359,
80,
14,
505,
14,
1913,
342,
367,
284,
12,
299,
315,
3874,
8,
1162,
9,
340,
334,
635,
6119,
59,
73,
1055,
1913,
342,
6803,
2959,
358,
503,
334,
635,
6119,
59,
73,
1055,
1913,
342,
11800,
18669,
11323,
507,
198,
2308,
6007,
275,
359,
80,
14,
505,
14,
1913,
342,
367,
284,
12,
299,
315,
3874,
8,
1162,
9,
340,
1215,
6119,
59,
73,
1055,
1913,
342,
6803,
3205,
15,
2959,
418,
2742,
198,
3711,
59,
2324,
985,
61,
275,
1324,
6007,
507,
198,
4467,
59,
2324,
985,
61,
275,
1072,
6007,
507,
198,
9207,
59,
2324,
985,
61,
275,
5890,
6007,
2742,
198,
3,
5536,
9149,
507,
198,
893,
26,
686,
198,
1301,
2030,
275,
7482,
14,
1623,
63,
452,
8,
533,
7993,
2030,
406,
2030,
5832,
16,
61,
507,
198,
2590,
7888,
26,
686,
198,
1361,
480,
2324,
985,
26,
1052,
446,
949,
2396,
1674,
908,
8,
2324,
985,
395,
570,
29,
1274,
14,
3083,
9,
686,
198,
6958,
507,
198,
3,
5436,
365,
8034,
2419,
15158,
422,
14,
11083,
198,
1301,
275,
1382,
2030,
14,
1623,
63,
452,
480,
80,
9981,
16,
1055,
505,
507,
198,
1301,
275,
1382,
14,
1814,
4582,
78,
401,
6899,
507,
198,
1301,
275,
295,
14,
954,
4582,
84,
22758,
298,
3872,
1382,
9,
507,
198,
1301,
275,
295,
14,
954,
4582,
83,
22758,
298,
3872,
1382,
9,
507,
198,
1301,
275,
1382,
14,
1814,
20630,
26144,
358,
507,
198,
1301,
275,
1382,
14,
1814,
480,
2765,
805,
401,
4325,
985,
9,
507,
198,
1301,
275,
1382,
14,
1814,
480,
2765,
12981,
401,
4325,
985,
9,
507,
198,
1301,
275,
1382,
14,
1814,
480,
2765,
401,
4325,
985,
9,
507,
198,
1301,
275,
1382,
14,
1913,
342,
507,
198,
4757,
59,
2324,
985,
61,
275,
1382,
421,
198,
3,
2218,
314,
2621,
570,
199,
198,
1361,
480,
2491,
2446,
531,
199,
198,
1361,
480,
1391,
1324,
6007,
275,
2341,
59,
875,
1527,
61,
875,
91,
531,
199,
198,
509,
1022,
12,
373,
315,
4153,
14,
1744,
837,
507,
198,
692,
822,
8,
86,
9,
508,
378,
26,
1980,
507,
198,
1361,
14088,
2440,
582,
8448,
1987,
908,
8,
75,
395,
1284,
18413,
507,
198,
509,
10702,
315,
373,
520,
686,
198,
1294,
275,
10702,
14,
1294,
20324,
686,
198,
509,
308,
315,
3715,
26,
1585,
198,
1361,
14088,
2440,
401,
1987,
908,
8,
83,
14,
1913,
4000,
1284,
18413,
507,
198,
1361,
480,
1386,
531,
199,
198,
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,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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
] |
MortalViews/python-notes
|
inheritance.py
|
1
|
1192
|
import random
class Person:
def __init__(self,name,age,location):
self.name = name
self.age = age
self.locaiton = location
def is_sick(self):
return random.randint(1,10)%2==0
class AttendenceMixin:
def swip_in(self):
pass
def swip_out(self):
pass
class Employee(Person):
def __init__(self,emp_id,joining_date,*args,**kwargs):
self.emp_id =emp_id
self.joining_date =joining_date
super().__init__(*args,**kwargs)
class Contractor(Employee):
pass
class InfraEmployee(Employee,AttendenceMixin):
def __init__(self,dept,*args,**kwargs):
self.dept = dept
super().__init__(*args,**kwargs)
class ITEmployee(Employee,AttendenceMixin):
def __init__(self,project,technologies,system_id,*args,**kwargs):
self.project =project
self.tech = technologies
self.system = system_id
super().__init__(*args,**kwargs)
def is_sick(self):
return random.randint(1,10)%2==1
class Manager(Employee):
def __init__(self,cabin_no,*args,**kwargs):
self.cabin=cabin_no
super().__init__(*args,**kwargs)
|
apache-2.0
|
[
646,
2196,
199,
533,
8028,
26,
272,
347,
636,
826,
721,
277,
12,
354,
12,
474,
12,
1985,
304,
267,
291,
14,
354,
275,
536,
4960,
291,
14,
474,
275,
11437,
4960,
291,
14,
320,
696,
390,
265,
275,
2909,
339,
347,
365,
63,
32370,
8,
277,
304,
267,
372,
2196,
14,
8393,
8,
17,
12,
709,
19656,
18,
389,
16,
1362,
199,
533,
2854,
724,
5606,
4256,
26,
272,
347,
5584,
711,
63,
262,
8,
277,
304,
267,
986,
5591,
347,
5584,
711,
63,
548,
8,
277,
304,
267,
986,
221,
199,
533,
24089,
8,
7344,
304,
272,
347,
636,
826,
721,
277,
12,
2109,
63,
344,
12,
904,
316,
63,
602,
19166,
589,
12663,
958,
304,
267,
291,
14,
2109,
63,
344,
275,
2109,
63,
344,
267,
291,
14,
904,
316,
63,
602,
275,
904,
316,
63,
602,
267,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
221,
268,
199,
533,
1448,
1239,
630,
8,
22635,
304,
272,
986,
9948,
199,
533,
1010,
21844,
22635,
8,
22635,
12,
1271,
724,
5606,
4256,
304,
2043,
347,
636,
826,
721,
277,
12,
271,
541,
19166,
589,
12663,
958,
304,
2126,
291,
14,
271,
541,
275,
477,
541,
2126,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
4960,
199,
533,
473,
3727,
15817,
8,
22635,
12,
1271,
724,
5606,
4256,
304,
272,
347,
636,
826,
721,
277,
12,
1715,
12,
266,
10575,
15241,
12,
2253,
63,
344,
19166,
589,
12663,
958,
304,
267,
291,
14,
1715,
275,
1715,
267,
291,
14,
15970,
275,
1565,
10575,
15241,
267,
291,
14,
2253,
275,
2656,
63,
344,
267,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
2286,
347,
365,
63,
32370,
8,
277,
304,
267,
372,
2196,
14,
8393,
8,
17,
12,
709,
19656,
18,
389,
17,
1362,
199,
533,
13537,
8,
22635,
304,
272,
347,
636,
826,
721,
277,
12,
26481,
262,
63,
889,
19166,
589,
12663,
958,
304,
267,
291,
14,
26481,
262,
29,
26481,
262,
63,
889,
267,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
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
] |
[
2196,
199,
533,
8028,
26,
272,
347,
636,
826,
721,
277,
12,
354,
12,
474,
12,
1985,
304,
267,
291,
14,
354,
275,
536,
4960,
291,
14,
474,
275,
11437,
4960,
291,
14,
320,
696,
390,
265,
275,
2909,
339,
347,
365,
63,
32370,
8,
277,
304,
267,
372,
2196,
14,
8393,
8,
17,
12,
709,
19656,
18,
389,
16,
1362,
199,
533,
2854,
724,
5606,
4256,
26,
272,
347,
5584,
711,
63,
262,
8,
277,
304,
267,
986,
5591,
347,
5584,
711,
63,
548,
8,
277,
304,
267,
986,
221,
199,
533,
24089,
8,
7344,
304,
272,
347,
636,
826,
721,
277,
12,
2109,
63,
344,
12,
904,
316,
63,
602,
19166,
589,
12663,
958,
304,
267,
291,
14,
2109,
63,
344,
275,
2109,
63,
344,
267,
291,
14,
904,
316,
63,
602,
275,
904,
316,
63,
602,
267,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
221,
268,
199,
533,
1448,
1239,
630,
8,
22635,
304,
272,
986,
9948,
199,
533,
1010,
21844,
22635,
8,
22635,
12,
1271,
724,
5606,
4256,
304,
2043,
347,
636,
826,
721,
277,
12,
271,
541,
19166,
589,
12663,
958,
304,
2126,
291,
14,
271,
541,
275,
477,
541,
2126,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
4960,
199,
533,
473,
3727,
15817,
8,
22635,
12,
1271,
724,
5606,
4256,
304,
272,
347,
636,
826,
721,
277,
12,
1715,
12,
266,
10575,
15241,
12,
2253,
63,
344,
19166,
589,
12663,
958,
304,
267,
291,
14,
1715,
275,
1715,
267,
291,
14,
15970,
275,
1565,
10575,
15241,
267,
291,
14,
2253,
275,
2656,
63,
344,
267,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
2286,
347,
365,
63,
32370,
8,
277,
304,
267,
372,
2196,
14,
8393,
8,
17,
12,
709,
19656,
18,
389,
17,
1362,
199,
533,
13537,
8,
22635,
304,
272,
347,
636,
826,
721,
277,
12,
26481,
262,
63,
889,
19166,
589,
12663,
958,
304,
267,
291,
14,
26481,
262,
29,
26481,
262,
63,
889,
267,
1613,
11027,
826,
9308,
589,
12663,
958,
9,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry.page import page as page
from telemetry.page import page_set as page_set
archive_data_file_path = 'data/service_worker_micro_benchmark.json'
class ServiceWorkerBenchmarkPage(page.Page):
"""Page for workload to measure some specific functions in JS"""
def RunNavigateSteps(self, action_runner):
action_runner.NavigateToPage(self)
action_runner.WaitForJavaScriptCondition('window.done')
class ServiceWorkerMicroBenchmarkPageSet(page_set.PageSet):
"""Page set for micro benchmarking of each functions with ServiceWorker"""
def __init__(self):
super(ServiceWorkerMicroBenchmarkPageSet, self).__init__(
archive_data_file=archive_data_file_path,
bucket=page_set.PUBLIC_BUCKET)
# pylint: disable=C0301
# The code of localhost:8091 is placed in
# https://github.com/coonsta/Service-Worker-Performance
# but currently the following is used:
# https://github.com/amiq11/Service-Worker-Performance/tree/follow_spec_and_many_registration
# (rev: 3238098ea0225f53dab2f69f7406db8a2712dbf9)
# This will be merged into the main repository.
# pylint: enable=C0301
# Why: to measure performance of many concurrent fetches
self.AddUserStory(ServiceWorkerBenchmarkPage(
'http://localhost:8091/index.html', self,
make_javascript_deterministic=False))
|
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,
504,
17298,
14,
1606,
492,
2034,
465,
2034,
199,
504,
17298,
14,
1606,
492,
2034,
63,
409,
465,
2034,
63,
409,
421,
199,
6404,
63,
576,
63,
493,
63,
515,
275,
283,
576,
15,
1364,
63,
6599,
63,
6453,
63,
11861,
14,
1001,
7,
421,
199,
533,
7591,
12678,
18644,
3276,
8,
1606,
14,
3276,
304,
523,
408,
3276,
367,
1736,
912,
370,
9775,
2005,
2488,
3423,
315,
18001,
624,
819,
347,
3378,
31914,
20960,
8,
277,
12,
1595,
63,
5933,
304,
272,
1595,
63,
5933,
14,
31914,
1378,
3276,
8,
277,
9,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
360,
3806,
14,
4456,
358,
421,
199,
533,
7591,
12678,
23990,
18644,
3276,
1084,
8,
1606,
63,
409,
14,
3276,
1084,
304,
523,
408,
3276,
663,
367,
9967,
12338,
316,
402,
1924,
3423,
543,
7591,
12678,
624,
819,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
3167,
12678,
23990,
18644,
3276,
1084,
12,
291,
2843,
826,
721,
267,
6359,
63,
576,
63,
493,
29,
6404,
63,
576,
63,
493,
63,
515,
12,
267,
5315,
29,
1606,
63,
409,
14,
19476,
63,
20156,
9,
339,
327,
4287,
26,
3507,
29,
35,
1644,
614,
272,
327,
710,
1233,
402,
11667,
26,
1257,
3328,
365,
15090,
315,
272,
327,
4178,
921,
5031,
14,
957,
15,
331,
265,
1207,
15,
3167,
13,
12678,
13,
25635,
272,
327,
1325,
5544,
314,
2569,
365,
1202,
26,
272,
327,
4178,
921,
5031,
14,
957,
15,
455,
9962,
845,
15,
3167,
13,
12678,
13,
25635,
15,
2350,
15,
7207,
63,
1650,
63,
460,
63,
3479,
63,
8054,
272,
327,
334,
4964,
26,
650,
1789,
1257,
2905,
4489,
996,
821,
70,
2481,
68,
371,
18,
70,
1876,
70,
1342,
1690,
697,
24,
65,
1465,
713,
26826,
25,
9,
272,
327,
961,
911,
506,
9545,
1901,
314,
2446,
7611,
14,
272,
327,
4287,
26,
4756,
29,
35,
1644,
614,
272,
327,
6827,
26,
370,
9775,
10238,
402,
5002,
23002,
28053,
272,
291,
14,
1123,
1899,
25120,
8,
3167,
12678,
18644,
3276,
8,
267,
283,
1014,
921,
5967,
26,
1257,
3328,
15,
1080,
14,
1360,
297,
291,
12,
267,
1852,
63,
9554,
63,
30709,
29,
797,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
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,
504,
17298,
14,
1606,
492,
2034,
465,
2034,
199,
504,
17298,
14,
1606,
492,
2034,
63,
409,
465,
2034,
63,
409,
421,
199,
6404,
63,
576,
63,
493,
63,
515,
275,
283,
576,
15,
1364,
63,
6599,
63,
6453,
63,
11861,
14,
1001,
7,
421,
199,
533,
7591,
12678,
18644,
3276,
8,
1606,
14,
3276,
304,
523,
408,
3276,
367,
1736,
912,
370,
9775,
2005,
2488,
3423,
315,
18001,
624,
819,
347,
3378,
31914,
20960,
8,
277,
12,
1595,
63,
5933,
304,
272,
1595,
63,
5933,
14,
31914,
1378,
3276,
8,
277,
9,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
360,
3806,
14,
4456,
358,
421,
199,
533,
7591,
12678,
23990,
18644,
3276,
1084,
8,
1606,
63,
409,
14,
3276,
1084,
304,
523,
408,
3276,
663,
367,
9967,
12338,
316,
402,
1924,
3423,
543,
7591,
12678,
624,
819,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
3167,
12678,
23990,
18644,
3276,
1084,
12,
291,
2843,
826,
721,
267,
6359,
63,
576,
63,
493,
29,
6404,
63,
576,
63,
493,
63,
515,
12,
267,
5315,
29,
1606,
63,
409,
14,
19476,
63,
20156,
9,
339,
327,
4287,
26,
3507,
29,
35,
1644,
614,
272,
327,
710,
1233,
402,
11667,
26,
1257,
3328,
365,
15090,
315,
272,
327,
4178,
921,
5031,
14,
957,
15,
331,
265,
1207,
15,
3167,
13,
12678,
13,
25635,
272,
327,
1325,
5544,
314,
2569,
365,
1202,
26,
272,
327,
4178,
921,
5031,
14,
957,
15,
455,
9962,
845,
15,
3167,
13,
12678,
13,
25635,
15,
2350,
15,
7207,
63,
1650,
63,
460,
63,
3479,
63,
8054,
272,
327,
334,
4964,
26,
650,
1789,
1257,
2905,
4489,
996,
821,
70,
2481,
68,
371,
18,
70,
1876,
70,
1342,
1690,
697,
24,
65,
1465,
713,
26826,
25,
9,
272,
327,
961,
911,
506,
9545,
1901,
314,
2446,
7611,
14,
272,
327,
4287,
26,
4756,
29,
35,
1644,
614,
272,
327,
6827,
26,
370,
9775,
10238,
402,
5002,
23002,
28053,
272,
291,
14,
1123,
1899,
25120,
8,
3167,
12678,
18644,
3276,
8,
267,
283,
1014,
921,
5967,
26,
1257,
3328,
15,
1080,
14,
1360,
297,
291,
12,
267,
1852,
63,
9554,
63,
30709,
29,
797,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
guaix-ucm/numina
|
numina/core/requirements.py
|
3
|
1934
|
#
# Copyright 2008-2021 Universidad Complutense de Madrid
#
# This file is part of Numina
#
# SPDX-License-Identifier: GPL-3.0+
# License-Filename: LICENSE.txt
#
"""
Recipe requirement holders
"""
import numina.exceptions
import numina.types.obsresult as obtypes
from .dataholders import Requirement
class ObservationResultRequirement(Requirement):
"""The Recipe requires the result of an observation."""
def __init__(self, query_opts=None):
super(ObservationResultRequirement, self).__init__(
obtypes.ObservationResultType, "Observation Result",
query_opts=query_opts
)
def __repr__(self):
sclass = type(self).__name__
fmt = "%s(dest=%r, description='%s')"
msg = fmt % (sclass, self.dest, self.description)
return msg
def query(self, dal, obsres, options=None):
"""
Parameters
----------
dal
obsres
options
Returns
-------
"""
from numina.core.query import ResultOf
q_options = self.query_options(options)
if isinstance(q_options, ResultOf):
dest_field = 'frames'
dest_type = list
# Field to insert the results
if not hasattr(obsres, dest_field):
setattr(obsres, dest_field, dest_type())
dest_obj = getattr(obsres, dest_field)
values = dal.search_result_relative(self.dest, self.type, obsres,
result_desc=q_options)
for partial in values:
dest_obj.append(partial.content)
return obsres
def on_query_not_found_from_type(self, notfound):
"""
Parameters
----------
notfound
Returns
-------
"""
raise numina.exceptions.NoResultFound('unable to complete ObservationResult') from notfound
|
gpl-3.0
|
[
3,
199,
3,
1898,
9079,
13,
22150,
1910,
4380,
4148,
350,
1849,
2421,
85,
724,
261,
477,
603,
350,
1677,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
16817,
13765,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
14629,
13,
19,
14,
16,
11,
199,
3,
844,
13,
8117,
26,
5113,
14,
2424,
199,
3,
199,
199,
624,
199,
25879,
10685,
31976,
199,
624,
421,
199,
646,
1967,
13765,
14,
3924,
199,
646,
1967,
13765,
14,
1313,
14,
11226,
1099,
465,
2607,
1313,
199,
199,
504,
1275,
576,
4302,
83,
492,
25013,
421,
199,
533,
17985,
8213,
2889,
17947,
8,
17947,
304,
272,
408,
1918,
799,
8233,
5074,
314,
754,
402,
376,
20038,
1041,
272,
347,
636,
826,
721,
277,
12,
1827,
63,
3291,
29,
403,
304,
398,
1613,
8,
11394,
8213,
2889,
17947,
12,
291,
2843,
826,
721,
288,
2607,
1313,
14,
11394,
8213,
2889,
804,
12,
298,
11394,
8213,
10695,
401,
288,
1827,
63,
3291,
29,
1131,
63,
3291,
288,
776,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
533,
275,
730,
8,
277,
2843,
354,
363,
267,
7104,
275,
2071,
83,
8,
2614,
2458,
82,
12,
1369,
9569,
83,
19124,
267,
1499,
275,
7104,
450,
334,
83,
533,
12,
291,
14,
2614,
12,
291,
14,
1802,
9,
267,
372,
1499,
339,
347,
1827,
8,
277,
12,
366,
279,
12,
16087,
470,
12,
1511,
29,
403,
304,
267,
408,
398,
3897,
267,
4143,
267,
366,
279,
267,
16087,
470,
267,
1511,
398,
1803,
267,
5514,
398,
408,
267,
687,
1967,
13765,
14,
1018,
14,
1131,
492,
10695,
3466,
398,
1894,
63,
1419,
275,
291,
14,
1131,
63,
1419,
8,
1419,
9,
398,
340,
1228,
8,
81,
63,
1419,
12,
10695,
3466,
304,
288,
2053,
63,
698,
275,
283,
8444,
7,
288,
2053,
63,
466,
275,
769,
288,
327,
5024,
370,
5518,
314,
2058,
288,
340,
440,
2688,
8,
11226,
470,
12,
2053,
63,
698,
304,
355,
5371,
8,
11226,
470,
12,
2053,
63,
698,
12,
2053,
63,
466,
1012,
953,
2053,
63,
1113,
275,
2519,
8,
11226,
470,
12,
2053,
63,
698,
9,
953,
1338,
275,
366,
279,
14,
1733,
63,
1099,
63,
6188,
8,
277,
14,
2614,
12,
291,
14,
466,
12,
16087,
470,
12,
6059,
754,
63,
3257,
29,
81,
63,
1419,
9,
953,
367,
7417,
315,
1338,
26,
355,
2053,
63,
1113,
14,
740,
8,
6672,
14,
1317,
9,
398,
372,
16087,
470,
339,
347,
641,
63,
1131,
63,
1397,
63,
4214,
63,
504,
63,
466,
8,
277,
12,
440,
4214,
304,
267,
408,
398,
3897,
267,
4143,
267,
440,
4214,
398,
1803,
267,
5514,
398,
408,
267,
746,
1967,
13765,
14,
3924,
14,
1944,
2889,
3601,
360,
17200,
370,
4890,
17985,
8213,
2889,
358,
687,
440,
4214,
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
] |
[
199,
3,
1898,
9079,
13,
22150,
1910,
4380,
4148,
350,
1849,
2421,
85,
724,
261,
477,
603,
350,
1677,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
16817,
13765,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
14629,
13,
19,
14,
16,
11,
199,
3,
844,
13,
8117,
26,
5113,
14,
2424,
199,
3,
199,
199,
624,
199,
25879,
10685,
31976,
199,
624,
421,
199,
646,
1967,
13765,
14,
3924,
199,
646,
1967,
13765,
14,
1313,
14,
11226,
1099,
465,
2607,
1313,
199,
199,
504,
1275,
576,
4302,
83,
492,
25013,
421,
199,
533,
17985,
8213,
2889,
17947,
8,
17947,
304,
272,
408,
1918,
799,
8233,
5074,
314,
754,
402,
376,
20038,
1041,
272,
347,
636,
826,
721,
277,
12,
1827,
63,
3291,
29,
403,
304,
398,
1613,
8,
11394,
8213,
2889,
17947,
12,
291,
2843,
826,
721,
288,
2607,
1313,
14,
11394,
8213,
2889,
804,
12,
298,
11394,
8213,
10695,
401,
288,
1827,
63,
3291,
29,
1131,
63,
3291,
288,
776,
339,
347,
636,
2722,
721,
277,
304,
267,
308,
533,
275,
730,
8,
277,
2843,
354,
363,
267,
7104,
275,
2071,
83,
8,
2614,
2458,
82,
12,
1369,
9569,
83,
19124,
267,
1499,
275,
7104,
450,
334,
83,
533,
12,
291,
14,
2614,
12,
291,
14,
1802,
9,
267,
372,
1499,
339,
347,
1827,
8,
277,
12,
366,
279,
12,
16087,
470,
12,
1511,
29,
403,
304,
267,
408,
398,
3897,
267,
4143,
267,
366,
279,
267,
16087,
470,
267,
1511,
398,
1803,
267,
5514,
398,
408,
267,
687,
1967,
13765,
14,
1018,
14,
1131,
492,
10695,
3466,
398,
1894,
63,
1419,
275,
291,
14,
1131,
63,
1419,
8,
1419,
9,
398,
340,
1228,
8,
81,
63,
1419,
12,
10695,
3466,
304,
288,
2053,
63,
698,
275,
283,
8444,
7,
288,
2053,
63,
466,
275,
769,
288,
327,
5024,
370,
5518,
314,
2058,
288,
340,
440,
2688,
8,
11226,
470,
12,
2053,
63,
698,
304,
355,
5371,
8,
11226,
470,
12,
2053,
63,
698,
12,
2053,
63,
466,
1012,
953,
2053,
63,
1113,
275,
2519,
8,
11226,
470,
12,
2053,
63,
698,
9,
953,
1338,
275,
366,
279,
14,
1733,
63,
1099,
63,
6188,
8,
277,
14,
2614,
12,
291,
14,
466,
12,
16087,
470,
12,
6059,
754,
63,
3257,
29,
81,
63,
1419,
9,
953,
367,
7417,
315,
1338,
26,
355,
2053,
63,
1113,
14,
740,
8,
6672,
14,
1317,
9,
398,
372,
16087,
470,
339,
347,
641,
63,
1131,
63,
1397,
63,
4214,
63,
504,
63,
466,
8,
277,
12,
440,
4214,
304,
267,
408,
398,
3897,
267,
4143,
267,
440,
4214,
398,
1803,
267,
5514,
398,
408,
267,
746,
1967,
13765,
14,
3924,
14,
1944,
2889,
3601,
360,
17200,
370,
4890,
17985,
8213,
2889,
358,
687,
440,
4214,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dwadler/QGIS
|
tests/src/python/test_qgslocator.py
|
8
|
16296
|
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsLocator.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = '(C) 2017 by Nyall Dawson'
__date__ = '6/05/2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import qgis # NOQA
import os
from qgis.core import (QgsLocator,
QgsLocatorFilter,
QgsLocatorContext,
QgsLocatorResult,
QgsLocatorModel,
QgsLocatorProxyModel,
QgsLocatorAutomaticModel,
QgsSettings)
from qgis.PyQt.QtCore import QVariant, pyqtSignal, QCoreApplication
from time import sleep
from qgis.testing import start_app, unittest
from qgis.PyQt import sip
start_app()
class test_filter(QgsLocatorFilter):
def __init__(self, identifier, prefix=None, groupResult=False, parent=None):
super().__init__(parent)
self.identifier = identifier
self._prefix = prefix
self.groupResult = groupResult
def clone(self):
return test_filter(self.identifier, self.prefix, self.groupResult)
def name(self):
return 'test_' + self.identifier
def displayName(self):
return 'test_' + self.identifier
def prefix(self):
return self._prefix
def fetchResults(self, string, context, feedback):
n = 3 if not self.groupResult else 9
for i in range(n):
if feedback.isCanceled():
return
sleep(0.001)
result = QgsLocatorResult()
result.displayString = self.identifier + str(i)
if self.groupResult:
if i < 6:
result.group = 'first group'
elif i < 8:
result.group = 'second group'
self.resultFetched.emit(result)
def triggerResult(self, result):
pass
def priority(self):
if self.identifier == 'a':
return QgsLocatorFilter.High
elif self.identifier == 'b':
return QgsLocatorFilter.Medium
elif self.identifier == 'c':
return QgsLocatorFilter.Low
else:
return QgsLocatorFilter.Medium
class TestQgsLocator(unittest.TestCase):
def testRegisteringFilters(self):
l = QgsLocator()
filter_a = test_filter('a')
filter_b = test_filter('b')
l.registerFilter(filter_a)
l.registerFilter(filter_b)
self.assertEqual(set(l.filters()), {filter_a, filter_b})
# ownership should be transferred to locator
del l
self.assertTrue(sip.isdeleted(filter_a))
self.assertTrue(sip.isdeleted(filter_b))
# try manually deregistering
l = QgsLocator()
filter_c = test_filter('c')
filter_d = test_filter('d')
l.registerFilter(filter_c)
l.registerFilter(filter_d)
self.assertEqual(set(l.filters()), {filter_c, filter_d})
l.deregisterFilter(filter_c)
self.assertTrue(sip.isdeleted(filter_c))
self.assertFalse(sip.isdeleted(filter_d))
self.assertEqual(l.filters(), [filter_d])
del l
self.assertTrue(sip.isdeleted(filter_c))
self.assertTrue(sip.isdeleted(filter_d))
def testFetchingResults(self):
def got_hit(result):
got_hit._results_.append(result.displayString)
got_hit._results_ = []
context = QgsLocatorContext()
# one filter
l = QgsLocator()
filter_a = test_filter('a')
l.registerFilter(filter_a)
l.foundResult.connect(got_hit)
l.fetchResults('a', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'a0', 'a1', 'a2'})
# two filters
filter_b = test_filter('b')
l.registerFilter(filter_b)
got_hit._results_ = []
l.fetchResults('a', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'a0', 'a1', 'a2', 'b0', 'b1', 'b2'})
def testDeleteWhileFetchingResults(self):
"""
Delete locator whilst fetching results
"""
def got_hit(result):
got_hit._results_.append(result.displayString)
got_hit._results_ = []
context = QgsLocatorContext()
l = QgsLocator()
filter_a = test_filter('a')
l.registerFilter(filter_a)
l.foundResult.connect(got_hit)
l.fetchResults('a', context)
del l
def testCancelWhileFetchingResults(self):
"""
Cancel locator whilst fetching results
"""
def got_hit(result):
got_hit._results_.append(result.displayString)
got_hit._results_ = []
context = QgsLocatorContext()
l = QgsLocator()
filter_a = test_filter('a')
l.registerFilter(filter_a)
l.foundResult.connect(got_hit)
l.fetchResults('a', context)
l.cancel()
def testPrefixes(self):
"""
Test custom (active) prefixes
"""
def got_hit(result):
got_hit._results_.append(result.displayString)
got_hit._results_ = []
context = QgsLocatorContext()
l = QgsLocator()
# filter with prefix
filter_a = test_filter('a', 'aaa')
l.registerFilter(filter_a)
self.assertEqual(filter_a.prefix(), 'aaa')
self.assertEqual(filter_a.activePrefix(), 'aaa')
self.assertEqual(filter_a.useWithoutPrefix(), True)
l.foundResult.connect(got_hit)
l.fetchResults('aaa a', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'a0', 'a1', 'a2'})
got_hit._results_ = []
l.fetchResults('bbb b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'a0', 'a1', 'a2'})
got_hit._results_ = []
filter_a.setUseWithoutPrefix(False)
self.assertEqual(filter_a.useWithoutPrefix(), False)
l.fetchResults('bbb b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(got_hit._results_, [])
got_hit._results_ = []
# test with two filters
filter_b = test_filter('b', 'bbb')
l.registerFilter(filter_b)
self.assertEqual(filter_b.prefix(), 'bbb')
self.assertEqual(filter_b.activePrefix(), 'bbb')
got_hit._results_ = []
l.fetchResults('bbb b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'b0', 'b1', 'b2'})
l.deregisterFilter(filter_b)
# test with two filters with same prefix
filter_b = test_filter('b', 'aaa')
l.registerFilter(filter_b)
self.assertEqual(filter_b.prefix(), 'aaa')
self.assertEqual(filter_b.activePrefix(), 'aaa')
got_hit._results_ = []
l.fetchResults('aaa b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'a0', 'a1', 'a2', 'b0', 'b1', 'b2'})
l.deregisterFilter(filter_b)
# filter with invalid prefix (less than 3 char)
filter_c = test_filter('c', 'bb')
l.registerFilter(filter_c)
self.assertEqual(filter_c.prefix(), 'bb')
self.assertEqual(filter_c.activePrefix(), '')
got_hit._results_ = []
l.fetchResults('b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'c0', 'c1', 'c2'})
l.deregisterFilter(filter_c)
# filter with custom prefix
QgsSettings().setValue("locator_filters/prefix_test_custom", 'xyz', QgsSettings.Gui)
filter_c = test_filter('custom', 'abc')
l.registerFilter(filter_c)
self.assertEqual(filter_c.prefix(), 'abc')
self.assertEqual(filter_c.activePrefix(), 'xyz')
got_hit._results_ = []
l.fetchResults('b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(set(got_hit._results_), {'custom0', 'custom1', 'custom2'})
l.deregisterFilter(filter_c)
del l
def testModel(self):
m = QgsLocatorModel()
p = QgsLocatorProxyModel(m)
p.setSourceModel(m)
l = QgsLocator()
filter_a = test_filter('a')
l.registerFilter(filter_a)
l.foundResult.connect(m.addResult)
context = QgsLocatorContext()
l.fetchResults('a', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
# 4 results - one is locator name
self.assertEqual(p.rowCount(), 4)
self.assertEqual(p.data(p.index(0, 0)), 'test_a')
self.assertEqual(p.data(p.index(0, 0), QgsLocatorModel.ResultTypeRole), 0)
self.assertEqual(p.data(p.index(0, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
self.assertEqual(p.data(p.index(1, 0)), 'a0')
self.assertEqual(p.data(p.index(1, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(p.data(p.index(1, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
self.assertEqual(p.data(p.index(2, 0)), 'a1')
self.assertEqual(p.data(p.index(2, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(p.data(p.index(2, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
self.assertEqual(p.data(p.index(3, 0)), 'a2')
self.assertEqual(p.data(p.index(3, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(p.data(p.index(3, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
m.clear()
self.assertEqual(p.rowCount(), 0)
l.fetchResults('b', context)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(p.rowCount(), 4)
self.assertEqual(p.data(p.index(1, 0)), 'a0')
self.assertEqual(p.data(p.index(2, 0)), 'a1')
self.assertEqual(p.data(p.index(3, 0)), 'a2')
m.deferredClear()
# should not be immediately cleared!
self.assertEqual(p.rowCount(), 4)
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(p.rowCount(), 0)
m.clear()
# test with groups
self.assertEqual(p.rowCount(), 0)
filter_b = test_filter('b', None, True)
l.registerFilter(filter_b)
l.fetchResults('c', context)
for i in range(200):
sleep(0.002)
QCoreApplication.processEvents()
self.assertEqual(p.rowCount(), 16) # 1 title a + 3 results + 1 title b + 2 groups + 9 results
self.assertEqual(p.data(p.index(0, 0)), 'test_a')
self.assertEqual(p.data(p.index(0, 0), QgsLocatorModel.ResultTypeRole), 0)
self.assertEqual(p.data(p.index(1, 0)), 'a0')
self.assertEqual(p.data(p.index(1, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(p.data(p.index(2, 0)), 'a1')
self.assertEqual(p.data(p.index(2, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(p.data(p.index(3, 0)), 'a2')
self.assertEqual(p.data(p.index(3, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(p.data(p.index(4, 0)), 'test_b')
self.assertEqual(p.data(p.index(4, 0), QgsLocatorModel.ResultTypeRole), 0)
self.assertEqual(p.data(p.index(4, 0), QgsLocatorModel.ResultFilterNameRole), 'test_b')
self.assertEqual(p.data(p.index(5, 0)).strip(), 'first group')
self.assertEqual(p.data(p.index(5, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(6, 0)), 'b0')
self.assertEqual(p.data(p.index(6, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(7, 0)), 'b1')
self.assertEqual(p.data(p.index(7, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(8, 0)), 'b2')
self.assertEqual(p.data(p.index(8, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(9, 0)), 'b3')
self.assertEqual(p.data(p.index(9, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(10, 0)), 'b4')
self.assertEqual(p.data(p.index(10, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(11, 0)), 'b5')
self.assertEqual(p.data(p.index(11, 0), QgsLocatorModel.ResultTypeRole), 1)
self.assertEqual(p.data(p.index(12, 0)).strip(), 'second group')
self.assertEqual(p.data(p.index(12, 0), QgsLocatorModel.ResultTypeRole), 2)
self.assertEqual(p.data(p.index(13, 0)), 'b6')
self.assertEqual(p.data(p.index(13, 0), QgsLocatorModel.ResultTypeRole), 2)
self.assertEqual(p.data(p.index(14, 0)), 'b7')
self.assertEqual(p.data(p.index(14, 0), QgsLocatorModel.ResultTypeRole), 2)
self.assertEqual(p.data(p.index(15, 0)), 'b8')
self.assertEqual(p.data(p.index(15, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
def testAutoModel(self):
"""
Test automatic model, QgsLocatorAutomaticModel - should be no need
for any manual connections
"""
l = QgsLocator()
m = QgsLocatorAutomaticModel(l)
filter_a = test_filter('a')
l.registerFilter(filter_a)
m.search('a')
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
# 4 results - one is locator name
self.assertEqual(m.rowCount(), 4)
self.assertEqual(m.data(m.index(0, 0)), 'test_a')
self.assertEqual(m.data(m.index(0, 0), QgsLocatorModel.ResultTypeRole), 0)
self.assertEqual(m.data(m.index(0, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
self.assertEqual(m.data(m.index(1, 0)), 'a0')
self.assertEqual(m.data(m.index(1, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(m.data(m.index(1, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
self.assertEqual(m.data(m.index(2, 0)), 'a1')
self.assertEqual(m.data(m.index(2, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(m.data(m.index(2, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
self.assertEqual(m.data(m.index(3, 0)), 'a2')
self.assertEqual(m.data(m.index(3, 0), QgsLocatorModel.ResultTypeRole), QgsLocatorModel.NoGroup)
self.assertEqual(m.data(m.index(3, 0), QgsLocatorModel.ResultFilterNameRole), 'test_a')
m.search('a')
for i in range(100):
sleep(0.002)
QCoreApplication.processEvents()
# 4 results - one is locator name
self.assertEqual(m.rowCount(), 4)
self.assertEqual(m.data(m.index(0, 0)), 'test_a')
self.assertEqual(m.data(m.index(1, 0)), 'a0')
self.assertEqual(m.data(m.index(2, 0)), 'a1')
self.assertEqual(m.data(m.index(3, 0)), 'a2')
def testStringMatches(self):
self.assertFalse(QgsLocatorFilter.stringMatches('xxx', 'yyyy'))
self.assertTrue(QgsLocatorFilter.stringMatches('axxxy', 'xxx'))
self.assertTrue(QgsLocatorFilter.stringMatches('aXXXXy', 'xxx'))
self.assertFalse(QgsLocatorFilter.stringMatches('aXXXXy', ''))
if __name__ == '__main__':
unittest.main()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
31329,
12008,
2295,
367,
4888,
10725,
14,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
624,
199,
363,
2502,
363,
275,
8189,
35,
9,
9708,
701,
653,
89,
452,
577,
10084,
834,
7,
199,
363,
602,
363,
275,
283,
22,
15,
1717,
15,
10680,
7,
199,
363,
7307,
363,
275,
283,
7384,
9708,
12,
710,
27024,
7290,
7,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
646,
15640,
221,
327,
20432,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
10725,
12,
2432,
4888,
10725,
4131,
12,
2432,
4888,
10725,
2998,
12,
2432,
4888,
10725,
2889,
12,
2432,
4888,
10725,
1685,
12,
2432,
4888,
10725,
4936,
1685,
12,
2432,
4888,
10725,
3358,
3889,
1685,
12,
2432,
4888,
5268,
9,
199,
504,
15640,
14,
24107,
14,
10901,
492,
27875,
12,
27149,
11274,
12,
1413,
29263,
199,
504,
900,
492,
9435,
199,
504,
15640,
14,
4776,
492,
1343,
63,
571,
12,
2882,
199,
504,
15640,
14,
24107,
492,
25342,
199,
928,
63,
571,
342,
421,
199,
533,
511,
63,
1541,
8,
7350,
10725,
4131,
304,
339,
347,
636,
826,
721,
277,
12,
5148,
12,
2403,
29,
403,
12,
1572,
2889,
29,
797,
12,
1676,
29,
403,
304,
267,
1613,
11027,
826,
721,
1708,
9,
267,
291,
14,
5364,
275,
5148,
267,
291,
423,
1861,
275,
2403,
267,
291,
14,
923,
2889,
275,
1572,
2889,
339,
347,
7289,
8,
277,
304,
267,
372,
511,
63,
1541,
8,
277,
14,
5364,
12,
291,
14,
1861,
12,
291,
14,
923,
2889,
9,
339,
347,
536,
8,
277,
304,
267,
372,
283,
396,
8650,
435,
291,
14,
5364,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
283,
396,
8650,
435,
291,
14,
5364,
339,
347,
2403,
8,
277,
304,
267,
372,
291,
423,
1861,
339,
347,
5267,
6579,
8,
277,
12,
1059,
12,
1067,
12,
17145,
304,
267,
302,
275,
650,
340,
440,
291,
14,
923,
2889,
587,
1749,
267,
367,
284,
315,
1425,
8,
78,
304,
288,
340,
17145,
14,
374,
35,
18959,
837,
355,
372,
288,
9435,
8,
16,
14,
4587,
9,
288,
754,
275,
4888,
10725,
2889,
342,
288,
754,
14,
2918,
1558,
275,
291,
14,
5364,
435,
620,
8,
73,
9,
288,
340,
291,
14,
923,
2889,
26,
355,
340,
284,
665,
1227,
26,
490,
754,
14,
923,
275,
283,
2246,
1572,
7,
355,
916,
284,
665,
1695,
26,
490,
754,
14,
923,
275,
283,
4375,
1572,
7,
288,
291,
14,
1099,
38,
13534,
14,
8159,
8,
1099,
9,
339,
347,
6804,
2889,
8,
277,
12,
754,
304,
267,
986,
339,
347,
7464,
8,
277,
304,
267,
340,
291,
14,
5364,
508,
283,
65,
356,
288,
372,
4888,
10725,
4131,
14,
11688,
267,
916,
291,
14,
5364,
508,
283,
66,
356,
288,
372,
4888,
10725,
4131,
14,
26139,
267,
916,
291,
14,
5364,
508,
283,
67,
356,
288,
372,
4888,
10725,
4131,
14,
10281,
267,
587,
26,
288,
372,
4888,
10725,
4131,
14,
26139,
421,
199,
533,
1379,
7350,
10725,
8,
2796,
14,
1746,
304,
339,
347,
511,
7099,
316,
18053,
8,
277,
304,
267,
634,
275,
4888,
10725,
342,
267,
2457,
63,
65,
275,
511,
63,
1541,
360,
65,
358,
267,
2457,
63,
66,
275,
511,
63,
1541,
360,
66,
358,
267,
634,
14,
2683,
4131,
8,
1541,
63,
65,
9,
267,
634,
14,
2683,
4131,
8,
1541,
63,
66,
9,
398,
291,
14,
629,
8,
409,
8,
76,
14,
4273,
4000,
469,
1541,
63,
65,
12,
2457,
63,
66,
1552,
398,
327,
12715,
1077,
506,
1752,
5057,
370,
14067,
267,
2150,
634,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
65,
430,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
66,
430,
398,
327,
862,
10250,
477,
2683,
316,
267,
634,
275,
4888,
10725,
342,
267,
2457,
63,
67,
275,
511,
63,
1541,
360,
67,
358,
267,
2457,
63,
68,
275,
511,
63,
1541,
360,
68,
358,
267,
634,
14,
2683,
4131,
8,
1541,
63,
67,
9,
267,
634,
14,
2683,
4131,
8,
1541,
63,
68,
9,
267,
291,
14,
629,
8,
409,
8,
76,
14,
4273,
4000,
469,
1541,
63,
67,
12,
2457,
63,
68,
1552,
398,
634,
14,
271,
2683,
4131,
8,
1541,
63,
67,
9,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
67,
430,
267,
291,
14,
3334,
8,
17839,
14,
374,
6062,
8,
1541,
63,
68,
430,
267,
291,
14,
629,
8,
76,
14,
4273,
1062,
359,
1541,
63,
68,
566,
267,
2150,
634,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
67,
430,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
68,
430,
339,
347,
511,
11135,
316,
6579,
8,
277,
304,
398,
347,
4788,
63,
12948,
8,
1099,
304,
288,
4788,
63,
12948,
423,
2604,
3754,
740,
8,
1099,
14,
2918,
1558,
9,
398,
4788,
63,
12948,
423,
2604,
63,
275,
942,
398,
1067,
275,
4888,
10725,
2998,
342,
398,
327,
1373,
2457,
267,
634,
275,
4888,
10725,
342,
267,
2457,
63,
65,
275,
511,
63,
1541,
360,
65,
358,
398,
634,
14,
2683,
4131,
8,
1541,
63,
65,
9,
398,
634,
14,
4214,
2889,
14,
2242,
8,
7808,
63,
12948,
9,
267,
634,
14,
3535,
6579,
360,
65,
297,
1067,
9,
398,
367,
284,
315,
1425,
8,
1960,
304,
288,
9435,
8,
16,
14,
7432,
9,
288,
1413,
29263,
14,
1412,
11770,
342,
398,
291,
14,
629,
8,
409,
8,
7808,
63,
12948,
423,
2604,
29425,
791,
65,
16,
297,
283,
65,
17,
297,
283,
65,
18,
3071,
398,
327,
2877,
4766,
267,
2457,
63,
66,
275,
511,
63,
1541,
360,
66,
358,
267,
634,
14,
2683,
4131,
8,
1541,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
31329,
12008,
2295,
367,
4888,
10725,
14,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
624,
199,
363,
2502,
363,
275,
8189,
35,
9,
9708,
701,
653,
89,
452,
577,
10084,
834,
7,
199,
363,
602,
363,
275,
283,
22,
15,
1717,
15,
10680,
7,
199,
363,
7307,
363,
275,
283,
7384,
9708,
12,
710,
27024,
7290,
7,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
646,
15640,
221,
327,
20432,
199,
199,
646,
747,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
10725,
12,
2432,
4888,
10725,
4131,
12,
2432,
4888,
10725,
2998,
12,
2432,
4888,
10725,
2889,
12,
2432,
4888,
10725,
1685,
12,
2432,
4888,
10725,
4936,
1685,
12,
2432,
4888,
10725,
3358,
3889,
1685,
12,
2432,
4888,
5268,
9,
199,
504,
15640,
14,
24107,
14,
10901,
492,
27875,
12,
27149,
11274,
12,
1413,
29263,
199,
504,
900,
492,
9435,
199,
504,
15640,
14,
4776,
492,
1343,
63,
571,
12,
2882,
199,
504,
15640,
14,
24107,
492,
25342,
199,
928,
63,
571,
342,
421,
199,
533,
511,
63,
1541,
8,
7350,
10725,
4131,
304,
339,
347,
636,
826,
721,
277,
12,
5148,
12,
2403,
29,
403,
12,
1572,
2889,
29,
797,
12,
1676,
29,
403,
304,
267,
1613,
11027,
826,
721,
1708,
9,
267,
291,
14,
5364,
275,
5148,
267,
291,
423,
1861,
275,
2403,
267,
291,
14,
923,
2889,
275,
1572,
2889,
339,
347,
7289,
8,
277,
304,
267,
372,
511,
63,
1541,
8,
277,
14,
5364,
12,
291,
14,
1861,
12,
291,
14,
923,
2889,
9,
339,
347,
536,
8,
277,
304,
267,
372,
283,
396,
8650,
435,
291,
14,
5364,
339,
347,
2929,
985,
8,
277,
304,
267,
372,
283,
396,
8650,
435,
291,
14,
5364,
339,
347,
2403,
8,
277,
304,
267,
372,
291,
423,
1861,
339,
347,
5267,
6579,
8,
277,
12,
1059,
12,
1067,
12,
17145,
304,
267,
302,
275,
650,
340,
440,
291,
14,
923,
2889,
587,
1749,
267,
367,
284,
315,
1425,
8,
78,
304,
288,
340,
17145,
14,
374,
35,
18959,
837,
355,
372,
288,
9435,
8,
16,
14,
4587,
9,
288,
754,
275,
4888,
10725,
2889,
342,
288,
754,
14,
2918,
1558,
275,
291,
14,
5364,
435,
620,
8,
73,
9,
288,
340,
291,
14,
923,
2889,
26,
355,
340,
284,
665,
1227,
26,
490,
754,
14,
923,
275,
283,
2246,
1572,
7,
355,
916,
284,
665,
1695,
26,
490,
754,
14,
923,
275,
283,
4375,
1572,
7,
288,
291,
14,
1099,
38,
13534,
14,
8159,
8,
1099,
9,
339,
347,
6804,
2889,
8,
277,
12,
754,
304,
267,
986,
339,
347,
7464,
8,
277,
304,
267,
340,
291,
14,
5364,
508,
283,
65,
356,
288,
372,
4888,
10725,
4131,
14,
11688,
267,
916,
291,
14,
5364,
508,
283,
66,
356,
288,
372,
4888,
10725,
4131,
14,
26139,
267,
916,
291,
14,
5364,
508,
283,
67,
356,
288,
372,
4888,
10725,
4131,
14,
10281,
267,
587,
26,
288,
372,
4888,
10725,
4131,
14,
26139,
421,
199,
533,
1379,
7350,
10725,
8,
2796,
14,
1746,
304,
339,
347,
511,
7099,
316,
18053,
8,
277,
304,
267,
634,
275,
4888,
10725,
342,
267,
2457,
63,
65,
275,
511,
63,
1541,
360,
65,
358,
267,
2457,
63,
66,
275,
511,
63,
1541,
360,
66,
358,
267,
634,
14,
2683,
4131,
8,
1541,
63,
65,
9,
267,
634,
14,
2683,
4131,
8,
1541,
63,
66,
9,
398,
291,
14,
629,
8,
409,
8,
76,
14,
4273,
4000,
469,
1541,
63,
65,
12,
2457,
63,
66,
1552,
398,
327,
12715,
1077,
506,
1752,
5057,
370,
14067,
267,
2150,
634,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
65,
430,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
66,
430,
398,
327,
862,
10250,
477,
2683,
316,
267,
634,
275,
4888,
10725,
342,
267,
2457,
63,
67,
275,
511,
63,
1541,
360,
67,
358,
267,
2457,
63,
68,
275,
511,
63,
1541,
360,
68,
358,
267,
634,
14,
2683,
4131,
8,
1541,
63,
67,
9,
267,
634,
14,
2683,
4131,
8,
1541,
63,
68,
9,
267,
291,
14,
629,
8,
409,
8,
76,
14,
4273,
4000,
469,
1541,
63,
67,
12,
2457,
63,
68,
1552,
398,
634,
14,
271,
2683,
4131,
8,
1541,
63,
67,
9,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
67,
430,
267,
291,
14,
3334,
8,
17839,
14,
374,
6062,
8,
1541,
63,
68,
430,
267,
291,
14,
629,
8,
76,
14,
4273,
1062,
359,
1541,
63,
68,
566,
267,
2150,
634,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
67,
430,
267,
291,
14,
1815,
8,
17839,
14,
374,
6062,
8,
1541,
63,
68,
430,
339,
347,
511,
11135,
316,
6579,
8,
277,
304,
398,
347,
4788,
63,
12948,
8,
1099,
304,
288,
4788,
63,
12948,
423,
2604,
3754,
740,
8,
1099,
14,
2918,
1558,
9,
398,
4788,
63,
12948,
423,
2604,
63,
275,
942,
398,
1067,
275,
4888,
10725,
2998,
342,
398,
327,
1373,
2457,
267,
634,
275,
4888,
10725,
342,
267,
2457,
63,
65,
275,
511,
63,
1541,
360,
65,
358,
398,
634,
14,
2683,
4131,
8,
1541,
63,
65,
9,
398,
634,
14,
4214,
2889,
14,
2242,
8,
7808,
63,
12948,
9,
267,
634,
14,
3535,
6579,
360,
65,
297,
1067,
9,
398,
367,
284,
315,
1425,
8,
1960,
304,
288,
9435,
8,
16,
14,
7432,
9,
288,
1413,
29263,
14,
1412,
11770,
342,
398,
291,
14,
629,
8,
409,
8,
7808,
63,
12948,
423,
2604,
29425,
791,
65,
16,
297,
283,
65,
17,
297,
283,
65,
18,
3071,
398,
327,
2877,
4766,
267,
2457,
63,
66,
275,
511,
63,
1541,
360,
66,
358,
267,
634,
14,
2683,
4131,
8,
1541,
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,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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
] |
ryfeus/lambda-packs
|
Selenium_PhantomJS/source/pyasn1_modules/rfc3447.py
|
127
|
1400
|
#
# PKCS#1 syntax
#
# ASN.1 source from:
# ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.asn
#
# Sample captures could be obtained with "openssl genrsa" command
#
from pyasn1_modules.rfc2437 import *
class OtherPrimeInfo(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('prime', univ.Integer()),
namedtype.NamedType('exponent', univ.Integer()),
namedtype.NamedType('coefficient', univ.Integer())
)
class OtherPrimeInfos(univ.SequenceOf):
componentType = OtherPrimeInfo()
subtypeSpec = univ.SequenceOf.subtypeSpec + \
constraint.ValueSizeConstraint(1, MAX)
class RSAPrivateKey(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('version', univ.Integer(namedValues=namedval.NamedValues(('two-prime', 0), ('multi', 1)))),
namedtype.NamedType('modulus', univ.Integer()),
namedtype.NamedType('publicExponent', univ.Integer()),
namedtype.NamedType('privateExponent', univ.Integer()),
namedtype.NamedType('prime1', univ.Integer()),
namedtype.NamedType('prime2', univ.Integer()),
namedtype.NamedType('exponent1', univ.Integer()),
namedtype.NamedType('exponent2', univ.Integer()),
namedtype.NamedType('coefficient', univ.Integer()),
namedtype.OptionalNamedType('otherPrimeInfos', OtherPrimeInfos())
)
|
mit
|
[
3,
199,
3,
32040,
3,
17,
6302,
199,
3,
199,
3,
31139,
14,
17,
1350,
687,
26,
199,
3,
14904,
921,
8915,
14,
2393,
482,
3360,
14,
957,
15,
5645,
15,
27100,
15,
27100,
13,
17,
15,
27100,
13,
17,
86,
18,
13,
17,
14,
6228,
199,
3,
199,
3,
15227,
12162,
1482,
4293,
506,
15884,
543,
298,
14837,
3805,
13487,
2,
1414,
199,
3,
199,
504,
1134,
6228,
17,
63,
3112,
14,
8973,
1194,
1401,
492,
627,
199,
199,
533,
5439,
4562,
278,
2354,
8,
27516,
14,
5826,
304,
272,
3931,
804,
275,
17712,
14,
7989,
4100,
8,
267,
17712,
14,
20317,
360,
12446,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
23475,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
21329,
297,
17225,
14,
2674,
1012,
267,
776,
199,
199,
533,
5439,
4562,
278,
32083,
8,
27516,
14,
5826,
3466,
304,
272,
3931,
804,
275,
5439,
4562,
278,
2354,
342,
272,
15686,
5307,
275,
17225,
14,
5826,
3466,
14,
10512,
5307,
435,
971,
2116,
5828,
14,
1110,
2320,
8463,
8,
17,
12,
9141,
9,
199,
199,
533,
820,
51,
1282,
322,
2409,
1197,
8,
27516,
14,
5826,
304,
272,
3931,
804,
275,
17712,
14,
7989,
4100,
8,
267,
17712,
14,
20317,
360,
1023,
297,
17225,
14,
2674,
8,
4579,
6550,
29,
4579,
637,
14,
7989,
6550,
4725,
5601,
13,
12446,
297,
378,
395,
661,
3029,
297,
413,
1724,
395,
267,
17712,
14,
20317,
360,
1494,
15909,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
3455,
30153,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
4239,
30153,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
12446,
17,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
12446,
18,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
23475,
17,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
23475,
18,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
21329,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
7012,
20317,
360,
1848,
4562,
278,
32083,
297,
5439,
4562,
278,
32083,
1012,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
32040,
3,
17,
6302,
199,
3,
199,
3,
31139,
14,
17,
1350,
687,
26,
199,
3,
14904,
921,
8915,
14,
2393,
482,
3360,
14,
957,
15,
5645,
15,
27100,
15,
27100,
13,
17,
15,
27100,
13,
17,
86,
18,
13,
17,
14,
6228,
199,
3,
199,
3,
15227,
12162,
1482,
4293,
506,
15884,
543,
298,
14837,
3805,
13487,
2,
1414,
199,
3,
199,
504,
1134,
6228,
17,
63,
3112,
14,
8973,
1194,
1401,
492,
627,
199,
199,
533,
5439,
4562,
278,
2354,
8,
27516,
14,
5826,
304,
272,
3931,
804,
275,
17712,
14,
7989,
4100,
8,
267,
17712,
14,
20317,
360,
12446,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
23475,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
21329,
297,
17225,
14,
2674,
1012,
267,
776,
199,
199,
533,
5439,
4562,
278,
32083,
8,
27516,
14,
5826,
3466,
304,
272,
3931,
804,
275,
5439,
4562,
278,
2354,
342,
272,
15686,
5307,
275,
17225,
14,
5826,
3466,
14,
10512,
5307,
435,
971,
2116,
5828,
14,
1110,
2320,
8463,
8,
17,
12,
9141,
9,
199,
199,
533,
820,
51,
1282,
322,
2409,
1197,
8,
27516,
14,
5826,
304,
272,
3931,
804,
275,
17712,
14,
7989,
4100,
8,
267,
17712,
14,
20317,
360,
1023,
297,
17225,
14,
2674,
8,
4579,
6550,
29,
4579,
637,
14,
7989,
6550,
4725,
5601,
13,
12446,
297,
378,
395,
661,
3029,
297,
413,
1724,
395,
267,
17712,
14,
20317,
360,
1494,
15909,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
3455,
30153,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
4239,
30153,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
12446,
17,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
12446,
18,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
23475,
17,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
23475,
18,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
20317,
360,
21329,
297,
17225,
14,
2674,
4000,
267,
17712,
14,
7012,
20317,
360,
1848,
4562,
278,
32083,
297,
5439,
4562,
278,
32083,
1012,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ales-erjavec/orange
|
Orange/OrangeWidgets/Visualize/OWSurveyPlot.py
|
6
|
9664
|
"""
<name>Survey Plot</name>
<description>Survey plot (multiattribute) visualization.</description>
<contact>Gregor Leban (gregor.leban@fri.uni-lj.si)</contact>
<icon>icons/SurveyPlot.svg</icon>
<priority>3250</priority>
"""
# OWSurveyPlot.py
#
# Show data using survey plot visualization method
#
from OWVisWidget import *
from OWSurveyPlotGraph import *
import OWColorPalette
import orngVisFuncts
import OWGUI
###########################################################################################
##### WIDGET : Survey plot visualization
###########################################################################################
class OWSurveyPlot(OWVisWidget):
settingsList = ["graph.exampleTracking", "graph.enabledLegend",
"graph.tooltipKind", "showAllAttributes", "colorSettings", "selectedSchemaIndex"]
attributeContOrder = ["Unordered","ReliefF", "Fisher discriminant"]
attributeDiscOrder = ["Unordered","ReliefF","GainRatio"]
contextHandlers = {"": DomainContextHandler("", [ContextField("shownAttributes", DomainContextHandler.RequiredList, selected="selectedShown", reservoir="hiddenAttributes")])}
def __init__(self,parent=None, signalManager = None):
OWWidget.__init__(self, parent, signalManager, "Survey Plot", TRUE)
self.inputs = [("Data", ExampleTable, self.setData, Default), ("Features", AttributeList, self.setShownAttributes)]
self.outputs = [("Features", AttributeList)]
#add a graph widget
self.graph = OWSurveyPlotGraph(self.mainArea)
self.mainArea.layout().addWidget(self.graph)
self.connect(self.graphButton, SIGNAL("clicked()"), self.graph.saveToFile)
#set default settings
self.data = None
self.showAllAttributes = 0
self.graph.exampleTracking = 0
self.graph.enabledLegend = 1
self.graph.tooltipKind = 1
self.attributeSelectionList = None
self.graphCanvasColor = str(QColor(Qt.white).name())
self.primaryAttribute = "(None)"
self.secondaryAttribute = "(None)"
self.colorSettings = None
self.selectedSchemaIndex = 0
#load settings
self.loadSettings()
#GUI
self.tabs = OWGUI.tabWidget(self.controlArea)
self.GeneralTab = OWGUI.createTabPage(self.tabs, "Main")
self.SettingsTab = OWGUI.createTabPage(self.tabs, "Settings")
#add controls to self.controlArea widget
self.sortingAttrGB = OWGUI.widgetBox(self.GeneralTab, "Sorting")
self.primaryAttrCombo = OWGUI.comboBoxWithCaption(self.sortingAttrGB, self, "primaryAttribute", label = '1st:', items = ["(None)"], sendSelectedValue = 1, valueType = str, callback = self.sortingClick, labelWidth = 25)
self.secondaryAttrCombo = OWGUI.comboBoxWithCaption(self.sortingAttrGB, self, "secondaryAttribute", label = '2nd:', items = ["(None)"], sendSelectedValue = 1, valueType = str, callback = self.sortingClick, labelWidth = 25)
self.createShowHiddenLists(self.GeneralTab, callback = self.updateGraph)
# ##################################
# survey plot settings
box = OWGUI.widgetBox(self.SettingsTab, "Visual settings")
OWGUI.checkBox(box, self, "graph.exampleTracking", "Example tracking", callback = self.updateGraph)
OWGUI.checkBox(box, self, "graph.enabledLegend", "Show legend", callback = self.updateGraph)
box = OWGUI.widgetBox(self.SettingsTab, "Tooltips settings")
OWGUI.comboBox(box, self, "graph.tooltipKind", items = ["Don't Show Tooltips", "Show Visible Attributes", "Show All Attributes"], callback = self.updateGraph)
self.colorButtonsBox = OWGUI.widgetBox(self.SettingsTab, "Colors", orientation = "horizontal")
OWGUI.button(self.colorButtonsBox, self, "Set Colors", self.setColors, tooltip = "Set the canvas background color, grid color and color palette for coloring continuous variables", debuggingEnabled = 0)
self.SettingsTab.layout().addStretch(100)
self.icons = self.createAttributeIconDict()
dlg = self.createColorDialog()
self.graph.contPalette = dlg.getContinuousPalette("contPalette")
self.graph.discPalette = dlg.getDiscretePalette("discPalette")
self.graph.setCanvasBackground(dlg.getColor("Canvas"))
self.graph.gridCurve.setPen(QPen(dlg.getColor("Grid")))
#self.graph.setCanvasBackground(QColor(self.graphCanvasColor))
self.cbShowAllAttributes()
self.resize(750,700)
# #####################
def setSortCombo(self):
items = [str(self.primaryAttrCombo.itemText(i)) for i in range(1, self.primaryAttrCombo.count())]
attrs = self.graph.dataDomain and [attr.name for attr in self.graph.dataDomain]
if items == attrs:
return
self.primaryAttrCombo.clear()
self.secondaryAttrCombo.clear()
self.primaryAttrCombo.addItem("(None)")
self.secondaryAttrCombo.addItem("(None)")
if not self.graph.haveData: return
for attr in self.graph.dataDomain:
self.primaryAttrCombo.addItem(self.icons[attr.varType], attr.name)
self.secondaryAttrCombo.addItem(self.icons[attr.varType], attr.name)
self.primaryAttribute = "(None)"
self.secondaryAttribute = "(None)"
def updateGraph(self, *args):
self.graph.updateData(self.getShownAttributeList())
# set combo box values with attributes that can be used for coloring the data
def sortingClick(self):
attrs = [self.primaryAttribute, self.secondaryAttribute]
while "(None)" in attrs: attrs.remove("(None)")
if attrs and self.data:
self.data.sort(attrs)
self.graph.setData(self.data, sortValuesForDiscreteAttrs = 0, skipIfSame = 0)
self.updateGraph()
# receive new data and update all fields
def setData(self, data):
if data and (len(data) == 0 or len(data.domain) == 0):
data = None
if self.data and data and self.data.checksum() == data.checksum():
return # check if the new data set is the same as the old one
self.closeContext()
sameDomain = self.data and data and data.domain.checksum() == self.data.domain.checksum() # preserve attribute choice if the domain is the same
self.data = data
self.graph.setData(self.data)
if self.graph.dataHasDiscreteClass:
self.graph.discPalette.setNumberOfColors(len(self.graph.dataDomain.classVar.values))
if not sameDomain:
self.setShownAttributes(self.attributeSelectionList)
self.resetAttrManipulation()
self.setSortCombo()
self.openContext("", self.data)
self.resetAttrManipulation()
self.updateGraph()
####### SELECTION signal ################################
# receive info about which attributes to show
def setShownAttributes(self, attributeSelectionList):
self.attributeSelectionList = attributeSelectionList
if self.graph.haveData and self.attributeSelectionList and 0 not in [self.graph.attributeNameIndex.has_key(attr) for attr in self.attributeSelectionList]:
self.setShownAttributeList(self.attributeSelectionList)
else:
self.setShownAttributeList()
# update attribute ordering
def updateShownAttributeList(self):
self.setShownAttributeList()
self.updateGraph()
def sendShownAttributes(self):
self.send("Features", [a[0] for a in self.shownAttributes])
# just tell the graph to hide the selected rectangle
def enterEvent(self, e):
if self.graph.selectedRectangle:
self.graph.selectedRectangle.detach()
self.graph.selectedRectangle = None
self.graph.replot()
def setColors(self):
dlg = self.createColorDialog()
if dlg.exec_():
self.colorSettings = dlg.getColorSchemas()
self.selectedSchemaIndex = dlg.selectedSchemaIndex
self.graph.contPalette = dlg.getContinuousPalette("contPalette")
self.graph.discPalette = dlg.getDiscretePalette("discPalette")
self.graph.setCanvasBackground(dlg.getColor("Canvas"))
self.graph.gridCurve.setPen(QPen(dlg.getColor("Grid")))
self.updateGraph()
def createColorDialog(self):
c = OWColorPalette.ColorPaletteDlg(self, "Color palette")
c.createDiscretePalette("discPalette", "Discrete Palette")
c.createContinuousPalette("contPalette", "Continuous Palette")
box = c.createBox("otherColors", "Other Colors")
c.createColorButton(box, "Canvas", "Canvas color", Qt.white)
box.layout().addSpacing(5)
c.createColorButton(box, "Grid", "Grid color", Qt.black)
box.layout().addSpacing(5)
c.setColorSchemas(self.colorSettings, self.selectedSchemaIndex)
return c
def sendReport(self):
self.reportSettings("",
[("Sorting", ", ".join([x for x in (self.primaryAttribute, self.secondaryAttribute) if x != "(None)"]) or "None"),
# ("Continuous attribute ordering", self.attrContOrder),
# ("Discrete attribute ordering", self.attrDiscOrder)
])
self.reportRaw("<br/>")
self.reportImage(self.graph.saveToFileDirect, QSize(400, 400))
#test widget appearance
if __name__=="__main__":
a=QApplication(sys.argv)
ow=OWSurveyPlot()
ow.show()
data = orange.ExampleTable(r"e:\Development\Orange Datasets\UCI\wine.tab")
ow.setData(data)
a.exec_()
|
gpl-3.0
|
[
624,
199,
28,
354,
30,
30188,
14794,
1108,
354,
30,
199,
28,
1802,
30,
30188,
5137,
334,
3029,
3215,
9,
13104,
2072,
9758,
1802,
30,
199,
28,
7811,
30,
39,
1135,
269,
491,
2871,
290,
334,
3939,
269,
14,
274,
13206,
32,
25876,
14,
5411,
13,
31025,
14,
338,
15939,
7811,
30,
199,
28,
4677,
30,
16471,
15,
30188,
10711,
14,
10273,
1108,
4677,
30,
199,
28,
6693,
30,
708,
1400,
1108,
6693,
30,
199,
624,
199,
3,
593,
5035,
300,
7158,
10711,
14,
647,
199,
3,
199,
3,
12968,
666,
1808,
16576,
5137,
13104,
2072,
1083,
199,
3,
199,
504,
593,
24918,
374,
3339,
492,
627,
199,
504,
593,
5035,
300,
7158,
10711,
4578,
492,
627,
199,
646,
593,
55,
4117,
24500,
199,
646,
503,
2753,
54,
374,
19941,
3021,
199,
646,
593,
55,
14438,
199,
199,
3060,
6565,
5680,
199,
8776,
644,
998,
2970,
520,
29013,
5137,
13104,
2072,
199,
3060,
6565,
5680,
199,
533,
593,
5035,
300,
7158,
10711,
8,
19716,
54,
374,
3339,
304,
272,
2202,
1296,
275,
2097,
2180,
14,
2694,
23785,
401,
298,
2180,
14,
3827,
23439,
401,
490,
298,
2180,
14,
22972,
13028,
401,
298,
2384,
2422,
5379,
401,
298,
2326,
5268,
401,
298,
5511,
6700,
2681,
937,
272,
2225,
714,
84,
4738,
275,
2097,
1358,
8235,
2266,
497,
317,
2829,
38,
401,
298,
38,
2453,
281,
487,
20129,
867,
937,
272,
2225,
18230,
4738,
275,
2097,
1358,
8235,
2266,
497,
317,
2829,
38,
2266,
28370,
13971,
937,
272,
1067,
25096,
275,
469,
29679,
14061,
2998,
2461,
12398,
359,
2998,
792,
480,
24422,
5379,
401,
14061,
2998,
2461,
14,
8030,
1296,
12,
4895,
628,
5511,
6824,
78,
401,
295,
25943,
723,
628,
5642,
5379,
13403,
93,
339,
347,
636,
826,
721,
277,
12,
1708,
29,
403,
12,
4673,
2988,
275,
488,
304,
267,
593,
55,
3339,
855,
826,
721,
277,
12,
1676,
12,
4673,
2988,
12,
298,
30188,
14794,
401,
9074,
4187,
9,
398,
291,
14,
3711,
275,
10003,
1451,
401,
5679,
3186,
12,
291,
14,
32288,
12,
3758,
395,
1689,
10807,
401,
3882,
1296,
12,
291,
14,
409,
6824,
78,
5379,
1874,
267,
291,
14,
4467,
275,
10003,
10807,
401,
3882,
1296,
1874,
398,
327,
525,
282,
3343,
3938,
267,
291,
14,
2180,
275,
593,
5035,
300,
7158,
10711,
4578,
8,
277,
14,
973,
11043,
9,
267,
291,
14,
973,
11043,
14,
4209,
1252,
9475,
8,
277,
14,
2180,
9,
267,
291,
14,
2242,
8,
277,
14,
2180,
4259,
12,
24360,
480,
11276,
26322,
291,
14,
2180,
14,
2117,
24320,
9,
398,
327,
409,
849,
2202,
267,
291,
14,
576,
275,
488,
267,
291,
14,
2384,
2422,
5379,
275,
378,
267,
291,
14,
2180,
14,
2694,
23785,
275,
378,
267,
291,
14,
2180,
14,
3827,
23439,
275,
413,
267,
291,
14,
2180,
14,
22972,
13028,
275,
413,
267,
291,
14,
3215,
7713,
1296,
275,
488,
267,
291,
14,
2180,
15174,
4117,
275,
620,
8,
24387,
8,
4238,
14,
7510,
680,
354,
1012,
267,
291,
14,
3327,
1646,
275,
7340,
403,
2924,
267,
291,
14,
12371,
1646,
275,
7340,
403,
2924,
267,
291,
14,
2326,
5268,
275,
488,
267,
291,
14,
5511,
6700,
2681,
275,
378,
398,
327,
912,
2202,
267,
291,
14,
912,
5268,
342,
398,
327,
14438,
267,
291,
14,
8741,
275,
593,
55,
14438,
14,
2902,
3339,
8,
277,
14,
2785,
11043,
9,
267,
291,
14,
14109,
7690,
275,
593,
55,
14438,
14,
981,
7690,
3276,
8,
277,
14,
8741,
12,
298,
6756,
531,
267,
291,
14,
5268,
7690,
275,
593,
55,
14438,
14,
981,
7690,
3276,
8,
277,
14,
8741,
12,
298,
5268,
531,
7318,
327,
525,
13467,
370,
291,
14,
2785,
11043,
3938,
267,
291,
14,
29411,
7144,
6487,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
14109,
7690,
12,
298,
14376,
316,
531,
267,
291,
14,
3327,
7144,
12413,
275,
593,
55,
14438,
14,
12650,
3532,
3007,
28366,
8,
277,
14,
29411,
7144,
6487,
12,
291,
12,
298,
3327,
1646,
401,
1768,
275,
283,
17,
270,
6536,
2974,
275,
2097,
8,
403,
9,
2255,
3222,
12461,
1110,
275,
413,
12,
574,
804,
275,
620,
12,
3233,
275,
291,
14,
29411,
12040,
12,
1768,
6216,
275,
5661,
9,
267,
291,
14,
12371,
7144,
12413,
275,
593,
55,
14438,
14,
12650,
3532,
3007,
28366,
8,
277,
14,
29411,
7144,
6487,
12,
291,
12,
298,
12371,
1646,
401,
1768,
275,
283,
18,
977,
6536,
2974,
275,
2097,
8,
403,
9,
2255,
3222,
12461,
1110,
275,
413,
12,
574,
804,
275,
620,
12,
3233,
275,
291,
14,
29411,
12040,
12,
1768,
6216,
275,
5661,
9,
398,
291,
14,
981,
6824,
14983,
15116,
8,
277,
14,
14109,
7690,
12,
3233,
275,
291,
14,
873,
4578,
9,
398,
327,
10371,
309,
267,
327,
16576,
5137,
2202,
267,
5689,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
5268,
7690,
12,
298,
15039,
2202,
531,
267,
593,
55,
14438,
14,
1074,
3532,
8,
1977,
12,
291,
12,
298,
2180,
14,
2694,
23785,
401,
298,
9846,
15161,
401,
3233,
275,
291,
14,
873,
4578,
9,
267,
593,
55,
14438,
14,
1074,
3532,
8,
1977,
12,
291,
12,
298,
2180,
14,
3827,
23439,
401,
298,
6824,
15906,
401,
3233,
275,
291,
14,
873,
4578,
9,
398,
5689,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
5268,
7690,
12,
298,
5157,
25842,
2202,
531,
267,
593,
55,
14438,
14,
12650,
3532,
8,
1977,
12,
291,
12,
298,
2180,
14,
22972,
13028,
401,
2974,
275,
2097,
16932,
1133,
12968,
15650,
25842,
401,
298,
6824,
6561,
1164,
9382,
401,
298,
6824,
2900,
9382,
2255,
3233,
275,
291,
14,
873,
4578,
9,
398,
291,
14,
2326,
24021,
3532,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
5268,
7690,
12,
298,
20094,
401,
16774,
275,
298,
11392,
531,
267,
593,
55,
14438,
14,
3887,
8,
277,
14,
2326,
24021,
3532,
12,
291,
12,
298,
1084,
3626,
1384,
401,
291,
14,
409,
20094,
12,
28013,
275,
298,
1084,
314,
10218,
8020,
3164,
12,
6068,
3164,
436,
3164,
17986,
367,
3164,
316,
19922,
2860,
401,
10201,
6589,
275,
378,
9,
267,
291,
14,
5268,
7690,
14,
4209,
1252,
525,
21537,
8,
1960,
9,
398,
291,
14,
16471,
275,
291,
14
] |
[
199,
28,
354,
30,
30188,
14794,
1108,
354,
30,
199,
28,
1802,
30,
30188,
5137,
334,
3029,
3215,
9,
13104,
2072,
9758,
1802,
30,
199,
28,
7811,
30,
39,
1135,
269,
491,
2871,
290,
334,
3939,
269,
14,
274,
13206,
32,
25876,
14,
5411,
13,
31025,
14,
338,
15939,
7811,
30,
199,
28,
4677,
30,
16471,
15,
30188,
10711,
14,
10273,
1108,
4677,
30,
199,
28,
6693,
30,
708,
1400,
1108,
6693,
30,
199,
624,
199,
3,
593,
5035,
300,
7158,
10711,
14,
647,
199,
3,
199,
3,
12968,
666,
1808,
16576,
5137,
13104,
2072,
1083,
199,
3,
199,
504,
593,
24918,
374,
3339,
492,
627,
199,
504,
593,
5035,
300,
7158,
10711,
4578,
492,
627,
199,
646,
593,
55,
4117,
24500,
199,
646,
503,
2753,
54,
374,
19941,
3021,
199,
646,
593,
55,
14438,
199,
199,
3060,
6565,
5680,
199,
8776,
644,
998,
2970,
520,
29013,
5137,
13104,
2072,
199,
3060,
6565,
5680,
199,
533,
593,
5035,
300,
7158,
10711,
8,
19716,
54,
374,
3339,
304,
272,
2202,
1296,
275,
2097,
2180,
14,
2694,
23785,
401,
298,
2180,
14,
3827,
23439,
401,
490,
298,
2180,
14,
22972,
13028,
401,
298,
2384,
2422,
5379,
401,
298,
2326,
5268,
401,
298,
5511,
6700,
2681,
937,
272,
2225,
714,
84,
4738,
275,
2097,
1358,
8235,
2266,
497,
317,
2829,
38,
401,
298,
38,
2453,
281,
487,
20129,
867,
937,
272,
2225,
18230,
4738,
275,
2097,
1358,
8235,
2266,
497,
317,
2829,
38,
2266,
28370,
13971,
937,
272,
1067,
25096,
275,
469,
29679,
14061,
2998,
2461,
12398,
359,
2998,
792,
480,
24422,
5379,
401,
14061,
2998,
2461,
14,
8030,
1296,
12,
4895,
628,
5511,
6824,
78,
401,
295,
25943,
723,
628,
5642,
5379,
13403,
93,
339,
347,
636,
826,
721,
277,
12,
1708,
29,
403,
12,
4673,
2988,
275,
488,
304,
267,
593,
55,
3339,
855,
826,
721,
277,
12,
1676,
12,
4673,
2988,
12,
298,
30188,
14794,
401,
9074,
4187,
9,
398,
291,
14,
3711,
275,
10003,
1451,
401,
5679,
3186,
12,
291,
14,
32288,
12,
3758,
395,
1689,
10807,
401,
3882,
1296,
12,
291,
14,
409,
6824,
78,
5379,
1874,
267,
291,
14,
4467,
275,
10003,
10807,
401,
3882,
1296,
1874,
398,
327,
525,
282,
3343,
3938,
267,
291,
14,
2180,
275,
593,
5035,
300,
7158,
10711,
4578,
8,
277,
14,
973,
11043,
9,
267,
291,
14,
973,
11043,
14,
4209,
1252,
9475,
8,
277,
14,
2180,
9,
267,
291,
14,
2242,
8,
277,
14,
2180,
4259,
12,
24360,
480,
11276,
26322,
291,
14,
2180,
14,
2117,
24320,
9,
398,
327,
409,
849,
2202,
267,
291,
14,
576,
275,
488,
267,
291,
14,
2384,
2422,
5379,
275,
378,
267,
291,
14,
2180,
14,
2694,
23785,
275,
378,
267,
291,
14,
2180,
14,
3827,
23439,
275,
413,
267,
291,
14,
2180,
14,
22972,
13028,
275,
413,
267,
291,
14,
3215,
7713,
1296,
275,
488,
267,
291,
14,
2180,
15174,
4117,
275,
620,
8,
24387,
8,
4238,
14,
7510,
680,
354,
1012,
267,
291,
14,
3327,
1646,
275,
7340,
403,
2924,
267,
291,
14,
12371,
1646,
275,
7340,
403,
2924,
267,
291,
14,
2326,
5268,
275,
488,
267,
291,
14,
5511,
6700,
2681,
275,
378,
398,
327,
912,
2202,
267,
291,
14,
912,
5268,
342,
398,
327,
14438,
267,
291,
14,
8741,
275,
593,
55,
14438,
14,
2902,
3339,
8,
277,
14,
2785,
11043,
9,
267,
291,
14,
14109,
7690,
275,
593,
55,
14438,
14,
981,
7690,
3276,
8,
277,
14,
8741,
12,
298,
6756,
531,
267,
291,
14,
5268,
7690,
275,
593,
55,
14438,
14,
981,
7690,
3276,
8,
277,
14,
8741,
12,
298,
5268,
531,
7318,
327,
525,
13467,
370,
291,
14,
2785,
11043,
3938,
267,
291,
14,
29411,
7144,
6487,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
14109,
7690,
12,
298,
14376,
316,
531,
267,
291,
14,
3327,
7144,
12413,
275,
593,
55,
14438,
14,
12650,
3532,
3007,
28366,
8,
277,
14,
29411,
7144,
6487,
12,
291,
12,
298,
3327,
1646,
401,
1768,
275,
283,
17,
270,
6536,
2974,
275,
2097,
8,
403,
9,
2255,
3222,
12461,
1110,
275,
413,
12,
574,
804,
275,
620,
12,
3233,
275,
291,
14,
29411,
12040,
12,
1768,
6216,
275,
5661,
9,
267,
291,
14,
12371,
7144,
12413,
275,
593,
55,
14438,
14,
12650,
3532,
3007,
28366,
8,
277,
14,
29411,
7144,
6487,
12,
291,
12,
298,
12371,
1646,
401,
1768,
275,
283,
18,
977,
6536,
2974,
275,
2097,
8,
403,
9,
2255,
3222,
12461,
1110,
275,
413,
12,
574,
804,
275,
620,
12,
3233,
275,
291,
14,
29411,
12040,
12,
1768,
6216,
275,
5661,
9,
398,
291,
14,
981,
6824,
14983,
15116,
8,
277,
14,
14109,
7690,
12,
3233,
275,
291,
14,
873,
4578,
9,
398,
327,
10371,
309,
267,
327,
16576,
5137,
2202,
267,
5689,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
5268,
7690,
12,
298,
15039,
2202,
531,
267,
593,
55,
14438,
14,
1074,
3532,
8,
1977,
12,
291,
12,
298,
2180,
14,
2694,
23785,
401,
298,
9846,
15161,
401,
3233,
275,
291,
14,
873,
4578,
9,
267,
593,
55,
14438,
14,
1074,
3532,
8,
1977,
12,
291,
12,
298,
2180,
14,
3827,
23439,
401,
298,
6824,
15906,
401,
3233,
275,
291,
14,
873,
4578,
9,
398,
5689,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
5268,
7690,
12,
298,
5157,
25842,
2202,
531,
267,
593,
55,
14438,
14,
12650,
3532,
8,
1977,
12,
291,
12,
298,
2180,
14,
22972,
13028,
401,
2974,
275,
2097,
16932,
1133,
12968,
15650,
25842,
401,
298,
6824,
6561,
1164,
9382,
401,
298,
6824,
2900,
9382,
2255,
3233,
275,
291,
14,
873,
4578,
9,
398,
291,
14,
2326,
24021,
3532,
275,
593,
55,
14438,
14,
3440,
3532,
8,
277,
14,
5268,
7690,
12,
298,
20094,
401,
16774,
275,
298,
11392,
531,
267,
593,
55,
14438,
14,
3887,
8,
277,
14,
2326,
24021,
3532,
12,
291,
12,
298,
1084,
3626,
1384,
401,
291,
14,
409,
20094,
12,
28013,
275,
298,
1084,
314,
10218,
8020,
3164,
12,
6068,
3164,
436,
3164,
17986,
367,
3164,
316,
19922,
2860,
401,
10201,
6589,
275,
378,
9,
267,
291,
14,
5268,
7690,
14,
4209,
1252,
525,
21537,
8,
1960,
9,
398,
291,
14,
16471,
275,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ravibhure/ansible
|
lib/ansible/modules/cloud/amazon/efs_facts.py
|
11
|
11498
|
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'certified'}
DOCUMENTATION = '''
---
module: efs_facts
short_description: Get information about Amazon EFS file systems
description:
- Module searches Amazon EFS file systems
version_added: "2.2"
requirements: [ boto3 ]
author:
- "Ryan Sydnor (@ryansydnor)"
options:
name:
description:
- Creation Token of Amazon EFS file system.
required: false
default: None
id:
description:
- ID of Amazon EFS.
required: false
default: None
tags:
description:
- List of tags of Amazon EFS. Should be defined as dictionary
required: false
default: None
targets:
description:
- list of targets on which to filter the returned results
- result must match all of the specified targets, each of which can be
a security group ID, a subnet ID or an IP address
required: false
default: None
extends_documentation_fragment:
- aws
- ec2
'''
EXAMPLES = '''
# find all existing efs
- efs_facts:
register: result
- efs_facts:
name: myTestNameTag
- efs_facts:
id: fs-1234abcd
# Searching all EFS instances with tag Name = 'myTestNameTag', in subnet 'subnet-1a2b3c4d' and with security group 'sg-4d3c2b1a'
- efs_facts:
tags:
name: myTestNameTag
targets:
- subnet-1a2b3c4d
- sg-4d3c2b1a
'''
RETURN = '''
creation_time:
description: timestamp of creation date
returned: always
type: str
sample: "2015-11-16 07:30:57-05:00"
creation_token:
description: EFS creation token
returned: always
type: str
sample: console-88609e04-9a0e-4a2e-912c-feaa99509961
file_system_id:
description: ID of the file system
returned: always
type: str
sample: fs-xxxxxxxx
life_cycle_state:
description: state of the EFS file system
returned: always
type: str
sample: creating, available, deleting, deleted
mount_point:
description: url of file system
returned: always
type: str
sample: .fs-xxxxxxxx.efs.us-west-2.amazonaws.com:/
mount_targets:
description: list of mount targets
returned: always
type: list
sample:
[
{
"file_system_id": "fs-a7ad440e",
"ip_address": "172.31.17.173",
"life_cycle_state": "available",
"mount_target_id": "fsmt-d8907871",
"network_interface_id": "eni-6e387e26",
"owner_id": "740748460359",
"security_groups": [
"sg-a30b22c6"
],
"subnet_id": "subnet-e265c895"
},
...
]
name:
description: name of the file system
returned: always
type: str
sample: my-efs
number_of_mount_targets:
description: the number of targets mounted
returned: always
type: int
sample: 3
owner_id:
description: AWS account ID of EFS owner
returned: always
type: str
sample: XXXXXXXXXXXX
size_in_bytes:
description: size of the file system in bytes as of a timestamp
returned: always
type: dict
sample:
{
"timestamp": "2015-12-21 13:59:59-05:00",
"value": 12288
}
performance_mode:
description: performance mode of the file system
returned: always
type: str
sample: "generalPurpose"
tags:
description: tags on the efs instance
returned: always
type: dict
sample:
{
"name": "my-efs",
"key": "Value"
}
'''
from collections import defaultdict
try:
import botocore
except ImportError:
pass # caught by AnsibleAWSModule
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, ec2_argument_spec, AWSRetry
from ansible.module_utils.ec2 import camel_dict_to_snake_dict, boto3_tag_list_to_ansible_dict
class EFSConnection(object):
STATE_CREATING = 'creating'
STATE_AVAILABLE = 'available'
STATE_DELETING = 'deleting'
STATE_DELETED = 'deleted'
def __init__(self, module, region, **aws_connect_params):
try:
self.connection = boto3_conn(module, conn_type='client',
resource='efs', region=region,
**aws_connect_params)
self.module = module
except Exception as e:
module.fail_json(msg="Failed to connect to AWS: %s" % str(e))
self.region = region
@AWSRetry.exponential_backoff()
def list_file_systems(self, **kwargs):
"""
Returns generator of file systems including all attributes of FS
"""
paginator = self.connection.get_paginator('describe_file_systems')
return paginator.paginate(**kwargs).build_full_result()['FileSystems']
@AWSRetry.exponential_backoff()
def get_tags(self, file_system_id):
"""
Returns tag list for selected instance of EFS
"""
paginator = self.connection.get_paginator('describe_tags')
return boto3_tag_list_to_ansible_dict(paginator.paginate(FileSystemId=file_system_id).build_full_result()['Tags'])
@AWSRetry.exponential_backoff()
def get_mount_targets(self, file_system_id):
"""
Returns mount targets for selected instance of EFS
"""
paginator = self.connection.get_paginator('describe_mount_targets')
return paginator.paginate(FileSystemId=file_system_id).build_full_result()['MountTargets']
@AWSRetry.exponential_backoff()
def get_security_groups(self, mount_target_id):
"""
Returns security groups for selected instance of EFS
"""
return self.connection.describe_mount_target_security_groups(MountTargetId=mount_target_id)['SecurityGroups']
def get_file_systems(self, file_system_id=None, creation_token=None):
kwargs = dict()
if file_system_id:
kwargs['FileSystemId'] = file_system_id
if creation_token:
kwargs['CreationToken'] = creation_token
try:
file_systems = self.list_file_systems(**kwargs)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self.module.fail_json_aws(e, msg="Couldn't get EFS file systems")
results = list()
for item in file_systems:
item['CreationTime'] = str(item['CreationTime'])
"""
Suffix of network path to be used as NFS device for mount. More detail here:
http://docs.aws.amazon.com/efs/latest/ug/gs-step-three-connect-to-ec2-instance.html
"""
item['MountPoint'] = '.%s.efs.%s.amazonaws.com:/' % (item['FileSystemId'], self.region)
if 'Timestamp' in item['SizeInBytes']:
item['SizeInBytes']['Timestamp'] = str(item['SizeInBytes']['Timestamp'])
if item['LifeCycleState'] == self.STATE_AVAILABLE:
try:
item['MountTargets'] = self.get_mount_targets(item['FileSystemId'])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self.module.fail_json_aws(e, msg="Couldn't get EFS targets")
for target in item['MountTargets']:
if target['LifeCycleState'] == self.STATE_AVAILABLE:
try:
target['SecurityGroups'] = self.get_security_groups(target['MountTargetId'])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self.module.fail_json_aws(e, msg="Couldn't get EFS security groups")
else:
target['SecurityGroups'] = []
else:
item['tags'] = {}
item['mount_targets'] = []
result = camel_dict_to_snake_dict(item)
# Set tags *after* doing camel to snake
if result['life_cycle_state'] == self.STATE_AVAILABLE:
try:
result['tags'] = self.get_tags(result['file_system_id'])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
self.module.fail_json_aws(e, msg="Couldn't get EFS tags")
results.append(result)
return results
def prefix_to_attr(attr_id):
"""
Helper method to convert ID prefix to mount target attribute
"""
attr_by_prefix = {
'fsmt-': 'mount_target_id',
'subnet-': 'subnet_id',
'eni-': 'network_interface_id',
'sg-': 'security_groups'
}
return first_or_default([attr_name for (prefix, attr_name) in attr_by_prefix.items()
if str(attr_id).startswith(prefix)], 'ip_address')
def first_or_default(items, default=None):
"""
Helper method to fetch first element of list (if exists)
"""
for item in items:
return item
return default
def has_tags(available, required):
"""
Helper method to determine if tag requested already exists
"""
for key, value in required.items():
if key not in available or value != available[key]:
return False
return True
def has_targets(available, required):
"""
Helper method to determine if mount target requested already exists
"""
grouped = group_list_of_dict(available)
for (value, field) in required:
if field not in grouped or value not in grouped[field]:
return False
return True
def group_list_of_dict(array):
"""
Helper method to group list of dict to dict with all possible values
"""
result = defaultdict(list)
for item in array:
for key, value in item.items():
result[key] += value if isinstance(value, list) else [value]
return result
def main():
"""
Module action handler
"""
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
id=dict(),
name=dict(),
tags=dict(type="dict", default={}),
targets=dict(type="list", default=[])
))
module = AnsibleAWSModule(argument_spec=argument_spec,
supports_check_mode=True)
region, _, aws_connect_params = get_aws_connection_info(module, boto3=True)
connection = EFSConnection(module, region, **aws_connect_params)
name = module.params.get('name')
fs_id = module.params.get('id')
tags = module.params.get('tags')
targets = module.params.get('targets')
file_systems_info = connection.get_file_systems(fs_id, name)
if tags:
file_systems_info = [item for item in file_systems_info if has_tags(item['tags'], tags)]
if targets:
targets = [(item, prefix_to_attr(item)) for item in targets]
file_systems_info = [item for item in file_systems_info if has_targets(item['mount_targets'], targets)]
module.exit_json(changed=False, ansible_facts={'efs': file_systems_info})
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
325,
2319,
63,
5047,
199,
3612,
63,
1802,
26,
2372,
2556,
3595,
14347,
662,
7079,
570,
10460,
199,
1802,
26,
272,
446,
5673,
21858,
14347,
662,
7079,
570,
10460,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
7538,
26,
359,
6055,
19,
1622,
199,
2502,
26,
272,
446,
298,
50,
89,
290,
5515,
4272,
269,
8593,
651,
796,
89,
4272,
269,
2924,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
288,
446,
9750,
425,
8767,
402,
14347,
662,
7079,
570,
2656,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
1305,
26,
267,
1369,
26,
288,
446,
2870,
402,
14347,
662,
7079,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
3762,
26,
267,
1369,
26,
288,
446,
3820,
402,
3762,
402,
14347,
662,
7079,
14,
7719,
506,
3247,
465,
2600,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
4545,
26,
267,
1369,
26,
881,
446,
769,
402,
4545,
641,
1314,
370,
2457,
314,
2138,
2058,
881,
446,
754,
1471,
1336,
1006,
402,
314,
2013,
4545,
12,
1924,
402,
1314,
883,
506,
288,
282,
6391,
1572,
2870,
12,
282,
6303,
2870,
503,
376,
3531,
2287,
267,
1415,
26,
3055,
267,
849,
26,
488,
199,
11036,
63,
9970,
63,
7677,
26,
523,
446,
11488,
523,
446,
7062,
18,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2342,
1006,
3411,
325,
2319,
199,
13,
325,
2319,
63,
5047,
26,
523,
2274,
26,
754,
199,
199,
13,
325,
2319,
63,
5047,
26,
272,
536,
26,
3002,
774,
985,
1931,
199,
199,
13,
325,
2319,
63,
5047,
26,
272,
1305,
26,
7449,
13,
4321,
13591,
199,
199,
3,
8730,
316,
1006,
662,
7079,
4454,
543,
1947,
2812,
275,
283,
1662,
774,
985,
1931,
297,
315,
6303,
283,
5327,
13,
17,
65,
18,
66,
19,
67,
20,
68,
7,
436,
543,
6391,
1572,
283,
1226,
13,
20,
68,
19,
67,
18,
66,
17,
65,
7,
199,
13,
325,
2319,
63,
5047,
26,
272,
3762,
26,
267,
536,
26,
3002,
774,
985,
1931,
272,
4545,
26,
267,
446,
6303,
13,
17,
65,
18,
66,
19,
67,
20,
68,
267,
446,
12578,
13,
20,
68,
19,
67,
18,
66,
17,
65,
199,
2344,
199,
199,
9677,
275,
1449,
199,
8782,
63,
521,
26,
272,
1369,
26,
4913,
402,
7143,
1434,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
298,
7806,
13,
845,
13,
975,
24937,
26,
1216,
26,
1641,
13,
1717,
26,
383,
2,
199,
8782,
63,
1418,
26,
272,
1369,
26,
662,
7079,
7143,
1526,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
8559,
13,
31830,
1643,
69,
966,
13,
25,
65,
16,
69,
13,
20,
65,
18,
69,
13,
25874,
67,
13,
771,
2158,
1020,
1400,
1020,
2976,
199,
493,
63,
2253,
63,
344,
26,
272,
1369,
26,
2870,
402,
314,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
7449,
13,
9505,
199,
13602,
63,
7612,
63,
929,
26,
272,
1369,
26,
1174,
402,
314,
662,
7079,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
6425,
12,
2808,
12,
13794,
12,
5463,
199,
3956,
63,
1403,
26,
272,
1369,
26,
1166,
402,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
1275,
2319,
13,
9505,
14,
16186,
14,
527,
13,
19082,
13,
18,
14,
21442,
14,
957,
11254,
199,
3956,
63,
4684,
26,
272,
1369,
26,
769,
402,
10760,
4545,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
267,
359,
288,
469,
355,
298,
493,
63,
2253,
63,
344,
582,
298,
2319,
13,
65,
23,
350,
14162,
69,
401,
355,
298,
711,
63,
1562,
582,
298,
10419,
14,
2192,
14,
1196,
14,
12478,
401,
355,
298,
13602,
63,
7612,
63,
929,
582,
298,
4561,
401,
355,
298,
3956,
63,
1375,
63,
344,
582,
298,
2319,
2037,
13,
68,
1407,
1780,
17369,
401,
355,
298,
1200,
63,
3266,
63,
344,
582,
298,
30647,
13,
22,
69,
12399,
69,
1479,
401,
355,
298,
4597,
63,
344,
582,
298,
17702,
1342,
1349,
2259,
11444,
401,
355,
298,
4416,
63,
2634,
582,
359,
490,
298,
1226,
13,
65,
1216,
66,
1081,
67,
22,
2,
355,
2156,
355,
298,
5327,
63,
344,
582,
298,
5327,
13,
69,
13730,
67,
11382,
2,
288,
1660,
288,
2263,
267,
1622,
199,
354,
26,
272,
1369,
26,
536,
402,
314,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
3002,
13,
16186,
199,
1955,
63,
1618,
63,
3956,
63,
4684,
26,
272,
1369,
26,
314,
1329,
402,
4545,
27979,
272,
2138,
26,
3544,
272,
730,
26,
1109,
272,
2690,
26,
650,
199,
4597,
63,
344,
26,
272,
1369,
26,
10168,
2933,
2870,
402,
662,
7079,
5771,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
5787,
13312,
56,
199,
890,
63,
262,
63,
2394,
26,
272,
1369,
26,
1568,
402,
314,
570,
2656,
315,
2783,
465,
402,
282,
4913,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
267,
469,
288,
298,
3954,
582,
298,
7806,
13,
713,
13,
2025,
4944,
26,
1427,
26,
1427,
13,
1717,
26,
383,
401,
288,
298,
585,
582,
24557,
1299,
267,
789,
199,
20576,
63,
632,
26,
272,
1369,
26,
10238,
818,
402,
314,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
298,
10706,
14959,
4070,
2,
199,
2969,
26,
272,
1369,
26,
3762,
641,
314,
325,
2319,
1256,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
325,
2319,
63,
5047,
199,
3612,
63,
1802,
26,
2372,
2556,
3595,
14347,
662,
7079,
570,
10460,
199,
1802,
26,
272,
446,
5673,
21858,
14347,
662,
7079,
570,
10460,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
7538,
26,
359,
6055,
19,
1622,
199,
2502,
26,
272,
446,
298,
50,
89,
290,
5515,
4272,
269,
8593,
651,
796,
89,
4272,
269,
2924,
199,
1419,
26,
272,
536,
26,
267,
1369,
26,
288,
446,
9750,
425,
8767,
402,
14347,
662,
7079,
570,
2656,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
1305,
26,
267,
1369,
26,
288,
446,
2870,
402,
14347,
662,
7079,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
3762,
26,
267,
1369,
26,
288,
446,
3820,
402,
3762,
402,
14347,
662,
7079,
14,
7719,
506,
3247,
465,
2600,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
4545,
26,
267,
1369,
26,
881,
446,
769,
402,
4545,
641,
1314,
370,
2457,
314,
2138,
2058,
881,
446,
754,
1471,
1336,
1006,
402,
314,
2013,
4545,
12,
1924,
402,
1314,
883,
506,
288,
282,
6391,
1572,
2870,
12,
282,
6303,
2870,
503,
376,
3531,
2287,
267,
1415,
26,
3055,
267,
849,
26,
488,
199,
11036,
63,
9970,
63,
7677,
26,
523,
446,
11488,
523,
446,
7062,
18,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2342,
1006,
3411,
325,
2319,
199,
13,
325,
2319,
63,
5047,
26,
523,
2274,
26,
754,
199,
199,
13,
325,
2319,
63,
5047,
26,
272,
536,
26,
3002,
774,
985,
1931,
199,
199,
13,
325,
2319,
63,
5047,
26,
272,
1305,
26,
7449,
13,
4321,
13591,
199,
199,
3,
8730,
316,
1006,
662,
7079,
4454,
543,
1947,
2812,
275,
283,
1662,
774,
985,
1931,
297,
315,
6303,
283,
5327,
13,
17,
65,
18,
66,
19,
67,
20,
68,
7,
436,
543,
6391,
1572,
283,
1226,
13,
20,
68,
19,
67,
18,
66,
17,
65,
7,
199,
13,
325,
2319,
63,
5047,
26,
272,
3762,
26,
267,
536,
26,
3002,
774,
985,
1931,
272,
4545,
26,
267,
446,
6303,
13,
17,
65,
18,
66,
19,
67,
20,
68,
267,
446,
12578,
13,
20,
68,
19,
67,
18,
66,
17,
65,
199,
2344,
199,
199,
9677,
275,
1449,
199,
8782,
63,
521,
26,
272,
1369,
26,
4913,
402,
7143,
1434,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
298,
7806,
13,
845,
13,
975,
24937,
26,
1216,
26,
1641,
13,
1717,
26,
383,
2,
199,
8782,
63,
1418,
26,
272,
1369,
26,
662,
7079,
7143,
1526,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
8559,
13,
31830,
1643,
69,
966,
13,
25,
65,
16,
69,
13,
20,
65,
18,
69,
13,
25874,
67,
13,
771,
2158,
1020,
1400,
1020,
2976,
199,
493,
63,
2253,
63,
344,
26,
272,
1369,
26,
2870,
402,
314,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
7449,
13,
9505,
199,
13602,
63,
7612,
63,
929,
26,
272,
1369,
26,
1174,
402,
314,
662,
7079,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
6425,
12,
2808,
12,
13794,
12,
5463,
199,
3956,
63,
1403,
26,
272,
1369,
26,
1166,
402,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
1275,
2319,
13,
9505,
14,
16186,
14,
527,
13,
19082,
13,
18,
14,
21442,
14,
957,
11254,
199,
3956,
63,
4684,
26,
272,
1369,
26,
769,
402,
10760,
4545,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
267,
359,
288,
469,
355,
298,
493,
63,
2253,
63,
344,
582,
298,
2319,
13,
65,
23,
350,
14162,
69,
401,
355,
298,
711,
63,
1562,
582,
298,
10419,
14,
2192,
14,
1196,
14,
12478,
401,
355,
298,
13602,
63,
7612,
63,
929,
582,
298,
4561,
401,
355,
298,
3956,
63,
1375,
63,
344,
582,
298,
2319,
2037,
13,
68,
1407,
1780,
17369,
401,
355,
298,
1200,
63,
3266,
63,
344,
582,
298,
30647,
13,
22,
69,
12399,
69,
1479,
401,
355,
298,
4597,
63,
344,
582,
298,
17702,
1342,
1349,
2259,
11444,
401,
355,
298,
4416,
63,
2634,
582,
359,
490,
298,
1226,
13,
65,
1216,
66,
1081,
67,
22,
2,
355,
2156,
355,
298,
5327,
63,
344,
582,
298,
5327,
13,
69,
13730,
67,
11382,
2,
288,
1660,
288,
2263,
267,
1622,
199,
354,
26,
272,
1369,
26,
536,
402,
314,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
3002,
13,
16186,
199,
1955,
63,
1618,
63,
3956,
63,
4684,
26,
272,
1369,
26,
314,
1329,
402,
4545,
27979,
272,
2138,
26,
3544,
272,
730,
26,
1109,
272,
2690,
26,
650,
199,
4597,
63,
344,
26,
272,
1369,
26,
10168,
2933,
2870,
402,
662,
7079,
5771,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
5787,
13312,
56,
199,
890,
63,
262,
63,
2394,
26,
272,
1369,
26,
1568,
402,
314,
570,
2656,
315,
2783,
465,
402,
282,
4913,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
267,
469,
288,
298,
3954,
582,
298,
7806,
13,
713,
13,
2025,
4944,
26,
1427,
26,
1427,
13,
1717,
26,
383,
401,
288,
298,
585,
582,
24557,
1299,
267,
789,
199,
20576,
63,
632,
26,
272,
1369,
26,
10238,
818,
402,
314,
570,
2656,
272,
2138,
26,
3544,
272,
730,
26,
620,
272,
2690,
26,
298,
10706,
14959,
4070,
2,
199,
2969,
26,
272,
1369,
26,
3762,
641,
314,
325,
2319,
1256,
272,
2138,
26,
3544,
272,
730,
26,
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,
1,
1,
1,
1
] |
kytvi2p/Sigil
|
3rdparty/python/Lib/test/curses_tests.py
|
194
|
1242
|
#!/usr/bin/env python3
#
# $Id: ncurses.py 36559 2004-07-18 05:56:09Z tim_one $
#
# Interactive test suite for the curses module.
# This script displays various things and the user should verify whether
# they display correctly.
#
import curses
from curses import textpad
def test_textpad(stdscr, insert_mode=False):
ncols, nlines = 8, 3
uly, ulx = 3, 2
if insert_mode:
mode = 'insert mode'
else:
mode = 'overwrite mode'
stdscr.addstr(uly-3, ulx, "Use Ctrl-G to end editing (%s)." % mode)
stdscr.addstr(uly-2, ulx, "Be sure to try typing in the lower-right corner.")
win = curses.newwin(nlines, ncols, uly, ulx)
textpad.rectangle(stdscr, uly-1, ulx-1, uly + nlines, ulx + ncols)
stdscr.refresh()
box = textpad.Textbox(win, insert_mode)
contents = box.edit()
stdscr.addstr(uly+ncols+2, 0, "Text entered in the box\n")
stdscr.addstr(repr(contents))
stdscr.addstr('\n')
stdscr.addstr('Press any key')
stdscr.getch()
for i in range(3):
stdscr.move(uly+ncols+2 + i, 0)
stdscr.clrtoeol()
def main(stdscr):
stdscr.clear()
test_textpad(stdscr, False)
test_textpad(stdscr, True)
if __name__ == '__main__':
curses.wrapper(main)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
2672,
1304,
26,
302,
12026,
14,
647,
8780,
17257,
8353,
13,
1780,
13,
1085,
22528,
26,
1367,
26,
1643,
58,
221,
2906,
63,
368,
2672,
199,
3,
199,
3,
1010,
7502,
511,
5241,
367,
314,
15429,
859,
14,
199,
3,
961,
2884,
17561,
7750,
7645,
436,
314,
922,
1077,
4911,
3775,
199,
3,
2985,
2929,
6657,
14,
199,
3,
199,
199,
646,
15429,
199,
504,
15429,
492,
1318,
6226,
199,
199,
318,
511,
63,
505,
6226,
8,
1516,
11047,
12,
5518,
63,
632,
29,
797,
304,
272,
302,
4574,
12,
302,
1278,
275,
1695,
12,
650,
272,
12581,
89,
12,
12581,
88,
275,
650,
12,
499,
272,
340,
5518,
63,
632,
26,
267,
818,
275,
283,
3176,
818,
7,
272,
587,
26,
267,
818,
275,
283,
14658,
818,
7,
339,
2418,
11047,
14,
525,
495,
8,
21797,
13,
19,
12,
12581,
88,
12,
298,
6119,
445,
7245,
13,
39,
370,
1284,
20401,
4366,
83,
17617,
450,
818,
9,
272,
2418,
11047,
14,
525,
495,
8,
21797,
13,
18,
12,
12581,
88,
12,
298,
3655,
3238,
370,
862,
14090,
315,
314,
5117,
13,
1019,
17703,
2685,
272,
4747,
275,
15429,
14,
1222,
2676,
8,
78,
1278,
12,
302,
4574,
12,
12581,
89,
12,
12581,
88,
9,
272,
1318,
6226,
14,
19954,
8,
1516,
11047,
12,
12581,
89,
13,
17,
12,
12581,
88,
13,
17,
12,
12581,
89,
435,
302,
1278,
12,
12581,
88,
435,
302,
4574,
9,
272,
2418,
11047,
14,
6635,
342,
339,
5689,
275,
1318,
6226,
14,
1872,
1977,
8,
2676,
12,
5518,
63,
632,
9,
272,
4072,
275,
5689,
14,
3773,
342,
272,
2418,
11047,
14,
525,
495,
8,
21797,
11,
78,
4574,
11,
18,
12,
378,
12,
298,
1872,
19138,
315,
314,
5689,
60,
78,
531,
272,
2418,
11047,
14,
525,
495,
8,
2722,
8,
4407,
430,
272,
2418,
11047,
14,
525,
495,
2258,
78,
358,
272,
2418,
11047,
14,
525,
495,
360,
14414,
1263,
790,
358,
272,
2418,
11047,
14,
362,
335,
342,
339,
367,
284,
315,
1425,
8,
19,
304,
267,
2418,
11047,
14,
1185,
8,
21797,
11,
78,
4574,
11,
18,
435,
284,
12,
378,
9,
267,
2418,
11047,
14,
31553,
475,
20470,
342,
199,
199,
318,
2446,
8,
1516,
11047,
304,
272,
2418,
11047,
14,
3584,
342,
272,
511,
63,
505,
6226,
8,
1516,
11047,
12,
756,
9,
272,
511,
63,
505,
6226,
8,
1516,
11047,
12,
715,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
15429,
14,
5029,
8,
973,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
2672,
1304,
26,
302,
12026,
14,
647,
8780,
17257,
8353,
13,
1780,
13,
1085,
22528,
26,
1367,
26,
1643,
58,
221,
2906,
63,
368,
2672,
199,
3,
199,
3,
1010,
7502,
511,
5241,
367,
314,
15429,
859,
14,
199,
3,
961,
2884,
17561,
7750,
7645,
436,
314,
922,
1077,
4911,
3775,
199,
3,
2985,
2929,
6657,
14,
199,
3,
199,
199,
646,
15429,
199,
504,
15429,
492,
1318,
6226,
199,
199,
318,
511,
63,
505,
6226,
8,
1516,
11047,
12,
5518,
63,
632,
29,
797,
304,
272,
302,
4574,
12,
302,
1278,
275,
1695,
12,
650,
272,
12581,
89,
12,
12581,
88,
275,
650,
12,
499,
272,
340,
5518,
63,
632,
26,
267,
818,
275,
283,
3176,
818,
7,
272,
587,
26,
267,
818,
275,
283,
14658,
818,
7,
339,
2418,
11047,
14,
525,
495,
8,
21797,
13,
19,
12,
12581,
88,
12,
298,
6119,
445,
7245,
13,
39,
370,
1284,
20401,
4366,
83,
17617,
450,
818,
9,
272,
2418,
11047,
14,
525,
495,
8,
21797,
13,
18,
12,
12581,
88,
12,
298,
3655,
3238,
370,
862,
14090,
315,
314,
5117,
13,
1019,
17703,
2685,
272,
4747,
275,
15429,
14,
1222,
2676,
8,
78,
1278,
12,
302,
4574,
12,
12581,
89,
12,
12581,
88,
9,
272,
1318,
6226,
14,
19954,
8,
1516,
11047,
12,
12581,
89,
13,
17,
12,
12581,
88,
13,
17,
12,
12581,
89,
435,
302,
1278,
12,
12581,
88,
435,
302,
4574,
9,
272,
2418,
11047,
14,
6635,
342,
339,
5689,
275,
1318,
6226,
14,
1872,
1977,
8,
2676,
12,
5518,
63,
632,
9,
272,
4072,
275,
5689,
14,
3773,
342,
272,
2418,
11047,
14,
525,
495,
8,
21797,
11,
78,
4574,
11,
18,
12,
378,
12,
298,
1872,
19138,
315,
314,
5689,
60,
78,
531,
272,
2418,
11047,
14,
525,
495,
8,
2722,
8,
4407,
430,
272,
2418,
11047,
14,
525,
495,
2258,
78,
358,
272,
2418,
11047,
14,
525,
495,
360,
14414,
1263,
790,
358,
272,
2418,
11047,
14,
362,
335,
342,
339,
367,
284,
315,
1425,
8,
19,
304,
267,
2418,
11047,
14,
1185,
8,
21797,
11,
78,
4574,
11,
18,
435,
284,
12,
378,
9,
267,
2418,
11047,
14,
31553,
475,
20470,
342,
199,
199,
318,
2446,
8,
1516,
11047,
304,
272,
2418,
11047,
14,
3584,
342,
272,
511,
63,
505,
6226,
8,
1516,
11047,
12,
756,
9,
272,
511,
63,
505,
6226,
8,
1516,
11047,
12,
715,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
15429,
14,
5029,
8,
973,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tarikgwa/nfd
|
newfies/appointment/models/rules.py
|
5
|
3218
|
from django.db import models
from django.utils.translation import ugettext_lazy as _
from dateutil import rrule
freqs = (
("YEARLY", _("Yearly")),
("MONTHLY", _("Monthly")),
("WEEKLY", _("Weekly")),
("DAILY", _("Daily")),
("HOURLY", _("Hourly")),
("MINUTELY", _("Minutely")),
("SECONDLY", _("Secondly"))
)
class Rule(models.Model):
"""
This defines a rule by which an event will recur. This is defined by the
rrule in the dateutil documentation.
* name - the human friendly name of this kind of recursion.
* description - a short description describing this type of recursion.
* frequency - the base recurrence period
* param - extra params required to define this type of recursion. The params
should follow this format:
param = [rruleparam:value;]*
rruleparam = see list below
value = int[,int]*
The options are: (documentation for these can be found at
http://labix.org/python-dateutil#head-470fa22b2db72000d7abe698a5783a46b0731b57)
** count
** bysetpos
** bymonth
** bymonthday
** byyearday
** byweekno
** byweekday
** byhour
** byminute
** bysecond
** byeaster
"""
name = models.CharField(verbose_name=_("name"), max_length=32)
description = models.TextField(verbose_name=_("description"))
frequency = models.CharField(verbose_name=_("frequency"), choices=freqs, max_length=10)
params = models.TextField(verbose_name=_("params"), null=True, blank=True,
help_text=_("example : count:1;bysecond:3;"))
class Meta:
verbose_name = _('rule')
verbose_name_plural = _('rules')
app_label = "appointment"
def get_params(self):
"""
>>> rule = Rule(params = "count:1;bysecond:1;byminute:1,2,4,5")
>>> rule.get_params()
{'count': 1, 'byminute': [1, 2, 4, 5], 'bysecond': 1}
>>> rule = Rule(params = "count:1;bysecond:3;byweekday:TU,WE,TH")
>>> rule.get_params()
{'bysecond': 1, 'byweekday': (TU, WE, TH), 'count': 1}
"""
if self.params is None:
return {}
# remove "" from self.params
params = self.params.replace('"', '')
params = params.split(';')
param_dict = []
for param in params:
param = param.split(':')
if len(param) == 2:
temp_list = []
tuple_flag = False
for p in param[1].split(','):
if p.isdigit():
temp_list.append(int(p))
else:
tuple_flag = True
temp_list.append(eval('rrule.%s' % str(p)))
if tuple_flag:
temp_list = tuple(temp_list)
param = (str(param[0]), temp_list)
if len(param[1]) == 1:
param = (param[0], param[1][0])
param_dict.append(param)
return dict(param_dict)
def __unicode__(self):
"""Human readable string for Rule"""
return 'Rule %s params %s' % (self.name, self.params)
|
mpl-2.0
|
[
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
22208,
492,
519,
2200,
199,
199,
28557,
275,
334,
272,
1689,
19216,
6084,
401,
3824,
15731,
590,
8150,
272,
1689,
16413,
6084,
401,
3824,
14306,
590,
8150,
272,
1689,
24929,
6084,
401,
3824,
20995,
590,
8150,
272,
1689,
36,
6593,
57,
401,
3824,
36,
17550,
8150,
272,
1689,
2979,
18642,
401,
3824,
24246,
590,
8150,
272,
1689,
4896,
934,
2901,
57,
401,
3824,
4649,
938,
590,
8150,
272,
1689,
24236,
6084,
401,
3824,
11906,
590,
2237,
199,
9,
421,
199,
533,
11949,
8,
992,
14,
1685,
304,
339,
408,
272,
961,
7890,
282,
2332,
701,
1314,
376,
1566,
911,
5344,
14,
221,
961,
365,
3247,
701,
314,
272,
519,
2200,
315,
314,
22208,
3794,
14,
339,
627,
536,
446,
314,
11779,
21428,
536,
402,
642,
4928,
402,
16189,
14,
272,
627,
1369,
446,
282,
3974,
1369,
13660,
642,
730,
402,
16189,
14,
272,
627,
9857,
446,
314,
1300,
5344,
4646,
6247,
272,
627,
1215,
446,
2402,
1862,
1415,
370,
5627,
642,
730,
402,
16189,
14,
710,
1862,
489,
1077,
2035,
642,
1475,
26,
398,
1215,
275,
359,
82,
2200,
635,
26,
585,
27,
3672,
267,
519,
2200,
635,
275,
1937,
769,
5084,
267,
574,
275,
1109,
14675,
442,
3672,
2541,
710,
1511,
787,
26,
334,
9970,
367,
3520,
883,
506,
1911,
737,
489,
1455,
921,
5561,
1148,
14,
1308,
15,
1548,
13,
602,
1974,
3,
2993,
13,
23110,
667,
1081,
66,
18,
697,
2819,
1493,
68,
23,
7570,
20983,
65,
1641,
2658,
65,
2466,
66,
1780,
2192,
66,
1641,
9,
267,
1011,
2338,
267,
1011,
701,
409,
1712,
267,
1011,
701,
4482,
267,
1011,
701,
4482,
2977,
267,
1011,
701,
3403,
2977,
267,
1011,
701,
6419,
889,
267,
1011,
701,
12451,
267,
1011,
701,
5180,
267,
1011,
701,
10698,
267,
1011,
701,
4375,
267,
1011,
701,
69,
2311,
272,
408,
272,
536,
275,
1709,
14,
2183,
8,
3832,
63,
354,
9384,
354,
1288,
1390,
63,
1267,
29,
708,
9,
272,
1369,
275,
1709,
14,
6254,
8,
3832,
63,
354,
9384,
1802,
2237,
272,
9857,
275,
1709,
14,
2183,
8,
3832,
63,
354,
9384,
11132,
1288,
3415,
29,
28557,
12,
1390,
63,
1267,
29,
709,
9,
272,
1862,
275,
1709,
14,
6254,
8,
3832,
63,
354,
9384,
1162,
1288,
2973,
29,
549,
12,
4596,
29,
549,
12,
2892,
1720,
63,
505,
9384,
2694,
520,
2338,
26,
17,
27,
991,
4375,
26,
19,
27,
2237,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
4018,
2200,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
4423,
358,
267,
1145,
63,
1302,
275,
298,
439,
29594,
2,
339,
347,
664,
63,
1162,
8,
277,
304,
267,
408,
267,
1306,
2332,
275,
11949,
8,
1162,
275,
298,
835,
26,
17,
27,
991,
4375,
26,
17,
27,
991,
10698,
26,
17,
12,
18,
12,
20,
12,
21,
531,
267,
1306,
2332,
14,
362,
63,
1162,
342,
267,
791,
835,
356,
413,
12,
283,
991,
10698,
356,
359,
17,
12,
499,
12,
841,
12,
959,
467,
283,
991,
4375,
356,
413,
93,
398,
1306,
2332,
275,
11949,
8,
1162,
275,
298,
835,
26,
17,
27,
991,
4375,
26,
19,
27,
991,
12451,
26,
21364,
12,
5408,
12,
2080,
531,
267,
1306,
2332,
14,
362,
63,
1162,
342,
267,
791,
991,
4375,
356,
413,
12,
283,
991,
12451,
356,
334,
21364,
12,
644,
37,
12,
4221,
395,
283,
835,
356,
413,
93,
267,
408,
267,
340,
291,
14,
1162,
365,
488,
26,
288,
372,
1052,
398,
327,
2813,
3087,
687,
291,
14,
1162,
267,
1862,
275,
291,
14,
1162,
14,
1814,
20630,
4074,
398,
1862,
275,
1862,
14,
1294,
26468,
267,
1215,
63,
807,
275,
942,
267,
367,
1215,
315,
1862,
26,
288,
1215,
275,
1215,
14,
1294,
11633,
288,
340,
822,
8,
635,
9,
508,
499,
26,
2234,
2388,
63,
513,
275,
942,
355,
2008,
63,
4173,
275,
756,
355,
367,
299,
315,
1215,
59,
17,
1055,
1294,
25908,
490,
340,
299,
14,
13896,
837,
717,
2388,
63,
513,
14,
740,
8,
442,
8,
80,
430,
490,
587,
26,
717,
2008,
63,
4173,
275,
715,
717,
2388,
63,
513,
14,
740,
8,
2579,
360,
82,
2200,
4111,
83,
7,
450,
620,
8,
80,
1724,
2234,
340,
2008,
63,
4173,
26,
490,
2388,
63,
513,
275,
2008,
8,
808,
63,
513,
9,
2234,
1215,
275,
334,
495,
8,
635,
59,
16,
2522,
2388,
63,
513,
9,
355,
340,
822,
8,
635,
59,
17,
566,
508,
413,
26,
490,
1215,
275,
334,
635,
59,
16,
467,
1215,
59,
17,
1527,
16,
566,
355,
1215,
63,
807,
14,
740,
8,
635,
9,
267,
372,
1211,
8,
635,
63,
807,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
408,
31355,
12701,
1059,
367,
11949,
624,
267,
372,
283,
5065,
450,
83,
1862,
450,
83,
7,
450,
334,
277,
14,
354,
12,
291,
14,
1162,
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
] |
[
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
22208,
492,
519,
2200,
199,
199,
28557,
275,
334,
272,
1689,
19216,
6084,
401,
3824,
15731,
590,
8150,
272,
1689,
16413,
6084,
401,
3824,
14306,
590,
8150,
272,
1689,
24929,
6084,
401,
3824,
20995,
590,
8150,
272,
1689,
36,
6593,
57,
401,
3824,
36,
17550,
8150,
272,
1689,
2979,
18642,
401,
3824,
24246,
590,
8150,
272,
1689,
4896,
934,
2901,
57,
401,
3824,
4649,
938,
590,
8150,
272,
1689,
24236,
6084,
401,
3824,
11906,
590,
2237,
199,
9,
421,
199,
533,
11949,
8,
992,
14,
1685,
304,
339,
408,
272,
961,
7890,
282,
2332,
701,
1314,
376,
1566,
911,
5344,
14,
221,
961,
365,
3247,
701,
314,
272,
519,
2200,
315,
314,
22208,
3794,
14,
339,
627,
536,
446,
314,
11779,
21428,
536,
402,
642,
4928,
402,
16189,
14,
272,
627,
1369,
446,
282,
3974,
1369,
13660,
642,
730,
402,
16189,
14,
272,
627,
9857,
446,
314,
1300,
5344,
4646,
6247,
272,
627,
1215,
446,
2402,
1862,
1415,
370,
5627,
642,
730,
402,
16189,
14,
710,
1862,
489,
1077,
2035,
642,
1475,
26,
398,
1215,
275,
359,
82,
2200,
635,
26,
585,
27,
3672,
267,
519,
2200,
635,
275,
1937,
769,
5084,
267,
574,
275,
1109,
14675,
442,
3672,
2541,
710,
1511,
787,
26,
334,
9970,
367,
3520,
883,
506,
1911,
737,
489,
1455,
921,
5561,
1148,
14,
1308,
15,
1548,
13,
602,
1974,
3,
2993,
13,
23110,
667,
1081,
66,
18,
697,
2819,
1493,
68,
23,
7570,
20983,
65,
1641,
2658,
65,
2466,
66,
1780,
2192,
66,
1641,
9,
267,
1011,
2338,
267,
1011,
701,
409,
1712,
267,
1011,
701,
4482,
267,
1011,
701,
4482,
2977,
267,
1011,
701,
3403,
2977,
267,
1011,
701,
6419,
889,
267,
1011,
701,
12451,
267,
1011,
701,
5180,
267,
1011,
701,
10698,
267,
1011,
701,
4375,
267,
1011,
701,
69,
2311,
272,
408,
272,
536,
275,
1709,
14,
2183,
8,
3832,
63,
354,
9384,
354,
1288,
1390,
63,
1267,
29,
708,
9,
272,
1369,
275,
1709,
14,
6254,
8,
3832,
63,
354,
9384,
1802,
2237,
272,
9857,
275,
1709,
14,
2183,
8,
3832,
63,
354,
9384,
11132,
1288,
3415,
29,
28557,
12,
1390,
63,
1267,
29,
709,
9,
272,
1862,
275,
1709,
14,
6254,
8,
3832,
63,
354,
9384,
1162,
1288,
2973,
29,
549,
12,
4596,
29,
549,
12,
2892,
1720,
63,
505,
9384,
2694,
520,
2338,
26,
17,
27,
991,
4375,
26,
19,
27,
2237,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
4018,
2200,
358,
267,
3376,
63,
354,
63,
10019,
275,
4018,
4423,
358,
267,
1145,
63,
1302,
275,
298,
439,
29594,
2,
339,
347,
664,
63,
1162,
8,
277,
304,
267,
408,
267,
1306,
2332,
275,
11949,
8,
1162,
275,
298,
835,
26,
17,
27,
991,
4375,
26,
17,
27,
991,
10698,
26,
17,
12,
18,
12,
20,
12,
21,
531,
267,
1306,
2332,
14,
362,
63,
1162,
342,
267,
791,
835,
356,
413,
12,
283,
991,
10698,
356,
359,
17,
12,
499,
12,
841,
12,
959,
467,
283,
991,
4375,
356,
413,
93,
398,
1306,
2332,
275,
11949,
8,
1162,
275,
298,
835,
26,
17,
27,
991,
4375,
26,
19,
27,
991,
12451,
26,
21364,
12,
5408,
12,
2080,
531,
267,
1306,
2332,
14,
362,
63,
1162,
342,
267,
791,
991,
4375,
356,
413,
12,
283,
991,
12451,
356,
334,
21364,
12,
644,
37,
12,
4221,
395,
283,
835,
356,
413,
93,
267,
408,
267,
340,
291,
14,
1162,
365,
488,
26,
288,
372,
1052,
398,
327,
2813,
3087,
687,
291,
14,
1162,
267,
1862,
275,
291,
14,
1162,
14,
1814,
20630,
4074,
398,
1862,
275,
1862,
14,
1294,
26468,
267,
1215,
63,
807,
275,
942,
267,
367,
1215,
315,
1862,
26,
288,
1215,
275,
1215,
14,
1294,
11633,
288,
340,
822,
8,
635,
9,
508,
499,
26,
2234,
2388,
63,
513,
275,
942,
355,
2008,
63,
4173,
275,
756,
355,
367,
299,
315,
1215,
59,
17,
1055,
1294,
25908,
490,
340,
299,
14,
13896,
837,
717,
2388,
63,
513,
14,
740,
8,
442,
8,
80,
430,
490,
587,
26,
717,
2008,
63,
4173,
275,
715,
717,
2388,
63,
513,
14,
740,
8,
2579,
360,
82,
2200,
4111,
83,
7,
450,
620,
8,
80,
1724,
2234,
340,
2008,
63,
4173,
26,
490,
2388,
63,
513,
275,
2008,
8,
808,
63,
513,
9,
2234,
1215,
275,
334,
495,
8,
635,
59,
16,
2522,
2388,
63,
513,
9,
355,
340,
822,
8,
635,
59,
17,
566,
508,
413,
26,
490,
1215,
275,
334,
635,
59,
16,
467,
1215,
59,
17,
1527,
16,
566,
355,
1215,
63,
807,
14,
740,
8,
635,
9,
267,
372,
1211,
8,
635,
63,
807,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
408,
31355,
12701,
1059,
367,
11949,
624,
267,
372,
283,
5065,
450,
83,
1862,
450,
83,
7,
450,
334,
277,
14,
354,
12,
291,
14,
1162,
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,
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,
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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
] |
Nispand1492/appengine-try-python-flask
|
lib/cloudstorage/api_utils.py
|
48
|
11314
|
# Copyright 2013 Google 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.
"""Util functions and classes for cloudstorage_api."""
__all__ = ['set_default_retry_params',
'RetryParams',
]
import copy
import httplib
import logging
import math
import os
import threading
import time
import urllib
try:
from google.appengine.api import app_identity
from google.appengine.api import urlfetch
from google.appengine.datastore import datastore_rpc
from google.appengine.ext import ndb
from google.appengine.ext.ndb import eventloop
from google.appengine.ext.ndb import tasklets
from google.appengine.ext.ndb import utils
from google.appengine import runtime
from google.appengine.runtime import apiproxy_errors
except ImportError:
from google.appengine.api import app_identity
from google.appengine.api import urlfetch
from google.appengine.datastore import datastore_rpc
from google.appengine import runtime
from google.appengine.runtime import apiproxy_errors
from google.appengine.ext import ndb
from google.appengine.ext.ndb import eventloop
from google.appengine.ext.ndb import tasklets
from google.appengine.ext.ndb import utils
_RETRIABLE_EXCEPTIONS = (urlfetch.DownloadError,
apiproxy_errors.Error,
app_identity.InternalError,
app_identity.BackendDeadlineExceeded)
_thread_local_settings = threading.local()
_thread_local_settings.default_retry_params = None
def set_default_retry_params(retry_params):
"""Set a default RetryParams for current thread current request."""
_thread_local_settings.default_retry_params = copy.copy(retry_params)
def _get_default_retry_params():
"""Get default RetryParams for current request and current thread.
Returns:
A new instance of the default RetryParams.
"""
default = getattr(_thread_local_settings, 'default_retry_params', None)
if default is None or not default.belong_to_current_request():
return RetryParams()
else:
return copy.copy(default)
def _quote_filename(filename):
"""Quotes filename to use as a valid URI path.
Args:
filename: user provided filename. /bucket/filename.
Returns:
The filename properly quoted to use as URI's path component.
"""
return urllib.quote(filename)
def _unquote_filename(filename):
"""Unquotes a valid URI path back to its filename.
This is the opposite of _quote_filename.
Args:
filename: a quoted filename. /bucket/some%20filename.
Returns:
The filename unquoted.
"""
return urllib.unquote(filename)
def _should_retry(resp):
"""Given a urlfetch response, decide whether to retry that request."""
return (resp.status_code == httplib.REQUEST_TIMEOUT or
(resp.status_code >= 500 and
resp.status_code < 600))
class _RetryWrapper(object):
"""A wrapper that wraps retry logic around any tasklet."""
def __init__(self,
retry_params,
retriable_exceptions=_RETRIABLE_EXCEPTIONS,
should_retry=lambda r: False):
"""Init.
Args:
retry_params: an RetryParams instance.
retriable_exceptions: a list of exception classes that are retriable.
should_retry: a function that takes a result from the tasklet and returns
a boolean. True if the result should be retried.
"""
self.retry_params = retry_params
self.retriable_exceptions = retriable_exceptions
self.should_retry = should_retry
@ndb.tasklet
def run(self, tasklet, **kwds):
"""Run a tasklet with retry.
The retry should be transparent to the caller: if no results
are successful, the exception or result from the last retry is returned
to the caller.
Args:
tasklet: the tasklet to run.
**kwds: keywords arguments to run the tasklet.
Raises:
The exception from running the tasklet.
Returns:
The result from running the tasklet.
"""
start_time = time.time()
n = 1
while True:
e = None
result = None
got_result = False
try:
result = yield tasklet(**kwds)
got_result = True
if not self.should_retry(result):
raise ndb.Return(result)
except runtime.DeadlineExceededError:
logging.debug(
'Tasklet has exceeded request deadline after %s seconds total',
time.time() - start_time)
raise
except self.retriable_exceptions, e:
pass
if n == 1:
logging.debug('Tasklet is %r', tasklet)
delay = self.retry_params.delay(n, start_time)
if delay <= 0:
logging.debug(
'Tasklet failed after %s attempts and %s seconds in total',
n, time.time() - start_time)
if got_result:
raise ndb.Return(result)
elif e is not None:
raise e
else:
assert False, 'Should never reach here.'
if got_result:
logging.debug(
'Got result %r from tasklet.', result)
else:
logging.debug(
'Got exception "%r" from tasklet.', e)
logging.debug('Retry in %s seconds.', delay)
n += 1
yield tasklets.sleep(delay)
class RetryParams(object):
"""Retry configuration parameters."""
_DEFAULT_USER_AGENT = 'App Engine Python GCS Client'
@datastore_rpc._positional(1)
def __init__(self,
backoff_factor=2.0,
initial_delay=0.1,
max_delay=10.0,
min_retries=3,
max_retries=6,
max_retry_period=30.0,
urlfetch_timeout=None,
save_access_token=False,
_user_agent=None):
"""Init.
This object is unique per request per thread.
Library will retry according to this setting when App Engine Server
can't call urlfetch, urlfetch timed out, or urlfetch got a 408 or
500-600 response.
Args:
backoff_factor: exponential backoff multiplier.
initial_delay: seconds to delay for the first retry.
max_delay: max seconds to delay for every retry.
min_retries: min number of times to retry. This value is automatically
capped by max_retries.
max_retries: max number of times to retry. Set this to 0 for no retry.
max_retry_period: max total seconds spent on retry. Retry stops when
this period passed AND min_retries has been attempted.
urlfetch_timeout: timeout for urlfetch in seconds. Could be None,
in which case the value will be chosen by urlfetch module.
save_access_token: persist access token to datastore to avoid
excessive usage of GetAccessToken API. Usually the token is cached
in process and in memcache. In some cases, memcache isn't very
reliable.
_user_agent: The user agent string that you want to use in your requests.
"""
self.backoff_factor = self._check('backoff_factor', backoff_factor)
self.initial_delay = self._check('initial_delay', initial_delay)
self.max_delay = self._check('max_delay', max_delay)
self.max_retry_period = self._check('max_retry_period', max_retry_period)
self.max_retries = self._check('max_retries', max_retries, True, int)
self.min_retries = self._check('min_retries', min_retries, True, int)
if self.min_retries > self.max_retries:
self.min_retries = self.max_retries
self.urlfetch_timeout = None
if urlfetch_timeout is not None:
self.urlfetch_timeout = self._check('urlfetch_timeout', urlfetch_timeout)
self.save_access_token = self._check('save_access_token', save_access_token,
True, bool)
self._user_agent = _user_agent or self._DEFAULT_USER_AGENT
self._request_id = os.getenv('REQUEST_LOG_ID')
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
return not self.__eq__(other)
@classmethod
def _check(cls, name, val, can_be_zero=False, val_type=float):
"""Check init arguments.
Args:
name: name of the argument. For logging purpose.
val: value. Value has to be non negative number.
can_be_zero: whether value can be zero.
val_type: Python type of the value.
Returns:
The value.
Raises:
ValueError: when invalid value is passed in.
TypeError: when invalid value type is passed in.
"""
valid_types = [val_type]
if val_type is float:
valid_types.append(int)
if type(val) not in valid_types:
raise TypeError(
'Expect type %s for parameter %s' % (val_type.__name__, name))
if val < 0:
raise ValueError(
'Value for parameter %s has to be greater than 0' % name)
if not can_be_zero and val == 0:
raise ValueError(
'Value for parameter %s can not be 0' % name)
return val
def belong_to_current_request(self):
return os.getenv('REQUEST_LOG_ID') == self._request_id
def delay(self, n, start_time):
"""Calculate delay before the next retry.
Args:
n: the number of current attempt. The first attempt should be 1.
start_time: the time when retry started in unix time.
Returns:
Number of seconds to wait before next retry. -1 if retry should give up.
"""
if (n > self.max_retries or
(n > self.min_retries and
time.time() - start_time > self.max_retry_period)):
return -1
return min(
math.pow(self.backoff_factor, n-1) * self.initial_delay,
self.max_delay)
def _run_until_rpc():
"""Eagerly evaluate tasklets until it is blocking on some RPC.
Usually ndb eventloop el isn't run until some code calls future.get_result().
When an async tasklet is called, the tasklet wrapper evaluates the tasklet
code into a generator, enqueues a callback _help_tasklet_along onto
the el.current queue, and returns a future.
_help_tasklet_along, when called by the el, will
get one yielded value from the generator. If the value if another future,
set up a callback _on_future_complete to invoke _help_tasklet_along
when the dependent future fulfills. If the value if a RPC, set up a
callback _on_rpc_complete to invoke _help_tasklet_along when the RPC fulfills.
Thus _help_tasklet_along drills down
the chain of futures until some future is blocked by RPC. El runs
all callbacks and constantly check pending RPC status.
"""
el = eventloop.get_event_loop()
while el.current:
el.run0()
def _eager_tasklet(tasklet):
"""Decorator to turn tasklet to run eagerly."""
@utils.wrapping(tasklet)
def eager_wrapper(*args, **kwds):
fut = tasklet(*args, **kwds)
_run_until_rpc()
return fut
return eager_wrapper
|
apache-2.0
|
[
3,
1898,
6171,
4475,
3277,
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
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,
844,
14,
199,
199,
624,
9562,
3423,
436,
3992,
367,
8002,
3494,
63,
1246,
1041,
4388,
199,
363,
452,
363,
275,
788,
409,
63,
885,
63,
7154,
63,
1162,
297,
1779,
283,
12989,
6007,
297,
881,
1622,
199,
199,
646,
1331,
199,
646,
8809,
199,
646,
2050,
199,
646,
3473,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
4011,
421,
199,
893,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
1246,
492,
7629,
29429,
523,
687,
6233,
14,
15358,
14,
11450,
492,
12007,
63,
4354,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
1566,
3813,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
2120,
16537,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
3778,
523,
687,
6233,
14,
15358,
492,
8836,
523,
687,
6233,
14,
15358,
14,
7726,
492,
2986,
3280,
63,
2550,
199,
2590,
3545,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
1246,
492,
7629,
29429,
523,
687,
6233,
14,
15358,
14,
11450,
492,
12007,
63,
4354,
523,
687,
6233,
14,
15358,
492,
8836,
523,
687,
6233,
14,
15358,
14,
7726,
492,
2986,
3280,
63,
2550,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
1566,
3813,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
2120,
16537,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
3778,
421,
199,
63,
7341,
6129,
2617,
63,
25054,
275,
334,
300,
29429,
14,
11950,
547,
12,
586,
2986,
3280,
63,
2550,
14,
547,
12,
586,
1145,
63,
5582,
14,
8405,
547,
12,
586,
1145,
63,
5582,
14,
8447,
22147,
604,
24748,
9,
199,
199,
63,
2671,
63,
1832,
63,
1751,
275,
5796,
14,
1832,
342,
199,
63,
2671,
63,
1832,
63,
1751,
14,
885,
63,
7154,
63,
1162,
275,
488,
421,
199,
318,
663,
63,
885,
63,
7154,
63,
1162,
8,
7154,
63,
1162,
304,
523,
408,
1084,
282,
849,
20506,
6007,
367,
1453,
2462,
1453,
1056,
1041,
523,
485,
2671,
63,
1832,
63,
1751,
14,
885,
63,
7154,
63,
1162,
275,
1331,
14,
1574,
8,
7154,
63,
1162,
9,
421,
199,
318,
485,
362,
63,
885,
63,
7154,
63,
1162,
837,
523,
408,
1002,
849,
20506,
6007,
367,
1453,
1056,
436,
1453,
2462,
14,
819,
1803,
26,
272,
437,
892,
1256,
402,
314,
849,
20506,
6007,
14,
523,
408,
523,
849,
275,
2519,
1547,
2671,
63,
1832,
63,
1751,
12,
283,
885,
63,
7154,
63,
1162,
297,
488,
9,
523,
340,
849,
365,
488,
503,
440,
849,
14,
20621,
951,
63,
475,
63,
1818,
63,
1069,
837,
272,
372,
20506,
6007,
342,
523,
587,
26,
272,
372,
1331,
14,
1574,
8,
885,
9,
421,
199,
318,
485,
3513,
63,
1501,
8,
1501,
304,
523,
408,
2371,
6510,
1788,
370,
675,
465,
282,
1686,
9022,
931,
14,
819,
3033,
26,
272,
1788,
26,
922,
2741,
1788,
14,
1182,
4623,
15,
1501,
14,
819,
1803,
26,
272,
710,
1788,
7684,
10999,
370,
675,
465,
9022,
1159,
931,
3931,
14,
523,
408,
523,
372,
4011,
14,
3513,
8,
1501,
9,
421,
199,
318,
485,
12240,
63,
1501,
8,
1501,
304,
523,
408,
1358,
14005,
282,
1686,
9022,
931,
1771,
370,
2399,
1788,
14,
819,
961,
365,
314,
26912,
402,
485,
3513,
63,
1501,
14,
819,
3033,
26,
272,
1788,
26,
282,
10999,
1788,
14,
1182,
4623,
15,
3972,
5,
1165,
1501,
14,
819,
1803,
26,
272,
710,
1788,
31791,
14,
523,
408,
523,
372,
4011,
14,
12240,
8,
1501,
9,
421,
199,
318,
485,
5626,
63,
7154,
8,
4518,
304,
523,
408,
13735,
282,
7629,
29429,
1177,
12,
19822,
3775,
370,
7269,
626,
1056,
1041,
523,
372,
334,
4518,
14,
1205,
63,
600,
508,
8809,
14,
6780,
63,
8899,
503,
881,
334,
4518,
14,
1205,
63,
600,
2356,
6891,
436,
1779,
3085,
14,
1205,
63,
600,
665,
11624,
430,
421,
199,
533,
485,
12989,
4590,
8,
785,
304,
523,
408,
33,
4975,
626,
14018,
7269,
9661,
6818,
1263,
2120,
2723,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
7269,
63,
1162,
12,
2049,
4444,
461,
63,
3924,
3699,
7341,
6129,
2617,
63,
25054,
12,
2049,
1077,
63,
7154,
29,
2734,
519,
26,
756,
304,
272,
408,
9346,
14,
339,
3033,
26,
489,
7269,
63,
1162,
26,
376,
20506,
6007,
1256,
14,
489,
4444,
461,
63,
3924,
26,
282,
769,
402,
1919,
3992,
626,
787,
4444,
461,
14,
489,
1077,
63,
7154,
26,
282,
805,
626,
6181,
282,
754,
687,
314,
2120,
2723,
436,
2529,
267,
282,
5046,
14,
715,
340,
314,
754,
1077,
506,
4444,
379,
14,
272,
408,
272,
291,
14,
7154,
63,
1162,
275,
7269,
63,
1162,
272,
291,
14,
11235,
461,
63,
3924,
275,
4444,
461,
63,
3924,
272,
291,
14,
5626,
63,
7154,
275,
1077,
63,
7154,
819,
768,
78,
697,
14,
1765,
2723,
523,
347,
1255,
8,
277,
12,
2120,
2723,
12,
1011,
10340,
304,
272,
408,
2540,
282,
2120,
2723,
543,
7269,
14,
339,
710,
7269,
1077,
506,
17265,
370,
314,
8025,
26,
340,
949,
2058,
272,
787,
9512,
12,
314,
1919,
503,
754,
687,
314,
2061,
7269,
365,
2138,
272,
370,
314,
8025
] |
[
1898,
6171,
4475,
3277,
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
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,
844,
14,
199,
199,
624,
9562,
3423,
436,
3992,
367,
8002,
3494,
63,
1246,
1041,
4388,
199,
363,
452,
363,
275,
788,
409,
63,
885,
63,
7154,
63,
1162,
297,
1779,
283,
12989,
6007,
297,
881,
1622,
199,
199,
646,
1331,
199,
646,
8809,
199,
646,
2050,
199,
646,
3473,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
4011,
421,
199,
893,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
1246,
492,
7629,
29429,
523,
687,
6233,
14,
15358,
14,
11450,
492,
12007,
63,
4354,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
1566,
3813,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
2120,
16537,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
3778,
523,
687,
6233,
14,
15358,
492,
8836,
523,
687,
6233,
14,
15358,
14,
7726,
492,
2986,
3280,
63,
2550,
199,
2590,
3545,
26,
523,
687,
6233,
14,
15358,
14,
1246,
492,
1145,
63,
5582,
523,
687,
6233,
14,
15358,
14,
1246,
492,
7629,
29429,
523,
687,
6233,
14,
15358,
14,
11450,
492,
12007,
63,
4354,
523,
687,
6233,
14,
15358,
492,
8836,
523,
687,
6233,
14,
15358,
14,
7726,
492,
2986,
3280,
63,
2550,
523,
687,
6233,
14,
15358,
14,
832,
492,
23788,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
1566,
3813,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
2120,
16537,
523,
687,
6233,
14,
15358,
14,
832,
14,
78,
697,
492,
3778,
421,
199,
63,
7341,
6129,
2617,
63,
25054,
275,
334,
300,
29429,
14,
11950,
547,
12,
586,
2986,
3280,
63,
2550,
14,
547,
12,
586,
1145,
63,
5582,
14,
8405,
547,
12,
586,
1145,
63,
5582,
14,
8447,
22147,
604,
24748,
9,
199,
199,
63,
2671,
63,
1832,
63,
1751,
275,
5796,
14,
1832,
342,
199,
63,
2671,
63,
1832,
63,
1751,
14,
885,
63,
7154,
63,
1162,
275,
488,
421,
199,
318,
663,
63,
885,
63,
7154,
63,
1162,
8,
7154,
63,
1162,
304,
523,
408,
1084,
282,
849,
20506,
6007,
367,
1453,
2462,
1453,
1056,
1041,
523,
485,
2671,
63,
1832,
63,
1751,
14,
885,
63,
7154,
63,
1162,
275,
1331,
14,
1574,
8,
7154,
63,
1162,
9,
421,
199,
318,
485,
362,
63,
885,
63,
7154,
63,
1162,
837,
523,
408,
1002,
849,
20506,
6007,
367,
1453,
1056,
436,
1453,
2462,
14,
819,
1803,
26,
272,
437,
892,
1256,
402,
314,
849,
20506,
6007,
14,
523,
408,
523,
849,
275,
2519,
1547,
2671,
63,
1832,
63,
1751,
12,
283,
885,
63,
7154,
63,
1162,
297,
488,
9,
523,
340,
849,
365,
488,
503,
440,
849,
14,
20621,
951,
63,
475,
63,
1818,
63,
1069,
837,
272,
372,
20506,
6007,
342,
523,
587,
26,
272,
372,
1331,
14,
1574,
8,
885,
9,
421,
199,
318,
485,
3513,
63,
1501,
8,
1501,
304,
523,
408,
2371,
6510,
1788,
370,
675,
465,
282,
1686,
9022,
931,
14,
819,
3033,
26,
272,
1788,
26,
922,
2741,
1788,
14,
1182,
4623,
15,
1501,
14,
819,
1803,
26,
272,
710,
1788,
7684,
10999,
370,
675,
465,
9022,
1159,
931,
3931,
14,
523,
408,
523,
372,
4011,
14,
3513,
8,
1501,
9,
421,
199,
318,
485,
12240,
63,
1501,
8,
1501,
304,
523,
408,
1358,
14005,
282,
1686,
9022,
931,
1771,
370,
2399,
1788,
14,
819,
961,
365,
314,
26912,
402,
485,
3513,
63,
1501,
14,
819,
3033,
26,
272,
1788,
26,
282,
10999,
1788,
14,
1182,
4623,
15,
3972,
5,
1165,
1501,
14,
819,
1803,
26,
272,
710,
1788,
31791,
14,
523,
408,
523,
372,
4011,
14,
12240,
8,
1501,
9,
421,
199,
318,
485,
5626,
63,
7154,
8,
4518,
304,
523,
408,
13735,
282,
7629,
29429,
1177,
12,
19822,
3775,
370,
7269,
626,
1056,
1041,
523,
372,
334,
4518,
14,
1205,
63,
600,
508,
8809,
14,
6780,
63,
8899,
503,
881,
334,
4518,
14,
1205,
63,
600,
2356,
6891,
436,
1779,
3085,
14,
1205,
63,
600,
665,
11624,
430,
421,
199,
533,
485,
12989,
4590,
8,
785,
304,
523,
408,
33,
4975,
626,
14018,
7269,
9661,
6818,
1263,
2120,
2723,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
7269,
63,
1162,
12,
2049,
4444,
461,
63,
3924,
3699,
7341,
6129,
2617,
63,
25054,
12,
2049,
1077,
63,
7154,
29,
2734,
519,
26,
756,
304,
272,
408,
9346,
14,
339,
3033,
26,
489,
7269,
63,
1162,
26,
376,
20506,
6007,
1256,
14,
489,
4444,
461,
63,
3924,
26,
282,
769,
402,
1919,
3992,
626,
787,
4444,
461,
14,
489,
1077,
63,
7154,
26,
282,
805,
626,
6181,
282,
754,
687,
314,
2120,
2723,
436,
2529,
267,
282,
5046,
14,
715,
340,
314,
754,
1077,
506,
4444,
379,
14,
272,
408,
272,
291,
14,
7154,
63,
1162,
275,
7269,
63,
1162,
272,
291,
14,
11235,
461,
63,
3924,
275,
4444,
461,
63,
3924,
272,
291,
14,
5626,
63,
7154,
275,
1077,
63,
7154,
819,
768,
78,
697,
14,
1765,
2723,
523,
347,
1255,
8,
277,
12,
2120,
2723,
12,
1011,
10340,
304,
272,
408,
2540,
282,
2120,
2723,
543,
7269,
14,
339,
710,
7269,
1077,
506,
17265,
370,
314,
8025,
26,
340,
949,
2058,
272,
787,
9512,
12,
314,
1919,
503,
754,
687,
314,
2061,
7269,
365,
2138,
272,
370,
314,
8025,
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
] |
michigraber/scikit-learn
|
examples/calibration/plot_calibration_multiclass.py
|
272
|
6972
|
"""
==================================================
Probability Calibration for 3-class classification
==================================================
This example illustrates how sigmoid calibration changes predicted
probabilities for a 3-class classification problem. Illustrated is the
standard 2-simplex, where the three corners correspond to the three classes.
Arrows point from the probability vectors predicted by an uncalibrated
classifier to the probability vectors predicted by the same classifier after
sigmoid calibration on a hold-out validation set. Colors indicate the true
class of an instance (red: class 1, green: class 2, blue: class 3).
The base classifier is a random forest classifier with 25 base estimators
(trees). If this classifier is trained on all 800 training datapoints, it is
overly confident in its predictions and thus incurs a large log-loss.
Calibrating an identical classifier, which was trained on 600 datapoints, with
method='sigmoid' on the remaining 200 datapoints reduces the confidence of the
predictions, i.e., moves the probability vectors from the edges of the simplex
towards the center. This calibration results in a lower log-loss. Note that an
alternative would have been to increase the number of base estimators which
would have resulted in a similar decrease in log-loss.
"""
print(__doc__)
# Author: Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>
# License: BSD Style.
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import make_blobs
from sklearn.ensemble import RandomForestClassifier
from sklearn.calibration import CalibratedClassifierCV
from sklearn.metrics import log_loss
np.random.seed(0)
# Generate data
X, y = make_blobs(n_samples=1000, n_features=2, random_state=42,
cluster_std=5.0)
X_train, y_train = X[:600], y[:600]
X_valid, y_valid = X[600:800], y[600:800]
X_train_valid, y_train_valid = X[:800], y[:800]
X_test, y_test = X[800:], y[800:]
# Train uncalibrated random forest classifier on whole train and validation
# data and evaluate on test data
clf = RandomForestClassifier(n_estimators=25)
clf.fit(X_train_valid, y_train_valid)
clf_probs = clf.predict_proba(X_test)
score = log_loss(y_test, clf_probs)
# Train random forest classifier, calibrate on validation data and evaluate
# on test data
clf = RandomForestClassifier(n_estimators=25)
clf.fit(X_train, y_train)
clf_probs = clf.predict_proba(X_test)
sig_clf = CalibratedClassifierCV(clf, method="sigmoid", cv="prefit")
sig_clf.fit(X_valid, y_valid)
sig_clf_probs = sig_clf.predict_proba(X_test)
sig_score = log_loss(y_test, sig_clf_probs)
# Plot changes in predicted probabilities via arrows
plt.figure(0)
colors = ["r", "g", "b"]
for i in range(clf_probs.shape[0]):
plt.arrow(clf_probs[i, 0], clf_probs[i, 1],
sig_clf_probs[i, 0] - clf_probs[i, 0],
sig_clf_probs[i, 1] - clf_probs[i, 1],
color=colors[y_test[i]], head_width=1e-2)
# Plot perfect predictions
plt.plot([1.0], [0.0], 'ro', ms=20, label="Class 1")
plt.plot([0.0], [1.0], 'go', ms=20, label="Class 2")
plt.plot([0.0], [0.0], 'bo', ms=20, label="Class 3")
# Plot boundaries of unit simplex
plt.plot([0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], 'k', label="Simplex")
# Annotate points on the simplex
plt.annotate(r'($\frac{1}{3}$, $\frac{1}{3}$, $\frac{1}{3}$)',
xy=(1.0/3, 1.0/3), xytext=(1.0/3, .23), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
plt.plot([1.0/3], [1.0/3], 'ko', ms=5)
plt.annotate(r'($\frac{1}{2}$, $0$, $\frac{1}{2}$)',
xy=(.5, .0), xytext=(.5, .1), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
plt.annotate(r'($0$, $\frac{1}{2}$, $\frac{1}{2}$)',
xy=(.0, .5), xytext=(.1, .5), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
plt.annotate(r'($\frac{1}{2}$, $\frac{1}{2}$, $0$)',
xy=(.5, .5), xytext=(.6, .6), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
plt.annotate(r'($0$, $0$, $1$)',
xy=(0, 0), xytext=(.1, .1), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
plt.annotate(r'($1$, $0$, $0$)',
xy=(1, 0), xytext=(1, .1), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
plt.annotate(r'($0$, $1$, $0$)',
xy=(0, 1), xytext=(.1, 1), xycoords='data',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='center', verticalalignment='center')
# Add grid
plt.grid("off")
for x in [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:
plt.plot([0, x], [x, 0], 'k', alpha=0.2)
plt.plot([0, 0 + (1-x)/2], [x, x + (1-x)/2], 'k', alpha=0.2)
plt.plot([x, x + (1-x)/2], [0, 0 + (1-x)/2], 'k', alpha=0.2)
plt.title("Change of predicted probabilities after sigmoid calibration")
plt.xlabel("Probability class 1")
plt.ylabel("Probability class 2")
plt.xlim(-0.05, 1.05)
plt.ylim(-0.05, 1.05)
plt.legend(loc="best")
print("Log-loss of")
print(" * uncalibrated classifier trained on 800 datapoints: %.3f "
% score)
print(" * classifier trained on 600 datapoints and calibrated on "
"200 datapoint: %.3f" % sig_score)
# Illustrate calibrator
plt.figure(1)
# generate grid over 2-simplex
p1d = np.linspace(0, 1, 20)
p0, p1 = np.meshgrid(p1d, p1d)
p2 = 1 - p0 - p1
p = np.c_[p0.ravel(), p1.ravel(), p2.ravel()]
p = p[p[:, 2] >= 0]
calibrated_classifier = sig_clf.calibrated_classifiers_[0]
prediction = np.vstack([calibrator.predict(this_p)
for calibrator, this_p in
zip(calibrated_classifier.calibrators_, p.T)]).T
prediction /= prediction.sum(axis=1)[:, None]
# Ploit modifications of calibrator
for i in range(prediction.shape[0]):
plt.arrow(p[i, 0], p[i, 1],
prediction[i, 0] - p[i, 0], prediction[i, 1] - p[i, 1],
head_width=1e-2, color=colors[np.argmax(p[i])])
# Plot boundaries of unit simplex
plt.plot([0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], 'k', label="Simplex")
plt.grid("off")
for x in [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]:
plt.plot([0, x], [x, 0], 'k', alpha=0.2)
plt.plot([0, 0 + (1-x)/2], [x, x + (1-x)/2], 'k', alpha=0.2)
plt.plot([x, x + (1-x)/2], [0, 0 + (1-x)/2], 'k', alpha=0.2)
plt.title("Illustration of sigmoid calibrator")
plt.xlabel("Probability class 1")
plt.ylabel("Probability class 2")
plt.xlim(-0.05, 1.05)
plt.ylim(-0.05, 1.05)
plt.show()
|
bsd-3-clause
|
[
624,
199,
12813,
389,
199,
20122,
3616,
8256,
1892,
1754,
367,
650,
13,
533,
12505,
199,
12813,
389,
199,
199,
2765,
2893,
22907,
11409,
2335,
4212,
28886,
25365,
4493,
14746,
199,
27583,
367,
282,
650,
13,
533,
12505,
5160,
14,
473,
914,
11409,
972,
365,
314,
199,
6807,
499,
13,
4129,
88,
12,
2382,
314,
7795,
31657,
17118,
370,
314,
7795,
3992,
14,
199,
1596,
3838,
2376,
687,
314,
12224,
11102,
14746,
701,
376,
625,
15737,
12601,
199,
14720,
370,
314,
12224,
11102,
14746,
701,
314,
2011,
12429,
2410,
199,
20035,
25365,
641,
282,
10266,
13,
548,
6411,
663,
14,
3626,
1384,
6623,
314,
2549,
199,
533,
402,
376,
1256,
334,
581,
26,
1021,
413,
12,
12431,
26,
1021,
499,
12,
10030,
26,
1021,
650,
680,
199,
199,
1918,
1300,
12429,
365,
282,
2196,
27882,
12429,
543,
5661,
1300,
23155,
199,
8,
14635,
680,
982,
642,
12429,
365,
28161,
641,
1006,
23466,
6093,
666,
3438,
12,
652,
365,
199,
1883,
590,
406,
329,
1326,
315,
2399,
7914,
436,
12850,
315,
17255,
282,
7031,
943,
13,
4358,
14,
199,
26015,
10417,
376,
13130,
12429,
12,
1314,
1990,
28161,
641,
11624,
666,
3438,
12,
543,
199,
765,
534,
20035,
7,
641,
314,
7971,
1926,
666,
3438,
295,
10569,
314,
15197,
402,
314,
199,
9869,
12,
284,
14,
69,
2020,
14569,
314,
12224,
11102,
687,
314,
8207,
402,
314,
3486,
88,
199,
475,
4751,
314,
8126,
14,
961,
25365,
2058,
315,
282,
5117,
943,
13,
4358,
14,
3390,
626,
376,
199,
19389,
3955,
1172,
2757,
370,
19781,
314,
1329,
402,
1300,
23155,
1314,
199,
2027,
854,
1172,
522,
30355,
315,
282,
8545,
477,
16772,
315,
943,
13,
4358,
14,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
17474,
869,
500,
25844,
10072,
5193,
665,
74,
14038,
32,
262,
10928,
30298,
14,
5411,
13,
10205,
1410,
14,
271,
30,
199,
3,
844,
26,
6289,
19442,
14,
421,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
15628,
492,
9571,
21668,
8508,
199,
504,
6357,
14,
25851,
492,
8256,
1892,
12601,
8508,
12847,
199,
504,
6357,
14,
6759,
492,
943,
63,
4358,
199,
199,
1590,
14,
2355,
14,
5176,
8,
16,
9,
199,
199,
3,
7958,
666,
199,
56,
12,
612,
275,
1852,
63,
21893,
8,
78,
63,
3356,
29,
5279,
12,
302,
63,
3179,
29,
18,
12,
2196,
63,
929,
29,
2260,
12,
2116,
4350,
63,
1516,
29,
21,
14,
16,
9,
199,
56,
63,
2834,
12,
612,
63,
2834,
275,
1323,
1491,
6683,
467,
612,
1491,
6683,
61,
199,
56,
63,
1078,
12,
612,
63,
1078,
275,
1323,
59,
6683,
26,
6718,
467,
612,
59,
6683,
26,
6718,
61,
199,
56,
63,
2834,
63,
1078,
12,
612,
63,
2834,
63,
1078,
275,
1323,
1491,
6718,
467,
612,
1491,
6718,
61,
199,
56,
63,
396,
12,
612,
63,
396,
275,
1323,
59,
6718,
8429,
612,
59,
6718,
2938,
199,
199,
3,
16732,
625,
15737,
12601,
2196,
27882,
12429,
641,
8852,
3560,
436,
6411,
199,
3,
666,
436,
9352,
641,
511,
666,
199,
9694,
275,
9571,
21668,
8508,
8,
78,
63,
10646,
29,
821,
9,
199,
9694,
14,
3269,
8,
56,
63,
2834,
63,
1078,
12,
612,
63,
2834,
63,
1078,
9,
199,
9694,
63,
15349,
275,
6975,
14,
6892,
63,
14417,
8,
56,
63,
396,
9,
199,
3397,
275,
943,
63,
4358,
8,
89,
63,
396,
12,
6975,
63,
15349,
9,
199,
199,
3,
16732,
2196,
27882,
12429,
12,
12855,
1866,
641,
6411,
666,
436,
9352,
199,
3,
641,
511,
666,
199,
9694,
275,
9571,
21668,
8508,
8,
78,
63,
10646,
29,
821,
9,
199,
9694,
14,
3269,
8,
56,
63,
2834,
12,
612,
63,
2834,
9,
199,
9694,
63,
15349,
275,
6975,
14,
6892,
63,
14417,
8,
56,
63,
396,
9,
199,
4093,
63,
9694,
275,
8256,
1892,
12601,
8508,
12847,
8,
9694,
12,
1083,
628,
20035,
401,
6277,
628,
657,
3269,
531,
199,
4093,
63,
9694,
14,
3269,
8,
56,
63,
1078,
12,
612,
63,
1078,
9,
199,
4093,
63,
9694,
63,
15349,
275,
5259,
63,
9694,
14,
6892,
63,
14417,
8,
56,
63,
396,
9,
199,
4093,
63,
3397,
275,
943,
63,
4358,
8,
89,
63,
396,
12,
5259,
63,
9694,
63,
15349,
9,
199,
199,
3,
14794,
4493,
315,
14746,
19555,
4799,
601,
3838,
199,
6003,
14,
8941,
8,
16,
9,
199,
7120,
275,
2097,
82,
401,
298,
71,
401,
298,
66,
937,
199,
509,
284,
315,
1425,
8,
9694,
63,
15349,
14,
1392,
59,
16,
4682,
272,
4488,
14,
7691,
8,
9694,
63,
15349,
59,
73,
12,
378,
467,
6975,
63,
15349,
59,
73,
12,
413,
467,
1598,
5259,
63,
9694,
63,
15349,
59,
73,
12,
378,
61,
446,
6975,
63,
15349,
59,
73,
12,
378,
467,
1598,
5259,
63,
9694,
63,
15349,
59,
73,
12,
413,
61,
446,
6975,
63,
15349,
59,
73,
12,
413,
467,
1598,
3164,
29,
7120,
59,
89,
63,
396,
59,
73,
2365,
4854,
63,
2063,
29,
17,
69,
13,
18,
9,
199,
199,
3,
14794,
23668,
7914,
199,
6003,
14,
2798,
779,
17,
14,
16,
467,
359,
16,
14,
16,
467,
283,
293,
297,
6605,
29,
1165,
12,
1768,
628,
2543,
413,
531,
199,
6003,
14,
2798,
779,
16,
14,
16,
467,
359,
17,
14,
16,
467,
283,
1939,
297,
6605,
29,
1165,
12,
1768,
628,
2543,
499,
531,
199,
6003,
14,
2798,
779,
16,
14,
16,
467,
359,
16,
14,
16,
467,
283,
656,
297,
6605,
29,
1165,
12,
1768,
628,
2543,
650,
531,
199,
199,
3,
14794,
18135,
402,
4137,
3486,
88,
199,
6003,
14,
2798,
779,
16,
14,
16,
12,
413,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
467,
359,
16,
14,
16,
12,
378,
14,
16,
12,
413,
14,
16,
12,
378,
14,
16,
467,
283,
75,
297,
1768,
628,
3184,
88,
531,
199,
199,
3,
1626,
1397,
323,
4501,
641,
314,
3486,
88,
199,
6003,
14,
10898,
8,
82,
6774,
16827,
10865,
91,
17,
8847,
19,
93,
4,
12,
2672,
60,
10865,
91,
17,
8847,
19,
93,
4,
12,
2672,
60,
10865,
91,
17,
8847,
19,
93
] |
[
199,
12813,
389,
199,
20122,
3616,
8256,
1892,
1754,
367,
650,
13,
533,
12505,
199,
12813,
389,
199,
199,
2765,
2893,
22907,
11409,
2335,
4212,
28886,
25365,
4493,
14746,
199,
27583,
367,
282,
650,
13,
533,
12505,
5160,
14,
473,
914,
11409,
972,
365,
314,
199,
6807,
499,
13,
4129,
88,
12,
2382,
314,
7795,
31657,
17118,
370,
314,
7795,
3992,
14,
199,
1596,
3838,
2376,
687,
314,
12224,
11102,
14746,
701,
376,
625,
15737,
12601,
199,
14720,
370,
314,
12224,
11102,
14746,
701,
314,
2011,
12429,
2410,
199,
20035,
25365,
641,
282,
10266,
13,
548,
6411,
663,
14,
3626,
1384,
6623,
314,
2549,
199,
533,
402,
376,
1256,
334,
581,
26,
1021,
413,
12,
12431,
26,
1021,
499,
12,
10030,
26,
1021,
650,
680,
199,
199,
1918,
1300,
12429,
365,
282,
2196,
27882,
12429,
543,
5661,
1300,
23155,
199,
8,
14635,
680,
982,
642,
12429,
365,
28161,
641,
1006,
23466,
6093,
666,
3438,
12,
652,
365,
199,
1883,
590,
406,
329,
1326,
315,
2399,
7914,
436,
12850,
315,
17255,
282,
7031,
943,
13,
4358,
14,
199,
26015,
10417,
376,
13130,
12429,
12,
1314,
1990,
28161,
641,
11624,
666,
3438,
12,
543,
199,
765,
534,
20035,
7,
641,
314,
7971,
1926,
666,
3438,
295,
10569,
314,
15197,
402,
314,
199,
9869,
12,
284,
14,
69,
2020,
14569,
314,
12224,
11102,
687,
314,
8207,
402,
314,
3486,
88,
199,
475,
4751,
314,
8126,
14,
961,
25365,
2058,
315,
282,
5117,
943,
13,
4358,
14,
3390,
626,
376,
199,
19389,
3955,
1172,
2757,
370,
19781,
314,
1329,
402,
1300,
23155,
1314,
199,
2027,
854,
1172,
522,
30355,
315,
282,
8545,
477,
16772,
315,
943,
13,
4358,
14,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
17474,
869,
500,
25844,
10072,
5193,
665,
74,
14038,
32,
262,
10928,
30298,
14,
5411,
13,
10205,
1410,
14,
271,
30,
199,
3,
844,
26,
6289,
19442,
14,
421,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
15628,
492,
9571,
21668,
8508,
199,
504,
6357,
14,
25851,
492,
8256,
1892,
12601,
8508,
12847,
199,
504,
6357,
14,
6759,
492,
943,
63,
4358,
199,
199,
1590,
14,
2355,
14,
5176,
8,
16,
9,
199,
199,
3,
7958,
666,
199,
56,
12,
612,
275,
1852,
63,
21893,
8,
78,
63,
3356,
29,
5279,
12,
302,
63,
3179,
29,
18,
12,
2196,
63,
929,
29,
2260,
12,
2116,
4350,
63,
1516,
29,
21,
14,
16,
9,
199,
56,
63,
2834,
12,
612,
63,
2834,
275,
1323,
1491,
6683,
467,
612,
1491,
6683,
61,
199,
56,
63,
1078,
12,
612,
63,
1078,
275,
1323,
59,
6683,
26,
6718,
467,
612,
59,
6683,
26,
6718,
61,
199,
56,
63,
2834,
63,
1078,
12,
612,
63,
2834,
63,
1078,
275,
1323,
1491,
6718,
467,
612,
1491,
6718,
61,
199,
56,
63,
396,
12,
612,
63,
396,
275,
1323,
59,
6718,
8429,
612,
59,
6718,
2938,
199,
199,
3,
16732,
625,
15737,
12601,
2196,
27882,
12429,
641,
8852,
3560,
436,
6411,
199,
3,
666,
436,
9352,
641,
511,
666,
199,
9694,
275,
9571,
21668,
8508,
8,
78,
63,
10646,
29,
821,
9,
199,
9694,
14,
3269,
8,
56,
63,
2834,
63,
1078,
12,
612,
63,
2834,
63,
1078,
9,
199,
9694,
63,
15349,
275,
6975,
14,
6892,
63,
14417,
8,
56,
63,
396,
9,
199,
3397,
275,
943,
63,
4358,
8,
89,
63,
396,
12,
6975,
63,
15349,
9,
199,
199,
3,
16732,
2196,
27882,
12429,
12,
12855,
1866,
641,
6411,
666,
436,
9352,
199,
3,
641,
511,
666,
199,
9694,
275,
9571,
21668,
8508,
8,
78,
63,
10646,
29,
821,
9,
199,
9694,
14,
3269,
8,
56,
63,
2834,
12,
612,
63,
2834,
9,
199,
9694,
63,
15349,
275,
6975,
14,
6892,
63,
14417,
8,
56,
63,
396,
9,
199,
4093,
63,
9694,
275,
8256,
1892,
12601,
8508,
12847,
8,
9694,
12,
1083,
628,
20035,
401,
6277,
628,
657,
3269,
531,
199,
4093,
63,
9694,
14,
3269,
8,
56,
63,
1078,
12,
612,
63,
1078,
9,
199,
4093,
63,
9694,
63,
15349,
275,
5259,
63,
9694,
14,
6892,
63,
14417,
8,
56,
63,
396,
9,
199,
4093,
63,
3397,
275,
943,
63,
4358,
8,
89,
63,
396,
12,
5259,
63,
9694,
63,
15349,
9,
199,
199,
3,
14794,
4493,
315,
14746,
19555,
4799,
601,
3838,
199,
6003,
14,
8941,
8,
16,
9,
199,
7120,
275,
2097,
82,
401,
298,
71,
401,
298,
66,
937,
199,
509,
284,
315,
1425,
8,
9694,
63,
15349,
14,
1392,
59,
16,
4682,
272,
4488,
14,
7691,
8,
9694,
63,
15349,
59,
73,
12,
378,
467,
6975,
63,
15349,
59,
73,
12,
413,
467,
1598,
5259,
63,
9694,
63,
15349,
59,
73,
12,
378,
61,
446,
6975,
63,
15349,
59,
73,
12,
378,
467,
1598,
5259,
63,
9694,
63,
15349,
59,
73,
12,
413,
61,
446,
6975,
63,
15349,
59,
73,
12,
413,
467,
1598,
3164,
29,
7120,
59,
89,
63,
396,
59,
73,
2365,
4854,
63,
2063,
29,
17,
69,
13,
18,
9,
199,
199,
3,
14794,
23668,
7914,
199,
6003,
14,
2798,
779,
17,
14,
16,
467,
359,
16,
14,
16,
467,
283,
293,
297,
6605,
29,
1165,
12,
1768,
628,
2543,
413,
531,
199,
6003,
14,
2798,
779,
16,
14,
16,
467,
359,
17,
14,
16,
467,
283,
1939,
297,
6605,
29,
1165,
12,
1768,
628,
2543,
499,
531,
199,
6003,
14,
2798,
779,
16,
14,
16,
467,
359,
16,
14,
16,
467,
283,
656,
297,
6605,
29,
1165,
12,
1768,
628,
2543,
650,
531,
199,
199,
3,
14794,
18135,
402,
4137,
3486,
88,
199,
6003,
14,
2798,
779,
16,
14,
16,
12,
413,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
467,
359,
16,
14,
16,
12,
378,
14,
16,
12,
413,
14,
16,
12,
378,
14,
16,
467,
283,
75,
297,
1768,
628,
3184,
88,
531,
199,
199,
3,
1626,
1397,
323,
4501,
641,
314,
3486,
88,
199,
6003,
14,
10898,
8,
82,
6774,
16827,
10865,
91,
17,
8847,
19,
93,
4,
12,
2672,
60,
10865,
91,
17,
8847,
19,
93,
4,
12,
2672,
60,
10865,
91,
17,
8847,
19,
93,
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
] |
xkmato/youtube-dl
|
youtube_dl/extractor/viki.py
|
81
|
11693
|
# coding: utf-8
from __future__ import unicode_literals
import json
import time
import hmac
import hashlib
import itertools
from ..utils import (
ExtractorError,
int_or_none,
parse_age_limit,
parse_iso8601,
)
from ..compat import compat_urllib_request
from .common import InfoExtractor
class VikiBaseIE(InfoExtractor):
_VALID_URL_BASE = r'https?://(?:www\.)?viki\.(?:com|net|mx|jp|fr)/'
_API_QUERY_TEMPLATE = '/v4/%sapp=%s&t=%s&site=www.viki.com'
_API_URL_TEMPLATE = 'http://api.viki.io%s&sig=%s'
_APP = '65535a'
_APP_VERSION = '2.2.5.1428709186'
_APP_SECRET = '-$iJ}@p7!G@SyU/je1bEyWg}upLu-6V6-Lg9VD(]siH,r.,m-r|ulZ,U4LC/SeR)'
_NETRC_MACHINE = 'viki'
_token = None
def _prepare_call(self, path, timestamp=None, post_data=None):
path += '?' if '?' not in path else '&'
if not timestamp:
timestamp = int(time.time())
query = self._API_QUERY_TEMPLATE % (path, self._APP, timestamp)
if self._token:
query += '&token=%s' % self._token
sig = hmac.new(
self._APP_SECRET.encode('ascii'),
query.encode('ascii'),
hashlib.sha1
).hexdigest()
url = self._API_URL_TEMPLATE % (query, sig)
return compat_urllib_request.Request(
url, json.dumps(post_data).encode('utf-8')) if post_data else url
def _call_api(self, path, video_id, note, timestamp=None, post_data=None):
resp = self._download_json(
self._prepare_call(path, timestamp, post_data), video_id, note)
error = resp.get('error')
if error:
if error == 'invalid timestamp':
resp = self._download_json(
self._prepare_call(path, int(resp['current_timestamp']), post_data),
video_id, '%s (retry)' % note)
error = resp.get('error')
if error:
self._raise_error(resp['error'])
return resp
def _raise_error(self, error):
raise ExtractorError(
'%s returned error: %s' % (self.IE_NAME, error),
expected=True)
def _real_initialize(self):
self._login()
def _login(self):
(username, password) = self._get_login_info()
if username is None:
return
login_form = {
'login_id': username,
'password': password,
}
login = self._call_api(
'sessions.json', None,
'Logging in as %s' % username, post_data=login_form)
self._token = login.get('token')
if not self._token:
self.report_warning('Unable to get session token, login has probably failed')
@staticmethod
def dict_selection(dict_obj, preferred_key):
if preferred_key in dict_obj:
return dict_obj.get(preferred_key)
filtered_dict = list(filter(None, [dict_obj.get(k) for k in dict_obj.keys()]))
return filtered_dict[0] if filtered_dict else None
class VikiIE(VikiBaseIE):
IE_NAME = 'viki'
_VALID_URL = r'%s(?:videos|player)/(?P<id>[0-9]+v)' % VikiBaseIE._VALID_URL_BASE
_TESTS = [{
'url': 'http://www.viki.com/videos/1023585v-heirs-episode-14',
'info_dict': {
'id': '1023585v',
'ext': 'mp4',
'title': 'Heirs Episode 14',
'uploader': 'SBS',
'description': 'md5:c4b17b9626dd4b143dcc4d855ba3474e',
'upload_date': '20131121',
'age_limit': 13,
},
'skip': 'Blocked in the US',
}, {
# clip
'url': 'http://www.viki.com/videos/1067139v-the-avengers-age-of-ultron-press-conference',
'md5': '86c0b5dbd4d83a6611a79987cc7a1989',
'info_dict': {
'id': '1067139v',
'ext': 'mp4',
'title': "'The Avengers: Age of Ultron' Press Conference",
'description': 'md5:d70b2f9428f5488321bfe1db10d612ea',
'duration': 352,
'timestamp': 1430380829,
'upload_date': '20150430',
'uploader': 'Arirang TV',
'like_count': int,
'age_limit': 0,
}
}, {
'url': 'http://www.viki.com/videos/1048879v-ankhon-dekhi',
'info_dict': {
'id': '1048879v',
'ext': 'mp4',
'title': 'Ankhon Dekhi',
'duration': 6512,
'timestamp': 1408532356,
'upload_date': '20140820',
'uploader': 'Spuul',
'like_count': int,
'age_limit': 13,
},
'params': {
# m3u8 download
'skip_download': True,
}
}, {
# episode
'url': 'http://www.viki.com/videos/44699v-boys-over-flowers-episode-1',
'md5': '190f3ef426005ba3a080a63325955bc3',
'info_dict': {
'id': '44699v',
'ext': 'mp4',
'title': 'Boys Over Flowers - Episode 1',
'description': 'md5:52617e4f729c7d03bfd4bcbbb6e946f2',
'duration': 4155,
'timestamp': 1270496524,
'upload_date': '20100405',
'uploader': 'group8',
'like_count': int,
'age_limit': 13,
}
}, {
# youtube external
'url': 'http://www.viki.com/videos/50562v-poor-nastya-complete-episode-1',
'md5': '216d1afdc0c64d1febc1e9f2bd4b864b',
'info_dict': {
'id': '50562v',
'ext': 'mp4',
'title': 'Poor Nastya [COMPLETE] - Episode 1',
'description': '',
'duration': 607,
'timestamp': 1274949505,
'upload_date': '20101213',
'uploader': 'ad14065n',
'uploader_id': 'ad14065n',
'like_count': int,
'age_limit': 13,
}
}, {
'url': 'http://www.viki.com/player/44699v',
'only_matching': True,
}, {
# non-English description
'url': 'http://www.viki.com/videos/158036v-love-in-magic',
'md5': '1713ae35df5a521b31f6dc40730e7c9c',
'info_dict': {
'id': '158036v',
'ext': 'mp4',
'uploader': 'I Planet Entertainment',
'upload_date': '20111122',
'timestamp': 1321985454,
'description': 'md5:44b1e46619df3a072294645c770cef36',
'title': 'Love In Magic',
},
}]
def _real_extract(self, url):
video_id = self._match_id(url)
video = self._call_api(
'videos/%s.json' % video_id, video_id, 'Downloading video JSON')
title = self.dict_selection(video.get('titles', {}), 'en')
if not title:
title = 'Episode %d' % video.get('number') if video.get('type') == 'episode' else video.get('id') or video_id
container_titles = video.get('container', {}).get('titles', {})
container_title = self.dict_selection(container_titles, 'en')
title = '%s - %s' % (container_title, title)
description = self.dict_selection(video.get('descriptions', {}), 'en')
duration = int_or_none(video.get('duration'))
timestamp = parse_iso8601(video.get('created_at'))
uploader = video.get('author')
like_count = int_or_none(video.get('likes', {}).get('count'))
age_limit = parse_age_limit(video.get('rating'))
thumbnails = []
for thumbnail_id, thumbnail in video.get('images', {}).items():
thumbnails.append({
'id': thumbnail_id,
'url': thumbnail.get('url'),
})
subtitles = {}
for subtitle_lang, _ in video.get('subtitle_completions', {}).items():
subtitles[subtitle_lang] = [{
'ext': subtitles_format,
'url': self._prepare_call(
'videos/%s/subtitles/%s.%s' % (video_id, subtitle_lang, subtitles_format)),
} for subtitles_format in ('srt', 'vtt')]
result = {
'id': video_id,
'title': title,
'description': description,
'duration': duration,
'timestamp': timestamp,
'uploader': uploader,
'like_count': like_count,
'age_limit': age_limit,
'thumbnails': thumbnails,
'subtitles': subtitles,
}
streams = self._call_api(
'videos/%s/streams.json' % video_id, video_id,
'Downloading video streams JSON')
if 'external' in streams:
result.update({
'_type': 'url_transparent',
'url': streams['external']['url'],
})
return result
formats = []
for format_id, stream_dict in streams.items():
height = int_or_none(self._search_regex(
r'^(\d+)[pP]$', format_id, 'height', default=None))
for protocol, format_dict in stream_dict.items():
if format_id == 'm3u8':
formats = self._extract_m3u8_formats(
format_dict['url'], video_id, 'mp4', m3u8_id='m3u8-%s' % protocol)
else:
formats.append({
'url': format_dict['url'],
'format_id': '%s-%s' % (format_id, protocol),
'height': height,
})
self._sort_formats(formats)
result['formats'] = formats
return result
class VikiChannelIE(VikiBaseIE):
IE_NAME = 'viki:channel'
_VALID_URL = r'%s(?:tv|news|movies|artists)/(?P<id>[0-9]+c)' % VikiBaseIE._VALID_URL_BASE
_TESTS = [{
'url': 'http://www.viki.com/tv/50c-boys-over-flowers',
'info_dict': {
'id': '50c',
'title': 'Boys Over Flowers',
'description': 'md5:ecd3cff47967fe193cff37c0bec52790',
},
'playlist_count': 70,
}, {
'url': 'http://www.viki.com/tv/1354c-poor-nastya-complete',
'info_dict': {
'id': '1354c',
'title': 'Poor Nastya [COMPLETE]',
'description': 'md5:05bf5471385aa8b21c18ad450e350525',
},
'playlist_count': 127,
}, {
'url': 'http://www.viki.com/news/24569c-showbiz-korea',
'only_matching': True,
}, {
'url': 'http://www.viki.com/movies/22047c-pride-and-prejudice-2005',
'only_matching': True,
}, {
'url': 'http://www.viki.com/artists/2141c-shinee',
'only_matching': True,
}]
_PER_PAGE = 25
def _real_extract(self, url):
channel_id = self._match_id(url)
channel = self._call_api(
'containers/%s.json' % channel_id, channel_id,
'Downloading channel JSON')
title = self.dict_selection(channel['titles'], 'en')
description = self.dict_selection(channel['descriptions'], 'en')
entries = []
for video_type in ('episodes', 'clips', 'movies'):
for page_num in itertools.count(1):
page = self._call_api(
'containers/%s/%s.json?per_page=%d&sort=number&direction=asc&with_paging=true&page=%d'
% (channel_id, video_type, self._PER_PAGE, page_num), channel_id,
'Downloading %s JSON page #%d' % (video_type, page_num))
for video in page['response']:
video_id = video['id']
entries.append(self.url_result(
'http://www.viki.com/videos/%s' % video_id, 'Viki'))
if not page['pagination']['next']:
break
return self.playlist_result(entries, channel_id, title, description)
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
646,
900,
199,
646,
20330,
199,
646,
8337,
199,
646,
7975,
199,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
474,
63,
3097,
12,
272,
2198,
63,
4595,
15363,
12,
199,
9,
199,
504,
2508,
5819,
492,
8434,
63,
4078,
63,
1069,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
812,
11545,
1563,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
63,
5825,
275,
519,
7,
2859,
24524,
1544,
20316,
433,
8810,
4537,
5169,
957,
92,
846,
92,
9457,
92,
11538,
92,
4391,
2447,
7,
272,
485,
3735,
63,
11938,
63,
7433,
275,
1994,
86,
20,
3149,
83,
571,
2458,
83,
6,
84,
2458,
83,
6,
2124,
29,
1544,
14,
433,
8810,
14,
957,
7,
272,
485,
3735,
63,
2632,
63,
7433,
275,
283,
1014,
921,
1246,
14,
433,
8810,
14,
2308,
5,
83,
6,
4093,
2458,
83,
7,
339,
485,
7121,
275,
283,
26439,
65,
7,
272,
485,
7121,
63,
4612,
275,
283,
18,
14,
18,
14,
21,
14,
1079,
11884,
1643,
11656,
7,
272,
485,
7121,
63,
12961,
275,
2475,
4,
73,
42,
93,
32,
80,
23,
1,
39,
32,
4323,
53,
15,
6532,
17,
66,
37,
89,
55,
71,
93,
384,
18176,
13,
22,
54,
22,
13,
44,
71,
25,
26197,
8,
61,
338,
40,
12,
82,
2020,
77,
13,
82,
92,
348,
58,
12,
53,
20,
7027,
15,
1513,
50,
3171,
339,
485,
7278,
8205,
63,
20890,
275,
283,
433,
8810,
7,
339,
485,
1418,
275,
488,
339,
347,
485,
6726,
63,
1250,
8,
277,
12,
931,
12,
4913,
29,
403,
12,
2963,
63,
576,
29,
403,
304,
267,
931,
847,
15539,
340,
15539,
440,
315,
931,
587,
29285,
267,
340,
440,
4913,
26,
288,
4913,
275,
1109,
8,
521,
14,
521,
1012,
267,
1827,
275,
291,
423,
3735,
63,
11938,
63,
7433,
450,
334,
515,
12,
291,
423,
7121,
12,
4913,
9,
267,
340,
291,
423,
1418,
26,
288,
1827,
847,
7673,
1418,
2458,
83,
7,
450,
291,
423,
1418,
267,
5259,
275,
20330,
14,
1222,
8,
288,
291,
423,
7121,
63,
12961,
14,
2143,
360,
4371,
659,
288,
1827,
14,
2143,
360,
4371,
659,
288,
8337,
14,
4835,
17,
267,
7092,
11453,
342,
267,
1166,
275,
291,
423,
3735,
63,
2632,
63,
7433,
450,
334,
1131,
12,
5259,
9,
267,
372,
8434,
63,
4078,
63,
1069,
14,
2017,
8,
288,
1166,
12,
2022,
14,
4180,
8,
1932,
63,
576,
680,
2143,
360,
1624,
13,
24,
1333,
340,
2963,
63,
576,
587,
1166,
339,
347,
485,
1250,
63,
1246,
8,
277,
12,
931,
12,
3991,
63,
344,
12,
5317,
12,
4913,
29,
403,
12,
2963,
63,
576,
29,
403,
304,
267,
3085,
275,
291,
423,
4249,
63,
1001,
8,
288,
291,
423,
6726,
63,
1250,
8,
515,
12,
4913,
12,
2963,
63,
576,
395,
3991,
63,
344,
12,
5317,
9,
398,
1125,
275,
3085,
14,
362,
360,
705,
358,
267,
340,
1125,
26,
288,
340,
1125,
508,
283,
3197,
4913,
356,
355,
3085,
275,
291,
423,
4249,
63,
1001,
8,
490,
291,
423,
6726,
63,
1250,
8,
515,
12,
1109,
8,
4518,
459,
1818,
63,
3954,
3815,
2963,
63,
576,
395,
490,
3991,
63,
344,
12,
1543,
83,
334,
7154,
3171,
450,
5317,
9,
355,
1125,
275,
3085,
14,
362,
360,
705,
358,
288,
340,
1125,
26,
355,
291,
423,
3730,
63,
705,
8,
4518,
459,
705,
1105,
398,
372,
3085,
339,
347,
485,
3730,
63,
705,
8,
277,
12,
1125,
304,
267,
746,
19783,
8,
288,
1543,
83,
2138,
1125,
26,
450,
83,
7,
450,
334,
277,
14,
4332,
63,
2339,
12,
1125,
395,
288,
1420,
29,
549,
9,
339,
347,
485,
3093,
63,
8489,
8,
277,
304,
267,
291,
423,
2886,
342,
339,
347,
485,
2886,
8,
277,
304,
267,
334,
2473,
12,
2505,
9,
275,
291,
423,
362,
63,
2886,
63,
815,
342,
267,
340,
3434,
365,
488,
26,
288,
372,
398,
4676,
63,
964,
275,
469,
288,
283,
2886,
63,
344,
356,
3434,
12,
288,
283,
2060,
356,
2505,
12,
267,
789,
398,
4676,
275,
291,
423,
1250,
63,
1246,
8,
288,
283,
11676,
14,
1001,
297,
488,
12,
288,
283,
14054,
315,
465,
450,
83,
7,
450,
3434,
12,
2963,
63,
576,
29,
2886,
63,
964,
9,
398,
291,
423,
1418,
275,
4676,
14,
362,
360,
1418,
358,
267,
340,
440,
291,
423,
1418,
26,
288,
291,
14,
3070,
63,
3764,
360,
6005,
370,
664,
2351,
1526,
12,
4676,
965,
8646,
3405,
358,
339,
768,
4639,
272,
347,
1211,
63,
5592,
8,
807,
63,
1113,
12,
14388,
63,
498,
304,
267,
340,
14388,
63,
498,
315,
1211,
63,
1113,
26,
288,
372,
1211,
63,
1113,
14,
362,
8,
17477,
63,
498,
9,
398,
9806,
63,
807,
275,
769,
8,
1541,
8,
403,
12,
359,
807,
63,
1113,
14,
362,
8,
75,
9,
367,
1022,
315,
1211,
63,
1113,
14,
1612,
342,
2459,
267,
372,
9806,
63,
807,
59,
16,
61,
340,
9806,
63,
807,
587,
488,
421,
199,
533,
812,
11545,
4332,
8,
2201,
8810,
1563,
4332,
304,
272,
15292,
63,
2339,
275,
283,
433,
8810,
7,
272,
485,
5600,
63,
2632,
275,
519,
5956,
83,
5169,
11418,
92,
6147,
2447,
2229,
48,
28,
344,
9514,
16,
13,
25,
2807,
86,
3171,
450,
812,
11545,
1563,
4332,
423,
5600,
63,
2632,
63,
5825,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
433,
8810,
14,
957,
15,
11418,
15,
7759,
1276,
2426,
86,
13,
426,
32030,
13,
9544,
13,
1079,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
7759,
1276,
2426,
86,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1966,
32030,
27255,
6045,
4329,
297,
288,
283,
13671,
356,
283,
51,
11087,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
67,
20,
66,
1196,
66,
2534,
1479,
617,
20,
66,
12289,
68,
2055,
20,
68,
12593,
2470,
1082,
1342,
69,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
2192,
10753,
297,
288
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
646,
900,
199,
646,
20330,
199,
646,
8337,
199,
646,
7975,
199,
199,
504,
2508,
1208,
492,
334,
272,
19783,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
474,
63,
3097,
12,
272,
2198,
63,
4595,
15363,
12,
199,
9,
199,
504,
2508,
5819,
492,
8434,
63,
4078,
63,
1069,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
812,
11545,
1563,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
63,
5825,
275,
519,
7,
2859,
24524,
1544,
20316,
433,
8810,
4537,
5169,
957,
92,
846,
92,
9457,
92,
11538,
92,
4391,
2447,
7,
272,
485,
3735,
63,
11938,
63,
7433,
275,
1994,
86,
20,
3149,
83,
571,
2458,
83,
6,
84,
2458,
83,
6,
2124,
29,
1544,
14,
433,
8810,
14,
957,
7,
272,
485,
3735,
63,
2632,
63,
7433,
275,
283,
1014,
921,
1246,
14,
433,
8810,
14,
2308,
5,
83,
6,
4093,
2458,
83,
7,
339,
485,
7121,
275,
283,
26439,
65,
7,
272,
485,
7121,
63,
4612,
275,
283,
18,
14,
18,
14,
21,
14,
1079,
11884,
1643,
11656,
7,
272,
485,
7121,
63,
12961,
275,
2475,
4,
73,
42,
93,
32,
80,
23,
1,
39,
32,
4323,
53,
15,
6532,
17,
66,
37,
89,
55,
71,
93,
384,
18176,
13,
22,
54,
22,
13,
44,
71,
25,
26197,
8,
61,
338,
40,
12,
82,
2020,
77,
13,
82,
92,
348,
58,
12,
53,
20,
7027,
15,
1513,
50,
3171,
339,
485,
7278,
8205,
63,
20890,
275,
283,
433,
8810,
7,
339,
485,
1418,
275,
488,
339,
347,
485,
6726,
63,
1250,
8,
277,
12,
931,
12,
4913,
29,
403,
12,
2963,
63,
576,
29,
403,
304,
267,
931,
847,
15539,
340,
15539,
440,
315,
931,
587,
29285,
267,
340,
440,
4913,
26,
288,
4913,
275,
1109,
8,
521,
14,
521,
1012,
267,
1827,
275,
291,
423,
3735,
63,
11938,
63,
7433,
450,
334,
515,
12,
291,
423,
7121,
12,
4913,
9,
267,
340,
291,
423,
1418,
26,
288,
1827,
847,
7673,
1418,
2458,
83,
7,
450,
291,
423,
1418,
267,
5259,
275,
20330,
14,
1222,
8,
288,
291,
423,
7121,
63,
12961,
14,
2143,
360,
4371,
659,
288,
1827,
14,
2143,
360,
4371,
659,
288,
8337,
14,
4835,
17,
267,
7092,
11453,
342,
267,
1166,
275,
291,
423,
3735,
63,
2632,
63,
7433,
450,
334,
1131,
12,
5259,
9,
267,
372,
8434,
63,
4078,
63,
1069,
14,
2017,
8,
288,
1166,
12,
2022,
14,
4180,
8,
1932,
63,
576,
680,
2143,
360,
1624,
13,
24,
1333,
340,
2963,
63,
576,
587,
1166,
339,
347,
485,
1250,
63,
1246,
8,
277,
12,
931,
12,
3991,
63,
344,
12,
5317,
12,
4913,
29,
403,
12,
2963,
63,
576,
29,
403,
304,
267,
3085,
275,
291,
423,
4249,
63,
1001,
8,
288,
291,
423,
6726,
63,
1250,
8,
515,
12,
4913,
12,
2963,
63,
576,
395,
3991,
63,
344,
12,
5317,
9,
398,
1125,
275,
3085,
14,
362,
360,
705,
358,
267,
340,
1125,
26,
288,
340,
1125,
508,
283,
3197,
4913,
356,
355,
3085,
275,
291,
423,
4249,
63,
1001,
8,
490,
291,
423,
6726,
63,
1250,
8,
515,
12,
1109,
8,
4518,
459,
1818,
63,
3954,
3815,
2963,
63,
576,
395,
490,
3991,
63,
344,
12,
1543,
83,
334,
7154,
3171,
450,
5317,
9,
355,
1125,
275,
3085,
14,
362,
360,
705,
358,
288,
340,
1125,
26,
355,
291,
423,
3730,
63,
705,
8,
4518,
459,
705,
1105,
398,
372,
3085,
339,
347,
485,
3730,
63,
705,
8,
277,
12,
1125,
304,
267,
746,
19783,
8,
288,
1543,
83,
2138,
1125,
26,
450,
83,
7,
450,
334,
277,
14,
4332,
63,
2339,
12,
1125,
395,
288,
1420,
29,
549,
9,
339,
347,
485,
3093,
63,
8489,
8,
277,
304,
267,
291,
423,
2886,
342,
339,
347,
485,
2886,
8,
277,
304,
267,
334,
2473,
12,
2505,
9,
275,
291,
423,
362,
63,
2886,
63,
815,
342,
267,
340,
3434,
365,
488,
26,
288,
372,
398,
4676,
63,
964,
275,
469,
288,
283,
2886,
63,
344,
356,
3434,
12,
288,
283,
2060,
356,
2505,
12,
267,
789,
398,
4676,
275,
291,
423,
1250,
63,
1246,
8,
288,
283,
11676,
14,
1001,
297,
488,
12,
288,
283,
14054,
315,
465,
450,
83,
7,
450,
3434,
12,
2963,
63,
576,
29,
2886,
63,
964,
9,
398,
291,
423,
1418,
275,
4676,
14,
362,
360,
1418,
358,
267,
340,
440,
291,
423,
1418,
26,
288,
291,
14,
3070,
63,
3764,
360,
6005,
370,
664,
2351,
1526,
12,
4676,
965,
8646,
3405,
358,
339,
768,
4639,
272,
347,
1211,
63,
5592,
8,
807,
63,
1113,
12,
14388,
63,
498,
304,
267,
340,
14388,
63,
498,
315,
1211,
63,
1113,
26,
288,
372,
1211,
63,
1113,
14,
362,
8,
17477,
63,
498,
9,
398,
9806,
63,
807,
275,
769,
8,
1541,
8,
403,
12,
359,
807,
63,
1113,
14,
362,
8,
75,
9,
367,
1022,
315,
1211,
63,
1113,
14,
1612,
342,
2459,
267,
372,
9806,
63,
807,
59,
16,
61,
340,
9806,
63,
807,
587,
488,
421,
199,
533,
812,
11545,
4332,
8,
2201,
8810,
1563,
4332,
304,
272,
15292,
63,
2339,
275,
283,
433,
8810,
7,
272,
485,
5600,
63,
2632,
275,
519,
5956,
83,
5169,
11418,
92,
6147,
2447,
2229,
48,
28,
344,
9514,
16,
13,
25,
2807,
86,
3171,
450,
812,
11545,
1563,
4332,
423,
5600,
63,
2632,
63,
5825,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
433,
8810,
14,
957,
15,
11418,
15,
7759,
1276,
2426,
86,
13,
426,
32030,
13,
9544,
13,
1079,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
7759,
1276,
2426,
86,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1966,
32030,
27255,
6045,
4329,
297,
288,
283,
13671,
356,
283,
51,
11087,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
67,
20,
66,
1196,
66,
2534,
1479,
617,
20,
66,
12289,
68,
2055,
20,
68,
12593,
2470,
1082,
1342,
69,
297,
288,
283,
5064,
63,
602,
356,
283,
1797,
2192,
10753,
297,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
lutris/website
|
games/notifier.py
|
1
|
1688
|
"""Send a digest of unpublished content to moderators"""
from django.conf import settings
from accounts.models import User
from games import models
from emails.messages import send_email
DEFAULT_COUNT = 12
def get_unpublished_installers(count=DEFAULT_COUNT):
"""Return a random list of unpublished installers"""
return models.Installer.objects.filter(published=False).order_by('?')[:count]
def get_unpublished_screenshots(count=DEFAULT_COUNT):
"""Return a random list of unpublished screenshots"""
return models.Screenshot.objects.filter(published=False).order_by('?')[:count]
def get_unreviewed_game_submissions(count=DEFAULT_COUNT):
"""Return a random list of unreviewed game submissions"""
return models.GameSubmission.objects.filter(
accepted_at__isnull=True
).order_by('?')[:count]
def get_installer_issues(count=DEFAULT_COUNT):
"""Return a random list of installer issues"""
return models.InstallerIssue.objects.all().order_by('?')[:count]
def get_mod_mail_content():
"""Get the payload to be included in the digest"""
return {
'installers': get_unpublished_installers(),
'screenshots': get_unpublished_screenshots(),
'submissions': get_unreviewed_game_submissions(),
'issues': get_installer_issues()
}
def send_daily_mod_mail():
"""Send the email to moderators"""
context = get_mod_mail_content()
if settings.DEBUG:
moderators = [u[1] for u in settings.MANAGERS]
else:
moderators = [u.email for u in User.objects.filter(is_staff=True)]
subject = 'Your daily moderator mail'
return send_email('daily_mod_mail', context, subject, moderators)
|
agpl-3.0
|
[
624,
6795,
282,
10017,
402,
625,
8987,
1564,
370,
818,
82,
2750,
624,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
12639,
14,
992,
492,
2876,
199,
504,
9219,
83,
492,
1709,
199,
504,
14931,
14,
3431,
492,
3222,
63,
2123,
199,
199,
3472,
63,
8760,
275,
3144,
421,
199,
318,
664,
63,
324,
8987,
63,
17047,
83,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
625,
8987,
18535,
83,
624,
272,
372,
1709,
14,
27598,
14,
1462,
14,
1541,
8,
8987,
29,
797,
680,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
324,
8987,
63,
23269,
83,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
625,
8987,
27981,
83,
624,
272,
372,
1709,
14,
9616,
2782,
14,
1462,
14,
1541,
8,
8987,
29,
797,
680,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
324,
8578,
379,
63,
5097,
63,
29752,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
625,
8578,
379,
9219,
30399,
624,
272,
372,
1709,
14,
11454,
2610,
2250,
14,
1462,
14,
1541,
8,
267,
10226,
63,
292,
363,
15114,
29,
549,
272,
7092,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
17047,
63,
10115,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
18535,
10876,
624,
272,
372,
1709,
14,
27598,
17106,
14,
1462,
14,
452,
1252,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
1494,
63,
1198,
63,
1317,
837,
272,
408,
1002,
314,
4886,
370,
506,
5120,
315,
314,
10017,
624,
272,
372,
469,
267,
283,
17047,
83,
356,
664,
63,
324,
8987,
63,
17047,
83,
1062,
267,
283,
23269,
83,
356,
664,
63,
324,
8987,
63,
23269,
83,
1062,
267,
283,
29752,
356,
664,
63,
324,
8578,
379,
63,
5097,
63,
29752,
1062,
267,
283,
10115,
356,
664,
63,
17047,
63,
10115,
342,
272,
789,
421,
199,
318,
3222,
63,
18621,
63,
1494,
63,
1198,
837,
272,
408,
6795,
314,
3031,
370,
818,
82,
2750,
624,
272,
1067,
275,
664,
63,
1494,
63,
1198,
63,
1317,
342,
272,
340,
2202,
14,
5287,
26,
267,
818,
82,
2750,
275,
359,
85,
59,
17,
61,
367,
399,
315,
2202,
14,
20600,
3960,
61,
272,
587,
26,
267,
818,
82,
2750,
275,
359,
85,
14,
2123,
367,
399,
315,
2876,
14,
1462,
14,
1541,
8,
374,
63,
7018,
29,
549,
1874,
272,
5420,
275,
283,
14398,
26122,
818,
9043,
6016,
7,
272,
372,
3222,
63,
2123,
360,
18621,
63,
1494,
63,
1198,
297,
1067,
12,
5420,
12,
818,
82,
2750,
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
] |
[
6795,
282,
10017,
402,
625,
8987,
1564,
370,
818,
82,
2750,
624,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
12639,
14,
992,
492,
2876,
199,
504,
9219,
83,
492,
1709,
199,
504,
14931,
14,
3431,
492,
3222,
63,
2123,
199,
199,
3472,
63,
8760,
275,
3144,
421,
199,
318,
664,
63,
324,
8987,
63,
17047,
83,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
625,
8987,
18535,
83,
624,
272,
372,
1709,
14,
27598,
14,
1462,
14,
1541,
8,
8987,
29,
797,
680,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
324,
8987,
63,
23269,
83,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
625,
8987,
27981,
83,
624,
272,
372,
1709,
14,
9616,
2782,
14,
1462,
14,
1541,
8,
8987,
29,
797,
680,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
324,
8578,
379,
63,
5097,
63,
29752,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
625,
8578,
379,
9219,
30399,
624,
272,
372,
1709,
14,
11454,
2610,
2250,
14,
1462,
14,
1541,
8,
267,
10226,
63,
292,
363,
15114,
29,
549,
272,
7092,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
17047,
63,
10115,
8,
835,
29,
3472,
63,
8760,
304,
272,
408,
1767,
282,
2196,
769,
402,
18535,
10876,
624,
272,
372,
1709,
14,
27598,
17106,
14,
1462,
14,
452,
1252,
1648,
63,
991,
360,
18478,
1491,
835,
61,
421,
199,
318,
664,
63,
1494,
63,
1198,
63,
1317,
837,
272,
408,
1002,
314,
4886,
370,
506,
5120,
315,
314,
10017,
624,
272,
372,
469,
267,
283,
17047,
83,
356,
664,
63,
324,
8987,
63,
17047,
83,
1062,
267,
283,
23269,
83,
356,
664,
63,
324,
8987,
63,
23269,
83,
1062,
267,
283,
29752,
356,
664,
63,
324,
8578,
379,
63,
5097,
63,
29752,
1062,
267,
283,
10115,
356,
664,
63,
17047,
63,
10115,
342,
272,
789,
421,
199,
318,
3222,
63,
18621,
63,
1494,
63,
1198,
837,
272,
408,
6795,
314,
3031,
370,
818,
82,
2750,
624,
272,
1067,
275,
664,
63,
1494,
63,
1198,
63,
1317,
342,
272,
340,
2202,
14,
5287,
26,
267,
818,
82,
2750,
275,
359,
85,
59,
17,
61,
367,
399,
315,
2202,
14,
20600,
3960,
61,
272,
587,
26,
267,
818,
82,
2750,
275,
359,
85,
14,
2123,
367,
399,
315,
2876,
14,
1462,
14,
1541,
8,
374,
63,
7018,
29,
549,
1874,
272,
5420,
275,
283,
14398,
26122,
818,
9043,
6016,
7,
272,
372,
3222,
63,
2123,
360,
18621,
63,
1494,
63,
1198,
297,
1067,
12,
5420,
12,
818,
82,
2750,
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,
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
] |
nehresma/bvcms
|
CmsWeb/test.py
|
3
|
1031
|
orgid = 2191107
sql = '''
WITH members AS (
SELECT om.PeopleId,
LastGroup = (SELECT MAX(Value) FROM dbo.Split(Groups, CHAR(10)) WHERE Value LIKE 'NewGuestEmail-%')
FROM dbo.OrgPeopleCurrent({0}) om
JOIN dbo.People p ON p.PeopleId = om.PeopleId
JOIN dbo.OrganizationMembers omm ON omm.PeopleId = p.PeopleId AND omm.OrganizationId = {0}
WHERE omm.MemberTypeId = 220
),
sends AS (
SELECT om.PeopleId,
SendNumber = CONVERT(INT, RIGHT(ISNULL(om.LastGroup, '0'), 1)) + 1
FROM members om
)
SELECT PeopleId FROM sends WHERE SendNumber = {1}
'''
# build queries for each email to send
qlist = []
for n in range(6):
nn = str(n+1)
query = q.SqlPeopleIdsToQuery(sql.format(orgid, nn))
qlist.append(query)
print nn, query, '<br>'
# use each query to send email and update sub-group
for n in range(6):
nn = str(n+1)
query = qlist[n]
model.EmailContent(query, 2920018, 'karen@bvcms.com', 'Karen Worrell', 'NewGuestEmail-' + nn)
# model.AddSubGroupFromQuery(query, orgid, 'NewGuestEmail-' + nn)
|
gpl-2.0
|
[
1308,
344,
275,
499,
1167,
6019,
23,
199,
199,
3009,
275,
1449,
199,
9139,
7556,
4319,
334,
199,
198,
4859,
30511,
14,
8070,
7939,
1304,
12,
11083,
198,
6090,
2448,
275,
334,
4859,
9141,
8,
1110,
9,
4442,
366,
656,
14,
8862,
8,
10177,
12,
8518,
8,
709,
430,
6038,
1594,
29369,
283,
4665,
16022,
7035,
3295,
358,
199,
198,
12491,
366,
656,
14,
11014,
8070,
7939,
5639,
2561,
16,
1552,
30511,
199,
198,
23321,
366,
656,
14,
8070,
7939,
299,
5258,
299,
14,
8070,
7939,
1304,
275,
30511,
14,
8070,
7939,
1304,
199,
198,
23321,
366,
656,
14,
15928,
23056,
312,
596,
5258,
312,
596,
14,
8070,
7939,
1304,
275,
299,
14,
8070,
7939,
1304,
2401,
312,
596,
14,
15928,
1304,
275,
469,
16,
93,
199,
198,
17688,
312,
596,
14,
7021,
2568,
275,
25647,
199,
395,
199,
2464,
795,
4319,
334,
199,
198,
4859,
30511,
14,
8070,
7939,
1304,
12,
11083,
198,
6795,
3259,
275,
1868,
8851,
8,
2919,
12,
7052,
8,
1311,
8084,
8,
676,
14,
6090,
2448,
12,
283,
16,
659,
413,
430,
435,
413,
199,
198,
12491,
7556,
30511,
199,
9,
199,
4859,
11379,
7939,
1304,
4442,
16178,
6038,
10217,
3259,
275,
469,
17,
93,
199,
2344,
199,
199,
3,
1900,
9212,
367,
1924,
3031,
370,
3222,
199,
81,
513,
275,
942,
199,
509,
302,
315,
1425,
8,
22,
304,
272,
11542,
275,
620,
8,
78,
11,
17,
9,
272,
1827,
275,
1894,
14,
16790,
8070,
7939,
11506,
1378,
3227,
8,
3009,
14,
908,
8,
1308,
344,
12,
11542,
430,
272,
1894,
513,
14,
740,
8,
1131,
9,
272,
870,
11542,
12,
1827,
12,
2650,
3289,
3524,
1362,
199,
3,
675,
1924,
1827,
370,
3222,
3031,
436,
1678,
1007,
13,
923,
199,
509,
302,
315,
1425,
8,
22,
304,
272,
11542,
275,
620,
8,
78,
11,
17,
9,
272,
1827,
275,
1894,
513,
59,
78,
61,
272,
1402,
14,
7035,
2714,
8,
1131,
12,
7349,
1840,
1085,
12,
283,
7351,
828,
32,
66,
6737,
706,
14,
957,
297,
283,
26133,
828,
10516,
264,
914,
297,
283,
4665,
16022,
7035,
15668,
435,
11542,
9,
272,
327,
1402,
14,
1123,
2610,
2448,
2532,
3227,
8,
1131,
12,
5981,
344,
12,
283,
4665,
16022,
7035,
15668,
435,
11542,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
344,
275,
499,
1167,
6019,
23,
199,
199,
3009,
275,
1449,
199,
9139,
7556,
4319,
334,
199,
198,
4859,
30511,
14,
8070,
7939,
1304,
12,
11083,
198,
6090,
2448,
275,
334,
4859,
9141,
8,
1110,
9,
4442,
366,
656,
14,
8862,
8,
10177,
12,
8518,
8,
709,
430,
6038,
1594,
29369,
283,
4665,
16022,
7035,
3295,
358,
199,
198,
12491,
366,
656,
14,
11014,
8070,
7939,
5639,
2561,
16,
1552,
30511,
199,
198,
23321,
366,
656,
14,
8070,
7939,
299,
5258,
299,
14,
8070,
7939,
1304,
275,
30511,
14,
8070,
7939,
1304,
199,
198,
23321,
366,
656,
14,
15928,
23056,
312,
596,
5258,
312,
596,
14,
8070,
7939,
1304,
275,
299,
14,
8070,
7939,
1304,
2401,
312,
596,
14,
15928,
1304,
275,
469,
16,
93,
199,
198,
17688,
312,
596,
14,
7021,
2568,
275,
25647,
199,
395,
199,
2464,
795,
4319,
334,
199,
198,
4859,
30511,
14,
8070,
7939,
1304,
12,
11083,
198,
6795,
3259,
275,
1868,
8851,
8,
2919,
12,
7052,
8,
1311,
8084,
8,
676,
14,
6090,
2448,
12,
283,
16,
659,
413,
430,
435,
413,
199,
198,
12491,
7556,
30511,
199,
9,
199,
4859,
11379,
7939,
1304,
4442,
16178,
6038,
10217,
3259,
275,
469,
17,
93,
199,
2344,
199,
199,
3,
1900,
9212,
367,
1924,
3031,
370,
3222,
199,
81,
513,
275,
942,
199,
509,
302,
315,
1425,
8,
22,
304,
272,
11542,
275,
620,
8,
78,
11,
17,
9,
272,
1827,
275,
1894,
14,
16790,
8070,
7939,
11506,
1378,
3227,
8,
3009,
14,
908,
8,
1308,
344,
12,
11542,
430,
272,
1894,
513,
14,
740,
8,
1131,
9,
272,
870,
11542,
12,
1827,
12,
2650,
3289,
3524,
1362,
199,
3,
675,
1924,
1827,
370,
3222,
3031,
436,
1678,
1007,
13,
923,
199,
509,
302,
315,
1425,
8,
22,
304,
272,
11542,
275,
620,
8,
78,
11,
17,
9,
272,
1827,
275,
1894,
513,
59,
78,
61,
272,
1402,
14,
7035,
2714,
8,
1131,
12,
7349,
1840,
1085,
12,
283,
7351,
828,
32,
66,
6737,
706,
14,
957,
297,
283,
26133,
828,
10516,
264,
914,
297,
283,
4665,
16022,
7035,
15668,
435,
11542,
9,
272,
327,
1402,
14,
1123,
2610,
2448,
2532,
3227,
8,
1131,
12,
5981,
344,
12,
283,
4665,
16022,
7035,
15668,
435,
11542,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
from addons.wiki.models import WikiPage, WikiVersion
class ContributorOrPublic(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
assert isinstance(obj, WikiPage), 'obj must be a WikiPage, got {}'.format(obj)
auth = get_user_auth(request)
if request.method in permissions.SAFE_METHODS:
return obj.node.is_public or obj.node.can_view(auth)
return (
obj.node.can_edit(auth)
or obj.node.addons_wiki_node_settings.is_publicly_editable
)
class ContributorOrPublicWikiVersion(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
assert isinstance(obj, WikiVersion), 'obj must be a WikiVersion, got {}'.format(obj)
auth = get_user_auth(request)
if request.method in permissions.SAFE_METHODS:
return obj.wiki_page.node.is_public or obj.wiki_page.node.can_view(auth)
return obj.wiki_page.node.can_edit(auth)
class ExcludeWithdrawals(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
assert isinstance(obj, WikiPage), 'obj must be a WikiPage, got {}'.format(obj)
node = obj.node
if node and node.is_retracted:
return False
return True
class ExcludeWithdrawalsWikiVersion(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
assert isinstance(obj, WikiVersion), 'obj must be a WikiVersion, got {}'.format(obj)
node = obj.wiki_page.node
if node and node.is_retracted:
return False
return True
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
4618,
63,
4857,
492,
3443,
199,
199,
504,
2986,
14,
1095,
14,
1208,
492,
664,
63,
751,
63,
1178,
199,
504,
21293,
14,
6797,
14,
992,
492,
644,
11545,
3276,
12,
644,
11545,
3353,
421,
199,
533,
17636,
2844,
9885,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3276,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3276,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1790,
275,
664,
63,
751,
63,
1178,
8,
1069,
9,
267,
340,
1056,
14,
765,
315,
3443,
14,
27657,
63,
18383,
26,
288,
372,
1559,
14,
932,
14,
374,
63,
3455,
503,
1559,
14,
932,
14,
2425,
63,
1345,
8,
1178,
9,
267,
372,
334,
288,
1559,
14,
932,
14,
2425,
63,
3773,
8,
1178,
9,
288,
503,
1559,
14,
932,
14,
10788,
63,
6797,
63,
932,
63,
1751,
14,
374,
63,
5645,
317,
429,
89,
63,
10820,
267,
776,
199,
199,
533,
17636,
2844,
9885,
26198,
3353,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3353,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3353,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1790,
275,
664,
63,
751,
63,
1178,
8,
1069,
9,
267,
340,
1056,
14,
765,
315,
3443,
14,
27657,
63,
18383,
26,
288,
372,
1559,
14,
6797,
63,
1606,
14,
932,
14,
374,
63,
3455,
503,
1559,
14,
6797,
63,
1606,
14,
932,
14,
2425,
63,
1345,
8,
1178,
9,
267,
372,
1559,
14,
6797,
63,
1606,
14,
932,
14,
2425,
63,
3773,
8,
1178,
9,
421,
199,
533,
28554,
3007,
5485,
2551,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3276,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3276,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1031,
275,
1559,
14,
932,
267,
340,
1031,
436,
1031,
14,
374,
63,
264,
1239,
1522,
26,
288,
372,
756,
267,
372,
715,
421,
199,
533,
28554,
3007,
5485,
2551,
26198,
3353,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3353,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3353,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1031,
275,
1559,
14,
6797,
63,
1606,
14,
932,
267,
340,
1031,
436,
1031,
14,
374,
63,
264,
1239,
1522,
26,
288,
372,
756,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
4618,
63,
4857,
492,
3443,
199,
199,
504,
2986,
14,
1095,
14,
1208,
492,
664,
63,
751,
63,
1178,
199,
504,
21293,
14,
6797,
14,
992,
492,
644,
11545,
3276,
12,
644,
11545,
3353,
421,
199,
533,
17636,
2844,
9885,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3276,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3276,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1790,
275,
664,
63,
751,
63,
1178,
8,
1069,
9,
267,
340,
1056,
14,
765,
315,
3443,
14,
27657,
63,
18383,
26,
288,
372,
1559,
14,
932,
14,
374,
63,
3455,
503,
1559,
14,
932,
14,
2425,
63,
1345,
8,
1178,
9,
267,
372,
334,
288,
1559,
14,
932,
14,
2425,
63,
3773,
8,
1178,
9,
288,
503,
1559,
14,
932,
14,
10788,
63,
6797,
63,
932,
63,
1751,
14,
374,
63,
5645,
317,
429,
89,
63,
10820,
267,
776,
199,
199,
533,
17636,
2844,
9885,
26198,
3353,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3353,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3353,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1790,
275,
664,
63,
751,
63,
1178,
8,
1069,
9,
267,
340,
1056,
14,
765,
315,
3443,
14,
27657,
63,
18383,
26,
288,
372,
1559,
14,
6797,
63,
1606,
14,
932,
14,
374,
63,
3455,
503,
1559,
14,
6797,
63,
1606,
14,
932,
14,
2425,
63,
1345,
8,
1178,
9,
267,
372,
1559,
14,
6797,
63,
1606,
14,
932,
14,
2425,
63,
3773,
8,
1178,
9,
421,
199,
533,
28554,
3007,
5485,
2551,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3276,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3276,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1031,
275,
1559,
14,
932,
267,
340,
1031,
436,
1031,
14,
374,
63,
264,
1239,
1522,
26,
288,
372,
756,
267,
372,
715,
421,
199,
533,
28554,
3007,
5485,
2551,
26198,
3353,
8,
6060,
14,
1563,
7980,
304,
339,
347,
965,
63,
785,
63,
5693,
8,
277,
12,
1056,
12,
2455,
12,
1559,
304,
267,
702,
1228,
8,
1113,
12,
644,
11545,
3353,
395,
283,
1113,
1471,
506,
282,
644,
11545,
3353,
12,
4788,
9499,
908,
8,
1113,
9,
267,
1031,
275,
1559,
14,
6797,
63,
1606,
14,
932,
267,
340,
1031,
436,
1031,
14,
374,
63,
264,
1239,
1522,
26,
288,
372,
756,
267,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Creworker/FreeCAD
|
src/Mod/Path/PathScripts/PathProject.py
|
6
|
6281
|
# -*- coding: utf-8 -*-
#***************************************************************************
#* *
#* Copyright (c) 2014 Yorik van Havre <yorik@uncreated.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* 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 Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import FreeCAD,FreeCADGui,Path,PathGui
from PySide import QtCore,QtGui
"""Path Project object and FreeCAD command"""
# Qt tanslation handling
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def translate(context, text, disambig=None):
return QtGui.QApplication.translate(context, text, disambig)
class ObjectPathProject:
def __init__(self,obj):
# obj.addProperty("App::PropertyFile", "PostProcessor", "CodeOutput", translate("PostProcessor","Select the Post Processor file for this project"))
obj.addProperty("App::PropertyFile", "OutputFile", "CodeOutput", translate("OutputFile","The NC output file for this project"))
obj.setEditorMode("OutputFile",0) #set to default mode
# obj.addProperty("App::PropertyBool","Editor","CodeOutput",translate("Show Editor","Show G-Code in simple editor after posting code"))
# obj.addProperty("Path::PropertyTooltable","Tooltable", "Path",translate("PathProject","The tooltable of this feature"))
obj.addProperty("App::PropertyString", "Description","Path",translate("PathProject","An optional description for this project"))
obj.Proxy = self
def __getstate__(self):
return None
def __setstate__(self,state):
return None
def onChanged(self,obj,prop):
pass
def execute(self,obj):
cmds = []
for child in obj.Group:
if child.isDerivedFrom("Path::Feature"):
cmds.extend(child.Path.Commands)
if cmds:
path = Path.Path(cmds)
obj.Path = path
class ViewProviderProject:
def __init__(self,vobj):
vobj.Proxy = self
mode = 2
vobj.setEditorMode('LineWidth',mode)
vobj.setEditorMode('MarkerColor',mode)
vobj.setEditorMode('NormalColor',mode)
# vobj.setEditorMode('ShowFirstRapid',mode)
vobj.setEditorMode('BoundingBox',mode)
vobj.setEditorMode('DisplayMode',mode)
vobj.setEditorMode('Selectable',mode)
vobj.setEditorMode('ShapeColor',mode)
vobj.setEditorMode('Transparency',mode)
vobj.setEditorMode('Visibility',mode)
def __getstate__(self): #mandatory
return None
def __setstate__(self,state): #mandatory
return None
def getIcon(self):
return ":/icons/Path-Project.svg"
def onChanged(self,vobj,prop):
mode = 2
vobj.setEditorMode('LineWidth',mode)
vobj.setEditorMode('MarkerColor',mode)
vobj.setEditorMode('NormalColor',mode)
# vobj.setEditorMode('ShowFirstRapid',mode)
vobj.setEditorMode('BoundingBox',mode)
vobj.setEditorMode('DisplayMode',mode)
vobj.setEditorMode('Selectable',mode)
vobj.setEditorMode('ShapeColor',mode)
vobj.setEditorMode('Transparency',mode)
vobj.setEditorMode('Visibility',mode)
class CommandProject:
def GetResources(self):
return {'Pixmap' : 'Path-Project',
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathProject","Project"),
'Accel': "P, P",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathProject","Creates a Path Project object")}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
def Activated(self):
incl = []
sel = FreeCADGui.Selection.getSelection()
for obj in sel:
if obj.isDerivedFrom("Path::Feature"):
incl.append(obj)
FreeCAD.ActiveDocument.openTransaction(translate("PathProject","Create Project"))
CommandProject.Create(incl)
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
@staticmethod
def Create(pathChildren = []):
"""Code to create a project"""
#FreeCADGui.addModule("PathScripts.PathProject")
obj = FreeCAD.ActiveDocument.addObject("Path::FeatureCompoundPython","Project")
ObjectPathProject(obj)
if pathChildren:
for child in pathChildren:
pathChildren.append(FreeCAD.ActiveDocument.getObject(obj.Name))
obj.Group = pathChildren
ViewProviderProject(obj.ViewObject)
#create a machine obj
import PathScripts
PathScripts.PathMachine.CommandPathMachine.Create()
return obj
if FreeCAD.GuiUp:
# register the FreeCAD command
FreeCADGui.addCommand('Path_Project',CommandProject())
FreeCAD.Console.PrintLog("Loading PathProject... done\n")
|
lgpl-2.1
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
17623,
199,
15002,
17997,
627,
199,
15002,
257,
1898,
334,
67,
9,
6927,
1488,
269,
3258,
20744,
869,
1214,
264,
665,
89,
269,
3258,
32,
324,
3966,
14,
846,
30,
4519,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
755,
627,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
199,
15002,
257,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8295,
627,
199,
15002,
17997,
627,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
199,
15002,
257,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
257,
627,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
199,
15002,
257,
8217,
6208,
257,
627,
199,
15002,
17997,
627,
199,
3,
17623,
199,
199,
646,
20914,
12,
10146,
17238,
4324,
12,
2042,
12,
2042,
4324,
199,
504,
1611,
15414,
492,
10565,
12,
10604,
199,
199,
624,
2042,
7290,
909,
436,
20914,
1414,
624,
199,
199,
3,
3959,
307,
796,
2212,
7252,
199,
893,
26,
272,
485,
2991,
275,
5928,
14,
12757,
14,
21865,
24,
272,
347,
9028,
8,
1100,
12,
1318,
12,
2153,
16902,
29,
403,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
12,
485,
2991,
9,
199,
2590,
4281,
26,
272,
347,
9028,
8,
1100,
12,
1318,
12,
2153,
16902,
29,
403,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
9,
421,
199,
533,
6935,
2042,
4761,
26,
1362,
339,
347,
636,
826,
721,
277,
12,
1113,
304,
199,
3,
263,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
1173,
401,
298,
6564,
10438,
401,
298,
3034,
2959,
401,
9028,
480,
6564,
10438,
2266,
5446,
314,
7711,
31500,
570,
367,
642,
2199,
2237,
267,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
1173,
401,
298,
23847,
401,
298,
3034,
2959,
401,
9028,
480,
23847,
2266,
1918,
653,
35,
1072,
570,
367,
642,
2199,
2237,
267,
1559,
14,
409,
10423,
1385,
480,
23847,
401,
16,
9,
327,
409,
370,
849,
818,
199,
3,
263,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
10349,
2266,
10423,
2266,
3034,
2959,
401,
5275,
480,
6824,
30318,
2266,
6824,
598,
13,
3034,
315,
3486,
8823,
2410,
25386,
1233,
2237,
199,
3,
263,
1559,
14,
525,
3697,
480,
2042,
447,
3697,
5157,
1224,
2266,
5157,
1224,
401,
221,
298,
2042,
401,
5275,
480,
2042,
4761,
2266,
1918,
4744,
1224,
402,
642,
3878,
2237,
267,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
1558,
401,
259,
298,
5831,
2266,
2042,
401,
5275,
480,
2042,
4761,
2266,
2493,
2716,
1369,
367,
642,
2199,
2237,
267,
1559,
14,
4936,
275,
291,
339,
347,
636,
16011,
721,
277,
304,
267,
372,
488,
339,
347,
636,
17212,
721,
277,
12,
929,
304,
267,
372,
488,
339,
347,
641,
6970,
8,
277,
12,
1113,
12,
4469,
304,
267,
986,
339,
347,
5341,
8,
277,
12,
1113,
304,
267,
11465,
275,
942,
267,
367,
1982,
315,
1559,
14,
2448,
26,
288,
340,
1982,
14,
374,
17793,
12905,
2532,
480,
2042,
447,
5968,
2349,
355,
11465,
14,
2880,
8,
1739,
14,
2042,
14,
14680,
9,
267,
340,
11465,
26,
288,
931,
275,
6912,
14,
2042,
8,
12975,
9,
288,
1559,
14,
2042,
275,
931,
199,
199,
533,
10935,
6663,
4761,
26,
339,
347,
636,
826,
721,
277,
12,
86,
1113,
304,
267,
373,
1113,
14,
4936,
275,
291,
267,
818,
275,
499,
267,
373,
1113,
14,
409,
10423,
1385,
360,
3049,
6216,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
12825,
4117,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
6241,
4117,
297,
632,
9,
199,
3,
263,
373,
1113,
14,
409,
10423,
1385,
360,
6824,
7147,
50,
27703,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
8934,
316,
3532,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7687,
1385,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
5446,
461,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7238,
4117,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
3188,
27292,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
24735,
297,
632,
9,
339,
347,
636,
16011,
721,
277,
304,
327,
19900,
267,
372,
488,
339,
347,
636,
17212,
721,
277,
12,
929,
304,
327,
19900,
267,
372,
488,
339,
347,
664,
8954,
8,
277,
304,
267,
372,
7244,
15,
16471,
15,
2042,
13,
4761,
14,
10273,
2,
339,
347,
641,
6970,
8,
277,
12,
86,
1113,
12,
4469,
304,
267,
818,
275,
499,
267,
373,
1113,
14,
409,
10423,
1385,
360,
3049,
6216,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
12825,
4117,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
6241,
4117,
297,
632,
9,
199,
3,
263,
373,
1113,
14,
409,
10423,
1385,
360,
6824,
7147,
50,
27703,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
8934,
316,
3532,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7687,
1385,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
5446,
461,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7238,
4117,
297
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
17623,
199,
15002,
17997,
627,
199,
15002,
257,
1898,
334,
67,
9,
6927,
1488,
269,
3258,
20744,
869,
1214,
264,
665,
89,
269,
3258,
32,
324,
3966,
14,
846,
30,
4519,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
199,
15002,
17997,
627,
199,
15002,
257,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
755,
627,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
199,
15002,
257,
1664,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
8295,
627,
199,
15002,
17997,
627,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
199,
15002,
257,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
257,
627,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
199,
15002,
257,
8217,
6208,
257,
627,
199,
15002,
17997,
627,
199,
3,
17623,
199,
199,
646,
20914,
12,
10146,
17238,
4324,
12,
2042,
12,
2042,
4324,
199,
504,
1611,
15414,
492,
10565,
12,
10604,
199,
199,
624,
2042,
7290,
909,
436,
20914,
1414,
624,
199,
199,
3,
3959,
307,
796,
2212,
7252,
199,
893,
26,
272,
485,
2991,
275,
5928,
14,
12757,
14,
21865,
24,
272,
347,
9028,
8,
1100,
12,
1318,
12,
2153,
16902,
29,
403,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
12,
485,
2991,
9,
199,
2590,
4281,
26,
272,
347,
9028,
8,
1100,
12,
1318,
12,
2153,
16902,
29,
403,
304,
267,
372,
5928,
14,
12757,
14,
5275,
8,
1100,
12,
1318,
12,
2153,
16902,
9,
421,
199,
533,
6935,
2042,
4761,
26,
1362,
339,
347,
636,
826,
721,
277,
12,
1113,
304,
199,
3,
263,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
1173,
401,
298,
6564,
10438,
401,
298,
3034,
2959,
401,
9028,
480,
6564,
10438,
2266,
5446,
314,
7711,
31500,
570,
367,
642,
2199,
2237,
267,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
1173,
401,
298,
23847,
401,
298,
3034,
2959,
401,
9028,
480,
23847,
2266,
1918,
653,
35,
1072,
570,
367,
642,
2199,
2237,
267,
1559,
14,
409,
10423,
1385,
480,
23847,
401,
16,
9,
327,
409,
370,
849,
818,
199,
3,
263,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
10349,
2266,
10423,
2266,
3034,
2959,
401,
5275,
480,
6824,
30318,
2266,
6824,
598,
13,
3034,
315,
3486,
8823,
2410,
25386,
1233,
2237,
199,
3,
263,
1559,
14,
525,
3697,
480,
2042,
447,
3697,
5157,
1224,
2266,
5157,
1224,
401,
221,
298,
2042,
401,
5275,
480,
2042,
4761,
2266,
1918,
4744,
1224,
402,
642,
3878,
2237,
267,
1559,
14,
525,
3697,
480,
2640,
447,
3697,
1558,
401,
259,
298,
5831,
2266,
2042,
401,
5275,
480,
2042,
4761,
2266,
2493,
2716,
1369,
367,
642,
2199,
2237,
267,
1559,
14,
4936,
275,
291,
339,
347,
636,
16011,
721,
277,
304,
267,
372,
488,
339,
347,
636,
17212,
721,
277,
12,
929,
304,
267,
372,
488,
339,
347,
641,
6970,
8,
277,
12,
1113,
12,
4469,
304,
267,
986,
339,
347,
5341,
8,
277,
12,
1113,
304,
267,
11465,
275,
942,
267,
367,
1982,
315,
1559,
14,
2448,
26,
288,
340,
1982,
14,
374,
17793,
12905,
2532,
480,
2042,
447,
5968,
2349,
355,
11465,
14,
2880,
8,
1739,
14,
2042,
14,
14680,
9,
267,
340,
11465,
26,
288,
931,
275,
6912,
14,
2042,
8,
12975,
9,
288,
1559,
14,
2042,
275,
931,
199,
199,
533,
10935,
6663,
4761,
26,
339,
347,
636,
826,
721,
277,
12,
86,
1113,
304,
267,
373,
1113,
14,
4936,
275,
291,
267,
818,
275,
499,
267,
373,
1113,
14,
409,
10423,
1385,
360,
3049,
6216,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
12825,
4117,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
6241,
4117,
297,
632,
9,
199,
3,
263,
373,
1113,
14,
409,
10423,
1385,
360,
6824,
7147,
50,
27703,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
8934,
316,
3532,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7687,
1385,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
5446,
461,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7238,
4117,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
3188,
27292,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
24735,
297,
632,
9,
339,
347,
636,
16011,
721,
277,
304,
327,
19900,
267,
372,
488,
339,
347,
636,
17212,
721,
277,
12,
929,
304,
327,
19900,
267,
372,
488,
339,
347,
664,
8954,
8,
277,
304,
267,
372,
7244,
15,
16471,
15,
2042,
13,
4761,
14,
10273,
2,
339,
347,
641,
6970,
8,
277,
12,
86,
1113,
12,
4469,
304,
267,
818,
275,
499,
267,
373,
1113,
14,
409,
10423,
1385,
360,
3049,
6216,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
12825,
4117,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
6241,
4117,
297,
632,
9,
199,
3,
263,
373,
1113,
14,
409,
10423,
1385,
360,
6824,
7147,
50,
27703,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
8934,
316,
3532,
297,
632,
9,
267,
373,
1113,
14,
409,
10423,
1385,
360,
7687,
1385,
297,
632,
9,
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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
] |
cloud-ark/cloudark
|
server/common/fm_logger.py
|
1
|
2400
|
import inspect
import logging
from server.common import constants
class Logging(object):
def __init__(self):
logging.basicConfig(filename=constants.LOG_FILE_NAME,
level=logging.DEBUG, filemode='a',
format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
self.logger = logging.getLogger("CloudARK")
# http://stackoverflow.com/questions/10973362/python-logging-function-name-file-name-line-number-using-a-single-file
def info(self, message):
# Get the previous frame in the stack, otherwise it would
# be this function!!!
try:
func = inspect.currentframe().f_back.f_code
# Dump the message + the name of this function to the log.
self.logger.info("<%s>: %s() %s:%i" % (
message,
func.co_name,
func.co_filename,
func.co_firstlineno
))
except IOError as e:
if e.errno == 28:
print("-- Disk full -- (most likely this also won't get printed.")
def debug(self, message):
# Get the previous frame in the stack, otherwise it would
# be this function!!!
try:
func = inspect.currentframe().f_back.f_code
# Dump the message + the name of this function to the log.
self.logger.debug("<%s>: %s() %s:%i" % (
message,
func.co_name,
func.co_filename,
func.co_firstlineno
))
except IOError as e:
if e.errno == 28:
print("-- Disk full -- (most likely this also won't get printed.")
def error(self, message):
# Get the previous frame in the stack, otherwise it would
# be this function!!!
try:
func = inspect.currentframe().f_back.f_code
# Dump the message + the name of this function to the log.
self.logger.error("<%s>: %s() %s:%i" % (
message,
func.co_name,
func.co_filename,
func.co_firstlineno
))
self.logger.error(message, exc_info=1)
except IOError as e:
if e.errno == 28:
print("-- Disk full -- (most likely this also won't get printed.")
|
apache-2.0
|
[
646,
6485,
199,
646,
2050,
199,
199,
504,
1654,
14,
2330,
492,
5262,
421,
199,
533,
19928,
8,
785,
304,
2286,
347,
636,
826,
721,
277,
304,
267,
2050,
14,
19602,
8,
1501,
29,
5559,
14,
4947,
63,
3817,
63,
2339,
12,
1169,
2166,
29,
4806,
14,
5287,
12,
32429,
534,
65,
297,
1169,
1475,
29342,
18331,
9,
83,
2818,
1188,
9,
83,
297,
1169,
1434,
5045,
9569,
77,
3149,
68,
3149,
57,
450,
41,
2689,
45,
2689,
51,
450,
80,
358,
267,
291,
14,
2921,
275,
2050,
14,
5572,
480,
9089,
5748,
531,
339,
327,
1455,
921,
23153,
14,
957,
15,
16069,
15,
709,
2576,
1153,
2789,
15,
1548,
13,
4806,
13,
1593,
13,
354,
13,
493,
13,
354,
13,
604,
13,
1955,
13,
4941,
13,
65,
13,
4780,
13,
493,
272,
347,
2256,
8,
277,
12,
1245,
304,
267,
327,
2372,
314,
4136,
2787,
315,
314,
3464,
12,
4257,
652,
3955,
267,
327,
506,
642,
805,
21512,
267,
862,
26,
288,
2562,
275,
6485,
14,
1818,
1943,
1252,
70,
63,
894,
14,
70,
63,
600,
288,
327,
19460,
314,
1245,
435,
314,
536,
402,
642,
805,
370,
314,
943,
14,
288,
291,
14,
2921,
14,
815,
6757,
5,
83,
20020,
450,
83,
342,
450,
83,
2689,
73,
2,
450,
334,
355,
1245,
12,
355,
2562,
14,
331,
63,
354,
12,
355,
2562,
14,
331,
63,
1501,
12,
355,
2562,
14,
331,
63,
30114,
288,
5082,
267,
871,
5925,
465,
325,
26,
288,
340,
325,
14,
7931,
508,
7294,
26,
355,
870,
6739,
26287,
2615,
1553,
334,
2786,
12060,
642,
2597,
7859,
1133,
664,
12487,
2685,
339,
347,
3105,
8,
277,
12,
1245,
304,
267,
327,
2372,
314,
4136,
2787,
315,
314,
3464,
12,
4257,
652,
3955,
267,
327,
506,
642,
805,
21512,
267,
862,
26,
288,
2562,
275,
6485,
14,
1818,
1943,
1252,
70,
63,
894,
14,
70,
63,
600,
288,
327,
19460,
314,
1245,
435,
314,
536,
402,
642,
805,
370,
314,
943,
14,
288,
291,
14,
2921,
14,
1757,
6757,
5,
83,
20020,
450,
83,
342,
450,
83,
2689,
73,
2,
450,
334,
355,
1245,
12,
355,
2562,
14,
331,
63,
354,
12,
355,
2562,
14,
331,
63,
1501,
12,
355,
2562,
14,
331,
63,
30114,
288,
5082,
267,
871,
5925,
465,
325,
26,
288,
340,
325,
14,
7931,
508,
7294,
26,
355,
870,
6739,
26287,
2615,
1553,
334,
2786,
12060,
642,
2597,
7859,
1133,
664,
12487,
2685,
339,
347,
1125,
8,
277,
12,
1245,
304,
398,
327,
2372,
314,
4136,
2787,
315,
314,
3464,
12,
4257,
652,
3955,
267,
327,
506,
642,
805,
21512,
398,
862,
26,
288,
2562,
275,
6485,
14,
1818,
1943,
1252,
70,
63,
894,
14,
70,
63,
600,
288,
327,
19460,
314,
1245,
435,
314,
536,
402,
642,
805,
370,
314,
943,
14,
288,
291,
14,
2921,
14,
705,
6757,
5,
83,
20020,
450,
83,
342,
450,
83,
2689,
73,
2,
450,
334,
355,
1245,
12,
355,
2562,
14,
331,
63,
354,
12,
355,
2562,
14,
331,
63,
1501,
12,
355,
2562,
14,
331,
63,
30114,
288,
5082,
953,
291,
14,
2921,
14,
705,
8,
1188,
12,
3178,
63,
815,
29,
17,
9,
398,
871,
5925,
465,
325,
26,
288,
340,
325,
14,
7931,
508,
7294,
26,
355,
870,
6739,
26287,
2615,
1553,
334,
2786,
12060,
642,
2597,
7859,
1133,
664,
12487,
2685,
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
] |
[
6485,
199,
646,
2050,
199,
199,
504,
1654,
14,
2330,
492,
5262,
421,
199,
533,
19928,
8,
785,
304,
2286,
347,
636,
826,
721,
277,
304,
267,
2050,
14,
19602,
8,
1501,
29,
5559,
14,
4947,
63,
3817,
63,
2339,
12,
1169,
2166,
29,
4806,
14,
5287,
12,
32429,
534,
65,
297,
1169,
1475,
29342,
18331,
9,
83,
2818,
1188,
9,
83,
297,
1169,
1434,
5045,
9569,
77,
3149,
68,
3149,
57,
450,
41,
2689,
45,
2689,
51,
450,
80,
358,
267,
291,
14,
2921,
275,
2050,
14,
5572,
480,
9089,
5748,
531,
339,
327,
1455,
921,
23153,
14,
957,
15,
16069,
15,
709,
2576,
1153,
2789,
15,
1548,
13,
4806,
13,
1593,
13,
354,
13,
493,
13,
354,
13,
604,
13,
1955,
13,
4941,
13,
65,
13,
4780,
13,
493,
272,
347,
2256,
8,
277,
12,
1245,
304,
267,
327,
2372,
314,
4136,
2787,
315,
314,
3464,
12,
4257,
652,
3955,
267,
327,
506,
642,
805,
21512,
267,
862,
26,
288,
2562,
275,
6485,
14,
1818,
1943,
1252,
70,
63,
894,
14,
70,
63,
600,
288,
327,
19460,
314,
1245,
435,
314,
536,
402,
642,
805,
370,
314,
943,
14,
288,
291,
14,
2921,
14,
815,
6757,
5,
83,
20020,
450,
83,
342,
450,
83,
2689,
73,
2,
450,
334,
355,
1245,
12,
355,
2562,
14,
331,
63,
354,
12,
355,
2562,
14,
331,
63,
1501,
12,
355,
2562,
14,
331,
63,
30114,
288,
5082,
267,
871,
5925,
465,
325,
26,
288,
340,
325,
14,
7931,
508,
7294,
26,
355,
870,
6739,
26287,
2615,
1553,
334,
2786,
12060,
642,
2597,
7859,
1133,
664,
12487,
2685,
339,
347,
3105,
8,
277,
12,
1245,
304,
267,
327,
2372,
314,
4136,
2787,
315,
314,
3464,
12,
4257,
652,
3955,
267,
327,
506,
642,
805,
21512,
267,
862,
26,
288,
2562,
275,
6485,
14,
1818,
1943,
1252,
70,
63,
894,
14,
70,
63,
600,
288,
327,
19460,
314,
1245,
435,
314,
536,
402,
642,
805,
370,
314,
943,
14,
288,
291,
14,
2921,
14,
1757,
6757,
5,
83,
20020,
450,
83,
342,
450,
83,
2689,
73,
2,
450,
334,
355,
1245,
12,
355,
2562,
14,
331,
63,
354,
12,
355,
2562,
14,
331,
63,
1501,
12,
355,
2562,
14,
331,
63,
30114,
288,
5082,
267,
871,
5925,
465,
325,
26,
288,
340,
325,
14,
7931,
508,
7294,
26,
355,
870,
6739,
26287,
2615,
1553,
334,
2786,
12060,
642,
2597,
7859,
1133,
664,
12487,
2685,
339,
347,
1125,
8,
277,
12,
1245,
304,
398,
327,
2372,
314,
4136,
2787,
315,
314,
3464,
12,
4257,
652,
3955,
267,
327,
506,
642,
805,
21512,
398,
862,
26,
288,
2562,
275,
6485,
14,
1818,
1943,
1252,
70,
63,
894,
14,
70,
63,
600,
288,
327,
19460,
314,
1245,
435,
314,
536,
402,
642,
805,
370,
314,
943,
14,
288,
291,
14,
2921,
14,
705,
6757,
5,
83,
20020,
450,
83,
342,
450,
83,
2689,
73,
2,
450,
334,
355,
1245,
12,
355,
2562,
14,
331,
63,
354,
12,
355,
2562,
14,
331,
63,
1501,
12,
355,
2562,
14,
331,
63,
30114,
288,
5082,
953,
291,
14,
2921,
14,
705,
8,
1188,
12,
3178,
63,
815,
29,
17,
9,
398,
871,
5925,
465,
325,
26,
288,
340,
325,
14,
7931,
508,
7294,
26,
355,
870,
6739,
26287,
2615,
1553,
334,
2786,
12060,
642,
2597,
7859,
1133,
664,
12487,
2685,
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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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
] |
azvoleff/chitwanabm
|
chitwanabm/modelloop.py
|
1
|
18907
|
# Copyright 2008-2013 Alex Zvoleff
#
# This file is part of the chitwanabm agent-based model.
#
# chitwanabm 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.
#
# chitwanabm 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
# chitwanabm. If not, see <http://www.gnu.org/licenses/>.
#
# See the README.rst file for author contact information.
"""
Contains main model loop: Contains the main loop for the model. Takes input
parameters read from runmodel.py, and passes results of model run back.
"""
from __future__ import division
import os
import time
import copy
import logging
import numpy as np
from pyabm.file_io import write_NBH_shapefile
from pyabm.utility import TimeSteps
from chitwanabm import rc_params
from chitwanabm import test
logger = logging.getLogger(__name__)
rcParams = rc_params.get_params()
timebounds = rcParams['model.timebounds']
timestep = rcParams['model.timestep']
model_time = TimeSteps(timebounds, timestep)
def main_loop(world, results_path):
"""This function contains the main model loop. Passed to it is a list of
regions, which contains the person, household, and neighborhood agents to
be used in the model, and the land-use parameters."""
if rcParams['run_validation_checks']:
if not test.validate_person_attributes(world):
logger.critical("Person attributes validation failed")
if not test.validate_household_attributes(world):
logger.critical("Household attributes validation failed")
if not test.validate_neighborhood_attributes(world):
logger.critical("Neighborhood attributes validation failed")
time_strings = {}
# Store the date values (as timestep number (0), float and date string)
# for time zero (T0) so that the initial values of the model (which are for
# time zero, the zeroth timestep) can be used in plotting model results.
time_strings['timestep'] = [0]
time_strings['time_float'] = [model_time.get_T0_date_float()]
time_strings['time_date'] = [model_time.get_T0_date_string()]
# Keep annual totals to print while the model is running
annual_num_marr = 0
annual_num_divo = 0
annual_num_births = 0
annual_num_deaths = 0
annual_num_out_migr_LL_indiv = 0
annual_num_ret_migr_LL_indiv = 0
annual_num_out_migr_LD_indiv = 0
annual_num_ret_migr_LD_indiv = 0
annual_num_in_migr_HH = 0
annual_num_out_migr_HH = 0
# Save the starting time of the model to use in printing elapsed time while
# it runs.
modelrun_starttime = time.time()
def write_results_CSV(world, results_path, timestep):
"""
Function to periodically save model results to CSV (if this option is
selected in the rc file).
"""
if rcParams['save_psn_data']:
world.write_persons_to_csv(timestep, results_path)
if rcParams['save_NBH_data']:
world.write_NBHs_to_csv(timestep, results_path)
if rcParams['save_LULC_shapefiles']:
NBH_shapefile = os.path.join(results_path, "NBHs_time_%s.shp"%timestep)
neighborhoods = []
regions = world.get_regions()
for region in regions:
neighborhoods.extend(region.get_agents())
file_io.write_NBH_shapefile(neighborhoods, NBH_shapefile)
# TODO: The below is still a work in progress
# def write_results_netcdf(world, results_path, timestep):
# if rcParams['save_psn_data_netcdf']:
# world.write_persons_to_netcdf(timestep, results_path)
# Write the results for timestep 0
write_results_CSV(world, results_path, 0)
# saved_data will store event, population, and fuelwood usage data keyed by
# timestep:variable:nbh.
saved_data = {}
# Save the initialization data for timestep 0 (note that all the event
# variables, like new_births, new_deaths, etc., need to be set to None
# in each neighborhood, for each variable, as they are unknown for timestep
# 0 (since the model has not yet begun). Need to construct an empty_events
# dictionary to initialize these events for timestep 0.
# TODO: Fix this to work for multiple regions.
region = world.get_regions()[0]
empty_events = {}
EVIs = {}
for neighborhood in region.iter_agents():
empty_events[neighborhood.get_ID()] = np.NaN
EVIs[neighborhood.get_ID()] = neighborhood._EVI
saved_data[0] = {}
saved_data[0]['EVI'] = EVIs
saved_data[0]['births'] = empty_events
saved_data[0]['deaths'] = empty_events
saved_data[0]['marr'] = empty_events
saved_data[0]['divo'] = empty_events
saved_data[0]['out_migr_LL_indiv'] = empty_events
saved_data[0]['ret_migr_LL_indiv'] = empty_events
saved_data[0]['out_migr_LD_indiv'] = empty_events
saved_data[0]['ret_migr_LD_indiv'] = empty_events
saved_data[0]['in_migr_HH'] = empty_events
saved_data[0]['out_migr_HH'] = empty_events
saved_data[0].update(region.get_neighborhood_pop_stats())
saved_data[0].update(region.get_neighborhood_fw_usage(model_time.get_T0_date_float()))
###########################################################################
# Define the result arrays - there will be three arrays stored in a
# dictionary:
# 1) timesteps stores the output
# 2) nbh stores neighborhood level output
# 3) psn stores person level output
results_new_format = {}
timesteps_dtype = [('timestep', 'i2'),
('year', 'i2'),
('month', 'i2'),
('date_float', 'f4')]
results_new_format['timesteps'] = np.zeros((model_time.get_total_num_timesteps()),
dtype=timesteps_dtype)
#TODO: Finish this
nbh_dtype = [('EVI', 'f4'),
('births', 'i2'),
('deaths', 'i2'),
('marr', 'i2'),
('divo', 'i2'),
('out_migr_LL_indiv', 'i2'),
('ret_migr_LL_indiv', 'i2'),
('out_migr_LD_indiv', 'i2'),
('ret_migr_LD_indiv', 'i2'),
('in_migr_HH', 'i2'),
('out_migr_HH', 'i2'),
('num_psn', 'i4'),
('num_hs', 'i2'),
('num_marr', 'i2')]
results_new_format['nbh'] = np.zeros((region.num_members() *
model_time.get_total_num_timesteps()), dtype=nbh_dtype)
#TODO: Finish this
psn_dtype = [('births', 'i2'),
('deaths', 'i2'),
('marr', 'i2'),
('divo', 'i2'),
('out_migr_LL_indiv', 'i2'),
('ret_migr_LL_indiv', 'i2'),
('out_migr_LD_indiv', 'i2'),
('ret_migr_LD_indiv', 'i2'),
('in_migr_HH', 'i2'),
('out_migr_HH', 'i2'),
('num_psn', 'i4'),
('num_hs', 'i2'),
('num_marr', 'i2')]
results_new_format['psn'] = np.zeros((model_time.get_total_num_timesteps()), dtype=psn_dtype)
# Make a dictionary to store empty (zero) event data for submodels if they
# are turned off by the user.
zero_events = {}
for neighborhood in region.iter_agents():
zero_events[neighborhood.get_ID()] = 0
# "Burn in" by running the model for three years in simulated mode, where
# age isn't incremented, but migrations occur. This allows starting the
# model with realistic migration histories, avoiding a huge loss of
# population to migration in the first month of the model.
logger.info('Burning in events for region %s'%region.get_ID())
for neg_timestep in xrange(-rcParams['model.burnin_timesteps'], 0):
for region in world.iter_regions():
if rcParams['submodels.migration_LL_individual']:
new_out_migr_LL_indiv, new_ret_migr_LL_indiv = region.individual_LL_migrations(model_time.get_T_minus_date_float(neg_timestep), neg_timestep, BURN_IN=True)
else: new_out_migr_LL_indiv, new_ret_migr_LL_indiv = zero_events, zero_events
if rcParams['submodels.migration_LD_individual']:
new_out_migr_LD_indiv, new_ret_migr_LD_indiv = region.individual_LD_migrations(model_time.get_T_minus_date_float(neg_timestep), neg_timestep, BURN_IN=True)
else: new_out_migr_LD_indiv, new_ret_migr_LD_indiv = zero_events, zero_events
if rcParams['submodels.fertility']:
new_births = region.births(model_time.get_cur_date_float(), model_time.get_cur_int_timestep(), simulate=True)
else: new_births = zero_events
num_new_births = sum(new_births.values())
num_new_out_migr_LL_indiv = sum(new_out_migr_LL_indiv.values())
num_new_ret_migr_LL_indiv = sum(new_ret_migr_LL_indiv.values())
num_new_out_migr_LD_indiv = sum(new_out_migr_LD_indiv.values())
num_new_ret_migr_LD_indiv = sum(new_ret_migr_LD_indiv.values())
logger.info("Burn in %3s: P: %5s NOLL: %3s NRLL: %3s NOLD: %3s NRLD: %3s NB: %3s"%(neg_timestep,
region.num_persons(), num_new_out_migr_LL_indiv,
num_new_ret_migr_LL_indiv, num_new_out_migr_LD_indiv,
num_new_ret_migr_LD_indiv, num_new_births))
while model_time.in_bounds():
timestep = model_time.get_cur_int_timestep()
results_new_format['timesteps'][timestep - 1] = (timestep,
model_time.get_cur_year(), model_time.get_cur_month(),
model_time.get_cur_date_float())
logger.debug('beginning timestep %s (%s)'%(model_time.get_cur_int_timestep(),
model_time.get_cur_date_string()))
if model_time.get_cur_month() == 1:
annual_num_births = 0
annual_num_deaths = 0
annual_num_marr = 0
annual_num_divo = 0
annual_num_out_migr_LL_indiv = 0
annual_num_ret_migr_LL_indiv = 0
annual_num_out_migr_LD_indiv = 0
annual_num_ret_migr_LD_indiv = 0
annual_num_in_migr_HH = 0
annual_num_out_migr_HH = 0
for region in world.iter_regions():
logger.debug('processing region %s'%region.get_ID())
# This could easily handle multiple regions, although currently
# there is only one, for all of Chitwan.
if rcParams['submodels.fertility']:
new_births = region.births(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_births = zero_events
if rcParams['submodels.mortality']:
new_deaths = region.deaths(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_deaths = zero_events
if rcParams['submodels.marriage']:
new_marr = region.marriages(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_marr = zero_events
if rcParams['submodels.divorce']:
new_divo = region.divorces(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_divo = zero_events
if rcParams['submodels.migration_LL_individual']:
new_out_migr_LL_indiv, new_ret_migr_LL_indiv = region.individual_LL_migrations(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_out_migr_LL_indiv, new_ret_migr_LL_indiv = zero_events, zero_events
if rcParams['submodels.migration_LD_individual']:
new_out_migr_LD_indiv, new_ret_migr_LD_indiv = region.individual_LD_migrations(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_out_migr_LD_indiv, new_ret_migr_LD_indiv = zero_events, zero_events
if rcParams['submodels.migration_household']:
new_in_migr_HH, new_out_migr_HH = region.household_migrations(model_time.get_cur_date_float(), model_time.get_cur_int_timestep())
else: new_in_migr_HH, new_out_migr_HH = zero_events, zero_events
if rcParams['submodels.schooling']:
schooling = region.education(model_time.get_cur_date_float())
else: schooling = zero_events
region.increment_age()
# Now account for changing NFOs (if desired)
if rcParams['NFOs.change.model'].lower() != 'none':
region.establish_NFOs()
# Save event, LULC, and population data in the saved_data dictionary
# for later output to CSV.
saved_data[timestep] = {}
saved_data[timestep]['EVI'] = EVIs
saved_data[timestep]['births'] = new_births
saved_data[timestep]['deaths'] = new_deaths
saved_data[timestep]['marr'] = new_marr
saved_data[timestep]['divo'] = new_divo
saved_data[timestep]['out_migr_LL_indiv'] = new_out_migr_LL_indiv
saved_data[timestep]['ret_migr_LL_indiv'] = new_ret_migr_LL_indiv
saved_data[timestep]['out_migr_LD_indiv'] = new_out_migr_LD_indiv
saved_data[timestep]['ret_migr_LD_indiv'] = new_ret_migr_LD_indiv
saved_data[timestep]['in_migr_HH'] = new_in_migr_HH
saved_data[timestep]['out_migr_HH'] = new_out_migr_HH
saved_data[timestep].update(region.get_neighborhood_pop_stats())
saved_data[timestep].update(region.get_neighborhood_fw_usage(model_time.get_cur_date_float()))
saved_data[timestep].update(region.get_neighborhood_landuse())
saved_data[timestep].update(region.get_neighborhood_nfo_context())
saved_data[timestep].update(region.get_neighborhood_forest_distance())
# Keep running totals of events for printing results:
num_new_births = sum(new_births.values())
num_new_deaths = sum(new_deaths.values())
num_new_marr = sum(new_marr.values())
num_new_divo = sum(new_divo.values())
num_new_out_migr_LL_indiv = sum(new_out_migr_LL_indiv.values())
num_new_ret_migr_LL_indiv = sum(new_ret_migr_LL_indiv.values())
num_new_out_migr_LD_indiv = sum(new_out_migr_LD_indiv.values())
num_new_ret_migr_LD_indiv = sum(new_ret_migr_LD_indiv.values())
num_new_in_migr_HH = sum(new_in_migr_HH.values())
num_new_out_migr_HH = sum(new_out_migr_HH.values())
annual_num_births += num_new_births
annual_num_deaths += num_new_deaths
annual_num_marr += num_new_marr
annual_num_divo += num_new_divo
annual_num_out_migr_LL_indiv += num_new_out_migr_LL_indiv
annual_num_ret_migr_LL_indiv += num_new_ret_migr_LL_indiv
annual_num_out_migr_LD_indiv += num_new_out_migr_LD_indiv
annual_num_ret_migr_LD_indiv += num_new_ret_migr_LD_indiv
annual_num_in_migr_HH += num_new_in_migr_HH
annual_num_out_migr_HH += num_new_out_migr_HH
# Print an information line to allow keeping tabs on the model while it
# is running.
num_persons = region.num_persons()
num_households = region.num_households()
stats_string = "%s: P: %5s TMa: %5s THH: %5s NMa: %3s NDv: %3s NB: %3s ND: %3s NOLL: %3s NRLL: %3s NOLD: %3s NRLD: %3s NOMH: %3s NIMH: %3s"%(
model_time.get_cur_date_string().ljust(7), num_persons,
region.get_num_marriages(), num_households,
num_new_marr, num_new_divo, num_new_births, num_new_deaths,
num_new_out_migr_LL_indiv, num_new_ret_migr_LL_indiv,
num_new_out_migr_LD_indiv, num_new_ret_migr_LD_indiv,
num_new_out_migr_HH, num_new_in_migr_HH)
logger.info('%s'%stats_string)
# Save timestep, year and month, and time_float values for use in
# storing results (to CSV) keyed to a particular timestep.
time_strings['timestep'].append(model_time.get_cur_int_timestep())
time_strings['time_float'].append(model_time.get_cur_date_float())
time_strings['time_date'].append(model_time.get_cur_date_string())
if model_time.get_cur_month() == 12 or model_time.is_last_iteration() \
and model_time.get_cur_date() != model_time._starttime:
# Model this years agricultural productivity, to be used in the
# next year's model runs.
EVIs = region.agricultural_productivity()
mean_NBH_EVI = np.mean(EVIs.values())
mean_Valley_EVI = region._Valley_Mean_EVI
# The last condition in the above if statement is necessary as
# there is no total to print on the first timestep, so it wouldn't
# make sense to print it.
total_string = "%s totals: New Ma: %3s Dv: %3s B: %3s D: %3s LLOutMi: %3s LLRetMi: %3s LDOutMi: %3s LDRetMi: %3s OutMiHH: %3s InMiHH: %3s | NBHEVI: %3s ValEVI: %3s"%(
model_time.get_cur_year(), annual_num_marr,
annual_num_divo, annual_num_births,
annual_num_deaths, annual_num_out_migr_LL_indiv,
annual_num_ret_migr_LL_indiv, annual_num_out_migr_LD_indiv,
annual_num_ret_migr_LD_indiv, annual_num_out_migr_HH,
annual_num_in_migr_HH, mean_NBH_EVI, mean_Valley_EVI)
logger.info('%s'%total_string)
logger.info("Elapsed time: %11s"%elapsed_time(modelrun_starttime))
if rcParams['run_validation_checks']:
if not test.validate_person_attributes(world):
logger.critical("Person attributes validation failed")
if not test.validate_household_attributes(world):
logger.critical("Household attributes validation failed")
if not test.validate_neighborhood_attributes(world):
logger.critical("Neighborhood attributes validation failed")
if num_persons == 0:
logger.info("End of model run: population is zero")
break
if model_time.get_cur_month() == 12 or model_time.is_last_iteration():
write_results_CSV(world, results_path, model_time.get_cur_int_timestep())
model_time.increment()
return saved_data, time_strings, results_new_format
def elapsed_time(start_time):
elapsed = int(time.time() - start_time)
hours = int(elapsed / 3600)
minutes = int((elapsed - hours * 3600) / 60)
seconds = int(elapsed - hours * 3600 - minutes * 60)
return "%ih %im %is" %(hours, minutes, seconds)
|
gpl-3.0
|
[
3,
1898,
9079,
13,
6965,
22986,
3107,
2392,
274,
556,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
314,
682,
390,
20444,
371,
77,
6631,
13,
6788,
1402,
14,
199,
3,
221,
199,
3,
682,
390,
20444,
371,
77,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
199,
3,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
221,
199,
3,
682,
390,
20444,
371,
77,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
2381,
437,
199,
3,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
682,
390,
20444,
371,
77,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
1666,
314,
27781,
14,
8332,
570,
367,
4132,
8966,
2556,
14,
199,
199,
624,
199,
6906,
2446,
1402,
4438,
26,
22493,
314,
2446,
4438,
367,
314,
1402,
14,
17415,
1324,
221,
199,
3214,
1586,
687,
1255,
1238,
14,
647,
12,
436,
14933,
2058,
402,
1402,
1255,
1771,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
747,
199,
646,
900,
199,
646,
1331,
199,
646,
2050,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
1134,
371,
77,
14,
493,
63,
2308,
492,
2218,
63,
16170,
40,
63,
1392,
493,
199,
504,
1134,
371,
77,
14,
16877,
492,
4703,
20960,
199,
199,
504,
682,
390,
20444,
371,
77,
492,
4819,
63,
1162,
199,
504,
682,
390,
20444,
371,
77,
492,
511,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
1195,
6007,
275,
4819,
63,
1162,
14,
362,
63,
1162,
342,
199,
199,
521,
9632,
275,
4819,
6007,
459,
1238,
14,
521,
9632,
418,
199,
521,
2926,
275,
4819,
6007,
459,
1238,
14,
521,
2926,
418,
199,
199,
1238,
63,
521,
275,
4703,
20960,
8,
521,
9632,
12,
900,
2926,
9,
199,
199,
318,
2446,
63,
3813,
8,
7617,
12,
2058,
63,
515,
304,
272,
408,
2765,
805,
3509,
314,
2446,
1402,
4438,
14,
510,
2744,
370,
652,
365,
282,
769,
402,
5591,
16150,
12,
1314,
3509,
314,
4954,
12,
25284,
12239,
12,
436,
15503,
10422,
22867,
370,
5591,
506,
1202,
315,
314,
1402,
12,
436,
314,
20078,
13,
1180,
2633,
1041,
272,
340,
4819,
6007,
459,
1065,
63,
6136,
63,
8625,
2565,
267,
340,
440,
511,
14,
3502,
63,
5484,
63,
2987,
8,
7617,
304,
288,
2512,
14,
13138,
480,
7344,
3004,
6411,
3405,
531,
267,
340,
440,
511,
14,
3502,
63,
6740,
12239,
63,
2987,
8,
7617,
304,
288,
2512,
14,
13138,
480,
40,
7130,
12239,
3004,
6411,
3405,
531,
267,
340,
440,
511,
14,
3502,
63,
13881,
10422,
63,
2987,
8,
7617,
304,
288,
2512,
14,
13138,
480,
13779,
10422,
3004,
6411,
3405,
531,
339,
900,
63,
5465,
275,
1052,
272,
327,
13874,
314,
1434,
1338,
334,
305,
900,
2926,
1329,
334,
16,
395,
221,
2069,
436,
1434,
1059,
9,
5591,
327,
367,
900,
4697,
334,
52,
16,
9,
880,
626,
314,
2536,
1338,
402,
314,
1402,
334,
6777,
787,
367,
5591,
327,
900,
4697,
12,
314,
4697,
273,
900,
2926,
9,
883,
506,
1202,
315,
25174,
1402,
2058,
14,
272,
900,
63,
5465,
459,
521,
2926,
418,
275,
359,
16,
61,
272,
900,
63,
5465,
459,
521,
63,
1609,
418,
275,
359,
1238,
63,
521,
14,
362,
63,
52,
16,
63,
602,
63,
1609,
5106,
272,
900,
63,
5465,
459,
521,
63,
602,
418,
275,
359,
1238,
63,
521,
14,
362,
63,
52,
16,
63,
602,
63,
875,
5106,
339,
327,
14797,
21172,
1061,
23576,
370,
870,
1830,
314,
1402,
365,
3879,
272,
21172,
1061,
63,
1507,
63,
4584,
82,
275,
378,
272,
21172,
1061,
63,
1507,
63,
328,
2392,
275,
378,
272,
21172,
1061,
63,
1507,
63,
10907,
83,
275,
378,
272,
21172,
1061,
63,
1507,
63,
23727,
83,
275,
378,
272,
21172,
1061,
63,
1507,
63,
548,
63,
4071,
82,
63,
4464,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
3292,
63,
4071,
82,
63,
4464,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
548,
63,
4071,
82,
63,
6533,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
3292,
63,
4071,
82,
63,
6533,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
262,
63,
4071,
82,
63,
10213,
275,
378,
272,
21172,
1061,
63,
1507,
63,
548,
63,
4071,
82,
63,
10213,
275,
378,
339,
327,
11063,
314,
6617,
900,
402,
314,
1402,
370,
675,
315,
16116,
14439,
900,
1830,
5591,
327,
652,
7858,
14,
272,
1402,
1065,
63,
32183,
275,
900,
14,
521,
342,
339,
347,
2218,
63,
2604,
63,
19018,
8,
7617,
12,
2058,
63,
515,
12,
900,
2926,
304,
267,
408,
267,
6801,
370,
18745,
1183,
3354,
1402,
2058,
370,
14689,
334,
692,
642,
945,
365,
4960,
4895,
315,
314,
4819,
570,
680,
267,
408,
267,
340,
4819,
6007,
459,
2117,
63,
1190,
78,
63,
576,
2565,
288,
6701,
14,
952,
63,
32146,
63,
475,
63,
4737,
8,
521,
2926,
12,
2058,
63,
515,
9,
267,
340,
4819,
6007,
459,
2117,
63,
16170,
40,
63,
576,
2565,
288,
6701,
14,
952,
63,
16170,
40,
83,
63,
475,
63,
4737,
8,
521,
2926,
12,
2058,
63,
515,
9,
267,
340,
4819,
6007,
459,
2117,
63,
44,
1293,
35,
63,
1392,
1725,
2565,
288,
25377,
40,
63,
1392,
493,
275,
747,
14,
515,
14,
904,
8,
2604,
63,
515,
12,
298,
16170,
40,
83,
63,
521,
4970,
83,
14,
17299,
6808,
521,
2926,
9,
288,
15503,
10422,
83,
275,
942,
288,
16150,
275,
6701,
14,
362,
63,
11963,
342,
288,
367,
4897,
315,
16150,
26,
355,
15503,
10422,
83,
14,
2880,
8,
4551,
14,
362,
63,
14250,
1012,
288,
570,
63,
2308
] |
[
1898,
9079,
13,
6965,
22986,
3107,
2392,
274,
556,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
314,
682,
390,
20444,
371,
77,
6631,
13,
6788,
1402,
14,
199,
3,
221,
199,
3,
682,
390,
20444,
371,
77,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
199,
3,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
199,
3,
221,
199,
3,
682,
390,
20444,
371,
77,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
199,
3,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
2381,
437,
199,
3,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
682,
390,
20444,
371,
77,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
1666,
314,
27781,
14,
8332,
570,
367,
4132,
8966,
2556,
14,
199,
199,
624,
199,
6906,
2446,
1402,
4438,
26,
22493,
314,
2446,
4438,
367,
314,
1402,
14,
17415,
1324,
221,
199,
3214,
1586,
687,
1255,
1238,
14,
647,
12,
436,
14933,
2058,
402,
1402,
1255,
1771,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
747,
199,
646,
900,
199,
646,
1331,
199,
646,
2050,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
1134,
371,
77,
14,
493,
63,
2308,
492,
2218,
63,
16170,
40,
63,
1392,
493,
199,
504,
1134,
371,
77,
14,
16877,
492,
4703,
20960,
199,
199,
504,
682,
390,
20444,
371,
77,
492,
4819,
63,
1162,
199,
504,
682,
390,
20444,
371,
77,
492,
511,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
1195,
6007,
275,
4819,
63,
1162,
14,
362,
63,
1162,
342,
199,
199,
521,
9632,
275,
4819,
6007,
459,
1238,
14,
521,
9632,
418,
199,
521,
2926,
275,
4819,
6007,
459,
1238,
14,
521,
2926,
418,
199,
199,
1238,
63,
521,
275,
4703,
20960,
8,
521,
9632,
12,
900,
2926,
9,
199,
199,
318,
2446,
63,
3813,
8,
7617,
12,
2058,
63,
515,
304,
272,
408,
2765,
805,
3509,
314,
2446,
1402,
4438,
14,
510,
2744,
370,
652,
365,
282,
769,
402,
5591,
16150,
12,
1314,
3509,
314,
4954,
12,
25284,
12239,
12,
436,
15503,
10422,
22867,
370,
5591,
506,
1202,
315,
314,
1402,
12,
436,
314,
20078,
13,
1180,
2633,
1041,
272,
340,
4819,
6007,
459,
1065,
63,
6136,
63,
8625,
2565,
267,
340,
440,
511,
14,
3502,
63,
5484,
63,
2987,
8,
7617,
304,
288,
2512,
14,
13138,
480,
7344,
3004,
6411,
3405,
531,
267,
340,
440,
511,
14,
3502,
63,
6740,
12239,
63,
2987,
8,
7617,
304,
288,
2512,
14,
13138,
480,
40,
7130,
12239,
3004,
6411,
3405,
531,
267,
340,
440,
511,
14,
3502,
63,
13881,
10422,
63,
2987,
8,
7617,
304,
288,
2512,
14,
13138,
480,
13779,
10422,
3004,
6411,
3405,
531,
339,
900,
63,
5465,
275,
1052,
272,
327,
13874,
314,
1434,
1338,
334,
305,
900,
2926,
1329,
334,
16,
395,
221,
2069,
436,
1434,
1059,
9,
5591,
327,
367,
900,
4697,
334,
52,
16,
9,
880,
626,
314,
2536,
1338,
402,
314,
1402,
334,
6777,
787,
367,
5591,
327,
900,
4697,
12,
314,
4697,
273,
900,
2926,
9,
883,
506,
1202,
315,
25174,
1402,
2058,
14,
272,
900,
63,
5465,
459,
521,
2926,
418,
275,
359,
16,
61,
272,
900,
63,
5465,
459,
521,
63,
1609,
418,
275,
359,
1238,
63,
521,
14,
362,
63,
52,
16,
63,
602,
63,
1609,
5106,
272,
900,
63,
5465,
459,
521,
63,
602,
418,
275,
359,
1238,
63,
521,
14,
362,
63,
52,
16,
63,
602,
63,
875,
5106,
339,
327,
14797,
21172,
1061,
23576,
370,
870,
1830,
314,
1402,
365,
3879,
272,
21172,
1061,
63,
1507,
63,
4584,
82,
275,
378,
272,
21172,
1061,
63,
1507,
63,
328,
2392,
275,
378,
272,
21172,
1061,
63,
1507,
63,
10907,
83,
275,
378,
272,
21172,
1061,
63,
1507,
63,
23727,
83,
275,
378,
272,
21172,
1061,
63,
1507,
63,
548,
63,
4071,
82,
63,
4464,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
3292,
63,
4071,
82,
63,
4464,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
548,
63,
4071,
82,
63,
6533,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
3292,
63,
4071,
82,
63,
6533,
63,
262,
3015,
275,
378,
272,
21172,
1061,
63,
1507,
63,
262,
63,
4071,
82,
63,
10213,
275,
378,
272,
21172,
1061,
63,
1507,
63,
548,
63,
4071,
82,
63,
10213,
275,
378,
339,
327,
11063,
314,
6617,
900,
402,
314,
1402,
370,
675,
315,
16116,
14439,
900,
1830,
5591,
327,
652,
7858,
14,
272,
1402,
1065,
63,
32183,
275,
900,
14,
521,
342,
339,
347,
2218,
63,
2604,
63,
19018,
8,
7617,
12,
2058,
63,
515,
12,
900,
2926,
304,
267,
408,
267,
6801,
370,
18745,
1183,
3354,
1402,
2058,
370,
14689,
334,
692,
642,
945,
365,
4960,
4895,
315,
314,
4819,
570,
680,
267,
408,
267,
340,
4819,
6007,
459,
2117,
63,
1190,
78,
63,
576,
2565,
288,
6701,
14,
952,
63,
32146,
63,
475,
63,
4737,
8,
521,
2926,
12,
2058,
63,
515,
9,
267,
340,
4819,
6007,
459,
2117,
63,
16170,
40,
63,
576,
2565,
288,
6701,
14,
952,
63,
16170,
40,
83,
63,
475,
63,
4737,
8,
521,
2926,
12,
2058,
63,
515,
9,
267,
340,
4819,
6007,
459,
2117,
63,
44,
1293,
35,
63,
1392,
1725,
2565,
288,
25377,
40,
63,
1392,
493,
275,
747,
14,
515,
14,
904,
8,
2604,
63,
515,
12,
298,
16170,
40,
83,
63,
521,
4970,
83,
14,
17299,
6808,
521,
2926,
9,
288,
15503,
10422,
83,
275,
942,
288,
16150,
275,
6701,
14,
362,
63,
11963,
342,
288,
367,
4897,
315,
16150,
26,
355,
15503,
10422,
83,
14,
2880,
8,
4551,
14,
362,
63,
14250,
1012,
288,
570,
63,
2308,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
1
|
5813
|
#!/usr/bin/env python
"""This program inputs a MemberHub directory dump, and analyzes it.
"""
import family
import roster
import os
from openpyxl import load_workbook
MIN_NUM_ROSTER_FIELDS = 5
def ReadRosterAdultsFromMostRecent(file_name=None):
""" roster_tools.ReadRosterAdultsFromMostRecent
PURPOSE:
Generates a list of adult names in the newest roster file.
INPUT:
- none
OUTPUTS:
- adults_list -- list of adult name fields in the newest roster file.
ASSUMPTIONS:
- none
"""
##
## Find the files in the "Roster" folder with ".xlsx" extension, sort them by
## date, and pick the most recently added
if not file_name:
file_path = os.path.abspath("./Roster/")
with os.scandir(file_path) as raw_files:
files = [file for file in raw_files \
if not(file.name.startswith('~')) and (file.name.endswith('.xlsx'))]
files.sort(key=lambda x: os.stat(x).st_mtime, reverse=True)
file_name = file_path + "/" +files[0].name
##
## Load the workbook, and select the active/only worksheet
wb = load_workbook(file_name)
ws = wb.active
##
## Copy all the values in column 'D' for all rows beyond the title row into
## the output list
adults_list = []
for fields in ws.iter_rows(min_row=2, max_row=ws.max_row, min_col=4, max_col=4):
adults_list.append(fields[0].value)
return adults_list
def ReadRosterFromFile(file_name, hub_map, rosterC):
""" roster_tools.ReadRosterFromFile
PURPOSE:
Reads a roster file with the following fields:
<**Last Name>,<**First Name>,<**Grade>,<**Parent/Guardian Name(s)>,<***Teacher Name>
** - indicates always required field
*** - indicates field that is required when Grade field is < 6
INPUT:
- file_name -- name of the roster file
- hub_map -- dictionary that maps hub names to hub IDs
- rosterC -- the Roster object containing the errata
OUTPUTS:
- roster -- list of families extracted from the roster
ASSUMPTIONS:
1. First row of the file is the column headers...not a member of the roster.
"""
wb = load_workbook(file_name)
ws = wb.active
student_count = -1
for fields in ws.values:
## Skip the first row
if student_count < 0:
student_count = 0
continue
## Skip any row for which all fields are not populated
empty_field_found = False
for i in range(MIN_NUM_ROSTER_FIELDS):
if fields[i] == None or fields[i] == "":
empty_field_found = True
print("Found row with missing required fields:", fields)
break
if empty_field_found:
continue
## each row represents one student
student_count += 1
## treat the student as a member of a new family...for now
new_family = family.RosterFamily(adults_raw_name=fields[3])
new_family.AddToFamily(child_first = fields[1],
child_last = fields[0],
grade = fields[2],
adult_names = fields[3],
teacher_name = fields[4],
hub_map = hub_map,
rosterC = rosterC)
# if new_family is the same as a family already in the roster, then combine
# families. Otherwise, append new_family at the end of the roster.
for roster_entry in rosterC.GetRoster():
if roster_entry.IsSameFamily(new_family):
roster_entry.CombineWith(new_family)
break
else:
rosterC.append(new_family)
print("%d students processed %d families." % (student_count, len(rosterC)))
return rosterC.GetRoster()
def GetRosterFileName():
""" roster_tools.GetRosterFileName
PURPOSE:
Gives the user a list of possible roster files, and processes their selection.
INPUTS:
None
OUTPUTS:
- file_name - the selected roster file name
ASSUMPTIONS:
- Assumes the candidate roster files are stored in a subfolder called 'Roster'
"""
print ("These are the potential roster files:")
file_path = os.path.abspath("./Roster/")
with os.scandir(file_path) as raw_files:
files = [file for file in raw_files \
if not(file.name.startswith('~')) and (file.name.endswith('.xlsx'))]
files.sort(key=lambda x: os.stat(x).st_mtime, reverse=True)
max_index = 0
file_number = '1'
while int(file_number) >= max_index:
for file in files:
max_index += 1
print("%d) %s" % (max_index, file.name))
file_number = input("Enter list number of file or press <enter> to use '" + files[0].name + "':")
if not file_number:
return file_path + "/" +files[0].name
elif 0 < int(file_number) <= max_index:
return file_path + "/" + files[int(file_number)-1].name
else:
max_index = 0
print("The selection made is out of range. Please try again.")
def ReadRoster(hub_map):
""" roster_tools.ReadRoster
PURPOSE:
Prompts the user for roster file name and proceeds to read the file.
INPUT:
- hub_map -- mapping of teacher names to hub numbers
OUTPUTS:
- roster -- list of families extracted from the roster
ASSUMPTIONS:
- All the candidate rosters reside in a folder called "Roster" under the
run directory.
- All candidate rosters are Microsoft Excel files.
"""
return ReadRosterFromFile(GetRosterFileName(), hub_map, roster.Roster())
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
2765,
2240,
4153,
282,
14409,
15338,
2082,
5461,
12,
436,
5909,
90,
397,
652,
14,
199,
624,
199,
646,
9614,
199,
646,
882,
11652,
199,
646,
747,
199,
504,
1551,
647,
15455,
492,
2248,
63,
30765,
199,
199,
4896,
63,
7125,
63,
1092,
14471,
63,
12767,
275,
959,
199,
199,
318,
5574,
50,
29895,
2767,
427,
83,
2532,
24625,
29574,
8,
493,
63,
354,
29,
403,
304,
272,
408,
882,
11652,
63,
2537,
14,
3284,
50,
29895,
2767,
427,
83,
2532,
24625,
29574,
272,
3104,
26,
272,
21687,
282,
769,
402,
1503,
427,
1561,
315,
314,
29608,
882,
11652,
570,
14,
272,
21955,
26,
272,
446,
7179,
272,
18746,
51,
26,
272,
446,
1503,
427,
83,
63,
513,
1553,
769,
402,
1503,
427,
536,
1504,
315,
314,
29608,
882,
11652,
570,
14,
272,
17567,
22759,
52,
2823,
26,
272,
446,
7179,
272,
408,
272,
925,
272,
925,
6668,
314,
1584,
315,
314,
298,
50,
29895,
2,
4922,
543,
3680,
19023,
88,
2,
3329,
12,
4069,
3062,
701,
272,
925,
1434,
12,
436,
3732,
314,
4750,
23568,
3483,
272,
340,
440,
570,
63,
354,
26,
267,
570,
63,
515,
275,
747,
14,
515,
14,
4832,
28615,
50,
29895,
13589,
267,
543,
747,
14,
6282,
694,
8,
493,
63,
515,
9,
465,
3066,
63,
1725,
26,
288,
1584,
275,
359,
493,
367,
570,
315,
3066,
63,
1725,
971,
717,
340,
440,
8,
493,
14,
354,
14,
2460,
21114,
1333,
436,
334,
493,
14,
354,
14,
4130,
5175,
19023,
88,
27738,
288,
1584,
14,
3191,
8,
498,
29,
2734,
671,
26,
747,
14,
3736,
8,
88,
680,
270,
63,
8180,
12,
3837,
29,
549,
9,
288,
570,
63,
354,
275,
570,
63,
515,
435,
10609,
435,
1725,
59,
16,
1055,
354,
2286,
925,
272,
925,
7190,
314,
1736,
2706,
12,
436,
3504,
314,
4702,
15,
2118,
21127,
272,
336,
66,
275,
2248,
63,
30765,
8,
493,
63,
354,
9,
272,
10900,
275,
336,
66,
14,
2682,
272,
925,
272,
925,
11247,
1006,
314,
1338,
315,
2763,
283,
36,
7,
367,
1006,
4730,
20561,
314,
2538,
1962,
1901,
272,
925,
314,
1072,
769,
272,
1503,
427,
83,
63,
513,
275,
942,
272,
367,
1504,
315,
10900,
14,
1661,
63,
3838,
8,
827,
63,
1143,
29,
18,
12,
1390,
63,
1143,
29,
3569,
14,
988,
63,
1143,
12,
1748,
63,
761,
29,
20,
12,
1390,
63,
761,
29,
20,
304,
267,
1503,
427,
83,
63,
513,
14,
740,
8,
955,
59,
16,
1055,
585,
9,
5493,
372,
1503,
427,
83,
63,
513,
421,
199,
318,
5574,
50,
29895,
26637,
8,
493,
63,
354,
12,
26726,
63,
1130,
12,
882,
11652,
35,
304,
272,
408,
882,
11652,
63,
2537,
14,
3284,
50,
29895,
26637,
272,
3104,
26,
272,
26129,
282,
882,
11652,
570,
543,
314,
2569,
1504,
26,
272,
665,
538,
6090,
2812,
32659,
538,
7147,
2812,
32659,
538,
5761,
271,
32659,
538,
6652,
15,
11548,
31186,
2812,
8,
83,
9,
32659,
9153,
6301,
19728,
2812,
30,
272,
1011,
221,
446,
9126,
3544,
1415,
901,
272,
19688,
446,
9126,
901,
626,
365,
1415,
1380,
10268,
271,
901,
365,
665,
1227,
272,
21955,
26,
272,
446,
570,
63,
354,
1553,
536,
402,
314,
882,
11652,
570,
272,
446,
26726,
63,
1130,
257,
1553,
2600,
626,
9033,
26726,
1561,
370,
26726,
11449,
272,
446,
882,
11652,
35,
257,
1553,
314,
820,
29895,
909,
3035,
314,
2329,
419,
272,
18746,
51,
26,
272,
446,
882,
11652,
259,
1553,
769,
402,
21450,
20111,
12509,
687,
314,
882,
11652,
272,
17567,
22759,
52,
2823,
26,
272,
413,
14,
7758,
1962,
402,
314,
570,
365,
314,
2763,
2323,
1396,
1397,
282,
3653,
402,
314,
882,
11652,
14,
272,
408,
272,
336,
66,
3322,
275,
2248,
63,
30765,
8,
493,
63,
354,
9,
272,
10900,
3322,
275,
336,
66,
14,
2682,
272,
6474,
63,
835,
275,
446,
17,
339,
367,
1504,
315,
10900,
14,
1459,
26,
398,
925,
8232,
314,
1642,
1962,
267,
340,
6474,
63,
835,
665,
378,
26,
288,
6474,
63,
835,
275,
378,
288,
1980,
398,
925,
8232,
1263,
1962,
367,
1314,
1006,
1504,
787,
440,
16460,
267,
2701,
63,
698,
63,
4214,
275,
756,
267,
367,
284,
315,
1425,
8,
4896,
63,
7125,
63,
1092,
14471,
63,
12767,
304,
288,
340,
1504,
59,
73,
61,
508,
488,
503,
1504,
59,
73,
61,
508,
10812,
355,
2701,
63,
698,
63,
4214,
275,
715,
355,
870,
480,
3601,
1962,
543,
4124,
1415,
1504,
6783,
1504,
9,
355,
2059,
267,
340,
2701,
63,
698,
63,
4214,
26,
288,
1980,
398,
925,
1924,
1962,
8469,
1373,
6474,
267,
6474,
63,
835,
847,
413,
398,
925,
14312,
314,
6474,
465,
282,
3653,
402,
282,
892,
9614,
1396,
509,
3063,
267,
892,
63,
6606,
275,
9614,
14,
50,
29895,
16345,
8,
350,
427,
83,
63,
1773,
63,
354,
29,
955,
59,
19,
566,
267,
892,
63,
6606,
14,
1123,
1378,
16345,
8,
1739,
63,
2246,
221,
275,
1504,
59,
17,
467,
3044,
1982,
63,
2019,
257,
275,
1504,
59,
16,
467,
3044,
16183,
263,
275,
1504,
59,
18,
467,
3044,
1503,
427,
63,
1247,
221,
275,
1504,
59,
19,
467,
3044,
1565,
19728,
63,
354,
275,
1504,
59,
20,
467,
3044,
26726,
63,
1130,
420,
275,
26726,
63,
1130,
12,
3044,
882,
11652,
35,
420,
275,
882,
11652,
35,
9,
398,
327,
340,
892,
63,
6606,
365,
314,
2011,
465,
282,
9614,
2575,
315,
314,
882,
11652,
12,
2066,
13323,
267,
327,
21450,
20111,
14,
221,
6630,
12,
5666,
892,
63,
6606,
737,
314,
1284,
402,
314,
882,
11652,
14,
267,
367,
882,
11652,
63,
2373,
315,
882,
11652,
35,
14,
1002,
50,
29895,
837,
288,
340,
882,
11652,
63,
2373,
14,
1831,
8479,
16345,
8,
1222,
63,
6606,
304,
355,
882,
11652,
63,
2373,
14,
23163,
3007,
8,
1222,
63,
6606,
9,
355,
2059,
267,
587,
26,
288,
882,
11652,
35,
14,
740,
8,
1222,
63,
6606,
9,
339,
870,
3647,
68,
18557,
7686,
450,
68,
21450,
20111,
2122,
450,
334,
5500,
63,
835,
12,
822,
8,
4796,
351,
35,
1724,
339,
372,
882,
11652,
35,
14,
1002,
50,
29895,
342,
421,
199,
318,
2372,
50,
29895,
7733,
837
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
2765,
2240,
4153,
282,
14409,
15338,
2082,
5461,
12,
436,
5909,
90,
397,
652,
14,
199,
624,
199,
646,
9614,
199,
646,
882,
11652,
199,
646,
747,
199,
504,
1551,
647,
15455,
492,
2248,
63,
30765,
199,
199,
4896,
63,
7125,
63,
1092,
14471,
63,
12767,
275,
959,
199,
199,
318,
5574,
50,
29895,
2767,
427,
83,
2532,
24625,
29574,
8,
493,
63,
354,
29,
403,
304,
272,
408,
882,
11652,
63,
2537,
14,
3284,
50,
29895,
2767,
427,
83,
2532,
24625,
29574,
272,
3104,
26,
272,
21687,
282,
769,
402,
1503,
427,
1561,
315,
314,
29608,
882,
11652,
570,
14,
272,
21955,
26,
272,
446,
7179,
272,
18746,
51,
26,
272,
446,
1503,
427,
83,
63,
513,
1553,
769,
402,
1503,
427,
536,
1504,
315,
314,
29608,
882,
11652,
570,
14,
272,
17567,
22759,
52,
2823,
26,
272,
446,
7179,
272,
408,
272,
925,
272,
925,
6668,
314,
1584,
315,
314,
298,
50,
29895,
2,
4922,
543,
3680,
19023,
88,
2,
3329,
12,
4069,
3062,
701,
272,
925,
1434,
12,
436,
3732,
314,
4750,
23568,
3483,
272,
340,
440,
570,
63,
354,
26,
267,
570,
63,
515,
275,
747,
14,
515,
14,
4832,
28615,
50,
29895,
13589,
267,
543,
747,
14,
6282,
694,
8,
493,
63,
515,
9,
465,
3066,
63,
1725,
26,
288,
1584,
275,
359,
493,
367,
570,
315,
3066,
63,
1725,
971,
717,
340,
440,
8,
493,
14,
354,
14,
2460,
21114,
1333,
436,
334,
493,
14,
354,
14,
4130,
5175,
19023,
88,
27738,
288,
1584,
14,
3191,
8,
498,
29,
2734,
671,
26,
747,
14,
3736,
8,
88,
680,
270,
63,
8180,
12,
3837,
29,
549,
9,
288,
570,
63,
354,
275,
570,
63,
515,
435,
10609,
435,
1725,
59,
16,
1055,
354,
2286,
925,
272,
925,
7190,
314,
1736,
2706,
12,
436,
3504,
314,
4702,
15,
2118,
21127,
272,
336,
66,
275,
2248,
63,
30765,
8,
493,
63,
354,
9,
272,
10900,
275,
336,
66,
14,
2682,
272,
925,
272,
925,
11247,
1006,
314,
1338,
315,
2763,
283,
36,
7,
367,
1006,
4730,
20561,
314,
2538,
1962,
1901,
272,
925,
314,
1072,
769,
272,
1503,
427,
83,
63,
513,
275,
942,
272,
367,
1504,
315,
10900,
14,
1661,
63,
3838,
8,
827,
63,
1143,
29,
18,
12,
1390,
63,
1143,
29,
3569,
14,
988,
63,
1143,
12,
1748,
63,
761,
29,
20,
12,
1390,
63,
761,
29,
20,
304,
267,
1503,
427,
83,
63,
513,
14,
740,
8,
955,
59,
16,
1055,
585,
9,
5493,
372,
1503,
427,
83,
63,
513,
421,
199,
318,
5574,
50,
29895,
26637,
8,
493,
63,
354,
12,
26726,
63,
1130,
12,
882,
11652,
35,
304,
272,
408,
882,
11652,
63,
2537,
14,
3284,
50,
29895,
26637,
272,
3104,
26,
272,
26129,
282,
882,
11652,
570,
543,
314,
2569,
1504,
26,
272,
665,
538,
6090,
2812,
32659,
538,
7147,
2812,
32659,
538,
5761,
271,
32659,
538,
6652,
15,
11548,
31186,
2812,
8,
83,
9,
32659,
9153,
6301,
19728,
2812,
30,
272,
1011,
221,
446,
9126,
3544,
1415,
901,
272,
19688,
446,
9126,
901,
626,
365,
1415,
1380,
10268,
271,
901,
365,
665,
1227,
272,
21955,
26,
272,
446,
570,
63,
354,
1553,
536,
402,
314,
882,
11652,
570,
272,
446,
26726,
63,
1130,
257,
1553,
2600,
626,
9033,
26726,
1561,
370,
26726,
11449,
272,
446,
882,
11652,
35,
257,
1553,
314,
820,
29895,
909,
3035,
314,
2329,
419,
272,
18746,
51,
26,
272,
446,
882,
11652,
259,
1553,
769,
402,
21450,
20111,
12509,
687,
314,
882,
11652,
272,
17567,
22759,
52,
2823,
26,
272,
413,
14,
7758,
1962,
402,
314,
570,
365,
314,
2763,
2323,
1396,
1397,
282,
3653,
402,
314,
882,
11652,
14,
272,
408,
272,
336,
66,
3322,
275,
2248,
63,
30765,
8,
493,
63,
354,
9,
272,
10900,
3322,
275,
336,
66,
14,
2682,
272,
6474,
63,
835,
275,
446,
17,
339,
367,
1504,
315,
10900,
14,
1459,
26,
398,
925,
8232,
314,
1642,
1962,
267,
340,
6474,
63,
835,
665,
378,
26,
288,
6474,
63,
835,
275,
378,
288,
1980,
398,
925,
8232,
1263,
1962,
367,
1314,
1006,
1504,
787,
440,
16460,
267,
2701,
63,
698,
63,
4214,
275,
756,
267,
367,
284,
315,
1425,
8,
4896,
63,
7125,
63,
1092,
14471,
63,
12767,
304,
288,
340,
1504,
59,
73,
61,
508,
488,
503,
1504,
59,
73,
61,
508,
10812,
355,
2701,
63,
698,
63,
4214,
275,
715,
355,
870,
480,
3601,
1962,
543,
4124,
1415,
1504,
6783,
1504,
9,
355,
2059,
267,
340,
2701,
63,
698,
63,
4214,
26,
288,
1980,
398,
925,
1924,
1962,
8469,
1373,
6474,
267,
6474,
63,
835,
847,
413,
398,
925,
14312,
314,
6474,
465,
282,
3653,
402,
282,
892,
9614,
1396,
509,
3063,
267,
892,
63,
6606,
275,
9614,
14,
50,
29895,
16345,
8,
350,
427,
83,
63,
1773,
63,
354,
29,
955,
59,
19,
566,
267,
892,
63,
6606,
14,
1123,
1378,
16345,
8,
1739,
63,
2246,
221,
275,
1504,
59,
17,
467,
3044,
1982,
63,
2019,
257,
275,
1504,
59,
16,
467,
3044,
16183,
263,
275,
1504,
59,
18,
467,
3044,
1503,
427,
63,
1247,
221,
275,
1504,
59,
19,
467,
3044,
1565,
19728,
63,
354,
275,
1504,
59,
20,
467,
3044,
26726,
63,
1130,
420,
275,
26726,
63,
1130,
12,
3044,
882,
11652,
35,
420,
275,
882,
11652,
35,
9,
398,
327,
340,
892,
63,
6606,
365,
314,
2011,
465,
282,
9614,
2575,
315,
314,
882,
11652,
12,
2066,
13323,
267,
327,
21450,
20111,
14,
221,
6630,
12,
5666,
892,
63,
6606,
737,
314,
1284,
402,
314,
882,
11652,
14,
267,
367,
882,
11652,
63,
2373,
315,
882,
11652,
35,
14,
1002,
50,
29895,
837,
288,
340,
882,
11652,
63,
2373,
14,
1831,
8479,
16345,
8,
1222,
63,
6606,
304,
355,
882,
11652,
63,
2373,
14,
23163,
3007,
8,
1222,
63,
6606,
9,
355,
2059,
267,
587,
26,
288,
882,
11652,
35,
14,
740,
8,
1222,
63,
6606,
9,
339,
870,
3647,
68,
18557,
7686,
450,
68,
21450,
20111,
2122,
450,
334,
5500,
63,
835,
12,
822,
8,
4796,
351,
35,
1724,
339,
372,
882,
11652,
35,
14,
1002,
50,
29895,
342,
421,
199,
318,
2372,
50,
29895,
7733,
837,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
SamWhited/photoREPL
|
photorepl/views/preview.py
|
2
|
1876
|
import os
from gi.repository import Gtk, GdkPixbuf
from photorepl import app_name
from threading import Lock
class Preview(Gtk.Window):
"""
The preview window, which shows photos as you edit them.
"""
def __init__(self, filename=None, rawfile=None, show=True):
super().__init__()
self.set_wmclass(app_name, app_name)
self.rawfile = rawfile
self.set_title(app_name)
self.set_default_size(800, 600)
self.settings = Gtk.Settings.get_default()
try:
self.settings.set_property(
'gtk-application-prefer-dark-theme',
True
)
except TypeError:
# Can't do this if we're using pgi for some reason.
pass
self.box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
self.mutex = Lock()
if filename is not None:
self.render_photo(filename)
self.add(self.box)
if show:
self.show_all()
def set_title(self, title):
"""
Sets the title of the preview window.
"""
if self.rawfile is None:
super().set_title(title)
else:
super().set_title('{} — {}'.format(
title,
os.path.basename(self.rawfile)
))
def render_photo(self, filename):
"""
Renders the given photo (generally in PGM format) in the preview
window.
"""
self.mutex.acquire()
self.set_title(app_name)
try:
self.box.remove(self.image)
except AttributeError:
pass
pix = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, 800, 600)
self.image = Gtk.Image.new_from_pixbuf(pix)
self.box.pack_start(self.image, True, True, 0)
self.show_all()
self.mutex.release()
|
bsd-2-clause
|
[
646,
747,
199,
199,
504,
18895,
14,
8421,
492,
11424,
12,
31392,
25747,
1436,
199,
504,
3945,
357,
720,
1168,
492,
1145,
63,
354,
199,
504,
5796,
492,
15536,
421,
199,
533,
5543,
1345,
8,
18891,
14,
4301,
304,
339,
408,
272,
710,
19653,
4353,
12,
1314,
13703,
3945,
17278,
465,
1265,
5283,
3062,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1788,
29,
403,
12,
3066,
493,
29,
403,
12,
2498,
29,
549,
304,
267,
1613,
11027,
826,
4533,
398,
291,
14,
409,
63,
16240,
533,
8,
571,
63,
354,
12,
1145,
63,
354,
9,
267,
291,
14,
1773,
493,
275,
3066,
493,
267,
291,
14,
409,
63,
1213,
8,
571,
63,
354,
9,
267,
291,
14,
409,
63,
885,
63,
890,
8,
6718,
12,
11624,
9,
398,
291,
14,
1751,
275,
11424,
14,
5268,
14,
362,
63,
885,
342,
398,
862,
26,
288,
291,
14,
1751,
14,
409,
63,
1829,
8,
355,
283,
12275,
13,
3578,
13,
24283,
13,
13625,
13,
7915,
297,
355,
715,
288,
776,
267,
871,
3146,
26,
288,
327,
6855,
1133,
886,
642,
340,
781,
3984,
1808,
299,
6153,
367,
2005,
4499,
14,
288,
986,
398,
291,
14,
1977,
275,
11424,
14,
3532,
14,
1222,
8,
18891,
14,
27536,
14,
25968,
12,
378,
9,
398,
291,
14,
19078,
275,
15536,
342,
398,
340,
1788,
365,
440,
488,
26,
288,
291,
14,
3352,
63,
13834,
8,
1501,
9,
398,
291,
14,
525,
8,
277,
14,
1977,
9,
398,
340,
2498,
26,
288,
291,
14,
2384,
63,
452,
342,
339,
347,
663,
63,
1213,
8,
277,
12,
2538,
304,
267,
408,
267,
10729,
314,
2538,
402,
314,
19653,
4353,
14,
267,
408,
398,
340,
291,
14,
1773,
493,
365,
488,
26,
288,
1613,
1252,
409,
63,
1213,
8,
1213,
9,
267,
587,
26,
288,
1613,
1252,
409,
63,
1213,
17519,
221,
20292,
9499,
908,
8,
355,
2538,
12,
355,
747,
14,
515,
14,
4846,
8,
277,
14,
1773,
493,
9,
288,
5082,
339,
347,
3795,
63,
13834,
8,
277,
12,
1788,
304,
267,
408,
267,
10055,
7735,
314,
1627,
19397,
334,
2038,
1183,
315,
510,
22636,
1475,
9,
315,
314,
19653,
267,
4353,
14,
267,
408,
398,
291,
14,
19078,
14,
8174,
342,
398,
291,
14,
409,
63,
1213,
8,
571,
63,
354,
9,
398,
862,
26,
288,
291,
14,
1977,
14,
2168,
8,
277,
14,
1569,
9,
267,
871,
4281,
26,
288,
986,
398,
25505,
275,
31392,
25747,
1436,
14,
25747,
1436,
14,
1222,
63,
504,
63,
493,
63,
292,
63,
890,
8,
1501,
12,
23466,
12,
11624,
9,
267,
291,
14,
1569,
275,
11424,
14,
3491,
14,
1222,
63,
504,
63,
25740,
8,
6644,
9,
267,
291,
14,
1977,
14,
1389,
63,
928,
8,
277,
14,
1569,
12,
715,
12,
715,
12,
378,
9,
267,
291,
14,
2384,
63,
452,
342,
398,
291,
14,
19078,
14,
3221,
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
] |
[
747,
199,
199,
504,
18895,
14,
8421,
492,
11424,
12,
31392,
25747,
1436,
199,
504,
3945,
357,
720,
1168,
492,
1145,
63,
354,
199,
504,
5796,
492,
15536,
421,
199,
533,
5543,
1345,
8,
18891,
14,
4301,
304,
339,
408,
272,
710,
19653,
4353,
12,
1314,
13703,
3945,
17278,
465,
1265,
5283,
3062,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1788,
29,
403,
12,
3066,
493,
29,
403,
12,
2498,
29,
549,
304,
267,
1613,
11027,
826,
4533,
398,
291,
14,
409,
63,
16240,
533,
8,
571,
63,
354,
12,
1145,
63,
354,
9,
267,
291,
14,
1773,
493,
275,
3066,
493,
267,
291,
14,
409,
63,
1213,
8,
571,
63,
354,
9,
267,
291,
14,
409,
63,
885,
63,
890,
8,
6718,
12,
11624,
9,
398,
291,
14,
1751,
275,
11424,
14,
5268,
14,
362,
63,
885,
342,
398,
862,
26,
288,
291,
14,
1751,
14,
409,
63,
1829,
8,
355,
283,
12275,
13,
3578,
13,
24283,
13,
13625,
13,
7915,
297,
355,
715,
288,
776,
267,
871,
3146,
26,
288,
327,
6855,
1133,
886,
642,
340,
781,
3984,
1808,
299,
6153,
367,
2005,
4499,
14,
288,
986,
398,
291,
14,
1977,
275,
11424,
14,
3532,
14,
1222,
8,
18891,
14,
27536,
14,
25968,
12,
378,
9,
398,
291,
14,
19078,
275,
15536,
342,
398,
340,
1788,
365,
440,
488,
26,
288,
291,
14,
3352,
63,
13834,
8,
1501,
9,
398,
291,
14,
525,
8,
277,
14,
1977,
9,
398,
340,
2498,
26,
288,
291,
14,
2384,
63,
452,
342,
339,
347,
663,
63,
1213,
8,
277,
12,
2538,
304,
267,
408,
267,
10729,
314,
2538,
402,
314,
19653,
4353,
14,
267,
408,
398,
340,
291,
14,
1773,
493,
365,
488,
26,
288,
1613,
1252,
409,
63,
1213,
8,
1213,
9,
267,
587,
26,
288,
1613,
1252,
409,
63,
1213,
17519,
221,
20292,
9499,
908,
8,
355,
2538,
12,
355,
747,
14,
515,
14,
4846,
8,
277,
14,
1773,
493,
9,
288,
5082,
339,
347,
3795,
63,
13834,
8,
277,
12,
1788,
304,
267,
408,
267,
10055,
7735,
314,
1627,
19397,
334,
2038,
1183,
315,
510,
22636,
1475,
9,
315,
314,
19653,
267,
4353,
14,
267,
408,
398,
291,
14,
19078,
14,
8174,
342,
398,
291,
14,
409,
63,
1213,
8,
571,
63,
354,
9,
398,
862,
26,
288,
291,
14,
1977,
14,
2168,
8,
277,
14,
1569,
9,
267,
871,
4281,
26,
288,
986,
398,
25505,
275,
31392,
25747,
1436,
14,
25747,
1436,
14,
1222,
63,
504,
63,
493,
63,
292,
63,
890,
8,
1501,
12,
23466,
12,
11624,
9,
267,
291,
14,
1569,
275,
11424,
14,
3491,
14,
1222,
63,
504,
63,
25740,
8,
6644,
9,
267,
291,
14,
1977,
14,
1389,
63,
928,
8,
277,
14,
1569,
12,
715,
12,
715,
12,
378,
9,
267,
291,
14,
2384,
63,
452,
342,
398,
291,
14,
19078,
14,
3221,
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,
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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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
marcoantoniooliveira/labweb
|
oscar/lib/python2.7/site-packages/setuptools/command/egg_info.py
|
215
|
14320
|
"""setuptools.command.egg_info
Create a distribution's .egg-info directory and contents"""
import os
import re
import sys
from setuptools import Command
import distutils.errors
from distutils import log
from setuptools.command.sdist import sdist
from setuptools.compat import basestring
from setuptools import svn_utils
from distutils.util import convert_path
from distutils.filelist import FileList as _FileList
from pkg_resources import (parse_requirements, safe_name, parse_version,
safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename)
from setuptools.command.sdist import walk_revctrl
class egg_info(Command):
description = "create a distribution's .egg-info directory"
user_options = [
('egg-base=', 'e', "directory containing .egg-info directories"
" (default: top of the source tree)"),
('tag-svn-revision', 'r',
"Add subversion revision ID to version number"),
('tag-date', 'd', "Add date stamp (e.g. 20050528) to version number"),
('tag-build=', 'b', "Specify explicit tag to add to version number"),
('no-svn-revision', 'R',
"Don't add subversion revision ID [default]"),
('no-date', 'D', "Don't include date stamp [default]"),
]
boolean_options = ['tag-date', 'tag-svn-revision']
negative_opt = {'no-svn-revision': 'tag-svn-revision',
'no-date': 'tag-date'}
def initialize_options(self):
self.egg_name = None
self.egg_version = None
self.egg_base = None
self.egg_info = None
self.tag_build = None
self.tag_svn_revision = 0
self.tag_date = 0
self.broken_egg_info = False
self.vtags = None
def save_version_info(self, filename):
from setuptools.command.setopt import edit_config
values = dict(
egg_info=dict(
tag_svn_revision=0,
tag_date=0,
tag_build=self.tags(),
)
)
edit_config(filename, values)
def finalize_options(self):
self.egg_name = safe_name(self.distribution.get_name())
self.vtags = self.tags()
self.egg_version = self.tagged_version()
try:
list(
parse_requirements('%s==%s' % (self.egg_name,self.egg_version))
)
except ValueError:
raise distutils.errors.DistutilsOptionError(
"Invalid distribution name or version syntax: %s-%s" %
(self.egg_name,self.egg_version)
)
if self.egg_base is None:
dirs = self.distribution.package_dir
self.egg_base = (dirs or {}).get('',os.curdir)
self.ensure_dirname('egg_base')
self.egg_info = to_filename(self.egg_name)+'.egg-info'
if self.egg_base != os.curdir:
self.egg_info = os.path.join(self.egg_base, self.egg_info)
if '-' in self.egg_name: self.check_broken_egg_info()
# Set package version for the benefit of dumber commands
# (e.g. sdist, bdist_wininst, etc.)
#
self.distribution.metadata.version = self.egg_version
# If we bootstrapped around the lack of a PKG-INFO, as might be the
# case in a fresh checkout, make sure that any special tags get added
# to the version info
#
pd = self.distribution._patched_dist
if pd is not None and pd.key==self.egg_name.lower():
pd._version = self.egg_version
pd._parsed_version = parse_version(self.egg_version)
self.distribution._patched_dist = None
def write_or_delete_file(self, what, filename, data, force=False):
"""Write `data` to `filename` or delete if empty
If `data` is non-empty, this routine is the same as ``write_file()``.
If `data` is empty but not ``None``, this is the same as calling
``delete_file(filename)`. If `data` is ``None``, then this is a no-op
unless `filename` exists, in which case a warning is issued about the
orphaned file (if `force` is false), or deleted (if `force` is true).
"""
if data:
self.write_file(what, filename, data)
elif os.path.exists(filename):
if data is None and not force:
log.warn(
"%s not set in setup(), but %s exists", what, filename
)
return
else:
self.delete_file(filename)
def write_file(self, what, filename, data):
"""Write `data` to `filename` (if not a dry run) after announcing it
`what` is used in a log message to identify what is being written
to the file.
"""
log.info("writing %s to %s", what, filename)
if sys.version_info >= (3,):
data = data.encode("utf-8")
if not self.dry_run:
f = open(filename, 'wb')
f.write(data)
f.close()
def delete_file(self, filename):
"""Delete `filename` (if not a dry run) after announcing it"""
log.info("deleting %s", filename)
if not self.dry_run:
os.unlink(filename)
def tagged_version(self):
version = self.distribution.get_version()
# egg_info may be called more than once for a distribution,
# in which case the version string already contains all tags.
if self.vtags and version.endswith(self.vtags):
return safe_version(version)
return safe_version(version + self.vtags)
def run(self):
self.mkpath(self.egg_info)
installer = self.distribution.fetch_build_egg
for ep in iter_entry_points('egg_info.writers'):
writer = ep.load(installer=installer)
writer(self, ep.name, os.path.join(self.egg_info,ep.name))
# Get rid of native_libs.txt if it was put there by older bdist_egg
nl = os.path.join(self.egg_info, "native_libs.txt")
if os.path.exists(nl):
self.delete_file(nl)
self.find_sources()
def tags(self):
version = ''
if self.tag_build:
version+=self.tag_build
if self.tag_svn_revision and (
os.path.exists('.svn') or os.path.exists('PKG-INFO')
): version += '-r%s' % self.get_svn_revision()
if self.tag_date:
import time
version += time.strftime("-%Y%m%d")
return version
@staticmethod
def get_svn_revision():
return str(svn_utils.SvnInfo.load(os.curdir).get_revision())
def find_sources(self):
"""Generate SOURCES.txt manifest file"""
manifest_filename = os.path.join(self.egg_info,"SOURCES.txt")
mm = manifest_maker(self.distribution)
mm.manifest = manifest_filename
mm.run()
self.filelist = mm.filelist
def check_broken_egg_info(self):
bei = self.egg_name+'.egg-info'
if self.egg_base != os.curdir:
bei = os.path.join(self.egg_base, bei)
if os.path.exists(bei):
log.warn(
"-"*78+'\n'
"Note: Your current .egg-info directory has a '-' in its name;"
'\nthis will not work correctly with "setup.py develop".\n\n'
'Please rename %s to %s to correct this problem.\n'+'-'*78,
bei, self.egg_info
)
self.broken_egg_info = self.egg_info
self.egg_info = bei # make it work for now
class FileList(_FileList):
"""File list that accepts only existing, platform-independent paths"""
def append(self, item):
if item.endswith('\r'): # Fix older sdists built on Windows
item = item[:-1]
path = convert_path(item)
if sys.version_info >= (3,):
try:
if os.path.exists(path) or os.path.exists(path.encode('utf-8')):
self.files.append(path)
except UnicodeEncodeError:
# Accept UTF-8 filenames even if LANG=C
if os.path.exists(path.encode('utf-8')):
self.files.append(path)
else:
log.warn("'%s' not %s encodable -- skipping", path,
sys.getfilesystemencoding())
else:
if os.path.exists(path):
self.files.append(path)
class manifest_maker(sdist):
template = "MANIFEST.in"
def initialize_options(self):
self.use_defaults = 1
self.prune = 1
self.manifest_only = 1
self.force_manifest = 1
def finalize_options(self):
pass
def run(self):
self.filelist = FileList()
if not os.path.exists(self.manifest):
self.write_manifest() # it must exist so it'll get in the list
self.filelist.findall()
self.add_defaults()
if os.path.exists(self.template):
self.read_template()
self.prune_file_list()
self.filelist.sort()
self.filelist.remove_duplicates()
self.write_manifest()
def write_manifest(self):
"""Write the file list in 'self.filelist' (presumably as filled in
by 'add_defaults()' and 'read_template()') to the manifest file
named by 'self.manifest'.
"""
# The manifest must be UTF-8 encodable. See #303.
if sys.version_info >= (3,):
files = []
for file in self.filelist.files:
try:
file.encode("utf-8")
except UnicodeEncodeError:
log.warn("'%s' not UTF-8 encodable -- skipping" % file)
else:
files.append(file)
self.filelist.files = files
files = self.filelist.files
if os.sep!='/':
files = [f.replace(os.sep,'/') for f in files]
self.execute(write_file, (self.manifest, files),
"writing manifest file '%s'" % self.manifest)
def warn(self, msg): # suppress missing-file warnings from sdist
if not msg.startswith("standard file not found:"):
sdist.warn(self, msg)
def add_defaults(self):
sdist.add_defaults(self)
self.filelist.append(self.template)
self.filelist.append(self.manifest)
rcfiles = list(walk_revctrl())
if rcfiles:
self.filelist.extend(rcfiles)
elif os.path.exists(self.manifest):
self.read_manifest()
ei_cmd = self.get_finalized_command('egg_info')
self.filelist.include_pattern("*", prefix=ei_cmd.egg_info)
def prune_file_list(self):
build = self.get_finalized_command('build')
base_dir = self.distribution.get_fullname()
self.filelist.exclude_pattern(None, prefix=build.build_base)
self.filelist.exclude_pattern(None, prefix=base_dir)
sep = re.escape(os.sep)
self.filelist.exclude_pattern(sep+r'(RCS|CVS|\.svn)'+sep, is_regex=1)
def write_file(filename, contents):
"""Create a file with the specified name and write 'contents' (a
sequence of strings without line terminators) to it.
"""
contents = "\n".join(contents)
if sys.version_info >= (3,):
contents = contents.encode("utf-8")
f = open(filename, "wb") # always write POSIX-style manifest
f.write(contents)
f.close()
def write_pkg_info(cmd, basename, filename):
log.info("writing %s", filename)
if not cmd.dry_run:
metadata = cmd.distribution.metadata
metadata.version, oldver = cmd.egg_version, metadata.version
metadata.name, oldname = cmd.egg_name, metadata.name
try:
# write unescaped data to PKG-INFO, so older pkg_resources
# can still parse it
metadata.write_pkg_info(cmd.egg_info)
finally:
metadata.name, metadata.version = oldname, oldver
safe = getattr(cmd.distribution,'zip_safe',None)
from setuptools.command import bdist_egg
bdist_egg.write_safety_flag(cmd.egg_info, safe)
def warn_depends_obsolete(cmd, basename, filename):
if os.path.exists(filename):
log.warn(
"WARNING: 'depends.txt' is not used by setuptools 0.6!\n"
"Use the install_requires/extras_require setup() args instead."
)
def write_requirements(cmd, basename, filename):
dist = cmd.distribution
data = ['\n'.join(yield_lines(dist.install_requires or ()))]
for extra,reqs in (dist.extras_require or {}).items():
data.append('\n\n[%s]\n%s' % (extra, '\n'.join(yield_lines(reqs))))
cmd.write_or_delete_file("requirements", filename, ''.join(data))
def write_toplevel_names(cmd, basename, filename):
pkgs = dict.fromkeys(
[
k.split('.',1)[0]
for k in cmd.distribution.iter_distribution_names()
]
)
cmd.write_file("top-level names", filename, '\n'.join(pkgs)+'\n')
def overwrite_arg(cmd, basename, filename):
write_arg(cmd, basename, filename, True)
def write_arg(cmd, basename, filename, force=False):
argname = os.path.splitext(basename)[0]
value = getattr(cmd.distribution, argname, None)
if value is not None:
value = '\n'.join(value)+'\n'
cmd.write_or_delete_file(argname, filename, value, force)
def write_entries(cmd, basename, filename):
ep = cmd.distribution.entry_points
if isinstance(ep,basestring) or ep is None:
data = ep
elif ep is not None:
data = []
for section, contents in ep.items():
if not isinstance(contents,basestring):
contents = EntryPoint.parse_group(section, contents)
contents = '\n'.join(map(str,contents.values()))
data.append('[%s]\n%s\n\n' % (section,contents))
data = ''.join(data)
cmd.write_or_delete_file('entry points', filename, data, True)
def get_pkg_info_revision():
# See if we can get a -r### off of PKG-INFO, in case this is an sdist of
# a subversion revision
#
if os.path.exists('PKG-INFO'):
f = open('PKG-INFO','rU')
for line in f:
match = re.match(r"Version:.*-r(\d+)\s*$", line)
if match:
return int(match.group(1))
f.close()
return 0
|
bsd-3-clause
|
[
624,
13623,
14,
1531,
14,
5799,
63,
815,
199,
199,
2499,
282,
4084,
1159,
1275,
5799,
13,
815,
2082,
436,
4072,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
504,
9116,
492,
5817,
199,
646,
7065,
14,
2550,
199,
504,
7065,
492,
943,
199,
504,
9116,
14,
1531,
14,
25147,
492,
26644,
199,
504,
9116,
14,
5819,
492,
7116,
199,
504,
9116,
492,
11327,
63,
1208,
199,
504,
7065,
14,
1974,
492,
3957,
63,
515,
199,
504,
7065,
14,
14964,
492,
3814,
1296,
465,
485,
1173,
1296,
199,
504,
5496,
63,
4435,
492,
334,
1122,
63,
7538,
12,
5048,
63,
354,
12,
2198,
63,
1023,
12,
272,
5048,
63,
1023,
12,
1995,
63,
1278,
12,
11855,
3428,
12,
2740,
63,
2373,
63,
3438,
12,
370,
63,
1501,
9,
199,
504,
9116,
14,
1531,
14,
25147,
492,
12778,
63,
4964,
12476,
421,
199,
533,
11393,
63,
815,
8,
3110,
304,
272,
1369,
275,
298,
981,
282,
4084,
1159,
1275,
5799,
13,
815,
2082,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
5799,
13,
1095,
4009,
283,
69,
297,
298,
3619,
3035,
1275,
5799,
13,
815,
6602,
2,
2574,
298,
334,
885,
26,
2746,
402,
314,
1350,
3123,
13185,
267,
661,
1450,
13,
6836,
13,
5792,
297,
283,
82,
297,
288,
298,
1123,
1007,
1023,
6974,
2870,
370,
1015,
1329,
1288,
267,
661,
1450,
13,
602,
297,
283,
68,
297,
298,
1123,
1434,
16206,
334,
69,
14,
71,
14,
1926,
13938,
1651,
9,
370,
1015,
1329,
1288,
267,
661,
1450,
13,
1506,
4009,
283,
66,
297,
298,
17768,
5027,
1947,
370,
1050,
370,
1015,
1329,
1288,
267,
661,
889,
13,
6836,
13,
5792,
297,
283,
50,
297,
288,
298,
16932,
1133,
1050,
1007,
1023,
6974,
2870,
359,
885,
31937,
267,
661,
889,
13,
602,
297,
283,
36,
297,
298,
16932,
1133,
2387,
1434,
16206,
359,
885,
31937,
272,
1622,
339,
5046,
63,
1419,
275,
788,
1450,
13,
602,
297,
283,
1450,
13,
6836,
13,
5792,
418,
272,
6946,
63,
2992,
275,
791,
889,
13,
6836,
13,
5792,
356,
283,
1450,
13,
6836,
13,
5792,
297,
490,
283,
889,
13,
602,
356,
283,
1450,
13,
602,
936,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
291,
14,
5799,
63,
354,
275,
488,
267,
291,
14,
5799,
63,
1023,
275,
488,
267,
291,
14,
5799,
63,
1095,
275,
488,
267,
291,
14,
5799,
63,
815,
275,
488,
267,
291,
14,
1450,
63,
1506,
275,
488,
267,
291,
14,
1450,
63,
6836,
63,
5792,
275,
378,
267,
291,
14,
1450,
63,
602,
275,
378,
267,
291,
14,
15697,
63,
5799,
63,
815,
275,
756,
267,
291,
14,
86,
2969,
275,
488,
339,
347,
3354,
63,
1023,
63,
815,
8,
277,
12,
1788,
304,
267,
687,
9116,
14,
1531,
14,
29852,
492,
5283,
63,
888,
267,
1338,
275,
1211,
8,
288,
11393,
63,
815,
29,
807,
8,
355,
1947,
63,
6836,
63,
5792,
29,
16,
12,
355,
1947,
63,
602,
29,
16,
12,
355,
1947,
63,
1506,
29,
277,
14,
2969,
1062,
288,
776,
267,
776,
267,
5283,
63,
888,
8,
1501,
12,
1338,
9,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
291,
14,
5799,
63,
354,
275,
5048,
63,
354,
8,
277,
14,
4972,
14,
362,
63,
354,
1012,
267,
291,
14,
86,
2969,
275,
291,
14,
2969,
342,
267,
291,
14,
5799,
63,
1023,
275,
291,
14,
15679,
63,
1023,
342,
398,
862,
26,
288,
769,
8,
355,
2198,
63,
7538,
3508,
83,
389,
5,
83,
7,
450,
334,
277,
14,
5799,
63,
354,
12,
277,
14,
5799,
63,
1023,
430,
288,
776,
267,
871,
1722,
26,
288,
746,
7065,
14,
2550,
14,
12012,
1208,
16546,
8,
355,
298,
3364,
4084,
536,
503,
1015,
6302,
26,
450,
83,
3295,
83,
2,
450,
355,
334,
277,
14,
5799,
63,
354,
12,
277,
14,
5799,
63,
1023,
9,
288,
776,
398,
340,
291,
14,
5799,
63,
1095,
365,
488,
26,
288,
7606,
275,
291,
14,
4972,
14,
2491,
63,
694,
288,
291,
14,
5799,
63,
1095,
275,
334,
3220,
503,
13056,
362,
8594,
736,
14,
15594,
9,
398,
291,
14,
7505,
63,
3475,
360,
5799,
63,
1095,
358,
267,
291,
14,
5799,
63,
815,
275,
370,
63,
1501,
8,
277,
14,
5799,
63,
354,
6393,
1370,
5799,
13,
815,
7,
267,
340,
291,
14,
5799,
63,
1095,
1137,
747,
14,
15594,
26,
288,
291,
14,
5799,
63,
815,
275,
747,
14,
515,
14,
904,
8,
277,
14,
5799,
63,
1095,
12,
291,
14,
5799,
63,
815,
9,
267,
340,
10791,
315,
291,
14,
5799,
63,
354,
26,
291,
14,
1074,
63,
15697,
63,
5799,
63,
815,
342,
398,
327,
2494,
2559,
1015,
367,
314,
22477,
3269,
402,
366,
884,
3718,
267,
327,
334,
69,
14,
71,
14,
26644,
12,
26308,
63,
2676,
3615,
12,
5423,
4959,
267,
327,
267,
291,
14,
4972,
14,
2343,
14,
1023,
275,
291,
14,
5799,
63,
1023,
398,
327,
982,
781,
15865,
1915,
6818,
314,
29098,
402,
282,
30281,
13,
4531,
12,
465,
5594,
506,
314,
267,
327,
1930,
315,
282,
17480,
15243,
12,
1852,
3238,
626,
1263,
4539,
3762,
664,
3483,
267,
327,
370,
314,
1015,
2256,
267,
327,
267,
6454,
275,
291,
14,
4972,
423,
22631,
63,
2686,
267,
340,
6454,
365,
440,
488,
436,
6454,
14,
498,
389,
277,
14,
5799,
63,
354,
14,
2325,
837,
288,
6454,
423,
1023,
275,
291,
14,
5799,
63,
1023,
288,
6454,
423,
6751,
63,
1023,
275,
2198,
63,
1023,
8,
277,
14,
5799,
63,
1023,
9,
288,
291,
14,
4972,
423,
22631,
63,
2686,
275,
488,
339,
347,
2218,
63,
269,
63,
1807,
63,
493,
8,
277,
12,
4052,
12,
1788,
12,
666,
12,
3542,
29,
797,
304,
267,
408,
3534,
658,
576,
64,
370,
658,
1501,
64,
503,
3145,
340,
2701,
398,
982,
658,
576,
64,
365,
2222,
13,
1667,
12,
642,
12981,
365,
314,
2011,
465,
1124,
952,
63,
493,
28566,
267,
982,
658,
576,
64,
365,
2701,
1325,
440,
1124,
403,
4542,
642,
365,
314,
2011,
465,
6358,
267,
1124,
1807,
63,
493,
8,
1501,
20414,
221,
982,
658,
576,
64,
365,
1124,
403,
4542,
2066,
642,
365,
282,
949,
13,
411,
267
] |
[
13623,
14,
1531,
14,
5799,
63,
815,
199,
199,
2499,
282,
4084,
1159,
1275,
5799,
13,
815,
2082,
436,
4072,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
199,
504,
9116,
492,
5817,
199,
646,
7065,
14,
2550,
199,
504,
7065,
492,
943,
199,
504,
9116,
14,
1531,
14,
25147,
492,
26644,
199,
504,
9116,
14,
5819,
492,
7116,
199,
504,
9116,
492,
11327,
63,
1208,
199,
504,
7065,
14,
1974,
492,
3957,
63,
515,
199,
504,
7065,
14,
14964,
492,
3814,
1296,
465,
485,
1173,
1296,
199,
504,
5496,
63,
4435,
492,
334,
1122,
63,
7538,
12,
5048,
63,
354,
12,
2198,
63,
1023,
12,
272,
5048,
63,
1023,
12,
1995,
63,
1278,
12,
11855,
3428,
12,
2740,
63,
2373,
63,
3438,
12,
370,
63,
1501,
9,
199,
504,
9116,
14,
1531,
14,
25147,
492,
12778,
63,
4964,
12476,
421,
199,
533,
11393,
63,
815,
8,
3110,
304,
272,
1369,
275,
298,
981,
282,
4084,
1159,
1275,
5799,
13,
815,
2082,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
5799,
13,
1095,
4009,
283,
69,
297,
298,
3619,
3035,
1275,
5799,
13,
815,
6602,
2,
2574,
298,
334,
885,
26,
2746,
402,
314,
1350,
3123,
13185,
267,
661,
1450,
13,
6836,
13,
5792,
297,
283,
82,
297,
288,
298,
1123,
1007,
1023,
6974,
2870,
370,
1015,
1329,
1288,
267,
661,
1450,
13,
602,
297,
283,
68,
297,
298,
1123,
1434,
16206,
334,
69,
14,
71,
14,
1926,
13938,
1651,
9,
370,
1015,
1329,
1288,
267,
661,
1450,
13,
1506,
4009,
283,
66,
297,
298,
17768,
5027,
1947,
370,
1050,
370,
1015,
1329,
1288,
267,
661,
889,
13,
6836,
13,
5792,
297,
283,
50,
297,
288,
298,
16932,
1133,
1050,
1007,
1023,
6974,
2870,
359,
885,
31937,
267,
661,
889,
13,
602,
297,
283,
36,
297,
298,
16932,
1133,
2387,
1434,
16206,
359,
885,
31937,
272,
1622,
339,
5046,
63,
1419,
275,
788,
1450,
13,
602,
297,
283,
1450,
13,
6836,
13,
5792,
418,
272,
6946,
63,
2992,
275,
791,
889,
13,
6836,
13,
5792,
356,
283,
1450,
13,
6836,
13,
5792,
297,
490,
283,
889,
13,
602,
356,
283,
1450,
13,
602,
936,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
291,
14,
5799,
63,
354,
275,
488,
267,
291,
14,
5799,
63,
1023,
275,
488,
267,
291,
14,
5799,
63,
1095,
275,
488,
267,
291,
14,
5799,
63,
815,
275,
488,
267,
291,
14,
1450,
63,
1506,
275,
488,
267,
291,
14,
1450,
63,
6836,
63,
5792,
275,
378,
267,
291,
14,
1450,
63,
602,
275,
378,
267,
291,
14,
15697,
63,
5799,
63,
815,
275,
756,
267,
291,
14,
86,
2969,
275,
488,
339,
347,
3354,
63,
1023,
63,
815,
8,
277,
12,
1788,
304,
267,
687,
9116,
14,
1531,
14,
29852,
492,
5283,
63,
888,
267,
1338,
275,
1211,
8,
288,
11393,
63,
815,
29,
807,
8,
355,
1947,
63,
6836,
63,
5792,
29,
16,
12,
355,
1947,
63,
602,
29,
16,
12,
355,
1947,
63,
1506,
29,
277,
14,
2969,
1062,
288,
776,
267,
776,
267,
5283,
63,
888,
8,
1501,
12,
1338,
9,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
291,
14,
5799,
63,
354,
275,
5048,
63,
354,
8,
277,
14,
4972,
14,
362,
63,
354,
1012,
267,
291,
14,
86,
2969,
275,
291,
14,
2969,
342,
267,
291,
14,
5799,
63,
1023,
275,
291,
14,
15679,
63,
1023,
342,
398,
862,
26,
288,
769,
8,
355,
2198,
63,
7538,
3508,
83,
389,
5,
83,
7,
450,
334,
277,
14,
5799,
63,
354,
12,
277,
14,
5799,
63,
1023,
430,
288,
776,
267,
871,
1722,
26,
288,
746,
7065,
14,
2550,
14,
12012,
1208,
16546,
8,
355,
298,
3364,
4084,
536,
503,
1015,
6302,
26,
450,
83,
3295,
83,
2,
450,
355,
334,
277,
14,
5799,
63,
354,
12,
277,
14,
5799,
63,
1023,
9,
288,
776,
398,
340,
291,
14,
5799,
63,
1095,
365,
488,
26,
288,
7606,
275,
291,
14,
4972,
14,
2491,
63,
694,
288,
291,
14,
5799,
63,
1095,
275,
334,
3220,
503,
13056,
362,
8594,
736,
14,
15594,
9,
398,
291,
14,
7505,
63,
3475,
360,
5799,
63,
1095,
358,
267,
291,
14,
5799,
63,
815,
275,
370,
63,
1501,
8,
277,
14,
5799,
63,
354,
6393,
1370,
5799,
13,
815,
7,
267,
340,
291,
14,
5799,
63,
1095,
1137,
747,
14,
15594,
26,
288,
291,
14,
5799,
63,
815,
275,
747,
14,
515,
14,
904,
8,
277,
14,
5799,
63,
1095,
12,
291,
14,
5799,
63,
815,
9,
267,
340,
10791,
315,
291,
14,
5799,
63,
354,
26,
291,
14,
1074,
63,
15697,
63,
5799,
63,
815,
342,
398,
327,
2494,
2559,
1015,
367,
314,
22477,
3269,
402,
366,
884,
3718,
267,
327,
334,
69,
14,
71,
14,
26644,
12,
26308,
63,
2676,
3615,
12,
5423,
4959,
267,
327,
267,
291,
14,
4972,
14,
2343,
14,
1023,
275,
291,
14,
5799,
63,
1023,
398,
327,
982,
781,
15865,
1915,
6818,
314,
29098,
402,
282,
30281,
13,
4531,
12,
465,
5594,
506,
314,
267,
327,
1930,
315,
282,
17480,
15243,
12,
1852,
3238,
626,
1263,
4539,
3762,
664,
3483,
267,
327,
370,
314,
1015,
2256,
267,
327,
267,
6454,
275,
291,
14,
4972,
423,
22631,
63,
2686,
267,
340,
6454,
365,
440,
488,
436,
6454,
14,
498,
389,
277,
14,
5799,
63,
354,
14,
2325,
837,
288,
6454,
423,
1023,
275,
291,
14,
5799,
63,
1023,
288,
6454,
423,
6751,
63,
1023,
275,
2198,
63,
1023,
8,
277,
14,
5799,
63,
1023,
9,
288,
291,
14,
4972,
423,
22631,
63,
2686,
275,
488,
339,
347,
2218,
63,
269,
63,
1807,
63,
493,
8,
277,
12,
4052,
12,
1788,
12,
666,
12,
3542,
29,
797,
304,
267,
408,
3534,
658,
576,
64,
370,
658,
1501,
64,
503,
3145,
340,
2701,
398,
982,
658,
576,
64,
365,
2222,
13,
1667,
12,
642,
12981,
365,
314,
2011,
465,
1124,
952,
63,
493,
28566,
267,
982,
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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
] |
Remwrath/bgui
|
bgui/texture.py
|
7
|
3754
|
# This module encapsulates texture loading so we are not dependent on bge.texture
from .gl_utils import *
try:
from bge import texture
import aud
USING_BGE_TEXTURE = True
except ImportError:
from PyQt4 import QtOpenGL, QtGui
USING_BGE_TEXTURE = False
class Texture:
def __init__(self, path, interp_mode):
self._tex_id = glGenTextures(1)
self.size = [0, 0]
self._interp_mode = None
self.path = None
# Setup some parameters
self.bind()
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
self.interp_mode = interp_mode
self.reload(path)
def __del__(self):
glDeleteTextures([self._tex_id])
@property
def interp_mode(self):
return self._interp_mode
@interp_mode.setter
def interp_mode(self, value):
if value != self._interp_mode:
self.bind()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, value)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, value)
self._interp_mode = value
def bind(self):
glBindTexture(GL_TEXTURE_2D, self._tex_id)
class ImageTexture(Texture):
_cache = {}
def __init__(self, image, interp_mode, caching):
self._caching = caching
super().__init__(image, interp_mode);
def reload(self, image):
if image == self.path:
return
if image in ImageTexture._cache:
# Image has already been loaded from disk, recall it from the cache
img = ImageTexture._cache[image]
else:
# Load the image data from disk
if USING_BGE_TEXTURE:
img = texture.ImageFFmpeg(image)
img.scale = False
if self._caching:
ImageTexture._cache[image] = img
else:
img = QtGui.QImage(image)
if USING_BGE_TEXTURE:
data = img.image
if data == None:
print("Unabled to load the image", image)
return
# Upload the texture data
self.bind()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.size[0], img.size[1], 0,
GL_RGBA, GL_UNSIGNED_BYTE, data)
self.image_size = img.size[:]
else:
if img.isNull():
print("Unable to load the image", image)
return
glDeleteTextures([self._tex_id])
self._tex_id = QtOpenGL.QGLContext.currentContext().bindTexture(img)
self.interp_mode = self.interp_mode
self.image_size = [img.width(), img.height()]
# Save the image name
self.path = image
img = None
class VideoTexture(Texture):
def __init__(self, video, interp_mode, repeat, play_audio):
self.repeat = repeat
self.play_audio = play_audio
self.video = None
self.audio = None
super().__init__(video, interp_mode)
def __del__(self):
super().__del__()
if self.audio:
self.audio.stop()
self.video = None
def reload(self, video):
if video == self.path:
return
if USING_BGE_TEXTURE:
vid = texture.VideoFFmpeg(video)
vid.repeat = self.repeat
vid.play()
self.video = vid
data = vid.image
if self.play_audio:
self.audio = aud.device().play(aud.Factory(video))
else:
data = None
if data == None:
print("Unable to load the video", video)
return
self.bind()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vid.size[0], vid.size[1],
0, GL_RGBA, GL_UNSIGNED_BYTE, data)
self.image_size = vid.size[:]
self.path = video
def update(self):
if not self.video:
return
self.video.refresh()
data = self.video.image
if data:
self.bind()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.video.size[0], self.video.size[1],
0, GL_RGBA, GL_UNSIGNED_BYTE, data)
def play(self, start, end, use_frames=True, fps=None):
if not self.video:
return
start = float(start)
end = float(end)
if use_frames:
if not fps:
fps = self.video.framerate
print("Using fps:", fps)
start /= fps
end /= fps
if start == end:
end += 0.1
self.video.stop()
self.video.range = [start, end]
self.video.play()
|
mit
|
[
3,
961,
859,
22667,
15409,
14855,
8697,
880,
781,
787,
440,
11410,
641,
330,
303,
14,
12611,
199,
199,
504,
1275,
3528,
63,
1208,
492,
627,
199,
893,
26,
199,
198,
504,
330,
303,
492,
14855,
199,
198,
646,
282,
1181,
199,
198,
1668,
1206,
63,
34,
4962,
63,
15044,
275,
715,
199,
2590,
3545,
26,
199,
198,
504,
14084,
20,
492,
3959,
4299,
2226,
12,
5928,
199,
198,
1668,
1206,
63,
34,
4962,
63,
15044,
275,
756,
199,
199,
533,
4516,
608,
26,
199,
198,
318,
636,
826,
721,
277,
12,
931,
12,
23716,
63,
632,
304,
507,
198,
277,
423,
3858,
63,
344,
275,
6482,
8168,
1872,
1482,
8,
17,
9,
507,
198,
277,
14,
890,
275,
359,
16,
12,
378,
61,
507,
198,
277,
423,
14252,
63,
632,
275,
488,
507,
198,
277,
14,
515,
275,
488,
2742,
198,
3,
12439,
2005,
2633,
507,
198,
277,
14,
3409,
342,
507,
198,
3528,
13999,
7744,
70,
8,
2226,
63,
15044,
63,
9984,
12,
3563,
63,
15044,
63,
9984,
63,
6963,
12,
3563,
63,
14671,
1951,
9,
507,
198,
277,
14,
14252,
63,
632,
275,
23716,
63,
632,
2742,
198,
277,
14,
9233,
8,
515,
9,
421,
198,
318,
636,
2264,
721,
277,
304,
507,
198,
3528,
5392,
1872,
1482,
779,
277,
423,
3858,
63,
344,
566,
421,
198,
32,
1829,
199,
198,
318,
23716,
63,
632,
8,
277,
304,
507,
198,
1107,
291,
423,
14252,
63,
632,
421,
198,
32,
14252,
63,
632,
14,
8345,
199,
198,
318,
23716,
63,
632,
8,
277,
12,
574,
304,
507,
198,
692,
574,
1137,
291,
423,
14252,
63,
632,
26,
686,
198,
277,
14,
3409,
342,
686,
198,
3528,
13999,
21438,
6236,
8,
2226,
63,
15044,
63,
18,
36,
12,
3563,
63,
15044,
63,
45,
1254,
63,
9905,
12,
574,
9,
686,
198,
3528,
13999,
21438,
6236,
8,
2226,
63,
15044,
63,
18,
36,
12,
3563,
63,
15044,
63,
4896,
63,
9905,
12,
574,
9,
686,
198,
277,
423,
14252,
63,
632,
275,
574,
421,
198,
318,
5398,
8,
277,
304,
507,
198,
3528,
8198,
17165,
8,
2226,
63,
15044,
63,
18,
36,
12,
291,
423,
3858,
63,
344,
9,
421,
199,
533,
6047,
17165,
8,
17165,
304,
421,
198,
63,
1637,
275,
1052,
421,
198,
318,
636,
826,
721,
277,
12,
1834,
12,
23716,
63,
632,
12,
13627,
304,
507,
198,
277,
423,
22738,
275,
13627,
507,
198,
4792,
11027,
826,
721,
1569,
12,
23716,
63,
632,
2736,
421,
198,
318,
13101,
8,
277,
12,
1834,
304,
507,
198,
692,
1834,
508,
291,
14,
515,
26,
686,
198,
1107,
2742,
198,
692,
1834,
315,
6047,
17165,
423,
1637,
26,
686,
198,
3,
6047,
965,
2575,
2757,
6511,
687,
4543,
12,
26174,
652,
687,
314,
2581,
686,
198,
4060,
275,
6047,
17165,
423,
1637,
59,
1569,
61,
507,
198,
2836,
26,
686,
198,
3,
7190,
314,
1834,
666,
687,
4543,
686,
198,
692,
32210,
63,
34,
4962,
63,
15044,
26,
1585,
198,
4060,
275,
14855,
14,
3491,
1665,
16801,
8,
1569,
9,
1585,
198,
4060,
14,
3467,
275,
756,
1585,
198,
692,
291,
423,
22738,
26,
1871,
198,
3491,
17165,
423,
1637,
59,
1569,
61,
275,
6050,
686,
198,
2836,
26,
1585,
198,
4060,
275,
5928,
14,
49,
3491,
8,
1569,
9,
2742,
198,
692,
32210,
63,
34,
4962,
63,
15044,
26,
686,
198,
576,
275,
6050,
14,
1569,
686,
198,
692,
666,
508,
488,
26,
1585,
198,
1361,
480,
1358,
1909,
370,
2248,
314,
1834,
401,
1834,
9,
1585,
198,
1107,
6319,
198,
3,
19149,
314,
14855,
666,
686,
198,
277,
14,
3409,
342,
686,
198,
3528,
13999,
3491,
18,
36,
8,
2226,
63,
15044,
63,
18,
36,
12,
378,
12,
3563,
63,
21631,
12,
6050,
14,
890,
59,
16,
467,
6050,
14,
890,
59,
17,
467,
378,
12,
5264,
198,
2226,
63,
21631,
12,
3563,
63,
30805,
63,
19714,
12,
666,
9,
6319,
198,
277,
14,
1569,
63,
890,
275,
6050,
14,
890,
5873,
507,
198,
2836,
26,
686,
198,
692,
6050,
14,
374,
8849,
837,
1585,
198,
1361,
480,
6005,
370,
2248,
314,
1834,
401,
1834,
9,
1585,
198,
1107,
686,
198,
3528,
5392,
1872,
1482,
779,
277,
423,
3858,
63,
344,
566,
686,
198,
277,
423,
3858,
63,
344,
275,
3959,
4299,
2226,
14,
49,
2226,
2998,
14,
1818,
2998,
1252,
3409,
17165,
8,
4060,
9,
686,
198,
277,
14,
14252,
63,
632,
275,
291,
14,
14252,
63,
632,
686,
198,
277,
14,
1569,
63,
890,
275,
359,
4060,
14,
2063,
1062,
6050,
14,
3333,
5106,
421,
507,
198,
3,
11063,
314,
1834,
536,
507,
198,
277,
14,
515,
275,
1834,
2742,
198,
4060,
275,
488,
421,
199,
533,
15709,
17165,
8,
17165,
304,
199,
198,
318,
636,
826,
721,
277,
12,
3991,
12,
23716,
63,
632,
12,
11982,
12,
5232,
63,
8130,
304,
507,
198,
277,
14,
8755,
275,
11982,
507,
198,
277,
14,
2802,
63,
8130,
275,
5232,
63,
8130,
507,
198,
277,
14,
3722,
275,
488,
507,
198,
277,
14,
8130,
275,
488,
2742,
198,
4792,
11027,
826,
721,
3722,
12,
23716,
63,
632,
9,
421,
198,
318,
636,
2264,
721,
277,
304,
507,
198,
4792,
11027,
2264,
4533,
2742,
198,
692,
291,
14,
8130,
26,
686,
198,
277,
14,
8130,
14,
2379,
342,
2742,
198,
277,
14,
3722,
275,
488,
421,
198,
318,
13101,
8,
277,
12,
3991,
304,
507,
198,
692,
3991,
508,
291,
14,
515,
26,
686,
198,
1107,
2742,
198,
692,
32210,
63,
34,
4962,
63,
15044,
26,
686,
198,
5017,
275,
14855,
14,
9166,
1665,
16801,
8,
3722,
9,
686,
198,
5017,
14,
8755,
275,
291,
14,
8755,
686,
198,
5017,
14,
2802,
342,
686,
198,
277,
14,
3722,
275,
27767,
686,
198,
576,
275,
27767,
14,
1569,
6319,
198,
692,
291,
14,
2802,
63,
8130,
26,
1585,
198,
277,
14,
8130,
275,
282,
1181,
14,
1782,
1252,
2802,
8,
32024,
14,
2927,
8,
3722,
430,
507,
198,
2836,
26,
686,
198,
576,
275,
488,
2742,
198,
692,
666,
508,
488,
26,
686,
198,
1361,
480,
6005,
370,
2248,
314,
3991,
401,
3991,
9,
686,
198,
1107,
2742,
198,
277,
14,
3409,
342,
507,
198,
3528,
13999,
3491,
18,
36,
8,
2226,
63
] |
[
961,
859,
22667,
15409,
14855,
8697,
880,
781,
787,
440,
11410,
641,
330,
303,
14,
12611,
199,
199,
504,
1275,
3528,
63,
1208,
492,
627,
199,
893,
26,
199,
198,
504,
330,
303,
492,
14855,
199,
198,
646,
282,
1181,
199,
198,
1668,
1206,
63,
34,
4962,
63,
15044,
275,
715,
199,
2590,
3545,
26,
199,
198,
504,
14084,
20,
492,
3959,
4299,
2226,
12,
5928,
199,
198,
1668,
1206,
63,
34,
4962,
63,
15044,
275,
756,
199,
199,
533,
4516,
608,
26,
199,
198,
318,
636,
826,
721,
277,
12,
931,
12,
23716,
63,
632,
304,
507,
198,
277,
423,
3858,
63,
344,
275,
6482,
8168,
1872,
1482,
8,
17,
9,
507,
198,
277,
14,
890,
275,
359,
16,
12,
378,
61,
507,
198,
277,
423,
14252,
63,
632,
275,
488,
507,
198,
277,
14,
515,
275,
488,
2742,
198,
3,
12439,
2005,
2633,
507,
198,
277,
14,
3409,
342,
507,
198,
3528,
13999,
7744,
70,
8,
2226,
63,
15044,
63,
9984,
12,
3563,
63,
15044,
63,
9984,
63,
6963,
12,
3563,
63,
14671,
1951,
9,
507,
198,
277,
14,
14252,
63,
632,
275,
23716,
63,
632,
2742,
198,
277,
14,
9233,
8,
515,
9,
421,
198,
318,
636,
2264,
721,
277,
304,
507,
198,
3528,
5392,
1872,
1482,
779,
277,
423,
3858,
63,
344,
566,
421,
198,
32,
1829,
199,
198,
318,
23716,
63,
632,
8,
277,
304,
507,
198,
1107,
291,
423,
14252,
63,
632,
421,
198,
32,
14252,
63,
632,
14,
8345,
199,
198,
318,
23716,
63,
632,
8,
277,
12,
574,
304,
507,
198,
692,
574,
1137,
291,
423,
14252,
63,
632,
26,
686,
198,
277,
14,
3409,
342,
686,
198,
3528,
13999,
21438,
6236,
8,
2226,
63,
15044,
63,
18,
36,
12,
3563,
63,
15044,
63,
45,
1254,
63,
9905,
12,
574,
9,
686,
198,
3528,
13999,
21438,
6236,
8,
2226,
63,
15044,
63,
18,
36,
12,
3563,
63,
15044,
63,
4896,
63,
9905,
12,
574,
9,
686,
198,
277,
423,
14252,
63,
632,
275,
574,
421,
198,
318,
5398,
8,
277,
304,
507,
198,
3528,
8198,
17165,
8,
2226,
63,
15044,
63,
18,
36,
12,
291,
423,
3858,
63,
344,
9,
421,
199,
533,
6047,
17165,
8,
17165,
304,
421,
198,
63,
1637,
275,
1052,
421,
198,
318,
636,
826,
721,
277,
12,
1834,
12,
23716,
63,
632,
12,
13627,
304,
507,
198,
277,
423,
22738,
275,
13627,
507,
198,
4792,
11027,
826,
721,
1569,
12,
23716,
63,
632,
2736,
421,
198,
318,
13101,
8,
277,
12,
1834,
304,
507,
198,
692,
1834,
508,
291,
14,
515,
26,
686,
198,
1107,
2742,
198,
692,
1834,
315,
6047,
17165,
423,
1637,
26,
686,
198,
3,
6047,
965,
2575,
2757,
6511,
687,
4543,
12,
26174,
652,
687,
314,
2581,
686,
198,
4060,
275,
6047,
17165,
423,
1637,
59,
1569,
61,
507,
198,
2836,
26,
686,
198,
3,
7190,
314,
1834,
666,
687,
4543,
686,
198,
692,
32210,
63,
34,
4962,
63,
15044,
26,
1585,
198,
4060,
275,
14855,
14,
3491,
1665,
16801,
8,
1569,
9,
1585,
198,
4060,
14,
3467,
275,
756,
1585,
198,
692,
291,
423,
22738,
26,
1871,
198,
3491,
17165,
423,
1637,
59,
1569,
61,
275,
6050,
686,
198,
2836,
26,
1585,
198,
4060,
275,
5928,
14,
49,
3491,
8,
1569,
9,
2742,
198,
692,
32210,
63,
34,
4962,
63,
15044,
26,
686,
198,
576,
275,
6050,
14,
1569,
686,
198,
692,
666,
508,
488,
26,
1585,
198,
1361,
480,
1358,
1909,
370,
2248,
314,
1834,
401,
1834,
9,
1585,
198,
1107,
6319,
198,
3,
19149,
314,
14855,
666,
686,
198,
277,
14,
3409,
342,
686,
198,
3528,
13999,
3491,
18,
36,
8,
2226,
63,
15044,
63,
18,
36,
12,
378,
12,
3563,
63,
21631,
12,
6050,
14,
890,
59,
16,
467,
6050,
14,
890,
59,
17,
467,
378,
12,
5264,
198,
2226,
63,
21631,
12,
3563,
63,
30805,
63,
19714,
12,
666,
9,
6319,
198,
277,
14,
1569,
63,
890,
275,
6050,
14,
890,
5873,
507,
198,
2836,
26,
686,
198,
692,
6050,
14,
374,
8849,
837,
1585,
198,
1361,
480,
6005,
370,
2248,
314,
1834,
401,
1834,
9,
1585,
198,
1107,
686,
198,
3528,
5392,
1872,
1482,
779,
277,
423,
3858,
63,
344,
566,
686,
198,
277,
423,
3858,
63,
344,
275,
3959,
4299,
2226,
14,
49,
2226,
2998,
14,
1818,
2998,
1252,
3409,
17165,
8,
4060,
9,
686,
198,
277,
14,
14252,
63,
632,
275,
291,
14,
14252,
63,
632,
686,
198,
277,
14,
1569,
63,
890,
275,
359,
4060,
14,
2063,
1062,
6050,
14,
3333,
5106,
421,
507,
198,
3,
11063,
314,
1834,
536,
507,
198,
277,
14,
515,
275,
1834,
2742,
198,
4060,
275,
488,
421,
199,
533,
15709,
17165,
8,
17165,
304,
199,
198,
318,
636,
826,
721,
277,
12,
3991,
12,
23716,
63,
632,
12,
11982,
12,
5232,
63,
8130,
304,
507,
198,
277,
14,
8755,
275,
11982,
507,
198,
277,
14,
2802,
63,
8130,
275,
5232,
63,
8130,
507,
198,
277,
14,
3722,
275,
488,
507,
198,
277,
14,
8130,
275,
488,
2742,
198,
4792,
11027,
826,
721,
3722,
12,
23716,
63,
632,
9,
421,
198,
318,
636,
2264,
721,
277,
304,
507,
198,
4792,
11027,
2264,
4533,
2742,
198,
692,
291,
14,
8130,
26,
686,
198,
277,
14,
8130,
14,
2379,
342,
2742,
198,
277,
14,
3722,
275,
488,
421,
198,
318,
13101,
8,
277,
12,
3991,
304,
507,
198,
692,
3991,
508,
291,
14,
515,
26,
686,
198,
1107,
2742,
198,
692,
32210,
63,
34,
4962,
63,
15044,
26,
686,
198,
5017,
275,
14855,
14,
9166,
1665,
16801,
8,
3722,
9,
686,
198,
5017,
14,
8755,
275,
291,
14,
8755,
686,
198,
5017,
14,
2802,
342,
686,
198,
277,
14,
3722,
275,
27767,
686,
198,
576,
275,
27767,
14,
1569,
6319,
198,
692,
291,
14,
2802,
63,
8130,
26,
1585,
198,
277,
14,
8130,
275,
282,
1181,
14,
1782,
1252,
2802,
8,
32024,
14,
2927,
8,
3722,
430,
507,
198,
2836,
26,
686,
198,
576,
275,
488,
2742,
198,
692,
666,
508,
488,
26,
686,
198,
1361,
480,
6005,
370,
2248,
314,
3991,
401,
3991,
9,
686,
198,
1107,
2742,
198,
277,
14,
3409,
342,
507,
198,
3528,
13999,
3491,
18,
36,
8,
2226,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
yusufm/mobly
|
mobly/controllers/android_device_lib/event_dispatcher.py
|
1
|
15487
|
#!/usr/bin/env python3.4
#
# Copyright 2016 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.
from concurrent.futures import ThreadPoolExecutor
import queue
import re
import threading
import time
import traceback
class EventDispatcherError(Exception):
pass
class IllegalStateError(EventDispatcherError):
"""Raise when user tries to put event_dispatcher into an illegal state.
"""
class DuplicateError(EventDispatcherError):
"""Raise when a duplicate is being created and it shouldn't.
"""
class EventDispatcher:
"""Class managing events for an sl4a connection.
"""
DEFAULT_TIMEOUT = 60
def __init__(self, sl4a):
self._sl4a = sl4a
self.started = False
self.executor = None
self.poller = None
self.event_dict = {}
self.handlers = {}
self.lock = threading.RLock()
def poll_events(self):
"""Continuously polls all types of events from sl4a.
Events are sorted by name and store in separate queues.
If there are registered handlers, the handlers will be called with
corresponding event immediately upon event discovery, and the event
won't be stored. If exceptions occur, stop the dispatcher and return
"""
while self.started:
event_obj = None
event_name = None
try:
event_obj = self._sl4a.eventWait(50000)
except:
if self.started:
print("Exception happened during polling.")
print(traceback.format_exc())
raise
if not event_obj:
continue
elif 'name' not in event_obj:
print("Received Malformed event {}".format(event_obj))
continue
else:
event_name = event_obj['name']
# if handler registered, process event
if event_name in self.handlers:
self.handle_subscribed_event(event_obj, event_name)
if event_name == "EventDispatcherShutdown":
self._sl4a.closeSl4aSession()
break
else:
self.lock.acquire()
if event_name in self.event_dict: # otherwise, cache event
self.event_dict[event_name].put(event_obj)
else:
q = queue.Queue()
q.put(event_obj)
self.event_dict[event_name] = q
self.lock.release()
def register_handler(self, handler, event_name, args):
"""Registers an event handler.
One type of event can only have one event handler associated with it.
Args:
handler: The event handler function to be registered.
event_name: Name of the event the handler is for.
args: User arguments to be passed to the handler when it's called.
Raises:
IllegalStateError: Raised if attempts to register a handler after
the dispatcher starts running.
DuplicateError: Raised if attempts to register more than one
handler for one type of event.
"""
if self.started:
raise IllegalStateError(("Can't register service after polling is"
" started"))
self.lock.acquire()
try:
if event_name in self.handlers:
raise DuplicateError('A handler for {} already exists'.format(
event_name))
self.handlers[event_name] = (handler, args)
finally:
self.lock.release()
def start(self):
"""Starts the event dispatcher.
Initiates executor and start polling events.
Raises:
IllegalStateError: Can't start a dispatcher again when it's already
running.
"""
if not self.started:
self.started = True
self.executor = ThreadPoolExecutor(max_workers=32)
self.poller = self.executor.submit(self.poll_events)
else:
raise IllegalStateError("Dispatcher is already started.")
def clean_up(self):
"""Clean up and release resources after the event dispatcher polling
loop has been broken.
The following things happen:
1. Clear all events and flags.
2. Close the sl4a client the event_dispatcher object holds.
3. Shut down executor without waiting.
"""
if not self.started:
return
self.started = False
self.clear_all_events()
self._sl4a.close()
self.poller.set_result("Done")
# The polling thread is guaranteed to finish after a max of 60 seconds,
# so we don't wait here.
self.executor.shutdown(wait=False)
def pop_event(self, event_name, timeout=DEFAULT_TIMEOUT):
"""Pop an event from its queue.
Return and remove the oldest entry of an event.
Block until an event of specified name is available or
times out if timeout is set.
Args:
event_name: Name of the event to be popped.
timeout: Number of seconds to wait when event is not present.
Never times out if None.
Returns:
event: The oldest entry of the specified event. None if timed out.
Raises:
IllegalStateError: Raised if pop is called before the dispatcher
starts polling.
"""
if not self.started:
raise IllegalStateError(
"Dispatcher needs to be started before popping.")
e_queue = self.get_event_q(event_name)
if not e_queue:
raise TypeError("Failed to get an event queue for {}".format(
event_name))
try:
# Block for timeout
if timeout:
return e_queue.get(True, timeout)
# Non-blocking poll for event
elif timeout == 0:
return e_queue.get(False)
else:
# Block forever on event wait
return e_queue.get(True)
except queue.Empty:
raise queue.Empty('Timeout after {}s waiting for event: {}'.format(
timeout, event_name))
def wait_for_event(self,
event_name,
predicate,
timeout=DEFAULT_TIMEOUT,
*args,
**kwargs):
"""Wait for an event that satisfies a predicate to appear.
Continuously pop events of a particular name and check against the
predicate until an event that satisfies the predicate is popped or
timed out. Note this will remove all the events of the same name that
do not satisfy the predicate in the process.
Args:
event_name: Name of the event to be popped.
predicate: A function that takes an event and returns True if the
predicate is satisfied, False otherwise.
timeout: Number of seconds to wait.
*args: Optional positional args passed to predicate().
**kwargs: Optional keyword args passed to predicate().
Returns:
The event that satisfies the predicate.
Raises:
queue.Empty: Raised if no event that satisfies the predicate was
found before time out.
"""
deadline = time.time() + timeout
while True:
event = None
try:
event = self.pop_event(event_name, 1)
except queue.Empty:
pass
if event and predicate(event, *args, **kwargs):
return event
if time.time() > deadline:
raise queue.Empty(
'Timeout after {}s waiting for event: {}'.format(
timeout, event_name))
def pop_events(self, regex_pattern, timeout):
"""Pop events whose names match a regex pattern.
If such event(s) exist, pop one event from each event queue that
satisfies the condition. Otherwise, wait for an event that satisfies
the condition to occur, with timeout.
Results are sorted by timestamp in ascending order.
Args:
regex_pattern: The regular expression pattern that an event name
should match in order to be popped.
timeout: Number of seconds to wait for events in case no event
matching the condition exits when the function is called.
Returns:
results: Pop events whose names match a regex pattern.
Empty if none exist and the wait timed out.
Raises:
IllegalStateError: Raised if pop is called before the dispatcher
starts polling.
queue.Empty: Raised if no event was found before time out.
"""
if not self.started:
raise IllegalStateError(
"Dispatcher needs to be started before popping.")
deadline = time.time() + timeout
while True:
#TODO: fix the sleep loop
results = self._match_and_pop(regex_pattern)
if len(results) != 0 or time.time() > deadline:
break
time.sleep(1)
if len(results) == 0:
raise queue.Empty('Timeout after {}s waiting for event: {}'.format(
timeout, regex_pattern))
return sorted(results, key=lambda event: event['time'])
def _match_and_pop(self, regex_pattern):
"""Pop one event from each of the event queues whose names
match (in a sense of regular expression) regex_pattern.
"""
results = []
self.lock.acquire()
for name in self.event_dict.keys():
if re.match(regex_pattern, name):
q = self.event_dict[name]
if q:
try:
results.append(q.get(False))
except:
pass
self.lock.release()
return results
def get_event_q(self, event_name):
"""Obtain the queue storing events of the specified name.
If no event of this name has been polled, wait for one to.
Returns:
queue: A queue storing all the events of the specified name.
None if timed out.
timeout: Number of seconds to wait for the operation.
Raises:
queue.Empty: Raised if the queue does not exist and timeout has
passed.
"""
self.lock.acquire()
if not event_name in self.event_dict or self.event_dict[
event_name] is None:
self.event_dict[event_name] = queue.Queue()
self.lock.release()
event_queue = self.event_dict[event_name]
return event_queue
def handle_subscribed_event(self, event_obj, event_name):
"""Execute the registered handler of an event.
Retrieve the handler and its arguments, and execute the handler in a
new thread.
Args:
event_obj: Json object of the event.
event_name: Name of the event to call handler for.
"""
handler, args = self.handlers[event_name]
self.executor.submit(handler, event_obj, *args)
def _handle(self, event_handler, event_name, user_args, event_timeout,
cond, cond_timeout):
"""Pop an event of specified type and calls its handler on it. If
condition is not None, block until condition is met or timeout.
"""
if cond:
cond.wait(cond_timeout)
event = self.pop_event(event_name, event_timeout)
return event_handler(event, *user_args)
def handle_event(self,
event_handler,
event_name,
user_args,
event_timeout=None,
cond=None,
cond_timeout=None):
"""Handle events that don't have registered handlers
In a new thread, poll one event of specified type from its queue and
execute its handler. If no such event exists, the thread waits until
one appears.
Args:
event_handler: Handler for the event, which should take at least
one argument - the event json object.
event_name: Name of the event to be handled.
user_args: User arguments for the handler; to be passed in after
the event json.
event_timeout: Number of seconds to wait for the event to come.
cond: A condition to wait on before executing the handler. Should
be a threading.Event object.
cond_timeout: Number of seconds to wait before the condition times
out. Never times out if None.
Returns:
worker: A concurrent.Future object associated with the handler.
If blocking call worker.result() is triggered, the handler
needs to return something to unblock.
"""
worker = self.executor.submit(self._handle, event_handler, event_name,
user_args, event_timeout, cond,
cond_timeout)
return worker
def pop_all(self, event_name):
"""Return and remove all stored events of a specified name.
Pops all events from their queue. May miss the latest ones.
If no event is available, return immediately.
Args:
event_name: Name of the events to be popped.
Returns:
results: List of the desired events.
Raises:
IllegalStateError: Raised if pop is called before the dispatcher
starts polling.
"""
if not self.started:
raise IllegalStateError(("Dispatcher needs to be started before "
"popping."))
results = []
try:
self.lock.acquire()
while True:
e = self.event_dict[event_name].get(block=False)
results.append(e)
except (queue.Empty, KeyError):
return results
finally:
self.lock.release()
def clear_events(self, event_name):
"""Clear all events of a particular name.
Args:
event_name: Name of the events to be popped.
"""
self.lock.acquire()
try:
q = self.get_event_q(event_name)
q.queue.clear()
except queue.Empty:
return
finally:
self.lock.release()
def clear_all_events(self):
"""Clear all event queues and their cached events."""
self.lock.acquire()
self.event_dict.clear()
self.lock.release()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
14,
20,
199,
3,
199,
3,
1898,
7800,
4475,
3277,
14,
199,
3,
221,
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,
221,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
221,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
23002,
14,
25513,
492,
11086,
5453,
16752,
199,
646,
4126,
199,
646,
295,
199,
646,
5796,
199,
646,
900,
199,
646,
5190,
421,
199,
533,
6763,
15461,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
473,
13486,
2223,
547,
8,
2390,
15461,
547,
304,
272,
408,
18111,
1380,
922,
11275,
370,
5324,
1566,
63,
14913,
1901,
376,
20282,
1174,
14,
272,
408,
421,
199,
533,
23942,
547,
8,
2390,
15461,
547,
304,
272,
408,
18111,
1380,
282,
9250,
365,
3769,
2737,
436,
652,
9296,
1133,
14,
272,
408,
421,
199,
533,
6763,
15461,
26,
272,
408,
2543,
28453,
4474,
367,
376,
5340,
20,
65,
1950,
14,
272,
408,
339,
6186,
63,
8899,
275,
5212,
339,
347,
636,
826,
721,
277,
12,
5340,
20,
65,
304,
267,
291,
423,
2482,
20,
65,
275,
5340,
20,
65,
267,
291,
14,
8924,
275,
756,
267,
291,
14,
13471,
275,
488,
267,
291,
14,
26746,
275,
488,
267,
291,
14,
1430,
63,
807,
275,
1052,
267,
291,
14,
5586,
275,
1052,
267,
291,
14,
831,
275,
5796,
14,
30550,
342,
339,
347,
11271,
63,
4368,
8,
277,
304,
267,
408,
24593,
7514,
590,
3708,
478,
1006,
2943,
402,
4474,
687,
5340,
20,
65,
14,
398,
27982,
787,
3355,
701,
536,
436,
3877,
315,
7396,
21366,
14,
267,
982,
2337,
787,
7264,
8297,
12,
314,
8297,
911,
506,
2797,
543,
267,
5226,
1566,
9939,
12188,
1566,
13172,
12,
436,
314,
1566,
267,
7859,
1133,
506,
5489,
14,
982,
4967,
4781,
12,
3631,
314,
17475,
436,
372,
267,
408,
267,
1830,
291,
14,
8924,
26,
288,
1566,
63,
1113,
275,
488,
288,
1566,
63,
354,
275,
488,
288,
862,
26,
355,
1566,
63,
1113,
275,
291,
423,
2482,
20,
65,
14,
1430,
7536,
8,
21,
993,
9,
288,
871,
26,
355,
340,
291,
14,
8924,
26,
490,
870,
480,
1726,
21056,
5309,
12353,
2685,
490,
870,
8,
6894,
14,
908,
63,
2804,
1012,
490,
746,
288,
340,
440,
1566,
63,
1113,
26,
355,
1980,
288,
916,
283,
354,
7,
440,
315,
1566,
63,
1113,
26,
355,
870,
480,
9392,
603,
24012,
1566,
8352,
908,
8,
1430,
63,
1113,
430,
355,
1980,
288,
587,
26,
355,
1566,
63,
354,
275,
1566,
63,
1113,
459,
354,
418,
288,
327,
340,
3016,
7264,
12,
2112,
1566,
288,
340,
1566,
63,
354,
315,
291,
14,
5586,
26,
355,
291,
14,
2479,
63,
23178,
63,
1430,
8,
1430,
63,
1113,
12,
1566,
63,
354,
9,
288,
340,
1566,
63,
354,
508,
298,
2390,
15461,
20043,
582,
355,
291,
423,
2482,
20,
65,
14,
1600,
11592,
20,
65,
4434,
342,
355,
2059,
288,
587,
26,
355,
291,
14,
831,
14,
8174,
342,
355,
340,
1566,
63,
354,
315,
291,
14,
1430,
63,
807,
26,
221,
327,
4257,
12,
2581,
1566,
490,
291,
14,
1430,
63,
807,
59,
1430,
63,
354,
1055,
524,
8,
1430,
63,
1113,
9,
355,
587,
26,
490,
1894,
275,
4126,
14,
3737,
342,
490,
1894,
14,
524,
8,
1430,
63,
1113,
9,
490,
291,
14,
1430,
63,
807,
59,
1430,
63,
354,
61,
275,
1894,
355,
291,
14,
831,
14,
3221,
342,
339,
347,
2274,
63,
2232,
8,
277,
12,
3016,
12,
1566,
63,
354,
12,
1249,
304,
267,
408,
31136,
376,
1566,
3016,
14,
398,
7309,
730,
402,
1566,
883,
1454,
1172,
1373,
1566,
3016,
4568,
543,
652,
14,
398,
3033,
26,
288,
3016,
26,
710,
1566,
3016,
805,
370,
506,
7264,
14,
288,
1566,
63,
354,
26,
2812,
402,
314,
1566,
314,
3016,
365,
367,
14,
288,
1249,
26,
2876,
2368,
370,
506,
3032,
370,
314,
3016,
1380,
652,
1159,
2797,
14,
398,
6218,
26,
288,
473,
13486,
2223,
547,
26,
24997,
340,
12454,
370,
2274,
282,
3016,
2410,
355,
314,
17475,
9174,
3879,
14,
288,
23942,
547,
26,
24997,
340,
12454,
370,
2274,
1655,
2419,
1373,
355,
3016,
367,
1373,
730,
402,
1566,
14,
267,
408,
267,
340,
291,
14,
8924,
26,
288,
746,
473,
13486,
2223,
547,
9313,
6049,
1133,
2274,
2435,
2410,
12353,
365,
2,
3660,
298,
8239,
2237,
267,
291,
14,
831,
14,
8174,
342,
267,
862,
26,
288,
340,
1566,
63,
354,
315,
291,
14,
5586,
26,
355,
746,
23942,
547,
360,
33,
3016,
367,
1052,
2575,
3495,
1370,
908,
8,
490,
1566,
63,
354,
430,
288,
291,
14,
5586,
59,
1430,
63,
354,
61,
275,
334,
2232,
12,
1249,
9,
267,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
339,
347,
1343,
8,
277,
304,
267,
408,
32142,
314,
1566,
17475,
14,
398,
21412,
2335,
13270,
436,
1343,
12353,
4474,
14,
398,
6218,
26,
288,
473,
13486,
2223,
547,
26,
6855,
1133,
1343,
282,
17475,
4020,
1380,
652,
1159,
2575,
355,
3879,
14,
267,
408,
267,
340,
440,
291,
14,
8924,
26,
288,
291,
14,
8924,
275,
715,
288,
291,
14,
13471,
275,
11086,
5453,
16752,
8,
988,
63,
11009,
29,
708,
9,
288,
291,
14,
26746,
275,
291,
14,
13471,
14,
7275,
8,
277,
14,
6843,
63,
4368,
9,
267,
587,
26,
288,
746,
473,
13486,
2223,
547,
480,
15461,
365,
2575,
8239,
2685,
339,
347,
3633,
63,
384,
8,
277,
304,
267,
408,
6580,
1536,
436,
4683,
5944,
2410,
314,
1566,
17475,
12353,
267,
4438,
965,
2757,
10529,
14,
398,
710,
2569,
7645,
5992
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
14,
20,
199,
3,
199,
3,
1898,
7800,
4475,
3277,
14,
199,
3,
221,
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,
221,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
221,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
23002,
14,
25513,
492,
11086,
5453,
16752,
199,
646,
4126,
199,
646,
295,
199,
646,
5796,
199,
646,
900,
199,
646,
5190,
421,
199,
533,
6763,
15461,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
473,
13486,
2223,
547,
8,
2390,
15461,
547,
304,
272,
408,
18111,
1380,
922,
11275,
370,
5324,
1566,
63,
14913,
1901,
376,
20282,
1174,
14,
272,
408,
421,
199,
533,
23942,
547,
8,
2390,
15461,
547,
304,
272,
408,
18111,
1380,
282,
9250,
365,
3769,
2737,
436,
652,
9296,
1133,
14,
272,
408,
421,
199,
533,
6763,
15461,
26,
272,
408,
2543,
28453,
4474,
367,
376,
5340,
20,
65,
1950,
14,
272,
408,
339,
6186,
63,
8899,
275,
5212,
339,
347,
636,
826,
721,
277,
12,
5340,
20,
65,
304,
267,
291,
423,
2482,
20,
65,
275,
5340,
20,
65,
267,
291,
14,
8924,
275,
756,
267,
291,
14,
13471,
275,
488,
267,
291,
14,
26746,
275,
488,
267,
291,
14,
1430,
63,
807,
275,
1052,
267,
291,
14,
5586,
275,
1052,
267,
291,
14,
831,
275,
5796,
14,
30550,
342,
339,
347,
11271,
63,
4368,
8,
277,
304,
267,
408,
24593,
7514,
590,
3708,
478,
1006,
2943,
402,
4474,
687,
5340,
20,
65,
14,
398,
27982,
787,
3355,
701,
536,
436,
3877,
315,
7396,
21366,
14,
267,
982,
2337,
787,
7264,
8297,
12,
314,
8297,
911,
506,
2797,
543,
267,
5226,
1566,
9939,
12188,
1566,
13172,
12,
436,
314,
1566,
267,
7859,
1133,
506,
5489,
14,
982,
4967,
4781,
12,
3631,
314,
17475,
436,
372,
267,
408,
267,
1830,
291,
14,
8924,
26,
288,
1566,
63,
1113,
275,
488,
288,
1566,
63,
354,
275,
488,
288,
862,
26,
355,
1566,
63,
1113,
275,
291,
423,
2482,
20,
65,
14,
1430,
7536,
8,
21,
993,
9,
288,
871,
26,
355,
340,
291,
14,
8924,
26,
490,
870,
480,
1726,
21056,
5309,
12353,
2685,
490,
870,
8,
6894,
14,
908,
63,
2804,
1012,
490,
746,
288,
340,
440,
1566,
63,
1113,
26,
355,
1980,
288,
916,
283,
354,
7,
440,
315,
1566,
63,
1113,
26,
355,
870,
480,
9392,
603,
24012,
1566,
8352,
908,
8,
1430,
63,
1113,
430,
355,
1980,
288,
587,
26,
355,
1566,
63,
354,
275,
1566,
63,
1113,
459,
354,
418,
288,
327,
340,
3016,
7264,
12,
2112,
1566,
288,
340,
1566,
63,
354,
315,
291,
14,
5586,
26,
355,
291,
14,
2479,
63,
23178,
63,
1430,
8,
1430,
63,
1113,
12,
1566,
63,
354,
9,
288,
340,
1566,
63,
354,
508,
298,
2390,
15461,
20043,
582,
355,
291,
423,
2482,
20,
65,
14,
1600,
11592,
20,
65,
4434,
342,
355,
2059,
288,
587,
26,
355,
291,
14,
831,
14,
8174,
342,
355,
340,
1566,
63,
354,
315,
291,
14,
1430,
63,
807,
26,
221,
327,
4257,
12,
2581,
1566,
490,
291,
14,
1430,
63,
807,
59,
1430,
63,
354,
1055,
524,
8,
1430,
63,
1113,
9,
355,
587,
26,
490,
1894,
275,
4126,
14,
3737,
342,
490,
1894,
14,
524,
8,
1430,
63,
1113,
9,
490,
291,
14,
1430,
63,
807,
59,
1430,
63,
354,
61,
275,
1894,
355,
291,
14,
831,
14,
3221,
342,
339,
347,
2274,
63,
2232,
8,
277,
12,
3016,
12,
1566,
63,
354,
12,
1249,
304,
267,
408,
31136,
376,
1566,
3016,
14,
398,
7309,
730,
402,
1566,
883,
1454,
1172,
1373,
1566,
3016,
4568,
543,
652,
14,
398,
3033,
26,
288,
3016,
26,
710,
1566,
3016,
805,
370,
506,
7264,
14,
288,
1566,
63,
354,
26,
2812,
402,
314,
1566,
314,
3016,
365,
367,
14,
288,
1249,
26,
2876,
2368,
370,
506,
3032,
370,
314,
3016,
1380,
652,
1159,
2797,
14,
398,
6218,
26,
288,
473,
13486,
2223,
547,
26,
24997,
340,
12454,
370,
2274,
282,
3016,
2410,
355,
314,
17475,
9174,
3879,
14,
288,
23942,
547,
26,
24997,
340,
12454,
370,
2274,
1655,
2419,
1373,
355,
3016,
367,
1373,
730,
402,
1566,
14,
267,
408,
267,
340,
291,
14,
8924,
26,
288,
746,
473,
13486,
2223,
547,
9313,
6049,
1133,
2274,
2435,
2410,
12353,
365,
2,
3660,
298,
8239,
2237,
267,
291,
14,
831,
14,
8174,
342,
267,
862,
26,
288,
340,
1566,
63,
354,
315,
291,
14,
5586,
26,
355,
746,
23942,
547,
360,
33,
3016,
367,
1052,
2575,
3495,
1370,
908,
8,
490,
1566,
63,
354,
430,
288,
291,
14,
5586,
59,
1430,
63,
354,
61,
275,
334,
2232,
12,
1249,
9,
267,
3753,
26,
288,
291,
14,
831,
14,
3221,
342,
339,
347,
1343,
8,
277,
304,
267,
408,
32142,
314,
1566,
17475,
14,
398,
21412,
2335,
13270,
436,
1343,
12353,
4474,
14,
398,
6218,
26,
288,
473,
13486,
2223,
547,
26,
6855,
1133,
1343,
282,
17475,
4020,
1380,
652,
1159,
2575,
355,
3879,
14,
267,
408,
267,
340,
440,
291,
14,
8924,
26,
288,
291,
14,
8924,
275,
715,
288,
291,
14,
13471,
275,
11086,
5453,
16752,
8,
988,
63,
11009,
29,
708,
9,
288,
291,
14,
26746,
275,
291,
14,
13471,
14,
7275,
8,
277,
14,
6843,
63,
4368,
9,
267,
587,
26,
288,
746,
473,
13486,
2223,
547,
480,
15461,
365,
2575,
8239,
2685,
339,
347,
3633,
63,
384,
8,
277,
304,
267,
408,
6580,
1536,
436,
4683,
5944,
2410,
314,
1566,
17475,
12353,
267,
4438,
965,
2757,
10529,
14,
398,
710,
2569,
7645,
5992,
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,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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
] |
ds-hwang/chromium-crosswalk
|
tools/memory_inspector/memory_inspector/data/file_storage_unittest.py
|
89
|
5331
|
# 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.
"""This unittest covers both file_storage and serialization modules."""
import os
import tempfile
import time
import unittest
from memory_inspector.core import memory_map
from memory_inspector.core import native_heap
from memory_inspector.core import stacktrace
from memory_inspector.core import symbol
from memory_inspector.data import file_storage
class FileStorageTest(unittest.TestCase):
def setUp(self):
self._storage_path = tempfile.mkdtemp()
self._storage = file_storage.Storage(self._storage_path)
def tearDown(self):
os.removedirs(self._storage_path)
def testSettings(self):
settings_1 = { 'foo' : 1, 'bar' : 2 }
settings_2 = { 'foo' : 1, 'bar' : 2 }
self._storage.StoreSettings('one', settings_1)
self._storage.StoreSettings('two', settings_2)
self._DeepCompare(settings_1, self._storage.LoadSettings('one'))
self._DeepCompare(settings_2, self._storage.LoadSettings('two'))
self._storage.StoreSettings('one', {})
self._storage.StoreSettings('two', {})
def testArchives(self):
self._storage.OpenArchive('foo', create=True)
self._storage.OpenArchive('bar', create=True)
self._storage.OpenArchive('baz', create=True)
self._storage.DeleteArchive('bar')
self.assertTrue('foo' in self._storage.ListArchives())
self.assertFalse('bar' in self._storage.ListArchives())
self.assertTrue('baz' in self._storage.ListArchives())
self._storage.DeleteArchive('foo')
self._storage.DeleteArchive('baz')
def testSnapshots(self):
archive = self._storage.OpenArchive('snapshots', create=True)
t1 = archive.StartNewSnapshot()
archive.StoreMemMaps(memory_map.Map())
time.sleep(0.01) # Max snapshot resolution is in the order of usecs.
t2 = archive.StartNewSnapshot()
archive.StoreMemMaps(memory_map.Map())
archive.StoreNativeHeap(native_heap.NativeHeap())
self.assertIn(t1, archive.ListSnapshots())
self.assertIn(t2, archive.ListSnapshots())
self.assertTrue(archive.HasMemMaps(t1))
self.assertFalse(archive.HasNativeHeap(t1))
self.assertTrue(archive.HasMemMaps(t2))
self.assertTrue(archive.HasNativeHeap(t2))
self._storage.DeleteArchive('snapshots')
def testMmap(self):
archive = self._storage.OpenArchive('mmap', create=True)
timestamp = archive.StartNewSnapshot()
mmap = memory_map.Map()
map_entry1 = memory_map.MapEntry(4096, 8191, 'rw--', '/foo', 0)
map_entry2 = memory_map.MapEntry(65536, 81919, 'rw--', '/bar', 4096)
map_entry2.resident_pages = [5]
mmap.Add(map_entry1)
mmap.Add(map_entry2)
archive.StoreMemMaps(mmap)
mmap_deser = archive.LoadMemMaps(timestamp)
self._DeepCompare(mmap, mmap_deser)
self._storage.DeleteArchive('mmap')
def testNativeHeap(self):
archive = self._storage.OpenArchive('nheap', create=True)
timestamp = archive.StartNewSnapshot()
nh = native_heap.NativeHeap()
for i in xrange(1, 4):
stack_trace = stacktrace.Stacktrace()
frame = nh.GetStackFrame(i * 10 + 1)
frame.SetExecFileInfo('foo.so', 1)
stack_trace.Add(frame)
frame = nh.GetStackFrame(i * 10 + 2)
frame.SetExecFileInfo('bar.so', 2)
stack_trace.Add(frame)
nh.Add(native_heap.Allocation(size=i * 10,
stack_trace=stack_trace,
start=i * 20,
flags=i * 30))
archive.StoreNativeHeap(nh)
nh_deser = archive.LoadNativeHeap(timestamp)
self._DeepCompare(nh, nh_deser)
self._storage.DeleteArchive('nheap')
def testSymbols(self):
archive = self._storage.OpenArchive('symbols', create=True)
symbols = symbol.Symbols()
# Symbol db is global per archive, no need to StartNewSnapshot.
symbols.Add('foo.so', 1, symbol.Symbol('sym1', 'file1.c', 11))
symbols.Add('bar.so', 2, symbol.Symbol('sym2', 'file2.c', 12))
sym3 = symbol.Symbol('sym3', 'file2.c', 13)
sym3.AddSourceLineInfo('outer_file.c', 23)
symbols.Add('baz.so', 3, sym3)
archive.StoreSymbols(symbols)
symbols_deser = archive.LoadSymbols()
self._DeepCompare(symbols, symbols_deser)
self._storage.DeleteArchive('symbols')
def _DeepCompare(self, a, b, prefix=''):
"""Recursively compares two objects (original and deserialized)."""
self.assertEqual(a is None, b is None)
if a is None:
return
_BASICTYPES = (long, int, basestring, float)
if isinstance(a, _BASICTYPES) and isinstance(b, _BASICTYPES):
return self.assertEqual(a, b, prefix)
self.assertEqual(type(a), type(b), prefix + ' type (%s vs %s' % (
type(a), type(b)))
if isinstance(a, list):
self.assertEqual(len(a), len(b), prefix + ' len (%d vs %d)' % (
len(a), len(b)))
for i in range(len(a)):
self._DeepCompare(a[i], b[i], prefix + '[%d]' % i)
return
if isinstance(a, dict):
self.assertEqual(a.keys(), b.keys(), prefix + ' keys (%s vs %s)' % (
str(a.keys()), str(b.keys())))
for k in a.iterkeys():
self._DeepCompare(a[k], b[k], prefix + '.' + str(k))
return
return self._DeepCompare(a.__dict__, b.__dict__, prefix)
|
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,
2765,
2882,
25858,
3865,
570,
63,
3494,
436,
16953,
4621,
1041,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
900,
199,
646,
2882,
199,
199,
504,
4402,
63,
26047,
14,
1018,
492,
4402,
63,
1130,
199,
504,
4402,
63,
26047,
14,
1018,
492,
5438,
63,
12492,
199,
504,
4402,
63,
26047,
14,
1018,
492,
3464,
3446,
199,
504,
4402,
63,
26047,
14,
1018,
492,
5272,
199,
504,
4402,
63,
26047,
14,
576,
492,
570,
63,
3494,
421,
199,
533,
3814,
6408,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
423,
3494,
63,
515,
275,
5549,
14,
11983,
342,
272,
291,
423,
3494,
275,
570,
63,
3494,
14,
6408,
8,
277,
423,
3494,
63,
515,
9,
819,
347,
6766,
8,
277,
304,
272,
747,
14,
2168,
3220,
8,
277,
423,
3494,
63,
515,
9,
819,
347,
511,
5268,
8,
277,
304,
272,
2202,
63,
17,
275,
469,
283,
1421,
7,
520,
413,
12,
283,
1700,
7,
520,
499,
789,
272,
2202,
63,
18,
275,
469,
283,
1421,
7,
520,
413,
12,
283,
1700,
7,
520,
499,
789,
272,
291,
423,
3494,
14,
5502,
5268,
360,
368,
297,
2202,
63,
17,
9,
272,
291,
423,
3494,
14,
5502,
5268,
360,
5601,
297,
2202,
63,
18,
9,
272,
291,
423,
27753,
16051,
8,
1751,
63,
17,
12,
291,
423,
3494,
14,
6200,
5268,
360,
368,
1333,
272,
291,
423,
27753,
16051,
8,
1751,
63,
18,
12,
291,
423,
3494,
14,
6200,
5268,
360,
5601,
1333,
272,
291,
423,
3494,
14,
5502,
5268,
360,
368,
297,
5009,
272,
291,
423,
3494,
14,
5502,
5268,
360,
5601,
297,
5009,
819,
347,
511,
8438,
7602,
8,
277,
304,
272,
291,
423,
3494,
14,
4299,
13042,
360,
1421,
297,
1218,
29,
549,
9,
272,
291,
423,
3494,
14,
4299,
13042,
360,
1700,
297,
1218,
29,
549,
9,
272,
291,
423,
3494,
14,
4299,
13042,
360,
6185,
297,
1218,
29,
549,
9,
272,
291,
423,
3494,
14,
5392,
13042,
360,
1700,
358,
272,
291,
14,
1815,
360,
1421,
7,
315,
291,
423,
3494,
14,
1296,
8438,
7602,
1012,
272,
291,
14,
3334,
360,
1700,
7,
315,
291,
423,
3494,
14,
1296,
8438,
7602,
1012,
272,
291,
14,
1815,
360,
6185,
7,
315,
291,
423,
3494,
14,
1296,
8438,
7602,
1012,
272,
291,
423,
3494,
14,
5392,
13042,
360,
1421,
358,
272,
291,
423,
3494,
14,
5392,
13042,
360,
6185,
358,
819,
347,
511,
12038,
83,
8,
277,
304,
272,
6359,
275,
291,
423,
3494,
14,
4299,
13042,
360,
15331,
297,
1218,
29,
549,
9,
272,
307,
17,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
6359,
14,
5502,
14169,
24995,
8,
4844,
63,
1130,
14,
2956,
1012,
272,
900,
14,
4532,
8,
16,
14,
614,
9,
327,
8228,
5740,
12401,
365,
315,
314,
1865,
402,
675,
1259,
14,
272,
307,
18,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
6359,
14,
5502,
14169,
24995,
8,
4844,
63,
1130,
14,
2956,
1012,
272,
6359,
14,
5502,
19675,
19777,
8,
6106,
63,
12492,
14,
19675,
19777,
1012,
272,
291,
14,
4080,
8,
84,
17,
12,
6359,
14,
1296,
12038,
83,
1012,
272,
291,
14,
4080,
8,
84,
18,
12,
6359,
14,
1296,
12038,
83,
1012,
272,
291,
14,
1815,
8,
6404,
14,
6362,
14169,
24995,
8,
84,
17,
430,
272,
291,
14,
3334,
8,
6404,
14,
6362,
19675,
19777,
8,
84,
17,
430,
272,
291,
14,
1815,
8,
6404,
14,
6362,
14169,
24995,
8,
84,
18,
430,
272,
291,
14,
1815,
8,
6404,
14,
6362,
19675,
19777,
8,
84,
18,
430,
272,
291,
423,
3494,
14,
5392,
13042,
360,
15331,
358,
819,
347,
511,
45,
1130,
8,
277,
304,
272,
6359,
275,
291,
423,
3494,
14,
4299,
13042,
360,
20671,
297,
1218,
29,
549,
9,
272,
4913,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
21991,
275,
4402,
63,
1130,
14,
2956,
342,
272,
2341,
63,
2373,
17,
275,
4402,
63,
1130,
14,
2956,
3900,
8,
20579,
12,
1695,
12632,
12,
283,
13057,
306,
297,
1994,
1421,
297,
378,
9,
272,
2341,
63,
2373,
18,
275,
4402,
63,
1130,
14,
2956,
3900,
8,
10027,
1344,
12,
1695,
1167,
1167,
12,
283,
13057,
306,
297,
1994,
1700,
297,
17125,
9,
272,
2341,
63,
2373,
18,
14,
20807,
1326,
63,
5856,
275,
359,
21,
61,
272,
21991,
14,
1123,
8,
1130,
63,
2373,
17,
9,
272,
21991,
14,
1123,
8,
1130,
63,
2373,
18,
9,
272,
6359,
14,
5502,
14169,
24995,
8,
20671,
9,
272,
21991,
63,
271,
332,
275,
6359,
14,
6200,
14169,
24995,
8,
3954,
9,
272,
291,
423,
27753,
16051,
8,
20671,
12,
21991,
63,
271,
332,
9,
272,
291,
423,
3494,
14,
5392,
13042,
360,
20671,
358,
819,
347,
511,
19675,
19777,
8,
277,
304,
272,
6359,
275,
291,
423,
3494,
14,
4299,
13042,
360,
78,
12492,
297,
1218,
29,
549,
9,
272,
4913,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
302,
72,
275,
5438,
63,
12492,
14,
19675,
19777,
342,
272,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
489,
3464,
63,
3446,
275,
3464,
3446,
14,
4851,
3446,
342,
489,
2787,
275,
302,
72,
14,
1002,
4851,
3160,
8,
73,
627,
1616,
435,
413,
9,
489,
2787,
14,
1084,
4858,
1173,
2354,
360,
1421,
14,
1152,
297,
413,
9,
489,
3464,
63,
3446,
14,
1123,
8,
1943,
9,
489,
2787,
275,
302,
72,
14,
1002,
4851,
3160,
8,
73,
627,
1616,
435,
499,
9,
489,
2787,
14,
1084,
4858,
1173,
2354,
360,
1700,
14,
1152,
297,
499,
9,
489,
3464,
63,
3446,
14,
1123,
8,
1943,
9,
489,
302,
72,
14,
1123,
8,
6106,
63,
12492,
14,
17794,
8,
890,
29,
73,
627,
1616,
12,
2511,
3464,
63,
3446,
29,
2340,
63,
3446,
12,
2511,
1343,
29,
73,
627,
3388,
12,
2511,
3285,
29,
73,
627,
4233,
430,
272,
6359,
14,
5502,
19675,
19777,
8,
29199,
9,
272,
302,
72,
63,
271,
332,
275,
6359,
14,
6200,
19675,
19777,
8,
3954
] |
[
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,
2765,
2882,
25858,
3865,
570,
63,
3494,
436,
16953,
4621,
1041,
199,
199,
646,
747,
199,
646,
5549,
199,
646,
900,
199,
646,
2882,
199,
199,
504,
4402,
63,
26047,
14,
1018,
492,
4402,
63,
1130,
199,
504,
4402,
63,
26047,
14,
1018,
492,
5438,
63,
12492,
199,
504,
4402,
63,
26047,
14,
1018,
492,
3464,
3446,
199,
504,
4402,
63,
26047,
14,
1018,
492,
5272,
199,
504,
4402,
63,
26047,
14,
576,
492,
570,
63,
3494,
421,
199,
533,
3814,
6408,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
423,
3494,
63,
515,
275,
5549,
14,
11983,
342,
272,
291,
423,
3494,
275,
570,
63,
3494,
14,
6408,
8,
277,
423,
3494,
63,
515,
9,
819,
347,
6766,
8,
277,
304,
272,
747,
14,
2168,
3220,
8,
277,
423,
3494,
63,
515,
9,
819,
347,
511,
5268,
8,
277,
304,
272,
2202,
63,
17,
275,
469,
283,
1421,
7,
520,
413,
12,
283,
1700,
7,
520,
499,
789,
272,
2202,
63,
18,
275,
469,
283,
1421,
7,
520,
413,
12,
283,
1700,
7,
520,
499,
789,
272,
291,
423,
3494,
14,
5502,
5268,
360,
368,
297,
2202,
63,
17,
9,
272,
291,
423,
3494,
14,
5502,
5268,
360,
5601,
297,
2202,
63,
18,
9,
272,
291,
423,
27753,
16051,
8,
1751,
63,
17,
12,
291,
423,
3494,
14,
6200,
5268,
360,
368,
1333,
272,
291,
423,
27753,
16051,
8,
1751,
63,
18,
12,
291,
423,
3494,
14,
6200,
5268,
360,
5601,
1333,
272,
291,
423,
3494,
14,
5502,
5268,
360,
368,
297,
5009,
272,
291,
423,
3494,
14,
5502,
5268,
360,
5601,
297,
5009,
819,
347,
511,
8438,
7602,
8,
277,
304,
272,
291,
423,
3494,
14,
4299,
13042,
360,
1421,
297,
1218,
29,
549,
9,
272,
291,
423,
3494,
14,
4299,
13042,
360,
1700,
297,
1218,
29,
549,
9,
272,
291,
423,
3494,
14,
4299,
13042,
360,
6185,
297,
1218,
29,
549,
9,
272,
291,
423,
3494,
14,
5392,
13042,
360,
1700,
358,
272,
291,
14,
1815,
360,
1421,
7,
315,
291,
423,
3494,
14,
1296,
8438,
7602,
1012,
272,
291,
14,
3334,
360,
1700,
7,
315,
291,
423,
3494,
14,
1296,
8438,
7602,
1012,
272,
291,
14,
1815,
360,
6185,
7,
315,
291,
423,
3494,
14,
1296,
8438,
7602,
1012,
272,
291,
423,
3494,
14,
5392,
13042,
360,
1421,
358,
272,
291,
423,
3494,
14,
5392,
13042,
360,
6185,
358,
819,
347,
511,
12038,
83,
8,
277,
304,
272,
6359,
275,
291,
423,
3494,
14,
4299,
13042,
360,
15331,
297,
1218,
29,
549,
9,
272,
307,
17,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
6359,
14,
5502,
14169,
24995,
8,
4844,
63,
1130,
14,
2956,
1012,
272,
900,
14,
4532,
8,
16,
14,
614,
9,
327,
8228,
5740,
12401,
365,
315,
314,
1865,
402,
675,
1259,
14,
272,
307,
18,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
6359,
14,
5502,
14169,
24995,
8,
4844,
63,
1130,
14,
2956,
1012,
272,
6359,
14,
5502,
19675,
19777,
8,
6106,
63,
12492,
14,
19675,
19777,
1012,
272,
291,
14,
4080,
8,
84,
17,
12,
6359,
14,
1296,
12038,
83,
1012,
272,
291,
14,
4080,
8,
84,
18,
12,
6359,
14,
1296,
12038,
83,
1012,
272,
291,
14,
1815,
8,
6404,
14,
6362,
14169,
24995,
8,
84,
17,
430,
272,
291,
14,
3334,
8,
6404,
14,
6362,
19675,
19777,
8,
84,
17,
430,
272,
291,
14,
1815,
8,
6404,
14,
6362,
14169,
24995,
8,
84,
18,
430,
272,
291,
14,
1815,
8,
6404,
14,
6362,
19675,
19777,
8,
84,
18,
430,
272,
291,
423,
3494,
14,
5392,
13042,
360,
15331,
358,
819,
347,
511,
45,
1130,
8,
277,
304,
272,
6359,
275,
291,
423,
3494,
14,
4299,
13042,
360,
20671,
297,
1218,
29,
549,
9,
272,
4913,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
21991,
275,
4402,
63,
1130,
14,
2956,
342,
272,
2341,
63,
2373,
17,
275,
4402,
63,
1130,
14,
2956,
3900,
8,
20579,
12,
1695,
12632,
12,
283,
13057,
306,
297,
1994,
1421,
297,
378,
9,
272,
2341,
63,
2373,
18,
275,
4402,
63,
1130,
14,
2956,
3900,
8,
10027,
1344,
12,
1695,
1167,
1167,
12,
283,
13057,
306,
297,
1994,
1700,
297,
17125,
9,
272,
2341,
63,
2373,
18,
14,
20807,
1326,
63,
5856,
275,
359,
21,
61,
272,
21991,
14,
1123,
8,
1130,
63,
2373,
17,
9,
272,
21991,
14,
1123,
8,
1130,
63,
2373,
18,
9,
272,
6359,
14,
5502,
14169,
24995,
8,
20671,
9,
272,
21991,
63,
271,
332,
275,
6359,
14,
6200,
14169,
24995,
8,
3954,
9,
272,
291,
423,
27753,
16051,
8,
20671,
12,
21991,
63,
271,
332,
9,
272,
291,
423,
3494,
14,
5392,
13042,
360,
20671,
358,
819,
347,
511,
19675,
19777,
8,
277,
304,
272,
6359,
275,
291,
423,
3494,
14,
4299,
13042,
360,
78,
12492,
297,
1218,
29,
549,
9,
272,
4913,
275,
6359,
14,
3162,
4665,
12038,
342,
272,
302,
72,
275,
5438,
63,
12492,
14,
19675,
19777,
342,
272,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
489,
3464,
63,
3446,
275,
3464,
3446,
14,
4851,
3446,
342,
489,
2787,
275,
302,
72,
14,
1002,
4851,
3160,
8,
73,
627,
1616,
435,
413,
9,
489,
2787,
14,
1084,
4858,
1173,
2354,
360,
1421,
14,
1152,
297,
413,
9,
489,
3464,
63,
3446,
14,
1123,
8,
1943,
9,
489,
2787,
275,
302,
72,
14,
1002,
4851,
3160,
8,
73,
627,
1616,
435,
499,
9,
489,
2787,
14,
1084,
4858,
1173,
2354,
360,
1700,
14,
1152,
297,
499,
9,
489,
3464,
63,
3446,
14,
1123,
8,
1943,
9,
489,
302,
72,
14,
1123,
8,
6106,
63,
12492,
14,
17794,
8,
890,
29,
73,
627,
1616,
12,
2511,
3464,
63,
3446,
29,
2340,
63,
3446,
12,
2511,
1343,
29,
73,
627,
3388,
12,
2511,
3285,
29,
73,
627,
4233,
430,
272,
6359,
14,
5502,
19675,
19777,
8,
29199,
9,
272,
302,
72,
63,
271,
332,
275,
6359,
14,
6200,
19675,
19777,
8,
3954,
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
] |
leorochael/odoo
|
addons/analytic/__openerp__.py
|
302
|
1891
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name' : 'Analytic Accounting',
'version': '1.1',
'author' : 'OpenERP SA',
'website' : 'https://www.odoo.com/page/accounting',
'category': 'Hidden/Dependency',
'depends' : ['base', 'decimal_precision', 'mail'],
'description': """
Module for defining analytic accounting object.
===============================================
In OpenERP, analytic accounts are linked to general accounts but are treated
totally independently. So, you can enter various different analytic operations
that have no counterpart in the general financial accounts.
""",
'data': [
'security/analytic_security.xml',
'security/ir.model.access.csv',
'analytic_sequence.xml',
'analytic_view.xml',
'analytic_data.xml',
],
'demo': [],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
7,
520,
283,
8014,
764,
9973,
316,
297,
272,
283,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
2502,
7,
520,
283,
25347,
13950,
297,
272,
283,
7360,
7,
520,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
21609,
297,
272,
283,
3710,
356,
283,
14983,
15,
14403,
297,
272,
283,
8912,
7,
520,
788,
1095,
297,
283,
6355,
63,
6833,
297,
283,
1198,
995,
272,
283,
1802,
356,
408,
199,
2377,
367,
12669,
20705,
24772,
909,
14,
199,
2486,
16964,
199,
199,
607,
7653,
12,
20705,
12639,
787,
10632,
370,
8605,
12639,
1325,
787,
10184,
199,
13280,
1183,
30426,
14,
2002,
12,
1265,
883,
9509,
7750,
3365,
20705,
5331,
199,
9099,
1172,
949,
7055,
2064,
315,
314,
8605,
2583,
24409,
12639,
14,
272,
10327,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
9782,
63,
4416,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
9782,
63,
4041,
14,
1652,
297,
267,
283,
9782,
63,
1345,
14,
1652,
297,
267,
283,
9782,
63,
576,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
283,
354,
7,
520,
283,
8014,
764,
9973,
316,
297,
272,
283,
1023,
356,
283,
17,
14,
17,
297,
272,
283,
2502,
7,
520,
283,
25347,
13950,
297,
272,
283,
7360,
7,
520,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
21609,
297,
272,
283,
3710,
356,
283,
14983,
15,
14403,
297,
272,
283,
8912,
7,
520,
788,
1095,
297,
283,
6355,
63,
6833,
297,
283,
1198,
995,
272,
283,
1802,
356,
408,
199,
2377,
367,
12669,
20705,
24772,
909,
14,
199,
2486,
16964,
199,
199,
607,
7653,
12,
20705,
12639,
787,
10632,
370,
8605,
12639,
1325,
787,
10184,
199,
13280,
1183,
30426,
14,
2002,
12,
1265,
883,
9509,
7750,
3365,
20705,
5331,
199,
9099,
1172,
949,
7055,
2064,
315,
314,
8605,
2583,
24409,
12639,
14,
272,
10327,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
9782,
63,
4416,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
9782,
63,
4041,
14,
1652,
297,
267,
283,
9782,
63,
1345,
14,
1652,
297,
267,
283,
9782,
63,
576,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
cavestruz/L500analysis
|
plotting/profiles/T_Vcirc_evolution/Vcirc_evolution/plot_Vcirc2_nu_binned_Vc500c.py
|
1
|
3175
|
from L500analysis.data_io.get_cluster_data import GetClusterData
from L500analysis.utils.utils import aexp2redshift
from L500analysis.plotting.tools.figure_formatting import *
from L500analysis.plotting.profiles.tools.profiles_percentile \
import *
from L500analysis.plotting.profiles.tools.select_profiles \
import nu_cut, prune_dict
from L500analysis.utils.constants import rbins
from derived_field_functions import *
color = matplotlib.cm.afmhot_r
aexps = [1.0,0.9,0.8,0.7,0.6,0.5,0.45,0.4,0.35]
nu_threshold = [2.3,2.7]
nu_label = r"%0.1f$\leq\nu_{500c}\leq$%0.1f"%(nu_threshold[0],nu_threshold[1])
db_name = 'L500_NR_0'
db_dir = '/home/babyostrich/Documents/Repos/L500analysis/'
profiles_list = ['r_mid',
'Vcirc2_Vc500c',
'M_dark', 'M_star', 'M_gas',
'R/R500c']
halo_properties_list=['r500c','M_total_500c','nu_500c']
Vcirc2ratioVc500c=r"$\tilde{V}=V^2_{c}/V^2_{c,500c}$"
fVcz1=r"$\tilde{V}/\tilde{V}(z=1)$"
pa = PlotAxes(figname='Vcirc2_Vc500c_nu%0.1f'%nu_threshold[0],
axes=[[0.15,0.4,0.80,0.55],[0.15,0.15,0.80,0.24]],
axes_labels=[Vcirc2ratioVc500c,fVcz1],
xlabel=r"$R/R_{500c}$",
xlim=(0.2,5),
ylims=[(0.6,1.4),(0.6,1.4)])
Vcirc2={}
clkeys = ['Vcirc2_Vc500c']
plots = [Vcirc2]
linestyles = ['-']
for aexp in aexps :
cldata = GetClusterData(aexp=aexp,db_name=db_name,
db_dir=db_dir,
profiles_list=profiles_list,
halo_properties_list=halo_properties_list)
nu_cut_hids = nu_cut(nu=cldata['nu_500c'], threshold=nu_threshold)
for plot, key in zip(plots,clkeys) :
pruned_profiles = prune_dict(d=cldata[key],k=nu_cut_hids)
plot[aexp] = calculate_profiles_mean_variance(pruned_profiles)
pa.axes[Vcirc2ratioVc500c].plot( rbins, Vcirc2[aexp]['mean'],color=color(aexp),
ls='-',label="$z=%3.1f$" % aexp2redshift(aexp))
pa.axes[Vcirc2ratioVc500c].fill_between(rbins, Vcirc2[0.5]['down'], Vcirc2[0.5]['up'],
color=color(0.5), zorder=0)
for aexp in aexps :
for V,ls in zip(plots,linestyles) :
fractional_evolution = get_profiles_division_mean_variance(
mean_profile1=V[aexp]['mean'],
var_profile1=V[aexp]['var'],
mean_profile2=V[0.5]['mean'],
var_profile2=V[0.5]['var'],
)
pa.axes[fVcz1].plot( rbins, fractional_evolution['mean'],
color=color(aexp),ls=ls)
pa.axes[Vcirc2ratioVc500c].annotate(nu_label, xy=(.75, .75), xytext=(.3, 1.3))
pa.axes[Vcirc2ratioVc500c].tick_params(labelsize=12)
pa.axes[Vcirc2ratioVc500c].tick_params(labelsize=12)
pa.axes[fVcz1].set_yticks(arange(0.6,1.4,0.2))
matplotlib.rcParams['legend.handlelength'] = 0
matplotlib.rcParams['legend.numpoints'] = 1
matplotlib.rcParams['legend.fontsize'] = 12
pa.set_legend(axes_label=Vcirc2ratioVc500c,ncol=3,loc='upper right', frameon=False)
pa.color_legend_texts(axes_label=Vcirc2ratioVc500c)
pa.savefig()
|
mit
|
[
504,
491,
5783,
10466,
14,
576,
63,
2308,
14,
362,
63,
4201,
63,
576,
492,
2372,
9581,
1451,
199,
504,
491,
5783,
10466,
14,
1208,
14,
1208,
492,
282,
1474,
18,
581,
4723,
199,
504,
491,
5783,
10466,
14,
2798,
1337,
14,
2537,
14,
8941,
63,
20034,
492,
627,
199,
504,
491,
5783,
10466,
14,
2798,
1337,
14,
11225,
14,
2537,
14,
11225,
63,
21188,
971,
272,
492,
627,
199,
504,
491,
5783,
10466,
14,
2798,
1337,
14,
11225,
14,
2537,
14,
2416,
63,
11225,
971,
272,
492,
15699,
63,
5919,
12,
27619,
63,
807,
199,
504,
491,
5783,
10466,
14,
1208,
14,
5559,
492,
519,
11329,
199,
504,
7131,
63,
698,
63,
5777,
492,
627,
199,
199,
2326,
275,
8027,
14,
4400,
14,
2756,
77,
8885,
63,
82,
199,
65,
476,
1190,
275,
359,
17,
14,
16,
12,
16,
14,
25,
12,
16,
14,
24,
12,
16,
14,
23,
12,
16,
14,
22,
12,
16,
14,
21,
12,
16,
14,
2322,
12,
16,
14,
20,
12,
16,
14,
1276,
61,
199,
4850,
63,
7227,
275,
359,
18,
14,
19,
12,
18,
14,
23,
61,
199,
4850,
63,
1302,
275,
519,
6808,
16,
14,
17,
70,
16827,
274,
81,
60,
4850,
7348,
5783,
67,
4988,
274,
81,
22074,
16,
14,
17,
70,
14007,
4850,
63,
7227,
59,
16,
467,
4850,
63,
7227,
59,
17,
566,
199,
697,
63,
354,
275,
283,
44,
5783,
63,
17774,
63,
16,
7,
199,
697,
63,
694,
275,
1994,
4219,
15,
26118,
16540,
816,
335,
15,
26872,
15,
497,
1712,
15,
44,
5783,
10466,
4805,
199,
199,
11225,
63,
513,
275,
788,
82,
63,
8523,
297,
20169,
283,
54,
6092,
18,
63,
54,
67,
5783,
67,
297,
326,
283,
45,
63,
13625,
297,
283,
45,
63,
7848,
297,
283,
45,
63,
24364,
297,
326,
283,
50,
15,
50,
5783,
67,
418,
199,
199,
72,
12201,
63,
3282,
63,
513,
2968,
82,
5783,
67,
1673,
45,
63,
2923,
63,
5783,
67,
1673,
4850,
63,
5783,
67,
418,
421,
199,
54,
6092,
18,
6884,
54,
67,
5783,
67,
29,
82,
2,
16827,
16488,
91,
54,
93,
29,
54,
62,
18,
7348,
67,
5995,
54,
62,
18,
7348,
67,
12,
5783,
67,
93,
17351,
199,
70,
54,
16823,
17,
29,
82,
2,
16827,
16488,
91,
54,
5995,
60,
16488,
91,
54,
22999,
90,
29,
17,
9,
17351,
199,
199,
387,
275,
14794,
20386,
8,
592,
354,
534,
54,
6092,
18,
63,
54,
67,
5783,
67,
63,
4850,
5,
16,
14,
17,
70,
5956,
4850,
63,
7227,
59,
16,
467,
1598,
7824,
16025,
16,
14,
1046,
12,
16,
14,
20,
12,
16,
14,
1257,
12,
16,
14,
1229,
6922,
16,
14,
1046,
12,
16,
14,
1046,
12,
16,
14,
1257,
12,
16,
14,
1194,
2365,
1598,
7824,
63,
3512,
1524,
54,
6092,
18,
6884,
54,
67,
5783,
67,
12,
70,
54,
16823,
17,
467,
1598,
671,
1302,
29,
82,
2,
4,
50,
15,
50,
7348,
5783,
67,
93,
11918,
1598,
671,
4175,
2687,
16,
14,
18,
12,
21,
395,
1598,
612,
31689,
17497,
16,
14,
22,
12,
17,
14,
20,
11865,
16,
14,
22,
12,
17,
14,
20,
3948,
199,
199,
54,
6092,
18,
7622,
199,
429,
1612,
275,
788,
54,
6092,
18,
63,
54,
67,
5783,
67,
418,
199,
13701,
275,
359,
54,
6092,
18,
61,
199,
472,
20953,
83,
275,
11573,
418,
199,
199,
509,
282,
1474,
315,
282,
476,
1190,
520,
272,
824,
576,
275,
2372,
9581,
1451,
8,
65,
1474,
29,
65,
1474,
12,
697,
63,
354,
29,
697,
63,
354,
12,
1169,
1592,
63,
694,
29,
697,
63,
694,
12,
1169,
17390,
63,
513,
29,
11225,
63,
513,
12,
1169,
394,
12201,
63,
3282,
63,
513,
29,
72,
12201,
63,
3282,
63,
513,
9,
2286,
15699,
63,
5919,
63,
72,
1580,
275,
15699,
63,
5919,
8,
4850,
29,
429,
576,
459,
4850,
63,
5783,
67,
995,
8765,
29,
4850,
63,
7227,
9,
339,
367,
5137,
12,
790,
315,
3482,
8,
13701,
12,
429,
1612,
9,
520,
267,
29501,
379,
63,
11225,
275,
27619,
63,
807,
8,
68,
29,
429,
576,
59,
498,
467,
75,
29,
4850,
63,
5919,
63,
72,
1580,
9,
267,
5137,
59,
65,
1474,
61,
275,
8671,
63,
11225,
63,
3670,
63,
6221,
8,
28461,
379,
63,
11225,
9,
2286,
691,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
2798,
8,
519,
11329,
12,
812,
6092,
18,
59,
65,
1474,
2733,
3670,
995,
2326,
29,
2326,
8,
65,
1474,
395,
3660,
9100,
534,
14382,
1302,
628,
4,
90,
2458,
19,
14,
17,
70,
17351,
450,
282,
1474,
18,
581,
4723,
8,
65,
1474,
430,
421,
199,
387,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
4498,
63,
13007,
8,
82,
11329,
12,
812,
6092,
18,
59,
16,
14,
21,
2733,
2110,
995,
812,
6092,
18,
59,
16,
14,
21,
2733,
384,
995,
221,
639,
3164,
29,
2326,
8,
16,
14,
21,
395,
1315,
1648,
29,
16,
9,
10813,
199,
509,
282,
1474,
315,
282,
476,
1190,
520,
272,
367,
812,
12,
478,
315,
3482,
8,
13701,
12,
472,
20953,
83,
9,
520,
267,
27487,
63,
6857,
3347,
275,
664,
63,
11225,
63,
25035,
63,
3670,
63,
6221,
8,
288,
4615,
63,
2913,
17,
29,
54,
59,
65,
1474,
2733,
3670,
995,
288,
2729,
63,
2913,
17,
29,
54,
59,
65,
1474,
2733,
1391,
995,
288,
4615,
63,
2913,
18,
29,
54,
59,
16,
14,
21,
2733,
3670,
995,
288,
2729,
63,
2913,
18,
29,
54,
59,
16,
14,
21,
2733,
1391,
995,
288,
776,
398,
691,
14,
6402,
59,
70,
54,
16823,
17,
1055,
2798,
8,
519,
11329,
12,
27487,
63,
6857,
3347,
459,
3670,
995,
2490,
3164,
29,
2326,
8,
65,
1474,
395,
478,
29,
478,
9,
221,
8179,
199,
199,
387,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
10898,
8,
4850,
63,
1302,
12,
13222,
2687,
14,
2194,
12,
1275,
2194,
395,
13222,
505,
2687,
14,
19,
12,
413,
14,
19,
430,
199,
387,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
8284,
63,
1162,
8,
1302,
890,
29,
713,
9,
199,
387,
14,
6402,
59
] |
[
491,
5783,
10466,
14,
576,
63,
2308,
14,
362,
63,
4201,
63,
576,
492,
2372,
9581,
1451,
199,
504,
491,
5783,
10466,
14,
1208,
14,
1208,
492,
282,
1474,
18,
581,
4723,
199,
504,
491,
5783,
10466,
14,
2798,
1337,
14,
2537,
14,
8941,
63,
20034,
492,
627,
199,
504,
491,
5783,
10466,
14,
2798,
1337,
14,
11225,
14,
2537,
14,
11225,
63,
21188,
971,
272,
492,
627,
199,
504,
491,
5783,
10466,
14,
2798,
1337,
14,
11225,
14,
2537,
14,
2416,
63,
11225,
971,
272,
492,
15699,
63,
5919,
12,
27619,
63,
807,
199,
504,
491,
5783,
10466,
14,
1208,
14,
5559,
492,
519,
11329,
199,
504,
7131,
63,
698,
63,
5777,
492,
627,
199,
199,
2326,
275,
8027,
14,
4400,
14,
2756,
77,
8885,
63,
82,
199,
65,
476,
1190,
275,
359,
17,
14,
16,
12,
16,
14,
25,
12,
16,
14,
24,
12,
16,
14,
23,
12,
16,
14,
22,
12,
16,
14,
21,
12,
16,
14,
2322,
12,
16,
14,
20,
12,
16,
14,
1276,
61,
199,
4850,
63,
7227,
275,
359,
18,
14,
19,
12,
18,
14,
23,
61,
199,
4850,
63,
1302,
275,
519,
6808,
16,
14,
17,
70,
16827,
274,
81,
60,
4850,
7348,
5783,
67,
4988,
274,
81,
22074,
16,
14,
17,
70,
14007,
4850,
63,
7227,
59,
16,
467,
4850,
63,
7227,
59,
17,
566,
199,
697,
63,
354,
275,
283,
44,
5783,
63,
17774,
63,
16,
7,
199,
697,
63,
694,
275,
1994,
4219,
15,
26118,
16540,
816,
335,
15,
26872,
15,
497,
1712,
15,
44,
5783,
10466,
4805,
199,
199,
11225,
63,
513,
275,
788,
82,
63,
8523,
297,
20169,
283,
54,
6092,
18,
63,
54,
67,
5783,
67,
297,
326,
283,
45,
63,
13625,
297,
283,
45,
63,
7848,
297,
283,
45,
63,
24364,
297,
326,
283,
50,
15,
50,
5783,
67,
418,
199,
199,
72,
12201,
63,
3282,
63,
513,
2968,
82,
5783,
67,
1673,
45,
63,
2923,
63,
5783,
67,
1673,
4850,
63,
5783,
67,
418,
421,
199,
54,
6092,
18,
6884,
54,
67,
5783,
67,
29,
82,
2,
16827,
16488,
91,
54,
93,
29,
54,
62,
18,
7348,
67,
5995,
54,
62,
18,
7348,
67,
12,
5783,
67,
93,
17351,
199,
70,
54,
16823,
17,
29,
82,
2,
16827,
16488,
91,
54,
5995,
60,
16488,
91,
54,
22999,
90,
29,
17,
9,
17351,
199,
199,
387,
275,
14794,
20386,
8,
592,
354,
534,
54,
6092,
18,
63,
54,
67,
5783,
67,
63,
4850,
5,
16,
14,
17,
70,
5956,
4850,
63,
7227,
59,
16,
467,
1598,
7824,
16025,
16,
14,
1046,
12,
16,
14,
20,
12,
16,
14,
1257,
12,
16,
14,
1229,
6922,
16,
14,
1046,
12,
16,
14,
1046,
12,
16,
14,
1257,
12,
16,
14,
1194,
2365,
1598,
7824,
63,
3512,
1524,
54,
6092,
18,
6884,
54,
67,
5783,
67,
12,
70,
54,
16823,
17,
467,
1598,
671,
1302,
29,
82,
2,
4,
50,
15,
50,
7348,
5783,
67,
93,
11918,
1598,
671,
4175,
2687,
16,
14,
18,
12,
21,
395,
1598,
612,
31689,
17497,
16,
14,
22,
12,
17,
14,
20,
11865,
16,
14,
22,
12,
17,
14,
20,
3948,
199,
199,
54,
6092,
18,
7622,
199,
429,
1612,
275,
788,
54,
6092,
18,
63,
54,
67,
5783,
67,
418,
199,
13701,
275,
359,
54,
6092,
18,
61,
199,
472,
20953,
83,
275,
11573,
418,
199,
199,
509,
282,
1474,
315,
282,
476,
1190,
520,
272,
824,
576,
275,
2372,
9581,
1451,
8,
65,
1474,
29,
65,
1474,
12,
697,
63,
354,
29,
697,
63,
354,
12,
1169,
1592,
63,
694,
29,
697,
63,
694,
12,
1169,
17390,
63,
513,
29,
11225,
63,
513,
12,
1169,
394,
12201,
63,
3282,
63,
513,
29,
72,
12201,
63,
3282,
63,
513,
9,
2286,
15699,
63,
5919,
63,
72,
1580,
275,
15699,
63,
5919,
8,
4850,
29,
429,
576,
459,
4850,
63,
5783,
67,
995,
8765,
29,
4850,
63,
7227,
9,
339,
367,
5137,
12,
790,
315,
3482,
8,
13701,
12,
429,
1612,
9,
520,
267,
29501,
379,
63,
11225,
275,
27619,
63,
807,
8,
68,
29,
429,
576,
59,
498,
467,
75,
29,
4850,
63,
5919,
63,
72,
1580,
9,
267,
5137,
59,
65,
1474,
61,
275,
8671,
63,
11225,
63,
3670,
63,
6221,
8,
28461,
379,
63,
11225,
9,
2286,
691,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
2798,
8,
519,
11329,
12,
812,
6092,
18,
59,
65,
1474,
2733,
3670,
995,
2326,
29,
2326,
8,
65,
1474,
395,
3660,
9100,
534,
14382,
1302,
628,
4,
90,
2458,
19,
14,
17,
70,
17351,
450,
282,
1474,
18,
581,
4723,
8,
65,
1474,
430,
421,
199,
387,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
4498,
63,
13007,
8,
82,
11329,
12,
812,
6092,
18,
59,
16,
14,
21,
2733,
2110,
995,
812,
6092,
18,
59,
16,
14,
21,
2733,
384,
995,
221,
639,
3164,
29,
2326,
8,
16,
14,
21,
395,
1315,
1648,
29,
16,
9,
10813,
199,
509,
282,
1474,
315,
282,
476,
1190,
520,
272,
367,
812,
12,
478,
315,
3482,
8,
13701,
12,
472,
20953,
83,
9,
520,
267,
27487,
63,
6857,
3347,
275,
664,
63,
11225,
63,
25035,
63,
3670,
63,
6221,
8,
288,
4615,
63,
2913,
17,
29,
54,
59,
65,
1474,
2733,
3670,
995,
288,
2729,
63,
2913,
17,
29,
54,
59,
65,
1474,
2733,
1391,
995,
288,
4615,
63,
2913,
18,
29,
54,
59,
16,
14,
21,
2733,
3670,
995,
288,
2729,
63,
2913,
18,
29,
54,
59,
16,
14,
21,
2733,
1391,
995,
288,
776,
398,
691,
14,
6402,
59,
70,
54,
16823,
17,
1055,
2798,
8,
519,
11329,
12,
27487,
63,
6857,
3347,
459,
3670,
995,
2490,
3164,
29,
2326,
8,
65,
1474,
395,
478,
29,
478,
9,
221,
8179,
199,
199,
387,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
10898,
8,
4850,
63,
1302,
12,
13222,
2687,
14,
2194,
12,
1275,
2194,
395,
13222,
505,
2687,
14,
19,
12,
413,
14,
19,
430,
199,
387,
14,
6402,
59,
54,
6092,
18,
6884,
54,
67,
5783,
67,
1055,
8284,
63,
1162,
8,
1302,
890,
29,
713,
9,
199,
387,
14,
6402,
59,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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_power.py
|
38
|
3879
|
#!/usr/bin/python
# -*- 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/>.
try:
from pyghmi.ipmi import command
except ImportError:
command = None
from ansible.module_utils.basic import *
DOCUMENTATION = '''
---
module: ipmi_power
short_description: Power management for machine
description:
- Use this module for power management
version_added: "2.2"
options:
name:
description:
- Hostname or ip address of the BMC.
required: true
port:
description:
- Remote RMCP port.
required: false
type: int
default: 623
user:
description:
- Username to use to connect to the BMC.
required: true
password:
description:
- Password to connect to the BMC.
required: true
default: null
state:
description:
- Whether to ensure that the machine in desired state.
required: true
choices:
- on -- Request system turn on
- off -- Request system turn off without waiting for OS to shutdown
- shutdown -- Have system request OS proper shutdown
- reset -- Request system reset without waiting for OS
- boot -- If system is off, then 'on', else 'reset'
timeout:
description:
- Maximum number of seconds before interrupt request.
required: false
type: int
default: 300
requirements:
- "python >= 2.6"
- pyghmi
author: "Bulat Gaifullin (gaifullinbf@gmail.com)"
'''
RETURN = '''
powerstate:
description: The current power state of the machine.
returned: success
type: string
sample: on
'''
EXAMPLES = '''
# Ensure machine is powered on.
- ipmi_power: name="test.testdomain.com" user="admin" password="password" state="on"
'''
# ==================================================
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(required=True),
port=dict(default=623, type='int'),
state=dict(required=True, choices=['on', 'off', 'shutdown', 'reset', 'boot']),
user=dict(required=True, no_log=True),
password=dict(required=True, no_log=True),
timeout=dict(default=300, type='int'),
),
supports_check_mode=True,
)
if command is None:
module.fail_json(msg='the python pyghmi module is required')
name = module.params['name']
port = module.params['port']
user = module.params['user']
password = module.params['password']
state = module.params['state']
timeout = module.params['timeout']
# --- run command ---
try:
ipmi_cmd = command.Command(
bmc=name, userid=user, password=password, port=port
)
module.debug('ipmi instantiated - name: "%s"' % name)
current = ipmi_cmd.get_power()
if current['powerstate'] != state:
response = {'powerstate': state} if module.check_mode else ipmi_cmd.set_power(state, wait=timeout)
changed = True
else:
response = current
changed = False
if 'error' in response:
module.fail_json(msg=response['error'])
module.exit_json(changed=changed, **response)
except Exception as e:
module.fail_json(msg=str(e))
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
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,
893,
26,
272,
687,
1134,
3561,
2664,
14,
711,
2664,
492,
1414,
199,
2590,
3545,
26,
272,
1414,
275,
488,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
3384,
2664,
63,
5652,
199,
3612,
63,
1802,
26,
18879,
10041,
367,
6844,
199,
1802,
26,
523,
446,
3645,
642,
859,
367,
7074,
10041,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
10891,
354,
503,
3384,
2287,
402,
314,
699,
7608,
14,
272,
1415,
26,
2549,
523,
1844,
26,
272,
1369,
26,
489,
446,
17283,
820,
45,
2890,
1844,
14,
272,
1415,
26,
3055,
272,
730,
26,
1109,
272,
849,
26,
1227,
1789,
523,
922,
26,
272,
1369,
26,
489,
446,
29739,
370,
675,
370,
4907,
370,
314,
699,
7608,
14,
272,
1415,
26,
2549,
523,
2505,
26,
272,
1369,
26,
489,
446,
13635,
370,
4907,
370,
314,
699,
7608,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
4868,
626,
314,
6844,
315,
6387,
1174,
14,
272,
1415,
26,
2549,
272,
3415,
26,
267,
446,
641,
1553,
4784,
2656,
7485,
641,
267,
446,
2331,
1553,
4784,
2656,
7485,
2331,
1928,
10923,
367,
4403,
370,
12842,
267,
446,
12842,
1553,
26858,
2656,
1056,
4403,
5576,
12842,
267,
446,
5305,
1553,
4784,
2656,
5305,
1928,
10923,
367,
4403,
267,
446,
8498,
1553,
982,
2656,
365,
2331,
12,
2066,
283,
265,
297,
587,
283,
3958,
7,
523,
2653,
26,
272,
1369,
26,
489,
446,
14212,
1329,
402,
4696,
2544,
26791,
1056,
14,
272,
1415,
26,
3055,
272,
730,
26,
1109,
272,
849,
26,
9601,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
1134,
3561,
2664,
199,
2502,
26,
298,
34,
348,
292,
9647,
692,
348,
472,
334,
5294,
692,
348,
472,
4361,
32,
6799,
14,
957,
2924,
199,
2344,
199,
199,
9677,
275,
1449,
199,
5652,
929,
26,
272,
1369,
26,
710,
1453,
7074,
1174,
402,
314,
6844,
14,
272,
2138,
26,
3182,
272,
730,
26,
1059,
272,
2690,
26,
641,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
6844,
365,
13131,
16179,
641,
14,
199,
13,
3384,
2664,
63,
5652,
26,
536,
628,
396,
14,
396,
2261,
14,
957,
2,
922,
628,
2113,
2,
2505,
628,
2060,
2,
1174,
628,
265,
2,
199,
2344,
199,
199,
3,
19691,
29,
421,
199,
318,
2446,
837,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
536,
29,
807,
8,
2427,
29,
549,
395,
288,
1844,
29,
807,
8,
885,
29,
31353,
12,
730,
534,
442,
659,
288,
1174,
29,
807,
8,
2427,
29,
549,
12,
3415,
2968,
265,
297,
283,
1997,
297,
283,
8831,
297,
283,
3958,
297,
283,
4930,
3815,
288,
922,
29,
807,
8,
2427,
29,
549,
12,
949,
63,
793,
29,
549,
395,
288,
2505,
29,
807,
8,
2427,
29,
549,
12,
949,
63,
793,
29,
549,
395,
288,
2653,
29,
807,
8,
885,
29,
5863,
12,
730,
534,
442,
659,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
549,
12,
272,
776,
339,
340,
1414,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
1589,
2366,
1134,
3561,
2664,
859,
365,
1415,
358,
339,
536,
275,
859,
14,
1162,
459,
354,
418,
272,
1844,
275,
859,
14,
1162,
459,
719,
418,
272,
922,
275,
859,
14,
1162,
459,
751,
418,
272,
2505,
275,
859,
14,
1162,
459,
2060,
418,
272,
1174,
275,
859,
14,
1162,
459,
929,
418,
272,
2653,
275,
859,
14,
1162,
459,
2593,
418,
339,
327,
10894,
1255,
1414,
10894,
272,
862,
26,
267,
3384,
2664,
63,
1760,
275,
1414,
14,
3110,
8,
288,
330,
5466,
29,
354,
12,
25580,
29,
751,
12,
2505,
29,
2060,
12,
1844,
29,
719,
267,
776,
267,
859,
14,
1757,
360,
711,
2664,
17544,
446,
536,
26,
2071,
83,
4507,
450,
536,
9,
398,
1453,
275,
3384,
2664,
63,
1760,
14,
362,
63,
5652,
342,
267,
340,
1453,
459,
5652,
929,
418,
1137,
1174,
26,
288,
1177,
275,
791,
5652,
929,
356,
1174,
93,
340,
859,
14,
1074,
63,
632,
587,
3384,
2664,
63,
1760,
14,
409,
63,
5652,
8,
929,
12,
3618,
29,
2593,
9,
288,
2896,
275,
715,
267,
587,
26,
288,
1177,
275,
1453,
288,
2896,
275,
756,
398,
340,
283,
705,
7,
315,
1177,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
29,
1310,
459,
705,
1105,
398,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
1011,
1310,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
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,
893,
26,
272,
687,
1134,
3561,
2664,
14,
711,
2664,
492,
1414,
199,
2590,
3545,
26,
272,
1414,
275,
488,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
3384,
2664,
63,
5652,
199,
3612,
63,
1802,
26,
18879,
10041,
367,
6844,
199,
1802,
26,
523,
446,
3645,
642,
859,
367,
7074,
10041,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
10891,
354,
503,
3384,
2287,
402,
314,
699,
7608,
14,
272,
1415,
26,
2549,
523,
1844,
26,
272,
1369,
26,
489,
446,
17283,
820,
45,
2890,
1844,
14,
272,
1415,
26,
3055,
272,
730,
26,
1109,
272,
849,
26,
1227,
1789,
523,
922,
26,
272,
1369,
26,
489,
446,
29739,
370,
675,
370,
4907,
370,
314,
699,
7608,
14,
272,
1415,
26,
2549,
523,
2505,
26,
272,
1369,
26,
489,
446,
13635,
370,
4907,
370,
314,
699,
7608,
14,
272,
1415,
26,
2549,
272,
849,
26,
2973,
523,
1174,
26,
272,
1369,
26,
489,
446,
7480,
370,
4868,
626,
314,
6844,
315,
6387,
1174,
14,
272,
1415,
26,
2549,
272,
3415,
26,
267,
446,
641,
1553,
4784,
2656,
7485,
641,
267,
446,
2331,
1553,
4784,
2656,
7485,
2331,
1928,
10923,
367,
4403,
370,
12842,
267,
446,
12842,
1553,
26858,
2656,
1056,
4403,
5576,
12842,
267,
446,
5305,
1553,
4784,
2656,
5305,
1928,
10923,
367,
4403,
267,
446,
8498,
1553,
982,
2656,
365,
2331,
12,
2066,
283,
265,
297,
587,
283,
3958,
7,
523,
2653,
26,
272,
1369,
26,
489,
446,
14212,
1329,
402,
4696,
2544,
26791,
1056,
14,
272,
1415,
26,
3055,
272,
730,
26,
1109,
272,
849,
26,
9601,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
1134,
3561,
2664,
199,
2502,
26,
298,
34,
348,
292,
9647,
692,
348,
472,
334,
5294,
692,
348,
472,
4361,
32,
6799,
14,
957,
2924,
199,
2344,
199,
199,
9677,
275,
1449,
199,
5652,
929,
26,
272,
1369,
26,
710,
1453,
7074,
1174,
402,
314,
6844,
14,
272,
2138,
26,
3182,
272,
730,
26,
1059,
272,
2690,
26,
641,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
7523,
6844,
365,
13131,
16179,
641,
14,
199,
13,
3384,
2664,
63,
5652,
26,
536,
628,
396,
14,
396,
2261,
14,
957,
2,
922,
628,
2113,
2,
2505,
628,
2060,
2,
1174,
628,
265,
2,
199,
2344,
199,
199,
3,
19691,
29,
421,
199,
318,
2446,
837,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
536,
29,
807,
8,
2427,
29,
549,
395,
288,
1844,
29,
807,
8,
885,
29,
31353,
12,
730,
534,
442,
659,
288,
1174,
29,
807,
8,
2427,
29,
549,
12,
3415,
2968,
265,
297,
283,
1997,
297,
283,
8831,
297,
283,
3958,
297,
283,
4930,
3815,
288,
922,
29,
807,
8,
2427,
29,
549,
12,
949,
63,
793,
29,
549,
395,
288,
2505,
29,
807,
8,
2427,
29,
549,
12,
949,
63,
793,
29,
549,
395,
288,
2653,
29,
807,
8,
885,
29,
5863,
12,
730,
534,
442,
659,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
549,
12,
272,
776,
339,
340,
1414,
365,
488,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
1589,
2366,
1134,
3561,
2664,
859,
365,
1415,
358,
339,
536,
275,
859,
14,
1162,
459,
354,
418,
272,
1844,
275,
859,
14,
1162,
459,
719,
418,
272,
922,
275,
859,
14,
1162,
459,
751,
418,
272,
2505,
275,
859,
14,
1162,
459,
2060,
418,
272,
1174,
275,
859,
14,
1162,
459,
929,
418,
272,
2653,
275,
859,
14,
1162,
459,
2593,
418,
339,
327,
10894,
1255,
1414,
10894,
272,
862,
26,
267,
3384,
2664,
63,
1760,
275,
1414,
14,
3110,
8,
288,
330,
5466,
29,
354,
12,
25580,
29,
751,
12,
2505,
29,
2060,
12,
1844,
29,
719,
267,
776,
267,
859,
14,
1757,
360,
711,
2664,
17544,
446,
536,
26,
2071,
83,
4507,
450,
536,
9,
398,
1453,
275,
3384,
2664,
63,
1760,
14,
362,
63,
5652,
342,
267,
340,
1453,
459,
5652,
929,
418,
1137,
1174,
26,
288,
1177,
275,
791,
5652,
929,
356,
1174,
93,
340,
859,
14,
1074,
63,
632,
587,
3384,
2664,
63,
1760,
14,
409,
63,
5652,
8,
929,
12,
3618,
29,
2593,
9,
288,
2896,
275,
715,
267,
587,
26,
288,
1177,
275,
1453,
288,
2896,
275,
756,
398,
340,
283,
705,
7,
315,
1177,
26,
288,
859,
14,
1633,
63,
1001,
8,
1328,
29,
1310,
459,
705,
1105,
398,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
12,
1011,
1310,
9,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
studio666/gnuradio
|
gr-channels/python/channels/qa_fading_model.py
|
47
|
1949
|
#!/usr/bin/env python
#
# Copyright 2012,2013 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio 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, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, gr_unittest, analog, blocks, channels
import math
class test_fading_model(gr_unittest.TestCase):
def setUp(self):
self.tb = gr.top_block()
def tearDown(self):
self.tb = None
def test_000(self):
N = 1000 # number of samples to use
fs = 1000 # baseband sampling rate
freq = 100
fDTs = 0.01
K = 4
signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
head = blocks.head(gr.sizeof_gr_complex, N)
op = channels.fading_model(8, fDTs=fDTs, LOS=True,
K=K, seed=0)
snk = blocks.vector_sink_c()
snk1 = blocks.vector_sink_c()
self.assertAlmostEqual(K, op.K(), 4)
self.assertAlmostEqual(fDTs, op.fDTs(), 4)
#self.tb.connect(signal, head, op, snk)
#self.tb.connect(op, snk1)
#self.tb.run()
#dst_data = snk.data()
#exp_data = snk1.data()
#self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
if __name__ == '__main__':
gr_unittest.run(test_fading_model, "test_fading_model.xml")
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6029,
12,
6965,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
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,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
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,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
12,
20439,
12,
5664,
12,
9245,
199,
646,
3473,
199,
199,
533,
511,
63,
70,
5384,
63,
1238,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
1493,
8,
277,
304,
267,
653,
275,
5198,
260,
327,
1329,
402,
5845,
370,
675,
267,
7449,
275,
5198,
263,
327,
1300,
7877,
15877,
6634,
267,
9220,
275,
2948,
398,
289,
7438,
83,
275,
378,
14,
614,
267,
1804,
275,
841,
267,
4673,
275,
20439,
14,
4093,
63,
1365,
63,
67,
8,
2319,
12,
20439,
14,
3975,
63,
51,
568,
63,
32482,
12,
9220,
12,
413,
9,
267,
4854,
275,
5664,
14,
2993,
8,
2587,
14,
12590,
63,
2587,
63,
5254,
12,
653,
9,
267,
1687,
275,
9245,
14,
70,
5384,
63,
1238,
8,
24,
12,
289,
7438,
83,
29,
70,
7438,
83,
12,
491,
3100,
29,
549,
12,
3521,
1804,
29,
43,
12,
6347,
29,
16,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
267,
6895,
75,
17,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
398,
291,
14,
7904,
8,
43,
12,
1687,
14,
43,
1062,
841,
9,
267,
291,
14,
7904,
8,
70,
7438,
83,
12,
1687,
14,
70,
7438,
83,
1062,
841,
9,
398,
327,
277,
14,
5842,
14,
2242,
8,
4653,
12,
4854,
12,
1687,
12,
6895,
75,
9,
267,
327,
277,
14,
5842,
14,
2242,
8,
411,
12,
6895,
75,
17,
9,
267,
327,
277,
14,
5842,
14,
1065,
342,
398,
327,
5119,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
327,
1474,
63,
576,
275,
6895,
75,
17,
14,
576,
342,
267,
327,
277,
14,
479,
14500,
7075,
83,
7331,
8,
1474,
63,
576,
12,
5042,
63,
576,
12,
959,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
14,
1065,
8,
396,
63,
70,
5384,
63,
1238,
12,
298,
396,
63,
70,
5384,
63,
1238,
14,
1652,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6029,
12,
6965,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
1664,
13514,
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,
650,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
1664,
13514,
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,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
504,
24526,
492,
7192,
12,
7192,
63,
2796,
12,
20439,
12,
5664,
12,
9245,
199,
646,
3473,
199,
199,
533,
511,
63,
70,
5384,
63,
1238,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
511,
63,
1493,
8,
277,
304,
267,
653,
275,
5198,
260,
327,
1329,
402,
5845,
370,
675,
267,
7449,
275,
5198,
263,
327,
1300,
7877,
15877,
6634,
267,
9220,
275,
2948,
398,
289,
7438,
83,
275,
378,
14,
614,
267,
1804,
275,
841,
267,
4673,
275,
20439,
14,
4093,
63,
1365,
63,
67,
8,
2319,
12,
20439,
14,
3975,
63,
51,
568,
63,
32482,
12,
9220,
12,
413,
9,
267,
4854,
275,
5664,
14,
2993,
8,
2587,
14,
12590,
63,
2587,
63,
5254,
12,
653,
9,
267,
1687,
275,
9245,
14,
70,
5384,
63,
1238,
8,
24,
12,
289,
7438,
83,
29,
70,
7438,
83,
12,
491,
3100,
29,
549,
12,
3521,
1804,
29,
43,
12,
6347,
29,
16,
9,
267,
6895,
75,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
267,
6895,
75,
17,
275,
5664,
14,
4106,
63,
11279,
63,
67,
342,
398,
291,
14,
7904,
8,
43,
12,
1687,
14,
43,
1062,
841,
9,
267,
291,
14,
7904,
8,
70,
7438,
83,
12,
1687,
14,
70,
7438,
83,
1062,
841,
9,
398,
327,
277,
14,
5842,
14,
2242,
8,
4653,
12,
4854,
12,
1687,
12,
6895,
75,
9,
267,
327,
277,
14,
5842,
14,
2242,
8,
411,
12,
6895,
75,
17,
9,
267,
327,
277,
14,
5842,
14,
1065,
342,
398,
327,
5119,
63,
576,
275,
6895,
75,
14,
576,
342,
267,
327,
1474,
63,
576,
275,
6895,
75,
17,
14,
576,
342,
267,
327,
277,
14,
479,
14500,
7075,
83,
7331,
8,
1474,
63,
576,
12,
5042,
63,
576,
12,
959,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
14,
1065,
8,
396,
63,
70,
5384,
63,
1238,
12,
298,
396,
63,
70,
5384,
63,
1238,
14,
1652,
531,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
tobiaghiraldini/DjangoBBB
|
docs/source/conf.py
|
1
|
8027
|
# -*- coding: utf-8 -*-
#
# Django Backbone Boilerplate documentation build configuration file, created by
# sphinx-quickstart on Thu Sep 19 19:15:23 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.viewcode']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Django Backbone Boilerplate'
copyright = u'2013, Tobia Ghiraldini'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.0'
# The full version, including alpha/beta/rc tags.
release = '1.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'DjangoBackboneBoilerplatedoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'DjangoBackboneBoilerplate.tex', u'Django Backbone Boilerplate Documentation',
u'Tobia Ghiraldini', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'djangobackboneboilerplate', u'Django Backbone Boilerplate Documentation',
[u'Tobia Ghiraldini'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'DjangoBackboneBoilerplate', u'Django Backbone Boilerplate Documentation',
u'Tobia Ghiraldini', 'DjangoBackboneBoilerplate', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
5634,
10257,
21134,
5088,
27025,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
3868,
85,
428,
1545,
5851,
5851,
26,
1046,
26,
1789,
6171,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
283,
8008,
14,
832,
14,
11390,
297,
283,
8008,
14,
832,
14,
11396,
297,
283,
8008,
14,
832,
14,
10828,
297,
283,
8008,
14,
832,
14,
1345,
600,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
9323,
10257,
21134,
5088,
27025,
7,
199,
7307,
275,
399,
7,
6965,
12,
377,
2873,
4674,
598,
72,
723,
27075,
2730,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
17,
14,
16,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
17,
14,
16,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
5634,
10257,
21134,
5088,
27025,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
3868,
85,
428,
1545,
5851,
5851,
26,
1046,
26,
1789,
6171,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
28056,
297,
283,
8008,
14,
832,
14,
11390,
297,
283,
8008,
14,
832,
14,
11396,
297,
283,
8008,
14,
832,
14,
10828,
297,
283,
8008,
14,
832,
14,
1345,
600,
418,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
9323,
10257,
21134,
5088,
27025,
7,
199,
7307,
275,
399,
7,
6965,
12,
377,
2873,
4674,
598,
72,
723,
27075,
2730,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
17,
14,
16,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
17,
14,
16,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
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
] |
40223211/cadb_g7_w18test
|
static/Brython3.1.1-20150328-091302/Lib/textwrap.py
|
745
|
16488
|
"""Text wrapping and filling.
"""
# Copyright (C) 1999-2001 Gregory P. Ward.
# Copyright (C) 2002, 2003 Python Software Foundation.
# Written by Greg Ward <gward@python.net>
import re
__all__ = ['TextWrapper', 'wrap', 'fill', 'dedent', 'indent']
# Hardcode the recognized whitespace characters to the US-ASCII
# whitespace characters. The main reason for doing this is that in
# ISO-8859-1, 0xa0 is non-breaking whitespace, so in certain locales
# that character winds up in string.whitespace. Respecting
# string.whitespace in those cases would 1) make textwrap treat 0xa0 the
# same as any other whitespace char, which is clearly wrong (it's a
# *non-breaking* space), 2) possibly cause problems with Unicode,
# since 0xa0 is not in range(128).
_whitespace = '\t\n\x0b\x0c\r '
class TextWrapper:
"""
Object for wrapping/filling text. The public interface consists of
the wrap() and fill() methods; the other methods are just there for
subclasses to override in order to tweak the default behaviour.
If you want to completely replace the main wrapping algorithm,
you'll probably have to override _wrap_chunks().
Several instance attributes control various aspects of wrapping:
width (default: 70)
the maximum width of wrapped lines (unless break_long_words
is false)
initial_indent (default: "")
string that will be prepended to the first line of wrapped
output. Counts towards the line's width.
subsequent_indent (default: "")
string that will be prepended to all lines save the first
of wrapped output; also counts towards each line's width.
expand_tabs (default: true)
Expand tabs in input text to spaces before further processing.
Each tab will become 0 .. 'tabsize' spaces, depending on its position
in its line. If false, each tab is treated as a single character.
tabsize (default: 8)
Expand tabs in input text to 0 .. 'tabsize' spaces, unless
'expand_tabs' is false.
replace_whitespace (default: true)
Replace all whitespace characters in the input text by spaces
after tab expansion. Note that if expand_tabs is false and
replace_whitespace is true, every tab will be converted to a
single space!
fix_sentence_endings (default: false)
Ensure that sentence-ending punctuation is always followed
by two spaces. Off by default because the algorithm is
(unavoidably) imperfect.
break_long_words (default: true)
Break words longer than 'width'. If false, those words will not
be broken, and some lines might be longer than 'width'.
break_on_hyphens (default: true)
Allow breaking hyphenated words. If true, wrapping will occur
preferably on whitespaces and right after hyphens part of
compound words.
drop_whitespace (default: true)
Drop leading and trailing whitespace from lines.
"""
unicode_whitespace_trans = {}
uspace = ord(' ')
for x in _whitespace:
unicode_whitespace_trans[ord(x)] = uspace
# This funky little regex is just the trick for splitting
# text up into word-wrappable chunks. E.g.
# "Hello there -- you goof-ball, use the -b option!"
# splits into
# Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
# (after stripping out empty strings).
wordsep_re = re.compile(
r'(\s+|' # any whitespace
r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|' # hyphenated words
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))') # em-dash
# This less funky little regex just split on recognized spaces. E.g.
# "Hello there -- you goof-ball, use the -b option!"
# splits into
# Hello/ /there/ /--/ /you/ /goof-ball,/ /use/ /the/ /-b/ /option!/
wordsep_simple_re = re.compile(r'(\s+)')
# XXX this is not locale- or charset-aware -- string.lowercase
# is US-ASCII only (and therefore English-only)
sentence_end_re = re.compile(r'[a-z]' # lowercase letter
r'[\.\!\?]' # sentence-ending punct.
r'[\"\']?' # optional end-of-quote
r'\Z') # end of chunk
def __init__(self,
width=70,
initial_indent="",
subsequent_indent="",
expand_tabs=True,
replace_whitespace=True,
fix_sentence_endings=False,
break_long_words=True,
drop_whitespace=True,
break_on_hyphens=True,
tabsize=8):
self.width = width
self.initial_indent = initial_indent
self.subsequent_indent = subsequent_indent
self.expand_tabs = expand_tabs
self.replace_whitespace = replace_whitespace
self.fix_sentence_endings = fix_sentence_endings
self.break_long_words = break_long_words
self.drop_whitespace = drop_whitespace
self.break_on_hyphens = break_on_hyphens
self.tabsize = tabsize
# -- Private methods -----------------------------------------------
# (possibly useful for subclasses to override)
def _munge_whitespace(self, text):
"""_munge_whitespace(text : string) -> string
Munge whitespace in text: expand tabs and convert all other
whitespace characters to spaces. Eg. " foo\tbar\n\nbaz"
becomes " foo bar baz".
"""
if self.expand_tabs:
text = text.expandtabs(self.tabsize)
if self.replace_whitespace:
text = text.translate(self.unicode_whitespace_trans)
return text
def _split(self, text):
"""_split(text : string) -> [string]
Split the text to wrap into indivisible chunks. Chunks are
not quite the same as words; see _wrap_chunks() for full
details. As an example, the text
Look, goof-ball -- use the -b option!
breaks into the following chunks:
'Look,', ' ', 'goof-', 'ball', ' ', '--', ' ',
'use', ' ', 'the', ' ', '-b', ' ', 'option!'
if break_on_hyphens is True, or in:
'Look,', ' ', 'goof-ball', ' ', '--', ' ',
'use', ' ', 'the', ' ', '-b', ' ', option!'
otherwise.
"""
if self.break_on_hyphens is True:
chunks = self.wordsep_re.split(text)
else:
chunks = self.wordsep_simple_re.split(text)
chunks = [c for c in chunks if c]
return chunks
def _fix_sentence_endings(self, chunks):
"""_fix_sentence_endings(chunks : [string])
Correct for sentence endings buried in 'chunks'. Eg. when the
original text contains "... foo.\nBar ...", munge_whitespace()
and split() will convert that to [..., "foo.", " ", "Bar", ...]
which has one too few spaces; this method simply changes the one
space to two.
"""
i = 0
patsearch = self.sentence_end_re.search
while i < len(chunks)-1:
if chunks[i+1] == " " and patsearch(chunks[i]):
chunks[i+1] = " "
i += 2
else:
i += 1
def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width):
"""_handle_long_word(chunks : [string],
cur_line : [string],
cur_len : int, width : int)
Handle a chunk of text (most likely a word, not whitespace) that
is too long to fit in any line.
"""
# Figure out when indent is larger than the specified width, and make
# sure at least one character is stripped off on every pass
if width < 1:
space_left = 1
else:
space_left = width - cur_len
# If we're allowed to break long words, then do so: put as much
# of the next chunk onto the current line as will fit.
if self.break_long_words:
cur_line.append(reversed_chunks[-1][:space_left])
reversed_chunks[-1] = reversed_chunks[-1][space_left:]
# Otherwise, we have to preserve the long word intact. Only add
# it to the current line if there's nothing already there --
# that minimizes how much we violate the width constraint.
elif not cur_line:
cur_line.append(reversed_chunks.pop())
# If we're not allowed to break long words, and there's already
# text on the current line, do nothing. Next time through the
# main loop of _wrap_chunks(), we'll wind up here again, but
# cur_len will be zero, so the next line will be entirely
# devoted to the long word that we can't handle right now.
def _wrap_chunks(self, chunks):
"""_wrap_chunks(chunks : [string]) -> [string]
Wrap a sequence of text chunks and return a list of lines of
length 'self.width' or less. (If 'break_long_words' is false,
some lines may be longer than this.) Chunks correspond roughly
to words and the whitespace between them: each chunk is
indivisible (modulo 'break_long_words'), but a line break can
come between any two chunks. Chunks should not have internal
whitespace; ie. a chunk is either all whitespace or a "word".
Whitespace chunks will be removed from the beginning and end of
lines, but apart from that whitespace is preserved.
"""
lines = []
if self.width <= 0:
raise ValueError("invalid width %r (must be > 0)" % self.width)
# Arrange in reverse order so items can be efficiently popped
# from a stack of chucks.
chunks.reverse()
while chunks:
# Start the list of chunks that will make up the current line.
# cur_len is just the length of all the chunks in cur_line.
cur_line = []
cur_len = 0
# Figure out which static string will prefix this line.
if lines:
indent = self.subsequent_indent
else:
indent = self.initial_indent
# Maximum width for this line.
width = self.width - len(indent)
# First chunk on line is whitespace -- drop it, unless this
# is the very beginning of the text (ie. no lines started yet).
if self.drop_whitespace and chunks[-1].strip() == '' and lines:
del chunks[-1]
while chunks:
l = len(chunks[-1])
# Can at least squeeze this chunk onto the current line.
if cur_len + l <= width:
cur_line.append(chunks.pop())
cur_len += l
# Nope, this line is full.
else:
break
# The current line is full, and the next chunk is too big to
# fit on *any* line (not just this one).
if chunks and len(chunks[-1]) > width:
self._handle_long_word(chunks, cur_line, cur_len, width)
# If the last chunk on this line is all whitespace, drop it.
if self.drop_whitespace and cur_line and cur_line[-1].strip() == '':
del cur_line[-1]
# Convert current line back to a string and store it in list
# of all lines (return value).
if cur_line:
lines.append(indent + ''.join(cur_line))
return lines
# -- Public interface ----------------------------------------------
def wrap(self, text):
"""wrap(text : string) -> [string]
Reformat the single paragraph in 'text' so it fits in lines of
no more than 'self.width' columns, and return a list of wrapped
lines. Tabs in 'text' are expanded with string.expandtabs(),
and all other whitespace characters (including newline) are
converted to space.
"""
text = self._munge_whitespace(text)
chunks = self._split(text)
if self.fix_sentence_endings:
self._fix_sentence_endings(chunks)
return self._wrap_chunks(chunks)
def fill(self, text):
"""fill(text : string) -> string
Reformat the single paragraph in 'text' to fit in lines of no
more than 'self.width' columns, and return a new string
containing the entire wrapped paragraph.
"""
return "\n".join(self.wrap(text))
# -- Convenience interface ---------------------------------------------
def wrap(text, width=70, **kwargs):
"""Wrap a single paragraph of text, returning a list of wrapped lines.
Reformat the single paragraph in 'text' so it fits in lines of no
more than 'width' columns, and return a list of wrapped lines. By
default, tabs in 'text' are expanded with string.expandtabs(), and
all other whitespace characters (including newline) are converted to
space. See TextWrapper class for available keyword args to customize
wrapping behaviour.
"""
w = TextWrapper(width=width, **kwargs)
return w.wrap(text)
def fill(text, width=70, **kwargs):
"""Fill a single paragraph of text, returning a new string.
Reformat the single paragraph in 'text' to fit in lines of no more
than 'width' columns, and return a new string containing the entire
wrapped paragraph. As with wrap(), tabs are expanded and other
whitespace characters converted to space. See TextWrapper class for
available keyword args to customize wrapping behaviour.
"""
w = TextWrapper(width=width, **kwargs)
return w.fill(text)
# -- Loosely related functionality -------------------------------------
_whitespace_only_re = re.compile('^[ \t]+$', re.MULTILINE)
_leading_whitespace_re = re.compile('(^[ \t]*)(?:[^ \t\n])', re.MULTILINE)
def dedent(text):
"""Remove any common leading whitespace from every line in `text`.
This can be used to make triple-quoted strings line up with the left
edge of the display, while still presenting them in the source code
in indented form.
Note that tabs and spaces are both treated as whitespace, but they
are not equal: the lines " hello" and "\thello" are
considered to have no common leading whitespace. (This behaviour is
new in Python 2.5; older versions of this module incorrectly
expanded tabs before searching for common leading whitespace.)
"""
# Look for the longest leading string of spaces and tabs common to
# all lines.
margin = None
text = _whitespace_only_re.sub('', text)
indents = _leading_whitespace_re.findall(text)
for indent in indents:
if margin is None:
margin = indent
# Current line more deeply indented than previous winner:
# no change (previous winner is still on top).
elif indent.startswith(margin):
pass
# Current line consistent with and no deeper than previous winner:
# it's the new winner.
elif margin.startswith(indent):
margin = indent
# Current line and previous winner have no common whitespace:
# there is no margin.
else:
margin = ""
break
# sanity check (testing/debugging only)
if 0 and margin:
for line in text.split("\n"):
assert not line or line.startswith(margin), \
"line = %r, margin = %r" % (line, margin)
if margin:
text = re.sub(r'(?m)^' + margin, '', text)
return text
def indent(text, prefix, predicate=None):
"""Adds 'prefix' to the beginning of selected lines in 'text'.
If 'predicate' is provided, 'prefix' will only be added to the lines
where 'predicate(line)' is True. If 'predicate' is not provided,
it will default to adding 'prefix' to all non-empty lines that do not
consist solely of whitespace characters.
"""
if predicate is None:
def predicate(line):
return line.strip()
def prefixed_lines():
for line in text.splitlines(True):
yield (prefix + line if predicate(line) else line)
return ''.join(prefixed_lines())
if __name__ == "__main__":
#print dedent("\tfoo\n\tbar")
#print dedent(" \thello there\n \t how are you?")
print(dedent("Hello there.\n This is indented."))
|
gpl-3.0
|
[
624,
1872,
19696,
436,
32499,
14,
199,
624,
199,
199,
3,
1898,
334,
35,
9,
21300,
13,
8339,
29096,
1089,
510,
14,
644,
1005,
14,
199,
3,
1898,
334,
35,
9,
14790,
12,
13004,
2018,
2290,
2752,
14,
199,
3,
27694,
701,
29096,
644,
1005,
665,
71,
3079,
32,
1548,
14,
846,
30,
199,
199,
646,
295,
199,
199,
363,
452,
363,
275,
788,
1872,
4590,
297,
283,
3823,
297,
283,
4498,
297,
283,
14674,
297,
283,
3724,
418,
199,
199,
3,
22825,
600,
314,
18054,
8139,
4110,
370,
314,
19635,
13,
12292,
199,
3,
8139,
4110,
14,
221,
710,
2446,
4499,
367,
9689,
642,
365,
626,
315,
199,
3,
9055,
13,
4830,
13,
17,
12,
378,
1800,
16,
365,
2222,
13,
4785,
316,
8139,
12,
880,
315,
9842,
24847,
199,
3,
626,
4528,
15417,
83,
1536,
315,
1059,
14,
8506,
14,
221,
3591,
1764,
316,
199,
3,
1059,
14,
8506,
315,
5204,
5560,
3955,
413,
9,
1852,
13390,
14312,
378,
1800,
16,
314,
199,
3,
2011,
465,
1263,
1163,
8139,
1495,
12,
1314,
365,
5436,
590,
6835,
334,
390,
1159,
282,
199,
3,
627,
2865,
13,
4785,
316,
10,
4601,
395,
499,
9,
12570,
7675,
8826,
543,
6140,
12,
199,
3,
3967,
378,
1800,
16,
365,
440,
315,
1425,
8,
3933,
680,
199,
63,
8506,
275,
1557,
84,
60,
78,
60,
88,
16,
66,
60,
88,
16,
67,
60,
82,
283,
199,
199,
533,
4516,
4590,
26,
272,
408,
272,
6935,
367,
19696,
15,
4498,
316,
1318,
14,
221,
710,
4575,
3217,
18581,
402,
272,
314,
4816,
342,
436,
5554,
342,
3102,
27,
314,
1163,
3102,
787,
2951,
2337,
367,
272,
9180,
370,
4278,
315,
1865,
370,
32464,
314,
849,
13942,
14,
272,
982,
1265,
2934,
370,
14793,
3350,
314,
2446,
19696,
5563,
12,
272,
1265,
7171,
8646,
1172,
370,
4278,
485,
3823,
63,
10660,
1252,
339,
3240,
422,
279,
1256,
3004,
3304,
7750,
17435,
83,
402,
19696,
26,
489,
3462,
334,
885,
26,
10045,
9,
267,
314,
5696,
3462,
402,
8072,
2385,
334,
18447,
2059,
63,
2809,
63,
3148,
267,
365,
3055,
9,
489,
2536,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
314,
1642,
1004,
402,
8072,
267,
1072,
14,
221,
14826,
83,
28354,
314,
1004,
1159,
3462,
14,
489,
13372,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
1006,
2385,
3354,
314,
1642,
267,
402,
8072,
1072,
27,
2597,
8242,
28354,
1924,
1004,
1159,
3462,
14,
489,
6544,
63,
8741,
334,
885,
26,
2549,
9,
267,
18890,
12187,
315,
1324,
1318,
370,
7883,
2544,
9848,
6661,
14,
267,
7048,
5174,
911,
8649,
378,
2508,
283,
2902,
890,
7,
7883,
12,
10298,
641,
2399,
3421,
267,
315,
2399,
1004,
14,
221,
982,
3055,
12,
1924,
5174,
365,
10184,
465,
282,
2849,
4528,
14,
489,
5174,
890,
334,
885,
26,
1695,
9,
267,
18890,
12187,
315,
1324,
1318,
370,
378,
2508,
283,
2902,
890,
7,
7883,
12,
7444,
267,
283,
4441,
63,
8741,
7,
365,
3055,
14,
489,
3350,
63,
8506,
334,
885,
26,
2549,
9,
267,
14402,
1006,
8139,
4110,
315,
314,
1324,
1318,
701,
7883,
267,
2410,
5174,
14819,
14,
221,
3390,
626,
340,
6544,
63,
8741,
365,
3055,
436,
267,
3350,
63,
8506,
365,
2549,
12,
4036,
5174,
911,
506,
6702,
370,
282,
267,
2849,
4601,
1,
489,
5325,
63,
17727,
63,
500,
780,
334,
885,
26,
3055,
9,
267,
7523,
626,
14537,
13,
3219,
22929,
365,
3544,
9437,
267,
701,
2877,
7883,
14,
221,
28856,
701,
849,
2952,
314,
5563,
365,
267,
334,
324,
27403,
6665,
9,
1742,
31740,
449,
14,
489,
2059,
63,
2809,
63,
3148,
334,
885,
26,
2549,
9,
267,
22535,
5932,
8088,
2419,
283,
2063,
1370,
221,
982,
3055,
12,
5204,
5932,
911,
440,
267,
506,
10529,
12,
436,
2005,
2385,
5594,
506,
8088,
2419,
283,
2063,
1370,
489,
2059,
63,
265,
63,
3577,
27920,
334,
885,
26,
2549,
9,
267,
9812,
27485,
7188,
17579,
972,
5932,
14,
982,
2549,
12,
19696,
911,
4781,
267,
16602,
6665,
641,
704,
31926,
436,
2451,
2410,
7188,
27920,
1777,
402,
267,
16487,
5932,
14,
489,
5978,
63,
8506,
334,
885,
26,
2549,
9,
267,
18110,
9186,
436,
8520,
8139,
687,
2385,
14,
272,
408,
339,
2649,
63,
8506,
63,
1515,
275,
1052,
272,
399,
2638,
275,
6206,
360,
5320,
272,
367,
671,
315,
485,
8506,
26,
267,
2649,
63,
8506,
63,
1515,
59,
2181,
8,
88,
1874,
275,
399,
2638,
339,
327,
961,
289,
1778,
89,
12050,
5163,
365,
2951,
314,
20907,
367,
26518,
272,
327,
1318,
1536,
1901,
4349,
13,
87,
345,
802,
461,
8291,
14,
221,
662,
14,
71,
14,
272,
327,
257,
298,
6257,
2337,
1553,
1265,
486,
1534,
70,
13,
8571,
12,
675,
314,
446,
66,
945,
9539,
272,
327,
19115,
1901,
272,
327,
257,
23833,
15,
1182,
16990,
15,
1182,
306,
15,
1182,
13297,
15,
1182,
29546,
70,
13,
15,
8571,
12,
15,
1182,
1180,
15,
1182,
1589,
15,
1182,
13,
66,
15,
1182,
1422,
1,
272,
327,
334,
4399,
4024,
3637,
734,
2701,
3326,
680,
272,
4349,
4127,
63,
264,
275,
295,
14,
2014,
8,
267,
519,
13445,
83,
11,
5227,
22456,
327,
1263,
8139,
267,
519,
29538,
83,
60,
87,
25739,
87,
11,
4735,
16,
13,
25,
60,
55,
11285,
2229,
9529,
87,
11,
4735,
16,
13,
25,
60,
55,
566,
5227,
257,
327,
7188,
17579,
972,
5932,
267,
519,
10120,
28,
32296,
87,
60,
12525,
3212,
1154,
28103,
3134,
4202,
31,
566,
24185,
18,
28209,
2229,
9529,
87,
28435,
257,
327,
18564,
13,
6760,
339,
327,
961,
6656,
289,
1778,
89,
12050,
5163,
2951,
3715,
641,
18054,
7883,
14,
662,
14,
71,
14,
272,
327,
257,
298,
6257,
2337,
1553,
1265,
486,
1534,
70,
13,
8571,
12,
675,
314,
446,
66,
945,
9539,
272,
327,
19115,
1901,
272,
327,
257,
23833,
15,
1182,
16990,
15,
1182,
306,
15,
1182,
13297,
15,
1182,
29546,
70,
13,
8571,
12,
15,
1182,
1180,
15,
1182,
1589,
15,
1182,
13,
66,
15,
1182,
1422,
1,
15,
272,
4349,
4127,
63,
4129,
63,
264,
275,
295,
14,
2014,
8,
82,
13445,
83,
11,
5942,
339,
327,
5787,
642,
365,
440,
5867,
13,
503,
5960
] |
[
1872,
19696,
436,
32499,
14,
199,
624,
199,
199,
3,
1898,
334,
35,
9,
21300,
13,
8339,
29096,
1089,
510,
14,
644,
1005,
14,
199,
3,
1898,
334,
35,
9,
14790,
12,
13004,
2018,
2290,
2752,
14,
199,
3,
27694,
701,
29096,
644,
1005,
665,
71,
3079,
32,
1548,
14,
846,
30,
199,
199,
646,
295,
199,
199,
363,
452,
363,
275,
788,
1872,
4590,
297,
283,
3823,
297,
283,
4498,
297,
283,
14674,
297,
283,
3724,
418,
199,
199,
3,
22825,
600,
314,
18054,
8139,
4110,
370,
314,
19635,
13,
12292,
199,
3,
8139,
4110,
14,
221,
710,
2446,
4499,
367,
9689,
642,
365,
626,
315,
199,
3,
9055,
13,
4830,
13,
17,
12,
378,
1800,
16,
365,
2222,
13,
4785,
316,
8139,
12,
880,
315,
9842,
24847,
199,
3,
626,
4528,
15417,
83,
1536,
315,
1059,
14,
8506,
14,
221,
3591,
1764,
316,
199,
3,
1059,
14,
8506,
315,
5204,
5560,
3955,
413,
9,
1852,
13390,
14312,
378,
1800,
16,
314,
199,
3,
2011,
465,
1263,
1163,
8139,
1495,
12,
1314,
365,
5436,
590,
6835,
334,
390,
1159,
282,
199,
3,
627,
2865,
13,
4785,
316,
10,
4601,
395,
499,
9,
12570,
7675,
8826,
543,
6140,
12,
199,
3,
3967,
378,
1800,
16,
365,
440,
315,
1425,
8,
3933,
680,
199,
63,
8506,
275,
1557,
84,
60,
78,
60,
88,
16,
66,
60,
88,
16,
67,
60,
82,
283,
199,
199,
533,
4516,
4590,
26,
272,
408,
272,
6935,
367,
19696,
15,
4498,
316,
1318,
14,
221,
710,
4575,
3217,
18581,
402,
272,
314,
4816,
342,
436,
5554,
342,
3102,
27,
314,
1163,
3102,
787,
2951,
2337,
367,
272,
9180,
370,
4278,
315,
1865,
370,
32464,
314,
849,
13942,
14,
272,
982,
1265,
2934,
370,
14793,
3350,
314,
2446,
19696,
5563,
12,
272,
1265,
7171,
8646,
1172,
370,
4278,
485,
3823,
63,
10660,
1252,
339,
3240,
422,
279,
1256,
3004,
3304,
7750,
17435,
83,
402,
19696,
26,
489,
3462,
334,
885,
26,
10045,
9,
267,
314,
5696,
3462,
402,
8072,
2385,
334,
18447,
2059,
63,
2809,
63,
3148,
267,
365,
3055,
9,
489,
2536,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
314,
1642,
1004,
402,
8072,
267,
1072,
14,
221,
14826,
83,
28354,
314,
1004,
1159,
3462,
14,
489,
13372,
63,
3724,
334,
885,
26,
6899,
267,
1059,
626,
911,
506,
20247,
370,
1006,
2385,
3354,
314,
1642,
267,
402,
8072,
1072,
27,
2597,
8242,
28354,
1924,
1004,
1159,
3462,
14,
489,
6544,
63,
8741,
334,
885,
26,
2549,
9,
267,
18890,
12187,
315,
1324,
1318,
370,
7883,
2544,
9848,
6661,
14,
267,
7048,
5174,
911,
8649,
378,
2508,
283,
2902,
890,
7,
7883,
12,
10298,
641,
2399,
3421,
267,
315,
2399,
1004,
14,
221,
982,
3055,
12,
1924,
5174,
365,
10184,
465,
282,
2849,
4528,
14,
489,
5174,
890,
334,
885,
26,
1695,
9,
267,
18890,
12187,
315,
1324,
1318,
370,
378,
2508,
283,
2902,
890,
7,
7883,
12,
7444,
267,
283,
4441,
63,
8741,
7,
365,
3055,
14,
489,
3350,
63,
8506,
334,
885,
26,
2549,
9,
267,
14402,
1006,
8139,
4110,
315,
314,
1324,
1318,
701,
7883,
267,
2410,
5174,
14819,
14,
221,
3390,
626,
340,
6544,
63,
8741,
365,
3055,
436,
267,
3350,
63,
8506,
365,
2549,
12,
4036,
5174,
911,
506,
6702,
370,
282,
267,
2849,
4601,
1,
489,
5325,
63,
17727,
63,
500,
780,
334,
885,
26,
3055,
9,
267,
7523,
626,
14537,
13,
3219,
22929,
365,
3544,
9437,
267,
701,
2877,
7883,
14,
221,
28856,
701,
849,
2952,
314,
5563,
365,
267,
334,
324,
27403,
6665,
9,
1742,
31740,
449,
14,
489,
2059,
63,
2809,
63,
3148,
334,
885,
26,
2549,
9,
267,
22535,
5932,
8088,
2419,
283,
2063,
1370,
221,
982,
3055,
12,
5204,
5932,
911,
440,
267,
506,
10529,
12,
436,
2005,
2385,
5594,
506,
8088,
2419,
283,
2063,
1370,
489,
2059,
63,
265,
63,
3577,
27920,
334,
885,
26,
2549,
9,
267,
9812,
27485,
7188,
17579,
972,
5932,
14,
982,
2549,
12,
19696,
911,
4781,
267,
16602,
6665,
641,
704,
31926,
436,
2451,
2410,
7188,
27920,
1777,
402,
267,
16487,
5932,
14,
489,
5978,
63,
8506,
334,
885,
26,
2549,
9,
267,
18110,
9186,
436,
8520,
8139,
687,
2385,
14,
272,
408,
339,
2649,
63,
8506,
63,
1515,
275,
1052,
272,
399,
2638,
275,
6206,
360,
5320,
272,
367,
671,
315,
485,
8506,
26,
267,
2649,
63,
8506,
63,
1515,
59,
2181,
8,
88,
1874,
275,
399,
2638,
339,
327,
961,
289,
1778,
89,
12050,
5163,
365,
2951,
314,
20907,
367,
26518,
272,
327,
1318,
1536,
1901,
4349,
13,
87,
345,
802,
461,
8291,
14,
221,
662,
14,
71,
14,
272,
327,
257,
298,
6257,
2337,
1553,
1265,
486,
1534,
70,
13,
8571,
12,
675,
314,
446,
66,
945,
9539,
272,
327,
19115,
1901,
272,
327,
257,
23833,
15,
1182,
16990,
15,
1182,
306,
15,
1182,
13297,
15,
1182,
29546,
70,
13,
15,
8571,
12,
15,
1182,
1180,
15,
1182,
1589,
15,
1182,
13,
66,
15,
1182,
1422,
1,
272,
327,
334,
4399,
4024,
3637,
734,
2701,
3326,
680,
272,
4349,
4127,
63,
264,
275,
295,
14,
2014,
8,
267,
519,
13445,
83,
11,
5227,
22456,
327,
1263,
8139,
267,
519,
29538,
83,
60,
87,
25739,
87,
11,
4735,
16,
13,
25,
60,
55,
11285,
2229,
9529,
87,
11,
4735,
16,
13,
25,
60,
55,
566,
5227,
257,
327,
7188,
17579,
972,
5932,
267,
519,
10120,
28,
32296,
87,
60,
12525,
3212,
1154,
28103,
3134,
4202,
31,
566,
24185,
18,
28209,
2229,
9529,
87,
28435,
257,
327,
18564,
13,
6760,
339,
327,
961,
6656,
289,
1778,
89,
12050,
5163,
2951,
3715,
641,
18054,
7883,
14,
662,
14,
71,
14,
272,
327,
257,
298,
6257,
2337,
1553,
1265,
486,
1534,
70,
13,
8571,
12,
675,
314,
446,
66,
945,
9539,
272,
327,
19115,
1901,
272,
327,
257,
23833,
15,
1182,
16990,
15,
1182,
306,
15,
1182,
13297,
15,
1182,
29546,
70,
13,
8571,
12,
15,
1182,
1180,
15,
1182,
1589,
15,
1182,
13,
66,
15,
1182,
1422,
1,
15,
272,
4349,
4127,
63,
4129,
63,
264,
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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
] |
Workday/OpenFrame
|
tools/telemetry/third_party/altgraph/doc/conf.py
|
25
|
6931
|
# -*- coding: utf-8 -*-
#
# altgraph documentation build configuration file, created by
# sphinx-quickstart on Tue Aug 31 11:04:49 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
def get_version():
fn = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
'setup.cfg')
for ln in open(fn):
if ln.startswith('version'):
version = ln.split('=')[-1].strip()
return version
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.append(os.path.abspath('.'))
sys.path.insert(0,
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.autodoc' ]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'altgraph'
copyright = u'2010-2011, Ronald Oussoren, Bob Ippolito, 2004 Istvan Albert'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = get_version()
# The full version, including alpha/beta/rc tags.
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'nature'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
html_show_sourcelink = False
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'altgraphdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'altgraph.tex', u'altgraph Documentation',
u'Ronald Oussoren', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'python': ('http://docs.python.org/', None) }
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
8791,
2180,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
25298,
7105,
4119,
26,
966,
26,
1887,
7129,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
318,
664,
63,
1023,
837,
272,
4325,
275,
747,
14,
515,
14,
904,
8,
288,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
395,
288,
283,
2758,
14,
4128,
358,
272,
367,
10359,
315,
1551,
8,
2324,
304,
267,
340,
10359,
14,
2460,
360,
1023,
735,
288,
1015,
275,
10359,
14,
1294,
23917,
1988,
17,
1055,
1913,
342,
288,
372,
1015,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
24535,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
267,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
363,
7845,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
1058,
8008,
297,
283,
8008,
14,
832,
14,
11396,
297,
283,
8008,
14,
832,
14,
28056,
7,
1622,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
4478,
2180,
7,
199,
7307,
275,
399,
7,
6542,
13,
8128,
12,
820,
8125,
68,
593,
27678,
720,
78,
12,
699,
2873,
31045,
555,
317,
475,
12,
8353,
473,
270,
20662,
4580,
12504,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
664,
63,
1023,
342,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
1015,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
8247,
626,
9296,
1133,
506,
5120,
315,
314,
1900,
14,
199,
3,
8618,
63,
4757,
275,
942,
199,
199,
3,
3820,
402,
6602,
12,
3847,
370,
1350,
2082,
12,
626,
9296,
1133,
506,
17543,
199,
3,
367,
1350,
1584,
14,
199,
5473,
63,
14635,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
16593,
5857,
17915,
626,
11492,
543,
199,
3,
10229,
787,
5544,
283,
885,
7,
436,
283,
8008,
1301,
1370,
199,
1360,
63,
7915,
275,
283,
78,
1463,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
8791,
2180,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
25298,
7105,
4119,
26,
966,
26,
1887,
7129,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
318,
664,
63,
1023,
837,
272,
4325,
275,
747,
14,
515,
14,
904,
8,
288,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
395,
288,
283,
2758,
14,
4128,
358,
272,
367,
10359,
315,
1551,
8,
2324,
304,
267,
340,
10359,
14,
2460,
360,
1023,
735,
288,
1015,
275,
10359,
14,
1294,
23917,
1988,
17,
1055,
1913,
342,
288,
372,
1015,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
4832,
24535,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
267,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
363,
7845,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
788,
8008,
14,
832,
14,
1058,
8008,
297,
283,
8008,
14,
832,
14,
11396,
297,
283,
8008,
14,
832,
14,
28056,
7,
1622,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
4478,
2180,
7,
199,
7307,
275,
399,
7,
6542,
13,
8128,
12,
820,
8125,
68,
593,
27678,
720,
78,
12,
699,
2873,
31045,
555,
317,
475,
12,
8353,
473,
270,
20662,
4580,
12504,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
664,
63,
1023,
342,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
1015,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
3671,
275,
488,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
8247,
626,
9296,
1133,
506,
5120,
315,
314,
1900,
14,
199,
3,
8618,
63,
4757,
275,
942,
199,
199,
3,
3820,
402,
6602,
12,
3847,
370,
1350,
2082,
12,
626,
9296,
1133,
506,
17543,
199,
3,
367,
1350,
1584,
14,
199,
5473,
63,
14635,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
16593,
5857,
17915,
626,
11492,
543,
199,
3,
10229,
787,
5544,
283,
885,
7,
436,
283,
8008,
1301,
1370,
199,
1360,
63,
7915,
275,
283,
78,
1463,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
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,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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
] |
SphinxKnight/kuma
|
kuma/wiki/tests/test_managers.py
|
2
|
10496
|
from datetime import datetime
import pytest
from ..constants import REDIRECT_CONTENT
from ..models import (Document, DocumentTag, LocalizationTag, ReviewTag,
Revision)
@pytest.fixture
def redirect_doc(root_doc, wiki_user):
"""A redirect document."""
html = REDIRECT_CONTENT % {'href': root_doc.get_absolute_url(),
'title': root_doc.title}
doc = Document.objects.create(locale='en-US', slug='OldRoot', html=html)
doc.current_revision = Revision.objects.create(
document=doc,
creator=wiki_user,
content=html,
created=datetime(2017, 10, 27, 17, 4))
doc.save()
return doc
@pytest.fixture
def archive_doc(wiki_user):
"""An archived document."""
archive = Document.objects.create(locale='en-US', slug='Archive',
title='Archive of obsolete content')
doc = Document.objects.create(locale='en-US', slug='Archive/Doc',
title='Archived document',
parent_topic=archive)
doc.current_revision = Revision.objects.create(
document=doc,
creator=wiki_user,
content='<p>Obsolete content.</p>',
comment='Obsolete content',
created=datetime(2017, 10, 27, 15, 48))
doc.save()
return doc
def test_get_queryset(root_doc):
"""Managers are customized for including / excluding deleted documents."""
deleted_doc = Document.objects.create(locale='en-US', slug='Deleted',
title='Deleted Document',
deleted=True)
assert Document.admin_objects.all().count() == 2
assert list(Document.objects.all()) == [root_doc]
assert list(Document.deleted_objects.all()) == [deleted_doc]
def test_get_natural_key(root_doc):
"""The locale + slug is the natural key for Documents."""
assert root_doc.natural_key() == (root_doc.locale, root_doc.slug)
assert root_doc == Document.objects.get_by_natural_key(root_doc.locale,
root_doc.slug)
@pytest.mark.parametrize(
'legacy_slug',
('User:ethertank',
'Talk:Developer_Guide/Build_Instructions/Windows_Prerequisites',
'User_talk:ethertank',
'Template_talk:anch',
'Project_talk:To-do_list',
))
def test_documents_filter_for_list_exclude_slug_prefixes(root_doc, legacy_slug):
"""filter_for_list excludes some slug prefixes."""
Document.objects.create(locale='en-US', slug=legacy_slug)
results = Document.objects.filter_for_list()
assert len(results) == 1
assert results[0] == root_doc
def test_documents_filter_for_list_exclude_redirects(root_doc, redirect_doc):
"""filter_for_list excludes redirects"""
assert list(Document.objects.filter_for_list()) == [root_doc]
def test_documents_filter_for_list_by_locale(root_doc, trans_doc):
"""filter_for_list can filter by locale."""
results = Document.objects.filter_for_list(locale=trans_doc.locale)
assert list(results) == [trans_doc]
def test_documents_filter_for_list_by_tag(root_doc):
"""filter_for_list can filter by a DocumentTag."""
tag_foo = DocumentTag.objects.create(name='foo')
tag_bar = DocumentTag.objects.create(name='bar')
root_doc.tags.add(tag_foo)
assert list(Document.objects.filter_for_list(tag=tag_foo)) == [root_doc]
assert len(Document.objects.filter_for_list(tag=tag_bar)) == 0
def test_documents_filter_for_list_by_tag_name(root_doc):
"""filter_for_list can filter by a DocumentTag name."""
tag_foo = DocumentTag.objects.create(name='foo')
root_doc.tags.add(tag_foo)
assert list(Document.objects.filter_for_list(tag_name='foo')) == [root_doc]
assert len(Document.objects.filter_for_list(tag_name='bar')) == 0
def test_documents_filter_for_list_by_errors(root_doc):
"""filter_for_list can filter by Documents with render errors."""
assert root_doc.rendered_errors is None
assert len(Document.objects.filter_for_list(errors=True)) == 0
root_doc.rendered_errors = '[]'
root_doc.save()
assert len(Document.objects.filter_for_list(errors=True)) == 0
root_doc.rendered_errors = '[{"name": "kumascript", "level": "error"}]'
root_doc.save()
assert list(Document.objects.filter_for_list(errors=True)) == [root_doc]
def test_documents_filter_for_list_by_noparent(root_doc, trans_doc):
"""filter_for_list can filter by Documents with no parent."""
assert list(Document.objects.filter_for_list(noparent=True)) == [root_doc]
result = Document.objects.filter_for_list(locale=trans_doc.locale,
noparent=True)
assert len(result) == 0
trans_doc.parent = None
trans_doc.save()
result = Document.objects.filter_for_list(locale=trans_doc.locale,
noparent=True)
assert list(result) == [trans_doc]
def test_documents_filter_for_list_by_toplevel(root_doc):
"""filter_for_list can filter by top-level Documents (no parent topic)."""
Document.objects.create(locale=root_doc.locale,
parent_topic=root_doc,
slug=root_doc.slug + '/Child',
title='Child Document')
assert len(Document.objects.filter_for_list()) == 2
assert list(Document.objects.filter_for_list(toplevel=True)) == [root_doc]
def test_documents_filter_for_review(create_revision):
"""filter_for_review can filter all documents with a review tag."""
assert len(Document.objects.filter_for_review()) == 0
create_revision.review_tags.set('tag')
doc = create_revision.document
assert list(Document.objects.filter_for_review()) == [doc]
def test_documents_filter_for_review_by_locale(create_revision, trans_revision):
"""filter_for_review can filter by locale."""
create_revision.review_tags.set('tag')
trans_revision.review_tags.set('other_tag')
assert len(Document.objects.filter_for_review()) == 2
doc = create_revision.document
resp = list(Document.objects.filter_for_review(locale=doc.locale))
assert resp == [doc]
def test_documents_filter_for_review_by_tag_name(create_revision):
"""filter_for_review can filter by ReviewTtag name."""
assert len(Document.objects.filter_for_review(tag_name='editorial')) == 0
assert len(Document.objects.filter_for_review(tag_name='technical')) == 0
create_revision.review_tags.set('editorial')
resp = list(Document.objects.filter_for_review(tag_name='editorial'))
assert resp == [create_revision.document]
assert len(Document.objects.filter_for_review(tag_name='technical')) == 0
def test_documents_filter_for_review_by_tag(create_revision):
"""filter_for_review can filter by ReviewTag instance."""
editorial, _ = ReviewTag.objects.get_or_create(name='editorial')
technical, _ = ReviewTag.objects.get_or_create(name='technical')
assert len(Document.objects.filter_for_review(tag=editorial)) == 0
assert len(Document.objects.filter_for_review(tag=technical)) == 0
create_revision.review_tags.add(technical)
assert len(Document.objects.filter_for_review(tag=editorial)) == 0
resp = list(Document.objects.filter_for_review(tag=technical))
assert resp == [create_revision.document]
def test_documents_filter_for_review_excludes_redirects(redirect_doc):
"""bug 1274874: filter_for_review excludes redirects."""
redirect_doc.current_revision.review_tags.set('editorial')
resp = Document.objects.filter_for_review(tag_name='editorial')
assert len(resp) == 0
def test_documents_filter_for_review_excludes_archive(archive_doc):
"""bug 1274874: filter_for_review excludes archive documents."""
archive_doc.current_revision.review_tags.set('editorial')
resp = Document.objects.filter_for_review(tag_name='editorial')
assert len(resp) == 0
def test_documents_filter_with_localization_tag(create_revision):
"""filter_with_localization_tag can filter all documents."""
assert len(Document.objects.filter_with_localization_tag()) == 0
create_revision.localization_tags.set('tag')
doc = create_revision.document
assert list(Document.objects.filter_with_localization_tag()) == [doc]
def test_documents_filter_with_localization_tag_by_locale(create_revision,
trans_revision):
"""filter_with_localization_tag can filter by locale."""
create_revision.localization_tags.set('tag')
trans_revision.localization_tags.set('other_tag')
assert len(Document.objects.filter_with_localization_tag()) == 2
doc = create_revision.document
resp = Document.objects.filter_with_localization_tag(locale=doc.locale)
assert list(resp) == [doc]
def test_documents_filter_with_localization_tag_by_tag_name(create_revision):
"""filter_with_localization_tag can filter by LocalizationTag name."""
tag = 'inprogress'
resp = Document.objects.filter_with_localization_tag(tag_name=tag)
assert len(resp) == 0
create_revision.localization_tags.set('inprogress')
resp = Document.objects.filter_with_localization_tag(tag_name=tag)
assert list(resp) == [create_revision.document]
def test_documents_filter_with_localization_tag_by_tag(create_revision):
"""filter_with_localization_tag can filter by the instance."""
inprogress = LocalizationTag.objects.create(name='inprogress')
resp = Document.objects.filter_with_localization_tag(tag=inprogress)
assert len(resp) == 0
create_revision.localization_tags.add(inprogress)
resp = Document.objects.filter_with_localization_tag(tag=inprogress)
assert list(resp) == [create_revision.document]
def test_documents_filter_with_localization_tag_excludes_redirects(
redirect_doc):
"""bug 1274874: filter_with_localization_tag excludes redirects."""
tag = 'inprogress'
redirect_doc.current_revision.localization_tags.set(tag)
resp = Document.objects.filter_with_localization_tag(tag_name=tag)
assert len(resp) == 0
def test_documents_filter_with_localization_tag_excludes_archive(archive_doc):
"""bug 1274874: filter_with_localization_tag excludes archive docs."""
tag = 'inprogress'
archive_doc.current_revision.localization_tags.set(tag)
resp = Document.objects.filter_with_localization_tag(tag_name=tag)
assert len(resp) == 0
|
mpl-2.0
|
[
504,
2197,
492,
2197,
199,
199,
646,
4613,
199,
199,
504,
2508,
5559,
492,
820,
7458,
4168,
63,
9663,
199,
504,
2508,
992,
492,
334,
5564,
12,
7543,
1931,
12,
10111,
2072,
1931,
12,
26705,
1931,
12,
1993,
27095,
9,
421,
199,
32,
4462,
14,
5997,
199,
318,
4660,
63,
1301,
8,
1231,
63,
1301,
12,
17195,
63,
751,
304,
272,
408,
33,
4660,
2213,
1041,
272,
3517,
275,
820,
7458,
4168,
63,
9663,
450,
791,
6399,
356,
1738,
63,
1301,
14,
362,
63,
6116,
63,
633,
1062,
3044,
283,
1213,
356,
1738,
63,
1301,
14,
1213,
93,
272,
1382,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
16411,
6405,
297,
3517,
29,
1360,
9,
272,
1382,
14,
1818,
63,
5792,
275,
27095,
14,
1462,
14,
981,
8,
267,
2213,
29,
1301,
12,
267,
14875,
29,
6797,
63,
751,
12,
267,
1564,
29,
1360,
12,
267,
2737,
29,
2083,
8,
10680,
12,
1616,
12,
8087,
12,
5557,
12,
841,
430,
272,
1382,
14,
2117,
342,
272,
372,
1382,
421,
199,
32,
4462,
14,
5997,
199,
318,
6359,
63,
1301,
8,
6797,
63,
751,
304,
272,
408,
2493,
3819,
12905,
2213,
1041,
272,
6359,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
13042,
297,
4228,
2538,
534,
13042,
402,
24985,
1564,
358,
272,
1382,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
13042,
15,
3768,
297,
3303,
2538,
534,
8438,
12905,
2213,
297,
3303,
1676,
63,
5746,
29,
6404,
9,
272,
1382,
14,
1818,
63,
5792,
275,
27095,
14,
1462,
14,
981,
8,
267,
2213,
29,
1301,
12,
267,
14875,
29,
6797,
63,
751,
12,
267,
1564,
15829,
80,
30,
11394,
15445,
1564,
9758,
80,
4206,
267,
3721,
534,
11394,
15445,
1564,
297,
267,
2737,
29,
2083,
8,
10680,
12,
1616,
12,
8087,
12,
4114,
12,
9615,
430,
272,
1382,
14,
2117,
342,
272,
372,
1382,
421,
199,
318,
511,
63,
362,
63,
7924,
8,
1231,
63,
1301,
304,
272,
408,
2395,
10246,
787,
26707,
367,
5893,
1182,
28529,
5463,
8247,
1041,
272,
5463,
63,
1301,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
17735,
297,
5101,
2538,
534,
17735,
7543,
297,
5101,
5463,
29,
549,
9,
272,
702,
7543,
14,
2113,
63,
1462,
14,
452,
1252,
835,
342,
508,
499,
272,
702,
769,
8,
5564,
14,
1462,
14,
452,
1012,
508,
359,
1231,
63,
1301,
61,
272,
702,
769,
8,
5564,
14,
6062,
63,
1462,
14,
452,
1012,
508,
359,
6062,
63,
1301,
61,
421,
199,
318,
511,
63,
362,
63,
15759,
63,
498,
8,
1231,
63,
1301,
304,
272,
408,
1918,
5867,
435,
8889,
365,
314,
19981,
790,
367,
21361,
1041,
272,
702,
1738,
63,
1301,
14,
15759,
63,
498,
342,
508,
334,
1231,
63,
1301,
14,
5508,
12,
1738,
63,
1301,
14,
5464,
9,
272,
702,
1738,
63,
1301,
508,
7543,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
8,
1231,
63,
1301,
14,
5508,
12,
15491,
1738,
63,
1301,
14,
5464,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
10000,
63,
5464,
297,
272,
661,
1899,
26,
27732,
84,
3580,
297,
1362,
283,
52,
4878,
26,
31032,
63,
4324,
271,
15,
3425,
63,
607,
10583,
15,
8647,
63,
2398,
30140,
297,
1362,
283,
1899,
63,
21890,
26,
27732,
84,
3580,
297,
1362,
283,
4231,
63,
21890,
26,
290,
335,
297,
1362,
283,
4761,
63,
21890,
26,
1378,
13,
1117,
63,
513,
297,
1362,
5082,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
5473,
63,
5464,
63,
14124,
8,
1231,
63,
1301,
12,
12139,
63,
5464,
304,
272,
408,
1541,
63,
509,
63,
513,
23388,
2005,
8889,
13158,
1041,
272,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
29,
10000,
63,
5464,
9,
272,
2058,
275,
7543,
14,
1462,
14,
1541,
63,
509,
63,
513,
342,
272,
702,
822,
8,
2604,
9,
508,
413,
272,
702,
2058,
59,
16,
61,
508,
1738,
63,
1301,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
5473,
63,
13607,
8,
1231,
63,
1301,
12,
4660,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
23388,
17784,
624,
272,
702,
769,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
1012,
508,
359,
1231,
63,
1301,
61,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
991,
63,
5508,
8,
1231,
63,
1301,
12,
1752,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
883,
2457,
701,
5867,
1041,
272,
2058,
275,
7543,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
5508,
29,
1515,
63,
1301,
14,
5508,
9,
272,
702,
769,
8,
2604,
9,
508,
359,
1515,
63,
1301,
61,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
991,
63,
1450,
8,
1231,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
883,
2457,
701,
282,
7543,
1931,
1041,
272,
1947,
63,
1421,
275,
7543,
1931,
14,
1462,
14,
981,
8,
354,
534,
1421,
358,
272,
1947,
63,
1700,
275,
7543,
1931,
14,
1462,
14,
981,
8,
354,
534,
1700,
358,
272,
1738,
63,
1301,
14,
2969,
14,
525,
8,
1450,
63,
1421,
9,
272,
702,
769,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
1450,
29,
1450,
63,
1421,
430,
508,
359,
1231,
63,
1301,
61,
272,
702,
822,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
1450,
29,
1450,
63,
1700,
430,
508,
378,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
991,
63,
1450,
63,
354,
8,
1231,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
883,
2457,
701,
282,
7543,
1931,
536,
1041,
272,
1947,
63,
1421,
275,
7543,
1931,
14,
1462,
14,
981,
8,
354,
534,
1421,
358,
272,
1738,
63,
1301,
14,
2969,
14,
525,
8,
1450,
63,
1421,
9,
272,
702,
769,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
1450,
63,
354,
534,
1421,
1333,
508,
359,
1231,
63,
1301
] |
[
2197,
492,
2197,
199,
199,
646,
4613,
199,
199,
504,
2508,
5559,
492,
820,
7458,
4168,
63,
9663,
199,
504,
2508,
992,
492,
334,
5564,
12,
7543,
1931,
12,
10111,
2072,
1931,
12,
26705,
1931,
12,
1993,
27095,
9,
421,
199,
32,
4462,
14,
5997,
199,
318,
4660,
63,
1301,
8,
1231,
63,
1301,
12,
17195,
63,
751,
304,
272,
408,
33,
4660,
2213,
1041,
272,
3517,
275,
820,
7458,
4168,
63,
9663,
450,
791,
6399,
356,
1738,
63,
1301,
14,
362,
63,
6116,
63,
633,
1062,
3044,
283,
1213,
356,
1738,
63,
1301,
14,
1213,
93,
272,
1382,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
16411,
6405,
297,
3517,
29,
1360,
9,
272,
1382,
14,
1818,
63,
5792,
275,
27095,
14,
1462,
14,
981,
8,
267,
2213,
29,
1301,
12,
267,
14875,
29,
6797,
63,
751,
12,
267,
1564,
29,
1360,
12,
267,
2737,
29,
2083,
8,
10680,
12,
1616,
12,
8087,
12,
5557,
12,
841,
430,
272,
1382,
14,
2117,
342,
272,
372,
1382,
421,
199,
32,
4462,
14,
5997,
199,
318,
6359,
63,
1301,
8,
6797,
63,
751,
304,
272,
408,
2493,
3819,
12905,
2213,
1041,
272,
6359,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
13042,
297,
4228,
2538,
534,
13042,
402,
24985,
1564,
358,
272,
1382,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
13042,
15,
3768,
297,
3303,
2538,
534,
8438,
12905,
2213,
297,
3303,
1676,
63,
5746,
29,
6404,
9,
272,
1382,
14,
1818,
63,
5792,
275,
27095,
14,
1462,
14,
981,
8,
267,
2213,
29,
1301,
12,
267,
14875,
29,
6797,
63,
751,
12,
267,
1564,
15829,
80,
30,
11394,
15445,
1564,
9758,
80,
4206,
267,
3721,
534,
11394,
15445,
1564,
297,
267,
2737,
29,
2083,
8,
10680,
12,
1616,
12,
8087,
12,
4114,
12,
9615,
430,
272,
1382,
14,
2117,
342,
272,
372,
1382,
421,
199,
318,
511,
63,
362,
63,
7924,
8,
1231,
63,
1301,
304,
272,
408,
2395,
10246,
787,
26707,
367,
5893,
1182,
28529,
5463,
8247,
1041,
272,
5463,
63,
1301,
275,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
534,
17735,
297,
5101,
2538,
534,
17735,
7543,
297,
5101,
5463,
29,
549,
9,
272,
702,
7543,
14,
2113,
63,
1462,
14,
452,
1252,
835,
342,
508,
499,
272,
702,
769,
8,
5564,
14,
1462,
14,
452,
1012,
508,
359,
1231,
63,
1301,
61,
272,
702,
769,
8,
5564,
14,
6062,
63,
1462,
14,
452,
1012,
508,
359,
6062,
63,
1301,
61,
421,
199,
318,
511,
63,
362,
63,
15759,
63,
498,
8,
1231,
63,
1301,
304,
272,
408,
1918,
5867,
435,
8889,
365,
314,
19981,
790,
367,
21361,
1041,
272,
702,
1738,
63,
1301,
14,
15759,
63,
498,
342,
508,
334,
1231,
63,
1301,
14,
5508,
12,
1738,
63,
1301,
14,
5464,
9,
272,
702,
1738,
63,
1301,
508,
7543,
14,
1462,
14,
362,
63,
991,
63,
15759,
63,
498,
8,
1231,
63,
1301,
14,
5508,
12,
15491,
1738,
63,
1301,
14,
5464,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
10000,
63,
5464,
297,
272,
661,
1899,
26,
27732,
84,
3580,
297,
1362,
283,
52,
4878,
26,
31032,
63,
4324,
271,
15,
3425,
63,
607,
10583,
15,
8647,
63,
2398,
30140,
297,
1362,
283,
1899,
63,
21890,
26,
27732,
84,
3580,
297,
1362,
283,
4231,
63,
21890,
26,
290,
335,
297,
1362,
283,
4761,
63,
21890,
26,
1378,
13,
1117,
63,
513,
297,
1362,
5082,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
5473,
63,
5464,
63,
14124,
8,
1231,
63,
1301,
12,
12139,
63,
5464,
304,
272,
408,
1541,
63,
509,
63,
513,
23388,
2005,
8889,
13158,
1041,
272,
7543,
14,
1462,
14,
981,
8,
5508,
534,
287,
13,
1668,
297,
8889,
29,
10000,
63,
5464,
9,
272,
2058,
275,
7543,
14,
1462,
14,
1541,
63,
509,
63,
513,
342,
272,
702,
822,
8,
2604,
9,
508,
413,
272,
702,
2058,
59,
16,
61,
508,
1738,
63,
1301,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
5473,
63,
13607,
8,
1231,
63,
1301,
12,
4660,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
23388,
17784,
624,
272,
702,
769,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
1012,
508,
359,
1231,
63,
1301,
61,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
991,
63,
5508,
8,
1231,
63,
1301,
12,
1752,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
883,
2457,
701,
5867,
1041,
272,
2058,
275,
7543,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
5508,
29,
1515,
63,
1301,
14,
5508,
9,
272,
702,
769,
8,
2604,
9,
508,
359,
1515,
63,
1301,
61,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
991,
63,
1450,
8,
1231,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
883,
2457,
701,
282,
7543,
1931,
1041,
272,
1947,
63,
1421,
275,
7543,
1931,
14,
1462,
14,
981,
8,
354,
534,
1421,
358,
272,
1947,
63,
1700,
275,
7543,
1931,
14,
1462,
14,
981,
8,
354,
534,
1700,
358,
272,
1738,
63,
1301,
14,
2969,
14,
525,
8,
1450,
63,
1421,
9,
272,
702,
769,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
1450,
29,
1450,
63,
1421,
430,
508,
359,
1231,
63,
1301,
61,
272,
702,
822,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
1450,
29,
1450,
63,
1700,
430,
508,
378,
421,
199,
318,
511,
63,
12233,
63,
1541,
63,
509,
63,
513,
63,
991,
63,
1450,
63,
354,
8,
1231,
63,
1301,
304,
272,
408,
1541,
63,
509,
63,
513,
883,
2457,
701,
282,
7543,
1931,
536,
1041,
272,
1947,
63,
1421,
275,
7543,
1931,
14,
1462,
14,
981,
8,
354,
534,
1421,
358,
272,
1738,
63,
1301,
14,
2969,
14,
525,
8,
1450,
63,
1421,
9,
272,
702,
769,
8,
5564,
14,
1462,
14,
1541,
63,
509,
63,
513,
8,
1450,
63,
354,
534,
1421,
1333,
508,
359,
1231,
63,
1301,
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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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
gigglesninja/senior-design
|
MissionPlanner/Lib/getpass.py
|
233
|
5563
|
"""Utilities to get a password and/or the current user name.
getpass(prompt[, stream]) - Prompt for a password, with echo turned off.
getuser() - Get the user name from the environment or password database.
GetPassWarning - This UserWarning is issued when getpass() cannot prevent
echoing of the password contents while reading.
On Windows, the msvcrt module will be used.
On the Mac EasyDialogs.AskPassword is used, if available.
"""
# Authors: Piers Lauder (original)
# Guido van Rossum (Windows support and cleanup)
# Gregory P. Smith (tty support & GetPassWarning)
import os, sys, warnings
__all__ = ["getpass","getuser","GetPassWarning"]
class GetPassWarning(UserWarning): pass
def unix_getpass(prompt='Password: ', stream=None):
"""Prompt for a password, with echo turned off.
Args:
prompt: Written on stream to ask for the input. Default: 'Password: '
stream: A writable file object to display the prompt. Defaults to
the tty. If no tty is available defaults to sys.stderr.
Returns:
The seKr3t input.
Raises:
EOFError: If our input tty or stdin was closed.
GetPassWarning: When we were unable to turn echo off on the input.
Always restores terminal settings before returning.
"""
fd = None
tty = None
try:
# Always try reading and writing directly on the tty first.
fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY)
tty = os.fdopen(fd, 'w+', 1)
input = tty
if not stream:
stream = tty
except EnvironmentError, e:
# If that fails, see if stdin can be controlled.
try:
fd = sys.stdin.fileno()
except (AttributeError, ValueError):
passwd = fallback_getpass(prompt, stream)
input = sys.stdin
if not stream:
stream = sys.stderr
if fd is not None:
passwd = None
try:
old = termios.tcgetattr(fd) # a copy to save
new = old[:]
new[3] &= ~termios.ECHO # 3 == 'lflags'
tcsetattr_flags = termios.TCSAFLUSH
if hasattr(termios, 'TCSASOFT'):
tcsetattr_flags |= termios.TCSASOFT
try:
termios.tcsetattr(fd, tcsetattr_flags, new)
passwd = _raw_input(prompt, stream, input=input)
finally:
termios.tcsetattr(fd, tcsetattr_flags, old)
stream.flush() # issue7208
except termios.error, e:
if passwd is not None:
# _raw_input succeeded. The final tcsetattr failed. Reraise
# instead of leaving the terminal in an unknown state.
raise
# We can't control the tty or stdin. Give up and use normal IO.
# fallback_getpass() raises an appropriate warning.
del input, tty # clean up unused file objects before blocking
passwd = fallback_getpass(prompt, stream)
stream.write('\n')
return passwd
def win_getpass(prompt='Password: ', stream=None):
"""Prompt for password with echo off, using Windows getch()."""
if sys.stdin is not sys.__stdin__:
return fallback_getpass(prompt, stream)
import msvcrt
for c in prompt:
msvcrt.putch(c)
pw = ""
while 1:
c = msvcrt.getch()
if c == '\r' or c == '\n':
break
if c == '\003':
raise KeyboardInterrupt
if c == '\b':
pw = pw[:-1]
else:
pw = pw + c
msvcrt.putch('\r')
msvcrt.putch('\n')
return pw
def fallback_getpass(prompt='Password: ', stream=None):
warnings.warn("Can not control echo on the terminal.", GetPassWarning,
stacklevel=2)
if not stream:
stream = sys.stderr
print >>stream, "Warning: Password input may be echoed."
return _raw_input(prompt, stream)
def _raw_input(prompt="", stream=None, input=None):
# A raw_input() replacement that doesn't save the string in the
# GNU readline history.
if not stream:
stream = sys.stderr
if not input:
input = sys.stdin
prompt = str(prompt)
if prompt:
stream.write(prompt)
stream.flush()
# NOTE: The Python C API calls flockfile() (and unlock) during readline.
line = input.readline()
if not line:
raise EOFError
if line[-1] == '\n':
line = line[:-1]
return line
def getuser():
"""Get the username from the environment or password database.
First try various environment variables, then the password
database. This works on Windows as long as USERNAME is set.
"""
import os
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
user = os.environ.get(name)
if user:
return user
# If this fails, the exception will "explain" why
import pwd
return pwd.getpwuid(os.getuid())[0]
# Bind the name getpass to the appropriate function
try:
import termios
# it's possible there is an incompatible termios from the
# McMillan Installer, make sure we have a UNIX-compatible termios
termios.tcgetattr, termios.tcsetattr
except (ImportError, AttributeError):
try:
import msvcrt
except ImportError:
try:
from EasyDialogs import AskPassword
except ImportError:
getpass = fallback_getpass
else:
getpass = AskPassword
else:
getpass = win_getpass
else:
getpass = unix_getpass
|
gpl-2.0
|
[
624,
22905,
370,
664,
282,
2505,
436,
15,
269,
314,
1453,
922,
536,
14,
199,
199,
27481,
8,
7650,
14675,
2547,
566,
446,
2165,
4787,
367,
282,
2505,
12,
543,
11343,
19136,
2331,
14,
199,
362,
751,
342,
446,
2372,
314,
922,
536,
687,
314,
3734,
503,
2505,
3050,
14,
199,
199,
1002,
4986,
3849,
446,
961,
2876,
3849,
365,
21117,
1380,
18354,
342,
3913,
7981,
326,
11343,
316,
402,
314,
2505,
4072,
1830,
7664,
14,
199,
199,
3314,
5417,
12,
314,
31756,
859,
911,
506,
1202,
14,
199,
3314,
314,
10444,
18951,
1341,
18238,
14,
25525,
6139,
365,
1202,
12,
340,
2808,
14,
199,
199,
624,
199,
199,
3,
6642,
26,
19835,
1192,
491,
3844,
424,
334,
5043,
9,
199,
3,
3515,
598,
1535,
79,
20744,
6848,
385,
453,
334,
8647,
2291,
436,
9058,
9,
199,
3,
3515,
29096,
1089,
510,
14,
25924,
334,
4707,
2291,
1253,
2372,
4986,
3849,
9,
199,
199,
646,
747,
12,
984,
12,
3598,
199,
199,
363,
452,
363,
275,
2097,
27481,
2266,
362,
751,
2266,
1002,
4986,
3849,
937,
421,
199,
533,
2372,
4986,
3849,
8,
32114,
304,
986,
421,
199,
318,
16572,
63,
27481,
8,
7650,
534,
6139,
26,
1656,
2547,
29,
403,
304,
272,
408,
20430,
367,
282,
2505,
12,
543,
11343,
19136,
2331,
14,
339,
3033,
26,
489,
8457,
26,
27694,
641,
2547,
370,
7198,
367,
314,
1324,
14,
221,
3758,
26,
283,
6139,
26,
283,
489,
2547,
26,
437,
17267,
570,
909,
370,
2929,
314,
8457,
14,
221,
7827,
370,
1598,
314,
21862,
14,
221,
982,
949,
21862,
365,
2808,
4243,
370,
984,
14,
3083,
14,
272,
1803,
26,
489,
710,
542,
27399,
19,
84,
1324,
14,
272,
6218,
26,
489,
21157,
26,
982,
4154,
1324,
21862,
503,
9009,
1990,
6876,
14,
489,
2372,
4986,
3849,
26,
3979,
781,
4898,
17329,
370,
7485,
11343,
2331,
641,
314,
1324,
14,
339,
16763,
4618,
7944,
11167,
2202,
2544,
8152,
14,
272,
408,
272,
6111,
275,
488,
272,
21862,
275,
488,
272,
862,
26,
267,
327,
16763,
862,
7664,
436,
3575,
5370,
641,
314,
21862,
1642,
14,
267,
6111,
275,
747,
14,
1490,
2336,
2374,
15,
4707,
297,
747,
14,
47,
63,
15543,
6524,
92,
736,
14,
47,
63,
2826,
1028,
2099,
9,
267,
21862,
275,
747,
14,
23140,
8,
2592,
12,
283,
87,
7386,
413,
9,
267,
1324,
275,
21862,
267,
340,
440,
2547,
26,
288,
2547,
275,
21862,
272,
871,
25139,
12,
325,
26,
267,
327,
982,
626,
6918,
12,
1937,
340,
9009,
883,
506,
22284,
14,
267,
862,
26,
288,
6111,
275,
984,
14,
6626,
14,
9843,
342,
267,
871,
334,
10227,
12,
1722,
304,
288,
15081,
275,
9567,
63,
27481,
8,
7650,
12,
2547,
9,
267,
1324,
275,
984,
14,
6626,
267,
340,
440,
2547,
26,
288,
2547,
275,
984,
14,
3083,
339,
340,
6111,
365,
440,
488,
26,
267,
15081,
275,
488,
267,
862,
26,
288,
2269,
275,
28725,
14,
3641,
5675,
8,
2592,
9,
258,
327,
282,
1331,
370,
3354,
288,
892,
275,
2269,
5873,
288,
892,
59,
19,
61,
18415,
6146,
351,
24597,
14,
37,
10465,
221,
327,
650,
508,
283,
276,
1550,
7,
288,
14415,
10202,
63,
2469,
275,
28725,
14,
52,
3298,
33,
32762,
288,
340,
2688,
8,
351,
24597,
12,
283,
52,
3298,
1179,
47,
2161,
735,
355,
14415,
10202,
63,
2469,
8901,
28725,
14,
52,
3298,
1179,
47,
2161,
288,
862,
26,
355,
28725,
14,
3641,
10202,
8,
2592,
12,
14415,
10202,
63,
2469,
12,
892,
9,
355,
15081,
275,
485,
1773,
63,
1210,
8,
7650,
12,
2547,
12,
1324,
29,
1210,
9,
288,
3753,
26,
355,
28725,
14,
3641,
10202,
8,
2592,
12,
14415,
10202,
63,
2469,
12,
2269,
9,
355,
2547,
14,
4939,
342,
221,
327,
4976,
23,
10630,
267,
871,
28725,
14,
705,
12,
325,
26,
288,
340,
15081,
365,
440,
488,
26,
355,
327,
485,
1773,
63,
1210,
19268,
14,
221,
710,
4242,
14415,
10202,
3405,
14,
221,
820,
32311,
572,
355,
327,
3140,
402,
23188,
314,
11167,
315,
376,
5809,
1174,
14,
355,
746,
288,
327,
2136,
883,
1133,
3304,
314,
21862,
503,
9009,
14,
221,
25495,
1536,
436,
675,
3293,
5004,
14,
288,
327,
9567,
63,
27481,
342,
6534,
376,
5827,
5721,
14,
288,
2150,
1324,
12,
21862,
221,
327,
3633,
1536,
9563,
570,
2251,
2544,
14592,
288,
15081,
275,
9567,
63,
27481,
8,
7650,
12,
2547,
9,
339,
2547,
14,
952,
2258,
78,
358,
272,
372,
15081,
421,
199,
318,
4747,
63,
27481,
8,
7650,
534,
6139,
26,
1656,
2547,
29,
403,
304,
272,
408,
20430,
367,
2505,
543,
11343,
2331,
12,
1808,
5417,
664,
335,
20693,
272,
340,
984,
14,
6626,
365,
440,
984,
855,
6626,
10651,
267,
372,
9567,
63,
27481,
8,
7650,
12,
2547,
9,
272,
492,
31756,
272,
367,
286,
315,
8457,
26,
267,
31756,
14,
524,
335,
8,
67,
9,
272,
19206,
275,
3087,
272,
1830,
413,
26,
267,
286,
275,
31756,
14,
362,
335,
342,
267,
340,
286,
508,
1557,
82,
7,
503,
286,
508,
1557,
78,
356,
288,
2059,
267,
340,
286,
508,
1557,
8262,
356,
288,
746,
13483,
267,
340,
286,
508,
1557,
66,
356,
288,
19206,
275,
19206,
4439,
17,
61,
267,
587,
26,
288,
19206,
275,
19206,
435,
286,
272,
31756,
14,
524,
335,
2258,
82,
358,
272,
31756,
14,
524,
335,
2258,
78,
358,
272,
372,
19206,
421,
199,
318,
9567,
63,
27481,
8,
7650,
534,
6139,
26,
1656,
2547,
29,
403,
304,
272,
3598,
14,
4050,
480,
6049,
440,
3304,
11343,
641,
314,
11167,
4765,
2372,
4986,
3849,
12,
2116,
13232,
29,
18,
9,
272,
340,
440,
2547,
26,
267,
2547,
275,
984,
14,
3083,
272,
870,
4331,
1745,
12,
298,
3849,
26,
13635,
1324,
1443,
506,
11343,
379,
2122,
272,
372,
485,
1773,
63,
1210,
8,
7650,
12,
2547,
9,
421,
199,
318,
485,
1773,
63,
1210,
8,
7650,
8772,
2547,
29,
403,
12,
1324,
29,
403,
304,
272,
327,
437,
3066,
63,
1210,
342,
8343,
626,
3181,
1133,
3354,
314,
1059,
315,
314,
272,
327,
1664,
14441,
7994,
14,
272,
340,
440,
2547,
26,
267,
2547,
275,
984,
14,
3083,
272,
340,
440,
1324,
26,
267,
1324,
275,
984,
14,
6626,
272,
8457,
275
] |
[
22905,
370,
664,
282,
2505,
436,
15,
269,
314,
1453,
922,
536,
14,
199,
199,
27481,
8,
7650,
14675,
2547,
566,
446,
2165,
4787,
367,
282,
2505,
12,
543,
11343,
19136,
2331,
14,
199,
362,
751,
342,
446,
2372,
314,
922,
536,
687,
314,
3734,
503,
2505,
3050,
14,
199,
199,
1002,
4986,
3849,
446,
961,
2876,
3849,
365,
21117,
1380,
18354,
342,
3913,
7981,
326,
11343,
316,
402,
314,
2505,
4072,
1830,
7664,
14,
199,
199,
3314,
5417,
12,
314,
31756,
859,
911,
506,
1202,
14,
199,
3314,
314,
10444,
18951,
1341,
18238,
14,
25525,
6139,
365,
1202,
12,
340,
2808,
14,
199,
199,
624,
199,
199,
3,
6642,
26,
19835,
1192,
491,
3844,
424,
334,
5043,
9,
199,
3,
3515,
598,
1535,
79,
20744,
6848,
385,
453,
334,
8647,
2291,
436,
9058,
9,
199,
3,
3515,
29096,
1089,
510,
14,
25924,
334,
4707,
2291,
1253,
2372,
4986,
3849,
9,
199,
199,
646,
747,
12,
984,
12,
3598,
199,
199,
363,
452,
363,
275,
2097,
27481,
2266,
362,
751,
2266,
1002,
4986,
3849,
937,
421,
199,
533,
2372,
4986,
3849,
8,
32114,
304,
986,
421,
199,
318,
16572,
63,
27481,
8,
7650,
534,
6139,
26,
1656,
2547,
29,
403,
304,
272,
408,
20430,
367,
282,
2505,
12,
543,
11343,
19136,
2331,
14,
339,
3033,
26,
489,
8457,
26,
27694,
641,
2547,
370,
7198,
367,
314,
1324,
14,
221,
3758,
26,
283,
6139,
26,
283,
489,
2547,
26,
437,
17267,
570,
909,
370,
2929,
314,
8457,
14,
221,
7827,
370,
1598,
314,
21862,
14,
221,
982,
949,
21862,
365,
2808,
4243,
370,
984,
14,
3083,
14,
272,
1803,
26,
489,
710,
542,
27399,
19,
84,
1324,
14,
272,
6218,
26,
489,
21157,
26,
982,
4154,
1324,
21862,
503,
9009,
1990,
6876,
14,
489,
2372,
4986,
3849,
26,
3979,
781,
4898,
17329,
370,
7485,
11343,
2331,
641,
314,
1324,
14,
339,
16763,
4618,
7944,
11167,
2202,
2544,
8152,
14,
272,
408,
272,
6111,
275,
488,
272,
21862,
275,
488,
272,
862,
26,
267,
327,
16763,
862,
7664,
436,
3575,
5370,
641,
314,
21862,
1642,
14,
267,
6111,
275,
747,
14,
1490,
2336,
2374,
15,
4707,
297,
747,
14,
47,
63,
15543,
6524,
92,
736,
14,
47,
63,
2826,
1028,
2099,
9,
267,
21862,
275,
747,
14,
23140,
8,
2592,
12,
283,
87,
7386,
413,
9,
267,
1324,
275,
21862,
267,
340,
440,
2547,
26,
288,
2547,
275,
21862,
272,
871,
25139,
12,
325,
26,
267,
327,
982,
626,
6918,
12,
1937,
340,
9009,
883,
506,
22284,
14,
267,
862,
26,
288,
6111,
275,
984,
14,
6626,
14,
9843,
342,
267,
871,
334,
10227,
12,
1722,
304,
288,
15081,
275,
9567,
63,
27481,
8,
7650,
12,
2547,
9,
267,
1324,
275,
984,
14,
6626,
267,
340,
440,
2547,
26,
288,
2547,
275,
984,
14,
3083,
339,
340,
6111,
365,
440,
488,
26,
267,
15081,
275,
488,
267,
862,
26,
288,
2269,
275,
28725,
14,
3641,
5675,
8,
2592,
9,
258,
327,
282,
1331,
370,
3354,
288,
892,
275,
2269,
5873,
288,
892,
59,
19,
61,
18415,
6146,
351,
24597,
14,
37,
10465,
221,
327,
650,
508,
283,
276,
1550,
7,
288,
14415,
10202,
63,
2469,
275,
28725,
14,
52,
3298,
33,
32762,
288,
340,
2688,
8,
351,
24597,
12,
283,
52,
3298,
1179,
47,
2161,
735,
355,
14415,
10202,
63,
2469,
8901,
28725,
14,
52,
3298,
1179,
47,
2161,
288,
862,
26,
355,
28725,
14,
3641,
10202,
8,
2592,
12,
14415,
10202,
63,
2469,
12,
892,
9,
355,
15081,
275,
485,
1773,
63,
1210,
8,
7650,
12,
2547,
12,
1324,
29,
1210,
9,
288,
3753,
26,
355,
28725,
14,
3641,
10202,
8,
2592,
12,
14415,
10202,
63,
2469,
12,
2269,
9,
355,
2547,
14,
4939,
342,
221,
327,
4976,
23,
10630,
267,
871,
28725,
14,
705,
12,
325,
26,
288,
340,
15081,
365,
440,
488,
26,
355,
327,
485,
1773,
63,
1210,
19268,
14,
221,
710,
4242,
14415,
10202,
3405,
14,
221,
820,
32311,
572,
355,
327,
3140,
402,
23188,
314,
11167,
315,
376,
5809,
1174,
14,
355,
746,
288,
327,
2136,
883,
1133,
3304,
314,
21862,
503,
9009,
14,
221,
25495,
1536,
436,
675,
3293,
5004,
14,
288,
327,
9567,
63,
27481,
342,
6534,
376,
5827,
5721,
14,
288,
2150,
1324,
12,
21862,
221,
327,
3633,
1536,
9563,
570,
2251,
2544,
14592,
288,
15081,
275,
9567,
63,
27481,
8,
7650,
12,
2547,
9,
339,
2547,
14,
952,
2258,
78,
358,
272,
372,
15081,
421,
199,
318,
4747,
63,
27481,
8,
7650,
534,
6139,
26,
1656,
2547,
29,
403,
304,
272,
408,
20430,
367,
2505,
543,
11343,
2331,
12,
1808,
5417,
664,
335,
20693,
272,
340,
984,
14,
6626,
365,
440,
984,
855,
6626,
10651,
267,
372,
9567,
63,
27481,
8,
7650,
12,
2547,
9,
272,
492,
31756,
272,
367,
286,
315,
8457,
26,
267,
31756,
14,
524,
335,
8,
67,
9,
272,
19206,
275,
3087,
272,
1830,
413,
26,
267,
286,
275,
31756,
14,
362,
335,
342,
267,
340,
286,
508,
1557,
82,
7,
503,
286,
508,
1557,
78,
356,
288,
2059,
267,
340,
286,
508,
1557,
8262,
356,
288,
746,
13483,
267,
340,
286,
508,
1557,
66,
356,
288,
19206,
275,
19206,
4439,
17,
61,
267,
587,
26,
288,
19206,
275,
19206,
435,
286,
272,
31756,
14,
524,
335,
2258,
82,
358,
272,
31756,
14,
524,
335,
2258,
78,
358,
272,
372,
19206,
421,
199,
318,
9567,
63,
27481,
8,
7650,
534,
6139,
26,
1656,
2547,
29,
403,
304,
272,
3598,
14,
4050,
480,
6049,
440,
3304,
11343,
641,
314,
11167,
4765,
2372,
4986,
3849,
12,
2116,
13232,
29,
18,
9,
272,
340,
440,
2547,
26,
267,
2547,
275,
984,
14,
3083,
272,
870,
4331,
1745,
12,
298,
3849,
26,
13635,
1324,
1443,
506,
11343,
379,
2122,
272,
372,
485,
1773,
63,
1210,
8,
7650,
12,
2547,
9,
421,
199,
318,
485,
1773,
63,
1210,
8,
7650,
8772,
2547,
29,
403,
12,
1324,
29,
403,
304,
272,
327,
437,
3066,
63,
1210,
342,
8343,
626,
3181,
1133,
3354,
314,
1059,
315,
314,
272,
327,
1664,
14441,
7994,
14,
272,
340,
440,
2547,
26,
267,
2547,
275,
984,
14,
3083,
272,
340,
440,
1324,
26,
267,
1324,
275,
984,
14,
6626,
272,
8457,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
ujenmr/ansible
|
lib/ansible/module_utils/linode.py
|
41
|
1985
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c), Luke Murphy @lwm
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
def get_user_agent(module):
"""Retrieve a user-agent to send with LinodeClient requests."""
try:
from ansible.module_utils.ansible_release import __version__ as ansible_version
except ImportError:
ansible_version = 'unknown'
return 'Ansible-%s/%s' % (module, ansible_version)
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
30936,
415,
603,
300,
6581,
768,
76,
16240,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
421,
199,
318,
664,
63,
751,
63,
4054,
8,
578,
304,
272,
408,
15310,
282,
922,
13,
4054,
370,
3222,
543,
491,
15993,
3041,
4145,
1041,
272,
862,
26,
267,
687,
3242,
14,
578,
63,
1208,
14,
4853,
63,
3221,
492,
636,
1023,
363,
465,
3242,
63,
1023,
272,
871,
3545,
26,
267,
3242,
63,
1023,
275,
283,
5187,
7,
272,
372,
283,
10047,
3295,
83,
3149,
83,
7,
450,
334,
578,
12,
3242,
63,
1023,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
67,
395,
30936,
415,
603,
300,
6581,
768,
76,
16240,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
421,
199,
318,
664,
63,
751,
63,
4054,
8,
578,
304,
272,
408,
15310,
282,
922,
13,
4054,
370,
3222,
543,
491,
15993,
3041,
4145,
1041,
272,
862,
26,
267,
687,
3242,
14,
578,
63,
1208,
14,
4853,
63,
3221,
492,
636,
1023,
363,
465,
3242,
63,
1023,
272,
871,
3545,
26,
267,
3242,
63,
1023,
275,
283,
5187,
7,
272,
372,
283,
10047,
3295,
83,
3149,
83,
7,
450,
334,
578,
12,
3242,
63,
1023,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
npe9/binutils-gdb
|
gdb/testsuite/gdb.perf/disassemble.py
|
46
|
1514
|
# Copyright (C) 2013-2015 Free Software Foundation, 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 this program. If not, see <http://www.gnu.org/licenses/>.
from perftest import perftest
class Disassemble(perftest.TestCaseWithBasicMeasurements):
def __init__(self):
super (Disassemble, self).__init__ ("disassemble")
def warm_up(self):
do_test_command = "disassemble ada_evaluate_subexp"
gdb.execute (do_test_command, False, True)
def _do_test(self, c):
for func in ["evaluate_subexp_standard", "handle_inferior_event", "c_parse_internal"]:
do_test_command = "disassemble %s" % func
for _ in range(c+1):
gdb.execute (do_test_command, False, True)
def execute_test(self):
for i in range(3):
# Flush code cache.
gdb.execute("set code-cache off");
gdb.execute("set code-cache on");
self.measure.measure(lambda: self._do_test(i), i)
|
gpl-2.0
|
[
3,
1898,
334,
35,
9,
6171,
13,
7806,
2868,
2290,
2752,
12,
3277,
14,
199,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
8582,
396,
492,
8582,
396,
199,
199,
533,
5289,
21263,
8,
9452,
396,
14,
1746,
3007,
6845,
18611,
1470,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
334,
2825,
21263,
12,
291,
2843,
826,
363,
1689,
2297,
21263,
531,
339,
347,
20060,
63,
384,
8,
277,
304,
267,
886,
63,
396,
63,
1531,
275,
298,
2297,
21263,
282,
983,
63,
7383,
63,
954,
1474,
2,
267,
12124,
14,
2526,
334,
1117,
63,
396,
63,
1531,
12,
756,
12,
715,
9,
339,
347,
485,
1117,
63,
396,
8,
277,
12,
286,
304,
267,
367,
2562,
315,
2097,
7383,
63,
954,
1474,
63,
6807,
401,
298,
2479,
63,
14578,
15499,
63,
1430,
401,
298,
67,
63,
1122,
63,
4672,
6229,
288,
886,
63,
396,
63,
1531,
275,
298,
2297,
21263,
450,
83,
2,
450,
2562,
288,
367,
485,
315,
1425,
8,
67,
11,
17,
304,
355,
12124,
14,
2526,
334,
1117,
63,
396,
63,
1531,
12,
756,
12,
715,
9,
339,
347,
5341,
63,
396,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
19,
304,
288,
327,
11040,
2084,
1233,
2581,
14,
288,
12124,
14,
2526,
480,
409,
1233,
13,
1637,
2331,
3547,
288,
12124,
14,
2526,
480,
409,
1233,
13,
1637,
641,
3547,
288,
291,
14,
9580,
14,
9580,
8,
2734,
26,
291,
423,
1117,
63,
396,
8,
73,
395,
284,
9,
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
] |
[
1898,
334,
35,
9,
6171,
13,
7806,
2868,
2290,
2752,
12,
3277,
14,
199,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
8582,
396,
492,
8582,
396,
199,
199,
533,
5289,
21263,
8,
9452,
396,
14,
1746,
3007,
6845,
18611,
1470,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
334,
2825,
21263,
12,
291,
2843,
826,
363,
1689,
2297,
21263,
531,
339,
347,
20060,
63,
384,
8,
277,
304,
267,
886,
63,
396,
63,
1531,
275,
298,
2297,
21263,
282,
983,
63,
7383,
63,
954,
1474,
2,
267,
12124,
14,
2526,
334,
1117,
63,
396,
63,
1531,
12,
756,
12,
715,
9,
339,
347,
485,
1117,
63,
396,
8,
277,
12,
286,
304,
267,
367,
2562,
315,
2097,
7383,
63,
954,
1474,
63,
6807,
401,
298,
2479,
63,
14578,
15499,
63,
1430,
401,
298,
67,
63,
1122,
63,
4672,
6229,
288,
886,
63,
396,
63,
1531,
275,
298,
2297,
21263,
450,
83,
2,
450,
2562,
288,
367,
485,
315,
1425,
8,
67,
11,
17,
304,
355,
12124,
14,
2526,
334,
1117,
63,
396,
63,
1531,
12,
756,
12,
715,
9,
339,
347,
5341,
63,
396,
8,
277,
304,
267,
367,
284,
315,
1425,
8,
19,
304,
288,
327,
11040,
2084,
1233,
2581,
14,
288,
12124,
14,
2526,
480,
409,
1233,
13,
1637,
2331,
3547,
288,
12124,
14,
2526,
480,
409,
1233,
13,
1637,
641,
3547,
288,
291,
14,
9580,
14,
9580,
8,
2734,
26,
291,
423,
1117,
63,
396,
8,
73,
395,
284,
9,
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,
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,
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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
] |
soleneulmer/atmos
|
indicators_molec.py
|
1
|
4324
|
# ===================================
# CALCULATES Ioff and Ires
# Indicators described in Molecfit II
#
# Solene 20.09.2016
# ===================================
#
import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
# from PyAstronomy import pyasl
from scipy.interpolate import interp1d
from scipy.interpolate import InterpolatedUnivariateSpline
from scipy import stats
# from sklearn.metrics import mean_squared_error
# from math import sqrt
# from numpy import linalg as LA
# MOLECFIT
#
file_molecfit = '/home/solene/atmos/For_Solene/1203nm/output/molecfit_crires_solene_tac.fits'
hdu_molecfit = fits.open(file_molecfit)
data_molecfit = hdu_molecfit[1].data
cols_molecfit = hdu_molecfit[1].columns
# cols_molecfit.info()
rawwl_molecfit = data_molecfit.field('mlambda')
wl_molecfit = rawwl_molecfit*10e2
trans_molecfit = data_molecfit.field('mtrans')
cflux_molecfit = data_molecfit.field('cflux')
# TELFIT
#
file_telfit = '/home/solene/atmos/trans_telfit.txt'
wl_telfit, trans_telfit, wl_datatelfit, flux_datatelfit = np.loadtxt(
file_telfit, unpack=True)
# Interpolation
f_molecfit = interp1d(wl_molecfit, cflux_molecfit, kind='cubic')
ftrans_molecfit = interp1d(wl_molecfit, trans_molecfit, kind='cubic')
# f_tapas = interp1d(wlcorr_tapas, trans_tapas)
# **1** BINNED DATA
# 3 delta-lambda = 0.036
# Mean and std deviation of bins on the telluric CORRECTED spectrum
fluxmean_bin_means, bin_edges, binnumber = stats.binned_statistic(
wl_datatelfit, f_molecfit(wl_datatelfit), statistic='mean',
bins=np.floor((wl_datatelfit[-1]-wl_datatelfit[0])/0.036))
fluxstd_bin_means, _, _ = stats.binned_statistic(
wl_datatelfit, f_molecfit(wl_datatelfit), statistic=np.std,
bins=np.floor((wl_datatelfit[-1]-wl_datatelfit[0])/0.036))
bin_width = (bin_edges[1] - bin_edges[0])
bin_centers = bin_edges[1:] - bin_width/2
# **2** Bins where average TRANSMISSION is > 0.99
flux_trans_mean_bin_means, _, _ = stats.binned_statistic(
wl_datatelfit, ftrans_molecfit(wl_datatelfit), statistic='mean',
bins=np.floor((wl_datatelfit[-1]-wl_datatelfit[0])/0.036))
# cont_bin_means = flux_trans_mean_bin_means[flux_trans_mean_bin_means > 0.99]
ind_cont = np.where(flux_trans_mean_bin_means > 0.99)
ind_out = np.where((flux_trans_mean_bin_means < 0.95) &
(flux_trans_mean_bin_means > 0.1))
# plt.plot(bin_centers[ind_cont], flux_trans_mean_bin_means[ind_cont], 'kx')
# **3** Interpolation of the continuum cubic
# f_cont = interp1d(bin_centers[ind_cont], flux_trans_mean_bin_means[ind_cont], kind='cubic')
# Extrapolation with constant value spline
f_cont = InterpolatedUnivariateSpline(
bin_centers[ind_cont], flux_trans_mean_bin_means[ind_cont], ext=3)
# bbox=[bin_centers[ind_cont][0], bin_centers[ind_cont][-1]],
# **5** Subtract cont to mean flux
# and Divide offset and std by interpolated continuum mean value
sys_offset = (fluxmean_bin_means - f_cont(bin_centers)) / f_cont(bin_centers)
flux_std = fluxstd_bin_means / f_cont(bin_centers)
# **6** independant WL = Divide by average absorption
absorp_molecfit = 1 - flux_trans_mean_bin_means
sys_offset_final = sys_offset / absorp_molecfit
flux_std_final = flux_std / absorp_molecfit
plt.figure(1)
plt.plot(wl_datatelfit, flux_datatelfit, 'b.-', label='Raw data')
# plt.hlines(flux_bin_means, bin_edges[:-1],
# bin_edges[1:], colors='g', lw=5, label='binned statistic of data')
plt.plot(bin_centers, fluxmean_bin_means, 'rx-', label='Mean binned data')
plt.plot(bin_centers, fluxstd_bin_means, 'kx-', label='Standard deviation binned data')
plt.legend()
plt.figure(2)
plt.plot(wl_datatelfit, flux_datatelfit, 'g.-', label='Data 2nd detector')
plt.plot(wl_molecfit, trans_molecfit, 'r-', label='Molecfit')
plt.plot(wl_datatelfit, f_molecfit(wl_datatelfit),
'b-', label='Corrected data - Molecfit')
plt.plot(wl_datatelfit, f_cont(wl_datatelfit),
'k-', label='Interpolated Continuum')
plt.plot(sys_offset_final[ind_out], flux_std_final[ind_out], 'kx')
plt.plot(flux_trans_mean_bin_means[ind_out],
sys_offset_final[ind_out], 'kx', label='Ioff vs Transmission')
plt.plot(flux_trans_mean_bin_means[ind_out],
flux_std_final[ind_out], 'r.', label='Ires vs Transmission')
plt.xlabel('Wavelength (nm)')
plt.ylabel('Transmission')
plt.legend(loc=3.)
plt.show()
|
mit
|
[
3,
19469,
389,
199,
3,
445,
748,
35,
1293,
16601,
473,
1997,
436,
473,
470,
199,
3,
1010,
5000,
2750,
11736,
315,
3930,
10251,
3269,
473,
41,
199,
3,
199,
3,
2002,
23630,
3388,
14,
1643,
14,
9261,
199,
3,
19469,
389,
199,
3,
199,
646,
2680,
465,
980,
199,
504,
28753,
14,
2308,
492,
20147,
199,
646,
8027,
14,
13563,
465,
4488,
199,
3,
687,
1611,
33,
495,
17293,
492,
1134,
305,
76,
199,
504,
7026,
14,
21294,
492,
23716,
17,
68,
199,
504,
7026,
14,
21294,
492,
6551,
2515,
972,
1358,
23225,
27558,
199,
504,
7026,
492,
5020,
199,
3,
687,
6357,
14,
6759,
492,
4615,
63,
12973,
63,
705,
199,
3,
687,
3473,
492,
7452,
199,
3,
687,
2680,
492,
16727,
465,
31046,
199,
199,
3,
10362,
906,
5487,
649,
199,
3,
199,
493,
63,
573,
10251,
3269,
275,
1994,
4219,
15,
1152,
23630,
15,
292,
16908,
15,
1858,
63,
5158,
23630,
15,
713,
1644,
10756,
15,
1199,
15,
573,
10251,
3269,
63,
1408,
470,
63,
1152,
23630,
63,
27308,
14,
14948,
7,
199,
72,
2033,
63,
573,
10251,
3269,
275,
20147,
14,
1490,
8,
493,
63,
573,
10251,
3269,
9,
199,
576,
63,
573,
10251,
3269,
275,
394,
2033,
63,
573,
10251,
3269,
59,
17,
1055,
576,
199,
4574,
63,
573,
10251,
3269,
275,
394,
2033,
63,
573,
10251,
3269,
59,
17,
1055,
3406,
199,
3,
8850,
63,
573,
10251,
3269,
14,
815,
342,
199,
345,
978,
76,
63,
573,
10251,
3269,
275,
666,
63,
573,
10251,
3269,
14,
698,
360,
77,
2734,
358,
199,
20159,
63,
573,
10251,
3269,
275,
660,
978,
76,
63,
573,
10251,
3269,
10,
709,
69,
18,
199,
1515,
63,
573,
10251,
3269,
275,
666,
63,
573,
10251,
3269,
14,
698,
360,
77,
1515,
358,
199,
2177,
76,
2521,
63,
573,
10251,
3269,
275,
666,
63,
573,
10251,
3269,
14,
698,
360,
2177,
76,
2521,
358,
199,
199,
3,
377,
2901,
38,
649,
199,
3,
199,
493,
63,
266,
276,
390,
275,
1994,
4219,
15,
1152,
23630,
15,
292,
16908,
15,
1515,
63,
266,
276,
390,
14,
2424,
7,
199,
20159,
63,
266,
276,
390,
12,
1752,
63,
266,
276,
390,
12,
336,
76,
63,
4616,
323,
276,
390,
12,
21475,
63,
4616,
323,
276,
390,
275,
980,
14,
27992,
8,
272,
570,
63,
266,
276,
390,
12,
7787,
29,
549,
9,
199,
199,
3,
6551,
9536,
199,
70,
63,
573,
10251,
3269,
275,
23716,
17,
68,
8,
20159,
63,
573,
10251,
3269,
12,
286,
14477,
63,
573,
10251,
3269,
12,
221,
4928,
534,
18455,
530,
358,
199,
70,
1515,
63,
573,
10251,
3269,
275,
23716,
17,
68,
8,
20159,
63,
573,
10251,
3269,
12,
1752,
63,
573,
10251,
3269,
12,
221,
4928,
534,
18455,
530,
358,
199,
3,
289,
63,
16609,
305,
275,
23716,
17,
68,
8,
20159,
16742,
63,
16609,
305,
12,
1752,
63,
16609,
305,
9,
199,
199,
3,
1011,
17,
538,
26348,
46,
1149,
7126,
199,
3,
221,
650,
5762,
13,
2734,
275,
378,
14,
25368,
199,
3,
25136,
436,
2418,
18458,
402,
13341,
641,
314,
11480,
300,
530,
18886,
4168,
1149,
20645,
199,
14477,
3670,
63,
1393,
63,
11579,
12,
2517,
63,
6929,
12,
2517,
1955,
275,
5020,
14,
1393,
7439,
63,
26065,
8,
272,
336,
76,
63,
4616,
323,
276,
390,
12,
289,
63,
573,
10251,
3269,
8,
20159,
63,
4616,
323,
276,
390,
395,
22394,
534,
3670,
297,
272,
13341,
29,
1590,
14,
11289,
1332,
20159,
63,
4616,
323,
276,
390,
1988,
17,
11285,
20159,
63,
4616,
323,
276,
390,
59,
16,
23067,
16,
14,
25368,
430,
199,
199,
14477,
1516,
63,
1393,
63,
11579,
12,
5501,
485,
275,
5020,
14,
1393,
7439,
63,
26065,
8,
272,
336,
76,
63,
4616,
323,
276,
390,
12,
289,
63,
573,
10251,
3269,
8,
20159,
63,
4616,
323,
276,
390,
395,
22394,
29,
1590,
14,
1516,
12,
272,
13341,
29,
1590,
14,
11289,
1332,
20159,
63,
4616,
323,
276,
390,
1988,
17,
11285,
20159,
63,
4616,
323,
276,
390,
59,
16,
23067,
16,
14,
25368,
430,
199,
199,
1393,
63,
2063,
275,
334,
1393,
63,
6929,
59,
17,
61,
446,
2517,
63,
6929,
59,
16,
566,
199,
1393,
63,
15660,
275,
2517,
63,
6929,
59,
17,
2938,
446,
2517,
63,
2063,
15,
18,
199,
199,
3,
1011,
18,
538,
699,
3617,
2382,
8095,
22499,
365,
690,
378,
14,
1020,
199,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
12,
5501,
485,
275,
5020,
14,
1393,
7439,
63,
26065,
8,
272,
336,
76,
63,
4616,
323,
276,
390,
12,
289,
1515,
63,
573,
10251,
3269,
8,
20159,
63,
4616,
323,
276,
390,
395,
22394,
534,
3670,
297,
272,
13341,
29,
1590,
14,
11289,
1332,
20159,
63,
4616,
323,
276,
390,
1988,
17,
11285,
20159,
63,
4616,
323,
276,
390,
59,
16,
23067,
16,
14,
25368,
430,
199,
3,
13770,
63,
1393,
63,
11579,
275,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
690,
378,
14,
1020,
61,
199,
688,
63,
11096,
275,
980,
14,
4509,
8,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
690,
378,
14,
1020,
9,
199,
688,
63,
548,
275,
980,
14,
4509,
1332,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
665,
378,
14,
2720,
9,
1253,
673,
334,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
690,
378,
14,
17,
430,
199,
199,
3,
4488,
14,
2798,
8,
1393,
63,
15660,
59,
688,
63,
11096,
467,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
688,
63,
11096,
467,
283,
75,
88,
358,
199,
199,
3,
1011,
19,
538,
6551,
9536,
402,
314,
9832,
19805,
22217,
530,
199,
3,
289,
63,
11096,
275,
23716,
17,
68,
8,
1393,
63,
15660,
59,
688,
63,
11096,
467,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
688,
63,
11096,
467,
221,
4928,
534,
18455,
530,
358,
199,
3,
7255,
1330,
10410,
543,
4413,
574,
30213,
199,
70,
63,
11096,
275,
6551,
2515,
972,
1358,
23225,
27558,
8,
272,
2517,
63,
15660,
59,
688,
63,
11096,
467,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
688,
63,
11096,
467,
1599
] |
[
19469,
389,
199,
3,
445,
748,
35,
1293,
16601,
473,
1997,
436,
473,
470,
199,
3,
1010,
5000,
2750,
11736,
315,
3930,
10251,
3269,
473,
41,
199,
3,
199,
3,
2002,
23630,
3388,
14,
1643,
14,
9261,
199,
3,
19469,
389,
199,
3,
199,
646,
2680,
465,
980,
199,
504,
28753,
14,
2308,
492,
20147,
199,
646,
8027,
14,
13563,
465,
4488,
199,
3,
687,
1611,
33,
495,
17293,
492,
1134,
305,
76,
199,
504,
7026,
14,
21294,
492,
23716,
17,
68,
199,
504,
7026,
14,
21294,
492,
6551,
2515,
972,
1358,
23225,
27558,
199,
504,
7026,
492,
5020,
199,
3,
687,
6357,
14,
6759,
492,
4615,
63,
12973,
63,
705,
199,
3,
687,
3473,
492,
7452,
199,
3,
687,
2680,
492,
16727,
465,
31046,
199,
199,
3,
10362,
906,
5487,
649,
199,
3,
199,
493,
63,
573,
10251,
3269,
275,
1994,
4219,
15,
1152,
23630,
15,
292,
16908,
15,
1858,
63,
5158,
23630,
15,
713,
1644,
10756,
15,
1199,
15,
573,
10251,
3269,
63,
1408,
470,
63,
1152,
23630,
63,
27308,
14,
14948,
7,
199,
72,
2033,
63,
573,
10251,
3269,
275,
20147,
14,
1490,
8,
493,
63,
573,
10251,
3269,
9,
199,
576,
63,
573,
10251,
3269,
275,
394,
2033,
63,
573,
10251,
3269,
59,
17,
1055,
576,
199,
4574,
63,
573,
10251,
3269,
275,
394,
2033,
63,
573,
10251,
3269,
59,
17,
1055,
3406,
199,
3,
8850,
63,
573,
10251,
3269,
14,
815,
342,
199,
345,
978,
76,
63,
573,
10251,
3269,
275,
666,
63,
573,
10251,
3269,
14,
698,
360,
77,
2734,
358,
199,
20159,
63,
573,
10251,
3269,
275,
660,
978,
76,
63,
573,
10251,
3269,
10,
709,
69,
18,
199,
1515,
63,
573,
10251,
3269,
275,
666,
63,
573,
10251,
3269,
14,
698,
360,
77,
1515,
358,
199,
2177,
76,
2521,
63,
573,
10251,
3269,
275,
666,
63,
573,
10251,
3269,
14,
698,
360,
2177,
76,
2521,
358,
199,
199,
3,
377,
2901,
38,
649,
199,
3,
199,
493,
63,
266,
276,
390,
275,
1994,
4219,
15,
1152,
23630,
15,
292,
16908,
15,
1515,
63,
266,
276,
390,
14,
2424,
7,
199,
20159,
63,
266,
276,
390,
12,
1752,
63,
266,
276,
390,
12,
336,
76,
63,
4616,
323,
276,
390,
12,
21475,
63,
4616,
323,
276,
390,
275,
980,
14,
27992,
8,
272,
570,
63,
266,
276,
390,
12,
7787,
29,
549,
9,
199,
199,
3,
6551,
9536,
199,
70,
63,
573,
10251,
3269,
275,
23716,
17,
68,
8,
20159,
63,
573,
10251,
3269,
12,
286,
14477,
63,
573,
10251,
3269,
12,
221,
4928,
534,
18455,
530,
358,
199,
70,
1515,
63,
573,
10251,
3269,
275,
23716,
17,
68,
8,
20159,
63,
573,
10251,
3269,
12,
1752,
63,
573,
10251,
3269,
12,
221,
4928,
534,
18455,
530,
358,
199,
3,
289,
63,
16609,
305,
275,
23716,
17,
68,
8,
20159,
16742,
63,
16609,
305,
12,
1752,
63,
16609,
305,
9,
199,
199,
3,
1011,
17,
538,
26348,
46,
1149,
7126,
199,
3,
221,
650,
5762,
13,
2734,
275,
378,
14,
25368,
199,
3,
25136,
436,
2418,
18458,
402,
13341,
641,
314,
11480,
300,
530,
18886,
4168,
1149,
20645,
199,
14477,
3670,
63,
1393,
63,
11579,
12,
2517,
63,
6929,
12,
2517,
1955,
275,
5020,
14,
1393,
7439,
63,
26065,
8,
272,
336,
76,
63,
4616,
323,
276,
390,
12,
289,
63,
573,
10251,
3269,
8,
20159,
63,
4616,
323,
276,
390,
395,
22394,
534,
3670,
297,
272,
13341,
29,
1590,
14,
11289,
1332,
20159,
63,
4616,
323,
276,
390,
1988,
17,
11285,
20159,
63,
4616,
323,
276,
390,
59,
16,
23067,
16,
14,
25368,
430,
199,
199,
14477,
1516,
63,
1393,
63,
11579,
12,
5501,
485,
275,
5020,
14,
1393,
7439,
63,
26065,
8,
272,
336,
76,
63,
4616,
323,
276,
390,
12,
289,
63,
573,
10251,
3269,
8,
20159,
63,
4616,
323,
276,
390,
395,
22394,
29,
1590,
14,
1516,
12,
272,
13341,
29,
1590,
14,
11289,
1332,
20159,
63,
4616,
323,
276,
390,
1988,
17,
11285,
20159,
63,
4616,
323,
276,
390,
59,
16,
23067,
16,
14,
25368,
430,
199,
199,
1393,
63,
2063,
275,
334,
1393,
63,
6929,
59,
17,
61,
446,
2517,
63,
6929,
59,
16,
566,
199,
1393,
63,
15660,
275,
2517,
63,
6929,
59,
17,
2938,
446,
2517,
63,
2063,
15,
18,
199,
199,
3,
1011,
18,
538,
699,
3617,
2382,
8095,
22499,
365,
690,
378,
14,
1020,
199,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
12,
5501,
485,
275,
5020,
14,
1393,
7439,
63,
26065,
8,
272,
336,
76,
63,
4616,
323,
276,
390,
12,
289,
1515,
63,
573,
10251,
3269,
8,
20159,
63,
4616,
323,
276,
390,
395,
22394,
534,
3670,
297,
272,
13341,
29,
1590,
14,
11289,
1332,
20159,
63,
4616,
323,
276,
390,
1988,
17,
11285,
20159,
63,
4616,
323,
276,
390,
59,
16,
23067,
16,
14,
25368,
430,
199,
3,
13770,
63,
1393,
63,
11579,
275,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
690,
378,
14,
1020,
61,
199,
688,
63,
11096,
275,
980,
14,
4509,
8,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
690,
378,
14,
1020,
9,
199,
688,
63,
548,
275,
980,
14,
4509,
1332,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
665,
378,
14,
2720,
9,
1253,
673,
334,
14477,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
690,
378,
14,
17,
430,
199,
199,
3,
4488,
14,
2798,
8,
1393,
63,
15660,
59,
688,
63,
11096,
467,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
688,
63,
11096,
467,
283,
75,
88,
358,
199,
199,
3,
1011,
19,
538,
6551,
9536,
402,
314,
9832,
19805,
22217,
530,
199,
3,
289,
63,
11096,
275,
23716,
17,
68,
8,
1393,
63,
15660,
59,
688,
63,
11096,
467,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
688,
63,
11096,
467,
221,
4928,
534,
18455,
530,
358,
199,
3,
7255,
1330,
10410,
543,
4413,
574,
30213,
199,
70,
63,
11096,
275,
6551,
2515,
972,
1358,
23225,
27558,
8,
272,
2517,
63,
15660,
59,
688,
63,
11096,
467,
21475,
63,
1515,
63,
3670,
63,
1393,
63,
11579,
59,
688,
63,
11096,
467,
1599,
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
] |
Alberto-Beralix/Beralix
|
i386-squashfs-root/usr/share/pyshared/twisted/internet/_posixserialport.py
|
18
|
1823
|
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Serial Port Protocol
"""
# system imports
import os, errno
# dependent on pyserial ( http://pyserial.sf.net/ )
# only tested w/ 1.18 (5 Dec 2002)
import serial
from serial import PARITY_NONE, PARITY_EVEN, PARITY_ODD
from serial import STOPBITS_ONE, STOPBITS_TWO
from serial import FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS
from serialport import BaseSerialPort
# twisted imports
from twisted.internet import abstract, fdesc, main
class SerialPort(BaseSerialPort, abstract.FileDescriptor):
"""
A select()able serial device, acting as a transport.
"""
connected = 1
def __init__(self, protocol, deviceNameOrPortNumber, reactor,
baudrate = 9600, bytesize = EIGHTBITS, parity = PARITY_NONE,
stopbits = STOPBITS_ONE, timeout = 0, xonxoff = 0, rtscts = 0):
abstract.FileDescriptor.__init__(self, reactor)
self._serial = serial.Serial(deviceNameOrPortNumber, baudrate = baudrate, bytesize = bytesize, parity = parity, stopbits = stopbits, timeout = timeout, xonxoff = xonxoff, rtscts = rtscts)
self.reactor = reactor
self.flushInput()
self.flushOutput()
self.protocol = protocol
self.protocol.makeConnection(self)
self.startReading()
def fileno(self):
return self._serial.fd
def writeSomeData(self, data):
"""
Write some data to the serial device.
"""
return fdesc.writeToFD(self.fileno(), data)
def doRead(self):
"""
Some data's readable from serial device.
"""
return fdesc.readFromFD(self.fileno(), self.protocol.dataReceived)
def connectionLost(self, reason):
abstract.FileDescriptor.connectionLost(self, reason)
self._serial.close()
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
3571,
10977,
11557,
199,
624,
199,
199,
3,
2656,
8925,
199,
646,
747,
12,
7554,
199,
199,
3,
11410,
641,
1134,
2171,
334,
1455,
921,
647,
2171,
14,
7646,
14,
846,
15,
776,
199,
3,
1454,
12470,
336,
15,
413,
14,
1085,
334,
21,
13966,
14790,
9,
199,
646,
3012,
199,
504,
3012,
492,
10263,
1922,
63,
9185,
12,
10263,
1922,
63,
37,
8253,
12,
10263,
1922,
63,
47,
5745,
199,
504,
3012,
492,
22348,
14662,
63,
4817,
12,
22348,
14662,
63,
52,
11325,
199,
504,
3012,
492,
28194,
14662,
12,
27953,
14662,
12,
28187,
14662,
12,
27457,
14662,
199,
199,
504,
3012,
719,
492,
3523,
3571,
4313,
199,
199,
3,
7390,
8925,
199,
504,
7390,
14,
4901,
492,
9006,
12,
289,
3257,
12,
2446,
199,
199,
533,
11973,
4313,
8,
1563,
3571,
4313,
12,
9006,
14,
23859,
304,
272,
408,
272,
437,
3504,
342,
461,
3012,
2243,
12,
2454,
316,
465,
282,
7773,
14,
272,
408,
339,
8539,
275,
413,
339,
347,
636,
826,
721,
277,
12,
4113,
12,
2243,
985,
2844,
4313,
3259,
12,
9655,
12,
4960,
19325,
27112,
275,
1749,
6683,
12,
3696,
890,
275,
27457,
14662,
12,
623,
1209,
275,
10263,
1922,
63,
9185,
12,
267,
3631,
5609,
275,
22348,
14662,
63,
4817,
12,
2653,
275,
378,
12,
671,
265,
88,
1997,
275,
378,
12,
519,
1086,
3021,
275,
378,
304,
267,
9006,
14,
23859,
855,
826,
721,
277,
12,
9655,
9,
267,
291,
423,
2171,
275,
3012,
14,
3571,
8,
1782,
985,
2844,
4313,
3259,
12,
19325,
27112,
275,
19325,
27112,
12,
3696,
890,
275,
3696,
890,
12,
623,
1209,
275,
623,
1209,
12,
3631,
5609,
275,
3631,
5609,
12,
2653,
275,
2653,
12,
671,
265,
88,
1997,
275,
671,
265,
88,
1997,
12,
519,
1086,
3021,
275,
519,
1086,
3021,
9,
267,
291,
14,
13544,
275,
9655,
267,
291,
14,
4939,
3205,
342,
267,
291,
14,
4939,
2959,
342,
267,
291,
14,
3922,
275,
4113,
267,
291,
14,
3922,
14,
1875,
3225,
8,
277,
9,
267,
291,
14,
928,
20568,
342,
339,
347,
25255,
8,
277,
304,
267,
372,
291,
423,
2171,
14,
2592,
339,
347,
2218,
7700,
1451,
8,
277,
12,
666,
304,
267,
408,
267,
6990,
2005,
666,
370,
314,
3012,
2243,
14,
267,
408,
267,
372,
289,
3257,
14,
952,
1378,
7902,
8,
277,
14,
9843,
1062,
666,
9,
339,
347,
886,
3284,
8,
277,
304,
267,
408,
267,
6601,
666,
1159,
12701,
687,
3012,
2243,
14,
267,
408,
267,
372,
289,
3257,
14,
739,
2532,
7902,
8,
277,
14,
9843,
1062,
291,
14,
3922,
14,
25037,
9,
339,
347,
1950,
14074,
8,
277,
12,
4499,
304,
267,
9006,
14,
23859,
14,
2105,
14074,
8,
277,
12,
4499,
9,
267,
291,
423,
2171,
14,
1600,
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
] |
[
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
3571,
10977,
11557,
199,
624,
199,
199,
3,
2656,
8925,
199,
646,
747,
12,
7554,
199,
199,
3,
11410,
641,
1134,
2171,
334,
1455,
921,
647,
2171,
14,
7646,
14,
846,
15,
776,
199,
3,
1454,
12470,
336,
15,
413,
14,
1085,
334,
21,
13966,
14790,
9,
199,
646,
3012,
199,
504,
3012,
492,
10263,
1922,
63,
9185,
12,
10263,
1922,
63,
37,
8253,
12,
10263,
1922,
63,
47,
5745,
199,
504,
3012,
492,
22348,
14662,
63,
4817,
12,
22348,
14662,
63,
52,
11325,
199,
504,
3012,
492,
28194,
14662,
12,
27953,
14662,
12,
28187,
14662,
12,
27457,
14662,
199,
199,
504,
3012,
719,
492,
3523,
3571,
4313,
199,
199,
3,
7390,
8925,
199,
504,
7390,
14,
4901,
492,
9006,
12,
289,
3257,
12,
2446,
199,
199,
533,
11973,
4313,
8,
1563,
3571,
4313,
12,
9006,
14,
23859,
304,
272,
408,
272,
437,
3504,
342,
461,
3012,
2243,
12,
2454,
316,
465,
282,
7773,
14,
272,
408,
339,
8539,
275,
413,
339,
347,
636,
826,
721,
277,
12,
4113,
12,
2243,
985,
2844,
4313,
3259,
12,
9655,
12,
4960,
19325,
27112,
275,
1749,
6683,
12,
3696,
890,
275,
27457,
14662,
12,
623,
1209,
275,
10263,
1922,
63,
9185,
12,
267,
3631,
5609,
275,
22348,
14662,
63,
4817,
12,
2653,
275,
378,
12,
671,
265,
88,
1997,
275,
378,
12,
519,
1086,
3021,
275,
378,
304,
267,
9006,
14,
23859,
855,
826,
721,
277,
12,
9655,
9,
267,
291,
423,
2171,
275,
3012,
14,
3571,
8,
1782,
985,
2844,
4313,
3259,
12,
19325,
27112,
275,
19325,
27112,
12,
3696,
890,
275,
3696,
890,
12,
623,
1209,
275,
623,
1209,
12,
3631,
5609,
275,
3631,
5609,
12,
2653,
275,
2653,
12,
671,
265,
88,
1997,
275,
671,
265,
88,
1997,
12,
519,
1086,
3021,
275,
519,
1086,
3021,
9,
267,
291,
14,
13544,
275,
9655,
267,
291,
14,
4939,
3205,
342,
267,
291,
14,
4939,
2959,
342,
267,
291,
14,
3922,
275,
4113,
267,
291,
14,
3922,
14,
1875,
3225,
8,
277,
9,
267,
291,
14,
928,
20568,
342,
339,
347,
25255,
8,
277,
304,
267,
372,
291,
423,
2171,
14,
2592,
339,
347,
2218,
7700,
1451,
8,
277,
12,
666,
304,
267,
408,
267,
6990,
2005,
666,
370,
314,
3012,
2243,
14,
267,
408,
267,
372,
289,
3257,
14,
952,
1378,
7902,
8,
277,
14,
9843,
1062,
666,
9,
339,
347,
886,
3284,
8,
277,
304,
267,
408,
267,
6601,
666,
1159,
12701,
687,
3012,
2243,
14,
267,
408,
267,
372,
289,
3257,
14,
739,
2532,
7902,
8,
277,
14,
9843,
1062,
291,
14,
3922,
14,
25037,
9,
339,
347,
1950,
14074,
8,
277,
12,
4499,
304,
267,
9006,
14,
23859,
14,
2105,
14074,
8,
277,
12,
4499,
9,
267,
291,
423,
2171,
14,
1600,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Videoclases/videoclases
|
quality_control/views/api.py
|
1
|
4172
|
import random
from django.contrib.auth.decorators import user_passes_test
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.db.models.aggregates import Count
from django.http.response import JsonResponse, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from django.core import serializers
from quality_control.models.quality_control import QualityControl
from videoclases.models.groupofstudents import GroupOfStudents
from videoclases.models.homework import Homework
from videoclases.models.student_evaluations import StudentEvaluations
def in_students_group(user):
if user:
return user.groups.filter(name='Alumnos').exists()
return False
class GetVideoClaseView(DetailView):
template_name = 'blank.html'
model = Homework
def get(self, request, *args, **kwargs):
result = dict()
homework_base = self.get_object()
homework = homework_base
groups = GroupOfStudents.objects.filter(homework=homework)
student = self.request.user.student
if homework_base.homework_to_evaluate is not None:
homework = homework_base.homework_to_evaluate
groups = GroupOfStudents.objects.filter(homework=homework)
else:
group_student = get_object_or_404(GroupOfStudents, students=student, homework=homework)
groups = groups.exclude(id=group_student.id)
groups = groups \
.exclude(videoclase__video__isnull=True) \
.exclude(videoclase__video__exact='') \
.exclude(videoclase__answers__student=student) \
.annotate(revision=Count('videoclase__answers')) \
.order_by('revision', '?')
element_response = groups[0] if groups.exists() else None
control = QualityControl.objects.filter(homework=homework)
control = control[0] if control.exists() else None
if control:
evaluated_items = control.list_items.filter(videoclase__answers__student=student)
# limit max evaluation of quality item to 5
if evaluated_items.count() < 3:
items = control.list_items.all() \
.exclude(videoclase__answers__student=student)
item_to_evaluate = items[random.randint(0, items.count()-1)] if items.exists() else None
if item_to_evaluate and element_response:
value_random = random.random()
# TODO: need to be a more smart filter
element_response = item_to_evaluate if value_random > 0.55 else element_response
elif item_to_evaluate:
element_response = item_to_evaluate
if element_response:
alternativas = [element_response.videoclase.correct_alternative,
element_response.videoclase.alternative_2,
element_response.videoclase.alternative_3]
random.shuffle(alternativas)
result['video'] = element_response.videoclase.video
result['question'] = element_response.videoclase.question
result['videoclase_id'] = element_response.videoclase.pk
result['alternativas'] = alternativas
result['redirect'] = False
else:
result['redirect'] = True
return JsonResponse(result)
def get_context_data(self, **kwargs):
context = super(GetVideoClaseView, self).get_context_data(**kwargs)
return context
@method_decorator(user_passes_test(in_students_group, login_url='/'))
def dispatch(self, *args, **kwargs):
obj = self.get_object()
hw = Homework.objects.filter(id=obj.id,course__students=self.request.user.student)
if hw.count() == 0:
messages.info(self.request, 'No tienes permisos para evaluar esta tarea.')
return HttpResponseRedirect(reverse('student'))
return super(GetVideoClaseView, self).dispatch(*args, **kwargs)
|
gpl-3.0
|
[
646,
2196,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
922,
63,
16027,
63,
396,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
697,
14,
992,
14,
21622,
492,
14826,
199,
504,
1639,
14,
1014,
14,
1310,
492,
21072,
12,
14935,
199,
504,
1639,
14,
17469,
492,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
4196,
14,
6767,
14,
1095,
492,
5458,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
5506,
492,
13302,
2768,
199,
504,
1639,
14,
1018,
492,
12506,
199,
199,
504,
11030,
63,
2785,
14,
992,
14,
9161,
63,
2785,
492,
24108,
3717,
199,
504,
1321,
271,
679,
416,
874,
14,
992,
14,
923,
1618,
17921,
492,
5611,
3466,
18086,
83,
199,
504,
1321,
271,
679,
416,
874,
14,
992,
14,
4219,
800,
492,
14621,
800,
199,
504,
1321,
271,
679,
416,
874,
14,
992,
14,
5500,
63,
2579,
18012,
492,
17246,
10006,
18012,
421,
199,
318,
315,
63,
17921,
63,
923,
8,
751,
304,
272,
340,
922,
26,
267,
372,
922,
14,
2634,
14,
1541,
8,
354,
534,
2439,
1307,
736,
1959,
2444,
342,
272,
372,
756,
199,
199,
533,
2372,
9166,
12086,
261,
2768,
8,
28539,
304,
272,
1978,
63,
354,
275,
283,
2500,
14,
1360,
7,
272,
1402,
275,
14621,
800,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
754,
275,
1211,
342,
267,
5629,
800,
63,
1095,
275,
291,
14,
362,
63,
785,
342,
267,
5629,
800,
275,
5629,
800,
63,
1095,
267,
4652,
275,
5611,
3466,
18086,
83,
14,
1462,
14,
1541,
8,
4219,
800,
29,
4219,
800,
9,
267,
6474,
275,
291,
14,
1069,
14,
751,
14,
5500,
267,
340,
5629,
800,
63,
1095,
14,
4219,
800,
63,
475,
63,
7383,
365,
440,
488,
26,
288,
5629,
800,
275,
5629,
800,
63,
1095,
14,
4219,
800,
63,
475,
63,
7383,
288,
4652,
275,
5611,
3466,
18086,
83,
14,
1462,
14,
1541,
8,
4219,
800,
29,
4219,
800,
9,
267,
587,
26,
288,
1572,
63,
5500,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
2448,
3466,
18086,
83,
12,
18557,
29,
5500,
12,
5629,
800,
29,
4219,
800,
9,
288,
4652,
275,
4652,
14,
5473,
8,
344,
29,
923,
63,
5500,
14,
344,
9,
398,
4652,
275,
4652,
971,
288,
1275,
5473,
8,
5624,
679,
416,
261,
363,
3722,
363,
15114,
29,
549,
9,
971,
288,
1275,
5473,
8,
5624,
679,
416,
261,
363,
3722,
363,
7327,
13275,
971,
288,
1275,
5473,
8,
5624,
679,
416,
261,
363,
13379,
363,
5500,
29,
5500,
9,
971,
288,
1275,
10898,
8,
5792,
29,
2353,
360,
5624,
679,
416,
261,
363,
13379,
1333,
971,
288,
1275,
1648,
63,
991,
360,
5792,
297,
8720,
358,
267,
1819,
63,
1310,
275,
4652,
59,
16,
61,
340,
4652,
14,
2444,
342,
587,
488,
267,
3304,
275,
24108,
3717,
14,
1462,
14,
1541,
8,
4219,
800,
29,
4219,
800,
9,
267,
3304,
275,
3304,
59,
16,
61,
340,
3304,
14,
2444,
342,
587,
488,
398,
340,
3304,
26,
288,
13006,
63,
1744,
275,
3304,
14,
513,
63,
1744,
14,
1541,
8,
5624,
679,
416,
261,
363,
13379,
363,
5500,
29,
5500,
9,
288,
327,
2304,
1390,
11735,
402,
11030,
1242,
370,
959,
288,
340,
13006,
63,
1744,
14,
835,
342,
665,
650,
26,
355,
2974,
275,
3304,
14,
513,
63,
1744,
14,
452,
342,
971,
490,
1275,
5473,
8,
5624,
679,
416,
261,
363,
13379,
363,
5500,
29,
5500,
9,
355,
1242,
63,
475,
63,
7383,
275,
2974,
59,
2355,
14,
8393,
8,
16,
12,
2974,
14,
835,
22251,
17,
1874,
340,
2974,
14,
2444,
342,
587,
488,
355,
340,
1242,
63,
475,
63,
7383,
436,
1819,
63,
1310,
26,
490,
574,
63,
2355,
275,
2196,
14,
2355,
342,
490,
327,
3254,
26,
1929,
370,
506,
282,
1655,
11179,
2457,
490,
1819,
63,
1310,
275,
1242,
63,
475,
63,
7383,
340,
574,
63,
2355,
690,
378,
14,
1229,
587,
1819,
63,
1310,
355,
916,
1242,
63,
475,
63,
7383,
26,
490,
1819,
63,
1310,
275,
1242,
63,
475,
63,
7383,
398,
340,
1819,
63,
1310,
26,
288,
8679,
2159,
4755,
275,
359,
2108,
63,
1310,
14,
5624,
679,
416,
261,
14,
4525,
63,
19389,
12,
1169,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
19389,
63,
18,
12,
1169,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
19389,
63,
19,
61,
288,
2196,
14,
11777,
8,
10280,
2159,
4755,
9,
288,
754,
459,
3722,
418,
275,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
3722,
288,
754,
459,
4790,
418,
275,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
4790,
288,
754,
459,
5624,
679,
416,
261,
63,
344,
418,
275,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
2051,
288,
754,
459,
10280,
2159,
4755,
418,
275,
8679,
2159,
4755,
288,
754,
459,
4876,
418,
275,
756,
267,
587,
26,
288,
754,
459,
4876,
418,
275,
715,
267,
372,
21072,
8,
1099,
9,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
1002,
9166,
12086,
261,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
372,
1067,
339,
768,
765,
63,
11547,
8,
751,
63,
16027,
63,
396,
8,
262,
63,
17921,
63,
923,
12,
4676,
63,
633,
8805,
1333,
272,
347,
7634,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1559,
275,
291,
14,
362,
63,
785,
342,
267,
12073,
275,
14621,
800,
14,
1462,
14,
1541,
8,
344,
29,
1113,
14,
344,
12,
1972,
363,
17921,
29,
277,
14,
1069,
14,
751,
14,
5500,
9,
267,
340,
12073,
14,
835,
342,
508,
378,
26,
288,
3788,
14,
815,
8,
277,
14,
1069,
12,
283,
1944,
3367,
287,
397,
1126,
1292,
736,
12665,
8031,
285,
325,
1207,
307,
6789,
2659,
288,
372,
14935,
8,
4471,
360,
5500,
1333,
267,
372,
1613,
8,
1002,
9166,
12086,
261,
2768,
12,
291,
680,
6052,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768
] |
[
2196,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
922,
63,
16027,
63,
396,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
697,
14,
992,
14,
21622,
492,
14826,
199,
504,
1639,
14,
1014,
14,
1310,
492,
21072,
12,
14935,
199,
504,
1639,
14,
17469,
492,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
4196,
14,
6767,
14,
1095,
492,
5458,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
5506,
492,
13302,
2768,
199,
504,
1639,
14,
1018,
492,
12506,
199,
199,
504,
11030,
63,
2785,
14,
992,
14,
9161,
63,
2785,
492,
24108,
3717,
199,
504,
1321,
271,
679,
416,
874,
14,
992,
14,
923,
1618,
17921,
492,
5611,
3466,
18086,
83,
199,
504,
1321,
271,
679,
416,
874,
14,
992,
14,
4219,
800,
492,
14621,
800,
199,
504,
1321,
271,
679,
416,
874,
14,
992,
14,
5500,
63,
2579,
18012,
492,
17246,
10006,
18012,
421,
199,
318,
315,
63,
17921,
63,
923,
8,
751,
304,
272,
340,
922,
26,
267,
372,
922,
14,
2634,
14,
1541,
8,
354,
534,
2439,
1307,
736,
1959,
2444,
342,
272,
372,
756,
199,
199,
533,
2372,
9166,
12086,
261,
2768,
8,
28539,
304,
272,
1978,
63,
354,
275,
283,
2500,
14,
1360,
7,
272,
1402,
275,
14621,
800,
272,
347,
664,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
754,
275,
1211,
342,
267,
5629,
800,
63,
1095,
275,
291,
14,
362,
63,
785,
342,
267,
5629,
800,
275,
5629,
800,
63,
1095,
267,
4652,
275,
5611,
3466,
18086,
83,
14,
1462,
14,
1541,
8,
4219,
800,
29,
4219,
800,
9,
267,
6474,
275,
291,
14,
1069,
14,
751,
14,
5500,
267,
340,
5629,
800,
63,
1095,
14,
4219,
800,
63,
475,
63,
7383,
365,
440,
488,
26,
288,
5629,
800,
275,
5629,
800,
63,
1095,
14,
4219,
800,
63,
475,
63,
7383,
288,
4652,
275,
5611,
3466,
18086,
83,
14,
1462,
14,
1541,
8,
4219,
800,
29,
4219,
800,
9,
267,
587,
26,
288,
1572,
63,
5500,
275,
664,
63,
785,
63,
269,
63,
5188,
8,
2448,
3466,
18086,
83,
12,
18557,
29,
5500,
12,
5629,
800,
29,
4219,
800,
9,
288,
4652,
275,
4652,
14,
5473,
8,
344,
29,
923,
63,
5500,
14,
344,
9,
398,
4652,
275,
4652,
971,
288,
1275,
5473,
8,
5624,
679,
416,
261,
363,
3722,
363,
15114,
29,
549,
9,
971,
288,
1275,
5473,
8,
5624,
679,
416,
261,
363,
3722,
363,
7327,
13275,
971,
288,
1275,
5473,
8,
5624,
679,
416,
261,
363,
13379,
363,
5500,
29,
5500,
9,
971,
288,
1275,
10898,
8,
5792,
29,
2353,
360,
5624,
679,
416,
261,
363,
13379,
1333,
971,
288,
1275,
1648,
63,
991,
360,
5792,
297,
8720,
358,
267,
1819,
63,
1310,
275,
4652,
59,
16,
61,
340,
4652,
14,
2444,
342,
587,
488,
267,
3304,
275,
24108,
3717,
14,
1462,
14,
1541,
8,
4219,
800,
29,
4219,
800,
9,
267,
3304,
275,
3304,
59,
16,
61,
340,
3304,
14,
2444,
342,
587,
488,
398,
340,
3304,
26,
288,
13006,
63,
1744,
275,
3304,
14,
513,
63,
1744,
14,
1541,
8,
5624,
679,
416,
261,
363,
13379,
363,
5500,
29,
5500,
9,
288,
327,
2304,
1390,
11735,
402,
11030,
1242,
370,
959,
288,
340,
13006,
63,
1744,
14,
835,
342,
665,
650,
26,
355,
2974,
275,
3304,
14,
513,
63,
1744,
14,
452,
342,
971,
490,
1275,
5473,
8,
5624,
679,
416,
261,
363,
13379,
363,
5500,
29,
5500,
9,
355,
1242,
63,
475,
63,
7383,
275,
2974,
59,
2355,
14,
8393,
8,
16,
12,
2974,
14,
835,
22251,
17,
1874,
340,
2974,
14,
2444,
342,
587,
488,
355,
340,
1242,
63,
475,
63,
7383,
436,
1819,
63,
1310,
26,
490,
574,
63,
2355,
275,
2196,
14,
2355,
342,
490,
327,
3254,
26,
1929,
370,
506,
282,
1655,
11179,
2457,
490,
1819,
63,
1310,
275,
1242,
63,
475,
63,
7383,
340,
574,
63,
2355,
690,
378,
14,
1229,
587,
1819,
63,
1310,
355,
916,
1242,
63,
475,
63,
7383,
26,
490,
1819,
63,
1310,
275,
1242,
63,
475,
63,
7383,
398,
340,
1819,
63,
1310,
26,
288,
8679,
2159,
4755,
275,
359,
2108,
63,
1310,
14,
5624,
679,
416,
261,
14,
4525,
63,
19389,
12,
1169,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
19389,
63,
18,
12,
1169,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
19389,
63,
19,
61,
288,
2196,
14,
11777,
8,
10280,
2159,
4755,
9,
288,
754,
459,
3722,
418,
275,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
3722,
288,
754,
459,
4790,
418,
275,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
4790,
288,
754,
459,
5624,
679,
416,
261,
63,
344,
418,
275,
1819,
63,
1310,
14,
5624,
679,
416,
261,
14,
2051,
288,
754,
459,
10280,
2159,
4755,
418,
275,
8679,
2159,
4755,
288,
754,
459,
4876,
418,
275,
756,
267,
587,
26,
288,
754,
459,
4876,
418,
275,
715,
267,
372,
21072,
8,
1099,
9,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
1613,
8,
1002,
9166,
12086,
261,
2768,
12,
291,
680,
362,
63,
1100,
63,
576,
3682,
958,
9,
267,
372,
1067,
339,
768,
765,
63,
11547,
8,
751,
63,
16027,
63,
396,
8,
262,
63,
17921,
63,
923,
12,
4676,
63,
633,
8805,
1333,
272,
347,
7634,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1559,
275,
291,
14,
362,
63,
785,
342,
267,
12073,
275,
14621,
800,
14,
1462,
14,
1541,
8,
344,
29,
1113,
14,
344,
12,
1972,
363,
17921,
29,
277,
14,
1069,
14,
751,
14,
5500,
9,
267,
340,
12073,
14,
835,
342,
508,
378,
26,
288,
3788,
14,
815,
8,
277,
14,
1069,
12,
283,
1944,
3367,
287,
397,
1126,
1292,
736,
12665,
8031,
285,
325,
1207,
307,
6789,
2659,
288,
372,
14935,
8,
4471,
360,
5500,
1333,
267,
372,
1613,
8,
1002,
9166,
12086,
261,
2768,
12,
291,
680,
6052,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tchernomax/ansible
|
lib/ansible/config/manager.py
|
18
|
21112
|
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import io
import os
import os.path
import sys
import stat
import tempfile
import traceback
from collections import namedtuple
from yaml import load as yaml_load
try:
# use C version if possible for speedup
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
from ansible.config.data import ConfigData
from ansible.errors import AnsibleOptionsError, AnsibleError
from ansible.module_utils.six import PY3, string_types
from ansible.module_utils.six.moves import configparser
from ansible.module_utils._text import to_text, to_bytes, to_native
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.parsing.quoting import unquote
from ansible.utils import py3compat
from ansible.utils.path import unfrackpath
from ansible.utils.path import makedirs_safe
Plugin = namedtuple('Plugin', 'name type')
Setting = namedtuple('Setting', 'name value origin type')
INTERNAL_DEFS = {'lookup': ('_terms',)}
# FIXME: see if we can unify in module_utils with similar function used by argspec
def ensure_type(value, value_type, origin=None):
''' return a configuration variable with casting
:arg value: The value to ensure correct typing of
:kwarg value_type: The type of the value. This can be any of the following strings:
:boolean: sets the value to a True or False value
:integer: Sets the value to an integer or raises a ValueType error
:float: Sets the value to a float or raises a ValueType error
:list: Treats the value as a comma separated list. Split the value
and return it as a python list.
:none: Sets the value to None
:path: Expands any environment variables and tilde's in the value.
:tmp_path: Create a unique temporary directory inside of the directory
specified by value and return its path.
:pathlist: Treat the value as a typical PATH string. (On POSIX, this
means colon separated strings.) Split the value and then expand
each part for environment variables and tildes.
'''
basedir = None
if origin and os.path.isabs(origin) and os.path.exists(origin):
basedir = origin
if value_type:
value_type = value_type.lower()
if value_type in ('boolean', 'bool'):
value = boolean(value, strict=False)
elif value is not None:
if value_type in ('integer', 'int'):
value = int(value)
elif value_type == 'float':
value = float(value)
elif value_type == 'list':
if isinstance(value, string_types):
value = [x.strip() for x in value.split(',')]
elif value_type == 'none':
if value == "None":
value = None
elif value_type == 'path':
value = resolve_path(value, basedir=basedir)
elif value_type in ('tmp', 'temppath', 'tmppath'):
value = resolve_path(value, basedir=basedir)
if not os.path.exists(value):
makedirs_safe(value, 0o700)
prefix = 'ansible-local-%s' % os.getpid()
value = tempfile.mkdtemp(prefix=prefix, dir=value)
elif value_type == 'pathspec':
if isinstance(value, string_types):
value = value.split(os.pathsep)
value = [resolve_path(x, basedir=basedir) for x in value]
elif value_type == 'pathlist':
if isinstance(value, string_types):
value = value.split(',')
value = [resolve_path(x, basedir=basedir) for x in value]
elif value_type in ('str', 'string'):
value = unquote(to_text(value, errors='surrogate_or_strict'))
# defaults to string type
elif isinstance(value, string_types):
value = unquote(value)
return to_text(value, errors='surrogate_or_strict', nonstring='passthru')
# FIXME: see if this can live in utils/path
def resolve_path(path, basedir=None):
''' resolve relative or 'varaible' paths '''
if '{{CWD}}' in path: # allow users to force CWD using 'magic' {{CWD}}
path = path.replace('{{CWD}}', os.getcwd())
return unfrackpath(path, follow=False, basedir=basedir)
# FIXME: generic file type?
def get_config_type(cfile):
ftype = None
if cfile is not None:
ext = os.path.splitext(cfile)[-1]
if ext in ('.ini', '.cfg'):
ftype = 'ini'
elif ext in ('.yaml', '.yml'):
ftype = 'yaml'
else:
raise AnsibleOptionsError("Unsupported configuration file extension for %s: %s" % (cfile, to_native(ext)))
return ftype
# FIXME: can move to module_utils for use for ini plugins also?
def get_ini_config_value(p, entry):
''' returns the value of last ini entry found '''
value = None
if p is not None:
try:
value = p.get(entry.get('section', 'defaults'), entry.get('key', ''), raw=True)
except Exception: # FIXME: actually report issues here
pass
return value
def find_ini_config_file(warnings=None):
''' Load INI Config File order(first found is used): ENV, CWD, HOME, /etc/ansible '''
# FIXME: eventually deprecate ini configs
if warnings is None:
# Note: In this case, warnings does nothing
warnings = set()
# A value that can never be a valid path so that we can tell if ANSIBLE_CONFIG was set later
# We can't use None because we could set path to None.
SENTINEL = object
potential_paths = []
# Environment setting
path_from_env = os.getenv("ANSIBLE_CONFIG", SENTINEL)
if path_from_env is not SENTINEL:
path_from_env = unfrackpath(path_from_env, follow=False)
if os.path.isdir(path_from_env):
path_from_env = os.path.join(path_from_env, "ansible.cfg")
potential_paths.append(path_from_env)
# Current working directory
warn_cmd_public = False
try:
cwd = os.getcwd()
perms = os.stat(cwd)
cwd_cfg = os.path.join(cwd, "ansible.cfg")
if perms.st_mode & stat.S_IWOTH:
# Working directory is world writable so we'll skip it.
# Still have to look for a file here, though, so that we know if we have to warn
if os.path.exists(cwd_cfg):
warn_cmd_public = True
else:
potential_paths.append(cwd_cfg)
except OSError:
# If we can't access cwd, we'll simply skip it as a possible config source
pass
# Per user location
potential_paths.append(unfrackpath("~/.ansible.cfg", follow=False))
# System location
potential_paths.append("/etc/ansible/ansible.cfg")
for path in potential_paths:
if os.path.exists(path):
break
else:
path = None
# Emit a warning if all the following are true:
# * We did not use a config from ANSIBLE_CONFIG
# * There's an ansible.cfg in the current working directory that we skipped
if path_from_env != path and warn_cmd_public:
warnings.add(u"Ansible is being run in a world writable directory (%s),"
u" ignoring it as an ansible.cfg source."
u" For more information see"
u" https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir"
% to_text(cwd))
return path
class ConfigManager(object):
DEPRECATED = []
WARNINGS = set()
def __init__(self, conf_file=None, defs_file=None):
self._base_defs = {}
self._plugins = {}
self._parsers = {}
self._config_file = conf_file
self.data = ConfigData()
self._base_defs = self._read_config_yaml_file(defs_file or ('%s/base.yml' % os.path.dirname(__file__)))
if self._config_file is None:
# set config using ini
self._config_file = find_ini_config_file(self.WARNINGS)
# consume configuration
if self._config_file:
if os.path.exists(self._config_file):
# initialize parser and read config
self._parse_config_file()
# update constants
self.update_config_data()
try:
self.update_module_defaults_groups()
except Exception as e:
# Since this is a 2.7 preview feature, we want to have it fail as gracefully as possible when there are issues.
sys.stderr.write('Could not load module_defaults_groups: %s: %s\n\n' % (type(e).__name__, e))
self.module_defaults_groups = {}
def _read_config_yaml_file(self, yml_file):
# TODO: handle relative paths as relative to the directory containing the current playbook instead of CWD
# Currently this is only used with absolute paths to the `ansible/config` directory
yml_file = to_bytes(yml_file)
if os.path.exists(yml_file):
with open(yml_file, 'rb') as config_def:
return yaml_load(config_def, Loader=SafeLoader) or {}
raise AnsibleError(
"Missing base YAML definition file (bad install?): %s" % to_native(yml_file))
def _parse_config_file(self, cfile=None):
''' return flat configuration settings from file(s) '''
# TODO: take list of files with merge/nomerge
if cfile is None:
cfile = self._config_file
ftype = get_config_type(cfile)
if cfile is not None:
if ftype == 'ini':
self._parsers[cfile] = configparser.ConfigParser()
with open(cfile, 'rb') as f:
try:
cfg_text = to_text(f.read(), errors='surrogate_or_strict')
except UnicodeError as e:
raise AnsibleOptionsError("Error reading config file(%s) because the config file was not utf8 encoded: %s" % (cfile, to_native(e)))
try:
if PY3:
self._parsers[cfile].read_string(cfg_text)
else:
cfg_file = io.StringIO(cfg_text)
self._parsers[cfile].readfp(cfg_file)
except configparser.Error as e:
raise AnsibleOptionsError("Error reading config file (%s): %s" % (cfile, to_native(e)))
# FIXME: this should eventually handle yaml config files
# elif ftype == 'yaml':
# with open(cfile, 'rb') as config_stream:
# self._parsers[cfile] = yaml.safe_load(config_stream)
else:
raise AnsibleOptionsError("Unsupported configuration file type: %s" % to_native(ftype))
def _find_yaml_config_files(self):
''' Load YAML Config Files in order, check merge flags, keep origin of settings'''
pass
def get_plugin_options(self, plugin_type, name, keys=None, variables=None, direct=None):
options = {}
defs = self.get_configuration_definitions(plugin_type, name)
for option in defs:
options[option] = self.get_config_value(option, plugin_type=plugin_type, plugin_name=name, keys=keys, variables=variables, direct=direct)
return options
def get_plugin_vars(self, plugin_type, name):
pvars = []
for pdef in self.get_configuration_definitions(plugin_type, name).values():
if 'vars' in pdef and pdef['vars']:
for var_entry in pdef['vars']:
pvars.append(var_entry['name'])
return pvars
def get_configuration_definitions(self, plugin_type=None, name=None):
''' just list the possible settings, either base or for specific plugins or plugin '''
ret = {}
if plugin_type is None:
ret = self._base_defs
elif name is None:
ret = self._plugins.get(plugin_type, {})
else:
ret = self._plugins.get(plugin_type, {}).get(name, {})
return ret
def _loop_entries(self, container, entry_list):
''' repeat code for value entry assignment '''
value = None
origin = None
for entry in entry_list:
name = entry.get('name')
temp_value = container.get(name, None)
if temp_value is not None: # only set if env var is defined
value = temp_value
origin = name
# deal with deprecation of setting source, if used
if 'deprecated' in entry:
self.DEPRECATED.append((entry['name'], entry['deprecated']))
return value, origin
def get_config_value(self, config, cfile=None, plugin_type=None, plugin_name=None, keys=None, variables=None, direct=None):
''' wrapper '''
try:
value, _drop = self.get_config_value_and_origin(config, cfile=cfile, plugin_type=plugin_type, plugin_name=plugin_name,
keys=keys, variables=variables, direct=direct)
except AnsibleError:
raise
except Exception as e:
raise AnsibleError("Unhandled exception when retrieving %s:\n%s" % (config, traceback.format_exc()))
return value
def get_config_value_and_origin(self, config, cfile=None, plugin_type=None, plugin_name=None, keys=None, variables=None, direct=None):
''' Given a config key figure out the actual value and report on the origin of the settings '''
if cfile is None:
# use default config
cfile = self._config_file
# Note: sources that are lists listed in low to high precedence (last one wins)
value = None
origin = None
defs = {}
if plugin_type is None:
defs = self._base_defs
elif plugin_name is None:
defs = self._plugins[plugin_type]
else:
defs = self._plugins[plugin_type][plugin_name]
if config in defs:
# direct setting via plugin arguments, can set to None so we bypass rest of processing/defaults
if direct and config in direct:
value = direct[config]
origin = 'Direct'
else:
# Use 'variable overrides' if present, highest precedence, but only present when querying running play
if variables and defs[config].get('vars'):
value, origin = self._loop_entries(variables, defs[config]['vars'])
origin = 'var: %s' % origin
# use playbook keywords if you have em
if value is None and keys and defs[config].get('keywords'):
value, origin = self._loop_entries(keys, defs[config]['keywords'])
origin = 'keyword: %s' % origin
# env vars are next precedence
if value is None and defs[config].get('env'):
value, origin = self._loop_entries(py3compat.environ, defs[config]['env'])
origin = 'env: %s' % origin
# try config file entries next, if we have one
if self._parsers.get(cfile, None) is None:
self._parse_config_file(cfile)
if value is None and cfile is not None:
ftype = get_config_type(cfile)
if ftype and defs[config].get(ftype):
if ftype == 'ini':
# load from ini config
try: # FIXME: generalize _loop_entries to allow for files also, most of this code is dupe
for ini_entry in defs[config]['ini']:
temp_value = get_ini_config_value(self._parsers[cfile], ini_entry)
if temp_value is not None:
value = temp_value
origin = cfile
if 'deprecated' in ini_entry:
self.DEPRECATED.append(('[%s]%s' % (ini_entry['section'], ini_entry['key']), ini_entry['deprecated']))
except Exception as e:
sys.stderr.write("Error while loading ini config %s: %s" % (cfile, to_native(e)))
elif ftype == 'yaml':
# FIXME: implement, also , break down key from defs (. notation???)
origin = cfile
# set default if we got here w/o a value
if value is None:
if defs[config].get('required', False):
entry = ''
if plugin_type:
entry += 'plugin_type: %s ' % plugin_type
if plugin_name:
entry += 'plugin: %s ' % plugin_name
entry += 'setting: %s ' % config
if not plugin_type or config not in INTERNAL_DEFS.get(plugin_type, {}):
raise AnsibleError("No setting was provided for required configuration %s" % (entry))
else:
value = defs[config].get('default')
origin = 'default'
# skip typing as this is a temlated default that will be resolved later in constants, which has needed vars
if plugin_type is None and isinstance(value, string_types) and (value.startswith('{{') and value.endswith('}}')):
return value, origin
# ensure correct type, can raise exceptoins on mismatched types
value = ensure_type(value, defs[config].get('type'), origin=origin)
# deal with deprecation of the setting
if 'deprecated' in defs[config] and origin != 'default':
self.DEPRECATED.append((config, defs[config].get('deprecated')))
else:
raise AnsibleError('Requested option %s was not defined in configuration' % to_native(config))
return value, origin
def initialize_plugin_configuration_definitions(self, plugin_type, name, defs):
if plugin_type not in self._plugins:
self._plugins[plugin_type] = {}
self._plugins[plugin_type][name] = defs
def update_module_defaults_groups(self):
defaults_config = self._read_config_yaml_file(
'%s/module_defaults.yml' % os.path.join(os.path.dirname(__file__))
)
if defaults_config.get('version') not in ('1', '1.0', 1, 1.0):
raise AnsibleError('module_defaults.yml has an invalid version "%s" for configuration. Could be a bad install.' % defaults_config.get('version'))
self.module_defaults_groups = defaults_config.get('groupings', {})
def update_config_data(self, defs=None, configfile=None):
''' really: update constants '''
if defs is None:
defs = self._base_defs
if configfile is None:
configfile = self._config_file
if not isinstance(defs, dict):
raise AnsibleOptionsError("Invalid configuration definition type: %s for %s" % (type(defs), defs))
# update the constant for config file
self.data.update_setting(Setting('CONFIG_FILE', configfile, '', 'string'))
origin = None
# env and config defs can have several entries, ordered in list from lowest to highest precedence
for config in defs:
if not isinstance(defs[config], dict):
raise AnsibleOptionsError("Invalid configuration definition '%s': type is %s" % (to_native(config), type(defs[config])))
# get value and origin
try:
value, origin = self.get_config_value_and_origin(config, configfile)
except Exception as e:
# Printing the problem here because, in the current code:
# (1) we can't reach the error handler for AnsibleError before we
# hit a different error due to lack of working config.
# (2) We don't have access to display yet because display depends on config
# being properly loaded.
#
# If we start getting double errors printed from this section of code, then the
# above problem #1 has been fixed. Revamp this to be more like the try: except
# in get_config_value() at that time.
sys.stderr.write("Unhandled error:\n %s\n\n" % traceback.format_exc())
raise AnsibleError("Invalid settings supplied for %s: %s\n%s" % (config, to_native(e), traceback.format_exc()))
# set the constant
self.data.update_setting(Setting(config, value, origin, defs[config].get('type', 'string')))
|
gpl-3.0
|
[
3,
1898,
26,
334,
67,
9,
9708,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
5890,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
5672,
199,
646,
5549,
199,
646,
5190,
199,
504,
5055,
492,
12863,
199,
199,
504,
8864,
492,
2248,
465,
8864,
63,
912,
199,
893,
26,
272,
327,
675,
445,
1015,
340,
3962,
367,
8112,
384,
272,
687,
8864,
492,
445,
11090,
5455,
465,
14969,
5455,
199,
2590,
3545,
26,
272,
687,
8864,
492,
14969,
5455,
199,
199,
504,
3242,
14,
888,
14,
576,
492,
4094,
1451,
199,
504,
3242,
14,
2550,
492,
2622,
4558,
547,
12,
13358,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
7843,
19,
12,
1059,
63,
1313,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
21230,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
12,
370,
63,
2394,
12,
370,
63,
6106,
199,
504,
3242,
14,
578,
63,
1208,
14,
11059,
14,
3916,
63,
2245,
492,
5046,
199,
504,
3242,
14,
11059,
14,
25272,
492,
14342,
199,
504,
3242,
14,
1208,
492,
1134,
19,
5819,
199,
504,
3242,
14,
1208,
14,
515,
492,
625,
70,
8085,
515,
199,
504,
3242,
14,
1208,
14,
515,
492,
1852,
3220,
63,
3489,
421,
199,
5061,
275,
12863,
360,
5061,
297,
283,
354,
730,
358,
199,
7776,
275,
12863,
360,
7776,
297,
283,
354,
574,
6330,
730,
358,
199,
199,
17681,
63,
5638,
51,
275,
791,
3892,
356,
12331,
9187,
297,
6769,
421,
199,
3,
7600,
26,
1937,
340,
781,
883,
625,
2021,
315,
859,
63,
1208,
543,
8545,
805,
1202,
701,
26632,
199,
318,
4868,
63,
466,
8,
585,
12,
574,
63,
466,
12,
6330,
29,
403,
304,
272,
1449,
372,
282,
2897,
1750,
543,
22883,
272,
520,
1273,
574,
26,
710,
574,
370,
4868,
3211,
14090,
402,
272,
520,
12745,
574,
63,
466,
26,
710,
730,
402,
314,
574,
14,
221,
961,
883,
506,
1263,
402,
314,
2569,
3326,
26,
267,
520,
4871,
26,
5951,
314,
574,
370,
282,
715,
503,
756,
574,
267,
520,
4115,
26,
10729,
314,
574,
370,
376,
3000,
503,
6534,
282,
1594,
804,
1125,
267,
520,
1609,
26,
10729,
314,
574,
370,
282,
2069,
503,
6534,
282,
1594,
804,
1125,
267,
520,
513,
26,
377,
264,
1956,
314,
574,
465,
282,
10029,
11673,
769,
14,
221,
11740,
314,
574,
288,
436,
372,
652,
465,
282,
2366,
769,
14,
267,
520,
3592,
26,
10729,
314,
574,
370,
488,
267,
520,
515,
26,
7910,
5915,
1263,
3734,
2860,
436,
221,
16488,
1159,
315,
314,
574,
14,
267,
520,
2791,
63,
515,
26,
2790,
282,
3747,
7937,
2082,
6272,
402,
314,
2082,
288,
2013,
701,
574,
436,
372,
2399,
931,
14,
267,
520,
515,
513,
26,
377,
8319,
314,
574,
465,
282,
25780,
15097,
1059,
14,
221,
334,
3314,
18169,
12,
642,
288,
4910,
18307,
11673,
3326,
4959,
221,
11740,
314,
574,
436,
2066,
6544,
288,
1924,
1777,
367,
3734,
2860,
436,
221,
2270,
3424,
14,
272,
1449,
339,
19380,
275,
488,
272,
340,
6330,
436,
747,
14,
515,
14,
17896,
8,
6493,
9,
436,
747,
14,
515,
14,
2444,
8,
6493,
304,
267,
19380,
275,
6330,
339,
340,
574,
63,
466,
26,
267,
574,
63,
466,
275,
574,
63,
466,
14,
2325,
342,
339,
340,
574,
63,
466,
315,
661,
4871,
297,
283,
2245,
735,
267,
574,
275,
5046,
8,
585,
12,
7478,
29,
797,
9,
339,
916,
574,
365,
440,
488,
26,
267,
340,
574,
63,
466,
315,
661,
4115,
297,
283,
442,
735,
288,
574,
275,
1109,
8,
585,
9,
398,
916,
574,
63,
466,
508,
283,
1609,
356,
288,
574,
275,
2069,
8,
585,
9,
398,
916,
574,
63,
466,
508,
283,
513,
356,
288,
340,
1228,
8,
585,
12,
1059,
63,
1313,
304,
355,
574,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
574,
14,
1294,
29972,
398,
916,
574,
63,
466,
508,
283,
3592,
356,
288,
340,
574,
508,
298,
403,
582,
355,
574,
275,
488,
398,
916,
574,
63,
466,
508,
283,
515,
356,
288,
574,
275,
7512,
63,
515,
8,
585,
12,
19380,
29,
12484,
9,
398,
916,
574,
63,
466,
315,
661,
2791,
297,
283,
808,
515,
297,
283,
2791,
515,
735,
288,
574,
275,
7512,
63,
515,
8,
585,
12,
19380,
29,
12484,
9,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
585,
304,
355,
1852,
3220,
63,
3489,
8,
585,
12,
378,
79,
15946,
9,
288,
2403,
275,
283,
4853,
13,
1832,
3295,
83,
7,
450,
747,
14,
17829,
342,
288,
574,
275,
5549,
14,
11983,
8,
1861,
29,
1861,
12,
2935,
29,
585,
9,
398,
916,
574,
63,
466,
508,
283,
515,
1650,
356,
288,
340,
1228,
8,
585,
12,
1059,
63,
1313,
304,
355,
574,
275,
574,
14,
1294,
8,
736,
14,
17843,
9,
288,
574,
275,
359,
6983,
63,
515,
8,
88,
12,
19380,
29,
12484,
9,
367,
671,
315,
574,
61,
398,
916,
574,
63,
466,
508,
283,
515,
513,
356,
288,
340,
1228,
8,
585,
12,
1059,
63,
1313,
304,
355,
574,
275,
574,
14,
1294,
11917,
288,
574,
275,
359,
6983,
63,
515,
8,
88,
12,
19380,
29,
12484,
9,
367,
671,
315,
574,
61,
398,
916,
574,
63,
466,
315,
661,
495,
297,
283,
875,
735,
288,
574,
275,
14342,
8,
475,
63,
505,
8,
585,
12,
2552,
534,
16380,
63,
269,
63,
4768,
1333,
398,
327,
4243,
370,
1059,
730,
267,
916,
1228,
8,
585,
12,
1059,
63,
1313,
304,
288,
574,
275,
14342,
8,
585,
9,
339,
372,
370,
63,
505,
8,
585,
12,
2552,
534,
16380,
63,
269,
63,
4768,
297,
2222,
875,
534,
15534,
270,
6271,
85,
358,
421,
199,
3,
7600,
26,
1937,
340,
642,
883,
12166,
315,
3778,
15,
515,
199,
318,
7512,
63,
515,
8,
515,
12,
19380
] |
[
1898,
26,
334,
67,
9,
9708,
12,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
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,
5890,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
5672,
199,
646,
5549,
199,
646,
5190,
199,
504,
5055,
492,
12863,
199,
199,
504,
8864,
492,
2248,
465,
8864,
63,
912,
199,
893,
26,
272,
327,
675,
445,
1015,
340,
3962,
367,
8112,
384,
272,
687,
8864,
492,
445,
11090,
5455,
465,
14969,
5455,
199,
2590,
3545,
26,
272,
687,
8864,
492,
14969,
5455,
199,
199,
504,
3242,
14,
888,
14,
576,
492,
4094,
1451,
199,
504,
3242,
14,
2550,
492,
2622,
4558,
547,
12,
13358,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
7843,
19,
12,
1059,
63,
1313,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
21230,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
12,
370,
63,
2394,
12,
370,
63,
6106,
199,
504,
3242,
14,
578,
63,
1208,
14,
11059,
14,
3916,
63,
2245,
492,
5046,
199,
504,
3242,
14,
11059,
14,
25272,
492,
14342,
199,
504,
3242,
14,
1208,
492,
1134,
19,
5819,
199,
504,
3242,
14,
1208,
14,
515,
492,
625,
70,
8085,
515,
199,
504,
3242,
14,
1208,
14,
515,
492,
1852,
3220,
63,
3489,
421,
199,
5061,
275,
12863,
360,
5061,
297,
283,
354,
730,
358,
199,
7776,
275,
12863,
360,
7776,
297,
283,
354,
574,
6330,
730,
358,
199,
199,
17681,
63,
5638,
51,
275,
791,
3892,
356,
12331,
9187,
297,
6769,
421,
199,
3,
7600,
26,
1937,
340,
781,
883,
625,
2021,
315,
859,
63,
1208,
543,
8545,
805,
1202,
701,
26632,
199,
318,
4868,
63,
466,
8,
585,
12,
574,
63,
466,
12,
6330,
29,
403,
304,
272,
1449,
372,
282,
2897,
1750,
543,
22883,
272,
520,
1273,
574,
26,
710,
574,
370,
4868,
3211,
14090,
402,
272,
520,
12745,
574,
63,
466,
26,
710,
730,
402,
314,
574,
14,
221,
961,
883,
506,
1263,
402,
314,
2569,
3326,
26,
267,
520,
4871,
26,
5951,
314,
574,
370,
282,
715,
503,
756,
574,
267,
520,
4115,
26,
10729,
314,
574,
370,
376,
3000,
503,
6534,
282,
1594,
804,
1125,
267,
520,
1609,
26,
10729,
314,
574,
370,
282,
2069,
503,
6534,
282,
1594,
804,
1125,
267,
520,
513,
26,
377,
264,
1956,
314,
574,
465,
282,
10029,
11673,
769,
14,
221,
11740,
314,
574,
288,
436,
372,
652,
465,
282,
2366,
769,
14,
267,
520,
3592,
26,
10729,
314,
574,
370,
488,
267,
520,
515,
26,
7910,
5915,
1263,
3734,
2860,
436,
221,
16488,
1159,
315,
314,
574,
14,
267,
520,
2791,
63,
515,
26,
2790,
282,
3747,
7937,
2082,
6272,
402,
314,
2082,
288,
2013,
701,
574,
436,
372,
2399,
931,
14,
267,
520,
515,
513,
26,
377,
8319,
314,
574,
465,
282,
25780,
15097,
1059,
14,
221,
334,
3314,
18169,
12,
642,
288,
4910,
18307,
11673,
3326,
4959,
221,
11740,
314,
574,
436,
2066,
6544,
288,
1924,
1777,
367,
3734,
2860,
436,
221,
2270,
3424,
14,
272,
1449,
339,
19380,
275,
488,
272,
340,
6330,
436,
747,
14,
515,
14,
17896,
8,
6493,
9,
436,
747,
14,
515,
14,
2444,
8,
6493,
304,
267,
19380,
275,
6330,
339,
340,
574,
63,
466,
26,
267,
574,
63,
466,
275,
574,
63,
466,
14,
2325,
342,
339,
340,
574,
63,
466,
315,
661,
4871,
297,
283,
2245,
735,
267,
574,
275,
5046,
8,
585,
12,
7478,
29,
797,
9,
339,
916,
574,
365,
440,
488,
26,
267,
340,
574,
63,
466,
315,
661,
4115,
297,
283,
442,
735,
288,
574,
275,
1109,
8,
585,
9,
398,
916,
574,
63,
466,
508,
283,
1609,
356,
288,
574,
275,
2069,
8,
585,
9,
398,
916,
574,
63,
466,
508,
283,
513,
356,
288,
340,
1228,
8,
585,
12,
1059,
63,
1313,
304,
355,
574,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
574,
14,
1294,
29972,
398,
916,
574,
63,
466,
508,
283,
3592,
356,
288,
340,
574,
508,
298,
403,
582,
355,
574,
275,
488,
398,
916,
574,
63,
466,
508,
283,
515,
356,
288,
574,
275,
7512,
63,
515,
8,
585,
12,
19380,
29,
12484,
9,
398,
916,
574,
63,
466,
315,
661,
2791,
297,
283,
808,
515,
297,
283,
2791,
515,
735,
288,
574,
275,
7512,
63,
515,
8,
585,
12,
19380,
29,
12484,
9,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
585,
304,
355,
1852,
3220,
63,
3489,
8,
585,
12,
378,
79,
15946,
9,
288,
2403,
275,
283,
4853,
13,
1832,
3295,
83,
7,
450,
747,
14,
17829,
342,
288,
574,
275,
5549,
14,
11983,
8,
1861,
29,
1861,
12,
2935,
29,
585,
9,
398,
916,
574,
63,
466,
508,
283,
515,
1650,
356,
288,
340,
1228,
8,
585,
12,
1059,
63,
1313,
304,
355,
574,
275,
574,
14,
1294,
8,
736,
14,
17843,
9,
288,
574,
275,
359,
6983,
63,
515,
8,
88,
12,
19380,
29,
12484,
9,
367,
671,
315,
574,
61,
398,
916,
574,
63,
466,
508,
283,
515,
513,
356,
288,
340,
1228,
8,
585,
12,
1059,
63,
1313,
304,
355,
574,
275,
574,
14,
1294,
11917,
288,
574,
275,
359,
6983,
63,
515,
8,
88,
12,
19380,
29,
12484,
9,
367,
671,
315,
574,
61,
398,
916,
574,
63,
466,
315,
661,
495,
297,
283,
875,
735,
288,
574,
275,
14342,
8,
475,
63,
505,
8,
585,
12,
2552,
534,
16380,
63,
269,
63,
4768,
1333,
398,
327,
4243,
370,
1059,
730,
267,
916,
1228,
8,
585,
12,
1059,
63,
1313,
304,
288,
574,
275,
14342,
8,
585,
9,
339,
372,
370,
63,
505,
8,
585,
12,
2552,
534,
16380,
63,
269,
63,
4768,
297,
2222,
875,
534,
15534,
270,
6271,
85,
358,
421,
199,
3,
7600,
26,
1937,
340,
642,
883,
12166,
315,
3778,
15,
515,
199,
318,
7512,
63,
515,
8,
515,
12,
19380,
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
] |
dgsantana/arsenalsuite
|
cpp/lib/PyQt4/examples/mainwindows/recentfiles.py
|
17
|
8720
|
#!/usr/bin/env python
#############################################################################
##
## Copyright (C) 2010 Riverbank Computing Limited.
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
## All rights reserved.
##
## This file is part of the examples of PyQt.
##
## $QT_BEGIN_LICENSE:BSD$
## You may use this file under the terms of the BSD license as follows:
##
## "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 Nokia Corporation and its Subsidiary(-ies) 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."
## $QT_END_LICENSE$
##
#############################################################################
# These are only needed for Python v2 but are harmless for Python v3.
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui
class MainWindow(QtGui.QMainWindow):
MaxRecentFiles = 5
windowList = []
def __init__(self):
super(MainWindow, self).__init__()
self.recentFileActs = []
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.textEdit = QtGui.QTextEdit()
self.setCentralWidget(self.textEdit)
self.createActions()
self.createMenus()
self.statusBar()
self.setWindowTitle("Recent Files")
self.resize(400, 300)
def newFile(self):
other = MainWindow()
MainWindow.windowList.append(other)
other.show()
def open(self):
fileName = QtGui.QFileDialog.getOpenFileName(self)
if fileName:
self.loadFile(fileName)
def save(self):
if self.curFile:
self.saveFile(self.curFile)
else:
self.saveAs()
def saveAs(self):
fileName = QtGui.QFileDialog.getSaveFileName(self)
if fileName:
self.saveFile(fileName)
def openRecentFile(self):
action = self.sender()
if action:
self.loadFile(action.data())
def about(self):
QtGui.QMessageBox.about(self, "About Recent Files",
"The <b>Recent Files</b> example demonstrates how to provide "
"a recently used file menu in a Qt application.")
def createActions(self):
self.newAct = QtGui.QAction("&New", self,
shortcut=QtGui.QKeySequence.New,
statusTip="Create a new file", triggered=self.newFile)
self.openAct = QtGui.QAction("&Open...", self,
shortcut=QtGui.QKeySequence.Open,
statusTip="Open an existing file", triggered=self.open)
self.saveAct = QtGui.QAction("&Save", self,
shortcut=QtGui.QKeySequence.Save,
statusTip="Save the document to disk", triggered=self.save)
self.saveAsAct = QtGui.QAction("Save &As...", self,
shortcut=QtGui.QKeySequence.SaveAs,
statusTip="Save the document under a new name",
triggered=self.saveAs)
for i in range(MainWindow.MaxRecentFiles):
self.recentFileActs.append(
QtGui.QAction(self, visible=False,
triggered=self.openRecentFile))
self.exitAct = QtGui.QAction("E&xit", self, shortcut="Ctrl+Q",
statusTip="Exit the application",
triggered=QtGui.qApp.closeAllWindows)
self.aboutAct = QtGui.QAction("&About", self,
statusTip="Show the application's About box",
triggered=self.about)
self.aboutQtAct = QtGui.QAction("About &Qt", self,
statusTip="Show the Qt library's About box",
triggered=QtGui.qApp.aboutQt)
def createMenus(self):
self.fileMenu = self.menuBar().addMenu("&File")
self.fileMenu.addAction(self.newAct)
self.fileMenu.addAction(self.openAct)
self.fileMenu.addAction(self.saveAct)
self.fileMenu.addAction(self.saveAsAct)
self.separatorAct = self.fileMenu.addSeparator()
for i in range(MainWindow.MaxRecentFiles):
self.fileMenu.addAction(self.recentFileActs[i])
self.fileMenu.addSeparator()
self.fileMenu.addAction(self.exitAct)
self.updateRecentFileActions()
self.menuBar().addSeparator()
self.helpMenu = self.menuBar().addMenu("&Help")
self.helpMenu.addAction(self.aboutAct)
self.helpMenu.addAction(self.aboutQtAct)
def loadFile(self, fileName):
file = QtCore.QFile(fileName)
if not file.open( QtCore.QFile.ReadOnly | QtCore.QFile.Text):
QtGui.QMessageBox.warning(self, "Recent Files",
"Cannot read file %s:\n%s." % (fileName, file.errorString()))
return
instr = QtCore.QTextStream(file)
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
self.textEdit.setPlainText(instr.readAll())
QtGui.QApplication.restoreOverrideCursor()
self.setCurrentFile(fileName)
self.statusBar().showMessage("File loaded", 2000)
def saveFile(self, fileName):
file = QtCore.QFile(fileName)
if not file.open( QtCore.QFile.WriteOnly | QtCore.QFile.Text):
QtGui.QMessageBox.warning(self, "Recent Files",
"Cannot write file %s:\n%s." % (fileName, file.errorString()))
return
outstr = QtCore.QTextStream(file)
QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
outstr << self.textEdit.toPlainText()
QtGui.QApplication.restoreOverrideCursor()
self.setCurrentFile(fileName)
self.statusBar().showMessage("File saved", 2000)
def setCurrentFile(self, fileName):
self.curFile = fileName
if self.curFile:
self.setWindowTitle("%s - Recent Files" % self.strippedName(self.curFile))
else:
self.setWindowTitle("Recent Files")
settings = QtCore.QSettings('Trolltech', 'Recent Files Example')
files = settings.value('recentFileList')
try:
files.remove(fileName)
except ValueError:
pass
files.insert(0, fileName)
del files[MainWindow.MaxRecentFiles:]
settings.setValue('recentFileList', files)
for widget in QtGui.QApplication.topLevelWidgets():
if isinstance(widget, MainWindow):
widget.updateRecentFileActions()
def updateRecentFileActions(self):
settings = QtCore.QSettings('Trolltech', 'Recent Files Example')
files = settings.value('recentFileList')
numRecentFiles = min(len(files), MainWindow.MaxRecentFiles)
for i in range(numRecentFiles):
text = "&%d %s" % (i + 1, self.strippedName(files[i]))
self.recentFileActs[i].setText(text)
self.recentFileActs[i].setData(files[i])
self.recentFileActs[i].setVisible(True)
for j in range(numRecentFiles, MainWindow.MaxRecentFiles):
self.recentFileActs[j].setVisible(False)
self.separatorAct.setVisible((numRecentFiles > 0))
def strippedName(self, fullFileName):
return QtCore.QFileInfo(fullFileName).fileName()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit(app.exec_())
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
421,
199,
31635,
199,
309,
199,
309,
1898,
334,
35,
9,
7129,
820,
4380,
9860,
27799,
23954,
14,
199,
309,
1898,
334,
35,
9,
7129,
653,
745,
4674,
11098,
436,
15,
269,
2399,
1007,
338,
328,
695,
2801,
1500,
680,
199,
309,
2900,
4481,
4644,
14,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
314,
7251,
402,
14084,
14,
199,
309,
199,
309,
2672,
19229,
63,
15947,
63,
3961,
26,
15400,
4,
199,
309,
2047,
1443,
675,
642,
570,
1334,
314,
2895,
402,
314,
6289,
4190,
465,
11924,
26,
199,
309,
199,
309,
298,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
309,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
309,
7647,
26,
199,
309,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
309,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
309,
258,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
309,
258,
4084,
14,
199,
309,
257,
627,
11443,
314,
536,
402,
653,
745,
4674,
11098,
436,
2399,
4804,
338,
328,
695,
2801,
1500,
9,
6590,
199,
309,
258,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
309,
258,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
309,
258,
4983,
14,
199,
309,
199,
309,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
309,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
309,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
309,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
309,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
309,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
309,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
309,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
309,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
2122,
199,
309,
2672,
19229,
63,
3902,
63,
3961,
4,
199,
309,
199,
31635,
421,
199,
3,
5723,
787,
1454,
4346,
367,
2018,
373,
18,
1325,
787,
394,
5362,
2003,
367,
2018,
373,
19,
14,
199,
646,
25342,
199,
17839,
14,
409,
1246,
360,
49,
1558,
297,
499,
9,
199,
17839,
14,
409,
1246,
360,
49,
12935,
297,
499,
9,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
421,
199,
533,
11298,
4301,
8,
10604,
14,
49,
16031,
304,
272,
8228,
29574,
5535,
275,
959,
272,
4353,
1296,
275,
942,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
16031,
12,
291,
2843,
826,
4533,
398,
291,
14,
14951,
1173,
33,
3021,
275,
942,
398,
291,
14,
17618,
8,
10901,
14,
4238,
14,
9004,
63,
5392,
3314,
4724,
9,
398,
291,
14,
505,
4685,
275,
5928,
14,
49,
1872,
4685,
342,
267,
291,
14,
409,
25290,
3339,
8,
277,
14,
505,
4685,
9,
398,
291,
14,
981,
9303,
342,
267,
291,
14,
981,
29230,
527,
342,
267,
291,
14,
1205,
5281,
342,
398,
291,
14,
30601,
480,
29574,
16920,
531,
267,
291,
14,
8709,
8,
5303,
12,
9601,
9,
339,
347,
892,
1173,
8,
277,
304,
267,
1163,
275,
11298,
4301,
342,
267,
11298,
4301,
14,
3806,
1296,
14,
740,
8,
1848,
9,
267,
1163,
14,
2384,
342,
339,
347,
1551,
8,
277,
304,
267,
18305,
275,
5928,
14,
49,
25213,
14,
362,
4299,
7733,
8,
277,
9,
267,
340,
18305,
26,
288,
291,
14,
912,
1173,
8,
15450,
9,
268,
198,
272,
347,
3354,
8,
277,
304,
267,
340,
291,
14,
895,
1173,
26,
288,
291,
14,
2117,
1173,
8,
277,
14,
895,
1173,
9,
267,
587,
26,
288,
291,
14,
2117,
2822,
342,
339,
347,
3354,
2822,
8,
277,
304,
267,
18305,
275,
5928,
14,
49,
25213,
14,
362,
8229,
7733,
8,
277,
9,
267,
340,
18305,
26,
288,
291,
14,
2117,
1173,
8,
15450,
9,
339,
347,
1551,
29574,
1173,
8,
277,
304,
267,
1595,
275,
291,
14,
8114,
342,
267,
340,
1595,
26,
288,
291,
14,
912,
1173,
8,
1287,
14,
576,
1012,
339,
347,
3595,
8,
277,
304,
267,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
18816,
799,
2946,
16920,
401,
355,
298,
1918,
665,
66,
30,
29574,
16920,
1108,
66,
30,
2893,
23789,
31216,
4212,
370,
5647,
298,
355,
298,
65,
23568,
1202,
570,
6269,
315,
282,
3959,
4223,
2685,
339,
347,
1218,
9303,
8,
277,
304,
267,
291,
14,
1222,
19348,
275,
5928,
14,
49,
3310,
22077,
4665,
401,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
4665,
12,
355,
2004,
15915,
628,
2499,
282,
892,
570,
401,
15572,
29,
277,
14,
1222,
1173,
9,
398,
291,
14,
1490,
19348,
275,
5928,
14,
49,
3310,
22077,
4299,
23966,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
4299,
12,
355,
2004,
15915,
628,
4299,
376,
3411,
570,
401,
15572,
29,
277,
14,
1490,
9,
398,
291,
14,
2117,
19348,
275,
5928,
14,
49,
3310,
22077,
8229,
401,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
8229,
12,
355,
2004,
15915,
628,
8229,
314,
2213,
370,
4543,
401,
15572,
29,
277,
14,
2117,
9,
398,
291,
14,
2117,
2822,
19348,
275,
5928,
14,
49,
3310,
480,
8229,
1253,
2822,
23966,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
8229,
2822,
12,
355,
2004,
15915,
628,
8229,
314,
2213,
1334,
282,
892,
536,
401,
355,
15572,
29,
277,
14,
2117,
2822,
9,
398,
367,
284,
315,
1425,
8,
16031,
14,
4261,
29574,
5535,
304,
288,
291,
14,
14951,
1173,
33,
3021,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
421,
199,
31635,
199,
309,
199,
309,
1898,
334,
35,
9,
7129,
820,
4380,
9860,
27799,
23954,
14,
199,
309,
1898,
334,
35,
9,
7129,
653,
745,
4674,
11098,
436,
15,
269,
2399,
1007,
338,
328,
695,
2801,
1500,
680,
199,
309,
2900,
4481,
4644,
14,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
314,
7251,
402,
14084,
14,
199,
309,
199,
309,
2672,
19229,
63,
15947,
63,
3961,
26,
15400,
4,
199,
309,
2047,
1443,
675,
642,
570,
1334,
314,
2895,
402,
314,
6289,
4190,
465,
11924,
26,
199,
309,
199,
309,
298,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
309,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
309,
7647,
26,
199,
309,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
309,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
309,
258,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
309,
258,
4084,
14,
199,
309,
257,
627,
11443,
314,
536,
402,
653,
745,
4674,
11098,
436,
2399,
4804,
338,
328,
695,
2801,
1500,
9,
6590,
199,
309,
258,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
309,
258,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
309,
258,
4983,
14,
199,
309,
199,
309,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
309,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
309,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
309,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
309,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
309,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
309,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
309,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
309,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
2122,
199,
309,
2672,
19229,
63,
3902,
63,
3961,
4,
199,
309,
199,
31635,
421,
199,
3,
5723,
787,
1454,
4346,
367,
2018,
373,
18,
1325,
787,
394,
5362,
2003,
367,
2018,
373,
19,
14,
199,
646,
25342,
199,
17839,
14,
409,
1246,
360,
49,
1558,
297,
499,
9,
199,
17839,
14,
409,
1246,
360,
49,
12935,
297,
499,
9,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
421,
199,
533,
11298,
4301,
8,
10604,
14,
49,
16031,
304,
272,
8228,
29574,
5535,
275,
959,
272,
4353,
1296,
275,
942,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
16031,
12,
291,
2843,
826,
4533,
398,
291,
14,
14951,
1173,
33,
3021,
275,
942,
398,
291,
14,
17618,
8,
10901,
14,
4238,
14,
9004,
63,
5392,
3314,
4724,
9,
398,
291,
14,
505,
4685,
275,
5928,
14,
49,
1872,
4685,
342,
267,
291,
14,
409,
25290,
3339,
8,
277,
14,
505,
4685,
9,
398,
291,
14,
981,
9303,
342,
267,
291,
14,
981,
29230,
527,
342,
267,
291,
14,
1205,
5281,
342,
398,
291,
14,
30601,
480,
29574,
16920,
531,
267,
291,
14,
8709,
8,
5303,
12,
9601,
9,
339,
347,
892,
1173,
8,
277,
304,
267,
1163,
275,
11298,
4301,
342,
267,
11298,
4301,
14,
3806,
1296,
14,
740,
8,
1848,
9,
267,
1163,
14,
2384,
342,
339,
347,
1551,
8,
277,
304,
267,
18305,
275,
5928,
14,
49,
25213,
14,
362,
4299,
7733,
8,
277,
9,
267,
340,
18305,
26,
288,
291,
14,
912,
1173,
8,
15450,
9,
268,
198,
272,
347,
3354,
8,
277,
304,
267,
340,
291,
14,
895,
1173,
26,
288,
291,
14,
2117,
1173,
8,
277,
14,
895,
1173,
9,
267,
587,
26,
288,
291,
14,
2117,
2822,
342,
339,
347,
3354,
2822,
8,
277,
304,
267,
18305,
275,
5928,
14,
49,
25213,
14,
362,
8229,
7733,
8,
277,
9,
267,
340,
18305,
26,
288,
291,
14,
2117,
1173,
8,
15450,
9,
339,
347,
1551,
29574,
1173,
8,
277,
304,
267,
1595,
275,
291,
14,
8114,
342,
267,
340,
1595,
26,
288,
291,
14,
912,
1173,
8,
1287,
14,
576,
1012,
339,
347,
3595,
8,
277,
304,
267,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
18816,
799,
2946,
16920,
401,
355,
298,
1918,
665,
66,
30,
29574,
16920,
1108,
66,
30,
2893,
23789,
31216,
4212,
370,
5647,
298,
355,
298,
65,
23568,
1202,
570,
6269,
315,
282,
3959,
4223,
2685,
339,
347,
1218,
9303,
8,
277,
304,
267,
291,
14,
1222,
19348,
275,
5928,
14,
49,
3310,
22077,
4665,
401,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
4665,
12,
355,
2004,
15915,
628,
2499,
282,
892,
570,
401,
15572,
29,
277,
14,
1222,
1173,
9,
398,
291,
14,
1490,
19348,
275,
5928,
14,
49,
3310,
22077,
4299,
23966,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
4299,
12,
355,
2004,
15915,
628,
4299,
376,
3411,
570,
401,
15572,
29,
277,
14,
1490,
9,
398,
291,
14,
2117,
19348,
275,
5928,
14,
49,
3310,
22077,
8229,
401,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
8229,
12,
355,
2004,
15915,
628,
8229,
314,
2213,
370,
4543,
401,
15572,
29,
277,
14,
2117,
9,
398,
291,
14,
2117,
2822,
19348,
275,
5928,
14,
49,
3310,
480,
8229,
1253,
2822,
23966,
291,
12,
355,
17522,
29,
10604,
14,
49,
1197,
5826,
14,
8229,
2822,
12,
355,
2004,
15915,
628,
8229,
314,
2213,
1334,
282,
892,
536,
401,
355,
15572,
29,
277,
14,
2117,
2822,
9,
398,
367,
284,
315,
1425,
8,
16031,
14,
4261,
29574,
5535,
304,
288,
291,
14,
14951,
1173,
33,
3021,
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,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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
] |
zanderle/django
|
tests/aggregation/tests.py
|
108
|
45704
|
from __future__ import unicode_literals
import datetime
import re
from decimal import Decimal
from django.core.exceptions import FieldError
from django.db import connection
from django.db.models import (
F, Aggregate, Avg, Count, DecimalField, DurationField, FloatField, Func,
IntegerField, Max, Min, Sum, Value,
)
from django.test import TestCase, ignore_warnings
from django.test.utils import Approximate, CaptureQueriesContext
from django.utils import six, timezone
from django.utils.deprecation import RemovedInDjango110Warning
from .models import Author, Book, Publisher, Store
class AggregateTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.a1 = Author.objects.create(name='Adrian Holovaty', age=34)
cls.a2 = Author.objects.create(name='Jacob Kaplan-Moss', age=35)
cls.a3 = Author.objects.create(name='Brad Dayley', age=45)
cls.a4 = Author.objects.create(name='James Bennett', age=29)
cls.a5 = Author.objects.create(name='Jeffrey Forcier', age=37)
cls.a6 = Author.objects.create(name='Paul Bissex', age=29)
cls.a7 = Author.objects.create(name='Wesley J. Chun', age=25)
cls.a8 = Author.objects.create(name='Peter Norvig', age=57)
cls.a9 = Author.objects.create(name='Stuart Russell', age=46)
cls.a1.friends.add(cls.a2, cls.a4)
cls.a2.friends.add(cls.a1, cls.a7)
cls.a4.friends.add(cls.a1)
cls.a5.friends.add(cls.a6, cls.a7)
cls.a6.friends.add(cls.a5, cls.a7)
cls.a7.friends.add(cls.a2, cls.a5, cls.a6)
cls.a8.friends.add(cls.a9)
cls.a9.friends.add(cls.a8)
cls.p1 = Publisher.objects.create(name='Apress', num_awards=3, duration=datetime.timedelta(days=1))
cls.p2 = Publisher.objects.create(name='Sams', num_awards=1, duration=datetime.timedelta(days=2))
cls.p3 = Publisher.objects.create(name='Prentice Hall', num_awards=7)
cls.p4 = Publisher.objects.create(name='Morgan Kaufmann', num_awards=9)
cls.p5 = Publisher.objects.create(name="Jonno's House of Books", num_awards=0)
cls.b1 = Book.objects.create(
isbn='159059725', name='The Definitive Guide to Django: Web Development Done Right',
pages=447, rating=4.5, price=Decimal('30.00'), contact=cls.a1, publisher=cls.p1,
pubdate=datetime.date(2007, 12, 6)
)
cls.b2 = Book.objects.create(
isbn='067232959', name='Sams Teach Yourself Django in 24 Hours',
pages=528, rating=3.0, price=Decimal('23.09'), contact=cls.a3, publisher=cls.p2,
pubdate=datetime.date(2008, 3, 3)
)
cls.b3 = Book.objects.create(
isbn='159059996', name='Practical Django Projects',
pages=300, rating=4.0, price=Decimal('29.69'), contact=cls.a4, publisher=cls.p1,
pubdate=datetime.date(2008, 6, 23)
)
cls.b4 = Book.objects.create(
isbn='013235613', name='Python Web Development with Django',
pages=350, rating=4.0, price=Decimal('29.69'), contact=cls.a5, publisher=cls.p3,
pubdate=datetime.date(2008, 11, 3)
)
cls.b5 = Book.objects.create(
isbn='013790395', name='Artificial Intelligence: A Modern Approach',
pages=1132, rating=4.0, price=Decimal('82.80'), contact=cls.a8, publisher=cls.p3,
pubdate=datetime.date(1995, 1, 15)
)
cls.b6 = Book.objects.create(
isbn='155860191', name='Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp',
pages=946, rating=5.0, price=Decimal('75.00'), contact=cls.a8, publisher=cls.p4,
pubdate=datetime.date(1991, 10, 15)
)
cls.b1.authors.add(cls.a1, cls.a2)
cls.b2.authors.add(cls.a3)
cls.b3.authors.add(cls.a4)
cls.b4.authors.add(cls.a5, cls.a6, cls.a7)
cls.b5.authors.add(cls.a8, cls.a9)
cls.b6.authors.add(cls.a8)
s1 = Store.objects.create(
name='Amazon.com',
original_opening=datetime.datetime(1994, 4, 23, 9, 17, 42),
friday_night_closing=datetime.time(23, 59, 59)
)
s2 = Store.objects.create(
name='Books.com',
original_opening=datetime.datetime(2001, 3, 15, 11, 23, 37),
friday_night_closing=datetime.time(23, 59, 59)
)
s3 = Store.objects.create(
name="Mamma and Pappa's Books",
original_opening=datetime.datetime(1945, 4, 25, 16, 24, 14),
friday_night_closing=datetime.time(21, 30)
)
s1.books.add(cls.b1, cls.b2, cls.b3, cls.b4, cls.b5, cls.b6)
s2.books.add(cls.b1, cls.b3, cls.b5, cls.b6)
s3.books.add(cls.b3, cls.b4, cls.b6)
def test_empty_aggregate(self):
self.assertEqual(Author.objects.all().aggregate(), {})
def test_aggregate_in_order_by(self):
msg = (
'Using an aggregate in order_by() without also including it in '
'annotate() is not allowed: Avg(F(book__rating)'
)
with self.assertRaisesMessage(FieldError, msg):
Author.objects.values('age').order_by(Avg('book__rating'))
def test_single_aggregate(self):
vals = Author.objects.aggregate(Avg("age"))
self.assertEqual(vals, {"age__avg": Approximate(37.4, places=1)})
def test_multiple_aggregates(self):
vals = Author.objects.aggregate(Sum("age"), Avg("age"))
self.assertEqual(vals, {"age__sum": 337, "age__avg": Approximate(37.4, places=1)})
def test_filter_aggregate(self):
vals = Author.objects.filter(age__gt=29).aggregate(Sum("age"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["age__sum"], 254)
def test_related_aggregate(self):
vals = Author.objects.aggregate(Avg("friends__age"))
self.assertEqual(len(vals), 1)
self.assertAlmostEqual(vals["friends__age__avg"], 34.07, places=2)
vals = Book.objects.filter(rating__lt=4.5).aggregate(Avg("authors__age"))
self.assertEqual(len(vals), 1)
self.assertAlmostEqual(vals["authors__age__avg"], 38.2857, places=2)
vals = Author.objects.all().filter(name__contains="a").aggregate(Avg("book__rating"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["book__rating__avg"], 4.0)
vals = Book.objects.aggregate(Sum("publisher__num_awards"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["publisher__num_awards__sum"], 30)
vals = Publisher.objects.aggregate(Sum("book__price"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["book__price__sum"], Decimal("270.27"))
def test_aggregate_multi_join(self):
vals = Store.objects.aggregate(Max("books__authors__age"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["books__authors__age__max"], 57)
vals = Author.objects.aggregate(Min("book__publisher__num_awards"))
self.assertEqual(len(vals), 1)
self.assertEqual(vals["book__publisher__num_awards__min"], 1)
def test_aggregate_alias(self):
vals = Store.objects.filter(name="Amazon.com").aggregate(amazon_mean=Avg("books__rating"))
self.assertEqual(len(vals), 1)
self.assertAlmostEqual(vals["amazon_mean"], 4.08, places=2)
def test_annotate_basic(self):
self.assertQuerysetEqual(
Book.objects.annotate().order_by('pk'), [
"The Definitive Guide to Django: Web Development Done Right",
"Sams Teach Yourself Django in 24 Hours",
"Practical Django Projects",
"Python Web Development with Django",
"Artificial Intelligence: A Modern Approach",
"Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp"
],
lambda b: b.name
)
books = Book.objects.annotate(mean_age=Avg("authors__age"))
b = books.get(pk=self.b1.pk)
self.assertEqual(
b.name,
'The Definitive Guide to Django: Web Development Done Right'
)
self.assertEqual(b.mean_age, 34.5)
def test_annotate_defer(self):
qs = Book.objects.annotate(
page_sum=Sum("pages")).defer('name').filter(pk=self.b1.pk)
rows = [
(1, "159059725", 447, "The Definitive Guide to Django: Web Development Done Right")
]
self.assertQuerysetEqual(
qs.order_by('pk'), rows,
lambda r: (r.id, r.isbn, r.page_sum, r.name)
)
def test_annotate_defer_select_related(self):
qs = Book.objects.select_related('contact').annotate(
page_sum=Sum("pages")).defer('name').filter(pk=self.b1.pk)
rows = [
(1, "159059725", 447, "Adrian Holovaty",
"The Definitive Guide to Django: Web Development Done Right")
]
self.assertQuerysetEqual(
qs.order_by('pk'), rows,
lambda r: (r.id, r.isbn, r.page_sum, r.contact.name, r.name)
)
def test_annotate_m2m(self):
books = Book.objects.filter(rating__lt=4.5).annotate(Avg("authors__age")).order_by("name")
self.assertQuerysetEqual(
books, [
('Artificial Intelligence: A Modern Approach', 51.5),
('Practical Django Projects', 29.0),
('Python Web Development with Django', Approximate(30.3, places=1)),
('Sams Teach Yourself Django in 24 Hours', 45.0)
],
lambda b: (b.name, b.authors__age__avg),
)
books = Book.objects.annotate(num_authors=Count("authors")).order_by("name")
self.assertQuerysetEqual(
books, [
('Artificial Intelligence: A Modern Approach', 2),
('Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp', 1),
('Practical Django Projects', 1),
('Python Web Development with Django', 3),
('Sams Teach Yourself Django in 24 Hours', 1),
('The Definitive Guide to Django: Web Development Done Right', 2)
],
lambda b: (b.name, b.num_authors)
)
def test_backwards_m2m_annotate(self):
authors = Author.objects.filter(name__contains="a").annotate(Avg("book__rating")).order_by("name")
self.assertQuerysetEqual(
authors, [
('Adrian Holovaty', 4.5),
('Brad Dayley', 3.0),
('Jacob Kaplan-Moss', 4.5),
('James Bennett', 4.0),
('Paul Bissex', 4.0),
('Stuart Russell', 4.0)
],
lambda a: (a.name, a.book__rating__avg)
)
authors = Author.objects.annotate(num_books=Count("book")).order_by("name")
self.assertQuerysetEqual(
authors, [
('Adrian Holovaty', 1),
('Brad Dayley', 1),
('Jacob Kaplan-Moss', 1),
('James Bennett', 1),
('Jeffrey Forcier', 1),
('Paul Bissex', 1),
('Peter Norvig', 2),
('Stuart Russell', 1),
('Wesley J. Chun', 1)
],
lambda a: (a.name, a.num_books)
)
def test_reverse_fkey_annotate(self):
books = Book.objects.annotate(Sum("publisher__num_awards")).order_by("name")
self.assertQuerysetEqual(
books, [
('Artificial Intelligence: A Modern Approach', 7),
('Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp', 9),
('Practical Django Projects', 3),
('Python Web Development with Django', 7),
('Sams Teach Yourself Django in 24 Hours', 1),
('The Definitive Guide to Django: Web Development Done Right', 3)
],
lambda b: (b.name, b.publisher__num_awards__sum)
)
publishers = Publisher.objects.annotate(Sum("book__price")).order_by("name")
self.assertQuerysetEqual(
publishers, [
('Apress', Decimal("59.69")),
("Jonno's House of Books", None),
('Morgan Kaufmann', Decimal("75.00")),
('Prentice Hall', Decimal("112.49")),
('Sams', Decimal("23.09"))
],
lambda p: (p.name, p.book__price__sum)
)
def test_annotate_values(self):
books = list(Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg("authors__age")).values())
self.assertEqual(
books, [
{
"contact_id": 1,
"id": 1,
"isbn": "159059725",
"mean_age": 34.5,
"name": "The Definitive Guide to Django: Web Development Done Right",
"pages": 447,
"price": Approximate(Decimal("30")),
"pubdate": datetime.date(2007, 12, 6),
"publisher_id": 1,
"rating": 4.5,
}
]
)
books = Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg('authors__age')).values('pk', 'isbn', 'mean_age')
self.assertEqual(
list(books), [
{
"pk": 1,
"isbn": "159059725",
"mean_age": 34.5,
}
]
)
books = Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg("authors__age")).values("name")
self.assertEqual(
list(books), [
{
"name": "The Definitive Guide to Django: Web Development Done Right"
}
]
)
books = Book.objects.filter(pk=self.b1.pk).values().annotate(mean_age=Avg('authors__age'))
self.assertEqual(
list(books), [
{
"contact_id": 1,
"id": 1,
"isbn": "159059725",
"mean_age": 34.5,
"name": "The Definitive Guide to Django: Web Development Done Right",
"pages": 447,
"price": Approximate(Decimal("30")),
"pubdate": datetime.date(2007, 12, 6),
"publisher_id": 1,
"rating": 4.5,
}
]
)
books = Book.objects.values("rating").annotate(n_authors=Count("authors__id"), mean_age=Avg("authors__age")).order_by("rating")
self.assertEqual(
list(books), [
{
"rating": 3.0,
"n_authors": 1,
"mean_age": 45.0,
},
{
"rating": 4.0,
"n_authors": 6,
"mean_age": Approximate(37.16, places=1)
},
{
"rating": 4.5,
"n_authors": 2,
"mean_age": 34.5,
},
{
"rating": 5.0,
"n_authors": 1,
"mean_age": 57.0,
}
]
)
authors = Author.objects.annotate(Avg("friends__age")).order_by("name")
self.assertEqual(len(authors), 9)
self.assertQuerysetEqual(
authors, [
('Adrian Holovaty', 32.0),
('Brad Dayley', None),
('Jacob Kaplan-Moss', 29.5),
('James Bennett', 34.0),
('Jeffrey Forcier', 27.0),
('Paul Bissex', 31.0),
('Peter Norvig', 46.0),
('Stuart Russell', 57.0),
('Wesley J. Chun', Approximate(33.66, places=1))
],
lambda a: (a.name, a.friends__age__avg)
)
def test_count(self):
vals = Book.objects.aggregate(Count("rating"))
self.assertEqual(vals, {"rating__count": 6})
vals = Book.objects.aggregate(Count("rating", distinct=True))
self.assertEqual(vals, {"rating__count": 4})
def test_non_grouped_annotation_not_in_group_by(self):
"""
An annotation not included in values() before an aggregate should be
excluded from the group by clause.
"""
qs = (
Book.objects.annotate(xprice=F('price')).filter(rating=4.0).values('rating')
.annotate(count=Count('publisher_id', distinct=True)).values('count', 'rating').order_by('count')
)
self.assertEqual(
list(qs), [
{'rating': 4.0, 'count': 2},
]
)
def test_grouped_annotation_in_group_by(self):
"""
An annotation included in values() before an aggregate should be
included in the group by clause.
"""
qs = (
Book.objects.annotate(xprice=F('price')).filter(rating=4.0).values('rating', 'xprice')
.annotate(count=Count('publisher_id', distinct=True)).values('count', 'rating').order_by('count')
)
self.assertEqual(
list(qs), [
{'rating': 4.0, 'count': 1},
{'rating': 4.0, 'count': 2},
]
)
def test_fkey_aggregate(self):
explicit = list(Author.objects.annotate(Count('book__id')))
implicit = list(Author.objects.annotate(Count('book')))
self.assertEqual(explicit, implicit)
def test_annotate_ordering(self):
books = Book.objects.values('rating').annotate(oldest=Max('authors__age')).order_by('oldest', 'rating')
self.assertEqual(
list(books), [
{
"rating": 4.5,
"oldest": 35,
},
{
"rating": 3.0,
"oldest": 45
},
{
"rating": 4.0,
"oldest": 57,
},
{
"rating": 5.0,
"oldest": 57,
}
]
)
books = Book.objects.values("rating").annotate(oldest=Max("authors__age")).order_by("-oldest", "-rating")
self.assertEqual(
list(books), [
{
"rating": 5.0,
"oldest": 57,
},
{
"rating": 4.0,
"oldest": 57,
},
{
"rating": 3.0,
"oldest": 45,
},
{
"rating": 4.5,
"oldest": 35,
}
]
)
def test_aggregate_annotation(self):
vals = Book.objects.annotate(num_authors=Count("authors__id")).aggregate(Avg("num_authors"))
self.assertEqual(vals, {"num_authors__avg": Approximate(1.66, places=1)})
def test_avg_duration_field(self):
self.assertEqual(
Publisher.objects.aggregate(Avg('duration', output_field=DurationField())),
{'duration__avg': datetime.timedelta(days=1, hours=12)}
)
def test_sum_duration_field(self):
self.assertEqual(
Publisher.objects.aggregate(Sum('duration', output_field=DurationField())),
{'duration__sum': datetime.timedelta(days=3)}
)
def test_sum_distinct_aggregate(self):
"""
Sum on a distict() QuerySet should aggregate only the distinct items.
"""
authors = Author.objects.filter(book__in=[5, 6])
self.assertEqual(authors.count(), 3)
distinct_authors = authors.distinct()
self.assertEqual(distinct_authors.count(), 2)
# Selected author ages are 57 and 46
age_sum = distinct_authors.aggregate(Sum('age'))
self.assertEqual(age_sum['age__sum'], 103)
def test_filtering(self):
p = Publisher.objects.create(name='Expensive Publisher', num_awards=0)
Book.objects.create(
name='ExpensiveBook1',
pages=1,
isbn='111',
rating=3.5,
price=Decimal("1000"),
publisher=p,
contact_id=1,
pubdate=datetime.date(2008, 12, 1)
)
Book.objects.create(
name='ExpensiveBook2',
pages=1,
isbn='222',
rating=4.0,
price=Decimal("1000"),
publisher=p,
contact_id=1,
pubdate=datetime.date(2008, 12, 2)
)
Book.objects.create(
name='ExpensiveBook3',
pages=1,
isbn='333',
rating=4.5,
price=Decimal("35"),
publisher=p,
contact_id=1,
pubdate=datetime.date(2008, 12, 3)
)
publishers = Publisher.objects.annotate(num_books=Count("book__id")).filter(num_books__gt=1).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
"Prentice Hall",
"Expensive Publisher",
],
lambda p: p.name,
)
publishers = Publisher.objects.filter(book__price__lt=Decimal("40.0")).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
"Apress",
"Sams",
"Prentice Hall",
"Expensive Publisher",
],
lambda p: p.name
)
publishers = Publisher.objects.annotate(num_books=Count("book__id")).filter(num_books__gt=1, book__price__lt=Decimal("40.0")).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
"Prentice Hall",
"Expensive Publisher",
],
lambda p: p.name,
)
publishers = Publisher.objects.filter(book__price__lt=Decimal("40.0")).annotate(num_books=Count("book__id")).filter(num_books__gt=1).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
],
lambda p: p.name
)
publishers = Publisher.objects.annotate(num_books=Count("book")).filter(num_books__range=[1, 3]).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
"Sams",
"Prentice Hall",
"Morgan Kaufmann",
"Expensive Publisher",
],
lambda p: p.name
)
publishers = Publisher.objects.annotate(num_books=Count("book")).filter(num_books__range=[1, 2]).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
"Sams",
"Prentice Hall",
"Morgan Kaufmann",
],
lambda p: p.name
)
publishers = Publisher.objects.annotate(num_books=Count("book")).filter(num_books__in=[1, 3]).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Sams",
"Morgan Kaufmann",
"Expensive Publisher",
],
lambda p: p.name,
)
publishers = Publisher.objects.annotate(num_books=Count("book")).filter(num_books__isnull=True)
self.assertEqual(len(publishers), 0)
def test_annotation(self):
vals = Author.objects.filter(pk=self.a1.pk).aggregate(Count("friends__id"))
self.assertEqual(vals, {"friends__id__count": 2})
books = Book.objects.annotate(num_authors=Count("authors__name")).filter(num_authors__exact=2).order_by("pk")
self.assertQuerysetEqual(
books, [
"The Definitive Guide to Django: Web Development Done Right",
"Artificial Intelligence: A Modern Approach",
],
lambda b: b.name
)
authors = Author.objects.annotate(num_friends=Count("friends__id", distinct=True)).filter(num_friends=0).order_by("pk")
self.assertQuerysetEqual(
authors, [
"Brad Dayley",
],
lambda a: a.name
)
publishers = Publisher.objects.annotate(num_books=Count("book__id")).filter(num_books__gt=1).order_by("pk")
self.assertQuerysetEqual(
publishers, [
"Apress",
"Prentice Hall",
],
lambda p: p.name
)
publishers = Publisher.objects.filter(book__price__lt=Decimal("40.0")).annotate(num_books=Count("book__id")).filter(num_books__gt=1)
self.assertQuerysetEqual(
publishers, [
"Apress",
],
lambda p: p.name
)
books = Book.objects.annotate(num_authors=Count("authors__id")).filter(authors__name__contains="Norvig", num_authors__gt=1)
self.assertQuerysetEqual(
books, [
"Artificial Intelligence: A Modern Approach",
],
lambda b: b.name
)
def test_more_aggregation(self):
a = Author.objects.get(name__contains='Norvig')
b = Book.objects.get(name__contains='Done Right')
b.authors.add(a)
b.save()
vals = Book.objects.annotate(num_authors=Count("authors__id")).filter(authors__name__contains="Norvig", num_authors__gt=1).aggregate(Avg("rating"))
self.assertEqual(vals, {"rating__avg": 4.25})
def test_even_more_aggregate(self):
publishers = Publisher.objects.annotate(
earliest_book=Min("book__pubdate"),
).exclude(earliest_book=None).order_by("earliest_book").values(
'earliest_book',
'num_awards',
'id',
'name',
)
self.assertEqual(
list(publishers), [
{
'earliest_book': datetime.date(1991, 10, 15),
'num_awards': 9,
'id': 4,
'name': 'Morgan Kaufmann'
},
{
'earliest_book': datetime.date(1995, 1, 15),
'num_awards': 7,
'id': 3,
'name': 'Prentice Hall'
},
{
'earliest_book': datetime.date(2007, 12, 6),
'num_awards': 3,
'id': 1,
'name': 'Apress'
},
{
'earliest_book': datetime.date(2008, 3, 3),
'num_awards': 1,
'id': 2,
'name': 'Sams'
}
]
)
vals = Store.objects.aggregate(Max("friday_night_closing"), Min("original_opening"))
self.assertEqual(
vals,
{
"friday_night_closing__max": datetime.time(23, 59, 59),
"original_opening__min": datetime.datetime(1945, 4, 25, 16, 24, 14),
}
)
def test_annotate_values_list(self):
books = Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg("authors__age")).values_list("pk", "isbn", "mean_age")
self.assertEqual(
list(books), [
(1, "159059725", 34.5),
]
)
books = Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg("authors__age")).values_list("isbn")
self.assertEqual(
list(books), [
('159059725',)
]
)
books = Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg("authors__age")).values_list("mean_age")
self.assertEqual(
list(books), [
(34.5,)
]
)
books = Book.objects.filter(pk=self.b1.pk).annotate(mean_age=Avg("authors__age")).values_list("mean_age", flat=True)
self.assertEqual(list(books), [34.5])
books = Book.objects.values_list("price").annotate(count=Count("price")).order_by("-count", "price")
self.assertEqual(
list(books), [
(Decimal("29.69"), 2),
(Decimal('23.09'), 1),
(Decimal('30'), 1),
(Decimal('75'), 1),
(Decimal('82.8'), 1),
]
)
def test_dates_with_aggregation(self):
"""
Test that .dates() returns a distinct set of dates when applied to a
QuerySet with aggregation.
Refs #18056. Previously, .dates() would return distinct (date_kind,
aggregation) sets, in this case (year, num_authors), so 2008 would be
returned twice because there are books from 2008 with a different
number of authors.
"""
dates = Book.objects.annotate(num_authors=Count("authors")).dates('pubdate', 'year')
self.assertQuerysetEqual(
dates, [
"datetime.date(1991, 1, 1)",
"datetime.date(1995, 1, 1)",
"datetime.date(2007, 1, 1)",
"datetime.date(2008, 1, 1)"
]
)
def test_values_aggregation(self):
# Refs #20782
max_rating = Book.objects.values('rating').aggregate(max_rating=Max('rating'))
self.assertEqual(max_rating['max_rating'], 5)
max_books_per_rating = Book.objects.values('rating').annotate(
books_per_rating=Count('id')
).aggregate(Max('books_per_rating'))
self.assertEqual(
max_books_per_rating,
{'books_per_rating__max': 3})
def test_ticket17424(self):
"""
Check that doing exclude() on a foreign model after annotate()
doesn't crash.
"""
all_books = list(Book.objects.values_list('pk', flat=True).order_by('pk'))
annotated_books = Book.objects.order_by('pk').annotate(one=Count("id"))
# The value doesn't matter, we just need any negative
# constraint on a related model that's a noop.
excluded_books = annotated_books.exclude(publisher__name="__UNLIKELY_VALUE__")
# Try to generate query tree
str(excluded_books.query)
self.assertQuerysetEqual(excluded_books, all_books, lambda x: x.pk)
# Check internal state
self.assertIsNone(annotated_books.query.alias_map["aggregation_book"].join_type)
self.assertIsNone(excluded_books.query.alias_map["aggregation_book"].join_type)
def test_ticket12886(self):
"""
Check that aggregation over sliced queryset works correctly.
"""
qs = Book.objects.all().order_by('-rating')[0:3]
vals = qs.aggregate(average_top3_rating=Avg('rating'))['average_top3_rating']
self.assertAlmostEqual(vals, 4.5, places=2)
def test_ticket11881(self):
"""
Check that subqueries do not needlessly contain ORDER BY, SELECT FOR UPDATE
or select_related() stuff.
"""
qs = Book.objects.all().select_for_update().order_by(
'pk').select_related('publisher').annotate(max_pk=Max('pk'))
with CaptureQueriesContext(connection) as captured_queries:
qs.aggregate(avg_pk=Avg('max_pk'))
self.assertEqual(len(captured_queries), 1)
qstr = captured_queries[0]['sql'].lower()
self.assertNotIn('for update', qstr)
forced_ordering = connection.ops.force_no_ordering()
if forced_ordering:
# If the backend needs to force an ordering we make sure it's
# the only "ORDER BY" clause present in the query.
self.assertEqual(
re.findall(r'order by (\w+)', qstr),
[', '.join(f[1][0] for f in forced_ordering).lower()]
)
else:
self.assertNotIn('order by', qstr)
self.assertEqual(qstr.count(' join '), 0)
def test_decimal_max_digits_has_no_effect(self):
Book.objects.all().delete()
a1 = Author.objects.first()
p1 = Publisher.objects.first()
thedate = timezone.now()
for i in range(10):
Book.objects.create(
isbn="abcde{}".format(i), name="none", pages=10, rating=4.0,
price=9999.98, contact=a1, publisher=p1, pubdate=thedate)
book = Book.objects.aggregate(price_sum=Sum('price'))
self.assertEqual(book['price_sum'], Decimal("99999.80"))
def test_nonaggregate_aggregation_throws(self):
with six.assertRaisesRegex(self, TypeError, 'fail is not an aggregate expression'):
Book.objects.aggregate(fail=F('price'))
def test_nonfield_annotation(self):
book = Book.objects.annotate(val=Max(Value(2, output_field=IntegerField()))).first()
self.assertEqual(book.val, 2)
book = Book.objects.annotate(val=Max(Value(2), output_field=IntegerField())).first()
self.assertEqual(book.val, 2)
book = Book.objects.annotate(val=Max(2, output_field=IntegerField())).first()
self.assertEqual(book.val, 2)
def test_missing_output_field_raises_error(self):
with six.assertRaisesRegex(self, FieldError, 'Cannot resolve expression type, unknown output_field'):
Book.objects.annotate(val=Max(2)).first()
def test_annotation_expressions(self):
authors = Author.objects.annotate(combined_ages=Sum(F('age') + F('friends__age'))).order_by('name')
authors2 = Author.objects.annotate(combined_ages=Sum('age') + Sum('friends__age')).order_by('name')
for qs in (authors, authors2):
self.assertEqual(len(qs), 9)
self.assertQuerysetEqual(
qs, [
('Adrian Holovaty', 132),
('Brad Dayley', None),
('Jacob Kaplan-Moss', 129),
('James Bennett', 63),
('Jeffrey Forcier', 128),
('Paul Bissex', 120),
('Peter Norvig', 103),
('Stuart Russell', 103),
('Wesley J. Chun', 176)
],
lambda a: (a.name, a.combined_ages)
)
def test_aggregation_expressions(self):
a1 = Author.objects.aggregate(av_age=Sum('age') / Count('*'))
a2 = Author.objects.aggregate(av_age=Sum('age') / Count('age'))
a3 = Author.objects.aggregate(av_age=Avg('age'))
self.assertEqual(a1, {'av_age': 37})
self.assertEqual(a2, {'av_age': 37})
self.assertEqual(a3, {'av_age': Approximate(37.4, places=1)})
def test_avg_decimal_field(self):
v = Book.objects.filter(rating=4).aggregate(avg_price=(Avg('price')))['avg_price']
self.assertIsInstance(v, float)
self.assertEqual(v, Approximate(47.39, places=2))
def test_order_of_precedence(self):
p1 = Book.objects.filter(rating=4).aggregate(avg_price=(Avg('price') + 2) * 3)
self.assertEqual(p1, {'avg_price': Approximate(148.18, places=2)})
p2 = Book.objects.filter(rating=4).aggregate(avg_price=Avg('price') + 2 * 3)
self.assertEqual(p2, {'avg_price': Approximate(53.39, places=2)})
def test_combine_different_types(self):
with six.assertRaisesRegex(self, FieldError, 'Expression contains mixed types. You must set output_field'):
Book.objects.annotate(sums=Sum('rating') + Sum('pages') + Sum('price')).get(pk=self.b4.pk)
b1 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'),
output_field=IntegerField())).get(pk=self.b4.pk)
self.assertEqual(b1.sums, 383)
b2 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'),
output_field=FloatField())).get(pk=self.b4.pk)
self.assertEqual(b2.sums, 383.69)
b3 = Book.objects.annotate(sums=Sum(F('rating') + F('pages') + F('price'),
output_field=DecimalField())).get(pk=self.b4.pk)
self.assertEqual(b3.sums, Approximate(Decimal("383.69"), places=2))
def test_complex_aggregations_require_kwarg(self):
with six.assertRaisesRegex(self, TypeError, 'Complex annotations require an alias'):
Author.objects.annotate(Sum(F('age') + F('friends__age')))
with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'):
Author.objects.aggregate(Sum('age') / Count('age'))
with six.assertRaisesRegex(self, TypeError, 'Complex aggregates require an alias'):
Author.objects.aggregate(Sum(1))
def test_aggregate_over_complex_annotation(self):
qs = Author.objects.annotate(
combined_ages=Sum(F('age') + F('friends__age')))
age = qs.aggregate(max_combined_age=Max('combined_ages'))
self.assertEqual(age['max_combined_age'], 176)
age = qs.aggregate(max_combined_age_doubled=Max('combined_ages') * 2)
self.assertEqual(age['max_combined_age_doubled'], 176 * 2)
age = qs.aggregate(
max_combined_age_doubled=Max('combined_ages') + Max('combined_ages'))
self.assertEqual(age['max_combined_age_doubled'], 176 * 2)
age = qs.aggregate(
max_combined_age_doubled=Max('combined_ages') + Max('combined_ages'),
sum_combined_age=Sum('combined_ages'))
self.assertEqual(age['max_combined_age_doubled'], 176 * 2)
self.assertEqual(age['sum_combined_age'], 954)
age = qs.aggregate(
max_combined_age_doubled=Max('combined_ages') + Max('combined_ages'),
sum_combined_age_doubled=Sum('combined_ages') + Sum('combined_ages'))
self.assertEqual(age['max_combined_age_doubled'], 176 * 2)
self.assertEqual(age['sum_combined_age_doubled'], 954 * 2)
def test_values_annotation_with_expression(self):
# ensure the F() is promoted to the group by clause
qs = Author.objects.values('name').annotate(another_age=Sum('age') + F('age'))
a = qs.get(name="Adrian Holovaty")
self.assertEqual(a['another_age'], 68)
qs = qs.annotate(friend_count=Count('friends'))
a = qs.get(name="Adrian Holovaty")
self.assertEqual(a['friend_count'], 2)
qs = qs.annotate(combined_age=Sum('age') + F('friends__age')).filter(
name="Adrian Holovaty").order_by('-combined_age')
self.assertEqual(
list(qs), [
{
"name": 'Adrian Holovaty',
"another_age": 68,
"friend_count": 1,
"combined_age": 69
},
{
"name": 'Adrian Holovaty',
"another_age": 68,
"friend_count": 1,
"combined_age": 63
}
]
)
vals = qs.values('name', 'combined_age')
self.assertEqual(
list(vals), [
{
"name": 'Adrian Holovaty',
"combined_age": 69
},
{
"name": 'Adrian Holovaty',
"combined_age": 63
}
]
)
def test_annotate_values_aggregate(self):
alias_age = Author.objects.annotate(
age_alias=F('age')
).values(
'age_alias',
).aggregate(sum_age=Sum('age_alias'))
age = Author.objects.values('age').aggregate(sum_age=Sum('age'))
self.assertEqual(alias_age['sum_age'], age['sum_age'])
def test_annotate_over_annotate(self):
author = Author.objects.annotate(
age_alias=F('age')
).annotate(
sum_age=Sum('age_alias')
).get(name="Adrian Holovaty")
other_author = Author.objects.annotate(
sum_age=Sum('age')
).get(name="Adrian Holovaty")
self.assertEqual(author.sum_age, other_author.sum_age)
def test_annotated_aggregate_over_annotated_aggregate(self):
with self.assertRaisesMessage(FieldError, "Cannot compute Sum('id__max'): 'id__max' is an aggregate"):
Book.objects.annotate(Max('id')).annotate(Sum('id__max'))
class MyMax(Max):
def as_sql(self, compiler, connection):
self.set_source_expressions(self.get_source_expressions()[0:1])
return super(MyMax, self).as_sql(compiler, connection)
with self.assertRaisesMessage(FieldError, "Cannot compute Max('id__max'): 'id__max' is an aggregate"):
Book.objects.annotate(Max('id')).annotate(my_max=MyMax('id__max', 'price'))
def test_multi_arg_aggregate(self):
class MyMax(Max):
def as_sql(self, compiler, connection):
self.set_source_expressions(self.get_source_expressions()[0:1])
return super(MyMax, self).as_sql(compiler, connection)
with self.assertRaisesMessage(TypeError, 'Complex aggregates require an alias'):
Book.objects.aggregate(MyMax('pages', 'price'))
with self.assertRaisesMessage(TypeError, 'Complex annotations require an alias'):
Book.objects.annotate(MyMax('pages', 'price'))
Book.objects.aggregate(max_field=MyMax('pages', 'price'))
def test_add_implementation(self):
class MySum(Sum):
pass
# test completely changing how the output is rendered
def lower_case_function_override(self, compiler, connection):
sql, params = compiler.compile(self.source_expressions[0])
substitutions = dict(function=self.function.lower(), expressions=sql)
substitutions.update(self.extra)
return self.template % substitutions, params
setattr(MySum, 'as_' + connection.vendor, lower_case_function_override)
qs = Book.objects.annotate(
sums=MySum(F('rating') + F('pages') + F('price'), output_field=IntegerField())
)
self.assertEqual(str(qs.query).count('sum('), 1)
b1 = qs.get(pk=self.b4.pk)
self.assertEqual(b1.sums, 383)
# test changing the dict and delegating
def lower_case_function_super(self, compiler, connection):
self.extra['function'] = self.function.lower()
return super(MySum, self).as_sql(compiler, connection)
setattr(MySum, 'as_' + connection.vendor, lower_case_function_super)
qs = Book.objects.annotate(
sums=MySum(F('rating') + F('pages') + F('price'), output_field=IntegerField())
)
self.assertEqual(str(qs.query).count('sum('), 1)
b1 = qs.get(pk=self.b4.pk)
self.assertEqual(b1.sums, 383)
# test overriding all parts of the template
def be_evil(self, compiler, connection):
substitutions = dict(function='MAX', expressions='2')
substitutions.update(self.extra)
return self.template % substitutions, ()
setattr(MySum, 'as_' + connection.vendor, be_evil)
qs = Book.objects.annotate(
sums=MySum(F('rating') + F('pages') + F('price'), output_field=IntegerField())
)
self.assertEqual(str(qs.query).count('MAX('), 1)
b1 = qs.get(pk=self.b4.pk)
self.assertEqual(b1.sums, 2)
def test_complex_values_aggregation(self):
max_rating = Book.objects.values('rating').aggregate(
double_max_rating=Max('rating') + Max('rating'))
self.assertEqual(max_rating['double_max_rating'], 5 * 2)
max_books_per_rating = Book.objects.values('rating').annotate(
books_per_rating=Count('id') + 5
).aggregate(Max('books_per_rating'))
self.assertEqual(
max_books_per_rating,
{'books_per_rating__max': 3 + 5})
def test_expression_on_aggregation(self):
# Create a plain expression
class Greatest(Func):
function = 'GREATEST'
def as_sqlite(self, compiler, connection):
return super(Greatest, self).as_sql(compiler, connection, function='MAX')
qs = Publisher.objects.annotate(
price_or_median=Greatest(Avg('book__rating'), Avg('book__price'))
).filter(price_or_median__gte=F('num_awards')).order_by('num_awards')
self.assertQuerysetEqual(
qs, [1, 3, 7, 9], lambda v: v.num_awards)
qs2 = Publisher.objects.annotate(
rating_or_num_awards=Greatest(Avg('book__rating'), F('num_awards'),
output_field=FloatField())
).filter(rating_or_num_awards__gt=F('num_awards')).order_by('num_awards')
self.assertQuerysetEqual(
qs2, [1, 3], lambda v: v.num_awards)
@ignore_warnings(category=RemovedInDjango110Warning)
def test_backwards_compatibility(self):
from django.db.models.sql import aggregates as sql_aggregates
class SqlNewSum(sql_aggregates.Aggregate):
sql_function = 'SUM'
class NewSum(Aggregate):
name = 'Sum'
def add_to_query(self, query, alias, col, source, is_summary):
klass = SqlNewSum
aggregate = klass(
col, source=source, is_summary=is_summary, **self.extra)
query.annotations[alias] = aggregate
qs = Author.objects.values('name').annotate(another_age=NewSum('age') + F('age'))
a = qs.get(name="Adrian Holovaty")
self.assertEqual(a['another_age'], 68)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
295,
199,
504,
6107,
492,
6345,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
992,
492,
334,
272,
481,
12,
29397,
12,
437,
10929,
12,
14826,
12,
6345,
792,
12,
31836,
792,
12,
11140,
792,
12,
28794,
12,
272,
26141,
12,
8228,
12,
10195,
12,
12094,
12,
1594,
12,
199,
9,
199,
504,
1639,
14,
396,
492,
7640,
12,
3686,
63,
5451,
199,
504,
1639,
14,
396,
14,
1208,
492,
13450,
8221,
6897,
12,
29828,
13611,
2998,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
199,
504,
1275,
992,
492,
6529,
12,
8944,
12,
19952,
281,
12,
13874,
421,
199,
533,
29397,
1746,
8,
1746,
304,
339,
768,
3744,
272,
347,
3613,
16550,
8,
1886,
304,
267,
843,
14,
65,
17,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
2767,
18429,
28673,
320,
16305,
89,
297,
11437,
29,
1082,
9,
267,
843,
14,
65,
18,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
13286,
66,
1804,
439,
1502,
13,
3716,
385,
297,
11437,
29,
1276,
9,
267,
843,
14,
65,
19,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
34,
9525,
28358,
15515,
297,
11437,
29,
2322,
9,
267,
843,
14,
65,
20,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
14015,
26844,
846,
84,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
21,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
3609,
17885,
2104,
559,
281,
297,
11437,
29,
1401,
9,
267,
843,
14,
65,
22,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
28282,
699,
374,
20160,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
23,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
55,
397,
15515,
1603,
14,
2799,
324,
297,
11437,
29,
821,
9,
267,
843,
14,
65,
24,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
8070,
351,
653,
269,
433,
71,
297,
11437,
29,
1641,
9,
267,
843,
14,
65,
25,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
933,
85,
580,
820,
527,
23235,
297,
11437,
29,
2466,
9,
267,
843,
14,
65,
17,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
20,
9,
267,
843,
14,
65,
18,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
20,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
9,
267,
843,
14,
65,
21,
14,
18024,
14,
525,
8,
1886,
14,
65,
22,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
22,
14,
18024,
14,
525,
8,
1886,
14,
65,
21,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
23,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
21,
12,
843,
14,
65,
22,
9,
267,
843,
14,
65,
24,
14,
18024,
14,
525,
8,
1886,
14,
65,
25,
9,
267,
843,
14,
65,
25,
14,
18024,
14,
525,
8,
1886,
14,
65,
24,
9,
398,
843,
14,
80,
17,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
33,
2915,
297,
1967,
63,
31255,
29,
19,
12,
7373,
29,
2083,
14,
7473,
8,
4899,
29,
17,
430,
267,
843,
14,
80,
18,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
51,
19470,
297,
1967,
63,
31255,
29,
17,
12,
7373,
29,
2083,
14,
7473,
8,
4899,
29,
18,
430,
267,
843,
14,
80,
19,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
48,
828,
3548,
869,
452,
297,
1967,
63,
31255,
29,
23,
9,
267,
843,
14,
80,
20,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
45,
19916,
1804,
65,
1286,
20059,
297,
1967,
63,
31255,
29,
25,
9,
267,
843,
14,
80,
21,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
628,
42,
265,
889,
1159,
869,
7130,
402,
8944,
83,
401,
1967,
63,
31255,
29,
16,
9,
398,
843,
14,
66,
17,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1046,
2710,
15459,
821,
297,
536,
534,
1918,
22659,
857,
15423,
370,
5634,
26,
6001,
15290,
23541,
20854,
297,
288,
6497,
29,
20773,
12,
18360,
29,
20,
14,
21,
12,
8033,
29,
6745,
360,
1216,
14,
383,
659,
8966,
29,
1886,
14,
65,
17,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9488,
12,
3144,
12,
1227,
9,
267,
776,
267,
843,
14,
66,
18,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1690,
2819,
11685,
1427,
297,
536,
534,
51,
19470,
5773,
1225,
19519,
277,
5634,
315,
5504,
869,
16363,
297,
288,
6497,
29,
28032,
12,
18360,
29,
19,
14,
16,
12,
8033,
29,
6745,
360,
1789,
14,
1643,
659,
8966,
29,
1886,
14,
65,
19,
12,
19704,
29,
1886,
14,
80,
18,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
650,
12,
650,
9,
267,
776,
267,
843,
14,
66,
19,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
9327,
1717,
1020,
2534,
297,
536,
534,
48,
6457,
3294,
5634,
7290,
83,
297,
288,
6497,
29,
5863,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
20,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
1227,
12,
6546,
9,
267,
776,
267,
843,
14,
66,
20,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
614,
708,
13251,
969,
297,
536,
534,
4718,
6001,
15290,
543,
5634,
297,
288,
6497,
29,
13595,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
21,
12,
19704,
29,
1886,
14,
80,
19,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
4119,
12,
650,
9,
267,
776,
267,
843,
14,
66,
21,
275,
8944,
14,
1462,
14,
981,
8,
288
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
295,
199,
504,
6107,
492,
6345,
199,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
992,
492,
334,
272,
481,
12,
29397,
12,
437,
10929,
12,
14826,
12,
6345,
792,
12,
31836,
792,
12,
11140,
792,
12,
28794,
12,
272,
26141,
12,
8228,
12,
10195,
12,
12094,
12,
1594,
12,
199,
9,
199,
504,
1639,
14,
396,
492,
7640,
12,
3686,
63,
5451,
199,
504,
1639,
14,
396,
14,
1208,
492,
13450,
8221,
6897,
12,
29828,
13611,
2998,
199,
504,
1639,
14,
1208,
492,
3816,
12,
7137,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
199,
504,
1275,
992,
492,
6529,
12,
8944,
12,
19952,
281,
12,
13874,
421,
199,
533,
29397,
1746,
8,
1746,
304,
339,
768,
3744,
272,
347,
3613,
16550,
8,
1886,
304,
267,
843,
14,
65,
17,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
2767,
18429,
28673,
320,
16305,
89,
297,
11437,
29,
1082,
9,
267,
843,
14,
65,
18,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
13286,
66,
1804,
439,
1502,
13,
3716,
385,
297,
11437,
29,
1276,
9,
267,
843,
14,
65,
19,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
34,
9525,
28358,
15515,
297,
11437,
29,
2322,
9,
267,
843,
14,
65,
20,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
14015,
26844,
846,
84,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
21,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
42,
3609,
17885,
2104,
559,
281,
297,
11437,
29,
1401,
9,
267,
843,
14,
65,
22,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
28282,
699,
374,
20160,
297,
11437,
29,
1398,
9,
267,
843,
14,
65,
23,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
55,
397,
15515,
1603,
14,
2799,
324,
297,
11437,
29,
821,
9,
267,
843,
14,
65,
24,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
8070,
351,
653,
269,
433,
71,
297,
11437,
29,
1641,
9,
267,
843,
14,
65,
25,
275,
6529,
14,
1462,
14,
981,
8,
354,
534,
933,
85,
580,
820,
527,
23235,
297,
11437,
29,
2466,
9,
267,
843,
14,
65,
17,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
20,
9,
267,
843,
14,
65,
18,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
20,
14,
18024,
14,
525,
8,
1886,
14,
65,
17,
9,
267,
843,
14,
65,
21,
14,
18024,
14,
525,
8,
1886,
14,
65,
22,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
22,
14,
18024,
14,
525,
8,
1886,
14,
65,
21,
12,
843,
14,
65,
23,
9,
267,
843,
14,
65,
23,
14,
18024,
14,
525,
8,
1886,
14,
65,
18,
12,
843,
14,
65,
21,
12,
843,
14,
65,
22,
9,
267,
843,
14,
65,
24,
14,
18024,
14,
525,
8,
1886,
14,
65,
25,
9,
267,
843,
14,
65,
25,
14,
18024,
14,
525,
8,
1886,
14,
65,
24,
9,
398,
843,
14,
80,
17,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
33,
2915,
297,
1967,
63,
31255,
29,
19,
12,
7373,
29,
2083,
14,
7473,
8,
4899,
29,
17,
430,
267,
843,
14,
80,
18,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
51,
19470,
297,
1967,
63,
31255,
29,
17,
12,
7373,
29,
2083,
14,
7473,
8,
4899,
29,
18,
430,
267,
843,
14,
80,
19,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
48,
828,
3548,
869,
452,
297,
1967,
63,
31255,
29,
23,
9,
267,
843,
14,
80,
20,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
534,
45,
19916,
1804,
65,
1286,
20059,
297,
1967,
63,
31255,
29,
25,
9,
267,
843,
14,
80,
21,
275,
19952,
281,
14,
1462,
14,
981,
8,
354,
628,
42,
265,
889,
1159,
869,
7130,
402,
8944,
83,
401,
1967,
63,
31255,
29,
16,
9,
398,
843,
14,
66,
17,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1046,
2710,
15459,
821,
297,
536,
534,
1918,
22659,
857,
15423,
370,
5634,
26,
6001,
15290,
23541,
20854,
297,
288,
6497,
29,
20773,
12,
18360,
29,
20,
14,
21,
12,
8033,
29,
6745,
360,
1216,
14,
383,
659,
8966,
29,
1886,
14,
65,
17,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9488,
12,
3144,
12,
1227,
9,
267,
776,
267,
843,
14,
66,
18,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
1690,
2819,
11685,
1427,
297,
536,
534,
51,
19470,
5773,
1225,
19519,
277,
5634,
315,
5504,
869,
16363,
297,
288,
6497,
29,
28032,
12,
18360,
29,
19,
14,
16,
12,
8033,
29,
6745,
360,
1789,
14,
1643,
659,
8966,
29,
1886,
14,
65,
19,
12,
19704,
29,
1886,
14,
80,
18,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
650,
12,
650,
9,
267,
776,
267,
843,
14,
66,
19,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
9327,
1717,
1020,
2534,
297,
536,
534,
48,
6457,
3294,
5634,
7290,
83,
297,
288,
6497,
29,
5863,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
20,
12,
19704,
29,
1886,
14,
80,
17,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
1227,
12,
6546,
9,
267,
776,
267,
843,
14,
66,
20,
275,
8944,
14,
1462,
14,
981,
8,
288,
365,
10472,
534,
614,
708,
13251,
969,
297,
536,
534,
4718,
6001,
15290,
543,
5634,
297,
288,
6497,
29,
13595,
12,
18360,
29,
20,
14,
16,
12,
8033,
29,
6745,
360,
1398,
14,
1876,
659,
8966,
29,
1886,
14,
65,
21,
12,
19704,
29,
1886,
14,
80,
19,
12,
288,
7974,
602,
29,
2083,
14,
602,
8,
9300,
12,
4119,
12,
650,
9,
267,
776,
267,
843,
14,
66,
21,
275,
8944,
14,
1462,
14,
981,
8,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
JGrishey/MHLSim
|
pylib/simulation.py
|
1
|
19119
|
'''
Season Simulation
2017 Jacob Grishey
For the purpose of simulating sports seasons
and determining regular season standings.
'''
# IMPORTS
import json
import statistics
import numpy
from operator import itemgetter
import copy
# Read JSON file (schedule, team list)
with open("./../data/season.json") as jsonfile:
data = json.load(jsonfile)
# Parse JSON file
teams = {team: {'w': 0, 'l': 0, 'otl': 0, 'elo': 1500} for team in data['teams']}
schedule = data['schedule']
# Results
results = [{'name': team, 'seed1': 0, 'seed2': 0, 'seed3': 0, 'seed4': 0,
'seed5': 0, 'seed6': 0, 'seed7': 0, 'seed8': 0, 'aw': 0,
'al': 0, 'aotl': 0, 'r2': 0, 'r3': 0, 'cup': 0} for team in teams]
# Divisions
brent = ["Cape Cod Bluefins", "Trevor Phillips Industries",
"Inglorious Basterds", "Crack Smoking Monkeys",
"Moose Knuckles", "Hood Rich"]
drew = ["Small Sample Size", "The Bearded Bandits",
"Row Row Fight the Powah", "Motor City Machine Guns",
"Suck Our Dekes", "Tenacious V"]
# Separate past from future games
past = [game for game in schedule if game['h-score'] != -1]
future = [game for game in schedule if game['h-score'] == -1]
# Update teams with past results
for game in past:
if game['h-score'] > game['a-score']:
if game['ot'] == 1:
teams[game['home']]['w'] += 1
teams[game['away']]['otl'] += 1
else:
teams[game['home']]['w'] += 1
teams[game['away']]['l'] += 1
else:
if game['ot'] == 1:
teams[game['away']]['w'] += 1
teams[game['home']]['otl'] += 1
else:
teams[game['away']]['w'] += 1
teams[game['home']]['l'] += 1
# Expected Score function
#
# Given elo of team A and team B, calculate expected score of team A.
def expectedScoreA (eloA, eloB):
return 1 / (1 + 10 ** ((eloB - eloA) / 400))
# New Rating Function
#
# Given Elo, actual score, expected score, and goal differential and calculate the team's new Elo rating.
def newRating (eloA, eloB, scoreActual, scoreExpected, goalDifferential, win):
# K-Factor
if eloA < 2100:
K = 32
elif eloA <= 2400:
K = 24
else:
K = 16
# Calculate for goal differential and autocorrelation
marginMult = numpy.log(goalDifferential + 1) * (2.2 / (abs(eloA - eloB) * 0.01 + 2.2))
# Return new rating
return eloA + (marginMult * K) * (scoreActual - scoreExpected)
# Update elo from past games
for game in past:
# Current Elo ratings
currentEloA = teams[game['home']]['elo']
currentEloB = teams[game['away']]['elo']
# Get Expected Scores
eA = expectedScoreA(currentEloA, currentEloB)
eB = 1 - eA
# Get scores
homeGoals = game['h-score']
awayGoals = game['a-score']
goalDifferential = abs(homeGoals - awayGoals)
# Get Actual Scores
if homeGoals > awayGoals:
if game['ot'] == 1:
sA = 1.0
sB = 0.5
winA = True
winB = False
else:
sA = 1.0
sB = 0.0
winA = False
winB = True
else:
if game['ot'] == 1:
sB = 1.0
sA = 0.5
winA = True
winB = False
else:
sB = 1.0
sA = 0.0
winA = False
winB = True
# Calculate new Elo ratings
newA = newRating(currentEloA, currentEloB, sA, eA, goalDifferential, winA)
newB = newRating(currentEloB, currentEloA, sB, eB, goalDifferential, winB)
# Apply Elo ratings
teams[game['home']]['elo'] = newA
teams[game['away']]['elo'] = newB
# Simulation
def runSeason (tempTeams):
for game in future:
# Current Elo ratings
currentEloA = tempTeams[game['home']]['elo']
currentEloB = tempTeams[game['away']]['elo']
# Get Expected Scores
eA = expectedScoreA(currentEloA, currentEloB)
eB = 1 - eA
# Random number between 0 and 1 to decide who wins.
decideWin = numpy.random.random()
# Random number between 0 and 1 to decide if it goes into Overtime.
decideOT = numpy.random.random()
# Actual Predicted Scores
if decideOT <= 0.233:
if decideWin <= eA:
sA = 1.0
tempTeams[game['home']]['w'] += 1
sB = 0.5
tempTeams[game['away']]['otl'] += 1
else:
sA = 0.5
tempTeams[game['home']]['otl'] += 1
sB = 1.0
tempTeams[game['away']]['w'] += 1
else:
if decideWin <= eA:
sA = 1.0
tempTeams[game['home']]['w'] += 1
sB = 0.0
tempTeams[game['away']]['l'] += 1
else:
sA = 0.0
tempTeams[game['home']]['l'] += 1
sB = 1.0
tempTeams[game['away']]['w'] += 1
# Calculate new Elo ratings
#newA = newRating(currentEloA, sA, eA)
#newB = newRating(currentEloB, sB, eB)
# Apply new Elo ratings
#tempTeams[game['home']]['elo'] = newA
#tempTeams[game['away']]['elo'] = newB
# End of Season standings
brentStandings = []
drewStandings = []
# Collect teams, calculate points.
for team in tempTeams:
if team in brent:
brentStandings.append({"name": team, "pts": tempTeams[team]['w'] * 2 + tempTeams[team]['otl']})
next(item for item in results if item["name"] == team)['aw'] += tempTeams[team]['w']
next(item for item in results if item["name"] == team)['al'] += tempTeams[team]['l']
next(item for item in results if item["name"] == team)['aotl'] += tempTeams[team]['otl']
else:
drewStandings.append({"name": team, "pts": tempTeams[team]['w'] * 2 + tempTeams[team]['otl']})
next(item for item in results if item["name"] == team)['aw'] += tempTeams[team]['w']
next(item for item in results if item["name"] == team)['al'] += tempTeams[team]['l']
next(item for item in results if item["name"] == team)['aotl'] += tempTeams[team]['otl']
# Sort by points
brentStandings = sorted(brentStandings, key=itemgetter('pts'), reverse=True)
drewStandings = sorted(drewStandings, key=itemgetter('pts'), reverse=True)
# Cut off top 2, then concat and sort by points
overall8 = sorted(brentStandings[2:] + drewStandings[2:], key=itemgetter('pts'), reverse=True)
# Playoff Seeding
playoffs = [{"seed": seed, "name": ""} for seed in range(1,9)]
# Get playoff teams
playoffTeams = sorted(brentStandings[:2] + drewStandings[:2] + overall8[:4],
key=itemgetter('pts'), reverse=True)
# Add Results
next(item for item in results if item["name"] == playoffTeams[0]['name'])['seed1'] += 1
next(item for item in results if item["name"] == playoffTeams[1]['name'])['seed2'] += 1
next(item for item in results if item["name"] == playoffTeams[2]['name'])['seed3'] += 1
next(item for item in results if item["name"] == playoffTeams[3]['name'])['seed4'] += 1
next(item for item in results if item["name"] == playoffTeams[4]['name'])['seed5'] += 1
next(item for item in results if item["name"] == playoffTeams[5]['name'])['seed6'] += 1
next(item for item in results if item["name"] == playoffTeams[6]['name'])['seed7'] += 1
next(item for item in results if item["name"] == playoffTeams[7]['name'])['seed8'] += 1
# Insert into seeds
for (team, i) in zip(playoffTeams, range(0, 8)):
playoffs[i]['name'] = team['name']
# Schedule first round games
firstRoundGames = []
firstRoundSeries = []
for i in range(0, 4):
firstRoundSeries.append({
'home': playoffs[i]['name'],
'away': playoffs[7-i]['name'],
'h-seed': playoffs[i]['seed'],
'a-seed': playoffs[7-i]['seed'],
'h-wins': 0,
'a-wins': 0
})
for k in range(0, 4):
firstRoundGames.append({
'home': playoffs[i]['name'],
'away': playoffs[7-i]['name']
})
# Simulate first round
for game in firstRoundGames:
# Current Elo ratings of both teams
homeElo = tempTeams[game['home']]['elo']
awayElo = tempTeams[game['away']]['elo']
# Win probabilities
eA = expectedScoreA(homeElo, awayElo)
eB = 1 - eA
# Decide win and OT
decideWin = numpy.random.random()
decideOT = numpy.random.random()
# Get series data
series = next(item for item in firstRoundSeries if item['home'] == game['home'])
# For scheduling purposes
previousLow = min([series['h-wins'], series['a-wins']])
# Simulate game
if decideOT <= 0.233:
if decideWin <= eA:
series['h-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
firstRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 1.0
sB = 0.5
else:
series['a-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
firstRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 0.5
sB = 1.0
else:
if decideWin <= eA:
series['h-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
firstRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 1.0
sB = 0.0
else:
series['a-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
firstRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 0.0
sB = 1.0
# Calculate new Elo ratings
#newA = newRating(homeElo, sA, eA)
#newB = newRating(awayElo, sB, eB)
# Apply new Elo ratings
#tempTeams[game['home']]['elo'] = newA
#tempTeams[game['away']]['elo'] = newB
# Collect series winners.
secondRoundTeams = []
for series in firstRoundSeries:
if series['h-wins'] == 4:
secondRoundTeams.append({'seed': series['h-seed'], 'name': series['home']})
next(item for item in results if item['name'] == series['home'])['r2'] += 1
else:
secondRoundTeams.append({'seed': series['a-seed'], 'name': series['away']})
next(item for item in results if item['name'] == series['away'])['r2'] += 1
secondRoundTeams = sorted(secondRoundTeams, key=itemgetter('seed'))
# Schedule second round games
secondRoundGames = []
secondRoundSeries = []
for i in range(0, 2):
secondRoundSeries.append({
'home': secondRoundTeams[i]['name'],
'away': secondRoundTeams[3-i]['name'],
'h-seed': secondRoundTeams[i]['seed'],
'a-seed': secondRoundTeams[3-i]['seed'],
'h-wins': 0,
'a-wins': 0
})
for k in range(0, 4):
secondRoundGames.append({
'home': secondRoundTeams[i]['name'],
'away': secondRoundTeams[3-i]['name']
})
# Simulate second round
for game in secondRoundGames:
# Current Elo ratings of both teams
homeElo = tempTeams[game['home']]['elo']
awayElo = tempTeams[game['away']]['elo']
# Win probabilities
eA = expectedScoreA(homeElo, awayElo)
eB = 1 - eA
# Decide win and OT
decideWin = numpy.random.random()
decideOT = numpy.random.random()
# Get series data
series = next(item for item in secondRoundSeries if item['home'] == game['home'])
# For scheduling purposes
previousLow = min([series['h-wins'], series['a-wins']])
# Simulate game
if decideOT <= 0.233:
if decideWin <= eA:
series['h-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
secondRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 1.0
sB = 0.5
else:
series['a-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
secondRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 0.5
sB = 1.0
else:
if decideWin <= eA:
series['h-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
secondRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 1.0
sB = 0.0
else:
series['a-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
secondRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 0.0
sB = 1.0
# Calculate new Elo ratings
#newA = newRating(homeElo, sA, eA)
#newB = newRating(awayElo, sB, eB)
# Apply new Elo ratings
#tempTeams[game['home']]['elo'] = newA
#tempTeams[game['away']]['elo'] = newB
# Collect series winners.
thirdRoundTeams = []
for series in secondRoundSeries:
if series['h-wins'] == 4:
thirdRoundTeams.append({'seed': series['h-seed'], 'name': series['home']})
next(item for item in results if item['name'] == series['home'])['r3'] += 1
else:
thirdRoundTeams.append({'seed': series['a-seed'], 'name': series['away']})
next(item for item in results if item['name'] == series['away'])['r3'] += 1
thirdRoundTeams = sorted(thirdRoundTeams, key=itemgetter('seed'))
# Schedule second round games
thirdRoundGames = []
thirdRoundSeries = []
for i in range(0, 1):
thirdRoundSeries.append({
'home': thirdRoundTeams[i]['name'],
'away': thirdRoundTeams[1-i]['name'],
'h-seed': thirdRoundTeams[i]['seed'],
'a-seed': thirdRoundTeams[1-i]['seed'],
'h-wins': 0,
'a-wins': 0
})
for k in range(0, 4):
thirdRoundGames.append({
'home': thirdRoundTeams[i]['name'],
'away': thirdRoundTeams[1-i]['name']
})
# Simulate third round
for game in thirdRoundGames:
# Current Elo ratings of both teams
homeElo = tempTeams[game['home']]['elo']
awayElo = tempTeams[game['away']]['elo']
# Win probabilities
eA = expectedScoreA(homeElo, awayElo)
eB = 1 - eA
# Decide win and OT
decideWin = numpy.random.random()
decideOT = numpy.random.random()
# Get series data
series = next(item for item in thirdRoundSeries if item['home'] == game['home'])
# For scheduling purposes
previousLow = min([series['h-wins'], series['a-wins']])
# Simulate game
if decideOT <= 0.233:
if decideWin <= eA:
series['h-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
thirdRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 1.0
sB = 0.5
else:
series['a-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
thirdRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 0.5
sB = 1.0
else:
if decideWin <= eA:
series['h-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
thirdRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 1.0
sB = 0.0
else:
series['a-wins'] += 1
if min([series['h-wins'], series['a-wins']]) > previousLow:
thirdRoundGames.append({
'home': game['home'],
'away': game['away']
})
sA = 0.0
sB = 1.0
# Calculate new Elo ratings
#newA = newRating(homeElo, sA, eA)
#newB = newRating(awayElo, sB, eB)
# Apply new Elo ratings
#tempTeams[game['home']]['elo'] = newA
#tempTeams[game['away']]['elo'] = newB
# Collect series winners.
cupWinner = []
for series in thirdRoundSeries:
if series['h-wins'] == 4:
cupWinner.append({'seed': series['h-seed'], 'name': series['home']})
next(item for item in results if item['name'] == series['home'])['cup'] += 1
else:
cupWinner.append({'seed': series['a-seed'], 'name': series['away']})
next(item for item in results if item['name'] == series['away'])['cup'] += 1
# Run simulation 100,000 times.
for i in range(0, 100000):
runSeason(copy.deepcopy(teams))
# Calculate average season.
for team in results:
team['aw'] /= 100000
team['al'] /= 100000
team['aotl'] /= 100000
# Add division info to each team.
for team in teams:
if team in brent:
teams[team]['division'] = "Brent"
else:
teams[team]['division'] = "Drew"
next(item for item in results if item["name"] == team)['w'] = teams[team]['w']
next(item for item in results if item["name"] == team)['l'] = teams[team]['l']
next(item for item in results if item["name"] == team)['otl'] = teams[team]['otl']
next(item for item in results if item["name"] == team)['elo'] = teams[team]['elo']
next(item for item in results if item["name"] == team)['division'] = teams[team]['division']
# Write results to outfile.
with open('./../data/results.json', 'w') as outfile:
json.dump(results, outfile, indent=4)
|
mit
|
[
2344,
272,
3240,
2660,
10751,
5332,
2286,
9708,
1603,
13286,
66,
598,
5719,
426,
89,
339,
2104,
314,
12016,
402,
4389,
20529,
308,
5203,
14718,
83,
272,
436,
26638,
5578,
14718,
10584,
780,
14,
199,
2344,
199,
199,
3,
5025,
2596,
51,
199,
199,
646,
2022,
199,
646,
11076,
199,
646,
2680,
199,
504,
4182,
492,
1242,
7416,
199,
646,
1331,
9948,
199,
3,
5574,
4840,
570,
334,
7211,
12,
8099,
769,
9,
199,
199,
1045,
1551,
28615,
5093,
576,
15,
12605,
14,
1001,
531,
465,
2022,
493,
26,
272,
666,
275,
2022,
14,
912,
8,
1001,
493,
9,
199,
199,
3,
6077,
4840,
570,
199,
199,
19048,
275,
469,
5969,
26,
791,
87,
356,
378,
12,
283,
76,
356,
378,
12,
283,
357,
76,
356,
378,
12,
283,
69,
320,
356,
24970,
93,
367,
8099,
315,
666,
459,
19048,
12074,
199,
199,
7211,
275,
666,
459,
7211,
418,
199,
199,
3,
24288,
199,
199,
2604,
275,
9016,
354,
356,
8099,
12,
283,
5176,
17,
356,
378,
12,
283,
5176,
18,
356,
378,
12,
283,
5176,
19,
356,
378,
12,
283,
5176,
20,
356,
378,
12,
1467,
283,
5176,
21,
356,
378,
12,
283,
5176,
22,
356,
378,
12,
283,
5176,
23,
356,
378,
12,
283,
5176,
24,
356,
378,
12,
283,
10084,
356,
378,
12,
1598,
283,
279,
356,
378,
12,
283,
65,
357,
76,
356,
378,
12,
283,
82,
18,
356,
378,
12,
283,
82,
19,
356,
378,
12,
283,
17500,
356,
378,
93,
367,
8099,
315,
25823,
61,
199,
199,
3,
3757,
13193,
199,
199,
66,
640,
275,
2097,
35,
924,
445,
364,
22447,
2408,
83,
401,
298,
52,
4964,
269,
11308,
8148,
1190,
473,
977,
85,
816,
397,
401,
267,
298,
607,
3528,
16039,
1785,
699,
2311,
795,
401,
298,
35,
8085,
428,
573,
17443,
10953,
1612,
401,
267,
298,
45,
10518,
1804,
4850,
346,
2978,
401,
298,
17810,
364,
30846,
937,
199,
68,
5257,
275,
2097,
10712,
15227,
14579,
401,
298,
1918,
699,
2210,
770,
699,
290,
15256,
401,
267,
298,
5810,
15231,
481,
1070,
314,
510,
583,
11326,
401,
298,
31642,
14753,
18722,
598,
324,
83,
401,
267,
298,
51,
10112,
25119,
1487,
9246,
401,
298,
22216,
22832,
1785,
812,
937,
199,
199,
3,
27504,
323,
13541,
687,
6466,
9219,
83,
199,
199,
18597,
275,
359,
5097,
367,
9219,
315,
8732,
340,
9219,
459,
72,
13,
3397,
418,
1137,
446,
17,
61,
199,
199,
2443,
275,
359,
5097,
367,
9219,
315,
8732,
340,
9219,
459,
72,
13,
3397,
418,
508,
446,
17,
61,
199,
199,
3,
6162,
25823,
543,
13541,
2058,
199,
199,
509,
9219,
315,
13541,
26,
272,
340,
9219,
459,
72,
13,
3397,
418,
690,
9219,
459,
65,
13,
3397,
2565,
267,
340,
9219,
459,
357,
418,
508,
413,
26,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
357,
76,
418,
847,
413,
267,
587,
26,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
76,
418,
847,
413,
272,
587,
26,
267,
340,
9219,
459,
357,
418,
508,
413,
26,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
357,
76,
418,
847,
413,
267,
587,
26,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
76,
418,
847,
413,
199,
199,
3,
13796,
25318,
805,
199,
3,
199,
3,
9138,
325,
320,
402,
8099,
437,
436,
8099,
699,
12,
8671,
1420,
5396,
402,
8099,
437,
14,
199,
199,
318,
1420,
12642,
33,
334,
69,
320,
33,
12,
325,
320,
34,
304,
272,
372,
413,
1182,
334,
17,
435,
1616,
1011,
3666,
69,
320,
34,
446,
325,
320,
33,
9,
1182,
8290,
430,
199,
199,
3,
7053,
820,
1958,
6801,
199,
3,
199,
3,
9138,
662,
320,
12,
3503,
5396,
12,
1420,
5396,
12,
436,
14850,
31605,
436,
8671,
314,
8099,
1159,
892,
662,
320,
18360,
14,
199,
199,
318,
892,
32533,
334,
69,
320,
33,
12,
325,
320,
34,
12,
5396,
30141,
12,
5396,
6964,
12,
14850,
16384,
27257,
12,
4747,
304,
272,
327,
1804,
13,
12666,
272,
340,
325,
320,
33,
665,
499,
1960,
26,
267,
1804,
275,
4337,
272,
916,
325,
320,
33,
2695,
499,
5303,
26,
267,
1804,
275,
5504,
272,
587,
26,
267,
1804,
275,
3193,
2286,
327,
12707,
367,
14850,
31605,
436,
6384,
28720,
5690,
272,
11042,
30233,
275,
2680,
14,
793,
8,
16117,
16384,
27257,
435,
413,
9,
627,
334,
18,
14,
18,
1182,
334,
2101,
8,
69,
320,
33,
446,
325,
320,
34,
9,
627,
378,
14,
614,
435,
499,
14,
18,
430,
339,
327,
1432,
892,
18360,
272,
372,
325,
320,
33,
435,
334,
9650,
30233,
627,
1804,
9,
627,
334,
3397,
30141,
446,
5396,
6964,
9,
199,
199,
3,
6162,
325,
320,
687,
13541,
9219,
83,
199,
199,
509,
9219,
315,
13541,
26,
272,
327,
9338,
662,
320,
32026,
780,
272,
1453,
37,
320,
33,
275,
25823,
59,
5097,
459,
4219,
418,
2733,
69,
320,
418,
272,
1453,
37,
320,
34,
275,
25823,
59,
5097,
459,
22703,
418,
2733,
69,
320,
418,
339,
327,
2372,
13796,
428,
4630,
272,
325,
33,
275,
1420,
12642,
33,
8,
1818,
37,
320,
33,
12,
1453,
37,
320,
34,
9,
272,
325,
34,
275,
413,
446,
325,
33,
339,
327,
2372,
9342,
272,
5629,
7250,
2551,
275,
9219,
459,
72,
13,
3397,
418,
272,
13437,
7250,
2551,
275,
9219,
459,
65,
13,
3397,
418,
272,
14850,
16384,
27257,
275,
2853,
8,
4219,
7250,
2551,
446,
13437,
7250,
2551,
9,
339,
327,
2372,
18982,
1061,
428,
4630,
272,
340,
5629,
7250,
2551,
690,
13437,
7250,
2551,
26,
267,
340,
9219,
459,
357,
418,
508,
413,
26,
288,
308,
33,
275,
413,
14,
16,
288,
308,
34,
275,
378,
14,
21,
288,
4747,
33,
275,
715,
288,
4747,
34,
275,
756,
267,
587,
26,
288,
308,
33,
275,
413,
14,
16,
288,
308,
34,
275,
378,
14,
16,
288,
4747,
33,
275,
756,
288,
4747,
34,
275,
715,
272,
587,
26,
267,
340,
9219,
459,
357
] |
[
272,
3240,
2660,
10751,
5332,
2286,
9708,
1603,
13286,
66,
598,
5719,
426,
89,
339,
2104,
314,
12016,
402,
4389,
20529,
308,
5203,
14718,
83,
272,
436,
26638,
5578,
14718,
10584,
780,
14,
199,
2344,
199,
199,
3,
5025,
2596,
51,
199,
199,
646,
2022,
199,
646,
11076,
199,
646,
2680,
199,
504,
4182,
492,
1242,
7416,
199,
646,
1331,
9948,
199,
3,
5574,
4840,
570,
334,
7211,
12,
8099,
769,
9,
199,
199,
1045,
1551,
28615,
5093,
576,
15,
12605,
14,
1001,
531,
465,
2022,
493,
26,
272,
666,
275,
2022,
14,
912,
8,
1001,
493,
9,
199,
199,
3,
6077,
4840,
570,
199,
199,
19048,
275,
469,
5969,
26,
791,
87,
356,
378,
12,
283,
76,
356,
378,
12,
283,
357,
76,
356,
378,
12,
283,
69,
320,
356,
24970,
93,
367,
8099,
315,
666,
459,
19048,
12074,
199,
199,
7211,
275,
666,
459,
7211,
418,
199,
199,
3,
24288,
199,
199,
2604,
275,
9016,
354,
356,
8099,
12,
283,
5176,
17,
356,
378,
12,
283,
5176,
18,
356,
378,
12,
283,
5176,
19,
356,
378,
12,
283,
5176,
20,
356,
378,
12,
1467,
283,
5176,
21,
356,
378,
12,
283,
5176,
22,
356,
378,
12,
283,
5176,
23,
356,
378,
12,
283,
5176,
24,
356,
378,
12,
283,
10084,
356,
378,
12,
1598,
283,
279,
356,
378,
12,
283,
65,
357,
76,
356,
378,
12,
283,
82,
18,
356,
378,
12,
283,
82,
19,
356,
378,
12,
283,
17500,
356,
378,
93,
367,
8099,
315,
25823,
61,
199,
199,
3,
3757,
13193,
199,
199,
66,
640,
275,
2097,
35,
924,
445,
364,
22447,
2408,
83,
401,
298,
52,
4964,
269,
11308,
8148,
1190,
473,
977,
85,
816,
397,
401,
267,
298,
607,
3528,
16039,
1785,
699,
2311,
795,
401,
298,
35,
8085,
428,
573,
17443,
10953,
1612,
401,
267,
298,
45,
10518,
1804,
4850,
346,
2978,
401,
298,
17810,
364,
30846,
937,
199,
68,
5257,
275,
2097,
10712,
15227,
14579,
401,
298,
1918,
699,
2210,
770,
699,
290,
15256,
401,
267,
298,
5810,
15231,
481,
1070,
314,
510,
583,
11326,
401,
298,
31642,
14753,
18722,
598,
324,
83,
401,
267,
298,
51,
10112,
25119,
1487,
9246,
401,
298,
22216,
22832,
1785,
812,
937,
199,
199,
3,
27504,
323,
13541,
687,
6466,
9219,
83,
199,
199,
18597,
275,
359,
5097,
367,
9219,
315,
8732,
340,
9219,
459,
72,
13,
3397,
418,
1137,
446,
17,
61,
199,
199,
2443,
275,
359,
5097,
367,
9219,
315,
8732,
340,
9219,
459,
72,
13,
3397,
418,
508,
446,
17,
61,
199,
199,
3,
6162,
25823,
543,
13541,
2058,
199,
199,
509,
9219,
315,
13541,
26,
272,
340,
9219,
459,
72,
13,
3397,
418,
690,
9219,
459,
65,
13,
3397,
2565,
267,
340,
9219,
459,
357,
418,
508,
413,
26,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
357,
76,
418,
847,
413,
267,
587,
26,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
76,
418,
847,
413,
272,
587,
26,
267,
340,
9219,
459,
357,
418,
508,
413,
26,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
357,
76,
418,
847,
413,
267,
587,
26,
288,
25823,
59,
5097,
459,
22703,
418,
2733,
87,
418,
847,
413,
288,
25823,
59,
5097,
459,
4219,
418,
2733,
76,
418,
847,
413,
199,
199,
3,
13796,
25318,
805,
199,
3,
199,
3,
9138,
325,
320,
402,
8099,
437,
436,
8099,
699,
12,
8671,
1420,
5396,
402,
8099,
437,
14,
199,
199,
318,
1420,
12642,
33,
334,
69,
320,
33,
12,
325,
320,
34,
304,
272,
372,
413,
1182,
334,
17,
435,
1616,
1011,
3666,
69,
320,
34,
446,
325,
320,
33,
9,
1182,
8290,
430,
199,
199,
3,
7053,
820,
1958,
6801,
199,
3,
199,
3,
9138,
662,
320,
12,
3503,
5396,
12,
1420,
5396,
12,
436,
14850,
31605,
436,
8671,
314,
8099,
1159,
892,
662,
320,
18360,
14,
199,
199,
318,
892,
32533,
334,
69,
320,
33,
12,
325,
320,
34,
12,
5396,
30141,
12,
5396,
6964,
12,
14850,
16384,
27257,
12,
4747,
304,
272,
327,
1804,
13,
12666,
272,
340,
325,
320,
33,
665,
499,
1960,
26,
267,
1804,
275,
4337,
272,
916,
325,
320,
33,
2695,
499,
5303,
26,
267,
1804,
275,
5504,
272,
587,
26,
267,
1804,
275,
3193,
2286,
327,
12707,
367,
14850,
31605,
436,
6384,
28720,
5690,
272,
11042,
30233,
275,
2680,
14,
793,
8,
16117,
16384,
27257,
435,
413,
9,
627,
334,
18,
14,
18,
1182,
334,
2101,
8,
69,
320,
33,
446,
325,
320,
34,
9,
627,
378,
14,
614,
435,
499,
14,
18,
430,
339,
327,
1432,
892,
18360,
272,
372,
325,
320,
33,
435,
334,
9650,
30233,
627,
1804,
9,
627,
334,
3397,
30141,
446,
5396,
6964,
9,
199,
199,
3,
6162,
325,
320,
687,
13541,
9219,
83,
199,
199,
509,
9219,
315,
13541,
26,
272,
327,
9338,
662,
320,
32026,
780,
272,
1453,
37,
320,
33,
275,
25823,
59,
5097,
459,
4219,
418,
2733,
69,
320,
418,
272,
1453,
37,
320,
34,
275,
25823,
59,
5097,
459,
22703,
418,
2733,
69,
320,
418,
339,
327,
2372,
13796,
428,
4630,
272,
325,
33,
275,
1420,
12642,
33,
8,
1818,
37,
320,
33,
12,
1453,
37,
320,
34,
9,
272,
325,
34,
275,
413,
446,
325,
33,
339,
327,
2372,
9342,
272,
5629,
7250,
2551,
275,
9219,
459,
72,
13,
3397,
418,
272,
13437,
7250,
2551,
275,
9219,
459,
65,
13,
3397,
418,
272,
14850,
16384,
27257,
275,
2853,
8,
4219,
7250,
2551,
446,
13437,
7250,
2551,
9,
339,
327,
2372,
18982,
1061,
428,
4630,
272,
340,
5629,
7250,
2551,
690,
13437,
7250,
2551,
26,
267,
340,
9219,
459,
357,
418,
508,
413,
26,
288,
308,
33,
275,
413,
14,
16,
288,
308,
34,
275,
378,
14,
21,
288,
4747,
33,
275,
715,
288,
4747,
34,
275,
756,
267,
587,
26,
288,
308,
33,
275,
413,
14,
16,
288,
308,
34,
275,
378,
14,
16,
288,
4747,
33,
275,
756,
288,
4747,
34,
275,
715,
272,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
ilexius/odoo
|
addons/membership/__openerp__.py
|
24
|
1270
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Membership Management',
'version': '0.1',
'category': 'Association',
'description': """
This module allows you to manage all operations for managing memberships.
=========================================================================
It supports different kind of members:
--------------------------------------
* Free member
* Associated member (e.g.: a group subscribes to a membership for all subsidiaries)
* Paid members
* Special member prices
It is integrated with sales and accounting to allow you to automatically
invoice and send propositions for membership renewal.
""",
'depends': ['base', 'product', 'account'],
'data': [
'security/ir.model.access.csv',
'wizard/membership_invoice_view.xml',
'membership_data.xml',
'membership_view.xml',
'report/report_membership_view.xml',
],
'demo': [
'membership_demo.xml',
],
'website': 'https://www.odoo.com/page/community-builder',
'test': [
'../account/test/account_minimal_test.xml',
'test/test_membership.yml'
],
'installable': True,
'auto_install': False,
}
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
421,
199,
91,
272,
283,
354,
356,
283,
19480,
8259,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
18662,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
6127,
1265,
370,
9635,
1006,
5331,
367,
28453,
14616,
83,
14,
199,
5695,
15495,
199,
199,
7940,
5171,
3365,
4928,
402,
7556,
26,
199,
1444,
8648,
272,
627,
2868,
3653,
272,
627,
24207,
972,
3653,
334,
69,
14,
71,
16781,
282,
1572,
1007,
729,
11562,
370,
282,
14616,
367,
1006,
1007,
338,
328,
3433,
9,
272,
627,
10164,
344,
7556,
272,
627,
12568,
3653,
1979,
823,
199,
199,
7940,
365,
17806,
972,
543,
21702,
436,
24772,
370,
2040,
1265,
370,
5847,
199,
5404,
436,
3222,
557,
12658,
367,
14616,
295,
1222,
279,
14,
272,
10327,
272,
283,
8912,
356,
788,
1095,
297,
283,
2558,
297,
283,
2048,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
9819,
15,
13105,
63,
5404,
63,
1345,
14,
1652,
297,
267,
283,
13105,
63,
576,
14,
1652,
297,
267,
283,
13105,
63,
1345,
14,
1652,
297,
267,
283,
3070,
15,
3070,
63,
13105,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
359,
267,
283,
13105,
63,
8768,
14,
1652,
297,
272,
2156,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
9387,
13,
5649,
297,
272,
283,
396,
356,
359,
267,
20644,
2048,
15,
396,
15,
2048,
63,
21508,
63,
396,
14,
1652,
297,
267,
283,
396,
15,
396,
63,
13105,
14,
11714,
7,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
421,
199,
91,
272,
283,
354,
356,
283,
19480,
8259,
297,
272,
283,
1023,
356,
283,
16,
14,
17,
297,
272,
283,
3710,
356,
283,
18662,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
6127,
1265,
370,
9635,
1006,
5331,
367,
28453,
14616,
83,
14,
199,
5695,
15495,
199,
199,
7940,
5171,
3365,
4928,
402,
7556,
26,
199,
1444,
8648,
272,
627,
2868,
3653,
272,
627,
24207,
972,
3653,
334,
69,
14,
71,
16781,
282,
1572,
1007,
729,
11562,
370,
282,
14616,
367,
1006,
1007,
338,
328,
3433,
9,
272,
627,
10164,
344,
7556,
272,
627,
12568,
3653,
1979,
823,
199,
199,
7940,
365,
17806,
972,
543,
21702,
436,
24772,
370,
2040,
1265,
370,
5847,
199,
5404,
436,
3222,
557,
12658,
367,
14616,
295,
1222,
279,
14,
272,
10327,
272,
283,
8912,
356,
788,
1095,
297,
283,
2558,
297,
283,
2048,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
9819,
15,
13105,
63,
5404,
63,
1345,
14,
1652,
297,
267,
283,
13105,
63,
576,
14,
1652,
297,
267,
283,
13105,
63,
1345,
14,
1652,
297,
267,
283,
3070,
15,
3070,
63,
13105,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
359,
267,
283,
13105,
63,
8768,
14,
1652,
297,
272,
2156,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
9387,
13,
5649,
297,
272,
283,
396,
356,
359,
267,
20644,
2048,
15,
396,
15,
2048,
63,
21508,
63,
396,
14,
1652,
297,
267,
283,
396,
15,
396,
63,
13105,
14,
11714,
7,
272,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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,
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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
] |
PuZheng/lejian-backend
|
lejian/apis/model_wrapper.py
|
1
|
3211
|
# -*- coding: UTF-8 -*-
import types
import inspect
import traceback
class _MyAttributeError(Exception):
pass
def convert_attribute_error(f):
def f_(*args, **kwargs):
try:
return f(*args, **kwargs)
except AttributeError, e:
print "~" * 78
traceback.print_exc()
print "~" * 78
raise _MyAttributeError(e)
return f_
class _FGet(object):
def __init__(self, attr):
self.attr = attr
def __call__(self, wrapper):
return wraps(convert_attribute_error(self.attr.fget)(wrapper))
def wraps(obj):
if isinstance(obj, types.ListType) or isinstance(obj, types.TupleType):
return obj.__class__(wraps(obj_) for obj_ in obj)
if hasattr(obj.__class__, '_sa_class_manager'):
try:
return _wrappers[obj.__class__.__name__ + "Wrapper"](obj)
except KeyError:
return obj
return obj
def unwraps(obj):
if isinstance(obj, types.ListType) or isinstance(obj, types.TupleType):
return obj.__class__(unwraps(obj_) for obj_ in obj)
if isinstance(obj, ModelWrapper):
return obj.obj
return obj
_wrappers = {}
class ModelWrapper(object):
class __metaclass__(type):
def __init__(cls, name, bases, nmspc):
type.__init__(cls, name, bases, nmspc)
# register wrappers
_wrappers[cls.__name__] = cls
# decorate wrapper's method:
#
# * convert result object(s) to wrapper(s)
# * convert attribute error, otherwise the underlying object
# will be searched, and finally make bizzare result
for name, attr in cls.__dict__.items():
if isinstance(attr, property) and name not in {'obj'}:
setattr(cls, name, property(fget=_FGet(attr),
fset=attr.fset,
fdel=attr.fdel))
elif inspect.ismethod(attr) and attr not in {'__getattr__',
'__setattr__',
'__unicode__'}:
old = convert_attribute_error(getattr(cls, name))
setattr(cls, name, lambda wrapper, *args,
**kwargs: wraps(old(wrapper, *args, **kwargs)))
def __init__(self, obj):
self.__obj = obj
@property
def obj(self):
return self.__obj
def __getattr__(self, name):
attr = getattr(self.__obj, name)
if isinstance(attr, types.ListType) or isinstance(attr,
types.TupleType):
return type(attr)(wraps(i) for i in attr)
return wraps(attr)
def __setattr__(self, key, value):
# TODO when only key is defined in wrapped object
if key != '_ModelWrapper__obj':
self.__obj.__setattr__(key, value)
else:
self.__dict__[key] = value
def __unicode__(self):
return unicode(self.__obj)
def __dir__(self):
return self.__obj.__dict__.keys()
|
mit
|
[
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
646,
2943,
199,
646,
6485,
199,
646,
5190,
421,
199,
533,
485,
5713,
10227,
8,
1726,
304,
339,
986,
421,
199,
318,
3957,
63,
3215,
63,
705,
8,
70,
304,
339,
347,
289,
63,
2031,
589,
12,
1011,
958,
304,
267,
862,
26,
288,
372,
289,
2031,
589,
12,
1011,
958,
9,
267,
871,
4281,
12,
325,
26,
288,
870,
26810,
2,
627,
14679,
288,
5190,
14,
1361,
63,
2804,
342,
288,
870,
26810,
2,
627,
14679,
288,
746,
485,
5713,
10227,
8,
69,
9,
339,
372,
289,
63,
421,
199,
533,
485,
38,
1002,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1921,
304,
267,
291,
14,
962,
275,
1921,
339,
347,
636,
1250,
721,
277,
12,
4975,
304,
267,
372,
14018,
8,
3916,
63,
3215,
63,
705,
8,
277,
14,
962,
14,
27823,
5130,
5029,
430,
421,
199,
318,
14018,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
2943,
14,
22113,
9,
503,
1228,
8,
1113,
12,
2943,
14,
7075,
804,
304,
267,
372,
1559,
855,
533,
721,
13582,
8,
1113,
4602,
367,
1559,
63,
315,
1559,
9,
272,
340,
2688,
8,
1113,
855,
533,
3108,
2513,
2231,
63,
533,
63,
2609,
735,
267,
862,
26,
288,
372,
485,
21148,
59,
1113,
855,
533,
4914,
354,
363,
435,
298,
4590,
937,
8,
1113,
9,
267,
871,
4067,
26,
288,
372,
1559,
272,
372,
1559,
421,
199,
318,
625,
13582,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
2943,
14,
22113,
9,
503,
1228,
8,
1113,
12,
2943,
14,
7075,
804,
304,
267,
372,
1559,
855,
533,
721,
324,
13582,
8,
1113,
4602,
367,
1559,
63,
315,
1559,
9,
272,
340,
1228,
8,
1113,
12,
5822,
4590,
304,
267,
372,
1559,
14,
1113,
272,
372,
1559,
199,
199,
63,
21148,
275,
1052,
421,
199,
533,
5822,
4590,
8,
785,
304,
339,
1021,
636,
6577,
721,
466,
304,
267,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
16751,
681,
67,
304,
288,
730,
855,
826,
721,
1886,
12,
536,
12,
9768,
12,
16751,
681,
67,
9,
288,
327,
2274,
17995,
288,
485,
21148,
59,
1886,
855,
354,
22705,
275,
843,
288,
327,
24774,
4975,
1159,
1083,
26,
288,
327,
288,
327,
257,
627,
3957,
754,
909,
8,
83,
9,
370,
4975,
8,
83,
9,
288,
327,
257,
627,
3957,
2225,
1125,
12,
4257,
314,
8793,
909,
288,
327,
258,
911,
506,
17543,
12,
436,
3753,
1852,
330,
28981,
1530,
754,
288,
367,
536,
12,
1921,
315,
843,
855,
807,
4343,
1744,
837,
355,
340,
1228,
8,
962,
12,
3324,
9,
436,
536,
440,
315,
791,
1113,
936,
26,
490,
5371,
8,
1886,
12,
536,
12,
3324,
8,
27823,
3699,
38,
1002,
8,
962,
395,
6059,
289,
409,
29,
962,
14,
70,
409,
12,
6059,
289,
2264,
29,
962,
14,
70,
2264,
430,
355,
916,
6485,
14,
374,
765,
8,
962,
9,
436,
1921,
440,
315,
791,
363,
5675,
7500,
18193,
2560,
10202,
7500,
18193,
2560,
2975,
363,
936,
26,
490,
2269,
275,
3957,
63,
3215,
63,
705,
8,
5675,
8,
1886,
12,
536,
430,
490,
5371,
8,
1886,
12,
536,
12,
2400,
4975,
12,
627,
589,
12,
1169,
1011,
958,
26,
14018,
8,
1753,
8,
5029,
12,
627,
589,
12,
1011,
958,
1724,
339,
347,
636,
826,
721,
277,
12,
1559,
304,
267,
291,
855,
1113,
275,
1559,
339,
768,
1829,
272,
347,
1559,
8,
277,
304,
267,
372,
291,
855,
1113,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
1921,
275,
2519,
8,
277,
855,
1113,
12,
536,
9,
267,
340,
1228,
8,
962,
12,
2943,
14,
22113,
9,
503,
1228,
8,
962,
12,
12933,
2943,
14,
7075,
804,
304,
288,
372,
730,
8,
962,
5130,
13582,
8,
73,
9,
367,
284,
315,
1921,
9,
267,
372,
14018,
8,
962,
9,
339,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
327,
3254,
1380,
1454,
790,
365,
3247,
315,
8072,
909,
267,
340,
790,
1137,
2513,
1685,
4590,
363,
1113,
356,
288,
291,
855,
1113,
855,
10202,
721,
498,
12,
574,
9,
267,
587,
26,
288,
291,
855,
807,
12298,
498,
61,
275,
574,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
2649,
8,
277,
855,
1113,
9,
339,
347,
636,
694,
721,
277,
304,
267,
372,
291,
855,
1113,
855,
807,
4343,
1612,
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
] |
[
1882,
2803,
26,
9094,
13,
24,
1882,
199,
646,
2943,
199,
646,
6485,
199,
646,
5190,
421,
199,
533,
485,
5713,
10227,
8,
1726,
304,
339,
986,
421,
199,
318,
3957,
63,
3215,
63,
705,
8,
70,
304,
339,
347,
289,
63,
2031,
589,
12,
1011,
958,
304,
267,
862,
26,
288,
372,
289,
2031,
589,
12,
1011,
958,
9,
267,
871,
4281,
12,
325,
26,
288,
870,
26810,
2,
627,
14679,
288,
5190,
14,
1361,
63,
2804,
342,
288,
870,
26810,
2,
627,
14679,
288,
746,
485,
5713,
10227,
8,
69,
9,
339,
372,
289,
63,
421,
199,
533,
485,
38,
1002,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1921,
304,
267,
291,
14,
962,
275,
1921,
339,
347,
636,
1250,
721,
277,
12,
4975,
304,
267,
372,
14018,
8,
3916,
63,
3215,
63,
705,
8,
277,
14,
962,
14,
27823,
5130,
5029,
430,
421,
199,
318,
14018,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
2943,
14,
22113,
9,
503,
1228,
8,
1113,
12,
2943,
14,
7075,
804,
304,
267,
372,
1559,
855,
533,
721,
13582,
8,
1113,
4602,
367,
1559,
63,
315,
1559,
9,
272,
340,
2688,
8,
1113,
855,
533,
3108,
2513,
2231,
63,
533,
63,
2609,
735,
267,
862,
26,
288,
372,
485,
21148,
59,
1113,
855,
533,
4914,
354,
363,
435,
298,
4590,
937,
8,
1113,
9,
267,
871,
4067,
26,
288,
372,
1559,
272,
372,
1559,
421,
199,
318,
625,
13582,
8,
1113,
304,
272,
340,
1228,
8,
1113,
12,
2943,
14,
22113,
9,
503,
1228,
8,
1113,
12,
2943,
14,
7075,
804,
304,
267,
372,
1559,
855,
533,
721,
324,
13582,
8,
1113,
4602,
367,
1559,
63,
315,
1559,
9,
272,
340,
1228,
8,
1113,
12,
5822,
4590,
304,
267,
372,
1559,
14,
1113,
272,
372,
1559,
199,
199,
63,
21148,
275,
1052,
421,
199,
533,
5822,
4590,
8,
785,
304,
339,
1021,
636,
6577,
721,
466,
304,
267,
347,
636,
826,
721,
1886,
12,
536,
12,
9768,
12,
16751,
681,
67,
304,
288,
730,
855,
826,
721,
1886,
12,
536,
12,
9768,
12,
16751,
681,
67,
9,
288,
327,
2274,
17995,
288,
485,
21148,
59,
1886,
855,
354,
22705,
275,
843,
288,
327,
24774,
4975,
1159,
1083,
26,
288,
327,
288,
327,
257,
627,
3957,
754,
909,
8,
83,
9,
370,
4975,
8,
83,
9,
288,
327,
257,
627,
3957,
2225,
1125,
12,
4257,
314,
8793,
909,
288,
327,
258,
911,
506,
17543,
12,
436,
3753,
1852,
330,
28981,
1530,
754,
288,
367,
536,
12,
1921,
315,
843,
855,
807,
4343,
1744,
837,
355,
340,
1228,
8,
962,
12,
3324,
9,
436,
536,
440,
315,
791,
1113,
936,
26,
490,
5371,
8,
1886,
12,
536,
12,
3324,
8,
27823,
3699,
38,
1002,
8,
962,
395,
6059,
289,
409,
29,
962,
14,
70,
409,
12,
6059,
289,
2264,
29,
962,
14,
70,
2264,
430,
355,
916,
6485,
14,
374,
765,
8,
962,
9,
436,
1921,
440,
315,
791,
363,
5675,
7500,
18193,
2560,
10202,
7500,
18193,
2560,
2975,
363,
936,
26,
490,
2269,
275,
3957,
63,
3215,
63,
705,
8,
5675,
8,
1886,
12,
536,
430,
490,
5371,
8,
1886,
12,
536,
12,
2400,
4975,
12,
627,
589,
12,
1169,
1011,
958,
26,
14018,
8,
1753,
8,
5029,
12,
627,
589,
12,
1011,
958,
1724,
339,
347,
636,
826,
721,
277,
12,
1559,
304,
267,
291,
855,
1113,
275,
1559,
339,
768,
1829,
272,
347,
1559,
8,
277,
304,
267,
372,
291,
855,
1113,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
1921,
275,
2519,
8,
277,
855,
1113,
12,
536,
9,
267,
340,
1228,
8,
962,
12,
2943,
14,
22113,
9,
503,
1228,
8,
962,
12,
12933,
2943,
14,
7075,
804,
304,
288,
372,
730,
8,
962,
5130,
13582,
8,
73,
9,
367,
284,
315,
1921,
9,
267,
372,
14018,
8,
962,
9,
339,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
327,
3254,
1380,
1454,
790,
365,
3247,
315,
8072,
909,
267,
340,
790,
1137,
2513,
1685,
4590,
363,
1113,
356,
288,
291,
855,
1113,
855,
10202,
721,
498,
12,
574,
9,
267,
587,
26,
288,
291,
855,
807,
12298,
498,
61,
275,
574,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
2649,
8,
277,
855,
1113,
9,
339,
347,
636,
694,
721,
277,
304,
267,
372,
291,
855,
1113,
855,
807,
4343,
1612,
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,
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,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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
] |
chouseknecht/ansible
|
lib/ansible/plugins/filter/core.py
|
11
|
21162
|
# (c) 2012, Jeroen Hoekx <jeroen@hoekx.be>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import base64
import crypt
import glob
import hashlib
import itertools
import json
import ntpath
import os.path
import re
import string
import sys
import time
import uuid
import yaml
import datetime
from functools import partial
from random import Random, SystemRandom, shuffle
from jinja2.filters import environmentfilter, do_groupby as _do_groupby
from ansible.errors import AnsibleError, AnsibleFilterError
from ansible.module_utils.six import iteritems, string_types, integer_types, reraise
from ansible.module_utils.six.moves import reduce, shlex_quote
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.common.collections import is_sequence
from ansible.module_utils.common._collections_compat import Mapping, MutableMapping
from ansible.parsing.ajson import AnsibleJSONEncoder
from ansible.parsing.yaml.dumper import AnsibleDumper
from ansible.template import recursive_check_defined
from ansible.utils.display import Display
from ansible.utils.encrypt import passlib_or_crypt
from ansible.utils.hashing import md5s, checksum_s
from ansible.utils.unicode import unicode_wrap
from ansible.utils.vars import merge_hash
display = Display()
UUID_NAMESPACE_ANSIBLE = uuid.UUID('361E6D51-FAEC-444A-9079-341386DA8E2E')
def to_yaml(a, *args, **kw):
'''Make verbose, human readable yaml'''
default_flow_style = kw.pop('default_flow_style', None)
transformed = yaml.dump(a, Dumper=AnsibleDumper, allow_unicode=True, default_flow_style=default_flow_style, **kw)
return to_text(transformed)
def to_nice_yaml(a, indent=4, *args, **kw):
'''Make verbose, human readable yaml'''
transformed = yaml.dump(a, Dumper=AnsibleDumper, indent=indent, allow_unicode=True, default_flow_style=False, **kw)
return to_text(transformed)
def to_json(a, *args, **kw):
''' Convert the value to JSON '''
return json.dumps(a, cls=AnsibleJSONEncoder, *args, **kw)
def to_nice_json(a, indent=4, sort_keys=True, *args, **kw):
'''Make verbose, human readable JSON'''
try:
return json.dumps(a, indent=indent, sort_keys=sort_keys, separators=(',', ': '), cls=AnsibleJSONEncoder, *args, **kw)
except Exception as e:
# Fallback to the to_json filter
display.warning(u'Unable to convert data using to_nice_json, falling back to to_json: %s' % to_text(e))
return to_json(a, *args, **kw)
def to_bool(a):
''' return a bool for the arg '''
if a is None or isinstance(a, bool):
return a
if isinstance(a, string_types):
a = a.lower()
if a in ('yes', 'on', '1', 'true', 1):
return True
return False
def to_datetime(string, format="%Y-%m-%d %H:%M:%S"):
return datetime.datetime.strptime(string, format)
def strftime(string_format, second=None):
''' return a date string using string. See https://docs.python.org/2/library/time.html#time.strftime for format '''
if second is not None:
try:
second = int(second)
except Exception:
raise AnsibleFilterError('Invalid value for epoch value (%s)' % second)
return time.strftime(string_format, time.localtime(second))
def quote(a):
''' return its argument quoted for shell usage '''
return shlex_quote(to_text(a))
def fileglob(pathname):
''' return list of matched regular files for glob '''
return [g for g in glob.glob(pathname) if os.path.isfile(g)]
def regex_replace(value='', pattern='', replacement='', ignorecase=False):
''' Perform a `re.sub` returning a string '''
value = to_text(value, errors='surrogate_or_strict', nonstring='simplerepr')
if ignorecase:
flags = re.I
else:
flags = 0
_re = re.compile(pattern, flags=flags)
return _re.sub(replacement, value)
def regex_findall(value, regex, multiline=False, ignorecase=False):
''' Perform re.findall and return the list of matches '''
flags = 0
if ignorecase:
flags |= re.I
if multiline:
flags |= re.M
return re.findall(regex, value, flags)
def regex_search(value, regex, *args, **kwargs):
''' Perform re.search and return the list of matches or a backref '''
groups = list()
for arg in args:
if arg.startswith('\\g'):
match = re.match(r'\\g<(\S+)>', arg).group(1)
groups.append(match)
elif arg.startswith('\\'):
match = int(re.match(r'\\(\d+)', arg).group(1))
groups.append(match)
else:
raise AnsibleFilterError('Unknown argument')
flags = 0
if kwargs.get('ignorecase'):
flags |= re.I
if kwargs.get('multiline'):
flags |= re.M
match = re.search(regex, value, flags)
if match:
if not groups:
return match.group()
else:
items = list()
for item in groups:
items.append(match.group(item))
return items
def ternary(value, true_val, false_val, none_val=None):
''' value ? true_val : false_val '''
if value is None and none_val is not None:
return none_val
elif bool(value):
return true_val
else:
return false_val
def regex_escape(string, re_type='python'):
'''Escape all regular expressions special characters from STRING.'''
if re_type == 'python':
return re.escape(string)
elif re_type == 'posix_basic':
# list of BRE special chars:
# https://en.wikibooks.org/wiki/Regular_Expressions/POSIX_Basic_Regular_Expressions
return regex_replace(string, r'([].[^$*\\])', r'\\\1')
# TODO: implement posix_extended
# It's similar to, but different from python regex, which is similar to,
# but different from PCRE. It's possible that re.escape would work here.
# https://remram44.github.io/regex-cheatsheet/regex.html#programs
elif re_type == 'posix_extended':
raise AnsibleFilterError('Regex type (%s) not yet implemented' % re_type)
else:
raise AnsibleFilterError('Invalid regex type (%s)' % re_type)
def from_yaml(data):
if isinstance(data, string_types):
return yaml.safe_load(data)
return data
def from_yaml_all(data):
if isinstance(data, string_types):
return yaml.safe_load_all(data)
return data
@environmentfilter
def rand(environment, end, start=None, step=None, seed=None):
if seed is None:
r = SystemRandom()
else:
r = Random(seed)
if isinstance(end, integer_types):
if not start:
start = 0
if not step:
step = 1
return r.randrange(start, end, step)
elif hasattr(end, '__iter__'):
if start or step:
raise AnsibleFilterError('start and step can only be used with integer values')
return r.choice(end)
else:
raise AnsibleFilterError('random can only be used on sequences and integers')
def randomize_list(mylist, seed=None):
try:
mylist = list(mylist)
if seed:
r = Random(seed)
r.shuffle(mylist)
else:
shuffle(mylist)
except Exception:
pass
return mylist
def get_hash(data, hashtype='sha1'):
try: # see if hash is supported
h = hashlib.new(hashtype)
except Exception:
return None
h.update(to_bytes(data, errors='surrogate_or_strict'))
return h.hexdigest()
def get_encrypted_password(password, hashtype='sha512', salt=None, salt_size=None, rounds=None):
passlib_mapping = {
'md5': 'md5_crypt',
'blowfish': 'bcrypt',
'sha256': 'sha256_crypt',
'sha512': 'sha512_crypt',
}
hashtype = passlib_mapping.get(hashtype, hashtype)
try:
return passlib_or_crypt(password, hashtype, salt=salt, salt_size=salt_size, rounds=rounds)
except AnsibleError as e:
reraise(AnsibleFilterError, AnsibleFilterError(to_native(e), orig_exc=e), sys.exc_info()[2])
def to_uuid(string):
return str(uuid.uuid5(UUID_NAMESPACE_ANSIBLE, str(string)))
def mandatory(a, msg=None):
from jinja2.runtime import Undefined
''' Make a variable mandatory '''
if isinstance(a, Undefined):
if a._undefined_name is not None:
name = "'%s' " % to_text(a._undefined_name)
else:
name = ''
if msg is not None:
raise AnsibleFilterError(to_native(msg))
else:
raise AnsibleFilterError("Mandatory variable %s not defined." % name)
return a
def combine(*terms, **kwargs):
recursive = kwargs.get('recursive', False)
if len(kwargs) > 1 or (len(kwargs) == 1 and 'recursive' not in kwargs):
raise AnsibleFilterError("'recursive' is the only valid keyword argument")
dicts = []
for t in terms:
if isinstance(t, MutableMapping):
recursive_check_defined(t)
dicts.append(t)
elif isinstance(t, list):
recursive_check_defined(t)
dicts.append(combine(*t, **kwargs))
else:
raise AnsibleFilterError("|combine expects dictionaries, got " + repr(t))
if recursive:
return reduce(merge_hash, dicts)
else:
return dict(itertools.chain(*map(iteritems, dicts)))
def comment(text, style='plain', **kw):
# Predefined comment types
comment_styles = {
'plain': {
'decoration': '# '
},
'erlang': {
'decoration': '% '
},
'c': {
'decoration': '// '
},
'cblock': {
'beginning': '/*',
'decoration': ' * ',
'end': ' */'
},
'xml': {
'beginning': '<!--',
'decoration': ' - ',
'end': '-->'
}
}
# Pointer to the right comment type
style_params = comment_styles[style]
if 'decoration' in kw:
prepostfix = kw['decoration']
else:
prepostfix = style_params['decoration']
# Default params
p = {
'newline': '\n',
'beginning': '',
'prefix': (prepostfix).rstrip(),
'prefix_count': 1,
'decoration': '',
'postfix': (prepostfix).rstrip(),
'postfix_count': 1,
'end': ''
}
# Update default params
p.update(style_params)
p.update(kw)
# Compose substrings for the final string
str_beginning = ''
if p['beginning']:
str_beginning = "%s%s" % (p['beginning'], p['newline'])
str_prefix = ''
if p['prefix']:
if p['prefix'] != p['newline']:
str_prefix = str(
"%s%s" % (p['prefix'], p['newline'])) * int(p['prefix_count'])
else:
str_prefix = str(
"%s" % (p['newline'])) * int(p['prefix_count'])
str_text = ("%s%s" % (
p['decoration'],
# Prepend each line of the text with the decorator
text.replace(
p['newline'], "%s%s" % (p['newline'], p['decoration'])))).replace(
# Remove trailing spaces when only decorator is on the line
"%s%s" % (p['decoration'], p['newline']),
"%s%s" % (p['decoration'].rstrip(), p['newline']))
str_postfix = p['newline'].join(
[''] + [p['postfix'] for x in range(p['postfix_count'])])
str_end = ''
if p['end']:
str_end = "%s%s" % (p['newline'], p['end'])
# Return the final string
return "%s%s%s%s%s" % (
str_beginning,
str_prefix,
str_text,
str_postfix,
str_end)
def extract(item, container, morekeys=None):
from jinja2.runtime import Undefined
value = container[item]
if value is not Undefined and morekeys is not None:
if not isinstance(morekeys, list):
morekeys = [morekeys]
try:
value = reduce(lambda d, k: d[k], morekeys, value)
except KeyError:
value = Undefined()
return value
@environmentfilter
def do_groupby(environment, value, attribute):
"""Overridden groupby filter for jinja2, to address an issue with
jinja2>=2.9.0,<2.9.5 where a namedtuple was returned which
has repr that prevents ansible.template.safe_eval.safe_eval from being
able to parse and eval the data.
jinja2<2.9.0,>=2.9.5 is not affected, as <2.9.0 uses a tuple, and
>=2.9.5 uses a standard tuple repr on the namedtuple.
The adaptation here, is to run the jinja2 `do_groupby` function, and
cast all of the namedtuples to a regular tuple.
See https://github.com/ansible/ansible/issues/20098
We may be able to remove this in the future.
"""
return [tuple(t) for t in _do_groupby(environment, value, attribute)]
def b64encode(string, encoding='utf-8'):
return to_text(base64.b64encode(to_bytes(string, encoding=encoding, errors='surrogate_or_strict')))
def b64decode(string, encoding='utf-8'):
return to_text(base64.b64decode(to_bytes(string, errors='surrogate_or_strict')), encoding=encoding)
def flatten(mylist, levels=None):
ret = []
for element in mylist:
if element in (None, 'None', 'null'):
# ignore undefined items
break
elif is_sequence(element):
if levels is None:
ret.extend(flatten(element))
elif levels >= 1:
# decrement as we go down the stack
ret.extend(flatten(element, levels=(int(levels) - 1)))
else:
ret.append(element)
else:
ret.append(element)
return ret
def subelements(obj, subelements, skip_missing=False):
'''Accepts a dict or list of dicts, and a dotted accessor and produces a product
of the element and the results of the dotted accessor
>>> obj = [{"name": "alice", "groups": ["wheel"], "authorized": ["/tmp/alice/onekey.pub"]}]
>>> subelements(obj, 'groups')
[({'name': 'alice', 'groups': ['wheel'], 'authorized': ['/tmp/alice/onekey.pub']}, 'wheel')]
'''
if isinstance(obj, dict):
element_list = list(obj.values())
elif isinstance(obj, list):
element_list = obj[:]
else:
raise AnsibleFilterError('obj must be a list of dicts or a nested dict')
if isinstance(subelements, list):
subelement_list = subelements[:]
elif isinstance(subelements, string_types):
subelement_list = subelements.split('.')
else:
raise AnsibleFilterError('subelements must be a list or a string')
results = []
for element in element_list:
values = element
for subelement in subelement_list:
try:
values = values[subelement]
except KeyError:
if skip_missing:
values = []
break
raise AnsibleFilterError("could not find %r key in iterated item %r" % (subelement, values))
except TypeError:
raise AnsibleFilterError("the key %s should point to a dictionary, got '%s'" % (subelement, values))
if not isinstance(values, list):
raise AnsibleFilterError("the key %r should point to a list, got %r" % (subelement, values))
for value in values:
results.append((element, value))
return results
def dict_to_list_of_dict_key_value_elements(mydict, key_name='key', value_name='value'):
''' takes a dictionary and transforms it into a list of dictionaries,
with each having a 'key' and 'value' keys that correspond to the keys and values of the original '''
if not isinstance(mydict, Mapping):
raise AnsibleFilterError("dict2items requires a dictionary, got %s instead." % type(mydict))
ret = []
for key in mydict:
ret.append({key_name: key, value_name: mydict[key]})
return ret
def list_of_dict_key_value_elements_to_dict(mylist, key_name='key', value_name='value'):
''' takes a list of dicts with each having a 'key' and 'value' keys, and transforms the list into a dictionary,
effectively as the reverse of dict2items '''
if not is_sequence(mylist):
raise AnsibleFilterError("items2dict requires a list, got %s instead." % type(mylist))
return dict((item[key_name], item[value_name]) for item in mylist)
def random_mac(value, seed=None):
''' takes string prefix, and return it completed with random bytes
to get a complete 6 bytes MAC address '''
if not isinstance(value, string_types):
raise AnsibleFilterError('Invalid value type (%s) for random_mac (%s)' % (type(value), value))
value = value.lower()
mac_items = value.split(':')
if len(mac_items) > 5:
raise AnsibleFilterError('Invalid value (%s) for random_mac: 5 colon(:) separated items max' % value)
err = ""
for mac in mac_items:
if len(mac) == 0:
err += ",empty item"
continue
if not re.match('[a-f0-9]{2}', mac):
err += ",%s not hexa byte" % mac
err = err.strip(',')
if len(err):
raise AnsibleFilterError('Invalid value (%s) for random_mac: %s' % (value, err))
if seed is None:
r = SystemRandom()
else:
r = Random(seed)
# Generate random int between x1000000000 and xFFFFFFFFFF
v = r.randint(68719476736, 1099511627775)
# Select first n chars to complement input prefix
remain = 2 * (6 - len(mac_items))
rnd = ('%x' % v)[:remain]
return value + re.sub(r'(..)', r':\1', rnd)
class FilterModule(object):
''' Ansible core jinja2 filters '''
def filters(self):
return {
# jinja2 overrides
'groupby': do_groupby,
# base 64
'b64decode': b64decode,
'b64encode': b64encode,
# uuid
'to_uuid': to_uuid,
# json
'to_json': to_json,
'to_nice_json': to_nice_json,
'from_json': json.loads,
# yaml
'to_yaml': to_yaml,
'to_nice_yaml': to_nice_yaml,
'from_yaml': from_yaml,
'from_yaml_all': from_yaml_all,
# path
'basename': partial(unicode_wrap, os.path.basename),
'dirname': partial(unicode_wrap, os.path.dirname),
'expanduser': partial(unicode_wrap, os.path.expanduser),
'expandvars': partial(unicode_wrap, os.path.expandvars),
'realpath': partial(unicode_wrap, os.path.realpath),
'relpath': partial(unicode_wrap, os.path.relpath),
'splitext': partial(unicode_wrap, os.path.splitext),
'win_basename': partial(unicode_wrap, ntpath.basename),
'win_dirname': partial(unicode_wrap, ntpath.dirname),
'win_splitdrive': partial(unicode_wrap, ntpath.splitdrive),
# file glob
'fileglob': fileglob,
# types
'bool': to_bool,
'to_datetime': to_datetime,
# date formatting
'strftime': strftime,
# quote string for shell usage
'quote': quote,
# hash filters
# md5 hex digest of string
'md5': md5s,
# sha1 hex digest of string
'sha1': checksum_s,
# checksum of string as used by ansible for checksumming files
'checksum': checksum_s,
# generic hashing
'password_hash': get_encrypted_password,
'hash': get_hash,
# regex
'regex_replace': regex_replace,
'regex_escape': regex_escape,
'regex_search': regex_search,
'regex_findall': regex_findall,
# ? : ;
'ternary': ternary,
# random stuff
'random': rand,
'shuffle': randomize_list,
# undefined
'mandatory': mandatory,
# comment-style decoration
'comment': comment,
# debug
'type_debug': lambda o: o.__class__.__name__,
# Data structures
'combine': combine,
'extract': extract,
'flatten': flatten,
'dict2items': dict_to_list_of_dict_key_value_elements,
'items2dict': list_of_dict_key_value_elements_to_dict,
'subelements': subelements,
# Misc
'random_mac': random_mac,
}
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
12,
1603,
3478,
287,
28673,
5711,
88,
665,
74,
3478,
287,
32,
526,
5711,
88,
14,
1235,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
1300,
772,
199,
646,
21570,
199,
646,
5739,
199,
646,
8337,
199,
646,
7975,
199,
646,
2022,
199,
646,
13377,
515,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
1059,
199,
646,
984,
199,
646,
900,
199,
646,
5377,
199,
646,
8864,
199,
199,
646,
2197,
199,
504,
9143,
492,
7417,
199,
504,
2196,
492,
9571,
12,
6187,
3883,
12,
13031,
199,
199,
504,
10321,
18,
14,
4273,
492,
3734,
1541,
12,
886,
63,
16968,
465,
485,
1117,
63,
16968,
199,
199,
504,
3242,
14,
2550,
492,
13358,
12,
2622,
4131,
547,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
12,
1059,
63,
1313,
12,
3000,
63,
1313,
12,
24139,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
7114,
12,
16701,
63,
3513,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
2394,
12,
370,
63,
6106,
12,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
7882,
492,
365,
63,
4041,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
423,
7882,
63,
5819,
492,
12340,
12,
29396,
199,
504,
3242,
14,
11059,
14,
65,
1001,
492,
2622,
23069,
199,
504,
3242,
14,
11059,
14,
5963,
14,
2724,
281,
492,
2622,
28593,
199,
504,
3242,
14,
1160,
492,
9133,
63,
1074,
63,
4037,
199,
504,
3242,
14,
1208,
14,
2918,
492,
12175,
199,
504,
3242,
14,
1208,
14,
11929,
492,
986,
773,
63,
269,
63,
4997,
199,
504,
3242,
14,
1208,
14,
2227,
316,
492,
6128,
21,
83,
12,
9040,
63,
83,
199,
504,
3242,
14,
1208,
14,
2975,
492,
2649,
63,
3823,
199,
504,
3242,
14,
1208,
14,
2936,
492,
5389,
63,
2227,
199,
199,
2918,
275,
12175,
342,
199,
199,
8757,
63,
13001,
63,
8490,
275,
5377,
14,
8757,
360,
15702,
37,
22,
36,
2869,
13,
2078,
4220,
13,
18078,
33,
13,
25,
19000,
13,
1082,
969,
1184,
8980,
24,
37,
18,
37,
358,
421,
199,
318,
370,
63,
5963,
8,
65,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
5483,
3376,
12,
11779,
12701,
8864,
2344,
272,
849,
63,
1659,
63,
2487,
275,
4775,
14,
1935,
360,
885,
63,
1659,
63,
2487,
297,
488,
9,
272,
14834,
275,
8864,
14,
2724,
8,
65,
12,
19460,
281,
29,
10047,
28593,
12,
2040,
63,
2975,
29,
549,
12,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
12,
1011,
829,
9,
272,
372,
370,
63,
505,
8,
20209,
9,
421,
199,
318,
370,
63,
22746,
63,
5963,
8,
65,
12,
4363,
29,
20,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
5483,
3376,
12,
11779,
12701,
8864,
2344,
272,
14834,
275,
8864,
14,
2724,
8,
65,
12,
19460,
281,
29,
10047,
28593,
12,
4363,
29,
3724,
12,
2040,
63,
2975,
29,
549,
12,
849,
63,
1659,
63,
2487,
29,
797,
12,
1011,
829,
9,
272,
372,
370,
63,
505,
8,
20209,
9,
421,
199,
318,
370,
63,
1001,
8,
65,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
7905,
314,
574,
370,
4840,
1449,
272,
372,
2022,
14,
4180,
8,
65,
12,
843,
29,
10047,
23069,
12,
627,
589,
12,
1011,
829,
9,
421,
199,
318,
370,
63,
22746,
63,
1001,
8,
65,
12,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
5483,
3376,
12,
11779,
12701,
4840,
2344,
272,
862,
26,
267,
372,
2022,
14,
4180,
8,
65,
12,
4363,
29,
3724,
12,
4069,
63,
1612,
29,
3191,
63,
1612,
12,
17658,
2687,
23324,
7596,
17748,
843,
29,
10047,
23069,
12,
627,
589,
12,
1011,
829,
9,
272,
871,
2186,
465,
325,
26,
267,
327,
481,
5421,
370,
314,
370,
63,
1001,
2457,
267,
2929,
14,
3764,
8,
85,
7,
6005,
370,
3957,
666,
1808,
370,
63,
22746,
63,
1001,
12,
32039,
1771,
370,
370,
63,
1001,
26,
450,
83,
7,
450,
370,
63,
505,
8,
69,
430,
267,
372,
370,
63,
1001,
8,
65,
12,
627,
589,
12,
1011,
829,
9,
421,
199,
318,
370,
63,
2245,
8,
65,
304,
272,
1449,
372,
282,
2155,
367,
314,
1680,
1449,
272,
340,
282,
365,
488,
503,
1228,
8,
65,
12,
2155,
304,
267,
372,
282,
272,
340,
1228,
8,
65,
12,
1059,
63,
1313,
304,
267,
282,
275,
282,
14,
2325,
342,
272,
340,
282,
315,
661,
5066,
297,
283,
265,
297,
283,
17,
297,
283,
2052,
297,
413,
304,
267,
372,
715,
272,
372,
756,
421,
199,
318,
370,
63,
2083,
8,
875,
12,
1475,
5961,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
2349,
272,
372,
2197,
14,
2083,
14,
9866,
8,
875,
12,
1475,
9,
421,
199,
318,
14053,
8,
875,
63,
908,
12,
3499,
29,
403,
304,
272,
1449,
372,
282,
1434,
1059,
1808,
1059,
14,
1666,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
18
] |
[
334,
67,
9,
6029,
12,
1603,
3478,
287,
28673,
5711,
88,
665,
74,
3478,
287,
32,
526,
5711,
88,
14,
1235,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
1300,
772,
199,
646,
21570,
199,
646,
5739,
199,
646,
8337,
199,
646,
7975,
199,
646,
2022,
199,
646,
13377,
515,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
1059,
199,
646,
984,
199,
646,
900,
199,
646,
5377,
199,
646,
8864,
199,
199,
646,
2197,
199,
504,
9143,
492,
7417,
199,
504,
2196,
492,
9571,
12,
6187,
3883,
12,
13031,
199,
199,
504,
10321,
18,
14,
4273,
492,
3734,
1541,
12,
886,
63,
16968,
465,
485,
1117,
63,
16968,
199,
199,
504,
3242,
14,
2550,
492,
13358,
12,
2622,
4131,
547,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
492,
10849,
12,
1059,
63,
1313,
12,
3000,
63,
1313,
12,
24139,
199,
504,
3242,
14,
578,
63,
1208,
14,
4174,
14,
4912,
492,
7114,
12,
16701,
63,
3513,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
2394,
12,
370,
63,
6106,
12,
370,
63,
505,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
7882,
492,
365,
63,
4041,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
423,
7882,
63,
5819,
492,
12340,
12,
29396,
199,
504,
3242,
14,
11059,
14,
65,
1001,
492,
2622,
23069,
199,
504,
3242,
14,
11059,
14,
5963,
14,
2724,
281,
492,
2622,
28593,
199,
504,
3242,
14,
1160,
492,
9133,
63,
1074,
63,
4037,
199,
504,
3242,
14,
1208,
14,
2918,
492,
12175,
199,
504,
3242,
14,
1208,
14,
11929,
492,
986,
773,
63,
269,
63,
4997,
199,
504,
3242,
14,
1208,
14,
2227,
316,
492,
6128,
21,
83,
12,
9040,
63,
83,
199,
504,
3242,
14,
1208,
14,
2975,
492,
2649,
63,
3823,
199,
504,
3242,
14,
1208,
14,
2936,
492,
5389,
63,
2227,
199,
199,
2918,
275,
12175,
342,
199,
199,
8757,
63,
13001,
63,
8490,
275,
5377,
14,
8757,
360,
15702,
37,
22,
36,
2869,
13,
2078,
4220,
13,
18078,
33,
13,
25,
19000,
13,
1082,
969,
1184,
8980,
24,
37,
18,
37,
358,
421,
199,
318,
370,
63,
5963,
8,
65,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
5483,
3376,
12,
11779,
12701,
8864,
2344,
272,
849,
63,
1659,
63,
2487,
275,
4775,
14,
1935,
360,
885,
63,
1659,
63,
2487,
297,
488,
9,
272,
14834,
275,
8864,
14,
2724,
8,
65,
12,
19460,
281,
29,
10047,
28593,
12,
2040,
63,
2975,
29,
549,
12,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
12,
1011,
829,
9,
272,
372,
370,
63,
505,
8,
20209,
9,
421,
199,
318,
370,
63,
22746,
63,
5963,
8,
65,
12,
4363,
29,
20,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
5483,
3376,
12,
11779,
12701,
8864,
2344,
272,
14834,
275,
8864,
14,
2724,
8,
65,
12,
19460,
281,
29,
10047,
28593,
12,
4363,
29,
3724,
12,
2040,
63,
2975,
29,
549,
12,
849,
63,
1659,
63,
2487,
29,
797,
12,
1011,
829,
9,
272,
372,
370,
63,
505,
8,
20209,
9,
421,
199,
318,
370,
63,
1001,
8,
65,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
7905,
314,
574,
370,
4840,
1449,
272,
372,
2022,
14,
4180,
8,
65,
12,
843,
29,
10047,
23069,
12,
627,
589,
12,
1011,
829,
9,
421,
199,
318,
370,
63,
22746,
63,
1001,
8,
65,
12,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
12,
627,
589,
12,
1011,
829,
304,
272,
1449,
5483,
3376,
12,
11779,
12701,
4840,
2344,
272,
862,
26,
267,
372,
2022,
14,
4180,
8,
65,
12,
4363,
29,
3724,
12,
4069,
63,
1612,
29,
3191,
63,
1612,
12,
17658,
2687,
23324,
7596,
17748,
843,
29,
10047,
23069,
12,
627,
589,
12,
1011,
829,
9,
272,
871,
2186,
465,
325,
26,
267,
327,
481,
5421,
370,
314,
370,
63,
1001,
2457,
267,
2929,
14,
3764,
8,
85,
7,
6005,
370,
3957,
666,
1808,
370,
63,
22746,
63,
1001,
12,
32039,
1771,
370,
370,
63,
1001,
26,
450,
83,
7,
450,
370,
63,
505,
8,
69,
430,
267,
372,
370,
63,
1001,
8,
65,
12,
627,
589,
12,
1011,
829,
9,
421,
199,
318,
370,
63,
2245,
8,
65,
304,
272,
1449,
372,
282,
2155,
367,
314,
1680,
1449,
272,
340,
282,
365,
488,
503,
1228,
8,
65,
12,
2155,
304,
267,
372,
282,
272,
340,
1228,
8,
65,
12,
1059,
63,
1313,
304,
267,
282,
275,
282,
14,
2325,
342,
272,
340,
282,
315,
661,
5066,
297,
283,
265,
297,
283,
17,
297,
283,
2052,
297,
413,
304,
267,
372,
715,
272,
372,
756,
421,
199,
318,
370,
63,
2083,
8,
875,
12,
1475,
5961,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
2349,
272,
372,
2197,
14,
2083,
14,
9866,
8,
875,
12,
1475,
9,
421,
199,
318,
14053,
8,
875,
63,
908,
12,
3499,
29,
403,
304,
272,
1449,
372,
282,
1434,
1059,
1808,
1059,
14,
1666,
4178,
921,
4757,
14,
1548,
14,
1308,
15,
18,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
xuewei4d/scikit-learn
|
sklearn/decomposition/__init__.py
|
14
|
1396
|
"""
The :mod:`sklearn.decomposition` module includes matrix decomposition
algorithms, including among others PCA, NMF or ICA. Most of the algorithms of
this module can be regarded as dimensionality reduction techniques.
"""
from ._nmf import NMF, non_negative_factorization
from ._pca import PCA
from ._incremental_pca import IncrementalPCA
from ._kernel_pca import KernelPCA
from ._sparse_pca import SparsePCA, MiniBatchSparsePCA
from ._truncated_svd import TruncatedSVD
from ._fastica import FastICA, fastica
from ._dict_learning import (dict_learning, dict_learning_online,
sparse_encode, DictionaryLearning,
MiniBatchDictionaryLearning, SparseCoder)
from ._factor_analysis import FactorAnalysis
from ..utils.extmath import randomized_svd
from ._lda import LatentDirichletAllocation
__all__ = ['DictionaryLearning',
'FastICA',
'IncrementalPCA',
'KernelPCA',
'MiniBatchDictionaryLearning',
'MiniBatchSparsePCA',
'NMF',
'PCA',
'SparseCoder',
'SparsePCA',
'dict_learning',
'dict_learning_online',
'fastica',
'non_negative_factorization',
'randomized_svd',
'sparse_encode',
'FactorAnalysis',
'TruncatedSVD',
'LatentDirichletAllocation']
|
bsd-3-clause
|
[
624,
199,
1918,
520,
1494,
1705,
27993,
14,
31384,
64,
859,
6952,
3634,
22706,
199,
24365,
12,
5893,
16885,
11789,
25266,
12,
653,
13463,
503,
473,
3263,
14,
17536,
402,
314,
18036,
402,
199,
3749,
859,
883,
506,
1295,
12910,
465,
6240,
6712,
16773,
32414,
83,
14,
199,
624,
421,
199,
504,
13653,
10756,
70,
492,
653,
13463,
12,
2222,
63,
7371,
63,
4778,
2072,
199,
504,
13653,
19247,
492,
25266,
199,
504,
13653,
23760,
63,
19247,
492,
14684,
23852,
199,
504,
13653,
4989,
63,
19247,
492,
24901,
23852,
199,
504,
13653,
4421,
63,
19247,
492,
14531,
23852,
12,
24954,
8842,
8629,
23852,
199,
504,
13653,
19347,
63,
18675,
492,
25594,
3153,
4985,
36,
199,
504,
13653,
7015,
24027,
492,
22613,
948,
33,
12,
7377,
24027,
199,
504,
13653,
807,
63,
10546,
492,
334,
807,
63,
10546,
12,
1211,
63,
10546,
63,
15178,
12,
2490,
5178,
63,
2143,
12,
11932,
25519,
12,
2490,
24954,
8842,
11728,
25519,
12,
14531,
3034,
82,
9,
199,
504,
13653,
4778,
63,
10466,
492,
27348,
13182,
199,
504,
2508,
1208,
14,
832,
3442,
492,
2196,
1759,
63,
18675,
199,
504,
13653,
76,
983,
492,
491,
323,
343,
1341,
19683,
17794,
421,
199,
363,
452,
363,
275,
788,
11728,
25519,
297,
1779,
283,
16976,
948,
33,
297,
1779,
283,
10287,
23852,
297,
1779,
283,
14127,
23852,
297,
1779,
283,
26822,
8842,
11728,
25519,
297,
1779,
283,
26822,
8842,
8629,
23852,
297,
1779,
283,
46,
13463,
297,
1779,
283,
23852,
297,
1779,
283,
8629,
3034,
82,
297,
1779,
283,
8629,
23852,
297,
1779,
283,
807,
63,
10546,
297,
1779,
283,
807,
63,
10546,
63,
15178,
297,
1779,
283,
7015,
24027,
297,
1779,
283,
2865,
63,
7371,
63,
4778,
2072,
297,
1779,
283,
2355,
1759,
63,
18675,
297,
1779,
283,
4421,
63,
2143,
297,
1779,
283,
12666,
13182,
297,
1779,
283,
20460,
3153,
4985,
36,
297,
1779,
283,
16500,
343,
1341,
19683,
17794,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
1918,
520,
1494,
1705,
27993,
14,
31384,
64,
859,
6952,
3634,
22706,
199,
24365,
12,
5893,
16885,
11789,
25266,
12,
653,
13463,
503,
473,
3263,
14,
17536,
402,
314,
18036,
402,
199,
3749,
859,
883,
506,
1295,
12910,
465,
6240,
6712,
16773,
32414,
83,
14,
199,
624,
421,
199,
504,
13653,
10756,
70,
492,
653,
13463,
12,
2222,
63,
7371,
63,
4778,
2072,
199,
504,
13653,
19247,
492,
25266,
199,
504,
13653,
23760,
63,
19247,
492,
14684,
23852,
199,
504,
13653,
4989,
63,
19247,
492,
24901,
23852,
199,
504,
13653,
4421,
63,
19247,
492,
14531,
23852,
12,
24954,
8842,
8629,
23852,
199,
504,
13653,
19347,
63,
18675,
492,
25594,
3153,
4985,
36,
199,
504,
13653,
7015,
24027,
492,
22613,
948,
33,
12,
7377,
24027,
199,
504,
13653,
807,
63,
10546,
492,
334,
807,
63,
10546,
12,
1211,
63,
10546,
63,
15178,
12,
2490,
5178,
63,
2143,
12,
11932,
25519,
12,
2490,
24954,
8842,
11728,
25519,
12,
14531,
3034,
82,
9,
199,
504,
13653,
4778,
63,
10466,
492,
27348,
13182,
199,
504,
2508,
1208,
14,
832,
3442,
492,
2196,
1759,
63,
18675,
199,
504,
13653,
76,
983,
492,
491,
323,
343,
1341,
19683,
17794,
421,
199,
363,
452,
363,
275,
788,
11728,
25519,
297,
1779,
283,
16976,
948,
33,
297,
1779,
283,
10287,
23852,
297,
1779,
283,
14127,
23852,
297,
1779,
283,
26822,
8842,
11728,
25519,
297,
1779,
283,
26822,
8842,
8629,
23852,
297,
1779,
283,
46,
13463,
297,
1779,
283,
23852,
297,
1779,
283,
8629,
3034,
82,
297,
1779,
283,
8629,
23852,
297,
1779,
283,
807,
63,
10546,
297,
1779,
283,
807,
63,
10546,
63,
15178,
297,
1779,
283,
7015,
24027,
297,
1779,
283,
2865,
63,
7371,
63,
4778,
2072,
297,
1779,
283,
2355,
1759,
63,
18675,
297,
1779,
283,
4421,
63,
2143,
297,
1779,
283,
12666,
13182,
297,
1779,
283,
20460,
3153,
4985,
36,
297,
1779,
283,
16500,
343,
1341,
19683,
17794,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Senseg/Py4A
|
python3-alpha/extra_modules/gdata/tlslite/utils/keyfactory.py
|
48
|
8803
|
"""Factory functions for asymmetric cryptography.
@sort: generateRSAKey, parseXMLKey, parsePEMKey, parseAsPublicKey,
parseAsPrivateKey
"""
from .compat import *
from .RSAKey import RSAKey
from .Python_RSAKey import Python_RSAKey
from . import cryptomath
if cryptomath.m2cryptoLoaded:
from .OpenSSL_RSAKey import OpenSSL_RSAKey
if cryptomath.pycryptoLoaded:
from .PyCrypto_RSAKey import PyCrypto_RSAKey
# **************************************************************************
# Factory Functions for RSA Keys
# **************************************************************************
def generateRSAKey(bits, implementations=["openssl", "python"]):
"""Generate an RSA key with the specified bit length.
@type bits: int
@param bits: Desired bit length of the new key's modulus.
@rtype: L{tlslite.utils.RSAKey.RSAKey}
@return: A new RSA private key.
"""
for implementation in implementations:
if implementation == "openssl" and cryptomath.m2cryptoLoaded:
return OpenSSL_RSAKey.generate(bits)
elif implementation == "python":
return Python_RSAKey.generate(bits)
raise ValueError("No acceptable implementations")
def parseXMLKey(s, private=False, public=False, implementations=["python"]):
"""Parse an XML-format key.
The XML format used here is specific to tlslite and cryptoIDlib. The
format can store the public component of a key, or the public and
private components. For example::
<publicKey xmlns="http://trevp.net/rsa">
<n>4a5yzB8oGNlHo866CAspAC47M4Fvx58zwK8pou...
<e>Aw==</e>
</publicKey>
<privateKey xmlns="http://trevp.net/rsa">
<n>4a5yzB8oGNlHo866CAspAC47M4Fvx58zwK8pou...
<e>Aw==</e>
<d>JZ0TIgUxWXmL8KJ0VqyG1V0J3ern9pqIoB0xmy...
<p>5PreIj6z6ldIGL1V4+1C36dQFHNCQHJvW52GXc...
<q>/E/wDit8YXPCxx126zTq2ilQ3IcW54NJYyNjiZ...
<dP>mKc+wX8inDowEH45Qp4slRo1YveBgExKPROu6...
<dQ>qDVKtBz9lk0shL5PR3ickXDgkwS576zbl2ztB...
<qInv>j6E8EA7dNsTImaXexAmLA1DoeArsYeFAInr...
</privateKey>
@type s: str
@param s: A string containing an XML public or private key.
@type private: bool
@param private: If True, a L{SyntaxError} will be raised if the private
key component is not present.
@type public: bool
@param public: If True, the private key component (if present) will be
discarded, so this function will always return a public key.
@rtype: L{tlslite.utils.RSAKey.RSAKey}
@return: An RSA key.
@raise SyntaxError: If the key is not properly formatted.
"""
for implementation in implementations:
if implementation == "python":
key = Python_RSAKey.parseXML(s)
break
else:
raise ValueError("No acceptable implementations")
return _parseKeyHelper(key, private, public)
#Parse as an OpenSSL or Python key
def parsePEMKey(s, private=False, public=False, passwordCallback=None,
implementations=["openssl", "python"]):
"""Parse a PEM-format key.
The PEM format is used by OpenSSL and other tools. The
format is typically used to store both the public and private
components of a key. For example::
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDYscuoMzsGmW0pAYsmyHltxB2TdwHS0dImfjCMfaSDkfLdZY5+
dOWORVns9etWnr194mSGA1F0Pls/VJW8+cX9+3vtJV8zSdANPYUoQf0TP7VlJxkH
dSRkUbEoz5bAAs/+970uos7n7iXQIni+3erUTdYEk2iWnMBjTljfgbK/dQIDAQAB
AoGAJHoJZk75aKr7DSQNYIHuruOMdv5ZeDuJvKERWxTrVJqE32/xBKh42/IgqRrc
esBN9ZregRCd7YtxoL+EVUNWaJNVx2mNmezEznrc9zhcYUrgeaVdFO2yBF1889zO
gCOVwrO8uDgeyj6IKa25H6c1N13ih/o7ZzEgWbGG+ylU1yECQQDv4ZSJ4EjSh/Fl
aHdz3wbBa/HKGTjC8iRy476Cyg2Fm8MZUe9Yy3udOrb5ZnS2MTpIXt5AF3h2TfYV
VoFXIorjAkEA50FcJmzT8sNMrPaV8vn+9W2Lu4U7C+K/O2g1iXMaZms5PC5zV5aV
CKXZWUX1fq2RaOzlbQrpgiolhXpeh8FjxwJBAOFHzSQfSsTNfttp3KUpU0LbiVvv
i+spVSnA0O4rq79KpVNmK44Mq67hsW1P11QzrzTAQ6GVaUBRv0YS061td1kCQHnP
wtN2tboFR6lABkJDjxoGRvlSt4SOPr7zKGgrWjeiuTZLHXSAnCY+/hr5L9Q3ZwXG
6x6iBdgLjVIe4BZQNtcCQQDXGv/gWinCNTN3MPWfTW/RGzuMYVmyBFais0/VrgdH
h1dLpztmpQqfyH/zrBXQ9qL/zR4ojS6XYneO/U18WpEe
-----END RSA PRIVATE KEY-----
To generate a key like this with OpenSSL, run::
openssl genrsa 2048 > key.pem
This format also supports password-encrypted private keys. TLS
Lite can only handle password-encrypted private keys when OpenSSL
and M2Crypto are installed. In this case, passwordCallback will be
invoked to query the user for the password.
@type s: str
@param s: A string containing a PEM-encoded public or private key.
@type private: bool
@param private: If True, a L{SyntaxError} will be raised if the
private key component is not present.
@type public: bool
@param public: If True, the private key component (if present) will
be discarded, so this function will always return a public key.
@type passwordCallback: callable
@param passwordCallback: This function will be called, with no
arguments, if the PEM-encoded private key is password-encrypted.
The callback should return the password string. If the password is
incorrect, SyntaxError will be raised. If no callback is passed
and the key is password-encrypted, a prompt will be displayed at
the console.
@rtype: L{tlslite.utils.RSAKey.RSAKey}
@return: An RSA key.
@raise SyntaxError: If the key is not properly formatted.
"""
for implementation in implementations:
if implementation == "openssl" and cryptomath.m2cryptoLoaded:
key = OpenSSL_RSAKey.parse(s, passwordCallback)
break
elif implementation == "python":
key = Python_RSAKey.parsePEM(s)
break
else:
raise ValueError("No acceptable implementations")
return _parseKeyHelper(key, private, public)
def _parseKeyHelper(key, private, public):
if private:
if not key.hasPrivateKey():
raise SyntaxError("Not a private key!")
if public:
return _createPublicKey(key)
if private:
if hasattr(key, "d"):
return _createPrivateKey(key)
else:
return key
return key
def parseAsPublicKey(s):
"""Parse an XML or PEM-formatted public key.
@type s: str
@param s: A string containing an XML or PEM-encoded public or private key.
@rtype: L{tlslite.utils.RSAKey.RSAKey}
@return: An RSA public key.
@raise SyntaxError: If the key is not properly formatted.
"""
try:
return parsePEMKey(s, public=True)
except:
return parseXMLKey(s, public=True)
def parsePrivateKey(s):
"""Parse an XML or PEM-formatted private key.
@type s: str
@param s: A string containing an XML or PEM-encoded private key.
@rtype: L{tlslite.utils.RSAKey.RSAKey}
@return: An RSA private key.
@raise SyntaxError: If the key is not properly formatted.
"""
try:
return parsePEMKey(s, private=True)
except:
return parseXMLKey(s, private=True)
def _createPublicKey(key):
"""
Create a new public key. Discard any private component,
and return the most efficient key possible.
"""
if not isinstance(key, RSAKey):
raise AssertionError()
return _createPublicRSAKey(key.n, key.e)
def _createPrivateKey(key):
"""
Create a new private key. Return the most efficient key possible.
"""
if not isinstance(key, RSAKey):
raise AssertionError()
if not key.hasPrivateKey():
raise AssertionError()
return _createPrivateRSAKey(key.n, key.e, key.d, key.p, key.q, key.dP,
key.dQ, key.qInv)
def _createPublicRSAKey(n, e, implementations = ["openssl", "pycrypto",
"python"]):
for implementation in implementations:
if implementation == "openssl" and cryptomath.m2cryptoLoaded:
return OpenSSL_RSAKey(n, e)
elif implementation == "pycrypto" and cryptomath.pycryptoLoaded:
return PyCrypto_RSAKey(n, e)
elif implementation == "python":
return Python_RSAKey(n, e)
raise ValueError("No acceptable implementations")
def _createPrivateRSAKey(n, e, d, p, q, dP, dQ, qInv,
implementations = ["pycrypto", "python"]):
for implementation in implementations:
if implementation == "pycrypto" and cryptomath.pycryptoLoaded:
return PyCrypto_RSAKey(n, e, d, p, q, dP, dQ, qInv)
elif implementation == "python":
return Python_RSAKey(n, e, d, p, q, dP, dQ, qInv)
raise ValueError("No acceptable implementations")
|
apache-2.0
|
[
624,
2927,
3423,
367,
465,
12828,
5165,
27617,
14,
199,
32,
3191,
26,
3550,
12115,
1197,
12,
2198,
4317,
1197,
12,
2198,
24160,
1197,
12,
2198,
2822,
26238,
12,
199,
1122,
2822,
31757,
199,
624,
199,
199,
504,
1275,
5819,
492,
627,
199,
199,
504,
1275,
12115,
1197,
492,
18471,
1197,
199,
504,
1275,
4718,
63,
12115,
1197,
492,
2018,
63,
12115,
1197,
199,
504,
1275,
492,
13230,
3442,
199,
199,
692,
13230,
3442,
14,
77,
18,
10316,
19757,
26,
272,
687,
1275,
22791,
63,
12115,
1197,
492,
14296,
63,
12115,
1197,
199,
199,
692,
13230,
3442,
14,
647,
10316,
19757,
26,
272,
687,
1275,
2713,
17134,
63,
12115,
1197,
492,
1611,
17134,
63,
12115,
1197,
199,
199,
3,
1011,
14355,
199,
3,
23616,
17471,
367,
18471,
17276,
199,
3,
1011,
14355,
199,
199,
318,
3550,
12115,
1197,
8,
5609,
12,
12591,
6270,
14837,
401,
298,
1548,
21473,
272,
408,
6864,
376,
18471,
790,
543,
314,
2013,
4546,
2582,
14,
339,
768,
466,
5821,
26,
1109,
272,
768,
635,
5821,
26,
1487,
5381,
4546,
2582,
402,
314,
892,
790,
1159,
3413,
15909,
14,
339,
768,
4500,
26,
491,
91,
32449,
14,
1208,
14,
12115,
1197,
14,
12115,
1197,
93,
272,
768,
1107,
26,
437,
892,
18471,
5726,
790,
14,
272,
408,
272,
367,
4514,
315,
12591,
26,
267,
340,
4514,
508,
298,
14837,
2,
436,
13230,
3442,
14,
77,
18,
10316,
19757,
26,
288,
372,
14296,
63,
12115,
1197,
14,
4208,
8,
5609,
9,
267,
916,
4514,
508,
298,
1548,
582,
288,
372,
2018,
63,
12115,
1197,
14,
4208,
8,
5609,
9,
272,
746,
1722,
480,
1944,
14712,
12591,
531,
199,
199,
318,
2198,
4317,
1197,
8,
83,
12,
5726,
29,
797,
12,
4575,
29,
797,
12,
12591,
6270,
1548,
21473,
272,
408,
4003,
376,
4692,
13,
908,
790,
14,
339,
710,
4692,
1475,
1202,
2348,
365,
2488,
370,
15142,
5333,
436,
13230,
998,
773,
14,
221,
710,
272,
1475,
883,
3877,
314,
4575,
3931,
402,
282,
790,
12,
503,
314,
4575,
436,
272,
5726,
7323,
14,
221,
2104,
2893,
447,
398,
665,
3455,
1197,
9604,
628,
1014,
921,
84,
4964,
80,
14,
846,
15,
13487,
1743,
288,
665,
78,
30,
20,
65,
21,
19873,
34,
24,
79,
15306,
76,
17810,
13465,
3263,
681,
1348,
2417,
45,
20,
38,
18843,
2010,
90,
87,
43,
24,
555,
85,
1396,
288,
665,
69,
30,
26917,
389,
1108,
69,
30,
267,
3068,
3455,
1197,
30,
398,
665,
4239,
1197,
9604,
628,
1014,
921,
84,
4964,
80,
14,
846,
15,
13487,
1743,
288,
665,
78,
30,
20,
65,
21,
19873,
34,
24,
79,
15306,
76,
17810,
13465,
3263,
681,
1348,
2417,
45,
20,
38,
18843,
2010,
90,
87,
43,
24,
555,
85,
1396,
288,
665,
69,
30,
26917,
389,
1108,
69,
30,
288,
665,
68,
30,
42,
58,
16,
13247,
71,
53,
88,
16783,
77,
44,
24,
43,
42,
16,
54,
81,
89,
39,
17,
54,
16,
42,
19,
27569,
25,
26295,
16512,
34,
16,
88,
1662,
1396,
288,
665,
80,
30,
21,
2398,
41,
74,
22,
90,
22,
1447,
1277,
44,
17,
54,
20,
11,
17,
35,
1344,
68,
49,
32259,
6389,
49,
22313,
86,
55,
2528,
39,
56,
67,
1396,
288,
665,
81,
12202,
37,
15,
87,
36,
390,
24,
16936,
4222,
2154,
7957,
90,
52,
81,
18,
382,
49,
19,
41,
67,
55,
1477,
46,
42,
30694,
46,
8047,
58,
1396,
288,
665,
68,
48,
30,
77,
43,
67,
11,
87,
56,
24,
262,
36,
583,
24948,
2322,
49,
80,
20,
2482,
3863,
17,
57,
432,
23571,
920,
43,
2514,
85,
22,
1396,
288,
665,
68,
49,
30,
81,
6741,
43,
84,
34,
90,
25,
23333,
16,
609,
44,
21,
3311,
19,
2000,
18184,
71,
829,
51,
12255,
90,
3345,
18,
90,
84,
34,
1396,
288,
665,
81,
14883,
30,
74,
22,
37,
24,
11765,
23,
68,
2438,
13247,
391,
56,
476,
24566,
5837,
17,
2585,
69,
1596,
83,
57,
69,
2078,
607,
82,
1396,
267,
3068,
4239,
1197,
30,
339,
768,
466,
308,
26,
620,
272,
768,
635,
308,
26,
437,
1059,
3035,
376,
4692,
4575,
503,
5726,
790,
14,
339,
768,
466,
5726,
26,
2155,
272,
768,
635,
5726,
26,
982,
715,
12,
282,
491,
91,
9294,
93,
911,
506,
4915,
340,
314,
5726,
272,
790,
3931,
365,
440,
3451,
14,
339,
768,
466,
4575,
26,
2155,
272,
768,
635,
4575,
26,
982,
715,
12,
314,
5726,
790,
3931,
334,
692,
3451,
9,
911,
506,
272,
22002,
12,
880,
642,
805,
911,
3544,
372,
282,
4575,
790,
14,
339,
768,
4500,
26,
491,
91,
32449,
14,
1208,
14,
12115,
1197,
14,
12115,
1197,
93,
272,
768,
1107,
26,
1626,
18471,
790,
14,
339,
768,
3730,
12053,
26,
982,
314,
790,
365,
440,
7684,
7871,
14,
272,
408,
272,
367,
4514,
315,
12591,
26,
267,
340,
4514,
508,
298,
1548,
582,
288,
790,
275,
2018,
63,
12115,
1197,
14,
1122,
4317,
8,
83,
9,
288,
2059,
272,
587,
26,
267,
746,
1722,
480,
1944,
14712,
12591,
531,
339,
372,
485,
1122,
1197,
4433,
8,
498,
12,
5726,
12,
4575,
9,
199,
199,
3,
4003,
465,
376,
14296,
503,
2018,
790,
199,
318,
2198,
24160,
1197,
8,
83,
12,
5726,
29,
797,
12,
4575,
29,
797,
12,
2505,
2806,
29,
403,
12,
355,
12591,
6270,
14837,
401,
298,
1548,
21473,
272,
408,
4003,
282,
25957,
13,
908,
790,
14,
339,
710,
25957,
1475,
365,
1202,
701,
14296,
436,
1163,
7249,
14,
221,
710,
272,
1475,
365,
13609,
1202,
370,
3877,
3865,
314,
4575,
436,
5726,
272,
7323,
402,
282,
790,
14,
221,
2104,
2893,
447,
10817,
9063,
15947,
18471,
28644,
1951,
9301,
9858,
267,
603,
41,
948,
56,
49,
2100,
2276,
12780,
71,
49,
11446,
551,
13780,
23332,
83,
39,
77,
55,
16,
80,
3448,
83,
1662,
40,
76,
2347,
34,
18,
52,
10772,
15467,
16,
68,
41,
11821,
74,
9249,
667,
3693,
16791,
30251,
58,
57,
21,
11,
267,
366,
47,
6746,
54,
561,
25,
386,
55,
7865,
10860,
77,
4254,
33,
17,
38,
16,
48,
478,
15,
54,
42,
55,
24,
11,
67,
56,
25,
11,
19,
5941,
42,
54,
24,
90,
51,
68,
879,
4521,
53,
79,
49,
70,
16,
6495,
23
] |
[
2927,
3423,
367,
465,
12828,
5165,
27617,
14,
199,
32,
3191,
26,
3550,
12115,
1197,
12,
2198,
4317,
1197,
12,
2198,
24160,
1197,
12,
2198,
2822,
26238,
12,
199,
1122,
2822,
31757,
199,
624,
199,
199,
504,
1275,
5819,
492,
627,
199,
199,
504,
1275,
12115,
1197,
492,
18471,
1197,
199,
504,
1275,
4718,
63,
12115,
1197,
492,
2018,
63,
12115,
1197,
199,
504,
1275,
492,
13230,
3442,
199,
199,
692,
13230,
3442,
14,
77,
18,
10316,
19757,
26,
272,
687,
1275,
22791,
63,
12115,
1197,
492,
14296,
63,
12115,
1197,
199,
199,
692,
13230,
3442,
14,
647,
10316,
19757,
26,
272,
687,
1275,
2713,
17134,
63,
12115,
1197,
492,
1611,
17134,
63,
12115,
1197,
199,
199,
3,
1011,
14355,
199,
3,
23616,
17471,
367,
18471,
17276,
199,
3,
1011,
14355,
199,
199,
318,
3550,
12115,
1197,
8,
5609,
12,
12591,
6270,
14837,
401,
298,
1548,
21473,
272,
408,
6864,
376,
18471,
790,
543,
314,
2013,
4546,
2582,
14,
339,
768,
466,
5821,
26,
1109,
272,
768,
635,
5821,
26,
1487,
5381,
4546,
2582,
402,
314,
892,
790,
1159,
3413,
15909,
14,
339,
768,
4500,
26,
491,
91,
32449,
14,
1208,
14,
12115,
1197,
14,
12115,
1197,
93,
272,
768,
1107,
26,
437,
892,
18471,
5726,
790,
14,
272,
408,
272,
367,
4514,
315,
12591,
26,
267,
340,
4514,
508,
298,
14837,
2,
436,
13230,
3442,
14,
77,
18,
10316,
19757,
26,
288,
372,
14296,
63,
12115,
1197,
14,
4208,
8,
5609,
9,
267,
916,
4514,
508,
298,
1548,
582,
288,
372,
2018,
63,
12115,
1197,
14,
4208,
8,
5609,
9,
272,
746,
1722,
480,
1944,
14712,
12591,
531,
199,
199,
318,
2198,
4317,
1197,
8,
83,
12,
5726,
29,
797,
12,
4575,
29,
797,
12,
12591,
6270,
1548,
21473,
272,
408,
4003,
376,
4692,
13,
908,
790,
14,
339,
710,
4692,
1475,
1202,
2348,
365,
2488,
370,
15142,
5333,
436,
13230,
998,
773,
14,
221,
710,
272,
1475,
883,
3877,
314,
4575,
3931,
402,
282,
790,
12,
503,
314,
4575,
436,
272,
5726,
7323,
14,
221,
2104,
2893,
447,
398,
665,
3455,
1197,
9604,
628,
1014,
921,
84,
4964,
80,
14,
846,
15,
13487,
1743,
288,
665,
78,
30,
20,
65,
21,
19873,
34,
24,
79,
15306,
76,
17810,
13465,
3263,
681,
1348,
2417,
45,
20,
38,
18843,
2010,
90,
87,
43,
24,
555,
85,
1396,
288,
665,
69,
30,
26917,
389,
1108,
69,
30,
267,
3068,
3455,
1197,
30,
398,
665,
4239,
1197,
9604,
628,
1014,
921,
84,
4964,
80,
14,
846,
15,
13487,
1743,
288,
665,
78,
30,
20,
65,
21,
19873,
34,
24,
79,
15306,
76,
17810,
13465,
3263,
681,
1348,
2417,
45,
20,
38,
18843,
2010,
90,
87,
43,
24,
555,
85,
1396,
288,
665,
69,
30,
26917,
389,
1108,
69,
30,
288,
665,
68,
30,
42,
58,
16,
13247,
71,
53,
88,
16783,
77,
44,
24,
43,
42,
16,
54,
81,
89,
39,
17,
54,
16,
42,
19,
27569,
25,
26295,
16512,
34,
16,
88,
1662,
1396,
288,
665,
80,
30,
21,
2398,
41,
74,
22,
90,
22,
1447,
1277,
44,
17,
54,
20,
11,
17,
35,
1344,
68,
49,
32259,
6389,
49,
22313,
86,
55,
2528,
39,
56,
67,
1396,
288,
665,
81,
12202,
37,
15,
87,
36,
390,
24,
16936,
4222,
2154,
7957,
90,
52,
81,
18,
382,
49,
19,
41,
67,
55,
1477,
46,
42,
30694,
46,
8047,
58,
1396,
288,
665,
68,
48,
30,
77,
43,
67,
11,
87,
56,
24,
262,
36,
583,
24948,
2322,
49,
80,
20,
2482,
3863,
17,
57,
432,
23571,
920,
43,
2514,
85,
22,
1396,
288,
665,
68,
49,
30,
81,
6741,
43,
84,
34,
90,
25,
23333,
16,
609,
44,
21,
3311,
19,
2000,
18184,
71,
829,
51,
12255,
90,
3345,
18,
90,
84,
34,
1396,
288,
665,
81,
14883,
30,
74,
22,
37,
24,
11765,
23,
68,
2438,
13247,
391,
56,
476,
24566,
5837,
17,
2585,
69,
1596,
83,
57,
69,
2078,
607,
82,
1396,
267,
3068,
4239,
1197,
30,
339,
768,
466,
308,
26,
620,
272,
768,
635,
308,
26,
437,
1059,
3035,
376,
4692,
4575,
503,
5726,
790,
14,
339,
768,
466,
5726,
26,
2155,
272,
768,
635,
5726,
26,
982,
715,
12,
282,
491,
91,
9294,
93,
911,
506,
4915,
340,
314,
5726,
272,
790,
3931,
365,
440,
3451,
14,
339,
768,
466,
4575,
26,
2155,
272,
768,
635,
4575,
26,
982,
715,
12,
314,
5726,
790,
3931,
334,
692,
3451,
9,
911,
506,
272,
22002,
12,
880,
642,
805,
911,
3544,
372,
282,
4575,
790,
14,
339,
768,
4500,
26,
491,
91,
32449,
14,
1208,
14,
12115,
1197,
14,
12115,
1197,
93,
272,
768,
1107,
26,
1626,
18471,
790,
14,
339,
768,
3730,
12053,
26,
982,
314,
790,
365,
440,
7684,
7871,
14,
272,
408,
272,
367,
4514,
315,
12591,
26,
267,
340,
4514,
508,
298,
1548,
582,
288,
790,
275,
2018,
63,
12115,
1197,
14,
1122,
4317,
8,
83,
9,
288,
2059,
272,
587,
26,
267,
746,
1722,
480,
1944,
14712,
12591,
531,
339,
372,
485,
1122,
1197,
4433,
8,
498,
12,
5726,
12,
4575,
9,
199,
199,
3,
4003,
465,
376,
14296,
503,
2018,
790,
199,
318,
2198,
24160,
1197,
8,
83,
12,
5726,
29,
797,
12,
4575,
29,
797,
12,
2505,
2806,
29,
403,
12,
355,
12591,
6270,
14837,
401,
298,
1548,
21473,
272,
408,
4003,
282,
25957,
13,
908,
790,
14,
339,
710,
25957,
1475,
365,
1202,
701,
14296,
436,
1163,
7249,
14,
221,
710,
272,
1475,
365,
13609,
1202,
370,
3877,
3865,
314,
4575,
436,
5726,
272,
7323,
402,
282,
790,
14,
221,
2104,
2893,
447,
10817,
9063,
15947,
18471,
28644,
1951,
9301,
9858,
267,
603,
41,
948,
56,
49,
2100,
2276,
12780,
71,
49,
11446,
551,
13780,
23332,
83,
39,
77,
55,
16,
80,
3448,
83,
1662,
40,
76,
2347,
34,
18,
52,
10772,
15467,
16,
68,
41,
11821,
74,
9249,
667,
3693,
16791,
30251,
58,
57,
21,
11,
267,
366,
47,
6746,
54,
561,
25,
386,
55,
7865,
10860,
77,
4254,
33,
17,
38,
16,
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