mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-07 20:00:20 +00:00
Add test for escape_path.
This commit is contained in:
parent
2bd244dde9
commit
210eb5b529
@ -1,3 +1,5 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os, sys, urllib, textwrap
|
import os, sys, urllib, textwrap
|
||||||
@ -270,6 +272,16 @@ def get_alias(aliases, path_unicode, default):
|
|||||||
return uri.from_string_dirnode(aliases[alias]).to_string(), path[colon+1:]
|
return uri.from_string_dirnode(aliases[alias]).to_string(), path[colon+1:]
|
||||||
|
|
||||||
def escape_path(path):
|
def escape_path(path):
|
||||||
|
# type: (str) -> str
|
||||||
|
"""
|
||||||
|
Return path quoted to US-ASCII.
|
||||||
|
|
||||||
|
>>> path = u'/føö/bar/☃'
|
||||||
|
>>> escape_path(path)
|
||||||
|
'/f%C3%B8%C3%B6/bar/%E2%98%83'
|
||||||
|
>>> escape_path(path).encode('ascii')
|
||||||
|
b'/f%C3%B8%C3%B6/bar/%E2%98%83'
|
||||||
|
"""
|
||||||
# this always returns bytes, specifically US-ASCII, valid URL characters
|
# this always returns bytes, specifically US-ASCII, valid URL characters
|
||||||
segments = path.split("/")
|
segments = path.split("/")
|
||||||
return "/".join([urllib.quote(unicode_to_url(s)) for s in segments])
|
return "/".join([urllib.quote(unicode_to_url(s)) for s in segments])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user