View Single Post
Old 08-10-2023, 01:16 PM   #1
MerlinMama
Evangelist
MerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beautyMerlinMama does all things with Zen-like beauty
 
MerlinMama's Avatar
 
Posts: 498
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
Error in built-in RegEx function

I was looking to create a RegEx function and wanted to see how one of the others was set up, so I opened one (clicked the 'Create/Edit' button on Lower-Case Text)

Without changing anything, as I just wanted to see how it was set up, I clicked 'OK' and I got the following error message:

Spoiler:
calibre, version 6.24.0
ERROR: Invalid Python code: The code you created is not valid Python code, with error: cannot import name 'change_case' from 'calibre.utils.icu' (C:\Program Files\Calibre2\app\bin\python-lib.bypy.frozen\calibre\utils\icu.pyc)


I realize that perhaps while I was checking this out I might have inadvertently changed something, I wasn't really paying attention, so I checked 'Upper-case text'. This time I definitely touched only the 'OK' button and got the same error message.

I checked 'Title-case text', and this one does NOT give me the error message.

Here is what is in the Function:

Spoiler:
Code:
from calibre.utils.icu import change_case
from calibre.ebooks.oeb.polish.utils import apply_func_to_match_groups

def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    '''Make matched text lower case. If the regular expression contains groups,
    only the text in the groups will be changed, otherwise the entire text is
    changed.'''
    return apply_func_to_match_groups(match, lower)
MerlinMama is offline   Reply With Quote