mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-19 09:16:39 +00:00
in the recent reconciliation of webopen patches, I wound up adjusting webopen to 'pass through' the state of the trailing slash on the given argument to the resultant url passed to the browser. this change removes the requirement that arguments must be directories, and allows webopen to be used with files. it also broke the tests that assumed that webopen would always normalise the url to have a trailing slash. in fixing the tests, I realised that, IMHO, there's something deeply awry with the way tahoe handles paths; specifically in the combination of '/' being the name of the root path within an alias, but a leading slash on paths, e.g. 'alias:/path', is catagorically incorrect. i.e. 'tahoe:' == 'tahoe:/' == '/' but 'tahoe:/foo' is an invalid path, and must be 'tahoe:foo' I wound up making the internals of webopen simply spot a 'path' of '/' and smash it to '', which 'fixes' webopen to match the behaviour of tahoe's path handling elsewhere, but that special case sort of points to the weirdness. (fwiw, I personally found the fact that the leading / in a path was disallowed to be weird - I'm just used to seeing paths qualified by the leading / I guess - so in a debate about normalising path handling I'd vote to include the /)
22 lines
563 B
Python
22 lines
563 B
Python
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
|
|
import urllib
|
|
|
|
def webopen(options, opener=None):
|
|
nodeurl = options['node-url']
|
|
if not nodeurl.endswith("/"):
|
|
nodeurl += "/"
|
|
where = options.where
|
|
rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
|
|
if path == '/':
|
|
path = ''
|
|
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
|
|
if path:
|
|
url += "/" + escape_path(path)
|
|
if not opener:
|
|
import webbrowser
|
|
opener = webbrowser.open
|
|
opener(url)
|
|
return 0
|
|
|