18 from .body
import Body, BodyItem, Branches
19 from .keyword
import Keywords
26 repr_args = (
'variables',
'flavor',
'values')
27 __slots__ = [
'variables',
'flavor',
'values']
29 def __init__(self, variables=(), flavor=
'IN', values=(), parent=
None):
50 Keywords.raise_deprecation_error()
53 visitor.visit_for(self)
56 variables =
' '.join(self.
variablesvariables)
57 values =
' '.join(self.
valuesvalues)
58 return 'FOR %s %s %s' % (variables, self.
flavorflavor, values)
65 repr_args = (
'condition',
'limit')
66 __slots__ = [
'condition',
'limit']
68 def __init__(self, condition=None, limit=None, parent=None):
79 visitor.visit_while(self)
82 return f
'WHILE {self.condition}' + (f
' {self.limit}' if self.
limitlimit
else '')
87 repr_args = (
'type',
'condition')
88 __slots__ = [
'type',
'condition']
90 def __init__(self, type=BodyItem.IF, condition=None, parent=None):
107 if not self.
parentparent.parent:
108 return 'k%d' % (self.
parentparent.body.index(self) + 1)
115 return 'ELSE IF %s' % self.
conditioncondition
119 visitor.visit_if_branch(self)
125 type = BodyItem.IF_ELSE_ROOT
126 branch_class = IfBranch
127 branches_class = Branches
128 __slots__ = [
'parent']
146 visitor.visit_if(self)
151 repr_args = (
'type',
'patterns',
'pattern_type',
'variable')
152 __slots__ = [
'type',
'patterns',
'pattern_type',
'variable']
154 def __init__(self, type=BodyItem.TRY, patterns=(), pattern_type=
None,
155 variable=
None, parent=
None):
156 if (patterns
or pattern_type
or variable)
and type != BodyItem.EXCEPT:
157 raise TypeError(f
"'{type}' branches do not accept patterns or variables.")
176 if not self.
parentparent.parent:
177 return 'k%d' % (self.
parentparent.body.index(self) + 1)
181 if self.
typetypetype != BodyItem.EXCEPT:
183 parts = [
'EXCEPT'] + list(self.
patternspatterns)
185 parts.append(f
'type={self.pattern_type}')
187 parts.extend([
'AS', self.
variablevariable])
188 return ' '.join(parts)
192 return self.
_repr_repr(repr_args)
195 visitor.visit_try_branch(self)
201 type = BodyItem.TRY_EXCEPT_ROOT
202 branch_class = TryBranch
203 branches_class = Branches
215 try_branch = property
220 raise TypeError(
"No 'TRY' branch or 'TRY' branch is not first.")
223 except_branches = property
226 return [branch
for branch
in self.
bodybodybody
if branch.type == BodyItem.EXCEPT]
229 else_branch = property
233 if branch.type == BodyItem.ELSE:
238 finally_branch = property
253 visitor.visit_try(self)
258 type = BodyItem.RETURN
259 repr_args = (
'values',)
260 __slots__ = [
'values']
267 visitor.visit_return(self)
272 type = BodyItem.CONTINUE
279 visitor.visit_continue(self)
284 type = BodyItem.BREAK
291 visitor.visit_break(self)
def _get_id(self, parent)
def __init__(self, parent=None)
def __init__(self, parent=None)
def __init__(self, variables=(), flavor='IN', values=(), parent=None)
keywords
Deprecated since Robot Framework 4.0.
id
Branch id omits IF/ELSE root from the parent id part.
def __init__(self, type=BodyItem.IF, condition=None, parent=None)
id
Root IF/ELSE id is always None.
def __init__(self, parent=None)
def __init__(self, values=(), parent=None)
id
Branch id omits TRY/EXCEPT root from the parent id part.
def __init__(self, type=BodyItem.TRY, patterns=(), pattern_type=None, variable=None, parent=None)
TRY/EXCEPT structure root.
def __init__(self, parent=None)
id
Root TRY/EXCEPT id is always None.
def __init__(self, condition=None, limit=None, parent=None)
A list-like object representing keywords in a suite, a test or a keyword.
def _repr(self, repr_args)