diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2009-06-11 20:45:04 +0200 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2009-06-11 20:45:04 +0200 |
commit | cdf0c12bf95d076d6ed92ecd82338d50d90dc627 (patch) | |
tree | 4e49d54021074a262de52685a20dc78bc1a8b99c /sqlparse/tokens.py | |
parent | 393dfcabc22d7cb20e3dbd408df5087ce500fa8c (diff) | |
download | sqlparse-cdf0c12bf95d076d6ed92ecd82338d50d90dc627.tar.gz |
Cleanup in token.py
Diffstat (limited to 'sqlparse/tokens.py')
-rw-r--r-- | sqlparse/tokens.py | 45 |
1 files changed, 1 insertions, 44 deletions
diff --git a/sqlparse/tokens.py b/sqlparse/tokens.py index 2c63c41..8ae5706 100644 --- a/sqlparse/tokens.py +++ b/sqlparse/tokens.py @@ -27,22 +27,14 @@ class _TokenType(tuple): buf.reverse() return buf - def __init__(self, *args): - # no need to call super.__init__ - self.subtypes = set() - def __contains__(self, val): - return self is val or ( - type(val) is self.__class__ and - val[:len(self)] == self - ) + return val is not None and (self is val or val[:len(self)] == self) def __getattr__(self, val): if not val or not val[0].isupper(): return tuple.__getattribute__(self, val) new = _TokenType(self + (val,)) setattr(self, val, new) - self.subtypes.add(new) new.parent = self return new @@ -94,38 +86,3 @@ Group.Parenthesis = Token.Group.Parenthesis Group.Comment = Token.Group.Comment Group.Where = Token.Group.Where - -def is_token_subtype(ttype, other): - """ - Return True if ``ttype`` is a subtype of ``other``. - - exists for backwards compatibility. use ``ttype in other`` now. - """ - return ttype in other - - -def string_to_tokentype(s): - """ - Convert a string into a token type:: - - >>> string_to_token('String.Double') - Token.Literal.String.Double - >>> string_to_token('Token.Literal.Number') - Token.Literal.Number - >>> string_to_token('') - Token - - Tokens that are already tokens are returned unchanged: - - >>> string_to_token(String) - Token.Literal.String - """ - if isinstance(s, _TokenType): - return s - if not s: - return Token - node = Token - for item in s.split('.'): - node = getattr(node, item) - return node - |