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 requests.adapters import HTTPAdapter, Retry | |
| from requests import Session | |
| retries = Retry( | |
| total=5, backoff_factor=1, status_forcelist=[502, 503, 504] | |
| ) | |
| session = Session() # reuse tcp connection | |
| session.mount("http://", HTTPAdapter(max_retries=retries)) | |
| session.mount("https://", HTTPAdapter(max_retries=retries)) |
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 logging | |
| import time | |
| import tornado.gen | |
| import tornado.ioloop | |
| import tornado.queues | |
| import tornado.web | |
| class Client(): |
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 iterate_all(iterable, returned="key"): | |
| """Returns an iterator that returns all keys or values | |
| of a (nested) iterable. | |
| Arguments: | |
| - iterable: <list> or <dictionary> | |
| - returned: <string> "key" or "value" | |
| Returns: |
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/python | |
| import socket, select | |
| host = '121.40.77.208' | |
| port = 10000 | |
| socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| socket.connect((host, port)) | |
| inout = [socket] |
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 json, datetime | |
| class RoundTripEncoder(json.JSONEncoder): | |
| DATE_FORMAT = "%Y-%m-%d" | |
| TIME_FORMAT = "%H:%M:%S" | |
| def default(self, obj): | |
| if isinstance(obj, datetime.datetime): | |
| return { | |
| "_type": "datetime", | |
| "value": obj.strftime("%s %s" % ( |
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 __future__ import annotations | |
| from typing import Any, Dict, Iterable, Mapping, MutableMapping, MutableSequence, Union | |
| class AttrDict: | |
| """ | |
| A class with both dictionary and attribute style access to it's data member. | |
| It can be used in `RestrictedPython <http://restrictedpython.readthedocs.io/>`_ |