Best Python code snippet using playwright-python
ast.py
Source:ast.py
...31 self._children = args32 self.lineno = None33 def __getitem__(self, index):34 return self._children[index]35 def __repr__(self):36 return "<Node %s>" % self._children[0]37 def __len__(self):38 return len(self._children)39 def __getslice__(self, low, high):40 return self._children[low:high]41 def getChildren(self):42 return tuple(flatten(self._children[1:]))43 def getType(self):44 return self._children[0]45 def asList(self):46 return tuple(asList(self._children))47class EmptyNode(Node):48 def __init__(self):49 self.lineno = None50class Module(Node):51 nodes['module'] = 'Module'52 def __init__(self, doc, node):53 self.doc = doc54 self.node = node55 self._children = ('module', doc, node)56 def __repr__(self):57 return "Module(%s,%s)" % self._children[1:]58class Stmt(Node):59 nodes['stmt'] = 'Stmt'60 def __init__(self, nodes):61 self.nodes = nodes62 self._children = ('stmt', nodes)63 def __repr__(self):64 return "Stmt(%s)" % self._children[1:]65class Function(Node):66 nodes['function'] = 'Function'67 def __init__(self, name, argnames, defaults, flags, doc, code):68 self.name = name69 self.argnames = argnames70 self.defaults = defaults71 self.flags = flags72 self.doc = doc73 self.code = code74 self._children = ('function',75 name, argnames, defaults, flags, doc, code)76 self.varargs = self.kwargs = None77 if flags & CO_VARARGS:78 self.varargs = 179 if flags & CO_VARKEYWORDS:80 self.kwargs = 181 82 def __repr__(self):83 return "Function(%s,%s,%s,%s,%s,%s)" % self._children[1:]84class Lambda(Node):85 nodes['lambda'] = 'Lambda'86 def __init__(self, argnames, defaults, flags, code):87 self.argnames = argnames88 self.defaults = defaults89 self.flags = flags90 self.code = code91 self._children = ('lambda', argnames, defaults, flags, code)92 self.varargs = self.kwargs = None93 if flags & CO_VARARGS:94 self.varargs = 195 if flags & CO_VARKEYWORDS:96 self.kwargs = 197 def __repr__(self):98 return "Lambda(%s,%s,%s,%s)" % self._children[1:]99class Class(Node):100 nodes['class'] = 'Class'101 def __init__(self, name, bases, doc, code):102 self.name = name103 self.bases = bases104 self.doc = doc105 self.code = code106 self._children = ('class', name, bases, doc, code)107 def __repr__(self):108 return "Class(%s,%s,%s,%s)" % self._children[1:]109class Pass(EmptyNode):110 nodes['pass'] = 'Pass'111 _children = ('pass',)112 def __repr__(self):113 return "Pass()"114class Break(EmptyNode):115 nodes['break'] = 'Break'116 _children = ('break',)117 def __repr__(self):118 return "Break()"119class Continue(EmptyNode):120 nodes['continue'] = 'Continue'121 _children = ('continue',)122 def __repr__(self):123 return "Continue()"124class For(Node):125 nodes['for'] = 'For'126 def __init__(self, assign, list, body, else_):127 self.assign = assign128 self.list = list129 self.body = body130 self.else_ = else_131 self._children = ('for', assign, list, body, else_)132 def __repr__(self):133 return "For(%s,%s,%s,%s)" % self._children[1:]134class While(Node):135 nodes['while'] = 'While'136 def __init__(self, test, body, else_):137 self.test = test138 self.body = body139 self.else_ = else_140 self._children = ('while', test, body, else_)141 def __repr__(self):142 return "While(%s,%s,%s)" % self._children[1:]143class If(Node):144 """if: [ (testNode, suiteNode), ...], elseNode"""145 nodes['if'] = 'If'146 def __init__(self, tests, else_):147 self.tests = tests148 self.else_ = else_149 self._children = ('if', tests, else_)150 def __repr__(self):151 return "If(%s,%s)" % self._children[1:]152class Exec(Node):153 nodes['exec'] = 'Exec'154 def __init__(self, expr, locals, globals):155 self.expr = expr156 self.locals = locals157 self.globals = globals158 self._children = ('exec', expr, locals, globals)159 def __repr__(self):160 return "Exec(%s,%s,%s)" % self._children[1:]161class From(Node):162 nodes['from'] = 'From'163 def __init__(self, modname, names):164 self.modname = modname165 self.names = names166 self._children = ('from', modname, names)167 def __repr__(self):168 return "From(%s,%s)" % self._children[1:]169class Import(Node):170 nodes['import'] = 'Import'171 def __init__(self, names):172 self.names = names173 self._children = ('import', names)174 def __repr__(self):175 return "Import(%s)" % self._children[1:]176class Raise(Node):177 nodes['raise'] = 'Raise'178 def __init__(self, expr1, expr2, expr3):179 self.expr1 = expr1180 self.expr2 = expr2181 self.expr3 = expr3182 self._children = ('raise', expr1, expr2, expr3)183 def __repr__(self):184 return "Raise(%s,%s,%s)" % self._children[1:]185class TryFinally(Node):186 nodes['tryfinally'] = 'TryFinally'187 def __init__(self, body, final):188 self.body = body189 self.final = final190 self._children = ('tryfinally', body, final)191 def __repr__(self):192 return "TryFinally(%s,%s)" % self._children[1:]193class TryExcept(Node):194 """Try/Except body and handlers195 The handlers attribute is a sequence of tuples. The elements of the196 tuple are the exception name, the name to bind the exception to, and197 the body of the except clause.198 """199 nodes['tryexcept'] = 'TryExcept'200 def __init__(self, body, handlers, else_):201 self.body = body202 self.handlers = handlers203 self.else_ = else_204 self._children = ('tryexcept', body, handlers, else_)205 def __repr__(self):206 return "TryExcept(%s,%s,%s)" % self._children[1:]207class Return(Node):208 nodes['return'] = 'Return'209 def __init__(self, value):210 self.value = value211 self._children = ('return', value)212 def __repr__(self):213 return "Return(%s)" % self._children[1:]214class Const(Node):215 nodes['const'] = 'Const'216 def __init__(self, value):217 self.value = value218 self._children = ('const', value)219 def __repr__(self):220 return "Const(%s)" % self._children[1:]221class Print(Node):222 nodes['print'] = 'Print'223 def __init__(self, nodes, dest):224 self.nodes = nodes225 self.dest = dest226 self._children = ('print', nodes, dest)227 def __repr__(self):228 return "Print(%s, %s)" % (self._children[1:-1], self._children[-1])229class Printnl(Node):230 nodes['printnl'] = 'Printnl'231 def __init__(self, nodes, dest):232 self.nodes = nodes233 self.dest = dest234 self._children = ('printnl', nodes, dest)235 def __repr__(self):236 return "Printnl(%s, %s)" % (self._children[1:-1], self._children[-1])237class Discard(Node):238 nodes['discard'] = 'Discard'239 def __init__(self, expr):240 self.expr = expr241 self._children = ('discard', expr)242 def __repr__(self):243 return "Discard(%s)" % self._children[1:]244class AugAssign(Node):245 nodes['augassign'] = 'AugAssign'246 def __init__(self, node, op, expr):247 self.node = node248 self.op = op249 self.expr = expr250 self._children = ('augassign', node, op, expr)251 def __repr__(self):252 return "AugAssign(%s)" % str(self._children[1:])253class Assign(Node):254 nodes['assign'] = 'Assign'255 def __init__(self, nodes, expr):256 self.nodes = nodes257 self.expr = expr258 self._children = ('assign', nodes, expr)259 def __repr__(self):260 return "Assign(%s,%s)" % self._children[1:]261class AssTuple(Node):262 nodes['ass_tuple'] = 'AssTuple'263 def __init__(self, nodes):264 self.nodes = nodes265 self._children = ('ass_tuple', nodes)266 def __repr__(self):267 return "AssTuple(%s)" % self._children[1:]268class AssList(Node):269 nodes['ass_list'] = 'AssList'270 def __init__(self, nodes):271 self.nodes = nodes272 self._children = ('ass_list', nodes)273 def __repr__(self):274 return "AssList(%s)" % self._children[1:]275class AssName(Node):276 nodes['ass_name'] = 'AssName'277 def __init__(self, name, flags):278 self.name = name279 self.flags = flags280 self._children = ('ass_name', name, flags)281 def __repr__(self):282 return "AssName(%s,%s)" % self._children[1:]283class AssAttr(Node):284 nodes['ass_attr'] = 'AssAttr'285 def __init__(self, expr, attrname, flags):286 self.expr = expr287 self.attrname = attrname288 self.flags = flags289 self._children = ('ass_attr', expr, attrname, flags)290 def __repr__(self):291 return "AssAttr(%s,%s,%s)" % self._children[1:]292class ListComp(Node):293 nodes['listcomp'] = 'ListComp'294 def __init__(self, expr, quals):295 self.expr = expr296 self.quals = quals297 self._children = ('listcomp', expr, quals)298 def __repr__(self):299 return "ListComp(%s, %s)" % self._children[1:]300class ListCompFor(Node):301 nodes['listcomp_for'] = 'ListCompFor'302 # transformer fills in ifs after node is created303 def __init__(self, assign, list, ifs):304 self.assign = assign305 self.list = list306 self.ifs = ifs307 self._children = ('listcomp_for', assign, list, ifs)308 def __repr__(self):309 return "ListCompFor(%s, %s, %s)" % self._children[1:]310class ListCompIf(Node):311 nodes['listcomp_if'] = 'ListCompIf'312 def __init__(self, test):313 self.test = test314 self._children = ('listcomp_if', test)315 def __repr__(self):316 return "ListCompIf(%s)" % self._children[1:]317class List(Node):318 nodes['list'] = 'List'319 def __init__(self, nodes):320 self.nodes = nodes321 self._children = ('list', nodes)322 def __repr__(self):323 return "List(%s)" % self._children[1:]324class Dict(Node):325 nodes['dict'] = 'Dict'326 def __init__(self, items):327 self.items = items328 self._children = ('dict', items)329 def __repr__(self):330 return "Dict(%s)" % self._children[1:]331class Not(Node):332 nodes['not'] = 'Not'333 def __init__(self, expr):334 self.expr = expr335 self._children = ('not', expr)336 def __repr__(self):337 return "Not(%s)" % self._children[1:]338class Compare(Node):339 nodes['compare'] = 'Compare'340 def __init__(self, expr, ops):341 self.expr = expr342 self.ops = ops343 self._children = ('compare', expr, ops)344 def __repr__(self):345 return "Compare(%s,%s)" % self._children[1:]346class Name(Node):347 nodes['name'] = 'Name'348 def __init__(self, name):349 self.name = name350 self._children = ('name', name)351 def __repr__(self):352 return "Name(%s)" % self._children[1:]353class Global(Node):354 nodes['global'] = 'Global'355 def __init__(self, names):356 self.names = names357 self._children = ('global', names)358 def __repr__(self):359 return "Global(%s)" % self._children[1:]360class Backquote(Node):361 nodes['backquote'] = 'Backquote'362 def __init__(self, node):363 self.expr = node364 self._children = ('backquote', node)365 def __repr__(self):366 return "Backquote(%s)" % self._children[1:]367class Getattr(Node):368 nodes['getattr'] = 'Getattr'369 def __init__(self, expr, attrname):370 self.expr = expr371 self.attrname = attrname372 self._children = ('getattr', expr, attrname)373 def __repr__(self):374 return "Getattr(%s,%s)" % self._children[1:]375class CallFunc(Node):376 nodes['call_func'] = 'CallFunc'377 def __init__(self, node, args, star_args = None, dstar_args = None):378 self.node = node379 self.args = args380 self.star_args = star_args381 self.dstar_args = dstar_args382 self._children = ('call_func', node, args, star_args, dstar_args)383 def __repr__(self):384 return "CallFunc(%s,%s,*%s, **%s)" % self._children[1:]385class Keyword(Node):386 nodes['keyword'] = 'Keyword'387 def __init__(self, name, expr):388 self.name = name389 self.expr = expr390 self._children = ('keyword', name, expr)391 def __repr__(self):392 return "Keyword(%s,%s)" % self._children[1:]393class Subscript(Node):394 nodes['subscript'] = 'Subscript'395 def __init__(self, expr, flags, subs):396 self.expr = expr397 self.flags = flags398 self.subs = subs399 self._children = ('subscript', expr, flags, subs)400 def __repr__(self):401 return "Subscript(%s,%s,%s)" % self._children[1:]402class Ellipsis(EmptyNode):403 nodes['ellipsis'] = 'Ellipsis'404 _children = ('ellipsis',)405 def __repr__(self):406 return "Ellipsis()"407class Sliceobj(Node):408 nodes['sliceobj'] = 'Sliceobj'409 def __init__(self, nodes):410 self.nodes = nodes411 self._children = ('sliceobj', nodes)412 def __repr__(self):413 return "Sliceobj(%s)" % self._children[1:]414class Slice(Node):415 nodes['slice'] = 'Slice'416 def __init__(self, expr, flags, lower, upper):417 self.expr = expr418 self.flags = flags419 self.lower = lower420 self.upper = upper421 self._children = ('slice', expr, flags, lower, upper)422 def __repr__(self):423 return "Slice(%s,%s,%s,%s)" % self._children[1:]424class Assert(Node):425 nodes['assert'] = 'Assert'426 def __init__(self, test, fail):427 self.test = test428 self.fail = fail429 self._children = ('assert', test, fail)430 def __repr__(self):431 return "Assert(%s,%s)" % self._children[1:]432class Tuple(Node):433 nodes['tuple'] = 'Tuple'434 def __init__(self, nodes):435 self.nodes = nodes436 self._children = ('tuple', nodes)437 def __repr__(self):438 return "Tuple(%s)" % self._children[1:]439class Or(Node):440 nodes['or'] = 'Or'441 def __init__(self, nodes):442 self.nodes = nodes443 self._children = ('or', nodes)444 def __repr__(self):445 return "Or(%s)" % self._children[1:]446class And(Node):447 nodes['and'] = 'And'448 def __init__(self, nodes):449 self.nodes = nodes450 self._children = ('and', nodes)451 def __repr__(self):452 return "And(%s)" % self._children[1:]453class Bitor(Node):454 nodes['bitor'] = 'Bitor'455 def __init__(self, nodes):456 self.nodes = nodes457 self._children = ('bitor', nodes)458 def __repr__(self):459 return "Bitor(%s)" % self._children[1:]460class Bitxor(Node):461 nodes['bitxor'] = 'Bitxor'462 def __init__(self, nodes):463 self.nodes = nodes464 self._children = ('bitxor', nodes)465 def __repr__(self):466 return "Bitxor(%s)" % self._children[1:]467class Bitand(Node):468 nodes['bitand'] = 'Bitand'469 def __init__(self, nodes):470 self.nodes = nodes471 self._children = ('bitand', nodes)472 def __repr__(self):473 return "Bitand(%s)" % self._children[1:]474class LeftShift(Node):475 nodes['<<'] = 'LeftShift'476 def __init__(self, (left, right)):477 self.left = left478 self.right = right479 self._children = ('<<', (left, right))480 def __repr__(self):481 return "LeftShift(%s)" % self._children[1:]482class RightShift(Node):483 nodes['>>'] = 'RightShift'484 def __init__(self, (left, right)):485 self.left = left486 self.right = right487 self._children = ('>>', (left, right))488 def __repr__(self):489 return "RightShift(%s)" % self._children[1:]490class Add(Node):491 nodes['+'] = 'Add'492 def __init__(self, (left, right)):493 self.left = left494 self.right = right495 self._children = ('+', (left, right))496 def __repr__(self):497 return "Add(%s)" % self._children[1:]498class Sub(Node):499 nodes['-'] = 'Sub'500 def __init__(self, (left, right)):501 self.left = left502 self.right = right503 self._children = ('-', (left, right))504 def __repr__(self):505 return "Sub(%s)" % self._children[1:]506class Mul(Node):507 nodes['*'] = 'Mul'508 def __init__(self, (left, right)):509 self.left = left510 self.right = right511 self._children = ('*', (left, right))512 def __repr__(self):513 return "Mul(%s)" % self._children[1:]514class Div(Node):515 nodes['/'] = 'Div'516 def __init__(self, (left, right)):517 self.left = left518 self.right = right519 self._children = ('/', (left, right))520 def __repr__(self):521 return "Div(%s)" % self._children[1:]522class Mod(Node):523 nodes['%'] = 'Mod'524 def __init__(self, (left, right)):525 self.left = left526 self.right = right527 self._children = ('%', (left, right))528 def __repr__(self):529 return "Mod(%s)" % self._children[1:]530class Power(Node):531 nodes['power'] = 'Power'532 def __init__(self, (left, right)):533 self.left = left534 self.right = right535 self._children = ('power', (left, right))536 def __repr__(self):537 return "Power(%s)" % self._children[1:]538class UnaryAdd(Node):539 nodes['unary+'] = 'UnaryAdd'540 def __init__(self, node):541 self.expr = node542 self._children = ('unary+', node)543 def __repr__(self):544 return "UnaryAdd(%s)" % self._children[1:]545class UnarySub(Node):546 nodes['unary-'] = 'UnarySub'547 def __init__(self, node):548 self.expr = node549 self._children = ('unary-', node)550 def __repr__(self):551 return "UnarySub(%s)" % self._children[1:]552class Invert(Node):553 nodes['invert'] = 'Invert'554 def __init__(self, node):555 self.expr = node556 self._children = ('invert', node)557 def __repr__(self):558 return "Invert(%s)" % self._children[1:]559# now clean up the nodes dictionary560klasses = globals()561for k in nodes.keys():562 nodes[k] = klasses[nodes[k]]563# Local Variables: 564# mode:python 565# indent-tabs-mode: nil 566# py-indent-offset: 2 567# py-smart-indentation: nil ...
php_tree.py
Source:php_tree.py
1class ParseTree:2 def __init__(self, tree):3 self.tree = tree4 def __repr__(self):5 return '<ParseTree contents:\n%r>' % self.tree6 def emit(self):7 return '.sub _MAIN\n' + self.tree.emit() + '\tend\n.end\n'8 9class Identifier:10 def __init__(self, name):11 self.name = name12 def __repr__(self):13 return '<Identifier name:%r>' % self.name14class StatementList:15 def __init__(self, statement_list):16 self.statement_list = statement_list17 def __repr__(self):18 return '<StatementList len:%d contents:\n%r>' % (len(self.statement_list), self.statement_list)19 def emit(self):20 return ''.join(['\t' + x.emit() + '\n' for x in self.statement_list])21class WhileStatement:22 def __init__(self, expr, statement):23 self.expr = expr24 self.statement = statement25 def __repr__(self):26 return '<WhileStatement\nexpr:%r\nstatement:%r>' % (self.expr, self.statement)27class SwitchStatement:28 def __init__(self, expr, case_list):29 self.expr = expr30 self.case_list = case_list31 def __repr__(self):32 return '<SwitchStatement\nexpr:%r\ncase_list:%r>' % (self.expr, self.case_list)33class IfStatement:34 def __init__(self, expr, statement, elseif_list, else_statement):35 self.expr = expr36 self.statement = statement37 self.elseif_list = elseif_list38 self.else_statement = else_statement39 def __repr__(self):40 return '<IfStatement\nexpr:%r\nstatement:%r\nelsieif:%r\nelse:%r>' % (self.expr, self.statement, self.elseif_list, self.else_statement)41class DeclareStatement:42 def __init__(self, declare_list, statement):43 (self.declare_list, self.statement) = (declare_list, statement)44 def __repr__(self):45 return '<Declare (%r)\n%r>' % (self.declare_list, self.statement)46class UseStatement:47 def __init__(self, filename):48 self.filename = filename49 def __repr__(self):50 return '<Use file:%r>' % self.filename51class Try:52 def __init__(self, statement_list, catches):53 (self.statement_list, self.catches) = (statement_list, catches)54 def __repr__(self):55 return '<Try %r\n%r>' % (self.statement_list, self.catches)56 57class Catch:58 def __init__(self, type, variable, statement_list):59 (self.type, self.variable, self.statement_list) = (type, variable, statement_list)60 def __repr__(self):61 return '<Catch %r as %r\n%r>' % (self.type, self.variable, self.statement_list)62class Throw:63 def __init__(self, expr):64 self.expr = expr65 def __repr__(self):66 return '<Throw %r>' % self.expr67class Empty:68 def __repr__(self):69 return '<Empty>'70class DefaultCase:71 def __repr__(self):72 return '<Default>'73class Case:74 def __init__(self, expr):75 self.expr = expr76 def __repr__(self):77 return '<Case %r>' % self.expr78class ExprStatement:79 def __init__(self, expr):80 self.expr = expr81 def __repr__(self):82 return '<Expr %r>' % self.expr83 def emit(self):84 return '\t' + self.expr.emit() + '\n'85class PostExpr:86 def __init__(self, var, op):87 (self.var, self.op) = (var, op)88 def __repr__(self):89 return '<Post %r%r>' % (self.var, self.op)90class PreExpr:91 def __init__(self, op, var):92 (self.op, self.var) = (op, var)93 def __repr__(self):94 return '<Pre %r%r>' % (self.op, self.var)95class InstanceofExpr:96 def __init__(self, expr, classname):97 (self.expr, self.classname) = (expr, classname)98 def __repr__(self):99 return '<Instanceof %r %r>' % (self.expr, self.classname)100class ContinueStatement:101 def __init__(self, expr):102 self.expr = expr103 def __repr__(self):104 return '<Continue %r>' % self.expr105class BreakStatement:106 def __init__(self, expr):107 self.expr = expr108 def __repr__(self):109 return '<Break %r>' % self.expr110class ReturnStatement:111 def __init__(self, expr):112 self.expr = expr113 def __repr__(self):114 return '<Return %r>' % self.expr115class EchoStatement:116 def __init__(self, expr_list):117 self.print_list = [PrintExpr(e) for e in expr_list]118 def __repr__(self):119 return '<Echo %r>' % self.print_list120 def emit(self):121 return [p.emit() for p in self.print_list]122 123class PrintExpr:124 def __init__(self, expr):125 self.expr = expr126 def __repr__(self):127 return '<Print %r>' % self.expr128 def emit(self): 129 return 'print ' + self.expr.emit()130class UnsetStatement:131 def __init__(self, variables):132 self.variables = variables133 def __repr__(self):134 return '<Unset %r>' % self.variables135class String:136 def __init__(self, encaps):137 self.encaps = encaps138 def __repr__(self):139 return '<String %r>' % self.encaps140 def emit(self):141 return '"' + [x.emit() for x in self.encaps] + '"'142class ConstString:143 def __init__(self, contents):144 self.contents = contents145 def __repr__(self):146 return '<ConstString %r>' % self.contents147 def emit(self):148 return '"' + self.contents + '"'149class Function:150 def __init__(self, name, params, statement_list, reference = 0):151 (self.name, self.params, self.statement_list, self.reference) = \152 (name, params, statement_list, reference)153 def __repr__(self):154 return '<Func\n%s%s(%s)\nstatementlist:%s>' % \155 (('','&')[self.reference], self.name, self.params, self.statement_list)156class Class:157 def __init__(self, name, type, extends, implements, statementlist):158 (self.name, self.type, self.extends, self.implements, self.statementlist) = \159 (name, type, extends, implements, statementlist)160 def __repr__(self):161 return '<Class %r %r %r %r %r>' % \162 (self.name, self.type, self.extends, self.implements, self.statementlist)163class ForStatement:164 def __init__(self, expr1, expr2, expr3, statement):165 self.expr1 = expr1166 self.expr2 = expr2167 self.expr3 = expr3168 self.statement = statement169 def __repr__(self):170 return '<ForStatement\nexpr1:%r\nexpr2:%r\nexpr3:%r\nstatement:%r>' % (self.expr1, self.expr2, self.expr3, self.statement)171class ForeachStatement:172 def __init__(self, array, key, value, statement):173 (self.array, self.key, self.value, self.statement) = (array, key, value, statement)174 def __repr__(self):175 return '<Foreach\narray:%r\nkey:%r\nvalue:%r\nstatement:%r>' % (self.array,self.key, self.value, self.statement)176class Declaration:177 def __init__(self, identifier, scalar):178 (self.identifier, self.scalar) = (identifier, scalar)179 def __repr__(self):180 return '<Declaration %r = %r>' % (self.identifier, self.scalar)181class ElseIf:182 def __init__(self, expr, statement):183 self.expr = expr184 self.statement = statement185 def __repr__(self):186 return '<ElseIf %r\n%r>' % (self.expr, self.statement)187class Parameter:188 def __init__(self, variable, opt_type, default=None):189 self.variable = variable190 self.opt_type = opt_type191 self.default = default192 def __repr__(self):193 return '<Parm %r %r %r>' % (self.opt_type, self.variable, self.default)194 195class Argument:196 def __init__(self, arg):197 self.arg = arg198 def __repr__(self):199 return "<Arg %r>" % self.arg200 201class Reference:202 def __init__(self, variable):203 self.variable = variable204 def __repr__(self):205 return "<Ref %r>" % self.variable206class SuppressExpr:207 def __init__(self, variable):208 self.variable = variable209 def __repr__(self):210 return "<Suppress %r>" % self.variable211class GlobalStatement:212 def __init__(self, var_list):213 self.var_list = var_list214 def __repr__(self):215 return '<Global %r>' % self.var_list216class StaticStatement:217 def __init__(self, var_list):218 self.var_list = var_list219 def __repr__(self):220 return '<Static %r>' % self.var_list221class StaticVariable:222 def __init__(self, variable, default=None):223 self.variable, self.default = variable, default224 def __repr__(self):225 return '<StaticVariable %r = %r>' % (self.variable, self.default)226class PrefixOpExpr:227 def __init__(self, op, rhs):228 self.op, self.rhs = op, rhs229 def __repr__(self):230 return '<PrefixOp %r %r>' % (self.op , self.rhs)231class AssignmentExpr:232 def __init__(self, lhs, rhs):233 self.lhs, self.rhs = lhs, rhs234 def __repr__(self):235 return '<Assignment %r = %r>' % (self.lhs , self.rhs)236class InfixOpExpr:237 def __init__(self, lhs, op, rhs):238 self.lhs, self.op, self.rhs = lhs, op, rhs239 def __repr__(self):240 return '<InFixOp %r %r %r>' % (self.lhs , self.op, self.rhs)241 def emit(self):242 return ' '.join([self.lhs.emit(), self.op, self.rhs.emit()])243class ListAssignmentExpr:244 def __init__(self, lhs, rhs=None):245 self.lhs, self.rhs = lhs, rhs246 def __repr__(self):247 return '<ListAssignment %r = %r>' % (self.lhs , self.rhs)248class CastExpr:249 def __init__(self, type, expr):250 self.type, self.expr = type, expr251 def __repr__(self):252 return '<Cast (%r)%r>' % (self.type , self.expr)253class ListTuple:254 def __init__(self, contents):255 self.contents = contents256 def __repr__(self):257 return '<Tuple %r>' % self.contents258 259class BacktickExpr:260 def __init__(self, encaps):261 self.encaps = encaps262 def __repr__(self):263 return '<Backtick %r>' % self.encaps264 265class InPlaceExpr:266 def __init__(self, lvar, op, expr):267 (self.lvar, self.op, self.expr) = (lvar, op, expr)268 def __repr__(self):269 return '<InPlace\nLVal:%r\nOp:%r\nExpr:%r>' % (self.lvar, self.op, self.expr)270class Comparison:271 def __init__(self, type, expr1, expr2):272 (self.type, self.expr1, self.expr2) = (type, expr1, expr2)273 def __repr__(self):274 return '<Comparison\ntype:%r\nLHS:%r\nRHS:%r>' % (self.type, self.expr1, self.expr2)275class VariableVariable:276 def __init__(self, expr):277 self.expr = expr278 def __repr__(self):279 return "<VariableVariable %r>" % self.expr280class Variable:281 def __init__(self, ident):282 self.ident = ident283 def __repr__(self):284 return "<Variable %s>" % self.ident285class Array:286 def __init__(self, pair_list):287 self.pair_list = pair_list288 def __repr__(self):289 return '<Array %r>' % self.pair_list290class ArraySingle:291 def __init__(self, expr):292 self.expr = expr293 def __repr__(self):294 return '<ArraySingle %r>' % (self.expr)295class ArrayPair:296 def __init__(self, expr1, expr2):297 (self.expr1, self.expr2) = (expr1, expr2)298 def __repr__(self):299 return '<ArrayPair %r=>%r>' % (self.expr1, self.expr2)300class ExitExpr:301 def __init__(self, expr=None):302 self.expr = expr303 def __repr__(self):304 return '<Exit %r>' % self.expr305class ClassVariable:306 def __init__(self, variable, default=None):307 self.variable, self.default = variable, default308 def __repr__(self):309 return '<ClassVariable %r = %r>' % (self.variable, self.default)310class ObjectVariable:311 def __init__(self, object, property):312 self.object, self.property = object, property313 def __repr__(self):314 return '<ObjectVariable %r -> %r>' % (self.object, self.property)315class FunctionCall:316 def __init__(self, function, parameters):317 self.function , self.parameters = function, parameters318 def __repr__(self):319 return '<FunctionCall %r %r>' % (self.function, self.parameters)320class ObjectCall:321 def __init__(self, object, method, parameters):322 self.object, self.method , self.parameters = object, method, parameters323 def __repr__(self):324 return '<ObjectCall %r -> %r %r>' % (self.object, self.method, self.parameters)325class TurnaryExpr:326 def __init__(self, expr1, expr2, expr3):327 (self.expr1, self.expr2, self.expr3) = (expr1, expr2,expr3)328 def __repr__(self):329 return '<Turnary %r ? %r : %r>' % (self.expr1, self.expr2, self.expr3)330class Number:331 def __init__(self, num):332 self.num = num333 def __repr__(self):334 return '<Number %r>' % self.num335 def emit(self):...
rhnErrors.py
Source:rhnErrors.py
...13 """base class for errors"""14 def __init__(self, errmsg):15 self.errmsg = errmsg16 self.log = rhnLog.initLog()17 def __repr__(self):18 self.log.log_me(self.errmsg)19 return self.errmsg20class FileError(Error):21 """22 error to report when we encounter file errors (missing files/dirs,23 lack of permissions, quoat issues, etc"""24 def __repr__(self):25 msg = _("Disk error. The message was:\n") + self.errmsg26 log = rhnLog.initLog()27 log.log_me(msg)28 return msg29class RpmError(Error):30 """rpm itself raised an error condition"""31 def __repr__(self):32 msg = _("RPM error. The message was:\n") + self.errmsg33 log = rhnLog.initLog()34 log.log_me(msg)35 return msg36class RpmInstallError(Error):37 """Raise when a package fails to install properly"""38 def __init__(self, msg, pkg = None):39 self.errmsg = msg40 self.pkg = pkg41 def __repr__(self):42 msg = _("There was a fatal error installing the package:\n")43 msg = msg + self.errmsg44 log = rhnLog.initLog()45 log.log_me(msg)46 return msg47class PasswordError(Error):48 """Raise when the server responds with that a password is incorrect"""49 def __repr__(self):50 log = rhnLog.initLog()51 msg = _("Password error. The message was:\n") + self.errmsg52 log.log_me(msg)53 return msg54class ConflictError(Error):55 """Raise when a rpm transaction set has a package conflict"""56 def __init__(self, msg, rc=None, data=None):57 self.rc = rc58 self.errmsg = msg59 self.data = data60 def __repr__(self):61 msg = _("RPM package conflict error. The message was:\n")62 msg = msg + self.errmsg63 log = rhnLog.initLog()64 log.log_me(msg)65 return msg66class FileConflictError(Error):67 """Raise when a rpm tranaction set has a file conflict"""68 def __init__(self, msg, rc=None):69 self.rc = rc70 self.errmsg = msg71 def __repr__(self):72 msg = _("RPM file conflict error. The message was:\n") + self.errmsg73 log = rhnLog.initLog()74 log.log_me(msg)75 return msg76class DependencyError(Error):77 """Raise when a rpm transaction set has a dependency error"""78 def __init__(self, msg, deps=None):79 self.errmsg = msg80 # just tag on the whole deps tuple, so we have plenty of info81 # to play with82 self.deps = deps83 def __repr__(self):84 msg = _("RPM dependency error. The message was:\n") + self.errmsg85 log = rhnLog.initLog()86 log.log_me(msg)87 return msg88class TransactionError(Error):89 """Raise when a rpm transaction set has a dependency error"""90 def __init__(self, msg, deps=None):91 self.errmsg = msg92 # just tag on the whole deps tuple, so we have plenty of info93 # to play with94 self.deps = deps95 def __repr__(self):96 msg = _("RPM error. The message was:\n") + self.errmsg97 log = rhnLog.initLog()98 log.log_me(msg)99 return msg100class UnsolvedDependencyError(Error):101 """Raise when we have a dependency that the server can not find"""102 def __init__(self, msg, dep=None, pkgs=None):103 self.errmsg = msg104 self.dep = dep105 self.pkgs = pkgs106 def __repr__(self):107 msg = _("RPM dependency error. The message was:\n") + self.errmsg108 log = rhnLog.initLog()109 log.log_me(msg)110 return msg111class DependencySenseError(Error):112 """113 Raise when a rpm transaction set has a dependency sense "\114 "we don't understand"""115 def __init__(self, msg, sense=None):116 self.errmsg = msg117 self.sense = sense118 def __repr__(self):119 msg = _("RPM dependency error. The message was:\n") + self.errmsg120 log = rhnLog.initLog()121 log.log_me(msg)122 return msg123class SkipListError(Error):124 """Raise when all the packages you want updated are on a skip list"""125 def __init__(self, msg, pkglist=None):126 self.errmsg = msg127 self.pkglist = pkglist128 def __repr__(self):129 msg = _("Package Skip List error. The message was:\n") + self.errmsg130 log = rhnLog.initLog()131 log.log_me(msg)132 return msg133class FileConfigSkipListError(Error):134 """135 Raise when all the packages you want updated are skip136 because of config or file skip list"""137 def __init__(self, msg, pkglist=None):138 self.errmsg = msg139 self.pkglist = None140 def __repr__(self):141 msg = _("File Skip List or config file overwrite error. "\142 "The message was:\n") + self.errmsg143 log = rhnLog.initLog()144 log.log_me(msg)145 return msg146class CommunicationError(Error):147 """Indicates a problem doing xml-rpc http communication with the server"""148 def __repr__(self):149 msg = _("Error communicating with server. "\150 "The message was:\n") + self.errmsg151 log = rhnLog.initLog()152 log.log_me(msg)153 return msg154class FileNotFoundError(Error):155 """156 Raise when a package or header that is requested returns157 a 404 error code"""158 def __repr__(self):159 msg = _("File Not Found: \n") + self.errmsg160 log = rhnLog.initLog()161 log.log_me(msg)162 return msg163class DelayError(Error):164 """165 Raise when the expected response from a xml-rpc call166 exceeds a timeout"""167 def __repr__(self):168 msg = _("Delay error from server. The message was:\n") + self.errmsg169 log = rhnLog.initLog()170 log.log_me(msg)171 return msg172class RpmRemoveSkipListError(Error):173 """Raise when we try to remove a package on the RemoveSkipList"""174 def __repr__(self):175 msg = _("Could not remove package \"%s\". "\176 "It was on the RemoveSkipList") % self.errmsg177 log = rhnLog.initLog()178 log.log_me(msg)179 return msg180class RpmRemoveError(Error):181 """182 Raise when we can't remove a package for some reason183 (failed deps, etc)"""184 def __init__(self, args):185 self.args = args186 self.errmsg = ""187 for key in self.args.keys():188 self.errmsg = self.errmsg + "%s failed because of %s\n" % (189 key, self.args[key])190 self.data = self.args191 def __repr__(self):192 return self.errmsg193class GPGInstallationError(Error):194 """Raise when we we detect that the GPG is not installed properly"""195 def __repr__(self):196 msg = _("GPG is not installed properly.")197 log = rhnLog.initLog()198 log.log_me(msg)199 return msg200class GPGKeyringError(Error):201 """202 Raise when we we detect that the gpg keyring for the user203 does not have the Red Hat Key installed"""204 def __repr__(self):205 msg = _("GPG keyring does not include the Red Hat, Inc. "\206 "public package-signing key")207 log = rhnLog.initLog()208 log.log_me(msg)209 return msg210class GPGVerificationError(Error):211 """Raise when we fail to verify a package is signed with a gpg signature"""212 def __init__(self, msg):213 self.errmsg = msg214 self.pkg = msg215 def __repr__(self):216 msg = _("The package %s failed its gpg signature verification. "\217 "This means the package is corrupt." % self.errmsg)218 log = rhnLog.initLog()219 log.log_me(msg)220 return msg221class GPGVerificationUnsignedPackageError(Error):222 """223 Raise when a package that is supposed to be verified has224 no gpg signature"""225 def __init__(self, msg):226 self.errmsg = msg227 self.pkg = msg228 def __repr__(self):229 msg = _("Package %s does not have a GPG signature.\n") % self.errmsg230 log = rhnLog.initLog()231 log.log_me(msg)232 return msg233class GPGVerificationUntrustedKeyError(Error):234 """235 Raise when a package that is supposed to be verified has an236 untrusted gpg signature"""237 def __init__(self, msg):238 self.errmsg = msg239 self.pkg = msg240 def __repr__(self):241 msg = _("Package %s has a untrusted GPG signature.\n") % self.errmsg242 log = rhnLog.initLog()243 log.log_me(msg)244 return msg245class GPGVerificationUnknownKeyError(Error):246 """247 Raise when a package that is supposed to be verified has an248 unknown gpg signature"""249 def __init__(self, msg):250 self.errmsg = msg251 self.pkg = msg252 def __repr__(self):253 msg = _("Package %s has a unknown GPG signature.\n") % self.errmsg254 log = rhnLog.initLog()255 log.log_me(msg)256 return msg257class OutOfSpaceError(Error):258 def __init__(self, totalSize, freeDiskSpace):259 self.ts = totalSize260 self.fds = freeDiskSpace261 self.errmsg = "The total size of the selected packages (%d kB) "\262 "exceeds your free disk space (%d kB)." % (263 self.ts, self.fds)264 def __repr__(self):265 return self.errmsg266class ServerThrottleError(Error):267 def __init__(self, msg):268 self.errmsg = msg269 def __repr__(self):270 return self.errmsg271class AbuseError(Error):272 def __init__(self, msg):273 self.errmsg = msg274 def __repr__(self):275 return self.errmsg276class AuthenticationTicketError(Error):277 def __init__(self, msg):278 self.errmsg = msg279 def __repr__(self):280 return self.errmsg281class AuthenticationError(Error):282 def __init__(self, msg):283 self.errmsg = msg284 def __repr__(self):285 return self.errmsg286class ValidationError(Error):287 def __init__(self, errmsg):288 Error.__init__(self, errmsg)289 # indicates an error during server input validation290 def __repr__(self):291 return _("Error validating data at server:\n") + self.errmsg292class OemInfoFileError(Error):293 def __init__(self,errmsg):294 Error.__init__(self, errmsg)295 def __repr__(self):296 return _("Error parsing the oemInfo file at field:\n") + self.errmsg297class NoRollbacksToUndoError(Error):298 """299 Raise when attempting to undo but there are no rollbacks"""300 def __repr__(self):301 log = rhnLog.initLog()302 log.log_me(self.errmsg)303 return self.errmsg304class RhnUuidUniquenessError(Error):305 def __init__(self, msg):306 self.errmsg = msg307 def __repr__(self):308 return self.errmsg309class Up2dateNeedsUpdateError(Error):310 def __init__(self, msg=""):311 self.errmsg = msg312 def __repr__(self):313 return self.errmsg314class ServerCapabilityError(Error):315 def __init__(self, msg, errorlist=None):316 self.errmsg = msg317 self.errorlist = []318 if errorlist:319 self.errorlist=errorlist320 def __repr__(self):321 return self.errmsg322class ServerCapabilityMissingError(Error):323 def __init__(self, msg):324 self.errmsg = msg325 def __repr__(self):326 return self.errmsg327class InvalidUrlError(Error):328 def __init__(self, msg):329 self.errmsg = msg330 def __repr__(self):331 return self.errmsg332class ServerCapabilityVersionError(Error):333 def __init__(self, msg):334 self.errmsg = msg335 def __repr__(self):336 return self.errmsg337class NoChannelsError(Error):338 def __init__(self, msg):339 self.errmsg = msg340 def __repr__(self):341 return self.errmsg342class PackageNotAvailableError(Error):343 def __init__(self, msg, missing_packages=None):344 self.errmsg = msg345 self.missing_packages = missing_packages346 def __repr__(self):347 errstring = "%s\n" % self.errmsg348 for i in self.missing_packages:349 errstring = errstring + "%s\n" % i350 return errstring351class PackageArchNotAvailableError(Error):352 def __init__(self, msg, missing_packages=None):353 self.errmsg = msg354 self.missing_packages = missing_packages355 def __repr__(self):356 errstring = "%s\n" % self.errmsg357 for i in self.missing_packages:358 errstring = errstring + "%s\n" % i...
errors.py
Source:errors.py
...8 def __init__(self, param_name):9 # passing in the name of the variable rather than the actual string10 # but feel free to pass in the value instead if you want!11 self.param_name = param_name12 def __repr__(self):13 errstr = 'Maximum string length of exceeded for {0}'.format(14 self.param_name)15 return errstr16 __str__ = __repr__17class InvalidIPAddress(FeatureError):18 def __init__(self, ipaddr):19 self.ipaddr = ipaddr20 def __repr__(self):21 errstr = 'Invalid IPv4 or IPv6 Address: {0}'.format(22 self.ipaddr)23 return errstr24 __str__ = __repr__25##################################26# INTERFACE ERRORS #27##################################28class InterfaceError(FeatureError):29 def __init__(self, if_name):30 self.if_name = if_name31class InterfaceTypeError(InterfaceError):32 def __init__(self, if_name, if_types=None):33 super(InterfaceTypeError, self).__init__(if_name)34 self.if_types = if_types35 def __repr__(self):36 errstr = '{0} is not a valid interface type.'.format(self.if_name)37 if self.if_types:38 errstr += ' Type must be one of {0}'.format(self.if_types)39 return errstr40 __str__ = __repr__41class InterfaceAbsentError(InterfaceError):42 def __init__(self, if_name):43 super(InterfaceAbsentError, self).__init__(if_name)44 def __repr__(self):45 return 'Interface {0} not found on the device.'.format(self.if_name)46 __str__ = __repr__47class InterfaceParamsError(InterfaceError):48 def __init__(self, if_name, params):49 super(InterfaceParamsError, self).__init__(if_name)50 self.params = params51 def __repr__(self):52 return 'Interface {0} does not take parameters {1}.'.format(53 self.if_name, self.params)54 __str__ = __repr__55class InterfaceCreateError(InterfaceError):56 def __init__(self, if_name):57 super(InterfaceCreateError, self).__init__(if_name)58 def __repr__(self):59 return 'Interface {0} could not be created.'.format(self.if_name)60 __str__ = __repr__61class InterfaceRemoveError(InterfaceError):62 def __init__(self, if_name):63 super(InterfaceRemoveError, self).__init__(if_name)64 def __repr__(self):65 return 'Interface {0} could not be removed.'.format(self.if_name)66 __str__ = __repr__67class InterfaceVlanMustExist(InterfaceError):68 def __init__(self, if_name, number):69 super(InterfaceVlanMustExist, self).__init__(if_name)70 self.number = number71 def __repr__(self):72 return 'Vlan {0} must exist before interface can be created.'.format(73 self.number)74 __str__ = __repr__75######################76# IPINTERFACE ERRORS #77######################78class IpInterfaceError(FeatureError):79 pass80class IpIfaceMissingData(IpInterfaceError):81 def __init__(self):82 super(IpIfaceMissingData, self).__init__()83 def __repr__(self):84 return 'IP address and mask must be supplied'85 __str__ = __repr__86##################################87# VLAN ERRORS #88##################################89class VlanError(FeatureError):90 pass91class VlanIDError(VlanError):92 def __repr__(self):93 errstr = 'VLAN ID must be between 1-4094'94 return errstr95 __str__ = __repr__96##################################97# REBOOT ERRORS #98##################################99class RebootError(FeatureError):100 pass101class RebootTimeError(RebootError):102 def __repr__(self):103 errstr = 'Format for time must be HH:MM'104 return errstr105 __str__ = __repr__106class RebootDateError(RebootError):107 def __repr__(self):108 errstr = 'Format for the date must be MM/DD/YYYY'109 return errstr110 __str__ = __repr__111##################################112# PORTCHANNEL ERRORS #113##################################114class PortChannelError(FeatureError):115 def __init__(self):116 pass117class InvalidPortType(PortChannelError):118 def __init__(self, if_name, config_type, pc_type):119 self.if_name = if_name120 self.config_type = config_type121 self.pc_type = pc_type122 def __repr__(self):123 errstr = ('Proposed port-channel type of "{0}" '.format(self.pc_type)124 + '\ndoes not match existing physical interface '125 + '\nof port type "{0}" '.format(self.config_type)126 + 'on interface: "{0}"'.format(self.if_name))127 return errstr128 __str__ = __repr__129class AggregationGroupError(PortChannelError):130 def __init__(self, if_name):131 self.if_name = if_name132 def __repr__(self):133 errstr = ('interface {0}'.format(self.if_name)134 + ' is assigned \nto another aggregation group.'135 + 'It needs to be \nremoved first.')136 return errstr137 __str__ = __repr__138##################################139# FILE COPY ERRORS #140##################################141class FileError(FeatureError):142 def __init__(self, src=None, dst=None):143 self.src = src144 self.dst = dst145class FileNotReadableError(FileError):146 def __repr__(self):147 return '{0} doesn\'t exist, or isn\'t readable.'.format(self.src)148 __str__ = __repr__149class FileNotEnoughSpaceError(FileError):150 def __init__(self, src, file_size, flash_size):151 super(FileNotEnoughSpaceError, self).__init__(src)152 self.file_size = file_size153 self.flash_size = flash_size154 def __repr__(self):155 return 'Not enough space on remote device for {0}.\n'.format(self.src) +\156 'File Size: {0} bytes\n'.format(self.file_size) +\157 'Space Available: {0} bytes\n'.format(self.flash_size)158 __str__ = __repr__159class FileTransferError(FileError):160 def __repr__(self):161 return 'There was an error while the file was in transit.'162 __str__ = __repr__163class FileHashMismatchError(FileError):164 def __init__(self, src, dst, src_hash, dst_hash):165 super(FileHashMismatchError, self).__init__(src, dst)166 self.src_hash = src_hash167 self.dst_hash = dst_hash168 def __repr__(self):169 return 'The MD5 hash digests do not match.\n' +\170 'The hash of the source {0} was {1}.\n'.format(self.src, self.src_hash) +\171 'The hash of the destinatino {0} was {1}.\n'.format(self.dst, self.dst_hash)172 __str__ = __repr__173class FileRemoteDirDoesNotExist(FileError):174 def __init__(self, remote_dir):175 self.remote_dir = remote_dir176 def __repr__(self):177 return 'The remote directory {0}'.format(self.remote_dir) +\178 ' does not exist.'179 __str__ = __repr__180##################################181# Config Errors #182##################################183class ConfigError(FeatureError):184 pass185class InvalidConfigFile(ConfigError):186 def __repr__(self):187 errstr = ('Config replace operation failed.\n' +188 ' Validate the config file being applied.')189 return errstr190 __str__ = __repr__191##################################192# IRF Errors #193##################################194class IRFError(FeatureError):195 pass196class IRFMemberDoesntExistError(IRFError):197 def __init__(self, member_id):198 self.member_id = member_id199 def __repr__(self):200 return 'The IRF member {0}'.format(self.member_id) +\201 ' does not exist.'...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!