unnecessary regex (auto-fix)

ruff 'RUF055'
This commit is contained in:
un-pogaz 2025-01-24 11:14:20 +01:00
parent 7f6a11a368
commit bd59682f46
25 changed files with 99 additions and 99 deletions

View File

@ -92,8 +92,7 @@ class brewiarz(BasicNewsRecipe):
for sublink in sublinks: for sublink in sublinks:
link_title = self.tag_to_string( link_title = self.tag_to_string(
link) + ' - ' + self.tag_to_string(sublink) link) + ' - ' + self.tag_to_string(sublink)
link_url_print = re.sub( link_url_print = sublink['href'].replace('php3', 'php3?kr=_druk&wr=lg&')
'php3', 'php3?kr=_druk&wr=lg&', sublink['href'])
link_url = url[:-10] + link_url_print link_url = url[:-10] + link_url_print
current_articles.append({'title': link_title, current_articles.append({'title': link_title,
'url': link_url, 'description': '', 'date': ''}) 'url': link_url, 'description': '', 'date': ''})
@ -102,8 +101,7 @@ class brewiarz(BasicNewsRecipe):
continue continue
else: else:
link_title = self.tag_to_string(link) link_title = self.tag_to_string(link)
link_url_print = re.sub( link_url_print = link['href'].replace('php3', 'php3?kr=_druk&wr=lg&')
'php3', 'php3?kr=_druk&wr=lg&', link['href'])
link_url = url[:-10] + link_url_print link_url = url[:-10] + link_url_print
current_articles.append({'title': link_title, current_articles.append({'title': link_title,
'url': link_url, 'description': '', 'date': ''}) 'url': link_url, 'description': '', 'date': ''})

View File

@ -170,18 +170,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -170,18 +170,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -170,18 +170,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -86,7 +86,7 @@ class NikkeiNet_paper_subscription(BasicNewsRecipe):
sect_title = sect_title.contents[0] sect_title = sect_title.contents[0]
sect_result = [] sect_result = []
url = sect.a['href'] url = sect.a['href']
url = re.sub('/article/', '/print-article/', url) url = url.replace('/article/', '/print-article/')
url = 'http://www.nikkei.com' + url url = 'http://www.nikkei.com' + url
sect_result.append(dict(title=sect_title, url=url, date='',description='', content='')) sect_result.append(dict(title=sect_title, url=url, date='',description='', content=''))
result.append([sect_title, sect_result]) result.append([sect_title, sect_result])

View File

@ -170,18 +170,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -129,18 +129,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -73,7 +73,7 @@ class respektRecipe(BasicNewsRecipe):
def preprocess_raw_html(self, raw_html, url): def preprocess_raw_html(self, raw_html, url):
root = lxml.html.fromstring(raw_html) root = lxml.html.fromstring(raw_html)
if root.xpath('//title')[0].text == (u'Respekt • Despekt • RESPEKT'): if root.xpath('//title')[0].text == (u'Respekt • Despekt • RESPEKT'):
raw_html = re.sub('h2','h1',raw_html) raw_html = raw_html.replace('h2', 'h1')
return raw_html return raw_html
def parse_index(self): def parse_index(self):

View File

@ -129,18 +129,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -183,18 +183,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -171,18 +171,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -133,18 +133,18 @@ class TimesColonist(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -129,18 +129,18 @@ class CanWestPaper(BasicNewsRecipe):
def fixChars(self, string): def fixChars(self, string):
# Replace lsquo (\x91) # Replace lsquo (\x91)
fixed = re.sub('\x91', '', string) fixed = string.replace('\x91', '')
# Replace rsquo (\x92) # Replace rsquo (\x92)
fixed = re.sub('\x92', '', fixed) fixed = fixed.replace('\x92', '')
# Replace ldquo (\x93) # Replace ldquo (\x93)
fixed = re.sub('\x93', '', fixed) fixed = fixed.replace('\x93', '')
# Replace rdquo (\x94) # Replace rdquo (\x94)
fixed = re.sub('\x94', '', fixed) fixed = fixed.replace('\x94', '')
# Replace ndash (\x96) # Replace ndash (\x96)
fixed = re.sub('\x96', '', fixed) fixed = fixed.replace('\x96', '')
# Replace mdash (\x97) # Replace mdash (\x97)
fixed = re.sub('\x97', '', fixed) fixed = fixed.replace('\x97', '')
fixed = re.sub('’', '', fixed) fixed = fixed.replace('’', '')
return fixed return fixed
def massageNCXText(self, description): def massageNCXText(self, description):

View File

@ -33,6 +33,7 @@ select = [
'RUF', # nota: RUF can flag many unsolicited errors 'RUF', # nota: RUF can flag many unsolicited errors
# preview rules # preview rules
'RUF051', 'RUF056', # useless dict operation 'RUF051', 'RUF056', # useless dict operation
'RUF055', # unnecessary regex
] ]
[lint.per-file-ignores] [lint.per-file-ignores]
@ -45,6 +46,7 @@ select = [
"src/calibre/gui2/store/stores/*" = ['UP'] "src/calibre/gui2/store/stores/*" = ['UP']
"src/calibre/gui2/tts/manager.py" = ['UP037'] "src/calibre/gui2/tts/manager.py" = ['UP037']
"src/calibre/utils/copy_files.py" = ['UP037'] "src/calibre/utils/copy_files.py" = ['UP037']
"src/calibre/utils/smartypants.py" = ['RUF055']
"src/qt/*.py" = ['I'] "src/qt/*.py" = ['I']
"src/qt/*.pyi" = ['I'] "src/qt/*.pyi" = ['I']

View File

@ -686,7 +686,7 @@ class HeuristicProcessor:
else: else:
text_indent = style+':'+str(setting)+'pt;' text_indent = style+':'+str(setting)+'pt;'
if style == 'padding': if style == 'padding':
setting = re.sub('pt', '', setting).split(' ') setting = setting.replace('pt', '').split(' ')
if int(setting[1]) < 16 and int(setting[3]) < 16: if int(setting[1]) < 16 and int(setting[3]) < 16:
if self.in_blockquote: if self.in_blockquote:
debugabby = True debugabby = True

View File

@ -153,7 +153,7 @@ class HTMLConverter:
# Remove <br> and replace <br><br> with <p> # Remove <br> and replace <br><br> with <p>
(re.compile(r'<br.*?>\s*<br.*?>', re.IGNORECASE), lambda match: '<p>'), (re.compile(r'<br.*?>\s*<br.*?>', re.IGNORECASE), lambda match: '<p>'),
(re.compile(r'(.*)<br.*?>', re.IGNORECASE), (re.compile(r'(.*)<br.*?>', re.IGNORECASE),
lambda match: match.group() if re.match('<', match.group(1).lstrip()) or len(match.group(1)) < 40 lambda match: match.group() if match.group(1).lstrip().startswith('<') or len(match.group(1)) < 40
else match.group(1)), else match.group(1)),
# Remove hyphenation # Remove hyphenation
(re.compile(r'-\n\r?'), lambda match: ''), (re.compile(r'-\n\r?'), lambda match: ''),
@ -1864,8 +1864,8 @@ def process_file(path, options, logger):
fheader = '%t by %a' fheader = '%t by %a'
fheader = re.sub(r'(?<!%)%t', options.title, fheader) fheader = re.sub(r'(?<!%)%t', options.title, fheader)
fheader = re.sub(r'(?<!%)%a', options.author, fheader) fheader = re.sub(r'(?<!%)%a', options.author, fheader)
fheader = re.sub(r'%%a','%a',fheader) fheader = fheader.replace('%%a', '%a')
fheader = re.sub(r'%%t','%t',fheader) fheader = fheader.replace('%%t', '%t')
header.append(fheader + ' ') header.append(fheader + ' ')
book, fonts = Book(options, logger, header=header, **args) book, fonts = Book(options, logger, header=header, **args)
le = re.compile(options.link_exclude) if options.link_exclude else \ le = re.compile(options.link_exclude) if options.link_exclude else \

View File

@ -312,7 +312,7 @@ class FlowSplitter:
def split_text(self, text, root, size): def split_text(self, text, root, size):
self.log.debug('\t\t\tSplitting text of length: %d'%len(text)) self.log.debug('\t\t\tSplitting text of length: %d'%len(text))
rest = text.replace('\r', '') rest = text.replace('\r', '')
parts = re.split('\n\n', rest) parts = rest.split('\n\n')
self.log.debug('\t\t\t\tFound %d parts'%len(parts)) self.log.debug('\t\t\t\tFound %d parts'%len(parts))
if max(map(len, parts)) > size: if max(map(len, parts)) > size:
raise SplitError('Cannot split as file contains a <pre> tag ' raise SplitError('Cannot split as file contains a <pre> tag '

View File

@ -200,7 +200,7 @@ class RTFMLizer:
# Remove excessive spaces # Remove excessive spaces
text = re.sub('[ ]{2,}', ' ', text) text = re.sub('[ ]{2,}', ' ', text)
text = re.sub('\t{2,}', '\t', text) text = re.sub('\t{2,}', '\t', text)
text = re.sub('\t ', '\t', text) text = text.replace('\t ', '\t')
# Remove excessive line breaks # Remove excessive line breaks
text = re.sub(r'(\{\\line \}\s*){3,}', r'{\\line }{\\line }', text) text = re.sub(r'(\{\\line \}\s*){3,}', r'{\\line }{\\line }', text)

View File

@ -594,7 +594,7 @@ class Textile:
line = self.doPBr(line) line = self.doPBr(line)
if self.html_type == 'xhtml': if self.html_type == 'xhtml':
line = re.sub(r'<br>', '<br />', line) line = line.replace('<br>', '<br />')
if ext and anon: if ext and anon:
out.append(out.pop() + '\n' + line) out.append(out.pop() + '\n' + line)

View File

@ -63,7 +63,7 @@ class MarkdownMLizer(OEB2HTML):
start = start.group() start = start.group()
else: else:
start = '' start = ''
l = re.sub('\t', '', l) l = l.replace('\t', '')
new_text.append(start + l) new_text.append(start + l)
text = '\n'.join(new_text) text = '\n'.join(new_text)

View File

@ -95,7 +95,7 @@ class TextileMLizer(OEB2HTML):
# remove empty spans # remove empty spans
text = re.sub(r'%\xa0+', r'%', text) text = re.sub(r'%\xa0+', r'%', text)
# remove empty spans - MAY MERGE SOME ? # remove empty spans - MAY MERGE SOME ?
text = re.sub(r'%%', r'', text) text = text.replace('%%', '')
# remove spans from tagged output # remove spans from tagged output
text = re.sub(r'%([_+*-]+)%', r'\1', text) text = re.sub(r'%([_+*-]+)%', r'\1', text)
# remove spaces before a newline # remove spaces before a newline
@ -402,7 +402,7 @@ class TextileMLizer(OEB2HTML):
txt = self.build_block('', style, attribs, stylizer) txt = self.build_block('', style, attribs, stylizer)
txt += '. ' txt += '. '
if txt != '\n. ': if txt != '\n. ':
txt = re.sub('\n', '', txt) txt = txt.replace('\n', '')
text.append(txt) text.append(txt)
tags.append('|\n') tags.append('|\n')
elif tag == 'td': elif tag == 'td':

View File

@ -72,7 +72,7 @@ class GenerateCatalogAction(InterfaceAction):
# jobs.results is a list - the first entry is the intended title for the dialog # jobs.results is a list - the first entry is the intended title for the dialog
# Subsequent strings are error messages # Subsequent strings are error messages
dialog_title = job.result.pop(0) dialog_title = job.result.pop(0)
if re.search('warning', job.result[0].lower()): if 'warning' in job.result[0].lower():
msg = _('Catalog generation complete, with warnings.') msg = _('Catalog generation complete, with warnings.')
warning_dialog(self.gui, dialog_title, msg, det_msg='\n'.join(job.result), show=True) warning_dialog(self.gui, dialog_title, msg, det_msg='\n'.join(job.result), show=True)
else: else:

View File

@ -82,10 +82,10 @@ class NextoStore(BasicStoreConfig, StorePlugin):
price = ''.join(data.xpath('.//strong[@class="nprice"]/text()')) price = ''.join(data.xpath('.//strong[@class="nprice"]/text()'))
cover_url = ''.join(data.xpath('.//picture[@class="cover"]/img/@data-src')) cover_url = ''.join(data.xpath('.//picture[@class="cover"]/img/@data-src'))
cover_url = re.sub(r'%2F', '/', cover_url) cover_url = cover_url.replace('%2F', '/')
cover_url = re.sub(r'widthMax=235&heightMax=335', 'widthMax=64&heightMax=64', cover_url) cover_url = cover_url.replace('widthMax=235&heightMax=335', 'widthMax=64&heightMax=64')
title = ''.join(data.xpath('.//a[@class="title"]/text()')) title = ''.join(data.xpath('.//a[@class="title"]/text()'))
title = re.sub(r' ebook', '', title) title = title.replace(' ebook', '')
author = ', '.join(data.xpath('.//div[@class="col-7"]//h4//a/text()')) author = ', '.join(data.xpath('.//div[@class="col-7"]//h4//a/text()'))
formats = ', '.join(data.xpath('.//ul[@class="formats"]/li//b/text()')) formats = ', '.join(data.xpath('.//ul[@class="formats"]/li//b/text()'))
DrmFree = data.xpath('.//ul[@class="formats"]/li//b[contains(@title, "znak")]') DrmFree = data.xpath('.//ul[@class="formats"]/li//b[contains(@title, "znak")]')

View File

@ -75,7 +75,7 @@ class RW2010Store(BasicStoreConfig, StorePlugin):
s.title = title.strip() s.title = title.strip()
s.author = author.strip() s.author = author.strip()
s.price = price s.price = price
s.detail_item = re.sub(r'%3D', '=', id) s.detail_item = id.replace('%3D', '=')
s.drm = SearchResult.DRM_UNLOCKED s.drm = SearchResult.DRM_UNLOCKED
s.formats = formats[0:-2].upper() s.formats = formats[0:-2].upper()

View File

@ -88,9 +88,9 @@ class NumberToText: # {{{
# Special case ordinals # Special case ordinals
if re.search('[st|nd|rd|th]',self.number): if re.search('[st|nd|rd|th]',self.number):
self.number = re.sub(',','',self.number) self.number = self.number.replace(',', '')
ordinal_suffix = re.search(r'[\D]', self.number) ordinal_suffix = re.search(r'[\D]', self.number)
ordinal_number = re.sub(r'\D','',re.sub(',','',self.number)) ordinal_number = re.sub(r'\D','',self.number.replace(',', ''))
if self.verbose: if self.verbose:
self.log('Ordinal: %s' % ordinal_number) self.log('Ordinal: %s' % ordinal_number)
self.number_as_float = ordinal_number self.number_as_float = ordinal_number
@ -102,17 +102,17 @@ class NumberToText: # {{{
self.text = '%s' % (self.ORDINALS[int(ordinal_number)]) self.text = '%s' % (self.ORDINALS[int(ordinal_number)])
# Test for time # Test for time
elif re.search(':',self.number): elif ':' in self.number:
if self.verbose: if self.verbose:
self.log('Time: %s' % self.number) self.log('Time: %s' % self.number)
self.number_as_float = re.sub(':','.',self.number) self.number_as_float = self.number.replace(':', '.')
time_strings = self.number.split(':') time_strings = self.number.split(':')
hours = NumberToText(time_strings[0]).text hours = NumberToText(time_strings[0]).text
minutes = NumberToText(time_strings[1]).text minutes = NumberToText(time_strings[1]).text
self.text = f'{hours.capitalize()}-{minutes}' self.text = f'{hours.capitalize()}-{minutes}'
# Test for % # Test for %
elif re.search('%', self.number): elif '%' in self.number:
if self.verbose: if self.verbose:
self.log('Percent: %s' % self.number) self.log('Percent: %s' % self.number)
self.number_as_float = self.number.split('%')[0] self.number_as_float = self.number.split('%')[0]
@ -129,7 +129,7 @@ class NumberToText: # {{{
self.text = f'{left.capitalize()} point {right}' self.text = f'{left.capitalize()} point {right}'
# Test for hyphenated # Test for hyphenated
elif re.search('-', self.number): elif '-' in self.number:
if self.verbose: if self.verbose:
self.log('Hyphenated: %s' % self.number) self.log('Hyphenated: %s' % self.number)
self.number_as_float = self.number.split('-')[0] self.number_as_float = self.number.split('-')[0]
@ -143,10 +143,10 @@ class NumberToText: # {{{
self.text = f'{left}-{right}' self.text = f'{left}-{right}'
# Test for only commas and numbers # Test for only commas and numbers
elif re.search(',', self.number) and not re.search('[^0-9,]',self.number): elif ',' in self.number and not re.search('[^0-9,]',self.number):
if self.verbose: if self.verbose:
self.log('Comma(s): %s' % self.number) self.log('Comma(s): %s' % self.number)
self.number_as_float = re.sub(',','',self.number) self.number_as_float = self.number.replace(',', '')
self.text = NumberToText(self.number_as_float).text self.text = NumberToText(self.number_as_float).text
# Test for hybrid e.g., 'K2, 2nd, 10@10' # Test for hybrid e.g., 'K2, 2nd, 10@10'