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 time | |
import errno | |
import threading | |
import weakref | |
__all__ = ["lock_file"] | |
try: | |
import fcntl |
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/python3 | |
import requests | |
import re | |
from requests.auth import HTTPBasicAuth | |
class ProxyRequests: | |
def __init__(self, url): | |
self.sockets = [] | |
self.url = url |
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 python | |
# -*- coding: utf-8 -*- | |
import Queue | |
import urlparse | |
import httplib | |
import ssl | |
import zlib | |
import gzip | |
import StringIO | |
import re |
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 | |
# coding:utf-8 | |
from peewee import SQL | |
from peewee import QueryCompiler | |
from models import Blog | |
compiler = QueryCompiler('"', '?', {}, {}) |
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 longest_substring(s): | |
res, start, n = 0, 0, 0, len(s) | |
maps = {} | |
for i in range(n): | |
start = max(start, maps.get(s[i], -1)+1) | |
res = max(res, i-start+1) | |
maps[s[i]] = i | |
return start, start+res-1, res |
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
# -*- coding: utf-8 -*- | |
def first(iterable, default=None, key=None): | |
""" | |
Return first element of `iterable` that evaluates true, else return None | |
(or an optional default value). | |
>>> first([0, False, None, [], (), 42]) | |
42 |
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
# -*- coding: utf-8 -*- | |
# flake8: noqa | |
""" | |
werkzeug.local | |
~~~~~~~~~~~~~~ | |
This module implements context-local objects. | |
:copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details. | |
:license: BSD, see LICENSE for more details. |
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
# -*- coding: utf-8 -*- | |
import logging | |
def is_python_version(*versions): | |
for version in versions: | |
if (sys.version_info[0] == version[0] and | |
sys.version_info >= version): | |
return True |
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 | |
PY2 = sys.version_info[0] == 2 | |
if not PY2: | |
# Python 3.x and up | |
text_type = str | |
string_types = (str,) | |
def as_text(v): | |
if v is None: |
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 cached_property(object): | |
""" | |
Decorator that converts a method with a single self argument into a | |
property cached on the instance. | |
Optional ``name`` argument allows you to make cached properties of other | |
methods. (e.g. url = cached_property(get_absolute_url, name='url') ) | |
""" | |
def __init__(self, func, name=None): | |
self.func = func |