summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorVictor Uriarte <victor.m.uriarte@intel.com>2016-06-06 19:05:17 -0700
committerVictor Uriarte <victor.m.uriarte@intel.com>2016-06-06 19:13:34 -0700
commit321509255b31c9de14f7d4049f36de141e12c0e5 (patch)
tree0241e903b5984ad5a5e373194f8d36f6efd1fed6 /sqlparse
parent66df11633723d7c5e7bde27a4ad3e9fcdd692e7f (diff)
downloadsqlparse-321509255b31c9de14f7d4049f36de141e12c0e5.tar.gz
Encapsulate and relocate create_table_info
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters/__init__.py3
-rw-r--r--sqlparse/filters/create_table_info.py (renamed from sqlparse/filters_tmp.py)41
-rw-r--r--sqlparse/functions_tmp.py45
3 files changed, 44 insertions, 45 deletions
diff --git a/sqlparse/filters/__init__.py b/sqlparse/filters/__init__.py
index f2525c5..bed54c1 100644
--- a/sqlparse/filters/__init__.py
+++ b/sqlparse/filters/__init__.py
@@ -20,6 +20,7 @@ from sqlparse.filters.tokens import TruncateStringFilter
from sqlparse.filters.reindent import ReindentFilter
from sqlparse.filters.right_margin import RightMarginFilter
from sqlparse.filters.aligned_indent import AlignedIndentFilter
+from sqlparse.filters.create_table_info import get_create_table_info
__all__ = [
'SerializerUnicode',
@@ -37,4 +38,6 @@ __all__ = [
'ReindentFilter',
'RightMarginFilter',
'AlignedIndentFilter',
+
+ 'get_create_table_info',
]
diff --git a/sqlparse/filters_tmp.py b/sqlparse/filters/create_table_info.py
index b95cd9a..3496221 100644
--- a/sqlparse/filters_tmp.py
+++ b/sqlparse/filters/create_table_info.py
@@ -6,6 +6,47 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
from sqlparse import tokens as T
+from types import GeneratorType
+
+
+class Pipeline(list):
+ """Pipeline to process filters sequentially"""
+
+ def __call__(self, stream):
+ """Run the pipeline
+
+ Return a static (non generator) version of the result
+ """
+
+ # Run the stream over all the filters on the pipeline
+ for filter in self:
+ # Functions and callable objects (objects with '__call__' method)
+ if callable(filter):
+ stream = filter(stream)
+
+ # Normal filters (objects with 'process' method)
+ else:
+ stream = filter.process(None, stream)
+
+ # If last filter return a generator, staticalize it inside a list
+ if isinstance(stream, GeneratorType):
+ return list(stream)
+ return stream
+
+
+def get_create_table_info(stream):
+ """
+ Function that returns the columns of a CREATE TABLE statement including
+ their type and NULL declaration.
+
+ The nullable declaration is None if not specified, else NOT NULL or NULL.
+ >>> import lexer as lex
+ >>> get_create_table_info(lex.tokenize('CREATE TABLE t (a INT NOT NULL )'))
+ [('t', {0: ('a', 'INT', 'NOT NULL')})]
+ """
+ pipe = Pipeline()
+ pipe.append(InfoCreateTable())
+ return pipe(stream)
def StripWhitespace(stream):
diff --git a/sqlparse/functions_tmp.py b/sqlparse/functions_tmp.py
deleted file mode 100644
index 02aacd2..0000000
--- a/sqlparse/functions_tmp.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from types import GeneratorType
-
-from sqlparse.filters_tmp import InfoCreateTable
-
-
-class Pipeline(list):
- """Pipeline to process filters sequentially"""
-
- def __call__(self, stream):
- """Run the pipeline
-
- Return a static (non generator) version of the result
- """
-
- # Run the stream over all the filters on the pipeline
- for filter in self:
- # Functions and callable objects (objects with '__call__' method)
- if callable(filter):
- stream = filter(stream)
-
- # Normal filters (objects with 'process' method)
- else:
- stream = filter.process(None, stream)
-
- # If last filter return a generator, staticalize it inside a list
- if isinstance(stream, GeneratorType):
- return list(stream)
- return stream
-
-
-def get_create_table_info(stream):
- """
- Function that returns the columns of a CREATE TABLE statement including
- their type and NULL declaration.
-
- The nullable declaration is None if not specified, else NOT NULL or NULL.
- >>> import lexer as lex
- >>> get_create_table_info(lex.tokenize('CREATE TABLE t (a INT NOT NULL )'))
- [('t', {0: ('a', 'INT', 'NOT NULL')})]
- """
- pipe = Pipeline()
- pipe.append(InfoCreateTable())
- return pipe(stream)