# (c) 2002 by Gerfried Fuchs use Irssi qw(command_bind command signal_add_last signal_stop settings_get_bool settings_add_bool); use strict; use vars qw($VERSION %IRSSI); $VERSION = '2.3.1'; %IRSSI = ( 'authors' => 'Gerfried Fuchs', 'contact' => 'alfie@channel.debian.de', 'name' => 'kenny speech', 'description' => 'autodekennyfies /kenny, adds /kenny, /dekenny. Based on Jan-Pieter Cornets signature version', 'license' => 'BSD', 'url' => 'http://alfie.ist.org/projects/irssi/scripts/kenny.pl', 'changed' => '2002-06-13', ); # Maintainer & original Author: Gerfried Fuchs # Based on signature kenny from: Jan-Pieter Cornet # Autodekenny-suggestion: BC-bd # Sugguestions from darix: Add <$nick> to [kenny] line patch # This script offers you /kenny and /dekenny which both do the kenny-filter # magic on the argument you give it. Despite it's name *both* do kenny/dekenny # the argument; the difference is that /kenny writes it to the channel/query # but /dekenny only to your screen. # Version-History: # ================ # 2.3.1 -- fixed autodekenny in channels for people != yourself # # 2.3.0 -- fixed kenny in querys # fixed dekenny in status window # # 2.2.3 -- fixed pattern matching for autokenny string ("\w" != "a-z" :/) # # 2.2.2 -- first version available to track history from... # TODO List # ... currently empty sub KennyIt { ($_)=@_;my($p,$f);$p=3-2*/[^\W\dmpf_]/i;s.[a-z]{$p}.vec($f=join('',$p-1?chr( sub{$_[0]*9+$_[1]*3+$_[2] }->(map {/p|f/i+/f/i}split//,$&)+97):('m','p','f') [map{((ord$&)%32-1)/$_%3}(9, 3,1)]),5,1)='`'lt$&;$f.eig;return ($_); }; sub cmd_kenny { my ($msg, undef, $channel) = @_; $channel->command("msg $channel->{'name'} ".KennyIt($msg)); } sub cmd_dekenny { my ($msg, undef, $channel) = @_; if ($channel) { $channel->print('[kenny] '.KennyIt($msg), MSGLEVEL_CRAP); } else { Irssi::print('[kenny] '.KennyIt($msg), MSGLEVEL_CRAP); } } sub sig_kenny { my ($server, $msg, $nick, $address, $target) = @_; if ($msg=~m/^[^a-z]*[mfp]{3}(?:[^a-z]|[mfp]{3})+$/i) { $target=$nick if $target eq ""; # the address may _never_ be emtpy, if it is its own_public $nick=$server->{'nick'} if $address eq ""; $server->window_item_find($target)->print("[kenny] <$nick> " . KennyIt($msg), MSGLEVEL_CRAP); signal_stop if not settings_get_bool('show_kenny_too'); } } command_bind('kenny', 'cmd_kenny'); command_bind('dekenny', 'cmd_dekenny'); signal_add_last('message own_public', 'sig_kenny'); signal_add_last('message public', 'sig_kenny'); signal_add_last('message own_private', 'sig_kenny'); signal_add_last('message private', 'sig_kenny'); settings_add_bool('lookandfeel', 'show_kenny_too', 0); 9d1355b39e55748cc041759afec'/>
blob: 34e9fe0fd99f76e6ddc7894dad2558faff069faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Copyright (C) 2008 Andi Albrecht, albrecht.andi@gmail.com
#
# This module is part of python-sqlparse and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php.

"""SQL formatter"""

from debug_toolbar.utils.sqlparse import SQLParseError
from debug_toolbar.utils.sqlparse import filters


def validate_options(options):
    """Validates options."""
    kwcase = options.get('keyword_case', None)
    if kwcase not in [None, 'upper', 'lower', 'capitalize']:
        raise SQLParseError('Invalid value for keyword_case: %r' % kwcase)

    idcase = options.get('identifier_case', None)
    if idcase not in [None, 'upper', 'lower', 'capitalize']:
        raise SQLParseError('Invalid value for identifier_case: %r' % idcase)

    ofrmt = options.get('output_format', None)
    if ofrmt not in [None, 'sql', 'python', 'php']:
        raise SQLParseError('Unknown output format: %r' % ofrmt)

    strip_comments = options.get('strip_comments', False)
    if strip_comments not in [True, False]:
        raise SQLParseError('Invalid value for strip_comments: %r'
                            % strip_comments)

    strip_ws = options.get('strip_whitespace', False)
    if strip_ws not in [True, False]:
        raise SQLParseError('Invalid value for strip_whitespace: %r'
                            % strip_ws)

    reindent = options.get('reindent', False)
    if reindent not in [True, False]:
        raise SQLParseError('Invalid value for reindent: %r'
                            % reindent)
    elif reindent:
        options['strip_whitespace'] = True
    indent_tabs = options.get('indent_tabs', False)
    if indent_tabs not in [True, False]:
        raise SQLParseError('Invalid value for indent_tabs: %r' % indent_tabs)
    elif indent_tabs:
        options['indent_char'] = '\t'
    else:
        options['indent_char'] = ' '
    indent_width = options.get('indent_width', 2)
    try:
        indent_width = int(indent_width)
    except (TypeError, ValueError):
        raise SQLParseError('indent_width requires an integer')
    if indent_width < 1:
        raise SQLParseError('indent_width requires an positive integer')
    options['indent_width'] = indent_width

    right_margin = options.get('right_margin', None)
    if right_margin is not None:
        try:
            right_margin = int(right_margin)
        except (TypeError, ValueError):
            raise SQLParseError('right_margin requires an integer')
        if right_margin < 10:
            raise SQLParseError('right_margin requires an integer > 10')
    options['right_margin'] = right_margin

    return options


def build_filter_stack(stack, options):
    """Setup and return a filter stack.

    Args:
      stack: :class:`~sqlparse.filters.FilterStack` instance
      options: Dictionary with options validated by validate_options.
    """
    # Token filter
    if 'keyword_case' in options:
        stack.preprocess.append(
            filters.KeywordCaseFilter(options['keyword_case']))

    if 'identifier_case' in options:
        stack.preprocess.append(
            filters.IdentifierCaseFilter(options['identifier_case']))

    # After grouping
    if options.get('strip_comments', False):
        stack.enable_grouping()
        stack.stmtprocess.append(filters.StripCommentsFilter())

    if (options.get('strip_whitespace', False)
        or options.get('reindent', False)):
        stack.enable_grouping()
        stack.stmtprocess.append(filters.StripWhitespaceFilter())

    if options.get('reindent', False):
        stack.enable_grouping()
        stack.stmtprocess.append(
            filters.ReindentFilter(char=options['indent_char'],
                                   width=options['indent_width']))

    if options.get('right_margin', False):
        stack.enable_grouping()
        stack.stmtprocess.append(
            filters.RightMarginFilter(width=options['right_margin']))

    # Serializer
    if options.get('output_format'):
        frmt = options['output_format']
        if frmt.lower() == 'php':
            fltr = filters.OutputPHPFilter()
        elif frmt.lower() == 'python':
            fltr = filters.OutputPythonFilter()
        else:
            fltr = None
        if fltr is not None:
            stack.postprocess.append(fltr)

    return stack