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
|
|---|---|---|---|---|---|---|---|---|
gnarula/eden_deployment
|
modules/savage/graphics/shapes.py
|
24
|
24007
|
from base import Element, PositionableElement, BoxElement
from group import Grouping
from defs import Symbol, Use
from utils import ViewBox
from ..utils.struct import Vector as V, Matrix
from math import sqrt, cos, sin
from copy import deepcopy
class Circle (PositionableElement):
def __init__ (self, **attr):
PositionableElement.__init__ (self, name = 'circle', **attr)
if attr.has_key ('radius'):
self.radius = attr['radius']
else:
self.radius = 0.0
def size (self, value):
self.radius = value
def setSVG (self):
pos = V (self.x, self.y)
self.applyTransform (pos)
attr = PositionableElement.setSVG (self)
attr.update ([('cx', pos.x),
('cy', pos.y),
('r', self.radius)])
return attr
class PathElement:
def matrix (self):
return Matrix (3, 1, [self.x, self.y, 1])
class AnchorElement (PathElement):
def __init__ (self, x, y):
self.x = x
self.y = y
def __str__ (self):
return ' '.join (['M'] + map (str, [self.x, self.y]))
class LinearElement (PathElement):
def __init__ (self, x, y):
self.x = x
self.y = y
def __str__ (self):
return ' '.join (['L'] + map (str, [self.x, self.y]))
class CloseElement (PathElement):
def __init__ (self):
pass
def __str__ (self):
return 'Z'
class Path (PositionableElement):
def __init__ (self, **attr):
PositionableElement.__init__ (self, name = 'path', **attr)
if attr.has_key ('transform'):
self.postTransform = attr['transform']
else:
self.postTransform = None
self.elements = []
self.closed = False
def line (self, x, y):
self.elements.append (LinearElement (x, y))
def move (self, x, y):
self.elements.append (AnchorElement (x, y))
def close (self):
self.closed = True
def open (self):
self.closed = False
def setSVG (self):
attr = Element.setSVG (self)
elements = deepcopy (self.elements)
self.applyTransform (*elements)
strings = map (str, elements)
if self.closed:
strings.append (str (CloseElement ()))
attr.update ([('d', ' '.join (strings)), ('transform', self.postTransform)])
return attr
class CDATAPath (Element):
def __init__ (self, **attr):
Element.__init__ (self, name='path', **attr)
if attr.has_key ('data'):
self.data = attr['data']
else:
self.data = None
if attr.has_key ('transform'):
self.postTransform = attr['transform']
else:
self.postTransform = None
def setSVG (self):
attr = Element.setSVG (self)
attr.update ([('d', self.data), ('transform', self.postTransform)])
return attr
class Rectangle (BoxElement):
def __init__ (self, **attr):
BoxElement.__init__ (self, name = 'rect', **attr)
if attr.has_key ('width'):
self.width = float (attr['width'])
else:
self.width = None
if attr.has_key ('height'):
self.height = float (attr['height'])
else:
self.height = None
if attr.has_key ('absoluteSize'):
self.absoluteSize = bool (attr['absoluteSize'])
else:
self.absoluteSize = False
if attr.has_key ('worldDeltaX'):
self.worldDeltaX = float (attr['worldDeltaX'])
else:
self.worldDeltaX = 0.0
if attr.has_key ('worldDeltaY'):
self.worldDeltaY = float (attr['worldDeltaY'])
else:
self.worldDeltaY = 0.0
def setSVG (self):
attr = BoxElement.setSVG (self)
if not self.absoluteSize:
points = self.calulateBox (self.x, self.y, self.width, self.height)
else:
point = V (self.x, self.y)
self.applyTransform (point)
points = {'x': point.x, 'y': point.y,
'width': self.width, 'height': self.height}
points['x'] += self.worldDeltaX
points['y'] += self.worldDeltaY
attr.update (points)
return attr
class Square (Rectangle):
def __init__ (self, width, **attr):
attr.update ([('width', width), ('height', width)])
Rectangle.__init__ (self, **attr)
def size (self, value):
self.width = value
self.height = value
class Line (PositionableElement):
def __init__ (self, **attr):
PositionableElement.__init__ (self, name = 'line', **attr)
if attr.has_key ('point1'):
self.point1 = V (*attr['point1'])
else:
self.point1 = V (0.0, 0.0)
if attr.has_key ('point2'):
self.point2 = V (*attr['point2'])
else:
self.point2 = V (0.0, 0.0)
def setSVG (self):
attr = PositionableElement.setSVG (self)
point1 = V (self.point1.x + self.x, self.point1.y + self.y)
point2 = V (self.point2.x + self.x, self.point2.y + self.y)
self.applyTransform (point1, point2)
attr.update ([('x1', point1.x),
('y1', point1.y),
('x2', point2.x),
('y2', point2.y)])
return attr
class Sector (PositionableElement):
def __init__ (self, radius, start, delta, **attr):
PositionableElement.__init__ (self, name = 'path', **attr)
self.radius = radius
if delta < 0:
delta = -delta
start -= delta
self.point1 = self.arcPoint (start)
self.point2 = self.arcPoint (start + delta)
def arcPoint (self, rads):
x = self.radius * cos (rads)
y = self.radius * sin (rads)
return V (x, y)
def setSVG (self):
attr = PositionableElement.setSVG (self)
pos = V (self.x, self.y)
o = pos
p1 = self.point1 + pos
p2 = self.point2 + pos
self.applyTransform (o, p1, p2)
d1 = 'M ' + str (o)
d2 = 'L ' + str (p1)
d3 = 'A ' + str(self.radius) + ' ' + str(self.radius) + ' 1 0 0 '
d3 += str(p2)
d4 = 'Z'
data = ' '.join ([d1, d2, d3, d4])
attr.update ([('d', data)])
return attr
class Text (Grouping, PositionableElement):
def __init__ (self, **attr):
Grouping.__init__ (self, **attr)
PositionableElement.__init__ (self, **attr)
if attr.has_key ('text'):
self.text = attr['text']
else:
self.text = ''
if attr.has_key ('textHeight'):
self.textHeight = attr['textHeight']
else:
self.textHeight = 10
if attr.has_key ('verticalAnchor'):
self.verticalAnchor = attr['verticalAnchor']
else:
self.verticalAnchor = 'top'
if attr.has_key ('horizontalAnchor'):
self.horizontalAnchor = attr['horizontalAnchor']
else:
self.horizontalAnchor = 'left'
self.width = 0
self.height = 0
self.createText ()
def createText (self):
xpos = self.x
for char in self.text:
if LetterDict.has_key (char):
letter = LetterDict[char]
id = char
s = Symbol (id = id, viewBox = ViewBox (0, -800, letter[0], 250))
p = CDATAPath (data=letter[1], transform = 'scale(1,-1)')
p.style.strokeColor = 'black'
s.draw (p)
self.createDef (s)
w = self.textHeight * (letter[0] / 1050.0)
self.draw (Letter (href = ('#' + id),
x = xpos,
y = self.y,
width = w,
height = self.textHeight))
xpos += w
else:
xpos += self.textHeight * (300.0 / 1050.0)
self.width = xpos - self.x
self.height = self.textHeight
self.applyAnchors ()
def move (self, dx, dy):
for char in self:
char.x += dx
char.y += dy
def applyAnchors (self):
dh = 0
hv = 0
if self.horizontalAnchor == 'left':
dh = 0
elif self.horizontalAnchor == 'right':
dh = - self.width
elif self.horizontalAnchor == 'center':
dh = - (self.width / 2.0)
if self.verticalAnchor == 'top':
dv = 0
elif self.verticalAnchor == 'bottom':
dv = - self.height
elif self.verticalAnchor == 'middle':
dv = - (self.height / 2.0)
for char in self:
char.dh += dh
char.dv += dv
def setText (self, text):
self.clear ()
self.text = text
self.createText ()
@staticmethod
def textWidth (text, height):
width = 0.0
for char in text:
if LetterDict.has_key (char):
w = LetterDict[char][0]
letterWidth = height * (w / 1050.0)
width += letterWidth
else:
width += height * (300.0 / 1050.0)
return width
class Letter (Use):
def __init__ (self, **attr):
Use.__init__ (self, **attr)
if attr.has_key ('dh'):
self.dh = attr['dh']
else:
self.dh = 0
if attr.has_key ('dv'):
self.dv = attr['dv']
else:
self.dv = 0
def setSVG (self):
p = V (self.x, self.y)
self.applyTransform (p)
return {'x': p.x + self.dh,
'y': p.y + self.dv,
'width': self.width,
'height': self.height,
'xlink:href': self.href,
}
LetterDict = {
"!": (278,"M208 729V391L186 168H147L125 391V729H208ZM208 104V0H124V104H208Z"),
"#": (556,"M485 697L449 501H542V433H436L405 259H510V191H393L354 -20H278L316 191H192L153 -20H77L115 191H14V259H128L159 433H51V501H172L208 697H284L248 501H373L408 697H485ZM360 433H236L204 259H329L360 433Z"),
"$": (556,"M518 195Q518 99 463 42T302 -23V-126H243V-23Q142 -16 88 39T33 191V208H112Q114 188 114 182T118 157T124 131T134 108T150 86T172 69T203 55T243 46V318Q150 346 117 370Q46 421 46 516Q46 601 96 652T243 716V770H302V716Q393 709 444 657T496 519H417Q416 574 384 609T302 646V397Q306 396 332 389T372 377T411 361T452 337T485 304T510 256T518 195ZM243 405V645Q187 637 157 606T127 526Q127 436 243 405ZM302 46Q369 54 402 91T436 183Q436 232 408 259T302 309V46Z"),
"%": (889,"M199 685Q271 685 320 635T370 512Q370 443 320 393T200 343T80 393T29 514T79 634T199 685ZM199 615Q158 615 128 586T98 514Q98 473 128 443T200 413Q241 413 271 442T301 513Q301 556 272 585T199 615ZM609 709H675L280 -20H214L609 709ZM688 322Q760 322 809 272T859 150Q859 81 809 31T689 -19Q618 -19 568 31T518 152T568 272T688 322ZM688 252Q647 252 617 223T587 152Q587 110 617 81T689 51Q730 51 760 80T790 150Q790 193 761 222T688 252Z"),
"(": (333,"M236 729H291Q154 508 154 259Q154 11 291 -212H236Q161 -114 117 13T73 259T117 504T236 729Z"),
")": (333,"M93 -212H38Q175 9 175 258Q175 506 38 729H93Q168 631 212 504T256 258T212 13T93 -212Z"),
"*": (389,"M160 729H223L218 617L324 655L343 596L235 566L305 477L254 441L192 534L129 441L79 477L148 566L40 596L59 655L165 617L160 729Z"),
"+": (584,"M534 267V197H327V-10H257V197H50V267H257V474H327V267H534Z"),
",": (278,"M87 104H192V-16Q192 -147 87 -147V-109Q122 -108 134 -89T147 -18V0H87V104Z"),
"-": (333,"M284 312V240H46V312H284Z"),
".": (278,"M191 104V0H87V104H191Z"),
"/": (278,"M229 729H284L47 -20H-8L229 729Z"),
"0": (556,"M43 343Q43 432 58 500T96 606T151 669T212 701T275 709Q507 709 507 337Q507 162 448 70T275 -23Q161 -23 102 70T43 343ZM417 631T275 631T133 342Q133 50 273 50Q347 50 382 122T417 345Q417 631 275 631Z"),
"1": (556,"M259 505H102V568Q204 581 235 604T289 709H347V0H259V505Z"),
"2": (556,"M50 463Q57 709 284 709Q385 709 448 651T511 501Q511 369 361 287L261 233Q196 198 168 165T133 87H506V0H34Q40 117 81 180T233 307L325 359Q421 414 421 499Q421 556 381 594T281 632Q148 632 138 463H50Z"),
"3": (556,"M270 632Q194 632 166 591T135 480H47Q52 709 269 709Q370 709 427 657T485 514Q485 406 386 367Q450 345 478 306T506 198Q506 97 441 37T266 -23Q48 -23 32 206H120Q125 129 161 92T269 55Q338 55 377 92T416 197Q416 326 269 326L232 325H221V400Q316 402 355 424T395 511Q395 567 362 599T270 632Z"),
"4": (556,"M327 170H28V263L350 709H415V249H520V170H415V0H327V170ZM327 249V559L105 249H327Z"),
"5": (556,"M476 709V622H181L153 424Q212 467 284 467Q386 467 449 402T513 231Q513 119 445 48T270 -23Q229 -23 195 -14T138 7T97 40T69 76T51 115T40 148T35 174H123Q154 55 268 55Q340 55 381 99T423 219Q423 298 381 343T268 389Q227 389 198 375T138 323H57L110 709H476Z"),
"6": (556,"M43 323Q43 417 60 488T102 601T163 667T230 701T297 709Q378 709 431 660T498 524H410Q399 575 368 603T291 631Q215 631 175 562T133 362Q191 441 296 441Q391 441 452 378T513 216Q513 112 448 45T281 -23Q43 -23 43 323ZM285 363Q220 363 179 322T138 214Q138 146 179 101T282 55Q343 55 383 98T423 209Q423 280 386 321T285 363Z"),
"7": (556,"M520 709V635Q400 475 331 323T232 0H138Q178 175 240 308T429 622H46V709H520Z"),
"8": (556,"M391 373Q513 315 513 196Q513 99 447 38T275 -23T104 38T37 197Q37 315 158 373Q104 407 83 439T62 520Q62 603 121 656T275 709T428 656T488 520Q488 470 467 438T391 373ZM331 631T275 631T186 601T152 519Q152 469 185 439T275 408Q330 408 364 438T398 518Q398 570 365 600ZM341 334T275 334T168 296T127 195T167 94T273 55Q340 55 381 93T423 195Q423 257 382 295Z"),
"9": (556,"M509 363Q509 269 492 198T450 85T389 19T321 -15T254 -23Q173 -23 120 26T53 162H141Q152 111 183 83T260 55Q336 55 376 124T418 324Q352 245 256 245T99 308T38 470Q38 574 103 641T270 709Q509 709 509 363ZM269 632Q208 632 168 588T128 477Q128 406 165 365T266 323T371 365T413 472Q413 541 372 586T269 632Z"),
":": (278,"M214 104V0H110V104H214ZM214 524V420H110V524H214Z"),
";": (278,"M215 524V420H111V524H215ZM110 104H215V-16Q215 -147 110 -147V-109Q145 -108 157 -89T170 -18V0H110V104Z"),
"=": (584,"M534 353V283H50V353H534ZM534 181V111H50V181H534Z"),
"?": (556,"M509 549Q509 503 491 466T446 405T394 358T349 307T330 246V199H240V254Q240 291 258 324T303 381T356 429T400 483T419 549Q419 600 384 631T291 663Q218 663 190 622T162 507H77Q77 622 132 681T296 741Q393 741 451 689T509 549ZM330 104V0H240V104H330Z"),
"@": (1015,"M665 501H748L658 221Q646 186 646 171Q646 153 661 140T696 127Q760 127 812 198T864 357Q864 482 760 573T512 664Q354 664 237 547T119 273Q119 130 227 33T494 -65Q573 -65 687 -33L715 -100Q603 -142 489 -142Q365 -142 260 -89T95 57T34 258Q34 356 76 450T192 612Q258 672 347 706T525 741Q700 741 825 631T951 369Q951 246 865 146Q789 57 679 57Q583 57 569 134Q503 62 427 62Q357 62 311 114T264 245Q264 354 342 438T521 522Q605 522 643 435L665 501ZM453 126Q518 126 563 209T609 368Q609 406 582 432T515 458Q452 458 403 393T354 244Q354 195 383 161T453 126Z"),
"A": (667,"M474 219H193L116 0H17L277 729H397L653 0H549L474 219ZM448 297L336 629L216 297H448Z"),
"B": (667,"M623 208Q623 114 564 57T408 0H79V729H375Q436 729 481 711T548 664T581 605T591 544Q591 432 490 385Q560 358 591 316T623 208ZM498 415T498 531T352 647H172V415H352Q498 415 498 531ZM399 82Q448 82 479 103T520 151T530 207Q530 264 496 298T399 333H172V82H399Z"),
"C": (722,"M48 356Q48 406 56 455T89 557T148 649T244 715T381 741Q619 741 662 503H567Q551 581 504 620T370 659Q264 659 203 578T141 357Q141 220 205 140T378 59Q468 59 516 109T581 266H677Q644 -23 377 -23Q302 -23 243 2T148 67T89 158T57 259T48 356Z"),
"D": (722,"M89 0V729H370Q509 729 588 632T667 365T588 98T370 0H89ZM182 82H354Q462 82 518 154T574 364Q574 503 518 575T354 647H182V82Z"),
"E": (667,"M183 332V82H613V0H90V729H595V647H183V414H580V332H183Z"),
"F": (611,"M183 332V0H90V729H579V647H183V414H531V332H183Z"),
"G": (778,"M137 362Q137 324 144 286T169 205T215 132T291 80T398 59Q498 59 562 122T627 283V303H405V385H709V-4H650L627 93Q523 -23 378 -23Q230 -23 137 83T44 357Q44 405 53 453T87 555T149 648T250 714T394 741Q519 741 599 680T699 508H604Q589 578 533 618T393 659Q277 659 207 578T137 362Z"),
"H": (722,"M551 332H176V0H83V729H176V414H551V729H644V0H551V332Z"),
"I": (278,"M194 729V0H100V729H194Z"),
"J": (500,"M221 55Q285 55 309 97T333 216V729H426V182Q426 87 371 32T220 -23Q126 -23 72 29T17 170V234H112V187Q112 123 140 89T221 55Z"),
"K": (667,"M172 255V0H79V729H172V360L535 729H655L358 432L658 0H548L291 374L172 255Z"),
"L": (556,"M173 729V82H533V0H80V729H173Z"),
"M": (833,"M468 0H370L163 611V0H75V729H204L420 94L632 729H761V0H673V611L468 0Z"),
"N": (722,"M646 729V0H541L164 591V0H76V729H177L558 133V729H646Z"),
"O": (778,"M742 353Q742 191 646 84T390 -23Q232 -23 135 82T38 359T135 635T389 741Q549 741 645 635T742 353ZM389 659Q273 659 202 577T131 359T202 142T390 59T577 141T649 355Q649 493 578 576T389 659Z"),
"P": (667,"M617 515Q617 422 561 366T413 309H184V0H91V729H392Q500 729 558 674T617 515ZM184 391H378Q445 391 482 425T520 519T483 613T378 647H184V391Z"),
"Q": (778,"M733 -1L686 -59L581 28Q495 -23 390 -23Q232 -23 135 82T38 359T135 635T390 741Q547 741 644 636T742 361Q742 189 639 76L733 -1ZM481 205L570 132Q649 221 649 360Q649 494 578 576T390 659T203 577T131 359T202 142T389 59Q449 59 509 87L435 149L481 205Z"),
"R": (722,"M536 360Q568 346 589 327T620 284T633 239T636 189Q636 180 636 163T635 138Q635 97 644 69T679 23V0H566Q546 46 546 119V184Q546 251 517 282T426 314H186V0H93V729H429Q536 729 593 679T651 534Q651 472 624 431T536 360ZM554 521Q554 593 516 620T411 647H186V396H411Q485 396 519 426T554 521Z"),
"S": (667,"M342 59Q398 59 437 72T494 106T520 147T528 191Q528 274 394 309L213 357Q70 394 70 527Q70 626 139 683T329 741Q455 741 525 682T596 515H508Q507 586 460 624T326 663Q252 663 208 629T163 540Q163 498 190 474T283 432L466 383Q540 363 580 315T621 200Q621 171 614 143T586 84T535 30T453 -8T336 -23Q295 -23 258 -17T181 7T114 52T68 126T48 232H136V227Q136 196 145 169T176 116T240 75T342 59Z"),
"T": (611,"M354 647V0H261V647H21V729H593V647H354Z"),
"U": (722,"M552 729H645V217Q645 107 569 42T364 -23Q234 -23 160 41T85 217V729H178V217Q178 138 228 99T364 59Q452 59 502 101T552 217V729Z"),
"V": (667,"M392 0H292L30 729H130L344 112L546 729H645L392 0Z"),
"W": (944,"M744 0H642L474 599L311 0H209L22 729H126L263 137L425 729H525L691 137L825 729H929L744 0Z"),
"X": (667,"M391 374L649 0H534L335 304L135 0H22L280 374L38 729H151L338 443L526 729H637L391 374Z"),
"Y": (667,"M387 286V0H294V286L13 729H128L342 374L550 729H661L387 286Z"),
"Z": (611,"M581 729V645L145 82H583V0H28V82L466 647H56V729H581Z"),
"[": (278,"M250 729V657H147V-140H250V-212H64V729H250Z"),
"\\": (278,"M47 729L284 -20H229L-8 729H47Z"),
"]": (277,"M22 -212V-140H125V657H22V729H208V-212H22Z"),
"^": (469,"M197 709H270L425 329H356L234 629L113 329H44L197 709Z"),
"_": (556,"M578 -126V-176H-22V-126H578Z"),
"`": (333,"M135 740L231 592H171L22 740H135Z"),
"a": (556,"M65 369Q71 539 275 539Q372 539 422 503T472 396V88Q472 47 517 47Q526 47 535 49V-14Q500 -23 478 -23Q438 -23 418 -5T392 54Q308 -23 214 -23Q135 -23 89 19T42 132Q42 155 46 174T56 207T76 234T99 255T131 270T166 281T208 290T252 297T302 304Q351 310 370 323T389 362V384Q389 422 359 442T272 462Q214 462 184 440T149 369H65ZM232 50Q301 50 345 86T389 165V259Q364 247 314 239T226 225T159 197T129 134T156 72T232 50Z"),
"b": (556,"M54 729H137V453Q194 539 299 539Q403 539 463 465T523 264Q523 134 461 56T295 -23Q188 -23 129 67V0H54V729ZM283 461Q217 461 177 406T137 258T177 111T283 55Q351 55 393 110T436 255Q436 349 395 405T283 461Z"),
"c": (500,"M471 348H387Q379 403 347 432T263 462Q195 462 157 407T118 253Q118 160 157 107T265 54Q372 54 393 180H477Q469 84 413 31T263 -23Q156 -23 94 51T31 253Q31 383 94 461T264 539Q355 539 409 490T471 348Z"),
"d": (556,"M495 729V0H421V69Q387 20 348 -1T254 -23Q148 -23 87 53T26 263Q26 388 87 463T251 539Q359 539 412 458V729H495ZM265 461Q197 461 155 405T113 258Q113 166 155 111T266 55Q332 55 372 110T412 256Q412 350 372 405T265 461Z"),
"e": (556,"M513 234H127Q128 162 155 122Q198 54 281 54Q383 54 418 159H502Q486 73 427 25T278 -23Q168 -23 104 51T40 255T105 461T280 539Q354 539 410 502T492 401Q513 346 513 234ZM129 302H423Q424 304 424 308Q424 373 382 417T279 462Q216 462 175 419T129 302Z"),
"f": (278,"M258 524V456H171V0H88V456H18V524H88V613Q88 669 120 700T211 732Q234 732 258 727V658Q239 659 229 659Q171 659 171 606V524H258Z"),
"g": (556,"M245 -23Q153 -23 91 52T29 253Q29 381 90 460T252 539Q350 539 412 448V524H489V86Q489 11 480 -39T447 -133T376 -197T255 -218Q163 -218 108 -176T46 -60H131Q145 -148 258 -148Q342 -148 373 -101T404 44V71Q369 21 332 -1T245 -23ZM261 462Q194 462 155 407T116 258Q116 163 155 109T262 54Q328 54 366 107T404 255Q404 353 367 407T261 462Z"),
"h": (556,"M403 363Q403 418 370 442T295 466Q231 466 192 418T153 289V0H70V729H153V452Q190 500 227 519T321 539Q397 539 441 501T486 396V0H403V363Z"),
"i": (222,"M150 518V-6H67V518H150ZM150 729V624H66V729H150Z"),
"j": (222,"M70 524H153V-109Q153 -218 10 -218Q-3 -218 -18 -215V-144Q-7 -145 2 -145Q40 -145 55 -130T70 -76V524ZM153 729V624H70V729H153Z"),
"k": (500,"M141 729V302L363 524H470L288 343L502 0H399L222 284L141 204V0H58V729H141Z"),
"l": (222,"M152 729V0H68V729H152Z"),
"m": (833,"M70 524H147V450Q181 497 218 518T308 539Q405 539 449 459Q486 503 522 521T610 539Q683 539 722 502T762 393V0H678V361Q678 411 653 438T581 466Q530 466 494 426T458 329V0H374V361Q374 411 349 438T277 466Q226 466 190 426T154 329V0H70V524Z"),
"n": (556,"M70 524H147V436Q182 491 222 515T321 539Q397 539 442 500T487 396V0H404V363Q404 410 375 438T296 466Q232 466 193 418T154 289V0H70V524Z"),
"o": (556,"M272 539Q385 539 447 465T510 254Q510 125 447 51T273 -23Q161 -23 99 51T36 258T99 464T272 539ZM273 462Q203 462 163 408T123 258T163 109T273 54Q342 54 382 108T423 255Q423 352 384 407T273 462Z"),
"p": (556,"M54 -218V524H131V445Q190 539 298 539Q402 539 462 462T523 253Q523 128 462 53T299 -23Q202 -23 138 55V-218H54ZM284 461Q218 461 178 406T138 258T178 111T284 55Q352 55 394 110T436 255Q436 349 395 405T284 461Z"),
"q": (556,"M495 -218H412V60Q355 -23 250 -23Q146 -23 86 51T26 252Q26 382 88 460T254 539Q361 539 421 454V524H495V-218ZM266 461Q197 461 155 405T113 258Q113 166 155 111T266 55Q332 55 372 110T412 255Q412 349 373 405T266 461Z"),
"r": (333,"M321 451Q237 449 195 412T153 272V0H69V524H146V429Q182 488 215 513T289 539Q300 539 321 536V451Z"),
"s": (500,"M122 156Q128 109 154 82T250 54Q305 54 338 76T372 136Q372 165 353 182T291 209L213 228Q120 250 84 283T47 379Q47 452 102 495T248 539T388 497T438 378H350Q347 462 245 462Q194 462 164 441T134 383Q134 355 157 338T231 308L311 289Q389 270 424 236T459 143Q459 67 401 22T243 -23Q40 -23 34 156H122Z"),
"t": (278,"M254 524V456H168V97Q168 69 177 60T214 50Q239 50 254 54V-16Q215 -23 186 -23Q137 -23 111 -2T85 60V456H14V524H85V668H168V524H254Z"),
"u": (556,"M482 0H407V73Q370 21 330 -1T232 -23Q156 -23 111 16T65 120V524H148V153Q148 106 177 78T256 50Q321 50 360 98T399 227V524H482V0Z"),
"v": (500,"M285 0H194L10 524H104L244 99L392 524H486L285 0Z"),
"w": (722,"M554 0H459L353 411L252 0H158L6 524H98L205 116L305 524H407L510 116L614 524H708L554 0Z"),
"x": (500,"M292 271L473 0H376L245 201L112 0H17L202 267L27 524H122L248 334L374 524H468L292 271Z"),
"y": (500,"M388 524H478L245 -110Q204 -218 110 -218Q79 -218 54 -205V-130Q81 -136 98 -136Q124 -136 139 -125T165 -85L197 -2L20 524H109L243 116L388 524Z"),
"z": (500,"M443 524V450L132 73H457V0H31V75L344 451H52V524H443Z"),
"{": (334,"M276 729V664H261Q224 664 211 650T198 597V416Q198 347 180 312T116 259Q198 221 198 101V-80Q198 -119 211 -133T261 -147H276V-212H230Q178 -212 150 -178T121 -81V86Q121 155 104 185T43 224V293Q87 302 104 331T121 431V598Q121 660 149 694T230 729H276Z"),
"|": (260,"M100 729H160V-212H100V729Z"),
"}": (334,"M29 -212V-147H45Q82 -147 95 -133T109 -80V101Q109 221 191 258Q109 296 109 416V597Q109 636 96 650T45 664H29V729H76Q128 729 157 695T186 598V431Q186 362 202 332T262 293V224Q219 215 203 185T186 86V-81Q186 -143 157 -177T76 -212H29Z"),
"~": (584,"M181 371Q134 371 128 293H75Q79 363 106 400T183 438Q210 438 237 422L354 353Q382 336 404 336Q434 336 444 354T455 411H508Q508 268 403 268Q364 268 322 294L224 357Q201 371 181 371Z")
}
|
mit
|
[
504,
1300,
492,
6566,
12,
15483,
461,
2162,
12,
20783,
2162,
199,
504,
1572,
492,
21313,
199,
504,
22603,
492,
10080,
12,
3645,
199,
504,
3778,
492,
10935,
3532,
199,
199,
504,
2508,
1208,
14,
1820,
492,
11388,
465,
812,
12,
8449,
199,
504,
3473,
492,
7452,
12,
9794,
12,
9829,
421,
199,
504,
1331,
492,
14800,
421,
199,
533,
445,
12571,
334,
5625,
461,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
15483,
461,
2162,
855,
826,
363,
334,
277,
12,
536,
275,
283,
11001,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
8017,
735,
288,
291,
14,
8017,
275,
1921,
459,
8017,
418,
267,
587,
26,
288,
291,
14,
8017,
275,
378,
14,
16,
339,
347,
1568,
334,
277,
12,
574,
304,
267,
291,
14,
8017,
275,
574,
339,
347,
663,
19366,
334,
277,
304,
267,
2086,
275,
812,
334,
277,
14,
88,
12,
291,
14,
89,
9,
267,
291,
14,
4998,
6939,
334,
1712,
9,
267,
1921,
275,
15483,
461,
2162,
14,
409,
19366,
334,
277,
9,
4960,
1921,
14,
873,
26236,
11859,
297,
2086,
14,
88,
395,
221,
1993,
661,
1480,
297,
2086,
14,
89,
395,
1993,
661,
82,
297,
291,
14,
8017,
3948,
267,
372,
1921,
199,
199,
533,
6912,
2162,
26,
272,
347,
3634,
334,
277,
304,
267,
372,
8449,
334,
19,
12,
413,
12,
359,
277,
14,
88,
12,
291,
14,
89,
12,
413,
566,
199,
199,
533,
1626,
7050,
2162,
334,
2042,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
339,
347,
636,
495,
363,
334,
277,
304,
267,
372,
283,
1987,
904,
21022,
45,
418,
435,
2341,
334,
495,
12,
359,
277,
14,
88,
12,
291,
14,
89,
2459,
9948,
199,
533,
12489,
2162,
334,
2042,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
339,
347,
636,
495,
363,
334,
277,
304,
267,
372,
283,
1987,
904,
21022,
44,
418,
435,
2341,
334,
495,
12,
359,
277,
14,
88,
12,
291,
14,
89,
2459,
9948,
199,
533,
15524,
2162,
334,
2042,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
304,
267,
986,
339,
347,
636,
495,
363,
334,
277,
304,
267,
372,
283,
58,
7,
199,
199,
533,
6912,
334,
5625,
461,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
15483,
461,
2162,
855,
826,
363,
334,
277,
12,
536,
275,
283,
515,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
4711,
735,
288,
291,
14,
1932,
6939,
275,
1921,
459,
4711,
418,
267,
587,
26,
288,
291,
14,
1932,
6939,
275,
488,
267,
291,
14,
5527,
275,
942,
267,
291,
14,
5938,
275,
756,
339,
347,
1004,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
5527,
14,
740,
334,
10608,
2162,
334,
88,
12,
612,
430,
339,
347,
4057,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
5527,
14,
740,
334,
23517,
2162,
334,
88,
12,
612,
430,
339,
347,
4002,
334,
277,
304,
267,
291,
14,
5938,
275,
715,
339,
347,
1551,
334,
277,
304,
267,
291,
14,
5938,
275,
756,
339,
347,
663,
19366,
334,
277,
304,
267,
1921,
275,
6566,
14,
409,
19366,
334,
277,
9,
267,
4008,
275,
14800,
334,
277,
14,
5527,
9,
267,
291,
14,
4998,
6939,
19943,
5527,
9,
267,
3326,
275,
2341,
334,
495,
12,
4008,
9,
267,
340,
291,
14,
5938,
26,
288,
3326,
14,
740,
334,
495,
334,
4724,
2162,
334,
1724,
267,
1921,
14,
873,
26236,
68,
297,
283,
1987,
904,
334,
5465,
1826,
661,
4711,
297,
291,
14,
1932,
6939,
3948,
267,
372,
1921,
27844,
199,
533,
445,
6521,
1282,
1619,
334,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
6566,
855,
826,
363,
334,
277,
12,
536,
534,
515,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
576,
735,
288,
291,
14,
576,
275,
1921,
459,
576,
418,
267,
587,
26,
288,
291,
14,
576,
275,
488,
267,
340,
1921,
14,
1989,
63,
498,
661,
4711,
735,
288,
291,
14,
1932,
6939,
275,
1921,
459,
4711,
418,
267,
587,
26,
288,
291,
14,
1932,
6939,
275,
488,
339,
347,
663,
19366,
334,
277,
304,
267,
1921,
275,
6566,
14,
409,
19366,
334,
277,
9,
267,
1921,
14,
873,
26236,
68,
297,
291,
14,
576,
395,
661,
4711,
297,
291,
14,
1932,
6939,
3948,
267,
372,
1921,
421,
199,
533,
21536,
4593,
334,
3532,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
20783,
2162,
855,
826,
363,
334,
277,
12,
536,
275,
283,
1201,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
2063,
735,
288,
291,
14,
2063,
275,
2069,
334,
962,
459,
2063,
1105,
267,
587,
26,
288,
291,
14,
2063,
275,
488,
267,
340,
1921,
14,
1989,
63,
498,
661,
3333,
735,
288,
291,
14,
3333,
275,
2069,
334,
962,
459,
3333,
1105,
267,
587,
26,
288,
291,
14,
3333,
275,
488,
267,
340,
1921,
14,
1989,
63,
498,
661,
6116,
2320,
735,
288,
291,
14,
6116,
2320,
275,
2155,
334,
962,
459,
6116,
2320,
1105,
267,
587,
26,
288,
291,
14,
6116,
2320,
275,
756,
267,
340,
1921,
14,
1989,
63,
498,
661,
7617,
13411,
56,
735,
288,
291,
14,
7617,
13411,
56,
275,
2069,
334,
962,
459,
7617,
13411,
56,
1105,
267,
587,
26,
288,
291,
14,
7617,
13411,
56,
275,
378,
14,
16,
267,
340,
1921,
14,
1989,
63,
498,
661,
7617,
13411,
57,
735,
288,
291,
14,
7617,
13411,
57,
275,
2069,
334,
962,
459,
7617,
13411,
57,
1105,
267,
587,
26,
288,
291,
14,
7617,
13411,
57,
275,
378,
14,
16,
5493,
347,
663,
19366,
334,
277,
304,
267,
1921,
275,
20783,
2162,
14,
409,
19366,
334,
277,
9,
267,
340,
440,
291,
14,
6116,
2320,
26,
288,
4501,
275,
291,
14,
915,
5434,
3532,
334,
277,
14,
88,
12,
291,
14,
89,
12
] |
[
1300,
492,
6566,
12,
15483,
461,
2162,
12,
20783,
2162,
199,
504,
1572,
492,
21313,
199,
504,
22603,
492,
10080,
12,
3645,
199,
504,
3778,
492,
10935,
3532,
199,
199,
504,
2508,
1208,
14,
1820,
492,
11388,
465,
812,
12,
8449,
199,
504,
3473,
492,
7452,
12,
9794,
12,
9829,
421,
199,
504,
1331,
492,
14800,
421,
199,
533,
445,
12571,
334,
5625,
461,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
15483,
461,
2162,
855,
826,
363,
334,
277,
12,
536,
275,
283,
11001,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
8017,
735,
288,
291,
14,
8017,
275,
1921,
459,
8017,
418,
267,
587,
26,
288,
291,
14,
8017,
275,
378,
14,
16,
339,
347,
1568,
334,
277,
12,
574,
304,
267,
291,
14,
8017,
275,
574,
339,
347,
663,
19366,
334,
277,
304,
267,
2086,
275,
812,
334,
277,
14,
88,
12,
291,
14,
89,
9,
267,
291,
14,
4998,
6939,
334,
1712,
9,
267,
1921,
275,
15483,
461,
2162,
14,
409,
19366,
334,
277,
9,
4960,
1921,
14,
873,
26236,
11859,
297,
2086,
14,
88,
395,
221,
1993,
661,
1480,
297,
2086,
14,
89,
395,
1993,
661,
82,
297,
291,
14,
8017,
3948,
267,
372,
1921,
199,
199,
533,
6912,
2162,
26,
272,
347,
3634,
334,
277,
304,
267,
372,
8449,
334,
19,
12,
413,
12,
359,
277,
14,
88,
12,
291,
14,
89,
12,
413,
566,
199,
199,
533,
1626,
7050,
2162,
334,
2042,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
339,
347,
636,
495,
363,
334,
277,
304,
267,
372,
283,
1987,
904,
21022,
45,
418,
435,
2341,
334,
495,
12,
359,
277,
14,
88,
12,
291,
14,
89,
2459,
9948,
199,
533,
12489,
2162,
334,
2042,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
88,
275,
671,
267,
291,
14,
89,
275,
612,
339,
347,
636,
495,
363,
334,
277,
304,
267,
372,
283,
1987,
904,
21022,
44,
418,
435,
2341,
334,
495,
12,
359,
277,
14,
88,
12,
291,
14,
89,
2459,
9948,
199,
533,
15524,
2162,
334,
2042,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
304,
267,
986,
339,
347,
636,
495,
363,
334,
277,
304,
267,
372,
283,
58,
7,
199,
199,
533,
6912,
334,
5625,
461,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
15483,
461,
2162,
855,
826,
363,
334,
277,
12,
536,
275,
283,
515,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
4711,
735,
288,
291,
14,
1932,
6939,
275,
1921,
459,
4711,
418,
267,
587,
26,
288,
291,
14,
1932,
6939,
275,
488,
267,
291,
14,
5527,
275,
942,
267,
291,
14,
5938,
275,
756,
339,
347,
1004,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
5527,
14,
740,
334,
10608,
2162,
334,
88,
12,
612,
430,
339,
347,
4057,
334,
277,
12,
671,
12,
612,
304,
267,
291,
14,
5527,
14,
740,
334,
23517,
2162,
334,
88,
12,
612,
430,
339,
347,
4002,
334,
277,
304,
267,
291,
14,
5938,
275,
715,
339,
347,
1551,
334,
277,
304,
267,
291,
14,
5938,
275,
756,
339,
347,
663,
19366,
334,
277,
304,
267,
1921,
275,
6566,
14,
409,
19366,
334,
277,
9,
267,
4008,
275,
14800,
334,
277,
14,
5527,
9,
267,
291,
14,
4998,
6939,
19943,
5527,
9,
267,
3326,
275,
2341,
334,
495,
12,
4008,
9,
267,
340,
291,
14,
5938,
26,
288,
3326,
14,
740,
334,
495,
334,
4724,
2162,
334,
1724,
267,
1921,
14,
873,
26236,
68,
297,
283,
1987,
904,
334,
5465,
1826,
661,
4711,
297,
291,
14,
1932,
6939,
3948,
267,
372,
1921,
27844,
199,
533,
445,
6521,
1282,
1619,
334,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
6566,
855,
826,
363,
334,
277,
12,
536,
534,
515,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
576,
735,
288,
291,
14,
576,
275,
1921,
459,
576,
418,
267,
587,
26,
288,
291,
14,
576,
275,
488,
267,
340,
1921,
14,
1989,
63,
498,
661,
4711,
735,
288,
291,
14,
1932,
6939,
275,
1921,
459,
4711,
418,
267,
587,
26,
288,
291,
14,
1932,
6939,
275,
488,
339,
347,
663,
19366,
334,
277,
304,
267,
1921,
275,
6566,
14,
409,
19366,
334,
277,
9,
267,
1921,
14,
873,
26236,
68,
297,
291,
14,
576,
395,
661,
4711,
297,
291,
14,
1932,
6939,
3948,
267,
372,
1921,
421,
199,
533,
21536,
4593,
334,
3532,
2162,
304,
272,
347,
636,
826,
363,
334,
277,
12,
1011,
962,
304,
267,
20783,
2162,
855,
826,
363,
334,
277,
12,
536,
275,
283,
1201,
297,
1011,
962,
9,
267,
340,
1921,
14,
1989,
63,
498,
661,
2063,
735,
288,
291,
14,
2063,
275,
2069,
334,
962,
459,
2063,
1105,
267,
587,
26,
288,
291,
14,
2063,
275,
488,
267,
340,
1921,
14,
1989,
63,
498,
661,
3333,
735,
288,
291,
14,
3333,
275,
2069,
334,
962,
459,
3333,
1105,
267,
587,
26,
288,
291,
14,
3333,
275,
488,
267,
340,
1921,
14,
1989,
63,
498,
661,
6116,
2320,
735,
288,
291,
14,
6116,
2320,
275,
2155,
334,
962,
459,
6116,
2320,
1105,
267,
587,
26,
288,
291,
14,
6116,
2320,
275,
756,
267,
340,
1921,
14,
1989,
63,
498,
661,
7617,
13411,
56,
735,
288,
291,
14,
7617,
13411,
56,
275,
2069,
334,
962,
459,
7617,
13411,
56,
1105,
267,
587,
26,
288,
291,
14,
7617,
13411,
56,
275,
378,
14,
16,
267,
340,
1921,
14,
1989,
63,
498,
661,
7617,
13411,
57,
735,
288,
291,
14,
7617,
13411,
57,
275,
2069,
334,
962,
459,
7617,
13411,
57,
1105,
267,
587,
26,
288,
291,
14,
7617,
13411,
57,
275,
378,
14,
16,
5493,
347,
663,
19366,
334,
277,
304,
267,
1921,
275,
20783,
2162,
14,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
MihaiMoldovanu/ansible
|
lib/ansible/modules/network/nxos/nxos_vtp_version.py
|
13
|
5711
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
DOCUMENTATION = '''
---
module: nxos_vtp_version
extends_documentation_fragment: nxos
version_added: "2.2"
short_description: Manages VTP version configuration.
description:
- Manages VTP version configuration.
author:
- Gabriele Gerbino (@GGabriele)
notes:
- Tested against NXOSv 7.3.(0)D1(1) on VIRL
- VTP feature must be active on the device to use this module.
- This module is used to manage only VTP version.
- Use this in combination with M(nxos_vtp_password) and M(nxos_vtp_version)
to fully manage VTP operations.
options:
version:
description:
- VTP version number.
required: true
choices: ['1', '2']
'''
EXAMPLES = '''
# ENSURE VTP VERSION IS 2
- nxos_vtp_version:
version: 2
host: "{{ inventory_hostname }}"
username: "{{ un }}"
password: "{{ pwd }}"
'''
RETURN = '''
proposed:
description: k/v pairs of parameters passed into module
returned: always
type: dict
sample: {"version": "2"}
existing:
description:
- k/v pairs of existing vtp
returned: always
type: dict
sample: {"domain": "testing", "version": "1", "vtp_password": "\"}
end_state:
description: k/v pairs of vtp after module execution
returned: always
type: dict
sample: {"domain": "testing", "version": "2", "vtp_password": "\"}
updates:
description: command sent to the device
returned: always
type: list
sample: ["vtp version 2"]
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
'''
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
import re
import re
def execute_show_command(command, module, command_type='cli_show'):
if 'status' not in command:
output = 'json'
else:
output = 'text'
cmds = [{
'command': command,
'output': output,
}]
body = run_commands(module, cmds)
return body
def flatten_list(command_lists):
flat_command_list = []
for command in command_lists:
if isinstance(command, list):
flat_command_list.extend(command)
else:
flat_command_list.append(command)
return flat_command_list
def get_vtp_config(module):
command = 'show vtp status'
body = execute_show_command(
command, module)[0]
vtp_parsed = {}
if body:
version_regex = '.*VTP version running\s+:\s+(?P<version>\d).*'
domain_regex = '.*VTP Domain Name\s+:\s+(?P<domain>\S+).*'
try:
match_version = re.match(version_regex, body, re.DOTALL)
version = match_version.groupdict()['version']
except AttributeError:
version = ''
try:
match_domain = re.match(domain_regex, body, re.DOTALL)
domain = match_domain.groupdict()['domain']
except AttributeError:
domain = ''
if domain and version:
vtp_parsed['domain'] = domain
vtp_parsed['version'] = version
vtp_parsed['vtp_password'] = get_vtp_password(module)
return vtp_parsed
def get_vtp_password(module):
command = 'show vtp password'
body = execute_show_command(command, module)[0]
try:
password = body['passwd']
if password:
return str(password)
else:
return ""
except TypeError:
return ""
def main():
argument_spec = dict(
version=dict(type='str', choices=['1', '2'], required=True),
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
warnings = list()
check_args(module, warnings)
version = module.params['version']
existing = get_vtp_config(module)
end_state = existing
args = dict(version=version)
changed = False
proposed = dict((k, v) for k, v in args.items() if v is not None)
delta = dict(set(proposed.items()).difference(existing.items()))
commands = []
if delta:
commands.append(['vtp version {0}'.format(version)])
cmds = flatten_list(commands)
if cmds:
if module.check_mode:
module.exit_json(changed=True, commands=cmds)
else:
changed = True
load_config(module, cmds)
end_state = get_vtp_config(module)
if 'configure' in cmds:
cmds.pop(0)
results = {}
results['proposed'] = proposed
results['existing'] = existing
results['end_state'] = end_state
results['updates'] = cmds
results['changed'] = changed
results['warnings'] = warnings
module.exit_json(**results)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
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,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1200,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
199,
578,
26,
22072,
63,
86,
683,
63,
1023,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
812,
6495,
1015,
2897,
14,
199,
1802,
26,
272,
446,
21612,
812,
6495,
1015,
2897,
14,
199,
2502,
26,
272,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
272,
446,
30568,
6169,
653,
56,
3100,
86,
1520,
14,
19,
14,
8,
16,
9,
36,
17,
8,
17,
9,
641,
812,
41,
2431,
272,
446,
812,
6495,
3878,
1471,
506,
4702,
641,
314,
2243,
370,
675,
642,
859,
14,
272,
446,
961,
859,
365,
1202,
370,
9635,
1454,
812,
6495,
1015,
14,
272,
446,
3645,
642,
315,
14665,
543,
603,
8,
17982,
63,
86,
683,
63,
2060,
9,
436,
603,
8,
17982,
63,
86,
683,
63,
1023,
9,
489,
370,
9999,
9635,
812,
6495,
5331,
14,
199,
1419,
26,
272,
1015,
26,
267,
1369,
26,
288,
446,
812,
6495,
1015,
1329,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
17,
297,
283,
18,
418,
199,
2344,
199,
8918,
275,
1449,
199,
3,
21587,
3942,
812,
6495,
15945,
2281,
499,
199,
13,
22072,
63,
86,
683,
63,
1023,
26,
272,
1015,
26,
499,
272,
1591,
26,
7370,
8200,
63,
4269,
7820,
272,
3434,
26,
7370,
625,
7820,
272,
2505,
26,
7370,
14374,
7820,
199,
2344,
199,
199,
9677,
275,
1449,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1023,
582,
298,
18,
3570,
199,
5952,
26,
272,
1369,
26,
267,
446,
1022,
15,
86,
6342,
402,
3411,
373,
683,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
2261,
582,
298,
4776,
401,
298,
1023,
582,
298,
17,
401,
298,
86,
683,
63,
2060,
582,
1867,
3570,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
373,
683,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
2261,
582,
298,
4776,
401,
298,
1023,
582,
298,
18,
401,
298,
86,
683,
63,
2060,
582,
1867,
3570,
199,
7618,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
86,
683,
1015,
499,
937,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
2344,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
421,
199,
646,
295,
199,
646,
295,
421,
199,
318,
5341,
63,
2384,
63,
1531,
8,
1531,
12,
859,
12,
1414,
63,
466,
534,
2764,
63,
2384,
735,
272,
340,
283,
1205,
7,
440,
315,
1414,
26,
267,
1072,
275,
283,
1001,
7,
272,
587,
26,
267,
1072,
275,
283,
505,
7,
272,
11465,
275,
8910,
267,
283,
1531,
356,
1414,
12,
267,
283,
1199,
356,
1072,
12,
272,
14877,
272,
2396,
275,
1255,
63,
4405,
8,
578,
12,
11465,
9,
272,
372,
2396,
421,
199,
318,
9378,
63,
513,
8,
1531,
63,
6717,
304,
272,
6829,
63,
1531,
63,
513,
275,
942,
272,
367,
1414,
315,
1414,
63,
6717,
26,
267,
340,
1228,
8,
1531,
12,
769,
304,
288,
6829,
63,
1531,
63,
513,
14,
2880,
8,
1531,
9,
267,
587,
26,
288,
6829,
63,
1531,
63,
513,
14,
740,
8,
1531,
9,
272,
372,
6829,
63,
1531,
63,
513,
421,
199,
318,
664,
63,
86,
683,
63,
888,
8,
578,
304,
272,
1414,
275,
283,
2384,
373,
683,
2004,
7,
272,
2396,
275,
5341,
63,
2384,
63,
1531,
8,
267,
1414,
12,
859,
2788,
16,
61,
272,
373,
683,
63,
6751,
275,
1052,
339,
340,
2396,
26,
267,
1015,
63,
3821,
275,
1987,
10,
54,
6495,
1015,
3879,
60,
83,
11,
3427,
83,
11,
2229,
48,
28,
1023,
3072,
68,
680,
10223,
267,
2881,
63,
3821,
275,
1987,
10,
54,
6495,
14061,
2812,
60,
83,
11,
3427,
83,
11,
2229,
48,
28,
2261,
3072,
51,
11,
680,
10223,
398,
862,
26,
288,
1336,
63,
1023,
275,
295,
14,
1431,
8,
1023,
63,
3821,
12,
2396,
12,
295,
14,
16504,
9,
288,
1015,
275,
1336,
63,
1023,
14,
20567,
12047,
1023,
418,
267,
871,
4281,
26,
288,
1015,
275,
2125,
398,
862,
26,
288,
1336,
63,
2261,
275,
295,
14,
1431,
8,
2261,
63,
3821,
12,
2396,
12,
295,
14,
16504,
9,
288,
2881,
275,
1336,
63,
2261,
14,
20567,
12047,
2261,
418,
267,
871,
4281,
26,
288,
2881,
275,
2125,
398,
340,
2881,
436,
1015,
26,
288,
373,
683,
63,
6751
] |
[
2647,
15,
1393,
15,
1548,
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,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
1200,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
199,
578,
26,
22072,
63,
86,
683,
63,
1023,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
3612,
63,
1802,
26,
21612,
812,
6495,
1015,
2897,
14,
199,
1802,
26,
272,
446,
21612,
812,
6495,
1015,
2897,
14,
199,
2502,
26,
272,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
272,
446,
30568,
6169,
653,
56,
3100,
86,
1520,
14,
19,
14,
8,
16,
9,
36,
17,
8,
17,
9,
641,
812,
41,
2431,
272,
446,
812,
6495,
3878,
1471,
506,
4702,
641,
314,
2243,
370,
675,
642,
859,
14,
272,
446,
961,
859,
365,
1202,
370,
9635,
1454,
812,
6495,
1015,
14,
272,
446,
3645,
642,
315,
14665,
543,
603,
8,
17982,
63,
86,
683,
63,
2060,
9,
436,
603,
8,
17982,
63,
86,
683,
63,
1023,
9,
489,
370,
9999,
9635,
812,
6495,
5331,
14,
199,
1419,
26,
272,
1015,
26,
267,
1369,
26,
288,
446,
812,
6495,
1015,
1329,
14,
267,
1415,
26,
2549,
267,
3415,
26,
788,
17,
297,
283,
18,
418,
199,
2344,
199,
8918,
275,
1449,
199,
3,
21587,
3942,
812,
6495,
15945,
2281,
499,
199,
13,
22072,
63,
86,
683,
63,
1023,
26,
272,
1015,
26,
499,
272,
1591,
26,
7370,
8200,
63,
4269,
7820,
272,
3434,
26,
7370,
625,
7820,
272,
2505,
26,
7370,
14374,
7820,
199,
2344,
199,
199,
9677,
275,
1449,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
1023,
582,
298,
18,
3570,
199,
5952,
26,
272,
1369,
26,
267,
446,
1022,
15,
86,
6342,
402,
3411,
373,
683,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
2261,
582,
298,
4776,
401,
298,
1023,
582,
298,
17,
401,
298,
86,
683,
63,
2060,
582,
1867,
3570,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
373,
683,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
2261,
582,
298,
4776,
401,
298,
1023,
582,
298,
18,
401,
298,
86,
683,
63,
2060,
582,
1867,
3570,
199,
7618,
26,
272,
1369,
26,
1414,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
86,
683,
1015,
499,
937,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
2344,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
421,
199,
646,
295,
199,
646,
295,
421,
199,
318,
5341,
63,
2384,
63,
1531,
8,
1531,
12,
859,
12,
1414,
63,
466,
534,
2764,
63,
2384,
735,
272,
340,
283,
1205,
7,
440,
315,
1414,
26,
267,
1072,
275,
283,
1001,
7,
272,
587,
26,
267,
1072,
275,
283,
505,
7,
272,
11465,
275,
8910,
267,
283,
1531,
356,
1414,
12,
267,
283,
1199,
356,
1072,
12,
272,
14877,
272,
2396,
275,
1255,
63,
4405,
8,
578,
12,
11465,
9,
272,
372,
2396,
421,
199,
318,
9378,
63,
513,
8,
1531,
63,
6717,
304,
272,
6829,
63,
1531,
63,
513,
275,
942,
272,
367,
1414,
315,
1414,
63,
6717,
26,
267,
340,
1228,
8,
1531,
12,
769,
304,
288,
6829,
63,
1531,
63,
513,
14,
2880,
8,
1531,
9,
267,
587,
26,
288,
6829,
63,
1531,
63,
513,
14,
740,
8,
1531,
9,
272,
372,
6829,
63,
1531,
63,
513,
421,
199,
318,
664,
63,
86,
683,
63,
888,
8,
578,
304,
272,
1414,
275,
283,
2384,
373,
683,
2004,
7,
272,
2396,
275,
5341,
63,
2384,
63,
1531,
8,
267,
1414,
12,
859,
2788,
16,
61,
272,
373,
683,
63,
6751,
275,
1052,
339,
340,
2396,
26,
267,
1015,
63,
3821,
275,
1987,
10,
54,
6495,
1015,
3879,
60,
83,
11,
3427,
83,
11,
2229,
48,
28,
1023,
3072,
68,
680,
10223,
267,
2881,
63,
3821,
275,
1987,
10,
54,
6495,
14061,
2812,
60,
83,
11,
3427,
83,
11,
2229,
48,
28,
2261,
3072,
51,
11,
680,
10223,
398,
862,
26,
288,
1336,
63,
1023,
275,
295,
14,
1431,
8,
1023,
63,
3821,
12,
2396,
12,
295,
14,
16504,
9,
288,
1015,
275,
1336,
63,
1023,
14,
20567,
12047,
1023,
418,
267,
871,
4281,
26,
288,
1015,
275,
2125,
398,
862,
26,
288,
1336,
63,
2261,
275,
295,
14,
1431,
8,
2261,
63,
3821,
12,
2396,
12,
295,
14,
16504,
9,
288,
2881,
275,
1336,
63,
2261,
14,
20567,
12047,
2261,
418,
267,
871,
4281,
26,
288,
2881,
275,
2125,
398,
340,
2881,
436,
1015,
26,
288,
373,
683,
63,
6751,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jasonwee/asus-rt-n14uhp-mrtg
|
tmp/ve_asus-rt-n14uhp-mrtg/lib/python3.4/site-packages/django/db/models/aggregates.py
|
65
|
6528
|
"""
Classes to represent the definitions of aggregate functions.
"""
from django.core.exceptions import FieldError
from django.db.models.expressions import Func, Star
from django.db.models.fields import FloatField, IntegerField
__all__ = [
'Aggregate', 'Avg', 'Count', 'Max', 'Min', 'StdDev', 'Sum', 'Variance',
]
class Aggregate(Func):
contains_aggregate = True
name = None
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
# Aggregates are not allowed in UPDATE queries, so ignore for_save
c = super(Aggregate, self).resolve_expression(query, allow_joins, reuse, summarize)
if not summarize:
expressions = c.get_source_expressions()
for index, expr in enumerate(expressions):
if expr.contains_aggregate:
before_resolved = self.get_source_expressions()[index]
name = before_resolved.name if hasattr(before_resolved, 'name') else repr(before_resolved)
raise FieldError("Cannot compute %s('%s'): '%s' is an aggregate" % (c.name, name, name))
c._patch_aggregate(query) # backward-compatibility support
return c
@property
def default_alias(self):
expressions = self.get_source_expressions()
if len(expressions) == 1 and hasattr(expressions[0], 'name'):
return '%s__%s' % (expressions[0].name, self.name.lower())
raise TypeError("Complex expressions require an alias")
def get_group_by_cols(self):
return []
def _patch_aggregate(self, query):
"""
Helper method for patching 3rd party aggregates that do not yet support
the new way of subclassing. This method will be removed in Django 1.10.
add_to_query(query, alias, col, source, is_summary) will be defined on
legacy aggregates which, in turn, instantiates the SQL implementation of
the aggregate. In all the cases found, the general implementation of
add_to_query looks like:
def add_to_query(self, query, alias, col, source, is_summary):
klass = SQLImplementationAggregate
aggregate = klass(col, source=source, is_summary=is_summary, **self.extra)
query.aggregates[alias] = aggregate
By supplying a known alias, we can get the SQLAggregate out of the
aggregates dict, and use the sql_function and sql_template attributes
to patch *this* aggregate.
"""
if not hasattr(self, 'add_to_query') or self.function is not None:
return
placeholder_alias = "_XXXXXXXX_"
self.add_to_query(query, placeholder_alias, None, None, None)
sql_aggregate = query.aggregates.pop(placeholder_alias)
if 'sql_function' not in self.extra and hasattr(sql_aggregate, 'sql_function'):
self.extra['function'] = sql_aggregate.sql_function
if hasattr(sql_aggregate, 'sql_template'):
self.extra['template'] = sql_aggregate.sql_template
class Avg(Aggregate):
function = 'AVG'
name = 'Avg'
def __init__(self, expression, **extra):
output_field = extra.pop('output_field', FloatField())
super(Avg, self).__init__(expression, output_field=output_field, **extra)
def as_oracle(self, compiler, connection):
if self.output_field.get_internal_type() == 'DurationField':
expression = self.get_source_expressions()[0]
from django.db.backends.oracle.functions import IntervalToSeconds, SecondsToInterval
return compiler.compile(
SecondsToInterval(Avg(IntervalToSeconds(expression)))
)
return super(Avg, self).as_sql(compiler, connection)
class Count(Aggregate):
function = 'COUNT'
name = 'Count'
template = '%(function)s(%(distinct)s%(expressions)s)'
def __init__(self, expression, distinct=False, **extra):
if expression == '*':
expression = Star()
super(Count, self).__init__(
expression, distinct='DISTINCT ' if distinct else '', output_field=IntegerField(), **extra)
def __repr__(self):
return "{}({}, distinct={})".format(
self.__class__.__name__,
self.arg_joiner.join(str(arg) for arg in self.source_expressions),
'False' if self.extra['distinct'] == '' else 'True',
)
def convert_value(self, value, expression, connection, context):
if value is None:
return 0
return int(value)
class Max(Aggregate):
function = 'MAX'
name = 'Max'
class Min(Aggregate):
function = 'MIN'
name = 'Min'
class StdDev(Aggregate):
name = 'StdDev'
def __init__(self, expression, sample=False, **extra):
self.function = 'STDDEV_SAMP' if sample else 'STDDEV_POP'
super(StdDev, self).__init__(expression, output_field=FloatField(), **extra)
def __repr__(self):
return "{}({}, sample={})".format(
self.__class__.__name__,
self.arg_joiner.join(str(arg) for arg in self.source_expressions),
'False' if self.function == 'STDDEV_POP' else 'True',
)
def convert_value(self, value, expression, connection, context):
if value is None:
return value
return float(value)
class Sum(Aggregate):
function = 'SUM'
name = 'Sum'
def as_oracle(self, compiler, connection):
if self.output_field.get_internal_type() == 'DurationField':
expression = self.get_source_expressions()[0]
from django.db.backends.oracle.functions import IntervalToSeconds, SecondsToInterval
return compiler.compile(
SecondsToInterval(Sum(IntervalToSeconds(expression)))
)
return super(Sum, self).as_sql(compiler, connection)
class Variance(Aggregate):
name = 'Variance'
def __init__(self, expression, sample=False, **extra):
self.function = 'VAR_SAMP' if sample else 'VAR_POP'
super(Variance, self).__init__(expression, output_field=FloatField(), **extra)
def __repr__(self):
return "{}({}, sample={})".format(
self.__class__.__name__,
self.arg_joiner.join(str(arg) for arg in self.source_expressions),
'False' if self.function == 'VAR_POP' else 'True',
)
def convert_value(self, value, expression, connection, context):
if value is None:
return value
return float(value)
|
apache-2.0
|
[
624,
199,
15711,
370,
2954,
314,
10269,
402,
9531,
3423,
14,
199,
624,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
14,
992,
14,
15264,
492,
28794,
12,
1933,
285,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
11140,
792,
12,
26141,
199,
199,
363,
452,
363,
275,
359,
272,
283,
10170,
297,
283,
16650,
297,
283,
2353,
297,
283,
4261,
297,
283,
4649,
297,
283,
11976,
12680,
297,
283,
6959,
297,
283,
31805,
297,
199,
61,
421,
199,
533,
29397,
8,
7465,
304,
272,
3509,
63,
7516,
275,
715,
272,
536,
275,
488,
339,
347,
7512,
63,
5599,
8,
277,
12,
1827,
29,
403,
12,
2040,
63,
20155,
29,
549,
12,
12598,
29,
403,
12,
22301,
29,
797,
12,
367,
63,
2117,
29,
797,
304,
267,
327,
21369,
2335,
787,
440,
4370,
315,
17148,
9212,
12,
880,
3686,
367,
63,
2117,
267,
286,
275,
1613,
8,
10170,
12,
291,
680,
6983,
63,
5599,
8,
1131,
12,
2040,
63,
20155,
12,
12598,
12,
22301,
9,
267,
340,
440,
22301,
26,
288,
8455,
275,
286,
14,
362,
63,
1365,
63,
15264,
342,
288,
367,
1478,
12,
5348,
315,
3874,
8,
15264,
304,
355,
340,
5348,
14,
6134,
63,
7516,
26,
490,
2544,
63,
13697,
275,
291,
14,
362,
63,
1365,
63,
15264,
3430,
1080,
61,
490,
536,
275,
2544,
63,
13697,
14,
354,
340,
2688,
8,
5182,
63,
13697,
12,
283,
354,
358,
587,
4700,
8,
5182,
63,
13697,
9,
490,
746,
27691,
480,
6612,
4526,
450,
83,
3508,
83,
735,
1543,
83,
7,
365,
376,
9531,
2,
450,
334,
67,
14,
354,
12,
536,
12,
536,
430,
267,
286,
423,
2068,
63,
7516,
8,
1131,
9,
221,
327,
13388,
13,
15390,
2291,
267,
372,
286,
339,
768,
1829,
272,
347,
849,
63,
3620,
8,
277,
304,
267,
8455,
275,
291,
14,
362,
63,
1365,
63,
15264,
342,
267,
340,
822,
8,
15264,
9,
508,
413,
436,
2688,
8,
15264,
59,
16,
467,
283,
354,
735,
288,
372,
1543,
83,
363,
5,
83,
7,
450,
334,
15264,
59,
16,
1055,
354,
12,
291,
14,
354,
14,
2325,
1012,
267,
746,
3146,
480,
14500,
8455,
4409,
376,
5162,
531,
339,
347,
664,
63,
923,
63,
991,
63,
4574,
8,
277,
304,
267,
372,
942,
339,
347,
485,
2068,
63,
7516,
8,
277,
12,
1827,
304,
267,
408,
267,
11642,
1083,
367,
3371,
316,
650,
6883,
17135,
27535,
626,
886,
440,
5966,
2291,
267,
314,
892,
4340,
402,
24572,
14,
961,
1083,
911,
506,
4829,
315,
5634,
413,
14,
709,
14,
398,
1050,
63,
475,
63,
1131,
8,
1131,
12,
5162,
12,
1048,
12,
1350,
12,
365,
63,
4705,
9,
911,
506,
3247,
641,
267,
12139,
27535,
1314,
12,
315,
7485,
12,
9034,
2335,
314,
5385,
4514,
402,
267,
314,
9531,
14,
1010,
1006,
314,
5560,
1911,
12,
314,
8605,
4514,
402,
267,
1050,
63,
475,
63,
1131,
10734,
2839,
26,
398,
347,
1050,
63,
475,
63,
1131,
8,
277,
12,
1827,
12,
5162,
12,
1048,
12,
1350,
12,
365,
63,
4705,
304,
288,
8531,
275,
428,
49,
2673,
575,
3117,
10170,
288,
9531,
275,
8531,
8,
761,
12,
1350,
29,
1365,
12,
365,
63,
4705,
29,
374,
63,
4705,
12,
1011,
277,
14,
2911,
9,
288,
1827,
14,
21622,
59,
3620,
61,
275,
9531,
398,
4885,
4973,
6670,
282,
6040,
5162,
12,
781,
883,
664,
314,
5385,
10170,
734,
402,
314,
267,
27535,
1211,
12,
436,
675,
314,
3875,
63,
1593,
436,
3875,
63,
1160,
3004,
267,
370,
3371,
627,
3749,
10,
9531,
14,
267,
408,
267,
340,
440,
2688,
8,
277,
12,
283,
525,
63,
475,
63,
1131,
358,
503,
291,
14,
1593,
365,
440,
488,
26,
288,
372,
398,
10069,
63,
3620,
275,
2668,
13312,
12172,
267,
291,
14,
525,
63,
475,
63,
1131,
8,
1131,
12,
10069,
63,
3620,
12,
488,
12,
488,
12,
488,
9,
267,
3875,
63,
7516,
275,
1827,
14,
21622,
14,
1935,
8,
6199,
63,
3620,
9,
267,
340,
283,
3009,
63,
1593,
7,
440,
315,
291,
14,
2911,
436,
2688,
8,
3009,
63,
7516,
12,
283,
3009,
63,
1593,
735,
288,
291,
14,
2911,
459,
1593,
418,
275,
3875,
63,
7516,
14,
3009,
63,
1593,
398,
340,
2688,
8,
3009,
63,
7516,
12,
283,
3009,
63,
1160,
735,
288,
291,
14,
2911,
459,
1160,
418,
275,
3875,
63,
7516,
14,
3009,
63,
1160,
421,
199,
533,
437,
10929,
8,
10170,
304,
272,
805,
275,
283,
6087,
39,
7,
272,
536,
275,
283,
16650,
7,
339,
347,
636,
826,
721,
277,
12,
3965,
12,
1011,
2911,
304,
267,
1072,
63,
698,
275,
2402,
14,
1935,
360,
1199,
63,
698,
297,
11140,
792,
1012,
267,
1613,
8,
16650,
12,
291,
2843,
826,
721,
5599,
12,
1072,
63,
698,
29,
1199,
63,
698,
12,
1011,
2911,
9,
339,
347,
465,
63,
16404,
8,
277,
12,
6365,
12,
1950,
304,
267,
340,
291,
14,
1199,
63,
698,
14,
362,
63,
4672,
63,
466,
342,
508,
283,
13283,
792,
356,
288,
3965,
275,
291,
14,
362,
63,
1365,
63,
15264,
3430,
16,
61,
288,
687,
1639,
14,
697,
14,
7765,
14,
16404,
14,
5777,
492,
18766,
1378,
13165,
12,
3240,
2776,
1378,
8227,
288,
372,
6365,
14,
2014,
8,
355,
3240,
2776,
1378,
8227,
8,
16650,
8,
8227,
1378,
13165,
8,
5599,
1724,
288,
776,
267,
372,
1613,
8,
16650,
12,
291,
680,
305,
63,
3009,
8,
5772,
12,
1950,
9,
421,
199,
533,
14826,
8,
10170,
304,
272,
805,
275,
283,
8760,
7,
272,
536,
275,
283,
2353,
7,
272,
1978,
275,
9487,
1593,
9,
83,
12473,
12926,
9,
83,
2840,
15264,
9,
83,
3171,
339,
347,
636,
826,
721,
277,
12,
3965,
12,
15392,
29,
797,
12,
1011,
2911,
304,
267,
340,
3965,
508,
22969,
288,
3965,
275,
1933,
285,
342,
267,
1613,
8,
2353,
12,
291,
2843,
826,
721,
288,
3965,
12,
15392,
534,
13783,
28437,
283,
340,
15392,
587,
3260,
1072,
63,
698,
29,
3901,
1062,
1011,
2911,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
11491,
16037,
15392,
21146,
1674,
908,
8,
288,
291,
855,
533,
4914,
354,
3108,
288,
291,
14,
1273,
63,
904,
281,
14,
904
] |
[
199,
15711,
370,
2954,
314,
10269,
402,
9531,
3423,
14,
199,
624,
199,
504,
1639,
14,
1018,
14,
3924,
492,
27691,
199,
504,
1639,
14,
697,
14,
992,
14,
15264,
492,
28794,
12,
1933,
285,
199,
504,
1639,
14,
697,
14,
992,
14,
955,
492,
11140,
792,
12,
26141,
199,
199,
363,
452,
363,
275,
359,
272,
283,
10170,
297,
283,
16650,
297,
283,
2353,
297,
283,
4261,
297,
283,
4649,
297,
283,
11976,
12680,
297,
283,
6959,
297,
283,
31805,
297,
199,
61,
421,
199,
533,
29397,
8,
7465,
304,
272,
3509,
63,
7516,
275,
715,
272,
536,
275,
488,
339,
347,
7512,
63,
5599,
8,
277,
12,
1827,
29,
403,
12,
2040,
63,
20155,
29,
549,
12,
12598,
29,
403,
12,
22301,
29,
797,
12,
367,
63,
2117,
29,
797,
304,
267,
327,
21369,
2335,
787,
440,
4370,
315,
17148,
9212,
12,
880,
3686,
367,
63,
2117,
267,
286,
275,
1613,
8,
10170,
12,
291,
680,
6983,
63,
5599,
8,
1131,
12,
2040,
63,
20155,
12,
12598,
12,
22301,
9,
267,
340,
440,
22301,
26,
288,
8455,
275,
286,
14,
362,
63,
1365,
63,
15264,
342,
288,
367,
1478,
12,
5348,
315,
3874,
8,
15264,
304,
355,
340,
5348,
14,
6134,
63,
7516,
26,
490,
2544,
63,
13697,
275,
291,
14,
362,
63,
1365,
63,
15264,
3430,
1080,
61,
490,
536,
275,
2544,
63,
13697,
14,
354,
340,
2688,
8,
5182,
63,
13697,
12,
283,
354,
358,
587,
4700,
8,
5182,
63,
13697,
9,
490,
746,
27691,
480,
6612,
4526,
450,
83,
3508,
83,
735,
1543,
83,
7,
365,
376,
9531,
2,
450,
334,
67,
14,
354,
12,
536,
12,
536,
430,
267,
286,
423,
2068,
63,
7516,
8,
1131,
9,
221,
327,
13388,
13,
15390,
2291,
267,
372,
286,
339,
768,
1829,
272,
347,
849,
63,
3620,
8,
277,
304,
267,
8455,
275,
291,
14,
362,
63,
1365,
63,
15264,
342,
267,
340,
822,
8,
15264,
9,
508,
413,
436,
2688,
8,
15264,
59,
16,
467,
283,
354,
735,
288,
372,
1543,
83,
363,
5,
83,
7,
450,
334,
15264,
59,
16,
1055,
354,
12,
291,
14,
354,
14,
2325,
1012,
267,
746,
3146,
480,
14500,
8455,
4409,
376,
5162,
531,
339,
347,
664,
63,
923,
63,
991,
63,
4574,
8,
277,
304,
267,
372,
942,
339,
347,
485,
2068,
63,
7516,
8,
277,
12,
1827,
304,
267,
408,
267,
11642,
1083,
367,
3371,
316,
650,
6883,
17135,
27535,
626,
886,
440,
5966,
2291,
267,
314,
892,
4340,
402,
24572,
14,
961,
1083,
911,
506,
4829,
315,
5634,
413,
14,
709,
14,
398,
1050,
63,
475,
63,
1131,
8,
1131,
12,
5162,
12,
1048,
12,
1350,
12,
365,
63,
4705,
9,
911,
506,
3247,
641,
267,
12139,
27535,
1314,
12,
315,
7485,
12,
9034,
2335,
314,
5385,
4514,
402,
267,
314,
9531,
14,
1010,
1006,
314,
5560,
1911,
12,
314,
8605,
4514,
402,
267,
1050,
63,
475,
63,
1131,
10734,
2839,
26,
398,
347,
1050,
63,
475,
63,
1131,
8,
277,
12,
1827,
12,
5162,
12,
1048,
12,
1350,
12,
365,
63,
4705,
304,
288,
8531,
275,
428,
49,
2673,
575,
3117,
10170,
288,
9531,
275,
8531,
8,
761,
12,
1350,
29,
1365,
12,
365,
63,
4705,
29,
374,
63,
4705,
12,
1011,
277,
14,
2911,
9,
288,
1827,
14,
21622,
59,
3620,
61,
275,
9531,
398,
4885,
4973,
6670,
282,
6040,
5162,
12,
781,
883,
664,
314,
5385,
10170,
734,
402,
314,
267,
27535,
1211,
12,
436,
675,
314,
3875,
63,
1593,
436,
3875,
63,
1160,
3004,
267,
370,
3371,
627,
3749,
10,
9531,
14,
267,
408,
267,
340,
440,
2688,
8,
277,
12,
283,
525,
63,
475,
63,
1131,
358,
503,
291,
14,
1593,
365,
440,
488,
26,
288,
372,
398,
10069,
63,
3620,
275,
2668,
13312,
12172,
267,
291,
14,
525,
63,
475,
63,
1131,
8,
1131,
12,
10069,
63,
3620,
12,
488,
12,
488,
12,
488,
9,
267,
3875,
63,
7516,
275,
1827,
14,
21622,
14,
1935,
8,
6199,
63,
3620,
9,
267,
340,
283,
3009,
63,
1593,
7,
440,
315,
291,
14,
2911,
436,
2688,
8,
3009,
63,
7516,
12,
283,
3009,
63,
1593,
735,
288,
291,
14,
2911,
459,
1593,
418,
275,
3875,
63,
7516,
14,
3009,
63,
1593,
398,
340,
2688,
8,
3009,
63,
7516,
12,
283,
3009,
63,
1160,
735,
288,
291,
14,
2911,
459,
1160,
418,
275,
3875,
63,
7516,
14,
3009,
63,
1160,
421,
199,
533,
437,
10929,
8,
10170,
304,
272,
805,
275,
283,
6087,
39,
7,
272,
536,
275,
283,
16650,
7,
339,
347,
636,
826,
721,
277,
12,
3965,
12,
1011,
2911,
304,
267,
1072,
63,
698,
275,
2402,
14,
1935,
360,
1199,
63,
698,
297,
11140,
792,
1012,
267,
1613,
8,
16650,
12,
291,
2843,
826,
721,
5599,
12,
1072,
63,
698,
29,
1199,
63,
698,
12,
1011,
2911,
9,
339,
347,
465,
63,
16404,
8,
277,
12,
6365,
12,
1950,
304,
267,
340,
291,
14,
1199,
63,
698,
14,
362,
63,
4672,
63,
466,
342,
508,
283,
13283,
792,
356,
288,
3965,
275,
291,
14,
362,
63,
1365,
63,
15264,
3430,
16,
61,
288,
687,
1639,
14,
697,
14,
7765,
14,
16404,
14,
5777,
492,
18766,
1378,
13165,
12,
3240,
2776,
1378,
8227,
288,
372,
6365,
14,
2014,
8,
355,
3240,
2776,
1378,
8227,
8,
16650,
8,
8227,
1378,
13165,
8,
5599,
1724,
288,
776,
267,
372,
1613,
8,
16650,
12,
291,
680,
305,
63,
3009,
8,
5772,
12,
1950,
9,
421,
199,
533,
14826,
8,
10170,
304,
272,
805,
275,
283,
8760,
7,
272,
536,
275,
283,
2353,
7,
272,
1978,
275,
9487,
1593,
9,
83,
12473,
12926,
9,
83,
2840,
15264,
9,
83,
3171,
339,
347,
636,
826,
721,
277,
12,
3965,
12,
15392,
29,
797,
12,
1011,
2911,
304,
267,
340,
3965,
508,
22969,
288,
3965,
275,
1933,
285,
342,
267,
1613,
8,
2353,
12,
291,
2843,
826,
721,
288,
3965,
12,
15392,
534,
13783,
28437,
283,
340,
15392,
587,
3260,
1072,
63,
698,
29,
3901,
1062,
1011,
2911,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
11491,
16037,
15392,
21146,
1674,
908,
8,
288,
291,
855,
533,
4914,
354,
3108,
288,
291,
14,
1273,
63,
904,
281,
14,
904,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
totallybradical/temp_servo2
|
tests/wpt/css-tests/tools/html5lib/html5lib/filters/whitespace.py
|
1730
|
1142
|
from __future__ import absolute_import, division, unicode_literals
import re
from . import _base
from ..constants import rcdataElements, spaceCharacters
spaceCharacters = "".join(spaceCharacters)
SPACES_REGEX = re.compile("[%s]+" % spaceCharacters)
class Filter(_base.Filter):
spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements))
def __iter__(self):
preserve = 0
for token in _base.Filter.__iter__(self):
type = token["type"]
if type == "StartTag" \
and (preserve or token["name"] in self.spacePreserveElements):
preserve += 1
elif type == "EndTag" and preserve:
preserve -= 1
elif not preserve and type == "SpaceCharacters" and token["data"]:
# Test on token["data"] above to not introduce spaces where there were not
token["data"] = " "
elif not preserve and type == "Characters":
token["data"] = collapse_spaces(token["data"])
yield token
def collapse_spaces(text):
return SPACES_REGEX.sub(' ', text)
|
mpl-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
485,
1095,
199,
504,
2508,
5559,
492,
4819,
576,
6255,
12,
25431,
199,
2638,
9272,
275,
10587,
904,
8,
2638,
9272,
9,
199,
199,
5763,
21287,
63,
10710,
275,
295,
14,
2014,
480,
9722,
83,
2807,
2,
450,
25431,
9,
421,
199,
533,
9388,
1547,
1095,
14,
4131,
304,
339,
4601,
2398,
4909,
6255,
275,
9522,
5234,
657,
401,
298,
20895,
937,
435,
769,
8,
1195,
576,
6255,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
11211,
275,
378,
267,
367,
1526,
315,
485,
1095,
14,
4131,
855,
1661,
721,
277,
304,
288,
730,
275,
1526,
905,
466,
937,
288,
340,
730,
508,
298,
17697,
2,
971,
490,
436,
334,
17053,
503,
1526,
905,
354,
937,
315,
291,
14,
2638,
2398,
4909,
6255,
304,
355,
11211,
847,
413,
953,
916,
730,
508,
298,
16906,
2,
436,
11211,
26,
355,
11211,
4862,
413,
953,
916,
440,
11211,
436,
730,
508,
298,
28501,
2,
436,
1526,
905,
576,
6229,
355,
327,
1379,
641,
1526,
905,
576,
937,
3432,
370,
440,
13318,
3402,
7883,
2382,
2337,
4898,
440,
355,
1526,
905,
576,
937,
275,
298,
298,
953,
916,
440,
11211,
436,
730,
508,
298,
9272,
582,
355,
1526,
905,
576,
937,
275,
24311,
63,
10749,
8,
1418,
905,
576,
3135,
953,
1995,
1526,
421,
199,
318,
24311,
63,
10749,
8,
505,
304,
272,
372,
6988,
21287,
63,
10710,
14,
954,
360,
1656,
1318,
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,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
485,
1095,
199,
504,
2508,
5559,
492,
4819,
576,
6255,
12,
25431,
199,
2638,
9272,
275,
10587,
904,
8,
2638,
9272,
9,
199,
199,
5763,
21287,
63,
10710,
275,
295,
14,
2014,
480,
9722,
83,
2807,
2,
450,
25431,
9,
421,
199,
533,
9388,
1547,
1095,
14,
4131,
304,
339,
4601,
2398,
4909,
6255,
275,
9522,
5234,
657,
401,
298,
20895,
937,
435,
769,
8,
1195,
576,
6255,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
11211,
275,
378,
267,
367,
1526,
315,
485,
1095,
14,
4131,
855,
1661,
721,
277,
304,
288,
730,
275,
1526,
905,
466,
937,
288,
340,
730,
508,
298,
17697,
2,
971,
490,
436,
334,
17053,
503,
1526,
905,
354,
937,
315,
291,
14,
2638,
2398,
4909,
6255,
304,
355,
11211,
847,
413,
953,
916,
730,
508,
298,
16906,
2,
436,
11211,
26,
355,
11211,
4862,
413,
953,
916,
440,
11211,
436,
730,
508,
298,
28501,
2,
436,
1526,
905,
576,
6229,
355,
327,
1379,
641,
1526,
905,
576,
937,
3432,
370,
440,
13318,
3402,
7883,
2382,
2337,
4898,
440,
355,
1526,
905,
576,
937,
275,
298,
298,
953,
916,
440,
11211,
436,
730,
508,
298,
9272,
582,
355,
1526,
905,
576,
937,
275,
24311,
63,
10749,
8,
1418,
905,
576,
3135,
953,
1995,
1526,
421,
199,
318,
24311,
63,
10749,
8,
505,
304,
272,
372,
6988,
21287,
63,
10710,
14,
954,
360,
1656,
1318,
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,
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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logging
from django import forms
from django.core.exceptions import ValidationError
from bulk_email.models import CourseEmailTemplate, COURSE_EMAIL_MESSAGE_BODY_TAG, CourseAuthorization
from opaque_keys import InvalidKeyError
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locations import SlashSeparatedCourseKey
log = logging.getLogger(__name__)
class CourseEmailTemplateForm(forms.ModelForm):
"""Form providing validation of CourseEmail templates."""
name = forms.CharField(required=False)
class Meta(object): # pylint: disable=missing-docstring
model = CourseEmailTemplate
fields = ('html_template', 'plain_template', 'name')
def _validate_template(self, template):
"""Check the template for required tags."""
index = template.find(COURSE_EMAIL_MESSAGE_BODY_TAG)
if index < 0:
msg = 'Missing tag: "{}"'.format(COURSE_EMAIL_MESSAGE_BODY_TAG)
log.warning(msg)
raise ValidationError(msg)
if template.find(COURSE_EMAIL_MESSAGE_BODY_TAG, index + 1) >= 0:
msg = 'Multiple instances of tag: "{}"'.format(COURSE_EMAIL_MESSAGE_BODY_TAG)
log.warning(msg)
raise ValidationError(msg)
# TODO: add more validation here, including the set of known tags
# for which values will be supplied. (Email will fail if the template
# uses tags for which values are not supplied.)
def clean_html_template(self):
"""Validate the HTML template."""
template = self.cleaned_data["html_template"]
self._validate_template(template)
return template
def clean_plain_template(self):
"""Validate the plaintext template."""
template = self.cleaned_data["plain_template"]
self._validate_template(template)
return template
def clean_name(self):
"""Validate the name field. Enforce uniqueness constraint on 'name' field"""
# Note that we get back a blank string in the Form for an empty 'name' field
# we want those to be set to None in Python and NULL in the database
name = self.cleaned_data.get("name").strip() or None
# if we are creating a new CourseEmailTemplate, then we need to
# enforce the uniquess constraint as part of the Form validation
if not self.instance.pk:
try:
CourseEmailTemplate.get_template(name)
# already exists, this is no good
raise ValidationError('Name of "{}" already exists, this must be unique.'.format(name))
except CourseEmailTemplate.DoesNotExist:
# this is actually the successful validation
pass
return name
class CourseAuthorizationAdminForm(forms.ModelForm):
"""Input form for email enabling, allowing us to verify data."""
class Meta(object): # pylint: disable=missing-docstring
model = CourseAuthorization
def clean_course_id(self):
"""Validate the course id"""
cleaned_id = self.cleaned_data["course_id"]
try:
course_key = CourseKey.from_string(cleaned_id)
except InvalidKeyError:
try:
course_key = SlashSeparatedCourseKey.from_deprecated_string(cleaned_id)
except InvalidKeyError:
msg = u'Course id invalid.'
msg += u' --- Entered course id was: "{0}". '.format(cleaned_id)
msg += 'Please recheck that you have supplied a valid course id.'
raise forms.ValidationError(msg)
if not modulestore().has_course(course_key):
msg = u'COURSE NOT FOUND'
msg += u' --- Entered course id was: "{0}". '.format(course_key.to_deprecated_string())
msg += 'Please recheck that you have supplied a valid course id.'
raise forms.ValidationError(msg)
# Now, try and discern if it is a Studio course - HTML editor doesn't work with XML courses
is_studio_course = modulestore().get_modulestore_type(course_key) != ModuleStoreEnum.Type.xml
if not is_studio_course:
msg = "Course Email feature is only available for courses authored in Studio. "
msg += '"{0}" appears to be an XML backed course.'.format(course_key.to_deprecated_string())
raise forms.ValidationError(msg)
return course_key
|
agpl-3.0
|
[
624,
199,
23891,
282,
1824,
367,
13070,
6411,
402,
5531,
7035,
7009,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
199,
504,
13137,
63,
2123,
14,
992,
492,
5531,
7035,
4231,
12,
5099,
14302,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
12,
5531,
11626,
199,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
5531,
7035,
4231,
2821,
8,
3351,
14,
15937,
304,
272,
408,
2821,
13070,
6411,
402,
5531,
7035,
7009,
1041,
339,
536,
275,
4513,
14,
2183,
8,
2427,
29,
797,
9,
339,
1021,
6288,
8,
785,
304,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
1402,
275,
5531,
7035,
4231,
267,
1504,
275,
661,
1360,
63,
1160,
297,
283,
6104,
63,
1160,
297,
283,
354,
358,
339,
347,
485,
3502,
63,
1160,
8,
277,
12,
1978,
304,
267,
408,
1799,
314,
1978,
367,
1415,
3762,
1041,
267,
1478,
275,
1978,
14,
1623,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
9,
267,
340,
1478,
665,
378,
26,
288,
1499,
275,
283,
7718,
1947,
26,
28168,
1370,
908,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
9,
288,
943,
14,
3764,
8,
1328,
9,
288,
746,
8505,
8,
1328,
9,
267,
340,
1978,
14,
1623,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
12,
1478,
435,
413,
9,
2356,
378,
26,
288,
1499,
275,
283,
8433,
4454,
402,
1947,
26,
28168,
1370,
908,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
9,
288,
943,
14,
3764,
8,
1328,
9,
288,
746,
8505,
8,
1328,
9,
267,
327,
3254,
26,
1050,
1655,
6411,
2348,
12,
5893,
314,
663,
402,
6040,
3762,
267,
327,
367,
1314,
1338,
911,
506,
6841,
14,
221,
334,
7035,
911,
2449,
340,
314,
1978,
267,
327,
4440,
3762,
367,
1314,
1338,
787,
440,
6841,
4959,
339,
347,
3633,
63,
1360,
63,
1160,
8,
277,
304,
267,
408,
12584,
314,
4163,
1978,
1041,
267,
1978,
275,
291,
14,
8275,
63,
576,
905,
1360,
63,
1160,
937,
267,
291,
423,
3502,
63,
1160,
8,
1160,
9,
267,
372,
1978,
339,
347,
3633,
63,
6104,
63,
1160,
8,
277,
304,
267,
408,
12584,
314,
18577,
1978,
1041,
267,
1978,
275,
291,
14,
8275,
63,
576,
905,
6104,
63,
1160,
937,
267,
291,
423,
3502,
63,
1160,
8,
1160,
9,
267,
372,
1978,
339,
347,
3633,
63,
354,
8,
277,
304,
267,
408,
12584,
314,
536,
901,
14,
3447,
3990,
15439,
31820,
5828,
641,
283,
354,
7,
901,
624,
398,
327,
3390,
626,
781,
664,
1771,
282,
4596,
1059,
315,
314,
8204,
367,
376,
2701,
283,
354,
7,
901,
267,
327,
781,
2934,
5204,
370,
506,
663,
370,
488,
315,
2018,
436,
5962,
315,
314,
3050,
267,
536,
275,
291,
14,
8275,
63,
576,
14,
362,
480,
354,
3471,
1913,
342,
503,
488,
398,
327,
340,
781,
787,
6425,
282,
892,
5531,
7035,
4231,
12,
2066,
781,
1929,
370,
267,
327,
15814,
314,
3747,
385,
5828,
465,
1777,
402,
314,
8204,
6411,
267,
340,
440,
291,
14,
842,
14,
2051,
26,
288,
862,
26,
355,
5531,
7035,
4231,
14,
362,
63,
1160,
8,
354,
9,
355,
327,
2575,
3495,
12,
642,
365,
949,
6954,
355,
746,
8505,
360,
985,
402,
28168,
2575,
3495,
12,
642,
1471,
506,
3747,
17374,
908,
8,
354,
430,
288,
871,
5531,
7035,
4231,
14,
7400,
26,
355,
327,
642,
365,
5965,
314,
9512,
6411,
355,
986,
267,
372,
536,
421,
199,
533,
5531,
11626,
4880,
2821,
8,
3351,
14,
15937,
304,
272,
408,
3205,
1824,
367,
3031,
29310,
12,
17266,
2739,
370,
4911,
666,
1041,
339,
1021,
6288,
8,
785,
304,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
1402,
275,
5531,
11626,
339,
347,
3633,
63,
1972,
63,
344,
8,
277,
304,
267,
408,
12584,
314,
2518,
1305,
624,
267,
12364,
63,
344,
275,
291,
14,
8275,
63,
576,
905,
1972,
63,
344,
937,
267,
862,
26,
288,
2518,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
8275,
63,
344,
9,
267,
871,
6378,
10230,
26,
288,
862,
26,
355,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
8275,
63,
344,
9,
288,
871,
6378,
10230,
26,
355,
1499,
275,
399,
7,
6979,
1305,
3866,
3530,
355,
1499,
847,
399,
7,
10894,
3447,
3014,
2518,
1305,
1990,
26,
5310,
16,
5469,
1987,
908,
8,
8275,
63,
344,
9,
355,
1499,
847,
283,
8254,
295,
1074,
626,
1265,
1172,
6841,
282,
1686,
2518,
1305,
3530,
355,
746,
4513,
14,
8172,
8,
1328,
9,
398,
340,
440,
10996,
1252,
1989,
63,
1972,
8,
1972,
63,
498,
304,
288,
1499,
275,
399,
7,
15552,
2845,
481,
47,
6131,
7,
288,
1499,
847,
399,
7,
10894,
3447,
3014,
2518,
1305,
1990,
26,
5310,
16,
5469,
1987,
908,
8,
1972,
63,
498,
14,
475,
63,
6667,
63,
875,
1012,
288,
1499,
847,
283,
8254,
295,
1074,
626,
1265,
1172,
6841,
282,
1686,
2518,
1305,
3530,
288,
746,
4513,
14,
8172,
8,
1328,
9,
398,
327,
7356,
12,
862,
436,
4339,
27569,
340,
652,
365,
282,
13225,
2518,
446,
4163,
8823,
3181,
1133,
1736,
543,
4692,
13588,
267,
365,
63,
19806,
63,
1972,
275,
10996,
1252,
362,
63,
10012,
63,
466,
8,
1972,
63,
498,
9,
1137,
23431,
14,
804,
14,
1652,
267,
340,
440,
365,
63,
19806,
63,
1972,
26,
288,
1499,
275,
298,
6979,
11426,
3878,
365,
1454,
2808,
367,
13588,
1790,
2908,
315,
13225,
14,
298,
288,
1499,
847,
5522,
91,
16,
7063,
11337,
370,
506,
376,
4692,
1771,
379,
2518,
17374,
908,
8,
1972,
63,
498,
14,
475,
63,
6667,
63,
875,
1012,
288,
746,
4513,
14,
8172,
8,
1328,
9,
398,
372,
2518,
63,
498,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
23891,
282,
1824,
367,
13070,
6411,
402,
5531,
7035,
7009,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1018,
14,
3924,
492,
8505,
199,
199,
504,
13137,
63,
2123,
14,
992,
492,
5531,
7035,
4231,
12,
5099,
14302,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
12,
5531,
11626,
199,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
15058,
63,
1612,
14,
8268,
14,
1612,
492,
22574,
199,
504,
15058,
63,
1612,
14,
8268,
14,
8022,
492,
30687,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
5531,
7035,
4231,
2821,
8,
3351,
14,
15937,
304,
272,
408,
2821,
13070,
6411,
402,
5531,
7035,
7009,
1041,
339,
536,
275,
4513,
14,
2183,
8,
2427,
29,
797,
9,
339,
1021,
6288,
8,
785,
304,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
1402,
275,
5531,
7035,
4231,
267,
1504,
275,
661,
1360,
63,
1160,
297,
283,
6104,
63,
1160,
297,
283,
354,
358,
339,
347,
485,
3502,
63,
1160,
8,
277,
12,
1978,
304,
267,
408,
1799,
314,
1978,
367,
1415,
3762,
1041,
267,
1478,
275,
1978,
14,
1623,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
9,
267,
340,
1478,
665,
378,
26,
288,
1499,
275,
283,
7718,
1947,
26,
28168,
1370,
908,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
9,
288,
943,
14,
3764,
8,
1328,
9,
288,
746,
8505,
8,
1328,
9,
267,
340,
1978,
14,
1623,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
12,
1478,
435,
413,
9,
2356,
378,
26,
288,
1499,
275,
283,
8433,
4454,
402,
1947,
26,
28168,
1370,
908,
8,
15552,
63,
10089,
63,
8272,
63,
23708,
63,
6967,
9,
288,
943,
14,
3764,
8,
1328,
9,
288,
746,
8505,
8,
1328,
9,
267,
327,
3254,
26,
1050,
1655,
6411,
2348,
12,
5893,
314,
663,
402,
6040,
3762,
267,
327,
367,
1314,
1338,
911,
506,
6841,
14,
221,
334,
7035,
911,
2449,
340,
314,
1978,
267,
327,
4440,
3762,
367,
1314,
1338,
787,
440,
6841,
4959,
339,
347,
3633,
63,
1360,
63,
1160,
8,
277,
304,
267,
408,
12584,
314,
4163,
1978,
1041,
267,
1978,
275,
291,
14,
8275,
63,
576,
905,
1360,
63,
1160,
937,
267,
291,
423,
3502,
63,
1160,
8,
1160,
9,
267,
372,
1978,
339,
347,
3633,
63,
6104,
63,
1160,
8,
277,
304,
267,
408,
12584,
314,
18577,
1978,
1041,
267,
1978,
275,
291,
14,
8275,
63,
576,
905,
6104,
63,
1160,
937,
267,
291,
423,
3502,
63,
1160,
8,
1160,
9,
267,
372,
1978,
339,
347,
3633,
63,
354,
8,
277,
304,
267,
408,
12584,
314,
536,
901,
14,
3447,
3990,
15439,
31820,
5828,
641,
283,
354,
7,
901,
624,
398,
327,
3390,
626,
781,
664,
1771,
282,
4596,
1059,
315,
314,
8204,
367,
376,
2701,
283,
354,
7,
901,
267,
327,
781,
2934,
5204,
370,
506,
663,
370,
488,
315,
2018,
436,
5962,
315,
314,
3050,
267,
536,
275,
291,
14,
8275,
63,
576,
14,
362,
480,
354,
3471,
1913,
342,
503,
488,
398,
327,
340,
781,
787,
6425,
282,
892,
5531,
7035,
4231,
12,
2066,
781,
1929,
370,
267,
327,
15814,
314,
3747,
385,
5828,
465,
1777,
402,
314,
8204,
6411,
267,
340,
440,
291,
14,
842,
14,
2051,
26,
288,
862,
26,
355,
5531,
7035,
4231,
14,
362,
63,
1160,
8,
354,
9,
355,
327,
2575,
3495,
12,
642,
365,
949,
6954,
355,
746,
8505,
360,
985,
402,
28168,
2575,
3495,
12,
642,
1471,
506,
3747,
17374,
908,
8,
354,
430,
288,
871,
5531,
7035,
4231,
14,
7400,
26,
355,
327,
642,
365,
5965,
314,
9512,
6411,
355,
986,
267,
372,
536,
421,
199,
533,
5531,
11626,
4880,
2821,
8,
3351,
14,
15937,
304,
272,
408,
3205,
1824,
367,
3031,
29310,
12,
17266,
2739,
370,
4911,
666,
1041,
339,
1021,
6288,
8,
785,
304,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
1402,
275,
5531,
11626,
339,
347,
3633,
63,
1972,
63,
344,
8,
277,
304,
267,
408,
12584,
314,
2518,
1305,
624,
267,
12364,
63,
344,
275,
291,
14,
8275,
63,
576,
905,
1972,
63,
344,
937,
267,
862,
26,
288,
2518,
63,
498,
275,
22574,
14,
504,
63,
875,
8,
8275,
63,
344,
9,
267,
871,
6378,
10230,
26,
288,
862,
26,
355,
2518,
63,
498,
275,
30687,
14,
504,
63,
6667,
63,
875,
8,
8275,
63,
344,
9,
288,
871,
6378,
10230,
26,
355,
1499,
275,
399,
7,
6979,
1305,
3866,
3530,
355,
1499,
847,
399,
7,
10894,
3447,
3014,
2518,
1305,
1990,
26,
5310,
16,
5469,
1987,
908,
8,
8275,
63,
344,
9,
355,
1499,
847,
283,
8254,
295,
1074,
626,
1265,
1172,
6841,
282,
1686,
2518,
1305,
3530,
355,
746,
4513,
14,
8172,
8,
1328,
9,
398,
340,
440,
10996,
1252,
1989,
63,
1972,
8,
1972,
63,
498,
304,
288,
1499,
275,
399,
7,
15552,
2845,
481,
47,
6131,
7,
288,
1499,
847,
399,
7,
10894,
3447,
3014,
2518,
1305,
1990,
26,
5310,
16,
5469,
1987,
908,
8,
1972,
63,
498,
14,
475,
63,
6667,
63,
875,
1012,
288,
1499,
847,
283,
8254,
295,
1074,
626,
1265,
1172,
6841,
282,
1686,
2518,
1305,
3530,
288,
746,
4513,
14,
8172,
8,
1328,
9,
398,
327,
7356,
12,
862,
436,
4339,
27569,
340,
652,
365,
282,
13225,
2518,
446,
4163,
8823,
3181,
1133,
1736,
543,
4692,
13588,
267,
365,
63,
19806,
63,
1972,
275,
10996,
1252,
362,
63,
10012,
63,
466,
8,
1972,
63,
498,
9,
1137,
23431,
14,
804,
14,
1652,
267,
340,
440,
365,
63,
19806,
63,
1972,
26,
288,
1499,
275,
298,
6979,
11426,
3878,
365,
1454,
2808,
367,
13588,
1790,
2908,
315,
13225,
14,
298,
288,
1499,
847,
5522,
91,
16,
7063,
11337,
370,
506,
376,
4692,
1771,
379,
2518,
17374,
908,
8,
1972,
63,
498,
14,
475,
63,
6667,
63,
875,
1012,
288,
746,
4513,
14,
8172,
8,
1328,
9,
398,
372,
2518,
63,
498,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Ahmad31/Web_Flask_Cassandra
|
flask/lib/python2.7/site-packages/wtforms/utils.py
|
194
|
1504
|
class UnsetValue(object):
"""
An unset value.
This is used in situations where a blank value like `None` is acceptable
usually as the default value of a class variable or function parameter
(iow, usually when `None` is a valid value.)
"""
def __str__(self):
return '<unset value>'
def __repr__(self):
return '<unset value>'
def __bool__(self):
return False
def __nonzero__(self):
return False
unset_value = UnsetValue()
class WebobInputWrapper(object):
"""
Wrap a webob MultiDict for use as passing as `formdata` to Field.
Since for consistency, we have decided in WTForms to support as input a
small subset of the API provided in common between cgi.FieldStorage,
Django's QueryDict, and Werkzeug's MultiDict, we need to wrap Webob, the
only supported framework whose multidict does not fit this API, but is
nevertheless used by a lot of frameworks.
While we could write a full wrapper to support all the methods, this will
undoubtedly result in bugs due to some subtle differences between the
various wrappers. So we will keep it simple.
"""
def __init__(self, multidict):
self._wrapped = multidict
def __iter__(self):
return iter(self._wrapped)
def __len__(self):
return len(self._wrapped)
def __contains__(self, name):
return (name in self._wrapped)
def getlist(self, name):
return self._wrapped.getall(name)
|
apache-2.0
|
[
199,
199,
533,
1910,
14733,
8,
785,
304,
272,
408,
272,
1626,
15376,
574,
14,
339,
961,
365,
1202,
315,
24325,
2382,
282,
4596,
574,
2839,
658,
403,
64,
365,
14712,
272,
9987,
465,
314,
849,
574,
402,
282,
1021,
1750,
503,
805,
2725,
272,
334,
73,
583,
12,
9987,
1380,
658,
403,
64,
365,
282,
1686,
574,
4959,
272,
408,
272,
347,
636,
495,
721,
277,
304,
267,
372,
2650,
16787,
574,
3524,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
16787,
574,
3524,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
756,
339,
347,
636,
10262,
721,
277,
304,
267,
372,
756,
199,
199,
16787,
63,
585,
275,
1910,
14733,
342,
421,
199,
533,
2136,
7913,
3205,
4590,
8,
785,
304,
272,
408,
272,
20322,
282,
14568,
29393,
367,
675,
465,
9476,
465,
658,
30942,
64,
370,
5024,
14,
339,
9336,
367,
17754,
12,
781,
1172,
12985,
770,
315,
644,
52,
26028,
370,
2291,
465,
1324,
282,
272,
7425,
10026,
402,
314,
3261,
2741,
315,
2863,
3382,
16004,
14,
792,
6408,
12,
272,
5634,
1159,
8133,
2141,
12,
436,
22798,
1159,
29393,
12,
781,
1929,
370,
4816,
2136,
7913,
12,
314,
272,
1454,
3748,
10059,
7447,
3510,
807,
1630,
440,
5542,
642,
3261,
12,
1325,
365,
272,
7078,
1589,
2003,
1202,
701,
282,
13918,
402,
10059,
83,
14,
339,
22117,
781,
4293,
2218,
282,
2615,
4975,
370,
2291,
1006,
314,
3102,
12,
642,
911,
272,
18172,
456,
471,
590,
754,
315,
18227,
7037,
370,
2005,
1007,
1118,
15109,
3382,
314,
272,
7750,
17995,
14,
2002,
781,
911,
4215,
652,
3486,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3510,
807,
304,
267,
291,
423,
9130,
275,
3510,
807,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
9130,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
423,
9130,
9,
339,
347,
636,
6134,
721,
277,
12,
536,
304,
267,
372,
334,
354,
315,
291,
423,
9130,
9,
339,
347,
664,
513,
8,
277,
12,
536,
304,
267,
372,
291,
423,
9130,
14,
362,
452,
8,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
533,
1910,
14733,
8,
785,
304,
272,
408,
272,
1626,
15376,
574,
14,
339,
961,
365,
1202,
315,
24325,
2382,
282,
4596,
574,
2839,
658,
403,
64,
365,
14712,
272,
9987,
465,
314,
849,
574,
402,
282,
1021,
1750,
503,
805,
2725,
272,
334,
73,
583,
12,
9987,
1380,
658,
403,
64,
365,
282,
1686,
574,
4959,
272,
408,
272,
347,
636,
495,
721,
277,
304,
267,
372,
2650,
16787,
574,
3524,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
16787,
574,
3524,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
756,
339,
347,
636,
10262,
721,
277,
304,
267,
372,
756,
199,
199,
16787,
63,
585,
275,
1910,
14733,
342,
421,
199,
533,
2136,
7913,
3205,
4590,
8,
785,
304,
272,
408,
272,
20322,
282,
14568,
29393,
367,
675,
465,
9476,
465,
658,
30942,
64,
370,
5024,
14,
339,
9336,
367,
17754,
12,
781,
1172,
12985,
770,
315,
644,
52,
26028,
370,
2291,
465,
1324,
282,
272,
7425,
10026,
402,
314,
3261,
2741,
315,
2863,
3382,
16004,
14,
792,
6408,
12,
272,
5634,
1159,
8133,
2141,
12,
436,
22798,
1159,
29393,
12,
781,
1929,
370,
4816,
2136,
7913,
12,
314,
272,
1454,
3748,
10059,
7447,
3510,
807,
1630,
440,
5542,
642,
3261,
12,
1325,
365,
272,
7078,
1589,
2003,
1202,
701,
282,
13918,
402,
10059,
83,
14,
339,
22117,
781,
4293,
2218,
282,
2615,
4975,
370,
2291,
1006,
314,
3102,
12,
642,
911,
272,
18172,
456,
471,
590,
754,
315,
18227,
7037,
370,
2005,
1007,
1118,
15109,
3382,
314,
272,
7750,
17995,
14,
2002,
781,
911,
4215,
652,
3486,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3510,
807,
304,
267,
291,
423,
9130,
275,
3510,
807,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
9130,
9,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
423,
9130,
9,
339,
347,
636,
6134,
721,
277,
12,
536,
304,
267,
372,
334,
354,
315,
291,
423,
9130,
9,
339,
347,
664,
513,
8,
277,
12,
536,
304,
267,
372,
291,
423,
9130,
14,
362,
452,
8,
354,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
sivel/ansible-modules-extras
|
network/illumos/dladm_etherstub.py
|
48
|
4629
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2015, 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 = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: dladm_etherstub
short_description: Manage etherstubs on Solaris/illumos systems.
description:
- Create or delete etherstubs on Solaris/illumos systems.
version_added: "2.2"
author: Adam Števko (@xen0l)
options:
name:
description:
- Etherstub name.
required: true
temporary:
description:
- Specifies that the etherstub is temporary. Temporary etherstubs
do not persist across reboots.
required: false
default: false
choices: [ "true", "false" ]
state:
description:
- Create or delete Solaris/illumos etherstub.
required: false
default: "present"
choices: [ "present", "absent" ]
'''
EXAMPLES = '''
# Create 'stub0' etherstub
- dladm_etherstub:
name: stub0
state: present
# Remove 'stub0 etherstub
- dladm_etherstub:
name: stub0
state: absent
'''
RETURN = '''
name:
description: etherstub name
returned: always
type: string
sample: "switch0"
state:
description: state of the target
returned: always
type: string
sample: "present"
temporary:
description: etherstub's persistence
returned: always
type: boolean
sample: "True"
'''
class Etherstub(object):
def __init__(self, module):
self.module = module
self.name = module.params['name']
self.temporary = module.params['temporary']
self.state = module.params['state']
def etherstub_exists(self):
cmd = [self.module.get_bin_path('dladm', True)]
cmd.append('show-etherstub')
cmd.append(self.name)
(rc, _, _) = self.module.run_command(cmd)
if rc == 0:
return True
else:
return False
def create_etherstub(self):
cmd = [self.module.get_bin_path('dladm', True)]
cmd.append('create-etherstub')
if self.temporary:
cmd.append('-t')
cmd.append(self.name)
return self.module.run_command(cmd)
def delete_etherstub(self):
cmd = [self.module.get_bin_path('dladm', True)]
cmd.append('delete-etherstub')
if self.temporary:
cmd.append('-t')
cmd.append(self.name)
return self.module.run_command(cmd)
def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(required=True),
temporary=dict(default=False, type='bool'),
state=dict(default='present', choices=['absent', 'present']),
),
supports_check_mode=True
)
etherstub = Etherstub(module)
rc = None
out = ''
err = ''
result = {}
result['name'] = etherstub.name
result['state'] = etherstub.state
result['temporary'] = etherstub.temporary
if etherstub.state == 'absent':
if etherstub.etherstub_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = etherstub.delete_etherstub()
if rc != 0:
module.fail_json(name=etherstub.name, msg=err, rc=rc)
elif etherstub.state == 'present':
if not etherstub.etherstub_exists():
if module.check_mode:
module.exit_json(changed=True)
(rc, out, err) = etherstub.create_etherstub()
if rc is not None and rc != 0:
module.fail_json(name=etherstub.name, msg=err, rc=rc)
if rc is None:
result['changed'] = False
else:
result['changed'] = True
if out:
result['stdout'] = out
if err:
result['stderr'] = err
module.exit_json(**result)
from ansible.module_utils.basic import *
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,
6900,
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,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
15396,
14464,
63,
27732,
5811,
199,
3612,
63,
1802,
26,
14944,
30201,
8957,
641,
17991,
4663,
15,
778,
453,
736,
10460,
14,
199,
1802,
26,
272,
446,
2790,
503,
3145,
30201,
8957,
641,
17991,
4663,
15,
778,
453,
736,
10460,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
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,
662,
728,
5811,
536,
14,
267,
1415,
26,
2549,
272,
7937,
26,
267,
1369,
26,
288,
446,
11015,
626,
314,
30201,
5811,
365,
7937,
14,
21791,
30201,
8957,
1598,
886,
440,
22400,
9371,
19457,
83,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
267,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
272,
1174,
26,
267,
1369,
26,
288,
446,
2790,
503,
3145,
17991,
4663,
15,
778,
453,
736,
30201,
5811,
14,
267,
1415,
26,
3055,
267,
849,
26,
298,
1881,
2,
267,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
283,
5811,
16,
7,
30201,
5811,
199,
13,
15396,
14464,
63,
27732,
5811,
26,
272,
536,
26,
10098,
16,
272,
1174,
26,
3451,
199,
199,
3,
5852,
283,
5811,
16,
30201,
5811,
199,
13,
15396,
14464,
63,
27732,
5811,
26,
272,
536,
26,
10098,
16,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
354,
26,
272,
1369,
26,
30201,
5811,
536,
272,
2138,
26,
3544,
272,
730,
26,
1059,
272,
2690,
26,
298,
5656,
16,
2,
199,
929,
26,
272,
1369,
26,
1174,
402,
314,
1347,
272,
2138,
26,
3544,
272,
730,
26,
1059,
272,
2690,
26,
298,
1881,
2,
199,
13555,
26,
272,
1369,
26,
30201,
5811,
1159,
26882,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
298,
549,
2,
199,
2344,
421,
199,
533,
662,
728,
5811,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
398,
291,
14,
354,
275,
859,
14,
1162,
459,
354,
418,
267,
291,
14,
13555,
275,
859,
14,
1162,
459,
13555,
418,
267,
291,
14,
929,
275,
859,
14,
1162,
459,
929,
418,
339,
347,
30201,
5811,
63,
2444,
8,
277,
304,
267,
2088,
275,
359,
277,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
5030,
14464,
297,
715,
1874,
398,
2088,
14,
740,
360,
2384,
13,
27732,
5811,
358,
267,
2088,
14,
740,
8,
277,
14,
354,
9,
398,
334,
1195,
12,
5501,
20795,
275,
291,
14,
578,
14,
1065,
63,
1531,
8,
1760,
9,
398,
340,
4819,
508,
378,
26,
288,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
1218,
63,
27732,
5811,
8,
277,
304,
267,
2088,
275,
359,
277,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
5030,
14464,
297,
715,
1874,
398,
2088,
14,
740,
360,
981,
13,
27732,
5811,
358,
398,
340,
291,
14,
13555,
26,
288,
2088,
14,
740,
3654,
84,
358,
267,
2088,
14,
740,
8,
277,
14,
354,
9,
398,
372,
291,
14,
578,
14,
1065,
63,
1531,
8,
1760,
9,
339,
347,
3145,
63,
27732,
5811,
8,
277,
304,
267,
2088,
275,
359,
277,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
5030,
14464,
297,
715,
1874,
398,
2088,
14,
740,
360,
1807,
13,
27732,
5811,
358,
398,
340,
291,
14,
13555,
26,
288,
2088,
14,
740,
3654,
84,
358,
267,
2088,
14,
740,
8,
277,
14,
354,
9,
398,
372,
291,
14,
578,
14,
1065,
63,
1531,
8,
1760,
9,
421,
199,
318,
2446,
837,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
536,
29,
807,
8,
2427,
29,
549,
395,
288,
7937,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
549,
272,
776,
339,
30201,
5811,
275,
662,
728,
5811,
8,
578,
9,
339,
4819,
275,
488,
272,
734,
275,
2125,
272,
2329,
275,
2125,
272,
754,
275,
1052,
272,
754,
459,
354,
418,
275,
30201,
5811,
14,
354,
272,
754,
459,
929,
418,
275,
30201,
5811,
14,
929,
272,
754,
459,
13555,
418,
275,
30201,
5811,
14,
13555,
339,
340,
30201,
5811,
14,
929,
508,
283,
5575,
356,
267,
340,
30201,
5811,
14,
27732,
5811,
63,
2444,
837,
288,
340,
859,
14,
1074,
63,
632,
26,
355,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
288,
334,
1195,
12,
734,
12,
2329,
9,
275,
30201,
5811,
14,
1807,
63,
27732,
5811,
342,
288,
340,
4819,
1137,
378,
26,
355,
859,
14,
1633,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
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,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
15396,
14464,
63,
27732,
5811,
199,
3612,
63,
1802,
26,
14944,
30201,
8957,
641,
17991,
4663,
15,
778,
453,
736,
10460,
14,
199,
1802,
26,
272,
446,
2790,
503,
3145,
30201,
8957,
641,
17991,
4663,
15,
778,
453,
736,
10460,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
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,
662,
728,
5811,
536,
14,
267,
1415,
26,
2549,
272,
7937,
26,
267,
1369,
26,
288,
446,
11015,
626,
314,
30201,
5811,
365,
7937,
14,
21791,
30201,
8957,
1598,
886,
440,
22400,
9371,
19457,
83,
14,
267,
1415,
26,
3055,
267,
849,
26,
3055,
267,
3415,
26,
359,
298,
2052,
401,
298,
3910,
2,
1622,
272,
1174,
26,
267,
1369,
26,
288,
446,
2790,
503,
3145,
17991,
4663,
15,
778,
453,
736,
30201,
5811,
14,
267,
1415,
26,
3055,
267,
849,
26,
298,
1881,
2,
267,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
2790,
283,
5811,
16,
7,
30201,
5811,
199,
13,
15396,
14464,
63,
27732,
5811,
26,
272,
536,
26,
10098,
16,
272,
1174,
26,
3451,
199,
199,
3,
5852,
283,
5811,
16,
30201,
5811,
199,
13,
15396,
14464,
63,
27732,
5811,
26,
272,
536,
26,
10098,
16,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
354,
26,
272,
1369,
26,
30201,
5811,
536,
272,
2138,
26,
3544,
272,
730,
26,
1059,
272,
2690,
26,
298,
5656,
16,
2,
199,
929,
26,
272,
1369,
26,
1174,
402,
314,
1347,
272,
2138,
26,
3544,
272,
730,
26,
1059,
272,
2690,
26,
298,
1881,
2,
199,
13555,
26,
272,
1369,
26,
30201,
5811,
1159,
26882,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
298,
549,
2,
199,
2344,
421,
199,
533,
662,
728,
5811,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
859,
304,
267,
291,
14,
578,
275,
859,
398,
291,
14,
354,
275,
859,
14,
1162,
459,
354,
418,
267,
291,
14,
13555,
275,
859,
14,
1162,
459,
13555,
418,
267,
291,
14,
929,
275,
859,
14,
1162,
459,
929,
418,
339,
347,
30201,
5811,
63,
2444,
8,
277,
304,
267,
2088,
275,
359,
277,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
5030,
14464,
297,
715,
1874,
398,
2088,
14,
740,
360,
2384,
13,
27732,
5811,
358,
267,
2088,
14,
740,
8,
277,
14,
354,
9,
398,
334,
1195,
12,
5501,
20795,
275,
291,
14,
578,
14,
1065,
63,
1531,
8,
1760,
9,
398,
340,
4819,
508,
378,
26,
288,
372,
715,
267,
587,
26,
288,
372,
756,
339,
347,
1218,
63,
27732,
5811,
8,
277,
304,
267,
2088,
275,
359,
277,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
5030,
14464,
297,
715,
1874,
398,
2088,
14,
740,
360,
981,
13,
27732,
5811,
358,
398,
340,
291,
14,
13555,
26,
288,
2088,
14,
740,
3654,
84,
358,
267,
2088,
14,
740,
8,
277,
14,
354,
9,
398,
372,
291,
14,
578,
14,
1065,
63,
1531,
8,
1760,
9,
339,
347,
3145,
63,
27732,
5811,
8,
277,
304,
267,
2088,
275,
359,
277,
14,
578,
14,
362,
63,
1393,
63,
515,
360,
5030,
14464,
297,
715,
1874,
398,
2088,
14,
740,
360,
1807,
13,
27732,
5811,
358,
398,
340,
291,
14,
13555,
26,
288,
2088,
14,
740,
3654,
84,
358,
267,
2088,
14,
740,
8,
277,
14,
354,
9,
398,
372,
291,
14,
578,
14,
1065,
63,
1531,
8,
1760,
9,
421,
199,
318,
2446,
837,
272,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
536,
29,
807,
8,
2427,
29,
549,
395,
288,
7937,
29,
807,
8,
885,
29,
797,
12,
730,
534,
2245,
659,
288,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
549,
272,
776,
339,
30201,
5811,
275,
662,
728,
5811,
8,
578,
9,
339,
4819,
275,
488,
272,
734,
275,
2125,
272,
2329,
275,
2125,
272,
754,
275,
1052,
272,
754,
459,
354,
418,
275,
30201,
5811,
14,
354,
272,
754,
459,
929,
418,
275,
30201,
5811,
14,
929,
272,
754,
459,
13555,
418,
275,
30201,
5811,
14,
13555,
339,
340,
30201,
5811,
14,
929,
508,
283,
5575,
356,
267,
340,
30201,
5811,
14,
27732,
5811,
63,
2444,
837,
288,
340,
859,
14,
1074,
63,
632,
26,
355,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
288,
334,
1195,
12,
734,
12,
2329,
9,
275,
30201,
5811,
14,
1807,
63,
27732,
5811,
342,
288,
340,
4819,
1137,
378,
26,
355,
859,
14,
1633,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
kerr-huang/SL4A
|
python-build/python-libs/python-twitter/twitter.py
|
89
|
70251
|
#!/usr/bin/python2.4
#
# Copyright 2007 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''A library that provides a python interface to the Twitter API'''
__author__ = 'dewitt@google.com'
__version__ = '0.7-devel'
import base64
import calendar
import httplib
import os
import rfc822
import simplejson
import sys
import tempfile
import textwrap
import time
import urllib
import urllib2
import urlparse
try:
from hashlib import md5
except ImportError:
from md5 import md5
CHARACTER_LIMIT = 140
# A singleton representing a lazily instantiated FileCache.
DEFAULT_CACHE = object()
class TwitterError(Exception):
'''Base class for Twitter errors'''
@property
def message(self):
'''Returns the first argument used to construct this error.'''
return self.args[0]
class Status(object):
'''A class representing the Status structure used by the twitter API.
The Status structure exposes the following properties:
status.created_at
status.created_at_in_seconds # read only
status.favorited
status.in_reply_to_screen_name
status.in_reply_to_user_id
status.in_reply_to_status_id
status.truncated
status.source
status.id
status.text
status.relative_created_at # read only
status.user
'''
def __init__(self,
created_at=None,
favorited=None,
id=None,
text=None,
user=None,
in_reply_to_screen_name=None,
in_reply_to_user_id=None,
in_reply_to_status_id=None,
truncated=None,
source=None,
now=None):
'''An object to hold a Twitter status message.
This class is normally instantiated by the twitter.Api class and
returned in a sequence.
Note: Dates are posted in the form "Sat Jan 27 04:17:38 +0000 2007"
Args:
created_at: The time this status message was posted
favorited: Whether this is a favorite of the authenticated user
id: The unique id of this status message
text: The text of this status message
relative_created_at:
A human readable string representing the posting time
user:
A twitter.User instance representing the person posting the message
now:
The current time, if the client choses to set it. Defaults to the
wall clock time.
'''
self.created_at = created_at
self.favorited = favorited
self.id = id
self.text = text
self.user = user
self.now = now
self.in_reply_to_screen_name = in_reply_to_screen_name
self.in_reply_to_user_id = in_reply_to_user_id
self.in_reply_to_status_id = in_reply_to_status_id
self.truncated = truncated
self.source = source
def GetCreatedAt(self):
'''Get the time this status message was posted.
Returns:
The time this status message was posted
'''
return self._created_at
def SetCreatedAt(self, created_at):
'''Set the time this status message was posted.
Args:
created_at: The time this status message was created
'''
self._created_at = created_at
created_at = property(GetCreatedAt, SetCreatedAt,
doc='The time this status message was posted.')
def GetCreatedAtInSeconds(self):
'''Get the time this status message was posted, in seconds since the epoch.
Returns:
The time this status message was posted, in seconds since the epoch.
'''
return calendar.timegm(rfc822.parsedate(self.created_at))
created_at_in_seconds = property(GetCreatedAtInSeconds,
doc="The time this status message was "
"posted, in seconds since the epoch")
def GetFavorited(self):
'''Get the favorited setting of this status message.
Returns:
True if this status message is favorited; False otherwise
'''
return self._favorited
def SetFavorited(self, favorited):
'''Set the favorited state of this status message.
Args:
favorited: boolean True/False favorited state of this status message
'''
self._favorited = favorited
favorited = property(GetFavorited, SetFavorited,
doc='The favorited state of this status message.')
def GetId(self):
'''Get the unique id of this status message.
Returns:
The unique id of this status message
'''
return self._id
def SetId(self, id):
'''Set the unique id of this status message.
Args:
id: The unique id of this status message
'''
self._id = id
id = property(GetId, SetId,
doc='The unique id of this status message.')
def GetInReplyToScreenName(self):
return self._in_reply_to_screen_name
def SetInReplyToScreenName(self, in_reply_to_screen_name):
self._in_reply_to_screen_name = in_reply_to_screen_name
in_reply_to_screen_name = property(GetInReplyToScreenName, SetInReplyToScreenName,
doc='')
def GetInReplyToUserId(self):
return self._in_reply_to_user_id
def SetInReplyToUserId(self, in_reply_to_user_id):
self._in_reply_to_user_id = in_reply_to_user_id
in_reply_to_user_id = property(GetInReplyToUserId, SetInReplyToUserId,
doc='')
def GetInReplyToStatusId(self):
return self._in_reply_to_status_id
def SetInReplyToStatusId(self, in_reply_to_status_id):
self._in_reply_to_status_id = in_reply_to_status_id
in_reply_to_status_id = property(GetInReplyToStatusId, SetInReplyToStatusId,
doc='')
def GetTruncated(self):
return self._truncated
def SetTruncated(self, truncated):
self._truncated = truncated
truncated = property(GetTruncated, SetTruncated,
doc='')
def GetSource(self):
return self._source
def SetSource(self, source):
self._source = source
source = property(GetSource, SetSource,
doc='')
def GetText(self):
'''Get the text of this status message.
Returns:
The text of this status message.
'''
return self._text
def SetText(self, text):
'''Set the text of this status message.
Args:
text: The text of this status message
'''
self._text = text
text = property(GetText, SetText,
doc='The text of this status message')
def GetRelativeCreatedAt(self):
'''Get a human redable string representing the posting time
Returns:
A human readable string representing the posting time
'''
fudge = 1.25
delta = long(self.now) - long(self.created_at_in_seconds)
if delta < (1 * fudge):
return 'about a second ago'
elif delta < (60 * (1/fudge)):
return 'about %d seconds ago' % (delta)
elif delta < (60 * fudge):
return 'about a minute ago'
elif delta < (60 * 60 * (1/fudge)):
return 'about %d minutes ago' % (delta / 60)
elif delta < (60 * 60 * fudge):
return 'about an hour ago'
elif delta < (60 * 60 * 24 * (1/fudge)):
return 'about %d hours ago' % (delta / (60 * 60))
elif delta < (60 * 60 * 24 * fudge):
return 'about a day ago'
else:
return 'about %d days ago' % (delta / (60 * 60 * 24))
relative_created_at = property(GetRelativeCreatedAt,
doc='Get a human readable string representing'
'the posting time')
def GetUser(self):
'''Get a twitter.User reprenting the entity posting this status message.
Returns:
A twitter.User reprenting the entity posting this status message
'''
return self._user
def SetUser(self, user):
'''Set a twitter.User reprenting the entity posting this status message.
Args:
user: A twitter.User reprenting the entity posting this status message
'''
self._user = user
user = property(GetUser, SetUser,
doc='A twitter.User reprenting the entity posting this '
'status message')
def GetNow(self):
'''Get the wallclock time for this status message.
Used to calculate relative_created_at. Defaults to the time
the object was instantiated.
Returns:
Whatever the status instance believes the current time to be,
in seconds since the epoch.
'''
if self._now is None:
self._now = time.time()
return self._now
def SetNow(self, now):
'''Set the wallclock time for this status message.
Used to calculate relative_created_at. Defaults to the time
the object was instantiated.
Args:
now: The wallclock time for this instance.
'''
self._now = now
now = property(GetNow, SetNow,
doc='The wallclock time for this status instance.')
def __ne__(self, other):
return not self.__eq__(other)
def __eq__(self, other):
try:
return other and \
self.created_at == other.created_at and \
self.id == other.id and \
self.text == other.text and \
self.user == other.user and \
self.in_reply_to_screen_name == other.in_reply_to_screen_name and \
self.in_reply_to_user_id == other.in_reply_to_user_id and \
self.in_reply_to_status_id == other.in_reply_to_status_id and \
self.truncated == other.truncated and \
self.favorited == other.favorited and \
self.source == other.source
except AttributeError:
return False
def __str__(self):
'''A string representation of this twitter.Status instance.
The return value is the same as the JSON string representation.
Returns:
A string representation of this twitter.Status instance.
'''
return self.AsJsonString()
def AsJsonString(self):
'''A JSON string representation of this twitter.Status instance.
Returns:
A JSON string representation of this twitter.Status instance
'''
return simplejson.dumps(self.AsDict(), sort_keys=True)
def AsDict(self):
'''A dict representation of this twitter.Status instance.
The return value uses the same key names as the JSON representation.
Return:
A dict representing this twitter.Status instance
'''
data = {}
if self.created_at:
data['created_at'] = self.created_at
if self.favorited:
data['favorited'] = self.favorited
if self.id:
data['id'] = self.id
if self.text:
data['text'] = self.text
if self.user:
data['user'] = self.user.AsDict()
if self.in_reply_to_screen_name:
data['in_reply_to_screen_name'] = self.in_reply_to_screen_name
if self.in_reply_to_user_id:
data['in_reply_to_user_id'] = self.in_reply_to_user_id
if self.in_reply_to_status_id:
data['in_reply_to_status_id'] = self.in_reply_to_status_id
if self.truncated is not None:
data['truncated'] = self.truncated
if self.favorited is not None:
data['favorited'] = self.favorited
if self.source:
data['source'] = self.source
return data
@staticmethod
def NewFromJsonDict(data):
'''Create a new instance based on a JSON dict.
Args:
data: A JSON dict, as converted from the JSON in the twitter API
Returns:
A twitter.Status instance
'''
if 'user' in data:
user = User.NewFromJsonDict(data['user'])
else:
user = None
return Status(created_at=data.get('created_at', None),
favorited=data.get('favorited', None),
id=data.get('id', None),
text=data.get('text', None),
in_reply_to_screen_name=data.get('in_reply_to_screen_name', None),
in_reply_to_user_id=data.get('in_reply_to_user_id', None),
in_reply_to_status_id=data.get('in_reply_to_status_id', None),
truncated=data.get('truncated', None),
source=data.get('source', None),
user=user)
class User(object):
'''A class representing the User structure used by the twitter API.
The User structure exposes the following properties:
user.id
user.name
user.screen_name
user.location
user.description
user.profile_image_url
user.profile_background_tile
user.profile_background_image_url
user.profile_sidebar_fill_color
user.profile_background_color
user.profile_link_color
user.profile_text_color
user.protected
user.utc_offset
user.time_zone
user.url
user.status
user.statuses_count
user.followers_count
user.friends_count
user.favourites_count
'''
def __init__(self,
id=None,
name=None,
screen_name=None,
location=None,
description=None,
profile_image_url=None,
profile_background_tile=None,
profile_background_image_url=None,
profile_sidebar_fill_color=None,
profile_background_color=None,
profile_link_color=None,
profile_text_color=None,
protected=None,
utc_offset=None,
time_zone=None,
followers_count=None,
friends_count=None,
statuses_count=None,
favourites_count=None,
url=None,
status=None):
self.id = id
self.name = name
self.screen_name = screen_name
self.location = location
self.description = description
self.profile_image_url = profile_image_url
self.profile_background_tile = profile_background_tile
self.profile_background_image_url = profile_background_image_url
self.profile_sidebar_fill_color = profile_sidebar_fill_color
self.profile_background_color = profile_background_color
self.profile_link_color = profile_link_color
self.profile_text_color = profile_text_color
self.protected = protected
self.utc_offset = utc_offset
self.time_zone = time_zone
self.followers_count = followers_count
self.friends_count = friends_count
self.statuses_count = statuses_count
self.favourites_count = favourites_count
self.url = url
self.status = status
def GetId(self):
'''Get the unique id of this user.
Returns:
The unique id of this user
'''
return self._id
def SetId(self, id):
'''Set the unique id of this user.
Args:
id: The unique id of this user.
'''
self._id = id
id = property(GetId, SetId,
doc='The unique id of this user.')
def GetName(self):
'''Get the real name of this user.
Returns:
The real name of this user
'''
return self._name
def SetName(self, name):
'''Set the real name of this user.
Args:
name: The real name of this user
'''
self._name = name
name = property(GetName, SetName,
doc='The real name of this user.')
def GetScreenName(self):
'''Get the short username of this user.
Returns:
The short username of this user
'''
return self._screen_name
def SetScreenName(self, screen_name):
'''Set the short username of this user.
Args:
screen_name: the short username of this user
'''
self._screen_name = screen_name
screen_name = property(GetScreenName, SetScreenName,
doc='The short username of this user.')
def GetLocation(self):
'''Get the geographic location of this user.
Returns:
The geographic location of this user
'''
return self._location
def SetLocation(self, location):
'''Set the geographic location of this user.
Args:
location: The geographic location of this user
'''
self._location = location
location = property(GetLocation, SetLocation,
doc='The geographic location of this user.')
def GetDescription(self):
'''Get the short text description of this user.
Returns:
The short text description of this user
'''
return self._description
def SetDescription(self, description):
'''Set the short text description of this user.
Args:
description: The short text description of this user
'''
self._description = description
description = property(GetDescription, SetDescription,
doc='The short text description of this user.')
def GetUrl(self):
'''Get the homepage url of this user.
Returns:
The homepage url of this user
'''
return self._url
def SetUrl(self, url):
'''Set the homepage url of this user.
Args:
url: The homepage url of this user
'''
self._url = url
url = property(GetUrl, SetUrl,
doc='The homepage url of this user.')
def GetProfileImageUrl(self):
'''Get the url of the thumbnail of this user.
Returns:
The url of the thumbnail of this user
'''
return self._profile_image_url
def SetProfileImageUrl(self, profile_image_url):
'''Set the url of the thumbnail of this user.
Args:
profile_image_url: The url of the thumbnail of this user
'''
self._profile_image_url = profile_image_url
profile_image_url= property(GetProfileImageUrl, SetProfileImageUrl,
doc='The url of the thumbnail of this user.')
def GetProfileBackgroundTile(self):
'''Boolean for whether to tile the profile background image.
Returns:
True if the background is to be tiled, False if not, None if unset.
'''
return self._profile_background_tile
def SetProfileBackgroundTile(self, profile_background_tile):
'''Set the boolean flag for whether to tile the profile background image.
Args:
profile_background_tile: Boolean flag for whether to tile or not.
'''
self._profile_background_tile = profile_background_tile
profile_background_tile = property(GetProfileBackgroundTile, SetProfileBackgroundTile,
doc='Boolean for whether to tile the background image.')
def GetProfileBackgroundImageUrl(self):
return self._profile_background_image_url
def SetProfileBackgroundImageUrl(self, profile_background_image_url):
self._profile_background_image_url = profile_background_image_url
profile_background_image_url = property(GetProfileBackgroundImageUrl, SetProfileBackgroundImageUrl,
doc='The url of the profile background of this user.')
def GetProfileSidebarFillColor(self):
return self._profile_sidebar_fill_color
def SetProfileSidebarFillColor(self, profile_sidebar_fill_color):
self._profile_sidebar_fill_color = profile_sidebar_fill_color
profile_sidebar_fill_color = property(GetProfileSidebarFillColor, SetProfileSidebarFillColor)
def GetProfileBackgroundColor(self):
return self._profile_background_color
def SetProfileBackgroundColor(self, profile_background_color):
self._profile_background_color = profile_background_color
profile_background_color = property(GetProfileBackgroundColor, SetProfileBackgroundColor)
def GetProfileLinkColor(self):
return self._profile_link_color
def SetProfileLinkColor(self, profile_link_color):
self._profile_link_color = profile_link_color
profile_link_color = property(GetProfileLinkColor, SetProfileLinkColor)
def GetProfileTextColor(self):
return self._profile_text_color
def SetProfileTextColor(self, profile_text_color):
self._profile_text_color = profile_text_color
profile_text_color = property(GetProfileTextColor, SetProfileTextColor)
def GetProtected(self):
return self._protected
def SetProtected(self, protected):
self._protected = protected
protected = property(GetProtected, SetProtected)
def GetUtcOffset(self):
return self._utc_offset
def SetUtcOffset(self, utc_offset):
self._utc_offset = utc_offset
utc_offset = property(GetUtcOffset, SetUtcOffset)
def GetTimeZone(self):
'''Returns the current time zone string for the user.
Returns:
The descriptive time zone string for the user.
'''
return self._time_zone
def SetTimeZone(self, time_zone):
'''Sets the user's time zone string.
Args:
time_zone: The descriptive time zone to assign for the user.
'''
self._time_zone = time_zone
time_zone = property(GetTimeZone, SetTimeZone)
def GetStatus(self):
'''Get the latest twitter.Status of this user.
Returns:
The latest twitter.Status of this user
'''
return self._status
def SetStatus(self, status):
'''Set the latest twitter.Status of this user.
Args:
status: The latest twitter.Status of this user
'''
self._status = status
status = property(GetStatus, SetStatus,
doc='The latest twitter.Status of this user.')
def GetFriendsCount(self):
'''Get the friend count for this user.
Returns:
The number of users this user has befriended.
'''
return self._friends_count
def SetFriendsCount(self, count):
'''Set the friend count for this user.
Args:
count: The number of users this user has befriended.
'''
self._friends_count = count
friends_count = property(GetFriendsCount, SetFriendsCount,
doc='The number of friends for this user.')
def GetFollowersCount(self):
'''Get the follower count for this user.
Returns:
The number of users following this user.
'''
return self._followers_count
def SetFollowersCount(self, count):
'''Set the follower count for this user.
Args:
count: The number of users following this user.
'''
self._followers_count = count
followers_count = property(GetFollowersCount, SetFollowersCount,
doc='The number of users following this user.')
def GetStatusesCount(self):
'''Get the number of status updates for this user.
Returns:
The number of status updates for this user.
'''
return self._statuses_count
def SetStatusesCount(self, count):
'''Set the status update count for this user.
Args:
count: The number of updates for this user.
'''
self._statuses_count = count
statuses_count = property(GetStatusesCount, SetStatusesCount,
doc='The number of updates for this user.')
def GetFavouritesCount(self):
'''Get the number of favourites for this user.
Returns:
The number of favourites for this user.
'''
return self._favourites_count
def SetFavouritesCount(self, count):
'''Set the favourite count for this user.
Args:
count: The number of favourites for this user.
'''
self._favourites_count = count
favourites_count = property(GetFavouritesCount, SetFavouritesCount,
doc='The number of favourites for this user.')
def __ne__(self, other):
return not self.__eq__(other)
def __eq__(self, other):
try:
return other and \
self.id == other.id and \
self.name == other.name and \
self.screen_name == other.screen_name and \
self.location == other.location and \
self.description == other.description and \
self.profile_image_url == other.profile_image_url and \
self.profile_background_tile == other.profile_background_tile and \
self.profile_background_image_url == other.profile_background_image_url and \
self.profile_sidebar_fill_color == other.profile_sidebar_fill_color and \
self.profile_background_color == other.profile_background_color and \
self.profile_link_color == other.profile_link_color and \
self.profile_text_color == other.profile_text_color and \
self.protected == other.protected and \
self.utc_offset == other.utc_offset and \
self.time_zone == other.time_zone and \
self.url == other.url and \
self.statuses_count == other.statuses_count and \
self.followers_count == other.followers_count and \
self.favourites_count == other.favourites_count and \
self.friends_count == other.friends_count and \
self.status == other.status
except AttributeError:
return False
def __str__(self):
'''A string representation of this twitter.User instance.
The return value is the same as the JSON string representation.
Returns:
A string representation of this twitter.User instance.
'''
return self.AsJsonString()
def AsJsonString(self):
'''A JSON string representation of this twitter.User instance.
Returns:
A JSON string representation of this twitter.User instance
'''
return simplejson.dumps(self.AsDict(), sort_keys=True)
def AsDict(self):
'''A dict representation of this twitter.User instance.
The return value uses the same key names as the JSON representation.
Return:
A dict representing this twitter.User instance
'''
data = {}
if self.id:
data['id'] = self.id
if self.name:
data['name'] = self.name
if self.screen_name:
data['screen_name'] = self.screen_name
if self.location:
data['location'] = self.location
if self.description:
data['description'] = self.description
if self.profile_image_url:
data['profile_image_url'] = self.profile_image_url
if self.profile_background_tile is not None:
data['profile_background_tile'] = self.profile_background_tile
if self.profile_background_image_url:
data['profile_sidebar_fill_color'] = self.profile_background_image_url
if self.profile_background_color:
data['profile_background_color'] = self.profile_background_color
if self.profile_link_color:
data['profile_link_color'] = self.profile_link_color
if self.profile_text_color:
data['profile_text_color'] = self.profile_text_color
if self.protected is not None:
data['protected'] = self.protected
if self.utc_offset:
data['utc_offset'] = self.utc_offset
if self.time_zone:
data['time_zone'] = self.time_zone
if self.url:
data['url'] = self.url
if self.status:
data['status'] = self.status.AsDict()
if self.friends_count:
data['friends_count'] = self.friends_count
if self.followers_count:
data['followers_count'] = self.followers_count
if self.statuses_count:
data['statuses_count'] = self.statuses_count
if self.favourites_count:
data['favourites_count'] = self.favourites_count
return data
@staticmethod
def NewFromJsonDict(data):
'''Create a new instance based on a JSON dict.
Args:
data: A JSON dict, as converted from the JSON in the twitter API
Returns:
A twitter.User instance
'''
if 'status' in data:
status = Status.NewFromJsonDict(data['status'])
else:
status = None
return User(id=data.get('id', None),
name=data.get('name', None),
screen_name=data.get('screen_name', None),
location=data.get('location', None),
description=data.get('description', None),
statuses_count=data.get('statuses_count', None),
followers_count=data.get('followers_count', None),
favourites_count=data.get('favourites_count', None),
friends_count=data.get('friends_count', None),
profile_image_url=data.get('profile_image_url', None),
profile_background_tile = data.get('profile_background_tile', None),
profile_background_image_url = data.get('profile_background_image_url', None),
profile_sidebar_fill_color = data.get('profile_sidebar_fill_color', None),
profile_background_color = data.get('profile_background_color', None),
profile_link_color = data.get('profile_link_color', None),
profile_text_color = data.get('profile_text_color', None),
protected = data.get('protected', None),
utc_offset = data.get('utc_offset', None),
time_zone = data.get('time_zone', None),
url=data.get('url', None),
status=status)
class DirectMessage(object):
'''A class representing the DirectMessage structure used by the twitter API.
The DirectMessage structure exposes the following properties:
direct_message.id
direct_message.created_at
direct_message.created_at_in_seconds # read only
direct_message.sender_id
direct_message.sender_screen_name
direct_message.recipient_id
direct_message.recipient_screen_name
direct_message.text
'''
def __init__(self,
id=None,
created_at=None,
sender_id=None,
sender_screen_name=None,
recipient_id=None,
recipient_screen_name=None,
text=None):
'''An object to hold a Twitter direct message.
This class is normally instantiated by the twitter.Api class and
returned in a sequence.
Note: Dates are posted in the form "Sat Jan 27 04:17:38 +0000 2007"
Args:
id: The unique id of this direct message
created_at: The time this direct message was posted
sender_id: The id of the twitter user that sent this message
sender_screen_name: The name of the twitter user that sent this message
recipient_id: The id of the twitter that received this message
recipient_screen_name: The name of the twitter that received this message
text: The text of this direct message
'''
self.id = id
self.created_at = created_at
self.sender_id = sender_id
self.sender_screen_name = sender_screen_name
self.recipient_id = recipient_id
self.recipient_screen_name = recipient_screen_name
self.text = text
def GetId(self):
'''Get the unique id of this direct message.
Returns:
The unique id of this direct message
'''
return self._id
def SetId(self, id):
'''Set the unique id of this direct message.
Args:
id: The unique id of this direct message
'''
self._id = id
id = property(GetId, SetId,
doc='The unique id of this direct message.')
def GetCreatedAt(self):
'''Get the time this direct message was posted.
Returns:
The time this direct message was posted
'''
return self._created_at
def SetCreatedAt(self, created_at):
'''Set the time this direct message was posted.
Args:
created_at: The time this direct message was created
'''
self._created_at = created_at
created_at = property(GetCreatedAt, SetCreatedAt,
doc='The time this direct message was posted.')
def GetCreatedAtInSeconds(self):
'''Get the time this direct message was posted, in seconds since the epoch.
Returns:
The time this direct message was posted, in seconds since the epoch.
'''
return calendar.timegm(rfc822.parsedate(self.created_at))
created_at_in_seconds = property(GetCreatedAtInSeconds,
doc="The time this direct message was "
"posted, in seconds since the epoch")
def GetSenderId(self):
'''Get the unique sender id of this direct message.
Returns:
The unique sender id of this direct message
'''
return self._sender_id
def SetSenderId(self, sender_id):
'''Set the unique sender id of this direct message.
Args:
sender id: The unique sender id of this direct message
'''
self._sender_id = sender_id
sender_id = property(GetSenderId, SetSenderId,
doc='The unique sender id of this direct message.')
def GetSenderScreenName(self):
'''Get the unique sender screen name of this direct message.
Returns:
The unique sender screen name of this direct message
'''
return self._sender_screen_name
def SetSenderScreenName(self, sender_screen_name):
'''Set the unique sender screen name of this direct message.
Args:
sender_screen_name: The unique sender screen name of this direct message
'''
self._sender_screen_name = sender_screen_name
sender_screen_name = property(GetSenderScreenName, SetSenderScreenName,
doc='The unique sender screen name of this direct message.')
def GetRecipientId(self):
'''Get the unique recipient id of this direct message.
Returns:
The unique recipient id of this direct message
'''
return self._recipient_id
def SetRecipientId(self, recipient_id):
'''Set the unique recipient id of this direct message.
Args:
recipient id: The unique recipient id of this direct message
'''
self._recipient_id = recipient_id
recipient_id = property(GetRecipientId, SetRecipientId,
doc='The unique recipient id of this direct message.')
def GetRecipientScreenName(self):
'''Get the unique recipient screen name of this direct message.
Returns:
The unique recipient screen name of this direct message
'''
return self._recipient_screen_name
def SetRecipientScreenName(self, recipient_screen_name):
'''Set the unique recipient screen name of this direct message.
Args:
recipient_screen_name: The unique recipient screen name of this direct message
'''
self._recipient_screen_name = recipient_screen_name
recipient_screen_name = property(GetRecipientScreenName, SetRecipientScreenName,
doc='The unique recipient screen name of this direct message.')
def GetText(self):
'''Get the text of this direct message.
Returns:
The text of this direct message.
'''
return self._text
def SetText(self, text):
'''Set the text of this direct message.
Args:
text: The text of this direct message
'''
self._text = text
text = property(GetText, SetText,
doc='The text of this direct message')
def __ne__(self, other):
return not self.__eq__(other)
def __eq__(self, other):
try:
return other and \
self.id == other.id and \
self.created_at == other.created_at and \
self.sender_id == other.sender_id and \
self.sender_screen_name == other.sender_screen_name and \
self.recipient_id == other.recipient_id and \
self.recipient_screen_name == other.recipient_screen_name and \
self.text == other.text
except AttributeError:
return False
def __str__(self):
'''A string representation of this twitter.DirectMessage instance.
The return value is the same as the JSON string representation.
Returns:
A string representation of this twitter.DirectMessage instance.
'''
return self.AsJsonString()
def AsJsonString(self):
'''A JSON string representation of this twitter.DirectMessage instance.
Returns:
A JSON string representation of this twitter.DirectMessage instance
'''
return simplejson.dumps(self.AsDict(), sort_keys=True)
def AsDict(self):
'''A dict representation of this twitter.DirectMessage instance.
The return value uses the same key names as the JSON representation.
Return:
A dict representing this twitter.DirectMessage instance
'''
data = {}
if self.id:
data['id'] = self.id
if self.created_at:
data['created_at'] = self.created_at
if self.sender_id:
data['sender_id'] = self.sender_id
if self.sender_screen_name:
data['sender_screen_name'] = self.sender_screen_name
if self.recipient_id:
data['recipient_id'] = self.recipient_id
if self.recipient_screen_name:
data['recipient_screen_name'] = self.recipient_screen_name
if self.text:
data['text'] = self.text
return data
@staticmethod
def NewFromJsonDict(data):
'''Create a new instance based on a JSON dict.
Args:
data: A JSON dict, as converted from the JSON in the twitter API
Returns:
A twitter.DirectMessage instance
'''
return DirectMessage(created_at=data.get('created_at', None),
recipient_id=data.get('recipient_id', None),
sender_id=data.get('sender_id', None),
text=data.get('text', None),
sender_screen_name=data.get('sender_screen_name', None),
id=data.get('id', None),
recipient_screen_name=data.get('recipient_screen_name', None))
class Api(object):
'''A python interface into the Twitter API
By default, the Api caches results for 1 minute.
Example usage:
To create an instance of the twitter.Api class, with no authentication:
>>> import twitter
>>> api = twitter.Api()
To fetch the most recently posted public twitter status messages:
>>> statuses = api.GetPublicTimeline()
>>> print [s.user.name for s in statuses]
[u'DeWitt', u'Kesuke Miyagi', u'ev', u'Buzz Andersen', u'Biz Stone'] #...
To fetch a single user's public status messages, where "user" is either
a Twitter "short name" or their user id.
>>> statuses = api.GetUserTimeline(user)
>>> print [s.text for s in statuses]
To use authentication, instantiate the twitter.Api class with a
username and password:
>>> api = twitter.Api(username='twitter user', password='twitter pass')
To fetch your friends (after being authenticated):
>>> users = api.GetFriends()
>>> print [u.name for u in users]
To post a twitter status message (after being authenticated):
>>> status = api.PostUpdate('I love python-twitter!')
>>> print status.text
I love python-twitter!
There are many other methods, including:
>>> api.PostUpdates(status)
>>> api.PostDirectMessage(user, text)
>>> api.GetUser(user)
>>> api.GetReplies()
>>> api.GetUserTimeline(user)
>>> api.GetStatus(id)
>>> api.DestroyStatus(id)
>>> api.GetFriendsTimeline(user)
>>> api.GetFriends(user)
>>> api.GetFollowers()
>>> api.GetFeatured()
>>> api.GetDirectMessages()
>>> api.PostDirectMessage(user, text)
>>> api.DestroyDirectMessage(id)
>>> api.DestroyFriendship(user)
>>> api.CreateFriendship(user)
>>> api.GetUserByEmail(email)
'''
DEFAULT_CACHE_TIMEOUT = 60 # cache for 1 minute
_API_REALM = 'Twitter API'
def __init__(self,
username=None,
password=None,
input_encoding=None,
request_headers=None,
cache=DEFAULT_CACHE):
'''Instantiate a new twitter.Api object.
Args:
username: The username of the twitter account. [optional]
password: The password for the twitter account. [optional]
input_encoding: The encoding used to encode input strings. [optional]
request_header: A dictionary of additional HTTP request headers. [optional]
cache:
The cache instance to use. Defaults to DEFAULT_CACHE. Use
None to disable caching. [optional]
'''
self.SetCache(cache)
self._urllib = urllib2
self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
self._InitializeRequestHeaders(request_headers)
self._InitializeUserAgent()
self._InitializeDefaultParameters()
self._input_encoding = input_encoding
self.SetCredentials(username, password)
def GetPublicTimeline(self, since_id=None):
'''Fetch the sequnce of public twitter.Status message for all users.
Args:
since_id:
Returns only public statuses with an ID greater than (that is,
more recent than) the specified ID. [Optional]
Returns:
An sequence of twitter.Status instances, one for each message
'''
parameters = {}
if since_id:
parameters['since_id'] = since_id
url = 'http://twitter.com/statuses/public_timeline.json'
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [Status.NewFromJsonDict(x) for x in data]
def GetFriendsTimeline(self,
user=None,
count=None,
since=None,
since_id=None):
'''Fetch the sequence of twitter.Status messages for a user's friends
The twitter.Api instance must be authenticated if the user is private.
Args:
user:
Specifies the ID or screen name of the user for whom to return
the friends_timeline. If unspecified, the username and password
must be set in the twitter.Api instance. [Optional]
count:
Specifies the number of statuses to retrieve. May not be
greater than 200. [Optional]
since:
Narrows the returned results to just those statuses created
after the specified HTTP-formatted date. [Optional]
since_id:
Returns only public statuses with an ID greater than (that is,
more recent than) the specified ID. [Optional]
Returns:
A sequence of twitter.Status instances, one for each message
'''
if not user and not self._username:
raise TwitterError("User must be specified if API is not authenticated.")
if user:
url = 'http://twitter.com/statuses/friends_timeline/%s.json' % user
else:
url = 'http://twitter.com/statuses/friends_timeline.json'
parameters = {}
if count is not None:
try:
if int(count) > 200:
raise TwitterError("'count' may not be greater than 200")
except ValueError:
raise TwitterError("'count' must be an integer")
parameters['count'] = count
if since:
parameters['since'] = since
if since_id:
parameters['since_id'] = since_id
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [Status.NewFromJsonDict(x) for x in data]
def GetUserTimeline(self,
id=None,
user_id=None,
screen_name=None,
since_id=None,
max_id=None,
count=None,
page=None):
'''Fetch the sequence of public Status messages for a single user.
The twitter.Api instance must be authenticated if the user is private.
Args:
id:
Specifies the ID or screen name of the user for whom to return
the user_timeline. [optional]
user_id:
Specfies the ID of the user for whom to return the
user_timeline. Helpful for disambiguating when a valid user ID
is also a valid screen name. [optional]
screen_name:
Specfies the screen name of the user for whom to return the
user_timeline. Helpful for disambiguating when a valid screen
name is also a user ID. [optional]
since_id:
Returns only public statuses with an ID greater than (that is,
more recent than) the specified ID. [optional]
max_id:
Returns only statuses with an ID less than (that is, older
than) or equal to the specified ID. [optional]
count:
Specifies the number of statuses to retrieve. May not be
greater than 200. [optional]
page:
Specifies the page of results to retrieve. Note: there are
pagination limits. [optional]
Returns:
A sequence of Status instances, one for each message up to count
'''
parameters = {}
if id:
url = 'http://twitter.com/statuses/user_timeline/%s.json' % id
elif user_id:
url = 'http://twitter.com/statuses/user_timeline.json?user_id=%d' % user_id
elif screen_name:
url = ('http://twitter.com/statuses/user_timeline.json?screen_name=%s' %
screen_name)
elif not self._username:
raise TwitterError("User must be specified if API is not authenticated.")
else:
url = 'http://twitter.com/statuses/user_timeline.json'
if since_id:
try:
parameters['since_id'] = long(since_id)
except:
raise TwitterError("since_id must be an integer")
if max_id:
try:
parameters['max_id'] = long(max_id)
except:
raise TwitterError("max_id must be an integer")
if count:
try:
parameters['count'] = int(count)
except:
raise TwitterError("count must be an integer")
if page:
try:
parameters['page'] = int(page)
except:
raise TwitterError("page must be an integer")
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [Status.NewFromJsonDict(x) for x in data]
def GetStatus(self, id):
'''Returns a single status message.
The twitter.Api instance must be authenticated if the status message is private.
Args:
id: The numerical ID of the status you're trying to retrieve.
Returns:
A twitter.Status instance representing that status message
'''
try:
if id:
long(id)
except:
raise TwitterError("id must be an long integer")
url = 'http://twitter.com/statuses/show/%s.json' % id
json = self._FetchUrl(url)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return Status.NewFromJsonDict(data)
def DestroyStatus(self, id):
'''Destroys the status specified by the required ID parameter.
The twitter.Api instance must be authenticated and thee
authenticating user must be the author of the specified status.
Args:
id: The numerical ID of the status you're trying to destroy.
Returns:
A twitter.Status instance representing the destroyed status message
'''
try:
if id:
long(id)
except:
raise TwitterError("id must be an integer")
url = 'http://twitter.com/statuses/destroy/%s.json' % id
json = self._FetchUrl(url, post_data={})
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return Status.NewFromJsonDict(data)
def PostUpdate(self, status, in_reply_to_status_id=None):
'''Post a twitter status message from the authenticated user.
The twitter.Api instance must be authenticated.
Args:
status:
The message text to be posted. Must be less than or equal to
140 characters.
in_reply_to_status_id:
The ID of an existing status that the status to be posted is
in reply to. This implicitly sets the in_reply_to_user_id
attribute of the resulting status to the user ID of the
message being replied to. Invalid/missing status IDs will be
ignored. [Optional]
Returns:
A twitter.Status instance representing the message posted.
'''
if not self._username:
raise TwitterError("The twitter.Api instance must be authenticated.")
url = 'http://twitter.com/statuses/update.json'
if len(status) > CHARACTER_LIMIT:
raise TwitterError("Text must be less than or equal to %d characters. "
"Consider using PostUpdates." % CHARACTER_LIMIT)
data = {'status': status}
if in_reply_to_status_id:
data['in_reply_to_status_id'] = in_reply_to_status_id
json = self._FetchUrl(url, post_data=data)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return Status.NewFromJsonDict(data)
def PostUpdates(self, status, continuation=None, **kwargs):
'''Post one or more twitter status messages from the authenticated user.
Unlike api.PostUpdate, this method will post multiple status updates
if the message is longer than 140 characters.
The twitter.Api instance must be authenticated.
Args:
status:
The message text to be posted. May be longer than 140 characters.
continuation:
The character string, if any, to be appended to all but the
last message. Note that Twitter strips trailing '...' strings
from messages. Consider using the unicode \u2026 character
(horizontal ellipsis) instead. [Defaults to None]
**kwargs:
See api.PostUpdate for a list of accepted parameters.
Returns:
A of list twitter.Status instance representing the messages posted.
'''
results = list()
if continuation is None:
continuation = ''
line_length = CHARACTER_LIMIT - len(continuation)
lines = textwrap.wrap(status, line_length)
for line in lines[0:-1]:
results.append(self.PostUpdate(line + continuation, **kwargs))
results.append(self.PostUpdate(lines[-1], **kwargs))
return results
def GetReplies(self, since=None, since_id=None, page=None):
'''Get a sequence of status messages representing the 20 most recent
replies (status updates prefixed with @username) to the authenticating
user.
Args:
page:
since:
Narrows the returned results to just those statuses created
after the specified HTTP-formatted date. [optional]
since_id:
Returns only public statuses with an ID greater than (that is,
more recent than) the specified ID. [Optional]
Returns:
A sequence of twitter.Status instances, one for each reply to the user.
'''
url = 'http://twitter.com/statuses/replies.json'
if not self._username:
raise TwitterError("The twitter.Api instance must be authenticated.")
parameters = {}
if since:
parameters['since'] = since
if since_id:
parameters['since_id'] = since_id
if page:
parameters['page'] = page
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [Status.NewFromJsonDict(x) for x in data]
def GetFriends(self, user=None, page=None):
'''Fetch the sequence of twitter.User instances, one for each friend.
Args:
user: the username or id of the user whose friends you are fetching. If
not specified, defaults to the authenticated user. [optional]
The twitter.Api instance must be authenticated.
Returns:
A sequence of twitter.User instances, one for each friend
'''
if not user and not self._username:
raise TwitterError("twitter.Api instance must be authenticated")
if user:
url = 'http://twitter.com/statuses/friends/%s.json' % user
else:
url = 'http://twitter.com/statuses/friends.json'
parameters = {}
if page:
parameters['page'] = page
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [User.NewFromJsonDict(x) for x in data]
def GetFollowers(self, page=None):
'''Fetch the sequence of twitter.User instances, one for each follower
The twitter.Api instance must be authenticated.
Returns:
A sequence of twitter.User instances, one for each follower
'''
if not self._username:
raise TwitterError("twitter.Api instance must be authenticated")
url = 'http://twitter.com/statuses/followers.json'
parameters = {}
if page:
parameters['page'] = page
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [User.NewFromJsonDict(x) for x in data]
def GetFeatured(self):
'''Fetch the sequence of twitter.User instances featured on twitter.com
The twitter.Api instance must be authenticated.
Returns:
A sequence of twitter.User instances
'''
url = 'http://twitter.com/statuses/featured.json'
json = self._FetchUrl(url)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [User.NewFromJsonDict(x) for x in data]
def GetUser(self, user):
'''Returns a single user.
The twitter.Api instance must be authenticated.
Args:
user: The username or id of the user to retrieve.
Returns:
A twitter.User instance representing that user
'''
url = 'http://twitter.com/users/show/%s.json' % user
json = self._FetchUrl(url)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return User.NewFromJsonDict(data)
def GetDirectMessages(self, since=None, since_id=None, page=None):
'''Returns a list of the direct messages sent to the authenticating user.
The twitter.Api instance must be authenticated.
Args:
since:
Narrows the returned results to just those statuses created
after the specified HTTP-formatted date. [optional]
since_id:
Returns only public statuses with an ID greater than (that is,
more recent than) the specified ID. [Optional]
Returns:
A sequence of twitter.DirectMessage instances
'''
url = 'http://twitter.com/direct_messages.json'
if not self._username:
raise TwitterError("The twitter.Api instance must be authenticated.")
parameters = {}
if since:
parameters['since'] = since
if since_id:
parameters['since_id'] = since_id
if page:
parameters['page'] = page
json = self._FetchUrl(url, parameters=parameters)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return [DirectMessage.NewFromJsonDict(x) for x in data]
def PostDirectMessage(self, user, text):
'''Post a twitter direct message from the authenticated user
The twitter.Api instance must be authenticated.
Args:
user: The ID or screen name of the recipient user.
text: The message text to be posted. Must be less than 140 characters.
Returns:
A twitter.DirectMessage instance representing the message posted
'''
if not self._username:
raise TwitterError("The twitter.Api instance must be authenticated.")
url = 'http://twitter.com/direct_messages/new.json'
data = {'text': text, 'user': user}
json = self._FetchUrl(url, post_data=data)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return DirectMessage.NewFromJsonDict(data)
def DestroyDirectMessage(self, id):
'''Destroys the direct message specified in the required ID parameter.
The twitter.Api instance must be authenticated, and the
authenticating user must be the recipient of the specified direct
message.
Args:
id: The id of the direct message to be destroyed
Returns:
A twitter.DirectMessage instance representing the message destroyed
'''
url = 'http://twitter.com/direct_messages/destroy/%s.json' % id
json = self._FetchUrl(url, post_data={})
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return DirectMessage.NewFromJsonDict(data)
def CreateFriendship(self, user):
'''Befriends the user specified in the user parameter as the authenticating user.
The twitter.Api instance must be authenticated.
Args:
The ID or screen name of the user to befriend.
Returns:
A twitter.User instance representing the befriended user.
'''
url = 'http://twitter.com/friendships/create/%s.json' % user
json = self._FetchUrl(url, post_data={})
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return User.NewFromJsonDict(data)
def DestroyFriendship(self, user):
'''Discontinues friendship with the user specified in the user parameter.
The twitter.Api instance must be authenticated.
Args:
The ID or screen name of the user with whom to discontinue friendship.
Returns:
A twitter.User instance representing the discontinued friend.
'''
url = 'http://twitter.com/friendships/destroy/%s.json' % user
json = self._FetchUrl(url, post_data={})
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return User.NewFromJsonDict(data)
def CreateFavorite(self, status):
'''Favorites the status specified in the status parameter as the authenticating user.
Returns the favorite status when successful.
The twitter.Api instance must be authenticated.
Args:
The twitter.Status instance to mark as a favorite.
Returns:
A twitter.Status instance representing the newly-marked favorite.
'''
url = 'http://twitter.com/favorites/create/%s.json' % status.id
json = self._FetchUrl(url, post_data={})
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return Status.NewFromJsonDict(data)
def DestroyFavorite(self, status):
'''Un-favorites the status specified in the ID parameter as the authenticating user.
Returns the un-favorited status in the requested format when successful.
The twitter.Api instance must be authenticated.
Args:
The twitter.Status to unmark as a favorite.
Returns:
A twitter.Status instance representing the newly-unmarked favorite.
'''
url = 'http://twitter.com/favorites/destroy/%s.json' % status.id
json = self._FetchUrl(url, post_data={})
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return Status.NewFromJsonDict(data)
def GetUserByEmail(self, email):
'''Returns a single user by email address.
Args:
email: The email of the user to retrieve.
Returns:
A twitter.User instance representing that user
'''
url = 'http://twitter.com/users/show.json?email=%s' % email
json = self._FetchUrl(url)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return User.NewFromJsonDict(data)
def VerifyCredentials(self):
'''Returns a twitter.User instance if the authenticating user is valid.
Returns:
A twitter.User instance representing that user if the
credentials are valid, None otherwise.
'''
if not self._username:
raise TwitterError("Api instance must first be given user credentials.")
url = 'http://twitter.com/account/verify_credentials.json'
try:
json = self._FetchUrl(url, no_cache=True)
except urllib2.HTTPError, http_error:
if http_error.code == httplib.UNAUTHORIZED:
return None
else:
raise http_error
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return User.NewFromJsonDict(data)
def SetCredentials(self, username, password):
'''Set the username and password for this instance
Args:
username: The twitter username.
password: The twitter password.
'''
self._username = username
self._password = password
def ClearCredentials(self):
'''Clear the username and password for this instance
'''
self._username = None
self._password = None
def SetCache(self, cache):
'''Override the default cache. Set to None to prevent caching.
Args:
cache: an instance that supports the same API as the twitter._FileCache
'''
if cache == DEFAULT_CACHE:
self._cache = _FileCache()
else:
self._cache = cache
def SetUrllib(self, urllib):
'''Override the default urllib implementation.
Args:
urllib: an instance that supports the same API as the urllib2 module
'''
self._urllib = urllib
def SetCacheTimeout(self, cache_timeout):
'''Override the default cache timeout.
Args:
cache_timeout: time, in seconds, that responses should be reused.
'''
self._cache_timeout = cache_timeout
def SetUserAgent(self, user_agent):
'''Override the default user agent
Args:
user_agent: a string that should be send to the server as the User-agent
'''
self._request_headers['User-Agent'] = user_agent
def SetXTwitterHeaders(self, client, url, version):
'''Set the X-Twitter HTTP headers that will be sent to the server.
Args:
client:
The client name as a string. Will be sent to the server as
the 'X-Twitter-Client' header.
url:
The URL of the meta.xml as a string. Will be sent to the server
as the 'X-Twitter-Client-URL' header.
version:
The client version as a string. Will be sent to the server
as the 'X-Twitter-Client-Version' header.
'''
self._request_headers['X-Twitter-Client'] = client
self._request_headers['X-Twitter-Client-URL'] = url
self._request_headers['X-Twitter-Client-Version'] = version
def SetSource(self, source):
'''Suggest the "from source" value to be displayed on the Twitter web site.
The value of the 'source' parameter must be first recognized by
the Twitter server. New source values are authorized on a case by
case basis by the Twitter development team.
Args:
source:
The source name as a string. Will be sent to the server as
the 'source' parameter.
'''
self._default_params['source'] = source
def _BuildUrl(self, url, path_elements=None, extra_params=None):
# Break url into consituent parts
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
# Add any additional path elements to the path
if path_elements:
# Filter out the path elements that have a value of None
p = [i for i in path_elements if i]
if not path.endswith('/'):
path += '/'
path += '/'.join(p)
# Add any additional query parameters to the query string
if extra_params and len(extra_params) > 0:
extra_query = self._EncodeParameters(extra_params)
# Add it to the existing query
if query:
query += '&' + extra_query
else:
query = extra_query
# Return the rebuilt URL
return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
def _InitializeRequestHeaders(self, request_headers):
if request_headers:
self._request_headers = request_headers
else:
self._request_headers = {}
def _InitializeUserAgent(self):
user_agent = 'Python-urllib/%s (python-twitter/%s)' % \
(self._urllib.__version__, __version__)
self.SetUserAgent(user_agent)
def _InitializeDefaultParameters(self):
self._default_params = {}
def _AddAuthorizationHeader(self, username, password):
if username and password:
basic_auth = base64.encodestring('%s:%s' % (username, password))[:-1]
self._request_headers['Authorization'] = 'Basic %s' % basic_auth
def _RemoveAuthorizationHeader(self):
if self._request_headers and 'Authorization' in self._request_headers:
del self._request_headers['Authorization']
def _GetOpener(self, url, username=None, password=None):
if username and password:
self._AddAuthorizationHeader(username, password)
handler = self._urllib.HTTPBasicAuthHandler()
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
handler.add_password(Api._API_REALM, netloc, username, password)
opener = self._urllib.build_opener(handler)
else:
opener = self._urllib.build_opener()
opener.addheaders = self._request_headers.items()
return opener
def _Encode(self, s):
if self._input_encoding:
return unicode(s, self._input_encoding).encode('utf-8')
else:
return unicode(s).encode('utf-8')
def _EncodeParameters(self, parameters):
'''Return a string in key=value&key=value form
Values of None are not included in the output string.
Args:
parameters:
A dict of (key, value) tuples, where value is encoded as
specified by self._encoding
Returns:
A URL-encoded string in "key=value&key=value" form
'''
if parameters is None:
return None
else:
return urllib.urlencode(dict([(k, self._Encode(v)) for k, v in parameters.items() if v is not None]))
def _EncodePostData(self, post_data):
'''Return a string in key=value&key=value form
Values are assumed to be encoded in the format specified by self._encoding,
and are subsequently URL encoded.
Args:
post_data:
A dict of (key, value) tuples, where value is encoded as
specified by self._encoding
Returns:
A URL-encoded string in "key=value&key=value" form
'''
if post_data is None:
return None
else:
return urllib.urlencode(dict([(k, self._Encode(v)) for k, v in post_data.items()]))
def _CheckForTwitterError(self, data):
"""Raises a TwitterError if twitter returns an error message.
Args:
data: A python dict created from the Twitter json response
Raises:
TwitterError wrapping the twitter error message if one exists.
"""
# Twitter errors are relatively unlikely, so it is faster
# to check first, rather than try and catch the exception
if 'error' in data:
raise TwitterError(data['error'])
def _FetchUrl(self,
url,
post_data=None,
parameters=None,
no_cache=None):
'''Fetch a URL, optionally caching for a specified time.
Args:
url: The URL to retrieve
post_data:
A dict of (str, unicode) key/value pairs. If set, POST will be used.
parameters:
A dict whose key/value pairs should encoded and added
to the query string. [OPTIONAL]
no_cache: If true, overrides the cache on the current request
Returns:
A string containing the body of the response.
'''
# Build the extra parameters dict
extra_params = {}
if self._default_params:
extra_params.update(self._default_params)
if parameters:
extra_params.update(parameters)
# Add key/value parameters to the query string of the url
url = self._BuildUrl(url, extra_params=extra_params)
# Get a url opener that can handle basic auth
opener = self._GetOpener(url, username=self._username, password=self._password)
encoded_post_data = self._EncodePostData(post_data)
# Open and return the URL immediately if we're not going to cache
if encoded_post_data or no_cache or not self._cache or not self._cache_timeout:
url_data = opener.open(url, encoded_post_data).read()
opener.close()
else:
# Unique keys are a combination of the url and the username
if self._username:
key = self._username + ':' + url
else:
key = url
# See if it has been cached before
last_cached = self._cache.GetCachedTime(key)
# If the cached version is outdated then fetch another and store it
if not last_cached or time.time() >= last_cached + self._cache_timeout:
url_data = opener.open(url, encoded_post_data).read()
opener.close()
self._cache.Set(key, url_data)
else:
url_data = self._cache.Get(key)
# Always return the latest version
return url_data
class _FileCacheError(Exception):
'''Base exception class for FileCache related errors'''
class _FileCache(object):
DEPTH = 3
def __init__(self,root_directory=None):
self._InitializeRootDirectory(root_directory)
def Get(self,key):
path = self._GetPath(key)
if os.path.exists(path):
return open(path).read()
else:
return None
def Set(self,key,data):
path = self._GetPath(key)
directory = os.path.dirname(path)
if not os.path.exists(directory):
os.makedirs(directory)
if not os.path.isdir(directory):
raise _FileCacheError('%s exists but is not a directory' % directory)
temp_fd, temp_path = tempfile.mkstemp()
temp_fp = os.fdopen(temp_fd, 'w')
temp_fp.write(data)
temp_fp.close()
if not path.startswith(self._root_directory):
raise _FileCacheError('%s does not appear to live under %s' %
(path, self._root_directory))
if os.path.exists(path):
os.remove(path)
os.rename(temp_path, path)
def Remove(self,key):
path = self._GetPath(key)
if not path.startswith(self._root_directory):
raise _FileCacheError('%s does not appear to live under %s' %
(path, self._root_directory ))
if os.path.exists(path):
os.remove(path)
def GetCachedTime(self,key):
path = self._GetPath(key)
if os.path.exists(path):
return os.path.getmtime(path)
else:
return None
def _GetUsername(self):
'''Attempt to find the username in a cross-platform fashion.'''
try:
return os.getenv('USER') or \
os.getenv('LOGNAME') or \
os.getenv('USERNAME') or \
os.getlogin() or \
'nobody'
except (IOError, OSError), e:
return 'nobody'
def _GetTmpCachePath(self):
username = self._GetUsername()
cache_directory = 'python.cache_' + username
return os.path.join(tempfile.gettempdir(), cache_directory)
def _InitializeRootDirectory(self, root_directory):
if not root_directory:
root_directory = self._GetTmpCachePath()
root_directory = os.path.abspath(root_directory)
if not os.path.exists(root_directory):
os.mkdir(root_directory)
if not os.path.isdir(root_directory):
raise _FileCacheError('%s exists but is not a directory' %
root_directory)
self._root_directory = root_directory
def _GetPath(self,key):
try:
hashed_key = md5(key).hexdigest()
except TypeError:
hashed_key = md5.new(key).hexdigest()
return os.path.join(self._root_directory,
self._GetPrefix(hashed_key),
hashed_key)
def _GetPrefix(self,hashed_key):
return os.path.sep.join(hashed_key[0:_FileCache.DEPTH])
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
2344,
33,
3555,
626,
6571,
282,
2366,
3217,
370,
314,
19259,
3261,
2344,
199,
199,
363,
2502,
363,
275,
283,
271,
2503,
84,
32,
3098,
14,
957,
7,
199,
363,
1023,
363,
275,
283,
16,
14,
23,
13,
27870,
7,
421,
199,
646,
1300,
772,
199,
646,
11234,
199,
646,
8809,
199,
646,
747,
199,
646,
18158,
10228,
199,
646,
13804,
199,
646,
984,
199,
646,
5549,
199,
646,
13390,
199,
646,
900,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
893,
26,
523,
687,
8337,
492,
6128,
21,
199,
2590,
3545,
26,
523,
687,
6128,
21,
492,
6128,
21,
421,
199,
29007,
63,
13387,
275,
22796,
199,
199,
3,
437,
19768,
6144,
282,
29667,
3444,
17544,
3814,
4437,
14,
199,
3472,
63,
8677,
275,
909,
342,
421,
199,
533,
19259,
547,
8,
1726,
304,
523,
1449,
1563,
1021,
367,
19259,
2552,
2344,
12244,
768,
1829,
523,
347,
1245,
8,
277,
304,
272,
1449,
3407,
314,
1642,
1423,
1202,
370,
6982,
642,
1125,
10595,
272,
372,
291,
14,
589,
59,
16,
61,
421,
199,
533,
9795,
8,
785,
304,
523,
1449,
33,
1021,
6144,
314,
9795,
5523,
1202,
701,
314,
15811,
3261,
14,
819,
710,
9795,
5523,
444,
10553,
314,
2569,
4382,
26,
339,
2004,
14,
3966,
63,
292,
272,
2004,
14,
3966,
63,
292,
63,
262,
63,
4515,
327,
1586,
1454,
272,
2004,
14,
17520,
5703,
272,
2004,
14,
262,
63,
8102,
63,
475,
63,
5410,
63,
354,
272,
2004,
14,
262,
63,
8102,
63,
475,
63,
751,
63,
344,
272,
2004,
14,
262,
63,
8102,
63,
475,
63,
1205,
63,
344,
272,
2004,
14,
19347,
272,
2004,
14,
1365,
272,
2004,
14,
344,
272,
2004,
14,
505,
272,
2004,
14,
6188,
63,
3966,
63,
292,
327,
1586,
1454,
272,
2004,
14,
751,
523,
1449,
523,
347,
636,
826,
721,
277,
12,
2049,
2737,
63,
292,
29,
403,
12,
2049,
17914,
5703,
29,
403,
12,
2049,
1305,
29,
403,
12,
2049,
1318,
29,
403,
12,
2049,
922,
29,
403,
12,
2049,
315,
63,
8102,
63,
475,
63,
5410,
63,
354,
29,
403,
12,
2049,
315,
63,
8102,
63,
475,
63,
751,
63,
344,
29,
403,
12,
2049,
315,
63,
8102,
63,
475,
63,
1205,
63,
344,
29,
403,
12,
2049,
17661,
29,
403,
12,
2049,
1350,
29,
403,
12,
2049,
3063,
29,
403,
304,
272,
1449,
2493,
909,
370,
10266,
282,
19259,
2004,
1245,
14,
339,
961,
1021,
365,
12252,
17544,
701,
314,
15811,
14,
7394,
1021,
436,
272,
2138,
315,
282,
3414,
14,
339,
3390,
26,
577,
2335,
787,
22752,
315,
314,
1824,
298,
22332,
17474,
8087,
28527,
26,
1196,
26,
1703,
435,
993,
10219,
2,
339,
3033,
26,
489,
2737,
63,
292,
26,
710,
900,
642,
2004,
1245,
1990,
22752,
489,
17914,
5703,
26,
7480,
642,
365,
282,
17914,
1175,
402,
314,
15082,
922,
489,
1305,
26,
710,
3747,
1305,
402,
642,
2004,
1245,
489,
1318,
26,
710,
1318,
402,
642,
2004,
1245,
489,
3847,
63,
3966,
63,
292,
26,
267,
437,
11779,
12701,
1059,
6144,
314,
25386,
900,
489,
922,
26,
267,
437,
15811,
14,
1899,
1256,
6144,
314,
4954,
25386,
314,
1245,
489,
3063,
26,
267,
710,
1453,
900,
12,
340,
314,
1890,
2468,
874,
370,
663,
652,
14,
221,
7827,
370,
314,
267,
19882,
12516,
900,
14,
272,
1449,
272,
291,
14,
3966,
63,
292,
275,
2737,
63,
292,
272,
291,
14,
17520,
5703,
275,
17914,
5703,
272,
291,
14,
344,
275,
1305,
272,
291,
14,
505,
275,
1318,
272,
291,
14,
751,
275,
922,
272,
291,
14,
2131,
275,
3063,
272,
291,
14,
262,
63,
8102,
63,
475,
63,
5410,
63,
354,
275,
315,
63,
8102,
63,
475,
63,
5410,
63,
354,
272,
291,
14,
262,
63,
8102,
63,
475,
63,
751,
63,
344,
275,
315,
63,
8102,
63,
475,
63,
751,
63,
344,
272,
291,
14,
262,
63,
8102,
63,
475,
63,
1205,
63,
344,
275,
315,
63,
8102,
63,
475,
63,
1205,
63,
344,
272,
291,
14,
19347,
275,
17661,
272,
291,
14,
1365,
275,
1350,
819,
347,
2372,
10502,
1271,
8,
277,
304,
272,
1449,
1002,
314,
900,
642,
2004,
1245,
1990,
22752,
14,
339,
1803,
26,
489,
710,
900,
642,
2004,
1245,
1990,
22752,
272,
1449,
272,
372,
291,
423,
3966,
63,
292,
819,
347,
2494,
10502,
1271,
8,
277,
12,
2737,
63,
292,
304,
272,
1449,
1084,
314,
900,
642,
2004,
1245,
1990,
22752,
14,
339,
3033,
26,
489,
2737,
63,
292,
26,
710,
900,
642,
2004,
1245,
1990,
2737,
272,
1449,
272,
291,
423,
3966,
63,
292,
275,
2737,
63,
292,
819,
2737,
63,
292,
275,
3324,
8,
1002,
10502,
1271,
12,
2494,
10502,
1271,
12,
717,
1382,
534,
1918,
900,
642,
2004,
1245,
1990,
22752,
2659,
819,
347,
2372,
10502,
1271,
607,
13165,
8,
277,
304,
272,
1449,
1002,
314,
900,
642,
2004,
1245,
1990,
22752,
12,
315,
4696,
3967,
314,
9463,
14,
339,
1803,
26,
489,
710,
900,
642,
2004,
1245,
1990,
22752,
12,
315,
4696,
3967,
314,
9463,
14,
272,
1449,
272,
372,
11234,
14,
521,
13844,
8,
8973,
10228,
14,
1122,
602,
8,
277,
14,
3966,
63,
292,
430,
819,
2737,
63,
292,
63,
262,
63,
4515,
275,
3324,
8,
1002,
10502,
1271,
607,
13165,
12,
3521,
1382
] |
[
2647,
15,
1393,
15,
1548,
18,
14,
20,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
2344,
33,
3555,
626,
6571,
282,
2366,
3217,
370,
314,
19259,
3261,
2344,
199,
199,
363,
2502,
363,
275,
283,
271,
2503,
84,
32,
3098,
14,
957,
7,
199,
363,
1023,
363,
275,
283,
16,
14,
23,
13,
27870,
7,
421,
199,
646,
1300,
772,
199,
646,
11234,
199,
646,
8809,
199,
646,
747,
199,
646,
18158,
10228,
199,
646,
13804,
199,
646,
984,
199,
646,
5549,
199,
646,
13390,
199,
646,
900,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
7097,
199,
199,
893,
26,
523,
687,
8337,
492,
6128,
21,
199,
2590,
3545,
26,
523,
687,
6128,
21,
492,
6128,
21,
421,
199,
29007,
63,
13387,
275,
22796,
199,
199,
3,
437,
19768,
6144,
282,
29667,
3444,
17544,
3814,
4437,
14,
199,
3472,
63,
8677,
275,
909,
342,
421,
199,
533,
19259,
547,
8,
1726,
304,
523,
1449,
1563,
1021,
367,
19259,
2552,
2344,
12244,
768,
1829,
523,
347,
1245,
8,
277,
304,
272,
1449,
3407,
314,
1642,
1423,
1202,
370,
6982,
642,
1125,
10595,
272,
372,
291,
14,
589,
59,
16,
61,
421,
199,
533,
9795,
8,
785,
304,
523,
1449,
33,
1021,
6144,
314,
9795,
5523,
1202,
701,
314,
15811,
3261,
14,
819,
710,
9795,
5523,
444,
10553,
314,
2569,
4382,
26,
339,
2004,
14,
3966,
63,
292,
272,
2004,
14,
3966,
63,
292,
63,
262,
63,
4515,
327,
1586,
1454,
272,
2004,
14,
17520,
5703,
272,
2004,
14,
262,
63,
8102,
63,
475,
63,
5410,
63,
354,
272,
2004,
14,
262,
63,
8102,
63,
475,
63,
751,
63,
344,
272,
2004,
14,
262,
63,
8102,
63,
475,
63,
1205,
63,
344,
272,
2004,
14,
19347,
272,
2004,
14,
1365,
272,
2004,
14,
344,
272,
2004,
14,
505,
272,
2004,
14,
6188,
63,
3966,
63,
292,
327,
1586,
1454,
272,
2004,
14,
751,
523,
1449,
523,
347,
636,
826,
721,
277,
12,
2049,
2737,
63,
292,
29,
403,
12,
2049,
17914,
5703,
29,
403,
12,
2049,
1305,
29,
403,
12,
2049,
1318,
29,
403,
12,
2049,
922,
29,
403,
12,
2049,
315,
63,
8102,
63,
475,
63,
5410,
63,
354,
29,
403,
12,
2049,
315,
63,
8102,
63,
475,
63,
751,
63,
344,
29,
403,
12,
2049,
315,
63,
8102,
63,
475,
63,
1205,
63,
344,
29,
403,
12,
2049,
17661,
29,
403,
12,
2049,
1350,
29,
403,
12,
2049,
3063,
29,
403,
304,
272,
1449,
2493,
909,
370,
10266,
282,
19259,
2004,
1245,
14,
339,
961,
1021,
365,
12252,
17544,
701,
314,
15811,
14,
7394,
1021,
436,
272,
2138,
315,
282,
3414,
14,
339,
3390,
26,
577,
2335,
787,
22752,
315,
314,
1824,
298,
22332,
17474,
8087,
28527,
26,
1196,
26,
1703,
435,
993,
10219,
2,
339,
3033,
26,
489,
2737,
63,
292,
26,
710,
900,
642,
2004,
1245,
1990,
22752,
489,
17914,
5703,
26,
7480,
642,
365,
282,
17914,
1175,
402,
314,
15082,
922,
489,
1305,
26,
710,
3747,
1305,
402,
642,
2004,
1245,
489,
1318,
26,
710,
1318,
402,
642,
2004,
1245,
489,
3847,
63,
3966,
63,
292,
26,
267,
437,
11779,
12701,
1059,
6144,
314,
25386,
900,
489,
922,
26,
267,
437,
15811,
14,
1899,
1256,
6144,
314,
4954,
25386,
314,
1245,
489,
3063,
26,
267,
710,
1453,
900,
12,
340,
314,
1890,
2468,
874,
370,
663,
652,
14,
221,
7827,
370,
314,
267,
19882,
12516,
900,
14,
272,
1449,
272,
291,
14,
3966,
63,
292,
275,
2737,
63,
292,
272,
291,
14,
17520,
5703,
275,
17914,
5703,
272,
291,
14,
344,
275,
1305,
272,
291,
14,
505,
275,
1318,
272,
291,
14,
751,
275,
922,
272,
291,
14,
2131,
275,
3063,
272,
291,
14,
262,
63,
8102,
63,
475,
63,
5410,
63,
354,
275,
315,
63,
8102,
63,
475,
63,
5410,
63,
354,
272,
291,
14,
262,
63,
8102,
63,
475,
63,
751,
63,
344,
275,
315,
63,
8102,
63,
475,
63,
751,
63,
344,
272,
291,
14,
262,
63,
8102,
63,
475,
63,
1205,
63,
344,
275,
315,
63,
8102,
63,
475,
63,
1205,
63,
344,
272,
291,
14,
19347,
275,
17661,
272,
291,
14,
1365,
275,
1350,
819,
347,
2372,
10502,
1271,
8,
277,
304,
272,
1449,
1002,
314,
900,
642,
2004,
1245,
1990,
22752,
14,
339,
1803,
26,
489,
710,
900,
642,
2004,
1245,
1990,
22752,
272,
1449,
272,
372,
291,
423,
3966,
63,
292,
819,
347,
2494,
10502,
1271,
8,
277,
12,
2737,
63,
292,
304,
272,
1449,
1084,
314,
900,
642,
2004,
1245,
1990,
22752,
14,
339,
3033,
26,
489,
2737,
63,
292,
26,
710,
900,
642,
2004,
1245,
1990,
2737,
272,
1449,
272,
291,
423,
3966,
63,
292,
275,
2737,
63,
292,
819,
2737,
63,
292,
275,
3324,
8,
1002,
10502,
1271,
12,
2494,
10502,
1271,
12,
717,
1382,
534,
1918,
900,
642,
2004,
1245,
1990,
22752,
2659,
819,
347,
2372,
10502,
1271,
607,
13165,
8,
277,
304,
272,
1449,
1002,
314,
900,
642,
2004,
1245,
1990,
22752,
12,
315,
4696,
3967,
314,
9463,
14,
339,
1803,
26,
489,
710,
900,
642,
2004,
1245,
1990,
22752,
12,
315,
4696,
3967,
314,
9463,
14,
272,
1449,
272,
372,
11234,
14,
521,
13844,
8,
8973,
10228,
14,
1122,
602,
8,
277,
14,
3966,
63,
292,
430,
819,
2737,
63,
292,
63,
262,
63,
4515,
275,
3324,
8,
1002,
10502,
1271,
607,
13165,
12,
3521,
1382,
0
] |
[
1,
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alvinNeo/EasyMLPlatform
|
py/graphic/tree.py
|
1
|
4067
|
#coding:utf8
import numpy as np
import math
import pylab as pl
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import json
class GraphTree:
def __init__(self):
self.jsonobj = {}
self.leafNode = dict(boxstyle = 'round4',fc = '0.8')
self.branchNode = dict(boxstyle = 'sawtooth',fc = '0.8')
self.arrow = dict(arrowstyle = '<-')
self.depth = 0
self.leafcount = 0
def get_depth_leafcount(self,root):
current_node = root.keys()[0] #name of choice node(string)
branch_dict = root[current_node]
maxdepth, thisdepth, thisleafcount = 0,0,0
for current_node in branch_dict.keys():
# print current_node,type(branch_dict[current_node]).__name__
if type(branch_dict[current_node]).__name__ == 'dict':
temp = self.get_depth_leafcount(branch_dict[current_node])
thisdepth = 1 + temp[0]
thisleafcount += temp[1]
else:
thisdepth = 1
thisleafcount += 1
if thisdepth > maxdepth:
maxdepth = thisdepth
return maxdepth,thisleafcount
def load(self,strjson):
self.jsonobj = dict(strjson)
self.depth,self.leafcount = self.get_depth_leafcount(self.jsonobj)
def plotMidText(self, cntrPt, parentPt, txtString):
xMid = (parentPt[0] - cntrPt[0]) / 2.0 + cntrPt[0]
yMid = (parentPt[1] - cntrPt[1]) / 2.0 + cntrPt[1]
self.ax1.text(xMid, yMid, txtString)
def plotNode(self, nodeTxt, cntrPt, parentPt, nodeType):
self.ax1.annotate(nodeTxt, xy = parentPt, xycoords = 'axes fraction', xytext = cntrPt, \
textcoords = 'axes fraction', va = 'center', ha = 'center', bbox = nodeType, arrowprops = self.arrow)
def plotTree(self, myTree, parentPt, nodeTxt):
depth, leaves = self.get_depth_leafcount(myTree)
current_node = myTree.keys()[0]
cntrPt = (self.xOff + (1.0 + leaves) / 2.0 / self.leafcount, self.yOff)
self.plotMidText(cntrPt, parentPt, nodeTxt)
self.plotNode(current_node, cntrPt, parentPt, self.branchNode)
branch_dict = myTree[current_node]
self.yOff -= 1.0 / self.depth
for current_node in branch_dict.keys():
if type(branch_dict[current_node]).__name__ == 'dict':
self.plotTree(branch_dict[current_node], cntrPt, str(current_node))
else:
self.xOff += 1.0 / self.leafcount
self.plotNode(branch_dict[current_node], (self.xOff, self.yOff), cntrPt, self.leafNode)
self.plotMidText((self.xOff, self.yOff), cntrPt, str(current_node))
self.yOff += 1.0 / self.depth
def createPlot(self, show = True, save = ''):
fig = plt.figure(1, facecolor = 'white')
fig.clf()
axprops = dict(xticks = [], yticks = [])
self.ax1 = plt.subplot(111,frameon = False, **axprops)
self.xOff, self.yOff = -0.5 / self.leafcount, 1.0
self.plotTree(self.jsonobj, (0.5,1.0), '')
import StringIO, urllib, base64
if show:
plt.show()
else:
imgdata = StringIO.StringIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0) # rewind the data
uri = 'data:image/png;base64,' + urllib.quote(base64.b64encode(imgdata.buf))
imgdata.close()
return uri
def showPlot(self):
plt.show()
if __name__ == '__main__':
tr = GraphTree()
# aa = '{"no surfacing":{"0":"no","1":{"flippers":{"0":"no","1":"yes"}}}}'
# tr.load(json.loads(aa))
#JSON can't have non-string key
aa = {"aged":{"0":"no","1":{"male":{"0":"no","1":"yes"}}}}
# aa = {'water': {0: 1, 1: {'foot': {0: "'no'", 1: "'yes'"}}}}
print dict(aa)
# aa = {"no surfacing":{0:"no",1:{"flippers":{0:"no",1:"yes"}}}}
# print dict(aa)
tr.load(aa)
print tr.leafcount,tr.depth
tr.createPlot(show=True)
|
apache-2.0
|
[
3,
1523,
26,
1624,
24,
199,
199,
646,
2680,
465,
980,
199,
646,
3473,
199,
646,
19199,
465,
1620,
199,
646,
8027,
14,
4400,
465,
6904,
199,
646,
8027,
14,
757,
371,
465,
333,
5561,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
22513,
63,
3557,
75,
1405,
14,
311,
1653,
19,
68,
492,
437,
12908,
19,
36,
199,
199,
646,
2022,
199,
199,
533,
11513,
3987,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1001,
1113,
275,
1052,
267,
291,
14,
8914,
1716,
275,
1211,
8,
1977,
2487,
275,
283,
2363,
20,
297,
3003,
275,
283,
16,
14,
24,
358,
267,
291,
14,
4694,
1716,
275,
1211,
8,
1977,
2487,
275,
283,
2231,
87,
16453,
297,
3003,
275,
283,
16,
14,
24,
358,
267,
291,
14,
7691,
275,
1211,
8,
7691,
2487,
275,
2650,
25815,
267,
291,
14,
4631,
275,
378,
267,
291,
14,
8914,
835,
275,
378,
339,
347,
664,
63,
4631,
63,
8914,
835,
8,
277,
12,
1231,
304,
267,
1453,
63,
932,
275,
1738,
14,
1612,
3430,
16,
61,
327,
354,
402,
7141,
1031,
8,
875,
9,
267,
5246,
63,
807,
275,
1738,
59,
1818,
63,
932,
61,
267,
1390,
4631,
12,
642,
4631,
12,
642,
8914,
835,
275,
378,
12,
16,
12,
16,
267,
367,
1453,
63,
932,
315,
5246,
63,
807,
14,
1612,
837,
288,
327,
870,
1453,
63,
932,
12,
466,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
855,
354,
363,
7205,
340,
730,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
855,
354,
363,
508,
283,
807,
356,
355,
2388,
275,
291,
14,
362,
63,
4631,
63,
8914,
835,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
355,
642,
4631,
275,
413,
435,
2388,
59,
16,
61,
355,
642,
8914,
835,
847,
2388,
59,
17,
61,
288,
587,
26,
355,
642,
4631,
275,
413,
355,
642,
8914,
835,
847,
413,
288,
340,
642,
4631,
690,
1390,
4631,
26,
355,
1390,
4631,
275,
642,
4631,
267,
372,
1390,
4631,
12,
3749,
8914,
835,
339,
347,
2248,
8,
277,
12,
495,
1001,
304,
267,
291,
14,
1001,
1113,
275,
1211,
8,
495,
1001,
9,
267,
291,
14,
4631,
12,
277,
14,
8914,
835,
275,
291,
14,
362,
63,
4631,
63,
8914,
835,
8,
277,
14,
1001,
1113,
9,
339,
347,
5137,
28735,
1872,
8,
277,
12,
12703,
82,
19886,
12,
1676,
19886,
12,
9444,
1558,
304,
267,
671,
28735,
275,
334,
1708,
19886,
59,
16,
61,
221,
446,
12703,
82,
19886,
59,
16,
566,
1182,
499,
14,
16,
435,
12703,
82,
19886,
59,
16,
61,
267,
612,
28735,
275,
334,
1708,
19886,
59,
17,
61,
221,
446,
12703,
82,
19886,
59,
17,
566,
1182,
499,
14,
16,
435,
12703,
82,
19886,
59,
17,
61,
267,
291,
14,
1219,
17,
14,
505,
8,
88,
28735,
12,
612,
28735,
12,
9444,
1558,
9,
339,
347,
5137,
1716,
8,
277,
12,
1031,
32199,
12,
12703,
82,
19886,
12,
1676,
19886,
12,
1031,
804,
304,
267,
291,
14,
1219,
17,
14,
10898,
8,
932,
32199,
12,
13222,
275,
1676,
19886,
12,
13222,
8032,
275,
283,
6402,
12347,
297,
13222,
505,
275,
12703,
82,
19886,
12,
971,
1467,
1318,
8032,
275,
283,
6402,
12347,
297,
25819,
275,
283,
4218,
297,
18251,
275,
283,
4218,
297,
12494,
275,
1031,
804,
12,
18800,
6750,
275,
291,
14,
7691,
9,
339,
347,
5137,
3987,
8,
277,
12,
3002,
3987,
12,
1676,
19886,
12,
1031,
32199,
304,
267,
5818,
12,
16733,
275,
291,
14,
362,
63,
4631,
63,
8914,
835,
8,
1662,
3987,
9,
267,
1453,
63,
932,
275,
3002,
3987,
14,
1612,
3430,
16,
61,
267,
12703,
82,
19886,
275,
334,
277,
14,
88,
5195,
435,
334,
17,
14,
16,
435,
16733,
9,
1182,
499,
14,
16,
1182,
291,
14,
8914,
835,
12,
291,
14,
89,
5195,
9,
267,
291,
14,
2798,
28735,
1872,
8,
6507,
82,
19886,
12,
1676,
19886,
12,
1031,
32199,
9,
267,
291,
14,
2798,
1716,
8,
1818,
63,
932,
12,
12703,
82,
19886,
12,
1676,
19886,
12,
291,
14,
4694,
1716,
9,
267,
5246,
63,
807,
275,
3002,
3987,
59,
1818,
63,
932,
61,
267,
291,
14,
89,
5195,
4862,
413,
14,
16,
1182,
291,
14,
4631,
259,
267,
367,
1453,
63,
932,
315,
5246,
63,
807,
14,
1612,
837,
288,
340,
730,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
855,
354,
363,
508,
283,
807,
356,
355,
291,
14,
2798,
3987,
8,
4694,
63,
807,
59,
1818,
63,
932,
467,
12703,
82,
19886,
12,
620,
8,
1818,
63,
932,
430,
288,
587,
26,
355,
291,
14,
88,
5195,
847,
413,
14,
16,
1182,
291,
14,
8914,
835,
355,
291,
14,
2798,
1716,
8,
4694,
63,
807,
59,
1818,
63,
932,
467,
334,
277,
14,
88,
5195,
12,
291,
14,
89,
5195,
395,
12703,
82,
19886,
12,
291,
14,
8914,
1716,
9,
355,
291,
14,
2798,
28735,
1872,
1332,
277,
14,
88,
5195,
12,
291,
14,
89,
5195,
395,
12703,
82,
19886,
12,
620,
8,
1818,
63,
932,
430,
267,
291,
14,
89,
5195,
847,
413,
14,
16,
1182,
291,
14,
4631,
339,
347,
1218,
10711,
8,
277,
12,
2498,
275,
715,
12,
3354,
275,
21019,
267,
6085,
275,
4488,
14,
8941,
8,
17,
12,
8870,
2326,
275,
283,
7510,
358,
267,
6085,
14,
9694,
342,
267,
2185,
6750,
275,
1211,
8,
26217,
275,
990,
612,
10406,
275,
3073,
267,
291,
14,
1219,
17,
275,
4488,
14,
13334,
8,
6673,
12,
1943,
265,
275,
756,
12,
1011,
1219,
6750,
9,
267,
291,
14,
88,
5195,
12,
291,
14,
89,
5195,
275,
446,
16,
14,
21,
1182,
291,
14,
8914,
835,
12,
413,
14,
16,
267,
291,
14,
2798,
3987,
8,
277,
14,
1001,
1113,
12,
334,
16,
14,
21,
12,
17,
14,
16,
395,
4074,
267,
492,
5228,
12,
4011,
12,
1300,
772,
267,
340,
2498,
26,
288,
4488,
14,
2384,
342,
267,
587,
26,
288,
6050,
576,
275,
5228,
14,
6424,
342,
288,
6085,
14,
19556,
8,
4060,
576,
12,
1475,
534,
4524,
358,
288,
6050,
576,
14,
5507,
8,
16,
9,
221,
327,
295,
11530,
314,
666,
288,
5108,
275,
283,
576,
26,
1569,
15,
4524,
27,
1095,
772
] |
[
1523,
26,
1624,
24,
199,
199,
646,
2680,
465,
980,
199,
646,
3473,
199,
646,
19199,
465,
1620,
199,
646,
8027,
14,
4400,
465,
6904,
199,
646,
8027,
14,
757,
371,
465,
333,
5561,
199,
646,
8027,
14,
13563,
465,
4488,
199,
504,
22513,
63,
3557,
75,
1405,
14,
311,
1653,
19,
68,
492,
437,
12908,
19,
36,
199,
199,
646,
2022,
199,
199,
533,
11513,
3987,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1001,
1113,
275,
1052,
267,
291,
14,
8914,
1716,
275,
1211,
8,
1977,
2487,
275,
283,
2363,
20,
297,
3003,
275,
283,
16,
14,
24,
358,
267,
291,
14,
4694,
1716,
275,
1211,
8,
1977,
2487,
275,
283,
2231,
87,
16453,
297,
3003,
275,
283,
16,
14,
24,
358,
267,
291,
14,
7691,
275,
1211,
8,
7691,
2487,
275,
2650,
25815,
267,
291,
14,
4631,
275,
378,
267,
291,
14,
8914,
835,
275,
378,
339,
347,
664,
63,
4631,
63,
8914,
835,
8,
277,
12,
1231,
304,
267,
1453,
63,
932,
275,
1738,
14,
1612,
3430,
16,
61,
327,
354,
402,
7141,
1031,
8,
875,
9,
267,
5246,
63,
807,
275,
1738,
59,
1818,
63,
932,
61,
267,
1390,
4631,
12,
642,
4631,
12,
642,
8914,
835,
275,
378,
12,
16,
12,
16,
267,
367,
1453,
63,
932,
315,
5246,
63,
807,
14,
1612,
837,
288,
327,
870,
1453,
63,
932,
12,
466,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
855,
354,
363,
7205,
340,
730,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
855,
354,
363,
508,
283,
807,
356,
355,
2388,
275,
291,
14,
362,
63,
4631,
63,
8914,
835,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
355,
642,
4631,
275,
413,
435,
2388,
59,
16,
61,
355,
642,
8914,
835,
847,
2388,
59,
17,
61,
288,
587,
26,
355,
642,
4631,
275,
413,
355,
642,
8914,
835,
847,
413,
288,
340,
642,
4631,
690,
1390,
4631,
26,
355,
1390,
4631,
275,
642,
4631,
267,
372,
1390,
4631,
12,
3749,
8914,
835,
339,
347,
2248,
8,
277,
12,
495,
1001,
304,
267,
291,
14,
1001,
1113,
275,
1211,
8,
495,
1001,
9,
267,
291,
14,
4631,
12,
277,
14,
8914,
835,
275,
291,
14,
362,
63,
4631,
63,
8914,
835,
8,
277,
14,
1001,
1113,
9,
339,
347,
5137,
28735,
1872,
8,
277,
12,
12703,
82,
19886,
12,
1676,
19886,
12,
9444,
1558,
304,
267,
671,
28735,
275,
334,
1708,
19886,
59,
16,
61,
221,
446,
12703,
82,
19886,
59,
16,
566,
1182,
499,
14,
16,
435,
12703,
82,
19886,
59,
16,
61,
267,
612,
28735,
275,
334,
1708,
19886,
59,
17,
61,
221,
446,
12703,
82,
19886,
59,
17,
566,
1182,
499,
14,
16,
435,
12703,
82,
19886,
59,
17,
61,
267,
291,
14,
1219,
17,
14,
505,
8,
88,
28735,
12,
612,
28735,
12,
9444,
1558,
9,
339,
347,
5137,
1716,
8,
277,
12,
1031,
32199,
12,
12703,
82,
19886,
12,
1676,
19886,
12,
1031,
804,
304,
267,
291,
14,
1219,
17,
14,
10898,
8,
932,
32199,
12,
13222,
275,
1676,
19886,
12,
13222,
8032,
275,
283,
6402,
12347,
297,
13222,
505,
275,
12703,
82,
19886,
12,
971,
1467,
1318,
8032,
275,
283,
6402,
12347,
297,
25819,
275,
283,
4218,
297,
18251,
275,
283,
4218,
297,
12494,
275,
1031,
804,
12,
18800,
6750,
275,
291,
14,
7691,
9,
339,
347,
5137,
3987,
8,
277,
12,
3002,
3987,
12,
1676,
19886,
12,
1031,
32199,
304,
267,
5818,
12,
16733,
275,
291,
14,
362,
63,
4631,
63,
8914,
835,
8,
1662,
3987,
9,
267,
1453,
63,
932,
275,
3002,
3987,
14,
1612,
3430,
16,
61,
267,
12703,
82,
19886,
275,
334,
277,
14,
88,
5195,
435,
334,
17,
14,
16,
435,
16733,
9,
1182,
499,
14,
16,
1182,
291,
14,
8914,
835,
12,
291,
14,
89,
5195,
9,
267,
291,
14,
2798,
28735,
1872,
8,
6507,
82,
19886,
12,
1676,
19886,
12,
1031,
32199,
9,
267,
291,
14,
2798,
1716,
8,
1818,
63,
932,
12,
12703,
82,
19886,
12,
1676,
19886,
12,
291,
14,
4694,
1716,
9,
267,
5246,
63,
807,
275,
3002,
3987,
59,
1818,
63,
932,
61,
267,
291,
14,
89,
5195,
4862,
413,
14,
16,
1182,
291,
14,
4631,
259,
267,
367,
1453,
63,
932,
315,
5246,
63,
807,
14,
1612,
837,
288,
340,
730,
8,
4694,
63,
807,
59,
1818,
63,
932,
566,
855,
354,
363,
508,
283,
807,
356,
355,
291,
14,
2798,
3987,
8,
4694,
63,
807,
59,
1818,
63,
932,
467,
12703,
82,
19886,
12,
620,
8,
1818,
63,
932,
430,
288,
587,
26,
355,
291,
14,
88,
5195,
847,
413,
14,
16,
1182,
291,
14,
8914,
835,
355,
291,
14,
2798,
1716,
8,
4694,
63,
807,
59,
1818,
63,
932,
467,
334,
277,
14,
88,
5195,
12,
291,
14,
89,
5195,
395,
12703,
82,
19886,
12,
291,
14,
8914,
1716,
9,
355,
291,
14,
2798,
28735,
1872,
1332,
277,
14,
88,
5195,
12,
291,
14,
89,
5195,
395,
12703,
82,
19886,
12,
620,
8,
1818,
63,
932,
430,
267,
291,
14,
89,
5195,
847,
413,
14,
16,
1182,
291,
14,
4631,
339,
347,
1218,
10711,
8,
277,
12,
2498,
275,
715,
12,
3354,
275,
21019,
267,
6085,
275,
4488,
14,
8941,
8,
17,
12,
8870,
2326,
275,
283,
7510,
358,
267,
6085,
14,
9694,
342,
267,
2185,
6750,
275,
1211,
8,
26217,
275,
990,
612,
10406,
275,
3073,
267,
291,
14,
1219,
17,
275,
4488,
14,
13334,
8,
6673,
12,
1943,
265,
275,
756,
12,
1011,
1219,
6750,
9,
267,
291,
14,
88,
5195,
12,
291,
14,
89,
5195,
275,
446,
16,
14,
21,
1182,
291,
14,
8914,
835,
12,
413,
14,
16,
267,
291,
14,
2798,
3987,
8,
277,
14,
1001,
1113,
12,
334,
16,
14,
21,
12,
17,
14,
16,
395,
4074,
267,
492,
5228,
12,
4011,
12,
1300,
772,
267,
340,
2498,
26,
288,
4488,
14,
2384,
342,
267,
587,
26,
288,
6050,
576,
275,
5228,
14,
6424,
342,
288,
6085,
14,
19556,
8,
4060,
576,
12,
1475,
534,
4524,
358,
288,
6050,
576,
14,
5507,
8,
16,
9,
221,
327,
295,
11530,
314,
666,
288,
5108,
275,
283,
576,
26,
1569,
15,
4524,
27,
1095,
772,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dfalt974/SickRage
|
lib/rebulk/validators.py
|
33
|
1589
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Validator functions to use in patterns.
All those function have last argument as match, so it's possible to use functools.partial to bind previous arguments.
"""
def chars_before(chars, match):
"""
Validate the match if left character is in a given sequence.
:param chars:
:type chars:
:param match:
:type match:
:return:
:rtype:
"""
if match.start <= 0:
return True
return match.input_string[match.start - 1] in chars
def chars_after(chars, match):
"""
Validate the match if right character is in a given sequence.
:param chars:
:type chars:
:param match:
:type match:
:return:
:rtype:
"""
if match.end >= len(match.input_string):
return True
return match.input_string[match.end] in chars
def chars_surround(chars, match):
"""
Validate the match if surrounding characters are in a given sequence.
:param chars:
:type chars:
:param match:
:type match:
:return:
:rtype:
"""
return chars_before(chars, match) and chars_after(chars, match)
def validators(*chained_validators):
"""
Creates a validator chain from several validator functions.
:param chained_validators:
:type chained_validators:
:return:
:rtype:
"""
def validator_chain(match): # pylint:disable=missing-docstring
for chained_validator in chained_validators:
if not chained_validator(match):
return False
return True
return validator_chain
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
8640,
3423,
370,
675,
315,
7970,
14,
199,
199,
2422,
5204,
805,
1172,
2061,
1423,
465,
1336,
12,
880,
652,
1159,
3962,
370,
675,
9143,
14,
6672,
370,
5398,
4136,
2368,
14,
199,
624,
421,
199,
318,
8365,
63,
5182,
8,
6574,
12,
1336,
304,
272,
408,
272,
12134,
314,
1336,
340,
3602,
4528,
365,
315,
282,
1627,
3414,
14,
339,
520,
635,
8365,
26,
272,
520,
466,
8365,
26,
272,
520,
635,
1336,
26,
272,
520,
466,
1336,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
340,
1336,
14,
928,
2695,
378,
26,
267,
372,
715,
272,
372,
1336,
14,
1210,
63,
875,
59,
1431,
14,
928,
446,
413,
61,
315,
8365,
421,
199,
318,
8365,
63,
4399,
8,
6574,
12,
1336,
304,
272,
408,
272,
12134,
314,
1336,
340,
2451,
4528,
365,
315,
282,
1627,
3414,
14,
339,
520,
635,
8365,
26,
272,
520,
466,
8365,
26,
272,
520,
635,
1336,
26,
272,
520,
466,
1336,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
340,
1336,
14,
500,
2356,
822,
8,
1431,
14,
1210,
63,
875,
304,
267,
372,
715,
272,
372,
1336,
14,
1210,
63,
875,
59,
1431,
14,
500,
61,
315,
8365,
421,
199,
318,
8365,
63,
5105,
2363,
8,
6574,
12,
1336,
304,
272,
408,
272,
12134,
314,
1336,
340,
6296,
15326,
4110,
787,
315,
282,
1627,
3414,
14,
339,
520,
635,
8365,
26,
272,
520,
466,
8365,
26,
272,
520,
635,
1336,
26,
272,
520,
466,
1336,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
372,
8365,
63,
5182,
8,
6574,
12,
1336,
9,
436,
8365,
63,
4399,
8,
6574,
12,
1336,
9,
421,
199,
318,
14370,
2031,
4429,
379,
63,
11346,
304,
272,
408,
272,
10560,
282,
11822,
6036,
687,
9978,
11822,
3423,
14,
339,
520,
635,
6036,
379,
63,
11346,
26,
272,
520,
466,
6036,
379,
63,
11346,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
347,
11822,
63,
4429,
8,
1431,
304,
221,
327,
4287,
26,
5993,
29,
4752,
13,
12485,
267,
367,
6036,
379,
63,
11034,
315,
6036,
379,
63,
11346,
26,
288,
340,
440,
6036,
379,
63,
11034,
8,
1431,
304,
355,
372,
756,
267,
372,
715,
272,
372,
11822,
63,
4429,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
8640,
3423,
370,
675,
315,
7970,
14,
199,
199,
2422,
5204,
805,
1172,
2061,
1423,
465,
1336,
12,
880,
652,
1159,
3962,
370,
675,
9143,
14,
6672,
370,
5398,
4136,
2368,
14,
199,
624,
421,
199,
318,
8365,
63,
5182,
8,
6574,
12,
1336,
304,
272,
408,
272,
12134,
314,
1336,
340,
3602,
4528,
365,
315,
282,
1627,
3414,
14,
339,
520,
635,
8365,
26,
272,
520,
466,
8365,
26,
272,
520,
635,
1336,
26,
272,
520,
466,
1336,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
340,
1336,
14,
928,
2695,
378,
26,
267,
372,
715,
272,
372,
1336,
14,
1210,
63,
875,
59,
1431,
14,
928,
446,
413,
61,
315,
8365,
421,
199,
318,
8365,
63,
4399,
8,
6574,
12,
1336,
304,
272,
408,
272,
12134,
314,
1336,
340,
2451,
4528,
365,
315,
282,
1627,
3414,
14,
339,
520,
635,
8365,
26,
272,
520,
466,
8365,
26,
272,
520,
635,
1336,
26,
272,
520,
466,
1336,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
340,
1336,
14,
500,
2356,
822,
8,
1431,
14,
1210,
63,
875,
304,
267,
372,
715,
272,
372,
1336,
14,
1210,
63,
875,
59,
1431,
14,
500,
61,
315,
8365,
421,
199,
318,
8365,
63,
5105,
2363,
8,
6574,
12,
1336,
304,
272,
408,
272,
12134,
314,
1336,
340,
6296,
15326,
4110,
787,
315,
282,
1627,
3414,
14,
339,
520,
635,
8365,
26,
272,
520,
466,
8365,
26,
272,
520,
635,
1336,
26,
272,
520,
466,
1336,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
372,
8365,
63,
5182,
8,
6574,
12,
1336,
9,
436,
8365,
63,
4399,
8,
6574,
12,
1336,
9,
421,
199,
318,
14370,
2031,
4429,
379,
63,
11346,
304,
272,
408,
272,
10560,
282,
11822,
6036,
687,
9978,
11822,
3423,
14,
339,
520,
635,
6036,
379,
63,
11346,
26,
272,
520,
466,
6036,
379,
63,
11346,
26,
272,
520,
1107,
26,
272,
520,
4500,
26,
272,
408,
272,
347,
11822,
63,
4429,
8,
1431,
304,
221,
327,
4287,
26,
5993,
29,
4752,
13,
12485,
267,
367,
6036,
379,
63,
11034,
315,
6036,
379,
63,
11346,
26,
288,
340,
440,
6036,
379,
63,
11034,
8,
1431,
304,
355,
372,
756,
267,
372,
715,
272,
372,
11822,
63,
4429,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
khiner/aubio
|
python/demos/demo_waveform_plot.py
|
10
|
2099
|
#! /usr/bin/env python
import sys
from aubio import pvoc, source
from numpy import zeros, hstack
def get_waveform_plot(filename, samplerate = 0, block_size = 4096, ax = None, downsample = 2**4):
import matplotlib.pyplot as plt
if not ax:
fig = plt.figure()
ax = fig.add_subplot(111)
hop_s = block_size
allsamples_max = zeros(0,)
downsample = downsample # to plot n samples / hop_s
a = source(filename, samplerate, hop_s) # source file
if samplerate == 0: samplerate = a.samplerate
total_frames = 0
while True:
samples, read = a()
# keep some data to plot it later
new_maxes = (abs(samples.reshape(hop_s/downsample, downsample))).max(axis=0)
allsamples_max = hstack([allsamples_max, new_maxes])
total_frames += read
if read < hop_s: break
allsamples_max = (allsamples_max > 0) * allsamples_max
allsamples_max_times = [ ( float (t) / downsample ) * hop_s for t in range(len(allsamples_max)) ]
ax.plot(allsamples_max_times, allsamples_max, '-b')
ax.plot(allsamples_max_times, -allsamples_max, '-b')
ax.axis(xmin = allsamples_max_times[0], xmax = allsamples_max_times[-1])
set_xlabels_sample2time(ax, allsamples_max_times[-1], samplerate)
return ax
def set_xlabels_sample2time(ax, latest_sample, samplerate):
ax.axis(xmin = 0, xmax = latest_sample)
if latest_sample / float(samplerate) > 60:
ax.set_xlabel('time (mm:ss)')
ax.set_xticklabels([ "%02d:%02d" % (t/float(samplerate)/60, (t/float(samplerate))%60) for t in ax.get_xticks()[:-1]], rotation = 50)
else:
ax.set_xlabel('time (ss.mm)')
ax.set_xticklabels([ "%02d.%02d" % (t/float(samplerate), 100*((t/float(samplerate))%1) ) for t in ax.get_xticks()[:-1]], rotation = 50)
if __name__ == '__main__':
import matplotlib.pyplot as plt
if len(sys.argv) < 2:
print "Usage: %s <filename>" % sys.argv[0]
else:
for soundfile in sys.argv[1:]:
get_waveform_plot(soundfile)
# display graph
plt.show()
|
gpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
199,
504,
282,
456,
2308,
492,
20279,
679,
12,
1350,
199,
504,
2680,
492,
10136,
12,
394,
2340,
199,
199,
318,
664,
63,
10024,
964,
63,
2798,
8,
1501,
12,
2690,
1866,
275,
378,
12,
1853,
63,
890,
275,
17125,
12,
2185,
275,
488,
12,
366,
23311,
865,
275,
499,
538,
20,
304,
272,
492,
8027,
14,
13563,
465,
4488,
272,
340,
440,
2185,
26,
267,
6085,
275,
4488,
14,
8941,
342,
267,
2185,
275,
6085,
14,
525,
63,
13334,
8,
6673,
9,
272,
22377,
63,
83,
275,
1853,
63,
890,
339,
1006,
3356,
63,
988,
275,
10136,
8,
16,
4258,
272,
366,
23311,
865,
275,
366,
23311,
865,
221,
327,
370,
5137,
302,
5845,
1182,
22377,
63,
83,
339,
282,
275,
1350,
8,
1501,
12,
2690,
1866,
12,
22377,
63,
83,
9,
3322,
327,
1350,
570,
272,
340,
2690,
1866,
508,
378,
26,
2690,
1866,
275,
282,
14,
3271,
1866,
339,
3141,
63,
8444,
275,
378,
272,
1830,
715,
26,
267,
5845,
12,
1586,
275,
282,
342,
267,
327,
4215,
2005,
666,
370,
5137,
652,
2945,
267,
892,
63,
988,
397,
275,
334,
2101,
8,
3356,
14,
5217,
8,
13376,
63,
83,
15,
68,
23311,
865,
12,
366,
23311,
865,
23261,
988,
8,
3127,
29,
16,
9,
267,
1006,
3356,
63,
988,
275,
394,
2340,
779,
452,
3356,
63,
988,
12,
892,
63,
988,
397,
566,
267,
3141,
63,
8444,
847,
1586,
267,
340,
1586,
665,
22377,
63,
83,
26,
2059,
272,
1006,
3356,
63,
988,
275,
334,
452,
3356,
63,
988,
690,
378,
9,
627,
1006,
3356,
63,
988,
272,
1006,
3356,
63,
988,
63,
4508,
275,
359,
334,
2069,
334,
84,
9,
1182,
366,
23311,
865,
776,
627,
22377,
63,
83,
367,
307,
315,
1425,
8,
552,
8,
452,
3356,
63,
988,
430,
1622,
339,
2185,
14,
2798,
8,
452,
3356,
63,
988,
63,
4508,
12,
221,
1006,
3356,
63,
988,
12,
2475,
66,
358,
272,
2185,
14,
2798,
8,
452,
3356,
63,
988,
63,
4508,
12,
446,
452,
3356,
63,
988,
12,
2475,
66,
358,
272,
2185,
14,
3127,
8,
21601,
275,
1006,
3356,
63,
988,
63,
4508,
59,
16,
467,
19906,
275,
1006,
3356,
63,
988,
63,
4508,
1988,
17,
566,
339,
663,
63,
88,
3512,
63,
3271,
18,
521,
8,
1219,
12,
1006,
3356,
63,
988,
63,
4508,
1988,
17,
467,
2690,
1866,
9,
272,
372,
2185,
199,
199,
318,
663,
63,
88,
3512,
63,
3271,
18,
521,
8,
1219,
12,
8839,
63,
3271,
12,
2690,
1866,
304,
272,
2185,
14,
3127,
8,
21601,
275,
378,
12,
19906,
275,
8839,
63,
3271,
9,
272,
340,
8839,
63,
3271,
1182,
2069,
8,
3271,
1866,
9,
690,
5212,
26,
267,
2185,
14,
409,
63,
14168,
360,
521,
334,
596,
26,
385,
5942,
267,
2185,
14,
409,
63,
88,
27435,
779,
2071,
996,
68,
2689,
996,
68,
2,
450,
334,
84,
15,
1609,
8,
3271,
1866,
2447,
2259,
12,
334,
84,
15,
1609,
8,
3271,
1866,
430,
5,
2259,
9,
367,
307,
315,
2185,
14,
362,
63,
26217,
342,
4439,
17,
2365,
13038,
275,
5238,
9,
272,
587,
26,
267,
2185,
14,
409,
63,
14168,
360,
521,
334,
385,
14,
596,
5942,
267,
2185,
14,
409,
63,
88,
27435,
779,
2071,
996,
68,
4111,
996,
68,
2,
450,
334,
84,
15,
1609,
8,
3271,
1866,
395,
2948,
10,
1332,
84,
15,
1609,
8,
3271,
1866,
430,
5,
17,
9,
776,
367,
307,
315,
2185,
14,
362,
63,
26217,
342,
4439,
17,
2365,
13038,
275,
5238,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
8027,
14,
13563,
465,
4488,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
870,
298,
7692,
26,
450,
83,
665,
1501,
4335,
450,
984,
14,
3020,
59,
16,
61,
272,
587,
26,
267,
367,
20453,
493,
315,
984,
14,
3020,
59,
17,
10688,
288,
664,
63,
10024,
964,
63,
2798,
8,
14990,
493,
9,
288,
327,
2929,
3343,
288,
4488,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
199,
504,
282,
456,
2308,
492,
20279,
679,
12,
1350,
199,
504,
2680,
492,
10136,
12,
394,
2340,
199,
199,
318,
664,
63,
10024,
964,
63,
2798,
8,
1501,
12,
2690,
1866,
275,
378,
12,
1853,
63,
890,
275,
17125,
12,
2185,
275,
488,
12,
366,
23311,
865,
275,
499,
538,
20,
304,
272,
492,
8027,
14,
13563,
465,
4488,
272,
340,
440,
2185,
26,
267,
6085,
275,
4488,
14,
8941,
342,
267,
2185,
275,
6085,
14,
525,
63,
13334,
8,
6673,
9,
272,
22377,
63,
83,
275,
1853,
63,
890,
339,
1006,
3356,
63,
988,
275,
10136,
8,
16,
4258,
272,
366,
23311,
865,
275,
366,
23311,
865,
221,
327,
370,
5137,
302,
5845,
1182,
22377,
63,
83,
339,
282,
275,
1350,
8,
1501,
12,
2690,
1866,
12,
22377,
63,
83,
9,
3322,
327,
1350,
570,
272,
340,
2690,
1866,
508,
378,
26,
2690,
1866,
275,
282,
14,
3271,
1866,
339,
3141,
63,
8444,
275,
378,
272,
1830,
715,
26,
267,
5845,
12,
1586,
275,
282,
342,
267,
327,
4215,
2005,
666,
370,
5137,
652,
2945,
267,
892,
63,
988,
397,
275,
334,
2101,
8,
3356,
14,
5217,
8,
13376,
63,
83,
15,
68,
23311,
865,
12,
366,
23311,
865,
23261,
988,
8,
3127,
29,
16,
9,
267,
1006,
3356,
63,
988,
275,
394,
2340,
779,
452,
3356,
63,
988,
12,
892,
63,
988,
397,
566,
267,
3141,
63,
8444,
847,
1586,
267,
340,
1586,
665,
22377,
63,
83,
26,
2059,
272,
1006,
3356,
63,
988,
275,
334,
452,
3356,
63,
988,
690,
378,
9,
627,
1006,
3356,
63,
988,
272,
1006,
3356,
63,
988,
63,
4508,
275,
359,
334,
2069,
334,
84,
9,
1182,
366,
23311,
865,
776,
627,
22377,
63,
83,
367,
307,
315,
1425,
8,
552,
8,
452,
3356,
63,
988,
430,
1622,
339,
2185,
14,
2798,
8,
452,
3356,
63,
988,
63,
4508,
12,
221,
1006,
3356,
63,
988,
12,
2475,
66,
358,
272,
2185,
14,
2798,
8,
452,
3356,
63,
988,
63,
4508,
12,
446,
452,
3356,
63,
988,
12,
2475,
66,
358,
272,
2185,
14,
3127,
8,
21601,
275,
1006,
3356,
63,
988,
63,
4508,
59,
16,
467,
19906,
275,
1006,
3356,
63,
988,
63,
4508,
1988,
17,
566,
339,
663,
63,
88,
3512,
63,
3271,
18,
521,
8,
1219,
12,
1006,
3356,
63,
988,
63,
4508,
1988,
17,
467,
2690,
1866,
9,
272,
372,
2185,
199,
199,
318,
663,
63,
88,
3512,
63,
3271,
18,
521,
8,
1219,
12,
8839,
63,
3271,
12,
2690,
1866,
304,
272,
2185,
14,
3127,
8,
21601,
275,
378,
12,
19906,
275,
8839,
63,
3271,
9,
272,
340,
8839,
63,
3271,
1182,
2069,
8,
3271,
1866,
9,
690,
5212,
26,
267,
2185,
14,
409,
63,
14168,
360,
521,
334,
596,
26,
385,
5942,
267,
2185,
14,
409,
63,
88,
27435,
779,
2071,
996,
68,
2689,
996,
68,
2,
450,
334,
84,
15,
1609,
8,
3271,
1866,
2447,
2259,
12,
334,
84,
15,
1609,
8,
3271,
1866,
430,
5,
2259,
9,
367,
307,
315,
2185,
14,
362,
63,
26217,
342,
4439,
17,
2365,
13038,
275,
5238,
9,
272,
587,
26,
267,
2185,
14,
409,
63,
14168,
360,
521,
334,
385,
14,
596,
5942,
267,
2185,
14,
409,
63,
88,
27435,
779,
2071,
996,
68,
4111,
996,
68,
2,
450,
334,
84,
15,
1609,
8,
3271,
1866,
395,
2948,
10,
1332,
84,
15,
1609,
8,
3271,
1866,
430,
5,
17,
9,
776,
367,
307,
315,
2185,
14,
362,
63,
26217,
342,
4439,
17,
2365,
13038,
275,
5238,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
8027,
14,
13563,
465,
4488,
272,
340,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
267,
870,
298,
7692,
26,
450,
83,
665,
1501,
4335,
450,
984,
14,
3020,
59,
16,
61,
272,
587,
26,
267,
367,
20453,
493,
315,
984,
14,
3020,
59,
17,
10688,
288,
664,
63,
10024,
964,
63,
2798,
8,
14990,
493,
9,
288,
327,
2929,
3343,
288,
4488,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
archf/ansible
|
lib/ansible/modules/network/netscaler/netscaler_gslb_site.py
|
27
|
14153
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2017 Citrix Systems
# 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: netscaler_gslb_site
short_description: Manage gslb site entities in Netscaler.
description:
- Manage gslb site entities in Netscaler.
version_added: "2.4.0"
author: George Nikolopoulos (@giorgos-nikolopoulos)
options:
sitename:
description:
- >-
Name for the GSLB site. Must begin with an ASCII alphanumeric or underscore C(_) character, and must
contain only ASCII alphanumeric, underscore C(_), hash C(#), period C(.), space C( ), colon C(:), at C(@), equals
C(=), and hyphen C(-) characters. Cannot be changed after the virtual server is created.
- "Minimum length = 1"
sitetype:
choices:
- 'REMOTE'
- 'LOCAL'
description:
- >-
Type of site to create. If the type is not specified, the appliance automatically detects and sets
the type on the basis of the IP address being assigned to the site. If the specified site IP address
is owned by the appliance (for example, a MIP address or SNIP address), the site is a local site.
Otherwise, it is a remote site.
siteipaddress:
description:
- >-
IP address for the GSLB site. The GSLB site uses this IP address to communicate with other GSLB
sites. For a local site, use any IP address that is owned by the appliance (for example, a SNIP or
MIP address, or the IP address of the ADNS service).
- "Minimum length = 1"
publicip:
description:
- >-
Public IP address for the local site. Required only if the appliance is deployed in a private address
space and the site has a public IP address hosted on an external firewall or a NAT device.
- "Minimum length = 1"
metricexchange:
choices:
- 'enabled'
- 'disabled'
description:
- >-
Exchange metrics with other sites. Metrics are exchanged by using Metric Exchange Protocol (MEP). The
appliances in the GSLB setup exchange health information once every second.
- >-
If you disable metrics exchange, you can use only static load balancing methods (such as round robin,
static proximity, or the hash-based methods), and if you disable metrics exchange when a dynamic load
balancing method (such as least connection) is in operation, the appliance falls back to round robin.
Also, if you disable metrics exchange, you must use a monitor to determine the state of GSLB
services. Otherwise, the service is marked as DOWN.
nwmetricexchange:
choices:
- 'enabled'
- 'disabled'
description:
- >-
Exchange, with other GSLB sites, network metrics such as round-trip time (RTT), learned from
communications with various local DNS (LDNS) servers used by clients. RTT information is used in the
dynamic RTT load balancing method, and is exchanged every 5 seconds.
sessionexchange:
choices:
- 'enabled'
- 'disabled'
description:
- "Exchange persistent session entries with other GSLB sites every five seconds."
triggermonitor:
choices:
- 'ALWAYS'
- 'MEPDOWN'
- 'MEPDOWN_SVCDOWN'
description:
- >-
Specify the conditions under which the GSLB service must be monitored by a monitor, if one is bound.
Available settings function as follows:
- "* C(ALWAYS) - Monitor the GSLB service at all times."
- >-
* C(MEPDOWN) - Monitor the GSLB service only when the exchange of metrics through the Metrics Exchange
Protocol (MEP) is disabled.
- "C(MEPDOWN_SVCDOWN) - Monitor the service in either of the following situations:"
- "* The exchange of metrics through MEP is disabled."
- >-
* The exchange of metrics through MEP is enabled but the status of the service, learned through
metrics exchange, is DOWN.
parentsite:
description:
- "Parent site of the GSLB site, in a parent-child topology."
clip:
description:
- >-
Cluster IP address. Specify this parameter to connect to the remote cluster site for GSLB auto-sync.
Note: The cluster IP address is defined when creating the cluster.
publicclip:
description:
- >-
IP address to be used to globally access the remote cluster when it is deployed behind a NAT. It can
be same as the normal cluster IP address.
naptrreplacementsuffix:
description:
- >-
The naptr replacement suffix configured here will be used to construct the naptr replacement field in
NAPTR record.
- "Minimum length = 1"
extends_documentation_fragment: netscaler
requirements:
- nitro python sdk
'''
EXAMPLES = '''
- name: Setup gslb site
delegate_to: localhost
netscaler_gslb_site:
nsip: 172.18.0.2
nitro_user: nsroot
nitro_pass: nsroot
sitename: gslb-site-1
siteipaddress: 192.168.1.1
sitetype: LOCAL
publicip: 192.168.1.1
metricexchange: enabled
nwmetricexchange: enabled
sessionexchange: enabled
triggermonitor: ALWAYS
'''
RETURN = '''
loglines:
description: list of logged messages by the module
returned: always
type: list
sample: "['message 1', 'message 2']"
msg:
description: Message detailing the failure reason
returned: failure
type: string
sample: "Action does not exist"
diff:
description: List of differences between the actual configured object and the configuration specified in the module
returned: failure
type: dictionary
sample: "{ 'targetlbvserver': 'difference. ours: (str) server1 other: (str) server2' }"
'''
try:
from nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbsite import gslbsite
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
PYTHON_SDK_IMPORTED = True
except ImportError as e:
PYTHON_SDK_IMPORTED = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.netscaler import (
ConfigProxy,
get_nitro_client,
netscaler_common_arguments,
log,
loglines,
ensure_feature_is_enabled,
get_immutables_intersection,
)
def gslb_site_exists(client, module):
if gslbsite.count_filtered(client, 'sitename:%s' % module.params['sitename']) > 0:
return True
else:
return False
def gslb_site_identical(client, module, gslb_site_proxy):
gslb_site_list = gslbsite.get_filtered(client, 'sitename:%s' % module.params['sitename'])
diff_dict = gslb_site_proxy.diff_object(gslb_site_list[0])
if len(diff_dict) == 0:
return True
else:
return False
def diff_list(client, module, gslb_site_proxy):
gslb_site_list = gslbsite.get_filtered(client, 'sitename:%s' % module.params['sitename'])
return gslb_site_proxy.diff_object(gslb_site_list[0])
def main():
module_specific_arguments = dict(
sitename=dict(type='str'),
sitetype=dict(
type='str',
choices=[
'REMOTE',
'LOCAL',
]
),
siteipaddress=dict(type='str'),
publicip=dict(type='str'),
metricexchange=dict(
type='str',
choices=[
'enabled',
'disabled',
]
),
nwmetricexchange=dict(
type='str',
choices=[
'enabled',
'disabled',
]
),
sessionexchange=dict(
type='str',
choices=[
'enabled',
'disabled',
]
),
triggermonitor=dict(
type='str',
choices=[
'ALWAYS',
'MEPDOWN',
'MEPDOWN_SVCDOWN',
]
),
parentsite=dict(type='str'),
clip=dict(type='str'),
publicclip=dict(type='str'),
naptrreplacementsuffix=dict(type='str'),
)
hand_inserted_arguments = dict(
)
argument_spec = dict()
argument_spec.update(netscaler_common_arguments)
argument_spec.update(module_specific_arguments)
argument_spec.update(hand_inserted_arguments)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
)
module_result = dict(
changed=False,
failed=False,
loglines=loglines,
)
# Fail the module if imports failed
if not PYTHON_SDK_IMPORTED:
module.fail_json(msg='Could not load nitro python sdk')
# Fallthrough to rest of execution
client = get_nitro_client(module)
try:
client.login()
except nitro_exception as e:
msg = "nitro exception during login. errorcode=%s, message=%s" % (str(e.errorcode), e.message)
module.fail_json(msg=msg)
except Exception as e:
if str(type(e)) == "<class 'requests.exceptions.ConnectionError'>":
module.fail_json(msg='Connection error %s' % str(e))
elif str(type(e)) == "<class 'requests.exceptions.SSLError'>":
module.fail_json(msg='SSL Error %s' % str(e))
else:
module.fail_json(msg='Unexpected error during login %s' % str(e))
readwrite_attrs = [
'sitename',
'sitetype',
'siteipaddress',
'publicip',
'metricexchange',
'nwmetricexchange',
'sessionexchange',
'triggermonitor',
'parentsite',
'clip',
'publicclip',
'naptrreplacementsuffix',
]
readonly_attrs = [
'status',
'persistencemepstatus',
'version',
'__count',
]
immutable_attrs = [
'sitename',
'sitetype',
'siteipaddress',
'publicip',
'parentsite',
'clip',
'publicclip',
]
transforms = {
'metricexchange': [lambda v: v.upper()],
'nwmetricexchange': [lambda v: v.upper()],
'sessionexchange': [lambda v: v.upper()],
}
# Instantiate config proxy
gslb_site_proxy = ConfigProxy(
actual=gslbsite(),
client=client,
attribute_values_dict=module.params,
readwrite_attrs=readwrite_attrs,
readonly_attrs=readonly_attrs,
immutable_attrs=immutable_attrs,
transforms=transforms,
)
try:
ensure_feature_is_enabled(client, 'GSLB')
# Apply appropriate state
if module.params['state'] == 'present':
log('Applying actions for state present')
if not gslb_site_exists(client, module):
if not module.check_mode:
gslb_site_proxy.add()
if module.params['save_config']:
client.save_config()
module_result['changed'] = True
elif not gslb_site_identical(client, module, gslb_site_proxy):
# Check if we try to change value of immutable attributes
immutables_changed = get_immutables_intersection(gslb_site_proxy, diff_list(client, module, gslb_site_proxy).keys())
if immutables_changed != []:
module.fail_json(
msg='Cannot update immutable attributes %s' % (immutables_changed,),
diff=diff_list(client, module, gslb_site_proxy),
**module_result
)
if not module.check_mode:
gslb_site_proxy.update()
if module.params['save_config']:
client.save_config()
module_result['changed'] = True
else:
module_result['changed'] = False
# Sanity check for state
if not module.check_mode:
log('Sanity checks for state present')
if not gslb_site_exists(client, module):
module.fail_json(msg='GSLB site does not exist', **module_result)
if not gslb_site_identical(client, module, gslb_site_proxy):
module.fail_json(msg='GSLB site differs from configured', diff=diff_list(client, module, gslb_site_proxy), **module_result)
elif module.params['state'] == 'absent':
log('Applying actions for state absent')
if gslb_site_exists(client, module):
if not module.check_mode:
gslb_site_proxy.delete()
if module.params['save_config']:
client.save_config()
module_result['changed'] = True
else:
module_result['changed'] = False
# Sanity check for state
if not module.check_mode:
log('Sanity checks for state absent')
if gslb_site_exists(client, module):
module.fail_json(msg='GSLB site still exists', **module_result)
except nitro_exception as e:
msg = "nitro exception errorcode=%s, message=%s" % (str(e.errorcode), e.message)
module.fail_json(msg=msg, **module_result)
client.logout()
module.exit_json(**module_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,
221,
1898,
334,
67,
9,
9708,
445,
390,
1904,
15285,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
26067,
63,
29027,
63,
2124,
199,
3612,
63,
1802,
26,
14944,
8763,
6374,
4770,
9045,
315,
5365,
11494,
14,
199,
1802,
26,
272,
446,
14944,
8763,
6374,
4770,
9045,
315,
5365,
11494,
14,
199,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
14,
16,
2,
199,
199,
2502,
26,
5346,
24591,
653,
16625,
320,
555,
85,
11560,
8593,
6153,
1308,
736,
13,
78,
16625,
320,
555,
85,
11560,
9,
199,
199,
1419,
26,
339,
4770,
354,
26,
267,
1369,
26,
288,
446,
690,
13,
355,
2812,
367,
314,
598,
4929,
34,
4770,
14,
9498,
5386,
543,
376,
10485,
27964,
503,
18888,
445,
1547,
9,
4528,
12,
436,
1471,
355,
1395,
1454,
10485,
27964,
12,
18888,
445,
1547,
395,
2631,
445,
27496,
395,
6247,
445,
13417,
395,
4601,
445,
8,
2318,
18307,
445,
8,
26,
395,
737,
445,
8,
32,
395,
18527,
355,
445,
8,
29,
395,
436,
7188,
17579,
445,
2801,
9,
4110,
14,
18435,
506,
2896,
2410,
314,
5791,
1654,
365,
2737,
14,
288,
446,
298,
12092,
2582,
275,
413,
2,
339,
4770,
466,
26,
267,
3415,
26,
288,
446,
283,
16058,
7,
288,
446,
283,
7486,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
2434,
402,
4770,
370,
1218,
14,
982,
314,
730,
365,
440,
2013,
12,
314,
20986,
5847,
477,
28853,
436,
5951,
355,
314,
730,
641,
314,
5597,
402,
314,
3531,
2287,
3769,
7943,
370,
314,
4770,
14,
982,
314,
2013,
4770,
3531,
2287,
355,
365,
23191,
701,
314,
20986,
334,
509,
2893,
12,
282,
603,
1772,
2287,
503,
428,
46,
1772,
2287,
395,
314,
4770,
365,
282,
2257,
4770,
14,
355,
6630,
12,
652,
365,
282,
3982,
4770,
14,
339,
4770,
21809,
26,
267,
1369,
26,
288,
446,
690,
13,
355,
3531,
2287,
367,
314,
598,
4929,
34,
4770,
14,
710,
598,
4929,
34,
4770,
4440,
642,
3531,
2287,
370,
26808,
543,
1163,
598,
4929,
34,
355,
15424,
14,
2104,
282,
2257,
4770,
12,
675,
1263,
3531,
2287,
626,
365,
23191,
701,
314,
20986,
334,
509,
2893,
12,
282,
428,
46,
1772,
503,
355,
603,
1772,
2287,
12,
503,
314,
3531,
2287,
402,
314,
437,
12323,
2435,
680,
288,
446,
298,
12092,
2582,
275,
413,
2,
339,
7974,
317,
6237,
26,
267,
1369,
26,
288,
446,
690,
13,
355,
1684,
3531,
2287,
367,
314,
2257,
4770,
14,
11105,
1454,
340,
314,
20986,
365,
26181,
315,
282,
5726,
2287,
355,
4601,
436,
314,
4770,
965,
282,
4575,
3531,
2287,
28311,
641,
376,
5957,
12042,
503,
282,
31363,
2243,
14,
288,
446,
298,
12092,
2582,
275,
413,
2,
339,
4417,
301,
88,
1461,
26,
267,
3415,
26,
288,
446,
283,
3827,
7,
288,
446,
283,
7011,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
25655,
7186,
543,
1163,
15424,
14,
10072,
11818,
787,
444,
2489,
701,
1808,
22465,
25655,
11557,
334,
3635,
48,
680,
710,
355,
20986,
83,
315,
314,
598,
4929,
34,
3272,
15343,
13822,
2556,
5403,
4036,
3499,
14,
288,
446,
690,
13,
355,
982,
1265,
3507,
7186,
15343,
12,
1265,
883,
675,
1454,
2955,
2248,
29300,
3102,
334,
10180,
465,
6168,
882,
1393,
12,
355,
2955,
10645,
1017,
1209,
12,
503,
314,
2631,
13,
6788,
3102,
395,
436,
340,
1265,
3507,
7186,
15343,
1380,
282,
8336,
2248,
355,
29300,
1083,
334,
10180,
465,
5210,
1950,
9,
365,
315,
3439,
12,
314,
20986,
26945,
1771,
370,
6168,
882,
1393,
14,
355,
6121,
12,
340,
1265,
3507,
7186,
15343,
12,
1265,
1471,
675,
282,
8372,
370,
6705,
314,
1174,
402,
598,
4929,
34,
355,
8500,
14,
6630,
12,
314,
2435,
365,
11584,
465,
10163,
14,
339,
22823,
3318,
301,
88,
1461,
26,
267,
3415,
26,
288,
446,
283,
3827,
7,
288,
446,
283,
7011,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
25655,
12,
543,
1163,
598,
4929,
34,
15424,
12,
2784,
7186,
4066,
465,
6168,
13,
7254,
900,
334,
50,
1481,
395,
12537,
379,
687,
355,
13882,
1298,
543,
7750,
2257,
10237,
334,
6533,
2709,
9,
8037,
1202,
701,
13431,
14,
820,
1481,
2556,
365,
1202,
315,
314,
355,
8336,
820,
1481,
2248,
29300,
1083,
12,
436,
365,
444,
2489,
4036,
959,
4696,
14,
339,
2217,
9353,
88,
1461,
26,
267,
3415,
26,
288,
446,
283,
3827,
7,
288,
446,
283,
7011,
7,
267,
1369,
26,
288,
446,
298,
13188,
16149,
2351,
4811,
543,
1163,
598,
4929,
34,
15424,
4036,
24187,
4696,
2122,
339,
6804,
7157,
26,
267,
3415,
26,
288,
446,
283,
32509,
7,
288,
446,
283,
3635,
48,
8819,
7,
288,
446,
283,
3635,
48,
8819,
63,
17675,
8819,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
13327,
314,
3704,
1334,
1314,
314,
598,
4929,
34,
2435,
1471,
506,
23821,
701,
282,
8372,
12,
340,
1373,
365,
3914,
14,
355,
23840,
2202,
805,
465,
11924,
26,
288,
446,
8969,
445,
8,
32509,
9,
446,
26504,
314,
598,
4929,
34,
2435,
737,
1006,
5431,
2122,
288,
446,
690,
13,
355,
627,
445,
8,
3635,
48,
8819,
9,
446,
26504,
314,
598,
4929,
34,
2435,
1454,
1380,
314,
15343,
402,
7186,
4012,
314,
10072,
11818,
25655,
355,
11557,
334,
3635,
48,
9,
365,
6980,
14,
288,
446,
298,
35,
8,
3635,
48,
8819,
63,
17675,
8819,
9,
446,
26504,
314,
2435,
315,
1902,
402,
314,
2569,
24325,
5424,
288,
446,
8969,
710,
15343,
402,
7186,
4012,
603,
6102,
365,
6980,
2122,
288,
446,
690,
13,
355,
627,
710,
15343,
402,
7186,
4012,
603,
6102,
365,
5223,
1325,
314,
2004
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
221,
1898,
334,
67,
9,
9708,
445,
390,
1904,
15285,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
26067,
63,
29027,
63,
2124,
199,
3612,
63,
1802,
26,
14944,
8763,
6374,
4770,
9045,
315,
5365,
11494,
14,
199,
1802,
26,
272,
446,
14944,
8763,
6374,
4770,
9045,
315,
5365,
11494,
14,
199,
199,
1023,
63,
3270,
26,
298,
18,
14,
20,
14,
16,
2,
199,
199,
2502,
26,
5346,
24591,
653,
16625,
320,
555,
85,
11560,
8593,
6153,
1308,
736,
13,
78,
16625,
320,
555,
85,
11560,
9,
199,
199,
1419,
26,
339,
4770,
354,
26,
267,
1369,
26,
288,
446,
690,
13,
355,
2812,
367,
314,
598,
4929,
34,
4770,
14,
9498,
5386,
543,
376,
10485,
27964,
503,
18888,
445,
1547,
9,
4528,
12,
436,
1471,
355,
1395,
1454,
10485,
27964,
12,
18888,
445,
1547,
395,
2631,
445,
27496,
395,
6247,
445,
13417,
395,
4601,
445,
8,
2318,
18307,
445,
8,
26,
395,
737,
445,
8,
32,
395,
18527,
355,
445,
8,
29,
395,
436,
7188,
17579,
445,
2801,
9,
4110,
14,
18435,
506,
2896,
2410,
314,
5791,
1654,
365,
2737,
14,
288,
446,
298,
12092,
2582,
275,
413,
2,
339,
4770,
466,
26,
267,
3415,
26,
288,
446,
283,
16058,
7,
288,
446,
283,
7486,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
2434,
402,
4770,
370,
1218,
14,
982,
314,
730,
365,
440,
2013,
12,
314,
20986,
5847,
477,
28853,
436,
5951,
355,
314,
730,
641,
314,
5597,
402,
314,
3531,
2287,
3769,
7943,
370,
314,
4770,
14,
982,
314,
2013,
4770,
3531,
2287,
355,
365,
23191,
701,
314,
20986,
334,
509,
2893,
12,
282,
603,
1772,
2287,
503,
428,
46,
1772,
2287,
395,
314,
4770,
365,
282,
2257,
4770,
14,
355,
6630,
12,
652,
365,
282,
3982,
4770,
14,
339,
4770,
21809,
26,
267,
1369,
26,
288,
446,
690,
13,
355,
3531,
2287,
367,
314,
598,
4929,
34,
4770,
14,
710,
598,
4929,
34,
4770,
4440,
642,
3531,
2287,
370,
26808,
543,
1163,
598,
4929,
34,
355,
15424,
14,
2104,
282,
2257,
4770,
12,
675,
1263,
3531,
2287,
626,
365,
23191,
701,
314,
20986,
334,
509,
2893,
12,
282,
428,
46,
1772,
503,
355,
603,
1772,
2287,
12,
503,
314,
3531,
2287,
402,
314,
437,
12323,
2435,
680,
288,
446,
298,
12092,
2582,
275,
413,
2,
339,
7974,
317,
6237,
26,
267,
1369,
26,
288,
446,
690,
13,
355,
1684,
3531,
2287,
367,
314,
2257,
4770,
14,
11105,
1454,
340,
314,
20986,
365,
26181,
315,
282,
5726,
2287,
355,
4601,
436,
314,
4770,
965,
282,
4575,
3531,
2287,
28311,
641,
376,
5957,
12042,
503,
282,
31363,
2243,
14,
288,
446,
298,
12092,
2582,
275,
413,
2,
339,
4417,
301,
88,
1461,
26,
267,
3415,
26,
288,
446,
283,
3827,
7,
288,
446,
283,
7011,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
25655,
7186,
543,
1163,
15424,
14,
10072,
11818,
787,
444,
2489,
701,
1808,
22465,
25655,
11557,
334,
3635,
48,
680,
710,
355,
20986,
83,
315,
314,
598,
4929,
34,
3272,
15343,
13822,
2556,
5403,
4036,
3499,
14,
288,
446,
690,
13,
355,
982,
1265,
3507,
7186,
15343,
12,
1265,
883,
675,
1454,
2955,
2248,
29300,
3102,
334,
10180,
465,
6168,
882,
1393,
12,
355,
2955,
10645,
1017,
1209,
12,
503,
314,
2631,
13,
6788,
3102,
395,
436,
340,
1265,
3507,
7186,
15343,
1380,
282,
8336,
2248,
355,
29300,
1083,
334,
10180,
465,
5210,
1950,
9,
365,
315,
3439,
12,
314,
20986,
26945,
1771,
370,
6168,
882,
1393,
14,
355,
6121,
12,
340,
1265,
3507,
7186,
15343,
12,
1265,
1471,
675,
282,
8372,
370,
6705,
314,
1174,
402,
598,
4929,
34,
355,
8500,
14,
6630,
12,
314,
2435,
365,
11584,
465,
10163,
14,
339,
22823,
3318,
301,
88,
1461,
26,
267,
3415,
26,
288,
446,
283,
3827,
7,
288,
446,
283,
7011,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
25655,
12,
543,
1163,
598,
4929,
34,
15424,
12,
2784,
7186,
4066,
465,
6168,
13,
7254,
900,
334,
50,
1481,
395,
12537,
379,
687,
355,
13882,
1298,
543,
7750,
2257,
10237,
334,
6533,
2709,
9,
8037,
1202,
701,
13431,
14,
820,
1481,
2556,
365,
1202,
315,
314,
355,
8336,
820,
1481,
2248,
29300,
1083,
12,
436,
365,
444,
2489,
4036,
959,
4696,
14,
339,
2217,
9353,
88,
1461,
26,
267,
3415,
26,
288,
446,
283,
3827,
7,
288,
446,
283,
7011,
7,
267,
1369,
26,
288,
446,
298,
13188,
16149,
2351,
4811,
543,
1163,
598,
4929,
34,
15424,
4036,
24187,
4696,
2122,
339,
6804,
7157,
26,
267,
3415,
26,
288,
446,
283,
32509,
7,
288,
446,
283,
3635,
48,
8819,
7,
288,
446,
283,
3635,
48,
8819,
63,
17675,
8819,
7,
267,
1369,
26,
288,
446,
690,
13,
355,
13327,
314,
3704,
1334,
1314,
314,
598,
4929,
34,
2435,
1471,
506,
23821,
701,
282,
8372,
12,
340,
1373,
365,
3914,
14,
355,
23840,
2202,
805,
465,
11924,
26,
288,
446,
8969,
445,
8,
32509,
9,
446,
26504,
314,
598,
4929,
34,
2435,
737,
1006,
5431,
2122,
288,
446,
690,
13,
355,
627,
445,
8,
3635,
48,
8819,
9,
446,
26504,
314,
598,
4929,
34,
2435,
1454,
1380,
314,
15343,
402,
7186,
4012,
314,
10072,
11818,
25655,
355,
11557,
334,
3635,
48,
9,
365,
6980,
14,
288,
446,
298,
35,
8,
3635,
48,
8819,
63,
17675,
8819,
9,
446,
26504,
314,
2435,
315,
1902,
402,
314,
2569,
24325,
5424,
288,
446,
8969,
710,
15343,
402,
7186,
4012,
603,
6102,
365,
6980,
2122,
288,
446,
690,
13,
355,
627,
710,
15343,
402,
7186,
4012,
603,
6102,
365,
5223,
1325,
314,
2004,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dgoodwin/origin
|
vendor/github.com/google/certificate-transparency/cpp/server/ct-dns-server-test.py
|
33
|
10792
|
import base64
import dns.resolver
import dns.rdatatype
import logging
import math
import os
import random
import shlex
import signal
import subprocess
import sys
import time
NUMBER_OF_CERTS = 100
basepath = os.path.dirname(sys.argv[0])
sys.path.append(os.path.join(basepath, '../../python'))
from ct.crypto import merkle
from ct.proto import ct_pb2
tmpdir = sys.argv[1]
class CTDNSLookup:
def __init__(self, nameservers, port):
self.resolver = dns.resolver.Resolver(configure=False)
self.resolver.nameservers = nameservers
self.resolver.port = port
def Get(self, name):
answers = self.resolver.query(name, 'TXT')
assert answers.rdtype == dns.rdatatype.TXT
return answers
def GetOne(self, name):
answers = self.Get(name)
assert len(answers) == 1
txt = answers[0]
assert len(txt.strings) == 1
return txt.strings[0]
def GetSTH(self):
sth_str = self.GetOne('sth.example.com')
sth = ct_pb2.SignedTreeHead()
parts = str(sth_str).split('.')
sth.tree_size = int(parts[0])
sth.timestamp = int(parts[1])
sth.sha256_root_hash = base64.b64decode(parts[2])
#FIXME(benl): decompose signature into its parts
#sth.signature = base64.b64decode(parts[3])
return sth
def GetEntry(self, level, index, size):
return self.GetOne(str(level) + '.' + str(index) + '.' + str(size)
+ '.tree.example.com')
def GetLeafHash(self, index):
return self.GetOne(str(index) + '.leafhash.example.com')
class DNSServerRunner:
def Run(self, cmd):
args = shlex.split(cmd)
self.proc = subprocess.Popen(args)
def OpenSSL(*params):
logging.info("RUN: openssl " + str(params))
null = open("/dev/null")
subprocess.check_call(("openssl",) + params, stdout=null, stderr=null)
class timeout:
def __init__(self, seconds, error_message='Timeout'):
self.seconds = seconds
self.error_message = error_message
def handle_timeout(self, signum, frame):
raise TimeoutError(self.error_message)
def __enter__(self):
signal.signal(signal.SIGALRM, self.handle_timeout)
signal.alarm(self.seconds)
def __exit__(self, type, value, traceback):
signal.alarm(0)
class CTServer:
def __init__(self, cmd, base, ca):
self.cmd_ = cmd
self.base_ = base
self.ca_ = ca
self.GenerateKey()
def __del__(self):
self.proc.terminate()
self.proc.wait()
def PrivateKey(self):
return self.base_ + "-ct-server-private-key.pem"
def PublicKey(self):
return self.base_ + "-ct-server-public-key.pem"
def Database(self):
return self.base_ + "-database.sqlite"
def GenerateKey(self):
OpenSSL("ecparam",
"-out", self.PrivateKey(),
"-name", "secp256r1",
"-genkey")
OpenSSL("ec",
"-in", self.PrivateKey(),
"-pubout",
"-out", self.PublicKey())
def URL(self):
return "http://localhost:9999/"
def Run(self):
cmd = (self.cmd_ + " -key " + self.PrivateKey() +
" -trusted_cert_file " + self.ca_.RootCertificate() +
" -sqlite_db " + self.Database() +
" -tree_signing_frequency_seconds 1" +
" -logtostderr")
logging.info("RUN: " + cmd)
args = shlex.split(cmd)
self.proc = subprocess.Popen(args, stdout=subprocess.PIPE)
with timeout(10):
while self.proc.stdout.readline() != "READY\n":
continue
RootConfig = """[ req ]
distinguished_name=req_distinguished_name
prompt=no
x509_extensions=v3_ca
[ req_distinguished_name ]
countryName=GB
stateOrProvinceName=Wales
localityName=Erw Wen
0.organizationName=Certificate Transparency Test CA
[ v3_ca ]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints=CA:TRUE
"""
CAConfig = """[ ca ]
default_ca = CA_default
[ CA_default ]
default_startdate = 120601000000Z
default_enddate = 220601000000Z
default_md = sha1
unique_subject = no
email_in_dn = no
policy = policy_default
serial = {serial}
database = {database}
[ policy_default ]
countryName = supplied
organizationName = supplied
stateOrProvinceName = optional
localityName = optional
commonName = optional
"""
RequestConfig = """[ req ]
distinguished_name=req_distinguished_name
prompt=no
[ req_distinguished_name ]
countryName=GB
stateOrProvinceName=Wales
localityName=Erw Wen
0.organizationName={subject}
# For the precert
[ pre ]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints=CA:FALSE
1.3.6.1.4.1.11129.2.4.3=critical,ASN1:NULL
# For the simple cert, without embedded proof extensions
[ simple ]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints=CA:FALSE
# For the cert with an embedded proof
[ embedded ]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer:always
basicConstraints=CA:FALSE
"""
def WriteFile(name, content):
with open(name, "w") as f:
f.write(content)
class CA:
def __init__(self, base):
self.base_ = base
os.mkdir(self.Directory())
open(self.Database(), "w")
WriteFile(self.Serial(), "0000000000000001")
WriteFile(self.RootConfig(), RootConfig)
ca_config = CAConfig.format(database = self.Database(),
serial = self.Serial())
WriteFile(self.CAConfig(), ca_config)
self.GenerateRootCertificate()
os.mkdir(self.IssuedCertificates())
def Directory(self):
"""Where the CA does house-keeping"""
return self.base_ + "-housekeeping"
def Database(self):
return self.Directory() + "/database"
def Serial(self):
return self.Directory() + "/serial"
def RootConfig(self):
return self.base_ + "-root-config"
def CAConfig(self):
return self.base_ + "-ca-config"
def PrivateKey(self):
return self.base_ + "-private-key.pem"
def RootCertificate(self):
return self.base_ + "-cert.pem"
def TempFile(self, name):
return self.base_ + "-temp-" + name
def RequestConfig(self):
return self.TempFile("req-config")
def IssuedCertificates(self):
return self.base_ + "-issued"
def IssuedFile(self, name, subject):
return self.IssuedCertificates() + "/" + name + "-" + subject + ".pem"
def IssuedPrivateKey(self, subject):
return self.IssuedFile("private-key", subject)
def IssuedCertificate(self, subject):
return self.IssuedFile("certificate", subject)
def GenerateRootCertificate(self):
csr = self.TempFile("csr")
OpenSSL("req",
"-new",
"-newkey", "rsa:2048",
"-keyout", self.PrivateKey(),
"-out", csr,
"-config", self.RootConfig(),
"-nodes")
OpenSSL("ca",
"-in", csr,
"-selfsign",
"-keyfile", self.PrivateKey(),
"-config", self.CAConfig(),
"-extfile", self.RootConfig(),
"-extensions", "v3_ca",
"-outdir", self.Directory(),
"-out", self.RootCertificate(),
"-batch")
def CreateAndLogCert(self, ct_server, subject):
WriteFile(self.RequestConfig(), RequestConfig.format(subject=subject))
csr = self.TempFile("csr")
OpenSSL("req",
"-new",
"-newkey", "rsa:1024",
"-keyout", self.IssuedPrivateKey(subject),
"-out", csr,
"-config", self.RequestConfig(),
"-nodes")
OpenSSL("ca",
"-in", csr,
"-cert", self.RootCertificate(),
"-keyfile", self.PrivateKey(),
"-config", self.CAConfig(),
"-extfile", self.RequestConfig(),
"-extensions", "simple",
"-outdir", self.Directory(),
"-out", self.IssuedCertificate(subject),
"-batch")
# Reverse the order of these to show a bug in ct-server where
# it accepts the CA cert even though there's a redundant extra
# cert in the chain. At least, I think its a bug.
certs = (open(self.IssuedCertificate(subject)).read()
+ open(self.RootCertificate()).read())
chain_file = self.TempFile("chain")
WriteFile(chain_file, certs)
subprocess.check_call(("client/ct", "upload",
"-ct_server_submission", chain_file,
"-ct_server", ct_server.URL(),
"-ct_server_public_key", ct_server.PublicKey(),
"-ct_server_response_out", self.TempFile("sct")))
logging.basicConfig(level="WARNING")
# Set up our test CA
ca = CA(tmpdir + "/ct-test-ca")
# Run a CT server
ct_cmd = basepath + "/ct-server"
ct_server = CTServer(ct_cmd, tmpdir + "/ct-test", ca)
ct_server.Run()
# Add nn certs to the CT server
for x in range(NUMBER_OF_CERTS):
ca.CreateAndLogCert(ct_server, "TestCertificate" + str(x))
# Make sure server has had enough time to assimilate all certs
time.sleep(2)
# We'll need the DB for the DNS server
db = ct_server.Database()
# Kill the CT server (shared database access not currently supported)
del ct_server
# Now run the DNS server from the same database
server_cmd = basepath + "/ct-dns-server --port=1111 --domain=example.com. --db=" + db
runner = DNSServerRunner()
runner.Run(server_cmd)
# Get the STH
lookup = CTDNSLookup(['127.0.0.1'], 1111)
sth = lookup.GetSTH()
logging.info("sth = " + str(sth))
logging.info("size = " + str(sth.tree_size))
assert sth.tree_size == NUMBER_OF_CERTS
# test all the entries
for index in range(NUMBER_OF_CERTS):
leaf_hash = lookup.GetLeafHash(index)
logging.info("index = " + str(index) + " hash = " + leaf_hash)
verifier = merkle.MerkleVerifier()
audit_path = []
for level in range(0, verifier.audit_path_length(index, sth.tree_size)):
hash = lookup.GetEntry(level, index, sth.tree_size)
logging.info("hash = " + hash)
audit_path.append(base64.b64decode(hash))
logging.info("path = " + str(map(base64.b64encode, audit_path)))
assert verifier.verify_leaf_hash_inclusion(base64.b64decode(leaf_hash),
index, audit_path, sth)
print "DNS Server test passed"
|
apache-2.0
|
[
646,
1300,
772,
199,
646,
6715,
14,
7717,
199,
646,
6715,
14,
82,
14184,
199,
646,
2050,
199,
646,
3473,
199,
646,
747,
199,
646,
2196,
199,
646,
16701,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
646,
900,
199,
199,
9190,
63,
3359,
63,
11163,
51,
275,
2948,
199,
199,
1095,
515,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
1095,
515,
12,
283,
9707,
1548,
1333,
199,
504,
9428,
14,
10316,
492,
4004,
23572,
199,
504,
9428,
14,
2625,
492,
9428,
63,
3317,
18,
199,
199,
8616,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
533,
24990,
12323,
7521,
26,
272,
347,
636,
826,
721,
277,
12,
536,
5871,
12,
1844,
304,
267,
291,
14,
7717,
275,
6715,
14,
7717,
14,
12407,
8,
6472,
29,
797,
9,
267,
291,
14,
7717,
14,
28620,
275,
536,
5871,
267,
291,
14,
7717,
14,
719,
275,
1844,
339,
347,
2372,
8,
277,
12,
536,
304,
267,
17133,
275,
291,
14,
7717,
14,
1131,
8,
354,
12,
283,
17715,
358,
267,
702,
17133,
14,
82,
2271,
508,
6715,
14,
82,
14184,
14,
17715,
267,
372,
17133,
339,
347,
2372,
4395,
8,
277,
12,
536,
304,
267,
17133,
275,
291,
14,
1002,
8,
354,
9,
267,
702,
822,
8,
13379,
9,
508,
413,
267,
9444,
275,
17133,
59,
16,
61,
267,
702,
822,
8,
2424,
14,
5465,
9,
508,
413,
267,
372,
9444,
14,
5465,
59,
16,
61,
339,
347,
2372,
840,
40,
8,
277,
304,
267,
410,
72,
63,
495,
275,
291,
14,
1002,
4395,
360,
17082,
14,
2694,
14,
957,
358,
267,
410,
72,
275,
9428,
63,
3317,
18,
14,
23013,
3987,
11664,
342,
267,
4184,
275,
620,
8,
17082,
63,
495,
680,
1294,
7563,
267,
410,
72,
14,
2350,
63,
890,
275,
1109,
8,
4181,
59,
16,
566,
267,
410,
72,
14,
3954,
275,
1109,
8,
4181,
59,
17,
566,
267,
410,
72,
14,
4835,
3912,
63,
1231,
63,
2227,
275,
1300,
772,
14,
66,
772,
2708,
8,
4181,
59,
18,
566,
267,
327,
31779,
8,
18486,
76,
304,
477,
12607,
4955,
1901,
2399,
4184,
267,
327,
17082,
14,
5233,
275,
1300,
772,
14,
66,
772,
2708,
8,
4181,
59,
19,
566,
267,
372,
410,
72,
339,
347,
2372,
3900,
8,
277,
12,
2166,
12,
1478,
12,
1568,
304,
267,
372,
291,
14,
1002,
4395,
8,
495,
8,
1896,
9,
435,
7815,
435,
620,
8,
1080,
9,
435,
7815,
435,
620,
8,
890,
9,
2574,
435,
1987,
2350,
14,
2694,
14,
957,
358,
339,
347,
2372,
20475,
3476,
8,
277,
12,
1478,
304,
267,
372,
291,
14,
1002,
4395,
8,
495,
8,
1080,
9,
435,
1987,
8914,
2227,
14,
2694,
14,
957,
358,
199,
199,
533,
10237,
3120,
7446,
26,
272,
347,
3378,
8,
277,
12,
2088,
304,
267,
1249,
275,
16701,
14,
1294,
8,
1760,
9,
267,
291,
14,
4687,
275,
3873,
14,
7942,
8,
589,
9,
199,
199,
318,
14296,
2031,
1162,
304,
272,
2050,
14,
815,
480,
9390,
26,
1551,
4266,
298,
435,
620,
8,
1162,
430,
272,
2973,
275,
1551,
4769,
2374,
15,
2307,
531,
272,
3873,
14,
1074,
63,
1250,
9313,
14837,
26360,
435,
1862,
12,
3839,
29,
2307,
12,
4635,
29,
2307,
9,
199,
199,
533,
2653,
26,
272,
347,
636,
826,
721,
277,
12,
4696,
12,
1125,
63,
1188,
534,
6372,
735,
267,
291,
14,
4515,
275,
4696,
267,
291,
14,
705,
63,
1188,
275,
1125,
63,
1188,
339,
347,
2429,
63,
2593,
8,
277,
12,
2070,
453,
12,
2787,
304,
267,
746,
31886,
8,
277,
14,
705,
63,
1188,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
4673,
14,
4653,
8,
4653,
14,
7864,
748,
11026,
12,
291,
14,
2479,
63,
2593,
9,
267,
4673,
14,
14160,
8,
277,
14,
4515,
9,
339,
347,
636,
2224,
721,
277,
12,
730,
12,
574,
12,
5190,
304,
267,
4673,
14,
14160,
8,
16,
9,
199,
199,
533,
24990,
3120,
26,
272,
347,
636,
826,
721,
277,
12,
2088,
12,
1300,
12,
1704,
304,
267,
291,
14,
1760,
63,
275,
2088,
267,
291,
14,
1095,
63,
275,
1300,
267,
291,
14,
696,
63,
275,
1704,
267,
291,
14,
6864,
1197,
342,
339,
347,
636,
2264,
721,
277,
304,
267,
291,
14,
4687,
14,
14478,
342,
267,
291,
14,
4687,
14,
2573,
342,
339,
347,
18551,
1197,
8,
277,
304,
267,
372,
291,
14,
1095,
63,
435,
3905,
319,
13,
1000,
13,
4239,
13,
498,
14,
13102,
2,
5493,
347,
1684,
1197,
8,
277,
304,
267,
372,
291,
14,
1095,
63,
435,
3905,
319,
13,
1000,
13,
3455,
13,
498,
14,
13102,
2,
339,
347,
8692,
8,
277,
304,
267,
372,
291,
14,
1095,
63,
435,
3905,
4659,
14,
10659,
2,
339,
347,
7958,
1197,
8,
277,
304,
267,
14296,
480,
825,
635,
401,
355,
3905,
548,
401,
291,
14,
31757,
1062,
355,
3905,
354,
401,
298,
261,
1850,
3912,
82,
17,
401,
355,
3905,
2268,
498,
531,
267,
14296,
480,
825,
401,
355,
3905,
262,
401,
291,
14,
31757,
1062,
355,
3905,
5645,
548,
401,
355,
3905,
548,
401,
291,
14,
26238,
1012,
339,
347,
2851,
8,
277,
304,
267,
372,
298,
1014,
921,
5967,
26,
5008,
6687,
339,
347,
3378,
8,
277,
304,
267,
2088,
275,
334,
277,
14,
1760,
63,
435,
298,
446,
498,
298,
435,
291,
14,
31757,
342,
435,
2049,
298,
446,
17549,
63,
4736,
63,
493,
298,
435,
291,
14,
696,
3754,
6405,
11414,
342,
435,
2049,
298,
446,
10659,
63,
697,
298,
435,
291,
14,
7243,
342,
435,
2049,
298,
446,
2350,
63,
23238,
63,
11132,
63,
4515,
413,
2,
435,
2049,
298,
446,
793,
475,
3083,
531,
267,
2050,
14,
815,
480,
9390,
26,
298,
435,
2088,
9,
267,
1249,
275,
16701,
14,
1294,
8,
1760,
9,
267,
291,
14,
4687,
275,
3873,
14,
7942,
8,
589,
12,
3839,
29,
5781,
14,
6089,
9,
267,
543,
2653,
8,
709,
304,
288,
1830,
291,
14,
4687,
14,
2703,
14,
6407,
342,
1137,
298,
22579,
60,
78,
582,
355,
1980,
199,
199,
6405,
2028,
275,
408,
59,
2648,
1622,
199,
2686
] |
[
1300,
772,
199,
646,
6715,
14,
7717,
199,
646,
6715,
14,
82,
14184,
199,
646,
2050,
199,
646,
3473,
199,
646,
747,
199,
646,
2196,
199,
646,
16701,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
646,
900,
199,
199,
9190,
63,
3359,
63,
11163,
51,
275,
2948,
199,
199,
1095,
515,
275,
747,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
566,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
1095,
515,
12,
283,
9707,
1548,
1333,
199,
504,
9428,
14,
10316,
492,
4004,
23572,
199,
504,
9428,
14,
2625,
492,
9428,
63,
3317,
18,
199,
199,
8616,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
533,
24990,
12323,
7521,
26,
272,
347,
636,
826,
721,
277,
12,
536,
5871,
12,
1844,
304,
267,
291,
14,
7717,
275,
6715,
14,
7717,
14,
12407,
8,
6472,
29,
797,
9,
267,
291,
14,
7717,
14,
28620,
275,
536,
5871,
267,
291,
14,
7717,
14,
719,
275,
1844,
339,
347,
2372,
8,
277,
12,
536,
304,
267,
17133,
275,
291,
14,
7717,
14,
1131,
8,
354,
12,
283,
17715,
358,
267,
702,
17133,
14,
82,
2271,
508,
6715,
14,
82,
14184,
14,
17715,
267,
372,
17133,
339,
347,
2372,
4395,
8,
277,
12,
536,
304,
267,
17133,
275,
291,
14,
1002,
8,
354,
9,
267,
702,
822,
8,
13379,
9,
508,
413,
267,
9444,
275,
17133,
59,
16,
61,
267,
702,
822,
8,
2424,
14,
5465,
9,
508,
413,
267,
372,
9444,
14,
5465,
59,
16,
61,
339,
347,
2372,
840,
40,
8,
277,
304,
267,
410,
72,
63,
495,
275,
291,
14,
1002,
4395,
360,
17082,
14,
2694,
14,
957,
358,
267,
410,
72,
275,
9428,
63,
3317,
18,
14,
23013,
3987,
11664,
342,
267,
4184,
275,
620,
8,
17082,
63,
495,
680,
1294,
7563,
267,
410,
72,
14,
2350,
63,
890,
275,
1109,
8,
4181,
59,
16,
566,
267,
410,
72,
14,
3954,
275,
1109,
8,
4181,
59,
17,
566,
267,
410,
72,
14,
4835,
3912,
63,
1231,
63,
2227,
275,
1300,
772,
14,
66,
772,
2708,
8,
4181,
59,
18,
566,
267,
327,
31779,
8,
18486,
76,
304,
477,
12607,
4955,
1901,
2399,
4184,
267,
327,
17082,
14,
5233,
275,
1300,
772,
14,
66,
772,
2708,
8,
4181,
59,
19,
566,
267,
372,
410,
72,
339,
347,
2372,
3900,
8,
277,
12,
2166,
12,
1478,
12,
1568,
304,
267,
372,
291,
14,
1002,
4395,
8,
495,
8,
1896,
9,
435,
7815,
435,
620,
8,
1080,
9,
435,
7815,
435,
620,
8,
890,
9,
2574,
435,
1987,
2350,
14,
2694,
14,
957,
358,
339,
347,
2372,
20475,
3476,
8,
277,
12,
1478,
304,
267,
372,
291,
14,
1002,
4395,
8,
495,
8,
1080,
9,
435,
1987,
8914,
2227,
14,
2694,
14,
957,
358,
199,
199,
533,
10237,
3120,
7446,
26,
272,
347,
3378,
8,
277,
12,
2088,
304,
267,
1249,
275,
16701,
14,
1294,
8,
1760,
9,
267,
291,
14,
4687,
275,
3873,
14,
7942,
8,
589,
9,
199,
199,
318,
14296,
2031,
1162,
304,
272,
2050,
14,
815,
480,
9390,
26,
1551,
4266,
298,
435,
620,
8,
1162,
430,
272,
2973,
275,
1551,
4769,
2374,
15,
2307,
531,
272,
3873,
14,
1074,
63,
1250,
9313,
14837,
26360,
435,
1862,
12,
3839,
29,
2307,
12,
4635,
29,
2307,
9,
199,
199,
533,
2653,
26,
272,
347,
636,
826,
721,
277,
12,
4696,
12,
1125,
63,
1188,
534,
6372,
735,
267,
291,
14,
4515,
275,
4696,
267,
291,
14,
705,
63,
1188,
275,
1125,
63,
1188,
339,
347,
2429,
63,
2593,
8,
277,
12,
2070,
453,
12,
2787,
304,
267,
746,
31886,
8,
277,
14,
705,
63,
1188,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
4673,
14,
4653,
8,
4653,
14,
7864,
748,
11026,
12,
291,
14,
2479,
63,
2593,
9,
267,
4673,
14,
14160,
8,
277,
14,
4515,
9,
339,
347,
636,
2224,
721,
277,
12,
730,
12,
574,
12,
5190,
304,
267,
4673,
14,
14160,
8,
16,
9,
199,
199,
533,
24990,
3120,
26,
272,
347,
636,
826,
721,
277,
12,
2088,
12,
1300,
12,
1704,
304,
267,
291,
14,
1760,
63,
275,
2088,
267,
291,
14,
1095,
63,
275,
1300,
267,
291,
14,
696,
63,
275,
1704,
267,
291,
14,
6864,
1197,
342,
339,
347,
636,
2264,
721,
277,
304,
267,
291,
14,
4687,
14,
14478,
342,
267,
291,
14,
4687,
14,
2573,
342,
339,
347,
18551,
1197,
8,
277,
304,
267,
372,
291,
14,
1095,
63,
435,
3905,
319,
13,
1000,
13,
4239,
13,
498,
14,
13102,
2,
5493,
347,
1684,
1197,
8,
277,
304,
267,
372,
291,
14,
1095,
63,
435,
3905,
319,
13,
1000,
13,
3455,
13,
498,
14,
13102,
2,
339,
347,
8692,
8,
277,
304,
267,
372,
291,
14,
1095,
63,
435,
3905,
4659,
14,
10659,
2,
339,
347,
7958,
1197,
8,
277,
304,
267,
14296,
480,
825,
635,
401,
355,
3905,
548,
401,
291,
14,
31757,
1062,
355,
3905,
354,
401,
298,
261,
1850,
3912,
82,
17,
401,
355,
3905,
2268,
498,
531,
267,
14296,
480,
825,
401,
355,
3905,
262,
401,
291,
14,
31757,
1062,
355,
3905,
5645,
548,
401,
355,
3905,
548,
401,
291,
14,
26238,
1012,
339,
347,
2851,
8,
277,
304,
267,
372,
298,
1014,
921,
5967,
26,
5008,
6687,
339,
347,
3378,
8,
277,
304,
267,
2088,
275,
334,
277,
14,
1760,
63,
435,
298,
446,
498,
298,
435,
291,
14,
31757,
342,
435,
2049,
298,
446,
17549,
63,
4736,
63,
493,
298,
435,
291,
14,
696,
3754,
6405,
11414,
342,
435,
2049,
298,
446,
10659,
63,
697,
298,
435,
291,
14,
7243,
342,
435,
2049,
298,
446,
2350,
63,
23238,
63,
11132,
63,
4515,
413,
2,
435,
2049,
298,
446,
793,
475,
3083,
531,
267,
2050,
14,
815,
480,
9390,
26,
298,
435,
2088,
9,
267,
1249,
275,
16701,
14,
1294,
8,
1760,
9,
267,
291,
14,
4687,
275,
3873,
14,
7942,
8,
589,
12,
3839,
29,
5781,
14,
6089,
9,
267,
543,
2653,
8,
709,
304,
288,
1830,
291,
14,
4687,
14,
2703,
14,
6407,
342,
1137,
298,
22579,
60,
78,
582,
355,
1980,
199,
199,
6405,
2028,
275,
408,
59,
2648,
1622,
199,
2686,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rbruyere/appengine-mapreduce
|
python/test/mapreduce gcs/pipeline/status_ui.py
|
6
|
6317
|
#!/usr/bin/env python
#
# Copyright 2010 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.
"""Status UI for Google App Engine Pipeline API."""
import logging
import os
import pkgutil
import traceback
from google.appengine.api import users
from google.appengine.ext import webapp
# Relative imports
from mapreduce.third_party import simplejson
import util
class _StatusUiHandler(webapp.RequestHandler):
"""Render the status UI."""
_RESOURCE_MAP = {
'/status': ('ui/status.html', 'text/html'),
'/status.css': ('ui/status.css', 'text/css'),
'/status.js': ('ui/status.js', 'text/javascript'),
'/list': ('ui/root_list.html', 'text/html'),
'/list.css': ('ui/root_list.css', 'text/css'),
'/list.js': ('ui/root_list.js', 'text/javascript'),
'/common.js': ('ui/common.js', 'text/javascript'),
'/common.css': ('ui/common.css', 'text/css'),
'/jquery-1.4.2.min.js': ('ui/jquery-1.4.2.min.js', 'text/javascript'),
'/jquery.treeview.min.js': ('ui/jquery.treeview.min.js', 'text/javascript'),
'/jquery.cookie.js': ('ui/jquery.cookie.js', 'text/javascript'),
'/jquery.timeago.js': ('ui/jquery.timeago.js', 'text/javascript'),
'/jquery.ba-hashchange.min.js': (
'ui/jquery.ba-hashchange.min.js', 'text/javascript'),
'/jquery.json.min.js': ('ui/jquery.json.min.js', 'text/javascript'),
'/jquery.treeview.css': ('ui/jquery.treeview.css', 'text/css'),
'/treeview-default.gif': ('ui/images/treeview-default.gif', 'image/gif'),
'/treeview-default-line.gif': (
'ui/images/treeview-default-line.gif', 'image/gif'),
'/treeview-black.gif': ('ui/images/treeview-black.gif', 'image/gif'),
'/treeview-black-line.gif': (
'ui/images/treeview-black-line.gif', 'image/gif'),
'/images/treeview-default.gif': (
'ui/images/treeview-default.gif', 'image/gif'),
'/images/treeview-default-line.gif': (
'ui/images/treeview-default-line.gif', 'image/gif'),
'/images/treeview-black.gif': (
'ui/images/treeview-black.gif', 'image/gif'),
'/images/treeview-black-line.gif': (
'ui/images/treeview-black-line.gif', 'image/gif'),
}
def get(self, resource=''):
import pipeline # Break circular dependency
if pipeline._ENFORCE_AUTH:
if users.get_current_user() is None:
logging.debug('User is not logged in')
self.redirect(users.create_login_url(self.request.url))
return
if not users.is_current_user_admin():
logging.debug('User is not admin: %r', users.get_current_user())
self.response.out.write('Forbidden')
self.response.set_status(403)
return
if resource not in self._RESOURCE_MAP:
logging.debug('Could not find: %s', resource)
self.response.set_status(404)
self.response.out.write("Resource not found.")
self.response.headers['Content-Type'] = 'text/plain'
return
relative_path, content_type = self._RESOURCE_MAP[resource]
path = os.path.join(os.path.dirname(__file__), relative_path)
if not pipeline._DEBUG:
self.response.headers["Cache-Control"] = "public, max-age=300"
self.response.headers["Content-Type"] = content_type
try:
data = pkgutil.get_data(__name__, relative_path)
except AttributeError: # Python < 2.6.
data = None
self.response.out.write(data or open(path, 'rb').read())
class _BaseRpcHandler(webapp.RequestHandler):
"""Base handler for JSON-RPC responses.
Sub-classes should fill in the 'json_response' property. All exceptions will
be rturne
"""
def get(self):
import pipeline # Break circular dependency
if pipeline._ENFORCE_AUTH:
if not users.is_current_user_admin():
logging.debug('User is not admin: %r', users.get_current_user())
self.response.out.write('Forbidden')
self.response.set_status(403)
return
# XSRF protection
if (not pipeline._DEBUG and
self.request.headers.get('X-Requested-With') != 'XMLHttpRequest'):
logging.debug('Request missing X-Requested-With header')
self.response.out.write('Request missing X-Requested-With header')
self.response.set_status(403)
return
self.json_response = {}
try:
self.handle()
output = simplejson.dumps(self.json_response, cls=util.JsonEncoder)
except Exception, e:
self.json_response.clear()
self.json_response['error_class'] = e.__class__.__name__
self.json_response['error_message'] = str(e)
self.json_response['error_traceback'] = traceback.format_exc()
output = simplejson.dumps(self.json_response, cls=util.JsonEncoder)
self.response.set_status(200)
self.response.headers['Content-Type'] = 'text/javascript'
self.response.headers['Cache-Control'] = 'no-cache'
self.response.out.write(output)
def handle(self):
raise NotImplementedError('To be implemented by sub-classes.')
class _TreeStatusHandler(_BaseRpcHandler):
"""RPC handler for getting the status of all children of root pipeline."""
def handle(self):
import pipeline # Break circular dependency
self.json_response.update(
pipeline.get_status_tree(self.request.get('root_pipeline_id')))
class _ClassPathListHandler(_BaseRpcHandler):
"""RPC handler for getting the list of all Pipeline classes defined."""
def handle(self):
import pipeline # Break circular dependency
self.json_response['classPaths'] = pipeline.get_pipeline_names()
class _RootListHandler(_BaseRpcHandler):
"""RPC handler for getting the status of all root pipelines."""
def handle(self):
import pipeline # Break circular dependency
self.json_response.update(
pipeline.get_root_list(
class_path=self.request.get('class_path'),
cursor=self.request.get('cursor')))
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7129,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
3694,
14041,
367,
4475,
4693,
12580,
19090,
3261,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
28728,
199,
646,
5190,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
4390,
199,
504,
6233,
14,
15358,
14,
832,
492,
24812,
199,
199,
3,
22419,
8925,
199,
504,
2341,
5270,
14,
11470,
63,
7522,
492,
13804,
199,
646,
4884,
421,
199,
533,
485,
3694,
18203,
2461,
8,
22632,
14,
11149,
304,
523,
408,
9216,
314,
2004,
14041,
1041,
819,
485,
14110,
63,
5443,
275,
469,
272,
1994,
1205,
356,
661,
1907,
15,
1205,
14,
1360,
297,
283,
505,
15,
1360,
659,
272,
1994,
1205,
14,
3919,
356,
661,
1907,
15,
1205,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
1205,
14,
3596,
356,
661,
1907,
15,
1205,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
513,
356,
661,
1907,
15,
1231,
63,
513,
14,
1360,
297,
283,
505,
15,
1360,
659,
272,
1994,
513,
14,
3919,
356,
661,
1907,
15,
1231,
63,
513,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
513,
14,
3596,
356,
661,
1907,
15,
1231,
63,
513,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
2330,
14,
3596,
356,
661,
1907,
15,
2330,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
2330,
14,
3919,
356,
661,
1907,
15,
2330,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
22324,
13,
17,
14,
20,
14,
18,
14,
827,
14,
3596,
356,
661,
1907,
15,
22324,
13,
17,
14,
20,
14,
18,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
32440,
14,
827,
14,
3596,
356,
661,
1907,
15,
22324,
14,
32440,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
5306,
14,
3596,
356,
661,
1907,
15,
22324,
14,
5306,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
521,
14315,
14,
3596,
356,
661,
1907,
15,
22324,
14,
521,
14315,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
2470,
13,
2227,
1461,
14,
827,
14,
3596,
356,
334,
267,
283,
1907,
15,
22324,
14,
2470,
13,
2227,
1461,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
1001,
14,
827,
14,
3596,
356,
661,
1907,
15,
22324,
14,
1001,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
32440,
14,
3919,
356,
661,
1907,
15,
22324,
14,
32440,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
32440,
13,
885,
14,
14513,
356,
661,
1907,
15,
4782,
15,
32440,
13,
885,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
32440,
13,
885,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
885,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
32440,
13,
8399,
14,
14513,
356,
661,
1907,
15,
4782,
15,
32440,
13,
8399,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
32440,
13,
8399,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
8399,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
885,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
885,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
885,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
885,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
8399,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
8399,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
8399,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
8399,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
523,
789,
819,
347,
664,
8,
277,
12,
2073,
9280,
272,
492,
7679,
221,
327,
22535,
15032,
5936,
272,
340,
7679,
423,
742,
27240,
63,
5580,
26,
489,
340,
4390,
14,
362,
63,
1818,
63,
751,
342,
365,
488,
26,
267,
2050,
14,
1757,
360,
1899,
365,
440,
10367,
315,
358,
267,
291,
14,
4876,
8,
3707,
14,
981,
63,
2886,
63,
633,
8,
277,
14,
1069,
14,
633,
430,
267,
372,
2541,
340,
440,
4390,
14,
374,
63,
1818,
63,
751,
63,
2113,
837,
267,
2050,
14,
1757,
360,
1899,
365,
440,
4628,
26,
450,
82,
297,
4390,
14,
362,
63,
1818,
63,
751,
1012,
267,
291,
14,
1310,
14,
548,
14,
952,
360,
17454,
358,
267,
291,
14,
1310,
14,
409,
63,
1205,
8,
13353,
9,
267,
372,
339,
340,
2073,
440,
315,
291,
423,
14110,
63,
5443,
26,
489,
2050,
14,
1757,
360,
6531,
440,
2342,
26,
450,
83,
297,
2073,
9,
489,
291,
14,
1310,
14,
409,
63,
1205,
8,
5188,
9,
489,
291,
14,
1310,
14,
548,
14,
952,
480,
4031,
440,
1911,
2685,
489,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
505,
15,
6104,
7,
489,
372,
339,
3847,
63,
515,
12,
1564,
63,
466,
275,
291,
423,
14110,
63,
5443,
59,
1927,
61,
272,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
7129,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
3694,
14041,
367,
4475,
4693,
12580,
19090,
3261,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
28728,
199,
646,
5190,
199,
199,
504,
6233,
14,
15358,
14,
1246,
492,
4390,
199,
504,
6233,
14,
15358,
14,
832,
492,
24812,
199,
199,
3,
22419,
8925,
199,
504,
2341,
5270,
14,
11470,
63,
7522,
492,
13804,
199,
646,
4884,
421,
199,
533,
485,
3694,
18203,
2461,
8,
22632,
14,
11149,
304,
523,
408,
9216,
314,
2004,
14041,
1041,
819,
485,
14110,
63,
5443,
275,
469,
272,
1994,
1205,
356,
661,
1907,
15,
1205,
14,
1360,
297,
283,
505,
15,
1360,
659,
272,
1994,
1205,
14,
3919,
356,
661,
1907,
15,
1205,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
1205,
14,
3596,
356,
661,
1907,
15,
1205,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
513,
356,
661,
1907,
15,
1231,
63,
513,
14,
1360,
297,
283,
505,
15,
1360,
659,
272,
1994,
513,
14,
3919,
356,
661,
1907,
15,
1231,
63,
513,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
513,
14,
3596,
356,
661,
1907,
15,
1231,
63,
513,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
2330,
14,
3596,
356,
661,
1907,
15,
2330,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
2330,
14,
3919,
356,
661,
1907,
15,
2330,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
22324,
13,
17,
14,
20,
14,
18,
14,
827,
14,
3596,
356,
661,
1907,
15,
22324,
13,
17,
14,
20,
14,
18,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
32440,
14,
827,
14,
3596,
356,
661,
1907,
15,
22324,
14,
32440,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
5306,
14,
3596,
356,
661,
1907,
15,
22324,
14,
5306,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
521,
14315,
14,
3596,
356,
661,
1907,
15,
22324,
14,
521,
14315,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
2470,
13,
2227,
1461,
14,
827,
14,
3596,
356,
334,
267,
283,
1907,
15,
22324,
14,
2470,
13,
2227,
1461,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
1001,
14,
827,
14,
3596,
356,
661,
1907,
15,
22324,
14,
1001,
14,
827,
14,
3596,
297,
283,
505,
15,
9554,
659,
272,
1994,
22324,
14,
32440,
14,
3919,
356,
661,
1907,
15,
22324,
14,
32440,
14,
3919,
297,
283,
505,
15,
3919,
659,
272,
1994,
32440,
13,
885,
14,
14513,
356,
661,
1907,
15,
4782,
15,
32440,
13,
885,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
32440,
13,
885,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
885,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
32440,
13,
8399,
14,
14513,
356,
661,
1907,
15,
4782,
15,
32440,
13,
8399,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
32440,
13,
8399,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
8399,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
885,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
885,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
885,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
885,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
8399,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
8399,
14,
14513,
297,
283,
1569,
15,
14513,
659,
272,
1994,
4782,
15,
32440,
13,
8399,
13,
604,
14,
14513,
356,
334,
267,
283,
1907,
15,
4782,
15,
32440,
13,
8399,
13,
604,
14,
14513,
297,
283,
1569,
15,
14513,
659,
523,
789,
819,
347,
664,
8,
277,
12,
2073,
9280,
272,
492,
7679,
221,
327,
22535,
15032,
5936,
272,
340,
7679,
423,
742,
27240,
63,
5580,
26,
489,
340,
4390,
14,
362,
63,
1818,
63,
751,
342,
365,
488,
26,
267,
2050,
14,
1757,
360,
1899,
365,
440,
10367,
315,
358,
267,
291,
14,
4876,
8,
3707,
14,
981,
63,
2886,
63,
633,
8,
277,
14,
1069,
14,
633,
430,
267,
372,
2541,
340,
440,
4390,
14,
374,
63,
1818,
63,
751,
63,
2113,
837,
267,
2050,
14,
1757,
360,
1899,
365,
440,
4628,
26,
450,
82,
297,
4390,
14,
362,
63,
1818,
63,
751,
1012,
267,
291,
14,
1310,
14,
548,
14,
952,
360,
17454,
358,
267,
291,
14,
1310,
14,
409,
63,
1205,
8,
13353,
9,
267,
372,
339,
340,
2073,
440,
315,
291,
423,
14110,
63,
5443,
26,
489,
2050,
14,
1757,
360,
6531,
440,
2342,
26,
450,
83,
297,
2073,
9,
489,
291,
14,
1310,
14,
409,
63,
1205,
8,
5188,
9,
489,
291,
14,
1310,
14,
548,
14,
952,
480,
4031,
440,
1911,
2685,
489,
291,
14,
1310,
14,
2139,
459,
2714,
13,
804,
418,
275,
283,
505,
15,
6104,
7,
489,
372,
339,
3847,
63,
515,
12,
1564,
63,
466,
275,
291,
423,
14110,
63,
5443,
59,
1927,
61,
272,
931,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
deplinenoise/rlaunch
|
vbcc-driver.py
|
1
|
1297
|
#! /usr/bin/python
import sys
import os
import os.path
import subprocess
import re
line_re = re.compile(r'^(warning|error) (\d+) in line (\d+) of "([^"]*)":\s*(.*)$')
def fix_fn(root_dir, fn):
# If there are path separators in the filename, assume the path is valid
if fn.find(os.sep) != -1:
return fn
if os.path.exists(fn):
return fn
full_path = os.path.join(root_dir, fn)
if os.path.exists(full_path):
return full_path
return 'bah'
def munge(root_dir, line):
m = re.match(line_re, line)
if not m:
return line.strip()
fn = fix_fn(root_dir, m.group(4))
return '%s(%s) : %s %s: %s' % (fn, m.group(3), m.group(1), m.group(2), m.group(5))
if __name__ == '__main__':
vbcc_root = os.environ.get('VBCC')
if not vbcc_root:
sys.stderr.write('VBCC environment variable not set')
sys.exit(1)
vc_bin = os.path.join(vbcc_root, 'bin' + os.sep + 'vc')
if os.name == 'nt':
vc_bin += '.exe'
root_dir = '.'
for arg in sys.argv[1:]:
if arg.endswith('.c'):
root_dir, dummy = os.path.split(arg)
vc = subprocess.Popen(
args = sys.argv[1:],
executable = vc_bin,
universal_newlines=True,
stdin = None,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT)
for line in vc.stdout:
sys.stdout.write(munge(root_dir, line))
sys.stdout.write('\n')
|
gpl-3.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1548,
199,
199,
646,
984,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
295,
199,
199,
604,
63,
264,
275,
295,
14,
2014,
8,
82,
31996,
3764,
92,
705,
9,
14749,
68,
8771,
315,
1004,
14749,
68,
8771,
402,
32397,
13278,
582,
60,
83,
5830,
12432,
9988,
199,
199,
318,
5325,
63,
2324,
8,
1231,
63,
694,
12,
4325,
304,
199,
198,
3,
982,
2337,
787,
931,
17658,
315,
314,
1788,
12,
5534,
314,
931,
365,
1686,
199,
198,
692,
4325,
14,
1623,
8,
736,
14,
4127,
9,
1137,
446,
17,
26,
507,
198,
1107,
4325,
8299,
198,
692,
747,
14,
515,
14,
2444,
8,
2324,
304,
507,
198,
1107,
4325,
421,
198,
2861,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
63,
694,
12,
4325,
9,
421,
198,
692,
747,
14,
515,
14,
2444,
8,
2861,
63,
515,
304,
507,
198,
1107,
2615,
63,
515,
421,
198,
1107,
283,
2470,
72,
7,
199,
199,
318,
333,
16993,
8,
1231,
63,
694,
12,
1004,
304,
199,
198,
77,
275,
295,
14,
1431,
8,
604,
63,
264,
12,
1004,
9,
199,
198,
692,
440,
333,
26,
507,
198,
1107,
1004,
14,
1913,
342,
421,
198,
2324,
275,
5325,
63,
2324,
8,
1231,
63,
694,
12,
333,
14,
923,
8,
20,
430,
199,
198,
1107,
1543,
83,
4042,
83,
9,
520,
450,
83,
450,
83,
26,
450,
83,
7,
450,
334,
2324,
12,
333,
14,
923,
8,
19,
395,
333,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
21,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
421,
198,
18708,
2055,
63,
1231,
275,
747,
14,
2314,
14,
362,
360,
27966,
2571,
358,
199,
198,
692,
440,
373,
21976,
63,
1231,
26,
507,
198,
1274,
14,
3083,
14,
952,
360,
27966,
2571,
3734,
1750,
440,
663,
358,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
6737,
63,
1393,
275,
747,
14,
515,
14,
904,
8,
18708,
2055,
63,
1231,
12,
283,
1393,
7,
435,
747,
14,
4127,
435,
283,
6737,
358,
421,
198,
692,
747,
14,
354,
508,
283,
343,
356,
507,
198,
6737,
63,
1393,
847,
1987,
5803,
7,
421,
198,
1231,
63,
694,
275,
7815,
421,
198,
509,
1680,
315,
984,
14,
3020,
59,
17,
10688,
507,
198,
692,
1680,
14,
4130,
5175,
67,
735,
686,
198,
1231,
63,
694,
12,
7283,
275,
747,
14,
515,
14,
1294,
8,
1273,
9,
421,
198,
6737,
275,
3873,
14,
7942,
8,
686,
198,
589,
275,
984,
14,
3020,
59,
17,
8429,
686,
198,
5904,
275,
16548,
63,
1393,
12,
686,
198,
24866,
63,
13839,
29,
549,
12,
686,
198,
6626,
275,
488,
12,
686,
198,
2703,
275,
3873,
14,
6089,
12,
686,
198,
3083,
275,
3873,
14,
13850,
9,
421,
198,
509,
1004,
315,
16548,
14,
2703,
26,
507,
198,
1274,
14,
2703,
14,
952,
8,
77,
16993,
8,
1231,
63,
694,
12,
1004,
430,
507,
198,
1274,
14,
2703,
14,
952,
2258,
78,
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
] |
[
1182,
2647,
15,
1393,
15,
1548,
199,
199,
646,
984,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
295,
199,
199,
604,
63,
264,
275,
295,
14,
2014,
8,
82,
31996,
3764,
92,
705,
9,
14749,
68,
8771,
315,
1004,
14749,
68,
8771,
402,
32397,
13278,
582,
60,
83,
5830,
12432,
9988,
199,
199,
318,
5325,
63,
2324,
8,
1231,
63,
694,
12,
4325,
304,
199,
198,
3,
982,
2337,
787,
931,
17658,
315,
314,
1788,
12,
5534,
314,
931,
365,
1686,
199,
198,
692,
4325,
14,
1623,
8,
736,
14,
4127,
9,
1137,
446,
17,
26,
507,
198,
1107,
4325,
8299,
198,
692,
747,
14,
515,
14,
2444,
8,
2324,
304,
507,
198,
1107,
4325,
421,
198,
2861,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1231,
63,
694,
12,
4325,
9,
421,
198,
692,
747,
14,
515,
14,
2444,
8,
2861,
63,
515,
304,
507,
198,
1107,
2615,
63,
515,
421,
198,
1107,
283,
2470,
72,
7,
199,
199,
318,
333,
16993,
8,
1231,
63,
694,
12,
1004,
304,
199,
198,
77,
275,
295,
14,
1431,
8,
604,
63,
264,
12,
1004,
9,
199,
198,
692,
440,
333,
26,
507,
198,
1107,
1004,
14,
1913,
342,
421,
198,
2324,
275,
5325,
63,
2324,
8,
1231,
63,
694,
12,
333,
14,
923,
8,
20,
430,
199,
198,
1107,
1543,
83,
4042,
83,
9,
520,
450,
83,
450,
83,
26,
450,
83,
7,
450,
334,
2324,
12,
333,
14,
923,
8,
19,
395,
333,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
395,
333,
14,
923,
8,
21,
430,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
421,
198,
18708,
2055,
63,
1231,
275,
747,
14,
2314,
14,
362,
360,
27966,
2571,
358,
199,
198,
692,
440,
373,
21976,
63,
1231,
26,
507,
198,
1274,
14,
3083,
14,
952,
360,
27966,
2571,
3734,
1750,
440,
663,
358,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
6737,
63,
1393,
275,
747,
14,
515,
14,
904,
8,
18708,
2055,
63,
1231,
12,
283,
1393,
7,
435,
747,
14,
4127,
435,
283,
6737,
358,
421,
198,
692,
747,
14,
354,
508,
283,
343,
356,
507,
198,
6737,
63,
1393,
847,
1987,
5803,
7,
421,
198,
1231,
63,
694,
275,
7815,
421,
198,
509,
1680,
315,
984,
14,
3020,
59,
17,
10688,
507,
198,
692,
1680,
14,
4130,
5175,
67,
735,
686,
198,
1231,
63,
694,
12,
7283,
275,
747,
14,
515,
14,
1294,
8,
1273,
9,
421,
198,
6737,
275,
3873,
14,
7942,
8,
686,
198,
589,
275,
984,
14,
3020,
59,
17,
8429,
686,
198,
5904,
275,
16548,
63,
1393,
12,
686,
198,
24866,
63,
13839,
29,
549,
12,
686,
198,
6626,
275,
488,
12,
686,
198,
2703,
275,
3873,
14,
6089,
12,
686,
198,
3083,
275,
3873,
14,
13850,
9,
421,
198,
509,
1004,
315,
16548,
14,
2703,
26,
507,
198,
1274,
14,
2703,
14,
952,
8,
77,
16993,
8,
1231,
63,
694,
12,
1004,
430,
507,
198,
1274,
14,
2703,
14,
952,
2258,
78,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fjxhkj/PTVS
|
Python/Tests/TestData/VirtualEnv/env/Lib/codecs.py
|
84
|
36364
|
""" codecs -- Python Codec Registry, API and helpers.
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""#"
import __builtin__, sys
### Registry and builtin stateless codec functions
try:
from _codecs import *
except ImportError, why:
raise SystemError('Failed to load the builtin codecs: %s' % why)
__all__ = ["register", "lookup", "open", "EncodedFile", "BOM", "BOM_BE",
"BOM_LE", "BOM32_BE", "BOM32_LE", "BOM64_BE", "BOM64_LE",
"BOM_UTF8", "BOM_UTF16", "BOM_UTF16_LE", "BOM_UTF16_BE",
"BOM_UTF32", "BOM_UTF32_LE", "BOM_UTF32_BE",
"strict_errors", "ignore_errors", "replace_errors",
"xmlcharrefreplace_errors",
"register_error", "lookup_error"]
### Constants
#
# Byte Order Mark (BOM = ZERO WIDTH NO-BREAK SPACE = U+FEFF)
# and its possible byte string values
# for UTF8/UTF16/UTF32 output and little/big endian machines
#
# UTF-8
BOM_UTF8 = '\xef\xbb\xbf'
# UTF-16, little endian
BOM_LE = BOM_UTF16_LE = '\xff\xfe'
# UTF-16, big endian
BOM_BE = BOM_UTF16_BE = '\xfe\xff'
# UTF-32, little endian
BOM_UTF32_LE = '\xff\xfe\x00\x00'
# UTF-32, big endian
BOM_UTF32_BE = '\x00\x00\xfe\xff'
if sys.byteorder == 'little':
# UTF-16, native endianness
BOM = BOM_UTF16 = BOM_UTF16_LE
# UTF-32, native endianness
BOM_UTF32 = BOM_UTF32_LE
else:
# UTF-16, native endianness
BOM = BOM_UTF16 = BOM_UTF16_BE
# UTF-32, native endianness
BOM_UTF32 = BOM_UTF32_BE
# Old broken names (don't use in new code)
BOM32_LE = BOM_UTF16_LE
BOM32_BE = BOM_UTF16_BE
BOM64_LE = BOM_UTF32_LE
BOM64_BE = BOM_UTF32_BE
### Codec base classes (defining the API)
class CodecInfo(tuple):
def __new__(cls, encode, decode, streamreader=None, streamwriter=None,
incrementalencoder=None, incrementaldecoder=None, name=None):
self = tuple.__new__(cls, (encode, decode, streamreader, streamwriter))
self.name = name
self.encode = encode
self.decode = decode
self.incrementalencoder = incrementalencoder
self.incrementaldecoder = incrementaldecoder
self.streamwriter = streamwriter
self.streamreader = streamreader
return self
def __repr__(self):
return "<%s.%s object for encoding %s at 0x%x>" % (self.__class__.__module__, self.__class__.__name__, self.name, id(self))
class Codec:
""" Defines the interface for stateless encoders/decoders.
The .encode()/.decode() methods may use different error
handling schemes by providing the errors argument. These
string values are predefined:
'strict' - raise a ValueError error (or a subclass)
'ignore' - ignore the character and continue with the next
'replace' - replace with a suitable replacement character;
Python will use the official U+FFFD REPLACEMENT
CHARACTER for the builtin Unicode codecs on
decoding and '?' on encoding.
'xmlcharrefreplace' - Replace with the appropriate XML
character reference (only for encoding).
'backslashreplace' - Replace with backslashed escape sequences
(only for encoding).
The set of allowed values can be extended via register_error.
"""
def encode(self, input, errors='strict'):
""" Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling.
The method may not store state in the Codec instance. Use
StreamCodec for codecs which have to keep state in order to
make encoding/decoding efficient.
The encoder must be able to handle zero length input and
return an empty object of the output object type in this
situation.
"""
raise NotImplementedError
def decode(self, input, errors='strict'):
""" Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error handling to apply. It defaults to
'strict' handling.
The method may not store state in the Codec instance. Use
StreamCodec for codecs which have to keep state in order to
make encoding/decoding efficient.
The decoder must be able to handle zero length input and
return an empty object of the output object type in this
situation.
"""
raise NotImplementedError
class IncrementalEncoder(object):
"""
An IncrementalEncoder encodes an input in multiple steps. The input can be
passed piece by piece to the encode() method. The IncrementalEncoder remembers
the state of the Encoding process between calls to encode().
"""
def __init__(self, errors='strict'):
"""
Creates an IncrementalEncoder instance.
The IncrementalEncoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.
"""
self.errors = errors
self.buffer = ""
def encode(self, input, final=False):
"""
Encodes input and returns the resulting object.
"""
raise NotImplementedError
def reset(self):
"""
Resets the encoder to the initial state.
"""
def getstate(self):
"""
Return the current state of the encoder.
"""
return 0
def setstate(self, state):
"""
Set the current state of the encoder. state must have been
returned by getstate().
"""
class BufferedIncrementalEncoder(IncrementalEncoder):
"""
This subclass of IncrementalEncoder can be used as the baseclass for an
incremental encoder if the encoder must keep some of the output in a
buffer between calls to encode().
"""
def __init__(self, errors='strict'):
IncrementalEncoder.__init__(self, errors)
self.buffer = "" # unencoded input that is kept between calls to encode()
def _buffer_encode(self, input, errors, final):
# Overwrite this method in subclasses: It must encode input
# and return an (output, length consumed) tuple
raise NotImplementedError
def encode(self, input, final=False):
# encode input (taking the buffer into account)
data = self.buffer + input
(result, consumed) = self._buffer_encode(data, self.errors, final)
# keep unencoded input until the next call
self.buffer = data[consumed:]
return result
def reset(self):
IncrementalEncoder.reset(self)
self.buffer = ""
def getstate(self):
return self.buffer or 0
def setstate(self, state):
self.buffer = state or ""
class IncrementalDecoder(object):
"""
An IncrementalDecoder decodes an input in multiple steps. The input can be
passed piece by piece to the decode() method. The IncrementalDecoder
remembers the state of the decoding process between calls to decode().
"""
def __init__(self, errors='strict'):
"""
Creates a IncrementalDecoder instance.
The IncrementalDecoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.
"""
self.errors = errors
def decode(self, input, final=False):
"""
Decodes input and returns the resulting object.
"""
raise NotImplementedError
def reset(self):
"""
Resets the decoder to the initial state.
"""
def getstate(self):
"""
Return the current state of the decoder.
This must be a (buffered_input, additional_state_info) tuple.
buffered_input must be a bytes object containing bytes that
were passed to decode() that have not yet been converted.
additional_state_info must be a non-negative integer
representing the state of the decoder WITHOUT yet having
processed the contents of buffered_input. In the initial state
and after reset(), getstate() must return (b"", 0).
"""
return (b"", 0)
def setstate(self, state):
"""
Set the current state of the decoder.
state must have been returned by getstate(). The effect of
setstate((b"", 0)) must be equivalent to reset().
"""
class BufferedIncrementalDecoder(IncrementalDecoder):
"""
This subclass of IncrementalDecoder can be used as the baseclass for an
incremental decoder if the decoder must be able to handle incomplete byte
sequences.
"""
def __init__(self, errors='strict'):
IncrementalDecoder.__init__(self, errors)
self.buffer = "" # undecoded input that is kept between calls to decode()
def _buffer_decode(self, input, errors, final):
# Overwrite this method in subclasses: It must decode input
# and return an (output, length consumed) tuple
raise NotImplementedError
def decode(self, input, final=False):
# decode input (taking the buffer into account)
data = self.buffer + input
(result, consumed) = self._buffer_decode(data, self.errors, final)
# keep undecoded input until the next call
self.buffer = data[consumed:]
return result
def reset(self):
IncrementalDecoder.reset(self)
self.buffer = ""
def getstate(self):
# additional state info is always 0
return (self.buffer, 0)
def setstate(self, state):
# ignore additional state info
self.buffer = state[0]
#
# The StreamWriter and StreamReader class provide generic working
# interfaces which can be used to implement new encoding submodules
# very easily. See encodings/utf_8.py for an example on how this is
# done.
#
class StreamWriter(Codec):
def __init__(self, stream, errors='strict'):
""" Creates a StreamWriter instance.
stream must be a file-like object open for writing
(binary) data.
The StreamWriter may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character
'xmlcharrefreplace' - Replace with the appropriate XML
character reference.
'backslashreplace' - Replace with backslashed escape
sequences (only for encoding).
The set of allowed parameter values can be extended via
register_error.
"""
self.stream = stream
self.errors = errors
def write(self, object):
""" Writes the object's contents encoded to self.stream.
"""
data, consumed = self.encode(object, self.errors)
self.stream.write(data)
def writelines(self, list):
""" Writes the concatenated list of strings to the stream
using .write().
"""
self.write(''.join(list))
def reset(self):
""" Flushes and resets the codec buffers used for keeping state.
Calling this method should ensure that the data on the
output is put into a clean state, that allows appending
of new fresh data without having to rescan the whole
stream to recover state.
"""
pass
def seek(self, offset, whence=0):
self.stream.seek(offset, whence)
if whence == 0 and offset == 0:
self.reset()
def __getattr__(self, name,
getattr=getattr):
""" Inherit all other methods from the underlying stream.
"""
return getattr(self.stream, name)
def __enter__(self):
return self
def __exit__(self, type, value, tb):
self.stream.close()
###
class StreamReader(Codec):
def __init__(self, stream, errors='strict'):
""" Creates a StreamReader instance.
stream must be a file-like object open for reading
(binary) data.
The StreamReader may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
'strict' - raise a ValueError (or a subclass)
'ignore' - ignore the character and continue with the next
'replace'- replace with a suitable replacement character;
The set of allowed parameter values can be extended via
register_error.
"""
self.stream = stream
self.errors = errors
self.bytebuffer = ""
# For str->str decoding this will stay a str
# For str->unicode decoding the first read will promote it to unicode
self.charbuffer = ""
self.linebuffer = None
def decode(self, input, errors='strict'):
raise NotImplementedError
def read(self, size=-1, chars=-1, firstline=False):
""" Decodes data from the stream self.stream and returns the
resulting object.
chars indicates the number of characters to read from the
stream. read() will never return more than chars
characters, but it might return less, if there are not enough
characters available.
size indicates the approximate maximum number of bytes to
read from the stream for decoding purposes. The decoder
can modify this setting as appropriate. The default value
-1 indicates to read and decode as much as possible. size
is intended to prevent having to decode huge files in one
step.
If firstline is true, and a UnicodeDecodeError happens
after the first line terminator in the input only the first line
will be returned, the rest of the input will be kept until the
next call to read().
The method should use a greedy read strategy meaning that
it should read as much data as is allowed within the
definition of the encoding and the given size, e.g. if
optional encoding endings or state markers are available
on the stream, these should be read too.
"""
# If we have lines cached, first merge them back into characters
if self.linebuffer:
self.charbuffer = "".join(self.linebuffer)
self.linebuffer = None
# read until we get the required number of characters (if available)
while True:
# can the request can be satisfied from the character buffer?
if chars < 0:
if size < 0:
if self.charbuffer:
break
elif len(self.charbuffer) >= size:
break
else:
if len(self.charbuffer) >= chars:
break
# we need more data
if size < 0:
newdata = self.stream.read()
else:
newdata = self.stream.read(size)
# decode bytes (those remaining from the last call included)
data = self.bytebuffer + newdata
try:
newchars, decodedbytes = self.decode(data, self.errors)
except UnicodeDecodeError, exc:
if firstline:
newchars, decodedbytes = self.decode(data[:exc.start], self.errors)
lines = newchars.splitlines(True)
if len(lines)<=1:
raise
else:
raise
# keep undecoded bytes until the next call
self.bytebuffer = data[decodedbytes:]
# put new characters in the character buffer
self.charbuffer += newchars
# there was no data available
if not newdata:
break
if chars < 0:
# Return everything we've got
result = self.charbuffer
self.charbuffer = ""
else:
# Return the first chars characters
result = self.charbuffer[:chars]
self.charbuffer = self.charbuffer[chars:]
return result
def readline(self, size=None, keepends=True):
""" Read one line from the input stream and return the
decoded data.
size, if given, is passed as size argument to the
read() method.
"""
# If we have lines cached from an earlier read, return
# them unconditionally
if self.linebuffer:
line = self.linebuffer[0]
del self.linebuffer[0]
if len(self.linebuffer) == 1:
# revert to charbuffer mode; we might need more data
# next time
self.charbuffer = self.linebuffer[0]
self.linebuffer = None
if not keepends:
line = line.splitlines(False)[0]
return line
readsize = size or 72
line = ""
# If size is given, we call read() only once
while True:
data = self.read(readsize, firstline=True)
if data:
# If we're at a "\r" read one extra character (which might
# be a "\n") to get a proper line ending. If the stream is
# temporarily exhausted we return the wrong line ending.
if data.endswith("\r"):
data += self.read(size=1, chars=1)
line += data
lines = line.splitlines(True)
if lines:
if len(lines) > 1:
# More than one line result; the first line is a full line
# to return
line = lines[0]
del lines[0]
if len(lines) > 1:
# cache the remaining lines
lines[-1] += self.charbuffer
self.linebuffer = lines
self.charbuffer = None
else:
# only one remaining line, put it back into charbuffer
self.charbuffer = lines[0] + self.charbuffer
if not keepends:
line = line.splitlines(False)[0]
break
line0withend = lines[0]
line0withoutend = lines[0].splitlines(False)[0]
if line0withend != line0withoutend: # We really have a line end
# Put the rest back together and keep it until the next call
self.charbuffer = "".join(lines[1:]) + self.charbuffer
if keepends:
line = line0withend
else:
line = line0withoutend
break
# we didn't get anything or this was our only try
if not data or size is not None:
if line and not keepends:
line = line.splitlines(False)[0]
break
if readsize<8000:
readsize *= 2
return line
def readlines(self, sizehint=None, keepends=True):
""" Read all lines available on the input stream
and return them as list of lines.
Line breaks are implemented using the codec's decoder
method and are included in the list entries.
sizehint, if given, is ignored since there is no efficient
way to finding the true end-of-line.
"""
data = self.read()
return data.splitlines(keepends)
def reset(self):
""" Resets the codec buffers used for keeping state.
Note that no stream repositioning should take place.
This method is primarily intended to be able to recover
from decoding errors.
"""
self.bytebuffer = ""
self.charbuffer = u""
self.linebuffer = None
def seek(self, offset, whence=0):
""" Set the input stream's current position.
Resets the codec buffers used for keeping state.
"""
self.stream.seek(offset, whence)
self.reset()
def next(self):
""" Return the next decoded line from the input stream."""
line = self.readline()
if line:
return line
raise StopIteration
def __iter__(self):
return self
def __getattr__(self, name,
getattr=getattr):
""" Inherit all other methods from the underlying stream.
"""
return getattr(self.stream, name)
def __enter__(self):
return self
def __exit__(self, type, value, tb):
self.stream.close()
###
class StreamReaderWriter:
""" StreamReaderWriter instances allow wrapping streams which
work in both read and write modes.
The design is such that one can use the factory functions
returned by the codec.lookup() function to construct the
instance.
"""
# Optional attributes set by the file wrappers below
encoding = 'unknown'
def __init__(self, stream, Reader, Writer, errors='strict'):
""" Creates a StreamReaderWriter instance.
stream must be a Stream-like object.
Reader, Writer must be factory functions or classes
providing the StreamReader, StreamWriter interface resp.
Error handling is done in the same way as defined for the
StreamWriter/Readers.
"""
self.stream = stream
self.reader = Reader(stream, errors)
self.writer = Writer(stream, errors)
self.errors = errors
def read(self, size=-1):
return self.reader.read(size)
def readline(self, size=None):
return self.reader.readline(size)
def readlines(self, sizehint=None):
return self.reader.readlines(sizehint)
def next(self):
""" Return the next decoded line from the input stream."""
return self.reader.next()
def __iter__(self):
return self
def write(self, data):
return self.writer.write(data)
def writelines(self, list):
return self.writer.writelines(list)
def reset(self):
self.reader.reset()
self.writer.reset()
def seek(self, offset, whence=0):
self.stream.seek(offset, whence)
self.reader.reset()
if whence == 0 and offset == 0:
self.writer.reset()
def __getattr__(self, name,
getattr=getattr):
""" Inherit all other methods from the underlying stream.
"""
return getattr(self.stream, name)
# these are needed to make "with codecs.open(...)" work properly
def __enter__(self):
return self
def __exit__(self, type, value, tb):
self.stream.close()
###
class StreamRecoder:
""" StreamRecoder instances provide a frontend - backend
view of encoding data.
They use the complete set of APIs returned by the
codecs.lookup() function to implement their task.
Data written to the stream is first decoded into an
intermediate format (which is dependent on the given codec
combination) and then written to the stream using an instance
of the provided Writer class.
In the other direction, data is read from the stream using a
Reader instance and then return encoded data to the caller.
"""
# Optional attributes set by the file wrappers below
data_encoding = 'unknown'
file_encoding = 'unknown'
def __init__(self, stream, encode, decode, Reader, Writer,
errors='strict'):
""" Creates a StreamRecoder instance which implements a two-way
conversion: encode and decode work on the frontend (the
input to .read() and output of .write()) while
Reader and Writer work on the backend (reading and
writing to the stream).
You can use these objects to do transparent direct
recodings from e.g. latin-1 to utf-8 and back.
stream must be a file-like object.
encode, decode must adhere to the Codec interface, Reader,
Writer must be factory functions or classes providing the
StreamReader, StreamWriter interface resp.
encode and decode are needed for the frontend translation,
Reader and Writer for the backend translation. Unicode is
used as intermediate encoding.
Error handling is done in the same way as defined for the
StreamWriter/Readers.
"""
self.stream = stream
self.encode = encode
self.decode = decode
self.reader = Reader(stream, errors)
self.writer = Writer(stream, errors)
self.errors = errors
def read(self, size=-1):
data = self.reader.read(size)
data, bytesencoded = self.encode(data, self.errors)
return data
def readline(self, size=None):
if size is None:
data = self.reader.readline()
else:
data = self.reader.readline(size)
data, bytesencoded = self.encode(data, self.errors)
return data
def readlines(self, sizehint=None):
data = self.reader.read()
data, bytesencoded = self.encode(data, self.errors)
return data.splitlines(1)
def next(self):
""" Return the next decoded line from the input stream."""
data = self.reader.next()
data, bytesencoded = self.encode(data, self.errors)
return data
def __iter__(self):
return self
def write(self, data):
data, bytesdecoded = self.decode(data, self.errors)
return self.writer.write(data)
def writelines(self, list):
data = ''.join(list)
data, bytesdecoded = self.decode(data, self.errors)
return self.writer.write(data)
def reset(self):
self.reader.reset()
self.writer.reset()
def __getattr__(self, name,
getattr=getattr):
""" Inherit all other methods from the underlying stream.
"""
return getattr(self.stream, name)
def __enter__(self):
return self
def __exit__(self, type, value, tb):
self.stream.close()
### Shortcuts
def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
""" Open an encoded file using the given mode and return
a wrapped version providing transparent encoding/decoding.
Note: The wrapped version will only accept the object format
defined by the codecs, i.e. Unicode objects for most builtin
codecs. Output is also codec dependent and will usually be
Unicode as well.
Files are always opened in binary mode, even if no binary mode
was specified. This is done to avoid data loss due to encodings
using 8-bit values. The default file mode is 'rb' meaning to
open the file in binary read mode.
encoding specifies the encoding which is to be used for the
file.
errors may be given to define the error handling. It defaults
to 'strict' which causes ValueErrors to be raised in case an
encoding error occurs.
buffering has the same meaning as for the builtin open() API.
It defaults to line buffered.
The returned wrapped file object provides an extra attribute
.encoding which allows querying the used encoding. This
attribute is only available if an encoding was specified as
parameter.
"""
if encoding is not None:
if 'U' in mode:
# No automatic conversion of '\n' is done on reading and writing
mode = mode.strip().replace('U', '')
if mode[:1] not in set('rwa'):
mode = 'r' + mode
if 'b' not in mode:
# Force opening of the file in binary mode
mode = mode + 'b'
file = __builtin__.open(filename, mode, buffering)
if encoding is None:
return file
info = lookup(encoding)
srw = StreamReaderWriter(file, info.streamreader, info.streamwriter, errors)
# Add attributes to simplify introspection
srw.encoding = encoding
return srw
def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'):
""" Return a wrapped version of file which provides transparent
encoding translation.
Strings written to the wrapped file are interpreted according
to the given data_encoding and then written to the original
file as string using file_encoding. The intermediate encoding
will usually be Unicode but depends on the specified codecs.
Strings are read from the file using file_encoding and then
passed back to the caller as string using data_encoding.
If file_encoding is not given, it defaults to data_encoding.
errors may be given to define the error handling. It defaults
to 'strict' which causes ValueErrors to be raised in case an
encoding error occurs.
The returned wrapped file object provides two extra attributes
.data_encoding and .file_encoding which reflect the given
parameters of the same name. The attributes can be used for
introspection by Python programs.
"""
if file_encoding is None:
file_encoding = data_encoding
data_info = lookup(data_encoding)
file_info = lookup(file_encoding)
sr = StreamRecoder(file, data_info.encode, data_info.decode,
file_info.streamreader, file_info.streamwriter, errors)
# Add attributes to simplify introspection
sr.data_encoding = data_encoding
sr.file_encoding = file_encoding
return sr
### Helpers for codec lookup
def getencoder(encoding):
""" Lookup up the codec for the given encoding and return
its encoder function.
Raises a LookupError in case the encoding cannot be found.
"""
return lookup(encoding).encode
def getdecoder(encoding):
""" Lookup up the codec for the given encoding and return
its decoder function.
Raises a LookupError in case the encoding cannot be found.
"""
return lookup(encoding).decode
def getincrementalencoder(encoding):
""" Lookup up the codec for the given encoding and return
its IncrementalEncoder class or factory function.
Raises a LookupError in case the encoding cannot be found
or the codecs doesn't provide an incremental encoder.
"""
encoder = lookup(encoding).incrementalencoder
if encoder is None:
raise LookupError(encoding)
return encoder
def getincrementaldecoder(encoding):
""" Lookup up the codec for the given encoding and return
its IncrementalDecoder class or factory function.
Raises a LookupError in case the encoding cannot be found
or the codecs doesn't provide an incremental decoder.
"""
decoder = lookup(encoding).incrementaldecoder
if decoder is None:
raise LookupError(encoding)
return decoder
def getreader(encoding):
""" Lookup up the codec for the given encoding and return
its StreamReader class or factory function.
Raises a LookupError in case the encoding cannot be found.
"""
return lookup(encoding).streamreader
def getwriter(encoding):
""" Lookup up the codec for the given encoding and return
its StreamWriter class or factory function.
Raises a LookupError in case the encoding cannot be found.
"""
return lookup(encoding).streamwriter
def iterencode(iterator, encoding, errors='strict', **kwargs):
"""
Encoding iterator.
Encodes the input strings from the iterator using a IncrementalEncoder.
errors and kwargs are passed through to the IncrementalEncoder
constructor.
"""
encoder = getincrementalencoder(encoding)(errors, **kwargs)
for input in iterator:
output = encoder.encode(input)
if output:
yield output
output = encoder.encode("", True)
if output:
yield output
def iterdecode(iterator, encoding, errors='strict', **kwargs):
"""
Decoding iterator.
Decodes the input strings from the iterator using a IncrementalDecoder.
errors and kwargs are passed through to the IncrementalDecoder
constructor.
"""
decoder = getincrementaldecoder(encoding)(errors, **kwargs)
for input in iterator:
output = decoder.decode(input)
if output:
yield output
output = decoder.decode("", True)
if output:
yield output
### Helpers for charmap-based codecs
def make_identity_dict(rng):
""" make_identity_dict(rng) -> dict
Return a dictionary where elements of the rng sequence are
mapped to themselves.
"""
res = {}
for i in rng:
res[i]=i
return res
def make_encoding_map(decoding_map):
""" Creates an encoding map from a decoding map.
If a target mapping in the decoding map occurs multiple
times, then that target is mapped to None (undefined mapping),
causing an exception when encountered by the charmap codec
during translation.
One example where this happens is cp875.py which decodes
multiple character to \u001a.
"""
m = {}
for k,v in decoding_map.items():
if not v in m:
m[v] = k
else:
m[v] = None
return m
### error handlers
try:
strict_errors = lookup_error("strict")
ignore_errors = lookup_error("ignore")
replace_errors = lookup_error("replace")
xmlcharrefreplace_errors = lookup_error("xmlcharrefreplace")
backslashreplace_errors = lookup_error("backslashreplace")
except LookupError:
# In --disable-unicode builds, these error handler are missing
strict_errors = None
ignore_errors = None
replace_errors = None
xmlcharrefreplace_errors = None
backslashreplace_errors = None
# Tell modulefinder that using codecs probably needs the encodings
# package
_false = 0
if _false:
import encodings
### Tests
if __name__ == '__main__':
# Make stdout translate Latin-1 output into UTF-8 output
sys.stdout = EncodedFile(sys.stdout, 'latin-1', 'utf-8')
# Have stdin translate Latin-1 input into UTF-8 input
sys.stdin = EncodedFile(sys.stdin, 'utf-8', 'latin-1')
|
apache-2.0
|
[
624,
6010,
1553,
2018,
13732,
20738,
12,
3261,
436,
10897,
14,
8065,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
2999,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
2999,
199,
624,
23662,
2999,
199,
646,
636,
5351,
3108,
984,
2999,
199,
5680,
20738,
436,
6762,
1174,
2003,
9076,
3423,
2999,
199,
893,
26,
1128,
687,
485,
8933,
492,
627,
202,
199,
2590,
3545,
12,
10842,
26,
1128,
746,
6187,
547,
360,
4276,
370,
2248,
314,
6762,
6010,
26,
450,
83,
7,
450,
10842,
9,
2999,
199,
363,
452,
363,
275,
2097,
2683,
401,
298,
3892,
401,
298,
1490,
401,
298,
32149,
1173,
401,
298,
19550,
401,
298,
19550,
63,
6773,
401,
18691,
298,
19550,
63,
906,
401,
298,
19550,
708,
63,
6773,
401,
298,
19550,
708,
63,
906,
401,
298,
19550,
772,
63,
6773,
401,
298,
19550,
772,
63,
906,
401,
18691,
298,
19550,
63,
6610,
24,
401,
298,
19550,
63,
6610,
975,
401,
298,
19550,
63,
6610,
975,
63,
906,
401,
298,
19550,
63,
6610,
975,
63,
6773,
401,
18691,
298,
19550,
63,
6610,
708,
401,
298,
19550,
63,
6610,
708,
63,
906,
401,
298,
19550,
63,
6610,
708,
63,
6773,
401,
18691,
298,
4768,
63,
2550,
401,
298,
4247,
63,
2550,
401,
298,
1814,
63,
2550,
401,
18691,
298,
1652,
24253,
1814,
63,
2550,
401,
18691,
298,
2683,
63,
705,
401,
298,
3892,
63,
705,
937,
2999,
199,
5680,
22296,
2999,
199,
3,
202,
199,
3,
20301,
9240,
7173,
334,
19550,
275,
20348,
644,
998,
2080,
4825,
13,
14731,
16796,
275,
738,
11,
5100,
1665,
9,
202,
199,
3,
436,
2399,
3962,
3696,
1059,
1338,
202,
199,
3,
367,
9094,
24,
15,
6610,
975,
15,
6610,
708,
1072,
436,
12050,
15,
5076,
17638,
20601,
202,
199,
3,
2999,
199,
3,
9094,
13,
24,
202,
199,
19550,
63,
6610,
24,
275,
1557,
9532,
60,
9932,
60,
9566,
7,
2999,
199,
3,
9094,
13,
975,
12,
12050,
17638,
202,
199,
19550,
63,
906,
275,
17720,
63,
6610,
975,
63,
906,
275,
1557,
3581,
60,
8371,
7,
2999,
199,
3,
9094,
13,
975,
12,
7282,
17638,
202,
199,
19550,
63,
6773,
275,
17720,
63,
6610,
975,
63,
6773,
275,
1557,
8371,
60,
3581,
7,
2999,
199,
3,
9094,
13,
708,
12,
12050,
17638,
202,
199,
19550,
63,
6610,
708,
63,
906,
275,
1557,
3581,
60,
8371,
60,
88,
383,
60,
88,
383,
7,
2999,
199,
3,
9094,
13,
708,
12,
7282,
17638,
202,
199,
19550,
63,
6610,
708,
63,
6773,
275,
1557,
88,
383,
60,
88,
383,
60,
8371,
60,
3581,
7,
2999,
199,
692,
984,
14,
19415,
508,
283,
10182,
356,
2958,
327,
9094,
13,
975,
12,
5438,
17638,
4171,
1128,
17720,
275,
17720,
63,
6610,
975,
275,
17720,
63,
6610,
975,
63,
906,
2958,
327,
9094,
13,
708,
12,
5438,
17638,
4171,
1128,
17720,
63,
6610,
708,
275,
17720,
63,
6610,
708,
63,
906,
2999,
199,
2836,
26,
2958,
327,
9094,
13,
975,
12,
5438,
17638,
4171,
1128,
17720,
275,
17720,
63,
6610,
975,
275,
17720,
63,
6610,
975,
63,
6773,
2958,
327,
9094,
13,
708,
12,
5438,
17638,
4171,
1128,
17720,
63,
6610,
708,
275,
17720,
63,
6610,
708,
63,
6773,
2999,
199,
3,
21238,
10529,
1561,
334,
13196,
1133,
675,
315,
892,
1233,
9,
202,
199,
19550,
708,
63,
906,
275,
17720,
63,
6610,
975,
63,
906,
202,
199,
19550,
708,
63,
6773,
275,
17720,
63,
6610,
975,
63,
6773,
202,
199,
19550,
772,
63,
906,
275,
17720,
63,
6610,
708,
63,
906,
202,
199,
19550,
772,
63,
6773,
275,
17720,
63,
6610,
708,
63,
6773,
8065,
199,
5680,
13732,
1300,
3992,
334,
318,
7969,
314,
3261,
9,
2999,
199,
533,
13732,
2354,
8,
2960,
304,
2958,
347,
636,
1222,
721,
1886,
12,
3752,
12,
4849,
12,
26101,
29,
403,
12,
26112,
29,
403,
12,
1039,
26329,
29,
403,
12,
26317,
29,
403,
12,
536,
29,
403,
304,
1039,
291,
275,
2008,
855,
1222,
721,
1886,
12,
334,
2143,
12,
4849,
12,
26101,
12,
26112,
430,
1039,
291,
14,
354,
275,
536,
1039,
291,
14,
2143,
275,
3752,
1039,
291,
14,
2708,
275,
4849,
1039,
291,
14,
9728,
24080,
275,
26329,
1039,
291,
14,
23760,
8813,
275,
26317,
1039,
291,
14,
1745,
5491,
275,
26112,
1039,
291,
14,
1745,
5503,
275,
26101,
1039,
372,
291,
2958,
347,
636,
2722,
721,
277,
304,
1039,
372,
23054,
83,
4111,
83,
909,
367,
2644,
450,
83,
737,
378,
88,
5,
88,
4335,
450,
334,
277,
855,
533,
4914,
578,
3108,
291,
855,
533,
4914,
354,
3108,
291,
14,
354,
12,
1305,
8,
277,
430,
2999,
199,
533,
13732,
26,
2958,
408,
25022,
314,
3217,
367,
1174,
2003,
10295,
83,
15,
8813,
83,
14,
4341,
710,
1275,
2143,
342,
8083,
2708,
342,
3102,
1443,
675,
3365,
1125,
1039,
7252,
21149,
701,
13070,
314,
2552,
1423,
14,
5723,
1039,
1059,
1338,
787,
27684,
26,
2999,
268,
283,
4768,
7,
446,
746,
282,
1722,
1125,
334,
269,
282,
5516,
9,
8740,
283,
4247,
7,
446,
3686,
314,
4528,
436,
1980,
543,
314,
2163,
8740,
283,
1814,
7,
446,
3350,
543,
282,
11233,
8343,
4528,
27,
4906,
2018,
911,
675,
314,
25410,
738,
11,
28050,
5363,
2749,
22194,
4906,
9502,
367,
314,
6762,
6140,
6010,
641,
4906,
15952,
436,
15539,
641,
2644,
14,
8740,
283,
1652,
24253,
1814,
7,
446,
14402,
543,
314,
5827,
4692,
202,
3044,
4528,
3659,
334,
2118,
367,
2644,
680,
8740,
283,
21509,
1814,
7,
221,
446,
14402,
543,
13831,
379,
4772,
8013,
202,
3044,
334,
2118,
367,
2644,
680,
4341,
710,
663,
402,
4370,
1338,
883,
506,
9243,
4799,
2274,
63,
705,
14,
2958,
408,
1128,
347,
3752,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
4341,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
1675,
909,
12,
2582,
16949,
680,
11556,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
1675,
283,
4768,
7,
7252,
14,
11556,
710,
1083,
1443,
440,
3877,
1174,
315,
314,
13732,
1256,
14,
3645,
1675,
8271,
8818,
367,
6010,
1314,
1172,
370,
4215,
1174,
315,
1865,
370,
1675,
1852,
2644,
15
] |
[
6010,
1553,
2018,
13732,
20738,
12,
3261,
436,
10897,
14,
8065,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
2999,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
2999,
199,
624,
23662,
2999,
199,
646,
636,
5351,
3108,
984,
2999,
199,
5680,
20738,
436,
6762,
1174,
2003,
9076,
3423,
2999,
199,
893,
26,
1128,
687,
485,
8933,
492,
627,
202,
199,
2590,
3545,
12,
10842,
26,
1128,
746,
6187,
547,
360,
4276,
370,
2248,
314,
6762,
6010,
26,
450,
83,
7,
450,
10842,
9,
2999,
199,
363,
452,
363,
275,
2097,
2683,
401,
298,
3892,
401,
298,
1490,
401,
298,
32149,
1173,
401,
298,
19550,
401,
298,
19550,
63,
6773,
401,
18691,
298,
19550,
63,
906,
401,
298,
19550,
708,
63,
6773,
401,
298,
19550,
708,
63,
906,
401,
298,
19550,
772,
63,
6773,
401,
298,
19550,
772,
63,
906,
401,
18691,
298,
19550,
63,
6610,
24,
401,
298,
19550,
63,
6610,
975,
401,
298,
19550,
63,
6610,
975,
63,
906,
401,
298,
19550,
63,
6610,
975,
63,
6773,
401,
18691,
298,
19550,
63,
6610,
708,
401,
298,
19550,
63,
6610,
708,
63,
906,
401,
298,
19550,
63,
6610,
708,
63,
6773,
401,
18691,
298,
4768,
63,
2550,
401,
298,
4247,
63,
2550,
401,
298,
1814,
63,
2550,
401,
18691,
298,
1652,
24253,
1814,
63,
2550,
401,
18691,
298,
2683,
63,
705,
401,
298,
3892,
63,
705,
937,
2999,
199,
5680,
22296,
2999,
199,
3,
202,
199,
3,
20301,
9240,
7173,
334,
19550,
275,
20348,
644,
998,
2080,
4825,
13,
14731,
16796,
275,
738,
11,
5100,
1665,
9,
202,
199,
3,
436,
2399,
3962,
3696,
1059,
1338,
202,
199,
3,
367,
9094,
24,
15,
6610,
975,
15,
6610,
708,
1072,
436,
12050,
15,
5076,
17638,
20601,
202,
199,
3,
2999,
199,
3,
9094,
13,
24,
202,
199,
19550,
63,
6610,
24,
275,
1557,
9532,
60,
9932,
60,
9566,
7,
2999,
199,
3,
9094,
13,
975,
12,
12050,
17638,
202,
199,
19550,
63,
906,
275,
17720,
63,
6610,
975,
63,
906,
275,
1557,
3581,
60,
8371,
7,
2999,
199,
3,
9094,
13,
975,
12,
7282,
17638,
202,
199,
19550,
63,
6773,
275,
17720,
63,
6610,
975,
63,
6773,
275,
1557,
8371,
60,
3581,
7,
2999,
199,
3,
9094,
13,
708,
12,
12050,
17638,
202,
199,
19550,
63,
6610,
708,
63,
906,
275,
1557,
3581,
60,
8371,
60,
88,
383,
60,
88,
383,
7,
2999,
199,
3,
9094,
13,
708,
12,
7282,
17638,
202,
199,
19550,
63,
6610,
708,
63,
6773,
275,
1557,
88,
383,
60,
88,
383,
60,
8371,
60,
3581,
7,
2999,
199,
692,
984,
14,
19415,
508,
283,
10182,
356,
2958,
327,
9094,
13,
975,
12,
5438,
17638,
4171,
1128,
17720,
275,
17720,
63,
6610,
975,
275,
17720,
63,
6610,
975,
63,
906,
2958,
327,
9094,
13,
708,
12,
5438,
17638,
4171,
1128,
17720,
63,
6610,
708,
275,
17720,
63,
6610,
708,
63,
906,
2999,
199,
2836,
26,
2958,
327,
9094,
13,
975,
12,
5438,
17638,
4171,
1128,
17720,
275,
17720,
63,
6610,
975,
275,
17720,
63,
6610,
975,
63,
6773,
2958,
327,
9094,
13,
708,
12,
5438,
17638,
4171,
1128,
17720,
63,
6610,
708,
275,
17720,
63,
6610,
708,
63,
6773,
2999,
199,
3,
21238,
10529,
1561,
334,
13196,
1133,
675,
315,
892,
1233,
9,
202,
199,
19550,
708,
63,
906,
275,
17720,
63,
6610,
975,
63,
906,
202,
199,
19550,
708,
63,
6773,
275,
17720,
63,
6610,
975,
63,
6773,
202,
199,
19550,
772,
63,
906,
275,
17720,
63,
6610,
708,
63,
906,
202,
199,
19550,
772,
63,
6773,
275,
17720,
63,
6610,
708,
63,
6773,
8065,
199,
5680,
13732,
1300,
3992,
334,
318,
7969,
314,
3261,
9,
2999,
199,
533,
13732,
2354,
8,
2960,
304,
2958,
347,
636,
1222,
721,
1886,
12,
3752,
12,
4849,
12,
26101,
29,
403,
12,
26112,
29,
403,
12,
1039,
26329,
29,
403,
12,
26317,
29,
403,
12,
536,
29,
403,
304,
1039,
291,
275,
2008,
855,
1222,
721,
1886,
12,
334,
2143,
12,
4849,
12,
26101,
12,
26112,
430,
1039,
291,
14,
354,
275,
536,
1039,
291,
14,
2143,
275,
3752,
1039,
291,
14,
2708,
275,
4849,
1039,
291,
14,
9728,
24080,
275,
26329,
1039,
291,
14,
23760,
8813,
275,
26317,
1039,
291,
14,
1745,
5491,
275,
26112,
1039,
291,
14,
1745,
5503,
275,
26101,
1039,
372,
291,
2958,
347,
636,
2722,
721,
277,
304,
1039,
372,
23054,
83,
4111,
83,
909,
367,
2644,
450,
83,
737,
378,
88,
5,
88,
4335,
450,
334,
277,
855,
533,
4914,
578,
3108,
291,
855,
533,
4914,
354,
3108,
291,
14,
354,
12,
1305,
8,
277,
430,
2999,
199,
533,
13732,
26,
2958,
408,
25022,
314,
3217,
367,
1174,
2003,
10295,
83,
15,
8813,
83,
14,
4341,
710,
1275,
2143,
342,
8083,
2708,
342,
3102,
1443,
675,
3365,
1125,
1039,
7252,
21149,
701,
13070,
314,
2552,
1423,
14,
5723,
1039,
1059,
1338,
787,
27684,
26,
2999,
268,
283,
4768,
7,
446,
746,
282,
1722,
1125,
334,
269,
282,
5516,
9,
8740,
283,
4247,
7,
446,
3686,
314,
4528,
436,
1980,
543,
314,
2163,
8740,
283,
1814,
7,
446,
3350,
543,
282,
11233,
8343,
4528,
27,
4906,
2018,
911,
675,
314,
25410,
738,
11,
28050,
5363,
2749,
22194,
4906,
9502,
367,
314,
6762,
6140,
6010,
641,
4906,
15952,
436,
15539,
641,
2644,
14,
8740,
283,
1652,
24253,
1814,
7,
446,
14402,
543,
314,
5827,
4692,
202,
3044,
4528,
3659,
334,
2118,
367,
2644,
680,
8740,
283,
21509,
1814,
7,
221,
446,
14402,
543,
13831,
379,
4772,
8013,
202,
3044,
334,
2118,
367,
2644,
680,
4341,
710,
663,
402,
4370,
1338,
883,
506,
9243,
4799,
2274,
63,
705,
14,
2958,
408,
1128,
347,
3752,
8,
277,
12,
1324,
12,
2552,
534,
4768,
735,
4341,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
1675,
909,
12,
2582,
16949,
680,
11556,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
1675,
283,
4768,
7,
7252,
14,
11556,
710,
1083,
1443,
440,
3877,
1174,
315,
314,
13732,
1256,
14,
3645,
1675,
8271,
8818,
367,
6010,
1314,
1172,
370,
4215,
1174,
315,
1865,
370,
1675,
1852,
2644,
15,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sajavadi/pinot
|
pinot-dashboard/pinotui/config.py
|
17
|
2368
|
#!/usr/bin/env python2.6
#
# Copyright (C) 2015 LinkedIn Corp. (pinot-core@linkedin.com)
#
# 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 yaml
from exceptions import PinotException
class ConfigManager(object):
def __init__(self, logger):
self.path = 'config.yml'
self.logger = logger
self.config = {}
def load(self):
try:
with open(self.path, 'r') as h:
contents = h.read()
except IOError:
self.logger.exception('Failed reading config file')
return
try:
self.config = yaml.load(contents)
except yaml.YAMLError:
self.logger.exception('Failed parsing config yaml')
def update(self, conf):
self.config.update(conf)
def get_controller_url(self, fabric):
try:
return self.config['fabrics'][fabric]['controller_url']
except KeyError:
error = 'Failed getting controller url from config'
self.logger.exception(error)
raise PinotException(error)
def get_zk_host(self, fabric):
try:
return self.config['fabrics'][fabric]['zk_host']
except KeyError:
error = 'Failed getting zookeeper host from config'
self.logger.exception(error)
raise PinotException(error)
def get_zk_root(self, fabric):
try:
return self.config['fabrics'][fabric]['zk_root']
except KeyError:
error = 'Failed getting zookeeper root from config'
self.logger.exception(error)
raise PinotException(error)
def get_fabrics(self):
try:
return self.config['fabrics'].keys()
except KeyError:
error = 'Failed getting list of fabrics from config'
self.logger.exception(error)
raise PinotException(error)
def get_flask_port(self):
try:
return int(self.config['listen_port'])
except (KeyError, ValueError):
self.logger.exception('Failed getting flask port from config')
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
14,
22,
199,
3,
199,
3,
1898,
334,
35,
9,
6900,
10967,
379,
607,
22304,
14,
334,
7751,
357,
13,
1018,
32,
12751,
262,
14,
957,
9,
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,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
8864,
199,
504,
4967,
492,
26486,
357,
1726,
421,
199,
533,
4094,
2988,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2512,
304,
272,
291,
14,
515,
275,
283,
888,
14,
11714,
7,
272,
291,
14,
2921,
275,
2512,
272,
291,
14,
888,
275,
1052,
819,
347,
2248,
8,
277,
304,
272,
862,
26,
489,
543,
1551,
8,
277,
14,
515,
12,
283,
82,
358,
465,
394,
26,
267,
4072,
275,
394,
14,
739,
342,
272,
871,
5925,
26,
489,
291,
14,
2921,
14,
1971,
360,
4276,
7664,
1101,
570,
358,
489,
372,
339,
862,
26,
489,
291,
14,
888,
275,
8864,
14,
912,
8,
4407,
9,
272,
871,
8864,
14,
23103,
547,
26,
489,
291,
14,
2921,
14,
1971,
360,
4276,
6057,
1101,
8864,
358,
819,
347,
1678,
8,
277,
12,
3743,
304,
272,
291,
14,
888,
14,
873,
8,
2190,
9,
819,
347,
664,
63,
5538,
63,
633,
8,
277,
12,
2630,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
3488,
4991,
2733,
5538,
63,
633,
418,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
7614,
1166,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
20344,
63,
1102,
8,
277,
12,
2630,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
3488,
4991,
2733,
20344,
63,
1102,
418,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
1315,
23479,
1591,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
20344,
63,
1231,
8,
277,
12,
2630,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
3488,
4991,
2733,
20344,
63,
1231,
418,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
1315,
23479,
1738,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
21159,
11818,
8,
277,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
2278,
1612,
342,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
769,
402,
31507,
11818,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
15720,
63,
719,
8,
277,
304,
272,
862,
26,
489,
372,
1109,
8,
277,
14,
888,
459,
5859,
63,
719,
1105,
272,
871,
334,
10230,
12,
1722,
304,
489,
291,
14,
2921,
14,
1971,
360,
4276,
10232,
7209,
1844,
687,
1101,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
14,
22,
199,
3,
199,
3,
1898,
334,
35,
9,
6900,
10967,
379,
607,
22304,
14,
334,
7751,
357,
13,
1018,
32,
12751,
262,
14,
957,
9,
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,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
8864,
199,
504,
4967,
492,
26486,
357,
1726,
421,
199,
533,
4094,
2988,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2512,
304,
272,
291,
14,
515,
275,
283,
888,
14,
11714,
7,
272,
291,
14,
2921,
275,
2512,
272,
291,
14,
888,
275,
1052,
819,
347,
2248,
8,
277,
304,
272,
862,
26,
489,
543,
1551,
8,
277,
14,
515,
12,
283,
82,
358,
465,
394,
26,
267,
4072,
275,
394,
14,
739,
342,
272,
871,
5925,
26,
489,
291,
14,
2921,
14,
1971,
360,
4276,
7664,
1101,
570,
358,
489,
372,
339,
862,
26,
489,
291,
14,
888,
275,
8864,
14,
912,
8,
4407,
9,
272,
871,
8864,
14,
23103,
547,
26,
489,
291,
14,
2921,
14,
1971,
360,
4276,
6057,
1101,
8864,
358,
819,
347,
1678,
8,
277,
12,
3743,
304,
272,
291,
14,
888,
14,
873,
8,
2190,
9,
819,
347,
664,
63,
5538,
63,
633,
8,
277,
12,
2630,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
3488,
4991,
2733,
5538,
63,
633,
418,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
7614,
1166,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
20344,
63,
1102,
8,
277,
12,
2630,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
3488,
4991,
2733,
20344,
63,
1102,
418,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
1315,
23479,
1591,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
20344,
63,
1231,
8,
277,
12,
2630,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
3488,
4991,
2733,
20344,
63,
1231,
418,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
1315,
23479,
1738,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
21159,
11818,
8,
277,
304,
272,
862,
26,
489,
372,
291,
14,
888,
459,
21159,
11818,
2278,
1612,
342,
272,
871,
4067,
26,
489,
1125,
275,
283,
4276,
10232,
769,
402,
31507,
11818,
687,
1101,
7,
489,
291,
14,
2921,
14,
1971,
8,
705,
9,
489,
746,
26486,
357,
1726,
8,
705,
9,
819,
347,
664,
63,
15720,
63,
719,
8,
277,
304,
272,
862,
26,
489,
372,
1109,
8,
277,
14,
888,
459,
5859,
63,
719,
1105,
272,
871,
334,
10230,
12,
1722,
304,
489,
291,
14,
2921,
14,
1971,
360,
4276,
10232,
7209,
1844,
687,
1101,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
awylie/hadoop
|
src/contrib/hod/hodlib/Common/xmlrpc.py
|
182
|
2374
|
#Licensed to the Apache Software Foundation (ASF) under one
#or more contributor license agreements. See the NOTICE file
#distributed with this work for additional information
#regarding copyright ownership. The ASF licenses this file
#to you under the Apache License, Version 2.0 (the
#"License"); you may not use this file except in compliance
#with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
import xmlrpclib, time, random, signal
from hodlib.Common.util import hodInterrupt, HodInterruptException
class hodXRClient(xmlrpclib.ServerProxy):
def __init__(self, uri, transport=None, encoding=None, verbose=0,
allow_none=0, installSignalHandlers=1, retryRequests=True, timeOut=15):
xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding, verbose,
allow_none)
self.__retryRequests = retryRequests
self.__timeOut = timeOut
if (installSignalHandlers!=0):
self.__set_alarm()
def __set_alarm(self):
def alarm_handler(sigNum, sigHandler):
raise Exception("XML-RPC socket timeout.")
signal.signal(signal.SIGALRM, alarm_handler)
def __request(self, methodname, params):
response = None
retryWaitTime = 5 + random.randint(0, 5)
for i in range(0, 30):
signal.alarm(self.__timeOut)
try:
response = self._ServerProxy__request(methodname, params)
signal.alarm(0)
break
except Exception:
if self.__retryRequests:
if hodInterrupt.isSet():
raise HodInterruptException()
time.sleep(retryWaitTime)
else:
raise Exception("hodXRClientTimeout")
return response
def __getattr__(self, name):
# magic method dispatcher
return xmlrpclib._Method(self.__request, name)
|
apache-2.0
|
[
3,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
646,
19122,
12,
900,
12,
2196,
12,
4673,
199,
504,
394,
364,
773,
14,
7844,
14,
1974,
492,
394,
364,
10647,
12,
869,
364,
10647,
1726,
199,
199,
533,
394,
364,
12297,
3041,
8,
17596,
773,
14,
3120,
4936,
304,
272,
347,
636,
826,
721,
277,
12,
5108,
12,
7773,
29,
403,
12,
2644,
29,
403,
12,
3376,
29,
16,
12,
326,
2040,
63,
3592,
29,
16,
12,
3907,
11274,
25096,
29,
17,
12,
7269,
16272,
29,
549,
12,
900,
2204,
29,
1046,
304,
267,
19122,
14,
3120,
4936,
855,
826,
721,
277,
12,
5108,
12,
7773,
12,
2644,
12,
3376,
12,
221,
4318,
2040,
63,
3592,
9,
267,
291,
855,
7154,
16272,
275,
7269,
16272,
267,
291,
855,
521,
2204,
275,
900,
2204,
267,
340,
334,
3174,
11274,
25096,
1111,
16,
304,
881,
291,
855,
409,
63,
14160,
342,
2286,
347,
636,
409,
63,
14160,
8,
277,
304,
267,
347,
17987,
63,
2232,
8,
4093,
5667,
12,
5259,
2461,
304,
288,
746,
2186,
480,
4317,
13,
8171,
2838,
2653,
2685,
1779,
267,
4673,
14,
4653,
8,
4653,
14,
7864,
748,
11026,
12,
17987,
63,
2232,
9,
2126,
272,
347,
636,
1069,
8,
277,
12,
28009,
12,
1862,
304,
267,
1177,
275,
488,
267,
7269,
7536,
1366,
275,
959,
435,
2196,
14,
8393,
8,
16,
12,
959,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
4233,
304,
288,
4673,
14,
14160,
8,
277,
855,
521,
2204,
9,
288,
862,
26,
355,
1177,
275,
291,
423,
3120,
4936,
363,
1069,
8,
765,
354,
12,
1862,
9,
355,
4673,
14,
14160,
8,
16,
9,
355,
2059,
288,
871,
2186,
26,
355,
340,
291,
855,
7154,
16272,
26,
2116,
340,
394,
364,
10647,
14,
374,
1084,
837,
490,
746,
869,
364,
10647,
1726,
342,
2116,
900,
14,
4532,
8,
7154,
7536,
1366,
9,
355,
587,
26,
2116,
746,
2186,
480,
72,
364,
12297,
3041,
6372,
531,
398,
372,
1177,
326,
272,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
327,
10628,
1083,
17475,
267,
372,
19122,
423,
3767,
8,
277,
855,
1069,
12,
536,
9,
1169,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
646,
19122,
12,
900,
12,
2196,
12,
4673,
199,
504,
394,
364,
773,
14,
7844,
14,
1974,
492,
394,
364,
10647,
12,
869,
364,
10647,
1726,
199,
199,
533,
394,
364,
12297,
3041,
8,
17596,
773,
14,
3120,
4936,
304,
272,
347,
636,
826,
721,
277,
12,
5108,
12,
7773,
29,
403,
12,
2644,
29,
403,
12,
3376,
29,
16,
12,
326,
2040,
63,
3592,
29,
16,
12,
3907,
11274,
25096,
29,
17,
12,
7269,
16272,
29,
549,
12,
900,
2204,
29,
1046,
304,
267,
19122,
14,
3120,
4936,
855,
826,
721,
277,
12,
5108,
12,
7773,
12,
2644,
12,
3376,
12,
221,
4318,
2040,
63,
3592,
9,
267,
291,
855,
7154,
16272,
275,
7269,
16272,
267,
291,
855,
521,
2204,
275,
900,
2204,
267,
340,
334,
3174,
11274,
25096,
1111,
16,
304,
881,
291,
855,
409,
63,
14160,
342,
2286,
347,
636,
409,
63,
14160,
8,
277,
304,
267,
347,
17987,
63,
2232,
8,
4093,
5667,
12,
5259,
2461,
304,
288,
746,
2186,
480,
4317,
13,
8171,
2838,
2653,
2685,
1779,
267,
4673,
14,
4653,
8,
4653,
14,
7864,
748,
11026,
12,
17987,
63,
2232,
9,
2126,
272,
347,
636,
1069,
8,
277,
12,
28009,
12,
1862,
304,
267,
1177,
275,
488,
267,
7269,
7536,
1366,
275,
959,
435,
2196,
14,
8393,
8,
16,
12,
959,
9,
267,
367,
284,
315,
1425,
8,
16,
12,
4233,
304,
288,
4673,
14,
14160,
8,
277,
855,
521,
2204,
9,
288,
862,
26,
355,
1177,
275,
291,
423,
3120,
4936,
363,
1069,
8,
765,
354,
12,
1862,
9,
355,
4673,
14,
14160,
8,
16,
9,
355,
2059,
288,
871,
2186,
26,
355,
340,
291,
855,
7154,
16272,
26,
2116,
340,
394,
364,
10647,
14,
374,
1084,
837,
490,
746,
869,
364,
10647,
1726,
342,
2116,
900,
14,
4532,
8,
7154,
7536,
1366,
9,
355,
587,
26,
2116,
746,
2186,
480,
72,
364,
12297,
3041,
6372,
531,
398,
372,
1177,
326,
272,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
327,
10628,
1083,
17475,
267,
372,
19122,
423,
3767,
8,
277,
855,
1069,
12,
536,
9,
1169,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
asajeffrey/servo
|
tests/power/PowerMeasure.py
|
5
|
7013
|
#!/usr/bin/env python
# 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 https://mozilla.org/MPL/2.0/.
# ---------Power measurement ------------------------------#
# This script will run the servo with the given benchmark and
# get the power usage using Powermetrics. Results will be put
# in sperate files with that name.
# Do not forget to run the script in servo/tests/power folder
# --------------------------------------------------------#
from __future__ import print_function, unicode_literals
import os
from os import path
import time
import argparse
# ------------------------PowerCollector----------------------------#
# Collecting all the power data and put them into files
TOP_DIR = path.join("..", "..")
def PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer):
print("Running the power collector")
power_dir = path.join(OutputDir, "power")
time_dir = path.join(OutputDir, "time")
etc_dir = path.join(OutputDir, "etc")
for d in [power_dir, time_dir, etc_dir]:
os.mkdir(d)
SleepTime = 20
GuardTime = 0.5
powerTiming = 1
ExperimentNum = 21
for ExpNum in range(1, ExperimentNum):
for layoutT in range(1, LayoutThreads + 1):
print(" layoutT=%d ExpNum=%d" % (layoutT, ExpNum))
PowerFiles = path.join(
power_dir, "power-Layout%d-set%d.csv" % (layoutT, ExpNum))
TimeFiles = path.join(
time_dir, "time-Layout%d-set%d.csv" % (layoutT, ExpNum))
ServoCmd = "(time ../../target/release/servo -x -y %d %s %s) 2> %s" % \
(layoutT, Renderer, Benchmarks, TimeFiles)
Metrics = path.join(
etc_dir, "metrics-Layout%d-set%d-css.csv" % (layoutT, ExpNum))
cmd = "(sudo powermetrics -i %d | " \
"grep \"energy\\|elapsed\\|servo\" > %s &_) 2> %s" % \
(powerTiming, PowerFiles, Metrics)
time.sleep(SleepTime)
os.system(cmd)
time.sleep(GuardTime)
os.system(ServoCmd)
time.sleep(GuardTime)
os.system('sudo pkill -9 powermetrics')
time.sleep(SleepTime)
# -------------------PowerParser ---------------------------------#
# Parsing collected power by PowerCollector fucntion
def PowerParser(OutputDir, LayoutThreads):
print("Running the PowerParser")
ExperimentNum = 21
ResultTable = OutputDir + "ResultTable.csv"
ResultFile = open(ResultTable, "w")
ResultFile.write("LayoutThreads, MeanPower, MaxPower , MinPower, MeanTime , MaxTime, "
"MinTime \n")
for layoutT in range(1, LayoutThreads + 1):
MaxTime = 0
MinTime = 1000000
MaxPower = 0
MinPower = 1000000
TotalPower = 0
TotalTime = 0
TimeGen = 0
PowerGen = 0
for ExpNum in range(1, ExperimentNum):
print(" layoutT=%d ExpNum=%d" % (layoutT, ExpNum))
Files = path.join(
OutputDir, "power", "power-Layout%d-set%d.csv" %
(layoutT, ExpNum))
NewFile = path.join(OutputDir, "power", "Servo-Layout%d-set%d.csv" %
(layoutT, ExpNum))
File = open(Files, 'r')
PowerFile = open(NewFile, 'w')
TimeFiles = path.join(OutputDir, "time", "time-Layout%d-set%d.csv" %
(layoutT, ExpNum))
# ----Putting the power the power and its time into a table---- #
for line in File:
words = line.split()
if words[0] == "***":
insertingWord = words[10][1:-2] + " "
elif words[0] == "Intel":
insertingWord += words[7][:-1]
insertingWord += "\n"
PowerFile.write(insertingWord)
File.close()
PowerFile.close()
# ---------------geting the total power of experiments-------- #
TempFile = open(NewFile, 'r')
Power = 0
for line in TempFile:
words2 = line.split()
Power += float(words2[0]) * float(words2[1])
TotalPower = float(Power / 1000.0)
if TotalPower > MaxPower:
MaxPower = TotalPower
if TotalPower < MinPower:
MinPower = TotalPower
# -------------getting the total time of execution---------- #
TempFile2 = open(TimeFiles, "r")
for line in TempFile2:
words3 = line.split()
if line != "\n" and words3[0] == "real":
TotalTime = (float(words3[1][0]) * 60) + \
float(words3[1][2:-1])
if TotalTime > MaxTime:
MaxTime = TotalTime
if TotalTime < MinTime:
MinTime = TotalTime
TimeGen = TimeGen + TotalTime
PowerGen = PowerGen + TotalPower
TotalPower = PowerGen / float(ExperimentNum - 1)
TotalTime = TimeGen / float(ExperimentNum - 1)
ResultFile.write(str(layoutT) + " , " + str(TotalPower) + " , "
+ str(MaxPower) + " , " + str(MinPower) + " , "
+ str(TotalTime) + " , " + str(MaxTime) + " , "
+ str(MinTime) + "\n")
ResultFile.close()
Opener = ResultFile = open(ResultTable, "r")
for line in Opener:
print(line)
print("Also you can find all the numbers for Power "
"and Performance in : ", ResultTable)
# ----------------------------------------------------#
def main():
LayoutThreads = 8 # Maximum number of threads considered for Layout
Benchmarks = path.join(TOP_DIR, "tests", "html", "perf-rainbow.html")
OutputDir = "Experiments"
os.mkdir(OutputDir)
Renderer = ""
# Parsing the input of the script
parser = argparse.ArgumentParser(description="Measuring \
power and performance of your Servo runs")
parser.add_argument("-b", "--benchmark", help="Gets the \
benchmark, for example \"-B perf-rainbow.html\"")
parser.add_argument("-c", "--CPU", help="Rendering with \
CPU instead of GPU, for example -C")
parser.add_argument("-l", "--LayoutThreads", help="Specify \
the maximum number of threads for layout, for example \" -L 5\"")
parser.add_argument("-o", "--Output", help="Specify \
the output directory")
args = parser.parse_args()
if args.benchmark:
Benchmarks = args.benchmark
if args.CPU:
Renderer = "-c"
if args.LayoutThreads:
LayoutThreads = int(args.LayoutThreads)
if args.Output:
OutputDir = args.Output
PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer)
PowerParser(OutputDir, LayoutThreads)
if __name__ == "__main__":
main()
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
4178,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
421,
199,
3,
3001,
13,
6921,
18216,
10652,
10965,
3,
199,
3,
961,
2884,
911,
1255,
314,
8926,
2392,
543,
314,
1627,
12338,
436,
199,
3,
664,
314,
7074,
4503,
1808,
18879,
6759,
14,
24288,
911,
506,
5324,
199,
3,
315,
308,
529,
323,
1584,
543,
626,
536,
14,
199,
3,
4226,
440,
19459,
370,
1255,
314,
2884,
315,
8926,
2392,
15,
2219,
15,
5652,
4922,
199,
3,
9527,
518,
3,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
504,
747,
492,
931,
199,
646,
900,
199,
646,
7534,
199,
199,
3,
10652,
518,
6921,
12852,
777,
4559,
3,
199,
3,
19649,
316,
1006,
314,
7074,
666,
436,
5324,
3062,
1901,
1584,
421,
199,
11422,
63,
3022,
275,
931,
14,
904,
480,
703,
401,
21777,
531,
421,
199,
318,
18879,
12852,
8,
2959,
3567,
12,
27067,
83,
12,
25604,
22785,
12,
10055,
5813,
304,
272,
870,
480,
9602,
314,
7074,
14910,
531,
272,
7074,
63,
694,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
5652,
531,
272,
900,
63,
694,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
521,
531,
272,
5423,
63,
694,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
6839,
531,
272,
367,
366,
315,
359,
5652,
63,
694,
12,
900,
63,
694,
12,
5423,
63,
694,
2189,
267,
747,
14,
8215,
8,
68,
9,
272,
428,
3614,
1366,
275,
3388,
272,
12436,
1005,
1366,
275,
378,
14,
21,
272,
7074,
30101,
275,
413,
272,
23997,
5667,
275,
7829,
272,
367,
7910,
5667,
315,
1425,
8,
17,
12,
23997,
5667,
304,
267,
367,
7054,
52,
315,
1425,
8,
17,
12,
25604,
22785,
435,
413,
304,
288,
870,
480,
221,
7054,
52,
2458,
68,
7910,
5667,
2458,
68,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
18879,
5535,
275,
931,
14,
904,
8,
355,
7074,
63,
694,
12,
298,
5652,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
4703,
5535,
275,
931,
14,
904,
8,
355,
900,
63,
694,
12,
298,
521,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
3739,
2392,
7874,
275,
7340,
521,
24272,
5093,
1375,
15,
3221,
15,
25943,
446,
88,
446,
89,
450,
68,
450,
83,
450,
83,
9,
499,
30,
450,
83,
2,
450,
971,
2432,
334,
4209,
52,
12,
10055,
5813,
12,
27067,
83,
12,
4703,
5535,
9,
288,
10072,
11818,
275,
931,
14,
904,
8,
355,
5423,
63,
694,
12,
298,
6759,
13,
4798,
5,
68,
13,
409,
5,
68,
13,
3919,
14,
4737,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
2088,
275,
7340,
12095,
7074,
6759,
446,
73,
450,
68,
1204,
298,
971,
2116,
298,
25914,
8441,
8443,
1103,
92,
16691,
1103,
92,
25943,
4451,
690,
450,
83,
1253,
4602,
499,
30,
450,
83,
2,
450,
971,
2116,
334,
5652,
30101,
12,
18879,
5535,
12,
10072,
11818,
9,
288,
900,
14,
4532,
8,
17306,
1366,
9,
288,
747,
14,
2253,
8,
1760,
9,
288,
900,
14,
4532,
8,
18183,
1366,
9,
288,
747,
14,
2253,
8,
1505,
2392,
7874,
9,
288,
900,
14,
4532,
8,
18183,
1366,
9,
288,
747,
14,
2253,
360,
12095,
3803,
778,
446,
25,
7074,
6759,
358,
288,
900,
14,
4532,
8,
17306,
1366,
9,
199,
199,
3,
10652,
2595,
6921,
2842,
11016,
8492,
199,
3,
28747,
13736,
7074,
701,
18879,
12852,
289,
947,
78,
296,
421,
199,
318,
18879,
2842,
8,
2959,
3567,
12,
25604,
22785,
304,
272,
870,
480,
9602,
314,
18879,
2842,
531,
272,
23997,
5667,
275,
7829,
272,
10695,
3186,
275,
7242,
3567,
435,
298,
2889,
3186,
14,
4737,
2,
272,
10695,
1173,
275,
1551,
8,
2889,
3186,
12,
298,
87,
531,
272,
10695,
1173,
14,
952,
480,
4798,
22785,
12,
25136,
6921,
12,
8228,
6921,
2360,
10195,
6921,
12,
25136,
1366,
2360,
8228,
1366,
12,
298,
2151,
298,
4649,
1366,
221,
971,
78,
531,
339,
367,
7054,
52,
315,
1425,
8,
17,
12,
25604,
22785,
435,
413,
304,
267,
8228,
1366,
275,
378,
267,
10195,
1366,
275,
19492,
267,
8228,
6921,
275,
378,
267,
10195,
6921,
275,
19492,
267,
19271,
6921,
275,
378,
267,
19271,
1366,
275,
378,
267,
4703,
8168,
275,
378,
267,
18879,
8168,
275,
378,
267,
367,
7910,
5667,
315,
1425,
8,
17,
12,
23997,
5667,
304,
288,
870,
480,
221,
7054,
52,
2458,
68,
7910,
5667,
2458,
68,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
16920,
275,
931,
14,
904,
8,
355,
7242,
3567,
12,
298,
5652,
401,
298,
5652,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
355,
334,
4209,
52,
12,
7910,
5667,
430,
288,
7053,
1173,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
5652,
401,
298,
1505,
2392,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
1816,
334,
4209,
52,
12,
7910,
5667,
430,
288,
3814,
275,
1551,
8,
5535,
12,
283,
82,
358,
288,
18879,
1173,
275,
1551,
8,
4665,
1173,
12,
283,
87,
358,
288,
4703,
5535,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
521,
401,
298,
521,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
3303,
334,
4209,
52,
12,
7910,
5667,
430,
288,
327,
4099,
18989,
1337,
314,
7074,
314,
7074,
436,
2399,
900,
1901,
282,
1817,
375,
327,
953,
367,
1004,
315,
3814,
26,
355,
5932,
275,
1004,
14,
1294,
342,
355,
340,
5932,
59,
16,
61,
508,
298,
9153,
582,
490,
28498,
10155,
275,
5932,
59,
709,
1527,
17,
6809,
18,
61,
435,
298,
298,
355,
916,
5932,
59,
16,
61,
508,
298,
27528,
582,
490,
28498,
10155,
847,
5932,
59,
23,
61,
4439
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
4178,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
421,
199,
3,
3001,
13,
6921,
18216,
10652,
10965,
3,
199,
3,
961,
2884,
911,
1255,
314,
8926,
2392,
543,
314,
1627,
12338,
436,
199,
3,
664,
314,
7074,
4503,
1808,
18879,
6759,
14,
24288,
911,
506,
5324,
199,
3,
315,
308,
529,
323,
1584,
543,
626,
536,
14,
199,
3,
4226,
440,
19459,
370,
1255,
314,
2884,
315,
8926,
2392,
15,
2219,
15,
5652,
4922,
199,
3,
9527,
518,
3,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
504,
747,
492,
931,
199,
646,
900,
199,
646,
7534,
199,
199,
3,
10652,
518,
6921,
12852,
777,
4559,
3,
199,
3,
19649,
316,
1006,
314,
7074,
666,
436,
5324,
3062,
1901,
1584,
421,
199,
11422,
63,
3022,
275,
931,
14,
904,
480,
703,
401,
21777,
531,
421,
199,
318,
18879,
12852,
8,
2959,
3567,
12,
27067,
83,
12,
25604,
22785,
12,
10055,
5813,
304,
272,
870,
480,
9602,
314,
7074,
14910,
531,
272,
7074,
63,
694,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
5652,
531,
272,
900,
63,
694,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
521,
531,
272,
5423,
63,
694,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
6839,
531,
272,
367,
366,
315,
359,
5652,
63,
694,
12,
900,
63,
694,
12,
5423,
63,
694,
2189,
267,
747,
14,
8215,
8,
68,
9,
272,
428,
3614,
1366,
275,
3388,
272,
12436,
1005,
1366,
275,
378,
14,
21,
272,
7074,
30101,
275,
413,
272,
23997,
5667,
275,
7829,
272,
367,
7910,
5667,
315,
1425,
8,
17,
12,
23997,
5667,
304,
267,
367,
7054,
52,
315,
1425,
8,
17,
12,
25604,
22785,
435,
413,
304,
288,
870,
480,
221,
7054,
52,
2458,
68,
7910,
5667,
2458,
68,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
18879,
5535,
275,
931,
14,
904,
8,
355,
7074,
63,
694,
12,
298,
5652,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
4703,
5535,
275,
931,
14,
904,
8,
355,
900,
63,
694,
12,
298,
521,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
3739,
2392,
7874,
275,
7340,
521,
24272,
5093,
1375,
15,
3221,
15,
25943,
446,
88,
446,
89,
450,
68,
450,
83,
450,
83,
9,
499,
30,
450,
83,
2,
450,
971,
2432,
334,
4209,
52,
12,
10055,
5813,
12,
27067,
83,
12,
4703,
5535,
9,
288,
10072,
11818,
275,
931,
14,
904,
8,
355,
5423,
63,
694,
12,
298,
6759,
13,
4798,
5,
68,
13,
409,
5,
68,
13,
3919,
14,
4737,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
2088,
275,
7340,
12095,
7074,
6759,
446,
73,
450,
68,
1204,
298,
971,
2116,
298,
25914,
8441,
8443,
1103,
92,
16691,
1103,
92,
25943,
4451,
690,
450,
83,
1253,
4602,
499,
30,
450,
83,
2,
450,
971,
2116,
334,
5652,
30101,
12,
18879,
5535,
12,
10072,
11818,
9,
288,
900,
14,
4532,
8,
17306,
1366,
9,
288,
747,
14,
2253,
8,
1760,
9,
288,
900,
14,
4532,
8,
18183,
1366,
9,
288,
747,
14,
2253,
8,
1505,
2392,
7874,
9,
288,
900,
14,
4532,
8,
18183,
1366,
9,
288,
747,
14,
2253,
360,
12095,
3803,
778,
446,
25,
7074,
6759,
358,
288,
900,
14,
4532,
8,
17306,
1366,
9,
199,
199,
3,
10652,
2595,
6921,
2842,
11016,
8492,
199,
3,
28747,
13736,
7074,
701,
18879,
12852,
289,
947,
78,
296,
421,
199,
318,
18879,
2842,
8,
2959,
3567,
12,
25604,
22785,
304,
272,
870,
480,
9602,
314,
18879,
2842,
531,
272,
23997,
5667,
275,
7829,
272,
10695,
3186,
275,
7242,
3567,
435,
298,
2889,
3186,
14,
4737,
2,
272,
10695,
1173,
275,
1551,
8,
2889,
3186,
12,
298,
87,
531,
272,
10695,
1173,
14,
952,
480,
4798,
22785,
12,
25136,
6921,
12,
8228,
6921,
2360,
10195,
6921,
12,
25136,
1366,
2360,
8228,
1366,
12,
298,
2151,
298,
4649,
1366,
221,
971,
78,
531,
339,
367,
7054,
52,
315,
1425,
8,
17,
12,
25604,
22785,
435,
413,
304,
267,
8228,
1366,
275,
378,
267,
10195,
1366,
275,
19492,
267,
8228,
6921,
275,
378,
267,
10195,
6921,
275,
19492,
267,
19271,
6921,
275,
378,
267,
19271,
1366,
275,
378,
267,
4703,
8168,
275,
378,
267,
18879,
8168,
275,
378,
267,
367,
7910,
5667,
315,
1425,
8,
17,
12,
23997,
5667,
304,
288,
870,
480,
221,
7054,
52,
2458,
68,
7910,
5667,
2458,
68,
2,
450,
334,
4209,
52,
12,
7910,
5667,
430,
288,
16920,
275,
931,
14,
904,
8,
355,
7242,
3567,
12,
298,
5652,
401,
298,
5652,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
355,
334,
4209,
52,
12,
7910,
5667,
430,
288,
7053,
1173,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
5652,
401,
298,
1505,
2392,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
1816,
334,
4209,
52,
12,
7910,
5667,
430,
288,
3814,
275,
1551,
8,
5535,
12,
283,
82,
358,
288,
18879,
1173,
275,
1551,
8,
4665,
1173,
12,
283,
87,
358,
288,
4703,
5535,
275,
931,
14,
904,
8,
2959,
3567,
12,
298,
521,
401,
298,
521,
13,
4798,
5,
68,
13,
409,
5,
68,
14,
4737,
2,
450,
3303,
334,
4209,
52,
12,
7910,
5667,
430,
288,
327,
4099,
18989,
1337,
314,
7074,
314,
7074,
436,
2399,
900,
1901,
282,
1817,
375,
327,
953,
367,
1004,
315,
3814,
26,
355,
5932,
275,
1004,
14,
1294,
342,
355,
340,
5932,
59,
16,
61,
508,
298,
9153,
582,
490,
28498,
10155,
275,
5932,
59,
709,
1527,
17,
6809,
18,
61,
435,
298,
298,
355,
916,
5932,
59,
16,
61,
508,
298,
27528,
582,
490,
28498,
10155,
847,
5932,
59,
23,
61,
4439,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ltilve/chromium
|
third_party/python_gflags/gflags.py
|
448
|
104236
|
#!/usr/bin/env python
#
# Copyright (c) 2002, 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.
#
# ---
# Author: Chad Lester
# Design and style contributions by:
# Amit Patel, Bogdan Cocosel, Daniel Dulitz, Eric Tiedemann,
# Eric Veach, Laurence Gonsalves, Matthew Springer
# Code reorganized a bit by Craig Silverstein
"""This module is used to define and parse command line flags.
This module defines a *distributed* flag-definition policy: rather than
an application having to define all flags in or near main(), each python
module defines flags that are useful to it. When one python module
imports another, it gains access to the other's flags. (This is
implemented by having all modules share a common, global registry object
containing all the flag information.)
Flags are defined through the use of one of the DEFINE_xxx functions.
The specific function used determines how the flag is parsed, checked,
and optionally type-converted, when it's seen on the command line.
IMPLEMENTATION: DEFINE_* creates a 'Flag' object and registers it with a
'FlagValues' object (typically the global FlagValues FLAGS, defined
here). The 'FlagValues' object can scan the command line arguments and
pass flag arguments to the corresponding 'Flag' objects for
value-checking and type conversion. The converted flag values are
available as attributes of the 'FlagValues' object.
Code can access the flag through a FlagValues object, for instance
gflags.FLAGS.myflag. Typically, the __main__ module passes the command
line arguments to gflags.FLAGS for parsing.
At bottom, this module calls getopt(), so getopt functionality is
supported, including short- and long-style flags, and the use of -- to
terminate flags.
Methods defined by the flag module will throw 'FlagsError' exceptions.
The exception argument will be a human-readable string.
FLAG TYPES: This is a list of the DEFINE_*'s that you can do. All flags
take a name, default value, help-string, and optional 'short' name
(one-letter name). Some flags have other arguments, which are described
with the flag.
DEFINE_string: takes any input, and interprets it as a string.
DEFINE_bool or
DEFINE_boolean: typically does not take an argument: say --myflag to
set FLAGS.myflag to true, or --nomyflag to set
FLAGS.myflag to false. Alternately, you can say
--myflag=true or --myflag=t or --myflag=1 or
--myflag=false or --myflag=f or --myflag=0
DEFINE_float: takes an input and interprets it as a floating point
number. Takes optional args lower_bound and upper_bound;
if the number specified on the command line is out of
range, it will raise a FlagError.
DEFINE_integer: takes an input and interprets it as an integer. Takes
optional args lower_bound and upper_bound as for floats.
DEFINE_enum: takes a list of strings which represents legal values. If
the command-line value is not in this list, raise a flag
error. Otherwise, assign to FLAGS.flag as a string.
DEFINE_list: Takes a comma-separated list of strings on the commandline.
Stores them in a python list object.
DEFINE_spaceseplist: Takes a space-separated list of strings on the
commandline. Stores them in a python list object.
Example: --myspacesepflag "foo bar baz"
DEFINE_multistring: The same as DEFINE_string, except the flag can be
specified more than once on the commandline. The
result is a python list object (list of strings),
even if the flag is only on the command line once.
DEFINE_multi_int: The same as DEFINE_integer, except the flag can be
specified more than once on the commandline. The
result is a python list object (list of ints), even if
the flag is only on the command line once.
SPECIAL FLAGS: There are a few flags that have special meaning:
--help prints a list of all the flags in a human-readable fashion
--helpshort prints a list of all key flags (see below).
--helpxml prints a list of all flags, in XML format. DO NOT parse
the output of --help and --helpshort. Instead, parse
the output of --helpxml. For more info, see
"OUTPUT FOR --helpxml" below.
--flagfile=foo read flags from file foo.
--undefok=f1,f2 ignore unrecognized option errors for f1,f2.
For boolean flags, you should use --undefok=boolflag, and
--boolflag and --noboolflag will be accepted. Do not use
--undefok=noboolflag.
-- as in getopt(), terminates flag-processing
FLAGS VALIDATORS: If your program:
- requires flag X to be specified
- needs flag Y to match a regular expression
- or requires any more general constraint to be satisfied
then validators are for you!
Each validator represents a constraint over one flag, which is enforced
starting from the initial parsing of the flags and until the program
terminates.
Also, lower_bound and upper_bound for numerical flags are enforced using flag
validators.
Howto:
If you want to enforce a constraint over one flag, use
gflags.RegisterValidator(flag_name,
checker,
message='Flag validation failed',
flag_values=FLAGS)
After flag values are initially parsed, and after any change to the specified
flag, method checker(flag_value) will be executed. If constraint is not
satisfied, an IllegalFlagValue exception will be raised. See
RegisterValidator's docstring for a detailed explanation on how to construct
your own checker.
EXAMPLE USAGE:
FLAGS = gflags.FLAGS
gflags.DEFINE_integer('my_version', 0, 'Version number.')
gflags.DEFINE_string('filename', None, 'Input file name', short_name='f')
gflags.RegisterValidator('my_version',
lambda value: value % 2 == 0,
message='--my_version must be divisible by 2')
gflags.MarkFlagAsRequired('filename')
NOTE ON --flagfile:
Flags may be loaded from text files in addition to being specified on
the commandline.
Any flags you don't feel like typing, throw them in a file, one flag per
line, for instance:
--myflag=myvalue
--nomyboolean_flag
You then specify your file with the special flag '--flagfile=somefile'.
You CAN recursively nest flagfile= tokens OR use multiple files on the
command line. Lines beginning with a single hash '#' or a double slash
'//' are comments in your flagfile.
Any flagfile=<file> will be interpreted as having a relative path from
the current working directory rather than from the place the file was
included from:
myPythonScript.py --flagfile=config/somefile.cfg
If somefile.cfg includes further --flagfile= directives, these will be
referenced relative to the original CWD, not from the directory the
including flagfile was found in!
The caveat applies to people who are including a series of nested files
in a different dir than they are executing out of. Relative path names
are always from CWD, not from the directory of the parent include
flagfile. We do now support '~' expanded directory names.
Absolute path names ALWAYS work!
EXAMPLE USAGE:
FLAGS = gflags.FLAGS
# Flag names are globally defined! So in general, we need to be
# careful to pick names that are unlikely to be used by other libraries.
# If there is a conflict, we'll get an error at import time.
gflags.DEFINE_string('name', 'Mr. President', 'your name')
gflags.DEFINE_integer('age', None, 'your age in years', lower_bound=0)
gflags.DEFINE_boolean('debug', False, 'produces debugging output')
gflags.DEFINE_enum('gender', 'male', ['male', 'female'], 'your gender')
def main(argv):
try:
argv = FLAGS(argv) # parse flags
except gflags.FlagsError, e:
print '%s\\nUsage: %s ARGS\\n%s' % (e, sys.argv[0], FLAGS)
sys.exit(1)
if FLAGS.debug: print 'non-flag arguments:', argv
print 'Happy Birthday', FLAGS.name
if FLAGS.age is not None:
print 'You are a %d year old %s' % (FLAGS.age, FLAGS.gender)
if __name__ == '__main__':
main(sys.argv)
KEY FLAGS:
As we already explained, each module gains access to all flags defined
by all the other modules it transitively imports. In the case of
non-trivial scripts, this means a lot of flags ... For documentation
purposes, it is good to identify the flags that are key (i.e., really
important) to a module. Clearly, the concept of "key flag" is a
subjective one. When trying to determine whether a flag is key to a
module or not, assume that you are trying to explain your module to a
potential user: which flags would you really like to mention first?
We'll describe shortly how to declare which flags are key to a module.
For the moment, assume we know the set of key flags for each module.
Then, if you use the app.py module, you can use the --helpshort flag to
print only the help for the flags that are key to the main module, in a
human-readable format.
NOTE: If you need to parse the flag help, do NOT use the output of
--help / --helpshort. That output is meant for human consumption, and
may be changed in the future. Instead, use --helpxml; flags that are
key for the main module are marked there with a <key>yes</key> element.
The set of key flags for a module M is composed of:
1. Flags defined by module M by calling a DEFINE_* function.
2. Flags that module M explictly declares as key by using the function
DECLARE_key_flag(<flag_name>)
3. Key flags of other modules that M specifies by using the function
ADOPT_module_key_flags(<other_module>)
This is a "bulk" declaration of key flags: each flag that is key for
<other_module> becomes key for the current module too.
Notice that if you do not use the functions described at points 2 and 3
above, then --helpshort prints information only about the flags defined
by the main module of our script. In many cases, this behavior is good
enough. But if you move part of the main module code (together with the
related flags) into a different module, then it is nice to use
DECLARE_key_flag / ADOPT_module_key_flags and make sure --helpshort
lists all relevant flags (otherwise, your code refactoring may confuse
your users).
Note: each of DECLARE_key_flag / ADOPT_module_key_flags has its own
pluses and minuses: DECLARE_key_flag is more targeted and may lead a
more focused --helpshort documentation. ADOPT_module_key_flags is good
for cases when an entire module is considered key to the current script.
Also, it does not require updates to client scripts when a new flag is
added to the module.
EXAMPLE USAGE 2 (WITH KEY FLAGS):
Consider an application that contains the following three files (two
auxiliary modules and a main module)
File libfoo.py:
import gflags
gflags.DEFINE_integer('num_replicas', 3, 'Number of replicas to start')
gflags.DEFINE_boolean('rpc2', True, 'Turn on the usage of RPC2.')
... some code ...
File libbar.py:
import gflags
gflags.DEFINE_string('bar_gfs_path', '/gfs/path',
'Path to the GFS files for libbar.')
gflags.DEFINE_string('email_for_bar_errors', 'bar-team@google.com',
'Email address for bug reports about module libbar.')
gflags.DEFINE_boolean('bar_risky_hack', False,
'Turn on an experimental and buggy optimization.')
... some code ...
File myscript.py:
import gflags
import libfoo
import libbar
gflags.DEFINE_integer('num_iterations', 0, 'Number of iterations.')
# Declare that all flags that are key for libfoo are
# key for this module too.
gflags.ADOPT_module_key_flags(libfoo)
# Declare that the flag --bar_gfs_path (defined in libbar) is key
# for this module.
gflags.DECLARE_key_flag('bar_gfs_path')
... some code ...
When myscript is invoked with the flag --helpshort, the resulted help
message lists information about all the key flags for myscript:
--num_iterations, --num_replicas, --rpc2, and --bar_gfs_path.
Of course, myscript uses all the flags declared by it (in this case,
just --num_replicas) or by any of the modules it transitively imports
(e.g., the modules libfoo, libbar). E.g., it can access the value of
FLAGS.bar_risky_hack, even if --bar_risky_hack is not declared as a key
flag for myscript.
OUTPUT FOR --helpxml:
The --helpxml flag generates output with the following structure:
<?xml version="1.0"?>
<AllFlags>
<program>PROGRAM_BASENAME</program>
<usage>MAIN_MODULE_DOCSTRING</usage>
(<flag>
[<key>yes</key>]
<file>DECLARING_MODULE</file>
<name>FLAG_NAME</name>
<meaning>FLAG_HELP_MESSAGE</meaning>
<default>DEFAULT_FLAG_VALUE</default>
<current>CURRENT_FLAG_VALUE</current>
<type>FLAG_TYPE</type>
[OPTIONAL_ELEMENTS]
</flag>)*
</AllFlags>
Notes:
1. The output is intentionally similar to the output generated by the
C++ command-line flag library. The few differences are due to the
Python flags that do not have a C++ equivalent (at least not yet),
e.g., DEFINE_list.
2. New XML elements may be added in the future.
3. DEFAULT_FLAG_VALUE is in serialized form, i.e., the string you can
pass for this flag on the command-line. E.g., for a flag defined
using DEFINE_list, this field may be foo,bar, not ['foo', 'bar'].
4. CURRENT_FLAG_VALUE is produced using str(). This means that the
string 'false' will be represented in the same way as the boolean
False. Using repr() would have removed this ambiguity and simplified
parsing, but would have broken the compatibility with the C++
command-line flags.
5. OPTIONAL_ELEMENTS describe elements relevant for certain kinds of
flags: lower_bound, upper_bound (for flags that specify bounds),
enum_value (for enum flags), list_separator (for flags that consist of
a list of values, separated by a special token).
6. We do not provide any example here: please use --helpxml instead.
This module requires at least python 2.2.1 to run.
"""
import cgi
import getopt
import os
import re
import string
import struct
import sys
# pylint: disable-msg=C6204
try:
import fcntl
except ImportError:
fcntl = None
try:
# Importing termios will fail on non-unix platforms.
import termios
except ImportError:
termios = None
import gflags_validators
# pylint: enable-msg=C6204
# Are we running under pychecker?
_RUNNING_PYCHECKER = 'pychecker.python' in sys.modules
def _GetCallingModuleObjectAndName():
"""Returns the module that's calling into this module.
We generally use this function to get the name of the module calling a
DEFINE_foo... function.
"""
# Walk down the stack to find the first globals dict that's not ours.
for depth in range(1, sys.getrecursionlimit()):
if not sys._getframe(depth).f_globals is globals():
globals_for_frame = sys._getframe(depth).f_globals
module, module_name = _GetModuleObjectAndName(globals_for_frame)
if module_name is not None:
return module, module_name
raise AssertionError("No module was found")
def _GetCallingModule():
"""Returns the name of the module that's calling into this module."""
return _GetCallingModuleObjectAndName()[1]
def _GetThisModuleObjectAndName():
"""Returns: (module object, module name) for this module."""
return _GetModuleObjectAndName(globals())
# module exceptions:
class FlagsError(Exception):
"""The base class for all flags errors."""
pass
class DuplicateFlag(FlagsError):
"""Raised if there is a flag naming conflict."""
pass
class CantOpenFlagFileError(FlagsError):
"""Raised if flagfile fails to open: doesn't exist, wrong permissions, etc."""
pass
class DuplicateFlagCannotPropagateNoneToSwig(DuplicateFlag):
"""Special case of DuplicateFlag -- SWIG flag value can't be set to None.
This can be raised when a duplicate flag is created. Even if allow_override is
True, we still abort if the new value is None, because it's currently
impossible to pass None default value back to SWIG. See FlagValues.SetDefault
for details.
"""
pass
class DuplicateFlagError(DuplicateFlag):
"""A DuplicateFlag whose message cites the conflicting definitions.
A DuplicateFlagError conveys more information than a DuplicateFlag,
namely the modules where the conflicting definitions occur. This
class was created to avoid breaking external modules which depend on
the existing DuplicateFlags interface.
"""
def __init__(self, flagname, flag_values, other_flag_values=None):
"""Create a DuplicateFlagError.
Args:
flagname: Name of the flag being redefined.
flag_values: FlagValues object containing the first definition of
flagname.
other_flag_values: If this argument is not None, it should be the
FlagValues object where the second definition of flagname occurs.
If it is None, we assume that we're being called when attempting
to create the flag a second time, and we use the module calling
this one as the source of the second definition.
"""
self.flagname = flagname
first_module = flag_values.FindModuleDefiningFlag(
flagname, default='<unknown>')
if other_flag_values is None:
second_module = _GetCallingModule()
else:
second_module = other_flag_values.FindModuleDefiningFlag(
flagname, default='<unknown>')
msg = "The flag '%s' is defined twice. First from %s, Second from %s" % (
self.flagname, first_module, second_module)
DuplicateFlag.__init__(self, msg)
class IllegalFlagValue(FlagsError):
"""The flag command line argument is illegal."""
pass
class UnrecognizedFlag(FlagsError):
"""Raised if a flag is unrecognized."""
pass
# An UnrecognizedFlagError conveys more information than an UnrecognizedFlag.
# Since there are external modules that create DuplicateFlags, the interface to
# DuplicateFlag shouldn't change. The flagvalue will be assigned the full value
# of the flag and its argument, if any, allowing handling of unrecognized flags
# in an exception handler.
# If flagvalue is the empty string, then this exception is an due to a
# reference to a flag that was not already defined.
class UnrecognizedFlagError(UnrecognizedFlag):
def __init__(self, flagname, flagvalue=''):
self.flagname = flagname
self.flagvalue = flagvalue
UnrecognizedFlag.__init__(
self, "Unknown command line flag '%s'" % flagname)
# Global variable used by expvar
_exported_flags = {}
_help_width = 80 # width of help output
def GetHelpWidth():
"""Returns: an integer, the width of help lines that is used in TextWrap."""
if (not sys.stdout.isatty()) or (termios is None) or (fcntl is None):
return _help_width
try:
data = fcntl.ioctl(sys.stdout, termios.TIOCGWINSZ, '1234')
columns = struct.unpack('hh', data)[1]
# Emacs mode returns 0.
# Here we assume that any value below 40 is unreasonable
if columns >= 40:
return columns
# Returning an int as default is fine, int(int) just return the int.
return int(os.getenv('COLUMNS', _help_width))
except (TypeError, IOError, struct.error):
return _help_width
def CutCommonSpacePrefix(text):
"""Removes a common space prefix from the lines of a multiline text.
If the first line does not start with a space, it is left as it is and
only in the remaining lines a common space prefix is being searched
for. That means the first line will stay untouched. This is especially
useful to turn doc strings into help texts. This is because some
people prefer to have the doc comment start already after the
apostrophe and then align the following lines while others have the
apostrophes on a separate line.
The function also drops trailing empty lines and ignores empty lines
following the initial content line while calculating the initial
common whitespace.
Args:
text: text to work on
Returns:
the resulting text
"""
text_lines = text.splitlines()
# Drop trailing empty lines
while text_lines and not text_lines[-1]:
text_lines = text_lines[:-1]
if text_lines:
# We got some content, is the first line starting with a space?
if text_lines[0] and text_lines[0][0].isspace():
text_first_line = []
else:
text_first_line = [text_lines.pop(0)]
# Calculate length of common leading whitespace (only over content lines)
common_prefix = os.path.commonprefix([line for line in text_lines if line])
space_prefix_len = len(common_prefix) - len(common_prefix.lstrip())
# If we have a common space prefix, drop it from all lines
if space_prefix_len:
for index in xrange(len(text_lines)):
if text_lines[index]:
text_lines[index] = text_lines[index][space_prefix_len:]
return '\n'.join(text_first_line + text_lines)
return ''
def TextWrap(text, length=None, indent='', firstline_indent=None, tabs=' '):
"""Wraps a given text to a maximum line length and returns it.
We turn lines that only contain whitespace into empty lines. We keep
new lines and tabs (e.g., we do not treat tabs as spaces).
Args:
text: text to wrap
length: maximum length of a line, includes indentation
if this is None then use GetHelpWidth()
indent: indent for all but first line
firstline_indent: indent for first line; if None, fall back to indent
tabs: replacement for tabs
Returns:
wrapped text
Raises:
FlagsError: if indent not shorter than length
FlagsError: if firstline_indent not shorter than length
"""
# Get defaults where callee used None
if length is None:
length = GetHelpWidth()
if indent is None:
indent = ''
if len(indent) >= length:
raise FlagsError('Indent must be shorter than length')
# In line we will be holding the current line which is to be started
# with indent (or firstline_indent if available) and then appended
# with words.
if firstline_indent is None:
firstline_indent = ''
line = indent
else:
line = firstline_indent
if len(firstline_indent) >= length:
raise FlagsError('First line indent must be shorter than length')
# If the callee does not care about tabs we simply convert them to
# spaces If callee wanted tabs to be single space then we do that
# already here.
if not tabs or tabs == ' ':
text = text.replace('\t', ' ')
else:
tabs_are_whitespace = not tabs.strip()
line_regex = re.compile('([ ]*)(\t*)([^ \t]+)', re.MULTILINE)
# Split the text into lines and the lines with the regex above. The
# resulting lines are collected in result[]. For each split we get the
# spaces, the tabs and the next non white space (e.g. next word).
result = []
for text_line in text.splitlines():
# Store result length so we can find out whether processing the next
# line gave any new content
old_result_len = len(result)
# Process next line with line_regex. For optimization we do an rstrip().
# - process tabs (changes either line or word, see below)
# - process word (first try to squeeze on line, then wrap or force wrap)
# Spaces found on the line are ignored, they get added while wrapping as
# needed.
for spaces, current_tabs, word in line_regex.findall(text_line.rstrip()):
# If tabs weren't converted to spaces, handle them now
if current_tabs:
# If the last thing we added was a space anyway then drop
# it. But let's not get rid of the indentation.
if (((result and line != indent) or
(not result and line != firstline_indent)) and line[-1] == ' '):
line = line[:-1]
# Add the tabs, if that means adding whitespace, just add it at
# the line, the rstrip() code while shorten the line down if
# necessary
if tabs_are_whitespace:
line += tabs * len(current_tabs)
else:
# if not all tab replacement is whitespace we prepend it to the word
word = tabs * len(current_tabs) + word
# Handle the case where word cannot be squeezed onto current last line
if len(line) + len(word) > length and len(indent) + len(word) <= length:
result.append(line.rstrip())
line = indent + word
word = ''
# No space left on line or can we append a space?
if len(line) + 1 >= length:
result.append(line.rstrip())
line = indent
else:
line += ' '
# Add word and shorten it up to allowed line length. Restart next
# line with indent and repeat, or add a space if we're done (word
# finished) This deals with words that cannot fit on one line
# (e.g. indent + word longer than allowed line length).
while len(line) + len(word) >= length:
line += word
result.append(line[:length])
word = line[length:]
line = indent
# Default case, simply append the word and a space
if word:
line += word + ' '
# End of input line. If we have content we finish the line. If the
# current line is just the indent but we had content in during this
# original line then we need to add an empty line.
if (result and line != indent) or (not result and line != firstline_indent):
result.append(line.rstrip())
elif len(result) == old_result_len:
result.append('')
line = indent
return '\n'.join(result)
def DocToHelp(doc):
"""Takes a __doc__ string and reformats it as help."""
# Get rid of starting and ending white space. Using lstrip() or even
# strip() could drop more than maximum of first line and right space
# of last line.
doc = doc.strip()
# Get rid of all empty lines
whitespace_only_line = re.compile('^[ \t]+$', re.M)
doc = whitespace_only_line.sub('', doc)
# Cut out common space at line beginnings
doc = CutCommonSpacePrefix(doc)
# Just like this module's comment, comments tend to be aligned somehow.
# In other words they all start with the same amount of white space
# 1) keep double new lines
# 2) keep ws after new lines if not empty line
# 3) all other new lines shall be changed to a space
# Solution: Match new lines between non white space and replace with space.
doc = re.sub('(?<=\S)\n(?=\S)', ' ', doc, re.M)
return doc
def _GetModuleObjectAndName(globals_dict):
"""Returns the module that defines a global environment, and its name.
Args:
globals_dict: A dictionary that should correspond to an environment
providing the values of the globals.
Returns:
A pair consisting of (1) module object and (2) module name (a
string). Returns (None, None) if the module could not be
identified.
"""
# The use of .items() (instead of .iteritems()) is NOT a mistake: if
# a parallel thread imports a module while we iterate over
# .iteritems() (not nice, but possible), we get a RuntimeError ...
# Hence, we use the slightly slower but safer .items().
for name, module in sys.modules.items():
if getattr(module, '__dict__', None) is globals_dict:
if name == '__main__':
# Pick a more informative name for the main module.
name = sys.argv[0]
return (module, name)
return (None, None)
def _GetMainModule():
"""Returns: string, name of the module from which execution started."""
# First, try to use the same logic used by _GetCallingModuleObjectAndName(),
# i.e., call _GetModuleObjectAndName(). For that we first need to
# find the dictionary that the main module uses to store the
# globals.
#
# That's (normally) the same dictionary object that the deepest
# (oldest) stack frame is using for globals.
deepest_frame = sys._getframe(0)
while deepest_frame.f_back is not None:
deepest_frame = deepest_frame.f_back
globals_for_main_module = deepest_frame.f_globals
main_module_name = _GetModuleObjectAndName(globals_for_main_module)[1]
# The above strategy fails in some cases (e.g., tools that compute
# code coverage by redefining, among other things, the main module).
# If so, just use sys.argv[0]. We can probably always do this, but
# it's safest to try to use the same logic as _GetCallingModuleObjectAndName()
if main_module_name is None:
main_module_name = sys.argv[0]
return main_module_name
class FlagValues:
"""Registry of 'Flag' objects.
A 'FlagValues' can then scan command line arguments, passing flag
arguments through to the 'Flag' objects that it owns. It also
provides easy access to the flag values. Typically only one
'FlagValues' object is needed by an application: gflags.FLAGS
This class is heavily overloaded:
'Flag' objects are registered via __setitem__:
FLAGS['longname'] = x # register a new flag
The .value attribute of the registered 'Flag' objects can be accessed
as attributes of this 'FlagValues' object, through __getattr__. Both
the long and short name of the original 'Flag' objects can be used to
access its value:
FLAGS.longname # parsed flag value
FLAGS.x # parsed flag value (short name)
Command line arguments are scanned and passed to the registered 'Flag'
objects through the __call__ method. Unparsed arguments, including
argv[0] (e.g. the program name) are returned.
argv = FLAGS(sys.argv) # scan command line arguments
The original registered Flag objects can be retrieved through the use
of the dictionary-like operator, __getitem__:
x = FLAGS['longname'] # access the registered Flag object
The str() operator of a 'FlagValues' object provides help for all of
the registered 'Flag' objects.
"""
def __init__(self):
# Since everything in this class is so heavily overloaded, the only
# way of defining and using fields is to access __dict__ directly.
# Dictionary: flag name (string) -> Flag object.
self.__dict__['__flags'] = {}
# Dictionary: module name (string) -> list of Flag objects that are defined
# by that module.
self.__dict__['__flags_by_module'] = {}
# Dictionary: module id (int) -> list of Flag objects that are defined by
# that module.
self.__dict__['__flags_by_module_id'] = {}
# Dictionary: module name (string) -> list of Flag objects that are
# key for that module.
self.__dict__['__key_flags_by_module'] = {}
# Set if we should use new style gnu_getopt rather than getopt when parsing
# the args. Only possible with Python 2.3+
self.UseGnuGetOpt(False)
def UseGnuGetOpt(self, use_gnu_getopt=True):
"""Use GNU-style scanning. Allows mixing of flag and non-flag arguments.
See http://docs.python.org/library/getopt.html#getopt.gnu_getopt
Args:
use_gnu_getopt: wether or not to use GNU style scanning.
"""
self.__dict__['__use_gnu_getopt'] = use_gnu_getopt
def IsGnuGetOpt(self):
return self.__dict__['__use_gnu_getopt']
def FlagDict(self):
return self.__dict__['__flags']
def FlagsByModuleDict(self):
"""Returns the dictionary of module_name -> list of defined flags.
Returns:
A dictionary. Its keys are module names (strings). Its values
are lists of Flag objects.
"""
return self.__dict__['__flags_by_module']
def FlagsByModuleIdDict(self):
"""Returns the dictionary of module_id -> list of defined flags.
Returns:
A dictionary. Its keys are module IDs (ints). Its values
are lists of Flag objects.
"""
return self.__dict__['__flags_by_module_id']
def KeyFlagsByModuleDict(self):
"""Returns the dictionary of module_name -> list of key flags.
Returns:
A dictionary. Its keys are module names (strings). Its values
are lists of Flag objects.
"""
return self.__dict__['__key_flags_by_module']
def _RegisterFlagByModule(self, module_name, flag):
"""Records the module that defines a specific flag.
We keep track of which flag is defined by which module so that we
can later sort the flags by module.
Args:
module_name: A string, the name of a Python module.
flag: A Flag object, a flag that is key to the module.
"""
flags_by_module = self.FlagsByModuleDict()
flags_by_module.setdefault(module_name, []).append(flag)
def _RegisterFlagByModuleId(self, module_id, flag):
"""Records the module that defines a specific flag.
Args:
module_id: An int, the ID of the Python module.
flag: A Flag object, a flag that is key to the module.
"""
flags_by_module_id = self.FlagsByModuleIdDict()
flags_by_module_id.setdefault(module_id, []).append(flag)
def _RegisterKeyFlagForModule(self, module_name, flag):
"""Specifies that a flag is a key flag for a module.
Args:
module_name: A string, the name of a Python module.
flag: A Flag object, a flag that is key to the module.
"""
key_flags_by_module = self.KeyFlagsByModuleDict()
# The list of key flags for the module named module_name.
key_flags = key_flags_by_module.setdefault(module_name, [])
# Add flag, but avoid duplicates.
if flag not in key_flags:
key_flags.append(flag)
def _GetFlagsDefinedByModule(self, module):
"""Returns the list of flags defined by a module.
Args:
module: A module object or a module name (a string).
Returns:
A new list of Flag objects. Caller may update this list as he
wishes: none of those changes will affect the internals of this
FlagValue object.
"""
if not isinstance(module, str):
module = module.__name__
return list(self.FlagsByModuleDict().get(module, []))
def _GetKeyFlagsForModule(self, module):
"""Returns the list of key flags for a module.
Args:
module: A module object or a module name (a string)
Returns:
A new list of Flag objects. Caller may update this list as he
wishes: none of those changes will affect the internals of this
FlagValue object.
"""
if not isinstance(module, str):
module = module.__name__
# Any flag is a key flag for the module that defined it. NOTE:
# key_flags is a fresh list: we can update it without affecting the
# internals of this FlagValues object.
key_flags = self._GetFlagsDefinedByModule(module)
# Take into account flags explicitly declared as key for a module.
for flag in self.KeyFlagsByModuleDict().get(module, []):
if flag not in key_flags:
key_flags.append(flag)
return key_flags
def FindModuleDefiningFlag(self, flagname, default=None):
"""Return the name of the module defining this flag, or default.
Args:
flagname: Name of the flag to lookup.
default: Value to return if flagname is not defined. Defaults
to None.
Returns:
The name of the module which registered the flag with this name.
If no such module exists (i.e. no flag with this name exists),
we return default.
"""
for module, flags in self.FlagsByModuleDict().iteritems():
for flag in flags:
if flag.name == flagname or flag.short_name == flagname:
return module
return default
def FindModuleIdDefiningFlag(self, flagname, default=None):
"""Return the ID of the module defining this flag, or default.
Args:
flagname: Name of the flag to lookup.
default: Value to return if flagname is not defined. Defaults
to None.
Returns:
The ID of the module which registered the flag with this name.
If no such module exists (i.e. no flag with this name exists),
we return default.
"""
for module_id, flags in self.FlagsByModuleIdDict().iteritems():
for flag in flags:
if flag.name == flagname or flag.short_name == flagname:
return module_id
return default
def AppendFlagValues(self, flag_values):
"""Appends flags registered in another FlagValues instance.
Args:
flag_values: registry to copy from
"""
for flag_name, flag in flag_values.FlagDict().iteritems():
# Each flags with shortname appears here twice (once under its
# normal name, and again with its short name). To prevent
# problems (DuplicateFlagError) with double flag registration, we
# perform a check to make sure that the entry we're looking at is
# for its normal name.
if flag_name == flag.name:
try:
self[flag_name] = flag
except DuplicateFlagError:
raise DuplicateFlagError(flag_name, self,
other_flag_values=flag_values)
def RemoveFlagValues(self, flag_values):
"""Remove flags that were previously appended from another FlagValues.
Args:
flag_values: registry containing flags to remove.
"""
for flag_name in flag_values.FlagDict():
self.__delattr__(flag_name)
def __setitem__(self, name, flag):
"""Registers a new flag variable."""
fl = self.FlagDict()
if not isinstance(flag, Flag):
raise IllegalFlagValue(flag)
if not isinstance(name, type("")):
raise FlagsError("Flag name must be a string")
if len(name) == 0:
raise FlagsError("Flag name cannot be empty")
# If running under pychecker, duplicate keys are likely to be
# defined. Disable check for duplicate keys when pycheck'ing.
if (name in fl and not flag.allow_override and
not fl[name].allow_override and not _RUNNING_PYCHECKER):
module, module_name = _GetCallingModuleObjectAndName()
if (self.FindModuleDefiningFlag(name) == module_name and
id(module) != self.FindModuleIdDefiningFlag(name)):
# If the flag has already been defined by a module with the same name,
# but a different ID, we can stop here because it indicates that the
# module is simply being imported a subsequent time.
return
raise DuplicateFlagError(name, self)
short_name = flag.short_name
if short_name is not None:
if (short_name in fl and not flag.allow_override and
not fl[short_name].allow_override and not _RUNNING_PYCHECKER):
raise DuplicateFlagError(short_name, self)
fl[short_name] = flag
fl[name] = flag
global _exported_flags
_exported_flags[name] = flag
def __getitem__(self, name):
"""Retrieves the Flag object for the flag --name."""
return self.FlagDict()[name]
def __getattr__(self, name):
"""Retrieves the 'value' attribute of the flag --name."""
fl = self.FlagDict()
if name not in fl:
raise AttributeError(name)
return fl[name].value
def __setattr__(self, name, value):
"""Sets the 'value' attribute of the flag --name."""
fl = self.FlagDict()
fl[name].value = value
self._AssertValidators(fl[name].validators)
return value
def _AssertAllValidators(self):
all_validators = set()
for flag in self.FlagDict().itervalues():
for validator in flag.validators:
all_validators.add(validator)
self._AssertValidators(all_validators)
def _AssertValidators(self, validators):
"""Assert if all validators in the list are satisfied.
Asserts validators in the order they were created.
Args:
validators: Iterable(gflags_validators.Validator), validators to be
verified
Raises:
AttributeError: if validators work with a non-existing flag.
IllegalFlagValue: if validation fails for at least one validator
"""
for validator in sorted(
validators, key=lambda validator: validator.insertion_index):
try:
validator.Verify(self)
except gflags_validators.Error, e:
message = validator.PrintFlagsWithValues(self)
raise IllegalFlagValue('%s: %s' % (message, str(e)))
def _FlagIsRegistered(self, flag_obj):
"""Checks whether a Flag object is registered under some name.
Note: this is non trivial: in addition to its normal name, a flag
may have a short name too. In self.FlagDict(), both the normal and
the short name are mapped to the same flag object. E.g., calling
only "del FLAGS.short_name" is not unregistering the corresponding
Flag object (it is still registered under the longer name).
Args:
flag_obj: A Flag object.
Returns:
A boolean: True iff flag_obj is registered under some name.
"""
flag_dict = self.FlagDict()
# Check whether flag_obj is registered under its long name.
name = flag_obj.name
if flag_dict.get(name, None) == flag_obj:
return True
# Check whether flag_obj is registered under its short name.
short_name = flag_obj.short_name
if (short_name is not None and
flag_dict.get(short_name, None) == flag_obj):
return True
# The flag cannot be registered under any other name, so we do not
# need to do a full search through the values of self.FlagDict().
return False
def __delattr__(self, flag_name):
"""Deletes a previously-defined flag from a flag object.
This method makes sure we can delete a flag by using
del flag_values_object.<flag_name>
E.g.,
gflags.DEFINE_integer('foo', 1, 'Integer flag.')
del gflags.FLAGS.foo
Args:
flag_name: A string, the name of the flag to be deleted.
Raises:
AttributeError: When there is no registered flag named flag_name.
"""
fl = self.FlagDict()
if flag_name not in fl:
raise AttributeError(flag_name)
flag_obj = fl[flag_name]
del fl[flag_name]
if not self._FlagIsRegistered(flag_obj):
# If the Flag object indicated by flag_name is no longer
# registered (please see the docstring of _FlagIsRegistered), then
# we delete the occurrences of the flag object in all our internal
# dictionaries.
self.__RemoveFlagFromDictByModule(self.FlagsByModuleDict(), flag_obj)
self.__RemoveFlagFromDictByModule(self.FlagsByModuleIdDict(), flag_obj)
self.__RemoveFlagFromDictByModule(self.KeyFlagsByModuleDict(), flag_obj)
def __RemoveFlagFromDictByModule(self, flags_by_module_dict, flag_obj):
"""Removes a flag object from a module -> list of flags dictionary.
Args:
flags_by_module_dict: A dictionary that maps module names to lists of
flags.
flag_obj: A flag object.
"""
for unused_module, flags_in_module in flags_by_module_dict.iteritems():
# while (as opposed to if) takes care of multiple occurrences of a
# flag in the list for the same module.
while flag_obj in flags_in_module:
flags_in_module.remove(flag_obj)
def SetDefault(self, name, value):
"""Changes the default value of the named flag object."""
fl = self.FlagDict()
if name not in fl:
raise AttributeError(name)
fl[name].SetDefault(value)
self._AssertValidators(fl[name].validators)
def __contains__(self, name):
"""Returns True if name is a value (flag) in the dict."""
return name in self.FlagDict()
has_key = __contains__ # a synonym for __contains__()
def __iter__(self):
return iter(self.FlagDict())
def __call__(self, argv):
"""Parses flags from argv; stores parsed flags into this FlagValues object.
All unparsed arguments are returned. Flags are parsed using the GNU
Program Argument Syntax Conventions, using getopt:
http://www.gnu.org/software/libc/manual/html_mono/libc.html#Getopt
Args:
argv: argument list. Can be of any type that may be converted to a list.
Returns:
The list of arguments not parsed as options, including argv[0]
Raises:
FlagsError: on any parsing error
"""
# Support any sequence type that can be converted to a list
argv = list(argv)
shortopts = ""
longopts = []
fl = self.FlagDict()
# This pre parses the argv list for --flagfile=<> options.
argv = argv[:1] + self.ReadFlagsFromFiles(argv[1:], force_gnu=False)
# Correct the argv to support the google style of passing boolean
# parameters. Boolean parameters may be passed by using --mybool,
# --nomybool, --mybool=(true|false|1|0). getopt does not support
# having options that may or may not have a parameter. We replace
# instances of the short form --mybool and --nomybool with their
# full forms: --mybool=(true|false).
original_argv = list(argv) # list() makes a copy
shortest_matches = None
for name, flag in fl.items():
if not flag.boolean:
continue
if shortest_matches is None:
# Determine the smallest allowable prefix for all flag names
shortest_matches = self.ShortestUniquePrefixes(fl)
no_name = 'no' + name
prefix = shortest_matches[name]
no_prefix = shortest_matches[no_name]
# Replace all occurrences of this boolean with extended forms
for arg_idx in range(1, len(argv)):
arg = argv[arg_idx]
if arg.find('=') >= 0: continue
if arg.startswith('--'+prefix) and ('--'+name).startswith(arg):
argv[arg_idx] = ('--%s=true' % name)
elif arg.startswith('--'+no_prefix) and ('--'+no_name).startswith(arg):
argv[arg_idx] = ('--%s=false' % name)
# Loop over all of the flags, building up the lists of short options
# and long options that will be passed to getopt. Short options are
# specified as a string of letters, each letter followed by a colon
# if it takes an argument. Long options are stored in an array of
# strings. Each string ends with an '=' if it takes an argument.
for name, flag in fl.items():
longopts.append(name + "=")
if len(name) == 1: # one-letter option: allow short flag type also
shortopts += name
if not flag.boolean:
shortopts += ":"
longopts.append('undefok=')
undefok_flags = []
# In case --undefok is specified, loop to pick up unrecognized
# options one by one.
unrecognized_opts = []
args = argv[1:]
while True:
try:
if self.__dict__['__use_gnu_getopt']:
optlist, unparsed_args = getopt.gnu_getopt(args, shortopts, longopts)
else:
optlist, unparsed_args = getopt.getopt(args, shortopts, longopts)
break
except getopt.GetoptError, e:
if not e.opt or e.opt in fl:
# Not an unrecognized option, re-raise the exception as a FlagsError
raise FlagsError(e)
# Remove offender from args and try again
for arg_index in range(len(args)):
if ((args[arg_index] == '--' + e.opt) or
(args[arg_index] == '-' + e.opt) or
(args[arg_index].startswith('--' + e.opt + '='))):
unrecognized_opts.append((e.opt, args[arg_index]))
args = args[0:arg_index] + args[arg_index+1:]
break
else:
# We should have found the option, so we don't expect to get
# here. We could assert, but raising the original exception
# might work better.
raise FlagsError(e)
for name, arg in optlist:
if name == '--undefok':
flag_names = arg.split(',')
undefok_flags.extend(flag_names)
# For boolean flags, if --undefok=boolflag is specified, then we should
# also accept --noboolflag, in addition to --boolflag.
# Since we don't know the type of the undefok'd flag, this will affect
# non-boolean flags as well.
# NOTE: You shouldn't use --undefok=noboolflag, because then we will
# accept --nonoboolflag here. We are choosing not to do the conversion
# from noboolflag -> boolflag because of the ambiguity that flag names
# can start with 'no'.
undefok_flags.extend('no' + name for name in flag_names)
continue
if name.startswith('--'):
# long option
name = name[2:]
short_option = 0
else:
# short option
name = name[1:]
short_option = 1
if name in fl:
flag = fl[name]
if flag.boolean and short_option: arg = 1
flag.Parse(arg)
# If there were unrecognized options, raise an exception unless
# the options were named via --undefok.
for opt, value in unrecognized_opts:
if opt not in undefok_flags:
raise UnrecognizedFlagError(opt, value)
if unparsed_args:
if self.__dict__['__use_gnu_getopt']:
# if using gnu_getopt just return the program name + remainder of argv.
ret_val = argv[:1] + unparsed_args
else:
# unparsed_args becomes the first non-flag detected by getopt to
# the end of argv. Because argv may have been modified above,
# return original_argv for this region.
ret_val = argv[:1] + original_argv[-len(unparsed_args):]
else:
ret_val = argv[:1]
self._AssertAllValidators()
return ret_val
def Reset(self):
"""Resets the values to the point before FLAGS(argv) was called."""
for f in self.FlagDict().values():
f.Unparse()
def RegisteredFlags(self):
"""Returns: a list of the names and short names of all registered flags."""
return list(self.FlagDict())
def FlagValuesDict(self):
"""Returns: a dictionary that maps flag names to flag values."""
flag_values = {}
for flag_name in self.RegisteredFlags():
flag = self.FlagDict()[flag_name]
flag_values[flag_name] = flag.value
return flag_values
def __str__(self):
"""Generates a help string for all known flags."""
return self.GetHelp()
def GetHelp(self, prefix=''):
"""Generates a help string for all known flags."""
helplist = []
flags_by_module = self.FlagsByModuleDict()
if flags_by_module:
modules = sorted(flags_by_module)
# Print the help for the main module first, if possible.
main_module = _GetMainModule()
if main_module in modules:
modules.remove(main_module)
modules = [main_module] + modules
for module in modules:
self.__RenderOurModuleFlags(module, helplist)
self.__RenderModuleFlags('gflags',
_SPECIAL_FLAGS.FlagDict().values(),
helplist)
else:
# Just print one long list of flags.
self.__RenderFlagList(
self.FlagDict().values() + _SPECIAL_FLAGS.FlagDict().values(),
helplist, prefix)
return '\n'.join(helplist)
def __RenderModuleFlags(self, module, flags, output_lines, prefix=""):
"""Generates a help string for a given module."""
if not isinstance(module, str):
module = module.__name__
output_lines.append('\n%s%s:' % (prefix, module))
self.__RenderFlagList(flags, output_lines, prefix + " ")
def __RenderOurModuleFlags(self, module, output_lines, prefix=""):
"""Generates a help string for a given module."""
flags = self._GetFlagsDefinedByModule(module)
if flags:
self.__RenderModuleFlags(module, flags, output_lines, prefix)
def __RenderOurModuleKeyFlags(self, module, output_lines, prefix=""):
"""Generates a help string for the key flags of a given module.
Args:
module: A module object or a module name (a string).
output_lines: A list of strings. The generated help message
lines will be appended to this list.
prefix: A string that is prepended to each generated help line.
"""
key_flags = self._GetKeyFlagsForModule(module)
if key_flags:
self.__RenderModuleFlags(module, key_flags, output_lines, prefix)
def ModuleHelp(self, module):
"""Describe the key flags of a module.
Args:
module: A module object or a module name (a string).
Returns:
string describing the key flags of a module.
"""
helplist = []
self.__RenderOurModuleKeyFlags(module, helplist)
return '\n'.join(helplist)
def MainModuleHelp(self):
"""Describe the key flags of the main module.
Returns:
string describing the key flags of a module.
"""
return self.ModuleHelp(_GetMainModule())
def __RenderFlagList(self, flaglist, output_lines, prefix=" "):
fl = self.FlagDict()
special_fl = _SPECIAL_FLAGS.FlagDict()
flaglist = [(flag.name, flag) for flag in flaglist]
flaglist.sort()
flagset = {}
for (name, flag) in flaglist:
# It's possible this flag got deleted or overridden since being
# registered in the per-module flaglist. Check now against the
# canonical source of current flag information, the FlagDict.
if fl.get(name, None) != flag and special_fl.get(name, None) != flag:
# a different flag is using this name now
continue
# only print help once
if flag in flagset: continue
flagset[flag] = 1
flaghelp = ""
if flag.short_name: flaghelp += "-%s," % flag.short_name
if flag.boolean:
flaghelp += "--[no]%s" % flag.name + ":"
else:
flaghelp += "--%s" % flag.name + ":"
flaghelp += " "
if flag.help:
flaghelp += flag.help
flaghelp = TextWrap(flaghelp, indent=prefix+" ",
firstline_indent=prefix)
if flag.default_as_str:
flaghelp += "\n"
flaghelp += TextWrap("(default: %s)" % flag.default_as_str,
indent=prefix+" ")
if flag.parser.syntactic_help:
flaghelp += "\n"
flaghelp += TextWrap("(%s)" % flag.parser.syntactic_help,
indent=prefix+" ")
output_lines.append(flaghelp)
def get(self, name, default):
"""Returns the value of a flag (if not None) or a default value.
Args:
name: A string, the name of a flag.
default: Default value to use if the flag value is None.
"""
value = self.__getattr__(name)
if value is not None: # Can't do if not value, b/c value might be '0' or ""
return value
else:
return default
def ShortestUniquePrefixes(self, fl):
"""Returns: dictionary; maps flag names to their shortest unique prefix."""
# Sort the list of flag names
sorted_flags = []
for name, flag in fl.items():
sorted_flags.append(name)
if flag.boolean:
sorted_flags.append('no%s' % name)
sorted_flags.sort()
# For each name in the sorted list, determine the shortest unique
# prefix by comparing itself to the next name and to the previous
# name (the latter check uses cached info from the previous loop).
shortest_matches = {}
prev_idx = 0
for flag_idx in range(len(sorted_flags)):
curr = sorted_flags[flag_idx]
if flag_idx == (len(sorted_flags) - 1):
next = None
else:
next = sorted_flags[flag_idx+1]
next_len = len(next)
for curr_idx in range(len(curr)):
if (next is None
or curr_idx >= next_len
or curr[curr_idx] != next[curr_idx]):
# curr longer than next or no more chars in common
shortest_matches[curr] = curr[:max(prev_idx, curr_idx) + 1]
prev_idx = curr_idx
break
else:
# curr shorter than (or equal to) next
shortest_matches[curr] = curr
prev_idx = curr_idx + 1 # next will need at least one more char
return shortest_matches
def __IsFlagFileDirective(self, flag_string):
"""Checks whether flag_string contain a --flagfile=<foo> directive."""
if isinstance(flag_string, type("")):
if flag_string.startswith('--flagfile='):
return 1
elif flag_string == '--flagfile':
return 1
elif flag_string.startswith('-flagfile='):
return 1
elif flag_string == '-flagfile':
return 1
else:
return 0
return 0
def ExtractFilename(self, flagfile_str):
"""Returns filename from a flagfile_str of form -[-]flagfile=filename.
The cases of --flagfile foo and -flagfile foo shouldn't be hitting
this function, as they are dealt with in the level above this
function.
"""
if flagfile_str.startswith('--flagfile='):
return os.path.expanduser((flagfile_str[(len('--flagfile=')):]).strip())
elif flagfile_str.startswith('-flagfile='):
return os.path.expanduser((flagfile_str[(len('-flagfile=')):]).strip())
else:
raise FlagsError('Hit illegal --flagfile type: %s' % flagfile_str)
def __GetFlagFileLines(self, filename, parsed_file_list):
"""Returns the useful (!=comments, etc) lines from a file with flags.
Args:
filename: A string, the name of the flag file.
parsed_file_list: A list of the names of the files we have
already read. MUTATED BY THIS FUNCTION.
Returns:
List of strings. See the note below.
NOTE(springer): This function checks for a nested --flagfile=<foo>
tag and handles the lower file recursively. It returns a list of
all the lines that _could_ contain command flags. This is
EVERYTHING except whitespace lines and comments (lines starting
with '#' or '//').
"""
line_list = [] # All line from flagfile.
flag_line_list = [] # Subset of lines w/o comments, blanks, flagfile= tags.
try:
file_obj = open(filename, 'r')
except IOError, e_msg:
raise CantOpenFlagFileError('ERROR:: Unable to open flagfile: %s' % e_msg)
line_list = file_obj.readlines()
file_obj.close()
parsed_file_list.append(filename)
# This is where we check each line in the file we just read.
for line in line_list:
if line.isspace():
pass
# Checks for comment (a line that starts with '#').
elif line.startswith('#') or line.startswith('//'):
pass
# Checks for a nested "--flagfile=<bar>" flag in the current file.
# If we find one, recursively parse down into that file.
elif self.__IsFlagFileDirective(line):
sub_filename = self.ExtractFilename(line)
# We do a little safety check for reparsing a file we've already done.
if not sub_filename in parsed_file_list:
included_flags = self.__GetFlagFileLines(sub_filename,
parsed_file_list)
flag_line_list.extend(included_flags)
else: # Case of hitting a circularly included file.
sys.stderr.write('Warning: Hit circular flagfile dependency: %s\n' %
(sub_filename,))
else:
# Any line that's not a comment or a nested flagfile should get
# copied into 2nd position. This leaves earlier arguments
# further back in the list, thus giving them higher priority.
flag_line_list.append(line.strip())
return flag_line_list
def ReadFlagsFromFiles(self, argv, force_gnu=True):
"""Processes command line args, but also allow args to be read from file.
Args:
argv: A list of strings, usually sys.argv[1:], which may contain one or
more flagfile directives of the form --flagfile="./filename".
Note that the name of the program (sys.argv[0]) should be omitted.
force_gnu: If False, --flagfile parsing obeys normal flag semantics.
If True, --flagfile parsing instead follows gnu_getopt semantics.
*** WARNING *** force_gnu=False may become the future default!
Returns:
A new list which has the original list combined with what we read
from any flagfile(s).
References: Global gflags.FLAG class instance.
This function should be called before the normal FLAGS(argv) call.
This function scans the input list for a flag that looks like:
--flagfile=<somefile>. Then it opens <somefile>, reads all valid key
and value pairs and inserts them into the input list between the
first item of the list and any subsequent items in the list.
Note that your application's flags are still defined the usual way
using gflags DEFINE_flag() type functions.
Notes (assuming we're getting a commandline of some sort as our input):
--> Flags from the command line argv _should_ always take precedence!
--> A further "--flagfile=<otherfile.cfg>" CAN be nested in a flagfile.
It will be processed after the parent flag file is done.
--> For duplicate flags, first one we hit should "win".
--> In a flagfile, a line beginning with # or // is a comment.
--> Entirely blank lines _should_ be ignored.
"""
parsed_file_list = []
rest_of_args = argv
new_argv = []
while rest_of_args:
current_arg = rest_of_args[0]
rest_of_args = rest_of_args[1:]
if self.__IsFlagFileDirective(current_arg):
# This handles the case of -(-)flagfile foo. In this case the
# next arg really is part of this one.
if current_arg == '--flagfile' or current_arg == '-flagfile':
if not rest_of_args:
raise IllegalFlagValue('--flagfile with no argument')
flag_filename = os.path.expanduser(rest_of_args[0])
rest_of_args = rest_of_args[1:]
else:
# This handles the case of (-)-flagfile=foo.
flag_filename = self.ExtractFilename(current_arg)
new_argv.extend(
self.__GetFlagFileLines(flag_filename, parsed_file_list))
else:
new_argv.append(current_arg)
# Stop parsing after '--', like getopt and gnu_getopt.
if current_arg == '--':
break
# Stop parsing after a non-flag, like getopt.
if not current_arg.startswith('-'):
if not force_gnu and not self.__dict__['__use_gnu_getopt']:
break
if rest_of_args:
new_argv.extend(rest_of_args)
return new_argv
def FlagsIntoString(self):
"""Returns a string with the flags assignments from this FlagValues object.
This function ignores flags whose value is None. Each flag
assignment is separated by a newline.
NOTE: MUST mirror the behavior of the C++ CommandlineFlagsIntoString
from http://code.google.com/p/google-gflags
"""
s = ''
for flag in self.FlagDict().values():
if flag.value is not None:
s += flag.Serialize() + '\n'
return s
def AppendFlagsIntoFile(self, filename):
"""Appends all flags assignments from this FlagInfo object to a file.
Output will be in the format of a flagfile.
NOTE: MUST mirror the behavior of the C++ AppendFlagsIntoFile
from http://code.google.com/p/google-gflags
"""
out_file = open(filename, 'a')
out_file.write(self.FlagsIntoString())
out_file.close()
def WriteHelpInXMLFormat(self, outfile=None):
"""Outputs flag documentation in XML format.
NOTE: We use element names that are consistent with those used by
the C++ command-line flag library, from
http://code.google.com/p/google-gflags
We also use a few new elements (e.g., <key>), but we do not
interfere / overlap with existing XML elements used by the C++
library. Please maintain this consistency.
Args:
outfile: File object we write to. Default None means sys.stdout.
"""
outfile = outfile or sys.stdout
outfile.write('<?xml version=\"1.0\"?>\n')
outfile.write('<AllFlags>\n')
indent = ' '
_WriteSimpleXMLElement(outfile, 'program', os.path.basename(sys.argv[0]),
indent)
usage_doc = sys.modules['__main__'].__doc__
if not usage_doc:
usage_doc = '\nUSAGE: %s [flags]\n' % sys.argv[0]
else:
usage_doc = usage_doc.replace('%s', sys.argv[0])
_WriteSimpleXMLElement(outfile, 'usage', usage_doc, indent)
# Get list of key flags for the main module.
key_flags = self._GetKeyFlagsForModule(_GetMainModule())
# Sort flags by declaring module name and next by flag name.
flags_by_module = self.FlagsByModuleDict()
all_module_names = list(flags_by_module.keys())
all_module_names.sort()
for module_name in all_module_names:
flag_list = [(f.name, f) for f in flags_by_module[module_name]]
flag_list.sort()
for unused_flag_name, flag in flag_list:
is_key = flag in key_flags
flag.WriteInfoInXMLFormat(outfile, module_name,
is_key=is_key, indent=indent)
outfile.write('</AllFlags>\n')
outfile.flush()
def AddValidator(self, validator):
"""Register new flags validator to be checked.
Args:
validator: gflags_validators.Validator
Raises:
AttributeError: if validators work with a non-existing flag.
"""
for flag_name in validator.GetFlagsNames():
flag = self.FlagDict()[flag_name]
flag.validators.append(validator)
# end of FlagValues definition
# The global FlagValues instance
FLAGS = FlagValues()
def _StrOrUnicode(value):
"""Converts value to a python string or, if necessary, unicode-string."""
try:
return str(value)
except UnicodeEncodeError:
return unicode(value)
def _MakeXMLSafe(s):
"""Escapes <, >, and & from s, and removes XML 1.0-illegal chars."""
s = cgi.escape(s) # Escape <, >, and &
# Remove characters that cannot appear in an XML 1.0 document
# (http://www.w3.org/TR/REC-xml/#charsets).
#
# NOTE: if there are problems with current solution, one may move to
# XML 1.1, which allows such chars, if they're entity-escaped (&#xHH;).
s = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f]', '', s)
# Convert non-ascii characters to entities. Note: requires python >=2.3
s = s.encode('ascii', 'xmlcharrefreplace') # u'\xce\x88' -> 'uΈ'
return s
def _WriteSimpleXMLElement(outfile, name, value, indent):
"""Writes a simple XML element.
Args:
outfile: File object we write the XML element to.
name: A string, the name of XML element.
value: A Python object, whose string representation will be used
as the value of the XML element.
indent: A string, prepended to each line of generated output.
"""
value_str = _StrOrUnicode(value)
if isinstance(value, bool):
# Display boolean values as the C++ flag library does: no caps.
value_str = value_str.lower()
safe_value_str = _MakeXMLSafe(value_str)
outfile.write('%s<%s>%s</%s>\n' % (indent, name, safe_value_str, name))
class Flag:
"""Information about a command-line flag.
'Flag' objects define the following fields:
.name - the name for this flag
.default - the default value for this flag
.default_as_str - default value as repr'd string, e.g., "'true'" (or None)
.value - the most recent parsed value of this flag; set by Parse()
.help - a help string or None if no help is available
.short_name - the single letter alias for this flag (or None)
.boolean - if 'true', this flag does not accept arguments
.present - true if this flag was parsed from command line flags.
.parser - an ArgumentParser object
.serializer - an ArgumentSerializer object
.allow_override - the flag may be redefined without raising an error
The only public method of a 'Flag' object is Parse(), but it is
typically only called by a 'FlagValues' object. The Parse() method is
a thin wrapper around the 'ArgumentParser' Parse() method. The parsed
value is saved in .value, and the .present attribute is updated. If
this flag was already present, a FlagsError is raised.
Parse() is also called during __init__ to parse the default value and
initialize the .value attribute. This enables other python modules to
safely use flags even if the __main__ module neglects to parse the
command line arguments. The .present attribute is cleared after
__init__ parsing. If the default value is set to None, then the
__init__ parsing step is skipped and the .value attribute is
initialized to None.
Note: The default value is also presented to the user in the help
string, so it is important that it be a legal value for this flag.
"""
def __init__(self, parser, serializer, name, default, help_string,
short_name=None, boolean=0, allow_override=0):
self.name = name
if not help_string:
help_string = '(no help available)'
self.help = help_string
self.short_name = short_name
self.boolean = boolean
self.present = 0
self.parser = parser
self.serializer = serializer
self.allow_override = allow_override
self.value = None
self.validators = []
self.SetDefault(default)
def __hash__(self):
return hash(id(self))
def __eq__(self, other):
return self is other
def __lt__(self, other):
if isinstance(other, Flag):
return id(self) < id(other)
return NotImplemented
def __GetParsedValueAsString(self, value):
if value is None:
return None
if self.serializer:
return repr(self.serializer.Serialize(value))
if self.boolean:
if value:
return repr('true')
else:
return repr('false')
return repr(_StrOrUnicode(value))
def Parse(self, argument):
try:
self.value = self.parser.Parse(argument)
except ValueError, e: # recast ValueError as IllegalFlagValue
raise IllegalFlagValue("flag --%s=%s: %s" % (self.name, argument, e))
self.present += 1
def Unparse(self):
if self.default is None:
self.value = None
else:
self.Parse(self.default)
self.present = 0
def Serialize(self):
if self.value is None:
return ''
if self.boolean:
if self.value:
return "--%s" % self.name
else:
return "--no%s" % self.name
else:
if not self.serializer:
raise FlagsError("Serializer not present for flag %s" % self.name)
return "--%s=%s" % (self.name, self.serializer.Serialize(self.value))
def SetDefault(self, value):
"""Changes the default value (and current value too) for this Flag."""
# We can't allow a None override because it may end up not being
# passed to C++ code when we're overriding C++ flags. So we
# cowardly bail out until someone fixes the semantics of trying to
# pass None to a C++ flag. See swig_flags.Init() for details on
# this behavior.
# TODO(olexiy): Users can directly call this method, bypassing all flags
# validators (we don't have FlagValues here, so we can not check
# validators).
# The simplest solution I see is to make this method private.
# Another approach would be to store reference to the corresponding
# FlagValues with each flag, but this seems to be an overkill.
if value is None and self.allow_override:
raise DuplicateFlagCannotPropagateNoneToSwig(self.name)
self.default = value
self.Unparse()
self.default_as_str = self.__GetParsedValueAsString(self.value)
def Type(self):
"""Returns: a string that describes the type of this Flag."""
# NOTE: we use strings, and not the types.*Type constants because
# our flags can have more exotic types, e.g., 'comma separated list
# of strings', 'whitespace separated list of strings', etc.
return self.parser.Type()
def WriteInfoInXMLFormat(self, outfile, module_name, is_key=False, indent=''):
"""Writes common info about this flag, in XML format.
This is information that is relevant to all flags (e.g., name,
meaning, etc.). If you defined a flag that has some other pieces of
info, then please override _WriteCustomInfoInXMLFormat.
Please do NOT override this method.
Args:
outfile: File object we write to.
module_name: A string, the name of the module that defines this flag.
is_key: A boolean, True iff this flag is key for main module.
indent: A string that is prepended to each generated line.
"""
outfile.write(indent + '<flag>\n')
inner_indent = indent + ' '
if is_key:
_WriteSimpleXMLElement(outfile, 'key', 'yes', inner_indent)
_WriteSimpleXMLElement(outfile, 'file', module_name, inner_indent)
# Print flag features that are relevant for all flags.
_WriteSimpleXMLElement(outfile, 'name', self.name, inner_indent)
if self.short_name:
_WriteSimpleXMLElement(outfile, 'short_name', self.short_name,
inner_indent)
if self.help:
_WriteSimpleXMLElement(outfile, 'meaning', self.help, inner_indent)
# The default flag value can either be represented as a string like on the
# command line, or as a Python object. We serialize this value in the
# latter case in order to remain consistent.
if self.serializer and not isinstance(self.default, str):
default_serialized = self.serializer.Serialize(self.default)
else:
default_serialized = self.default
_WriteSimpleXMLElement(outfile, 'default', default_serialized, inner_indent)
_WriteSimpleXMLElement(outfile, 'current', self.value, inner_indent)
_WriteSimpleXMLElement(outfile, 'type', self.Type(), inner_indent)
# Print extra flag features this flag may have.
self._WriteCustomInfoInXMLFormat(outfile, inner_indent)
outfile.write(indent + '</flag>\n')
def _WriteCustomInfoInXMLFormat(self, outfile, indent):
"""Writes extra info about this flag, in XML format.
"Extra" means "not already printed by WriteInfoInXMLFormat above."
Args:
outfile: File object we write to.
indent: A string that is prepended to each generated line.
"""
# Usually, the parser knows the extra details about the flag, so
# we just forward the call to it.
self.parser.WriteCustomInfoInXMLFormat(outfile, indent)
# End of Flag definition
class _ArgumentParserCache(type):
"""Metaclass used to cache and share argument parsers among flags."""
_instances = {}
def __call__(mcs, *args, **kwargs):
"""Returns an instance of the argument parser cls.
This method overrides behavior of the __new__ methods in
all subclasses of ArgumentParser (inclusive). If an instance
for mcs with the same set of arguments exists, this instance is
returned, otherwise a new instance is created.
If any keyword arguments are defined, or the values in args
are not hashable, this method always returns a new instance of
cls.
Args:
args: Positional initializer arguments.
kwargs: Initializer keyword arguments.
Returns:
An instance of cls, shared or new.
"""
if kwargs:
return type.__call__(mcs, *args, **kwargs)
else:
instances = mcs._instances
key = (mcs,) + tuple(args)
try:
return instances[key]
except KeyError:
# No cache entry for key exists, create a new one.
return instances.setdefault(key, type.__call__(mcs, *args))
except TypeError:
# An object in args cannot be hashed, always return
# a new instance.
return type.__call__(mcs, *args)
class ArgumentParser(object):
"""Base class used to parse and convert arguments.
The Parse() method checks to make sure that the string argument is a
legal value and convert it to a native type. If the value cannot be
converted, it should throw a 'ValueError' exception with a human
readable explanation of why the value is illegal.
Subclasses should also define a syntactic_help string which may be
presented to the user to describe the form of the legal values.
Argument parser classes must be stateless, since instances are cached
and shared between flags. Initializer arguments are allowed, but all
member variables must be derived from initializer arguments only.
"""
__metaclass__ = _ArgumentParserCache
syntactic_help = ""
def Parse(self, argument):
"""Default implementation: always returns its argument unmodified."""
return argument
def Type(self):
return 'string'
def WriteCustomInfoInXMLFormat(self, outfile, indent):
pass
class ArgumentSerializer:
"""Base class for generating string representations of a flag value."""
def Serialize(self, value):
return _StrOrUnicode(value)
class ListSerializer(ArgumentSerializer):
def __init__(self, list_sep):
self.list_sep = list_sep
def Serialize(self, value):
return self.list_sep.join([_StrOrUnicode(x) for x in value])
# Flags validators
def RegisterValidator(flag_name,
checker,
message='Flag validation failed',
flag_values=FLAGS):
"""Adds a constraint, which will be enforced during program execution.
The constraint is validated when flags are initially parsed, and after each
change of the corresponding flag's value.
Args:
flag_name: string, name of the flag to be checked.
checker: method to validate the flag.
input - value of the corresponding flag (string, boolean, etc.
This value will be passed to checker by the library). See file's
docstring for examples.
output - Boolean.
Must return True if validator constraint is satisfied.
If constraint is not satisfied, it should either return False or
raise gflags_validators.Error(desired_error_message).
message: error text to be shown to the user if checker returns False.
If checker raises gflags_validators.Error, message from the raised
Error will be shown.
flag_values: FlagValues
Raises:
AttributeError: if flag_name is not registered as a valid flag name.
"""
flag_values.AddValidator(gflags_validators.SimpleValidator(flag_name,
checker,
message))
def MarkFlagAsRequired(flag_name, flag_values=FLAGS):
"""Ensure that flag is not None during program execution.
Registers a flag validator, which will follow usual validator
rules.
Args:
flag_name: string, name of the flag
flag_values: FlagValues
Raises:
AttributeError: if flag_name is not registered as a valid flag name.
"""
RegisterValidator(flag_name,
lambda value: value is not None,
message='Flag --%s must be specified.' % flag_name,
flag_values=flag_values)
def _RegisterBoundsValidatorIfNeeded(parser, name, flag_values):
"""Enforce lower and upper bounds for numeric flags.
Args:
parser: NumericParser (either FloatParser or IntegerParser). Provides lower
and upper bounds, and help text to display.
name: string, name of the flag
flag_values: FlagValues
"""
if parser.lower_bound is not None or parser.upper_bound is not None:
def Checker(value):
if value is not None and parser.IsOutsideBounds(value):
message = '%s is not %s' % (value, parser.syntactic_help)
raise gflags_validators.Error(message)
return True
RegisterValidator(name,
Checker,
flag_values=flag_values)
# The DEFINE functions are explained in mode details in the module doc string.
def DEFINE(parser, name, default, help, flag_values=FLAGS, serializer=None,
**args):
"""Registers a generic Flag object.
NOTE: in the docstrings of all DEFINE* functions, "registers" is short
for "creates a new flag and registers it".
Auxiliary function: clients should use the specialized DEFINE_<type>
function instead.
Args:
parser: ArgumentParser that is used to parse the flag arguments.
name: A string, the flag name.
default: The default value of the flag.
help: A help string.
flag_values: FlagValues object the flag will be registered with.
serializer: ArgumentSerializer that serializes the flag value.
args: Dictionary with extra keyword args that are passes to the
Flag __init__.
"""
DEFINE_flag(Flag(parser, serializer, name, default, help, **args),
flag_values)
def DEFINE_flag(flag, flag_values=FLAGS):
"""Registers a 'Flag' object with a 'FlagValues' object.
By default, the global FLAGS 'FlagValue' object is used.
Typical users will use one of the more specialized DEFINE_xxx
functions, such as DEFINE_string or DEFINE_integer. But developers
who need to create Flag objects themselves should use this function
to register their flags.
"""
# copying the reference to flag_values prevents pychecker warnings
fv = flag_values
fv[flag.name] = flag
# Tell flag_values who's defining the flag.
if isinstance(flag_values, FlagValues):
# Regarding the above isinstance test: some users pass funny
# values of flag_values (e.g., {}) in order to avoid the flag
# registration (in the past, there used to be a flag_values ==
# FLAGS test here) and redefine flags with the same name (e.g.,
# debug). To avoid breaking their code, we perform the
# registration only if flag_values is a real FlagValues object.
module, module_name = _GetCallingModuleObjectAndName()
flag_values._RegisterFlagByModule(module_name, flag)
flag_values._RegisterFlagByModuleId(id(module), flag)
def _InternalDeclareKeyFlags(flag_names,
flag_values=FLAGS, key_flag_values=None):
"""Declares a flag as key for the calling module.
Internal function. User code should call DECLARE_key_flag or
ADOPT_module_key_flags instead.
Args:
flag_names: A list of strings that are names of already-registered
Flag objects.
flag_values: A FlagValues object that the flags listed in
flag_names have registered with (the value of the flag_values
argument from the DEFINE_* calls that defined those flags).
This should almost never need to be overridden.
key_flag_values: A FlagValues object that (among possibly many
other things) keeps track of the key flags for each module.
Default None means "same as flag_values". This should almost
never need to be overridden.
Raises:
UnrecognizedFlagError: when we refer to a flag that was not
defined yet.
"""
key_flag_values = key_flag_values or flag_values
module = _GetCallingModule()
for flag_name in flag_names:
if flag_name not in flag_values:
raise UnrecognizedFlagError(flag_name)
flag = flag_values.FlagDict()[flag_name]
key_flag_values._RegisterKeyFlagForModule(module, flag)
def DECLARE_key_flag(flag_name, flag_values=FLAGS):
"""Declares one flag as key to the current module.
Key flags are flags that are deemed really important for a module.
They are important when listing help messages; e.g., if the
--helpshort command-line flag is used, then only the key flags of the
main module are listed (instead of all flags, as in the case of
--help).
Sample usage:
gflags.DECLARED_key_flag('flag_1')
Args:
flag_name: A string, the name of an already declared flag.
(Redeclaring flags as key, including flags implicitly key
because they were declared in this module, is a no-op.)
flag_values: A FlagValues object. This should almost never
need to be overridden.
"""
if flag_name in _SPECIAL_FLAGS:
# Take care of the special flags, e.g., --flagfile, --undefok.
# These flags are defined in _SPECIAL_FLAGS, and are treated
# specially during flag parsing, taking precedence over the
# user-defined flags.
_InternalDeclareKeyFlags([flag_name],
flag_values=_SPECIAL_FLAGS,
key_flag_values=flag_values)
return
_InternalDeclareKeyFlags([flag_name], flag_values=flag_values)
def ADOPT_module_key_flags(module, flag_values=FLAGS):
"""Declares that all flags key to a module are key to the current module.
Args:
module: A module object.
flag_values: A FlagValues object. This should almost never need
to be overridden.
Raises:
FlagsError: When given an argument that is a module name (a
string), instead of a module object.
"""
# NOTE(salcianu): an even better test would be if not
# isinstance(module, types.ModuleType) but I didn't want to import
# types for such a tiny use.
if isinstance(module, str):
raise FlagsError('Received module name %s; expected a module object.'
% module)
_InternalDeclareKeyFlags(
[f.name for f in flag_values._GetKeyFlagsForModule(module.__name__)],
flag_values=flag_values)
# If module is this flag module, take _SPECIAL_FLAGS into account.
if module == _GetThisModuleObjectAndName()[0]:
_InternalDeclareKeyFlags(
# As we associate flags with _GetCallingModuleObjectAndName(), the
# special flags defined in this module are incorrectly registered with
# a different module. So, we can't use _GetKeyFlagsForModule.
# Instead, we take all flags from _SPECIAL_FLAGS (a private
# FlagValues, where no other module should register flags).
[f.name for f in _SPECIAL_FLAGS.FlagDict().values()],
flag_values=_SPECIAL_FLAGS,
key_flag_values=flag_values)
#
# STRING FLAGS
#
def DEFINE_string(name, default, help, flag_values=FLAGS, **args):
"""Registers a flag whose value can be any string."""
parser = ArgumentParser()
serializer = ArgumentSerializer()
DEFINE(parser, name, default, help, flag_values, serializer, **args)
#
# BOOLEAN FLAGS
#
class BooleanParser(ArgumentParser):
"""Parser of boolean values."""
def Convert(self, argument):
"""Converts the argument to a boolean; raise ValueError on errors."""
if type(argument) == str:
if argument.lower() in ['true', 't', '1']:
return True
elif argument.lower() in ['false', 'f', '0']:
return False
bool_argument = bool(argument)
if argument == bool_argument:
# The argument is a valid boolean (True, False, 0, or 1), and not just
# something that always converts to bool (list, string, int, etc.).
return bool_argument
raise ValueError('Non-boolean argument to boolean flag', argument)
def Parse(self, argument):
val = self.Convert(argument)
return val
def Type(self):
return 'bool'
class BooleanFlag(Flag):
"""Basic boolean flag.
Boolean flags do not take any arguments, and their value is either
True (1) or False (0). The false value is specified on the command
line by prepending the word 'no' to either the long or the short flag
name.
For example, if a Boolean flag was created whose long name was
'update' and whose short name was 'x', then this flag could be
explicitly unset through either --noupdate or --nox.
"""
def __init__(self, name, default, help, short_name=None, **args):
p = BooleanParser()
Flag.__init__(self, p, None, name, default, help, short_name, 1, **args)
if not self.help: self.help = "a boolean value"
def DEFINE_boolean(name, default, help, flag_values=FLAGS, **args):
"""Registers a boolean flag.
Such a boolean flag does not take an argument. If a user wants to
specify a false value explicitly, the long option beginning with 'no'
must be used: i.e. --noflag
This flag will have a value of None, True or False. None is possible
if default=None and the user does not specify the flag on the command
line.
"""
DEFINE_flag(BooleanFlag(name, default, help, **args), flag_values)
# Match C++ API to unconfuse C++ people.
DEFINE_bool = DEFINE_boolean
class HelpFlag(BooleanFlag):
"""
HelpFlag is a special boolean flag that prints usage information and
raises a SystemExit exception if it is ever found in the command
line arguments. Note this is called with allow_override=1, so other
apps can define their own --help flag, replacing this one, if they want.
"""
def __init__(self):
BooleanFlag.__init__(self, "help", 0, "show this help",
short_name="?", allow_override=1)
def Parse(self, arg):
if arg:
doc = sys.modules["__main__"].__doc__
flags = str(FLAGS)
print doc or ("\nUSAGE: %s [flags]\n" % sys.argv[0])
if flags:
print "flags:"
print flags
sys.exit(1)
class HelpXMLFlag(BooleanFlag):
"""Similar to HelpFlag, but generates output in XML format."""
def __init__(self):
BooleanFlag.__init__(self, 'helpxml', False,
'like --help, but generates XML output',
allow_override=1)
def Parse(self, arg):
if arg:
FLAGS.WriteHelpInXMLFormat(sys.stdout)
sys.exit(1)
class HelpshortFlag(BooleanFlag):
"""
HelpshortFlag is a special boolean flag that prints usage
information for the "main" module, and rasies a SystemExit exception
if it is ever found in the command line arguments. Note this is
called with allow_override=1, so other apps can define their own
--helpshort flag, replacing this one, if they want.
"""
def __init__(self):
BooleanFlag.__init__(self, "helpshort", 0,
"show usage only for this module", allow_override=1)
def Parse(self, arg):
if arg:
doc = sys.modules["__main__"].__doc__
flags = FLAGS.MainModuleHelp()
print doc or ("\nUSAGE: %s [flags]\n" % sys.argv[0])
if flags:
print "flags:"
print flags
sys.exit(1)
#
# Numeric parser - base class for Integer and Float parsers
#
class NumericParser(ArgumentParser):
"""Parser of numeric values.
Parsed value may be bounded to a given upper and lower bound.
"""
def IsOutsideBounds(self, val):
return ((self.lower_bound is not None and val < self.lower_bound) or
(self.upper_bound is not None and val > self.upper_bound))
def Parse(self, argument):
val = self.Convert(argument)
if self.IsOutsideBounds(val):
raise ValueError("%s is not %s" % (val, self.syntactic_help))
return val
def WriteCustomInfoInXMLFormat(self, outfile, indent):
if self.lower_bound is not None:
_WriteSimpleXMLElement(outfile, 'lower_bound', self.lower_bound, indent)
if self.upper_bound is not None:
_WriteSimpleXMLElement(outfile, 'upper_bound', self.upper_bound, indent)
def Convert(self, argument):
"""Default implementation: always returns its argument unmodified."""
return argument
# End of Numeric Parser
#
# FLOAT FLAGS
#
class FloatParser(NumericParser):
"""Parser of floating point values.
Parsed value may be bounded to a given upper and lower bound.
"""
number_article = "a"
number_name = "number"
syntactic_help = " ".join((number_article, number_name))
def __init__(self, lower_bound=None, upper_bound=None):
super(FloatParser, self).__init__()
self.lower_bound = lower_bound
self.upper_bound = upper_bound
sh = self.syntactic_help
if lower_bound is not None and upper_bound is not None:
sh = ("%s in the range [%s, %s]" % (sh, lower_bound, upper_bound))
elif lower_bound == 0:
sh = "a non-negative %s" % self.number_name
elif upper_bound == 0:
sh = "a non-positive %s" % self.number_name
elif upper_bound is not None:
sh = "%s <= %s" % (self.number_name, upper_bound)
elif lower_bound is not None:
sh = "%s >= %s" % (self.number_name, lower_bound)
self.syntactic_help = sh
def Convert(self, argument):
"""Converts argument to a float; raises ValueError on errors."""
return float(argument)
def Type(self):
return 'float'
# End of FloatParser
def DEFINE_float(name, default, help, lower_bound=None, upper_bound=None,
flag_values=FLAGS, **args):
"""Registers a flag whose value must be a float.
If lower_bound or upper_bound are set, then this flag must be
within the given range.
"""
parser = FloatParser(lower_bound, upper_bound)
serializer = ArgumentSerializer()
DEFINE(parser, name, default, help, flag_values, serializer, **args)
_RegisterBoundsValidatorIfNeeded(parser, name, flag_values=flag_values)
#
# INTEGER FLAGS
#
class IntegerParser(NumericParser):
"""Parser of an integer value.
Parsed value may be bounded to a given upper and lower bound.
"""
number_article = "an"
number_name = "integer"
syntactic_help = " ".join((number_article, number_name))
def __init__(self, lower_bound=None, upper_bound=None):
super(IntegerParser, self).__init__()
self.lower_bound = lower_bound
self.upper_bound = upper_bound
sh = self.syntactic_help
if lower_bound is not None and upper_bound is not None:
sh = ("%s in the range [%s, %s]" % (sh, lower_bound, upper_bound))
elif lower_bound == 1:
sh = "a positive %s" % self.number_name
elif upper_bound == -1:
sh = "a negative %s" % self.number_name
elif lower_bound == 0:
sh = "a non-negative %s" % self.number_name
elif upper_bound == 0:
sh = "a non-positive %s" % self.number_name
elif upper_bound is not None:
sh = "%s <= %s" % (self.number_name, upper_bound)
elif lower_bound is not None:
sh = "%s >= %s" % (self.number_name, lower_bound)
self.syntactic_help = sh
def Convert(self, argument):
__pychecker__ = 'no-returnvalues'
if type(argument) == str:
base = 10
if len(argument) > 2 and argument[0] == "0" and argument[1] == "x":
base = 16
return int(argument, base)
else:
return int(argument)
def Type(self):
return 'int'
def DEFINE_integer(name, default, help, lower_bound=None, upper_bound=None,
flag_values=FLAGS, **args):
"""Registers a flag whose value must be an integer.
If lower_bound, or upper_bound are set, then this flag must be
within the given range.
"""
parser = IntegerParser(lower_bound, upper_bound)
serializer = ArgumentSerializer()
DEFINE(parser, name, default, help, flag_values, serializer, **args)
_RegisterBoundsValidatorIfNeeded(parser, name, flag_values=flag_values)
#
# ENUM FLAGS
#
class EnumParser(ArgumentParser):
"""Parser of a string enum value (a string value from a given set).
If enum_values (see below) is not specified, any string is allowed.
"""
def __init__(self, enum_values=None):
super(EnumParser, self).__init__()
self.enum_values = enum_values
def Parse(self, argument):
if self.enum_values and argument not in self.enum_values:
raise ValueError("value should be one of <%s>" %
"|".join(self.enum_values))
return argument
def Type(self):
return 'string enum'
class EnumFlag(Flag):
"""Basic enum flag; its value can be any string from list of enum_values."""
def __init__(self, name, default, help, enum_values=None,
short_name=None, **args):
enum_values = enum_values or []
p = EnumParser(enum_values)
g = ArgumentSerializer()
Flag.__init__(self, p, g, name, default, help, short_name, **args)
if not self.help: self.help = "an enum string"
self.help = "<%s>: %s" % ("|".join(enum_values), self.help)
def _WriteCustomInfoInXMLFormat(self, outfile, indent):
for enum_value in self.parser.enum_values:
_WriteSimpleXMLElement(outfile, 'enum_value', enum_value, indent)
def DEFINE_enum(name, default, enum_values, help, flag_values=FLAGS,
**args):
"""Registers a flag whose value can be any string from enum_values."""
DEFINE_flag(EnumFlag(name, default, help, enum_values, ** args),
flag_values)
#
# LIST FLAGS
#
class BaseListParser(ArgumentParser):
"""Base class for a parser of lists of strings.
To extend, inherit from this class; from the subclass __init__, call
BaseListParser.__init__(self, token, name)
where token is a character used to tokenize, and name is a description
of the separator.
"""
def __init__(self, token=None, name=None):
assert name
super(BaseListParser, self).__init__()
self._token = token
self._name = name
self.syntactic_help = "a %s separated list" % self._name
def Parse(self, argument):
if isinstance(argument, list):
return argument
elif argument == '':
return []
else:
return [s.strip() for s in argument.split(self._token)]
def Type(self):
return '%s separated list of strings' % self._name
class ListParser(BaseListParser):
"""Parser for a comma-separated list of strings."""
def __init__(self):
BaseListParser.__init__(self, ',', 'comma')
def WriteCustomInfoInXMLFormat(self, outfile, indent):
BaseListParser.WriteCustomInfoInXMLFormat(self, outfile, indent)
_WriteSimpleXMLElement(outfile, 'list_separator', repr(','), indent)
class WhitespaceSeparatedListParser(BaseListParser):
"""Parser for a whitespace-separated list of strings."""
def __init__(self):
BaseListParser.__init__(self, None, 'whitespace')
def WriteCustomInfoInXMLFormat(self, outfile, indent):
BaseListParser.WriteCustomInfoInXMLFormat(self, outfile, indent)
separators = list(string.whitespace)
separators.sort()
for ws_char in string.whitespace:
_WriteSimpleXMLElement(outfile, 'list_separator', repr(ws_char), indent)
def DEFINE_list(name, default, help, flag_values=FLAGS, **args):
"""Registers a flag whose value is a comma-separated list of strings."""
parser = ListParser()
serializer = ListSerializer(',')
DEFINE(parser, name, default, help, flag_values, serializer, **args)
def DEFINE_spaceseplist(name, default, help, flag_values=FLAGS, **args):
"""Registers a flag whose value is a whitespace-separated list of strings.
Any whitespace can be used as a separator.
"""
parser = WhitespaceSeparatedListParser()
serializer = ListSerializer(' ')
DEFINE(parser, name, default, help, flag_values, serializer, **args)
#
# MULTI FLAGS
#
class MultiFlag(Flag):
"""A flag that can appear multiple time on the command-line.
The value of such a flag is a list that contains the individual values
from all the appearances of that flag on the command-line.
See the __doc__ for Flag for most behavior of this class. Only
differences in behavior are described here:
* The default value may be either a single value or a list of values.
A single value is interpreted as the [value] singleton list.
* The value of the flag is always a list, even if the option was
only supplied once, and even if the default value is a single
value
"""
def __init__(self, *args, **kwargs):
Flag.__init__(self, *args, **kwargs)
self.help += ';\n repeat this option to specify a list of values'
def Parse(self, arguments):
"""Parses one or more arguments with the installed parser.
Args:
arguments: a single argument or a list of arguments (typically a
list of default values); a single argument is converted
internally into a list containing one item.
"""
if not isinstance(arguments, list):
# Default value may be a list of values. Most other arguments
# will not be, so convert them into a single-item list to make
# processing simpler below.
arguments = [arguments]
if self.present:
# keep a backup reference to list of previously supplied option values
values = self.value
else:
# "erase" the defaults with an empty list
values = []
for item in arguments:
# have Flag superclass parse argument, overwriting self.value reference
Flag.Parse(self, item) # also increments self.present
values.append(self.value)
# put list of option values back in the 'value' attribute
self.value = values
def Serialize(self):
if not self.serializer:
raise FlagsError("Serializer not present for flag %s" % self.name)
if self.value is None:
return ''
s = ''
multi_value = self.value
for self.value in multi_value:
if s: s += ' '
s += Flag.Serialize(self)
self.value = multi_value
return s
def Type(self):
return 'multi ' + self.parser.Type()
def DEFINE_multi(parser, serializer, name, default, help, flag_values=FLAGS,
**args):
"""Registers a generic MultiFlag that parses its args with a given parser.
Auxiliary function. Normal users should NOT use it directly.
Developers who need to create their own 'Parser' classes for options
which can appear multiple times can call this module function to
register their flags.
"""
DEFINE_flag(MultiFlag(parser, serializer, name, default, help, **args),
flag_values)
def DEFINE_multistring(name, default, help, flag_values=FLAGS, **args):
"""Registers a flag whose value can be a list of any strings.
Use the flag on the command line multiple times to place multiple
string values into the list. The 'default' may be a single string
(which will be converted into a single-element list) or a list of
strings.
"""
parser = ArgumentParser()
serializer = ArgumentSerializer()
DEFINE_multi(parser, serializer, name, default, help, flag_values, **args)
def DEFINE_multi_int(name, default, help, lower_bound=None, upper_bound=None,
flag_values=FLAGS, **args):
"""Registers a flag whose value can be a list of arbitrary integers.
Use the flag on the command line multiple times to place multiple
integer values into the list. The 'default' may be a single integer
(which will be converted into a single-element list) or a list of
integers.
"""
parser = IntegerParser(lower_bound, upper_bound)
serializer = ArgumentSerializer()
DEFINE_multi(parser, serializer, name, default, help, flag_values, **args)
def DEFINE_multi_float(name, default, help, lower_bound=None, upper_bound=None,
flag_values=FLAGS, **args):
"""Registers a flag whose value can be a list of arbitrary floats.
Use the flag on the command line multiple times to place multiple
float values into the list. The 'default' may be a single float
(which will be converted into a single-element list) or a list of
floats.
"""
parser = FloatParser(lower_bound, upper_bound)
serializer = ArgumentSerializer()
DEFINE_multi(parser, serializer, name, default, help, flag_values, **args)
# Now register the flags that we want to exist in all applications.
# These are all defined with allow_override=1, so user-apps can use
# these flagnames for their own purposes, if they want.
DEFINE_flag(HelpFlag())
DEFINE_flag(HelpshortFlag())
DEFINE_flag(HelpXMLFlag())
# Define special flags here so that help may be generated for them.
# NOTE: Please do NOT use _SPECIAL_FLAGS from outside this module.
_SPECIAL_FLAGS = FlagValues()
DEFINE_string(
'flagfile', "",
"Insert flag definitions from the given file into the command line.",
_SPECIAL_FLAGS)
DEFINE_string(
'undefok', "",
"comma-separated list of flag names that it is okay to specify "
"on the command line even if the program does not define a flag "
"with that name. IMPORTANT: flags in this list that have "
"arguments MUST use the --flag=value format.", _SPECIAL_FLAGS)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
14790,
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,
3,
199,
3,
10894,
199,
3,
6529,
26,
2799,
350,
491,
17338,
199,
3,
29410,
436,
3449,
406,
26675,
701,
26,
199,
3,
257,
437,
1147,
510,
21163,
12,
699,
974,
24863,
1849,
331,
5891,
12,
24747,
14769,
577,
85,
29382,
12,
662,
1567,
377,
1873,
271,
20059,
12,
199,
3,
257,
662,
1567,
812,
10885,
12,
7964,
608,
21225,
598,
4654,
279,
2310,
12,
18619,
29640,
428,
2700,
7886,
199,
3,
5495,
295,
19916,
1759,
282,
4546,
701,
445,
345,
528,
428,
382,
422,
1597,
262,
199,
199,
624,
2765,
859,
365,
1202,
370,
5627,
436,
2198,
1414,
1004,
3285,
14,
199,
199,
2765,
859,
7890,
282,
627,
16832,
10,
3305,
13,
7463,
4592,
26,
7830,
2419,
199,
290,
4223,
9445,
370,
5627,
1006,
3285,
315,
503,
17429,
2446,
1062,
1924,
2366,
199,
578,
7890,
3285,
626,
787,
2997,
370,
652,
14,
221,
3979,
1373,
2366,
859,
199,
12775,
4573,
12,
652,
15334,
83,
2879,
370,
314,
1163,
1159,
3285,
14,
221,
334,
2765,
365,
199,
13825,
701,
9445,
1006,
4621,
8663,
282,
2863,
12,
2288,
7086,
909,
199,
16133,
1006,
314,
3305,
2556,
4959,
199,
199,
6381,
787,
3247,
4012,
314,
675,
402,
1373,
402,
314,
23566,
3565,
63,
10013,
3423,
14,
199,
1918,
2488,
805,
1202,
16756,
4212,
314,
3305,
365,
4565,
12,
7923,
12,
199,
460,
14190,
730,
13,
22818,
12,
1380,
652,
1159,
6775,
641,
314,
1414,
1004,
14,
421,
199,
8947,
10320,
2594,
26,
23566,
3565,
15192,
8491,
282,
283,
5318,
7,
909,
436,
24493,
652,
543,
282,
199,
7,
5318,
6550,
7,
909,
334,
32251,
314,
2288,
18241,
6550,
12846,
12,
3247,
199,
1681,
680,
221,
710,
283,
5318,
6550,
7,
909,
883,
8000,
314,
1414,
1004,
2368,
436,
199,
1529,
3305,
2368,
370,
314,
5226,
283,
5318,
7,
2251,
367,
199,
585,
13,
19527,
436,
730,
8603,
14,
221,
710,
6702,
3305,
1338,
787,
199,
4561,
465,
3004,
402,
314,
283,
5318,
6550,
7,
909,
14,
199,
199,
3034,
883,
2879,
314,
3305,
4012,
282,
18241,
6550,
909,
12,
367,
1256,
199,
71,
2469,
14,
4831,
14,
1662,
4173,
14,
221,
26914,
12,
314,
636,
973,
363,
859,
14933,
314,
1414,
199,
604,
2368,
370,
486,
2469,
14,
4831,
367,
6057,
14,
199,
199,
1271,
9048,
12,
642,
859,
4882,
12733,
1062,
880,
12733,
9330,
365,
199,
4946,
12,
5893,
3974,
13,
436,
1846,
13,
2487,
3285,
12,
436,
314,
675,
402,
1553,
370,
199,
14478,
3285,
14,
199,
199,
10385,
3247,
701,
314,
3305,
859,
911,
7978,
283,
6381,
547,
7,
4967,
14,
199,
1918,
1919,
1423,
911,
506,
282,
11779,
13,
11875,
1059,
14,
421,
199,
3719,
32317,
26,
961,
365,
282,
769,
402,
314,
23566,
3565,
63,
10223,
83,
626,
1265,
883,
886,
14,
221,
2900,
3285,
199,
11066,
282,
536,
12,
849,
574,
12,
1720,
13,
875,
12,
436,
2716,
283,
3612,
7,
536,
199,
8,
368,
13,
9269,
536,
680,
221,
6601,
3285,
1172,
1163,
2368,
12,
1314,
787,
11736,
199,
1045,
314,
3305,
14,
199,
199,
14603,
63,
875,
26,
6181,
1263,
1324,
12,
436,
6421,
1086,
652,
465,
282,
1059,
14,
199,
199,
14603,
63,
2245,
503,
199,
14603,
63,
4871,
26,
13609,
1630,
440,
5452,
376,
1423,
26,
14722,
1553,
1662,
4173,
370,
355,
663,
12846,
14,
1662,
4173,
370,
2549,
12,
503,
1553,
15998,
89,
4173,
370,
663,
355,
12846,
14,
1662,
4173,
370,
3055,
14,
221,
17669,
13824,
12,
1265,
883,
14722,
673,
1553,
1662,
4173,
29,
2052,
221,
503,
1553,
1662,
4173,
29,
84,
503,
1553,
1662,
4173,
29,
17,
221,
503,
673,
1553,
1662,
4173,
29,
3910,
503,
1553,
1662,
4173,
29,
70,
503,
1553,
1662,
4173,
29,
16,
199,
199,
14603,
63,
1609,
26,
6181,
376,
1324,
436,
6421,
1086,
652,
465,
282,
8402,
2376,
1598,
1329,
14,
221,
17415,
2716,
1249,
5117,
63,
3556,
436,
7008,
63,
3556,
27,
1598,
340,
314,
1329,
2013,
641,
314,
1414,
1004,
365,
734,
402,
1598,
1425,
12,
652,
911,
746,
282,
18241,
547,
14,
199,
199,
14603,
63,
4115,
26,
6181,
376,
1324,
436,
6421,
1086,
652,
465,
376,
3000,
14,
221,
17415,
355,
2716,
1249,
5117,
63,
3556,
436,
7008
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
334,
67,
9,
14790,
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,
3,
199,
3,
10894,
199,
3,
6529,
26,
2799,
350,
491,
17338,
199,
3,
29410,
436,
3449,
406,
26675,
701,
26,
199,
3,
257,
437,
1147,
510,
21163,
12,
699,
974,
24863,
1849,
331,
5891,
12,
24747,
14769,
577,
85,
29382,
12,
662,
1567,
377,
1873,
271,
20059,
12,
199,
3,
257,
662,
1567,
812,
10885,
12,
7964,
608,
21225,
598,
4654,
279,
2310,
12,
18619,
29640,
428,
2700,
7886,
199,
3,
5495,
295,
19916,
1759,
282,
4546,
701,
445,
345,
528,
428,
382,
422,
1597,
262,
199,
199,
624,
2765,
859,
365,
1202,
370,
5627,
436,
2198,
1414,
1004,
3285,
14,
199,
199,
2765,
859,
7890,
282,
627,
16832,
10,
3305,
13,
7463,
4592,
26,
7830,
2419,
199,
290,
4223,
9445,
370,
5627,
1006,
3285,
315,
503,
17429,
2446,
1062,
1924,
2366,
199,
578,
7890,
3285,
626,
787,
2997,
370,
652,
14,
221,
3979,
1373,
2366,
859,
199,
12775,
4573,
12,
652,
15334,
83,
2879,
370,
314,
1163,
1159,
3285,
14,
221,
334,
2765,
365,
199,
13825,
701,
9445,
1006,
4621,
8663,
282,
2863,
12,
2288,
7086,
909,
199,
16133,
1006,
314,
3305,
2556,
4959,
199,
199,
6381,
787,
3247,
4012,
314,
675,
402,
1373,
402,
314,
23566,
3565,
63,
10013,
3423,
14,
199,
1918,
2488,
805,
1202,
16756,
4212,
314,
3305,
365,
4565,
12,
7923,
12,
199,
460,
14190,
730,
13,
22818,
12,
1380,
652,
1159,
6775,
641,
314,
1414,
1004,
14,
421,
199,
8947,
10320,
2594,
26,
23566,
3565,
15192,
8491,
282,
283,
5318,
7,
909,
436,
24493,
652,
543,
282,
199,
7,
5318,
6550,
7,
909,
334,
32251,
314,
2288,
18241,
6550,
12846,
12,
3247,
199,
1681,
680,
221,
710,
283,
5318,
6550,
7,
909,
883,
8000,
314,
1414,
1004,
2368,
436,
199,
1529,
3305,
2368,
370,
314,
5226,
283,
5318,
7,
2251,
367,
199,
585,
13,
19527,
436,
730,
8603,
14,
221,
710,
6702,
3305,
1338,
787,
199,
4561,
465,
3004,
402,
314,
283,
5318,
6550,
7,
909,
14,
199,
199,
3034,
883,
2879,
314,
3305,
4012,
282,
18241,
6550,
909,
12,
367,
1256,
199,
71,
2469,
14,
4831,
14,
1662,
4173,
14,
221,
26914,
12,
314,
636,
973,
363,
859,
14933,
314,
1414,
199,
604,
2368,
370,
486,
2469,
14,
4831,
367,
6057,
14,
199,
199,
1271,
9048,
12,
642,
859,
4882,
12733,
1062,
880,
12733,
9330,
365,
199,
4946,
12,
5893,
3974,
13,
436,
1846,
13,
2487,
3285,
12,
436,
314,
675,
402,
1553,
370,
199,
14478,
3285,
14,
199,
199,
10385,
3247,
701,
314,
3305,
859,
911,
7978,
283,
6381,
547,
7,
4967,
14,
199,
1918,
1919,
1423,
911,
506,
282,
11779,
13,
11875,
1059,
14,
421,
199,
3719,
32317,
26,
961,
365,
282,
769,
402,
314,
23566,
3565,
63,
10223,
83,
626,
1265,
883,
886,
14,
221,
2900,
3285,
199,
11066,
282,
536,
12,
849,
574,
12,
1720,
13,
875,
12,
436,
2716,
283,
3612,
7,
536,
199,
8,
368,
13,
9269,
536,
680,
221,
6601,
3285,
1172,
1163,
2368,
12,
1314,
787,
11736,
199,
1045,
314,
3305,
14,
199,
199,
14603,
63,
875,
26,
6181,
1263,
1324,
12,
436,
6421,
1086,
652,
465,
282,
1059,
14,
199,
199,
14603,
63,
2245,
503,
199,
14603,
63,
4871,
26,
13609,
1630,
440,
5452,
376,
1423,
26,
14722,
1553,
1662,
4173,
370,
355,
663,
12846,
14,
1662,
4173,
370,
2549,
12,
503,
1553,
15998,
89,
4173,
370,
663,
355,
12846,
14,
1662,
4173,
370,
3055,
14,
221,
17669,
13824,
12,
1265,
883,
14722,
673,
1553,
1662,
4173,
29,
2052,
221,
503,
1553,
1662,
4173,
29,
84,
503,
1553,
1662,
4173,
29,
17,
221,
503,
673,
1553,
1662,
4173,
29,
3910,
503,
1553,
1662,
4173,
29,
70,
503,
1553,
1662,
4173,
29,
16,
199,
199,
14603,
63,
1609,
26,
6181,
376,
1324,
436,
6421,
1086,
652,
465,
282,
8402,
2376,
1598,
1329,
14,
221,
17415,
2716,
1249,
5117,
63,
3556,
436,
7008,
63,
3556,
27,
1598,
340,
314,
1329,
2013,
641,
314,
1414,
1004,
365,
734,
402,
1598,
1425,
12,
652,
911,
746,
282,
18241,
547,
14,
199,
199,
14603,
63,
4115,
26,
6181,
376,
1324,
436,
6421,
1086,
652,
465,
376,
3000,
14,
221,
17415,
355,
2716,
1249,
5117,
63,
3556,
436,
7008,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alivecor/tensorflow
|
tensorflow/examples/speech_commands/freeze_test.py
|
48
|
1474
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for data input for speech commands."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.examples.speech_commands import freeze
from tensorflow.python.platform import test
class FreezeTest(test.TestCase):
def testCreateInferenceGraph(self):
with self.test_session() as sess:
freeze.create_inference_graph('a,b,c,d', 16000, 1000.0, 30.0, 30.0, 10.0,
40, 'conv')
self.assertIsNotNone(sess.graph.get_tensor_by_name('wav_data:0'))
self.assertIsNotNone(
sess.graph.get_tensor_by_name('decoded_sample_data:0'))
self.assertIsNotNone(sess.graph.get_tensor_by_name('labels_softmax:0'))
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
666,
1324,
367,
32093,
3718,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
8589,
14,
23660,
63,
4405,
492,
22778,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
2868,
806,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
2499,
29731,
4578,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
22778,
14,
981,
63,
20580,
63,
2180,
360,
65,
12,
66,
12,
67,
12,
68,
297,
3193,
1493,
12,
5198,
14,
16,
12,
4233,
14,
16,
12,
4233,
14,
16,
12,
1616,
14,
16,
12,
2511,
6335,
12,
283,
5598,
358,
489,
291,
14,
10389,
8,
5480,
14,
2180,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
19118,
63,
576,
26,
16,
1333,
489,
291,
14,
10389,
8,
881,
4043,
14,
2180,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
16167,
63,
3271,
63,
576,
26,
16,
1333,
489,
291,
14,
10389,
8,
5480,
14,
2180,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
3512,
63,
16395,
26,
16,
1333,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
666,
1324,
367,
32093,
3718,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
8589,
14,
23660,
63,
4405,
492,
22778,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
2868,
806,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
2499,
29731,
4578,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
22778,
14,
981,
63,
20580,
63,
2180,
360,
65,
12,
66,
12,
67,
12,
68,
297,
3193,
1493,
12,
5198,
14,
16,
12,
4233,
14,
16,
12,
4233,
14,
16,
12,
1616,
14,
16,
12,
2511,
6335,
12,
283,
5598,
358,
489,
291,
14,
10389,
8,
5480,
14,
2180,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
19118,
63,
576,
26,
16,
1333,
489,
291,
14,
10389,
8,
881,
4043,
14,
2180,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
16167,
63,
3271,
63,
576,
26,
16,
1333,
489,
291,
14,
10389,
8,
5480,
14,
2180,
14,
362,
63,
3128,
63,
991,
63,
354,
360,
3512,
63,
16395,
26,
16,
1333,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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0,
0,
0
] |
Anwesh43/numpy
|
numpy/core/tests/test_indexerrors.py
|
145
|
4938
|
from __future__ import division, absolute_import, print_function
import numpy as np
from numpy.testing import TestCase, run_module_suite, assert_raises
class TestIndexErrors(TestCase):
'''Tests to exercise indexerrors not covered by other tests.'''
def test_arraytypes_fasttake(self):
'take from a 0-length dimension'
x = np.empty((2, 3, 0, 4))
assert_raises(IndexError, x.take, [0], axis=2)
assert_raises(IndexError, x.take, [1], axis=2)
assert_raises(IndexError, x.take, [0], axis=2, mode='wrap')
assert_raises(IndexError, x.take, [0], axis=2, mode='clip')
def test_take_from_object(self):
# Check exception taking from object array
d = np.zeros(5, dtype=object)
assert_raises(IndexError, d.take, [6])
# Check exception taking from 0-d array
d = np.zeros((5, 0), dtype=object)
assert_raises(IndexError, d.take, [1], axis=1)
assert_raises(IndexError, d.take, [0], axis=1)
assert_raises(IndexError, d.take, [0])
assert_raises(IndexError, d.take, [0], mode='wrap')
assert_raises(IndexError, d.take, [0], mode='clip')
def test_multiindex_exceptions(self):
a = np.empty(5, dtype=object)
assert_raises(IndexError, a.item, 20)
a = np.empty((5, 0), dtype=object)
assert_raises(IndexError, a.item, (0, 0))
a = np.empty(5, dtype=object)
assert_raises(IndexError, a.itemset, 20, 0)
a = np.empty((5, 0), dtype=object)
assert_raises(IndexError, a.itemset, (0, 0), 0)
def test_put_exceptions(self):
a = np.zeros((5, 5))
assert_raises(IndexError, a.put, 100, 0)
a = np.zeros((5, 5), dtype=object)
assert_raises(IndexError, a.put, 100, 0)
a = np.zeros((5, 5, 0))
assert_raises(IndexError, a.put, 100, 0)
a = np.zeros((5, 5, 0), dtype=object)
assert_raises(IndexError, a.put, 100, 0)
def test_iterators_exceptions(self):
"cases in iterators.c"
def assign(obj, ind, val):
obj[ind] = val
a = np.zeros([1, 2, 3])
assert_raises(IndexError, lambda: a[0, 5, None, 2])
assert_raises(IndexError, lambda: a[0, 5, 0, 2])
assert_raises(IndexError, lambda: assign(a, (0, 5, None, 2), 1))
assert_raises(IndexError, lambda: assign(a, (0, 5, 0, 2), 1))
a = np.zeros([1, 0, 3])
assert_raises(IndexError, lambda: a[0, 0, None, 2])
assert_raises(IndexError, lambda: assign(a, (0, 0, None, 2), 1))
a = np.zeros([1, 2, 3])
assert_raises(IndexError, lambda: a.flat[10])
assert_raises(IndexError, lambda: assign(a.flat, 10, 5))
a = np.zeros([1, 0, 3])
assert_raises(IndexError, lambda: a.flat[10])
assert_raises(IndexError, lambda: assign(a.flat, 10, 5))
a = np.zeros([1, 2, 3])
assert_raises(IndexError, lambda: a.flat[np.array(10)])
assert_raises(IndexError, lambda: assign(a.flat, np.array(10), 5))
a = np.zeros([1, 0, 3])
assert_raises(IndexError, lambda: a.flat[np.array(10)])
assert_raises(IndexError, lambda: assign(a.flat, np.array(10), 5))
a = np.zeros([1, 2, 3])
assert_raises(IndexError, lambda: a.flat[np.array([10])])
assert_raises(IndexError, lambda: assign(a.flat, np.array([10]), 5))
a = np.zeros([1, 0, 3])
assert_raises(IndexError, lambda: a.flat[np.array([10])])
assert_raises(IndexError, lambda: assign(a.flat, np.array([10]), 5))
def test_mapping(self):
"cases from mapping.c"
def assign(obj, ind, val):
obj[ind] = val
a = np.zeros((0, 10))
assert_raises(IndexError, lambda: a[12])
a = np.zeros((3, 5))
assert_raises(IndexError, lambda: a[(10, 20)])
assert_raises(IndexError, lambda: assign(a, (10, 20), 1))
a = np.zeros((3, 0))
assert_raises(IndexError, lambda: a[(1, 0)])
assert_raises(IndexError, lambda: assign(a, (1, 0), 1))
a = np.zeros((10,))
assert_raises(IndexError, lambda: assign(a, 10, 1))
a = np.zeros((0,))
assert_raises(IndexError, lambda: assign(a, 10, 1))
a = np.zeros((3, 5))
assert_raises(IndexError, lambda: a[(1, [1, 20])])
assert_raises(IndexError, lambda: assign(a, (1, [1, 20]), 1))
a = np.zeros((3, 0))
assert_raises(IndexError, lambda: a[(1, [0, 1])])
assert_raises(IndexError, lambda: assign(a, (1, [0, 1]), 1))
def test_methods(self):
"cases from methods.c"
a = np.zeros((3, 3))
assert_raises(IndexError, lambda: a.item(100))
assert_raises(IndexError, lambda: a.itemset(100, 1))
a = np.zeros((0, 3))
assert_raises(IndexError, lambda: a.item(100))
assert_raises(IndexError, lambda: a.itemset(100, 1))
if __name__ == "__main__":
run_module_suite()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
3536,
199,
199,
533,
1379,
2681,
9298,
8,
1746,
304,
272,
1449,
2925,
370,
26511,
1478,
2550,
440,
24295,
701,
1163,
2295,
10595,
339,
347,
511,
63,
1144,
1313,
63,
7015,
11066,
8,
277,
304,
267,
283,
11066,
687,
282,
378,
13,
1267,
6240,
7,
267,
671,
275,
980,
14,
1667,
1332,
18,
12,
650,
12,
378,
12,
841,
430,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
16,
467,
3114,
29,
18,
9,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
17,
467,
3114,
29,
18,
9,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
16,
467,
3114,
29,
18,
12,
818,
534,
3823,
358,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
16,
467,
3114,
29,
18,
12,
818,
534,
7548,
358,
339,
347,
511,
63,
11066,
63,
504,
63,
785,
8,
277,
304,
267,
327,
2670,
1919,
16466,
687,
909,
1625,
267,
366,
275,
980,
14,
4250,
8,
21,
12,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
22,
566,
398,
327,
2670,
1919,
16466,
687,
378,
13,
68,
1625,
267,
366,
275,
980,
14,
4250,
1332,
21,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
17,
467,
3114,
29,
17,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
467,
3114,
29,
17,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
566,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
467,
818,
534,
3823,
358,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
467,
818,
534,
7548,
358,
339,
347,
511,
63,
3029,
1080,
63,
3924,
8,
277,
304,
267,
282,
275,
980,
14,
1667,
8,
21,
12,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
12,
3388,
9,
267,
282,
275,
980,
14,
1667,
1332,
21,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
12,
334,
16,
12,
378,
430,
398,
282,
275,
980,
14,
1667,
8,
21,
12,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
409,
12,
3388,
12,
378,
9,
267,
282,
275,
980,
14,
1667,
1332,
21,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
409,
12,
334,
16,
12,
378,
395,
378,
9,
339,
347,
511,
63,
524,
63,
3924,
8,
277,
304,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
430,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
12,
378,
430,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
339,
347,
511,
63,
1661,
2750,
63,
3924,
8,
277,
304,
267,
298,
9403,
315,
28241,
14,
67,
2,
267,
347,
5090,
8,
1113,
12,
7654,
12,
1139,
304,
288,
1559,
59,
688,
61,
275,
1139,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
59,
16,
12,
959,
12,
488,
12,
499,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
59,
16,
12,
959,
12,
378,
12,
499,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
12,
334,
16,
12,
959,
12,
488,
12,
499,
395,
413,
430,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
12,
334,
16,
12,
959,
12,
378,
12,
499,
395,
221,
413,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
378,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
59,
16,
12,
378,
12,
488,
12,
499,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
12,
334,
16,
12,
378,
12,
488,
12,
499,
395,
413,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
709,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
1616,
12,
959,
430,
267,
282,
275,
980,
14,
4250,
779,
17,
12,
378,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
709,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
1616,
12,
959,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
1590,
14,
1144,
8,
709,
3948,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
980,
14,
1144,
8,
709,
395,
959,
430,
267,
282,
275,
980,
14,
4250,
779,
17,
12,
378,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
1590,
14,
1144,
8,
709,
3948,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
980,
14,
1144,
8,
709,
395,
959,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
1590,
14,
1144,
779,
709,
24310,
267,
702,
63,
3536,
8
] |
[
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
7640,
12,
1255,
63,
578,
63,
5768,
12,
702,
63,
3536,
199,
199,
533,
1379,
2681,
9298,
8,
1746,
304,
272,
1449,
2925,
370,
26511,
1478,
2550,
440,
24295,
701,
1163,
2295,
10595,
339,
347,
511,
63,
1144,
1313,
63,
7015,
11066,
8,
277,
304,
267,
283,
11066,
687,
282,
378,
13,
1267,
6240,
7,
267,
671,
275,
980,
14,
1667,
1332,
18,
12,
650,
12,
378,
12,
841,
430,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
16,
467,
3114,
29,
18,
9,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
17,
467,
3114,
29,
18,
9,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
16,
467,
3114,
29,
18,
12,
818,
534,
3823,
358,
267,
702,
63,
3536,
8,
12129,
12,
671,
14,
11066,
12,
359,
16,
467,
3114,
29,
18,
12,
818,
534,
7548,
358,
339,
347,
511,
63,
11066,
63,
504,
63,
785,
8,
277,
304,
267,
327,
2670,
1919,
16466,
687,
909,
1625,
267,
366,
275,
980,
14,
4250,
8,
21,
12,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
22,
566,
398,
327,
2670,
1919,
16466,
687,
378,
13,
68,
1625,
267,
366,
275,
980,
14,
4250,
1332,
21,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
17,
467,
3114,
29,
17,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
467,
3114,
29,
17,
9,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
566,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
467,
818,
534,
3823,
358,
267,
702,
63,
3536,
8,
12129,
12,
366,
14,
11066,
12,
359,
16,
467,
818,
534,
7548,
358,
339,
347,
511,
63,
3029,
1080,
63,
3924,
8,
277,
304,
267,
282,
275,
980,
14,
1667,
8,
21,
12,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
12,
3388,
9,
267,
282,
275,
980,
14,
1667,
1332,
21,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
12,
334,
16,
12,
378,
430,
398,
282,
275,
980,
14,
1667,
8,
21,
12,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
409,
12,
3388,
12,
378,
9,
267,
282,
275,
980,
14,
1667,
1332,
21,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
1053,
409,
12,
334,
16,
12,
378,
395,
378,
9,
339,
347,
511,
63,
524,
63,
3924,
8,
277,
304,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
430,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
12,
378,
430,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
267,
282,
275,
980,
14,
4250,
1332,
21,
12,
959,
12,
378,
395,
2152,
29,
785,
9,
267,
702,
63,
3536,
8,
12129,
12,
282,
14,
524,
12,
2948,
12,
378,
9,
339,
347,
511,
63,
1661,
2750,
63,
3924,
8,
277,
304,
267,
298,
9403,
315,
28241,
14,
67,
2,
267,
347,
5090,
8,
1113,
12,
7654,
12,
1139,
304,
288,
1559,
59,
688,
61,
275,
1139,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
59,
16,
12,
959,
12,
488,
12,
499,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
59,
16,
12,
959,
12,
378,
12,
499,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
12,
334,
16,
12,
959,
12,
488,
12,
499,
395,
413,
430,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
12,
334,
16,
12,
959,
12,
378,
12,
499,
395,
221,
413,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
378,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
59,
16,
12,
378,
12,
488,
12,
499,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
12,
334,
16,
12,
378,
12,
488,
12,
499,
395,
413,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
709,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
1616,
12,
959,
430,
267,
282,
275,
980,
14,
4250,
779,
17,
12,
378,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
709,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
1616,
12,
959,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
1590,
14,
1144,
8,
709,
3948,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
980,
14,
1144,
8,
709,
395,
959,
430,
267,
282,
275,
980,
14,
4250,
779,
17,
12,
378,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
1590,
14,
1144,
8,
709,
3948,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
5090,
8,
65,
14,
7088,
12,
980,
14,
1144,
8,
709,
395,
959,
430,
398,
282,
275,
980,
14,
4250,
779,
17,
12,
499,
12,
650,
566,
267,
702,
63,
3536,
8,
12129,
12,
2400,
26,
282,
14,
7088,
59,
1590,
14,
1144,
779,
709,
24310,
267,
702,
63,
3536,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Just-D/chromium-1
|
tools/run-bisect-manual-test.py
|
9
|
6350
|
#!/usr/bin/env python
# Copyright 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.
"""Run Manual Test Bisect Tool
An example usage:
tools/run-bisect-manual-test.py -g 201281 -b 201290
On Linux platform, follow the instructions in this document
https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
to setup the sandbox manually before running the script. Otherwise the script
fails to launch Chrome and exits with an error.
This script serves a similar function to bisect-builds.py, except it uses
the bisect_perf_regression.py. This means that that it can obtain builds of
Chromium for revisions where builds aren't available in cloud storage.
"""
import os
import subprocess
import sys
CROS_BOARD_ENV = 'BISECT_CROS_BOARD'
CROS_IP_ENV = 'BISECT_CROS_IP'
_TOOLS_DIR = os.path.abspath(os.path.dirname(__file__))
_BISECT_SCRIPT_PATH = os.path.join(
_TOOLS_DIR, 'auto_bisect', 'bisect_perf_regression.py')
sys.path.append(os.path.join(_TOOLS_DIR, 'telemetry'))
from telemetry.internal.browser import browser_options
def _RunBisectionScript(options):
"""Attempts to execute the bisect script (bisect_perf_regression.py).
Args:
options: The configuration options to pass to the bisect script.
Returns:
An exit code; 0 for success, 1 for failure.
"""
script_path = os.path.join(options.working_directory,
'bisect', 'src', 'tools','bisect-manual-test.py')
abs_script_path = os.path.abspath(script_path)
test_command = ('python %s --browser=%s --chrome-root=.' %
(abs_script_path, options.browser_type))
cmd = ['python', _BISECT_SCRIPT_PATH,
'-c', test_command,
'-g', options.good_revision,
'-b', options.bad_revision,
'-m', 'manual_test/manual_test',
'-r', '1',
'--working_directory', options.working_directory,
'--build_preference', 'ninja',
'--no_custom_deps',
'--builder_type', options.builder_type]
if options.extra_src:
cmd.extend(['--extra_src', options.extra_src])
if 'cros' in options.browser_type:
cmd.extend(['--target_platform', 'cros'])
if os.environ[CROS_BOARD_ENV] and os.environ[CROS_IP_ENV]:
cmd.extend(['--cros_board', os.environ[CROS_BOARD_ENV]])
cmd.extend(['--cros_remote_ip', os.environ[CROS_IP_ENV]])
else:
print ('Error: Cros build selected, but BISECT_CROS_IP or'
'BISECT_CROS_BOARD undefined.\n')
return 1
elif 'android-chrome' == options.browser_type:
if not options.extra_src:
print 'Error: Missing --extra_src to run bisect for android-chrome.'
sys.exit(-1)
cmd.extend(['--target_platform', 'android-chrome'])
elif 'android' in options.browser_type:
cmd.extend(['--target_platform', 'android'])
elif not options.target_build_type:
cmd.extend(['--target_build_type', options.browser_type.title()])
if options.target_build_type:
cmd.extend(['--target_build_type', options.target_build_type])
if options.goma_threads:
cmd.extend(['--use_goma', '--goma_threads', options.goma_threads])
cmd = [str(c) for c in cmd]
return_code = subprocess.call(cmd)
if return_code:
print 'Error: bisect_perf_regression.py had exit code %d.' % return_code
print
return return_code
def main():
"""Does a bisect based on the command-line arguments passed in.
The user will be prompted to classify each revision as good or bad.
"""
usage = ('%prog [options]\n'
'Used to run the bisection script with a manual test.')
options = browser_options.BrowserFinderOptions('release')
parser = options.CreateParser(usage)
parser.add_option('-b', '--bad_revision',
type='str',
help='A bad revision to start bisection. ' +
'Must be later than good revision. May be either a git' +
' or svn revision.')
parser.add_option('-g', '--good_revision',
type='str',
help='A revision to start bisection where performance' +
' test is known to pass. Must be earlier than the ' +
'bad revision. May be either a git or svn revision.')
parser.add_option('-w', '--working_directory',
type='str',
default='..',
help='A working directory to supply to the bisection '
'script, which will use it as the location to checkout '
'a copy of the chromium depot.')
parser.add_option('--extra_src',
type='str',
help='Path to extra source file. If this is supplied, '
'bisect script will use this to override default behavior.')
parser.add_option('--target_build_type',
type='choice',
choices=['Release', 'Debug'],
help='The target build type. Choices are "Release" '
'or "Debug".')
parser.add_option('--goma_threads', default=64,
type='int',
help='Number of goma threads to use. 0 will disable goma.')
parser.add_option('--builder_type', default='',
choices=['perf',
'full',
'android-chrome-perf', ''],
help='Type of builder to get build from. This allows '
'script to use cached builds. By default (empty), binaries '
'are built locally.')
options, _ = parser.parse_args()
error_msg = ''
if not options.good_revision:
error_msg += 'Error: missing required parameter: --good_revision\n'
if not options.bad_revision:
error_msg += 'Error: missing required parameter: --bad_revision\n'
if error_msg:
print error_msg
parser.print_help()
return 1
if 'android' not in options.browser_type and sys.platform.startswith('linux'):
if not os.environ.get('CHROME_DEVEL_SANDBOX'):
print 'SUID sandbox has not been setup.'\
' See https://code.google.com/p/chromium/wiki/'\
'LinuxSUIDSandboxDevelopment for more information.'
return 1
return _RunBisectionScript(options)
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
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,
2540,
30247,
1379,
699,
13133,
15650,
199,
199,
2493,
2893,
4503,
26,
199,
2537,
15,
1065,
13,
23247,
13,
9285,
13,
396,
14,
647,
446,
71,
1784,
16263,
446,
66,
1784,
15117,
199,
199,
3314,
10130,
4298,
12,
2035,
314,
15794,
315,
642,
2213,
199,
2859,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
13211,
15,
6797,
15,
14091,
6195,
20857,
10075,
23753,
199,
475,
3272,
314,
19699,
10250,
2544,
3879,
314,
2884,
14,
6630,
314,
2884,
199,
15762,
370,
10623,
16776,
436,
20100,
543,
376,
1125,
14,
199,
199,
2765,
2884,
23739,
282,
8545,
805,
370,
19063,
13,
10838,
14,
647,
12,
871,
652,
4440,
199,
1589,
19063,
63,
9452,
63,
12513,
14,
647,
14,
961,
4910,
626,
626,
652,
883,
3332,
14723,
402,
199,
29381,
367,
22164,
2382,
14723,
10621,
1133,
2808,
315,
8002,
4887,
14,
199,
624,
199,
199,
646,
747,
199,
646,
3873,
199,
646,
984,
199,
199,
35,
1092,
51,
63,
23368,
63,
9984,
275,
283,
34,
4971,
1028,
63,
35,
1092,
51,
63,
23368,
7,
199,
35,
1092,
51,
63,
1772,
63,
9984,
275,
283,
34,
4971,
1028,
63,
35,
1092,
51,
63,
1772,
7,
199,
63,
20261,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
63,
34,
4971,
1028,
63,
10484,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
272,
485,
20261,
63,
3022,
12,
283,
2495,
63,
23247,
297,
283,
23247,
63,
9452,
63,
12513,
14,
647,
358,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
1547,
20261,
63,
3022,
12,
283,
15253,
10987,
1333,
199,
504,
17298,
14,
4672,
14,
5750,
492,
7042,
63,
1419,
421,
199,
318,
485,
2540,
34,
572,
414,
5229,
8,
1419,
304,
523,
408,
15322,
1086,
370,
5341,
314,
19063,
2884,
334,
23247,
63,
9452,
63,
12513,
14,
647,
680,
819,
3033,
26,
272,
1511,
26,
710,
2897,
1511,
370,
986,
370,
314,
19063,
2884,
14,
819,
1803,
26,
272,
1626,
4458,
1233,
27,
378,
367,
3182,
12,
413,
367,
5988,
14,
523,
408,
523,
2884,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1419,
14,
9818,
63,
3619,
12,
489,
283,
23247,
297,
283,
2164,
297,
283,
2537,
1673,
23247,
13,
9285,
13,
396,
14,
647,
358,
523,
2853,
63,
1579,
63,
515,
275,
747,
14,
515,
14,
4832,
8,
1579,
63,
515,
9,
819,
511,
63,
1531,
275,
661,
1548,
450,
83,
1553,
5750,
2458,
83,
1553,
9887,
13,
1231,
29,
3530,
450,
2116,
334,
2101,
63,
1579,
63,
515,
12,
1511,
14,
5750,
63,
466,
430,
819,
2088,
275,
788,
1548,
297,
485,
34,
4971,
1028,
63,
10484,
63,
3243,
12,
268,
2475,
67,
297,
511,
63,
1531,
12,
268,
2475,
71,
297,
1511,
14,
8302,
63,
5792,
12,
268,
2475,
66,
297,
1511,
14,
4087,
63,
5792,
12,
268,
2475,
77,
297,
283,
9285,
63,
396,
15,
9285,
63,
396,
297,
268,
2475,
82,
297,
283,
17,
297,
268,
2850,
9818,
63,
3619,
297,
1511,
14,
9818,
63,
3619,
12,
268,
2850,
1506,
63,
14994,
297,
283,
8675,
297,
268,
2850,
889,
63,
4229,
63,
5846,
297,
268,
2850,
5649,
63,
466,
297,
1511,
14,
5649,
63,
466,
61,
819,
340,
1511,
14,
2911,
63,
2164,
26,
272,
2088,
14,
2880,
18510,
2911,
63,
2164,
297,
1511,
14,
2911,
63,
2164,
566,
819,
340,
283,
20363,
7,
315,
1511,
14,
5750,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
3246,
297,
283,
20363,
1105,
339,
340,
747,
14,
2314,
59,
35,
1092,
51,
63,
23368,
63,
9984,
61,
436,
747,
14,
2314,
59,
35,
1092,
51,
63,
1772,
63,
9984,
2189,
489,
2088,
14,
2880,
18510,
20363,
63,
3576,
297,
747,
14,
2314,
59,
35,
1092,
51,
63,
23368,
63,
9984,
3934,
489,
2088,
14,
2880,
18510,
20363,
63,
3846,
63,
711,
297,
747,
14,
2314,
59,
35,
1092,
51,
63,
1772,
63,
9984,
3934,
272,
587,
26,
489,
870,
661,
547,
26,
445,
4796,
1900,
4895,
12,
1325,
699,
4971,
1028,
63,
35,
1092,
51,
63,
1772,
503,
7,
1467,
283,
34,
4971,
1028,
63,
35,
1092,
51,
63,
23368,
10942,
3134,
78,
358,
489,
372,
413,
523,
916,
283,
6238,
13,
9887,
7,
508,
1511,
14,
5750,
63,
466,
26,
272,
340,
440,
1511,
14,
2911,
63,
2164,
26,
489,
870,
283,
547,
26,
15626,
1553,
2911,
63,
2164,
370,
1255,
19063,
367,
15516,
13,
9887,
3530,
489,
984,
14,
2224,
2801,
17,
9,
272,
2088,
14,
2880,
18510,
1375,
63,
3246,
297,
283,
6238,
13,
9887,
1105,
523,
916,
283,
6238,
7,
315,
1511,
14,
5750,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
3246,
297,
283,
6238,
1105,
523,
916,
440,
1511,
14,
1375,
63,
1506,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
1506,
63,
466,
297,
1511,
14,
5750,
63,
466,
14,
1213,
9383,
819,
340,
1511,
14,
1375,
63,
1506,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
1506,
63,
466,
297,
1511,
14,
1375,
63,
1506,
63,
466,
566,
819,
340,
1511,
14,
1939,
391,
63,
6962,
26,
272,
2088,
14,
2880,
18510,
1180,
63,
1939,
391,
297,
2850,
1939,
391,
63,
6962,
297,
1511,
14,
1939,
391,
63,
6962,
566,
819,
2088,
275,
359,
495,
8,
67,
9,
367,
286,
315,
2088,
61,
819,
372,
63,
600,
275,
3873,
14,
1250,
8,
1760,
9,
819,
340,
372,
63,
600,
26,
272,
870,
283,
547,
26,
19063,
63,
9452,
63,
12513,
14,
647,
10530,
4458,
1233,
450,
68,
3530,
450,
372,
63,
600,
272,
870,
819,
372,
372,
63,
600,
421,
199,
318,
2446,
837,
523,
408,
6586,
282,
19063,
4079,
641,
314,
1414,
13,
604,
2368,
3032,
315,
14,
819,
710,
922,
911,
506,
21652,
471,
370,
28837,
1924,
6974,
465,
6954,
503,
4875,
14,
523,
408,
523,
4503,
275,
16651,
6595,
359
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
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,
2540,
30247,
1379,
699,
13133,
15650,
199,
199,
2493,
2893,
4503,
26,
199,
2537,
15,
1065,
13,
23247,
13,
9285,
13,
396,
14,
647,
446,
71,
1784,
16263,
446,
66,
1784,
15117,
199,
199,
3314,
10130,
4298,
12,
2035,
314,
15794,
315,
642,
2213,
199,
2859,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
13211,
15,
6797,
15,
14091,
6195,
20857,
10075,
23753,
199,
475,
3272,
314,
19699,
10250,
2544,
3879,
314,
2884,
14,
6630,
314,
2884,
199,
15762,
370,
10623,
16776,
436,
20100,
543,
376,
1125,
14,
199,
199,
2765,
2884,
23739,
282,
8545,
805,
370,
19063,
13,
10838,
14,
647,
12,
871,
652,
4440,
199,
1589,
19063,
63,
9452,
63,
12513,
14,
647,
14,
961,
4910,
626,
626,
652,
883,
3332,
14723,
402,
199,
29381,
367,
22164,
2382,
14723,
10621,
1133,
2808,
315,
8002,
4887,
14,
199,
624,
199,
199,
646,
747,
199,
646,
3873,
199,
646,
984,
199,
199,
35,
1092,
51,
63,
23368,
63,
9984,
275,
283,
34,
4971,
1028,
63,
35,
1092,
51,
63,
23368,
7,
199,
35,
1092,
51,
63,
1772,
63,
9984,
275,
283,
34,
4971,
1028,
63,
35,
1092,
51,
63,
1772,
7,
199,
63,
20261,
63,
3022,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
63,
34,
4971,
1028,
63,
10484,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
272,
485,
20261,
63,
3022,
12,
283,
2495,
63,
23247,
297,
283,
23247,
63,
9452,
63,
12513,
14,
647,
358,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
1547,
20261,
63,
3022,
12,
283,
15253,
10987,
1333,
199,
504,
17298,
14,
4672,
14,
5750,
492,
7042,
63,
1419,
421,
199,
318,
485,
2540,
34,
572,
414,
5229,
8,
1419,
304,
523,
408,
15322,
1086,
370,
5341,
314,
19063,
2884,
334,
23247,
63,
9452,
63,
12513,
14,
647,
680,
819,
3033,
26,
272,
1511,
26,
710,
2897,
1511,
370,
986,
370,
314,
19063,
2884,
14,
819,
1803,
26,
272,
1626,
4458,
1233,
27,
378,
367,
3182,
12,
413,
367,
5988,
14,
523,
408,
523,
2884,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1419,
14,
9818,
63,
3619,
12,
489,
283,
23247,
297,
283,
2164,
297,
283,
2537,
1673,
23247,
13,
9285,
13,
396,
14,
647,
358,
523,
2853,
63,
1579,
63,
515,
275,
747,
14,
515,
14,
4832,
8,
1579,
63,
515,
9,
819,
511,
63,
1531,
275,
661,
1548,
450,
83,
1553,
5750,
2458,
83,
1553,
9887,
13,
1231,
29,
3530,
450,
2116,
334,
2101,
63,
1579,
63,
515,
12,
1511,
14,
5750,
63,
466,
430,
819,
2088,
275,
788,
1548,
297,
485,
34,
4971,
1028,
63,
10484,
63,
3243,
12,
268,
2475,
67,
297,
511,
63,
1531,
12,
268,
2475,
71,
297,
1511,
14,
8302,
63,
5792,
12,
268,
2475,
66,
297,
1511,
14,
4087,
63,
5792,
12,
268,
2475,
77,
297,
283,
9285,
63,
396,
15,
9285,
63,
396,
297,
268,
2475,
82,
297,
283,
17,
297,
268,
2850,
9818,
63,
3619,
297,
1511,
14,
9818,
63,
3619,
12,
268,
2850,
1506,
63,
14994,
297,
283,
8675,
297,
268,
2850,
889,
63,
4229,
63,
5846,
297,
268,
2850,
5649,
63,
466,
297,
1511,
14,
5649,
63,
466,
61,
819,
340,
1511,
14,
2911,
63,
2164,
26,
272,
2088,
14,
2880,
18510,
2911,
63,
2164,
297,
1511,
14,
2911,
63,
2164,
566,
819,
340,
283,
20363,
7,
315,
1511,
14,
5750,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
3246,
297,
283,
20363,
1105,
339,
340,
747,
14,
2314,
59,
35,
1092,
51,
63,
23368,
63,
9984,
61,
436,
747,
14,
2314,
59,
35,
1092,
51,
63,
1772,
63,
9984,
2189,
489,
2088,
14,
2880,
18510,
20363,
63,
3576,
297,
747,
14,
2314,
59,
35,
1092,
51,
63,
23368,
63,
9984,
3934,
489,
2088,
14,
2880,
18510,
20363,
63,
3846,
63,
711,
297,
747,
14,
2314,
59,
35,
1092,
51,
63,
1772,
63,
9984,
3934,
272,
587,
26,
489,
870,
661,
547,
26,
445,
4796,
1900,
4895,
12,
1325,
699,
4971,
1028,
63,
35,
1092,
51,
63,
1772,
503,
7,
1467,
283,
34,
4971,
1028,
63,
35,
1092,
51,
63,
23368,
10942,
3134,
78,
358,
489,
372,
413,
523,
916,
283,
6238,
13,
9887,
7,
508,
1511,
14,
5750,
63,
466,
26,
272,
340,
440,
1511,
14,
2911,
63,
2164,
26,
489,
870,
283,
547,
26,
15626,
1553,
2911,
63,
2164,
370,
1255,
19063,
367,
15516,
13,
9887,
3530,
489,
984,
14,
2224,
2801,
17,
9,
272,
2088,
14,
2880,
18510,
1375,
63,
3246,
297,
283,
6238,
13,
9887,
1105,
523,
916,
283,
6238,
7,
315,
1511,
14,
5750,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
3246,
297,
283,
6238,
1105,
523,
916,
440,
1511,
14,
1375,
63,
1506,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
1506,
63,
466,
297,
1511,
14,
5750,
63,
466,
14,
1213,
9383,
819,
340,
1511,
14,
1375,
63,
1506,
63,
466,
26,
272,
2088,
14,
2880,
18510,
1375,
63,
1506,
63,
466,
297,
1511,
14,
1375,
63,
1506,
63,
466,
566,
819,
340,
1511,
14,
1939,
391,
63,
6962,
26,
272,
2088,
14,
2880,
18510,
1180,
63,
1939,
391,
297,
2850,
1939,
391,
63,
6962,
297,
1511,
14,
1939,
391,
63,
6962,
566,
819,
2088,
275,
359,
495,
8,
67,
9,
367,
286,
315,
2088,
61,
819,
372,
63,
600,
275,
3873,
14,
1250,
8,
1760,
9,
819,
340,
372,
63,
600,
26,
272,
870,
283,
547,
26,
19063,
63,
9452,
63,
12513,
14,
647,
10530,
4458,
1233,
450,
68,
3530,
450,
372,
63,
600,
272,
870,
819,
372,
372,
63,
600,
421,
199,
318,
2446,
837,
523,
408,
6586,
282,
19063,
4079,
641,
314,
1414,
13,
604,
2368,
3032,
315,
14,
819,
710,
922,
911,
506,
21652,
471,
370,
28837,
1924,
6974,
465,
6954,
503,
4875,
14,
523,
408,
523,
4503,
275,
16651,
6595,
359,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Ziqi-Li/bknqgis
|
pandas/pandas/tests/io/test_packers.py
|
7
|
31902
|
import pytest
from warnings import catch_warnings
import os
import datetime
import numpy as np
import sys
from distutils.version import LooseVersion
from pandas import compat
from pandas.compat import u, PY3
from pandas import (Series, DataFrame, Panel, MultiIndex, bdate_range,
date_range, period_range, Index, Categorical)
from pandas.errors import PerformanceWarning
from pandas.io.packers import to_msgpack, read_msgpack
import pandas.util.testing as tm
from pandas.util.testing import (ensure_clean,
assert_categorical_equal,
assert_frame_equal,
assert_index_equal,
assert_series_equal,
patch)
from pandas.tests.test_panel import assert_panel_equal
import pandas
from pandas import Timestamp, NaT
from pandas._libs.tslib import iNaT
nan = np.nan
try:
import blosc # NOQA
except ImportError:
_BLOSC_INSTALLED = False
else:
_BLOSC_INSTALLED = True
try:
import zlib # NOQA
except ImportError:
_ZLIB_INSTALLED = False
else:
_ZLIB_INSTALLED = True
@pytest.fixture(scope='module')
def current_packers_data():
# our current version packers data
from pandas.tests.io.generate_legacy_storage_files import (
create_msgpack_data)
return create_msgpack_data()
@pytest.fixture(scope='module')
def all_packers_data():
# our all of our current version packers data
from pandas.tests.io.generate_legacy_storage_files import (
create_data)
return create_data()
def check_arbitrary(a, b):
if isinstance(a, (list, tuple)) and isinstance(b, (list, tuple)):
assert(len(a) == len(b))
for a_, b_ in zip(a, b):
check_arbitrary(a_, b_)
elif isinstance(a, Panel):
assert_panel_equal(a, b)
elif isinstance(a, DataFrame):
assert_frame_equal(a, b)
elif isinstance(a, Series):
assert_series_equal(a, b)
elif isinstance(a, Index):
assert_index_equal(a, b)
elif isinstance(a, Categorical):
# Temp,
# Categorical.categories is changed from str to bytes in PY3
# maybe the same as GH 13591
if PY3 and b.categories.inferred_type == 'string':
pass
else:
tm.assert_categorical_equal(a, b)
elif a is NaT:
assert b is NaT
elif isinstance(a, Timestamp):
assert a == b
assert a.freq == b.freq
else:
assert(a == b)
class TestPackers(object):
def setup_method(self, method):
self.path = '__%s__.msg' % tm.rands(10)
def teardown_method(self, method):
pass
def encode_decode(self, x, compress=None, **kwargs):
with ensure_clean(self.path) as p:
to_msgpack(p, x, compress=compress, **kwargs)
return read_msgpack(p, **kwargs)
class TestAPI(TestPackers):
def test_string_io(self):
df = DataFrame(np.random.randn(10, 2))
s = df.to_msgpack(None)
result = read_msgpack(s)
tm.assert_frame_equal(result, df)
s = df.to_msgpack()
result = read_msgpack(s)
tm.assert_frame_equal(result, df)
s = df.to_msgpack()
result = read_msgpack(compat.BytesIO(s))
tm.assert_frame_equal(result, df)
s = to_msgpack(None, df)
result = read_msgpack(s)
tm.assert_frame_equal(result, df)
with ensure_clean(self.path) as p:
s = df.to_msgpack()
fh = open(p, 'wb')
fh.write(s)
fh.close()
result = read_msgpack(p)
tm.assert_frame_equal(result, df)
def test_path_pathlib(self):
df = tm.makeDataFrame()
result = tm.round_trip_pathlib(df.to_msgpack, read_msgpack)
tm.assert_frame_equal(df, result)
def test_path_localpath(self):
df = tm.makeDataFrame()
result = tm.round_trip_localpath(df.to_msgpack, read_msgpack)
tm.assert_frame_equal(df, result)
def test_iterator_with_string_io(self):
dfs = [DataFrame(np.random.randn(10, 2)) for i in range(5)]
s = to_msgpack(None, *dfs)
for i, result in enumerate(read_msgpack(s, iterator=True)):
tm.assert_frame_equal(result, dfs[i])
def test_invalid_arg(self):
# GH10369
class A(object):
def __init__(self):
self.read = 0
pytest.raises(ValueError, read_msgpack, path_or_buf=None)
pytest.raises(ValueError, read_msgpack, path_or_buf={})
pytest.raises(ValueError, read_msgpack, path_or_buf=A())
class TestNumpy(TestPackers):
def test_numpy_scalar_float(self):
x = np.float32(np.random.rand())
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
def test_numpy_scalar_complex(self):
x = np.complex64(np.random.rand() + 1j * np.random.rand())
x_rec = self.encode_decode(x)
assert np.allclose(x, x_rec)
def test_scalar_float(self):
x = np.random.rand()
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
def test_scalar_complex(self):
x = np.random.rand() + 1j * np.random.rand()
x_rec = self.encode_decode(x)
assert np.allclose(x, x_rec)
def test_list_numpy_float(self):
x = [np.float32(np.random.rand()) for i in range(5)]
x_rec = self.encode_decode(x)
# current msgpack cannot distinguish list/tuple
tm.assert_almost_equal(tuple(x), x_rec)
x_rec = self.encode_decode(tuple(x))
tm.assert_almost_equal(tuple(x), x_rec)
def test_list_numpy_float_complex(self):
if not hasattr(np, 'complex128'):
pytest.skip('numpy cant handle complex128')
x = [np.float32(np.random.rand()) for i in range(5)] + \
[np.complex128(np.random.rand() + 1j * np.random.rand())
for i in range(5)]
x_rec = self.encode_decode(x)
assert np.allclose(x, x_rec)
def test_list_float(self):
x = [np.random.rand() for i in range(5)]
x_rec = self.encode_decode(x)
# current msgpack cannot distinguish list/tuple
tm.assert_almost_equal(tuple(x), x_rec)
x_rec = self.encode_decode(tuple(x))
tm.assert_almost_equal(tuple(x), x_rec)
def test_list_float_complex(self):
x = [np.random.rand() for i in range(5)] + \
[(np.random.rand() + 1j * np.random.rand()) for i in range(5)]
x_rec = self.encode_decode(x)
assert np.allclose(x, x_rec)
def test_dict_float(self):
x = {'foo': 1.0, 'bar': 2.0}
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
def test_dict_complex(self):
x = {'foo': 1.0 + 1.0j, 'bar': 2.0 + 2.0j}
x_rec = self.encode_decode(x)
tm.assert_dict_equal(x, x_rec)
for key in x:
tm.assert_class_equal(x[key], x_rec[key], obj="complex value")
def test_dict_numpy_float(self):
x = {'foo': np.float32(1.0), 'bar': np.float32(2.0)}
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
def test_dict_numpy_complex(self):
x = {'foo': np.complex128(1.0 + 1.0j),
'bar': np.complex128(2.0 + 2.0j)}
x_rec = self.encode_decode(x)
tm.assert_dict_equal(x, x_rec)
for key in x:
tm.assert_class_equal(x[key], x_rec[key], obj="numpy complex128")
def test_numpy_array_float(self):
# run multiple times
for n in range(10):
x = np.random.rand(10)
for dtype in ['float32', 'float64']:
x = x.astype(dtype)
x_rec = self.encode_decode(x)
tm.assert_almost_equal(x, x_rec)
def test_numpy_array_complex(self):
x = (np.random.rand(5) + 1j * np.random.rand(5)).astype(np.complex128)
x_rec = self.encode_decode(x)
assert (all(map(lambda x, y: x == y, x, x_rec)) and
x.dtype == x_rec.dtype)
def test_list_mixed(self):
x = [1.0, np.float32(3.5), np.complex128(4.25), u('foo')]
x_rec = self.encode_decode(x)
# current msgpack cannot distinguish list/tuple
tm.assert_almost_equal(tuple(x), x_rec)
x_rec = self.encode_decode(tuple(x))
tm.assert_almost_equal(tuple(x), x_rec)
class TestBasic(TestPackers):
def test_timestamp(self):
for i in [Timestamp(
'20130101'), Timestamp('20130101', tz='US/Eastern'),
Timestamp('201301010501')]:
i_rec = self.encode_decode(i)
assert i == i_rec
def test_nat(self):
nat_rec = self.encode_decode(NaT)
assert NaT is nat_rec
def test_datetimes(self):
# fails under 2.6/win32 (np.datetime64 seems broken)
if LooseVersion(sys.version) < '2.7':
pytest.skip('2.6 with np.datetime64 is broken')
for i in [datetime.datetime(2013, 1, 1),
datetime.datetime(2013, 1, 1, 5, 1),
datetime.date(2013, 1, 1),
np.datetime64(datetime.datetime(2013, 1, 5, 2, 15))]:
i_rec = self.encode_decode(i)
assert i == i_rec
def test_timedeltas(self):
for i in [datetime.timedelta(days=1),
datetime.timedelta(days=1, seconds=10),
np.timedelta64(1000000)]:
i_rec = self.encode_decode(i)
assert i == i_rec
class TestIndex(TestPackers):
def setup_method(self, method):
super(TestIndex, self).setup_method(method)
self.d = {
'string': tm.makeStringIndex(100),
'date': tm.makeDateIndex(100),
'int': tm.makeIntIndex(100),
'rng': tm.makeRangeIndex(100),
'float': tm.makeFloatIndex(100),
'empty': Index([]),
'tuple': Index(zip(['foo', 'bar', 'baz'], [1, 2, 3])),
'period': Index(period_range('2012-1-1', freq='M', periods=3)),
'date2': Index(date_range('2013-01-1', periods=10)),
'bdate': Index(bdate_range('2013-01-02', periods=10)),
'cat': tm.makeCategoricalIndex(100)
}
self.mi = {
'reg': MultiIndex.from_tuples([('bar', 'one'), ('baz', 'two'),
('foo', 'two'),
('qux', 'one'), ('qux', 'two')],
names=['first', 'second']),
}
def test_basic_index(self):
for s, i in self.d.items():
i_rec = self.encode_decode(i)
tm.assert_index_equal(i, i_rec)
# datetime with no freq (GH5506)
i = Index([Timestamp('20130101'), Timestamp('20130103')])
i_rec = self.encode_decode(i)
tm.assert_index_equal(i, i_rec)
# datetime with timezone
i = Index([Timestamp('20130101 9:00:00'), Timestamp(
'20130103 11:00:00')]).tz_localize('US/Eastern')
i_rec = self.encode_decode(i)
tm.assert_index_equal(i, i_rec)
def test_multi_index(self):
for s, i in self.mi.items():
i_rec = self.encode_decode(i)
tm.assert_index_equal(i, i_rec)
def test_unicode(self):
i = tm.makeUnicodeIndex(100)
i_rec = self.encode_decode(i)
tm.assert_index_equal(i, i_rec)
def categorical_index(self):
# GH15487
df = DataFrame(np.random.randn(10, 2))
df = df.astype({0: 'category'}).set_index(0)
result = self.encode_decode(df)
tm.assert_frame_equal(result, df)
class TestSeries(TestPackers):
def setup_method(self, method):
super(TestSeries, self).setup_method(method)
self.d = {}
s = tm.makeStringSeries()
s.name = 'string'
self.d['string'] = s
s = tm.makeObjectSeries()
s.name = 'object'
self.d['object'] = s
s = Series(iNaT, dtype='M8[ns]', index=range(5))
self.d['date'] = s
data = {
'A': [0., 1., 2., 3., np.nan],
'B': [0, 1, 0, 1, 0],
'C': ['foo1', 'foo2', 'foo3', 'foo4', 'foo5'],
'D': date_range('1/1/2009', periods=5),
'E': [0., 1, Timestamp('20100101'), 'foo', 2.],
'F': [Timestamp('20130102', tz='US/Eastern')] * 2 +
[Timestamp('20130603', tz='CET')] * 3,
'G': [Timestamp('20130102', tz='US/Eastern')] * 5,
'H': Categorical([1, 2, 3, 4, 5]),
'I': Categorical([1, 2, 3, 4, 5], ordered=True),
}
self.d['float'] = Series(data['A'])
self.d['int'] = Series(data['B'])
self.d['mixed'] = Series(data['E'])
self.d['dt_tz_mixed'] = Series(data['F'])
self.d['dt_tz'] = Series(data['G'])
self.d['cat_ordered'] = Series(data['H'])
self.d['cat_unordered'] = Series(data['I'])
def test_basic(self):
# run multiple times here
for n in range(10):
for s, i in self.d.items():
i_rec = self.encode_decode(i)
assert_series_equal(i, i_rec)
class TestCategorical(TestPackers):
def setup_method(self, method):
super(TestCategorical, self).setup_method(method)
self.d = {}
self.d['plain_str'] = Categorical(['a', 'b', 'c', 'd', 'e'])
self.d['plain_str_ordered'] = Categorical(['a', 'b', 'c', 'd', 'e'],
ordered=True)
self.d['plain_int'] = Categorical([5, 6, 7, 8])
self.d['plain_int_ordered'] = Categorical([5, 6, 7, 8], ordered=True)
def test_basic(self):
# run multiple times here
for n in range(10):
for s, i in self.d.items():
i_rec = self.encode_decode(i)
assert_categorical_equal(i, i_rec)
class TestNDFrame(TestPackers):
def setup_method(self, method):
super(TestNDFrame, self).setup_method(method)
data = {
'A': [0., 1., 2., 3., np.nan],
'B': [0, 1, 0, 1, 0],
'C': ['foo1', 'foo2', 'foo3', 'foo4', 'foo5'],
'D': date_range('1/1/2009', periods=5),
'E': [0., 1, Timestamp('20100101'), 'foo', 2.],
'F': [Timestamp('20130102', tz='US/Eastern')] * 5,
'G': [Timestamp('20130603', tz='CET')] * 5,
'H': Categorical(['a', 'b', 'c', 'd', 'e']),
'I': Categorical(['a', 'b', 'c', 'd', 'e'], ordered=True),
}
self.frame = {
'float': DataFrame(dict(A=data['A'], B=Series(data['A']) + 1)),
'int': DataFrame(dict(A=data['B'], B=Series(data['B']) + 1)),
'mixed': DataFrame(data)}
with catch_warnings(record=True):
self.panel = {
'float': Panel(dict(ItemA=self.frame['float'],
ItemB=self.frame['float'] + 1))}
def test_basic_frame(self):
for s, i in self.frame.items():
i_rec = self.encode_decode(i)
assert_frame_equal(i, i_rec)
def test_basic_panel(self):
with catch_warnings(record=True):
for s, i in self.panel.items():
i_rec = self.encode_decode(i)
assert_panel_equal(i, i_rec)
def test_multi(self):
i_rec = self.encode_decode(self.frame)
for k in self.frame.keys():
assert_frame_equal(self.frame[k], i_rec[k])
l = tuple([self.frame['float'], self.frame['float'].A,
self.frame['float'].B, None])
l_rec = self.encode_decode(l)
check_arbitrary(l, l_rec)
# this is an oddity in that packed lists will be returned as tuples
l = [self.frame['float'], self.frame['float']
.A, self.frame['float'].B, None]
l_rec = self.encode_decode(l)
assert isinstance(l_rec, tuple)
check_arbitrary(l, l_rec)
def test_iterator(self):
l = [self.frame['float'], self.frame['float']
.A, self.frame['float'].B, None]
with ensure_clean(self.path) as path:
to_msgpack(path, *l)
for i, packed in enumerate(read_msgpack(path, iterator=True)):
check_arbitrary(packed, l[i])
def tests_datetimeindex_freq_issue(self):
# GH 5947
# inferring freq on the datetimeindex
df = DataFrame([1, 2, 3], index=date_range('1/1/2013', '1/3/2013'))
result = self.encode_decode(df)
assert_frame_equal(result, df)
df = DataFrame([1, 2], index=date_range('1/1/2013', '1/2/2013'))
result = self.encode_decode(df)
assert_frame_equal(result, df)
def test_dataframe_duplicate_column_names(self):
# GH 9618
expected_1 = DataFrame(columns=['a', 'a'])
expected_2 = DataFrame(columns=[1] * 100)
expected_2.loc[0] = np.random.randn(100)
expected_3 = DataFrame(columns=[1, 1])
expected_3.loc[0] = ['abc', np.nan]
result_1 = self.encode_decode(expected_1)
result_2 = self.encode_decode(expected_2)
result_3 = self.encode_decode(expected_3)
assert_frame_equal(result_1, expected_1)
assert_frame_equal(result_2, expected_2)
assert_frame_equal(result_3, expected_3)
class TestSparse(TestPackers):
def _check_roundtrip(self, obj, comparator, **kwargs):
# currently these are not implemetned
# i_rec = self.encode_decode(obj)
# comparator(obj, i_rec, **kwargs)
pytest.raises(NotImplementedError, self.encode_decode, obj)
def test_sparse_series(self):
s = tm.makeStringSeries()
s[3:5] = np.nan
ss = s.to_sparse()
self._check_roundtrip(ss, tm.assert_series_equal,
check_series_type=True)
ss2 = s.to_sparse(kind='integer')
self._check_roundtrip(ss2, tm.assert_series_equal,
check_series_type=True)
ss3 = s.to_sparse(fill_value=0)
self._check_roundtrip(ss3, tm.assert_series_equal,
check_series_type=True)
def test_sparse_frame(self):
s = tm.makeDataFrame()
s.loc[3:5, 1:3] = np.nan
s.loc[8:10, -2] = np.nan
ss = s.to_sparse()
self._check_roundtrip(ss, tm.assert_frame_equal,
check_frame_type=True)
ss2 = s.to_sparse(kind='integer')
self._check_roundtrip(ss2, tm.assert_frame_equal,
check_frame_type=True)
ss3 = s.to_sparse(fill_value=0)
self._check_roundtrip(ss3, tm.assert_frame_equal,
check_frame_type=True)
class TestCompression(TestPackers):
"""See https://github.com/pandas-dev/pandas/pull/9783
"""
def setup_method(self, method):
try:
from sqlalchemy import create_engine
self._create_sql_engine = create_engine
except ImportError:
self._SQLALCHEMY_INSTALLED = False
else:
self._SQLALCHEMY_INSTALLED = True
super(TestCompression, self).setup_method(method)
data = {
'A': np.arange(1000, dtype=np.float64),
'B': np.arange(1000, dtype=np.int32),
'C': list(100 * 'abcdefghij'),
'D': date_range(datetime.datetime(2015, 4, 1), periods=1000),
'E': [datetime.timedelta(days=x) for x in range(1000)],
}
self.frame = {
'float': DataFrame(dict((k, data[k]) for k in ['A', 'A'])),
'int': DataFrame(dict((k, data[k]) for k in ['B', 'B'])),
'mixed': DataFrame(data),
}
def test_plain(self):
i_rec = self.encode_decode(self.frame)
for k in self.frame.keys():
assert_frame_equal(self.frame[k], i_rec[k])
def _test_compression(self, compress):
i_rec = self.encode_decode(self.frame, compress=compress)
for k in self.frame.keys():
value = i_rec[k]
expected = self.frame[k]
assert_frame_equal(value, expected)
# make sure that we can write to the new frames
for block in value._data.blocks:
assert block.values.flags.writeable
def test_compression_zlib(self):
if not _ZLIB_INSTALLED:
pytest.skip('no zlib')
self._test_compression('zlib')
def test_compression_blosc(self):
if not _BLOSC_INSTALLED:
pytest.skip('no blosc')
self._test_compression('blosc')
def _test_compression_warns_when_decompress_caches(self, compress):
not_garbage = []
control = [] # copied data
compress_module = globals()[compress]
real_decompress = compress_module.decompress
def decompress(ob):
"""mock decompress function that delegates to the real
decompress but caches the result and a copy of the result.
"""
res = real_decompress(ob)
not_garbage.append(res) # hold a reference to this bytes object
control.append(bytearray(res)) # copy the data here to check later
return res
# types mapped to values to add in place.
rhs = {
np.dtype('float64'): 1.0,
np.dtype('int32'): 1,
np.dtype('object'): 'a',
np.dtype('datetime64[ns]'): np.timedelta64(1, 'ns'),
np.dtype('timedelta64[ns]'): np.timedelta64(1, 'ns'),
}
with patch(compress_module, 'decompress', decompress), \
tm.assert_produces_warning(PerformanceWarning) as ws:
i_rec = self.encode_decode(self.frame, compress=compress)
for k in self.frame.keys():
value = i_rec[k]
expected = self.frame[k]
assert_frame_equal(value, expected)
# make sure that we can write to the new frames even though
# we needed to copy the data
for block in value._data.blocks:
assert block.values.flags.writeable
# mutate the data in some way
block.values[0] += rhs[block.dtype]
for w in ws:
# check the messages from our warnings
assert str(w.message) == ('copying data after decompressing; '
'this may mean that decompress is '
'caching its result')
for buf, control_buf in zip(not_garbage, control):
# make sure none of our mutations above affected the
# original buffers
assert buf == control_buf
def test_compression_warns_when_decompress_caches_zlib(self):
if not _ZLIB_INSTALLED:
pytest.skip('no zlib')
self._test_compression_warns_when_decompress_caches('zlib')
def test_compression_warns_when_decompress_caches_blosc(self):
if not _BLOSC_INSTALLED:
pytest.skip('no blosc')
self._test_compression_warns_when_decompress_caches('blosc')
def _test_small_strings_no_warn(self, compress):
empty = np.array([], dtype='uint8')
with tm.assert_produces_warning(None):
empty_unpacked = self.encode_decode(empty, compress=compress)
tm.assert_numpy_array_equal(empty_unpacked, empty)
assert empty_unpacked.flags.writeable
char = np.array([ord(b'a')], dtype='uint8')
with tm.assert_produces_warning(None):
char_unpacked = self.encode_decode(char, compress=compress)
tm.assert_numpy_array_equal(char_unpacked, char)
assert char_unpacked.flags.writeable
# if this test fails I am sorry because the interpreter is now in a
# bad state where b'a' points to 98 == ord(b'b').
char_unpacked[0] = ord(b'b')
# we compare the ord of bytes b'a' with unicode u'a' because the should
# always be the same (unless we were able to mutate the shared
# character singleton in which case ord(b'a') == ord(b'b').
assert ord(b'a') == ord(u'a')
tm.assert_numpy_array_equal(
char_unpacked,
np.array([ord(b'b')], dtype='uint8'),
)
def test_small_strings_no_warn_zlib(self):
if not _ZLIB_INSTALLED:
pytest.skip('no zlib')
self._test_small_strings_no_warn('zlib')
def test_small_strings_no_warn_blosc(self):
if not _BLOSC_INSTALLED:
pytest.skip('no blosc')
self._test_small_strings_no_warn('blosc')
def test_readonly_axis_blosc(self):
# GH11880
if not _BLOSC_INSTALLED:
pytest.skip('no blosc')
df1 = DataFrame({'A': list('abcd')})
df2 = DataFrame(df1, index=[1., 2., 3., 4.])
assert 1 in self.encode_decode(df1['A'], compress='blosc')
assert 1. in self.encode_decode(df2['A'], compress='blosc')
def test_readonly_axis_zlib(self):
# GH11880
df1 = DataFrame({'A': list('abcd')})
df2 = DataFrame(df1, index=[1., 2., 3., 4.])
assert 1 in self.encode_decode(df1['A'], compress='zlib')
assert 1. in self.encode_decode(df2['A'], compress='zlib')
def test_readonly_axis_blosc_to_sql(self):
# GH11880
if not _BLOSC_INSTALLED:
pytest.skip('no blosc')
if not self._SQLALCHEMY_INSTALLED:
pytest.skip('no sqlalchemy')
expected = DataFrame({'A': list('abcd')})
df = self.encode_decode(expected, compress='blosc')
eng = self._create_sql_engine("sqlite:///:memory:")
df.to_sql('test', eng, if_exists='append')
result = pandas.read_sql_table('test', eng, index_col='index')
result.index.names = [None]
assert_frame_equal(expected, result)
def test_readonly_axis_zlib_to_sql(self):
# GH11880
if not _ZLIB_INSTALLED:
pytest.skip('no zlib')
if not self._SQLALCHEMY_INSTALLED:
pytest.skip('no sqlalchemy')
expected = DataFrame({'A': list('abcd')})
df = self.encode_decode(expected, compress='zlib')
eng = self._create_sql_engine("sqlite:///:memory:")
df.to_sql('test', eng, if_exists='append')
result = pandas.read_sql_table('test', eng, index_col='index')
result.index.names = [None]
assert_frame_equal(expected, result)
class TestEncoding(TestPackers):
def setup_method(self, method):
super(TestEncoding, self).setup_method(method)
data = {
'A': [compat.u('\u2019')] * 1000,
'B': np.arange(1000, dtype=np.int32),
'C': list(100 * 'abcdefghij'),
'D': date_range(datetime.datetime(2015, 4, 1), periods=1000),
'E': [datetime.timedelta(days=x) for x in range(1000)],
'G': [400] * 1000
}
self.frame = {
'float': DataFrame(dict((k, data[k]) for k in ['A', 'A'])),
'int': DataFrame(dict((k, data[k]) for k in ['B', 'B'])),
'mixed': DataFrame(data),
}
self.utf_encodings = ['utf8', 'utf16', 'utf32']
def test_utf(self):
# GH10581
for encoding in self.utf_encodings:
for frame in compat.itervalues(self.frame):
result = self.encode_decode(frame, encoding=encoding)
assert_frame_equal(result, frame)
def test_default_encoding(self):
for frame in compat.itervalues(self.frame):
result = frame.to_msgpack()
expected = frame.to_msgpack(encoding='utf8')
assert result == expected
result = self.encode_decode(frame)
assert_frame_equal(result, frame)
def legacy_packers_versions():
# yield the packers versions
path = tm.get_data_path('legacy_msgpack')
for v in os.listdir(path):
p = os.path.join(path, v)
if os.path.isdir(p):
yield v
class TestMsgpack(object):
"""
How to add msgpack tests:
1. Install pandas version intended to output the msgpack.
TestPackers
2. Execute "generate_legacy_storage_files.py" to create the msgpack.
$ python generate_legacy_storage_files.py <output_dir> msgpack
3. Move the created pickle to "data/legacy_msgpack/<version>" directory.
"""
minimum_structure = {'series': ['float', 'int', 'mixed',
'ts', 'mi', 'dup'],
'frame': ['float', 'int', 'mixed', 'mi'],
'panel': ['float'],
'index': ['int', 'date', 'period'],
'mi': ['reg2']}
def check_min_structure(self, data, version):
for typ, v in self.minimum_structure.items():
assert typ in data, '"{0}" not found in unpacked data'.format(typ)
for kind in v:
msg = '"{0}" not found in data["{1}"]'.format(kind, typ)
assert kind in data[typ], msg
def compare(self, current_data, all_data, vf, version):
# GH12277 encoding default used to be latin-1, now utf-8
if LooseVersion(version) < '0.18.0':
data = read_msgpack(vf, encoding='latin-1')
else:
data = read_msgpack(vf)
self.check_min_structure(data, version)
for typ, dv in data.items():
assert typ in all_data, ('unpacked data contains '
'extra key "{0}"'
.format(typ))
for dt, result in dv.items():
assert dt in current_data[typ], ('data["{0}"] contains extra '
'key "{1}"'.format(typ, dt))
try:
expected = current_data[typ][dt]
except KeyError:
continue
# use a specific comparator
# if available
comp_method = "compare_{typ}_{dt}".format(typ=typ, dt=dt)
comparator = getattr(self, comp_method, None)
if comparator is not None:
comparator(result, expected, typ, version)
else:
check_arbitrary(result, expected)
return data
def compare_series_dt_tz(self, result, expected, typ, version):
# 8260
# dtype is object < 0.17.0
if LooseVersion(version) < '0.17.0':
expected = expected.astype(object)
tm.assert_series_equal(result, expected)
else:
tm.assert_series_equal(result, expected)
def compare_frame_dt_mixed_tzs(self, result, expected, typ, version):
# 8260
# dtype is object < 0.17.0
if LooseVersion(version) < '0.17.0':
expected = expected.astype(object)
tm.assert_frame_equal(result, expected)
else:
tm.assert_frame_equal(result, expected)
@pytest.mark.parametrize('version', legacy_packers_versions())
def test_msgpacks_legacy(self, current_packers_data, all_packers_data,
version):
pth = tm.get_data_path('legacy_msgpack/{0}'.format(version))
n = 0
for f in os.listdir(pth):
# GH12142 0.17 files packed in P2 can't be read in P3
if (compat.PY3 and version.startswith('0.17.') and
f.split('.')[-4][-1] == '2'):
continue
vf = os.path.join(pth, f)
try:
with catch_warnings(record=True):
self.compare(current_packers_data, all_packers_data,
vf, version)
except ImportError:
# blosc not installed
continue
n += 1
assert n > 0, 'Msgpack files are not tested'
|
gpl-2.0
|
[
646,
4613,
199,
199,
504,
3598,
492,
8579,
63,
5451,
199,
646,
747,
199,
646,
2197,
199,
646,
2680,
465,
980,
199,
646,
984,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
10634,
492,
8434,
199,
504,
10634,
14,
5819,
492,
399,
12,
7843,
19,
199,
504,
10634,
492,
334,
9641,
12,
10071,
12,
510,
4822,
12,
6879,
2681,
12,
330,
602,
63,
1842,
12,
490,
1434,
63,
1842,
12,
6247,
63,
1842,
12,
5499,
12,
31227,
9,
199,
504,
10634,
14,
2550,
492,
32117,
3849,
199,
504,
10634,
14,
2308,
14,
1389,
1192,
492,
370,
63,
1328,
1389,
12,
1586,
63,
1328,
1389,
199,
646,
10634,
14,
1974,
14,
4776,
465,
7352,
199,
504,
10634,
14,
1974,
14,
4776,
492,
334,
7505,
63,
3118,
12,
639,
702,
63,
16810,
63,
1452,
12,
639,
702,
63,
1943,
63,
1452,
12,
639,
702,
63,
1080,
63,
1452,
12,
639,
702,
63,
5602,
63,
1452,
12,
639,
3371,
9,
199,
504,
10634,
14,
2219,
14,
396,
63,
7885,
492,
702,
63,
7885,
63,
1452,
199,
199,
646,
10634,
199,
504,
10634,
492,
18267,
12,
11290,
52,
199,
504,
10634,
423,
8450,
14,
1086,
773,
492,
284,
25638,
199,
199,
4304,
275,
980,
14,
4304,
199,
199,
893,
26,
272,
492,
32580,
551,
221,
327,
20432,
199,
2590,
3545,
26,
272,
485,
34,
1484,
5153,
63,
15942,
275,
756,
199,
2836,
26,
272,
485,
34,
1484,
5153,
63,
15942,
275,
715,
199,
199,
893,
26,
272,
492,
12472,
221,
327,
20432,
199,
2590,
3545,
26,
272,
485,
58,
5617,
63,
15942,
275,
756,
199,
2836,
26,
272,
485,
58,
5617,
63,
15942,
275,
715,
421,
199,
32,
4462,
14,
5997,
8,
2645,
534,
578,
358,
199,
318,
1453,
63,
1389,
1192,
63,
576,
837,
272,
327,
4154,
1453,
1015,
1706,
1192,
666,
272,
687,
10634,
14,
2219,
14,
2308,
14,
4208,
63,
10000,
63,
3494,
63,
1725,
492,
334,
267,
1218,
63,
1328,
1389,
63,
576,
9,
272,
372,
1218,
63,
1328,
1389,
63,
576,
342,
421,
199,
32,
4462,
14,
5997,
8,
2645,
534,
578,
358,
199,
318,
1006,
63,
1389,
1192,
63,
576,
837,
272,
327,
4154,
1006,
402,
4154,
1453,
1015,
1706,
1192,
666,
272,
687,
10634,
14,
2219,
14,
2308,
14,
4208,
63,
10000,
63,
3494,
63,
1725,
492,
334,
267,
1218,
63,
576,
9,
272,
372,
1218,
63,
576,
342,
421,
199,
318,
1104,
63,
285,
8734,
8,
65,
12,
330,
304,
339,
340,
1228,
8,
65,
12,
334,
513,
12,
2008,
430,
436,
1228,
8,
66,
12,
334,
513,
12,
2008,
2298,
267,
702,
8,
552,
8,
65,
9,
508,
822,
8,
66,
430,
267,
367,
282,
3131,
330,
63,
315,
3482,
8,
65,
12,
330,
304,
288,
1104,
63,
285,
8734,
8,
65,
3131,
330,
4602,
272,
916,
1228,
8,
65,
12,
510,
4822,
304,
267,
702,
63,
7885,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
10071,
304,
267,
702,
63,
1943,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
12403,
304,
267,
702,
63,
5602,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
5499,
304,
267,
702,
63,
1080,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
31227,
304,
267,
327,
12540,
12,
267,
327,
31227,
14,
8906,
365,
2896,
687,
620,
370,
2783,
315,
7843,
19,
267,
327,
11703,
314,
2011,
465,
20321,
23051,
3328,
267,
340,
7843,
19,
436,
330,
14,
8906,
14,
262,
5057,
63,
466,
508,
283,
875,
356,
288,
986,
267,
587,
26,
288,
7352,
14,
479,
63,
16810,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
282,
365,
11290,
52,
26,
267,
702,
330,
365,
11290,
52,
272,
916,
1228,
8,
65,
12,
18267,
304,
267,
702,
282,
508,
330,
267,
702,
282,
14,
5646,
508,
330,
14,
5646,
272,
587,
26,
267,
702,
8,
65,
508,
330,
9,
421,
199,
533,
1379,
2305,
1192,
8,
785,
304,
339,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
291,
14,
515,
275,
2560,
5,
83,
4343,
1328,
7,
450,
7352,
14,
3759,
83,
8,
709,
9,
339,
347,
17558,
63,
765,
8,
277,
12,
1083,
304,
267,
986,
339,
347,
3752,
63,
2708,
8,
277,
12,
671,
12,
11029,
29,
403,
12,
1011,
958,
304,
267,
543,
4868,
63,
3118,
8,
277,
14,
515,
9,
465,
299,
26,
288,
370,
63,
1328,
1389,
8,
80,
12,
671,
12,
11029,
29,
6447,
12,
1011,
958,
9,
288,
372,
1586,
63,
1328,
1389,
8,
80,
12,
1011,
958,
9,
421,
199,
533,
1379,
3735,
8,
774,
2305,
1192,
304,
339,
347,
511,
63,
875,
63,
2308,
8,
277,
304,
398,
4051,
275,
10071,
8,
1590,
14,
2355,
14,
10843,
8,
709,
12,
499,
430,
267,
308,
275,
4051,
14,
475,
63,
1328,
1389,
8,
403,
9,
267,
754,
275,
1586,
63,
1328,
1389,
8,
83,
9,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
308,
275,
4051,
14,
475,
63,
1328,
1389,
342,
267,
754,
275,
1586,
63,
1328,
1389,
8,
83,
9,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
308,
275,
4051,
14,
475,
63,
1328,
1389,
342,
267,
754,
275,
1586,
63,
1328,
1389,
8,
5819,
14,
15466,
8,
83,
430,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
308,
275,
370,
63,
1328,
1389,
8,
403,
12,
4051,
9,
267,
754,
275,
1586,
63,
1328,
1389,
8,
83,
9,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
543,
4868,
63,
3118,
8,
277,
14,
515,
9,
465,
299,
26,
953,
308,
275,
4051,
14,
475,
63,
1328,
1389,
342,
288,
11155,
275,
1551,
8,
80,
12,
283,
6603,
358,
288,
11155,
14,
952,
8,
83,
9,
288,
11155,
14,
1600,
342,
288,
754,
275,
1586,
63,
1328,
1389,
8,
80,
9,
288,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
339,
347,
511,
63,
515,
63,
515,
773,
8,
277,
304,
267,
4051,
275,
7352,
14,
1875,
9205
] |
[
4613,
199,
199,
504,
3598,
492,
8579,
63,
5451,
199,
646,
747,
199,
646,
2197,
199,
646,
2680,
465,
980,
199,
646,
984,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
10634,
492,
8434,
199,
504,
10634,
14,
5819,
492,
399,
12,
7843,
19,
199,
504,
10634,
492,
334,
9641,
12,
10071,
12,
510,
4822,
12,
6879,
2681,
12,
330,
602,
63,
1842,
12,
490,
1434,
63,
1842,
12,
6247,
63,
1842,
12,
5499,
12,
31227,
9,
199,
504,
10634,
14,
2550,
492,
32117,
3849,
199,
504,
10634,
14,
2308,
14,
1389,
1192,
492,
370,
63,
1328,
1389,
12,
1586,
63,
1328,
1389,
199,
646,
10634,
14,
1974,
14,
4776,
465,
7352,
199,
504,
10634,
14,
1974,
14,
4776,
492,
334,
7505,
63,
3118,
12,
639,
702,
63,
16810,
63,
1452,
12,
639,
702,
63,
1943,
63,
1452,
12,
639,
702,
63,
1080,
63,
1452,
12,
639,
702,
63,
5602,
63,
1452,
12,
639,
3371,
9,
199,
504,
10634,
14,
2219,
14,
396,
63,
7885,
492,
702,
63,
7885,
63,
1452,
199,
199,
646,
10634,
199,
504,
10634,
492,
18267,
12,
11290,
52,
199,
504,
10634,
423,
8450,
14,
1086,
773,
492,
284,
25638,
199,
199,
4304,
275,
980,
14,
4304,
199,
199,
893,
26,
272,
492,
32580,
551,
221,
327,
20432,
199,
2590,
3545,
26,
272,
485,
34,
1484,
5153,
63,
15942,
275,
756,
199,
2836,
26,
272,
485,
34,
1484,
5153,
63,
15942,
275,
715,
199,
199,
893,
26,
272,
492,
12472,
221,
327,
20432,
199,
2590,
3545,
26,
272,
485,
58,
5617,
63,
15942,
275,
756,
199,
2836,
26,
272,
485,
58,
5617,
63,
15942,
275,
715,
421,
199,
32,
4462,
14,
5997,
8,
2645,
534,
578,
358,
199,
318,
1453,
63,
1389,
1192,
63,
576,
837,
272,
327,
4154,
1453,
1015,
1706,
1192,
666,
272,
687,
10634,
14,
2219,
14,
2308,
14,
4208,
63,
10000,
63,
3494,
63,
1725,
492,
334,
267,
1218,
63,
1328,
1389,
63,
576,
9,
272,
372,
1218,
63,
1328,
1389,
63,
576,
342,
421,
199,
32,
4462,
14,
5997,
8,
2645,
534,
578,
358,
199,
318,
1006,
63,
1389,
1192,
63,
576,
837,
272,
327,
4154,
1006,
402,
4154,
1453,
1015,
1706,
1192,
666,
272,
687,
10634,
14,
2219,
14,
2308,
14,
4208,
63,
10000,
63,
3494,
63,
1725,
492,
334,
267,
1218,
63,
576,
9,
272,
372,
1218,
63,
576,
342,
421,
199,
318,
1104,
63,
285,
8734,
8,
65,
12,
330,
304,
339,
340,
1228,
8,
65,
12,
334,
513,
12,
2008,
430,
436,
1228,
8,
66,
12,
334,
513,
12,
2008,
2298,
267,
702,
8,
552,
8,
65,
9,
508,
822,
8,
66,
430,
267,
367,
282,
3131,
330,
63,
315,
3482,
8,
65,
12,
330,
304,
288,
1104,
63,
285,
8734,
8,
65,
3131,
330,
4602,
272,
916,
1228,
8,
65,
12,
510,
4822,
304,
267,
702,
63,
7885,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
10071,
304,
267,
702,
63,
1943,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
12403,
304,
267,
702,
63,
5602,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
5499,
304,
267,
702,
63,
1080,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
1228,
8,
65,
12,
31227,
304,
267,
327,
12540,
12,
267,
327,
31227,
14,
8906,
365,
2896,
687,
620,
370,
2783,
315,
7843,
19,
267,
327,
11703,
314,
2011,
465,
20321,
23051,
3328,
267,
340,
7843,
19,
436,
330,
14,
8906,
14,
262,
5057,
63,
466,
508,
283,
875,
356,
288,
986,
267,
587,
26,
288,
7352,
14,
479,
63,
16810,
63,
1452,
8,
65,
12,
330,
9,
272,
916,
282,
365,
11290,
52,
26,
267,
702,
330,
365,
11290,
52,
272,
916,
1228,
8,
65,
12,
18267,
304,
267,
702,
282,
508,
330,
267,
702,
282,
14,
5646,
508,
330,
14,
5646,
272,
587,
26,
267,
702,
8,
65,
508,
330,
9,
421,
199,
533,
1379,
2305,
1192,
8,
785,
304,
339,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
291,
14,
515,
275,
2560,
5,
83,
4343,
1328,
7,
450,
7352,
14,
3759,
83,
8,
709,
9,
339,
347,
17558,
63,
765,
8,
277,
12,
1083,
304,
267,
986,
339,
347,
3752,
63,
2708,
8,
277,
12,
671,
12,
11029,
29,
403,
12,
1011,
958,
304,
267,
543,
4868,
63,
3118,
8,
277,
14,
515,
9,
465,
299,
26,
288,
370,
63,
1328,
1389,
8,
80,
12,
671,
12,
11029,
29,
6447,
12,
1011,
958,
9,
288,
372,
1586,
63,
1328,
1389,
8,
80,
12,
1011,
958,
9,
421,
199,
533,
1379,
3735,
8,
774,
2305,
1192,
304,
339,
347,
511,
63,
875,
63,
2308,
8,
277,
304,
398,
4051,
275,
10071,
8,
1590,
14,
2355,
14,
10843,
8,
709,
12,
499,
430,
267,
308,
275,
4051,
14,
475,
63,
1328,
1389,
8,
403,
9,
267,
754,
275,
1586,
63,
1328,
1389,
8,
83,
9,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
308,
275,
4051,
14,
475,
63,
1328,
1389,
342,
267,
754,
275,
1586,
63,
1328,
1389,
8,
83,
9,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
308,
275,
4051,
14,
475,
63,
1328,
1389,
342,
267,
754,
275,
1586,
63,
1328,
1389,
8,
5819,
14,
15466,
8,
83,
430,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
308,
275,
370,
63,
1328,
1389,
8,
403,
12,
4051,
9,
267,
754,
275,
1586,
63,
1328,
1389,
8,
83,
9,
267,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
398,
543,
4868,
63,
3118,
8,
277,
14,
515,
9,
465,
299,
26,
953,
308,
275,
4051,
14,
475,
63,
1328,
1389,
342,
288,
11155,
275,
1551,
8,
80,
12,
283,
6603,
358,
288,
11155,
14,
952,
8,
83,
9,
288,
11155,
14,
1600,
342,
288,
754,
275,
1586,
63,
1328,
1389,
8,
80,
9,
288,
7352,
14,
479,
63,
1943,
63,
1452,
8,
1099,
12,
4051,
9,
339,
347,
511,
63,
515,
63,
515,
773,
8,
277,
304,
267,
4051,
275,
7352,
14,
1875,
9205,
0
] |
[
1,
1,
1,
1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ible
|
lib/ansible/plugins/callback/unixy.py
|
14
|
8485
|
# Copyright: (c) 2017, Allyson Bowles <@akatch>
# Copyright: (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
callback: unixy
type: stdout
author: Allyson Bowles <@akatch>
short_description: condensed Ansible output
version_added: 2.5
description:
- Consolidated Ansible output in the style of LINUX/UNIX startup logs.
extends_documentation_fragment:
- default_callback
requirements:
- set as stdout in configuration
'''
from os.path import basename
from ansible import constants as C
from ansible.module_utils._text import to_text
from ansible.plugins.callback import CallbackBase
from ansible.utils.color import colorize, hostcolor
class CallbackModule(CallbackBase):
'''
Design goals:
- Print consolidated output that looks like a *NIX startup log
- Defaults should avoid displaying unnecessary information wherever possible
TODOs:
- Only display task names if the task runs on at least one host
- Add option to display all hostnames on a single line in the appropriate result color (failures may have a separate line)
- Consolidate stats display
- Display whether run is in --check mode
- Don't show play name if no hosts found
'''
CALLBACK_VERSION = 2.0
CALLBACK_TYPE = 'stdout'
CALLBACK_NAME = 'unixy'
def _run_is_verbose(self, result):
return ((self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result)
def _get_task_display_name(self, task):
self.task_display_name = None
display_name = task.get_name().strip().split(" : ")
task_display_name = display_name[-1]
if task_display_name.startswith("include"):
return
else:
self.task_display_name = task_display_name
def _preprocess_result(self, result):
self.delegated_vars = result._result.get('_ansible_delegated_vars', None)
self._handle_exception(result._result)
self._handle_warnings(result._result)
def _process_result_output(self, result, msg):
task_host = result._host.get_name()
task_result = "%s %s" % (task_host, msg)
if self._run_is_verbose(result):
task_result = "%s %s: %s" % (task_host, msg, self._dump_results(result._result, indent=4))
return task_result
if self.delegated_vars:
task_delegate_host = self.delegated_vars['ansible_host']
task_result = "%s -> %s %s" % (task_host, task_delegate_host, msg)
if result._result.get('msg') and result._result.get('msg') != "All items completed":
task_result += " | msg: " + to_text(result._result.get('msg'))
if result._result.get('stdout'):
task_result += " | stdout: " + result._result.get('stdout')
if result._result.get('stderr'):
task_result += " | stderr: " + result._result.get('stderr')
return task_result
def v2_playbook_on_task_start(self, task, is_conditional):
self._get_task_display_name(task)
if self.task_display_name is not None:
self._display.display("%s..." % self.task_display_name)
def v2_playbook_on_handler_task_start(self, task):
self._get_task_display_name(task)
if self.task_display_name is not None:
self._display.display("%s (via handler)... " % self.task_display_name)
def v2_playbook_on_play_start(self, play):
# TODO display name of play and list of play hosts
# TODO don't display play name if no hosts in play
name = play.get_name().strip()
if name:
msg = u"\n- %s -" % name
else:
msg = u"---"
self._display.display(msg)
def v2_runner_on_skipped(self, result, ignore_errors=False):
self._preprocess_result(result)
display_color = C.COLOR_SKIP
msg = "skipped"
task_result = self._process_result_output(result, msg)
self._display.display(" " + task_result, display_color)
def v2_runner_on_failed(self, result, ignore_errors=False):
self._preprocess_result(result)
display_color = C.COLOR_ERROR
msg = "failed"
task_result = self._process_result_output(result, msg)
self._display.display(" " + task_result, display_color)
def v2_runner_on_ok(self, result, msg="ok", display_color=C.COLOR_OK):
self._preprocess_result(result)
result_was_changed = ('changed' in result._result and result._result['changed'])
if result_was_changed:
msg = "done"
display_color = C.COLOR_CHANGED
task_result = self._process_result_output(result, msg)
self._display.display(" " + task_result, display_color)
def v2_runner_item_on_skipped(self, result):
self.v2_runner_on_skipped(result)
def v2_runner_item_on_failed(self, result):
self.v2_runner_on_failed(result)
def v2_runner_item_on_ok(self, result):
self.v2_runner_on_ok(result)
def v2_runner_on_unreachable(self, result):
msg = "unreachable"
display_color = C.COLOR_UNREACHABLE
task_result = self._process_result_output(result, msg)
self._display.display(" " + task_result, display_color)
def v2_on_file_diff(self, result):
if result._task.loop and 'results' in result._result:
for res in result._result['results']:
if 'diff' in res and res['diff'] and res.get('changed', False):
diff = self._get_diff(res['diff'])
if diff:
self._display.display(diff)
elif 'diff' in result._result and result._result['diff'] and result._result.get('changed', False):
diff = self._get_diff(result._result['diff'])
if diff:
self._display.display(diff)
def v2_playbook_on_stats(self, stats):
self._display.display("\n- Play recap -", screen_only=True)
hosts = sorted(stats.processed.keys())
for h in hosts:
# TODO how else can we display these?
t = stats.summarize(h)
self._display.display(u" %s : %s %s %s %s" % (
hostcolor(h, t),
colorize(u'ok', t['ok'], C.COLOR_OK),
colorize(u'changed', t['changed'], C.COLOR_CHANGED),
colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE),
colorize(u'failed', t['failures'], C.COLOR_ERROR)),
screen_only=True
)
self._display.display(u" %s : %s %s %s %s" % (
hostcolor(h, t, False),
colorize(u'ok', t['ok'], None),
colorize(u'changed', t['changed'], None),
colorize(u'unreachable', t['unreachable'], None),
colorize(u'failed', t['failures'], None)),
log_only=True
)
def v2_playbook_on_no_hosts_matched(self):
self._display.display(" No hosts found!", color=C.COLOR_DEBUG)
def v2_playbook_on_no_hosts_remaining(self):
self._display.display(" Ran out of hosts!", color=C.COLOR_ERROR)
def v2_playbook_on_start(self, playbook):
# TODO display whether this run is happening in check mode
self._display.display("Executing playbook %s" % basename(playbook._file_name))
if self._display.verbosity > 3:
if self._options is not None:
for option in dir(self._options):
if option.startswith('_') or option in ['read_file', 'ensure_value', 'read_module']:
continue
val = getattr(self._options, option)
if val:
self._display.vvvv('%s: %s' % (option, val))
def v2_runner_retry(self, result):
msg = " Retrying... (%d of %d)" % (result._result['attempts'], result._result['retries'])
if (self._display.verbosity > 2 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
msg += "Result was: %s" % self._dump_results(result._result)
self._display.display(msg, color=C.COLOR_DEBUG)
|
mit
|
[
3,
1898,
26,
334,
67,
9,
9708,
12,
2900,
588,
265,
699,
583,
2978,
665,
32,
1151,
693,
30,
199,
3,
1898,
26,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
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,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
8948,
275,
1449,
272,
3233,
26,
16572,
89,
272,
730,
26,
3839,
272,
4132,
26,
2900,
588,
265,
699,
583,
2978,
665,
32,
1151,
693,
30,
272,
3974,
63,
1802,
26,
406,
848,
939,
2622,
1072,
272,
1015,
63,
3270,
26,
499,
14,
21,
272,
1369,
26,
489,
446,
1448,
28335,
19074,
2622,
1072,
315,
314,
3449,
402,
491,
568,
14272,
15,
19584,
14210,
9610,
14,
272,
16879,
63,
9970,
63,
7677,
26,
489,
446,
849,
63,
3058,
272,
9760,
26,
489,
446,
663,
465,
3839,
315,
2897,
199,
2344,
199,
199,
504,
747,
14,
515,
492,
9593,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
5265,
14,
3058,
492,
17555,
1563,
199,
504,
3242,
14,
1208,
14,
2326,
492,
31019,
12,
1591,
2326,
421,
199,
533,
17555,
2377,
8,
9822,
304,
339,
1449,
272,
29410,
2621,
2551,
26,
272,
446,
9101,
406,
28335,
19074,
1072,
626,
10734,
2839,
282,
627,
46,
3867,
14210,
943,
272,
446,
7827,
1077,
5126,
20589,
23361,
2556,
2382,
422,
3962,
339,
3254,
83,
26,
272,
446,
5972,
2929,
2120,
1561,
340,
314,
2120,
7858,
641,
737,
5210,
1373,
1591,
272,
446,
2654,
945,
370,
2929,
1006,
1591,
1247,
641,
282,
2849,
1004,
315,
314,
5827,
754,
3164,
334,
9968,
1443,
1172,
282,
7396,
1004,
9,
272,
446,
1448,
28335,
602,
5020,
2929,
272,
446,
12175,
3775,
1255,
365,
315,
1553,
1074,
818,
272,
446,
7529,
1133,
2498,
5232,
536,
340,
949,
7057,
1911,
272,
1449,
339,
24251,
7111,
63,
4612,
275,
499,
14,
16,
272,
24251,
7111,
63,
2711,
275,
283,
2703,
7,
272,
24251,
7111,
63,
2339,
275,
283,
11864,
89,
7,
339,
347,
485,
1065,
63,
374,
63,
3832,
8,
277,
12,
754,
304,
267,
372,
3666,
277,
423,
2918,
14,
9833,
690,
378,
503,
2513,
4853,
63,
3832,
63,
9223,
7,
315,
754,
423,
1099,
9,
436,
2513,
4853,
63,
3832,
63,
4415,
7,
440,
315,
754,
423,
1099,
9,
339,
347,
485,
362,
63,
1765,
63,
2918,
63,
354,
8,
277,
12,
2120,
304,
267,
291,
14,
1765,
63,
2918,
63,
354,
275,
488,
267,
2929,
63,
354,
275,
2120,
14,
362,
63,
354,
1252,
1913,
1252,
1294,
480,
520,
6099,
398,
2120,
63,
2918,
63,
354,
275,
2929,
63,
354,
1988,
17,
61,
267,
340,
2120,
63,
2918,
63,
354,
14,
2460,
480,
2613,
2349,
288,
372,
267,
587,
26,
288,
291,
14,
1765,
63,
2918,
63,
354,
275,
2120,
63,
2918,
63,
354,
339,
347,
485,
17677,
63,
1099,
8,
277,
12,
754,
304,
267,
291,
14,
23684,
972,
63,
2936,
275,
754,
423,
1099,
14,
362,
6412,
4853,
63,
23684,
972,
63,
2936,
297,
488,
9,
267,
291,
423,
2479,
63,
1971,
8,
1099,
423,
1099,
9,
267,
291,
423,
2479,
63,
5451,
8,
1099,
423,
1099,
9,
339,
347,
485,
1412,
63,
1099,
63,
1199,
8,
277,
12,
754,
12,
1499,
304,
267,
2120,
63,
1102,
275,
754,
423,
1102,
14,
362,
63,
354,
342,
267,
2120,
63,
1099,
275,
2071,
83,
450,
83,
2,
450,
334,
1765,
63,
1102,
12,
1499,
9,
398,
340,
291,
423,
1065,
63,
374,
63,
3832,
8,
1099,
304,
288,
2120,
63,
1099,
275,
2071,
83,
450,
83,
26,
450,
83,
2,
450,
334,
1765,
63,
1102,
12,
1499,
12,
291,
423,
2724,
63,
2604,
8,
1099,
423,
1099,
12,
4363,
29,
20,
430,
288,
372,
2120,
63,
1099,
398,
340,
291,
14,
23684,
972,
63,
2936,
26,
288,
2120,
63,
15286,
63,
1102,
275,
291,
14,
23684,
972,
63,
2936,
459,
4853,
63,
1102,
418,
288,
2120,
63,
1099,
275,
2071,
83,
1035,
450,
83,
450,
83,
2,
450,
334,
1765,
63,
1102,
12,
2120,
63,
15286,
63,
1102,
12,
1499,
9,
398,
340,
754,
423,
1099,
14,
362,
360,
1328,
358,
436,
754,
423,
1099,
14,
362,
360,
1328,
358,
1137,
298,
2422,
2974,
9709,
582,
288,
2120,
63,
1099,
847,
298,
1204,
1499,
26,
298,
435,
370,
63,
505,
8,
1099,
423,
1099,
14,
362,
360,
1328,
1333,
398,
340,
754,
423,
1099,
14,
362,
360,
2703,
735,
288,
2120,
63,
1099,
847,
298,
1204,
3839,
26,
298,
435,
754,
423,
1099,
14,
362,
360,
2703,
358,
398,
340,
754,
423,
1099,
14,
362,
360,
3083,
735,
288,
2120,
63,
1099,
847,
298,
1204,
4635,
26,
298,
435,
754,
423,
1099,
14,
362,
360,
3083,
358,
398,
372,
2120,
63,
1099,
339,
347,
373,
18,
63,
14205,
63,
265,
63,
1765,
63,
928,
8,
277,
12,
2120,
12,
365,
63,
14353,
304,
267,
291,
423,
362,
63,
1765,
63,
2918,
63,
354,
8,
1765,
9,
267,
340,
291,
14,
1765,
63,
2918,
63,
354,
365,
440,
488,
26,
288,
291,
423,
2918,
14,
2918,
3647,
83,
11500,
450,
291,
14,
1765,
63,
2918,
63,
354,
9,
339,
347,
373,
18,
63,
14205,
63,
265,
63,
2232,
63,
1765,
63,
928,
8,
277,
12,
2120,
304,
267,
291,
423,
362,
63,
1765,
63,
2918,
63,
354,
8,
1765,
9,
267,
340,
291,
14,
1765,
63,
2918,
63,
354,
365,
440,
488,
26,
288,
291,
423,
2918,
14,
2918,
3647,
83,
334,
12897,
3016,
680,
703,
298,
450,
291,
14,
1765,
63,
2918,
63,
354,
9,
339,
347,
373,
18,
63,
14205,
63,
265,
63,
2802,
63,
928,
8,
277,
12,
5232,
304,
267,
327,
3254,
2929,
536,
402,
5232,
436,
769,
402,
5232,
7057,
267,
327,
3254,
2793,
1133,
2929,
5232,
536,
340,
949,
7057,
315
] |
[
1898,
26,
334,
67,
9,
9708,
12,
2900,
588,
265,
699,
583,
2978,
665,
32,
1151,
693,
30,
199,
3,
1898,
26,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
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,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
8948,
275,
1449,
272,
3233,
26,
16572,
89,
272,
730,
26,
3839,
272,
4132,
26,
2900,
588,
265,
699,
583,
2978,
665,
32,
1151,
693,
30,
272,
3974,
63,
1802,
26,
406,
848,
939,
2622,
1072,
272,
1015,
63,
3270,
26,
499,
14,
21,
272,
1369,
26,
489,
446,
1448,
28335,
19074,
2622,
1072,
315,
314,
3449,
402,
491,
568,
14272,
15,
19584,
14210,
9610,
14,
272,
16879,
63,
9970,
63,
7677,
26,
489,
446,
849,
63,
3058,
272,
9760,
26,
489,
446,
663,
465,
3839,
315,
2897,
199,
2344,
199,
199,
504,
747,
14,
515,
492,
9593,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
5265,
14,
3058,
492,
17555,
1563,
199,
504,
3242,
14,
1208,
14,
2326,
492,
31019,
12,
1591,
2326,
421,
199,
533,
17555,
2377,
8,
9822,
304,
339,
1449,
272,
29410,
2621,
2551,
26,
272,
446,
9101,
406,
28335,
19074,
1072,
626,
10734,
2839,
282,
627,
46,
3867,
14210,
943,
272,
446,
7827,
1077,
5126,
20589,
23361,
2556,
2382,
422,
3962,
339,
3254,
83,
26,
272,
446,
5972,
2929,
2120,
1561,
340,
314,
2120,
7858,
641,
737,
5210,
1373,
1591,
272,
446,
2654,
945,
370,
2929,
1006,
1591,
1247,
641,
282,
2849,
1004,
315,
314,
5827,
754,
3164,
334,
9968,
1443,
1172,
282,
7396,
1004,
9,
272,
446,
1448,
28335,
602,
5020,
2929,
272,
446,
12175,
3775,
1255,
365,
315,
1553,
1074,
818,
272,
446,
7529,
1133,
2498,
5232,
536,
340,
949,
7057,
1911,
272,
1449,
339,
24251,
7111,
63,
4612,
275,
499,
14,
16,
272,
24251,
7111,
63,
2711,
275,
283,
2703,
7,
272,
24251,
7111,
63,
2339,
275,
283,
11864,
89,
7,
339,
347,
485,
1065,
63,
374,
63,
3832,
8,
277,
12,
754,
304,
267,
372,
3666,
277,
423,
2918,
14,
9833,
690,
378,
503,
2513,
4853,
63,
3832,
63,
9223,
7,
315,
754,
423,
1099,
9,
436,
2513,
4853,
63,
3832,
63,
4415,
7,
440,
315,
754,
423,
1099,
9,
339,
347,
485,
362,
63,
1765,
63,
2918,
63,
354,
8,
277,
12,
2120,
304,
267,
291,
14,
1765,
63,
2918,
63,
354,
275,
488,
267,
2929,
63,
354,
275,
2120,
14,
362,
63,
354,
1252,
1913,
1252,
1294,
480,
520,
6099,
398,
2120,
63,
2918,
63,
354,
275,
2929,
63,
354,
1988,
17,
61,
267,
340,
2120,
63,
2918,
63,
354,
14,
2460,
480,
2613,
2349,
288,
372,
267,
587,
26,
288,
291,
14,
1765,
63,
2918,
63,
354,
275,
2120,
63,
2918,
63,
354,
339,
347,
485,
17677,
63,
1099,
8,
277,
12,
754,
304,
267,
291,
14,
23684,
972,
63,
2936,
275,
754,
423,
1099,
14,
362,
6412,
4853,
63,
23684,
972,
63,
2936,
297,
488,
9,
267,
291,
423,
2479,
63,
1971,
8,
1099,
423,
1099,
9,
267,
291,
423,
2479,
63,
5451,
8,
1099,
423,
1099,
9,
339,
347,
485,
1412,
63,
1099,
63,
1199,
8,
277,
12,
754,
12,
1499,
304,
267,
2120,
63,
1102,
275,
754,
423,
1102,
14,
362,
63,
354,
342,
267,
2120,
63,
1099,
275,
2071,
83,
450,
83,
2,
450,
334,
1765,
63,
1102,
12,
1499,
9,
398,
340,
291,
423,
1065,
63,
374,
63,
3832,
8,
1099,
304,
288,
2120,
63,
1099,
275,
2071,
83,
450,
83,
26,
450,
83,
2,
450,
334,
1765,
63,
1102,
12,
1499,
12,
291,
423,
2724,
63,
2604,
8,
1099,
423,
1099,
12,
4363,
29,
20,
430,
288,
372,
2120,
63,
1099,
398,
340,
291,
14,
23684,
972,
63,
2936,
26,
288,
2120,
63,
15286,
63,
1102,
275,
291,
14,
23684,
972,
63,
2936,
459,
4853,
63,
1102,
418,
288,
2120,
63,
1099,
275,
2071,
83,
1035,
450,
83,
450,
83,
2,
450,
334,
1765,
63,
1102,
12,
2120,
63,
15286,
63,
1102,
12,
1499,
9,
398,
340,
754,
423,
1099,
14,
362,
360,
1328,
358,
436,
754,
423,
1099,
14,
362,
360,
1328,
358,
1137,
298,
2422,
2974,
9709,
582,
288,
2120,
63,
1099,
847,
298,
1204,
1499,
26,
298,
435,
370,
63,
505,
8,
1099,
423,
1099,
14,
362,
360,
1328,
1333,
398,
340,
754,
423,
1099,
14,
362,
360,
2703,
735,
288,
2120,
63,
1099,
847,
298,
1204,
3839,
26,
298,
435,
754,
423,
1099,
14,
362,
360,
2703,
358,
398,
340,
754,
423,
1099,
14,
362,
360,
3083,
735,
288,
2120,
63,
1099,
847,
298,
1204,
4635,
26,
298,
435,
754,
423,
1099,
14,
362,
360,
3083,
358,
398,
372,
2120,
63,
1099,
339,
347,
373,
18,
63,
14205,
63,
265,
63,
1765,
63,
928,
8,
277,
12,
2120,
12,
365,
63,
14353,
304,
267,
291,
423,
362,
63,
1765,
63,
2918,
63,
354,
8,
1765,
9,
267,
340,
291,
14,
1765,
63,
2918,
63,
354,
365,
440,
488,
26,
288,
291,
423,
2918,
14,
2918,
3647,
83,
11500,
450,
291,
14,
1765,
63,
2918,
63,
354,
9,
339,
347,
373,
18,
63,
14205,
63,
265,
63,
2232,
63,
1765,
63,
928,
8,
277,
12,
2120,
304,
267,
291,
423,
362,
63,
1765,
63,
2918,
63,
354,
8,
1765,
9,
267,
340,
291,
14,
1765,
63,
2918,
63,
354,
365,
440,
488,
26,
288,
291,
423,
2918,
14,
2918,
3647,
83,
334,
12897,
3016,
680,
703,
298,
450,
291,
14,
1765,
63,
2918,
63,
354,
9,
339,
347,
373,
18,
63,
14205,
63,
265,
63,
2802,
63,
928,
8,
277,
12,
5232,
304,
267,
327,
3254,
2929,
536,
402,
5232,
436,
769,
402,
5232,
7057,
267,
327,
3254,
2793,
1133,
2929,
5232,
536,
340,
949,
7057,
315,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jeffzheng1/tensorflow
|
tensorflow/contrib/learn/python/learn/learn_io/pandas_io.py
|
14
|
3569
|
# 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.
# ==============================================================================
"""Methods to allow pandas.DataFrame."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
try:
# pylint: disable=g-import-not-at-top
import pandas as pd
HAS_PANDAS = True
except ImportError:
HAS_PANDAS = False
PANDAS_DTYPES = {
'int8': 'int',
'int16': 'int',
'int32': 'int',
'int64': 'int',
'uint8': 'int',
'uint16': 'int',
'uint32': 'int',
'uint64': 'int',
'float16': 'float',
'float32': 'float',
'float64': 'float',
'bool': 'i'
}
def extract_pandas_data(data):
"""Extract data from pandas.DataFrame for predictors.
Given a DataFrame, will extract the values and cast them to float. The
DataFrame is expected to contain values of type int, float or bool.
Args:
data: `pandas.DataFrame` containing the data to be extracted.
Returns:
A numpy `ndarray` of the DataFrame's values as floats.
Raises:
ValueError: if data contains types other than int, float or bool.
"""
if not isinstance(data, pd.DataFrame):
return data
bad_data = [column for column in data
if data[column].dtype.name not in PANDAS_DTYPES]
if not bad_data:
return data.values.astype('float')
else:
error_report = [("'" + str(column) + "' type='" +
data[column].dtype.name + "'") for column in bad_data]
raise ValueError('Data types for extracting pandas data must be int, '
'float, or bool. Found: ' + ', '.join(error_report))
def extract_pandas_matrix(data):
"""Extracts numpy matrix from pandas DataFrame.
Args:
data: `pandas.DataFrame` containing the data to be extracted.
Returns:
A numpy `ndarray` of the DataFrame's values.
"""
if not isinstance(data, pd.DataFrame):
return data
return data.as_matrix()
def extract_pandas_labels(labels):
"""Extract data from pandas.DataFrame for labels.
Args:
labels: `pandas.DataFrame` or `pandas.Series` containing one column of
labels to be extracted.
Returns:
A numpy `ndarray` of labels from the DataFrame.
Raises:
ValueError: if more than one column is found or type is not int, float or
bool.
"""
if isinstance(labels,
pd.DataFrame): # pandas.Series also belongs to DataFrame
if len(labels.columns) > 1:
raise ValueError('Only one column for labels is allowed.')
bad_data = [column for column in labels
if labels[column].dtype.name not in PANDAS_DTYPES]
if not bad_data:
return labels.values
else:
error_report = ["'" + str(column) + "' type="
+ str(labels[column].dtype.name) for column in bad_data]
raise ValueError('Data types for extracting labels must be int, '
'float, or bool. Found: ' + ', '.join(error_report))
else:
return labels
|
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,
199,
624,
10385,
370,
2040,
10634,
14,
9205,
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,
893,
26,
523,
327,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
523,
492,
10634,
465,
6454,
523,
7509,
63,
48,
3649,
1179,
275,
715,
199,
2590,
3545,
26,
523,
7509,
63,
48,
3649,
1179,
275,
756,
199,
199,
48,
3649,
1179,
63,
36,
7893,
275,
469,
272,
283,
442,
24,
356,
283,
442,
297,
272,
283,
442,
975,
356,
283,
442,
297,
272,
283,
442,
708,
356,
283,
442,
297,
272,
283,
442,
772,
356,
283,
442,
297,
272,
283,
1635,
24,
356,
283,
442,
297,
272,
283,
1635,
975,
356,
283,
442,
297,
272,
283,
1635,
708,
356,
283,
442,
297,
272,
283,
1635,
772,
356,
283,
442,
297,
272,
283,
1609,
975,
356,
283,
1609,
297,
272,
283,
1609,
708,
356,
283,
1609,
297,
272,
283,
1609,
772,
356,
283,
1609,
297,
272,
283,
2245,
356,
283,
73,
7,
199,
93,
421,
199,
318,
5536,
63,
15718,
63,
576,
8,
576,
304,
523,
408,
12147,
666,
687,
10634,
14,
9205,
367,
4557,
13451,
14,
819,
9138,
282,
10071,
12,
911,
5536,
314,
1338,
436,
9106,
3062,
370,
2069,
14,
710,
523,
10071,
365,
1420,
370,
1395,
1338,
402,
730,
1109,
12,
2069,
503,
2155,
14,
819,
3033,
26,
272,
666,
26,
658,
15718,
14,
9205,
64,
3035,
314,
666,
370,
506,
12509,
14,
819,
1803,
26,
272,
437,
2680,
658,
8237,
64,
402,
314,
10071,
1159,
1338,
465,
15657,
14,
819,
6218,
26,
272,
1722,
26,
340,
666,
3509,
2943,
1163,
2419,
1109,
12,
2069,
503,
2155,
14,
523,
408,
523,
340,
440,
1228,
8,
576,
12,
6454,
14,
9205,
304,
272,
372,
666,
819,
4875,
63,
576,
275,
359,
2301,
367,
2763,
315,
666,
1598,
340,
666,
59,
2301,
1055,
2271,
14,
354,
440,
315,
510,
3649,
1179,
63,
36,
7893,
61,
819,
340,
440,
4875,
63,
576,
26,
272,
372,
666,
14,
1459,
14,
6041,
360,
1609,
358,
523,
587,
26,
272,
1125,
63,
3070,
275,
10003,
4065,
435,
620,
8,
2301,
9,
435,
3546,
730,
534,
2,
435,
2151,
666,
59,
2301,
1055,
2271,
14,
354,
435,
3546,
531,
367,
2763,
315,
4875,
63,
576,
61,
272,
746,
1722,
360,
1451,
2943,
367,
30137,
10634,
666,
1471,
506,
1109,
12,
283,
2151,
283,
1609,
12,
503,
2155,
14,
2643,
26,
283,
435,
1656,
1987,
904,
8,
705,
63,
3070,
430,
421,
199,
318,
5536,
63,
15718,
63,
3642,
8,
576,
304,
523,
408,
12147,
83,
2680,
3634,
687,
10634,
10071,
14,
819,
3033,
26,
272,
666,
26,
658,
15718,
14,
9205,
64,
3035,
314,
666,
370,
506,
12509,
14,
819,
1803,
26,
272,
437,
2680,
658,
8237,
64,
402,
314,
10071,
1159,
1338,
14,
523,
408,
523,
340,
440,
1228,
8,
576,
12,
6454,
14,
9205,
304,
272,
372,
666,
819,
372,
666,
14,
305,
63,
3642,
342,
421,
199,
318,
5536,
63,
15718,
63,
3512,
8,
3512,
304,
523,
408,
12147,
666,
687,
10634,
14,
9205,
367,
3628,
14,
819,
3033,
26,
272,
3628,
26,
658,
15718,
14,
9205,
64,
503,
658,
15718,
14,
9641,
64,
3035,
1373,
2763,
402,
489,
3628,
370,
506,
12509,
14,
819,
1803,
26,
272,
437,
2680,
658,
8237,
64,
402,
3628,
687,
314,
10071,
14,
819,
6218,
26,
272,
1722,
26,
340,
1655,
2419,
1373,
2763,
365,
1911,
503,
730,
365,
440,
1109,
12,
2069,
503,
489,
2155,
14,
523,
408,
523,
340,
1228,
8,
3512,
12,
355,
6454,
14,
9205,
304,
221,
327,
10634,
14,
9641,
2597,
15006,
370,
10071,
272,
340,
822,
8,
3512,
14,
3406,
9,
690,
413,
26,
489,
746,
1722,
360,
5903,
1373,
2763,
367,
3628,
365,
4370,
2659,
339,
4875,
63,
576,
275,
359,
2301,
367,
2763,
315,
3628,
355,
340,
3628,
59,
2301,
1055,
2271,
14,
354,
440,
315,
510,
3649,
1179,
63,
36,
7893,
61,
272,
340,
440,
4875,
63,
576,
26,
489,
372,
3628,
14,
1459,
272,
587,
26,
489,
1125,
63,
3070,
275,
2097,
4065,
435,
620,
8,
2301,
9,
435,
3546,
730,
628,
1993,
435,
620,
8,
3512,
59,
2301,
1055,
2271,
14,
354,
9,
367,
2763,
315,
4875,
63,
576,
61,
489,
746,
1722,
360,
1451,
2943,
367,
30137,
3628,
1471,
506,
1109,
12,
283,
2432,
283,
1609,
12,
503,
2155,
14,
2643,
26,
283,
435,
1656,
1987,
904,
8,
705,
63,
3070,
430,
523,
587,
26,
272,
372,
3628,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
10385,
370,
2040,
10634,
14,
9205,
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,
893,
26,
523,
327,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
523,
492,
10634,
465,
6454,
523,
7509,
63,
48,
3649,
1179,
275,
715,
199,
2590,
3545,
26,
523,
7509,
63,
48,
3649,
1179,
275,
756,
199,
199,
48,
3649,
1179,
63,
36,
7893,
275,
469,
272,
283,
442,
24,
356,
283,
442,
297,
272,
283,
442,
975,
356,
283,
442,
297,
272,
283,
442,
708,
356,
283,
442,
297,
272,
283,
442,
772,
356,
283,
442,
297,
272,
283,
1635,
24,
356,
283,
442,
297,
272,
283,
1635,
975,
356,
283,
442,
297,
272,
283,
1635,
708,
356,
283,
442,
297,
272,
283,
1635,
772,
356,
283,
442,
297,
272,
283,
1609,
975,
356,
283,
1609,
297,
272,
283,
1609,
708,
356,
283,
1609,
297,
272,
283,
1609,
772,
356,
283,
1609,
297,
272,
283,
2245,
356,
283,
73,
7,
199,
93,
421,
199,
318,
5536,
63,
15718,
63,
576,
8,
576,
304,
523,
408,
12147,
666,
687,
10634,
14,
9205,
367,
4557,
13451,
14,
819,
9138,
282,
10071,
12,
911,
5536,
314,
1338,
436,
9106,
3062,
370,
2069,
14,
710,
523,
10071,
365,
1420,
370,
1395,
1338,
402,
730,
1109,
12,
2069,
503,
2155,
14,
819,
3033,
26,
272,
666,
26,
658,
15718,
14,
9205,
64,
3035,
314,
666,
370,
506,
12509,
14,
819,
1803,
26,
272,
437,
2680,
658,
8237,
64,
402,
314,
10071,
1159,
1338,
465,
15657,
14,
819,
6218,
26,
272,
1722,
26,
340,
666,
3509,
2943,
1163,
2419,
1109,
12,
2069,
503,
2155,
14,
523,
408,
523,
340,
440,
1228,
8,
576,
12,
6454,
14,
9205,
304,
272,
372,
666,
819,
4875,
63,
576,
275,
359,
2301,
367,
2763,
315,
666,
1598,
340,
666,
59,
2301,
1055,
2271,
14,
354,
440,
315,
510,
3649,
1179,
63,
36,
7893,
61,
819,
340,
440,
4875,
63,
576,
26,
272,
372,
666,
14,
1459,
14,
6041,
360,
1609,
358,
523,
587,
26,
272,
1125,
63,
3070,
275,
10003,
4065,
435,
620,
8,
2301,
9,
435,
3546,
730,
534,
2,
435,
2151,
666,
59,
2301,
1055,
2271,
14,
354,
435,
3546,
531,
367,
2763,
315,
4875,
63,
576,
61,
272,
746,
1722,
360,
1451,
2943,
367,
30137,
10634,
666,
1471,
506,
1109,
12,
283,
2151,
283,
1609,
12,
503,
2155,
14,
2643,
26,
283,
435,
1656,
1987,
904,
8,
705,
63,
3070,
430,
421,
199,
318,
5536,
63,
15718,
63,
3642,
8,
576,
304,
523,
408,
12147,
83,
2680,
3634,
687,
10634,
10071,
14,
819,
3033,
26,
272,
666,
26,
658,
15718,
14,
9205,
64,
3035,
314,
666,
370,
506,
12509,
14,
819,
1803,
26,
272,
437,
2680,
658,
8237,
64,
402,
314,
10071,
1159,
1338,
14,
523,
408,
523,
340,
440,
1228,
8,
576,
12,
6454,
14,
9205,
304,
272,
372,
666,
819,
372,
666,
14,
305,
63,
3642,
342,
421,
199,
318,
5536,
63,
15718,
63,
3512,
8,
3512,
304,
523,
408,
12147,
666,
687,
10634,
14,
9205,
367,
3628,
14,
819,
3033,
26,
272,
3628,
26,
658,
15718,
14,
9205,
64,
503,
658,
15718,
14,
9641,
64,
3035,
1373,
2763,
402,
489,
3628,
370,
506,
12509,
14,
819,
1803,
26,
272,
437,
2680,
658,
8237,
64,
402,
3628,
687,
314,
10071,
14,
819,
6218,
26,
272,
1722,
26,
340,
1655,
2419,
1373,
2763,
365,
1911,
503,
730,
365,
440,
1109,
12,
2069,
503,
489,
2155,
14,
523,
408,
523,
340,
1228,
8,
3512,
12,
355,
6454,
14,
9205,
304,
221,
327,
10634,
14,
9641,
2597,
15006,
370,
10071,
272,
340,
822,
8,
3512,
14,
3406,
9,
690,
413,
26,
489,
746,
1722,
360,
5903,
1373,
2763,
367,
3628,
365,
4370,
2659,
339,
4875,
63,
576,
275,
359,
2301,
367,
2763,
315,
3628,
355,
340,
3628,
59,
2301,
1055,
2271,
14,
354,
440,
315,
510,
3649,
1179,
63,
36,
7893,
61,
272,
340,
440,
4875,
63,
576,
26,
489,
372,
3628,
14,
1459,
272,
587,
26,
489,
1125,
63,
3070,
275,
2097,
4065,
435,
620,
8,
2301,
9,
435,
3546,
730,
628,
1993,
435,
620,
8,
3512,
59,
2301,
1055,
2271,
14,
354,
9,
367,
2763,
315,
4875,
63,
576,
61,
489,
746,
1722,
360,
1451,
2943,
367,
30137,
3628,
1471,
506,
1109,
12,
283,
2432,
283,
1609,
12,
503,
2155,
14,
2643,
26,
283,
435,
1656,
1987,
904,
8,
705,
63,
3070,
430,
523,
587,
26,
272,
372,
3628,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
raccoongang/edx-platform
|
common/djangoapps/track/views/__init__.py
|
23
|
6545
|
import datetime
import json
import pytz
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.shortcuts import redirect
from django.views.decorators.csrf import ensure_csrf_cookie
from edxmako.shortcuts import render_to_response
from ipware.ip import get_ip
from track import tracker
from track import contexts
from track import shim
from track.models import TrackingLog
from eventtracking import tracker as eventtracker
def log_event(event):
"""Capture a event by sending it to the register trackers"""
tracker.send(event)
def _get_request_header(request, header_name, default=''):
"""Helper method to get header values from a request's META dict, if present."""
if request is not None and hasattr(request, 'META') and header_name in request.META:
return request.META[header_name]
else:
return default
def _get_request_ip(request, default=''):
"""Helper method to get IP from a request's META dict, if present."""
if request is not None and hasattr(request, 'META'):
return get_ip(request)
else:
return default
def _get_request_value(request, value_name, default=''):
"""Helper method to get header values from a request's GET/POST dict, if present."""
if request is not None:
if request.method == 'GET':
return request.GET.get(value_name, default)
elif request.method == 'POST':
return request.POST.get(value_name, default)
return default
def user_track(request):
"""
Log when POST call to "event" URL is made by a user.
GET or POST call should provide "event_type", "event", and "page" arguments.
"""
try:
username = request.user.username
except:
username = "anonymous"
name = _get_request_value(request, 'event_type')
data = _get_request_value(request, 'event', {})
page = _get_request_value(request, 'page')
if isinstance(data, basestring) and len(data) > 0:
try:
data = json.loads(data)
except ValueError:
pass
context_override = contexts.course_context_from_url(page)
context_override['username'] = username
context_override['event_source'] = 'browser'
context_override['page'] = page
with eventtracker.get_tracker().context('edx.course.browser', context_override):
eventtracker.emit(name=name, data=data)
return HttpResponse('success')
def server_track(request, event_type, event, page=None):
"""
Log events related to server requests.
Handle the situation where the request may be NULL, as may happen with management commands.
"""
if event_type.startswith("/event_logs") and request.user.is_staff:
return # don't log
try:
username = request.user.username
except:
username = "anonymous"
# define output:
event = {
"username": username,
"ip": _get_request_ip(request),
"referer": _get_request_header(request, 'HTTP_REFERER'),
"accept_language": _get_request_header(request, 'HTTP_ACCEPT_LANGUAGE'),
"event_source": "server",
"event_type": event_type,
"event": event,
"agent": _get_request_header(request, 'HTTP_USER_AGENT').decode('latin1'),
"page": page,
"time": datetime.datetime.utcnow().replace(tzinfo=pytz.utc),
"host": _get_request_header(request, 'SERVER_NAME'),
"context": eventtracker.get_tracker().resolve_context(),
}
# Some duplicated fields are passed into event-tracking via the context by track.middleware.
# Remove them from the event here since they are captured elsewhere.
shim.remove_shim_context(event)
log_event(event)
def task_track(request_info, task_info, event_type, event, page=None):
"""
Logs tracking information for events occuring within celery tasks.
The `event_type` is a string naming the particular event being logged,
while `event` is a dict containing whatever additional contextual information
is desired.
The `request_info` is a dict containing information about the original
task request. Relevant keys are `username`, `ip`, `agent`, and `host`.
While the dict is required, the values in it are not, so that {} can be
passed in.
In addition, a `task_info` dict provides more information about the current
task, to be stored with the `event` dict. This may also be an empty dict.
The `page` parameter is optional, and allows the name of the page to
be provided.
"""
# supplement event information with additional information
# about the task in which it is running.
full_event = dict(event, **task_info)
# All fields must be specified, in case the tracking information is
# also saved to the TrackingLog model. Get values from the task-level
# information, or just add placeholder values.
with eventtracker.get_tracker().context('edx.course.task', contexts.course_context_from_url(page)):
event = {
"username": request_info.get('username', 'unknown'),
"ip": request_info.get('ip', 'unknown'),
"event_source": "task",
"event_type": event_type,
"event": full_event,
"agent": request_info.get('agent', 'unknown'),
"page": page,
"time": datetime.datetime.utcnow().replace(tzinfo=pytz.utc),
"host": request_info.get('host', 'unknown'),
"context": eventtracker.get_tracker().resolve_context(),
}
log_event(event)
@login_required
@ensure_csrf_cookie
def view_tracking_log(request, args=''):
"""View to output contents of TrackingLog model. For staff use only."""
if not request.user.is_staff:
return redirect('/')
nlen = 100
username = ''
if args:
for arg in args.split('/'):
if arg.isdigit():
nlen = int(arg)
if arg.startswith('username='):
username = arg[9:]
record_instances = TrackingLog.objects.all().order_by('-time')
if username:
record_instances = record_instances.filter(username=username)
record_instances = record_instances[0:nlen]
# fix dtstamp
fmt = '%a %d-%b-%y %H:%M:%S' # "%Y-%m-%d %H:%M:%S %Z%z"
for rinst in record_instances:
rinst.dtstr = rinst.time.replace(tzinfo=pytz.utc).astimezone(pytz.timezone('US/Eastern')).strftime(fmt)
return render_to_response('tracking_log.html', {'records': record_instances})
|
agpl-3.0
|
[
646,
2197,
199,
646,
2022,
199,
199,
646,
15444,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
17469,
492,
4660,
199,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
4868,
63,
10088,
63,
5306,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
3384,
1068,
14,
711,
492,
664,
63,
711,
199,
199,
504,
4426,
492,
15271,
199,
504,
4426,
492,
18191,
199,
504,
4426,
492,
25905,
199,
504,
4426,
14,
992,
492,
17507,
316,
2445,
199,
504,
1566,
14428,
492,
15271,
465,
1566,
8877,
421,
199,
318,
943,
63,
1430,
8,
1430,
304,
272,
408,
16640,
282,
1566,
701,
10209,
652,
370,
314,
2274,
4426,
1192,
624,
272,
15271,
14,
2254,
8,
1430,
9,
421,
199,
318,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
1406,
63,
354,
12,
849,
9280,
272,
408,
4433,
1083,
370,
664,
1406,
1338,
687,
282,
1056,
1159,
603,
15808,
1211,
12,
340,
3451,
1041,
272,
340,
1056,
365,
440,
488,
436,
2688,
8,
1069,
12,
283,
10614,
358,
436,
1406,
63,
354,
315,
1056,
14,
10614,
26,
267,
372,
1056,
14,
10614,
59,
1291,
63,
354,
61,
272,
587,
26,
267,
372,
849,
421,
199,
318,
485,
362,
63,
1069,
63,
711,
8,
1069,
12,
849,
9280,
272,
408,
4433,
1083,
370,
664,
3531,
687,
282,
1056,
1159,
603,
15808,
1211,
12,
340,
3451,
1041,
272,
340,
1056,
365,
440,
488,
436,
2688,
8,
1069,
12,
283,
10614,
735,
267,
372,
664,
63,
711,
8,
1069,
9,
272,
587,
26,
267,
372,
849,
421,
199,
318,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
574,
63,
354,
12,
849,
9280,
272,
408,
4433,
1083,
370,
664,
1406,
1338,
687,
282,
1056,
1159,
9576,
15,
4030,
1211,
12,
340,
3451,
1041,
272,
340,
1056,
365,
440,
488,
26,
267,
340,
1056,
14,
765,
508,
283,
2970,
356,
288,
372,
1056,
14,
2970,
14,
362,
8,
585,
63,
354,
12,
849,
9,
267,
916,
1056,
14,
765,
508,
283,
4030,
356,
288,
372,
1056,
14,
4030,
14,
362,
8,
585,
63,
354,
12,
849,
9,
272,
372,
849,
421,
199,
318,
922,
63,
3885,
8,
1069,
304,
272,
408,
272,
5297,
1380,
8761,
1240,
370,
298,
1430,
2,
2851,
365,
6326,
701,
282,
922,
14,
339,
9576,
503,
8761,
1240,
1077,
5647,
298,
1430,
63,
466,
401,
298,
1430,
401,
436,
298,
1606,
2,
2368,
14,
272,
408,
272,
862,
26,
267,
3434,
275,
1056,
14,
751,
14,
2473,
272,
871,
26,
267,
3434,
275,
298,
12628,
2,
339,
536,
275,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
283,
1430,
63,
466,
358,
272,
666,
275,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
283,
1430,
297,
5009,
272,
2034,
275,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
283,
1606,
358,
339,
340,
1228,
8,
576,
12,
7116,
9,
436,
822,
8,
576,
9,
690,
378,
26,
267,
862,
26,
288,
666,
275,
2022,
14,
3640,
8,
576,
9,
267,
871,
1722,
26,
288,
986,
339,
1067,
63,
4415,
275,
18191,
14,
1972,
63,
1100,
63,
504,
63,
633,
8,
1606,
9,
272,
1067,
63,
4415,
459,
2473,
418,
275,
3434,
272,
1067,
63,
4415,
459,
1430,
63,
1365,
418,
275,
283,
5750,
7,
272,
1067,
63,
4415,
459,
1606,
418,
275,
2034,
339,
543,
1566,
8877,
14,
362,
63,
8877,
1252,
1100,
360,
8268,
14,
1972,
14,
5750,
297,
1067,
63,
4415,
304,
267,
1566,
8877,
14,
8159,
8,
354,
29,
354,
12,
666,
29,
576,
9,
339,
372,
6183,
360,
3742,
358,
421,
199,
318,
1654,
63,
3885,
8,
1069,
12,
1566,
63,
466,
12,
1566,
12,
2034,
29,
403,
304,
272,
408,
272,
5297,
4474,
4048,
370,
1654,
4145,
14,
339,
8690,
314,
25781,
2382,
314,
1056,
1443,
506,
5962,
12,
465,
1443,
5992,
543,
10041,
3718,
14,
272,
408,
272,
340,
1566,
63,
466,
14,
2460,
4769,
1430,
63,
7270,
531,
436,
1056,
14,
751,
14,
374,
63,
7018,
26,
267,
372,
221,
327,
2793,
1133,
943,
339,
862,
26,
267,
3434,
275,
1056,
14,
751,
14,
2473,
272,
871,
26,
267,
3434,
275,
298,
12628,
2,
339,
327,
5627,
1072,
26,
272,
1566,
275,
469,
267,
298,
2473,
582,
3434,
12,
267,
298,
711,
582,
485,
362,
63,
1069,
63,
711,
8,
1069,
395,
267,
298,
20996,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
2856,
63,
19494,
540,
659,
267,
298,
5694,
63,
3671,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
2856,
63,
13089,
63,
13947,
659,
267,
298,
1430,
63,
1365,
582,
298,
1000,
401,
267,
298,
1430,
63,
466,
582,
1566,
63,
466,
12,
267,
298,
1430,
582,
1566,
12,
267,
298,
4054,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
2856,
63,
3791,
63,
14565,
1959,
2708,
360,
10378,
17,
659,
267,
298,
1606,
582,
2034,
12,
267,
298,
521,
582,
2197,
14,
2083,
14,
10779,
1252,
1814,
8,
9374,
29,
21948,
14,
5834,
395,
267,
298,
1102,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
6613,
63,
2339,
659,
267,
298,
1100,
582,
1566,
8877,
14,
362,
63,
8877,
1252,
6983,
63,
1100,
1062,
272,
789,
339,
327,
6601,
21747,
1504,
787,
3032,
1901,
1566,
13,
14428,
4799,
314,
1067,
701,
4426,
14,
5754,
14,
272,
327,
5852,
3062,
687,
314,
1566,
2348,
3967,
2985,
787,
17487,
25320,
14,
272,
25905,
14,
2168,
63,
28238,
63,
1100,
8,
1430,
9,
339,
943,
63,
1430,
8,
1430,
9,
421,
199,
318,
2120,
63,
3885,
8,
1069,
63,
815,
12,
2120,
63,
815,
12,
1566,
63,
466,
12,
1566,
12,
2034,
29,
403,
304,
272,
408,
272,
3835,
458,
15161,
2556,
367,
4474,
4781,
316,
4453,
22748,
6527,
14,
339,
710,
658,
1430,
63,
466,
64,
365,
282,
1059,
19720,
314,
6770,
1566,
3769,
10367,
12,
272,
1830,
658,
1430,
64,
365,
282,
1211,
3035,
15685,
4722,
1067,
1061,
2556,
272,
365,
6387,
14,
339,
710,
658,
1069,
63,
815,
64,
365,
282,
1211,
3035,
2556
] |
[
2197,
199,
646,
2022,
199,
199,
646,
15444,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
1014,
492,
6183,
199,
504,
1639,
14,
17469,
492,
4660,
199,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
4868,
63,
10088,
63,
5306,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
504,
3384,
1068,
14,
711,
492,
664,
63,
711,
199,
199,
504,
4426,
492,
15271,
199,
504,
4426,
492,
18191,
199,
504,
4426,
492,
25905,
199,
504,
4426,
14,
992,
492,
17507,
316,
2445,
199,
504,
1566,
14428,
492,
15271,
465,
1566,
8877,
421,
199,
318,
943,
63,
1430,
8,
1430,
304,
272,
408,
16640,
282,
1566,
701,
10209,
652,
370,
314,
2274,
4426,
1192,
624,
272,
15271,
14,
2254,
8,
1430,
9,
421,
199,
318,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
1406,
63,
354,
12,
849,
9280,
272,
408,
4433,
1083,
370,
664,
1406,
1338,
687,
282,
1056,
1159,
603,
15808,
1211,
12,
340,
3451,
1041,
272,
340,
1056,
365,
440,
488,
436,
2688,
8,
1069,
12,
283,
10614,
358,
436,
1406,
63,
354,
315,
1056,
14,
10614,
26,
267,
372,
1056,
14,
10614,
59,
1291,
63,
354,
61,
272,
587,
26,
267,
372,
849,
421,
199,
318,
485,
362,
63,
1069,
63,
711,
8,
1069,
12,
849,
9280,
272,
408,
4433,
1083,
370,
664,
3531,
687,
282,
1056,
1159,
603,
15808,
1211,
12,
340,
3451,
1041,
272,
340,
1056,
365,
440,
488,
436,
2688,
8,
1069,
12,
283,
10614,
735,
267,
372,
664,
63,
711,
8,
1069,
9,
272,
587,
26,
267,
372,
849,
421,
199,
318,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
574,
63,
354,
12,
849,
9280,
272,
408,
4433,
1083,
370,
664,
1406,
1338,
687,
282,
1056,
1159,
9576,
15,
4030,
1211,
12,
340,
3451,
1041,
272,
340,
1056,
365,
440,
488,
26,
267,
340,
1056,
14,
765,
508,
283,
2970,
356,
288,
372,
1056,
14,
2970,
14,
362,
8,
585,
63,
354,
12,
849,
9,
267,
916,
1056,
14,
765,
508,
283,
4030,
356,
288,
372,
1056,
14,
4030,
14,
362,
8,
585,
63,
354,
12,
849,
9,
272,
372,
849,
421,
199,
318,
922,
63,
3885,
8,
1069,
304,
272,
408,
272,
5297,
1380,
8761,
1240,
370,
298,
1430,
2,
2851,
365,
6326,
701,
282,
922,
14,
339,
9576,
503,
8761,
1240,
1077,
5647,
298,
1430,
63,
466,
401,
298,
1430,
401,
436,
298,
1606,
2,
2368,
14,
272,
408,
272,
862,
26,
267,
3434,
275,
1056,
14,
751,
14,
2473,
272,
871,
26,
267,
3434,
275,
298,
12628,
2,
339,
536,
275,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
283,
1430,
63,
466,
358,
272,
666,
275,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
283,
1430,
297,
5009,
272,
2034,
275,
485,
362,
63,
1069,
63,
585,
8,
1069,
12,
283,
1606,
358,
339,
340,
1228,
8,
576,
12,
7116,
9,
436,
822,
8,
576,
9,
690,
378,
26,
267,
862,
26,
288,
666,
275,
2022,
14,
3640,
8,
576,
9,
267,
871,
1722,
26,
288,
986,
339,
1067,
63,
4415,
275,
18191,
14,
1972,
63,
1100,
63,
504,
63,
633,
8,
1606,
9,
272,
1067,
63,
4415,
459,
2473,
418,
275,
3434,
272,
1067,
63,
4415,
459,
1430,
63,
1365,
418,
275,
283,
5750,
7,
272,
1067,
63,
4415,
459,
1606,
418,
275,
2034,
339,
543,
1566,
8877,
14,
362,
63,
8877,
1252,
1100,
360,
8268,
14,
1972,
14,
5750,
297,
1067,
63,
4415,
304,
267,
1566,
8877,
14,
8159,
8,
354,
29,
354,
12,
666,
29,
576,
9,
339,
372,
6183,
360,
3742,
358,
421,
199,
318,
1654,
63,
3885,
8,
1069,
12,
1566,
63,
466,
12,
1566,
12,
2034,
29,
403,
304,
272,
408,
272,
5297,
4474,
4048,
370,
1654,
4145,
14,
339,
8690,
314,
25781,
2382,
314,
1056,
1443,
506,
5962,
12,
465,
1443,
5992,
543,
10041,
3718,
14,
272,
408,
272,
340,
1566,
63,
466,
14,
2460,
4769,
1430,
63,
7270,
531,
436,
1056,
14,
751,
14,
374,
63,
7018,
26,
267,
372,
221,
327,
2793,
1133,
943,
339,
862,
26,
267,
3434,
275,
1056,
14,
751,
14,
2473,
272,
871,
26,
267,
3434,
275,
298,
12628,
2,
339,
327,
5627,
1072,
26,
272,
1566,
275,
469,
267,
298,
2473,
582,
3434,
12,
267,
298,
711,
582,
485,
362,
63,
1069,
63,
711,
8,
1069,
395,
267,
298,
20996,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
2856,
63,
19494,
540,
659,
267,
298,
5694,
63,
3671,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
2856,
63,
13089,
63,
13947,
659,
267,
298,
1430,
63,
1365,
582,
298,
1000,
401,
267,
298,
1430,
63,
466,
582,
1566,
63,
466,
12,
267,
298,
1430,
582,
1566,
12,
267,
298,
4054,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
2856,
63,
3791,
63,
14565,
1959,
2708,
360,
10378,
17,
659,
267,
298,
1606,
582,
2034,
12,
267,
298,
521,
582,
2197,
14,
2083,
14,
10779,
1252,
1814,
8,
9374,
29,
21948,
14,
5834,
395,
267,
298,
1102,
582,
485,
362,
63,
1069,
63,
1291,
8,
1069,
12,
283,
6613,
63,
2339,
659,
267,
298,
1100,
582,
1566,
8877,
14,
362,
63,
8877,
1252,
6983,
63,
1100,
1062,
272,
789,
339,
327,
6601,
21747,
1504,
787,
3032,
1901,
1566,
13,
14428,
4799,
314,
1067,
701,
4426,
14,
5754,
14,
272,
327,
5852,
3062,
687,
314,
1566,
2348,
3967,
2985,
787,
17487,
25320,
14,
272,
25905,
14,
2168,
63,
28238,
63,
1100,
8,
1430,
9,
339,
943,
63,
1430,
8,
1430,
9,
421,
199,
318,
2120,
63,
3885,
8,
1069,
63,
815,
12,
2120,
63,
815,
12,
1566,
63,
466,
12,
1566,
12,
2034,
29,
403,
304,
272,
408,
272,
3835,
458,
15161,
2556,
367,
4474,
4781,
316,
4453,
22748,
6527,
14,
339,
710,
658,
1430,
63,
466,
64,
365,
282,
1059,
19720,
314,
6770,
1566,
3769,
10367,
12,
272,
1830,
658,
1430,
64,
365,
282,
1211,
3035,
15685,
4722,
1067,
1061,
2556,
272,
365,
6387,
14,
339,
710,
658,
1069,
63,
815,
64,
365,
282,
1211,
3035,
2556,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
thefab/tornadis
|
tornadis/pool.py
|
1
|
7269
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of tornadis library released under the MIT license.
# See the LICENSE file for more information.
import tornado.gen
import tornado.ioloop
import tornado.locks
import logging
import functools
from collections import deque
from tornadis.client import Client
from tornadis.utils import ContextManagerFuture
from tornadis.exceptions import ClientError
LOG = logging.getLogger(__name__)
class ClientPool(object):
"""High level object to deal with a pool of redis clients."""
def __init__(self, max_size=-1, client_timeout=-1, autoclose=False,
**client_kwargs):
"""Constructor.
Args:
max_size (int): max size of the pool (-1 means "no limit").
client_timeout (int): timeout in seconds of a connection released
to the pool (-1 means "no timeout").
autoclose (boolean): automatically disconnect released connections
with lifetime > client_timeout (test made every
client_timeout/10 seconds).
client_kwargs (dict): Client constructor arguments.
"""
self.max_size = max_size
self.client_timeout = client_timeout
self.client_kwargs = client_kwargs
self.__ioloop = client_kwargs.get('ioloop',
tornado.ioloop.IOLoop.instance())
self.autoclose = autoclose
self.__pool = deque()
if self.max_size != -1:
self.__sem = tornado.locks.Semaphore(self.max_size)
else:
self.__sem = None
self.__autoclose_periodic = None
if self.autoclose and self.client_timeout > 0:
every = int(self.client_timeout) * 100
if int(tornado.version[0]) >= 5:
cb = tornado.ioloop.PeriodicCallback(self._autoclose,
every)
else:
cb = tornado.ioloop.PeriodicCallback(self._autoclose,
every, self.__ioloop)
self.__autoclose_periodic = cb
self.__autoclose_periodic.start()
def _get_client_from_pool_or_make_it(self):
try:
while True:
client = self.__pool.popleft()
if client.is_connected():
if self._is_expired_client(client):
client.disconnect()
continue
break
except IndexError:
client = self._make_client()
return (True, client)
return (False, client)
@tornado.gen.coroutine
def get_connected_client(self):
"""Gets a connected Client object.
If max_size is reached, this method will block until a new client
object is available.
Returns:
A Future object with connected Client instance as a result
(or ClientError if there was a connection problem)
"""
if self.__sem is not None:
yield self.__sem.acquire()
client = None
newly_created, client = self._get_client_from_pool_or_make_it()
if newly_created:
res = yield client.connect()
if not res:
LOG.warning("can't connect to %s", client.title)
raise tornado.gen.Return(
ClientError("can't connect to %s" % client.title))
raise tornado.gen.Return(client)
def get_client_nowait(self):
"""Gets a Client object (not necessary connected).
If max_size is reached, this method will return None (and won't block).
Returns:
A Client instance (not necessary connected) as result (or None).
"""
if self.__sem is not None:
if self.__sem._value == 0:
return None
self.__sem.acquire()
_, client = self._get_client_from_pool_or_make_it()
return client
def _autoclose(self):
newpool = deque()
try:
while True:
client = self.__pool.popleft()
if client.is_connected():
if self._is_expired_client(client):
client.disconnect()
else:
newpool.append(client)
except IndexError:
self.__pool = newpool
def _is_expired_client(self, client):
if self.client_timeout != -1 and client.is_connected():
delta = client.get_last_state_change_timedelta()
if delta.total_seconds() >= self.client_timeout:
return True
return False
def connected_client(self):
"""Returns a ContextManagerFuture to be yielded in a with statement.
Returns:
A ContextManagerFuture object.
Examples:
>>> with (yield pool.connected_client()) as client:
# client is a connected tornadis.Client instance
# it will be automatically released to the pool thanks to
# the "with" keyword
reply = yield client.call("PING")
"""
future = self.get_connected_client()
cb = functools.partial(self._connected_client_release_cb, future)
return ContextManagerFuture(future, cb)
def _connected_client_release_cb(self, future=None):
client = future.result()
self.release_client(client)
def release_client(self, client):
"""Releases a client object to the pool.
Args:
client: Client object.
"""
if isinstance(client, Client):
if not self._is_expired_client(client):
LOG.debug('Client is not expired. Adding back to pool')
self.__pool.append(client)
elif client.is_connected():
LOG.debug('Client is expired and connected. Disconnecting')
client.disconnect()
if self.__sem is not None:
self.__sem.release()
def destroy(self):
"""Disconnects all pooled client objects."""
while True:
try:
client = self.__pool.popleft()
if isinstance(client, Client):
client.disconnect()
except IndexError:
break
@tornado.gen.coroutine
def preconnect(self, size=-1):
"""(pre)Connects some or all redis clients inside the pool.
Args:
size (int): number of redis clients to build and to connect
(-1 means all clients if pool max_size > -1)
Raises:
ClientError: when size == -1 and pool max_size == -1
"""
if size == -1 and self.max_size == -1:
raise ClientError("size=-1 not allowed with pool max_size=-1")
limit = min(size, self.max_size) if size != -1 else self.max_size
clients = yield [self.get_connected_client() for _ in range(0, limit)]
for client in clients:
self.release_client(client)
def _make_client(self):
"""Makes and returns a Client object."""
kwargs = self.client_kwargs
client = Client(**kwargs)
return client
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
11095,
3540,
2297,
3555,
14286,
1334,
314,
10697,
4190,
14,
199,
3,
1666,
314,
5113,
570,
367,
1655,
2556,
14,
199,
199,
646,
12148,
14,
2268,
199,
646,
12148,
14,
27212,
199,
646,
12148,
14,
20218,
199,
646,
2050,
199,
646,
9143,
199,
504,
5055,
492,
15782,
199,
199,
504,
11095,
3540,
2297,
14,
1258,
492,
6810,
199,
504,
11095,
3540,
2297,
14,
1208,
492,
9470,
2988,
14224,
199,
504,
11095,
3540,
2297,
14,
3924,
492,
28972,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
6810,
5453,
8,
785,
304,
272,
408,
11688,
2166,
909,
370,
7962,
543,
282,
4203,
402,
16967,
13431,
1041,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
890,
4022,
17,
12,
1890,
63,
2593,
4022,
17,
12,
6384,
679,
22641,
29,
797,
12,
326,
1011,
1258,
63,
958,
304,
267,
408,
11447,
14,
398,
3033,
26,
288,
1390,
63,
890,
334,
442,
304,
1390,
1568,
402,
314,
4203,
5868,
17,
4910,
298,
889,
2304,
3471,
288,
1890,
63,
2593,
334,
442,
304,
2653,
315,
4696,
402,
282,
1950,
14286,
355,
370,
314,
4203,
5868,
17,
4910,
298,
889,
2653,
3471,
288,
6384,
679,
22641,
334,
4871,
304,
5847,
17639,
14286,
6947,
355,
543,
30097,
690,
1890,
63,
2593,
334,
396,
6326,
4036,
355,
1890,
63,
2593,
15,
709,
4696,
680,
288,
1890,
63,
958,
334,
807,
304,
6810,
3787,
2368,
14,
267,
408,
267,
291,
14,
988,
63,
890,
275,
1390,
63,
890,
267,
291,
14,
1258,
63,
2593,
275,
1890,
63,
2593,
267,
291,
14,
1258,
63,
958,
275,
1890,
63,
958,
267,
291,
855,
27212,
275,
1890,
63,
958,
14,
362,
360,
27212,
297,
5101,
12148,
14,
27212,
14,
23152,
14,
842,
1012,
267,
291,
14,
6898,
679,
22641,
275,
6384,
679,
22641,
267,
291,
855,
2293,
275,
15782,
342,
267,
340,
291,
14,
988,
63,
890,
1137,
446,
17,
26,
288,
291,
855,
21678,
275,
12148,
14,
20218,
14,
26574,
8,
277,
14,
988,
63,
890,
9,
267,
587,
26,
288,
291,
855,
21678,
275,
488,
267,
291,
855,
6898,
679,
22641,
63,
20339,
275,
488,
267,
340,
291,
14,
6898,
679,
22641,
436,
291,
14,
1258,
63,
2593,
690,
378,
26,
288,
4036,
275,
1109,
8,
277,
14,
1258,
63,
2593,
9,
627,
2948,
288,
340,
1109,
8,
18443,
14,
1023,
59,
16,
566,
2356,
959,
26,
355,
7434,
275,
12148,
14,
27212,
14,
2623,
11273,
2806,
8,
277,
423,
6898,
679,
22641,
12,
9349,
4036,
9,
288,
587,
26,
355,
7434,
275,
12148,
14,
27212,
14,
2623,
11273,
2806,
8,
277,
423,
6898,
679,
22641,
12,
9349,
4036,
12,
291,
855,
27212,
9,
288,
291,
855,
6898,
679,
22641,
63,
20339,
275,
7434,
288,
291,
855,
6898,
679,
22641,
63,
20339,
14,
928,
342,
339,
347,
485,
362,
63,
1258,
63,
504,
63,
2293,
63,
269,
63,
1875,
63,
390,
8,
277,
304,
267,
862,
26,
288,
1830,
715,
26,
355,
1890,
275,
291,
855,
2293,
14,
25704,
342,
355,
340,
1890,
14,
374,
63,
7113,
837,
490,
340,
291,
423,
374,
63,
16340,
63,
1258,
8,
1258,
304,
717,
1890,
14,
10673,
342,
717,
1980,
490,
2059,
267,
871,
7888,
26,
288,
1890,
275,
291,
423,
1875,
63,
1258,
342,
288,
372,
334,
549,
12,
1890,
9,
267,
372,
334,
797,
12,
1890,
9,
339,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
63,
7113,
63,
1258,
8,
277,
304,
267,
408,
14426,
282,
8539,
6810,
909,
14,
398,
982,
1390,
63,
890,
365,
13075,
12,
642,
1083,
911,
1853,
5133,
282,
892,
1890,
267,
909,
365,
2808,
14,
398,
1803,
26,
288,
437,
20799,
909,
543,
8539,
6810,
1256,
465,
282,
754,
355,
334,
269,
28972,
340,
2337,
1990,
282,
1950,
5160,
9,
267,
408,
267,
340,
291,
855,
21678,
365,
440,
488,
26,
288,
1995,
291,
855,
21678,
14,
8174,
342,
267,
1890,
275,
488,
267,
13903,
63,
3966,
12,
1890,
275,
291,
423,
362,
63,
1258,
63,
504,
63,
2293,
63,
269,
63,
1875,
63,
390,
342,
267,
340,
13903,
63,
3966,
26,
288,
522,
275,
1995,
1890,
14,
2242,
342,
288,
340,
440,
522,
26,
355,
5051,
14,
3764,
480,
2425,
1133,
4907,
370,
450,
83,
401,
1890,
14,
1213,
9,
355,
746,
12148,
14,
2268,
14,
1767,
8,
490,
28972,
480,
2425,
1133,
4907,
370,
450,
83,
2,
450,
1890,
14,
1213,
430,
267,
746,
12148,
14,
2268,
14,
1767,
8,
1258,
9,
339,
347,
664,
63,
1258,
63,
20870,
8,
277,
304,
267,
408,
14426,
282,
6810,
909,
334,
1397,
5784,
8539,
680,
398,
982,
1390,
63,
890,
365,
13075,
12,
642,
1083,
911,
372,
488,
334,
460,
7859,
1133,
1853,
680,
398,
1803,
26,
288,
437,
6810,
1256,
334,
1397,
5784,
8539,
9,
465,
754,
334,
269,
488,
680,
267,
408,
267,
340,
291,
855,
21678,
365,
440,
488,
26,
288,
340,
291,
855,
21678,
423,
585,
508,
378,
26,
355,
372,
488,
288,
291,
855,
21678,
14,
8174,
342,
267,
5501,
1890,
275,
291,
423,
362,
63,
1258,
63,
504,
63,
2293,
63,
269,
63,
1875,
63,
390,
342,
267,
372,
1890,
339,
347,
485,
6898,
679,
22641,
8,
277,
304,
267,
892,
2293,
275,
15782,
342,
267,
862,
26,
288,
1830,
715,
26,
355,
1890,
275,
291,
855,
2293,
14,
25704,
342,
355,
340,
1890,
14,
374,
63,
7113,
837,
490,
340,
291,
423,
374,
63,
16340,
63,
1258,
8,
1258,
304,
717,
1890,
14,
10673,
342,
490,
587,
26,
717,
892,
2293,
14,
740,
8,
1258,
9,
267,
871,
7888,
26,
288,
291,
855,
2293,
275,
892,
2293,
339,
347,
485,
374,
63,
16340,
63,
1258,
8,
277,
12,
1890,
304,
267,
340,
291,
14,
1258,
63,
2593,
1137,
446,
17,
436,
1890,
14,
374,
63,
7113,
837,
288,
5762,
275,
1890,
14,
362,
63,
2019,
63,
929,
63,
1461,
63,
7473,
342,
288,
340,
5762,
14,
2923,
63,
4515,
342,
2356,
291,
14,
1258,
63,
2593,
26,
355,
372,
715,
267,
372,
756,
339,
347,
8539,
63,
1258,
8,
277
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
11095,
3540,
2297,
3555,
14286,
1334,
314,
10697,
4190,
14,
199,
3,
1666,
314,
5113,
570,
367,
1655,
2556,
14,
199,
199,
646,
12148,
14,
2268,
199,
646,
12148,
14,
27212,
199,
646,
12148,
14,
20218,
199,
646,
2050,
199,
646,
9143,
199,
504,
5055,
492,
15782,
199,
199,
504,
11095,
3540,
2297,
14,
1258,
492,
6810,
199,
504,
11095,
3540,
2297,
14,
1208,
492,
9470,
2988,
14224,
199,
504,
11095,
3540,
2297,
14,
3924,
492,
28972,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
6810,
5453,
8,
785,
304,
272,
408,
11688,
2166,
909,
370,
7962,
543,
282,
4203,
402,
16967,
13431,
1041,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
890,
4022,
17,
12,
1890,
63,
2593,
4022,
17,
12,
6384,
679,
22641,
29,
797,
12,
326,
1011,
1258,
63,
958,
304,
267,
408,
11447,
14,
398,
3033,
26,
288,
1390,
63,
890,
334,
442,
304,
1390,
1568,
402,
314,
4203,
5868,
17,
4910,
298,
889,
2304,
3471,
288,
1890,
63,
2593,
334,
442,
304,
2653,
315,
4696,
402,
282,
1950,
14286,
355,
370,
314,
4203,
5868,
17,
4910,
298,
889,
2653,
3471,
288,
6384,
679,
22641,
334,
4871,
304,
5847,
17639,
14286,
6947,
355,
543,
30097,
690,
1890,
63,
2593,
334,
396,
6326,
4036,
355,
1890,
63,
2593,
15,
709,
4696,
680,
288,
1890,
63,
958,
334,
807,
304,
6810,
3787,
2368,
14,
267,
408,
267,
291,
14,
988,
63,
890,
275,
1390,
63,
890,
267,
291,
14,
1258,
63,
2593,
275,
1890,
63,
2593,
267,
291,
14,
1258,
63,
958,
275,
1890,
63,
958,
267,
291,
855,
27212,
275,
1890,
63,
958,
14,
362,
360,
27212,
297,
5101,
12148,
14,
27212,
14,
23152,
14,
842,
1012,
267,
291,
14,
6898,
679,
22641,
275,
6384,
679,
22641,
267,
291,
855,
2293,
275,
15782,
342,
267,
340,
291,
14,
988,
63,
890,
1137,
446,
17,
26,
288,
291,
855,
21678,
275,
12148,
14,
20218,
14,
26574,
8,
277,
14,
988,
63,
890,
9,
267,
587,
26,
288,
291,
855,
21678,
275,
488,
267,
291,
855,
6898,
679,
22641,
63,
20339,
275,
488,
267,
340,
291,
14,
6898,
679,
22641,
436,
291,
14,
1258,
63,
2593,
690,
378,
26,
288,
4036,
275,
1109,
8,
277,
14,
1258,
63,
2593,
9,
627,
2948,
288,
340,
1109,
8,
18443,
14,
1023,
59,
16,
566,
2356,
959,
26,
355,
7434,
275,
12148,
14,
27212,
14,
2623,
11273,
2806,
8,
277,
423,
6898,
679,
22641,
12,
9349,
4036,
9,
288,
587,
26,
355,
7434,
275,
12148,
14,
27212,
14,
2623,
11273,
2806,
8,
277,
423,
6898,
679,
22641,
12,
9349,
4036,
12,
291,
855,
27212,
9,
288,
291,
855,
6898,
679,
22641,
63,
20339,
275,
7434,
288,
291,
855,
6898,
679,
22641,
63,
20339,
14,
928,
342,
339,
347,
485,
362,
63,
1258,
63,
504,
63,
2293,
63,
269,
63,
1875,
63,
390,
8,
277,
304,
267,
862,
26,
288,
1830,
715,
26,
355,
1890,
275,
291,
855,
2293,
14,
25704,
342,
355,
340,
1890,
14,
374,
63,
7113,
837,
490,
340,
291,
423,
374,
63,
16340,
63,
1258,
8,
1258,
304,
717,
1890,
14,
10673,
342,
717,
1980,
490,
2059,
267,
871,
7888,
26,
288,
1890,
275,
291,
423,
1875,
63,
1258,
342,
288,
372,
334,
549,
12,
1890,
9,
267,
372,
334,
797,
12,
1890,
9,
339,
768,
18443,
14,
2268,
14,
16675,
272,
347,
664,
63,
7113,
63,
1258,
8,
277,
304,
267,
408,
14426,
282,
8539,
6810,
909,
14,
398,
982,
1390,
63,
890,
365,
13075,
12,
642,
1083,
911,
1853,
5133,
282,
892,
1890,
267,
909,
365,
2808,
14,
398,
1803,
26,
288,
437,
20799,
909,
543,
8539,
6810,
1256,
465,
282,
754,
355,
334,
269,
28972,
340,
2337,
1990,
282,
1950,
5160,
9,
267,
408,
267,
340,
291,
855,
21678,
365,
440,
488,
26,
288,
1995,
291,
855,
21678,
14,
8174,
342,
267,
1890,
275,
488,
267,
13903,
63,
3966,
12,
1890,
275,
291,
423,
362,
63,
1258,
63,
504,
63,
2293,
63,
269,
63,
1875,
63,
390,
342,
267,
340,
13903,
63,
3966,
26,
288,
522,
275,
1995,
1890,
14,
2242,
342,
288,
340,
440,
522,
26,
355,
5051,
14,
3764,
480,
2425,
1133,
4907,
370,
450,
83,
401,
1890,
14,
1213,
9,
355,
746,
12148,
14,
2268,
14,
1767,
8,
490,
28972,
480,
2425,
1133,
4907,
370,
450,
83,
2,
450,
1890,
14,
1213,
430,
267,
746,
12148,
14,
2268,
14,
1767,
8,
1258,
9,
339,
347,
664,
63,
1258,
63,
20870,
8,
277,
304,
267,
408,
14426,
282,
6810,
909,
334,
1397,
5784,
8539,
680,
398,
982,
1390,
63,
890,
365,
13075,
12,
642,
1083,
911,
372,
488,
334,
460,
7859,
1133,
1853,
680,
398,
1803,
26,
288,
437,
6810,
1256,
334,
1397,
5784,
8539,
9,
465,
754,
334,
269,
488,
680,
267,
408,
267,
340,
291,
855,
21678,
365,
440,
488,
26,
288,
340,
291,
855,
21678,
423,
585,
508,
378,
26,
355,
372,
488,
288,
291,
855,
21678,
14,
8174,
342,
267,
5501,
1890,
275,
291,
423,
362,
63,
1258,
63,
504,
63,
2293,
63,
269,
63,
1875,
63,
390,
342,
267,
372,
1890,
339,
347,
485,
6898,
679,
22641,
8,
277,
304,
267,
892,
2293,
275,
15782,
342,
267,
862,
26,
288,
1830,
715,
26,
355,
1890,
275,
291,
855,
2293,
14,
25704,
342,
355,
340,
1890,
14,
374,
63,
7113,
837,
490,
340,
291,
423,
374,
63,
16340,
63,
1258,
8,
1258,
304,
717,
1890,
14,
10673,
342,
490,
587,
26,
717,
892,
2293,
14,
740,
8,
1258,
9,
267,
871,
7888,
26,
288,
291,
855,
2293,
275,
892,
2293,
339,
347,
485,
374,
63,
16340,
63,
1258,
8,
277,
12,
1890,
304,
267,
340,
291,
14,
1258,
63,
2593,
1137,
446,
17,
436,
1890,
14,
374,
63,
7113,
837,
288,
5762,
275,
1890,
14,
362,
63,
2019,
63,
929,
63,
1461,
63,
7473,
342,
288,
340,
5762,
14,
2923,
63,
4515,
342,
2356,
291,
14,
1258,
63,
2593,
26,
355,
372,
715,
267,
372,
756,
339,
347,
8539,
63,
1258,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
masayukig/tempest
|
tempest/tests/lib/services/compute/test_servers_client.py
|
3
|
36247
|
# Copyright 2015 IBM Corp.
# Copyright 2017 AT&T Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import mock
from tempest.lib.services.compute import base_compute_client
from tempest.lib.services.compute import servers_client
from tempest.tests.lib import fake_auth_provider
from tempest.tests.lib.services import base
class TestServersClient(base.BaseServiceTest):
FAKE_SERVERS = {'servers': [{
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"links": [
{
"href": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19",
"rel": "self"
},
{
"href": "http://os.co/616fb98f-46ca-475e-917e-2563e5a8cd19",
"rel": "bookmark"
}
],
"name": u"new\u1234-server-test"}]
}
FAKE_SERVER_DIAGNOSTICS = {
"cpu0_time": 17300000000,
"memory": 524288,
"vda_errors": -1,
"vda_read": 262144,
"vda_read_req": 112,
"vda_write": 5778432,
"vda_write_req": 488,
"vnet1_rx": 2070139,
"vnet1_rx_drop": 0,
"vnet1_rx_errors": 0,
"vnet1_rx_packets": 26701,
"vnet1_tx": 140208,
"vnet1_tx_drop": 0,
"vnet1_tx_errors": 0,
"vnet1_tx_packets": 662
}
FAKE_SERVER_GET = {'server': {
"accessIPv4": "",
"accessIPv6": "",
"addresses": {
"private": [
{
"addr": "192.168.0.3",
"version": 4
}
]
},
"created": "2012-08-20T21:11:09Z",
"flavor": {
"id": "1",
"links": [
{
"href": "http://os.com/openstack/flavors/1",
"rel": "bookmark"
}
]
},
"hostId": "65201c14a29663e06d0748e561207d998b343e1d164bfa0aafa9c45d",
"id": "893c7791-f1df-4c3d-8383-3caae9656c62",
"image": {
"id": "70a599e0-31e7-49b7-b260-868f441e862b",
"links": [
{
"href": "http://imgs/70a599e0-31e7-49b7-b260-868f441e862b",
"rel": "bookmark"
}
]
},
"links": [
{
"href": "http://v2/srvs/893c7791-f1df-4c3d-8383-3caae9656c62",
"rel": "self"
},
{
"href": "http://srvs/893c7791-f1df-4c3d-8383-3caae9656c62",
"rel": "bookmark"
}
],
"metadata": {
u"My Server N\u1234me": u"Apa\u1234che1"
},
"name": u"new\u1234-server-test",
"progress": 0,
"status": "ACTIVE",
"tenant_id": "openstack",
"updated": "2012-08-20T21:11:09Z",
"user_id": "fake"}
}
FAKE_SERVER_POST = {"server": {
"id": "616fb98f-46ca-475e-917e-2563e5a8cd19",
"adminPass": "fake-admin-pass",
"security_groups": [
'fake-security-group-1',
'fake-security-group-2'
],
"links": [
{
"href": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19",
"rel": "self"
},
{
"href": "http://os.co/616fb98f-46ca-475e-917e-2563e5a8cd19",
"rel": "bookmark"
}
],
"OS-DCF:diskConfig": "fake-disk-config"}
}
FAKE_ADDRESS = {"addresses": {
"private": [
{
"addr": "192.168.0.3",
"version": 4
}
]}
}
FAKE_COMMON_VOLUME = {
"id": "a6b0875b-6b5d-4a5a-81eb-0c3aa62e5fdb",
"device": "fake-device",
"volumeId": "a6b0875b-46ca-475e-917e-0c3aa62e5fdb",
"serverId": "616fb98f-46ca-475e-917e-2563e5a8cd19"
}
FAKE_VIRTUAL_INTERFACES = {
"id": "a6b0875b-46ca-475e-917e-0c3aa62e5fdb",
"mac_address": "00:25:90:5b:f8:c3",
"OS-EXT-VIF-NET:net_id": "fake-os-net-id"
}
FAKE_INSTANCE_ACTIONS = {
"action": "fake-action",
"request_id": "16fb98f-46ca-475e-917e-2563e5a8cd19",
"user_id": "16fb98f-46ca-475e-917e-2563e5a8cd12",
"project_id": "16fb98f-46ca-475e-917e-2563e5a8cd34",
"start_time": "2016-10-02T10:00:00-05:00",
"message": "fake-msg",
"instance_uuid": "16fb98f-46ca-475e-917e-2563e5a8cd12"
}
FAKE_VNC_CONSOLE = {
"type": "fake-type",
"url": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19"
}
FAKE_SERVER_PASSWORD = {
"adminPass": "fake-password",
}
FAKE_INSTANCE_ACTION_EVENTS = {
"event": "fake-event",
"start_time": "2016-10-02T10:00:00-05:00",
"finish_time": "2016-10-02T10:00:00-05:00",
"result": "fake-result",
"traceback": "fake-trace-back"
}
FAKE_SECURITY_GROUPS = [{
"description": "default",
"id": "3fb26eb3-581b-4420-9963-b0879a026506",
"name": "default",
"rules": [],
"tenant_id": "openstack"
}]
FAKE_INSTANCE_WITH_EVENTS = copy.deepcopy(FAKE_INSTANCE_ACTIONS)
FAKE_INSTANCE_WITH_EVENTS['events'] = [FAKE_INSTANCE_ACTION_EVENTS]
FAKE_REBUILD_SERVER = copy.deepcopy(FAKE_SERVER_GET)
FAKE_REBUILD_SERVER['server']['adminPass'] = 'fake-admin-pass'
FAKE_TAGS = ["foo", "bar"]
REPLACE_FAKE_TAGS = ["baz", "qux"]
server_id = FAKE_SERVER_GET['server']['id']
network_id = 'a6b0875b-6b5d-4a5a-81eb-0c3aa62e5fdb'
def setUp(self):
super(TestServersClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
self.client = servers_client.ServersClient(
fake_auth, 'compute', 'regionOne')
self.addCleanup(mock.patch.stopall)
def test_list_servers_with_str_body(self):
self._test_list_servers()
def test_list_servers_with_bytes_body(self):
self._test_list_servers(bytes_body=True)
def _test_list_servers(self, bytes_body=False):
self.check_service_client_function(
self.client.list_servers,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_SERVERS,
bytes_body)
def test_show_server_with_str_body(self):
self._test_show_server()
def test_show_server_with_bytes_body(self):
self._test_show_server(bytes_body=True)
def _test_show_server(self, bytes_body=False):
self.check_service_client_function(
self.client.show_server,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_SERVER_GET,
bytes_body,
server_id=self.server_id
)
def test_delete_server(self):
self.check_service_client_function(
self.client.delete_server,
'tempest.lib.common.rest_client.RestClient.delete',
{},
status=204,
server_id=self.server_id
)
def test_create_server_with_str_body(self):
self._test_create_server()
def test_create_server_with_bytes_body(self):
self._test_create_server(True)
def _test_create_server(self, bytes_body=False):
self.check_service_client_function(
self.client.create_server,
'tempest.lib.common.rest_client.RestClient.post',
self.FAKE_SERVER_POST,
bytes_body,
status=202,
name='fake-name',
imageRef='fake-image-ref',
flavorRef='fake-flavor-ref'
)
def test_list_addresses_with_str_body(self):
self._test_list_addresses()
def test_list_addresses_with_bytes_body(self):
self._test_list_addresses(True)
def _test_list_addresses(self, bytes_body=False):
self.check_service_client_function(
self.client.list_addresses,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_ADDRESS,
bytes_body,
server_id=self.server_id
)
def test_list_addresses_by_network_with_str_body(self):
self._test_list_addresses_by_network()
def test_list_addresses_by_network_with_bytes_body(self):
self._test_list_addresses_by_network(True)
def _test_list_addresses_by_network(self, bytes_body=False):
self.check_service_client_function(
self.client.list_addresses_by_network,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_ADDRESS['addresses'],
bytes_body,
server_id=self.server_id,
network_id=self.network_id
)
def test_action_with_str_body(self):
self._test_action()
def test_action_with_bytes_body(self):
self._test_action(True)
def _test_action(self, bytes_body=False):
self.check_service_client_function(
self.client.action,
'tempest.lib.common.rest_client.RestClient.post',
{},
bytes_body,
server_id=self.server_id,
action_name='fake-action-name',
schema={'status_code': 200}
)
def test_create_backup_with_str_body(self):
self._test_create_backup()
def test_create_backup_with_bytes_body(self):
self._test_create_backup(True)
def _test_create_backup(self, bytes_body=False):
self.check_service_client_function(
self.client.create_backup,
'tempest.lib.common.rest_client.RestClient.post',
{},
bytes_body,
status=202,
server_id=self.server_id,
backup_type='fake-backup',
rotation='fake-rotation',
name='fake-name'
)
def test_evacuate_server_with_str_body(self):
self._test_evacuate_server()
def test_evacuate_server_with_bytes_body(self):
self._test_evacuate_server(bytes_body=True)
def _test_evacuate_server(self, bytes_body=False):
kwargs = {'server_id': self.server_id,
'host': 'fake-target-host'}
self.check_service_client_function(
self.client.evacuate_server,
'tempest.lib.common.rest_client.RestClient.post',
self.FAKE_SERVER_PASSWORD,
bytes_body,
**kwargs)
def test_change_password_with_str_body(self):
self._test_change_password()
def test_change_password_with_bytes_body(self):
self._test_change_password(True)
def _test_change_password(self, bytes_body=False):
self.check_service_client_function(
self.client.change_password,
'tempest.lib.common.rest_client.RestClient.post',
{},
bytes_body,
status=202,
server_id=self.server_id,
adminPass='fake-admin-pass'
)
def test_show_password_with_str_body(self):
self._test_show_password()
def test_show_password_with_bytes_body(self):
self._test_show_password(True)
def _test_show_password(self, bytes_body=False):
self.check_service_client_function(
self.client.show_password,
'tempest.lib.common.rest_client.RestClient.get',
{'password': 'fake-password'},
bytes_body,
server_id=self.server_id
)
def test_delete_password(self):
self.check_service_client_function(
self.client.delete_password,
'tempest.lib.common.rest_client.RestClient.delete',
{},
status=204,
server_id=self.server_id
)
def test_reboot_server(self):
self.check_service_client_function(
self.client.reboot_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id,
type='fake-reboot-type'
)
def test_rebuild_server_with_str_body(self):
self._test_rebuild_server()
def test_rebuild_server_with_bytes_body(self):
self._test_rebuild_server(True)
def _test_rebuild_server(self, bytes_body=False):
self.check_service_client_function(
self.client.rebuild_server,
'tempest.lib.common.rest_client.RestClient.post',
self.FAKE_REBUILD_SERVER,
bytes_body,
status=202,
server_id=self.server_id,
image_ref='fake-image-ref'
)
def test_resize_server(self):
self.check_service_client_function(
self.client.resize_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id,
flavor_ref='fake-flavor-ref'
)
def test_confirm_resize_server(self):
self.check_service_client_function(
self.client.confirm_resize_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=204,
server_id=self.server_id
)
def test_revert_resize(self):
self.check_service_client_function(
self.client.revert_resize_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_list_server_metadata_with_str_body(self):
self._test_list_server_metadata()
def test_list_server_metadata_with_bytes_body(self):
self._test_list_server_metadata()
def _test_list_server_metadata(self, bytes_body=False):
self.check_service_client_function(
self.client.list_server_metadata,
'tempest.lib.common.rest_client.RestClient.get',
{'metadata': {'fake-key': 'fake-meta-data'}},
bytes_body,
server_id=self.server_id
)
def test_set_server_metadata_with_str_body(self):
self._test_set_server_metadata()
def test_set_server_metadata_with_bytes_body(self):
self._test_set_server_metadata(True)
def _test_set_server_metadata(self, bytes_body=False):
self.check_service_client_function(
self.client.set_server_metadata,
'tempest.lib.common.rest_client.RestClient.put',
{'metadata': {'fake-key': 'fake-meta-data'}},
bytes_body,
server_id=self.server_id,
meta='fake-meta'
)
def test_update_server_metadata_with_str_body(self):
self._test_update_server_metadata()
def test_update_server_metadata_with_bytes_body(self):
self._test_update_server_metadata(True)
def _test_update_server_metadata(self, bytes_body=False):
self.check_service_client_function(
self.client.update_server_metadata,
'tempest.lib.common.rest_client.RestClient.post',
{'metadata': {'fake-key': 'fake-meta-data'}},
bytes_body,
server_id=self.server_id,
meta='fake-meta'
)
def test_show_server_metadata_item_with_str_body(self):
self._test_show_server_metadata()
def test_show_server_metadata_item_with_bytes_body(self):
self._test_show_server_metadata(True)
def _test_show_server_metadata(self, bytes_body=False):
self.check_service_client_function(
self.client.show_server_metadata_item,
'tempest.lib.common.rest_client.RestClient.get',
{'meta': {'fake-key': 'fake-meta-data'}},
bytes_body,
server_id=self.server_id,
key='fake-key'
)
def test_set_server_metadata_item_with_str_body(self):
self._test_set_server_metadata_item()
def test_set_server_metadata_item_with_bytes_body(self):
self._test_set_server_metadata_item(True)
def _test_set_server_metadata_item(self, bytes_body=False):
self.check_service_client_function(
self.client.set_server_metadata_item,
'tempest.lib.common.rest_client.RestClient.put',
{'meta': {'fake-key': 'fake-meta-data'}},
bytes_body,
server_id=self.server_id,
key='fake-key',
meta='fake-meta'
)
def test_delete_server_metadata(self):
self.check_service_client_function(
self.client.delete_server_metadata_item,
'tempest.lib.common.rest_client.RestClient.delete',
{},
status=204,
server_id=self.server_id,
key='fake-key'
)
def test_stop_server(self):
self.check_service_client_function(
self.client.stop_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_start_server(self):
self.check_service_client_function(
self.client.start_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_attach_volume_with_str_body(self):
self._test_attach_volume_server()
def test_attach_volume_with_bytes_body(self):
self._test_attach_volume_server(True)
def _test_attach_volume_server(self, bytes_body=False):
self.check_service_client_function(
self.client.attach_volume,
'tempest.lib.common.rest_client.RestClient.post',
{'volumeAttachment': self.FAKE_COMMON_VOLUME},
bytes_body,
server_id=self.server_id
)
def test_update_attached_volume(self):
self.check_service_client_function(
self.client.update_attached_volume,
'tempest.lib.common.rest_client.RestClient.put',
{},
status=202,
server_id=self.server_id,
attachment_id='fake-attachment-id',
volumeId='fake-volume-id'
)
def test_detach_volume_with_str_body(self):
self._test_detach_volume_server()
def test_detach_volume_with_bytes_body(self):
self._test_detach_volume_server(True)
def _test_detach_volume_server(self, bytes_body=False):
self.check_service_client_function(
self.client.detach_volume,
'tempest.lib.common.rest_client.RestClient.delete',
{},
bytes_body,
status=202,
server_id=self.server_id,
volume_id=self.FAKE_COMMON_VOLUME['volumeId']
)
def test_show_volume_attachment_with_str_body(self):
self._test_show_volume_attachment()
def test_show_volume_attachment_with_bytes_body(self):
self._test_show_volume_attachment(True)
def _test_show_volume_attachment(self, bytes_body=False):
self.check_service_client_function(
self.client.show_volume_attachment,
'tempest.lib.common.rest_client.RestClient.get',
{'volumeAttachment': self.FAKE_COMMON_VOLUME},
bytes_body,
server_id=self.server_id,
volume_id=self.FAKE_COMMON_VOLUME['volumeId']
)
def test_list_volume_attachments_with_str_body(self):
self._test_list_volume_attachments()
def test_list_volume_attachments_with_bytes_body(self):
self._test_list_volume_attachments(True)
def _test_list_volume_attachments(self, bytes_body=False):
self.check_service_client_function(
self.client.list_volume_attachments,
'tempest.lib.common.rest_client.RestClient.get',
{'volumeAttachments': [self.FAKE_COMMON_VOLUME]},
bytes_body,
server_id=self.server_id
)
def test_add_security_group_with_str_body(self):
self._test_add_security_group()
def test_add_security_group_with_bytes_body(self):
self._test_add_security_group(True)
def _test_add_security_group(self, bytes_body=False):
self.check_service_client_function(
self.client.add_security_group,
'tempest.lib.common.rest_client.RestClient.post',
{},
bytes_body,
status=202,
server_id=self.server_id,
name='fake-name'
)
def test_remove_security_group(self):
self.check_service_client_function(
self.client.remove_security_group,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id,
name='fake-name'
)
def test_live_migrate_server_with_str_body(self):
self._test_live_migrate_server()
def test_live_migrate_server_with_bytes_body(self):
self._test_live_migrate_server(True)
def _test_live_migrate_server(self, bytes_body=False):
self.check_service_client_function(
self.client.live_migrate_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
bytes_body,
status=202,
server_id=self.server_id
)
def test_migrate_server_with_str_body(self):
self._test_migrate_server()
def test_migrate_server_with_bytes_body(self):
self._test_migrate_server(True)
def _test_migrate_server(self, bytes_body=False):
self.check_service_client_function(
self.client.migrate_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
bytes_body,
status=202,
server_id=self.server_id
)
def test_lock_server(self):
self.check_service_client_function(
self.client.lock_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_unlock_server(self):
self.check_service_client_function(
self.client.unlock_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_suspend_server(self):
self.check_service_client_function(
self.client.suspend_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_resume_server(self):
self.check_service_client_function(
self.client.resume_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_pause_server(self):
self.check_service_client_function(
self.client.pause_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_unpause_server(self):
self.check_service_client_function(
self.client.unpause_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_reset_state(self):
self.check_service_client_function(
self.client.reset_state,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id,
state='fake-state'
)
def test_shelve_server(self):
self.check_service_client_function(
self.client.shelve_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_unshelve_server(self):
self.check_service_client_function(
self.client.unshelve_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_shelve_offload_server(self):
self.check_service_client_function(
self.client.shelve_offload_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_get_console_output_with_str_body(self):
self._test_get_console_output()
def test_get_console_output_with_bytes_body(self):
self._test_get_console_output(True)
def _test_get_console_output(self, bytes_body=False):
self.check_service_client_function(
self.client.get_console_output,
'tempest.lib.common.rest_client.RestClient.post',
{'output': 'fake-output'},
bytes_body,
server_id=self.server_id,
length='fake-length'
)
def test_list_virtual_interfaces_with_str_body(self):
self._test_list_virtual_interfaces()
def test_list_virtual_interfaces_with_bytes_body(self):
self._test_list_virtual_interfaces(True)
def _test_list_virtual_interfaces(self, bytes_body=False):
self.check_service_client_function(
self.client.list_virtual_interfaces,
'tempest.lib.common.rest_client.RestClient.get',
{'virtual_interfaces': [self.FAKE_VIRTUAL_INTERFACES]},
bytes_body,
server_id=self.server_id
)
def test_rescue_server_with_str_body(self):
self._test_rescue_server()
def test_rescue_server_with_bytes_body(self):
self._test_rescue_server(True)
def _test_rescue_server(self, bytes_body=False):
self.check_service_client_function(
self.client.rescue_server,
'tempest.lib.common.rest_client.RestClient.post',
{'adminPass': 'fake-admin-pass'},
bytes_body,
server_id=self.server_id
)
def test_unrescue_server(self):
self.check_service_client_function(
self.client.unrescue_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_show_server_diagnostics_with_str_body(self):
self._test_show_server_diagnostics()
def test_show_server_diagnostics_with_bytes_body(self):
self._test_show_server_diagnostics(True)
def _test_show_server_diagnostics(self, bytes_body=False):
self.check_service_client_function(
self.client.show_server_diagnostics,
'tempest.lib.common.rest_client.RestClient.get',
self.FAKE_SERVER_DIAGNOSTICS,
bytes_body,
status=200,
server_id=self.server_id
)
def test_list_instance_actions_with_str_body(self):
self._test_list_instance_actions()
def test_list_instance_actions_with_bytes_body(self):
self._test_list_instance_actions(True)
def _test_list_instance_actions(self, bytes_body=False):
self.check_service_client_function(
self.client.list_instance_actions,
'tempest.lib.common.rest_client.RestClient.get',
{'instanceActions': [self.FAKE_INSTANCE_ACTIONS]},
bytes_body,
server_id=self.server_id
)
def test_show_instance_action_with_str_body(self):
self._test_show_instance_action()
def test_show_instance_action_with_bytes_body(self):
self._test_show_instance_action(True)
def _test_show_instance_action(self, bytes_body=False):
self.check_service_client_function(
self.client.show_instance_action,
'tempest.lib.common.rest_client.RestClient.get',
{'instanceAction': self.FAKE_INSTANCE_WITH_EVENTS},
bytes_body,
server_id=self.server_id,
request_id='fake-request-id'
)
def test_force_delete_server(self):
self.check_service_client_function(
self.client.force_delete_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_restore_soft_deleted_server(self):
self.check_service_client_function(
self.client.restore_soft_deleted_server,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_reset_network(self):
self.check_service_client_function(
self.client.reset_network,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_inject_network_info(self):
self.check_service_client_function(
self.client.inject_network_info,
'tempest.lib.common.rest_client.RestClient.post',
{},
status=202,
server_id=self.server_id
)
def test_get_vnc_console_with_str_body(self):
self._test_get_vnc_console()
def test_get_vnc_console_with_bytes_body(self):
self._test_get_vnc_console(True)
def _test_get_vnc_console(self, bytes_body=False):
self.check_service_client_function(
self.client.get_vnc_console,
'tempest.lib.common.rest_client.RestClient.post',
{'console': self.FAKE_VNC_CONSOLE},
bytes_body,
server_id=self.server_id,
type='fake-console-type'
)
def test_list_security_groups_by_server_with_str_body(self):
self._test_list_security_groups_by_server()
def test_list_security_groups_by_server_with_bytes_body(self):
self._test_list_security_groups_by_server(True)
def _test_list_security_groups_by_server(self, bytes_body=False):
self.check_service_client_function(
self.client.list_security_groups_by_server,
'tempest.lib.common.rest_client.RestClient.get',
{'security_groups': self.FAKE_SECURITY_GROUPS},
bytes_body,
server_id=self.server_id
)
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_list_tags_str_body(self, _):
self._test_list_tags()
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_list_tags_byte_body(self, _):
self._test_list_tags(bytes_body=True)
def _test_list_tags(self, bytes_body=False):
expected = {"tags": self.FAKE_TAGS}
self.check_service_client_function(
self.client.list_tags,
'tempest.lib.common.rest_client.RestClient.get',
expected,
server_id=self.server_id,
to_utf=bytes_body)
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_update_all_tags_str_body(self, _):
self._test_update_all_tags()
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_update_all_tags_byte_body(self, _):
self._test_update_all_tags(bytes_body=True)
def _test_update_all_tags(self, bytes_body=False):
expected = {"tags": self.REPLACE_FAKE_TAGS}
self.check_service_client_function(
self.client.update_all_tags,
'tempest.lib.common.rest_client.RestClient.put',
expected,
server_id=self.server_id,
tags=self.REPLACE_FAKE_TAGS,
to_utf=bytes_body)
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_delete_all_tags(self, _):
self.check_service_client_function(
self.client.delete_all_tags,
'tempest.lib.common.rest_client.RestClient.delete',
{},
server_id=self.server_id,
status=204)
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_check_tag_existence_str_body(self, _):
self._test_check_tag_existence()
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_check_tag_existence_byte_body(self, _):
self._test_check_tag_existence(bytes_body=True)
def _test_check_tag_existence(self, bytes_body=False):
self.check_service_client_function(
self.client.check_tag_existence,
'tempest.lib.common.rest_client.RestClient.get',
{},
server_id=self.server_id,
tag=self.FAKE_TAGS[0],
status=204,
to_utf=bytes_body)
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_update_tag_str_body(self, _):
self._test_update_tag()
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_update_tag_byte_body(self, _):
self._test_update_tag(bytes_body=True)
def _test_update_tag(self, bytes_body=False):
self.check_service_client_function(
self.client.update_tag,
'tempest.lib.common.rest_client.RestClient.put',
{},
server_id=self.server_id,
tag=self.FAKE_TAGS[0],
status=201,
headers={'location': 'fake_location'},
to_utf=bytes_body)
@mock.patch.object(base_compute_client, 'COMPUTE_MICROVERSION',
new_callable=mock.PropertyMock(return_value='2.26'))
def test_delete_tag(self, _):
self.check_service_client_function(
self.client.delete_tag,
'tempest.lib.common.rest_client.RestClient.delete',
{},
server_id=self.server_id,
tag=self.FAKE_TAGS[0],
status=204,
)
class TestServersClientMinV26(base.BaseServiceTest):
def setUp(self):
super(TestServersClientMinV26, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
self.client = servers_client.ServersClient(fake_auth, 'compute',
'regionOne')
base_compute_client.COMPUTE_MICROVERSION = '2.6'
self.server_id = "920eaac8-a284-4fd1-9c2c-b30f0181b125"
def tearDown(self):
super(TestServersClientMinV26, self).tearDown()
base_compute_client.COMPUTE_MICROVERSION = None
def test_get_remote_consoles(self):
self.check_service_client_function(
self.client.get_remote_console,
'tempest.lib.common.rest_client.RestClient.post',
{
'remote_console': {
'protocol': 'serial',
'type': 'serial',
'url': 'ws://127.0.0.1:6083/?token=IllAllowIt'
}
},
server_id=self.server_id,
console_type='serial',
protocol='serial',
)
|
apache-2.0
|
[
3,
1898,
6900,
26202,
22304,
14,
199,
3,
1898,
9708,
15059,
6,
52,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
199,
646,
1683,
199,
199,
504,
24076,
14,
773,
14,
5950,
14,
3357,
492,
1300,
63,
3357,
63,
1258,
199,
504,
24076,
14,
773,
14,
5950,
14,
3357,
492,
8037,
63,
1258,
199,
504,
24076,
14,
2219,
14,
773,
492,
4026,
63,
1178,
63,
3780,
199,
504,
24076,
14,
2219,
14,
773,
14,
5950,
492,
1300,
421,
199,
533,
1379,
23637,
3041,
8,
1095,
14,
1563,
3167,
774,
304,
339,
25699,
63,
6613,
51,
275,
791,
5871,
356,
8910,
267,
298,
344,
582,
298,
26666,
4675,
2905,
70,
13,
2466,
696,
13,
30494,
69,
13,
29702,
69,
13,
29990,
69,
21,
65,
24,
2866,
1167,
401,
267,
298,
4614,
582,
359,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
736,
14,
331,
15,
86,
18,
15,
26666,
4675,
2905,
70,
13,
2466,
696,
13,
30494,
69,
13,
29702,
69,
13,
29990,
69,
21,
65,
24,
2866,
1167,
401,
355,
298,
3369,
582,
298,
277,
2,
288,
1660,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
736,
14,
331,
15,
26666,
4675,
2905,
70,
13,
2466,
696,
13,
30494,
69,
13,
29702,
69,
13,
29990,
69,
21,
65,
24,
2866,
1167,
401,
355,
298,
3369,
582,
298,
17341,
2,
288,
789,
267,
2156,
267,
298,
354,
582,
399,
2,
1222,
60,
85,
4321,
13,
1000,
13,
396,
3570,
61,
272,
789,
339,
25699,
63,
6613,
63,
1914,
1254,
2826,
840,
21174,
275,
469,
267,
298,
3541,
16,
63,
521,
582,
413,
2898,
3607,
12,
267,
298,
4844,
582,
959,
1194,
10740,
12,
267,
298,
86,
983,
63,
2550,
582,
446,
17,
12,
267,
298,
86,
983,
63,
739,
582,
499,
2789,
9862,
12,
267,
298,
86,
983,
63,
739,
63,
2103,
582,
20240,
12,
267,
298,
86,
983,
63,
952,
582,
959,
1138,
1349,
708,
12,
267,
298,
86,
983,
63,
952,
63,
2103,
582,
841,
1299,
12,
267,
298,
86,
846,
17,
63,
6872,
582,
31533,
614,
1355,
12,
267,
298,
86,
846,
17,
63,
6872,
63,
4824,
582,
378,
12,
267,
298,
86,
846,
17,
63,
6872,
63,
2550,
582,
378,
12,
267,
298,
86,
846,
17,
63,
6872,
63,
18853,
582,
499,
1822,
614,
12,
267,
298,
86,
846,
17,
63,
2347,
582,
4329,
996,
2036,
12,
267,
298,
86,
846,
17,
63,
2347,
63,
4824,
582,
378,
12,
267,
298,
86,
846,
17,
63,
2347,
63,
2550,
582,
378,
12,
267,
298,
86,
846,
17,
63,
2347,
63,
18853,
582,
1227,
2789,
272,
789,
339,
25699,
63,
6613,
63,
2970,
275,
791,
1000,
356,
469,
267,
298,
2732,
12179,
20,
582,
4873,
267,
298,
2732,
12179,
22,
582,
4873,
267,
298,
7423,
582,
469,
288,
298,
4239,
582,
359,
355,
469,
490,
298,
2697,
582,
298,
5756,
14,
6568,
14,
16,
14,
19,
401,
490,
298,
1023,
582,
841,
355,
789,
288,
1622,
267,
1660,
267,
298,
3966,
582,
298,
7409,
13,
2036,
13,
1165,
52,
2025,
26,
845,
26,
1643,
58,
401,
267,
298,
6081,
582,
469,
288,
298,
344,
582,
298,
17,
401,
288,
298,
4614,
582,
359,
355,
469,
490,
298,
6399,
582,
298,
1014,
921,
736,
14,
957,
15,
8512,
15,
18664,
15,
17,
401,
490,
298,
3369,
582,
298,
17341,
2,
355,
789,
288,
1622,
267,
1660,
267,
298,
1102,
1304,
582,
298,
2182,
1797,
67,
1079,
65,
1398,
18263,
69,
1690,
68,
16,
18770,
69,
1367,
713,
1780,
68,
13830,
66,
14761,
69,
17,
68,
8982,
66,
667,
16,
2158,
667,
25,
67,
2322,
68,
401,
267,
298,
344,
582,
298,
14590,
67,
1138,
3328,
13,
70,
17,
1587,
13,
20,
67,
19,
68,
13,
24,
15504,
13,
19,
696,
3624,
2534,
1367,
67,
2789,
401,
267,
298,
1569,
582,
469,
288,
298,
344,
582,
298,
2760,
65,
30859,
69,
16,
13,
2192,
69,
23,
13,
1887,
66,
23,
13,
66,
13085,
13,
15430,
70,
24284,
69,
16414,
66,
401,
288,
298,
4614,
582,
359,
355,
469,
490,
298,
6399,
582,
298,
1014,
921,
1017,
458,
15,
2760,
65,
30859,
69,
16,
13,
2192,
69,
23,
13,
1887,
66,
23,
13,
66,
13085,
13,
15430,
70,
24284,
69,
16414,
66,
401,
490,
298,
3369,
582,
298,
17341,
2,
355,
789,
288,
1622,
267,
1660,
267,
298,
4614,
582,
359,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
86,
18,
15,
5474,
3122,
15,
14590,
67,
1138,
3328,
13,
70,
17,
1587,
13,
20,
67,
19,
68,
13,
24,
15504,
13,
19,
696,
3624,
2534,
1367,
67,
2789,
401,
355,
298,
3369,
582,
298,
277,
2,
288,
1660,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
5474,
3122,
15,
14590,
67,
1138,
3328,
13,
70,
17,
1587,
13,
20,
67,
19,
68,
13,
24,
15504,
13,
19,
696,
3624,
2534,
1367,
67,
2789,
401,
355,
298,
3369,
582,
298,
17341,
2,
288,
789,
267,
2156,
267,
298,
2343,
582,
469,
288,
399,
2,
5713,
7146,
653,
60,
85,
4321,
278,
582,
399,
2,
33,
387,
60,
85,
4321,
595,
17,
2,
267,
1660,
267,
298,
354,
582,
399,
2,
1222,
60,
85,
4321,
13,
1000,
13,
396,
401,
267,
298,
5734,
582,
378,
12,
267,
298,
1205,
582,
298,
10401,
401,
267,
298,
4647,
63,
344,
582,
298,
8512,
401,
267,
298,
5334
] |
[
1898,
6900,
26202,
22304,
14,
199,
3,
1898,
9708,
15059,
6,
52,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
199,
646,
1683,
199,
199,
504,
24076,
14,
773,
14,
5950,
14,
3357,
492,
1300,
63,
3357,
63,
1258,
199,
504,
24076,
14,
773,
14,
5950,
14,
3357,
492,
8037,
63,
1258,
199,
504,
24076,
14,
2219,
14,
773,
492,
4026,
63,
1178,
63,
3780,
199,
504,
24076,
14,
2219,
14,
773,
14,
5950,
492,
1300,
421,
199,
533,
1379,
23637,
3041,
8,
1095,
14,
1563,
3167,
774,
304,
339,
25699,
63,
6613,
51,
275,
791,
5871,
356,
8910,
267,
298,
344,
582,
298,
26666,
4675,
2905,
70,
13,
2466,
696,
13,
30494,
69,
13,
29702,
69,
13,
29990,
69,
21,
65,
24,
2866,
1167,
401,
267,
298,
4614,
582,
359,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
736,
14,
331,
15,
86,
18,
15,
26666,
4675,
2905,
70,
13,
2466,
696,
13,
30494,
69,
13,
29702,
69,
13,
29990,
69,
21,
65,
24,
2866,
1167,
401,
355,
298,
3369,
582,
298,
277,
2,
288,
1660,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
736,
14,
331,
15,
26666,
4675,
2905,
70,
13,
2466,
696,
13,
30494,
69,
13,
29702,
69,
13,
29990,
69,
21,
65,
24,
2866,
1167,
401,
355,
298,
3369,
582,
298,
17341,
2,
288,
789,
267,
2156,
267,
298,
354,
582,
399,
2,
1222,
60,
85,
4321,
13,
1000,
13,
396,
3570,
61,
272,
789,
339,
25699,
63,
6613,
63,
1914,
1254,
2826,
840,
21174,
275,
469,
267,
298,
3541,
16,
63,
521,
582,
413,
2898,
3607,
12,
267,
298,
4844,
582,
959,
1194,
10740,
12,
267,
298,
86,
983,
63,
2550,
582,
446,
17,
12,
267,
298,
86,
983,
63,
739,
582,
499,
2789,
9862,
12,
267,
298,
86,
983,
63,
739,
63,
2103,
582,
20240,
12,
267,
298,
86,
983,
63,
952,
582,
959,
1138,
1349,
708,
12,
267,
298,
86,
983,
63,
952,
63,
2103,
582,
841,
1299,
12,
267,
298,
86,
846,
17,
63,
6872,
582,
31533,
614,
1355,
12,
267,
298,
86,
846,
17,
63,
6872,
63,
4824,
582,
378,
12,
267,
298,
86,
846,
17,
63,
6872,
63,
2550,
582,
378,
12,
267,
298,
86,
846,
17,
63,
6872,
63,
18853,
582,
499,
1822,
614,
12,
267,
298,
86,
846,
17,
63,
2347,
582,
4329,
996,
2036,
12,
267,
298,
86,
846,
17,
63,
2347,
63,
4824,
582,
378,
12,
267,
298,
86,
846,
17,
63,
2347,
63,
2550,
582,
378,
12,
267,
298,
86,
846,
17,
63,
2347,
63,
18853,
582,
1227,
2789,
272,
789,
339,
25699,
63,
6613,
63,
2970,
275,
791,
1000,
356,
469,
267,
298,
2732,
12179,
20,
582,
4873,
267,
298,
2732,
12179,
22,
582,
4873,
267,
298,
7423,
582,
469,
288,
298,
4239,
582,
359,
355,
469,
490,
298,
2697,
582,
298,
5756,
14,
6568,
14,
16,
14,
19,
401,
490,
298,
1023,
582,
841,
355,
789,
288,
1622,
267,
1660,
267,
298,
3966,
582,
298,
7409,
13,
2036,
13,
1165,
52,
2025,
26,
845,
26,
1643,
58,
401,
267,
298,
6081,
582,
469,
288,
298,
344,
582,
298,
17,
401,
288,
298,
4614,
582,
359,
355,
469,
490,
298,
6399,
582,
298,
1014,
921,
736,
14,
957,
15,
8512,
15,
18664,
15,
17,
401,
490,
298,
3369,
582,
298,
17341,
2,
355,
789,
288,
1622,
267,
1660,
267,
298,
1102,
1304,
582,
298,
2182,
1797,
67,
1079,
65,
1398,
18263,
69,
1690,
68,
16,
18770,
69,
1367,
713,
1780,
68,
13830,
66,
14761,
69,
17,
68,
8982,
66,
667,
16,
2158,
667,
25,
67,
2322,
68,
401,
267,
298,
344,
582,
298,
14590,
67,
1138,
3328,
13,
70,
17,
1587,
13,
20,
67,
19,
68,
13,
24,
15504,
13,
19,
696,
3624,
2534,
1367,
67,
2789,
401,
267,
298,
1569,
582,
469,
288,
298,
344,
582,
298,
2760,
65,
30859,
69,
16,
13,
2192,
69,
23,
13,
1887,
66,
23,
13,
66,
13085,
13,
15430,
70,
24284,
69,
16414,
66,
401,
288,
298,
4614,
582,
359,
355,
469,
490,
298,
6399,
582,
298,
1014,
921,
1017,
458,
15,
2760,
65,
30859,
69,
16,
13,
2192,
69,
23,
13,
1887,
66,
23,
13,
66,
13085,
13,
15430,
70,
24284,
69,
16414,
66,
401,
490,
298,
3369,
582,
298,
17341,
2,
355,
789,
288,
1622,
267,
1660,
267,
298,
4614,
582,
359,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
86,
18,
15,
5474,
3122,
15,
14590,
67,
1138,
3328,
13,
70,
17,
1587,
13,
20,
67,
19,
68,
13,
24,
15504,
13,
19,
696,
3624,
2534,
1367,
67,
2789,
401,
355,
298,
3369,
582,
298,
277,
2,
288,
1660,
288,
469,
355,
298,
6399,
582,
298,
1014,
921,
5474,
3122,
15,
14590,
67,
1138,
3328,
13,
70,
17,
1587,
13,
20,
67,
19,
68,
13,
24,
15504,
13,
19,
696,
3624,
2534,
1367,
67,
2789,
401,
355,
298,
3369,
582,
298,
17341,
2,
288,
789,
267,
2156,
267,
298,
2343,
582,
469,
288,
399,
2,
5713,
7146,
653,
60,
85,
4321,
278,
582,
399,
2,
33,
387,
60,
85,
4321,
595,
17,
2,
267,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Azure/azure-sdk-for-python
|
sdk/network/azure-mgmt-network/azure/mgmt/network/v2019_07_01/operations/_virtual_network_taps_operations.py
|
1
|
29661
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from typing import TYPE_CHECKING
import warnings
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
from azure.core.paging import ItemPaged
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.polling import LROPoller, NoPolling, PollingMethod
from azure.mgmt.core.exceptions import ARMErrorFormat
from azure.mgmt.core.polling.arm_polling import ARMPolling
from .. import models as _models
if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar, Union
T = TypeVar('T')
ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]]
class VirtualNetworkTapsOperations(object):
"""VirtualNetworkTapsOperations operations.
You should not instantiate this class directly. Instead, you should create a Client instance that
instantiates it for you and attaches it as an attribute.
:ivar models: Alias to model classes used in this operation group.
:type models: ~azure.mgmt.network.v2019_07_01.models
:param client: Client for service requests.
:param config: Configuration of service client.
:param serializer: An object model serializer.
:param deserializer: An object model deserializer.
"""
models = _models
def __init__(self, client, config, serializer, deserializer):
self._client = client
self._serialize = serializer
self._deserialize = deserializer
self._config = config
def _delete_initial(
self,
resource_group_name, # type: str
tap_name, # type: str
**kwargs # type: Any
):
# type: (...) -> None
cls = kwargs.pop('cls', None) # type: ClsType[None]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-07-01"
# Construct URL
url = self._delete_initial.metadata['url'] # type: ignore
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
# Construct headers
header_parameters = {} # type: Dict[str, Any]
request = self._client.delete(url, query_parameters, header_parameters)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 202, 204]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
if cls:
return cls(pipeline_response, None, {})
_delete_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def begin_delete(
self,
resource_group_name, # type: str
tap_name, # type: str
**kwargs # type: Any
):
# type: (...) -> LROPoller[None]
"""Deletes the specified virtual network tap.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:param tap_name: The name of the virtual network tap.
:type tap_name: str
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: Pass in True if you'd like the ARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of LROPoller that returns either None or the result of cls(response)
:rtype: ~azure.core.polling.LROPoller[None]
:raises ~azure.core.exceptions.HttpResponseError:
"""
polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod]
cls = kwargs.pop('cls', None) # type: ClsType[None]
lro_delay = kwargs.pop(
'polling_interval',
self._config.polling_interval
)
cont_token = kwargs.pop('continuation_token', None) # type: Optional[str]
if cont_token is None:
raw_result = self._delete_initial(
resource_group_name=resource_group_name,
tap_name=tap_name,
cls=lambda x,y,z: x,
**kwargs
)
kwargs.pop('error_map', None)
kwargs.pop('content_type', None)
def get_long_running_output(pipeline_response):
if cls:
return cls(pipeline_response, None, {})
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments, **kwargs)
elif polling is False: polling_method = NoPolling()
else: polling_method = polling
if cont_token:
return LROPoller.from_continuation_token(
polling_method=polling_method,
continuation_token=cont_token,
client=self._client,
deserialization_callback=get_long_running_output
)
else:
return LROPoller(self._client, raw_result, get_long_running_output, polling_method)
begin_delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def get(
self,
resource_group_name, # type: str
tap_name, # type: str
**kwargs # type: Any
):
# type: (...) -> "_models.VirtualNetworkTap"
"""Gets information about the specified virtual network tap.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:param tap_name: The name of virtual network tap.
:type tap_name: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: VirtualNetworkTap, or the result of cls(response)
:rtype: ~azure.mgmt.network.v2019_07_01.models.VirtualNetworkTap
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTap"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-07-01"
accept = "application/json"
# Construct URL
url = self.get.metadata['url'] # type: ignore
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
request = self._client.get(url, query_parameters, header_parameters)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
deserialized = self._deserialize('VirtualNetworkTap', pipeline_response)
if cls:
return cls(pipeline_response, deserialized, {})
return deserialized
get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def _create_or_update_initial(
self,
resource_group_name, # type: str
tap_name, # type: str
parameters, # type: "_models.VirtualNetworkTap"
**kwargs # type: Any
):
# type: (...) -> "_models.VirtualNetworkTap"
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTap"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-07-01"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"
# Construct URL
url = self._create_or_update_initial.metadata['url'] # type: ignore
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
body_content_kwargs = {} # type: Dict[str, Any]
body_content = self._serialize.body(parameters, 'VirtualNetworkTap')
body_content_kwargs['content'] = body_content
request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200, 201]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
if response.status_code == 200:
deserialized = self._deserialize('VirtualNetworkTap', pipeline_response)
if response.status_code == 201:
deserialized = self._deserialize('VirtualNetworkTap', pipeline_response)
if cls:
return cls(pipeline_response, deserialized, {})
return deserialized
_create_or_update_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def begin_create_or_update(
self,
resource_group_name, # type: str
tap_name, # type: str
parameters, # type: "_models.VirtualNetworkTap"
**kwargs # type: Any
):
# type: (...) -> LROPoller["_models.VirtualNetworkTap"]
"""Creates or updates a Virtual Network Tap.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:param tap_name: The name of the virtual network tap.
:type tap_name: str
:param parameters: Parameters supplied to the create or update virtual network tap operation.
:type parameters: ~azure.mgmt.network.v2019_07_01.models.VirtualNetworkTap
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: Pass in True if you'd like the ARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of LROPoller that returns either VirtualNetworkTap or the result of cls(response)
:rtype: ~azure.core.polling.LROPoller[~azure.mgmt.network.v2019_07_01.models.VirtualNetworkTap]
:raises ~azure.core.exceptions.HttpResponseError:
"""
polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod]
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTap"]
lro_delay = kwargs.pop(
'polling_interval',
self._config.polling_interval
)
cont_token = kwargs.pop('continuation_token', None) # type: Optional[str]
if cont_token is None:
raw_result = self._create_or_update_initial(
resource_group_name=resource_group_name,
tap_name=tap_name,
parameters=parameters,
cls=lambda x,y,z: x,
**kwargs
)
kwargs.pop('error_map', None)
kwargs.pop('content_type', None)
def get_long_running_output(pipeline_response):
deserialized = self._deserialize('VirtualNetworkTap', pipeline_response)
if cls:
return cls(pipeline_response, deserialized, {})
return deserialized
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, path_format_arguments=path_format_arguments, **kwargs)
elif polling is False: polling_method = NoPolling()
else: polling_method = polling
if cont_token:
return LROPoller.from_continuation_token(
polling_method=polling_method,
continuation_token=cont_token,
client=self._client,
deserialization_callback=get_long_running_output
)
else:
return LROPoller(self._client, raw_result, get_long_running_output, polling_method)
begin_create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def _update_tags_initial(
self,
resource_group_name, # type: str
tap_name, # type: str
tap_parameters, # type: "_models.TagsObject"
**kwargs # type: Any
):
# type: (...) -> "_models.VirtualNetworkTap"
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTap"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-07-01"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"
# Construct URL
url = self._update_tags_initial.metadata['url'] # type: ignore
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
body_content_kwargs = {} # type: Dict[str, Any]
body_content = self._serialize.body(tap_parameters, 'TagsObject')
body_content_kwargs['content'] = body_content
request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
deserialized = self._deserialize('VirtualNetworkTap', pipeline_response)
if cls:
return cls(pipeline_response, deserialized, {})
return deserialized
_update_tags_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def begin_update_tags(
self,
resource_group_name, # type: str
tap_name, # type: str
tap_parameters, # type: "_models.TagsObject"
**kwargs # type: Any
):
# type: (...) -> LROPoller["_models.VirtualNetworkTap"]
"""Updates an VirtualNetworkTap tags.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:param tap_name: The name of the tap.
:type tap_name: str
:param tap_parameters: Parameters supplied to update VirtualNetworkTap tags.
:type tap_parameters: ~azure.mgmt.network.v2019_07_01.models.TagsObject
:keyword callable cls: A custom type or function that will be passed the direct response
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: Pass in True if you'd like the ARMPolling polling method,
False for no polling, or your own initialized polling object for a personal polling strategy.
:paramtype polling: bool or ~azure.core.polling.PollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
:return: An instance of LROPoller that returns either VirtualNetworkTap or the result of cls(response)
:rtype: ~azure.core.polling.LROPoller[~azure.mgmt.network.v2019_07_01.models.VirtualNetworkTap]
:raises ~azure.core.exceptions.HttpResponseError:
"""
polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod]
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTap"]
lro_delay = kwargs.pop(
'polling_interval',
self._config.polling_interval
)
cont_token = kwargs.pop('continuation_token', None) # type: Optional[str]
if cont_token is None:
raw_result = self._update_tags_initial(
resource_group_name=resource_group_name,
tap_name=tap_name,
tap_parameters=tap_parameters,
cls=lambda x,y,z: x,
**kwargs
)
kwargs.pop('error_map', None)
kwargs.pop('content_type', None)
def get_long_running_output(pipeline_response):
deserialized = self._deserialize('VirtualNetworkTap', pipeline_response)
if cls:
return cls(pipeline_response, deserialized, {})
return deserialized
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'tapName': self._serialize.url("tap_name", tap_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
if polling is True: polling_method = ARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs)
elif polling is False: polling_method = NoPolling()
else: polling_method = polling
if cont_token:
return LROPoller.from_continuation_token(
polling_method=polling_method,
continuation_token=cont_token,
client=self._client,
deserialization_callback=get_long_running_output
)
else:
return LROPoller(self._client, raw_result, get_long_running_output, polling_method)
begin_update_tags.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps/{tapName}'} # type: ignore
def list_all(
self,
**kwargs # type: Any
):
# type: (...) -> Iterable["_models.VirtualNetworkTapListResult"]
"""Gets all the VirtualNetworkTaps in a subscription.
:keyword callable cls: A custom type or function that will be passed the direct response
:return: An iterator like instance of either VirtualNetworkTapListResult or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.network.v2019_07_01.models.VirtualNetworkTapListResult]
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTapListResult"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-07-01"
accept = "application/json"
def prepare_request(next_link=None):
# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
if not next_link:
# Construct URL
url = self.list_all.metadata['url'] # type: ignore
path_format_arguments = {
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
request = self._client.get(url, query_parameters, header_parameters)
else:
url = next_link
query_parameters = {} # type: Dict[str, Any]
request = self._client.get(url, query_parameters, header_parameters)
return request
def extract_data(pipeline_response):
deserialized = self._deserialize('VirtualNetworkTapListResult', pipeline_response)
list_of_elem = deserialized.value
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link or None, iter(list_of_elem)
def get_next(next_link=None):
request = prepare_request(next_link)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
return pipeline_response
return ItemPaged(
get_next, extract_data
)
list_all.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Network/virtualNetworkTaps'} # type: ignore
def list_by_resource_group(
self,
resource_group_name, # type: str
**kwargs # type: Any
):
# type: (...) -> Iterable["_models.VirtualNetworkTapListResult"]
"""Gets all the VirtualNetworkTaps in a subscription.
:param resource_group_name: The name of the resource group.
:type resource_group_name: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: An iterator like instance of either VirtualNetworkTapListResult or the result of cls(response)
:rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.network.v2019_07_01.models.VirtualNetworkTapListResult]
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualNetworkTapListResult"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2019-07-01"
accept = "application/json"
def prepare_request(next_link=None):
# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')
if not next_link:
# Construct URL
url = self.list_by_resource_group.metadata['url'] # type: ignore
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)
# Construct parameters
query_parameters = {} # type: Dict[str, Any]
query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str')
request = self._client.get(url, query_parameters, header_parameters)
else:
url = next_link
query_parameters = {} # type: Dict[str, Any]
request = self._client.get(url, query_parameters, header_parameters)
return request
def extract_data(pipeline_response):
deserialized = self._deserialize('VirtualNetworkTapListResult', pipeline_response)
list_of_elem = deserialized.value
if cls:
list_of_elem = cls(list_of_elem)
return deserialized.next_link or None, iter(list_of_elem)
def get_next(next_link=None):
request = prepare_request(next_link)
pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response
if response.status_code not in [200]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
raise HttpResponseError(response=response, error_format=ARMErrorFormat)
return pipeline_response
return ItemPaged(
get_next, extract_data
)
list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworkTaps'} # type: ignore
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
4190,
2556,
14,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
31904,
14,
199,
3,
24775,
199,
504,
14090,
492,
11511,
63,
8936,
1206,
199,
646,
3598,
199,
199,
504,
13601,
14,
1018,
14,
3924,
492,
6810,
27942,
12,
6183,
547,
12,
7337,
23839,
12,
28783,
12,
2341,
63,
705,
199,
504,
13601,
14,
1018,
14,
31691,
492,
7020,
16769,
199,
504,
13601,
14,
1018,
14,
7379,
492,
19090,
2364,
199,
504,
13601,
14,
1018,
14,
7379,
14,
5545,
492,
20730,
12,
6183,
199,
504,
13601,
14,
1018,
14,
17154,
492,
491,
26898,
12,
3091,
28588,
12,
8467,
2983,
3767,
199,
504,
13601,
14,
9752,
14,
1018,
14,
3924,
492,
27155,
547,
3484,
199,
504,
13601,
14,
9752,
14,
1018,
14,
17154,
14,
5362,
63,
17154,
492,
4160,
1658,
393,
2983,
199,
199,
504,
2508,
492,
1709,
465,
485,
992,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
327,
4287,
26,
3507,
29,
8618,
13,
646,
12,
10335,
11330,
13,
12775,
272,
687,
14090,
492,
6184,
12,
16975,
12,
7448,
12,
8307,
12,
19937,
12,
4879,
12,
2434,
5894,
12,
15961,
339,
377,
275,
2434,
5894,
360,
52,
358,
272,
28793,
804,
275,
4879,
59,
16410,
9046,
17562,
2364,
59,
10441,
12,
6183,
467,
377,
12,
7448,
59,
495,
12,
6184,
2365,
6184,
2677,
199,
199,
533,
13311,
4491,
52,
7461,
12929,
8,
785,
304,
272,
408,
8735,
4491,
52,
7461,
12929,
5331,
14,
339,
2047,
1077,
440,
17321,
642,
1021,
5370,
14,
15345,
12,
1265,
1077,
1218,
282,
6810,
1256,
626,
272,
9034,
2335,
652,
367,
1265,
436,
6554,
397,
652,
465,
376,
2225,
14,
339,
520,
7725,
1709,
26,
24777,
370,
1402,
3992,
1202,
315,
642,
3439,
1572,
14,
272,
520,
466,
1709,
26,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
14982,
63,
1780,
63,
614,
14,
992,
272,
520,
635,
1890,
26,
6810,
367,
2435,
4145,
14,
272,
520,
635,
1101,
26,
11595,
402,
2435,
1890,
14,
272,
520,
635,
9146,
26,
1626,
909,
1402,
9146,
14,
272,
520,
635,
30237,
26,
1626,
909,
1402,
30237,
14,
272,
408,
339,
1709,
275,
485,
992,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
1101,
12,
9146,
12,
30237,
304,
267,
291,
423,
1258,
275,
1890,
267,
291,
423,
3549,
275,
9146,
267,
291,
423,
11143,
275,
30237,
267,
291,
423,
888,
275,
1101,
339,
347,
485,
1807,
63,
2747,
8,
267,
291,
12,
267,
2073,
63,
923,
63,
354,
12,
221,
327,
730,
26,
620,
267,
24410,
63,
354,
12,
221,
327,
730,
26,
620,
267,
1011,
958,
221,
327,
730,
26,
6184,
272,
3461,
267,
327,
730,
26,
30934,
1035,
488,
267,
843,
275,
2074,
14,
1935,
360,
1886,
297,
488,
9,
221,
327,
730,
26,
28793,
804,
59,
403,
61,
267,
1125,
63,
1130,
275,
469,
288,
13952,
26,
6810,
27942,
12,
7901,
26,
28783,
12,
21292,
26,
7337,
23839,
267,
789,
267,
1125,
63,
1130,
14,
873,
8,
958,
14,
1935,
360,
705,
63,
1130,
297,
17003,
267,
2986,
63,
1023,
275,
298,
14982,
13,
1780,
13,
614,
2,
398,
327,
9215,
2851,
267,
1166,
275,
291,
423,
1807,
63,
2747,
14,
2343,
459,
633,
418,
221,
327,
730,
26,
3686,
267,
931,
63,
908,
63,
4958,
275,
469,
288,
283,
22023,
356,
291,
423,
3549,
14,
633,
480,
1927,
63,
923,
63,
354,
401,
2073,
63,
923,
63,
354,
12,
283,
495,
659,
288,
283,
16609,
985,
356,
291,
423,
3549,
14,
633,
480,
16609,
63,
354,
401,
24410,
63,
354,
12,
283,
495,
659,
288,
283,
20505,
356,
291,
423,
3549,
14,
633,
480,
277,
423,
888,
14,
6645,
63,
344,
401,
291,
423,
888,
14,
6645,
63,
344,
12,
283,
495,
659,
267,
789,
267,
1166,
275,
291,
423,
1258,
14,
908,
63,
633,
8,
633,
12,
1011,
515,
63,
908,
63,
4958,
9,
398,
327,
9215,
2633,
267,
1827,
63,
3214,
275,
1052,
221,
327,
730,
26,
7448,
59,
495,
12,
6184,
61,
267,
1827,
63,
3214,
459,
1246,
13,
1023,
418,
275,
291,
423,
3549,
14,
1131,
480,
1246,
63,
1023,
401,
2986,
63,
1023,
12,
283,
495,
358,
398,
327,
9215,
2323,
267,
1406,
63,
3214,
275,
1052,
221,
327,
730,
26,
7448,
59,
495,
12,
6184,
61,
398,
1056,
275,
291,
423,
1258,
14,
1807,
8,
633,
12,
1827,
63,
3214,
12,
1406,
63,
3214,
9,
267,
7679,
63,
1310,
275,
291,
423,
1258,
423,
7379,
14,
1065,
8,
1069,
12,
2547,
29,
797,
12,
1011,
958,
9,
267,
1177,
275,
7679,
63,
1310,
14,
1014,
63,
1310,
398,
340,
1177,
14,
1205,
63,
600,
440,
315,
359,
1840,
12,
19328,
12,
14785,
2189,
288,
2341,
63,
705,
8,
1205,
63,
600,
29,
1310,
14,
1205,
63,
600,
12,
1177,
29,
1310,
12,
1125,
63,
1130,
29,
705,
63,
1130,
9,
288,
746,
6183,
547,
8,
1310,
29,
1310,
12,
1125,
63,
908,
29,
12482,
547,
3484,
9,
398,
340,
843,
26,
288,
372,
843,
8,
7379,
63,
1310,
12,
488,
12,
5009,
339,
485,
1807,
63,
2747,
14,
2343,
275,
791,
633,
356,
1994,
13233,
5321,
20505,
5995,
26952,
5321,
22023,
5995,
9710,
15,
12940,
14,
4491,
15,
2065,
4491,
52,
7461,
5321,
16609,
985,
93,
936,
221,
327,
730,
26,
3686,
339,
347,
5386,
63,
1807,
8,
267,
291,
12,
267,
2073,
63,
923,
63,
354,
12,
221,
327,
730,
26,
620,
267,
24410,
63,
354,
12,
221,
327,
730,
26,
620,
267,
1011,
958,
221,
327,
730,
26,
6184,
272,
3461,
267,
327,
730,
26,
30934,
1035,
491,
26898,
59,
403,
61,
267,
408,
26372,
314,
2013,
5791,
2784,
24410,
14,
398,
520,
635,
2073,
63,
923,
63,
354,
26,
710,
536,
402,
314,
2073,
1572,
14,
267,
520,
466,
2073,
63,
923,
63,
354,
26,
620,
267,
520,
635,
24410,
63,
354,
26,
710,
536
] |
[
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
4190,
2556,
14,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
31904,
14,
199,
3,
24775,
199,
504,
14090,
492,
11511,
63,
8936,
1206,
199,
646,
3598,
199,
199,
504,
13601,
14,
1018,
14,
3924,
492,
6810,
27942,
12,
6183,
547,
12,
7337,
23839,
12,
28783,
12,
2341,
63,
705,
199,
504,
13601,
14,
1018,
14,
31691,
492,
7020,
16769,
199,
504,
13601,
14,
1018,
14,
7379,
492,
19090,
2364,
199,
504,
13601,
14,
1018,
14,
7379,
14,
5545,
492,
20730,
12,
6183,
199,
504,
13601,
14,
1018,
14,
17154,
492,
491,
26898,
12,
3091,
28588,
12,
8467,
2983,
3767,
199,
504,
13601,
14,
9752,
14,
1018,
14,
3924,
492,
27155,
547,
3484,
199,
504,
13601,
14,
9752,
14,
1018,
14,
17154,
14,
5362,
63,
17154,
492,
4160,
1658,
393,
2983,
199,
199,
504,
2508,
492,
1709,
465,
485,
992,
199,
199,
692,
11511,
63,
8936,
1206,
26,
272,
327,
4287,
26,
3507,
29,
8618,
13,
646,
12,
10335,
11330,
13,
12775,
272,
687,
14090,
492,
6184,
12,
16975,
12,
7448,
12,
8307,
12,
19937,
12,
4879,
12,
2434,
5894,
12,
15961,
339,
377,
275,
2434,
5894,
360,
52,
358,
272,
28793,
804,
275,
4879,
59,
16410,
9046,
17562,
2364,
59,
10441,
12,
6183,
467,
377,
12,
7448,
59,
495,
12,
6184,
2365,
6184,
2677,
199,
199,
533,
13311,
4491,
52,
7461,
12929,
8,
785,
304,
272,
408,
8735,
4491,
52,
7461,
12929,
5331,
14,
339,
2047,
1077,
440,
17321,
642,
1021,
5370,
14,
15345,
12,
1265,
1077,
1218,
282,
6810,
1256,
626,
272,
9034,
2335,
652,
367,
1265,
436,
6554,
397,
652,
465,
376,
2225,
14,
339,
520,
7725,
1709,
26,
24777,
370,
1402,
3992,
1202,
315,
642,
3439,
1572,
14,
272,
520,
466,
1709,
26,
6146,
9078,
14,
9752,
14,
1200,
14,
86,
14982,
63,
1780,
63,
614,
14,
992,
272,
520,
635,
1890,
26,
6810,
367,
2435,
4145,
14,
272,
520,
635,
1101,
26,
11595,
402,
2435,
1890,
14,
272,
520,
635,
9146,
26,
1626,
909,
1402,
9146,
14,
272,
520,
635,
30237,
26,
1626,
909,
1402,
30237,
14,
272,
408,
339,
1709,
275,
485,
992,
339,
347,
636,
826,
721,
277,
12,
1890,
12,
1101,
12,
9146,
12,
30237,
304,
267,
291,
423,
1258,
275,
1890,
267,
291,
423,
3549,
275,
9146,
267,
291,
423,
11143,
275,
30237,
267,
291,
423,
888,
275,
1101,
339,
347,
485,
1807,
63,
2747,
8,
267,
291,
12,
267,
2073,
63,
923,
63,
354,
12,
221,
327,
730,
26,
620,
267,
24410,
63,
354,
12,
221,
327,
730,
26,
620,
267,
1011,
958,
221,
327,
730,
26,
6184,
272,
3461,
267,
327,
730,
26,
30934,
1035,
488,
267,
843,
275,
2074,
14,
1935,
360,
1886,
297,
488,
9,
221,
327,
730,
26,
28793,
804,
59,
403,
61,
267,
1125,
63,
1130,
275,
469,
288,
13952,
26,
6810,
27942,
12,
7901,
26,
28783,
12,
21292,
26,
7337,
23839,
267,
789,
267,
1125,
63,
1130,
14,
873,
8,
958,
14,
1935,
360,
705,
63,
1130,
297,
17003,
267,
2986,
63,
1023,
275,
298,
14982,
13,
1780,
13,
614,
2,
398,
327,
9215,
2851,
267,
1166,
275,
291,
423,
1807,
63,
2747,
14,
2343,
459,
633,
418,
221,
327,
730,
26,
3686,
267,
931,
63,
908,
63,
4958,
275,
469,
288,
283,
22023,
356,
291,
423,
3549,
14,
633,
480,
1927,
63,
923,
63,
354,
401,
2073,
63,
923,
63,
354,
12,
283,
495,
659,
288,
283,
16609,
985,
356,
291,
423,
3549,
14,
633,
480,
16609,
63,
354,
401,
24410,
63,
354,
12,
283,
495,
659,
288,
283,
20505,
356,
291,
423,
3549,
14,
633,
480,
277,
423,
888,
14,
6645,
63,
344,
401,
291,
423,
888,
14,
6645,
63,
344,
12,
283,
495,
659,
267,
789,
267,
1166,
275,
291,
423,
1258,
14,
908,
63,
633,
8,
633,
12,
1011,
515,
63,
908,
63,
4958,
9,
398,
327,
9215,
2633,
267,
1827,
63,
3214,
275,
1052,
221,
327,
730,
26,
7448,
59,
495,
12,
6184,
61,
267,
1827,
63,
3214,
459,
1246,
13,
1023,
418,
275,
291,
423,
3549,
14,
1131,
480,
1246,
63,
1023,
401,
2986,
63,
1023,
12,
283,
495,
358,
398,
327,
9215,
2323,
267,
1406,
63,
3214,
275,
1052,
221,
327,
730,
26,
7448,
59,
495,
12,
6184,
61,
398,
1056,
275,
291,
423,
1258,
14,
1807,
8,
633,
12,
1827,
63,
3214,
12,
1406,
63,
3214,
9,
267,
7679,
63,
1310,
275,
291,
423,
1258,
423,
7379,
14,
1065,
8,
1069,
12,
2547,
29,
797,
12,
1011,
958,
9,
267,
1177,
275,
7679,
63,
1310,
14,
1014,
63,
1310,
398,
340,
1177,
14,
1205,
63,
600,
440,
315,
359,
1840,
12,
19328,
12,
14785,
2189,
288,
2341,
63,
705,
8,
1205,
63,
600,
29,
1310,
14,
1205,
63,
600,
12,
1177,
29,
1310,
12,
1125,
63,
1130,
29,
705,
63,
1130,
9,
288,
746,
6183,
547,
8,
1310,
29,
1310,
12,
1125,
63,
908,
29,
12482,
547,
3484,
9,
398,
340,
843,
26,
288,
372,
843,
8,
7379,
63,
1310,
12,
488,
12,
5009,
339,
485,
1807,
63,
2747,
14,
2343,
275,
791,
633,
356,
1994,
13233,
5321,
20505,
5995,
26952,
5321,
22023,
5995,
9710,
15,
12940,
14,
4491,
15,
2065,
4491,
52,
7461,
5321,
16609,
985,
93,
936,
221,
327,
730,
26,
3686,
339,
347,
5386,
63,
1807,
8,
267,
291,
12,
267,
2073,
63,
923,
63,
354,
12,
221,
327,
730,
26,
620,
267,
24410,
63,
354,
12,
221,
327,
730,
26,
620,
267,
1011,
958,
221,
327,
730,
26,
6184,
272,
3461,
267,
327,
730,
26,
30934,
1035,
491,
26898,
59,
403,
61,
267,
408,
26372,
314,
2013,
5791,
2784,
24410,
14,
398,
520,
635,
2073,
63,
923,
63,
354,
26,
710,
536,
402,
314,
2073,
1572,
14,
267,
520,
466,
2073,
63,
923,
63,
354,
26,
620,
267,
520,
635,
24410,
63,
354,
26,
710,
536,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wonder-sk/inasafe
|
safe/storage/utilities.py
|
2
|
37736
|
# coding=utf-8
"""**Utilities for storage module**
"""
import os
import re
import copy
import numpy
import math
from ast import literal_eval
from osgeo import ogr
from collections import OrderedDict
from geometry import Polygon
from safe.gis.numerics import ensure_numeric
from safe.common.utilities import verify
from safe.common.exceptions import (
BoundingBoxError, InaSAFEError, ReadMetadataError)
from safe.utilities.i18n import tr
from safe.utilities.unicode import get_string, get_unicode
from safe.storage.metadata_utilities import (
write_keyword_in_iso_metadata, read_iso_metadata)
# Default attribute to assign to vector layers
DEFAULT_ATTRIBUTE = 'inapolygon'
# Spatial layer file extensions that are recognised in Risiko
# FIXME: Perhaps add '.gml', '.zip', ...
LAYER_TYPES = ['.shp', '.asc', '.tif', '.tiff', '.geotif', '.geotiff']
# Map between extensions and ORG drivers
DRIVER_MAP = {'.sqlite': 'SQLITE',
'.shp': 'ESRI Shapefile',
'.gml': 'GML',
'.tif': 'GTiff',
'.asc': 'AAIGrid'}
# Map between Python types and OGR field types
# FIXME (Ole): I can't find a double precision type for OGR
TYPE_MAP = {type(None): ogr.OFTString, # What else should this be?
type(''): ogr.OFTString,
type(True): ogr.OFTInteger,
type(0): ogr.OFTInteger,
type(0.0): ogr.OFTReal,
type(numpy.array([0.0])[0]): ogr.OFTReal, # numpy.float64
type(numpy.array([[0.0]])[0]): ogr.OFTReal} # numpy.ndarray
# Map between verbose types and OGR geometry types
INVERSE_GEOMETRY_TYPE_MAP = {'point': ogr.wkbPoint,
'line': ogr.wkbLineString,
'polygon': ogr.wkbPolygon}
# Miscellaneous auxiliary functions
def _keywords_to_string(keywords, sublayer=None):
"""Create a string from a keywords dict.
Args:
* keywords: A required dictionary containing the keywords to stringify.
* sublayer: str optional group marker for a sub layer.
Returns:
str: a String containing the rendered keywords list
Raises:
Any exceptions are propogated.
.. note: Only simple keyword dicts should be passed here, not multilayer
dicts.
For example you pass a dict like this::
{'datatype': 'osm',
'category': 'exposure',
'title': 'buildings_osm_4326',
'subcategory': 'building',
'purpose': 'dki'}
and the following string would be returned:
datatype: osm
category: exposure
title: buildings_osm_4326
subcategory: building
purpose: dki
If sublayer is provided e.g. _keywords_to_string(keywords, sublayer='foo'),
the following:
[foo]
datatype: osm
category: exposure
title: buildings_osm_4326
subcategory: building
purpose: dki
"""
# Write
result = get_unicode('')
if sublayer is not None:
result = '[%s]\n' % sublayer
for k, value in keywords.items():
# Create key
msg = ('Key in keywords dictionary must be a string. '
'I got %s with type %s' % (k, str(type(k))[1:-1]))
verify(isinstance(k, basestring), msg)
key = k
msg = ('Key in keywords dictionary must not contain the ":" '
'character. I got "%s"' % key)
verify(':' not in key, msg)
# Store
result += '%s: %s\n' % (key, value)
return result
def write_keywords(keywords, filename, sublayer=None):
"""Write keywords dictonary to file
:param keywords: Dictionary of keyword, value pairs
:type keywords: dict
:param filename: Name of keywords file. Extension expected to be .keywords
:type filename: str
:param sublayer: Optional sublayer applicable only to multilayer formats
such as sqlite or netcdf which can potentially hold more than
one layer. The string should map to the layer group as per the
example below. **If the keywords file contains sublayer
definitions but no sublayer was defined, keywords file content
will be removed and replaced with only the keywords provided
here.**
:type sublayer: str
A keyword file with sublayers may look like this:
[osm_buildings]
datatype: osm
category: exposure
subcategory: building
purpose: dki
title: buildings_osm_4326
[osm_flood]
datatype: flood
category: hazard
subcategory: building
title: flood_osm_4326
Keys must be strings not containing the ":" character
Values can be anything that can be converted to a string (using
Python's str function)
Surrounding whitespace is removed from values, but keys are unmodified
The reason being that keys must always be valid for the dictionary they
came from. For values we have decided to be flexible and treat entries like
'unit:m' the same as 'unit: m', or indeed 'unit: m '.
Otherwise, unintentional whitespace in values would lead to surprising
errors in the application.
"""
# Input checks
basename, ext = os.path.splitext(filename)
msg = ('Unknown extension for file %s. Expected %s.keywords' % (
filename, basename))
verify(ext == '.keywords', msg)
# First read any keywords out of the file so that we can retain
# keywords for other sublayers
existing_keywords = read_keywords(filename, all_blocks=True)
first_value = None
if len(existing_keywords) > 0:
first_value = existing_keywords[existing_keywords.keys()[0]]
multilayer_flag = isinstance(first_value, dict)
handle = file(filename, 'w')
if multilayer_flag:
if sublayer is not None and sublayer != '':
# replace existing keywords / add new for this layer
existing_keywords[sublayer] = keywords
for key, value in existing_keywords.iteritems():
handle.write(_keywords_to_string(value, sublayer=key))
handle.write('\n')
else:
# It is currently a multilayer but we will replace it with
# a single keyword block since the user passed no sublayer
handle.write(_keywords_to_string(keywords))
else:
# currently a simple layer so replace it with our content
keywords = get_string(_keywords_to_string(keywords, sublayer=sublayer))
handle.write(keywords)
handle.close()
write_keyword_in_iso_metadata(filename)
def read_keywords(keyword_filename, sublayer=None, all_blocks=False):
"""Read keywords dictionary from file
:param keyword_filename: Name of keywords file. Extension expected to be
.keywords or .xml metadata.
The format of one line is expected to be either
string: string or string
:type keyword_filename: str
:param sublayer: Optional sublayer applicable only to multilayer formats
such as sqlite or netcdf which can potentially hold more than
one layer. The string should map to the layer group as per the
example below. If the keywords file contains sublayer definitions
but no sublayer was defined, the first layer group will be
returned.
:type sublayer: str
:param all_blocks: Optional, defaults to False. If True will return
a dict of dicts, where the top level dict entries each represent
a sublayer, and the values of that dict will be dicts of keyword
entries.
:type all_blocks: bool
:returns: keywords: Dictionary of keyword, value pairs
A keyword layer with sublayers may look like this:
[osm_buildings]
datatype: osm
category: exposure
subcategory: building
purpose: dki
title: buildings_osm_4326
[osm_flood]
datatype: flood
category: hazard
subcategory: building
title: flood_osm_4326
Whereas a simple keywords file would look like this
datatype: flood
category: hazard
subcategory: building
title: flood_osm_4326
If filename does not exist, an empty dictionary is returned
Blank lines are ignored
Surrounding whitespace is removed from values, but keys are unmodified
If there are no ':', then the keyword is treated as a key with no value
"""
# Input checks
basename, ext = os.path.splitext(keyword_filename)
msg = ('Unknown extension for file %s. '
'Expected %s.keywords or %s.xml' %
(keyword_filename, basename, basename))
verify(ext == '.keywords' or ext == '.xml', msg)
metadata = False
# check .keywords file exist
keywords_file = os.path.isfile(keyword_filename) \
and ext == '.keywords'
try:
# read the xml metadata first
metadata = read_iso_metadata(keyword_filename)
except (IOError, ReadMetadataError):
# error reading xml metadata or file not exist
if keywords_file:
# if there is a keyword file generate an xml file also
write_keyword_in_iso_metadata(keyword_filename)
metadata = read_iso_metadata(keyword_filename)
# we have no valid xml metadata nor a keyword file
if not metadata and not keywords_file:
return {}
if metadata:
lines = metadata['keywords']
else:
# Read all entries
with open(keyword_filename, 'r') as fid:
lines = fid.readlines()
blocks = {}
keywords = {}
current_block = None
first_keywords = None
for line in lines:
# Remove trailing (but not preceeding!) whitespace
# FIXME: Can be removed altogether
text = line.rstrip()
# Ignore blank lines
if text == '':
continue
# Check if it is an ini style group header
block_flag = re.search(r'^\[.*]$', text, re.M | re.I)
if block_flag:
# Write the old block if it exists - must have a current
# block to prevent orphans
if len(keywords) > 0 and current_block is not None:
blocks[current_block] = keywords
if first_keywords is None and len(keywords) > 0:
first_keywords = keywords
# Now set up for a new block
current_block = text[1:-1]
# Reset the keywords each time we encounter a new block
# until we know we are on the desired one
keywords = {}
continue
if ':' not in text:
key = text.strip()
val = None
else:
# Get splitting point
idx = text.find(':')
# Take key as everything up to the first ':'
key = text[:idx]
# Take value as everything after the first ':'
textval = text[idx + 1:].strip()
try:
# Take care of python structures like
# booleans, None, lists, dicts etc
val = literal_eval(textval)
except (ValueError, SyntaxError):
if 'OrderedDict(' == textval[:12]:
try:
val = OrderedDict(
literal_eval(textval[12:-1]))
except (ValueError, SyntaxError, TypeError):
val = textval
else:
val = textval
# Add entry to dictionary
keywords[key] = val
# Write our any unfinalised block data
if len(keywords) > 0 and current_block is not None:
blocks[current_block] = keywords
if first_keywords is None:
first_keywords = keywords
# Ok we have generated a structure that looks like this:
# blocks = {{ 'foo' : { 'a': 'b', 'c': 'd'},
# { 'bar' : { 'd': 'e', 'f': 'g'}}
# where foo and bar are sublayers and their dicts are the sublayer keywords
if all_blocks:
return blocks
if sublayer is not None:
if sublayer in blocks:
return blocks[sublayer]
else:
return first_keywords
# noinspection PyExceptionInherit
def check_geotransform(geotransform):
"""Check that geotransform is valid
:param geotransform: GDAL geotransform (6-tuple).
(top left x, w-e pixel resolution, rotation,
top left y, rotation, n-s pixel resolution).
See e.g. http://www.gdal.org/gdal_tutorial.html
:type geotransform: tuple
.. note::
This assumes that the spatial reference uses geographic coordinates,
so will not work for projected coordinate systems.
"""
msg = ('Supplied geotransform must be a tuple with '
'6 numbers. I got %s' % str(geotransform))
verify(len(geotransform) == 6, msg)
for x in geotransform:
try:
float(x)
except TypeError:
raise InaSAFEError(msg)
# Check longitude
msg = ('Element in 0 (first) geotransform must be a valid '
'longitude. I got %s' % geotransform[0])
verify(-180 <= geotransform[0] <= 180, msg)
# Check latitude
msg = ('Element 3 (fourth) in geotransform must be a valid '
'latitude. I got %s' % geotransform[3])
verify(-90 <= geotransform[3] <= 90, msg)
# Check cell size
msg = ('Element 1 (second) in geotransform must be a positive '
'number. I got %s' % geotransform[1])
verify(geotransform[1] > 0, msg)
msg = ('Element 5 (sixth) in geotransform must be a negative '
'number. I got %s' % geotransform[1])
verify(geotransform[5] < 0, msg)
def geotransform_to_bbox(geotransform, columns, rows):
"""Convert geotransform to bounding box
:param geotransform: GDAL geotransform (6-tuple).
(top left x, w-e pixel resolution, rotation,
top left y, rotation, n-s pixel resolution).
See e.g. http://www.gdal.org/gdal_tutorial.html
:type geotransform: tuple
:param columns: Number of columns in grid
:type columns: int
:param rows: Number of rows in grid
:type rows: int
:returns: bbox: Bounding box as a list of geographic coordinates
[west, south, east, north]
.. note::
Rows and columns are needed to determine eastern and northern bounds.
FIXME: Not sure if the pixel vs gridline registration issue is observed
correctly here. Need to check against gdal > v1.7
"""
x_origin = geotransform[0] # top left x
y_origin = geotransform[3] # top left y
x_res = geotransform[1] # w-e pixel resolution
y_res = geotransform[5] # n-s pixel resolution
x_pix = columns
y_pix = rows
min_x = x_origin
max_x = x_origin + (x_pix * x_res)
min_y = y_origin + (y_pix * y_res)
max_y = y_origin
return [min_x, min_y, max_x, max_y]
def geotransform_to_resolution(geotransform, isotropic=False):
"""Convert geotransform to resolution
:param geotransform: GDAL geotransform (6-tuple).
(top left x, w-e pixel resolution, rotation,
top left y, rotation, n-s pixel resolution).
See e.g. http://www.gdal.org/gdal_tutorial.html
:type geotransform: tuple
:param isotropic: If True, return the average (dx + dy) / 2
:type isotropic: bool
:returns: resolution: grid spacing (res_x, res_y) in (positive) decimal
degrees ordered as longitude first, then latitude.
or (res_x + res_y) / 2 (if isotropic is True)
"""
res_x = geotransform[1] # w-e pixel resolution
res_y = -geotransform[5] # n-s pixel resolution (always negative)
if isotropic:
return (res_x + res_y) / 2
else:
return res_x, res_y
def raster_geometry_to_geotransform(longitudes, latitudes):
"""Convert vectors of longitudes and latitudes to geotransform
Note:
This is the inverse operation of Raster.get_geometry().
:param longitudes: Vectors of geographic coordinates
:type longitudes:
:param latitudes: Vectors of geographic coordinates
:type latitudes:
:returns: geotransform: 6-tuple (top left x, w-e pixel resolution,
rotation, top left y, rotation, n-s pixel resolution)
"""
nx = len(longitudes)
ny = len(latitudes)
msg = ('You must specify more than 1 longitude to make geotransform: '
'I got %s' % str(longitudes))
verify(nx > 1, msg)
msg = ('You must specify more than 1 latitude to make geotransform: '
'I got %s' % str(latitudes))
verify(ny > 1, msg)
dx = float(longitudes[1] - longitudes[0]) # Longitudinal resolution
dy = float(latitudes[0] - latitudes[1]) # Latitudinal resolution (neg)
# Define pixel centers along each directions
# This is to achieve pixel registration rather
# than gridline registration
dx2 = dx / 2
dy2 = dy / 2
geotransform = (longitudes[0] - dx2, # Longitude of upper left corner
dx, # w-e pixel resolution
0, # rotation
latitudes[-1] - dy2, # Latitude of upper left corner
0, # rotation
dy) # n-s pixel resolution
return geotransform
# noinspection PyExceptionInherit
def bbox_intersection(*args):
"""Compute intersection between two or more bounding boxes.
:param args: two or more bounding boxes.
Each is assumed to be a list or a tuple with
four coordinates (W, S, E, N)
:returns: The minimal common bounding box
"""
msg = 'Function bbox_intersection must take at least 2 arguments.'
verify(len(args) > 1, msg)
result = [-180, -90, 180, 90]
for a in args:
if a is None:
continue
msg = ('Bounding box expected to be a list of the '
'form [W, S, E, N]. '
'Instead i got "%s"' % str(a))
try:
box = list(a)
except:
raise Exception(msg)
if not len(box) == 4:
raise BoundingBoxError(msg)
msg = ('Western boundary must be less than or equal to eastern. '
'I got %s' % box)
if not box[0] <= box[2]:
raise BoundingBoxError(msg)
msg = ('Southern boundary must be less than or equal to northern. '
'I got %s' % box)
if not box[1] <= box[3]:
raise BoundingBoxError(msg)
# Compute intersection
# West and South
for i in [0, 1]:
result[i] = max(result[i], box[i])
# East and North
for i in [2, 3]:
result[i] = min(result[i], box[i])
# Check validity and return
if result[0] <= result[2] and result[1] <= result[3]:
return result
else:
return None
def minimal_bounding_box(bbox, min_res, eps=1.0e-6):
"""Grow bounding box to exceed specified resolution if needed
:param bbox: Bounding box with format [W, S, E, N]
:type bbox: list
:param min_res: Minimal acceptable resolution to exceed
:type min_res: float
:param eps: Optional tolerance that will be applied to 'buffer' result
:type eps: float
:returns: Adjusted bounding box guaranteed to exceed specified resolution
"""
# FIXME (Ole): Probably obsolete now
bbox = copy.copy(list(bbox))
delta_x = bbox[2] - bbox[0]
delta_y = bbox[3] - bbox[1]
if delta_x < min_res:
dx = (min_res - delta_x) / 2 + eps
bbox[0] -= dx
bbox[2] += dx
if delta_y < min_res:
dy = (min_res - delta_y) / 2 + eps
bbox[1] -= dy
bbox[3] += dy
return bbox
def buffered_bounding_box(bbox, resolution):
"""Grow bounding box with one unit of resolution in each direction
Note:
This will ensure there are enough pixels to robustly provide
interpolated values without having to painstakingly deal with
all corner cases such as 1 x 1, 1 x 2 and 2 x 1 arrays.
The border will also make sure that points that would otherwise fall
outside the domain (as defined by a tight bounding box) get assigned
values.
:param bbox: Bounding box with format [W, S, E, N]
:type bbox: list
:param resolution: (resx, resy) - Raster resolution in each direction.
res - Raster resolution in either direction
If resolution is None bbox is returned unchanged.
:type resolution: tuple
:returns: Adjusted bounding box
Note:
Case in point: Interpolation point O would fall outside this domain
even though there are enough grid points to support it
::
--------------
| |
| * * | * *
| O|
| |
| * * | * *
--------------
"""
bbox = copy.copy(list(bbox))
if resolution is None:
return bbox
try:
resx, resy = resolution
except TypeError:
resx = resy = resolution
bbox[0] -= resx
bbox[1] -= resy
bbox[2] += resx
bbox[3] += resy
return bbox
def get_geometry_type(geometry, geometry_type):
"""Determine geometry type based on data
:param geometry: A list of either point coordinates [lon, lat] or polygons
which are assumed to be numpy arrays of coordinates
:type geometry: list
:param geometry_type: Optional type - 'point', 'line', 'polygon' or None
:type geometry_type: str, None
:returns: geometry_type: Either ogr.wkbPoint, ogr.wkbLineString or
ogr.wkbPolygon
Note:
If geometry type cannot be determined an Exception is raised.
There is no consistency check across all entries of the
geometry list, only the first element is used in this determination.
"""
# FIXME (Ole): Perhaps use OGR's own symbols
msg = ('Argument geometry_type must be either "point", "line", '
'"polygon" or None')
verify(geometry_type is None or
geometry_type in [1, 2, 3] or
geometry_type.lower() in ['point', 'line', 'polygon'], msg)
if geometry_type is not None:
if isinstance(geometry_type, basestring):
return INVERSE_GEOMETRY_TYPE_MAP[geometry_type.lower()]
else:
return geometry_type
# FIXME (Ole): Should add some additional checks to see if choice
# makes sense
msg = 'Argument geometry must be a sequence. I got %s ' % type(geometry)
verify(is_sequence(geometry), msg)
if len(geometry) == 0:
# Default to point if there is no data
return ogr.wkbPoint
msg = ('The first element in geometry must be a sequence of length > 2. '
'I got %s ' % str(geometry[0]))
verify(is_sequence(geometry[0]), msg)
verify(len(geometry[0]) >= 2, msg)
if len(geometry[0]) == 2:
try:
float(geometry[0][0])
float(geometry[0][1])
except (ValueError, TypeError, IndexError):
pass
else:
# This geometry appears to be point data
geometry_type = ogr.wkbPoint
elif len(geometry[0]) > 2:
try:
x = numpy.array(geometry[0])
except ValueError:
pass
else:
# This geometry appears to be polygon data
if x.shape[0] > 2 and x.shape[1] == 2:
geometry_type = ogr.wkbPolygon
if geometry_type is None:
msg = 'Could not determine geometry type'
raise Exception(msg)
return geometry_type
def is_sequence(x):
"""Determine if x behaves like a true sequence but not a string
:param x: Sequence like object
:type x: object
:returns: Test result
:rtype: bool
Note:
This will for example return True for lists, tuples and numpy arrays
but False for strings and dictionaries.
"""
if isinstance(x, basestring):
return False
try:
list(x)
except TypeError:
return False
else:
return True
def array_to_line(A, geometry_type=ogr.wkbLinearRing):
"""Convert coordinates to linear_ring
:param A: Nx2 Array of coordinates representing either a polygon or a line.
A can be either a numpy array or a list of coordinates.
:type A: numpy.ndarray, list
:param geometry_type: A valid OGR geometry type.
Default type ogr.wkbLinearRing
:type geometry_type: ogr.wkbLinearRing, include ogr.wkbLineString
Returns:
* ring: OGR line geometry
Note:
Based on http://www.packtpub.com/article/working-geospatial-data-python
"""
try:
A = ensure_numeric(A, numpy.float)
except Exception, e:
msg = ('Array (%s) could not be converted to numeric array. '
'I got type %s. Error message: %s'
% (A, str(type(A)), e))
raise Exception(msg)
msg = 'Array must be a 2d array of vertices. I got %s' % (str(A.shape))
verify(len(A.shape) == 2, msg)
msg = 'A array must have two columns. I got %s' % (str(A.shape[0]))
verify(A.shape[1] == 2, msg)
N = A.shape[0] # Number of vertices
line = ogr.Geometry(geometry_type)
for i in range(N):
line.AddPoint(A[i, 0], A[i, 1])
return line
def rings_equal(x, y, rtol=1.0e-6, atol=1.0e-8):
"""Compares to linear rings as numpy arrays
:param x: A 2d array of the first ring
:type x: numpy.ndarray
:param y: A 2d array of the second ring
:type y: numpy.ndarray
:param rtol: The relative tolerance parameter
:type rtol: float
:param atol: The relative tolerance parameter
:type rtol: float
Returns:
* True if x == y or x' == y (up to the specified tolerance)
where x' is x reversed in the first dimension. This corresponds to
linear rings being seen as equal irrespective of whether they are
organised in clock wise or counter clock wise order
"""
x = ensure_numeric(x, numpy.float)
y = ensure_numeric(y, numpy.float)
msg = 'Arrays must a 2d arrays of vertices. I got %s and %s' % (x, y)
verify(len(x.shape) == 2 and len(y.shape) == 2, msg)
msg = 'Arrays must have two columns. I got %s and %s' % (x, y)
verify(x.shape[1] == 2 and y.shape[1] == 2, msg)
if (numpy.allclose(x, y, rtol=rtol, atol=atol) or
numpy.allclose(x, y[::-1], rtol=rtol, atol=atol)):
return True
else:
return False
# FIXME (Ole): We can retire this messy function now
# Positive: Delete it :-)
def array_to_wkt(A, geom_type='POLYGON'):
"""Convert coordinates to wkt format
:param A: Nx2 Array of coordinates representing either a polygon or a line.
A can be either a numpy array or a list of coordinates.
:type A: numpy.array
:param geom_type: Determines output keyword 'POLYGON' or 'LINESTRING'
:type geom_type: str
:returns: wkt: geometry in the format known to ogr: Examples
Note:
POLYGON((1020 1030,1020 1045,1050 1045,1050 1030,1020 1030))
LINESTRING(1000 1000, 1100 1050)
"""
try:
A = ensure_numeric(A, numpy.float)
except Exception, e:
msg = ('Array (%s) could not be converted to numeric array. '
'I got type %s. Error message: %s'
% (geom_type, str(type(A)), e))
raise Exception(msg)
msg = 'Array must be a 2d array of vertices. I got %s' % (str(A.shape))
verify(len(A.shape) == 2, msg)
msg = 'A array must have two columns. I got %s' % (str(A.shape[0]))
verify(A.shape[1] == 2, msg)
if geom_type == 'LINESTRING':
# One bracket
n = 1
elif geom_type == 'POLYGON':
# Two brackets (tsk tsk)
n = 2
else:
msg = 'Unknown geom_type: %s' % geom_type
raise Exception(msg)
wkt_string = geom_type + '(' * n
N = len(A)
for i in range(N):
# Works for both lists and arrays
wkt_string += '%f %f, ' % tuple(A[i])
return wkt_string[:-2] + ')' * n
# Map of ogr numerical geometry types to their textual representation
# FIXME (Ole): Some of them don't exist, even though they show up
# when doing dir(ogr) - Why?:
geometry_type_map = {ogr.wkbPoint: 'Point',
ogr.wkbPoint25D: 'Point25D',
ogr.wkbPolygon: 'Polygon',
ogr.wkbPolygon25D: 'Polygon25D',
# ogr.wkbLinePoint: 'LinePoint', # ??
ogr.wkbGeometryCollection: 'GeometryCollection',
ogr.wkbGeometryCollection25D: 'GeometryCollection25D',
ogr.wkbLineString: 'LineString',
ogr.wkbLineString25D: 'LineString25D',
ogr.wkbLinearRing: 'LinearRing',
ogr.wkbMultiLineString: 'MultiLineString',
ogr.wkbMultiLineString25D: 'MultiLineString25D',
ogr.wkbMultiPoint: 'MultiPoint',
ogr.wkbMultiPoint25D: 'MultiPoint25D',
ogr.wkbMultiPolygon: 'MultiPolygon',
ogr.wkbMultiPolygon25D: 'MultiPolygon25D',
ogr.wkbNDR: 'NDR',
ogr.wkbNone: 'None',
ogr.wkbUnknown: 'Unknown'}
def geometry_type_to_string(g_type):
"""Provides string representation of numeric geometry types
:param g_type: geometry type:
:type g_type: ogr.wkb*, None
FIXME (Ole): I can't find anything like this in ORG. Why?
"""
if g_type in geometry_type_map:
return geometry_type_map[g_type]
elif g_type is None:
return 'No geometry type assigned'
else:
return 'Unknown geometry type: %s' % str(g_type)
# FIXME: Move to common numerics area along with polygon.py
def calculate_polygon_area(polygon, signed=False):
"""Calculate the signed area of non-self-intersecting polygon
:param polygon: Numeric array of points (longitude, latitude). It is
assumed to be closed, i.e. first and last points are identical
:type polygon: numpy.ndarray
:param signed: Optional flag deciding whether returned area retains its
sign:
If points are ordered counter clockwise, the signed area
will be positive.
If points are ordered clockwise, it will be negative
Default is False which means that the area is always
positive.
:type signed: bool
:returns: area: Area of polygon (subject to the value of argument signed)
:rtype: numpy.ndarray
Note:
Sources
http://paulbourke.net/geometry/polyarea/
http://en.wikipedia.org/wiki/Centroid
"""
# Make sure it is numeric
P = numpy.array(polygon)
msg = ('Polygon is assumed to consist of coordinate pairs. '
'I got second dimension %i instead of 2' % P.shape[1])
verify(P.shape[1] == 2, msg)
x = P[:, 0]
y = P[:, 1]
# Calculate 0.5 sum_{i=0}^{N-1} (x_i y_{i+1} - x_{i+1} y_i)
a = x[:-1] * y[1:]
b = y[:-1] * x[1:]
A = numpy.sum(a - b) / 2.
if signed:
return A
else:
return abs(A)
def calculate_polygon_centroid(polygon):
"""Calculate the centroid of non-self-intersecting polygon
:param polygon: Numeric array of points (longitude, latitude). It is
assumed to be closed, i.e. first and last points are identical
:type polygon: numpy.ndarray
:returns: calculated centroid
:rtype: numpy.ndarray
.. note::
Sources
http://paulbourke.net/geometry/polyarea/
http://en.wikipedia.org/wiki/Centroid
"""
# Make sure it is numeric
P = numpy.array(polygon)
# Normalise to ensure numerical accurracy.
# This requirement in backed by tests in test_io.py and without it
# centroids at building footprint level may get shifted outside the
# polygon!
P_origin = numpy.amin(P, axis=0)
P = P - P_origin
# Get area. This calculation could be incorporated to save time
# if necessary as the two formulas are very similar.
A = calculate_polygon_area(polygon, signed=True)
x = P[:, 0]
y = P[:, 1]
# Calculate
# Cx = sum_{i=0}^{N-1} (x_i + x_{i+1})(x_i y_{i+1} - x_{i+1} y_i)/(6A)
# Cy = sum_{i=0}^{N-1} (y_i + y_{i+1})(x_i y_{i+1} - x_{i+1} y_i)/(6A)
a = x[:-1] * y[1:]
b = y[:-1] * x[1:]
cx = x[:-1] + x[1:]
cy = y[:-1] + y[1:]
Cx = numpy.sum(cx * (a - b)) / (6. * A)
Cy = numpy.sum(cy * (a - b)) / (6. * A)
# Translate back to real location
C = numpy.array([Cx, Cy]) + P_origin
return C
def points_between_points(point1, point2, delta):
"""Creates an array of points between two points given a delta
:param point1: The first point
:type point1: numpy.ndarray
:param point2: The second point
:type point2: numpy.ndarray
:param delta: The increment between inserted points
:type delta: float
:returns: Array of points.
:rtype: numpy.ndarray
Note:
u = (x1-x0, y1-y0)/L, where
L=sqrt( (x1-x0)^2 + (y1-y0)^2).
If r is the resolution, then the
points will be given by
(x0, y0) + u * n * r for n = 1, 2, ....
while len(n*u*r) < L
"""
x0, y0 = point1
x1, y1 = point2
L = math.sqrt(math.pow((x1 - x0), 2) + math.pow((y1 - y0), 2))
pieces = int(L / delta)
uu = numpy.array([x1 - x0, y1 - y0]) / L
points = [point1]
for nn in range(pieces):
point = point1 + uu * (nn + 1) * delta
points.append(point)
return numpy.array(points)
def points_along_line(line, delta):
"""Calculate a list of points along a line with a given delta
:param line: Numeric array of points (longitude, latitude).
:type line: numpy.ndarray
:param delta: Decimal number to be used as step
:type delta: float
:returns: Numeric array of points (longitude, latitude).
:rtype: numpy.ndarray
Note:
Sources
http://paulbourke.net/geometry/polyarea/
http://en.wikipedia.org/wiki/Centroid
"""
# Make sure it is numeric
P = numpy.array(line)
points = []
for i in range(len(P) - 1):
pts = points_between_points(P[i], P[i + 1], delta)
# If the first point of this list is the same
# as the last one recorded, do not use it
if len(points) > 0:
if numpy.allclose(points[-1], pts[0]):
pts = pts[1:]
points.extend(pts)
C = numpy.array(points)
return C
def combine_polygon_and_point_layers(layers):
"""Combine polygon and point layers
:param layers: List of vector layers of type polygon or point
:type layers: list
:returns: One point layer with all input point layers and centroids from
all input polygon layers.
:rtype: numpy.ndarray
:raises: InaSAFEError (in case attribute names are not the same.)
"""
# This is to implement issue #276
print layers
def get_ring_data(ring):
"""Extract coordinates from OGR ring object
:param ring: OGR ring object
:type ring:
:returns: Nx2 numpy array of vertex coordinates (lon, lat)
:rtype: numpy.array
"""
N = ring.GetPointCount()
# noinspection PyTypeChecker
A = numpy.zeros((N, 2), dtype='d')
# FIXME (Ole): Is there any way to get the entire data vectors?
for j in range(N):
A[j, :] = ring.GetX(j), ring.GetY(j)
# Return ring as an Nx2 numpy array
return A
def get_polygon_data(G):
"""Extract polygon data from OGR geometry
:param G: OGR polygon geometry
:return: List of InaSAFE polygon instances
"""
# Get outer ring, then inner rings
# http://osgeo-org.1560.n6.nabble.com/
# gdal-dev-Polygon-topology-td3745761.html
number_of_rings = G.GetGeometryCount()
# Get outer ring
outer_ring = get_ring_data(G.GetGeometryRef(0))
# Get inner rings if any
inner_rings = []
if number_of_rings > 1:
for i in range(1, number_of_rings):
inner_ring = get_ring_data(G.GetGeometryRef(i))
inner_rings.append(inner_ring)
# Return Polygon instance
return Polygon(outer_ring=outer_ring,
inner_rings=inner_rings)
def safe_to_qgis_layer(layer):
"""Helper function to make a QgsMapLayer from a safe read_layer layer.
:param layer: Layer object as provided by InaSAFE engine.
:type layer: read_layer
:returns: A validated QGIS layer or None. Returns None when QGIS is not
available.
:rtype: QgsMapLayer, QgsVectorLayer, QgsRasterLayer, None
:raises: Exception if layer is not valid.
"""
try:
from qgis.core import QgsVectorLayer, QgsRasterLayer
except ImportError:
return None
# noinspection PyUnresolvedReferences
message = tr(
'Input layer must be a InaSAFE spatial object. I got %s'
) % (str(type(layer)))
if not hasattr(layer, 'is_inasafe_spatial_object'):
raise Exception(message)
if not layer.is_inasafe_spatial_object:
raise Exception(message)
# Get associated filename and symbolic name
filename = layer.get_filename()
name = layer.get_name()
qgis_layer = None
# Read layer
if layer.is_vector:
qgis_layer = QgsVectorLayer(filename, name, 'ogr')
elif layer.is_raster:
qgis_layer = QgsRasterLayer(filename, name)
# Verify that new qgis layer is valid
if qgis_layer.isValid():
return qgis_layer
else:
# noinspection PyUnresolvedReferences
message = tr('Loaded impact layer "%s" is not valid') % filename
raise Exception(message)
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
624,
538,
22905,
367,
4887,
859,
538,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
1331,
199,
646,
2680,
199,
646,
3473,
199,
504,
6073,
492,
8785,
63,
2579,
199,
504,
747,
6721,
492,
20713,
199,
504,
5055,
492,
8773,
199,
199,
504,
3400,
492,
17560,
199,
504,
5048,
14,
5668,
14,
10563,
11818,
492,
4868,
63,
6677,
199,
504,
5048,
14,
2330,
14,
16355,
492,
4911,
199,
504,
5048,
14,
2330,
14,
3924,
492,
334,
272,
21972,
316,
3532,
547,
12,
1010,
65,
27657,
547,
12,
5574,
5142,
547,
9,
199,
504,
5048,
14,
16355,
14,
73,
1085,
78,
492,
5651,
199,
504,
5048,
14,
16355,
14,
2975,
492,
664,
63,
875,
12,
664,
63,
2975,
199,
504,
5048,
14,
3494,
14,
2343,
63,
16355,
492,
334,
272,
2218,
63,
6691,
63,
262,
63,
4595,
63,
2343,
12,
1586,
63,
4595,
63,
2343,
9,
199,
199,
3,
3758,
2225,
370,
5090,
370,
5477,
9393,
199,
3472,
63,
17075,
275,
283,
262,
439,
393,
6585,
7,
199,
199,
3,
13423,
4045,
570,
5478,
626,
787,
17319,
9096,
315,
820,
29022,
7697,
199,
3,
7600,
26,
3492,
17396,
1050,
1987,
18594,
297,
1987,
3065,
297,
2263,
199,
24167,
63,
7893,
275,
18953,
17299,
297,
1987,
10125,
297,
1987,
9142,
297,
1987,
29119,
297,
1987,
6721,
9142,
297,
1987,
6721,
29119,
418,
199,
199,
3,
9672,
3382,
5478,
436,
1549,
39,
19016,
199,
23401,
63,
5443,
275,
791,
14,
10659,
356,
283,
4657,
4427,
297,
1598,
1987,
17299,
356,
283,
654,
6129,
16528,
493,
297,
1598,
1987,
18594,
356,
283,
39,
1698,
297,
1598,
1987,
9142,
356,
283,
8391,
15126,
297,
1598,
1987,
10125,
356,
283,
2276,
1277,
1677,
936,
199,
199,
3,
9672,
3382,
2018,
2943,
436,
10904,
901,
2943,
199,
3,
7600,
334,
47,
274,
304,
473,
883,
1133,
2342,
282,
4270,
7151,
730,
367,
10904,
199,
2711,
63,
5443,
275,
469,
466,
8,
403,
304,
20713,
14,
47,
2161,
1558,
12,
221,
327,
14791,
587,
1077,
642,
506,
31,
288,
730,
360,
735,
20713,
14,
47,
2161,
1558,
12,
288,
730,
8,
549,
304,
20713,
14,
47,
2161,
2674,
12,
288,
730,
8,
16,
304,
20713,
14,
47,
2161,
2674,
12,
288,
730,
8,
16,
14,
16,
304,
20713,
14,
47,
2161,
10099,
12,
288,
730,
8,
4714,
14,
1144,
779,
16,
14,
16,
11057,
16,
4682,
20713,
14,
47,
2161,
10099,
12,
221,
327,
2680,
14,
1609,
772,
288,
730,
8,
4714,
14,
1144,
4038,
16,
14,
16,
3934,
59,
16,
4682,
20713,
14,
47,
2161,
10099,
93,
221,
327,
2680,
14,
8237,
199,
199,
3,
9672,
3382,
3376,
2943,
436,
10904,
3400,
2943,
199,
568,
21233,
63,
28472,
63,
2711,
63,
5443,
275,
791,
1403,
356,
20713,
14,
18914,
3428,
12,
2490,
283,
604,
356,
20713,
14,
18914,
22134,
12,
2490,
283,
16295,
356,
20713,
14,
18914,
12367,
93,
421,
199,
3,
12481,
19549,
31407,
3423,
199,
318,
485,
7511,
63,
475,
63,
875,
8,
7511,
12,
1007,
1897,
29,
403,
304,
272,
408,
2499,
282,
1059,
687,
282,
7681,
1211,
14,
339,
3033,
26,
267,
627,
7681,
26,
437,
1415,
2600,
3035,
314,
7681,
370,
1059,
2021,
14,
267,
627,
1007,
1897,
26,
620,
2716,
1572,
3608,
367,
282,
1007,
4045,
14,
339,
1803,
26,
267,
620,
26,
282,
2624,
3035,
314,
8018,
7681,
769,
339,
6218,
26,
267,
6184,
4967,
787,
557,
555,
71,
972,
14,
339,
2508,
5317,
26,
5972,
3486,
4252,
10809,
1077,
506,
3032,
2348,
12,
440,
3510,
1897,
2126,
10809,
14,
339,
2104,
2893,
1265,
986,
282,
1211,
2839,
642,
447,
398,
791,
14184,
356,
283,
30613,
297,
268,
283,
3710,
356,
283,
28480,
297,
268,
283,
1213,
356,
283,
32589,
63,
30613,
63,
17948,
297,
268,
283,
954,
3710,
356,
283,
17952,
297,
268,
283,
22615,
356,
283,
6341,
73,
936,
339,
436,
314,
2569,
1059,
3955,
506,
2138,
26,
398,
16048,
26,
747,
77,
267,
4637,
26,
30105,
267,
2538,
26,
1900,
780,
63,
30613,
63,
17948,
267,
1007,
3710,
26,
10015,
267,
12016,
26,
366,
8810,
339,
982,
1007,
1897,
365,
2741,
325,
14,
71,
14,
485,
7511,
63,
475,
63,
875,
8,
7511,
12,
1007,
1897,
534,
1421,
659,
272,
314,
2569,
26,
398,
359,
1421,
61,
267,
16048,
26,
747,
77,
267,
4637,
26,
30105,
267,
2538,
26,
1900,
780,
63,
30613,
63,
17948,
267,
1007,
3710,
26,
10015,
267,
12016,
26,
366,
8810,
272,
408,
339,
327,
6990,
272,
754,
275,
664,
63,
2975,
8355,
272,
340,
1007,
1897,
365,
440,
488,
26,
267,
754,
275,
30423,
83,
7272,
78,
7,
450,
1007,
1897,
272,
367,
1022,
12,
574,
315,
7681,
14,
1744,
837,
267,
327,
2790,
790,
267,
1499,
275,
661,
1197,
315,
7681,
2600,
1471,
506,
282,
1059,
14,
283,
2049,
283,
41,
4788,
450,
83,
543,
730,
450,
83,
7,
450,
334,
75,
12,
620,
8,
466,
8,
75,
11515,
17,
6809,
17,
2459,
267,
4911,
8,
6074,
8,
75,
12,
7116,
395,
1499,
9,
398,
790,
275,
1022,
267,
1499,
275,
661,
1197,
315,
7681,
2600,
1471,
440,
1395,
314,
14725,
283,
2049,
283,
10856,
14,
473,
4788,
2071,
83,
4507,
450,
790,
9,
267,
4911,
8,
5242,
440,
315,
790,
12,
1499,
9,
398,
327,
13874,
267,
754,
847,
1543,
83,
26,
450,
83,
60,
78,
7,
450,
334,
498,
12,
574,
9,
272,
372,
754,
421,
199,
318,
2218,
63,
7511,
8,
7511,
12,
1788,
12,
1007,
1897,
29,
403,
304,
272,
408,
3534,
7681,
1211,
265,
695,
370,
570,
339,
520,
635,
7681,
26,
11932,
402,
4252,
12,
574,
6342,
272,
520,
466,
7681,
26,
1211,
339,
520,
635,
1788,
26,
2812,
402,
7681,
570,
14,
13282,
1420,
370,
506,
1275,
7511,
272,
520,
466,
1788,
26,
620,
339,
520,
635,
1007,
1897,
26,
4879,
1007,
1897,
3964,
1454,
370,
3510,
1897,
6752,
267,
4066,
465,
11723,
503,
1851,
10790,
1314,
883,
18994,
10266,
1655,
2419,
267,
1373,
4045,
14,
710,
1059,
1077,
2341,
370,
314,
4045,
1572,
465,
1126,
314,
267,
2893,
5084,
14,
1011,
3917,
314,
7681,
570,
3509,
1007,
1897,
267,
10269,
1325,
949,
1007,
1897,
1990,
3247,
12
] |
[
2803,
29,
1624,
13,
24,
199,
624,
538,
22905,
367,
4887,
859,
538,
199,
624,
199,
199,
646,
747,
199,
646,
295,
199,
646,
1331,
199,
646,
2680,
199,
646,
3473,
199,
504,
6073,
492,
8785,
63,
2579,
199,
504,
747,
6721,
492,
20713,
199,
504,
5055,
492,
8773,
199,
199,
504,
3400,
492,
17560,
199,
504,
5048,
14,
5668,
14,
10563,
11818,
492,
4868,
63,
6677,
199,
504,
5048,
14,
2330,
14,
16355,
492,
4911,
199,
504,
5048,
14,
2330,
14,
3924,
492,
334,
272,
21972,
316,
3532,
547,
12,
1010,
65,
27657,
547,
12,
5574,
5142,
547,
9,
199,
504,
5048,
14,
16355,
14,
73,
1085,
78,
492,
5651,
199,
504,
5048,
14,
16355,
14,
2975,
492,
664,
63,
875,
12,
664,
63,
2975,
199,
504,
5048,
14,
3494,
14,
2343,
63,
16355,
492,
334,
272,
2218,
63,
6691,
63,
262,
63,
4595,
63,
2343,
12,
1586,
63,
4595,
63,
2343,
9,
199,
199,
3,
3758,
2225,
370,
5090,
370,
5477,
9393,
199,
3472,
63,
17075,
275,
283,
262,
439,
393,
6585,
7,
199,
199,
3,
13423,
4045,
570,
5478,
626,
787,
17319,
9096,
315,
820,
29022,
7697,
199,
3,
7600,
26,
3492,
17396,
1050,
1987,
18594,
297,
1987,
3065,
297,
2263,
199,
24167,
63,
7893,
275,
18953,
17299,
297,
1987,
10125,
297,
1987,
9142,
297,
1987,
29119,
297,
1987,
6721,
9142,
297,
1987,
6721,
29119,
418,
199,
199,
3,
9672,
3382,
5478,
436,
1549,
39,
19016,
199,
23401,
63,
5443,
275,
791,
14,
10659,
356,
283,
4657,
4427,
297,
1598,
1987,
17299,
356,
283,
654,
6129,
16528,
493,
297,
1598,
1987,
18594,
356,
283,
39,
1698,
297,
1598,
1987,
9142,
356,
283,
8391,
15126,
297,
1598,
1987,
10125,
356,
283,
2276,
1277,
1677,
936,
199,
199,
3,
9672,
3382,
2018,
2943,
436,
10904,
901,
2943,
199,
3,
7600,
334,
47,
274,
304,
473,
883,
1133,
2342,
282,
4270,
7151,
730,
367,
10904,
199,
2711,
63,
5443,
275,
469,
466,
8,
403,
304,
20713,
14,
47,
2161,
1558,
12,
221,
327,
14791,
587,
1077,
642,
506,
31,
288,
730,
360,
735,
20713,
14,
47,
2161,
1558,
12,
288,
730,
8,
549,
304,
20713,
14,
47,
2161,
2674,
12,
288,
730,
8,
16,
304,
20713,
14,
47,
2161,
2674,
12,
288,
730,
8,
16,
14,
16,
304,
20713,
14,
47,
2161,
10099,
12,
288,
730,
8,
4714,
14,
1144,
779,
16,
14,
16,
11057,
16,
4682,
20713,
14,
47,
2161,
10099,
12,
221,
327,
2680,
14,
1609,
772,
288,
730,
8,
4714,
14,
1144,
4038,
16,
14,
16,
3934,
59,
16,
4682,
20713,
14,
47,
2161,
10099,
93,
221,
327,
2680,
14,
8237,
199,
199,
3,
9672,
3382,
3376,
2943,
436,
10904,
3400,
2943,
199,
568,
21233,
63,
28472,
63,
2711,
63,
5443,
275,
791,
1403,
356,
20713,
14,
18914,
3428,
12,
2490,
283,
604,
356,
20713,
14,
18914,
22134,
12,
2490,
283,
16295,
356,
20713,
14,
18914,
12367,
93,
421,
199,
3,
12481,
19549,
31407,
3423,
199,
318,
485,
7511,
63,
475,
63,
875,
8,
7511,
12,
1007,
1897,
29,
403,
304,
272,
408,
2499,
282,
1059,
687,
282,
7681,
1211,
14,
339,
3033,
26,
267,
627,
7681,
26,
437,
1415,
2600,
3035,
314,
7681,
370,
1059,
2021,
14,
267,
627,
1007,
1897,
26,
620,
2716,
1572,
3608,
367,
282,
1007,
4045,
14,
339,
1803,
26,
267,
620,
26,
282,
2624,
3035,
314,
8018,
7681,
769,
339,
6218,
26,
267,
6184,
4967,
787,
557,
555,
71,
972,
14,
339,
2508,
5317,
26,
5972,
3486,
4252,
10809,
1077,
506,
3032,
2348,
12,
440,
3510,
1897,
2126,
10809,
14,
339,
2104,
2893,
1265,
986,
282,
1211,
2839,
642,
447,
398,
791,
14184,
356,
283,
30613,
297,
268,
283,
3710,
356,
283,
28480,
297,
268,
283,
1213,
356,
283,
32589,
63,
30613,
63,
17948,
297,
268,
283,
954,
3710,
356,
283,
17952,
297,
268,
283,
22615,
356,
283,
6341,
73,
936,
339,
436,
314,
2569,
1059,
3955,
506,
2138,
26,
398,
16048,
26,
747,
77,
267,
4637,
26,
30105,
267,
2538,
26,
1900,
780,
63,
30613,
63,
17948,
267,
1007,
3710,
26,
10015,
267,
12016,
26,
366,
8810,
339,
982,
1007,
1897,
365,
2741,
325,
14,
71,
14,
485,
7511,
63,
475,
63,
875,
8,
7511,
12,
1007,
1897,
534,
1421,
659,
272,
314,
2569,
26,
398,
359,
1421,
61,
267,
16048,
26,
747,
77,
267,
4637,
26,
30105,
267,
2538,
26,
1900,
780,
63,
30613,
63,
17948,
267,
1007,
3710,
26,
10015,
267,
12016,
26,
366,
8810,
272,
408,
339,
327,
6990,
272,
754,
275,
664,
63,
2975,
8355,
272,
340,
1007,
1897,
365,
440,
488,
26,
267,
754,
275,
30423,
83,
7272,
78,
7,
450,
1007,
1897,
272,
367,
1022,
12,
574,
315,
7681,
14,
1744,
837,
267,
327,
2790,
790,
267,
1499,
275,
661,
1197,
315,
7681,
2600,
1471,
506,
282,
1059,
14,
283,
2049,
283,
41,
4788,
450,
83,
543,
730,
450,
83,
7,
450,
334,
75,
12,
620,
8,
466,
8,
75,
11515,
17,
6809,
17,
2459,
267,
4911,
8,
6074,
8,
75,
12,
7116,
395,
1499,
9,
398,
790,
275,
1022,
267,
1499,
275,
661,
1197,
315,
7681,
2600,
1471,
440,
1395,
314,
14725,
283,
2049,
283,
10856,
14,
473,
4788,
2071,
83,
4507,
450,
790,
9,
267,
4911,
8,
5242,
440,
315,
790,
12,
1499,
9,
398,
327,
13874,
267,
754,
847,
1543,
83,
26,
450,
83,
60,
78,
7,
450,
334,
498,
12,
574,
9,
272,
372,
754,
421,
199,
318,
2218,
63,
7511,
8,
7511,
12,
1788,
12,
1007,
1897,
29,
403,
304,
272,
408,
3534,
7681,
1211,
265,
695,
370,
570,
339,
520,
635,
7681,
26,
11932,
402,
4252,
12,
574,
6342,
272,
520,
466,
7681,
26,
1211,
339,
520,
635,
1788,
26,
2812,
402,
7681,
570,
14,
13282,
1420,
370,
506,
1275,
7511,
272,
520,
466,
1788,
26,
620,
339,
520,
635,
1007,
1897,
26,
4879,
1007,
1897,
3964,
1454,
370,
3510,
1897,
6752,
267,
4066,
465,
11723,
503,
1851,
10790,
1314,
883,
18994,
10266,
1655,
2419,
267,
1373,
4045,
14,
710,
1059,
1077,
2341,
370,
314,
4045,
1572,
465,
1126,
314,
267,
2893,
5084,
14,
1011,
3917,
314,
7681,
570,
3509,
1007,
1897,
267,
10269,
1325,
949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
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dapeng0802/djangocms-blog
|
tests/test_views.py
|
8
|
10836
|
# -*- coding: utf-8 -*-
from django.contrib.auth.models import AnonymousUser
from django.http import Http404
from django.utils.timezone import now
from django.utils.translation import activate
from djangocms_blog.feeds import LatestEntriesFeed, TagFeed
from djangocms_blog.sitemaps import BlogSitemap
from djangocms_blog.views import (AuthorEntriesView, CategoryEntriesView, PostArchiveView,
PostDetailView, PostListView, TaggedListView)
from parler.tests.utils import override_parler_settings
from parler.utils.conf import add_default_language_settings
from parler.utils.context import switch_language
from . import BaseTest
class ViewTest(BaseTest):
def test_post_list_view(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
request = self.get_page_request(page1, AnonymousUser(), r'/en/blog/', edit=False)
activate('en')
view_obj = PostListView()
view_obj.request = request
self.assertEqual(list(view_obj.get_queryset()), [post1])
request = self.get_page_request(page1, self.user, r'/en/blog/', edit=False)
activate('en')
view_obj.request = request
view_obj.kwargs = {}
qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 1)
self.assertEqual(set(qs), set([post1]))
request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True)
view_obj.request = request
self.assertEqual(set(view_obj.get_queryset()), set([post1, post2]))
view_obj.kwargs = {}
view_obj.object_list = view_obj.get_queryset()
view_obj.paginate_by = 1
context = view_obj.get_context_data(object_list=view_obj.object_list)
self.assertTrue(context['is_paginated'])
self.assertEqual(list(context['post_list']), [post2])
self.assertEqual(context['paginator'].count, 2)
self.assertEqual(context['post_list'][0].title, 'Second post')
response = view_obj.render_to_response(context)
self.assertContains(response, context['post_list'][0].get_absolute_url())
request = self.get_page_request(page1, self.user, r'/it/blog/', lang_code='it', edit=True)
activate('it')
view_obj.request = request
view_obj.object_list = view_obj.get_queryset()
context = view_obj.get_context_data(object_list=view_obj.object_list)
self.assertEqual(context['post_list'][0].title, 'Secondo post')
response = view_obj.render_to_response(context)
self.assertContains(response, context['post_list'][0].get_absolute_url())
def test_post_list_view_fallback(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
PARLER_FALLBACK = {
1: (
{'code': 'en'},
{'code': 'it'},
{'code': 'fr', 'hide_untranslated': True},
),
'default': {
'fallback': 'en',
'hide_untranslated': False,
}
}
view_obj = PostListView()
request = self.get_page_request(page1, self.user, r'/fr/blog/', lang_code='fr', edit=True)
activate('fr')
view_obj.request = request
view_obj.kwargs = {}
view_obj.object_list = view_obj.get_queryset()
view_obj.get_context_data(object_list=view_obj.object_list)
self.assertEqual(view_obj.get_queryset().count(), 2)
PARLER_FALLBACK = add_default_language_settings(PARLER_FALLBACK)
with override_parler_settings(PARLER_LANGUAGES=PARLER_FALLBACK):
view_obj = PostListView()
request = self.get_page_request(page1, self.user, r'/fr/blog/', lang_code='fr', edit=True)
activate('fr')
view_obj.request = request
view_obj.kwargs = {}
view_obj.object_list = view_obj.get_queryset()
view_obj.get_context_data(object_list=view_obj.object_list)
self.assertEqual(view_obj.get_queryset().count(), 0)
def test_post_detail_view(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
with switch_language(post1, 'en'):
request = self.get_page_request(page1, AnonymousUser(), r'/en/blog/', edit=False)
view_obj = PostDetailView()
view_obj.request = request
with self.assertRaises(Http404):
view_obj.kwargs = {'slug': 'not-existing'}
post_obj = view_obj.get_object()
view_obj.kwargs = {'slug': post1.slug}
post_obj = view_obj.get_object()
self.assertEqual(post_obj, post1)
self.assertEqual(post_obj.language_code, 'en')
with switch_language(post1, 'it'):
request = self.get_page_request(page1, AnonymousUser(), r'/it/blog/', lang_code='it', edit=False)
view_obj.request = request
view_obj.kwargs = {'slug': post1.slug}
post_obj = view_obj.get_object()
self.assertEqual(post_obj, post1)
self.assertEqual(post_obj.language_code, 'it')
view_obj.object = post_obj
context = view_obj.get_context_data()
self.assertEqual(context['post'], post1)
self.assertEqual(context['post'].language_code, 'it')
self.assertTrue(context['meta'])
def test_post_archive_view(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
request = self.get_page_request(page1, AnonymousUser(), r'/en/blog/', edit=False)
activate('en')
view_obj = PostArchiveView()
view_obj.request = request
view_obj.kwargs = {'year': now().year, 'month': now().month}
# One post only, anonymous request
qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 1)
self.assertEqual(list(qs), [post1])
view_obj.object_list = qs
context = view_obj.get_context_data(object_list=view_obj.object_list)
self.assertEqual(context['archive_date'].date(), now().replace(year=now().year, month=now().month, day=1).date())
def test_category_entries_view(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True)
activate('en')
view_obj = CategoryEntriesView()
view_obj.request = request
view_obj.kwargs = {'category': 'category-1'}
qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 2)
self.assertEqual(set(qs), set([post1, post2]))
view_obj.paginate_by = 1
view_obj.object_list = qs
context = view_obj.get_context_data(object_list=view_obj.object_list)
self.assertTrue(context['category'])
self.assertEqual(context['category'], self.category_1)
self.assertTrue(context['is_paginated'])
self.assertEqual(list(context['post_list']), [post2])
self.assertEqual(context['paginator'].count, 2)
self.assertEqual(context['post_list'][0].title, 'Second post')
def test_author_entries_view(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True)
activate('en')
view_obj = AuthorEntriesView()
view_obj.request = request
view_obj.kwargs = {'username': self.user.get_username()}
qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 2)
self.assertEqual(set(qs), set([post1, post2]))
view_obj.paginate_by = 1
view_obj.object_list = qs
context = view_obj.get_context_data(object_list=view_obj.object_list)
self.assertTrue(context['author'])
self.assertEqual(context['author'], self.user)
self.assertTrue(context['is_paginated'])
self.assertEqual(list(context['post_list']), [post2])
self.assertEqual(context['paginator'].count, 2)
self.assertEqual(context['post_list'][0].title, 'Second post')
def test_taggedlist_view(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
post1.save()
post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
post2.save()
request = self.get_page_request(page1, self.user, r'/en/blog/', edit=True)
activate('en')
view_obj = TaggedListView()
view_obj.request = request
view_obj.kwargs = {'tag': 'tag-2'}
qs = view_obj.get_queryset()
self.assertEqual(qs.count(), 2)
self.assertEqual(set(qs), set([post1, post2]))
view_obj.paginate_by = 1
view_obj.object_list = qs
context = view_obj.get_context_data(object_list=view_obj.object_list)
self.assertTrue(context['tagged_entries'], 'tag-2')
self.assertTrue(context['is_paginated'])
self.assertEqual(list(context['post_list']), [post2])
self.assertEqual(context['paginator'].count, 2)
self.assertEqual(context['post_list'][0].title, 'Second post')
def test_feed(self):
page1, page2 = self.get_pages()
post1, post2 = self.get_posts()
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
post1.save()
post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
post2.save()
post1.set_current_language('en')
feed = LatestEntriesFeed()
self.assertEqual(list(feed.items()), [post1])
request = self.get_page_request(page1, self.user, r'/en/blog/', lang_code='en', edit=False)
xml = feed(request)
self.assertContains(xml, post1.get_absolute_url())
self.assertContains(xml, 'Blog articles on example.com')
activate('it')
post1.set_current_language('it')
feed = LatestEntriesFeed()
self.assertEqual(list(feed.items()), [post1])
request = self.get_page_request(page1, self.user, r'/it/blog/', lang_code='it', edit=False)
xml = feed(request)
self.assertContains(xml, post1.get_absolute_url())
self.assertContains(xml, 'Articoli del blog su example.com')
feed = TagFeed()
self.assertEqual(list(feed.items('tag-2')), [post1])
def test_sitemap(self):
post1, post2 = self.get_posts()
post1.tags.add('tag 1', 'tag 2', 'tag 3', 'tag 4')
post1.save()
post2.tags.add('tag 6', 'tag 2', 'tag 5', 'tag 8')
post2.publish = True
post2.save()
post1.set_current_language('en')
sitemap = BlogSitemap()
self.assertEqual(sitemap.items().count(), 2)
for item in sitemap.items():
self.assertTrue(sitemap.lastmod(item).date(), now().today())
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
504,
1639,
14,
1208,
14,
6893,
492,
15422,
199,
504,
366,
851,
679,
706,
63,
11486,
14,
11522,
492,
491,
27126,
17816,
7658,
12,
8053,
7658,
199,
504,
366,
851,
679,
706,
63,
11486,
14,
30515,
492,
29775,
8972,
1130,
199,
504,
366,
851,
679,
706,
63,
11486,
14,
4196,
492,
334,
5949,
17816,
2768,
12,
13573,
17816,
2768,
12,
7711,
13042,
2768,
12,
3303,
7711,
28539,
12,
7711,
23239,
12,
32121,
23239,
9,
199,
504,
623,
1435,
14,
2219,
14,
1208,
492,
4278,
63,
462,
1435,
63,
1751,
199,
504,
623,
1435,
14,
1208,
14,
2190,
492,
1050,
63,
885,
63,
3671,
63,
1751,
199,
504,
623,
1435,
14,
1208,
14,
1100,
492,
6258,
63,
3671,
199,
199,
504,
1275,
492,
3523,
774,
421,
199,
533,
10935,
774,
8,
23170,
304,
339,
347,
511,
63,
1932,
63,
513,
63,
1345,
8,
277,
304,
267,
2034,
17,
12,
2034,
18,
275,
291,
14,
362,
63,
5856,
342,
267,
2963,
17,
12,
2963,
18,
275,
291,
14,
362,
63,
18084,
342,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
29952,
1062,
519,
9807,
287,
15,
11486,
3678,
5283,
29,
797,
9,
267,
15422,
360,
287,
358,
267,
2455,
63,
1113,
275,
7711,
23239,
342,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
398,
291,
14,
629,
8,
513,
8,
1345,
63,
1113,
14,
362,
63,
7924,
4000,
359,
1932,
17,
566,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
287,
15,
11486,
3678,
5283,
29,
797,
9,
267,
15422,
360,
287,
358,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
2455,
63,
1113,
14,
958,
275,
1052,
267,
6377,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
291,
14,
629,
8,
6177,
14,
835,
1062,
413,
9,
267,
291,
14,
629,
8,
409,
8,
6177,
395,
663,
779,
1932,
17,
2459,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
287,
15,
11486,
3678,
5283,
29,
549,
9,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
291,
14,
629,
8,
409,
8,
1345,
63,
1113,
14,
362,
63,
7924,
4000,
663,
779,
1932,
17,
12,
2963,
18,
2459,
398,
2455,
63,
1113,
14,
958,
275,
1052,
267,
2455,
63,
1113,
14,
785,
63,
513,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
2455,
63,
1113,
14,
30979,
63,
991,
275,
413,
267,
1067,
275,
2455,
63,
1113,
14,
362,
63,
1100,
63,
576,
8,
785,
63,
513,
29,
1345,
63,
1113,
14,
785,
63,
513,
9,
267,
291,
14,
1815,
8,
1100,
459,
374,
63,
28030,
1105,
267,
291,
14,
629,
8,
513,
8,
1100,
459,
1932,
63,
513,
3815,
359,
1932,
18,
566,
267,
291,
14,
629,
8,
1100,
459,
22073,
2278,
835,
12,
499,
9,
267,
291,
14,
629,
8,
1100,
459,
1932,
63,
513,
3488,
16,
1055,
1213,
12,
283,
11906,
2963,
358,
267,
1177,
275,
2455,
63,
1113,
14,
3352,
63,
475,
63,
1310,
8,
1100,
9,
267,
291,
14,
9535,
8,
1310,
12,
1067,
459,
1932,
63,
513,
3488,
16,
1055,
362,
63,
6116,
63,
633,
1012,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
390,
15,
11486,
3678,
6339,
63,
600,
534,
390,
297,
5283,
29,
549,
9,
267,
15422,
360,
390,
358,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
2455,
63,
1113,
14,
785,
63,
513,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
1067,
275,
2455,
63,
1113,
14,
362,
63,
1100,
63,
576,
8,
785,
63,
513,
29,
1345,
63,
1113,
14,
785,
63,
513,
9,
267,
291,
14,
629,
8,
1100,
459,
1932,
63,
513,
3488,
16,
1055,
1213,
12,
283,
1513,
388,
1117,
2963,
358,
267,
1177,
275,
2455,
63,
1113,
14,
3352,
63,
475,
63,
1310,
8,
1100,
9,
267,
291,
14,
9535,
8,
1310,
12,
1067,
459,
1932,
63,
513,
3488,
16,
1055,
362,
63,
6116,
63,
633,
1012,
339,
347,
511,
63,
1932,
63,
513,
63,
1345,
63,
10538,
8,
277,
304,
267,
2034,
17,
12,
2034,
18,
275,
291,
14,
362,
63,
5856,
342,
267,
2963,
17,
12,
2963,
18,
275,
291,
14,
362,
63,
18084,
342,
398,
10263,
19650,
63,
38,
1761,
7111,
275,
469,
288,
413,
26,
334,
355,
791,
600,
356,
283,
287,
2267,
355,
791,
600,
356,
283,
390,
2267,
355,
791,
600,
356,
283,
4391,
297,
283,
8191,
63,
324,
18065,
356,
715,
1386,
288,
2318,
288,
283,
885,
356,
469,
355,
283,
10538,
356,
283,
287,
297,
355,
283,
8191,
63,
324,
18065,
356,
756,
12,
288,
789,
267,
789,
398,
2455,
63,
1113,
275,
7711,
23239,
342,
267,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
4391,
15,
11486,
3678,
6339,
63,
600,
534,
4391,
297,
5283,
29,
549,
9,
267,
15422,
360,
4391,
358,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
2455,
63,
1113,
14,
958,
275,
1052,
267,
2455,
63,
1113,
14,
785,
63,
513,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
2455,
63,
1113,
14,
362,
63,
1100,
63,
576,
8,
785,
63,
513,
29,
1345,
63,
1113,
14,
785,
63,
513,
9,
267,
291,
14,
629,
8,
1345,
63,
1113,
14,
362,
63,
7924,
1252,
835,
1062,
499,
9,
398,
10263,
19650,
63,
38,
1761,
7111,
275,
1050,
63,
885,
63,
3671,
63,
1751,
8,
4014,
19650,
63,
38,
1761,
7111,
9,
267,
543,
4278,
63,
462,
1435,
63,
1751,
8,
4014,
19650,
63,
26886,
29,
4014,
19650,
63,
38,
1761,
7111,
304,
953,
2455,
63,
1113,
275,
7711,
23239,
342,
288,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
4391,
15,
11486,
3678
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
199,
504,
1639,
14,
1014,
492,
4760,
5188,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
504,
1639,
14,
1208,
14,
6893,
492,
15422,
199,
504,
366,
851,
679,
706,
63,
11486,
14,
11522,
492,
491,
27126,
17816,
7658,
12,
8053,
7658,
199,
504,
366,
851,
679,
706,
63,
11486,
14,
30515,
492,
29775,
8972,
1130,
199,
504,
366,
851,
679,
706,
63,
11486,
14,
4196,
492,
334,
5949,
17816,
2768,
12,
13573,
17816,
2768,
12,
7711,
13042,
2768,
12,
3303,
7711,
28539,
12,
7711,
23239,
12,
32121,
23239,
9,
199,
504,
623,
1435,
14,
2219,
14,
1208,
492,
4278,
63,
462,
1435,
63,
1751,
199,
504,
623,
1435,
14,
1208,
14,
2190,
492,
1050,
63,
885,
63,
3671,
63,
1751,
199,
504,
623,
1435,
14,
1208,
14,
1100,
492,
6258,
63,
3671,
199,
199,
504,
1275,
492,
3523,
774,
421,
199,
533,
10935,
774,
8,
23170,
304,
339,
347,
511,
63,
1932,
63,
513,
63,
1345,
8,
277,
304,
267,
2034,
17,
12,
2034,
18,
275,
291,
14,
362,
63,
5856,
342,
267,
2963,
17,
12,
2963,
18,
275,
291,
14,
362,
63,
18084,
342,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
29952,
1062,
519,
9807,
287,
15,
11486,
3678,
5283,
29,
797,
9,
267,
15422,
360,
287,
358,
267,
2455,
63,
1113,
275,
7711,
23239,
342,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
398,
291,
14,
629,
8,
513,
8,
1345,
63,
1113,
14,
362,
63,
7924,
4000,
359,
1932,
17,
566,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
287,
15,
11486,
3678,
5283,
29,
797,
9,
267,
15422,
360,
287,
358,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
2455,
63,
1113,
14,
958,
275,
1052,
267,
6377,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
291,
14,
629,
8,
6177,
14,
835,
1062,
413,
9,
267,
291,
14,
629,
8,
409,
8,
6177,
395,
663,
779,
1932,
17,
2459,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
287,
15,
11486,
3678,
5283,
29,
549,
9,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
291,
14,
629,
8,
409,
8,
1345,
63,
1113,
14,
362,
63,
7924,
4000,
663,
779,
1932,
17,
12,
2963,
18,
2459,
398,
2455,
63,
1113,
14,
958,
275,
1052,
267,
2455,
63,
1113,
14,
785,
63,
513,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
2455,
63,
1113,
14,
30979,
63,
991,
275,
413,
267,
1067,
275,
2455,
63,
1113,
14,
362,
63,
1100,
63,
576,
8,
785,
63,
513,
29,
1345,
63,
1113,
14,
785,
63,
513,
9,
267,
291,
14,
1815,
8,
1100,
459,
374,
63,
28030,
1105,
267,
291,
14,
629,
8,
513,
8,
1100,
459,
1932,
63,
513,
3815,
359,
1932,
18,
566,
267,
291,
14,
629,
8,
1100,
459,
22073,
2278,
835,
12,
499,
9,
267,
291,
14,
629,
8,
1100,
459,
1932,
63,
513,
3488,
16,
1055,
1213,
12,
283,
11906,
2963,
358,
267,
1177,
275,
2455,
63,
1113,
14,
3352,
63,
475,
63,
1310,
8,
1100,
9,
267,
291,
14,
9535,
8,
1310,
12,
1067,
459,
1932,
63,
513,
3488,
16,
1055,
362,
63,
6116,
63,
633,
1012,
398,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
390,
15,
11486,
3678,
6339,
63,
600,
534,
390,
297,
5283,
29,
549,
9,
267,
15422,
360,
390,
358,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
2455,
63,
1113,
14,
785,
63,
513,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
1067,
275,
2455,
63,
1113,
14,
362,
63,
1100,
63,
576,
8,
785,
63,
513,
29,
1345,
63,
1113,
14,
785,
63,
513,
9,
267,
291,
14,
629,
8,
1100,
459,
1932,
63,
513,
3488,
16,
1055,
1213,
12,
283,
1513,
388,
1117,
2963,
358,
267,
1177,
275,
2455,
63,
1113,
14,
3352,
63,
475,
63,
1310,
8,
1100,
9,
267,
291,
14,
9535,
8,
1310,
12,
1067,
459,
1932,
63,
513,
3488,
16,
1055,
362,
63,
6116,
63,
633,
1012,
339,
347,
511,
63,
1932,
63,
513,
63,
1345,
63,
10538,
8,
277,
304,
267,
2034,
17,
12,
2034,
18,
275,
291,
14,
362,
63,
5856,
342,
267,
2963,
17,
12,
2963,
18,
275,
291,
14,
362,
63,
18084,
342,
398,
10263,
19650,
63,
38,
1761,
7111,
275,
469,
288,
413,
26,
334,
355,
791,
600,
356,
283,
287,
2267,
355,
791,
600,
356,
283,
390,
2267,
355,
791,
600,
356,
283,
4391,
297,
283,
8191,
63,
324,
18065,
356,
715,
1386,
288,
2318,
288,
283,
885,
356,
469,
355,
283,
10538,
356,
283,
287,
297,
355,
283,
8191,
63,
324,
18065,
356,
756,
12,
288,
789,
267,
789,
398,
2455,
63,
1113,
275,
7711,
23239,
342,
267,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
4391,
15,
11486,
3678,
6339,
63,
600,
534,
4391,
297,
5283,
29,
549,
9,
267,
15422,
360,
4391,
358,
267,
2455,
63,
1113,
14,
1069,
275,
1056,
267,
2455,
63,
1113,
14,
958,
275,
1052,
267,
2455,
63,
1113,
14,
785,
63,
513,
275,
2455,
63,
1113,
14,
362,
63,
7924,
342,
267,
2455,
63,
1113,
14,
362,
63,
1100,
63,
576,
8,
785,
63,
513,
29,
1345,
63,
1113,
14,
785,
63,
513,
9,
267,
291,
14,
629,
8,
1345,
63,
1113,
14,
362,
63,
7924,
1252,
835,
1062,
499,
9,
398,
10263,
19650,
63,
38,
1761,
7111,
275,
1050,
63,
885,
63,
3671,
63,
1751,
8,
4014,
19650,
63,
38,
1761,
7111,
9,
267,
543,
4278,
63,
462,
1435,
63,
1751,
8,
4014,
19650,
63,
26886,
29,
4014,
19650,
63,
38,
1761,
7111,
304,
953,
2455,
63,
1113,
275,
7711,
23239,
342,
288,
1056,
275,
291,
14,
362,
63,
1606,
63,
1069,
8,
1606,
17,
12,
291,
14,
751,
12,
519,
9807,
4391,
15,
11486,
3678,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
xfguo/skyeye
|
gui/wxpython/dialogs_xrc.py
|
3
|
21837
|
# This file was automatically generated by pywxrc.
# -*- coding: UTF-8 -*-
import wx
import wx.xrc as xrc
import os
import wx.grid
__res = None
def get_resources():
""" This function provides access to the XML resources in this module."""
global __res
if __res == None:
__init_resources()
return __res
class xrcmainframe(wx.Dialog):
#!XRCED:begin-block:xrcmainframe.PreCreate
def PreCreate(self, pre):
""" This function is called during the class's initialization.
Override it for custom setup before the window is created usually to
set additional window styles using SetWindowStyle() and SetExtraStyle().
"""
pass
#!XRCED:end-block:xrcmainframe.PreCreate
def __init__(self, parent):
# Two stage creation (see http://wiki.wxpython.org/index.cgi/TwoStageCreation)
pre = wx.PreDialog()
self.PreCreate(pre)
get_resources().LoadOnDialog(pre, parent, "mainframe")
self.PostCreate(pre)
# Draw the 5x4 table about mem_bank
colLabels = ["map", "type", "addr", "size"]
grid = self.FindWindowById(xrc.XRCID('mem_bank_tab'))
grid.CreateGrid(6,4)
for row in range(4):
grid.SetColLabelValue(row, colLabels[row])
# Define variables for the controls, bind event handlers
self.Bind(wx.EVT_COMBOBOX, self.OnCombobox_arch_box, id=xrc.XRCID('arch_box'))
self.Bind(wx.EVT_COMBOBOX, self.OnCombobox_cpu_box, id=xrc.XRCID('cpu_box'))
self.Bind(wx.EVT_COMBOBOX, self.OnCombobox_mach_box, id=xrc.XRCID('mach_box'))
self.Bind(wx.EVT_BUTTON, self.OnButton_load_file_path_button, id=xrc.XRCID('load_file_path_button'))
self.Bind(wx.EVT_BUTTON, self.OnButton_reset_button, id=xrc.XRCID('reset_button'))
self.Bind(wx.EVT_BUTTON, self.OnButton_save_button, id=xrc.XRCID('save_button'))
self.Bind(wx.EVT_BUTTON, self.OnButton_exit_button, id=xrc.XRCID('exit_button'))
#!XRCED:begin-block:xrcmainframe.OnCombobox_arch_box
def OnCombobox_arch_box(self, evt):
# Replace with event handler code
print "OnCombobox_arch_box()"
#!XRCED:end-block:xrcmainframe.OnCombobox_arch_box
#!XRCED:begin-block:xrcmainframe.OnCombobox_cpu_box
def OnCombobox_cpu_box(self, evt):
# Replace with event handler code
print "OnCombobox_cpu_box()"
#!XRCED:end-block:xrcmainframe.OnCombobox_cpu_box
#!XRCED:begin-block:xrcmainframe.OnCombobox_mach_box
def OnCombobox_mach_box(self, evt):
# Replace with event handler code
print "OnCombobox_mach_box()"
#!XRCED:end-block:xrcmainframe.OnCombobox_mach_box
#!XRCED:begin-block:xrcmainframe.OnButton_load_file_path_button
def OnButton_load_file_path_button(self, evt):
# Replace with event handler code
print "OnButton_load_file_path_button()"
dialog = wx.FileDialog(None, "Choose a file",
os.getcwd(),"", "All files (*)|*", wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
self.FindWindowById(xrc.XRCID('load_file_path_val')).SetValue(dialog.GetPath())
dialog.Destroy()
#!XRCED:end-block:xrcmainframe.OnButton_load_file_path_button
#!XRCED:begin-block:xrcmainframe.OnButton_reset_button
def OnButton_reset_button(self, evt):
# Replace with event handler code
print "OnButton_reset_button()"
#!XRCED:end-block:xrcmainframe.OnButton_reset_button
#!XRCED:begin-block:xrcmainframe.OnButton_save_button
def OnButton_save_button(self, evt):
# Replace with event handler code
print "OnButton_save_button()"
fp = open('skyeye_tmp.conf', 'w+')
# Fill the commont about skyeye_tmp.conf
mach_box = self.FindWindowById(xrc.XRCID('mach_box')).GetValue()
fp.writelines('#skyeye config file for ' + mach_box + '\n')
arch_box = self.FindWindowById(xrc.XRCID('arch_box')).GetValue()
print "arch: %s" % arch_box
fp.writelines('arch: ' + arch_box + '\n')
cpu_box = self.FindWindowById(xrc.XRCID('cpu_box')).GetValue()
print "cpu: %s" % cpu_box
fp.writelines('cpu: ' + cpu_box + '\n')
print "mach: %s" % mach_box
fp.writelines('mach: ' + mach_box + '\n\n')
fp.writelines('#address space\n')
grid = self.FindWindowById(xrc.XRCID('mem_bank_tab'))
# Create a [6,4] array for mem_bank
mem_bank = [[0 for col in range(4)] for row in range(6)]
# Derive the value from table.
for row in range(6):
for col in range(4):
mem_bank[row][col] = grid.GetCellValue(row, col)
# output the data to skyeye_tmp.conf
break_flag = False
for row in range(6):
for col in range(4):
if mem_bank[row][col] == '':
break_flag = True
break
if break_flag == True:
break_flag = False
continue
fp.writelines('mem_bank: map=' + mem_bank[row][0] + ', type=' + mem_bank[row][1] + ', addr=' + mem_bank[row][2] + ', size=' + mem_bank[row][3] + '\n')
fp.writelines('\n')
# Fill the uart option
fp.writelines('uart:mod=term\n\n')
# Fill the load_file option
load_file_path_val = self.FindWindowById(xrc.XRCID('load_file_path_val')).GetValue()
addr_text_val = self.FindWindowById(xrc.XRCID('addr_text_val')).GetValue()
#print "load_file: filename=%s, initrd_start=%s" %(load_file_path_val,addr_text_val)
fp.writelines('load_file: filename=' + load_file_path_val + ', initrd_start=' + addr_text_val + '\n')
# Fill the load_addr option
base_addr_val = self.FindWindowById(xrc.XRCID('base_addr_val')).GetValue()
mask_val = self.FindWindowById(xrc.XRCID('mask_val')).GetValue()
#print "load_addr: base=%s, mask=%s" %(base_addr_val,mask_val)
fp.writelines('load_addr: base=' + base_addr_val + ', mask=' + mask_val + '\n')
fp.close()
#!XRCED:end-block:xrcmainframe.OnButton_save_button
#!XRCED:begin-block:xrcmainframe.OnButton_exit_button
def OnButton_exit_button(self, evt):
# Replace with event handler code
print "OnButton_exit_button()"
self.Destroy()
#!XRCED:end-block:xrcmainframe.OnButton_exit_button
# ------------------------ Resource data ----------------------
def __init_resources():
global __res
__res = xrc.EmptyXmlResource()
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
dialogs_xrc = '''\
<?xml version="1.0" ?><resource>
<object class="wxDialog" name="mainframe">
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<object class="wxBoxSizer">
<object class="sizeritem">
<object class="wxStaticText" name="dec_text">
<label>The option of skyeye</label>
</object>
<flag>wxALL|wxEXPAND</flag>
</object>
<object class="spacer">
<size>0,10</size>
</object>
<object class="sizeritem">
<object class="wxStaticBoxSizer">
<object class="sizeritem">
<object class="wxFlexGridSizer">
<object class="sizeritem">
<object class="wxStaticText" name="arch_text">
<label>arch:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxComboBox" name="arch_box">
<content>
<item>arm</item>
<item>powerpc</item>
<item>x86</item>
<item>mips</item>
</content>
<value>arm</value>
<style>wxCB_READONLY</style>
<XRCED>
<events>EVT_COMBOBOX</events>
</XRCED>
</object>
</object>
</object>
<option>1</option>
<flag>wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="cpu_text">
<label>cpu:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxComboBox" name="cpu_box">
<content>
<item>arm710</item>
<item>arm7tdmi</item>
<item>arm720t</item>
<item>sa1110</item>
<item>sa1100</item>
<item>arm920t</item>
<item>arm926ejs</item>
<item>pxa25x</item>
<item>pxa27x</item>
<item>arm11</item>
</content>
<value>arm920t</value>
<style>wxCB_READONLY</style>
<XRCED>
<events>EVT_COMBOBOX</events>
</XRCED>
</object>
</object>
</object>
<option>1</option>
<flag>wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="mach_text">
<label>mach:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<object class="sizeritem">
<object class="wxComboBox" name="mach_box">
<content>
<item>at91rm92</item>
<item>pxa_lubbock</item>
<item>pxa_mainstone</item>
<item>s3c2410x</item>
<item>s3c2440</item>
<item>s3c6410</item>
</content>
<value>s3c2410x</value>
<style>wxCB_READONLY</style>
<XRCED>
<events>EVT_COMBOBOX</events>
</XRCED>
</object>
<option>1</option>
</object>
<orient>wxHORIZONTAL</orient>
</object>
<option>1</option>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="mem_bank_text">
<label>mem_bank:</label>
</object>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<object class="sizeritem">
<object class="wxGrid" name="mem_bank_tab">
<style>wxNO_BORDER</style>
</object>
<minsize>420,200</minsize>
</object>
<orient>wxVERTICAL</orient>
</object>
<flag>wxALL|wxEXPAND|wxADJUST_MINSIZE</flag>
<minsize>150</minsize>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="load_file_text">
<label>load_file:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxFlexGridSizer">
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="spacer">
<size>45,0</size>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="load_file_path_text">
<label>path:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxTextCtrl" name="load_file_path_val"/>
<flag>wxALL|wxEXPAND|wxALIGN_CENTRE_VERTICAL</flag>
<minsize>210, -1</minsize>
</object>
<object class="spacer">
<size>5,0</size>
</object>
<object class="sizeritem">
<object class="wxButton" name="load_file_path_button">
<label>Browse...</label>
<XRCED>
<events>EVT_BUTTON</events>
</XRCED>
</object>
</object>
</object>
<option>1</option>
</object>
<object class="spacer">
<size>20,0</size>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxStaticText" name="addr_text">
<label>initrd_start:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxTextCtrl" name="addr_text_val"/>
<flag>wxALL|wxEXPAND|wxALIGN_CENTRE_VERTICAL</flag>
<minsize>210, -1</minsize>
</object>
</object>
<option>1</option>
</object>
<cols>2</cols>
<rows>2</rows>
</object>
</object>
<cols>2</cols>
<vgap>5</vgap>
<hgap>20</hgap>
<growablecols>1</growablecols>
<object class="sizeritem">
<object class="wxStaticText" name="load_addr_text">
<label>load_addr:</label>
</object>
</object>
<object class="sizeritem">
<object class="wxFlexGridSizer">
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="spacer">
<size>7,0</size>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="base_addr_text">
<label>base_addr:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxTextCtrl" name="base_addr_val"/>
<flag>wxALL|wxEXPAND|wxALIGN_CENTRE_VERTICAL</flag>
<minsize>210, -1</minsize>
</object>
</object>
<option>1</option>
</object>
<object class="spacer">
<size>20,0</size>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="spacer">
<size>42,0</size>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="mask_text">
<label>mask:</label>
</object>
<flag>wxALL|wxALIGN_CENTRE_VERTICAL</flag>
</object>
<object class="sizeritem">
<object class="wxTextCtrl" name="mask_val"/>
<flag>wxALL|wxEXPAND|wxALIGN_CENTRE_VERTICAL</flag>
<minsize>210, -1</minsize>
</object>
</object>
<option>1</option>
</object>
<cols>2</cols>
<rows>2</rows>
</object>
</object>
</object>
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
</object>
<label>Options:</label>
<orient>wxVERTICAL</orient>
</object>
<flag>wxALL|wxEXPAND</flag>
<minsize>1000,800</minsize>
</object>
<object class="spacer">
<size>0,10</size>
</object>
<object class="sizeritem">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxGridSizer">
<cols>3</cols>
<object class="sizeritem">
<object class="wxButton" name="reset_button">
<label>reset</label>
<XRCED>
<events>EVT_BUTTON</events>
</XRCED>
</object>
<flag>wxALL|wxEXPAND</flag>
</object>
<hgap>5</hgap>
<object class="sizeritem">
<object class="wxButton" name="save_button">
<label>save</label>
<XRCED>
<events>EVT_BUTTON</events>
</XRCED>
</object>
<flag>wxALL|wxEXPAND</flag>
</object>
<object class="sizeritem">
<object class="wxButton" name="exit_button">
<label>Quit</label>
<XRCED>
<events>EVT_BUTTON</events>
</XRCED>
</object>
<flag>wxALL|wxEXPAND</flag>
</object>
</object>
</object>
</object>
<flag>wxALIGN_RIGHT</flag>
</object>
<orient>wxVERTICAL</orient>
</object>
<option>1</option>
<flag>wxALL|wxEXPAND</flag>
</object>
</object>
<title>skyeye.conf</title>
<font>
<size>11</size>
<style>normal</style>
<weight>normal</weight>
<underlined>0</underlined>
<family>default</family>
<face>Ubuntu</face>
<encoding>UTF-8</encoding>
</font>
<style>wxCAPTION|wxRESIZE_BORDER|wxRESIZE_BOX|wxCLOSE_BOX|wxMAXIMIZE_BOX</style>
</object>
</resource>'''
wx.MemoryFSHandler.AddFile('XRC/dialogs/dialogs_xrc', dialogs_xrc)
__res.Load('memory:XRC/dialogs/dialogs_xrc')
# ----------------------- Gettext strings ---------------------
def __gettext_strings():
# This is a dummy function that lists all the strings that are used in
# the XRC file in the _("a string") format to be recognized by GNU
# gettext utilities (specificaly the xgettext utility) and the
# mki18n.py script. For more information see:
# http://wiki.wxpython.org/index.cgi/Internationalization
def _(str): pass
_("The option of skyeye")
_("arch:")
_("arm")
_("powerpc")
_("x86")
_("mips")
_("arm")
_("cpu:")
_("arm710")
_("arm7tdmi")
_("arm720t")
_("sa1110")
_("sa1100")
_("arm920t")
_("arm926ejs")
_("pxa25x")
_("pxa27x")
_("arm11")
_("arm920t")
_("mach:")
_("at91rm92")
_("pxa&lubbock")
_("pxa&mainstone")
_("s3c2410x")
_("s3c2440")
_("s3c6410")
_("s3c2410x")
_("mem&bank:")
_("load&file:")
_("path:")
_("Browse...")
_("initrd&start:")
_("load&addr:")
_("base&addr:")
_("mask:")
_("Options:")
_("reset")
_("save")
_("Quit")
_("skyeye.conf")
|
gpl-2.0
|
[
3,
961,
570,
1990,
5847,
4046,
701,
1134,
6323,
1195,
14,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
646,
4818,
199,
646,
4818,
14,
88,
1195,
465,
671,
1195,
199,
646,
747,
199,
646,
4818,
14,
3825,
4388,
199,
363,
470,
275,
488,
199,
199,
318,
664,
63,
4435,
837,
272,
408,
961,
805,
6571,
2879,
370,
314,
4692,
5944,
315,
642,
859,
1041,
272,
2288,
636,
470,
272,
340,
636,
470,
508,
488,
26,
267,
636,
826,
63,
4435,
342,
272,
372,
636,
470,
6905,
199,
533,
671,
1195,
973,
1943,
8,
6323,
14,
5619,
304,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
2398,
2499,
272,
347,
5543,
2499,
8,
277,
12,
876,
304,
267,
408,
961,
805,
365,
2797,
5309,
314,
1021,
1159,
11097,
14,
2728,
11041,
652,
367,
3537,
3272,
2544,
314,
4353,
365,
2737,
9987,
370,
267,
663,
4722,
4353,
15725,
1808,
2494,
4301,
6609,
342,
436,
2494,
7426,
6609,
1252,
267,
408,
267,
986,
268,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
2398,
2499,
339,
347,
636,
826,
721,
277,
12,
1676,
304,
267,
327,
16853,
9546,
7143,
334,
3239,
1455,
921,
6797,
14,
6323,
1548,
14,
1308,
15,
1080,
14,
13814,
15,
11467,
21052,
13921,
9,
267,
876,
275,
4818,
14,
2398,
5619,
342,
267,
291,
14,
2398,
2499,
8,
657,
9,
267,
664,
63,
4435,
1252,
6200,
3314,
5619,
8,
657,
12,
1676,
12,
298,
973,
1943,
531,
267,
291,
14,
6564,
2499,
8,
657,
9,
398,
327,
17813,
314,
959,
88,
20,
1817,
3595,
7573,
63,
9860,
267,
1048,
14016,
275,
2097,
1130,
401,
298,
466,
401,
298,
2697,
401,
298,
890,
937,
267,
6068,
275,
291,
14,
6591,
4301,
18954,
8,
88,
1195,
14,
56,
8205,
998,
360,
5286,
63,
9860,
63,
2902,
1333,
267,
6068,
14,
2499,
7900,
8,
22,
12,
20,
9,
267,
367,
1962,
315,
1425,
8,
20,
304,
288,
6068,
14,
1084,
2001,
4314,
1110,
8,
1143,
12,
1048,
14016,
59,
1143,
566,
523,
398,
327,
13930,
2860,
367,
314,
13467,
12,
5398,
1566,
8297,
398,
291,
14,
8198,
8,
6323,
14,
12093,
63,
11265,
3973,
15694,
12,
291,
14,
3314,
12413,
1977,
63,
1047,
63,
1977,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
1047,
63,
1977,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
11265,
3973,
15694,
12,
291,
14,
3314,
12413,
1977,
63,
3541,
63,
1977,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
3541,
63,
1977,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
11265,
3973,
15694,
12,
291,
14,
3314,
12413,
1977,
63,
14121,
63,
1977,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
14121,
63,
1977,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
912,
63,
493,
63,
515,
63,
3887,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
3958,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
3958,
63,
3887,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
2117,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
2117,
63,
3887,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
2224,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
2224,
63,
3887,
1333,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
1047,
63,
1977,
272,
347,
4068,
12413,
1977,
63,
1047,
63,
1977,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
267,
870,
298,
3314,
12413,
1977,
63,
1047,
63,
1977,
16493,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
1047,
63,
1977,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
3541,
63,
1977,
272,
347,
4068,
12413,
1977,
63,
3541,
63,
1977,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
267,
870,
298,
3314,
12413,
1977,
63,
3541,
63,
1977,
16493,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
3541,
63,
1977,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
14121,
63,
1977,
272,
347,
4068,
12413,
1977,
63,
14121,
63,
1977,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
267,
870,
298,
3314,
12413,
1977,
63,
14121,
63,
1977,
16493,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
14121,
63,
1977,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
272,
347,
4068,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
2126,
870,
298,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
16493,
2126,
9592,
275,
4818,
14,
25213,
8,
403,
12,
298,
23932,
282,
570,
401,
28932,
8295,
747,
14,
9458,
1062,
5151,
298,
2422,
1584,
19943,
8636,
14421,
4818,
14,
9935,
9,
10817,
340,
9592,
14,
6824,
23689,
342,
508,
4818,
14,
998,
63,
3593,
26,
288,
291,
14,
6591,
4301,
18954,
8,
88,
1195,
14,
56,
8205,
998,
360,
912,
63,
493,
63,
515,
63,
637,
11103,
21322,
8,
7196,
14,
1002,
2042,
1012,
10817,
9592,
14,
14704,
342,
199,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973
] |
[
961,
570,
1990,
5847,
4046,
701,
1134,
6323,
1195,
14,
199,
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
199,
646,
4818,
199,
646,
4818,
14,
88,
1195,
465,
671,
1195,
199,
646,
747,
199,
646,
4818,
14,
3825,
4388,
199,
363,
470,
275,
488,
199,
199,
318,
664,
63,
4435,
837,
272,
408,
961,
805,
6571,
2879,
370,
314,
4692,
5944,
315,
642,
859,
1041,
272,
2288,
636,
470,
272,
340,
636,
470,
508,
488,
26,
267,
636,
826,
63,
4435,
342,
272,
372,
636,
470,
6905,
199,
533,
671,
1195,
973,
1943,
8,
6323,
14,
5619,
304,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
2398,
2499,
272,
347,
5543,
2499,
8,
277,
12,
876,
304,
267,
408,
961,
805,
365,
2797,
5309,
314,
1021,
1159,
11097,
14,
2728,
11041,
652,
367,
3537,
3272,
2544,
314,
4353,
365,
2737,
9987,
370,
267,
663,
4722,
4353,
15725,
1808,
2494,
4301,
6609,
342,
436,
2494,
7426,
6609,
1252,
267,
408,
267,
986,
268,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
2398,
2499,
339,
347,
636,
826,
721,
277,
12,
1676,
304,
267,
327,
16853,
9546,
7143,
334,
3239,
1455,
921,
6797,
14,
6323,
1548,
14,
1308,
15,
1080,
14,
13814,
15,
11467,
21052,
13921,
9,
267,
876,
275,
4818,
14,
2398,
5619,
342,
267,
291,
14,
2398,
2499,
8,
657,
9,
267,
664,
63,
4435,
1252,
6200,
3314,
5619,
8,
657,
12,
1676,
12,
298,
973,
1943,
531,
267,
291,
14,
6564,
2499,
8,
657,
9,
398,
327,
17813,
314,
959,
88,
20,
1817,
3595,
7573,
63,
9860,
267,
1048,
14016,
275,
2097,
1130,
401,
298,
466,
401,
298,
2697,
401,
298,
890,
937,
267,
6068,
275,
291,
14,
6591,
4301,
18954,
8,
88,
1195,
14,
56,
8205,
998,
360,
5286,
63,
9860,
63,
2902,
1333,
267,
6068,
14,
2499,
7900,
8,
22,
12,
20,
9,
267,
367,
1962,
315,
1425,
8,
20,
304,
288,
6068,
14,
1084,
2001,
4314,
1110,
8,
1143,
12,
1048,
14016,
59,
1143,
566,
523,
398,
327,
13930,
2860,
367,
314,
13467,
12,
5398,
1566,
8297,
398,
291,
14,
8198,
8,
6323,
14,
12093,
63,
11265,
3973,
15694,
12,
291,
14,
3314,
12413,
1977,
63,
1047,
63,
1977,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
1047,
63,
1977,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
11265,
3973,
15694,
12,
291,
14,
3314,
12413,
1977,
63,
3541,
63,
1977,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
3541,
63,
1977,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
11265,
3973,
15694,
12,
291,
14,
3314,
12413,
1977,
63,
14121,
63,
1977,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
14121,
63,
1977,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
912,
63,
493,
63,
515,
63,
3887,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
3958,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
3958,
63,
3887,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
2117,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
2117,
63,
3887,
1333,
267,
291,
14,
8198,
8,
6323,
14,
12093,
63,
13272,
12,
291,
14,
3314,
4259,
63,
2224,
63,
3887,
12,
1305,
29,
88,
1195,
14,
56,
8205,
998,
360,
2224,
63,
3887,
1333,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
1047,
63,
1977,
272,
347,
4068,
12413,
1977,
63,
1047,
63,
1977,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
267,
870,
298,
3314,
12413,
1977,
63,
1047,
63,
1977,
16493,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
1047,
63,
1977,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
3541,
63,
1977,
272,
347,
4068,
12413,
1977,
63,
3541,
63,
1977,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
267,
870,
298,
3314,
12413,
1977,
63,
3541,
63,
1977,
16493,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
3541,
63,
1977,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
14121,
63,
1977,
272,
347,
4068,
12413,
1977,
63,
14121,
63,
1977,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
267,
870,
298,
3314,
12413,
1977,
63,
14121,
63,
1977,
16493,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
12413,
1977,
63,
14121,
63,
1977,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
272,
347,
4068,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
8,
277,
12,
16330,
304,
267,
327,
14402,
543,
1566,
3016,
1233,
2126,
870,
298,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
16493,
2126,
9592,
275,
4818,
14,
25213,
8,
403,
12,
298,
23932,
282,
570,
401,
28932,
8295,
747,
14,
9458,
1062,
5151,
298,
2422,
1584,
19943,
8636,
14421,
4818,
14,
9935,
9,
10817,
340,
9592,
14,
6824,
23689,
342,
508,
4818,
14,
998,
63,
3593,
26,
288,
291,
14,
6591,
4301,
18954,
8,
88,
1195,
14,
56,
8205,
998,
360,
912,
63,
493,
63,
515,
63,
637,
11103,
21322,
8,
7196,
14,
1002,
2042,
1012,
10817,
9592,
14,
14704,
342,
199,
199,
3168,
56,
8205,
1149,
26,
500,
13,
1457,
26,
88,
1195,
973,
1943,
14,
3314,
4259,
63,
912,
63,
493,
63,
515,
63,
3887,
260,
199,
199,
3168,
56,
8205,
1149,
26,
5037,
13,
1457,
26,
88,
1195,
973,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zimmerle/gnuradio
|
gr-digital/python/qa_map.py
|
8
|
1784
|
#!/usr/bin/env python
#
# Copyright 2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, gr_unittest
import digital_swig as digital
class test_map(gr_unittest.TestCase):
def setUp(self):
self.tb = gr.top_block()
def tearDown(self):
self.tb = None
def helper(self, symbols):
src_data = [0, 1, 2, 3, 0, 1, 2, 3]
expected_data = map(lambda x: symbols[x], src_data)
src = gr.vector_source_b (src_data)
op = digital.map_bb(symbols)
dst = gr.vector_sink_b ()
self.tb.connect (src, op, dst)
self.tb.run ()
result_data = list(dst.data())
self.assertEqual (expected_data, result_data)
def test_001(self):
symbols = [0, 0, 0, 0]
self.helper(symbols)
def test_002(self):
symbols = [3, 2, 1, 0]
self.helper(symbols)
def test_003(self):
symbols = [8-1, 32-1, 128, 256-1]
self.helper(symbols)
if __name__ == '__main__':
gr_unittest.run(test_map, "test_map.xml")
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6029,
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,
7192,
63,
2796,
199,
646,
20545,
63,
9676,
465,
20545,
199,
199,
533,
511,
63,
1130,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
5922,
8,
277,
12,
6698,
304,
267,
2928,
63,
576,
275,
359,
16,
12,
413,
12,
499,
12,
650,
12,
378,
12,
413,
12,
499,
12,
650,
61,
267,
1420,
63,
576,
275,
2341,
8,
2734,
671,
26,
6698,
59,
88,
467,
2928,
63,
576,
9,
267,
2928,
275,
7192,
14,
4106,
63,
1365,
63,
66,
334,
2164,
63,
576,
9,
267,
1687,
275,
20545,
14,
1130,
63,
2501,
8,
7450,
9,
267,
5042,
275,
7192,
14,
4106,
63,
11279,
63,
66,
6248,
267,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
6248,
398,
754,
63,
576,
275,
769,
8,
5119,
14,
576,
1012,
267,
291,
14,
629,
334,
2062,
63,
576,
12,
754,
63,
576,
9,
339,
347,
511,
63,
4587,
8,
277,
304,
267,
6698,
275,
359,
16,
12,
378,
12,
378,
12,
378,
61,
267,
291,
14,
3676,
8,
7450,
9,
5493,
347,
511,
63,
7432,
8,
277,
304,
267,
6698,
275,
359,
19,
12,
499,
12,
413,
12,
378,
61,
267,
291,
14,
3676,
8,
7450,
9,
339,
347,
511,
63,
8262,
8,
277,
304,
267,
6698,
275,
359,
24,
13,
17,
12,
4337,
13,
17,
12,
7960,
12,
7633,
13,
17,
61,
267,
291,
14,
3676,
8,
7450,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
14,
1065,
8,
396,
63,
1130,
12,
298,
396,
63,
1130,
14,
1652,
531,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6029,
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,
7192,
63,
2796,
199,
646,
20545,
63,
9676,
465,
20545,
199,
199,
533,
511,
63,
1130,
8,
2587,
63,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5842,
275,
7192,
14,
2119,
63,
1457,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5842,
275,
488,
339,
347,
5922,
8,
277,
12,
6698,
304,
267,
2928,
63,
576,
275,
359,
16,
12,
413,
12,
499,
12,
650,
12,
378,
12,
413,
12,
499,
12,
650,
61,
267,
1420,
63,
576,
275,
2341,
8,
2734,
671,
26,
6698,
59,
88,
467,
2928,
63,
576,
9,
267,
2928,
275,
7192,
14,
4106,
63,
1365,
63,
66,
334,
2164,
63,
576,
9,
267,
1687,
275,
20545,
14,
1130,
63,
2501,
8,
7450,
9,
267,
5042,
275,
7192,
14,
4106,
63,
11279,
63,
66,
6248,
267,
291,
14,
5842,
14,
2242,
334,
2164,
12,
1687,
12,
5042,
9,
267,
291,
14,
5842,
14,
1065,
6248,
398,
754,
63,
576,
275,
769,
8,
5119,
14,
576,
1012,
267,
291,
14,
629,
334,
2062,
63,
576,
12,
754,
63,
576,
9,
339,
347,
511,
63,
4587,
8,
277,
304,
267,
6698,
275,
359,
16,
12,
378,
12,
378,
12,
378,
61,
267,
291,
14,
3676,
8,
7450,
9,
5493,
347,
511,
63,
7432,
8,
277,
304,
267,
6698,
275,
359,
19,
12,
499,
12,
413,
12,
378,
61,
267,
291,
14,
3676,
8,
7450,
9,
339,
347,
511,
63,
8262,
8,
277,
304,
267,
6698,
275,
359,
24,
13,
17,
12,
4337,
13,
17,
12,
7960,
12,
7633,
13,
17,
61,
267,
291,
14,
3676,
8,
7450,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
7192,
63,
2796,
14,
1065,
8,
396,
63,
1130,
12,
298,
396,
63,
1130,
14,
1652,
531,
27844,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
whip112/Whip112
|
vendor/packages/pygments/formatters/__init__.py
|
44
|
3597
|
# -*- coding: utf-8 -*-
"""
pygments.formatters
~~~~~~~~~~~~~~~~~~~
Pygments formatters.
:copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
import sys
import types
import fnmatch
from os.path import basename
from pygments.formatters._mapping import FORMATTERS
from pygments.plugin import find_plugin_formatters
from pygments.util import ClassNotFound, itervalues
__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
'get_all_formatters'] + list(FORMATTERS)
_formatter_cache = {} # classes by name
_pattern_cache = {}
def _fn_matches(fn, glob):
"""Return whether the supplied file name fn matches pattern filename."""
if glob not in _pattern_cache:
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
return pattern.match(fn)
return _pattern_cache[glob].match(fn)
def _load_formatters(module_name):
"""Load a formatter (and all others in the module too)."""
mod = __import__(module_name, None, None, ['__all__'])
for formatter_name in mod.__all__:
cls = getattr(mod, formatter_name)
_formatter_cache[cls.name] = cls
def get_all_formatters():
"""Return a generator for all formatter classes."""
# NB: this returns formatter classes, not info like get_all_lexers().
for info in itervalues(FORMATTERS):
if info[1] not in _formatter_cache:
_load_formatters(info[0])
yield _formatter_cache[info[1]]
for _, formatter in find_plugin_formatters():
yield formatter
def find_formatter_class(alias):
"""Lookup a formatter by alias.
Returns None if not found.
"""
for module_name, name, aliases, _, _ in itervalues(FORMATTERS):
if alias in aliases:
if name not in _formatter_cache:
_load_formatters(module_name)
return _formatter_cache[name]
for _, cls in find_plugin_formatters():
if alias in cls.aliases:
return cls
def get_formatter_by_name(_alias, **options):
"""Lookup and instantiate a formatter by alias.
Raises ClassNotFound if not found.
"""
cls = find_formatter_class(_alias)
if cls is None:
raise ClassNotFound("no formatter found for name %r" % _alias)
return cls(**options)
def get_formatter_for_filename(fn, **options):
"""Lookup and instantiate a formatter by filename pattern.
Raises ClassNotFound if not found.
"""
fn = basename(fn)
for modname, name, _, filenames, _ in itervalues(FORMATTERS):
for filename in filenames:
if _fn_matches(fn, filename):
if name not in _formatter_cache:
_load_formatters(modname)
return _formatter_cache[name](**options)
for cls in find_plugin_formatters():
for filename in cls.filenames:
if _fn_matches(fn, filename):
return cls(**options)
raise ClassNotFound("no formatter found for file name %r" % fn)
class _automodule(types.ModuleType):
"""Automatically import formatters."""
def __getattr__(self, name):
info = FORMATTERS.get(name)
if info:
_load_formatters(info[0])
cls = _formatter_cache[info[1]]
setattr(self, name, cls)
return cls
raise AttributeError(name)
oldmod = sys.modules[__name__]
newmod = _automodule(__name__)
newmod.__dict__.update(oldmod.__dict__)
sys.modules[__name__] = newmod
del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
|
mpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
24270,
272,
18294,
23597,
339,
14493,
30514,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
2943,
199,
646,
15951,
199,
504,
747,
14,
515,
492,
9593,
199,
199,
504,
13277,
14,
24270,
423,
4745,
492,
11295,
619,
1157,
51,
199,
504,
13277,
14,
2718,
492,
2342,
63,
2718,
63,
24270,
199,
504,
13277,
14,
1974,
492,
8089,
4667,
12,
24451,
199,
199,
363,
452,
363,
275,
788,
362,
63,
8911,
63,
991,
63,
354,
297,
283,
362,
63,
8911,
63,
509,
63,
1501,
297,
1779,
283,
362,
63,
452,
63,
24270,
418,
435,
769,
8,
4807,
1157,
51,
9,
199,
199,
63,
8911,
63,
1637,
275,
1052,
221,
327,
3992,
701,
536,
199,
63,
3401,
63,
1637,
275,
1052,
421,
199,
318,
485,
2324,
63,
6742,
8,
2324,
12,
5739,
304,
272,
408,
1767,
3775,
314,
6841,
570,
536,
4325,
4450,
3851,
1788,
1041,
272,
340,
5739,
440,
315,
485,
3401,
63,
1637,
26,
267,
3851,
275,
485,
3401,
63,
1637,
59,
6463,
61,
275,
295,
14,
2014,
8,
15359,
14,
5275,
8,
6463,
430,
267,
372,
3851,
14,
1431,
8,
2324,
9,
272,
372,
485,
3401,
63,
1637,
59,
6463,
1055,
1431,
8,
2324,
9,
421,
199,
318,
485,
912,
63,
24270,
8,
578,
63,
354,
304,
272,
408,
6200,
282,
9698,
334,
460,
1006,
11789,
315,
314,
859,
4634,
10477,
272,
3413,
275,
636,
646,
721,
578,
63,
354,
12,
488,
12,
488,
12,
14050,
452,
363,
1105,
272,
367,
9698,
63,
354,
315,
3413,
855,
452,
10651,
267,
843,
275,
2519,
8,
1494,
12,
9698,
63,
354,
9,
267,
485,
8911,
63,
1637,
59,
1886,
14,
354,
61,
275,
843,
421,
199,
318,
664,
63,
452,
63,
24270,
837,
272,
408,
1767,
282,
4306,
367,
1006,
9698,
3992,
1041,
272,
327,
25377,
26,
642,
2529,
9698,
3992,
12,
440,
2256,
2839,
664,
63,
452,
63,
12245,
1252,
272,
367,
2256,
315,
24451,
8,
4807,
1157,
51,
304,
267,
340,
2256,
59,
17,
61,
440,
315,
485,
8911,
63,
1637,
26,
288,
485,
912,
63,
24270,
8,
815,
59,
16,
566,
267,
1995,
485,
8911,
63,
1637,
59,
815,
59,
17,
2677,
272,
367,
5501,
9698,
315,
2342,
63,
2718,
63,
24270,
837,
267,
1995,
9698,
421,
199,
318,
2342,
63,
8911,
63,
533,
8,
3620,
304,
272,
408,
7521,
282,
9698,
701,
5162,
14,
339,
1803,
488,
340,
440,
1911,
14,
272,
408,
272,
367,
859,
63,
354,
12,
536,
12,
5481,
12,
5501,
485,
315,
24451,
8,
4807,
1157,
51,
304,
267,
340,
5162,
315,
5481,
26,
288,
340,
536,
440,
315,
485,
8911,
63,
1637,
26,
355,
485,
912,
63,
24270,
8,
578,
63,
354,
9,
288,
372,
485,
8911,
63,
1637,
59,
354,
61,
272,
367,
5501,
843,
315,
2342,
63,
2718,
63,
24270,
837,
267,
340,
5162,
315,
843,
14,
8602,
26,
288,
372,
843,
421,
199,
318,
664,
63,
8911,
63,
991,
63,
354,
1547,
3620,
12,
1011,
1419,
304,
272,
408,
7521,
436,
17321,
282,
9698,
701,
5162,
14,
339,
6218,
8089,
4667,
340,
440,
1911,
14,
272,
408,
272,
843,
275,
2342,
63,
8911,
63,
533,
1547,
3620,
9,
272,
340,
843,
365,
488,
26,
267,
746,
8089,
4667,
480,
889,
9698,
1911,
367,
536,
450,
82,
2,
450,
485,
3620,
9,
272,
372,
843,
3682,
1419,
9,
421,
199,
318,
664,
63,
8911,
63,
509,
63,
1501,
8,
2324,
12,
1011,
1419,
304,
272,
408,
7521,
436,
17321,
282,
9698,
701,
1788,
3851,
14,
339,
6218,
8089,
4667,
340,
440,
1911,
14,
272,
408,
272,
4325,
275,
9593,
8,
2324,
9,
272,
367,
13526,
12,
536,
12,
5501,
6203,
12,
485,
315,
24451,
8,
4807,
1157,
51,
304,
267,
367,
1788,
315,
6203,
26,
288,
340,
485,
2324,
63,
6742,
8,
2324,
12,
1788,
304,
355,
340,
536,
440,
315,
485,
8911,
63,
1637,
26,
490,
485,
912,
63,
24270,
8,
14789,
9,
355,
372,
485,
8911,
63,
1637,
59,
354,
61,
3682,
1419,
9,
272,
367,
843,
315,
2342,
63,
2718,
63,
24270,
837,
267,
367,
1788,
315,
843,
14,
10309,
26,
288,
340,
485,
2324,
63,
6742,
8,
2324,
12,
1788,
304,
355,
372,
843,
3682,
1419,
9,
272,
746,
8089,
4667,
480,
889,
9698,
1911,
367,
570,
536,
450,
82,
2,
450,
4325,
9,
421,
199,
533,
485,
2495,
578,
8,
1313,
14,
21820,
304,
272,
408,
3358,
17174,
492,
30514,
1041,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
2256,
275,
11295,
619,
1157,
51,
14,
362,
8,
354,
9,
267,
340,
2256,
26,
288,
485,
912,
63,
24270,
8,
815,
59,
16,
566,
288,
843,
275,
485,
8911,
63,
1637,
59,
815,
59,
17,
2677,
288,
5371,
8,
277,
12,
536,
12,
843,
9,
288,
372,
843,
267,
746,
4281,
8,
354,
9,
421,
199,
1753,
1494,
275,
984,
14,
3112,
28894,
354,
22705,
199,
1222,
1494,
275,
485,
2495,
578,
3460,
354,
3368,
199,
1222,
1494,
855,
807,
4343,
873,
8,
1753,
1494,
855,
807,
3368,
199,
1274,
14,
3112,
28894,
354,
22705,
275,
892,
1494,
199,
2264,
892,
1494,
14,
1222,
1494,
12,
892,
1494,
14,
1753,
1494,
12,
892,
1494,
14,
1274,
12,
892,
1494,
14,
1313,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
13277,
14,
24270,
272,
18294,
23597,
339,
14493,
30514,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7280,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
2943,
199,
646,
15951,
199,
504,
747,
14,
515,
492,
9593,
199,
199,
504,
13277,
14,
24270,
423,
4745,
492,
11295,
619,
1157,
51,
199,
504,
13277,
14,
2718,
492,
2342,
63,
2718,
63,
24270,
199,
504,
13277,
14,
1974,
492,
8089,
4667,
12,
24451,
199,
199,
363,
452,
363,
275,
788,
362,
63,
8911,
63,
991,
63,
354,
297,
283,
362,
63,
8911,
63,
509,
63,
1501,
297,
1779,
283,
362,
63,
452,
63,
24270,
418,
435,
769,
8,
4807,
1157,
51,
9,
199,
199,
63,
8911,
63,
1637,
275,
1052,
221,
327,
3992,
701,
536,
199,
63,
3401,
63,
1637,
275,
1052,
421,
199,
318,
485,
2324,
63,
6742,
8,
2324,
12,
5739,
304,
272,
408,
1767,
3775,
314,
6841,
570,
536,
4325,
4450,
3851,
1788,
1041,
272,
340,
5739,
440,
315,
485,
3401,
63,
1637,
26,
267,
3851,
275,
485,
3401,
63,
1637,
59,
6463,
61,
275,
295,
14,
2014,
8,
15359,
14,
5275,
8,
6463,
430,
267,
372,
3851,
14,
1431,
8,
2324,
9,
272,
372,
485,
3401,
63,
1637,
59,
6463,
1055,
1431,
8,
2324,
9,
421,
199,
318,
485,
912,
63,
24270,
8,
578,
63,
354,
304,
272,
408,
6200,
282,
9698,
334,
460,
1006,
11789,
315,
314,
859,
4634,
10477,
272,
3413,
275,
636,
646,
721,
578,
63,
354,
12,
488,
12,
488,
12,
14050,
452,
363,
1105,
272,
367,
9698,
63,
354,
315,
3413,
855,
452,
10651,
267,
843,
275,
2519,
8,
1494,
12,
9698,
63,
354,
9,
267,
485,
8911,
63,
1637,
59,
1886,
14,
354,
61,
275,
843,
421,
199,
318,
664,
63,
452,
63,
24270,
837,
272,
408,
1767,
282,
4306,
367,
1006,
9698,
3992,
1041,
272,
327,
25377,
26,
642,
2529,
9698,
3992,
12,
440,
2256,
2839,
664,
63,
452,
63,
12245,
1252,
272,
367,
2256,
315,
24451,
8,
4807,
1157,
51,
304,
267,
340,
2256,
59,
17,
61,
440,
315,
485,
8911,
63,
1637,
26,
288,
485,
912,
63,
24270,
8,
815,
59,
16,
566,
267,
1995,
485,
8911,
63,
1637,
59,
815,
59,
17,
2677,
272,
367,
5501,
9698,
315,
2342,
63,
2718,
63,
24270,
837,
267,
1995,
9698,
421,
199,
318,
2342,
63,
8911,
63,
533,
8,
3620,
304,
272,
408,
7521,
282,
9698,
701,
5162,
14,
339,
1803,
488,
340,
440,
1911,
14,
272,
408,
272,
367,
859,
63,
354,
12,
536,
12,
5481,
12,
5501,
485,
315,
24451,
8,
4807,
1157,
51,
304,
267,
340,
5162,
315,
5481,
26,
288,
340,
536,
440,
315,
485,
8911,
63,
1637,
26,
355,
485,
912,
63,
24270,
8,
578,
63,
354,
9,
288,
372,
485,
8911,
63,
1637,
59,
354,
61,
272,
367,
5501,
843,
315,
2342,
63,
2718,
63,
24270,
837,
267,
340,
5162,
315,
843,
14,
8602,
26,
288,
372,
843,
421,
199,
318,
664,
63,
8911,
63,
991,
63,
354,
1547,
3620,
12,
1011,
1419,
304,
272,
408,
7521,
436,
17321,
282,
9698,
701,
5162,
14,
339,
6218,
8089,
4667,
340,
440,
1911,
14,
272,
408,
272,
843,
275,
2342,
63,
8911,
63,
533,
1547,
3620,
9,
272,
340,
843,
365,
488,
26,
267,
746,
8089,
4667,
480,
889,
9698,
1911,
367,
536,
450,
82,
2,
450,
485,
3620,
9,
272,
372,
843,
3682,
1419,
9,
421,
199,
318,
664,
63,
8911,
63,
509,
63,
1501,
8,
2324,
12,
1011,
1419,
304,
272,
408,
7521,
436,
17321,
282,
9698,
701,
1788,
3851,
14,
339,
6218,
8089,
4667,
340,
440,
1911,
14,
272,
408,
272,
4325,
275,
9593,
8,
2324,
9,
272,
367,
13526,
12,
536,
12,
5501,
6203,
12,
485,
315,
24451,
8,
4807,
1157,
51,
304,
267,
367,
1788,
315,
6203,
26,
288,
340,
485,
2324,
63,
6742,
8,
2324,
12,
1788,
304,
355,
340,
536,
440,
315,
485,
8911,
63,
1637,
26,
490,
485,
912,
63,
24270,
8,
14789,
9,
355,
372,
485,
8911,
63,
1637,
59,
354,
61,
3682,
1419,
9,
272,
367,
843,
315,
2342,
63,
2718,
63,
24270,
837,
267,
367,
1788,
315,
843,
14,
10309,
26,
288,
340,
485,
2324,
63,
6742,
8,
2324,
12,
1788,
304,
355,
372,
843,
3682,
1419,
9,
272,
746,
8089,
4667,
480,
889,
9698,
1911,
367,
570,
536,
450,
82,
2,
450,
4325,
9,
421,
199,
533,
485,
2495,
578,
8,
1313,
14,
21820,
304,
272,
408,
3358,
17174,
492,
30514,
1041,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
2256,
275,
11295,
619,
1157,
51,
14,
362,
8,
354,
9,
267,
340,
2256,
26,
288,
485,
912,
63,
24270,
8,
815,
59,
16,
566,
288,
843,
275,
485,
8911,
63,
1637,
59,
815,
59,
17,
2677,
288,
5371,
8,
277,
12,
536,
12,
843,
9,
288,
372,
843,
267,
746,
4281,
8,
354,
9,
421,
199,
1753,
1494,
275,
984,
14,
3112,
28894,
354,
22705,
199,
1222,
1494,
275,
485,
2495,
578,
3460,
354,
3368,
199,
1222,
1494,
855,
807,
4343,
873,
8,
1753,
1494,
855,
807,
3368,
199,
1274,
14,
3112,
28894,
354,
22705,
275,
892,
1494,
199,
2264,
892,
1494,
14,
1222,
1494,
12,
892,
1494,
14,
1753,
1494,
12,
892,
1494,
14,
1274,
12,
892,
1494,
14,
1313,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
arabenjamin/pybrain
|
pybrain/tools/plotting/fitnesslandscapes.py
|
31
|
3853
|
# some utility code for nicely plotting 3D images of function fitness landscapes.
__author__ = 'Tom Schaul, tom@idsia.ch'
from scipy import zeros, r_, cos, sin, pi, array, dot, sqrt, diag
from scipy.linalg import svd
from pylab import figure, plot, show, meshgrid, contour, savefig, colorbar
from pybrain.rl.environments.functions import FunctionEnvironment
from inspect import isclass
def plotCovEllipse(emat, center, segments=50, color='y', transp=1.):
""" Plots a covariance ellipse. """
# compute a nb of points on the ellipse
ex = zeros(segments + 1)
ey = zeros(segments + 1)
u, s, d = svd(emat)
sm = dot(d, dot(diag(sqrt(s)), u))
for i in range(segments + 1):
circlex = cos((2 * pi * i) / float(segments))
circley = sin((2 * pi * i) / float(segments))
ex[i] = center[0] + sm[0, 0] * circlex + sm[0, 1] * circley
ey[i] = center[1] + sm[1, 0] * circlex + sm[1, 1] * circley
# plot them
plot([center[0]], [center[1]], '+', color=color, alpha=transp)
plot(ex, ey, '-', color=color, alpha=transp)
return ex, ey
class FitnessPlotter:
""" plot the function's values in the rectangular region specified by ranges. By default, plot in [-1,1] """
def __init__(self, f, xmin= -1, xmax=1, ymin= -1, ymax=1, precision=50, newfig=True,
colorbar=False, cblabel=None):
""" :key precision: how many steps along every dimension """
if isinstance(f, FunctionEnvironment):
assert f.xdim == 2
self.f = lambda x, y: f(array([x, y]))
elif isclass(f) and issubclass(f, FunctionEnvironment):
tmp = f(2)
self.f = lambda x, y: tmp(array([x, y]))
else:
self.f = f
self.precision = precision
self.colorbar = colorbar
self.cblabel = cblabel
self.xs = r_[xmin:xmax:self.precision * 1j]
self.ys = r_[ymin:ymax:self.precision * 1j]
self.zs = self._generateValMap()
if newfig:
self.fig = figure()
def _generateValMap(self):
""" generate the function fitness values for the current grid of x and y """
vals = zeros((len(self.xs), len(self.ys)))
for i, x in enumerate(self.xs):
for j, y in enumerate(self.ys):
vals[j, i] = self.f(x, y)
return vals
def plotAll(self, levels=50, popup=True):
""" :key levels: how many fitness levels should be drawn."""
tmp = contour(self.xs, self.ys, self.zs, levels)
if self.colorbar:
cb = colorbar(tmp)
if self.cblabel != None:
cb.set_label(self.cblabel)
if popup: show()
def addSamples(self, samples, rescale=True, color=''):
"""plot some sample points on the fitness landscape.
:key rescale: should the plotting ranges be adjusted? """
# split samples into x and y
sx = zeros(len(samples))
sy = zeros(len(samples))
for i, s in enumerate(samples):
sx[i] = s[0]
sy[i] = s[1]
if rescale:
self._rescale(min(sx), max(sx), min(sy), max(sy))
plot(sx, sy, color + '+')
def _rescale(self, xmin, xmax, ymin, ymax):
self.xs = r_[min(xmin * 1.1, min(self.xs)):max(xmax * 1.1, max(self.xs)):self.precision * 1j]
self.ys = r_[min(ymin * 1.1, min(self.ys)):max(ymax * 1.1, max(self.ys)):self.precision * 1j]
self.zs = self._generateValMap()
def addCovEllipse(self, emat, center, segments=50, rescale=True, color='c', transp=1.):
"""plot a covariance ellipse """
ex, ey = plotCovEllipse(emat, center, segments, color, transp)
if rescale:
self._rescale(min(ex), max(ex), min(ey), max(ey))
def saveAs(self, filename, format='.jpg'):
savefig(filename + format)
|
bsd-3-clause
|
[
3,
2005,
11420,
1233,
367,
14213,
590,
25174,
650,
36,
5935,
402,
805,
5542,
4171,
20078,
3588,
83,
14,
199,
199,
363,
2502,
363,
275,
283,
52,
676,
428,
9518,
348,
12,
370,
77,
32,
344,
10971,
14,
335,
7,
199,
199,
504,
7026,
492,
10136,
12,
519,
3131,
9794,
12,
9829,
12,
6682,
12,
1625,
12,
6308,
12,
7452,
12,
8348,
199,
504,
7026,
14,
10096,
492,
26937,
199,
504,
19199,
492,
9658,
12,
5137,
12,
2498,
12,
9364,
3825,
12,
23176,
12,
3354,
592,
12,
3164,
1700,
199,
504,
1134,
22246,
14,
4308,
14,
26411,
14,
5777,
492,
6801,
8263,
199,
504,
6485,
492,
365,
533,
421,
199,
318,
5137,
967,
86,
23525,
261,
8,
69,
569,
12,
8126,
12,
11998,
29,
1400,
12,
3164,
534,
89,
297,
7115,
681,
29,
17,
14,
304,
272,
408,
510,
4555,
282,
13263,
16028,
261,
14,
408,
272,
327,
4526,
282,
8526,
402,
4501,
641,
314,
16028,
261,
272,
444,
275,
10136,
8,
13879,
435,
413,
9,
272,
325,
89,
275,
10136,
8,
13879,
435,
413,
9,
272,
399,
12,
308,
12,
366,
275,
26937,
8,
69,
569,
9,
272,
4383,
275,
6308,
8,
68,
12,
6308,
8,
6706,
8,
5079,
8,
83,
1826,
399,
430,
272,
367,
284,
315,
1425,
8,
13879,
435,
413,
304,
267,
17990,
88,
275,
9794,
1332,
18,
627,
6682,
627,
284,
9,
1182,
2069,
8,
13879,
430,
267,
17990,
89,
275,
9829,
1332,
18,
627,
6682,
627,
284,
9,
1182,
2069,
8,
13879,
430,
267,
444,
59,
73,
61,
275,
8126,
59,
16,
61,
435,
4383,
59,
16,
12,
378,
61,
627,
17990,
88,
435,
4383,
59,
16,
12,
413,
61,
627,
17990,
89,
267,
325,
89,
59,
73,
61,
275,
8126,
59,
17,
61,
435,
4383,
59,
17,
12,
378,
61,
627,
17990,
88,
435,
4383,
59,
17,
12,
413,
61,
627,
17990,
89,
339,
327,
5137,
3062,
272,
5137,
779,
4218,
59,
16,
2365,
359,
4218,
59,
17,
2365,
32278,
3164,
29,
2326,
12,
5131,
29,
3936,
681,
9,
272,
5137,
8,
476,
12,
325,
89,
12,
17525,
3164,
29,
2326,
12,
5131,
29,
3936,
681,
9,
272,
372,
444,
12,
325,
89,
421,
199,
533,
481,
24531,
10711,
351,
26,
272,
408,
5137,
314,
805,
1159,
1338,
315,
314,
8626,
11572,
4897,
2013,
701,
12271,
14,
4885,
849,
12,
5137,
315,
5243,
17,
12,
17,
61,
408,
272,
347,
636,
826,
721,
277,
12,
289,
12,
22036,
29,
446,
17,
12,
19906,
29,
17,
12,
22506,
29,
446,
17,
12,
21023,
29,
17,
12,
7151,
29,
1400,
12,
892,
592,
29,
549,
12,
326,
3164,
1700,
29,
797,
12,
7434,
1302,
29,
403,
304,
267,
408,
520,
498,
7151,
26,
4212,
5002,
7124,
3180,
4036,
6240,
408,
267,
340,
1228,
8,
70,
12,
6801,
8263,
304,
288,
702,
289,
14,
88,
3572,
508,
499,
288,
291,
14,
70,
275,
2400,
671,
12,
612,
26,
289,
8,
1144,
779,
88,
12,
612,
2459,
267,
916,
365,
533,
8,
70,
9,
436,
11602,
8,
70,
12,
6801,
8263,
304,
288,
3529,
275,
289,
8,
18,
9,
288,
291,
14,
70,
275,
2400,
671,
12,
612,
26,
3529,
8,
1144,
779,
88,
12,
612,
2459,
267,
587,
26,
288,
291,
14,
70,
275,
289,
398,
291,
14,
6833,
275,
7151,
267,
291,
14,
30995,
275,
3164,
1700,
267,
291,
14,
2894,
1302,
275,
7434,
1302,
267,
291,
14,
7977,
275,
519,
9925,
21601,
26,
28961,
26,
277,
14,
6833,
627,
413,
74,
61,
267,
291,
14,
588,
275,
519,
9925,
27429,
26,
30036,
26,
277,
14,
6833,
627,
413,
74,
61,
267,
291,
14,
31765,
275,
291,
423,
4208,
7562,
2956,
342,
267,
340,
892,
592,
26,
288,
291,
14,
592,
275,
9658,
342,
339,
347,
485,
4208,
7562,
2956,
8,
277,
304,
267,
408,
3550,
314,
805,
5542,
4171,
1338,
367,
314,
1453,
6068,
402,
671,
436,
612,
408,
267,
5322,
275,
10136,
1332,
552,
8,
277,
14,
7977,
395,
822,
8,
277,
14,
588,
1724,
267,
367,
284,
12,
671,
315,
3874,
8,
277,
14,
7977,
304,
288,
367,
1335,
12,
612,
315,
3874,
8,
277,
14,
588,
304,
355,
5322,
59,
74,
12,
284,
61,
275,
291,
14,
70,
8,
88,
12,
612,
9,
267,
372,
5322,
339,
347,
5137,
2422,
8,
277,
12,
11106,
29,
1400,
12,
22365,
29,
549,
304,
267,
408,
520,
498,
11106,
26,
4212,
5002,
5542,
4171,
11106,
1077,
506,
19341,
1041,
267,
3529,
275,
23176,
8,
277,
14,
7977,
12,
291,
14,
588,
12,
291,
14,
31765,
12,
11106,
9,
267,
340,
291,
14,
30995,
26,
288,
7434,
275,
3164,
1700,
8,
2791,
9,
288,
340,
291,
14,
2894,
1302,
1137,
488,
26,
355,
7434,
14,
409,
63,
1302,
8,
277,
14,
2894,
1302,
9,
398,
340,
22365,
26,
2498,
342,
339,
347,
1050,
27665,
8,
277,
12,
5845,
12,
522,
2357,
29,
549,
12,
3164,
9280,
267,
408,
2798,
2005,
2690,
4501,
641,
314,
5542,
4171,
20078,
3588,
14,
398,
520,
498,
522,
2357,
26,
1077,
314,
25174,
12271,
506,
19477,
31,
408,
267,
327,
3715,
5845,
1901,
671,
436,
612,
267,
23132,
275,
10136,
8,
552,
8,
3356,
430,
267,
1847,
275,
10136,
8,
552,
8,
3356,
430,
267,
367,
284,
12,
308,
315,
3874,
8,
3356,
304,
288,
23132,
59,
73,
61,
275,
308,
59,
16,
61,
288,
1847,
59,
73,
61,
275,
308,
59,
17,
61,
267,
340,
522,
2357,
26,
288,
291,
423,
470,
2357,
8,
827,
8,
12915,
395,
1390,
8,
12915,
395,
1748,
8,
1786,
395,
1390,
8,
1786,
430,
398,
5137,
8,
12915,
12,
1847,
12,
3164,
435,
6681,
358,
339,
347,
485,
470,
2357,
8,
277,
12,
22036,
12,
19906,
12,
22506,
12,
21023,
304,
267,
291,
14,
7977,
275,
519,
9925,
827,
8,
21601,
627,
413,
14,
17,
12,
1748,
8,
277,
14,
7977,
2298,
988,
8,
28961,
627,
413,
14,
17,
12,
1390,
8,
277,
14,
7977,
2298,
277,
14,
6833,
627,
413,
74,
61,
267,
291,
14,
588,
275,
519,
9925,
827,
8,
27429,
627,
413,
14,
17,
12,
1748,
8,
277,
14,
588,
2298,
988,
8,
30036,
627,
413,
14,
17,
12,
1390,
8,
277,
14,
588
] |
[
2005,
11420,
1233,
367,
14213,
590,
25174,
650,
36,
5935,
402,
805,
5542,
4171,
20078,
3588,
83,
14,
199,
199,
363,
2502,
363,
275,
283,
52,
676,
428,
9518,
348,
12,
370,
77,
32,
344,
10971,
14,
335,
7,
199,
199,
504,
7026,
492,
10136,
12,
519,
3131,
9794,
12,
9829,
12,
6682,
12,
1625,
12,
6308,
12,
7452,
12,
8348,
199,
504,
7026,
14,
10096,
492,
26937,
199,
504,
19199,
492,
9658,
12,
5137,
12,
2498,
12,
9364,
3825,
12,
23176,
12,
3354,
592,
12,
3164,
1700,
199,
504,
1134,
22246,
14,
4308,
14,
26411,
14,
5777,
492,
6801,
8263,
199,
504,
6485,
492,
365,
533,
421,
199,
318,
5137,
967,
86,
23525,
261,
8,
69,
569,
12,
8126,
12,
11998,
29,
1400,
12,
3164,
534,
89,
297,
7115,
681,
29,
17,
14,
304,
272,
408,
510,
4555,
282,
13263,
16028,
261,
14,
408,
272,
327,
4526,
282,
8526,
402,
4501,
641,
314,
16028,
261,
272,
444,
275,
10136,
8,
13879,
435,
413,
9,
272,
325,
89,
275,
10136,
8,
13879,
435,
413,
9,
272,
399,
12,
308,
12,
366,
275,
26937,
8,
69,
569,
9,
272,
4383,
275,
6308,
8,
68,
12,
6308,
8,
6706,
8,
5079,
8,
83,
1826,
399,
430,
272,
367,
284,
315,
1425,
8,
13879,
435,
413,
304,
267,
17990,
88,
275,
9794,
1332,
18,
627,
6682,
627,
284,
9,
1182,
2069,
8,
13879,
430,
267,
17990,
89,
275,
9829,
1332,
18,
627,
6682,
627,
284,
9,
1182,
2069,
8,
13879,
430,
267,
444,
59,
73,
61,
275,
8126,
59,
16,
61,
435,
4383,
59,
16,
12,
378,
61,
627,
17990,
88,
435,
4383,
59,
16,
12,
413,
61,
627,
17990,
89,
267,
325,
89,
59,
73,
61,
275,
8126,
59,
17,
61,
435,
4383,
59,
17,
12,
378,
61,
627,
17990,
88,
435,
4383,
59,
17,
12,
413,
61,
627,
17990,
89,
339,
327,
5137,
3062,
272,
5137,
779,
4218,
59,
16,
2365,
359,
4218,
59,
17,
2365,
32278,
3164,
29,
2326,
12,
5131,
29,
3936,
681,
9,
272,
5137,
8,
476,
12,
325,
89,
12,
17525,
3164,
29,
2326,
12,
5131,
29,
3936,
681,
9,
272,
372,
444,
12,
325,
89,
421,
199,
533,
481,
24531,
10711,
351,
26,
272,
408,
5137,
314,
805,
1159,
1338,
315,
314,
8626,
11572,
4897,
2013,
701,
12271,
14,
4885,
849,
12,
5137,
315,
5243,
17,
12,
17,
61,
408,
272,
347,
636,
826,
721,
277,
12,
289,
12,
22036,
29,
446,
17,
12,
19906,
29,
17,
12,
22506,
29,
446,
17,
12,
21023,
29,
17,
12,
7151,
29,
1400,
12,
892,
592,
29,
549,
12,
326,
3164,
1700,
29,
797,
12,
7434,
1302,
29,
403,
304,
267,
408,
520,
498,
7151,
26,
4212,
5002,
7124,
3180,
4036,
6240,
408,
267,
340,
1228,
8,
70,
12,
6801,
8263,
304,
288,
702,
289,
14,
88,
3572,
508,
499,
288,
291,
14,
70,
275,
2400,
671,
12,
612,
26,
289,
8,
1144,
779,
88,
12,
612,
2459,
267,
916,
365,
533,
8,
70,
9,
436,
11602,
8,
70,
12,
6801,
8263,
304,
288,
3529,
275,
289,
8,
18,
9,
288,
291,
14,
70,
275,
2400,
671,
12,
612,
26,
3529,
8,
1144,
779,
88,
12,
612,
2459,
267,
587,
26,
288,
291,
14,
70,
275,
289,
398,
291,
14,
6833,
275,
7151,
267,
291,
14,
30995,
275,
3164,
1700,
267,
291,
14,
2894,
1302,
275,
7434,
1302,
267,
291,
14,
7977,
275,
519,
9925,
21601,
26,
28961,
26,
277,
14,
6833,
627,
413,
74,
61,
267,
291,
14,
588,
275,
519,
9925,
27429,
26,
30036,
26,
277,
14,
6833,
627,
413,
74,
61,
267,
291,
14,
31765,
275,
291,
423,
4208,
7562,
2956,
342,
267,
340,
892,
592,
26,
288,
291,
14,
592,
275,
9658,
342,
339,
347,
485,
4208,
7562,
2956,
8,
277,
304,
267,
408,
3550,
314,
805,
5542,
4171,
1338,
367,
314,
1453,
6068,
402,
671,
436,
612,
408,
267,
5322,
275,
10136,
1332,
552,
8,
277,
14,
7977,
395,
822,
8,
277,
14,
588,
1724,
267,
367,
284,
12,
671,
315,
3874,
8,
277,
14,
7977,
304,
288,
367,
1335,
12,
612,
315,
3874,
8,
277,
14,
588,
304,
355,
5322,
59,
74,
12,
284,
61,
275,
291,
14,
70,
8,
88,
12,
612,
9,
267,
372,
5322,
339,
347,
5137,
2422,
8,
277,
12,
11106,
29,
1400,
12,
22365,
29,
549,
304,
267,
408,
520,
498,
11106,
26,
4212,
5002,
5542,
4171,
11106,
1077,
506,
19341,
1041,
267,
3529,
275,
23176,
8,
277,
14,
7977,
12,
291,
14,
588,
12,
291,
14,
31765,
12,
11106,
9,
267,
340,
291,
14,
30995,
26,
288,
7434,
275,
3164,
1700,
8,
2791,
9,
288,
340,
291,
14,
2894,
1302,
1137,
488,
26,
355,
7434,
14,
409,
63,
1302,
8,
277,
14,
2894,
1302,
9,
398,
340,
22365,
26,
2498,
342,
339,
347,
1050,
27665,
8,
277,
12,
5845,
12,
522,
2357,
29,
549,
12,
3164,
9280,
267,
408,
2798,
2005,
2690,
4501,
641,
314,
5542,
4171,
20078,
3588,
14,
398,
520,
498,
522,
2357,
26,
1077,
314,
25174,
12271,
506,
19477,
31,
408,
267,
327,
3715,
5845,
1901,
671,
436,
612,
267,
23132,
275,
10136,
8,
552,
8,
3356,
430,
267,
1847,
275,
10136,
8,
552,
8,
3356,
430,
267,
367,
284,
12,
308,
315,
3874,
8,
3356,
304,
288,
23132,
59,
73,
61,
275,
308,
59,
16,
61,
288,
1847,
59,
73,
61,
275,
308,
59,
17,
61,
267,
340,
522,
2357,
26,
288,
291,
423,
470,
2357,
8,
827,
8,
12915,
395,
1390,
8,
12915,
395,
1748,
8,
1786,
395,
1390,
8,
1786,
430,
398,
5137,
8,
12915,
12,
1847,
12,
3164,
435,
6681,
358,
339,
347,
485,
470,
2357,
8,
277,
12,
22036,
12,
19906,
12,
22506,
12,
21023,
304,
267,
291,
14,
7977,
275,
519,
9925,
827,
8,
21601,
627,
413,
14,
17,
12,
1748,
8,
277,
14,
7977,
2298,
988,
8,
28961,
627,
413,
14,
17,
12,
1390,
8,
277,
14,
7977,
2298,
277,
14,
6833,
627,
413,
74,
61,
267,
291,
14,
588,
275,
519,
9925,
827,
8,
27429,
627,
413,
14,
17,
12,
1748,
8,
277,
14,
588,
2298,
988,
8,
30036,
627,
413,
14,
17,
12,
1390,
8,
277,
14,
588,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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Coupling.py
|
1
|
5341
|
__all__ = ['calculate_couplings_3points', 'calculate_couplings_levine',
'compute_overlaps_for_coupling', 'correct_phases']
from compute_integrals import compute_integrals_couplings
from nac.common import (
Matrix, Tensor3D, retrieve_hdf5_data, tuplesXYZ_to_plams)
from os.path import join
import numpy as np
import os
import uuid
def calculate_couplings_3points(
dt: float, mtx_sji_t0: Matrix, mtx_sij_t0: Matrix,
mtx_sji_t1: Matrix, mtx_sij_t1: Matrix) -> None:
"""
Calculate the non-adiabatic interaction matrix using 3 geometries,
the CGFs for the atoms and molecular orbitals coefficients read
from a HDF5 File.
"""
cte = 1.0 / (4.0 * dt)
return cte * (3 * (mtx_sji_t1 - mtx_sij_t1) + (mtx_sij_t0 - mtx_sji_t0))
def calculate_couplings_levine(dt: float, w_jk: Matrix,
w_kj: Matrix) -> Matrix:
"""
Compute the non-adiabatic coupling according to:
`Evaluation of the Time-Derivative Coupling for Accurate Electronic
State Transition Probabilities from Numerical Simulations`.
Garrett A. Meek and Benjamin G. Levine.
dx.doi.org/10.1021/jz5009449 | J. Phys. Chem. Lett. 2014, 5, 2351−2356
NOTE:
In numpy sinc is defined as sin(pi * x) / (pi * x)
"""
# Diagonal matrix
w_jj = np.diag(np.diag(w_jk))
w_kk = np.diag(np.diag(w_kj))
# remove the values from the diagonal
np.fill_diagonal(w_jk, 0)
np.fill_diagonal(w_kj, 0)
# Components A + B
acos_w_jj = np.arccos(w_jj)
asin_w_jk = np.arcsin(w_jk)
a = acos_w_jj - asin_w_jk
b = acos_w_jj + asin_w_jk
A = - np.sinc(a / np.pi)
B = np.sinc(b / np.pi)
# Components C + D
acos_w_kk = np.arccos(w_kk)
asin_w_kj = np.arcsin(w_kj)
c = acos_w_kk - asin_w_kj
d = acos_w_kk + asin_w_kj
C = np.sinc(c / np.pi)
D = np.sinc(d / np.pi)
# Components E
w_lj = np.sqrt(1 - (w_jj ** 2) - (w_kj ** 2))
w_lk = -(w_jk * w_jj + w_kk * w_kj) / w_lj
asin_w_lj = np.arcsin(w_lj)
asin_w_lk = np.arcsin(w_lk)
asin_w_lj2 = asin_w_lj ** 2
asin_w_lk2 = asin_w_lk ** 2
t1 = w_lj * w_lk * asin_w_lj
x1 = np.sqrt((1 - w_lj ** 2) * (1 - w_lk ** 2)) - 1
t2 = x1 * asin_w_lk
t = t1 + t2
E_nonzero = 2 * asin_w_lj * t / (asin_w_lj2 - asin_w_lk2)
# Check whether w_lj is different of zero
E1 = np.where(np.abs(w_lj) > 1e-8, E_nonzero, np.zeros(A.shape))
# Check whether w_lj is different of zero
E = np.where(np.isclose(asin_w_lj2, asin_w_lk2), w_lj ** 2, E1)
cte = 1 / (2 * dt)
return cte * (np.arccos(w_jj) * (A + B) + np.arcsin(w_kj) * (C + D) + E)
def correct_phases(overlaps: Tensor3D, mtx_phases: Matrix) -> list:
"""
Correct the phases for all the overlaps
"""
nOverlaps = overlaps.shape[0] # total number of overlap matrices
dim = overlaps.shape[1] # Size of the square matrix
for k in range(nOverlaps):
# Extract phases
phases_t0, phases_t1 = mtx_phases[k: k + 2]
phases_t0 = phases_t0.reshape(dim, 1)
phases_t1 = phases_t1.reshape(1, dim)
mtx_phases_Sji_t0_t1 = np.dot(phases_t0, phases_t1)
# Update array with the fixed phases
overlaps[k] *= mtx_phases_Sji_t0_t1
return overlaps
def compute_overlaps_for_coupling(
config: dict, pair_molecules: tuple, coefficients: tuple) -> tuple:
"""
Compute the Overlap matrices used to compute the couplings
:returns: [Matrix] containing the overlaps at different times
"""
# Atomic orbitals overlap
suv = calcOverlapMtx(config, pair_molecules)
# Read Orbitals Coefficients
css0, css1 = coefficients
return np.dot(css0.T, np.dot(suv, css1))
def read_overlap_data(config: dict, mo_paths: list) -> tuple:
"""
Read the Molecular orbital coefficients and the transformation matrix
"""
mos = retrieve_hdf5_data(config.path_hdf5, mo_paths)
# Extract a subset of molecular orbitals to compute the coupling
lowest, highest = compute_range_orbitals(config)
css0, css1 = tuple(map(lambda xs: xs[:, lowest: highest], mos))
return css0, css1
def compute_range_orbitals(config: dict) -> tuple:
"""
Compute the lowest and highest index used to extract
a subset of Columns from the MOs
"""
lowest = config.nHOMO - (config.mo_index_range[0] + config.active_space[0])
highest = config.nHOMO + config.active_space[1] - config.mo_index_range[0]
return lowest, highest
def calcOverlapMtx(config: dict, molecules: tuple) -> Matrix:
"""
Parallel calculation of the overlap matrix using the libint2 library
at two different geometries: R0 and R1.
"""
mol_i, mol_j = tuple(tuplesXYZ_to_plams(x) for x in molecules)
# unique molecular paths
path_i = join(config["scratch_path"],
f"molecule_{uuid.uuid4()}.xyz")
path_j = join(config["scratch_path"],
"molecule_{uuid.uuid4()}.xyz")
# Write the molecules in atomic units
mol_i.write(path_i)
mol_j.write(path_j)
basis_name = config["cp2k_general_settings"]["basis"]
try:
integrals = compute_integrals_couplings(
path_i, path_j, config["path_hdf5"], basis_name)
finally:
os.remove(path_i)
os.remove(path_j)
return integrals
|
mit
|
[
363,
452,
363,
275,
788,
12063,
63,
331,
384,
24910,
63,
19,
3438,
297,
283,
12063,
63,
331,
384,
24910,
63,
6972,
1132,
297,
1779,
283,
3357,
63,
20798,
63,
509,
63,
331,
384,
2983,
297,
283,
4525,
63,
14236,
418,
199,
199,
504,
4526,
63,
25323,
2551,
492,
4526,
63,
25323,
2551,
63,
331,
384,
24910,
199,
504,
302,
645,
14,
2330,
492,
334,
272,
8449,
12,
5878,
19,
36,
12,
8044,
63,
19912,
21,
63,
576,
12,
6346,
16694,
63,
475,
63,
80,
416,
706,
9,
199,
504,
747,
14,
515,
492,
4263,
199,
646,
2680,
465,
980,
199,
646,
747,
199,
646,
5377,
421,
199,
318,
8671,
63,
331,
384,
24910,
63,
19,
3438,
8,
267,
4487,
26,
2069,
12,
333,
2347,
63,
83,
8047,
63,
84,
16,
26,
8449,
12,
333,
2347,
63,
338,
74,
63,
84,
16,
26,
8449,
12,
267,
333,
2347,
63,
83,
8047,
63,
84,
17,
26,
8449,
12,
333,
2347,
63,
338,
74,
63,
84,
17,
26,
8449,
9,
1035,
488,
26,
272,
408,
272,
12707,
314,
2222,
13,
65,
328,
20338,
764,
18752,
3634,
1808,
650,
24883,
12,
272,
314,
445,
17395,
83,
367,
314,
14503,
436,
1303,
10251,
2238,
503,
2075,
2551,
12343,
1586,
272,
687,
282,
24521,
21,
3814,
14,
272,
408,
272,
286,
266,
275,
413,
14,
16,
1182,
334,
20,
14,
16,
627,
4487,
9,
272,
372,
286,
266,
627,
334,
19,
627,
334,
26029,
63,
83,
8047,
63,
84,
17,
446,
333,
2347,
63,
338,
74,
63,
84,
17,
9,
435,
334,
26029,
63,
338,
74,
63,
84,
16,
446,
333,
2347,
63,
83,
8047,
63,
84,
16,
430,
421,
199,
318,
8671,
63,
331,
384,
24910,
63,
6972,
1132,
8,
3583,
26,
2069,
12,
336,
63,
17421,
26,
8449,
12,
3044,
336,
63,
25775,
26,
8449,
9,
1035,
8449,
26,
272,
408,
272,
8354,
314,
2222,
13,
65,
328,
20338,
764,
512,
384,
2983,
7182,
370,
26,
272,
658,
29786,
402,
314,
4703,
13,
17793,
27418,
1849,
384,
2983,
367,
4473,
19471,
662,
16728,
530,
272,
8511,
19894,
1588,
22770,
5807,
687,
653,
27685,
10751,
21429,
2313,
272,
598,
285,
3292,
84,
437,
14,
603,
4374,
436,
26844,
16997,
262,
598,
14,
491,
6857,
1132,
14,
272,
11868,
14,
27334,
14,
1308,
15,
709,
14,
709,
2025,
15,
74,
90,
5783,
25,
19738,
1204,
1603,
14,
11308,
588,
14,
445,
27037,
14,
12230,
84,
14,
6927,
12,
959,
12,
499,
16860,
159,
231,
241,
8276,
22,
339,
6944,
26,
1362,
1010,
2680,
308,
6559,
365,
3247,
465,
9829,
8,
1038,
627,
671,
9,
1182,
334,
1038,
627,
671,
9,
272,
408,
339,
327,
3757,
643,
8125,
3634,
272,
336,
63,
12098,
275,
980,
14,
6706,
8,
1590,
14,
6706,
8,
87,
63,
17421,
430,
272,
336,
63,
16247,
275,
980,
14,
6706,
8,
1590,
14,
6706,
8,
87,
63,
25775,
430,
339,
327,
2813,
314,
1338,
687,
314,
16788,
272,
980,
14,
4498,
63,
20057,
8,
87,
63,
17421,
12,
378,
9,
272,
980,
14,
4498,
63,
20057,
8,
87,
63,
25775,
12,
378,
9,
339,
327,
17823,
437,
435,
699,
272,
282,
5197,
63,
87,
63,
12098,
275,
980,
14,
9912,
5197,
8,
87,
63,
12098,
9,
272,
465,
262,
63,
87,
63,
17421,
275,
980,
14,
20672,
262,
8,
87,
63,
17421,
9,
339,
282,
275,
282,
5197,
63,
87,
63,
12098,
446,
465,
262,
63,
87,
63,
17421,
272,
330,
275,
282,
5197,
63,
87,
63,
12098,
435,
465,
262,
63,
87,
63,
17421,
272,
437,
275,
446,
980,
14,
5911,
67,
8,
65,
1182,
980,
14,
1038,
9,
272,
699,
275,
980,
14,
5911,
67,
8,
66,
1182,
980,
14,
1038,
9,
339,
327,
17823,
445,
435,
577,
272,
282,
5197,
63,
87,
63,
16247,
275,
980,
14,
9912,
5197,
8,
87,
63,
16247,
9,
272,
465,
262,
63,
87,
63,
25775,
275,
980,
14,
20672,
262,
8,
87,
63,
25775,
9,
339,
286,
275,
282,
5197,
63,
87,
63,
16247,
446,
465,
262,
63,
87,
63,
25775,
272,
366,
275,
282,
5197,
63,
87,
63,
16247,
435,
465,
262,
63,
87,
63,
25775,
272,
445,
275,
980,
14,
5911,
67,
8,
67,
1182,
980,
14,
1038,
9,
272,
577,
275,
980,
14,
5911,
67,
8,
68,
1182,
980,
14,
1038,
9,
339,
327,
17823,
662,
272,
336,
63,
31025,
275,
980,
14,
5079,
8,
17,
446,
334,
87,
63,
12098,
1011,
499,
9,
446,
334,
87,
63,
25775,
1011,
499,
430,
272,
336,
63,
23333,
275,
24953,
87,
63,
17421,
627,
336,
63,
12098,
435,
336,
63,
16247,
627,
336,
63,
25775,
9,
1182,
336,
63,
31025,
272,
465,
262,
63,
87,
63,
31025,
275,
980,
14,
20672,
262,
8,
87,
63,
31025,
9,
272,
465,
262,
63,
87,
63,
23333,
275,
980,
14,
20672,
262,
8,
87,
63,
23333,
9,
272,
465,
262,
63,
87,
63,
31025,
18,
275,
465,
262,
63,
87,
63,
31025,
1011,
499,
272,
465,
262,
63,
87,
63,
23333,
18,
275,
465,
262,
63,
87,
63,
23333,
1011,
499,
339,
307,
17,
275,
336,
63,
31025,
627,
336,
63,
23333,
627,
465,
262,
63,
87,
63,
31025,
272,
671,
17,
275,
980,
14,
5079,
1332,
17,
446,
336,
63,
31025,
1011,
499,
9,
627,
334,
17,
446,
336,
63,
23333,
1011,
499,
430,
446,
413,
272,
307,
18,
275,
671,
17,
627,
465,
262,
63,
87,
63,
23333,
272,
307,
275,
307,
17,
435,
307,
18,
272,
662,
63,
10262,
275,
499,
627,
465,
262,
63,
87,
63,
31025,
627,
307,
1182,
334,
24202,
63,
87,
63,
31025,
18,
446,
465,
262,
63,
87,
63,
23333,
18,
9,
339,
327,
2670,
3775,
336,
63,
31025,
365,
3365,
402,
4697,
272,
662,
17,
275,
980,
14,
4509,
8,
1590,
14,
2101,
8,
87,
63,
31025,
9,
690,
413,
69,
13,
24,
12,
662,
63,
10262,
12,
980,
14,
4250,
8,
33,
14,
1392,
430,
339,
327,
2670,
3775,
336,
63,
31025,
365,
3365,
402,
4697,
272,
662,
275,
980,
14,
4509,
8,
1590,
14,
31899,
8,
24202,
63,
87,
63,
31025,
18,
12,
465,
262,
63,
87,
63,
23333,
18,
395,
336,
63,
31025,
1011,
499,
12,
662
] |
[
452,
363,
275,
788,
12063,
63,
331,
384,
24910,
63,
19,
3438,
297,
283,
12063,
63,
331,
384,
24910,
63,
6972,
1132,
297,
1779,
283,
3357,
63,
20798,
63,
509,
63,
331,
384,
2983,
297,
283,
4525,
63,
14236,
418,
199,
199,
504,
4526,
63,
25323,
2551,
492,
4526,
63,
25323,
2551,
63,
331,
384,
24910,
199,
504,
302,
645,
14,
2330,
492,
334,
272,
8449,
12,
5878,
19,
36,
12,
8044,
63,
19912,
21,
63,
576,
12,
6346,
16694,
63,
475,
63,
80,
416,
706,
9,
199,
504,
747,
14,
515,
492,
4263,
199,
646,
2680,
465,
980,
199,
646,
747,
199,
646,
5377,
421,
199,
318,
8671,
63,
331,
384,
24910,
63,
19,
3438,
8,
267,
4487,
26,
2069,
12,
333,
2347,
63,
83,
8047,
63,
84,
16,
26,
8449,
12,
333,
2347,
63,
338,
74,
63,
84,
16,
26,
8449,
12,
267,
333,
2347,
63,
83,
8047,
63,
84,
17,
26,
8449,
12,
333,
2347,
63,
338,
74,
63,
84,
17,
26,
8449,
9,
1035,
488,
26,
272,
408,
272,
12707,
314,
2222,
13,
65,
328,
20338,
764,
18752,
3634,
1808,
650,
24883,
12,
272,
314,
445,
17395,
83,
367,
314,
14503,
436,
1303,
10251,
2238,
503,
2075,
2551,
12343,
1586,
272,
687,
282,
24521,
21,
3814,
14,
272,
408,
272,
286,
266,
275,
413,
14,
16,
1182,
334,
20,
14,
16,
627,
4487,
9,
272,
372,
286,
266,
627,
334,
19,
627,
334,
26029,
63,
83,
8047,
63,
84,
17,
446,
333,
2347,
63,
338,
74,
63,
84,
17,
9,
435,
334,
26029,
63,
338,
74,
63,
84,
16,
446,
333,
2347,
63,
83,
8047,
63,
84,
16,
430,
421,
199,
318,
8671,
63,
331,
384,
24910,
63,
6972,
1132,
8,
3583,
26,
2069,
12,
336,
63,
17421,
26,
8449,
12,
3044,
336,
63,
25775,
26,
8449,
9,
1035,
8449,
26,
272,
408,
272,
8354,
314,
2222,
13,
65,
328,
20338,
764,
512,
384,
2983,
7182,
370,
26,
272,
658,
29786,
402,
314,
4703,
13,
17793,
27418,
1849,
384,
2983,
367,
4473,
19471,
662,
16728,
530,
272,
8511,
19894,
1588,
22770,
5807,
687,
653,
27685,
10751,
21429,
2313,
272,
598,
285,
3292,
84,
437,
14,
603,
4374,
436,
26844,
16997,
262,
598,
14,
491,
6857,
1132,
14,
272,
11868,
14,
27334,
14,
1308,
15,
709,
14,
709,
2025,
15,
74,
90,
5783,
25,
19738,
1204,
1603,
14,
11308,
588,
14,
445,
27037,
14,
12230,
84,
14,
6927,
12,
959,
12,
499,
16860,
159,
231,
241,
8276,
22,
339,
6944,
26,
1362,
1010,
2680,
308,
6559,
365,
3247,
465,
9829,
8,
1038,
627,
671,
9,
1182,
334,
1038,
627,
671,
9,
272,
408,
339,
327,
3757,
643,
8125,
3634,
272,
336,
63,
12098,
275,
980,
14,
6706,
8,
1590,
14,
6706,
8,
87,
63,
17421,
430,
272,
336,
63,
16247,
275,
980,
14,
6706,
8,
1590,
14,
6706,
8,
87,
63,
25775,
430,
339,
327,
2813,
314,
1338,
687,
314,
16788,
272,
980,
14,
4498,
63,
20057,
8,
87,
63,
17421,
12,
378,
9,
272,
980,
14,
4498,
63,
20057,
8,
87,
63,
25775,
12,
378,
9,
339,
327,
17823,
437,
435,
699,
272,
282,
5197,
63,
87,
63,
12098,
275,
980,
14,
9912,
5197,
8,
87,
63,
12098,
9,
272,
465,
262,
63,
87,
63,
17421,
275,
980,
14,
20672,
262,
8,
87,
63,
17421,
9,
339,
282,
275,
282,
5197,
63,
87,
63,
12098,
446,
465,
262,
63,
87,
63,
17421,
272,
330,
275,
282,
5197,
63,
87,
63,
12098,
435,
465,
262,
63,
87,
63,
17421,
272,
437,
275,
446,
980,
14,
5911,
67,
8,
65,
1182,
980,
14,
1038,
9,
272,
699,
275,
980,
14,
5911,
67,
8,
66,
1182,
980,
14,
1038,
9,
339,
327,
17823,
445,
435,
577,
272,
282,
5197,
63,
87,
63,
16247,
275,
980,
14,
9912,
5197,
8,
87,
63,
16247,
9,
272,
465,
262,
63,
87,
63,
25775,
275,
980,
14,
20672,
262,
8,
87,
63,
25775,
9,
339,
286,
275,
282,
5197,
63,
87,
63,
16247,
446,
465,
262,
63,
87,
63,
25775,
272,
366,
275,
282,
5197,
63,
87,
63,
16247,
435,
465,
262,
63,
87,
63,
25775,
272,
445,
275,
980,
14,
5911,
67,
8,
67,
1182,
980,
14,
1038,
9,
272,
577,
275,
980,
14,
5911,
67,
8,
68,
1182,
980,
14,
1038,
9,
339,
327,
17823,
662,
272,
336,
63,
31025,
275,
980,
14,
5079,
8,
17,
446,
334,
87,
63,
12098,
1011,
499,
9,
446,
334,
87,
63,
25775,
1011,
499,
430,
272,
336,
63,
23333,
275,
24953,
87,
63,
17421,
627,
336,
63,
12098,
435,
336,
63,
16247,
627,
336,
63,
25775,
9,
1182,
336,
63,
31025,
272,
465,
262,
63,
87,
63,
31025,
275,
980,
14,
20672,
262,
8,
87,
63,
31025,
9,
272,
465,
262,
63,
87,
63,
23333,
275,
980,
14,
20672,
262,
8,
87,
63,
23333,
9,
272,
465,
262,
63,
87,
63,
31025,
18,
275,
465,
262,
63,
87,
63,
31025,
1011,
499,
272,
465,
262,
63,
87,
63,
23333,
18,
275,
465,
262,
63,
87,
63,
23333,
1011,
499,
339,
307,
17,
275,
336,
63,
31025,
627,
336,
63,
23333,
627,
465,
262,
63,
87,
63,
31025,
272,
671,
17,
275,
980,
14,
5079,
1332,
17,
446,
336,
63,
31025,
1011,
499,
9,
627,
334,
17,
446,
336,
63,
23333,
1011,
499,
430,
446,
413,
272,
307,
18,
275,
671,
17,
627,
465,
262,
63,
87,
63,
23333,
272,
307,
275,
307,
17,
435,
307,
18,
272,
662,
63,
10262,
275,
499,
627,
465,
262,
63,
87,
63,
31025,
627,
307,
1182,
334,
24202,
63,
87,
63,
31025,
18,
446,
465,
262,
63,
87,
63,
23333,
18,
9,
339,
327,
2670,
3775,
336,
63,
31025,
365,
3365,
402,
4697,
272,
662,
17,
275,
980,
14,
4509,
8,
1590,
14,
2101,
8,
87,
63,
31025,
9,
690,
413,
69,
13,
24,
12,
662,
63,
10262,
12,
980,
14,
4250,
8,
33,
14,
1392,
430,
339,
327,
2670,
3775,
336,
63,
31025,
365,
3365,
402,
4697,
272,
662,
275,
980,
14,
4509,
8,
1590,
14,
31899,
8,
24202,
63,
87,
63,
31025,
18,
12,
465,
262,
63,
87,
63,
23333,
18,
395,
336,
63,
31025,
1011,
499,
12,
662,
0
] |
[
1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
evamwangi/bc-7-Todo_List
|
venv/Lib/encodings/hex_codec.py
|
528
|
2309
|
""" Python 'hex_codec' Codec - 2-digit hex content transfer encoding
Unlike most of the other codecs which target Unicode, this codec
will return Python string objects for both encode and decode.
Written by Marc-Andre Lemburg (mal@lemburg.com).
"""
import codecs, binascii
### Codec APIs
def hex_encode(input,errors='strict'):
""" Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
output = binascii.b2a_hex(input)
return (output, len(input))
def hex_decode(input,errors='strict'):
""" Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error handling to apply. It defaults to
'strict' handling which is the only currently supported
error handling for this codec.
"""
assert errors == 'strict'
output = binascii.a2b_hex(input)
return (output, len(input))
class Codec(codecs.Codec):
def encode(self, input,errors='strict'):
return hex_encode(input,errors)
def decode(self, input,errors='strict'):
return hex_decode(input,errors)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
assert self.errors == 'strict'
return binascii.b2a_hex(input)
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
assert self.errors == 'strict'
return binascii.a2b_hex(input)
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='hex',
encode=hex_encode,
decode=hex_decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamwriter=StreamWriter,
streamreader=StreamReader,
)
|
mit
|
[
624,
2018,
283,
4097,
63,
9276,
7,
13732,
446,
499,
13,
8573,
6318,
1564,
9307,
2644,
339,
25059,
4750,
402,
314,
1163,
6010,
1314,
1347,
6140,
12,
642,
9076,
272,
911,
372,
2018,
1059,
2251,
367,
3865,
3752,
436,
4849,
14,
339,
27694,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
624,
199,
646,
6010,
12,
14755,
199,
199,
5680,
13732,
15913,
199,
199,
318,
6318,
63,
2143,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
14755,
14,
66,
18,
65,
63,
4097,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
318,
6318,
63,
2708,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
1487,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
1324,
1471,
506,
376,
909,
1314,
6571,
314,
18839,
63,
362,
739,
1436,
267,
3335,
9348,
14,
2018,
3326,
12,
3335,
2251,
436,
4402,
267,
9994,
1584,
787,
7251,
402,
2251,
13070,
642,
9348,
14,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
14755,
14,
65,
18,
66,
63,
4097,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1324,
12,
2550,
534,
4768,
735,
267,
372,
6318,
63,
2143,
8,
1210,
12,
2550,
9,
272,
347,
4849,
8,
277,
12,
1324,
12,
2550,
534,
4768,
735,
267,
372,
6318,
63,
2708,
8,
1210,
12,
2550,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
702,
291,
14,
2550,
508,
283,
4768,
7,
267,
372,
14755,
14,
66,
18,
65,
63,
4097,
8,
1210,
9,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
702,
291,
14,
2550,
508,
283,
4768,
7,
267,
372,
14755,
14,
65,
18,
66,
63,
4097,
8,
1210,
9,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
4097,
297,
267,
3752,
29,
4097,
63,
2143,
12,
267,
4849,
29,
4097,
63,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26112,
29,
16551,
12,
267,
26101,
29,
16132,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
4097,
63,
9276,
7,
13732,
446,
499,
13,
8573,
6318,
1564,
9307,
2644,
339,
25059,
4750,
402,
314,
1163,
6010,
1314,
1347,
6140,
12,
642,
9076,
272,
911,
372,
2018,
1059,
2251,
367,
3865,
3752,
436,
4849,
14,
339,
27694,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
624,
199,
646,
6010,
12,
14755,
199,
199,
5680,
13732,
15913,
199,
199,
318,
6318,
63,
2143,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
3447,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
14755,
14,
66,
18,
65,
63,
4097,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
318,
6318,
63,
2708,
8,
1210,
12,
2550,
534,
4768,
735,
339,
408,
1487,
6021,
314,
909,
1324,
436,
2529,
282,
2008,
334,
1199,
267,
909,
12,
2582,
16949,
680,
398,
1324,
1471,
506,
376,
909,
1314,
6571,
314,
18839,
63,
362,
739,
1436,
267,
3335,
9348,
14,
2018,
3326,
12,
3335,
2251,
436,
4402,
267,
9994,
1584,
787,
7251,
402,
2251,
13070,
642,
9348,
14,
398,
2552,
7890,
314,
1125,
7252,
370,
4838,
14,
2779,
4243,
370,
267,
283,
4768,
7,
7252,
1314,
365,
314,
1454,
5544,
3748,
267,
1125,
7252,
367,
642,
9076,
14,
339,
408,
272,
702,
2552,
508,
283,
4768,
7,
272,
1072,
275,
14755,
14,
65,
18,
66,
63,
4097,
8,
1210,
9,
272,
372,
334,
1199,
12,
822,
8,
1210,
430,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1324,
12,
2550,
534,
4768,
735,
267,
372,
6318,
63,
2143,
8,
1210,
12,
2550,
9,
272,
347,
4849,
8,
277,
12,
1324,
12,
2550,
534,
4768,
735,
267,
372,
6318,
63,
2708,
8,
1210,
12,
2550,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
702,
291,
14,
2550,
508,
283,
4768,
7,
267,
372,
14755,
14,
66,
18,
65,
63,
4097,
8,
1210,
9,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
702,
291,
14,
2550,
508,
283,
4768,
7,
267,
372,
14755,
14,
65,
18,
66,
63,
4097,
8,
1210,
9,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
4097,
297,
267,
3752,
29,
4097,
63,
2143,
12,
267,
4849,
29,
4097,
63,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26112,
29,
16551,
12,
267,
26101,
29,
16132,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fnordahl/nova
|
nova/tests/unit/virt/libvirt/storage/test_rbd.py
|
12
|
13996
|
# 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 mock
from oslo_log import log as logging
from nova import exception
from nova import objects
from nova import test
from nova import utils
from nova.virt.libvirt.storage import rbd_utils
LOG = logging.getLogger(__name__)
CEPH_MON_DUMP = """dumped monmap epoch 1
{ "epoch": 1,
"fsid": "33630410-6d93-4d66-8e42-3b953cf194aa",
"modified": "2013-05-22 17:44:56.343618",
"created": "2013-05-22 17:44:56.343618",
"mons": [
{ "rank": 0,
"name": "a",
"addr": "[::1]:6789\/0"},
{ "rank": 1,
"name": "b",
"addr": "[::1]:6790\/0"},
{ "rank": 2,
"name": "c",
"addr": "[::1]:6791\/0"},
{ "rank": 3,
"name": "d",
"addr": "127.0.0.1:6792\/0"},
{ "rank": 4,
"name": "e",
"addr": "example.com:6791\/0"}],
"quorum": [
0,
1,
2]}
"""
class RbdTestCase(test.NoDBTestCase):
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def setUp(self, mock_rados, mock_rbd):
super(RbdTestCase, self).setUp()
self.mock_rados = mock_rados
self.mock_rados.Rados = mock.Mock
self.mock_rados.Rados.ioctx = mock.Mock()
self.mock_rados.Rados.connect = mock.Mock()
self.mock_rados.Rados.shutdown = mock.Mock()
self.mock_rados.Rados.open_ioctx = mock.Mock()
self.mock_rados.Rados.open_ioctx.return_value = \
self.mock_rados.Rados.ioctx
self.mock_rados.Error = Exception
self.mock_rbd = mock_rbd
self.mock_rbd.RBD = mock.Mock
self.mock_rbd.Image = mock.Mock
self.mock_rbd.Image.close = mock.Mock()
self.mock_rbd.RBD.Error = Exception
self.rbd_pool = 'rbd'
self.driver = rbd_utils.RBDDriver(self.rbd_pool, None, None)
self.volume_name = u'volume-00000001'
def tearDown(self):
super(RbdTestCase, self).tearDown()
def test_good_locations(self):
locations = ['rbd://fsid/pool/image/snap',
'rbd://%2F/%2F/%2F/%2F', ]
map(self.driver.parse_url, locations)
def test_bad_locations(self):
locations = ['rbd://image',
'http://path/to/somewhere/else',
'rbd://image/extra',
'rbd://image/',
'rbd://fsid/pool/image/',
'rbd://fsid/pool/image/snap/',
'rbd://///', ]
image_meta = objects.ImageMeta.from_dict({'disk_format': 'raw'})
for loc in locations:
self.assertRaises(exception.ImageUnacceptable,
self.driver.parse_url, loc)
self.assertFalse(self.driver.is_cloneable({'url': loc},
image_meta))
@mock.patch.object(rbd_utils.RBDDriver, '_get_fsid')
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_cloneable(self, mock_rados, mock_rbd, mock_get_fsid):
mock_get_fsid.return_value = 'abc'
location = {'url': 'rbd://abc/pool/image/snap'}
image_meta = objects.ImageMeta.from_dict({'disk_format': 'raw'})
self.assertTrue(self.driver.is_cloneable(location, image_meta))
self.assertTrue(mock_get_fsid.called)
@mock.patch.object(rbd_utils.RBDDriver, '_get_fsid')
def test_uncloneable_different_fsid(self, mock_get_fsid):
mock_get_fsid.return_value = 'abc'
location = {'url': 'rbd://def/pool/image/snap'}
image_meta = objects.ImageMeta.from_dict({'disk_format': 'raw'})
self.assertFalse(
self.driver.is_cloneable(location, image_meta))
self.assertTrue(mock_get_fsid.called)
@mock.patch.object(rbd_utils.RBDDriver, '_get_fsid')
@mock.patch.object(rbd_utils, 'RBDVolumeProxy')
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_uncloneable_unreadable(self, mock_rados, mock_rbd, mock_proxy,
mock_get_fsid):
mock_get_fsid.return_value = 'abc'
location = {'url': 'rbd://abc/pool/image/snap'}
mock_proxy.side_effect = mock_rbd.Error
image_meta = objects.ImageMeta.from_dict({'disk_format': 'raw'})
self.assertFalse(
self.driver.is_cloneable(location, image_meta))
mock_proxy.assert_called_once_with(self.driver, 'image', pool='pool',
snapshot='snap', read_only=True)
self.assertTrue(mock_get_fsid.called)
@mock.patch.object(rbd_utils.RBDDriver, '_get_fsid')
def test_uncloneable_bad_format(self, mock_get_fsid):
mock_get_fsid.return_value = 'abc'
location = {'url': 'rbd://abc/pool/image/snap'}
formats = ['qcow2', 'vmdk', 'vdi']
for f in formats:
image_meta = objects.ImageMeta.from_dict({'disk_format': f})
self.assertFalse(
self.driver.is_cloneable(location, image_meta))
self.assertTrue(mock_get_fsid.called)
@mock.patch.object(utils, 'execute')
def test_get_mon_addrs(self, mock_execute):
mock_execute.return_value = (CEPH_MON_DUMP, '')
hosts = ['::1', '::1', '::1', '127.0.0.1', 'example.com']
ports = ['6789', '6790', '6791', '6792', '6791']
self.assertEqual((hosts, ports), self.driver.get_mon_addrs())
@mock.patch.object(rbd_utils.RBDDriver, '_connect_to_rados')
@mock.patch.object(rbd_utils, 'rbd')
def test_rbd_conf_features(self, mock_rbd, mock_connect):
mock_rbd.RBD_FEATURE_LAYERING = 1
mock_cluster = mock.Mock()
mock_cluster.conf_get = mock.Mock()
mock_cluster.conf_get.return_value = None
mock_connect.return_value = (mock_cluster, None)
client = rbd_utils.RADOSClient(self.driver)
self.assertEqual(1, client.features)
mock_cluster.conf_get.return_value = '2'
self.assertEqual(2, client.features)
@mock.patch.object(rbd_utils, 'RADOSClient')
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_clone(self, mock_rados, mock_rbd, mock_client):
pool = u'images'
image = u'image-name'
snap = u'snapshot-name'
location = {'url': u'rbd://fsid/%s/%s/%s' % (pool, image, snap)}
client_stack = []
def mock__enter__(inst):
def _inner():
client_stack.append(inst)
return inst
return _inner
client = mock_client.return_value
# capture both rados client used to perform the clone
client.__enter__.side_effect = mock__enter__(client)
rbd = mock_rbd.RBD.return_value
self.driver.clone(location, self.volume_name)
args = [client_stack[0].ioctx, str(image), str(snap),
client_stack[1].ioctx, str(self.volume_name)]
kwargs = {'features': client.features}
rbd.clone.assert_called_once_with(*args, **kwargs)
self.assertEqual(2, client.__enter__.call_count)
@mock.patch.object(rbd_utils, 'RBDVolumeProxy')
def test_resize(self, mock_proxy):
size = 1024
proxy = mock_proxy.return_value
proxy.__enter__.return_value = proxy
self.driver.resize(self.volume_name, size)
proxy.resize.assert_called_once_with(size)
@mock.patch.object(rbd_utils.RBDDriver, '_disconnect_from_rados')
@mock.patch.object(rbd_utils.RBDDriver, '_connect_to_rados')
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_rbd_volume_proxy_init(self, mock_rados, mock_rbd,
mock_connect_from_rados,
mock_disconnect_from_rados):
mock_connect_from_rados.return_value = (None, None)
mock_disconnect_from_rados.return_value = (None, None)
with rbd_utils.RBDVolumeProxy(self.driver, self.volume_name):
mock_connect_from_rados.assert_called_once_with(None)
self.assertFalse(mock_disconnect_from_rados.called)
mock_disconnect_from_rados.assert_called_once_with(None, None)
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_connect_to_rados_default(self, mock_rados, mock_rbd):
ret = self.driver._connect_to_rados()
self.assertTrue(self.mock_rados.Rados.connect.called)
self.assertTrue(self.mock_rados.Rados.open_ioctx.called)
self.assertIsInstance(ret[0], self.mock_rados.Rados)
self.assertEqual(self.mock_rados.Rados.ioctx, ret[1])
self.mock_rados.Rados.open_ioctx.assert_called_with(self.rbd_pool)
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
def test_connect_to_rados_different_pool(self, mock_rados, mock_rbd):
ret = self.driver._connect_to_rados('alt_pool')
self.assertTrue(self.mock_rados.Rados.connect.called)
self.assertTrue(self.mock_rados.Rados.open_ioctx.called)
self.assertIsInstance(ret[0], self.mock_rados.Rados)
self.assertEqual(self.mock_rados.Rados.ioctx, ret[1])
self.mock_rados.Rados.open_ioctx.assert_called_with('alt_pool')
@mock.patch.object(rbd_utils, 'rados')
def test_connect_to_rados_error(self, mock_rados):
mock_rados.Rados.open_ioctx.side_effect = mock_rados.Error
self.assertRaises(mock_rados.Error, self.driver._connect_to_rados)
mock_rados.Rados.open_ioctx.assert_called_once_with(self.rbd_pool)
mock_rados.Rados.shutdown.assert_called_once_with()
def test_ceph_args_none(self):
self.driver.rbd_user = None
self.driver.ceph_conf = None
self.assertEqual([], self.driver.ceph_args())
def test_ceph_args_rbd_user(self):
self.driver.rbd_user = 'foo'
self.driver.ceph_conf = None
self.assertEqual(['--id', 'foo'], self.driver.ceph_args())
def test_ceph_args_ceph_conf(self):
self.driver.rbd_user = None
self.driver.ceph_conf = '/path/bar.conf'
self.assertEqual(['--conf', '/path/bar.conf'],
self.driver.ceph_args())
def test_ceph_args_rbd_user_and_ceph_conf(self):
self.driver.rbd_user = 'foo'
self.driver.ceph_conf = '/path/bar.conf'
self.assertEqual(['--id', 'foo', '--conf', '/path/bar.conf'],
self.driver.ceph_args())
@mock.patch.object(rbd_utils, 'RBDVolumeProxy')
def test_exists(self, mock_proxy):
snapshot = 'snap'
proxy = mock_proxy.return_value
self.assertTrue(self.driver.exists(self.volume_name,
self.rbd_pool,
snapshot))
proxy.__enter__.assert_called_once_with()
proxy.__exit__.assert_called_once_with(None, None, None)
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
@mock.patch.object(rbd_utils, 'RADOSClient')
def test_cleanup_volumes(self, mock_client, mock_rados, mock_rbd):
instance = objects.Instance(id=1, uuid='12345')
rbd = mock_rbd.RBD.return_value
rbd.list.return_value = ['12345_test', '111_test']
client = mock_client.return_value
self.driver.cleanup_volumes(instance)
rbd.remove.assert_called_once_with(client.ioctx, '12345_test')
client.__enter__.assert_called_once_with()
client.__exit__.assert_called_once_with(None, None, None)
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
@mock.patch.object(rbd_utils, 'RADOSClient')
def _test_cleanup_exception(self, exception_name,
mock_client, mock_rados, mock_rbd):
instance = objects.Instance(id=1, uuid='12345')
setattr(mock_rbd, exception_name, test.TestingException)
rbd = mock_rbd.RBD.return_value
rbd.remove.side_effect = test.TestingException
rbd.list.return_value = ['12345_test', '111_test']
client = mock_client.return_value
with mock.patch('eventlet.greenthread.sleep'):
self.driver.cleanup_volumes(instance)
rbd.remove.assert_any_call(client.ioctx, '12345_test')
# NOTE(danms): 10 retries + 1 final attempt to propagate = 11
self.assertEqual(11, len(rbd.remove.call_args_list))
def test_cleanup_volumes_fail_not_found(self):
self._test_cleanup_exception('ImageBusy')
def test_cleanup_volumes_fail_snapshots(self):
self._test_cleanup_exception('ImageHasSnapshots')
def test_cleanup_volumes_fail_other(self):
self.assertRaises(test.TestingException,
self._test_cleanup_exception, 'DoesNotExist')
@mock.patch.object(rbd_utils, 'rbd')
@mock.patch.object(rbd_utils, 'rados')
@mock.patch.object(rbd_utils, 'RADOSClient')
def test_remove_image(self, mock_client, mock_rados, mock_rbd):
name = '12345_disk.config.rescue'
rbd = mock_rbd.RBD.return_value
client = mock_client.return_value
self.driver.remove_image(name)
rbd.remove.assert_called_once_with(client.ioctx, name)
# Make sure that we entered and exited the RADOSClient
client.__enter__.assert_called_once_with()
client.__exit__.assert_called_once_with(None, None, None)
|
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,
421,
199,
646,
1683,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
4549,
14,
11877,
14,
3494,
492,
519,
3691,
63,
1208,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
2089,
9791,
63,
11710,
63,
26406,
275,
408,
2724,
379,
3485,
1130,
9463,
413,
199,
91,
298,
7367,
582,
413,
12,
523,
298,
70,
4148,
582,
298,
1153,
2766,
966,
709,
13,
22,
68,
3129,
13,
20,
68,
1272,
13,
24,
69,
2260,
13,
19,
66,
25,
2481,
2177,
10860,
2158,
401,
523,
298,
5540,
582,
298,
6965,
13,
1717,
13,
1081,
5557,
26,
1602,
26,
1367,
14,
1082,
1344,
1085,
401,
523,
298,
3966,
582,
298,
6965,
13,
1717,
13,
1081,
5557,
26,
1602,
26,
1367,
14,
1082,
1344,
1085,
401,
523,
298,
2106,
83,
582,
359,
267,
469,
298,
4648,
582,
378,
12,
881,
298,
354,
582,
298,
65,
401,
881,
298,
2697,
582,
7369,
447,
17,
2189,
1822,
1407,
19814,
16,
6018,
267,
469,
298,
4648,
582,
413,
12,
881,
298,
354,
582,
298,
66,
401,
881,
298,
2697,
582,
7369,
447,
17,
2189,
1822,
2710,
19814,
16,
6018,
267,
469,
298,
4648,
582,
499,
12,
881,
298,
354,
582,
298,
67,
401,
881,
298,
2697,
582,
7369,
447,
17,
2189,
1822,
3328,
19814,
16,
6018,
267,
469,
298,
4648,
582,
650,
12,
881,
298,
354,
582,
298,
68,
401,
881,
298,
2697,
582,
298,
4195,
14,
16,
14,
16,
14,
17,
26,
1822,
2942,
19814,
16,
6018,
267,
469,
298,
4648,
582,
841,
12,
881,
298,
354,
582,
298,
69,
401,
881,
298,
2697,
582,
298,
2694,
14,
957,
26,
1822,
3328,
19814,
16,
3570,
467,
523,
298,
392,
32346,
582,
359,
267,
378,
12,
267,
413,
12,
267,
499,
9420,
199,
624,
421,
199,
533,
820,
3691,
1746,
8,
396,
14,
32437,
304,
339,
768,
1805,
14,
2068,
14,
785,
8,
18640,
63,
1208,
12,
283,
18640,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
18640,
63,
1208,
12,
283,
9525,
736,
358,
272,
347,
3613,
8,
277,
12,
1683,
63,
9525,
736,
12,
1683,
63,
18640,
304,
267,
1613,
8,
50,
3691,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
1805,
63,
9525,
736,
275,
1683,
63,
9525,
736,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
275,
1683,
14,
3346,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
2308,
3799,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
2242,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
8831,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
1490,
63,
2308,
3799,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
1490,
63,
2308,
3799,
14,
1107,
63,
585,
275,
971,
288,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
2308,
3799,
267,
291,
14,
1805,
63,
9525,
736,
14,
547,
275,
2186,
398,
291,
14,
1805,
63,
18640,
275,
1683,
63,
18640,
267,
291,
14,
1805,
63,
18640,
14,
50,
11156,
275,
1683,
14,
3346,
267,
291,
14,
1805,
63,
18640,
14,
3491,
275,
1683,
14,
3346,
267,
291,
14,
1805,
63,
18640,
14,
3491,
14,
1600,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
18640,
14,
50,
11156,
14,
547,
275,
2186,
398,
291,
14,
18640,
63,
2293,
275,
283,
18640,
7,
267,
291,
14,
3090,
275,
519,
3691,
63,
1208,
14,
16567,
5745,
2046,
8,
277,
14,
18640,
63,
2293,
12,
488,
12,
488,
9,
398,
291,
14,
2405,
63,
354,
275,
399,
7,
2405,
13,
23848,
7,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
50,
3691,
1746,
12,
291,
680,
12336,
342,
339,
347,
511,
63,
8302,
63,
8022,
8,
277,
304,
267,
9918,
275,
788,
18640,
921,
70,
4148,
15,
2293,
15,
1569,
15,
10002,
297,
2151,
283,
18640,
13827,
18,
38,
3149,
18,
38,
3149,
18,
38,
3149,
18,
38,
297,
1622,
267,
2341,
8,
277,
14,
3090,
14,
1122,
63,
633,
12,
9918,
9,
339,
347,
511,
63,
4087,
63,
8022,
8,
277,
304,
267,
9918,
275,
788,
18640,
921,
1569,
297,
2151,
283,
1014,
921,
515,
15,
475,
15,
3972,
4509,
15,
2836,
297,
2151,
283,
18640,
921,
1569,
15,
2911,
297,
2151,
283,
18640,
921,
1569,
3678,
2151,
283,
18640,
921,
70,
4148,
15,
2293,
15,
1569,
3678,
2151,
283,
18640,
921,
70,
4148,
15,
2293,
15,
1569,
15,
10002,
3678,
2151,
283,
18640,
26,
868,
3678,
1622,
267,
1834,
63,
2024,
275,
2251,
14,
3491,
3396,
14,
504,
63,
807,
3252,
4032,
63,
908,
356,
283,
1773,
3071,
398,
367,
4355,
315,
9918,
26,
288,
291,
14,
1855,
8,
1971,
14,
3491,
1358,
28751,
12,
2892,
291,
14,
3090,
14,
1122,
63,
633,
12,
4355,
9,
288,
291,
14,
3334,
8,
277,
14,
3090,
14,
374,
63,
6311,
461,
3252,
633,
356,
4355,
1386,
10028,
1834,
63,
2024,
430,
339,
768,
1805,
14,
2068,
14,
785,
8,
18640,
63,
1208,
14,
16567,
5745,
2046,
12,
2513,
362,
63,
70,
4148,
358,
272,
768,
1805,
14,
2068,
14,
785,
8
] |
[
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
421,
199,
646,
1683,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
492,
3778,
199,
504,
5913,
14,
4549,
14,
11877,
14,
3494,
492,
519,
3691,
63,
1208,
421,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
2089,
9791,
63,
11710,
63,
26406,
275,
408,
2724,
379,
3485,
1130,
9463,
413,
199,
91,
298,
7367,
582,
413,
12,
523,
298,
70,
4148,
582,
298,
1153,
2766,
966,
709,
13,
22,
68,
3129,
13,
20,
68,
1272,
13,
24,
69,
2260,
13,
19,
66,
25,
2481,
2177,
10860,
2158,
401,
523,
298,
5540,
582,
298,
6965,
13,
1717,
13,
1081,
5557,
26,
1602,
26,
1367,
14,
1082,
1344,
1085,
401,
523,
298,
3966,
582,
298,
6965,
13,
1717,
13,
1081,
5557,
26,
1602,
26,
1367,
14,
1082,
1344,
1085,
401,
523,
298,
2106,
83,
582,
359,
267,
469,
298,
4648,
582,
378,
12,
881,
298,
354,
582,
298,
65,
401,
881,
298,
2697,
582,
7369,
447,
17,
2189,
1822,
1407,
19814,
16,
6018,
267,
469,
298,
4648,
582,
413,
12,
881,
298,
354,
582,
298,
66,
401,
881,
298,
2697,
582,
7369,
447,
17,
2189,
1822,
2710,
19814,
16,
6018,
267,
469,
298,
4648,
582,
499,
12,
881,
298,
354,
582,
298,
67,
401,
881,
298,
2697,
582,
7369,
447,
17,
2189,
1822,
3328,
19814,
16,
6018,
267,
469,
298,
4648,
582,
650,
12,
881,
298,
354,
582,
298,
68,
401,
881,
298,
2697,
582,
298,
4195,
14,
16,
14,
16,
14,
17,
26,
1822,
2942,
19814,
16,
6018,
267,
469,
298,
4648,
582,
841,
12,
881,
298,
354,
582,
298,
69,
401,
881,
298,
2697,
582,
298,
2694,
14,
957,
26,
1822,
3328,
19814,
16,
3570,
467,
523,
298,
392,
32346,
582,
359,
267,
378,
12,
267,
413,
12,
267,
499,
9420,
199,
624,
421,
199,
533,
820,
3691,
1746,
8,
396,
14,
32437,
304,
339,
768,
1805,
14,
2068,
14,
785,
8,
18640,
63,
1208,
12,
283,
18640,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
18640,
63,
1208,
12,
283,
9525,
736,
358,
272,
347,
3613,
8,
277,
12,
1683,
63,
9525,
736,
12,
1683,
63,
18640,
304,
267,
1613,
8,
50,
3691,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
1805,
63,
9525,
736,
275,
1683,
63,
9525,
736,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
275,
1683,
14,
3346,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
2308,
3799,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
2242,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
8831,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
1490,
63,
2308,
3799,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
1490,
63,
2308,
3799,
14,
1107,
63,
585,
275,
971,
288,
291,
14,
1805,
63,
9525,
736,
14,
50,
20257,
14,
2308,
3799,
267,
291,
14,
1805,
63,
9525,
736,
14,
547,
275,
2186,
398,
291,
14,
1805,
63,
18640,
275,
1683,
63,
18640,
267,
291,
14,
1805,
63,
18640,
14,
50,
11156,
275,
1683,
14,
3346,
267,
291,
14,
1805,
63,
18640,
14,
3491,
275,
1683,
14,
3346,
267,
291,
14,
1805,
63,
18640,
14,
3491,
14,
1600,
275,
1683,
14,
3346,
342,
267,
291,
14,
1805,
63,
18640,
14,
50,
11156,
14,
547,
275,
2186,
398,
291,
14,
18640,
63,
2293,
275,
283,
18640,
7,
267,
291,
14,
3090,
275,
519,
3691,
63,
1208,
14,
16567,
5745,
2046,
8,
277,
14,
18640,
63,
2293,
12,
488,
12,
488,
9,
398,
291,
14,
2405,
63,
354,
275,
399,
7,
2405,
13,
23848,
7,
339,
347,
6766,
8,
277,
304,
267,
1613,
8,
50,
3691,
1746,
12,
291,
680,
12336,
342,
339,
347,
511,
63,
8302,
63,
8022,
8,
277,
304,
267,
9918,
275,
788,
18640,
921,
70,
4148,
15,
2293,
15,
1569,
15,
10002,
297,
2151,
283,
18640,
13827,
18,
38,
3149,
18,
38,
3149,
18,
38,
3149,
18,
38,
297,
1622,
267,
2341,
8,
277,
14,
3090,
14,
1122,
63,
633,
12,
9918,
9,
339,
347,
511,
63,
4087,
63,
8022,
8,
277,
304,
267,
9918,
275,
788,
18640,
921,
1569,
297,
2151,
283,
1014,
921,
515,
15,
475,
15,
3972,
4509,
15,
2836,
297,
2151,
283,
18640,
921,
1569,
15,
2911,
297,
2151,
283,
18640,
921,
1569,
3678,
2151,
283,
18640,
921,
70,
4148,
15,
2293,
15,
1569,
3678,
2151,
283,
18640,
921,
70,
4148,
15,
2293,
15,
1569,
15,
10002,
3678,
2151,
283,
18640,
26,
868,
3678,
1622,
267,
1834,
63,
2024,
275,
2251,
14,
3491,
3396,
14,
504,
63,
807,
3252,
4032,
63,
908,
356,
283,
1773,
3071,
398,
367,
4355,
315,
9918,
26,
288,
291,
14,
1855,
8,
1971,
14,
3491,
1358,
28751,
12,
2892,
291,
14,
3090,
14,
1122,
63,
633,
12,
4355,
9,
288,
291,
14,
3334,
8,
277,
14,
3090,
14,
374,
63,
6311,
461,
3252,
633,
356,
4355,
1386,
10028,
1834,
63,
2024,
430,
339,
768,
1805,
14,
2068,
14,
785,
8,
18640,
63,
1208,
14,
16567,
5745,
2046,
12,
2513,
362,
63,
70,
4148,
358,
272,
768,
1805,
14,
2068,
14,
785,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Gillu13/scipy
|
scipy/sparse/linalg/isolve/lgmres.py
|
3
|
11059
|
# Copyright (C) 2009, Pauli Virtanen <pav@iki.fi>
# Distributed under the same license as Scipy.
from __future__ import division, print_function, absolute_import
import numpy as np
from scipy._lib.six import xrange
from scipy.linalg import get_blas_funcs, get_lapack_funcs, qr_insert
from .utils import make_system
__all__ = ['lgmres']
def lgmres(A, b, x0=None, tol=1e-5, maxiter=1000, M=None, callback=None,
inner_m=30, outer_k=3, outer_v=None, store_outer_Av=True):
"""
Solve a matrix equation using the LGMRES algorithm.
The LGMRES algorithm [1]_ [2]_ is designed to avoid some problems
in the convergence in restarted GMRES, and often converges in fewer
iterations.
Parameters
----------
A : {sparse matrix, dense matrix, LinearOperator}
The real or complex N-by-N matrix of the linear system.
b : {array, matrix}
Right hand side of the linear system. Has shape (N,) or (N,1).
x0 : {array, matrix}
Starting guess for the solution.
tol : float, optional
Tolerance to achieve. The algorithm terminates when either the relative
or the absolute residual is below `tol`.
maxiter : int, optional
Maximum number of iterations. Iteration will stop after maxiter
steps even if the specified tolerance has not been achieved.
M : {sparse matrix, dense matrix, LinearOperator}, optional
Preconditioner for A. The preconditioner should approximate the
inverse of A. Effective preconditioning dramatically improves the
rate of convergence, which implies that fewer iterations are needed
to reach a given error tolerance.
callback : function, optional
User-supplied function to call after each iteration. It is called
as callback(xk), where xk is the current solution vector.
inner_m : int, optional
Number of inner GMRES iterations per each outer iteration.
outer_k : int, optional
Number of vectors to carry between inner GMRES iterations.
According to [1]_, good values are in the range of 1...3.
However, note that if you want to use the additional vectors to
accelerate solving multiple similar problems, larger values may
be beneficial.
outer_v : list of tuples, optional
List containing tuples ``(v, Av)`` of vectors and corresponding
matrix-vector products, used to augment the Krylov subspace, and
carried between inner GMRES iterations. The element ``Av`` can
be `None` if the matrix-vector product should be re-evaluated.
This parameter is modified in-place by `lgmres`, and can be used
to pass "guess" vectors in and out of the algorithm when solving
similar problems.
store_outer_Av : bool, optional
Whether LGMRES should store also A*v in addition to vectors `v`
in the `outer_v` list. Default is True.
Returns
-------
x : array or matrix
The converged solution.
info : int
Provides convergence information:
- 0 : successful exit
- >0 : convergence to tolerance not achieved, number of iterations
- <0 : illegal input or breakdown
Notes
-----
The LGMRES algorithm [1]_ [2]_ is designed to avoid the
slowing of convergence in restarted GMRES, due to alternating
residual vectors. Typically, it often outperforms GMRES(m) of
comparable memory requirements by some measure, or at least is not
much worse.
Another advantage in this algorithm is that you can supply it with
'guess' vectors in the `outer_v` argument that augment the Krylov
subspace. If the solution lies close to the span of these vectors,
the algorithm converges faster. This can be useful if several very
similar matrices need to be inverted one after another, such as in
Newton-Krylov iteration where the Jacobian matrix often changes
little in the nonlinear steps.
References
----------
.. [1] A.H. Baker and E.R. Jessup and T. Manteuffel,
SIAM J. Matrix Anal. Appl. 26, 962 (2005).
.. [2] A.H. Baker, PhD thesis, University of Colorado (2003).
http://amath.colorado.edu/activities/thesis/allisonb/Thesis.ps
"""
A,M,x,b,postprocess = make_system(A,M,x0,b)
if not np.isfinite(b).all():
raise ValueError("RHS must contain only finite numbers")
matvec = A.matvec
psolve = M.matvec
if outer_v is None:
outer_v = []
axpy, dot, scal = None, None, None
nrm2 = get_blas_funcs('nrm2', [b])
b_norm = nrm2(b)
if b_norm == 0:
b_norm = 1
for k_outer in xrange(maxiter):
r_outer = matvec(x) - b
# -- callback
if callback is not None:
callback(x)
# -- determine input type routines
if axpy is None:
if np.iscomplexobj(r_outer) and not np.iscomplexobj(x):
x = x.astype(r_outer.dtype)
axpy, dot, scal, nrm2 = get_blas_funcs(['axpy', 'dot', 'scal', 'nrm2'],
(x, r_outer))
trtrs = get_lapack_funcs('trtrs', (x, r_outer))
# -- check stopping condition
r_norm = nrm2(r_outer)
if r_norm <= tol * b_norm or r_norm <= tol:
break
# -- inner LGMRES iteration
vs0 = -psolve(r_outer)
inner_res_0 = nrm2(vs0)
if inner_res_0 == 0:
rnorm = nrm2(r_outer)
raise RuntimeError("Preconditioner returned a zero vector; "
"|v| ~ %.1g, |M v| = 0" % rnorm)
vs0 = scal(1.0/inner_res_0, vs0)
vs = [vs0]
ws = []
y = None
# H is stored in QR factorized form
Q = np.ones((1, 1), dtype=vs0.dtype)
R = np.zeros((1, 0), dtype=vs0.dtype)
eps = np.finfo(vs0.dtype).eps
for j in xrange(1, 1 + inner_m + len(outer_v)):
# -- Arnoldi process:
#
# Build an orthonormal basis V and matrices W and H such that
# A W = V H
# Columns of W, V, and H are stored in `ws`, `vs` and `hs`.
#
# The first column of V is always the residual vector, `vs0`;
# V has *one more column* than the other of the three matrices.
#
# The other columns in V are built by feeding in, one
# by one, some vectors `z` and orthonormalizing them
# against the basis so far. The trick here is to
# feed in first some augmentation vectors, before
# starting to construct the Krylov basis on `v0`.
#
# It was shown in [BJM]_ that a good choice (the LGMRES choice)
# for these augmentation vectors are the `dx` vectors obtained
# from a couple of the previous restart cycles.
#
# Note especially that while `vs0` is always the first
# column in V, there is no reason why it should also be
# the first column in W. (In fact, below `vs0` comes in
# W only after the augmentation vectors.)
#
# The rest of the algorithm then goes as in GMRES, one
# solves a minimization problem in the smaller subspace
# spanned by W (range) and V (image).
#
# ++ evaluate
v_new = None
if j < len(outer_v) + 1:
z, v_new = outer_v[j-1]
elif j == len(outer_v) + 1:
z = vs0
else:
z = vs[-1]
if v_new is None:
v_new = psolve(matvec(z))
else:
# Note: v_new is modified in-place below. Must make a
# copy to ensure that the outer_v vectors are not
# clobbered.
v_new = v_new.copy()
# ++ orthogonalize
hcur = np.zeros(j+1, dtype=Q.dtype)
for i, v in enumerate(vs):
alpha = dot(v, v_new)
hcur[i] = alpha
v_new = axpy(v, v_new, v.shape[0], -alpha) # v_new -= alpha*v
hcur[-1] = nrm2(v_new)
with np.errstate(over='ignore', divide='ignore'):
# Careful with denormals
alpha = 1/hcur[-1]
if np.isfinite(alpha):
v_new = scal(alpha, v_new)
else:
# v_new either zero (solution in span of previous
# vectors) or we have nans. If we already have
# previous vectors in R, we can discard the current
# vector and bail out.
if j > 1:
j -= 1
break
vs.append(v_new)
ws.append(z)
# -- GMRES optimization problem
# Add new column to H=Q*R, padding other columns with zeros
Q2 = np.zeros((j+1, j+1), dtype=Q.dtype, order='F')
Q2[:j,:j] = Q
Q2[j,j] = 1
R2 = np.zeros((j+1, j-1), dtype=R.dtype, order='F')
R2[:j,:] = R
Q, R = qr_insert(Q2, R2, hcur, j-1, which='col',
overwrite_qru=True, check_finite=False)
# Transformed least squares problem
# || Q R y - inner_res_0 * e_1 ||_2 = min!
# Since R = [R'; 0], solution is y = inner_res_0 (R')^{-1} (Q^H)[:j,0]
# Residual is immediately known
inner_res = abs(Q[0,-1]) * inner_res_0
# -- check for termination
if inner_res <= tol * inner_res_0:
break
# -- Get the LSQ problem solution
y, info = trtrs(R[:j,:j], Q[0,:j].conj())
if info != 0:
# Zero diagonal -> exact solution, but we handled that above
raise RuntimeError("QR solution failed")
y *= inner_res_0
if not np.isfinite(y).all():
# Floating point over/underflow, non-finite result from
# matmul etc. -- report failure.
return postprocess(x), k_outer + 1
# -- GMRES terminated: eval solution
dx = ws[0]*y[0]
for w, yc in zip(ws[1:], y[1:]):
dx = axpy(w, dx, dx.shape[0], yc) # dx += w*yc
# -- Store LGMRES augmentation vectors
nx = nrm2(dx)
if nx > 0:
if store_outer_Av:
q = Q.dot(R.dot(y))
ax = vs[0]*q[0]
for v, qc in zip(vs[1:], q[1:]):
ax = axpy(v, ax, ax.shape[0], qc)
outer_v.append((dx/nx, ax/nx))
else:
outer_v.append((dx/nx, None))
# -- Retain only a finite number of augmentation vectors
while len(outer_v) > outer_k:
del outer_v[0]
# -- Apply step
x += dx
else:
# didn't converge ...
return postprocess(x), maxiter
return postprocess(x), 0
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
8937,
12,
510,
3844,
317,
812,
8401,
290,
287,
665,
387,
86,
32,
11545,
14,
329,
30,
199,
3,
17484,
1334,
314,
2011,
4190,
465,
16578,
647,
14,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
423,
773,
14,
4174,
492,
4945,
199,
504,
7026,
14,
10096,
492,
664,
63,
21044,
63,
9204,
12,
664,
63,
26760,
63,
9204,
12,
29757,
63,
3176,
199,
504,
1275,
1208,
492,
1852,
63,
2253,
199,
199,
363,
452,
363,
275,
788,
9783,
77,
470,
418,
421,
199,
318,
634,
13844,
470,
8,
33,
12,
330,
12,
671,
16,
29,
403,
12,
9561,
29,
17,
69,
13,
21,
12,
27150,
29,
5279,
12,
603,
29,
403,
12,
3233,
29,
403,
12,
1779,
6506,
63,
77,
29,
1216,
12,
6890,
63,
75,
29,
19,
12,
6890,
63,
86,
29,
403,
12,
3877,
63,
7837,
63,
6651,
29,
549,
304,
272,
408,
272,
428,
3344,
282,
3634,
18649,
1808,
314,
491,
22636,
3830,
5563,
14,
339,
710,
491,
22636,
3830,
5563,
359,
17,
25276,
359,
18,
25276,
365,
19829,
370,
5126,
2005,
8826,
272,
315,
314,
21346,
315,
32277,
598,
45,
3830,
12,
436,
14115,
3818,
3389,
315,
27392,
272,
10615,
14,
339,
3897,
272,
4143,
272,
437,
520,
469,
4421,
3634,
12,
9363,
3634,
12,
12489,
7961,
93,
267,
710,
3363,
503,
6114,
653,
13,
991,
13,
46,
3634,
402,
314,
7798,
2656,
14,
272,
330,
520,
469,
1144,
12,
3634,
93,
267,
20854,
4926,
5366,
402,
314,
7798,
2656,
14,
13481,
2215,
334,
46,
4258,
503,
334,
46,
12,
17,
680,
272,
671,
16,
221,
520,
469,
1144,
12,
3634,
93,
267,
24175,
9519,
367,
314,
8744,
14,
272,
9561,
520,
2069,
12,
2716,
267,
4005,
8807,
370,
32194,
14,
710,
5563,
26751,
1380,
1902,
314,
3847,
267,
503,
314,
3679,
16731,
365,
5084,
658,
6896,
2313,
272,
27150,
520,
1109,
12,
2716,
267,
14212,
1329,
402,
10615,
14,
221,
473,
5388,
911,
3631,
2410,
27150,
267,
7124,
2755,
340,
314,
2013,
13464,
965,
440,
2757,
22175,
1354,
14,
272,
603,
520,
469,
4421,
3634,
12,
9363,
3634,
12,
12489,
7961,
1386,
2716,
267,
5543,
5394,
281,
367,
437,
14,
221,
710,
876,
5394,
281,
1077,
19917,
314,
267,
11484,
402,
437,
14,
221,
662,
556,
6850,
876,
5394,
316,
366,
345,
17174,
1742,
293,
2310,
314,
267,
6634,
402,
21346,
12,
1314,
22660,
626,
27392,
10615,
787,
4346,
267,
370,
12276,
282,
1627,
1125,
13464,
14,
272,
3233,
520,
805,
12,
2716,
267,
2876,
13,
22525,
805,
370,
1240,
2410,
1924,
8494,
14,
221,
2779,
365,
2797,
267,
465,
3233,
8,
28351,
395,
2382,
671,
75,
365,
314,
1453,
8744,
5477,
14,
272,
6506,
63,
77,
520,
1109,
12,
2716,
267,
4860,
402,
6506,
598,
45,
3830,
10615,
1126,
1924,
6890,
8494,
14,
272,
6890,
63,
75,
520,
1109,
12,
2716,
267,
4860,
402,
11102,
370,
25176,
3382,
6506,
598,
45,
3830,
10615,
14,
267,
31970,
370,
359,
17,
61,
3131,
6954,
1338,
787,
315,
314,
1425,
402,
413,
1396,
19,
14,
267,
9738,
12,
5317,
626,
340,
1265,
2934,
370,
675,
314,
4722,
11102,
370,
267,
1066,
11338,
323,
8597,
4007,
3663,
8545,
8826,
12,
12142,
1338,
1443,
267,
506,
22477,
16714,
14,
272,
6890,
63,
86,
520,
769,
402,
6346,
12,
2716,
267,
3820,
3035,
6346,
15475,
86,
12,
16599,
9719,
402,
11102,
436,
5226,
267,
3634,
13,
4106,
7585,
12,
1202,
370,
18336,
434,
314,
1804,
651,
32555,
1007,
2638,
12,
436,
267,
9590,
18906,
3382,
6506,
598,
45,
3830,
10615,
14,
710,
1819,
1124,
6651,
1040,
883,
267,
506,
658,
403,
64,
340,
314,
3634,
13,
4106,
3336,
1077,
506,
295,
13,
2579,
23130,
14,
267,
961,
2725,
365,
6042,
315,
13,
2778,
701,
658,
9783,
77,
470,
3559,
436,
883,
506,
1202,
267,
370,
986,
298,
11636,
2,
11102,
315,
436,
734,
402,
314,
5563,
1380,
8597,
4007,
267,
8545,
8826,
14,
272,
3877,
63,
7837,
63,
6651,
520,
2155,
12,
2716,
267,
7480,
491,
22636,
3830,
1077,
3877,
2597,
437,
10,
86,
315,
10234,
370,
11102,
658,
86,
64,
267,
315,
314,
658,
7837,
63,
86,
64,
769,
14,
3758,
365,
715,
14,
339,
1803,
272,
5514,
272,
671,
520,
1625,
503,
3634,
267,
710,
3818,
3046,
8744,
14,
272,
2256,
520,
1109,
267,
21552,
21346,
2556,
26,
953,
446,
378,
221,
520,
9512,
4458,
288,
446,
690,
16,
520,
21346,
370,
13464,
440,
22175,
1354,
12,
1329,
402,
10615,
288,
446,
665,
16,
520,
20282,
1324,
503,
2059,
2110,
339,
8144,
272,
9063,
272,
710,
491,
22636,
3830,
5563,
359,
17,
25276,
359,
18,
25276,
365,
19829,
370,
5126,
314,
272,
11999,
316,
402,
21346,
315,
32277,
598,
45,
3830,
12,
7037,
370,
8679,
1958,
272,
16731,
11102,
14,
26914,
12,
652,
14115,
734,
529,
3351,
598,
45,
3830,
8,
77,
9,
402,
272,
1013,
19816,
4402,
9760,
701,
2005,
9775,
12,
503,
737,
5210,
365,
440,
272,
8298,
1319,
261,
14,
339,
22604,
30268,
315,
642,
5563,
365,
626,
1265,
883,
17169,
652,
543,
272,
283,
11636,
7,
11102,
315,
314,
658,
7837,
63,
86,
64,
1423,
626,
18336,
434,
314,
1804,
651,
32555,
272,
1007,
2638,
14,
982,
314,
8744,
1212,
397,
4002,
370,
314,
13598,
402,
3520,
11102,
12,
272,
314,
5563,
3818,
3389,
12930,
14,
961,
883,
506,
2997,
340,
9978,
7437,
272,
8545,
12627,
1929,
370,
506,
29402,
1373,
2410,
4573,
12,
4066,
465,
315,
272,
7053,
1860,
13,
43,
651,
32555,
8494,
2382,
314,
30633,
3634,
14115,
4493,
272,
12050,
315,
314,
2222,
6676,
7124,
14,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
437,
14,
40,
14,
699,
12630,
436,
662,
14,
50,
14,
1603,
16709,
384,
436,
377,
14,
4688,
266,
3043,
352,
12,
1467,
428,
41,
1156,
1603,
14,
8449,
1626,
279,
14,
4693,
76,
14,
7875,
12,
1749,
2789,
334,
9397,
680,
272,
2508,
359,
18,
61,
437,
14,
40,
14,
699,
12630,
12,
11308,
36,
314,
2316,
12,
15904,
402,
11581,
5129,
334,
17919,
680,
1467,
1455,
921,
65,
3442,
14,
2326,
5129,
14,
8654,
15
] |
[
1898,
334,
35,
9,
8937,
12,
510,
3844,
317,
812,
8401,
290,
287,
665,
387,
86,
32,
11545,
14,
329,
30,
199,
3,
17484,
1334,
314,
2011,
4190,
465,
16578,
647,
14,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
646,
2680,
465,
980,
199,
504,
7026,
423,
773,
14,
4174,
492,
4945,
199,
504,
7026,
14,
10096,
492,
664,
63,
21044,
63,
9204,
12,
664,
63,
26760,
63,
9204,
12,
29757,
63,
3176,
199,
504,
1275,
1208,
492,
1852,
63,
2253,
199,
199,
363,
452,
363,
275,
788,
9783,
77,
470,
418,
421,
199,
318,
634,
13844,
470,
8,
33,
12,
330,
12,
671,
16,
29,
403,
12,
9561,
29,
17,
69,
13,
21,
12,
27150,
29,
5279,
12,
603,
29,
403,
12,
3233,
29,
403,
12,
1779,
6506,
63,
77,
29,
1216,
12,
6890,
63,
75,
29,
19,
12,
6890,
63,
86,
29,
403,
12,
3877,
63,
7837,
63,
6651,
29,
549,
304,
272,
408,
272,
428,
3344,
282,
3634,
18649,
1808,
314,
491,
22636,
3830,
5563,
14,
339,
710,
491,
22636,
3830,
5563,
359,
17,
25276,
359,
18,
25276,
365,
19829,
370,
5126,
2005,
8826,
272,
315,
314,
21346,
315,
32277,
598,
45,
3830,
12,
436,
14115,
3818,
3389,
315,
27392,
272,
10615,
14,
339,
3897,
272,
4143,
272,
437,
520,
469,
4421,
3634,
12,
9363,
3634,
12,
12489,
7961,
93,
267,
710,
3363,
503,
6114,
653,
13,
991,
13,
46,
3634,
402,
314,
7798,
2656,
14,
272,
330,
520,
469,
1144,
12,
3634,
93,
267,
20854,
4926,
5366,
402,
314,
7798,
2656,
14,
13481,
2215,
334,
46,
4258,
503,
334,
46,
12,
17,
680,
272,
671,
16,
221,
520,
469,
1144,
12,
3634,
93,
267,
24175,
9519,
367,
314,
8744,
14,
272,
9561,
520,
2069,
12,
2716,
267,
4005,
8807,
370,
32194,
14,
710,
5563,
26751,
1380,
1902,
314,
3847,
267,
503,
314,
3679,
16731,
365,
5084,
658,
6896,
2313,
272,
27150,
520,
1109,
12,
2716,
267,
14212,
1329,
402,
10615,
14,
221,
473,
5388,
911,
3631,
2410,
27150,
267,
7124,
2755,
340,
314,
2013,
13464,
965,
440,
2757,
22175,
1354,
14,
272,
603,
520,
469,
4421,
3634,
12,
9363,
3634,
12,
12489,
7961,
1386,
2716,
267,
5543,
5394,
281,
367,
437,
14,
221,
710,
876,
5394,
281,
1077,
19917,
314,
267,
11484,
402,
437,
14,
221,
662,
556,
6850,
876,
5394,
316,
366,
345,
17174,
1742,
293,
2310,
314,
267,
6634,
402,
21346,
12,
1314,
22660,
626,
27392,
10615,
787,
4346,
267,
370,
12276,
282,
1627,
1125,
13464,
14,
272,
3233,
520,
805,
12,
2716,
267,
2876,
13,
22525,
805,
370,
1240,
2410,
1924,
8494,
14,
221,
2779,
365,
2797,
267,
465,
3233,
8,
28351,
395,
2382,
671,
75,
365,
314,
1453,
8744,
5477,
14,
272,
6506,
63,
77,
520,
1109,
12,
2716,
267,
4860,
402,
6506,
598,
45,
3830,
10615,
1126,
1924,
6890,
8494,
14,
272,
6890,
63,
75,
520,
1109,
12,
2716,
267,
4860,
402,
11102,
370,
25176,
3382,
6506,
598,
45,
3830,
10615,
14,
267,
31970,
370,
359,
17,
61,
3131,
6954,
1338,
787,
315,
314,
1425,
402,
413,
1396,
19,
14,
267,
9738,
12,
5317,
626,
340,
1265,
2934,
370,
675,
314,
4722,
11102,
370,
267,
1066,
11338,
323,
8597,
4007,
3663,
8545,
8826,
12,
12142,
1338,
1443,
267,
506,
22477,
16714,
14,
272,
6890,
63,
86,
520,
769,
402,
6346,
12,
2716,
267,
3820,
3035,
6346,
15475,
86,
12,
16599,
9719,
402,
11102,
436,
5226,
267,
3634,
13,
4106,
7585,
12,
1202,
370,
18336,
434,
314,
1804,
651,
32555,
1007,
2638,
12,
436,
267,
9590,
18906,
3382,
6506,
598,
45,
3830,
10615,
14,
710,
1819,
1124,
6651,
1040,
883,
267,
506,
658,
403,
64,
340,
314,
3634,
13,
4106,
3336,
1077,
506,
295,
13,
2579,
23130,
14,
267,
961,
2725,
365,
6042,
315,
13,
2778,
701,
658,
9783,
77,
470,
3559,
436,
883,
506,
1202,
267,
370,
986,
298,
11636,
2,
11102,
315,
436,
734,
402,
314,
5563,
1380,
8597,
4007,
267,
8545,
8826,
14,
272,
3877,
63,
7837,
63,
6651,
520,
2155,
12,
2716,
267,
7480,
491,
22636,
3830,
1077,
3877,
2597,
437,
10,
86,
315,
10234,
370,
11102,
658,
86,
64,
267,
315,
314,
658,
7837,
63,
86,
64,
769,
14,
3758,
365,
715,
14,
339,
1803,
272,
5514,
272,
671,
520,
1625,
503,
3634,
267,
710,
3818,
3046,
8744,
14,
272,
2256,
520,
1109,
267,
21552,
21346,
2556,
26,
953,
446,
378,
221,
520,
9512,
4458,
288,
446,
690,
16,
520,
21346,
370,
13464,
440,
22175,
1354,
12,
1329,
402,
10615,
288,
446,
665,
16,
520,
20282,
1324,
503,
2059,
2110,
339,
8144,
272,
9063,
272,
710,
491,
22636,
3830,
5563,
359,
17,
25276,
359,
18,
25276,
365,
19829,
370,
5126,
314,
272,
11999,
316,
402,
21346,
315,
32277,
598,
45,
3830,
12,
7037,
370,
8679,
1958,
272,
16731,
11102,
14,
26914,
12,
652,
14115,
734,
529,
3351,
598,
45,
3830,
8,
77,
9,
402,
272,
1013,
19816,
4402,
9760,
701,
2005,
9775,
12,
503,
737,
5210,
365,
440,
272,
8298,
1319,
261,
14,
339,
22604,
30268,
315,
642,
5563,
365,
626,
1265,
883,
17169,
652,
543,
272,
283,
11636,
7,
11102,
315,
314,
658,
7837,
63,
86,
64,
1423,
626,
18336,
434,
314,
1804,
651,
32555,
272,
1007,
2638,
14,
982,
314,
8744,
1212,
397,
4002,
370,
314,
13598,
402,
3520,
11102,
12,
272,
314,
5563,
3818,
3389,
12930,
14,
961,
883,
506,
2997,
340,
9978,
7437,
272,
8545,
12627,
1929,
370,
506,
29402,
1373,
2410,
4573,
12,
4066,
465,
315,
272,
7053,
1860,
13,
43,
651,
32555,
8494,
2382,
314,
30633,
3634,
14115,
4493,
272,
12050,
315,
314,
2222,
6676,
7124,
14,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
437,
14,
40,
14,
699,
12630,
436,
662,
14,
50,
14,
1603,
16709,
384,
436,
377,
14,
4688,
266,
3043,
352,
12,
1467,
428,
41,
1156,
1603,
14,
8449,
1626,
279,
14,
4693,
76,
14,
7875,
12,
1749,
2789,
334,
9397,
680,
272,
2508,
359,
18,
61,
437,
14,
40,
14,
699,
12630,
12,
11308,
36,
314,
2316,
12,
15904,
402,
11581,
5129,
334,
17919,
680,
1467,
1455,
921,
65,
3442,
14,
2326,
5129,
14,
8654,
15,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jmesteve/medical
|
openerp/addons/stock/wizard/stock_inventory_line_split.py
|
64
|
4976
|
# -*- 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
class stock_inventory_line_split(osv.osv_memory):
_inherit = "stock.move.split"
_name = "stock.inventory.line.split"
_description = "Split inventory lines"
_columns = {
'line_ids': fields.one2many('stock.inventory.line.split.lines', 'wizard_id', 'Serial Numbers'),
'line_exist_ids': fields.one2many('stock.inventory.line.split.lines', 'wizard_exist_id', 'Serial Numbers'),
}
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
record_id = context and context.get('active_id',False)
res = {}
line = self.pool.get('stock.inventory.line').browse(cr, uid, record_id, context=context)
if 'product_id' in fields:
res.update({'product_id':line.product_id.id})
if 'product_uom' in fields:
res.update({'product_uom': line.product_uom.id})
if 'qty' in fields:
res.update({'qty': line.product_qty})
return res
def split(self, cr, uid, ids, line_ids, context=None):
""" To split stock inventory lines according to serial numbers.
:param line_ids: the ID or list of IDs of inventory lines we want to split
"""
if context is None:
context = {}
assert context.get('active_model') == 'stock.inventory.line',\
'Incorrect use of the inventory line split wizard.'
prodlot_obj = self.pool.get('stock.production.lot')
ir_sequence_obj = self.pool.get('ir.sequence')
line_obj = self.pool.get('stock.inventory.line')
new_line = []
for data in self.browse(cr, uid, ids, context=context):
for inv_line in line_obj.browse(cr, uid, line_ids, context=context):
line_qty = inv_line.product_qty
quantity_rest = inv_line.product_qty
new_line = []
if data.use_exist:
lines = [l for l in data.line_exist_ids if l]
else:
lines = [l for l in data.line_ids if l]
for line in lines:
quantity = line.quantity
if quantity <= 0 or line_qty == 0:
continue
quantity_rest -= quantity
if quantity_rest < 0:
quantity_rest = quantity
break
default_val = {
'product_qty': quantity,
}
if quantity_rest > 0:
current_line = line_obj.copy(cr, uid, inv_line.id, default_val)
new_line.append(current_line)
if quantity_rest == 0:
current_line = inv_line.id
prodlot_id = False
if data.use_exist:
prodlot_id = line.prodlot_id.id
if not prodlot_id:
prodlot_id = prodlot_obj.create(cr, uid, {
'name': line.name,
'product_id': inv_line.product_id.id},
context=context)
line_obj.write(cr, uid, [current_line], {'prod_lot_id': prodlot_id})
prodlot = prodlot_obj.browse(cr, uid, prodlot_id)
update_val = {}
if quantity_rest > 0:
update_val['product_qty'] = quantity_rest
line_obj.write(cr, uid, [inv_line.id], update_val)
return new_line
class stock_inventory_split_lines(osv.osv_memory):
_inherit = "stock.move.split.lines"
_name = "stock.inventory.line.split.lines"
_description = "Inventory Split lines"
_columns = {
'wizard_id': fields.many2one('stock.inventory.line.split', 'Parent Wizard'),
'wizard_exist_id': fields.many2one('stock.inventory.line.split', 'Parent Wizard'),
}
|
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,
199,
533,
10952,
63,
7212,
63,
604,
63,
1294,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
6486,
275,
298,
6088,
14,
1185,
14,
1294,
2,
272,
485,
354,
275,
298,
6088,
14,
7212,
14,
604,
14,
1294,
2,
272,
485,
1802,
275,
298,
8862,
8200,
2385,
2,
339,
485,
3406,
275,
469,
267,
283,
604,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
7212,
14,
604,
14,
1294,
14,
1278,
297,
283,
9819,
63,
344,
297,
283,
3571,
4860,
83,
659,
267,
283,
604,
63,
4494,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
7212,
14,
604,
14,
1294,
14,
1278,
297,
283,
9819,
63,
4494,
63,
344,
297,
283,
3571,
4860,
83,
659,
1362,
789,
339,
347,
849,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
1504,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
2777,
63,
344,
275,
1067,
436,
1067,
14,
362,
360,
2682,
63,
344,
297,
797,
9,
267,
522,
275,
1052,
267,
1004,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
7212,
14,
604,
1959,
4570,
8,
1556,
12,
1747,
12,
2777,
63,
344,
12,
1067,
29,
1100,
9,
267,
340,
283,
2558,
63,
344,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
344,
356,
604,
14,
2558,
63,
344,
14,
344,
1552,
267,
340,
283,
2558,
63,
7519,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
7519,
356,
1004,
14,
2558,
63,
7519,
14,
344,
1552,
267,
340,
283,
5643,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
5643,
356,
1004,
14,
2558,
63,
5643,
1552,
267,
372,
522,
339,
347,
3715,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1004,
63,
1580,
12,
1067,
29,
403,
304,
267,
408,
4005,
3715,
10952,
8200,
2385,
7182,
370,
3012,
5579,
14,
398,
520,
635,
1004,
63,
1580,
26,
314,
2870,
503,
769,
402,
11449,
402,
8200,
2385,
781,
2934,
370,
3715,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
702,
1067,
14,
362,
360,
2682,
63,
1238,
358,
508,
283,
6088,
14,
7212,
14,
604,
30989,
1467,
283,
18298,
675,
402,
314,
8200,
1004,
3715,
12262,
3530,
267,
12441,
1653,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
10777,
14,
1653,
358,
267,
8190,
63,
4041,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
4041,
358,
267,
1004,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
7212,
14,
604,
358,
267,
892,
63,
604,
275,
942,
267,
367,
666,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
367,
4572,
63,
604,
315,
1004,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1004,
63,
1580,
12,
1067,
29,
1100,
304,
355,
1004,
63,
5643,
275,
4572,
63,
604,
14,
2558,
63,
5643,
355,
12524,
63,
3911,
275,
4572,
63,
604,
14,
2558,
63,
5643,
355,
892,
63,
604,
275,
942,
355,
340,
666,
14,
1180,
63,
4494,
26,
490,
2385,
275,
359,
76,
367,
634,
315,
666,
14,
604,
63,
4494,
63,
1580,
340,
634,
61,
355,
587,
26,
490,
2385,
275,
359,
76,
367,
634,
315,
666,
14,
604,
63,
1580,
340,
634,
61,
355,
367,
1004,
315,
2385,
26,
490,
12524,
275,
1004,
14,
10577,
490,
340,
12524,
2695,
378,
503,
1004,
63,
5643,
508,
378,
26,
717,
1980,
490,
12524,
63,
3911,
4862,
12524,
490,
340,
12524,
63,
3911,
665,
378,
26,
717,
12524,
63,
3911,
275,
12524,
717,
2059,
490,
849,
63,
637,
275,
469,
717,
283,
2558,
63,
5643,
356,
12524,
12,
490,
789,
490,
340,
12524,
63,
3911,
690,
378,
26,
717,
1453,
63,
604,
275,
1004,
63,
1113,
14,
1574,
8,
1556,
12,
1747,
12,
4572,
63,
604,
14,
344,
12,
849,
63,
637,
9,
717,
892,
63,
604,
14,
740,
8,
1818,
63,
604,
9,
490,
340,
12524,
63,
3911,
508,
378,
26,
717,
1453,
63,
604,
275,
4572,
63,
604,
14,
344,
490,
12441,
1653,
63,
344,
275,
756,
490,
340,
666,
14,
1180,
63,
4494,
26,
717,
12441,
1653,
63,
344,
275,
1004,
14,
8788,
1653,
63,
344,
14,
344,
490,
340,
440,
12441,
1653,
63,
344,
26,
717,
12441,
1653,
63,
344,
275,
12441,
1653,
63,
1113,
14,
981,
8,
1556,
12,
1747,
12,
469,
1169,
283,
354,
356,
1004,
14,
354,
12,
1169,
283,
2558,
63,
344,
356,
4572,
63,
604,
14,
2558,
63,
344,
14,
344,
1386,
717,
1067,
29,
1100,
9,
490,
1004,
63,
1113,
14,
952,
8,
1556,
12,
1747,
12,
359,
1818,
63,
604,
467,
791,
8788,
63,
1653,
63,
344,
356,
12441,
1653,
63,
344,
1552,
490,
12441,
1653,
275,
12441,
1653,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
12441,
1653,
63,
344
] |
[
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,
199,
533,
10952,
63,
7212,
63,
604,
63,
1294,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
6486,
275,
298,
6088,
14,
1185,
14,
1294,
2,
272,
485,
354,
275,
298,
6088,
14,
7212,
14,
604,
14,
1294,
2,
272,
485,
1802,
275,
298,
8862,
8200,
2385,
2,
339,
485,
3406,
275,
469,
267,
283,
604,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
7212,
14,
604,
14,
1294,
14,
1278,
297,
283,
9819,
63,
344,
297,
283,
3571,
4860,
83,
659,
267,
283,
604,
63,
4494,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
6088,
14,
7212,
14,
604,
14,
1294,
14,
1278,
297,
283,
9819,
63,
4494,
63,
344,
297,
283,
3571,
4860,
83,
659,
1362,
789,
339,
347,
849,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
1504,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
2777,
63,
344,
275,
1067,
436,
1067,
14,
362,
360,
2682,
63,
344,
297,
797,
9,
267,
522,
275,
1052,
267,
1004,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
7212,
14,
604,
1959,
4570,
8,
1556,
12,
1747,
12,
2777,
63,
344,
12,
1067,
29,
1100,
9,
267,
340,
283,
2558,
63,
344,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
344,
356,
604,
14,
2558,
63,
344,
14,
344,
1552,
267,
340,
283,
2558,
63,
7519,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
2558,
63,
7519,
356,
1004,
14,
2558,
63,
7519,
14,
344,
1552,
267,
340,
283,
5643,
7,
315,
1504,
26,
288,
522,
14,
873,
3252,
5643,
356,
1004,
14,
2558,
63,
5643,
1552,
267,
372,
522,
339,
347,
3715,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1004,
63,
1580,
12,
1067,
29,
403,
304,
267,
408,
4005,
3715,
10952,
8200,
2385,
7182,
370,
3012,
5579,
14,
398,
520,
635,
1004,
63,
1580,
26,
314,
2870,
503,
769,
402,
11449,
402,
8200,
2385,
781,
2934,
370,
3715,
267,
408,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
702,
1067,
14,
362,
360,
2682,
63,
1238,
358,
508,
283,
6088,
14,
7212,
14,
604,
30989,
1467,
283,
18298,
675,
402,
314,
8200,
1004,
3715,
12262,
3530,
267,
12441,
1653,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
10777,
14,
1653,
358,
267,
8190,
63,
4041,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
4041,
358,
267,
1004,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
6088,
14,
7212,
14,
604,
358,
267,
892,
63,
604,
275,
942,
267,
367,
666,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
367,
4572,
63,
604,
315,
1004,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1004,
63,
1580,
12,
1067,
29,
1100,
304,
355,
1004,
63,
5643,
275,
4572,
63,
604,
14,
2558,
63,
5643,
355,
12524,
63,
3911,
275,
4572,
63,
604,
14,
2558,
63,
5643,
355,
892,
63,
604,
275,
942,
355,
340,
666,
14,
1180,
63,
4494,
26,
490,
2385,
275,
359,
76,
367,
634,
315,
666,
14,
604,
63,
4494,
63,
1580,
340,
634,
61,
355,
587,
26,
490,
2385,
275,
359,
76,
367,
634,
315,
666,
14,
604,
63,
1580,
340,
634,
61,
355,
367,
1004,
315,
2385,
26,
490,
12524,
275,
1004,
14,
10577,
490,
340,
12524,
2695,
378,
503,
1004,
63,
5643,
508,
378,
26,
717,
1980,
490,
12524,
63,
3911,
4862,
12524,
490,
340,
12524,
63,
3911,
665,
378,
26,
717,
12524,
63,
3911,
275,
12524,
717,
2059,
490,
849,
63,
637,
275,
469,
717,
283,
2558,
63,
5643,
356,
12524,
12,
490,
789,
490,
340,
12524,
63,
3911,
690,
378,
26,
717,
1453,
63,
604,
275,
1004,
63,
1113,
14,
1574,
8,
1556,
12,
1747,
12,
4572,
63,
604,
14,
344,
12,
849,
63,
637,
9,
717,
892,
63,
604,
14,
740,
8,
1818,
63,
604,
9,
490,
340,
12524,
63,
3911,
508,
378,
26,
717,
1453,
63,
604,
275,
4572,
63,
604,
14,
344,
490,
12441,
1653,
63,
344,
275,
756,
490,
340,
666,
14,
1180,
63,
4494,
26,
717,
12441,
1653,
63,
344,
275,
1004,
14,
8788,
1653,
63,
344,
14,
344,
490,
340,
440,
12441,
1653,
63,
344,
26,
717,
12441,
1653,
63,
344,
275,
12441,
1653,
63,
1113,
14,
981,
8,
1556,
12,
1747,
12,
469,
1169,
283,
354,
356,
1004,
14,
354,
12,
1169,
283,
2558,
63,
344,
356,
4572,
63,
604,
14,
2558,
63,
344,
14,
344,
1386,
717,
1067,
29,
1100,
9,
490,
1004,
63,
1113,
14,
952,
8,
1556,
12,
1747,
12,
359,
1818,
63,
604,
467,
791,
8788,
63,
1653,
63,
344,
356,
12441,
1653,
63,
344,
1552,
490,
12441,
1653,
275,
12441,
1653,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
12441,
1653,
63,
344,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nuncjo/odoo
|
addons/account_analytic_plans/report/__init__.py
|
445
|
1084
|
# -*- 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 crossovered_analytic
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
8059,
79,
10050,
63,
9782,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
8059,
79,
10050,
63,
9782,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jamiebull1/eppy
|
docs/Outputs_Tutorial.py
|
3
|
11037
|
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <headingcell level=1>
# Reading outputs from E+
# <codecell>
# some initial set up
# if you have not installed epp, and only downloaded it
# you will need the following lines
import sys
# pathnameto_eppy = 'c:/eppy'
pathnameto_eppy = '../'
sys.path.append(pathnameto_eppy)
# <headingcell level=2>
# Using titletable() to get at the tables
# <markdowncell>
# So far we have been making changes to the IDF input file.
# How about looking at the outputs.
#
# Energyplus makes nice htmlout files that look like this.
# <codecell>
from eppy import ex_inits #no need to know this code, it just shows the image below
for_images = ex_inits
for_images.display_png(for_images.html_snippet1) #display the image below
# <markdowncell>
# If you look at the clipping of the html file above, you see tables with data in them. Eppy has functions that let you access of these tables and get the data from any of it's cells.
#
# Let us say you want to find the "Net Site Energy".
#
# This is in table "Site and Source Energy".
#
# The number you want is in the third row, second column and it's value is "47694.47"
#
# Let us use eppy to extract this number
# <codecell>
from eppy import readhtml # the eppy module with functions to read the html
fname = "../eppy/resources/outputfiles/V_7_2/5ZoneCAVtoVAVWarmestTempFlowTable_ABUPS.html" # the html file you want to read
filehandle = open(fname, 'r').read() # get a file handle to the html file
htables = readhtml.titletable(filehandle) # reads the tables with their titles
# <markdowncell>
# If you open the python file readhtml.py and look at the function titletable, you can see the function documentation.
#
# It says the following
# <rawcell>
# """return a list of [(title, table), .....]
# title = previous item with a <b> tag
# table = rows -> [[cell1, cell2, ..], [cell1, cell2, ..], ..]"""
#
# <markdowncell>
# The documentation says that it returns a list.
# Let us take a look inside this list.
# Let us look at the first item in the list.
# <codecell>
firstitem = htables[0]
print(firstitem)
# <markdowncell>
# Ughh !!! that is ugly. Hard to see what it is.
# Let us use a python module to print it pretty
# <codecell>
import pprint
pp = pprint.PrettyPrinter()
pp.pprint(firstitem)
# <markdowncell>
# Nice. that is a little clearer
# <codecell>
firstitem_title = firstitem[0]
pp.pprint(firstitem_title)
# <codecell>
firstitem_table = firstitem[1]
pp.pprint(firstitem_table)
# <markdowncell>
# How do we get to value of "Net Site Energy".
# We know it is in the third row, second column of the table.
#
# Easy.
# <codecell>
thirdrow = firstitem_table[2] # we start counting with 0. So 0, 1, 2 is third row
print(thirdrow)
# <codecell>
thirdrow_secondcolumn = thirdrow[1]
thirdrow_secondcolumn
# <markdowncell>
# the text from the html table is in unicode.
# That is why you see that weird 'u' letter.
#
# Let us convert it to a floating point number
# <codecell>
net_site_energy = float(thirdrow_secondcolumn)
net_site_energy
# <markdowncell>
# Let us have a little fun with the tables.
#
# Get the titles of all the tables
# <codecell>
alltitles = [htable[0] for htable in htables]
alltitles
# <markdowncell>
# Now let us grab the tables with the titles "Building Area" and "Site to Source Energy Conversion Factors"
# <markdowncell>
# twotables = [htable for htable in htables if htable[0] in ["Building Area", "Site to Source Energy Conversion Factors"]]
# twotables
# <markdowncell>
# Let us leave readtables for now.
#
# It gives us the basic functionality to read any of the tables in the html output file.
# <headingcell level=2>
# Using lines_table() to get at the tables
# <markdowncell>
# We have been using titletable() to get at the tables. There is a constraint using function titletable(). Titletable() assumes that there is a unique title (in HTML bold) just above the table. It is assumed that this title will adequetly describe the table. This is true in most cases and titletable() is perfectly good to use. Unfortuntely there are some tables that do not follow this rule. The snippet below shows one of them.
# <codecell>
from eppy import ex_inits #no need to know this code, it just shows the image below
for_images = ex_inits
for_images.display_png(for_images.html_snippet2) # display the image below
# <markdowncell>
# Notice that the HTML snippet shows a table with three lines above it. The first two lines have information that describe the table. We need to look at both those lines to understand what the table contains. So we need a different function that will capture all those lines before the table. The funtion lines_table() described below will do this.
# <codecell>
from eppy import readhtml # the eppy module with functions to read the html
fname = "../eppy/resources/outputfiles/V_8_1/ASHRAE30pct.PI.Final11_OfficeMedium_STD2010_Chicago-baseTable.html" # the html file you want to read
filehandle = open(fname, 'r').read() # get a file handle to the html file
ltables = readhtml.lines_table(filehandle) # reads the tables with their titles
# <markdowncell>
# The html snippet shown above is the last table in HTML file we just opened. We have used lines_table() to read the tables into the variable ltables. We can get to the last table by ltable[-1]. Let us print it and see what we have.
# <codecell>
import pprint
pp = pprint.PrettyPrinter()
pp.pprint(ltables[-1])
# <markdowncell>
# We can see that ltables has captured all the lines before the table. Let us make our code more explicit to see this
# <codecell>
last_ltable = ltables[-1]
lines_before_table = last_ltable[0]
table_itself = last_ltable[-1]
pp.pprint(lines_before_table)
# <markdowncell>
# We found this table the easy way this time, because we knew it was the last one. How do we find it if we don't know where it is in the file ? Python comes to our rescue :-) Let assume that we want to find the table that has the following two lines before it.
#
# - Report: FANGER DURING COOLING AND ADAPTIVE COMFORT
# - For: PERIMETER_MID_ZN_4
# <codecell>
line1 = 'Report: FANGER DURING COOLING AND ADAPTIVE COMFORT'
line2 = 'For: PERIMETER_MID_ZN_4'
#
# check if those two lines are before the table
line1 in lines_before_table and line2 in lines_before_table
# <codecell>
# find all the tables where those two lines are before the table
[ltable for ltable in ltables
if line1 in ltable[0] and line2 in ltable[0]]
# <markdowncell>
# That worked !
#
# What if you want to find the words "FANGER" and "PERIMETER_MID_ZN_4" before the table. The following code will do it.
# <codecell>
# sample code to illustrate what we are going to do
last_ltable = ltables[-1]
lines_before_table = last_ltable[0]
table_itself = last_ltable[-1]
# join lines_before_table into a paragraph of text
justtext = '\n'.join(lines_before_table)
print(justtext)
# <codecell>
"FANGER" in justtext and "PERIMETER_MID_ZN_4" in justtext
# <codecell>
# Let us combine the this trick to find the table
[ltable for ltable in ltables
if "FANGER" in '\n'.join(ltable[0]) and "PERIMETER_MID_ZN_4" in '\n'.join(ltable[0])]
# <headingcell level=2>
# Extracting data from the tables
# <markdowncell>
# The tables in the HTML page in general have text in the top header row. The first vertical row has text. The remaining cells have numbers. We can identify the numbers we need by looking at the labelin the top row and the label in the first column. Let us construct a simple example and explore this.
# <codecell>
# ignore the following three lines. I am using them to construct the table below
from IPython.display import HTML
atablestring = '<TABLE cellpadding="4" style="border: 1px solid #000000; border-collapse: collapse;" border="1">\n <TR>\n <TD> </TD>\n <TD>a b</TD>\n <TD>b c</TD>\n <TD>c d</TD>\n </TR>\n <TR>\n <TD>x y</TD>\n <TD>1</TD>\n <TD>2</TD>\n <TD>3</TD>\n </TR>\n <TR>\n <TD>y z</TD>\n <TD>4</TD>\n <TD>5</TD>\n <TD>6</TD>\n </TR>\n <TR>\n <TD>z z</TD>\n <TD>7</TD>\n <TD>8</TD>\n <TD>9</TD>\n </TR>\n</TABLE>'
HTML(atablestring)
# <markdowncell>
# This table is actually in the follwoing form:
# <codecell>
atable = [["", "a b", "b c", "c d"],
["x y", 1, 2, 3 ],
["y z", 4, 5, 6 ],
["z z", 7, 8, 9 ],]
# <markdowncell>
# We can see the labels in the table. So we an look at row "x y" and column "c d". The value there is 3
# <markdowncell>
# right now we can get to it by saying atable[1][3]
# <codecell>
print(atable[1][3])
# <markdowncell>
# readhtml has some functions that will let us address the values by the labels. We use a structure from python called named tuples to do this. The only limitation is that the labels have to be letters or digits. Named tuples does not allow spaces in the labels. We could replace the space with an underscore ' _ '. So "a b" will become "a_b". So we can look for row "x_y" and column "c_d". Let us try this out.
# <codecell>
from eppy import readhtml
h_table = readhtml.named_grid_h(atable)
# <codecell>
print(h_table.x_y.c_d)
# <markdowncell>
# We can still get to the value by index
# <codecell>
print(h_table[0][2])
# <markdowncell>
# Note that we used atable[1][3], but here we used h_table[0][2]. That is because h_table does not count the rows and columns where the labels are.
# <markdowncell>
# We can also do the following:
# <codecell>
print(h_table.x_y[2])
# or
print(h_table[0].c_d)
# <markdowncell>
# Wow … that is pretty cool. What if we want to just check what the labels are ?
# <codecell>
print(h_table._fields)
# <markdowncell>
# That gives us the horizontal lables. How about the vertical labels ?
# <codecell>
h_table.x_y._fields
# <markdowncell>
# There you go !!!
# <markdowncell>
# How about if I want to use the labels differently ? Say I want to refer to the row first and then to the column. That woul be saying table.c_d.x_y. We can do that by using a different function
# <codecell>
v_table = readhtml.named_grid_v(atable)
print(v_table.c_d.x_y)
# <markdowncell>
# And we can do the following
# <codecell>
print(v_table[2][0])
print(v_table.c_d[0])
print(v_table[2].x_y)
# <markdowncell>
# Let us try to get the numbers in the first column and then get their sum
# <codecell>
v_table.a_b
# <markdowncell>
# Look like we got the right column. But not in the right format. We really need a list of numbers
# <codecell>
[cell for cell in v_table.a_b]
# <markdowncell>
# That looks like waht we wanted. Now let us get the sum
# <codecell>
values_in_first_column = [cell for cell in v_table.a_b]
print(values_in_first_column)
print(sum(values_in_first_column)) # sum is a builtin function that will sum a list
# <markdowncell>
# To get the first row we use the variable h_table
# <codecell>
values_in_first_row = [cell for cell in h_table.x_y]
print(values_in_first_row)
print(sum(values_in_first_row))
# <codecell>
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
665,
4994,
908,
30,
19,
14,
16,
1108,
4994,
908,
30,
199,
199,
3,
665,
13983,
3890,
2166,
29,
17,
30,
199,
199,
3,
799,
5384,
4704,
687,
662,
11,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
3,
2005,
2536,
663,
1536,
199,
3,
340,
1265,
1172,
440,
4903,
325,
802,
12,
436,
1454,
13557,
652,
199,
3,
1265,
911,
1929,
314,
2569,
2385,
199,
646,
984,
199,
3,
11776,
475,
63,
1545,
647,
275,
283,
67,
11254,
1545,
647,
7,
199,
12445,
475,
63,
1545,
647,
275,
11541,
4805,
199,
1274,
14,
515,
14,
740,
8,
12445,
475,
63,
1545,
647,
9,
9948,
199,
3,
665,
13983,
3890,
2166,
29,
18,
30,
199,
199,
3,
11719,
2538,
1224,
342,
370,
664,
737,
314,
6716,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
2002,
12474,
781,
1172,
2757,
10663,
4493,
370,
314,
2870,
38,
1324,
570,
14,
199,
3,
7494,
3595,
10023,
737,
314,
4704,
14,
199,
3,
221,
199,
3,
662,
1372,
4312,
6666,
7704,
14213,
30010,
22316,
1584,
626,
3648,
2839,
642,
14,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
504,
5442,
647,
492,
444,
63,
826,
83,
327,
889,
1929,
370,
5715,
642,
1233,
12,
652,
2951,
13703,
314,
1834,
5084,
199,
509,
63,
4782,
275,
444,
63,
826,
83,
199,
509,
63,
4782,
14,
2918,
63,
4524,
8,
509,
63,
4782,
14,
1360,
63,
18547,
17,
9,
327,
2918,
314,
1834,
5084,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
982,
1265,
3648,
737,
314,
5053,
3637,
402,
314,
3517,
570,
3432,
12,
1265,
1937,
6716,
543,
666,
315,
3062,
14,
27255,
647,
965,
3423,
626,
4691,
1265,
2879,
402,
3520,
6716,
436,
664,
314,
666,
687,
1263,
402,
652,
1159,
10106,
14,
199,
3,
221,
199,
3,
12230,
2739,
14722,
1265,
2934,
370,
2342,
314,
298,
2480,
11666,
662,
1372,
4312,
1674,
257,
199,
3,
221,
199,
3,
961,
365,
315,
1817,
298,
8972,
436,
5800,
662,
1372,
4312,
1674,
257,
199,
3,
221,
199,
3,
710,
1329,
1265,
2934,
365,
315,
314,
10919,
1962,
12,
3499,
2763,
436,
652,
1159,
574,
365,
298,
2417,
19421,
14,
2417,
2,
199,
3,
221,
199,
3,
12230,
2739,
675,
5442,
647,
370,
5536,
642,
1329,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
504,
5442,
647,
492,
1586,
1360,
327,
314,
5442,
647,
859,
543,
3423,
370,
1586,
314,
3517,
199,
5252,
275,
29024,
1545,
647,
15,
4435,
15,
1199,
1725,
15,
54,
63,
23,
63,
18,
15,
21,
11860,
3263,
54,
475,
54,
6087,
55,
285,
278,
270,
6530,
5060,
3186,
63,
1217,
2160,
51,
14,
1360,
2,
327,
314,
3517,
570,
1265,
2934,
370,
1586,
199,
493,
2479,
275,
1551,
8,
5252,
12,
283,
82,
1959,
739,
342,
327,
664,
282,
570,
2429,
370,
314,
3517,
570,
421,
199,
517,
5921,
275,
1586,
1360,
14,
1213,
1224,
8,
493,
2479,
9,
327,
11597,
314,
6716,
543,
3932,
16194,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
982,
1265,
1551,
314,
2366,
570,
1586,
1360,
14,
647,
436,
3648,
737,
314,
805,
2538,
1224,
12,
1265,
883,
1937,
314,
805,
3794,
14,
199,
3,
221,
199,
3,
2779,
20065,
314,
2569,
199,
199,
3,
665,
1773,
3890,
30,
199,
199,
3,
258,
408,
1107,
282,
769,
402,
3842,
1213,
12,
1817,
395,
2508,
18737,
199,
3,
258,
2538,
275,
4136,
1242,
543,
282,
665,
66,
30,
1947,
199,
3,
258,
1817,
275,
4730,
1035,
3474,
3890,
17,
12,
4917,
18,
12,
2508,
467,
359,
3890,
17,
12,
4917,
18,
12,
2508,
467,
2508,
61,
624,
199,
3,
420,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
710,
3794,
20065,
626,
652,
2529,
282,
769,
14,
199,
3,
12230,
2739,
5452,
282,
3648,
6272,
642,
769,
14,
199,
3,
12230,
2739,
3648,
737,
314,
1642,
1242,
315,
314,
769,
14,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
2246,
1053,
275,
394,
5987,
59,
16,
61,
199,
1361,
8,
2246,
1053,
9,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
738,
3561,
72,
221,
21512,
626,
365,
23761,
14,
22825,
370,
1937,
4052,
652,
365,
14,
257,
199,
3,
12230,
2739,
675,
282,
2366,
859,
370,
870,
652,
7268,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
646,
10933,
199,
802,
275,
10933,
14,
27153,
14131,
342,
199,
802,
14,
15380,
8,
2246,
1053,
9,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
653,
1885,
14,
626,
365,
282,
12050,
15158,
21462,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
2246,
1053,
63,
1213,
275,
1642,
1053,
59,
16,
61,
199,
802,
14,
15380,
8,
2246,
1053,
63,
1213,
9,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
2246,
1053,
63,
1224,
275,
1642,
1053,
59,
17,
61,
199,
802,
14,
15380,
8,
2246,
1053,
63,
1224,
9,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
7494,
886,
781,
664,
370,
574,
402,
298,
2480,
11666,
662,
1372,
4312,
1674,
257,
199,
3,
2136,
5715,
652,
365,
315,
314,
10919,
1962,
12,
3499,
2763,
402,
314,
1817,
14,
257,
199,
3,
221,
199,
3,
18951,
14,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
11470,
1143,
275,
1642,
1053,
63,
1224,
59,
18,
61,
327,
781,
1343,
23190,
543,
378,
14,
2002,
378,
12,
413,
12,
499,
365,
10919,
1962,
199,
1361,
8,
11470,
1143,
9,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
11470,
1143,
63,
4375,
2301,
275,
10919,
1143,
59,
17,
61,
199,
11470,
1143,
63,
4375,
2301,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
314,
1318,
687,
314,
3517,
1817,
365,
315,
2649,
14,
257,
199,
3,
10314,
365,
10842,
1265,
1937,
626,
22965,
283,
85,
7,
8082,
14,
257,
199,
3,
221,
199,
3,
12230,
2739,
3957,
652,
370,
282,
8402,
2376,
1329,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
846,
63,
2124,
63,
8443,
275,
2069,
8,
11470,
1143,
63,
4375,
2301,
9,
199,
846,
63,
2124,
63,
8443,
199,
199,
3,
665,
15653,
3890
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
665,
4994,
908,
30,
19,
14,
16,
1108,
4994,
908,
30,
199,
199,
3,
665,
13983,
3890,
2166,
29,
17,
30,
199,
199,
3,
799,
5384,
4704,
687,
662,
11,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
3,
2005,
2536,
663,
1536,
199,
3,
340,
1265,
1172,
440,
4903,
325,
802,
12,
436,
1454,
13557,
652,
199,
3,
1265,
911,
1929,
314,
2569,
2385,
199,
646,
984,
199,
3,
11776,
475,
63,
1545,
647,
275,
283,
67,
11254,
1545,
647,
7,
199,
12445,
475,
63,
1545,
647,
275,
11541,
4805,
199,
1274,
14,
515,
14,
740,
8,
12445,
475,
63,
1545,
647,
9,
9948,
199,
3,
665,
13983,
3890,
2166,
29,
18,
30,
199,
199,
3,
11719,
2538,
1224,
342,
370,
664,
737,
314,
6716,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
2002,
12474,
781,
1172,
2757,
10663,
4493,
370,
314,
2870,
38,
1324,
570,
14,
199,
3,
7494,
3595,
10023,
737,
314,
4704,
14,
199,
3,
221,
199,
3,
662,
1372,
4312,
6666,
7704,
14213,
30010,
22316,
1584,
626,
3648,
2839,
642,
14,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
504,
5442,
647,
492,
444,
63,
826,
83,
327,
889,
1929,
370,
5715,
642,
1233,
12,
652,
2951,
13703,
314,
1834,
5084,
199,
509,
63,
4782,
275,
444,
63,
826,
83,
199,
509,
63,
4782,
14,
2918,
63,
4524,
8,
509,
63,
4782,
14,
1360,
63,
18547,
17,
9,
327,
2918,
314,
1834,
5084,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
982,
1265,
3648,
737,
314,
5053,
3637,
402,
314,
3517,
570,
3432,
12,
1265,
1937,
6716,
543,
666,
315,
3062,
14,
27255,
647,
965,
3423,
626,
4691,
1265,
2879,
402,
3520,
6716,
436,
664,
314,
666,
687,
1263,
402,
652,
1159,
10106,
14,
199,
3,
221,
199,
3,
12230,
2739,
14722,
1265,
2934,
370,
2342,
314,
298,
2480,
11666,
662,
1372,
4312,
1674,
257,
199,
3,
221,
199,
3,
961,
365,
315,
1817,
298,
8972,
436,
5800,
662,
1372,
4312,
1674,
257,
199,
3,
221,
199,
3,
710,
1329,
1265,
2934,
365,
315,
314,
10919,
1962,
12,
3499,
2763,
436,
652,
1159,
574,
365,
298,
2417,
19421,
14,
2417,
2,
199,
3,
221,
199,
3,
12230,
2739,
675,
5442,
647,
370,
5536,
642,
1329,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
504,
5442,
647,
492,
1586,
1360,
327,
314,
5442,
647,
859,
543,
3423,
370,
1586,
314,
3517,
199,
5252,
275,
29024,
1545,
647,
15,
4435,
15,
1199,
1725,
15,
54,
63,
23,
63,
18,
15,
21,
11860,
3263,
54,
475,
54,
6087,
55,
285,
278,
270,
6530,
5060,
3186,
63,
1217,
2160,
51,
14,
1360,
2,
327,
314,
3517,
570,
1265,
2934,
370,
1586,
199,
493,
2479,
275,
1551,
8,
5252,
12,
283,
82,
1959,
739,
342,
327,
664,
282,
570,
2429,
370,
314,
3517,
570,
421,
199,
517,
5921,
275,
1586,
1360,
14,
1213,
1224,
8,
493,
2479,
9,
327,
11597,
314,
6716,
543,
3932,
16194,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
982,
1265,
1551,
314,
2366,
570,
1586,
1360,
14,
647,
436,
3648,
737,
314,
805,
2538,
1224,
12,
1265,
883,
1937,
314,
805,
3794,
14,
199,
3,
221,
199,
3,
2779,
20065,
314,
2569,
199,
199,
3,
665,
1773,
3890,
30,
199,
199,
3,
258,
408,
1107,
282,
769,
402,
3842,
1213,
12,
1817,
395,
2508,
18737,
199,
3,
258,
2538,
275,
4136,
1242,
543,
282,
665,
66,
30,
1947,
199,
3,
258,
1817,
275,
4730,
1035,
3474,
3890,
17,
12,
4917,
18,
12,
2508,
467,
359,
3890,
17,
12,
4917,
18,
12,
2508,
467,
2508,
61,
624,
199,
3,
420,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
710,
3794,
20065,
626,
652,
2529,
282,
769,
14,
199,
3,
12230,
2739,
5452,
282,
3648,
6272,
642,
769,
14,
199,
3,
12230,
2739,
3648,
737,
314,
1642,
1242,
315,
314,
769,
14,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
2246,
1053,
275,
394,
5987,
59,
16,
61,
199,
1361,
8,
2246,
1053,
9,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
738,
3561,
72,
221,
21512,
626,
365,
23761,
14,
22825,
370,
1937,
4052,
652,
365,
14,
257,
199,
3,
12230,
2739,
675,
282,
2366,
859,
370,
870,
652,
7268,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
646,
10933,
199,
802,
275,
10933,
14,
27153,
14131,
342,
199,
802,
14,
15380,
8,
2246,
1053,
9,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
653,
1885,
14,
626,
365,
282,
12050,
15158,
21462,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
2246,
1053,
63,
1213,
275,
1642,
1053,
59,
16,
61,
199,
802,
14,
15380,
8,
2246,
1053,
63,
1213,
9,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
2246,
1053,
63,
1224,
275,
1642,
1053,
59,
17,
61,
199,
802,
14,
15380,
8,
2246,
1053,
63,
1224,
9,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
7494,
886,
781,
664,
370,
574,
402,
298,
2480,
11666,
662,
1372,
4312,
1674,
257,
199,
3,
2136,
5715,
652,
365,
315,
314,
10919,
1962,
12,
3499,
2763,
402,
314,
1817,
14,
257,
199,
3,
221,
199,
3,
18951,
14,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
11470,
1143,
275,
1642,
1053,
63,
1224,
59,
18,
61,
327,
781,
1343,
23190,
543,
378,
14,
2002,
378,
12,
413,
12,
499,
365,
10919,
1962,
199,
1361,
8,
11470,
1143,
9,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
11470,
1143,
63,
4375,
2301,
275,
10919,
1143,
59,
17,
61,
199,
11470,
1143,
63,
4375,
2301,
199,
199,
3,
665,
15653,
3890,
30,
199,
199,
3,
314,
1318,
687,
314,
3517,
1817,
365,
315,
2649,
14,
257,
199,
3,
10314,
365,
10842,
1265,
1937,
626,
22965,
283,
85,
7,
8082,
14,
257,
199,
3,
221,
199,
3,
12230,
2739,
3957,
652,
370,
282,
8402,
2376,
1329,
199,
199,
3,
665,
600,
3890,
30,
199,
199,
846,
63,
2124,
63,
8443,
275,
2069,
8,
11470,
1143,
63,
4375,
2301,
9,
199,
846,
63,
2124,
63,
8443,
199,
199,
3,
665,
15653,
3890,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wkerzendorf/wsynphot
|
wsynphot/base.py
|
1
|
15987
|
# defining the base filter curve classes
import os
from scipy import interpolate
from wsynphot.spectrum1d import SKSpectrum1D as Spectrum1D
import pandas as pd
from wsynphot.io.cache_filters import load_filter_index, load_transmission_data
from astropy import units as u, constants as const
from astropy import utils
import numpy as np
from wsynphot.calibration import get_vega_calibration_spectrum
def calculate_filter_flux_density(spectrum, filter):
"""
Calculate the average flux through the filter by evaluating the integral
..math::
f_lambda = \\frac{\\int_}{}
Parameters
----------
spectrum: ~specutils.Spectrum1D
spectrum object
filter: ~wsynphot.FilterCurve
:return:
"""
filtered_spectrum = filter * spectrum
filter_flux_density = np.trapz(filtered_spectrum.flux * filtered_spectrum.wavelength,
filtered_spectrum.wavelength)
return filter_flux_density
def calculate_vega_magnitude(spectrum, filter):
filter_flux_density = calculate_filter_flux_density(spectrum, filter)
wavelength_delta = filter.calculate_wavelength_delta()
filtered_f_lambda = (filter_flux_density / wavelength_delta)
zp_vega_f_lambda = filter.zp_vega_f_lambda
return -2.5 * np.log10(filtered_f_lambda / zp_vega_f_lambda)
def calculate_ab_magnitude(spectrum, filter):
filtered_f_lambda = (calculate_filter_flux_density(spectrum, filter) /
filter.calculate_wavelength_delta())
return -2.5 * np.log10(filtered_f_lambda / filter.zp_ab_f_lambda)
def list_filters():
"""
List available filter sets along with their properties
"""
return load_filter_index()
class BaseFilterCurve(object):
"""
Basic filter curve class
Parameters
----------
wavelength: ~astropy.units.Quantity
wavelength for filter curve
transmission_lambda: numpy.ndarray
transmission_lambda for filter curve
interpolation_kind: str
allowed interpolation kinds given in scipy.interpolate.interp1d
"""
@classmethod
def load_filter(cls, filter_id=None, interpolation_kind='linear'):
"""
Parameters
----------
filter_id: str or None
if None is provided will return a DataFrame of all filters
interpolation_kind: str
see scipy.interpolation.interp1d
"""
if filter_id is None:
return list_filters()
else:
filter = load_transmission_data(filter_id)
wavelength_unit = 'angstrom'
wavelength = filter['Wavelength'].values * u.Unit(wavelength_unit)
return cls(wavelength, filter['Transmission'].values,
interpolation_kind=interpolation_kind,
filter_id=filter_id)
def __init__(self, wavelength, transmission_lambda,
interpolation_kind='linear', filter_id=None):
if not hasattr(wavelength, 'unit'):
raise ValueError('the wavelength needs to be a astropy quantity')
self.wavelength = wavelength
self.transmission_lambda = transmission_lambda
self.interpolation_object = interpolate.interp1d(self.wavelength,
self.transmission_lambda,
kind=interpolation_kind,
bounds_error=False,
fill_value=0.0)
self.filter_id = filter_id
def __mul__(self, other):
if not hasattr(other, 'flux') or not hasattr(other, 'wavelength'):
raise ValueError('requiring a specutils.Spectrum1D-like object that'
'has attributes "flux" and "wavelength"')
#new_wavelength = np.union1d(other.wavelength.to(self.wavelength.unit).value,
# self.wavelength.value) * self.wavelength.unit
transmission = self.interpolate(other.wavelength)
return Spectrum1D.from_array(other.wavelength, transmission * other.flux)
def __rmul__(self, other):
return self.__mul__(other)
@utils.lazyproperty
def lambda_pivot(self):
"""
Calculate the pivotal wavelength as defined in Bessell & Murphy 2012
.. math::
\\lambda_\\textrm{pivot} = \\sqrt{
\\frac{\\int S(\\lambda)\\lambda d\\lambda}{\\int \\frac{S(\\lambda)}{\\lambda}}}\\\\
<f_\\nu> = <f_\\lambda>\\frac{\\lambda_\\textrm{pivot}^2}{c}
"""
return np.sqrt((np.trapz(self.transmission_lambda * self.wavelength, self.wavelength)/
(np.trapz(self.transmission_lambda / self.wavelength, self.wavelength))))
@utils.lazyproperty
def wavelength_start(self):
return self.get_wavelength_start()
@utils.lazyproperty
def wavelength_end(self):
return self.get_wavelength_end()
@utils.lazyproperty
def zp_ab_f_lambda(self):
return (self.zp_ab_f_nu * const.c / self.lambda_pivot**2).to(
'erg/s/cm^2/Angstrom', u.spectral())
@utils.lazyproperty
def zp_ab_f_nu(self):
return (3631 * u.Jy).to('erg/s/cm^2/Hz')
@utils.lazyproperty
def zp_vega_f_lambda(self):
return (calculate_filter_flux_density(get_vega_calibration_spectrum(), self) /
self.calculate_wavelength_delta())
def interpolate(self, wavelength):
"""
Interpolate the filter onto new wavelength grid
Parameters
----------
wavelength: ~astropy.units.Quantity
wavelength grid to interpolate on
"""
converted_wavelength = wavelength.to(self.wavelength.unit)
return self.interpolation_object(converted_wavelength)
def _calculuate_flux_density(self, wavelength, flux):
return _calculcate_filter_flux_density(flux, self)
def calculate_flux_density(self, spectrum):
return calculate_filter_flux_density(spectrum, self)
def calculate_f_lambda(self, spectrum):
return (self.calculate_flux_density(spectrum) /
self.calculate_wavelength_delta())
def calculate_wavelength_delta(self):
"""
Calculate the Integral :math:`\integral
:return:
"""
return np.trapz(self.transmission_lambda * self.wavelength,
self.wavelength)
def calculate_weighted_average_wavelength(self):
"""
Calculate integral :math:`\\frac{\\int S(\\lambda) \\lambda d\\lambda}{\\int S(\\lambda) d\\lambda}`
Returns
: ~astropy.units.Quantity
"""
return (np.trapz(self.transmission_lambda * self.wavelength,
self.wavelength) / self.calculate_wavelength_delta())
def calculate_vega_magnitude(self, spectrum):
__doc__ = calculate_vega_magnitude.__doc__
return calculate_vega_magnitude(spectrum, self)
def calculate_ab_magnitude(self, spectrum):
__doc__ = calculate_ab_magnitude.__doc__
return calculate_ab_magnitude(spectrum, self)
def convert_ab_magnitude_to_f_lambda(self, mag):
return 10**(-0.4*mag) * self.zp_ab_f_lambda
def convert_vega_magnitude_to_f_lambda(self, mag):
return 10**(-0.4*mag) * self.zp_vega_f_lambda
def plot(self, ax, scale_max=None, make_label=True, plot_kwargs={},
format_filter_id=None):
if scale_max is not None:
if hasattr(scale_max, 'unit'):
scale_max = scale_max.value
transmission = (self.transmission_lambda * scale_max
/ self.transmission_lambda.max())
else:
transmission = self.transmission_lambda
ax.plot(self.wavelength, transmission, **plot_kwargs)
ax.set_xlabel('Wavelength [{0}]'.format(
self.wavelength.unit.to_string(format='latex')))
ax.set_ylabel('Transmission [1]')
if make_label==True and self.filter_id is not None:
if format_filter_id is not None:
filter_id = format_filter_id(self.filter_id)
else:
filter_id = self.filter_id
text_x = (self.lambda_pivot).value
text_y = transmission.max()/2
ax.text(text_x, text_y, filter_id,
horizontalalignment='center', verticalalignment='center',
bbox=dict(facecolor='white', alpha=0.5))
def get_wavelength_start(self, threshold=0.01):
norm_cum_sum = (np.cumsum(self.transmission_lambda)
/ np.sum(self.transmission_lambda))
return self.wavelength[norm_cum_sum.searchsorted(threshold)]
def get_wavelength_end(self, threshold=0.01):
norm_cum_sum = (np.cumsum(self.transmission_lambda)
/ np.sum(self.transmission_lambda))
return self.wavelength[norm_cum_sum.searchsorted(1 - threshold)]
class FilterCurve(BaseFilterCurve):
def __repr__(self):
if self.filter_id is None:
filter_id = "{0:x}".format(self.__hash__())
else:
filter_id = self.filter_id
return "FilterCurve <{0}>".format(filter_id)
class FilterSet(object):
"""
A set of filters
Parameters
----------
filter_set: ~list
a list of strings or a list of filters
interpolation_kind: ~str
scipy interpolaton kinds
"""
def __init__(self, filter_set, interpolation_kind='linear'):
if hasattr(filter_set[0], 'wavelength'):
self.filter_set = filter_set
else:
self.filter_set = [FilterCurve.load_filter(filter_id,
interpolation_kind=
interpolation_kind)
for filter_id in filter_set]
def __iter__(self):
self.current_filter_idx = 0
return self
def __next__(self):
try:
item = self.filter_set[self.current_filter_idx]
except IndexError:
raise StopIteration
self.current_filter_idx += 1
return item
next = __next__
def __getitem__(self, item):
return self.filter_set.__getitem__(item)
def __repr__(self):
return "<{0} \n{1}>".format(self.__class__.__name__,
'\n'.join(
[item.filter_id
for item in self.filter_set]))
@property
def lambda_pivot(self):
return u.Quantity([item.lambda_pivot for item in self])
def calculate_f_lambda(self, spectrum):
return u.Quantity(
[item.calculate_f_lambda(spectrum) for item in self.filter_set])
def calculate_ab_magnitudes(self, spectrum):
mags = [item.calculate_ab_magnitude(spectrum)
for item in self.filter_set]
return mags
def calculate_vega_magnitudes(self, spectrum):
mags = [item.calculate_vega_magnitude(spectrum)
for item in self.filter_set]
return mags
def convert_ab_magnitudes_to_f_lambda(self, magnitudes):
if len(magnitudes) != len(self.filter_set):
raise ValueError("Filter set and magnitudes need to have the same "
"number of items")
f_lambdas = [filter.convert_ab_magnitude_to_f_lambda(mag)
for filter, mag in zip(self.filter_set, magnitudes)]
return u.Quantity(f_lambdas)
def convert_ab_magnitude_uncertainties_to_f_lambda_uncertainties(
self, magnitudes, magnitude_uncertainties):
if len(magnitudes) != len(self.filter_set):
raise ValueError("Filter set and magnitudes need to have the same "
"number of items")
f_lambda_positive_uncertainties = u.Quantity(
[filter.convert_ab_magnitude_to_f_lambda(mag + mag_uncertainty)
for filter, mag, mag_uncertainty in zip(
self.filter_set, magnitudes, magnitude_uncertainties, )])
f_lambda_negative_uncertainties = u.Quantity(
[filter.convert_ab_magnitude_to_f_lambda(mag - mag_uncertainty)
for filter, mag, mag_uncertainty in zip(
self.filter_set, magnitudes, magnitude_uncertainties)])
return np.abs(u.Quantity((f_lambda_positive_uncertainties,
f_lambda_negative_uncertainties))
- self.convert_ab_magnitudes_to_f_lambda(magnitudes))
def convert_vega_magnitude_uncertainties_to_f_lambda_uncertainties(
self, magnitudes, magnitude_uncertainties):
if len(magnitudes) != len(self.filter_set):
raise ValueError("Filter set and magnitudes need to have the same "
"number of items")
f_lambda_positive_uncertainties = u.Quantity(
[filter.convert_vega_magnitude_to_f_lambda(mag + mag_uncertainty)
for filter, mag, mag_uncertainty in zip(
self.filter_set, magnitudes, magnitude_uncertainties, )])
f_lambda_negative_uncertainties = u.Quantity(
[filter.convert_vega_magnitude_to_f_lambda(mag - mag_uncertainty)
for filter, mag, mag_uncertainty in zip(
self.filter_set, magnitudes, magnitude_uncertainties)])
return np.abs(u.Quantity((f_lambda_positive_uncertainties,
f_lambda_negative_uncertainties))
- self.convert_vega_magnitudes_to_f_lambda(magnitudes))
def convert_vega_magnitudes_to_f_lambda(self, magnitudes):
if len(magnitudes) != len(self.filter_set):
raise ValueError("Filter set and magnitudes need to have the same "
"number of items")
f_lambdas = [filter.convert_vega_magnitude_to_f_lambda(mag)
for filter, mag in zip(self.filter_set, magnitudes)]
return u.Quantity(f_lambdas)
def plot_spectrum(self, spectrum, ax, make_labels=True,
spectrum_plot_kwargs={}, filter_plot_kwargs={},
filter_color_list=None, format_filter_id=None):
"""
plot a spectrum with the given filters
spectrum:
ax:
make_labels:
:return:
"""
ax.plot(spectrum.wavelength, spectrum.flux, **spectrum_plot_kwargs)
for i, filter in enumerate(self.filter_set):
filter_scale = filter.calculate_f_lambda(spectrum)
if filter_color_list is not None:
filter_plot_kwargs['color'] = filter_color_list[i]
filter.plot(ax, scale_max=filter_scale, make_label=make_labels,
plot_kwargs=filter_plot_kwargs,
format_filter_id=format_filter_id)
class MagnitudeSet(FilterSet):
def __init__(self, filter_set, magnitudes, magnitude_uncertainties=None,
interpolation_kind='linear'):
super(MagnitudeSet, self).__init__(filter_set,
interpolation_kind=
interpolation_kind)
self.magnitudes = np.array(magnitudes)
self.magnitude_uncertainties = np.array(magnitude_uncertainties)
def __repr__(self):
mag_str = '{0} {1:.4f} +/- {2:.4f}'
mag_data = []
for i, filter in enumerate(self.filter_set):
unc = (np.nan if self.magnitude_uncertainties is None
else self.magnitude_uncertainties[i])
mag_data.append(mag_str.format(filter.filter_id,
self.magnitudes[i], unc))
return "<{0} \n{1}>".format(self.__class__.__name__,
'\n'.join(mag_data))
|
bsd-3-clause
|
[
3,
12669,
314,
1300,
2457,
15318,
3992,
199,
199,
646,
747,
199,
199,
504,
7026,
492,
28884,
199,
504,
336,
9466,
838,
357,
14,
18142,
17,
68,
492,
20062,
16684,
17,
36,
465,
428,
9120,
17,
36,
199,
646,
10634,
465,
6454,
199,
504,
336,
9466,
838,
357,
14,
2308,
14,
1637,
63,
4273,
492,
2248,
63,
1541,
63,
1080,
12,
2248,
63,
1515,
2250,
63,
576,
4388,
199,
504,
28753,
492,
6204,
465,
399,
12,
5262,
465,
950,
199,
199,
504,
28753,
492,
3778,
199,
646,
2680,
465,
980,
199,
504,
336,
9466,
838,
357,
14,
25851,
492,
664,
63,
432,
5294,
63,
25851,
63,
18142,
421,
199,
318,
8671,
63,
1541,
63,
14477,
63,
15669,
8,
18142,
12,
2457,
304,
272,
408,
272,
12707,
314,
8095,
21475,
4012,
314,
2457,
701,
27083,
314,
20583,
339,
2508,
3442,
447,
398,
289,
63,
2734,
275,
8522,
10865,
26156,
442,
63,
93,
2440,
272,
3897,
272,
4143,
339,
20645,
26,
6146,
1650,
1208,
14,
16684,
17,
36,
267,
20645,
909,
272,
2457,
26,
6146,
3569,
1236,
838,
357,
14,
4131,
20966,
339,
520,
1107,
26,
272,
408,
339,
9806,
63,
18142,
275,
2457,
627,
20645,
272,
2457,
63,
14477,
63,
15669,
275,
980,
14,
19510,
90,
8,
11142,
63,
18142,
14,
14477,
627,
9806,
63,
18142,
14,
10024,
1267,
12,
490,
9806,
63,
18142,
14,
10024,
1267,
9,
272,
372,
2457,
63,
14477,
63,
15669,
421,
199,
318,
8671,
63,
432,
5294,
63,
32167,
8,
18142,
12,
2457,
304,
272,
2457,
63,
14477,
63,
15669,
275,
8671,
63,
1541,
63,
14477,
63,
15669,
8,
18142,
12,
2457,
9,
272,
12204,
1267,
63,
3136,
275,
2457,
14,
12063,
63,
10024,
1267,
63,
3136,
342,
272,
9806,
63,
70,
63,
2734,
275,
334,
1541,
63,
14477,
63,
15669,
1182,
12204,
1267,
63,
3136,
9,
339,
1315,
80,
63,
432,
5294,
63,
70,
63,
2734,
275,
2457,
14,
90,
80,
63,
432,
5294,
63,
70,
63,
2734,
339,
372,
446,
18,
14,
21,
627,
980,
14,
793,
709,
8,
11142,
63,
70,
63,
2734,
1182,
1315,
80,
63,
432,
5294,
63,
70,
63,
2734,
9,
421,
199,
318,
8671,
63,
371,
63,
32167,
8,
18142,
12,
2457,
304,
272,
9806,
63,
70,
63,
2734,
275,
334,
12063,
63,
1541,
63,
14477,
63,
15669,
8,
18142,
12,
2457,
9,
1182,
586,
2457,
14,
12063,
63,
10024,
1267,
63,
3136,
1012,
339,
372,
446,
18,
14,
21,
627,
980,
14,
793,
709,
8,
11142,
63,
70,
63,
2734,
1182,
2457,
14,
90,
80,
63,
371,
63,
70,
63,
2734,
9,
421,
199,
318,
769,
63,
4273,
837,
272,
408,
272,
3820,
2808,
2457,
5951,
3180,
543,
3932,
4382,
272,
408,
272,
372,
2248,
63,
1541,
63,
1080,
342,
421,
199,
533,
3523,
4131,
20966,
8,
785,
304,
272,
408,
272,
10082,
2457,
15318,
1021,
339,
3897,
272,
4143,
339,
12204,
1267,
26,
6146,
1810,
7537,
14,
5260,
14,
19703,
267,
12204,
1267,
367,
2457,
15318,
339,
1752,
2250,
63,
2734,
26,
2680,
14,
8237,
267,
1752,
2250,
63,
2734,
367,
2457,
15318,
339,
14046,
63,
5091,
26,
620,
267,
4370,
14046,
24241,
1627,
315,
7026,
14,
21294,
14,
14252,
17,
68,
272,
408,
339,
768,
3744,
272,
347,
2248,
63,
1541,
8,
1886,
12,
2457,
63,
344,
29,
403,
12,
14046,
63,
5091,
534,
6676,
735,
267,
408,
398,
3897,
267,
4143,
398,
2457,
63,
344,
26,
620,
503,
488,
288,
340,
488,
365,
2741,
911,
372,
282,
10071,
402,
1006,
4766,
398,
14046,
63,
5091,
26,
620,
288,
1937,
7026,
14,
21080,
14,
14252,
17,
68,
10631,
408,
267,
340,
2457,
63,
344,
365,
488,
26,
288,
372,
769,
63,
4273,
342,
398,
587,
26,
288,
2457,
275,
2248,
63,
1515,
2250,
63,
576,
8,
1541,
63,
344,
9,
7846,
12204,
1267,
63,
3248,
275,
283,
621,
31672,
7,
953,
12204,
1267,
275,
2457,
459,
21393,
1267,
2278,
1459,
627,
399,
14,
5072,
8,
10024,
1267,
63,
3248,
9,
953,
372,
843,
8,
10024,
1267,
12,
2457,
459,
24011,
2278,
1459,
12,
2432,
14046,
63,
5091,
29,
21080,
63,
5091,
12,
2432,
2457,
63,
344,
29,
1541,
63,
344,
9,
2378,
347,
636,
826,
721,
277,
12,
12204,
1267,
12,
1752,
2250,
63,
2734,
12,
326,
14046,
63,
5091,
534,
6676,
297,
2457,
63,
344,
29,
403,
304,
267,
340,
440,
2688,
8,
10024,
1267,
12,
283,
3248,
735,
288,
746,
1722,
360,
1589,
12204,
1267,
4839,
370,
506,
282,
28753,
12524,
358,
267,
291,
14,
10024,
1267,
275,
12204,
1267,
267,
291,
14,
1515,
2250,
63,
2734,
275,
1752,
2250,
63,
2734,
398,
291,
14,
21080,
63,
785,
275,
28884,
14,
14252,
17,
68,
8,
277,
14,
10024,
1267,
12,
12740,
291,
14,
1515,
2250,
63,
2734,
12,
12740,
4928,
29,
21080,
63,
5091,
12,
12740,
10461,
63,
705,
29,
797,
12,
12740,
5554,
63,
585,
29,
16,
14,
16,
9,
267,
291,
14,
1541,
63,
344,
275,
2457,
63,
344,
2378,
347,
636,
3703,
721,
277,
12,
1163,
304,
267,
340,
440,
2688,
8,
1848,
12,
283,
14477,
358,
503,
440,
2688,
8,
1848,
12,
283,
10024,
1267,
735,
288,
746,
1722,
360,
264,
23729,
282,
3158,
1208,
14,
16684,
17,
36,
13,
2930,
909,
626,
7,
2490,
283,
1989,
3004,
298,
14477,
2,
436,
298,
10024,
1267,
9008,
398,
327,
1222,
63,
10024,
1267,
275,
980,
14,
8888,
17,
68,
8,
1848,
14,
10024,
1267,
14,
475,
8,
277,
14,
10024,
1267,
14,
3248,
680,
585,
12,
267,
327,
14960,
291,
14,
10024,
1267,
14,
585,
9,
627,
291,
14,
10024,
1267,
14,
3248,
267,
1752,
2250,
275,
291,
14,
21294,
8,
1848,
14,
10024,
1267,
9,
398,
372,
428,
9120,
17,
36,
14,
504,
63,
1144,
8,
1848,
14,
10024,
1267,
12,
1752,
2250,
627,
1163,
14,
14477,
9,
339,
347,
636,
27968,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
3703,
721,
1848,
9,
2378,
768,
1208,
14,
6395,
1829,
272,
347,
2400,
63,
21558,
8,
277,
304,
267,
408,
267,
12707,
314,
299,
1003,
1735,
12204,
1267,
465,
3247,
315,
699,
397,
23235,
1253,
603,
300,
6581,
6029,
398,
2508,
3473,
447,
953,
8522,
2734,
63,
1103,
505,
5682,
91,
21558,
93
] |
[
12669,
314,
1300,
2457,
15318,
3992,
199,
199,
646,
747,
199,
199,
504,
7026,
492,
28884,
199,
504,
336,
9466,
838,
357,
14,
18142,
17,
68,
492,
20062,
16684,
17,
36,
465,
428,
9120,
17,
36,
199,
646,
10634,
465,
6454,
199,
504,
336,
9466,
838,
357,
14,
2308,
14,
1637,
63,
4273,
492,
2248,
63,
1541,
63,
1080,
12,
2248,
63,
1515,
2250,
63,
576,
4388,
199,
504,
28753,
492,
6204,
465,
399,
12,
5262,
465,
950,
199,
199,
504,
28753,
492,
3778,
199,
646,
2680,
465,
980,
199,
504,
336,
9466,
838,
357,
14,
25851,
492,
664,
63,
432,
5294,
63,
25851,
63,
18142,
421,
199,
318,
8671,
63,
1541,
63,
14477,
63,
15669,
8,
18142,
12,
2457,
304,
272,
408,
272,
12707,
314,
8095,
21475,
4012,
314,
2457,
701,
27083,
314,
20583,
339,
2508,
3442,
447,
398,
289,
63,
2734,
275,
8522,
10865,
26156,
442,
63,
93,
2440,
272,
3897,
272,
4143,
339,
20645,
26,
6146,
1650,
1208,
14,
16684,
17,
36,
267,
20645,
909,
272,
2457,
26,
6146,
3569,
1236,
838,
357,
14,
4131,
20966,
339,
520,
1107,
26,
272,
408,
339,
9806,
63,
18142,
275,
2457,
627,
20645,
272,
2457,
63,
14477,
63,
15669,
275,
980,
14,
19510,
90,
8,
11142,
63,
18142,
14,
14477,
627,
9806,
63,
18142,
14,
10024,
1267,
12,
490,
9806,
63,
18142,
14,
10024,
1267,
9,
272,
372,
2457,
63,
14477,
63,
15669,
421,
199,
318,
8671,
63,
432,
5294,
63,
32167,
8,
18142,
12,
2457,
304,
272,
2457,
63,
14477,
63,
15669,
275,
8671,
63,
1541,
63,
14477,
63,
15669,
8,
18142,
12,
2457,
9,
272,
12204,
1267,
63,
3136,
275,
2457,
14,
12063,
63,
10024,
1267,
63,
3136,
342,
272,
9806,
63,
70,
63,
2734,
275,
334,
1541,
63,
14477,
63,
15669,
1182,
12204,
1267,
63,
3136,
9,
339,
1315,
80,
63,
432,
5294,
63,
70,
63,
2734,
275,
2457,
14,
90,
80,
63,
432,
5294,
63,
70,
63,
2734,
339,
372,
446,
18,
14,
21,
627,
980,
14,
793,
709,
8,
11142,
63,
70,
63,
2734,
1182,
1315,
80,
63,
432,
5294,
63,
70,
63,
2734,
9,
421,
199,
318,
8671,
63,
371,
63,
32167,
8,
18142,
12,
2457,
304,
272,
9806,
63,
70,
63,
2734,
275,
334,
12063,
63,
1541,
63,
14477,
63,
15669,
8,
18142,
12,
2457,
9,
1182,
586,
2457,
14,
12063,
63,
10024,
1267,
63,
3136,
1012,
339,
372,
446,
18,
14,
21,
627,
980,
14,
793,
709,
8,
11142,
63,
70,
63,
2734,
1182,
2457,
14,
90,
80,
63,
371,
63,
70,
63,
2734,
9,
421,
199,
318,
769,
63,
4273,
837,
272,
408,
272,
3820,
2808,
2457,
5951,
3180,
543,
3932,
4382,
272,
408,
272,
372,
2248,
63,
1541,
63,
1080,
342,
421,
199,
533,
3523,
4131,
20966,
8,
785,
304,
272,
408,
272,
10082,
2457,
15318,
1021,
339,
3897,
272,
4143,
339,
12204,
1267,
26,
6146,
1810,
7537,
14,
5260,
14,
19703,
267,
12204,
1267,
367,
2457,
15318,
339,
1752,
2250,
63,
2734,
26,
2680,
14,
8237,
267,
1752,
2250,
63,
2734,
367,
2457,
15318,
339,
14046,
63,
5091,
26,
620,
267,
4370,
14046,
24241,
1627,
315,
7026,
14,
21294,
14,
14252,
17,
68,
272,
408,
339,
768,
3744,
272,
347,
2248,
63,
1541,
8,
1886,
12,
2457,
63,
344,
29,
403,
12,
14046,
63,
5091,
534,
6676,
735,
267,
408,
398,
3897,
267,
4143,
398,
2457,
63,
344,
26,
620,
503,
488,
288,
340,
488,
365,
2741,
911,
372,
282,
10071,
402,
1006,
4766,
398,
14046,
63,
5091,
26,
620,
288,
1937,
7026,
14,
21080,
14,
14252,
17,
68,
10631,
408,
267,
340,
2457,
63,
344,
365,
488,
26,
288,
372,
769,
63,
4273,
342,
398,
587,
26,
288,
2457,
275,
2248,
63,
1515,
2250,
63,
576,
8,
1541,
63,
344,
9,
7846,
12204,
1267,
63,
3248,
275,
283,
621,
31672,
7,
953,
12204,
1267,
275,
2457,
459,
21393,
1267,
2278,
1459,
627,
399,
14,
5072,
8,
10024,
1267,
63,
3248,
9,
953,
372,
843,
8,
10024,
1267,
12,
2457,
459,
24011,
2278,
1459,
12,
2432,
14046,
63,
5091,
29,
21080,
63,
5091,
12,
2432,
2457,
63,
344,
29,
1541,
63,
344,
9,
2378,
347,
636,
826,
721,
277,
12,
12204,
1267,
12,
1752,
2250,
63,
2734,
12,
326,
14046,
63,
5091,
534,
6676,
297,
2457,
63,
344,
29,
403,
304,
267,
340,
440,
2688,
8,
10024,
1267,
12,
283,
3248,
735,
288,
746,
1722,
360,
1589,
12204,
1267,
4839,
370,
506,
282,
28753,
12524,
358,
267,
291,
14,
10024,
1267,
275,
12204,
1267,
267,
291,
14,
1515,
2250,
63,
2734,
275,
1752,
2250,
63,
2734,
398,
291,
14,
21080,
63,
785,
275,
28884,
14,
14252,
17,
68,
8,
277,
14,
10024,
1267,
12,
12740,
291,
14,
1515,
2250,
63,
2734,
12,
12740,
4928,
29,
21080,
63,
5091,
12,
12740,
10461,
63,
705,
29,
797,
12,
12740,
5554,
63,
585,
29,
16,
14,
16,
9,
267,
291,
14,
1541,
63,
344,
275,
2457,
63,
344,
2378,
347,
636,
3703,
721,
277,
12,
1163,
304,
267,
340,
440,
2688,
8,
1848,
12,
283,
14477,
358,
503,
440,
2688,
8,
1848,
12,
283,
10024,
1267,
735,
288,
746,
1722,
360,
264,
23729,
282,
3158,
1208,
14,
16684,
17,
36,
13,
2930,
909,
626,
7,
2490,
283,
1989,
3004,
298,
14477,
2,
436,
298,
10024,
1267,
9008,
398,
327,
1222,
63,
10024,
1267,
275,
980,
14,
8888,
17,
68,
8,
1848,
14,
10024,
1267,
14,
475,
8,
277,
14,
10024,
1267,
14,
3248,
680,
585,
12,
267,
327,
14960,
291,
14,
10024,
1267,
14,
585,
9,
627,
291,
14,
10024,
1267,
14,
3248,
267,
1752,
2250,
275,
291,
14,
21294,
8,
1848,
14,
10024,
1267,
9,
398,
372,
428,
9120,
17,
36,
14,
504,
63,
1144,
8,
1848,
14,
10024,
1267,
12,
1752,
2250,
627,
1163,
14,
14477,
9,
339,
347,
636,
27968,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
3703,
721,
1848,
9,
2378,
768,
1208,
14,
6395,
1829,
272,
347,
2400,
63,
21558,
8,
277,
304,
267,
408,
267,
12707,
314,
299,
1003,
1735,
12204,
1267,
465,
3247,
315,
699,
397,
23235,
1253,
603,
300,
6581,
6029,
398,
2508,
3473,
447,
953,
8522,
2734,
63,
1103,
505,
5682,
91,
21558,
93,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
agry/NGECore2
|
scripts/mobiles/tatooine/gunrunner_sentry.py
|
2
|
1353
|
import sys
from services.spawn import MobileTemplate
from services.spawn import WeaponTemplate
from resources.datatables import WeaponType
from resources.datatables import Difficulty
from resources.datatables import Options
from java.util import Vector
def addTemplate(core):
mobileTemplate = MobileTemplate()
mobileTemplate.setCreatureName('gunrunner_newbie_sentry')
mobileTemplate.setLevel(6)
mobileTemplate.setDifficulty(Difficulty.NORMAL)
mobileTemplate.setMinSpawnDistance(4)
mobileTemplate.setMaxSpawnDistance(8)
mobileTemplate.setDeathblow(False)
mobileTemplate.setScale(1)
mobileTemplate.setSocialGroup("gunrunner")
mobileTemplate.setAssistRange(4)
mobileTemplate.setStalker(False)
mobileTemplate.setOptionsBitmask(Options.AGGRESSIVE | Options.ATTACKABLE)
templates = Vector()
templates.add('object/mobile/shared_dressed_tatooine_gunrunner.iff')
mobileTemplate.setTemplates(templates)
weaponTemplates = Vector()
weapontemplate = WeaponTemplate('object/weapon/ranged/carbine/shared_carbine_e5.iff', WeaponType.CARBINE, 1.0, 15, 'energy')
weaponTemplates.add(weapontemplate)
mobileTemplate.setWeaponTemplateVector(weaponTemplates)
attacks = Vector()
mobileTemplate.setDefaultAttack('rangedShot')
mobileTemplate.setAttacks(attacks)
core.spawnService.addMobileTemplate('gunrunner_sentry', mobileTemplate)
return
|
lgpl-3.0
|
[
646,
984,
199,
504,
8500,
14,
10212,
492,
29724,
4231,
199,
504,
8500,
14,
10212,
492,
2136,
21921,
4231,
199,
504,
5944,
14,
4616,
292,
5921,
492,
2136,
21921,
804,
199,
504,
5944,
14,
4616,
292,
5921,
492,
577,
692,
24161,
199,
504,
5944,
14,
4616,
292,
5921,
492,
8394,
199,
504,
12120,
14,
1974,
492,
11388,
421,
199,
318,
1050,
4231,
8,
1018,
304,
199,
198,
27339,
275,
29724,
4231,
342,
8299,
198,
27339,
14,
409,
5482,
1463,
985,
360,
17924,
5933,
63,
1222,
66,
1873,
63,
3870,
358,
199,
198,
27339,
14,
13548,
8,
22,
9,
199,
198,
27339,
14,
409,
36,
692,
24161,
8,
36,
692,
24161,
14,
10765,
9,
421,
198,
27339,
14,
409,
4649,
12739,
3501,
10076,
8,
20,
9,
199,
198,
27339,
14,
409,
4261,
12739,
3501,
10076,
8,
24,
9,
199,
198,
27339,
14,
409,
31577,
66,
674,
8,
797,
9,
199,
198,
27339,
14,
409,
9944,
8,
17,
9,
199,
198,
27339,
14,
409,
31356,
2448,
480,
17924,
5933,
531,
199,
198,
27339,
14,
409,
2822,
11734,
4709,
8,
20,
9,
199,
198,
27339,
14,
409,
933,
14976,
8,
797,
9,
198,
199,
198,
27339,
14,
409,
4558,
4734,
2629,
8,
4558,
14,
1254,
19568,
5399,
1204,
8394,
14,
11712,
3099,
2617,
9,
8299,
198,
5876,
275,
11388,
342,
199,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
84,
292,
1534,
1132,
63,
17924,
5933,
14,
15126,
358,
199,
198,
27339,
14,
409,
17969,
8,
5876,
9,
8299,
198,
30804,
17969,
275,
11388,
342,
199,
198,
30804,
1160,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
1842,
68,
15,
7007,
15767,
15,
5555,
63,
7007,
15767,
63,
69,
21,
14,
15126,
297,
2136,
21921,
804,
14,
35,
8611,
3565,
12,
413,
14,
16,
12,
4114,
12,
283,
8443,
358,
199,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
9,
199,
198,
27339,
14,
409,
6004,
21921,
4231,
3646,
8,
30804,
17969,
9,
8299,
198,
292,
21807,
275,
11388,
342,
199,
198,
27339,
14,
409,
2698,
1271,
13058,
360,
1842,
68,
2662,
357,
358,
199,
198,
27339,
14,
409,
1271,
21807,
8,
292,
21807,
9,
8299,
198,
1018,
14,
10212,
3167,
14,
525,
27245,
4231,
360,
17924,
5933,
63,
3870,
297,
21305,
4231,
9,
199,
198,
1107,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
984,
199,
504,
8500,
14,
10212,
492,
29724,
4231,
199,
504,
8500,
14,
10212,
492,
2136,
21921,
4231,
199,
504,
5944,
14,
4616,
292,
5921,
492,
2136,
21921,
804,
199,
504,
5944,
14,
4616,
292,
5921,
492,
577,
692,
24161,
199,
504,
5944,
14,
4616,
292,
5921,
492,
8394,
199,
504,
12120,
14,
1974,
492,
11388,
421,
199,
318,
1050,
4231,
8,
1018,
304,
199,
198,
27339,
275,
29724,
4231,
342,
8299,
198,
27339,
14,
409,
5482,
1463,
985,
360,
17924,
5933,
63,
1222,
66,
1873,
63,
3870,
358,
199,
198,
27339,
14,
13548,
8,
22,
9,
199,
198,
27339,
14,
409,
36,
692,
24161,
8,
36,
692,
24161,
14,
10765,
9,
421,
198,
27339,
14,
409,
4649,
12739,
3501,
10076,
8,
20,
9,
199,
198,
27339,
14,
409,
4261,
12739,
3501,
10076,
8,
24,
9,
199,
198,
27339,
14,
409,
31577,
66,
674,
8,
797,
9,
199,
198,
27339,
14,
409,
9944,
8,
17,
9,
199,
198,
27339,
14,
409,
31356,
2448,
480,
17924,
5933,
531,
199,
198,
27339,
14,
409,
2822,
11734,
4709,
8,
20,
9,
199,
198,
27339,
14,
409,
933,
14976,
8,
797,
9,
198,
199,
198,
27339,
14,
409,
4558,
4734,
2629,
8,
4558,
14,
1254,
19568,
5399,
1204,
8394,
14,
11712,
3099,
2617,
9,
8299,
198,
5876,
275,
11388,
342,
199,
198,
5876,
14,
525,
360,
785,
15,
11375,
15,
5555,
63,
68,
5111,
63,
84,
292,
1534,
1132,
63,
17924,
5933,
14,
15126,
358,
199,
198,
27339,
14,
409,
17969,
8,
5876,
9,
8299,
198,
30804,
17969,
275,
11388,
342,
199,
198,
30804,
1160,
275,
2136,
21921,
4231,
360,
785,
15,
30804,
15,
1842,
68,
15,
7007,
15767,
15,
5555,
63,
7007,
15767,
63,
69,
21,
14,
15126,
297,
2136,
21921,
804,
14,
35,
8611,
3565,
12,
413,
14,
16,
12,
4114,
12,
283,
8443,
358,
199,
198,
30804,
17969,
14,
525,
8,
30804,
1160,
9,
199,
198,
27339,
14,
409,
6004,
21921,
4231,
3646,
8,
30804,
17969,
9,
8299,
198,
292,
21807,
275,
11388,
342,
199,
198,
27339,
14,
409,
2698,
1271,
13058,
360,
1842,
68,
2662,
357,
358,
199,
198,
27339,
14,
409,
1271,
21807,
8,
292,
21807,
9,
8299,
198,
1018,
14,
10212,
3167,
14,
525,
27245,
4231,
360,
17924,
5933,
63,
3870,
297,
21305,
4231,
9,
199,
198,
1107,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ChrisTimperley/PythonCGum
|
cgum/program.py
|
1
|
5861
|
from cgum.basic import *
from cgum.utility import FNULL
from pprint import pprint
import cgum.statement as statement
import cgum.expression as expression
import cgum.preprocessor as preprocessor
import cgum.typs as typs
from subprocess import Popen, CalledProcessError
import os.path
import json
import tempfile
import codecs
# TODO: Probe
class Asm(Node):
CODE = "260800"
LABEL = "Asm"
def __init__(self, pos, length, label, children):
assert label is None
super().__init__(pos, length, label, children)
class Label(Node):
CODE = "270100"
LABEL = "Label"
def __init__(self, pos, length, label, children):
assert label is None
assert len(children) in [1, 2]
assert isinstance(children[0], GenericString)
super().__init__(pos, length, label, children)
def name(self):
return self.__children[0].to_s()
def statement(self):
children = self.children()
if len(children) == 2:
return children[1]
return None
class FunctionParameter(Node):
CODE = "220100"
LABEL = "ParameterType"
def __init__(self, pos, length, label, children):
assert label is None
assert len(children) <= 2
# Find the optional type and name of this parameter
tmp = children.copy()
self.__typ = \
tmp.pop(0) if (tmp and isinstance(tmp[0], typs.FullType)) else None
self.__name = tmp.pop(0) if tmp else None
assert self.__typ is None or isinstance(self.__typ, typs.FullType)
assert self.__name is None or isinstance(self.__name, GenericString)
super().__init__(pos, length, label, children)
def is_incomplete(self):
return self.name() is None
def typ(self):
return self.__typ.to_s() if self.__typ else None
def name(self):
return self.__name.to_s() if self.__name else None
class FunctionParameters(Node):
CODE = "200000"
LABEL = "ParamList"
def __init__(self, pos, length, label, children):
assert label is None
assert all([isinstance(c, FunctionParameter) for c in children])
super().__init__(pos, length, label, children)
def parameters(self):
return self.__children
class FunctionDefinition(Node):
CODE = "380000"
LABEL = "Definition"
@staticmethod
def from_json(jsn):
return FunctionDefinition(jsn['pos'], name, params, block, storage, dots)
def __init__(self, pos, length, label, children):
assert len(children) >= 3 and len(children) <= 5
tmp = children.copy()
self.__storage = \
tmp.pop(0) if isinstance(tmp[0], typs.Storage) else None
self.__parameters = tmp.pop(0)
self.__dots = \
tmp.pop(0) if isinstance(tmp[0], typs.DotsParameter) else None
self.__name = tmp.pop(0)
self.__block = tmp.pop(0)
assert isinstance(self.__parameters, FunctionParameters)
assert self.__dots is None or \
isinstance(self.__dots, typs.DotsParameter)
assert self.__storage is None or \
isinstance(self.__storage, typs.Storage)
assert isinstance(self.__name, GenericString)
assert isinstance(self.__block, statement.Block)
super().__init__(pos, length, label, children)
def name(self):
return self.__name
def parameters(self):
return self.__parameters
def block(self):
return self.__block
def storage(self):
return self.__storage
def dots(self):
return self.__dots
def is_variadic(self):
return not (self.dots() is None)
# Used to mark the end of the program!
class FinalDef(Token):
CODE = "450800"
LABEL = "FinalDef"
# Represents the root AST node for a program
# For now we just get all the "components" of a program and worry about what
# kind of components they might be later.
#
# Throw away the FinalDef
class Program(Node):
CODE = "460000"
LABEL = "Program"
# Generates an AST for a given source code file, using GumTree and CGum
@staticmethod
def from_source_file(fn):
tmp_f = tempfile.NamedTemporaryFile()
Program.parse_to_json_file(fn, tmp_f)
return Program.from_json_file(tmp_f.name)
# Parses a JSON CGum AST, stored in a file at a specified location, into an
# equivalent, Python representation
@staticmethod
def from_json_file(fn):
#print("Attempting to read CGum AST from a JSON file: %s" % fn)
assert os.path.isfile(fn), "file not found"
with codecs.open(fn, 'r', 'utf-8') as f:
program = Node.from_json(json.load(f)['root'])
#print("Finished converting CGum AST from JSON into Python")
program.renumber()
return program
def __init__(self, pos, length, label, children):
assert label is None
assert len(children) >= 1
assert isinstance(children[-1], FinalDef)
children.pop()
super().__init__(pos, length, label, children)
@staticmethod
def parse_to_json_file(src_fn, jsn_f):
with tempfile.TemporaryFile() as f_err:
cmd = "gumtree parse \"%s\"" % src_fn
p = Popen(cmd, shell=True, stdin=FNULL, stdout=jsn_f, stderr=f_err)
code = p.wait()
# read the contents of the standard error
f_err.seek(0)
err = str(f_err.read())[2:-1]
# ensure the exit status was zero
if code != 0:
raise Exception("ERROR [PyCGum/parse_to_json_file]: unexpected exit code - %s" % error)
# run-time exceptions can occur whilst still returning an exit status
# of zero
elif err.startswith("java.lang.RuntimeException:"):
raise Exception("ERROR [PyCGum/parse_to_json_file]: %s" % err)
|
mit
|
[
504,
19711,
453,
14,
4316,
492,
627,
199,
504,
19711,
453,
14,
16877,
492,
481,
8084,
199,
504,
10933,
492,
10933,
199,
646,
19711,
453,
14,
6242,
465,
5164,
199,
646,
19711,
453,
14,
5599,
465,
3965,
199,
646,
19711,
453,
14,
657,
6459,
465,
22335,
199,
646,
19711,
453,
14,
369,
1190,
465,
10284,
1190,
199,
199,
504,
3873,
492,
13995,
12,
12295,
19148,
199,
646,
747,
14,
515,
199,
646,
2022,
199,
646,
5549,
199,
646,
6010,
199,
199,
3,
3254,
26,
2165,
1235,
199,
533,
437,
3300,
8,
1716,
304,
272,
22547,
275,
298,
1479,
25822,
2,
272,
491,
1217,
2901,
275,
298,
2822,
77,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
199,
199,
533,
10354,
8,
1716,
304,
272,
22547,
275,
298,
1465,
16569,
2,
272,
491,
1217,
2901,
275,
298,
4314,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
702,
822,
8,
3223,
9,
315,
359,
17,
12,
499,
61,
267,
702,
1228,
8,
3223,
59,
16,
467,
8307,
1558,
9,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
536,
8,
277,
304,
267,
372,
291,
855,
3223,
59,
16,
1055,
475,
63,
83,
342,
272,
347,
5164,
8,
277,
304,
267,
4978,
275,
291,
14,
3223,
342,
267,
340,
822,
8,
3223,
9,
508,
499,
26,
288,
372,
4978,
59,
17,
61,
267,
372,
488,
199,
199,
533,
6801,
4720,
8,
1716,
304,
272,
22547,
275,
298,
1081,
16569,
2,
272,
491,
1217,
2901,
275,
298,
4720,
804,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
702,
822,
8,
3223,
9,
2695,
499,
398,
327,
6668,
314,
2716,
730,
436,
536,
402,
642,
2725,
267,
3529,
275,
4978,
14,
1574,
342,
267,
291,
855,
9749,
275,
971,
288,
3529,
14,
1935,
8,
16,
9,
340,
334,
2791,
436,
1228,
8,
2791,
59,
16,
467,
10284,
1190,
14,
9042,
804,
430,
587,
488,
267,
291,
855,
354,
275,
3529,
14,
1935,
8,
16,
9,
340,
3529,
587,
488,
398,
702,
291,
855,
9749,
365,
488,
503,
1228,
8,
277,
855,
9749,
12,
10284,
1190,
14,
9042,
804,
9,
267,
702,
291,
855,
354,
365,
488,
503,
1228,
8,
277,
855,
354,
12,
8307,
1558,
9,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
365,
63,
24575,
8,
277,
304,
267,
372,
291,
14,
354,
342,
365,
488,
272,
347,
6211,
8,
277,
304,
267,
372,
291,
855,
9749,
14,
475,
63,
83,
342,
340,
291,
855,
9749,
587,
488,
272,
347,
536,
8,
277,
304,
267,
372,
291,
855,
354,
14,
475,
63,
83,
342,
340,
291,
855,
354,
587,
488,
199,
199,
533,
6801,
5976,
8,
1716,
304,
272,
22547,
275,
298,
18,
5345,
2,
272,
491,
1217,
2901,
275,
298,
4098,
1296,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
702,
1006,
779,
6074,
8,
67,
12,
6801,
4720,
9,
367,
286,
315,
4978,
566,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
2633,
8,
277,
304,
267,
372,
291,
855,
3223,
199,
199,
533,
6801,
10701,
8,
1716,
304,
272,
22547,
275,
298,
1703,
993,
2,
272,
491,
1217,
2901,
275,
298,
10701,
2,
339,
768,
4639,
272,
347,
687,
63,
1001,
8,
3596,
78,
304,
355,
372,
6801,
10701,
8,
3596,
78,
459,
1712,
995,
536,
12,
1862,
12,
1853,
12,
4887,
12,
21185,
9,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
822,
8,
3223,
9,
2356,
650,
436,
822,
8,
3223,
9,
2695,
959,
398,
3529,
275,
4978,
14,
1574,
342,
267,
291,
855,
3494,
275,
971,
288,
3529,
14,
1935,
8,
16,
9,
340,
1228,
8,
2791,
59,
16,
467,
10284,
1190,
14,
6408,
9,
587,
488,
267,
291,
855,
3214,
275,
3529,
14,
1935,
8,
16,
9,
267,
291,
855,
25310,
275,
971,
288,
3529,
14,
1935,
8,
16,
9,
340,
1228,
8,
2791,
59,
16,
467,
10284,
1190,
14,
14004,
83,
4720,
9,
587,
488,
267,
291,
855,
354,
275,
3529,
14,
1935,
8,
16,
9,
267,
291,
855,
1457,
275,
3529,
14,
1935,
8,
16,
9,
398,
702,
1228,
8,
277,
855,
3214,
12,
6801,
5976,
9,
267,
702,
291,
855,
25310,
365,
488,
503,
971,
288,
1228,
8,
277,
855,
25310,
12,
10284,
1190,
14,
14004,
83,
4720,
9,
267,
702,
291,
855,
3494,
365,
488,
503,
971,
288,
1228,
8,
277,
855,
3494,
12,
10284,
1190,
14,
6408,
9,
267,
702,
1228,
8,
277,
855,
354,
12,
8307,
1558,
9,
267,
702,
1228,
8,
277,
855,
1457,
12,
5164,
14,
3142,
9,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
536,
8,
277,
304,
267,
372,
291,
855,
354,
272,
347,
2633,
8,
277,
304,
267,
372,
291,
855,
3214,
272,
347,
1853,
8,
277,
304,
267,
372,
291,
855,
1457,
272,
347,
4887,
8,
277,
304,
267,
372,
291,
855,
3494,
272,
347,
21185,
8,
277,
304,
267,
372,
291,
855,
25310,
339,
347,
365,
63,
3808,
31764,
8,
277,
304,
267,
372,
440,
334,
277,
14,
25310,
342,
365,
488,
9,
199,
199,
3,
8051,
370,
2216,
314,
1284,
402,
314,
2240,
1,
199,
533,
21789,
6172,
8,
3264,
304,
272,
22547,
275,
298,
24223,
6718,
2,
272,
491,
1217,
2901,
275,
298,
12776,
6172,
2,
199,
199,
3,
21591,
314,
1738,
20788,
1031,
367,
282,
2240,
199,
3,
2104,
3063,
781,
2951,
664,
1006,
314,
298,
4608,
2,
402,
282,
2240,
436,
30944,
3595,
4052,
199,
3,
4928,
402,
7323,
2985,
5594,
506,
2945,
14,
199,
3,
199,
3,
3868,
1143,
13437,
314,
21789,
6172,
199,
533,
18841,
8,
1716,
304,
272,
22547,
275,
298,
2466,
993,
2
] |
[
19711,
453,
14,
4316,
492,
627,
199,
504,
19711,
453,
14,
16877,
492,
481,
8084,
199,
504,
10933,
492,
10933,
199,
646,
19711,
453,
14,
6242,
465,
5164,
199,
646,
19711,
453,
14,
5599,
465,
3965,
199,
646,
19711,
453,
14,
657,
6459,
465,
22335,
199,
646,
19711,
453,
14,
369,
1190,
465,
10284,
1190,
199,
199,
504,
3873,
492,
13995,
12,
12295,
19148,
199,
646,
747,
14,
515,
199,
646,
2022,
199,
646,
5549,
199,
646,
6010,
199,
199,
3,
3254,
26,
2165,
1235,
199,
533,
437,
3300,
8,
1716,
304,
272,
22547,
275,
298,
1479,
25822,
2,
272,
491,
1217,
2901,
275,
298,
2822,
77,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
199,
199,
533,
10354,
8,
1716,
304,
272,
22547,
275,
298,
1465,
16569,
2,
272,
491,
1217,
2901,
275,
298,
4314,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
702,
822,
8,
3223,
9,
315,
359,
17,
12,
499,
61,
267,
702,
1228,
8,
3223,
59,
16,
467,
8307,
1558,
9,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
536,
8,
277,
304,
267,
372,
291,
855,
3223,
59,
16,
1055,
475,
63,
83,
342,
272,
347,
5164,
8,
277,
304,
267,
4978,
275,
291,
14,
3223,
342,
267,
340,
822,
8,
3223,
9,
508,
499,
26,
288,
372,
4978,
59,
17,
61,
267,
372,
488,
199,
199,
533,
6801,
4720,
8,
1716,
304,
272,
22547,
275,
298,
1081,
16569,
2,
272,
491,
1217,
2901,
275,
298,
4720,
804,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
702,
822,
8,
3223,
9,
2695,
499,
398,
327,
6668,
314,
2716,
730,
436,
536,
402,
642,
2725,
267,
3529,
275,
4978,
14,
1574,
342,
267,
291,
855,
9749,
275,
971,
288,
3529,
14,
1935,
8,
16,
9,
340,
334,
2791,
436,
1228,
8,
2791,
59,
16,
467,
10284,
1190,
14,
9042,
804,
430,
587,
488,
267,
291,
855,
354,
275,
3529,
14,
1935,
8,
16,
9,
340,
3529,
587,
488,
398,
702,
291,
855,
9749,
365,
488,
503,
1228,
8,
277,
855,
9749,
12,
10284,
1190,
14,
9042,
804,
9,
267,
702,
291,
855,
354,
365,
488,
503,
1228,
8,
277,
855,
354,
12,
8307,
1558,
9,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
365,
63,
24575,
8,
277,
304,
267,
372,
291,
14,
354,
342,
365,
488,
272,
347,
6211,
8,
277,
304,
267,
372,
291,
855,
9749,
14,
475,
63,
83,
342,
340,
291,
855,
9749,
587,
488,
272,
347,
536,
8,
277,
304,
267,
372,
291,
855,
354,
14,
475,
63,
83,
342,
340,
291,
855,
354,
587,
488,
199,
199,
533,
6801,
5976,
8,
1716,
304,
272,
22547,
275,
298,
18,
5345,
2,
272,
491,
1217,
2901,
275,
298,
4098,
1296,
2,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
1768,
365,
488,
267,
702,
1006,
779,
6074,
8,
67,
12,
6801,
4720,
9,
367,
286,
315,
4978,
566,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
2633,
8,
277,
304,
267,
372,
291,
855,
3223,
199,
199,
533,
6801,
10701,
8,
1716,
304,
272,
22547,
275,
298,
1703,
993,
2,
272,
491,
1217,
2901,
275,
298,
10701,
2,
339,
768,
4639,
272,
347,
687,
63,
1001,
8,
3596,
78,
304,
355,
372,
6801,
10701,
8,
3596,
78,
459,
1712,
995,
536,
12,
1862,
12,
1853,
12,
4887,
12,
21185,
9,
339,
347,
636,
826,
721,
277,
12,
2086,
12,
2582,
12,
1768,
12,
4978,
304,
267,
702,
822,
8,
3223,
9,
2356,
650,
436,
822,
8,
3223,
9,
2695,
959,
398,
3529,
275,
4978,
14,
1574,
342,
267,
291,
855,
3494,
275,
971,
288,
3529,
14,
1935,
8,
16,
9,
340,
1228,
8,
2791,
59,
16,
467,
10284,
1190,
14,
6408,
9,
587,
488,
267,
291,
855,
3214,
275,
3529,
14,
1935,
8,
16,
9,
267,
291,
855,
25310,
275,
971,
288,
3529,
14,
1935,
8,
16,
9,
340,
1228,
8,
2791,
59,
16,
467,
10284,
1190,
14,
14004,
83,
4720,
9,
587,
488,
267,
291,
855,
354,
275,
3529,
14,
1935,
8,
16,
9,
267,
291,
855,
1457,
275,
3529,
14,
1935,
8,
16,
9,
398,
702,
1228,
8,
277,
855,
3214,
12,
6801,
5976,
9,
267,
702,
291,
855,
25310,
365,
488,
503,
971,
288,
1228,
8,
277,
855,
25310,
12,
10284,
1190,
14,
14004,
83,
4720,
9,
267,
702,
291,
855,
3494,
365,
488,
503,
971,
288,
1228,
8,
277,
855,
3494,
12,
10284,
1190,
14,
6408,
9,
267,
702,
1228,
8,
277,
855,
354,
12,
8307,
1558,
9,
267,
702,
1228,
8,
277,
855,
1457,
12,
5164,
14,
3142,
9,
267,
1613,
11027,
826,
721,
1712,
12,
2582,
12,
1768,
12,
4978,
9,
339,
347,
536,
8,
277,
304,
267,
372,
291,
855,
354,
272,
347,
2633,
8,
277,
304,
267,
372,
291,
855,
3214,
272,
347,
1853,
8,
277,
304,
267,
372,
291,
855,
1457,
272,
347,
4887,
8,
277,
304,
267,
372,
291,
855,
3494,
272,
347,
21185,
8,
277,
304,
267,
372,
291,
855,
25310,
339,
347,
365,
63,
3808,
31764,
8,
277,
304,
267,
372,
440,
334,
277,
14,
25310,
342,
365,
488,
9,
199,
199,
3,
8051,
370,
2216,
314,
1284,
402,
314,
2240,
1,
199,
533,
21789,
6172,
8,
3264,
304,
272,
22547,
275,
298,
24223,
6718,
2,
272,
491,
1217,
2901,
275,
298,
12776,
6172,
2,
199,
199,
3,
21591,
314,
1738,
20788,
1031,
367,
282,
2240,
199,
3,
2104,
3063,
781,
2951,
664,
1006,
314,
298,
4608,
2,
402,
282,
2240,
436,
30944,
3595,
4052,
199,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
h2o64/android_kernel_motorola_msm8226-3.10
|
tools/perf/util/setup.py
|
2079
|
1438
|
#!/usr/bin/python2
from distutils.core import setup, Extension
from os import getenv
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.install_lib import install_lib as _install_lib
class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
self.build_lib = build_lib
self.build_temp = build_tmp
class install_lib(_install_lib):
def finalize_options(self):
_install_lib.finalize_options(self)
self.build_dir = build_lib
cflags = ['-fno-strict-aliasing', '-Wno-write-strings']
cflags += getenv('CFLAGS', '').split()
build_lib = getenv('PYTHON_EXTBUILD_LIB')
build_tmp = getenv('PYTHON_EXTBUILD_TMP')
libtraceevent = getenv('LIBTRACEEVENT')
liblk = getenv('LIBLK')
ext_sources = [f.strip() for f in file('util/python-ext-sources')
if len(f.strip()) > 0 and f[0] != '#']
perf = Extension('perf',
sources = ext_sources,
include_dirs = ['util/include'],
extra_compile_args = cflags,
extra_objects = [libtraceevent, liblk],
)
setup(name='perf',
version='0.1',
description='Interface with the Linux profiling infrastructure',
author='Arnaldo Carvalho de Melo',
author_email='acme@redhat.com',
license='GPLv2',
url='http://perf.wiki.kernel.org',
ext_modules=[perf],
cmdclass={'build_ext': build_ext, 'install_lib': install_lib})
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
18,
199,
199,
504,
7065,
14,
1018,
492,
3272,
12,
13282,
199,
504,
747,
492,
29626,
199,
199,
504,
7065,
14,
1531,
14,
1506,
63,
832,
257,
492,
1900,
63,
832,
257,
465,
485,
1506,
63,
832,
199,
504,
7065,
14,
1531,
14,
3174,
63,
773,
492,
3907,
63,
773,
465,
485,
3174,
63,
773,
199,
199,
533,
1900,
63,
832,
1547,
1506,
63,
832,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
773,
221,
275,
1900,
63,
773,
267,
291,
14,
1506,
63,
808,
275,
1900,
63,
2791,
199,
199,
533,
3907,
63,
773,
1547,
3174,
63,
773,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
3174,
63,
773,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
694,
275,
1900,
63,
773,
421,
199,
14002,
275,
11573,
70,
889,
13,
4768,
13,
3620,
316,
297,
2475,
55,
889,
13,
952,
13,
5465,
418,
199,
14002,
847,
29626,
360,
14804,
297,
12548,
1294,
342,
199,
199,
1506,
63,
773,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
5617,
358,
199,
1506,
63,
2791,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
17983,
358,
199,
773,
3446,
1430,
275,
29626,
360,
5617,
20112,
8193,
358,
199,
773,
23333,
275,
29626,
360,
5617,
44,
43,
358,
199,
199,
832,
63,
4553,
275,
359,
70,
14,
1913,
342,
367,
289,
315,
570,
360,
1974,
15,
1548,
13,
832,
13,
4553,
358,
1585,
198,
692,
822,
8,
70,
14,
1913,
1012,
690,
378,
436,
289,
59,
16,
61,
1137,
3943,
418,
199,
199,
9452,
275,
13282,
360,
9452,
297,
29294,
5274,
275,
1599,
63,
4553,
12,
29294,
2387,
63,
3220,
275,
788,
1974,
15,
2613,
995,
29294,
2402,
63,
2014,
63,
589,
275,
13426,
12,
29294,
2402,
63,
1462,
275,
359,
773,
3446,
1430,
12,
1973,
23333,
467,
326,
776,
199,
199,
2758,
8,
354,
534,
9452,
297,
489,
1015,
534,
16,
14,
17,
297,
489,
1369,
534,
4267,
543,
314,
10130,
30238,
28890,
6976,
297,
489,
4132,
534,
20498,
279,
1117,
14243,
637,
526,
477,
3194,
320,
297,
489,
4132,
63,
2123,
534,
18107,
32,
17164,
14,
957,
297,
489,
4190,
534,
28863,
18,
297,
489,
1166,
534,
1014,
921,
9452,
14,
6797,
14,
4989,
14,
1308,
297,
489,
1599,
63,
3112,
1524,
9452,
467,
489,
2088,
533,
3713,
1506,
63,
832,
356,
1900,
63,
832,
12,
283,
3174,
63,
773,
356,
3907,
63,
773,
1552,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
18,
199,
199,
504,
7065,
14,
1018,
492,
3272,
12,
13282,
199,
504,
747,
492,
29626,
199,
199,
504,
7065,
14,
1531,
14,
1506,
63,
832,
257,
492,
1900,
63,
832,
257,
465,
485,
1506,
63,
832,
199,
504,
7065,
14,
1531,
14,
3174,
63,
773,
492,
3907,
63,
773,
465,
485,
3174,
63,
773,
199,
199,
533,
1900,
63,
832,
1547,
1506,
63,
832,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
1506,
63,
832,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
773,
221,
275,
1900,
63,
773,
267,
291,
14,
1506,
63,
808,
275,
1900,
63,
2791,
199,
199,
533,
3907,
63,
773,
1547,
3174,
63,
773,
304,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
485,
3174,
63,
773,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
1506,
63,
694,
275,
1900,
63,
773,
421,
199,
14002,
275,
11573,
70,
889,
13,
4768,
13,
3620,
316,
297,
2475,
55,
889,
13,
952,
13,
5465,
418,
199,
14002,
847,
29626,
360,
14804,
297,
12548,
1294,
342,
199,
199,
1506,
63,
773,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
5617,
358,
199,
1506,
63,
2791,
275,
29626,
360,
11720,
63,
2472,
8248,
63,
17983,
358,
199,
773,
3446,
1430,
275,
29626,
360,
5617,
20112,
8193,
358,
199,
773,
23333,
275,
29626,
360,
5617,
44,
43,
358,
199,
199,
832,
63,
4553,
275,
359,
70,
14,
1913,
342,
367,
289,
315,
570,
360,
1974,
15,
1548,
13,
832,
13,
4553,
358,
1585,
198,
692,
822,
8,
70,
14,
1913,
1012,
690,
378,
436,
289,
59,
16,
61,
1137,
3943,
418,
199,
199,
9452,
275,
13282,
360,
9452,
297,
29294,
5274,
275,
1599,
63,
4553,
12,
29294,
2387,
63,
3220,
275,
788,
1974,
15,
2613,
995,
29294,
2402,
63,
2014,
63,
589,
275,
13426,
12,
29294,
2402,
63,
1462,
275,
359,
773,
3446,
1430,
12,
1973,
23333,
467,
326,
776,
199,
199,
2758,
8,
354,
534,
9452,
297,
489,
1015,
534,
16,
14,
17,
297,
489,
1369,
534,
4267,
543,
314,
10130,
30238,
28890,
6976,
297,
489,
4132,
534,
20498,
279,
1117,
14243,
637,
526,
477,
3194,
320,
297,
489,
4132,
63,
2123,
534,
18107,
32,
17164,
14,
957,
297,
489,
4190,
534,
28863,
18,
297,
489,
1166,
534,
1014,
921,
9452,
14,
6797,
14,
4989,
14,
1308,
297,
489,
1599,
63,
3112,
1524,
9452,
467,
489,
2088,
533,
3713,
1506,
63,
832,
356,
1900,
63,
832,
12,
283,
3174,
63,
773,
356,
3907,
63,
773,
1552,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
totemtang/hadoop-RHJoin
|
src/contrib/hod/hodlib/Common/threads.py
|
182
|
12248
|
#Licensed to the Apache Software Foundation (ASF) under one
#or more contributor license agreements. See the NOTICE file
#distributed with this work for additional information
#regarding copyright ownership. The ASF licenses this file
#to you under the Apache License, Version 2.0 (the
#"License"); you may not use this file except in compliance
#with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
import threading, time, os, sys, pprint
from popen2 import Popen4, Popen3, MAXFD
from signal import SIGTERM, SIGKILL
class baseThread(threading.Thread):
"""Base CAM threading class. The run method should be overridden."""
def __init__(self, name):
threading.Thread.__init__(self, name=name)
self.stopFlag = threading.Event()
self.stopFlag.clear()
self.running = threading.Event()
self.running.set()
self.isFinished = threading.Event()
self.isFinished.clear()
def join(self, timeout=None):
self.stopFlag.set()
threading.Thread.join(self, timeout)
def pause(self):
"""Pause thread."""
self.running.clear()
def cont(self):
"""Resume thread operation."""
self.running.set()
class simpleCommand(baseThread):
"""Command execution object. Command output and exit status are captured.
Public class attributes:
cmdString - command to be executed
outputBuffer - command output, stdout + stderr
status - exit status, as returned by wait
stdin - standard input for command
stdout - standard output of command when buffer == False
stderr - standard error of command when mode == 3 and buffer == False
"""
def __init__(self, name, cmdString, env=os.environ, mode=4, buffer=True,
wait=True, chdir=None):
"""Class initialization.
name - thread name to use when running the command
cmdString - command string to execute
inputString - string to print to command's stdin
env - shell environment dictionary
mode - 3 for popen3 and 4 for popen4
buffer - out put to be retrieved with output() method
wait - return immediately after start() is called and output
command results as they come to stdout"""
baseThread.__init__(self, name=name)
self.cmdString = cmdString
self.__mode = mode
self.__buffer = buffer
self.__wait = wait
self.__chdir = chdir
self.__outputBuffer = []
self.__status = None
self.__pid = None
self.__isFinished = threading.Event()
self.__isFinished.clear()
self.stdin = None
self.stdout = None
self.stderr = None
self.__env = env
def run(self):
""" Overridden run method. Most of the work happens here. start()
should be called in place of this method."""
oldDir = None
if self.__chdir:
if os.path.exists(self.__chdir):
oldDir = os.getcwd()
os.chdir(self.__chdir)
else:
raise Exception(
"simpleCommand: invalid chdir specified: %s" %
self.__chdir)
cmd = None
if self.__mode == 3:
cmd = _Popen3Env(self.cmdString, env=self.__env)
else:
cmd = _Popen4Env(self.cmdString, env=self.__env)
self.__pid = cmd.pid
self.stdin = cmd.tochild
if self.__mode == 3:
self.stderr = cmd.childerr
while cmd.fromchild == None:
time.sleep(1)
if self.__buffer == True:
output = cmd.fromchild.readline()
while output != '':
while not self.running.isSet():
if self.stopFlag.isSet():
break
time.sleep(1)
self.__outputBuffer.append(output)
output = cmd.fromchild.readline()
elif self.__wait == False:
output = cmd.fromchild.readline()
while output != '':
while not self.running.isSet():
if self.stopFlag.isSet():
break
time.sleep(1)
print output,
if self.stopFlag.isSet():
break
output = cmd.fromchild.readline()
else:
self.stdout = cmd.fromchild
self.__status = cmd.poll()
while self.__status == -1:
while not self.running.isSet():
if self.stopFlag.isSet():
break
time.sleep(1)
self.__status = cmd.poll()
time.sleep(1)
if oldDir:
os.chdir(oldDir)
self.__isFinished.set()
sys.exit(0)
def getPid(self):
"""return pid of the launches process"""
return self.__pid
def output(self):
return self.__outputBuffer[:]
def wait(self):
"""Wait blocking until command execution completes."""
self.__isFinished.wait()
return os.WEXITSTATUS(self.__status)
def is_running(self):
"""Returns boolean, are we running?"""
status = True
if self.__isFinished.isSet():
status = False
return status
def exit_code(self):
""" Returns process exit code."""
if self.__status != None:
return os.WEXITSTATUS(self.__status)
else:
return None
def exit_status_string(self):
"""Return a string representation of the command's exit status."""
statusString = None
if self.__status:
exitStatus = os.WEXITSTATUS(self.__status)
exitSignal = os.WIFSIGNALED(self.__status)
coreDump = os.WCOREDUMP(self.__status)
statusString = "exit code: %s | signal: %s | core %s" % \
(exitStatus, exitSignal, coreDump)
return(statusString)
def stop(self):
"""Stop the running command and join it's execution thread."""
self.join()
def kill(self):
count = 0
while self.is_running():
try:
if count > 20:
os.kill(self.__pid, SIGKILL)
break
else:
os.kill(self.__pid, SIGTERM)
except:
break
time.sleep(.1)
count = count + 1
self.stop()
class _Popen3Env(Popen3):
def __init__(self, cmd, capturestderr=False, bufsize=-1, env=os.environ):
self._env = env
Popen3.__init__(self, cmd, capturestderr, bufsize)
def _run_child(self, cmd):
if isinstance(cmd, basestring):
cmd = ['/bin/sh', '-c', cmd]
for i in xrange(3, MAXFD):
try:
os.close(i)
except OSError:
pass
try:
os.execvpe(cmd[0], cmd, self._env)
finally:
os._exit(1)
class _Popen4Env(_Popen3Env, Popen4):
childerr = None
def __init__(self, cmd, bufsize=-1, env=os.environ):
self._env = env
Popen4.__init__(self, cmd, bufsize)
class loop(baseThread):
""" A simple extension of the threading.Thread class which continuously
executes a block of code until join().
"""
def __init__(self, name, functionRef, functionArgs=None, sleep=1, wait=0,
offset=False):
"""Initialize a loop object.
name - thread name
functionRef - a function reference
functionArgs - function arguments in the form of a tuple,
sleep - time to wait between function execs
wait - time to wait before executing the first time
offset - set true to sleep as an offset of the start of the
last func exec instead of the end of the last func
exec
"""
self.__functionRef = functionRef
self.__functionArgs = functionArgs
self.__sleep = sleep
self.__wait = wait
self.__offset = offset
baseThread.__init__(self, name=name)
def run(self):
"""Do not call this directly. Call self.start()."""
startTime = None
while not self.stopFlag.isSet():
sleep = self.__sleep
if self.__wait > 0:
startWaitCount = 0
while not self.stopFlag.isSet():
while not self.running.isSet():
if self.stopFlag.isSet():
break
time.sleep(1)
time.sleep(0.5)
startWaitCount = startWaitCount + .5
if startWaitCount >= self.__wait:
self.__wait = 0
break
startTime = time.time()
if not self.stopFlag.isSet():
if self.running.isSet():
if self.__functionArgs:
self.__functionRef(self.__functionArgs)
else:
self.__functionRef()
endTime = time.time()
while not self.running.isSet():
time.sleep(1)
while not self.stopFlag.isSet():
while not self.running.isSet():
if self.stopFlag.isSet():
break
time.sleep(1)
currentTime = time.time()
if self.__offset:
elapsed = time.time() - startTime
else:
elapsed = time.time() - endTime
if elapsed >= self.__sleep:
break
time.sleep(0.5)
self.isFinished.set()
def set_sleep(self, sleep, wait=None, offset=None):
"""Modify loop frequency paramaters.
sleep - time to wait between function execs
wait - time to wait before executing the first time
offset - set true to sleep as an offset of the start of the
last func exec instead of the end of the last func
exec
"""
self.__sleep = sleep
if wait != None:
self.__wait = wait
if offset != None:
self.__offset = offset
def get_sleep(self):
"""Get loop frequency paramaters.
Returns a dictionary with sleep, wait, offset.
"""
return {
'sleep' : self.__sleep,
'wait' : self.__wait,
'offset' : self.__offset,
}
class func(baseThread):
""" A simple extension of the threading.Thread class which executes
a function in a separate thread.
"""
def __init__(self, name, functionRef, functionArgs=None):
"""Initialize a func object.
name - thread name
functionRef - a function reference
functionArgs - function arguments in the form of a tuple,
"""
self.__functionRef = functionRef
self.__functionArgs = functionArgs
baseThread.__init__(self, name=name)
def run(self):
"""Do not call this directly. Call self.start()."""
if not self.stopFlag.isSet():
if self.running.isSet():
if self.__functionArgs:
self.__functionRef(self.__functionArgs)
else:
self.__functionRef()
sys.exit(0)
|
apache-2.0
|
[
3,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
199,
646,
5796,
12,
900,
12,
747,
12,
984,
12,
10933,
199,
199,
504,
17758,
18,
492,
13995,
20,
12,
13995,
19,
12,
9141,
7902,
199,
504,
4673,
492,
15522,
16718,
12,
15522,
30691,
199,
199,
533,
1300,
4436,
8,
12562,
14,
4436,
304,
272,
408,
1563,
445,
1156,
5796,
1021,
14,
221,
710,
1255,
1083,
1077,
506,
10087,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
12,
536,
29,
354,
9,
267,
291,
14,
2379,
5318,
275,
5796,
14,
2390,
342,
267,
291,
14,
2379,
5318,
14,
3584,
342,
267,
291,
14,
5720,
275,
5796,
14,
2390,
342,
267,
291,
14,
5720,
14,
409,
342,
267,
291,
14,
374,
13430,
275,
5796,
14,
2390,
342,
267,
291,
14,
374,
13430,
14,
3584,
342,
339,
347,
4263,
8,
277,
12,
2653,
29,
403,
304,
267,
291,
14,
2379,
5318,
14,
409,
342,
267,
5796,
14,
4436,
14,
904,
8,
277,
12,
2653,
9,
339,
347,
16834,
8,
277,
304,
267,
408,
30851,
2462,
1041,
398,
291,
14,
5720,
14,
3584,
342,
339,
347,
13770,
8,
277,
304,
267,
408,
22279,
2462,
3439,
1041,
398,
291,
14,
5720,
14,
409,
342,
199,
199,
533,
3486,
3110,
8,
1095,
4436,
304,
272,
408,
3110,
6451,
909,
14,
221,
5817,
1072,
436,
4458,
2004,
787,
17487,
14,
10817,
1684,
1021,
3004,
26,
10817,
2088,
1558,
259,
446,
1414,
370,
506,
7934,
2126,
1072,
3299,
446,
1414,
1072,
12,
3839,
435,
4635,
2126,
2004,
755,
446,
4458,
2004,
12,
465,
2138,
701,
3618,
267,
2126,
9009,
263,
446,
4465,
1324,
367,
1414,
2126,
3839,
755,
446,
4465,
1072,
402,
1414,
1380,
3335,
508,
756,
2126,
4635,
755,
446,
4465,
1125,
402,
1414,
1380,
818,
508,
650,
436,
3335,
508,
756,
267,
2126,
408,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2088,
1558,
12,
2589,
29,
736,
14,
2314,
12,
818,
29,
20,
12,
3335,
29,
549,
12,
20169,
3618,
29,
549,
12,
13097,
29,
403,
304,
267,
408,
2543,
11097,
14,
13596,
536,
263,
446,
2462,
536,
370,
675,
1380,
3879,
314,
1414,
1779,
2088,
1558,
257,
446,
1414,
1059,
370,
5341,
1779,
1324,
1558,
446,
1059,
370,
870,
370,
1414,
1159,
9009,
1779,
2589,
260,
446,
5218,
3734,
2600,
1779,
818,
263,
446,
650,
367,
17758,
19,
436,
841,
367,
17758,
20,
1779,
3335,
420,
446,
734,
5324,
370,
506,
12396,
543,
1072,
342,
1083,
1779,
3618,
263,
446,
372,
9939,
2410,
1343,
342,
365,
2797,
436,
1072,
221,
586,
1414,
2058,
465,
2985,
11492,
370,
3839,
624,
398,
1300,
4436,
855,
826,
721,
277,
12,
536,
29,
354,
9,
398,
291,
14,
1760,
1558,
275,
2088,
1558,
267,
291,
855,
632,
275,
818,
267,
291,
855,
2738,
275,
3335,
267,
291,
855,
2573,
275,
3618,
267,
291,
855,
8563,
275,
13097,
267,
291,
855,
1199,
3299,
275,
942,
267,
291,
855,
1205,
275,
488,
267,
291,
855,
3150,
275,
488,
267,
291,
855,
374,
13430,
275,
5796,
14,
2390,
342,
267,
291,
855,
374,
13430,
14,
3584,
342,
2728,
291,
14,
6626,
275,
488,
267,
291,
14,
2703,
275,
488,
267,
291,
14,
3083,
275,
488,
398,
291,
855,
1813,
275,
2589,
2286,
347,
1255,
8,
277,
304,
267,
408,
7259,
8639,
1255,
1083,
14,
221,
17536,
402,
314,
1736,
10986,
2348,
14,
221,
1343,
342,
288,
1077,
506,
2797,
315,
4192,
402,
642,
1083,
1041,
10631,
2269,
3567,
275,
488,
267,
340,
291,
855,
8563,
26,
288,
340,
747,
14,
515,
14,
2444,
8,
277,
855,
8563,
304,
355,
2269,
3567,
275,
747,
14,
9458,
342,
257,
355,
747,
14,
8563,
8,
277,
855,
8563,
9,
288,
587,
26,
355,
746,
2186,
8,
490,
298,
4129,
3110,
26,
3866,
13097,
2013,
26,
450,
83,
2,
450,
15324,
291,
855,
8563,
9,
10631,
2088,
275,
488,
267,
340,
291,
855,
632,
508,
650,
26,
288,
2088,
275,
485,
7942,
19,
7744,
8,
277,
14,
1760,
1558,
12,
2589,
29,
277,
855,
1813,
9,
267,
587,
26,
288,
2088,
275,
485,
7942,
20,
7744,
8,
277,
14,
1760,
1558,
12,
2589,
29,
277,
855,
1813,
9,
267,
291,
855,
3150,
275,
2088,
14,
3150,
398,
291,
14,
6626,
275,
2088,
14,
475,
1739,
2728,
340,
291,
855,
632,
508,
650,
26,
288,
291,
14,
3083,
275,
2088,
14,
335,
382,
2303,
398,
1830,
2088,
14,
504,
1739,
508,
488,
26,
288,
900,
14,
4532,
8,
17,
9,
2728,
340,
291,
855,
2738,
508,
715,
26,
288,
1072,
275,
2088,
14,
504,
1739,
14,
6407,
342,
288,
1830,
1072,
1137,
8061,
355,
1830,
440,
291,
14,
5720,
14,
374,
1084,
837,
490,
340,
291,
14,
2379,
5318,
14,
374,
1084,
837,
717,
2059,
490,
900,
14,
4532,
8,
17,
9,
355,
291,
855,
1199,
3299,
14,
740,
8,
1199,
9,
355,
1072,
275,
2088,
14,
504,
1739,
14,
6407,
342,
398,
916,
291,
855,
2573,
508,
756,
26,
288,
1072,
275,
2088,
14,
504,
1739,
14,
6407,
342,
288,
1830,
1072,
1137,
8061,
355,
1830,
440,
291,
14,
5720,
14,
374,
1084,
837,
490,
340,
291,
14,
2379
] |
[
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
199,
646,
5796,
12,
900,
12,
747,
12,
984,
12,
10933,
199,
199,
504,
17758,
18,
492,
13995,
20,
12,
13995,
19,
12,
9141,
7902,
199,
504,
4673,
492,
15522,
16718,
12,
15522,
30691,
199,
199,
533,
1300,
4436,
8,
12562,
14,
4436,
304,
272,
408,
1563,
445,
1156,
5796,
1021,
14,
221,
710,
1255,
1083,
1077,
506,
10087,
1041,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
12,
536,
29,
354,
9,
267,
291,
14,
2379,
5318,
275,
5796,
14,
2390,
342,
267,
291,
14,
2379,
5318,
14,
3584,
342,
267,
291,
14,
5720,
275,
5796,
14,
2390,
342,
267,
291,
14,
5720,
14,
409,
342,
267,
291,
14,
374,
13430,
275,
5796,
14,
2390,
342,
267,
291,
14,
374,
13430,
14,
3584,
342,
339,
347,
4263,
8,
277,
12,
2653,
29,
403,
304,
267,
291,
14,
2379,
5318,
14,
409,
342,
267,
5796,
14,
4436,
14,
904,
8,
277,
12,
2653,
9,
339,
347,
16834,
8,
277,
304,
267,
408,
30851,
2462,
1041,
398,
291,
14,
5720,
14,
3584,
342,
339,
347,
13770,
8,
277,
304,
267,
408,
22279,
2462,
3439,
1041,
398,
291,
14,
5720,
14,
409,
342,
199,
199,
533,
3486,
3110,
8,
1095,
4436,
304,
272,
408,
3110,
6451,
909,
14,
221,
5817,
1072,
436,
4458,
2004,
787,
17487,
14,
10817,
1684,
1021,
3004,
26,
10817,
2088,
1558,
259,
446,
1414,
370,
506,
7934,
2126,
1072,
3299,
446,
1414,
1072,
12,
3839,
435,
4635,
2126,
2004,
755,
446,
4458,
2004,
12,
465,
2138,
701,
3618,
267,
2126,
9009,
263,
446,
4465,
1324,
367,
1414,
2126,
3839,
755,
446,
4465,
1072,
402,
1414,
1380,
3335,
508,
756,
2126,
4635,
755,
446,
4465,
1125,
402,
1414,
1380,
818,
508,
650,
436,
3335,
508,
756,
267,
2126,
408,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2088,
1558,
12,
2589,
29,
736,
14,
2314,
12,
818,
29,
20,
12,
3335,
29,
549,
12,
20169,
3618,
29,
549,
12,
13097,
29,
403,
304,
267,
408,
2543,
11097,
14,
13596,
536,
263,
446,
2462,
536,
370,
675,
1380,
3879,
314,
1414,
1779,
2088,
1558,
257,
446,
1414,
1059,
370,
5341,
1779,
1324,
1558,
446,
1059,
370,
870,
370,
1414,
1159,
9009,
1779,
2589,
260,
446,
5218,
3734,
2600,
1779,
818,
263,
446,
650,
367,
17758,
19,
436,
841,
367,
17758,
20,
1779,
3335,
420,
446,
734,
5324,
370,
506,
12396,
543,
1072,
342,
1083,
1779,
3618,
263,
446,
372,
9939,
2410,
1343,
342,
365,
2797,
436,
1072,
221,
586,
1414,
2058,
465,
2985,
11492,
370,
3839,
624,
398,
1300,
4436,
855,
826,
721,
277,
12,
536,
29,
354,
9,
398,
291,
14,
1760,
1558,
275,
2088,
1558,
267,
291,
855,
632,
275,
818,
267,
291,
855,
2738,
275,
3335,
267,
291,
855,
2573,
275,
3618,
267,
291,
855,
8563,
275,
13097,
267,
291,
855,
1199,
3299,
275,
942,
267,
291,
855,
1205,
275,
488,
267,
291,
855,
3150,
275,
488,
267,
291,
855,
374,
13430,
275,
5796,
14,
2390,
342,
267,
291,
855,
374,
13430,
14,
3584,
342,
2728,
291,
14,
6626,
275,
488,
267,
291,
14,
2703,
275,
488,
267,
291,
14,
3083,
275,
488,
398,
291,
855,
1813,
275,
2589,
2286,
347,
1255,
8,
277,
304,
267,
408,
7259,
8639,
1255,
1083,
14,
221,
17536,
402,
314,
1736,
10986,
2348,
14,
221,
1343,
342,
288,
1077,
506,
2797,
315,
4192,
402,
642,
1083,
1041,
10631,
2269,
3567,
275,
488,
267,
340,
291,
855,
8563,
26,
288,
340,
747,
14,
515,
14,
2444,
8,
277,
855,
8563,
304,
355,
2269,
3567,
275,
747,
14,
9458,
342,
257,
355,
747,
14,
8563,
8,
277,
855,
8563,
9,
288,
587,
26,
355,
746,
2186,
8,
490,
298,
4129,
3110,
26,
3866,
13097,
2013,
26,
450,
83,
2,
450,
15324,
291,
855,
8563,
9,
10631,
2088,
275,
488,
267,
340,
291,
855,
632,
508,
650,
26,
288,
2088,
275,
485,
7942,
19,
7744,
8,
277,
14,
1760,
1558,
12,
2589,
29,
277,
855,
1813,
9,
267,
587,
26,
288,
2088,
275,
485,
7942,
20,
7744,
8,
277,
14,
1760,
1558,
12,
2589,
29,
277,
855,
1813,
9,
267,
291,
855,
3150,
275,
2088,
14,
3150,
398,
291,
14,
6626,
275,
2088,
14,
475,
1739,
2728,
340,
291,
855,
632,
508,
650,
26,
288,
291,
14,
3083,
275,
2088,
14,
335,
382,
2303,
398,
1830,
2088,
14,
504,
1739,
508,
488,
26,
288,
900,
14,
4532,
8,
17,
9,
2728,
340,
291,
855,
2738,
508,
715,
26,
288,
1072,
275,
2088,
14,
504,
1739,
14,
6407,
342,
288,
1830,
1072,
1137,
8061,
355,
1830,
440,
291,
14,
5720,
14,
374,
1084,
837,
490,
340,
291,
14,
2379,
5318,
14,
374,
1084,
837,
717,
2059,
490,
900,
14,
4532,
8,
17,
9,
355,
291,
855,
1199,
3299,
14,
740,
8,
1199,
9,
355,
1072,
275,
2088,
14,
504,
1739,
14,
6407,
342,
398,
916,
291,
855,
2573,
508,
756,
26,
288,
1072,
275,
2088,
14,
504,
1739,
14,
6407,
342,
288,
1830,
1072,
1137,
8061,
355,
1830,
440,
291,
14,
5720,
14,
374,
1084,
837,
490,
340,
291,
14,
2379,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
invisiblek/python-for-android
|
python-modules/twisted/twisted/mail/test/test_mailmail.py
|
54
|
2688
|
# Copyright (c) 2008 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.mail.scripts.mailmail}, the implementation of the
command line program I{mailmail}.
"""
import sys
from StringIO import StringIO
from twisted.trial.unittest import TestCase
from twisted.mail.scripts.mailmail import parseOptions
class OptionsTests(TestCase):
"""
Tests for L{parseOptions} which parses command line arguments and reads
message text from stdin to produce an L{Options} instance which can be
used to send a message.
"""
def test_unspecifiedRecipients(self):
"""
If no recipients are given in the argument list and there is no
recipient header in the message text, L{parseOptions} raises
L{SystemExit} with a string describing the problem.
"""
self.addCleanup(setattr, sys, 'stdin', sys.stdin)
sys.stdin = StringIO(
'Subject: foo\n'
'\n'
'Hello, goodbye.\n')
exc = self.assertRaises(SystemExit, parseOptions, [])
self.assertEqual(exc.args, ('No recipients specified.',))
def test_listQueueInformation(self):
"""
The I{-bp} option for listing queue information is unsupported and
if it is passed to L{parseOptions}, L{SystemExit} is raised.
"""
exc = self.assertRaises(SystemExit, parseOptions, ['-bp'])
self.assertEqual(exc.args, ("Unsupported option.",))
def test_stdioTransport(self):
"""
The I{-bs} option for using stdin and stdout as the SMTP transport
is unsupported and if it is passed to L{parseOptions}, L{SystemExit}
is raised.
"""
exc = self.assertRaises(SystemExit, parseOptions, ['-bs'])
self.assertEqual(exc.args, ("Unsupported option.",))
def test_ignoreFullStop(self):
"""
The I{-i} and I{-oi} options for ignoring C{"."} by itself on a line
are unsupported and if either is passed to L{parseOptions},
L{SystemExit} is raised.
"""
exc = self.assertRaises(SystemExit, parseOptions, ['-i'])
self.assertEqual(exc.args, ("Unsupported option.",))
exc = self.assertRaises(SystemExit, parseOptions, ['-oi'])
self.assertEqual(exc.args, ("Unsupported option.",))
def test_copyAliasedSender(self):
"""
The I{-om} option for copying the sender if they appear in an alias
expansion is unsupported and if it is passed to L{parseOptions},
L{SystemExit} is raised.
"""
exc = self.assertRaises(SystemExit, parseOptions, ['-om'])
self.assertEqual(exc.args, ("Unsupported option.",))
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
9079,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
1198,
14,
6429,
14,
1198,
1198,
1386,
314,
4514,
402,
314,
199,
1531,
1004,
2240,
473,
91,
1198,
1198,
5565,
199,
624,
199,
199,
646,
984,
199,
504,
5228,
492,
5228,
199,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
504,
7390,
14,
1198,
14,
6429,
14,
1198,
1198,
492,
2198,
4558,
421,
199,
533,
8394,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1122,
4558,
93,
1314,
19953,
1414,
1004,
2368,
436,
11597,
272,
1245,
1318,
687,
9009,
370,
7389,
376,
491,
91,
4558,
93,
1256,
1314,
883,
506,
272,
1202,
370,
3222,
282,
1245,
14,
272,
408,
272,
347,
511,
63,
324,
10085,
26893,
83,
8,
277,
304,
267,
408,
267,
982,
949,
19255,
787,
1627,
315,
314,
1423,
769,
436,
2337,
365,
949,
267,
10318,
1406,
315,
314,
1245,
1318,
12,
491,
91,
1122,
4558,
93,
6534,
267,
491,
91,
24738,
93,
543,
282,
1059,
13660,
314,
5160,
14,
267,
408,
267,
291,
14,
12808,
8,
10202,
12,
984,
12,
283,
6626,
297,
984,
14,
6626,
9,
267,
984,
14,
6626,
275,
5228,
8,
288,
283,
13528,
26,
3925,
60,
78,
7,
288,
1557,
78,
7,
288,
283,
6257,
12,
6954,
16481,
3134,
78,
358,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
3073,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
661,
1944,
19255,
2013,
3130,
430,
2378,
347,
511,
63,
513,
3737,
4935,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
10913,
93,
945,
367,
13778,
4126,
2556,
365,
16313,
436,
267,
340,
652,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
491,
91,
24738,
93,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
10913,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
2378,
347,
511,
63,
32011,
7836,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
1533,
93,
945,
367,
1808,
9009,
436,
3839,
465,
314,
19810,
7773,
267,
365,
16313,
436,
340,
652,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
491,
91,
24738,
93,
267,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
1533,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
2378,
347,
511,
63,
4247,
9042,
6293,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
73,
93,
436,
473,
91,
13,
16142,
93,
1511,
367,
17289,
445,
91,
1674,
3570,
701,
6337,
641,
282,
1004,
267,
787,
16313,
436,
340,
1902,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
267,
491,
91,
24738,
93,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
73,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
16142,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
2378,
347,
511,
63,
1574,
6985,
11185,
28002,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
676,
93,
945,
367,
16743,
314,
8904,
340,
2985,
7468,
315,
376,
5162,
267,
14819,
365,
16313,
436,
340,
652,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
267,
491,
91,
24738,
93,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
676,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
9079,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
1198,
14,
6429,
14,
1198,
1198,
1386,
314,
4514,
402,
314,
199,
1531,
1004,
2240,
473,
91,
1198,
1198,
5565,
199,
624,
199,
199,
646,
984,
199,
504,
5228,
492,
5228,
199,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
504,
7390,
14,
1198,
14,
6429,
14,
1198,
1198,
492,
2198,
4558,
421,
199,
533,
8394,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
1122,
4558,
93,
1314,
19953,
1414,
1004,
2368,
436,
11597,
272,
1245,
1318,
687,
9009,
370,
7389,
376,
491,
91,
4558,
93,
1256,
1314,
883,
506,
272,
1202,
370,
3222,
282,
1245,
14,
272,
408,
272,
347,
511,
63,
324,
10085,
26893,
83,
8,
277,
304,
267,
408,
267,
982,
949,
19255,
787,
1627,
315,
314,
1423,
769,
436,
2337,
365,
949,
267,
10318,
1406,
315,
314,
1245,
1318,
12,
491,
91,
1122,
4558,
93,
6534,
267,
491,
91,
24738,
93,
543,
282,
1059,
13660,
314,
5160,
14,
267,
408,
267,
291,
14,
12808,
8,
10202,
12,
984,
12,
283,
6626,
297,
984,
14,
6626,
9,
267,
984,
14,
6626,
275,
5228,
8,
288,
283,
13528,
26,
3925,
60,
78,
7,
288,
1557,
78,
7,
288,
283,
6257,
12,
6954,
16481,
3134,
78,
358,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
3073,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
661,
1944,
19255,
2013,
3130,
430,
2378,
347,
511,
63,
513,
3737,
4935,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
10913,
93,
945,
367,
13778,
4126,
2556,
365,
16313,
436,
267,
340,
652,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
491,
91,
24738,
93,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
10913,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
2378,
347,
511,
63,
32011,
7836,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
1533,
93,
945,
367,
1808,
9009,
436,
3839,
465,
314,
19810,
7773,
267,
365,
16313,
436,
340,
652,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
491,
91,
24738,
93,
267,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
1533,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
2378,
347,
511,
63,
4247,
9042,
6293,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
73,
93,
436,
473,
91,
13,
16142,
93,
1511,
367,
17289,
445,
91,
1674,
3570,
701,
6337,
641,
282,
1004,
267,
787,
16313,
436,
340,
1902,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
267,
491,
91,
24738,
93,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
73,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
16142,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
2378,
347,
511,
63,
1574,
6985,
11185,
28002,
8,
277,
304,
267,
408,
267,
710,
473,
91,
13,
676,
93,
945,
367,
16743,
314,
8904,
340,
2985,
7468,
315,
376,
5162,
267,
14819,
365,
16313,
436,
340,
652,
365,
3032,
370,
491,
91,
1122,
4558,
1386,
267,
491,
91,
24738,
93,
365,
4915,
14,
267,
408,
267,
3178,
275,
291,
14,
1855,
8,
24738,
12,
2198,
4558,
12,
11573,
676,
1105,
267,
291,
14,
629,
8,
2804,
14,
589,
12,
1689,
12647,
945,
4765,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
KyleAMoore/KanjiNani
|
Android/.buildozer/android/platform/build/build/other_builds/kivy-python3crystax-sdl2/armeabi-v7a/kivy/kivy/input/providers/mactouch.py
|
21
|
7204
|
'''
Native support of MultitouchSupport framework for MacBook (MaxOSX platform)
===========================================================================
'''
__all__ = ('MacMotionEventProvider', )
import ctypes
import threading
import collections
import os
from kivy.input.provider import MotionEventProvider
from kivy.input.factory import MotionEventFactory
from kivy.input.motionevent import MotionEvent
from kivy.input.shape import ShapeRect
if 'KIVY_DOC' not in os.environ:
CFArrayRef = ctypes.c_void_p
CFMutableArrayRef = ctypes.c_void_p
CFIndex = ctypes.c_long
dll = '/System/Library/PrivateFrameworks/' + \
'MultitouchSupport.framework/MultitouchSupport'
MultitouchSupport = ctypes.CDLL(dll)
CFArrayGetCount = MultitouchSupport.CFArrayGetCount
CFArrayGetCount.argtypes = [CFArrayRef]
CFArrayGetCount.restype = CFIndex
CFArrayGetValueAtIndex = MultitouchSupport.CFArrayGetValueAtIndex
CFArrayGetValueAtIndex.argtypes = [CFArrayRef, CFIndex]
CFArrayGetValueAtIndex.restype = ctypes.c_void_p
MTDeviceCreateList = MultitouchSupport.MTDeviceCreateList
MTDeviceCreateList.argtypes = []
MTDeviceCreateList.restype = CFMutableArrayRef
class MTPoint(ctypes.Structure):
_fields_ = [('x', ctypes.c_float),
('y', ctypes.c_float)]
class MTVector(ctypes.Structure):
_fields_ = [('position', MTPoint),
('velocity', MTPoint)]
class MTData(ctypes.Structure):
_fields_ = [
('frame', ctypes.c_int),
('timestamp', ctypes.c_double),
('identifier', ctypes.c_int),
# Current state (of unknown meaning).
('state', ctypes.c_int),
('unknown1', ctypes.c_int),
('unknown2', ctypes.c_int),
# Normalized position and vector of the touch (0 to 1)
('normalized', MTVector),
# The area of the touch.
('size', ctypes.c_float),
('unknown3', ctypes.c_int),
# The following three define the ellipsoid of a finger.
('angle', ctypes.c_float),
('major_axis', ctypes.c_float),
('minor_axis', ctypes.c_float),
('unknown4', MTVector),
('unknown5_1', ctypes.c_int),
('unknown5_2', ctypes.c_int),
('unknown6', ctypes.c_float), ]
MTDataRef = ctypes.POINTER(MTData)
MTContactCallbackFunction = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int,
MTDataRef, ctypes.c_int,
ctypes.c_double, ctypes.c_int)
MTDeviceRef = ctypes.c_void_p
MTRegisterContactFrameCallback = \
MultitouchSupport.MTRegisterContactFrameCallback
MTRegisterContactFrameCallback.argtypes = \
[MTDeviceRef, MTContactCallbackFunction]
MTRegisterContactFrameCallback.restype = None
MTDeviceStart = MultitouchSupport.MTDeviceStart
MTDeviceStart.argtypes = [MTDeviceRef, ctypes.c_int]
MTDeviceStart.restype = None
else:
MTContactCallbackFunction = lambda x: None
class MacMotionEvent(MotionEvent):
'''MotionEvent representing a contact point on the touchpad. Supports pos
and shape profiles.
'''
def depack(self, args):
self.is_touch = True
self.shape = ShapeRect()
self.sx, self.sy = args[0], args[1]
self.shape.width = args[2]
self.shape.height = args[2]
self.profile = ('pos', 'shape')
super(MacMotionEvent, self).depack(args)
def __str__(self):
return '<MacMotionEvent id=%d pos=(%f, %f) device=%s>' \
% (self.id, self.sx, self.sy, self.device)
_instance = None
class MacMotionEventProvider(MotionEventProvider):
def __init__(self, *largs, **kwargs):
global _instance
if _instance is not None:
raise Exception('Only one MacMotionEvent provider is allowed.')
_instance = self
super(MacMotionEventProvider, self).__init__(*largs, **kwargs)
def start(self):
# global uid
self.uid = 0
# touches will be per devices
self.touches = {}
# lock needed to access on uid
self.lock = threading.Lock()
# event queue to dispatch in main thread
self.queue = collections.deque()
# ok, listing devices, and attach !
devices = MultitouchSupport.MTDeviceCreateList()
num_devices = CFArrayGetCount(devices)
for i in range(num_devices):
device = CFArrayGetValueAtIndex(devices, i)
# create touch dict for this device
data_id = str(device)
self.touches[data_id] = {}
# start !
MTRegisterContactFrameCallback(device, self._mts_callback)
MTDeviceStart(device, 0)
def update(self, dispatch_fn):
# dispatch all event from threads
try:
while True:
event_type, touch = self.queue.popleft()
dispatch_fn(event_type, touch)
except:
pass
def stop(self):
# i don't known how to stop it...
pass
@MTContactCallbackFunction
def _mts_callback(device, data_ptr, n_fingers, timestamp, frame):
global _instance
devid = str(device)
# XXX create live touch, we get one case that
# the device announced by macosx don't match the device
# in _mts_callback....
if devid not in _instance.touches:
_instance.touches[devid] = {}
touches = _instance.touches[devid]
actives = []
for i in range(n_fingers):
# get pointer on data
data = data_ptr[i]
# add this touch as an active touch
actives.append(data.identifier)
# extract identifier
data_id = data.identifier
# prepare argument position
norm_pos = data.normalized.position
args = (norm_pos.x, norm_pos.y, data.size)
if data_id not in touches:
# increment uid
_instance.lock.acquire()
_instance.uid += 1
# create a touch
touch = MacMotionEvent(_instance.device, _instance.uid, args)
_instance.lock.release()
# create event
_instance.queue.append(('begin', touch))
# store touch
touches[data_id] = touch
else:
touch = touches[data_id]
# check if he really moved
if data.normalized.position.x == touch.sx and \
data.normalized.position.y == touch.sy:
continue
touch.move(args)
_instance.queue.append(('update', touch))
# delete old touchs
for tid in list(touches.keys())[:]:
if tid not in actives:
touch = touches[tid]
touch.update_time_end()
_instance.queue.append(('end', touch))
del touches[tid]
return 0
MotionEventFactory.register('mactouch', MacMotionEventProvider)
|
gpl-3.0
|
[
2344,
199,
19675,
2291,
402,
6879,
12376,
11532,
10059,
367,
10444,
8696,
334,
4261,
25160,
4298,
9,
199,
5695,
21326,
199,
2344,
199,
199,
363,
452,
363,
275,
661,
3399,
24875,
2390,
6663,
297,
776,
199,
199,
646,
5577,
199,
646,
5796,
199,
646,
5055,
199,
646,
747,
199,
504,
17227,
14,
1210,
14,
3780,
492,
3930,
296,
2390,
6663,
199,
504,
17227,
14,
1210,
14,
3702,
492,
3930,
296,
2390,
2927,
199,
504,
17227,
14,
1210,
14,
15335,
1430,
492,
3930,
296,
2390,
199,
504,
17227,
14,
1210,
14,
1392,
492,
16528,
8252,
199,
199,
692,
283,
43,
6882,
57,
63,
16618,
7,
440,
315,
747,
14,
2314,
26,
272,
6035,
3836,
2891,
275,
5577,
14,
67,
63,
1647,
63,
80,
272,
6035,
17707,
3836,
2891,
275,
5577,
14,
67,
63,
1647,
63,
80,
272,
6035,
2681,
275,
5577,
14,
67,
63,
2809,
339,
17112,
275,
1994,
3989,
15,
7424,
15,
12185,
30052,
4805,
435,
971,
267,
283,
3947,
12376,
11532,
14,
4857,
15,
3947,
12376,
11532,
7,
272,
6879,
12376,
11532,
275,
5577,
14,
7695,
4464,
8,
9259,
9,
339,
6035,
3836,
1002,
2353,
275,
6879,
12376,
11532,
14,
5487,
3836,
1002,
2353,
272,
6035,
3836,
1002,
2353,
14,
10025,
275,
359,
5487,
3836,
2891,
61,
272,
6035,
3836,
1002,
2353,
14,
9990,
275,
6035,
2681,
339,
6035,
3836,
9334,
1271,
2681,
275,
6879,
12376,
11532,
14,
5487,
3836,
9334,
1271,
2681,
272,
6035,
3836,
9334,
1271,
2681,
14,
10025,
275,
359,
5487,
3836,
2891,
12,
6035,
2681,
61,
272,
6035,
3836,
9334,
1271,
2681,
14,
9990,
275,
5577,
14,
67,
63,
1647,
63,
80,
339,
603,
52,
2510,
2499,
1296,
275,
6879,
12376,
11532,
14,
5747,
2510,
2499,
1296,
272,
603,
52,
2510,
2499,
1296,
14,
10025,
275,
942,
272,
603,
52,
2510,
2499,
1296,
14,
9990,
275,
6035,
17707,
3836,
2891,
339,
1021,
603,
52,
3428,
8,
9798,
14,
10766,
304,
267,
485,
955,
63,
275,
4274,
88,
297,
5577,
14,
67,
63,
1609,
395,
490,
661,
89,
297,
5577,
14,
67,
63,
1609,
1874,
339,
1021,
603,
52,
3646,
8,
9798,
14,
10766,
304,
267,
485,
955,
63,
275,
4274,
3124,
297,
603,
52,
3428,
395,
490,
661,
16350,
297,
603,
52,
3428,
1874,
339,
1021,
603,
52,
1451,
8,
9798,
14,
10766,
304,
267,
485,
955,
63,
275,
359,
288,
661,
1943,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
3954,
297,
5577,
14,
67,
63,
3157,
395,
288,
661,
5364,
297,
5577,
14,
67,
63,
442,
395,
288,
327,
9338,
1174,
334,
1618,
5809,
11150,
680,
288,
661,
929,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
17,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
18,
297,
5577,
14,
67,
63,
442,
395,
288,
327,
11514,
1759,
3421,
436,
5477,
402,
314,
12943,
334,
16,
370,
413,
9,
288,
661,
12916,
297,
603,
52,
3646,
395,
288,
327,
710,
9150,
402,
314,
12943,
14,
288,
661,
890,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
5187,
19,
297,
5577,
14,
67,
63,
442,
395,
288,
327,
710,
2569,
7795,
5627,
314,
16028,
29331,
402,
282,
289,
7886,
14,
288,
661,
4593,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
8452,
63,
3127,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
11067,
63,
3127,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
5187,
20,
297,
603,
52,
3646,
395,
288,
661,
5187,
21,
63,
17,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
21,
63,
18,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
22,
297,
5577,
14,
67,
63,
1609,
395,
1622,
339,
603,
52,
1451,
2891,
275,
5577,
14,
11260,
8,
5747,
1451,
9,
339,
603,
52,
14499,
2806,
3481,
275,
5577,
14,
5487,
10637,
8,
9798,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
1740,
603,
52,
1451,
2891,
12,
5577,
14,
67,
63,
442,
12,
1740,
5577,
14,
67,
63,
3157,
12,
5577,
14,
67,
63,
442,
9,
339,
603,
52,
2510,
2891,
275,
5577,
14,
67,
63,
1647,
63,
80,
339,
603,
52,
7099,
14499,
3160,
2806,
275,
971,
267,
6879,
12376,
11532,
14,
5747,
7099,
14499,
3160,
2806,
272,
603,
52,
7099,
14499,
3160,
2806,
14,
10025,
275,
971,
267,
359,
5747,
2510,
2891,
12,
603,
52,
14499,
2806,
3481,
61,
272,
603,
52,
7099,
14499,
3160,
2806,
14,
9990,
275,
488,
339,
603,
52,
2510,
3162,
275,
6879,
12376,
11532,
14,
5747,
2510,
3162,
272,
603,
52,
2510,
3162,
14,
10025,
275,
359,
5747,
2510,
2891,
12,
5577,
14,
67,
63,
442,
61,
272,
603,
52,
2510,
3162,
14,
9990,
275,
488,
199,
199,
2836,
26,
272,
603,
52,
14499,
2806,
3481,
275,
2400,
671,
26,
488,
421,
199,
533,
10444,
24875,
2390,
8,
24875,
2390,
304,
272,
1449,
24875,
2390,
6144,
282,
8966,
2376,
641,
314,
12943,
6226,
14,
32090,
2086,
272,
436,
2215,
17390,
14,
272,
1449,
339,
347,
477,
1389,
8,
277,
12,
1249,
304,
267,
291,
14,
374,
63,
12376,
275,
715,
267,
291,
14,
1392,
275,
16528,
8252,
342,
267,
291,
14,
12915,
12,
291,
14,
1786,
275,
1249,
59,
16,
467,
1249,
59,
17,
61,
267,
291,
14,
1392,
14,
2063,
275,
1249,
59,
18,
61,
267,
291,
14,
1392,
14,
3333,
275,
1249,
59,
18,
61,
267,
291,
14,
2913,
275,
661,
1712,
297,
283,
1392,
358,
267,
1613,
8,
3399,
24875,
2390,
12,
291,
680,
271,
1389,
8,
589,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2650,
3399,
24875,
2390,
1305,
2458,
68,
2086,
2687,
5,
70,
12,
450,
70,
9,
2243,
2458,
83,
3524,
971,
288,
450,
334,
277,
14,
344,
12,
291,
14,
12915,
12,
291,
14,
1786,
12,
291,
14,
1782,
9,
421,
199,
63,
842,
275,
488,
421,
199,
533,
10444,
24875,
2390,
6663,
8,
24875,
2390,
6663,
304,
339,
347,
636,
826,
721,
277,
12,
627,
76,
589,
12,
1011,
958,
304,
267,
2288,
485,
842,
267,
340,
485,
842,
365,
440,
488,
26,
288,
746,
2186,
360,
5903,
1373,
10444,
24875,
2390,
5022,
365,
4370,
2659,
267,
485,
842,
275,
291,
267,
1613,
8,
3399,
24875,
2390
] |
[
199,
19675,
2291,
402,
6879,
12376,
11532,
10059,
367,
10444,
8696,
334,
4261,
25160,
4298,
9,
199,
5695,
21326,
199,
2344,
199,
199,
363,
452,
363,
275,
661,
3399,
24875,
2390,
6663,
297,
776,
199,
199,
646,
5577,
199,
646,
5796,
199,
646,
5055,
199,
646,
747,
199,
504,
17227,
14,
1210,
14,
3780,
492,
3930,
296,
2390,
6663,
199,
504,
17227,
14,
1210,
14,
3702,
492,
3930,
296,
2390,
2927,
199,
504,
17227,
14,
1210,
14,
15335,
1430,
492,
3930,
296,
2390,
199,
504,
17227,
14,
1210,
14,
1392,
492,
16528,
8252,
199,
199,
692,
283,
43,
6882,
57,
63,
16618,
7,
440,
315,
747,
14,
2314,
26,
272,
6035,
3836,
2891,
275,
5577,
14,
67,
63,
1647,
63,
80,
272,
6035,
17707,
3836,
2891,
275,
5577,
14,
67,
63,
1647,
63,
80,
272,
6035,
2681,
275,
5577,
14,
67,
63,
2809,
339,
17112,
275,
1994,
3989,
15,
7424,
15,
12185,
30052,
4805,
435,
971,
267,
283,
3947,
12376,
11532,
14,
4857,
15,
3947,
12376,
11532,
7,
272,
6879,
12376,
11532,
275,
5577,
14,
7695,
4464,
8,
9259,
9,
339,
6035,
3836,
1002,
2353,
275,
6879,
12376,
11532,
14,
5487,
3836,
1002,
2353,
272,
6035,
3836,
1002,
2353,
14,
10025,
275,
359,
5487,
3836,
2891,
61,
272,
6035,
3836,
1002,
2353,
14,
9990,
275,
6035,
2681,
339,
6035,
3836,
9334,
1271,
2681,
275,
6879,
12376,
11532,
14,
5487,
3836,
9334,
1271,
2681,
272,
6035,
3836,
9334,
1271,
2681,
14,
10025,
275,
359,
5487,
3836,
2891,
12,
6035,
2681,
61,
272,
6035,
3836,
9334,
1271,
2681,
14,
9990,
275,
5577,
14,
67,
63,
1647,
63,
80,
339,
603,
52,
2510,
2499,
1296,
275,
6879,
12376,
11532,
14,
5747,
2510,
2499,
1296,
272,
603,
52,
2510,
2499,
1296,
14,
10025,
275,
942,
272,
603,
52,
2510,
2499,
1296,
14,
9990,
275,
6035,
17707,
3836,
2891,
339,
1021,
603,
52,
3428,
8,
9798,
14,
10766,
304,
267,
485,
955,
63,
275,
4274,
88,
297,
5577,
14,
67,
63,
1609,
395,
490,
661,
89,
297,
5577,
14,
67,
63,
1609,
1874,
339,
1021,
603,
52,
3646,
8,
9798,
14,
10766,
304,
267,
485,
955,
63,
275,
4274,
3124,
297,
603,
52,
3428,
395,
490,
661,
16350,
297,
603,
52,
3428,
1874,
339,
1021,
603,
52,
1451,
8,
9798,
14,
10766,
304,
267,
485,
955,
63,
275,
359,
288,
661,
1943,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
3954,
297,
5577,
14,
67,
63,
3157,
395,
288,
661,
5364,
297,
5577,
14,
67,
63,
442,
395,
288,
327,
9338,
1174,
334,
1618,
5809,
11150,
680,
288,
661,
929,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
17,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
18,
297,
5577,
14,
67,
63,
442,
395,
288,
327,
11514,
1759,
3421,
436,
5477,
402,
314,
12943,
334,
16,
370,
413,
9,
288,
661,
12916,
297,
603,
52,
3646,
395,
288,
327,
710,
9150,
402,
314,
12943,
14,
288,
661,
890,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
5187,
19,
297,
5577,
14,
67,
63,
442,
395,
288,
327,
710,
2569,
7795,
5627,
314,
16028,
29331,
402,
282,
289,
7886,
14,
288,
661,
4593,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
8452,
63,
3127,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
11067,
63,
3127,
297,
5577,
14,
67,
63,
1609,
395,
288,
661,
5187,
20,
297,
603,
52,
3646,
395,
288,
661,
5187,
21,
63,
17,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
21,
63,
18,
297,
5577,
14,
67,
63,
442,
395,
288,
661,
5187,
22,
297,
5577,
14,
67,
63,
1609,
395,
1622,
339,
603,
52,
1451,
2891,
275,
5577,
14,
11260,
8,
5747,
1451,
9,
339,
603,
52,
14499,
2806,
3481,
275,
5577,
14,
5487,
10637,
8,
9798,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
1740,
603,
52,
1451,
2891,
12,
5577,
14,
67,
63,
442,
12,
1740,
5577,
14,
67,
63,
3157,
12,
5577,
14,
67,
63,
442,
9,
339,
603,
52,
2510,
2891,
275,
5577,
14,
67,
63,
1647,
63,
80,
339,
603,
52,
7099,
14499,
3160,
2806,
275,
971,
267,
6879,
12376,
11532,
14,
5747,
7099,
14499,
3160,
2806,
272,
603,
52,
7099,
14499,
3160,
2806,
14,
10025,
275,
971,
267,
359,
5747,
2510,
2891,
12,
603,
52,
14499,
2806,
3481,
61,
272,
603,
52,
7099,
14499,
3160,
2806,
14,
9990,
275,
488,
339,
603,
52,
2510,
3162,
275,
6879,
12376,
11532,
14,
5747,
2510,
3162,
272,
603,
52,
2510,
3162,
14,
10025,
275,
359,
5747,
2510,
2891,
12,
5577,
14,
67,
63,
442,
61,
272,
603,
52,
2510,
3162,
14,
9990,
275,
488,
199,
199,
2836,
26,
272,
603,
52,
14499,
2806,
3481,
275,
2400,
671,
26,
488,
421,
199,
533,
10444,
24875,
2390,
8,
24875,
2390,
304,
272,
1449,
24875,
2390,
6144,
282,
8966,
2376,
641,
314,
12943,
6226,
14,
32090,
2086,
272,
436,
2215,
17390,
14,
272,
1449,
339,
347,
477,
1389,
8,
277,
12,
1249,
304,
267,
291,
14,
374,
63,
12376,
275,
715,
267,
291,
14,
1392,
275,
16528,
8252,
342,
267,
291,
14,
12915,
12,
291,
14,
1786,
275,
1249,
59,
16,
467,
1249,
59,
17,
61,
267,
291,
14,
1392,
14,
2063,
275,
1249,
59,
18,
61,
267,
291,
14,
1392,
14,
3333,
275,
1249,
59,
18,
61,
267,
291,
14,
2913,
275,
661,
1712,
297,
283,
1392,
358,
267,
1613,
8,
3399,
24875,
2390,
12,
291,
680,
271,
1389,
8,
589,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2650,
3399,
24875,
2390,
1305,
2458,
68,
2086,
2687,
5,
70,
12,
450,
70,
9,
2243,
2458,
83,
3524,
971,
288,
450,
334,
277,
14,
344,
12,
291,
14,
12915,
12,
291,
14,
1786,
12,
291,
14,
1782,
9,
421,
199,
63,
842,
275,
488,
421,
199,
533,
10444,
24875,
2390,
6663,
8,
24875,
2390,
6663,
304,
339,
347,
636,
826,
721,
277,
12,
627,
76,
589,
12,
1011,
958,
304,
267,
2288,
485,
842,
267,
340,
485,
842,
365,
440,
488,
26,
288,
746,
2186,
360,
5903,
1373,
10444,
24875,
2390,
5022,
365,
4370,
2659,
267,
485,
842,
275,
291,
267,
1613,
8,
3399,
24875,
2390,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tommytarts/QuantumKernelM8-GPe
|
tools/perf/scripts/python/futex-contention.py
|
11261
|
1486
|
# futex contention
# (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Translation of:
#
# http://sourceware.org/systemtap/wiki/WSFutexContention
#
# to perf python scripting.
#
# Measures futex contention
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Util import *
process_names = {}
thread_thislock = {}
thread_blocktime = {}
lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time
process_names = {} # long-lived pid-to-execname mapping
def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm,
nr, uaddr, op, val, utime, uaddr2, val3):
cmd = op & FUTEX_CMD_MASK
if cmd != FUTEX_WAIT:
return # we don't care about originators of WAKE events
process_names[tid] = comm
thread_thislock[tid] = uaddr
thread_blocktime[tid] = nsecs(s, ns)
def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm,
nr, ret):
if thread_blocktime.has_key(tid):
elapsed = nsecs(s, ns) - thread_blocktime[tid]
add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
del thread_blocktime[tid]
del thread_thislock[tid]
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
for (tid, lock) in lock_waits:
min, max, avg, count = lock_waits[tid, lock]
print "%s[%d] lock %x contended %d times, %d avg ns" % \
(process_names[tid], tid, lock, count, avg)
|
gpl-2.0
|
[
3,
289,
18173,
406,
9553,
199,
3,
334,
67,
9,
7129,
12,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
25224,
402,
26,
199,
3,
199,
3,
1455,
921,
1365,
1068,
14,
1308,
15,
2253,
16609,
15,
6797,
15,
5035,
38,
18173,
714,
9553,
199,
3,
199,
3,
370,
8582,
2366,
2884,
316,
14,
199,
3,
199,
3,
3194,
305,
1482,
289,
18173,
406,
9553,
199,
199,
646,
747,
12,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
504,
21248,
492,
627,
199,
199,
1412,
63,
1247,
275,
1052,
199,
2671,
63,
3749,
831,
275,
1052,
199,
2671,
63,
1457,
521,
275,
1052,
199,
199,
831,
63,
758,
1405,
275,
1052,
327,
1846,
13,
317,
1354,
5020,
641,
334,
5700,
12,
831,
9,
1853,
474,
14439,
900,
199,
1412,
63,
1247,
275,
1052,
327,
1846,
13,
317,
1354,
4422,
13,
475,
13,
1628,
354,
4412,
199,
199,
318,
19473,
363,
1274,
63,
4200,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
420,
14762,
12,
399,
2697,
12,
1687,
12,
1139,
12,
399,
521,
12,
399,
2697,
18,
12,
1139,
19,
304,
199,
198,
1760,
275,
1687,
1253,
481,
934,
1438,
63,
9744,
63,
12880,
199,
198,
692,
2088,
1137,
481,
934,
1438,
63,
12458,
26,
507,
198,
1107,
327,
781,
2793,
1133,
10296,
3595,
6330,
2750,
402,
644,
22339,
4474,
421,
198,
1412,
63,
1247,
59,
5700,
61,
275,
1923,
199,
198,
2671,
63,
3749,
831,
59,
5700,
61,
275,
399,
2697,
199,
198,
2671,
63,
1457,
521,
59,
5700,
61,
275,
13781,
8,
83,
12,
700,
9,
199,
199,
318,
19473,
363,
1274,
63,
2224,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
258,
14762,
12,
2203,
304,
199,
198,
692,
2462,
63,
1457,
521,
14,
1989,
63,
498,
8,
5700,
304,
507,
198,
16691,
275,
13781,
8,
83,
12,
700,
9,
446,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
525,
63,
3200,
8,
831,
63,
758,
1405,
12,
334,
5700,
12,
2462,
63,
3749,
831,
59,
5700,
2522,
14439,
9,
507,
198,
2264,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
2264,
2462,
63,
3749,
831,
59,
5700,
61,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
509,
334,
5700,
12,
4650,
9,
315,
4650,
63,
758,
1405,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
4650,
63,
758,
1405,
59,
5700,
12,
4650,
61,
507,
198,
1361,
2071,
83,
9722,
68,
61,
4650,
450,
88,
406,
6943,
450,
68,
5431,
12,
450,
68,
12402,
700,
2,
450,
971,
686,
420,
334,
1412,
63,
1247,
59,
5700,
467,
11559,
12,
4650,
12,
2338,
12,
12402,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
289,
18173,
406,
9553,
199,
3,
334,
67,
9,
7129,
12,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
25224,
402,
26,
199,
3,
199,
3,
1455,
921,
1365,
1068,
14,
1308,
15,
2253,
16609,
15,
6797,
15,
5035,
38,
18173,
714,
9553,
199,
3,
199,
3,
370,
8582,
2366,
2884,
316,
14,
199,
3,
199,
3,
3194,
305,
1482,
289,
18173,
406,
9553,
199,
199,
646,
747,
12,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
504,
21248,
492,
627,
199,
199,
1412,
63,
1247,
275,
1052,
199,
2671,
63,
3749,
831,
275,
1052,
199,
2671,
63,
1457,
521,
275,
1052,
199,
199,
831,
63,
758,
1405,
275,
1052,
327,
1846,
13,
317,
1354,
5020,
641,
334,
5700,
12,
831,
9,
1853,
474,
14439,
900,
199,
1412,
63,
1247,
275,
1052,
327,
1846,
13,
317,
1354,
4422,
13,
475,
13,
1628,
354,
4412,
199,
199,
318,
19473,
363,
1274,
63,
4200,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
420,
14762,
12,
399,
2697,
12,
1687,
12,
1139,
12,
399,
521,
12,
399,
2697,
18,
12,
1139,
19,
304,
199,
198,
1760,
275,
1687,
1253,
481,
934,
1438,
63,
9744,
63,
12880,
199,
198,
692,
2088,
1137,
481,
934,
1438,
63,
12458,
26,
507,
198,
1107,
327,
781,
2793,
1133,
10296,
3595,
6330,
2750,
402,
644,
22339,
4474,
421,
198,
1412,
63,
1247,
59,
5700,
61,
275,
1923,
199,
198,
2671,
63,
3749,
831,
59,
5700,
61,
275,
399,
2697,
199,
198,
2671,
63,
1457,
521,
59,
5700,
61,
275,
13781,
8,
83,
12,
700,
9,
199,
199,
318,
19473,
363,
1274,
63,
2224,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
258,
14762,
12,
2203,
304,
199,
198,
692,
2462,
63,
1457,
521,
14,
1989,
63,
498,
8,
5700,
304,
507,
198,
16691,
275,
13781,
8,
83,
12,
700,
9,
446,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
525,
63,
3200,
8,
831,
63,
758,
1405,
12,
334,
5700,
12,
2462,
63,
3749,
831,
59,
5700,
2522,
14439,
9,
507,
198,
2264,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
2264,
2462,
63,
3749,
831,
59,
5700,
61,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
509,
334,
5700,
12,
4650,
9,
315,
4650,
63,
758,
1405,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
4650,
63,
758,
1405,
59,
5700,
12,
4650,
61,
507,
198,
1361,
2071,
83,
9722,
68,
61,
4650,
450,
88,
406,
6943,
450,
68,
5431,
12,
450,
68,
12402,
700,
2,
450,
971,
686,
420,
334,
1412,
63,
1247,
59,
5700,
467,
11559,
12,
4650,
12,
2338,
12,
12402,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Bulochkin/tensorflow_pack
|
tensorflow/contrib/distributions/python/ops/deterministic.py
|
64
|
13215
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""The Deterministic distribution class."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import abc
import six
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import tensor_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import check_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops.distributions import distribution
__all__ = [
"Deterministic",
"VectorDeterministic",
]
@six.add_metaclass(abc.ABCMeta)
class _BaseDeterministic(distribution.Distribution):
"""Base class for Deterministic distributions."""
def __init__(self,
loc,
atol=None,
rtol=None,
is_vector=False,
validate_args=False,
allow_nan_stats=True,
name="_BaseDeterministic"):
"""Initialize a batch of `_BaseDeterministic` distributions.
The `atol` and `rtol` parameters allow for some slack in `pmf`, `cdf`
computations, e.g. due to floating-point error.
```
pmf(x; loc)
= 1, if Abs(x - loc) <= atol + rtol * Abs(loc),
= 0, otherwise.
```
Args:
loc: Numeric `Tensor`. The point (or batch of points) on which this
distribution is supported.
atol: Non-negative `Tensor` of same `dtype` as `loc` and broadcastable
shape. The absolute tolerance for comparing closeness to `loc`.
Default is `0`.
rtol: Non-negative `Tensor` of same `dtype` as `loc` and broadcastable
shape. The relative tolerance for comparing closeness to `loc`.
Default is `0`.
is_vector: Python `bool`. If `True`, this is for `VectorDeterministic`,
else `Deterministic`.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
(e.g., mean, mode, variance) use the value "`NaN`" to indicate the
result is undefined. When `False`, an exception is raised if one or
more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.
Raises:
ValueError: If `loc` is a scalar.
"""
parameters = locals()
with ops.name_scope(name, values=[loc, atol, rtol]):
loc = ops.convert_to_tensor(loc, name="loc")
if is_vector and validate_args:
msg = "Argument loc must be at least rank 1."
if loc.get_shape().ndims is not None:
if loc.get_shape().ndims < 1:
raise ValueError(msg)
else:
loc = control_flow_ops.with_dependencies(
[check_ops.assert_rank_at_least(loc, 1, message=msg)], loc)
self._loc = loc
super(_BaseDeterministic, self).__init__(
dtype=self._loc.dtype,
reparameterization_type=distribution.NOT_REPARAMETERIZED,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
parameters=parameters,
graph_parents=[self._loc],
name=name)
self._atol = self._get_tol(atol)
self._rtol = self._get_tol(rtol)
# Avoid using the large broadcast with self.loc if possible.
if rtol is None:
self._slack = self.atol
else:
self._slack = self.atol + self.rtol * math_ops.abs(self.loc)
def _get_tol(self, tol):
if tol is None:
return ops.convert_to_tensor(0, dtype=self.loc.dtype)
tol = ops.convert_to_tensor(tol, dtype=self.loc.dtype)
if self.validate_args:
tol = control_flow_ops.with_dependencies([
check_ops.assert_non_negative(
tol, message="Argument 'tol' must be non-negative")
], tol)
return tol
@property
def loc(self):
"""Point (or batch of points) at which this distribution is supported."""
return self._loc
@property
def atol(self):
"""Absolute tolerance for comparing points to `self.loc`."""
return self._atol
@property
def rtol(self):
"""Relative tolerance for comparing points to `self.loc`."""
return self._rtol
def _mean(self):
return array_ops.identity(self.loc)
def _variance(self):
return array_ops.zeros_like(self.loc)
def _mode(self):
return self.mean()
def _sample_n(self, n, seed=None): # pylint: disable=unused-arg
n_static = tensor_util.constant_value(ops.convert_to_tensor(n))
if n_static is not None and self.loc.get_shape().ndims is not None:
ones = [1] * self.loc.get_shape().ndims
multiples = [n_static] + ones
else:
ones = array_ops.ones_like(array_ops.shape(self.loc))
multiples = array_ops.concat(([n], ones), axis=0)
return array_ops.tile(self.loc[array_ops.newaxis, ...], multiples=multiples)
class Deterministic(_BaseDeterministic):
"""Scalar `Deterministic` distribution on the real line.
The scalar `Deterministic` distribution is parameterized by a [batch] point
`loc` on the real line. The distribution is supported at this point only,
and corresponds to a random variable that is constant, equal to `loc`.
See [Degenerate rv](https://en.wikipedia.org/wiki/Degenerate_distribution).
#### Mathematical Details
The probability mass function (pmf) and cumulative distribution function (cdf)
are
```none
pmf(x; loc) = 1, if x == loc, else 0
cdf(x; loc) = 1, if x >= loc, else 0
```
#### Examples
```python
# Initialize a single Deterministic supported at zero.
constant = tf.contrib.distributions.Deterministic(0.)
constant.prob(0.)
==> 1.
constant.prob(2.)
==> 0.
# Initialize a [2, 2] batch of scalar constants.
loc = [[0., 1.], [2., 3.]]
x = [[0., 1.1], [1.99, 3.]]
constant = tf.contrib.distributions.Deterministic(loc)
constant.prob(x)
==> [[1., 0.], [0., 1.]]
```
"""
def __init__(self,
loc,
atol=None,
rtol=None,
validate_args=False,
allow_nan_stats=True,
name="Deterministic"):
"""Initialize a scalar `Deterministic` distribution.
The `atol` and `rtol` parameters allow for some slack in `pmf`, `cdf`
computations, e.g. due to floating-point error.
```
pmf(x; loc)
= 1, if Abs(x - loc) <= atol + rtol * Abs(loc),
= 0, otherwise.
```
Args:
loc: Numeric `Tensor` of shape `[B1, ..., Bb]`, with `b >= 0`.
The point (or batch of points) on which this distribution is supported.
atol: Non-negative `Tensor` of same `dtype` as `loc` and broadcastable
shape. The absolute tolerance for comparing closeness to `loc`.
Default is `0`.
rtol: Non-negative `Tensor` of same `dtype` as `loc` and broadcastable
shape. The relative tolerance for comparing closeness to `loc`.
Default is `0`.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
(e.g., mean, mode, variance) use the value "`NaN`" to indicate the
result is undefined. When `False`, an exception is raised if one or
more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.
"""
super(Deterministic, self).__init__(
loc,
atol=atol,
rtol=rtol,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
name=name)
def _batch_shape_tensor(self):
return array_ops.shape(self.loc)
def _batch_shape(self):
return self.loc.get_shape()
def _event_shape_tensor(self):
return constant_op.constant([], dtype=dtypes.int32)
def _event_shape(self):
return tensor_shape.scalar()
def _prob(self, x):
return math_ops.cast(
math_ops.abs(x - self.loc) <= self._slack, dtype=self.dtype)
def _cdf(self, x):
return math_ops.cast(x >= self.loc - self._slack, dtype=self.dtype)
class VectorDeterministic(_BaseDeterministic):
"""Vector `Deterministic` distribution on `R^k`.
The `VectorDeterministic` distribution is parameterized by a [batch] point
`loc in R^k`. The distribution is supported at this point only,
and corresponds to a random variable that is constant, equal to `loc`.
See [Degenerate rv](https://en.wikipedia.org/wiki/Degenerate_distribution).
#### Mathematical Details
The probability mass function (pmf) is
```none
pmf(x; loc)
= 1, if All[Abs(x - loc) <= atol + rtol * Abs(loc)],
= 0, otherwise.
```
#### Examples
```python
# Initialize a single VectorDeterministic supported at [0., 2.] in R^2.
constant = tf.contrib.distributions.Deterministic([0., 2.])
constant.prob([0., 2.])
==> 1.
constant.prob([0., 3.])
==> 0.
# Initialize a [3] batch of constants on R^2.
loc = [[0., 1.], [2., 3.], [4., 5.]]
constant = constant_lib.VectorDeterministic(loc)
constant.prob([[0., 1.], [1.9, 3.], [3.99, 5.]])
==> [1., 0., 0.]
```
"""
def __init__(self,
loc,
atol=None,
rtol=None,
validate_args=False,
allow_nan_stats=True,
name="VectorDeterministic"):
"""Initialize a `VectorDeterministic` distribution on `R^k`, for `k >= 0`.
Note that there is only one point in `R^0`, the "point" `[]`. So if `k = 0`
then `self.prob([]) == 1`.
The `atol` and `rtol` parameters allow for some slack in `pmf`
computations, e.g. due to floating-point error.
```
pmf(x; loc)
= 1, if All[Abs(x - loc) <= atol + rtol * Abs(loc)],
= 0, otherwise
```
Args:
loc: Numeric `Tensor` of shape `[B1, ..., Bb, k]`, with `b >= 0`, `k >= 0`
The point (or batch of points) on which this distribution is supported.
atol: Non-negative `Tensor` of same `dtype` as `loc` and broadcastable
shape. The absolute tolerance for comparing closeness to `loc`.
Default is `0`.
rtol: Non-negative `Tensor` of same `dtype` as `loc` and broadcastable
shape. The relative tolerance for comparing closeness to `loc`.
Default is `0`.
validate_args: Python `bool`, default `False`. When `True` distribution
parameters are checked for validity despite possibly degrading runtime
performance. When `False` invalid inputs may silently render incorrect
outputs.
allow_nan_stats: Python `bool`, default `True`. When `True`, statistics
(e.g., mean, mode, variance) use the value "`NaN`" to indicate the
result is undefined. When `False`, an exception is raised if one or
more of the statistic's batch members are undefined.
name: Python `str` name prefixed to Ops created by this class.
"""
super(VectorDeterministic, self).__init__(
loc,
atol=atol,
rtol=rtol,
is_vector=True,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
name=name)
def _batch_shape_tensor(self):
return array_ops.shape(self.loc)[:-1]
def _batch_shape(self):
return self.loc.get_shape()[:-1]
def _event_shape_tensor(self):
return array_ops.shape(self.loc)[-1]
def _event_shape(self):
return self.loc.get_shape()[-1:]
def _prob(self, x):
if self.validate_args:
is_vector_check = check_ops.assert_rank_at_least(x, 1)
right_vec_space_check = check_ops.assert_equal(
self.event_shape_tensor(),
array_ops.gather(array_ops.shape(x), array_ops.rank(x) - 1),
message=
"Argument 'x' not defined in the same space R^k as this distribution")
with ops.control_dependencies([is_vector_check]):
with ops.control_dependencies([right_vec_space_check]):
x = array_ops.identity(x)
return math_ops.cast(
math_ops.reduce_all(math_ops.abs(x - self.loc) <= self._slack, axis=-1),
dtype=self.dtype)
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1918,
1487,
2704,
6937,
4084,
1021,
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,
13022,
199,
199,
646,
3816,
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,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4084,
199,
199,
363,
452,
363,
275,
359,
272,
298,
28946,
401,
272,
298,
3646,
28946,
401,
199,
61,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
485,
1563,
28946,
8,
4972,
14,
8580,
304,
523,
408,
1563,
1021,
367,
1487,
2704,
6937,
10208,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
4355,
12,
2049,
9543,
29,
403,
12,
2049,
10561,
29,
403,
12,
2049,
365,
63,
4106,
29,
797,
12,
2049,
4107,
63,
589,
29,
797,
12,
2049,
2040,
63,
4304,
63,
3200,
29,
549,
12,
2049,
536,
19667,
1563,
28946,
2349,
272,
408,
9345,
282,
3522,
402,
18494,
1563,
28946,
64,
10208,
14,
339,
710,
658,
24504,
64,
436,
658,
23565,
64,
2633,
2040,
367,
2005,
29877,
315,
658,
31842,
3559,
658,
10790,
64,
272,
28319,
1298,
12,
325,
14,
71,
14,
7037,
370,
8402,
13,
1403,
1125,
14,
339,
10841,
272,
299,
11821,
8,
88,
27,
4355,
9,
489,
275,
413,
12,
340,
20319,
8,
88,
446,
4355,
9,
2695,
9543,
435,
10561,
627,
20319,
8,
2102,
395,
489,
275,
378,
12,
4257,
14,
272,
10841,
339,
3033,
26,
489,
4355,
26,
19378,
658,
3861,
2313,
221,
710,
2376,
334,
269,
3522,
402,
4501,
9,
641,
1314,
642,
267,
4084,
365,
3748,
14,
489,
9543,
26,
221,
10172,
13,
7371,
658,
3861,
64,
402,
2011,
658,
2271,
64,
465,
658,
2102,
64,
436,
11180,
461,
267,
2215,
14,
221,
710,
3679,
13464,
367,
20234,
4002,
4171,
370,
658,
2102,
2313,
267,
3758,
365,
658,
16,
2313,
489,
10561,
26,
221,
10172,
13,
7371,
658,
3861,
64,
402,
2011,
658,
2271,
64,
465,
658,
2102,
64,
436,
11180,
461,
267,
2215,
14,
221,
710,
3847,
13464,
367,
20234,
4002,
4171,
370,
658,
2102,
2313,
267,
3758,
365,
658,
16,
2313,
489,
365,
63,
4106,
26,
221,
2018,
658,
2245,
2313,
221,
982,
658,
549,
3559,
642,
365,
367,
658,
3646,
28946,
3559,
267,
587,
658,
28946,
2313,
489,
4107,
63,
589,
26,
2018,
658,
2245,
3559,
849,
658,
797,
2313,
3979,
658,
549,
64,
4084,
267,
2633,
787,
7923,
367,
25667,
477,
681,
1175,
12570,
477,
16050,
8836,
267,
10238,
14,
3979,
658,
797,
64,
3866,
4153,
1443,
18030,
3795,
8927,
267,
4704,
14,
489,
2040,
63,
4304,
63,
3200,
26,
2018,
658,
2245,
3559,
849,
658,
549,
2313,
3979,
658,
549,
3559,
11076,
267,
334,
69,
14,
71,
2020,
4615,
12,
818,
12,
11773,
9,
675,
314,
574,
24505,
14300,
64,
2,
370,
6623,
314,
267,
754,
365,
10942,
14,
3979,
658,
797,
3559,
376,
1919,
365,
4915,
340,
1373,
503,
267,
1655,
402,
314,
22394,
1159,
3522,
7556,
787,
10942,
14,
489,
536,
26,
2018,
658,
495,
64,
536,
18239,
370,
593,
1190,
2737,
701,
642,
1021,
14,
339,
6218,
26,
489,
1722,
26,
221,
982,
658,
2102,
64,
365,
282,
6917,
14,
272,
408,
272,
2633,
275,
9480,
342,
272,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
1338,
1524,
2102,
12,
9543,
12,
10561,
4682,
489,
4355,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
2102,
12,
536,
628,
2102,
531,
489,
340,
365,
63,
4106,
436,
4107,
63,
589,
26,
267,
1499,
275,
298,
5201,
4355,
1471,
506,
737,
5210,
6915,
413,
2122,
267,
340,
4355,
14,
362,
63,
1392,
1252,
13575,
365,
440,
488,
26,
881,
340,
4355,
14,
362,
63,
1392,
1252,
13575,
665,
413,
26,
288,
746,
1722,
8,
1328,
9,
267,
587,
26,
881,
4355,
275,
3304,
63,
1659,
63,
1483,
14,
1045,
63,
5714,
8,
1598,
359,
1074,
63,
1483,
14,
479,
63,
4648,
63,
292,
63,
11790,
8,
2102,
12,
413,
12,
1245,
29,
1328,
4360,
4355,
9,
489,
291,
423,
2102,
275,
4355,
2541,
1613,
1547,
1563,
28946,
12,
291,
2843,
826,
721,
881,
2152,
29,
277,
423,
2102,
14,
2271,
12,
881,
295,
8121,
6236,
13362,
63,
466,
29,
4972,
14,
4609,
63,
907,
14472,
18732,
12,
881,
4107,
63,
589,
29,
3502,
63,
589,
12,
881,
2040,
63,
4304,
63,
3200,
29,
3306,
63,
4304,
63,
3200,
12,
881,
2633,
29,
3214,
12,
881,
3343,
63,
8859,
1524,
277,
423,
2102,
467,
881,
536,
29,
354,
9,
2541,
291,
423,
24504,
275,
291,
423,
362,
63,
6896,
8,
24504,
9,
489,
291,
423,
23565,
275,
291,
423,
362,
63,
6896,
8,
23565,
9,
489,
327,
19503,
1808,
314,
7031,
11180,
543,
291
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1918,
1487,
2704,
6937,
4084,
1021,
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,
13022,
199,
199,
646,
3816,
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,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1392,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
4084,
199,
199,
363,
452,
363,
275,
359,
272,
298,
28946,
401,
272,
298,
3646,
28946,
401,
199,
61,
421,
199,
32,
4174,
14,
525,
63,
6577,
8,
3175,
14,
22254,
9,
199,
533,
485,
1563,
28946,
8,
4972,
14,
8580,
304,
523,
408,
1563,
1021,
367,
1487,
2704,
6937,
10208,
1041,
819,
347,
636,
826,
721,
277,
12,
2049,
4355,
12,
2049,
9543,
29,
403,
12,
2049,
10561,
29,
403,
12,
2049,
365,
63,
4106,
29,
797,
12,
2049,
4107,
63,
589,
29,
797,
12,
2049,
2040,
63,
4304,
63,
3200,
29,
549,
12,
2049,
536,
19667,
1563,
28946,
2349,
272,
408,
9345,
282,
3522,
402,
18494,
1563,
28946,
64,
10208,
14,
339,
710,
658,
24504,
64,
436,
658,
23565,
64,
2633,
2040,
367,
2005,
29877,
315,
658,
31842,
3559,
658,
10790,
64,
272,
28319,
1298,
12,
325,
14,
71,
14,
7037,
370,
8402,
13,
1403,
1125,
14,
339,
10841,
272,
299,
11821,
8,
88,
27,
4355,
9,
489,
275,
413,
12,
340,
20319,
8,
88,
446,
4355,
9,
2695,
9543,
435,
10561,
627,
20319,
8,
2102,
395,
489,
275,
378,
12,
4257,
14,
272,
10841,
339,
3033,
26,
489,
4355,
26,
19378,
658,
3861,
2313,
221,
710,
2376,
334,
269,
3522,
402,
4501,
9,
641,
1314,
642,
267,
4084,
365,
3748,
14,
489,
9543,
26,
221,
10172,
13,
7371,
658,
3861,
64,
402,
2011,
658,
2271,
64,
465,
658,
2102,
64,
436,
11180,
461,
267,
2215,
14,
221,
710,
3679,
13464,
367,
20234,
4002,
4171,
370,
658,
2102,
2313,
267,
3758,
365,
658,
16,
2313,
489,
10561,
26,
221,
10172,
13,
7371,
658,
3861,
64,
402,
2011,
658,
2271,
64,
465,
658,
2102,
64,
436,
11180,
461,
267,
2215,
14,
221,
710,
3847,
13464,
367,
20234,
4002,
4171,
370,
658,
2102,
2313,
267,
3758,
365,
658,
16,
2313,
489,
365,
63,
4106,
26,
221,
2018,
658,
2245,
2313,
221,
982,
658,
549,
3559,
642,
365,
367,
658,
3646,
28946,
3559,
267,
587,
658,
28946,
2313,
489,
4107,
63,
589,
26,
2018,
658,
2245,
3559,
849,
658,
797,
2313,
3979,
658,
549,
64,
4084,
267,
2633,
787,
7923,
367,
25667,
477,
681,
1175,
12570,
477,
16050,
8836,
267,
10238,
14,
3979,
658,
797,
64,
3866,
4153,
1443,
18030,
3795,
8927,
267,
4704,
14,
489,
2040,
63,
4304,
63,
3200,
26,
2018,
658,
2245,
3559,
849,
658,
549,
2313,
3979,
658,
549,
3559,
11076,
267,
334,
69,
14,
71,
2020,
4615,
12,
818,
12,
11773,
9,
675,
314,
574,
24505,
14300,
64,
2,
370,
6623,
314,
267,
754,
365,
10942,
14,
3979,
658,
797,
3559,
376,
1919,
365,
4915,
340,
1373,
503,
267,
1655,
402,
314,
22394,
1159,
3522,
7556,
787,
10942,
14,
489,
536,
26,
2018,
658,
495,
64,
536,
18239,
370,
593,
1190,
2737,
701,
642,
1021,
14,
339,
6218,
26,
489,
1722,
26,
221,
982,
658,
2102,
64,
365,
282,
6917,
14,
272,
408,
272,
2633,
275,
9480,
342,
272,
543,
4156,
14,
354,
63,
2645,
8,
354,
12,
1338,
1524,
2102,
12,
9543,
12,
10561,
4682,
489,
4355,
275,
4156,
14,
3916,
63,
475,
63,
3128,
8,
2102,
12,
536,
628,
2102,
531,
489,
340,
365,
63,
4106,
436,
4107,
63,
589,
26,
267,
1499,
275,
298,
5201,
4355,
1471,
506,
737,
5210,
6915,
413,
2122,
267,
340,
4355,
14,
362,
63,
1392,
1252,
13575,
365,
440,
488,
26,
881,
340,
4355,
14,
362,
63,
1392,
1252,
13575,
665,
413,
26,
288,
746,
1722,
8,
1328,
9,
267,
587,
26,
881,
4355,
275,
3304,
63,
1659,
63,
1483,
14,
1045,
63,
5714,
8,
1598,
359,
1074,
63,
1483,
14,
479,
63,
4648,
63,
292,
63,
11790,
8,
2102,
12,
413,
12,
1245,
29,
1328,
4360,
4355,
9,
489,
291,
423,
2102,
275,
4355,
2541,
1613,
1547,
1563,
28946,
12,
291,
2843,
826,
721,
881,
2152,
29,
277,
423,
2102,
14,
2271,
12,
881,
295,
8121,
6236,
13362,
63,
466,
29,
4972,
14,
4609,
63,
907,
14472,
18732,
12,
881,
4107,
63,
589,
29,
3502,
63,
589,
12,
881,
2040,
63,
4304,
63,
3200,
29,
3306,
63,
4304,
63,
3200,
12,
881,
2633,
29,
3214,
12,
881,
3343,
63,
8859,
1524,
277,
423,
2102,
467,
881,
536,
29,
354,
9,
2541,
291,
423,
24504,
275,
291,
423,
362,
63,
6896,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
greenonion/pytvd
|
tvdip.py
|
1
|
8146
|
"""
tvdip.py
~~~~~~~~
This module is a direct port of the original [1] tvdip Matlab script into
NumPy.
[1] M.A. Little, Nick S. Jones (2010) "Sparse Bayesian Step-Filtering for High-
Throughput Analysis of Molecular Machine Dynamics", in 2010 IEEE International
Conference on Acoustics, Speech and Signal Processing, 2010, ICASSP 2010
Proceedings.
"""
import numpy as np
import scipy as Sci
from scipy import sparse
from scipy.sparse import linalg
import sys
def tvdiplmax(y):
"""Calculate the value of lambda so that if lambda >= lambdamax, the TVD
functional solved by TVDIP is minimized by the trivial constant solution
x = mean(y). This can then be used to determine a useful range of values
of lambda, for example.
Args:
y: Original signal to denoise, size N x 1.
Returns:
lambdamax: Value of lambda at which x = mean(y) is the output of the
TVDIP function.
"""
N = y.size
M = N - 1
# Construct sparse operator matrices
I1 = sparse.eye(M)
O1 = sparse.dia_matrix((M, 1))
D = sparse.hstack([I1, O1]) - sparse.hstack([O1, I1])
DDT = D.dot(D.conj().T)
Dy = D.dot(y)
lambdamax = np.absolute(linalg.spsolve(DDT, Dy)).max(0)
return lambdamax
def tvdip(y, lambdas, display=1, stoptol=1e-3, maxiter=60):
"""Performs discrete total variation denoising (TVD) using a primal-dual
interior-point solver. It minimizes the following discrete functional:
E=(1/2)||y-x||_2^2+lambda*||Dx||_1
over the variable x, given the input signal y, according to each value of
the regularization parametero lambda > 0. D is the first difference matrix.
Uses hot-restarts from each value of lambda to speed up convergence for
subsequent values: best use of the feature is made by ensuring that the
chosen lambda values are close to each other.
Args:
y: Original signal to denoise, size N x 1.
lambdas: A vector of positive regularization parameters, size L x 1.
TVD will be applied to each value in the vector.
display: (Optional) Set to 0 to turn off progress display, 1 to turn
on. Defaults to 1.
stoptol: (Optional) Precision as determined by duality gap tolerance,
if not specified defaults to 1e-3.
maxiter: (Optional) Maximum interior-point iterations, if not specified
defaults to 60.
Returns:
x: Denoised output signal for each value of lambda, size N x L.
E: Objective functional at minimum for each lamvda, size L x 1.
s: Optimization result, 1 = solved, 0 = maximum iterations
exceeded before reaching duality gap tolerance, size L x 1.
lambdamax: Maximum value of lambda for the given y. If
lambda >= lambdamax, the output is the trivial constant solution
x = mean(y).
Example:
>>> import numpy as np
>>> import tvdip as tv
>>> # Find the value of lambda greater than which the TVD solution is
>>> # just the mean.
>>> lmax = tv.tvdiplmax(y)
>>> # Perform TV denoising for lambda across a range of values up to a
>>> # small fraction of the maximum found above.
>>> lratio = np.array([1e-4, 1e-3, 1e-2, 1e-1])
>>> x, E, status, l_max = tv.tvdip(y, lmax*lratio, True, 1e-3)
>>> plot(x[:,0])
"""
# Search tuning parameters
ALPHA = 0.01 # Backtracking linesearch parameter (0,0.5]
BETA = 0.5 # Backtracking linesearch parameter (0,1)
MAXLSITER = 20 # Max iterations of backtracking linesearch
MU = 2 # t update
N = y.size # Length of input signal y
M = N - 1 # Size of Dx
# Construct sparse operator matrices
I1 = sparse.eye(M)
O1 = sparse.dia_matrix((M, 1))
D = sparse.hstack([I1, O1]) - sparse.hstack([O1, I1])
DDT = D.dot(D.conj().T)
Dy = D.dot(y)
# Find max value of lambda
lambdamax = (np.absolute(linalg.spsolve(DDT, Dy))).max(0)
if display:
print "lambda_max=%5.2e" % lambdamax
L = lambdas.size
x = np.zeros((N, L))
s = np.zeros((L, 1))
E = np.zeros((L, 1))
# Optimization variables set up once at the start
z = np.zeros((M, 1))
mu1 = np.ones((M, 1))
mu2 = np.ones((M, 1))
# Work through each value of lambda, with hot-restart on optimization
# variables
for idx, l in enumerate(lambdas):
t = 1e-10
step = np.inf
f1 = z - l
f2 = -z - l
# Main optimization loop
s[idx] = 1
if display:
print "Solving for lambda={0:5.2e}, lambda/lambda_max={1:5.2e}".format(l, l/lambdamax)
print "Iter# primal Dual Gap"
for iters in xrange(maxiter):
DTz = (z.conj().T * D).conj().T
DDTz = D.dot(DTz)
w = Dy - (mu1 - mu2)
# Calculate objectives and primal-dual gap
pobj1 = 0.5*w.conj().T.dot(linalg.spsolve(DDT,w))+l*(np.sum(mu1+mu2))
pobj2 = 0.5*DTz.conj().T.dot(DTz)+l*np.sum(np.absolute(Dy-DDTz))
pobj = np.minimum(pobj1, pobj2)
dobj = -0.5*DTz.conj().T.dot(DTz) + Dy.conj().T.dot(z)
gap = pobj - dobj
if display:
print "{:5d} {:7.2e} {:7.2e} {:7.2e}".format(iters, pobj[0, 0],
dobj[0, 0],
gap[0, 0])
# Test duality gap stopping criterion
if gap <= stoptol:
s[idx] = 1
break
if step >= 0.2:
t = np.maximum(2*M*MU/gap, 1.2*t)
# Do Newton step
rz = DDTz - w
Sdata = (mu1/f1 + mu2/f2)
S = DDT-sparse.csc_matrix((Sdata.reshape(Sdata.size),
(np.arange(M), np.arange(M))))
r = -DDTz + Dy + (1/t)/f1 - (1/t)/f2
dz = linalg.spsolve(S, r).reshape(r.size, 1)
dmu1 = -(mu1+((1/t)+dz*mu1)/f1)
dmu2 = -(mu2+((1/t)-dz*mu2)/f2)
resDual = rz.copy()
resCent = np.vstack((-mu1*f1-1/t, -mu2*f2-1/t))
residual = np.vstack((resDual, resCent))
# Perform backtracking linesearch
negIdx1 = dmu1 < 0
negIdx2 = dmu2 < 0
step = 1
if np.any(negIdx1):
step = np.minimum(step,
0.99*(-mu1[negIdx1]/dmu1[negIdx1]).min(0))
if np.any(negIdx2):
step = np.minimum(step,
0.99*(-mu2[negIdx2]/dmu2[negIdx2]).min(0))
for _ in xrange(MAXLSITER):
newz = z + step*dz
newmu1 = mu1 + step*dmu1
newmu2 = mu2 + step*dmu2
newf1 = newz - l
newf2 = -newz - l
# Update residuals
newResDual = DDT.dot(newz) - Dy + newmu1 - newmu2
newResCent = np.vstack((-newmu1*newf1-1/t, -newmu2*newf2-1/t))
newResidual = np.vstack((newResDual, newResCent))
if (np.maximum(newf1.max(0), newf2.max(0)) < 0
and (Sci.linalg.norm(newResidual) <=
(1-ALPHA*step)*Sci.linalg.norm(residual))):
break
step = BETA * step
# Update primal and dual optimization parameters
z = newz
mu1 = newmu1
mu2 = newmu2
f1 = newf1
f2 = newf2
x[:, idx] = (y-D.conj().T.dot(z)).reshape(x.shape[0])
xval = x[:, idx].reshape(x.shape[0], 1)
E[idx] = 0.5*np.sum((y-xval)**2)+l*np.sum(np.absolute(D.dot(xval)))
# We may have a close solution that does not satisfy the duality gap
if iters >= maxiter:
s[idx] = 0
if display:
if s[idx]:
print("Solved to precision of duality gap %5.2e") % gap
else:
print("Max iterations exceeded - solution may be inaccurate")
return x, E, s, lambdamax
|
gpl-2.0
|
[
624,
199,
6993,
21846,
14,
647,
199,
4919,
199,
199,
2765,
859,
365,
282,
4125,
1844,
402,
314,
3379,
359,
17,
61,
13466,
21846,
18619,
5561,
2884,
1901,
199,
5667,
2713,
14,
199,
199,
59,
17,
61,
603,
14,
33,
14,
491,
390,
1118,
12,
653,
2000,
428,
14,
1603,
4548,
334,
6542,
9,
298,
8629,
29434,
69,
6214,
13382,
13,
4131,
316,
367,
16332,
13,
199,
26732,
524,
21916,
402,
3930,
10251,
2238,
18722,
577,
4019,
2932,
401,
315,
7129,
473,
29146,
28220,
199,
714,
1769,
641,
437,
331,
833,
2932,
12,
428,
321,
12736,
436,
18288,
20157,
12,
7129,
12,
473,
35,
3755,
48,
7129,
199,
919,
15648,
780,
14,
199,
624,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
465,
16578,
199,
504,
7026,
492,
5178,
199,
504,
7026,
14,
4421,
492,
16727,
199,
646,
984,
421,
199,
318,
13466,
328,
1168,
988,
8,
89,
304,
272,
408,
14860,
314,
574,
402,
2400,
880,
626,
340,
2400,
2356,
2400,
988,
12,
314,
377,
26197,
272,
22380,
308,
7064,
701,
377,
26197,
1772,
365,
18790,
1759,
701,
314,
28586,
4413,
8744,
272,
671,
275,
4615,
8,
89,
680,
961,
883,
2066,
506,
1202,
370,
6705,
282,
2997,
1425,
402,
1338,
272,
402,
2400,
12,
367,
2893,
14,
339,
3033,
26,
267,
612,
26,
12769,
4673,
370,
477,
11838,
12,
1568,
653,
671,
413,
14,
339,
1803,
26,
267,
2400,
988,
26,
1594,
402,
2400,
737,
1314,
671,
275,
4615,
8,
89,
9,
365,
314,
1072,
402,
314,
288,
377,
26197,
1772,
805,
14,
339,
408,
339,
653,
275,
612,
14,
890,
272,
603,
275,
653,
446,
413,
339,
327,
9215,
5178,
4182,
12627,
272,
473,
17,
275,
5178,
14,
15240,
8,
45,
9,
272,
593,
17,
275,
5178,
14,
2391,
63,
3642,
1332,
45,
12,
413,
430,
272,
577,
275,
5178,
14,
20949,
779,
41,
17,
12,
593,
17,
566,
446,
5178,
14,
20949,
779,
47,
17,
12,
473,
17,
566,
339,
577,
7438,
275,
577,
14,
3287,
8,
36,
14,
14765,
1252,
52,
9,
272,
577,
89,
275,
577,
14,
3287,
8,
89,
9,
339,
2400,
988,
275,
980,
14,
6116,
8,
10096,
14,
681,
11356,
8,
5745,
52,
12,
577,
89,
4992,
988,
8,
16,
9,
339,
372,
2400,
988,
421,
199,
318,
13466,
21846,
8,
89,
12,
27593,
24315,
12,
2929,
29,
17,
12,
410,
2992,
393,
29,
17,
69,
13,
19,
12,
27150,
29,
2259,
304,
272,
408,
2623,
3351,
24635,
3141,
29844,
477,
889,
11136,
334,
12764,
36,
9,
1808,
282,
1979,
2174,
13,
17962,
272,
4661,
17942,
13,
1403,
10196,
14,
2779,
18790,
6491,
314,
2569,
24635,
22380,
26,
339,
662,
2687,
17,
15,
18,
8636,
92,
89,
13,
88,
10644,
63,
18,
62,
18,
11,
2734,
10,
10644,
36,
88,
10644,
63,
17,
339,
1806,
314,
1750,
671,
12,
1627,
314,
1324,
4673,
612,
12,
7182,
370,
1924,
574,
402,
272,
314,
21095,
18117,
24208,
2400,
690,
378,
14,
577,
365,
314,
1642,
8865,
3634,
14,
272,
14911,
18469,
13,
10506,
83,
687,
1924,
574,
402,
2400,
370,
8112,
1536,
21346,
367,
272,
13372,
1338,
26,
5526,
675,
402,
314,
3878,
365,
6326,
701,
12889,
4039,
626,
314,
272,
12414,
2400,
1338,
787,
4002,
370,
1924,
1163,
14,
339,
3033,
26,
267,
612,
26,
12769,
4673,
370,
477,
11838,
12,
1568,
653,
671,
413,
14,
267,
27593,
24315,
26,
437,
5477,
402,
7317,
21095,
2633,
12,
1568,
491,
671,
413,
14,
288,
377,
26197,
911,
506,
6781,
370,
1924,
574,
315,
314,
5477,
14,
267,
2929,
26,
334,
7012,
9,
2494,
370,
378,
370,
7485,
2331,
6696,
2929,
12,
413,
370,
7485,
288,
641,
14,
7827,
370,
413,
14,
267,
410,
2992,
393,
26,
334,
7012,
9,
5543,
3688,
465,
12037,
701,
21164,
1209,
16301,
13464,
12,
288,
340,
440,
2013,
4243,
370,
413,
69,
13,
19,
14,
267,
27150,
26,
334,
7012,
9,
14212,
4661,
17942,
13,
1403,
10615,
12,
340,
440,
2013,
288,
4243,
370,
5212,
14,
339,
1803,
26,
267,
671,
26,
25187,
79,
9096,
1072,
4673,
367,
1924,
574,
402,
2400,
12,
1568,
653,
671,
491,
14,
267,
662,
26,
24921,
6850,
22380,
737,
7481,
367,
1924,
1127,
12393,
983,
12,
1568,
491,
671,
413,
14,
267,
308,
26,
19246,
2072,
754,
12,
413,
275,
308,
7064,
12,
378,
275,
5696,
10615,
288,
22007,
2544,
12276,
316,
21164,
1209,
16301,
13464,
12,
1568,
491,
671,
413,
14,
267,
2400,
988,
26,
14212,
574,
402,
2400,
367,
314,
1627,
612,
14,
982,
288,
2400,
2356,
2400,
988,
12,
314,
1072,
365,
314,
28586,
4413,
8744,
288,
671,
275,
4615,
8,
89,
680,
339,
5679,
26,
267,
1306,
492,
2680,
465,
980,
267,
1306,
492,
13466,
21846,
465,
13466,
267,
1306,
327,
6668,
314,
574,
402,
2400,
8932,
2419,
1314,
314,
377,
26197,
8744,
365,
267,
1306,
327,
2951,
314,
4615,
14,
267,
1306,
634,
988,
275,
13466,
14,
6993,
328,
1168,
988,
8,
89,
9,
267,
1306,
327,
14795,
26990,
477,
889,
11136,
367,
2400,
9371,
282,
1425,
402,
1338,
1536,
370,
282,
267,
1306,
327,
7425,
12347,
402,
314,
5696,
1911,
3432,
14,
267,
1306,
634,
6884,
275,
980,
14,
1144,
779,
17,
69,
13,
20,
12,
413,
69,
13,
19,
12,
413,
69,
13,
18,
12,
413,
69,
13,
17,
566,
267,
1306,
671,
12,
662,
12,
2004,
12,
634,
63,
988,
275,
13466,
14,
6993,
21846,
8,
89,
12,
634,
988,
10,
76,
6884,
12,
715,
12,
413,
69,
13,
19,
9,
267,
1306,
5137,
8,
88,
3981,
16,
566,
272,
408,
339,
327,
8730,
15486,
316,
2633,
272,
31278,
275,
378,
14,
614,
259,
327,
10257,
14428,
1004,
1733,
2725,
334,
16,
12,
16,
14,
21,
61,
272,
699,
15808,
275,
378,
14,
21,
420,
327,
10257,
14428,
1004,
1733,
2725,
334,
16,
12,
17,
9,
272,
9141,
5296,
11084,
275,
3388,
221,
327,
8228,
10615,
402,
1771,
14428,
1004,
1733,
272,
603,
53,
275,
499,
3515,
327,
307,
1678,
339,
653,
275,
612,
14,
890,
221,
327,
19893,
402,
1324,
4673,
612,
272,
603,
275,
653,
446,
413,
257,
327,
14579,
402,
577,
88,
339,
327,
9215,
5178,
4182,
12627,
272,
473,
17,
275,
5178,
14
] |
[
199,
6993,
21846,
14,
647,
199,
4919,
199,
199,
2765,
859,
365,
282,
4125,
1844,
402,
314,
3379,
359,
17,
61,
13466,
21846,
18619,
5561,
2884,
1901,
199,
5667,
2713,
14,
199,
199,
59,
17,
61,
603,
14,
33,
14,
491,
390,
1118,
12,
653,
2000,
428,
14,
1603,
4548,
334,
6542,
9,
298,
8629,
29434,
69,
6214,
13382,
13,
4131,
316,
367,
16332,
13,
199,
26732,
524,
21916,
402,
3930,
10251,
2238,
18722,
577,
4019,
2932,
401,
315,
7129,
473,
29146,
28220,
199,
714,
1769,
641,
437,
331,
833,
2932,
12,
428,
321,
12736,
436,
18288,
20157,
12,
7129,
12,
473,
35,
3755,
48,
7129,
199,
919,
15648,
780,
14,
199,
624,
199,
199,
646,
2680,
465,
980,
199,
646,
7026,
465,
16578,
199,
504,
7026,
492,
5178,
199,
504,
7026,
14,
4421,
492,
16727,
199,
646,
984,
421,
199,
318,
13466,
328,
1168,
988,
8,
89,
304,
272,
408,
14860,
314,
574,
402,
2400,
880,
626,
340,
2400,
2356,
2400,
988,
12,
314,
377,
26197,
272,
22380,
308,
7064,
701,
377,
26197,
1772,
365,
18790,
1759,
701,
314,
28586,
4413,
8744,
272,
671,
275,
4615,
8,
89,
680,
961,
883,
2066,
506,
1202,
370,
6705,
282,
2997,
1425,
402,
1338,
272,
402,
2400,
12,
367,
2893,
14,
339,
3033,
26,
267,
612,
26,
12769,
4673,
370,
477,
11838,
12,
1568,
653,
671,
413,
14,
339,
1803,
26,
267,
2400,
988,
26,
1594,
402,
2400,
737,
1314,
671,
275,
4615,
8,
89,
9,
365,
314,
1072,
402,
314,
288,
377,
26197,
1772,
805,
14,
339,
408,
339,
653,
275,
612,
14,
890,
272,
603,
275,
653,
446,
413,
339,
327,
9215,
5178,
4182,
12627,
272,
473,
17,
275,
5178,
14,
15240,
8,
45,
9,
272,
593,
17,
275,
5178,
14,
2391,
63,
3642,
1332,
45,
12,
413,
430,
272,
577,
275,
5178,
14,
20949,
779,
41,
17,
12,
593,
17,
566,
446,
5178,
14,
20949,
779,
47,
17,
12,
473,
17,
566,
339,
577,
7438,
275,
577,
14,
3287,
8,
36,
14,
14765,
1252,
52,
9,
272,
577,
89,
275,
577,
14,
3287,
8,
89,
9,
339,
2400,
988,
275,
980,
14,
6116,
8,
10096,
14,
681,
11356,
8,
5745,
52,
12,
577,
89,
4992,
988,
8,
16,
9,
339,
372,
2400,
988,
421,
199,
318,
13466,
21846,
8,
89,
12,
27593,
24315,
12,
2929,
29,
17,
12,
410,
2992,
393,
29,
17,
69,
13,
19,
12,
27150,
29,
2259,
304,
272,
408,
2623,
3351,
24635,
3141,
29844,
477,
889,
11136,
334,
12764,
36,
9,
1808,
282,
1979,
2174,
13,
17962,
272,
4661,
17942,
13,
1403,
10196,
14,
2779,
18790,
6491,
314,
2569,
24635,
22380,
26,
339,
662,
2687,
17,
15,
18,
8636,
92,
89,
13,
88,
10644,
63,
18,
62,
18,
11,
2734,
10,
10644,
36,
88,
10644,
63,
17,
339,
1806,
314,
1750,
671,
12,
1627,
314,
1324,
4673,
612,
12,
7182,
370,
1924,
574,
402,
272,
314,
21095,
18117,
24208,
2400,
690,
378,
14,
577,
365,
314,
1642,
8865,
3634,
14,
272,
14911,
18469,
13,
10506,
83,
687,
1924,
574,
402,
2400,
370,
8112,
1536,
21346,
367,
272,
13372,
1338,
26,
5526,
675,
402,
314,
3878,
365,
6326,
701,
12889,
4039,
626,
314,
272,
12414,
2400,
1338,
787,
4002,
370,
1924,
1163,
14,
339,
3033,
26,
267,
612,
26,
12769,
4673,
370,
477,
11838,
12,
1568,
653,
671,
413,
14,
267,
27593,
24315,
26,
437,
5477,
402,
7317,
21095,
2633,
12,
1568,
491,
671,
413,
14,
288,
377,
26197,
911,
506,
6781,
370,
1924,
574,
315,
314,
5477,
14,
267,
2929,
26,
334,
7012,
9,
2494,
370,
378,
370,
7485,
2331,
6696,
2929,
12,
413,
370,
7485,
288,
641,
14,
7827,
370,
413,
14,
267,
410,
2992,
393,
26,
334,
7012,
9,
5543,
3688,
465,
12037,
701,
21164,
1209,
16301,
13464,
12,
288,
340,
440,
2013,
4243,
370,
413,
69,
13,
19,
14,
267,
27150,
26,
334,
7012,
9,
14212,
4661,
17942,
13,
1403,
10615,
12,
340,
440,
2013,
288,
4243,
370,
5212,
14,
339,
1803,
26,
267,
671,
26,
25187,
79,
9096,
1072,
4673,
367,
1924,
574,
402,
2400,
12,
1568,
653,
671,
491,
14,
267,
662,
26,
24921,
6850,
22380,
737,
7481,
367,
1924,
1127,
12393,
983,
12,
1568,
491,
671,
413,
14,
267,
308,
26,
19246,
2072,
754,
12,
413,
275,
308,
7064,
12,
378,
275,
5696,
10615,
288,
22007,
2544,
12276,
316,
21164,
1209,
16301,
13464,
12,
1568,
491,
671,
413,
14,
267,
2400,
988,
26,
14212,
574,
402,
2400,
367,
314,
1627,
612,
14,
982,
288,
2400,
2356,
2400,
988,
12,
314,
1072,
365,
314,
28586,
4413,
8744,
288,
671,
275,
4615,
8,
89,
680,
339,
5679,
26,
267,
1306,
492,
2680,
465,
980,
267,
1306,
492,
13466,
21846,
465,
13466,
267,
1306,
327,
6668,
314,
574,
402,
2400,
8932,
2419,
1314,
314,
377,
26197,
8744,
365,
267,
1306,
327,
2951,
314,
4615,
14,
267,
1306,
634,
988,
275,
13466,
14,
6993,
328,
1168,
988,
8,
89,
9,
267,
1306,
327,
14795,
26990,
477,
889,
11136,
367,
2400,
9371,
282,
1425,
402,
1338,
1536,
370,
282,
267,
1306,
327,
7425,
12347,
402,
314,
5696,
1911,
3432,
14,
267,
1306,
634,
6884,
275,
980,
14,
1144,
779,
17,
69,
13,
20,
12,
413,
69,
13,
19,
12,
413,
69,
13,
18,
12,
413,
69,
13,
17,
566,
267,
1306,
671,
12,
662,
12,
2004,
12,
634,
63,
988,
275,
13466,
14,
6993,
21846,
8,
89,
12,
634,
988,
10,
76,
6884,
12,
715,
12,
413,
69,
13,
19,
9,
267,
1306,
5137,
8,
88,
3981,
16,
566,
272,
408,
339,
327,
8730,
15486,
316,
2633,
272,
31278,
275,
378,
14,
614,
259,
327,
10257,
14428,
1004,
1733,
2725,
334,
16,
12,
16,
14,
21,
61,
272,
699,
15808,
275,
378,
14,
21,
420,
327,
10257,
14428,
1004,
1733,
2725,
334,
16,
12,
17,
9,
272,
9141,
5296,
11084,
275,
3388,
221,
327,
8228,
10615,
402,
1771,
14428,
1004,
1733,
272,
603,
53,
275,
499,
3515,
327,
307,
1678,
339,
653,
275,
612,
14,
890,
221,
327,
19893,
402,
1324,
4673,
612,
272,
603,
275,
653,
446,
413,
257,
327,
14579,
402,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
adrienbrault/home-assistant
|
tests/components/canary/test_sensor.py
|
8
|
7215
|
"""The tests for the Canary sensor platform."""
from datetime import timedelta
from unittest.mock import patch
from homeassistant.components.canary.const import DOMAIN, MANUFACTURER
from homeassistant.components.canary.sensor import (
ATTR_AIR_QUALITY,
STATE_AIR_QUALITY_ABNORMAL,
STATE_AIR_QUALITY_NORMAL,
STATE_AIR_QUALITY_VERY_ABNORMAL,
)
from homeassistant.const import (
ATTR_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_TEMPERATURE,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS,
)
from homeassistant.setup import async_setup_component
from homeassistant.util.dt import utcnow
from . import mock_device, mock_location, mock_reading
from tests.common import async_fire_time_changed, mock_device_registry, mock_registry
async def test_sensors_pro(hass, canary) -> None:
"""Test the creation and values of the sensors for Canary Pro."""
await async_setup_component(hass, "persistent_notification", {})
registry = mock_registry(hass)
device_registry = mock_device_registry(hass)
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Pro")
instance = canary.return_value
instance.get_locations.return_value = [
mock_location(100, "Home", True, devices=[online_device_at_home]),
]
instance.get_latest_readings.return_value = [
mock_reading("temperature", "21.12"),
mock_reading("humidity", "50.46"),
mock_reading("air_quality", "0.59"),
]
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
with patch("homeassistant.components.canary.PLATFORMS", ["sensor"]):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
sensors = {
"home_dining_room_temperature": (
"20_temperature",
"21.12",
TEMP_CELSIUS,
DEVICE_CLASS_TEMPERATURE,
None,
),
"home_dining_room_humidity": (
"20_humidity",
"50.46",
PERCENTAGE,
DEVICE_CLASS_HUMIDITY,
None,
),
"home_dining_room_air_quality": (
"20_air_quality",
"0.59",
None,
None,
"mdi:weather-windy",
),
}
for (sensor_id, data) in sensors.items():
entity_entry = registry.async_get(f"sensor.{sensor_id}")
assert entity_entry
assert entity_entry.device_class == data[3]
assert entity_entry.unique_id == data[0]
assert entity_entry.original_icon == data[4]
state = hass.states.get(f"sensor.{sensor_id}")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
assert state.state == data[1]
device = device_registry.async_get_device({(DOMAIN, "20")})
assert device
assert device.manufacturer == MANUFACTURER
assert device.name == "Dining Room"
assert device.model == "Canary Pro"
async def test_sensors_attributes_pro(hass, canary) -> None:
"""Test the creation and values of the sensors attributes for Canary Pro."""
await async_setup_component(hass, "persistent_notification", {})
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Pro")
instance = canary.return_value
instance.get_locations.return_value = [
mock_location(100, "Home", True, devices=[online_device_at_home]),
]
instance.get_latest_readings.return_value = [
mock_reading("temperature", "21.12"),
mock_reading("humidity", "50.46"),
mock_reading("air_quality", "0.59"),
]
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
with patch("homeassistant.components.canary.PLATFORMS", ["sensor"]):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
entity_id = "sensor.home_dining_room_air_quality"
state = hass.states.get(entity_id)
assert state
assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_ABNORMAL
instance.get_latest_readings.return_value = [
mock_reading("temperature", "21.12"),
mock_reading("humidity", "50.46"),
mock_reading("air_quality", "0.4"),
]
future = utcnow() + timedelta(seconds=30)
async_fire_time_changed(hass, future)
await hass.helpers.entity_component.async_update_entity(entity_id)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state
assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_VERY_ABNORMAL
instance.get_latest_readings.return_value = [
mock_reading("temperature", "21.12"),
mock_reading("humidity", "50.46"),
mock_reading("air_quality", "1.0"),
]
future += timedelta(seconds=30)
async_fire_time_changed(hass, future)
await hass.helpers.entity_component.async_update_entity(entity_id)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state
assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_NORMAL
async def test_sensors_flex(hass, canary) -> None:
"""Test the creation and values of the sensors for Canary Flex."""
await async_setup_component(hass, "persistent_notification", {})
registry = mock_registry(hass)
device_registry = mock_device_registry(hass)
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Flex")
instance = canary.return_value
instance.get_locations.return_value = [
mock_location(100, "Home", True, devices=[online_device_at_home]),
]
instance.get_latest_readings.return_value = [
mock_reading("battery", "70.4567"),
mock_reading("wifi", "-57"),
]
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
with patch("homeassistant.components.canary.PLATFORMS", ["sensor"]):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
sensors = {
"home_dining_room_battery": (
"20_battery",
"70.46",
PERCENTAGE,
DEVICE_CLASS_BATTERY,
None,
),
"home_dining_room_wifi": (
"20_wifi",
"-57.0",
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
DEVICE_CLASS_SIGNAL_STRENGTH,
None,
),
}
for (sensor_id, data) in sensors.items():
entity_entry = registry.async_get(f"sensor.{sensor_id}")
assert entity_entry
assert entity_entry.device_class == data[3]
assert entity_entry.unique_id == data[0]
assert entity_entry.original_icon == data[4]
state = hass.states.get(f"sensor.{sensor_id}")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
assert state.state == data[1]
device = device_registry.async_get_device({(DOMAIN, "20")})
assert device
assert device.manufacturer == MANUFACTURER
assert device.name == "Dining Room"
assert device.model == "Canary Flex"
|
mit
|
[
624,
1918,
2295,
367,
314,
6855,
695,
8778,
4298,
1041,
199,
504,
2197,
492,
6871,
199,
504,
2882,
14,
1805,
492,
3371,
199,
199,
504,
8846,
14,
4608,
14,
2425,
695,
14,
1297,
492,
15265,
12,
26688,
53,
18164,
1230,
540,
199,
504,
8846,
14,
4608,
14,
2425,
695,
14,
8956,
492,
334,
272,
10762,
63,
33,
3927,
63,
9283,
1922,
12,
272,
11377,
63,
33,
3927,
63,
9283,
1922,
63,
1217,
10765,
12,
272,
11377,
63,
33,
3927,
63,
9283,
1922,
63,
10765,
12,
272,
11377,
63,
33,
3927,
63,
9283,
1922,
63,
2111,
57,
63,
1217,
10765,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
272,
11643,
63,
6885,
63,
28839,
1157,
57,
12,
272,
11643,
63,
6885,
63,
40,
2639,
998,
1922,
12,
272,
11643,
63,
6885,
63,
16496,
63,
3027,
32106,
12,
272,
11643,
63,
6885,
63,
12510,
32559,
12,
272,
26684,
2962,
12,
272,
24360,
63,
3027,
32106,
63,
16387,
2100,
2901,
51,
63,
45,
1193,
2673,
55,
11712,
12,
272,
24314,
63,
21595,
2684,
1668,
12,
199,
9,
199,
504,
8846,
14,
2758,
492,
5316,
63,
2758,
63,
3173,
199,
504,
8846,
14,
1974,
14,
3583,
492,
221,
10779,
199,
199,
504,
1275,
492,
1683,
63,
1782,
12,
1683,
63,
1985,
12,
1683,
63,
19332,
199,
199,
504,
2295,
14,
2330,
492,
5316,
63,
8935,
63,
521,
63,
2489,
12,
1683,
63,
1782,
63,
5189,
12,
1683,
63,
5189,
421,
199,
4146,
347,
511,
63,
22675,
63,
496,
8,
5387,
12,
883,
695,
9,
1035,
488,
26,
272,
408,
774,
314,
7143,
436,
1338,
402,
314,
19678,
367,
6855,
695,
2165,
1041,
272,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
18539,
63,
6761,
401,
5009,
339,
7086,
275,
1683,
63,
5189,
8,
5387,
9,
272,
2243,
63,
5189,
275,
1683,
63,
1782,
63,
5189,
8,
5387,
9,
339,
18470,
63,
1782,
63,
292,
63,
4219,
275,
1683,
63,
1782,
8,
1165,
12,
298,
36,
7969,
6848,
676,
401,
715,
12,
298,
6049,
695,
2165,
531,
339,
1256,
275,
883,
695,
14,
1107,
63,
585,
272,
1256,
14,
362,
63,
8022,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
1985,
8,
1960,
12,
298,
12054,
401,
715,
12,
7256,
1524,
15178,
63,
1782,
63,
292,
63,
4219,
2522,
272,
1622,
339,
1256,
14,
362,
63,
7410,
63,
739,
780,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
19332,
480,
12954,
401,
298,
2025,
14,
713,
1288,
267,
1683,
63,
19332,
480,
31812,
401,
298,
1400,
14,
2466,
1288,
267,
1683,
63,
19332,
480,
8387,
63,
9161,
401,
298,
16,
14,
1427,
1288,
272,
1622,
339,
1101,
275,
469,
7378,
26,
2420,
2473,
582,
298,
396,
13,
2473,
401,
298,
2060,
582,
298,
396,
13,
2060,
32655,
272,
543,
3371,
480,
22799,
14,
4608,
14,
2425,
695,
14,
2749,
619,
11518,
401,
2097,
8956,
21473,
267,
702,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
15265,
12,
1101,
9,
267,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
19678,
275,
469,
267,
298,
4219,
63,
68,
7969,
63,
11245,
63,
12954,
582,
334,
288,
298,
1165,
63,
12954,
401,
288,
298,
2025,
14,
713,
401,
288,
24314,
63,
21595,
2684,
1668,
12,
288,
11643,
63,
6885,
63,
12510,
32559,
12,
288,
488,
12,
267,
2318,
267,
298,
4219,
63,
68,
7969,
63,
11245,
63,
31812,
582,
334,
288,
298,
1165,
63,
31812,
401,
288,
298,
1400,
14,
2466,
401,
288,
26684,
2962,
12,
288,
11643,
63,
6885,
63,
40,
2639,
998,
1922,
12,
288,
488,
12,
267,
2318,
267,
298,
4219,
63,
68,
7969,
63,
11245,
63,
8387,
63,
9161,
582,
334,
288,
298,
1165,
63,
8387,
63,
9161,
401,
288,
298,
16,
14,
1427,
401,
288,
488,
12,
288,
488,
12,
288,
298,
20208,
26,
23026,
13,
11530,
89,
401,
267,
2318,
272,
789,
339,
367,
334,
8956,
63,
344,
12,
666,
9,
315,
19678,
14,
1744,
837,
267,
4642,
63,
2373,
275,
7086,
14,
4146,
63,
362,
8,
70,
2,
8956,
23379,
8956,
63,
344,
15412,
267,
702,
4642,
63,
2373,
267,
702,
4642,
63,
2373,
14,
1782,
63,
533,
508,
666,
59,
19,
61,
267,
702,
4642,
63,
2373,
14,
3235,
63,
344,
508,
666,
59,
16,
61,
267,
702,
4642,
63,
2373,
14,
5043,
63,
4677,
508,
666,
59,
20,
61,
398,
1174,
275,
6298,
14,
4981,
14,
362,
8,
70,
2,
8956,
23379,
8956,
63,
344,
15412,
267,
702,
1174,
267,
702,
1174,
14,
2987,
14,
362,
8,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
9,
508,
666,
59,
18,
61,
267,
702,
1174,
14,
929,
508,
666,
59,
17,
61,
339,
2243,
275,
2243,
63,
5189,
14,
4146,
63,
362,
63,
1782,
2561,
8,
7378,
12,
298,
1165,
531,
1552,
272,
702,
2243,
272,
702,
2243,
14,
32214,
508,
26688,
53,
18164,
1230,
540,
272,
702,
2243,
14,
354,
508,
298,
36,
7969,
6848,
676,
2,
272,
702,
2243,
14,
1238,
508,
298,
6049,
695,
2165,
2,
421,
199,
4146,
347,
511,
63,
22675,
63,
2987,
63,
496,
8,
5387,
12,
883,
695,
9,
1035,
488,
26,
272,
408,
774,
314,
7143,
436,
1338,
402,
314,
19678,
3004,
367,
6855,
695,
2165,
1041,
272,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
18539,
63,
6761,
401,
5009,
339,
18470,
63,
1782,
63,
292,
63,
4219,
275,
1683,
63,
1782,
8,
1165,
12,
298,
36,
7969,
6848,
676,
401,
715,
12,
298,
6049,
695,
2165,
531,
339,
1256,
275,
883,
695,
14,
1107,
63,
585,
272,
1256,
14,
362,
63,
8022,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
1985,
8,
1960,
12,
298,
12054,
401,
715,
12,
7256,
1524,
15178,
63,
1782,
63,
292,
63,
4219,
2522,
272,
1622,
339,
1256,
14,
362,
63,
7410,
63,
739,
780,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
19332,
480,
12954,
401,
298,
2025,
14,
713,
1288,
267,
1683,
63,
19332,
480,
31812,
401,
298,
1400,
14,
2466,
1288,
267,
1683,
63,
19332,
480,
8387,
63,
9161,
401,
298,
16,
14,
1427,
1288,
272,
1622,
339,
1101
] |
[
1918,
2295,
367,
314,
6855,
695,
8778,
4298,
1041,
199,
504,
2197,
492,
6871,
199,
504,
2882,
14,
1805,
492,
3371,
199,
199,
504,
8846,
14,
4608,
14,
2425,
695,
14,
1297,
492,
15265,
12,
26688,
53,
18164,
1230,
540,
199,
504,
8846,
14,
4608,
14,
2425,
695,
14,
8956,
492,
334,
272,
10762,
63,
33,
3927,
63,
9283,
1922,
12,
272,
11377,
63,
33,
3927,
63,
9283,
1922,
63,
1217,
10765,
12,
272,
11377,
63,
33,
3927,
63,
9283,
1922,
63,
10765,
12,
272,
11377,
63,
33,
3927,
63,
9283,
1922,
63,
2111,
57,
63,
1217,
10765,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
334,
272,
10762,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
272,
11643,
63,
6885,
63,
28839,
1157,
57,
12,
272,
11643,
63,
6885,
63,
40,
2639,
998,
1922,
12,
272,
11643,
63,
6885,
63,
16496,
63,
3027,
32106,
12,
272,
11643,
63,
6885,
63,
12510,
32559,
12,
272,
26684,
2962,
12,
272,
24360,
63,
3027,
32106,
63,
16387,
2100,
2901,
51,
63,
45,
1193,
2673,
55,
11712,
12,
272,
24314,
63,
21595,
2684,
1668,
12,
199,
9,
199,
504,
8846,
14,
2758,
492,
5316,
63,
2758,
63,
3173,
199,
504,
8846,
14,
1974,
14,
3583,
492,
221,
10779,
199,
199,
504,
1275,
492,
1683,
63,
1782,
12,
1683,
63,
1985,
12,
1683,
63,
19332,
199,
199,
504,
2295,
14,
2330,
492,
5316,
63,
8935,
63,
521,
63,
2489,
12,
1683,
63,
1782,
63,
5189,
12,
1683,
63,
5189,
421,
199,
4146,
347,
511,
63,
22675,
63,
496,
8,
5387,
12,
883,
695,
9,
1035,
488,
26,
272,
408,
774,
314,
7143,
436,
1338,
402,
314,
19678,
367,
6855,
695,
2165,
1041,
272,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
18539,
63,
6761,
401,
5009,
339,
7086,
275,
1683,
63,
5189,
8,
5387,
9,
272,
2243,
63,
5189,
275,
1683,
63,
1782,
63,
5189,
8,
5387,
9,
339,
18470,
63,
1782,
63,
292,
63,
4219,
275,
1683,
63,
1782,
8,
1165,
12,
298,
36,
7969,
6848,
676,
401,
715,
12,
298,
6049,
695,
2165,
531,
339,
1256,
275,
883,
695,
14,
1107,
63,
585,
272,
1256,
14,
362,
63,
8022,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
1985,
8,
1960,
12,
298,
12054,
401,
715,
12,
7256,
1524,
15178,
63,
1782,
63,
292,
63,
4219,
2522,
272,
1622,
339,
1256,
14,
362,
63,
7410,
63,
739,
780,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
19332,
480,
12954,
401,
298,
2025,
14,
713,
1288,
267,
1683,
63,
19332,
480,
31812,
401,
298,
1400,
14,
2466,
1288,
267,
1683,
63,
19332,
480,
8387,
63,
9161,
401,
298,
16,
14,
1427,
1288,
272,
1622,
339,
1101,
275,
469,
7378,
26,
2420,
2473,
582,
298,
396,
13,
2473,
401,
298,
2060,
582,
298,
396,
13,
2060,
32655,
272,
543,
3371,
480,
22799,
14,
4608,
14,
2425,
695,
14,
2749,
619,
11518,
401,
2097,
8956,
21473,
267,
702,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
15265,
12,
1101,
9,
267,
5517,
6298,
14,
4146,
63,
1457,
63,
12587,
63,
4456,
342,
339,
19678,
275,
469,
267,
298,
4219,
63,
68,
7969,
63,
11245,
63,
12954,
582,
334,
288,
298,
1165,
63,
12954,
401,
288,
298,
2025,
14,
713,
401,
288,
24314,
63,
21595,
2684,
1668,
12,
288,
11643,
63,
6885,
63,
12510,
32559,
12,
288,
488,
12,
267,
2318,
267,
298,
4219,
63,
68,
7969,
63,
11245,
63,
31812,
582,
334,
288,
298,
1165,
63,
31812,
401,
288,
298,
1400,
14,
2466,
401,
288,
26684,
2962,
12,
288,
11643,
63,
6885,
63,
40,
2639,
998,
1922,
12,
288,
488,
12,
267,
2318,
267,
298,
4219,
63,
68,
7969,
63,
11245,
63,
8387,
63,
9161,
582,
334,
288,
298,
1165,
63,
8387,
63,
9161,
401,
288,
298,
16,
14,
1427,
401,
288,
488,
12,
288,
488,
12,
288,
298,
20208,
26,
23026,
13,
11530,
89,
401,
267,
2318,
272,
789,
339,
367,
334,
8956,
63,
344,
12,
666,
9,
315,
19678,
14,
1744,
837,
267,
4642,
63,
2373,
275,
7086,
14,
4146,
63,
362,
8,
70,
2,
8956,
23379,
8956,
63,
344,
15412,
267,
702,
4642,
63,
2373,
267,
702,
4642,
63,
2373,
14,
1782,
63,
533,
508,
666,
59,
19,
61,
267,
702,
4642,
63,
2373,
14,
3235,
63,
344,
508,
666,
59,
16,
61,
267,
702,
4642,
63,
2373,
14,
5043,
63,
4677,
508,
666,
59,
20,
61,
398,
1174,
275,
6298,
14,
4981,
14,
362,
8,
70,
2,
8956,
23379,
8956,
63,
344,
15412,
267,
702,
1174,
267,
702,
1174,
14,
2987,
14,
362,
8,
5280,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
9,
508,
666,
59,
18,
61,
267,
702,
1174,
14,
929,
508,
666,
59,
17,
61,
339,
2243,
275,
2243,
63,
5189,
14,
4146,
63,
362,
63,
1782,
2561,
8,
7378,
12,
298,
1165,
531,
1552,
272,
702,
2243,
272,
702,
2243,
14,
32214,
508,
26688,
53,
18164,
1230,
540,
272,
702,
2243,
14,
354,
508,
298,
36,
7969,
6848,
676,
2,
272,
702,
2243,
14,
1238,
508,
298,
6049,
695,
2165,
2,
421,
199,
4146,
347,
511,
63,
22675,
63,
2987,
63,
496,
8,
5387,
12,
883,
695,
9,
1035,
488,
26,
272,
408,
774,
314,
7143,
436,
1338,
402,
314,
19678,
3004,
367,
6855,
695,
2165,
1041,
272,
5517,
5316,
63,
2758,
63,
3173,
8,
5387,
12,
298,
18539,
63,
6761,
401,
5009,
339,
18470,
63,
1782,
63,
292,
63,
4219,
275,
1683,
63,
1782,
8,
1165,
12,
298,
36,
7969,
6848,
676,
401,
715,
12,
298,
6049,
695,
2165,
531,
339,
1256,
275,
883,
695,
14,
1107,
63,
585,
272,
1256,
14,
362,
63,
8022,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
1985,
8,
1960,
12,
298,
12054,
401,
715,
12,
7256,
1524,
15178,
63,
1782,
63,
292,
63,
4219,
2522,
272,
1622,
339,
1256,
14,
362,
63,
7410,
63,
739,
780,
14,
1107,
63,
585,
275,
359,
267,
1683,
63,
19332,
480,
12954,
401,
298,
2025,
14,
713,
1288,
267,
1683,
63,
19332,
480,
31812,
401,
298,
1400,
14,
2466,
1288,
267,
1683,
63,
19332,
480,
8387,
63,
9161,
401,
298,
16,
14,
1427,
1288,
272,
1622,
339,
1101,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
t1m0thy/autograd
|
autograd/numpy/numpy_grads.py
|
4
|
18791
|
from __future__ import absolute_import
import operator as op
from autograd.core import getval
from . import numpy_wrapper as anp
from .numpy_extra import ArrayNode, take
import six
from six.moves import range
from six.moves import zip
# ----- Functions that are constant w.r.t. continuous inputs -----
anp.floor.defgrad_is_zero()
anp.ceil.defgrad_is_zero()
anp.round.defgrad_is_zero()
anp.rint.defgrad_is_zero()
anp.around.defgrad_is_zero()
anp.fix.defgrad_is_zero()
anp.trunc.defgrad_is_zero()
anp.all.defgrad_is_zero()
anp.any.defgrad_is_zero()
anp.argmax.defgrad_is_zero()
anp.argmin.defgrad_is_zero()
anp.argpartition.defgrad_is_zero()
anp.argsort.defgrad_is_zero()
anp.argwhere.defgrad_is_zero()
anp.nonzero.defgrad_is_zero()
anp.flatnonzero.defgrad_is_zero()
anp.count_nonzero.defgrad_is_zero()
anp.searchsorted.defgrad_is_zero()
anp.sign.defgrad_is_zero()
anp.ndim.defgrad_is_zero()
anp.shape.defgrad_is_zero()
anp.floor_divide.defgrad_is_zero(argnums=(0, 1))
anp.nan_to_num.defgrad_is_zero()
anp.logical_and.defgrad_is_zero(argnums=(0, 1))
anp.logical_or.defgrad_is_zero(argnums=(0, 1))
anp.logical_not.defgrad_is_zero(argnums=(0, 1))
anp.logical_xor.defgrad_is_zero(argnums=(0, 1))
anp.isfinite.defgrad_is_zero()
anp.isinf.defgrad_is_zero()
anp.isnan.defgrad_is_zero()
anp.isneginf.defgrad_is_zero()
anp.isposinf.defgrad_is_zero()
anp.allclose.defgrad_is_zero()
anp.isclose.defgrad_is_zero()
anp.array_equal.defgrad_is_zero()
anp.array_equiv.defgrad_is_zero()
anp.greater.defgrad_is_zero(argnums=(0, 1))
anp.greater_equal.defgrad_is_zero(argnums=(0, 1))
anp.less.defgrad_is_zero(argnums=(0, 1))
anp.less_equal.defgrad_is_zero(argnums=(0, 1))
anp.equal.defgrad_is_zero(argnums=(0, 1))
anp.not_equal.defgrad_is_zero(argnums=(0, 1))
anp.iscomplexobj.defgrad_is_zero()
anp.iscomplex.defgrad_is_zero()
anp.nan_to_num.defgrad_is_zero()
anp.size.defgrad_is_zero()
anp.where.defgrad_is_zero(argnums=(0,))
# ----- Binary ufuncs -----
I = lambda x : x
anp.add.defgrad(lambda ans, x, y : unbroadcast(ans, x, I))
anp.add.defgrad(lambda ans, x, y : unbroadcast(ans, y, I), argnum=1)
anp.multiply.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : y * g))
anp.multiply.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : x * g), argnum=1)
anp.subtract.defgrad(lambda ans, x, y : unbroadcast(ans, x, I))
anp.subtract.defgrad(lambda ans, x, y : unbroadcast(ans, y, op.neg), argnum=1)
anp.divide.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g / y))
anp.divide.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : - g * x / y**2), argnum=1)
anp.power.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g * y * x ** (y - 1)))
anp.power.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : g * anp.log(x) * x ** y), argnum=1)
anp.maximum.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g * (x == ans)))
anp.maximum.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : g * (y == ans)), argnum=1)
anp.minimum.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g * (x == ans)))
anp.minimum.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : g * (y == ans)), argnum=1)
anp.logaddexp.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g * anp.exp(x-ans)))
anp.logaddexp.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : g * anp.exp(y-ans)), argnum=1)
anp.logaddexp2.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g * 2**(x-ans)))
anp.logaddexp2.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : g * 2**(y-ans)), argnum=1)
anp.true_divide.defgrad(lambda ans, x, y : unbroadcast(ans, x, lambda g : g / y))
anp.true_divide.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : - g * x / y**2), argnum=1)
anp.mod.defgrad( lambda ans, x, y : unbroadcast(ans, x, I))
anp.remainder.defgrad(lambda ans, x, y : unbroadcast(ans, x, I))
anp.mod.defgrad( lambda ans, x, y : unbroadcast(ans, y, lambda g : -g * anp.floor(x/y)), argnum=1)
anp.remainder.defgrad(lambda ans, x, y : unbroadcast(ans, y, lambda g : -g * anp.floor(x/y)), argnum=1)
# ----- Simple grads -----
anp.negative.defgrad(lambda ans, x: op.neg)
anp.abs.defgrad( lambda ans, x : lambda g : g * anp.conj(x) / ans)
anp.fabs.defgrad( lambda ans, x : lambda g : anp.sign(x) * g) # fabs doesn't take complex numbers.
anp.absolute.defgrad(lambda ans, x : lambda g : g * anp.conj(x) / ans)
anp.reciprocal.defgrad(lambda ans, x : lambda g : - g / x**2)
anp.exp.defgrad( lambda ans, x : lambda g : ans * g)
anp.exp2.defgrad( lambda ans, x : lambda g : ans * anp.log(2) * g)
anp.expm1.defgrad( lambda ans, x : lambda g : (ans + 1) * g)
anp.log.defgrad( lambda ans, x : lambda g : g / x)
anp.log2.defgrad( lambda ans, x : lambda g : g / x / anp.log(2))
anp.log10.defgrad( lambda ans, x : lambda g : g / x / anp.log(10))
anp.log1p.defgrad( lambda ans, x : lambda g : g / (x + 1))
anp.sin.defgrad( lambda ans, x : lambda g : g * anp.cos(x))
anp.cos.defgrad( lambda ans, x : lambda g : - g * anp.sin(x))
anp.tan.defgrad( lambda ans, x : lambda g : g / anp.cos(x) **2)
anp.arcsin.defgrad(lambda ans, x : lambda g : g / anp.sqrt(1 - x**2))
anp.arccos.defgrad(lambda ans, x : lambda g :-g / anp.sqrt(1 - x**2))
anp.arctan.defgrad(lambda ans, x : lambda g : g / (1 + x**2))
anp.sinh.defgrad( lambda ans, x : lambda g : g * anp.cosh(x))
anp.cosh.defgrad( lambda ans, x : lambda g : g * anp.sinh(x))
anp.tanh.defgrad( lambda ans, x : lambda g : g / anp.cosh(x) **2)
anp.arcsinh.defgrad(lambda ans, x : lambda g : g / anp.sqrt(x**2 + 1))
anp.arccosh.defgrad(lambda ans, x : lambda g : g / anp.sqrt(x**2 - 1))
anp.arctanh.defgrad(lambda ans, x : lambda g : g / (1 - x**2))
anp.rad2deg.defgrad(lambda ans, x : lambda g : g / anp.pi * 180.0)
anp.degrees.defgrad(lambda ans, x : lambda g : g / anp.pi * 180.0)
anp.deg2rad.defgrad(lambda ans, x : lambda g : g * anp.pi / 180.0)
anp.radians.defgrad(lambda ans, x : lambda g : g * anp.pi / 180.0)
anp.square.defgrad( lambda ans, x : lambda g : g * 2 * x)
anp.sqrt.defgrad( lambda ans, x : lambda g : g * 0.5 * x**-0.5)
anp.sinc.defgrad( lambda ans, x : lambda g : g * (anp.cos(anp.pi*x)*anp.pi*x - anp.sin(anp.pi*x))/(anp.pi*x**2))
anp.reshape.defgrad(lambda ans, x, shape, order=None : lambda g : anp.reshape(g, anp.shape(x), order=order))
anp.roll.defgrad( lambda ans, x, shift, axis=None : lambda g : anp.roll(g, -shift, axis=axis))
anp.array_split.defgrad(lambda ans, ary, idxs, axis=0 : lambda g : anp.concatenate(g, axis=axis))
anp.split.defgrad( lambda ans, ary, idxs, axis=0 : lambda g : anp.concatenate(g, axis=axis))
anp.vsplit.defgrad( lambda ans, ary, idxs : lambda g : anp.concatenate(g, axis=0))
anp.hsplit.defgrad( lambda ans, ary, idxs : lambda g : anp.concatenate(g, axis=1))
anp.dsplit.defgrad( lambda ans, ary, idxs : lambda g : anp.concatenate(g, axis=2))
anp.ravel.defgrad( lambda ans, x, order=None : lambda g : anp.reshape(g, anp.shape(x), order=order))
anp.expand_dims.defgrad(lambda ans, x, axis : lambda g : anp.reshape(g, anp.shape(x)))
anp.squeeze.defgrad(lambda ans, x, axis=None : lambda g : anp.reshape(g, anp.shape(x)))
anp.diag.defgrad( lambda ans, x, k=0 : lambda g : anp.diag(g, k))
anp.flipud.defgrad( lambda ans, x, : lambda g : anp.flipud(g))
anp.fliplr.defgrad( lambda ans, x, : lambda g : anp.fliplr(g))
anp.rot90.defgrad( lambda ans, x, k=1 : lambda g : anp.rot90(g, -k))
anp.trace.defgrad( lambda ans, x, offset=0 : lambda g : anp.einsum('ij,...->ij...', anp.eye(x.shape[0], x.shape[1], k=offset), g))
anp.full.defgrad( lambda ans, shape, fill_value, dtype=None : lambda g : anp.sum(g), argnum=1)
anp.triu.defgrad( lambda ans, x, k=0 : lambda g : anp.triu(g, k=k))
anp.tril.defgrad( lambda ans, x, k=0 : lambda g : anp.tril(g, k=k))
anp.clip.defgrad( lambda ans, x, a_min, a_max : lambda g : g * anp.logical_and(ans != a_min, ans != a_max))
anp.swapaxes.defgrad(lambda ans, x, axis1, axis2: lambda g : anp.swapaxes(g, axis2, axis1))
anp.real_if_close.defgrad(lambda ans, x : lambda g : g)
anp.real.defgrad( lambda ans, x : lambda g : g)
anp.imag.defgrad( lambda ans, x : lambda g : -1j * g)
anp.conj.defgrad( lambda ans, x : lambda g : anp.conj(g))
anp.angle.defgrad( lambda ans, x : lambda g : g * anp.conj(x * 1j) / anp.abs(x)**2)
anp.where.defgrad( lambda ans, c, x=None, y=None : lambda g : anp.where(c, g, anp.zeros(g.shape)), argnum=1)
anp.where.defgrad( lambda ans, c, x=None, y=None : lambda g : anp.where(c, anp.zeros(g.shape), g), argnum=2)
anp.cross.defgrad(lambda ans, a, b, axisa=-1, axisb=-1, axisc=-1, axis=None : lambda g : anp.cross(b, g, axisb, axisc, axisa, axis), argnum=0)
anp.cross.defgrad(lambda ans, a, b, axisa=-1, axisb=-1, axisc=-1, axis=None : lambda g : anp.cross(g, a, axisc, axisa, axisb, axis), argnum=1)
# ----- Trickier grads -----
def make_grad_repeat(ans, x, repeats, axis=None):
shape = x.shape
if axis is None: # If axis is none, np.repeat() repeats the flattened array.
def grad_repeat(g):
expanded = anp.reshape(g, (anp.prod(shape),) + (repeats,))
return anp.reshape(anp.sum(expanded, axis=1, keepdims=False), shape)
return grad_repeat
else:
if shape[axis] == 1: # For this common case, the logic is simple.
return lambda g: anp.sum(g, axis=axis, keepdims=True)
else:
def grad_repeat(g):
expanded = anp.reshape(g, shape[0:axis+1] + (repeats,) + shape[axis+1:])
return anp.sum(expanded, axis=axis+1, keepdims=False)
return grad_repeat
anp.repeat.defgrad(make_grad_repeat)
def make_grad_transpose(ans, x, axes=None):
if axes is not None:
axes = anp.argsort(axes)
return lambda g : anp.transpose(g, axes)
anp.transpose.defgrad(make_grad_transpose)
isarray = lambda x : isinstance(getval(x), anp.ndarray)
def repeat_to_match_shape(x, axis, keepdims):
"""Returns a function that repeats an array along axis to get a given shape.
Also returns the number of repetitions of the array."""
if not isarray(x):
return I, 1
shape = x.shape
if axis is None:
dtype=None
if anp.iscomplexobj(x):
dtype = getval(anp.array(x)).dtype # np.full() has a bug for complex numbers
if keepdims:
return lambda g : anp.full(shape, anp.sum(g), dtype=dtype), anp.prod(shape)
else:
return lambda g : anp.full(shape, g, dtype=dtype), anp.prod(shape)
else:
if keepdims:
return lambda g : anp.repeat(g, shape[axis], axis), shape[axis]
else:
return lambda g : anp.repeat(anp.expand_dims(g, axis),
shape[axis], axis), shape[axis]
def make_grad_np_sum(ans, x, axis=None, keepdims=False):
repeater, _ = repeat_to_match_shape(x, axis, keepdims)
return repeater
anp.sum.defgrad(make_grad_np_sum)
def make_grad_np_mean(ans, x, axis=None, keepdims=False):
repeater, num_reps = repeat_to_match_shape(x, axis, keepdims)
return lambda g: repeater(g) / num_reps
anp.mean.defgrad(make_grad_np_mean)
def make_grad_np_prod(ans, x, axis=None, keepdims=False): # TODO: Support tuples of axes.
repeater, _ = repeat_to_match_shape(x, axis, keepdims)
return lambda g: repeater(g * ans) / x
anp.prod.defgrad(make_grad_np_prod)
def make_grad_np_var(ans, x, axis=None, ddof=0, keepdims=False):
repeater, num_reps = repeat_to_match_shape(x, axis, keepdims)
x_minus_mean = anp.conj(x - anp.mean(x, axis=axis, keepdims=True))
return lambda g: 2.0 * repeater(g) * x_minus_mean / (num_reps - ddof)
anp.var.defgrad(make_grad_np_var)
def make_grad_np_std(ans, x, axis=None, ddof=0, keepdims=False):
repeater, num_reps = repeat_to_match_shape(x, axis, keepdims)
if num_reps <= 1:
return lambda g: repeater(0.0 * g) # Avoid division by zero.
else:
x_minus_mean = anp.conj(x - anp.mean(x, axis=axis, keepdims=True))
return lambda g: repeater(g / ans) * x_minus_mean / (num_reps - ddof)
anp.std.defgrad(make_grad_np_std)
def make_grad_chooser(ans, x, axis=None, keepdims=None):
"""Builds gradient of functions that choose a single item, such as min or max."""
repeater, _ = repeat_to_match_shape(x, axis, keepdims)
argmax_locations = x == repeater(ans)
return lambda g: repeater(g) * argmax_locations
anp.max.defgrad(make_grad_chooser)
anp.min.defgrad(make_grad_chooser)
anp.amax.defgrad(make_grad_chooser)
anp.amin.defgrad(make_grad_chooser)
def reverse_axis(x, axis):
x = x.swapaxes(axis, 0)
x = x[::-1,...]
return x.swapaxes(0, axis)
def make_grad_np_cumsum(ans, x, axis=None):
if axis:
return lambda g: reverse_axis(anp.cumsum(reverse_axis(g, axis)), axis)
else:
shape = x.shape
return lambda g: anp.reshape(anp.cumsum(g[::-1], axis)[::-1], shape)
anp.cumsum.defgrad(make_grad_np_cumsum)
def make_grad_dot(argnum, ans, A, B):
if anp.ndim(A) == 0 or anp.ndim(B) == 0:
axes = ([], [])
else:
axes = ([A.ndim - 1], [max(0, B.ndim - 2)])
return make_grad_tensordot(argnum, ans, A, B, axes=axes)
anp.dot.defgrads(make_grad_dot, [0, 1])
def make_grad_tensordot(argnum, ans, A, B, axes=2):
if type(axes) is int:
axes = (list(range(anp.ndim(A)))[-axes:],
list(range(anp.ndim(B)))[:axes])
def gradfun(g):
N_axes_summed = len(axes[0])
if argnum == 0:
X, Y = A, B
X_axes_summed, Y_axes_summed = axes
g_axes_from_Y = list(range(anp.ndim(g)))[(anp.ndim(X) - N_axes_summed):]
else:
X, Y = B, A
X_axes_summed, Y_axes_summed = axes[::-1]
g_axes_from_Y = list(range(anp.ndim(g)))[:(anp.ndim(Y) - N_axes_summed)]
Y_axes_ignored = [i for i in range(anp.ndim(Y)) if i not in Y_axes_summed]
result = anp.tensordot(g, Y, axes=[g_axes_from_Y, Y_axes_ignored])
sorted_axes_pairs = sorted(zip(X_axes_summed, Y_axes_summed), key = lambda x : x[1])
forward_permutation = ([i for i in range(anp.ndim(X)) if i not in X_axes_summed]
+ [i for i, _ in sorted_axes_pairs])
reverse_permutation = list(anp.argsort(forward_permutation))
if result.ndim == 0:
result = result[()]
return anp.transpose(result, axes=reverse_permutation)
return gradfun
anp.tensordot.defgrads(make_grad_tensordot, [0, 1])
anp.outer.defgrad(lambda ans, a, b : lambda g : anp.dot(g, b.T))
anp.outer.defgrad(lambda ans, a, b : lambda g : anp.dot(a.T, g), argnum=1)
def make_grad_concatenate_args(argnum, ans, axis_args, kwargs):
axis, args = axis_args[0], axis_args[1:]
start = sum([a.shape[axis] for a in args[:argnum-1]])
idxs = [slice(None)] * ans.ndim
idxs[axis] = slice(start, start + args[argnum-1].shape[axis])
return lambda g : take(g, idxs)
anp.concatenate_args.gradmaker = make_grad_concatenate_args
def wrapped_reshape(x, *args, **kwargs):
# The reshape method can be called like A.reshape((5,4)) or A.reshape(5,4).
# The reshape function doesn't support both ways, so we have to wrap it.
if isinstance(args[0], int):
return anp.reshape(x, args, **kwargs)
else:
return anp.reshape(x, *args, **kwargs)
setattr(ArrayNode, 'reshape', wrapped_reshape)
def make_grad_sort(ans, x, axis=-1, kind='quicksort', order=None):
#TODO: Cast input with np.asanyarray()
if len(x.shape) > 1:
raise NotImplementedError(
"Gradient of sort not implemented for multi-dimensional arrays.")
sort_perm = anp.argsort(x, axis, kind, order)
return unpermuter(sort_perm)
anp.sort.defgrad(make_grad_sort)
anp.msort.defgrad(make_grad_sort) # Until multi-D is allowed, these are the same.
def make_grad_partition(ans, x, kth, axis=-1, kind='introselect', order=None):
#TODO: Cast input with np.asanyarray()
if len(x.shape) > 1:
raise NotImplementedError(
"Gradient of partition not implemented for multi-dimensional arrays.")
partition_perm = anp.argpartition(x, kth, axis, kind, order)
return unpermuter(partition_perm)
anp.partition.defgrad(make_grad_partition)
def unpermuter(permutation):
unsort = anp.zeros(len(permutation), dtype=int)
unsort[permutation] = list(range(len(permutation)))
return lambda g: g[unsort]
def make_grad_reshape_list(ans, *arys):
if len(arys) > 1:
raise NotImplementedError("Can't handle multiple arguments yet.")
shape = anp.shape(arys[0])
return lambda g: anp.reshape(g, shape)
anp.atleast_1d.defgrad(make_grad_reshape_list)
anp.atleast_2d.defgrad(make_grad_reshape_list)
anp.atleast_3d.defgrad(make_grad_reshape_list)
def make_grad_einsum(argnum, ans, operands, kwargs):
# Gradient of einsum is obtained by swapping outgrad with the argument
# being differentiated wrt.
if isinstance(operands[0], six.string_types): # using "ijk" convention.
subscripts, operands = operands[0], operands[1:]
if not '->' in subscripts:
raise NotImplementedError("Need indices on both sides.")
op_num = argnum - 1
input_subs, output_subs = subscripts.split('->')
input_subs_list = input_subs.split(',')
subs_wrt = input_subs_list[op_num]
rest_of_ops = operands[:op_num] + operands[op_num + 1:]
rest_of_subs = input_subs_list[:op_num] + input_subs_list[op_num + 1:]
new_subscripts = ','.join([output_subs] + rest_of_subs) + '->' + subs_wrt
return lambda g: anp.einsum(new_subscripts, *((g,) + rest_of_ops))
else: # Using (op0, sublist0, op1, sublist1..., sublistout) convention.
if len(operands) % 2 == 0:
raise NotImplementedError("Need sublistout argument")
operands = list(operands)
rest_of_ops = [operands[-1]] + operands[:argnum] + operands[(argnum+2):-1] + [operands[argnum+1]]
return lambda g: anp.einsum(g, *rest_of_ops)
anp.einsum.gradmaker = make_grad_einsum
# ----- Handle broadcasting -----
def unbroadcast(ans, x, gradfun):
# x is the argument that we're differentiating with respect to.
if isarray(x):
shape = x.shape
def new_fun(g):
result = gradfun(g)
while anp.ndim(result) > len(shape):
result = anp.sum(result, axis=0)
for axis, size in enumerate(shape):
if size == 1:
result = anp.sum(result, axis=axis, keepdims=True)
assert anp.shape(result) == shape
return result
elif isarray(ans):
new_fun = lambda g : anp.sum(gradfun(g))
else:
return gradfun
new_fun.__name__ = "unbroadcast_{0}".format(gradfun.__name__)
return new_fun
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
4182,
465,
1687,
199,
199,
504,
2599,
6017,
14,
1018,
492,
664,
637,
199,
504,
1275,
492,
2680,
63,
5029,
465,
376,
80,
199,
504,
1275,
4714,
63,
2911,
492,
8725,
1716,
12,
5452,
199,
646,
3816,
199,
504,
3816,
14,
4912,
492,
1425,
199,
504,
3816,
14,
4912,
492,
3482,
199,
199,
3,
9063,
17471,
626,
787,
4413,
336,
14,
82,
14,
84,
14,
19922,
4153,
9063,
199,
199,
290,
80,
14,
11289,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
14085,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
2363,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
672,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
11659,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
970,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
8208,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
452,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1629,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
16383,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
26488,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1273,
5312,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
20188,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1273,
4509,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
10262,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
7088,
10262,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
835,
63,
10262,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
31698,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1037,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
8322,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1392,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
11289,
63,
16081,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
4304,
63,
475,
63,
1507,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
7954,
63,
460,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
7954,
63,
269,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
7954,
63,
1397,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
7954,
63,
15721,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
30276,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
29326,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
12936,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
374,
685,
903,
70,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
374,
1712,
4904,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
7520,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
31899,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1144,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1144,
63,
20146,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
13154,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
13154,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
2003,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
2003,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
1397,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
374,
5254,
1113,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
374,
5254,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
4304,
63,
475,
63,
1507,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
890,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
4509,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
4641,
199,
199,
3,
9063,
14161,
399,
9204,
9063,
199,
199,
41,
275,
2400,
671,
520,
671,
199,
290,
80,
14,
525,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
671,
12,
473,
430,
199,
290,
80,
14,
525,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
612,
12,
473,
395,
601,
784,
453,
29,
17,
9,
199,
290,
80,
14,
13710,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
671,
12,
2400,
486,
520,
612,
627,
486,
430,
199,
290,
80,
14,
13710,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
612,
12,
2400,
486,
520,
671,
627,
486,
395,
601,
784,
453,
29,
17,
9,
199,
290,
80,
14,
25719,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
671,
12,
473,
430,
199,
290,
80,
14,
25719,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
612,
12,
1687,
14,
8705,
395,
601,
784,
453,
29,
17,
9,
199,
290,
80
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
4182,
465,
1687,
199,
199,
504,
2599,
6017,
14,
1018,
492,
664,
637,
199,
504,
1275,
492,
2680,
63,
5029,
465,
376,
80,
199,
504,
1275,
4714,
63,
2911,
492,
8725,
1716,
12,
5452,
199,
646,
3816,
199,
504,
3816,
14,
4912,
492,
1425,
199,
504,
3816,
14,
4912,
492,
3482,
199,
199,
3,
9063,
17471,
626,
787,
4413,
336,
14,
82,
14,
84,
14,
19922,
4153,
9063,
199,
199,
290,
80,
14,
11289,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
14085,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
2363,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
672,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
11659,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
970,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
8208,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
452,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1629,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
16383,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
26488,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1273,
5312,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
20188,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1273,
4509,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
10262,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
7088,
10262,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
835,
63,
10262,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
31698,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1037,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
8322,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1392,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
11289,
63,
16081,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
4304,
63,
475,
63,
1507,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
7954,
63,
460,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
7954,
63,
269,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
7954,
63,
1397,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
7954,
63,
15721,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
30276,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
29326,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
12936,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
374,
685,
903,
70,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
374,
1712,
4904,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
7520,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
31899,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1144,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
1144,
63,
20146,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
13154,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
13154,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
2003,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
2003,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
1397,
63,
1452,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
12,
413,
430,
199,
290,
80,
14,
374,
5254,
1113,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
374,
5254,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
4304,
63,
475,
63,
1507,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
890,
14,
318,
6017,
63,
374,
63,
4262,
342,
199,
290,
80,
14,
4509,
14,
318,
6017,
63,
374,
63,
4262,
8,
285,
784,
23816,
2687,
16,
4641,
199,
199,
3,
9063,
14161,
399,
9204,
9063,
199,
199,
41,
275,
2400,
671,
520,
671,
199,
290,
80,
14,
525,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
671,
12,
473,
430,
199,
290,
80,
14,
525,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
612,
12,
473,
395,
601,
784,
453,
29,
17,
9,
199,
290,
80,
14,
13710,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
671,
12,
2400,
486,
520,
612,
627,
486,
430,
199,
290,
80,
14,
13710,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
612,
12,
2400,
486,
520,
671,
627,
486,
395,
601,
784,
453,
29,
17,
9,
199,
290,
80,
14,
25719,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
671,
12,
473,
430,
199,
290,
80,
14,
25719,
14,
318,
6017,
8,
2734,
4987,
12,
671,
12,
612,
520,
625,
10786,
8,
796,
12,
612,
12,
1687,
14,
8705,
395,
601,
784,
453,
29,
17,
9,
199,
290,
80,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andreas-kowasch/DomainSearch
|
DomainSearchViewer/modules/RobotsTxt.py
|
2
|
4113
|
# -*- coding: utf-8 -*-
"""
Module for loadiing the robots.txt file
"""
import re
import socket
from http import client
from modules import DatasourceBase
from modules import ModuleError
################################################################################
class RobotsTxt(DatasourceBase):
"""
The module loads the robots.txt if exists.
"""
# version of the module
_version = 2015012401
# dependencies of the module
_dependencies = set()
# database query strings of the module
_queries = {
'create' : '''
CREATE TABLE IF NOT EXISTS module_RobotsTxt (
id INT AUTO_INCREMENT NOT NULL,
request_id INT NOT NULL,
file TEXT,
PRIMARY KEY (id),
FOREIGN KEY (request_id) REFERENCES requests(id)
)''',
'insert' : '''
INSERT INTO module_RobotsTxt (request_id, file)
VALUES (%s, %s)''',
'select' : '''
SELECT *
FROM module_RobotsTxt
WHERE request_id = %s'''
}
############################################################################
def __init__(self):
super(RobotsTxt, self).__init__()
############################################################################
def _search(self, request_id, domain, counter):
"""
Inherited method to start the search. The result will be entered in the
database.
"""
try:
content = self._get_robots(domain)
self._db.insert_data(
self._queries['insert'],
(request_id, content)
)
except socket.gaierror:
self._report_module_error(request_id, 'No webserver on this domain')
raise ModuleError
except Exception as error:
self._report_module_error(request_id, error)
raise ModuleError
############################################################################
def _get_robots(self, domain):
"""
Connects to to the domain and tries to get the robots.txt file.
@return: content of robots.txt or nothing
"""
request = '/robots.txt'
do_again = True
https = False
counter = 0
while do_again and counter < self._get_module_config('max_depth'):
do_again = False
counter += 1
self._log.debug(domain + ' ' + request)
# open connection
if https:
conn = client.HTTPSConnection(domain, 443)
else:
conn = client.HTTPConnection(domain, 80)
conn.request('GET' , request)
response = conn.getresponse()
# read response
code = response.code
content = response.read().decode('utf-8', 'ignore')
self._log.debug(code)
self._log.debug(content)
# look for location in header fields if code
# redirects and look again
if code >= 300 and code <= 303:
for title, loc in response.getheaders():
self._log.debug(title + ' ' + loc)
if title.lower() == 'location':
match = re.search(r'http(s?)://(.*?)($|/.*)', loc)
if match:
if match.group(1) == 's':
https = True
new_request = match.group(3)
new_domain = match.group(2)
if domain == new_domain and request == new_request:
return None
if new_request:
request = new_request
domain = new_domain
break
do_again = True
conn.close()
continue
# return if robots.txt found
if code is 200:
return content
|
bsd-2-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
2377,
367,
560,
65,
328,
316,
314,
14544,
83,
14,
2424,
570,
199,
624,
199,
199,
646,
295,
199,
646,
2838,
199,
504,
1455,
492,
1890,
199,
199,
504,
4621,
492,
577,
292,
305,
616,
1563,
199,
504,
4621,
492,
5673,
547,
199,
199,
13289,
199,
199,
533,
820,
2873,
16673,
32199,
8,
28369,
305,
616,
1563,
304,
272,
408,
272,
710,
859,
14404,
314,
14544,
83,
14,
2424,
340,
3495,
14,
272,
408,
339,
327,
1015,
402,
314,
859,
272,
485,
1023,
275,
6900,
614,
1194,
614,
339,
327,
5124,
402,
314,
859,
272,
485,
5714,
275,
663,
342,
339,
327,
3050,
1827,
3326,
402,
314,
859,
272,
485,
10590,
275,
469,
267,
283,
981,
7,
520,
1449,
288,
16999,
9934,
8036,
2845,
23875,
859,
63,
50,
2873,
16673,
32199,
334,
355,
1305,
16429,
25420,
63,
568,
31431,
2845,
5962,
12,
355,
1056,
63,
344,
16429,
2845,
5962,
12,
355,
570,
11951,
12,
355,
19770,
9301,
334,
344,
395,
355,
2381,
37,
3203,
9301,
334,
1069,
63,
344,
9,
26901,
22243,
4145,
8,
344,
9,
288,
776,
18108,
398,
283,
3176,
7,
520,
1449,
288,
22542,
12872,
859,
63,
50,
2873,
16673,
32199,
334,
1069,
63,
344,
12,
570,
9,
288,
13992,
4366,
83,
12,
450,
83,
9,
18108,
398,
283,
2416,
7,
520,
1449,
288,
10468,
627,
288,
4442,
859,
63,
50,
2873,
16673,
32199,
288,
6038,
1056,
63,
344,
275,
450,
83,
2344,
272,
789,
339,
23441,
381,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
50,
2873,
16673,
32199,
12,
291,
2843,
826,
4533,
339,
23441,
381,
339,
347,
485,
1733,
8,
277,
12,
1056,
63,
344,
12,
2881,
12,
7055,
304,
267,
408,
267,
1010,
8829,
1083,
370,
1343,
314,
2754,
14,
710,
754,
911,
506,
19138,
315,
314,
267,
3050,
14,
267,
408,
398,
862,
26,
953,
1564,
275,
291,
423,
362,
63,
28889,
8,
2261,
9,
953,
291,
423,
697,
14,
3176,
63,
576,
8,
355,
291,
423,
10590,
459,
3176,
995,
355,
334,
1069,
63,
344,
12,
1564,
9,
288,
776,
398,
871,
2838,
14,
5294,
73,
705,
26,
953,
291,
423,
3070,
63,
578,
63,
705,
8,
1069,
63,
344,
12,
283,
1944,
3330,
1000,
641,
642,
2881,
358,
953,
746,
5673,
547,
398,
871,
2186,
465,
1125,
26,
953,
291,
423,
3070,
63,
578,
63,
705,
8,
1069,
63,
344,
12,
1125,
9,
953,
746,
5673,
547,
339,
23441,
381,
339,
347,
485,
362,
63,
28889,
8,
277,
12,
2881,
304,
267,
408,
267,
15175,
83,
370,
370,
314,
2881,
436,
11275,
370,
664,
314,
14544,
83,
14,
2424,
570,
14,
398,
768,
1107,
26,
1564,
402,
14544,
83,
14,
2424,
503,
6548,
267,
408,
398,
1056,
275,
1994,
28889,
14,
2424,
7,
267,
886,
63,
14199,
275,
715,
267,
4178,
275,
756,
267,
7055,
275,
378,
398,
1830,
886,
63,
14199,
436,
7055,
665,
291,
423,
362,
63,
578,
63,
888,
360,
988,
63,
4631,
735,
953,
886,
63,
14199,
275,
756,
288,
7055,
847,
413,
953,
291,
423,
793,
14,
1757,
8,
2261,
435,
283,
283,
435,
1056,
9,
953,
327,
1551,
1950,
953,
340,
4178,
26,
355,
2557,
275,
1890,
14,
27945,
8,
2261,
12,
23865,
9,
953,
587,
26,
355,
2557,
275,
1890,
14,
19114,
8,
2261,
12,
5939,
9,
953,
2557,
14,
1069,
360,
2970,
7,
2360,
1056,
9,
288,
1177,
275,
2557,
14,
25006,
342,
953,
327,
1586,
1177,
288,
1233,
275,
1177,
14,
600,
288,
1564,
275,
1177,
14,
739,
1252,
2708,
360,
1624,
13,
24,
297,
283,
4247,
358,
953,
291,
423,
793,
14,
1757,
8,
600,
9,
288,
291,
423,
793,
14,
1757,
8,
1317,
9,
953,
327,
3648,
367,
2909,
315,
1406,
1504,
340,
1233,
288,
327,
17784,
436,
3648,
4020,
288,
340,
1233,
2356,
9601,
436,
1233,
2695,
25989,
26,
2234,
367,
2538,
12,
4355,
315,
1177,
14,
19958,
83,
837,
4951,
291,
423,
793,
14,
1757,
8,
1213,
435,
283,
283,
435,
4355,
9,
4951,
340,
2538,
14,
2325,
342,
508,
283,
1985,
356,
9453,
1336,
275,
295,
14,
1733,
8,
82,
7,
1014,
8,
83,
31,
304,
501,
17140,
5130,
31686,
15,
2795,
3196,
4355,
9,
9453,
340,
1336,
26,
18008,
340,
1336,
14,
923,
8,
17,
9,
508,
283,
83,
356,
1816,
4178,
275,
715,
18008,
892,
63,
1069,
275,
1336,
14,
923,
8,
19,
9,
1169,
892,
63,
2261,
275,
1336,
14,
923,
8,
18,
9,
18008,
340,
2881,
508,
892,
63,
2261,
436,
1056,
508,
892,
63,
1069,
26,
1816,
372,
488,
18008,
340,
892,
63,
1069,
26,
1816,
1056,
275,
892,
63,
1069,
18008,
2881,
275,
892,
63,
2261,
18008,
2059,
2234,
886,
63,
14199,
275,
715,
355,
2557,
14,
1600,
342,
355,
1980,
953,
327,
372,
340,
14544,
83,
14,
2424,
1911,
288,
340,
1233,
365,
1926,
26,
355,
372,
1564,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
2377,
367,
560,
65,
328,
316,
314,
14544,
83,
14,
2424,
570,
199,
624,
199,
199,
646,
295,
199,
646,
2838,
199,
504,
1455,
492,
1890,
199,
199,
504,
4621,
492,
577,
292,
305,
616,
1563,
199,
504,
4621,
492,
5673,
547,
199,
199,
13289,
199,
199,
533,
820,
2873,
16673,
32199,
8,
28369,
305,
616,
1563,
304,
272,
408,
272,
710,
859,
14404,
314,
14544,
83,
14,
2424,
340,
3495,
14,
272,
408,
339,
327,
1015,
402,
314,
859,
272,
485,
1023,
275,
6900,
614,
1194,
614,
339,
327,
5124,
402,
314,
859,
272,
485,
5714,
275,
663,
342,
339,
327,
3050,
1827,
3326,
402,
314,
859,
272,
485,
10590,
275,
469,
267,
283,
981,
7,
520,
1449,
288,
16999,
9934,
8036,
2845,
23875,
859,
63,
50,
2873,
16673,
32199,
334,
355,
1305,
16429,
25420,
63,
568,
31431,
2845,
5962,
12,
355,
1056,
63,
344,
16429,
2845,
5962,
12,
355,
570,
11951,
12,
355,
19770,
9301,
334,
344,
395,
355,
2381,
37,
3203,
9301,
334,
1069,
63,
344,
9,
26901,
22243,
4145,
8,
344,
9,
288,
776,
18108,
398,
283,
3176,
7,
520,
1449,
288,
22542,
12872,
859,
63,
50,
2873,
16673,
32199,
334,
1069,
63,
344,
12,
570,
9,
288,
13992,
4366,
83,
12,
450,
83,
9,
18108,
398,
283,
2416,
7,
520,
1449,
288,
10468,
627,
288,
4442,
859,
63,
50,
2873,
16673,
32199,
288,
6038,
1056,
63,
344,
275,
450,
83,
2344,
272,
789,
339,
23441,
381,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
50,
2873,
16673,
32199,
12,
291,
2843,
826,
4533,
339,
23441,
381,
339,
347,
485,
1733,
8,
277,
12,
1056,
63,
344,
12,
2881,
12,
7055,
304,
267,
408,
267,
1010,
8829,
1083,
370,
1343,
314,
2754,
14,
710,
754,
911,
506,
19138,
315,
314,
267,
3050,
14,
267,
408,
398,
862,
26,
953,
1564,
275,
291,
423,
362,
63,
28889,
8,
2261,
9,
953,
291,
423,
697,
14,
3176,
63,
576,
8,
355,
291,
423,
10590,
459,
3176,
995,
355,
334,
1069,
63,
344,
12,
1564,
9,
288,
776,
398,
871,
2838,
14,
5294,
73,
705,
26,
953,
291,
423,
3070,
63,
578,
63,
705,
8,
1069,
63,
344,
12,
283,
1944,
3330,
1000,
641,
642,
2881,
358,
953,
746,
5673,
547,
398,
871,
2186,
465,
1125,
26,
953,
291,
423,
3070,
63,
578,
63,
705,
8,
1069,
63,
344,
12,
1125,
9,
953,
746,
5673,
547,
339,
23441,
381,
339,
347,
485,
362,
63,
28889,
8,
277,
12,
2881,
304,
267,
408,
267,
15175,
83,
370,
370,
314,
2881,
436,
11275,
370,
664,
314,
14544,
83,
14,
2424,
570,
14,
398,
768,
1107,
26,
1564,
402,
14544,
83,
14,
2424,
503,
6548,
267,
408,
398,
1056,
275,
1994,
28889,
14,
2424,
7,
267,
886,
63,
14199,
275,
715,
267,
4178,
275,
756,
267,
7055,
275,
378,
398,
1830,
886,
63,
14199,
436,
7055,
665,
291,
423,
362,
63,
578,
63,
888,
360,
988,
63,
4631,
735,
953,
886,
63,
14199,
275,
756,
288,
7055,
847,
413,
953,
291,
423,
793,
14,
1757,
8,
2261,
435,
283,
283,
435,
1056,
9,
953,
327,
1551,
1950,
953,
340,
4178,
26,
355,
2557,
275,
1890,
14,
27945,
8,
2261,
12,
23865,
9,
953,
587,
26,
355,
2557,
275,
1890,
14,
19114,
8,
2261,
12,
5939,
9,
953,
2557,
14,
1069,
360,
2970,
7,
2360,
1056,
9,
288,
1177,
275,
2557,
14,
25006,
342,
953,
327,
1586,
1177,
288,
1233,
275,
1177,
14,
600,
288,
1564,
275,
1177,
14,
739,
1252,
2708,
360,
1624,
13,
24,
297,
283,
4247,
358,
953,
291,
423,
793,
14,
1757,
8,
600,
9,
288,
291,
423,
793,
14,
1757,
8,
1317,
9,
953,
327,
3648,
367,
2909,
315,
1406,
1504,
340,
1233,
288,
327,
17784,
436,
3648,
4020,
288,
340,
1233,
2356,
9601,
436,
1233,
2695,
25989,
26,
2234,
367,
2538,
12,
4355,
315,
1177,
14,
19958,
83,
837,
4951,
291,
423,
793,
14,
1757,
8,
1213,
435,
283,
283,
435,
4355,
9,
4951,
340,
2538,
14,
2325,
342,
508,
283,
1985,
356,
9453,
1336,
275,
295,
14,
1733,
8,
82,
7,
1014,
8,
83,
31,
304,
501,
17140,
5130,
31686,
15,
2795,
3196,
4355,
9,
9453,
340,
1336,
26,
18008,
340,
1336,
14,
923,
8,
17,
9,
508,
283,
83,
356,
1816,
4178,
275,
715,
18008,
892,
63,
1069,
275,
1336,
14,
923,
8,
19,
9,
1169,
892,
63,
2261,
275,
1336,
14,
923,
8,
18,
9,
18008,
340,
2881,
508,
892,
63,
2261,
436,
1056,
508,
892,
63,
1069,
26,
1816,
372,
488,
18008,
340,
892,
63,
1069,
26,
1816,
1056,
275,
892,
63,
1069,
18008,
2881,
275,
892,
63,
2261,
18008,
2059,
2234,
886,
63,
14199,
275,
715,
355,
2557,
14,
1600,
342,
355,
1980,
953,
327,
372,
340,
14544,
83,
14,
2424,
1911,
288,
340,
1233,
365,
1926,
26,
355,
372,
1564,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Adarnof/allianceauth
|
allianceauth/eveonline/migrations/0001_initial.py
|
6
|
3197
|
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-09-05 21:39
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='EveAllianceInfo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('alliance_id', models.CharField(max_length=254)),
('alliance_name', models.CharField(max_length=254)),
('alliance_ticker', models.CharField(max_length=254)),
('executor_corp_id', models.CharField(max_length=254)),
('is_blue', models.BooleanField(default=False)),
('member_count', models.IntegerField()),
],
),
migrations.CreateModel(
name='EveApiKeyPair',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('api_id', models.CharField(max_length=254)),
('api_key', models.CharField(max_length=254)),
('error_count', models.PositiveIntegerField(default=0)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='EveCharacter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('character_id', models.CharField(max_length=254)),
('character_name', models.CharField(max_length=254)),
('corporation_id', models.CharField(max_length=254)),
('corporation_name', models.CharField(max_length=254)),
('corporation_ticker', models.CharField(max_length=254)),
('alliance_id', models.CharField(max_length=254)),
('alliance_name', models.CharField(max_length=254)),
('api_id', models.CharField(max_length=254)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='EveCorporationInfo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('corporation_id', models.CharField(max_length=254)),
('corporation_name', models.CharField(max_length=254)),
('corporation_ticker', models.CharField(max_length=254)),
('member_count', models.IntegerField()),
('is_blue', models.BooleanField(default=False)),
('alliance', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='eveonline.EveAllianceInfo')),
],
),
]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
709,
14,
17,
641,
7800,
13,
1643,
13,
1717,
7829,
26,
1355,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
2536,
275,
715,
339,
5124,
275,
359,
267,
6180,
14,
31925,
63,
8575,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
2439,
3636,
2354,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
279,
3636,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
28572,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
13471,
63,
989,
80,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
374,
63,
6304,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
1114,
63,
835,
297,
1709,
14,
3901,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
7394,
1197,
12882,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
1246,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
1246,
63,
498,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
705,
63,
835,
297,
1709,
14,
8591,
8,
885,
29,
16,
1826,
355,
661,
751,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
14852,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
10856,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
10856,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
28572,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
1246,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
751,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
8380,
10633,
2354,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
989,
10633,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
28572,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
1114,
63,
835,
297,
1709,
14,
3901,
4000,
355,
661,
374,
63,
6304,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
279,
3636,
297,
1709,
14,
3190,
8,
2500,
29,
549,
12,
2973,
29,
549,
12,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
4754,
15178,
14,
37,
432,
2439,
3636,
2354,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
709,
14,
17,
641,
7800,
13,
1643,
13,
1717,
7829,
26,
1355,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
2536,
275,
715,
339,
5124,
275,
359,
267,
6180,
14,
31925,
63,
8575,
8,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
2439,
3636,
2354,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
279,
3636,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
28572,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
13471,
63,
989,
80,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
374,
63,
6304,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
1114,
63,
835,
297,
1709,
14,
3901,
4000,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
7394,
1197,
12882,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
1246,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
1246,
63,
498,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
705,
63,
835,
297,
1709,
14,
8591,
8,
885,
29,
16,
1826,
355,
661,
751,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
14852,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
10856,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
10856,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
28572,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
279,
3636,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
1246,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
751,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
37,
432,
8380,
10633,
2354,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
989,
10633,
63,
344,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
989,
10633,
63,
28572,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8306,
1826,
355,
661,
1114,
63,
835,
297,
1709,
14,
3901,
4000,
355,
661,
374,
63,
6304,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
279,
3636,
297,
1709,
14,
3190,
8,
2500,
29,
549,
12,
2973,
29,
549,
12,
641,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
4754,
15178,
14,
37,
432,
2439,
3636,
2354,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Hitechverma/zamboni
|
mkt/webapps/indexers.py
|
1
|
19450
|
from operator import attrgetter
from django.core.urlresolvers import reverse
from django.db.models import Min
import commonware.log
from elasticsearch_dsl import F
from elasticsearch_dsl.filter import Bool
import mkt
from mkt.constants import APP_FEATURES
from mkt.constants.applications import DEVICE_GAIA
from mkt.prices.models import AddonPremium
from mkt.search.indexers import BaseIndexer
from mkt.search.utils import Search
from mkt.tags.models import attach_tags
from mkt.translations.models import attach_trans_dict
log = commonware.log.getLogger('z.addons')
class WebappIndexer(BaseIndexer):
"""Fields we don't need to expose in the results, only used for filtering
or sorting."""
hidden_fields = (
'*.raw',
'*_sort',
'popularity_*',
'trending_*',
'boost',
'owners',
'features',
# 'name' and 'description', as well as the locale variants, are only
# used for filtering. The fields that are used by the API are
# 'name_translations' and 'description_translations'.
'name',
'description',
'name_l10n_*',
'description_l10n_*',
)
"""
Bunch of ES stuff for Webapp include mappings, indexing, search.
"""
@classmethod
def search(cls, using=None):
"""
Returns a `Search` object.
We override this to use our patched version which adds statsd timing.
"""
return (Search(
using=using or cls.get_es(), index=cls.get_index(),
doc_type=cls.get_mapping_type_name())
.extra(_source={'exclude': cls.hidden_fields}))
@classmethod
def get_mapping_type_name(cls):
"""
Returns mapping type name which is used as the key in ES_INDEXES to
determine which index to use.
We override this because Webapp is a proxy model to Addon.
"""
return 'webapp'
@classmethod
def get_model(cls):
from mkt.webapps.models import Webapp
return Webapp
@classmethod
def get_mapping(cls):
doc_type = cls.get_mapping_type_name()
mapping = {
doc_type: {
# Disable _all field to reduce index size.
'_all': {'enabled': False},
'properties': {
# App fields.
'id': {'type': 'long'},
'app_slug': {'type': 'string'},
'app_type': {'type': 'byte'},
'author': {
'type': 'string',
'analyzer': 'default_icu',
'fields': {
# For exact matches. The simple analyzer allows
# for case-insensitive matching.
'raw': {'type': 'string',
'analyzer': 'exact_lowercase'},
},
},
'banner_regions': cls.string_not_indexed(),
'bayesian_rating': {'type': 'float', 'doc_values': True},
'category': cls.string_not_analyzed(),
'content_descriptors': cls.string_not_indexed(),
'content_ratings': {
'type': 'object',
'dynamic': 'true',
},
'created': {'format': 'dateOptionalTime', 'type': 'date',
'doc_values': True},
'current_version': cls.string_not_indexed(),
'default_locale': cls.string_not_indexed(),
'description': {'type': 'string',
'analyzer': 'default_icu',
'position_offset_gap': 100},
'device': {'type': 'byte'},
# The date this app was added to the escalation queue.
'escalation_date': {'format': 'dateOptionalTime',
'type': 'date', 'doc_values': True},
'features': {
'type': 'object',
'properties': dict(
('has_%s' % f.lower(), {'type': 'boolean'})
for f in APP_FEATURES)
},
'file_size': {'type': 'long'},
'guid': cls.string_not_analyzed(),
'has_public_stats': {'type': 'boolean'},
'icon_hash': cls.string_not_indexed(),
'interactive_elements': cls.string_not_indexed(),
'installs_allowed_from': cls.string_not_analyzed(),
'is_disabled': {'type': 'boolean'},
'is_escalated': {'type': 'boolean'},
'is_offline': {'type': 'boolean'},
'is_priority': {'type': 'boolean'},
'is_rereviewed': {'type': 'boolean'},
'last_updated': {'format': 'dateOptionalTime',
'type': 'date'},
'latest_version': {
'type': 'object',
'properties': {
'status': {'type': 'byte'},
'is_privileged': {'type': 'boolean'},
'has_editor_comment': {'type': 'boolean'},
'has_info_request': {'type': 'boolean'},
'nomination_date': {'type': 'date',
'format': 'dateOptionalTime'},
'created_date': {'type': 'date',
'format': 'dateOptionalTime'},
},
},
'manifest_url': cls.string_not_analyzed(),
'modified': {'format': 'dateOptionalTime',
'type': 'date'},
# Name for searching. This is a list of all the localized
# names for the app. We add "position_offset_gap" to work
# around the fact that ES stores the same list of tokens as
# if this were a single string. The offset gap adds 100
# positions between each name and ensures one string from
# one name and one string from another name won't both
# match with a phrase match query.
'name': {
'type': 'string',
'analyzer': 'default_icu',
'position_offset_gap': 100,
# For exact matches. Referenced as `name.raw`.
'fields': {
'raw': cls.string_not_analyzed(
position_offset_gap=100)
},
},
# Name for sorting.
'name_sort': cls.string_not_analyzed(doc_values=True),
# Name for suggestions.
'name_suggest': {'type': 'completion', 'payloads': True},
'owners': {'type': 'long'},
'package_path': cls.string_not_indexed(),
'premium_type': {'type': 'byte'},
'previews': {
'type': 'object',
'dynamic': 'true',
},
'price_tier': cls.string_not_indexed(),
'ratings': {
'type': 'object',
'properties': {
'average': {'type': 'float'},
'count': {'type': 'short'},
}
},
'region_exclusions': {'type': 'short'},
'reviewed': {'format': 'dateOptionalTime', 'type': 'date',
'doc_values': True},
# The date this app was added to the re-review queue.
'rereview_date': {'format': 'dateOptionalTime',
'type': 'date', 'doc_values': True},
'status': {'type': 'byte'},
'supported_locales': cls.string_not_analyzed(),
'tags': cls.string_not_analyzed(),
'upsell': {
'type': 'object',
'properties': {
'id': {'type': 'long'},
'app_slug': cls.string_not_indexed(),
'icon_url': cls.string_not_indexed(),
'name': cls.string_not_indexed(),
'region_exclusions': {'type': 'short'},
}
},
'uses_flash': {'type': 'boolean'},
'versions': {
'type': 'object',
'properties': {
'version': cls.string_not_indexed(),
'resource_uri': cls.string_not_indexed(),
}
},
}
}
}
# Attach boost field, because we are going to need search by relevancy.
cls.attach_boost_mapping(mapping)
# Attach popularity and trending.
cls.attach_trending_and_popularity_mappings(mapping)
# Add fields that we expect to return all translations.
cls.attach_translation_mappings(
mapping, ('banner_message', 'description', 'homepage',
'name', 'release_notes', 'support_email',
'support_url'))
# Add language-specific analyzers.
cls.attach_language_specific_analyzers(
mapping, ('name', 'description'))
return mapping
@classmethod
def extract_document(cls, pk=None, obj=None):
"""Extracts the ElasticSearch index document for this instance."""
from mkt.webapps.models import (AppFeatures, attach_devices,
attach_prices, attach_translations,
RatingDescriptors, RatingInteractives)
if obj is None:
obj = cls.get_model().objects.get(pk=pk)
# Attach everything we need to index apps.
for transform in (attach_devices, attach_prices, attach_tags,
attach_translations):
transform([obj])
latest_version = obj.latest_version
version = obj.current_version
geodata = obj.geodata
features = (version.features.to_dict()
if version else AppFeatures().to_dict())
try:
status = latest_version.statuses[0][1] if latest_version else None
except IndexError:
status = None
attrs = ('app_slug', 'bayesian_rating', 'created', 'default_locale',
'guid', 'icon_hash', 'id', 'is_disabled', 'is_offline',
'file_size', 'last_updated', 'modified', 'premium_type',
'status', 'uses_flash')
d = dict(zip(attrs, attrgetter(*attrs)(obj)))
d['app_type'] = obj.app_type_id
d['author'] = obj.developer_name
d['banner_regions'] = geodata.banner_regions_slugs()
d['category'] = obj.categories if obj.categories else []
d['content_ratings'] = (obj.get_content_ratings_by_body(es=True) or
None)
try:
d['content_descriptors'] = obj.rating_descriptors.to_keys()
except RatingDescriptors.DoesNotExist:
d['content_descriptors'] = []
d['current_version'] = version.version if version else None
d['device'] = getattr(obj, 'device_ids', [])
d['features'] = features
d['has_public_stats'] = obj.public_stats
try:
d['interactive_elements'] = obj.rating_interactives.to_keys()
except RatingInteractives.DoesNotExist:
d['interactive_elements'] = []
d['installs_allowed_from'] = (
version.manifest.get('installs_allowed_from', ['*'])
if version else ['*'])
d['is_priority'] = obj.priority_review
is_escalated = obj.escalationqueue_set.exists()
d['is_escalated'] = is_escalated
d['escalation_date'] = (obj.escalationqueue_set.get().created
if is_escalated else None)
is_rereviewed = obj.rereviewqueue_set.exists()
d['is_rereviewed'] = is_rereviewed
d['rereview_date'] = (obj.rereviewqueue_set.get().created
if is_rereviewed else None)
if latest_version:
d['latest_version'] = {
'status': status,
'is_privileged': latest_version.is_privileged,
'has_editor_comment': latest_version.has_editor_comment,
'has_info_request': latest_version.has_info_request,
'nomination_date': latest_version.nomination,
'created_date': latest_version.created,
}
else:
d['latest_version'] = {
'status': None,
'is_privileged': None,
'has_editor_comment': None,
'has_info_request': None,
'nomination_date': None,
'created_date': None,
}
d['manifest_url'] = obj.get_manifest_url()
d['package_path'] = obj.get_package_path()
d['name_sort'] = unicode(obj.name).lower()
d['owners'] = [au.user.id for au in
obj.addonuser_set.filter(role=mkt.AUTHOR_ROLE_OWNER)]
d['previews'] = [{'filetype': p.filetype, 'modified': p.modified,
'id': p.id, 'sizes': p.sizes}
for p in obj.previews.all()]
try:
p = obj.addonpremium.price
d['price_tier'] = p.name
except AddonPremium.DoesNotExist:
d['price_tier'] = None
d['ratings'] = {
'average': obj.average_rating,
'count': obj.total_reviews,
}
d['region_exclusions'] = obj.get_excluded_region_ids()
d['reviewed'] = obj.versions.filter(
deleted=False).aggregate(Min('reviewed')).get('reviewed__min')
# The default locale of the app is considered "supported" by default.
supported_locales = [obj.default_locale]
other_locales = (filter(None, version.supported_locales.split(','))
if version else [])
if other_locales:
supported_locales.extend(other_locales)
d['supported_locales'] = list(set(supported_locales))
d['tags'] = getattr(obj, 'tags_list', [])
if obj.upsell and obj.upsell.premium.is_published():
upsell_obj = obj.upsell.premium
d['upsell'] = {
'id': upsell_obj.id,
'app_slug': upsell_obj.app_slug,
'icon_url': upsell_obj.get_icon_url(128),
# TODO: Store all localizations of upsell.name.
'name': unicode(upsell_obj.name),
'region_exclusions': upsell_obj.get_excluded_region_ids()
}
d['versions'] = [dict(version=v.version,
resource_uri=reverse_version(v))
for v in obj.versions.all()]
# Handle localized fields.
# This adds both the field used for search and the one with
# all translations for the API.
for field in ('description', 'name'):
d.update(cls.extract_field_translations(
obj, field, include_field_for_search=True))
# This adds only the field with all the translations for the API, we
# don't need to search on those.
for field in ('homepage', 'support_email', 'support_url'):
d.update(cls.extract_field_translations(obj, field))
if version:
attach_trans_dict(version._meta.model, [version])
d.update(cls.extract_field_translations(
version, 'release_notes', db_field='releasenotes_id'))
else:
d['release_notes_translations'] = None
attach_trans_dict(geodata._meta.model, [geodata])
d.update(cls.extract_field_translations(geodata, 'banner_message'))
# Add boost, popularity, trending values.
d.update(cls.extract_popularity_trending_boost(obj))
# If the app is compatible with Firefox OS, push suggestion data in the
# index - This will be used by RocketbarView API, which is specific to
# Firefox OS.
if DEVICE_GAIA.id in d['device'] and obj.is_published():
d['name_suggest'] = {
'input': d['name'],
'output': unicode(obj.id), # We only care about the payload.
'weight': int(d['boost']),
'payload': {
'default_locale': d['default_locale'],
'icon_hash': d['icon_hash'],
'id': d['id'],
'manifest_url': d['manifest_url'],
'modified': d['modified'],
'name_translations': d['name_translations'],
'slug': d['app_slug'],
}
}
for field in ('name', 'description'):
d.update(cls.extract_field_analyzed_translations(obj, field))
return d
@classmethod
def get_indexable(cls):
"""Returns the queryset of ids of all things to be indexed."""
from mkt.webapps.models import Webapp
return Webapp.with_deleted.all()
@classmethod
def run_indexing(cls, ids, ES=None, index=None, **kw):
"""Override run_indexing to use app transformers."""
from mkt.webapps.models import Webapp
log.info('Indexing %s webapps' % len(ids))
qs = Webapp.with_deleted.filter(id__in=ids)
ES = ES or cls.get_es()
docs = []
for obj in list(qs):
try:
docs.append(cls.extract_document(obj.id, obj=obj))
except Exception as e:
log.error('Failed to index webapp {0}: {1}'
.format(obj.id, repr(e)),
# Trying to chase down a cache-machine problem.
exc_info="marketplace:" in str(e))
cls.bulk_index(docs, es=ES, index=index or cls.get_index())
@classmethod
def filter_by_apps(cls, app_ids, queryset=None):
"""
Filters the given queryset by the given app IDs.
This uses a `should` filter, which is equivalent to an "OR".
"""
queryset = queryset or cls.search()
app_ids = list(set(app_ids)) # De-dupe.
queryset = queryset.filter(Bool(should=[F('terms', id=app_ids)]))
return queryset[0:len(app_ids)]
def reverse_version(version):
"""
The try/except AttributeError allows this to be used where the input is
ambiguous, and could be either an already-reversed URL or a Version object.
"""
if version:
try:
return reverse('version-detail', kwargs={'pk': version.pk})
except AttributeError:
return version
return
|
bsd-3-clause
|
[
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
697,
14,
992,
492,
10195,
199,
199,
646,
2863,
1068,
14,
793,
199,
504,
24380,
1733,
63,
795,
76,
492,
481,
199,
504,
24380,
1733,
63,
795,
76,
14,
1541,
492,
19287,
199,
199,
646,
21825,
199,
504,
21825,
14,
5559,
492,
19525,
63,
13313,
199,
504,
21825,
14,
5559,
14,
15853,
492,
11643,
63,
39,
7730,
33,
199,
504,
21825,
14,
32434,
14,
992,
492,
29366,
2398,
23481,
199,
504,
21825,
14,
1733,
14,
1080,
1192,
492,
3523,
32275,
199,
504,
21825,
14,
1733,
14,
1208,
492,
8730,
199,
504,
21825,
14,
2969,
14,
992,
492,
6554,
63,
2969,
199,
504,
21825,
14,
13982,
14,
992,
492,
6554,
63,
1515,
63,
807,
421,
199,
793,
275,
2863,
1068,
14,
793,
14,
5572,
360,
90,
14,
10788,
358,
421,
199,
533,
6001,
571,
32275,
8,
1563,
32275,
304,
272,
408,
7304,
781,
2793,
1133,
1929,
370,
23705,
315,
314,
2058,
12,
1454,
1202,
367,
14545,
272,
503,
13351,
1041,
272,
8752,
63,
955,
275,
334,
267,
11937,
1773,
297,
267,
6438,
63,
3191,
297,
267,
283,
1935,
22504,
63,
7693,
267,
283,
84,
828,
1098,
63,
7693,
267,
283,
15589,
297,
267,
283,
27169,
297,
267,
283,
3179,
297,
267,
327,
283,
354,
7,
436,
283,
1802,
297,
465,
5521,
465,
314,
5867,
21169,
12,
787,
1454,
267,
327,
1202,
367,
14545,
14,
710,
1504,
626,
787,
1202,
701,
314,
3261,
787,
267,
327,
283,
354,
63,
13982,
7,
436,
283,
1802,
63,
13982,
1370,
267,
283,
354,
297,
267,
283,
1802,
297,
267,
283,
354,
63,
76,
709,
78,
63,
7693,
267,
283,
1802,
63,
76,
709,
78,
63,
7693,
272,
776,
339,
408,
272,
699,
4689,
402,
10427,
8292,
367,
6001,
571,
2387,
13546,
12,
16356,
12,
2754,
14,
272,
408,
272,
768,
3744,
272,
347,
2754,
8,
1886,
12,
1808,
29,
403,
304,
267,
408,
267,
1803,
282,
658,
5278,
64,
909,
14,
398,
2136,
4278,
642,
370,
675,
4154,
19483,
1015,
1314,
9584,
5020,
68,
20542,
14,
267,
408,
267,
372,
334,
5278,
8,
288,
1808,
29,
4941,
503,
843,
14,
362,
63,
397,
1062,
1478,
29,
1886,
14,
362,
63,
1080,
1062,
288,
1382,
63,
466,
29,
1886,
14,
362,
63,
4745,
63,
466,
63,
354,
1012,
288,
1275,
2911,
1547,
1365,
3713,
5473,
356,
843,
14,
5642,
63,
955,
12466,
339,
768,
3744,
272,
347,
664,
63,
4745,
63,
466,
63,
354,
8,
1886,
304,
267,
408,
267,
1803,
4412,
730,
536,
1314,
365,
1202,
465,
314,
790,
315,
10427,
63,
10215,
654,
370,
267,
6705,
1314,
1478,
370,
675,
14,
398,
2136,
4278,
642,
2952,
6001,
571,
365,
282,
4566,
1402,
370,
29366,
14,
267,
408,
267,
372,
283,
22632,
7,
339,
768,
3744,
272,
347,
664,
63,
1238,
8,
1886,
304,
267,
687,
21825,
14,
2520,
5181,
14,
992,
492,
6001,
571,
267,
372,
6001,
571,
339,
768,
3744,
272,
347,
664,
63,
4745,
8,
1886,
304,
267,
1382,
63,
466,
275,
843,
14,
362,
63,
4745,
63,
466,
63,
354,
342,
398,
4412,
275,
469,
288,
1382,
63,
466,
26,
469,
355,
327,
17534,
485,
452,
901,
370,
7114,
1478,
1568,
14,
355,
2513,
452,
356,
791,
3827,
356,
756,
1386,
355,
283,
3282,
356,
469,
490,
327,
4693,
1504,
14,
490,
283,
344,
356,
791,
466,
356,
283,
2809,
2267,
490,
283,
571,
63,
5464,
356,
791,
466,
356,
283,
875,
2267,
490,
283,
571,
63,
466,
356,
791,
466,
356,
283,
4414,
2267,
490,
283,
2502,
356,
469,
717,
283,
466,
356,
283,
875,
297,
717,
283,
17965,
356,
283,
885,
63,
530,
85,
297,
717,
283,
955,
356,
469,
1169,
327,
2104,
5835,
4450,
14,
710,
3486,
24608,
6127,
1169,
327,
367,
1930,
13,
15851,
4877,
14,
1169,
283,
1773,
356,
791,
466,
356,
283,
875,
297,
2511,
283,
17965,
356,
283,
7327,
63,
21636,
2267,
717,
1660,
490,
1660,
490,
283,
13066,
63,
11963,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
19558,
69,
6214,
63,
10417,
356,
791,
466,
356,
283,
1609,
297,
283,
1301,
63,
1459,
356,
715,
1386,
490,
283,
3710,
356,
843,
14,
875,
63,
1397,
63,
4797,
7068,
1062,
490,
283,
1317,
63,
17752,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
1317,
63,
17565,
780,
356,
469,
717,
283,
466,
356,
283,
785,
297,
717,
283,
7764,
356,
283,
2052,
297,
490,
1660,
490,
283,
3966,
356,
791,
908,
356,
283,
602,
7012,
1366,
297,
283,
466,
356,
283,
602,
297,
1816,
283,
1301,
63,
1459,
356,
715,
1386,
490,
283,
1818,
63,
1023,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
885,
63,
5508,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
1802,
356,
791,
466,
356,
283,
875,
297,
2511,
283,
17965,
356,
283,
885,
63,
530,
85,
297,
2511,
283,
3124,
63,
2743,
63,
15046,
356,
2948,
1386,
490,
283,
1782,
356,
791,
466,
356,
283,
4414,
2267,
490,
327,
710,
1434,
642,
1145,
1990,
3483,
370,
314,
325,
4732,
425,
4126,
14,
490,
283,
397,
915,
425,
63,
602,
356,
791,
908,
356,
283,
602,
7012,
1366,
297,
3147,
283,
466,
356,
283,
602,
297,
283,
1301,
63,
1459,
356,
715,
1386,
490,
283,
3179,
356,
469,
717,
283,
466,
356,
283,
785,
297,
717,
283,
3282,
356,
1211,
8,
1169,
661,
1989,
4970,
83,
7,
450,
289,
14,
2325,
1062,
791,
466,
356,
283,
4871,
3071,
1169,
367,
289,
315,
19525,
63,
13313,
9,
490,
1660,
490,
283,
493,
63,
890,
356,
791,
466,
356,
283,
2809,
2267,
490,
283,
9473,
356,
843,
14,
875,
63,
1397,
63,
4797,
7068,
1062,
490,
283,
1989,
63,
3455,
63,
3200,
356,
791,
466,
356,
283,
4871,
2267,
490,
283,
4677,
63,
2227,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
13543,
63,
5527,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
3174,
83,
63,
6541,
63,
504,
356,
843,
14,
875,
63,
1397,
63,
4797,
7068,
1062,
490,
283,
374,
63,
7011,
356,
791,
466,
356
] |
[
4182,
492,
21829,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
697,
14,
992,
492,
10195,
199,
199,
646,
2863,
1068,
14,
793,
199,
504,
24380,
1733,
63,
795,
76,
492,
481,
199,
504,
24380,
1733,
63,
795,
76,
14,
1541,
492,
19287,
199,
199,
646,
21825,
199,
504,
21825,
14,
5559,
492,
19525,
63,
13313,
199,
504,
21825,
14,
5559,
14,
15853,
492,
11643,
63,
39,
7730,
33,
199,
504,
21825,
14,
32434,
14,
992,
492,
29366,
2398,
23481,
199,
504,
21825,
14,
1733,
14,
1080,
1192,
492,
3523,
32275,
199,
504,
21825,
14,
1733,
14,
1208,
492,
8730,
199,
504,
21825,
14,
2969,
14,
992,
492,
6554,
63,
2969,
199,
504,
21825,
14,
13982,
14,
992,
492,
6554,
63,
1515,
63,
807,
421,
199,
793,
275,
2863,
1068,
14,
793,
14,
5572,
360,
90,
14,
10788,
358,
421,
199,
533,
6001,
571,
32275,
8,
1563,
32275,
304,
272,
408,
7304,
781,
2793,
1133,
1929,
370,
23705,
315,
314,
2058,
12,
1454,
1202,
367,
14545,
272,
503,
13351,
1041,
272,
8752,
63,
955,
275,
334,
267,
11937,
1773,
297,
267,
6438,
63,
3191,
297,
267,
283,
1935,
22504,
63,
7693,
267,
283,
84,
828,
1098,
63,
7693,
267,
283,
15589,
297,
267,
283,
27169,
297,
267,
283,
3179,
297,
267,
327,
283,
354,
7,
436,
283,
1802,
297,
465,
5521,
465,
314,
5867,
21169,
12,
787,
1454,
267,
327,
1202,
367,
14545,
14,
710,
1504,
626,
787,
1202,
701,
314,
3261,
787,
267,
327,
283,
354,
63,
13982,
7,
436,
283,
1802,
63,
13982,
1370,
267,
283,
354,
297,
267,
283,
1802,
297,
267,
283,
354,
63,
76,
709,
78,
63,
7693,
267,
283,
1802,
63,
76,
709,
78,
63,
7693,
272,
776,
339,
408,
272,
699,
4689,
402,
10427,
8292,
367,
6001,
571,
2387,
13546,
12,
16356,
12,
2754,
14,
272,
408,
272,
768,
3744,
272,
347,
2754,
8,
1886,
12,
1808,
29,
403,
304,
267,
408,
267,
1803,
282,
658,
5278,
64,
909,
14,
398,
2136,
4278,
642,
370,
675,
4154,
19483,
1015,
1314,
9584,
5020,
68,
20542,
14,
267,
408,
267,
372,
334,
5278,
8,
288,
1808,
29,
4941,
503,
843,
14,
362,
63,
397,
1062,
1478,
29,
1886,
14,
362,
63,
1080,
1062,
288,
1382,
63,
466,
29,
1886,
14,
362,
63,
4745,
63,
466,
63,
354,
1012,
288,
1275,
2911,
1547,
1365,
3713,
5473,
356,
843,
14,
5642,
63,
955,
12466,
339,
768,
3744,
272,
347,
664,
63,
4745,
63,
466,
63,
354,
8,
1886,
304,
267,
408,
267,
1803,
4412,
730,
536,
1314,
365,
1202,
465,
314,
790,
315,
10427,
63,
10215,
654,
370,
267,
6705,
1314,
1478,
370,
675,
14,
398,
2136,
4278,
642,
2952,
6001,
571,
365,
282,
4566,
1402,
370,
29366,
14,
267,
408,
267,
372,
283,
22632,
7,
339,
768,
3744,
272,
347,
664,
63,
1238,
8,
1886,
304,
267,
687,
21825,
14,
2520,
5181,
14,
992,
492,
6001,
571,
267,
372,
6001,
571,
339,
768,
3744,
272,
347,
664,
63,
4745,
8,
1886,
304,
267,
1382,
63,
466,
275,
843,
14,
362,
63,
4745,
63,
466,
63,
354,
342,
398,
4412,
275,
469,
288,
1382,
63,
466,
26,
469,
355,
327,
17534,
485,
452,
901,
370,
7114,
1478,
1568,
14,
355,
2513,
452,
356,
791,
3827,
356,
756,
1386,
355,
283,
3282,
356,
469,
490,
327,
4693,
1504,
14,
490,
283,
344,
356,
791,
466,
356,
283,
2809,
2267,
490,
283,
571,
63,
5464,
356,
791,
466,
356,
283,
875,
2267,
490,
283,
571,
63,
466,
356,
791,
466,
356,
283,
4414,
2267,
490,
283,
2502,
356,
469,
717,
283,
466,
356,
283,
875,
297,
717,
283,
17965,
356,
283,
885,
63,
530,
85,
297,
717,
283,
955,
356,
469,
1169,
327,
2104,
5835,
4450,
14,
710,
3486,
24608,
6127,
1169,
327,
367,
1930,
13,
15851,
4877,
14,
1169,
283,
1773,
356,
791,
466,
356,
283,
875,
297,
2511,
283,
17965,
356,
283,
7327,
63,
21636,
2267,
717,
1660,
490,
1660,
490,
283,
13066,
63,
11963,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
19558,
69,
6214,
63,
10417,
356,
791,
466,
356,
283,
1609,
297,
283,
1301,
63,
1459,
356,
715,
1386,
490,
283,
3710,
356,
843,
14,
875,
63,
1397,
63,
4797,
7068,
1062,
490,
283,
1317,
63,
17752,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
1317,
63,
17565,
780,
356,
469,
717,
283,
466,
356,
283,
785,
297,
717,
283,
7764,
356,
283,
2052,
297,
490,
1660,
490,
283,
3966,
356,
791,
908,
356,
283,
602,
7012,
1366,
297,
283,
466,
356,
283,
602,
297,
1816,
283,
1301,
63,
1459,
356,
715,
1386,
490,
283,
1818,
63,
1023,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
885,
63,
5508,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
1802,
356,
791,
466,
356,
283,
875,
297,
2511,
283,
17965,
356,
283,
885,
63,
530,
85,
297,
2511,
283,
3124,
63,
2743,
63,
15046,
356,
2948,
1386,
490,
283,
1782,
356,
791,
466,
356,
283,
4414,
2267,
490,
327,
710,
1434,
642,
1145,
1990,
3483,
370,
314,
325,
4732,
425,
4126,
14,
490,
283,
397,
915,
425,
63,
602,
356,
791,
908,
356,
283,
602,
7012,
1366,
297,
3147,
283,
466,
356,
283,
602,
297,
283,
1301,
63,
1459,
356,
715,
1386,
490,
283,
3179,
356,
469,
717,
283,
466,
356,
283,
785,
297,
717,
283,
3282,
356,
1211,
8,
1169,
661,
1989,
4970,
83,
7,
450,
289,
14,
2325,
1062,
791,
466,
356,
283,
4871,
3071,
1169,
367,
289,
315,
19525,
63,
13313,
9,
490,
1660,
490,
283,
493,
63,
890,
356,
791,
466,
356,
283,
2809,
2267,
490,
283,
9473,
356,
843,
14,
875,
63,
1397,
63,
4797,
7068,
1062,
490,
283,
1989,
63,
3455,
63,
3200,
356,
791,
466,
356,
283,
4871,
2267,
490,
283,
4677,
63,
2227,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
13543,
63,
5527,
356,
843,
14,
875,
63,
1397,
63,
16821,
1062,
490,
283,
3174,
83,
63,
6541,
63,
504,
356,
843,
14,
875,
63,
1397,
63,
4797,
7068,
1062,
490,
283,
374,
63,
7011,
356,
791,
466,
356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tobykurien/MakerDroid
|
assetsrc/public.mp3/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/gts.py
|
1
|
4561
|
"""
This page is in the table of contents.
The gts.py script is an import translator plugin to get a carving from an gts file.
An import plugin is a script in the interpret_plugins folder which has the function getCarving. It is meant to be run from the interpret tool. To ensure that the plugin works on platforms which do not handle file capitalization properly, give the plugin a lower case name.
The getCarving function takes the file name of an gts file and returns the carving.
The GNU Triangulated Surface (.gts) format is described at:
http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE
Quoted from http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE
"All the lines beginning with GTS_COMMENTS (#!) are ignored. The first line contains three unsigned integers separated by spaces. The first integer is the number of vertices, nv, the second is the number of edges, ne and the third is the number of faces, nf.
Follows nv lines containing the x, y and z coordinates of the vertices. Follows ne lines containing the two indices (starting from one) of the vertices of each edge. Follows nf lines containing the three ordered indices (also starting from one) of the edges of each face.
The format described above is the least common denominator to all GTS files. Consistent with an object-oriented approach, the GTS file format is extensible. Each of the lines of the file can be extended with user-specific attributes accessible through the read() and write() virtual methods of each of the objects written (surface, vertices, edges or faces). When read with different object classes, these extra attributes are just ignored."
This example gets a carving for the gts file Screw Holder Bottom.gts. This example is run in a terminal in the folder which contains Screw Holder Bottom.gts and gts.py.
> python
Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gts
>>> gts.getCarving()
[11.6000003815, 10.6837882996, 7.80209827423
..
many more lines of the carving
..
"""
from __future__ import absolute_import
#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
import __init__
from fabmetheus_utilities.vector3 import Vector3
from fabmetheus_utilities import gcodec
from fabmetheus_utilities.solids import triangle_mesh
__author__ = "Enrique Perez (perez_enrique@yahoo.com)"
__credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>'
__date__ = "$Date: 2008/21/04 $"
__license__ = "GPL 3.0"
def getFromGNUTriangulatedSurfaceText( gnuTriangulatedSurfaceText, triangleMesh ):
"Initialize from a GNU Triangulated Surface Text."
if gnuTriangulatedSurfaceText == '':
return None
lines = gcodec.getTextLines( gnuTriangulatedSurfaceText )
linesWithoutComments = []
for line in lines:
if len( line ) > 0:
firstCharacter = line[ 0 ]
if firstCharacter != '#' and firstCharacter != '!':
linesWithoutComments.append( line )
splitLine = linesWithoutComments[ 0 ].split()
numberOfVertices = int( splitLine[ 0 ] )
numberOfEdges = int( splitLine[ 1 ] )
numberOfFaces = int( splitLine[ 2 ] )
faceTriples = []
for vertexIndex in xrange( numberOfVertices ):
line = linesWithoutComments[ vertexIndex + 1 ]
splitLine = line.split()
vertex = Vector3( float( splitLine[ 0 ] ), float( splitLine[ 1 ] ), float( splitLine[ 2 ] ) )
triangleMesh.vertices.append( vertex )
edgeStart = numberOfVertices + 1
for edgeIndex in xrange( numberOfEdges ):
line = linesWithoutComments[ edgeIndex + edgeStart ]
splitLine = line.split()
vertexIndexes = []
for word in splitLine[ : 2 ]:
vertexIndexes.append( int( word ) - 1 )
edge = triangle_mesh.Edge().getFromVertexIndexes( edgeIndex, vertexIndexes )
triangleMesh.edges.append( edge )
faceStart = edgeStart + numberOfEdges
for faceIndex in xrange( numberOfFaces ):
line = linesWithoutComments[ faceIndex + faceStart ]
splitLine = line.split()
edgeIndexes = []
for word in splitLine[ : 3 ]:
edgeIndexes.append( int( word ) - 1 )
face = triangle_mesh.Face().getFromEdgeIndexes( edgeIndexes, triangleMesh.edges, faceIndex )
triangleMesh.faces.append( face )
return triangleMesh
def getCarving( fileName ):
"Get the carving for the gts file."
return getFromGNUTriangulatedSurfaceText( gcodec.getFileText( fileName ), triangle_mesh.TriangleMesh() )
|
gpl-3.0
|
[
624,
199,
2765,
2034,
365,
315,
314,
1817,
402,
4072,
14,
199,
1918,
486,
1086,
14,
647,
2884,
365,
376,
492,
32034,
3589,
370,
664,
282,
9590,
4007,
687,
376,
486,
1086,
570,
14,
199,
199,
2493,
492,
3589,
365,
282,
2884,
315,
314,
15579,
63,
5265,
4922,
1314,
965,
314,
805,
664,
16034,
4007,
14,
221,
2779,
365,
18329,
370,
506,
1255,
687,
314,
15579,
4744,
14,
221,
4005,
4868,
626,
314,
3589,
5419,
641,
10677,
1314,
886,
440,
2429,
570,
17094,
2072,
7684,
12,
8120,
314,
3589,
282,
5117,
1930,
536,
14,
199,
199,
1918,
664,
16034,
4007,
805,
6181,
314,
570,
536,
402,
376,
486,
1086,
570,
436,
2529,
314,
9590,
4007,
14,
199,
199,
1918,
1664,
12480,
621,
8097,
29564,
17048,
71,
1086,
9,
1475,
365,
11736,
737,
26,
199,
1014,
921,
71,
1086,
14,
22943,
14,
846,
15,
4443,
15,
71,
1086,
13,
5105,
4309,
14,
1360,
3,
8391,
51,
13,
51,
1230,
13199,
13,
10387,
199,
199,
24115,
687,
1455,
921,
71,
1086,
14,
22943,
14,
846,
15,
4443,
15,
71,
1086,
13,
5105,
4309,
14,
1360,
3,
8391,
51,
13,
51,
1230,
13199,
13,
10387,
199,
2,
2422,
314,
2385,
9608,
543,
598,
9730,
63,
10973,
51,
334,
3168,
9,
787,
5525,
14,
710,
1642,
1004,
3509,
7795,
7381,
9446,
11673,
701,
7883,
14,
710,
1642,
3000,
365,
314,
1329,
402,
14971,
12,
26510,
12,
314,
3499,
365,
314,
1329,
402,
8207,
12,
1279,
436,
314,
10919,
365,
314,
1329,
402,
21143,
12,
302,
70,
14,
199,
199,
18696,
83,
26510,
2385,
3035,
314,
671,
12,
612,
436,
1315,
8983,
402,
314,
14971,
14,
21876,
83,
1279,
2385,
3035,
314,
2877,
4918,
334,
15769,
687,
1373,
9,
402,
314,
14971,
402,
1924,
6275,
14,
21876,
83,
302,
70,
2385,
3035,
314,
7795,
7741,
4918,
334,
12344,
6617,
687,
1373,
9,
402,
314,
8207,
402,
1924,
8870,
14,
199,
199,
1918,
1475,
11736,
3432,
365,
314,
5210,
2863,
21859,
370,
1006,
598,
9730,
1584,
14,
1448,
6082,
543,
376,
909,
13,
16039,
287,
471,
18140,
12,
314,
598,
9730,
570,
1475,
365,
2178,
1164,
14,
7048,
402,
314,
2385,
402,
314,
570,
883,
506,
9243,
543,
922,
13,
6100,
3004,
17909,
4012,
314,
1586,
342,
436,
2218,
342,
5791,
3102,
402,
1924,
402,
314,
2251,
5313,
334,
10992,
12,
14971,
12,
8207,
503,
21143,
680,
3979,
1586,
543,
3365,
909,
3992,
12,
3520,
2402,
3004,
787,
2951,
5525,
2122,
199,
199,
2765,
2893,
7545,
282,
9590,
4007,
367,
314,
486,
1086,
570,
428,
1353,
87,
869,
2149,
24896,
3151,
14,
71,
1086,
14,
221,
961,
2893,
365,
1255,
315,
282,
11167,
315,
314,
4922,
1314,
3509,
428,
1353,
87,
869,
2149,
24896,
3151,
14,
71,
1086,
436,
486,
1086,
14,
647,
14,
421,
199,
30,
2366,
199,
4718,
499,
14,
21,
14,
17,
334,
82,
12140,
26,
1477,
15887,
12,
428,
1545,
6928,
10219,
12,
17163,
26,
2824,
26,
2192,
9,
199,
59,
10566,
841,
14,
18,
14,
17,
334,
51,
4701,
10130,
1874,
641,
18369,
18,
199,
804,
298,
3437,
401,
298,
7307,
401,
298,
22461,
2,
503,
298,
1682,
2,
367,
1655,
2556,
14,
199,
6071,
492,
486,
1086,
199,
6071,
486,
1086,
14,
362,
16034,
4007,
342,
199,
59,
845,
14,
22,
993,
14273,
1046,
12,
1616,
14,
2333,
1401,
1299,
10488,
22,
12,
1520,
14,
11366,
1643,
2564,
1342,
1789,
199,
703,
199,
3479,
1655,
2385,
402,
314,
9590,
4007,
199,
703,
199,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
3,
9346,
965,
370,
506,
8439,
1642,
2952,
652,
965,
1233,
370,
18092,
314,
2366,
6519,
2382,
3847,
8925,
2793,
1133,
1736,
340,
314,
859,
365,
8439,
465,
282,
2446,
859,
14,
199,
646,
636,
826,
363,
199,
199,
504,
31507,
278,
32761,
63,
16355,
14,
4106,
19,
492,
11388,
19,
199,
504,
31507,
278,
32761,
63,
16355,
492,
486,
9276,
199,
504,
31507,
278,
32761,
63,
16355,
14,
28335,
795,
492,
26268,
63,
6480,
199,
199,
363,
2502,
363,
275,
298,
1327,
322,
544,
11379,
25409,
334,
321,
25409,
63,
287,
322,
544,
32,
27231,
14,
957,
2924,
199,
363,
22461,
363,
275,
283,
46,
411,
2993,
665,
1014,
921,
3577,
5012,
285,
6182,
269,
14,
66,
7270,
14173,
14,
957,
15,
3072,
78,
28922,
402,
473,
914,
12444,
665,
1014,
921,
1544,
14,
285,
475,
4498,
12444,
14,
1308,
3133,
7,
199,
363,
602,
363,
275,
7880,
2506,
26,
9079,
15,
2025,
15,
966,
2672,
2,
199,
363,
1682,
363,
275,
298,
12006,
650,
14,
16,
2,
421,
199,
318,
664,
2532,
15306,
934,
322,
621,
8097,
16923,
1872,
8,
486,
4850,
6948,
621,
8097,
16923,
1872,
12,
26268,
12241,
3461,
199,
198,
2,
9345,
687,
282,
1664,
12480,
621,
8097,
29564,
4516,
2122,
199,
198,
692,
486,
4850,
6948,
621,
8097,
16923,
1872,
508,
8061,
507,
198,
1107,
488,
199,
198,
1278,
275,
486,
9276,
14,
25506,
9863,
8,
486,
4850,
6948,
621,
8097,
16923,
1872,
776,
199,
198,
1278,
12450,
18929,
275,
942,
199,
198,
509,
1004,
315,
2385,
26,
507,
198,
692,
822,
8,
1004,
776,
690,
378,
26,
686,
198,
2246,
14852,
275,
1004,
59,
378,
1622,
686,
198,
692,
1642,
14852,
1137,
19619,
436,
1642,
14852,
1137,
14597,
356,
1585,
198,
1278,
12450,
18929,
14,
740,
8,
1004,
776,
199,
198,
1294,
3049,
275,
2385,
12450,
18929,
59,
378,
221,
1055,
1294,
342,
199,
198,
23922,
30972,
275,
1109,
8,
3715,
3049,
59,
378,
1622,
776,
199,
198,
23922,
24121,
275,
1109,
8,
3715,
3049,
59,
413,
1622,
776,
199,
198,
23922,
1906,
823,
275,
1109,
8,
3715,
3049,
59,
499,
1622,
776,
199,
198,
1409,
32220,
2978,
275,
942,
199,
198,
509,
12759,
2681,
315,
4945,
8,
28127,
30972,
3461,
507,
198,
604,
275,
2385,
12450,
18929,
59,
12759,
2681,
435,
413,
1622,
507,
198,
1294,
3049,
275,
1004,
14,
1294,
342,
507,
198,
11417,
275,
11388,
19,
8,
2069,
8,
3715,
3049,
59,
378,
1622,
2318,
2069,
8,
3715,
3049,
59,
413,
1622,
2318,
2069,
8,
3715,
3049,
59,
499,
1622,
776,
776,
507,
198,
21584,
12241,
14,
12637,
14,
740,
8,
12759,
776,
199,
198,
5173,
3162,
275
] |
[
199,
2765,
2034,
365,
315,
314,
1817,
402,
4072,
14,
199,
1918,
486,
1086,
14,
647,
2884,
365,
376,
492,
32034,
3589,
370,
664,
282,
9590,
4007,
687,
376,
486,
1086,
570,
14,
199,
199,
2493,
492,
3589,
365,
282,
2884,
315,
314,
15579,
63,
5265,
4922,
1314,
965,
314,
805,
664,
16034,
4007,
14,
221,
2779,
365,
18329,
370,
506,
1255,
687,
314,
15579,
4744,
14,
221,
4005,
4868,
626,
314,
3589,
5419,
641,
10677,
1314,
886,
440,
2429,
570,
17094,
2072,
7684,
12,
8120,
314,
3589,
282,
5117,
1930,
536,
14,
199,
199,
1918,
664,
16034,
4007,
805,
6181,
314,
570,
536,
402,
376,
486,
1086,
570,
436,
2529,
314,
9590,
4007,
14,
199,
199,
1918,
1664,
12480,
621,
8097,
29564,
17048,
71,
1086,
9,
1475,
365,
11736,
737,
26,
199,
1014,
921,
71,
1086,
14,
22943,
14,
846,
15,
4443,
15,
71,
1086,
13,
5105,
4309,
14,
1360,
3,
8391,
51,
13,
51,
1230,
13199,
13,
10387,
199,
199,
24115,
687,
1455,
921,
71,
1086,
14,
22943,
14,
846,
15,
4443,
15,
71,
1086,
13,
5105,
4309,
14,
1360,
3,
8391,
51,
13,
51,
1230,
13199,
13,
10387,
199,
2,
2422,
314,
2385,
9608,
543,
598,
9730,
63,
10973,
51,
334,
3168,
9,
787,
5525,
14,
710,
1642,
1004,
3509,
7795,
7381,
9446,
11673,
701,
7883,
14,
710,
1642,
3000,
365,
314,
1329,
402,
14971,
12,
26510,
12,
314,
3499,
365,
314,
1329,
402,
8207,
12,
1279,
436,
314,
10919,
365,
314,
1329,
402,
21143,
12,
302,
70,
14,
199,
199,
18696,
83,
26510,
2385,
3035,
314,
671,
12,
612,
436,
1315,
8983,
402,
314,
14971,
14,
21876,
83,
1279,
2385,
3035,
314,
2877,
4918,
334,
15769,
687,
1373,
9,
402,
314,
14971,
402,
1924,
6275,
14,
21876,
83,
302,
70,
2385,
3035,
314,
7795,
7741,
4918,
334,
12344,
6617,
687,
1373,
9,
402,
314,
8207,
402,
1924,
8870,
14,
199,
199,
1918,
1475,
11736,
3432,
365,
314,
5210,
2863,
21859,
370,
1006,
598,
9730,
1584,
14,
1448,
6082,
543,
376,
909,
13,
16039,
287,
471,
18140,
12,
314,
598,
9730,
570,
1475,
365,
2178,
1164,
14,
7048,
402,
314,
2385,
402,
314,
570,
883,
506,
9243,
543,
922,
13,
6100,
3004,
17909,
4012,
314,
1586,
342,
436,
2218,
342,
5791,
3102,
402,
1924,
402,
314,
2251,
5313,
334,
10992,
12,
14971,
12,
8207,
503,
21143,
680,
3979,
1586,
543,
3365,
909,
3992,
12,
3520,
2402,
3004,
787,
2951,
5525,
2122,
199,
199,
2765,
2893,
7545,
282,
9590,
4007,
367,
314,
486,
1086,
570,
428,
1353,
87,
869,
2149,
24896,
3151,
14,
71,
1086,
14,
221,
961,
2893,
365,
1255,
315,
282,
11167,
315,
314,
4922,
1314,
3509,
428,
1353,
87,
869,
2149,
24896,
3151,
14,
71,
1086,
436,
486,
1086,
14,
647,
14,
421,
199,
30,
2366,
199,
4718,
499,
14,
21,
14,
17,
334,
82,
12140,
26,
1477,
15887,
12,
428,
1545,
6928,
10219,
12,
17163,
26,
2824,
26,
2192,
9,
199,
59,
10566,
841,
14,
18,
14,
17,
334,
51,
4701,
10130,
1874,
641,
18369,
18,
199,
804,
298,
3437,
401,
298,
7307,
401,
298,
22461,
2,
503,
298,
1682,
2,
367,
1655,
2556,
14,
199,
6071,
492,
486,
1086,
199,
6071,
486,
1086,
14,
362,
16034,
4007,
342,
199,
59,
845,
14,
22,
993,
14273,
1046,
12,
1616,
14,
2333,
1401,
1299,
10488,
22,
12,
1520,
14,
11366,
1643,
2564,
1342,
1789,
199,
703,
199,
3479,
1655,
2385,
402,
314,
9590,
4007,
199,
703,
199,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
3,
9346,
965,
370,
506,
8439,
1642,
2952,
652,
965,
1233,
370,
18092,
314,
2366,
6519,
2382,
3847,
8925,
2793,
1133,
1736,
340,
314,
859,
365,
8439,
465,
282,
2446,
859,
14,
199,
646,
636,
826,
363,
199,
199,
504,
31507,
278,
32761,
63,
16355,
14,
4106,
19,
492,
11388,
19,
199,
504,
31507,
278,
32761,
63,
16355,
492,
486,
9276,
199,
504,
31507,
278,
32761,
63,
16355,
14,
28335,
795,
492,
26268,
63,
6480,
199,
199,
363,
2502,
363,
275,
298,
1327,
322,
544,
11379,
25409,
334,
321,
25409,
63,
287,
322,
544,
32,
27231,
14,
957,
2924,
199,
363,
22461,
363,
275,
283,
46,
411,
2993,
665,
1014,
921,
3577,
5012,
285,
6182,
269,
14,
66,
7270,
14173,
14,
957,
15,
3072,
78,
28922,
402,
473,
914,
12444,
665,
1014,
921,
1544,
14,
285,
475,
4498,
12444,
14,
1308,
3133,
7,
199,
363,
602,
363,
275,
7880,
2506,
26,
9079,
15,
2025,
15,
966,
2672,
2,
199,
363,
1682,
363,
275,
298,
12006,
650,
14,
16,
2,
421,
199,
318,
664,
2532,
15306,
934,
322,
621,
8097,
16923,
1872,
8,
486,
4850,
6948,
621,
8097,
16923,
1872,
12,
26268,
12241,
3461,
199,
198,
2,
9345,
687,
282,
1664,
12480,
621,
8097,
29564,
4516,
2122,
199,
198,
692,
486,
4850,
6948,
621,
8097,
16923,
1872,
508,
8061,
507,
198,
1107,
488,
199,
198,
1278,
275,
486,
9276,
14,
25506,
9863,
8,
486,
4850,
6948,
621,
8097,
16923,
1872,
776,
199,
198,
1278,
12450,
18929,
275,
942,
199,
198,
509,
1004,
315,
2385,
26,
507,
198,
692,
822,
8,
1004,
776,
690,
378,
26,
686,
198,
2246,
14852,
275,
1004,
59,
378,
1622,
686,
198,
692,
1642,
14852,
1137,
19619,
436,
1642,
14852,
1137,
14597,
356,
1585,
198,
1278,
12450,
18929,
14,
740,
8,
1004,
776,
199,
198,
1294,
3049,
275,
2385,
12450,
18929,
59,
378,
221,
1055,
1294,
342,
199,
198,
23922,
30972,
275,
1109,
8,
3715,
3049,
59,
378,
1622,
776,
199,
198,
23922,
24121,
275,
1109,
8,
3715,
3049,
59,
413,
1622,
776,
199,
198,
23922,
1906,
823,
275,
1109,
8,
3715,
3049,
59,
499,
1622,
776,
199,
198,
1409,
32220,
2978,
275,
942,
199,
198,
509,
12759,
2681,
315,
4945,
8,
28127,
30972,
3461,
507,
198,
604,
275,
2385,
12450,
18929,
59,
12759,
2681,
435,
413,
1622,
507,
198,
1294,
3049,
275,
1004,
14,
1294,
342,
507,
198,
11417,
275,
11388,
19,
8,
2069,
8,
3715,
3049,
59,
378,
1622,
2318,
2069,
8,
3715,
3049,
59,
413,
1622,
2318,
2069,
8,
3715,
3049,
59,
499,
1622,
776,
776,
507,
198,
21584,
12241,
14,
12637,
14,
740,
8,
12759,
776,
199,
198,
5173,
3162,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
DarkFenX/Pyfa
|
eos/saveddata/targetProfile.py
|
1
|
20115
|
# ===============================================================================
# Copyright (C) 2014 Ryan Holmes
#
# This file is part of eos.
#
# eos is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# eos 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 eos. If not, see <http://www.gnu.org/licenses/>.
# ===============================================================================
import math
import re
from collections import OrderedDict
from logbook import Logger
from sqlalchemy.orm import reconstructor
import eos.db
pyfalog = Logger(__name__)
BUILTINS = OrderedDict([
# 0 is taken by ideal target profile, composed manually in one of TargetProfile methods
(-1, ('Uniform (25%)', 0.25, 0.25, 0.25, 0.25)),
(-2, ('Uniform (50%)', 0.50, 0.50, 0.50, 0.50)),
(-3, ('Uniform (75%)', 0.75, 0.75, 0.75, 0.75)),
(-4, ('Uniform (90%)', 0.90, 0.90, 0.90, 0.90)),
(-5, ('[T1 Resist]Shield', 0.0, 0.20, 0.40, 0.50)),
(-6, ('[T1 Resist]Armor', 0.50, 0.45, 0.25, 0.10)),
(-7, ('[T1 Resist]Hull', 0.33, 0.33, 0.33, 0.33)),
(-8, ('[T1 Resist]Shield (+T2 DCU)', 0.125, 0.30, 0.475, 0.562)),
(-9, ('[T1 Resist]Armor (+T2 DCU)', 0.575, 0.532, 0.363, 0.235)),
(-10, ('[T1 Resist]Hull (+T2 DCU)', 0.598, 0.598, 0.598, 0.598)),
(-11, ('[T2 Resist]Amarr (Shield)', 0.0, 0.20, 0.70, 0.875)),
(-12, ('[T2 Resist]Amarr (Armor)', 0.50, 0.35, 0.625, 0.80)),
(-13, ('[T2 Resist]Caldari (Shield)', 0.20, 0.84, 0.76, 0.60)),
(-14, ('[T2 Resist]Caldari (Armor)', 0.50, 0.8625, 0.625, 0.10)),
(-15, ('[T2 Resist]Gallente (Shield)', 0.0, 0.60, 0.85, 0.50)),
(-16, ('[T2 Resist]Gallente (Armor)', 0.50, 0.675, 0.8375, 0.10)),
(-17, ('[T2 Resist]Minmatar (Shield)', 0.75, 0.60, 0.40, 0.50)),
(-18, ('[T2 Resist]Minmatar (Armor)', 0.90, 0.675, 0.25, 0.10)),
(-19, ('[NPC][Asteroid]Angel Cartel', 0.54, 0.42, 0.37, 0.32)),
(-20, ('[NPC][Asteroid]Blood Raiders', 0.34, 0.39, 0.45, 0.52)),
(-21, ('[NPC][Asteroid]Guristas', 0.55, 0.35, 0.3, 0.48)),
(-22, ('[NPC][Asteroid]Rogue Drones', 0.35, 0.38, 0.44, 0.49)),
(-23, ('[NPC][Asteroid]Sanshas Nation', 0.35, 0.4, 0.47, 0.53)),
(-24, ('[NPC][Asteroid]Serpentis', 0.49, 0.38, 0.29, 0.51)),
(-25, ('[NPC][Deadspace]Angel Cartel', 0.59, 0.48, 0.4, 0.32)),
(-26, ('[NPC][Deadspace]Blood Raiders', 0.31, 0.39, 0.47, 0.56)),
(-27, ('[NPC][Deadspace]Guristas', 0.57, 0.39, 0.31, 0.5)),
(-28, ('[NPC][Deadspace]Rogue Drones', 0.42, 0.42, 0.47, 0.49)),
(-29, ('[NPC][Deadspace]Sanshas Nation', 0.31, 0.39, 0.47, 0.56)),
(-30, ('[NPC][Deadspace]Serpentis', 0.49, 0.38, 0.29, 0.56)),
(-31, ('[NPC][Mission]Amarr Empire', 0.34, 0.38, 0.42, 0.46)),
(-32, ('[NPC][Mission]Caldari State', 0.51, 0.38, 0.3, 0.51)),
(-33, ('[NPC][Mission]CONCORD', 0.47, 0.46, 0.47, 0.47)),
(-34, ('[NPC][Mission]Gallente Federation', 0.51, 0.38, 0.31, 0.52)),
(-35, ('[NPC][Mission]Khanid', 0.51, 0.42, 0.36, 0.4)),
(-36, ('[NPC][Mission]Minmatar Republic', 0.51, 0.46, 0.41, 0.35)),
(-37, ('[NPC][Mission]Mordus Legion', 0.32, 0.48, 0.4, 0.62)),
(-38, ('[NPC][Other]Sleeper', 0.61, 0.61, 0.61, 0.61)),
(-39, ('[NPC][Other]Sansha Incursion', 0.65, 0.63, 0.64, 0.65)),
(-40, ('[NPC][Burner]Cruor (Blood Raiders)', 0.8, 0.73, 0.69, 0.67)),
(-41, ('[NPC][Burner]Dramiel (Angel)', 0.35, 0.48, 0.61, 0.68)),
(-42, ('[NPC][Burner]Daredevil (Serpentis)', 0.69, 0.59, 0.59, 0.43)),
(-43, ('[NPC][Burner]Succubus (Sanshas Nation)', 0.35, 0.48, 0.61, 0.68)),
(-44, ('[NPC][Burner]Worm (Guristas)', 0.48, 0.58, 0.69, 0.74)),
(-45, ('[NPC][Burner]Enyo', 0.58, 0.72, 0.86, 0.24)),
(-46, ('[NPC][Burner]Hawk', 0.3, 0.86, 0.79, 0.65)),
(-47, ('[NPC][Burner]Jaguar', 0.78, 0.65, 0.48, 0.56)),
(-48, ('[NPC][Burner]Vengeance', 0.66, 0.56, 0.75, 0.86)),
(-49, ('[NPC][Burner]Ashimmu (Blood Raiders)', 0.8, 0.76, 0.68, 0.7)),
(-50, ('[NPC][Burner]Talos', 0.68, 0.59, 0.59, 0.43)),
(-51, ('[NPC][Burner]Sentinel', 0.58, 0.45, 0.52, 0.66)),
# Source: ticket #2067
(-52, ('[NPC][Invasion]Invading Precursor Entities', 0.422, 0.367, 0.453, 0.411)),
(-53, ('[NPC][Invasion]Retaliating Amarr Entities', 0.360, 0.310, 0.441, 0.602)),
(-54, ('[NPC][Invasion]Retaliating Caldari Entities', 0.287, 0.610, 0.487, 0.401)),
(-55, ('[NPC][Invasion]Retaliating Gallente Entities', 0.383, 0.414, 0.578, 0.513)),
(-56, ('[NPC][Invasion]Retaliating Minmatar Entities', 0.620, 0.422, 0.355, 0.399)),
(-57, ('[NPC][Abyssal][Dark Matter All Tiers]Drones', 0.439, 0.522, 0.529, 0.435)),
(-58, ('[NPC][Abyssal][Dark Matter All Tiers]Overmind', 0.626, 0.576, 0.612, 0.624)),
(-59, ('[NPC][Abyssal][Dark Matter All Tiers]Seeker', 0.082, 0.082, 0.082, 0.082)),
(-60, ('[NPC][Abyssal][Dark Matter All Tiers]Triglavian', 0.477, 0.401, 0.449, 0.37)),
(-61, ('[NPC][Abyssal][Dark Matter All Tiers]Drifter', 0.403, 0.403, 0.403, 0.403)),
(-62, ('[NPC][Abyssal][Dark Matter All Tiers]Sleeper', 0.435, 0.435, 0.435, 0.435)),
(-63, ('[NPC][Abyssal][Dark Matter All Tiers]All', 0.507, 0.477, 0.502, 0.493)),
(-64, ('[NPC][Abyssal][Electrical T1/T2]Drones', 0.323, 0.522, 0.529, 0.435)),
(-65, ('[NPC][Abyssal][Electrical T1/T2]Overmind', 0.521, 0.576, 0.612, 0.624)),
(-66, ('[NPC][Abyssal][Electrical T1/T2]Seeker', 0, 0.082, 0.082, 0.082)),
(-67, ('[NPC][Abyssal][Electrical T1/T2]Triglavian', 0.333, 0.401, 0.449, 0.37)),
(-68, ('[NPC][Abyssal][Electrical T1/T2]Drifter', 0.267, 0.403, 0.403, 0.403)),
(-69, ('[NPC][Abyssal][Electrical T1/T2]Sleeper', 0.329, 0.435, 0.435, 0.435)),
(-70, ('[NPC][Abyssal][Electrical T1/T2]All', 0.385, 0.477, 0.502, 0.493)),
(-71, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]Drones', 0.255, 0.522, 0.529, 0.435)),
(-72, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]Overmind', 0.457, 0.576, 0.612, 0.624)),
(-73, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]Seeker', 0, 0.082, 0.082, 0.082)),
(-74, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]Triglavian', 0.241, 0.401, 0.449, 0.37)),
(-75, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]Drifter', 0.184, 0.403, 0.403, 0.403)),
(-76, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]Sleeper', 0.268, 0.435, 0.435, 0.435)),
(-77, ('[NPC][Abyssal][Electrical T3 (Some T5 Rooms)]All', 0.313, 0.477, 0.502, 0.493)),
(-78, ('[NPC][Abyssal][Electrical T4/T5]Drones', 0.193, 0.522, 0.529, 0.435)),
(-79, ('[NPC][Abyssal][Electrical T4/T5]Overmind', 0.398, 0.576, 0.612, 0.624)),
(-80, ('[NPC][Abyssal][Electrical T4/T5]Seeker', 0, 0.082, 0.082, 0.082)),
(-81, ('[NPC][Abyssal][Electrical T4/T5]Triglavian', 0.183, 0.401, 0.449, 0.37)),
(-82, ('[NPC][Abyssal][Electrical T4/T5]Drifter', 0.107, 0.403, 0.403, 0.403)),
(-83, ('[NPC][Abyssal][Electrical T4/T5]Sleeper', 0.215, 0.435, 0.435, 0.435)),
(-84, ('[NPC][Abyssal][Electrical T4/T5]All', 0.25, 0.477, 0.502, 0.493)),
(-85, ('[NPC][Abyssal][Firestorm T1/T2]Drones', 0.461, 0.425, 0.541, 0.443)),
(-86, ('[NPC][Abyssal][Firestorm T1/T2]Overmind', 0.65, 0.469, 0.625, 0.633)),
(-87, ('[NPC][Abyssal][Firestorm T1/T2]Seeker', 0.084, 0, 0.084, 0.084)),
(-88, ('[NPC][Abyssal][Firestorm T1/T2]Triglavian', 0.534, 0.266, 0.484, 0.366)),
(-89, ('[NPC][Abyssal][Firestorm T1/T2]Drifter', 0.422, 0.282, 0.422, 0.422)),
(-90, ('[NPC][Abyssal][Firestorm T1/T2]Sleeper', 0.512, 0.402, 0.512, 0.512)),
(-91, ('[NPC][Abyssal][Firestorm T1/T2]All', 0.541, 0.365, 0.524, 0.504)),
(-92, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]Drones', 0.461, 0.36, 0.541, 0.443)),
(-93, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]Overmind', 0.65, 0.391, 0.625, 0.633)),
(-94, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]Seeker', 0.084, 0, 0.084, 0.084)),
(-95, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]Triglavian', 0.534, 0.161, 0.484, 0.366)),
(-96, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]Drifter', 0.422, 0.196, 0.422, 0.422)),
(-97, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]Sleeper', 0.512, 0.337, 0.512, 0.512)),
(-98, ('[NPC][Abyssal][Firestorm T3 (Some T5 Rooms)]All', 0.541, 0.284, 0.524, 0.504)),
(-99, ('[NPC][Abyssal][Firestorm T4/T5]Drones', 0.461, 0.305, 0.541, 0.443)),
(-100, ('[NPC][Abyssal][Firestorm T4/T5]Overmind', 0.65, 0.323, 0.625, 0.633)),
(-101, ('[NPC][Abyssal][Firestorm T4/T5]Seeker', 0.084, 0, 0.084, 0.084)),
(-102, ('[NPC][Abyssal][Firestorm T4/T5]Triglavian', 0.534, 0.082, 0.484, 0.366)),
(-103, ('[NPC][Abyssal][Firestorm T4/T5]Drifter', 0.422, 0.114, 0.422, 0.422)),
(-104, ('[NPC][Abyssal][Firestorm T4/T5]Sleeper', 0.512, 0.276, 0.512, 0.512)),
(-105, ('[NPC][Abyssal][Firestorm T4/T5]All', 0.541, 0.214, 0.524, 0.504)),
(-106, ('[NPC][Abyssal][Exotic T1/T2]Drones', 0.439, 0.522, 0.417, 0.435)),
(-107, ('[NPC][Abyssal][Exotic T1/T2]Overmind', 0.626, 0.576, 0.496, 0.624)),
(-108, ('[NPC][Abyssal][Exotic T1/T2]Seeker', 0.082, 0.082, 0, 0.082)),
(-109, ('[NPC][Abyssal][Exotic T1/T2]Triglavian', 0.477, 0.401, 0.284, 0.37)),
(-110, ('[NPC][Abyssal][Exotic T1/T2]Drifter', 0.403, 0.403, 0.267, 0.403)),
(-111, ('[NPC][Abyssal][Exotic T1/T2]Sleeper', 0.435, 0.435, 0.329, 0.435)),
(-112, ('[NPC][Abyssal][Exotic T1/T2]All', 0.507, 0.477, 0.373, 0.493)),
(-113, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]Drones', 0.439, 0.522, 0.351, 0.435)),
(-114, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]Overmind', 0.626, 0.576, 0.419, 0.624)),
(-115, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]Seeker', 0.082, 0.082, 0, 0.082)),
(-116, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]Triglavian', 0.477, 0.401, 0.176, 0.37)),
(-117, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]Drifter', 0.403, 0.403, 0.184, 0.403)),
(-118, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]Sleeper', 0.435, 0.435, 0.268, 0.435)),
(-119, ('[NPC][Abyssal][Exotic T3 (Some T5 Rooms)]All', 0.507, 0.477, 0.293, 0.493)),
(-120, ('[NPC][Abyssal][Exotic T4/T5]Drones', 0.439, 0.522, 0.293, 0.435)),
(-121, ('[NPC][Abyssal][Exotic T4/T5]Overmind', 0.626, 0.576, 0.344, 0.624)),
(-122, ('[NPC][Abyssal][Exotic T4/T5]Seeker', 0.082, 0.082, 0, 0.082)),
(-123, ('[NPC][Abyssal][Exotic T4/T5]Triglavian', 0.477, 0.401, 0.107, 0.37)),
(-124, ('[NPC][Abyssal][Exotic T4/T5]Drifter', 0.403, 0.403, 0.107, 0.403)),
(-125, ('[NPC][Abyssal][Exotic T4/T5]Sleeper', 0.435, 0.435, 0.215, 0.435)),
(-126, ('[NPC][Abyssal][Exotic T4/T5]All', 0.507, 0.477, 0.223, 0.493)),
(-127, ('[NPC][Abyssal][Gamma T1/T2]Drones', 0.449, 0.54, 0.549, 0.336)),
(-128, ('[NPC][Abyssal][Gamma T1/T2]Overmind', 0.6, 0.557, 0.601, 0.504)),
(-129, ('[NPC][Abyssal][Gamma T1/T2]Seeker', 0.085, 0.085, 0.085, 0)),
(-130, ('[NPC][Abyssal][Gamma T1/T2]Triglavian', 0.463, 0.392, 0.447, 0.193)),
(-131, ('[NPC][Abyssal][Gamma T1/T2]Drifter', 0.428, 0.428, 0.428, 0.287)),
(-132, ('[NPC][Abyssal][Gamma T1/T2]Sleeper', 0.435, 0.435, 0.435, 0.329)),
(-133, ('[NPC][Abyssal][Gamma T1/T2]All', 0.493, 0.472, 0.5, 0.362)),
(-134, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]Drones', 0.449, 0.54, 0.549, 0.264)),
(-135, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]Overmind', 0.6, 0.557, 0.601, 0.428)),
(-136, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]Seeker', 0.085, 0.085, 0.085, 0)),
(-137, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]Triglavian', 0.463, 0.392, 0.447, 0.071)),
(-138, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]Drifter', 0.428, 0.428, 0.428, 0.2)),
(-139, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]Sleeper', 0.435, 0.435, 0.435, 0.268)),
(-140, ('[NPC][Abyssal][Gamma T3 (Some T5 Rooms)]All', 0.493, 0.472, 0.5, 0.28)),
(-141, ('[NPC][Abyssal][Gamma T4/T5]Drones', 0.449, 0.54, 0.549, 0.197)),
(-142, ('[NPC][Abyssal][Gamma T4/T5]Overmind', 0.6, 0.557, 0.601, 0.356)),
(-143, ('[NPC][Abyssal][Gamma T4/T5]Seeker', 0.085, 0.085, 0.085, 0)),
(-144, ('[NPC][Abyssal][Gamma T4/T5]Triglavian', 0.463, 0.392, 0.447, 0.029)),
(-145, ('[NPC][Abyssal][Gamma T4/T5]Drifter', 0.428, 0.428, 0.428, 0.117)),
(-146, ('[NPC][Abyssal][Gamma T4/T5]Sleeper', 0.435, 0.435, 0.435, 0.215)),
(-147, ('[NPC][Abyssal][Gamma T4/T5]All', 0.493, 0.472, 0.5, 0.21))])
class TargetProfile:
# also determined import/export order - VERY IMPORTANT
DAMAGE_TYPES = ('em', 'thermal', 'kinetic', 'explosive')
_idealTarget = None
_builtins = None
def __init__(self, *args, **kwargs):
self.builtin = False
self.update(*args, **kwargs)
@reconstructor
def init(self):
self.builtin = False
def update(self, emAmount=0, thermalAmount=0, kineticAmount=0, explosiveAmount=0, maxVelocity=None, signatureRadius=None, radius=None):
self.emAmount = emAmount
self.thermalAmount = thermalAmount
self.kineticAmount = kineticAmount
self.explosiveAmount = explosiveAmount
self._maxVelocity = maxVelocity
self._signatureRadius = signatureRadius
self._radius = radius
@classmethod
def getBuiltinList(cls):
if cls._builtins is None:
cls.__generateBuiltins()
return list(cls._builtins.values())
@classmethod
def getBuiltinById(cls, id):
if cls._builtins is None:
cls.__generateBuiltins()
return cls._builtins.get(id)
@classmethod
def __generateBuiltins(cls):
cls._builtins = OrderedDict()
for id, data in BUILTINS.items():
rawName = data[0]
data = data[1:]
profile = TargetProfile(*data)
profile.ID = id
profile.rawName = rawName
profile.builtin = True
cls._builtins[id] = profile
@classmethod
def getIdeal(cls):
if cls._idealTarget is None:
cls._idealTarget = cls(
emAmount=0,
thermalAmount=0,
kineticAmount=0,
explosiveAmount=0,
maxVelocity=0,
signatureRadius=None,
radius=0)
cls._idealTarget.rawName = 'Ideal Target'
cls._idealTarget.ID = 0
cls._idealTarget.builtin = True
return cls._idealTarget
@property
def maxVelocity(self):
return self._maxVelocity or 0
@maxVelocity.setter
def maxVelocity(self, val):
self._maxVelocity = val
@property
def signatureRadius(self):
if self._signatureRadius is None or self._signatureRadius == -1:
return math.inf
return self._signatureRadius
@signatureRadius.setter
def signatureRadius(self, val):
if val is not None and math.isinf(val):
val = None
self._signatureRadius = val
@property
def radius(self):
return self._radius or 0
@radius.setter
def radius(self, val):
self._radius = val
@classmethod
def importPatterns(cls, text):
lines = re.split('[\n\r]+', text)
patterns = []
numPatterns = 0
# When we import damage profiles, we create new ones and update old ones. To do this, get a list of current
# patterns to allow lookup
lookup = {}
current = eos.db.getTargetProfileList()
for pattern in current:
lookup[pattern.rawName] = pattern
for line in lines:
try:
if line.strip()[0] == "#": # comments
continue
line = line.split('#', 1)[0] # allows for comments
type, data = line.rsplit('=', 1)
type, data = type.strip(), [d.strip() for d in data.split(',')]
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.warning("Data isn't in correct format, continue to next line.")
continue
if type not in ("TargetProfile", "TargetResists"):
continue
numPatterns += 1
name, dataRes, dataMisc = data[0], data[1:5], data[5:8]
fields = {}
for index, val in enumerate(dataRes):
val = float(val) if val else 0
if math.isinf(val):
val = 0
try:
assert 0 <= val <= 100
fields["%sAmount" % cls.DAMAGE_TYPES[index]] = val / 100
except (KeyboardInterrupt, SystemExit):
raise
except:
pyfalog.warning("Caught unhandled exception in import patterns.")
continue
if len(dataMisc) == 3:
for index, val in enumerate(dataMisc):
try:
fieldName = ("maxVelocity", "signatureRadius", "radius")[index]
except IndexError:
break
val = float(val) if val else 0
if fieldName != "signatureRadius" and math.isinf(val):
val = 0
fields[fieldName] = val
if len(fields) in (4, 7): # Avoid possible blank lines
if name.strip() in lookup:
pattern = lookup[name.strip()]
pattern.update(**fields)
eos.db.save(pattern)
else:
pattern = TargetProfile(**fields)
pattern.rawName = name.strip()
eos.db.save(pattern)
patterns.append(pattern)
eos.db.commit()
return patterns, numPatterns
EXPORT_FORMAT = "TargetProfile = %s,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f\n"
@classmethod
def exportPatterns(cls, *patterns):
out = "# Exported from pyfa\n#\n"
out += "# Values are in following format:\n"
out += "# TargetProfile = [name],[EM %],[Thermal %],[Kinetic %],[Explosive %],[Max velocity m/s],[Signature radius m],[Radius m]\n\n"
for dp in patterns:
out += cls.EXPORT_FORMAT % (
dp.rawName,
dp.emAmount * 100,
dp.thermalAmount * 100,
dp.kineticAmount * 100,
dp.explosiveAmount * 100,
dp.maxVelocity,
dp.signatureRadius,
dp.radius
)
return out.strip()
@property
def name(self):
return self.rawName
@property
def fullName(self):
categories, tail = self.__parseRawName()
return '{}{}'.format(''.join('[{}]'.format(c) for c in categories), tail)
@property
def shortName(self):
return self.__parseRawName()[1]
@property
def hierarchy(self):
return self.__parseRawName()[0]
def __parseRawName(self):
hierarchy = []
remainingName = self.rawName.strip() if self.rawName else ''
while True:
start, end = remainingName.find('['), remainingName.find(']')
if start == -1 or end == -1:
return hierarchy, remainingName
splitter = remainingName.find('|')
if splitter != -1 and splitter == start - 1:
return hierarchy, remainingName[1:]
hierarchy.append(remainingName[start + 1:end])
remainingName = remainingName[end + 1:].strip()
def __deepcopy__(self, memo):
p = TargetProfile(
self.emAmount, self.thermalAmount, self.kineticAmount, self.explosiveAmount,
self._maxVelocity, self._signatureRadius, self._radius)
p.rawName = "%s copy" % self.rawName
return p
|
gpl-3.0
|
[
3,
7819,
17224,
199,
3,
1898,
334,
35,
9,
6927,
820,
89,
290,
869,
393,
6415,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
325,
736,
14,
199,
3,
199,
3,
325,
736,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
325,
736,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
325,
736,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
7819,
17224,
199,
199,
646,
3473,
199,
646,
295,
199,
504,
5055,
492,
8773,
199,
199,
504,
943,
2706,
492,
15996,
199,
504,
8335,
14,
1025,
492,
295,
1880,
199,
199,
646,
325,
736,
14,
697,
421,
199,
647,
70,
2548,
275,
15996,
3460,
354,
3368,
421,
199,
18637,
52,
10789,
275,
8773,
779,
272,
327,
378,
365,
9394,
701,
28264,
1347,
4690,
12,
26356,
10250,
315,
1373,
402,
10256,
5736,
3102,
272,
5868,
17,
12,
661,
12421,
334,
821,
5,
3196,
378,
14,
821,
12,
378,
14,
821,
12,
378,
14,
821,
12,
378,
14,
821,
1826,
272,
5868,
18,
12,
661,
12421,
334,
1400,
5,
3196,
378,
14,
1400,
12,
378,
14,
1400,
12,
378,
14,
1400,
12,
378,
14,
1400,
1826,
272,
5868,
19,
12,
661,
12421,
334,
2194,
5,
3196,
378,
14,
2194,
12,
378,
14,
2194,
12,
378,
14,
2194,
12,
378,
14,
2194,
1826,
272,
5868,
20,
12,
661,
12421,
334,
2710,
5,
3196,
378,
14,
2710,
12,
378,
14,
2710,
12,
378,
14,
2710,
12,
378,
14,
2710,
1826,
272,
5868,
21,
12,
23734,
52,
17,
799,
11734,
61,
2662,
553,
297,
378,
14,
16,
12,
378,
14,
1165,
12,
378,
14,
2167,
12,
378,
14,
1400,
1826,
272,
5868,
22,
12,
23734,
52,
17,
799,
11734,
61,
1596,
12416,
297,
378,
14,
1400,
12,
378,
14,
2322,
12,
378,
14,
821,
12,
378,
14,
709,
1826,
272,
5868,
23,
12,
23734,
52,
17,
799,
11734,
61,
40,
979,
297,
378,
14,
1153,
12,
378,
14,
1153,
12,
378,
14,
1153,
12,
378,
14,
1153,
1826,
272,
5868,
24,
12,
23734,
52,
17,
799,
11734,
61,
2662,
553,
334,
11,
52,
18,
30592,
53,
3196,
378,
14,
6889,
12,
378,
14,
1216,
12,
378,
14,
30494,
12,
378,
14,
18836,
1826,
272,
5868,
25,
12,
23734,
52,
17,
799,
11734,
61,
1596,
12416,
334,
11,
52,
18,
30592,
53,
3196,
378,
14,
14781,
12,
378,
14,
30102,
12,
378,
14,
15031,
12,
378,
14,
8276,
1826,
272,
5868,
709,
12,
23734,
52,
17,
799,
11734,
61,
40,
979,
334,
11,
52,
18,
30592,
53,
3196,
378,
14,
15897,
12,
378,
14,
15897,
12,
378,
14,
15897,
12,
378,
14,
15897,
1826,
272,
5868,
845,
12,
23734,
52,
18,
799,
11734,
61,
33,
4584,
82,
334,
2662,
553,
3196,
378,
14,
16,
12,
378,
14,
1165,
12,
378,
14,
2760,
12,
378,
14,
13357,
1826,
272,
5868,
713,
12,
23734,
52,
18,
799,
11734,
61,
33,
4584,
82,
334,
1596,
12416,
3196,
378,
14,
1400,
12,
378,
14,
1276,
12,
378,
14,
22475,
12,
378,
14,
1257,
1826,
272,
5868,
969,
12,
23734,
52,
18,
799,
11734,
61,
6584,
68,
759,
334,
2662,
553,
3196,
378,
14,
1165,
12,
378,
14,
1349,
12,
378,
14,
2114,
12,
378,
14,
2259,
1826,
272,
5868,
1079,
12,
23734,
52,
18,
799,
11734,
61,
6584,
68,
759,
334,
1596,
12416,
3196,
378,
14,
1400,
12,
378,
14,
1184,
821,
12,
378,
14,
22475,
12,
378,
14,
709,
1826,
272,
5868,
1046,
12,
23734,
52,
18,
799,
11734,
61,
39,
7670,
266,
334,
2662,
553,
3196,
378,
14,
16,
12,
378,
14,
2259,
12,
378,
14,
2426,
12,
378,
14,
1400,
1826,
272,
5868,
975,
12,
23734,
52,
18,
799,
11734,
61,
39,
7670,
266,
334,
1596,
12416,
3196,
378,
14,
1400,
12,
378,
14,
19895,
12,
378,
14,
24,
9946,
12,
378,
14,
709,
1826,
272,
5868,
1196,
12,
23734,
52,
18,
799,
11734,
61,
4649,
569,
285,
334,
2662,
553,
3196,
378,
14,
2194,
12,
378,
14,
2259,
12,
378,
14,
2167,
12,
378,
14,
1400,
1826,
272,
5868,
1085,
12,
23734,
52,
18,
799,
11734,
61,
4649,
569,
285,
334,
1596,
12416,
3196,
378,
14,
2710,
12,
378,
14,
19895,
12,
378,
14,
821,
12,
378,
14,
709,
1826,
272,
5868,
1167,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
2493,
24920,
14243,
14146,
297,
378,
14,
1477,
12,
378,
14,
2260,
12,
378,
14,
1401,
12,
378,
14,
708,
1826,
272,
5868,
1165,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
34,
21703,
3898,
73,
7735,
297,
378,
14,
1082,
12,
378,
14,
1355,
12,
378,
14,
2322,
12,
378,
14,
2528,
1826,
272,
5868,
2025,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
39,
300,
631,
305,
297,
378,
14,
1229,
12,
378,
14,
1276,
12,
378,
14,
19,
12,
378,
14,
2006,
1826,
272,
5868,
1081,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
50,
974,
310,
577,
82,
4548,
297,
378,
14,
1276,
12,
378,
14,
1703,
12,
378,
14,
1602,
12,
378,
14,
1887,
1826,
272,
5868,
1789,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
23906,
609,
305,
653,
425,
297,
378,
14,
1276,
12,
378,
14,
20,
12,
378,
14,
2417,
12,
378,
14,
2481,
1826,
272,
5868,
1194,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
1505,
897,
16753,
297,
378,
14,
1887,
12,
378,
14,
1703,
12,
378,
14,
1398,
12,
378,
14,
2869,
1826,
272,
5868,
821,
12,
23734
] |
[
7819,
17224,
199,
3,
1898,
334,
35,
9,
6927,
820,
89,
290,
869,
393,
6415,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
325,
736,
14,
199,
3,
199,
3,
325,
736,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
325,
736,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
325,
736,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
7819,
17224,
199,
199,
646,
3473,
199,
646,
295,
199,
504,
5055,
492,
8773,
199,
199,
504,
943,
2706,
492,
15996,
199,
504,
8335,
14,
1025,
492,
295,
1880,
199,
199,
646,
325,
736,
14,
697,
421,
199,
647,
70,
2548,
275,
15996,
3460,
354,
3368,
421,
199,
18637,
52,
10789,
275,
8773,
779,
272,
327,
378,
365,
9394,
701,
28264,
1347,
4690,
12,
26356,
10250,
315,
1373,
402,
10256,
5736,
3102,
272,
5868,
17,
12,
661,
12421,
334,
821,
5,
3196,
378,
14,
821,
12,
378,
14,
821,
12,
378,
14,
821,
12,
378,
14,
821,
1826,
272,
5868,
18,
12,
661,
12421,
334,
1400,
5,
3196,
378,
14,
1400,
12,
378,
14,
1400,
12,
378,
14,
1400,
12,
378,
14,
1400,
1826,
272,
5868,
19,
12,
661,
12421,
334,
2194,
5,
3196,
378,
14,
2194,
12,
378,
14,
2194,
12,
378,
14,
2194,
12,
378,
14,
2194,
1826,
272,
5868,
20,
12,
661,
12421,
334,
2710,
5,
3196,
378,
14,
2710,
12,
378,
14,
2710,
12,
378,
14,
2710,
12,
378,
14,
2710,
1826,
272,
5868,
21,
12,
23734,
52,
17,
799,
11734,
61,
2662,
553,
297,
378,
14,
16,
12,
378,
14,
1165,
12,
378,
14,
2167,
12,
378,
14,
1400,
1826,
272,
5868,
22,
12,
23734,
52,
17,
799,
11734,
61,
1596,
12416,
297,
378,
14,
1400,
12,
378,
14,
2322,
12,
378,
14,
821,
12,
378,
14,
709,
1826,
272,
5868,
23,
12,
23734,
52,
17,
799,
11734,
61,
40,
979,
297,
378,
14,
1153,
12,
378,
14,
1153,
12,
378,
14,
1153,
12,
378,
14,
1153,
1826,
272,
5868,
24,
12,
23734,
52,
17,
799,
11734,
61,
2662,
553,
334,
11,
52,
18,
30592,
53,
3196,
378,
14,
6889,
12,
378,
14,
1216,
12,
378,
14,
30494,
12,
378,
14,
18836,
1826,
272,
5868,
25,
12,
23734,
52,
17,
799,
11734,
61,
1596,
12416,
334,
11,
52,
18,
30592,
53,
3196,
378,
14,
14781,
12,
378,
14,
30102,
12,
378,
14,
15031,
12,
378,
14,
8276,
1826,
272,
5868,
709,
12,
23734,
52,
17,
799,
11734,
61,
40,
979,
334,
11,
52,
18,
30592,
53,
3196,
378,
14,
15897,
12,
378,
14,
15897,
12,
378,
14,
15897,
12,
378,
14,
15897,
1826,
272,
5868,
845,
12,
23734,
52,
18,
799,
11734,
61,
33,
4584,
82,
334,
2662,
553,
3196,
378,
14,
16,
12,
378,
14,
1165,
12,
378,
14,
2760,
12,
378,
14,
13357,
1826,
272,
5868,
713,
12,
23734,
52,
18,
799,
11734,
61,
33,
4584,
82,
334,
1596,
12416,
3196,
378,
14,
1400,
12,
378,
14,
1276,
12,
378,
14,
22475,
12,
378,
14,
1257,
1826,
272,
5868,
969,
12,
23734,
52,
18,
799,
11734,
61,
6584,
68,
759,
334,
2662,
553,
3196,
378,
14,
1165,
12,
378,
14,
1349,
12,
378,
14,
2114,
12,
378,
14,
2259,
1826,
272,
5868,
1079,
12,
23734,
52,
18,
799,
11734,
61,
6584,
68,
759,
334,
1596,
12416,
3196,
378,
14,
1400,
12,
378,
14,
1184,
821,
12,
378,
14,
22475,
12,
378,
14,
709,
1826,
272,
5868,
1046,
12,
23734,
52,
18,
799,
11734,
61,
39,
7670,
266,
334,
2662,
553,
3196,
378,
14,
16,
12,
378,
14,
2259,
12,
378,
14,
2426,
12,
378,
14,
1400,
1826,
272,
5868,
975,
12,
23734,
52,
18,
799,
11734,
61,
39,
7670,
266,
334,
1596,
12416,
3196,
378,
14,
1400,
12,
378,
14,
19895,
12,
378,
14,
24,
9946,
12,
378,
14,
709,
1826,
272,
5868,
1196,
12,
23734,
52,
18,
799,
11734,
61,
4649,
569,
285,
334,
2662,
553,
3196,
378,
14,
2194,
12,
378,
14,
2259,
12,
378,
14,
2167,
12,
378,
14,
1400,
1826,
272,
5868,
1085,
12,
23734,
52,
18,
799,
11734,
61,
4649,
569,
285,
334,
1596,
12416,
3196,
378,
14,
2710,
12,
378,
14,
19895,
12,
378,
14,
821,
12,
378,
14,
709,
1826,
272,
5868,
1167,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
2493,
24920,
14243,
14146,
297,
378,
14,
1477,
12,
378,
14,
2260,
12,
378,
14,
1401,
12,
378,
14,
708,
1826,
272,
5868,
1165,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
34,
21703,
3898,
73,
7735,
297,
378,
14,
1082,
12,
378,
14,
1355,
12,
378,
14,
2322,
12,
378,
14,
2528,
1826,
272,
5868,
2025,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
39,
300,
631,
305,
297,
378,
14,
1229,
12,
378,
14,
1276,
12,
378,
14,
19,
12,
378,
14,
2006,
1826,
272,
5868,
1081,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
50,
974,
310,
577,
82,
4548,
297,
378,
14,
1276,
12,
378,
14,
1703,
12,
378,
14,
1602,
12,
378,
14,
1887,
1826,
272,
5868,
1789,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
23906,
609,
305,
653,
425,
297,
378,
14,
1276,
12,
378,
14,
20,
12,
378,
14,
2417,
12,
378,
14,
2481,
1826,
272,
5868,
1194,
12,
23734,
46,
4222,
1527,
33,
1597,
3977,
61,
1505,
897,
16753,
297,
378,
14,
1887,
12,
378,
14,
1703,
12,
378,
14,
1398,
12,
378,
14,
2869,
1826,
272,
5868,
821,
12,
23734,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
crosswalk-project/chromium-crosswalk-efl
|
tools/site_compare/commands/measure.py
|
189
|
1573
|
# Copyright (c) 2011 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.
"""Command for measuring how long pages take to load in a browser.
Prerequisites:
1. The command_line package from tools/site_compare
2. Either the IE BHO or Firefox extension (or both)
Installation:
1. Build the IE BHO, or call regsvr32 on a prebuilt binary
2. Add a file called "measurepageloadtimeextension@google.com" to
the default Firefox profile directory under extensions, containing
the path to the Firefox extension root
Invoke with the command line arguments as documented within
the command line.
"""
import command_line
import win32process
from drivers import windowing
from utils import browser_iterate
def CreateCommand(cmdline):
"""Inserts the command and arguments into a command line for parsing."""
cmd = cmdline.AddCommand(
["measure"],
"Measures how long a series of URLs takes to load in one or more browsers.",
None,
ExecuteMeasure)
browser_iterate.SetupIterationCommandLine(cmd)
cmd.AddArgument(
["-log", "--logfile"], "File to write output", type="string", required=True)
def ExecuteMeasure(command):
"""Executes the Measure command."""
def LogResult(url, proc, wnd, result):
"""Write the result of the browse to the log file."""
log_file.write(result)
log_file = open(command["--logfile"], "w")
browser_iterate.Iterate(command, LogResult)
# Close the log file and return. We're done.
log_file.close()
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
7760,
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,
3110,
367,
17616,
4039,
4212,
1846,
6497,
5452,
370,
2248,
315,
282,
7042,
14,
199,
199,
2398,
30140,
26,
523,
413,
14,
710,
1414,
63,
604,
2559,
687,
7249,
15,
2124,
63,
5785,
523,
499,
14,
13083,
314,
15292,
699,
2979,
503,
24584,
3329,
334,
269,
3865,
9,
199,
199,
31456,
26,
523,
413,
14,
6516,
314,
15292,
699,
2979,
12,
503,
1240,
295,
458,
10922,
708,
641,
282,
876,
11730,
3366,
523,
499,
14,
2654,
282,
570,
2797,
298,
9580,
1606,
912,
521,
3435,
32,
3098,
14,
957,
2,
370,
1362,
314,
849,
24584,
4690,
2082,
1334,
5478,
12,
3035,
1362,
314,
931,
370,
314,
24584,
3329,
1738,
199,
199,
27736,
543,
314,
1414,
1004,
2368,
465,
22751,
4453,
199,
1589,
1414,
1004,
14,
199,
624,
199,
199,
646,
1414,
63,
604,
199,
646,
4747,
708,
1412,
199,
199,
504,
19016,
492,
4353,
316,
199,
504,
3778,
492,
7042,
63,
20627,
199,
199,
318,
2790,
3110,
8,
15612,
304,
523,
408,
9971,
83,
314,
1414,
436,
2368,
1901,
282,
1414,
1004,
367,
6057,
1041,
523,
2088,
275,
21206,
14,
1123,
3110,
8,
272,
2097,
9580,
2255,
272,
298,
1352,
305,
1482,
4212,
1846,
282,
6779,
402,
10867,
6181,
370,
2248,
315,
1373,
503,
1655,
23776,
4765,
272,
488,
12,
272,
17009,
18611,
9,
819,
7042,
63,
20627,
14,
8555,
8666,
16926,
8,
1760,
9,
523,
2088,
14,
1123,
5201,
8,
272,
16984,
793,
401,
4320,
12804,
2255,
298,
1173,
370,
2218,
1072,
401,
730,
628,
875,
401,
1415,
29,
549,
9,
421,
199,
318,
17009,
18611,
8,
1531,
304,
523,
408,
4858,
3862,
314,
22933,
1414,
1041,
819,
347,
5297,
2889,
8,
633,
12,
6499,
12,
336,
977,
12,
754,
304,
272,
408,
3534,
314,
754,
402,
314,
19249,
370,
314,
943,
570,
1041,
272,
943,
63,
493,
14,
952,
8,
1099,
9,
819,
943,
63,
493,
275,
1551,
8,
1531,
905,
306,
12804,
2255,
298,
87,
531,
819,
7042,
63,
20627,
14,
3315,
323,
8,
1531,
12,
5297,
2889,
9,
819,
327,
15524,
314,
943,
570,
436,
372,
14,
2136,
3984,
4224,
14,
523,
943,
63,
493,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7760,
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,
3110,
367,
17616,
4039,
4212,
1846,
6497,
5452,
370,
2248,
315,
282,
7042,
14,
199,
199,
2398,
30140,
26,
523,
413,
14,
710,
1414,
63,
604,
2559,
687,
7249,
15,
2124,
63,
5785,
523,
499,
14,
13083,
314,
15292,
699,
2979,
503,
24584,
3329,
334,
269,
3865,
9,
199,
199,
31456,
26,
523,
413,
14,
6516,
314,
15292,
699,
2979,
12,
503,
1240,
295,
458,
10922,
708,
641,
282,
876,
11730,
3366,
523,
499,
14,
2654,
282,
570,
2797,
298,
9580,
1606,
912,
521,
3435,
32,
3098,
14,
957,
2,
370,
1362,
314,
849,
24584,
4690,
2082,
1334,
5478,
12,
3035,
1362,
314,
931,
370,
314,
24584,
3329,
1738,
199,
199,
27736,
543,
314,
1414,
1004,
2368,
465,
22751,
4453,
199,
1589,
1414,
1004,
14,
199,
624,
199,
199,
646,
1414,
63,
604,
199,
646,
4747,
708,
1412,
199,
199,
504,
19016,
492,
4353,
316,
199,
504,
3778,
492,
7042,
63,
20627,
199,
199,
318,
2790,
3110,
8,
15612,
304,
523,
408,
9971,
83,
314,
1414,
436,
2368,
1901,
282,
1414,
1004,
367,
6057,
1041,
523,
2088,
275,
21206,
14,
1123,
3110,
8,
272,
2097,
9580,
2255,
272,
298,
1352,
305,
1482,
4212,
1846,
282,
6779,
402,
10867,
6181,
370,
2248,
315,
1373,
503,
1655,
23776,
4765,
272,
488,
12,
272,
17009,
18611,
9,
819,
7042,
63,
20627,
14,
8555,
8666,
16926,
8,
1760,
9,
523,
2088,
14,
1123,
5201,
8,
272,
16984,
793,
401,
4320,
12804,
2255,
298,
1173,
370,
2218,
1072,
401,
730,
628,
875,
401,
1415,
29,
549,
9,
421,
199,
318,
17009,
18611,
8,
1531,
304,
523,
408,
4858,
3862,
314,
22933,
1414,
1041,
819,
347,
5297,
2889,
8,
633,
12,
6499,
12,
336,
977,
12,
754,
304,
272,
408,
3534,
314,
754,
402,
314,
19249,
370,
314,
943,
570,
1041,
272,
943,
63,
493,
14,
952,
8,
1099,
9,
819,
943,
63,
493,
275,
1551,
8,
1531,
905,
306,
12804,
2255,
298,
87,
531,
819,
7042,
63,
20627,
14,
3315,
323,
8,
1531,
12,
5297,
2889,
9,
819,
327,
15524,
314,
943,
570,
436,
372,
14,
2136,
3984,
4224,
14,
523,
943,
63,
493,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mozilla/stoneridge
|
python/src/Lib/test/test_pprint.py
|
71
|
24693
|
import pprint
import test.test_support
import unittest
import test.test_set
try:
uni = unicode
except NameError:
def uni(x):
return x
# list, tuple and dict subclasses that do or don't overwrite __repr__
class list2(list):
pass
class list3(list):
def __repr__(self):
return list.__repr__(self)
class tuple2(tuple):
pass
class tuple3(tuple):
def __repr__(self):
return tuple.__repr__(self)
class dict2(dict):
pass
class dict3(dict):
def __repr__(self):
return dict.__repr__(self)
class QueryTestCase(unittest.TestCase):
def setUp(self):
self.a = range(100)
self.b = range(200)
self.a[-12] = self.b
def test_basic(self):
# Verify .isrecursive() and .isreadable() w/o recursion
pp = pprint.PrettyPrinter()
for safe in (2, 2.0, 2j, "abc", [3], (2,2), {3: 3}, uni("yaddayadda"),
self.a, self.b):
# module-level convenience functions
self.assertFalse(pprint.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
self.assertTrue(pprint.isreadable(safe),
"expected isreadable for %r" % (safe,))
# PrettyPrinter methods
self.assertFalse(pp.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
self.assertTrue(pp.isreadable(safe),
"expected isreadable for %r" % (safe,))
def test_knotted(self):
# Verify .isrecursive() and .isreadable() w/ recursion
# Tie a knot.
self.b[67] = self.a
# Messy dict.
self.d = {}
self.d[0] = self.d[1] = self.d[2] = self.d
pp = pprint.PrettyPrinter()
for icky in self.a, self.b, self.d, (self.d, self.d):
self.assertTrue(pprint.isrecursive(icky), "expected isrecursive")
self.assertFalse(pprint.isreadable(icky), "expected not isreadable")
self.assertTrue(pp.isrecursive(icky), "expected isrecursive")
self.assertFalse(pp.isreadable(icky), "expected not isreadable")
# Break the cycles.
self.d.clear()
del self.a[:]
del self.b[:]
for safe in self.a, self.b, self.d, (self.d, self.d):
# module-level convenience functions
self.assertFalse(pprint.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
self.assertTrue(pprint.isreadable(safe),
"expected isreadable for %r" % (safe,))
# PrettyPrinter methods
self.assertFalse(pp.isrecursive(safe),
"expected not isrecursive for %r" % (safe,))
self.assertTrue(pp.isreadable(safe),
"expected isreadable for %r" % (safe,))
def test_unreadable(self):
# Not recursive but not readable anyway
pp = pprint.PrettyPrinter()
for unreadable in type(3), pprint, pprint.isrecursive:
# module-level convenience functions
self.assertFalse(pprint.isrecursive(unreadable),
"expected not isrecursive for %r" % (unreadable,))
self.assertFalse(pprint.isreadable(unreadable),
"expected not isreadable for %r" % (unreadable,))
# PrettyPrinter methods
self.assertFalse(pp.isrecursive(unreadable),
"expected not isrecursive for %r" % (unreadable,))
self.assertFalse(pp.isreadable(unreadable),
"expected not isreadable for %r" % (unreadable,))
def test_same_as_repr(self):
# Simple objects, small containers and classes that overwrite __repr__
# For those the result should be the same as repr().
# Ahem. The docs don't say anything about that -- this appears to
# be testing an implementation quirk. Starting in Python 2.5, it's
# not true for dicts: pprint always sorts dicts by key now; before,
# it sorted a dict display if and only if the display required
# multiple lines. For that reason, dicts with more than one element
# aren't tested here.
for simple in (0, 0L, 0+0j, 0.0, "", uni(""),
(), tuple2(), tuple3(),
[], list2(), list3(),
{}, dict2(), dict3(),
self.assertTrue, pprint,
-6, -6L, -6-6j, -1.5, "x", uni("x"), (3,), [3], {3: 6},
(1,2), [3,4], {5: 6},
tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
[3,4], list2([3,4]), list3([3,4]), list3(range(100)),
dict2({5: 6}), dict3({5: 6}),
range(10, -11, -1)
):
native = repr(simple)
for function in "pformat", "saferepr":
f = getattr(pprint, function)
got = f(simple)
self.assertEqual(native, got,
"expected %s got %s from pprint.%s" %
(native, got, function))
def test_basic_line_wrap(self):
# verify basic line-wrapping operation
o = {'RPM_cal': 0,
'RPM_cal2': 48059,
'Speed_cal': 0,
'controldesk_runtime_us': 0,
'main_code_runtime_us': 0,
'read_io_runtime_us': 0,
'write_io_runtime_us': 43690}
exp = """\
{'RPM_cal': 0,
'RPM_cal2': 48059,
'Speed_cal': 0,
'controldesk_runtime_us': 0,
'main_code_runtime_us': 0,
'read_io_runtime_us': 0,
'write_io_runtime_us': 43690}"""
for type in [dict, dict2]:
self.assertEqual(pprint.pformat(type(o)), exp)
o = range(100)
exp = '[%s]' % ',\n '.join(map(str, o))
for type in [list, list2]:
self.assertEqual(pprint.pformat(type(o)), exp)
o = tuple(range(100))
exp = '(%s)' % ',\n '.join(map(str, o))
for type in [tuple, tuple2]:
self.assertEqual(pprint.pformat(type(o)), exp)
# indent parameter
o = range(100)
exp = '[ %s]' % ',\n '.join(map(str, o))
for type in [list, list2]:
self.assertEqual(pprint.pformat(type(o), indent=4), exp)
def test_nested_indentations(self):
o1 = list(range(10))
o2 = dict(first=1, second=2, third=3)
o = [o1, o2]
expected = """\
[ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
{ 'first': 1,
'second': 2,
'third': 3}]"""
self.assertEqual(pprint.pformat(o, indent=4, width=42), expected)
def test_sorted_dict(self):
# Starting in Python 2.5, pprint sorts dict displays by key regardless
# of how small the dictionary may be.
# Before the change, on 32-bit Windows pformat() gave order
# 'a', 'c', 'b' here, so this test failed.
d = {'a': 1, 'b': 1, 'c': 1}
self.assertEqual(pprint.pformat(d), "{'a': 1, 'b': 1, 'c': 1}")
self.assertEqual(pprint.pformat([d, d]),
"[{'a': 1, 'b': 1, 'c': 1}, {'a': 1, 'b': 1, 'c': 1}]")
# The next one is kind of goofy. The sorted order depends on the
# alphabetic order of type names: "int" < "str" < "tuple". Before
# Python 2.5, this was in the test_same_as_repr() test. It's worth
# keeping around for now because it's one of few tests of pprint
# against a crazy mix of types.
self.assertEqual(pprint.pformat({"xy\tab\n": (3,), 5: [[]], (): {}}),
r"{5: [[]], 'xy\tab\n': (3,), (): {}}")
def test_subclassing(self):
o = {'names with spaces': 'should be presented using repr()',
'others.should.not.be': 'like.this'}
exp = """\
{'names with spaces': 'should be presented using repr()',
others.should.not.be: like.this}"""
self.assertEqual(DottedPrettyPrinter().pformat(o), exp)
def test_set_reprs(self):
self.assertEqual(pprint.pformat(set()), 'set()')
self.assertEqual(pprint.pformat(set(range(3))), 'set([0, 1, 2])')
self.assertEqual(pprint.pformat(frozenset()), 'frozenset()')
self.assertEqual(pprint.pformat(frozenset(range(3))), 'frozenset([0, 1, 2])')
cube_repr_tgt = """\
{frozenset([]): frozenset([frozenset([2]), frozenset([0]), frozenset([1])]),
frozenset([0]): frozenset([frozenset(),
frozenset([0, 2]),
frozenset([0, 1])]),
frozenset([1]): frozenset([frozenset(),
frozenset([1, 2]),
frozenset([0, 1])]),
frozenset([2]): frozenset([frozenset(),
frozenset([1, 2]),
frozenset([0, 2])]),
frozenset([1, 2]): frozenset([frozenset([2]),
frozenset([1]),
frozenset([0, 1, 2])]),
frozenset([0, 2]): frozenset([frozenset([2]),
frozenset([0]),
frozenset([0, 1, 2])]),
frozenset([0, 1]): frozenset([frozenset([0]),
frozenset([1]),
frozenset([0, 1, 2])]),
frozenset([0, 1, 2]): frozenset([frozenset([1, 2]),
frozenset([0, 2]),
frozenset([0, 1])])}"""
cube = test.test_set.cube(3)
self.assertEqual(pprint.pformat(cube), cube_repr_tgt)
cubo_repr_tgt = """\
{frozenset([frozenset([0, 2]), frozenset([0])]): frozenset([frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset([2]),
frozenset([0,
2])])]),
frozenset([frozenset([0, 1]), frozenset([1])]): frozenset([frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset([1]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([1])])]),
frozenset([frozenset([1, 2]), frozenset([1])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([1])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([1, 2]), frozenset([2])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([1]),
frozenset([1,
2])]),
frozenset([frozenset([2]),
frozenset([0,
2])]),
frozenset([frozenset(),
frozenset([2])])]),
frozenset([frozenset([]), frozenset([0])]): frozenset([frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset(),
frozenset([1])]),
frozenset([frozenset(),
frozenset([2])])]),
frozenset([frozenset([]), frozenset([1])]): frozenset([frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset([1]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([2])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([2]), frozenset([])]): frozenset([frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset(),
frozenset([1])]),
frozenset([frozenset([2]),
frozenset([0,
2])])]),
frozenset([frozenset([0, 1, 2]), frozenset([0, 1])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
1])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([0]), frozenset([0, 1])]): frozenset([frozenset([frozenset(),
frozenset([0])]),
frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset([1]),
frozenset([0,
1])])]),
frozenset([frozenset([2]), frozenset([0, 2])]): frozenset([frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset(),
frozenset([2])])]),
frozenset([frozenset([0, 1, 2]), frozenset([0, 2])]): frozenset([frozenset([frozenset([1,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0]),
frozenset([0,
2])]),
frozenset([frozenset([2]),
frozenset([0,
2])])]),
frozenset([frozenset([1, 2]), frozenset([0, 1, 2])]): frozenset([frozenset([frozenset([0,
2]),
frozenset([0,
1,
2])]),
frozenset([frozenset([0,
1]),
frozenset([0,
1,
2])]),
frozenset([frozenset([2]),
frozenset([1,
2])]),
frozenset([frozenset([1]),
frozenset([1,
2])])])}"""
cubo = test.test_set.linegraph(cube)
self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt)
def test_depth(self):
nested_tuple = (1, (2, (3, (4, (5, 6)))))
nested_dict = {1: {2: {3: {4: {5: {6: 6}}}}}}
nested_list = [1, [2, [3, [4, [5, [6, []]]]]]]
self.assertEqual(pprint.pformat(nested_tuple), repr(nested_tuple))
self.assertEqual(pprint.pformat(nested_dict), repr(nested_dict))
self.assertEqual(pprint.pformat(nested_list), repr(nested_list))
lv1_tuple = '(1, (...))'
lv1_dict = '{1: {...}}'
lv1_list = '[1, [...]]'
self.assertEqual(pprint.pformat(nested_tuple, depth=1), lv1_tuple)
self.assertEqual(pprint.pformat(nested_dict, depth=1), lv1_dict)
self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list)
class DottedPrettyPrinter(pprint.PrettyPrinter):
def format(self, object, context, maxlevels, level):
if isinstance(object, str):
if ' ' in object:
return repr(object), 1, 0
else:
return object, 0, 0
else:
return pprint.PrettyPrinter.format(
self, object, context, maxlevels, level)
def test_main():
test.test_support.run_unittest(QueryTestCase)
if __name__ == "__main__":
test_main()
|
mpl-2.0
|
[
646,
10933,
199,
646,
511,
14,
396,
63,
4058,
199,
646,
2882,
199,
646,
511,
14,
396,
63,
409,
199,
199,
893,
26,
272,
15439,
275,
2649,
199,
2590,
12746,
26,
272,
347,
15439,
8,
88,
304,
267,
372,
671,
199,
199,
3,
769,
12,
2008,
436,
1211,
9180,
626,
886,
503,
2793,
1133,
8970,
636,
2722,
363,
199,
533,
769,
18,
8,
513,
304,
272,
986,
199,
199,
533,
769,
19,
8,
513,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
769,
855,
2722,
721,
277,
9,
199,
199,
533,
2008,
18,
8,
2960,
304,
272,
986,
199,
199,
533,
2008,
19,
8,
2960,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
2008,
855,
2722,
721,
277,
9,
199,
199,
533,
1211,
18,
8,
807,
304,
272,
986,
199,
199,
533,
1211,
19,
8,
807,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1211,
855,
2722,
721,
277,
9,
199,
199,
533,
8133,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
65,
275,
1425,
8,
1960,
9,
267,
291,
14,
66,
275,
1425,
8,
1840,
9,
267,
291,
14,
65,
1988,
713,
61,
275,
291,
14,
66,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
79,
16189,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
5048,
315,
334,
18,
12,
499,
14,
16,
12,
499,
74,
12,
298,
3175,
401,
359,
19,
467,
334,
18,
12,
18,
395,
469,
19,
26,
650,
1386,
15439,
480,
89,
525,
1187,
525,
65,
1288,
2151,
291,
14,
65,
12,
291,
14,
66,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
291,
14,
3334,
8,
15380,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
15380,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
291,
14,
3334,
8,
802,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
802,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
75,
1397,
471,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
16189,
267,
327,
377,
1873,
282,
1022,
1397,
14,
267,
291,
14,
66,
59,
1822,
61,
275,
291,
14,
65,
267,
327,
3194,
385,
89,
1211,
14,
267,
291,
14,
68,
275,
1052,
267,
291,
14,
68,
59,
16,
61,
275,
291,
14,
68,
59,
17,
61,
275,
291,
14,
68,
59,
18,
61,
275,
291,
14,
68,
398,
11618,
275,
10933,
14,
27153,
14131,
342,
398,
367,
284,
346,
89,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
291,
14,
1815,
8,
15380,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
291,
14,
3334,
8,
15380,
14,
374,
11875,
8,
14022,
395,
298,
2062,
440,
365,
11875,
531,
288,
291,
14,
1815,
8,
802,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
291,
14,
3334,
8,
802,
14,
374,
11875,
8,
14022,
395,
298,
2062,
440,
365,
11875,
531,
398,
327,
22535,
314,
19001,
14,
267,
291,
14,
68,
14,
3584,
342,
267,
2150,
291,
14,
65,
5873,
267,
2150,
291,
14,
66,
5873,
398,
367,
5048,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
291,
14,
3334,
8,
15380,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
15380,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
291,
14,
3334,
8,
802,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
802,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
324,
11875,
8,
277,
304,
267,
327,
2832,
9133,
1325,
440,
12701,
15988,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
625,
11875,
315,
730,
8,
19,
395,
10933,
12,
10933,
14,
374,
9931,
26,
288,
327,
859,
13,
1896,
16777,
3423,
288,
291,
14,
3334,
8,
15380,
14,
374,
9931,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
291,
14,
3334,
8,
15380,
14,
374,
11875,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
327,
31651,
14131,
3102,
288,
291,
14,
3334,
8,
802,
14,
374,
9931,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
291,
14,
3334,
8,
802,
14,
374,
11875,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
339,
347,
511,
63,
7191,
63,
305,
63,
2722,
8,
277,
304,
267,
327,
5870,
2251,
12,
7425,
15333,
436,
3992,
626,
8970,
636,
2722,
363,
267,
327,
2104,
5204,
314,
754,
1077,
506,
314,
2011,
465,
4700,
1252,
267,
327,
437,
27037,
14,
221,
710,
9149,
2793,
1133,
14722,
7003,
3595,
626,
1553,
642,
11337,
370,
267,
327,
506,
5343,
376,
4514,
2173,
723,
75,
14,
221,
24175,
315,
2018,
499,
14,
21,
12,
652,
1159,
267,
327,
440,
2549,
367,
10809,
26,
221,
10933,
3544,
30313,
10809,
701,
790,
3063,
27,
2544,
12,
267,
327,
652,
3355,
282,
1211,
2929,
340,
436,
1454,
340,
314,
2929,
1415,
267,
327,
3663,
2385,
14
] |
[
10933,
199,
646,
511,
14,
396,
63,
4058,
199,
646,
2882,
199,
646,
511,
14,
396,
63,
409,
199,
199,
893,
26,
272,
15439,
275,
2649,
199,
2590,
12746,
26,
272,
347,
15439,
8,
88,
304,
267,
372,
671,
199,
199,
3,
769,
12,
2008,
436,
1211,
9180,
626,
886,
503,
2793,
1133,
8970,
636,
2722,
363,
199,
533,
769,
18,
8,
513,
304,
272,
986,
199,
199,
533,
769,
19,
8,
513,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
769,
855,
2722,
721,
277,
9,
199,
199,
533,
2008,
18,
8,
2960,
304,
272,
986,
199,
199,
533,
2008,
19,
8,
2960,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
2008,
855,
2722,
721,
277,
9,
199,
199,
533,
1211,
18,
8,
807,
304,
272,
986,
199,
199,
533,
1211,
19,
8,
807,
304,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
1211,
855,
2722,
721,
277,
9,
199,
199,
533,
8133,
1746,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
65,
275,
1425,
8,
1960,
9,
267,
291,
14,
66,
275,
1425,
8,
1840,
9,
267,
291,
14,
65,
1988,
713,
61,
275,
291,
14,
66,
339,
347,
511,
63,
4316,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
79,
16189,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
5048,
315,
334,
18,
12,
499,
14,
16,
12,
499,
74,
12,
298,
3175,
401,
359,
19,
467,
334,
18,
12,
18,
395,
469,
19,
26,
650,
1386,
15439,
480,
89,
525,
1187,
525,
65,
1288,
2151,
291,
14,
65,
12,
291,
14,
66,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
291,
14,
3334,
8,
15380,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
15380,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
291,
14,
3334,
8,
802,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
802,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
75,
1397,
471,
8,
277,
304,
267,
327,
7635,
1275,
374,
9931,
342,
436,
1275,
374,
11875,
342,
336,
15,
16189,
267,
327,
377,
1873,
282,
1022,
1397,
14,
267,
291,
14,
66,
59,
1822,
61,
275,
291,
14,
65,
267,
327,
3194,
385,
89,
1211,
14,
267,
291,
14,
68,
275,
1052,
267,
291,
14,
68,
59,
16,
61,
275,
291,
14,
68,
59,
17,
61,
275,
291,
14,
68,
59,
18,
61,
275,
291,
14,
68,
398,
11618,
275,
10933,
14,
27153,
14131,
342,
398,
367,
284,
346,
89,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
291,
14,
1815,
8,
15380,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
291,
14,
3334,
8,
15380,
14,
374,
11875,
8,
14022,
395,
298,
2062,
440,
365,
11875,
531,
288,
291,
14,
1815,
8,
802,
14,
374,
9931,
8,
14022,
395,
298,
2062,
365,
9931,
531,
288,
291,
14,
3334,
8,
802,
14,
374,
11875,
8,
14022,
395,
298,
2062,
440,
365,
11875,
531,
398,
327,
22535,
314,
19001,
14,
267,
291,
14,
68,
14,
3584,
342,
267,
2150,
291,
14,
65,
5873,
267,
2150,
291,
14,
66,
5873,
398,
367,
5048,
315,
291,
14,
65,
12,
291,
14,
66,
12,
291,
14,
68,
12,
334,
277,
14,
68,
12,
291,
14,
68,
304,
288,
327,
859,
13,
1896,
16777,
3423,
288,
291,
14,
3334,
8,
15380,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
15380,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
327,
31651,
14131,
3102,
288,
291,
14,
3334,
8,
802,
14,
374,
9931,
8,
3489,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
3489,
4641,
288,
291,
14,
1815,
8,
802,
14,
374,
11875,
8,
3489,
395,
1169,
298,
2062,
365,
11875,
367,
450,
82,
2,
450,
334,
3489,
4641,
339,
347,
511,
63,
324,
11875,
8,
277,
304,
267,
327,
2832,
9133,
1325,
440,
12701,
15988,
267,
11618,
275,
10933,
14,
27153,
14131,
342,
267,
367,
625,
11875,
315,
730,
8,
19,
395,
10933,
12,
10933,
14,
374,
9931,
26,
288,
327,
859,
13,
1896,
16777,
3423,
288,
291,
14,
3334,
8,
15380,
14,
374,
9931,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
291,
14,
3334,
8,
15380,
14,
374,
11875,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
327,
31651,
14131,
3102,
288,
291,
14,
3334,
8,
802,
14,
374,
9931,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
9931,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
288,
291,
14,
3334,
8,
802,
14,
374,
11875,
8,
324,
11875,
395,
2490,
298,
2062,
440,
365,
11875,
367,
450,
82,
2,
450,
334,
324,
11875,
4641,
339,
347,
511,
63,
7191,
63,
305,
63,
2722,
8,
277,
304,
267,
327,
5870,
2251,
12,
7425,
15333,
436,
3992,
626,
8970,
636,
2722,
363,
267,
327,
2104,
5204,
314,
754,
1077,
506,
314,
2011,
465,
4700,
1252,
267,
327,
437,
27037,
14,
221,
710,
9149,
2793,
1133,
14722,
7003,
3595,
626,
1553,
642,
11337,
370,
267,
327,
506,
5343,
376,
4514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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
gedare/gem5
|
src/arch/x86/isa/insts/system/invlpg.py
|
84
|
2383
|
# Copyright (c) 2007-2008 The Hewlett-Packard Development Company
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Copyright (c) 2008 The Regents of The University of Michigan
# 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 the copyright holders 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.
#
# Authors: Gabe Black
microcode = '''
def macroop INVLPG_M {
.serializing
tia seg, sib, disp
};
def macroop INVLPG_P {
.serializing
rdip t7
tia seg, riprel, disp
};
'''
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
13,
9300,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
9079,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
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,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
1621,
54,
9257,
39,
63,
45,
469,
272,
1275,
2171,
9147,
272,
3367,
65,
8812,
12,
20417,
12,
9628,
199,
12084,
199,
199,
318,
21308,
1621,
54,
9257,
39,
63,
48,
469,
272,
1275,
2171,
9147,
272,
519,
21846,
307,
23,
272,
3367,
65,
8812,
12,
8012,
30788,
12,
9628,
199,
12084,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
10219,
13,
9300,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
9079,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
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,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
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,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
6453,
600,
275,
1449,
199,
318,
21308,
1621,
54,
9257,
39,
63,
45,
469,
272,
1275,
2171,
9147,
272,
3367,
65,
8812,
12,
20417,
12,
9628,
199,
12084,
199,
199,
318,
21308,
1621,
54,
9257,
39,
63,
48,
469,
272,
1275,
2171,
9147,
272,
519,
21846,
307,
23,
272,
3367,
65,
8812,
12,
8012,
30788,
12,
9628,
199,
12084,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Tchanders/socorro
|
socorro/cron/jobs/truncate_partitions.py
|
9
|
1248
|
# 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/.
from configman import Namespace
from crontabber.base import BaseCronApp
from crontabber.mixins import (
with_postgres_transactions,
with_single_postgres_transaction,
)
@with_postgres_transactions()
@with_single_postgres_transaction()
class TruncatePartitionsCronApp(BaseCronApp):
app_name = 'truncate-partitions'
app_version = '1.0'
app_description = """See
http://socorro.readthedocs.org/en/latest/development
/databaseadminfunctions.html#truncate-partitions
See https://bugzilla.mozilla.org/show_bug.cgi?id=1117911
"""
required_config = Namespace()
required_config.add_option(
'weeks_to_keep',
default=2, # 2 weeks is sufficient for a backfill range if need be
doc='Number of weeks of raw crash data to keep in Postgres')
def run(self, connection):
cursor = connection.cursor()
# Casting to date because stored procs in psql are strongly typed.
cursor.execute(
"select truncate_partitions(%s)", (self.config.weeks_to_keep,)
)
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
504,
1101,
1237,
492,
19317,
199,
504,
2467,
1888,
20280,
14,
1095,
492,
3523,
35,
2641,
2640,
199,
504,
2467,
1888,
20280,
14,
30192,
492,
334,
272,
543,
63,
10675,
63,
13754,
12,
272,
543,
63,
4780,
63,
10675,
63,
5945,
12,
199,
9,
421,
199,
32,
1045,
63,
10675,
63,
13754,
342,
199,
32,
1045,
63,
4780,
63,
10675,
63,
5945,
342,
199,
533,
25594,
1411,
23921,
35,
2641,
2640,
8,
1563,
35,
2641,
2640,
304,
272,
1145,
63,
354,
275,
283,
12517,
13,
12553,
7,
272,
1145,
63,
1023,
275,
283,
17,
14,
16,
7,
272,
1145,
63,
1802,
275,
408,
9295,
272,
1455,
921,
83,
28720,
293,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
31688,
272,
1182,
4659,
2113,
5777,
14,
1360,
3,
12517,
13,
12553,
272,
1666,
4178,
921,
29220,
14,
12102,
14,
1308,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
845,
10699,
845,
272,
408,
272,
1415,
63,
888,
275,
19317,
342,
272,
1415,
63,
888,
14,
525,
63,
1422,
8,
267,
283,
25287,
63,
475,
63,
3250,
297,
267,
849,
29,
18,
12,
221,
327,
499,
29540,
365,
19258,
367,
282,
1771,
4498,
1425,
340,
1929,
506,
267,
1382,
534,
3259,
402,
29540,
402,
3066,
12420,
666,
370,
4215,
315,
7711,
7266,
358,
339,
347,
1255,
8,
277,
12,
1950,
304,
267,
3920,
275,
1950,
14,
3937,
342,
267,
327,
445,
1810,
316,
370,
1434,
2952,
5489,
557,
1259,
315,
299,
3009,
787,
30390,
20041,
14,
267,
3920,
14,
2526,
8,
288,
298,
2416,
14547,
63,
12553,
4042,
83,
4186,
334,
277,
14,
888,
14,
25287,
63,
475,
63,
3250,
4258,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
504,
1101,
1237,
492,
19317,
199,
504,
2467,
1888,
20280,
14,
1095,
492,
3523,
35,
2641,
2640,
199,
504,
2467,
1888,
20280,
14,
30192,
492,
334,
272,
543,
63,
10675,
63,
13754,
12,
272,
543,
63,
4780,
63,
10675,
63,
5945,
12,
199,
9,
421,
199,
32,
1045,
63,
10675,
63,
13754,
342,
199,
32,
1045,
63,
4780,
63,
10675,
63,
5945,
342,
199,
533,
25594,
1411,
23921,
35,
2641,
2640,
8,
1563,
35,
2641,
2640,
304,
272,
1145,
63,
354,
275,
283,
12517,
13,
12553,
7,
272,
1145,
63,
1023,
275,
283,
17,
14,
16,
7,
272,
1145,
63,
1802,
275,
408,
9295,
272,
1455,
921,
83,
28720,
293,
14,
25085,
14,
1308,
15,
287,
15,
7410,
15,
31688,
272,
1182,
4659,
2113,
5777,
14,
1360,
3,
12517,
13,
12553,
272,
1666,
4178,
921,
29220,
14,
12102,
14,
1308,
15,
2384,
63,
1266,
14,
13814,
31,
344,
29,
845,
10699,
845,
272,
408,
272,
1415,
63,
888,
275,
19317,
342,
272,
1415,
63,
888,
14,
525,
63,
1422,
8,
267,
283,
25287,
63,
475,
63,
3250,
297,
267,
849,
29,
18,
12,
221,
327,
499,
29540,
365,
19258,
367,
282,
1771,
4498,
1425,
340,
1929,
506,
267,
1382,
534,
3259,
402,
29540,
402,
3066,
12420,
666,
370,
4215,
315,
7711,
7266,
358,
339,
347,
1255,
8,
277,
12,
1950,
304,
267,
3920,
275,
1950,
14,
3937,
342,
267,
327,
445,
1810,
316,
370,
1434,
2952,
5489,
557,
1259,
315,
299,
3009,
787,
30390,
20041,
14,
267,
3920,
14,
2526,
8,
288,
298,
2416,
14547,
63,
12553,
4042,
83,
4186,
334,
277,
14,
888,
14,
25287,
63,
475,
63,
3250,
4258,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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three init scripts, the third one
# runs when the gui is up
#***************************************************************************
#* Copyright (c) 2002 Juergen Riegel <juergen.riegel@web.de> *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************/
class RaytracingWorkbench ( Workbench ):
"Raytracing workbench object"
def __init__(self):
self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Raytracing/Resources/icons/RaytracingWorkbench.svg"
self.__class__.MenuText = "Raytracing"
self.__class__.ToolTip = "Raytracing workbench"
def Initialize(self):
# load the module
import PartGui
import RaytracingGui
def GetClassName(self):
return "RaytracingGui::Workbench"
Gui.addWorkbench(RaytracingWorkbench())
FreeCAD.addImportType("Povray format (*.pov *.inc)","RaytracingGui")
|
lgpl-2.1
|
[
3,
30703,
21635,
11621,
4205,
859,
202,
199,
3,
334,
67,
9,
13004,
1603,
14262,
2268,
820,
1873,
24920,
202,
199,
3,
202,
199,
3,
19634,
316,
1006,
314,
2556,
370,
1343,
20914,
202,
199,
3,
961,
365,
314,
3499,
1373,
402,
7795,
4205,
10554,
12,
314,
10919,
1373,
202,
199,
3,
7858,
1380,
314,
11621,
365,
1536,
2999,
199,
3,
17623,
202,
199,
15002,
257,
1898,
334,
67,
9,
14790,
1603,
14262,
2268,
820,
1873,
24920,
665,
74,
14262,
2268,
14,
11317,
24920,
32,
2520,
14,
271,
30,
3777,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
570,
365,
1777,
402,
314,
20914,
7240,
88,
16367,
2656,
14,
4519,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
202,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
202,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
202,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
202,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
20914,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
3322,
627,
202,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
202,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
202,
199,
15002,
257,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
7861,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
202,
199,
15002,
257,
844,
3180,
543,
20914,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
263,
627,
202,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
202,
199,
15002,
257,
8217,
6208,
257,
627,
202,
199,
15002,
17997,
627,
202,
199,
3,
17623,
15,
1223,
8065,
199,
533,
30703,
21635,
6517,
16571,
334,
9361,
16571,
3461,
1128,
298,
25474,
21635,
1736,
16571,
909,
2,
1128,
347,
636,
826,
721,
277,
304,
1039,
291,
855,
533,
4343,
8954,
275,
20914,
14,
362,
4031,
3567,
342,
435,
298,
9871,
15,
25474,
21635,
15,
13745,
15,
16471,
15,
25474,
21635,
6517,
16571,
14,
10273,
2,
1039,
291,
855,
533,
4343,
5977,
1872,
275,
298,
25474,
21635,
2,
1039,
291,
855,
533,
4343,
21784,
275,
298,
25474,
21635,
1736,
16571,
2,
2958,
347,
11578,
8,
277,
304,
1039,
327,
2248,
314,
859,
1039,
492,
14320,
4324,
1039,
492,
30703,
21635,
4324,
1128,
347,
2372,
23200,
8,
277,
304,
1039,
372,
298,
25474,
21635,
4324,
447,
6517,
16571,
2,
2999,
199,
4324,
14,
525,
6517,
16571,
8,
25474,
21635,
6517,
16571,
1012,
2999,
199,
10146,
17238,
14,
525,
6295,
804,
480,
1575,
86,
803,
1475,
334,
4856,
555,
86,
23588,
6559,
9,
2266,
25474,
21635,
4324,
531,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
30703,
21635,
11621,
4205,
859,
202,
199,
3,
334,
67,
9,
13004,
1603,
14262,
2268,
820,
1873,
24920,
202,
199,
3,
202,
199,
3,
19634,
316,
1006,
314,
2556,
370,
1343,
20914,
202,
199,
3,
961,
365,
314,
3499,
1373,
402,
7795,
4205,
10554,
12,
314,
10919,
1373,
202,
199,
3,
7858,
1380,
314,
11621,
365,
1536,
2999,
199,
3,
17623,
202,
199,
15002,
257,
1898,
334,
67,
9,
14790,
1603,
14262,
2268,
820,
1873,
24920,
665,
74,
14262,
2268,
14,
11317,
24920,
32,
2520,
14,
271,
30,
3777,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
570,
365,
1777,
402,
314,
20914,
7240,
88,
16367,
2656,
14,
4519,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
202,
199,
15002,
257,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
44,
12006,
9,
259,
627,
202,
199,
15002,
257,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
258,
627,
202,
199,
15002,
257,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
7861,
627,
202,
199,
15002,
257,
367,
10093,
1937,
314,
5059,
6013,
1318,
570,
14,
2476,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
20914,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
3322,
627,
202,
199,
15002,
257,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
263,
627,
202,
199,
15002,
257,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
260,
627,
202,
199,
15002,
257,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
7861,
627,
202,
199,
15002,
17997,
627,
202,
199,
15002,
257,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
258,
627,
202,
199,
15002,
257,
844,
3180,
543,
20914,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
263,
627,
202,
199,
15002,
257,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
627,
202,
199,
15002,
257,
8217,
6208,
257,
627,
202,
199,
15002,
17997,
627,
202,
199,
3,
17623,
15,
1223,
8065,
199,
533,
30703,
21635,
6517,
16571,
334,
9361,
16571,
3461,
1128,
298,
25474,
21635,
1736,
16571,
909,
2,
1128,
347,
636,
826,
721,
277,
304,
1039,
291,
855,
533,
4343,
8954,
275,
20914,
14,
362,
4031,
3567,
342,
435,
298,
9871,
15,
25474,
21635,
15,
13745,
15,
16471,
15,
25474,
21635,
6517,
16571,
14,
10273,
2,
1039,
291,
855,
533,
4343,
5977,
1872,
275,
298,
25474,
21635,
2,
1039,
291,
855,
533,
4343,
21784,
275,
298,
25474,
21635,
1736,
16571,
2,
2958,
347,
11578,
8,
277,
304,
1039,
327,
2248,
314,
859,
1039,
492,
14320,
4324,
1039,
492,
30703,
21635,
4324,
1128,
347,
2372,
23200,
8,
277,
304,
1039,
372,
298,
25474,
21635,
4324,
447,
6517,
16571,
2,
2999,
199,
4324,
14,
525,
6517,
16571,
8,
25474,
21635,
6517,
16571,
1012,
2999,
199,
10146,
17238,
14,
525,
6295,
804,
480,
1575,
86,
803,
1475,
334,
4856,
555,
86,
23588,
6559,
9,
2266,
25474,
21635,
4324,
531,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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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
] |
HackPartners/bigdatadarwin
|
tests/test_schedule.py
|
2
|
3060
|
import os
import sys
sys.path.append(os.getcwd())
import pytest
import darwinpush.xb.pushport as pp
from darwinpush.messagefactories.xml import ScheduleXMLMessageFactory
import datetime
# set environment variables to the test database
try_envs = ["DARWINPUSH_DBUSER", "DARWINPUSH_DBPASS", "DARWINPUSH_DBNAME"]
for k in try_envs:
r = os.getenv("TEST_" + k, None)
if r is not None:
os.environ[k] = r
from ex import MyListener, db
from models import Schedule, CallingPoint
def setup_module():
print("Resetting database")
db.create_tables([Schedule, CallingPoint], safe=True)
def teardown_module():
""" Remove the tables so the db is always ready for tests. """
print("Removing all tables")
db.drop_tables([Schedule, CallingPoint])
class TestSchedule:
def from_file(self, file_path):
"""Get schedule message from file."""
with open(file_path) as f:
x = f.read()
r = pp.CreateFromDocument(x)
assert(None is r.sR)
assert(None is not r.uR)
assert(1 == len(r.uR.schedule))
s = ScheduleXMLMessageFactory.build(r.uR.schedule[0], r, x)
return s
def test_duplicate_update(self):
"""Test whether duplicates are actually updated or re-inserted."""
initial = self.from_file("tests/data/schedule_initial.xml")
duplicate = self.from_file("tests/data/schedule_duplicate.xml")
# just to be sure
assert(initial.uid == duplicate.uid)
assert(initial.rid == duplicate.rid)
# force messages directly to listener
listener = MyListener(None, None)
listener.on_schedule_message(initial)
res = Schedule.select().where(
(Schedule.uid==initial.uid) & (Schedule.rid==initial.rid)
)
assert(res.count() == 1)
s = res[0]
assert(s.uid == initial.uid)
assert(s.rid == initial.rid)
assert(s.toc_code == initial.toc_code)
cps = CallingPoint.select().where(
CallingPoint.schedule==s
).order_by(CallingPoint.id.asc())
assert(cps.count() == 2)
destination_cp = cps[1]
assert(destination_cp.public_arrival == datetime.time(
hour=10,
minute=14))
listener.on_schedule_message(duplicate)
res = Schedule.select().where(
(Schedule.uid==initial.uid) & (Schedule.rid==initial.rid)
)
assert(res.count() == 1)
s_after = res[0]
assert(s_after.uid == initial.uid) # same uid
assert(s_after.rid == initial.rid) # same rid
assert(s_after.toc_code == duplicate.toc_code) # different toc
# get calling points
cps = CallingPoint.select().where(
CallingPoint.schedule == s_after
).order_by(CallingPoint.id.asc())
assert(cps.count() == 2) # should be only two
destination_cp = cps[1]
assert(destination_cp.public_arrival == datetime.time(
hour=10,
minute=17)) # updated time
|
apache-2.0
|
[
646,
747,
199,
646,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
9458,
1012,
199,
199,
646,
4613,
199,
199,
646,
366,
22822,
5335,
14,
1774,
14,
5335,
719,
465,
11618,
199,
504,
366,
22822,
5335,
14,
1188,
15406,
14,
1652,
492,
24317,
4317,
2209,
2927,
199,
646,
2197,
199,
199,
3,
663,
3734,
2860,
370,
314,
511,
3050,
199,
893,
63,
27900,
275,
2097,
36,
689,
7941,
21378,
63,
2846,
3791,
401,
298,
36,
689,
7941,
21378,
63,
2846,
6909,
401,
298,
36,
689,
7941,
21378,
63,
2846,
2339,
937,
199,
199,
509,
1022,
315,
862,
63,
27900,
26,
272,
519,
275,
747,
14,
12959,
480,
2864,
12172,
435,
1022,
12,
488,
9,
272,
340,
519,
365,
440,
488,
26,
267,
747,
14,
2314,
59,
75,
61,
275,
519,
199,
199,
504,
444,
492,
4932,
10464,
12,
1592,
199,
504,
1709,
492,
24317,
12,
23892,
3428,
199,
199,
318,
3272,
63,
578,
837,
272,
870,
480,
497,
6031,
3050,
531,
339,
1592,
14,
981,
63,
5987,
779,
15535,
12,
23892,
3428,
467,
5048,
29,
549,
9,
199,
199,
318,
17558,
63,
578,
837,
272,
408,
5852,
314,
6716,
880,
314,
1592,
365,
3544,
10144,
367,
2295,
14,
408,
272,
870,
480,
23420,
1006,
6716,
531,
272,
1592,
14,
4824,
63,
5987,
779,
15535,
12,
23892,
3428,
566,
199,
199,
533,
1379,
15535,
26,
339,
347,
687,
63,
493,
8,
277,
12,
570,
63,
515,
304,
267,
408,
1002,
8732,
1245,
687,
570,
1041,
267,
543,
1551,
8,
493,
63,
515,
9,
465,
289,
26,
288,
671,
275,
289,
14,
739,
342,
288,
519,
275,
11618,
14,
2499,
2532,
5564,
8,
88,
9,
288,
702,
8,
403,
365,
519,
14,
83,
50,
9,
288,
702,
8,
403,
365,
440,
519,
14,
85,
50,
9,
288,
702,
8,
17,
508,
822,
8,
82,
14,
85,
50,
14,
7211,
430,
953,
308,
275,
24317,
4317,
2209,
2927,
14,
1506,
8,
82,
14,
85,
50,
14,
7211,
59,
16,
467,
519,
12,
671,
9,
288,
372,
308,
339,
347,
511,
63,
11081,
63,
873,
8,
277,
304,
267,
408,
774,
3775,
15755,
787,
5965,
4588,
503,
295,
13,
28565,
1041,
398,
2536,
275,
291,
14,
504,
63,
493,
480,
2219,
15,
576,
15,
7211,
63,
2747,
14,
1652,
531,
267,
9250,
275,
291,
14,
504,
63,
493,
480,
2219,
15,
576,
15,
7211,
63,
11081,
14,
1652,
531,
398,
327,
2951,
370,
506,
3238,
267,
702,
8,
2747,
14,
1535,
508,
9250,
14,
1535,
9,
267,
702,
8,
2747,
14,
1677,
508,
9250,
14,
1677,
9,
398,
327,
3542,
3788,
5370,
370,
11647,
267,
11647,
275,
4932,
10464,
8,
403,
12,
488,
9,
398,
11647,
14,
265,
63,
7211,
63,
1188,
8,
2747,
9,
398,
522,
275,
24317,
14,
2416,
1252,
4509,
8,
288,
334,
15535,
14,
1535,
389,
2747,
14,
1535,
9,
1253,
334,
15535,
14,
1677,
389,
2747,
14,
1677,
9,
267,
776,
398,
702,
8,
470,
14,
835,
342,
508,
413,
9,
267,
308,
275,
522,
59,
16,
61,
267,
702,
8,
83,
14,
1535,
508,
2536,
14,
1535,
9,
267,
702,
8,
83,
14,
1677,
508,
2536,
14,
1677,
9,
267,
702,
8,
83,
14,
13255,
63,
600,
508,
2536,
14,
13255,
63,
600,
9,
398,
286,
1190,
275,
23892,
3428,
14,
2416,
1252,
4509,
8,
288,
23892,
3428,
14,
7211,
389,
83,
267,
7092,
1648,
63,
991,
8,
23796,
3428,
14,
344,
14,
10125,
1012,
398,
702,
8,
67,
1190,
14,
835,
342,
508,
499,
9,
267,
5724,
63,
1850,
275,
286,
1190,
59,
17,
61,
267,
702,
8,
6881,
63,
1850,
14,
3455,
63,
285,
26976,
508,
2197,
14,
521,
8,
288,
6925,
29,
709,
12,
288,
12709,
29,
1079,
430,
398,
11647,
14,
265,
63,
7211,
63,
1188,
8,
11081,
9,
398,
522,
275,
24317,
14,
2416,
1252,
4509,
8,
288,
334,
15535,
14,
1535,
389,
2747,
14,
1535,
9,
1253,
334,
15535,
14,
1677,
389,
2747,
14,
1677,
9,
267,
776,
398,
702,
8,
470,
14,
835,
342,
508,
413,
9,
267,
308,
63,
4399,
275,
522,
59,
16,
61,
267,
702,
8,
83,
63,
4399,
14,
1535,
508,
2536,
14,
1535,
9,
327,
2011,
1747,
267,
702,
8,
83,
63,
4399,
14,
1677,
508,
2536,
14,
1677,
9,
327,
2011,
16146,
267,
702,
8,
83,
63,
4399,
14,
13255,
63,
600,
508,
9250,
14,
13255,
63,
600,
9,
327,
3365,
22021,
398,
327,
664,
6358,
4501,
267,
286,
1190,
275,
23892,
3428,
14,
2416,
1252,
4509,
8,
288,
23892,
3428,
14,
7211,
508,
308,
63,
4399,
267,
7092,
1648,
63,
991,
8,
23796,
3428,
14,
344,
14,
10125,
1012,
398,
702,
8,
67,
1190,
14,
835,
342,
508,
499,
9,
327,
1077,
506,
1454,
2877,
267,
5724,
63,
1850,
275,
286,
1190,
59,
17,
61,
267,
702,
8,
6881,
63,
1850,
14,
3455,
63,
285,
26976,
508,
2197,
14,
521,
8,
288,
6925,
29,
709,
12,
288,
12709,
29,
1196,
430,
327,
4588,
900,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
9458,
1012,
199,
199,
646,
4613,
199,
199,
646,
366,
22822,
5335,
14,
1774,
14,
5335,
719,
465,
11618,
199,
504,
366,
22822,
5335,
14,
1188,
15406,
14,
1652,
492,
24317,
4317,
2209,
2927,
199,
646,
2197,
199,
199,
3,
663,
3734,
2860,
370,
314,
511,
3050,
199,
893,
63,
27900,
275,
2097,
36,
689,
7941,
21378,
63,
2846,
3791,
401,
298,
36,
689,
7941,
21378,
63,
2846,
6909,
401,
298,
36,
689,
7941,
21378,
63,
2846,
2339,
937,
199,
199,
509,
1022,
315,
862,
63,
27900,
26,
272,
519,
275,
747,
14,
12959,
480,
2864,
12172,
435,
1022,
12,
488,
9,
272,
340,
519,
365,
440,
488,
26,
267,
747,
14,
2314,
59,
75,
61,
275,
519,
199,
199,
504,
444,
492,
4932,
10464,
12,
1592,
199,
504,
1709,
492,
24317,
12,
23892,
3428,
199,
199,
318,
3272,
63,
578,
837,
272,
870,
480,
497,
6031,
3050,
531,
339,
1592,
14,
981,
63,
5987,
779,
15535,
12,
23892,
3428,
467,
5048,
29,
549,
9,
199,
199,
318,
17558,
63,
578,
837,
272,
408,
5852,
314,
6716,
880,
314,
1592,
365,
3544,
10144,
367,
2295,
14,
408,
272,
870,
480,
23420,
1006,
6716,
531,
272,
1592,
14,
4824,
63,
5987,
779,
15535,
12,
23892,
3428,
566,
199,
199,
533,
1379,
15535,
26,
339,
347,
687,
63,
493,
8,
277,
12,
570,
63,
515,
304,
267,
408,
1002,
8732,
1245,
687,
570,
1041,
267,
543,
1551,
8,
493,
63,
515,
9,
465,
289,
26,
288,
671,
275,
289,
14,
739,
342,
288,
519,
275,
11618,
14,
2499,
2532,
5564,
8,
88,
9,
288,
702,
8,
403,
365,
519,
14,
83,
50,
9,
288,
702,
8,
403,
365,
440,
519,
14,
85,
50,
9,
288,
702,
8,
17,
508,
822,
8,
82,
14,
85,
50,
14,
7211,
430,
953,
308,
275,
24317,
4317,
2209,
2927,
14,
1506,
8,
82,
14,
85,
50,
14,
7211,
59,
16,
467,
519,
12,
671,
9,
288,
372,
308,
339,
347,
511,
63,
11081,
63,
873,
8,
277,
304,
267,
408,
774,
3775,
15755,
787,
5965,
4588,
503,
295,
13,
28565,
1041,
398,
2536,
275,
291,
14,
504,
63,
493,
480,
2219,
15,
576,
15,
7211,
63,
2747,
14,
1652,
531,
267,
9250,
275,
291,
14,
504,
63,
493,
480,
2219,
15,
576,
15,
7211,
63,
11081,
14,
1652,
531,
398,
327,
2951,
370,
506,
3238,
267,
702,
8,
2747,
14,
1535,
508,
9250,
14,
1535,
9,
267,
702,
8,
2747,
14,
1677,
508,
9250,
14,
1677,
9,
398,
327,
3542,
3788,
5370,
370,
11647,
267,
11647,
275,
4932,
10464,
8,
403,
12,
488,
9,
398,
11647,
14,
265,
63,
7211,
63,
1188,
8,
2747,
9,
398,
522,
275,
24317,
14,
2416,
1252,
4509,
8,
288,
334,
15535,
14,
1535,
389,
2747,
14,
1535,
9,
1253,
334,
15535,
14,
1677,
389,
2747,
14,
1677,
9,
267,
776,
398,
702,
8,
470,
14,
835,
342,
508,
413,
9,
267,
308,
275,
522,
59,
16,
61,
267,
702,
8,
83,
14,
1535,
508,
2536,
14,
1535,
9,
267,
702,
8,
83,
14,
1677,
508,
2536,
14,
1677,
9,
267,
702,
8,
83,
14,
13255,
63,
600,
508,
2536,
14,
13255,
63,
600,
9,
398,
286,
1190,
275,
23892,
3428,
14,
2416,
1252,
4509,
8,
288,
23892,
3428,
14,
7211,
389,
83,
267,
7092,
1648,
63,
991,
8,
23796,
3428,
14,
344,
14,
10125,
1012,
398,
702,
8,
67,
1190,
14,
835,
342,
508,
499,
9,
267,
5724,
63,
1850,
275,
286,
1190,
59,
17,
61,
267,
702,
8,
6881,
63,
1850,
14,
3455,
63,
285,
26976,
508,
2197,
14,
521,
8,
288,
6925,
29,
709,
12,
288,
12709,
29,
1079,
430,
398,
11647,
14,
265,
63,
7211,
63,
1188,
8,
11081,
9,
398,
522,
275,
24317,
14,
2416,
1252,
4509,
8,
288,
334,
15535,
14,
1535,
389,
2747,
14,
1535,
9,
1253,
334,
15535,
14,
1677,
389,
2747,
14,
1677,
9,
267,
776,
398,
702,
8,
470,
14,
835,
342,
508,
413,
9,
267,
308,
63,
4399,
275,
522,
59,
16,
61,
267,
702,
8,
83,
63,
4399,
14,
1535,
508,
2536,
14,
1535,
9,
327,
2011,
1747,
267,
702,
8,
83,
63,
4399,
14,
1677,
508,
2536,
14,
1677,
9,
327,
2011,
16146,
267,
702,
8,
83,
63,
4399,
14,
13255,
63,
600,
508,
9250,
14,
13255,
63,
600,
9,
327,
3365,
22021,
398,
327,
664,
6358,
4501,
267,
286,
1190,
275,
23892,
3428,
14,
2416,
1252,
4509,
8,
288,
23892,
3428,
14,
7211,
508,
308,
63,
4399,
267,
7092,
1648,
63,
991,
8,
23796,
3428,
14,
344,
14,
10125,
1012,
398,
702,
8,
67,
1190,
14,
835,
342,
508,
499,
9,
327,
1077,
506,
1454,
2877,
267,
5724,
63,
1850,
275,
286,
1190,
59,
17,
61,
267,
702,
8,
6881,
63,
1850,
14,
3455,
63,
285,
26976,
508,
2197,
14,
521,
8,
288,
6925,
29,
709,
12,
288,
12709,
29,
1196,
430,
327,
4588,
900,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tkingless/webtesting
|
venvs/tutorials/lib/python2.7/site-packages/pip/commands/search.py
|
78
|
4816
|
from __future__ import absolute_import
import logging
import sys
import textwrap
from pip.basecommand import Command, SUCCESS
from pip.download import PipXmlrpcTransport
from pip.models import PyPI
from pip.utils import get_terminal_size
from pip.utils.logging import indent_log
from pip.exceptions import CommandError
from pip.status_codes import NO_MATCHES_FOUND
from pip._vendor import pkg_resources
from pip._vendor.six.moves import xmlrpc_client
logger = logging.getLogger(__name__)
class SearchCommand(Command):
"""Search for PyPI packages whose name or summary contains <query>."""
name = 'search'
usage = """
%prog [options] <query>"""
summary = 'Search PyPI for packages.'
def __init__(self, *args, **kw):
super(SearchCommand, self).__init__(*args, **kw)
self.cmd_opts.add_option(
'--index',
dest='index',
metavar='URL',
default=PyPI.pypi_url,
help='Base URL of Python Package Index (default %default)')
self.parser.insert_option_group(0, self.cmd_opts)
def run(self, options, args):
if not args:
raise CommandError('Missing required argument (search query).')
query = args
pypi_hits = self.search(query, options)
hits = transform_hits(pypi_hits)
terminal_width = None
if sys.stdout.isatty():
terminal_width = get_terminal_size()[0]
print_results(hits, terminal_width=terminal_width)
if pypi_hits:
return SUCCESS
return NO_MATCHES_FOUND
def search(self, query, options):
index_url = options.index
with self._build_session(options) as session:
transport = PipXmlrpcTransport(index_url, session)
pypi = xmlrpc_client.ServerProxy(index_url, transport)
hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits
def transform_hits(hits):
"""
The list from pypi is really a list of versions. We want a list of
packages with the list of versions stored inline. This converts the
list from pypi into one we can use.
"""
packages = {}
for hit in hits:
name = hit['name']
summary = hit['summary']
version = hit['version']
score = hit['_pypi_ordering']
if score is None:
score = 0
if name not in packages.keys():
packages[name] = {
'name': name,
'summary': summary,
'versions': [version],
'score': score,
}
else:
packages[name]['versions'].append(version)
# if this is the highest version, replace summary and score
if version == highest_version(packages[name]['versions']):
packages[name]['summary'] = summary
packages[name]['score'] = score
# each record has a unique name now, so we will convert the dict into a
# list sorted by score
package_list = sorted(
packages.values(),
key=lambda x: x['score'],
reverse=True,
)
return package_list
def print_results(hits, name_column_width=None, terminal_width=None):
if not hits:
return
if name_column_width is None:
name_column_width = max([
len(hit['name']) + len(hit.get('versions', ['-'])[-1])
for hit in hits
]) + 4
installed_packages = [p.project_name for p in pkg_resources.working_set]
for hit in hits:
name = hit['name']
summary = hit['summary'] or ''
version = hit.get('versions', ['-'])[-1]
if terminal_width is not None:
target_width = terminal_width - name_column_width - 5
if target_width > 10:
# wrap and indent summary to fit terminal
summary = textwrap.wrap(summary, target_width)
summary = ('\n' + ' ' * (name_column_width + 3)).join(summary)
line = '%-*s - %s' % (name_column_width,
'%s (%s)' % (name, version), summary)
try:
logger.info(line)
if name in installed_packages:
dist = pkg_resources.get_distribution(name)
with indent_log():
latest = highest_version(hit['versions'])
if dist.version == latest:
logger.info('INSTALLED: %s (latest)', dist.version)
else:
logger.info('INSTALLED: %s', dist.version)
logger.info('LATEST: %s', latest)
except UnicodeEncodeError:
pass
def highest_version(versions):
return next(iter(
sorted(versions, key=pkg_resources.parse_version, reverse=True)
))
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
984,
199,
646,
13390,
199,
199,
504,
7305,
14,
1095,
1531,
492,
5817,
12,
28364,
199,
504,
7305,
14,
4249,
492,
510,
711,
8672,
4354,
7836,
199,
504,
7305,
14,
992,
492,
24330,
199,
504,
7305,
14,
1208,
492,
664,
63,
12010,
63,
890,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
3924,
492,
14393,
199,
504,
7305,
14,
1205,
63,
6021,
492,
4825,
63,
14747,
654,
63,
13945,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
15432,
63,
1258,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
8730,
3110,
8,
3110,
304,
272,
408,
5278,
367,
24330,
6117,
7447,
536,
503,
6212,
3509,
665,
1131,
30,
1041,
272,
536,
275,
283,
1733,
7,
272,
4503,
275,
408,
489,
450,
6595,
359,
1419,
61,
665,
1131,
11193,
272,
6212,
275,
283,
5278,
24330,
367,
6117,
3530,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
1613,
8,
5278,
3110,
12,
291,
2843,
826,
9308,
589,
12,
1011,
829,
9,
267,
291,
14,
1760,
63,
3291,
14,
525,
63,
1422,
8,
288,
2850,
1080,
297,
288,
2053,
534,
1080,
297,
288,
8214,
534,
2632,
297,
288,
849,
29,
2713,
2252,
14,
17343,
63,
633,
12,
288,
1720,
534,
1563,
2851,
402,
2018,
15665,
5499,
334,
885,
450,
885,
5942,
398,
291,
14,
2087,
14,
3176,
63,
1422,
63,
923,
8,
16,
12,
291,
14,
1760,
63,
3291,
9,
339,
347,
1255,
8,
277,
12,
1511,
12,
1249,
304,
267,
340,
440,
1249,
26,
288,
746,
14393,
360,
7718,
1415,
1423,
334,
1733,
1827,
28583,
267,
1827,
275,
1249,
267,
1134,
1038,
63,
16595,
275,
291,
14,
1733,
8,
1131,
12,
1511,
9,
267,
19745,
275,
5793,
63,
16595,
8,
17343,
63,
16595,
9,
398,
11167,
63,
2063,
275,
488,
267,
340,
984,
14,
2703,
14,
21122,
837,
288,
11167,
63,
2063,
275,
664,
63,
12010,
63,
890,
3430,
16,
61,
398,
870,
63,
2604,
8,
16595,
12,
11167,
63,
2063,
29,
12010,
63,
2063,
9,
267,
340,
1134,
1038,
63,
16595,
26,
288,
372,
28364,
267,
372,
4825,
63,
14747,
654,
63,
13945,
339,
347,
2754,
8,
277,
12,
1827,
12,
1511,
304,
267,
1478,
63,
633,
275,
1511,
14,
1080,
267,
543,
291,
423,
1506,
63,
1730,
8,
1419,
9,
465,
2351,
26,
288,
7773,
275,
510,
711,
8672,
4354,
7836,
8,
1080,
63,
633,
12,
2351,
9,
288,
1134,
1038,
275,
15432,
63,
1258,
14,
3120,
4936,
8,
1080,
63,
633,
12,
7773,
9,
288,
19745,
275,
1134,
1038,
14,
1733,
3252,
354,
356,
1827,
12,
283,
4705,
356,
1827,
1386,
283,
269,
358,
288,
372,
19745,
421,
199,
318,
5793,
63,
16595,
8,
16595,
304,
272,
408,
272,
710,
769,
687,
1134,
1038,
365,
7710,
282,
769,
402,
5459,
14,
2136,
2934,
282,
769,
402,
272,
6117,
543,
314,
769,
402,
5459,
5489,
8308,
14,
961,
15373,
314,
272,
769,
687,
1134,
1038,
1901,
1373,
781,
883,
675,
14,
272,
408,
272,
6117,
275,
1052,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
267,
1015,
275,
9793,
459,
1023,
418,
267,
5396,
275,
9793,
8680,
17343,
63,
7128,
418,
267,
340,
5396,
365,
488,
26,
288,
5396,
275,
378,
398,
340,
536,
440,
315,
6117,
14,
1612,
837,
288,
6117,
59,
354,
61,
275,
469,
355,
283,
354,
356,
536,
12,
355,
283,
4705,
356,
6212,
12,
355,
283,
6234,
356,
359,
1023,
467,
355,
283,
3397,
356,
5396,
12,
288,
789,
267,
587,
26,
288,
6117,
59,
354,
2733,
6234,
2278,
740,
8,
1023,
9,
953,
327,
340,
642,
365,
314,
15356,
1015,
12,
3350,
6212,
436,
5396,
288,
340,
1015,
508,
15356,
63,
1023,
8,
5154,
59,
354,
2733,
6234,
9090,
355,
6117,
59,
354,
2733,
4705,
418,
275,
6212,
355,
6117,
59,
354,
2733,
3397,
418,
275,
5396,
339,
327,
1924,
2777,
965,
282,
3747,
536,
3063,
12,
880,
781,
911,
3957,
314,
1211,
1901,
282,
272,
327,
769,
3355,
701,
5396,
272,
2559,
63,
513,
275,
3355,
8,
267,
6117,
14,
1459,
1062,
267,
790,
29,
2734,
671,
26,
671,
459,
3397,
995,
267,
3837,
29,
549,
12,
272,
776,
272,
372,
2559,
63,
513,
421,
199,
318,
870,
63,
2604,
8,
16595,
12,
536,
63,
2301,
63,
2063,
29,
403,
12,
11167,
63,
2063,
29,
403,
304,
272,
340,
440,
19745,
26,
267,
372,
272,
340,
536,
63,
2301,
63,
2063,
365,
488,
26,
267,
536,
63,
2301,
63,
2063,
275,
1390,
779,
288,
822,
8,
12948,
459,
354,
1105,
435,
822,
8,
12948,
14,
362,
360,
6234,
297,
11573,
1105,
1988,
17,
566,
288,
367,
9793,
315,
19745,
267,
4794,
435,
841,
339,
4903,
63,
5154,
275,
359,
80,
14,
1715,
63,
354,
367,
299,
315,
5496,
63,
4435,
14,
9818,
63,
409,
61,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
503,
2125,
267,
1015,
275,
9793,
14,
362,
360,
6234,
297,
11573,
1105,
1988,
17,
61,
267,
340,
11167,
63,
2063,
365,
440,
488,
26,
288,
1347,
63,
2063,
275,
11167,
63,
2063,
446,
536,
63,
2301,
63,
2063,
446,
959,
288,
340,
1347,
63,
2063,
690,
1616,
26,
355,
327,
4816,
436,
4363,
6212,
370,
5542,
11167,
355,
6212,
275,
13390,
14,
3823,
8,
4705,
12,
1347,
63,
2063,
9,
355,
6212,
275,
17485,
78,
7,
435,
283,
283,
627,
334,
354,
63,
2301,
63,
2063,
435,
650,
4992,
904,
8,
4705,
9,
398,
1004,
275,
1543,
13,
10,
83,
446,
450,
83,
7,
450,
334,
354,
63,
2301,
63,
2063,
12,
2892,
1543,
83,
4366,
83,
3171,
450,
334,
354,
12,
1015,
395,
6212,
9,
267,
862,
26,
288,
2512,
14,
815,
8,
604,
9,
288,
340,
536,
315,
4903,
63,
5154,
26,
355,
2917,
275,
5496,
63,
4435,
14,
362,
63,
4972,
8,
354,
9,
355,
543,
4363,
63,
793,
837,
490,
8839,
275,
15356
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2050,
199,
646,
984,
199,
646,
13390,
199,
199,
504,
7305,
14,
1095,
1531,
492,
5817,
12,
28364,
199,
504,
7305,
14,
4249,
492,
510,
711,
8672,
4354,
7836,
199,
504,
7305,
14,
992,
492,
24330,
199,
504,
7305,
14,
1208,
492,
664,
63,
12010,
63,
890,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
3924,
492,
14393,
199,
504,
7305,
14,
1205,
63,
6021,
492,
4825,
63,
14747,
654,
63,
13945,
199,
504,
7305,
423,
9884,
492,
5496,
63,
4435,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
15432,
63,
1258,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
8730,
3110,
8,
3110,
304,
272,
408,
5278,
367,
24330,
6117,
7447,
536,
503,
6212,
3509,
665,
1131,
30,
1041,
272,
536,
275,
283,
1733,
7,
272,
4503,
275,
408,
489,
450,
6595,
359,
1419,
61,
665,
1131,
11193,
272,
6212,
275,
283,
5278,
24330,
367,
6117,
3530,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
1613,
8,
5278,
3110,
12,
291,
2843,
826,
9308,
589,
12,
1011,
829,
9,
267,
291,
14,
1760,
63,
3291,
14,
525,
63,
1422,
8,
288,
2850,
1080,
297,
288,
2053,
534,
1080,
297,
288,
8214,
534,
2632,
297,
288,
849,
29,
2713,
2252,
14,
17343,
63,
633,
12,
288,
1720,
534,
1563,
2851,
402,
2018,
15665,
5499,
334,
885,
450,
885,
5942,
398,
291,
14,
2087,
14,
3176,
63,
1422,
63,
923,
8,
16,
12,
291,
14,
1760,
63,
3291,
9,
339,
347,
1255,
8,
277,
12,
1511,
12,
1249,
304,
267,
340,
440,
1249,
26,
288,
746,
14393,
360,
7718,
1415,
1423,
334,
1733,
1827,
28583,
267,
1827,
275,
1249,
267,
1134,
1038,
63,
16595,
275,
291,
14,
1733,
8,
1131,
12,
1511,
9,
267,
19745,
275,
5793,
63,
16595,
8,
17343,
63,
16595,
9,
398,
11167,
63,
2063,
275,
488,
267,
340,
984,
14,
2703,
14,
21122,
837,
288,
11167,
63,
2063,
275,
664,
63,
12010,
63,
890,
3430,
16,
61,
398,
870,
63,
2604,
8,
16595,
12,
11167,
63,
2063,
29,
12010,
63,
2063,
9,
267,
340,
1134,
1038,
63,
16595,
26,
288,
372,
28364,
267,
372,
4825,
63,
14747,
654,
63,
13945,
339,
347,
2754,
8,
277,
12,
1827,
12,
1511,
304,
267,
1478,
63,
633,
275,
1511,
14,
1080,
267,
543,
291,
423,
1506,
63,
1730,
8,
1419,
9,
465,
2351,
26,
288,
7773,
275,
510,
711,
8672,
4354,
7836,
8,
1080,
63,
633,
12,
2351,
9,
288,
1134,
1038,
275,
15432,
63,
1258,
14,
3120,
4936,
8,
1080,
63,
633,
12,
7773,
9,
288,
19745,
275,
1134,
1038,
14,
1733,
3252,
354,
356,
1827,
12,
283,
4705,
356,
1827,
1386,
283,
269,
358,
288,
372,
19745,
421,
199,
318,
5793,
63,
16595,
8,
16595,
304,
272,
408,
272,
710,
769,
687,
1134,
1038,
365,
7710,
282,
769,
402,
5459,
14,
2136,
2934,
282,
769,
402,
272,
6117,
543,
314,
769,
402,
5459,
5489,
8308,
14,
961,
15373,
314,
272,
769,
687,
1134,
1038,
1901,
1373,
781,
883,
675,
14,
272,
408,
272,
6117,
275,
1052,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
267,
1015,
275,
9793,
459,
1023,
418,
267,
5396,
275,
9793,
8680,
17343,
63,
7128,
418,
267,
340,
5396,
365,
488,
26,
288,
5396,
275,
378,
398,
340,
536,
440,
315,
6117,
14,
1612,
837,
288,
6117,
59,
354,
61,
275,
469,
355,
283,
354,
356,
536,
12,
355,
283,
4705,
356,
6212,
12,
355,
283,
6234,
356,
359,
1023,
467,
355,
283,
3397,
356,
5396,
12,
288,
789,
267,
587,
26,
288,
6117,
59,
354,
2733,
6234,
2278,
740,
8,
1023,
9,
953,
327,
340,
642,
365,
314,
15356,
1015,
12,
3350,
6212,
436,
5396,
288,
340,
1015,
508,
15356,
63,
1023,
8,
5154,
59,
354,
2733,
6234,
9090,
355,
6117,
59,
354,
2733,
4705,
418,
275,
6212,
355,
6117,
59,
354,
2733,
3397,
418,
275,
5396,
339,
327,
1924,
2777,
965,
282,
3747,
536,
3063,
12,
880,
781,
911,
3957,
314,
1211,
1901,
282,
272,
327,
769,
3355,
701,
5396,
272,
2559,
63,
513,
275,
3355,
8,
267,
6117,
14,
1459,
1062,
267,
790,
29,
2734,
671,
26,
671,
459,
3397,
995,
267,
3837,
29,
549,
12,
272,
776,
272,
372,
2559,
63,
513,
421,
199,
318,
870,
63,
2604,
8,
16595,
12,
536,
63,
2301,
63,
2063,
29,
403,
12,
11167,
63,
2063,
29,
403,
304,
272,
340,
440,
19745,
26,
267,
372,
272,
340,
536,
63,
2301,
63,
2063,
365,
488,
26,
267,
536,
63,
2301,
63,
2063,
275,
1390,
779,
288,
822,
8,
12948,
459,
354,
1105,
435,
822,
8,
12948,
14,
362,
360,
6234,
297,
11573,
1105,
1988,
17,
566,
288,
367,
9793,
315,
19745,
267,
4794,
435,
841,
339,
4903,
63,
5154,
275,
359,
80,
14,
1715,
63,
354,
367,
299,
315,
5496,
63,
4435,
14,
9818,
63,
409,
61,
272,
367,
9793,
315,
19745,
26,
267,
536,
275,
9793,
459,
354,
418,
267,
6212,
275,
9793,
459,
4705,
418,
503,
2125,
267,
1015,
275,
9793,
14,
362,
360,
6234,
297,
11573,
1105,
1988,
17,
61,
267,
340,
11167,
63,
2063,
365,
440,
488,
26,
288,
1347,
63,
2063,
275,
11167,
63,
2063,
446,
536,
63,
2301,
63,
2063,
446,
959,
288,
340,
1347,
63,
2063,
690,
1616,
26,
355,
327,
4816,
436,
4363,
6212,
370,
5542,
11167,
355,
6212,
275,
13390,
14,
3823,
8,
4705,
12,
1347,
63,
2063,
9,
355,
6212,
275,
17485,
78,
7,
435,
283,
283,
627,
334,
354,
63,
2301,
63,
2063,
435,
650,
4992,
904,
8,
4705,
9,
398,
1004,
275,
1543,
13,
10,
83,
446,
450,
83,
7,
450,
334,
354,
63,
2301,
63,
2063,
12,
2892,
1543,
83,
4366,
83,
3171,
450,
334,
354,
12,
1015,
395,
6212,
9,
267,
862,
26,
288,
2512,
14,
815,
8,
604,
9,
288,
340,
536,
315,
4903,
63,
5154,
26,
355,
2917,
275,
5496,
63,
4435,
14,
362,
63,
4972,
8,
354,
9,
355,
543,
4363,
63,
793,
837,
490,
8839,
275,
15356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yousafsyed/casperjs
|
bin/Lib/site-packages/setuptools/tests/test_packageindex.py
|
377
|
7625
|
"""Package Index Tests
"""
import sys
import os
import unittest
import pkg_resources
from setuptools.compat import urllib2, httplib, HTTPError, unicode, pathname2url
import distutils.errors
import setuptools.package_index
from setuptools.tests.server import IndexServer
class TestPackageIndex(unittest.TestCase):
def test_bad_url_bad_port(self):
index = setuptools.package_index.PackageIndex()
url = 'http://127.0.0.1:0/nonesuch/test_package_index'
try:
v = index.open_url(url)
except Exception:
v = sys.exc_info()[1]
self.assertTrue(url in str(v))
else:
self.assertTrue(isinstance(v, HTTPError))
def test_bad_url_typo(self):
# issue 16
# easy_install inquant.contentmirror.plone breaks because of a typo
# in its home URL
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk'
try:
v = index.open_url(url)
except Exception:
v = sys.exc_info()[1]
self.assertTrue(url in str(v))
else:
self.assertTrue(isinstance(v, HTTPError))
def test_bad_url_bad_status_line(self):
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
def _urlopen(*args):
raise httplib.BadStatusLine('line')
index.opener = _urlopen
url = 'http://example.com'
try:
v = index.open_url(url)
except Exception:
v = sys.exc_info()[1]
self.assertTrue('line' in str(v))
else:
raise AssertionError('Should have raise here!')
def test_bad_url_double_scheme(self):
"""
A bad URL with a double scheme should raise a DistutilsError.
"""
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
# issue 20
url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
try:
index.open_url(url)
except distutils.errors.DistutilsError:
error = sys.exc_info()[1]
msg = unicode(error)
assert 'nonnumeric port' in msg or 'getaddrinfo failed' in msg or 'Name or service not known' in msg
return
raise RuntimeError("Did not raise")
def test_bad_url_screwy_href(self):
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
# issue #160
if sys.version_info[0] == 2 and sys.version_info[1] == 7:
# this should not fail
url = 'http://example.com'
page = ('<a href="http://www.famfamfam.com]('
'http://www.famfamfam.com/">')
index.process_index(url, page)
def test_url_ok(self):
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
url = 'file:///tmp/test_package_index'
self.assertTrue(index.url_ok(url, True))
def test_links_priority(self):
"""
Download links from the pypi simple index should be used before
external download links.
https://bitbucket.org/tarek/distribute/issue/163
Usecase :
- someone uploads a package on pypi, a md5 is generated
- someone manually copies this link (with the md5 in the url) onto an
external page accessible from the package page.
- someone reuploads the package (with a different md5)
- while easy_installing, an MD5 error occurs because the external link
is used
-> Setuptools should use the link from pypi, not the external one.
"""
if sys.platform.startswith('java'):
# Skip this test on jython because binding to :0 fails
return
# start an index server
server = IndexServer()
server.start()
index_url = server.base_url() + 'test_links_priority/simple/'
# scan a test index
pi = setuptools.package_index.PackageIndex(index_url)
requirement = pkg_resources.Requirement.parse('foobar')
pi.find_packages(requirement)
server.stop()
# the distribution has been found
self.assertTrue('foobar' in pi)
# we have only one link, because links are compared without md5
self.assertTrue(len(pi['foobar'])==1)
# the link should be from the index
self.assertTrue('correct_md5' in pi['foobar'][0].location)
def test_parse_bdist_wininst(self):
self.assertEqual(setuptools.package_index.parse_bdist_wininst(
'reportlab-2.5.win32-py2.4.exe'), ('reportlab-2.5', '2.4', 'win32'))
self.assertEqual(setuptools.package_index.parse_bdist_wininst(
'reportlab-2.5.win32.exe'), ('reportlab-2.5', None, 'win32'))
self.assertEqual(setuptools.package_index.parse_bdist_wininst(
'reportlab-2.5.win-amd64-py2.7.exe'), ('reportlab-2.5', '2.7', 'win-amd64'))
self.assertEqual(setuptools.package_index.parse_bdist_wininst(
'reportlab-2.5.win-amd64.exe'), ('reportlab-2.5', None, 'win-amd64'))
def test__vcs_split_rev_from_url(self):
"""
Test the basic usage of _vcs_split_rev_from_url
"""
vsrfu = setuptools.package_index.PackageIndex._vcs_split_rev_from_url
url, rev = vsrfu('https://example.com/bar@2995')
self.assertEqual(url, 'https://example.com/bar')
self.assertEqual(rev, '2995')
def test_local_index(self):
"""
local_open should be able to read an index from the file system.
"""
f = open('index.html', 'w')
f.write('<div>content</div>')
f.close()
try:
url = 'file:' + pathname2url(os.getcwd()) + '/'
res = setuptools.package_index.local_open(url)
finally:
os.remove('index.html')
assert 'content' in res.read()
class TestContentCheckers(unittest.TestCase):
def test_md5(self):
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478')
checker.feed('You should probably not be using MD5'.encode('ascii'))
self.assertEqual(checker.hash.hexdigest(),
'f12895fdffbd45007040d2e44df98478')
self.assertTrue(checker.is_valid())
def test_other_fragment(self):
"Content checks should succeed silently if no hash is present"
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#something%20completely%20different')
checker.feed('anything'.encode('ascii'))
self.assertTrue(checker.is_valid())
def test_blank_md5(self):
"Content checks should succeed if a hash is empty"
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=')
checker.feed('anything'.encode('ascii'))
self.assertTrue(checker.is_valid())
def test_get_hash_name_md5(self):
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478')
self.assertEqual(checker.hash_name, 'md5')
def test_report(self):
checker = setuptools.package_index.HashChecker.from_url(
'http://foo/bar#md5=f12895fdffbd45007040d2e44df98478')
rep = checker.report(lambda x: x, 'My message about %s')
self.assertEqual(rep, 'My message about md5')
|
mit
|
[
624,
8599,
5499,
6496,
199,
624,
199,
646,
984,
199,
646,
747,
199,
646,
2882,
199,
646,
5496,
63,
4435,
199,
504,
9116,
14,
5819,
492,
4011,
18,
12,
8809,
12,
15050,
12,
2649,
12,
11776,
18,
633,
199,
646,
7065,
14,
2550,
199,
646,
9116,
14,
2491,
63,
1080,
199,
504,
9116,
14,
2219,
14,
1000,
492,
5499,
3120,
199,
199,
533,
1379,
8599,
2681,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4087,
63,
633,
63,
4087,
63,
719,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
342,
267,
1166,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
16,
15,
3592,
10180,
15,
396,
63,
2491,
63,
1080,
7,
267,
862,
26,
288,
373,
275,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
2186,
26,
288,
373,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
291,
14,
1815,
8,
633,
315,
620,
8,
86,
430,
267,
587,
26,
288,
291,
14,
1815,
8,
6074,
8,
86,
12,
15050,
430,
339,
347,
511,
63,
4087,
63,
633,
63,
369,
555,
8,
277,
304,
267,
327,
4976,
3193,
267,
327,
8837,
63,
3174,
315,
13603,
14,
1317,
12324,
14,
1168,
368,
18277,
2952,
402,
282,
24013,
267,
327,
315,
2399,
5629,
2851,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
1166,
275,
283,
633,
2689,
1165,
2859,
921,
6836,
14,
1168,
368,
14,
1308,
15,
6836,
15,
761,
25982,
15,
262,
13603,
14,
1317,
12324,
14,
1168,
368,
15,
13409,
7,
267,
862,
26,
288,
373,
275,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
2186,
26,
288,
373,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
291,
14,
1815,
8,
633,
315,
620,
8,
86,
430,
267,
587,
26,
288,
291,
14,
1815,
8,
6074,
8,
86,
12,
15050,
430,
339,
347,
511,
63,
4087,
63,
633,
63,
4087,
63,
1205,
63,
604,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
347,
485,
10890,
2031,
589,
304,
288,
746,
8809,
14,
5725,
3694,
3049,
360,
604,
358,
398,
1478,
14,
11637,
275,
485,
10890,
267,
1166,
275,
283,
1014,
921,
2694,
14,
957,
7,
267,
862,
26,
288,
373,
275,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
2186,
26,
288,
373,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
291,
14,
1815,
360,
604,
7,
315,
620,
8,
86,
430,
267,
587,
26,
288,
746,
9070,
360,
11408,
1172,
746,
2348,
10916,
339,
347,
511,
63,
4087,
63,
633,
63,
3157,
63,
5512,
8,
277,
304,
267,
408,
267,
437,
4875,
2851,
543,
282,
4270,
5687,
1077,
746,
282,
12577,
547,
14,
267,
408,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
327,
4976,
3388,
267,
1166,
275,
283,
1014,
921,
1014,
921,
6836,
14,
1548,
16586,
14,
1308,
15,
48,
9209,
15,
87,
8624,
15,
13409,
7,
267,
862,
26,
288,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
7065,
14,
2550,
14,
12012,
1208,
547,
26,
288,
1125,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
1499,
275,
2649,
8,
705,
9,
288,
702,
283,
2865,
6677,
1844,
7,
315,
1499,
503,
283,
27606,
815,
3405,
7,
315,
1499,
503,
283,
985,
503,
2435,
440,
6040,
7,
315,
1499,
288,
372,
267,
746,
6064,
480,
17366,
440,
746,
531,
339,
347,
511,
63,
4087,
63,
633,
63,
551,
5257,
89,
63,
6399,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
327,
4976,
327,
8488,
267,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
436,
984,
14,
1023,
63,
815,
59,
17,
61,
508,
1520,
26,
288,
327,
642,
1077,
440,
2449,
288,
1166,
275,
283,
1014,
921,
2694,
14,
957,
7,
288,
2034,
275,
19990,
65,
4369,
628,
1014,
921,
1544,
14,
18493,
18493,
18493,
14,
957,
61,
360,
490,
283,
1014,
921,
1544,
14,
18493,
18493,
18493,
14,
957,
26049,
358,
288,
1478,
14,
1412,
63,
1080,
8,
633,
12,
2034,
9,
339,
347,
511,
63,
633,
63,
745,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
267,
1166,
275,
283,
493,
24436,
2791,
15,
396,
63,
2491,
63,
1080,
7,
267,
291,
14,
1815,
8,
1080,
14,
633,
63,
745,
8,
633,
12,
715,
430,
339,
347,
511,
63,
4614,
63,
6693,
8,
277,
304,
267,
408,
267,
17955,
6220,
687,
314,
1134,
1038,
3486,
1478,
1077,
506,
1202,
2544,
267,
5957,
5235,
6220,
14,
267,
4178,
921,
25668,
14,
1308,
15,
502,
264,
75,
15,
3470,
15,
5237,
15,
11931,
398,
3645,
2546,
520,
267,
446,
17122,
26598,
282,
2559,
641,
1134,
1038,
12,
282,
6128,
21,
365,
4046,
267,
446,
17122,
10250,
6866,
642,
2142,
334,
1045,
314,
6128,
21,
315,
314,
1166,
9,
14602,
376,
881,
5957,
2034,
17909,
687,
314,
2559,
2034,
14,
267,
446,
17122,
295,
21725,
314,
2559,
334,
1045,
282,
3365,
6128,
21,
9,
267,
446,
1830,
8837,
63,
3174,
316,
12,
376,
15830,
21,
1125,
11058,
2952,
314,
5957,
2142,
881,
365,
1202,
267,
1035,
12439,
2537,
1077,
675,
314,
2142,
687,
1134,
1038,
12,
440,
314,
5957,
1373,
14,
267,
408,
267,
340,
984,
14,
3246,
14,
2460,
360,
6138,
735,
288,
327,
8232,
642,
511,
641,
1335,
11361,
2952,
11696,
370,
520,
16,
6918,
288,
372,
398,
327,
1343,
376,
1478,
1654,
267,
1654,
275,
5499,
3120,
342,
267,
1654,
14,
928,
342,
267,
1478,
63,
633,
275,
1654,
14,
1095,
63,
633,
342,
435,
283,
396,
63,
4614,
63,
6693,
15,
4129,
4805,
398,
327,
8000,
282,
511,
1478,
267,
6682,
275,
9116,
14,
2491,
63,
1080,
14,
8599
] |
[
8599,
5499,
6496,
199,
624,
199,
646,
984,
199,
646,
747,
199,
646,
2882,
199,
646,
5496,
63,
4435,
199,
504,
9116,
14,
5819,
492,
4011,
18,
12,
8809,
12,
15050,
12,
2649,
12,
11776,
18,
633,
199,
646,
7065,
14,
2550,
199,
646,
9116,
14,
2491,
63,
1080,
199,
504,
9116,
14,
2219,
14,
1000,
492,
5499,
3120,
199,
199,
533,
1379,
8599,
2681,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4087,
63,
633,
63,
4087,
63,
719,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
342,
267,
1166,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
16,
15,
3592,
10180,
15,
396,
63,
2491,
63,
1080,
7,
267,
862,
26,
288,
373,
275,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
2186,
26,
288,
373,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
291,
14,
1815,
8,
633,
315,
620,
8,
86,
430,
267,
587,
26,
288,
291,
14,
1815,
8,
6074,
8,
86,
12,
15050,
430,
339,
347,
511,
63,
4087,
63,
633,
63,
369,
555,
8,
277,
304,
267,
327,
4976,
3193,
267,
327,
8837,
63,
3174,
315,
13603,
14,
1317,
12324,
14,
1168,
368,
18277,
2952,
402,
282,
24013,
267,
327,
315,
2399,
5629,
2851,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
1166,
275,
283,
633,
2689,
1165,
2859,
921,
6836,
14,
1168,
368,
14,
1308,
15,
6836,
15,
761,
25982,
15,
262,
13603,
14,
1317,
12324,
14,
1168,
368,
15,
13409,
7,
267,
862,
26,
288,
373,
275,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
2186,
26,
288,
373,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
291,
14,
1815,
8,
633,
315,
620,
8,
86,
430,
267,
587,
26,
288,
291,
14,
1815,
8,
6074,
8,
86,
12,
15050,
430,
339,
347,
511,
63,
4087,
63,
633,
63,
4087,
63,
1205,
63,
604,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
347,
485,
10890,
2031,
589,
304,
288,
746,
8809,
14,
5725,
3694,
3049,
360,
604,
358,
398,
1478,
14,
11637,
275,
485,
10890,
267,
1166,
275,
283,
1014,
921,
2694,
14,
957,
7,
267,
862,
26,
288,
373,
275,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
2186,
26,
288,
373,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
291,
14,
1815,
360,
604,
7,
315,
620,
8,
86,
430,
267,
587,
26,
288,
746,
9070,
360,
11408,
1172,
746,
2348,
10916,
339,
347,
511,
63,
4087,
63,
633,
63,
3157,
63,
5512,
8,
277,
304,
267,
408,
267,
437,
4875,
2851,
543,
282,
4270,
5687,
1077,
746,
282,
12577,
547,
14,
267,
408,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
327,
4976,
3388,
267,
1166,
275,
283,
1014,
921,
1014,
921,
6836,
14,
1548,
16586,
14,
1308,
15,
48,
9209,
15,
87,
8624,
15,
13409,
7,
267,
862,
26,
288,
1478,
14,
1490,
63,
633,
8,
633,
9,
267,
871,
7065,
14,
2550,
14,
12012,
1208,
547,
26,
288,
1125,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
1499,
275,
2649,
8,
705,
9,
288,
702,
283,
2865,
6677,
1844,
7,
315,
1499,
503,
283,
27606,
815,
3405,
7,
315,
1499,
503,
283,
985,
503,
2435,
440,
6040,
7,
315,
1499,
288,
372,
267,
746,
6064,
480,
17366,
440,
746,
531,
339,
347,
511,
63,
4087,
63,
633,
63,
551,
5257,
89,
63,
6399,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
398,
327,
4976,
327,
8488,
267,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
436,
984,
14,
1023,
63,
815,
59,
17,
61,
508,
1520,
26,
288,
327,
642,
1077,
440,
2449,
288,
1166,
275,
283,
1014,
921,
2694,
14,
957,
7,
288,
2034,
275,
19990,
65,
4369,
628,
1014,
921,
1544,
14,
18493,
18493,
18493,
14,
957,
61,
360,
490,
283,
1014,
921,
1544,
14,
18493,
18493,
18493,
14,
957,
26049,
358,
288,
1478,
14,
1412,
63,
1080,
8,
633,
12,
2034,
9,
339,
347,
511,
63,
633,
63,
745,
8,
277,
304,
267,
1478,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
2681,
8,
288,
7057,
7782,
1544,
14,
2694,
14,
957,
9538,
267,
776,
267,
1166,
275,
283,
493,
24436,
2791,
15,
396,
63,
2491,
63,
1080,
7,
267,
291,
14,
1815,
8,
1080,
14,
633,
63,
745,
8,
633,
12,
715,
430,
339,
347,
511,
63,
4614,
63,
6693,
8,
277,
304,
267,
408,
267,
17955,
6220,
687,
314,
1134,
1038,
3486,
1478,
1077,
506,
1202,
2544,
267,
5957,
5235,
6220,
14,
267,
4178,
921,
25668,
14,
1308,
15,
502,
264,
75,
15,
3470,
15,
5237,
15,
11931,
398,
3645,
2546,
520,
267,
446,
17122,
26598,
282,
2559,
641,
1134,
1038,
12,
282,
6128,
21,
365,
4046,
267,
446,
17122,
10250,
6866,
642,
2142,
334,
1045,
314,
6128,
21,
315,
314,
1166,
9,
14602,
376,
881,
5957,
2034,
17909,
687,
314,
2559,
2034,
14,
267,
446,
17122,
295,
21725,
314,
2559,
334,
1045,
282,
3365,
6128,
21,
9,
267,
446,
1830,
8837,
63,
3174,
316,
12,
376,
15830,
21,
1125,
11058,
2952,
314,
5957,
2142,
881,
365,
1202,
267,
1035,
12439,
2537,
1077,
675,
314,
2142,
687,
1134,
1038,
12,
440,
314,
5957,
1373,
14,
267,
408,
267,
340,
984,
14,
3246,
14,
2460,
360,
6138,
735,
288,
327,
8232,
642,
511,
641,
1335,
11361,
2952,
11696,
370,
520,
16,
6918,
288,
372,
398,
327,
1343,
376,
1478,
1654,
267,
1654,
275,
5499,
3120,
342,
267,
1654,
14,
928,
342,
267,
1478,
63,
633,
275,
1654,
14,
1095,
63,
633,
342,
435,
283,
396,
63,
4614,
63,
6693,
15,
4129,
4805,
398,
327,
8000,
282,
511,
1478,
267,
6682,
275,
9116,
14,
2491,
63,
1080,
14,
8599,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MakeHer/edx-platform
|
common/lib/xmodule/xmodule/backcompat_module.py
|
204
|
3681
|
"""
These modules exist to translate old format XML into newer, semantic forms
"""
from .x_module import XModuleDescriptor
from lxml import etree
from functools import wraps
import logging
import traceback
log = logging.getLogger(__name__)
def process_includes(fn):
"""
Wraps a XModuleDescriptor.from_xml method, and modifies xml_data to replace
any immediate child <include> items with the contents of the file that they
are supposed to include
"""
@wraps(fn)
def from_xml(cls, xml_data, system, id_generator):
xml_object = etree.fromstring(xml_data)
next_include = xml_object.find('include')
while next_include is not None:
system.error_tracker("WARNING: the <include> tag is deprecated, and will go away.")
file = next_include.get('file')
parent = next_include.getparent()
if file is None:
continue
try:
ifp = system.resources_fs.open(file)
# read in and convert to XML
incxml = etree.XML(ifp.read())
# insert new XML into tree in place of include
parent.insert(parent.index(next_include), incxml)
except Exception:
# Log error
msg = "Error in problem xml include: %s" % (
etree.tostring(next_include, pretty_print=True))
# tell the tracker
system.error_tracker(msg)
# work around
parent = next_include.getparent()
errorxml = etree.Element('error')
messagexml = etree.SubElement(errorxml, 'message')
messagexml.text = msg
stackxml = etree.SubElement(errorxml, 'stacktrace')
stackxml.text = traceback.format_exc()
# insert error XML in place of include
parent.insert(parent.index(next_include), errorxml)
parent.remove(next_include)
next_include = xml_object.find('include')
return fn(cls, etree.tostring(xml_object), system, id_generator)
return from_xml
class SemanticSectionDescriptor(XModuleDescriptor):
@classmethod
@process_includes
def from_xml(cls, xml_data, system, id_generator):
"""
Removes sections with single child elements in favor of just embedding
the child element
"""
xml_object = etree.fromstring(xml_data)
system.error_tracker("WARNING: the <{0}> tag is deprecated. Please do not use in new content."
.format(xml_object.tag))
if len(xml_object) == 1:
for (key, val) in xml_object.items():
xml_object[0].set(key, val)
return system.process_xml(etree.tostring(xml_object[0]))
else:
xml_object.tag = 'sequential'
return system.process_xml(etree.tostring(xml_object))
class TranslateCustomTagDescriptor(XModuleDescriptor):
@classmethod
def from_xml(cls, xml_data, system, id_generator):
"""
Transforms the xml_data from <$custom_tag attr="" attr=""/> to
<customtag attr="" attr="" impl="$custom_tag"/>
"""
xml_object = etree.fromstring(xml_data)
system.error_tracker('WARNING: the <{tag}> tag is deprecated. '
'Instead, use <customtag impl="{tag}" attr1="..." attr2="..."/>. '
.format(tag=xml_object.tag))
tag = xml_object.tag
xml_object.tag = 'customtag'
xml_object.attrib['impl'] = tag
return system.process_xml(etree.tostring(xml_object))
|
agpl-3.0
|
[
624,
199,
20676,
4621,
2187,
370,
9028,
2269,
1475,
4692,
1901,
15666,
12,
32451,
4513,
199,
624,
199,
504,
1275,
88,
63,
578,
492,
25656,
4311,
199,
504,
14490,
492,
7559,
199,
504,
9143,
492,
14018,
199,
646,
2050,
199,
646,
5190,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2112,
63,
9441,
8,
2324,
304,
272,
408,
272,
644,
8146,
282,
25656,
4311,
14,
504,
63,
1652,
1083,
12,
436,
26473,
2748,
63,
576,
370,
3350,
272,
1263,
8569,
1982,
665,
2613,
30,
2974,
543,
314,
4072,
402,
314,
570,
626,
2985,
272,
787,
20042,
370,
2387,
272,
408,
272,
768,
13582,
8,
2324,
9,
272,
347,
687,
63,
1652,
8,
1886,
12,
2748,
63,
576,
12,
2656,
12,
1305,
63,
4679,
304,
267,
2748,
63,
785,
275,
7559,
14,
13521,
8,
1652,
63,
576,
9,
267,
2163,
63,
2613,
275,
2748,
63,
785,
14,
1623,
360,
2613,
358,
267,
1830,
2163,
63,
2613,
365,
440,
488,
26,
288,
2656,
14,
705,
63,
8877,
480,
9171,
26,
314,
665,
2613,
30,
1947,
365,
5906,
12,
436,
911,
2621,
13437,
2685,
288,
570,
275,
2163,
63,
2613,
14,
362,
360,
493,
358,
288,
1676,
275,
2163,
63,
2613,
14,
362,
1708,
342,
953,
340,
570,
365,
488,
26,
355,
1980,
953,
862,
26,
355,
340,
80,
275,
2656,
14,
4435,
63,
2319,
14,
1490,
8,
493,
9,
355,
327,
1586,
315,
436,
3957,
370,
4692,
355,
12864,
1652,
275,
7559,
14,
4317,
8,
692,
80,
14,
739,
1012,
2234,
327,
5518,
221,
892,
4692,
1901,
3123,
315,
4192,
402,
2387,
355,
1676,
14,
3176,
8,
1708,
14,
1080,
8,
2184,
63,
2613,
395,
12864,
1652,
9,
288,
871,
2186,
26,
355,
327,
5297,
1125,
355,
1499,
275,
298,
547,
315,
5160,
2748,
2387,
26,
450,
83,
2,
450,
334,
490,
7559,
14,
14028,
8,
2184,
63,
2613,
12,
7268,
63,
1361,
29,
549,
430,
355,
327,
11480,
314,
15271,
355,
2656,
14,
705,
63,
8877,
8,
1328,
9,
2234,
327,
1736,
6818,
355,
1676,
275,
2163,
63,
2613,
14,
362,
1708,
342,
355,
1125,
1652,
275,
7559,
14,
2162,
360,
705,
358,
355,
1245,
1652,
275,
7559,
14,
10571,
8,
705,
1652,
12,
283,
1188,
358,
355,
1245,
1652,
14,
505,
275,
1499,
355,
3464,
1652,
275,
7559,
14,
10571,
8,
705,
1652,
12,
283,
32274,
358,
355,
3464,
1652,
14,
505,
275,
5190,
14,
908,
63,
2804,
342,
355,
327,
5518,
1125,
4692,
315,
4192,
402,
2387,
355,
1676,
14,
3176,
8,
1708,
14,
1080,
8,
2184,
63,
2613,
395,
1125,
1652,
9,
953,
1676,
14,
2168,
8,
2184,
63,
2613,
9,
953,
2163,
63,
2613,
275,
2748,
63,
785,
14,
1623,
360,
2613,
358,
267,
372,
4325,
8,
1886,
12,
7559,
14,
14028,
8,
1652,
63,
785,
395,
2656,
12,
1305,
63,
4679,
9,
272,
372,
687,
63,
1652,
421,
199,
533,
3240,
23127,
8660,
4311,
8,
56,
2377,
4311,
304,
272,
768,
3744,
272,
768,
1412,
63,
9441,
272,
347,
687,
63,
1652,
8,
1886,
12,
2748,
63,
576,
12,
2656,
12,
1305,
63,
4679,
304,
267,
408,
267,
23169,
10189,
543,
2849,
1982,
4008,
315,
17914,
402,
2951,
12452,
267,
314,
1982,
1819,
267,
408,
267,
2748,
63,
785,
275,
7559,
14,
13521,
8,
1652,
63,
576,
9,
267,
2656,
14,
705,
63,
8877,
480,
9171,
26,
314,
665,
91,
16,
93,
30,
1947,
365,
5906,
14,
221,
7754,
886,
440,
675,
315,
892,
1564,
2122,
2490,
1275,
908,
8,
1652,
63,
785,
14,
1450,
430,
398,
340,
822,
8,
1652,
63,
785,
9,
508,
413,
26,
288,
367,
334,
498,
12,
1139,
9,
315,
2748,
63,
785,
14,
1744,
837,
355,
2748,
63,
785,
59,
16,
1055,
409,
8,
498,
12,
1139,
9,
953,
372,
2656,
14,
1412,
63,
1652,
8,
9464,
14,
14028,
8,
1652,
63,
785,
59,
16,
2459,
267,
587,
26,
288,
2748,
63,
785,
14,
1450,
275,
283,
16211,
7,
288,
372,
2656,
14,
1412,
63,
1652,
8,
9464,
14,
14028,
8,
1652,
63,
785,
430,
421,
199,
533,
25540,
7223,
1931,
4311,
8,
56,
2377,
4311,
304,
272,
768,
3744,
272,
347,
687,
63,
1652,
8,
1886,
12,
2748,
63,
576,
12,
2656,
12,
1305,
63,
4679,
304,
267,
408,
267,
6266,
3351,
314,
2748,
63,
576,
687,
665,
4,
4229,
63,
1450,
1921,
9287,
1921,
9287,
3133,
370,
267,
665,
4229,
1450,
1921,
9287,
1921,
9287,
11512,
628,
4,
4229,
63,
1450,
7897,
267,
408,
398,
2748,
63,
785,
275,
7559,
14,
13521,
8,
1652,
63,
576,
9,
267,
2656,
14,
705,
63,
8877,
360,
9171,
26,
314,
665,
91,
1450,
93,
30,
1947,
365,
5906,
14,
221,
283,
2490,
283,
13962,
13558,
12,
675,
665,
4229,
1450,
11512,
18448,
1450,
7063,
1921,
17,
628,
11500,
1921,
18,
628,
11500,
4743,
283,
2490,
1275,
908,
8,
1450,
29,
1652,
63,
785,
14,
1450,
430,
398,
1947,
275,
2748,
63,
785,
14,
1450,
267,
2748,
63,
785,
14,
1450,
275,
283,
4229,
1450,
7,
267,
2748,
63,
785,
14,
6640,
459,
5472,
418,
275,
1947,
398,
372,
2656,
14,
1412,
63,
1652,
8,
9464,
14,
14028,
8,
1652,
63,
785,
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
] |
[
199,
20676,
4621,
2187,
370,
9028,
2269,
1475,
4692,
1901,
15666,
12,
32451,
4513,
199,
624,
199,
504,
1275,
88,
63,
578,
492,
25656,
4311,
199,
504,
14490,
492,
7559,
199,
504,
9143,
492,
14018,
199,
646,
2050,
199,
646,
5190,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
2112,
63,
9441,
8,
2324,
304,
272,
408,
272,
644,
8146,
282,
25656,
4311,
14,
504,
63,
1652,
1083,
12,
436,
26473,
2748,
63,
576,
370,
3350,
272,
1263,
8569,
1982,
665,
2613,
30,
2974,
543,
314,
4072,
402,
314,
570,
626,
2985,
272,
787,
20042,
370,
2387,
272,
408,
272,
768,
13582,
8,
2324,
9,
272,
347,
687,
63,
1652,
8,
1886,
12,
2748,
63,
576,
12,
2656,
12,
1305,
63,
4679,
304,
267,
2748,
63,
785,
275,
7559,
14,
13521,
8,
1652,
63,
576,
9,
267,
2163,
63,
2613,
275,
2748,
63,
785,
14,
1623,
360,
2613,
358,
267,
1830,
2163,
63,
2613,
365,
440,
488,
26,
288,
2656,
14,
705,
63,
8877,
480,
9171,
26,
314,
665,
2613,
30,
1947,
365,
5906,
12,
436,
911,
2621,
13437,
2685,
288,
570,
275,
2163,
63,
2613,
14,
362,
360,
493,
358,
288,
1676,
275,
2163,
63,
2613,
14,
362,
1708,
342,
953,
340,
570,
365,
488,
26,
355,
1980,
953,
862,
26,
355,
340,
80,
275,
2656,
14,
4435,
63,
2319,
14,
1490,
8,
493,
9,
355,
327,
1586,
315,
436,
3957,
370,
4692,
355,
12864,
1652,
275,
7559,
14,
4317,
8,
692,
80,
14,
739,
1012,
2234,
327,
5518,
221,
892,
4692,
1901,
3123,
315,
4192,
402,
2387,
355,
1676,
14,
3176,
8,
1708,
14,
1080,
8,
2184,
63,
2613,
395,
12864,
1652,
9,
288,
871,
2186,
26,
355,
327,
5297,
1125,
355,
1499,
275,
298,
547,
315,
5160,
2748,
2387,
26,
450,
83,
2,
450,
334,
490,
7559,
14,
14028,
8,
2184,
63,
2613,
12,
7268,
63,
1361,
29,
549,
430,
355,
327,
11480,
314,
15271,
355,
2656,
14,
705,
63,
8877,
8,
1328,
9,
2234,
327,
1736,
6818,
355,
1676,
275,
2163,
63,
2613,
14,
362,
1708,
342,
355,
1125,
1652,
275,
7559,
14,
2162,
360,
705,
358,
355,
1245,
1652,
275,
7559,
14,
10571,
8,
705,
1652,
12,
283,
1188,
358,
355,
1245,
1652,
14,
505,
275,
1499,
355,
3464,
1652,
275,
7559,
14,
10571,
8,
705,
1652,
12,
283,
32274,
358,
355,
3464,
1652,
14,
505,
275,
5190,
14,
908,
63,
2804,
342,
355,
327,
5518,
1125,
4692,
315,
4192,
402,
2387,
355,
1676,
14,
3176,
8,
1708,
14,
1080,
8,
2184,
63,
2613,
395,
1125,
1652,
9,
953,
1676,
14,
2168,
8,
2184,
63,
2613,
9,
953,
2163,
63,
2613,
275,
2748,
63,
785,
14,
1623,
360,
2613,
358,
267,
372,
4325,
8,
1886,
12,
7559,
14,
14028,
8,
1652,
63,
785,
395,
2656,
12,
1305,
63,
4679,
9,
272,
372,
687,
63,
1652,
421,
199,
533,
3240,
23127,
8660,
4311,
8,
56,
2377,
4311,
304,
272,
768,
3744,
272,
768,
1412,
63,
9441,
272,
347,
687,
63,
1652,
8,
1886,
12,
2748,
63,
576,
12,
2656,
12,
1305,
63,
4679,
304,
267,
408,
267,
23169,
10189,
543,
2849,
1982,
4008,
315,
17914,
402,
2951,
12452,
267,
314,
1982,
1819,
267,
408,
267,
2748,
63,
785,
275,
7559,
14,
13521,
8,
1652,
63,
576,
9,
267,
2656,
14,
705,
63,
8877,
480,
9171,
26,
314,
665,
91,
16,
93,
30,
1947,
365,
5906,
14,
221,
7754,
886,
440,
675,
315,
892,
1564,
2122,
2490,
1275,
908,
8,
1652,
63,
785,
14,
1450,
430,
398,
340,
822,
8,
1652,
63,
785,
9,
508,
413,
26,
288,
367,
334,
498,
12,
1139,
9,
315,
2748,
63,
785,
14,
1744,
837,
355,
2748,
63,
785,
59,
16,
1055,
409,
8,
498,
12,
1139,
9,
953,
372,
2656,
14,
1412,
63,
1652,
8,
9464,
14,
14028,
8,
1652,
63,
785,
59,
16,
2459,
267,
587,
26,
288,
2748,
63,
785,
14,
1450,
275,
283,
16211,
7,
288,
372,
2656,
14,
1412,
63,
1652,
8,
9464,
14,
14028,
8,
1652,
63,
785,
430,
421,
199,
533,
25540,
7223,
1931,
4311,
8,
56,
2377,
4311,
304,
272,
768,
3744,
272,
347,
687,
63,
1652,
8,
1886,
12,
2748,
63,
576,
12,
2656,
12,
1305,
63,
4679,
304,
267,
408,
267,
6266,
3351,
314,
2748,
63,
576,
687,
665,
4,
4229,
63,
1450,
1921,
9287,
1921,
9287,
3133,
370,
267,
665,
4229,
1450,
1921,
9287,
1921,
9287,
11512,
628,
4,
4229,
63,
1450,
7897,
267,
408,
398,
2748,
63,
785,
275,
7559,
14,
13521,
8,
1652,
63,
576,
9,
267,
2656,
14,
705,
63,
8877,
360,
9171,
26,
314,
665,
91,
1450,
93,
30,
1947,
365,
5906,
14,
221,
283,
2490,
283,
13962,
13558,
12,
675,
665,
4229,
1450,
11512,
18448,
1450,
7063,
1921,
17,
628,
11500,
1921,
18,
628,
11500,
4743,
283,
2490,
1275,
908,
8,
1450,
29,
1652,
63,
785,
14,
1450,
430,
398,
1947,
275,
2748,
63,
785,
14,
1450,
267,
2748,
63,
785,
14,
1450,
275,
283,
4229,
1450,
7,
267,
2748,
63,
785,
14,
6640,
459,
5472,
418,
275,
1947,
398,
372,
2656,
14,
1412,
63,
1652,
8,
9464,
14,
14028,
8,
1652,
63,
785,
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,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mdanielwork/intellij-community
|
python/lib/Lib/encodings/mac_greek.py
|
593
|
13977
|
""" Python Character Mapping Codec mac_greek generated from 'MAPPINGS/VENDORS/APPLE/GREEK.TXT' with gencodec.py.
"""#"
import codecs
### Codec APIs
class Codec(codecs.Codec):
def encode(self,input,errors='strict'):
return codecs.charmap_encode(input,errors,encoding_table)
def decode(self,input,errors='strict'):
return codecs.charmap_decode(input,errors,decoding_table)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='mac-greek',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
### Decoding Table
decoding_table = (
u'\x00' # 0x00 -> CONTROL CHARACTER
u'\x01' # 0x01 -> CONTROL CHARACTER
u'\x02' # 0x02 -> CONTROL CHARACTER
u'\x03' # 0x03 -> CONTROL CHARACTER
u'\x04' # 0x04 -> CONTROL CHARACTER
u'\x05' # 0x05 -> CONTROL CHARACTER
u'\x06' # 0x06 -> CONTROL CHARACTER
u'\x07' # 0x07 -> CONTROL CHARACTER
u'\x08' # 0x08 -> CONTROL CHARACTER
u'\t' # 0x09 -> CONTROL CHARACTER
u'\n' # 0x0A -> CONTROL CHARACTER
u'\x0b' # 0x0B -> CONTROL CHARACTER
u'\x0c' # 0x0C -> CONTROL CHARACTER
u'\r' # 0x0D -> CONTROL CHARACTER
u'\x0e' # 0x0E -> CONTROL CHARACTER
u'\x0f' # 0x0F -> CONTROL CHARACTER
u'\x10' # 0x10 -> CONTROL CHARACTER
u'\x11' # 0x11 -> CONTROL CHARACTER
u'\x12' # 0x12 -> CONTROL CHARACTER
u'\x13' # 0x13 -> CONTROL CHARACTER
u'\x14' # 0x14 -> CONTROL CHARACTER
u'\x15' # 0x15 -> CONTROL CHARACTER
u'\x16' # 0x16 -> CONTROL CHARACTER
u'\x17' # 0x17 -> CONTROL CHARACTER
u'\x18' # 0x18 -> CONTROL CHARACTER
u'\x19' # 0x19 -> CONTROL CHARACTER
u'\x1a' # 0x1A -> CONTROL CHARACTER
u'\x1b' # 0x1B -> CONTROL CHARACTER
u'\x1c' # 0x1C -> CONTROL CHARACTER
u'\x1d' # 0x1D -> CONTROL CHARACTER
u'\x1e' # 0x1E -> CONTROL CHARACTER
u'\x1f' # 0x1F -> CONTROL CHARACTER
u' ' # 0x20 -> SPACE
u'!' # 0x21 -> EXCLAMATION MARK
u'"' # 0x22 -> QUOTATION MARK
u'#' # 0x23 -> NUMBER SIGN
u'$' # 0x24 -> DOLLAR SIGN
u'%' # 0x25 -> PERCENT SIGN
u'&' # 0x26 -> AMPERSAND
u"'" # 0x27 -> APOSTROPHE
u'(' # 0x28 -> LEFT PARENTHESIS
u')' # 0x29 -> RIGHT PARENTHESIS
u'*' # 0x2A -> ASTERISK
u'+' # 0x2B -> PLUS SIGN
u',' # 0x2C -> COMMA
u'-' # 0x2D -> HYPHEN-MINUS
u'.' # 0x2E -> FULL STOP
u'/' # 0x2F -> SOLIDUS
u'0' # 0x30 -> DIGIT ZERO
u'1' # 0x31 -> DIGIT ONE
u'2' # 0x32 -> DIGIT TWO
u'3' # 0x33 -> DIGIT THREE
u'4' # 0x34 -> DIGIT FOUR
u'5' # 0x35 -> DIGIT FIVE
u'6' # 0x36 -> DIGIT SIX
u'7' # 0x37 -> DIGIT SEVEN
u'8' # 0x38 -> DIGIT EIGHT
u'9' # 0x39 -> DIGIT NINE
u':' # 0x3A -> COLON
u';' # 0x3B -> SEMICOLON
u'<' # 0x3C -> LESS-THAN SIGN
u'=' # 0x3D -> EQUALS SIGN
u'>' # 0x3E -> GREATER-THAN SIGN
u'?' # 0x3F -> QUESTION MARK
u'@' # 0x40 -> COMMERCIAL AT
u'A' # 0x41 -> LATIN CAPITAL LETTER A
u'B' # 0x42 -> LATIN CAPITAL LETTER B
u'C' # 0x43 -> LATIN CAPITAL LETTER C
u'D' # 0x44 -> LATIN CAPITAL LETTER D
u'E' # 0x45 -> LATIN CAPITAL LETTER E
u'F' # 0x46 -> LATIN CAPITAL LETTER F
u'G' # 0x47 -> LATIN CAPITAL LETTER G
u'H' # 0x48 -> LATIN CAPITAL LETTER H
u'I' # 0x49 -> LATIN CAPITAL LETTER I
u'J' # 0x4A -> LATIN CAPITAL LETTER J
u'K' # 0x4B -> LATIN CAPITAL LETTER K
u'L' # 0x4C -> LATIN CAPITAL LETTER L
u'M' # 0x4D -> LATIN CAPITAL LETTER M
u'N' # 0x4E -> LATIN CAPITAL LETTER N
u'O' # 0x4F -> LATIN CAPITAL LETTER O
u'P' # 0x50 -> LATIN CAPITAL LETTER P
u'Q' # 0x51 -> LATIN CAPITAL LETTER Q
u'R' # 0x52 -> LATIN CAPITAL LETTER R
u'S' # 0x53 -> LATIN CAPITAL LETTER S
u'T' # 0x54 -> LATIN CAPITAL LETTER T
u'U' # 0x55 -> LATIN CAPITAL LETTER U
u'V' # 0x56 -> LATIN CAPITAL LETTER V
u'W' # 0x57 -> LATIN CAPITAL LETTER W
u'X' # 0x58 -> LATIN CAPITAL LETTER X
u'Y' # 0x59 -> LATIN CAPITAL LETTER Y
u'Z' # 0x5A -> LATIN CAPITAL LETTER Z
u'[' # 0x5B -> LEFT SQUARE BRACKET
u'\\' # 0x5C -> REVERSE SOLIDUS
u']' # 0x5D -> RIGHT SQUARE BRACKET
u'^' # 0x5E -> CIRCUMFLEX ACCENT
u'_' # 0x5F -> LOW LINE
u'`' # 0x60 -> GRAVE ACCENT
u'a' # 0x61 -> LATIN SMALL LETTER A
u'b' # 0x62 -> LATIN SMALL LETTER B
u'c' # 0x63 -> LATIN SMALL LETTER C
u'd' # 0x64 -> LATIN SMALL LETTER D
u'e' # 0x65 -> LATIN SMALL LETTER E
u'f' # 0x66 -> LATIN SMALL LETTER F
u'g' # 0x67 -> LATIN SMALL LETTER G
u'h' # 0x68 -> LATIN SMALL LETTER H
u'i' # 0x69 -> LATIN SMALL LETTER I
u'j' # 0x6A -> LATIN SMALL LETTER J
u'k' # 0x6B -> LATIN SMALL LETTER K
u'l' # 0x6C -> LATIN SMALL LETTER L
u'm' # 0x6D -> LATIN SMALL LETTER M
u'n' # 0x6E -> LATIN SMALL LETTER N
u'o' # 0x6F -> LATIN SMALL LETTER O
u'p' # 0x70 -> LATIN SMALL LETTER P
u'q' # 0x71 -> LATIN SMALL LETTER Q
u'r' # 0x72 -> LATIN SMALL LETTER R
u's' # 0x73 -> LATIN SMALL LETTER S
u't' # 0x74 -> LATIN SMALL LETTER T
u'u' # 0x75 -> LATIN SMALL LETTER U
u'v' # 0x76 -> LATIN SMALL LETTER V
u'w' # 0x77 -> LATIN SMALL LETTER W
u'x' # 0x78 -> LATIN SMALL LETTER X
u'y' # 0x79 -> LATIN SMALL LETTER Y
u'z' # 0x7A -> LATIN SMALL LETTER Z
u'{' # 0x7B -> LEFT CURLY BRACKET
u'|' # 0x7C -> VERTICAL LINE
u'}' # 0x7D -> RIGHT CURLY BRACKET
u'~' # 0x7E -> TILDE
u'\x7f' # 0x7F -> CONTROL CHARACTER
u'\xc4' # 0x80 -> LATIN CAPITAL LETTER A WITH DIAERESIS
u'\xb9' # 0x81 -> SUPERSCRIPT ONE
u'\xb2' # 0x82 -> SUPERSCRIPT TWO
u'\xc9' # 0x83 -> LATIN CAPITAL LETTER E WITH ACUTE
u'\xb3' # 0x84 -> SUPERSCRIPT THREE
u'\xd6' # 0x85 -> LATIN CAPITAL LETTER O WITH DIAERESIS
u'\xdc' # 0x86 -> LATIN CAPITAL LETTER U WITH DIAERESIS
u'\u0385' # 0x87 -> GREEK DIALYTIKA TONOS
u'\xe0' # 0x88 -> LATIN SMALL LETTER A WITH GRAVE
u'\xe2' # 0x89 -> LATIN SMALL LETTER A WITH CIRCUMFLEX
u'\xe4' # 0x8A -> LATIN SMALL LETTER A WITH DIAERESIS
u'\u0384' # 0x8B -> GREEK TONOS
u'\xa8' # 0x8C -> DIAERESIS
u'\xe7' # 0x8D -> LATIN SMALL LETTER C WITH CEDILLA
u'\xe9' # 0x8E -> LATIN SMALL LETTER E WITH ACUTE
u'\xe8' # 0x8F -> LATIN SMALL LETTER E WITH GRAVE
u'\xea' # 0x90 -> LATIN SMALL LETTER E WITH CIRCUMFLEX
u'\xeb' # 0x91 -> LATIN SMALL LETTER E WITH DIAERESIS
u'\xa3' # 0x92 -> POUND SIGN
u'\u2122' # 0x93 -> TRADE MARK SIGN
u'\xee' # 0x94 -> LATIN SMALL LETTER I WITH CIRCUMFLEX
u'\xef' # 0x95 -> LATIN SMALL LETTER I WITH DIAERESIS
u'\u2022' # 0x96 -> BULLET
u'\xbd' # 0x97 -> VULGAR FRACTION ONE HALF
u'\u2030' # 0x98 -> PER MILLE SIGN
u'\xf4' # 0x99 -> LATIN SMALL LETTER O WITH CIRCUMFLEX
u'\xf6' # 0x9A -> LATIN SMALL LETTER O WITH DIAERESIS
u'\xa6' # 0x9B -> BROKEN BAR
u'\u20ac' # 0x9C -> EURO SIGN # before Mac OS 9.2.2, was SOFT HYPHEN
u'\xf9' # 0x9D -> LATIN SMALL LETTER U WITH GRAVE
u'\xfb' # 0x9E -> LATIN SMALL LETTER U WITH CIRCUMFLEX
u'\xfc' # 0x9F -> LATIN SMALL LETTER U WITH DIAERESIS
u'\u2020' # 0xA0 -> DAGGER
u'\u0393' # 0xA1 -> GREEK CAPITAL LETTER GAMMA
u'\u0394' # 0xA2 -> GREEK CAPITAL LETTER DELTA
u'\u0398' # 0xA3 -> GREEK CAPITAL LETTER THETA
u'\u039b' # 0xA4 -> GREEK CAPITAL LETTER LAMDA
u'\u039e' # 0xA5 -> GREEK CAPITAL LETTER XI
u'\u03a0' # 0xA6 -> GREEK CAPITAL LETTER PI
u'\xdf' # 0xA7 -> LATIN SMALL LETTER SHARP S
u'\xae' # 0xA8 -> REGISTERED SIGN
u'\xa9' # 0xA9 -> COPYRIGHT SIGN
u'\u03a3' # 0xAA -> GREEK CAPITAL LETTER SIGMA
u'\u03aa' # 0xAB -> GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
u'\xa7' # 0xAC -> SECTION SIGN
u'\u2260' # 0xAD -> NOT EQUAL TO
u'\xb0' # 0xAE -> DEGREE SIGN
u'\xb7' # 0xAF -> MIDDLE DOT
u'\u0391' # 0xB0 -> GREEK CAPITAL LETTER ALPHA
u'\xb1' # 0xB1 -> PLUS-MINUS SIGN
u'\u2264' # 0xB2 -> LESS-THAN OR EQUAL TO
u'\u2265' # 0xB3 -> GREATER-THAN OR EQUAL TO
u'\xa5' # 0xB4 -> YEN SIGN
u'\u0392' # 0xB5 -> GREEK CAPITAL LETTER BETA
u'\u0395' # 0xB6 -> GREEK CAPITAL LETTER EPSILON
u'\u0396' # 0xB7 -> GREEK CAPITAL LETTER ZETA
u'\u0397' # 0xB8 -> GREEK CAPITAL LETTER ETA
u'\u0399' # 0xB9 -> GREEK CAPITAL LETTER IOTA
u'\u039a' # 0xBA -> GREEK CAPITAL LETTER KAPPA
u'\u039c' # 0xBB -> GREEK CAPITAL LETTER MU
u'\u03a6' # 0xBC -> GREEK CAPITAL LETTER PHI
u'\u03ab' # 0xBD -> GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
u'\u03a8' # 0xBE -> GREEK CAPITAL LETTER PSI
u'\u03a9' # 0xBF -> GREEK CAPITAL LETTER OMEGA
u'\u03ac' # 0xC0 -> GREEK SMALL LETTER ALPHA WITH TONOS
u'\u039d' # 0xC1 -> GREEK CAPITAL LETTER NU
u'\xac' # 0xC2 -> NOT SIGN
u'\u039f' # 0xC3 -> GREEK CAPITAL LETTER OMICRON
u'\u03a1' # 0xC4 -> GREEK CAPITAL LETTER RHO
u'\u2248' # 0xC5 -> ALMOST EQUAL TO
u'\u03a4' # 0xC6 -> GREEK CAPITAL LETTER TAU
u'\xab' # 0xC7 -> LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\xbb' # 0xC8 -> RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
u'\u2026' # 0xC9 -> HORIZONTAL ELLIPSIS
u'\xa0' # 0xCA -> NO-BREAK SPACE
u'\u03a5' # 0xCB -> GREEK CAPITAL LETTER UPSILON
u'\u03a7' # 0xCC -> GREEK CAPITAL LETTER CHI
u'\u0386' # 0xCD -> GREEK CAPITAL LETTER ALPHA WITH TONOS
u'\u0388' # 0xCE -> GREEK CAPITAL LETTER EPSILON WITH TONOS
u'\u0153' # 0xCF -> LATIN SMALL LIGATURE OE
u'\u2013' # 0xD0 -> EN DASH
u'\u2015' # 0xD1 -> HORIZONTAL BAR
u'\u201c' # 0xD2 -> LEFT DOUBLE QUOTATION MARK
u'\u201d' # 0xD3 -> RIGHT DOUBLE QUOTATION MARK
u'\u2018' # 0xD4 -> LEFT SINGLE QUOTATION MARK
u'\u2019' # 0xD5 -> RIGHT SINGLE QUOTATION MARK
u'\xf7' # 0xD6 -> DIVISION SIGN
u'\u0389' # 0xD7 -> GREEK CAPITAL LETTER ETA WITH TONOS
u'\u038a' # 0xD8 -> GREEK CAPITAL LETTER IOTA WITH TONOS
u'\u038c' # 0xD9 -> GREEK CAPITAL LETTER OMICRON WITH TONOS
u'\u038e' # 0xDA -> GREEK CAPITAL LETTER UPSILON WITH TONOS
u'\u03ad' # 0xDB -> GREEK SMALL LETTER EPSILON WITH TONOS
u'\u03ae' # 0xDC -> GREEK SMALL LETTER ETA WITH TONOS
u'\u03af' # 0xDD -> GREEK SMALL LETTER IOTA WITH TONOS
u'\u03cc' # 0xDE -> GREEK SMALL LETTER OMICRON WITH TONOS
u'\u038f' # 0xDF -> GREEK CAPITAL LETTER OMEGA WITH TONOS
u'\u03cd' # 0xE0 -> GREEK SMALL LETTER UPSILON WITH TONOS
u'\u03b1' # 0xE1 -> GREEK SMALL LETTER ALPHA
u'\u03b2' # 0xE2 -> GREEK SMALL LETTER BETA
u'\u03c8' # 0xE3 -> GREEK SMALL LETTER PSI
u'\u03b4' # 0xE4 -> GREEK SMALL LETTER DELTA
u'\u03b5' # 0xE5 -> GREEK SMALL LETTER EPSILON
u'\u03c6' # 0xE6 -> GREEK SMALL LETTER PHI
u'\u03b3' # 0xE7 -> GREEK SMALL LETTER GAMMA
u'\u03b7' # 0xE8 -> GREEK SMALL LETTER ETA
u'\u03b9' # 0xE9 -> GREEK SMALL LETTER IOTA
u'\u03be' # 0xEA -> GREEK SMALL LETTER XI
u'\u03ba' # 0xEB -> GREEK SMALL LETTER KAPPA
u'\u03bb' # 0xEC -> GREEK SMALL LETTER LAMDA
u'\u03bc' # 0xED -> GREEK SMALL LETTER MU
u'\u03bd' # 0xEE -> GREEK SMALL LETTER NU
u'\u03bf' # 0xEF -> GREEK SMALL LETTER OMICRON
u'\u03c0' # 0xF0 -> GREEK SMALL LETTER PI
u'\u03ce' # 0xF1 -> GREEK SMALL LETTER OMEGA WITH TONOS
u'\u03c1' # 0xF2 -> GREEK SMALL LETTER RHO
u'\u03c3' # 0xF3 -> GREEK SMALL LETTER SIGMA
u'\u03c4' # 0xF4 -> GREEK SMALL LETTER TAU
u'\u03b8' # 0xF5 -> GREEK SMALL LETTER THETA
u'\u03c9' # 0xF6 -> GREEK SMALL LETTER OMEGA
u'\u03c2' # 0xF7 -> GREEK SMALL LETTER FINAL SIGMA
u'\u03c7' # 0xF8 -> GREEK SMALL LETTER CHI
u'\u03c5' # 0xF9 -> GREEK SMALL LETTER UPSILON
u'\u03b6' # 0xFA -> GREEK SMALL LETTER ZETA
u'\u03ca' # 0xFB -> GREEK SMALL LETTER IOTA WITH DIALYTIKA
u'\u03cb' # 0xFC -> GREEK SMALL LETTER UPSILON WITH DIALYTIKA
u'\u0390' # 0xFD -> GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
u'\u03b0' # 0xFE -> GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
u'\xad' # 0xFF -> SOFT HYPHEN # before Mac OS 9.2.2, was undefined
)
### Encoding table
encoding_table=codecs.charmap_build(decoding_table)
|
apache-2.0
|
[
624,
2018,
17660,
12340,
13732,
4497,
63,
32007,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
31683,
15,
39,
7440,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
3088,
13,
32007,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
421,
199,
5680,
27368,
6957,
199,
199,
12796,
63,
1224,
275,
334,
272,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
8098,
9502,
272,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
8098,
9502,
272,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
8098,
9502,
272,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
8098,
9502,
272,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
8098,
9502,
272,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
8098,
9502,
272,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
8098,
9502,
272,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
8098,
9502,
272,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
8098,
9502,
272,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8098,
9502,
272,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
8098,
9502,
272,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
8098,
9502,
272,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
8098,
9502,
272,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
8098,
9502,
272,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
8098,
9502,
272,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
8098,
9502,
272,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
8098,
9502,
272,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
8098,
9502,
272,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
8098,
9502,
272,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
8098,
9502,
272,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
8098,
9502,
272,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
8098,
9502,
272,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
272,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
272,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
272,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
272,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
272,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
272,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
272,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
272,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
272,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
272,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
272,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
272,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
272,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
272,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
272,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
272,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
272,
399,
7,
17,
7,
263,
327,
221,
378,
88,
2192,
1035,
7298,
13051,
272,
399,
7,
18,
7
] |
[
2018,
17660,
12340,
13732,
4497,
63,
32007,
4046,
687,
283,
32362,
15,
27839,
4149,
15,
31683,
15,
39,
7440,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
14,
199,
199,
624,
23662,
199,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
347,
3752,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
2550,
12,
2991,
63,
1224,
9,
339,
347,
4849,
8,
277,
12,
1210,
12,
2550,
534,
4768,
735,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
2550,
12,
12796,
63,
1224,
9,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2143,
8,
1210,
12,
277,
14,
2550,
12,
2991,
63,
1224,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
13391,
63,
2708,
8,
1210,
12,
277,
14,
2550,
12,
12796,
63,
1224,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
3088,
13,
32007,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
421,
199,
5680,
27368,
6957,
199,
199,
12796,
63,
1224,
275,
334,
272,
399,
1154,
88,
383,
7,
258,
327,
221,
378,
88,
383,
1035,
8098,
9502,
272,
399,
1154,
88,
614,
7,
258,
327,
221,
378,
88,
614,
1035,
8098,
9502,
272,
399,
1154,
88,
996,
7,
258,
327,
221,
378,
88,
996,
1035,
8098,
9502,
272,
399,
1154,
88,
1644,
7,
258,
327,
221,
378,
88,
1644,
1035,
8098,
9502,
272,
399,
1154,
88,
966,
7,
258,
327,
221,
378,
88,
966,
1035,
8098,
9502,
272,
399,
1154,
88,
1717,
7,
258,
327,
221,
378,
88,
1717,
1035,
8098,
9502,
272,
399,
1154,
88,
1690,
7,
258,
327,
221,
378,
88,
1690,
1035,
8098,
9502,
272,
399,
1154,
88,
1780,
7,
258,
327,
221,
378,
88,
1780,
1035,
8098,
9502,
272,
399,
1154,
88,
2036,
7,
258,
327,
221,
378,
88,
2036,
1035,
8098,
9502,
272,
399,
1154,
84,
7,
755,
327,
221,
378,
88,
1643,
1035,
8098,
9502,
272,
399,
1154,
78,
7,
755,
327,
221,
378,
88,
16,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
66,
7,
258,
327,
221,
378,
88,
16,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
67,
7,
258,
327,
221,
378,
88,
16,
35,
1035,
8098,
9502,
272,
399,
1154,
82,
7,
755,
327,
221,
378,
88,
16,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
69,
7,
258,
327,
221,
378,
88,
16,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
16,
70,
7,
258,
327,
221,
378,
88,
16,
38,
1035,
8098,
9502,
272,
399,
1154,
88,
709,
7,
258,
327,
221,
378,
88,
709,
1035,
8098,
9502,
272,
399,
1154,
88,
845,
7,
258,
327,
221,
378,
88,
845,
1035,
8098,
9502,
272,
399,
1154,
88,
713,
7,
258,
327,
221,
378,
88,
713,
1035,
8098,
9502,
272,
399,
1154,
88,
969,
7,
258,
327,
221,
378,
88,
969,
1035,
8098,
9502,
272,
399,
1154,
88,
1079,
7,
258,
327,
221,
378,
88,
1079,
1035,
8098,
9502,
272,
399,
1154,
88,
1046,
7,
258,
327,
221,
378,
88,
1046,
1035,
8098,
9502,
272,
399,
1154,
88,
975,
7,
258,
327,
221,
378,
88,
975,
1035,
8098,
9502,
272,
399,
1154,
88,
1196,
7,
258,
327,
221,
378,
88,
1196,
1035,
8098,
9502,
272,
399,
1154,
88,
1085,
7,
258,
327,
221,
378,
88,
1085,
1035,
8098,
9502,
272,
399,
1154,
88,
1167,
7,
258,
327,
221,
378,
88,
1167,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
65,
7,
258,
327,
221,
378,
88,
17,
33,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
66,
7,
258,
327,
221,
378,
88,
17,
34,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
67,
7,
258,
327,
221,
378,
88,
17,
35,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
68,
7,
258,
327,
221,
378,
88,
17,
36,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
69,
7,
258,
327,
221,
378,
88,
17,
37,
1035,
8098,
9502,
272,
399,
1154,
88,
17,
70,
7,
258,
327,
221,
378,
88,
17,
38,
1035,
8098,
9502,
272,
399,
7,
283,
263,
327,
221,
378,
88,
1165,
1035,
16796,
272,
399,
7,
11213,
263,
327,
221,
378,
88,
2025,
1035,
24232,
8132,
272,
399,
30385,
263,
327,
221,
378,
88,
1081,
1035,
11830,
8132,
272,
399,
11525,
7,
263,
327,
221,
378,
88,
1789,
1035,
18122,
5056,
272,
399,
7,
12913,
263,
327,
221,
378,
88,
1194,
1035,
30857,
5056,
272,
399,
5956,
7,
263,
327,
221,
378,
88,
821,
1035,
26684,
5056,
272,
399,
21840,
7,
263,
327,
221,
378,
88,
1479,
1035,
30602,
272,
399,
2,
4065,
263,
327,
221,
378,
88,
1465,
1035,
30876,
272,
399,
7,
360,
263,
327,
221,
378,
88,
1651,
1035,
6578,
20570,
272,
399,
358,
7,
263,
327,
221,
378,
88,
1398,
1035,
7052,
20570,
272,
399,
7,
10223,
263,
327,
221,
378,
88,
18,
33,
1035,
29725,
272,
399,
30269,
263,
327,
221,
378,
88,
18,
34,
1035,
18807,
5056,
272,
399,
1673,
263,
327,
221,
378,
88,
18,
35,
1035,
22849,
272,
399,
12418,
7,
263,
327,
221,
378,
88,
18,
36,
1035,
22553,
13,
18004,
272,
399,
30484,
263,
327,
221,
378,
88,
18,
37,
1035,
18530,
22348,
272,
399,
29957,
263,
327,
221,
378,
88,
18,
38,
1035,
20585,
272,
399,
7,
16,
7,
263,
327,
221,
378,
88,
1216,
1035,
7298,
20348,
272,
399,
7,
17,
7,
263,
327,
221,
378,
88,
2192,
1035,
7298,
13051,
272,
399,
7,
18,
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,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
hoosteeno/mozillians
|
vendor-local/lib/python/tablib/packages/yaml/composer.py
|
534
|
4921
|
__all__ = ['Composer', 'ComposerError']
from error import MarkedYAMLError
from events import *
from nodes import *
class ComposerError(MarkedYAMLError):
pass
class Composer(object):
def __init__(self):
self.anchors = {}
def check_node(self):
# Drop the STREAM-START event.
if self.check_event(StreamStartEvent):
self.get_event()
# If there are more documents available?
return not self.check_event(StreamEndEvent)
def get_node(self):
# Get the root node of the next document.
if not self.check_event(StreamEndEvent):
return self.compose_document()
def get_single_node(self):
# Drop the STREAM-START event.
self.get_event()
# Compose a document if the stream is not empty.
document = None
if not self.check_event(StreamEndEvent):
document = self.compose_document()
# Ensure that the stream contains no more documents.
if not self.check_event(StreamEndEvent):
event = self.get_event()
raise ComposerError("expected a single document in the stream",
document.start_mark, "but found another document",
event.start_mark)
# Drop the STREAM-END event.
self.get_event()
return document
def compose_document(self):
# Drop the DOCUMENT-START event.
self.get_event()
# Compose the root node.
node = self.compose_node(None, None)
# Drop the DOCUMENT-END event.
self.get_event()
self.anchors = {}
return node
def compose_node(self, parent, index):
if self.check_event(AliasEvent):
event = self.get_event()
anchor = event.anchor
if anchor not in self.anchors:
raise ComposerError(None, None, "found undefined alias %r"
% anchor.encode('utf-8'), event.start_mark)
return self.anchors[anchor]
event = self.peek_event()
anchor = event.anchor
if anchor is not None:
if anchor in self.anchors:
raise ComposerError("found duplicate anchor %r; first occurence"
% anchor.encode('utf-8'), self.anchors[anchor].start_mark,
"second occurence", event.start_mark)
self.descend_resolver(parent, index)
if self.check_event(ScalarEvent):
node = self.compose_scalar_node(anchor)
elif self.check_event(SequenceStartEvent):
node = self.compose_sequence_node(anchor)
elif self.check_event(MappingStartEvent):
node = self.compose_mapping_node(anchor)
self.ascend_resolver()
return node
def compose_scalar_node(self, anchor):
event = self.get_event()
tag = event.tag
if tag is None or tag == u'!':
tag = self.resolve(ScalarNode, event.value, event.implicit)
node = ScalarNode(tag, event.value,
event.start_mark, event.end_mark, style=event.style)
if anchor is not None:
self.anchors[anchor] = node
return node
def compose_sequence_node(self, anchor):
start_event = self.get_event()
tag = start_event.tag
if tag is None or tag == u'!':
tag = self.resolve(SequenceNode, None, start_event.implicit)
node = SequenceNode(tag, [],
start_event.start_mark, None,
flow_style=start_event.flow_style)
if anchor is not None:
self.anchors[anchor] = node
index = 0
while not self.check_event(SequenceEndEvent):
node.value.append(self.compose_node(node, index))
index += 1
end_event = self.get_event()
node.end_mark = end_event.end_mark
return node
def compose_mapping_node(self, anchor):
start_event = self.get_event()
tag = start_event.tag
if tag is None or tag == u'!':
tag = self.resolve(MappingNode, None, start_event.implicit)
node = MappingNode(tag, [],
start_event.start_mark, None,
flow_style=start_event.flow_style)
if anchor is not None:
self.anchors[anchor] = node
while not self.check_event(MappingEndEvent):
#key_event = self.peek_event()
item_key = self.compose_node(node, None)
#if item_key in node.value:
# raise ComposerError("while composing a mapping", start_event.start_mark,
# "found duplicate key", key_event.start_mark)
item_value = self.compose_node(node, item_key)
#node.value[item_key] = item_value
node.value.append((item_key, item_value))
end_event = self.get_event()
node.end_mark = end_event.end_mark
return node
|
bsd-3-clause
|
[
199,
363,
452,
363,
275,
788,
32325,
297,
283,
32325,
547,
418,
199,
199,
504,
1125,
492,
7173,
379,
23103,
547,
199,
504,
4474,
492,
627,
199,
504,
3380,
492,
627,
199,
199,
533,
3599,
13041,
547,
8,
6470,
379,
23103,
547,
304,
272,
986,
199,
199,
533,
3599,
13041,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
25942,
275,
1052,
339,
347,
1104,
63,
932,
8,
277,
304,
267,
327,
18110,
314,
4384,
8909,
13,
7363,
1566,
14,
267,
340,
291,
14,
1074,
63,
1430,
8,
3296,
3162,
2390,
304,
288,
291,
14,
362,
63,
1430,
342,
398,
327,
982,
2337,
787,
1655,
8247,
2808,
31,
267,
372,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
9,
339,
347,
664,
63,
932,
8,
277,
304,
267,
327,
2372,
314,
1738,
1031,
402,
314,
2163,
2213,
14,
267,
340,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
304,
288,
372,
291,
14,
12607,
63,
3554,
342,
339,
347,
664,
63,
4780,
63,
932,
8,
277,
304,
267,
327,
18110,
314,
4384,
8909,
13,
7363,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
327,
3599,
3362,
282,
2213,
340,
314,
2547,
365,
440,
2701,
14,
267,
2213,
275,
488,
267,
340,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
304,
288,
2213,
275,
291,
14,
12607,
63,
3554,
342,
398,
327,
7523,
626,
314,
2547,
3509,
949,
1655,
8247,
14,
267,
340,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
304,
288,
1566,
275,
291,
14,
362,
63,
1430,
342,
288,
746,
3599,
13041,
547,
480,
2062,
282,
2849,
2213,
315,
314,
2547,
401,
490,
2213,
14,
928,
63,
1657,
12,
298,
7911,
1911,
4573,
2213,
401,
490,
1566,
14,
928,
63,
1657,
9,
398,
327,
18110,
314,
4384,
8909,
13,
3902,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
372,
2213,
339,
347,
23366,
63,
3554,
8,
277,
304,
267,
327,
18110,
314,
29970,
13,
7363,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
327,
3599,
3362,
314,
1738,
1031,
14,
267,
1031,
275,
291,
14,
12607,
63,
932,
8,
403,
12,
488,
9,
398,
327,
18110,
314,
29970,
13,
3902,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
291,
14,
25942,
275,
1052,
267,
372,
1031,
339,
347,
23366,
63,
932,
8,
277,
12,
1676,
12,
1478,
304,
267,
340,
291,
14,
1074,
63,
1430,
8,
14149,
2390,
304,
288,
1566,
275,
291,
14,
362,
63,
1430,
342,
288,
12514,
275,
1566,
14,
11498,
288,
340,
12514,
440,
315,
291,
14,
25942,
26,
355,
746,
3599,
13041,
547,
8,
403,
12,
488,
12,
298,
4214,
10942,
5162,
450,
82,
2,
717,
450,
12514,
14,
2143,
360,
1624,
13,
24,
659,
1566,
14,
928,
63,
1657,
9,
288,
372,
291,
14,
25942,
59,
11498,
61,
267,
1566,
275,
291,
14,
13164,
63,
1430,
342,
267,
12514,
275,
1566,
14,
11498,
267,
340,
12514,
365,
440,
488,
26,
288,
340,
12514,
315,
291,
14,
25942,
26,
355,
746,
3599,
13041,
547,
480,
4214,
9250,
12514,
450,
82,
27,
1642,
14706,
608,
21225,
2,
717,
450,
12514,
14,
2143,
360,
1624,
13,
24,
659,
291,
14,
25942,
59,
11498,
1055,
928,
63,
1657,
12,
717,
298,
4375,
14706,
608,
21225,
401,
1566,
14,
928,
63,
1657,
9,
267,
291,
14,
18180,
63,
7717,
8,
1708,
12,
1478,
9,
267,
340,
291,
14,
1074,
63,
1430,
8,
13090,
2390,
304,
288,
1031,
275,
291,
14,
12607,
63,
7033,
63,
932,
8,
11498,
9,
267,
916,
291,
14,
1074,
63,
1430,
8,
5826,
3162,
2390,
304,
288,
1031,
275,
291,
14,
12607,
63,
4041,
63,
932,
8,
11498,
9,
267,
916,
291,
14,
1074,
63,
1430,
8,
7674,
3162,
2390,
304,
288,
1031,
275,
291,
14,
12607,
63,
4745,
63,
932,
8,
11498,
9,
267,
291,
14,
10125,
500,
63,
7717,
342,
267,
372,
1031,
339,
347,
23366,
63,
7033,
63,
932,
8,
277,
12,
12514,
304,
267,
1566,
275,
291,
14,
362,
63,
1430,
342,
267,
1947,
275,
1566,
14,
1450,
267,
340,
1947,
365,
488,
503,
1947,
508,
399,
7,
27676,
288,
1947,
275,
291,
14,
6983,
8,
13090,
1716,
12,
1566,
14,
585,
12,
1566,
14,
11886,
9,
267,
1031,
275,
24289,
1716,
8,
1450,
12,
1566,
14,
585,
12,
355,
1566,
14,
928,
63,
1657,
12,
1566,
14,
500,
63,
1657,
12,
3449,
29,
1430,
14,
2487,
9,
267,
340,
12514,
365,
440,
488,
26,
288,
291,
14,
25942,
59,
11498,
61,
275,
1031,
267,
372,
1031,
339,
347,
23366,
63,
4041,
63,
932,
8,
277,
12,
12514,
304,
267,
1343,
63,
1430,
275,
291,
14,
362,
63,
1430,
342,
267,
1947,
275,
1343,
63,
1430,
14,
1450,
267,
340,
1947,
365,
488,
503,
1947,
508,
399,
7,
27676,
288,
1947,
275,
291,
14,
6983,
8,
5826,
1716,
12,
488,
12,
1343,
63,
1430,
14,
11886,
9,
267,
1031,
275,
10975,
1716,
8,
1450,
12,
990,
355,
1343,
63,
1430,
14,
928,
63,
1657,
12,
488,
12,
355,
6369,
63,
2487,
29,
928,
63,
1430,
14,
1659,
63,
2487,
9,
267,
340,
12514,
365,
440,
488,
26,
288,
291,
14,
25942,
59,
11498,
61,
275,
1031,
267,
1478,
275,
378,
267,
1830,
440,
291,
14,
1074,
63,
1430,
8,
5826,
3005,
2390,
304,
288,
1031,
14,
585,
14,
740,
8,
277,
14,
12607,
63,
932,
8,
932,
12,
1478,
430,
288,
1478,
847,
413,
267,
1284,
63,
1430,
275,
291,
14,
362,
63,
1430,
342,
267,
1031,
14,
500,
63,
1657,
275,
1284,
63,
1430,
14,
500,
63,
1657,
267,
372,
1031,
339,
347,
23366,
63,
4745,
63,
932,
8,
277,
12,
12514,
304,
267,
1343,
63,
1430,
275,
291,
14,
362,
63,
1430,
342,
267,
1947,
275,
1343,
63,
1430,
14,
1450,
267,
340,
1947,
365,
488,
503,
1947,
508,
399,
7,
27676,
288,
1947,
275,
291,
14,
6983,
8,
7674,
1716,
12,
488,
12,
1343,
63,
1430,
14,
11886,
9,
267,
1031,
275,
12340,
1716,
8,
1450,
12,
990,
355,
1343,
63,
1430,
14,
928,
63,
1657,
12,
488,
12,
355,
6369,
63,
2487,
29,
928,
63,
1430,
14,
1659,
63
] |
[
363,
452,
363,
275,
788,
32325,
297,
283,
32325,
547,
418,
199,
199,
504,
1125,
492,
7173,
379,
23103,
547,
199,
504,
4474,
492,
627,
199,
504,
3380,
492,
627,
199,
199,
533,
3599,
13041,
547,
8,
6470,
379,
23103,
547,
304,
272,
986,
199,
199,
533,
3599,
13041,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
25942,
275,
1052,
339,
347,
1104,
63,
932,
8,
277,
304,
267,
327,
18110,
314,
4384,
8909,
13,
7363,
1566,
14,
267,
340,
291,
14,
1074,
63,
1430,
8,
3296,
3162,
2390,
304,
288,
291,
14,
362,
63,
1430,
342,
398,
327,
982,
2337,
787,
1655,
8247,
2808,
31,
267,
372,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
9,
339,
347,
664,
63,
932,
8,
277,
304,
267,
327,
2372,
314,
1738,
1031,
402,
314,
2163,
2213,
14,
267,
340,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
304,
288,
372,
291,
14,
12607,
63,
3554,
342,
339,
347,
664,
63,
4780,
63,
932,
8,
277,
304,
267,
327,
18110,
314,
4384,
8909,
13,
7363,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
327,
3599,
3362,
282,
2213,
340,
314,
2547,
365,
440,
2701,
14,
267,
2213,
275,
488,
267,
340,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
304,
288,
2213,
275,
291,
14,
12607,
63,
3554,
342,
398,
327,
7523,
626,
314,
2547,
3509,
949,
1655,
8247,
14,
267,
340,
440,
291,
14,
1074,
63,
1430,
8,
3296,
3005,
2390,
304,
288,
1566,
275,
291,
14,
362,
63,
1430,
342,
288,
746,
3599,
13041,
547,
480,
2062,
282,
2849,
2213,
315,
314,
2547,
401,
490,
2213,
14,
928,
63,
1657,
12,
298,
7911,
1911,
4573,
2213,
401,
490,
1566,
14,
928,
63,
1657,
9,
398,
327,
18110,
314,
4384,
8909,
13,
3902,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
372,
2213,
339,
347,
23366,
63,
3554,
8,
277,
304,
267,
327,
18110,
314,
29970,
13,
7363,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
327,
3599,
3362,
314,
1738,
1031,
14,
267,
1031,
275,
291,
14,
12607,
63,
932,
8,
403,
12,
488,
9,
398,
327,
18110,
314,
29970,
13,
3902,
1566,
14,
267,
291,
14,
362,
63,
1430,
342,
398,
291,
14,
25942,
275,
1052,
267,
372,
1031,
339,
347,
23366,
63,
932,
8,
277,
12,
1676,
12,
1478,
304,
267,
340,
291,
14,
1074,
63,
1430,
8,
14149,
2390,
304,
288,
1566,
275,
291,
14,
362,
63,
1430,
342,
288,
12514,
275,
1566,
14,
11498,
288,
340,
12514,
440,
315,
291,
14,
25942,
26,
355,
746,
3599,
13041,
547,
8,
403,
12,
488,
12,
298,
4214,
10942,
5162,
450,
82,
2,
717,
450,
12514,
14,
2143,
360,
1624,
13,
24,
659,
1566,
14,
928,
63,
1657,
9,
288,
372,
291,
14,
25942,
59,
11498,
61,
267,
1566,
275,
291,
14,
13164,
63,
1430,
342,
267,
12514,
275,
1566,
14,
11498,
267,
340,
12514,
365,
440,
488,
26,
288,
340,
12514,
315,
291,
14,
25942,
26,
355,
746,
3599,
13041,
547,
480,
4214,
9250,
12514,
450,
82,
27,
1642,
14706,
608,
21225,
2,
717,
450,
12514,
14,
2143,
360,
1624,
13,
24,
659,
291,
14,
25942,
59,
11498,
1055,
928,
63,
1657,
12,
717,
298,
4375,
14706,
608,
21225,
401,
1566,
14,
928,
63,
1657,
9,
267,
291,
14,
18180,
63,
7717,
8,
1708,
12,
1478,
9,
267,
340,
291,
14,
1074,
63,
1430,
8,
13090,
2390,
304,
288,
1031,
275,
291,
14,
12607,
63,
7033,
63,
932,
8,
11498,
9,
267,
916,
291,
14,
1074,
63,
1430,
8,
5826,
3162,
2390,
304,
288,
1031,
275,
291,
14,
12607,
63,
4041,
63,
932,
8,
11498,
9,
267,
916,
291,
14,
1074,
63,
1430,
8,
7674,
3162,
2390,
304,
288,
1031,
275,
291,
14,
12607,
63,
4745,
63,
932,
8,
11498,
9,
267,
291,
14,
10125,
500,
63,
7717,
342,
267,
372,
1031,
339,
347,
23366,
63,
7033,
63,
932,
8,
277,
12,
12514,
304,
267,
1566,
275,
291,
14,
362,
63,
1430,
342,
267,
1947,
275,
1566,
14,
1450,
267,
340,
1947,
365,
488,
503,
1947,
508,
399,
7,
27676,
288,
1947,
275,
291,
14,
6983,
8,
13090,
1716,
12,
1566,
14,
585,
12,
1566,
14,
11886,
9,
267,
1031,
275,
24289,
1716,
8,
1450,
12,
1566,
14,
585,
12,
355,
1566,
14,
928,
63,
1657,
12,
1566,
14,
500,
63,
1657,
12,
3449,
29,
1430,
14,
2487,
9,
267,
340,
12514,
365,
440,
488,
26,
288,
291,
14,
25942,
59,
11498,
61,
275,
1031,
267,
372,
1031,
339,
347,
23366,
63,
4041,
63,
932,
8,
277,
12,
12514,
304,
267,
1343,
63,
1430,
275,
291,
14,
362,
63,
1430,
342,
267,
1947,
275,
1343,
63,
1430,
14,
1450,
267,
340,
1947,
365,
488,
503,
1947,
508,
399,
7,
27676,
288,
1947,
275,
291,
14,
6983,
8,
5826,
1716,
12,
488,
12,
1343,
63,
1430,
14,
11886,
9,
267,
1031,
275,
10975,
1716,
8,
1450,
12,
990,
355,
1343,
63,
1430,
14,
928,
63,
1657,
12,
488,
12,
355,
6369,
63,
2487,
29,
928,
63,
1430,
14,
1659,
63,
2487,
9,
267,
340,
12514,
365,
440,
488,
26,
288,
291,
14,
25942,
59,
11498,
61,
275,
1031,
267,
1478,
275,
378,
267,
1830,
440,
291,
14,
1074,
63,
1430,
8,
5826,
3005,
2390,
304,
288,
1031,
14,
585,
14,
740,
8,
277,
14,
12607,
63,
932,
8,
932,
12,
1478,
430,
288,
1478,
847,
413,
267,
1284,
63,
1430,
275,
291,
14,
362,
63,
1430,
342,
267,
1031,
14,
500,
63,
1657,
275,
1284,
63,
1430,
14,
500,
63,
1657,
267,
372,
1031,
339,
347,
23366,
63,
4745,
63,
932,
8,
277,
12,
12514,
304,
267,
1343,
63,
1430,
275,
291,
14,
362,
63,
1430,
342,
267,
1947,
275,
1343,
63,
1430,
14,
1450,
267,
340,
1947,
365,
488,
503,
1947,
508,
399,
7,
27676,
288,
1947,
275,
291,
14,
6983,
8,
7674,
1716,
12,
488,
12,
1343,
63,
1430,
14,
11886,
9,
267,
1031,
275,
12340,
1716,
8,
1450,
12,
990,
355,
1343,
63,
1430,
14,
928,
63,
1657,
12,
488,
12,
355,
6369,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
napalm-automation/napalm-yang
|
napalm_yang/models/openconfig/network_instances/network_instance/protocols/protocol/isis/levels/level/link_state_database/lsp/tlvs/tlv/mt_isn/neighbors/neighbor/subTLVs/subTLVs_/bandwidth_constraints/__init__.py
|
1
|
12844
|
# -*- coding: utf-8 -*-
from operator import attrgetter
from pyangbind.lib.yangtypes import RestrictedPrecisionDecimalType
from pyangbind.lib.yangtypes import RestrictedClassType
from pyangbind.lib.yangtypes import TypedListType
from pyangbind.lib.yangtypes import YANGBool
from pyangbind.lib.yangtypes import YANGListType
from pyangbind.lib.yangtypes import YANGDynClass
from pyangbind.lib.yangtypes import ReferenceType
from pyangbind.lib.base import PybindBase
from collections import OrderedDict
from decimal import Decimal
from bitarray import bitarray
import six
# PY3 support of some PY2 keywords (needs improved)
if six.PY3:
import builtins as __builtin__
long = int
elif six.PY2:
import __builtin__
from . import state
class bandwidth_constraints(PybindBase):
"""
This class was auto-generated by the PythonClass plugin for PYANG
from YANG module openconfig-network-instance - based on the path /network-instances/network-instance/protocols/protocol/isis/levels/level/link-state-database/lsp/tlvs/tlv/mt-isn/neighbors/neighbor/subTLVs/subTLVs/bandwidth-constraints. Each member element of
the container is represented as a class variable - with a specific
YANG type.
YANG Description: This container defines bandwidth-constraints. For DS-TE, the
existing Maximum Reservable link bandwidth parameter is retained,
but its semantics is generalized and interpreted as the aggregate
bandwidth constraint across all Class-Types
"""
__slots__ = ("_path_helper", "_extmethods", "__state")
_yang_name = "bandwidth-constraints"
_pybind_generated_by = "container"
def __init__(self, *args, **kwargs):
self._path_helper = False
self._extmethods = False
self.__state = YANGDynClass(
base=state.state,
is_container="container",
yang_name="state",
parent=self,
path_helper=self._path_helper,
extmethods=self._extmethods,
register_paths=True,
extensions=None,
namespace="http://openconfig.net/yang/network-instance",
defining_module="openconfig-network-instance",
yang_type="container",
is_config=False,
)
load = kwargs.pop("load", None)
if args:
if len(args) > 1:
raise TypeError("cannot create a YANG container with >1 argument")
all_attr = True
for e in self._pyangbind_elements:
if not hasattr(args[0], e):
all_attr = False
break
if not all_attr:
raise ValueError("Supplied object did not have the correct attributes")
for e in self._pyangbind_elements:
nobj = getattr(args[0], e)
if nobj._changed() is False:
continue
setmethod = getattr(self, "_set_%s" % e)
if load is None:
setmethod(getattr(args[0], e))
else:
setmethod(getattr(args[0], e), load=load)
def _path(self):
if hasattr(self, "_parent"):
return self._parent._path() + [self._yang_name]
else:
return [
"network-instances",
"network-instance",
"protocols",
"protocol",
"isis",
"levels",
"level",
"link-state-database",
"lsp",
"tlvs",
"tlv",
"mt-isn",
"neighbors",
"neighbor",
"subTLVs",
"subTLVs",
"bandwidth-constraints",
]
def _get_state(self):
"""
Getter method for state, mapped from YANG variable /network_instances/network_instance/protocols/protocol/isis/levels/level/link_state_database/lsp/tlvs/tlv/mt_isn/neighbors/neighbor/subTLVs/subTLVs/bandwidth_constraints/state (container)
YANG Description: State parameters of IS Extended Reachability sub-TLV 22.
"""
return self.__state
def _set_state(self, v, load=False):
"""
Setter method for state, mapped from YANG variable /network_instances/network_instance/protocols/protocol/isis/levels/level/link_state_database/lsp/tlvs/tlv/mt_isn/neighbors/neighbor/subTLVs/subTLVs/bandwidth_constraints/state (container)
If this variable is read-only (config: false) in the
source YANG file, then _set_state is considered as a private
method. Backends looking to populate this variable should
do so via calling thisObj._set_state() directly.
YANG Description: State parameters of IS Extended Reachability sub-TLV 22.
"""
if hasattr(v, "_utype"):
v = v._utype(v)
try:
t = YANGDynClass(
v,
base=state.state,
is_container="container",
yang_name="state",
parent=self,
path_helper=self._path_helper,
extmethods=self._extmethods,
register_paths=True,
extensions=None,
namespace="http://openconfig.net/yang/network-instance",
defining_module="openconfig-network-instance",
yang_type="container",
is_config=False,
)
except (TypeError, ValueError):
raise ValueError(
{
"error-string": """state must be of a type compatible with container""",
"defined-type": "container",
"generated-type": """YANGDynClass(base=state.state, is_container='container', yang_name="state", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions=None, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='container', is_config=False)""",
}
)
self.__state = t
if hasattr(self, "_set"):
self._set()
def _unset_state(self):
self.__state = YANGDynClass(
base=state.state,
is_container="container",
yang_name="state",
parent=self,
path_helper=self._path_helper,
extmethods=self._extmethods,
register_paths=True,
extensions=None,
namespace="http://openconfig.net/yang/network-instance",
defining_module="openconfig-network-instance",
yang_type="container",
is_config=False,
)
state = __builtin__.property(_get_state)
_pyangbind_elements = OrderedDict([("state", state)])
from . import state
class bandwidth_constraints(PybindBase):
"""
This class was auto-generated by the PythonClass plugin for PYANG
from YANG module openconfig-network-instance-l2 - based on the path /network-instances/network-instance/protocols/protocol/isis/levels/level/link-state-database/lsp/tlvs/tlv/mt-isn/neighbors/neighbor/subTLVs/subTLVs/bandwidth-constraints. Each member element of
the container is represented as a class variable - with a specific
YANG type.
YANG Description: This container defines bandwidth-constraints. For DS-TE, the
existing Maximum Reservable link bandwidth parameter is retained,
but its semantics is generalized and interpreted as the aggregate
bandwidth constraint across all Class-Types
"""
__slots__ = ("_path_helper", "_extmethods", "__state")
_yang_name = "bandwidth-constraints"
_pybind_generated_by = "container"
def __init__(self, *args, **kwargs):
self._path_helper = False
self._extmethods = False
self.__state = YANGDynClass(
base=state.state,
is_container="container",
yang_name="state",
parent=self,
path_helper=self._path_helper,
extmethods=self._extmethods,
register_paths=True,
extensions=None,
namespace="http://openconfig.net/yang/network-instance",
defining_module="openconfig-network-instance",
yang_type="container",
is_config=False,
)
load = kwargs.pop("load", None)
if args:
if len(args) > 1:
raise TypeError("cannot create a YANG container with >1 argument")
all_attr = True
for e in self._pyangbind_elements:
if not hasattr(args[0], e):
all_attr = False
break
if not all_attr:
raise ValueError("Supplied object did not have the correct attributes")
for e in self._pyangbind_elements:
nobj = getattr(args[0], e)
if nobj._changed() is False:
continue
setmethod = getattr(self, "_set_%s" % e)
if load is None:
setmethod(getattr(args[0], e))
else:
setmethod(getattr(args[0], e), load=load)
def _path(self):
if hasattr(self, "_parent"):
return self._parent._path() + [self._yang_name]
else:
return [
"network-instances",
"network-instance",
"protocols",
"protocol",
"isis",
"levels",
"level",
"link-state-database",
"lsp",
"tlvs",
"tlv",
"mt-isn",
"neighbors",
"neighbor",
"subTLVs",
"subTLVs",
"bandwidth-constraints",
]
def _get_state(self):
"""
Getter method for state, mapped from YANG variable /network_instances/network_instance/protocols/protocol/isis/levels/level/link_state_database/lsp/tlvs/tlv/mt_isn/neighbors/neighbor/subTLVs/subTLVs/bandwidth_constraints/state (container)
YANG Description: State parameters of IS Extended Reachability sub-TLV 22.
"""
return self.__state
def _set_state(self, v, load=False):
"""
Setter method for state, mapped from YANG variable /network_instances/network_instance/protocols/protocol/isis/levels/level/link_state_database/lsp/tlvs/tlv/mt_isn/neighbors/neighbor/subTLVs/subTLVs/bandwidth_constraints/state (container)
If this variable is read-only (config: false) in the
source YANG file, then _set_state is considered as a private
method. Backends looking to populate this variable should
do so via calling thisObj._set_state() directly.
YANG Description: State parameters of IS Extended Reachability sub-TLV 22.
"""
if hasattr(v, "_utype"):
v = v._utype(v)
try:
t = YANGDynClass(
v,
base=state.state,
is_container="container",
yang_name="state",
parent=self,
path_helper=self._path_helper,
extmethods=self._extmethods,
register_paths=True,
extensions=None,
namespace="http://openconfig.net/yang/network-instance",
defining_module="openconfig-network-instance",
yang_type="container",
is_config=False,
)
except (TypeError, ValueError):
raise ValueError(
{
"error-string": """state must be of a type compatible with container""",
"defined-type": "container",
"generated-type": """YANGDynClass(base=state.state, is_container='container', yang_name="state", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions=None, namespace='http://openconfig.net/yang/network-instance', defining_module='openconfig-network-instance', yang_type='container', is_config=False)""",
}
)
self.__state = t
if hasattr(self, "_set"):
self._set()
def _unset_state(self):
self.__state = YANGDynClass(
base=state.state,
is_container="container",
yang_name="state",
parent=self,
path_helper=self._path_helper,
extmethods=self._extmethods,
register_paths=True,
extensions=None,
namespace="http://openconfig.net/yang/network-instance",
defining_module="openconfig-network-instance",
yang_type="container",
is_config=False,
)
state = __builtin__.property(_get_state)
_pyangbind_elements = OrderedDict([("state", state)])
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
4182,
492,
21829,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
32491,
1522,
28984,
6745,
804,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
32491,
1522,
31165,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
31906,
22113,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
29332,
10349,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
29332,
22113,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
29332,
36,
1236,
2543,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
10944,
804,
199,
504,
1134,
621,
3409,
14,
773,
14,
1095,
492,
1611,
3409,
1563,
199,
504,
5055,
492,
8773,
199,
504,
6107,
492,
6345,
199,
504,
4546,
1144,
492,
4546,
1144,
199,
646,
3816,
199,
199,
3,
7843,
19,
2291,
402,
2005,
7843,
18,
7681,
334,
10065,
1742,
26429,
9,
199,
692,
3816,
14,
4521,
19,
26,
272,
492,
12963,
465,
636,
5351,
363,
339,
1846,
275,
1109,
199,
4164,
3816,
14,
4521,
18,
26,
272,
492,
636,
5351,
363,
199,
199,
504,
1275,
492,
1174,
421,
199,
533,
20434,
63,
9882,
8,
2713,
3409,
1563,
304,
272,
408,
523,
961,
1021,
1990,
2599,
13,
10176,
701,
314,
2018,
2543,
3589,
367,
7843,
3986,
523,
687,
29332,
859,
1551,
888,
13,
1200,
13,
842,
446,
4079,
641,
314,
931,
1182,
1200,
13,
5990,
15,
1200,
13,
842,
15,
16541,
15,
3922,
15,
9200,
15,
11402,
15,
1896,
15,
1073,
13,
929,
13,
4659,
15,
478,
80,
15,
5019,
3122,
15,
19020,
15,
2037,
13,
374,
78,
15,
11113,
15,
13881,
15,
954,
14846,
83,
15,
954,
14846,
83,
15,
18358,
13,
9882,
14,
7048,
3653,
1819,
402,
523,
314,
3970,
365,
11159,
465,
282,
1021,
1750,
446,
543,
282,
2488,
523,
29332,
730,
14,
819,
29332,
11994,
26,
961,
3970,
7890,
20434,
13,
9882,
14,
2104,
577,
51,
13,
3727,
12,
314,
199,
5952,
14212,
799,
29454,
2142,
20434,
2725,
365,
30403,
12,
199,
7911,
2399,
19002,
365,
8605,
1759,
436,
11922,
465,
314,
9531,
199,
18358,
5828,
9371,
1006,
8089,
13,
4100,
523,
408,
272,
636,
7257,
363,
275,
1689,
63,
515,
63,
3676,
401,
2668,
832,
2474,
401,
4396,
929,
531,
339,
485,
11912,
63,
354,
275,
298,
18358,
13,
9882,
2,
339,
485,
647,
3409,
63,
10176,
63,
991,
275,
298,
3600,
2,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
291,
423,
515,
63,
3676,
275,
756,
398,
291,
423,
832,
2474,
275,
756,
267,
291,
855,
929,
275,
29332,
36,
1236,
2543,
8,
288,
1300,
29,
929,
14,
929,
12,
288,
365,
63,
3600,
628,
3600,
401,
288,
31193,
63,
354,
628,
929,
401,
288,
1676,
29,
277,
12,
288,
931,
63,
3676,
29,
277,
423,
515,
63,
3676,
12,
288,
1599,
2474,
29,
277,
423,
832,
2474,
12,
288,
2274,
63,
3771,
29,
549,
12,
288,
5478,
29,
403,
12,
288,
3231,
628,
1014,
921,
10010,
14,
846,
15,
11912,
15,
1200,
13,
842,
401,
288,
12669,
63,
578,
628,
10010,
13,
1200,
13,
842,
401,
288,
31193,
63,
466,
628,
3600,
401,
288,
365,
63,
888,
29,
797,
12,
267,
776,
398,
2248,
275,
2074,
14,
1935,
480,
912,
401,
488,
9,
267,
340,
1249,
26,
288,
340,
822,
8,
589,
9,
690,
413,
26,
355,
746,
3146,
480,
11250,
1218,
282,
29332,
3970,
543,
690,
17,
1423,
531,
288,
1006,
63,
962,
275,
715,
288,
367,
325,
315,
291,
423,
647,
621,
3409,
63,
5527,
26,
355,
340,
440,
2688,
8,
589,
59,
16,
467,
325,
304,
490,
1006,
63,
962,
275,
756,
490,
2059,
288,
340,
440,
1006,
63,
962,
26,
355,
746,
1722,
480,
17127,
1857,
909,
8103,
440,
1172,
314,
3211,
3004,
531,
288,
367,
325,
315,
291,
423,
647,
621,
3409,
63,
5527,
26,
355,
949,
468,
275,
2519,
8,
589,
59,
16,
467,
325,
9,
355,
340,
949,
468,
423,
2489,
342,
365,
756,
26,
490,
1980,
355,
663,
765,
275,
2519,
8,
277,
12,
2668,
409,
4970,
83,
2,
450,
325,
9,
355,
340,
2248,
365,
488,
26,
490,
663,
765,
8,
5675,
8,
589,
59,
16,
467,
325,
430,
355,
587,
26,
490,
663,
765,
8,
5675,
8,
589,
59,
16,
467,
325,
395,
2248,
29,
912,
9,
339,
347,
485,
515,
8,
277,
304,
267,
340,
2688,
8,
277,
12,
2668,
1708,
2349,
288,
372,
291,
423,
1708,
423,
515,
342,
435,
359,
277,
423,
11912,
63,
354,
61,
267,
587,
26,
288,
372,
359,
355,
298,
1200,
13,
5990,
401,
355,
298,
1200,
13,
842,
401,
355,
298,
16541,
401,
355,
298,
3922,
401,
355,
298,
9200,
401,
355,
298,
11402,
401,
355,
298,
1896,
401,
355,
298,
1073,
13,
929,
13,
4659,
401,
355,
298,
478,
80,
401,
355,
298,
5019,
3122,
401,
355,
298,
19020,
401,
355,
298,
2037,
13,
374,
78,
401,
355,
298,
11113,
401,
355,
298,
13881,
401,
355,
298,
954,
14846,
83,
401,
355,
298,
954,
14846,
83,
401,
355,
298,
18358,
13,
9882,
401,
288,
1622,
339,
347,
485,
362,
63,
929,
8,
277,
304,
267,
408,
272,
2372,
351,
1083,
367,
1174,
12,
9994,
687,
29332,
1750,
1182,
1200,
63,
5990,
15,
1200,
63,
842,
15,
16541,
15,
3922,
15,
9200,
15,
11402,
15,
1896,
15,
1073,
63,
929,
63,
4659,
15,
478,
80,
15,
5019,
3122,
15,
19020,
15,
2037,
63,
374,
78,
15,
11113,
15,
13881,
15,
954,
14846,
83,
15,
954,
14846,
83,
15,
18358,
63,
9882,
15,
929,
334,
3600,
9,
339,
29332,
11994,
26,
8511,
2633,
402,
2281,
13706,
799,
1225,
3616,
1007,
13,
14846,
6928,
14,
272,
408,
267,
372,
291,
855,
929,
339,
347,
485,
409,
63,
929,
8,
277,
12,
373,
12,
2248,
29,
797,
304,
267,
408,
272,
2494,
351,
1083,
367,
1174,
12,
9994,
687,
29332,
1750,
1182,
1200,
63,
5990,
15,
1200,
63,
842,
15,
16541,
15,
3922,
15,
9200,
15,
11402,
15,
1896,
15,
1073,
63,
929,
63,
4659,
15,
478,
80,
15,
5019,
3122,
15,
19020,
15,
2037,
63,
374,
78
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
4182,
492,
21829,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
32491,
1522,
28984,
6745,
804,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
32491,
1522,
31165,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
31906,
22113,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
29332,
10349,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
29332,
22113,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
29332,
36,
1236,
2543,
199,
504,
1134,
621,
3409,
14,
773,
14,
11912,
1313,
492,
10944,
804,
199,
504,
1134,
621,
3409,
14,
773,
14,
1095,
492,
1611,
3409,
1563,
199,
504,
5055,
492,
8773,
199,
504,
6107,
492,
6345,
199,
504,
4546,
1144,
492,
4546,
1144,
199,
646,
3816,
199,
199,
3,
7843,
19,
2291,
402,
2005,
7843,
18,
7681,
334,
10065,
1742,
26429,
9,
199,
692,
3816,
14,
4521,
19,
26,
272,
492,
12963,
465,
636,
5351,
363,
339,
1846,
275,
1109,
199,
4164,
3816,
14,
4521,
18,
26,
272,
492,
636,
5351,
363,
199,
199,
504,
1275,
492,
1174,
421,
199,
533,
20434,
63,
9882,
8,
2713,
3409,
1563,
304,
272,
408,
523,
961,
1021,
1990,
2599,
13,
10176,
701,
314,
2018,
2543,
3589,
367,
7843,
3986,
523,
687,
29332,
859,
1551,
888,
13,
1200,
13,
842,
446,
4079,
641,
314,
931,
1182,
1200,
13,
5990,
15,
1200,
13,
842,
15,
16541,
15,
3922,
15,
9200,
15,
11402,
15,
1896,
15,
1073,
13,
929,
13,
4659,
15,
478,
80,
15,
5019,
3122,
15,
19020,
15,
2037,
13,
374,
78,
15,
11113,
15,
13881,
15,
954,
14846,
83,
15,
954,
14846,
83,
15,
18358,
13,
9882,
14,
7048,
3653,
1819,
402,
523,
314,
3970,
365,
11159,
465,
282,
1021,
1750,
446,
543,
282,
2488,
523,
29332,
730,
14,
819,
29332,
11994,
26,
961,
3970,
7890,
20434,
13,
9882,
14,
2104,
577,
51,
13,
3727,
12,
314,
199,
5952,
14212,
799,
29454,
2142,
20434,
2725,
365,
30403,
12,
199,
7911,
2399,
19002,
365,
8605,
1759,
436,
11922,
465,
314,
9531,
199,
18358,
5828,
9371,
1006,
8089,
13,
4100,
523,
408,
272,
636,
7257,
363,
275,
1689,
63,
515,
63,
3676,
401,
2668,
832,
2474,
401,
4396,
929,
531,
339,
485,
11912,
63,
354,
275,
298,
18358,
13,
9882,
2,
339,
485,
647,
3409,
63,
10176,
63,
991,
275,
298,
3600,
2,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
291,
423,
515,
63,
3676,
275,
756,
398,
291,
423,
832,
2474,
275,
756,
267,
291,
855,
929,
275,
29332,
36,
1236,
2543,
8,
288,
1300,
29,
929,
14,
929,
12,
288,
365,
63,
3600,
628,
3600,
401,
288,
31193,
63,
354,
628,
929,
401,
288,
1676,
29,
277,
12,
288,
931,
63,
3676,
29,
277,
423,
515,
63,
3676,
12,
288,
1599,
2474,
29,
277,
423,
832,
2474,
12,
288,
2274,
63,
3771,
29,
549,
12,
288,
5478,
29,
403,
12,
288,
3231,
628,
1014,
921,
10010,
14,
846,
15,
11912,
15,
1200,
13,
842,
401,
288,
12669,
63,
578,
628,
10010,
13,
1200,
13,
842,
401,
288,
31193,
63,
466,
628,
3600,
401,
288,
365,
63,
888,
29,
797,
12,
267,
776,
398,
2248,
275,
2074,
14,
1935,
480,
912,
401,
488,
9,
267,
340,
1249,
26,
288,
340,
822,
8,
589,
9,
690,
413,
26,
355,
746,
3146,
480,
11250,
1218,
282,
29332,
3970,
543,
690,
17,
1423,
531,
288,
1006,
63,
962,
275,
715,
288,
367,
325,
315,
291,
423,
647,
621,
3409,
63,
5527,
26,
355,
340,
440,
2688,
8,
589,
59,
16,
467,
325,
304,
490,
1006,
63,
962,
275,
756,
490,
2059,
288,
340,
440,
1006,
63,
962,
26,
355,
746,
1722,
480,
17127,
1857,
909,
8103,
440,
1172,
314,
3211,
3004,
531,
288,
367,
325,
315,
291,
423,
647,
621,
3409,
63,
5527,
26,
355,
949,
468,
275,
2519,
8,
589,
59,
16,
467,
325,
9,
355,
340,
949,
468,
423,
2489,
342,
365,
756,
26,
490,
1980,
355,
663,
765,
275,
2519,
8,
277,
12,
2668,
409,
4970,
83,
2,
450,
325,
9,
355,
340,
2248,
365,
488,
26,
490,
663,
765,
8,
5675,
8,
589,
59,
16,
467,
325,
430,
355,
587,
26,
490,
663,
765,
8,
5675,
8,
589,
59,
16,
467,
325,
395,
2248,
29,
912,
9,
339,
347,
485,
515,
8,
277,
304,
267,
340,
2688,
8,
277,
12,
2668,
1708,
2349,
288,
372,
291,
423,
1708,
423,
515,
342,
435,
359,
277,
423,
11912,
63,
354,
61,
267,
587,
26,
288,
372,
359,
355,
298,
1200,
13,
5990,
401,
355,
298,
1200,
13,
842,
401,
355,
298,
16541,
401,
355,
298,
3922,
401,
355,
298,
9200,
401,
355,
298,
11402,
401,
355,
298,
1896,
401,
355,
298,
1073,
13,
929,
13,
4659,
401,
355,
298,
478,
80,
401,
355,
298,
5019,
3122,
401,
355,
298,
19020,
401,
355,
298,
2037,
13,
374,
78,
401,
355,
298,
11113,
401,
355,
298,
13881,
401,
355,
298,
954,
14846,
83,
401,
355,
298,
954,
14846,
83,
401,
355,
298,
18358,
13,
9882,
401,
288,
1622,
339,
347,
485,
362,
63,
929,
8,
277,
304,
267,
408,
272,
2372,
351,
1083,
367,
1174,
12,
9994,
687,
29332,
1750,
1182,
1200,
63,
5990,
15,
1200,
63,
842,
15,
16541,
15,
3922,
15,
9200,
15,
11402,
15,
1896,
15,
1073,
63,
929,
63,
4659,
15,
478,
80,
15,
5019,
3122,
15,
19020,
15,
2037,
63,
374,
78,
15,
11113,
15,
13881,
15,
954,
14846,
83,
15,
954,
14846,
83,
15,
18358,
63,
9882,
15,
929,
334,
3600,
9,
339,
29332,
11994,
26,
8511,
2633,
402,
2281,
13706,
799,
1225,
3616,
1007,
13,
14846,
6928,
14,
272,
408,
267,
372,
291,
855,
929,
339,
347,
485,
409,
63,
929,
8,
277,
12,
373,
12,
2248,
29,
797,
304,
267,
408,
272,
2494,
351,
1083,
367,
1174,
12,
9994,
687,
29332,
1750,
1182,
1200,
63,
5990,
15,
1200,
63,
842,
15,
16541,
15,
3922,
15,
9200,
15,
11402,
15,
1896,
15,
1073,
63,
929,
63,
4659,
15,
478,
80,
15,
5019,
3122,
15,
19020,
15,
2037,
63,
374,
78,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yvaucher/account-invoicing
|
__unported__/invoice_line_description/invoice.py
|
3
|
2572
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2014 Agile Business Group sagl
# (<http://www.agilebg.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
class account_invoice_line(orm.Model):
_inherit = "account.invoice.line"
def product_id_change(
self, cr, uid, ids, product_id, uom_id, qty=0,
name='', type='out_invoice', partner_id=False, fposition_id=False,
price_unit=False, currency_id=False, context=None, company_id=None
):
res = super(account_invoice_line, self).product_id_change(
cr, uid, ids, product_id, uom_id, qty=qty,
name=name, type=type, partner_id=partner_id,
fposition_id=fposition_id, price_unit=price_unit,
currency_id=currency_id, context=context, company_id=company_id
)
if product_id:
user = self.pool.get('res.users').browse(
cr, uid, uid, context=context)
user_groups = [g.id for g in user.groups_id]
ref = self.pool.get('ir.model.data').get_object_reference(
cr, uid, 'invoice_line_description',
'group_use_product_description_per_inv_line'
)
if ref and len(ref) > 1 and ref[1]:
group_id = ref[1]
if group_id in user_groups:
product_obj = self.pool.get('product.product')
product = product_obj.browse(
cr, uid, product_id, context=context)
if (
product
and product.description
and 'value' in res
):
res['value']['name'] = product.description
return res
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
6927,
21582,
441,
23813,
5611,
308,
643,
76,
199,
3,
259,
8642,
1014,
921,
1544,
14,
643,
441,
6856,
14,
957,
18956,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
259,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
9813,
421,
199,
533,
2933,
63,
5404,
63,
604,
8,
1025,
14,
1685,
304,
272,
485,
6486,
275,
298,
2048,
14,
5404,
14,
604,
2,
339,
347,
3336,
63,
344,
63,
1461,
8,
267,
291,
12,
2467,
12,
1747,
12,
2762,
12,
3336,
63,
344,
12,
19842,
63,
344,
12,
13556,
29,
16,
12,
267,
536,
4581,
730,
534,
548,
63,
5404,
297,
5854,
63,
344,
29,
797,
12,
289,
3124,
63,
344,
29,
797,
12,
267,
8033,
63,
3248,
29,
797,
12,
9952,
63,
344,
29,
797,
12,
1067,
29,
403,
12,
7233,
63,
344,
29,
403,
272,
3461,
267,
522,
275,
1613,
8,
2048,
63,
5404,
63,
604,
12,
291,
680,
2558,
63,
344,
63,
1461,
8,
288,
2467,
12,
1747,
12,
2762,
12,
3336,
63,
344,
12,
19842,
63,
344,
12,
13556,
29,
5643,
12,
288,
536,
29,
354,
12,
730,
29,
466,
12,
5854,
63,
344,
29,
3899,
63,
344,
12,
288,
289,
3124,
63,
344,
29,
70,
3124,
63,
344,
12,
8033,
63,
3248,
29,
4777,
63,
3248,
12,
288,
9952,
63,
344,
29,
4968,
63,
344,
12,
1067,
29,
1100,
12,
7233,
63,
344,
29,
4627,
63,
344,
267,
776,
267,
340,
3336,
63,
344,
26,
288,
922,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
355,
2467,
12,
1747,
12,
1747,
12,
1067,
29,
1100,
9,
288,
922,
63,
2634,
275,
359,
71,
14,
344,
367,
486,
315,
922,
14,
2634,
63,
344,
61,
288,
2984,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
355,
2467,
12,
1747,
12,
283,
5404,
63,
604,
63,
1802,
297,
355,
283,
923,
63,
1180,
63,
2558,
63,
1802,
63,
529,
63,
5350,
63,
604,
7,
288,
776,
288,
340,
2984,
436,
822,
8,
1121,
9,
690,
413,
436,
2984,
59,
17,
2189,
355,
1572,
63,
344,
275,
2984,
59,
17,
61,
355,
340,
1572,
63,
344,
315,
922,
63,
2634,
26,
490,
3336,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2558,
14,
2558,
358,
490,
3336,
275,
3336,
63,
1113,
14,
4570,
8,
717,
2467,
12,
1747,
12,
3336,
63,
344,
12,
1067,
29,
1100,
9,
490,
340,
334,
717,
3336,
717,
436,
3336,
14,
1802,
717,
436,
283,
585,
7,
315,
522,
490,
3461,
717,
522,
459,
585,
2545,
354,
418,
275,
3336,
14,
1802,
267,
372,
522,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1898,
334,
35,
9,
6927,
21582,
441,
23813,
5611,
308,
643,
76,
199,
3,
259,
8642,
1014,
921,
1544,
14,
643,
441,
6856,
14,
957,
18956,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
199,
3,
259,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
9813,
421,
199,
533,
2933,
63,
5404,
63,
604,
8,
1025,
14,
1685,
304,
272,
485,
6486,
275,
298,
2048,
14,
5404,
14,
604,
2,
339,
347,
3336,
63,
344,
63,
1461,
8,
267,
291,
12,
2467,
12,
1747,
12,
2762,
12,
3336,
63,
344,
12,
19842,
63,
344,
12,
13556,
29,
16,
12,
267,
536,
4581,
730,
534,
548,
63,
5404,
297,
5854,
63,
344,
29,
797,
12,
289,
3124,
63,
344,
29,
797,
12,
267,
8033,
63,
3248,
29,
797,
12,
9952,
63,
344,
29,
797,
12,
1067,
29,
403,
12,
7233,
63,
344,
29,
403,
272,
3461,
267,
522,
275,
1613,
8,
2048,
63,
5404,
63,
604,
12,
291,
680,
2558,
63,
344,
63,
1461,
8,
288,
2467,
12,
1747,
12,
2762,
12,
3336,
63,
344,
12,
19842,
63,
344,
12,
13556,
29,
5643,
12,
288,
536,
29,
354,
12,
730,
29,
466,
12,
5854,
63,
344,
29,
3899,
63,
344,
12,
288,
289,
3124,
63,
344,
29,
70,
3124,
63,
344,
12,
8033,
63,
3248,
29,
4777,
63,
3248,
12,
288,
9952,
63,
344,
29,
4968,
63,
344,
12,
1067,
29,
1100,
12,
7233,
63,
344,
29,
4627,
63,
344,
267,
776,
267,
340,
3336,
63,
344,
26,
288,
922,
275,
291,
14,
2293,
14,
362,
360,
470,
14,
3707,
1959,
4570,
8,
355,
2467,
12,
1747,
12,
1747,
12,
1067,
29,
1100,
9,
288,
922,
63,
2634,
275,
359,
71,
14,
344,
367,
486,
315,
922,
14,
2634,
63,
344,
61,
288,
2984,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1238,
14,
576,
1959,
362,
63,
785,
63,
4443,
8,
355,
2467,
12,
1747,
12,
283,
5404,
63,
604,
63,
1802,
297,
355,
283,
923,
63,
1180,
63,
2558,
63,
1802,
63,
529,
63,
5350,
63,
604,
7,
288,
776,
288,
340,
2984,
436,
822,
8,
1121,
9,
690,
413,
436,
2984,
59,
17,
2189,
355,
1572,
63,
344,
275,
2984,
59,
17,
61,
355,
340,
1572,
63,
344,
315,
922,
63,
2634,
26,
490,
3336,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2558,
14,
2558,
358,
490,
3336,
275,
3336,
63,
1113,
14,
4570,
8,
717,
2467,
12,
1747,
12,
3336,
63,
344,
12,
1067,
29,
1100,
9,
490,
340,
334,
717,
3336,
717,
436,
3336,
14,
1802,
717,
436,
283,
585,
7,
315,
522,
490,
3461,
717,
522,
459,
585,
2545,
354,
418,
275,
3336,
14,
1802,
267,
372,
522,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
hivelocity/python-namecheap
|
setup.py
|
3
|
2314
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2011, Martín Raúl Villalba
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
##############################################################################
import os
from setuptools import setup, find_packages
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name='namecheap',
version='develop',
url='http://www.github.com/mvillalba/python-namecheap/',
license='MIT',
description='Python wrapper for Namecheap\'s API.',
author=u'Mart\u00EDn Ra\u00FAl Villalba',
author_email='martin@martinvillalba.com',
long_description=read('README.md'),
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Internet",
],
packages=find_packages('src'),
package_dir={'': 'src'},
install_requires=['distribute'],
)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
12,
603,
580,
13676,
78,
3898,
24602,
76,
812,
778,
279,
2470,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
199,
3,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
199,
3,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
199,
3,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
4605,
199,
199,
646,
747,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
421,
199,
318,
1586,
8,
5252,
304,
272,
372,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
6748,
4992,
739,
342,
199,
199,
2758,
8,
272,
536,
534,
354,
595,
439,
297,
272,
1015,
534,
32176,
297,
272,
1166,
534,
1014,
921,
1544,
14,
5031,
14,
957,
15,
12393,
778,
279,
2470,
15,
1548,
13,
354,
595,
439,
3678,
272,
4190,
534,
13965,
297,
272,
1369,
534,
4718,
4975,
367,
2812,
595,
439,
3985,
83,
3261,
3130,
272,
4132,
29,
85,
7,
45,
580,
60,
85,
383,
1149,
78,
3898,
60,
85,
383,
2078,
76,
812,
778,
279,
2470,
297,
272,
4132,
63,
2123,
534,
77,
26788,
32,
77,
580,
5350,
778,
279,
2470,
14,
957,
297,
272,
1846,
63,
1802,
29,
739,
360,
18195,
14,
1064,
659,
272,
19137,
1524,
267,
298,
23753,
9795,
3800,
499,
446,
5543,
13,
16192,
401,
267,
298,
23910,
23975,
3800,
23493,
401,
267,
298,
3761,
3800,
25718,
26330,
3800,
10697,
844,
401,
267,
298,
23699,
6187,
3800,
4403,
1010,
7106,
401,
267,
298,
11411,
8466,
3800,
2018,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
22,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
401,
267,
298,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
401,
267,
298,
12157,
3800,
22026,
401,
267,
2156,
272,
6117,
29,
1623,
63,
5154,
360,
2164,
659,
272,
2559,
63,
694,
3713,
356,
283,
2164,
2267,
272,
3907,
63,
6537,
2968,
3470,
995,
199,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
12,
603,
580,
13676,
78,
3898,
24602,
76,
812,
778,
279,
2470,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
199,
3,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
199,
3,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
199,
3,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
3,
199,
4605,
199,
199,
646,
747,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
421,
199,
318,
1586,
8,
5252,
304,
272,
372,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
6748,
4992,
739,
342,
199,
199,
2758,
8,
272,
536,
534,
354,
595,
439,
297,
272,
1015,
534,
32176,
297,
272,
1166,
534,
1014,
921,
1544,
14,
5031,
14,
957,
15,
12393,
778,
279,
2470,
15,
1548,
13,
354,
595,
439,
3678,
272,
4190,
534,
13965,
297,
272,
1369,
534,
4718,
4975,
367,
2812,
595,
439,
3985,
83,
3261,
3130,
272,
4132,
29,
85,
7,
45,
580,
60,
85,
383,
1149,
78,
3898,
60,
85,
383,
2078,
76,
812,
778,
279,
2470,
297,
272,
4132,
63,
2123,
534,
77,
26788,
32,
77,
580,
5350,
778,
279,
2470,
14,
957,
297,
272,
1846,
63,
1802,
29,
739,
360,
18195,
14,
1064,
659,
272,
19137,
1524,
267,
298,
23753,
9795,
3800,
499,
446,
5543,
13,
16192,
401,
267,
298,
23910,
23975,
3800,
23493,
401,
267,
298,
3761,
3800,
25718,
26330,
3800,
10697,
844,
401,
267,
298,
23699,
6187,
3800,
4403,
1010,
7106,
401,
267,
298,
11411,
8466,
3800,
2018,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
22,
401,
267,
298,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
401,
267,
298,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
401,
267,
298,
12157,
3800,
22026,
401,
267,
2156,
272,
6117,
29,
1623,
63,
5154,
360,
2164,
659,
272,
2559,
63,
694,
3713,
356,
283,
2164,
2267,
272,
3907,
63,
6537,
2968,
3470,
995,
199,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sserrot/champion_relationships
|
venv/Lib/site-packages/ipykernel/inprocess/blocking.py
|
1
|
3068
|
""" Implements a fully blocking kernel client.
Useful for test suites and blocking terminal interfaces.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2012 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING.txt, distributed as part of this software.
#-----------------------------------------------------------------------------
import sys
try:
from queue import Queue, Empty # Py 3
except ImportError:
from Queue import Queue, Empty # Py 2
# IPython imports
from traitlets import Type
# Local imports
from .channels import (
InProcessChannel,
)
from .client import InProcessKernelClient
class BlockingInProcessChannel(InProcessChannel):
def __init__(self, *args, **kwds):
super(BlockingInProcessChannel, self).__init__(*args, **kwds)
self._in_queue = Queue()
def call_handlers(self, msg):
self._in_queue.put(msg)
def get_msg(self, block=True, timeout=None):
""" Gets a message if there is one that is ready. """
if timeout is None:
# Queue.get(timeout=None) has stupid uninteruptible
# behavior, so wait for a week instead
timeout = 604800
return self._in_queue.get(block, timeout)
def get_msgs(self):
""" Get all messages that are currently ready. """
msgs = []
while True:
try:
msgs.append(self.get_msg(block=False))
except Empty:
break
return msgs
def msg_ready(self):
""" Is there a message that has been received? """
return not self._in_queue.empty()
class BlockingInProcessStdInChannel(BlockingInProcessChannel):
def call_handlers(self, msg):
""" Overridden for the in-process channel.
This methods simply calls raw_input directly.
"""
msg_type = msg['header']['msg_type']
if msg_type == 'input_request':
_raw_input = self.client.kernel._sys_raw_input
prompt = msg['content']['prompt']
print(prompt, end='', file=sys.__stdout__)
sys.__stdout__.flush()
self.client.input(_raw_input())
class BlockingInProcessKernelClient(InProcessKernelClient):
# The classes to use for the various channels.
shell_channel_class = Type(BlockingInProcessChannel)
iopub_channel_class = Type(BlockingInProcessChannel)
stdin_channel_class = Type(BlockingInProcessStdInChannel)
def wait_for_ready(self):
# Wait for kernel info reply on shell channel
while True:
msg = self.shell_channel.get_msg(block=True)
if msg['msg_type'] == 'kernel_info_reply':
self._handle_kernel_info_reply(msg)
break
# Flush IOPub channel
while True:
try:
msg = self.iopub_channel.get_msg(block=True, timeout=0.2)
print(msg['msg_type'])
except Empty:
break
|
mit
|
[
624,
24664,
282,
9999,
14592,
5114,
1890,
14,
199,
199,
6119,
1893,
367,
511,
24203,
436,
14592,
11167,
8386,
14,
199,
624,
199,
18045,
199,
3,
221,
1898,
334,
35,
9,
6029,
221,
710,
16243,
15290,
11682,
199,
3,
199,
3,
221,
17484,
1334,
314,
2895,
402,
314,
6289,
844,
14,
221,
710,
2615,
4190,
365,
315,
199,
3,
221,
314,
570,
9685,
14,
2424,
12,
1854,
465,
1777,
402,
642,
2032,
14,
199,
18045,
199,
646,
984,
199,
893,
26,
272,
687,
4126,
492,
10703,
12,
9630,
221,
327,
1611,
650,
199,
2590,
3545,
26,
272,
687,
10703,
492,
10703,
12,
9630,
221,
327,
1611,
499,
199,
199,
3,
16243,
8925,
199,
504,
1468,
5776,
1086,
492,
2434,
199,
199,
3,
10111,
8925,
199,
504,
1275,
6324,
492,
334,
272,
1010,
3498,
5358,
12,
199,
9,
199,
504,
1275,
1258,
492,
1010,
3498,
14127,
3041,
199,
199,
533,
8651,
316,
607,
3498,
5358,
8,
607,
3498,
5358,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
1613,
8,
27132,
607,
3498,
5358,
12,
291,
2843,
826,
9308,
589,
12,
1011,
10340,
9,
267,
291,
423,
262,
63,
1825,
275,
10703,
342,
339,
347,
1240,
63,
5586,
8,
277,
12,
1499,
304,
267,
291,
423,
262,
63,
1825,
14,
524,
8,
1328,
9,
339,
347,
664,
63,
1328,
8,
277,
12,
1853,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
14509,
282,
1245,
340,
2337,
365,
1373,
626,
365,
10144,
14,
408,
267,
340,
2653,
365,
488,
26,
288,
327,
10703,
14,
362,
8,
2593,
29,
403,
9,
965,
410,
31596,
625,
1058,
384,
21602,
288,
327,
5953,
12,
880,
3618,
367,
282,
8620,
3140,
288,
2653,
275,
1227,
966,
6718,
267,
372,
291,
423,
262,
63,
1825,
14,
362,
8,
1457,
12,
2653,
9,
339,
347,
664,
63,
13429,
8,
277,
304,
267,
408,
2372,
1006,
3788,
626,
787,
5544,
10144,
14,
408,
267,
17599,
275,
942,
267,
1830,
715,
26,
288,
862,
26,
355,
17599,
14,
740,
8,
277,
14,
362,
63,
1328,
8,
1457,
29,
797,
430,
288,
871,
9630,
26,
355,
2059,
267,
372,
17599,
339,
347,
1499,
63,
2179,
8,
277,
304,
267,
408,
6596,
2337,
282,
1245,
626,
965,
2757,
3086,
31,
408,
267,
372,
440,
291,
423,
262,
63,
1825,
14,
1667,
342,
421,
199,
533,
8651,
316,
607,
3498,
11976,
607,
5358,
8,
27132,
607,
3498,
5358,
304,
272,
347,
1240,
63,
5586,
8,
277,
12,
1499,
304,
267,
408,
7259,
8639,
367,
314,
315,
13,
1412,
3623,
14,
398,
961,
3102,
9329,
4882,
3066,
63,
1210,
5370,
14,
267,
408,
267,
1499,
63,
466,
275,
1499,
459,
1291,
2545,
1328,
63,
466,
418,
267,
340,
1499,
63,
466,
508,
283,
1210,
63,
1069,
356,
288,
485,
1773,
63,
1210,
275,
291,
14,
1258,
14,
4989,
423,
1274,
63,
1773,
63,
1210,
288,
8457,
275,
1499,
459,
1317,
2545,
7650,
418,
288,
870,
8,
7650,
12,
1284,
4581,
570,
29,
1274,
855,
2703,
3368,
288,
984,
855,
2703,
4343,
4939,
342,
288,
291,
14,
1258,
14,
1210,
1547,
1773,
63,
1210,
1012,
199,
199,
533,
8651,
316,
607,
3498,
14127,
3041,
8,
607,
3498,
14127,
3041,
304,
339,
327,
710,
3992,
370,
675,
367,
314,
7750,
9245,
14,
272,
5218,
63,
2775,
63,
533,
275,
2434,
8,
27132,
607,
3498,
5358,
9,
272,
284,
411,
456,
63,
2775,
63,
533,
275,
2434,
8,
27132,
607,
3498,
5358,
9,
272,
9009,
63,
2775,
63,
533,
275,
2434,
8,
27132,
607,
3498,
11976,
607,
5358,
9,
339,
347,
3618,
63,
509,
63,
2179,
8,
277,
304,
267,
327,
13144,
367,
5114,
2256,
9351,
641,
5218,
3623,
267,
1830,
715,
26,
288,
1499,
275,
291,
14,
5641,
63,
2775,
14,
362,
63,
1328,
8,
1457,
29,
549,
9,
288,
340,
1499,
459,
1328,
63,
466,
418,
508,
283,
4989,
63,
815,
63,
8102,
356,
355,
291,
423,
2479,
63,
4989,
63,
815,
63,
8102,
8,
1328,
9,
355,
2059,
398,
327,
11040,
2084,
473,
1938,
456,
3623,
267,
1830,
715,
26,
288,
862,
26,
355,
1499,
275,
291,
14,
73,
411,
456,
63,
2775,
14,
362,
63,
1328,
8,
1457,
29,
549,
12,
2653,
29,
16,
14,
18,
9,
355,
870,
8,
1328,
459,
1328,
63,
466,
1105,
288,
871,
9630,
26,
355,
2059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
24664,
282,
9999,
14592,
5114,
1890,
14,
199,
199,
6119,
1893,
367,
511,
24203,
436,
14592,
11167,
8386,
14,
199,
624,
199,
18045,
199,
3,
221,
1898,
334,
35,
9,
6029,
221,
710,
16243,
15290,
11682,
199,
3,
199,
3,
221,
17484,
1334,
314,
2895,
402,
314,
6289,
844,
14,
221,
710,
2615,
4190,
365,
315,
199,
3,
221,
314,
570,
9685,
14,
2424,
12,
1854,
465,
1777,
402,
642,
2032,
14,
199,
18045,
199,
646,
984,
199,
893,
26,
272,
687,
4126,
492,
10703,
12,
9630,
221,
327,
1611,
650,
199,
2590,
3545,
26,
272,
687,
10703,
492,
10703,
12,
9630,
221,
327,
1611,
499,
199,
199,
3,
16243,
8925,
199,
504,
1468,
5776,
1086,
492,
2434,
199,
199,
3,
10111,
8925,
199,
504,
1275,
6324,
492,
334,
272,
1010,
3498,
5358,
12,
199,
9,
199,
504,
1275,
1258,
492,
1010,
3498,
14127,
3041,
199,
199,
533,
8651,
316,
607,
3498,
5358,
8,
607,
3498,
5358,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
1613,
8,
27132,
607,
3498,
5358,
12,
291,
2843,
826,
9308,
589,
12,
1011,
10340,
9,
267,
291,
423,
262,
63,
1825,
275,
10703,
342,
339,
347,
1240,
63,
5586,
8,
277,
12,
1499,
304,
267,
291,
423,
262,
63,
1825,
14,
524,
8,
1328,
9,
339,
347,
664,
63,
1328,
8,
277,
12,
1853,
29,
549,
12,
2653,
29,
403,
304,
267,
408,
14509,
282,
1245,
340,
2337,
365,
1373,
626,
365,
10144,
14,
408,
267,
340,
2653,
365,
488,
26,
288,
327,
10703,
14,
362,
8,
2593,
29,
403,
9,
965,
410,
31596,
625,
1058,
384,
21602,
288,
327,
5953,
12,
880,
3618,
367,
282,
8620,
3140,
288,
2653,
275,
1227,
966,
6718,
267,
372,
291,
423,
262,
63,
1825,
14,
362,
8,
1457,
12,
2653,
9,
339,
347,
664,
63,
13429,
8,
277,
304,
267,
408,
2372,
1006,
3788,
626,
787,
5544,
10144,
14,
408,
267,
17599,
275,
942,
267,
1830,
715,
26,
288,
862,
26,
355,
17599,
14,
740,
8,
277,
14,
362,
63,
1328,
8,
1457,
29,
797,
430,
288,
871,
9630,
26,
355,
2059,
267,
372,
17599,
339,
347,
1499,
63,
2179,
8,
277,
304,
267,
408,
6596,
2337,
282,
1245,
626,
965,
2757,
3086,
31,
408,
267,
372,
440,
291,
423,
262,
63,
1825,
14,
1667,
342,
421,
199,
533,
8651,
316,
607,
3498,
11976,
607,
5358,
8,
27132,
607,
3498,
5358,
304,
272,
347,
1240,
63,
5586,
8,
277,
12,
1499,
304,
267,
408,
7259,
8639,
367,
314,
315,
13,
1412,
3623,
14,
398,
961,
3102,
9329,
4882,
3066,
63,
1210,
5370,
14,
267,
408,
267,
1499,
63,
466,
275,
1499,
459,
1291,
2545,
1328,
63,
466,
418,
267,
340,
1499,
63,
466,
508,
283,
1210,
63,
1069,
356,
288,
485,
1773,
63,
1210,
275,
291,
14,
1258,
14,
4989,
423,
1274,
63,
1773,
63,
1210,
288,
8457,
275,
1499,
459,
1317,
2545,
7650,
418,
288,
870,
8,
7650,
12,
1284,
4581,
570,
29,
1274,
855,
2703,
3368,
288,
984,
855,
2703,
4343,
4939,
342,
288,
291,
14,
1258,
14,
1210,
1547,
1773,
63,
1210,
1012,
199,
199,
533,
8651,
316,
607,
3498,
14127,
3041,
8,
607,
3498,
14127,
3041,
304,
339,
327,
710,
3992,
370,
675,
367,
314,
7750,
9245,
14,
272,
5218,
63,
2775,
63,
533,
275,
2434,
8,
27132,
607,
3498,
5358,
9,
272,
284,
411,
456,
63,
2775,
63,
533,
275,
2434,
8,
27132,
607,
3498,
5358,
9,
272,
9009,
63,
2775,
63,
533,
275,
2434,
8,
27132,
607,
3498,
11976,
607,
5358,
9,
339,
347,
3618,
63,
509,
63,
2179,
8,
277,
304,
267,
327,
13144,
367,
5114,
2256,
9351,
641,
5218,
3623,
267,
1830,
715,
26,
288,
1499,
275,
291,
14,
5641,
63,
2775,
14,
362,
63,
1328,
8,
1457,
29,
549,
9,
288,
340,
1499,
459,
1328,
63,
466,
418,
508,
283,
4989,
63,
815,
63,
8102,
356,
355,
291,
423,
2479,
63,
4989,
63,
815,
63,
8102,
8,
1328,
9,
355,
2059,
398,
327,
11040,
2084,
473,
1938,
456,
3623,
267,
1830,
715,
26,
288,
862,
26,
355,
1499,
275,
291,
14,
73,
411,
456,
63,
2775,
14,
362,
63,
1328,
8,
1457,
29,
549,
12,
2653,
29,
16,
14,
18,
9,
355,
870,
8,
1328,
459,
1328,
63,
466,
1105,
288,
871,
9630,
26,
355,
2059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jamespcole/home-assistant
|
homeassistant/components/owlet/binary_sensor.py
|
8
|
2346
|
"""Support for Owlet binary sensors."""
from datetime import timedelta
from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.util import dt as dt_util
from . import DOMAIN as OWLET_DOMAIN
from .const import SENSOR_BASE_STATION, SENSOR_MOVEMENT
SCAN_INTERVAL = timedelta(seconds=120)
BINARY_CONDITIONS = {
SENSOR_BASE_STATION: {
'name': 'Base Station',
'device_class': 'power'
},
SENSOR_MOVEMENT: {
'name': 'Movement',
'device_class': 'motion'
}
}
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up owlet binary sensor."""
if discovery_info is None:
return
device = hass.data[OWLET_DOMAIN]
entities = []
for condition in BINARY_CONDITIONS:
if condition in device.monitor:
entities.append(OwletBinarySensor(device, condition))
add_entities(entities, True)
class OwletBinarySensor(BinarySensorDevice):
"""Representation of owlet binary sensor."""
def __init__(self, device, condition):
"""Init owlet binary sensor."""
self._device = device
self._condition = condition
self._state = None
self._base_on = False
self._prop_expiration = None
self._is_charging = None
@property
def name(self):
"""Return sensor name."""
return '{} {}'.format(self._device.name,
BINARY_CONDITIONS[self._condition]['name'])
@property
def is_on(self):
"""Return current state of sensor."""
return self._state
@property
def device_class(self):
"""Return the device class."""
return BINARY_CONDITIONS[self._condition]['device_class']
def update(self):
"""Update state of sensor."""
self._base_on = self._device.device.base_station_on
self._prop_expiration = self._device.device.prop_expire_time
self._is_charging = self._device.device.charge_status > 0
# handle expired values
if self._prop_expiration < dt_util.now().timestamp():
self._state = False
return
if self._condition == 'movement':
if not self._base_on or self._is_charging:
return False
self._state = getattr(self._device.device, self._condition)
|
apache-2.0
|
[
624,
11532,
367,
593,
87,
2723,
3366,
19678,
1041,
199,
504,
2197,
492,
6871,
199,
199,
504,
8846,
14,
4608,
14,
3008,
63,
8956,
492,
14161,
10160,
2510,
199,
504,
8846,
14,
1974,
492,
4487,
465,
4487,
63,
1974,
199,
199,
504,
1275,
492,
15265,
465,
593,
55,
44,
775,
63,
7378,
199,
504,
1275,
1297,
492,
428,
17850,
63,
5825,
63,
840,
2594,
12,
428,
17850,
63,
16207,
4479,
199,
199,
24078,
63,
17359,
275,
6871,
8,
4515,
29,
6708,
9,
199,
199,
13246,
63,
1864,
4150,
275,
469,
272,
428,
17850,
63,
5825,
63,
840,
2594,
26,
469,
267,
283,
354,
356,
283,
1563,
1933,
425,
297,
267,
283,
1782,
63,
533,
356,
283,
5652,
7,
272,
1660,
272,
428,
17850,
63,
16207,
4479,
26,
469,
267,
283,
354,
356,
283,
10370,
434,
297,
267,
283,
1782,
63,
533,
356,
283,
15335,
7,
272,
789,
199,
93,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
22182,
2723,
3366,
8778,
1041,
272,
340,
13172,
63,
815,
365,
488,
26,
267,
372,
339,
2243,
275,
6298,
14,
576,
59,
19716,
44,
775,
63,
7378,
61,
339,
9045,
275,
942,
272,
367,
5558,
315,
32698,
63,
1864,
4150,
26,
267,
340,
5558,
315,
2243,
14,
7157,
26,
288,
9045,
14,
740,
8,
18202,
2723,
6636,
10160,
8,
1782,
12,
5558,
430,
339,
1050,
63,
8327,
8,
8327,
12,
715,
9,
421,
199,
533,
593,
87,
2723,
6636,
10160,
8,
6636,
10160,
2510,
304,
272,
408,
20609,
402,
22182,
2723,
3366,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
2243,
12,
5558,
304,
267,
408,
9346,
22182,
2723,
3366,
8778,
1041,
267,
291,
423,
1782,
275,
2243,
267,
291,
423,
5394,
275,
5558,
267,
291,
423,
929,
275,
488,
267,
291,
423,
1095,
63,
265,
275,
756,
267,
291,
423,
4469,
63,
15469,
275,
488,
267,
291,
423,
374,
63,
335,
1273,
316,
275,
488,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
8778,
536,
1041,
267,
372,
9005,
9499,
908,
8,
277,
423,
1782,
14,
354,
12,
2892,
32698,
63,
1864,
4150,
59,
277,
423,
5394,
2733,
354,
1105,
339,
768,
1829,
272,
347,
365,
63,
265,
8,
277,
304,
267,
408,
1767,
1453,
1174,
402,
8778,
1041,
267,
372,
291,
423,
929,
339,
768,
1829,
272,
347,
2243,
63,
533,
8,
277,
304,
267,
408,
1767,
314,
2243,
1021,
1041,
267,
372,
32698,
63,
1864,
4150,
59,
277,
423,
5394,
2733,
1782,
63,
533,
418,
339,
347,
1678,
8,
277,
304,
267,
408,
4152,
1174,
402,
8778,
1041,
267,
291,
423,
1095,
63,
265,
275,
291,
423,
1782,
14,
1782,
14,
1095,
63,
10600,
63,
265,
267,
291,
423,
4469,
63,
15469,
275,
291,
423,
1782,
14,
1782,
14,
4469,
63,
14691,
63,
521,
267,
291,
423,
374,
63,
335,
1273,
316,
275,
291,
423,
1782,
14,
1782,
14,
16441,
63,
1205,
690,
378,
398,
327,
2429,
14721,
1338,
267,
340,
291,
423,
4469,
63,
15469,
665,
4487,
63,
1974,
14,
2131,
1252,
3954,
837,
288,
291,
423,
929,
275,
756,
288,
372,
398,
340,
291,
423,
5394,
508,
283,
1185,
434,
356,
288,
340,
440,
291,
423,
1095,
63,
265,
503,
291,
423,
374,
63,
335,
1273,
316,
26,
355,
372,
756,
398,
291,
423,
929,
275,
2519,
8,
277,
423,
1782,
14,
1782,
12,
291,
423,
5394,
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
] |
[
11532,
367,
593,
87,
2723,
3366,
19678,
1041,
199,
504,
2197,
492,
6871,
199,
199,
504,
8846,
14,
4608,
14,
3008,
63,
8956,
492,
14161,
10160,
2510,
199,
504,
8846,
14,
1974,
492,
4487,
465,
4487,
63,
1974,
199,
199,
504,
1275,
492,
15265,
465,
593,
55,
44,
775,
63,
7378,
199,
504,
1275,
1297,
492,
428,
17850,
63,
5825,
63,
840,
2594,
12,
428,
17850,
63,
16207,
4479,
199,
199,
24078,
63,
17359,
275,
6871,
8,
4515,
29,
6708,
9,
199,
199,
13246,
63,
1864,
4150,
275,
469,
272,
428,
17850,
63,
5825,
63,
840,
2594,
26,
469,
267,
283,
354,
356,
283,
1563,
1933,
425,
297,
267,
283,
1782,
63,
533,
356,
283,
5652,
7,
272,
1660,
272,
428,
17850,
63,
16207,
4479,
26,
469,
267,
283,
354,
356,
283,
10370,
434,
297,
267,
283,
1782,
63,
533,
356,
283,
15335,
7,
272,
789,
199,
93,
421,
199,
318,
3272,
63,
3246,
8,
5387,
12,
1101,
12,
1050,
63,
8327,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1084,
1536,
22182,
2723,
3366,
8778,
1041,
272,
340,
13172,
63,
815,
365,
488,
26,
267,
372,
339,
2243,
275,
6298,
14,
576,
59,
19716,
44,
775,
63,
7378,
61,
339,
9045,
275,
942,
272,
367,
5558,
315,
32698,
63,
1864,
4150,
26,
267,
340,
5558,
315,
2243,
14,
7157,
26,
288,
9045,
14,
740,
8,
18202,
2723,
6636,
10160,
8,
1782,
12,
5558,
430,
339,
1050,
63,
8327,
8,
8327,
12,
715,
9,
421,
199,
533,
593,
87,
2723,
6636,
10160,
8,
6636,
10160,
2510,
304,
272,
408,
20609,
402,
22182,
2723,
3366,
8778,
1041,
339,
347,
636,
826,
721,
277,
12,
2243,
12,
5558,
304,
267,
408,
9346,
22182,
2723,
3366,
8778,
1041,
267,
291,
423,
1782,
275,
2243,
267,
291,
423,
5394,
275,
5558,
267,
291,
423,
929,
275,
488,
267,
291,
423,
1095,
63,
265,
275,
756,
267,
291,
423,
4469,
63,
15469,
275,
488,
267,
291,
423,
374,
63,
335,
1273,
316,
275,
488,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
8778,
536,
1041,
267,
372,
9005,
9499,
908,
8,
277,
423,
1782,
14,
354,
12,
2892,
32698,
63,
1864,
4150,
59,
277,
423,
5394,
2733,
354,
1105,
339,
768,
1829,
272,
347,
365,
63,
265,
8,
277,
304,
267,
408,
1767,
1453,
1174,
402,
8778,
1041,
267,
372,
291,
423,
929,
339,
768,
1829,
272,
347,
2243,
63,
533,
8,
277,
304,
267,
408,
1767,
314,
2243,
1021,
1041,
267,
372,
32698,
63,
1864,
4150,
59,
277,
423,
5394,
2733,
1782,
63,
533,
418,
339,
347,
1678,
8,
277,
304,
267,
408,
4152,
1174,
402,
8778,
1041,
267,
291,
423,
1095,
63,
265,
275,
291,
423,
1782,
14,
1782,
14,
1095,
63,
10600,
63,
265,
267,
291,
423,
4469,
63,
15469,
275,
291,
423,
1782,
14,
1782,
14,
4469,
63,
14691,
63,
521,
267,
291,
423,
374,
63,
335,
1273,
316,
275,
291,
423,
1782,
14,
1782,
14,
16441,
63,
1205,
690,
378,
398,
327,
2429,
14721,
1338,
267,
340,
291,
423,
4469,
63,
15469,
665,
4487,
63,
1974,
14,
2131,
1252,
3954,
837,
288,
291,
423,
929,
275,
756,
288,
372,
398,
340,
291,
423,
5394,
508,
283,
1185,
434,
356,
288,
340,
440,
291,
423,
1095,
63,
265,
503,
291,
423,
374,
63,
335,
1273,
316,
26,
355,
372,
756,
398,
291,
423,
929,
275,
2519,
8,
277,
423,
1782,
14,
1782,
12,
291,
423,
5394,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
s20121035/rk3288_android5.1_repo
|
external/chromium_org/build/gn_helpers.py
|
117
|
1344
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Helper functions useful when writing scripts that are run from GN's
exec_script function."""
class GNException(Exception):
pass
def ToGNString(value, allow_dicts = True):
"""Prints the given value to stdout.
allow_dicts indicates if this function will allow converting dictionaries
to GN scopes. This is only possible at the top level, you can't nest a
GN scope in a list, so this should be set to False for recursive calls."""
if isinstance(value, str):
if value.find('\n') >= 0:
raise GNException("Trying to print a string with a newline in it.")
return '"' + value.replace('"', '\\"') + '"'
if isinstance(value, list):
return '[ %s ]' % ', '.join(ToGNString(v) for v in value)
if isinstance(value, dict):
if not allow_dicts:
raise GNException("Attempting to recursively print a dictionary.")
result = ""
for key in value:
if not isinstance(key, str):
raise GNException("Dictionary key is not a string.")
result += "%s = %s\n" % (key, ToGNString(value[key], False))
return result
if isinstance(value, int):
return str(value)
raise GNException("Unsupported type when printing to GN.")
|
gpl-3.0
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
4433,
3423,
2997,
1380,
3575,
10554,
626,
787,
1255,
687,
27650,
1159,
199,
1628,
63,
1579,
805,
1041,
199,
199,
533,
27650,
1726,
8,
1726,
304,
523,
986,
421,
199,
318,
4005,
15306,
1558,
8,
585,
12,
2040,
63,
7892,
275,
715,
304,
523,
408,
26113,
314,
1627,
574,
370,
3839,
14,
819,
2040,
63,
7892,
9126,
340,
642,
805,
911,
2040,
13806,
11196,
523,
370,
27650,
14570,
14,
961,
365,
1454,
3962,
737,
314,
2746,
2166,
12,
1265,
883,
1133,
10715,
282,
523,
27650,
4194,
315,
282,
769,
12,
880,
642,
1077,
506,
663,
370,
756,
367,
9133,
4882,
1041,
523,
340,
1228,
8,
585,
12,
620,
304,
272,
340,
574,
14,
1623,
2258,
78,
358,
2356,
378,
26,
489,
746,
27650,
1726,
480,
27693,
370,
870,
282,
1059,
543,
282,
8057,
315,
652,
2685,
272,
372,
14788,
435,
574,
14,
1814,
20630,
6468,
9008,
435,
14788,
819,
340,
1228,
8,
585,
12,
769,
304,
272,
372,
6730,
450,
83,
1622,
7,
450,
1656,
1987,
904,
8,
1378,
15306,
1558,
8,
86,
9,
367,
373,
315,
574,
9,
819,
340,
1228,
8,
585,
12,
1211,
304,
272,
340,
440,
2040,
63,
7892,
26,
489,
746,
27650,
1726,
480,
15322,
1337,
370,
15035,
870,
282,
2600,
2685,
272,
754,
275,
3087,
272,
367,
790,
315,
574,
26,
489,
340,
440,
1228,
8,
498,
12,
620,
304,
267,
746,
27650,
1726,
480,
11728,
790,
365,
440,
282,
1059,
2685,
489,
754,
847,
2071,
83,
275,
450,
83,
60,
78,
2,
450,
334,
498,
12,
4005,
15306,
1558,
8,
585,
59,
498,
467,
756,
430,
272,
372,
754,
819,
340,
1228,
8,
585,
12,
1109,
304,
272,
372,
620,
8,
585,
9,
819,
746,
27650,
1726,
480,
12647,
730,
1380,
16116,
370,
27650,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
4433,
3423,
2997,
1380,
3575,
10554,
626,
787,
1255,
687,
27650,
1159,
199,
1628,
63,
1579,
805,
1041,
199,
199,
533,
27650,
1726,
8,
1726,
304,
523,
986,
421,
199,
318,
4005,
15306,
1558,
8,
585,
12,
2040,
63,
7892,
275,
715,
304,
523,
408,
26113,
314,
1627,
574,
370,
3839,
14,
819,
2040,
63,
7892,
9126,
340,
642,
805,
911,
2040,
13806,
11196,
523,
370,
27650,
14570,
14,
961,
365,
1454,
3962,
737,
314,
2746,
2166,
12,
1265,
883,
1133,
10715,
282,
523,
27650,
4194,
315,
282,
769,
12,
880,
642,
1077,
506,
663,
370,
756,
367,
9133,
4882,
1041,
523,
340,
1228,
8,
585,
12,
620,
304,
272,
340,
574,
14,
1623,
2258,
78,
358,
2356,
378,
26,
489,
746,
27650,
1726,
480,
27693,
370,
870,
282,
1059,
543,
282,
8057,
315,
652,
2685,
272,
372,
14788,
435,
574,
14,
1814,
20630,
6468,
9008,
435,
14788,
819,
340,
1228,
8,
585,
12,
769,
304,
272,
372,
6730,
450,
83,
1622,
7,
450,
1656,
1987,
904,
8,
1378,
15306,
1558,
8,
86,
9,
367,
373,
315,
574,
9,
819,
340,
1228,
8,
585,
12,
1211,
304,
272,
340,
440,
2040,
63,
7892,
26,
489,
746,
27650,
1726,
480,
15322,
1337,
370,
15035,
870,
282,
2600,
2685,
272,
754,
275,
3087,
272,
367,
790,
315,
574,
26,
489,
340,
440,
1228,
8,
498,
12,
620,
304,
267,
746,
27650,
1726,
480,
11728,
790,
365,
440,
282,
1059,
2685,
489,
754,
847,
2071,
83,
275,
450,
83,
60,
78,
2,
450,
334,
498,
12,
4005,
15306,
1558,
8,
585,
59,
498,
467,
756,
430,
272,
372,
754,
819,
340,
1228,
8,
585,
12,
1109,
304,
272,
372,
620,
8,
585,
9,
819,
746,
27650,
1726,
480,
12647,
730,
1380,
16116,
370,
27650,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
ProfessorX/Config
|
.PyCharm30/system/python_stubs/-1247972723/PyQt4/QtGui/QFontMetricsF.py
|
2
|
5505
|
# encoding: utf-8
# module PyQt4.QtGui
# from /usr/lib/python2.7/dist-packages/PyQt4/QtGui.so
# by generator 1.135
# no doc
# imports
import PyQt4.QtCore as __PyQt4_QtCore
class QFontMetricsF(): # skipped bases: <type 'sip.simplewrapper'>
"""
QFontMetricsF(QFont)
QFontMetricsF(QFont, QPaintDevice)
QFontMetricsF(QFontMetrics)
QFontMetricsF(QFontMetricsF)
"""
def ascent(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.ascent() -> float """
return 0.0
def averageCharWidth(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.averageCharWidth() -> float """
return 0.0
def boundingRect(self, *__args): # real signature unknown; restored from __doc__ with multiple overloads
"""
QFontMetricsF.boundingRect(QChar) -> QRectF
QFontMetricsF.boundingRect(QString) -> QRectF
QFontMetricsF.boundingRect(QRectF, int, QString, int tabStops=0, list-of-int tabArray=0) -> QRectF
"""
pass
def boundingRectChar(self, *args, **kwargs): # real signature unknown
pass
def descent(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.descent() -> float """
return 0.0
def elidedText(self, QString, Qt_TextElideMode, p_float, int_flags=0): # real signature unknown; restored from __doc__
""" QFontMetricsF.elidedText(QString, Qt.TextElideMode, float, int flags=0) -> QString """
pass
def height(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.height() -> float """
return 0.0
def inFont(self, QChar): # real signature unknown; restored from __doc__
""" QFontMetricsF.inFont(QChar) -> bool """
return False
def inFontUcs4(self, p_int): # real signature unknown; restored from __doc__
""" QFontMetricsF.inFontUcs4(int) -> bool """
return False
def leading(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.leading() -> float """
return 0.0
def leftBearing(self, QChar): # real signature unknown; restored from __doc__
""" QFontMetricsF.leftBearing(QChar) -> float """
return 0.0
def lineSpacing(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.lineSpacing() -> float """
return 0.0
def lineWidth(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.lineWidth() -> float """
return 0.0
def maxWidth(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.maxWidth() -> float """
return 0.0
def minLeftBearing(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.minLeftBearing() -> float """
return 0.0
def minRightBearing(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.minRightBearing() -> float """
return 0.0
def overlinePos(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.overlinePos() -> float """
return 0.0
def rightBearing(self, QChar): # real signature unknown; restored from __doc__
""" QFontMetricsF.rightBearing(QChar) -> float """
return 0.0
def size(self, p_int, QString, int_tabStops=0, list_of_int_tabArray=0): # real signature unknown; restored from __doc__
""" QFontMetricsF.size(int, QString, int tabStops=0, list-of-int tabArray=0) -> QSizeF """
pass
def strikeOutPos(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.strikeOutPos() -> float """
return 0.0
def tightBoundingRect(self, QString): # real signature unknown; restored from __doc__
""" QFontMetricsF.tightBoundingRect(QString) -> QRectF """
pass
def underlinePos(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.underlinePos() -> float """
return 0.0
def width(self, *__args): # real signature unknown; restored from __doc__ with multiple overloads
"""
QFontMetricsF.width(QChar) -> float
QFontMetricsF.width(QString) -> float
"""
return 0.0
def widthChar(self, *args, **kwargs): # real signature unknown
pass
def xHeight(self): # real signature unknown; restored from __doc__
""" QFontMetricsF.xHeight() -> float """
return 0.0
def __eq__(self, y): # real signature unknown; restored from __doc__
""" x.__eq__(y) <==> x==y """
pass
def __ge__(self, y): # real signature unknown; restored from __doc__
""" x.__ge__(y) <==> x>=y """
pass
def __gt__(self, y): # real signature unknown; restored from __doc__
""" x.__gt__(y) <==> x>y """
pass
def __init__(self, *__args): # real signature unknown; restored from __doc__ with multiple overloads
pass
def __le__(self, y): # real signature unknown; restored from __doc__
""" x.__le__(y) <==> x<=y """
pass
def __lt__(self, y): # real signature unknown; restored from __doc__
""" x.__lt__(y) <==> x<y """
pass
def __ne__(self, y): # real signature unknown; restored from __doc__
""" x.__ne__(y) <==> x!=y """
pass
__weakref__ = property(lambda self: object(), lambda self, v: None, lambda self: None) # default
"""list of weak references to the object (if defined)"""
|
gpl-2.0
|
[
3,
2644,
26,
2774,
13,
24,
199,
3,
859,
14084,
20,
14,
10604,
199,
3,
687,
1182,
2647,
15,
773,
15,
1548,
18,
14,
23,
15,
2686,
13,
5154,
15,
24107,
20,
15,
10604,
14,
1152,
199,
3,
701,
4306,
413,
14,
8312,
199,
3,
949,
1382,
199,
199,
3,
8925,
199,
646,
14084,
20,
14,
10901,
465,
636,
24107,
20,
63,
10901,
421,
199,
533,
1413,
6986,
17213,
38,
837,
327,
9645,
9768,
26,
665,
466,
283,
17839,
14,
4129,
5029,
8423,
272,
408,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
9,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
12,
1413,
30833,
2510,
9,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
17213,
9,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
17213,
38,
9,
272,
408,
272,
347,
465,
2946,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
305,
2946,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
8095,
1610,
6216,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
8536,
1610,
6216,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
16842,
8252,
8,
277,
12,
29254,
589,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
543,
3663,
1806,
3640,
267,
408,
267,
1413,
6986,
17213,
38,
14,
24511,
8252,
8,
49,
1610,
9,
1035,
1413,
8252,
38,
267,
1413,
6986,
17213,
38,
14,
24511,
8252,
8,
49,
1558,
9,
1035,
1413,
8252,
38,
267,
1413,
6986,
17213,
38,
14,
24511,
8252,
8,
30197,
38,
12,
1109,
12,
1413,
1558,
12,
1109,
5174,
933,
1483,
29,
16,
12,
769,
13,
1618,
13,
442,
5174,
3836,
29,
16,
9,
1035,
1413,
8252,
38,
267,
408,
267,
986,
339,
347,
16842,
8252,
1610,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
327,
3363,
4955,
5809,
267,
986,
339,
347,
31518,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
26269,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
28214,
770,
1872,
8,
277,
12,
1413,
1558,
12,
3959,
63,
1872,
37,
8409,
1385,
12,
299,
63,
1609,
12,
1109,
63,
2469,
29,
16,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
18865,
770,
1872,
8,
49,
1558,
12,
3959,
14,
1872,
37,
8409,
1385,
12,
2069,
12,
1109,
3285,
29,
16,
9,
1035,
1413,
1558,
408,
267,
986,
339,
347,
4569,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
3333,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
315,
6986,
8,
277,
12,
1413,
1610,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
262,
6986,
8,
49,
1610,
9,
1035,
2155,
408,
267,
372,
756,
339,
347,
315,
6986,
53,
1259,
20,
8,
277,
12,
299,
63,
442,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
262,
6986,
53,
1259,
20,
8,
442,
9,
1035,
2155,
408,
267,
372,
756,
339,
347,
9186,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
16812,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
3602,
30860,
316,
8,
277,
12,
1413,
1610,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
3039,
30860,
316,
8,
49,
1610,
9,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1004,
24052,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
604,
24052,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1004,
6216,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
604,
6216,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1390,
6216,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
988,
6216,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1748,
8185,
30860,
316,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
827,
8185,
30860,
316,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1748,
9121,
30860,
316,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
827,
9121,
30860,
316,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1806,
604,
6981,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
1883,
604,
6981,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
2451,
30860,
316,
8,
277,
12,
1413,
1610,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
1019,
30860,
316,
8,
49,
1610,
9,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1568,
8,
277,
12,
299,
63,
442,
12,
1413,
1558,
12,
1109,
63,
2902,
933,
1483,
29,
16,
12,
769,
63,
1618,
63,
442,
63,
2902,
3836,
29,
16,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
890,
8,
442,
12,
1413,
1558,
12,
1109,
5174,
933,
1483,
29,
16,
12,
769,
13,
1618,
13,
442,
5174,
3836,
29,
16,
9,
1035,
1413,
2320,
38,
408,
267,
986,
339,
347,
4024,
415,
2204,
6981,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
26845,
2204,
6981,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
3367,
913,
8934,
316,
8252,
8,
277,
12,
1413,
1558,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363
] |
[
2644,
26,
2774,
13,
24,
199,
3,
859,
14084,
20,
14,
10604,
199,
3,
687,
1182,
2647,
15,
773,
15,
1548,
18,
14,
23,
15,
2686,
13,
5154,
15,
24107,
20,
15,
10604,
14,
1152,
199,
3,
701,
4306,
413,
14,
8312,
199,
3,
949,
1382,
199,
199,
3,
8925,
199,
646,
14084,
20,
14,
10901,
465,
636,
24107,
20,
63,
10901,
421,
199,
533,
1413,
6986,
17213,
38,
837,
327,
9645,
9768,
26,
665,
466,
283,
17839,
14,
4129,
5029,
8423,
272,
408,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
9,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
12,
1413,
30833,
2510,
9,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
17213,
9,
272,
1413,
6986,
17213,
38,
8,
49,
6986,
17213,
38,
9,
272,
408,
272,
347,
465,
2946,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
305,
2946,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
8095,
1610,
6216,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
8536,
1610,
6216,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
16842,
8252,
8,
277,
12,
29254,
589,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
543,
3663,
1806,
3640,
267,
408,
267,
1413,
6986,
17213,
38,
14,
24511,
8252,
8,
49,
1610,
9,
1035,
1413,
8252,
38,
267,
1413,
6986,
17213,
38,
14,
24511,
8252,
8,
49,
1558,
9,
1035,
1413,
8252,
38,
267,
1413,
6986,
17213,
38,
14,
24511,
8252,
8,
30197,
38,
12,
1109,
12,
1413,
1558,
12,
1109,
5174,
933,
1483,
29,
16,
12,
769,
13,
1618,
13,
442,
5174,
3836,
29,
16,
9,
1035,
1413,
8252,
38,
267,
408,
267,
986,
339,
347,
16842,
8252,
1610,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
327,
3363,
4955,
5809,
267,
986,
339,
347,
31518,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
26269,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
28214,
770,
1872,
8,
277,
12,
1413,
1558,
12,
3959,
63,
1872,
37,
8409,
1385,
12,
299,
63,
1609,
12,
1109,
63,
2469,
29,
16,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
18865,
770,
1872,
8,
49,
1558,
12,
3959,
14,
1872,
37,
8409,
1385,
12,
2069,
12,
1109,
3285,
29,
16,
9,
1035,
1413,
1558,
408,
267,
986,
339,
347,
4569,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
3333,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
315,
6986,
8,
277,
12,
1413,
1610,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
262,
6986,
8,
49,
1610,
9,
1035,
2155,
408,
267,
372,
756,
339,
347,
315,
6986,
53,
1259,
20,
8,
277,
12,
299,
63,
442,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
262,
6986,
53,
1259,
20,
8,
442,
9,
1035,
2155,
408,
267,
372,
756,
339,
347,
9186,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
16812,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
3602,
30860,
316,
8,
277,
12,
1413,
1610,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
3039,
30860,
316,
8,
49,
1610,
9,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1004,
24052,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
604,
24052,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1004,
6216,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
604,
6216,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1390,
6216,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
988,
6216,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1748,
8185,
30860,
316,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
827,
8185,
30860,
316,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1748,
9121,
30860,
316,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
827,
9121,
30860,
316,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1806,
604,
6981,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
1883,
604,
6981,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
2451,
30860,
316,
8,
277,
12,
1413,
1610,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
1019,
30860,
316,
8,
49,
1610,
9,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
1568,
8,
277,
12,
299,
63,
442,
12,
1413,
1558,
12,
1109,
63,
2902,
933,
1483,
29,
16,
12,
769,
63,
1618,
63,
442,
63,
2902,
3836,
29,
16,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
890,
8,
442,
12,
1413,
1558,
12,
1109,
5174,
933,
1483,
29,
16,
12,
769,
13,
1618,
13,
442,
5174,
3836,
29,
16,
9,
1035,
1413,
2320,
38,
408,
267,
986,
339,
347,
4024,
415,
2204,
6981,
8,
277,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
267,
408,
1413,
6986,
17213,
38,
14,
26845,
2204,
6981,
342,
1035,
2069,
408,
267,
372,
378,
14,
16,
339,
347,
3367,
913,
8934,
316,
8252,
8,
277,
12,
1413,
1558,
304,
327,
3363,
4955,
5809,
27,
14429,
687,
636,
1301,
363,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
JNRowe/shell-doctest
|
shelldoctest/shelldoctest.py
|
1
|
8293
|
#!/usr/bin/env python
"""
Shell Doctest module.
:Copyright: (c) 2009, the Shell Doctest Team All rights reserved.
:license: BSD, see LICENSE for more details.
"""
import commands
import doctest
import inspect
import re
import subprocess
import sys
master = None
_EXC_WRAPPER = 'system_command("%s")'
def system_command(cmd, shell="bash"):
p = subprocess.Popen('%(shell)s -c "%(cmd)s"' % vars(),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
status, stdout, stderr = p.wait(), p.stdout.read().strip(), p.stderr.read().strip()
if status == 0 and stderr == "":
format = "%(stdout)s"
elif stdout != "":
format = "(%(status)d)%(stderr)s\n%(stdout)s"
else:
format = "(%(status)d)%(stderr)s"
result = format % vars()
if sys.version_info < (2, 5):
print result
return
print(result)
class ShellExample(doctest.Example):
def __init__(self, source, want, exc_msg=None, lineno=0, indent=0,
label=None,
options=None):
doctest.Example.__init__(self, source, want, exc_msg=None, lineno=lineno, indent=indent,
options=None)
self.label = label
class ShellDocTestParser(doctest.DocTestParser):
_PROMPT = "$"
_EXC_WRAPPER = _EXC_WRAPPER
_EXAMPLE_RE = re.compile(r'''
# Source consists of a PS1 line followed by zero or more PS2 lines.
(?P<source>
(?:^ (?P<indent> [ ]*)) # PS0 line: indent
(?: \[(?P<label>.+)\]\n)? # PS0 line: label
(?: (?P<user>[\w]*)@(?P<host>[\w\.-]*)\n)? # PS0 line: user@host
(?: [ ]* \$ .*) # PS1 line
(?:\n [ ]* \. [ ].*)*) # PS2 lines
\n?
# Want consists of any non-blank lines that do not start with PS1.
(?P<want> (?:(?![ ]*$) # Not a blank line
(?![ ]*\$) # Not a line starting with PS1
.*$\n? # But any other line
)*)
''', re.MULTILINE | re.VERBOSE)
def parse(self, string, name='<string>'):
string = string.expandtabs()
min_indent = self._min_indent(string)
if min_indent > 0:
string = '\n'.join([l[min_indent:] for l in string.split('\n')])
output = []
charno, lineno = 0, 0
for m in self._EXAMPLE_RE.finditer(string):
output.append(string[charno:m.start()])
lineno += string.count('\n', charno, m.start())
(source, options, want, exc_msg) = \
self._parse_example(m, name, lineno)
if not self._IS_BLANK_OR_COMMENT(source):
source = source.replace("\n","; ")
user = m.group('user')
host = m.group('host')
if host:
if user:
cmd_base = "ssh %(user)s@%(host)s '%(source)s'"
else:
cmd_base = "ssh %(host)s '%(source)s'"
source = cmd_base % vars()
output.append( ShellExample(self._EXC_WRAPPER % source.replace("\n","; "),
want, exc_msg, lineno=lineno,
label=m.group('label'),
indent=min_indent+len(m.group('indent')),
options=options) )
lineno += string.count('\n', m.start(), m.end())
charno = m.end()
output.append(string[charno:])
return output
def _parse_example(self, m, name, lineno):
indent = len(m.group('indent'))
source_lines = [sl for sl in m.group('source').split('\n') if sl.strip()[1] == " "]
self._check_prompt_blank(source_lines, indent, name, lineno)
self._check_prefix(source_lines[1:], ' '*indent + '.', name, lineno)
source = '\n'.join([sl[indent+len(self._PROMPT)+1:] for sl in source_lines])
want = m.group('want')
want_lines = want.split('\n')
if len(want_lines) > 1 and re.match(r' *$', want_lines[-1]):
del want_lines[-1]
self._check_prefix(want_lines, ' '*indent, name,
lineno + len(source_lines))
want = '\n'.join([wl[indent:] for wl in want_lines])
m = self._EXCEPTION_RE.match(want)
if m:
exc_msg = m.group('msg')
else:
exc_msg = None
options = self._find_options(source, name, lineno)
return source, options, want, exc_msg
def _check_prompt_blank(self, lines, indent, name, lineno):
for i, line in enumerate(lines):
if len(line) >= indent+len(self._PROMPT)+1 and line[indent+len(self._PROMPT)] != ' ':
raise ValueError('line %r of the docstring for %s '
'lacks blank after %s: %r' %
(lineno+i+1, name,
line[indent:indent+len(self._PROMPT)], line))
class ShellDocTestRunner(doctest.DocTestRunner):
_EXC_WRAPPER = _EXC_WRAPPER
_BEFORE, _AFTER = [len(i) for i in _EXC_WRAPPER.split("%s")]
def __init__(self, checker=None, verbose=None, verbose_level=None, optionflags=0):
doctest.DocTestRunner.__init__(self, checker=checker, verbose=verbose, optionflags=optionflags)
self._verbose_level = verbose_level
def report_start(self, out, test, example):
source = example.source[self._BEFORE:-(self._AFTER+1)] + "\n"
if self._verbose_level > 1:
out('Label:%s\n' % example.label)
if self._verbose:
if example.want:
out('Trying:\n' + doctest._indent(source) +
'Expecting:\n' + doctest._indent(example.want))
else:
out('Trying:\n' + doctest._indent(source) +
'Expecting nothing\n')
def _failure_header(self, test, example):
out = [self.DIVIDER]
if test.filename:
if test.lineno is not None and example.lineno is not None:
lineno = test.lineno + example.lineno + 1
else:
lineno = '?'
out.append('File "%s", line %s, in %s' %
(test.filename, lineno, test.name))
else:
out.append('Line %s, in %s' % (example.lineno+1, test.name))
out.append('Failed example:')
source = example.source[self._BEFORE:-(self._AFTER+1)] + "\n"
out.append(doctest._indent(source))
return '\n'.join(out)
def testmod(m=None, name=None, globs=None, verbose=None,
report=True, optionflags=doctest.ELLIPSIS, extraglobs=None,
raise_on_error=False, exclude_empty=False,
verbose_level=None, filters=None,
):
if globs == None:
globs = dict()
globs.update({"system_command": system_command})
global master
if m is None:
m = sys.modules.get('__main__')
if not inspect.ismodule(m):
raise TypeError("testmod: module required; %r" % (m,))
if name is None:
name = m.__name__
finder = doctest.DocTestFinder(parser=ShellDocTestParser(), exclude_empty=exclude_empty)
if raise_on_error:
runner = doctest.DebugRunner(verbose=verbose, optionflags=optionflags)
else:
runner = ShellDocTestRunner(verbose=verbose, verbose_level=verbose_level, optionflags=optionflags)
tests = finder.find(m, name, globs=globs, extraglobs=extraglobs)
if filters:
_tests = list()
z = dict([(k,v) for v,k in enumerate(filters)])
for test in tests:
test.examples = sorted(filter(lambda x: x.label in filters, test.examples),
cmp=lambda x,y: cmp(z[x.label], z[y.label]))
_tests.append(test)
tests = _tests
for test in tests:
runner.run(test)
if report:
runner.summarize()
if master is None:
master = runner
else:
master.merge(runner)
if sys.version_info < (2, 6):
return runner.failures, runner.tries
return doctest.TestResults(runner.failures, runner.tries)
if __name__ == "__main__":
testmod()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
8529,
5454,
396,
859,
14,
199,
199,
26,
7384,
26,
334,
67,
9,
8937,
12,
314,
24599,
5454,
396,
11682,
2900,
4481,
4644,
14,
199,
26,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
3718,
199,
646,
8868,
199,
646,
6485,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
199,
4133,
275,
488,
199,
63,
1438,
35,
63,
23824,
4227,
275,
283,
2253,
63,
1531,
3647,
83,
32292,
199,
199,
318,
2656,
63,
1531,
8,
1760,
12,
5218,
628,
16408,
2349,
272,
299,
275,
3873,
14,
7942,
24713,
5641,
9,
83,
446,
67,
11792,
1760,
9,
83,
4507,
450,
6802,
1062,
586,
5218,
29,
549,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
9,
272,
2004,
12,
3839,
12,
4635,
275,
299,
14,
2573,
1062,
299,
14,
2703,
14,
739,
1252,
1913,
1062,
299,
14,
3083,
14,
739,
1252,
1913,
342,
272,
340,
2004,
508,
378,
436,
4635,
508,
10812,
267,
1475,
275,
11792,
2703,
9,
83,
2,
272,
916,
3839,
1137,
10812,
267,
1475,
275,
7340,
2840,
1205,
9,
68,
9,
2840,
3083,
9,
83,
60,
78,
2840,
2703,
9,
83,
2,
272,
587,
26,
267,
1475,
275,
7340,
2840,
1205,
9,
68,
9,
2840,
3083,
9,
83,
2,
272,
754,
275,
1475,
450,
6802,
342,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
959,
304,
267,
870,
754,
267,
372,
272,
870,
8,
1099,
9,
199,
199,
533,
24599,
9846,
8,
11390,
14,
9846,
304,
272,
347,
636,
826,
721,
277,
12,
1350,
12,
2934,
12,
3178,
63,
1328,
29,
403,
12,
5874,
29,
16,
12,
4363,
29,
16,
12,
2151,
1768,
29,
403,
12,
2151,
1511,
29,
403,
304,
267,
8868,
14,
9846,
855,
826,
721,
277,
12,
1350,
12,
2934,
12,
3178,
63,
1328,
29,
403,
12,
5874,
29,
3469,
12,
4363,
29,
3724,
12,
2151,
1511,
29,
403,
9,
267,
291,
14,
1302,
275,
1768,
199,
199,
533,
24599,
30311,
2842,
8,
11390,
14,
30311,
2842,
304,
272,
485,
2514,
26178,
275,
7880,
2,
272,
485,
1438,
35,
63,
23824,
4227,
275,
485,
1438,
35,
63,
23824,
4227,
272,
485,
26900,
63,
907,
275,
295,
14,
2014,
8,
82,
2344,
267,
327,
5800,
18581,
402,
282,
30382,
17,
1004,
9437,
701,
4697,
503,
1655,
30382,
18,
2385,
14,
267,
7558,
48,
28,
1365,
30,
288,
16697,
62,
221,
7558,
48,
28,
3724,
30,
359,
1622,
10,
430,
7861,
327,
30382,
16,
1004,
26,
4363,
288,
16697,
257,
30257,
2229,
48,
28,
1302,
31411,
2862,
7272,
78,
5547,
4483,
327,
30382,
16,
1004,
26,
1768,
288,
16697,
257,
7558,
48,
28,
751,
24693,
87,
23849,
32,
2229,
48,
28,
1102,
24693,
87,
4537,
13,
3672,
2862,
78,
5547,
327,
30382,
16,
1004,
26,
922,
32,
1102,
288,
16697,
257,
359,
1622,
10,
971,
4,
1275,
13278,
14516,
327,
30382,
17,
1004,
288,
7558,
3427,
78,
359,
1622,
10,
971,
14,
359,
221,
1055,
10,
3342,
9,
12788,
327,
30382,
18,
2385,
267,
971,
78,
31,
267,
327,
644,
867,
18581,
402,
1263,
2222,
13,
2500,
2385,
626,
886,
440,
1343,
543,
30382,
17,
14,
267,
7558,
48,
28,
7051,
30,
16697,
2229,
21282,
1622,
10,
4,
9,
259,
327,
2832,
282,
4596,
1004,
2151,
7558,
21282,
1622,
7590,
4,
9,
257,
327,
2832,
282,
1004,
6617,
543,
30382,
17,
2151,
23076,
16827,
78,
31,
755,
327,
11017,
1263,
1163,
1004,
2116,
776,
13278,
267,
21281,
295,
14,
16661,
1204,
295,
14,
16075,
9,
339,
347,
2198,
8,
277,
12,
1059,
12,
536,
15829,
875,
30,
735,
267,
1059,
275,
1059,
14,
30386,
342,
267,
1748,
63,
3724,
275,
291,
423,
827,
63,
3724,
8,
875,
9,
267,
340,
1748,
63,
3724,
690,
378,
26,
288,
1059,
275,
1557,
78,
1370,
904,
779,
76,
59,
827,
63,
3724,
2938,
367,
634,
315,
1059,
14,
1294,
2258,
78,
2023,
267,
1072,
275,
942,
267,
1495,
889,
12,
5874,
275,
378,
12,
378,
267,
367,
333,
315,
291,
423,
26900,
63,
907,
14,
19373,
8,
875,
304,
288,
1072,
14,
740,
8,
875,
59,
1560,
889,
26,
77,
14,
928,
9383,
288,
5874,
847,
1059,
14,
835,
2258,
78,
297,
1495,
889,
12,
333,
14,
928,
1012,
288,
334,
1365,
12,
1511,
12,
2934,
12,
3178,
63,
1328,
9,
275,
971,
2151,
291,
423,
1122,
63,
2694,
8,
77,
12,
536,
12,
5874,
9,
288,
340,
440,
291,
423,
1311,
63,
20438,
63,
726,
63,
10973,
8,
1365,
304,
355,
1350,
275,
1350,
14,
1814,
4582,
78,
2266,
27,
6099,
355,
922,
275,
333,
14,
923,
360,
751,
358,
355,
1591,
275,
333,
14,
923,
360,
1102,
358,
355,
340,
1591,
26,
490,
340,
922,
26,
717,
2088,
63,
1095,
275,
298,
5510,
2818,
751,
9,
83,
32,
2840,
1102,
9,
83,
9487,
1365,
9,
83,
4065,
490,
587,
26,
717,
2088,
63,
1095,
275,
298,
5510,
2818,
1102,
9,
83,
9487,
1365,
9,
83,
4065,
490,
1350,
275,
2088,
63,
1095,
450,
6802,
342,
355,
1072,
14,
740,
8,
24599,
9846,
8,
277,
423,
1438,
35,
63,
23824,
4227,
450,
1350,
14,
1814,
4582,
78,
2266,
27,
26261,
2511,
2934,
12,
3178,
63,
1328,
12,
5874,
29,
3469,
12,
2511,
1768,
29,
77,
14,
923,
360,
1302,
659,
2511,
4363,
29,
827,
63,
3724,
11,
552,
8,
77,
14,
923,
360,
3724,
3855,
2511,
1511,
29,
1419,
9,
776,
288,
5874,
847,
1059,
14,
835,
2258,
78,
297,
333,
14,
928,
1062,
333,
14,
500,
1012,
288,
1495,
889,
275,
333,
14,
500,
342,
267,
1072,
14,
740,
8,
875,
59,
1560,
889,
5728,
267,
372,
1072,
339,
347,
485,
1122,
63,
2694,
8,
277,
12,
333,
12,
536,
12,
5874,
304,
267,
4363,
275,
822,
8,
77,
14,
923,
360,
3724,
1333,
267,
1350,
63,
1278,
275,
359,
2482,
367,
5340,
315,
333,
14,
923,
360,
1365,
1959,
1294,
2258,
78,
358,
340,
5340,
14,
1913,
3430,
17,
61,
508,
298,
32705,
267,
291,
423,
1074,
63,
7650,
63,
2500,
8,
1365,
63,
1278,
12,
4363,
12,
536,
12,
5874,
9,
267,
291,
423,
1074
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
8529,
5454,
396,
859,
14,
199,
199,
26,
7384,
26,
334,
67,
9,
8937,
12,
314,
24599,
5454,
396,
11682,
2900,
4481,
4644,
14,
199,
26,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
199,
646,
3718,
199,
646,
8868,
199,
646,
6485,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
199,
4133,
275,
488,
199,
63,
1438,
35,
63,
23824,
4227,
275,
283,
2253,
63,
1531,
3647,
83,
32292,
199,
199,
318,
2656,
63,
1531,
8,
1760,
12,
5218,
628,
16408,
2349,
272,
299,
275,
3873,
14,
7942,
24713,
5641,
9,
83,
446,
67,
11792,
1760,
9,
83,
4507,
450,
6802,
1062,
586,
5218,
29,
549,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
9,
272,
2004,
12,
3839,
12,
4635,
275,
299,
14,
2573,
1062,
299,
14,
2703,
14,
739,
1252,
1913,
1062,
299,
14,
3083,
14,
739,
1252,
1913,
342,
272,
340,
2004,
508,
378,
436,
4635,
508,
10812,
267,
1475,
275,
11792,
2703,
9,
83,
2,
272,
916,
3839,
1137,
10812,
267,
1475,
275,
7340,
2840,
1205,
9,
68,
9,
2840,
3083,
9,
83,
60,
78,
2840,
2703,
9,
83,
2,
272,
587,
26,
267,
1475,
275,
7340,
2840,
1205,
9,
68,
9,
2840,
3083,
9,
83,
2,
272,
754,
275,
1475,
450,
6802,
342,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
18,
12,
959,
304,
267,
870,
754,
267,
372,
272,
870,
8,
1099,
9,
199,
199,
533,
24599,
9846,
8,
11390,
14,
9846,
304,
272,
347,
636,
826,
721,
277,
12,
1350,
12,
2934,
12,
3178,
63,
1328,
29,
403,
12,
5874,
29,
16,
12,
4363,
29,
16,
12,
2151,
1768,
29,
403,
12,
2151,
1511,
29,
403,
304,
267,
8868,
14,
9846,
855,
826,
721,
277,
12,
1350,
12,
2934,
12,
3178,
63,
1328,
29,
403,
12,
5874,
29,
3469,
12,
4363,
29,
3724,
12,
2151,
1511,
29,
403,
9,
267,
291,
14,
1302,
275,
1768,
199,
199,
533,
24599,
30311,
2842,
8,
11390,
14,
30311,
2842,
304,
272,
485,
2514,
26178,
275,
7880,
2,
272,
485,
1438,
35,
63,
23824,
4227,
275,
485,
1438,
35,
63,
23824,
4227,
272,
485,
26900,
63,
907,
275,
295,
14,
2014,
8,
82,
2344,
267,
327,
5800,
18581,
402,
282,
30382,
17,
1004,
9437,
701,
4697,
503,
1655,
30382,
18,
2385,
14,
267,
7558,
48,
28,
1365,
30,
288,
16697,
62,
221,
7558,
48,
28,
3724,
30,
359,
1622,
10,
430,
7861,
327,
30382,
16,
1004,
26,
4363,
288,
16697,
257,
30257,
2229,
48,
28,
1302,
31411,
2862,
7272,
78,
5547,
4483,
327,
30382,
16,
1004,
26,
1768,
288,
16697,
257,
7558,
48,
28,
751,
24693,
87,
23849,
32,
2229,
48,
28,
1102,
24693,
87,
4537,
13,
3672,
2862,
78,
5547,
327,
30382,
16,
1004,
26,
922,
32,
1102,
288,
16697,
257,
359,
1622,
10,
971,
4,
1275,
13278,
14516,
327,
30382,
17,
1004,
288,
7558,
3427,
78,
359,
1622,
10,
971,
14,
359,
221,
1055,
10,
3342,
9,
12788,
327,
30382,
18,
2385,
267,
971,
78,
31,
267,
327,
644,
867,
18581,
402,
1263,
2222,
13,
2500,
2385,
626,
886,
440,
1343,
543,
30382,
17,
14,
267,
7558,
48,
28,
7051,
30,
16697,
2229,
21282,
1622,
10,
4,
9,
259,
327,
2832,
282,
4596,
1004,
2151,
7558,
21282,
1622,
7590,
4,
9,
257,
327,
2832,
282,
1004,
6617,
543,
30382,
17,
2151,
23076,
16827,
78,
31,
755,
327,
11017,
1263,
1163,
1004,
2116,
776,
13278,
267,
21281,
295,
14,
16661,
1204,
295,
14,
16075,
9,
339,
347,
2198,
8,
277,
12,
1059,
12,
536,
15829,
875,
30,
735,
267,
1059,
275,
1059,
14,
30386,
342,
267,
1748,
63,
3724,
275,
291,
423,
827,
63,
3724,
8,
875,
9,
267,
340,
1748,
63,
3724,
690,
378,
26,
288,
1059,
275,
1557,
78,
1370,
904,
779,
76,
59,
827,
63,
3724,
2938,
367,
634,
315,
1059,
14,
1294,
2258,
78,
2023,
267,
1072,
275,
942,
267,
1495,
889,
12,
5874,
275,
378,
12,
378,
267,
367,
333,
315,
291,
423,
26900,
63,
907,
14,
19373,
8,
875,
304,
288,
1072,
14,
740,
8,
875,
59,
1560,
889,
26,
77,
14,
928,
9383,
288,
5874,
847,
1059,
14,
835,
2258,
78,
297,
1495,
889,
12,
333,
14,
928,
1012,
288,
334,
1365,
12,
1511,
12,
2934,
12,
3178,
63,
1328,
9,
275,
971,
2151,
291,
423,
1122,
63,
2694,
8,
77,
12,
536,
12,
5874,
9,
288,
340,
440,
291,
423,
1311,
63,
20438,
63,
726,
63,
10973,
8,
1365,
304,
355,
1350,
275,
1350,
14,
1814,
4582,
78,
2266,
27,
6099,
355,
922,
275,
333,
14,
923,
360,
751,
358,
355,
1591,
275,
333,
14,
923,
360,
1102,
358,
355,
340,
1591,
26,
490,
340,
922,
26,
717,
2088,
63,
1095,
275,
298,
5510,
2818,
751,
9,
83,
32,
2840,
1102,
9,
83,
9487,
1365,
9,
83,
4065,
490,
587,
26,
717,
2088,
63,
1095,
275,
298,
5510,
2818,
1102,
9,
83,
9487,
1365,
9,
83,
4065,
490,
1350,
275,
2088,
63,
1095,
450,
6802,
342,
355,
1072,
14,
740,
8,
24599,
9846,
8,
277,
423,
1438,
35,
63,
23824,
4227,
450,
1350,
14,
1814,
4582,
78,
2266,
27,
26261,
2511,
2934,
12,
3178,
63,
1328,
12,
5874,
29,
3469,
12,
2511,
1768,
29,
77,
14,
923,
360,
1302,
659,
2511,
4363,
29,
827,
63,
3724,
11,
552,
8,
77,
14,
923,
360,
3724,
3855,
2511,
1511,
29,
1419,
9,
776,
288,
5874,
847,
1059,
14,
835,
2258,
78,
297,
333,
14,
928,
1062,
333,
14,
500,
1012,
288,
1495,
889,
275,
333,
14,
500,
342,
267,
1072,
14,
740,
8,
875,
59,
1560,
889,
5728,
267,
372,
1072,
339,
347,
485,
1122,
63,
2694,
8,
277,
12,
333,
12,
536,
12,
5874,
304,
267,
4363,
275,
822,
8,
77,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
EUDAT-B2SHARE/invenio-old
|
modules/bibformat/lib/elements/bfe_report_numbers.py
|
17
|
2526
|
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2007, 2008, 2009, 2010, 2011 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.
"""BibFormat element - Prints report numbers
"""
__revision__ = ""
import cgi
from invenio.urlutils import create_html_link
def format_element(bfo, limit, separator=" ", extension=" etc.", link='yes'):
"""
Prints the report numbers of the record (037__a and 088__a)
@param separator: the separator between report numbers.
@param limit: the max number of report numbers to print
@param extension: a prefix printed when limit param is reached
@param link: if 'yes', display report number with corresponding link when possible
"""
numbers = bfo.fields("037__a")
numbers.extend(bfo.fields("088__a"))
if limit.isdigit():
limit_as_int = int(limit)
if limit_as_int <= len(numbers):
return separator.join(numbers[:limit_as_int]) + extension
return separator.join([build_report_number_link(report_number, \
link == 'yes') \
for report_number in numbers])
def build_report_number_link(report_number, link_p=True):
"""
Build HTML link out of given report number when it make sense (or
is possible) and/or escape report number.
@param report_number: the report number to consider
@param link_p: if True, build link, otherwise just escape
"""
if link_p and report_number.lower().startswith('arxiv:'):
return create_html_link('http://arxiv.org/abs/' + report_number,
urlargd={}, link_label=report_number)
else:
return cgi.escape(report_number)
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
624,
25217,
3484,
1819,
446,
9101,
83,
3622,
5579,
199,
624,
199,
199,
363,
5792,
363,
275,
3087,
199,
199,
646,
16004,
199,
504,
13640,
14,
633,
1208,
492,
1218,
63,
1360,
63,
1073,
199,
199,
318,
1475,
63,
2108,
8,
66,
545,
12,
2304,
12,
9432,
628,
3872,
3329,
628,
5423,
4765,
2142,
534,
5066,
735,
272,
408,
272,
9101,
83,
314,
3622,
5579,
402,
314,
2777,
334,
18325,
363,
65,
436,
378,
1299,
363,
65,
9,
339,
768,
635,
9432,
26,
314,
9432,
3382,
3622,
5579,
14,
272,
768,
635,
2304,
26,
314,
1390,
1329,
402,
3622,
5579,
370,
870,
272,
768,
635,
3329,
26,
282,
2403,
12487,
1380,
2304,
1215,
365,
13075,
272,
768,
635,
2142,
26,
340,
283,
5066,
297,
2929,
3622,
1329,
543,
5226,
2142,
1380,
3962,
272,
408,
272,
5579,
275,
330,
545,
14,
955,
480,
18325,
363,
65,
531,
272,
5579,
14,
2880,
8,
66,
545,
14,
955,
480,
27930,
363,
65,
2237,
339,
340,
2304,
14,
13896,
837,
267,
2304,
63,
305,
63,
442,
275,
1109,
8,
3097,
9,
267,
340,
2304,
63,
305,
63,
442,
2695,
822,
8,
10548,
304,
288,
372,
9432,
14,
904,
8,
10548,
1491,
3097,
63,
305,
63,
442,
566,
435,
3329,
339,
372,
9432,
14,
904,
779,
1506,
63,
3070,
63,
1955,
63,
1073,
8,
3070,
63,
1955,
12,
971,
8105,
2142,
508,
283,
5066,
358,
971,
2574,
367,
3622,
63,
1955,
315,
5579,
566,
199,
199,
318,
1900,
63,
3070,
63,
1955,
63,
1073,
8,
3070,
63,
1955,
12,
2142,
63,
80,
29,
549,
304,
272,
408,
272,
6516,
4163,
2142,
734,
402,
1627,
3622,
1329,
1380,
652,
1852,
12249,
334,
269,
272,
365,
3962,
9,
436,
15,
269,
4772,
3622,
1329,
14,
272,
768,
635,
3622,
63,
1955,
26,
314,
3622,
1329,
370,
11201,
272,
768,
635,
2142,
63,
80,
26,
340,
715,
12,
1900,
2142,
12,
4257,
2951,
4772,
272,
408,
272,
340,
2142,
63,
80,
436,
3622,
63,
1955,
14,
2325,
1252,
2460,
360,
27290,
23117,
267,
372,
1218,
63,
1360,
63,
1073,
360,
1014,
921,
27290,
14,
1308,
15,
2101,
4805,
435,
3622,
63,
1955,
12,
1816,
1166,
26282,
10324,
2142,
63,
1302,
29,
3070,
63,
1955,
9,
272,
587,
26,
267,
372,
16004,
14,
3765,
8,
3070,
63,
1955,
9,
199,
199,
318,
4772,
63,
1459,
8,
66,
545,
304,
272,
408,
272,
12295,
701,
21949,
3484,
315,
1865,
370,
1104,
340,
1072,
402,
642,
1819,
272,
1077,
506,
11077,
14,
272,
408,
272,
372,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
624,
25217,
3484,
1819,
446,
9101,
83,
3622,
5579,
199,
624,
199,
199,
363,
5792,
363,
275,
3087,
199,
199,
646,
16004,
199,
504,
13640,
14,
633,
1208,
492,
1218,
63,
1360,
63,
1073,
199,
199,
318,
1475,
63,
2108,
8,
66,
545,
12,
2304,
12,
9432,
628,
3872,
3329,
628,
5423,
4765,
2142,
534,
5066,
735,
272,
408,
272,
9101,
83,
314,
3622,
5579,
402,
314,
2777,
334,
18325,
363,
65,
436,
378,
1299,
363,
65,
9,
339,
768,
635,
9432,
26,
314,
9432,
3382,
3622,
5579,
14,
272,
768,
635,
2304,
26,
314,
1390,
1329,
402,
3622,
5579,
370,
870,
272,
768,
635,
3329,
26,
282,
2403,
12487,
1380,
2304,
1215,
365,
13075,
272,
768,
635,
2142,
26,
340,
283,
5066,
297,
2929,
3622,
1329,
543,
5226,
2142,
1380,
3962,
272,
408,
272,
5579,
275,
330,
545,
14,
955,
480,
18325,
363,
65,
531,
272,
5579,
14,
2880,
8,
66,
545,
14,
955,
480,
27930,
363,
65,
2237,
339,
340,
2304,
14,
13896,
837,
267,
2304,
63,
305,
63,
442,
275,
1109,
8,
3097,
9,
267,
340,
2304,
63,
305,
63,
442,
2695,
822,
8,
10548,
304,
288,
372,
9432,
14,
904,
8,
10548,
1491,
3097,
63,
305,
63,
442,
566,
435,
3329,
339,
372,
9432,
14,
904,
779,
1506,
63,
3070,
63,
1955,
63,
1073,
8,
3070,
63,
1955,
12,
971,
8105,
2142,
508,
283,
5066,
358,
971,
2574,
367,
3622,
63,
1955,
315,
5579,
566,
199,
199,
318,
1900,
63,
3070,
63,
1955,
63,
1073,
8,
3070,
63,
1955,
12,
2142,
63,
80,
29,
549,
304,
272,
408,
272,
6516,
4163,
2142,
734,
402,
1627,
3622,
1329,
1380,
652,
1852,
12249,
334,
269,
272,
365,
3962,
9,
436,
15,
269,
4772,
3622,
1329,
14,
272,
768,
635,
3622,
63,
1955,
26,
314,
3622,
1329,
370,
11201,
272,
768,
635,
2142,
63,
80,
26,
340,
715,
12,
1900,
2142,
12,
4257,
2951,
4772,
272,
408,
272,
340,
2142,
63,
80,
436,
3622,
63,
1955,
14,
2325,
1252,
2460,
360,
27290,
23117,
267,
372,
1218,
63,
1360,
63,
1073,
360,
1014,
921,
27290,
14,
1308,
15,
2101,
4805,
435,
3622,
63,
1955,
12,
1816,
1166,
26282,
10324,
2142,
63,
1302,
29,
3070,
63,
1955,
9,
272,
587,
26,
267,
372,
16004,
14,
3765,
8,
3070,
63,
1955,
9,
199,
199,
318,
4772,
63,
1459,
8,
66,
545,
304,
272,
408,
272,
12295,
701,
21949,
3484,
315,
1865,
370,
1104,
340,
1072,
402,
642,
1819,
272,
1077,
506,
11077,
14,
272,
408,
272,
372,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
imsparsh/python-for-android
|
python-modules/twisted/twisted/manhole/service.py
|
62
|
12946
|
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
# See LICENSE for details.
"""L{twisted.manhole} L{PB<twisted.spread.pb>} service implementation.
"""
# twisted imports
from twisted import copyright
from twisted.spread import pb
from twisted.python import log, failure
from twisted.cred import portal
from twisted.application import service
from zope.interface import implements, Interface
# sibling imports
import explorer
# system imports
from cStringIO import StringIO
import string
import sys
import traceback
import types
class FakeStdIO:
def __init__(self, type_, list):
self.type = type_
self.list = list
def write(self, text):
log.msg("%s: %s" % (self.type, string.strip(str(text))))
self.list.append((self.type, text))
def flush(self):
pass
def consolidate(self):
"""Concatenate adjacent messages of same type into one.
Greatly cuts down on the number of elements, increasing
network transport friendliness considerably.
"""
if not self.list:
return
inlist = self.list
outlist = []
last_type = inlist[0]
block_begin = 0
for i in xrange(1, len(self.list)):
(mtype, message) = inlist[i]
if mtype == last_type:
continue
else:
if (i - block_begin) == 1:
outlist.append(inlist[block_begin])
else:
messages = map(lambda l: l[1],
inlist[block_begin:i])
message = string.join(messages, '')
outlist.append((last_type, message))
last_type = mtype
block_begin = i
class IManholeClient(Interface):
def console(list_of_messages):
"""Takes a list of (type, message) pairs to display.
Types include:
- \"stdout\" -- string sent to sys.stdout
- \"stderr\" -- string sent to sys.stderr
- \"result\" -- string repr of the resulting value
of the expression
- \"exception\" -- a L{failure.Failure}
"""
def receiveExplorer(xplorer):
"""Receives an explorer.Explorer
"""
def listCapabilities():
"""List what manholey things I am capable of doing.
i.e. C{\"Explorer\"}, C{\"Failure\"}
"""
def runInConsole(command, console, globalNS=None, localNS=None,
filename=None, args=None, kw=None, unsafeTracebacks=False):
"""Run this, directing all output to the specified console.
If command is callable, it will be called with the args and keywords
provided. Otherwise, command will be compiled and eval'd.
(Wouldn't you like a macro?)
Returns the command's return value.
The console is called with a list of (type, message) pairs for
display, see L{IManholeClient.console}.
"""
output = []
fakeout = FakeStdIO("stdout", output)
fakeerr = FakeStdIO("stderr", output)
errfile = FakeStdIO("exception", output)
code = None
val = None
if filename is None:
filename = str(console)
if args is None:
args = ()
if kw is None:
kw = {}
if localNS is None:
localNS = globalNS
if (globalNS is None) and (not callable(command)):
raise ValueError("Need a namespace to evaluate the command in.")
try:
out = sys.stdout
err = sys.stderr
sys.stdout = fakeout
sys.stderr = fakeerr
try:
if callable(command):
val = apply(command, args, kw)
else:
try:
code = compile(command, filename, 'eval')
except:
code = compile(command, filename, 'single')
if code:
val = eval(code, globalNS, localNS)
finally:
sys.stdout = out
sys.stderr = err
except:
(eType, eVal, tb) = sys.exc_info()
fail = failure.Failure(eVal, eType, tb)
del tb
# In CVS reversion 1.35, there was some code here to fill in the
# source lines in the traceback for frames in the local command
# buffer. But I can't figure out when that's triggered, so it's
# going away in the conversion to Failure, until you bring it back.
errfile.write(pb.failure2Copyable(fail, unsafeTracebacks))
if console:
fakeout.consolidate()
console(output)
return val
def _failureOldStyle(fail):
"""Pre-Failure manhole representation of exceptions.
For compatibility with manhole clients without the \"Failure\"
capability.
A dictionary with two members:
- \'traceback\' -- traceback.extract_tb output; a list of tuples
(filename, line number, function name, text) suitable for
feeding to traceback.format_list.
- \'exception\' -- a list of one or more strings, each
ending in a newline. (traceback.format_exception_only output)
"""
import linecache
tb = []
for f in fail.frames:
# (filename, line number, function name, text)
tb.append((f[1], f[2], f[0], linecache.getline(f[1], f[2])))
return {
'traceback': tb,
'exception': traceback.format_exception_only(fail.type, fail.value)
}
# Capabilities clients are likely to have before they knew how to answer a
# "listCapabilities" query.
_defaultCapabilities = {
"Explorer": 'Set'
}
class Perspective(pb.Avatar):
lastDeferred = 0
def __init__(self, service):
self.localNamespace = {
"service": service,
"avatar": self,
"_": None,
}
self.clients = {}
self.service = service
def __getstate__(self):
state = self.__dict__.copy()
state['clients'] = {}
if state['localNamespace'].has_key("__builtins__"):
del state['localNamespace']['__builtins__']
return state
def attached(self, client, identity):
"""A client has attached -- welcome them and add them to the list.
"""
self.clients[client] = identity
host = ':'.join(map(str, client.broker.transport.getHost()[1:]))
msg = self.service.welcomeMessage % {
'you': getattr(identity, 'name', str(identity)),
'host': host,
'longversion': copyright.longversion,
}
client.callRemote('console', [("stdout", msg)])
client.capabilities = _defaultCapabilities
client.callRemote('listCapabilities').addCallbacks(
self._cbClientCapable, self._ebClientCapable,
callbackArgs=(client,),errbackArgs=(client,))
def detached(self, client, identity):
try:
del self.clients[client]
except KeyError:
pass
def runInConsole(self, command, *args, **kw):
"""Convience method to \"runInConsole with my stuff\".
"""
return runInConsole(command,
self.console,
self.service.namespace,
self.localNamespace,
str(self.service),
args=args,
kw=kw,
unsafeTracebacks=self.service.unsafeTracebacks)
### Methods for communicating to my clients.
def console(self, message):
"""Pass a message to my clients' console.
"""
clients = self.clients.keys()
origMessage = message
compatMessage = None
for client in clients:
try:
if not client.capabilities.has_key("Failure"):
if compatMessage is None:
compatMessage = origMessage[:]
for i in xrange(len(message)):
if ((message[i][0] == "exception") and
isinstance(message[i][1], failure.Failure)):
compatMessage[i] = (
message[i][0],
_failureOldStyle(message[i][1]))
client.callRemote('console', compatMessage)
else:
client.callRemote('console', message)
except pb.ProtocolError:
# Stale broker.
self.detached(client, None)
def receiveExplorer(self, objectLink):
"""Pass an Explorer on to my clients.
"""
clients = self.clients.keys()
for client in clients:
try:
client.callRemote('receiveExplorer', objectLink)
except pb.ProtocolError:
# Stale broker.
self.detached(client, None)
def _cbResult(self, val, dnum):
self.console([('result', "Deferred #%s Result: %r\n" %(dnum, val))])
return val
def _cbClientCapable(self, capabilities, client):
log.msg("client %x has %s" % (id(client), capabilities))
client.capabilities = capabilities
def _ebClientCapable(self, reason, client):
reason.trap(AttributeError)
log.msg("Couldn't get capabilities from %s, assuming defaults." %
(client,))
### perspective_ methods, commands used by the client.
def perspective_do(self, expr):
"""Evaluate the given expression, with output to the console.
The result is stored in the local variable '_', and its repr()
string is sent to the console as a \"result\" message.
"""
log.msg(">>> %s" % expr)
val = self.runInConsole(expr)
if val is not None:
self.localNamespace["_"] = val
from twisted.internet.defer import Deferred
# TODO: client support for Deferred.
if isinstance(val, Deferred):
self.lastDeferred += 1
self.console([('result', "Waiting for Deferred #%s...\n" % self.lastDeferred)])
val.addBoth(self._cbResult, self.lastDeferred)
else:
self.console([("result", repr(val) + '\n')])
log.msg("<<<")
def perspective_explore(self, identifier):
"""Browse the object obtained by evaluating the identifier.
The resulting ObjectLink is passed back through the client's
receiveBrowserObject method.
"""
object = self.runInConsole(identifier)
if object:
expl = explorer.explorerPool.getExplorer(object, identifier)
self.receiveExplorer(expl)
def perspective_watch(self, identifier):
"""Watch the object obtained by evaluating the identifier.
Whenever I think this object might have changed, I will pass
an ObjectLink of it back to the client's receiveBrowserObject
method.
"""
raise NotImplementedError
object = self.runInConsole(identifier)
if object:
# Return an ObjectLink of this right away, before the watch.
oLink = self.runInConsole(self.browser.browseObject,
object, identifier)
self.receiveExplorer(oLink)
self.runInConsole(self.browser.watchObject,
object, identifier,
self.receiveExplorer)
class Realm:
implements(portal.IRealm)
def __init__(self, service):
self.service = service
self._cache = {}
def requestAvatar(self, avatarId, mind, *interfaces):
if pb.IPerspective not in interfaces:
raise NotImplementedError("no interface")
if avatarId in self._cache:
p = self._cache[avatarId]
else:
p = Perspective(self.service)
p.attached(mind, avatarId)
def detached():
p.detached(mind, avatarId)
return (pb.IPerspective, p, detached)
class Service(service.Service):
welcomeMessage = (
"\nHello %(you)s, welcome to Manhole "
"on %(host)s.\n"
"%(longversion)s.\n\n")
def __init__(self, unsafeTracebacks=False, namespace=None):
self.unsafeTracebacks = unsafeTracebacks
self.namespace = {
'__name__': '__manhole%x__' % (id(self),),
'sys': sys
}
if namespace:
self.namespace.update(namespace)
def __getstate__(self):
"""This returns the persistent state of this shell factory.
"""
# TODO -- refactor this and twisted.reality.author.Author to
# use common functionality (perhaps the 'code' module?)
dict = self.__dict__.copy()
ns = dict['namespace'].copy()
dict['namespace'] = ns
if ns.has_key('__builtins__'):
del ns['__builtins__']
return dict
|
apache-2.0
|
[
199,
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
44,
91,
12145,
14,
1237,
16668,
93,
491,
91,
13167,
28,
12145,
14,
29889,
14,
3317,
23307,
2435,
4514,
14,
199,
624,
199,
199,
3,
7390,
8925,
199,
504,
7390,
492,
4248,
199,
504,
7390,
14,
29889,
492,
10446,
199,
504,
7390,
14,
1548,
492,
943,
12,
5988,
199,
504,
7390,
14,
18639,
492,
18428,
199,
504,
7390,
14,
3578,
492,
2435,
199,
504,
20110,
14,
3266,
492,
9031,
12,
14816,
199,
199,
3,
24238,
8925,
199,
646,
15868,
3859,
199,
199,
3,
2656,
8925,
199,
504,
15073,
492,
5228,
199,
199,
646,
1059,
199,
646,
984,
199,
646,
5190,
199,
646,
2943,
421,
199,
533,
7777,
11976,
2090,
26,
272,
347,
636,
826,
721,
277,
12,
730,
3131,
769,
304,
267,
291,
14,
466,
275,
730,
63,
267,
291,
14,
513,
275,
769,
339,
347,
2218,
8,
277,
12,
1318,
304,
267,
943,
14,
1328,
3647,
83,
26,
450,
83,
2,
450,
334,
277,
14,
466,
12,
1059,
14,
1913,
8,
495,
8,
505,
7845,
267,
291,
14,
513,
14,
740,
1332,
277,
14,
466,
12,
1318,
430,
339,
347,
8976,
8,
277,
304,
267,
986,
339,
347,
406,
28335,
602,
8,
277,
304,
267,
408,
714,
10592,
24113,
3788,
402,
2011,
730,
1901,
1373,
14,
398,
598,
8319,
590,
10415,
83,
3224,
641,
314,
1329,
402,
4008,
12,
22255,
267,
2784,
7773,
32506,
604,
385,
8219,
14411,
590,
14,
267,
408,
267,
340,
440,
291,
14,
513,
26,
288,
372,
398,
315,
513,
275,
291,
14,
513,
267,
734,
513,
275,
942,
267,
2061,
63,
466,
275,
315,
513,
59,
16,
61,
267,
1853,
63,
5037,
275,
378,
267,
367,
284,
315,
4945,
8,
17,
12,
822,
8,
277,
14,
513,
2298,
288,
334,
77,
466,
12,
1245,
9,
275,
315,
513,
59,
73,
61,
288,
340,
21021,
508,
2061,
63,
466,
26,
355,
1980,
288,
587,
26,
355,
340,
334,
73,
446,
1853,
63,
5037,
9,
508,
413,
26,
490,
734,
513,
14,
740,
8,
262,
513,
59,
1457,
63,
5037,
566,
355,
587,
26,
490,
3788,
275,
2341,
8,
2734,
634,
26,
634,
59,
17,
467,
3521,
315,
513,
59,
1457,
63,
5037,
26,
73,
566,
490,
1245,
275,
1059,
14,
904,
8,
3431,
12,
4074,
490,
734,
513,
14,
740,
1332,
2019,
63,
466,
12,
1245,
430,
355,
2061,
63,
466,
275,
21021,
355,
1853,
63,
5037,
275,
284,
421,
199,
533,
473,
2395,
16668,
3041,
8,
4267,
304,
272,
347,
8559,
8,
513,
63,
1618,
63,
3431,
304,
267,
408,
32488,
282,
769,
402,
334,
466,
12,
1245,
9,
6342,
370,
2929,
14,
398,
18851,
2387,
26,
288,
446,
8441,
2703,
4451,
1553,
1059,
4847,
370,
984,
14,
2703,
953,
446,
8441,
3083,
4451,
1553,
1059,
4847,
370,
984,
14,
3083,
953,
446,
8441,
1099,
4451,
1553,
1059,
4700,
402,
314,
9183,
574,
326,
402,
314,
3965,
953,
446,
8441,
1971,
4451,
1553,
282,
491,
91,
5328,
14,
6782,
93,
267,
408,
339,
347,
9128,
4527,
22732,
8,
9290,
22732,
304,
267,
408,
497,
2375,
397,
376,
15868,
3859,
14,
4527,
22732,
267,
408,
339,
347,
769,
17006,
837,
267,
408,
1296,
4052,
2169,
526,
15515,
7645,
473,
8140,
4021,
461,
402,
9689,
14,
398,
284,
14,
69,
14,
445,
91,
4451,
4527,
22732,
4451,
1386,
445,
91,
4451,
6782,
60,
3570,
267,
408,
199,
199,
318,
1255,
607,
9270,
8,
1531,
12,
8559,
12,
2288,
2709,
29,
403,
12,
2257,
2709,
29,
403,
12,
326,
1788,
29,
403,
12,
1249,
29,
403,
12,
4775,
29,
403,
12,
19293,
15905,
83,
29,
797,
304,
272,
408,
2540,
642,
12,
4125,
316,
1006,
1072,
370,
314,
2013,
8559,
14,
339,
982,
1414,
365,
4550,
12,
652,
911,
506,
2797,
543,
314,
1249,
436,
7681,
272,
2741,
14,
221,
6630,
12,
1414,
911,
506,
10311,
436,
3468,
5121,
14,
272,
334,
55,
3857,
78,
1133,
1265,
2839,
282,
9559,
17076,
339,
1803,
314,
1414,
1159,
372,
574,
14,
339,
710,
8559,
365,
2797,
543,
282,
769,
402,
334,
466,
12,
1245,
9,
6342,
367,
272,
2929,
12,
1937,
491,
91,
1469,
290,
16668,
3041,
14,
6614,
5565,
272,
408,
272,
1072,
275,
942,
272,
4026,
548,
275,
7777,
11976,
2090,
480,
2703,
401,
1072,
9,
272,
4026,
1508,
275,
7777,
11976,
2090,
480,
3083,
401,
1072,
9,
272,
2329,
493,
275,
7777,
11976,
2090,
480,
1971,
401,
1072,
9,
272,
1233,
275,
488,
272,
1139,
275,
488,
272,
340,
1788,
365,
488,
26,
267,
1788,
275,
620,
8,
6614,
9,
272,
340,
1249,
365,
488,
26,
267,
1249,
275,
6248,
272,
340,
4775,
365,
488,
26,
267,
4775,
275,
1052,
272,
340,
2257,
2709,
365,
488,
26,
267,
2257,
2709,
275,
2288,
2709,
272,
340,
334,
2966,
2709,
365,
488,
9,
436,
334,
1397,
4550,
8,
1531,
2298,
267,
746,
1722,
480,
17809,
282,
3231,
370,
9352,
314,
1414,
315,
2685,
339,
862,
26,
267,
734,
275,
984,
14,
2703,
267,
2329,
275,
984,
14,
3083,
267,
984,
14,
2703,
275,
4026,
548,
267,
984,
14,
3083,
275,
4026,
1508,
267,
862,
26,
288,
340,
4550,
8,
1531,
304,
355,
1139,
275,
4838,
8,
1531,
12,
1249,
12,
4775,
9,
288,
587,
26,
355,
862,
26,
490,
1233,
275,
6555,
8,
1531,
12,
1788,
12,
283,
2579,
358,
355,
871,
26,
490,
1233,
275,
6555,
8,
1531,
12,
1788,
12,
283,
4780,
358,
2234,
340,
1233,
26,
490,
1139,
275,
3468,
8,
600,
12,
2288,
2709,
12,
2257,
2709,
9,
267,
3753,
26,
288,
984,
14,
2703,
275,
734,
288,
984,
14,
3083,
275,
2329,
272,
871,
26,
267,
334,
69,
804,
12,
325,
7562,
12,
7070,
9,
275,
984,
14,
2804,
63,
815,
342,
267,
2449,
275,
5988,
14,
6782,
8,
69,
7562,
12,
325,
804,
12,
7070,
9,
267,
2150,
7070,
267,
327,
1010,
445,
7428,
295,
1023,
413,
14,
1276,
12,
2337,
1990,
2005,
1233,
2348,
370,
5554,
315,
314,
267,
327,
1350,
2385,
315,
314,
5190,
367,
11223,
315,
314,
2257,
1414,
267,
327,
3335,
14,
221,
11017,
473,
883,
1133,
9658,
734
] |
[
3,
1898,
334,
67,
9,
12521,
13,
15431,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
44,
91,
12145,
14,
1237,
16668,
93,
491,
91,
13167,
28,
12145,
14,
29889,
14,
3317,
23307,
2435,
4514,
14,
199,
624,
199,
199,
3,
7390,
8925,
199,
504,
7390,
492,
4248,
199,
504,
7390,
14,
29889,
492,
10446,
199,
504,
7390,
14,
1548,
492,
943,
12,
5988,
199,
504,
7390,
14,
18639,
492,
18428,
199,
504,
7390,
14,
3578,
492,
2435,
199,
504,
20110,
14,
3266,
492,
9031,
12,
14816,
199,
199,
3,
24238,
8925,
199,
646,
15868,
3859,
199,
199,
3,
2656,
8925,
199,
504,
15073,
492,
5228,
199,
199,
646,
1059,
199,
646,
984,
199,
646,
5190,
199,
646,
2943,
421,
199,
533,
7777,
11976,
2090,
26,
272,
347,
636,
826,
721,
277,
12,
730,
3131,
769,
304,
267,
291,
14,
466,
275,
730,
63,
267,
291,
14,
513,
275,
769,
339,
347,
2218,
8,
277,
12,
1318,
304,
267,
943,
14,
1328,
3647,
83,
26,
450,
83,
2,
450,
334,
277,
14,
466,
12,
1059,
14,
1913,
8,
495,
8,
505,
7845,
267,
291,
14,
513,
14,
740,
1332,
277,
14,
466,
12,
1318,
430,
339,
347,
8976,
8,
277,
304,
267,
986,
339,
347,
406,
28335,
602,
8,
277,
304,
267,
408,
714,
10592,
24113,
3788,
402,
2011,
730,
1901,
1373,
14,
398,
598,
8319,
590,
10415,
83,
3224,
641,
314,
1329,
402,
4008,
12,
22255,
267,
2784,
7773,
32506,
604,
385,
8219,
14411,
590,
14,
267,
408,
267,
340,
440,
291,
14,
513,
26,
288,
372,
398,
315,
513,
275,
291,
14,
513,
267,
734,
513,
275,
942,
267,
2061,
63,
466,
275,
315,
513,
59,
16,
61,
267,
1853,
63,
5037,
275,
378,
267,
367,
284,
315,
4945,
8,
17,
12,
822,
8,
277,
14,
513,
2298,
288,
334,
77,
466,
12,
1245,
9,
275,
315,
513,
59,
73,
61,
288,
340,
21021,
508,
2061,
63,
466,
26,
355,
1980,
288,
587,
26,
355,
340,
334,
73,
446,
1853,
63,
5037,
9,
508,
413,
26,
490,
734,
513,
14,
740,
8,
262,
513,
59,
1457,
63,
5037,
566,
355,
587,
26,
490,
3788,
275,
2341,
8,
2734,
634,
26,
634,
59,
17,
467,
3521,
315,
513,
59,
1457,
63,
5037,
26,
73,
566,
490,
1245,
275,
1059,
14,
904,
8,
3431,
12,
4074,
490,
734,
513,
14,
740,
1332,
2019,
63,
466,
12,
1245,
430,
355,
2061,
63,
466,
275,
21021,
355,
1853,
63,
5037,
275,
284,
421,
199,
533,
473,
2395,
16668,
3041,
8,
4267,
304,
272,
347,
8559,
8,
513,
63,
1618,
63,
3431,
304,
267,
408,
32488,
282,
769,
402,
334,
466,
12,
1245,
9,
6342,
370,
2929,
14,
398,
18851,
2387,
26,
288,
446,
8441,
2703,
4451,
1553,
1059,
4847,
370,
984,
14,
2703,
953,
446,
8441,
3083,
4451,
1553,
1059,
4847,
370,
984,
14,
3083,
953,
446,
8441,
1099,
4451,
1553,
1059,
4700,
402,
314,
9183,
574,
326,
402,
314,
3965,
953,
446,
8441,
1971,
4451,
1553,
282,
491,
91,
5328,
14,
6782,
93,
267,
408,
339,
347,
9128,
4527,
22732,
8,
9290,
22732,
304,
267,
408,
497,
2375,
397,
376,
15868,
3859,
14,
4527,
22732,
267,
408,
339,
347,
769,
17006,
837,
267,
408,
1296,
4052,
2169,
526,
15515,
7645,
473,
8140,
4021,
461,
402,
9689,
14,
398,
284,
14,
69,
14,
445,
91,
4451,
4527,
22732,
4451,
1386,
445,
91,
4451,
6782,
60,
3570,
267,
408,
199,
199,
318,
1255,
607,
9270,
8,
1531,
12,
8559,
12,
2288,
2709,
29,
403,
12,
2257,
2709,
29,
403,
12,
326,
1788,
29,
403,
12,
1249,
29,
403,
12,
4775,
29,
403,
12,
19293,
15905,
83,
29,
797,
304,
272,
408,
2540,
642,
12,
4125,
316,
1006,
1072,
370,
314,
2013,
8559,
14,
339,
982,
1414,
365,
4550,
12,
652,
911,
506,
2797,
543,
314,
1249,
436,
7681,
272,
2741,
14,
221,
6630,
12,
1414,
911,
506,
10311,
436,
3468,
5121,
14,
272,
334,
55,
3857,
78,
1133,
1265,
2839,
282,
9559,
17076,
339,
1803,
314,
1414,
1159,
372,
574,
14,
339,
710,
8559,
365,
2797,
543,
282,
769,
402,
334,
466,
12,
1245,
9,
6342,
367,
272,
2929,
12,
1937,
491,
91,
1469,
290,
16668,
3041,
14,
6614,
5565,
272,
408,
272,
1072,
275,
942,
272,
4026,
548,
275,
7777,
11976,
2090,
480,
2703,
401,
1072,
9,
272,
4026,
1508,
275,
7777,
11976,
2090,
480,
3083,
401,
1072,
9,
272,
2329,
493,
275,
7777,
11976,
2090,
480,
1971,
401,
1072,
9,
272,
1233,
275,
488,
272,
1139,
275,
488,
272,
340,
1788,
365,
488,
26,
267,
1788,
275,
620,
8,
6614,
9,
272,
340,
1249,
365,
488,
26,
267,
1249,
275,
6248,
272,
340,
4775,
365,
488,
26,
267,
4775,
275,
1052,
272,
340,
2257,
2709,
365,
488,
26,
267,
2257,
2709,
275,
2288,
2709,
272,
340,
334,
2966,
2709,
365,
488,
9,
436,
334,
1397,
4550,
8,
1531,
2298,
267,
746,
1722,
480,
17809,
282,
3231,
370,
9352,
314,
1414,
315,
2685,
339,
862,
26,
267,
734,
275,
984,
14,
2703,
267,
2329,
275,
984,
14,
3083,
267,
984,
14,
2703,
275,
4026,
548,
267,
984,
14,
3083,
275,
4026,
1508,
267,
862,
26,
288,
340,
4550,
8,
1531,
304,
355,
1139,
275,
4838,
8,
1531,
12,
1249,
12,
4775,
9,
288,
587,
26,
355,
862,
26,
490,
1233,
275,
6555,
8,
1531,
12,
1788,
12,
283,
2579,
358,
355,
871,
26,
490,
1233,
275,
6555,
8,
1531,
12,
1788,
12,
283,
4780,
358,
2234,
340,
1233,
26,
490,
1139,
275,
3468,
8,
600,
12,
2288,
2709,
12,
2257,
2709,
9,
267,
3753,
26,
288,
984,
14,
2703,
275,
734,
288,
984,
14,
3083,
275,
2329,
272,
871,
26,
267,
334,
69,
804,
12,
325,
7562,
12,
7070,
9,
275,
984,
14,
2804,
63,
815,
342,
267,
2449,
275,
5988,
14,
6782,
8,
69,
7562,
12,
325,
804,
12,
7070,
9,
267,
2150,
7070,
267,
327,
1010,
445,
7428,
295,
1023,
413,
14,
1276,
12,
2337,
1990,
2005,
1233,
2348,
370,
5554,
315,
314,
267,
327,
1350,
2385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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jhcepas/npr
|
nprlib/argparse.py
|
490
|
87791
|
# Author: Steven J. Bethard <steven.bethard@gmail.com>.
"""Command-line parsing library
This module is an optparse-inspired command-line parsing library that:
- handles both optional and positional arguments
- produces highly informative usage messages
- supports parsers that dispatch to sub-parsers
The following is a simple usage example that sums integers from the
command-line and writes the result to a file::
parser = argparse.ArgumentParser(
description='sum the integers at the command line')
parser.add_argument(
'integers', metavar='int', nargs='+', type=int,
help='an integer to be summed')
parser.add_argument(
'--log', default=sys.stdout, type=argparse.FileType('w'),
help='the file where the sum should be written')
args = parser.parse_args()
args.log.write('%s' % sum(args.integers))
args.log.close()
The module contains the following public classes:
- ArgumentParser -- The main entry point for command-line parsing. As the
example above shows, the add_argument() method is used to populate
the parser with actions for optional and positional arguments. Then
the parse_args() method is invoked to convert the args at the
command-line into an object with attributes.
- ArgumentError -- The exception raised by ArgumentParser objects when
there are errors with the parser's actions. Errors raised while
parsing the command-line are caught by ArgumentParser and emitted
as command-line messages.
- FileType -- A factory for defining types of files to be created. As the
example above shows, instances of FileType are typically passed as
the type= argument of add_argument() calls.
- Action -- The base class for parser actions. Typically actions are
selected by passing strings like 'store_true' or 'append_const' to
the action= argument of add_argument(). However, for greater
customization of ArgumentParser actions, subclasses of Action may
be defined and passed as the action= argument.
- HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter,
ArgumentDefaultsHelpFormatter -- Formatter classes which
may be passed as the formatter_class= argument to the
ArgumentParser constructor. HelpFormatter is the default,
RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser
not to change the formatting for help text, and
ArgumentDefaultsHelpFormatter adds information about argument defaults
to the help.
All other classes in this module are considered implementation details.
(Also note that HelpFormatter and RawDescriptionHelpFormatter are only
considered public as object names -- the API of the formatter objects is
still considered an implementation detail.)
"""
__version__ = '1.2.1'
__all__ = [
'ArgumentParser',
'ArgumentError',
'ArgumentTypeError',
'FileType',
'HelpFormatter',
'ArgumentDefaultsHelpFormatter',
'RawDescriptionHelpFormatter',
'RawTextHelpFormatter',
'Namespace',
'Action',
'ONE_OR_MORE',
'OPTIONAL',
'PARSER',
'REMAINDER',
'SUPPRESS',
'ZERO_OR_MORE',
]
import copy as _copy
import os as _os
import re as _re
import sys as _sys
import textwrap as _textwrap
from gettext import gettext as _
try:
set
except NameError:
# for python < 2.4 compatibility (sets module is there since 2.3):
from sets import Set as set
try:
basestring
except NameError:
basestring = str
try:
sorted
except NameError:
# for python < 2.4 compatibility:
def sorted(iterable, reverse=False):
result = list(iterable)
result.sort()
if reverse:
result.reverse()
return result
def _callable(obj):
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
SUPPRESS = '==SUPPRESS=='
OPTIONAL = '?'
ZERO_OR_MORE = '*'
ONE_OR_MORE = '+'
PARSER = 'A...'
REMAINDER = '...'
_UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'
# =============================
# Utility functions and classes
# =============================
class _AttributeHolder(object):
"""Abstract base class that provides __repr__.
The __repr__ method returns a string in the format::
ClassName(attr=name, attr=name, ...)
The attributes are determined either by a class-level attribute,
'_kwarg_names', or by inspecting the instance __dict__.
"""
def __repr__(self):
type_name = type(self).__name__
arg_strings = []
for arg in self._get_args():
arg_strings.append(repr(arg))
for name, value in self._get_kwargs():
arg_strings.append('%s=%r' % (name, value))
return '%s(%s)' % (type_name, ', '.join(arg_strings))
def _get_kwargs(self):
return sorted(self.__dict__.items())
def _get_args(self):
return []
def _ensure_value(namespace, name, value):
if getattr(namespace, name, None) is None:
setattr(namespace, name, value)
return getattr(namespace, name)
# ===============
# Formatting Help
# ===============
class HelpFormatter(object):
"""Formatter for generating usage messages and argument help strings.
Only the name of this class is considered a public API. All the methods
provided by the class are considered an implementation detail.
"""
def __init__(self,
prog,
indent_increment=2,
max_help_position=24,
width=None):
# default setting for width
if width is None:
try:
width = int(_os.environ['COLUMNS'])
except (KeyError, ValueError):
width = 80
width -= 2
self._prog = prog
self._indent_increment = indent_increment
self._max_help_position = max_help_position
self._width = width
self._current_indent = 0
self._level = 0
self._action_max_length = 0
self._root_section = self._Section(self, None)
self._current_section = self._root_section
self._whitespace_matcher = _re.compile(r'\s+')
self._long_break_matcher = _re.compile(r'\n\n\n+')
# ===============================
# Section and indentation methods
# ===============================
def _indent(self):
self._current_indent += self._indent_increment
self._level += 1
def _dedent(self):
self._current_indent -= self._indent_increment
assert self._current_indent >= 0, 'Indent decreased below 0.'
self._level -= 1
class _Section(object):
def __init__(self, formatter, parent, heading=None):
self.formatter = formatter
self.parent = parent
self.heading = heading
self.items = []
def format_help(self):
# format the indented section
if self.parent is not None:
self.formatter._indent()
join = self.formatter._join_parts
for func, args in self.items:
func(*args)
item_help = join([func(*args) for func, args in self.items])
if self.parent is not None:
self.formatter._dedent()
# return nothing if the section was empty
if not item_help:
return ''
# add the heading if the section was non-empty
if self.heading is not SUPPRESS and self.heading is not None:
current_indent = self.formatter._current_indent
heading = '%*s%s:\n' % (current_indent, '', self.heading)
else:
heading = ''
# join the section-initial newline, the heading and the help
return join(['\n', heading, item_help, '\n'])
def _add_item(self, func, args):
self._current_section.items.append((func, args))
# ========================
# Message building methods
# ========================
def start_section(self, heading):
self._indent()
section = self._Section(self, self._current_section, heading)
self._add_item(section.format_help, [])
self._current_section = section
def end_section(self):
self._current_section = self._current_section.parent
self._dedent()
def add_text(self, text):
if text is not SUPPRESS and text is not None:
self._add_item(self._format_text, [text])
def add_usage(self, usage, actions, groups, prefix=None):
if usage is not SUPPRESS:
args = usage, actions, groups, prefix
self._add_item(self._format_usage, args)
def add_argument(self, action):
if action.help is not SUPPRESS:
# find all invocations
get_invocation = self._format_action_invocation
invocations = [get_invocation(action)]
for subaction in self._iter_indented_subactions(action):
invocations.append(get_invocation(subaction))
# update the maximum item length
invocation_length = max([len(s) for s in invocations])
action_length = invocation_length + self._current_indent
self._action_max_length = max(self._action_max_length,
action_length)
# add the item to the list
self._add_item(self._format_action, [action])
def add_arguments(self, actions):
for action in actions:
self.add_argument(action)
# =======================
# Help-formatting methods
# =======================
def format_help(self):
help = self._root_section.format_help()
if help:
help = self._long_break_matcher.sub('\n\n', help)
help = help.strip('\n') + '\n'
return help
def _join_parts(self, part_strings):
return ''.join([part
for part in part_strings
if part and part is not SUPPRESS])
def _format_usage(self, usage, actions, groups, prefix):
if prefix is None:
prefix = _('usage: ')
# if usage is specified, use that
if usage is not None:
usage = usage % dict(prog=self._prog)
# if no optionals or positionals are available, usage is just prog
elif usage is None and not actions:
usage = '%(prog)s' % dict(prog=self._prog)
# if optionals and positionals are available, calculate usage
elif usage is None:
prog = '%(prog)s' % dict(prog=self._prog)
# split optionals from positionals
optionals = []
positionals = []
for action in actions:
if action.option_strings:
optionals.append(action)
else:
positionals.append(action)
# build full usage string
format = self._format_actions_usage
action_usage = format(optionals + positionals, groups)
usage = ' '.join([s for s in [prog, action_usage] if s])
# wrap the usage parts if it's too long
text_width = self._width - self._current_indent
if len(prefix) + len(usage) > text_width:
# break usage into wrappable parts
part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
opt_usage = format(optionals, groups)
pos_usage = format(positionals, groups)
opt_parts = _re.findall(part_regexp, opt_usage)
pos_parts = _re.findall(part_regexp, pos_usage)
assert ' '.join(opt_parts) == opt_usage
assert ' '.join(pos_parts) == pos_usage
# helper for wrapping lines
def get_lines(parts, indent, prefix=None):
lines = []
line = []
if prefix is not None:
line_len = len(prefix) - 1
else:
line_len = len(indent) - 1
for part in parts:
if line_len + 1 + len(part) > text_width:
lines.append(indent + ' '.join(line))
line = []
line_len = len(indent) - 1
line.append(part)
line_len += len(part) + 1
if line:
lines.append(indent + ' '.join(line))
if prefix is not None:
lines[0] = lines[0][len(indent):]
return lines
# if prog is short, follow it with optionals or positionals
if len(prefix) + len(prog) <= 0.75 * text_width:
indent = ' ' * (len(prefix) + len(prog) + 1)
if opt_parts:
lines = get_lines([prog] + opt_parts, indent, prefix)
lines.extend(get_lines(pos_parts, indent))
elif pos_parts:
lines = get_lines([prog] + pos_parts, indent, prefix)
else:
lines = [prog]
# if prog is long, put it on its own line
else:
indent = ' ' * len(prefix)
parts = opt_parts + pos_parts
lines = get_lines(parts, indent)
if len(lines) > 1:
lines = []
lines.extend(get_lines(opt_parts, indent))
lines.extend(get_lines(pos_parts, indent))
lines = [prog] + lines
# join lines into usage
usage = '\n'.join(lines)
# prefix with 'usage:'
return '%s%s\n\n' % (prefix, usage)
def _format_actions_usage(self, actions, groups):
# find group indices and identify actions in groups
group_actions = set()
inserts = {}
for group in groups:
try:
start = actions.index(group._group_actions[0])
except ValueError:
continue
else:
end = start + len(group._group_actions)
if actions[start:end] == group._group_actions:
for action in group._group_actions:
group_actions.add(action)
if not group.required:
if start in inserts:
inserts[start] += ' ['
else:
inserts[start] = '['
inserts[end] = ']'
else:
if start in inserts:
inserts[start] += ' ('
else:
inserts[start] = '('
inserts[end] = ')'
for i in range(start + 1, end):
inserts[i] = '|'
# collect all actions format strings
parts = []
for i, action in enumerate(actions):
# suppressed arguments are marked with None
# remove | separators for suppressed arguments
if action.help is SUPPRESS:
parts.append(None)
if inserts.get(i) == '|':
inserts.pop(i)
elif inserts.get(i + 1) == '|':
inserts.pop(i + 1)
# produce all arg strings
elif not action.option_strings:
part = self._format_args(action, action.dest)
# if it's in a group, strip the outer []
if action in group_actions:
if part[0] == '[' and part[-1] == ']':
part = part[1:-1]
# add the action string to the list
parts.append(part)
# produce the first way to invoke the option in brackets
else:
option_string = action.option_strings[0]
# if the Optional doesn't take a value, format is:
# -s or --long
if action.nargs == 0:
part = '%s' % option_string
# if the Optional takes a value, format is:
# -s ARGS or --long ARGS
else:
default = action.dest.upper()
args_string = self._format_args(action, default)
part = '%s %s' % (option_string, args_string)
# make it look optional if it's not required or in a group
if not action.required and action not in group_actions:
part = '[%s]' % part
# add the action string to the list
parts.append(part)
# insert things at the necessary indices
for i in sorted(inserts, reverse=True):
parts[i:i] = [inserts[i]]
# join all the action items with spaces
text = ' '.join([item for item in parts if item is not None])
# clean up separators for mutually exclusive groups
open = r'[\[(]'
close = r'[\])]'
text = _re.sub(r'(%s) ' % open, r'\1', text)
text = _re.sub(r' (%s)' % close, r'\1', text)
text = _re.sub(r'%s *%s' % (open, close), r'', text)
text = _re.sub(r'\(([^|]*)\)', r'\1', text)
text = text.strip()
# return the text
return text
def _format_text(self, text):
if '%(prog)' in text:
text = text % dict(prog=self._prog)
text_width = self._width - self._current_indent
indent = ' ' * self._current_indent
return self._fill_text(text, text_width, indent) + '\n\n'
def _format_action(self, action):
# determine the required width and the entry label
help_position = min(self._action_max_length + 2,
self._max_help_position)
help_width = self._width - help_position
action_width = help_position - self._current_indent - 2
action_header = self._format_action_invocation(action)
# ho nelp; start on same line and add a final newline
if not action.help:
tup = self._current_indent, '', action_header
action_header = '%*s%s\n' % tup
# short action name; start on the same line and pad two spaces
elif len(action_header) <= action_width:
tup = self._current_indent, '', action_width, action_header
action_header = '%*s%-*s ' % tup
indent_first = 0
# long action name; start on the next line
else:
tup = self._current_indent, '', action_header
action_header = '%*s%s\n' % tup
indent_first = help_position
# collect the pieces of the action help
parts = [action_header]
# if there was help for the action, add lines of help text
if action.help:
help_text = self._expand_help(action)
help_lines = self._split_lines(help_text, help_width)
parts.append('%*s%s\n' % (indent_first, '', help_lines[0]))
for line in help_lines[1:]:
parts.append('%*s%s\n' % (help_position, '', line))
# or add a newline if the description doesn't end with one
elif not action_header.endswith('\n'):
parts.append('\n')
# if there are any sub-actions, add their help as well
for subaction in self._iter_indented_subactions(action):
parts.append(self._format_action(subaction))
# return a single string
return self._join_parts(parts)
def _format_action_invocation(self, action):
if not action.option_strings:
metavar, = self._metavar_formatter(action, action.dest)(1)
return metavar
else:
parts = []
# if the Optional doesn't take a value, format is:
# -s, --long
if action.nargs == 0:
parts.extend(action.option_strings)
# if the Optional takes a value, format is:
# -s ARGS, --long ARGS
else:
default = action.dest.upper()
args_string = self._format_args(action, default)
for option_string in action.option_strings:
parts.append('%s %s' % (option_string, args_string))
return ', '.join(parts)
def _metavar_formatter(self, action, default_metavar):
if action.metavar is not None:
result = action.metavar
elif action.choices is not None:
choice_strs = [str(choice) for choice in action.choices]
result = '{%s}' % ','.join(choice_strs)
else:
result = default_metavar
def format(tuple_size):
if isinstance(result, tuple):
return result
else:
return (result, ) * tuple_size
return format
def _format_args(self, action, default_metavar):
get_metavar = self._metavar_formatter(action, default_metavar)
if action.nargs is None:
result = '%s' % get_metavar(1)
elif action.nargs == OPTIONAL:
result = '[%s]' % get_metavar(1)
elif action.nargs == ZERO_OR_MORE:
result = '[%s [%s ...]]' % get_metavar(2)
elif action.nargs == ONE_OR_MORE:
result = '%s [%s ...]' % get_metavar(2)
elif action.nargs == REMAINDER:
result = '...'
elif action.nargs == PARSER:
result = '%s ...' % get_metavar(1)
else:
formats = ['%s' for _ in range(action.nargs)]
result = ' '.join(formats) % get_metavar(action.nargs)
return result
def _expand_help(self, action):
params = dict(vars(action), prog=self._prog)
for name in list(params):
if params[name] is SUPPRESS:
del params[name]
for name in list(params):
if hasattr(params[name], '__name__'):
params[name] = params[name].__name__
if params.get('choices') is not None:
choices_str = ', '.join([str(c) for c in params['choices']])
params['choices'] = choices_str
return self._get_help_string(action) % params
def _iter_indented_subactions(self, action):
try:
get_subactions = action._get_subactions
except AttributeError:
pass
else:
self._indent()
for subaction in get_subactions():
yield subaction
self._dedent()
def _split_lines(self, text, width):
text = self._whitespace_matcher.sub(' ', text).strip()
return _textwrap.wrap(text, width)
def _fill_text(self, text, width, indent):
text = self._whitespace_matcher.sub(' ', text).strip()
return _textwrap.fill(text, width, initial_indent=indent,
subsequent_indent=indent)
def _get_help_string(self, action):
return action.help
class RawDescriptionHelpFormatter(HelpFormatter):
"""Help message formatter which retains any formatting in descriptions.
Only the name of this class is considered a public API. All the methods
provided by the class are considered an implementation detail.
"""
def _fill_text(self, text, width, indent):
return ''.join([indent + line for line in text.splitlines(True)])
class RawTextHelpFormatter(RawDescriptionHelpFormatter):
"""Help message formatter which retains formatting of all help text.
Only the name of this class is considered a public API. All the methods
provided by the class are considered an implementation detail.
"""
def _split_lines(self, text, width):
return text.splitlines()
class ArgumentDefaultsHelpFormatter(HelpFormatter):
"""Help message formatter which adds default values to argument help.
Only the name of this class is considered a public API. All the methods
provided by the class are considered an implementation detail.
"""
def _get_help_string(self, action):
help = action.help
if '%(default)' not in action.help:
if action.default is not SUPPRESS:
defaulting_nargs = [OPTIONAL, ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
help += ' (default: %(default)s)'
return help
# =====================
# Options and Arguments
# =====================
def _get_action_name(argument):
if argument is None:
return None
elif argument.option_strings:
return '/'.join(argument.option_strings)
elif argument.metavar not in (None, SUPPRESS):
return argument.metavar
elif argument.dest not in (None, SUPPRESS):
return argument.dest
else:
return None
class ArgumentError(Exception):
"""An error from creating or using an argument (optional or positional).
The string value of this exception is the message, augmented with
information about the argument that caused it.
"""
def __init__(self, argument, message):
self.argument_name = _get_action_name(argument)
self.message = message
def __str__(self):
if self.argument_name is None:
format = '%(message)s'
else:
format = 'argument %(argument_name)s: %(message)s'
return format % dict(message=self.message,
argument_name=self.argument_name)
class ArgumentTypeError(Exception):
"""An error from trying to convert a command line string to a type."""
pass
# ==============
# Action classes
# ==============
class Action(_AttributeHolder):
"""Information about how to convert command line strings to Python objects.
Action objects are used by an ArgumentParser to represent the information
needed to parse a single argument from one or more strings from the
command line. The keyword arguments to the Action constructor are also
all attributes of Action instances.
Keyword Arguments:
- option_strings -- A list of command-line option strings which
should be associated with this action.
- dest -- The name of the attribute to hold the created object(s)
- nargs -- The number of command-line arguments that should be
consumed. By default, one argument will be consumed and a single
value will be produced. Other values include:
- N (an integer) consumes N arguments (and produces a list)
- '?' consumes zero or one arguments
- '*' consumes zero or more arguments (and produces a list)
- '+' consumes one or more arguments (and produces a list)
Note that the difference between the default and nargs=1 is that
with the default, a single value will be produced, while with
nargs=1, a list containing a single value will be produced.
- const -- The value to be produced if the option is specified and the
option uses an action that takes no values.
- default -- The value to be produced if the option is not specified.
- type -- The type which the command-line arguments should be converted
to, should be one of 'string', 'int', 'float', 'complex' or a
callable object that accepts a single string argument. If None,
'string' is assumed.
- choices -- A container of values that should be allowed. If not None,
after a command-line argument has been converted to the appropriate
type, an exception will be raised if it is not a member of this
collection.
- required -- True if the action must always be specified at the
command line. This is only meaningful for optional command-line
arguments.
- help -- The help string describing the argument.
- metavar -- The name to be used for the option's argument with the
help string. If None, the 'dest' value will be used as the name.
"""
def __init__(self,
option_strings,
dest,
nargs=None,
const=None,
default=None,
type=None,
choices=None,
required=False,
help=None,
metavar=None):
self.option_strings = option_strings
self.dest = dest
self.nargs = nargs
self.const = const
self.default = default
self.type = type
self.choices = choices
self.required = required
self.help = help
self.metavar = metavar
def _get_kwargs(self):
names = [
'option_strings',
'dest',
'nargs',
'const',
'default',
'type',
'choices',
'help',
'metavar',
]
return [(name, getattr(self, name)) for name in names]
def __call__(self, parser, namespace, values, option_string=None):
raise NotImplementedError(_('.__call__() not defined'))
class _StoreAction(Action):
def __init__(self,
option_strings,
dest,
nargs=None,
const=None,
default=None,
type=None,
choices=None,
required=False,
help=None,
metavar=None):
if nargs == 0:
raise ValueError('nargs for store actions must be > 0; if you '
'have nothing to store, actions such as store '
'true or store const may be more appropriate')
if const is not None and nargs != OPTIONAL:
raise ValueError('nargs must be %r to supply const' % OPTIONAL)
super(_StoreAction, self).__init__(
option_strings=option_strings,
dest=dest,
nargs=nargs,
const=const,
default=default,
type=type,
choices=choices,
required=required,
help=help,
metavar=metavar)
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values)
class _StoreConstAction(Action):
def __init__(self,
option_strings,
dest,
const,
default=None,
required=False,
help=None,
metavar=None):
super(_StoreConstAction, self).__init__(
option_strings=option_strings,
dest=dest,
nargs=0,
const=const,
default=default,
required=required,
help=help)
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, self.const)
class _StoreTrueAction(_StoreConstAction):
def __init__(self,
option_strings,
dest,
default=False,
required=False,
help=None):
super(_StoreTrueAction, self).__init__(
option_strings=option_strings,
dest=dest,
const=True,
default=default,
required=required,
help=help)
class _StoreFalseAction(_StoreConstAction):
def __init__(self,
option_strings,
dest,
default=True,
required=False,
help=None):
super(_StoreFalseAction, self).__init__(
option_strings=option_strings,
dest=dest,
const=False,
default=default,
required=required,
help=help)
class _AppendAction(Action):
def __init__(self,
option_strings,
dest,
nargs=None,
const=None,
default=None,
type=None,
choices=None,
required=False,
help=None,
metavar=None):
if nargs == 0:
raise ValueError('nargs for append actions must be > 0; if arg '
'strings are not supplying the value to append, '
'the append const action may be more appropriate')
if const is not None and nargs != OPTIONAL:
raise ValueError('nargs must be %r to supply const' % OPTIONAL)
super(_AppendAction, self).__init__(
option_strings=option_strings,
dest=dest,
nargs=nargs,
const=const,
default=default,
type=type,
choices=choices,
required=required,
help=help,
metavar=metavar)
def __call__(self, parser, namespace, values, option_string=None):
items = _copy.copy(_ensure_value(namespace, self.dest, []))
items.append(values)
setattr(namespace, self.dest, items)
class _AppendConstAction(Action):
def __init__(self,
option_strings,
dest,
const,
default=None,
required=False,
help=None,
metavar=None):
super(_AppendConstAction, self).__init__(
option_strings=option_strings,
dest=dest,
nargs=0,
const=const,
default=default,
required=required,
help=help,
metavar=metavar)
def __call__(self, parser, namespace, values, option_string=None):
items = _copy.copy(_ensure_value(namespace, self.dest, []))
items.append(self.const)
setattr(namespace, self.dest, items)
class _CountAction(Action):
def __init__(self,
option_strings,
dest,
default=None,
required=False,
help=None):
super(_CountAction, self).__init__(
option_strings=option_strings,
dest=dest,
nargs=0,
default=default,
required=required,
help=help)
def __call__(self, parser, namespace, values, option_string=None):
new_count = _ensure_value(namespace, self.dest, 0) + 1
setattr(namespace, self.dest, new_count)
class _HelpAction(Action):
def __init__(self,
option_strings,
dest=SUPPRESS,
default=SUPPRESS,
help=None):
super(_HelpAction, self).__init__(
option_strings=option_strings,
dest=dest,
default=default,
nargs=0,
help=help)
def __call__(self, parser, namespace, values, option_string=None):
parser.print_help()
parser.exit()
class _VersionAction(Action):
def __init__(self,
option_strings,
version=None,
dest=SUPPRESS,
default=SUPPRESS,
help="show program's version number and exit"):
super(_VersionAction, self).__init__(
option_strings=option_strings,
dest=dest,
default=default,
nargs=0,
help=help)
self.version = version
def __call__(self, parser, namespace, values, option_string=None):
version = self.version
if version is None:
version = parser.version
formatter = parser._get_formatter()
formatter.add_text(version)
parser.exit(message=formatter.format_help())
class _SubParsersAction(Action):
class _ChoicesPseudoAction(Action):
def __init__(self, name, help):
sup = super(_SubParsersAction._ChoicesPseudoAction, self)
sup.__init__(option_strings=[], dest=name, help=help)
def __init__(self,
option_strings,
prog,
parser_class,
dest=SUPPRESS,
help=None,
metavar=None):
self._prog_prefix = prog
self._parser_class = parser_class
self._name_parser_map = {}
self._choices_actions = []
super(_SubParsersAction, self).__init__(
option_strings=option_strings,
dest=dest,
nargs=PARSER,
choices=self._name_parser_map,
help=help,
metavar=metavar)
def add_parser(self, name, **kwargs):
# set prog from the existing prefix
if kwargs.get('prog') is None:
kwargs['prog'] = '%s %s' % (self._prog_prefix, name)
# create a pseudo-action to hold the choice help
if 'help' in kwargs:
help = kwargs.pop('help')
choice_action = self._ChoicesPseudoAction(name, help)
self._choices_actions.append(choice_action)
# create the parser and add it to the map
parser = self._parser_class(**kwargs)
self._name_parser_map[name] = parser
return parser
def _get_subactions(self):
return self._choices_actions
def __call__(self, parser, namespace, values, option_string=None):
parser_name = values[0]
arg_strings = values[1:]
# set the parser name if requested
if self.dest is not SUPPRESS:
setattr(namespace, self.dest, parser_name)
# select the parser
try:
parser = self._name_parser_map[parser_name]
except KeyError:
tup = parser_name, ', '.join(self._name_parser_map)
msg = _('unknown parser %r (choices: %s)' % tup)
raise ArgumentError(self, msg)
# parse all the remaining options into the namespace
# store any unrecognized options on the object, so that the top
# level parser can decide what to do with them
namespace, arg_strings = parser.parse_known_args(arg_strings, namespace)
if arg_strings:
vars(namespace).setdefault(_UNRECOGNIZED_ARGS_ATTR, [])
getattr(namespace, _UNRECOGNIZED_ARGS_ATTR).extend(arg_strings)
# ==============
# Type classes
# ==============
class FileType(object):
"""Factory for creating file object types
Instances of FileType are typically passed as type= arguments to the
ArgumentParser add_argument() method.
Keyword Arguments:
- mode -- A string indicating how the file is to be opened. Accepts the
same values as the builtin open() function.
- bufsize -- The file's desired buffer size. Accepts the same values as
the builtin open() function.
"""
def __init__(self, mode='r', bufsize=None):
self._mode = mode
self._bufsize = bufsize
def __call__(self, string):
# the special argument "-" means sys.std{in,out}
if string == '-':
if 'r' in self._mode:
return _sys.stdin
elif 'w' in self._mode:
return _sys.stdout
else:
msg = _('argument "-" with mode %r' % self._mode)
raise ValueError(msg)
# all other arguments are used as file names
if self._bufsize:
return open(string, self._mode, self._bufsize)
else:
return open(string, self._mode)
def __repr__(self):
args = [self._mode, self._bufsize]
args_str = ', '.join([repr(arg) for arg in args if arg is not None])
return '%s(%s)' % (type(self).__name__, args_str)
# ===========================
# Optional and Positional Parsing
# ===========================
class Namespace(_AttributeHolder):
"""Simple object for storing attributes.
Implements equality by attribute names and values, and provides a simple
string representation.
"""
def __init__(self, **kwargs):
for name in kwargs:
setattr(self, name, kwargs[name])
__hash__ = None
def __eq__(self, other):
return vars(self) == vars(other)
def __ne__(self, other):
return not (self == other)
def __contains__(self, key):
return key in self.__dict__
class _ActionsContainer(object):
def __init__(self,
description,
prefix_chars,
argument_default,
conflict_handler):
super(_ActionsContainer, self).__init__()
self.description = description
self.argument_default = argument_default
self.prefix_chars = prefix_chars
self.conflict_handler = conflict_handler
# set up registries
self._registries = {}
# register actions
self.register('action', None, _StoreAction)
self.register('action', 'store', _StoreAction)
self.register('action', 'store_const', _StoreConstAction)
self.register('action', 'store_true', _StoreTrueAction)
self.register('action', 'store_false', _StoreFalseAction)
self.register('action', 'append', _AppendAction)
self.register('action', 'append_const', _AppendConstAction)
self.register('action', 'count', _CountAction)
self.register('action', 'help', _HelpAction)
self.register('action', 'version', _VersionAction)
self.register('action', 'parsers', _SubParsersAction)
# raise an exception if the conflict handler is invalid
self._get_handler()
# action storage
self._actions = []
self._option_string_actions = {}
# groups
self._action_groups = []
self._mutually_exclusive_groups = []
# defaults storage
self._defaults = {}
# determines whether an "option" looks like a negative number
self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$')
# whether or not there are any optionals that look like negative
# numbers -- uses a list so it can be shared and edited
self._has_negative_number_optionals = []
# ====================
# Registration methods
# ====================
def register(self, registry_name, value, object):
registry = self._registries.setdefault(registry_name, {})
registry[value] = object
def _registry_get(self, registry_name, value, default=None):
return self._registries[registry_name].get(value, default)
# ==================================
# Namespace default accessor methods
# ==================================
def set_defaults(self, **kwargs):
self._defaults.update(kwargs)
# if these defaults match any existing arguments, replace
# the previous default on the object with the new one
for action in self._actions:
if action.dest in kwargs:
action.default = kwargs[action.dest]
def get_default(self, dest):
for action in self._actions:
if action.dest == dest and action.default is not None:
return action.default
return self._defaults.get(dest, None)
# =======================
# Adding argument actions
# =======================
def add_argument(self, *args, **kwargs):
"""
add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...)
"""
# if no positional args are supplied or only one is supplied and
# it doesn't look like an option string, parse a positional
# argument
chars = self.prefix_chars
if not args or len(args) == 1 and args[0][0] not in chars:
if args and 'dest' in kwargs:
raise ValueError('dest supplied twice for positional argument')
kwargs = self._get_positional_kwargs(*args, **kwargs)
# otherwise, we're adding an optional argument
else:
kwargs = self._get_optional_kwargs(*args, **kwargs)
# if no default was supplied, use the parser-level default
if 'default' not in kwargs:
dest = kwargs['dest']
if dest in self._defaults:
kwargs['default'] = self._defaults[dest]
elif self.argument_default is not None:
kwargs['default'] = self.argument_default
# create the action object, and add it to the parser
action_class = self._pop_action_class(kwargs)
if not _callable(action_class):
raise ValueError('unknown action "%s"' % action_class)
action = action_class(**kwargs)
# raise an error if the action type is not callable
type_func = self._registry_get('type', action.type, action.type)
if not _callable(type_func):
raise ValueError('%r is not callable' % type_func)
return self._add_action(action)
def add_argument_group(self, *args, **kwargs):
group = _ArgumentGroup(self, *args, **kwargs)
self._action_groups.append(group)
return group
def add_mutually_exclusive_group(self, **kwargs):
group = _MutuallyExclusiveGroup(self, **kwargs)
self._mutually_exclusive_groups.append(group)
return group
def _add_action(self, action):
# resolve any conflicts
self._check_conflict(action)
# add to actions list
self._actions.append(action)
action.container = self
# index the action by any option strings it has
for option_string in action.option_strings:
self._option_string_actions[option_string] = action
# set the flag if any option strings look like negative numbers
for option_string in action.option_strings:
if self._negative_number_matcher.match(option_string):
if not self._has_negative_number_optionals:
self._has_negative_number_optionals.append(True)
# return the created action
return action
def _remove_action(self, action):
self._actions.remove(action)
def _add_container_actions(self, container):
# collect groups by titles
title_group_map = {}
for group in self._action_groups:
if group.title in title_group_map:
msg = _('cannot merge actions - two groups are named %r')
raise ValueError(msg % (group.title))
title_group_map[group.title] = group
# map each action to its group
group_map = {}
for group in container._action_groups:
# if a group with the title exists, use that, otherwise
# create a new group matching the container's group
if group.title not in title_group_map:
title_group_map[group.title] = self.add_argument_group(
title=group.title,
description=group.description,
conflict_handler=group.conflict_handler)
# map the actions to their new group
for action in group._group_actions:
group_map[action] = title_group_map[group.title]
# add container's mutually exclusive groups
# NOTE: if add_mutually_exclusive_group ever gains title= and
# description= then this code will need to be expanded as above
for group in container._mutually_exclusive_groups:
mutex_group = self.add_mutually_exclusive_group(
required=group.required)
# map the actions to their new mutex group
for action in group._group_actions:
group_map[action] = mutex_group
# add all actions to this container or their group
for action in container._actions:
group_map.get(action, self)._add_action(action)
def _get_positional_kwargs(self, dest, **kwargs):
# make sure required is not specified
if 'required' in kwargs:
msg = _("'required' is an invalid argument for positionals")
raise TypeError(msg)
# mark positional arguments as required if at least one is
# always required
if kwargs.get('nargs') not in [OPTIONAL, ZERO_OR_MORE]:
kwargs['required'] = True
if kwargs.get('nargs') == ZERO_OR_MORE and 'default' not in kwargs:
kwargs['required'] = True
# return the keyword arguments with no option strings
return dict(kwargs, dest=dest, option_strings=[])
def _get_optional_kwargs(self, *args, **kwargs):
# determine short and long option strings
option_strings = []
long_option_strings = []
for option_string in args:
# error on strings that don't start with an appropriate prefix
if not option_string[0] in self.prefix_chars:
msg = _('invalid option string %r: '
'must start with a character %r')
tup = option_string, self.prefix_chars
raise ValueError(msg % tup)
# strings starting with two prefix characters are long options
option_strings.append(option_string)
if option_string[0] in self.prefix_chars:
if len(option_string) > 1:
if option_string[1] in self.prefix_chars:
long_option_strings.append(option_string)
# infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
dest = kwargs.pop('dest', None)
if dest is None:
if long_option_strings:
dest_option_string = long_option_strings[0]
else:
dest_option_string = option_strings[0]
dest = dest_option_string.lstrip(self.prefix_chars)
if not dest:
msg = _('dest= is required for options like %r')
raise ValueError(msg % option_string)
dest = dest.replace('-', '_')
# return the updated keyword arguments
return dict(kwargs, dest=dest, option_strings=option_strings)
def _pop_action_class(self, kwargs, default=None):
action = kwargs.pop('action', default)
return self._registry_get('action', action, action)
def _get_handler(self):
# determine function from conflict handler string
handler_func_name = '_handle_conflict_%s' % self.conflict_handler
try:
return getattr(self, handler_func_name)
except AttributeError:
msg = _('invalid conflict_resolution value: %r')
raise ValueError(msg % self.conflict_handler)
def _check_conflict(self, action):
# find all options that conflict with this option
confl_optionals = []
for option_string in action.option_strings:
if option_string in self._option_string_actions:
confl_optional = self._option_string_actions[option_string]
confl_optionals.append((option_string, confl_optional))
# resolve any conflicts
if confl_optionals:
conflict_handler = self._get_handler()
conflict_handler(action, confl_optionals)
def _handle_conflict_error(self, action, conflicting_actions):
message = _('conflicting option string(s): %s')
conflict_string = ', '.join([option_string
for option_string, action
in conflicting_actions])
raise ArgumentError(action, message % conflict_string)
def _handle_conflict_resolve(self, action, conflicting_actions):
# remove all conflicting options
for option_string, action in conflicting_actions:
# remove the conflicting option
action.option_strings.remove(option_string)
self._option_string_actions.pop(option_string, None)
# if the option now has no option string, remove it from the
# container holding it
if not action.option_strings:
action.container._remove_action(action)
class _ArgumentGroup(_ActionsContainer):
def __init__(self, container, title=None, description=None, **kwargs):
# add any missing keyword arguments by checking the container
update = kwargs.setdefault
update('conflict_handler', container.conflict_handler)
update('prefix_chars', container.prefix_chars)
update('argument_default', container.argument_default)
super_init = super(_ArgumentGroup, self).__init__
super_init(description=description, **kwargs)
# group attributes
self.title = title
self._group_actions = []
# share most attributes with the container
self._registries = container._registries
self._actions = container._actions
self._option_string_actions = container._option_string_actions
self._defaults = container._defaults
self._has_negative_number_optionals = \
container._has_negative_number_optionals
def _add_action(self, action):
action = super(_ArgumentGroup, self)._add_action(action)
self._group_actions.append(action)
return action
def _remove_action(self, action):
super(_ArgumentGroup, self)._remove_action(action)
self._group_actions.remove(action)
class _MutuallyExclusiveGroup(_ArgumentGroup):
def __init__(self, container, required=False):
super(_MutuallyExclusiveGroup, self).__init__(container)
self.required = required
self._container = container
def _add_action(self, action):
if action.required:
msg = _('mutually exclusive arguments must be optional')
raise ValueError(msg)
action = self._container._add_action(action)
self._group_actions.append(action)
return action
def _remove_action(self, action):
self._container._remove_action(action)
self._group_actions.remove(action)
class ArgumentParser(_AttributeHolder, _ActionsContainer):
"""Object for parsing command line strings into Python objects.
Keyword Arguments:
- prog -- The name of the program (default: sys.argv[0])
- usage -- A usage message (default: auto-generated from arguments)
- description -- A description of what the program does
- epilog -- Text following the argument descriptions
- parents -- Parsers whose arguments should be copied into this one
- formatter_class -- HelpFormatter class for printing help messages
- prefix_chars -- Characters that prefix optional arguments
- fromfile_prefix_chars -- Characters that prefix files containing
additional arguments
- argument_default -- The default value for all arguments
- conflict_handler -- String indicating how to handle conflicts
- add_help -- Add a -h/-help option
"""
def __init__(self,
prog=None,
usage=None,
description=None,
epilog=None,
version=None,
parents=[],
formatter_class=HelpFormatter,
prefix_chars='-',
fromfile_prefix_chars=None,
argument_default=None,
conflict_handler='error',
add_help=True):
if version is not None:
import warnings
warnings.warn(
"""The "version" argument to ArgumentParser is deprecated. """
"""Please use """
""""add_argument(..., action='version', version="N", ...)" """
"""instead""", DeprecationWarning)
superinit = super(ArgumentParser, self).__init__
superinit(description=description,
prefix_chars=prefix_chars,
argument_default=argument_default,
conflict_handler=conflict_handler)
# default setting for prog
if prog is None:
prog = _os.path.basename(_sys.argv[0])
self.prog = prog
self.usage = usage
self.epilog = epilog
self.version = version
self.formatter_class = formatter_class
self.fromfile_prefix_chars = fromfile_prefix_chars
self.add_help = add_help
add_group = self.add_argument_group
self._positionals = add_group(_('positional arguments'))
self._optionals = add_group(_('optional arguments'))
self._subparsers = None
# register types
def identity(string):
return string
self.register('type', None, identity)
# add help and version arguments if necessary
# (using explicit default to override global argument_default)
if '-' in prefix_chars:
default_prefix = '-'
else:
default_prefix = prefix_chars[0]
if self.add_help:
self.add_argument(
default_prefix+'h', default_prefix*2+'help',
action='help', default=SUPPRESS,
help=_('show this help message and exit'))
if self.version:
self.add_argument(
default_prefix+'v', default_prefix*2+'version',
action='version', default=SUPPRESS,
version=self.version,
help=_("show program's version number and exit"))
# add parent arguments and defaults
for parent in parents:
self._add_container_actions(parent)
try:
defaults = parent._defaults
except AttributeError:
pass
else:
self._defaults.update(defaults)
# =======================
# Pretty __repr__ methods
# =======================
def _get_kwargs(self):
names = [
'prog',
'usage',
'description',
'version',
'formatter_class',
'conflict_handler',
'add_help',
]
return [(name, getattr(self, name)) for name in names]
# ==================================
# Optional/Positional adding methods
# ==================================
def add_subparsers(self, **kwargs):
if self._subparsers is not None:
self.error(_('cannot have multiple subparser arguments'))
# add the parser class to the arguments if it's not present
kwargs.setdefault('parser_class', type(self))
if 'title' in kwargs or 'description' in kwargs:
title = _(kwargs.pop('title', 'subcommands'))
description = _(kwargs.pop('description', None))
self._subparsers = self.add_argument_group(title, description)
else:
self._subparsers = self._positionals
# prog defaults to the usage message of this parser, skipping
# optional arguments and with no "usage:" prefix
if kwargs.get('prog') is None:
formatter = self._get_formatter()
positionals = self._get_positional_actions()
groups = self._mutually_exclusive_groups
formatter.add_usage(self.usage, positionals, groups, '')
kwargs['prog'] = formatter.format_help().strip()
# create the parsers action and add it to the positionals list
parsers_class = self._pop_action_class(kwargs, 'parsers')
action = parsers_class(option_strings=[], **kwargs)
self._subparsers._add_action(action)
# return the created parsers action
return action
def _add_action(self, action):
if action.option_strings:
self._optionals._add_action(action)
else:
self._positionals._add_action(action)
return action
def _get_optional_actions(self):
return [action
for action in self._actions
if action.option_strings]
def _get_positional_actions(self):
return [action
for action in self._actions
if not action.option_strings]
# =====================================
# Command line argument parsing methods
# =====================================
def parse_args(self, args=None, namespace=None):
args, argv = self.parse_known_args(args, namespace)
if argv:
msg = _('unrecognized arguments: %s')
self.error(msg % ' '.join(argv))
return args
def parse_known_args(self, args=None, namespace=None):
# args default to the system args
if args is None:
args = _sys.argv[1:]
# default Namespace built from parser defaults
if namespace is None:
namespace = Namespace()
# add any action defaults that aren't present
for action in self._actions:
if action.dest is not SUPPRESS:
if not hasattr(namespace, action.dest):
if action.default is not SUPPRESS:
default = action.default
if isinstance(action.default, basestring):
default = self._get_value(action, default)
setattr(namespace, action.dest, default)
# add any parser defaults that aren't present
for dest in self._defaults:
if not hasattr(namespace, dest):
setattr(namespace, dest, self._defaults[dest])
# parse the arguments and exit if there are any errors
try:
namespace, args = self._parse_known_args(args, namespace)
if hasattr(namespace, _UNRECOGNIZED_ARGS_ATTR):
args.extend(getattr(namespace, _UNRECOGNIZED_ARGS_ATTR))
delattr(namespace, _UNRECOGNIZED_ARGS_ATTR)
return namespace, args
except ArgumentError:
err = _sys.exc_info()[1]
self.error(str(err))
def _parse_known_args(self, arg_strings, namespace):
# replace arg strings that are file references
if self.fromfile_prefix_chars is not None:
arg_strings = self._read_args_from_files(arg_strings)
# map all mutually exclusive arguments to the other arguments
# they can't occur with
action_conflicts = {}
for mutex_group in self._mutually_exclusive_groups:
group_actions = mutex_group._group_actions
for i, mutex_action in enumerate(mutex_group._group_actions):
conflicts = action_conflicts.setdefault(mutex_action, [])
conflicts.extend(group_actions[:i])
conflicts.extend(group_actions[i + 1:])
# find all option indices, and determine the arg_string_pattern
# which has an 'O' if there is an option at an index,
# an 'A' if there is an argument, or a '-' if there is a '--'
option_string_indices = {}
arg_string_pattern_parts = []
arg_strings_iter = iter(arg_strings)
for i, arg_string in enumerate(arg_strings_iter):
# all args after -- are non-options
if arg_string == '--':
arg_string_pattern_parts.append('-')
for arg_string in arg_strings_iter:
arg_string_pattern_parts.append('A')
# otherwise, add the arg to the arg strings
# and note the index if it was an option
else:
option_tuple = self._parse_optional(arg_string)
if option_tuple is None:
pattern = 'A'
else:
option_string_indices[i] = option_tuple
pattern = 'O'
arg_string_pattern_parts.append(pattern)
# join the pieces together to form the pattern
arg_strings_pattern = ''.join(arg_string_pattern_parts)
# converts arg strings to the appropriate and then takes the action
seen_actions = set()
seen_non_default_actions = set()
def take_action(action, argument_strings, option_string=None):
seen_actions.add(action)
argument_values = self._get_values(action, argument_strings)
# error if this argument is not allowed with other previously
# seen arguments, assuming that actions that use the default
# value don't really count as "present"
if argument_values is not action.default:
seen_non_default_actions.add(action)
for conflict_action in action_conflicts.get(action, []):
if conflict_action in seen_non_default_actions:
msg = _('not allowed with argument %s')
action_name = _get_action_name(conflict_action)
raise ArgumentError(action, msg % action_name)
# take the action if we didn't receive a SUPPRESS value
# (e.g. from a default)
if argument_values is not SUPPRESS:
action(self, namespace, argument_values, option_string)
# function to convert arg_strings into an optional action
def consume_optional(start_index):
# get the optional identified at this index
option_tuple = option_string_indices[start_index]
action, option_string, explicit_arg = option_tuple
# identify additional optionals in the same arg string
# (e.g. -xyz is the same as -x -y -z if no args are required)
match_argument = self._match_argument
action_tuples = []
while True:
# if we found no optional action, skip it
if action is None:
extras.append(arg_strings[start_index])
return start_index + 1
# if there is an explicit argument, try to match the
# optional's string arguments to only this
if explicit_arg is not None:
arg_count = match_argument(action, 'A')
# if the action is a single-dash option and takes no
# arguments, try to parse more single-dash options out
# of the tail of the option string
chars = self.prefix_chars
if arg_count == 0 and option_string[1] not in chars:
action_tuples.append((action, [], option_string))
char = option_string[0]
option_string = char + explicit_arg[0]
new_explicit_arg = explicit_arg[1:] or None
optionals_map = self._option_string_actions
if option_string in optionals_map:
action = optionals_map[option_string]
explicit_arg = new_explicit_arg
else:
msg = _('ignored explicit argument %r')
raise ArgumentError(action, msg % explicit_arg)
# if the action expect exactly one argument, we've
# successfully matched the option; exit the loop
elif arg_count == 1:
stop = start_index + 1
args = [explicit_arg]
action_tuples.append((action, args, option_string))
break
# error if a double-dash option did not use the
# explicit argument
else:
msg = _('ignored explicit argument %r')
raise ArgumentError(action, msg % explicit_arg)
# if there is no explicit argument, try to match the
# optional's string arguments with the following strings
# if successful, exit the loop
else:
start = start_index + 1
selected_patterns = arg_strings_pattern[start:]
arg_count = match_argument(action, selected_patterns)
stop = start + arg_count
args = arg_strings[start:stop]
action_tuples.append((action, args, option_string))
break
# add the Optional to the list and return the index at which
# the Optional's string args stopped
assert action_tuples
for action, args, option_string in action_tuples:
take_action(action, args, option_string)
return stop
# the list of Positionals left to be parsed; this is modified
# by consume_positionals()
positionals = self._get_positional_actions()
# function to convert arg_strings into positional actions
def consume_positionals(start_index):
# match as many Positionals as possible
match_partial = self._match_arguments_partial
selected_pattern = arg_strings_pattern[start_index:]
arg_counts = match_partial(positionals, selected_pattern)
# slice off the appropriate arg strings for each Positional
# and add the Positional and its args to the list
for action, arg_count in zip(positionals, arg_counts):
args = arg_strings[start_index: start_index + arg_count]
start_index += arg_count
take_action(action, args)
# slice off the Positionals that we just parsed and return the
# index at which the Positionals' string args stopped
positionals[:] = positionals[len(arg_counts):]
return start_index
# consume Positionals and Optionals alternately, until we have
# passed the last option string
extras = []
start_index = 0
if option_string_indices:
max_option_string_index = max(option_string_indices)
else:
max_option_string_index = -1
while start_index <= max_option_string_index:
# consume any Positionals preceding the next option
next_option_string_index = min([
index
for index in option_string_indices
if index >= start_index])
if start_index != next_option_string_index:
positionals_end_index = consume_positionals(start_index)
# only try to parse the next optional if we didn't consume
# the option string during the positionals parsing
if positionals_end_index > start_index:
start_index = positionals_end_index
continue
else:
start_index = positionals_end_index
# if we consumed all the positionals we could and we're not
# at the index of an option string, there were extra arguments
if start_index not in option_string_indices:
strings = arg_strings[start_index:next_option_string_index]
extras.extend(strings)
start_index = next_option_string_index
# consume the next optional and any arguments for it
start_index = consume_optional(start_index)
# consume any positionals following the last Optional
stop_index = consume_positionals(start_index)
# if we didn't consume all the argument strings, there were extras
extras.extend(arg_strings[stop_index:])
# if we didn't use all the Positional objects, there were too few
# arg strings supplied.
if positionals:
self.error(_('too few arguments'))
# make sure all required actions were present
for action in self._actions:
if action.required:
if action not in seen_actions:
name = _get_action_name(action)
self.error(_('argument %s is required') % name)
# make sure all required groups had one option present
for group in self._mutually_exclusive_groups:
if group.required:
for action in group._group_actions:
if action in seen_non_default_actions:
break
# if no actions were used, report the error
else:
names = [_get_action_name(action)
for action in group._group_actions
if action.help is not SUPPRESS]
msg = _('one of the arguments %s is required')
self.error(msg % ' '.join(names))
# return the updated namespace and the extra arguments
return namespace, extras
def _read_args_from_files(self, arg_strings):
# expand arguments referencing files
new_arg_strings = []
for arg_string in arg_strings:
# for regular arguments, just add them back into the list
if arg_string[0] not in self.fromfile_prefix_chars:
new_arg_strings.append(arg_string)
# replace arguments referencing files with the file content
else:
try:
args_file = open(arg_string[1:])
try:
arg_strings = []
for arg_line in args_file.read().splitlines():
for arg in self.convert_arg_line_to_args(arg_line):
arg_strings.append(arg)
arg_strings = self._read_args_from_files(arg_strings)
new_arg_strings.extend(arg_strings)
finally:
args_file.close()
except IOError:
err = _sys.exc_info()[1]
self.error(str(err))
# return the modified argument list
return new_arg_strings
def convert_arg_line_to_args(self, arg_line):
return [arg_line]
def _match_argument(self, action, arg_strings_pattern):
# match the pattern for this action to the arg strings
nargs_pattern = self._get_nargs_pattern(action)
match = _re.match(nargs_pattern, arg_strings_pattern)
# raise an exception if we weren't able to find a match
if match is None:
nargs_errors = {
None: _('expected one argument'),
OPTIONAL: _('expected at most one argument'),
ONE_OR_MORE: _('expected at least one argument'),
}
default = _('expected %s argument(s)') % action.nargs
msg = nargs_errors.get(action.nargs, default)
raise ArgumentError(action, msg)
# return the number of arguments matched
return len(match.group(1))
def _match_arguments_partial(self, actions, arg_strings_pattern):
# progressively shorten the actions list by slicing off the
# final actions until we find a match
result = []
for i in range(len(actions), 0, -1):
actions_slice = actions[:i]
pattern = ''.join([self._get_nargs_pattern(action)
for action in actions_slice])
match = _re.match(pattern, arg_strings_pattern)
if match is not None:
result.extend([len(string) for string in match.groups()])
break
# return the list of arg string counts
return result
def _parse_optional(self, arg_string):
# if it's an empty string, it was meant to be a positional
if not arg_string:
return None
# if it doesn't start with a prefix, it was meant to be positional
if not arg_string[0] in self.prefix_chars:
return None
# if the option string is present in the parser, return the action
if arg_string in self._option_string_actions:
action = self._option_string_actions[arg_string]
return action, arg_string, None
# if it's just a single character, it was meant to be positional
if len(arg_string) == 1:
return None
# if the option string before the "=" is present, return the action
if '=' in arg_string:
option_string, explicit_arg = arg_string.split('=', 1)
if option_string in self._option_string_actions:
action = self._option_string_actions[option_string]
return action, option_string, explicit_arg
# search through all possible prefixes of the option string
# and all actions in the parser for possible interpretations
option_tuples = self._get_option_tuples(arg_string)
# if multiple actions match, the option string was ambiguous
if len(option_tuples) > 1:
options = ', '.join([option_string
for action, option_string, explicit_arg in option_tuples])
tup = arg_string, options
self.error(_('ambiguous option: %s could match %s') % tup)
# if exactly one action matched, this segmentation is good,
# so return the parsed action
elif len(option_tuples) == 1:
option_tuple, = option_tuples
return option_tuple
# if it was not found as an option, but it looks like a negative
# number, it was meant to be positional
# unless there are negative-number-like options
if self._negative_number_matcher.match(arg_string):
if not self._has_negative_number_optionals:
return None
# if it contains a space, it was meant to be a positional
if ' ' in arg_string:
return None
# it was meant to be an optional but there is no such option
# in this parser (though it might be a valid option in a subparser)
return None, arg_string, None
def _get_option_tuples(self, option_string):
result = []
# option strings starting with two prefix characters are only
# split at the '='
chars = self.prefix_chars
if option_string[0] in chars and option_string[1] in chars:
if '=' in option_string:
option_prefix, explicit_arg = option_string.split('=', 1)
else:
option_prefix = option_string
explicit_arg = None
for option_string in self._option_string_actions:
if option_string.startswith(option_prefix):
action = self._option_string_actions[option_string]
tup = action, option_string, explicit_arg
result.append(tup)
# single character options can be concatenated with their arguments
# but multiple character options always have to have their argument
# separate
elif option_string[0] in chars and option_string[1] not in chars:
option_prefix = option_string
explicit_arg = None
short_option_prefix = option_string[:2]
short_explicit_arg = option_string[2:]
for option_string in self._option_string_actions:
if option_string == short_option_prefix:
action = self._option_string_actions[option_string]
tup = action, option_string, short_explicit_arg
result.append(tup)
elif option_string.startswith(option_prefix):
action = self._option_string_actions[option_string]
tup = action, option_string, explicit_arg
result.append(tup)
# shouldn't ever get here
else:
self.error(_('unexpected option string: %s') % option_string)
# return the collected option tuples
return result
def _get_nargs_pattern(self, action):
# in all examples below, we have to allow for '--' args
# which are represented as '-' in the pattern
nargs = action.nargs
# the default (None) is assumed to be a single argument
if nargs is None:
nargs_pattern = '(-*A-*)'
# allow zero or one arguments
elif nargs == OPTIONAL:
nargs_pattern = '(-*A?-*)'
# allow zero or more arguments
elif nargs == ZERO_OR_MORE:
nargs_pattern = '(-*[A-]*)'
# allow one or more arguments
elif nargs == ONE_OR_MORE:
nargs_pattern = '(-*A[A-]*)'
# allow any number of options or arguments
elif nargs == REMAINDER:
nargs_pattern = '([-AO]*)'
# allow one argument followed by any number of options or arguments
elif nargs == PARSER:
nargs_pattern = '(-*A[-AO]*)'
# all others should be integers
else:
nargs_pattern = '(-*%s-*)' % '-*'.join('A' * nargs)
# if this is an optional action, -- is not allowed
if action.option_strings:
nargs_pattern = nargs_pattern.replace('-*', '')
nargs_pattern = nargs_pattern.replace('-', '')
# return the pattern
return nargs_pattern
# ========================
# Value conversion methods
# ========================
def _get_values(self, action, arg_strings):
# for everything but PARSER args, strip out '--'
if action.nargs not in [PARSER, REMAINDER]:
arg_strings = [s for s in arg_strings if s != '--']
# optional argument produces a default when not present
if not arg_strings and action.nargs == OPTIONAL:
if action.option_strings:
value = action.const
else:
value = action.default
if isinstance(value, basestring):
value = self._get_value(action, value)
self._check_value(action, value)
# when nargs='*' on a positional, if there were no command-line
# args, use the default if it is anything other than None
elif (not arg_strings and action.nargs == ZERO_OR_MORE and
not action.option_strings):
if action.default is not None:
value = action.default
else:
value = arg_strings
self._check_value(action, value)
# single argument or optional argument produces a single value
elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]:
arg_string, = arg_strings
value = self._get_value(action, arg_string)
self._check_value(action, value)
# REMAINDER arguments convert all values, checking none
elif action.nargs == REMAINDER:
value = [self._get_value(action, v) for v in arg_strings]
# PARSER arguments convert all values, but check only the first
elif action.nargs == PARSER:
value = [self._get_value(action, v) for v in arg_strings]
self._check_value(action, value[0])
# all other types of nargs produce a list
else:
value = [self._get_value(action, v) for v in arg_strings]
for v in value:
self._check_value(action, v)
# return the converted value
return value
def _get_value(self, action, arg_string):
type_func = self._registry_get('type', action.type, action.type)
if not _callable(type_func):
msg = _('%r is not callable')
raise ArgumentError(action, msg % type_func)
# convert the value to the appropriate type
try:
result = type_func(arg_string)
# ArgumentTypeErrors indicate errors
except ArgumentTypeError:
name = getattr(action.type, '__name__', repr(action.type))
msg = str(_sys.exc_info()[1])
raise ArgumentError(action, msg)
# TypeErrors or ValueErrors also indicate errors
except (TypeError, ValueError):
name = getattr(action.type, '__name__', repr(action.type))
msg = _('invalid %s value: %r')
raise ArgumentError(action, msg % (name, arg_string))
# return the converted value
return result
def _check_value(self, action, value):
# converted value must be one of the choices (if specified)
if action.choices is not None and value not in action.choices:
tup = value, ', '.join(map(repr, action.choices))
msg = _('invalid choice: %r (choose from %s)') % tup
raise ArgumentError(action, msg)
# =======================
# Help-formatting methods
# =======================
def format_usage(self):
formatter = self._get_formatter()
formatter.add_usage(self.usage, self._actions,
self._mutually_exclusive_groups)
return formatter.format_help()
def format_help(self):
formatter = self._get_formatter()
# usage
formatter.add_usage(self.usage, self._actions,
self._mutually_exclusive_groups)
# description
formatter.add_text(self.description)
# positionals, optionals and user-defined groups
for action_group in self._action_groups:
formatter.start_section(action_group.title)
formatter.add_text(action_group.description)
formatter.add_arguments(action_group._group_actions)
formatter.end_section()
# epilog
formatter.add_text(self.epilog)
# determine help from format above
return formatter.format_help()
def format_version(self):
import warnings
warnings.warn(
'The format_version method is deprecated -- the "version" '
'argument to ArgumentParser is no longer supported.',
DeprecationWarning)
formatter = self._get_formatter()
formatter.add_text(self.version)
return formatter.format_help()
def _get_formatter(self):
return self.formatter_class(prog=self.prog)
# =====================
# Help-printing methods
# =====================
def print_usage(self, file=None):
if file is None:
file = _sys.stdout
self._print_message(self.format_usage(), file)
def print_help(self, file=None):
if file is None:
file = _sys.stdout
self._print_message(self.format_help(), file)
def print_version(self, file=None):
import warnings
warnings.warn(
'The print_version method is deprecated -- the "version" '
'argument to ArgumentParser is no longer supported.',
DeprecationWarning)
self._print_message(self.format_version(), file)
def _print_message(self, message, file=None):
if message:
if file is None:
file = _sys.stderr
file.write(message)
# ===============
# Exiting methods
# ===============
def exit(self, status=0, message=None):
if message:
self._print_message(message, _sys.stderr)
_sys.exit(status)
def error(self, message):
"""error(message: string)
Prints a usage message incorporating the message to stderr and
exits.
If you override this in a subclass, it should not return -- it
should either exit or raise an exception.
"""
self.print_usage(_sys.stderr)
self.exit(2, _('%s: error: %s\n') % (self.prog, message))
|
gpl-3.0
|
[
3,
6529,
26,
17854,
1856,
1603,
14,
6423,
273,
1005,
665,
1597,
1856,
14,
1235,
273,
1005,
32,
6799,
14,
957,
10827,
199,
199,
624,
3110,
13,
604,
6057,
3555,
199,
199,
2765,
859,
365,
376,
8691,
13,
262,
8721,
581,
1414,
13,
604,
6057,
3555,
626,
26,
339,
446,
10022,
3865,
2716,
436,
11333,
2368,
272,
446,
16904,
4721,
590,
315,
20889,
4503,
3788,
272,
446,
5171,
21295,
626,
7634,
370,
1007,
13,
11531,
199,
199,
1918,
2569,
365,
282,
3486,
4503,
2893,
626,
27690,
9446,
687,
314,
199,
1531,
13,
604,
436,
14511,
314,
754,
370,
282,
570,
447,
339,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
534,
1838,
314,
9446,
737,
314,
1414,
1004,
358,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
23931,
297,
8214,
534,
442,
297,
9237,
534,
7386,
730,
29,
442,
12,
267,
1720,
534,
290,
3000,
370,
506,
3089,
3594,
358,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
793,
297,
849,
29,
1274,
14,
2703,
12,
730,
29,
18978,
14,
20683,
360,
87,
659,
267,
1720,
534,
1589,
570,
2382,
314,
3089,
1077,
506,
5313,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
1249,
14,
793,
14,
952,
3508,
83,
7,
450,
3089,
8,
589,
14,
23931,
430,
272,
1249,
14,
793,
14,
1600,
342,
199,
199,
1918,
859,
3509,
314,
2569,
4575,
3992,
26,
339,
446,
27615,
1553,
710,
2446,
2397,
2376,
367,
1414,
13,
604,
6057,
14,
3709,
314,
267,
2893,
3432,
13703,
12,
314,
1050,
63,
2094,
342,
1083,
365,
1202,
370,
13904,
267,
314,
1798,
543,
5445,
367,
2716,
436,
11333,
2368,
14,
9442,
267,
314,
2198,
63,
589,
342,
1083,
365,
10302,
370,
3957,
314,
1249,
737,
314,
267,
1414,
13,
604,
1901,
376,
909,
543,
3004,
14,
339,
446,
5886,
547,
1553,
710,
1919,
4915,
701,
27615,
2251,
1380,
267,
2337,
787,
2552,
543,
314,
1798,
1159,
5445,
14,
20456,
4915,
1830,
267,
6057,
314,
1414,
13,
604,
787,
15604,
701,
27615,
436,
19515,
267,
465,
1414,
13,
604,
3788,
14,
339,
446,
3814,
804,
1553,
437,
6434,
367,
12669,
2943,
402,
1584,
370,
506,
2737,
14,
3709,
314,
267,
2893,
3432,
13703,
12,
4454,
402,
3814,
804,
787,
13609,
3032,
465,
267,
314,
730,
29,
1423,
402,
1050,
63,
2094,
342,
4882,
14,
339,
446,
10033,
1553,
710,
1300,
1021,
367,
1798,
5445,
14,
26914,
5445,
787,
267,
4895,
701,
9476,
3326,
2839,
283,
1617,
63,
2052,
7,
503,
283,
740,
63,
1297,
7,
370,
267,
314,
1595,
29,
1423,
402,
1050,
63,
2094,
1252,
9738,
12,
367,
8932,
267,
32715,
402,
27615,
5445,
12,
9180,
402,
10033,
1443,
267,
506,
3247,
436,
3032,
465,
314,
1595,
29,
1423,
14,
339,
446,
15456,
7772,
12,
13480,
5831,
22779,
12,
13480,
1872,
22779,
12,
267,
5886,
16986,
22779,
1553,
31084,
3992,
1314,
267,
1443,
506,
3032,
465,
314,
9698,
63,
533,
29,
1423,
370,
314,
267,
27615,
3787,
14,
15456,
7772,
365,
314,
849,
12,
267,
13480,
5831,
22779,
436,
13480,
1872,
22779,
11480,
314,
1798,
267,
440,
370,
1570,
314,
10803,
367,
1720,
1318,
12,
436,
267,
5886,
16986,
22779,
9584,
2556,
3595,
1423,
4243,
267,
370,
314,
1720,
14,
199,
199,
2422,
1163,
3992,
315,
642,
859,
787,
8652,
4514,
2436,
14,
199,
8,
31892,
5317,
626,
15456,
7772,
436,
13480,
5831,
22779,
787,
1454,
199,
388,
2441,
581,
4575,
465,
909,
1561,
1553,
314,
3261,
402,
314,
9698,
2251,
365,
199,
32310,
8652,
376,
4514,
10093,
4959,
199,
624,
199,
199,
363,
1023,
363,
275,
283,
17,
14,
18,
14,
17,
7,
199,
363,
452,
363,
275,
359,
272,
283,
10730,
297,
272,
283,
17042,
297,
272,
283,
5201,
4333,
297,
272,
283,
20683,
297,
272,
283,
22779,
297,
272,
283,
5201,
16986,
22779,
297,
272,
283,
7963,
5831,
22779,
297,
272,
283,
7963,
1872,
22779,
297,
272,
283,
8814,
297,
272,
283,
3310,
297,
272,
283,
4817,
63,
726,
63,
45,
5788,
297,
272,
283,
21008,
297,
272,
283,
26078,
297,
272,
283,
907,
2054,
3192,
540,
297,
272,
283,
24023,
297,
272,
283,
24655,
63,
726,
63,
45,
5788,
297,
199,
61,
421,
199,
646,
1331,
465,
485,
1574,
199,
646,
747,
465,
485,
736,
199,
646,
295,
465,
485,
264,
199,
646,
984,
465,
485,
1274,
199,
646,
13390,
465,
485,
505,
3823,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
893,
26,
272,
663,
199,
2590,
12746,
26,
272,
327,
367,
2366,
665,
499,
14,
20,
7163,
334,
2193,
859,
365,
2337,
3967,
499,
14,
19,
304,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
893,
26,
272,
7116,
199,
2590,
12746,
26,
272,
7116,
275,
620,
199,
199,
893,
26,
272,
3355,
199,
2590,
12746,
26,
272,
327,
367,
2366,
665,
499,
14,
20,
7163,
26,
272,
347,
3355,
8,
8147,
12,
3837,
29,
797,
304,
267,
754,
275,
769,
8,
8147,
9,
267,
754,
14,
3191,
342,
267,
340,
3837,
26,
288,
754,
14,
4471,
342,
267,
372,
754,
421,
199,
318,
485,
8296,
8,
1113,
304,
272,
372,
2688,
8,
1113,
12,
2560,
1250,
13766,
503,
2688,
8,
1113,
12,
2560,
12087,
13766,
421,
199,
24023,
275,
283,
389,
24023,
6803,
199,
199,
21008,
275,
15539,
199,
24655,
63,
726,
63,
45,
5788,
275,
13626,
199,
4817,
63,
726,
63,
45,
5788,
275,
20246,
199,
26078,
275,
283,
33,
13698,
199,
907,
2054,
3192,
540,
275,
28044,
199,
63,
1734,
907,
1439,
15306,
18732,
63,
13990,
63,
5280,
275,
2513,
324,
13221,
63,
589,
7,
199,
199,
3,
16248,
5769,
199,
3,
20511,
3423,
436,
3992,
199,
3,
16248,
5769,
199,
199,
533,
485,
1646,
22570,
8,
785,
304,
272,
408,
8458,
1300,
1021,
626,
6571,
636,
2722,
4343,
339,
710,
636,
2722,
363,
1083,
2529,
282,
1059,
315,
314,
1475,
447,
267,
8089,
985,
8,
962,
29,
354,
12,
1921,
29,
354,
12,
19172,
272,
710,
3004,
787,
12037,
1902,
701,
282,
1021,
13,
1896,
2225,
12,
272,
2513,
12745,
63,
1247,
297,
503,
701,
6485,
316,
314,
1256,
636,
807,
4343,
272,
408,
339,
347,
636,
2722,
721,
277,
304,
267,
730,
63,
354,
275,
730,
8,
277
] |
[
6529,
26,
17854,
1856,
1603,
14,
6423,
273,
1005,
665,
1597,
1856,
14,
1235,
273,
1005,
32,
6799,
14,
957,
10827,
199,
199,
624,
3110,
13,
604,
6057,
3555,
199,
199,
2765,
859,
365,
376,
8691,
13,
262,
8721,
581,
1414,
13,
604,
6057,
3555,
626,
26,
339,
446,
10022,
3865,
2716,
436,
11333,
2368,
272,
446,
16904,
4721,
590,
315,
20889,
4503,
3788,
272,
446,
5171,
21295,
626,
7634,
370,
1007,
13,
11531,
199,
199,
1918,
2569,
365,
282,
3486,
4503,
2893,
626,
27690,
9446,
687,
314,
199,
1531,
13,
604,
436,
14511,
314,
754,
370,
282,
570,
447,
339,
1798,
275,
7534,
14,
10730,
8,
267,
1369,
534,
1838,
314,
9446,
737,
314,
1414,
1004,
358,
272,
1798,
14,
525,
63,
2094,
8,
267,
283,
23931,
297,
8214,
534,
442,
297,
9237,
534,
7386,
730,
29,
442,
12,
267,
1720,
534,
290,
3000,
370,
506,
3089,
3594,
358,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
793,
297,
849,
29,
1274,
14,
2703,
12,
730,
29,
18978,
14,
20683,
360,
87,
659,
267,
1720,
534,
1589,
570,
2382,
314,
3089,
1077,
506,
5313,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
272,
1249,
14,
793,
14,
952,
3508,
83,
7,
450,
3089,
8,
589,
14,
23931,
430,
272,
1249,
14,
793,
14,
1600,
342,
199,
199,
1918,
859,
3509,
314,
2569,
4575,
3992,
26,
339,
446,
27615,
1553,
710,
2446,
2397,
2376,
367,
1414,
13,
604,
6057,
14,
3709,
314,
267,
2893,
3432,
13703,
12,
314,
1050,
63,
2094,
342,
1083,
365,
1202,
370,
13904,
267,
314,
1798,
543,
5445,
367,
2716,
436,
11333,
2368,
14,
9442,
267,
314,
2198,
63,
589,
342,
1083,
365,
10302,
370,
3957,
314,
1249,
737,
314,
267,
1414,
13,
604,
1901,
376,
909,
543,
3004,
14,
339,
446,
5886,
547,
1553,
710,
1919,
4915,
701,
27615,
2251,
1380,
267,
2337,
787,
2552,
543,
314,
1798,
1159,
5445,
14,
20456,
4915,
1830,
267,
6057,
314,
1414,
13,
604,
787,
15604,
701,
27615,
436,
19515,
267,
465,
1414,
13,
604,
3788,
14,
339,
446,
3814,
804,
1553,
437,
6434,
367,
12669,
2943,
402,
1584,
370,
506,
2737,
14,
3709,
314,
267,
2893,
3432,
13703,
12,
4454,
402,
3814,
804,
787,
13609,
3032,
465,
267,
314,
730,
29,
1423,
402,
1050,
63,
2094,
342,
4882,
14,
339,
446,
10033,
1553,
710,
1300,
1021,
367,
1798,
5445,
14,
26914,
5445,
787,
267,
4895,
701,
9476,
3326,
2839,
283,
1617,
63,
2052,
7,
503,
283,
740,
63,
1297,
7,
370,
267,
314,
1595,
29,
1423,
402,
1050,
63,
2094,
1252,
9738,
12,
367,
8932,
267,
32715,
402,
27615,
5445,
12,
9180,
402,
10033,
1443,
267,
506,
3247,
436,
3032,
465,
314,
1595,
29,
1423,
14,
339,
446,
15456,
7772,
12,
13480,
5831,
22779,
12,
13480,
1872,
22779,
12,
267,
5886,
16986,
22779,
1553,
31084,
3992,
1314,
267,
1443,
506,
3032,
465,
314,
9698,
63,
533,
29,
1423,
370,
314,
267,
27615,
3787,
14,
15456,
7772,
365,
314,
849,
12,
267,
13480,
5831,
22779,
436,
13480,
1872,
22779,
11480,
314,
1798,
267,
440,
370,
1570,
314,
10803,
367,
1720,
1318,
12,
436,
267,
5886,
16986,
22779,
9584,
2556,
3595,
1423,
4243,
267,
370,
314,
1720,
14,
199,
199,
2422,
1163,
3992,
315,
642,
859,
787,
8652,
4514,
2436,
14,
199,
8,
31892,
5317,
626,
15456,
7772,
436,
13480,
5831,
22779,
787,
1454,
199,
388,
2441,
581,
4575,
465,
909,
1561,
1553,
314,
3261,
402,
314,
9698,
2251,
365,
199,
32310,
8652,
376,
4514,
10093,
4959,
199,
624,
199,
199,
363,
1023,
363,
275,
283,
17,
14,
18,
14,
17,
7,
199,
363,
452,
363,
275,
359,
272,
283,
10730,
297,
272,
283,
17042,
297,
272,
283,
5201,
4333,
297,
272,
283,
20683,
297,
272,
283,
22779,
297,
272,
283,
5201,
16986,
22779,
297,
272,
283,
7963,
5831,
22779,
297,
272,
283,
7963,
1872,
22779,
297,
272,
283,
8814,
297,
272,
283,
3310,
297,
272,
283,
4817,
63,
726,
63,
45,
5788,
297,
272,
283,
21008,
297,
272,
283,
26078,
297,
272,
283,
907,
2054,
3192,
540,
297,
272,
283,
24023,
297,
272,
283,
24655,
63,
726,
63,
45,
5788,
297,
199,
61,
421,
199,
646,
1331,
465,
485,
1574,
199,
646,
747,
465,
485,
736,
199,
646,
295,
465,
485,
264,
199,
646,
984,
465,
485,
1274,
199,
646,
13390,
465,
485,
505,
3823,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
893,
26,
272,
663,
199,
2590,
12746,
26,
272,
327,
367,
2366,
665,
499,
14,
20,
7163,
334,
2193,
859,
365,
2337,
3967,
499,
14,
19,
304,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
893,
26,
272,
7116,
199,
2590,
12746,
26,
272,
7116,
275,
620,
199,
199,
893,
26,
272,
3355,
199,
2590,
12746,
26,
272,
327,
367,
2366,
665,
499,
14,
20,
7163,
26,
272,
347,
3355,
8,
8147,
12,
3837,
29,
797,
304,
267,
754,
275,
769,
8,
8147,
9,
267,
754,
14,
3191,
342,
267,
340,
3837,
26,
288,
754,
14,
4471,
342,
267,
372,
754,
421,
199,
318,
485,
8296,
8,
1113,
304,
272,
372,
2688,
8,
1113,
12,
2560,
1250,
13766,
503,
2688,
8,
1113,
12,
2560,
12087,
13766,
421,
199,
24023,
275,
283,
389,
24023,
6803,
199,
199,
21008,
275,
15539,
199,
24655,
63,
726,
63,
45,
5788,
275,
13626,
199,
4817,
63,
726,
63,
45,
5788,
275,
20246,
199,
26078,
275,
283,
33,
13698,
199,
907,
2054,
3192,
540,
275,
28044,
199,
63,
1734,
907,
1439,
15306,
18732,
63,
13990,
63,
5280,
275,
2513,
324,
13221,
63,
589,
7,
199,
199,
3,
16248,
5769,
199,
3,
20511,
3423,
436,
3992,
199,
3,
16248,
5769,
199,
199,
533,
485,
1646,
22570,
8,
785,
304,
272,
408,
8458,
1300,
1021,
626,
6571,
636,
2722,
4343,
339,
710,
636,
2722,
363,
1083,
2529,
282,
1059,
315,
314,
1475,
447,
267,
8089,
985,
8,
962,
29,
354,
12,
1921,
29,
354,
12,
19172,
272,
710,
3004,
787,
12037,
1902,
701,
282,
1021,
13,
1896,
2225,
12,
272,
2513,
12745,
63,
1247,
297,
503,
701,
6485,
316,
314,
1256,
636,
807,
4343,
272,
408,
339,
347,
636,
2722,
721,
277,
304,
267,
730,
63,
354,
275,
730,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mambocab/cassandra-dtest
|
plugins/dtestconfig.py
|
7
|
1418
|
from collections import namedtuple
from nose import plugins
# A class that defines the attributes that have to be defined for configuring
# a dtest run. namedtuple does what we want -- it's immutable and requires
# all the attributes to be passed in to be instantiated.
GlobalConfigObject = namedtuple('GlobalConfigObject', [
'vnodes', # disable or enable vnodes
])
_CONFIG = None
class DtestConfigPlugin(plugins.Plugin):
"""
Pass in configuration options for the dtests.
"""
enabled = True # if this plugin is loaded at all, we're using it
name = 'dtest_config'
def __init__(self, config=None):
"""
Instantiate this plugin with a GlobalConfigObject or, by default, None.
Then, set the global _CONFIG constant with the value of the plugin.
This is a little weird, yes, but nose seems to generally be built
around the idea that a given plugin will be instantiated only once, so
this provides a way for test framework code to grab the value off this
module. We want that, since the plugin itself isn't available to test
code.
@param config an object meeting the GlobalConfigObject spec that will
be used as configuration for a dtest run.
"""
self.CONFIG = config
global _CONFIG
_CONFIG = self.CONFIG
def configure(self, options, conf):
pass
|
apache-2.0
|
[
504,
5055,
492,
12863,
199,
199,
504,
11354,
492,
8963,
199,
199,
3,
437,
1021,
626,
7890,
314,
3004,
626,
1172,
370,
506,
3247,
367,
1101,
4039,
199,
3,
282,
366,
396,
1255,
14,
12863,
1630,
4052,
781,
2934,
1553,
652,
1159,
17092,
436,
5074,
199,
3,
1006,
314,
3004,
370,
506,
3032,
315,
370,
506,
17544,
14,
199,
7025,
2028,
1692,
275,
12863,
360,
7025,
2028,
1692,
297,
359,
272,
283,
86,
2415,
297,
221,
327,
3507,
503,
4756,
373,
2415,
199,
566,
199,
199,
63,
5569,
275,
488,
421,
199,
533,
577,
396,
2028,
5061,
8,
5265,
14,
5061,
304,
272,
408,
272,
8325,
315,
2897,
1511,
367,
314,
366,
2219,
14,
272,
408,
272,
5223,
275,
715,
221,
327,
340,
642,
3589,
365,
6511,
737,
1006,
12,
781,
3984,
1808,
652,
272,
536,
275,
283,
68,
396,
63,
888,
7,
339,
347,
636,
826,
721,
277,
12,
1101,
29,
403,
304,
267,
408,
267,
32092,
642,
3589,
543,
282,
13641,
2028,
1692,
503,
12,
701,
849,
12,
488,
14,
267,
9442,
12,
663,
221,
314,
2288,
485,
5569,
4413,
543,
314,
574,
402,
314,
3589,
14,
398,
961,
365,
282,
12050,
22965,
12,
9456,
12,
1325,
11354,
12237,
370,
16711,
506,
6137,
267,
6818,
314,
16819,
626,
282,
1627,
3589,
911,
506,
17544,
1454,
5403,
12,
880,
267,
642,
6571,
282,
4340,
367,
511,
10059,
1233,
370,
18200,
314,
574,
2331,
642,
267,
859,
14,
2136,
2934,
626,
12,
3967,
314,
3589,
6337,
5712,
1133,
2808,
370,
511,
267,
1233,
14,
398,
768,
635,
1101,
376,
909,
31495,
314,
13641,
2028,
1692,
3158,
626,
911,
1993,
506,
1202,
465,
2897,
367,
282,
366,
396,
1255,
14,
267,
408,
267,
291,
14,
5569,
275,
1101,
398,
2288,
485,
5569,
267,
485,
5569,
275,
291,
14,
5569,
339,
347,
7908,
8,
277,
12,
1511,
12,
3743,
304,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5055,
492,
12863,
199,
199,
504,
11354,
492,
8963,
199,
199,
3,
437,
1021,
626,
7890,
314,
3004,
626,
1172,
370,
506,
3247,
367,
1101,
4039,
199,
3,
282,
366,
396,
1255,
14,
12863,
1630,
4052,
781,
2934,
1553,
652,
1159,
17092,
436,
5074,
199,
3,
1006,
314,
3004,
370,
506,
3032,
315,
370,
506,
17544,
14,
199,
7025,
2028,
1692,
275,
12863,
360,
7025,
2028,
1692,
297,
359,
272,
283,
86,
2415,
297,
221,
327,
3507,
503,
4756,
373,
2415,
199,
566,
199,
199,
63,
5569,
275,
488,
421,
199,
533,
577,
396,
2028,
5061,
8,
5265,
14,
5061,
304,
272,
408,
272,
8325,
315,
2897,
1511,
367,
314,
366,
2219,
14,
272,
408,
272,
5223,
275,
715,
221,
327,
340,
642,
3589,
365,
6511,
737,
1006,
12,
781,
3984,
1808,
652,
272,
536,
275,
283,
68,
396,
63,
888,
7,
339,
347,
636,
826,
721,
277,
12,
1101,
29,
403,
304,
267,
408,
267,
32092,
642,
3589,
543,
282,
13641,
2028,
1692,
503,
12,
701,
849,
12,
488,
14,
267,
9442,
12,
663,
221,
314,
2288,
485,
5569,
4413,
543,
314,
574,
402,
314,
3589,
14,
398,
961,
365,
282,
12050,
22965,
12,
9456,
12,
1325,
11354,
12237,
370,
16711,
506,
6137,
267,
6818,
314,
16819,
626,
282,
1627,
3589,
911,
506,
17544,
1454,
5403,
12,
880,
267,
642,
6571,
282,
4340,
367,
511,
10059,
1233,
370,
18200,
314,
574,
2331,
642,
267,
859,
14,
2136,
2934,
626,
12,
3967,
314,
3589,
6337,
5712,
1133,
2808,
370,
511,
267,
1233,
14,
398,
768,
635,
1101,
376,
909,
31495,
314,
13641,
2028,
1692,
3158,
626,
911,
1993,
506,
1202,
465,
2897,
367,
282,
366,
396,
1255,
14,
267,
408,
267,
291,
14,
5569,
275,
1101,
398,
2288,
485,
5569,
267,
485,
5569,
275,
291,
14,
5569,
339,
347,
7908,
8,
277,
12,
1511,
12,
3743,
304,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
byterom/android_external_chromium_org
|
tools/cygprofile/patch_orderfile.py
|
43
|
3978
|
#!/usr/bin/python
# Copyright 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.
import commands
import os
import sys
orderfile = sys.argv[1]
uninstrumented_shlib = sys.argv[2]
nmlines_uninstrumented = commands.getoutput ('nm -S -n ' +
uninstrumented_shlib + ' | egrep "( t )|( W )|( T )"').split('\n')
nmlines = []
for nmline in nmlines_uninstrumented:
if (len(nmline.split()) == 4):
nmlines.append(nmline)
# Map addresses to list of functions at that address. There are multiple
# functions at an address because of aliasing.
nm_index = 0
uniqueAddrs = []
addressMap = {}
while nm_index < len(nmlines):
if (len(nmlines[nm_index].split()) == 4):
nm_int = int (nmlines[nm_index].split()[0], 16)
size = int (nmlines[nm_index].split()[1], 16)
fnames = [nmlines[nm_index].split()[3]]
nm_index = nm_index + 1
while nm_index < len(nmlines) and nm_int == int (
nmlines[nm_index].split()[0], 16):
fnames.append(nmlines[nm_index].split()[3])
nm_index = nm_index + 1
addressMap[nm_int] = fnames
uniqueAddrs.append((nm_int, size))
else:
nm_index = nm_index + 1
def binary_search (addr, start, end):
if start >= end or start == end - 1:
(nm_addr, size) = uniqueAddrs[start]
if not (addr >= nm_addr and addr < nm_addr + size):
sys.stderr.write ("ERROR: did not find function in binary: addr: " +
hex(addr) + " nm_addr: " + str(nm_addr) + " start: " + str(start) +
" end: " + str(end) + "\n")
raise Error("error")
return (addressMap[nm_addr], size)
else:
halfway = start + ((end - start) / 2)
(nm_addr, size) = uniqueAddrs[halfway]
if (addr >= nm_addr and addr < nm_addr + size):
return (addressMap[nm_addr], size)
elif (addr < nm_addr):
return binary_search (addr, start, halfway)
elif (addr >= nm_addr + size):
return binary_search (addr, halfway, end)
else:
raise "ERROR: did not expect this case"
f = open (orderfile)
lines = f.readlines()
profiled_list = []
for line in lines:
if (line.strip() == ''):
continue
functionName = line.replace('.text.', '').split('.clone.')[0].strip()
profiled_list.append (functionName)
# Symbol names are not unique. Since the order file uses symbol names, the
# patched order file pulls in all symbols with the same name. Multiple function
# addresses for the same function name may also be due to ".clone" symbols,
# since the substring is stripped.
functions = []
functionAddressMap = {}
for line in nmlines:
try:
functionName = line.split()[3]
except:
functionName = line.split()[2]
functionName = functionName.split('.clone.')[0]
functionAddress = int (line.split()[0].strip(), 16)
try:
functionAddressMap[functionName].append(functionAddress)
except:
functionAddressMap[functionName] = [functionAddress]
functions.append(functionName)
sys.stderr.write ("profiled list size: " + str(len(profiled_list)) + "\n")
addresses = []
symbols_found = 0
for function in profiled_list:
try:
addrs = functionAddressMap[function]
symbols_found = symbols_found + 1
except:
addrs = []
# sys.stderr.write ("WARNING: could not find symbol " + function + "\n")
for addr in addrs:
if not (addr in addresses):
addresses.append(addr)
sys.stderr.write ("symbols found: " + str(symbols_found) + "\n")
sys.stderr.write ("number of addresses: " + str(len(addresses)) + "\n")
total_size = 0
for addr in addresses:
(functions, size) = binary_search (addr, 0, len(uniqueAddrs))
total_size = total_size + size
prefixes = ['.text.', '.text.startup.', '.text.hot.', '.text.unlikely.']
for function in functions:
for prefix in prefixes:
print prefix + function
# The following is needed otherwise Gold only applies a partial sort.
print '.text.*'
sys.stderr.write ("total_size: " + str(total_size) + "\n")
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
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,
646,
3718,
199,
646,
747,
199,
646,
984,
199,
199,
1648,
493,
275,
984,
14,
3020,
59,
17,
61,
199,
324,
21309,
12546,
63,
609,
773,
275,
984,
14,
3020,
59,
18,
61,
199,
199,
10756,
1278,
63,
324,
21309,
12546,
275,
3718,
14,
362,
1199,
661,
10756,
446,
51,
446,
78,
283,
435,
2043,
625,
21309,
12546,
63,
609,
773,
435,
283,
221,
1204,
11837,
1155,
7340,
307,
776,
92,
8,
644,
776,
92,
8,
377,
776,
2,
1959,
1294,
2258,
78,
358,
199,
199,
10756,
1278,
275,
942,
199,
509,
16751,
604,
315,
16751,
1278,
63,
324,
21309,
12546,
26,
523,
340,
334,
552,
8,
10756,
604,
14,
1294,
1012,
508,
841,
304,
272,
16751,
1278,
14,
740,
8,
10756,
604,
9,
199,
199,
3,
9672,
7149,
370,
769,
402,
3423,
737,
626,
2287,
14,
221,
6006,
787,
3663,
199,
3,
3423,
737,
376,
2287,
2952,
402,
5162,
316,
14,
199,
10756,
63,
1080,
275,
378,
199,
3235,
1123,
2393,
275,
942,
199,
1562,
2956,
275,
1052,
199,
6710,
16751,
63,
1080,
665,
822,
8,
10756,
1278,
304,
523,
340,
334,
552,
8,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
1012,
508,
841,
304,
272,
16751,
63,
442,
275,
1109,
334,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
16,
467,
3193,
9,
272,
1568,
275,
1109,
334,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
17,
467,
3193,
9,
272,
289,
1247,
275,
359,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
19,
2677,
272,
16751,
63,
1080,
275,
16751,
63,
1080,
435,
413,
272,
1830,
16751,
63,
1080,
665,
822,
8,
10756,
1278,
9,
436,
16751,
63,
442,
508,
1109,
334,
267,
16751,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
16,
467,
3193,
304,
489,
289,
1247,
14,
740,
8,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
19,
566,
489,
16751,
63,
1080,
275,
16751,
63,
1080,
435,
413,
272,
2287,
2956,
59,
10756,
63,
442,
61,
275,
289,
1247,
272,
3747,
1123,
2393,
14,
740,
1332,
10756,
63,
442,
12,
1568,
430,
523,
587,
26,
272,
16751,
63,
1080,
275,
16751,
63,
1080,
435,
413,
199,
199,
318,
3366,
63,
1733,
334,
2697,
12,
1343,
12,
1284,
304,
523,
340,
1343,
2356,
1284,
503,
1343,
508,
1284,
446,
413,
26,
272,
334,
10756,
63,
2697,
12,
1568,
9,
275,
3747,
1123,
2393,
59,
928,
61,
272,
340,
440,
334,
2697,
2356,
16751,
63,
2697,
436,
5552,
665,
16751,
63,
2697,
435,
1568,
304,
489,
984,
14,
3083,
14,
952,
1689,
3170,
26,
8103,
440,
2342,
805,
315,
3366,
26,
5552,
26,
298,
435,
881,
6318,
8,
2697,
9,
435,
298,
16751,
63,
2697,
26,
298,
435,
620,
8,
10756,
63,
2697,
9,
435,
298,
1343,
26,
298,
435,
620,
8,
928,
9,
435,
881,
298,
1284,
26,
298,
435,
620,
8,
500,
9,
435,
1867,
78,
531,
489,
746,
4520,
480,
705,
531,
272,
372,
334,
1562,
2956,
59,
10756,
63,
2697,
467,
1568,
9,
523,
587,
26,
272,
12995,
3316,
275,
1343,
435,
3666,
500,
446,
1343,
9,
1182,
499,
9,
272,
334,
10756,
63,
2697,
12,
1568,
9,
275,
3747,
1123,
2393,
59,
10220,
3316,
61,
272,
340,
334,
2697,
2356,
16751,
63,
2697,
436,
5552,
665,
16751,
63,
2697,
435,
1568,
304,
489,
372,
334,
1562,
2956,
59,
10756,
63,
2697,
467,
1568,
9,
272,
916,
334,
2697,
665,
16751,
63,
2697,
304,
489,
372,
3366,
63,
1733,
334,
2697,
12,
1343,
12,
12995,
3316,
9,
272,
916,
334,
2697,
2356,
16751,
63,
2697,
435,
1568,
304,
489,
372,
3366,
63,
1733,
334,
2697,
12,
12995,
3316,
12,
1284,
9,
272,
587,
26,
489,
746,
298,
3170,
26,
8103,
440,
4282,
642,
1930,
2,
199,
199,
70,
275,
1551,
334,
1648,
493,
9,
199,
1278,
275,
289,
14,
9684,
342,
199,
2913,
68,
63,
513,
275,
942,
199,
509,
1004,
315,
2385,
26,
523,
340,
334,
604,
14,
1913,
342,
508,
21019,
272,
1980,
523,
805,
985,
275,
1004,
14,
1814,
5175,
505,
3130,
12548,
1294,
5175,
6311,
2659,
59,
16,
1055,
1913,
342,
523,
4690,
68,
63,
513,
14,
740,
334,
1593,
985,
9,
199,
199,
3,
10080,
1561,
787,
440,
3747,
14,
221,
9336,
314,
1865,
570,
4440,
5272,
1561,
12,
314,
199,
3,
19483,
1865,
570,
299,
13072,
315,
1006,
6698,
543,
314,
2011,
536,
14,
221,
14326,
805,
199,
3,
7149,
367,
314,
2011,
805,
536,
1443,
2597,
506,
7037,
370,
3680,
6311,
2,
6698,
12,
199,
3,
3967,
314,
20597,
365,
14489,
14,
199,
5777,
275,
942,
199,
1593,
1476,
2956,
275,
1052,
199,
509,
1004,
315,
16751,
1278,
26,
523,
862,
26,
272,
805,
985,
275,
1004,
14,
1294,
3430,
19,
61,
523,
871,
26,
272,
805,
985,
275,
1004,
14,
1294,
3430,
18,
61,
523,
805,
985,
275,
805,
985,
14,
1294,
5175,
6311,
2659,
59,
16,
61,
523,
805,
1476,
275,
1109,
334,
604,
14,
1294,
3430,
16,
1055,
1913,
1062,
3193,
9,
523,
862,
26,
272,
805,
1476,
2956,
59,
1593,
985,
1055,
740,
8,
1593,
1476,
9,
523,
871,
26,
272,
805,
1476,
2956,
59,
1593,
985,
61,
275,
359,
1593,
1476,
61,
272,
3423,
14,
740,
8,
1593,
985,
9,
199,
199,
1274,
14,
3083,
14,
952,
1689,
2913,
68,
769,
1568,
26,
298,
435,
620,
8,
552,
8,
2913,
68,
63,
513,
430,
435,
1867,
78,
531,
199,
7423,
275,
942,
199,
7450,
63,
4214,
275,
378,
199,
509,
805,
315,
4690,
68,
63,
513,
26,
2043,
862,
26,
1362,
29259,
275,
805,
1476,
2956,
59,
1593,
61,
1362,
6698,
63,
4214,
275,
6698,
63,
4214,
435,
413,
2043,
871,
26,
1362,
29259,
275,
942,
1362,
327,
984,
14,
3083,
14,
952,
1689,
9171,
26,
4293,
440,
2342,
5272,
298,
435,
805,
435,
1867,
78,
531,
2043,
367,
5552,
315,
29259,
26,
1362,
340,
440,
334,
2697,
315,
7149,
304,
2126
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
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,
646,
3718,
199,
646,
747,
199,
646,
984,
199,
199,
1648,
493,
275,
984,
14,
3020,
59,
17,
61,
199,
324,
21309,
12546,
63,
609,
773,
275,
984,
14,
3020,
59,
18,
61,
199,
199,
10756,
1278,
63,
324,
21309,
12546,
275,
3718,
14,
362,
1199,
661,
10756,
446,
51,
446,
78,
283,
435,
2043,
625,
21309,
12546,
63,
609,
773,
435,
283,
221,
1204,
11837,
1155,
7340,
307,
776,
92,
8,
644,
776,
92,
8,
377,
776,
2,
1959,
1294,
2258,
78,
358,
199,
199,
10756,
1278,
275,
942,
199,
509,
16751,
604,
315,
16751,
1278,
63,
324,
21309,
12546,
26,
523,
340,
334,
552,
8,
10756,
604,
14,
1294,
1012,
508,
841,
304,
272,
16751,
1278,
14,
740,
8,
10756,
604,
9,
199,
199,
3,
9672,
7149,
370,
769,
402,
3423,
737,
626,
2287,
14,
221,
6006,
787,
3663,
199,
3,
3423,
737,
376,
2287,
2952,
402,
5162,
316,
14,
199,
10756,
63,
1080,
275,
378,
199,
3235,
1123,
2393,
275,
942,
199,
1562,
2956,
275,
1052,
199,
6710,
16751,
63,
1080,
665,
822,
8,
10756,
1278,
304,
523,
340,
334,
552,
8,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
1012,
508,
841,
304,
272,
16751,
63,
442,
275,
1109,
334,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
16,
467,
3193,
9,
272,
1568,
275,
1109,
334,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
17,
467,
3193,
9,
272,
289,
1247,
275,
359,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
19,
2677,
272,
16751,
63,
1080,
275,
16751,
63,
1080,
435,
413,
272,
1830,
16751,
63,
1080,
665,
822,
8,
10756,
1278,
9,
436,
16751,
63,
442,
508,
1109,
334,
267,
16751,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
16,
467,
3193,
304,
489,
289,
1247,
14,
740,
8,
10756,
1278,
59,
10756,
63,
1080,
1055,
1294,
3430,
19,
566,
489,
16751,
63,
1080,
275,
16751,
63,
1080,
435,
413,
272,
2287,
2956,
59,
10756,
63,
442,
61,
275,
289,
1247,
272,
3747,
1123,
2393,
14,
740,
1332,
10756,
63,
442,
12,
1568,
430,
523,
587,
26,
272,
16751,
63,
1080,
275,
16751,
63,
1080,
435,
413,
199,
199,
318,
3366,
63,
1733,
334,
2697,
12,
1343,
12,
1284,
304,
523,
340,
1343,
2356,
1284,
503,
1343,
508,
1284,
446,
413,
26,
272,
334,
10756,
63,
2697,
12,
1568,
9,
275,
3747,
1123,
2393,
59,
928,
61,
272,
340,
440,
334,
2697,
2356,
16751,
63,
2697,
436,
5552,
665,
16751,
63,
2697,
435,
1568,
304,
489,
984,
14,
3083,
14,
952,
1689,
3170,
26,
8103,
440,
2342,
805,
315,
3366,
26,
5552,
26,
298,
435,
881,
6318,
8,
2697,
9,
435,
298,
16751,
63,
2697,
26,
298,
435,
620,
8,
10756,
63,
2697,
9,
435,
298,
1343,
26,
298,
435,
620,
8,
928,
9,
435,
881,
298,
1284,
26,
298,
435,
620,
8,
500,
9,
435,
1867,
78,
531,
489,
746,
4520,
480,
705,
531,
272,
372,
334,
1562,
2956,
59,
10756,
63,
2697,
467,
1568,
9,
523,
587,
26,
272,
12995,
3316,
275,
1343,
435,
3666,
500,
446,
1343,
9,
1182,
499,
9,
272,
334,
10756,
63,
2697,
12,
1568,
9,
275,
3747,
1123,
2393,
59,
10220,
3316,
61,
272,
340,
334,
2697,
2356,
16751,
63,
2697,
436,
5552,
665,
16751,
63,
2697,
435,
1568,
304,
489,
372,
334,
1562,
2956,
59,
10756,
63,
2697,
467,
1568,
9,
272,
916,
334,
2697,
665,
16751,
63,
2697,
304,
489,
372,
3366,
63,
1733,
334,
2697,
12,
1343,
12,
12995,
3316,
9,
272,
916,
334,
2697,
2356,
16751,
63,
2697,
435,
1568,
304,
489,
372,
3366,
63,
1733,
334,
2697,
12,
12995,
3316,
12,
1284,
9,
272,
587,
26,
489,
746,
298,
3170,
26,
8103,
440,
4282,
642,
1930,
2,
199,
199,
70,
275,
1551,
334,
1648,
493,
9,
199,
1278,
275,
289,
14,
9684,
342,
199,
2913,
68,
63,
513,
275,
942,
199,
509,
1004,
315,
2385,
26,
523,
340,
334,
604,
14,
1913,
342,
508,
21019,
272,
1980,
523,
805,
985,
275,
1004,
14,
1814,
5175,
505,
3130,
12548,
1294,
5175,
6311,
2659,
59,
16,
1055,
1913,
342,
523,
4690,
68,
63,
513,
14,
740,
334,
1593,
985,
9,
199,
199,
3,
10080,
1561,
787,
440,
3747,
14,
221,
9336,
314,
1865,
570,
4440,
5272,
1561,
12,
314,
199,
3,
19483,
1865,
570,
299,
13072,
315,
1006,
6698,
543,
314,
2011,
536,
14,
221,
14326,
805,
199,
3,
7149,
367,
314,
2011,
805,
536,
1443,
2597,
506,
7037,
370,
3680,
6311,
2,
6698,
12,
199,
3,
3967,
314,
20597,
365,
14489,
14,
199,
5777,
275,
942,
199,
1593,
1476,
2956,
275,
1052,
199,
509,
1004,
315,
16751,
1278,
26,
523,
862,
26,
272,
805,
985,
275,
1004,
14,
1294,
3430,
19,
61,
523,
871,
26,
272,
805,
985,
275,
1004,
14,
1294,
3430,
18,
61,
523,
805,
985,
275,
805,
985,
14,
1294,
5175,
6311,
2659,
59,
16,
61,
523,
805,
1476,
275,
1109,
334,
604,
14,
1294,
3430,
16,
1055,
1913,
1062,
3193,
9,
523,
862,
26,
272,
805,
1476,
2956,
59,
1593,
985,
1055,
740,
8,
1593,
1476,
9,
523,
871,
26,
272,
805,
1476,
2956,
59,
1593,
985,
61,
275,
359,
1593,
1476,
61,
272,
3423,
14,
740,
8,
1593,
985,
9,
199,
199,
1274,
14,
3083,
14,
952,
1689,
2913,
68,
769,
1568,
26,
298,
435,
620,
8,
552,
8,
2913,
68,
63,
513,
430,
435,
1867,
78,
531,
199,
7423,
275,
942,
199,
7450,
63,
4214,
275,
378,
199,
509,
805,
315,
4690,
68,
63,
513,
26,
2043,
862,
26,
1362,
29259,
275,
805,
1476,
2956,
59,
1593,
61,
1362,
6698,
63,
4214,
275,
6698,
63,
4214,
435,
413,
2043,
871,
26,
1362,
29259,
275,
942,
1362,
327,
984,
14,
3083,
14,
952,
1689,
9171,
26,
4293,
440,
2342,
5272,
298,
435,
805,
435,
1867,
78,
531,
2043,
367,
5552,
315,
29259,
26,
1362,
340,
440,
334,
2697,
315,
7149,
304,
2126,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@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: infini_vol
version_added: 2.3
short_description: Create, Delete or Modify volumes on Infinibox
description:
- This module creates, deletes or modifies volume on Infinibox.
author: Gregory Shulov (@GR360RY)
options:
name:
description:
- Volume Name
required: true
state:
description:
- Creates/Modifies volume when present or removes when absent
required: false
default: present
choices: [ "present", "absent" ]
size:
description:
- Volume size in MB, GB or TB units. See examples.
required: false
pool:
description:
- Pool that volume will reside on
required: true
extends_documentation_fragment:
- infinibox
'''
EXAMPLES = '''
- name: Create new volume named foo under pool named bar
infini_vol:
name: foo
size: 1TB
pool: bar
state: present
user: admin
password: secret
system: ibox001
'''
RETURN = '''
'''
HAS_INFINISDK = True
try:
from infinisdk import InfiniBox, core
except ImportError:
HAS_INFINISDK = False
from ansible.module_utils.infinibox import *
from capacity import KiB, Capacity
@api_wrapper
def get_pool(module, system):
"""Return Pool or None"""
try:
return system.pools.get(name=module.params['pool'])
except:
return None
@api_wrapper
def get_volume(module, system):
"""Return Volume or None"""
try:
return system.volumes.get(name=module.params['name'])
except:
return None
@api_wrapper
def create_volume(module, system):
"""Create Volume"""
if not module.check_mode:
volume = system.volumes.create(name=module.params['name'], pool=get_pool(module, system))
if module.params['size']:
size = Capacity(module.params['size']).roundup(64 * KiB)
volume.update_size(size)
module.exit_json(changed=True)
@api_wrapper
def update_volume(module, volume):
"""Update Volume"""
changed = False
if module.params['size']:
size = Capacity(module.params['size']).roundup(64 * KiB)
if volume.get_size() != size:
if not module.check_mode:
volume.update_size(size)
changed = True
module.exit_json(changed=changed)
@api_wrapper
def delete_volume(module, volume):
""" Delete Volume"""
if not module.check_mode:
volume.delete()
module.exit_json(changed=True)
def main():
argument_spec = infinibox_argument_spec()
argument_spec.update(
dict(
name = dict(required=True),
state = dict(default='present', choices=['present', 'absent']),
pool = dict(required=True),
size = dict()
)
)
module = AnsibleModule(argument_spec, supports_check_mode=True)
if not HAS_INFINISDK:
module.fail_json(msg='infinisdk is required for this module')
if module.params['size']:
try:
Capacity(module.params['size'])
except:
module.fail_json(msg='size (Physical Capacity) should be defined in MB, GB, TB or PB units')
state = module.params['state']
system = get_system(module)
pool = get_pool(module, system)
volume = get_volume(module, system)
if pool is None:
module.fail_json(msg='Pool {} not found'.format(module.params['pool']))
if state == 'present' and not volume:
create_volume(module, system)
elif state == 'present' and volume:
update_volume(module, volume)
elif state == 'absent' and volume:
delete_volume(module, volume)
elif state == 'absent' and not volume:
module.exit_json(changed=False)
# Import Ansible Utilities
from ansible.module_utils.basic import AnsibleModule
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,
29096,
1089,
5244,
13957,
86,
334,
3939,
1089,
14,
609,
13957,
86,
32,
6799,
14,
957,
9,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
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,
315,
7295,
63,
5650,
199,
1023,
63,
3270,
26,
499,
14,
19,
199,
3612,
63,
1802,
26,
221,
2790,
12,
8496,
503,
22520,
12158,
641,
1010,
7295,
1977,
199,
1802,
26,
272,
446,
961,
859,
8491,
12,
21812,
503,
26473,
3301,
641,
1010,
7295,
1977,
14,
199,
2502,
26,
29096,
1089,
5244,
13957,
86,
8593,
3975,
11197,
5782,
9,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
15018,
2812,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
10560,
15,
7469,
5604,
3301,
1380,
3451,
503,
14185,
1380,
9552,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
523,
1568,
26,
272,
1369,
26,
489,
446,
15018,
1568,
315,
19487,
12,
18553,
503,
377,
34,
6204,
14,
1666,
7251,
14,
272,
1415,
26,
3055,
523,
4203,
26,
272,
1369,
26,
489,
446,
15553,
626,
3301,
911,
295,
2441,
641,
272,
1415,
26,
2549,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
315,
7295,
1977,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
892,
3301,
4310,
3925,
1334,
4203,
4310,
4681,
523,
315,
7295,
63,
5650,
26,
272,
536,
26,
3925,
272,
1568,
26,
413,
20098,
272,
4203,
26,
4681,
272,
1174,
26,
3451,
272,
922,
26,
4628,
272,
2505,
26,
7565,
272,
2656,
26,
284,
1977,
4587,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2344,
199,
199,
13533,
63,
32191,
1311,
10892,
275,
715,
199,
893,
26,
272,
687,
315,
2408,
374,
6341,
492,
1010,
7295,
3532,
12,
6170,
199,
2590,
3545,
26,
272,
7509,
63,
32191,
1311,
10892,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
262,
7295,
1977,
492,
627,
199,
504,
14893,
492,
1804,
17587,
12,
8790,
6192,
421,
199,
32,
1246,
63,
5029,
199,
318,
664,
63,
2293,
8,
578,
12,
2656,
304,
272,
408,
1767,
15553,
503,
488,
624,
272,
862,
26,
267,
372,
2656,
14,
12406,
14,
362,
8,
354,
29,
578,
14,
1162,
459,
2293,
1105,
272,
871,
26,
267,
372,
488,
421,
199,
32,
1246,
63,
5029,
199,
318,
664,
63,
2405,
8,
578,
12,
2656,
304,
272,
408,
1767,
15018,
503,
488,
624,
272,
862,
26,
267,
372,
2656,
14,
8838,
14,
362,
8,
354,
29,
578,
14,
1162,
459,
354,
1105,
272,
871,
26,
267,
372,
488,
421,
199,
32,
1246,
63,
5029,
199,
318,
1218,
63,
2405,
8,
578,
12,
2656,
304,
272,
408,
2499,
15018,
624,
272,
340,
440,
859,
14,
1074,
63,
632,
26,
267,
3301,
275,
2656,
14,
8838,
14,
981,
8,
354,
29,
578,
14,
1162,
459,
354,
995,
4203,
29,
362,
63,
2293,
8,
578,
12,
2656,
430,
267,
340,
859,
14,
1162,
459,
890,
2565,
288,
1568,
275,
8790,
6192,
8,
578,
14,
1162,
459,
890,
13227,
2363,
384,
8,
772,
627,
1804,
17587,
9,
288,
3301,
14,
873,
63,
890,
8,
890,
9,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
421,
199,
32,
1246,
63,
5029,
199,
318,
1678,
63,
2405,
8,
578,
12,
3301,
304,
272,
408,
4152,
15018,
624,
272,
2896,
275,
756,
272,
340,
859,
14,
1162,
459,
890,
2565,
267,
1568,
275,
8790,
6192,
8,
578,
14,
1162,
459,
890,
13227,
2363,
384,
8,
772,
627,
1804,
17587,
9,
267,
340,
3301,
14,
362,
63,
890,
342,
1137,
1568,
26,
288,
340,
440,
859,
14,
1074,
63,
632,
26,
355,
3301,
14,
873,
63,
890,
8,
890,
9,
288,
2896,
275,
715,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
9,
421,
199,
32,
1246,
63,
5029,
199,
318,
3145,
63,
2405,
8,
578,
12,
3301,
304,
272,
408,
8496,
15018,
624,
272,
340,
440,
859,
14,
1074,
63,
632,
26,
267,
3301,
14,
1807,
342,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
315,
7295,
1977,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
536,
221,
275,
1211,
8,
2427,
29,
549,
395,
288,
1174,
275,
1211,
8,
885,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
3815,
288,
4203,
221,
275,
1211,
8,
2427,
29,
549,
395,
288,
1568,
221,
275,
1211,
342,
267,
776,
272,
776,
339,
859,
275,
6953,
8,
2094,
63,
1650,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
339,
340,
440,
7509,
63,
32191,
1311,
10892,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
262,
2408,
374,
6341,
365,
1415,
367,
642,
859,
358,
339,
340,
859,
14,
1162,
459,
890,
2565,
267,
862,
26,
288,
8790,
6192,
8,
578,
14,
1162,
459,
890,
1105,
267,
871,
26,
288,
859,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
7800,
12,
29096,
1089,
5244,
13957,
86,
334,
3939,
1089,
14,
609,
13957,
86,
32,
6799,
14,
957,
9,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
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,
315,
7295,
63,
5650,
199,
1023,
63,
3270,
26,
499,
14,
19,
199,
3612,
63,
1802,
26,
221,
2790,
12,
8496,
503,
22520,
12158,
641,
1010,
7295,
1977,
199,
1802,
26,
272,
446,
961,
859,
8491,
12,
21812,
503,
26473,
3301,
641,
1010,
7295,
1977,
14,
199,
2502,
26,
29096,
1089,
5244,
13957,
86,
8593,
3975,
11197,
5782,
9,
199,
1419,
26,
523,
536,
26,
272,
1369,
26,
489,
446,
15018,
2812,
272,
1415,
26,
2549,
523,
1174,
26,
272,
1369,
26,
489,
446,
10560,
15,
7469,
5604,
3301,
1380,
3451,
503,
14185,
1380,
9552,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
359,
298,
1881,
401,
298,
5575,
2,
1622,
523,
1568,
26,
272,
1369,
26,
489,
446,
15018,
1568,
315,
19487,
12,
18553,
503,
377,
34,
6204,
14,
1666,
7251,
14,
272,
1415,
26,
3055,
523,
4203,
26,
272,
1369,
26,
489,
446,
15553,
626,
3301,
911,
295,
2441,
641,
272,
1415,
26,
2549,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
315,
7295,
1977,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
892,
3301,
4310,
3925,
1334,
4203,
4310,
4681,
523,
315,
7295,
63,
5650,
26,
272,
536,
26,
3925,
272,
1568,
26,
413,
20098,
272,
4203,
26,
4681,
272,
1174,
26,
3451,
272,
922,
26,
4628,
272,
2505,
26,
7565,
272,
2656,
26,
284,
1977,
4587,
199,
2344,
199,
199,
9677,
275,
1449,
199,
2344,
199,
199,
13533,
63,
32191,
1311,
10892,
275,
715,
199,
893,
26,
272,
687,
315,
2408,
374,
6341,
492,
1010,
7295,
3532,
12,
6170,
199,
2590,
3545,
26,
272,
7509,
63,
32191,
1311,
10892,
275,
756,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
262,
7295,
1977,
492,
627,
199,
504,
14893,
492,
1804,
17587,
12,
8790,
6192,
421,
199,
32,
1246,
63,
5029,
199,
318,
664,
63,
2293,
8,
578,
12,
2656,
304,
272,
408,
1767,
15553,
503,
488,
624,
272,
862,
26,
267,
372,
2656,
14,
12406,
14,
362,
8,
354,
29,
578,
14,
1162,
459,
2293,
1105,
272,
871,
26,
267,
372,
488,
421,
199,
32,
1246,
63,
5029,
199,
318,
664,
63,
2405,
8,
578,
12,
2656,
304,
272,
408,
1767,
15018,
503,
488,
624,
272,
862,
26,
267,
372,
2656,
14,
8838,
14,
362,
8,
354,
29,
578,
14,
1162,
459,
354,
1105,
272,
871,
26,
267,
372,
488,
421,
199,
32,
1246,
63,
5029,
199,
318,
1218,
63,
2405,
8,
578,
12,
2656,
304,
272,
408,
2499,
15018,
624,
272,
340,
440,
859,
14,
1074,
63,
632,
26,
267,
3301,
275,
2656,
14,
8838,
14,
981,
8,
354,
29,
578,
14,
1162,
459,
354,
995,
4203,
29,
362,
63,
2293,
8,
578,
12,
2656,
430,
267,
340,
859,
14,
1162,
459,
890,
2565,
288,
1568,
275,
8790,
6192,
8,
578,
14,
1162,
459,
890,
13227,
2363,
384,
8,
772,
627,
1804,
17587,
9,
288,
3301,
14,
873,
63,
890,
8,
890,
9,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
421,
199,
32,
1246,
63,
5029,
199,
318,
1678,
63,
2405,
8,
578,
12,
3301,
304,
272,
408,
4152,
15018,
624,
272,
2896,
275,
756,
272,
340,
859,
14,
1162,
459,
890,
2565,
267,
1568,
275,
8790,
6192,
8,
578,
14,
1162,
459,
890,
13227,
2363,
384,
8,
772,
627,
1804,
17587,
9,
267,
340,
3301,
14,
362,
63,
890,
342,
1137,
1568,
26,
288,
340,
440,
859,
14,
1074,
63,
632,
26,
355,
3301,
14,
873,
63,
890,
8,
890,
9,
288,
2896,
275,
715,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
9,
421,
199,
32,
1246,
63,
5029,
199,
318,
3145,
63,
2405,
8,
578,
12,
3301,
304,
272,
408,
8496,
15018,
624,
272,
340,
440,
859,
14,
1074,
63,
632,
26,
267,
3301,
14,
1807,
342,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
315,
7295,
1977,
63,
2094,
63,
1650,
342,
272,
1423,
63,
1650,
14,
873,
8,
267,
1211,
8,
288,
536,
221,
275,
1211,
8,
2427,
29,
549,
395,
288,
1174,
275,
1211,
8,
885,
534,
1881,
297,
3415,
2968,
1881,
297,
283,
5575,
3815,
288,
4203,
221,
275,
1211,
8,
2427,
29,
549,
395,
288,
1568,
221,
275,
1211,
342,
267,
776,
272,
776,
339,
859,
275,
6953,
8,
2094,
63,
1650,
12,
5171,
63,
1074,
63,
632,
29,
549,
9,
339,
340,
440,
7509,
63,
32191,
1311,
10892,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
262,
2408,
374,
6341,
365,
1415,
367,
642,
859,
358,
339,
340,
859,
14,
1162,
459,
890,
2565,
267,
862,
26,
288,
8790,
6192,
8,
578,
14,
1162,
459,
890,
1105,
267,
871,
26,
288,
859,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
alfa-addon/addon
|
plugin.video.alfa/channels/vi2.py
|
1
|
11788
|
# -*- coding: utf-8 -*-
# -*- Channel Vi2.co -*-
# -*- Created for Alfa-addon -*-
# -*- By the Alfa Develop Group -*-
import sys
PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
import re
import base64
from channelselector import get_thumb
from core import httptools
from core import jsontools
from core import scrapertools
from core import servertools
from core import tmdb
from lib import jsunpack
from core.item import Item
from channels import filtertools
from channels import autoplay
from platformcode import config, logger
IDIOMAS = {'Latino': 'LAT', 'Español':'CAST', 'Subtitulado': 'VOSE', 'VO': 'VO'}
list_language = list(IDIOMAS.values())
list_quality = ['Full HD 1080p',
'HDRip',
'DVDScreener',
'720p',
'Ts Screener hq',
'HD Real 720p',
'DVDRip',
'BluRay-1080p',
'BDremux-1080p']
list_servers = [
'directo',
'openload',
'rapidvideo',
'jawcloud',
'cloudvideo',
'upvid',
'vevio',
'gamovideo'
]
host = 'http://vi2.co'
def mainlist(item):
logger.info()
autoplay.init(item.channel, list_servers, list_quality)
itemlist = []
itemlist.append(Item(channel=item.channel, title='Peliculas', action='select_menu', type='peliculas',
thumbnail= get_thumb('movies', auto=True)))
# itemlist.append(Item(channel=item.channel, title='Series', url=host+'serie', action='select_menu', type='series',
# thumbnail= get_thumb('tvshows', auto=True)))
autoplay.show_option(item.channel, itemlist)
return itemlist
def select_menu(item):
logger.info()
itemlist=[]
url = host + '/%s/es/' % item.type
itemlist.append(Item(channel=item.channel, title='Streaming', action='sub_menu',
thumbnail=get_thumb('all', auto=True), type=item.type))
itemlist.append(Item(channel=item.channel, title='Torrent', action='sub_menu',
thumbnail=get_thumb('all', auto=True), type=item.type))
itemlist.append(Item(channel=item.channel, title='Generos', action='section', url=url,
thumbnail=get_thumb('genres', auto=True), type='all'))
itemlist.append(Item(channel=item.channel, title='Por Año', action='section', url=url,
thumbnail=get_thumb('year', auto=True), type='all'))
return itemlist
def sub_menu(item):
logger.info()
itemlist = []
url = host + '/%s/es/ajax/1/' % item.type
link_type = item.title.lower()
if link_type == 'streaming':
link_type = 'flash'
movies_options = ['Todas', 'Castellano', 'Latino', 'VOSE']
tv_options = ['Ultimas', 'Ultimas Castellano', 'Ultimas Latino', 'Ultimas VOSE']
if item.type == 'peliculas':
title = movies_options
thumb_1 = 'all'
else:
thumb_1 = 'last'
title = tv_options
itemlist.append(Item(channel=item.channel, title=title[0], url=url+'?q=%s' % link_type,
action='list_all', thumbnail=get_thumb(thumb_1, auto=True), type=item.type,
link_type=link_type))
itemlist.append(Item(channel=item.channel, title=title[1],
url=url + '?q=%s+espanol' % link_type, action='list_all',
thumbnail=get_thumb('cast', auto=True), type=item.type, send_lang='Español',
link_type=link_type))
itemlist.append(Item(channel=item.channel, title=title[2],
url=url + '?q=%s+latino' % link_type, action='list_all',
thumbnail=get_thumb('lat', auto=True), type=item.type, send_lang='Latino',
link_type=link_type))
itemlist.append(Item(channel=item.channel, title=title[3],
url=url + '?q=%s+subtitulado' % link_type, action='list_all',
thumbnail=get_thumb('vose', auto=True), type=item.type, send_lang='VOSE',
link_type=link_type))
itemlist.append(Item(channel=item.channel, title="Buscar", action="search", url=url + '?q=',
thumbnail=get_thumb("search", auto=True), type=item.type, link_type=link_type))
return itemlist
def get_source(url, referer=None):
logger.info()
if referer is None:
data = httptools.downloadpage(url).data
else:
data = httptools.downloadpage(url, headers={'Referer':referer}).data
data = re.sub(r'\n|\r|\t| |<br>|\s{2,}', "", data)
return data
def section(item):
logger.info()
itemlist=[]
excluded = ['latino', 'español', 'subtitulado', 'v.o.', 'streaming', 'torrent']
full_data = get_source(item.url)
data = scrapertools.find_single_match(full_data, 'toptags-container(.*?)<div class="android-more-section">')
patron = 'href="([^"]+)">([^<]+)<'
matches = re.compile(patron, re.DOTALL).findall(data)
for scrapedurl, scrapedtitle in matches:
title = scrapedtitle
url = host+scrapedurl.replace('/?','/ajax/1/?')
if (item.title=='Generos' and title.lower() not in excluded and not title.isdigit()) or (item.title=='Por Año' and title.isdigit()):
itemlist.append(Item(channel=item.channel, url=url, title=title, action='list_all', type=item.type))
return itemlist
def list_all(item):
from core import jsontools
logger.info()
itemlist = []
listed =[]
quality=''
infoLabels = {}
json_data= jsontools.load(get_source(item.url))
data = json_data['render']
data = re.sub(r'\n|\r|\t| |<br>|\s{2,}', "", data)
#if item.type == 'peliculas':
patron = '<img\s*class="cover"[^>]+src="([^"]+)"\s*data-id="\d+"\s*'
patron +='alt="Ver\s*([^\(]+)(.*?)">\s*'
patron += '<div\s*class="mdl-card__menu">\s*<a\s*class="clean-link"\s*href="([^"]+)">'
patron += '.*?<span\s*class="link-size">([^<]*)<'
matches = re.compile(patron, re.DOTALL).findall(data)
for scrapedthumbnail, scrapedtitle, extra_info, scrapedurl , size in matches:
if item.send_lang != '':
lang = item.send_lang
else:
lang = ''
year='-'
extra_info = extra_info.replace('(', '|').replace('[','|').replace(')','').replace(']','')
extra_info = extra_info.split('|')
for info in extra_info:
info = info.strip()
if 'Rip' in info or '1080' in info or '720' in info or 'Screener' in info:
quality = info
if 'ingl' in info.lower():
info = 'VO'
if info in IDIOMAS:
lang = info
elif info.isdigit():
year = info
if lang in IDIOMAS:
lang = IDIOMAS[lang]
title = '%s' % scrapedtitle.strip()
if not config.get_setting('unify'):
if year.isdigit():
title = '%s [%s]' % (title, year)
if quality != '':
title = '%s [%s]' % (title, quality)
if lang != '':
title = '%s [%s]' % (title, lang)
thumbnail = host+scrapedthumbnail
url = host+scrapedurl
if item.type == 'series':
season, episode = scrapertools.find_single_match(scrapedtitle, '(\d+)x(\d+)')
infoLabels['season'] = season
infoLabels['episode'] = episode
else:
infoLabels['year'] = year
if title not in listed:
new_item = Item(channel=item.channel,
title=title,
url=url,
action='findvideos',
thumbnail=thumbnail,
type=item.type,
language = lang,
quality=quality,
link_type=item.link_type,
torrent_data= size,
infoLabels = infoLabels
)
if item.type == 'peliculas' or item.type == 'all':
new_item.contentTitle = scrapedtitle
else:
scrapedtitle = scrapedtitle.split(' - ')
new_item.contentSerieName = scrapedtitle[0]
itemlist.append(new_item)
listed.append(title)
tmdb.set_infoLabels(itemlist, seekTmdb=True)
itemlist.sort(key=lambda it: it.title)
# Paginación
if json_data['next']:
actual_page = scrapertools.find_single_match(item.url, 'ajax/(\d+)/')
next_page =int(actual_page) + 1
url_next_page = item.url.replace('ajax/%s' % actual_page, 'ajax/%s' % next_page)
itemlist.append(item.clone(title="Siguiente >>", url=url_next_page, type=item.type,
action='list_all', send_lang=item.send_lang))
return itemlist
def findvideos(item):
logger.info()
import base64
itemlist = []
server = ''
data = get_source(item.url)
pre_url = scrapertools.find_single_match(data, 'class="inside-link" href="([^"]+)".*?<button type="button"')
data = get_source(host+pre_url)
patron = 'data-video="([^"]+)"'
matches = re.compile(patron, re.DOTALL).findall(data)
lang = item.language
quality = item.quality
for url in matches:
title = ''
link_type = ''
server = ''
url = base64.b64decode(url.encode('utf8')).decode('utf8')
if 'torrent' in url:
if item.link_type == 'torrent' or item.type == 'all':
server = 'torrent'
link_type = 'torrent'
title = ' [%s]' % item.torrent_data
elif 'torrent' not in url:
link_type = 'flash'
if link_type == item.link_type.lower() or item.type == 'all':
itemlist.append(Item(channel=item.channel, url=url, title='%s'+title, action='play', server=server,
language=lang, quality=quality, infoLabels=item.infoLabels))
itemlist = servertools.get_servers_itemlist(itemlist, lambda x: x.title % x.server.capitalize())
# Requerido para FilterTools
itemlist = filtertools.get_links(itemlist, item, list_language)
# Requerido para AutoPlay
autoplay.start(itemlist, item)
itemlist = sorted(itemlist, key=lambda it: it.language)
if item.contentType != 'episode':
if config.get_videolibrary_support() and len(itemlist) > 0 and item.extra != 'findvideos':
itemlist.append(
Item(channel=item.channel, title='[COLOR yellow]Añadir esta pelicula a la videoteca[/COLOR]', url=item.url,
action="add_pelicula_to_library", extra="findvideos", contentTitle=item.contentTitle))
return itemlist
def search(item, texto):
logger.info()
texto = texto.replace(" ", "+")
url = '%spelicula+%s+%s&o=2' % (item.url, texto, item.link_type)
#Parche busqueda global (solo vale para peliculas en streaming)
if not item.url:
item.type = 'peliculas'
item.link_type = 'flash'
ajax = '%s/%s/es/ajax/1/' % (host, item.type)
url = '%s?q=%s+%s+%s&o=2' % (ajax, item.type, texto, item.link_type)
item.url = url
try:
return list_all(item)
except:
import sys
for line in sys.exc_info():
logger.error("%s" % line)
return []
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
3,
1882,
17270,
6561,
18,
14,
331,
1882,
202,
199,
3,
1882,
18208,
367,
437,
276,
65,
13,
9291,
1882,
202,
199,
3,
1882,
4885,
314,
437,
276,
65,
1487,
7549,
5611,
1882,
2999,
199,
646,
984,
202,
199,
4521,
19,
275,
756,
202,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
7843,
19,
275,
715,
27,
2649,
275,
620,
27,
17742,
275,
8678,
27,
1846,
275,
1109,
2999,
199,
646,
295,
202,
199,
646,
1300,
772,
2999,
199,
504,
3623,
6662,
492,
664,
63,
16534,
202,
199,
504,
6170,
492,
1455,
2537,
202,
199,
504,
6170,
492,
2022,
2537,
202,
199,
504,
6170,
492,
28348,
202,
199,
504,
6170,
492,
1654,
2537,
202,
199,
504,
6170,
492,
7352,
697,
202,
199,
504,
1973,
492,
8586,
5301,
202,
199,
504,
6170,
14,
1053,
492,
7020,
202,
199,
504,
9245,
492,
2457,
2537,
202,
199,
504,
9245,
492,
6384,
411,
817,
202,
199,
504,
4298,
600,
492,
1101,
12,
2512,
8065,
199,
998,
2090,
45,
1179,
275,
791,
22510,
10175,
356,
283,
20307,
297,
283,
37,
3770,
22692,
393,
5242,
18898,
297,
283,
2610,
6403,
348,
5129,
356,
283,
10662,
899,
297,
283,
10662,
356,
283,
10662,
936,
202,
199,
513,
63,
3671,
275,
769,
8,
998,
2090,
45,
1179,
14,
1459,
1012,
2999,
199,
513,
63,
9161,
275,
788,
9042,
869,
36,
1616,
1257,
80,
297,
2628,
283,
40,
4564,
711,
297,
2628,
283,
6741,
3177,
1353,
727,
297,
2628,
283,
18386,
80,
297,
2628,
283,
23433,
428,
1353,
727,
394,
81,
297,
2628,
283,
14903,
14849,
29692,
80,
297,
2628,
283,
6741,
4564,
711,
297,
2628,
283,
34,
10836,
25474,
13,
23514,
80,
297,
2628,
283,
11156,
13179,
2521,
13,
23514,
80,
418,
2999,
199,
513,
63,
5871,
275,
359,
1128,
283,
2275,
79,
297,
1128,
283,
1490,
912,
297,
1128,
283,
1330,
344,
3722,
297,
1128,
283,
3387,
87,
4091,
297,
1128,
283,
4091,
3722,
297,
1128,
283,
384,
5017,
297,
1128,
283,
432,
32052,
297,
1128,
283,
71,
4393,
3722,
7,
202,
199,
61,
2999,
199,
1102,
275,
283,
1014,
921,
433,
18,
14,
331,
7,
2999,
199,
318,
2446,
513,
8,
1053,
304,
1128,
2512,
14,
815,
342,
2958,
6384,
411,
817,
14,
826,
8,
1053,
14,
2775,
12,
769,
63,
5871,
12,
769,
63,
9161,
9,
2958,
22921,
275,
942,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
8070,
606,
32646,
297,
1595,
534,
2416,
63,
4470,
297,
730,
534,
321,
606,
32646,
297,
202,
586,
10062,
29,
664,
63,
16534,
360,
20888,
297,
2599,
29,
549,
1724,
1128,
327,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
9641,
297,
1166,
29,
1102,
4786,
261,
11317,
297,
1595,
534,
2416,
63,
4470,
297,
730,
534,
5602,
297,
1128,
327,
10473,
10062,
29,
664,
63,
16534,
360,
6993,
23866,
297,
2599,
29,
549,
1724,
18801,
6384,
411,
817,
14,
2384,
63,
1422,
8,
1053,
14,
2775,
12,
22921,
9,
2958,
372,
22921,
2999,
199,
318,
3504,
63,
4470,
8,
1053,
304,
1128,
2512,
14,
815,
342,
2958,
22921,
9811,
1128,
1166,
275,
1591,
435,
1994,
5,
83,
15,
397,
4805,
450,
1242,
14,
466,
1128,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
22555,
297,
1595,
534,
954,
63,
4470,
297,
202,
586,
10062,
29,
362,
63,
16534,
360,
452,
297,
2599,
29,
549,
395,
730,
29,
1053,
14,
466,
430,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
32004,
297,
1595,
534,
954,
63,
4470,
297,
202,
586,
10062,
29,
362,
63,
16534,
360,
452,
297,
2599,
29,
549,
395,
730,
29,
1053,
14,
466,
430,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
3139,
736,
297,
1595,
534,
2792,
297,
1166,
29,
633,
12,
202,
586,
10062,
29,
362,
63,
16534,
360,
2268,
470,
297,
2599,
29,
549,
395,
730,
534,
452,
1333,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
48,
269,
437,
22692,
79,
297,
1595,
534,
2792,
297,
1166,
29,
633,
12,
202,
586,
10062,
29,
362,
63,
16534,
360,
3403,
297,
2599,
29,
549,
395,
730,
534,
452,
1333,
2958,
372,
22921,
2999,
199,
318,
1007,
63,
4470,
8,
1053,
304,
1128,
2512,
14,
815,
342,
2958,
22921,
275,
942,
1128,
1166,
275,
1591,
435,
1994,
5,
83,
15,
397,
15,
12774,
15,
17,
4805,
450,
1242,
14,
466,
1128,
2142,
63,
466,
275,
1242,
14,
1213,
14,
2325,
342,
1128,
340,
2142,
63,
466,
508,
283,
12076,
356,
1039,
2142,
63,
466,
275,
283,
11331,
7,
1128,
1303,
14484,
63,
1419,
275,
788,
52,
364,
305,
297,
283,
35,
9209,
914,
8143,
297,
283,
22510,
10175,
297,
283,
10662,
899,
418,
1128,
13466,
63,
1419,
275,
788,
18505,
2906,
305,
297,
283,
18505,
2906,
305,
445,
9209,
914,
8143,
297,
283,
18505,
2906,
305,
491,
292,
10175,
297,
283,
18505,
2906,
305,
812,
47,
899,
418,
2958,
340,
1242,
14,
466,
508,
283,
321,
606,
32646,
356,
1039,
2538,
275,
1303,
14484,
63,
1419,
1039,
21541,
63,
17,
275,
283,
452,
7,
1128,
587,
26,
1039,
21541,
63,
17,
275,
283,
2019,
7,
1039,
2538,
275,
13466,
63,
1419,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
29,
1213,
59,
16,
467,
1166,
29,
633,
4786,
31,
81,
2458,
83,
7,
450,
2142,
63,
466,
12,
202,
586,
1595,
534,
513,
63,
452,
297,
10062,
29,
362,
63,
16534,
8,
16534,
63,
17,
12,
2599,
29,
549,
395,
730,
29,
1053,
14,
466,
12,
202,
586,
2142,
63,
466,
29,
1073,
63,
466,
430,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
29,
1213,
59,
17,
467,
202,
586,
1166,
29,
633,
435,
8720,
81,
2458,
83,
11,
397,
10384,
393,
7,
450,
2142,
63,
466,
12,
1595,
534,
513,
63,
452,
297,
202,
586,
10062,
29,
362,
63,
16534,
360,
2931,
297,
2599,
29,
549
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
3,
1882,
17270,
6561,
18,
14,
331,
1882,
202,
199,
3,
1882,
18208,
367,
437,
276,
65,
13,
9291,
1882,
202,
199,
3,
1882,
4885,
314,
437,
276,
65,
1487,
7549,
5611,
1882,
2999,
199,
646,
984,
202,
199,
4521,
19,
275,
756,
202,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
7843,
19,
275,
715,
27,
2649,
275,
620,
27,
17742,
275,
8678,
27,
1846,
275,
1109,
2999,
199,
646,
295,
202,
199,
646,
1300,
772,
2999,
199,
504,
3623,
6662,
492,
664,
63,
16534,
202,
199,
504,
6170,
492,
1455,
2537,
202,
199,
504,
6170,
492,
2022,
2537,
202,
199,
504,
6170,
492,
28348,
202,
199,
504,
6170,
492,
1654,
2537,
202,
199,
504,
6170,
492,
7352,
697,
202,
199,
504,
1973,
492,
8586,
5301,
202,
199,
504,
6170,
14,
1053,
492,
7020,
202,
199,
504,
9245,
492,
2457,
2537,
202,
199,
504,
9245,
492,
6384,
411,
817,
202,
199,
504,
4298,
600,
492,
1101,
12,
2512,
8065,
199,
998,
2090,
45,
1179,
275,
791,
22510,
10175,
356,
283,
20307,
297,
283,
37,
3770,
22692,
393,
5242,
18898,
297,
283,
2610,
6403,
348,
5129,
356,
283,
10662,
899,
297,
283,
10662,
356,
283,
10662,
936,
202,
199,
513,
63,
3671,
275,
769,
8,
998,
2090,
45,
1179,
14,
1459,
1012,
2999,
199,
513,
63,
9161,
275,
788,
9042,
869,
36,
1616,
1257,
80,
297,
2628,
283,
40,
4564,
711,
297,
2628,
283,
6741,
3177,
1353,
727,
297,
2628,
283,
18386,
80,
297,
2628,
283,
23433,
428,
1353,
727,
394,
81,
297,
2628,
283,
14903,
14849,
29692,
80,
297,
2628,
283,
6741,
4564,
711,
297,
2628,
283,
34,
10836,
25474,
13,
23514,
80,
297,
2628,
283,
11156,
13179,
2521,
13,
23514,
80,
418,
2999,
199,
513,
63,
5871,
275,
359,
1128,
283,
2275,
79,
297,
1128,
283,
1490,
912,
297,
1128,
283,
1330,
344,
3722,
297,
1128,
283,
3387,
87,
4091,
297,
1128,
283,
4091,
3722,
297,
1128,
283,
384,
5017,
297,
1128,
283,
432,
32052,
297,
1128,
283,
71,
4393,
3722,
7,
202,
199,
61,
2999,
199,
1102,
275,
283,
1014,
921,
433,
18,
14,
331,
7,
2999,
199,
318,
2446,
513,
8,
1053,
304,
1128,
2512,
14,
815,
342,
2958,
6384,
411,
817,
14,
826,
8,
1053,
14,
2775,
12,
769,
63,
5871,
12,
769,
63,
9161,
9,
2958,
22921,
275,
942,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
8070,
606,
32646,
297,
1595,
534,
2416,
63,
4470,
297,
730,
534,
321,
606,
32646,
297,
202,
586,
10062,
29,
664,
63,
16534,
360,
20888,
297,
2599,
29,
549,
1724,
1128,
327,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
9641,
297,
1166,
29,
1102,
4786,
261,
11317,
297,
1595,
534,
2416,
63,
4470,
297,
730,
534,
5602,
297,
1128,
327,
10473,
10062,
29,
664,
63,
16534,
360,
6993,
23866,
297,
2599,
29,
549,
1724,
18801,
6384,
411,
817,
14,
2384,
63,
1422,
8,
1053,
14,
2775,
12,
22921,
9,
2958,
372,
22921,
2999,
199,
318,
3504,
63,
4470,
8,
1053,
304,
1128,
2512,
14,
815,
342,
2958,
22921,
9811,
1128,
1166,
275,
1591,
435,
1994,
5,
83,
15,
397,
4805,
450,
1242,
14,
466,
1128,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
22555,
297,
1595,
534,
954,
63,
4470,
297,
202,
586,
10062,
29,
362,
63,
16534,
360,
452,
297,
2599,
29,
549,
395,
730,
29,
1053,
14,
466,
430,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
32004,
297,
1595,
534,
954,
63,
4470,
297,
202,
586,
10062,
29,
362,
63,
16534,
360,
452,
297,
2599,
29,
549,
395,
730,
29,
1053,
14,
466,
430,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
3139,
736,
297,
1595,
534,
2792,
297,
1166,
29,
633,
12,
202,
586,
10062,
29,
362,
63,
16534,
360,
2268,
470,
297,
2599,
29,
549,
395,
730,
534,
452,
1333,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
534,
48,
269,
437,
22692,
79,
297,
1595,
534,
2792,
297,
1166,
29,
633,
12,
202,
586,
10062,
29,
362,
63,
16534,
360,
3403,
297,
2599,
29,
549,
395,
730,
534,
452,
1333,
2958,
372,
22921,
2999,
199,
318,
1007,
63,
4470,
8,
1053,
304,
1128,
2512,
14,
815,
342,
2958,
22921,
275,
942,
1128,
1166,
275,
1591,
435,
1994,
5,
83,
15,
397,
15,
12774,
15,
17,
4805,
450,
1242,
14,
466,
1128,
2142,
63,
466,
275,
1242,
14,
1213,
14,
2325,
342,
1128,
340,
2142,
63,
466,
508,
283,
12076,
356,
1039,
2142,
63,
466,
275,
283,
11331,
7,
1128,
1303,
14484,
63,
1419,
275,
788,
52,
364,
305,
297,
283,
35,
9209,
914,
8143,
297,
283,
22510,
10175,
297,
283,
10662,
899,
418,
1128,
13466,
63,
1419,
275,
788,
18505,
2906,
305,
297,
283,
18505,
2906,
305,
445,
9209,
914,
8143,
297,
283,
18505,
2906,
305,
491,
292,
10175,
297,
283,
18505,
2906,
305,
812,
47,
899,
418,
2958,
340,
1242,
14,
466,
508,
283,
321,
606,
32646,
356,
1039,
2538,
275,
1303,
14484,
63,
1419,
1039,
21541,
63,
17,
275,
283,
452,
7,
1128,
587,
26,
1039,
21541,
63,
17,
275,
283,
2019,
7,
1039,
2538,
275,
13466,
63,
1419,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
29,
1213,
59,
16,
467,
1166,
29,
633,
4786,
31,
81,
2458,
83,
7,
450,
2142,
63,
466,
12,
202,
586,
1595,
534,
513,
63,
452,
297,
10062,
29,
362,
63,
16534,
8,
16534,
63,
17,
12,
2599,
29,
549,
395,
730,
29,
1053,
14,
466,
12,
202,
586,
2142,
63,
466,
29,
1073,
63,
466,
430,
2958,
22921,
14,
740,
8,
2081,
8,
2775,
29,
1053,
14,
2775,
12,
2538,
29,
1213,
59,
17,
467,
202,
586,
1166,
29,
633,
435,
8720,
81,
2458,
83,
11,
397,
10384,
393,
7,
450,
2142,
63,
466,
12,
1595,
534,
513,
63,
452,
297,
202,
586,
10062,
29,
362,
63,
16534,
360,
2931,
297,
2599,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jonathonwalz/ansible
|
lib/ansible/modules/network/eos/eos_command.py
|
58
|
7620
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'core'}
DOCUMENTATION = """
---
module: eos_command
version_added: "2.1"
author: "Peter Sprygada (@privateip)"
short_description: Run arbitrary commands on an Arista EOS device
description:
- Sends an arbitrary set of commands to an EOS node and returns the results
read from the device. This module includes an
argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met.
extends_documentation_fragment: eos
options:
commands:
description:
- The commands to send to the remote EOS device over the
configured provider. The resulting output from the command
is returned. If the I(wait_for) argument is provided, the
module is not returned until the condition is satisfied or
the number of I(retries) has been exceeded.
required: true
wait_for:
description:
- Specifies what to evaluate from the output of the command
and what conditionals to apply. This argument will cause
the task to wait for a particular conditional to be true
before moving forward. If the conditional is not true
by the configured retries, the task fails. See examples.
required: false
default: null
aliases: ['waitfor']
version_added: "2.2"
match:
description:
- The I(match) argument is used in conjunction with the
I(wait_for) argument to specify the match policy. Valid
values are C(all) or C(any). If the value is set to C(all)
then all conditionals in the I(wait_for) must be satisfied. If
the value is set to C(any) then only one of the values must be
satisfied.
required: false
default: all
choices: ['any', 'all']
version_added: "2.2"
retries:
description:
- Specifies the number of retries a command should be tried
before it is considered failed. The command is run on the
target device every retry and evaluated against the I(wait_for)
conditionals.
required: false
default: 10
interval:
description:
- Configures the interval in seconds to wait between retries
of the command. If the command does not pass the specified
conditional, the interval indicates how to long to wait before
trying the command again.
required: false
default: 1
"""
EXAMPLES = """
- name: run show version on remote devices
eos_command:
commands: show version
- name: run show version and check to see if output contains Arista
eos_command:
commands: show version
wait_for: result[0] contains Arista
- name: run multiple commands on remote nodes
eos_command:
commands:
- show version
- show interfaces
- name: run multiple commands and evaluate the output
eos_command:
commands:
- show version
- show interfaces
wait_for:
- result[0] contains Arista
- result[1] contains Loopback0
- name: run commands and specify the output format
eos_command:
commands:
- command: show version
output: json
"""
RETURN = """
stdout:
description: The set of responses from the commands
returned: always apart from low level errors (such as action plugin)
type: list
sample: ['...', '...']
stdout_lines:
description: The value of stdout split into a list
returned: always apart from low level errors (such as action plugin)
type: list
sample: [['...', '...'], ['...'], ['...']]
failed_conditions:
description: The list of conditionals that have failed
returned: failed
type: list
sample: ['...', '...']
"""
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six import string_types
from ansible.module_utils.netcli import Conditional
from ansible.module_utils.network_common import ComplexList
from ansible.module_utils.eos import run_commands
from ansible.module_utils.eos import eos_argument_spec, check_args
VALID_KEYS = ['command', 'output', 'prompt', 'response']
def to_lines(stdout):
lines = list()
for item in stdout:
if isinstance(item, string_types):
item = str(item).split('\n')
lines.append(item)
return lines
def parse_commands(module, warnings):
spec = dict(
command=dict(key=True),
output=dict(),
prompt=dict(),
answer=dict()
)
transform = ComplexList(spec, module)
commands = transform(module.params['commands'])
for index, item in enumerate(commands):
if module.check_mode and not item['command'].startswith('show'):
warnings.append(
'Only show commands are supported when using check_mode, not '
'executing %s' % item['command']
)
return commands
def to_cli(obj):
cmd = obj['command']
if obj.get('output') == 'json':
cmd += ' | json'
return cmd
def main():
"""entry point for module execution
"""
argument_spec = dict(
commands=dict(type='list', required=True),
wait_for=dict(type='list', aliases=['waitfor']),
match=dict(default='all', choices=['all', 'any']),
retries=dict(default=10, type='int'),
interval=dict(default=1, type='int')
)
argument_spec.update(eos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
result = {'changed': False}
warnings = list()
check_args(module, warnings)
commands = parse_commands(module, warnings)
if warnings:
result['warnings'] = warnings
wait_for = module.params['wait_for'] or list()
try:
conditionals = [Conditional(c) for c in wait_for]
except AttributeError:
exc = get_exception()
module.fail_json(msg=str(exc))
retries = module.params['retries']
interval = module.params['interval']
match = module.params['match']
while retries > 0:
responses = run_commands(module, commands)
for item in list(conditionals):
if item(responses):
if match == 'any':
conditionals = list()
break
conditionals.remove(item)
if not conditionals:
break
time.sleep(interval)
retries -= 1
if conditionals:
failed_conditions = [item.raw for item in conditionals]
msg = 'One or more conditional statements have not be satisfied'
module.fail_json(msg=msg, failed_conditions=failed_conditions)
result.update({
'changed': False,
'stdout': responses,
'stdout_lines': to_lines(responses)
})
module.exit_json(**result)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
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,
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,
1018,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
325,
736,
63,
1531,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
3378,
9697,
3718,
641,
376,
31153,
1207,
662,
3100,
2243,
199,
1802,
26,
523,
446,
428,
3198,
376,
9697,
663,
402,
3718,
370,
376,
662,
3100,
1031,
436,
2529,
314,
2058,
272,
1586,
687,
314,
2243,
14,
221,
961,
859,
6952,
376,
272,
1423,
626,
911,
7675,
314,
859,
370,
3618,
367,
282,
2488,
5558,
272,
2544,
8152,
503,
20542,
734,
340,
314,
5558,
365,
440,
7647,
14,
199,
11036,
63,
9970,
63,
7677,
26,
325,
736,
199,
1419,
26,
523,
3718,
26,
272,
1369,
26,
489,
446,
710,
3718,
370,
3222,
370,
314,
3982,
662,
3100,
2243,
1806,
314,
267,
7526,
5022,
14,
221,
710,
9183,
1072,
687,
314,
1414,
267,
365,
2138,
14,
221,
982,
314,
473,
8,
2573,
63,
509,
9,
1423,
365,
2741,
12,
314,
267,
859,
365,
440,
2138,
5133,
314,
5558,
365,
23233,
503,
267,
314,
1329,
402,
473,
8,
10937,
9,
965,
2757,
22007,
14,
272,
1415,
26,
2549,
523,
3618,
63,
509,
26,
272,
1369,
26,
489,
446,
11015,
4052,
370,
9352,
687,
314,
1072,
402,
314,
1414,
267,
436,
4052,
29265,
370,
4838,
14,
221,
961,
1423,
911,
7675,
267,
314,
2120,
370,
3618,
367,
282,
6770,
12303,
370,
506,
2549,
267,
2544,
12876,
7568,
14,
257,
982,
314,
12303,
365,
440,
2549,
267,
701,
314,
7526,
10086,
12,
314,
2120,
6918,
14,
221,
1666,
7251,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
788,
2573,
509,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
1336,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
1431,
9,
1423,
365,
1202,
315,
22888,
543,
314,
267,
473,
8,
2573,
63,
509,
9,
1423,
370,
4165,
314,
1336,
4592,
14,
221,
4821,
267,
1338,
787,
445,
8,
452,
9,
503,
445,
8,
1629,
680,
221,
982,
314,
574,
365,
663,
370,
445,
8,
452,
9,
267,
2066,
1006,
29265,
315,
314,
473,
8,
2573,
63,
509,
9,
1471,
506,
23233,
14,
221,
982,
267,
314,
574,
365,
663,
370,
445,
8,
1629,
9,
2066,
1454,
1373,
402,
314,
1338,
1471,
506,
267,
23233,
14,
272,
1415,
26,
3055,
272,
849,
26,
1006,
272,
3415,
26,
788,
1629,
297,
283,
452,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
10086,
26,
272,
1369,
26,
489,
446,
11015,
314,
1329,
402,
10086,
282,
1414,
1077,
506,
16416,
267,
2544,
652,
365,
8652,
3405,
14,
221,
710,
1414,
365,
1255,
641,
314,
267,
1347,
2243,
4036,
7269,
436,
13006,
6169,
314,
473,
8,
2573,
63,
509,
9,
267,
29265,
14,
272,
1415,
26,
3055,
272,
849,
26,
1616,
523,
6252,
26,
272,
1369,
26,
489,
446,
4094,
1482,
314,
6252,
315,
4696,
370,
3618,
3382,
10086,
267,
402,
314,
1414,
14,
221,
982,
314,
1414,
1630,
440,
986,
314,
2013,
267,
12303,
12,
314,
6252,
9126,
4212,
370,
1846,
370,
3618,
2544,
267,
9936,
314,
1414,
4020,
14,
272,
1415,
26,
3055,
272,
849,
26,
413,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1255,
2498,
1015,
641,
3982,
7256,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
2498,
1015,
199,
199,
13,
536,
26,
1255,
2498,
1015,
436,
1104,
370,
1937,
340,
1072,
3509,
31153,
1207,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
2498,
1015,
272,
3618,
63,
509,
26,
754,
59,
16,
61,
3509,
31153,
1207,
199,
199,
13,
536,
26,
1255,
3663,
3718,
641,
3982,
3380,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
489,
446,
2498,
1015,
489,
446,
2498,
8386,
199,
199,
13,
536,
26,
1255,
3663,
3718,
436,
9352,
314,
1072,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
489,
446,
2498,
1015,
489,
446,
2498,
8386,
272,
3618,
63,
509,
26,
489,
446,
754,
59,
16,
61,
3509,
31153,
1207,
489,
446,
754,
59,
17,
61,
3509,
18175,
894,
16,
199,
199,
13,
536,
26,
1255,
3718,
436,
4165,
314,
1072,
1475,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
489,
446,
1414,
26,
2498,
1015,
267,
1072,
26,
2022,
199,
624,
199,
199,
9677,
275,
408,
199,
2703,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
314,
3718,
523,
2138,
26,
3544,
29430,
687,
6465,
2166,
2552,
334,
10180,
465,
1595,
3589,
9,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
2703,
63,
1278,
26,
523,
1369,
26,
710,
574,
402,
3839,
3715,
1901,
282,
769,
523,
2138,
26,
3544,
29430,
687,
6465,
2166,
2552,
334,
10180,
465,
1595,
3589,
9,
523,
730,
26,
769,
523,
2690,
26,
11194,
20833,
24352,
995,
788,
1396,
995,
788,
1396,
6538,
199,
4892,
63,
9855,
26,
523,
1369,
26,
710,
769,
402,
29265,
626,
1172,
3405,
523,
2138
] |
[
2647,
15,
1393,
15,
1548,
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,
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,
1018,
936,
421,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
325,
736,
63,
1531,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
2502,
26,
298,
8070,
351,
8360,
651,
71,
10641,
8593,
4239,
711,
2924,
199,
3612,
63,
1802,
26,
3378,
9697,
3718,
641,
376,
31153,
1207,
662,
3100,
2243,
199,
1802,
26,
523,
446,
428,
3198,
376,
9697,
663,
402,
3718,
370,
376,
662,
3100,
1031,
436,
2529,
314,
2058,
272,
1586,
687,
314,
2243,
14,
221,
961,
859,
6952,
376,
272,
1423,
626,
911,
7675,
314,
859,
370,
3618,
367,
282,
2488,
5558,
272,
2544,
8152,
503,
20542,
734,
340,
314,
5558,
365,
440,
7647,
14,
199,
11036,
63,
9970,
63,
7677,
26,
325,
736,
199,
1419,
26,
523,
3718,
26,
272,
1369,
26,
489,
446,
710,
3718,
370,
3222,
370,
314,
3982,
662,
3100,
2243,
1806,
314,
267,
7526,
5022,
14,
221,
710,
9183,
1072,
687,
314,
1414,
267,
365,
2138,
14,
221,
982,
314,
473,
8,
2573,
63,
509,
9,
1423,
365,
2741,
12,
314,
267,
859,
365,
440,
2138,
5133,
314,
5558,
365,
23233,
503,
267,
314,
1329,
402,
473,
8,
10937,
9,
965,
2757,
22007,
14,
272,
1415,
26,
2549,
523,
3618,
63,
509,
26,
272,
1369,
26,
489,
446,
11015,
4052,
370,
9352,
687,
314,
1072,
402,
314,
1414,
267,
436,
4052,
29265,
370,
4838,
14,
221,
961,
1423,
911,
7675,
267,
314,
2120,
370,
3618,
367,
282,
6770,
12303,
370,
506,
2549,
267,
2544,
12876,
7568,
14,
257,
982,
314,
12303,
365,
440,
2549,
267,
701,
314,
7526,
10086,
12,
314,
2120,
6918,
14,
221,
1666,
7251,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
272,
5481,
26,
788,
2573,
509,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
1336,
26,
272,
1369,
26,
489,
446,
710,
473,
8,
1431,
9,
1423,
365,
1202,
315,
22888,
543,
314,
267,
473,
8,
2573,
63,
509,
9,
1423,
370,
4165,
314,
1336,
4592,
14,
221,
4821,
267,
1338,
787,
445,
8,
452,
9,
503,
445,
8,
1629,
680,
221,
982,
314,
574,
365,
663,
370,
445,
8,
452,
9,
267,
2066,
1006,
29265,
315,
314,
473,
8,
2573,
63,
509,
9,
1471,
506,
23233,
14,
221,
982,
267,
314,
574,
365,
663,
370,
445,
8,
1629,
9,
2066,
1454,
1373,
402,
314,
1338,
1471,
506,
267,
23233,
14,
272,
1415,
26,
3055,
272,
849,
26,
1006,
272,
3415,
26,
788,
1629,
297,
283,
452,
418,
272,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
523,
10086,
26,
272,
1369,
26,
489,
446,
11015,
314,
1329,
402,
10086,
282,
1414,
1077,
506,
16416,
267,
2544,
652,
365,
8652,
3405,
14,
221,
710,
1414,
365,
1255,
641,
314,
267,
1347,
2243,
4036,
7269,
436,
13006,
6169,
314,
473,
8,
2573,
63,
509,
9,
267,
29265,
14,
272,
1415,
26,
3055,
272,
849,
26,
1616,
523,
6252,
26,
272,
1369,
26,
489,
446,
4094,
1482,
314,
6252,
315,
4696,
370,
3618,
3382,
10086,
267,
402,
314,
1414,
14,
221,
982,
314,
1414,
1630,
440,
986,
314,
2013,
267,
12303,
12,
314,
6252,
9126,
4212,
370,
1846,
370,
3618,
2544,
267,
9936,
314,
1414,
4020,
14,
272,
1415,
26,
3055,
272,
849,
26,
413,
199,
624,
199,
199,
8918,
275,
408,
199,
13,
536,
26,
1255,
2498,
1015,
641,
3982,
7256,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
2498,
1015,
199,
199,
13,
536,
26,
1255,
2498,
1015,
436,
1104,
370,
1937,
340,
1072,
3509,
31153,
1207,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
2498,
1015,
272,
3618,
63,
509,
26,
754,
59,
16,
61,
3509,
31153,
1207,
199,
199,
13,
536,
26,
1255,
3663,
3718,
641,
3982,
3380,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
489,
446,
2498,
1015,
489,
446,
2498,
8386,
199,
199,
13,
536,
26,
1255,
3663,
3718,
436,
9352,
314,
1072,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
489,
446,
2498,
1015,
489,
446,
2498,
8386,
272,
3618,
63,
509,
26,
489,
446,
754,
59,
16,
61,
3509,
31153,
1207,
489,
446,
754,
59,
17,
61,
3509,
18175,
894,
16,
199,
199,
13,
536,
26,
1255,
3718,
436,
4165,
314,
1072,
1475,
523,
325,
736,
63,
1531,
26,
272,
3718,
26,
489,
446,
1414,
26,
2498,
1015,
267,
1072,
26,
2022,
199,
624,
199,
199,
9677,
275,
408,
199,
2703,
26,
523,
1369,
26,
710,
663,
402,
9320,
687,
314,
3718,
523,
2138,
26,
3544,
29430,
687,
6465,
2166,
2552,
334,
10180,
465,
1595,
3589,
9,
523,
730,
26,
769,
523,
2690,
26,
788,
20833,
24352,
418,
199,
2703,
63,
1278,
26,
523,
1369,
26,
710,
574,
402,
3839,
3715,
1901,
282,
769,
523,
2138,
26,
3544,
29430,
687,
6465,
2166,
2552,
334,
10180,
465,
1595,
3589,
9,
523,
730,
26,
769,
523,
2690,
26,
11194,
20833,
24352,
995,
788,
1396,
995,
788,
1396,
6538,
199,
4892,
63,
9855,
26,
523,
1369,
26,
710,
769,
402,
29265,
626,
1172,
3405,
523,
2138,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dhruvparamhans/fuel
|
fuel/datasets/text.py
|
21
|
4353
|
from picklable_itertools import iter_, chain
from fuel.datasets import Dataset
class TextFile(Dataset):
r"""Reads text files and numberizes them given a dictionary.
Parameters
----------
files : list of str
The names of the files in order which they should be read. Each
file is expected to have a sentence per line.
dictionary : str or dict
Either the path to a Pickled dictionary mapping tokens to integers,
or the dictionary itself. At the very least this dictionary must
map the unknown word-token to an integer.
bos_token : str or None, optional
The beginning-of-sentence (BOS) token in the dictionary that
denotes the beginning of a sentence. Is ``<S>`` by default. If
passed ``None`` no beginning of sentence markers will be added.
eos_token : str or None, optional
The end-of-sentence (EOS) token is ``</S>`` by default, see
``bos_taken``.
unk_token : str, optional
The token in the dictionary to fall back on when a token could not
be found in the dictionary.
level : 'word' or 'character', optional
If 'word' the dictionary is expected to contain full words. The
sentences in the text file will be split at the spaces, and each
word replaced with its number as given by the dictionary, resulting
in each example being a single list of numbers. If 'character' the
dictionary is expected to contain single letters as keys. A single
example will be a list of character numbers, starting with the
first non-whitespace character and finishing with the last one.
preprocess : function, optional
A function which takes a sentence (string) as an input and returns
a modified string. For example ``str.lower`` in order to lowercase
the sentence before numberizing.
Examples
--------
>>> with open('sentences.txt', 'w') as f:
... _ = f.write("This is a sentence\n")
... _ = f.write("This another one")
>>> dictionary = {'<UNK>': 0, '</S>': 1, 'this': 2, 'a': 3, 'one': 4}
>>> def lower(s):
... return s.lower()
>>> text_data = TextFile(files=['sentences.txt'],
... dictionary=dictionary, bos_token=None,
... preprocess=lower)
>>> from fuel.streams import DataStream
>>> for data in DataStream(text_data).get_epoch_iterator():
... print(data)
([2, 0, 3, 0, 1],)
([2, 0, 4, 1],)
.. doctest::
:hide:
>>> import os
>>> os.remove('sentences.txt')
"""
provides_sources = ('features',)
example_iteration_scheme = None
def __init__(self, files, dictionary, bos_token='<S>', eos_token='</S>',
unk_token='<UNK>', level='word', preprocess=None):
self.files = files
self.dictionary = dictionary
if bos_token is not None and bos_token not in dictionary:
raise ValueError
self.bos_token = bos_token
if eos_token is not None and eos_token not in dictionary:
raise ValueError
self.eos_token = eos_token
if unk_token not in dictionary:
raise ValueError
self.unk_token = unk_token
if level not in ('word', 'character'):
raise ValueError
self.level = level
self.preprocess = preprocess
super(TextFile, self).__init__()
def open(self):
return chain(*[iter_(open(f)) for f in self.files])
def get_data(self, state=None, request=None):
if request is not None:
raise ValueError
sentence = next(state)
if self.preprocess is not None:
sentence = self.preprocess(sentence)
data = [self.dictionary[self.bos_token]] if self.bos_token else []
if self.level == 'word':
data.extend(self.dictionary.get(word,
self.dictionary[self.unk_token])
for word in sentence.split())
else:
data.extend(self.dictionary.get(char,
self.dictionary[self.unk_token])
for char in sentence.strip())
if self.eos_token:
data.append(self.dictionary[self.eos_token])
return (data,)
|
mit
|
[
504,
3732,
76,
461,
63,
17691,
492,
2740,
3131,
6036,
199,
199,
504,
289,
13086,
14,
12281,
492,
20284,
421,
199,
533,
4516,
1173,
8,
9271,
304,
272,
519,
624,
23614,
1318,
1584,
436,
1329,
6491,
3062,
1627,
282,
2600,
14,
339,
3897,
272,
4143,
272,
1584,
520,
769,
402,
620,
267,
710,
1561,
402,
314,
1584,
315,
1865,
1314,
2985,
1077,
506,
1586,
14,
7048,
267,
570,
365,
1420,
370,
1172,
282,
14537,
1126,
1004,
14,
272,
2600,
520,
620,
503,
1211,
267,
13083,
314,
931,
370,
282,
16568,
1146,
2600,
4412,
4645,
370,
9446,
12,
267,
503,
314,
2600,
6337,
14,
2854,
314,
7437,
5210,
642,
2600,
1471,
267,
2341,
314,
5809,
4349,
13,
1418,
370,
376,
3000,
14,
272,
330,
736,
63,
1418,
520,
620,
503,
488,
12,
2716,
267,
710,
9608,
13,
1618,
13,
17727,
334,
34,
3100,
9,
1526,
315,
314,
2600,
626,
267,
477,
5983,
314,
9608,
402,
282,
14537,
14,
6596,
23696,
51,
28210,
701,
849,
14,
982,
267,
3032,
1124,
403,
1040,
949,
9608,
402,
14537,
14327,
911,
506,
3483,
14,
272,
325,
736,
63,
1418,
520,
620,
503,
488,
12,
2716,
267,
710,
1284,
13,
1618,
13,
17727,
334,
37,
3100,
9,
1526,
365,
1124,
1108,
51,
28210,
701,
849,
12,
1937,
267,
1124,
656,
83,
63,
28549,
4345,
272,
625,
75,
63,
1418,
520,
620,
12,
2716,
267,
710,
1526,
315,
314,
2600,
370,
11264,
1771,
641,
1380,
282,
1526,
4293,
440,
267,
506,
1911,
315,
314,
2600,
14,
272,
2166,
520,
283,
1027,
7,
503,
283,
10856,
297,
2716,
267,
982,
283,
1027,
7,
314,
2600,
365,
1420,
370,
1395,
2615,
5932,
14,
710,
267,
24256,
315,
314,
1318,
570,
911,
506,
3715,
737,
314,
7883,
12,
436,
1924,
267,
4349,
8717,
543,
2399,
1329,
465,
1627,
701,
314,
2600,
12,
9183,
267,
315,
1924,
2893,
3769,
282,
2849,
769,
402,
5579,
14,
982,
283,
10856,
7,
314,
267,
2600,
365,
1420,
370,
1395,
2849,
14435,
465,
2883,
14,
437,
2849,
267,
2893,
911,
506,
282,
769,
402,
4528,
5579,
12,
6617,
543,
314,
267,
1642,
2222,
13,
8506,
4528,
436,
9578,
316,
543,
314,
2061,
1373,
14,
272,
23351,
520,
805,
12,
2716,
267,
437,
805,
1314,
6181,
282,
14537,
334,
875,
9,
465,
376,
1324,
436,
2529,
267,
282,
6042,
1059,
14,
2104,
2893,
1124,
495,
14,
2325,
1040,
315,
1865,
370,
12141,
267,
314,
14537,
2544,
1329,
9147,
14,
339,
6058,
272,
3001,
272,
1306,
543,
1551,
360,
25669,
14,
2424,
297,
283,
87,
358,
465,
289,
26,
272,
2263,
258,
485,
275,
289,
14,
952,
480,
2765,
365,
282,
14537,
60,
78,
531,
272,
2263,
258,
485,
275,
289,
14,
952,
480,
2765,
4573,
1373,
531,
272,
1306,
2600,
275,
791,
28,
8019,
30838,
378,
12,
11936,
51,
30838,
413,
12,
283,
3749,
356,
499,
12,
283,
65,
356,
650,
12,
283,
368,
356,
841,
93,
272,
1306,
347,
5117,
8,
83,
304,
272,
2263,
258,
372,
308,
14,
2325,
342,
272,
1306,
1318,
63,
576,
275,
4516,
1173,
8,
1725,
2968,
25669,
14,
2424,
995,
272,
2263,
10473,
2600,
29,
9086,
12,
330,
736,
63,
1418,
29,
403,
12,
272,
2263,
10473,
23351,
29,
2325,
9,
272,
1306,
687,
289,
13086,
14,
11231,
492,
3918,
3296,
272,
1306,
367,
666,
315,
3918,
3296,
8,
505,
63,
576,
680,
362,
63,
7367,
63,
5778,
837,
272,
2263,
258,
870,
8,
576,
9,
272,
7287,
18,
12,
378,
12,
650,
12,
378,
12,
413,
467,
9,
272,
7287,
18,
12,
378,
12,
841,
12,
413,
467,
9,
339,
2508,
8868,
447,
2126,
520,
8191,
26,
10817,
1306,
492,
747,
2126,
1306,
747,
14,
2168,
360,
25669,
14,
2424,
358,
339,
408,
272,
6571,
63,
4553,
275,
661,
3179,
9538,
272,
2893,
63,
12575,
63,
5512,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1584,
12,
2600,
12,
330,
736,
63,
1418,
15829,
51,
4206,
325,
736,
63,
1418,
534,
1108,
51,
4206,
326,
625,
75,
63,
1418,
15829,
8019,
4206,
2166,
534,
1027,
297,
23351,
29,
403,
304,
267,
291,
14,
1725,
275,
1584,
267,
291,
14,
9086,
275,
2600,
267,
340,
330,
736,
63,
1418,
365,
440,
488,
436,
330,
736,
63,
1418,
440,
315,
2600,
26,
288,
746,
1722,
267,
291,
14,
656,
83,
63,
1418,
275,
330,
736,
63,
1418,
267,
340,
325,
736,
63,
1418,
365,
440,
488,
436,
325,
736,
63,
1418,
440,
315,
2600,
26,
288,
746,
1722,
267,
291,
14,
24909,
63,
1418,
275,
325,
736,
63,
1418,
267,
340,
625,
75,
63,
1418,
440,
315,
2600,
26,
288,
746,
1722,
267,
291,
14,
1778,
63,
1418,
275,
625,
75,
63,
1418,
267,
340,
2166,
440,
315,
661,
1027,
297,
283,
10856,
735,
288,
746,
1722,
267,
291,
14,
1896,
275,
2166,
267,
291,
14,
17677,
275,
23351,
267,
1613,
8,
1872,
1173,
12,
291,
2843,
826,
4533,
339,
347,
1551,
8,
277,
304,
267,
372,
6036,
23151,
1661,
2531,
1490,
8,
70,
430,
367,
289,
315,
291,
14,
1725,
566,
339,
347,
664,
63,
576,
8,
277,
12,
1174,
29,
403,
12,
1056,
29,
403,
304,
267,
340,
1056,
365,
440,
488,
26,
288,
746,
1722,
267,
14537,
275,
2163,
8,
929,
9,
267,
340,
291,
14,
17677,
365,
440,
488,
26,
288,
14537,
275,
291,
14,
17677,
8,
17727,
9,
267,
666,
275,
359,
277,
14,
9086,
59,
277,
14,
656,
83,
63,
1418,
2677,
340,
291,
14,
656,
83,
63,
1418,
587,
942,
267,
340,
291,
14,
1896,
508,
283,
1027,
356,
288,
666,
14,
2880,
8,
277,
14,
9086,
14,
362,
8,
1027,
12,
4490,
291,
14,
9086,
59,
277,
14,
1778,
63,
1418,
566,
717,
367,
4349,
315,
14537,
14,
1294,
1012,
267,
587,
26,
288,
666,
14,
2880,
8,
277,
14,
9086,
14,
362,
8,
1560,
12,
4490,
291,
14,
9086,
59,
277,
14,
1778,
63,
1418,
566,
717,
367,
1495,
315,
14537,
14,
1913,
1012,
267,
340,
291,
14,
24909,
63,
1418,
26,
288,
666,
14,
740,
8,
277,
14,
9086,
59,
277,
14,
24909,
63,
1418,
566,
267,
372,
334,
576,
4258,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3732,
76,
461,
63,
17691,
492,
2740,
3131,
6036,
199,
199,
504,
289,
13086,
14,
12281,
492,
20284,
421,
199,
533,
4516,
1173,
8,
9271,
304,
272,
519,
624,
23614,
1318,
1584,
436,
1329,
6491,
3062,
1627,
282,
2600,
14,
339,
3897,
272,
4143,
272,
1584,
520,
769,
402,
620,
267,
710,
1561,
402,
314,
1584,
315,
1865,
1314,
2985,
1077,
506,
1586,
14,
7048,
267,
570,
365,
1420,
370,
1172,
282,
14537,
1126,
1004,
14,
272,
2600,
520,
620,
503,
1211,
267,
13083,
314,
931,
370,
282,
16568,
1146,
2600,
4412,
4645,
370,
9446,
12,
267,
503,
314,
2600,
6337,
14,
2854,
314,
7437,
5210,
642,
2600,
1471,
267,
2341,
314,
5809,
4349,
13,
1418,
370,
376,
3000,
14,
272,
330,
736,
63,
1418,
520,
620,
503,
488,
12,
2716,
267,
710,
9608,
13,
1618,
13,
17727,
334,
34,
3100,
9,
1526,
315,
314,
2600,
626,
267,
477,
5983,
314,
9608,
402,
282,
14537,
14,
6596,
23696,
51,
28210,
701,
849,
14,
982,
267,
3032,
1124,
403,
1040,
949,
9608,
402,
14537,
14327,
911,
506,
3483,
14,
272,
325,
736,
63,
1418,
520,
620,
503,
488,
12,
2716,
267,
710,
1284,
13,
1618,
13,
17727,
334,
37,
3100,
9,
1526,
365,
1124,
1108,
51,
28210,
701,
849,
12,
1937,
267,
1124,
656,
83,
63,
28549,
4345,
272,
625,
75,
63,
1418,
520,
620,
12,
2716,
267,
710,
1526,
315,
314,
2600,
370,
11264,
1771,
641,
1380,
282,
1526,
4293,
440,
267,
506,
1911,
315,
314,
2600,
14,
272,
2166,
520,
283,
1027,
7,
503,
283,
10856,
297,
2716,
267,
982,
283,
1027,
7,
314,
2600,
365,
1420,
370,
1395,
2615,
5932,
14,
710,
267,
24256,
315,
314,
1318,
570,
911,
506,
3715,
737,
314,
7883,
12,
436,
1924,
267,
4349,
8717,
543,
2399,
1329,
465,
1627,
701,
314,
2600,
12,
9183,
267,
315,
1924,
2893,
3769,
282,
2849,
769,
402,
5579,
14,
982,
283,
10856,
7,
314,
267,
2600,
365,
1420,
370,
1395,
2849,
14435,
465,
2883,
14,
437,
2849,
267,
2893,
911,
506,
282,
769,
402,
4528,
5579,
12,
6617,
543,
314,
267,
1642,
2222,
13,
8506,
4528,
436,
9578,
316,
543,
314,
2061,
1373,
14,
272,
23351,
520,
805,
12,
2716,
267,
437,
805,
1314,
6181,
282,
14537,
334,
875,
9,
465,
376,
1324,
436,
2529,
267,
282,
6042,
1059,
14,
2104,
2893,
1124,
495,
14,
2325,
1040,
315,
1865,
370,
12141,
267,
314,
14537,
2544,
1329,
9147,
14,
339,
6058,
272,
3001,
272,
1306,
543,
1551,
360,
25669,
14,
2424,
297,
283,
87,
358,
465,
289,
26,
272,
2263,
258,
485,
275,
289,
14,
952,
480,
2765,
365,
282,
14537,
60,
78,
531,
272,
2263,
258,
485,
275,
289,
14,
952,
480,
2765,
4573,
1373,
531,
272,
1306,
2600,
275,
791,
28,
8019,
30838,
378,
12,
11936,
51,
30838,
413,
12,
283,
3749,
356,
499,
12,
283,
65,
356,
650,
12,
283,
368,
356,
841,
93,
272,
1306,
347,
5117,
8,
83,
304,
272,
2263,
258,
372,
308,
14,
2325,
342,
272,
1306,
1318,
63,
576,
275,
4516,
1173,
8,
1725,
2968,
25669,
14,
2424,
995,
272,
2263,
10473,
2600,
29,
9086,
12,
330,
736,
63,
1418,
29,
403,
12,
272,
2263,
10473,
23351,
29,
2325,
9,
272,
1306,
687,
289,
13086,
14,
11231,
492,
3918,
3296,
272,
1306,
367,
666,
315,
3918,
3296,
8,
505,
63,
576,
680,
362,
63,
7367,
63,
5778,
837,
272,
2263,
258,
870,
8,
576,
9,
272,
7287,
18,
12,
378,
12,
650,
12,
378,
12,
413,
467,
9,
272,
7287,
18,
12,
378,
12,
841,
12,
413,
467,
9,
339,
2508,
8868,
447,
2126,
520,
8191,
26,
10817,
1306,
492,
747,
2126,
1306,
747,
14,
2168,
360,
25669,
14,
2424,
358,
339,
408,
272,
6571,
63,
4553,
275,
661,
3179,
9538,
272,
2893,
63,
12575,
63,
5512,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1584,
12,
2600,
12,
330,
736,
63,
1418,
15829,
51,
4206,
325,
736,
63,
1418,
534,
1108,
51,
4206,
326,
625,
75,
63,
1418,
15829,
8019,
4206,
2166,
534,
1027,
297,
23351,
29,
403,
304,
267,
291,
14,
1725,
275,
1584,
267,
291,
14,
9086,
275,
2600,
267,
340,
330,
736,
63,
1418,
365,
440,
488,
436,
330,
736,
63,
1418,
440,
315,
2600,
26,
288,
746,
1722,
267,
291,
14,
656,
83,
63,
1418,
275,
330,
736,
63,
1418,
267,
340,
325,
736,
63,
1418,
365,
440,
488,
436,
325,
736,
63,
1418,
440,
315,
2600,
26,
288,
746,
1722,
267,
291,
14,
24909,
63,
1418,
275,
325,
736,
63,
1418,
267,
340,
625,
75,
63,
1418,
440,
315,
2600,
26,
288,
746,
1722,
267,
291,
14,
1778,
63,
1418,
275,
625,
75,
63,
1418,
267,
340,
2166,
440,
315,
661,
1027,
297,
283,
10856,
735,
288,
746,
1722,
267,
291,
14,
1896,
275,
2166,
267,
291,
14,
17677,
275,
23351,
267,
1613,
8,
1872,
1173,
12,
291,
2843,
826,
4533,
339,
347,
1551,
8,
277,
304,
267,
372,
6036,
23151,
1661,
2531,
1490,
8,
70,
430,
367,
289,
315,
291,
14,
1725,
566,
339,
347,
664,
63,
576,
8,
277,
12,
1174,
29,
403,
12,
1056,
29,
403,
304,
267,
340,
1056,
365,
440,
488,
26,
288,
746,
1722,
267,
14537,
275,
2163,
8,
929,
9,
267,
340,
291,
14,
17677,
365,
440,
488,
26,
288,
14537,
275,
291,
14,
17677,
8,
17727,
9,
267,
666,
275,
359,
277,
14,
9086,
59,
277,
14,
656,
83,
63,
1418,
2677,
340,
291,
14,
656,
83,
63,
1418,
587,
942,
267,
340,
291,
14,
1896,
508,
283,
1027,
356,
288,
666,
14,
2880,
8,
277,
14,
9086,
14,
362,
8,
1027,
12,
4490,
291,
14,
9086,
59,
277,
14,
1778,
63,
1418,
566,
717,
367,
4349,
315,
14537,
14,
1294,
1012,
267,
587,
26,
288,
666,
14,
2880,
8,
277,
14,
9086,
14,
362,
8,
1560,
12,
4490,
291,
14,
9086,
59,
277,
14,
1778,
63,
1418,
566,
717,
367,
1495,
315,
14537,
14,
1913,
1012,
267,
340,
291,
14,
24909,
63,
1418,
26,
288,
666,
14,
740,
8,
277,
14,
9086,
59,
277,
14,
24909,
63,
1418,
566,
267,
372,
334,
576,
4258,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alduxvm/pyMultiWii
|
pymultiwii/__init__.py
|
1
|
17209
|
#!/usr/bin/env python
"""multiwii.py: Handles Multiwii Serial Protocol."""
__author__ = "Aldo Vargas"
__copyright__ = "Copyright 2017 Altax.net"
__license__ = "GPL"
__version__ = "1.6"
__maintainer__ = "Aldo Vargas"
__email__ = "alduxvm@gmail.com"
__status__ = "Development"
import serial, time, struct
class MultiWii:
"""Multiwii Serial Protocol message ID"""
""" notice: just attitude, rc channels and raw imu, set raw rc are implemented at the moment """
IDENT = 100
STATUS = 101
RAW_IMU = 102
SERVO = 103
MOTOR = 104
RC = 105
RAW_GPS = 106
COMP_GPS = 107
ATTITUDE = 108
ALTITUDE = 109
ANALOG = 110
RC_TUNING = 111
PID = 112
BOX = 113
MISC = 114
MOTOR_PINS = 115
BOXNAMES = 116
PIDNAMES = 117
WP = 118
BOXIDS = 119
RC_RAW_IMU = 121
SET_RAW_RC = 200
SET_RAW_GPS = 201
SET_PID = 202
SET_BOX = 203
SET_RC_TUNING = 204
ACC_CALIBRATION = 205
MAG_CALIBRATION = 206
SET_MISC = 207
RESET_CONF = 208
SET_WP = 209
SWITCH_RC_SERIAL = 210
IS_SERIAL = 211
DEBUG = 254
VTX_CONFIG = 88
VTX_SET_CONFIG = 89
EEPROM_WRITE = 250
REBOOT = 68
"""Class initialization"""
def __init__(self, serPort):
"""Global variables of data"""
self.PIDcoef = {'rp':0,'ri':0,'rd':0,'pp':0,'pi':0,'pd':0,'yp':0,'yi':0,'yd':0}
self.rcChannels = {'roll':0,'pitch':0,'yaw':0,'throttle':0,'elapsed':0,'timestamp':0}
self.rawIMU = {'ax':0,'ay':0,'az':0,'gx':0,'gy':0,'gz':0,'mx':0,'my':0,'mz':0,'elapsed':0,'timestamp':0}
self.motor = {'m1':0,'m2':0,'m3':0,'m4':0,'elapsed':0,'timestamp':0}
self.attitude = {'angx':0,'angy':0,'heading':0,'elapsed':0,'timestamp':0}
self.altitude = {'estalt':0,'vario':0,'elapsed':0,'timestamp':0}
self.message = {'angx':0,'angy':0,'heading':0,'roll':0,'pitch':0,'yaw':0,'throttle':0,'elapsed':0,'timestamp':0}
self.vtxConfig = {'device':0, 'band':0, 'channel':0, 'power':0, 'pit':0, 'unknown':0}
self.temp = ();
self.temp2 = ();
self.elapsed = 0
self.PRINT = 1
self.ser = serial.Serial()
self.ser.port = serPort
self.ser.baudrate = 115200
self.ser.bytesize = serial.EIGHTBITS
self.ser.parity = serial.PARITY_NONE
self.ser.stopbits = serial.STOPBITS_ONE
self.ser.timeout = 0
self.ser.xonxoff = False
self.ser.rtscts = False
self.ser.dsrdtr = False
self.ser.writeTimeout = 2
"""Time to wait until the board becomes operational"""
wakeup = 2
try:
self.ser.open()
if self.PRINT:
print ("Waking up board on "+self.ser.port+"...")
for i in range(1,wakeup):
if self.PRINT:
print (wakeup-i)
time.sleep(1)
else:
time.sleep(1)
except Exception as error:
print ("\n\nError opening "+self.ser.port+" port.\n"+str(error)+"\n\n")
"""Function for sending a command to the board"""
def sendCMD(self, data_length, code, data, data_format):
checksum = 0
total_data = ['$'.encode('utf-8'), 'M'.encode('utf-8'), '<'.encode('utf-8'), data_length, code] + data
for i in struct.pack('<2B' + data_format, *total_data[3:len(total_data)]):
checksum = checksum ^ i
total_data.append(checksum)
try:
b = None
b = self.ser.write(struct.pack('<3c2B'+ data_format + 'B', *total_data))
except Exception as error:
print ("\n\nError in sendCMD.")
print ("("+str(error)+")\n\n")
pass
"""Function for sending a command to the board and receive attitude"""
"""
Modification required on Multiwii firmware to Protocol.cpp in evaluateCommand:
case MSP_SET_RAW_RC:
s_struct_w((uint8_t*)&rcSerial,16);
rcSerialCount = 50; // 1s transition
s_struct((uint8_t*)&att,6);
break;
"""
def sendCMDreceiveATT(self, data_length, code, data):
checksum = 0
total_data = ['$'.encode('utf-8'), 'M'.encode('utf-8'), '<'.encode('utf-8'), data_length, code] + data
for i in struct.pack('<2B%dH' % len(data), *total_data[3:len(total_data)]):
checksum = checksum ^ i
total_data.append(checksum)
try:
start = time.time()
b = None
b = self.ser.write(struct.pack('<3c2B%dHB' % len(data), *total_data))
while True:
header = self.ser.read().decode('utf-8')
if header == '$':
header = header+self.ser.read(2).decode('utf-8')
break
datalength = struct.unpack('<b', self.ser.read())[0]
code = struct.unpack('<b', self.ser.read())
data = self.ser.read(datalength)
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.ser.flushInput()
self.ser.flushOutput()
elapsed = time.time() - start
self.attitude['angx']=float(temp[0]/10.0)
self.attitude['angy']=float(temp[1]/10.0)
self.attitude['heading']=float(temp[2])
self.attitude['elapsed']=round(elapsed,3)
self.attitude['timestamp']="%0.2f" % (time.time(),)
return self.attitude
except Exception as error:
print ("\n\nError in sendCMDreceiveATT.")
print ("("+str(error)+")\n\n")
pass
"""Function to arm / disarm """
"""
Modification required on Multiwii firmware to Protocol.cpp in evaluateCommand:
case MSP_SET_RAW_RC:
s_struct_w((uint8_t*)&rcSerial,16);
rcSerialCount = 50; // 1s transition
s_struct((uint8_t*)&att,6);
break;
"""
def arm(self):
timer = 0
start = time.time()
while timer < 0.5:
data = [1500,1500,2000,1000]
self.sendCMD(8,MultiWii.SET_RAW_RC,data)
time.sleep(0.05)
timer = timer + (time.time() - start)
start = time.time()
def disarm(self):
timer = 0
start = time.time()
while timer < 0.5:
data = [1500,1500,1000,1000]
self.sendCMD(8,MultiWii.SET_RAW_RC,data)
time.sleep(0.05)
timer = timer + (time.time() - start)
start = time.time()
def setPID(self,pd):
nd=[]
for i in np.arange(1,len(pd),2):
nd.append(pd[i]+pd[i+1]*256)
data = pd
print ("PID sending:", data)
self.sendCMD(30,MultiWii.SET_PID,data)
self.sendCMD(0,MultiWii.EEPROM_WRITE,[])
def setVTX(self,band,channel,power):
band_channel = ((band-1) << 3)|(channel-1)
t = None
while t == None :
t = self.getData(MultiWii.VTX_CONFIG)
different = (self.vtxConfig['band'] != band) | (self.vtxConfig['channel'] != channel) | (self.vtxConfig['power'] != power)
data = [band_channel,power,self.vtxConfig['pit']]
while different :
self.sendCMD(4,MultiWii.VTX_SET_CONFIG,data, 'H2B')
time.sleep(1)
self.sendCMD(0,MultiWii.EEPROM_WRITE,[],'')
self.ser.close()
time.sleep(3)
self.ser.open()
time.sleep(3)
t = None
while t == None :
t = self.getData(MultiWii.VTX_CONFIG)
print(t)
different = (self.vtxConfig['band'] != band) | (self.vtxConfig['channel'] != channel) | (self.vtxConfig['power'] != power)
"""Function to receive a data packet from the board"""
def getData(self, cmd):
try:
start = time.time()
self.sendCMD(0,cmd,[],'')
while True:
header = self.ser.read().decode('utf-8')
if header == '$':
header = header+self.ser.read(2).decode('utf-8')
break
datalength = struct.unpack('<b', self.ser.read())[0]
code = struct.unpack('<b', self.ser.read())
data = self.ser.read(datalength)
self.ser.flushInput()
self.ser.flushOutput()
elapsed = time.time() - start
if cmd == MultiWii.ATTITUDE:
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.attitude['angx']=float(temp[0]/10.0)
self.attitude['angy']=float(temp[1]/10.0)
self.attitude['heading']=float(temp[2])
self.attitude['elapsed']=round(elapsed,3)
self.attitude['timestamp']="%0.2f" % (time.time(),)
return self.attitude
elif cmd == MultiWii.ALTITUDE:
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.altitude['estalt']=float(temp[0])
self.altitude['vario']=float(temp[1])
self.altitude['elapsed']=round(elapsed,3)
self.altitude['timestamp']="%0.2f" % (time.time(),)
return self.altitude
elif cmd == MultiWii.RC:
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.rcChannels['roll']=temp[0]
self.rcChannels['pitch']=temp[1]
self.rcChannels['yaw']=temp[2]
self.rcChannels['throttle']=temp[3]
self.rcChannels['elapsed']=round(elapsed,3)
self.rcChannels['timestamp']="%0.2f" % (time.time(),)
return self.rcChannels
elif cmd == MultiWii.RAW_IMU:
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.rawIMU['ax']=float(temp[0])
self.rawIMU['ay']=float(temp[1])
self.rawIMU['az']=float(temp[2])
self.rawIMU['gx']=float(temp[3])
self.rawIMU['gy']=float(temp[4])
self.rawIMU['gz']=float(temp[5])
self.rawIMU['mx']=float(temp[6])
self.rawIMU['my']=float(temp[7])
self.rawIMU['mz']=float(temp[8])
self.rawIMU['elapsed']=round(elapsed,3)
self.rawIMU['timestamp']="%0.2f" % (time.time(),)
return self.rawIMU
elif cmd == MultiWii.MOTOR:
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.motor['m1']=float(temp[0])
self.motor['m2']=float(temp[1])
self.motor['m3']=float(temp[2])
self.motor['m4']=float(temp[3])
self.motor['elapsed']="%0.3f" % (elapsed,)
self.motor['timestamp']="%0.2f" % (time.time(),)
return self.motor
elif cmd == MultiWii.PID:
temp = struct.unpack('<'+'h'*int(datalength/2),data)
dataPID=[]
if len(temp)>1:
d=0
for t in temp:
dataPID.append(t%256)
dataPID.append(t/256)
for p in [0,3,6,9]:
dataPID[p]=dataPID[p]/10.0
dataPID[p+1]=dataPID[p+1]/1000.0
self.PIDcoef['rp']= dataPID=[0]
self.PIDcoef['ri']= dataPID=[1]
self.PIDcoef['rd']= dataPID=[2]
self.PIDcoef['pp']= dataPID=[3]
self.PIDcoef['pi']= dataPID=[4]
self.PIDcoef['pd']= dataPID=[5]
self.PIDcoef['yp']= dataPID=[6]
self.PIDcoef['yi']= dataPID=[7]
self.PIDcoef['yd']= dataPID=[8]
return self.PIDcoef
elif cmd == MultiWii.VTX_CONFIG:
if datalength > 1:
temp = struct.unpack('<bbbbb',data)
self.vtxConfig['device'] = temp[0]
self.vtxConfig['band'] = temp[1]
self.vtxConfig['channel'] = temp[2]
self.vtxConfig['power'] = temp[3]
self.vtxConfig['pit'] = temp[4]
self.vtxConfig['unknown'] = 0
return self.vtxConfig
else:
temp = struct.unpack('<b',data)
self.vtxConfig['unknown'] = temp[0]
return self.vtxConfig
else:
return "No return error!"
except Exception as error:
print (error)
pass
"""Function to receive a data packet from the board. Note: easier to use on threads"""
def getDataInf(self, cmd):
while True:
try:
start = time.clock()
self.sendCMD(0,cmd,[])
while True:
header = self.ser.read().decode('utf-8')
if header == '$':
header = header+self.ser.read(2).decode('utf-8')
break
datalength = struct.unpack('<b', self.ser.read())[0]
code = struct.unpack('<b', self.ser.read())
data = self.ser.read(datalength)
temp = struct.unpack('<'+'h'*int(datalength/2),data)
elapsed = time.clock() - start
self.ser.flushInput()
self.ser.flushOutput()
if cmd == MultiWii.ATTITUDE:
self.attitude['angx']=float(temp[0]/10.0)
self.attitude['angy']=float(temp[1]/10.0)
self.attitude['heading']=float(temp[2])
self.attitude['elapsed']="%0.3f" % (elapsed,)
self.attitude['timestamp']="%0.2f" % (time.time(),)
elif cmd == MultiWii.RC:
self.rcChannels['roll']=temp[0]
self.rcChannels['pitch']=temp[1]
self.rcChannels['yaw']=temp[2]
self.rcChannels['throttle']=temp[3]
self.rcChannels['elapsed']="%0.3f" % (elapsed,)
self.rcChannels['timestamp']="%0.2f" % (time.time(),)
elif cmd == MultiWii.RAW_IMU:
self.rawIMU['ax']=float(temp[0])
self.rawIMU['ay']=float(temp[1])
self.rawIMU['az']=float(temp[2])
self.rawIMU['gx']=float(temp[3])
self.rawIMU['gy']=float(temp[4])
self.rawIMU['gz']=float(temp[5])
self.rawIMU['elapsed']="%0.3f" % (elapsed,)
self.rawIMU['timestamp']="%0.2f" % (time.time(),)
elif cmd == MultiWii.MOTOR:
self.motor['m1']=float(temp[0])
self.motor['m2']=float(temp[1])
self.motor['m3']=float(temp[2])
self.motor['m4']=float(temp[3])
self.motor['elapsed']="%0.3f" % (elapsed,)
self.motor['timestamp']="%0.2f" % (time.time(),)
except Exception as error:
print(error)
pass
"""Function to ask for 2 fixed cmds, attitude and rc channels, and receive them. Note: is a bit slower than others"""
def getData2cmd(self, cmd):
try:
start = time.time()
self.sendCMD(0,self.ATTITUDE,[])
while True:
header = self.ser.read().decode('utf-8')
if header == '$':
header = header+self.ser.read(2).decode('utf-8')
break
datalength = struct.unpack('<b', self.ser.read())[0]
code = struct.unpack('<b', self.ser.read())
data = self.ser.read(datalength)
temp = struct.unpack('<'+'h'*int(datalength/2),data)
self.ser.flushInput()
self.ser.flushOutput()
self.sendCMD(0,self.RC,[])
while True:
header = self.ser.read().decode('utf-8')
if header == '$':
header = header+self.ser.read(2).decode('utf-8')
break
datalength = struct.unpack('<b', self.ser.read())[0]
code = struct.unpack('<b', self.ser.read())
data = self.ser.read(datalength)
temp2 = struct.unpack('<'+'h'*int(datalength/2),data)
elapsed = time.time() - start
self.ser.flushInput()
self.ser.flushOutput()
if cmd == MultiWii.ATTITUDE:
self.message['angx']=float(temp[0]/10.0)
self.message['angy']=float(temp[1]/10.0)
self.message['heading']=float(temp[2])
self.message['roll']=temp2[0]
self.message['pitch']=temp2[1]
self.message['yaw']=temp2[2]
self.message['throttle']=temp2[3]
self.message['elapsed']=round(elapsed,3)
self.message['timestamp']="%0.2f" % (time.time(),)
return self.message
else:
return "No return error!"
except Exception as error:
print (error)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
3029,
87,
5908,
14,
647,
26,
23873,
6879,
87,
5908,
11973,
11557,
1041,
199,
199,
363,
2502,
363,
275,
298,
2439,
1117,
812,
1273,
305,
2,
199,
363,
7307,
363,
275,
298,
7384,
9708,
4580,
5530,
14,
846,
2,
199,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
22,
2,
199,
363,
26665,
363,
275,
298,
2439,
1117,
812,
1273,
305,
2,
199,
363,
2123,
363,
275,
298,
279,
2033,
88,
2611,
32,
6799,
14,
957,
2,
199,
363,
1205,
363,
275,
298,
23753,
2,
421,
199,
646,
3012,
12,
900,
12,
2702,
421,
199,
533,
6879,
55,
5908,
26,
339,
408,
3947,
87,
5908,
11973,
11557,
1245,
2870,
624,
272,
408,
4245,
26,
2951,
737,
7951,
12,
4819,
9245,
436,
3066,
3416,
85,
12,
663,
3066,
4819,
787,
6366,
737,
314,
12427,
408,
272,
26179,
275,
2948,
272,
18460,
275,
14313,
272,
820,
15088,
63,
1469,
53,
275,
12996,
272,
7017,
10662,
275,
22363,
272,
603,
1387,
726,
275,
21083,
272,
29256,
275,
20462,
272,
820,
15088,
63,
26359,
275,
23746,
272,
16503,
63,
26359,
275,
23543,
272,
10395,
28742,
275,
24579,
272,
12112,
52,
28742,
275,
24058,
272,
1261,
23622,
275,
16814,
272,
29256,
63,
52,
1734,
1206,
275,
20128,
272,
20674,
275,
20240,
272,
5240,
275,
24073,
272,
603,
25806,
275,
23510,
272,
603,
1387,
726,
63,
48,
10789,
275,
22560,
272,
5240,
14546,
275,
25186,
272,
20674,
14546,
275,
26189,
272,
644,
48,
275,
25760,
272,
5240,
20857,
275,
26497,
272,
29256,
63,
4307,
63,
1469,
53,
275,
26228,
272,
11543,
63,
4307,
63,
8205,
275,
1926,
272,
11543,
63,
4307,
63,
26359,
275,
1784,
272,
11543,
63,
16098,
275,
19328,
272,
11543,
63,
15694,
275,
29202,
272,
11543,
63,
8205,
63,
52,
1734,
1206,
275,
14785,
272,
16362,
63,
13329,
2100,
23743,
275,
24005,
272,
603,
1254,
63,
13329,
2100,
23743,
275,
26761,
272,
11543,
63,
9674,
35,
275,
31533,
272,
12565,
775,
63,
3103,
275,
29203,
272,
11543,
63,
22512,
275,
499,
1643,
272,
17548,
15894,
63,
8205,
63,
19637,
275,
26160,
272,
2281,
63,
19637,
275,
30301,
272,
10990,
275,
22540,
272,
812,
10051,
63,
5569,
275,
10523,
272,
812,
10051,
63,
3597,
63,
5569,
275,
17838,
272,
662,
37,
2514,
45,
63,
10387,
275,
16074,
272,
5363,
22679,
275,
10851,
2378,
408,
2543,
11097,
624,
272,
347,
636,
826,
721,
277,
12,
8926,
4313,
304,
398,
408,
7025,
2860,
402,
666,
624,
267,
291,
14,
16098,
8009,
275,
791,
4599,
356,
16,
2584,
322,
356,
16,
2584,
6883,
356,
16,
2584,
802,
356,
16,
2584,
1038,
356,
16,
2584,
8961,
356,
16,
2584,
2279,
356,
16,
2584,
21643,
356,
16,
2584,
24503,
356,
16,
93,
267,
291,
14,
1195,
27138,
275,
791,
2827,
356,
16,
2584,
16966,
356,
16,
2584,
89,
10084,
356,
16,
2584,
20086,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
1773,
1469,
53,
275,
791,
1219,
356,
16,
2584,
1187,
356,
16,
2584,
4651,
356,
16,
2584,
20777,
356,
16,
2584,
4312,
356,
16,
2584,
6838,
356,
16,
2584,
9457,
356,
16,
2584,
1662,
356,
16,
2584,
28808,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
27840,
275,
791,
77,
17,
356,
16,
2584,
77,
18,
356,
16,
2584,
77,
19,
356,
16,
2584,
77,
20,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
292,
7951,
275,
791,
621,
88,
356,
16,
2584,
621,
89,
356,
16,
2584,
13983,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
27539,
275,
791,
597,
4478,
356,
16,
2584,
3808,
79,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
1188,
275,
791,
621,
88,
356,
16,
2584,
621,
89,
356,
16,
2584,
13983,
356,
16,
2584,
2827,
356,
16,
2584,
16966,
356,
16,
2584,
89,
10084,
356,
16,
2584,
20086,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
26784,
2028,
275,
791,
1782,
356,
16,
12,
283,
7877,
356,
16,
12,
283,
2775,
356,
16,
12,
283,
5652,
356,
16,
12,
283,
80,
390,
356,
16,
12,
283,
5187,
356,
16,
93,
267,
291,
14,
808,
275,
334,
2736,
267,
291,
14,
808,
18,
275,
334,
2736,
267,
291,
14,
16691,
275,
378,
267,
291,
14,
21754,
275,
413,
398,
291,
14,
332,
275,
3012,
14,
3571,
342,
267,
291,
14,
332,
14,
719,
275,
8926,
4313,
267,
291,
14,
332,
14,
2470,
27112,
275,
22560,
1840,
267,
291,
14,
332,
14,
4414,
890,
275,
3012,
14,
37,
2830,
14662,
267,
291,
14,
332,
14,
462,
1209,
275,
3012,
14,
4014,
1922,
63,
9185,
267,
291,
14,
332,
14,
2379,
5609,
275,
3012,
14,
11632,
14662,
63,
4817,
267,
291,
14,
332,
14,
2593,
275,
378,
267,
291,
14,
332,
14,
88,
265,
88,
1997,
275,
756,
267,
291,
14,
332,
14,
31210,
3021,
275,
756,
267,
291,
14,
332,
14,
795,
6883,
454,
275,
756,
267,
291,
14,
332,
14,
952,
6372,
275,
499,
267,
408,
1366,
370,
3618,
5133,
314,
13811,
15410,
3439,
279,
624,
267,
21560,
384,
275,
499,
267,
862,
26,
288,
291,
14,
332,
14,
1490,
342,
288,
340,
291,
14,
21754,
26,
355,
870,
1689,
55,
11124,
1536,
13811,
641,
7210,
277,
14,
332,
14,
719,
5207,
12594,
288,
367,
284,
315,
1425,
8,
17,
12,
28715,
304,
355,
340,
291,
14,
21754,
26,
490,
870,
334,
28715,
13,
73,
9,
490,
900,
14,
4532,
8,
17,
9,
355,
587,
26,
490,
900,
14,
4532,
8,
17,
9,
267,
871,
2186,
465,
1125,
26,
288,
870,
25381,
78,
60,
78,
547,
13618,
7210,
277,
14,
332,
14,
719,
5207,
1844,
3134,
78,
7709,
495,
8,
705,
6393,
3212,
78,
60,
78,
531,
339,
408,
3481,
367,
10209,
282,
1414,
370,
314,
13811,
624,
272,
347,
3222,
9744,
8,
277,
12,
666,
63,
1267,
12,
1233,
12,
666,
12,
666,
63,
908,
304,
267,
9040,
275,
378,
267,
3141,
63,
576,
275,
788,
4,
1370,
2143,
360
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
3029,
87,
5908,
14,
647,
26,
23873,
6879,
87,
5908,
11973,
11557,
1041,
199,
199,
363,
2502,
363,
275,
298,
2439,
1117,
812,
1273,
305,
2,
199,
363,
7307,
363,
275,
298,
7384,
9708,
4580,
5530,
14,
846,
2,
199,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
22,
2,
199,
363,
26665,
363,
275,
298,
2439,
1117,
812,
1273,
305,
2,
199,
363,
2123,
363,
275,
298,
279,
2033,
88,
2611,
32,
6799,
14,
957,
2,
199,
363,
1205,
363,
275,
298,
23753,
2,
421,
199,
646,
3012,
12,
900,
12,
2702,
421,
199,
533,
6879,
55,
5908,
26,
339,
408,
3947,
87,
5908,
11973,
11557,
1245,
2870,
624,
272,
408,
4245,
26,
2951,
737,
7951,
12,
4819,
9245,
436,
3066,
3416,
85,
12,
663,
3066,
4819,
787,
6366,
737,
314,
12427,
408,
272,
26179,
275,
2948,
272,
18460,
275,
14313,
272,
820,
15088,
63,
1469,
53,
275,
12996,
272,
7017,
10662,
275,
22363,
272,
603,
1387,
726,
275,
21083,
272,
29256,
275,
20462,
272,
820,
15088,
63,
26359,
275,
23746,
272,
16503,
63,
26359,
275,
23543,
272,
10395,
28742,
275,
24579,
272,
12112,
52,
28742,
275,
24058,
272,
1261,
23622,
275,
16814,
272,
29256,
63,
52,
1734,
1206,
275,
20128,
272,
20674,
275,
20240,
272,
5240,
275,
24073,
272,
603,
25806,
275,
23510,
272,
603,
1387,
726,
63,
48,
10789,
275,
22560,
272,
5240,
14546,
275,
25186,
272,
20674,
14546,
275,
26189,
272,
644,
48,
275,
25760,
272,
5240,
20857,
275,
26497,
272,
29256,
63,
4307,
63,
1469,
53,
275,
26228,
272,
11543,
63,
4307,
63,
8205,
275,
1926,
272,
11543,
63,
4307,
63,
26359,
275,
1784,
272,
11543,
63,
16098,
275,
19328,
272,
11543,
63,
15694,
275,
29202,
272,
11543,
63,
8205,
63,
52,
1734,
1206,
275,
14785,
272,
16362,
63,
13329,
2100,
23743,
275,
24005,
272,
603,
1254,
63,
13329,
2100,
23743,
275,
26761,
272,
11543,
63,
9674,
35,
275,
31533,
272,
12565,
775,
63,
3103,
275,
29203,
272,
11543,
63,
22512,
275,
499,
1643,
272,
17548,
15894,
63,
8205,
63,
19637,
275,
26160,
272,
2281,
63,
19637,
275,
30301,
272,
10990,
275,
22540,
272,
812,
10051,
63,
5569,
275,
10523,
272,
812,
10051,
63,
3597,
63,
5569,
275,
17838,
272,
662,
37,
2514,
45,
63,
10387,
275,
16074,
272,
5363,
22679,
275,
10851,
2378,
408,
2543,
11097,
624,
272,
347,
636,
826,
721,
277,
12,
8926,
4313,
304,
398,
408,
7025,
2860,
402,
666,
624,
267,
291,
14,
16098,
8009,
275,
791,
4599,
356,
16,
2584,
322,
356,
16,
2584,
6883,
356,
16,
2584,
802,
356,
16,
2584,
1038,
356,
16,
2584,
8961,
356,
16,
2584,
2279,
356,
16,
2584,
21643,
356,
16,
2584,
24503,
356,
16,
93,
267,
291,
14,
1195,
27138,
275,
791,
2827,
356,
16,
2584,
16966,
356,
16,
2584,
89,
10084,
356,
16,
2584,
20086,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
1773,
1469,
53,
275,
791,
1219,
356,
16,
2584,
1187,
356,
16,
2584,
4651,
356,
16,
2584,
20777,
356,
16,
2584,
4312,
356,
16,
2584,
6838,
356,
16,
2584,
9457,
356,
16,
2584,
1662,
356,
16,
2584,
28808,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
27840,
275,
791,
77,
17,
356,
16,
2584,
77,
18,
356,
16,
2584,
77,
19,
356,
16,
2584,
77,
20,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
292,
7951,
275,
791,
621,
88,
356,
16,
2584,
621,
89,
356,
16,
2584,
13983,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
27539,
275,
791,
597,
4478,
356,
16,
2584,
3808,
79,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
1188,
275,
791,
621,
88,
356,
16,
2584,
621,
89,
356,
16,
2584,
13983,
356,
16,
2584,
2827,
356,
16,
2584,
16966,
356,
16,
2584,
89,
10084,
356,
16,
2584,
20086,
356,
16,
2584,
16691,
356,
16,
2584,
3954,
356,
16,
93,
267,
291,
14,
26784,
2028,
275,
791,
1782,
356,
16,
12,
283,
7877,
356,
16,
12,
283,
2775,
356,
16,
12,
283,
5652,
356,
16,
12,
283,
80,
390,
356,
16,
12,
283,
5187,
356,
16,
93,
267,
291,
14,
808,
275,
334,
2736,
267,
291,
14,
808,
18,
275,
334,
2736,
267,
291,
14,
16691,
275,
378,
267,
291,
14,
21754,
275,
413,
398,
291,
14,
332,
275,
3012,
14,
3571,
342,
267,
291,
14,
332,
14,
719,
275,
8926,
4313,
267,
291,
14,
332,
14,
2470,
27112,
275,
22560,
1840,
267,
291,
14,
332,
14,
4414,
890,
275,
3012,
14,
37,
2830,
14662,
267,
291,
14,
332,
14,
462,
1209,
275,
3012,
14,
4014,
1922,
63,
9185,
267,
291,
14,
332,
14,
2379,
5609,
275,
3012,
14,
11632,
14662,
63,
4817,
267,
291,
14,
332,
14,
2593,
275,
378,
267,
291,
14,
332,
14,
88,
265,
88,
1997,
275,
756,
267,
291,
14,
332,
14,
31210,
3021,
275,
756,
267,
291,
14,
332,
14,
795,
6883,
454,
275,
756,
267,
291,
14,
332,
14,
952,
6372,
275,
499,
267,
408,
1366,
370,
3618,
5133,
314,
13811,
15410,
3439,
279,
624,
267,
21560,
384,
275,
499,
267,
862,
26,
288,
291,
14,
332,
14,
1490,
342,
288,
340,
291,
14,
21754,
26,
355,
870,
1689,
55,
11124,
1536,
13811,
641,
7210,
277,
14,
332,
14,
719,
5207,
12594,
288,
367,
284,
315,
1425,
8,
17,
12,
28715,
304,
355,
340,
291,
14,
21754,
26,
490,
870,
334,
28715,
13,
73,
9,
490,
900,
14,
4532,
8,
17,
9,
355,
587,
26,
490,
900,
14,
4532,
8,
17,
9,
267,
871,
2186,
465,
1125,
26,
288,
870,
25381,
78,
60,
78,
547,
13618,
7210,
277,
14,
332,
14,
719,
5207,
1844,
3134,
78,
7709,
495,
8,
705,
6393,
3212,
78,
60,
78,
531,
339,
408,
3481,
367,
10209,
282,
1414,
370,
314,
13811,
624,
272,
347,
3222,
9744,
8,
277,
12,
666,
63,
1267,
12,
1233,
12,
666,
12,
666,
63,
908,
304,
267,
9040,
275,
378,
267,
3141,
63,
576,
275,
788,
4,
1370,
2143,
360,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alextsui05/gmock
|
gtest/scripts/fuse_gtest_files.py
|
2577
|
8813
|
#!/usr/bin/env python
#
# Copyright 2009, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""fuse_gtest_files.py v0.2.0
Fuses Google Test source code into a .h file and a .cc file.
SYNOPSIS
fuse_gtest_files.py [GTEST_ROOT_DIR] OUTPUT_DIR
Scans GTEST_ROOT_DIR for Google Test source code, and generates
two files: OUTPUT_DIR/gtest/gtest.h and OUTPUT_DIR/gtest/gtest-all.cc.
Then you can build your tests by adding OUTPUT_DIR to the include
search path and linking with OUTPUT_DIR/gtest/gtest-all.cc. These
two files contain everything you need to use Google Test. Hence
you can "install" Google Test by copying them to wherever you want.
GTEST_ROOT_DIR can be omitted and defaults to the parent
directory of the directory holding this script.
EXAMPLES
./fuse_gtest_files.py fused_gtest
./fuse_gtest_files.py path/to/unpacked/gtest fused_gtest
This tool is experimental. In particular, it assumes that there is no
conditional inclusion of Google Test headers. Please report any
problems to googletestframework@googlegroups.com. You can read
http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide for
more information.
"""
__author__ = 'wan@google.com (Zhanyong Wan)'
import os
import re
import sets
import sys
# We assume that this file is in the scripts/ directory in the Google
# Test root directory.
DEFAULT_GTEST_ROOT_DIR = os.path.join(os.path.dirname(__file__), '..')
# Regex for matching '#include "gtest/..."'.
INCLUDE_GTEST_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(gtest/.+)"')
# Regex for matching '#include "src/..."'.
INCLUDE_SRC_FILE_REGEX = re.compile(r'^\s*#\s*include\s*"(src/.+)"')
# Where to find the source seed files.
GTEST_H_SEED = 'include/gtest/gtest.h'
GTEST_SPI_H_SEED = 'include/gtest/gtest-spi.h'
GTEST_ALL_CC_SEED = 'src/gtest-all.cc'
# Where to put the generated files.
GTEST_H_OUTPUT = 'gtest/gtest.h'
GTEST_ALL_CC_OUTPUT = 'gtest/gtest-all.cc'
def VerifyFileExists(directory, relative_path):
"""Verifies that the given file exists; aborts on failure.
relative_path is the file path relative to the given directory.
"""
if not os.path.isfile(os.path.join(directory, relative_path)):
print 'ERROR: Cannot find %s in directory %s.' % (relative_path,
directory)
print ('Please either specify a valid project root directory '
'or omit it on the command line.')
sys.exit(1)
def ValidateGTestRootDir(gtest_root):
"""Makes sure gtest_root points to a valid gtest root directory.
The function aborts the program on failure.
"""
VerifyFileExists(gtest_root, GTEST_H_SEED)
VerifyFileExists(gtest_root, GTEST_ALL_CC_SEED)
def VerifyOutputFile(output_dir, relative_path):
"""Verifies that the given output file path is valid.
relative_path is relative to the output_dir directory.
"""
# Makes sure the output file either doesn't exist or can be overwritten.
output_file = os.path.join(output_dir, relative_path)
if os.path.exists(output_file):
# TODO(wan@google.com): The following user-interaction doesn't
# work with automated processes. We should provide a way for the
# Makefile to force overwriting the files.
print ('%s already exists in directory %s - overwrite it? (y/N) ' %
(relative_path, output_dir))
answer = sys.stdin.readline().strip()
if answer not in ['y', 'Y']:
print 'ABORTED.'
sys.exit(1)
# Makes sure the directory holding the output file exists; creates
# it and all its ancestors if necessary.
parent_directory = os.path.dirname(output_file)
if not os.path.isdir(parent_directory):
os.makedirs(parent_directory)
def ValidateOutputDir(output_dir):
"""Makes sure output_dir points to a valid output directory.
The function aborts the program on failure.
"""
VerifyOutputFile(output_dir, GTEST_H_OUTPUT)
VerifyOutputFile(output_dir, GTEST_ALL_CC_OUTPUT)
def FuseGTestH(gtest_root, output_dir):
"""Scans folder gtest_root to generate gtest/gtest.h in output_dir."""
output_file = file(os.path.join(output_dir, GTEST_H_OUTPUT), 'w')
processed_files = sets.Set() # Holds all gtest headers we've processed.
def ProcessFile(gtest_header_path):
"""Processes the given gtest header file."""
# We don't process the same header twice.
if gtest_header_path in processed_files:
return
processed_files.add(gtest_header_path)
# Reads each line in the given gtest header.
for line in file(os.path.join(gtest_root, gtest_header_path), 'r'):
m = INCLUDE_GTEST_FILE_REGEX.match(line)
if m:
# It's '#include "gtest/..."' - let's process it recursively.
ProcessFile('include/' + m.group(1))
else:
# Otherwise we copy the line unchanged to the output file.
output_file.write(line)
ProcessFile(GTEST_H_SEED)
output_file.close()
def FuseGTestAllCcToFile(gtest_root, output_file):
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_file."""
processed_files = sets.Set()
def ProcessFile(gtest_source_file):
"""Processes the given gtest source file."""
# We don't process the same #included file twice.
if gtest_source_file in processed_files:
return
processed_files.add(gtest_source_file)
# Reads each line in the given gtest source file.
for line in file(os.path.join(gtest_root, gtest_source_file), 'r'):
m = INCLUDE_GTEST_FILE_REGEX.match(line)
if m:
if 'include/' + m.group(1) == GTEST_SPI_H_SEED:
# It's '#include "gtest/gtest-spi.h"'. This file is not
# #included by "gtest/gtest.h", so we need to process it.
ProcessFile(GTEST_SPI_H_SEED)
else:
# It's '#include "gtest/foo.h"' where foo is not gtest-spi.
# We treat it as '#include "gtest/gtest.h"', as all other
# gtest headers are being fused into gtest.h and cannot be
# #included directly.
# There is no need to #include "gtest/gtest.h" more than once.
if not GTEST_H_SEED in processed_files:
processed_files.add(GTEST_H_SEED)
output_file.write('#include "%s"\n' % (GTEST_H_OUTPUT,))
else:
m = INCLUDE_SRC_FILE_REGEX.match(line)
if m:
# It's '#include "src/foo"' - let's process it recursively.
ProcessFile(m.group(1))
else:
output_file.write(line)
ProcessFile(GTEST_ALL_CC_SEED)
def FuseGTestAllCc(gtest_root, output_dir):
"""Scans folder gtest_root to generate gtest/gtest-all.cc in output_dir."""
output_file = file(os.path.join(output_dir, GTEST_ALL_CC_OUTPUT), 'w')
FuseGTestAllCcToFile(gtest_root, output_file)
output_file.close()
def FuseGTest(gtest_root, output_dir):
"""Fuses gtest.h and gtest-all.cc."""
ValidateGTestRootDir(gtest_root)
ValidateOutputDir(output_dir)
FuseGTestH(gtest_root, output_dir)
FuseGTestAllCc(gtest_root, output_dir)
def main():
argc = len(sys.argv)
if argc == 2:
# fuse_gtest_files.py OUTPUT_DIR
FuseGTest(DEFAULT_GTEST_ROOT_DIR, sys.argv[1])
elif argc == 3:
# fuse_gtest_files.py GTEST_ROOT_DIR OUTPUT_DIR
FuseGTest(sys.argv[1], sys.argv[2])
else:
print __doc__
sys.exit(1)
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
70,
1180,
63,
8385,
63,
1725,
14,
647,
373,
16,
14,
18,
14,
16,
199,
38,
5589,
4475,
1379,
1350,
1233,
1901,
282,
1275,
72,
570,
436,
282,
1275,
2055,
570,
14,
199,
199,
31802,
21665,
1311,
2126,
289,
1180,
63,
8385,
63,
1725,
14,
647,
359,
16151,
63,
5441,
63,
3022,
61,
18746,
63,
3022,
10817,
13916,
796,
18652,
63,
5441,
63,
3022,
367,
4475,
1379,
1350,
1233,
12,
436,
12821,
2126,
2877,
1584,
26,
18746,
63,
3022,
15,
8385,
15,
8385,
14,
72,
436,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
2126,
9442,
1265,
883,
1900,
2195,
2295,
701,
7791,
18746,
63,
3022,
370,
314,
2387,
2126,
2754,
931,
436,
25833,
543,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
221,
5723,
2126,
2877,
1584,
1395,
8137,
1265,
1929,
370,
675,
4475,
1379,
14,
221,
869,
4894,
2126,
1265,
883,
298,
3174,
2,
4475,
1379,
701,
16743,
3062,
370,
2382,
422,
1265,
2934,
14,
10817,
18652,
63,
5441,
63,
3022,
883,
506,
11684,
436,
4243,
370,
314,
1676,
2126,
2082,
402,
314,
2082,
17573,
642,
2884,
14,
199,
199,
8918,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
28580,
63,
8385,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
931,
15,
475,
15,
24497,
15,
8385,
28580,
63,
8385,
199,
199,
2765,
4744,
365,
22820,
14,
221,
1010,
6770,
12,
652,
15194,
626,
2337,
365,
949,
199,
14353,
20396,
402,
4475,
1379,
2323,
14,
221,
7754,
3622,
1263,
199,
22959,
370,
31141,
4857,
32,
3098,
2634,
14,
957,
14,
221,
2047,
883,
1586,
199,
1014,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
3098,
396,
15,
6797,
15,
13266,
774,
23613,
4324,
271,
367,
199,
6878,
2556,
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,
5951,
199,
646,
984,
199,
199,
3,
2136,
5534,
626,
642,
570,
365,
315,
314,
10554,
15,
2082,
315,
314,
4475,
199,
3,
1379,
1738,
2082,
14,
199,
3472,
63,
16151,
63,
5441,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
8385,
15,
11500,
1370,
199,
18171,
63,
16151,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
8385,
15,
6977,
2924,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
2164,
15,
11500,
1370,
199,
18171,
63,
12447,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
2164,
15,
6977,
2924,
358,
199,
199,
3,
17685,
370,
2342,
314,
1350,
6347,
1584,
14,
199,
16151,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
20495,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
13,
8721,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
25508,
275,
283,
2164,
15,
8385,
13,
452,
14,
2055,
7,
199,
199,
3,
17685,
370,
5324,
314,
4046,
1584,
14,
199,
16151,
63,
40,
63,
8414,
275,
283,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
8414,
275,
283,
8385,
15,
8385,
13,
452,
14,
2055,
7,
421,
199,
318,
7635,
1173,
7965,
8,
3619,
12,
3847,
63,
515,
304,
523,
408,
21168,
626,
314,
1627,
570,
3495,
27,
12004,
83,
641,
5988,
14,
819,
3847,
63,
515,
365,
314,
570,
931,
3847,
370,
314,
1627,
2082,
14,
523,
408,
819,
340,
440,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
3619,
12,
3847,
63,
515,
2298,
272,
870,
283,
3170,
26,
18435,
2342,
450,
83,
315,
2082,
450,
83,
3530,
450,
334,
6188,
63,
515,
12,
10028,
2082,
9,
272,
870,
661,
8254,
1902,
4165,
282,
1686,
2199,
1738,
2082,
283,
1779,
283,
269,
19413,
652,
641,
314,
1414,
1004,
2659,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
12134,
39,
774
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
70,
1180,
63,
8385,
63,
1725,
14,
647,
373,
16,
14,
18,
14,
16,
199,
38,
5589,
4475,
1379,
1350,
1233,
1901,
282,
1275,
72,
570,
436,
282,
1275,
2055,
570,
14,
199,
199,
31802,
21665,
1311,
2126,
289,
1180,
63,
8385,
63,
1725,
14,
647,
359,
16151,
63,
5441,
63,
3022,
61,
18746,
63,
3022,
10817,
13916,
796,
18652,
63,
5441,
63,
3022,
367,
4475,
1379,
1350,
1233,
12,
436,
12821,
2126,
2877,
1584,
26,
18746,
63,
3022,
15,
8385,
15,
8385,
14,
72,
436,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
2126,
9442,
1265,
883,
1900,
2195,
2295,
701,
7791,
18746,
63,
3022,
370,
314,
2387,
2126,
2754,
931,
436,
25833,
543,
18746,
63,
3022,
15,
8385,
15,
8385,
13,
452,
14,
2055,
14,
221,
5723,
2126,
2877,
1584,
1395,
8137,
1265,
1929,
370,
675,
4475,
1379,
14,
221,
869,
4894,
2126,
1265,
883,
298,
3174,
2,
4475,
1379,
701,
16743,
3062,
370,
2382,
422,
1265,
2934,
14,
10817,
18652,
63,
5441,
63,
3022,
883,
506,
11684,
436,
4243,
370,
314,
1676,
2126,
2082,
402,
314,
2082,
17573,
642,
2884,
14,
199,
199,
8918,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
28580,
63,
8385,
2126,
16605,
70,
1180,
63,
8385,
63,
1725,
14,
647,
931,
15,
475,
15,
24497,
15,
8385,
28580,
63,
8385,
199,
199,
2765,
4744,
365,
22820,
14,
221,
1010,
6770,
12,
652,
15194,
626,
2337,
365,
949,
199,
14353,
20396,
402,
4475,
1379,
2323,
14,
221,
7754,
3622,
1263,
199,
22959,
370,
31141,
4857,
32,
3098,
2634,
14,
957,
14,
221,
2047,
883,
1586,
199,
1014,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
3098,
396,
15,
6797,
15,
13266,
774,
23613,
4324,
271,
367,
199,
6878,
2556,
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,
5951,
199,
646,
984,
199,
199,
3,
2136,
5534,
626,
642,
570,
365,
315,
314,
10554,
15,
2082,
315,
314,
4475,
199,
3,
1379,
1738,
2082,
14,
199,
3472,
63,
16151,
63,
5441,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
8385,
15,
11500,
1370,
199,
18171,
63,
16151,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
8385,
15,
6977,
2924,
358,
199,
199,
3,
12939,
367,
4877,
3943,
2613,
298,
2164,
15,
11500,
1370,
199,
18171,
63,
12447,
63,
3817,
63,
10710,
275,
295,
14,
2014,
8,
82,
15542,
83,
10,
20262,
83,
10,
2613,
60,
83,
12469,
8,
2164,
15,
6977,
2924,
358,
199,
199,
3,
17685,
370,
2342,
314,
1350,
6347,
1584,
14,
199,
16151,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
20495,
63,
40,
63,
25508,
275,
283,
2613,
15,
8385,
15,
8385,
13,
8721,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
25508,
275,
283,
2164,
15,
8385,
13,
452,
14,
2055,
7,
199,
199,
3,
17685,
370,
5324,
314,
4046,
1584,
14,
199,
16151,
63,
40,
63,
8414,
275,
283,
8385,
15,
8385,
14,
72,
7,
199,
16151,
63,
1761,
63,
2571,
63,
8414,
275,
283,
8385,
15,
8385,
13,
452,
14,
2055,
7,
421,
199,
318,
7635,
1173,
7965,
8,
3619,
12,
3847,
63,
515,
304,
523,
408,
21168,
626,
314,
1627,
570,
3495,
27,
12004,
83,
641,
5988,
14,
819,
3847,
63,
515,
365,
314,
570,
931,
3847,
370,
314,
1627,
2082,
14,
523,
408,
819,
340,
440,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
3619,
12,
3847,
63,
515,
2298,
272,
870,
283,
3170,
26,
18435,
2342,
450,
83,
315,
2082,
450,
83,
3530,
450,
334,
6188,
63,
515,
12,
10028,
2082,
9,
272,
870,
661,
8254,
1902,
4165,
282,
1686,
2199,
1738,
2082,
283,
1779,
283,
269,
19413,
652,
641,
314,
1414,
1004,
2659,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
12134,
39,
774,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ryfeus/lambda-packs
|
pytorch/source/caffe2/python/transformations_test.py
|
1
|
12467
|
# Copyright (c) 2016-present, Facebook, 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 __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from hypothesis import given
import hypothesis.strategies as st
import numpy as np
from caffe2.python.transformations import Transformer
from caffe2.python import core, workspace
from caffe2.python import test_util as tu
transformer = Transformer()
class TestTransformations(tu.TestCase):
def _base_test_net(self):
net = core.Net("net")
net.Conv(["X", "w", "b"], ["Y"], stride=1, pad=0, kernel=3, order="NCHW")
return net
def _add_nnpack(self, net):
transformer.AddNNPACK(net)
assert tu.str_compare(net.Proto().op[0].engine, "NNPACK")
def _fuse_nnpack_convrelu(self, net, expected_result_num_ops,
expected_activation_arg=True):
self._add_nnpack(net)
transformer.FuseNNPACKConvRelu(net)
self.assertEquals(tu.numOps(net), expected_result_num_ops)
has_activation_arg = False
for arg in net.Proto().op[0].arg:
if tu.str_compare(arg.name, "activation"):
assert tu.str_compare(arg.s, "Relu")
has_activation_arg = True
if expected_activation_arg:
assert has_activation_arg
else:
assert not has_activation_arg
def test_transformer_AddNNPACK(self):
net = self._base_test_net()
net.Relu(["Y"], ["Y2"])
self._add_nnpack(net)
def test_transformer_FuseNNPACKConvRelu(self):
net = self._base_test_net()
net.Relu(["Y"], ["Y2"])
self._fuse_nnpack_convrelu(net, 1)
def test_noFuseNNPACKConvRelu(self):
net = self._base_test_net()
net.Relu(["Y"], ["Y2"])
net.Relu(["Y"], ["Y3"])
self._fuse_nnpack_convrelu(net, 3, expected_activation_arg=False)
def test_transformer_FuseNNPACKConvReluNoInplace(self):
net = self._base_test_net()
net.Relu(["Y"], ["X"])
self._fuse_nnpack_convrelu(net, 1)
assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0]
def test_transformer_FuseNNPACKConvReluInplaceRelu(self):
net = self._base_test_net()
net.Relu(["Y"], ["Y"])
self._fuse_nnpack_convrelu(net, 1)
assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0]
def test_transformer_FuseNNPACKConvReluPingPongNaming(self):
net = self._base_test_net()
net.Relu(["Y"], ["X"])
net.Conv(["X", "w", "b"], ["Y"], stride=1, pad=0, kernel=3, order="NCHW")
self._fuse_nnpack_convrelu(net, 2)
assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0]
assert net.Proto().op[1].output[0] != net.Proto().op[1].input[0]
def test_transformer_FuseNNPACKConvReluFollowedByMultipleInputOp(self):
net = self._base_test_net()
net.Relu(["Y"], ["Y2"])
net.Conv(["Y2", "w", "b"], ["Y"], stride=1, pad=0, kernel=3, order="NCHW")
net.Relu(["Y"], ["Y2"])
self._fuse_nnpack_convrelu(net, 2)
assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0]
assert net.Proto().op[1].output[0] != net.Proto().op[1].input[0]
def test_transformer_FuseNNPACKConvReluInplaceFollowedByMultipleInputOp(self):
net = self._base_test_net()
net.Relu(["Y"], ["Y"])
net.Conv(["Y", "w", "b"], ["Y2"], stride=1, pad=0, kernel=3, order="NCHW")
net.Relu(["Y2"], ["Y2"])
self._fuse_nnpack_convrelu(net, 2)
assert net.Proto().op[0].output[0] != net.Proto().op[0].input[0]
assert net.Proto().op[1].output[0] != net.Proto().op[1].input[0]
def test_transformer_SinkMaxPool(self):
net = self._base_test_net()
net.MaxPool(["Y"], ["Y1"], kernel=3)
net.Relu(["Y1"], ["Y1"])
transformer.SinkMaxPool(net)
assert tu.str_compare(net.Proto().op[1].type, "Relu")
assert tu.str_compare(net.Proto().op[2].type, "MaxPool")
@given(
size=st.integers(7, 10),
input_channels=st.integers(1, 10),
seed=st.integers(0, 65535),
order=st.sampled_from(["NCHW", "NHWC"]),
epsilon=st.floats(min_value=1e-5, max_value=1e-2),
)
def test_transformer_FuseConvBN(self, size, input_channels, seed, order, epsilon):
workspace.ResetWorkspace()
net = core.Net("net")
c = input_channels
h = size
w = size
k = 3
net.Conv(["X", "w", "b"], ["Y"], stride=1, pad=0, kernel=k, order=order)
net.SpatialBN(
["Y", "scale", "bias", "mean", "var"],
["Y2"],
is_test=True,
order=order,
epsilon=epsilon,
)
np.random.seed(seed)
if order == "NCHW":
tu.randBlobFloat32("X", 1, c, h, w)
tu.randBlobFloat32("w", c, c, k, k)
else:
tu.randBlobFloat32("X", 1, h, w, c)
tu.randBlobFloat32("w", c, k, k, c)
tu.randBlobsFloat32(["b", "scale", "bias", "mean"], c)
# This is necessary because 1/sqrt(var) is used and if var is too small
# we get floating point artifacts that cause test failures
tu.randBlobFloat32("var", c, offset=0.5)
workspace.RunNetOnce(net)
preTransformOutput = workspace.FetchBlob("Y2").flatten()
workspace.FeedBlob("Y2", np.zeros((1, 1)))
transformer.FuseConvBN(net)
# Ensure fusion
assert tu.numOps(net) == 1
workspace.RunNetOnce(net)
postTransformOutput = workspace.FetchBlob("Y2").flatten()
# Check that there is no numerical difference
assert np.allclose(
preTransformOutput,
postTransformOutput,
rtol=5e-02,
atol=1e-03
)
@given(
size=st.integers(7, 10),
input_channels=st.integers(1, 10),
seed=st.integers(0, 65535),
order=st.sampled_from(["NCHW", "NHWC"]),
epsilon=st.floats(min_value=1e-5, max_value=1e-2),
)
def test_transformer_FuseConvBNNoConvBias(self, size, input_channels, seed, order, epsilon):
workspace.ResetWorkspace()
net = core.Net("net")
c = input_channels
h = size
w = size
k = 3
net.Conv(["X", "w"], ["Y"], stride=1, pad=0, kernel=k, order=order)
net.SpatialBN(
["Y", "scale", "bias", "mean", "var"],
["Y2"],
is_test=True,
order=order,
epsilon=epsilon,
)
np.random.seed(seed)
if order == "NCHW":
tu.randBlobFloat32("X", 1, c, h, w)
tu.randBlobFloat32("w", c, c, k, k)
else:
tu.randBlobFloat32("X", 1, h, w, c)
tu.randBlobFloat32("w", c, k, k, c)
tu.randBlobsFloat32(["scale", "bias", "mean"], c)
# This is necessary because 1/sqrt(var) is used and if var is too small
# we get floating point artifacts that cause test failures
tu.randBlobFloat32("var", c, offset=0.5)
workspace.RunNetOnce(net)
preTransformOutput = workspace.FetchBlob("Y2").flatten()
workspace.FeedBlob("Y2", np.zeros((1, 1)))
transformer.FuseConvBN(net)
# Ensure fusion
assert tu.numOps(net) == 1
workspace.RunNetOnce(net)
postTransformOutput = workspace.FetchBlob("Y2").flatten()
# Check that there is no numerical difference
assert np.allclose(
preTransformOutput,
postTransformOutput,
rtol=5e-02,
atol=1e-03
)
@given(
size=st.integers(7, 10),
input_channels=st.integers(1, 10),
seed=st.integers(0, 65535),
order=st.sampled_from(["NCHW", "NHWC"]),
epsilon=st.floats(min_value=1e-5, max_value=1e-2),
)
def test_transformer_FuseConvBNNoConvBiasDuplicatedName(self, size, input_channels, seed, order, epsilon):
workspace.ResetWorkspace()
net = core.Net("net")
c = input_channels
h = size
w = size
k = 3
net.Conv(["X", "w"], ["Y"], stride=1, pad=0, kernel=k, order=order)
net.SpatialBN(
["Y", "scale", "_bias0", "mean", "var"],
["Y2"],
is_test=True,
order=order,
epsilon=epsilon,
)
np.random.seed(seed)
if order == "NCHW":
tu.randBlobFloat32("X", 1, c, h, w)
tu.randBlobFloat32("w", c, c, k, k)
else:
tu.randBlobFloat32("X", 1, h, w, c)
tu.randBlobFloat32("w", c, k, k, c)
tu.randBlobsFloat32(["scale", "_bias0", "mean"], c)
# This is necessary because 1/sqrt(var) is used and if var is too small
# we get floating point artifacts that cause test failures
tu.randBlobFloat32("var", c, offset=0.5)
workspace.RunNetOnce(net)
preTransformOutput = workspace.FetchBlob("Y2").flatten()
workspace.FeedBlob("Y2", np.zeros((1, 1)))
transformer.FuseConvBN(net)
# Ensure fusion
assert tu.numOps(net) == 1
workspace.RunNetOnce(net)
postTransformOutput = workspace.FetchBlob("Y2").flatten()
print("pre")
print(preTransformOutput)
print("after")
print(postTransformOutput)
# Check that there is no numerical difference
assert np.allclose(
preTransformOutput,
postTransformOutput,
rtol=5e-02,
atol=1e-03
)
@given(
size=st.integers(7, 10),
input_channels=st.integers(1, 10),
kt=st.integers(3, 5),
kh=st.integers(3, 5),
kw=st.integers(3, 5),
seed=st.integers(0, 65535),
epsilon=st.floats(min_value=1e-5, max_value=1e-2),
)
def test_transformer_FuseConv3DBN(
self, size, input_channels, kt, kh, kw, seed, epsilon
):
workspace.ResetWorkspace()
net = core.Net("net")
c = input_channels
t = size
h = size
w = size
net.Conv(
["X", "w", "b"],
["Y"],
kernels=[kt, kh, kw],
)
net.SpatialBN(
["Y", "scale", "bias", "mean", "var"],
["Y2"],
is_test=True,
epsilon=epsilon,
)
np.random.seed(seed)
tu.randBlobFloat32("X", 1, c, t, h, w)
tu.randBlobFloat32("w", c, c, kt, kh, kw)
tu.randBlobsFloat32(["b", "scale", "bias", "mean"], c)
# This is necessary because 1/sqrt(var) is used and if var is too small
# we get floating point artifacts that cause test failures
tu.randBlobFloat32("var", c, offset=0.5)
workspace.RunNetOnce(net)
preTransformOutput = workspace.FetchBlob("Y2").flatten()
workspace.FeedBlob("Y2", np.zeros((1, 1)))
transformer.FuseConvBN(net)
# Ensure fusion
assert tu.numOps(net) == 1
workspace.RunNetOnce(net)
postTransformOutput = workspace.FetchBlob("Y2").flatten()
# Check that there is no numerical difference
assert np.allclose(
preTransformOutput,
postTransformOutput,
rtol=1e-02,
atol=1e-04
)
def test_converterEnforceUnusedInputs(self):
net = core.Net("net")
net.Relu(["X"], ["Y"])
net.Proto().external_input.extend(["fake"])
# This should now work
transformer.AddNNPACK(net) # just testing the converter
def test_converterEnforceUnusedOutputs(self):
net = core.Net("net")
net.Relu(["X"], ["Y"])
net.Proto().external_output.extend(["fake"])
with self.assertRaises(Exception):
transformer.AddNNPACK(net) # just testing the converter
|
mit
|
[
3,
1898,
334,
67,
9,
7800,
13,
1881,
12,
27107,
12,
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,
4605,
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
29268,
492,
1627,
199,
646,
29268,
14,
20694,
1500,
465,
410,
199,
646,
2680,
465,
980,
199,
199,
504,
1704,
2026,
18,
14,
1548,
14,
1515,
17308,
492,
30486,
199,
504,
1704,
2026,
18,
14,
1548,
492,
6170,
12,
14466,
199,
504,
1704,
2026,
18,
14,
1548,
492,
511,
63,
1974,
465,
30799,
199,
199,
19754,
275,
30486,
342,
421,
199,
533,
1379,
3188,
17308,
8,
10963,
14,
1746,
304,
272,
347,
485,
1095,
63,
396,
63,
846,
8,
277,
304,
267,
1851,
275,
6170,
14,
2480,
480,
846,
531,
267,
1851,
14,
11596,
5234,
56,
401,
298,
87,
401,
298,
66,
2255,
2097,
57,
2255,
7345,
29,
17,
12,
6567,
29,
16,
12,
5114,
29,
19,
12,
1865,
628,
27086,
531,
267,
372,
1851,
339,
347,
485,
525,
63,
4411,
1389,
8,
277,
12,
1851,
304,
267,
21484,
14,
1123,
7178,
6961,
8,
846,
9,
267,
702,
30799,
14,
495,
63,
5785,
8,
846,
14,
8548,
1252,
411,
59,
16,
1055,
3908,
12,
298,
7178,
6961,
531,
339,
347,
485,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
277,
12,
1851,
12,
1420,
63,
1099,
63,
1507,
63,
1483,
12,
272,
1420,
63,
12312,
63,
1273,
29,
549,
304,
267,
291,
423,
525,
63,
4411,
1389,
8,
846,
9,
267,
21484,
14,
38,
1180,
7178,
6961,
11596,
5640,
85,
8,
846,
9,
267,
291,
14,
2947,
8,
10963,
14,
1507,
16452,
8,
846,
395,
1420,
63,
1099,
63,
1507,
63,
1483,
9,
267,
965,
63,
12312,
63,
1273,
275,
756,
267,
367,
1680,
315,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1273,
26,
288,
340,
30799,
14,
495,
63,
5785,
8,
1273,
14,
354,
12,
298,
12312,
2349,
355,
702,
30799,
14,
495,
63,
5785,
8,
1273,
14,
83,
12,
298,
5640,
85,
531,
355,
965,
63,
12312,
63,
1273,
275,
715,
267,
340,
1420,
63,
12312,
63,
1273,
26,
288,
702,
965,
63,
12312,
63,
1273,
267,
587,
26,
288,
702,
440,
965,
63,
12312,
63,
1273,
339,
347,
511,
63,
19754,
63,
1123,
7178,
6961,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
18,
3135,
267,
291,
423,
525,
63,
4411,
1389,
8,
846,
9,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
18,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
413,
9,
339,
347,
511,
63,
889,
38,
1180,
7178,
6961,
11596,
5640,
85,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
18,
3135,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
19,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
650,
12,
1420,
63,
12312,
63,
1273,
29,
797,
9,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
1944,
607,
2778,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
56,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
413,
9,
267,
702,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1210,
59,
16,
61,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
607,
2778,
5640,
85,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
413,
9,
267,
702,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1210,
59,
16,
61,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
22638,
48,
951,
46,
9568,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
56,
3135,
267,
1851,
14,
11596,
5234,
56,
401,
298,
87,
401,
298,
66,
2255,
2097,
57,
2255,
7345,
29,
17,
12,
6567,
29,
16,
12,
5114,
29,
19,
12,
1865,
628,
27086,
531,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
499,
9,
267,
702,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1210,
59,
16,
61,
267,
702,
1851,
14,
8548,
1252,
411,
59,
17,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
17,
1055,
1210,
59,
16,
61,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
18696,
379,
2175,
8433,
3205,
4619,
8,
277
] |
[
1898,
334,
67,
9,
7800,
13,
1881,
12,
27107,
12,
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,
4605,
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,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
29268,
492,
1627,
199,
646,
29268,
14,
20694,
1500,
465,
410,
199,
646,
2680,
465,
980,
199,
199,
504,
1704,
2026,
18,
14,
1548,
14,
1515,
17308,
492,
30486,
199,
504,
1704,
2026,
18,
14,
1548,
492,
6170,
12,
14466,
199,
504,
1704,
2026,
18,
14,
1548,
492,
511,
63,
1974,
465,
30799,
199,
199,
19754,
275,
30486,
342,
421,
199,
533,
1379,
3188,
17308,
8,
10963,
14,
1746,
304,
272,
347,
485,
1095,
63,
396,
63,
846,
8,
277,
304,
267,
1851,
275,
6170,
14,
2480,
480,
846,
531,
267,
1851,
14,
11596,
5234,
56,
401,
298,
87,
401,
298,
66,
2255,
2097,
57,
2255,
7345,
29,
17,
12,
6567,
29,
16,
12,
5114,
29,
19,
12,
1865,
628,
27086,
531,
267,
372,
1851,
339,
347,
485,
525,
63,
4411,
1389,
8,
277,
12,
1851,
304,
267,
21484,
14,
1123,
7178,
6961,
8,
846,
9,
267,
702,
30799,
14,
495,
63,
5785,
8,
846,
14,
8548,
1252,
411,
59,
16,
1055,
3908,
12,
298,
7178,
6961,
531,
339,
347,
485,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
277,
12,
1851,
12,
1420,
63,
1099,
63,
1507,
63,
1483,
12,
272,
1420,
63,
12312,
63,
1273,
29,
549,
304,
267,
291,
423,
525,
63,
4411,
1389,
8,
846,
9,
267,
21484,
14,
38,
1180,
7178,
6961,
11596,
5640,
85,
8,
846,
9,
267,
291,
14,
2947,
8,
10963,
14,
1507,
16452,
8,
846,
395,
1420,
63,
1099,
63,
1507,
63,
1483,
9,
267,
965,
63,
12312,
63,
1273,
275,
756,
267,
367,
1680,
315,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1273,
26,
288,
340,
30799,
14,
495,
63,
5785,
8,
1273,
14,
354,
12,
298,
12312,
2349,
355,
702,
30799,
14,
495,
63,
5785,
8,
1273,
14,
83,
12,
298,
5640,
85,
531,
355,
965,
63,
12312,
63,
1273,
275,
715,
267,
340,
1420,
63,
12312,
63,
1273,
26,
288,
702,
965,
63,
12312,
63,
1273,
267,
587,
26,
288,
702,
440,
965,
63,
12312,
63,
1273,
339,
347,
511,
63,
19754,
63,
1123,
7178,
6961,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
18,
3135,
267,
291,
423,
525,
63,
4411,
1389,
8,
846,
9,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
18,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
413,
9,
339,
347,
511,
63,
889,
38,
1180,
7178,
6961,
11596,
5640,
85,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
18,
3135,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
19,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
650,
12,
1420,
63,
12312,
63,
1273,
29,
797,
9,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
1944,
607,
2778,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
56,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
413,
9,
267,
702,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1210,
59,
16,
61,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
607,
2778,
5640,
85,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
57,
3135,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
413,
9,
267,
702,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1210,
59,
16,
61,
339,
347,
511,
63,
19754,
63,
38,
1180,
7178,
6961,
11596,
5640,
85,
22638,
48,
951,
46,
9568,
8,
277,
304,
267,
1851,
275,
291,
423,
1095,
63,
396,
63,
846,
342,
267,
1851,
14,
5640,
85,
5234,
57,
2255,
2097,
56,
3135,
267,
1851,
14,
11596,
5234,
56,
401,
298,
87,
401,
298,
66,
2255,
2097,
57,
2255,
7345,
29,
17,
12,
6567,
29,
16,
12,
5114,
29,
19,
12,
1865,
628,
27086,
531,
267,
291,
423,
70,
1180,
63,
4411,
1389,
63,
5598,
12833,
8,
846,
12,
499,
9,
267,
702,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1199,
59,
16,
61,
1137,
1851,
14,
8548,
1252,
411,
59,
16,
1055,
1210,
59,
16,
61,
267,
702,
1851,
14,
8548,
1252,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
DecipherOne/Troglodyte
|
Trog Build Dependencies/Python26/Lib/test/buffer_tests.py
|
61
|
10504
|
# Tests that work for both bytes and buffer objects.
# See PEP 3137.
import struct
import sys
class MixinBytesBufferCommonTests(object):
"""Tests that work for both bytes and buffer objects.
See PEP 3137.
"""
def marshal(self, x):
"""Convert x into the appropriate type for these tests."""
raise RuntimeError('test class must provide a marshal method')
def test_islower(self):
self.assertFalse(self.marshal(b'').islower())
self.assert_(self.marshal(b'a').islower())
self.assertFalse(self.marshal(b'A').islower())
self.assertFalse(self.marshal(b'\n').islower())
self.assert_(self.marshal(b'abc').islower())
self.assertFalse(self.marshal(b'aBc').islower())
self.assert_(self.marshal(b'abc\n').islower())
self.assertRaises(TypeError, self.marshal(b'abc').islower, 42)
def test_isupper(self):
self.assertFalse(self.marshal(b'').isupper())
self.assertFalse(self.marshal(b'a').isupper())
self.assert_(self.marshal(b'A').isupper())
self.assertFalse(self.marshal(b'\n').isupper())
self.assert_(self.marshal(b'ABC').isupper())
self.assertFalse(self.marshal(b'AbC').isupper())
self.assert_(self.marshal(b'ABC\n').isupper())
self.assertRaises(TypeError, self.marshal(b'abc').isupper, 42)
def test_istitle(self):
self.assertFalse(self.marshal(b'').istitle())
self.assertFalse(self.marshal(b'a').istitle())
self.assert_(self.marshal(b'A').istitle())
self.assertFalse(self.marshal(b'\n').istitle())
self.assert_(self.marshal(b'A Titlecased Line').istitle())
self.assert_(self.marshal(b'A\nTitlecased Line').istitle())
self.assert_(self.marshal(b'A Titlecased, Line').istitle())
self.assertFalse(self.marshal(b'Not a capitalized String').istitle())
self.assertFalse(self.marshal(b'Not\ta Titlecase String').istitle())
self.assertFalse(self.marshal(b'Not--a Titlecase String').istitle())
self.assertFalse(self.marshal(b'NOT').istitle())
self.assertRaises(TypeError, self.marshal(b'abc').istitle, 42)
def test_isspace(self):
self.assertFalse(self.marshal(b'').isspace())
self.assertFalse(self.marshal(b'a').isspace())
self.assert_(self.marshal(b' ').isspace())
self.assert_(self.marshal(b'\t').isspace())
self.assert_(self.marshal(b'\r').isspace())
self.assert_(self.marshal(b'\n').isspace())
self.assert_(self.marshal(b' \t\r\n').isspace())
self.assertFalse(self.marshal(b' \t\r\na').isspace())
self.assertRaises(TypeError, self.marshal(b'abc').isspace, 42)
def test_isalpha(self):
self.assertFalse(self.marshal(b'').isalpha())
self.assert_(self.marshal(b'a').isalpha())
self.assert_(self.marshal(b'A').isalpha())
self.assertFalse(self.marshal(b'\n').isalpha())
self.assert_(self.marshal(b'abc').isalpha())
self.assertFalse(self.marshal(b'aBc123').isalpha())
self.assertFalse(self.marshal(b'abc\n').isalpha())
self.assertRaises(TypeError, self.marshal(b'abc').isalpha, 42)
def test_isalnum(self):
self.assertFalse(self.marshal(b'').isalnum())
self.assert_(self.marshal(b'a').isalnum())
self.assert_(self.marshal(b'A').isalnum())
self.assertFalse(self.marshal(b'\n').isalnum())
self.assert_(self.marshal(b'123abc456').isalnum())
self.assert_(self.marshal(b'a1b3c').isalnum())
self.assertFalse(self.marshal(b'aBc000 ').isalnum())
self.assertFalse(self.marshal(b'abc\n').isalnum())
self.assertRaises(TypeError, self.marshal(b'abc').isalnum, 42)
def test_isdigit(self):
self.assertFalse(self.marshal(b'').isdigit())
self.assertFalse(self.marshal(b'a').isdigit())
self.assert_(self.marshal(b'0').isdigit())
self.assert_(self.marshal(b'0123456789').isdigit())
self.assertFalse(self.marshal(b'0123456789a').isdigit())
self.assertRaises(TypeError, self.marshal(b'abc').isdigit, 42)
def test_lower(self):
self.assertEqual(b'hello', self.marshal(b'HeLLo').lower())
self.assertEqual(b'hello', self.marshal(b'hello').lower())
self.assertRaises(TypeError, self.marshal(b'hello').lower, 42)
def test_upper(self):
self.assertEqual(b'HELLO', self.marshal(b'HeLLo').upper())
self.assertEqual(b'HELLO', self.marshal(b'HELLO').upper())
self.assertRaises(TypeError, self.marshal(b'hello').upper, 42)
def test_capitalize(self):
self.assertEqual(b' hello ', self.marshal(b' hello ').capitalize())
self.assertEqual(b'Hello ', self.marshal(b'Hello ').capitalize())
self.assertEqual(b'Hello ', self.marshal(b'hello ').capitalize())
self.assertEqual(b'Aaaa', self.marshal(b'aaaa').capitalize())
self.assertEqual(b'Aaaa', self.marshal(b'AaAa').capitalize())
self.assertRaises(TypeError, self.marshal(b'hello').capitalize, 42)
def test_ljust(self):
self.assertEqual(b'abc ', self.marshal(b'abc').ljust(10))
self.assertEqual(b'abc ', self.marshal(b'abc').ljust(6))
self.assertEqual(b'abc', self.marshal(b'abc').ljust(3))
self.assertEqual(b'abc', self.marshal(b'abc').ljust(2))
self.assertEqual(b'abc*******', self.marshal(b'abc').ljust(10, '*'))
self.assertRaises(TypeError, self.marshal(b'abc').ljust)
def test_rjust(self):
self.assertEqual(b' abc', self.marshal(b'abc').rjust(10))
self.assertEqual(b' abc', self.marshal(b'abc').rjust(6))
self.assertEqual(b'abc', self.marshal(b'abc').rjust(3))
self.assertEqual(b'abc', self.marshal(b'abc').rjust(2))
self.assertEqual(b'*******abc', self.marshal(b'abc').rjust(10, '*'))
self.assertRaises(TypeError, self.marshal(b'abc').rjust)
def test_center(self):
self.assertEqual(b' abc ', self.marshal(b'abc').center(10))
self.assertEqual(b' abc ', self.marshal(b'abc').center(6))
self.assertEqual(b'abc', self.marshal(b'abc').center(3))
self.assertEqual(b'abc', self.marshal(b'abc').center(2))
self.assertEqual(b'***abc****', self.marshal(b'abc').center(10, '*'))
self.assertRaises(TypeError, self.marshal(b'abc').center)
def test_swapcase(self):
self.assertEqual(b'hEllO CoMPuTErS',
self.marshal(b'HeLLo cOmpUteRs').swapcase())
self.assertRaises(TypeError, self.marshal(b'hello').swapcase, 42)
def test_zfill(self):
self.assertEqual(b'123', self.marshal(b'123').zfill(2))
self.assertEqual(b'123', self.marshal(b'123').zfill(3))
self.assertEqual(b'0123', self.marshal(b'123').zfill(4))
self.assertEqual(b'+123', self.marshal(b'+123').zfill(3))
self.assertEqual(b'+123', self.marshal(b'+123').zfill(4))
self.assertEqual(b'+0123', self.marshal(b'+123').zfill(5))
self.assertEqual(b'-123', self.marshal(b'-123').zfill(3))
self.assertEqual(b'-123', self.marshal(b'-123').zfill(4))
self.assertEqual(b'-0123', self.marshal(b'-123').zfill(5))
self.assertEqual(b'000', self.marshal(b'').zfill(3))
self.assertEqual(b'34', self.marshal(b'34').zfill(1))
self.assertEqual(b'0034', self.marshal(b'34').zfill(4))
self.assertRaises(TypeError, self.marshal(b'123').zfill)
def test_expandtabs(self):
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(4))
self.assertEqual(b'abc\r\nab def\ng hi',
self.marshal(b'abc\r\nab\tdef\ng\thi').expandtabs(4))
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs())
self.assertEqual(b'abc\rab def\ng hi',
self.marshal(b'abc\rab\tdef\ng\thi').expandtabs(8))
self.assertEqual(b'abc\r\nab\r\ndef\ng\r\nhi',
self.marshal(b'abc\r\nab\r\ndef\ng\r\nhi').expandtabs(4))
self.assertEqual(b' a\n b', self.marshal(b' \ta\n\tb').expandtabs(1))
self.assertRaises(TypeError, self.marshal(b'hello').expandtabs, 42, 42)
# This test is only valid when sizeof(int) == sizeof(void*) == 4.
if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
self.assertRaises(OverflowError,
self.marshal(b'\ta\n\tb').expandtabs, sys.maxint)
def test_title(self):
self.assertEqual(b' Hello ', self.marshal(b' hello ').title())
self.assertEqual(b'Hello ', self.marshal(b'hello ').title())
self.assertEqual(b'Hello ', self.marshal(b'Hello ').title())
self.assertEqual(b'Format This As Title String',
self.marshal(b'fOrMaT thIs aS titLe String').title())
self.assertEqual(b'Format,This-As*Title;String',
self.marshal(b'fOrMaT,thIs-aS*titLe;String').title())
self.assertEqual(b'Getint', self.marshal(b'getInt').title())
self.assertRaises(TypeError, self.marshal(b'hello').title, 42)
def test_splitlines(self):
self.assertEqual([b'abc', b'def', b'', b'ghi'],
self.marshal(b'abc\ndef\n\rghi').splitlines())
self.assertEqual([b'abc', b'def', b'', b'ghi'],
self.marshal(b'abc\ndef\n\r\nghi').splitlines())
self.assertEqual([b'abc', b'def', b'ghi'],
self.marshal(b'abc\ndef\r\nghi').splitlines())
self.assertEqual([b'abc', b'def', b'ghi'],
self.marshal(b'abc\ndef\r\nghi\n').splitlines())
self.assertEqual([b'abc', b'def', b'ghi', b''],
self.marshal(b'abc\ndef\r\nghi\n\r').splitlines())
self.assertEqual([b'', b'abc', b'def', b'ghi', b''],
self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines())
self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'],
self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(1))
self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42)
|
mit
|
[
3,
6496,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
199,
3,
1666,
13663,
650,
7498,
14,
199,
199,
646,
2702,
199,
646,
984,
199,
199,
533,
28438,
5571,
3299,
7844,
2925,
8,
785,
304,
272,
408,
2925,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
272,
1666,
13663,
650,
7498,
14,
272,
408,
339,
347,
21985,
8,
277,
12,
671,
304,
267,
408,
7306,
671,
1901,
314,
5827,
730,
367,
3520,
2295,
1041,
267,
746,
6064,
360,
396,
1021,
1471,
5647,
282,
21985,
1083,
358,
339,
347,
511,
63,
374,
2325,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
2325,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
2325,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
2325,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
2325,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
1959,
374,
2325,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
2325,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
12,
5685,
9,
339,
347,
511,
63,
374,
4142,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4142,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4142,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4142,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4142,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
8390,
1959,
374,
4142,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
5583,
35,
1959,
374,
4142,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
8390,
60,
78,
1959,
374,
4142,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4142,
12,
5685,
9,
339,
347,
511,
63,
631,
5776,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
7030,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
60,
78,
6888,
32738,
7030,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
12,
7030,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
282,
17094,
1759,
2624,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
60,
502,
16881,
2546,
2624,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
306,
65,
16881,
2546,
2624,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
4609,
1959,
631,
5776,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
631,
5776,
12,
5685,
9,
339,
347,
511,
63,
23360,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
23360,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
27274,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
1154,
84,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
1154,
82,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
1154,
78,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
78,
1959,
23360,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
3540,
1959,
23360,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
23360,
12,
5685,
9,
339,
347,
511,
63,
374,
4468,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4468,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4468,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4468,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4468,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
4288,
1959,
374,
4468,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
4468,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
12,
5685,
9,
339,
347,
511,
63,
28235,
1507,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
28235,
1507,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
4288,
3175,
11419,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
17,
66,
19,
67,
1959,
28235,
1507,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8
] |
[
6496,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
199,
3,
1666,
13663,
650,
7498,
14,
199,
199,
646,
2702,
199,
646,
984,
199,
199,
533,
28438,
5571,
3299,
7844,
2925,
8,
785,
304,
272,
408,
2925,
626,
1736,
367,
3865,
2783,
436,
3335,
2251,
14,
272,
1666,
13663,
650,
7498,
14,
272,
408,
339,
347,
21985,
8,
277,
12,
671,
304,
267,
408,
7306,
671,
1901,
314,
5827,
730,
367,
3520,
2295,
1041,
267,
746,
6064,
360,
396,
1021,
1471,
5647,
282,
21985,
1083,
358,
339,
347,
511,
63,
374,
2325,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
2325,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
2325,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
2325,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
2325,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
1959,
374,
2325,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
2325,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
2325,
12,
5685,
9,
339,
347,
511,
63,
374,
4142,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4142,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4142,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4142,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4142,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
8390,
1959,
374,
4142,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
5583,
35,
1959,
374,
4142,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
8390,
60,
78,
1959,
374,
4142,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4142,
12,
5685,
9,
339,
347,
511,
63,
631,
5776,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
7030,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
60,
78,
6888,
32738,
7030,
1959,
631,
5776,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
16881,
32738,
12,
7030,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
282,
17094,
1759,
2624,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
60,
502,
16881,
2546,
2624,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1763,
306,
65,
16881,
2546,
2624,
1959,
631,
5776,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
4609,
1959,
631,
5776,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
631,
5776,
12,
5685,
9,
339,
347,
511,
63,
23360,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
23360,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
27274,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
1154,
84,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
1154,
82,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
1154,
78,
1959,
23360,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
78,
1959,
23360,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
971,
84,
60,
82,
60,
3540,
1959,
23360,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
23360,
12,
5685,
9,
339,
347,
511,
63,
374,
4468,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
374,
4468,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
1959,
374,
4468,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
374,
4468,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
374,
4468,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
65,
34,
67,
4288,
1959,
374,
4468,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
3175,
60,
78,
1959,
374,
4468,
1012,
267,
291,
14,
1855,
8,
4333,
12,
291,
14,
18376,
8,
66,
7,
3175,
1959,
374,
4468,
12,
5685,
9,
339,
347,
511,
63,
28235,
1507,
8,
277,
304,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
7,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
33,
1959,
28235,
1507,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
66,
1154,
78,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
4288,
3175,
11419,
1959,
28235,
1507,
1012,
267,
291,
14,
479,
2531,
277,
14,
18376,
8,
66,
7,
65,
17,
66,
19,
67,
1959,
28235,
1507,
1012,
267,
291,
14,
3334,
8,
277,
14,
18376,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mio-to/cnambot
|
simulations/cnambot/cyr_demo02.py
|
1
|
2268
|
from morse.builder import *
# Land robot
morsy = Morsy()
morsy.translate(2.25, -0.75)
pose = Pose()
pose.translate(x=-0.0, z=0.0)
morsy.append(pose)
gripper = Gripper()
gripper.translate(x=0.2000, z=0.5000)
gripper.properties(Angle=360.0, Distance=0.5);
morsy.append(gripper)
camera = VideoCamera()
camera.translate(x=0.2000, z=0.9000)
camera.properties(cam_width=128, cam_height=128);
morsy.append(camera)
waypoint = Waypoint()
waypoint.translate(x=0.0, y=0.0, z=0.0)
waypoint.properties(AngleTolerance=0.1, Speed=50.0)
morsy.append(waypoint)
motion = MotionVW()
morsy.append(motion)
motion.add_service('socket')
gripper.add_service('socket')
pose.add_service('socket')
camera.add_interface('socket')
waypoint.add_interface('socket')
duke = Morsy()
duke.translate(-18.25, -0.25)
pose = Pose()
pose.translate(x=-0.0, z=0.0)
duke.append(pose)
gripper = Gripper()
gripper.translate(x=0.2000, z=0.5000)
gripper.properties(Angle=360.0, Distance=0.5);
duke.append(gripper)
camera = VideoCamera()
camera.translate(x=0.2000, z=0.9000)
camera.properties(cam_width=128, cam_height=128);
duke.append(camera)
waypoint = Waypoint()
waypoint.translate(x=0.0, y=0.0, z=0.0)
waypoint.properties(AngleTolerance=0.1, Speed=50.0)
duke.append(waypoint)
motion = MotionVW()
duke.append(motion)
motion.add_service('socket')
gripper.add_service('socket')
pose.add_service('socket')
camera.add_interface('socket')
waypoint.add_interface('socket')
lara = Morsy()
lara.translate(-8.75, -9.25)
pose = Pose()
pose.translate(x=-0.0, z=0.0)
lara.append(pose)
gripper = Gripper()
gripper.translate(x=0.2000, z=0.5000)
gripper.properties(Angle=360.0, Distance=0.5);
lara.append(gripper)
camera = VideoCamera()
camera.translate(x=0.2000, z=0.9000)
camera.properties(cam_width=128, cam_height=128);
lara.append(camera)
waypoint = Waypoint()
waypoint.translate(x=0.0, y=0.0, z=0.0)
waypoint.properties(AngleTolerance=0.1, Speed=50.0)
lara.append(waypoint)
motion = MotionVW()
lara.append(motion)
motion.add_service('socket')
gripper.add_service('socket')
pose.add_service('socket')
camera.add_interface('socket')
waypoint.add_interface('socket')
env = Environment('/home/orocos/Desktop/cnambot/code/environment_blender/indoor-5')
env.set_camera_rotation([1.0470, 0, 0.7854])
|
gpl-2.0
|
[
504,
333,
9050,
14,
5649,
492,
627,
199,
199,
3,
491,
460,
14544,
199,
77,
1384,
89,
275,
603,
1384,
89,
342,
199,
77,
1384,
89,
14,
5275,
8,
18,
14,
821,
12,
446,
16,
14,
2194,
9,
199,
199,
4070,
275,
510,
3362,
342,
199,
4070,
14,
5275,
8,
88,
4022,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
77,
1384,
89,
14,
740,
8,
4070,
9,
199,
199,
7928,
80,
529,
275,
598,
24210,
529,
342,
199,
7928,
80,
529,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
13128,
9,
199,
7928,
80,
529,
14,
3282,
8,
16943,
29,
11197,
14,
16,
12,
21892,
29,
16,
14,
21,
2736,
199,
77,
1384,
89,
14,
740,
8,
7928,
80,
529,
9,
199,
199,
11928,
275,
15709,
18425,
342,
199,
11928,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
25,
1493,
9,
199,
11928,
14,
3282,
8,
15176,
63,
2063,
29,
3933,
12,
27570,
63,
3333,
29,
3933,
2736,
199,
77,
1384,
89,
14,
740,
8,
11928,
9,
199,
199,
3316,
1403,
275,
644,
1187,
1403,
342,
199,
3316,
1403,
14,
5275,
8,
88,
29,
16,
14,
16,
12,
612,
29,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
3316,
1403,
14,
3282,
8,
16943,
1378,
8807,
29,
16,
14,
17,
12,
428,
4536,
29,
1400,
14,
16,
9,
199,
77,
1384,
89,
14,
740,
8,
3316,
1403,
9,
199,
199,
15335,
275,
3930,
296,
54,
55,
342,
199,
77,
1384,
89,
14,
740,
8,
15335,
9,
199,
199,
15335,
14,
525,
63,
1364,
360,
3450,
358,
199,
7928,
80,
529,
14,
525,
63,
1364,
360,
3450,
358,
199,
4070,
14,
525,
63,
1364,
360,
3450,
358,
199,
11928,
14,
525,
63,
3266,
360,
3450,
358,
199,
3316,
1403,
14,
525,
63,
3266,
360,
3450,
358,
4388,
199,
2033,
415,
275,
603,
1384,
89,
342,
199,
2033,
415,
14,
5275,
2801,
1085,
14,
821,
12,
446,
16,
14,
821,
9,
199,
199,
4070,
275,
510,
3362,
342,
199,
4070,
14,
5275,
8,
88,
4022,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
2033,
415,
14,
740,
8,
4070,
9,
199,
199,
7928,
80,
529,
275,
598,
24210,
529,
342,
199,
7928,
80,
529,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
13128,
9,
199,
7928,
80,
529,
14,
3282,
8,
16943,
29,
11197,
14,
16,
12,
21892,
29,
16,
14,
21,
2736,
199,
2033,
415,
14,
740,
8,
7928,
80,
529,
9,
199,
199,
11928,
275,
15709,
18425,
342,
199,
11928,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
25,
1493,
9,
199,
11928,
14,
3282,
8,
15176,
63,
2063,
29,
3933,
12,
27570,
63,
3333,
29,
3933,
2736,
199,
2033,
415,
14,
740,
8,
11928,
9,
199,
199,
3316,
1403,
275,
644,
1187,
1403,
342,
199,
3316,
1403,
14,
5275,
8,
88,
29,
16,
14,
16,
12,
612,
29,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
3316,
1403,
14,
3282,
8,
16943,
1378,
8807,
29,
16,
14,
17,
12,
428,
4536,
29,
1400,
14,
16,
9,
199,
2033,
415,
14,
740,
8,
3316,
1403,
9,
199,
199,
15335,
275,
3930,
296,
54,
55,
342,
199,
2033,
415,
14,
740,
8,
15335,
9,
199,
199,
15335,
14,
525,
63,
1364,
360,
3450,
358,
199,
7928,
80,
529,
14,
525,
63,
1364,
360,
3450,
358,
199,
4070,
14,
525,
63,
1364,
360,
3450,
358,
199,
11928,
14,
525,
63,
3266,
360,
3450,
358,
199,
3316,
1403,
14,
525,
63,
3266,
360,
3450,
358,
199,
199,
9828,
65,
275,
603,
1384,
89,
342,
199,
9828,
65,
14,
5275,
2801,
24,
14,
2194,
12,
446,
25,
14,
821,
9,
199,
199,
4070,
275,
510,
3362,
342,
199,
4070,
14,
5275,
8,
88,
4022,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
9828,
65,
14,
740,
8,
4070,
9,
199,
199,
7928,
80,
529,
275,
598,
24210,
529,
342,
199,
7928,
80,
529,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
13128,
9,
199,
7928,
80,
529,
14,
3282,
8,
16943,
29,
11197,
14,
16,
12,
21892,
29,
16,
14,
21,
2736,
199,
9828,
65,
14,
740,
8,
7928,
80,
529,
9,
199,
199,
11928,
275,
15709,
18425,
342,
199,
11928,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
25,
1493,
9,
199,
11928,
14,
3282,
8,
15176,
63,
2063,
29,
3933,
12,
27570,
63,
3333,
29,
3933,
2736,
199,
9828,
65,
14,
740,
8,
11928,
9,
199,
199,
3316,
1403,
275,
644,
1187,
1403,
342,
199,
3316,
1403,
14,
5275,
8,
88,
29,
16,
14,
16,
12,
612,
29,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
3316,
1403,
14,
3282,
8,
16943,
1378,
8807,
29,
16,
14,
17,
12,
428,
4536,
29,
1400,
14,
16,
9,
199,
9828,
65,
14,
740,
8,
3316,
1403,
9,
199,
199,
15335,
275,
3930,
296,
54,
55,
342,
199,
9828,
65,
14,
740,
8,
15335,
9,
421,
199,
15335,
14,
525,
63,
1364,
360,
3450,
358,
199,
7928,
80,
529,
14,
525,
63,
1364,
360,
3450,
358,
199,
4070,
14,
525,
63,
1364,
360,
3450,
358,
199,
11928,
14,
525,
63,
3266,
360,
3450,
358,
199,
3316,
1403,
14,
525,
63,
3266,
360,
3450,
358,
421,
199,
1813,
275,
9711,
2336,
4219,
15,
269,
79,
5197,
15,
20436,
15,
6413,
455,
3018,
15,
600,
15,
5418,
63,
66,
24912,
15,
688,
79,
269,
13,
21,
358,
199,
1813,
14,
409,
63,
11928,
63,
15362,
779,
17,
14,
966,
2760,
12,
378,
12,
378,
14,
2277,
1477,
566,
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
] |
[
333,
9050,
14,
5649,
492,
627,
199,
199,
3,
491,
460,
14544,
199,
77,
1384,
89,
275,
603,
1384,
89,
342,
199,
77,
1384,
89,
14,
5275,
8,
18,
14,
821,
12,
446,
16,
14,
2194,
9,
199,
199,
4070,
275,
510,
3362,
342,
199,
4070,
14,
5275,
8,
88,
4022,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
77,
1384,
89,
14,
740,
8,
4070,
9,
199,
199,
7928,
80,
529,
275,
598,
24210,
529,
342,
199,
7928,
80,
529,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
13128,
9,
199,
7928,
80,
529,
14,
3282,
8,
16943,
29,
11197,
14,
16,
12,
21892,
29,
16,
14,
21,
2736,
199,
77,
1384,
89,
14,
740,
8,
7928,
80,
529,
9,
199,
199,
11928,
275,
15709,
18425,
342,
199,
11928,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
25,
1493,
9,
199,
11928,
14,
3282,
8,
15176,
63,
2063,
29,
3933,
12,
27570,
63,
3333,
29,
3933,
2736,
199,
77,
1384,
89,
14,
740,
8,
11928,
9,
199,
199,
3316,
1403,
275,
644,
1187,
1403,
342,
199,
3316,
1403,
14,
5275,
8,
88,
29,
16,
14,
16,
12,
612,
29,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
3316,
1403,
14,
3282,
8,
16943,
1378,
8807,
29,
16,
14,
17,
12,
428,
4536,
29,
1400,
14,
16,
9,
199,
77,
1384,
89,
14,
740,
8,
3316,
1403,
9,
199,
199,
15335,
275,
3930,
296,
54,
55,
342,
199,
77,
1384,
89,
14,
740,
8,
15335,
9,
199,
199,
15335,
14,
525,
63,
1364,
360,
3450,
358,
199,
7928,
80,
529,
14,
525,
63,
1364,
360,
3450,
358,
199,
4070,
14,
525,
63,
1364,
360,
3450,
358,
199,
11928,
14,
525,
63,
3266,
360,
3450,
358,
199,
3316,
1403,
14,
525,
63,
3266,
360,
3450,
358,
4388,
199,
2033,
415,
275,
603,
1384,
89,
342,
199,
2033,
415,
14,
5275,
2801,
1085,
14,
821,
12,
446,
16,
14,
821,
9,
199,
199,
4070,
275,
510,
3362,
342,
199,
4070,
14,
5275,
8,
88,
4022,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
2033,
415,
14,
740,
8,
4070,
9,
199,
199,
7928,
80,
529,
275,
598,
24210,
529,
342,
199,
7928,
80,
529,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
13128,
9,
199,
7928,
80,
529,
14,
3282,
8,
16943,
29,
11197,
14,
16,
12,
21892,
29,
16,
14,
21,
2736,
199,
2033,
415,
14,
740,
8,
7928,
80,
529,
9,
199,
199,
11928,
275,
15709,
18425,
342,
199,
11928,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
25,
1493,
9,
199,
11928,
14,
3282,
8,
15176,
63,
2063,
29,
3933,
12,
27570,
63,
3333,
29,
3933,
2736,
199,
2033,
415,
14,
740,
8,
11928,
9,
199,
199,
3316,
1403,
275,
644,
1187,
1403,
342,
199,
3316,
1403,
14,
5275,
8,
88,
29,
16,
14,
16,
12,
612,
29,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
3316,
1403,
14,
3282,
8,
16943,
1378,
8807,
29,
16,
14,
17,
12,
428,
4536,
29,
1400,
14,
16,
9,
199,
2033,
415,
14,
740,
8,
3316,
1403,
9,
199,
199,
15335,
275,
3930,
296,
54,
55,
342,
199,
2033,
415,
14,
740,
8,
15335,
9,
199,
199,
15335,
14,
525,
63,
1364,
360,
3450,
358,
199,
7928,
80,
529,
14,
525,
63,
1364,
360,
3450,
358,
199,
4070,
14,
525,
63,
1364,
360,
3450,
358,
199,
11928,
14,
525,
63,
3266,
360,
3450,
358,
199,
3316,
1403,
14,
525,
63,
3266,
360,
3450,
358,
199,
199,
9828,
65,
275,
603,
1384,
89,
342,
199,
9828,
65,
14,
5275,
2801,
24,
14,
2194,
12,
446,
25,
14,
821,
9,
199,
199,
4070,
275,
510,
3362,
342,
199,
4070,
14,
5275,
8,
88,
4022,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
9828,
65,
14,
740,
8,
4070,
9,
199,
199,
7928,
80,
529,
275,
598,
24210,
529,
342,
199,
7928,
80,
529,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
13128,
9,
199,
7928,
80,
529,
14,
3282,
8,
16943,
29,
11197,
14,
16,
12,
21892,
29,
16,
14,
21,
2736,
199,
9828,
65,
14,
740,
8,
7928,
80,
529,
9,
199,
199,
11928,
275,
15709,
18425,
342,
199,
11928,
14,
5275,
8,
88,
29,
16,
14,
8269,
12,
1315,
29,
16,
14,
25,
1493,
9,
199,
11928,
14,
3282,
8,
15176,
63,
2063,
29,
3933,
12,
27570,
63,
3333,
29,
3933,
2736,
199,
9828,
65,
14,
740,
8,
11928,
9,
199,
199,
3316,
1403,
275,
644,
1187,
1403,
342,
199,
3316,
1403,
14,
5275,
8,
88,
29,
16,
14,
16,
12,
612,
29,
16,
14,
16,
12,
1315,
29,
16,
14,
16,
9,
199,
3316,
1403,
14,
3282,
8,
16943,
1378,
8807,
29,
16,
14,
17,
12,
428,
4536,
29,
1400,
14,
16,
9,
199,
9828,
65,
14,
740,
8,
3316,
1403,
9,
199,
199,
15335,
275,
3930,
296,
54,
55,
342,
199,
9828,
65,
14,
740,
8,
15335,
9,
421,
199,
15335,
14,
525,
63,
1364,
360,
3450,
358,
199,
7928,
80,
529,
14,
525,
63,
1364,
360,
3450,
358,
199,
4070,
14,
525,
63,
1364,
360,
3450,
358,
199,
11928,
14,
525,
63,
3266,
360,
3450,
358,
199,
3316,
1403,
14,
525,
63,
3266,
360,
3450,
358,
421,
199,
1813,
275,
9711,
2336,
4219,
15,
269,
79,
5197,
15,
20436,
15,
6413,
455,
3018,
15,
600,
15,
5418,
63,
66,
24912,
15,
688,
79,
269,
13,
21,
358,
199,
1813,
14,
409,
63,
11928,
63,
15362,
779,
17,
14,
966,
2760,
12,
378,
12,
378,
14,
2277,
1477,
566,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mancoast/CPythonPyc_test
|
fail/331_test_code_module.py
|
32
|
2478
|
"Test InteractiveConsole and InteractiveInterpreter from code module"
import sys
import unittest
from contextlib import ExitStack
from unittest import mock
from test import support
code = support.import_module('code')
class TestInteractiveConsole(unittest.TestCase):
def setUp(self):
self.console = code.InteractiveConsole()
self.mock_sys()
def mock_sys(self):
"Mock system environment for InteractiveConsole"
# use exit stack to match patch context managers to addCleanup
stack = ExitStack()
self.addCleanup(stack.close)
self.infunc = stack.enter_context(mock.patch('code.input',
create=True))
self.stdout = stack.enter_context(mock.patch('code.sys.stdout'))
self.stderr = stack.enter_context(mock.patch('code.sys.stderr'))
prepatch = mock.patch('code.sys', wraps=code.sys, spec=code.sys)
self.sysmod = stack.enter_context(prepatch)
if sys.excepthook is sys.__excepthook__:
self.sysmod.excepthook = self.sysmod.__excepthook__
def test_ps1(self):
self.infunc.side_effect = EOFError('Finished')
self.console.interact()
self.assertEqual(self.sysmod.ps1, '>>> ')
def test_ps2(self):
self.infunc.side_effect = EOFError('Finished')
self.console.interact()
self.assertEqual(self.sysmod.ps2, '... ')
def test_console_stderr(self):
self.infunc.side_effect = ["'antioch'", "", EOFError('Finished')]
self.console.interact()
for call in list(self.stdout.method_calls):
if 'antioch' in ''.join(call[1]):
break
else:
raise AssertionError("no console stdout")
def test_syntax_error(self):
self.infunc.side_effect = ["undefined", EOFError('Finished')]
self.console.interact()
for call in self.stderr.method_calls:
if 'NameError:' in ''.join(call[1]):
break
else:
raise AssertionError("No syntax error from console")
def test_sysexcepthook(self):
self.infunc.side_effect = ["raise ValueError('')",
EOFError('Finished')]
hook = mock.Mock()
self.sysmod.excepthook = hook
self.console.interact()
self.assertTrue(hook.called)
def test_main():
support.run_unittest(TestInteractiveConsole)
if __name__ == "__main__":
unittest.main()
|
gpl-3.0
|
[
2,
774,
1010,
7502,
9270,
436,
1010,
7502,
2620,
26499,
687,
1233,
859,
2,
199,
646,
984,
199,
646,
2882,
199,
504,
15502,
492,
18704,
4851,
199,
504,
2882,
492,
1683,
199,
504,
511,
492,
2291,
199,
199,
600,
275,
2291,
14,
646,
63,
578,
360,
600,
358,
421,
199,
533,
1379,
23879,
9270,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
6614,
275,
1233,
14,
23879,
9270,
342,
267,
291,
14,
1805,
63,
1274,
342,
339,
347,
1683,
63,
1274,
8,
277,
304,
267,
298,
3346,
2656,
3734,
367,
1010,
7502,
9270,
2,
267,
327,
675,
4458,
3464,
370,
1336,
3371,
1067,
19680,
370,
1050,
7891,
267,
3464,
275,
18704,
4851,
342,
267,
291,
14,
12808,
8,
2340,
14,
1600,
9,
267,
291,
14,
262,
1532,
275,
3464,
14,
4200,
63,
1100,
8,
1805,
14,
2068,
360,
600,
14,
1210,
297,
5101,
1218,
29,
549,
430,
267,
291,
14,
2703,
275,
3464,
14,
4200,
63,
1100,
8,
1805,
14,
2068,
360,
600,
14,
1274,
14,
2703,
1333,
267,
291,
14,
3083,
275,
3464,
14,
4200,
63,
1100,
8,
1805,
14,
2068,
360,
600,
14,
1274,
14,
3083,
1333,
267,
876,
2068,
275,
1683,
14,
2068,
360,
600,
14,
1274,
297,
14018,
29,
600,
14,
1274,
12,
3158,
29,
600,
14,
1274,
9,
267,
291,
14,
1274,
1494,
275,
3464,
14,
4200,
63,
1100,
8,
657,
2068,
9,
267,
340,
984,
14,
476,
301,
13316,
6992,
365,
984,
855,
476,
301,
13316,
6992,
10651,
288,
291,
14,
1274,
1494,
14,
476,
301,
13316,
6992,
275,
291,
14,
1274,
1494,
855,
476,
301,
13316,
6992,
363,
339,
347,
511,
63,
1190,
17,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
21157,
360,
13430,
358,
267,
291,
14,
6614,
14,
25850,
342,
267,
291,
14,
629,
8,
277,
14,
1274,
1494,
14,
1190,
17,
12,
283,
6071,
5320,
339,
347,
511,
63,
1190,
18,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
21157,
360,
13430,
358,
267,
291,
14,
6614,
14,
25850,
342,
267,
291,
14,
629,
8,
277,
14,
1274,
1494,
14,
1190,
18,
12,
24352,
5320,
339,
347,
511,
63,
6614,
63,
3083,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
2097,
7,
4466,
79,
335,
4662,
4873,
21157,
360,
13430,
5440,
267,
291,
14,
6614,
14,
25850,
342,
267,
367,
1240,
315,
769,
8,
277,
14,
2703,
14,
765,
63,
5352,
304,
288,
340,
283,
4466,
79,
335,
7,
315,
6522,
904,
8,
1250,
59,
17,
4682,
355,
2059,
267,
587,
26,
288,
746,
9070,
480,
889,
8559,
3839,
531,
339,
347,
511,
63,
7093,
63,
705,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
2097,
10705,
401,
21157,
360,
13430,
5440,
267,
291,
14,
6614,
14,
25850,
342,
267,
367,
1240,
315,
291,
14,
3083,
14,
765,
63,
5352,
26,
288,
340,
283,
985,
547,
4881,
315,
6522,
904,
8,
1250,
59,
17,
4682,
355,
2059,
267,
587,
26,
288,
746,
9070,
480,
1944,
6302,
1125,
687,
8559,
531,
339,
347,
511,
63,
1786,
261,
10489,
13316,
6992,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
2097,
3730,
1722,
8355,
401,
2511,
21157,
360,
13430,
5440,
267,
5759,
275,
1683,
14,
3346,
342,
267,
291,
14,
1274,
1494,
14,
476,
301,
13316,
6992,
275,
5759,
267,
291,
14,
6614,
14,
25850,
342,
267,
291,
14,
1815,
8,
3664,
14,
3527,
9,
421,
199,
318,
511,
63,
973,
837,
272,
2291,
14,
1065,
63,
2796,
8,
774,
23879,
9270,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
774,
1010,
7502,
9270,
436,
1010,
7502,
2620,
26499,
687,
1233,
859,
2,
199,
646,
984,
199,
646,
2882,
199,
504,
15502,
492,
18704,
4851,
199,
504,
2882,
492,
1683,
199,
504,
511,
492,
2291,
199,
199,
600,
275,
2291,
14,
646,
63,
578,
360,
600,
358,
421,
199,
533,
1379,
23879,
9270,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
6614,
275,
1233,
14,
23879,
9270,
342,
267,
291,
14,
1805,
63,
1274,
342,
339,
347,
1683,
63,
1274,
8,
277,
304,
267,
298,
3346,
2656,
3734,
367,
1010,
7502,
9270,
2,
267,
327,
675,
4458,
3464,
370,
1336,
3371,
1067,
19680,
370,
1050,
7891,
267,
3464,
275,
18704,
4851,
342,
267,
291,
14,
12808,
8,
2340,
14,
1600,
9,
267,
291,
14,
262,
1532,
275,
3464,
14,
4200,
63,
1100,
8,
1805,
14,
2068,
360,
600,
14,
1210,
297,
5101,
1218,
29,
549,
430,
267,
291,
14,
2703,
275,
3464,
14,
4200,
63,
1100,
8,
1805,
14,
2068,
360,
600,
14,
1274,
14,
2703,
1333,
267,
291,
14,
3083,
275,
3464,
14,
4200,
63,
1100,
8,
1805,
14,
2068,
360,
600,
14,
1274,
14,
3083,
1333,
267,
876,
2068,
275,
1683,
14,
2068,
360,
600,
14,
1274,
297,
14018,
29,
600,
14,
1274,
12,
3158,
29,
600,
14,
1274,
9,
267,
291,
14,
1274,
1494,
275,
3464,
14,
4200,
63,
1100,
8,
657,
2068,
9,
267,
340,
984,
14,
476,
301,
13316,
6992,
365,
984,
855,
476,
301,
13316,
6992,
10651,
288,
291,
14,
1274,
1494,
14,
476,
301,
13316,
6992,
275,
291,
14,
1274,
1494,
855,
476,
301,
13316,
6992,
363,
339,
347,
511,
63,
1190,
17,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
21157,
360,
13430,
358,
267,
291,
14,
6614,
14,
25850,
342,
267,
291,
14,
629,
8,
277,
14,
1274,
1494,
14,
1190,
17,
12,
283,
6071,
5320,
339,
347,
511,
63,
1190,
18,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
21157,
360,
13430,
358,
267,
291,
14,
6614,
14,
25850,
342,
267,
291,
14,
629,
8,
277,
14,
1274,
1494,
14,
1190,
18,
12,
24352,
5320,
339,
347,
511,
63,
6614,
63,
3083,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
2097,
7,
4466,
79,
335,
4662,
4873,
21157,
360,
13430,
5440,
267,
291,
14,
6614,
14,
25850,
342,
267,
367,
1240,
315,
769,
8,
277,
14,
2703,
14,
765,
63,
5352,
304,
288,
340,
283,
4466,
79,
335,
7,
315,
6522,
904,
8,
1250,
59,
17,
4682,
355,
2059,
267,
587,
26,
288,
746,
9070,
480,
889,
8559,
3839,
531,
339,
347,
511,
63,
7093,
63,
705,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
2097,
10705,
401,
21157,
360,
13430,
5440,
267,
291,
14,
6614,
14,
25850,
342,
267,
367,
1240,
315,
291,
14,
3083,
14,
765,
63,
5352,
26,
288,
340,
283,
985,
547,
4881,
315,
6522,
904,
8,
1250,
59,
17,
4682,
355,
2059,
267,
587,
26,
288,
746,
9070,
480,
1944,
6302,
1125,
687,
8559,
531,
339,
347,
511,
63,
1786,
261,
10489,
13316,
6992,
8,
277,
304,
267,
291,
14,
262,
1532,
14,
2441,
63,
5881,
275,
2097,
3730,
1722,
8355,
401,
2511,
21157,
360,
13430,
5440,
267,
5759,
275,
1683,
14,
3346,
342,
267,
291,
14,
1274,
1494,
14,
476,
301,
13316,
6992,
275,
5759,
267,
291,
14,
6614,
14,
25850,
342,
267,
291,
14,
1815,
8,
3664,
14,
3527,
9,
421,
199,
318,
511,
63,
973,
837,
272,
2291,
14,
1065,
63,
2796,
8,
774,
23879,
9270,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
WPMedia/dd-agent
|
checks.d/directory.py
|
9
|
4748
|
# (C) Datadog, Inc. 2013-2016
# (C) Brett Langdon <brett@blangdon.com> 2013
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
# stdlib
from fnmatch import fnmatch
from os import stat
from os.path import abspath, exists, join
import time
# 3p
from scandir import walk
# project
from checks import AgentCheck
from config import _is_affirmative
class DirectoryCheck(AgentCheck):
"""This check is for monitoring and reporting metrics on the files for a provided directory
WARNING: the user/group that dd-agent runs as must have access to stat the files in the desired directory
Config options:
"directory" - string, the directory to gather stats for. required
"name" - string, the name to use when tagging the metrics. defaults to the "directory"
"dirtagname" - string, the name of the tag used for the directory. defaults to "name"
"filetagname" - string, the name of the tag used for each file. defaults to "filename"
"filegauges" - boolean, when true stats will be an individual gauge per file (max. 20 files!) and not a histogram of the whole directory. default False
"pattern" - string, the `fnmatch` pattern to use when reading the "directory"'s files. default "*"
"recursive" - boolean, when true the stats will recurse into directories. default False
"""
SOURCE_TYPE_NAME = 'system'
def check(self, instance):
if "directory" not in instance:
raise Exception('DirectoryCheck: missing "directory" in config')
directory = instance["directory"]
abs_directory = abspath(directory)
name = instance.get("name", directory)
pattern = instance.get("pattern", "*")
recursive = _is_affirmative(instance.get("recursive", False))
dirtagname = instance.get("dirtagname", "name")
filetagname = instance.get("filetagname", "filename")
filegauges = _is_affirmative(instance.get("filegauges", False))
countonly = _is_affirmative(instance.get("countonly", False))
if not exists(abs_directory):
raise Exception("DirectoryCheck: the directory (%s) does not exist" % abs_directory)
self._get_stats(abs_directory, name, dirtagname, filetagname, filegauges, pattern, recursive, countonly)
def _get_stats(self, directory, name, dirtagname, filetagname, filegauges, pattern, recursive, countonly):
dirtags = [dirtagname + ":%s" % name]
directory_bytes = 0
directory_files = 0
for root, dirs, files in walk(directory):
for filename in files:
filename = join(root, filename)
# check if it passes our filter
if not fnmatch(filename, pattern):
continue
directory_files += 1
# We're just looking to count the files, don't stat it as well
if countonly:
continue
try:
file_stat = stat(filename)
except OSError as ose:
self.warning("DirectoryCheck: could not stat file %s - %s" % (filename, ose))
else:
# file specific metrics
directory_bytes += file_stat.st_size
if filegauges and directory_files <= 20:
filetags = list(dirtags)
filetags.append(filetagname + ":%s" % filename)
self.gauge("system.disk.directory.file.bytes", file_stat.st_size, tags=filetags)
self.gauge("system.disk.directory.file.modified_sec_ago", time.time() - file_stat.st_mtime, tags=filetags)
self.gauge("system.disk.directory.file.created_sec_ago", time.time() - file_stat.st_ctime, tags=filetags)
elif not filegauges:
self.histogram("system.disk.directory.file.bytes", file_stat.st_size, tags=dirtags)
self.histogram("system.disk.directory.file.modified_sec_ago", time.time() - file_stat.st_mtime, tags=dirtags)
self.histogram("system.disk.directory.file.created_sec_ago", time.time() - file_stat.st_ctime, tags=dirtags)
# os.walk gives us all sub-directories and their files
# if we do not want to do this recursively and just want
# the top level directory we gave it, then break
if not recursive:
break
# number of files
self.gauge("system.disk.directory.files", directory_files, tags=dirtags)
# total file size
if not countonly:
self.gauge("system.disk.directory.bytes", directory_bytes, tags=dirtags)
|
bsd-3-clause
|
[
3,
334,
35,
9,
577,
292,
30821,
12,
3277,
14,
6171,
13,
9261,
199,
3,
334,
35,
9,
699,
3292,
84,
491,
621,
13196,
665,
66,
3292,
84,
32,
3345,
621,
13196,
14,
957,
30,
6171,
199,
3,
2900,
4481,
4644,
199,
3,
3909,
1334,
29094,
30200,
6289,
844,
334,
3239,
5113,
9,
421,
199,
3,
26678,
199,
504,
15951,
492,
15951,
199,
504,
747,
492,
5672,
199,
504,
747,
14,
515,
492,
19529,
12,
3495,
12,
4263,
199,
646,
900,
199,
199,
3,
650,
80,
199,
504,
8000,
694,
492,
12778,
199,
199,
3,
2199,
199,
504,
5920,
492,
19866,
1799,
199,
504,
1101,
492,
485,
374,
63,
2756,
1795,
391,
857,
421,
199,
533,
15191,
1799,
8,
7788,
1799,
304,
272,
408,
2765,
1104,
365,
367,
20391,
436,
17290,
7186,
641,
314,
1584,
367,
282,
2741,
2082,
339,
14750,
26,
314,
922,
15,
923,
626,
13972,
13,
4054,
7858,
465,
1471,
1172,
2879,
370,
5672,
314,
1584,
315,
314,
6387,
2082,
339,
4094,
1511,
26,
267,
298,
3619,
2,
446,
1059,
12,
314,
2082,
370,
13082,
5020,
367,
14,
1415,
267,
298,
354,
2,
446,
1059,
12,
314,
536,
370,
675,
1380,
1947,
1540,
314,
7186,
14,
4243,
370,
314,
298,
3619,
2,
267,
298,
694,
24173,
2,
446,
1059,
12,
314,
536,
402,
314,
1947,
1202,
367,
314,
2082,
14,
4243,
370,
298,
354,
2,
267,
298,
493,
24173,
2,
446,
1059,
12,
314,
536,
402,
314,
1947,
1202,
367,
1924,
570,
14,
4243,
370,
298,
1501,
2,
267,
298,
493,
16750,
3389,
2,
446,
5046,
12,
1380,
2549,
5020,
911,
506,
376,
8212,
486,
30949,
1126,
570,
334,
988,
14,
3388,
1584,
21866,
436,
440,
282,
15379,
402,
314,
8852,
2082,
14,
849,
756,
267,
298,
3401,
2,
446,
1059,
12,
314,
658,
15359,
64,
3851,
370,
675,
1380,
7664,
314,
298,
3619,
4507,
83,
1584,
14,
849,
22423,
267,
298,
9931,
2,
446,
5046,
12,
1380,
2549,
314,
5020,
911,
18011,
1901,
6602,
14,
849,
756,
272,
408,
339,
25470,
63,
2711,
63,
2339,
275,
283,
2253,
7,
339,
347,
1104,
8,
277,
12,
1256,
304,
267,
340,
298,
3619,
2,
440,
315,
1256,
26,
288,
746,
2186,
360,
6231,
1799,
26,
4124,
298,
3619,
2,
315,
1101,
358,
398,
2082,
275,
1256,
905,
3619,
937,
267,
2853,
63,
3619,
275,
19529,
8,
3619,
9,
267,
536,
275,
1256,
14,
362,
480,
354,
401,
2082,
9,
267,
3851,
275,
1256,
14,
362,
480,
3401,
401,
8969,
531,
267,
9133,
275,
485,
374,
63,
2756,
1795,
391,
857,
8,
842,
14,
362,
480,
9931,
401,
756,
430,
267,
2935,
24173,
275,
1256,
14,
362,
480,
694,
24173,
401,
298,
354,
531,
267,
570,
24173,
275,
1256,
14,
362,
480,
493,
24173,
401,
298,
1501,
531,
267,
570,
16750,
3389,
275,
485,
374,
63,
2756,
1795,
391,
857,
8,
842,
14,
362,
480,
493,
16750,
3389,
401,
756,
430,
267,
2338,
2118,
275,
485,
374,
63,
2756,
1795,
391,
857,
8,
842,
14,
362,
480,
835,
2118,
401,
756,
430,
398,
340,
440,
3495,
8,
2101,
63,
3619,
304,
288,
746,
2186,
480,
6231,
1799,
26,
314,
2082,
4366,
83,
9,
1630,
440,
2187,
2,
450,
2853,
63,
3619,
9,
398,
291,
423,
362,
63,
3200,
8,
2101,
63,
3619,
12,
536,
12,
2935,
24173,
12,
570,
24173,
12,
570,
16750,
3389,
12,
3851,
12,
9133,
12,
2338,
2118,
9,
339,
347,
485,
362,
63,
3200,
8,
277,
12,
2082,
12,
536,
12,
2935,
24173,
12,
570,
24173,
12,
570,
16750,
3389,
12,
3851,
12,
9133,
12,
2338,
2118,
304,
267,
2935,
2969,
275,
359,
694,
24173,
435,
298,
2689,
83,
2,
450,
536,
61,
267,
2082,
63,
2394,
275,
378,
267,
2082,
63,
1725,
275,
378,
267,
367,
1738,
12,
7606,
12,
1584,
315,
12778,
8,
3619,
304,
288,
367,
1788,
315,
1584,
26,
355,
1788,
275,
4263,
8,
1231,
12,
1788,
9,
355,
327,
1104,
340,
652,
14933,
4154,
2457,
355,
340,
440,
15951,
8,
1501,
12,
3851,
304,
490,
1980,
2234,
2082,
63,
1725,
847,
413,
2234,
327,
2136,
3984,
2951,
10023,
370,
2338,
314,
1584,
12,
2793,
1133,
5672,
652,
465,
5521,
355,
340,
2338,
2118,
26,
490,
1980,
2234,
862,
26,
490,
570,
63,
3736,
275,
5672,
8,
1501,
9,
2234,
871,
6440,
465,
312,
261,
26,
490,
291,
14,
3764,
480,
6231,
1799,
26,
4293,
440,
5672,
570,
450,
83,
446,
450,
83,
2,
450,
334,
1501,
12,
312,
261,
430,
355,
587,
26,
490,
327,
570,
2488,
7186,
490,
2082,
63,
2394,
847,
570,
63,
3736,
14,
270,
63,
890,
490,
340,
570,
16750,
3389,
436,
2082,
63,
1725,
2695,
3388,
26,
717,
570,
2969,
275,
769,
8,
694,
2969,
9,
717,
570,
2969,
14,
740,
8,
493,
24173,
435,
298,
2689,
83,
2,
450,
1788,
9,
717,
291,
14,
26775,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
2394,
401,
570,
63,
3736,
14,
270,
63,
890,
12,
3762,
29,
493,
2969,
9,
717,
291,
14,
26775,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
5540,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
8180,
12,
3762,
29,
493,
2969,
9,
717,
291,
14,
26775,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
3966,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
20691,
12,
3762,
29,
493,
2969,
9,
490,
916,
440,
570,
16750,
3389,
26,
717,
291,
14,
14805,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
2394,
401,
570,
63,
3736,
14,
270,
63,
890,
12,
3762,
29,
694,
2969,
9,
717,
291,
14,
14805,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
5540,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
8180,
12,
3762,
29,
694,
2969,
9,
717,
291,
14,
14805,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
3966,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
20691,
12,
3762,
29,
694,
2969,
9,
953,
327,
747,
14,
7757,
10557,
2739,
1006,
1007,
13,
12629,
436,
3932,
1584,
288,
327
] |
[
334,
35,
9,
577,
292,
30821,
12,
3277,
14,
6171,
13,
9261,
199,
3,
334,
35,
9,
699,
3292,
84,
491,
621,
13196,
665,
66,
3292,
84,
32,
3345,
621,
13196,
14,
957,
30,
6171,
199,
3,
2900,
4481,
4644,
199,
3,
3909,
1334,
29094,
30200,
6289,
844,
334,
3239,
5113,
9,
421,
199,
3,
26678,
199,
504,
15951,
492,
15951,
199,
504,
747,
492,
5672,
199,
504,
747,
14,
515,
492,
19529,
12,
3495,
12,
4263,
199,
646,
900,
199,
199,
3,
650,
80,
199,
504,
8000,
694,
492,
12778,
199,
199,
3,
2199,
199,
504,
5920,
492,
19866,
1799,
199,
504,
1101,
492,
485,
374,
63,
2756,
1795,
391,
857,
421,
199,
533,
15191,
1799,
8,
7788,
1799,
304,
272,
408,
2765,
1104,
365,
367,
20391,
436,
17290,
7186,
641,
314,
1584,
367,
282,
2741,
2082,
339,
14750,
26,
314,
922,
15,
923,
626,
13972,
13,
4054,
7858,
465,
1471,
1172,
2879,
370,
5672,
314,
1584,
315,
314,
6387,
2082,
339,
4094,
1511,
26,
267,
298,
3619,
2,
446,
1059,
12,
314,
2082,
370,
13082,
5020,
367,
14,
1415,
267,
298,
354,
2,
446,
1059,
12,
314,
536,
370,
675,
1380,
1947,
1540,
314,
7186,
14,
4243,
370,
314,
298,
3619,
2,
267,
298,
694,
24173,
2,
446,
1059,
12,
314,
536,
402,
314,
1947,
1202,
367,
314,
2082,
14,
4243,
370,
298,
354,
2,
267,
298,
493,
24173,
2,
446,
1059,
12,
314,
536,
402,
314,
1947,
1202,
367,
1924,
570,
14,
4243,
370,
298,
1501,
2,
267,
298,
493,
16750,
3389,
2,
446,
5046,
12,
1380,
2549,
5020,
911,
506,
376,
8212,
486,
30949,
1126,
570,
334,
988,
14,
3388,
1584,
21866,
436,
440,
282,
15379,
402,
314,
8852,
2082,
14,
849,
756,
267,
298,
3401,
2,
446,
1059,
12,
314,
658,
15359,
64,
3851,
370,
675,
1380,
7664,
314,
298,
3619,
4507,
83,
1584,
14,
849,
22423,
267,
298,
9931,
2,
446,
5046,
12,
1380,
2549,
314,
5020,
911,
18011,
1901,
6602,
14,
849,
756,
272,
408,
339,
25470,
63,
2711,
63,
2339,
275,
283,
2253,
7,
339,
347,
1104,
8,
277,
12,
1256,
304,
267,
340,
298,
3619,
2,
440,
315,
1256,
26,
288,
746,
2186,
360,
6231,
1799,
26,
4124,
298,
3619,
2,
315,
1101,
358,
398,
2082,
275,
1256,
905,
3619,
937,
267,
2853,
63,
3619,
275,
19529,
8,
3619,
9,
267,
536,
275,
1256,
14,
362,
480,
354,
401,
2082,
9,
267,
3851,
275,
1256,
14,
362,
480,
3401,
401,
8969,
531,
267,
9133,
275,
485,
374,
63,
2756,
1795,
391,
857,
8,
842,
14,
362,
480,
9931,
401,
756,
430,
267,
2935,
24173,
275,
1256,
14,
362,
480,
694,
24173,
401,
298,
354,
531,
267,
570,
24173,
275,
1256,
14,
362,
480,
493,
24173,
401,
298,
1501,
531,
267,
570,
16750,
3389,
275,
485,
374,
63,
2756,
1795,
391,
857,
8,
842,
14,
362,
480,
493,
16750,
3389,
401,
756,
430,
267,
2338,
2118,
275,
485,
374,
63,
2756,
1795,
391,
857,
8,
842,
14,
362,
480,
835,
2118,
401,
756,
430,
398,
340,
440,
3495,
8,
2101,
63,
3619,
304,
288,
746,
2186,
480,
6231,
1799,
26,
314,
2082,
4366,
83,
9,
1630,
440,
2187,
2,
450,
2853,
63,
3619,
9,
398,
291,
423,
362,
63,
3200,
8,
2101,
63,
3619,
12,
536,
12,
2935,
24173,
12,
570,
24173,
12,
570,
16750,
3389,
12,
3851,
12,
9133,
12,
2338,
2118,
9,
339,
347,
485,
362,
63,
3200,
8,
277,
12,
2082,
12,
536,
12,
2935,
24173,
12,
570,
24173,
12,
570,
16750,
3389,
12,
3851,
12,
9133,
12,
2338,
2118,
304,
267,
2935,
2969,
275,
359,
694,
24173,
435,
298,
2689,
83,
2,
450,
536,
61,
267,
2082,
63,
2394,
275,
378,
267,
2082,
63,
1725,
275,
378,
267,
367,
1738,
12,
7606,
12,
1584,
315,
12778,
8,
3619,
304,
288,
367,
1788,
315,
1584,
26,
355,
1788,
275,
4263,
8,
1231,
12,
1788,
9,
355,
327,
1104,
340,
652,
14933,
4154,
2457,
355,
340,
440,
15951,
8,
1501,
12,
3851,
304,
490,
1980,
2234,
2082,
63,
1725,
847,
413,
2234,
327,
2136,
3984,
2951,
10023,
370,
2338,
314,
1584,
12,
2793,
1133,
5672,
652,
465,
5521,
355,
340,
2338,
2118,
26,
490,
1980,
2234,
862,
26,
490,
570,
63,
3736,
275,
5672,
8,
1501,
9,
2234,
871,
6440,
465,
312,
261,
26,
490,
291,
14,
3764,
480,
6231,
1799,
26,
4293,
440,
5672,
570,
450,
83,
446,
450,
83,
2,
450,
334,
1501,
12,
312,
261,
430,
355,
587,
26,
490,
327,
570,
2488,
7186,
490,
2082,
63,
2394,
847,
570,
63,
3736,
14,
270,
63,
890,
490,
340,
570,
16750,
3389,
436,
2082,
63,
1725,
2695,
3388,
26,
717,
570,
2969,
275,
769,
8,
694,
2969,
9,
717,
570,
2969,
14,
740,
8,
493,
24173,
435,
298,
2689,
83,
2,
450,
1788,
9,
717,
291,
14,
26775,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
2394,
401,
570,
63,
3736,
14,
270,
63,
890,
12,
3762,
29,
493,
2969,
9,
717,
291,
14,
26775,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
5540,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
8180,
12,
3762,
29,
493,
2969,
9,
717,
291,
14,
26775,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
3966,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
20691,
12,
3762,
29,
493,
2969,
9,
490,
916,
440,
570,
16750,
3389,
26,
717,
291,
14,
14805,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
2394,
401,
570,
63,
3736,
14,
270,
63,
890,
12,
3762,
29,
694,
2969,
9,
717,
291,
14,
14805,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
5540,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
8180,
12,
3762,
29,
694,
2969,
9,
717,
291,
14,
14805,
480,
2253,
14,
4032,
14,
3619,
14,
493,
14,
3966,
63,
3321,
63,
14315,
401,
900,
14,
521,
342,
446,
570,
63,
3736,
14,
270,
63,
20691,
12,
3762,
29,
694,
2969,
9,
953,
327,
747,
14,
7757,
10557,
2739,
1006,
1007,
13,
12629,
436,
3932,
1584,
288,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sadimusi/mc4p
|
mc4p/encryption.py
|
2
|
4012
|
# -*- coding: utf-8 -*-
# This source file is part of mc4p,
# the Minecraft Portable Protocol-Parsing Proxy.
#
# Copyright (C) 2011 Matthew J. McGill, Simon Marti
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details
from Crypto.PublicKey import RSA
from Crypto import Random
from Crypto.Cipher import AES, DES
from hashlib import md5
from struct import unpack
def decode_public_key(bytes):
"""Decodes a public RSA key in ASN.1 format as defined by x.509"""
return RSA.importKey(bytes)
def encode_public_key(key):
"""Encodes a public RSA key in ASN.1 format as defined by x.509"""
return key.publickey().exportKey(format="DER")
def generate_key_pair():
"""Generates a 1024 bit RSA key pair"""
return RSA.generate(1024)
def generate_random_bytes(length):
return Random.get_random_bytes(length)
def generate_server_id():
"""Generates 20 random hex characters"""
return "".join("%02x" % ord(c) for c in generate_random_bytes(10))
def generate_challenge_token():
"""Generates 4 random bytes"""
return generate_random_bytes(4)
def generate_shared_secret():
"""Generates a 128 bit secret key to be used in symmetric encryption"""
return generate_random_bytes(16)
def encrypt_shared_secret(shared_secret, public_key):
"""Encrypts the PKCS#1 padded shared secret using the public RSA key"""
return public_key.encrypt(_pkcs1_pad(shared_secret), 0)[0]
def decrypt_shared_secret(encrypted_key, private_key):
"""Decrypts the PKCS#1 padded shared secret using the private RSA key"""
return _pkcs1_unpad(private_key.decrypt(encrypted_key))
def encryption_for_version(version):
if version <= 32:
return RC4
else:
return AES128CFB8
class RC4(object):
def __init__(self, key):
self.key = key
x = 0
self.box = box = range(256)
for i in range(256):
x = (x + box[i] + ord(key[i % len(key)])) % 256
box[i], box[x] = box[x], box[i]
self.x = self.y = 0
def crypt(self, data):
out = ""
box = self.box
for char in data:
self.x = x = (self.x + 1) % 256
self.y = y = (self.y + box[self.x]) % 256
box[x], box[y] = box[y], box[x]
out += chr(ord(char) ^ box[(box[x] + box[y]) % 256])
return out
decrypt = encrypt = crypt
def AES128CFB8(shared_secret):
"""Creates a AES128 stream cipher using cfb8 mode"""
return AES.new(shared_secret, AES.MODE_CFB, shared_secret)
def _pkcs1_unpad(bytes):
pos = bytes.find('\x00')
if pos > 0:
return bytes[pos+1:]
def _pkcs1_pad(bytes):
assert len(bytes) < 117
padding = ""
while len(padding) < 125-len(bytes):
byte = Random.get_random_bytes(1)
if byte != '\x00':
padding += byte
return '\x00\x02%s\x00%s' % (padding, bytes)
class PBEWithMD5AndDES(object):
"""PBES1 implementation according to RFC 2898 section 6.1"""
SALT = '\x0c\x9d\x4a\xe4\x1e\x83\x15\xfc'
COUNT = 5
def __init__(self, key):
key = self._generate_key(key, self.SALT, self.COUNT, 16)
self.key = key[:8]
self.iv = key[8:16]
def encrypt(self, plaintext):
padding = 8 - len(plaintext) % 8
plaintext += chr(padding)*padding
return self._cipher().encrypt(plaintext)
def decrypt(self, ciphertext):
plaintext = self._cipher().decrypt(ciphertext)
return plaintext[:-ord(plaintext[-1])]
def _cipher(self):
return DES.new(self.key, DES.MODE_CBC, self.iv)
def _generate_key(self, key, salt, count, length):
key = key + salt
for i in range(count):
key = md5(key).digest()
return key[:length]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
1350,
570,
365,
1777,
402,
16377,
20,
80,
12,
199,
3,
314,
10195,
825,
4800,
10977,
461,
11557,
13,
17412,
12373,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
18619,
29640,
1603,
14,
22895,
39,
778,
12,
10751,
265,
16794,
280,
199,
199,
3,
961,
2240,
365,
2867,
2032,
14,
2779,
12477,
1928,
1263,
3750,
12,
370,
199,
3,
314,
13675,
8211,
701,
3964,
4179,
14,
2047,
883,
3604,
652,
199,
3,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
4226,
14791,
710,
481,
10112,
2047,
644,
867,
199,
3,
4005,
1684,
844,
12,
3394,
499,
12,
465,
3267,
701,
428,
455,
28673,
301,
1391,
14,
1666,
199,
3,
1455,
921,
21660,
14,
18070,
89,
14,
1308,
15,
87,
3249,
1168,
15,
16188,
1206,
367,
1655,
2436,
199,
199,
504,
18855,
14,
26238,
492,
18471,
199,
504,
18855,
492,
9571,
199,
504,
18855,
14,
21967,
492,
19093,
12,
11758,
199,
504,
8337,
492,
6128,
21,
199,
504,
2702,
492,
7787,
421,
199,
318,
4849,
63,
3455,
63,
498,
8,
2394,
304,
272,
408,
872,
6021,
282,
4575,
18471,
790,
315,
31139,
14,
17,
1475,
465,
3247,
701,
671,
14,
6576,
624,
272,
372,
18471,
14,
646,
1197,
8,
2394,
9,
421,
199,
318,
3752,
63,
3455,
63,
498,
8,
498,
304,
272,
408,
1327,
6021,
282,
4575,
18471,
790,
315,
31139,
14,
17,
1475,
465,
3247,
701,
671,
14,
6576,
624,
272,
372,
790,
14,
5645,
8442,
14655,
1252,
3790,
1197,
8,
908,
628,
11733,
531,
421,
199,
318,
3550,
63,
498,
63,
3852,
837,
272,
408,
20551,
282,
6619,
4546,
18471,
790,
4092,
624,
272,
372,
18471,
14,
4208,
8,
7727,
9,
421,
199,
318,
3550,
63,
2355,
63,
2394,
8,
1267,
304,
272,
372,
9571,
14,
362,
63,
2355,
63,
2394,
8,
1267,
9,
421,
199,
318,
3550,
63,
1000,
63,
344,
837,
272,
408,
20551,
3388,
2196,
6318,
4110,
624,
272,
372,
10587,
904,
3647,
996,
88,
2,
450,
6206,
8,
67,
9,
367,
286,
315,
3550,
63,
2355,
63,
2394,
8,
709,
430,
421,
199,
318,
3550,
63,
13911,
63,
1418,
837,
272,
408,
20551,
841,
2196,
2783,
624,
272,
372,
3550,
63,
2355,
63,
2394,
8,
20,
9,
421,
199,
318,
3550,
63,
5555,
63,
4731,
837,
272,
408,
20551,
282,
7960,
4546,
7565,
790,
370,
506,
1202,
315,
16371,
14396,
624,
272,
372,
3550,
63,
2355,
63,
2394,
8,
975,
9,
421,
199,
318,
14645,
63,
5555,
63,
4731,
8,
5555,
63,
4731,
12,
4575,
63,
498,
304,
272,
408,
1327,
4997,
83,
314,
32040,
3,
17,
21824,
5709,
7565,
1808,
314,
4575,
18471,
790,
624,
272,
372,
4575,
63,
498,
14,
11929,
1547,
27100,
17,
63,
6226,
8,
5555,
63,
4731,
395,
378,
2788,
16,
61,
421,
199,
318,
20090,
63,
5555,
63,
4731,
8,
15078,
63,
498,
12,
5726,
63,
498,
304,
272,
408,
8584,
651,
8382,
314,
32040,
3,
17,
21824,
5709,
7565,
1808,
314,
5726,
18471,
790,
624,
272,
372,
485,
27100,
17,
63,
324,
6226,
8,
4239,
63,
498,
14,
15682,
8,
15078,
63,
498,
430,
421,
199,
318,
14396,
63,
509,
63,
1023,
8,
1023,
304,
272,
340,
1015,
2695,
4337,
26,
267,
372,
29256,
20,
272,
587,
26,
267,
372,
19093,
3933,
5487,
34,
24,
421,
199,
533,
29256,
20,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
267,
671,
275,
378,
267,
291,
14,
1977,
275,
5689,
275,
1425,
8,
3912,
9,
267,
367,
284,
315,
1425,
8,
3912,
304,
288,
671,
275,
334,
88,
435,
5689,
59,
73,
61,
435,
6206,
8,
498,
59,
73,
450,
822,
8,
498,
19563,
450,
7633,
288,
5689,
59,
73,
467,
5689,
59,
88,
61,
275,
5689,
59,
88,
467,
5689,
59,
73,
61,
267,
291,
14,
88,
275,
291,
14,
89,
275,
378,
339,
347,
21570,
8,
277,
12,
666,
304,
267,
734,
275,
3087,
267,
5689,
275,
291,
14,
1977,
267,
367,
1495,
315,
666,
26,
288,
291,
14,
88,
275,
671,
275,
334,
277,
14,
88,
435,
413,
9,
450,
7633,
288,
291,
14,
89,
275,
612,
275,
334,
277,
14,
89,
435,
5689,
59,
277,
14,
88,
566,
450,
7633,
288,
5689,
59,
88,
467,
5689,
59,
89,
61,
275,
5689,
59,
89,
467,
5689,
59,
88,
61,
288,
734,
847,
8678,
8,
2181,
8,
1560,
9,
7167,
5689,
7528,
1977,
59,
88,
61,
435,
5689,
59,
89,
566,
450,
7633,
566,
267,
372,
734,
339,
20090,
275,
14645,
275,
21570,
421,
199,
318,
19093,
3933,
5487,
34,
24,
8,
5555,
63,
4731,
304,
272,
408,
10607,
282,
19093,
3933,
2547,
10830,
1808,
3980,
66,
24,
818,
624,
272,
372,
19093,
14,
1222,
8,
5555,
63,
4731,
12,
19093,
14,
6963,
63,
5487,
34,
12,
5709,
63,
4731,
9,
421,
199,
318,
485,
27100,
17,
63,
324,
6226,
8,
2394,
304,
272,
2086,
275,
2783,
14,
1623,
2258,
88,
383,
358,
272,
340,
2086,
690,
378,
26,
267,
372,
2783,
59,
1712,
11,
17,
2938,
421,
199,
318,
485,
27100,
17,
63,
6226,
8,
2394,
304,
272,
702,
822,
8,
2394,
9,
665,
26189,
272,
6273,
275,
3087,
272,
1830,
822,
8,
8358,
9,
665,
19163,
13,
552,
8,
2394,
304,
267,
3696,
275,
9571,
14,
362,
63,
2355,
63,
2394,
8,
17,
9,
267,
340,
3696,
1137,
1557,
88,
383,
356,
288,
6273,
847,
3696,
272,
372,
1557,
88,
383,
60,
88,
996,
5,
83,
60,
88,
383,
5,
83,
7,
450,
334,
8358,
12,
2783,
9,
421,
199,
533,
510,
6773,
3007,
5127,
21,
3325,
4448,
8,
785,
304,
272,
408,
13167,
654,
17,
4514,
7182,
370,
7329,
499,
13176,
3420,
1227,
14,
17,
624,
272,
428,
19600,
275,
1557,
88,
16,
67,
60,
88,
25,
68,
60,
88,
20,
65,
60,
1845,
20,
60,
88,
17,
69,
60,
88,
2658,
60,
88,
1046,
60,
10347,
7,
272,
24903,
275,
959,
339,
347,
636,
826,
721,
277,
12,
790,
304,
267,
790,
275,
291,
423,
4208,
63,
498,
8,
498,
12,
291,
14,
51,
19600,
12,
291,
14,
8760,
12,
3193
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
961,
1350,
570,
365,
1777,
402,
16377,
20,
80,
12,
199,
3,
314,
10195,
825,
4800,
10977,
461,
11557,
13,
17412,
12373,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
18619,
29640,
1603,
14,
22895,
39,
778,
12,
10751,
265,
16794,
280,
199,
199,
3,
961,
2240,
365,
2867,
2032,
14,
2779,
12477,
1928,
1263,
3750,
12,
370,
199,
3,
314,
13675,
8211,
701,
3964,
4179,
14,
2047,
883,
3604,
652,
199,
3,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
4226,
14791,
710,
481,
10112,
2047,
644,
867,
199,
3,
4005,
1684,
844,
12,
3394,
499,
12,
465,
3267,
701,
428,
455,
28673,
301,
1391,
14,
1666,
199,
3,
1455,
921,
21660,
14,
18070,
89,
14,
1308,
15,
87,
3249,
1168,
15,
16188,
1206,
367,
1655,
2436,
199,
199,
504,
18855,
14,
26238,
492,
18471,
199,
504,
18855,
492,
9571,
199,
504,
18855,
14,
21967,
492,
19093,
12,
11758,
199,
504,
8337,
492,
6128,
21,
199,
504,
2702,
492,
7787,
421,
199,
318,
4849,
63,
3455,
63,
498,
8,
2394,
304,
272,
408,
872,
6021,
282,
4575,
18471,
790,
315,
31139,
14,
17,
1475,
465,
3247,
701,
671,
14,
6576,
624,
272,
372,
18471,
14,
646,
1197,
8,
2394,
9,
421,
199,
318,
3752,
63,
3455,
63,
498,
8,
498,
304,
272,
408,
1327,
6021,
282,
4575,
18471,
790,
315,
31139,
14,
17,
1475,
465,
3247,
701,
671,
14,
6576,
624,
272,
372,
790,
14,
5645,
8442,
14655,
1252,
3790,
1197,
8,
908,
628,
11733,
531,
421,
199,
318,
3550,
63,
498,
63,
3852,
837,
272,
408,
20551,
282,
6619,
4546,
18471,
790,
4092,
624,
272,
372,
18471,
14,
4208,
8,
7727,
9,
421,
199,
318,
3550,
63,
2355,
63,
2394,
8,
1267,
304,
272,
372,
9571,
14,
362,
63,
2355,
63,
2394,
8,
1267,
9,
421,
199,
318,
3550,
63,
1000,
63,
344,
837,
272,
408,
20551,
3388,
2196,
6318,
4110,
624,
272,
372,
10587,
904,
3647,
996,
88,
2,
450,
6206,
8,
67,
9,
367,
286,
315,
3550,
63,
2355,
63,
2394,
8,
709,
430,
421,
199,
318,
3550,
63,
13911,
63,
1418,
837,
272,
408,
20551,
841,
2196,
2783,
624,
272,
372,
3550,
63,
2355,
63,
2394,
8,
20,
9,
421,
199,
318,
3550,
63,
5555,
63,
4731,
837,
272,
408,
20551,
282,
7960,
4546,
7565,
790,
370,
506,
1202,
315,
16371,
14396,
624,
272,
372,
3550,
63,
2355,
63,
2394,
8,
975,
9,
421,
199,
318,
14645,
63,
5555,
63,
4731,
8,
5555,
63,
4731,
12,
4575,
63,
498,
304,
272,
408,
1327,
4997,
83,
314,
32040,
3,
17,
21824,
5709,
7565,
1808,
314,
4575,
18471,
790,
624,
272,
372,
4575,
63,
498,
14,
11929,
1547,
27100,
17,
63,
6226,
8,
5555,
63,
4731,
395,
378,
2788,
16,
61,
421,
199,
318,
20090,
63,
5555,
63,
4731,
8,
15078,
63,
498,
12,
5726,
63,
498,
304,
272,
408,
8584,
651,
8382,
314,
32040,
3,
17,
21824,
5709,
7565,
1808,
314,
5726,
18471,
790,
624,
272,
372,
485,
27100,
17,
63,
324,
6226,
8,
4239,
63,
498,
14,
15682,
8,
15078,
63,
498,
430,
421,
199,
318,
14396,
63,
509,
63,
1023,
8,
1023,
304,
272,
340,
1015,
2695,
4337,
26,
267,
372,
29256,
20,
272,
587,
26,
267,
372,
19093,
3933,
5487,
34,
24,
421,
199,
533,
29256,
20,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
267,
671,
275,
378,
267,
291,
14,
1977,
275,
5689,
275,
1425,
8,
3912,
9,
267,
367,
284,
315,
1425,
8,
3912,
304,
288,
671,
275,
334,
88,
435,
5689,
59,
73,
61,
435,
6206,
8,
498,
59,
73,
450,
822,
8,
498,
19563,
450,
7633,
288,
5689,
59,
73,
467,
5689,
59,
88,
61,
275,
5689,
59,
88,
467,
5689,
59,
73,
61,
267,
291,
14,
88,
275,
291,
14,
89,
275,
378,
339,
347,
21570,
8,
277,
12,
666,
304,
267,
734,
275,
3087,
267,
5689,
275,
291,
14,
1977,
267,
367,
1495,
315,
666,
26,
288,
291,
14,
88,
275,
671,
275,
334,
277,
14,
88,
435,
413,
9,
450,
7633,
288,
291,
14,
89,
275,
612,
275,
334,
277,
14,
89,
435,
5689,
59,
277,
14,
88,
566,
450,
7633,
288,
5689,
59,
88,
467,
5689,
59,
89,
61,
275,
5689,
59,
89,
467,
5689,
59,
88,
61,
288,
734,
847,
8678,
8,
2181,
8,
1560,
9,
7167,
5689,
7528,
1977,
59,
88,
61,
435,
5689,
59,
89,
566,
450,
7633,
566,
267,
372,
734,
339,
20090,
275,
14645,
275,
21570,
421,
199,
318,
19093,
3933,
5487,
34,
24,
8,
5555,
63,
4731,
304,
272,
408,
10607,
282,
19093,
3933,
2547,
10830,
1808,
3980,
66,
24,
818,
624,
272,
372,
19093,
14,
1222,
8,
5555,
63,
4731,
12,
19093,
14,
6963,
63,
5487,
34,
12,
5709,
63,
4731,
9,
421,
199,
318,
485,
27100,
17,
63,
324,
6226,
8,
2394,
304,
272,
2086,
275,
2783,
14,
1623,
2258,
88,
383,
358,
272,
340,
2086,
690,
378,
26,
267,
372,
2783,
59,
1712,
11,
17,
2938,
421,
199,
318,
485,
27100,
17,
63,
6226,
8,
2394,
304,
272,
702,
822,
8,
2394,
9,
665,
26189,
272,
6273,
275,
3087,
272,
1830,
822,
8,
8358,
9,
665,
19163,
13,
552,
8,
2394,
304,
267,
3696,
275,
9571,
14,
362,
63,
2355,
63,
2394,
8,
17,
9,
267,
340,
3696,
1137,
1557,
88,
383,
356,
288,
6273,
847,
3696,
272,
372,
1557,
88,
383,
60,
88,
996,
5,
83,
60,
88,
383,
5,
83,
7,
450,
334,
8358,
12,
2783,
9,
421,
199,
533,
510,
6773,
3007,
5127,
21,
3325,
4448,
8,
785,
304,
272,
408,
13167,
654,
17,
4514,
7182,
370,
7329,
499,
13176,
3420,
1227,
14,
17,
624,
272,
428,
19600,
275,
1557,
88,
16,
67,
60,
88,
25,
68,
60,
88,
20,
65,
60,
1845,
20,
60,
88,
17,
69,
60,
88,
2658,
60,
88,
1046,
60,
10347,
7,
272,
24903,
275,
959,
339,
347,
636,
826,
721,
277,
12,
790,
304,
267,
790,
275,
291,
423,
4208,
63,
498,
8,
498,
12,
291,
14,
51,
19600,
12,
291,
14,
8760,
12,
3193,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Aravinthu/odoo
|
addons/mrp_repair/models/mrp_repair.py
|
4
|
32545
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from odoo import api, fields, models, _
from odoo.addons import decimal_precision as dp
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_compare
class StockMove(models.Model):
_inherit = 'stock.move'
repair_id = fields.Many2one('mrp.repair')
class Repair(models.Model):
_name = 'mrp.repair'
_description = 'Repair Order'
_inherit = ['mail.thread', 'mail.activity.mixin']
_order = 'create_date desc'
@api.model
def _default_stock_location(self):
warehouse = self.env['stock.warehouse'].search([], limit=1)
if warehouse:
return warehouse.lot_stock_id.id
return False
name = fields.Char(
'Repair Reference',
default=lambda self: self.env['ir.sequence'].next_by_code('mrp.repair'),
copy=False, required=True,
states={'confirmed': [('readonly', True)]})
product_id = fields.Many2one(
'product.product', string='Product to Repair',
readonly=True, required=True, states={'draft': [('readonly', False)]})
product_qty = fields.Float(
'Product Quantity',
default=1.0, digits=dp.get_precision('Product Unit of Measure'),
readonly=True, required=True, states={'draft': [('readonly', False)]})
product_uom = fields.Many2one(
'product.uom', 'Product Unit of Measure',
readonly=True, required=True, states={'draft': [('readonly', False)]})
partner_id = fields.Many2one(
'res.partner', 'Customer',
index=True, states={'confirmed': [('readonly', True)]},
help='Choose partner for whom the order will be invoiced and delivered.')
address_id = fields.Many2one(
'res.partner', 'Delivery Address',
domain="[('parent_id','=',partner_id)]",
states={'confirmed': [('readonly', True)]})
default_address_id = fields.Many2one('res.partner', compute='_compute_default_address_id')
state = fields.Selection([
('draft', 'Quotation'),
('cancel', 'Cancelled'),
('confirmed', 'Confirmed'),
('under_repair', 'Under Repair'),
('ready', 'Ready to Repair'),
('2binvoiced', 'To be Invoiced'),
('invoice_except', 'Invoice Exception'),
('done', 'Repaired')], string='Status',
copy=False, default='draft', readonly=True, track_visibility='onchange',
help="* The \'Draft\' status is used when a user is encoding a new and unconfirmed repair order.\n"
"* The \'Confirmed\' status is used when a user confirms the repair order.\n"
"* The \'Ready to Repair\' status is used to start to repairing, user can start repairing only after repair order is confirmed.\n"
"* The \'To be Invoiced\' status is used to generate the invoice before or after repairing done.\n"
"* The \'Done\' status is set when repairing is completed.\n"
"* The \'Cancelled\' status is used when user cancel repair order.")
location_id = fields.Many2one(
'stock.location', 'Current Location',
default=_default_stock_location,
index=True, readonly=True, required=True,
states={'draft': [('readonly', False)], 'confirmed': [('readonly', True)]})
location_dest_id = fields.Many2one(
'stock.location', 'Delivery Location',
readonly=True, required=True,
states={'draft': [('readonly', False)], 'confirmed': [('readonly', True)]})
lot_id = fields.Many2one(
'stock.production.lot', 'Lot/Serial',
domain="[('product_id','=', product_id)]",
help="Products repaired are all belonging to this lot", oldname="prodlot_id")
guarantee_limit = fields.Date('Warranty Expiration', states={'confirmed': [('readonly', True)]})
operations = fields.One2many(
'mrp.repair.line', 'repair_id', 'Parts',
copy=True, readonly=True, states={'draft': [('readonly', False)]})
pricelist_id = fields.Many2one(
'product.pricelist', 'Pricelist',
default=lambda self: self.env['product.pricelist'].search([], limit=1).id,
help='Pricelist of the selected partner.')
partner_invoice_id = fields.Many2one('res.partner', 'Invoicing Address')
invoice_method = fields.Selection([
("none", "No Invoice"),
("b4repair", "Before Repair"),
("after_repair", "After Repair")], string="Invoice Method",
default='none', index=True, readonly=True, required=True,
states={'draft': [('readonly', False)]},
help='Selecting \'Before Repair\' or \'After Repair\' will allow you to generate invoice before or after the repair is done respectively. \'No invoice\' means you don\'t want to generate invoice for this repair order.')
invoice_id = fields.Many2one(
'account.invoice', 'Invoice',
copy=False, readonly=True, track_visibility="onchange")
move_id = fields.Many2one(
'stock.move', 'Move',
copy=False, readonly=True, track_visibility="onchange",
help="Move created by the repair order")
fees_lines = fields.One2many(
'mrp.repair.fee', 'repair_id', 'Operations',
copy=True, readonly=True, states={'draft': [('readonly', False)]})
internal_notes = fields.Text('Internal Notes')
quotation_notes = fields.Text('Quotation Notes')
company_id = fields.Many2one(
'res.company', 'Company',
default=lambda self: self.env['res.company']._company_default_get('mrp.repair'))
invoiced = fields.Boolean('Invoiced', copy=False, readonly=True)
repaired = fields.Boolean('Repaired', copy=False, readonly=True)
amount_untaxed = fields.Float('Untaxed Amount', compute='_amount_untaxed', store=True)
amount_tax = fields.Float('Taxes', compute='_amount_tax', store=True)
amount_total = fields.Float('Total', compute='_amount_total', store=True)
tracking = fields.Selection('Product Tracking', related="product_id.tracking")
@api.one
@api.depends('partner_id')
def _compute_default_address_id(self):
if self.partner_id:
self.default_address_id = self.partner_id.address_get(['contact'])['contact']
@api.one
@api.depends('operations.price_subtotal', 'invoice_method', 'fees_lines.price_subtotal', 'pricelist_id.currency_id')
def _amount_untaxed(self):
total = sum(operation.price_subtotal for operation in self.operations)
total += sum(fee.price_subtotal for fee in self.fees_lines)
self.amount_untaxed = self.pricelist_id.currency_id.round(total)
@api.one
@api.depends('operations.price_unit', 'operations.product_uom_qty', 'operations.product_id',
'fees_lines.price_unit', 'fees_lines.product_uom_qty', 'fees_lines.product_id',
'pricelist_id.currency_id', 'partner_id')
def _amount_tax(self):
val = 0.0
for operation in self.operations:
if operation.tax_id:
tax_calculate = operation.tax_id.compute_all(operation.price_unit, self.pricelist_id.currency_id, operation.product_uom_qty, operation.product_id, self.partner_id)
for c in tax_calculate['taxes']:
val += c['amount']
for fee in self.fees_lines:
if fee.tax_id:
tax_calculate = fee.tax_id.compute_all(fee.price_unit, self.pricelist_id.currency_id, fee.product_uom_qty, fee.product_id, self.partner_id)
for c in tax_calculate['taxes']:
val += c['amount']
self.amount_tax = val
@api.one
@api.depends('amount_untaxed', 'amount_tax')
def _amount_total(self):
self.amount_total = self.pricelist_id.currency_id.round(self.amount_untaxed + self.amount_tax)
_sql_constraints = [
('name', 'unique (name)', 'The name of the Repair Order must be unique!'),
]
@api.onchange('product_id')
def onchange_product_id(self):
self.guarantee_limit = False
self.lot_id = False
if self.product_id:
self.product_uom = self.product_id.uom_id.id
@api.onchange('product_uom')
def onchange_product_uom(self):
res = {}
if not self.product_id or not self.product_uom:
return res
if self.product_uom.category_id != self.product_id.uom_id.category_id:
res['warning'] = {'title': _('Warning'), 'message': _('The Product Unit of Measure you chose has a different category than in the product form.')}
self.product_uom = self.product_id.uom_id.id
return res
@api.onchange('location_id')
def onchange_location_id(self):
self.location_dest_id = self.location_id.id
@api.onchange('partner_id')
def onchange_partner_id(self):
if not self.partner_id:
self.address_id = False
self.partner_invoice_id = False
self.pricelist_id = self.env['product.pricelist'].search([], limit=1).id
else:
addresses = self.partner_id.address_get(['delivery', 'invoice', 'contact'])
self.address_id = addresses['delivery'] or addresses['contact']
self.partner_invoice_id = addresses['invoice']
self.pricelist_id = self.partner_id.property_product_pricelist.id
@api.multi
def button_dummy(self):
# TDE FIXME: this button is very interesting
return True
@api.multi
def action_repair_cancel_draft(self):
if self.filtered(lambda repair: repair.state != 'cancel'):
raise UserError(_("Repair must be canceled in order to reset it to draft."))
self.mapped('operations').write({'state': 'draft'})
return self.write({'state': 'draft'})
def action_validate(self):
self.ensure_one()
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
available_qty = self.env['stock.quant']._get_available_quantity(self.product_id, self.location_id, self.lot_id, strict=True)
if float_compare(available_qty, self.product_qty, precision_digits=precision) >= 0:
return self.action_repair_confirm()
else:
return {
'name': _('Insufficient Quantity'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'stock.warn.insufficient.qty.repair',
'view_id': self.env.ref('mrp_repair.stock_warn_insufficient_qty_repair_form_view').id,
'type': 'ir.actions.act_window',
'context': {
'default_product_id': self.product_id.id,
'default_location_id': self.location_id.id,
'default_repair_id': self.id
},
'target': 'new'
}
@api.multi
def action_repair_confirm(self):
""" Repair order state is set to 'To be invoiced' when invoice method
is 'Before repair' else state becomes 'Confirmed'.
@param *arg: Arguments
@return: True
"""
if self.filtered(lambda repair: repair.state != 'draft'):
raise UserError(_("Can only confirm draft repairs."))
before_repair = self.filtered(lambda repair: repair.invoice_method == 'b4repair')
before_repair.write({'state': '2binvoiced'})
to_confirm = self - before_repair
to_confirm_operations = to_confirm.mapped('operations')
to_confirm_operations.write({'state': 'confirmed'})
to_confirm.write({'state': 'confirmed'})
return True
@api.multi
def action_repair_cancel(self):
if self.filtered(lambda repair: repair.state == 'done'):
raise UserError(_("Cannot cancel completed repairs."))
if any(repair.invoiced for repair in self):
raise UserError(_('Repair order is already invoiced.'))
self.mapped('operations').write({'state': 'cancel'})
return self.write({'state': 'cancel'})
@api.multi
def action_send_mail(self):
self.ensure_one()
template_id = self.env.ref('mrp_repair.mail_template_mrp_repair_quotation').id
ctx = {
'default_model': 'mrp.repair',
'default_res_id': self.id,
'default_use_template': bool(template_id),
'default_template_id': template_id,
'default_composition_mode': 'comment'
}
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'target': 'new',
'context': ctx,
}
@api.multi
def print_repair_order(self):
return self.env.ref('mrp_repair.action_report_mrp_repair_order').report_action(self)
def action_repair_invoice_create(self):
for repair in self:
repair.action_invoice_create()
if repair.invoice_method == 'b4repair':
repair.action_repair_ready()
elif repair.invoice_method == 'after_repair':
repair.write({'state': 'done'})
return True
@api.multi
def action_invoice_create(self, group=False):
""" Creates invoice(s) for repair order.
@param group: It is set to true when group invoice is to be generated.
@return: Invoice Ids.
"""
res = dict.fromkeys(self.ids, False)
invoices_group = {}
InvoiceLine = self.env['account.invoice.line']
Invoice = self.env['account.invoice']
for repair in self.filtered(lambda repair: repair.state not in ('draft', 'cancel') and not repair.invoice_id):
if not repair.partner_id.id and not repair.partner_invoice_id.id:
raise UserError(_('You have to select a Partner Invoice Address in the repair form!'))
comment = repair.quotation_notes
if repair.invoice_method != 'none':
if group and repair.partner_invoice_id.id in invoices_group:
invoice = invoices_group[repair.partner_invoice_id.id]
invoice.write({
'name': invoice.name + ', ' + repair.name,
'origin': invoice.origin + ', ' + repair.name,
'comment': (comment and (invoice.comment and invoice.comment + "\n" + comment or comment)) or (invoice.comment and invoice.comment or ''),
})
else:
if not repair.partner_id.property_account_receivable_id:
raise UserError(_('No account defined for partner "%s".') % repair.partner_id.name)
invoice = Invoice.create({
'name': repair.name,
'origin': repair.name,
'type': 'out_invoice',
'account_id': repair.partner_id.property_account_receivable_id.id,
'partner_id': repair.partner_invoice_id.id or repair.partner_id.id,
'currency_id': repair.pricelist_id.currency_id.id,
'comment': repair.quotation_notes,
'fiscal_position_id': repair.partner_id.property_account_position_id.id
})
invoices_group[repair.partner_invoice_id.id] = invoice
repair.write({'invoiced': True, 'invoice_id': invoice.id})
for operation in repair.operations:
if operation.type == 'add':
if group:
name = repair.name + '-' + operation.name
else:
name = operation.name
if operation.product_id.property_account_income_id:
account_id = operation.product_id.property_account_income_id.id
elif operation.product_id.categ_id.property_account_income_categ_id:
account_id = operation.product_id.categ_id.property_account_income_categ_id.id
else:
raise UserError(_('No account defined for product "%s".') % operation.product_id.name)
invoice_line = InvoiceLine.create({
'invoice_id': invoice.id,
'name': name,
'origin': repair.name,
'account_id': account_id,
'quantity': operation.product_uom_qty,
'invoice_line_tax_ids': [(6, 0, [x.id for x in operation.tax_id])],
'uom_id': operation.product_uom.id,
'price_unit': operation.price_unit,
'price_subtotal': operation.product_uom_qty * operation.price_unit,
'product_id': operation.product_id and operation.product_id.id or False
})
operation.write({'invoiced': True, 'invoice_line_id': invoice_line.id})
for fee in repair.fees_lines:
if group:
name = repair.name + '-' + fee.name
else:
name = fee.name
if not fee.product_id:
raise UserError(_('No product defined on Fees!'))
if fee.product_id.property_account_income_id:
account_id = fee.product_id.property_account_income_id.id
elif fee.product_id.categ_id.property_account_income_categ_id:
account_id = fee.product_id.categ_id.property_account_income_categ_id.id
else:
raise UserError(_('No account defined for product "%s".') % fee.product_id.name)
invoice_line = InvoiceLine.create({
'invoice_id': invoice.id,
'name': name,
'origin': repair.name,
'account_id': account_id,
'quantity': fee.product_uom_qty,
'invoice_line_tax_ids': [(6, 0, [x.id for x in fee.tax_id])],
'uom_id': fee.product_uom.id,
'product_id': fee.product_id and fee.product_id.id or False,
'price_unit': fee.price_unit,
'price_subtotal': fee.product_uom_qty * fee.price_unit
})
fee.write({'invoiced': True, 'invoice_line_id': invoice_line.id})
invoice.compute_taxes()
res[repair.id] = invoice.id
return res
@api.multi
def action_created_invoice(self):
self.ensure_one()
return {
'name': _('Invoice created'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'account.invoice',
'view_id': self.env.ref('account.invoice_form').id,
'target': 'current',
'res_id': self.invoice_id.id,
}
def action_repair_ready(self):
self.mapped('operations').write({'state': 'confirmed'})
return self.write({'state': 'ready'})
@api.multi
def action_repair_start(self):
""" Writes repair order state to 'Under Repair'
@return: True
"""
if self.filtered(lambda repair: repair.state not in ['confirmed', 'ready']):
raise UserError(_("Repair must be confirmed before starting reparation."))
self.mapped('operations').write({'state': 'confirmed'})
return self.write({'state': 'under_repair'})
@api.multi
def action_repair_end(self):
""" Writes repair order state to 'To be invoiced' if invoice method is
After repair else state is set to 'Ready'.
@return: True
"""
if self.filtered(lambda repair: repair.state != 'under_repair'):
raise UserError(_("Repair must be under repair in order to end reparation."))
for repair in self:
repair.write({'repaired': True})
vals = {'state': 'done'}
vals['move_id'] = repair.action_repair_done().get(repair.id)
if not repair.invoiced and repair.invoice_method == 'after_repair':
vals['state'] = '2binvoiced'
repair.write(vals)
return True
@api.multi
def action_repair_done(self):
""" Creates stock move for operation and stock move for final product of repair order.
@return: Move ids of final products
"""
if self.filtered(lambda repair: not repair.repaired):
raise UserError(_("Repair must be repaired in order to make the product moves."))
res = {}
Move = self.env['stock.move']
for repair in self:
moves = self.env['stock.move']
for operation in repair.operations:
move = Move.create({
'name': repair.name,
'product_id': operation.product_id.id,
'product_uom_qty': operation.product_uom_qty,
'product_uom': operation.product_uom.id,
'partner_id': repair.address_id.id,
'location_id': operation.location_id.id,
'location_dest_id': operation.location_dest_id.id,
'move_line_ids': [(0, 0, {'product_id': operation.product_id.id,
'lot_id': operation.lot_id.id,
'product_uom_qty': 0, # bypass reservation here
'product_uom_id': operation.product_uom.id,
'qty_done': operation.product_uom_qty,
'package_id': False,
'result_package_id': False,
'location_id': operation.location_id.id, #TODO: owner stuff
'location_dest_id': operation.location_dest_id.id,})],
'repair_id': repair.id,
'origin': repair.name,
})
moves |= move
operation.write({'move_id': move.id, 'state': 'done'})
move = Move.create({
'name': repair.name,
'product_id': repair.product_id.id,
'product_uom': repair.product_uom.id or repair.product_id.uom_id.id,
'product_uom_qty': repair.product_qty,
'partner_id': repair.address_id.id,
'location_id': repair.location_id.id,
'location_dest_id': repair.location_dest_id.id,
'move_line_ids': [(0, 0, {'product_id': repair.product_id.id,
'lot_id': repair.lot_id.id,
'product_uom_qty': 0, # bypass reservation here
'product_uom_id': repair.product_uom.id or repair.product_id.uom_id.id,
'qty_done': repair.product_qty,
'package_id': False,
'result_package_id': False,
'location_id': repair.location_id.id, #TODO: owner stuff
'location_dest_id': repair.location_dest_id.id,})],
'repair_id': repair.id,
'origin': repair.name,
})
consumed_lines = moves.mapped('move_line_ids')
produced_lines = move.move_line_ids
moves |= move
moves._action_done()
produced_lines.write({'consume_line_ids': [(6, 0, consumed_lines.ids)]})
res[repair.id] = move.id
return res
class RepairLine(models.Model):
_name = 'mrp.repair.line'
_description = 'Repair Line'
name = fields.Char('Description', required=True)
repair_id = fields.Many2one(
'mrp.repair', 'Repair Order Reference',
index=True, ondelete='cascade')
type = fields.Selection([
('add', 'Add'),
('remove', 'Remove')], 'Type', required=True)
product_id = fields.Many2one('product.product', 'Product', required=True)
invoiced = fields.Boolean('Invoiced', copy=False, readonly=True)
price_unit = fields.Float('Unit Price', required=True, digits=dp.get_precision('Product Price'))
price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', digits=0)
tax_id = fields.Many2many(
'account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes')
product_uom_qty = fields.Float(
'Quantity', default=1.0,
digits=dp.get_precision('Product Unit of Measure'), required=True)
product_uom = fields.Many2one(
'product.uom', 'Product Unit of Measure',
required=True)
invoice_line_id = fields.Many2one(
'account.invoice.line', 'Invoice Line',
copy=False, readonly=True)
location_id = fields.Many2one(
'stock.location', 'Source Location',
index=True, required=True)
location_dest_id = fields.Many2one(
'stock.location', 'Dest. Location',
index=True, required=True)
move_id = fields.Many2one(
'stock.move', 'Inventory Move',
copy=False, readonly=True)
lot_id = fields.Many2one('stock.production.lot', 'Lot/Serial')
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('done', 'Done'),
('cancel', 'Cancelled')], 'Status', default='draft',
copy=False, readonly=True, required=True,
help='The status of a repair line is set automatically to the one of the linked repair order.')
@api.constrains('lot_id', 'product_id')
def constrain_lot_id(self):
for line in self.filtered(lambda x: x.product_id.tracking != 'none' and not x.lot_id):
raise ValidationError(_("Serial number is required for operation line with product '%s'") % (line.product_id.name))
@api.one
@api.depends('price_unit', 'repair_id', 'product_uom_qty', 'product_id', 'repair_id.invoice_method')
def _compute_price_subtotal(self):
taxes = self.tax_id.compute_all(self.price_unit, self.repair_id.pricelist_id.currency_id, self.product_uom_qty, self.product_id, self.repair_id.partner_id)
self.price_subtotal = taxes['total_excluded']
@api.onchange('type', 'repair_id')
def onchange_operation_type(self):
""" On change of operation type it sets source location, destination location
and to invoice field.
@param product: Changed operation type.
@param guarantee_limit: Guarantee limit of current record.
@return: Dictionary of values.
"""
if not self.type:
self.location_id = False
self.location_dest_id = False
elif self.type == 'add':
self.onchange_product_id()
args = self.repair_id.company_id and [('company_id', '=', self.repair_id.company_id.id)] or []
warehouse = self.env['stock.warehouse'].search(args, limit=1)
self.location_id = warehouse.lot_stock_id
self.location_dest_id = self.env['stock.location'].search([('usage', '=', 'production')], limit=1).id
else:
self.price_unit = 0.0
self.tax_id = False
self.location_id = self.env['stock.location'].search([('usage', '=', 'production')], limit=1).id
self.location_dest_id = self.env['stock.location'].search([('scrap_location', '=', True)], limit=1).id
@api.onchange('repair_id', 'product_id', 'product_uom_qty')
def onchange_product_id(self):
""" On change of product it sets product quantity, tax account, name,
uom of product, unit price and price subtotal. """
partner = self.repair_id.partner_id
pricelist = self.repair_id.pricelist_id
if not self.product_id or not self.product_uom_qty:
return
if self.product_id:
if partner:
self.name = self.product_id.with_context(lang=partner.lang).display_name
else:
self.name = self.product_id.display_name
self.product_uom = self.product_id.uom_id.id
if self.type != 'remove':
if partner and self.product_id:
self.tax_id = partner.property_account_position_id.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
warning = False
if not pricelist:
warning = {
'title': _('No Pricelist!'),
'message':
_('You have to select a pricelist in the Repair form !\n Please set one before choosing a product.')}
else:
price = pricelist.get_product_price(self.product_id, self.product_uom_qty, partner)
if price is False:
warning = {
'title': _('No valid pricelist line found !'),
'message':
_("Couldn't find a pricelist line matching this product and quantity.\nYou have to change either the product, the quantity or the pricelist.")}
else:
self.price_unit = price
if warning:
return {'warning': warning}
class RepairFee(models.Model):
_name = 'mrp.repair.fee'
_description = 'Repair Fees Line'
repair_id = fields.Many2one(
'mrp.repair', 'Repair Order Reference',
index=True, ondelete='cascade', required=True)
name = fields.Char('Description', index=True, required=True)
product_id = fields.Many2one('product.product', 'Product')
product_uom_qty = fields.Float('Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0)
price_unit = fields.Float('Unit Price', required=True)
product_uom = fields.Many2one('product.uom', 'Product Unit of Measure', required=True)
price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', digits=0)
tax_id = fields.Many2many('account.tax', 'repair_fee_line_tax', 'repair_fee_line_id', 'tax_id', 'Taxes')
invoice_line_id = fields.Many2one('account.invoice.line', 'Invoice Line', copy=False, readonly=True)
invoiced = fields.Boolean('Invoiced', copy=False, readonly=True)
@api.one
@api.depends('price_unit', 'repair_id', 'product_uom_qty', 'product_id')
def _compute_price_subtotal(self):
taxes = self.tax_id.compute_all(self.price_unit, self.repair_id.pricelist_id.currency_id, self.product_uom_qty, self.product_id, self.repair_id.partner_id)
self.price_subtotal = taxes['total_excluded']
@api.onchange('repair_id', 'product_id', 'product_uom_qty')
def onchange_product_id(self):
""" On change of product it sets product quantity, tax account, name,
uom of product, unit price and price subtotal. """
if not self.product_id:
return
partner = self.repair_id.partner_id
pricelist = self.repair_id.pricelist_id
if partner and self.product_id:
self.tax_id = partner.property_account_position_id.map_tax(self.product_id.taxes_id, self.product_id, partner).ids
if self.product_id:
self.name = self.product_id.display_name
self.product_uom = self.product_id.uom_id.id
warning = False
if not pricelist:
warning = {
'title': _('No Pricelist!'),
'message':
_('You have to select a pricelist in the Repair form !\n Please set one before choosing a product.')}
else:
price = pricelist.get_product_price(self.product_id, self.product_uom_qty, partner)
if price is False:
warning = {
'title': _('No valid pricelist line found !'),
'message':
_("Couldn't find a pricelist line matching this product and quantity.\nYou have to change either the product, the quantity or the pricelist.")}
else:
self.price_unit = price
if warning:
return {'warning': warning}
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
2197,
492,
2197,
199,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
12,
485,
199,
504,
28811,
14,
10788,
492,
6107,
63,
6833,
465,
12392,
199,
504,
28811,
14,
3924,
492,
29908,
12,
8505,
199,
504,
28811,
14,
2537,
492,
2069,
63,
5785,
421,
199,
533,
28406,
10370,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
1185,
7,
339,
27331,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
17058,
14,
25279,
358,
421,
199,
533,
799,
3852,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
17058,
14,
25279,
7,
272,
485,
1802,
275,
283,
497,
3852,
9240,
7,
272,
485,
6486,
275,
788,
1198,
14,
2671,
297,
283,
1198,
14,
8240,
14,
20406,
418,
272,
485,
1648,
275,
283,
981,
63,
602,
4328,
7,
339,
768,
1246,
14,
1238,
272,
347,
485,
885,
63,
6088,
63,
1985,
8,
277,
304,
267,
13782,
275,
291,
14,
1813,
459,
6088,
14,
12806,
2278,
1733,
8798,
2304,
29,
17,
9,
267,
340,
13782,
26,
288,
372,
13782,
14,
1653,
63,
6088,
63,
344,
14,
344,
267,
372,
756,
339,
536,
275,
1504,
14,
1610,
8,
267,
283,
497,
3852,
10944,
297,
267,
849,
29,
2734,
291,
26,
291,
14,
1813,
459,
723,
14,
4041,
2278,
2184,
63,
991,
63,
600,
360,
17058,
14,
25279,
659,
267,
1331,
29,
797,
12,
1415,
29,
549,
12,
267,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
3336,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
2558,
14,
2558,
297,
1059,
534,
5884,
370,
799,
3852,
297,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
3336,
63,
5643,
275,
1504,
14,
5136,
8,
267,
283,
5884,
31951,
297,
267,
849,
29,
17,
14,
16,
12,
7576,
29,
5780,
14,
362,
63,
6833,
360,
5884,
12008,
402,
22933,
659,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
3336,
63,
7519,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
2558,
14,
7519,
297,
283,
5884,
12008,
402,
22933,
297,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
5854,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
470,
14,
3899,
297,
283,
17025,
297,
267,
1478,
29,
549,
12,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
26804,
267,
1720,
534,
23932,
5854,
367,
12676,
314,
1865,
911,
506,
8485,
68,
436,
28218,
2659,
272,
2287,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
470,
14,
3899,
297,
283,
24640,
9906,
297,
267,
2881,
628,
19412,
1708,
63,
344,
18937,
3899,
63,
344,
1874,
401,
267,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
849,
63,
1562,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3899,
297,
4526,
17574,
3357,
63,
885,
63,
1562,
63,
344,
358,
272,
1174,
275,
1504,
14,
7713,
779,
267,
661,
7185,
297,
283,
2371,
357,
425,
659,
267,
661,
6406,
297,
283,
22127,
659,
267,
661,
16391,
297,
283,
714,
11451,
659,
267,
661,
7138,
63,
25279,
297,
283,
16001,
799,
3852,
659,
267,
661,
2179,
297,
283,
17960,
370,
799,
3852,
659,
267,
661,
18,
1393,
3789,
68,
297,
283,
1378,
506,
19868,
68,
659,
267,
661,
5404,
63,
2590,
297,
283,
21092,
2186,
659,
267,
661,
4456,
297,
283,
497,
29796,
2665,
1059,
534,
3694,
297,
267,
1331,
29,
797,
12,
849,
534,
7185,
297,
6863,
29,
549,
12,
4426,
63,
11269,
534,
18128,
297,
267,
1720,
32103,
710,
8891,
18332,
3985,
2004,
365,
1202,
1380,
282,
922,
365,
2644,
282,
892,
436,
625,
16391,
27331,
1865,
3134,
78,
2,
1467,
8969,
710,
8891,
714,
11451,
3985,
2004,
365,
1202,
1380,
282,
922,
406,
1795,
706,
314,
27331,
1865,
3134,
78,
2,
1467,
8969,
710,
8891,
17960,
370,
799,
3852,
3985,
2004,
365,
1202,
370,
1343,
370,
27331,
316,
12,
922,
883,
1343,
27331,
316,
1454,
2410,
27331,
1865,
365,
22763,
3134,
78,
2,
1467,
8969,
710,
8891,
1378,
506,
19868,
68,
3985,
2004,
365,
1202,
370,
3550,
314,
8485,
2544,
503,
2410,
27331,
316,
4224,
3134,
78,
2,
1467,
8969,
710,
8891,
10759,
3985,
2004,
365,
663,
1380,
27331,
316,
365,
9709,
3134,
78,
2,
1467,
8969,
710,
8891,
22127,
3985,
2004,
365,
1202,
1380,
922,
9311,
27331,
1865,
2685,
272,
2909,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
6088,
14,
1985,
297,
283,
5639,
12625,
297,
267,
849,
3699,
885,
63,
6088,
63,
1985,
12,
267,
1478,
29,
549,
12,
6863,
29,
549,
12,
1415,
29,
549,
12,
267,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
4360,
283,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
2909,
63,
2614,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
6088,
14,
1985,
297,
283,
24640,
12625,
297,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
267,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
4360,
283,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
13918,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
6088,
14,
10777,
14,
1653,
297,
283,
44,
357,
15,
3571,
297,
267,
2881,
628,
19412,
2558,
63,
344,
18937,
3336,
63,
344,
1874,
401,
267,
1720,
628,
29631,
295,
29796,
787,
1006,
30226,
370,
642,
13918,
401,
2269,
354,
628,
8788,
1653,
63,
344,
531,
272,
24197,
63,
3097,
275,
1504,
14,
2506,
360,
55,
285,
1312,
369,
1316,
1038,
1754,
297,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
5331,
275,
1504,
14,
4395,
18,
3479,
8,
267,
283,
17058,
14,
25279,
14,
604,
297,
283,
25279,
63,
344,
297,
283,
28662,
297,
267,
1331,
29,
549,
12,
6863,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
25162,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
2197,
492,
2197,
199,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
12,
485,
199,
504,
28811,
14,
10788,
492,
6107,
63,
6833,
465,
12392,
199,
504,
28811,
14,
3924,
492,
29908,
12,
8505,
199,
504,
28811,
14,
2537,
492,
2069,
63,
5785,
421,
199,
533,
28406,
10370,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
6088,
14,
1185,
7,
339,
27331,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
17058,
14,
25279,
358,
421,
199,
533,
799,
3852,
8,
992,
14,
1685,
304,
272,
485,
354,
275,
283,
17058,
14,
25279,
7,
272,
485,
1802,
275,
283,
497,
3852,
9240,
7,
272,
485,
6486,
275,
788,
1198,
14,
2671,
297,
283,
1198,
14,
8240,
14,
20406,
418,
272,
485,
1648,
275,
283,
981,
63,
602,
4328,
7,
339,
768,
1246,
14,
1238,
272,
347,
485,
885,
63,
6088,
63,
1985,
8,
277,
304,
267,
13782,
275,
291,
14,
1813,
459,
6088,
14,
12806,
2278,
1733,
8798,
2304,
29,
17,
9,
267,
340,
13782,
26,
288,
372,
13782,
14,
1653,
63,
6088,
63,
344,
14,
344,
267,
372,
756,
339,
536,
275,
1504,
14,
1610,
8,
267,
283,
497,
3852,
10944,
297,
267,
849,
29,
2734,
291,
26,
291,
14,
1813,
459,
723,
14,
4041,
2278,
2184,
63,
991,
63,
600,
360,
17058,
14,
25279,
659,
267,
1331,
29,
797,
12,
1415,
29,
549,
12,
267,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
3336,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
2558,
14,
2558,
297,
1059,
534,
5884,
370,
799,
3852,
297,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
3336,
63,
5643,
275,
1504,
14,
5136,
8,
267,
283,
5884,
31951,
297,
267,
849,
29,
17,
14,
16,
12,
7576,
29,
5780,
14,
362,
63,
6833,
360,
5884,
12008,
402,
22933,
659,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
3336,
63,
7519,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
2558,
14,
7519,
297,
283,
5884,
12008,
402,
22933,
297,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
1874,
1552,
272,
5854,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
470,
14,
3899,
297,
283,
17025,
297,
267,
1478,
29,
549,
12,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
26804,
267,
1720,
534,
23932,
5854,
367,
12676,
314,
1865,
911,
506,
8485,
68,
436,
28218,
2659,
272,
2287,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
470,
14,
3899,
297,
283,
24640,
9906,
297,
267,
2881,
628,
19412,
1708,
63,
344,
18937,
3899,
63,
344,
1874,
401,
267,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
849,
63,
1562,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
470,
14,
3899,
297,
4526,
17574,
3357,
63,
885,
63,
1562,
63,
344,
358,
272,
1174,
275,
1504,
14,
7713,
779,
267,
661,
7185,
297,
283,
2371,
357,
425,
659,
267,
661,
6406,
297,
283,
22127,
659,
267,
661,
16391,
297,
283,
714,
11451,
659,
267,
661,
7138,
63,
25279,
297,
283,
16001,
799,
3852,
659,
267,
661,
2179,
297,
283,
17960,
370,
799,
3852,
659,
267,
661,
18,
1393,
3789,
68,
297,
283,
1378,
506,
19868,
68,
659,
267,
661,
5404,
63,
2590,
297,
283,
21092,
2186,
659,
267,
661,
4456,
297,
283,
497,
29796,
2665,
1059,
534,
3694,
297,
267,
1331,
29,
797,
12,
849,
534,
7185,
297,
6863,
29,
549,
12,
4426,
63,
11269,
534,
18128,
297,
267,
1720,
32103,
710,
8891,
18332,
3985,
2004,
365,
1202,
1380,
282,
922,
365,
2644,
282,
892,
436,
625,
16391,
27331,
1865,
3134,
78,
2,
1467,
8969,
710,
8891,
714,
11451,
3985,
2004,
365,
1202,
1380,
282,
922,
406,
1795,
706,
314,
27331,
1865,
3134,
78,
2,
1467,
8969,
710,
8891,
17960,
370,
799,
3852,
3985,
2004,
365,
1202,
370,
1343,
370,
27331,
316,
12,
922,
883,
1343,
27331,
316,
1454,
2410,
27331,
1865,
365,
22763,
3134,
78,
2,
1467,
8969,
710,
8891,
1378,
506,
19868,
68,
3985,
2004,
365,
1202,
370,
3550,
314,
8485,
2544,
503,
2410,
27331,
316,
4224,
3134,
78,
2,
1467,
8969,
710,
8891,
10759,
3985,
2004,
365,
663,
1380,
27331,
316,
365,
9709,
3134,
78,
2,
1467,
8969,
710,
8891,
22127,
3985,
2004,
365,
1202,
1380,
922,
9311,
27331,
1865,
2685,
272,
2909,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
6088,
14,
1985,
297,
283,
5639,
12625,
297,
267,
849,
3699,
885,
63,
6088,
63,
1985,
12,
267,
1478,
29,
549,
12,
6863,
29,
549,
12,
1415,
29,
549,
12,
267,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
4360,
283,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
2909,
63,
2614,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
6088,
14,
1985,
297,
283,
24640,
12625,
297,
267,
6863,
29,
549,
12,
1415,
29,
549,
12,
267,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
4360,
283,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
13918,
63,
344,
275,
1504,
14,
4089,
18,
368,
8,
267,
283,
6088,
14,
10777,
14,
1653,
297,
283,
44,
357,
15,
3571,
297,
267,
2881,
628,
19412,
2558,
63,
344,
18937,
3336,
63,
344,
1874,
401,
267,
1720,
628,
29631,
295,
29796,
787,
1006,
30226,
370,
642,
13918,
401,
2269,
354,
628,
8788,
1653,
63,
344,
531,
272,
24197,
63,
3097,
275,
1504,
14,
2506,
360,
55,
285,
1312,
369,
1316,
1038,
1754,
297,
6363,
3713,
16391,
356,
4274,
6753,
297,
715,
1874,
1552,
272,
5331,
275,
1504,
14,
4395,
18,
3479,
8,
267,
283,
17058,
14,
25279,
14,
604,
297,
283,
25279,
63,
344,
297,
283,
28662,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
arsfeld/conduit
|
conduit/modules/ShutterflyModule/ShutterflyModule.py
|
1
|
3532
|
"""
Shutterfly Data Sink
"""
import logging
log = logging.getLogger("modules.Shutterfly")
import conduit
import conduit.utils as Utils
from conduit.datatypes import Rid
import conduit.dataproviders.Image as Image
import conduit.Exceptions as Exceptions
import conduit.datatypes.Photo as Photo
Utils.dataprovider_add_dir_to_path(__file__, "shutterfly")
from shutterfly import Shutterfly
from gettext import gettext as _
MODULES = {
"ShutterflySink" : {"type" : "dataprovider"},
}
class ShutterflySink(Image.ImageSink):
_name_ = _("Shutterfly")
_description_ = _("Synchronize your Shutterfly photos")
_module_type_ = "sink"
_icon_ = "shutterfly"
_configurable_ = True
def __init__(self, *args):
Image.ImageSink.__init__(self)
self.username = ""
self.password = ""
self.album = ""
self.sapi = None
self.salbum = None
self.sphotos = None
def _get_raw_photo_url(self, photoInfo):
return photoInfo.url
def _get_photo_info(self, id):
if self.sphotos.has_key(id):
return self.sphotos[id]
else:
return None
def _get_photo_formats(self):
return ("image/jpeg", )
def refresh(self):
Image.ImageSink.refresh(self)
self.sapi = Shutterfly(self.username, self.password)
albums = self.sapi.getAlbums()
if not albums.has_key(self.album):
self.salbum = self.sapi.createAlbum(self.album)
else:
self.salbum = albums[self.album]
self.sphotos = self.salbum.getPhotos()
def get_all(self):
return self.sphotos.keys()
def get(self, LUID):
#Image.ImageSink.get(self, LUID)
sphoto = self.sphotos[LUID]
f = Photo.Photo(URI=sphoto.url)
f.set_open_URI(sphoto.url)
f.set_UID(LUID)
return f
def delete(self, LUID):
"""
Delete a photo by ID
Deleting a photo invalidates album length and photo index values.
We must reload the photos (or do something else...)
"""
if not self.sphotos.has_key(LUID):
log.warn("Photo does not exist")
return
try:
self.salbum.deletePhoto(self.sphotos[LUID])
except Exception, e:
raise Exceptions.SyncronizeError("Shutterfly Delete Error - Try Again.")
self.sphotos = self.salbum.getPhotos()
def _upload_photo(self, uploadInfo):
"""
Upload to album
"""
try:
ret = self.salbum.uploadPhoto(uploadInfo.url, uploadInfo.mimeType, uploadInfo.name)
return Rid(ret.id)
except Exception, e:
raise Exceptions.SyncronizeError("Shutterfly Upload Error.")
def configure(self, window):
"""
Configures the ShutterflySink
"""
widget = Utils.dataprovider_glade_get_widget(
__file__,
"shutterfly.glade",
"ShutterflySinkConfigDialog")
# Get configuration widgets
username = widget.get_widget("username")
password = widget.get_widget("password")
album = widget.get_widget("album")
# Load the widgets with presets
username.set_text(self.username)
password.set_text(self.password)
album.set_text(self.album)
dlg = widget.get_widget("ShutterflySinkConfigDialog")
response = Utils.run_dialog(dlg, window)
if response == True:
self.username = username.get_text()
self.password = password.get_text()
self.album = album.get_text()
dlg.destroy()
def get_configuration(self):
return {
"username" : self.username,
"password" : self.password,
"album" : self.album
}
def is_configured(self, isSource, isTwoWay):
if len(self.username) < 1:
return False
if len(self.password) < 1:
return False
if len(self.album) < 1:
return False
return True
def get_UID(self):
return self.username+":"+self.album
|
gpl-2.0
|
[
624,
199,
2662,
18404,
21600,
3918,
428,
2292,
199,
624,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
480,
3112,
14,
2662,
18404,
21600,
531,
199,
199,
646,
406,
2033,
390,
199,
646,
406,
2033,
390,
14,
1208,
465,
17397,
199,
504,
406,
2033,
390,
14,
14184,
83,
492,
820,
344,
199,
646,
406,
2033,
390,
14,
576,
9710,
14,
3491,
465,
6047,
199,
646,
406,
2033,
390,
14,
16836,
465,
24873,
199,
646,
406,
2033,
390,
14,
14184,
83,
14,
21258,
465,
30808,
199,
199,
7535,
14,
576,
3780,
63,
525,
63,
694,
63,
475,
63,
515,
3460,
493,
3108,
298,
609,
18404,
21600,
531,
199,
504,
1033,
18404,
21600,
492,
5244,
18404,
21600,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
21194,
275,
469,
199,
198,
2,
2662,
18404,
21600,
17111,
2,
520,
2420,
466,
2,
520,
298,
576,
3780,
6018,
199,
93,
421,
199,
533,
5244,
18404,
21600,
17111,
8,
3491,
14,
3491,
17111,
304,
8299,
198,
63,
354,
63,
275,
3824,
2662,
18404,
21600,
531,
199,
198,
63,
1802,
63,
275,
3824,
21814,
794,
2195,
5244,
18404,
21600,
3945,
17278,
531,
199,
198,
63,
578,
63,
466,
63,
275,
298,
11279,
2,
199,
198,
63,
4677,
63,
275,
298,
609,
18404,
21600,
2,
199,
198,
63,
888,
15684,
63,
275,
715,
8299,
198,
318,
636,
826,
721,
277,
12,
627,
589,
304,
507,
198,
3491,
14,
3491,
17111,
855,
826,
721,
277,
9,
507,
198,
277,
14,
2473,
275,
3087,
507,
198,
277,
14,
2060,
275,
3087,
507,
198,
277,
14,
12110,
275,
3087,
507,
198,
277,
14,
83,
1246,
275,
488,
507,
198,
277,
14,
6327,
7767,
275,
488,
507,
198,
277,
14,
7616,
17278,
275,
488,
421,
198,
318,
485,
362,
63,
1773,
63,
13834,
63,
633,
8,
277,
12,
19397,
2354,
304,
507,
198,
1107,
19397,
2354,
14,
633,
421,
198,
318,
485,
362,
63,
13834,
63,
815,
8,
277,
12,
1305,
304,
507,
198,
692,
291,
14,
7616,
17278,
14,
1989,
63,
498,
8,
344,
304,
686,
198,
1107,
291,
14,
7616,
17278,
59,
344,
61,
507,
198,
2836,
26,
686,
198,
1107,
488,
8299,
198,
318,
485,
362,
63,
13834,
63,
6321,
8,
277,
304,
507,
198,
1107,
1689,
1569,
15,
14230,
401,
776,
8299,
198,
318,
9236,
8,
277,
304,
507,
198,
3491,
14,
3491,
17111,
14,
6635,
8,
277,
9,
507,
198,
277,
14,
83,
1246,
275,
5244,
18404,
21600,
8,
277,
14,
2473,
12,
291,
14,
2060,
9,
9068,
198,
12110,
83,
275,
291,
14,
83,
1246,
14,
362,
26369,
83,
342,
507,
198,
692,
440,
16379,
83,
14,
1989,
63,
498,
8,
277,
14,
12110,
304,
686,
198,
277,
14,
6327,
7767,
275,
291,
14,
83,
1246,
14,
981,
26369,
8,
277,
14,
12110,
9,
507,
198,
2836,
26,
686,
198,
277,
14,
6327,
7767,
275,
16379,
83,
59,
277,
14,
12110,
61,
9068,
198,
277,
14,
7616,
17278,
275,
291,
14,
6327,
7767,
14,
362,
5663,
17278,
342,
8299,
198,
318,
664,
63,
452,
8,
277,
304,
507,
198,
1107,
291,
14,
7616,
17278,
14,
1612,
342,
8299,
198,
318,
664,
8,
277,
12,
491,
6685,
304,
507,
198,
3,
3491,
14,
3491,
17111,
14,
362,
8,
277,
12,
491,
6685,
9,
507,
198,
7616,
3459,
275,
291,
14,
7616,
17278,
59,
44,
6685,
61,
2742,
198,
70,
275,
30808,
14,
21258,
8,
7639,
29,
7616,
3459,
14,
633,
9,
507,
198,
70,
14,
409,
63,
1490,
63,
7639,
8,
7616,
3459,
14,
633,
9,
507,
198,
70,
14,
409,
63,
6685,
8,
44,
6685,
9,
2742,
198,
1107,
289,
421,
198,
318,
3145,
8,
277,
12,
491,
6685,
304,
507,
198,
624,
507,
198,
5392,
282,
19397,
701,
2870,
507,
198,
22001,
282,
19397,
3866,
2335,
16379,
2582,
436,
19397,
1478,
1338,
14,
507,
198,
6004,
1471,
13101,
314,
3945,
17278,
334,
269,
886,
6020,
587,
11965,
507,
198,
624,
507,
198,
692,
440,
291,
14,
7616,
17278,
14,
1989,
63,
498,
8,
44,
6685,
304,
686,
198,
793,
14,
4050,
480,
21258,
1630,
440,
2187,
531,
686,
198,
1107,
2742,
198,
893,
26,
686,
198,
277,
14,
6327,
7767,
14,
1807,
21258,
8,
277,
14,
7616,
17278,
59,
44,
6685,
566,
507,
198,
2590,
2186,
12,
325,
26,
686,
198,
3730,
24873,
14,
17746,
14829,
794,
547,
480,
2662,
18404,
21600,
8496,
4520,
446,
7649,
437,
13020,
2685,
2742,
198,
277,
14,
7616,
17278,
275,
291,
14,
6327,
7767,
14,
362,
5663,
17278,
342,
18118,
198,
318,
485,
5064,
63,
13834,
8,
277,
12,
5802,
2354,
304,
507,
198,
624,
507,
198,
10301,
370,
16379,
507,
198,
624,
507,
198,
893,
26,
686,
198,
3292,
275,
291,
14,
6327,
7767,
14,
5064,
21258,
8,
5064,
2354,
14,
633,
12,
5802,
2354,
14,
7626,
804,
12,
5802,
2354,
14,
354,
9,
686,
198,
1107,
820,
344,
8,
3292,
14,
344,
9,
507,
198,
2590,
2186,
12,
325,
26,
686,
198,
3730,
24873,
14,
17746,
14829,
794,
547,
480,
2662,
18404,
21600,
19149,
4520,
2685,
8299,
198,
318,
7908,
8,
277,
12,
4353,
304,
507,
198,
624,
507,
198,
2028,
1482,
314,
5244,
18404,
21600,
17111,
507,
198,
624,
507,
198,
3440,
275,
17397,
14,
576,
3780,
63,
31589,
63,
362,
63,
3440,
8,
686,
198,
363,
493,
3108,
686,
198,
2,
609,
18404,
21600,
14,
31589,
401,
686,
198,
2,
2662,
18404,
21600,
17111,
2028,
5619,
531,
9068,
198,
3,
2372,
2897,
11114,
507,
198,
2473,
275,
3938,
14,
362,
63,
3440,
480,
2473,
531,
507,
198,
2060,
275,
3938,
14,
362,
63,
3440,
480,
2060,
531,
507,
198,
12110,
275,
3938,
14,
362,
63,
3440,
480,
12110,
531,
9068,
198,
3,
7190,
314,
11114,
543,
876,
2193,
507,
198,
2473,
14,
409,
63,
505,
8,
277,
14,
2473,
9,
507,
198,
2060,
14,
409,
63,
505,
8,
277,
14,
2060,
9,
507,
198,
12110,
14,
409,
63,
505,
8,
277,
14,
12110,
9,
9068,
198,
24645,
275,
3938,
14,
362,
63,
3440,
480,
2662,
18404,
21600,
17111,
2028,
5619,
531,
9068,
198,
1310,
275,
17397,
14,
1065,
63,
7196,
8,
24645,
12,
4353,
9,
9068,
198,
692,
1177,
508,
715,
26,
686,
198,
277,
14
] |
[
199,
2662,
18404,
21600,
3918,
428,
2292,
199,
624,
199,
646,
2050,
199,
793,
275,
2050,
14,
5572,
480,
3112,
14,
2662,
18404,
21600,
531,
199,
199,
646,
406,
2033,
390,
199,
646,
406,
2033,
390,
14,
1208,
465,
17397,
199,
504,
406,
2033,
390,
14,
14184,
83,
492,
820,
344,
199,
646,
406,
2033,
390,
14,
576,
9710,
14,
3491,
465,
6047,
199,
646,
406,
2033,
390,
14,
16836,
465,
24873,
199,
646,
406,
2033,
390,
14,
14184,
83,
14,
21258,
465,
30808,
199,
199,
7535,
14,
576,
3780,
63,
525,
63,
694,
63,
475,
63,
515,
3460,
493,
3108,
298,
609,
18404,
21600,
531,
199,
504,
1033,
18404,
21600,
492,
5244,
18404,
21600,
199,
199,
504,
9796,
492,
9796,
465,
485,
199,
199,
21194,
275,
469,
199,
198,
2,
2662,
18404,
21600,
17111,
2,
520,
2420,
466,
2,
520,
298,
576,
3780,
6018,
199,
93,
421,
199,
533,
5244,
18404,
21600,
17111,
8,
3491,
14,
3491,
17111,
304,
8299,
198,
63,
354,
63,
275,
3824,
2662,
18404,
21600,
531,
199,
198,
63,
1802,
63,
275,
3824,
21814,
794,
2195,
5244,
18404,
21600,
3945,
17278,
531,
199,
198,
63,
578,
63,
466,
63,
275,
298,
11279,
2,
199,
198,
63,
4677,
63,
275,
298,
609,
18404,
21600,
2,
199,
198,
63,
888,
15684,
63,
275,
715,
8299,
198,
318,
636,
826,
721,
277,
12,
627,
589,
304,
507,
198,
3491,
14,
3491,
17111,
855,
826,
721,
277,
9,
507,
198,
277,
14,
2473,
275,
3087,
507,
198,
277,
14,
2060,
275,
3087,
507,
198,
277,
14,
12110,
275,
3087,
507,
198,
277,
14,
83,
1246,
275,
488,
507,
198,
277,
14,
6327,
7767,
275,
488,
507,
198,
277,
14,
7616,
17278,
275,
488,
421,
198,
318,
485,
362,
63,
1773,
63,
13834,
63,
633,
8,
277,
12,
19397,
2354,
304,
507,
198,
1107,
19397,
2354,
14,
633,
421,
198,
318,
485,
362,
63,
13834,
63,
815,
8,
277,
12,
1305,
304,
507,
198,
692,
291,
14,
7616,
17278,
14,
1989,
63,
498,
8,
344,
304,
686,
198,
1107,
291,
14,
7616,
17278,
59,
344,
61,
507,
198,
2836,
26,
686,
198,
1107,
488,
8299,
198,
318,
485,
362,
63,
13834,
63,
6321,
8,
277,
304,
507,
198,
1107,
1689,
1569,
15,
14230,
401,
776,
8299,
198,
318,
9236,
8,
277,
304,
507,
198,
3491,
14,
3491,
17111,
14,
6635,
8,
277,
9,
507,
198,
277,
14,
83,
1246,
275,
5244,
18404,
21600,
8,
277,
14,
2473,
12,
291,
14,
2060,
9,
9068,
198,
12110,
83,
275,
291,
14,
83,
1246,
14,
362,
26369,
83,
342,
507,
198,
692,
440,
16379,
83,
14,
1989,
63,
498,
8,
277,
14,
12110,
304,
686,
198,
277,
14,
6327,
7767,
275,
291,
14,
83,
1246,
14,
981,
26369,
8,
277,
14,
12110,
9,
507,
198,
2836,
26,
686,
198,
277,
14,
6327,
7767,
275,
16379,
83,
59,
277,
14,
12110,
61,
9068,
198,
277,
14,
7616,
17278,
275,
291,
14,
6327,
7767,
14,
362,
5663,
17278,
342,
8299,
198,
318,
664,
63,
452,
8,
277,
304,
507,
198,
1107,
291,
14,
7616,
17278,
14,
1612,
342,
8299,
198,
318,
664,
8,
277,
12,
491,
6685,
304,
507,
198,
3,
3491,
14,
3491,
17111,
14,
362,
8,
277,
12,
491,
6685,
9,
507,
198,
7616,
3459,
275,
291,
14,
7616,
17278,
59,
44,
6685,
61,
2742,
198,
70,
275,
30808,
14,
21258,
8,
7639,
29,
7616,
3459,
14,
633,
9,
507,
198,
70,
14,
409,
63,
1490,
63,
7639,
8,
7616,
3459,
14,
633,
9,
507,
198,
70,
14,
409,
63,
6685,
8,
44,
6685,
9,
2742,
198,
1107,
289,
421,
198,
318,
3145,
8,
277,
12,
491,
6685,
304,
507,
198,
624,
507,
198,
5392,
282,
19397,
701,
2870,
507,
198,
22001,
282,
19397,
3866,
2335,
16379,
2582,
436,
19397,
1478,
1338,
14,
507,
198,
6004,
1471,
13101,
314,
3945,
17278,
334,
269,
886,
6020,
587,
11965,
507,
198,
624,
507,
198,
692,
440,
291,
14,
7616,
17278,
14,
1989,
63,
498,
8,
44,
6685,
304,
686,
198,
793,
14,
4050,
480,
21258,
1630,
440,
2187,
531,
686,
198,
1107,
2742,
198,
893,
26,
686,
198,
277,
14,
6327,
7767,
14,
1807,
21258,
8,
277,
14,
7616,
17278,
59,
44,
6685,
566,
507,
198,
2590,
2186,
12,
325,
26,
686,
198,
3730,
24873,
14,
17746,
14829,
794,
547,
480,
2662,
18404,
21600,
8496,
4520,
446,
7649,
437,
13020,
2685,
2742,
198,
277,
14,
7616,
17278,
275,
291,
14,
6327,
7767,
14,
362,
5663,
17278,
342,
18118,
198,
318,
485,
5064,
63,
13834,
8,
277,
12,
5802,
2354,
304,
507,
198,
624,
507,
198,
10301,
370,
16379,
507,
198,
624,
507,
198,
893,
26,
686,
198,
3292,
275,
291,
14,
6327,
7767,
14,
5064,
21258,
8,
5064,
2354,
14,
633,
12,
5802,
2354,
14,
7626,
804,
12,
5802,
2354,
14,
354,
9,
686,
198,
1107,
820,
344,
8,
3292,
14,
344,
9,
507,
198,
2590,
2186,
12,
325,
26,
686,
198,
3730,
24873,
14,
17746,
14829,
794,
547,
480,
2662,
18404,
21600,
19149,
4520,
2685,
8299,
198,
318,
7908,
8,
277,
12,
4353,
304,
507,
198,
624,
507,
198,
2028,
1482,
314,
5244,
18404,
21600,
17111,
507,
198,
624,
507,
198,
3440,
275,
17397,
14,
576,
3780,
63,
31589,
63,
362,
63,
3440,
8,
686,
198,
363,
493,
3108,
686,
198,
2,
609,
18404,
21600,
14,
31589,
401,
686,
198,
2,
2662,
18404,
21600,
17111,
2028,
5619,
531,
9068,
198,
3,
2372,
2897,
11114,
507,
198,
2473,
275,
3938,
14,
362,
63,
3440,
480,
2473,
531,
507,
198,
2060,
275,
3938,
14,
362,
63,
3440,
480,
2060,
531,
507,
198,
12110,
275,
3938,
14,
362,
63,
3440,
480,
12110,
531,
9068,
198,
3,
7190,
314,
11114,
543,
876,
2193,
507,
198,
2473,
14,
409,
63,
505,
8,
277,
14,
2473,
9,
507,
198,
2060,
14,
409,
63,
505,
8,
277,
14,
2060,
9,
507,
198,
12110,
14,
409,
63,
505,
8,
277,
14,
12110,
9,
9068,
198,
24645,
275,
3938,
14,
362,
63,
3440,
480,
2662,
18404,
21600,
17111,
2028,
5619,
531,
9068,
198,
1310,
275,
17397,
14,
1065,
63,
7196,
8,
24645,
12,
4353,
9,
9068,
198,
692,
1177,
508,
715,
26,
686,
198,
277,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
totallybradical/temp_servo2
|
tests/wpt/css-tests/css-text-decor-3_dev/xhtml1/reference/support/generate-text-emphasis-style-property-tests.py
|
841
|
3434
|
#!/usr/bin/env python
# - * - coding: UTF-8 - * -
"""
This script generates tests text-emphasis-style-property-011 ~ 020 which
cover all possible values of text-emphasis-style property, except none
and <string>, with horizontal writing mode. It outputs a list of all
tests it generated in the format of Mozilla reftest.list to the stdout.
"""
from __future__ import unicode_literals
TEST_FILE = 'text-emphasis-style-property-{:03}{}.html'
TEST_TEMPLATE = '''<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Test: text-emphasis-style: {title}</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
<link rel="author" title="Mozilla" href="https://www.mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-style-property">
<meta name="assert" content="'text-emphasis-style: {value}' produces {code} as emphasis marks.">
<link rel="match" href="text-emphasis-style-property-{index:03}-ref.html">
<p>Pass if there is a '{char}' above every character below:</p>
<div style="line-height: 5; text-emphasis-style: {value}">試験テスト</div>
'''
REF_FILE = 'text-emphasis-style-property-{:03}-ref.html'
REF_TEMPLATE = '''<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Reference: text-emphasis-style: {0}</title>
<link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
<link rel="author" title="Mozilla" href="https://www.mozilla.org">
<style> rt {{ font-variant-east-asian: inherit; }} </style>
<p>Pass if there is a '{1}' above every character below:</p>
<div style="line-height: 5;"><ruby>試<rt>{1}</rt>験<rt>{1}</rt>テ<rt>{1}</rt>ス<rt>{1}</rt>ト<rt>{1}</rt></ruby></div>
'''
DATA_SET = [
('dot', 0x2022, 0x25e6),
('circle', 0x25cf, 0x25cb),
('double-circle', 0x25c9, 0x25ce),
('triangle', 0x25b2, 0x25b3),
('sesame', 0xfe45, 0xfe46),
]
SUFFIXES = ['', 'a', 'b', 'c', 'd', 'e']
def get_html_entity(code):
return '&#x{:04X};'.format(code)
def write_file(filename, content):
with open(filename, 'wb') as f:
f.write(content.encode('UTF-8'))
def write_test_file(idx, suffix, style, code, name=None):
if not name:
name = style
filename = TEST_FILE.format(idx, suffix)
write_file(filename, TEST_TEMPLATE.format(index=idx, value=style,
char=get_html_entity(code),
code='U+{:04X}'.format(code),
title=name))
print("== {} {}".format(filename, REF_FILE.format(idx)))
idx = 10
def write_files(style, code):
global idx
idx += 1
fill, shape = style
basic_style = "{} {}".format(fill, shape)
write_file(REF_FILE.format(idx),
REF_TEMPLATE.format(basic_style, get_html_entity(code)))
suffix = iter(SUFFIXES)
write_test_file(idx, next(suffix), basic_style, code)
write_test_file(idx, next(suffix), "{} {}".format(shape, fill), code)
if fill == 'filled':
write_test_file(idx, next(suffix), shape, code)
if shape == 'circle':
write_test_file(idx, next(suffix), fill, code, fill + ', horizontal')
print("# START tests from {}".format(__file__))
for name, code, _ in DATA_SET:
write_files(('filled', name), code)
for name, _, code in DATA_SET:
write_files(('open', name), code)
print("# END tests from {}".format(__file__))
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
446,
627,
446,
2803,
26,
9094,
13,
24,
446,
627,
446,
199,
199,
624,
199,
2765,
2884,
12821,
2295,
1318,
13,
28907,
13,
2487,
13,
1829,
13,
13059,
6146,
378,
1165,
1314,
199,
5899,
1006,
3962,
1338,
402,
1318,
13,
28907,
13,
2487,
3324,
12,
871,
7179,
199,
460,
665,
875,
6244,
543,
17528,
3575,
818,
14,
2779,
4704,
282,
769,
402,
1006,
199,
2219,
652,
4046,
315,
314,
1475,
402,
17728,
2984,
396,
14,
513,
370,
314,
3839,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
2864,
63,
3817,
275,
283,
505,
13,
28907,
13,
2487,
13,
1829,
24185,
26,
1644,
93,
31270,
1360,
7,
199,
2864,
63,
7433,
275,
1449,
11230,
16556,
3517,
30,
199,
28,
2024,
5960,
628,
1624,
13,
24,
1743,
199,
28,
1213,
30,
14391,
1379,
26,
1318,
13,
28907,
13,
2487,
26,
469,
1213,
17890,
1213,
30,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
56,
344,
6161,
5843,
290,
2,
4369,
628,
2859,
921,
1544,
14,
384,
4792,
14,
1308,
1743,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
22285,
2,
4369,
628,
2859,
921,
1544,
14,
12102,
14,
1308,
1743,
199,
28,
1073,
4668,
628,
3437,
2,
4369,
628,
2859,
921,
7185,
83,
14,
3919,
23596,
14,
1308,
15,
3919,
13,
505,
13,
6518,
13,
19,
12645,
505,
13,
28907,
13,
2487,
13,
1829,
1743,
199,
28,
2024,
536,
628,
479,
2,
1564,
26957,
505,
13,
28907,
13,
2487,
26,
469,
585,
6834,
16904,
469,
600,
93,
465,
9052,
24059,
17370,
14,
1743,
199,
28,
1073,
4668,
628,
1431,
2,
4369,
628,
505,
13,
28907,
13,
2487,
13,
1829,
24185,
1080,
26,
1644,
17063,
1121,
14,
1360,
1743,
199,
28,
80,
30,
4986,
340,
2337,
365,
282,
5041,
1560,
6834,
3432,
4036,
4528,
5084,
9919,
80,
30,
199,
28,
3015,
3449,
628,
604,
13,
3333,
26,
959,
27,
1318,
13,
28907,
13,
2487,
26,
469,
585,
93,
1743,
165,
103,
100,
166,
102,
242,
5692,
229,
25111,
23869,
1108,
3015,
30,
199,
2344,
199,
199,
8279,
63,
3817,
275,
283,
505,
13,
28907,
13,
2487,
13,
1829,
24185,
26,
1644,
17063,
1121,
14,
1360,
7,
199,
8279,
63,
7433,
275,
1449,
11230,
16556,
3517,
30,
199,
28,
2024,
5960,
628,
1624,
13,
24,
1743,
199,
28,
1213,
30,
14391,
10944,
26,
1318,
13,
28907,
13,
2487,
26,
469,
16,
17890,
1213,
30,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
56,
344,
6161,
5843,
290,
2,
4369,
628,
2859,
921,
1544,
14,
384,
4792,
14,
1308,
1743,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
22285,
2,
4369,
628,
2859,
921,
1544,
14,
12102,
14,
1308,
1743,
199,
28,
2487,
30,
14059,
8448,
5023,
13,
8759,
13,
14346,
13,
305,
5653,
26,
8287,
27,
3586,
3068,
2487,
30,
199,
28,
80,
30,
4986,
340,
2337,
365,
282,
5041,
17,
6834,
3432,
4036,
4528,
5084,
9919,
80,
30,
199,
28,
3015,
3449,
628,
604,
13,
3333,
26,
959,
27,
8186,
21952,
30,
165,
103,
100,
28,
2591,
22266,
17,
17890,
2591,
30,
166,
102,
242,
28,
2591,
22266,
17,
17890,
2591,
30,
5692,
229,
28,
2591,
22266,
17,
17890,
2591,
30,
25111,
28,
2591,
22266,
17,
17890,
2591,
30,
23869,
28,
2591,
22266,
17,
17890,
2591,
2957,
21952,
2957,
3015,
30,
199,
2344,
199,
199,
3998,
63,
3597,
275,
359,
267,
661,
3287,
297,
3698,
378,
88,
13859,
12,
378,
88,
821,
69,
22,
395,
267,
661,
11001,
297,
263,
378,
88,
821,
2177,
12,
378,
88,
821,
2894,
395,
267,
661,
3157,
13,
11001,
297,
378,
88,
821,
67,
25,
12,
378,
88,
821,
301,
395,
267,
661,
21584,
297,
420,
378,
88,
821,
66,
18,
12,
378,
88,
821,
66,
19,
395,
267,
661,
874,
313,
297,
263,
378,
8371,
2322,
12,
378,
8371,
2466,
395,
267,
1622,
199,
199,
12273,
654,
275,
18179,
283,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
418,
199,
199,
318,
664,
63,
1360,
63,
4502,
8,
600,
304,
272,
372,
7673,
3,
88,
28476,
966,
56,
12084,
1370,
908,
8,
600,
9,
199,
199,
318,
2218,
63,
493,
8,
1501,
12,
1564,
304,
272,
543,
1551,
8,
1501,
12,
283,
6603,
358,
465,
289,
26,
267,
289,
14,
952,
8,
1317,
14,
2143,
360,
6610,
13,
24,
1333,
199,
199,
318,
2218,
63,
396,
63,
493,
8,
2996,
12,
4739,
12,
3449,
12,
1233,
12,
536,
29,
403,
304,
272,
340,
440,
536,
26,
267,
536,
275,
3449,
272,
1788,
275,
7393,
63,
3817,
14,
908,
8,
2996,
12,
4739,
9,
272,
2218,
63,
493,
8,
1501,
12,
7393,
63,
7433,
14,
908,
8,
1080,
29,
2996,
12,
574,
29,
2487,
12,
6343,
1495,
29,
362,
63,
1360,
63,
4502,
8,
600,
395,
6343,
1233,
534,
53,
11,
28476,
966,
56,
5285,
908,
8,
600,
395,
6343,
2538,
29,
354,
430,
272,
870,
480,
389,
1052,
8352,
908,
8,
1501,
12,
5363,
38,
63,
3817,
14,
908,
8,
2996,
1724,
199,
199,
2996,
275,
1616,
199,
318,
2218,
63,
1725,
8,
2487,
12,
1233,
304,
272,
2288,
4280,
272,
4280,
847,
413,
272,
5554,
12,
2215,
275,
3449,
272,
5678,
63,
2487,
275,
11491,
8352,
908,
8,
4498,
12,
2215,
9,
272,
2218,
63,
493,
8,
8279,
63,
3817,
14,
908,
8,
2996,
395,
2049,
5363,
38,
63,
7433,
14,
908,
8,
4316,
63,
2487,
12,
664,
63,
1360,
63,
4502,
8,
600,
1724,
272,
4739,
275,
2740,
8,
12273,
654,
9,
272,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
5678,
63,
2487,
12,
1233,
9,
272,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
11491,
8352,
908,
8,
1392,
12,
5554,
395,
1233,
9,
272,
340,
5554,
508,
283,
17647,
356,
267,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
2215,
12,
1233,
9,
272,
340,
2215,
508,
283,
11001,
356,
267,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
5554,
12,
1233,
12,
5554,
435,
1656,
17528,
358,
199,
199,
1361,
10064,
13910,
2295
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
446,
627,
446,
2803,
26,
9094,
13,
24,
446,
627,
446,
199,
199,
624,
199,
2765,
2884,
12821,
2295,
1318,
13,
28907,
13,
2487,
13,
1829,
13,
13059,
6146,
378,
1165,
1314,
199,
5899,
1006,
3962,
1338,
402,
1318,
13,
28907,
13,
2487,
3324,
12,
871,
7179,
199,
460,
665,
875,
6244,
543,
17528,
3575,
818,
14,
2779,
4704,
282,
769,
402,
1006,
199,
2219,
652,
4046,
315,
314,
1475,
402,
17728,
2984,
396,
14,
513,
370,
314,
3839,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
2864,
63,
3817,
275,
283,
505,
13,
28907,
13,
2487,
13,
1829,
24185,
26,
1644,
93,
31270,
1360,
7,
199,
2864,
63,
7433,
275,
1449,
11230,
16556,
3517,
30,
199,
28,
2024,
5960,
628,
1624,
13,
24,
1743,
199,
28,
1213,
30,
14391,
1379,
26,
1318,
13,
28907,
13,
2487,
26,
469,
1213,
17890,
1213,
30,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
56,
344,
6161,
5843,
290,
2,
4369,
628,
2859,
921,
1544,
14,
384,
4792,
14,
1308,
1743,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
22285,
2,
4369,
628,
2859,
921,
1544,
14,
12102,
14,
1308,
1743,
199,
28,
1073,
4668,
628,
3437,
2,
4369,
628,
2859,
921,
7185,
83,
14,
3919,
23596,
14,
1308,
15,
3919,
13,
505,
13,
6518,
13,
19,
12645,
505,
13,
28907,
13,
2487,
13,
1829,
1743,
199,
28,
2024,
536,
628,
479,
2,
1564,
26957,
505,
13,
28907,
13,
2487,
26,
469,
585,
6834,
16904,
469,
600,
93,
465,
9052,
24059,
17370,
14,
1743,
199,
28,
1073,
4668,
628,
1431,
2,
4369,
628,
505,
13,
28907,
13,
2487,
13,
1829,
24185,
1080,
26,
1644,
17063,
1121,
14,
1360,
1743,
199,
28,
80,
30,
4986,
340,
2337,
365,
282,
5041,
1560,
6834,
3432,
4036,
4528,
5084,
9919,
80,
30,
199,
28,
3015,
3449,
628,
604,
13,
3333,
26,
959,
27,
1318,
13,
28907,
13,
2487,
26,
469,
585,
93,
1743,
165,
103,
100,
166,
102,
242,
5692,
229,
25111,
23869,
1108,
3015,
30,
199,
2344,
199,
199,
8279,
63,
3817,
275,
283,
505,
13,
28907,
13,
2487,
13,
1829,
24185,
26,
1644,
17063,
1121,
14,
1360,
7,
199,
8279,
63,
7433,
275,
1449,
11230,
16556,
3517,
30,
199,
28,
2024,
5960,
628,
1624,
13,
24,
1743,
199,
28,
1213,
30,
14391,
10944,
26,
1318,
13,
28907,
13,
2487,
26,
469,
16,
17890,
1213,
30,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
56,
344,
6161,
5843,
290,
2,
4369,
628,
2859,
921,
1544,
14,
384,
4792,
14,
1308,
1743,
199,
28,
1073,
4668,
628,
2502,
2,
2538,
628,
22285,
2,
4369,
628,
2859,
921,
1544,
14,
12102,
14,
1308,
1743,
199,
28,
2487,
30,
14059,
8448,
5023,
13,
8759,
13,
14346,
13,
305,
5653,
26,
8287,
27,
3586,
3068,
2487,
30,
199,
28,
80,
30,
4986,
340,
2337,
365,
282,
5041,
17,
6834,
3432,
4036,
4528,
5084,
9919,
80,
30,
199,
28,
3015,
3449,
628,
604,
13,
3333,
26,
959,
27,
8186,
21952,
30,
165,
103,
100,
28,
2591,
22266,
17,
17890,
2591,
30,
166,
102,
242,
28,
2591,
22266,
17,
17890,
2591,
30,
5692,
229,
28,
2591,
22266,
17,
17890,
2591,
30,
25111,
28,
2591,
22266,
17,
17890,
2591,
30,
23869,
28,
2591,
22266,
17,
17890,
2591,
2957,
21952,
2957,
3015,
30,
199,
2344,
199,
199,
3998,
63,
3597,
275,
359,
267,
661,
3287,
297,
3698,
378,
88,
13859,
12,
378,
88,
821,
69,
22,
395,
267,
661,
11001,
297,
263,
378,
88,
821,
2177,
12,
378,
88,
821,
2894,
395,
267,
661,
3157,
13,
11001,
297,
378,
88,
821,
67,
25,
12,
378,
88,
821,
301,
395,
267,
661,
21584,
297,
420,
378,
88,
821,
66,
18,
12,
378,
88,
821,
66,
19,
395,
267,
661,
874,
313,
297,
263,
378,
8371,
2322,
12,
378,
8371,
2466,
395,
267,
1622,
199,
199,
12273,
654,
275,
18179,
283,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
418,
199,
199,
318,
664,
63,
1360,
63,
4502,
8,
600,
304,
272,
372,
7673,
3,
88,
28476,
966,
56,
12084,
1370,
908,
8,
600,
9,
199,
199,
318,
2218,
63,
493,
8,
1501,
12,
1564,
304,
272,
543,
1551,
8,
1501,
12,
283,
6603,
358,
465,
289,
26,
267,
289,
14,
952,
8,
1317,
14,
2143,
360,
6610,
13,
24,
1333,
199,
199,
318,
2218,
63,
396,
63,
493,
8,
2996,
12,
4739,
12,
3449,
12,
1233,
12,
536,
29,
403,
304,
272,
340,
440,
536,
26,
267,
536,
275,
3449,
272,
1788,
275,
7393,
63,
3817,
14,
908,
8,
2996,
12,
4739,
9,
272,
2218,
63,
493,
8,
1501,
12,
7393,
63,
7433,
14,
908,
8,
1080,
29,
2996,
12,
574,
29,
2487,
12,
6343,
1495,
29,
362,
63,
1360,
63,
4502,
8,
600,
395,
6343,
1233,
534,
53,
11,
28476,
966,
56,
5285,
908,
8,
600,
395,
6343,
2538,
29,
354,
430,
272,
870,
480,
389,
1052,
8352,
908,
8,
1501,
12,
5363,
38,
63,
3817,
14,
908,
8,
2996,
1724,
199,
199,
2996,
275,
1616,
199,
318,
2218,
63,
1725,
8,
2487,
12,
1233,
304,
272,
2288,
4280,
272,
4280,
847,
413,
272,
5554,
12,
2215,
275,
3449,
272,
5678,
63,
2487,
275,
11491,
8352,
908,
8,
4498,
12,
2215,
9,
272,
2218,
63,
493,
8,
8279,
63,
3817,
14,
908,
8,
2996,
395,
2049,
5363,
38,
63,
7433,
14,
908,
8,
4316,
63,
2487,
12,
664,
63,
1360,
63,
4502,
8,
600,
1724,
272,
4739,
275,
2740,
8,
12273,
654,
9,
272,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
5678,
63,
2487,
12,
1233,
9,
272,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
11491,
8352,
908,
8,
1392,
12,
5554,
395,
1233,
9,
272,
340,
5554,
508,
283,
17647,
356,
267,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
2215,
12,
1233,
9,
272,
340,
2215,
508,
283,
11001,
356,
267,
2218,
63,
396,
63,
493,
8,
2996,
12,
2163,
8,
4511,
395,
5554,
12,
1233,
12,
5554,
435,
1656,
17528,
358,
199,
199,
1361,
10064,
13910,
2295,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ybayle/ReproducibleResearchIEEE2017
|
src/svmbff.py
|
1
|
22789
|
# -*- coding: utf-8 -*-
#!/usr/bin/python
#
# Author Yann Bayle
# E-mail bayle.yann@live.fr
# License MIT
# Created 13/10/2016
# Updated 20/01/2017
# Version 1.0.0
#
"""
Description of svmbff.py
======================
bextract -mfcc -zcrs -ctd -rlf -flx -ws 1024 -as 898 -sv -fe filename.mf -w out.arff
:Example:
python svmbff.py
"""
import os
import csv
import sys
import time
import utils
import shutil
import argparse
import multiprocessing
from statistics import stdev
from scipy.io import arff
from sklearn.metrics import precision_recall_curve, precision_score, recall_score, classification_report, f1_score, accuracy_score
begin = int(round(time.time() * 1000))
def validate_arff(filename):
"""Description of validate_arff
Check if filename exists on path and is a file
If file corresponds to valid arff file return absolute path
Otherwise move file to invalid directory and return False
"""
# Check if file exists
if os.path.isfile(filename) and os.path.exists(filename):
filename = os.path.abspath(filename)
else:
return False
# If does not satisfy min size, move to "empty" folder
if os.stat(filename).st_size < 8100:
tmp_path = filename.split("/")
empty_dirname = "/".join(tmp_path[:-1]) + "/empty/"
if not os.path.exists(empty_dirname):
os.makedirs(empty_dirname)
shutil.move(filename, empty_dirname + tmp_path[-1])
return False
# # If filename does not match with feature name, move to "invalid" folder
# name_file = filename.split("/")[-1][:12]
# with open(filename) as filep:
# for i, line in enumerate(filep):
# if i == 70:
# # 71th line
# name_feat = line.split(" ")[2][1:13]
# break
# if name_file != name_feat:
# tmp_path = filename.split("/")
# invalid_dirname = "/".join(tmp_path[:-1]) + "/invalid/"
# if not os.path.exists(invalid_dirname):
# os.makedirs(invalid_dirname)
# shutil.move(filename, invalid_dirname + tmp_path[-1])
# return False
# If everything went well, return filename absolute path
return filename
def merge_arff(indir, outfilename):
"""Description of merge_arff
bextract program from Marsyas generate one output file per audio file
This function merge them all in one unique file
Check if analysed file are valid i.e. not empty
"""
utils.print_success("Preprocessing ARFFs")
indir = utils.abs_path_dir(indir)
filenames = os.listdir(indir)
outfn = open(outfilename, 'w')
cpt_invalid_fn = 0
# Write first lines of ARFF template file
for filename in filenames:
if os.path.isfile(indir + filename):
new_fn = validate_arff(indir + filename)
if new_fn:
with open(new_fn, 'r') as template:
nb_line = 74
for line in template:
if not nb_line:
break
nb_line -= 1
outfn.write(line)
break
else:
cpt_invalid_fn += 1
# Append all arff file to the output file
cur_file_num = 1
for filename in filenames:
if os.path.isfile(indir + filename):
new_fn = validate_arff(indir + filename)
if new_fn:
cur_file_num = cur_file_num + 1
utils.print_progress_start("Analysing file\t" + str(cur_file_num))
fname = open(new_fn, 'r')
outfn.write("".join(fname.readlines()[74:77]))
fname.close()
else:
cpt_invalid_fn += 1
utils.print_progress_end()
outfn.close()
# os.system("rm " + indir + "*.arff")
if cpt_invalid_fn:
utils.print_warning(str(cpt_invalid_fn) + " ARFF files with errors found")
return outfilename
def add_groundtruth(feature_fn, groundtruth_fn, output_fn):
"""Description of add_groundtruth
Write in output filename the groundtruth merged with corresponding features
..todo:: Error with old_tag not corresponding to filename...
"""
utils.print_success("Adding groundtruth")
feature_fn = utils.abs_path_file(feature_fn)
groundtruth_fn = utils.abs_path_file(groundtruth_fn)
if os.path.isfile(output_fn) and os.path.exists(output_fn):
utils.print_warning("Overwritting existing output file: " +
utils.abs_path_file(output_fn))
# TODO Read groundtruth file in memory
tmp_gt = csv.reader(open(groundtruth_fn, "r"))
groundtruths = {}
for row in tmp_gt:
groundtruths[row[0]] = row[1]
tags = []
output = open(output_fn, "w")
# switch if test set preprocessing
# separator = "_"
separator = "."
with open(feature_fn, "r") as feat:
line_num = 0
tmp_line = ""
for line in feat:
line_num += 1
if line_num > 74:
if line[0] != "%":
# Alter feature line with correct tag
cur_line = line.split(",")
old_tag = cur_line[-1].split(separator)[0]
if old_tag in groundtruths:
new_tag = groundtruths[old_tag]
output.write(tmp_line + ",".join(cur_line[:-1]) + "," + new_tag +"\n")
tmp_line = ""
tags.append(new_tag)
else:
# TODO
# File not in groundtruth
tmp_line = ""
# utils.print_warning("Error with " + old_tag)
else:
tmp_line += line
elif line_num == 2:
output.write("@relation train_test.arff\n")
# output.write("@relation MARSYAS_KEA\n")
elif line_num == 71:
# Alter line 71 containing all tag gathered along the way
# TODO enhance
output.write("@attribute output {i,s}\n")
else:
# Write header
output.write(line)
output.close()
def split_number(number, nb_folds):
"""Description of split_number
Return an int array of size nb_folds where the sum of cells = number
All the integers in cells are the same +-1
"""
if not isinstance(number, int) and not isinstance(nb_folds, int):
utils.print_error("Variable must be integer")
if number < nb_folds:
utils.print_error("Number of folds > Number of data available")
min_num = int(number/nb_folds)
folds = [min_num] * nb_folds
for num in range(0, number-(min_num*nb_folds)):
folds[num] = folds[num] + 1
return folds
def create_folds(filelist, nb_folds, folds_dir, invert_train_test=False):
"""Description of create_folds
"""
utils.print_success("Creating folds")
if nb_folds < 1:
utils.print_error("Wrong number of folds provided")
# folds_dir = "/".join(filelist.split("/")[:-1])
if nb_folds == 1:
# Train and test set are the same
folds_dir = folds_dir + "01_fold/"
utils.create_dir(folds_dir)
os.system("cp " + filelist + " " + folds_dir + "/train_test.arff")
else:
# Create train and test set
folds_dir = folds_dir + str(nb_folds).zfill(2) + "_folds/"
utils.create_dir(folds_dir)
# TODO
# Read filelist
# Extract name and tag
# Separate different tag
# create folds
data, meta = arff.loadarff(filelist)
tags = {}
for row in data:
tag = row[-1].decode("ascii")
if tag in tags:
tags[tag] += 1
else:
tags[tag] = 1
tags_folds = {}
tags_folds_index = {}
for tag in tags:
tags_folds[tag] = split_number(tags[tag], nb_folds)
tags_folds_index[tag] = 0
# Create empty folds
folds = {}
# Init empty folds
for index in range(0, nb_folds):
folds[index] = ""
# Fill folds with data
with open(filelist, "r") as filelist_pointer:
arff_header = ""
tmp = ""
for i, line in enumerate(filelist_pointer):
utils.print_progress_start("\t" + str(i))
# Until the 75th line
if i > 74:
# Process ARFF data
if "% " in line:
# Memorize line
tmp += line
else:
# Get line 3 and add it to corresponding fold
tag = line.split(",")[-1][:-1]
num_fold = tags_folds_index[tag]
if tags_folds[tag][num_fold] == 0:
tags_folds_index[tag] += 1
tags_folds[tag][tags_folds_index[tag]] -= 1
folds[tags_folds_index[tag]] += tmp + line
tmp = ""
else:
# Save ARFF header lines
arff_header += line
utils.print_progress_end
# At this point data has been split up in different part
# Use this part to create train/test split
if invert_train_test:
# Test is bigger than train
fn_with_min_data = "/train_"
fn_with_max_data = "/test_"
else:
# Train is bigger than test
fn_with_min_data = "/test_"
fn_with_max_data = "/train_"
for index_test in range(0, nb_folds):
filep = open(folds_dir + fn_with_min_data + str(index_test+1).zfill(2) + ".arff", "a")
filep.write(arff_header + folds[index_test])
filep.close()
filep = open(folds_dir + fn_with_max_data + str(index_test+1).zfill(2) + ".arff", "a")
filep.write(arff_header)
for index_train in range(0, nb_folds):
if index_train != index_test:
filep.write(folds[index_train])
filep.close()
return folds_dir
def process_results(in_fn, out_fn):
in_fn = utils.abs_path_file(in_fn)
out_fp = open(out_fn, "w")
with open(in_fn, "r") as filep:
for index, line in enumerate(filep):
if index % 2:
row = line[:-1].split("\t")
out_fp.write(row[0].split("_")[0] + "," + row[2] + "\n")
out_fp.close()
def experiment_2_3():
process_results("src/tmp/svmbff/SVMBFF.csv", "predictions/SVMBFF.csv")
def run_kea(train_file, test_file, out_file, verbose=False):
"""Description of run_kea
Launch kea classification on specified file
"""
kea_cmd = 'kea -m tags -w ' + train_file + ' -tw ' + test_file + ' -pr ' + out_file
if not verbose:
kea_cmd += "> /dev/null 2>&1"
os.system(kea_cmd)
train_dir = train_file.split(os.sep)
train_dir = os.sep.join(train_dir[:-1])
# os.system("rm " + train_dir + "/*affinities*")
test_dir = test_file.split(os.sep)
test_dir = os.sep.join(test_dir[:-1])
# os.system("rm " + test_dir + "/*affinities*")
def run_kea_on_folds(folds_dir):
"""Description of run_kea_on_folds
Wrapper for kea on folds
"""
folds_dir = utils.abs_path_dir(folds_dir)
out_file = folds_dir + "/results.txt"
if os.path.exists(folds_dir + "/train_test.arff"):
train_file = folds_dir + "/train_test.arff"
test_file = train_file
run_kea(train_file, test_file, out_file)
else:
nb_folds = len([name for name in os.listdir(folds_dir) if os.path.isfile(os.path.join(folds_dir, name))])
# Run on multiple train/test
for index in range(1, int(nb_folds/2)+1):
utils.print_progress_start("Train/Test on fold " + str(index))
train_file = folds_dir + "/train_" + str(index).zfill(2) + ".arff"
test_file = folds_dir + "/test_" + str(index).zfill(2) + ".arff"
out_file = folds_dir + "/results_" + str(index).zfill(2) + ".arff"
run_kea(train_file, test_file, out_file)
utils.print_progress_end()
utils.print_warning("TODO multiprocessing")
# # Parallel computing on each TrainTestFolds
# printTitle("Parallel train & test of folds")
# partialRunTrainTestOnFold = partial(runTrainTestOnFold, args=args)
# pool = multiprocessing.Pool()
# pool.map(partialRunTrainTestOnFold, range(nb_folds)) #make our results with a map call
# pool.close() #we are not adding any more processes
# pool.join() #tell it to wait until all threads are done before going on
def extract_feat_train():
dirs = ["/media/sf_SharedFolder/DataSets/Jamendo/Yann/song/",
"/media/sf_SharedFolder/DataSets/ccmixter_corpus/instru/",
"/media/sf_SharedFolder/DataSets/MedleyDB/MedleyDB/instru/vrai/"]
outdir= "res/"
for indir in dirs:
extensions = ["wav", "mp3"]
filenames = [fn for fn in os.listdir(indir)
if any(fn.endswith(ext) for ext in extensions)]
for index, filename in enumerate(filenames):
dirName = indir.split("/")[-2] + ".mf"
with open(dirName, "w") as filep:
filep.write(indir + filename + "\n")
outfilename = outdir + filename[:-3].replace(" ", "_") + "arff"
bextract_cmd = "bextract -mfcc -zcrs -ctd -rlf -flx -ws 1024 -as 898 -sv -fe " + dirName + " -w " + outfilename
os.system(bextract_cmd)
def read_gts(filename):
filename = utils.abs_path_file(filename)
groundtruths = {}
i = 0
with open(filename, "r") as filep:
for index, line in enumerate(filep):
if index > 73:
if i == 0:
i += 1
name = line.split("/")[-1][:-1]
elif i == 1:
i += 1
elif i == 2:
i = 0
groundtruths[name] = line.split(",")[-1][:-1]
return groundtruths
def read_preds(filename):
pres_filen = utils.abs_path_file(filename)
predictions = {}
i = 0
with open(filename, "r") as filep:
for index, line in enumerate(filep):
if index % 2:
line = line.split("\t")
name = line[0].split("/")[-1]
pred = float(line[-1])
if pred > 0.5:
predictions[name] = "s"
else:
predictions[name] = "i"
return predictions
def figure2():
# folds_dir = create_folds("results/dataset.arff", 5)
# run_kea_on_folds(folds_dir)
# read results arff file and print accuracy and f-measure
gts_filen = "results/dataset.arff"
gts = read_gts(gts_filen)
folds_dir = "results/05_folds/"
res_files = [name for name in os.listdir(folds_dir) if os.path.isfile(os.path.join(folds_dir, name)) and "results" in name]
acc = []
f1 = []
for res in res_files:
predictions = []
groundtruths = []
preds = read_preds(folds_dir + res)
for name in preds:
if name in gts:
groundtruths.append(gts[name])
predictions.append(preds[name])
acc.append(accuracy_score(groundtruths, predictions))
predictions = [1 if i=="s" else 0 for i in predictions]
groundtruths = [1 if i=="s" else 0 for i in groundtruths]
f1.append(f1_score(groundtruths, predictions, average='weighted'))
# Print average ± standard deviation
print("Accuracy " + str(sum(acc)/float(len(acc))) + " ± " + str(stdev(acc)))
print("F-Measure " + str(sum(f1)/float(len(f1))) + " ± " + str(stdev(f1)))
dir_stats = utils.create_dir("stats/")
with open(dir_stats + "table1_accuracy.csv", "a") as filep:
filep.write("SVMBFF")
for val in acc:
filep.write("," + str(val))
filep.write("\n")
with open(dir_stats + "table1_f1.csv", "a") as filep:
filep.write("SVMBFF")
for val in f1:
filep.write("," + str(val))
filep.write("\n")
# with open(dir_stats + "table1_accuracy.csv", "a") as filep:
# for val in acc:
# filep.write("SVMBFF," + str(val) + "\n")
# with open(dir_stats + "table1_f1.csv", "a") as filep:
# for val in f1:
# filep.write("SVMBFF," + str(val) + "\n")
def extract_features(tracks_dir="tracks/", feat_dir="features/"):
utils.print_success("Extracting features")
tracks_fn = os.listdir(tracks_dir)
utils.create_dir(feat_dir)
feat_dir = utils.create_dir(feat_dir + "svmbff")
bextract = "bextract -mfcc -zcrs -ctd -rlf -flx -ws 1024 -as 898 -sv -fe "
for index, filename in enumerate(tracks_fn):
utils.print_progress_start(str(index) + "/" + str(len(tracks_fn)) + " " + filename)
track_path = filename + ".mf"
with open(track_path, "w") as filep:
filep.write(tracks_dir + filename + "\n")
new_fn = filename.split(".")[0] + ".arff"
try:
os.system(bextract + track_path + " -w " + new_fn + "> /dev/null 2>&1")
except:
utils.print_info("You have to make marsyas available systemwide, tips:")
utils.print_info("http://marsyas.info/doc/manual/marsyas-user/Step_002dby_002dstep-building-instructions.html#Step_002dby_002dstep-building-instructions")
utils.print_info("http://stackoverflow.com/a/21173918")
utils.print_error("Program exit")
# print(new_fn)
# print(feat_dir + " " + new_fn)
os.rename(new_fn, feat_dir + new_fn)
# os.rename("MARSYAS_EMPTY" + new_fn, feat_dir + new_fn)
os.system("rm " + track_path)
utils.print_progress_end()
os.system("rm bextract_single.mf")
def table1_exp1(folds_dir):
utils.print_success("Experiment 1 in Table 1")
fn_gts = "groundtruths/database1.csv"
gts = utils.read_groundtruths(fn_gts)
res_files = [name for name in os.listdir(folds_dir) if os.path.isfile(os.path.join(folds_dir, name)) and "results" in name]
acc = []
f1 = []
for res in res_files:
predictions = []
groundtruths = []
preds = read_preds(folds_dir + res)
for name in preds:
name_gts = name.split(".")[0]
if name_gts in gts:
groundtruths.append(gts[name_gts])
predictions.append(preds[name])
acc.append(accuracy_score(groundtruths, predictions))
predictions = [1 if i=="s" else 0 for i in predictions]
groundtruths = [1 if i=="s" else 0 for i in groundtruths]
f1.append(f1_score(groundtruths, predictions, average='binary'))
# Print average ± standard deviation
utils.print_info("Accuracy " + str(sum(acc)/float(len(acc))) + " ± " + str(stdev(acc)))
utils.print_info("F-Measure " + str(sum(f1)/float(len(f1))) + " ± " + str(stdev(f1)))
dir_res = utils.create_dir("stats/")
with open(dir_res + "table1_accuracy.csv", "a") as filep:
for val in acc:
filep.write("SVMBFF," + str(val) + "\n")
with open(dir_res + "table1_f1.csv", "a") as filep:
for val in f1:
filep.write("SVMBFF," + str(val) + "\n")
def experiment_1(folder="."):
utils.print_success("SVMBFF Experiment 1 (approx. 1 minutes)")
# Variables
folder = utils.abs_path_dir(folder)
dir_tmp = utils.create_dir(folder + "src/tmp/")
dir_svmbff = utils.create_dir(dir_tmp + "svmbff/")
dir_tracks = folder + "tracks/"
dir_feat = folder + "features/svmbff/"
fn_feats_db1 = dir_svmbff + "svmbff_database1.arff"
feats_gts_db1 = folder + "features/" + "svmbff_database1.arff"
groundtruths = folder + "groundtruths/database1.csv"
extract_features(dir_tracks)
merge_arff(dir_feat, fn_feats_db1)
add_groundtruth(fn_feats_db1, groundtruths, feats_gts_db1)
os.remove(fn_feats_db1)
dir_folds = create_folds(feats_gts_db1, 5, dir_svmbff)
run_kea_on_folds(dir_folds)
table1_exp1(dir_folds)
def main():
utils.print_success("SVMBFF (approx. 2 minutes)")
experiment_1(folder="../")
if __name__ == "__main__":
PARSER = argparse.ArgumentParser(description="Validate list of ISRCs")
PARSER.add_argument(
"-i",
"--input_dir",
help="input directory containing all ARFF file from Marsyas bextract",
type=str,
default="data",
metavar="input_dir")
PARSER.add_argument(
"-o",
"--output_file",
help="output file",
type=str,
default="feat_with_groundtruth.txt",
metavar="output_file")
PARSER.add_argument(
"-g",
"--groundtruth_file",
help="groundtruth file",
type=str,
default="groundtruth.txt",
metavar="groundtruth_file")
PARSER.add_argument(
"-n",
"--nb_folds",
default=1,
type=int,
metavar="nb_folds",
help="classification folds number, must be >= 1, default = 1")
main()
# figure2()
# indir1 = "res/"
# indir2 = "/media/sf_DATA/Datasets/Simbals/new/201611/arff/"
# merge_arff(indir2, "test2.arff")
# utils.print_success("Kea classification")
# # Variable declaration
# input_dir = PARSER.parse_args().input_dir
# res_dir = "analysis"
# utils.create_dir(res_dir)
# if input_dir[-1] == "/":
# input_dir = input_dir[:-1]
# proj_dir = res_dir + "/" + input_dir.split("/")[-1]
# utils.create_dir(proj_dir)
# feat_without_groundtruth = proj_dir + "/feat_without_groundtruth.arff"
# feat_with_groundtruth = proj_dir + "/" + PARSER.parse_args().output_file
# # Functions call
# merge_arff(input_dir, feat_without_groundtruth)
# add_groundtruth(feat_without_groundtruth,
# PARSER.parse_args().groundtruth_file,
# feat_with_groundtruth)
# os.remove(feat_without_groundtruth)
# folds_dir = create_folds(feat_with_groundtruth, PARSER.parse_args().nb_folds, invert_train_test=True)
# folds_dir = create_folds("results/train_kea.arff", 5)
# run_kea_on_folds(folds_dir)
# # 2 merge all arff files dans train/test file (generate train/test folds/set,
# # reuse vqmm) à partir des fichiers sources d'un autre dossier, tout copier
# # dans dossier de svmbff. no-overlap train/Test
# # 3 lancer kea sur toutes les train/test
# # 4 Afficher les résultats
# utils.print_success("Finished in " + str(int(round(time.time() * 1000)) - begin) + "ms")
# """
# kea -m tags -w ' + train_file + ' -tw ' + test_file + ' -pr ' + out_file
# """
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
6529,
259,
1488,
1189,
29434,
274,
199,
3,
662,
13,
1198,
259,
30933,
274,
14,
89,
1189,
32,
6442,
14,
4391,
199,
3,
844,
257,
10697,
199,
3,
18208,
257,
4944,
15,
709,
15,
9261,
199,
3,
6162,
68,
257,
3388,
15,
614,
15,
10680,
199,
3,
3394,
257,
413,
14,
16,
14,
16,
199,
3,
199,
199,
624,
199,
5831,
402,
19291,
887,
556,
14,
647,
199,
1280,
23476,
199,
199,
66,
5005,
446,
11821,
2055,
446,
90,
19034,
446,
319,
68,
446,
82,
276,
446,
2327,
88,
446,
3569,
6619,
446,
305,
221,
13176,
446,
2772,
446,
771,
1788,
14,
11821,
446,
87,
734,
14,
285,
556,
199,
199,
26,
9846,
26,
199,
199,
1548,
19291,
887,
556,
14,
647,
199,
624,
199,
199,
646,
747,
199,
646,
7392,
199,
646,
984,
199,
646,
900,
199,
646,
3778,
199,
646,
5145,
199,
646,
7534,
199,
646,
12866,
199,
504,
11076,
492,
410,
2374,
199,
504,
7026,
14,
2308,
492,
601,
556,
199,
504,
6357,
14,
6759,
492,
7151,
63,
19183,
63,
11895,
12,
7151,
63,
3397,
12,
26174,
63,
3397,
12,
12505,
63,
3070,
12,
289,
17,
63,
3397,
12,
12862,
63,
3397,
199,
199,
5037,
275,
1109,
8,
2363,
8,
521,
14,
521,
342,
627,
5198,
430,
199,
199,
318,
4107,
63,
285,
556,
8,
1501,
304,
272,
408,
5831,
402,
4107,
63,
285,
556,
339,
2670,
340,
1788,
3495,
641,
931,
436,
365,
282,
570,
272,
982,
570,
13718,
370,
1686,
601,
556,
570,
372,
3679,
931,
272,
6630,
4057,
570,
370,
3866,
2082,
436,
372,
756,
272,
408,
272,
327,
2670,
340,
570,
3495,
272,
340,
747,
14,
515,
14,
6292,
8,
1501,
9,
436,
747,
14,
515,
14,
2444,
8,
1501,
304,
267,
1788,
275,
747,
14,
515,
14,
4832,
8,
1501,
9,
272,
587,
26,
267,
372,
756,
272,
327,
982,
1630,
440,
23082,
1748,
1568,
12,
4057,
370,
298,
1667,
2,
4922,
272,
340,
747,
14,
3736,
8,
1501,
680,
270,
63,
890,
665,
1695,
1960,
26,
267,
3529,
63,
515,
275,
1788,
14,
1294,
19031,
267,
2701,
63,
3475,
275,
3286,
1674,
904,
8,
2791,
63,
515,
4439,
17,
566,
435,
3286,
1667,
6687,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1667,
63,
3475,
304,
288,
747,
14,
8347,
8,
1667,
63,
3475,
9,
267,
5145,
14,
1185,
8,
1501,
12,
2701,
63,
3475,
435,
3529,
63,
515,
1988,
17,
566,
267,
372,
756,
272,
327,
327,
982,
1788,
1630,
440,
1336,
543,
3878,
536,
12,
4057,
370,
298,
3197,
2,
4922,
272,
327,
536,
63,
493,
275,
1788,
14,
1294,
19031,
1988,
17,
19663,
713,
61,
272,
327,
543,
1551,
8,
1501,
9,
465,
570,
80,
26,
272,
327,
258,
367,
284,
12,
1004,
315,
3874,
8,
493,
80,
304,
272,
327,
260,
340,
284,
508,
10045,
26,
272,
327,
3777,
327,
17245,
273,
1004,
272,
327,
3777,
536,
63,
11873,
275,
1004,
14,
1294,
480,
298,
2788,
18,
1527,
17,
26,
969,
61,
272,
327,
3777,
2059,
272,
327,
340,
536,
63,
493,
1137,
536,
63,
11873,
26,
272,
327,
258,
3529,
63,
515,
275,
1788,
14,
1294,
19031,
272,
327,
258,
3866,
63,
3475,
275,
3286,
1674,
904,
8,
2791,
63,
515,
4439,
17,
566,
435,
3286,
3197,
6687,
272,
327,
258,
340,
440,
747,
14,
515,
14,
2444,
8,
3197,
63,
3475,
304,
272,
327,
260,
747,
14,
8347,
8,
3197,
63,
3475,
9,
272,
327,
258,
5145,
14,
1185,
8,
1501,
12,
3866,
63,
3475,
435,
3529,
63,
515,
1988,
17,
566,
272,
327,
258,
372,
756,
272,
327,
982,
8137,
22396,
5521,
12,
372,
1788,
3679,
931,
272,
372,
1788,
199,
199,
318,
5389,
63,
285,
556,
8,
262,
694,
12,
734,
1501,
304,
272,
408,
5831,
402,
5389,
63,
285,
556,
339,
506,
400,
1957,
2240,
687,
16794,
1786,
305,
3550,
1373,
1072,
570,
1126,
10491,
570,
272,
961,
805,
5389,
3062,
1006,
315,
1373,
3747,
570,
272,
2670,
340,
5909,
939,
570,
787,
1686,
284,
14,
69,
14,
440,
2701,
272,
408,
272,
3778,
14,
1361,
63,
3742,
480,
2398,
6338,
4160,
1665,
83,
531,
272,
315,
694,
275,
3778,
14,
2101,
63,
515,
63,
694,
8,
262,
694,
9,
272,
6203,
275,
747,
14,
7374,
8,
262,
694,
9,
272,
734,
2324,
275,
1551,
8,
548,
1501,
12,
283,
87,
358,
272,
286,
541,
63,
3197,
63,
2324,
275,
378,
272,
327,
6990,
1642,
2385,
402,
4160,
1665,
1978,
570,
272,
367,
1788,
315,
6203,
26,
267,
340,
747,
14,
515,
14,
6292,
8,
262,
694,
435,
1788,
304,
288,
892,
63,
2324,
275,
4107,
63,
285,
556,
8,
262,
694,
435,
1788,
9,
288,
340,
892,
63,
2324,
26,
355,
543,
1551,
8,
1222,
63,
2324,
12,
283,
82,
358,
465,
1978,
26,
490,
8526,
63,
604,
275,
9720,
490,
367,
1004,
315,
1978,
26,
717,
340,
440,
8526,
63,
604,
26,
1169,
2059,
717,
8526,
63,
604,
4862,
413,
717,
734,
2324,
14,
952,
8,
604,
9,
490,
2059,
288,
587,
26,
355,
286,
541,
63,
3197,
63,
2324,
847,
413,
272,
327,
18726,
1006,
601,
556,
570,
370,
314,
1072,
570,
272,
1094,
63,
493,
63,
1507,
275,
413,
272,
367,
1788,
315,
6203,
26,
267,
340,
747,
14,
515,
14,
6292,
8,
262,
694,
435,
1788,
304,
288,
892,
63,
2324,
275,
4107,
63,
285,
556,
8,
262,
694,
435,
1788,
9,
288,
340,
892,
63,
2324,
26,
355,
1094,
63,
493,
63,
1507,
275,
1094,
63,
493,
63,
1507,
435,
413,
355,
3778,
14,
1361,
63,
5734,
63,
928,
480,
2493,
279,
588,
316,
570,
60,
84,
2,
435,
620,
8,
895,
63,
493,
63,
1507,
430,
355,
6748,
275,
1551,
8,
1222,
63,
2324,
12,
283,
82,
358,
355,
734,
2324,
14,
952,
31059,
904,
8,
5252,
14,
9684,
3430,
1342,
26,
1138,
2459,
355,
6748,
14,
1600,
342,
288,
587,
26,
355,
286,
541,
63,
3197,
63,
2324,
847,
413,
272,
3778,
14,
1361,
63,
5734,
63,
500,
342,
272,
734,
2324,
14,
1600,
342,
272,
327,
747
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
6529,
259,
1488,
1189,
29434,
274,
199,
3,
662,
13,
1198,
259,
30933,
274,
14,
89,
1189,
32,
6442,
14,
4391,
199,
3,
844,
257,
10697,
199,
3,
18208,
257,
4944,
15,
709,
15,
9261,
199,
3,
6162,
68,
257,
3388,
15,
614,
15,
10680,
199,
3,
3394,
257,
413,
14,
16,
14,
16,
199,
3,
199,
199,
624,
199,
5831,
402,
19291,
887,
556,
14,
647,
199,
1280,
23476,
199,
199,
66,
5005,
446,
11821,
2055,
446,
90,
19034,
446,
319,
68,
446,
82,
276,
446,
2327,
88,
446,
3569,
6619,
446,
305,
221,
13176,
446,
2772,
446,
771,
1788,
14,
11821,
446,
87,
734,
14,
285,
556,
199,
199,
26,
9846,
26,
199,
199,
1548,
19291,
887,
556,
14,
647,
199,
624,
199,
199,
646,
747,
199,
646,
7392,
199,
646,
984,
199,
646,
900,
199,
646,
3778,
199,
646,
5145,
199,
646,
7534,
199,
646,
12866,
199,
504,
11076,
492,
410,
2374,
199,
504,
7026,
14,
2308,
492,
601,
556,
199,
504,
6357,
14,
6759,
492,
7151,
63,
19183,
63,
11895,
12,
7151,
63,
3397,
12,
26174,
63,
3397,
12,
12505,
63,
3070,
12,
289,
17,
63,
3397,
12,
12862,
63,
3397,
199,
199,
5037,
275,
1109,
8,
2363,
8,
521,
14,
521,
342,
627,
5198,
430,
199,
199,
318,
4107,
63,
285,
556,
8,
1501,
304,
272,
408,
5831,
402,
4107,
63,
285,
556,
339,
2670,
340,
1788,
3495,
641,
931,
436,
365,
282,
570,
272,
982,
570,
13718,
370,
1686,
601,
556,
570,
372,
3679,
931,
272,
6630,
4057,
570,
370,
3866,
2082,
436,
372,
756,
272,
408,
272,
327,
2670,
340,
570,
3495,
272,
340,
747,
14,
515,
14,
6292,
8,
1501,
9,
436,
747,
14,
515,
14,
2444,
8,
1501,
304,
267,
1788,
275,
747,
14,
515,
14,
4832,
8,
1501,
9,
272,
587,
26,
267,
372,
756,
272,
327,
982,
1630,
440,
23082,
1748,
1568,
12,
4057,
370,
298,
1667,
2,
4922,
272,
340,
747,
14,
3736,
8,
1501,
680,
270,
63,
890,
665,
1695,
1960,
26,
267,
3529,
63,
515,
275,
1788,
14,
1294,
19031,
267,
2701,
63,
3475,
275,
3286,
1674,
904,
8,
2791,
63,
515,
4439,
17,
566,
435,
3286,
1667,
6687,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
1667,
63,
3475,
304,
288,
747,
14,
8347,
8,
1667,
63,
3475,
9,
267,
5145,
14,
1185,
8,
1501,
12,
2701,
63,
3475,
435,
3529,
63,
515,
1988,
17,
566,
267,
372,
756,
272,
327,
327,
982,
1788,
1630,
440,
1336,
543,
3878,
536,
12,
4057,
370,
298,
3197,
2,
4922,
272,
327,
536,
63,
493,
275,
1788,
14,
1294,
19031,
1988,
17,
19663,
713,
61,
272,
327,
543,
1551,
8,
1501,
9,
465,
570,
80,
26,
272,
327,
258,
367,
284,
12,
1004,
315,
3874,
8,
493,
80,
304,
272,
327,
260,
340,
284,
508,
10045,
26,
272,
327,
3777,
327,
17245,
273,
1004,
272,
327,
3777,
536,
63,
11873,
275,
1004,
14,
1294,
480,
298,
2788,
18,
1527,
17,
26,
969,
61,
272,
327,
3777,
2059,
272,
327,
340,
536,
63,
493,
1137,
536,
63,
11873,
26,
272,
327,
258,
3529,
63,
515,
275,
1788,
14,
1294,
19031,
272,
327,
258,
3866,
63,
3475,
275,
3286,
1674,
904,
8,
2791,
63,
515,
4439,
17,
566,
435,
3286,
3197,
6687,
272,
327,
258,
340,
440,
747,
14,
515,
14,
2444,
8,
3197,
63,
3475,
304,
272,
327,
260,
747,
14,
8347,
8,
3197,
63,
3475,
9,
272,
327,
258,
5145,
14,
1185,
8,
1501,
12,
3866,
63,
3475,
435,
3529,
63,
515,
1988,
17,
566,
272,
327,
258,
372,
756,
272,
327,
982,
8137,
22396,
5521,
12,
372,
1788,
3679,
931,
272,
372,
1788,
199,
199,
318,
5389,
63,
285,
556,
8,
262,
694,
12,
734,
1501,
304,
272,
408,
5831,
402,
5389,
63,
285,
556,
339,
506,
400,
1957,
2240,
687,
16794,
1786,
305,
3550,
1373,
1072,
570,
1126,
10491,
570,
272,
961,
805,
5389,
3062,
1006,
315,
1373,
3747,
570,
272,
2670,
340,
5909,
939,
570,
787,
1686,
284,
14,
69,
14,
440,
2701,
272,
408,
272,
3778,
14,
1361,
63,
3742,
480,
2398,
6338,
4160,
1665,
83,
531,
272,
315,
694,
275,
3778,
14,
2101,
63,
515,
63,
694,
8,
262,
694,
9,
272,
6203,
275,
747,
14,
7374,
8,
262,
694,
9,
272,
734,
2324,
275,
1551,
8,
548,
1501,
12,
283,
87,
358,
272,
286,
541,
63,
3197,
63,
2324,
275,
378,
272,
327,
6990,
1642,
2385,
402,
4160,
1665,
1978,
570,
272,
367,
1788,
315,
6203,
26,
267,
340,
747,
14,
515,
14,
6292,
8,
262,
694,
435,
1788,
304,
288,
892,
63,
2324,
275,
4107,
63,
285,
556,
8,
262,
694,
435,
1788,
9,
288,
340,
892,
63,
2324,
26,
355,
543,
1551,
8,
1222,
63,
2324,
12,
283,
82,
358,
465,
1978,
26,
490,
8526,
63,
604,
275,
9720,
490,
367,
1004,
315,
1978,
26,
717,
340,
440,
8526,
63,
604,
26,
1169,
2059,
717,
8526,
63,
604,
4862,
413,
717,
734,
2324,
14,
952,
8,
604,
9,
490,
2059,
288,
587,
26,
355,
286,
541,
63,
3197,
63,
2324,
847,
413,
272,
327,
18726,
1006,
601,
556,
570,
370,
314,
1072,
570,
272,
1094,
63,
493,
63,
1507,
275,
413,
272,
367,
1788,
315,
6203,
26,
267,
340,
747,
14,
515,
14,
6292,
8,
262,
694,
435,
1788,
304,
288,
892,
63,
2324,
275,
4107,
63,
285,
556,
8,
262,
694,
435,
1788,
9,
288,
340,
892,
63,
2324,
26,
355,
1094,
63,
493,
63,
1507,
275,
1094,
63,
493,
63,
1507,
435,
413,
355,
3778,
14,
1361,
63,
5734,
63,
928,
480,
2493,
279,
588,
316,
570,
60,
84,
2,
435,
620,
8,
895,
63,
493,
63,
1507,
430,
355,
6748,
275,
1551,
8,
1222,
63,
2324,
12,
283,
82,
358,
355,
734,
2324,
14,
952,
31059,
904,
8,
5252,
14,
9684,
3430,
1342,
26,
1138,
2459,
355,
6748,
14,
1600,
342,
288,
587,
26,
355,
286,
541,
63,
3197,
63,
2324,
847,
413,
272,
3778,
14,
1361,
63,
5734,
63,
500,
342,
272,
734,
2324,
14,
1600,
342,
272,
327,
747,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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