Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the AML parsing bug in case of emoticons or UTF-8 characters #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions kerckhoff/packages/google_drive_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from datetime import timedelta
from urllib.parse import parse_qs, urlparse

import archieml
from allauth.socialaccount.models import SocialToken
from bleach.sanitizer import Cleaner
from django.conf import settings
from django.utils import timezone
from html5lib.filters.base import Filter
from requests_oauthlib import OAuth2Session
from .parser import Parser

from .constants import *

Expand Down Expand Up @@ -79,17 +79,9 @@ def check_span(tag, name, value):
data = session.get(GOOGLE_API_PREFIX + "/v2/files/" + aml['id'] + "/export", params={"mimeType": "text/plain"})
aml_text = data.content.decode('utf-8')
#print("IN ARCHIEML ")
aml_content = archieml.loads(aml_text)

# HACK: Fixes a bad bug in the archieml parser
for key, value in aml_content.items():
if isinstance(value, list):
for index, item in enumerate(value):
if isinstance(item, dict):
if item.get("type") is None and item.get("value") and isinstance(value[index-1], dict) and value[index-1].get("type"):
aml_content[key][index-1]["value"] = item["value"]
aml_content[key][index] = None
aml_content[key] = [ i for i in aml_content[key] if i is not None ]

parser = Parser()
aml_content = parser.parse(aml_text)
Comment on lines +83 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the parser has several assert statements, that when triggered, will cause the server to return a 500 response without any clear indication of what went wrong. Could you wrap this in a try/except block and return a more informative response to the client? (If possible, it would be best if you could replace each "assert" statement in the parser with an exception with a custom error message, but if you don't completely understand the parser code then it's fine not to have this).

We will have to add the ability to show the error messages for non-200 responses in a future issue.


aml_data[aml['title']] = aml_content

Expand Down Expand Up @@ -248,3 +240,5 @@ def __iter__(self):
styles=STYLES,
strip=True,
filters=[KeepOnlyInterestingSpans, ConvertPTagsToNewlines, RemoveGoogleTrackingFromHrefs])


Loading