Skip to content

Commit 361122e

Browse files
committed
Initial import.
0 parents  commit 361122e

87 files changed

Lines changed: 5905 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
python-sqlparse is written and maintained by Andi Albrecht <[email protected]>.
2+
3+
This module contains code (namely the lexer and filter mechanism) from
4+
the pygments project that was written by Georg Brandl.
5+

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release 0.1.0 (In Development)
2+
------------------------------
3+
* Initial.

COPYING

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2008, Andi Albrecht <[email protected]>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
* Neither the name of the authors nor the names of its contributors may be
13+
used to endorse or promote products derived from this software without
14+
specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include COPYING
2+
include test.py
3+
recursive-include docs *.rst

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Makefile to simplify some common development tasks.
2+
# Run 'make help' for a list of commands.
3+
4+
PYTHON=`which python`
5+
6+
default: help
7+
8+
help:
9+
@echo "Available commands:"
10+
@sed -n '/^[a-zA-Z0-9_.]*:/s/:.*//p' <Makefile | sort
11+
12+
test:
13+
$(PYTHON) tests/run_tests.py
14+
15+
clean:
16+
$(PYTHON) setup.py clean
17+
find . -name '*.pyc' -delete
18+
find . -name '*~' -delete

README

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
python-sqlparse - Parse SQL statements
2+
======================================
3+
4+
sqlparse currently support only one feature: You can split a series
5+
of SQL statements into single statements.
6+
7+
Parts of the code are based on pygments written by Georg Brandl and others.
8+
pygments-Homepage: http://pygments.org/
9+
10+
Run Tests
11+
---------
12+
13+
python test/run_tests.py
14+
15+
16+
Create Documentation
17+
--------------------
18+
19+
You need `Sphinx`_ installed on your system to build the documentation.
20+
21+
cd docs/
22+
make html
23+
24+
25+
Install
26+
-------
27+
28+
Run
29+
30+
python setup.py install
31+
32+
with root privileges to install python-sqlparse on your system.
33+
34+
35+
Links
36+
-----
37+
38+
Source code: http://github.com/andialbrecht/python-sqlparse
39+
40+
41+
python-sqlparse is licensed under the BSD license:
42+
http://github.com/andialbrecht/python-sqlparse
43+
44+
45+
.. _Sphinx: http://sphinx.pocoo.org/

TODO

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add GQL dialect.

bin/sqlformat

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (C) 2008 Andi Albrecht, [email protected]
4+
#
5+
# This module is part of python-sqlparse and is released under
6+
# the BSD License: http://www.opensource.org/licenses/bsd-license.php.
7+
8+
import optparse
9+
import os
10+
import sys
11+
12+
import sqlparse
13+
14+
15+
_CASE_CHOICES = ['upper', 'lower', 'capitalize']
16+
17+
18+
parser = optparse.OptionParser(usage='%prog [OPTIONS] FILE, ...',
19+
version='%%prog %s' % sqlparse.__version__)
20+
parser.set_description(('Format FILE according to OPTIONS. Use "-" as FILE '
21+
'to read from stdin.'))
22+
parser.add_option('-v', '--verbose', dest='verbose', action='store_true')
23+
parser.add_option('-o', '--outfile', dest='outfile', metavar='FILE',
24+
help='write output to FILE (defaults to stdout)')
25+
group = parser.add_option_group('Formatting Options')
26+
group.add_option('-k', '--keywords', metavar='CHOICE',
27+
dest='keyword_case', choices=_CASE_CHOICES,
28+
help=('change case of keywords, CHOICE is one of %s'
29+
% ', '.join('"%s"' % x for x in _CASE_CHOICES)))
30+
group.add_option('-i', '--identifiers', metavar='CHOICE',
31+
dest='identifier_case', choices=_CASE_CHOICES,
32+
help=('change case of identifiers, CHOICE is one of %s'
33+
% ', '.join('"%s"' % x for x in _CASE_CHOICES)))
34+
group.add_option('-l', '--language', metavar='LANG',
35+
dest='output_format', choices=['python', 'php'],
36+
help=('output a snippet in programming language LANG, '
37+
'choices are "python", "php"'))
38+
group.add_option('--strip-comments', dest='strip_comments',
39+
action='store_true', default=False,
40+
help='remove comments')
41+
group.add_option('-r', '--reindent', dest='reindent',
42+
action='store_true', default=False,
43+
help='reindent statements')
44+
group.add_option('--indent_width', dest='indent_width', default=2,
45+
help='indentation width (defaults to 2 spaces)')
46+
47+
_FORMATTING_GROUP = group
48+
49+
50+
def _error(msg, exit_=None):
51+
"""Print msg and optionally exit with return code exit_."""
52+
print >>sys.stderr, '[ERROR] %s' % msg
53+
if exit_ is not None:
54+
sys.exit(exit_)
55+
56+
57+
def _build_formatter_opts(options):
58+
"""Convert command line options to dictionary."""
59+
d = {}
60+
for option in _FORMATTING_GROUP.option_list:
61+
d[option.dest] = getattr(options, option.dest)
62+
return d
63+
64+
65+
def main():
66+
options, args = parser.parse_args()
67+
if options.verbose:
68+
print >>sys.stderr, 'Verbose mode'
69+
70+
if len(args) != 1:
71+
_error('No input data.')
72+
parser.print_usage()
73+
sys.exit(1)
74+
75+
if '-' in args: # read from stdin
76+
data = sys.stdin.read()
77+
else:
78+
try:
79+
data = '\n'.join(open(args[0]).readlines())
80+
except OSError, err:
81+
_error('Failed to read %s: %s' % (args[0], err), exit_=1)
82+
83+
if options.outfile:
84+
try:
85+
stream = open(options.outfile, 'w')
86+
except OSError, err:
87+
_error('Failed to open %s: %s' % (options.outfile, err), exit_=1)
88+
else:
89+
stream = sys.stdout
90+
91+
formatter_opts = _build_formatter_opts(options)
92+
try:
93+
formatter_opts = sqlparse.formatter.validate_options(formatter_opts)
94+
except sqlparse.SQLParseError, err:
95+
_error('Invalid options: %s' % err, exit_=1)
96+
97+
stream.write(sqlparse.format(data, **formatter_opts).encode('utf-8',
98+
'replace'))
99+
stream.flush()
100+
101+
102+
if __name__ == '__main__':
103+
main()

docs/Makefile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
PAPER =
8+
9+
# Internal variables.
10+
PAPEROPT_a4 = -D latex_paper_size=a4
11+
PAPEROPT_letter = -D latex_paper_size=letter
12+
ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
13+
14+
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
15+
16+
help:
17+
@echo "Please use \`make <target>' where <target> is one of"
18+
@echo " html to make standalone HTML files"
19+
@echo " dirhtml to make HTML files named index.html in directories"
20+
@echo " pickle to make pickle files"
21+
@echo " json to make JSON files"
22+
@echo " htmlhelp to make HTML files and a HTML help project"
23+
@echo " qthelp to make HTML files and a qthelp project"
24+
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
25+
@echo " changes to make an overview of all changed/added/deprecated items"
26+
@echo " linkcheck to check all external links for integrity"
27+
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
28+
29+
clean:
30+
-rm -rf build/*
31+
32+
html:
33+
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html
34+
@echo
35+
@echo "Build finished. The HTML pages are in build/html."
36+
37+
dirhtml:
38+
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) build/dirhtml
39+
@echo
40+
@echo "Build finished. The HTML pages are in build/dirhtml."
41+
42+
pickle:
43+
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
44+
@echo
45+
@echo "Build finished; now you can process the pickle files."
46+
47+
json:
48+
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) build/json
49+
@echo
50+
@echo "Build finished; now you can process the JSON files."
51+
52+
htmlhelp:
53+
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp
54+
@echo
55+
@echo "Build finished; now you can run HTML Help Workshop with the" \
56+
".hhp project file in build/htmlhelp."
57+
58+
qthelp:
59+
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) build/qthelp
60+
@echo
61+
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
62+
".qhcp project file in build/qthelp, like this:"
63+
@echo "# qcollectiongenerator build/qthelp/python-sqlparse.qhcp"
64+
@echo "To view the help file:"
65+
@echo "# assistant -collectionFile build/qthelp/python-sqlparse.qhc"
66+
67+
latex:
68+
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex
69+
@echo
70+
@echo "Build finished; the LaTeX files are in build/latex."
71+
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
72+
"run these through (pdf)latex."
73+
74+
changes:
75+
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes
76+
@echo
77+
@echo "The overview file is in build/changes."
78+
79+
linkcheck:
80+
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck
81+
@echo
82+
@echo "Link check complete; look for any errors in the above output " \
83+
"or in build/linkcheck/output.txt."
84+
85+
doctest:
86+
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) build/doctest
87+
@echo "Testing of doctests in the sources finished, look at the " \
88+
"results in build/doctest/output.txt."

docs/source/api.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:mod:`sqlparse` -- Parse SQL statements
2+
=======================================
3+
4+
The :mod:`sqlparse` module provides the following functions on module-level.
5+
6+
.. autofunction:: sqlparse.split
7+
8+
.. autofunction:: sqlparse.format
9+
10+
.. autofunction:: sqlparse.parse
11+
12+

0 commit comments

Comments
 (0)