Skip to content

Commit 660c81c

Browse files
committed
Tweaked the file content read refactoring in [14406] to try latin-1 conversion if unicode doesn't work.
- Legacy-Id: 14410 Note: SVN reference [14406] has been migrated to Git commit 967ece7
1 parent 3f40d9c commit 660c81c

File tree

8 files changed

+22
-14
lines changed

8 files changed

+22
-14
lines changed

ietf/doc/mails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def email_charter_internal_review(request, charter):
518518
os.path.join(settings.CHARTER_PATH,filename),
519519
split=False,
520520
markup=False,
521-
).decode('utf-8')
521+
)
522522
utext = charter.text_or_error() # pyflakes:ignore
523523
if charter_text and charter_text != utext and not 'Error; cannot read' in charter_text:
524524
debug.show('charter_text[:64]')

ietf/doc/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ietf.name.models import DocReminderTypeName, DocRelationshipName
2323
from ietf.group.models import Role
2424
from ietf.ietfauth.utils import has_role
25-
from ietf.utils import draft
25+
from ietf.utils import draft, text
2626
from ietf.utils.mail import send_mail
2727
from ietf.mailtrigger.utils import gather_address_lists
2828

@@ -311,7 +311,7 @@ def get_document_content(key, filename, split=True, markup=True):
311311
# return markup_txt.markup(raw_content, split)
312312
# else:
313313
# return raw_content
314-
return raw_content
314+
return text.decode(raw_content)
315315

316316
def tags_suffix(tags):
317317
return (u"::" + u"::".join(t.name for t in tags)) if tags else u""

ietf/doc/views_conflict_review.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def edit_ad(request, name):
254254
def default_approval_text(review):
255255

256256
filename = "%s-%s.txt" % (review.canonical_name(), review.rev)
257-
current_text = get_document_content(filename, os.path.join(settings.CONFLICT_REVIEW_PATH, filename), split=False, markup=False).decode('utf-8')
257+
current_text = get_document_content(filename, os.path.join(settings.CONFLICT_REVIEW_PATH, filename), split=False, markup=False)
258258
utext = review.text_or_error() # pyflakes:ignore
259259
if current_text and current_text != utext and not 'Error; cannot read' in current_text:
260260
debug.show('current_text[:64]')

ietf/doc/views_doc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def document_main(request, name, rev=None):
188188
filename = name + ".txt"
189189

190190
content = get_document_content(filename, os.path.join(settings.RFC_PATH, filename),
191-
split_content, markup=True).decode('utf-8')
191+
split_content, markup=True)
192192
utext = doc.text_or_error() # pyflakes:ignore
193193
if content and content != utext and not 'Error; cannot read' in content:
194194
debug.show('content[:64]')
@@ -224,7 +224,7 @@ def document_main(request, name, rev=None):
224224
filename = "%s-%s.txt" % (draft_name, doc.rev)
225225

226226
content = get_document_content(filename, os.path.join(settings.INTERNET_ALL_DRAFTS_ARCHIVE_DIR, filename),
227-
split_content, markup=True).decode('utf-8')
227+
split_content, markup=True)
228228
utext = doc.text_or_error() # pyflakes:ignore
229229
if content and content != utext and not 'Error; cannot read' in content:
230230
debug.show('content[:64]')
@@ -453,7 +453,7 @@ def document_main(request, name, rev=None):
453453
if doc.type_id == "charter":
454454
filename = "%s-%s.txt" % (doc.canonical_name(), doc.rev)
455455

456-
content = get_document_content(filename, os.path.join(settings.CHARTER_PATH, filename), split=False, markup=True).decode('utf-8')
456+
content = get_document_content(filename, os.path.join(settings.CHARTER_PATH, filename), split=False, markup=True)
457457
utext = doc.text_or_error() # pyflakes:ignore
458458
if content and content != utext and not 'Error; cannot read' in content:
459459
debug.show('content[:64]')
@@ -502,7 +502,7 @@ def document_main(request, name, rev=None):
502502
# This could move to a template
503503
content = u"A conflict review response has not yet been proposed."
504504
else:
505-
content = get_document_content(filename, pathname, split=False, markup=True).decode('utf-8')
505+
content = get_document_content(filename, pathname, split=False, markup=True)
506506
utext = doc.text_or_error() # pyflakes:ignore
507507
if content and content != utext and not 'Error; cannot read' in content:
508508
debug.show('content[:64]')
@@ -535,7 +535,7 @@ def document_main(request, name, rev=None):
535535
# This could move to a template
536536
content = u"Status change text has not yet been proposed."
537537
else:
538-
content = get_document_content(filename, pathname, split=False).decode('utf-8')
538+
content = get_document_content(filename, pathname, split=False)
539539
utext = doc.text_or_error() # pyflakes:ignore
540540
if content and content != utext and not 'Error; cannot read' in content:
541541
debug.show('content[:64]')
@@ -593,7 +593,7 @@ def document_main(request, name, rev=None):
593593
url = urlbase + extension
594594

595595
if extension == ".txt":
596-
content = get_document_content(basename, pathname + extension, split=False).decode('utf-8')
596+
content = get_document_content(basename, pathname + extension, split=False)
597597
utext = doc.text_or_error() # pyflakes:ignore
598598
if content != utext:
599599
debug.show('content[:64]')

ietf/doc/views_status_change.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def newstatus(relateddoc):
282282
def default_approval_text(status_change,relateddoc):
283283

284284
filename = "%s-%s.txt" % (status_change.canonical_name(), status_change.rev)
285-
current_text = get_document_content(filename, os.path.join(settings.STATUS_CHANGE_PATH, filename), split=False, markup=False).decode('utf-8')
285+
current_text = get_document_content(filename, os.path.join(settings.STATUS_CHANGE_PATH, filename), split=False, markup=False)
286286
utext = status_change.text_or_error() # pyflakes:ignore
287287
if current_text and current_text != utext and not 'Error; cannot read' in current_text:
288288
debug.show('current_text[:64]')

ietf/meeting/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def __init__(self, *args, **kwargs):
221221
if self.instance.agenda():
222222
doc = self.instance.agenda()
223223
path = os.path.join(doc.get_file_path(), doc.filename_with_rev())
224-
content = get_document_content(os.path.basename(path), path, markup=False).decode('utf-8')
224+
content = get_document_content(os.path.basename(path), path, markup=False)
225225
utext = doc.text_or_error() # pyflakes:ignore
226226
if content and content != utext and not 'Error; cannot read' in content:
227227
debug.show('content[:64]')

ietf/secr/telechat/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_doc_writeup(doc):
7272
writeup = latest.text
7373
elif doc.type_id == 'conflrev':
7474
path = os.path.join(doc.get_file_path(),doc.filename_with_rev())
75-
writeup = get_document_content(doc.name,path,split=False,markup=False).decode('utf-8')
75+
writeup = get_document_content(doc.name,path,split=False,markup=False)
7676
utext = doc.text_or_error() # pyflakes:ignore
7777
if writeup and writeup != utext and not 'Error; cannot read' in writeup:
7878
debug.show('writeup[:64]')

ietf/utils/text.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,13 @@ def maybe_split(text, split=True, pos=5000):
131131
text = text[:n+1]
132132
return text
133133

134-
134+
def decode(raw):
135+
assert isinstance(raw, six.binary_type)
136+
try:
137+
text = raw.decode('utf-8')
138+
except UnicodeDecodeError:
139+
# if this fails, don't catch the exception here; let it propagate
140+
text = raw.decode('latin-1')
141+
#
142+
return text
135143

0 commit comments

Comments
 (0)