signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def localize_preserving_time_of_day(dt):
|
<EOL>year, month, day, hour, minute =dt.year, dt.month, dt.day, dt.hour, dt.minute<EOL>dt_localized = djtz.localize(dt)<EOL>return dt_localized.replace(<EOL>year=year, month=month, day=day, hour=hour, minute=minute)<EOL>
|
Return the given datetime with the same time-of-day (hours and minutes) as
it *seems* to have, even if it has been adjusted by applying `timedelta`
additions that traverse daylight savings dates and would therefore
otherwise trigger changes to its apparent time.
|
f4903:m6
|
def allowed_to_preview(user):
|
if (<EOL>user.is_authenticated and<EOL>user.is_active and<EOL>user.is_staff<EOL>):<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>
|
Is the user allowed to view the preview?
Users are only allowed to view the preview if they are authenticated, active and staff.
:param user: A User object instance.
:return: Boolean.
|
f4904:m0
|
def parse_start_date(self, request):
|
if request.GET.get('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>return djtz.parse('<STR_LIT>' % request.GET.get('<STR_LIT>'))<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return self.default_start_date or djtz.midnight()<EOL>
|
Return start date for event occurrences, which is one of the following
in order of priority:
- `start_date` GET parameter value, if given and valid
- page's `default_start_date` if set
- today's date
|
f4910:c0:m0
|
def parse_end_date(self, request, start_date):
|
if request.GET.get('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>return djtz.parse('<STR_LIT>' % request.GET.get('<STR_LIT>'))<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>days_to_show = self.default_days_to_show orappsettings.DEFAULT_DAYS_TO_SHOW<EOL>if '<STR_LIT>' in request.GET:<EOL><INDENT>try:<EOL><INDENT>days_to_show = int(request.GET.get('<STR_LIT>'))<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return start_date + timedelta(days=days_to_show)<EOL>
|
Return period in days after the start date to show event occurrences,
which is one of the following in order of priority:
- `end_date` GET parameter value, if given and valid. The filtering
will be *inclusive* of the end date: until end-of-day of this date
- `days_to_show` GET parameter value, if given and valid
- page's `default_days_to_show` if set
- the value of the app setting `DEFAULT_DAYS_TO_SHOW`
|
f4910:c0:m1
|
def parse_primary_types(self, request):
|
if request.GET.getlist('<STR_LIT>'):<EOL><INDENT>return EventType.objects.get(<EOL>slug__in=request.GET.getlist('<STR_LIT>'))<EOL><DEDENT>return None<EOL>
|
Return primary event types that occurrences must belong to, or `None`
if there is no constraint on primary type.
|
f4910:c0:m2
|
def parse_secondary_types(self, request):
|
if request.GET.getlist('<STR_LIT>'):<EOL><INDENT>return EventType.objects.filter(<EOL>slug__in=request.GET.getlist('<STR_LIT>'))<EOL><DEDENT>return None<EOL>
|
Return secondary event types that occurrences must belong to, or `None`
if there is no constraint on secondary type.
|
f4910:c0:m3
|
def parse_types(self, request):
|
if request.GET.getlist('<STR_LIT>'):<EOL><INDENT>return EventType.objects.filter(<EOL>slug__in=request.GET.getlist('<STR_LIT>'))<EOL><DEDENT>return None<EOL>
|
Return event types that occurrences must belong to as *either* a
primary or secondary type, or `None` if there is no constraint on type.
|
f4910:c0:m4
|
def get_items_to_mount(self, request):
|
return self._apply_constraints(request).visible()<EOL>
|
Return items that can be mounted, i.e. viewed as child pages
|
f4910:c0:m9
|
def get_items_to_list(self, request):
|
return self._apply_constraints(request).visible()<EOL>
|
Return items that can be seen on the listing page by current user
|
f4910:c0:m10
|
def get_occurrence_times_for_event(event):
|
occurrences_starts = set()<EOL>occurrences_ends = set()<EOL>for o in event.occurrence_list:<EOL><INDENT>occurrences_starts.add(<EOL>coerce_naive(o.original_start or o.start)<EOL>)<EOL>occurrences_ends.add(<EOL>coerce_naive(o.original_end or o.end)<EOL>)<EOL><DEDENT>return occurrences_starts, occurrences_ends<EOL>
|
Return a tuple with two sets containing the (start, end) *naive* datetimes
of an Event's Occurrences, or the original start datetime if an
Occurrence's start was modified by a user.
|
f4928:m0
|
def save(self, *args, **kwargs):
|
self.modified = djtz.now()<EOL>super(AbstractBaseModel, self).save(*args, **kwargs)<EOL>
|
Update ``self.modified``.
|
f4928:c1:m0
|
def cancel_occurrence(self, occurrence, hide_cancelled_occurrence=False,<EOL>reason=u'<STR_LIT>'):
|
if occurrence not in self.occurrence_list:<EOL><INDENT>return <EOL><DEDENT>occurrence.is_protected_from_regeneration = True<EOL>occurrence.is_cancelled = True<EOL>occurrence.is_hidden = hide_cancelled_occurrence<EOL>occurrence.cancel_reason = reason<EOL>occurrence.save()<EOL>self.invalidate_caches()<EOL>
|
"Delete" occurrence by flagging it as deleted, and optionally setting
it to be hidden and the reason for deletion.
We don't really delete occurrences because doing so would just cause
them to be re-generated the next time occurrence generation is done.
|
f4928:c4:m4
|
@transaction.atomic<EOL><INDENT>def make_variation(self, occurrence):<DEDENT>
|
<EOL>defaults = {<EOL>field: getattr(self, field)<EOL>for field in self.get_cloneable_fieldnames()<EOL>}<EOL>variation_event = type(self)(<EOL>derived_from=self,<EOL>**defaults<EOL>)<EOL>variation_event.save()<EOL>self.clone_event_relationships(variation_event)<EOL>self.end_repeat = occurrence.start<EOL>qs_overlapping_occurrences = self.occurrences.filter(start__gte=occurrence.start)<EOL>qs_overlapping_occurrences.delete()<EOL>self.save()<EOL>return variation_event<EOL>
|
Make and return a variation event cloned from this event at the given
occurrence time.
If ``save=False`` the caller is responsible for calling ``save`` on
both this event, and the returned variation event, to ensure they
are saved and occurrences are refreshed.
|
f4928:c4:m5
|
def missing_occurrence_data(self, until=None):
|
existing_starts, existing_ends = get_occurrence_times_for_event(self)<EOL>for generator in self.repeat_generators.all():<EOL><INDENT>for start, end in generator.generate(until=until):<EOL><INDENT>if start in existing_startsor end in existing_ends:<EOL><INDENT>continue<EOL><DEDENT>yield(start, end, generator)<EOL><DEDENT><DEDENT>self.invalidate_caches()<EOL>
|
Return a generator of (start, end, generator) tuples that are the
datetimes and generator responsible for occurrences based on any
``EventRepeatsGenerator``s associated with this event.
This method performs basic detection of existing occurrences with
matching start/end times so it can avoid recreating those occurrences,
which will generally be user-modified items.
|
f4928:c4:m6
|
@transaction.atomic<EOL><INDENT>def extend_occurrences(self, until=None):<DEDENT>
|
<EOL>count = <NUM_LIT:0><EOL>for start_dt, end_dt, generatorin self.missing_occurrence_data(until=until):<EOL><INDENT>Occurrence.objects.create(<EOL>event=self,<EOL>generator=generator,<EOL>start=start_dt,<EOL>end=end_dt,<EOL>original_start=start_dt,<EOL>original_end=end_dt,<EOL>is_all_day=generator.is_all_day,<EOL>)<EOL>count += <NUM_LIT:1><EOL><DEDENT>self.invalidate_caches()<EOL>return count<EOL>
|
Create missing occurrences for this Event, assuming that existing
occurrences are all correct (or have been pre-deleted).
This is mostly useful for adding not-yet-created future occurrences
with a scheduled job, e.g. via the `create_event_occurrences` command.
Occurrences are extended up to the event's ``end_repeat`` if set, or
the time given by the ``until`` parameter or the configured
``REPEAT_LIMIT`` for unlimited events.
|
f4928:c4:m7
|
@transaction.atomic<EOL><INDENT>def regenerate_occurrences(self, until=None):<DEDENT>
|
<EOL>self.occurrences.regeneratable().delete()<EOL>self.extend_occurrences(until=until)<EOL>
|
Delete and re-create occurrences for this Event.
|
f4928:c4:m8
|
def clone_event_relationships(self, dst_obj):
|
<EOL>for occurrence in self.occurrences.filter(Q(generator__isnull=True) | Q(is_protected_from_regeneration=True)):<EOL><INDENT>occurrence.pk = None<EOL>occurrence.event = dst_obj<EOL>occurrence.save()<EOL><DEDENT>for generator in self.repeat_generators.all():<EOL><INDENT>generator.pk = None<EOL>generator.event = dst_obj<EOL>generator.save()<EOL><DEDENT>
|
Clone related `EventRepeatsGenerator` and `Occurrence` relationships
from a source to destination event.
|
f4928:c4:m10
|
@cached_property<EOL><INDENT>def own_occurrences(self):<DEDENT>
|
return list(self.occurrences.all())<EOL>
|
The value is returned as a list, to emphasise its cached/resolved nature.
Manipulating a queryset would lose the benefit of caching.
:return: A list of occurrences directly attached to the event. Used to
fall back to `part_of` occurrences.
|
f4928:c4:m12
|
@cached_property<EOL><INDENT>def occurrence_list(self):<DEDENT>
|
o = self.own_occurrences<EOL>if o:<EOL><INDENT>return o<EOL><DEDENT>if self.visible_part_of:<EOL><INDENT>return self.visible_part_of.occurrence_list<EOL><DEDENT>return []<EOL>
|
:return: A list of my occurrences, or those of my visible_part_of event
|
f4928:c4:m13
|
def invalidate_caches(self):
|
try:<EOL><INDENT>del self.visible_part_of<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>del self.occurrence_list<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>del self.own_occurrences<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>try:<EOL><INDENT>del self.upcoming_occurrence_list<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>
|
Call this to clear out cached values, in case you want to access cached
properties after changing occurrences.
|
f4928:c4:m15
|
def get_occurrences_range(self):
|
<EOL>try:<EOL><INDENT>first = self.occurrence_list[<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>first = None<EOL><DEDENT>try:<EOL><INDENT>last = self.occurrence_list[-<NUM_LIT:1>]<EOL><DEDENT>except IndexError:<EOL><INDENT>last = None<EOL><DEDENT>return (first, last)<EOL>
|
Return the first and last chronological `Occurrence` for this event.
|
f4928:c4:m16
|
def get_upcoming_occurrences_by_day(self):
|
result = OrderedDict()<EOL>for occ in self.upcoming_occurrence_list:<EOL><INDENT>result.setdefault(occ.local_start.date(), []).append(occ)<EOL><DEDENT>return result.items()<EOL>
|
:return: an iterable of (day, occurrences)
|
f4928:c4:m17
|
def start_dates_set(self):
|
occurrences = [o for o in self.occurrence_list if not o.is_cancelled]<EOL>dates = set([o.local_start.date() for o in occurrences])<EOL>sorted_dates = sorted(dates)<EOL>return sorted_dates<EOL>
|
:return: a sorted set of all the different dates that this event
happens on.
|
f4928:c4:m18
|
def start_times_set(self):
|
occurrences = [o for o in self.occurrence_list if not o.is_cancelled and not o.is_all_day]<EOL>times = set([o.local_start.time() for o in occurrences])<EOL>sorted_times = sorted(times)<EOL>return sorted_times<EOL>
|
:return: a sorted set of all the different times that this event
happens on.
|
f4928:c4:m19
|
def has_finished(self):
|
return self.occurrence_list and not self.upcoming_occurrence_list<EOL>
|
:return: True if:
There are occurrences, and
There are no upcoming occurrences
|
f4928:c4:m29
|
def generate(self, until=None):
|
<EOL>start_dt = self.start - timedelta(seconds=<NUM_LIT:1>)<EOL>if until is None:<EOL><INDENT>if self.repeat_end:<EOL><INDENT>until = self.repeat_end<EOL><DEDENT>else:<EOL><INDENT>until = djtz.now() + appsettings.REPEAT_LIMIT<EOL><DEDENT>if self.is_all_day:<EOL><INDENT>until += timedelta(days=<NUM_LIT:1>)<EOL><DEDENT><DEDENT>start_dt = coerce_naive(start_dt)<EOL>until = coerce_naive(until)<EOL>occurrence_duration = self.duration or timedelta(days=<NUM_LIT:1>)<EOL>rruleset = self.get_rruleset(until=until)<EOL>return (<EOL>(start, start + occurrence_duration)<EOL>for start in rruleset.between(start_dt, until)<EOL>)<EOL>
|
Return a list of datetime objects for event occurrence start and end
times, up to the given ``until`` parameter, or up to the ``repeat_end``
time, or to the configured ``REPEAT_LIMIT`` for unlimited events.
|
f4928:c7:m1
|
def get_rruleset(self, until=None):
|
<EOL>return rrule.rrulestr(<EOL>self._build_complete_rrule(until=until),<EOL>forceset=True)<EOL>
|
Return an ``rruleset`` object representing the start datetimes for this
generator, whether for one-time events or repeating ones.
|
f4928:c7:m2
|
def _build_complete_rrule(self, start_dt=None, until=None):
|
if start_dt is None:<EOL><INDENT>start_dt = self.start<EOL><DEDENT>if until is None:<EOL><INDENT>until = self.repeat_endor djtz.now() + appsettings.REPEAT_LIMIT<EOL><DEDENT>rrule_spec = "<STR_LIT>" % format_naive_ical_dt(start_dt)<EOL>if not self.recurrence_rule:<EOL><INDENT>rrule_spec += "<STR_LIT>" % format_naive_ical_dt(start_dt)<EOL><DEDENT>else:<EOL><INDENT>rrule_spec += "<STR_LIT>" % self.recurrence_rule<EOL>if self.is_all_day:<EOL><INDENT>until += timedelta(days=<NUM_LIT:1>, microseconds=-<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>until -= timedelta(microseconds=<NUM_LIT:1>)<EOL><DEDENT>rrule_spec += "<STR_LIT>" % format_naive_ical_dt(until)<EOL><DEDENT>return rrule_spec<EOL>
|
Convert recurrence rule, start datetime and (optional) end datetime
into a full iCAL RRULE spec.
|
f4928:c7:m3
|
@property<EOL><INDENT>def duration(self):<DEDENT>
|
return self.end - self.start<EOL>
|
Return the duration between ``start`` and ``end`` as a timedelta.
|
f4928:c7:m5
|
@property<EOL><INDENT>def duration(self):<DEDENT>
|
return self.end - self.start<EOL>
|
Return the duration between ``start`` and ``end`` as a timedelta.
|
f4928:c8:m5
|
def is_past(self):
|
return self.end < djtz.now()<EOL>
|
:return: True if this occurrence is entirely in the past
|
f4928:c8:m8
|
def forwards(apps, schema_editor):
|
starts = timeutils.round_datetime(<EOL>when=timezone.now(),<EOL>precision=timedelta(days=<NUM_LIT:1>),<EOL>rounding=timeutils.ROUND_DOWN)<EOL>ends = starts + appsettings.DEFAULT_ENDS_DELTA<EOL>recurrence_rules = dict(<EOL>RecurrenceRule.objects.values_list('<STR_LIT:description>', '<STR_LIT>'))<EOL>daily = recurrence_rules['<STR_LIT>']<EOL>weekdays = recurrence_rules['<STR_LIT>']<EOL>weekends = recurrence_rules['<STR_LIT>']<EOL>weekly = recurrence_rules['<STR_LIT>']<EOL>monthly = recurrence_rules['<STR_LIT>']<EOL>yearly = recurrence_rules['<STR_LIT>']<EOL>daily_event = G(<EOL>EventBase,<EOL>title='<STR_LIT>',<EOL>starts=starts + timedelta(hours=<NUM_LIT:9>),<EOL>ends=ends + timedelta(hours=<NUM_LIT:9>),<EOL>recurrence_rule=daily,<EOL>)<EOL>weekday_event = G(<EOL>EventBase,<EOL>title='<STR_LIT>',<EOL>starts=starts + timedelta(hours=<NUM_LIT:11>),<EOL>ends=ends + timedelta(hours=<NUM_LIT:11>),<EOL>recurrence_rule=weekdays,<EOL>)<EOL>weekend_event = G(<EOL>EventBase,<EOL>title='<STR_LIT>',<EOL>starts=starts + timedelta(hours=<NUM_LIT>),<EOL>ends=ends + timedelta(hours=<NUM_LIT>),<EOL>recurrence_rule=weekends,<EOL>)<EOL>weekly_event = G(<EOL>EventBase,<EOL>title='<STR_LIT>',<EOL>starts=starts + timedelta(hours=<NUM_LIT:15>),<EOL>ends=ends + timedelta(hours=<NUM_LIT:15>),<EOL>recurrence_rule=weekly,<EOL>)<EOL>monthly_event = G(<EOL>EventBase,<EOL>title='<STR_LIT>',<EOL>starts=starts + timedelta(hours=<NUM_LIT>),<EOL>ends=ends + timedelta(hours=<NUM_LIT>),<EOL>recurrence_rule=monthly,<EOL>)<EOL>yearly_event = G(<EOL>EventBase,<EOL>title='<STR_LIT>',<EOL>starts=starts + timedelta(hours=<NUM_LIT>),<EOL>ends=ends + timedelta(hours=<NUM_LIT>),<EOL>recurrence_rule=yearly,<EOL>)<EOL>
|
Create sample events.
|
f4930:m0
|
def backwards(apps, schema_editor):
|
titles = [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>]<EOL>samples = EventBase.objects.filter(title__in=titles)<EOL>samples.delete()<EOL>
|
Delete sample events, including derivative repeat and variation events.
|
f4930:m1
|
def colorize(self, string, rgb=None, ansi=None, bg=None, ansi_bg=None):
|
if not isinstance(string, str):<EOL><INDENT>string = str(string)<EOL><DEDENT>if rgb is None and ansi is None:<EOL><INDENT>raise TerminalColorMapException(<EOL>'<STR_LIT>')<EOL><DEDENT>if rgb is not None and ansi is not None:<EOL><INDENT>raise TerminalColorMapException(<EOL>'<STR_LIT>')<EOL><DEDENT>if bg is not None and ansi_bg is not None:<EOL><INDENT>raise TerminalColorMapException(<EOL>'<STR_LIT>')<EOL><DEDENT>if rgb is not None:<EOL><INDENT>(closestAnsi, closestRgb) = self.convert(rgb)<EOL><DEDENT>elif ansi is not None:<EOL><INDENT>(closestAnsi, closestRgb) = (ansi, self.colors[ansi])<EOL><DEDENT>if bg is None and ansi_bg is None:<EOL><INDENT>return "<STR_LIT>".format(ansiCode=closestAnsi, string=string)<EOL><DEDENT>if bg is not None:<EOL><INDENT>(closestBgAnsi, unused) = self.convert(bg)<EOL><DEDENT>elif ansi_bg is not None:<EOL><INDENT>(closestBgAnsi, unused) = (ansi_bg, self.colors[ansi_bg])<EOL><DEDENT>return "<STR_LIT>".format(ansiCode=closestAnsi, bf=closestBgAnsi, string=string)<EOL>
|
Returns the colored string
|
f4938:c1:m2
|
def colorize(string, rgb=None, ansi=None, bg=None, ansi_bg=None, fd=<NUM_LIT:1>):
|
<EOL>if colorize.fd != fd:<EOL><INDENT>colorize.init = False<EOL>colorize.fd = fd<EOL><DEDENT>if not colorize.init:<EOL><INDENT>colorize.init = True<EOL>colorize.is_term = isatty(fd)<EOL>if '<STR_LIT>' in environ:<EOL><INDENT>if environ['<STR_LIT>'].startswith('<STR_LIT>'):<EOL><INDENT>colorize.cmap = XTermColorMap()<EOL><DEDENT>elif environ['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>colorize.cmap = VT100ColorMap()<EOL><DEDENT>else:<EOL><INDENT>colorize.is_term = False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>colorize.is_term = False<EOL><DEDENT><DEDENT>if colorize.is_term:<EOL><INDENT>string = colorize.cmap.colorize(string, rgb, ansi, bg, ansi_bg)<EOL><DEDENT>return string<EOL>
|
Returns the colored string to print on the terminal.
This function detects the terminal type and if it is supported and the
output is not going to a pipe or a file, then it will return the colored
string, otherwise it will return the string without modifications.
string = the string to print. Only accepts strings, unicode strings must
be encoded in advance.
rgb = Rgb color for the text; for example 0xFF0000 is red.
ansi = Ansi for the text
bg = Rgb color for the background
ansi_bg= Ansi color for the background
fd = The file descriptor that will be used by print, by default is the
stdout
|
f4939:m0
|
def _normalize_day(year, month, day):
|
if year < MIN_YEAR or year > MAX_YEAR:<EOL><INDENT>raise ValueError("<STR_LIT>" % (MIN_YEAR, MAX_YEAR))<EOL><DEDENT>if month < <NUM_LIT:1> or month > <NUM_LIT:12>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>days_in_month = DAYS_IN_MONTH[(year, month)]<EOL>if day in (days_in_month, -<NUM_LIT:1>):<EOL><INDENT>return year, month, -<NUM_LIT:1><EOL><DEDENT>if day in (days_in_month - <NUM_LIT:1>, -<NUM_LIT:2>):<EOL><INDENT>return year, month, -<NUM_LIT:2><EOL><DEDENT>if day in (days_in_month - <NUM_LIT:2>, -<NUM_LIT:3>):<EOL><INDENT>return year, month, -<NUM_LIT:3><EOL><DEDENT>if <NUM_LIT:1> <= day <= days_in_month - <NUM_LIT:3>:<EOL><INDENT>return year, month, int(day)<EOL><DEDENT>raise ValueError("<STR_LIT>" % (day, days_in_month))<EOL>
|
Coerce the day of the month to an internal value that may or
may not match the "public" value.
With the exception of the last three days of every month, all
days are stored as-is. The last three days are instead stored
as -1 (the last), -2 (first from last) and -3 (second from last).
Therefore, for a 28-day month, the last week is as follows:
Day | 22 23 24 25 26 27 28
Value | 22 23 24 25 -3 -2 -1
For a 29-day month, the last week is as follows:
Day | 23 24 25 26 27 28 29
Value | 23 24 25 26 -3 -2 -1
For a 30-day month, the last week is as follows:
Day | 24 25 26 27 28 29 30
Value | 24 25 26 27 -3 -2 -1
For a 31-day month, the last week is as follows:
Day | 25 26 27 28 29 30 31
Value | 25 26 27 28 -3 -2 -1
This slightly unintuitive system makes some temporal arithmetic
produce a more desirable outcome.
:param year:
:param month:
:param day:
:return:
|
f4944:m3
|
@classmethod<EOL><INDENT>def precision(cls):<DEDENT>
|
raise NotImplementedError("<STR_LIT>")<EOL>
|
The precision of this clock implementation, represented as a
number of decimal places. Therefore, for a nanosecond precision
clock, this function returns `9`.
|
f4944:c1:m1
|
@classmethod<EOL><INDENT>def available(cls):<DEDENT>
|
raise NotImplementedError("<STR_LIT>")<EOL>
|
Return a boolean flag to indicate whether or not this clock
implementation is available on this platform.
|
f4944:c1:m2
|
@classmethod<EOL><INDENT>def local_offset(cls):<DEDENT>
|
return ClockTime(-int(mktime(gmtime(<NUM_LIT:0>))))<EOL>
|
The offset from UTC for local time read from this clock.
|
f4944:c1:m3
|
def local_time(self):
|
return self.utc_time() + self.local_offset()<EOL>
|
Read and return the current local time from this clock, measured
relative to the Unix Epoch.
|
f4944:c1:m4
|
def utc_time(self):
|
raise NotImplementedError("<STR_LIT>")<EOL>
|
Read and return the current UTC time from this clock, measured
relative to the Unix Epoch.
|
f4944:c1:m5
|
def iso_format(self, sep="<STR_LIT:T>"):
|
parts = []<EOL>hours, minutes, seconds = self.hours_minutes_seconds<EOL>if hours:<EOL><INDENT>parts.append("<STR_LIT>" % hours)<EOL><DEDENT>if minutes:<EOL><INDENT>parts.append("<STR_LIT>" % minutes)<EOL><DEDENT>if seconds:<EOL><INDENT>if seconds == seconds // <NUM_LIT:1>:<EOL><INDENT>parts.append("<STR_LIT>" % seconds)<EOL><DEDENT>else:<EOL><INDENT>parts.append("<STR_LIT>" % seconds)<EOL><DEDENT><DEDENT>if parts:<EOL><INDENT>parts.insert(<NUM_LIT:0>, sep)<EOL><DEDENT>years, months, days = self.years_months_days<EOL>if days:<EOL><INDENT>parts.insert(<NUM_LIT:0>, "<STR_LIT>" % days)<EOL><DEDENT>if months:<EOL><INDENT>parts.insert(<NUM_LIT:0>, "<STR_LIT>" % months)<EOL><DEDENT>if years:<EOL><INDENT>parts.insert(<NUM_LIT:0>, "<STR_LIT>" % years)<EOL><DEDENT>if parts:<EOL><INDENT>parts.insert(<NUM_LIT:0>, "<STR_LIT:P>")<EOL>return "<STR_LIT>".join(parts)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>
|
:return:
|
f4944:c2:m15
|
@property<EOL><INDENT>def months(self):<DEDENT>
|
return self[<NUM_LIT:0>]<EOL>
|
:return:
|
f4944:c2:m16
|
@property<EOL><INDENT>def days(self):<DEDENT>
|
return self[<NUM_LIT:1>]<EOL>
|
:return:
|
f4944:c2:m17
|
@property<EOL><INDENT>def seconds(self):<DEDENT>
|
return self[<NUM_LIT:2>]<EOL>
|
:return:
|
f4944:c2:m18
|
@property<EOL><INDENT>def subseconds(self):<DEDENT>
|
return self[<NUM_LIT:3>]<EOL>
|
:return:
|
f4944:c2:m19
|
@property<EOL><INDENT>def years_months_days(self):<DEDENT>
|
years, months = symmetric_divmod(self[<NUM_LIT:0>], <NUM_LIT:12>)<EOL>return years, months, self[<NUM_LIT:1>]<EOL>
|
:return:
|
f4944:c2:m20
|
@property<EOL><INDENT>def hours_minutes_seconds(self):<DEDENT>
|
minutes, seconds = symmetric_divmod(self[<NUM_LIT:2>], <NUM_LIT>)<EOL>hours, minutes = symmetric_divmod(minutes, <NUM_LIT>)<EOL>return hours, minutes, float(seconds) + self[<NUM_LIT:3>]<EOL>
|
A 3-tuple of (hours, minutes, seconds).
|
f4944:c2:m21
|
def __getattr__(self, name):
|
try:<EOL><INDENT>return {<EOL>"<STR_LIT>": self.iso_calendar,<EOL>"<STR_LIT>": self.iso_format,<EOL>"<STR_LIT>": self.iso_weekday,<EOL>"<STR_LIT>": self.__format__,<EOL>"<STR_LIT>": self.to_ordinal,<EOL>"<STR_LIT>": self.time_tuple,<EOL>}[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AttributeError("<STR_LIT>" % name)<EOL><DEDENT>
|
Map standard library attribute names to local attribute names,
for compatibility.
|
f4944:c3:m2
|
@classmethod<EOL><INDENT>def from_ordinal(cls, ordinal):<DEDENT>
|
if ordinal == <NUM_LIT:0>:<EOL><INDENT>return ZeroDate<EOL><DEDENT>if ordinal >= <NUM_LIT>:<EOL><INDENT>year = <NUM_LIT> <EOL>month = <NUM_LIT:1><EOL>day = int(ordinal - <NUM_LIT>)<EOL><DEDENT>elif ordinal >= <NUM_LIT>:<EOL><INDENT>year = <NUM_LIT> <EOL>month = <NUM_LIT:1><EOL>day = int(ordinal - <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>year = <NUM_LIT:1><EOL>month = <NUM_LIT:1><EOL>day = int(ordinal)<EOL><DEDENT>if day < <NUM_LIT:1> or day > <NUM_LIT>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if year < MIN_YEAR or year > MAX_YEAR:<EOL><INDENT>raise ValueError("<STR_LIT>" % (MIN_YEAR, MAX_YEAR))<EOL><DEDENT>days_in_year = DAYS_IN_YEAR[year]<EOL>while day > days_in_year:<EOL><INDENT>day -= days_in_year<EOL>year += <NUM_LIT:1><EOL>days_in_year = DAYS_IN_YEAR[year]<EOL><DEDENT>days_in_month = DAYS_IN_MONTH[(year, month)]<EOL>while day > days_in_month:<EOL><INDENT>day -= days_in_month<EOL>month += <NUM_LIT:1><EOL>days_in_month = DAYS_IN_MONTH[(year, month)]<EOL><DEDENT>year, month, day = _normalize_day(year, month, day)<EOL>return cls.__new(ordinal, year, month, day)<EOL>
|
Return the :class:`.Date` that corresponds to the proleptic
Gregorian ordinal, where ``0001-01-01`` has ordinal 1 and
``9999-12-31`` has ordinal 3,652,059. Values outside of this
range trigger a :exc:`ValueError`. The corresponding instance
method for the reverse date-to-ordinal transformation is
:meth:`.to_ordinal`.
|
f4944:c3:m7
|
@classmethod<EOL><INDENT>def parse(cls, s):<DEDENT>
|
try:<EOL><INDENT>numbers = map(int, s.split("<STR_LIT:->"))<EOL><DEDENT>except (ValueError, AttributeError):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>numbers = list(numbers)<EOL>if len(numbers) == <NUM_LIT:3>:<EOL><INDENT>return cls(*numbers)<EOL><DEDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>
|
Parse a string to produce a :class:`.Date`.
Accepted formats:
'YYYY-MM-DD'
:param s:
:return:
|
f4944:c3:m8
|
@classmethod<EOL><INDENT>def from_native(cls, d):<DEDENT>
|
return Date.from_ordinal(d.toordinal())<EOL>
|
Convert from a native Python `datetime.date` value.
|
f4944:c3:m10
|
@classmethod<EOL><INDENT>def from_clock_time(cls, clock_time, epoch):<DEDENT>
|
try:<EOL><INDENT>clock_time = ClockTime(*clock_time)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>ordinal = clock_time.seconds // <NUM_LIT><EOL>return Date.from_ordinal(ordinal + epoch.date().to_ordinal())<EOL><DEDENT>
|
Convert from a ClockTime relative to a given epoch.
|
f4944:c3:m11
|
def replace(self, **kwargs):
|
return Date(kwargs.get("<STR_LIT>", self.__year),<EOL>kwargs.get("<STR_LIT>", self.__month),<EOL>kwargs.get("<STR_LIT>", self.__day))<EOL>
|
Return a :class:`.Date` with one or more components replaced
with new values.
|
f4944:c3:m31
|
def to_ordinal(self):
|
return self.__ordinal<EOL>
|
Return the current value as an ordinal.
|
f4944:c3:m33
|
def to_native(self):
|
return date.fromordinal(self.to_ordinal())<EOL>
|
Convert to a native Python `datetime.date` value.
|
f4944:c3:m35
|
def __getattr__(self, name):
|
try:<EOL><INDENT>return {<EOL>"<STR_LIT>": self.iso_format,<EOL>"<STR_LIT>": self.utc_offset,<EOL>}[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AttributeError("<STR_LIT>" % name)<EOL><DEDENT>
|
Map standard library attribute names to local attribute names,
for compatibility.
|
f4944:c4:m2
|
@classmethod<EOL><INDENT>def from_native(cls, t):<DEDENT>
|
second = (<NUM_LIT> * t.second + t.microsecond) / <NUM_LIT><EOL>return Time(t.hour, t.minute, second, t.tzinfo)<EOL>
|
Convert from a native Python `datetime.time` value.
|
f4944:c4:m7
|
@classmethod<EOL><INDENT>def from_clock_time(cls, clock_time, epoch):<DEDENT>
|
clock_time = ClockTime(*clock_time)<EOL>ts = clock_time.seconds % <NUM_LIT><EOL>nanoseconds = int(<NUM_LIT> * ts + clock_time.nanoseconds)<EOL>return Time.from_ticks(epoch.time().ticks + nanoseconds / <NUM_LIT>)<EOL>
|
Convert from a `.ClockTime` relative to a given epoch.
|
f4944:c4:m8
|
@property<EOL><INDENT>def ticks(self):<DEDENT>
|
return self.__ticks<EOL>
|
Return the total number of seconds since midnight.
|
f4944:c4:m12
|
def replace(self, **kwargs):
|
return Time(kwargs.get("<STR_LIT>", self.__hour),<EOL>kwargs.get("<STR_LIT>", self.__minute),<EOL>kwargs.get("<STR_LIT>", self.__second),<EOL>kwargs.get("<STR_LIT>", self.__tzinfo))<EOL>
|
Return a :class:`.Time` with one or more components replaced
with new values.
|
f4944:c4:m27
|
def to_native(self):
|
h, m, s = self.hour_minute_second<EOL>s, ns = nano_divmod(s, <NUM_LIT:1>)<EOL>ms = int(nano_mul(ns, <NUM_LIT>))<EOL>return time(h, m, s, ms)<EOL>
|
Convert to a native Python `datetime.time` value.
|
f4944:c4:m32
|
def __getattr__(self, name):
|
try:<EOL><INDENT>return {<EOL>"<STR_LIT>": self.as_timezone,<EOL>"<STR_LIT>": self.iso_calendar,<EOL>"<STR_LIT>": self.iso_format,<EOL>"<STR_LIT>": self.iso_weekday,<EOL>"<STR_LIT>": self.__format__,<EOL>"<STR_LIT>": self.to_ordinal,<EOL>"<STR_LIT>": self.time_tuple,<EOL>"<STR_LIT>": self.utc_offset,<EOL>"<STR_LIT>": self.utc_time_tuple,<EOL>}[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AttributeError("<STR_LIT>" % name)<EOL><DEDENT>
|
Map standard library attribute names to local attribute names,
for compatibility.
|
f4944:c5:m1
|
@classmethod<EOL><INDENT>def from_native(cls, dt):<DEDENT>
|
return cls.combine(Date.from_native(dt.date()), Time.from_native(dt.time()))<EOL>
|
Convert from a native Python `datetime.datetime` value.
|
f4944:c5:m10
|
@classmethod<EOL><INDENT>def from_clock_time(cls, clock_time, epoch):<DEDENT>
|
try:<EOL><INDENT>seconds, nanoseconds = ClockTime(*clock_time)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>ordinal, ticks = divmod(seconds, <NUM_LIT>)<EOL>date_ = Date.from_ordinal(ordinal + epoch.date().to_ordinal())<EOL>nanoseconds = int(<NUM_LIT> * ticks + nanoseconds)<EOL>time_ = Time.from_ticks(epoch.time().ticks + (nanoseconds / <NUM_LIT>))<EOL>return cls.combine(date_, time_)<EOL><DEDENT>
|
Convert from a ClockTime relative to a given epoch.
|
f4944:c5:m11
|
def to_native(self):
|
y, mo, d = self.year_month_day<EOL>h, m, s = self.hour_minute_second<EOL>s, ns = nano_divmod(s, <NUM_LIT:1>)<EOL>ms = int(nano_mul(ns, <NUM_LIT>))<EOL>return datetime(y, mo, d, h, m, s, ms)<EOL>
|
Convert to a native Python `datetime.datetime` value.
|
f4944:c5:m44
|
def nano_add(x, y):
|
return (int(<NUM_LIT> * x) + int(<NUM_LIT> * y)) / <NUM_LIT><EOL>
|
>>> 0.7 + 0.2
0.8999999999999999
>>> -0.7 + 0.2
-0.49999999999999994
>>> nano_add(0.7, 0.2)
0.9
>>> nano_add(-0.7, 0.2)
-0.5
:param x:
:param y:
:return:
|
f4946:m0
|
def nano_sub(x, y):
|
return (int(<NUM_LIT> * x) - int(<NUM_LIT> * y)) / <NUM_LIT><EOL>
|
>>> 0.7 - 0.2
0.49999999999999994
>>> -0.7 - 0.2
-0.8999999999999999
>>> nano_sub(0.7, 0.2)
0.5
>>> nano_sub(-0.7, 0.2)
-0.9
:param x:
:param y:
:return:
|
f4946:m1
|
def nano_mul(x, y):
|
return int(<NUM_LIT> * x) * int(<NUM_LIT> * y) / <NUM_LIT><EOL>
|
>>> 0.7 * 0.2
0.13999999999999999
>>> -0.7 * 0.2
-0.13999999999999999
>>> nano_mul(0.7, 0.2)
0.14
>>> nano_mul(-0.7, 0.2)
-0.14
:param x:
:param y:
:return:
|
f4946:m2
|
def nano_div(x, y):
|
return float(<NUM_LIT> * x) / int(<NUM_LIT> * y)<EOL>
|
>>> 0.7 / 0.2
3.4999999999999996
>>> -0.7 / 0.2
-3.4999999999999996
>>> nano_div(0.7, 0.2)
3.5
>>> nano_div(-0.7, 0.2)
-3.5
:param x:
:param y:
:return:
|
f4946:m3
|
def nano_mod(x, y):
|
number = type(x)<EOL>nx = int(<NUM_LIT> * x)<EOL>ny = int(<NUM_LIT> * y)<EOL>q, r = divmod(nx, ny)<EOL>return number(r / <NUM_LIT>)<EOL>
|
>>> 0.7 % 0.2
0.09999999999999992
>>> -0.7 % 0.2
0.10000000000000009
>>> nano_mod(0.7, 0.2)
0.1
>>> nano_mod(-0.7, 0.2)
0.1
:param x:
:param y:
:return:
|
f4946:m4
|
def nano_divmod(x, y):
|
number = type(x)<EOL>nx = int(<NUM_LIT> * x)<EOL>ny = int(<NUM_LIT> * y)<EOL>q, r = divmod(nx, ny)<EOL>return int(q), number(r / <NUM_LIT>)<EOL>
|
>>> divmod(0.7, 0.2)
(3.0, 0.09999999999999992)
>>> nano_divmod(0.7, 0.2)
(3, 0.1)
:param x:
:param y:
:return:
|
f4946:m5
|
def round_half_to_even(n):
|
ten_n = <NUM_LIT:10> * n<EOL>if ten_n == int(ten_n) and ten_n % <NUM_LIT:10> == <NUM_LIT:5>:<EOL><INDENT>up = int(n + <NUM_LIT:0.5>)<EOL>down = int(n - <NUM_LIT:0.5>)<EOL>return up if up % <NUM_LIT:2> == <NUM_LIT:0> else down<EOL><DEDENT>else:<EOL><INDENT>return int(round(n))<EOL><DEDENT>
|
>>> round_half_to_even(3)
3
>>> round_half_to_even(3.2)
3
>>> round_half_to_even(3.5)
4
>>> round_half_to_even(3.7)
4
>>> round_half_to_even(4)
4
>>> round_half_to_even(4.2)
4
>>> round_half_to_even(4.5)
4
>>> round_half_to_even(4.7)
5
:param n:
:return:
|
f4946:m8
|
def get(self, option):
|
return None<EOL>
|
Tries to find a configuration variable in the current store.
Returns:
string, number, boolean or other representation of what was found or
None when nothing found.
|
f4972:c0:m1
|
def __init__(self, prefix, section, filename=None):
|
options = dict(prefix=prefix, section=section, filename=filename)<EOL>super(Settings, self).__init__(**options)<EOL>
|
Will try to read configuration from environment variables and ini
files, if no value found in either of those ``None`` is
returned.
Args:
prefix: The environment variable prefix.
section: The ini file section this configuration is scoped to
filename: The path to the ini file to use
|
f4972:c4:m0
|
def expand_user(path):
|
if not path.startswith('<STR_LIT>'):<EOL><INDENT>return path<EOL><DEDENT>if os.name == '<STR_LIT>':<EOL><INDENT>user = pwd.getpwuid(os.geteuid())<EOL>return path.replace('<STR_LIT>', user.pw_dir, <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>return os.path.expanduser(path)<EOL><DEDENT>
|
Expands ~/path to /home/<current_user>/path
On POSIX systems does it by getting the home directory for the
current effective user from the passwd database. On other systems
do it by using :func:`os.path.expanduser`
Args:
path (str): A path to expand to a user's home folder
Returns:
str: expanded path
|
f4973:m4
|
def format_arguments(*args):
|
positional_args = []<EOL>kwargs = {}<EOL>split_key = None<EOL>for arg in args:<EOL><INDENT>if arg.startswith('<STR_LIT>'):<EOL><INDENT>arg = arg[<NUM_LIT:2>:]<EOL>if '<STR_LIT:=>' in arg:<EOL><INDENT>key, value = arg.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL>kwargs[key.replace('<STR_LIT:->', '<STR_LIT:_>')] = value<EOL><DEDENT>else:<EOL><INDENT>split_key = arg.replace('<STR_LIT:->', '<STR_LIT:_>')<EOL><DEDENT><DEDENT>elif split_key:<EOL><INDENT>kwargs[split_key] = arg<EOL>split_key = None<EOL><DEDENT>else:<EOL><INDENT>positional_args.append(arg)<EOL><DEDENT><DEDENT>return positional_args, kwargs<EOL>
|
Converts a list of arguments from the command line into a list of
positional arguments and a dictionary of keyword arguments.
Handled formats for keyword arguments are:
* --argument=value
* --argument value
Args:
*args (list): a list of arguments
Returns:
([positional_args], {kwargs})
|
f4973:m6
|
def get_command(go_server, command, subcommand, *args):
|
try:<EOL><INDENT>command_package = get_command_module(command)<EOL><DEDENT>except ImportError as exc:<EOL><INDENT>raise ImportError('<STR_LIT>'.format(exc))<EOL><DEDENT>class_name = classify_name(subcommand)<EOL>try:<EOL><INDENT>Klass = getattr(command_package, class_name)<EOL><DEDENT>except AttributeError as exc:<EOL><INDENT>raise AttributeError('<STR_LIT>'.format(command_package.__name__, exc))<EOL><DEDENT>args, kwargs = format_arguments(*args)<EOL>try:<EOL><INDENT>return Klass(go_server, *args, **kwargs)<EOL><DEDENT>except TypeError as exc:<EOL><INDENT>raise TypeError('<STR_LIT>'.format(class_name, exc))<EOL><DEDENT>
|
Raises:
AttributeError: when the `subcommand` doesn't exist in the
`command` package
ImportError: when the package `command` doesn't exist.
TypeError: when failing to initialize the `subcommand`
|
f4973:m7
|
def get_settings(section='<STR_LIT>', settings_paths=('<STR_LIT>', '<STR_LIT>')):
|
if isinstance(settings_paths, basestring):<EOL><INDENT>settings_paths = (settings_paths,)<EOL><DEDENT>config_file = next((path for path in settings_paths if is_file_readable(path)), None)<EOL>if config_file:<EOL><INDENT>config_file = expand_user(config_file)<EOL><DEDENT>return Settings(prefix=section, section=section, filename=config_file)<EOL>
|
Returns a `gocd_cli.settings.Settings` configured for settings file
The settings will be read from environment variables first, then
it'll be read from the first config file found (if any).
Environment variables are expected to be in UPPERCASE and to be prefixed
with `GOCD_`.
Args:
section: The prefix to use for reading environment variables and the
name of the section in the config file. Default: gocd
settings_path: Possible paths for the configuration file.
Default: `('~/.gocd/gocd-cli.cfg', '/etc/go/gocd-cli.cfg')`
Returns:
`gocd_cli.settings.Settings` instance
|
f4973:m8
|
def get_go_server(settings=None):
|
if not settings:<EOL><INDENT>settings = get_settings()<EOL><DEDENT>return gocd.Server(<EOL>settings.get('<STR_LIT>'),<EOL>user=settings.get('<STR_LIT:user>'),<EOL>password=settings.get('<STR_LIT:password>'),<EOL>)<EOL>
|
Returns a `gocd.Server` configured by the `settings`
object.
Args:
settings: a `gocd_cli.settings.Settings` object.
Default: if falsey calls `get_settings`.
Returns:
gocd.Server: a configured gocd.Server instance
|
f4973:m9
|
def _generate_simple_containers(*generators, **opts):
|
repeat = opts.get('<STR_LIT>', <NUM_LIT:1>)<EOL>targets = tuple(chain(*generators))<EOL>for empty_p in _generate_empty_containers():<EOL><INDENT>start_event, end_event = empty_p.events<EOL>delim = b'<STR_LIT:U+002C>'<EOL>if start_event.ion_type is _IT.SEXP:<EOL><INDENT>delim = b'<STR_LIT:U+0020>'<EOL><DEDENT>for value_p in targets:<EOL><INDENT>field_names = (None,)<EOL>if start_event.ion_type is _IT.STRUCT:<EOL><INDENT>field_names = (_SIMPLE_FIELD_NAME, _TOKEN_FIELD_NAME)<EOL><DEDENT>for field_name in field_names:<EOL><INDENT>b_start = empty_p.expected[<NUM_LIT:0>:<NUM_LIT:1>]<EOL>b_end = empty_p.expected[-<NUM_LIT:1>:]<EOL>value_event = value_p.events[<NUM_LIT:0>]<EOL>value_expected = value_p.expected<EOL>if field_name is not None:<EOL><INDENT>value_event = value_event.derive_field_name(field_name)<EOL>if isinstance(field_name, SymbolToken):<EOL><INDENT>value_expected =(u'<STR_LIT>'% field_name.sid).encode() + value_expected<EOL><DEDENT>else:<EOL><INDENT>value_expected =field_name.encode() + b"<STR_LIT::>" + value_expected<EOL><DEDENT><DEDENT>value_events = (value_event,) + value_p.events[<NUM_LIT:1>:]<EOL>events = (start_event,) + (value_events * repeat) + (end_event,)<EOL>expected = b_start + delim.join([value_expected] * repeat) + b_end<EOL>yield _P(<EOL>desc='<STR_LIT>' % (start_event.ion_type.name, expected),<EOL>events=events,<EOL>expected=expected<EOL>)<EOL><DEDENT><DEDENT><DEDENT>
|
Composes the empty tests with the simple scalars to make singletons.
|
f4978:m1
|
@coroutine<EOL>def always_self(result_func):
|
_, self = (yield)<EOL>while True:<EOL><INDENT>yield result_func(self)<EOL><DEDENT>
|
A simple co-routine that yields a result and transitions to itself indefinitely.
|
f4979:m0
|
@coroutine<EOL>def moves_to(target, result_func):
|
yield<EOL>yield result_func(target)<EOL>
|
A simple co-routine that yields a result and transitions to another co-routine.
|
f4979:m1
|
@coroutine<EOL>def yields_iter(*seq):
|
yield<EOL>for val in seq:<EOL><INDENT>yield val<EOL><DEDENT>
|
A simple co-routine that yields over an iterable ignoring what is sent to it.
Note that an iterator doesn't work because of the *priming* ``yield`` and ``listiterator``
and the like don't support ``send()``.
|
f4979:m2
|
def trampoline_scaffold(trampoline_func, p, *args):
|
trampoline = trampoline_func(p.coroutine, *args)<EOL>assert len(p.input) == len(p.expected)<EOL>for input, expected in zip(p.input, p.expected):<EOL><INDENT>if is_exception(expected):<EOL><INDENT>with raises(expected):<EOL><INDENT>trampoline.send(input)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output = trampoline.send(input)<EOL>assert expected == output<EOL><DEDENT><DEDENT>
|
Testing structure for trampolines.
Args:
trampoline_func (Callable): The function to construct a trampoline.
p (TrampolineParams): The parameters for the test.
|
f4979:m3
|
def _nextify(iter_func):
|
def delegate(*args, **kw_args):<EOL><INDENT>for ion_event in iter_func(*args, **kw_args):<EOL><INDENT>yield NEXT_EVENT, ion_event<EOL><DEDENT><DEDENT>delegate.__name__ = iter_func.__name__<EOL>return delegate<EOL>
|
Creates a decorator that generates event pairs of ``(NEXT_EVENT, event)``
where ``event`` are instances returned by the decorated function.
|
f4980:m0
|
@listify<EOL>@_nextify<EOL>def _lst(imports=None, symbols=None, token=_system_sid_token):
|
yield e_start_struct(annotations=(token(TEXT_ION_SYMBOL_TABLE),))<EOL>if imports is not None:<EOL><INDENT>if imports is _APPEND:<EOL><INDENT>yield e_symbol(token(TEXT_ION_SYMBOL_TABLE), field_name=(token(TEXT_IMPORTS)))<EOL><DEDENT>else:<EOL><INDENT>yield e_start_list(field_name=(token(TEXT_IMPORTS)))<EOL>for desc in imports:<EOL><INDENT>yield e_start_struct()<EOL>if desc.name is not None:<EOL><INDENT>yield e_string(desc.name, field_name=token(TEXT_NAME))<EOL><DEDENT>if desc.version is not None:<EOL><INDENT>yield e_int(desc.version, field_name=token(TEXT_VERSION))<EOL><DEDENT>if desc.max_id is not None:<EOL><INDENT>yield e_int(desc.max_id, field_name=token(TEXT_MAX_ID))<EOL><DEDENT>yield e_end_struct()<EOL><DEDENT>yield e_end_list()<EOL><DEDENT><DEDENT>if symbols is not None:<EOL><INDENT>yield e_start_list(field_name=(token(TEXT_SYMBOLS)))<EOL>for symbol_text in symbols:<EOL><INDENT>yield e_string(symbol_text)<EOL><DEDENT>yield e_end_list()<EOL><DEDENT>yield e_end_struct()<EOL>
|
Generates a list of event pairs for a local symbol table.
Args:
sys (SymbolTable): The symbol table to resolve SIDs from.
imports (Optional[Iterable[_ImportDesc]]): The symbol tables to import.
symbols (Optional[Iterable[Unicode]]): The local symbols to declare.
token (Optional[Callable]): Function to construct the token directly from text,
by default it uses the system symbol table.
Returns:
List[Tuple[ReadEvent,IonEvent]]
|
f4980:m4
|
def _create_lst_params(<EOL>prefix_desc='<STR_LIT>',<EOL>prefix_pairs=None,<EOL>token=_system_sid_token,<EOL>append_start=SYSTEM_SYMBOL_TABLE.max_id):
|
if prefix_pairs is None:<EOL><INDENT>prefix_pairs = [(NEXT, IVM)]<EOL><DEDENT>params = [<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(symbols=[u'<STR_LIT:a>', u'<STR_LIT:b>', u'<STR_LIT:c>'], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:11>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:12>))),<EOL>(NEXT, e_symbol(None)),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:b>', <NUM_LIT:11>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:c>', <NUM_LIT:12>))),<EOL>(NEXT, e_symbol(None)),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(symbols=[u'<STR_LIT:a>'], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>] + _lst(symbols=[u'<STR_LIT:b>'], token=_system_sid_token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, IVM),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:b>', <NUM_LIT:10>))),<EOL>(NEXT, IonException),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(symbols=[u'<STR_LIT>', u'<STR_LIT:a>'], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:11>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:11>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:11>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:11>))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(imports=[_desc(u'<STR_LIT>', <NUM_LIT:1>, <NUM_LIT:10>), _desc(u'<STR_LIT>', <NUM_LIT:1>, <NUM_LIT:5>)], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(None, <NUM_LIT:10>, _loc(u'<STR_LIT>', <NUM_LIT:1>)))),<EOL>(NEXT, e_symbol(_tok(None, <NUM_LIT>, _loc(u'<STR_LIT>', <NUM_LIT:3>)))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(imports=[_desc(u'<STR_LIT:foo>', <NUM_LIT:3>), _desc(u'<STR_LIT:bar>', <NUM_LIT:1>)], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:15>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:16>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:f>', <NUM_LIT:15>, _loc(u'<STR_LIT:foo>', <NUM_LIT:6>)))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:x>', <NUM_LIT:16>, _loc(u'<STR_LIT:bar>', <NUM_LIT:1>)))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(imports=[_desc(u'<STR_LIT:foo>'), _desc(u'<STR_LIT:bar>')], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:11>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:b>', <NUM_LIT:11>, _loc(u'<STR_LIT:foo>', <NUM_LIT:2>)))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:y>', <NUM_LIT>, _loc(u'<STR_LIT:bar>', <NUM_LIT:2>)))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(imports=[_desc(u'<STR_LIT>')], token=token),<EOL>outer=[<EOL>(NEXT, CannotSubstituteTable),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(imports=[_desc(u'<STR_LIT:bar>', max_id=<NUM_LIT:2>)], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:11>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:y>', <NUM_LIT:11>, _loc(u'<STR_LIT:bar>', <NUM_LIT:2>)))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(<EOL>imports=[_desc(u'<STR_LIT:foo>', <NUM_LIT:3>, <NUM_LIT:4>)],<EOL>symbols=[u'<STR_LIT>', u'<STR_LIT>', u'<STR_LIT>', u'<STR_LIT>'],<EOL>token=token<EOL>) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:15>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:d>', <NUM_LIT>, _loc(u'<STR_LIT:foo>', <NUM_LIT:4>)))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT>', <NUM_LIT:15>))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(imports=_APPEND, symbols=[u'<STR_LIT:a>', u'<STR_LIT:b>', u'<STR_LIT:c>'], token=token) + [<EOL>(NEXT, e_symbol(_sid(append_start + <NUM_LIT:1>))),<EOL>(NEXT, e_symbol(_sid(append_start + <NUM_LIT:3>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', append_start + <NUM_LIT:1>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:c>', append_start + <NUM_LIT:3>))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(symbols=[u'<STR_LIT:a>', u'<STR_LIT:b>', u'<STR_LIT:c>'], token=token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:12>))),<EOL>] + _lst(imports=_APPEND, symbols=[u'<STR_LIT:d>', u'<STR_LIT:e>', u'<STR_LIT:f>'], token=_system_sid_token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:15>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:c>', <NUM_LIT:12>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:d>', <NUM_LIT>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:f>', <NUM_LIT:15>))),<EOL>],<EOL>),<EOL>_P(<EOL>desc='<STR_LIT>',<EOL>inner=_lst(<EOL>imports=[_desc(u'<STR_LIT:foo>', <NUM_LIT:3>, <NUM_LIT:4>)],<EOL>symbols=[u'<STR_LIT>', u'<STR_LIT>', u'<STR_LIT>'],<EOL>token=token<EOL>) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:10>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT>))),<EOL>] + _lst(imports=_APPEND, symbols=[u'<STR_LIT>', u'<STR_LIT>', u'<STR_LIT>'], token=_system_sid_token) + [<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:11>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT:15>))),<EOL>(NEXT, e_symbol(_sid(<NUM_LIT>))),<EOL>],<EOL>outer=[<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:a>', <NUM_LIT:10>, _loc(u'<STR_LIT:foo>', <NUM_LIT:1>)))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT>', <NUM_LIT>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT:b>', <NUM_LIT:11>, _loc(u'<STR_LIT:foo>', <NUM_LIT:2>)))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT>', <NUM_LIT:15>))),<EOL>(NEXT, e_symbol(_tok(u'<STR_LIT>', <NUM_LIT>))),<EOL>],<EOL>),<EOL>]<EOL>for param in params:<EOL><INDENT>yield _P(<EOL>desc='<STR_LIT>' + prefix_desc + '<STR_LIT>' + param.desc,<EOL>catalog=_test_catalog(),<EOL>inner= prefix_pairs + param.inner,<EOL>outer=param.outer<EOL>)<EOL><DEDENT>
|
Args:
prefix_desc (Optional[String]): The prefix for the test parameter description.
prefix_pairs (Optional[Iterable[Tuple[DataEvent, IonEvent]]]): The prefix of event pairs to
put into the inner stream, should only be system values.
token (Optional[Callable]): The token encoder.
append_start (Optional[int]): The start of the LST for direct append test cases.
|
f4980:m7
|
def _scalar_event_pairs(data, events, info):
|
first = True<EOL>delimiter, in_container = info<EOL>space_delimited = not (b'<STR_LIT:U+002C>' in delimiter)<EOL>for event in events:<EOL><INDENT>input_event = NEXT<EOL>if first:<EOL><INDENT>input_event = e_read(data + delimiter)<EOL>if space_delimited and event.value is not Noneand ((event.ion_type is IonType.SYMBOL) or<EOL>(event.ion_type is IonType.STRING and<EOL>six.byte2int(b'<STR_LIT:">') != six.indexbytes(data, <NUM_LIT:0>))): <EOL><INDENT>yield input_event, INC<EOL>if in_container:<EOL><INDENT>yield e_read(b'<STR_LIT:0>' + delimiter), event<EOL>input_event, event = (NEXT, e_int(<NUM_LIT:0>))<EOL><DEDENT>else:<EOL><INDENT>input_event, event = (NEXT, event)<EOL><DEDENT><DEDENT>first = False<EOL><DEDENT>yield input_event, event<EOL><DEDENT>
|
Generates event pairs for all scalars.
Each scalar is represented by a sequence whose first element is the raw data and whose following elements are the
expected output events.
|
f4983:m2
|
@coroutine<EOL>def _scalar_params():
|
while True:<EOL><INDENT>info = yield<EOL>for data, event_pairs in _scalar_iter(info):<EOL><INDENT>yield _P(<EOL>desc=data,<EOL>event_pairs=event_pairs + [(NEXT, INC)]<EOL>)<EOL><DEDENT><DEDENT>
|
Generates scalars as reader parameters.
|
f4983:m3
|
def _top_level_value_params(delimiter=b'<STR_LIT:U+0020>', is_delegate=False):
|
info = (delimiter, False)<EOL>for data, event_pairs in _scalar_iter(info):<EOL><INDENT>_, first = event_pairs[<NUM_LIT:0>]<EOL>if first.event_type is IonEventType.INCOMPLETE: <EOL><INDENT>_, first = event_pairs[<NUM_LIT:1>]<EOL><DEDENT>yield _P(<EOL>desc='<STR_LIT>' %<EOL>(first.event_type.name, first.ion_type.name, data),<EOL>event_pairs=[(NEXT, END)] + event_pairs + [(NEXT, END)],<EOL>)<EOL><DEDENT>if is_delegate:<EOL><INDENT>yield<EOL><DEDENT>
|
Converts the top-level tuple list into parameters with appropriate ``NEXT`` inputs.
The expectation is starting from an end of stream top-level context.
|
f4983:m4
|
@coroutine<EOL>def _all_scalars_in_one_container_params():
|
while True:<EOL><INDENT>info = yield<EOL>@listify<EOL>def generate_event_pairs():<EOL><INDENT>for data, event_pairs in _scalar_iter(info):<EOL><INDENT>pairs = ((i, o) for i, o in event_pairs)<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>input_event, output_event = next(pairs)<EOL>yield input_event, output_event<EOL>if output_event is INC:<EOL><INDENT>yield next(pairs) <EOL>yield next(pairs) <EOL><DEDENT>yield (NEXT, INC)<EOL><DEDENT>except StopIteration:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT><DEDENT>yield _P(<EOL>desc='<STR_LIT>',<EOL>event_pairs=generate_event_pairs()<EOL>)<EOL><DEDENT>
|
Generates one parameter that contains all scalar events in a single container.
|
f4983:m5
|
def _collect_params(param_generator, info):
|
params = []<EOL>while True:<EOL><INDENT>param = param_generator.send(info)<EOL>if param is None:<EOL><INDENT>return params<EOL><DEDENT>params.append(param)<EOL><DEDENT>
|
Collects all output of the given coroutine into a single list.
|
f4983:m6
|
def _generate_annotations():
|
assert len(_TEST_SYMBOLS[<NUM_LIT:0>]) == len(_TEST_SYMBOLS[<NUM_LIT:1>])<EOL>i = <NUM_LIT:1><EOL>num_symbols = len(_TEST_SYMBOLS[<NUM_LIT:0>])<EOL>while True:<EOL><INDENT>yield _TEST_SYMBOLS[<NUM_LIT:0>][<NUM_LIT:0>:i], _TEST_SYMBOLS[<NUM_LIT:1>][<NUM_LIT:0>:i]<EOL>i += <NUM_LIT:1><EOL>if i == num_symbols:<EOL><INDENT>i = <NUM_LIT:0><EOL><DEDENT><DEDENT>
|
Circularly generates annotations.
|
f4983:m7
|
@coroutine<EOL>def _annotate_params(params, is_delegate=False):
|
while True:<EOL><INDENT>info = yield<EOL>params_list = _collect_params(params, info)<EOL>test_annotations, expected_annotations = next(_annotations_generator)<EOL>for param in params_list:<EOL><INDENT>@listify<EOL>def annotated():<EOL><INDENT>pairs = ((i, o) for i, o in param.event_pairs)<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>input_event, output_event = next(pairs)<EOL>if input_event.type is ReadEventType.DATA:<EOL><INDENT>data = b'<STR_LIT>'<EOL>for test_annotation in test_annotations:<EOL><INDENT>data += test_annotation + b'<STR_LIT>'<EOL><DEDENT>data += input_event.data<EOL>input_event = read_data_event(data)<EOL>if output_event is INC:<EOL><INDENT>yield input_event, output_event<EOL>input_event, output_event = next(pairs)<EOL><DEDENT>output_event = output_event.derive_annotations(expected_annotations)<EOL><DEDENT>yield input_event, output_event<EOL><DEDENT>except StopIteration:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>yield _P(<EOL>desc='<STR_LIT>' % (expected_annotations, param.desc),<EOL>event_pairs=annotated(),<EOL>)<EOL><DEDENT>if not is_delegate:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
|
Adds annotation wrappers for a given iterator of parameters.
|
f4983:m8
|
def _generate_field_name():
|
assert len(_TEST_FIELD_NAMES[<NUM_LIT:0>]) == len(_TEST_FIELD_NAMES[<NUM_LIT:1>])<EOL>i = <NUM_LIT:0><EOL>num_symbols = len(_TEST_FIELD_NAMES[<NUM_LIT:0>])<EOL>while True:<EOL><INDENT>yield _TEST_FIELD_NAMES[<NUM_LIT:0>][i], _TEST_FIELD_NAMES[<NUM_LIT:1>][i]<EOL>i += <NUM_LIT:1><EOL>if i == num_symbols:<EOL><INDENT>i = <NUM_LIT:0><EOL><DEDENT><DEDENT>
|
Circularly generates field names.
|
f4983:m9
|
@coroutine<EOL>def _containerize_params(param_generator, with_skip=True, is_delegate=False, top_level=True):
|
while True:<EOL><INDENT>yield<EOL>for info in ((IonType.LIST, b'<STR_LIT:[>', b'<STR_LIT:]>', b'<STR_LIT:U+002C>'),<EOL>(IonType.SEXP, b'<STR_LIT:(>', b'<STR_LIT:)>', b'<STR_LIT:U+0020>'), <EOL>(IonType.STRUCT, b'<STR_LIT>', b'<STR_LIT:}>', b'<STR_LIT:U+002C>'), <EOL>(IonType.LIST, b'<STR_LIT>', b'<STR_LIT>', b'<STR_LIT>'),<EOL>(IonType.SEXP, b'<STR_LIT>', b'<STR_LIT>', b'<STR_LIT>'),<EOL>(IonType.STRUCT, b'<STR_LIT>', b'<STR_LIT>', b'<STR_LIT>')):<EOL><INDENT>ion_type = info[<NUM_LIT:0>]<EOL>params = _collect_params(param_generator, (info[<NUM_LIT:3>], True))<EOL>for param in params:<EOL><INDENT>@listify<EOL>def add_field_names(event_pairs):<EOL><INDENT>container = False<EOL>first = True<EOL>for read_event, ion_event in event_pairs:<EOL><INDENT>if not container and read_event.type is ReadEventType.DATA:<EOL><INDENT>field_name, expected_field_name = next(_field_name_generator)<EOL>data = field_name + b'<STR_LIT::>' + read_event.data<EOL>read_event = read_data_event(data)<EOL>ion_event = ion_event.derive_field_name(expected_field_name)<EOL><DEDENT>if first and ion_event.event_type is IonEventType.CONTAINER_START:<EOL><INDENT>container = True<EOL><DEDENT>first = False<EOL>yield read_event, ion_event<EOL><DEDENT><DEDENT>start = []<EOL>end = [(e_read(info[<NUM_LIT:2>]), e_end(ion_type))]<EOL>if top_level:<EOL><INDENT>start = [(NEXT, END)]<EOL>end += [(NEXT, END)]<EOL><DEDENT>else:<EOL><INDENT>end += [(NEXT, INC)]<EOL><DEDENT>start += [<EOL>(e_read(info[<NUM_LIT:1>]), e_start(ion_type)),<EOL>(NEXT, INC)<EOL>]<EOL>if ion_type is IonType.STRUCT:<EOL><INDENT>mid = add_field_names(param.event_pairs)<EOL><DEDENT>else:<EOL><INDENT>mid = param.event_pairs<EOL><DEDENT>desc = '<STR_LIT>' % (ion_type.name, param.desc)<EOL>yield _P(<EOL>desc=desc,<EOL>event_pairs=start + mid + end,<EOL>)<EOL>if with_skip:<EOL><INDENT>@listify<EOL>def only_data_inc(event_pairs):<EOL><INDENT>for read_event, ion_event in event_pairs:<EOL><INDENT>if read_event.type is ReadEventType.DATA:<EOL><INDENT>yield read_event, INC<EOL><DEDENT><DEDENT><DEDENT>start = start[:-<NUM_LIT:1>] + [(SKIP, INC)]<EOL>mid = only_data_inc(mid)<EOL>yield _P(<EOL>desc='<STR_LIT>' % desc,<EOL>event_pairs=start + mid + end,<EOL>)<EOL><DEDENT><DEDENT><DEDENT>if not is_delegate:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
|
Adds container wrappers for a given iteration of parameters.
|
f4983:m10
|
def _expect_event(expected_event, data, events, delimiter):
|
events += (expected_event,)<EOL>outputs = events[<NUM_LIT:1>:]<EOL>event_pairs = [(e_read(data + delimiter), events[<NUM_LIT:0>])] + list(zip([NEXT] * len(outputs), outputs))<EOL>return event_pairs<EOL>
|
Generates event pairs for a stream that ends in an expected event (or exception), given the text and the output
events preceding the expected event.
|
f4983:m11
|
@coroutine<EOL>def _basic_params(event_func, desc, delimiter, data_event_pairs, is_delegate=False, top_level=True):
|
while True:<EOL><INDENT>yield<EOL>params = list(zip(*list(value_iter(event_func, data_event_pairs, delimiter))))[<NUM_LIT:1>]<EOL>for param in _paired_params(params, desc, top_level):<EOL><INDENT>yield param<EOL><DEDENT>if not is_delegate:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
|
Generates parameters from a sequence whose first element is the raw data and the following
elements are the expected output events.
|
f4983:m12
|
def _paired_params(params, desc, top_level=True):
|
for event_pairs in params:<EOL><INDENT>data = event_pairs[<NUM_LIT:0>][<NUM_LIT:0>].data<EOL>if top_level:<EOL><INDENT>event_pairs = [(NEXT, END)] + event_pairs<EOL><DEDENT>yield _P(<EOL>desc='<STR_LIT>' % (desc, data),<EOL>event_pairs=event_pairs,<EOL>is_unicode=isinstance(data, six.text_type)<EOL>)<EOL><DEDENT>
|
Generates reader parameters from sequences of input/output event pairs.
|
f4983:m13
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.