Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/sqlparse/tokens.py: 95%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

40 statements  

1# 

2# Copyright (C) 2009-2020 the sqlparse authors and contributors 

3# <see AUTHORS file> 

4# 

5# This module is part of python-sqlparse and is released under 

6# the BSD License: https://opensource.org/licenses/BSD-3-Clause 

7# 

8# The Token implementation is based on pygment's token system written 

9# by Georg Brandl. 

10# http://pygments.org/ 

11 

12"""Tokens""" 

13 

14 

15class _TokenType(tuple): 

16 parent = None 

17 

18 def __contains__(self, item): 

19 return item is not None and (self is item or item[:len(self)] == self) 

20 

21 def __getattr__(self, name): 

22 # don't mess with dunder 

23 if name.startswith('__'): 

24 return super().__getattr__(self, name) 

25 new = _TokenType(self + (name,)) 

26 setattr(self, name, new) 

27 new.parent = self 

28 return new 

29 

30 def __repr__(self): 

31 # self can be False only if its the `root` i.e. Token itself 

32 return 'Token' + ('.' if self else '') + '.'.join(self) 

33 

34 

35Token = _TokenType() 

36 

37# Special token types 

38Text = Token.Text 

39Whitespace = Text.Whitespace 

40Newline = Whitespace.Newline 

41Error = Token.Error 

42# Text that doesn't belong to this lexer (e.g. HTML in PHP) 

43Other = Token.Other 

44 

45# Common token types for source code 

46Keyword = Token.Keyword 

47Name = Token.Name 

48Literal = Token.Literal 

49String = Literal.String 

50Number = Literal.Number 

51Punctuation = Token.Punctuation 

52Operator = Token.Operator 

53Comparison = Operator.Comparison 

54Wildcard = Token.Wildcard 

55Comment = Token.Comment 

56Assignment = Token.Assignment 

57 

58# Generic types for non-source code 

59Generic = Token.Generic 

60Command = Generic.Command 

61 

62# String and some others are not direct children of Token. 

63# alias them: 

64Token.Token = Token 

65Token.String = String 

66Token.Number = Number 

67 

68# SQL specific tokens 

69DML = Keyword.DML 

70DDL = Keyword.DDL 

71CTE = Keyword.CTE