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
| #!/usr/bin/env python3 | |
| import random as _rng | |
| class ShuffleQueue: | |
| def __init__(self, items, rng=None): | |
| self._idx = 0 | |
| self._items = items | |
| self._rng = rng or _rng |
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 sys | |
| import warnings | |
| import inspect | |
| from pluggy import HookimplMarker, HookspecMarker, PluginManager, _HookCaller, normalize_hookimpl_opts, HookImpl | |
| class MetadataHookspecMarker(HookspecMarker): | |
| """ | |
| Allows storing arbitrary metadata on the hookspec options | |
| instead of what Pluggy sets by default. | |
| """ |
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 abc import ABCMeta, abstractmethod | |
| ABC = ABCMeta('ABC', (object,), {}) | |
| class ConversionStrategy(ABC): | |
| @abstractmethod | |
| def convert(self, a): | |
| raise NotImplementedError | |
| class IntegerConversionStrategy(ConversionStrategy): |
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 | |
| SUNDAY = 6 | |
| class UncleVernonMiddleware(object): | |
| def __init__(self, app): | |
| self.app = app | |
| def __call__(self, environ, start_response): | |
| if environ['REQUEST_METHOD'].lower() == 'post' and datetime.now().weekday() == SUNDAY: |
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 Thing: | |
| def r(self): | |
| pass | |
| class HasWhatever(metaclass=ImplicitMeta, companion=Thing): | |
| whatever = lambda s: print(s, 1) | |
| @property | |
| def nine(self): | |
| return 'nine' |
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
| [tox] | |
| envlist = cov-init,py27,py34,py35,py36,cov-report | |
| [testenv] | |
| usedevelop = True | |
| setenv = | |
| COVERAGE_FILE = .coverage.{envname} | |
| PYTHONDONTWRITEBYTECODE = pls | |
| commands = | |
| py.test --cov={toxinidir}/flask_sleepy --cov-report term-missing |
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 copy import deepcopy | |
| class Builder(object): | |
| def __init__(self, target, *args, **kwargs): | |
| self._target = target | |
| self._kwargs = kwargs | |
| self._args = list(args) | |
| def having(self, *args, **kwargs): |
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 decimal | |
| from functools import total_ordering | |
| from numbers import Real | |
| class Context(object): | |
| def __init__(self, **kwargs): | |
| self.context = decimal.Context(**kwargs) | |
| def __enter__(self): | |
| with decimal.localcontext(self.context) as c: |
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 abc import ABC, ABCMeta, abstractmethod | |
| from collections import namedtuple | |
| from itertools import count | |
| PayloadFactory = namedtuple('PayloadFactory', [ | |
| 'good', 'created', 'queued', 'unchanged', 'requires_auth', | |
| 'permission_denied', 'not_found', 'invalid', 'error' | |
| ]) | |
| """ |
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 UserNotFound(Exception): | |
| @classmethod | |
| def by_username(cls, username): | |
| return cls("No user found with username: {0}".format(username)) | |
| def find_user(username): | |
| user = User.query.filter_by(username==username).first() | |
| if not user: | |
| raise UserNotFound.by_username(username) | |
| return user |
NewerOlder