source: trunk/src/allmydata/scripts/tahoe_webopen.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 966 bytes
Line 
1"""
2Ported to Python 3.
3"""
4
5from urllib.parse import quote as url_quote
6
7from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
8                                     UnknownAliasError
9
10
11def webopen(options, opener=None):
12    nodeurl = options['node-url']
13    stderr = options.stderr
14    if not nodeurl.endswith("/"):
15        nodeurl += "/"
16    where = options.where
17    if where:
18        try:
19            rootcap, path = get_alias(options.aliases, where, DEFAULT_ALIAS)
20        except UnknownAliasError as e:
21            e.display(stderr)
22            return 1
23        path = str(path, "utf-8")
24        if path == '/':
25            path = ''
26        url = nodeurl + "uri/%s" % url_quote(rootcap)
27        if path:
28            url += "/" + escape_path(path)
29    else:
30        url = nodeurl
31    if options['info']:
32        url += "?t=info"
33    if not opener:
34        import webbrowser
35        opener = webbrowser.open
36    opener(url)
37    return 0
38
Note: See TracBrowser for help on using the repository browser.