- generators found in Python 3.3
- event loop in the form of
asyncio
: In Python 3.4, theasyncio.coroutine
decorator was used to label a function as acting as a coroutine that was meant for use withasyncio
and its event loop. yield from
toawait
in Python 3.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncpg | |
import ujson | |
class Transaction: | |
def __init__(self, pool): | |
self.pool = pool | |
async def __aenter__(self): | |
self.acquire_context = self.pool.acquire() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from starlette.applications import Starlette | |
from starlette.responses import StreamingResponse | |
from starlette.requests import Request | |
from starlette.routing import Route | |
from pathlib import Path | |
from typing import IO, Generator | |
""" | |
Stream a file, in this case an mp4 video, supporting range-requests using starlette |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delete(key, dict_obj): | |
"""Deletes element from dict_obj accessing by complex key | |
Args: | |
key (str): Complex key to your value (separated by dots) | |
dict_obj (dict): Your dictionary | |
Raises: | |
KeyError: if object doesn't contain key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from sqlalchemy import Column, Integer, DateTime, ForeignKey | |
from sqlalchemy.orm import relationship | |
from sqlalchemy.ext.declarative import declared_attr | |
from flask_security import current_user | |
class AuditMixin(object): | |
created_at = Column(DateTime, default=datetime.now) | |
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""This program is exactly the same as that of | |
https://gist.github.com/zzzeek/33943060f7a08cf9e82bf8df1f0f75de , | |
with the exception that the add_and_select_data function is written in | |
synchronous style. | |
UPDATED!! now includes refinements by @snaury and @Caselit . SIMPLER | |
AND FASTER!! | |
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 5 columns, instead of 3 in line 9.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Annotator,Description,Version,Annotator Approach,Annotator Model | |
Tokenizer*,Identifies tokens with tokenization open standards,Opensource,-,+ | |
Normalizer*,Removes all dirty characters from text,Opensource,-,+ | |
Stemmer*,Returns hard'-stems out of words with the objective of retrieving the meaningful part of the word,Opensource,+,- | |
Lemmatizer*,Retrieves lemmas out of words with the objective of returning a base dictionary word,Opensource,-,+ | |
RegexMatcher*,Uses a reference file to match a set of regular expressions and put them inside a provided key.,Opensource,+,+ | |
TextMatcher*,Annotator to match entire phrases (by token) provided in a file against a Document,Opensource,+,+ | |
Chunker*,Matches a pattern of part'-of'-speech tags in order to return meaningful phrases from document,Opensource,+,- | |
DateMatcher*,Reads from different forms of date and time expressions and converts them to a provided date format,Opensource,+,- | |
SentenceDetector*,Finds sentence bounds in raw text. Applies rules from Pragmatic Segmenter,Opensou |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class States(Enum): | |
# each Value have priority. Need when getting random event we know its more priority then last or not. | |
# y = YealinkStates.ANSWER_IN_CALL | |
# y = YealinkStates('ANSWER_NEW_IN_CALL') | |
# y.name -> 'ANSWER_IN_CALL' | |
# str(y) -> 'ANSWER_NEW_IN_CALL' | |
# y.priority -> 3 | |
# y.title -> 'ANSWER_NEW_IN_CALL' | |
INCOMING_CALL = (1, 'INCOMING_CALL') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache, wraps | |
from datetime import datetime, timedelta | |
def timed_lru_cache(seconds: int, maxsize: int = 128): | |
def wrapper_cache(func): | |
func = lru_cache(maxsize=maxsize)(func) | |
func.lifetime = timedelta(seconds=seconds) | |
func.expiration = datetime.utcnow() + func.lifetime | |
@wraps(func) |