예제 #1
0
파일: HttpUtils.py 프로젝트: zhzhwcn/libMA
def connect(url, params={}, opener=None):
    if opener == None:
        opener = __dafault_opener__
    url = crypt.getCryptUrl(url)
    headers = {
        "User-Agent": USER_AGENT,
        "Accept-Encoding": "gzip, deflate",
    }
    params = _cryptParams(params)
    request = urllib2.Request(url, urllib.urlencode(params), headers)
    response = opener.open(request)
    responsion = response.read()
    try:
        f = StringIO(responsion)
        gzipper = gzip.GzipFile(fileobj=f)
        data = gzipper.read()
    except:
        data = responsion
    try:
        rtn = crypt.decode(data)
    except:
        lines = filter(lambda s: len(s) > 0, data.split("\r\n"))
        rtn = None
        for line in lines:
            if len(d) % 16 == 0:
                try:
                    rtn = crypt.decode(d)
                    break
                except:
                    pass
    if rtn != None:
        rtn = XML2Object(rtn)
    return rtn
예제 #2
0
파일: HttpUtils.py 프로젝트: lfk0/libMA
def connect(url, params = {}, opener = None):
    if opener == None:
        opener = __dafault_opener__
    url = crypt.getCryptUrl(url)
    headers = {
        "User-Agent":
            USER_AGENT,
        "Accept-Encoding":
            "gzip, deflate",
    }
    params = _cryptParams(params)
    request = urllib2.Request(url, urllib.urlencode(params), headers)
    response = opener.open(request)
    responsion = response.read()
    try:
        f = StringIO(responsion)
        gzipper = gzip.GzipFile(fileobj = f)
        data = gzipper.read()
    except:
        data = responsion
    try:
        rtn = crypt.decode(data)
    except:
        lines = filter(lambda s: len(s) > 0, data.split("\r\n"))
        rtn = None
        for line in lines:
            if len(d) % 16 == 0:
                try:
                    rtn = crypt.decode(d)
                    break
                except:
                    pass
    if rtn != None:
        rtn = XML2Object(rtn)
    return rtn
예제 #3
0
파일: HttpUtils.py 프로젝트: kimbaol/libMA
def connect(url, params={}, opener=None):
    if opener == None:
        opener = __dafault_opener__
    url = crypt.getCryptUrl(url)
    headers = {
        "User-Agent":
            USER_AGENT,
        "Accept-Encoding":
            "gzip, deflate",
    }
    params = _cryptParams(params)
    request = urllib2.Request(url, urllib.urlencode(params), headers)
    cookiejar = [row for row in opener.handlers if isinstance(row, urllib2.HTTPCookieProcessor)][0].cookiejar
    if not cookiejar and os.path.isfile(cookiejar.filename):
        cookiejar.load(None, True, True)
    response = opener.open(request)
    cookiejar.save(None, True, True)
    responsion = response.read()
    try:
        f = StringIO(responsion)
        gzipper = gzip.GzipFile(fileobj=f)
        data = gzipper.read()
    except:
        data = responsion
    try:
        rtn = crypt.decode(data)
    except:
        lines = filter(lambda s: len(s) > 0, data.split("\r\n"))
        rtn = None
        for line in lines:
            if len(d) % 16 == 0:
                try:
                    rtn = crypt.decode(d)
                    break
                except:
                    pass
    return rtn