Skip to content

Commit 6264d68

Browse files
committed
Improve the doc and decode base 64
1 parent e48b71d commit 6264d68

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ __pycache__
44
.DS_Store
55
github_settings.py
66
*.pyc
7+
.venv

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ Then checkout this repository:
2121
cd ...wherever...
2222
git clone https://github.com/csev/dj4e-samples.git
2323
cd dj4e-samples
24-
virtualenv .venv
24+
python3.11 -m venv .venv
2525
source .venv/bin/activate
2626
python --version
2727
pip install -r requirements42.txt
28+
python -m django --version
2829

2930
python manage.py migrate
3031
python manage.py createsuperuser --username dj4e-samples
3132
# python manage.py changepassword dj4e-samples
3233
# dj4e_nn_!
3334

35+
...
36+
deactivate
37+
3438
Running Locally on the Mac
3539
--------------------------
3640

zip/views.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,19 @@ def post(self, request):
5656
xmlstr = data.decode()
5757
try:
5858
dom = minidom.parseString(data)
59-
xmlstr = dom.toprettyxml(encoding="utf-8");
59+
note = ""
6060
except Exception as e:
6161
soup = BeautifulSoup(xmlstr, "xml") # Use "xml" parser for XML files
62-
# xmlstr = ("XML parse failed "+str(e)+"\n"+"Re-parsed with BeautifulSoup\n").encode() + soup.prettify().encode()
6362
dom = minidom.parseString(soup.prettify());
64-
xmlstr = ("XML parse failed "+str(e)+"\n"+"Re-parsed with BeautifulSoup\n").encode() + dom.toprettyxml(encoding="utf-8");
65-
pass
66-
xmlstr = xmlstr.decode()
63+
note = "XML parse failed "+str(e)+"\n"+"Re-parsed with BeautifulSoup\n"
64+
for elem in dom.getElementsByTagName("property"):
65+
print(elem.nodeName)
66+
if elem.nodeName == "property" :
67+
if elem.getAttribute("enc") != "BASE64" : continue
68+
decoded = base64.b64decode(elem.getAttribute("value"))
69+
elem.setAttribute("B64Decoded", decoded.decode())
70+
xmlstr = dom.toprettyxml(encoding="utf-8");
71+
xmlstr = note + xmlstr.decode()
6772
xmlstr = re.sub(r'^\s*\n', '', xmlstr, flags=re.MULTILINE)
6873
htm = "<pre>\n" + html.escape(xmlstr) + "\n</pre>\n"
6974
piece['html'] = htm

0 commit comments

Comments
 (0)