Error in se xpath

85 views
Skip to first unread message

Alexander Keane

unread,
Sep 13, 2025, 8:20:41 AM (5 days ago) Sep 13
to Standard Ebooks
I'm at the manual typography section in the step-by-step and went to run the xpath command to find all caps. I got an error about a mismatched '(' in xpath.py

Error:
xpath "//p//text()[re:test(., '[A-Z]{2,}') and not(contains(., 'OK') or contains(., 'SOS')) and not(parent::abbr or parent::var or parent::a or parent::*[contains(@epub:type, 'z3998:roman')])]" src/epub/text/*.xhtml
Traceback (most recent call last):
  File "/home/squishy-mage/.local/bin/se", line 7, in <module>
    sys.exit(main())
  File "/home/squishy-mage/.local/pipx/venvs/standardebooks/lib/python3.10/site-packages/se/main.py", line 75, in main
    module = importlib.import_module(command_module)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 879, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1017, in get_code
  File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/squishy-mage/.local/pipx/venvs/standardebooks/lib/python3.10/site-packages/se/commands/xpath.py", line 48
    output = f"[path][link=file://{filepath.resolve()}#L{node.sourceline}]Line {node.sourceline}[/][/]: {node.to_string().replace("[", "\\[")}"
                                                                                                                                   ^
SyntaxError: f-string: unmatched '('

This is the first time I've gotten the error, and I verified that I am on 2.9.3

Vince

unread,
Sep 13, 2025, 10:47:04 AM (5 days ago) Sep 13
to Standard Ebooks
Someone else had this a couple of days ago, and Alex said to upgrade python, as later versions changed how f strings are handled, which the person did and it worked. Neither of them said what version, though; I can say that I’m on 3.13 and don’t get the error, but it’s possible 3.12 is OK as well.

Vince

unread,
Sep 13, 2025, 11:02:03 AM (5 days ago) Sep 13
to Standard Ebooks
It looks like the f-string improvements were made in 3.12.

Marshall Bockrath

unread,
Sep 13, 2025, 11:52:35 AM (5 days ago) Sep 13
to standar...@googlegroups.com
Should standard install instructions switch to installing via `uv` instead? It manages Python itself too, and has become pretty widely used.


--
You received this message because you are subscribed to the Google Groups "Standard Ebooks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to standardebook...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/standardebooks/8E12652C-917E-464C-8E04-2A9DDE4AA20A%40letterboxes.org.

Alex Cabal

unread,
Sep 13, 2025, 3:37:42 PM (4 days ago) Sep 13
to standar...@googlegroups.com
Every week there's a new ultimate Python version/package manager
solution. The whole thing is a disaster, but when it comes to disasters,
I prefer to learn and implement new disasters as little as possible.

On 9/13/25 10:52 AM, Marshall Bockrath wrote:
> Should standard install instructions switch to installing via `uv`
> instead? It manages Python itself too, and has become pretty widely used.
>
>
> On Sat, Sep 13, 2025, 11:02 Vince <vr_se...@letterboxes.org
> <mailto:vr_se...@letterboxes.org>> wrote:
>
> It looks like the f-string improvements were made in 3.12.
>
>> On Sep 13, 2025, at 9:46 AM, Vince <vr_se...@letterboxes.org
>> <mailto:vr_se...@letterboxes.org>> wrote:
>>
>> Someone else had this a couple of days ago, and Alex said to
>> upgrade python, as later versions changed how f strings are
>> handled, which the person did and it worked. Neither of them said
>> what version, though; I can say that I’m on 3.13 and don’t get the
>> error, but it’s possible 3.12 is OK as well.
>>
>>> On Sep 13, 2025, at 7:20 AM, Alexander Keane <lxtk...@gmail.com
> <mailto:standardebook...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> standardebooks/8E12652C-917E-464C-8E04-2A9DDE4AA20A%40letterboxes.org <https://groups.google.com/d/msgid/standardebooks/8E12652C-917E-464C-8E04-2A9DDE4AA20A%40letterboxes.org?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Standard Ebooks" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to standardebook...@googlegroups.com
> <mailto:standardebook...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> standardebooks/CAB-iOwqDKycOsgANLZR4-
> RyvoF_dvdaBTTrTfCSTw8b26sS1XQ%40mail.gmail.com <https://
> groups.google.com/d/msgid/standardebooks/CAB-iOwqDKycOsgANLZR4-
> RyvoF_dvdaBTTrTfCSTw8b26sS1XQ%40mail.gmail.com?
> utm_medium=email&utm_source=footer>.

Alexander Keane

unread,
Sep 15, 2025, 10:01:30 PM (2 days ago) Sep 15
to Standard Ebooks
Alright, I got python updated and finally got pipx and se pointing to the correct python. Xpath works, but now I'm getting an error when I run "find-unusual-characters" 

Traceback (most recent call last):
  File "/home/squishy-mage/.local/bin/se", line 7, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/squishy-mage/.local/pipx/venvs/standardebooks/lib/python3.12/site-packages/se/main.py", line 77, in main
    sys.exit(getattr(module, command_function)(args.plain_output))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/squishy-mage/.local/pipx/venvs/standardebooks/lib/python3.12/site-packages/se/commands/find_unusual_characters.py", line 125, in find_unusual_characters
    lines.append((unusual_character, unicodedata.name(unusual_character), count))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: no such name

Alex Cabal

unread,
Sep 16, 2025, 5:25:14 PM (2 days ago) Sep 16
to standar...@googlegroups.com
See this Github issue: https://github.com/python/cpython/issues/91103

You are running it on a file with extremely strange contents. Perhaps
you're accidentally running it on a directory that is not an ebook repo?
> <https://groups.google.com/d/msgid/>
> >
> standardebooks/8E12652C-917E-464C-8E04-2A9DDE4AA20A%40letterboxes.org <http://40letterboxes.org> <https://groups.google.com/d/msgid/standardebooks/8E12652C-917E-464C-8E04-2A9DDE4AA20A%40letterboxes.org?utm_medium=email&utm_source=footer <https://groups.google.com/d/msgid/standardebooks/8E12652C-917E-464C-8E04-2A9DDE4AA20A%40letterboxes.org?utm_medium=email&utm_source=footer>>.
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Standard Ebooks" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to standardebook...@googlegroups.com
> > <mailto:standardebook...@googlegroups.com>.
> > To view this discussion visit https://groups.google.com/d/msgid/
> <https://groups.google.com/d/msgid/>
> > standardebooks/CAB-iOwqDKycOsgANLZR4-
> > RyvoF_dvdaBTTrTfCSTw8b26sS1XQ%40mail.gmail.com
> <http://40mail.gmail.com> <https://
> > groups.google.com/d/msgid/standardebooks/CAB-iOwqDKycOsgANLZR4-
> <http://groups.google.com/d/msgid/standardebooks/CAB-
> iOwqDKycOsgANLZR4->
> > RyvoF_dvdaBTTrTfCSTw8b26sS1XQ%40mail.gmail.com
> <http://40mail.gmail.com>?
> > utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Standard Ebooks" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to standardebook...@googlegroups.com
> <mailto:standardebook...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> standardebooks/39a41b89-548b-478e-8c75-0fac6e2eb87cn%40googlegroups.com
> <https://groups.google.com/d/msgid/
> standardebooks/39a41b89-548b-478e-8c75-0fac6e2eb87cn%40googlegroups.com?
> utm_medium=email&utm_source=footer>.

Alexander Keane

unread,
Sep 16, 2025, 11:23:04 PM (2 days ago) Sep 16
to Standard Ebooks
Thank you!

Wish the Python team would make that error language clearer. It really had me thinking it was a function coding error rather than a file format error. Had it just told me "while parsing file X" from the get go...

Vince

unread,
Sep 17, 2025, 12:05:37 AM (yesterday) Sep 17
to standar...@googlegroups.com
That’s what the issue was about—the function doesn’t handle control characters, to be able to do that.

We might be able to, though; the unicode-names function already traps for this kind of situation. I just tried a random control character, though, and got an XML parsing error, so it never got to the error you received. Do you know what character it was choking on?

Alexander Keane

unread,
Sep 17, 2025, 12:13:30 AM (yesterday) Sep 17
to standar...@googlegroups.com
I'm not sure what it was. Once I knew what to look for, and tested find-unusual-characters on individual files to find the culprit file, it appeared in Emacs as a red \200 following a diacritic letter that had gotten messed up during the ASCII->UTF-8 conversion.

Cleared it out and everything ran fine.

--
You received this message because you are subscribed to the Google Groups "Standard Ebooks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to standardebook...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/standardebooks/B620C8DD-F2B4-4829-85B9-E5F3ACF0B55E%40letterboxes.org.


--
It's turtles all the way down!

Vince

unread,
Sep 17, 2025, 12:36:11 AM (yesterday) Sep 17
to Standard Ebooks
Thanks. I’ve submitted a PR (for `find-unusual-characters`, not python) that should trap these and handle them gracefully.
Reply all
Reply to author
Forward
0 new messages