text stringlengths 0 828 |
|---|
break |
if platform == ""linux"" or platform == ""linux2"": # In linux systems, readchunk() returns a tuple |
chunk = chunk[0] |
resp = dict() |
resp[""data""] = chunk.decode() |
current_milli_time = lambda: int(round(time() * 1000)) |
resp[""timestamp""] = str(current_milli_time()) |
self.subscribe_data = resp |
except Exception as e: |
print(""\n********* Oops: "" + url + "" "" + str(type(e)) + str(e) + "" *********\n"") |
print('\n********* Closing TCP: {} *********\n'.format(url))" |
1266,"def stop_subscribe(self): |
"""""" This function is used to stop the event loop created when subscribe is called. But this function doesn't |
stop the thread and should be avoided until its completely developed. |
"""""" |
asyncio.gather(*asyncio.Task.all_tasks()).cancel() |
self.event_loop.stop() |
self.event_loop.close()" |
1267,"def timesince(d, now=None): |
"""""" |
Takes two datetime objects and returns the time between d and now |
as a nicely formatted string, e.g. ""10 minutes"". If d occurs after now, |
then ""0 minutes"" is returned. |
Units used are years, months, weeks, days, hours, and minutes. |
Seconds and microseconds are ignored. Up to two adjacent units will be |
displayed. For example, ""2 weeks, 3 days"" and ""1 year, 3 months"" are |
possible outputs, but ""2 weeks, 3 hours"" and ""1 year, 5 days"" are not. |
Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since |
"""""" |
chunks = ( |
(60 * 60 * 24 * 365, lambda n: ungettext('year', 'years', n)), |
(60 * 60 * 24 * 30, lambda n: ungettext('month', 'months', n)), |
(60 * 60 * 24 * 7, lambda n : ungettext('week', 'weeks', n)), |
(60 * 60 * 24, lambda n : ungettext('day', 'days', n)), |
(60 * 60, lambda n: ungettext('hour', 'hours', n)), |
(60, lambda n: ungettext('minute', 'minutes', n)) |
) |
# Convert datetime.date to datetime.datetime for comparison. |
if not isinstance(d, datetime.datetime): |
d = datetime.datetime(d.year, d.month, d.day) |
if now and not isinstance(now, datetime.datetime): |
now = datetime.datetime(now.year, now.month, now.day) |
if not now: |
if d.tzinfo: |
now = datetime.datetime.now(LocalTimezone(d)) |
else: |
now = datetime.datetime.now() |
# ignore microsecond part of 'd' since we removed it from 'now' |
delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) |
since = delta.days * 24 * 60 * 60 + delta.seconds |
if since <= 0: |
# d is in the future compared to now, stop processing. |
return u'0 ' + ugettext('minutes') |
for i, (seconds, name) in enumerate(chunks): |
count = since // seconds |
if count != 0: |
break |
s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)} |
if i + 1 < len(chunks): |
# Now get the second item |
seconds2, name2 = chunks[i + 1] |
count2 = (since - (seconds * count)) // seconds2 |
if count2 != 0: |
s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)} |
return s" |
1268,"def timeuntil(d, now=None): |
"""""" |
Like timesince, but returns a string measuring the time until |
the given time. |
"""""" |
if not now: |
if getattr(d, 'tzinfo', None): |
now = datetime.datetime.now(LocalTimezone(d)) |
else: |
now = datetime.datetime.now() |
return timesince(now, d)" |
1269,"def updateCache(self, service, url, new_data, new_data_dt): |
"""""" |
:param new_data: a string representation of the data |
:param new_data_dt: a timezone aware datetime object giving |
the timestamp of the new_data |
:raise MemcachedException: if update failed |
"""""" |
key = self._get_key(service, url) |
# clear existing data |
try: |
value = self.client.get(key) |
if value: |
data = pickle.loads(value, encoding=""utf8"") |
if ""time_stamp"" in data: |
cached_data_dt = parse(data[""time_stamp""]) |
if new_data_dt > cached_data_dt: |
self.client.delete(key) |
# may raise MemcachedException |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.