-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some generic function were moved to core
- Loading branch information
Showing
5 changed files
with
70 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
import time | ||
import defusedxml.ElementTree as ET | ||
from random import randint | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def generate_tempfile_name(): | ||
t = int(round(time.time() * 1000)) | ||
r = randint(10000, 99999) | ||
fn = '/tmp/upload_' + str(t) + '_' + str(r) + '.xml' | ||
return fn | ||
|
||
|
||
def handle_uploaded_file(filedata): | ||
tempfilename = generate_tempfile_name() | ||
with open(tempfilename, 'wb+') as destination: | ||
for chunk in filedata.chunks(): | ||
destination.write(chunk) | ||
return tempfilename | ||
|
||
|
||
def validate_xml(tempfilename, root_tag): | ||
tree = None | ||
exit_code = 0 | ||
try: | ||
tree = ET.parse(tempfilename) | ||
except Exception as e: | ||
exit_code = 1 | ||
log.info('Xml parsing error: ' + str(e)) | ||
pass | ||
else: | ||
root = tree.getroot() | ||
if root.tag != root_tag: | ||
log.info('Validation failed. Xml\'s root node is "' + root_tag + '" and not "' + root.tag + '".') | ||
exit_code = 1 | ||
return exit_code, tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters