⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxy4_base.py

📁 一个java写的proxy的例子
💻 PY
字号:
# Since in each module we do from proxy4_base import *, we can# import stuff here that's used everywherefrom string import *from cStringIO import StringIOimport socket, select, time, rfc822import asyncoreimport os, sys, reTIMERS = [] # list of (time, function)# TODO: better name/implementation for this functiondef stripsite(url):    import urlparse    url = urlparse.urlparse(url)    return url[1], urlparse.urlunparse( (0,0,url[2],url[3],url[4],url[5]) )# Helper function for display -- show something using ANSI colorsdef color(col, text, bgcol=None):    if (col is not None) and (os.environ.get('TERM', '') in ('xterm', 'vt100')):        if bgcol is not None:            col = '%s;4%s' % (col, bgcol)        return '\033[3%sm%s\033[0m' % (col, text)    else:        return text# Helper function for displaying a message line with fieldsdef message(labelcolor, label, field1, field2, *args):    "label can span field1 and 2 if the fields are empty"    output = []    label = label+':'    labelwidth = 6    if field1 is None:        labelwidth = 11        if field2 is None:            labelwidth = 13    output.append(color(labelcolor, ljust(label, labelwidth)))    if field1 is not None: output.append(rjust(str(field1), 5))    output.append(' ')    if field1 is not None or field2 is not None: output.append(ljust(str(field2), 2))    for a in args:        output.append(' ')        output.append(str(a))    output = join(output, '')    print output    class ProxyConfig:    local_sockets_only = 0    def make_timer(delay, callback):    "After DELAY seconds, run the CALLBACK function"    TIMERS.append( (time.time() + delay, callback) )    TIMERS.sort()def run_timers():    "Run all timers ready to be run, and return seconds to the next timer"    # Note that we will run timers that are scheduled to be run within    # 10 ms.  This is because the select() statement doesn't have    # infinite precision and may end up returning slightly earlier.    # We're willing to run the event a few millisecond earlier.    while TIMERS and TIMERS[0][0] <= time.time() + 0.01:        # This timeout handler should be called        callback = TIMERS[0][1]        del TIMERS[0]        callback()    if TIMERS: return TIMERS[0][0] - time.time()     else:      return 60                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -