components/safe_browsing/content/resources/gen_file_type_proto.py
def FilterPbForPlatform(full_pb, platform_type):
    """ Return a filtered protobuf for this platform_type """
    assert type(platform_type) is int, "Bad platform_type type"

    new_pb = download_file_types_pb2.DownloadFileTypeConfig()
    new_pb.CopyFrom(full_pb)

    # Ensure there's only one platform_settings for the default.
    PrunePlatformSettings(new_pb.default_file_type, None, platform_type)

    # This can be extended if we want to match weird extensions.
    # Just no dots, non-UTF8, or uppercase chars.
    invalid_char_re = re.compile('[^a-z0-9_-]')

    # Filter platform_settings for each type.
    uma_values_used = set()
    extensions_used = set()
    for file_type in new_pb.file_types:
        assert not invalid_char_re.search(file_type.extension), (
            "File extension '%s' contains non alpha-num-dash chars" %
            (file_type.extension))
        assert file_type.extension not in extensions_used, (
            "Duplicate extension '%s'" % file_type.extension)
        extensions_used.add(file_type.extension)

        assert file_type.uma_value not in uma_values_used, (
            "Extension '%s' reused UMA value %d." %
            (file_type.extension, file_type.uma_value))
        uma_values_used.add(file_type.uma_value)

        # Modify file_type to include only the best match platform_setting.
        PrunePlatformSettings(
            file_type, new_pb.default_file_type.platform_settings[0], \
              platform_type)

    return new_pb
 Return a filtered protobuf for this platform_type 
Return a filtered protobuf for this platform_type
Return a filtered protobuf for this platform_type
def FilterPbForPlatform(full_pb, platform_type):
    assert type(platform_type) is int, "Bad platform_type type"
    new_pb = download_file_types_pb2.DownloadFileTypeConfig()
    new_pb.CopyFrom(full_pb)
    PrunePlatformSettings(new_pb.default_file_type, None, platform_type)
    invalid_char_re = re.compile('[^a-z0-9_-]')
    uma_values_used = set()
    extensions_used = set()
    for file_type in new_pb.file_types:
        assert not invalid_char_re.search(file_type.extension), (
            "File extension '%s' contains non alpha-num-dash chars" %
            (file_type.extension))
        assert file_type.extension not in extensions_used, (
            "Duplicate extension '%s'" % file_type.extension)
        extensions_used.add(file_type.extension)
        assert file_type.uma_value not in uma_values_used, (
            "Extension '%s' reused UMA value %d." %
            (file_type.extension, file_type.uma_value))
        uma_values_used.add(file_type.uma_value)
        PrunePlatformSettings(
            file_type, new_pb.default_file_type.platform_settings[0], \
              platform_type)
    return new_pb
def FilterPbForPlatform ( full_pb , platform_type ) : assert type ( platform_type ) is int , "Bad platform_type type" new_pb = download_file_types_pb2 . DownloadFileTypeConfig ( ) new_pb . CopyFrom ( full_pb ) PrunePlatformSettings ( new_pb . default_file_type , None , platform_type ) invalid_char_re = re . compile ( '[^a-z0-9_-]' ) uma_values_used = set ( ) extensions_used = set ( ) for file_type in new_pb . file_types : assert not invalid_char_re . search ( file_type . extension ) , ( "File extension '%s' contains non alpha-num-dash chars" % ( file_type . extension ) ) assert file_type . extension not in extensions_used , ( "Duplicate extension '%s'" % file_type . extension ) extensions_used . add ( file_type . extension ) assert file_type . uma_value not in uma_values_used , ( "Extension '%s' reused UMA value %d." % ( file_type . extension , file_type . uma_value ) ) uma_values_used . add ( file_type . uma_value ) PrunePlatformSettings ( file_type , new_pb . default_file_type . platform_settings [ 0 ] , platform_type ) return new_pb
Return a filtered protobuf for this platform_type
Return a filtered protobuf for this platform_type
""" Return a filtered protobuf for this platform_type """ # Ensure there's only one platform_settings for the default. # This can be extended if we want to match weird extensions. # Just no dots, non-UTF8, or uppercase chars. # Filter platform_settings for each type. # Modify file_type to include only the best match platform_setting.
full_pb
platform_type