Skip to content

Commit f7cfd0e

Browse files
committed
Apply pyupgrade to the tools directory
1 parent 2b16336 commit f7cfd0e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

tools/idna-data

+18-18
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def hexvalue(value):
8787
class UnicodeVersion(object):
8888

8989
def __init__(self, version):
90-
result = re.match('^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)$', version)
90+
result = re.match(r'^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)$', version)
9191
if result:
9292
self.major = int(result.group('major'))
9393
self.minor = int(result.group('minor'))
@@ -172,7 +172,7 @@ class UnicodeData(object):
172172
self.ucd_props = collections.defaultdict(list)
173173
for line in f_pl.splitlines():
174174
result = re.match(
175-
'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<prop>\S+)\s*(|\#.*)$',
175+
r'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<prop>\S+)\s*(|\#.*)$',
176176
line)
177177
if result:
178178
if result.group('end'):
@@ -187,7 +187,7 @@ class UnicodeData(object):
187187
f_dcp = self._ucdfile('DerivedCoreProperties.txt')
188188
for line in f_dcp.splitlines():
189189
result = re.match(
190-
'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<prop>\S+)\s*(|\#.*)$',
190+
r'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<prop>\S+)\s*(|\#.*)$',
191191
line)
192192
if result:
193193
if result.group('end'):
@@ -203,7 +203,7 @@ class UnicodeData(object):
203203
f_b = self._ucdfile('Blocks.txt')
204204
for line in f_b.splitlines():
205205
result = re.match(
206-
'^(?P<start>[0-9A-F]{4,6})\.\.(?P<end>[0-9A-F]{4,6})\s*;\s*(?P<block>.*)\s*$',
206+
r'^(?P<start>[0-9A-F]{4,6})\.\.(?P<end>[0-9A-F]{4,6})\s*;\s*(?P<block>.*)\s*$',
207207
line)
208208
if result:
209209
for i in hexrange(result.group('start'), result.group('end')):
@@ -216,7 +216,7 @@ class UnicodeData(object):
216216
f_cf = self._ucdfile('CaseFolding.txt')
217217
for line in f_cf.splitlines():
218218
result = re.match(
219-
'^(?P<cp>[0-9A-F]{4,6})\s*;\s*(?P<type>\S+)\s*;\s*(?P<subst>[0-9A-F\s]+)\s*',
219+
r'^(?P<cp>[0-9A-F]{4,6})\s*;\s*(?P<type>\S+)\s*;\s*(?P<subst>[0-9A-F\s]+)\s*',
220220
line)
221221
if result:
222222
if result.group('type') in ('C', 'F'):
@@ -229,7 +229,7 @@ class UnicodeData(object):
229229
f_hst = self._ucdfile('HangulSyllableType.txt')
230230
for line in f_hst.splitlines():
231231
result = re.match(
232-
'^(?P<start>[0-9A-F]{4,6})\.\.(?P<end>[0-9A-F]{4,6})\s*;\s*(?P<type>\S+)\s*(|\#.*)$',
232+
r'^(?P<start>[0-9A-F]{4,6})\.\.(?P<end>[0-9A-F]{4,6})\s*;\s*(?P<type>\S+)\s*(|\#.*)$',
233233
line)
234234
if result:
235235
for i in hexrange(result.group('start'), result.group('end')):
@@ -240,7 +240,7 @@ class UnicodeData(object):
240240
self.ucd_as = {}
241241
f_as = self._ucdfile('ArabicShaping.txt')
242242
for line in f_as.splitlines():
243-
result = re.match('^(?P<cp>[0-9A-F]{4,6})\s*;\s*.*?\s*;\s*(?P<jt>\S+)\s*;', line)
243+
result = re.match(r'^(?P<cp>[0-9A-F]{4,6})\s*;\s*.*?\s*;\s*(?P<jt>\S+)\s*;', line)
244244
if result:
245245
self.ucd_as[int(result.group('cp'), 16)] = result.group('jt')
246246

@@ -250,7 +250,7 @@ class UnicodeData(object):
250250
f_s = self._ucdfile('Scripts.txt')
251251
for line in f_s.splitlines():
252252
result = re.match(
253-
'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<script>\S+)\s*(|\#.*)$',
253+
r'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<script>\S+)\s*(|\#.*)$',
254254
line)
255255
if result:
256256
if not result.group('script') in self.ucd_s:
@@ -268,7 +268,7 @@ class UnicodeData(object):
268268
f_idnamt = self._ucdfile('IdnaMappingTable.txt', urlbase=UTS46_URL)
269269
for line in f_idnamt.splitlines():
270270
result = re.match(
271-
'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<fields>[^#]+)',
271+
r'^(?P<start>[0-9A-F]{4,6})(|\.\.(?P<end>[0-9A-F]{4,6}))\s*;\s*(?P<fields>[^#]+)',
272272
line)
273273
if result:
274274
fields = [x.strip() for x in result.group('fields').split(';')]
@@ -515,7 +515,7 @@ def idna_libdata(ucdata):
515515
#
516516
yield 'scripts = {'
517517
for script in SCRIPT_WHITELIST:
518-
prefix = ' \'{0}\': '.format(script)
518+
prefix = ' \'{}\': '.format(script)
519519
for line in optimised_list(ucdata.ucd_s[script]):
520520
yield prefix + line
521521
prefix = ''
@@ -527,7 +527,7 @@ def idna_libdata(ucdata):
527527
yield 'joining_types = {'
528528
for cp in ucdata.codepoints():
529529
if cp.joining_type:
530-
yield ' 0x{0:x}: {1},'.format(cp.value, ord(cp.joining_type))
530+
yield ' 0x{:x}: {},'.format(cp.value, ord(cp.joining_type))
531531
yield '}'
532532

533533
#
@@ -543,7 +543,7 @@ def idna_libdata(ucdata):
543543
classes[status] = set()
544544
classes[status].add(cp.value)
545545
for status in ['PVALID', 'CONTEXTJ', 'CONTEXTO']:
546-
prefix = ' \'{0}\': '.format(status)
546+
prefix = ' \'{}\': '.format(status)
547547
for line in optimised_list(classes[status]):
548548
yield prefix + line
549549
prefix = ''
@@ -567,9 +567,9 @@ def uts46_ranges(ucdata):
567567
last = (status, mapping)
568568

569569
if mapping is not None:
570-
yield '(0x{0:X}, \'{1}\', \'{2}\')'.format(cp.value, status, mapping)
570+
yield '(0x{:X}, \'{}\', \'{}\')'.format(cp.value, status, mapping)
571571
else:
572-
yield '(0x{0:X}, \'{1}\')'.format(cp.value, status)
572+
yield '(0x{:X}, \'{}\')'.format(cp.value, status)
573573

574574
def uts46_libdata(ucdata):
575575

@@ -585,14 +585,14 @@ def uts46_libdata(ucdata):
585585
if idx % UTS46_SEGMENT_SIZE == 0:
586586
if idx != 0:
587587
yield ' ]\n'
588-
yield 'def _seg_{0}():\n return ['.format(idx // UTS46_SEGMENT_SIZE)
589-
yield ' {0},'.format(row)
588+
yield 'def _seg_{}():\n return ['.format(idx // UTS46_SEGMENT_SIZE)
589+
yield ' {},'.format(row)
590590
yield ' ]\n'
591591

592592
yield 'uts46data = tuple('
593593
yield ' _seg_0()'
594594
for i in range(1, idx // UTS46_SEGMENT_SIZE + 1):
595-
yield ' + _seg_{0}()'.format(i)
595+
yield ' + _seg_{}()'.format(i)
596596
yield ')'
597597

598598
def make_libdata(args, ucdata):
@@ -655,7 +655,7 @@ def main():
655655
elif args.action == 'make-libdata':
656656
make_libdata(args, ucdata)
657657
else:
658-
result = re.match('^(?i)(U\+|)(?P<cp>[0-9A-F]{4,6})$', args.action)
658+
result = re.match(r'^(?i)(U\+|)(?P<cp>[0-9A-F]{4,6})$', args.action)
659659
if result:
660660
codepoint = int(result.group('cp'), 16)
661661
diagnose_codepoint(codepoint, args, ucdata)

0 commit comments

Comments
 (0)