Пример #1
0
class TellSection(types.StaticSection):
    use_private_reminder = types.ValidatedAttribute(
        'use_private_reminder', parse=bool, default=False)
    """When set to ``true``, Sopel will send reminder as private message."""
    maximum_public = types.ValidatedAttribute(
        'maximum_public', parse=int, default=4)
    """How many Sopel can send in public before using private message."""
Пример #2
0
class CurrencySection(types.StaticSection):
    fixer_io_key = types.ValidatedAttribute('fixer_io_key', default=None)
    """Optional API key for Fixer.io (increases currency support)"""
    auto_convert = types.ValidatedAttribute('auto_convert',
                                            parse=bool,
                                            default=False)
    """Whether to convert currencies without an explicit command"""
class AdminSection(types.StaticSection):
    hold_ground = types.ValidatedAttribute('hold_ground', bool, default=False)
    """Auto re-join on kick"""
    auto_accept_invite = types.ValidatedAttribute('auto_accept_invite',
                                                  bool,
                                                  default=True)
    """Auto-join channels when invited"""
class SafetySection(types.StaticSection):
    enabled_by_default = types.ValidatedAttribute('enabled_by_default',
                                                  bool,
                                                  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)."""
Пример #5
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."""
Пример #6
0
def test_validated_serialize():
    option = types.ValidatedAttribute('foo')
    assert option.serialize('string') == 'string'
    assert option.serialize('1') == '1'
    assert option.serialize('') == ''
    assert option.serialize(None) == 'None'  # TODO: empty string instead?
    assert option.serialize(1) == '1'
Пример #7
0
def test_validated_parse_bool():
    option = types.ValidatedAttribute('foo', parse=bool)
    assert option.parse('string') is False
    assert option.parse('1') is True
    assert option.parse('') is False
    assert option.parse(None) is False
    assert option.parse(1) == 1  # TODO: cast as ``True``?

    # true-ish values
    assert option.parse('yes') is True
    assert option.parse('YES') is True
    assert option.parse('yES') is True
    assert option.parse('y') is True
    assert option.parse('Y') is True
    assert option.parse('true') is True
    assert option.parse('True') is True
    assert option.parse('TRUE') is True
    assert option.parse('trUE') is True
    assert option.parse('on') is True
    assert option.parse('ON') is True
    assert option.parse('On') is True

    # everything else
    assert option.parse('no') is False
    assert option.parse('disable') is False
    assert option.parse('disabled') is False
    assert option.parse('enable') is False  # TODO: maybe true-ish?
    assert option.parse('enabled') is False  # TODO: maybe true-ish?
Пример #8
0
def test_validated_parse():
    option = types.ValidatedAttribute('foo')
    assert option.parse('string') == 'string'
    assert option.parse('1') == '1'
    assert option.parse('') == ''
    assert option.parse(None) is None
    assert option.parse(1) == 1
Пример #9
0
def test_validated_serialize_bool_custom():
    def _fixed_serialized(value):
        return 'fixed value'

    option = types.ValidatedAttribute('foo',
                                      parse=bool,
                                      serialize=_fixed_serialized)
    assert option.serialize(True) == 'fixed value'
    assert option.serialize('string') == 'fixed value'
    assert option.serialize('1') == 'fixed value'
    assert option.serialize('') == 'fixed value'
    assert option.serialize(None) == 'fixed value'
    assert option.serialize(1) == 'fixed value'

    # true-ish values
    assert option.serialize('yes') == 'fixed value'
    assert option.serialize('YES') == 'fixed value'
    assert option.serialize('yES') == 'fixed value'
    assert option.serialize('y') == 'fixed value'
    assert option.serialize('Y') == 'fixed value'
    assert option.serialize('true') == 'fixed value'
    assert option.serialize('True') == 'fixed value'
    assert option.serialize('TRUE') == 'fixed value'
    assert option.serialize('trUE') == 'fixed value'
    assert option.serialize('on') == 'fixed value'
    assert option.serialize('ON') == 'fixed value'
    assert option.serialize('On') == 'fixed value'

    # everything else
    assert option.serialize('no') == 'fixed value'
    assert option.serialize('disable') == 'fixed value'
    assert option.serialize('disabled') == 'fixed value'
    assert option.serialize('enable') == 'fixed value'
    assert option.serialize('enabled') == 'fixed value'
Пример #10
0
def test_validated_serialize_bool():
    option = types.ValidatedAttribute('foo', parse=bool)
    assert option.serialize(True) == 'true'
    assert option.serialize('string') == 'false'
    assert option.serialize('1') == 'true'
    assert option.serialize('') == 'false'
    assert option.serialize(None) == 'false'
    assert option.serialize(1) == 'true'

    # true-ish values
    assert option.serialize('yes') == 'true'
    assert option.serialize('YES') == 'true'
    assert option.serialize('yES') == 'true'
    assert option.serialize('y') == 'true'
    assert option.serialize('Y') == 'true'
    assert option.serialize('true') == 'true'
    assert option.serialize('True') == 'true'
    assert option.serialize('TRUE') == 'true'
    assert option.serialize('trUE') == 'true'
    assert option.serialize('on') == 'true'
    assert option.serialize('ON') == 'true'
    assert option.serialize('On') == 'true'

    # everything else
    assert option.serialize('no') == 'false'
    assert option.serialize('disable') == 'false'
    assert option.serialize('disabled') == 'false'
    assert option.serialize('enable') == 'false'  # TODO: maybe true-ish?
    assert option.serialize('enabled') == 'false'  # TODO: maybe true-ish?
Пример #11
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"""
Пример #12
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)
Пример #13
0
class QotdSection(config.StaticSession):
    """
    Base section for configuring qotd module.
    """
    translate_quote = config.ChoiceAttribute(
        'translate_quote', ['true', 'on', '1', 'false', 'off', '0'], 'true')
    language_subdomain = config.ValidatedAttribute('language_subdomain',
                                                   str,
                                                   default='fr')
    enabled = config.ChoiceAttribute('enabled',
                                     ['true', 'on', '1', 'false', 'off', '0'],
                                     'true')
    publishing_time = config.ValidatedAttribute(
        'publishing_time',
        lambda str_value: datetime.datetime.strptime(
            "1900-01-01 {}".format(str_value), "%Y-%m-%d %H:%M:%S").time(),
        default='09:00:00')
Пример #14
0
def test_validated_parse_custom():
    def _fixed_parser(value):
        return 'fixed value'

    option = types.ValidatedAttribute('foo', parse=_fixed_parser)
    assert option.parse('string') == 'fixed value'
    assert option.parse('1') == 'fixed value'
    assert option.parse('') == 'fixed value'
    assert option.parse(None) == 'fixed value'
    assert option.parse(1) == 'fixed value'
Пример #15
0
def test_validated_serialize_custom():
    def _fixed_serialize(value):
        return 'fixed value'

    option = types.ValidatedAttribute('foo', serialize=_fixed_serialize)
    assert option.serialize('string') == 'fixed value'
    assert option.serialize('1') == 'fixed value'
    assert option.serialize('') == 'fixed value'
    assert option.serialize(None) == 'fixed value'
    assert option.serialize(1) == 'fixed value'
Пример #16
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."""
Пример #17
0
class CurrencySection(types.StaticSection):
    fiat_provider = types.ChoiceAttribute('fiat_provider',
                                          list(FIAT_PROVIDERS.keys()),
                                          default='exchangerate.host')
    """Which data provider to use (some of which require no API key)"""
    fixer_io_key = types.ValidatedAttribute('fixer_io_key', default=None)
    """API key for Fixer.io (widest currency support)"""
    fixer_use_ssl = types.BooleanAttribute('fixer_use_ssl', default=False)
    """Whether to use SSL (HTTPS) for Fixer API"""
    auto_convert = types.BooleanAttribute('auto_convert', default=False)
    """Whether to convert currencies without an explicit command"""
class HelpSection(types.StaticSection):
    """Configuration section for this plugin."""
    output = types.ChoiceAttribute('output',
                                   list(PASTEBIN_PROVIDERS),
                                   default='clbin')
    """The pastebin provider to use for help output."""
    reply_method = types.ChoiceAttribute('reply_method',
                                         REPLY_METHODS,
                                         default='channel')
    """Where/how to reply to help commands (public/private)."""
    show_server_host = types.ValidatedAttribute('show_server_host',
                                                bool,
                                                default=True)
    """Show the IRC server's hostname/IP in the first line of the help listing?"""
class MeetbotSection(types.StaticSection):
    """Configuration file section definition"""

    meeting_log_path = types.FilenameAttribute("meeting_log_path",
                                               relative=False,
                                               directory=True,
                                               default="~/www/meetings")
    """Path to meeting logs storage directory.

    This should be an absolute path, accessible on a webserver.
    """

    meeting_log_baseurl = types.ValidatedAttribute(
        "meeting_log_baseurl", default="http://localhost/~sopel/meetings")
    """Base URL for the meeting logs directory."""
Пример #20
0
def test_validated_parse_int():
    option = types.ValidatedAttribute('foo', parse=int)
    assert option.parse('0') == 0
    assert option.parse('1') == 1
    assert option.parse('7814') == 7814
    assert option.parse('-1') == -1
    assert option.parse(1) == 1

    with pytest.raises(ValueError):
        option.parse('785.56')

    with pytest.raises(ValueError):
        option.parse('string')

    with pytest.raises(ValueError):
        option.parse('')

    with pytest.raises(TypeError):
        option.parse(None)
Пример #21
0
class RatbotConfigurationSection(StaticSection):
    apiurl = types.ValidatedAttribute('apiurl', str, default='')
    apitoken = types.ValidatedAttribute('apitoken', str, default='a')
    workdir = types.FilenameAttribute('workdir', directory=True, default='run')
    alembic = types.FilenameAttribute('alembic',
                                      directory=False,
                                      default='alembic.ini')
    debug_sql = BooleanAttribute('debug_sql', default=False)
    edsm_url = types.ValidatedAttribute(
        'edsm_url', str, default="http://edsm.net/api-v1/systems?coords=1")
    edsm_maxage = types.ValidatedAttribute('edsm_maxage',
                                           int,
                                           default=12 * 60 * 60)
    edsm_autorefresh = types.ValidatedAttribute('edsm_autorefresh',
                                                int,
                                                default=4 * 60 * 60)
    edsm_db = types.ValidatedAttribute('edsm_db', str, default="systems.db")
    websocketurl = types.ValidatedAttribute('websocketurl', str, default='12')
    websocketport = types.ValidatedAttribute('websocketport',
                                             str,
                                             default='9000')
    shortenerurl = types.ValidatedAttribute('shortenerurl', str, default='')
    shortenertoken = types.ValidatedAttribute('shortenertoken',
                                              str,
                                              default='asdf')
    debug_channel = types.ValidatedAttribute('debug_channel',
                                             str,
                                             default='#mechadeploy')
    chunked_systems = BooleanAttribute(
        'chunked_systems',
        default=True)  # Should be edsm_chunked_systems to fit others
    hastebin_url = types.ValidatedAttribute('hastebin_url',
                                            'str',
                                            default="http://hastebin.com/")
Пример #22
0
class WikipediaSection(types.StaticSection):
    default_lang = types.ValidatedAttribute('default_lang', default='en')
    """The default language to find articles from (same as Wikipedia language subdomain)."""
Пример #23
0
class WikipediaSection(types.StaticSection):
    default_lang = types.ValidatedAttribute('default_lang', default='en')
    """The default language to find articles from (same as Wikipedia language subdomain)."""
    lang_per_channel = types.ValidatedAttribute('lang_per_channel')
    """List of ``#channel:langcode`` pairs to define Wikipedia language per channel.
Пример #24
0
class FakeConfigSection(types.StaticSection):
    attr = types.ValidatedAttribute('attr')
Пример #25
0
class PySection(types.StaticSection):
    oblique_instance = types.ValidatedAttribute(
        'oblique_instance', default='https://oblique.sopel.chat/')
    """The Oblique instance to use when evaluating Python expressions"""
Пример #26
0
def test_validated_attribute():
    option = types.ValidatedAttribute('foo')
    assert option.name == 'foo'
    assert option.default is None
    assert option.is_secret is False