def parse_redaction_policy_from_file(filename):
 with open(filename) as f:
  s = f.read().strip()
  if (not s):
   return RedactionPolicy([])
  scheme = json.loads(s)
  try:
   version = str(scheme.pop('version'))
  except KeyError:
   raise ValueError('Redaction policy is missing `version` field')
  if (version != '1'):
   raise ValueError(('unknown version `%s`' % version))
  try:
   rules = scheme.pop('rules')
  except KeyError:
   raise ValueError('Redaction policy is missing `rules` field')
  rules = [parse_one_rule_from_dict(rule) for rule in rules]
  if scheme:
   raise ValueError(('Redaction policy contains unknown field(s): %s' % scheme.keys()))
  return RedactionPolicy(rules)

def parse_redaction_policy_from_file ( filename ) : with open ( filename ) as f : s = f . read ( ) . strip ( ) if ( not s ) : return RedactionPolicy ( [ ] ) scheme = json . loads ( s ) try : version = str ( scheme . pop ( 'version' ) ) except KeyError : raise ValueError ( 'Redaction policy is missing `version` field' ) if ( version != '1' ) : raise ValueError ( ( 'unknown version `%s`' % version ) ) try : rules = scheme . pop ( 'rules' ) except KeyError : raise ValueError ( 'Redaction policy is missing `rules` field' ) rules = [ parse_one_rule_from_dict ( rule ) for rule in rules ] if scheme : raise ValueError ( ( 'Redaction policy contains unknown field(s): %s' % scheme . keys ( ) ) ) return RedactionPolicy ( rules )
parse a file into a redactionpolicy .