forked from indymedia/epicyon
More debug
parent
f1ca34bac8
commit
1f68f22925
|
@ -481,11 +481,13 @@ def saveMediaInFormPOST(mediaBytes,baseDir: str, \
|
||||||
fd.close()
|
fd.close()
|
||||||
return filename,attachmentMediaType
|
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
|
"""Returns a dictionary containing the text fields of a http form POST
|
||||||
The boundary argument comes from the http header
|
The boundary argument comes from the http header
|
||||||
"""
|
"""
|
||||||
msg = email.parser.BytesParser().parsebytes(postBytes)
|
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)
|
messageFields=msg.get_payload(decode=True).decode('utf-8').split(boundary)
|
||||||
fields={}
|
fields={}
|
||||||
# examine each section of the POST, separated by the boundary
|
# 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
|
# in Python 3.8/3.10
|
||||||
# Instead we use the multipart mime parser from the email module
|
# Instead we use the multipart mime parser from the email module
|
||||||
postBytes=self.rfile.read(length)
|
postBytes=self.rfile.read(length)
|
||||||
|
if self.server.debug:
|
||||||
|
print('DEBUG: extracting media from POST')
|
||||||
mediaBytes,postBytes=extractMediaInFormPOST(postBytes,boundary,'attachpic')
|
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= \
|
filename,attachmentMediaType= \
|
||||||
saveMediaInFormPOST(mediaBytes,self.server.baseDir, \
|
saveMediaInFormPOST(mediaBytes,self.server.baseDir, \
|
||||||
nickname,self.server.domain, \
|
nickname,self.server.domain, \
|
||||||
self.server.debug,None)
|
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
|
# process the received text fields from the POST
|
||||||
if not fields.get('message') and not fields.get('imageDescription'):
|
if not fields.get('message') and not fields.get('imageDescription'):
|
||||||
|
|
Loading…
Reference in New Issue