signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def make_arrow(self, portal):
if (<EOL>portal["<STR_LIT>"] not in self.spot or<EOL>portal["<STR_LIT>"] not in self.spot<EOL>):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>if (<EOL>portal["<STR_LIT>"] in self.arrow and<EOL>portal["<STR_LIT>"] in self.arrow[portal["<STR_LIT>"]]<EOL>):<EOL><INDENT>raise KeyError("<STR_LIT>")<EOL><DEDENT>return self._core_make_arrow(portal, self.spot[portal['<STR_LIT>']], self.spot[portal['<STR_LIT>']], self.arrow)<EOL>
Make an :class:`Arrow` to represent a :class:`Portal`, store it, and return it.
f8988:c3:m14
def rm_pawn(self, name, *args):
if name not in self.pawn:<EOL><INDENT>raise KeyError("<STR_LIT>".format(name))<EOL><DEDENT>self.rm_arrows_to_and_from(name)<EOL>pwn = self.pawn.pop(name)<EOL>if pwn in self.selection_candidates:<EOL><INDENT>self.selection_candidates.remove(pwn)<EOL><DEDENT>pwn.parent.remove_widget(pwn)<EOL>
Remove the :class:`Pawn` by the given name.
f8988:c3:m17
def rm_spot(self, name, *args):
if name not in self.spot:<EOL><INDENT>raise KeyError("<STR_LIT>".format(name))<EOL><DEDENT>spot = self.spot.pop(name)<EOL>if spot in self.selection_candidates:<EOL><INDENT>self.selection_candidates.remove(spot)<EOL><DEDENT>pawns_here = list(spot.children)<EOL>self.rm_arrows_to_and_from(name)<EOL>self.spotlayout.remove_widget(spot)<EOL>spot.canvas.clear()<EOL>for pawn in pawns_here:<EOL><INDENT>self.rm_pawn(pawn.name)<EOL><DEDENT>
Remove the :class:`Spot` by the given name.
f8988:c3:m19
def rm_arrow(self, orig, dest, *args):
if (<EOL>orig not in self.arrow or<EOL>dest not in self.arrow[orig]<EOL>):<EOL><INDENT>raise KeyError("<STR_LIT>".format(orig, dest))<EOL><DEDENT>arr = self.arrow[orig].pop(dest)<EOL>if arr in self.selection_candidates:<EOL><INDENT>self.selection_candidates.remove(arr)<EOL><DEDENT>self.arrowlayout.remove_widget(arr)<EOL>
Remove the :class:`Arrow` that goes from ``orig`` to ``dest``.
f8988:c3:m21
def update(self, *args):
<EOL>Logger.debug("<STR_LIT>")<EOL>self.remove_absent_pawns()<EOL>self.remove_absent_spots()<EOL>self.remove_absent_arrows()<EOL>self.add_new_spots()<EOL>if self.arrow_cls:<EOL><INDENT>self.add_new_arrows()<EOL><DEDENT>self.add_new_pawns()<EOL>self.spotlayout.finalize_all()<EOL>Logger.debug("<STR_LIT>")<EOL>
Force an update to match the current state of my character. This polls every element of the character, and therefore causes me to sync with the LiSE core for a long time. Avoid when possible.
f8988:c3:m42
def update_from_delta(self, delta, *args):
for (node, extant) in delta.get('<STR_LIT>', {}).items():<EOL><INDENT>if extant:<EOL><INDENT>if node in delta.get('<STR_LIT>', {})and '<STR_LIT:location>' in delta['<STR_LIT>'][node]and node not in self.pawn:<EOL><INDENT>self.add_pawn(node)<EOL><DEDENT>elif node not in self.spot:<EOL><INDENT>self.add_spot(node)<EOL>spot = self.spot[node]<EOL>if '<STR_LIT>' not in spot.place or '<STR_LIT>' not in spot.place:<EOL><INDENT>self.spots_unposd.append(spot)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if node in self.pawn:<EOL><INDENT>self.rm_pawn(node)<EOL><DEDENT>if node in self.spot:<EOL><INDENT>self.rm_spot(node)<EOL><DEDENT><DEDENT><DEDENT>for (node, stats) in delta.get('<STR_LIT>', {}).items():<EOL><INDENT>if node in self.spot:<EOL><INDENT>spot = self.spot[node]<EOL>x = stats.get('<STR_LIT>')<EOL>y = stats.get('<STR_LIT>')<EOL>if x is not None:<EOL><INDENT>spot.x = x * self.width<EOL><DEDENT>if y is not None:<EOL><INDENT>spot.y = y * self.height<EOL><DEDENT>if '<STR_LIT>' in stats:<EOL><INDENT>spot.paths = stats['<STR_LIT>'] or spot.default_image_paths<EOL><DEDENT><DEDENT>elif node in self.pawn:<EOL><INDENT>pawn = self.pawn[node]<EOL>if '<STR_LIT:location>' in stats:<EOL><INDENT>pawn.loc_name = stats['<STR_LIT:location>']<EOL><DEDENT>if '<STR_LIT>' in stats:<EOL><INDENT>pawn.paths = stats['<STR_LIT>'] or pawn.default_image_paths<EOL><DEDENT><DEDENT>else:<EOL><INDENT>Logger.warning(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(node)<EOL>)<EOL><DEDENT><DEDENT>for (orig, dests) in delta.get('<STR_LIT>', {}).items():<EOL><INDENT>for (dest, extant) in dests.items():<EOL><INDENT>if extant and (orig not in self.arrow or dest not in self.arrow[orig]):<EOL><INDENT>self.add_arrow(orig, dest)<EOL><DEDENT>elif not extant and orig in self.arrow and dest in self.arrow[orig]:<EOL><INDENT>self.rm_arrow(orig, dest)<EOL><DEDENT><DEDENT><DEDENT>
Apply the changes described in the dict ``delta``.
f8988:c3:m43
def arrows(self):
for o in self.arrow.values():<EOL><INDENT>for arro in o.values():<EOL><INDENT>yield arro<EOL><DEDENT><DEDENT>
Iterate over all my arrows.
f8988:c3:m49
def pawns_at(self, x, y):
for pawn in self.pawn.values():<EOL><INDENT>if pawn.collide_point(x, y):<EOL><INDENT>yield pawn<EOL><DEDENT><DEDENT>
Iterate over pawns that collide the given point.
f8988:c3:m50
def spots_at(self, x, y):
for spot in self.spot.values():<EOL><INDENT>if spot.collide_point(x, y):<EOL><INDENT>yield spot<EOL><DEDENT><DEDENT>
Iterate over spots that collide the given point.
f8988:c3:m51
def arrows_at(self, x, y):
for arrow in self.arrows():<EOL><INDENT>if arrow.collide_point(x, y):<EOL><INDENT>yield arrow<EOL><DEDENT><DEDENT>
Iterate over arrows that collide the given point.
f8988:c3:m52
def spot_from_dummy(self, dummy):
(x, y) = self.to_local(*dummy.pos_up)<EOL>x /= self.board.width<EOL>y /= self.board.height<EOL>self.board.spotlayout.add_widget(<EOL>self.board.make_spot(<EOL>self.board.character.new_place(<EOL>dummy.name,<EOL>_x=x,<EOL>_y=y,<EOL>_image_paths=list(dummy.paths)<EOL>)<EOL>)<EOL>)<EOL>dummy.num += <NUM_LIT:1><EOL>
Make a real place and its spot from a dummy spot. Create a new :class:`board.Spot` instance, along with the underlying :class:`LiSE.Place` instance, and give it the name, position, and imagery of the provided dummy.
f8988:c4:m0
def pawn_from_dummy(self, dummy):
dummy.pos = self.to_local(*dummy.pos)<EOL>for spot in self.board.spotlayout.children:<EOL><INDENT>if spot.collide_widget(dummy):<EOL><INDENT>whereat = spot<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT>whereat.add_widget(<EOL>self.board.make_pawn(<EOL>self.board.character.new_thing(<EOL>dummy.name,<EOL>whereat.place.name,<EOL>_image_paths=list(dummy.paths)<EOL>)<EOL>)<EOL>)<EOL>dummy.num += <NUM_LIT:1><EOL>
Make a real thing and its pawn from a dummy pawn. Create a new :class:`board.Pawn` instance, along with the underlying :class:`LiSE.Place` instance, and give it the name, location, and imagery of the provided dummy.
f8988:c4:m1
def arrow_from_wid(self, wid):
for spot in self.board.spotlayout.children:<EOL><INDENT>if spot.collide_widget(wid):<EOL><INDENT>whereto = spot<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return<EOL><DEDENT>self.board.arrowlayout.add_widget(<EOL>self.board.make_arrow(<EOL>self.board.character.new_portal(<EOL>self.board.grabbed.place.name,<EOL>whereto.place.name,<EOL>reciprocal=self.reciprocal_portal<EOL>)<EOL>)<EOL>)<EOL>
Make a real portal and its arrow from a dummy arrow. This doesn't handle touch events. It takes a widget as its argument: the one the user has been dragging to indicate where they want the arrow to go. Said widget ought to be invisible. It checks if the dummy arrow connects two real spots first, and does nothing if it doesn't.
f8988:c4:m2
def __init__(self, **kwargs):
self._pospawn_partials = {}<EOL>self._pospawn_triggers = {}<EOL>kwargs['<STR_LIT>'] = (None, None)<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>kwargs['<STR_LIT>'] = kwargs['<STR_LIT>']<EOL>del kwargs['<STR_LIT>']<EOL><DEDENT>super().__init__(**kwargs)<EOL>
Deal with triggers and bindings, and arrange to take care of changes in game-time.
f8989:c0:m0
def push_pos(self, *args):
self.proxy['<STR_LIT>'] = self.x / self.board.width<EOL>self.proxy['<STR_LIT>'] = self.y / self.board.height<EOL>
Set my current position, expressed as proportions of the board's width and height, into the ``_x`` and ``_y`` keys of the entity in my ``proxy`` property, such that it will be recorded in the database.
f8989:c0:m4
def __repr__(self):
return "<STR_LIT>".format(self.name, self.x, self.y, id(self))<EOL>
Give my name and position.
f8989:c0:m6
def get_points(orig, dest, taillen):
<EOL>ox, oy = orig.center<EOL>ow, oh = orig.size<EOL>dx, dy = dest.center<EOL>dw, dh = dest.size<EOL>if ox < dx:<EOL><INDENT>leftx = ox<EOL>rightx = dx<EOL>xco = <NUM_LIT:1><EOL><DEDENT>elif ox > dx:<EOL><INDENT>leftx = ox * -<NUM_LIT:1><EOL>rightx = dx * -<NUM_LIT:1><EOL>xco = -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return up_and_down(orig, dest, taillen)<EOL><DEDENT>if oy < dy:<EOL><INDENT>boty = oy<EOL>topy = dy<EOL>yco = <NUM_LIT:1><EOL><DEDENT>elif oy > dy:<EOL><INDENT>boty = oy * -<NUM_LIT:1><EOL>topy = dy * -<NUM_LIT:1><EOL>yco = -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return left_and_right(orig, dest, taillen)<EOL><DEDENT>slope = (topy - boty) / (rightx - leftx)<EOL>if slope <= <NUM_LIT:1>:<EOL><INDENT>for rightx in range(<EOL>int(rightx - dw / <NUM_LIT:2>),<EOL>int(rightx)+<NUM_LIT:1><EOL>):<EOL><INDENT>topy = slope * (rightx - leftx) + boty<EOL>if dest.collide_point(rightx * xco, topy * yco):<EOL><INDENT>rightx = float(rightx - <NUM_LIT:1>)<EOL>for pip in range(<NUM_LIT:10>):<EOL><INDENT>rightx += <NUM_LIT:0.1> * pip<EOL>topy = slope * (rightx - leftx) + boty<EOL>if dest.collide_point(rightx * xco, topy * yco):<EOL><INDENT>break<EOL><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT>for leftx in range(<EOL>int(leftx + ow / <NUM_LIT:2>),<EOL>int(leftx)-<NUM_LIT:1>,<EOL>-<NUM_LIT:1><EOL>):<EOL><INDENT>boty = slope * (leftx - rightx) + topy<EOL>if orig.collide_point(leftx * xco, boty * yco):<EOL><INDENT>leftx = float(leftx + <NUM_LIT:1>)<EOL>for pip in range(<NUM_LIT:10>):<EOL><INDENT>leftx -= <NUM_LIT:0.1> * pip<EOL>boty = slope * (leftx - rightx) + topy<EOL>if orig.collide_point(leftx * xco, boty * yco):<EOL><INDENT>break<EOL><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for topy in range(<EOL>int(topy - dh / <NUM_LIT:2>),<EOL>int(topy) + <NUM_LIT:1><EOL>):<EOL><INDENT>rightx = leftx + (topy - boty) / slope<EOL>if dest.collide_point(rightx * xco, topy * yco):<EOL><INDENT>topy = float(topy - <NUM_LIT:1>)<EOL>for pip in range(<NUM_LIT:10>):<EOL><INDENT>topy += <NUM_LIT:0.1> * pip<EOL>rightx = leftx + (topy - boty) / slope<EOL>if dest.collide_point(rightx * xco, topy * yco):<EOL><INDENT>break<EOL><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT>for boty in range(<EOL>int(boty + oh / <NUM_LIT:2>),<EOL>int(boty) - <NUM_LIT:1>,<EOL>-<NUM_LIT:1><EOL>):<EOL><INDENT>leftx = (boty - topy) / slope + rightx<EOL>if orig.collide_point(leftx * xco, boty * yco):<EOL><INDENT>boty = float(boty + <NUM_LIT:1>)<EOL>for pip in range(<NUM_LIT:10>):<EOL><INDENT>boty -= <NUM_LIT:0.1> * pip<EOL>leftx = (boty - topy) / slope + rightx<EOL>if orig.collide_point(leftx * xco, boty * yco):<EOL><INDENT>break<EOL><DEDENT><DEDENT>break<EOL><DEDENT><DEDENT><DEDENT>rise = topy - boty<EOL>run = rightx - leftx<EOL>try:<EOL><INDENT>start_theta = atan(rise/run)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>return up_and_down(orig, dest, taillen)<EOL><DEDENT>try:<EOL><INDENT>end_theta = atan(run/rise)<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>return left_and_right(orig, dest, taillen)<EOL><DEDENT>top_theta = start_theta - fortyfive<EOL>bot_theta = pi - fortyfive - end_theta<EOL>xoff1 = cos(top_theta) * taillen<EOL>yoff1 = sin(top_theta) * taillen<EOL>xoff2 = cos(bot_theta) * taillen<EOL>yoff2 = sin(bot_theta) * taillen<EOL>x1 = (rightx - xoff1) * xco<EOL>x2 = (rightx - xoff2) * xco<EOL>y1 = (topy - yoff1) * yco<EOL>y2 = (topy - yoff2) * yco<EOL>startx = leftx * xco<EOL>starty = boty * yco<EOL>endx = rightx * xco<EOL>endy = topy * yco<EOL>return (<EOL>[startx, starty, endx, endy],<EOL>[x1, y1, endx, endy, x2, y2]<EOL>)<EOL>
Return a pair of lists of points for use making an arrow. The first list is the beginning and end point of the trunk of the arrow. The second list is the arrowhead.
f8990:m2
def on_portal(self, *args):
if not (<EOL>self.board and<EOL>self.origin and<EOL>self.destination and<EOL>self.origin.name in self.board.character.portal and<EOL>self.destination.name in self.board.character.portal<EOL>):<EOL><INDENT>Clock.schedule_once(self.on_portal, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self.name = '<STR_LIT>'.format(self.portal['<STR_LIT>'], self.portal['<STR_LIT>'])<EOL>
Set my ``name`` and instantiate my ``mirrormap`` as soon as I have the properties I need to do so.
f8990:c0:m0
def collide_point(self, x, y):
if not self.collider:<EOL><INDENT>return False<EOL><DEDENT>return (x, y) in self.collider<EOL>
Delegate to my ``collider``, or return ``False`` if I don't have one.
f8990:c0:m1
def __init__(self, **kwargs):
self._trigger_repoint = Clock.create_trigger(<EOL>self._repoint,<EOL>timeout=-<NUM_LIT:1><EOL>)<EOL>super().__init__(**kwargs)<EOL>
Create trigger for my _repoint method. Delegate to parent for everything else.
f8990:c0:m2
def on_origin(self, *args):
if self.origin is None:<EOL><INDENT>Clock.schedule_once(self.on_origin, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self.origin.bind(<EOL>pos=self._trigger_repoint,<EOL>size=self._trigger_repoint<EOL>)<EOL>
Make sure to redraw whenever the origin moves.
f8990:c0:m3
def on_destination(self, *args):
if self.destination is None:<EOL><INDENT>Clock.schedule_once(self.on_destination, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self.destination.bind(<EOL>pos=self._trigger_repoint,<EOL>size=self._trigger_repoint<EOL>)<EOL>
Make sure to redraw whenever the destination moves.
f8990:c0:m4
def on_board(self, *args):
if None in (<EOL>self.board,<EOL>self.origin,<EOL>self.destination<EOL>):<EOL><INDENT>Clock.schedule_once(self.on_board, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>self._trigger_repoint()<EOL>
Draw myself for the first time as soon as I have the properties I need to do so.
f8990:c0:m5
def add_widget(self, wid, index=<NUM_LIT:0>, canvas=None):
super().add_widget(wid, index, canvas)<EOL>if not hasattr(wid, '<STR_LIT>'):<EOL><INDENT>return<EOL><DEDENT>wid._no_use_canvas = True<EOL>mycanvas = (<EOL>self.canvas.before if canvas == '<STR_LIT>' else<EOL>self.canvas.after if canvas == '<STR_LIT>' else<EOL>self.canvas<EOL>)<EOL>mycanvas.remove(wid.canvas)<EOL>pawncanvas = (<EOL>self.board.spotlayout.canvas.before if canvas == '<STR_LIT>' else<EOL>self.board.spotlayout.canvas.after if canvas == '<STR_LIT>' else<EOL>self.board.spotlayout.canvas<EOL>)<EOL>for child in self.children:<EOL><INDENT>if hasattr(child, '<STR_LIT>') and child.group in pawncanvas.children:<EOL><INDENT>pawncanvas.remove(child.group)<EOL><DEDENT>pawncanvas.add(child.group)<EOL><DEDENT>self.pospawn(wid)<EOL>
Put the :class:`Pawn` at a point along my length proportionate to how close it is to finishing its travel through me. Only :class:`Pawn` should ever be added as a child of :class:`Arrow`.
f8990:c0:m6
def remove_widget(self, wid):
super().remove_widget(wid)<EOL>wid._no_use_canvas = False<EOL>
Remove the special :class:`InstructionGroup` I was using to draw this :class:`Pawn`.
f8990:c0:m7
def on_points(self, *args):
for pawn in self.children:<EOL><INDENT>self.pospawn(pawn)<EOL><DEDENT>
Reposition my children when I have new points.
f8990:c0:m8
def pos_along(self, pct):
if pct < <NUM_LIT:0> or pct > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>(ox, oy) = self.origin.center<EOL>(dx, dy) = self.destination.center<EOL>xdist = (dx - ox) * pct<EOL>ydist = (dy - oy) * pct<EOL>return (ox + xdist, oy + ydist)<EOL>
Return coordinates for where a Pawn should be if it has travelled along ``pct`` of my length (between 0 and 1). Might get complex when I switch over to using beziers for arrows, but for now this is quite simple, using distance along a line segment.
f8990:c0:m9
def pospawn(self, pawn):
if self._turn < pawn.thing['<STR_LIT>']:<EOL><INDENT>pawn.pos = self.pos_along(<NUM_LIT:0>)<EOL>return<EOL><DEDENT>elif (<EOL>pawn.thing['<STR_LIT>'] and<EOL>self._turn >= pawn.thing['<STR_LIT>']<EOL>):<EOL><INDENT>pawn.pos = self.pos_along(<NUM_LIT:1>)<EOL>return<EOL><DEDENT>try:<EOL><INDENT>pawn.pos = self.pos_along(<EOL>(<EOL>self._turn -<EOL>pawn.thing['<STR_LIT>']<EOL>) / (<EOL>pawn.thing['<STR_LIT>'] -<EOL>pawn.thing['<STR_LIT>']<EOL>)<EOL>)<EOL><DEDENT>except (TypeError, ZeroDivisionError):<EOL><INDENT>pawn.pos = self.pos_along(<NUM_LIT:0>)<EOL><DEDENT>
Position a :class:`Pawn` that is my child so as to reflect how far its :class:`Thing` has gone along my :class:`Portal`.
f8990:c0:m10
def _get_points(self):
return get_points(self.origin, self.destination, self.arrowhead_size)<EOL>
Return the coordinates of the points that describe my shape.
f8990:c0:m11
def _get_slope(self):
orig = self.origin<EOL>dest = self.destination<EOL>ox = orig.x<EOL>oy = orig.y<EOL>dx = dest.x<EOL>dy = dest.y<EOL>if oy == dy:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>elif ox == dx:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>rise = dy - oy<EOL>run = dx - ox<EOL>return rise / run<EOL><DEDENT>
Return a float of the increase in y divided by the increase in x, both from left to right.
f8990:c0:m12
def _get_b(self):
orig = self.origin<EOL>dest = self.destination<EOL>(ox, oy) = orig.pos<EOL>(dx, dy) = dest.pos<EOL>denominator = dx - ox<EOL>x_numerator = (dy - oy) * ox<EOL>y_numerator = denominator * oy<EOL>return ((y_numerator - x_numerator), denominator)<EOL>
Return my Y-intercept. I probably don't really hit the left edge of the window, but this is where I would, if I were long enough.
f8990:c0:m13
def _repoint(self, *args):
if None in (self.origin, self.destination):<EOL><INDENT>Clock.schedule_once(self._repoint, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>try:<EOL><INDENT>(self.trunk_points, self.head_points) = self._get_points()<EOL><DEDENT>except ValueError:<EOL><INDENT>self.trunk_points = self.head_points = []<EOL>return<EOL><DEDENT>(ox, oy, dx, dy) = self.trunk_points<EOL>r = self.w / <NUM_LIT:2><EOL>bgr = r * self.bg_scale_selected if self.selectedelse self.bg_scale_unselected<EOL>self.trunk_quad_vertices_bg = get_thin_rect_vertices(<EOL>ox, oy, dx, dy, bgr<EOL>)<EOL>self.collider = Collide2DPoly(self.trunk_quad_vertices_bg)<EOL>self.trunk_quad_vertices_fg = get_thin_rect_vertices(ox, oy, dx, dy, r)<EOL>(x1, y1, endx, endy, x2, y2) = self.head_points<EOL>self.left_head_quad_vertices_bg = get_thin_rect_vertices(<EOL>x1, y1, endx, endy, bgr<EOL>)<EOL>self.right_head_quad_vertices_bg = get_thin_rect_vertices(<EOL>x2, y2, endx, endy, bgr<EOL>)<EOL>self.left_head_quad_vertices_fg = get_thin_rect_vertices(<EOL>x1, y1, endx, endy, r<EOL>)<EOL>self.right_head_quad_vertices_fg = get_thin_rect_vertices(<EOL>x2, y2, endx, endy, r<EOL>)<EOL>self.slope = self._get_slope()<EOL>self.y_intercept = self._get_b()<EOL>self.repointed = True<EOL>
Recalculate points, y-intercept, and slope
f8990:c0:m14
def _get_reciprocal(self):
orign = self.portal['<STR_LIT>']<EOL>destn = self.portal['<STR_LIT>']<EOL>if (<EOL>destn in self.board.arrow and<EOL>orign in self.board.arrow[destn]<EOL>):<EOL><INDENT>return self.board.arrow[destn][orign]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
Return the :class:`Arrow` that connects my origin and destination in the opposite direction, if it exists.
f8990:c1:m0
def on_touch_move(self, touch):
if touch.grab_current is not self:<EOL><INDENT>return False<EOL><DEDENT>self.center = touch.pos<EOL>return True<EOL>
If I'm being dragged, move to follow the touch.
f8992:c0:m2
def finalize(self, initial=True):
if getattr(self, '<STR_LIT>', False):<EOL><INDENT>return<EOL><DEDENT>if (<EOL>self.proxy is None or<EOL>not hasattr(self.proxy, '<STR_LIT:name>')<EOL>):<EOL><INDENT>Clock.schedule_once(self.finalize, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>if initial:<EOL><INDENT>self.name = self.proxy.name<EOL>self.paths = self.proxy.setdefault(<EOL>'<STR_LIT>', self.default_image_paths<EOL>)<EOL>zeroes = [<NUM_LIT:0>] * len(self.paths)<EOL>self.offxs = self.proxy.setdefault('<STR_LIT>', zeroes)<EOL>self.offys = self.proxy.setdefault('<STR_LIT>', zeroes)<EOL>self.proxy.connect(self._trigger_pull_from_proxy)<EOL><DEDENT>self.bind(<EOL>paths=self._trigger_push_image_paths,<EOL>offxs=self._trigger_push_offxs,<EOL>offys=self._trigger_push_offys<EOL>)<EOL>self._finalized = True<EOL>self.finalize_children()<EOL>
Call this after you've created all the PawnSpot you need and are ready to add them to the board.
f8992:c0:m3
def on_linecolor(self, *args):
if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.color.rgba = self.linecolor<EOL>return<EOL><DEDENT>def upd_box_translate(*args):<EOL><INDENT>self.box_translate.xy = self.pos<EOL><DEDENT>def upd_box_points(*args):<EOL><INDENT>self.box.points = [<NUM_LIT:0>, <NUM_LIT:0>, self.width, <NUM_LIT:0>, self.width, self.height, <NUM_LIT:0>, self.height, <NUM_LIT:0>, <NUM_LIT:0>]<EOL><DEDENT>self.boxgrp = boxgrp = InstructionGroup()<EOL>self.color = Color(*self.linecolor)<EOL>self.box_translate = Translate(*self.pos)<EOL>boxgrp.add(PushMatrix())<EOL>boxgrp.add(self.box_translate)<EOL>boxgrp.add(self.color)<EOL>self.box = Line()<EOL>upd_box_points()<EOL>self.bind(<EOL>size=upd_box_points,<EOL>pos=upd_box_translate<EOL>)<EOL>boxgrp.add(self.box)<EOL>boxgrp.add(Color(<NUM_LIT:1.>, <NUM_LIT:1.>, <NUM_LIT:1.>))<EOL>boxgrp.add(PopMatrix())<EOL>
If I don't yet have the instructions for drawing the selection box in my canvas, put them there. In any case, set the :class:`Color` instruction to match my current ``linecolor``.
f8992:c0:m11
def on_touch_down(self, touch):
if not self.collide_point(*touch.pos):<EOL><INDENT>return False<EOL><DEDENT>self.pos_start = self.pos<EOL>self.pos_down = (<EOL>self.x - touch.x,<EOL>self.y - touch.y<EOL>)<EOL>touch.grab(self)<EOL>self._touch = touch<EOL>return True<EOL>
If hit, record my starting position, that I may return to it in ``on_touch_up`` after creating a real :class:`board.Spot` or :class:`board.Pawn` instance.
f8993:c0:m1
def on_touch_move(self, touch):
if touch is not self._touch:<EOL><INDENT>return False<EOL><DEDENT>self.pos = (<EOL>touch.x + self.x_down,<EOL>touch.y + self.y_down<EOL>)<EOL>return True<EOL>
Follow the touch
f8993:c0:m2
def on_touch_up(self, touch):
if touch is not self._touch:<EOL><INDENT>return False<EOL><DEDENT>self.pos_up = self.pos<EOL>self.pos = self.pos_start<EOL>self._touch = None<EOL>return True<EOL>
Return to ``pos_start``, but first, save my current ``pos`` into ``pos_up``, so that the layout knows where to put the real :class:`board.Spot` or :class:`board.Pawn` instance.
f8993:c0:m3
def toggle_chars_screen(self, *args):
<EOL>self.app.chars.toggle()<EOL>
Display or hide the list you use to switch between characters.
f8994:c0:m5
def toggle_rules(self, *args):
if self.app.manager.current != '<STR_LIT>' and not isinstance(self.app.selected_proxy, CharStatProxy):<EOL><INDENT>self.app.rules.entity = self.app.selected_proxy<EOL>self.app.rules.rulebook = self.app.selected_proxy.rulebook<EOL><DEDENT>if isinstance(self.app.selected_proxy, CharStatProxy):<EOL><INDENT>self.app.charrules.character = self.app.selected_proxy<EOL>self.app.charrules.toggle()<EOL><DEDENT>else:<EOL><INDENT>self.app.rules.toggle()<EOL><DEDENT>
Display or hide the view for constructing rules out of cards.
f8994:c0:m6
def toggle_funcs_editor(self):
self.app.funcs.toggle()<EOL>
Display or hide the text editing window for functions.
f8994:c0:m7
def toggle_spot_cfg(self):
if self.app.manager.current == '<STR_LIT>':<EOL><INDENT>dummyplace = self.screendummyplace<EOL>self.ids.placetab.remove_widget(dummyplace)<EOL>dummyplace.clear()<EOL>if self.app.spotcfg.prefix:<EOL><INDENT>dummyplace.prefix = self.app.spotcfg.prefix<EOL>dummyplace.num = dummynum(<EOL>self.app.character, dummyplace.prefix<EOL>) + <NUM_LIT:1><EOL><DEDENT>dummyplace.paths = self.app.spotcfg.imgpaths<EOL>self.ids.placetab.add_widget(dummyplace)<EOL><DEDENT>else:<EOL><INDENT>self.app.spotcfg.prefix = self.ids.dummyplace.prefix<EOL><DEDENT>self.app.spotcfg.toggle()<EOL>
Show the dialog where you select graphics and a name for a place, or hide it if already showing.
f8994:c0:m9
def toggle_pawn_cfg(self):
if self.app.manager.current == '<STR_LIT>':<EOL><INDENT>dummything = self.app.dummything<EOL>self.ids.thingtab.remove_widget(dummything)<EOL>dummything.clear()<EOL>if self.app.pawncfg.prefix:<EOL><INDENT>dummything.prefix = self.app.pawncfg.prefix<EOL>dummything.num = dummynum(<EOL>self.app.character, dummything.prefix<EOL>) + <NUM_LIT:1><EOL><DEDENT>if self.app.pawncfg.imgpaths:<EOL><INDENT>dummything.paths = self.app.pawncfg.imgpaths<EOL><DEDENT>else:<EOL><INDENT>dummything.paths = ['<STR_LIT>']<EOL><DEDENT>self.ids.thingtab.add_widget(dummything)<EOL><DEDENT>else:<EOL><INDENT>self.app.pawncfg.prefix = self.ids.dummything.prefix<EOL><DEDENT>self.app.pawncfg.toggle()<EOL>
Show or hide the pop-over where you can configure the dummy pawn
f8994:c0:m10
def toggle_reciprocal(self):
self.screen.boardview.reciprocal_portal = not self.screen.boardview.reciprocal_portal<EOL>if self.screen.boardview.reciprocal_portal:<EOL><INDENT>assert(self.revarrow is None)<EOL>self.revarrow = ArrowWidget(<EOL>board=self.screen.boardview.board,<EOL>origin=self.ids.emptyright,<EOL>destination=self.ids.emptyleft<EOL>)<EOL>self.ids.portaladdbut.add_widget(self.revarrow)<EOL><DEDENT>else:<EOL><INDENT>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.ids.portaladdbut.remove_widget(self.revarrow)<EOL>self.revarrow = None<EOL><DEDENT><DEDENT>
Flip my ``reciprocal_portal`` boolean, and draw (or stop drawing) an extra arrow on the appropriate button to indicate the fact.
f8994:c0:m11
def __init__(self, **kwargs):
kwargs['<STR_LIT>'] = False<EOL>super().__init__(**kwargs)<EOL>self.bind(on_text_validate=self.on_enter)<EOL>
Disable multiline, and bind ``on_text_validate`` to ``on_enter``
f8995:c0:m0
def on_enter(self, *args):
if self.text == '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>self.setter(self.text)<EOL>self.text = '<STR_LIT>'<EOL>self.focus = False<EOL>
Call the setter and blank myself out so that my hint text shows up. It will be the same you just entered if everything's working.
f8995:c0:m1
def on_focus(self, *args):
if not self.focus:<EOL><INDENT>self.on_enter(*args)<EOL><DEDENT>
If I've lost focus, treat it as if the user hit Enter.
f8995:c0:m2
def on_text_validate(self, *args):
self.on_enter()<EOL>
Equivalent to hitting Enter.
f8995:c0:m3
def insert_text(self, s, from_undo=False):
return super().insert_text(<EOL>'<STR_LIT>'.join(c for c in s if c in '<STR_LIT>'),<EOL>from_undo<EOL>)<EOL>
Natural numbers only.
f8995:c1:m0
def advance_dialog(self, *args):
self.clear_widgets()<EOL>try:<EOL><INDENT>self._update_dialog(self.todo[self.idx])<EOL><DEDENT>except IndexError:<EOL><INDENT>pass<EOL><DEDENT>
Try to display the next dialog described in my ``todo``.
f8997:c5:m4
def ok(self, *args, cb=None):
self.clear_widgets()<EOL>if cb:<EOL><INDENT>cb()<EOL><DEDENT>self.idx += <NUM_LIT:1><EOL>self.advance_dialog()<EOL>
Clear dialog widgets, call ``cb`` if provided, and advance the dialog queue
f8997:c5:m6
def set_value(self, *args):
self.sett(self.key, self.value)<EOL>
Use my ``sett`` function to set my stat (``key``) to my new ``value``. This doesn't need arguments, but accepts any positional arguments provided, so that you can use this in kvlang
f8998:c5:m0
def remake(self, *args):
if not self.config:<EOL><INDENT>return<EOL><DEDENT>if not all((self.key, self.gett, self.sett, self.listen, self.unlisten)):<EOL><INDENT>Clock.schedule_once(self.remake, <NUM_LIT:0>)<EOL>return<EOL><DEDENT>if not hasattr(self, '<STR_LIT:label>'):<EOL><INDENT>self.label = Label(text=str(self.key))<EOL>def updlabel(*args):<EOL><INDENT>self.label.text = str(self.key)<EOL><DEDENT>self.bind(key=updlabel)<EOL>self.add_widget(self.label)<EOL><DEDENT>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.remove_widget(self.wid)<EOL>del self.wid<EOL><DEDENT>control = self.config['<STR_LIT>']<EOL>widkwargs = {<EOL>'<STR_LIT:key>': self.key,<EOL>'<STR_LIT>': self.gett,<EOL>'<STR_LIT>': self.sett,<EOL>'<STR_LIT>': self.listen,<EOL>'<STR_LIT>': self.unlisten<EOL>}<EOL>if control == '<STR_LIT>':<EOL><INDENT>cls = StatRowSlider<EOL>try:<EOL><INDENT>widkwargs['<STR_LIT:value>'] = float(self.gett(self.key))<EOL>widkwargs['<STR_LIT>'] = float(self.config['<STR_LIT>'])<EOL>widkwargs['<STR_LIT>'] = float(self.config['<STR_LIT>'])<EOL><DEDENT>except (KeyError, ValueError):<EOL><INDENT>return<EOL><DEDENT><DEDENT>elif control == '<STR_LIT>':<EOL><INDENT>cls = StatRowToggleButton<EOL>try:<EOL><INDENT>widkwargs['<STR_LIT>'] = self.config['<STR_LIT>']<EOL>widkwargs['<STR_LIT>'] = self.config['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>return<EOL><DEDENT><DEDENT>elif control == '<STR_LIT>':<EOL><INDENT>cls = StatRowTextInput<EOL><DEDENT>else:<EOL><INDENT>cls = StatRowLabel<EOL><DEDENT>self.wid = cls(**widkwargs)<EOL>self.bind(<EOL>key=self.wid.setter('<STR_LIT:key>'),<EOL>gett=self.wid.setter('<STR_LIT>'),<EOL>sett=self.wid.setter('<STR_LIT>'),<EOL>listen=self.wid.setter('<STR_LIT>'),<EOL>unlisten=self.wid.setter('<STR_LIT>')<EOL>)<EOL>if control == '<STR_LIT>':<EOL><INDENT>self.unbind(config=self._toggle_update_config)<EOL>self.bind(config=self._slider_update_config)<EOL><DEDENT>elif control == '<STR_LIT>':<EOL><INDENT>self.unbind(config=self._slider_update_config)<EOL>self.bind(config=self._toggle_update_config)<EOL><DEDENT>else:<EOL><INDENT>self.unbind(config=self._slider_update_config)<EOL>self.unbind(config=self._toggle_update_config)<EOL><DEDENT>self.add_widget(self.wid)<EOL>
Replace any existing child widget with the one described by my ``config``. This doesn't need arguments, but accepts any positional arguments provided, so that you can use this in kvlang
f8998:c5:m5
def del_key(self, k):
if k not in self.mirror:<EOL><INDENT>raise KeyError<EOL><DEDENT>del self.proxy[k]<EOL>if '<STR_LIT>' in self.proxy and k in self.proxy['<STR_LIT>']:<EOL><INDENT>del self.proxy['<STR_LIT>'][k]<EOL><DEDENT>
Delete the key and any configuration for it
f8998:c6:m2
def set_value(self, k, v):
from ast import literal_eval<EOL>if self.engine is None or self.proxy is None:<EOL><INDENT>self._trigger_set_value(k, v)<EOL>return<EOL><DEDENT>if v is None:<EOL><INDENT>del self.proxy[k]<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>vv = literal_eval(v)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>vv = v<EOL><DEDENT>self.proxy[k] = vv<EOL><DEDENT>
Set a value on the proxy, parsing it to a useful datatype if possible
f8998:c6:m3
def init_config(self, key):
self.proxy['<STR_LIT>'].setdefault(key, default_cfg)<EOL>
Set the configuration for the key to something that will always work
f8998:c6:m5
def set_config(self, key, option, value):
if '<STR_LIT>' not in self.proxy:<EOL><INDENT>newopt = dict(default_cfg)<EOL>newopt[option] = value<EOL>self.proxy['<STR_LIT>'] = {key: newopt}<EOL><DEDENT>else:<EOL><INDENT>if key in self.proxy['<STR_LIT>']:<EOL><INDENT>self.proxy['<STR_LIT>'][key][option] = value<EOL><DEDENT>else:<EOL><INDENT>newopt = dict(default_cfg)<EOL>newopt[option] = value<EOL>self.proxy['<STR_LIT>'][key] = newopt<EOL><DEDENT><DEDENT>
Set a configuration option for a key
f8998:c6:m6
def set_configs(self, key, d):
if '<STR_LIT>' in self.proxy:<EOL><INDENT>self.proxy['<STR_LIT>'][key] = d<EOL><DEDENT>else:<EOL><INDENT>self.proxy['<STR_LIT>'] = {key: d}<EOL><DEDENT>
Set the whole configuration for a key
f8998:c6:m7
def iter_data(self):
for (k, v) in self.proxy.items():<EOL><INDENT>if (<EOL>not (isinstance(k, str) and k[<NUM_LIT:0>] == '<STR_LIT:_>') and<EOL>k not in (<EOL>'<STR_LIT>',<EOL>'<STR_LIT:name>',<EOL>'<STR_LIT:location>'<EOL>)<EOL>):<EOL><INDENT>yield k, v<EOL><DEDENT><DEDENT>
Iterate over key-value pairs that are really meant to be displayed
f8998:c6:m8
def munge(self, k, v):
if '<STR_LIT>' in self.proxy and k in self.proxy['<STR_LIT>']:<EOL><INDENT>config = self.proxy['<STR_LIT>'][k].unwrap()<EOL><DEDENT>else:<EOL><INDENT>config = default_cfg<EOL><DEDENT>return {<EOL>'<STR_LIT:key>': k,<EOL>'<STR_LIT>': self._reg_widget,<EOL>'<STR_LIT>': self._unreg_widget,<EOL>'<STR_LIT>': self.proxy.__getitem__,<EOL>'<STR_LIT>': self.set_value,<EOL>'<STR_LIT>': self.proxy.connect,<EOL>'<STR_LIT>': self.proxy.disconnect,<EOL>'<STR_LIT>': config<EOL>}<EOL>
Turn a key and value into a dictionary describing a widget to show
f8998:c6:m9
def upd_data(self, *args):
data = [self.munge(k, v) for k, v in self.iter_data()]<EOL>self.data = sorted(data, key=lambda d: d['<STR_LIT:key>'])<EOL>
Update to match new entity data
f8998:c6:m10
def set_tick(self, t):
self.tick = int(t)<EOL>
Set my tick to the given value, cast to an integer.
f8999:c0:m5
def select_character(self, char):
if char == self.character:<EOL><INDENT>return<EOL><DEDENT>self.character = char<EOL>
Change my ``character`` to the selected character object if they aren't the same.
f8999:c0:m7
def build_config(self, config):
for sec in '<STR_LIT>', '<STR_LIT>':<EOL><INDENT>config.adddefaultsection(sec)<EOL><DEDENT>config.setdefaults(<EOL>'<STR_LIT>',<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:info>'<EOL>}<EOL>)<EOL>config.setdefaults(<EOL>'<STR_LIT>',<EOL>{<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:yes>',<EOL>'<STR_LIT>': '<STR_LIT:1>',<EOL>'<STR_LIT>': json.dumps([<EOL>("<STR_LIT>", '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>')<EOL>]),<EOL>'<STR_LIT>': json.dumps([<EOL>("<STR_LIT>", '<STR_LIT>'),<EOL>("<STR_LIT>", '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>')<EOL>])<EOL>}<EOL>)<EOL>config.write()<EOL>
Set config defaults
f8999:c0:m8
def build(self):
self.icon = '<STR_LIT>'<EOL>config = self.config<EOL>Logger.debug(<EOL>"<STR_LIT>".format(<EOL>config['<STR_LIT>']['<STR_LIT>'],<EOL>LiSE.__path__[-<NUM_LIT:1>]<EOL>)<EOL>)<EOL>if config['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT:yes>':<EOL><INDENT>import pdb<EOL>pdb.set_trace()<EOL><DEDENT>self.manager = ScreenManager(transition=NoTransition())<EOL>if config['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT:yes>':<EOL><INDENT>from kivy.core.window import Window<EOL>from kivy.modules import inspector<EOL>inspector.create_inspector(Window, self.manager)<EOL><DEDENT>self._start_subprocess()<EOL>self._add_screens()<EOL>return self.manager<EOL>
Make sure I can use the database, create the tables as needed, and return the root widget.
f8999:c0:m9
def on_pause(self):
self.engine.commit()<EOL>self.strings.save()<EOL>self.funcs.save()<EOL>self.config.write()<EOL>
Sync the database with the current state of the game.
f8999:c0:m20
def on_stop(self, *largs):
self.strings.save()<EOL>self.funcs.save()<EOL>self.engine.commit()<EOL>self.procman.shutdown()<EOL>self.config.write()<EOL>
Sync the database, wrap up the game, and halt.
f8999:c0:m21
def delete_selection(self):
selection = self.selection<EOL>if selection is None:<EOL><INDENT>return<EOL><DEDENT>if isinstance(selection, ArrowWidget):<EOL><INDENT>self.mainscreen.boardview.board.rm_arrow(<EOL>selection.origin.name,<EOL>selection.destination.name<EOL>)<EOL>selection.portal.delete()<EOL><DEDENT>elif isinstance(selection, Spot):<EOL><INDENT>self.mainscreen.boardview.board.rm_spot(selection.name)<EOL>selection.proxy.delete()<EOL><DEDENT>else:<EOL><INDENT>assert isinstance(selection, Pawn)<EOL>self.mainscreen.boardview.board.rm_pawn(selection.name)<EOL>selection.proxy.delete()<EOL><DEDENT>self.selection = None<EOL>
Delete both the selected widget and whatever it represents.
f8999:c0:m22
def new_board(self, name):
char = self.engine.character[name]<EOL>board = Board(character=char)<EOL>self.mainscreen.boards[name] = board<EOL>self.character = char<EOL>
Make a board for a character name, and switch to it.
f8999:c0:m23
def _default_args_munger(self, k):
return tuple()<EOL>
By default, :class:`PickyDefaultDict`'s ``type`` is instantiated with no positional arguments.
f9006:m0
def _default_kwargs_munger(self, k):
return {}<EOL>
By default, :class:`PickyDefaultDict`'s ``type`` is instantiated with no keyword arguments.
f9006:m1
def lru_append(kc, lru, kckey, maxsize):
if kckey in lru:<EOL><INDENT>return<EOL><DEDENT>while len(lru) >= maxsize:<EOL><INDENT>(peb, turn, tick), _ = lru.popitem(False)<EOL>if peb not in kc:<EOL><INDENT>continue<EOL><DEDENT>kcpeb = kc[peb]<EOL>if turn not in kcpeb:<EOL><INDENT>continue<EOL><DEDENT>kcpebturn = kcpeb[turn]<EOL>if tick not in kcpebturn:<EOL><INDENT>continue<EOL><DEDENT>del kcpebturn[tick]<EOL>if not kcpebturn:<EOL><INDENT>del kcpeb[turn]<EOL><DEDENT>if not kcpeb:<EOL><INDENT>del kc[peb]<EOL><DEDENT><DEDENT>lru[kckey] = True<EOL>
Delete old data from ``kc``, then add the new ``kckey``. :param kc: a three-layer keycache :param lru: an :class:`OrderedDict` with a key for each triple that should fill out ``kc``'s three layers :param kckey: a triple that indexes into ``kc``, which will be added to ``lru`` if needed :param maxsize: maximum number of entries in ``lru`` and, therefore, ``kc``
f9006:m2
def load(self, data):
branches = defaultdict(list)<EOL>for row in data:<EOL><INDENT>branches[row[-<NUM_LIT:4>]].append(row)<EOL><DEDENT>childbranch = self.db._childbranch<EOL>branch2do = deque(['<STR_LIT>'])<EOL>store = self._store<EOL>while branch2do:<EOL><INDENT>branch = branch2do.popleft()<EOL>for row in branches[branch]:<EOL><INDENT>store(*row, planning=False, loading=True)<EOL><DEDENT>if branch in childbranch:<EOL><INDENT>branch2do.extend(childbranch[branch])<EOL><DEDENT><DEDENT>
Add a bunch of data. Must be in chronological order. But it doesn't need to all be from the same branch, as long as each branch is chronological of itself.
f9006:c2:m1
def _valcache_lookup(self, cache, branch, turn, tick):
if branch in cache:<EOL><INDENT>branc = cache[branch]<EOL>try:<EOL><INDENT>if turn in branc and branc[turn].rev_gettable(tick):<EOL><INDENT>return branc[turn][tick]<EOL><DEDENT>elif branc.rev_gettable(turn-<NUM_LIT:1>):<EOL><INDENT>turnd = branc[turn-<NUM_LIT:1>]<EOL>return turnd[turnd.end]<EOL><DEDENT><DEDENT>except HistoryError as ex:<EOL><INDENT>if ex.deleted:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>for b, r, t in self.db._iter_parent_btt(branch, turn, tick):<EOL><INDENT>if b in cache:<EOL><INDENT>if r in cache[b] and cache[b][r].rev_gettable(t):<EOL><INDENT>try:<EOL><INDENT>return cache[b][r][t]<EOL><DEDENT>except HistoryError as ex:<EOL><INDENT>if ex.deleted:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>elif cache[b].rev_gettable(r-<NUM_LIT:1>):<EOL><INDENT>cbr = cache[b][r-<NUM_LIT:1>]<EOL>try:<EOL><INDENT>return cbr[cbr.end]<EOL><DEDENT>except HistoryError as ex:<EOL><INDENT>if ex.deleted:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Return the value at the given time in ``cache``
f9006:c2:m2
def _get_keycachelike(self, keycache, keys, get_adds_dels, parentity, branch, turn, tick, *, forward):
keycache_key = parentity + (branch,)<EOL>keycache2 = keycache3 = None<EOL>if keycache_key in keycache:<EOL><INDENT>keycache2 = keycache[keycache_key]<EOL>if turn in keycache2:<EOL><INDENT>keycache3 = keycache2[turn]<EOL>if tick in keycache3:<EOL><INDENT>return keycache3[tick]<EOL><DEDENT><DEDENT><DEDENT>if forward:<EOL><INDENT>if keycache2 and keycache2.rev_gettable(turn):<EOL><INDENT>if turn not in keycache2:<EOL><INDENT>old_turn = keycache2.rev_before(turn)<EOL>old_turn_kc = keycache2[turn]<EOL>added, deleted = get_adds_dels(<EOL>keys[parentity], branch, turn, tick, stoptime=(<EOL>branch, old_turn, old_turn_kc.end<EOL>)<EOL>)<EOL>ret = old_turn_kc[old_turn_kc.end].union(added).difference(deleted)<EOL>new_turn_kc = WindowDict()<EOL>new_turn_kc[tick] = ret<EOL>keycache2[turn] = new_turn_kc<EOL>return ret<EOL><DEDENT>if not keycache3:<EOL><INDENT>keycache3 = keycache2[turn]<EOL><DEDENT>if tick not in keycache3:<EOL><INDENT>if keycache3.rev_gettable(tick):<EOL><INDENT>added, deleted = get_adds_dels(<EOL>keys[parentity], branch, turn, tick, stoptime=(<EOL>branch, turn, keycache3.rev_before(tick)<EOL>)<EOL>)<EOL>ret = keycache3[tick].union(added).difference(deleted)<EOL>keycache3[tick] = ret<EOL>return ret<EOL><DEDENT>else:<EOL><INDENT>turn_before = keycache2.rev_before(turn)<EOL>tick_before = keycache2[turn_before].end<EOL>keys_before = keycache2[turn_before][tick_before]<EOL>added, deleted = get_adds_dels(<EOL>keys[parentity], branch, turn, tick, stoptime=(<EOL>branch, turn_before, tick_before<EOL>)<EOL>)<EOL>ret = keycache3[tick] = keys_before.union(added).difference(deleted)<EOL>return ret<EOL><DEDENT><DEDENT>return keycache3[tick]<EOL><DEDENT>else:<EOL><INDENT>for (parbranch, parturn, partick) in self.db._iter_parent_btt(branch, turn, tick):<EOL><INDENT>par_kc_key = parentity + (parbranch,)<EOL>if par_kc_key in keycache:<EOL><INDENT>kcpkc = keycache[par_kc_key]<EOL>if parturn in kcpkc and kcpkc[parturn].rev_gettable(partick):<EOL><INDENT>parkeys = kcpkc[parturn][partick]<EOL>break<EOL><DEDENT>elif kcpkc.rev_gettable(parturn-<NUM_LIT:1>):<EOL><INDENT>partkeys = kcpkc[parturn-<NUM_LIT:1>]<EOL>parkeys = partkeys[partkeys.end]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>parkeys = frozenset()<EOL><DEDENT>keycache2 = SettingsTurnDict()<EOL>added, deleted = get_adds_dels(<EOL>keys[parentity], branch, turn, tick, stoptime=(<EOL>parbranch, parturn, partick<EOL>)<EOL>)<EOL>ret = parkeys.union(added).difference(deleted)<EOL>keycache2[turn] = {tick: ret}<EOL>keycache[keycache_key] = keycache2<EOL>return ret<EOL><DEDENT><DEDENT>ret = frozenset(get_adds_dels(keys[parentity], branch, turn, tick)[<NUM_LIT:0>])<EOL>if keycache2:<EOL><INDENT>if keycache3:<EOL><INDENT>keycache3[tick] = ret<EOL><DEDENT>else:<EOL><INDENT>keycache2[turn] = {tick: ret}<EOL><DEDENT><DEDENT>else:<EOL><INDENT>kcc = SettingsTurnDict()<EOL>kcc[turn] = {tick: ret}<EOL>keycache[keycache_key] = kcc<EOL><DEDENT>return ret<EOL>
Try to retrieve a frozenset representing extant keys. If I can't, generate one, store it, and return it.
f9006:c2:m3
def _get_keycache(self, parentity, branch, turn, tick, *, forward):
lru_append(self.keycache, self._kc_lru, (parentity+(branch,), turn, tick), KEYCACHE_MAXSIZE)<EOL>return self._get_keycachelike(<EOL>self.keycache, self.keys, self._get_adds_dels,<EOL>parentity, branch, turn, tick, forward=forward<EOL>)<EOL>
Get a frozenset of keys that exist in the entity at the moment. With ``forward=True``, enable an optimization that copies old key sets forward and updates them.
f9006:c2:m4
def _update_keycache(self, *args, forward):
entity, key, branch, turn, tick, value = args[-<NUM_LIT:6>:]<EOL>parent = args[:-<NUM_LIT:6>]<EOL>kc = self._get_keycache(parent + (entity,), branch, turn, tick, forward=forward)<EOL>if value is None:<EOL><INDENT>kc = kc.difference((key,))<EOL><DEDENT>else:<EOL><INDENT>kc = kc.union((key,))<EOL><DEDENT>self.keycache[parent+(entity, branch)][turn][tick] = kc<EOL>
Add or remove a key in the set describing the keys that exist.
f9006:c2:m5
def _get_adds_dels(self, cache, branch, turn, tick, *, stoptime=None):
added = set()<EOL>deleted = set()<EOL>for key, branches in cache.items():<EOL><INDENT>for (branc, trn, tck) in self.db._iter_parent_btt(branch, turn, tick, stoptime=stoptime):<EOL><INDENT>if branc not in branches or not branches[branc].rev_gettable(trn):<EOL><INDENT>continue<EOL><DEDENT>turnd = branches[branc]<EOL>if trn in turnd:<EOL><INDENT>if turnd[trn].rev_gettable(tck):<EOL><INDENT>if turnd[trn][tck] is None:<EOL><INDENT>deleted.add(key)<EOL><DEDENT>else:<EOL><INDENT>added.add(key)<EOL><DEDENT>break<EOL><DEDENT>else:<EOL><INDENT>trn -= <NUM_LIT:1><EOL><DEDENT><DEDENT>if not turnd.rev_gettable(trn):<EOL><INDENT>break<EOL><DEDENT>tickd = turnd[trn]<EOL>if tickd[tickd.end] is None:<EOL><INDENT>deleted.add(key)<EOL><DEDENT>else:<EOL><INDENT>added.add(key)<EOL><DEDENT>break<EOL><DEDENT><DEDENT>return added, deleted<EOL>
Return a pair of ``(added, deleted)`` sets describing changes since ``stoptime``. With ``stoptime=None`` (the default), ``added`` will in fact be all keys.
f9006:c2:m6
def store(self, *args, planning=None, forward=None, loading=False, contra=True):
db = self.db<EOL>if planning is None:<EOL><INDENT>planning = db._planning<EOL><DEDENT>if forward is None:<EOL><INDENT>forward = db._forward<EOL><DEDENT>self._store(*args, planning=planning, loading=loading, contra=contra)<EOL>if not db._no_kc:<EOL><INDENT>self._update_keycache(*args, forward=forward)<EOL><DEDENT>self.send(self, key=args[-<NUM_LIT:5>], branch=args[-<NUM_LIT:4>], turn=args[-<NUM_LIT:3>], tick=args[-<NUM_LIT:2>], value=args[-<NUM_LIT:1>], action='<STR_LIT:store>')<EOL>
Put a value in various dictionaries for later .retrieve(...). Needs at least five arguments, of which the -1th is the value to store, the -2th is the tick to store it at, the -3th is the turn to store it in, the -4th is the branch the revision is in, the -5th is the key the value is for, and the remaining arguments identify the entity that has the key, eg. a graph, node, or edge. With ``planning=True``, you will be permitted to alter "history" that takes place after the last non-planning moment of time, without much regard to consistency. Otherwise, contradictions will be handled by deleting everything in the contradicted plan after the present moment, unless you set ``contra=False``. ``loading=True`` prevents me from updating the ORM's records of the ends of branches and turns.
f9006:c2:m7
def remove(self, branch, turn, tick):
time_entity, parents, branches, keys, settings, presettings, remove_keycache, send = self._remove_stuff<EOL>parent, entity, key = time_entity[branch, turn, tick]<EOL>branchkey = parent + (entity, key)<EOL>keykey = parent + (entity,)<EOL>if parent in parents:<EOL><INDENT>parentt = parents[parent]<EOL>if entity in parentt:<EOL><INDENT>entty = parentt[entity]<EOL>if key in entty:<EOL><INDENT>kee = entty[key]<EOL>if branch in kee:<EOL><INDENT>branhc = kee[branch]<EOL>if turn in branhc:<EOL><INDENT>trn = branhc[turn]<EOL>del trn[tick]<EOL>if not trn:<EOL><INDENT>del branhc[turn]<EOL><DEDENT>if not branhc:<EOL><INDENT>del kee[branch]<EOL><DEDENT><DEDENT><DEDENT>if not kee:<EOL><INDENT>del entty[key]<EOL><DEDENT><DEDENT>if not entty:<EOL><INDENT>del parentt[entity]<EOL><DEDENT><DEDENT>if not parentt:<EOL><INDENT>del parents[parent]<EOL><DEDENT><DEDENT>if branchkey in branches:<EOL><INDENT>entty = branches[branchkey]<EOL>if branch in entty:<EOL><INDENT>branhc = entty[branch]<EOL>if turn in branhc:<EOL><INDENT>trn = branhc[turn]<EOL>if tick in trn:<EOL><INDENT>del trn[tick]<EOL><DEDENT>if not trn:<EOL><INDENT>del branhc[turn]<EOL><DEDENT><DEDENT>if not branhc:<EOL><INDENT>del entty[branch]<EOL><DEDENT><DEDENT>if not entty:<EOL><INDENT>del branches[branchkey]<EOL><DEDENT><DEDENT>if keykey in keys:<EOL><INDENT>entty = keys[keykey]<EOL>if key in entty:<EOL><INDENT>kee = entty[key]<EOL>if branch in kee:<EOL><INDENT>branhc = kee[branch]<EOL>if turn in branhc:<EOL><INDENT>trn = entty[turn]<EOL>if tick in trn:<EOL><INDENT>del trn[tick]<EOL><DEDENT>if not trn:<EOL><INDENT>del branhc[turn]<EOL><DEDENT><DEDENT>if not branhc:<EOL><INDENT>del kee[branch]<EOL><DEDENT><DEDENT>if not kee:<EOL><INDENT>del entty[key]<EOL><DEDENT><DEDENT>if not entty:<EOL><INDENT>del keys[keykey]<EOL><DEDENT><DEDENT>branhc = settings[branch]<EOL>pbranhc = presettings[branch]<EOL>trn = branhc[turn]<EOL>ptrn = pbranhc[turn]<EOL>if tick in trn:<EOL><INDENT>del trn[tick]<EOL><DEDENT>if tick in ptrn:<EOL><INDENT>del ptrn[tick]<EOL><DEDENT>if not ptrn:<EOL><INDENT>del pbranhc[turn]<EOL>del branhc[turn]<EOL><DEDENT>if not pbranhc:<EOL><INDENT>del settings[branch]<EOL>del presettings[branch]<EOL><DEDENT>self.shallowest = OrderedDict()<EOL>remove_keycache(parent + (entity, branch), turn, tick)<EOL>send(self, branch=branch, turn=turn, tick=tick, action='<STR_LIT>')<EOL>
Delete all data from a specific tick
f9006:c2:m8
def _remove_keycache(self, entity_branch, turn, tick):
keycache = self.keycache<EOL>if entity_branch in keycache:<EOL><INDENT>kc = keycache[entity_branch]<EOL>if turn in kc:<EOL><INDENT>kcturn = kc[turn]<EOL>if tick in kcturn:<EOL><INDENT>del kcturn[tick]<EOL><DEDENT>kcturn.truncate(tick)<EOL>if not kcturn:<EOL><INDENT>del kc[turn]<EOL><DEDENT><DEDENT>kc.truncate(turn)<EOL>if not kc:<EOL><INDENT>del keycache[entity_branch]<EOL><DEDENT><DEDENT>
Remove the future of a given entity from a branch in the keycache
f9006:c2:m9
def truncate(self, branch, turn, tick):
parents, branches, keys, settings, presettings, keycache, send = self._truncate_stuff<EOL>def truncate_branhc(branhc):<EOL><INDENT>if turn in branhc:<EOL><INDENT>trn = branhc[turn]<EOL>trn.truncate(tick)<EOL>branhc.truncate(turn)<EOL>if not trn:<EOL><INDENT>del branhc[turn]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>branhc.truncate(turn)<EOL><DEDENT><DEDENT>for entities in parents.values():<EOL><INDENT>for keys in entities.values():<EOL><INDENT>for branches in keys.values():<EOL><INDENT>if branch not in branches:<EOL><INDENT>continue<EOL><DEDENT>truncate_branhc(branches[branch])<EOL><DEDENT><DEDENT><DEDENT>for branches in branches.values():<EOL><INDENT>if branch not in branches:<EOL><INDENT>continue<EOL><DEDENT>truncate_branhc(branches[branch])<EOL><DEDENT>for keys in keys.values():<EOL><INDENT>for branches in keys.values():<EOL><INDENT>if branch not in branches:<EOL><INDENT>continue<EOL><DEDENT>truncate_branhc(branches[branch])<EOL><DEDENT><DEDENT>truncate_branhc(settings[branch])<EOL>truncate_branhc(presettings[branch])<EOL>self.shallowest = OrderedDict()<EOL>for entity_branch in keycache:<EOL><INDENT>if entity_branch[-<NUM_LIT:1>] == branch:<EOL><INDENT>truncate_branhc(keycache[entity_branch])<EOL><DEDENT><DEDENT>send(self, branch=branch, turn=turn, tick=tick, action='<STR_LIT>')<EOL>
Delete all data after (not on) a specific tick
f9006:c2:m10
@staticmethod<EOL><INDENT>def _iter_future_contradictions(entity, key, turns, branch, turn, tick, value):<DEDENT>
<EOL>if not turns:<EOL><INDENT>return<EOL><DEDENT>if turn in turns:<EOL><INDENT>future_ticks = turns[turn].future(tick)<EOL>for tck, newval in future_ticks.items():<EOL><INDENT>if newval != value:<EOL><INDENT>yield turn, tck<EOL><DEDENT><DEDENT>future_turns = turns.future(turn)<EOL><DEDENT>elif turns.rev_gettable(turn):<EOL><INDENT>future_turns = turns.future(turn)<EOL><DEDENT>else:<EOL><INDENT>future_turns = turns<EOL><DEDENT>if not future_turns:<EOL><INDENT>return<EOL><DEDENT>for trn, ticks in future_turns.items():<EOL><INDENT>for tick, newval in ticks.items():<EOL><INDENT>if newval != value:<EOL><INDENT>yield trn, tick<EOL><DEDENT><DEDENT><DEDENT>
If setting ``key=value`` would result in a contradiction, iterate over contradicted ``(turn, tick)``s.
f9006:c2:m11
def retrieve(self, *args):
ret = self._base_retrieve(args)<EOL>if ret is None:<EOL><INDENT>raise HistoryError("<STR_LIT>", deleted=True)<EOL><DEDENT>elif ret is KeyError:<EOL><INDENT>raise ret<EOL><DEDENT>return ret<EOL>
Get a value previously .store(...)'d. Needs at least five arguments. The -1th is the tick within the turn you want, the -2th is that turn, the -3th is the branch, and the -4th is the key. All other arguments identify the entity that the key is in.
f9006:c2:m15
def iter_entities_or_keys(self, *args, forward=None):
if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>entity = args[:-<NUM_LIT:3>]<EOL>branch, turn, tick = args[-<NUM_LIT:3>:]<EOL>if self.db._no_kc:<EOL><INDENT>yield from self._get_adds_dels(self.keys[entity], branch, turn, tick)[<NUM_LIT:0>]<EOL>return<EOL><DEDENT>yield from self._get_keycache(entity, branch, turn, tick, forward=forward)<EOL>
Iterate over the keys an entity has, if you specify an entity. Otherwise iterate over the entities themselves, or at any rate the tuple specifying which entity.
f9006:c2:m16
def count_entities_or_keys(self, *args, forward=None):
if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>entity = args[:-<NUM_LIT:3>]<EOL>branch, turn, tick = args[-<NUM_LIT:3>:]<EOL>if self.db._no_kc:<EOL><INDENT>return len(self._get_adds_dels(self.keys[entity], branch, turn, tick)[<NUM_LIT:0>])<EOL><DEDENT>return len(self._get_keycache(entity, branch, turn, tick, forward=forward))<EOL>
Return the number of keys an entity has, if you specify an entity. Otherwise return the number of entities.
f9006:c2:m17
def contains_entity_or_key(self, *args):
try:<EOL><INDENT>return self.retrieve(*args) is not None<EOL><DEDENT>except KeyError:<EOL><INDENT>return False<EOL><DEDENT>
Check if an entity has a key at the given time, if entity specified. Otherwise check if the entity exists.
f9006:c2:m18
def _adds_dels_sucpred(self, cache, branch, turn, tick, *, stoptime=None):
added = set()<EOL>deleted = set()<EOL>for node, nodes in cache.items():<EOL><INDENT>addidx, delidx = self._get_adds_dels(nodes, branch, turn, tick, stoptime=stoptime)<EOL>if addidx and not delidx:<EOL><INDENT>added.add(node)<EOL><DEDENT>elif delidx and not addidx:<EOL><INDENT>deleted.add(node)<EOL><DEDENT><DEDENT>return added, deleted<EOL>
Take the successors or predecessors cache and get nodes added or deleted from it Operates like ``_get_adds_dels``.
f9006:c4:m3
def _get_destcache(self, graph, orig, branch, turn, tick, *, forward):
destcache, destcache_lru, get_keycachelike, successors, adds_dels_sucpred = self._get_destcache_stuff<EOL>lru_append(destcache, destcache_lru, ((graph, orig, branch), turn, tick), KEYCACHE_MAXSIZE)<EOL>return get_keycachelike(<EOL>destcache, successors, adds_dels_sucpred, (graph, orig),<EOL>branch, turn, tick, forward=forward<EOL>)<EOL>
Return a set of destination nodes succeeding ``orig``
f9006:c4:m4
def _get_origcache(self, graph, dest, branch, turn, tick, *, forward):
origcache, origcache_lru, get_keycachelike, predecessors, adds_dels_sucpred = self._get_origcache_stuff<EOL>lru_append(origcache, origcache_lru, ((graph, dest, branch), turn, tick), KEYCACHE_MAXSIZE)<EOL>return get_keycachelike(<EOL>origcache, predecessors, adds_dels_sucpred, (graph, dest),<EOL>branch, turn, tick, forward=forward<EOL>)<EOL>
Return a set of origin nodes leading to ``dest``
f9006:c4:m5
def iter_successors(self, graph, orig, branch, turn, tick, *, forward=None):
if self.db._no_kc:<EOL><INDENT>yield from self._adds_dels_sucpred(self.successors[graph, orig], branch, turn, tick)[<NUM_LIT:0>]<EOL>return<EOL><DEDENT>if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>yield from self._get_destcache(graph, orig, branch, turn, tick, forward=forward)<EOL>
Iterate over successors of a given origin node at a given time.
f9006:c4:m6
def iter_predecessors(self, graph, dest, branch, turn, tick, *, forward=None):
if self.db._no_kc:<EOL><INDENT>yield from self._adds_dels_sucpred(self.predecessors[graph, dest], branch, turn, tick)[<NUM_LIT:0>]<EOL>return<EOL><DEDENT>if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>yield from self._get_origcache(graph, dest, branch, turn, tick, forward=forward)<EOL>
Iterate over predecessors to a given destination node at a given time.
f9006:c4:m7
def count_successors(self, graph, orig, branch, turn, tick, *, forward=None):
if self.db._no_kc:<EOL><INDENT>return len(self._adds_dels_sucpred(self.successors[graph, orig], branch, turn, tick)[<NUM_LIT:0>])<EOL><DEDENT>if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>return len(self._get_destcache(graph, orig, branch, turn, tick, forward=forward))<EOL>
Return the number of successors to a given origin node at a given time.
f9006:c4:m8
def count_predecessors(self, graph, dest, branch, turn, tick, *, forward=None):
if self.db._no_kc:<EOL><INDENT>return len(self._adds_dels_sucpred(self.predecessors[graph, dest], branch, turn, tick)[<NUM_LIT:0>])<EOL><DEDENT>if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>return len(self._get_origcache(graph, dest, branch, turn, tick, forward=forward))<EOL>
Return the number of predecessors from a given destination node at a given time.
f9006:c4:m9
def has_successor(self, graph, orig, dest, branch, turn, tick, *, forward=None):
if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>return dest in self._get_destcache(graph, orig, branch, turn, tick, forward=forward)<EOL>
Return whether an edge connects the origin to the destination at the given time. Doesn't require the edge's index, which makes it slower than retrieving a particular edge.
f9006:c4:m10
def has_predecessor(self, graph, dest, orig, branch, turn, tick, *, forward=None):
if forward is None:<EOL><INDENT>forward = self.db._forward<EOL><DEDENT>return orig in self._get_origcache(graph, dest, branch, turn, tick, forward=forward)<EOL>
Return whether an edge connects the destination to the origin at the given time. Doesn't require the edge's index, which makes it slower than retrieving a particular edge.
f9006:c4:m11
def runTest(self):
for graphmaker in self.graphmakers:<EOL><INDENT>gmn = graphmaker.__name__<EOL>self.assertTrue(self.engine.is_parent_of('<STR_LIT>', gmn))<EOL>self.assertTrue(self.engine.is_parent_of(gmn, gmn + '<STR_LIT>'))<EOL>self.assertTrue(self.engine.is_parent_of(gmn, gmn + '<STR_LIT>'))<EOL>self.assertTrue(self.engine.is_parent_of(gmn, gmn + '<STR_LIT>'))<EOL>self.assertTrue(self.engine.is_parent_of(gmn + '<STR_LIT>', gmn + '<STR_LIT>'))<EOL>self.assertTrue(self.engine.is_parent_of(gmn + '<STR_LIT>', gmn + '<STR_LIT>'))<EOL>self.assertFalse(self.engine.is_parent_of(gmn + '<STR_LIT>', '<STR_LIT>'))<EOL>self.assertFalse(self.engine.is_parent_of(gmn + '<STR_LIT>', gmn + '<STR_LIT>'))<EOL>g = self.engine.graph[gmn]<EOL>self.engine.branch = gmn<EOL>self.assertIn(<NUM_LIT:0>, g.node)<EOL>self.assertIn(<NUM_LIT:1>, g.node)<EOL>self.assertIn(<NUM_LIT:0>, g.edge)<EOL>self.assertIn(<NUM_LIT:1>, g.edge[<NUM_LIT:0>])<EOL>self.engine.turn = <NUM_LIT:0><EOL>def badjump():<EOL><INDENT>self.engine.branch = gmn + '<STR_LIT>'<EOL><DEDENT>self.assertRaises(ValueError, badjump)<EOL>self.engine.turn = <NUM_LIT:2><EOL>self.engine.branch = gmn + '<STR_LIT>'<EOL>self.assertIn(<NUM_LIT:0>, g)<EOL>self.assertIn(<NUM_LIT:0>, list(g.node.keys()))<EOL>self.assertNotIn(<NUM_LIT:1>, g.edge[<NUM_LIT:0>])<EOL>if g.is_multigraph():<EOL><INDENT>self.assertRaises(KeyError, lambda: g.edge[<NUM_LIT:0>][<NUM_LIT:1>][<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>self.assertRaises(KeyError, lambda: g.edge[<NUM_LIT:0>][<NUM_LIT:1>])<EOL><DEDENT>self.engine.branch = gmn + '<STR_LIT>'<EOL>self.assertIn(<NUM_LIT:2>, g.node)<EOL>for orig in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>):<EOL><INDENT>for dest in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>):<EOL><INDENT>if orig == dest:<EOL><INDENT>continue<EOL><DEDENT>self.assertIn(orig, g.edge)<EOL>self.assertIn(dest, g.edge[orig])<EOL><DEDENT><DEDENT>self.engine.branch = gmn + '<STR_LIT>'<EOL>self.assertNotIn(<NUM_LIT:0>, g.edge[<NUM_LIT:2>])<EOL>if g.is_multigraph():<EOL><INDENT>self.assertRaises(KeyError, lambda: g.edge[<NUM_LIT:2>][<NUM_LIT:0>][<NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>self.assertRaises(KeyError, lambda: g.edge[<NUM_LIT:2>][<NUM_LIT:0>])<EOL><DEDENT>self.engine.turn = <NUM_LIT:2><EOL>self.assertIn(<NUM_LIT:3>, g.node)<EOL>self.assertIn(<NUM_LIT:1>, g.edge[<NUM_LIT:0>])<EOL>self.assertIn(<NUM_LIT:2>, g.edge[<NUM_LIT:1>])<EOL>self.assertIn(<NUM_LIT:3>, g.edge[<NUM_LIT:2>])<EOL>self.assertIn(<NUM_LIT:0>, g.edge[<NUM_LIT:3>])<EOL>self.engine.branch = gmn + '<STR_LIT>'<EOL>for node in (<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>):<EOL><INDENT>self.assertNotIn(node, g.node)<EOL>self.assertNotIn(node, g.edge)<EOL><DEDENT>self.engine.branch = gmn<EOL>self.engine.turn = <NUM_LIT:0><EOL>self.assertIn(<NUM_LIT:0>, g.node)<EOL>self.assertIn(<NUM_LIT:1>, g.node)<EOL>self.assertIn(<NUM_LIT:0>, g.edge)<EOL>self.assertIn(<NUM_LIT:1>, g.edge[<NUM_LIT:0>])<EOL><DEDENT>
Create some branches of history and check that allegedb remembers where each came from and what happened in each.
f9007:c2:m0
def runTest(self):
for graphmaker in self.graphmakers:<EOL><INDENT>g = graphmaker('<STR_LIT>')<EOL>g.add_node(<NUM_LIT:0>)<EOL>g.add_node(<NUM_LIT:1>)<EOL>g.add_edge(<NUM_LIT:0>, <NUM_LIT:1>)<EOL>n = g.node[<NUM_LIT:0>]<EOL>e = g.edge[<NUM_LIT:0>][<NUM_LIT:1>]<EOL>if isinstance(e, allegedb.graph.AbstractMultiEdges):<EOL><INDENT>e = e[<NUM_LIT:0>]<EOL><DEDENT>for (k, v) in testdata:<EOL><INDENT>g.graph[k] = v<EOL>self.assertIn(k, g.graph)<EOL>self.assertEqual(g.graph[k], v)<EOL>del g.graph[k]<EOL>self.assertNotIn(k, g.graph)<EOL>n[k] = v<EOL>self.assertIn(k, n)<EOL>self.assertEqual(n[k], v)<EOL>del n[k]<EOL>self.assertNotIn(k, n)<EOL>e[k] = v<EOL>self.assertIn(k, e)<EOL>self.assertEqual(e[k], v)<EOL>del e[k]<EOL>self.assertNotIn(k, e)<EOL><DEDENT>self.engine.del_graph('<STR_LIT>')<EOL><DEDENT>
Test that all the graph types can store and retrieve key-value pairs for the graph as a whole, for nodes, and for edges.
f9007:c4:m0
def runTest(self):
from allegedb.alchemy import Alchemist<EOL>self.assertTrue(hasattr(self.engine.query, '<STR_LIT>'))<EOL>self.assertTrue(isinstance(self.engine.query.alchemist, Alchemist))<EOL>from json import load<EOL>with open(self.engine.query.path + '<STR_LIT>', '<STR_LIT:r>') as jsonfile:<EOL><INDENT>precompiled = load(jsonfile)<EOL><DEDENT>self.assertEqual(<EOL>precompiled.keys(), self.engine.query.alchemist.sql.keys()<EOL>)<EOL>for (k, query) in precompiled.items():<EOL><INDENT>self.assertEqual(<EOL>query,<EOL>str(<EOL>self.engine.query.alchemist.sql[k]<EOL>)<EOL>)<EOL><DEDENT>
Make sure that the queries generated in SQLAlchemy are the same as those precompiled into SQLite.
f9007:c8:m0