desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Get params for showing a legend.'
| def _GetLegendParams(self, chart):
| if chart._show_legend:
return util.JoinLists(data_series_label=chart._legend_labels)
return {}
|
'Return axis.labels & axis.label_positions.'
| def _GetAxisLabelsAndPositions(self, axis, chart):
| return (axis.labels, axis.label_positions)
|
'Collect params related to our various axes (x, y, right-hand).'
| def _GetAxisParams(self, chart):
| axis_types = []
axis_ranges = []
axis_labels = []
axis_label_positions = []
axis_label_gridlines = []
mark_length = max(self._width, self._height)
for (i, axis_pair) in enumerate((a for a in chart._GetAxes() if a[1].labels)):
(axis_type_code, axis) = axis_pair
axis_types.appe... |
'Collect params related to grid lines.'
| def _GetGridParams(self, chart):
| x = 0
y = 0
if chart.bottom.grid_spacing:
assert (chart.bottom.min is not None)
assert (chart.bottom.max is not None)
total = float((chart.bottom.max - chart.bottom.min))
x = ((100 * chart.bottom.grid_spacing) / total)
if chart.left.grid_spacing:
assert (chart.lef... |
'Get LineStyle parameters.'
| def _GetLineStyles(self, chart):
| styles = []
for series in chart.data:
style = series.style
if style:
styles.append(('%s,%s,%s' % (style.width, style.on, style.off)))
else:
assert (not styles)
return util.JoinLists(line_style=styles)
|
'Construct a new BarChartEncoder.
Args:
style: DEPRECATED. Set style on the chart object itself.'
| def __init__(self, chart, style=None):
| super(BarChartEncoder, self).__init__(chart)
if (style is not None):
warnings.warn(self.__STYLE_DEPRECATION, DeprecationWarning, stacklevel=2)
chart.style = style
|
'Reverse labels on the y-axis in horizontal bar charts.
(Otherwise the labels come out backwards from what you would expect)'
| def _GetAxisLabelsAndPositions(self, axis, chart):
| if ((not chart.vertical) and (axis == chart.left)):
return (reversed(axis.labels), reversed(axis.label_positions))
return (axis.labels, axis.label_positions)
|
'Get the zero-point if any bars are negative.'
| def _ZeroPoint(self, chart):
| (min, max) = (chart.GetDependentAxis().min, chart.GetDependentAxis().max)
out = {}
if (min < 0):
if (max < 0):
out['chp'] = 1
else:
out['chp'] = ((- min) / float((max - min)))
return out
|
'If bar style is specified, fill in the missing data and apply it.'
| def _ApplyBarChartStyle(self, chart):
| if ((chart.style is None) or (not chart.data)):
return {}
(bar_thickness, bar_gap, group_gap) = (chart.style.bar_thickness, chart.style.bar_gap, chart.style.group_gap)
if ((bar_gap is None) and (group_gap is not None)):
bar_gap = max(0, (group_gap / 2))
if (not chart.style.use_fracti... |
'Construct a new PieChartEncoder.
Args:
is3d: If True, draw a 3d pie chart. Default is False. If the pie chart
includes multiple pies, is3d must be set to False.
angle: Angle of rotation of the pie chart, in radians.'
| def __init__(self, chart, is3d=False, angle=None):
| super(PieChartEncoder, self).__init__(chart)
self.is3d = is3d
self.angle = None
|
'Add a formatter for the chart angle.'
| def _GetFormatters(self):
| formatters = super(PieChartEncoder, self)._GetFormatters()
formatters.append(self._GetAngleParams)
return formatters
|
'Collect params related to the data series.'
| def _GetDataSeriesParams(self, chart):
| pie_points = []
labels = []
max_val = 1
for pie in chart.data:
points = []
for segment in pie:
if segment:
points.append(segment.size)
max_val = max(max_val, segment.size)
labels.append((segment.label or ''))
if points:
... |
'If the user specified an angle, add it to the params.'
| def _GetAngleParams(self, chart):
| if self.angle:
return {'chp': str(self.angle)}
return {}
|
'Construct a Marker. See class docstring for details on args.'
| def __init__(self, shape, color, size):
| self.shape = shape
self.color = color
self.size = size
|
'Construct a DataSeries. See class docstring for details on args.'
| def __init__(self, points, label=None, style=None, markers=None, color=None):
| if ((label is not None) and util._IsColor(label)):
warnings.warn('Your code may be broken! Label is a hex triplet. Maybe it is a color? The old argument order (color & style before label) is deprecated.', DeprecationWarning, stac... |
'Construct a new Axis.
Args:
axis_min: smallest value on the axis
axis_max: largest value on the axis'
| def __init__(self, axis_min=None, axis_max=None):
| self.min = axis_min
self.max = axis_max
self.labels = []
self.label_positions = []
self.grid_spacing = 0
self.label_gridlines = False
|
'Construct a BaseChart object.'
| def __init__(self):
| self.data = []
self._axes = {}
for code in self._POSITION_CODES:
self._axes[code] = [Axis()]
self._legend_labels = []
self._show_legend = False
self.auto_color = formatters.AutoColor()
self.auto_scale = formatters.AutoScale()
self.auto_legend = formatters.AutoLegend
self.form... |
'Add a new formatter to the chart (convenience method).'
| def AddFormatter(self, formatter):
| self.formatters.append(formatter)
|
'DEPRECATED
Add a new series of data to the chart; return the DataSeries object.'
| def AddSeries(self, points, color=None, style=None, markers=None, label=None):
| warnings.warn('AddSeries is deprecated. Instead, call AddLine for LineCharts, AddBars for BarCharts, AddSegment for PieCharts ', DeprecationWarning, stacklevel=2)
series = DataSeries(points, color=color, style=style, markers=markers, label=label)
self.data.appen... |
'Return any dependent axes (\'left\' and \'right\' by default for LineCharts,
although bar charts would use \'bottom\' and \'top\').'
| def GetDependentAxes(self):
| return (self._axes[AxisPosition.LEFT] + self._axes[AxisPosition.RIGHT])
|
'Return any independent axes (normally top & bottom, although horizontal
bar charts use left & right by default).'
| def GetIndependentAxes(self):
| return (self._axes[AxisPosition.TOP] + self._axes[AxisPosition.BOTTOM])
|
'Return this chart\'s main dependent axis (often \'left\', but
horizontal bar-charts use \'bottom\').'
| def GetDependentAxis(self):
| return self.left
|
'Return this chart\'s main independent axis (often \'bottom\', but
horizontal bar-charts use \'left\').'
| def GetIndependentAxis(self):
| return self.bottom
|
'Make a deep copy this chart.
Formatters & display will be missing from the copy, due to limitations in
deepcopy.'
| def _Clone(self):
| orig_values = {}
uncopyables = ['formatters', 'display', 'auto_color', 'auto_scale', 'auto_legend']
for name in uncopyables:
orig_values[name] = getattr(self, name)
setattr(self, name, None)
clone = copy.deepcopy(self)
for (name, orig_value) in orig_values.iteritems():
setatt... |
'Get a copy of the chart with formatting applied.'
| def GetFormattedChart(self):
| scratchpad = self._Clone()
for formatter in self.formatters:
formatter(scratchpad)
return scratchpad
|
'Get the largest & smallest values in this chart, returned as
(min_value, max_value). Takes into account complciations like stacked data
series.
For example, with non-stacked series, a chart with [1, 2, 3] and [4, 5, 6]
would return (1, 6). If the same chart was stacking the data series, it
would return (5, 9).'
| def GetMinMaxValues(self):
| MinPoint = (lambda data: min((x for x in data if (x is not None))))
MaxPoint = (lambda data: max((x for x in data if (x is not None))))
mins = [MinPoint(series.data) for series in self.data if series.data]
maxes = [MaxPoint(series.data) for series in self.data if series.data]
if ((not mins) or (not ... |
'Add an axis to this chart in the given position.
Args:
position: an AxisPosition object specifying the axis\'s position
axis: The axis to add, an Axis object
Returns:
the value of the axis parameter'
| def AddAxis(self, position, axis):
| self._axes.setdefault(position, []).append(axis)
return axis
|
'Get or create the first available axis in the given position.
This is a helper method for the left, right, top, and bottom properties.
If the specified axis does not exist, it will be created.
Args:
position: the position to search for
Returns:
The first axis in the given position'
| def GetAxis(self, position):
| if (position in self._axes):
return self._axes[position][0]
else:
axis = Axis()
self._axes[position] = [axis]
return axis
|
'Set the first axis in the given position to the given value.
This is a helper method for the left, right, top, and bottom properties.
Args:
position: an AxisPosition object specifying the axis\'s position
axis: The axis to set, an Axis object
Returns:
the value of the axis parameter'
| def SetAxis(self, position, axis):
| self._axes.setdefault(position, [None])[0] = axis
return axis
|
'Return a generator of (position_code, Axis) tuples for this chart\'s axes.
The axes will be sorted by position using the canonical ordering sequence,
_POSITION_CODES.'
| def _GetAxes(self):
| for code in self._POSITION_CODES:
for axis in self._axes.get(code, []):
(yield (code, axis))
|
'Create a new BarChartStyle.
Args:
bar_thickness: The thickness of a bar, in pixels. Set this to None if
you want the bar thickness to be auto-calculated (this is the default
behaviour).
bar_gap: The gap between bars, in pixels. Default is 4.
group_gap: The gap between groups of bars, in pixels. Default is 8.'
| def __init__(self, bar_thickness=None, bar_gap=_DEFAULT_BAR_GAP, group_gap=_DEFAULT_GROUP_GAP, use_fractional_gap_spacing=False):
| self.bar_thickness = bar_thickness
self.bar_gap = bar_gap
self.group_gap = group_gap
self.use_fractional_gap_spacing = use_fractional_gap_spacing
|
'Constructor for BarChart objects.'
| def __init__(self, points=None):
| super(BarChart, self).__init__()
if (points is not None):
self.AddBars(points)
self.vertical = True
self.stacked = False
self.style = BarChartStyle(None, None, None)
|
'Add a series of bars to the chart.
points: List of y-values for the bars in this series
label: Name of the series (used in the legend)
color: Hex string, like \'00ff00\' for green
This is a convenience method which constructs & appends the DataSeries for
you.'
| def AddBars(self, points, label=None, color=None):
| if ((label is not None) and util._IsColor(label)):
warnings.warn('Your code may be broken! Label is a hex triplet. Maybe it is a color? The old argument order (color before label) is deprecated.', DeprecationWarning, stacklevel=2)
... |
'Get the dependendant axes, which depend on orientation.'
| def GetDependentAxes(self):
| if self.vertical:
return (self._axes[common.AxisPosition.LEFT] + self._axes[common.AxisPosition.RIGHT])
else:
return (self._axes[common.AxisPosition.TOP] + self._axes[common.AxisPosition.BOTTOM])
|
'Get the independendant axes, which depend on orientation.'
| def GetIndependentAxes(self):
| if self.vertical:
return (self._axes[common.AxisPosition.TOP] + self._axes[common.AxisPosition.BOTTOM])
else:
return (self._axes[common.AxisPosition.LEFT] + self._axes[common.AxisPosition.RIGHT])
|
'Get the main dependendant axis, which depends on orientation.'
| def GetDependentAxis(self):
| if self.vertical:
return self.left
else:
return self.bottom
|
'Get the main independendant axis, which depends on orientation.'
| def GetIndependentAxis(self):
| if self.vertical:
return self.bottom
else:
return self.left
|
'Get the largest & smallest bar values as (min_value, max_value).'
| def GetMinMaxValues(self):
| if (not self.stacked):
return super(BarChart, self).GetMinMaxValues()
if (not self.data):
return (None, None)
num_bars = max((len(series.data) for series in self.data))
positives = [0 for i in xrange(0, num_bars)]
negatives = list(positives)
for series in self.data:
for (... |
'Constructor for PieChart objects.
Creates a pie chart with a single pie.
Args:
points: A list of data points for the pie chart;
i.e., relative sizes of the pie segments
labels: A list of labels for the pie segments.
TODO: Allow the user to pass in None as one of
the labels in order to skip that label.
colors: A list o... | def __init__(self, points=None, labels=None, colors=None):
| super(PieChart, self).__init__()
self.formatters = []
self._colors = None
if points:
self.AddPie(points, labels, colors)
|
'Add a whole pie to the chart.
Args:
points: A list of pie segment sizes
labels: A list of labels for the pie segments
colors: A list of colors for the segments. Missing colors will be chosen
automatically.
Return:
The index of the newly added pie.'
| def AddPie(self, points, labels=None, colors=None):
| num_colors = len((colors or []))
num_labels = len((labels or []))
pie_index = len(self.data)
self.data.append([])
for (i, pt) in enumerate(points):
label = None
if (i < num_labels):
label = labels[i]
color = None
if (i < num_colors):
color = co... |
'DEPRECATED.'
| def AddSegments(self, points, labels, colors):
| warnings.warn('PieChart.AddSegments is deprecated. Call AddPie instead. ', DeprecationWarning, stacklevel=2)
num_colors = len((colors or []))
for (i, pt) in enumerate(points):
assert (pt >= 0)
label = labels[i]
color = None
if (i < num_colors):
c... |
'Add a pie segment to this chart, and return the segment.
size: The size of the segment.
label: The label for the segment.
color: The color of the segment, or None to automatically choose the color.
pie_index: The index of the pie that will receive the new segment.
By default, the chart has one pie (pie #0); use the Ad... | def AddSegment(self, size, label=None, color=None, pie_index=0):
| if isinstance(size, Segment):
warnings.warn('AddSegment(segment) is deprecated. Use AddSegment(size, label, color) instead', DeprecationWarning, stacklevel=2)
segment = size
else:
segment = Segment(size, label=label, color=color)
assert (segment.size >= 0)
... |
'DEPRECATED
Add a new segment to the chart and return it.
The segment must contain exactly one data point; all parameters
other than color and label are ignored.'
| def AddSeries(self, points, color=None, style=None, markers=None, label=None):
| warnings.warn('PieChart.AddSeries is deprecated. Call AddSegment or AddSegments instead.', DeprecationWarning)
return self.AddSegment(Segment(points[0], color=color, label=label))
|
'Change the colors of this chart to the specified list of colors.
Note that this will completely override the individual colors specified
in the pie segments. Missing colors will be interpolated, so that the
list of colors covers all segments in all the pies.'
| def SetColors(self, *colors):
| self._colors = colors
|
'Create a new AutoScale formatter.
Args:
buffer: percentage of extra space to allocate around the chart\'s axes.'
| def __init__(self, buffer=0.05):
| self.buffer = buffer
|
'Format the chart by setting the min/max values on its dependent axis.'
| def __call__(self, chart):
| if (not chart.data):
return
(min_value, max_value) = chart.GetMinMaxValues()
if (None in (min_value, max_value)):
return
for axis in chart.GetDependentAxes():
if (axis.min is not None):
min_value = axis.min
if (axis.max is not None):
max_value = ax... |
'Unescape markup again into an unicode string. This also resolves
known HTML4 and XHTML entities:
>>> Markup("Main » <em>About</em>").unescape()
u\'Main \xbb <em>About</em>\''
| def unescape(self):
| from markupsafe._constants import HTML_ENTITIES
def handle_match(m):
name = m.group(1)
if (name in HTML_ENTITIES):
return unichr(HTML_ENTITIES[name])
try:
if (name[:2] in ('#x', '#X')):
return unichr(int(name[2:], 16))
elif name.startsw... |
'Unescape markup into an unicode string and strip all tags. This
also resolves known HTML4 and XHTML entities. Whitespace is
normalized to one:
>>> Markup("Main » <em>About</em>").striptags()
u\'Main \xbb About\''
| def striptags(self):
| stripped = u' '.join(_striptags_re.sub('', self).split())
return Markup(stripped).unescape()
|
'Escape the string. Works like :func:`escape` with the difference
that for subclasses of :class:`Markup` this function would return the
correct subclass.'
| @classmethod
def escape(cls, s):
| rv = escape(s)
if (rv.__class__ is not cls):
return cls(rv)
return rv
|
'Return the token type or char of the unexpected input element'
| def getUnexpectedType(self):
| from antlr3.streams import TokenStream
from antlr3.tree import TreeNodeStream
if isinstance(self.input, TokenStream):
return self.token.type
elif isinstance(self.input, TreeNodeStream):
adaptor = self.input.treeAdaptor
return adaptor.getType(self.node)
else:
return se... |
'Tree tracks parent and child index now > 3.0'
| def getParent(self):
| raise NotImplementedError
|
'Tree tracks parent and child index now > 3.0'
| def setParent(self, t):
| raise NotImplementedError
|
'This node is what child index? 0..n-1'
| def getChildIndex(self):
| raise NotImplementedError
|
'This node is what child index? 0..n-1'
| def setChildIndex(self, index):
| raise NotImplementedError
|
'Set the parent and child index values for all children'
| def freshenParentAndChildIndexes(self):
| raise NotImplementedError
|
'Add t as a child to this node. If t is null, do nothing. If t
is nil, add all children of t to this\' children.'
| def addChild(self, t):
| raise NotImplementedError
|
'Set ith child (0..n-1) to t; t must be non-null and non-nil node'
| def setChild(self, i, t):
| raise NotImplementedError
|
'Delete children from start to stop and replace with t even if t is
a list (nil-root tree). num of children can increase or decrease.
For huge child lists, inserting children can force walking rest of
children to set their childindex; could be slow.'
| def replaceChildren(self, startChildIndex, stopChildIndex, t):
| raise NotImplementedError
|
'Indicates the node is a nil node but may still have children, meaning
the tree is a flat list.'
| def isNil(self):
| raise NotImplementedError
|
'What is the smallest token index (indexing from 0) for this node
and its children?'
| def getTokenStartIndex(self):
| raise NotImplementedError
|
'What is the largest token index (indexing from 0) for this node
and its children?'
| def getTokenStopIndex(self):
| raise NotImplementedError
|
'Return a token type; needed for tree parsing.'
| def getType(self):
| raise NotImplementedError
|
'In case we don\'t have a token payload, what is the line for errors?'
| def getLine(self):
| raise NotImplementedError
|
'Create a tree node from Token object; for CommonTree type trees,
then the token just becomes the payload. This is the most
common create call.
Override if you want another kind of node to be built.'
| def createWithPayload(self, payload):
| raise NotImplementedError
|
'Duplicate a single tree node.
Override if you want another kind of node to be built.'
| def dupNode(self, treeNode):
| raise NotImplementedError
|
'Duplicate tree recursively, using dupNode() for each node'
| def dupTree(self, tree):
| raise NotImplementedError
|
'Return a nil node (an empty but non-null node) that can hold
a list of element as the children. If you want a flat tree (a list)
use "t=adaptor.nil(); t.addChild(x); t.addChild(y);"'
| def nil(self):
| raise NotImplementedError
|
'Return a tree node representing an error. This node records the
tokens consumed during error recovery. The start token indicates the
input symbol at which the error was detected. The stop token indicates
the last symbol consumed during recovery.
You must specify the input stream so that the erroneous text can
be pa... | def errorNode(self, input, start, stop, exc):
| raise NotImplementedError
|
'Is tree considered a nil node used to make lists of child nodes?'
| def isNil(self, tree):
| raise NotImplementedError
|
'Add a child to the tree t. If child is a flat tree (a list), make all
in list children of t. Warning: if t has no children, but child does
and child isNil then you can decide it is ok to move children to t via
t.children = child.children; i.e., without copying the array. Just
make sure that this is consistent with ... | def addChild(self, t, child):
| raise NotImplementedError
|
'If oldRoot is a nil root, just copy or move the children to newRoot.
If not a nil root, make oldRoot a child of newRoot.
old=^(nil a b c), new=r yields ^(r a b c)
old=^(a b c), new=r yields ^(r ^(a b c))
If newRoot is a nil-rooted single child tree, use the single
child as the new root node.
old=^(nil a b c), new=^(ni... | def becomeRoot(self, newRoot, oldRoot):
| raise NotImplementedError
|
'Given the root of the subtree created for this rule, post process
it to do any simplifications or whatever you want. A required
behavior is to convert ^(nil singleSubtree) to singleSubtree
as the setting of start/stop indexes relies on a single non-nil root
for non-flat trees.
Flat trees such as for lists like "idlis... | def rulePostProcessing(self, root):
| raise NotImplementedError
|
'For identifying trees.
How to identify nodes so we can say "add node to a prior node"?
Even becomeRoot is an issue. Use System.identityHashCode(node)
usually.'
| def getUniqueID(self, node):
| raise NotImplementedError
|
'Create a new node derived from a token, with a new token type and
(optionally) new text.
This is invoked from an imaginary node ref on right side of a
rewrite rule as IMAG[$tokenLabel] or IMAG[$tokenLabel "IMAG"].
This should invoke createToken(Token).'
| def createFromToken(self, tokenType, fromToken, text=None):
| raise NotImplementedError
|
'Create a new node derived from a token, with a new token type.
This is invoked from an imaginary node ref on right side of a
rewrite rule as IMAG["IMAG"].
This should invoke createToken(int,String).'
| def createFromType(self, tokenType, text):
| raise NotImplementedError
|
'For tree parsing, I need to know the token type of a node'
| def getType(self, t):
| raise NotImplementedError
|
'Node constructors can set the type of a node'
| def setType(self, t, type):
| raise NotImplementedError
|
'Node constructors can set the text of a node'
| def setText(self, t, text):
| raise NotImplementedError
|
'Return the token object from which this node was created.
Currently used only for printing an error message.
The error display routine in BaseRecognizer needs to
display where the input the error occurred. If your
tree of limitation does not store information that can
lead you to the token, you can create a token fill... | def getToken(self, t):
| raise NotImplementedError
|
'Where are the bounds in the input token stream for this node and
all children? Each rule that creates AST nodes will call this
method right before returning. Flat trees (i.e., lists) will
still usually have a nil root node just to hold the children list.
That node would contain the start/stop indexes then.'
| def setTokenBoundaries(self, t, startToken, stopToken):
| raise NotImplementedError
|
'Get the token start index for this subtree; return -1 if no such index'
| def getTokenStartIndex(self, t):
| raise NotImplementedError
|
'Get the token stop index for this subtree; return -1 if no such index'
| def getTokenStopIndex(self, t):
| raise NotImplementedError
|
'Get a child 0..n-1 node'
| def getChild(self, t, i):
| raise NotImplementedError
|
'Set ith child (0..n-1) to t; t must be non-null and non-nil node'
| def setChild(self, t, i, child):
| raise NotImplementedError
|
'Remove ith child and shift children down from right.'
| def deleteChild(self, t, i):
| raise NotImplementedError
|
'How many children? If 0, then this is a leaf node'
| def getChildCount(self, t):
| raise NotImplementedError
|
'Who is the parent node of this node; if null, implies node is root.
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def getParent(self, t):
| raise NotImplementedError
|
'Who is the parent node of this node; if null, implies node is root.
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def setParent(self, t, parent):
| raise NotImplementedError
|
'What index is this node in the child list? Range: 0..n-1
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def getChildIndex(self, t):
| raise NotImplementedError
|
'What index is this node in the child list? Range: 0..n-1
If your node type doesn\'t handle this, it\'s ok but the tree rewrites
in tree parsers need this functionality.'
| def setChildIndex(self, t, index):
| raise NotImplementedError
|
'Replace from start to stop child index of parent with t, which might
be a list. Number of children may be different
after this call.
If parent is null, don\'t do anything; must be at root of overall tree.
Can\'t replace whatever points to the parent externally. Do nothing.'
| def replaceChildren(self, parent, startChildIndex, stopChildIndex, t):
| raise NotImplementedError
|
'Deprecated, use createWithPayload, createFromToken or createFromType.
This method only exists to mimic the Java interface of TreeAdaptor.'
| def create(self, *args):
| if ((len(args) == 1) and isinstance(args[0], Token)):
return self.createWithPayload(args[0])
if ((len(args) == 2) and isinstance(args[0], (int, long)) and isinstance(args[1], Token)):
return self.createFromToken(args[0], args[1])
if ((len(args) == 3) and isinstance(args[0], (int, long)) and ... |
'Create a new node from an existing node does nothing for BaseTree
as there are no fields other than the children list, which cannot
be copied as the children are not considered part of this node.'
| def __init__(self, node=None):
| Tree.__init__(self)
self.children = []
self.parent = None
self.childIndex = 0
|
'@brief Get the children internal List
Note that if you directly mess with
the list, do so at your own risk.'
| def getChildren(self):
| return self.children
|
'Add t as child of this node.
Warning: if t has no children, but child does
and child isNil then this routine moves children to t via
t.children = child.children; i.e., without copying the array.'
| def addChild(self, childTree):
| if (childTree is None):
return
if childTree.isNil():
if (self.children is childTree.children):
raise ValueError('attempt to add child list to itself')
for (idx, child) in enumerate(childTree.children):
child.parent = self
child.childI... |
'Add all elements of kids list as children of this node'
| def addChildren(self, children):
| self.children += children
|
'Delete children from start to stop and replace with t even if t is
a list (nil-root tree). num of children can increase or decrease.
For huge child lists, inserting children can force walking rest of
children to set their childindex; could be slow.'
| def replaceChildren(self, startChildIndex, stopChildIndex, newTree):
| if ((startChildIndex >= len(self.children)) or (stopChildIndex >= len(self.children))):
raise IndexError('indexes invalid')
replacingHowMany = ((stopChildIndex - startChildIndex) + 1)
if newTree.isNil():
newChildren = newTree.children
else:
newChildren = [newTree]
replacin... |
'BaseTree doesn\'t track child indexes.'
| def getChildIndex(self):
| return 0
|
'BaseTree doesn\'t track child indexes.'
| def setChildIndex(self, index):
| pass
|
'BaseTree doesn\'t track parent pointers.'
| def getParent(self):
| return None
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.