F*** bug
This commit is contained in:
15
bug.py
Normal file
15
bug.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class A:
|
||||||
|
def __init__(self, arg=None):
|
||||||
|
if arg is None:
|
||||||
|
self.arg = {}
|
||||||
|
|
||||||
|
def set(self):
|
||||||
|
self.arg['something'] = 'something'
|
||||||
|
|
||||||
|
|
||||||
|
a1 = A()
|
||||||
|
a1.set()
|
||||||
|
a2 = A()
|
||||||
|
|
||||||
|
print(a2.arg)
|
||||||
|
# output is {'something': 'something'}
|
||||||
9
mswp.py
9
mswp.py
@@ -1,11 +1,12 @@
|
|||||||
class Datapack:
|
class Datapack:
|
||||||
def __init__(self, method='post', app='all', version='msw/1.0', head=None, body=b'', check_head=True):
|
def __init__(self, method='post', app='all', version='msw/1.0', head=None, body=b'', check_head=True):
|
||||||
if head is None:
|
if head is None:
|
||||||
self.head = {}
|
head = {}
|
||||||
|
self.head = head
|
||||||
self.method = method
|
self.method = method
|
||||||
self.app = app
|
self.app = app
|
||||||
self.version = version
|
self.version = version
|
||||||
if not head and check_head:
|
if not self.head and check_head:
|
||||||
self.head = {'nohead': "true"}
|
self.head = {'nohead': "true"}
|
||||||
else:
|
else:
|
||||||
self.head = head
|
self.head = head
|
||||||
@@ -21,7 +22,6 @@ class Datapack:
|
|||||||
self.encode_data = first_line + b'\n' + heads + b'\n' + self.body
|
self.encode_data = first_line + b'\n' + heads + b'\n' + self.body
|
||||||
|
|
||||||
def decode(self, only_head=False):
|
def decode(self, only_head=False):
|
||||||
self.head = {}
|
|
||||||
index = self.encode_data.index(b'\n\n')
|
index = self.encode_data.index(b'\n\n')
|
||||||
upper = self.encode_data[:index]
|
upper = self.encode_data[:index]
|
||||||
if not only_head:
|
if not only_head:
|
||||||
@@ -37,3 +37,6 @@ class Datapack:
|
|||||||
self.head[i] = ii
|
self.head[i] = ii
|
||||||
if only_head:
|
if only_head:
|
||||||
return self.encode_data[index+2:]
|
return self.encode_data[index+2:]
|
||||||
|
|
||||||
|
|
||||||
|
dp = Datapack()
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class Netrecv:
|
|||||||
print('Null data')
|
print('Null data')
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Decode error')
|
print('Decode error %s: %s' % (type(e), str(e)))
|
||||||
break
|
break
|
||||||
# try unpack #
|
# try unpack #
|
||||||
|
|
||||||
@@ -138,6 +138,13 @@ class Netrecv:
|
|||||||
aleady_write_down += still_need
|
aleady_write_down += still_need
|
||||||
data = new_data[still_need:]
|
data = new_data[still_need:]
|
||||||
|
|
||||||
|
else:
|
||||||
|
file = open(dp.head['filename'], 'wb')
|
||||||
|
file.write(data[:length])
|
||||||
|
data = data[length:]
|
||||||
|
|
||||||
|
file.close()
|
||||||
|
|
||||||
else: # dp.method is not 'file'
|
else: # dp.method is not 'file'
|
||||||
length = int(dp.head['length'])
|
length = int(dp.head['length'])
|
||||||
data_length = len(data)
|
data_length = len(data)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
data = '''post log msw/1.0
|
data = '''file log msw/1.0
|
||||||
from: network
|
from: network
|
||||||
flag: abcdefgh
|
flag: abcdefgh
|
||||||
filename: download.txt
|
filename: download.txt
|
||||||
|
|||||||
Reference in New Issue
Block a user