Perfect at 07012250.
This commit is contained in:
parent
536604b148
commit
caf14c02a3
|
@ -0,0 +1,111 @@
|
|||
import io, base64, hashlib
|
||||
from urllib import parse
|
||||
|
||||
|
||||
def base64_encode(input, output=None):
|
||||
"""
|
||||
:param output:
|
||||
:param input: File pointer or str or bytes.
|
||||
:return:
|
||||
"""
|
||||
if isinstance(input, bytes):
|
||||
return base64.b64encode(input)
|
||||
elif isinstance(input, str):
|
||||
return base64.b64encode(bytes(input, encoding='utf-8')).decode()
|
||||
else:
|
||||
return base64.encode(input, output)
|
||||
|
||||
|
||||
def base64_decode(input, output=None):
|
||||
"""
|
||||
:param output:
|
||||
:param input: File pointer or str or bytes.
|
||||
:return:
|
||||
"""
|
||||
if isinstance(input, bytes):
|
||||
return base64.b64decode(input)
|
||||
elif isinstance(input, str):
|
||||
return base64.b64decode(bytes(input, encoding='utf-8')).decode()
|
||||
else:
|
||||
return base64.decode(input, output)
|
||||
|
||||
|
||||
def hash_sum(method, input):
|
||||
"""
|
||||
:param method:
|
||||
:param input: File pointer or str or bytes.
|
||||
:return:
|
||||
"""
|
||||
hashChoose = eval('hashlib.' + method)
|
||||
if isinstance(input, bytes):
|
||||
return hashChoose(input).hexdigest()
|
||||
elif isinstance(input, str):
|
||||
return hashChoose(bytes(input, encoding='utf-8')).hexdigest()
|
||||
else:
|
||||
hashObject = hashChoose()
|
||||
bufferSize = io.DEFAULT_BUFFER_SIZE
|
||||
while True:
|
||||
data = input.read(bufferSize)
|
||||
if data:
|
||||
hashObject.update(data)
|
||||
else:
|
||||
break
|
||||
return hashObject.hexdigest()
|
||||
|
||||
|
||||
def md5(input):
|
||||
from sys import _getframe as getframe
|
||||
return hash_sum(method=getframe().f_code.co_name, input=input)
|
||||
|
||||
|
||||
def sha1(input):
|
||||
from sys import _getframe as getframe
|
||||
return hash_sum(method=getframe().f_code.co_name, input=input)
|
||||
|
||||
|
||||
def sha224(input):
|
||||
from sys import _getframe as getframe
|
||||
return hash_sum(method=getframe().f_code.co_name, input=input)
|
||||
|
||||
|
||||
def sha256(input):
|
||||
from sys import _getframe as getframe
|
||||
return hash_sum(method=getframe().f_code.co_name, input=input)
|
||||
|
||||
|
||||
def sha384(input):
|
||||
from sys import _getframe as getframe
|
||||
return hash_sum(method=getframe().f_code.co_name, input=input)
|
||||
|
||||
|
||||
def sha512(input):
|
||||
from sys import _getframe as getframe
|
||||
return hash_sum(method=getframe().f_code.co_name, input=input)
|
||||
|
||||
|
||||
def urlencode(string):
|
||||
return parse.quote(str(string))
|
||||
|
||||
|
||||
def urldecode(string):
|
||||
return parse.unquote(string)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Example.
|
||||
# print(base64_encode(open('./example', 'rb'), open('./example.base64', 'wb')))
|
||||
# print(base64_decode(open('./example.base64', 'rb'), open('./example.base64.decode', 'wb')))
|
||||
print(base64_encode('root'))
|
||||
print(base64_encode(bytes('root', encoding='utf-8')))
|
||||
print(base64_decode('cm9vdA=='))
|
||||
print(base64_decode(bytes('cm9vdA==', encoding='utf-8')))
|
||||
print(sha1('root'))
|
||||
print(sha224('root'))
|
||||
print(sha256('root'))
|
||||
print(sha384('root'))
|
||||
print(sha512('root'))
|
||||
# print(md5('root'))
|
||||
# print(md5(bytes('root', encoding='utf-8')))
|
||||
# print(md5(open('./example', 'rb')))
|
||||
print(urlencode('百度一下'))
|
||||
print(urldecode('%E7%99%BE%E5%BA%A6%E4%B8%80%E4%B8%8B'))
|
|
@ -0,0 +1,15 @@
|
|||
import time
|
||||
|
||||
|
||||
def time_format(fmt='%Y-%m-%d %H:%M:%S', ts=None):
|
||||
return time.strftime(fmt, time.localtime(ts))
|
||||
|
||||
|
||||
def time_make(datetime_format='', dt=''):
|
||||
return time.mktime(time.strptime(dt, datetime_format))
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Example.
|
||||
print(time_format(fmt='%Y年%m月%d日 %H:%M:%S'))
|
||||
print(time_format(fmt='%Y年%m月%d日 %H:%M:%S', ts=1640012345))
|
||||
print(time_make('%Y-%m-%d %H:%M:%S', '2021-12-20 22:59:05'))
|
|
@ -0,0 +1,18 @@
|
|||
def countinfo(func):
|
||||
def funcNew(*args, **kwargs):
|
||||
import os, time, psutil
|
||||
_count_fname = func.__name__
|
||||
_count_pid = os.getpid()
|
||||
_count_ps = psutil.Process(_count_pid)
|
||||
_count_smeno = _count_ps.memory_full_info().uss/1024
|
||||
print('*' * 64)
|
||||
print("\033[1;32m" + 'Running...' + "\033[0m")
|
||||
print("\033[0;31m" + 'Function:' + '<' + _count_fname + '>' + '\tPid:' + str(_count_pid) + "\033[0m", end='\t')
|
||||
_count_stime = time.time()
|
||||
_count_ret = func(*args, **kwargs)
|
||||
_count_etime = time.time()
|
||||
_count_emeno = _count_ps.memory_full_info().uss / 1024
|
||||
print("\033[0;31m" + 'Run(unit:ms):' + str(int((_count_etime - _count_stime)*1000)) + '\t' + 'Men(unit:KB):' + str(int(_count_emeno - _count_smeno)) + "\033[0m")
|
||||
print('*' * 64)
|
||||
return _count_ret
|
||||
return funcNew
|
66
main4.py
66
main4.py
|
@ -1,2 +1,64 @@
|
|||
a = 4 and 6
|
||||
print(a)
|
||||
import requests, logging, time
|
||||
|
||||
def test():
|
||||
url = 'http://more-md.fanscloud.net/iplookup'
|
||||
url_upload = 'https://more-me.fanscloud.net/typoraUpload'
|
||||
|
||||
# logging.basicConfig()
|
||||
# logging.getLogger().setLevel(logging.DEBUG)
|
||||
# requests_log = logging.getLogger("requests.packages.urllib3")
|
||||
#
|
||||
# requests_log.setLevel(logging.DEBUG)
|
||||
#
|
||||
# requests_log.propagate = True
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
req = requests.request(
|
||||
method='POST',
|
||||
url=url,
|
||||
params={"ip": '119.29.29.29'},
|
||||
data='123456',
|
||||
headers={"Version": '1.0.0', "Accept-Encoding": 'gzip'},
|
||||
cookies={"user": 'zhaoyafan'},
|
||||
files={},
|
||||
auth=None,
|
||||
timeout=10,
|
||||
allow_redirects=False,
|
||||
proxies={"http": '127.0.0.1:8888', "https": '127.0.0.1:8888'},
|
||||
verify=None,
|
||||
cert=None,
|
||||
json=None
|
||||
)
|
||||
# req = requests.post(url=url, params={"ip": '119.29.29.29'}, proxies={"http": '127.0.0.1:8888', "https": '127.0.0.1:8888'})
|
||||
# proxies={"http": '127.0.0.1:8888', "https": '127.0.0.1:8888'},
|
||||
|
||||
|
||||
|
||||
# print(req.request.method + ' ' + req.request.url + ' ' + 'HTTP/1.1' + '\r\n')
|
||||
print(req.text)
|
||||
print(req.headers)
|
||||
logs = logging.getLogger()
|
||||
|
||||
logs.setLevel(logging.DEBUG)
|
||||
|
||||
path = './' + time.strftime('%Y-%m-%d-%H-%M-%S') + '.log'
|
||||
write_file = logging.FileHandler(path, 'a+', encoding='utf-8')
|
||||
|
||||
write_file.setLevel(logging.DEBUG)
|
||||
|
||||
set_logs = logging.Formatter('%(asctime)s - %(filename)s - %(funcName)s - %(levelname)s - %(message)s')
|
||||
|
||||
write_file.setFormatter(set_logs)
|
||||
|
||||
pycharm_text = logging.StreamHandler()
|
||||
|
||||
pycharm_text.setFormatter(set_logs)
|
||||
|
||||
logs.addHandler(write_file)
|
||||
|
||||
logs.addHandler(pycharm_text)
|
||||
test()
|
Loading…
Reference in New Issue