Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
charset = 'cp1251'
for pattern in stream:
pattern = pattern.decode(charset).strip()
if not pattern or pattern.startswith((
'%', '#', 'LEFTHYPHENMIN', 'RIGHTHYPHENMIN',
'COMPOUNDLEFTHYPHENMIN', 'COMPOUNDRIGHTHYPHENMIN')):
continue
# replace ^^hh with the real character
pattern = parse_hex(
lambda match: chr(int(match.group(1), 16)), pattern)
# read nonstandard hyphen alternatives
if '/' in pattern:
pattern, alternative = pattern.split('/', 1)
factory = AlternativeParser(pattern, alternative)
else:
factory = int
tags, values = zip(*[
(string, factory(i or '0'))
for i, string in parse(pattern)])
# if only zeros, skip this pattern
if max(values) == 0:
continue
# chop zeros from beginning and end, and store start offset
start, end = 0, len(values)
while not values[start]:
start += 1
while not values[end - 1]: