tools/media_engagement_preload/make_dafsa.py
def parse_json(infile):
  """Parses the JSON input file and appends a 0 or 1 based on protocol."""
  try:
    netlocs = {}
    for entry in json.loads(infile):
      # Parse the origin and reject any with an invalid protocol.
      parsed = urllib.parse.urlparse(entry)
      if parsed.scheme != 'http' and parsed.scheme != 'https':
        raise InputError('Invalid protocol: %s' % entry)

      # Store the netloc in netlocs with a flag for either HTTP+HTTPS or HTTPS
      # only. The HTTP+HTTPS value is numerically higher than HTTPS only so it
      # will take priority.
      netlocs[parsed.netloc] = max(
          netlocs.get(parsed.netloc, HTTPS_ONLY),
          HTTP_AND_HTTPS if parsed.scheme == 'http' else HTTPS_ONLY)

    # Join the numerical values to the netlocs.
    output = []
    for location, value in netlocs.items():
      output.append(location + str(value))
    return output
  except ValueError:
    raise InputError('Failed to parse JSON.')
Parses the JSON input file and appends a 0 or 1 based on protocol.
Parses the JSON input file and appends a 0 or 1 based on protocol.
Parses the JSON input file and appends a 0 or 1 based on protocol .
def parse_json(infile):
  try:
    netlocs = {}
    for entry in json.loads(infile):
      parsed = urllib.parse.urlparse(entry)
      if parsed.scheme != 'http' and parsed.scheme != 'https':
        raise InputError('Invalid protocol: %s' % entry)
      netlocs[parsed.netloc] = max(
          netlocs.get(parsed.netloc, HTTPS_ONLY),
          HTTP_AND_HTTPS if parsed.scheme == 'http' else HTTPS_ONLY)
    output = []
    for location, value in netlocs.items():
      output.append(location + str(value))
    return output
  except ValueError:
    raise InputError('Failed to parse JSON.')
def parse_json ( infile ) : try : netlocs = { } for entry in json . loads ( infile ) : parsed = urllib . parse . urlparse ( entry ) if parsed . scheme != 'http' and parsed . scheme != 'https' : raise InputError ( 'Invalid protocol: %s' % entry ) netlocs [ parsed . netloc ] = max ( netlocs . get ( parsed . netloc , HTTPS_ONLY ) , HTTP_AND_HTTPS if parsed . scheme == 'http' else HTTPS_ONLY ) output = [ ] for location , value in netlocs . items ( ) : output . append ( location + str ( value ) ) return output except ValueError : raise InputError ( 'Failed to parse JSON.' )
Parses the JSON input file and appends a 0 or 1 based on protocol.
Parses the JSON input file and appends a 0 or 1 based on protocol .
"""Parses the JSON input file and appends a 0 or 1 based on protocol.""" # Parse the origin and reject any with an invalid protocol. # Store the netloc in netlocs with a flag for either HTTP+HTTPS or HTTPS # only. The HTTP+HTTPS value is numerically higher than HTTPS only so it # will take priority. # Join the numerical values to the netlocs.
infile