Skip to content

Fix invalid and unintended regex escape sequences #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion brukerapi/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def _eval_conditions(self, conditions):

def _sub_parameters(self, recipe):
# entries with property e.g. VisuFGOrderDesc.nested to self._dataset['VisuFGOrderDesc'].nested
for match in re.finditer('#[a-zA-Z0-9_]+\.[a-zA-Z]+', recipe):
for match in re.finditer(r'#[a-zA-Z0-9_]+\.[a-zA-Z]+', recipe):
m = re.match('#[a-zA-Z0-9_]+', match.group())
recipe = recipe.replace(m.group(),"self['{}']".format(m.group()[1:]))
# entries without property e.g. VisuFGOrderDesc to self._dataset['VisuFGOrderDesc'].value
Expand Down
40 changes: 20 additions & 20 deletions brukerapi/jcampdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

SUPPORTED_VERSIONS = ['4.24', '5.0', '5.00 Bruker JCAMP library', '5.00 BRUKER JCAMP library', '5.01']
GRAMMAR = {
'COMMENT_LINE' : '\$\$[^\n]*\n',
'COMMENT_LINE' : r'\$\$[^\n]*\n',
'PARAMETER': '##',
'USER_DEFINED' : '\$',
'TRAILING_EOL' : '\n$',
'DATA_LABEL' : '\(XY..XY\)',
'DATA_DELIMETERS':', |\n',
'SIZE_BRACKET': '^\([^\(\)<>]*\)(?!$)',
'USER_DEFINED' : r'\$',
'TRAILING_EOL' : r'\n$',
'DATA_LABEL' : r'\(XY..XY\)',
'DATA_DELIMETERS': r', |\n',
'SIZE_BRACKET': r'^\([^\(\)<>]*\)(?!$)',
'LIST_DELIMETER': ', ',
'EQUAL_SIGN': '=',
'SINGLE_NUMBER':'-?[\d.]+(?:e[+-]?\d+)?',
'PARALLEL_BRACKET': '\) ',
'GEO_OBJ': '\(\(\([\s\S]*\)[\s\S]*\)[\s\S]*\)',
'SINGLE_NUMBER': r'-?[\d.]+(?:e[+-]?\d+)?',
'PARALLEL_BRACKET': r'\) ',
'GEO_OBJ': r'\(\(\([\s\S]*\)[\s\S]*\)[\s\S]*\)',
'HEADER':'TITLE|JCAMPDX|JCAMP-DX|DATA TYPE|DATATYPE|ORIGIN|OWNER',
'VERSION_TITLE':'JCAMPDX|JCAMP-DX'
}
Expand Down Expand Up @@ -107,7 +107,7 @@ def _encode_parameter(self, var):

@property
def key(self):
return re.sub('##', '', re.sub('\$', '', self.key_str)).rstrip()
return re.sub('##', '', re.sub(r'\$', '', self.key_str)).rstrip()

@key.setter
def key(self, key):
Expand Down Expand Up @@ -203,10 +203,10 @@ def from_values(cls, version, key, size, value, user_defined):
@property
def value(self, **kwargs):

val_str = re.sub('\n', '', self.val_str)
val_str = re.sub(r'\n', '', self.val_str)

# unwrap wrapped list
if re.match('@[0-9]*\*',val_str) is not None:
if re.match(r'@[0-9]*\*',val_str) is not None:
val_str = self._unwrap_list(val_str)

val_str_list = GenericParameter.split_parallel_lists(val_str)
Expand Down Expand Up @@ -318,7 +318,7 @@ def size(self, size):
@classmethod
def parse_value(cls, val_str, size_bracket=None):
# remove \n
val_str = re.sub('\n','', val_str)
val_str = re.sub(r'\n','', val_str)

# sharp string
if val_str.startswith('<') and val_str.endswith('>'):
Expand Down Expand Up @@ -455,12 +455,12 @@ def restore_right_bra(string):

def _unwrap_list(self, val_str):

while re.search('@[0-9]*\*\(\d*\.?\d*\)', val_str):
match = re.search('@[0-9]*\*\(\d*\.?\d*\)', val_str)
while re.search(r'@[0-9]*\*\(\d*\.?\d*\)', val_str):
match = re.search(r'@[0-9]*\*\(\d*\.?\d*\)', val_str)
left = val_str[0:match.start()]
right = val_str[match.end():]
sub = val_str[match.start():match.end()]
size, value = re.split('\*', sub)
size, value = re.split(r'\*', sub)
size = int(size[1:])
middle = ''
for i in range(size):
Expand Down Expand Up @@ -506,7 +506,7 @@ def value(self):
# :return: 4x4 3D Affine Transformation Matrix
# """
# # TODO support for multiple slice packages
# match = re.match('\(\(\([^\)]*\)', self.val_str)
# match = re.match(r'\(\(\([^\)]*\)', self.val_str)
# affine_str = self.val_str[match.start() + 3: match.end() - 1]
# orient, shift = affine_str.split(', ')
#
Expand Down Expand Up @@ -799,7 +799,7 @@ def load_parameter(cls, path, key):
except:
raise InvalidJcampdxFile(path)

match = re.search('##{}[^\#\$]+|##\${}[^\#\$]+'.format(key,key), content)
match = re.search(r'##{}[^\#\$]+|##\${}[^\#\$]+'.format(key,key), content)

if match == None:
raise ParameterNotFound(key, path)
Expand Down Expand Up @@ -903,10 +903,10 @@ def strip_size_bracket(cls, val_str):

@classmethod
def wrap_lines(cls, line):
line_wraps = re.split('\n', line)
line_wraps = re.split(r'\n', line)
tail = line_wraps[-1]

tail_bits = re.split('\s', tail)
tail_bits = re.split(r'\s', tail)

lines = 1
tail = ''
Expand Down