| Line | |
|---|
| 1 | """ |
|---|
| 2 | Ported to Python 3. |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | from urllib.parse import quote as url_quote |
|---|
| 6 | |
|---|
| 7 | from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \ |
|---|
| 8 | UnknownAliasError |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | def 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.