mirror of https://gitlab.com/bashrc2/epicyon
More debug
parent
f1ca34bac8
commit
1f68f22925
|
@ -481,11 +481,13 @@ def saveMediaInFormPOST(mediaBytes,baseDir: str, \
|
|||
fd.close()
|
||||
return filename,attachmentMediaType
|
||||
|
||||
def extractTextFieldsInPOST(postBytes,boundary) -> {}:
|
||||
def extractTextFieldsInPOST(postBytes,boundary,debug: bool) -> {}:
|
||||
"""Returns a dictionary containing the text fields of a http form POST
|
||||
The boundary argument comes from the http header
|
||||
"""
|
||||
msg = email.parser.BytesParser().parsebytes(postBytes)
|
||||
if debug:
|
||||
print('DEBUG: POST arriving '+msg.get_payload(decode=True).decode('utf-8'))
|
||||
messageFields=msg.get_payload(decode=True).decode('utf-8').split(boundary)
|
||||
fields={}
|
||||
# examine each section of the POST, separated by the boundary
|
||||
|
|
19
daemon.py
19
daemon.py
|
@ -2652,12 +2652,29 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# in Python 3.8/3.10
|
||||
# Instead we use the multipart mime parser from the email module
|
||||
postBytes=self.rfile.read(length)
|
||||
if self.server.debug:
|
||||
print('DEBUG: extracting media from POST')
|
||||
mediaBytes,postBytes=extractMediaInFormPOST(postBytes,boundary,'attachpic')
|
||||
if self.server.debug:
|
||||
if mediaBytes:
|
||||
print('DEBUG: media was found. '+str(len(mediaBytes))+' bytes')
|
||||
else:
|
||||
print('DEBUG: no media was found in POST')
|
||||
filename,attachmentMediaType= \
|
||||
saveMediaInFormPOST(mediaBytes,self.server.baseDir, \
|
||||
nickname,self.server.domain, \
|
||||
self.server.debug,None)
|
||||
fields=extractTextFieldsInPOST(postBytes,boundary)
|
||||
if self.server.debug:
|
||||
if filename:
|
||||
print('DEBUG: POST media filename is '+filename)
|
||||
else:
|
||||
print('DEBUG: no media filename in POST')
|
||||
fields=extractTextFieldsInPOST(postBytes,boundary,self.server.debug)
|
||||
if self.server.debug:
|
||||
if fields:
|
||||
print('DEBUG: text field extracted from POST '+str(fields))
|
||||
else:
|
||||
print('WARN: no text fields could be extracted from POST')
|
||||
|
||||
# process the received text fields from the POST
|
||||
if not fields.get('message') and not fields.get('imageDescription'):
|
||||
|
|
Loading…
Reference in New Issue