def test_list_serialize_quote():
    option = types.ListAttribute('foo')
    assert option.serialize(['value 1', '# value 2',
                             'value 3']) == ('\n'
                                             'value 1\n'
                                             '"# value 2"\n'
                                             'value 3')
def test_list_parse_legacy_comma_no_strip():
    option = types.ListAttribute('foo', strip=False)
    assert option.parse("""value 1, # value 2   ,   value 3""") == [
        'value 1',
        ' # value 2   ',
        '   value 3',
    ]
Beispiel #3
0
class SafetySection(types.StaticSection):
    enabled_by_default = types.BooleanAttribute('enabled_by_default',
                                                default=True)
    """Whether to enable URL safety in all channels where it isn't explicitly disabled."""
    known_good = types.ListAttribute('known_good')
    """List of "known good" domains to ignore."""
    vt_api_key = types.ValidatedAttribute('vt_api_key')
    """Optional VirusTotal API key (improves malicious URL detection)."""
Beispiel #4
0
class FakeConfigSection(types.StaticSection):
    valattr = types.ValidatedAttribute('valattr')
    listattr = types.ListAttribute('listattr')
    choiceattr = types.ChoiceAttribute('choiceattr', ['spam', 'egg', 'bacon'])
    af_fileattr = types.FilenameAttribute('af_fileattr', relative=False, directory=False)
    ad_fileattr = types.FilenameAttribute('ad_fileattr', relative=False, directory=True)
    rf_fileattr = types.FilenameAttribute('rf_fileattr', relative=True, directory=False)
    rd_fileattr = types.FilenameAttribute('rd_fileattr', relative=True, directory=True)
def test_list_serialize_value_error():
    option = types.ListAttribute('foo')

    with pytest.raises(ValueError):
        option.serialize('value 1')

    with pytest.raises(ValueError):
        option.serialize(('1', '2', '3'))  # tuple is not allowed
def test_list_parse_new_lines_legacy_comma():
    option = types.ListAttribute('foo')
    assert option.parse("""
        value 1, value 2,
        value 3
    """) == [
        'value 1, value 2',
        'value 3',
    ]
def test_list_serialize():
    option = types.ListAttribute('foo')
    assert option.serialize([]) == ''
    assert option.serialize(['value 1', 'value 2', 'value 3']) == ('\n'
                                                                   'value 1\n'
                                                                   'value 2\n'
                                                                   'value 3')

    assert option.serialize(set()) == ''
    assert option.serialize(set(
        ['1', '2', '3'])) == ('\n' + '\n'.join(set(['1', '2', '3'])))
def test_list_parse_new_lines():
    option = types.ListAttribute('foo')
    assert option.parse("""
    value 1
    "# value 2"
    value 3
    """) == [
        'value 1',
        '# value 2',
        'value 3',
    ]
def test_list_parse_single_value():
    option = types.ListAttribute('foo')
    assert option.parse('string') == ['string']
    assert option.parse('1') == ['1']
    assert option.parse('') == []

    with pytest.raises(TypeError):
        option.parse(None)

    with pytest.raises(TypeError):
        option.parse(1)
Beispiel #10
0
class RainbowSection(types.StaticSection):
    order = types.ListAttribute('order', default=[4, 7, 8, 3, 12, 2, 6])
    """The order of color codes to use.

    Defaults to a standard ROYGBIV rainbow (assuming readers' clients use
    typical IRC color code mappings).
    """
    random_start = types.ValidatedAttribute('random_start',
                                            bool,
                                            default=False)
    """Whether to randomize the start color."""
Beispiel #11
0
class SafetySection(types.StaticSection):
    enabled_by_default = types.BooleanAttribute("enabled_by_default",
                                                default=True)
    """Deprecated: Sets default_mode to "off" or "on"."""
    default_mode = types.ValidatedAttribute("default_mode")
    """Which mode to use in channels without a mode set."""
    known_good = types.ListAttribute('known_good')
    """List of "known good" domains or regexes to consider trusted."""
    vt_api_key = types.ValidatedAttribute('vt_api_key')
    """Optional VirusTotal API key (improves malicious URL detection)."""
    domain_blocklist_url = types.ValidatedAttribute("domain_blocklist_url")
    """Optional hosts-file formatted domain blocklist to use instead of StevenBlack's."""
Beispiel #12
0
def test_list_parse_new_lines_no_strip():
    option = types.ListAttribute('foo', strip=False)
    # strip isn't used for newline-based list attribute
    assert option.parse("""
    value 1
    "# value 2"
    value 3
    """) == [
        'value 1',
        '# value 2',
        'value 3',
    ]
Beispiel #13
0
class UrlSection(types.StaticSection):
    enable_auto_title = types.BooleanAttribute('enable_auto_title',
                                               default=True)
    """Enable auto-title (enabled by default)"""
    # TODO some validation rules maybe?
    exclude = types.ListAttribute('exclude')
    """A list of regular expressions to match URLs for which the title should not be shown."""
    exclusion_char = types.ValidatedAttribute('exclusion_char', default='!')
    """A character (or string) which, when immediately preceding a URL, will stop that URL's title from being shown."""
    shorten_url_length = types.ValidatedAttribute('shorten_url_length',
                                                  int,
                                                  default=0)
    """If greater than 0, the title fetcher will include a TinyURL version of links longer than this many characters."""
    enable_private_resolution = types.BooleanAttribute(
        'enable_private_resolution', default=False)
    """Enable requests to private and local network IP addresses"""
Beispiel #14
0
class BugzillaSection(types.StaticSection):
    domains = types.ListAttribute('domains')
    """A list of Bugzilla issue tracker domains from which to get information."""
Beispiel #15
0
class SpamSection(types.StaticSection):
    eggs = types.ListAttribute('eggs')
    bacons = types.ListAttribute('bacons', strip=False)
    cheeses = types.ListAttribute('cheeses')
    channels = types.ListAttribute('channels')
Beispiel #16
0
def test_list_attribute():
    option = types.ListAttribute('foo')
    assert option.name == 'foo'
    assert option.default == []
    assert option.is_secret is False