This file contains 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 python | |
from gevent import monkey | |
monkey.patch_all() | |
import sys | |
import redis | |
import urllib2 | |
import traceback | |
from cgi import escape | |
# -- gsdproxy |
This file contains 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
""" | |
State module | |
============ | |
The state module for logical union of several states. | |
Available Functions | |
------------------- |
This file contains 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
""" | |
State module | |
============ | |
The state module for logical union of several states. | |
Available Functions | |
------------------- |
This file contains 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 Constants(type): | |
class _ConstantsBase(dict): | |
def __getattribute__(self, name): | |
try: | |
return self[name] | |
except LookupError: | |
raise AttributeError(name) | |
This file contains 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 skip_error(object): | |
def __init__(self, exception, fn=None, default=None): | |
self.exception = exception | |
self.fn = fn | |
self.default = default | |
def __enter__(self): | |
return self.default |
This file contains 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 itertools import combinations | |
def combinations_dict(data): | |
""" | |
Generates all possible combinations of values for dictionary. | |
At the entrance you can pass either dictionary or list of tuples. | |
Examples:: |
This file contains 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 Namespace: | |
__slots__ = '_Namespace__names' | |
def __init__(self, **items): | |
self.__names = dict(**items) | |
def __setattr__(self, key, value): | |
if key in self.__slots__: | |
super().__setattr__(key, value) |
This file contains 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
__obj = object() | |
# uncomment for fix: | |
# _Class__obj = __obj | |
def func(): | |
print('func:', __obj) | |
class Class: |
This file contains 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 asyncio | |
from functools import partial | |
async def process(d): | |
print('process', d) | |
async def amain(loop): | |
data = range(2) |
This file contains 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 ctypes | |
import threading | |
import time | |
# inspired by https://github.com/mosquito/crew/blob/master/crew/worker/thread.py | |
def kill_thread( | |
thread: threading.Thread, exception: BaseException=KeyboardInterrupt | |
) -> None: | |
if not thread.isAlive(): |
OlderNewer