Skip to content

Commit ccfddd9

Browse files
committed
explaining url path handling and small cleanup.
1 parent 509316e commit ccfddd9

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

textile/core.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def fTextileList(self, match):
350350
try:
351351
self.olstarts[tl] = self.olstarts[tl] + 1
352352
# if we get here, we've got some poor textile formatting.
353-
# add this type of list to olstarts and assume we'llstart
353+
# add this type of list to olstarts and assume we'll start
354354
# it at 1. expect screwy output.
355355
except KeyError:
356356
self.olstarts[tl] = 1
@@ -982,16 +982,19 @@ def encode_url(self, url):
982982
quote(netloc_parsed['password']))
983983
host = netloc_parsed['host']
984984
port = netloc_parsed['port'] and netloc_parsed['port']
985+
# the below splits the path portion of the url by slashes, translates
986+
# percent-encoded characters back into strings, then re-percent-encodes
987+
# what's necessary. Sounds screwy, but the url could include encoded
988+
# slashes, and this is a way to clean that up. It branches for PY2/3
989+
# because the quote and unquote functions expects different input
990+
# types: unicode strings for PY2 and str for PY3.
985991
if six.PY2:
986-
path = '/'.join( # could be encoded slashes!
987-
quote(unquote(pce.encode('utf8')), b'')
988-
for pce in parsed.path.split('/')
989-
)
992+
path_parts = (quote(unquote(pce.encode('utf8')), b'') for pce in
993+
parsed.path.split('/'))
990994
else:
991-
path = '/'.join( # could be encoded slashes!
992-
quote(unquote(pce), b'')
993-
for pce in parsed.path.split('/')
994-
)
995+
path_parts = (quote(unquote(pce), b'') for pce in
996+
parsed.path.split('/'))
997+
path = '/'.join(path_parts)
995998
fragment = quote(unquote(parsed.fragment))
996999

9971000
# put it back together

0 commit comments

Comments
 (0)