Python pygments.token.Keyword() Examples

The following are 30 code examples of pygments.token.Keyword(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pygments.token , or try the search function .
Example #1
Source File: toolbar.py    From kube-shell with Apache License 2.0 6 votes vote down vote up
def _create_toolbar_handler(self, get_cluster_name, get_namespace, get_user, get_inline_help):
        def get_toolbar_items(_):
            if get_inline_help():
                help_token = Token.Toolbar.On
                help = "ON"
            else:
                help_token = Token.Toolbar.Off
                help = "OFF"

            return [
                (Keyword, ' [F4] Cluster: '),
                (Token.Toolbar, get_cluster_name()),
                (Keyword, ' [F5] Namespace: '),
                (Token.Toolbar, get_namespace()),
                (Keyword, ' User: '),
                (Token.Toolbar, get_user()),
                (Keyword, ' [F9] In-line help: '),
                (help_token, '{0}'.format(help)),
                (Keyword, ' [F10] Exit ')
            ]

        return get_toolbar_items 
Example #2
Source File: test_kotlin.py    From pygments with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_can_cope_with_destructuring(lexer):
    fragment = u'val (a, b) = '
    tokens = [
        (Keyword, u'val'),
        (Text, u' '),
        (Punctuation, u'('),
        (Name.Property, u'a'),
        (Punctuation, u','),
        (Text, u' '),
        (Name.Property, u'b'),
        (Punctuation, u')'),
        (Text, u' '),
        (Punctuation, u'='),
        (Text, u' '),
        (Text, u'\n')
    ]
    assert list(lexer.get_tokens(fragment)) == tokens 
Example #3
Source File: test_java.py    From pygments with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_enhanced_for(lexer):
    fragment = u'label:\nfor(String var2: var1) {}\n'
    tokens = [
        (Name.Label, u'label:'),
        (Text, u'\n'),
        (Keyword, u'for'),
        (Punctuation, u'('),
        (Name, u'String'),
        (Text, u' '),
        (Name, u'var2'),
        (Punctuation, u':'),
        (Text, u' '),
        (Name, u'var1'),
        (Punctuation, u')'),
        (Text, u' '),
        (Punctuation, u'{'),
        (Punctuation, u'}'),
        (Text, u'\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens 
Example #4
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_write_without_spaces(self):
        self.assertEqual(self.get_tokens('httpie>file.txt'), [
            (Keyword, 'httpie'),
            (Operator, '>'), (String, 'file.txt')
        ]) 
Example #5
Source File: lexer.py    From rpl-attacks with GNU Affero General Public License v3.0 5 votes vote down vote up
def analyze(self, text):
        if any([token is Error for token, value in self.get_tokens(text)]):
            return 2 * (None, )
        tokens, args, kwargs = self.get_tokens(text), [], {}
        for token, value in tokens:
            if token is Keyword:
                token = token in ['true', 'True']
            elif token is Number:
                token = int(token)
            if token in (Keyword, Number, String):
                args.append(value)
            if token is Name:
                next(tokens)  # pass the Operator '='
                kwargs.update({value: next(tokens)[1]})
        return args, kwargs 
Example #6
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_append(self):
        self.assertEqual(self.get_tokens('httpie >> file.txt'), [
            (Keyword, 'httpie'),
            (Operator, '>>'), (String, 'file.txt')
        ]) 
Example #7
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_write_with_post_param(self):
        self.assertEqual(self.get_tokens('httpie post name=jack > file.txt'), [
            (Keyword, 'httpie'), (Keyword, 'post'),
            (Name, 'name'), (Operator, '='), (String, 'jack'),
            (Operator, '>'), (String, 'file.txt')
        ]) 
Example #8
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_append_with_post_param(self):
        self.assertEqual(self.get_tokens('httpie post name=doe >> file.txt'), [
            (Keyword, 'httpie'), (Keyword, 'post'),
            (Name, 'name'), (Operator, '='), (String, 'doe'),
            (Operator, '>>'), (String, 'file.txt')
        ]) 
Example #9
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_write_quoted_filename(self):
        self.assertEqual(self.get_tokens("httpie > 'my file.txt'"), [
            (Keyword, 'httpie'), (Operator, '>'),
            (Text, "'"), (String, 'my file.txt'), (Text, "'")
        ]) 
Example #10
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_append_quoted_filename(self):
        self.assertEqual(self.get_tokens('httpie >> "my file.txt"'), [
            (Keyword, 'httpie'), (Operator, '>>'),
            (Text, '"'), (String, 'my file.txt'), (Text, '"')
        ]) 
Example #11
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_post_with_body_params(self):
        command = 'post name="john doe" username=john'
        self.assertEqual(self.get_tokens(command), [
            (Keyword, 'post'), (Name, 'name'), (Operator, '='),
            (Text, '"'), (String, 'john doe'), (Text, '"'),
            (Name, 'username'), (Operator, '='), (String, 'john')
        ]) 
Example #12
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_capital_head(self):
        self.assertEqual(self.get_tokens('HEAD'), [
            (Keyword, 'HEAD')
        ]) 
Example #13
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_patch(self):
        self.assertEqual(self.get_tokens('patch'), [
            (Keyword, 'patch')
        ]) 
Example #14
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_get_with_querystring_params(self):
        command = 'get page==10 id==200'
        self.assertEqual(self.get_tokens(command), [
            (Keyword, 'get'),
            (Name, 'page'), (Operator, '=='), (String, '10'),
            (Name, 'id'), (Operator, '=='), (String, '200')
        ]) 
Example #15
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_capital_get_with_querystring_params(self):
        command = 'GET page==10 id==200'
        self.assertEqual(self.get_tokens(command), [
            (Keyword, 'GET'),
            (Name, 'page'), (Operator, '=='), (String, '10'),
            (Name, 'id'), (Operator, '=='), (String, '200')
        ]) 
Example #16
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_post_relative_path(self):
        tokens = self.get_tokens('post /api/test name=foo',
                                 filter_spaces=False)
        self.assertEqual(tokens, [
            (Keyword, 'post'), (Text, ' '),
            (String, '/api/test'), (Text, ' '),
            (Name, 'name'), (Operator, '='), (String, 'foo'),
            (Text, '\n')
        ]) 
Example #17
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_exec_quoted_filename(self):
        self.assertEqual(self.get_tokens("exec '/tmp/my file.txt'"), [
            (Keyword, 'exec'),
            (Text, "'"), (String, '/tmp/my file.txt'), (Text, "'")
        ]) 
Example #18
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_write(self):
        self.assertEqual(self.get_tokens('httpie > file.txt'), [
            (Keyword, 'httpie'),
            (Operator, '>'), (String, 'file.txt')
        ]) 
Example #19
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_post_pipe(self):
        self.assertEqual(self.get_tokens('post | tee "/tmp/test"'), [
            (Keyword, 'post'),
            (Operator, '|'),
            (Text, 'tee'),
            (String.Double, '"/tmp/test"'),
        ]) 
Example #20
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_post_pipe(self):
        self.assertEqual(self.get_tokens('httpie post | tee "/tmp/test"'), [
            (Keyword, 'httpie'),
            (Keyword, 'post'),
            (Operator, '|'),
            (Text, 'tee'),
            (String.Double, '"/tmp/test"'),
        ]) 
Example #21
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_relative_path(self):
        tokens = self.get_tokens('httpie /api/test name==foo',
                                 filter_spaces=False)
        self.assertEqual(tokens, [
            (Keyword, 'httpie'), (Text, ' '),
            (String, '/api/test'), (Text, ' '),
            (Name, 'name'), (Operator, '=='), (String, 'foo'),
            (Text, '\n')
        ]) 
Example #22
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_options(self):
        self.assertEqual(self.get_tokens('httpie options test --body'), [
            (Keyword, 'httpie'), (Keyword, 'options'),
            (String, 'test'), (Name, '--body')
        ]) 
Example #23
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_body_param_first(self):
        self.assertEqual(self.get_tokens('httpie post name=jack --form'), [
            (Keyword, 'httpie'), (Keyword, 'post'),
            (Name, 'name'), (Operator, '='), (String, 'jack'),
            (Name, '--form')
        ]) 
Example #24
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_option_first(self):
        self.assertEqual(self.get_tokens('httpie post --form name=jack'), [
            (Keyword, 'httpie'), (Keyword, 'post'),
            (Name, '--form'),
            (Name, 'name'), (Operator, '='), (String, 'jack')
        ]) 
Example #25
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_absolute_url(self):
        cmd = 'httpie post http://example.com name=jack'
        self.assertEqual(self.get_tokens(cmd), [
            (Keyword, 'httpie'), (Keyword, 'post'),
            (String, 'http://example.com'),
            (Name, 'name'), (Operator, '='), (String, 'jack')
        ]) 
Example #26
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_httpie_without_action(self):
        cmd = 'httpie http://example.com name=jack'
        self.assertEqual(self.get_tokens(cmd), [
            (Keyword, 'httpie'),
            (String, 'http://example.com'),
            (Name, 'name'), (Operator, '='), (String, 'jack')
        ]) 
Example #27
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_exit_with_spaces(self):
        self.assertEqual(self.get_tokens('  exit   '), [
            (Keyword, 'exit')
        ]) 
Example #28
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_exit_simple(self):
        self.assertEqual(self.get_tokens('exit'), [
            (Keyword, 'exit')
        ]) 
Example #29
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_exec_escaped_filename(self):
        self.assertEqual(self.get_tokens(r"exec /tmp/my\ file.txt"), [
            (Keyword, 'exec'), (String, r'/tmp/my\ file.txt')
        ]) 
Example #30
Source File: test_lexer.py    From http-prompt with MIT License 5 votes vote down vote up
def test_get_write_quoted_filename(self):
        self.assertEqual(self.get_tokens('get > "/tmp/my file.txt"'), [
            (Keyword, 'get'), (Operator, '>'),
            (Text, '"'), (String, '/tmp/my file.txt'), (Text, '"')
        ])