def _validate_format(format, alternative):
 def _parse(string):
  result = []
  for match in PYTHON_FORMAT.finditer(string):
   (name, format, typechar) = match.groups()
   if ((typechar == '%') and (name is None)):
    continue
   result.append((name, str(typechar)))
  return result
 def _compatible(a, b):
  if (a == b):
   return True
  for set in _string_format_compatibilities:
   if ((a in set) and (b in set)):
    return True
  return False
 def _check_positional(results):
  positional = None
  for (name, char) in results:
   if (positional is None):
    positional = (name is None)
   elif ((name is None) != positional):
    raise TranslationError('format string mixes positional and named placeholders')
  return bool(positional)
 (a, b) = map(_parse, (format, alternative))
 (a_positional, b_positional) = map(_check_positional, (a, b))
 if (a_positional and (not b_positional) and (not b)):
  raise TranslationError('placeholders are incompatible')
 elif (a_positional != b_positional):
  raise TranslationError('the format strings are of different kinds')
 if a_positional:
  if (len(a) != len(b)):
   raise TranslationError('positional format placeholders are unbalanced')
  for (idx, ((_, first), (_, second))) in enumerate(izip(a, b)):
   if (not _compatible(first, second)):
    raise TranslationError(('incompatible format for placeholder %d: %r and %r are not compatible' % ((idx + 1), first, second)))
 else:
  type_map = dict(a)
  for (name, typechar) in b:
   if (name not in type_map):
    raise TranslationError(('unknown named placeholder %r' % name))
   elif (not _compatible(typechar, type_map[name])):
    raise TranslationError(('incompatible format for placeholder %r: %r and %r are not compatible' % (name, typechar, type_map[name])))

def _validate_format ( format , alternative ) : def _parse ( string ) : result = [ ] for match in PYTHON_FORMAT . finditer ( string ) : ( name , format , typechar ) = match . groups ( ) if ( ( typechar == '%' ) and ( name is None ) ) : continue result . append ( ( name , str ( typechar ) ) ) return result def _compatible ( a , b ) : if ( a == b ) : return True for set in _string_format_compatibilities : if ( ( a in set ) and ( b in set ) ) : return True return False def _check_positional ( results ) : positional = None for ( name , char ) in results : if ( positional is None ) : positional = ( name is None ) elif ( ( name is None ) != positional ) : raise TranslationError ( 'format string mixes positional and named placeholders' ) return bool ( positional ) ( a , b ) = map ( _parse , ( format , alternative ) ) ( a_positional , b_positional ) = map ( _check_positional , ( a , b ) ) if ( a_positional and ( not b_positional ) and ( not b ) ) : raise TranslationError ( 'placeholders are incompatible' ) elif ( a_positional != b_positional ) : raise TranslationError ( 'the format strings are of different kinds' ) if a_positional : if ( len ( a ) != len ( b ) ) : raise TranslationError ( 'positional format placeholders are unbalanced' ) for ( idx , ( ( _ , first ) , ( _ , second ) ) ) in enumerate ( izip ( a , b ) ) : if ( not _compatible ( first , second ) ) : raise TranslationError ( ( 'incompatible format for placeholder %d: %r and %r are not compatible' % ( ( idx + 1 ) , first , second ) ) ) else : type_map = dict ( a ) for ( name , typechar ) in b : if ( name not in type_map ) : raise TranslationError ( ( 'unknown named placeholder %r' % name ) ) elif ( not _compatible ( typechar , type_map [ name ] ) ) : raise TranslationError ( ( 'incompatible format for placeholder %r: %r and %r are not compatible' % ( name , typechar , type_map [ name ] ) ) )
validates disk_format and container_format fields introduced to split too complex validate_image_meta method .