Skip to content

Commit

Permalink
PEP8 && 优化效率
Browse files Browse the repository at this point in the history
  • Loading branch information
boy-hack committed Dec 26, 2018
1 parent c1b6046 commit 0a54586
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
32 changes: 15 additions & 17 deletions HackRequests/HackRequests.py
Expand Up @@ -4,17 +4,17 @@
# @Mail : w8ay@qq.com
# @File : hackRequests.py

from http import client
from urllib import parse
from threading import Lock
import threading
import ssl
import copy
import gzip
import zlib
import time
import queue
import socket
import ssl
import threading
import time
import zlib
from http import client
from threading import Lock
from urllib import parse


class Compatibleheader(str):
Expand Down Expand Up @@ -258,7 +258,7 @@ def http(self, url, **kwargs):
try:
conn.request(method, path, post, tmp_headers)
rep = conn.getresponse()
body = rep.read()
# body = rep.read()
except socket.timeout:
raise HackError("socket connect timeout")
except socket.gaierror:
Expand All @@ -284,14 +284,14 @@ def http(self, url, **kwargs):
if not redirect:
redirect = url
log["url"] = redirect
return response(rep, redirect, body, log, cookie)
return response(rep, redirect, log, cookie)


class response(object):

def __init__(self, rep, redirect, body, log, oldcookie):
def __init__(self, rep, redirect, log, oldcookie):
self.rep = rep
self.body = body
# self.body = body
self.status_code = self.rep.status # response code
self.url = redirect

Expand All @@ -318,8 +318,6 @@ def __init__(self, rep, redirect, body, log, oldcookie):
self.cookies = {}
self.headers = _header_dict
self.header = self.rep.msg # response header
self.log = {} # response log
self.charset = "" # response encoding
self.log = log
charset = self.rep.msg.get('content-type', 'utf-8')
try:
Expand All @@ -329,7 +327,7 @@ def __init__(self, rep, redirect, body, log, oldcookie):

def content(self):
encode = self.rep.msg.get('content-encoding', None)
body = self.body
body = self.rep.read()
if encode == 'gzip':
body = gzip.decompress(body)
elif encode == 'deflate':
Expand Down Expand Up @@ -455,9 +453,9 @@ def scan(self):


def http(url, **kwargs):
timeout = kwargs.get("timeout", 10)
con = httpcon(timeout=timeout)
hack = hackRequests(con)
# timeout = kwargs.get("timeout", 10)
# con = httpcon(timeout=timeout)
hack = hackRequests()
return hack.http(url, **kwargs)


Expand Down
9 changes: 5 additions & 4 deletions demo/demo.py
@@ -1,8 +1,9 @@
import HackRequests as hack
import hashlib

u = "https://bbs.125.la/"
u = "http://x.hacking8.com/"
cookie1 = "user=useraa; "
hh = hack.http(u, cookie=cookie1, post="1")
print(hh.text())
print(hh.log["request"])
hh = hack.http(u, cookie=cookie1, location=False)
# print(hh.text())
print(hh.status_code)
print(hh.log["request"], hh.log["response"])

0 comments on commit 0a54586

Please sign in to comment.