Skip to content

Commit

Permalink
sagemathgh-39193: Some improvements to findstat._submit
Browse files Browse the repository at this point in the history
    
* for some reason the proper header is needed to open the HTML file on
my machine.
* It's reported that `webbrowser.open()` doesn't work when called on a
file path, rather an URI is needed
(sagemath#38946)


### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview. (not needed)

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39193
Reported by: user202729
Reviewer(s): Martin Rubey
  • Loading branch information
Release Manager committed Jan 2, 2025
2 parents 3950c7d + 4a82a39 commit a5c4b48
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/sage/databases/findstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def mapping(sigma):

from ast import literal_eval
from copy import deepcopy
from pathlib import Path
import re
import webbrowser
import tempfile
Expand Down Expand Up @@ -491,8 +492,9 @@ def _submit(args, url):
....: "CurrentEmail": ""}
sage: _submit(args, url) # optional -- webbrowser
"""
f = tempfile.NamedTemporaryFile(mode='w', suffix='.html', delete=False)
f = tempfile.NamedTemporaryFile(mode='w', suffix='.html', encoding='utf-8', delete=False)
verbose("Created temporary file %s" % f.name, caller_name='FindStat')
f.write('<!doctype html>\n<html lang="en">\n<meta charset="utf-8">\n')
f.write(FINDSTAT_POST_HEADER)
f.write(url)
for key, value in args.items():
Expand All @@ -506,7 +508,7 @@ def _submit(args, url):
f.write(FINDSTAT_FORM_FOOTER)
f.close()
verbose("Opening file with webbrowser", caller_name='FindStat')
webbrowser.open(f.name)
webbrowser.open(Path(f.name).as_uri())


def _data_to_str(data, domain, codomain=None):
Expand Down

0 comments on commit a5c4b48

Please sign in to comment.