Revision 0b5303da lib/utils.py

b/lib/utils.py
100 100
 _TIMEOUT_TERM,
101 101
 _TIMEOUT_KILL) = range(3)
102 102

  
103
#: Shell param checker regexp
104
_SHELLPARAM_REGEX = re.compile(r"^[-a-zA-Z0-9._+/:%@]+$")
105

  
106
#: Unit checker regexp
107
_PARSEUNIT_REGEX = re.compile(r"^([.\d]+)\s*([a-zA-Z]+)?$")
108

  
109
#: ASN1 time regexp
110
_ANS1_TIME_REGEX = re.compile(r"^(\d+)([-+]\d\d)(\d\d)$")
111

  
103 112

  
104 113
class RunResult(object):
105 114
  """Holds the result of running external programs.
......
1345 1354
  @return: True if the word is 'safe'
1346 1355

  
1347 1356
  """
1348
  return bool(re.match("^[-a-zA-Z0-9._+/:%@]+$", word))
1357
  return bool(_SHELLPARAM_REGEX.match(word))
1349 1358

  
1350 1359

  
1351 1360
def BuildShellCmd(template, *args):
......
1414 1423
  is always an int in MiB.
1415 1424

  
1416 1425
  """
1417
  m = re.match('^([.\d]+)\s*([a-zA-Z]+)?$', str(input_string))
1426
  m = _PARSEUNIT_REGEX.match(str(input_string))
1418 1427
  if not m:
1419 1428
    raise errors.UnitParseError("Invalid format")
1420 1429

  
......
2805 2814
  @param value: ASN1 GENERALIZEDTIME timestamp
2806 2815

  
2807 2816
  """
2808
  m = re.match(r"^(\d+)([-+]\d\d)(\d\d)$", value)
2817
  m = _ANS1_TIME_REGEX.match(value)
2809 2818
  if m:
2810 2819
    # We have an offset
2811 2820
    asn1time = m.group(1)

Also available in: Unified diff