You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by rl...@apache.org on 2016/01/06 09:56:02 UTC
[01/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Repository: incubator-hawq
Updated Branches:
refs/heads/master 7e0ff4193 -> 0672292f3
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/setup.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/setup.py b/tools/bin/pythonSrc/PyGreSQL-4.0/setup.py
deleted file mode 100755
index 5d28b31..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/setup.py
+++ /dev/null
@@ -1,152 +0,0 @@
-#!/usr/bin/env python
-# $Id: setup.py,v 1.27 2008/11/21 17:08:17 cito Exp $
-
-"""Setup script for PyGreSQL version 4.0
-
-Authors and history:
-* PyGreSQL written 1997 by D'Arcy J.M. Cain <da...@druid.net>
-* based on code written 1995 by Pascal Andre <an...@chimay.via.ecp.fr>
-* setup script created 2000/04 Mark Alexander <mw...@gate.net>
-* tweaked 2000/05 Jeremy Hylton <je...@cnri.reston.va.us>
-* win32 support 2001/01 by Gerhard Haering <ge...@bigfoot.de>
-* tweaked 2006/02 and 2008/11 by Christoph Zwerschke <ci...@online.de>
-
-Prerequisites to be installed:
-* Python including devel package (header files and distutils)
-* PostgreSQL libs and devel packages (header files of client and server)
-* PostgreSQL pg_config tool (usually included in the devel package)
- (the Windows installer has it as part of the database server feature)
-
-Tested with Python 2.5.2 and PostGreSQL 8.3.5. Older version should work
-as well, but you will need at least Python 2.3 and PostgreSQL 7.4.
-
-Use as follows:
-python setup.py build # to build the module
-python setup.py install # to install it
-
-You should use MinGW (www.mingw.org) for building on Win32:
-python setup.py build -c mingw32 install # use MinGW
-Note that Python newer than version 2.3 is using msvcr71 instead of msvcrt
-as its common runtime library. So, if you are using MinGW to build PyGreSQL,
-you should edit the file "%MinGWpath%/lib/gcc/%MinGWversion%/specs"
-and change the entry that reads -lmsvcrt to -lmsvcr71.
-
-See docs.python.org/doc/install/ for more information on
-using distutils to install Python programs.
-
-"""
-
-version = "4.0"
-
-import sys
-
-if not (2, 2) < sys.version_info[:2] < (3, 0):
- raise Exception("PyGreSQL %s requires a Python 2 version"
- " newer than 2.2." % version)
-
-import os
-from distutils.core import setup
-from distutils.extension import Extension
-
-def pg_config(s):
- """Retrieve information about installed version of PostgreSQL."""
- if os.path.exists("../../../../src/bin/pg_config/pg_config"):
- f = os.popen("../../../../src/bin/pg_config/pg_config --%s" % s)
- else:
- """If a VPATH build, it might not be there. Look other places"""
- """It should be the one in the path, because the makefile includes greenplum_path.sh """
- f = os.popen("pg_config --%s" % s)
-
- d = f.readline().strip()
- if f.close() is not None:
- raise Exception("pg_config tool is not available.")
- if not d:
- raise Exception("Could not get %s information." % s)
- return d
-
-def mk_include():
- """Create a temporary local include directory.
-
- The directory will contain a copy of the PostgreSQL server header files,
- where all features which are not necessary for PyGreSQL are disabled.
-
- """
- os.mkdir('include')
- for f in os.listdir(pg_include_dir_server):
- if not f.endswith('.h'):
- continue
- d = open(os.path.join(pg_include_dir_server, f)).read()
- if f == 'pg_config.h':
- d += '\n'.join(('',
- '#undef ENABLE_NLS',
- '#undef USE_REPL_SNPRINTF',
- '#undef USE_SSL',
- '#undef USE_ZLIB',
- '#undef HAVE_STDINT_H',
- '#undef HAVE_SYS_TIME_H',
- '#undef HAVE_UNISTD_H',
- '#define _CRT_SECURE_NO_WARNINGS 1',
- '#define _USE_32BIT_TIME_T 1',
- ''))
- open(os.path.join('include', f), 'w').write(d)
-
-def rm_include():
- """Remove the temporary local include directory."""
- if os.path.exists('include'):
- for f in os.listdir('include'):
- os.remove(os.path.join('include', f))
- os.rmdir('include')
-
-pg_include_dir = pg_config('includedir')
-pg_include_dir_server = pg_config('includedir-server')
-
-rm_include()
-mk_include()
-
-include_dirs = ['include', pg_include_dir, pg_include_dir_server]
-
-pg_libdir = pg_config('libdir')
-library_dirs = [pg_libdir]
-
-libraries=['pq']
-
-if sys.platform == "win32":
- include_dirs.append(os.path.join(pg_include_dir_server, 'port/win32'))
-
-setup(
- name="PyGreSQL",
- version=version,
- description="Python PostgreSQL Interfaces",
- long_description = ("PyGreSQL is an open-source Python module"
- " that interfaces to a PostgreSQL database."
- " It embeds the PostgreSQL query library to allow easy use"
- " of the powerful PostgreSQL features from a Python script."),
- keywords="postgresql database api dbapi",
- author="D'Arcy J. M. Cain",
- author_email="darcy@PyGreSQL.org",
- url="http://www.pygresql.org",
- download_url = "ftp://ftp.pygresql.org/pub/distrib/",
- platforms = ["any"],
- license="Python",
- py_modules=['pg', 'pgdb'],
- ext_modules=[Extension(
- '_pg', ['pgmodule.c'],
- include_dirs = include_dirs,
- library_dirs = library_dirs,
- libraries = libraries,
- extra_compile_args = ['-O2']
- )],
- classifiers=[
- "Development Status :: 6 - Mature",
- "Intended Audience :: Developers",
- "License :: OSI Approved :: Python Software Foundation License",
- "Operating System :: OS Independent",
- "Programming Language :: C",
- "Programming Language :: Python",
- "Topic :: Database",
- "Topic :: Database :: Front-Ends",
- "Topic :: Software Development :: Libraries :: Python Modules"
- ]
-)
-
-rm_include()
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/advanced.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/advanced.py b/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/advanced.py
deleted file mode 100755
index 41a5bc4..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/advanced.py
+++ /dev/null
@@ -1,198 +0,0 @@
-#! /usr/bin/env python
-# advanced.py - demo of advanced features of PostGres. Some may not be ANSI.
-# inspired from the Postgres tutorial
-# adapted to Python 1995 by Pascal Andre
-
-print """
-__________________________________________________________________
-MODULE ADVANCED.PY : ADVANCED POSTGRES SQL COMMANDS TUTORIAL
-
-This module is designed for being imported from python prompt
-
-In order to run the samples included here, first create a connection
-using : cnx = advanced.DB(...)
-
-The "..." should be replaced with whatever arguments you need to open an
-existing database. Usually all you need is the name of the database and,
-in fact, if it is the same as your login name, you can leave it empty.
-
-then start the demo with: advanced.demo(cnx)
-__________________________________________________________________
-"""
-
-from pg import DB
-import sys
-
-# waits for a key
-def wait_key():
- print "Press <enter>"
- sys.stdin.read(1)
-
-# inheritance features
-def inherit_demo(pgcnx):
- print "-----------------------------"
- print "-- Inheritance:"
- print "-- a table can inherit from zero or more tables. A query"
- print "-- can reference either all rows of a table or all rows "
- print "-- of a table plus all of its descendants."
- print "-----------------------------"
- print
- print "-- For example, the capitals table inherits from cities table."
- print "-- (It inherits all data fields from cities.)"
- print
- print "CREATE TABLE cities ("
- print " name text,"
- print " population float8,"
- print " altitude int"
- print ")"
- print
- print "CREATE TABLE capitals ("
- print " state varchar(2)"
- print ") INHERITS (cities)"
- pgcnx.query("""CREATE TABLE cities (
- name text,
- population float8,
- altitude int)""")
- pgcnx.query("""CREATE TABLE capitals (
- state varchar(2)) INHERITS (cities)""")
- wait_key()
- print
- print "-- now, let's populate the tables"
- print
- print "INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63)"
- print "INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174)"
- print "INSERT INTO cities VALUES ('Mariposa', 1200, 1953)"
- print
- print "INSERT INTO capitals VALUES ('Sacramento', 3.694E+5, 30, 'CA')"
- print "INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI')"
- print
- pgcnx.query("INSERT INTO cities VALUES ('San Francisco', 7.24E+5, 63)")
- pgcnx.query("INSERT INTO cities VALUES ('Las Vegas', 2.583E+5, 2174)")
- pgcnx.query("INSERT INTO cities VALUES ('Mariposa', 1200, 1953)")
- pgcnx.query("INSERT INTO capitals VALUES ('Sacramento',3.694E+5,30,'CA')")
- pgcnx.query("INSERT INTO capitals VALUES ('Madison', 1.913E+5, 845, 'WI')")
- print
- print "SELECT * FROM cities"
- print pgcnx.query("SELECT * FROM cities")
- print "SELECT * FROM capitals"
- print pgcnx.query("SELECT * FROM capitals")
- print
- print "-- like before, a regular query references rows of the base"
- print "-- table only"
- print
- print "SELECT name, altitude"
- print "FROM cities"
- print "WHERE altitude > 500;"
- print pgcnx.query("""SELECT name, altitude
- FROM cities
- WHERE altitude > 500""")
- print
- print "-- on the other hand, you can find all cities, including "
- print "-- capitals, that are located at an altitude of 500 'ft "
- print "-- or higher by:"
- print
- print "SELECT c.name, c.altitude"
- print "FROM cities* c"
- print "WHERE c.altitude > 500"
- print pgcnx.query("""SELECT c.name, c.altitude
- FROM cities* c
- WHERE c.altitude > 500""")
-
-# arrays attributes
-def array_demo(pgcnx):
- print "----------------------"
- print "-- Arrays:"
- print "-- attributes can be arrays of base types or user-defined "
- print "-- types"
- print "----------------------"
- print
- print "CREATE TABLE sal_emp ("
- print " name text,"
- print " pay_by_quarter int4[],"
- print " pay_by_extra_quarter int8[],"
- print " schedule text[][]"
- print ")"
- pgcnx.query("""CREATE TABLE sal_emp (
- name text,
- pay_by_quarter int4[],
- pay_by_extra_quarter int8[],
- schedule text[][])""")
- wait_key()
- print
- print "-- insert instances with array attributes. "
- print " Note the use of braces"
- print
- print "INSERT INTO sal_emp VALUES ("
- print " 'Bill',"
- print " '{10000,10000,10000,10000}',"
- print " '{9223372036854775800,9223372036854775800,9223372036854775800}',"
- print " '{{\"meeting\", \"lunch\"}, {}}')"
- print
- print "INSERT INTO sal_emp VALUES ("
- print " 'Carol',"
- print " '{20000,25000,25000,25000}',"
- print " '{9223372036854775807,9223372036854775807,9223372036854775807}',"
- print " '{{\"talk\", \"consult\"}, {\"meeting\"}}')"
- print
- pgcnx.query("""INSERT INTO sal_emp VALUES (
- 'Bill', '{10000,10000,10000,10000}',
- '{9223372036854775800,9223372036854775800,9223372036854775800}',
- '{{\"meeting\", \"lunch\"}, {}}')""")
- pgcnx.query("""INSERT INTO sal_emp VALUES (
- 'Carol', '{20000,25000,25000,25000}',
- '{9223372036854775807,9223372036854775807,9223372036854775807}',
- '{{\"talk\", \"consult\"}, {\"meeting\"}}')""")
- wait_key()
- print
- print "----------------------"
- print "-- queries on array attributes"
- print "----------------------"
- print
- print "SELECT name FROM sal_emp WHERE"
- print " sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]"
- print
- print pgcnx.query("""SELECT name FROM sal_emp WHERE
- sal_emp.pay_by_quarter[1] <> sal_emp.pay_by_quarter[2]""")
- print
- print pgcnx.query("""SELECT name FROM sal_emp WHERE
- sal_emp.pay_by_extra_quarter[1] <> sal_emp.pay_by_extra_quarter[2]""")
- print
- print "-- retrieve third quarter pay of all employees"
- print
- print "SELECT sal_emp.pay_by_quarter[3] FROM sal_emp"
- print
- print pgcnx.query("SELECT sal_emp.pay_by_quarter[3] FROM sal_emp")
- print
- print "-- retrieve third quarter extra pay of all employees"
- print
- print "SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp"
- print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[3] FROM sal_emp")
- print
- print "-- retrieve first two quarters of extra quarter pay of all employees"
- print
- print "SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp"
- print
- print pgcnx.query("SELECT sal_emp.pay_by_extra_quarter[1:2] FROM sal_emp")
- print
- print "-- select subarrays"
- print
- print "SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE"
- print " sal_emp.name = 'Bill'"
- print pgcnx.query("SELECT sal_emp.schedule[1:2][1:1] FROM sal_emp WHERE " \
- "sal_emp.name = 'Bill'")
-
-# base cleanup
-def demo_cleanup(pgcnx):
- print "-- clean up (you must remove the children first)"
- print "DROP TABLE sal_emp"
- print "DROP TABLE capitals"
- print "DROP TABLE cities;"
- pgcnx.query("DROP TABLE sal_emp")
- pgcnx.query("DROP TABLE capitals")
- pgcnx.query("DROP TABLE cities")
-
-# main demo function
-def demo(pgcnx):
- inherit_demo(pgcnx)
- array_demo(pgcnx)
- demo_cleanup(pgcnx)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/basics.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/basics.py b/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/basics.py
deleted file mode 100755
index 98a7f86..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/basics.py
+++ /dev/null
@@ -1,296 +0,0 @@
-#! /usr/bin/env python
-# basics.py - basic SQL commands tutorial
-# inspired from the Postgres95 tutorial
-# adapted to Python 1995 by Pascal ANDRE
-
-print """
-__________________________________________________________________
-MODULE BASICS.PY : BASIC POSTGRES SQL COMMANDS TUTORIAL
-
-This module is designed for being imported from python prompt
-
-In order to run the samples included here, first create a connection
-using : cnx = basics.DB(...)
-
-The "..." should be replaced with whatever arguments you need to open an
-existing database. Usually all you need is the name of the database and,
-in fact, if it is the same as your login name, you can leave it empty.
-
-then start the demo with: basics.demo(cnx)
-__________________________________________________________________
-"""
-
-from pg import DB
-import sys
-
-# waits for a key
-def wait_key():
- print "Press <enter>"
- sys.stdin.read(1)
-
-# table creation commands
-def create_table(pgcnx):
- print "-----------------------------"
- print "-- Creating a table:"
- print "-- a CREATE TABLE is used to create base tables. POSTGRES"
- print "-- SQL has its own set of built-in types. (Note that"
- print "-- keywords are case-insensitive but identifiers are "
- print "-- case-sensitive.)"
- print "-----------------------------"
- print
- print "Sending query :"
- print "CREATE TABLE weather ("
- print " city varchar(80),"
- print " temp_lo int,"
- print " temp_hi int,"
- print " prcp float8,"
- print " date date"
- print ")"
- pgcnx.query("""CREATE TABLE weather (city varchar(80), temp_lo int,
- temp_hi int, prcp float8, date date)""")
- print
- print "Sending query :"
- print "CREATE TABLE cities ("
- print " name varchar(80),"
- print " location point"
- print ")"
- pgcnx.query("""CREATE TABLE cities (
- name varchar(80),
- location point)""")
-
-# data insertion commands
-def insert_data(pgcnx):
- print "-----------------------------"
- print "-- Inserting data:"
- print "-- an INSERT statement is used to insert a new row into"
- print "-- a table. There are several ways you can specify what"
- print "-- columns the data should go to."
- print "-----------------------------"
- print
- print "-- 1. the simplest case is when the list of value correspond to"
- print "-- the order of the columns specified in CREATE TABLE."
- print
- print "Sending query :"
- print "INSERT INTO weather "
- print " VALUES ('San Francisco', 46, 50, 0.25, '11/27/1994')"
- pgcnx.query("""INSERT INTO weather
- VALUES ('San Francisco', 46, 50, 0.25, '11/27/1994')""")
- print
- print "Sending query :"
- print "INSERT INTO cities "
- print " VALUES ('San Francisco', '(-194.0, 53.0)')"
- pgcnx.query("""INSERT INTO cities
- VALUES ('San Francisco', '(-194.0, 53.0)')""")
- print
- wait_key()
- print "-- 2. you can also specify what column the values correspond "
- print " to. (The columns can be specified in any order. You may "
- print " also omit any number of columns. eg. unknown precipitation"
- print " below)"
- print "Sending query :"
- print "INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)"
- print " VALUES ('San Francisco', 43, 57, 0.0, '11/29/1994')"
- pgcnx.query("INSERT INTO weather (date, city, temp_hi, temp_lo)" \
- "VALUES ('11/29/1994', 'Hayward', 54, 37)")
-
-# direct selection commands
-def select_data1(pgcnx):
- print "-----------------------------"
- print "-- Retrieving data:"
- print "-- a SELECT statement is used for retrieving data. The "
- print "-- basic syntax is:"
- print "-- SELECT columns FROM tables WHERE predicates"
- print "-----------------------------"
- print
- print "-- a simple one would be the query:"
- print "SELECT * FROM weather"
- print
- print "The result is :"
- q = pgcnx.query("SELECT * FROM weather")
- print q
- print
- print "-- you may also specify expressions in the target list (the "
- print "-- 'AS column' specifies the column name of the result. It is "
- print "-- optional.)"
- print "The query :"
- print " SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date "
- print " FROM weather"
- print "Gives :"
- print pgcnx.query("""SELECT city, (temp_hi+temp_lo)/2
- AS temp_avg, date FROM weather""")
- print
- print "-- if you want to retrieve rows that satisfy certain condition"
- print "-- (ie. a restriction), specify the condition in WHERE. The "
- print "-- following retrieves the weather of San Francisco on rainy "
- print "-- days."
- print "SELECT *"
- print "FROM weather"
- print "WHERE city = 'San Francisco' "
- print " and prcp > 0.0"
- print pgcnx.query("""SELECT * FROM weather WHERE city = 'San Francisco'
- AND prcp > 0.0""")
- print
- print "-- here is a more complicated one. Duplicates are removed when "
- print "-- DISTINCT is specified. ORDER BY specifies the column to sort"
- print "-- on. (Just to make sure the following won't confuse you, "
- print "-- DISTINCT and ORDER BY can be used separately.)"
- print "SELECT DISTINCT city"
- print "FROM weather"
- print "ORDER BY city;"
- print pgcnx.query("SELECT DISTINCT city FROM weather ORDER BY city")
-
-# selection to a temporary table
-def select_data2(pgcnx):
- print "-----------------------------"
- print "-- Retrieving data into other classes:"
- print "-- a SELECT ... INTO statement can be used to retrieve "
- print "-- data into another class."
- print "-----------------------------"
- print
- print "The query :"
- print "SELECT * INTO TABLE temptab "
- print "FROM weather"
- print "WHERE city = 'San Francisco' "
- print " and prcp > 0.0"
- pgcnx.query("""SELECT * INTO TABLE temptab FROM weather
- WHERE city = 'San Francisco' and prcp > 0.0""")
- print "Fills the table temptab, that can be listed with :"
- print "SELECT * from temptab"
- print pgcnx.query("SELECT * from temptab")
-
-# aggregate creation commands
-def create_aggregate(pgcnx):
- print "-----------------------------"
- print "-- Aggregates"
- print "-----------------------------"
- print
- print "Let's consider the query :"
- print "SELECT max(temp_lo)"
- print "FROM weather;"
- print pgcnx.query("SELECT max(temp_lo) FROM weather")
- print
- print "-- Aggregate with GROUP BY"
- print "SELECT city, max(temp_lo)"
- print "FROM weather "
- print "GROUP BY city;"
- print pgcnx.query( """SELECT city, max(temp_lo)
- FROM weather GROUP BY city""")
-
-# table join commands
-def join_table(pgcnx):
- print "-----------------------------"
- print "-- Joining tables:"
- print "-- queries can access multiple tables at once or access"
- print "-- the same table in such a way that multiple instances"
- print "-- of the table are being processed at the same time."
- print "-----------------------------"
- print
- print "-- suppose we want to find all the records that are in the "
- print "-- temperature range of other records. W1 and W2 are aliases "
- print "--for weather."
- print
- print "SELECT W1.city, W1.temp_lo, W1.temp_hi, "
- print " W2.city, W2.temp_lo, W2.temp_hi"
- print "FROM weather W1, weather W2"
- print "WHERE W1.temp_lo < W2.temp_lo "
- print " and W1.temp_hi > W2.temp_hi"
- print
- print pgcnx.query("""SELECT W1.city, W1.temp_lo, W1.temp_hi,
- W2.city, W2.temp_lo, W2.temp_hi FROM weather W1, weather W2
- WHERE W1.temp_lo < W2.temp_lo and W1.temp_hi > W2.temp_hi""")
- print
- print "-- let's join two tables. The following joins the weather table"
- print "-- and the cities table."
- print
- print "SELECT city, location, prcp, date"
- print "FROM weather, cities"
- print "WHERE name = city"
- print
- print pgcnx.query("""SELECT city, location, prcp, date FROM weather, cities
- WHERE name = city""")
- print
- print "-- since the column names are all different, we don't have to "
- print "-- specify the table name. If you want to be clear, you can do "
- print "-- the following. They give identical results, of course."
- print
- print "SELECT w.city, c.location, w.prcp, w.date"
- print "FROM weather w, cities c"
- print "WHERE c.name = w.city;"
- print
- print pgcnx.query("""SELECT w.city, c.location, w.prcp, w.date
- FROM weather w, cities c WHERE c.name = w.city""")
-
-# data updating commands
-def update_data(pgcnx):
- print "-----------------------------"
- print "-- Updating data:"
- print "-- an UPDATE statement is used for updating data. "
- print "-----------------------------"
- print
- print "-- suppose you discover the temperature readings are all off by"
- print "-- 2 degrees as of Nov 28, you may update the data as follow:"
- print
- print "UPDATE weather"
- print " SET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2"
- print " WHERE date > '11/28/1994'"
- print
- pgcnx.query("""UPDATE weather
- SET temp_hi = temp_hi - 2, temp_lo = temp_lo - 2
- WHERE date > '11/28/1994'""")
- print
- print "SELECT * from weather"
- print pgcnx.query("SELECT * from weather")
-
-# data deletion commands
-def delete_data(pgcnx):
- print "-----------------------------"
- print "-- Deleting data:"
- print "-- a DELETE statement is used for deleting rows from a "
- print "-- table."
- print "-----------------------------"
- print
- print "-- suppose you are no longer interested in the weather of "
- print "-- Hayward, you can do the following to delete those rows from"
- print "-- the table"
- print
- print "DELETE FROM weather WHERE city = 'Hayward'"
- pgcnx.query("DELETE FROM weather WHERE city = 'Hayward'")
- print
- print "SELECT * from weather"
- print
- print pgcnx.query("SELECT * from weather")
- print
- print "-- you can also delete all the rows in a table by doing the "
- print "-- following. (This is different from DROP TABLE which removes "
- print "-- the table in addition to the removing the rows.)"
- print
- print "DELETE FROM weather"
- pgcnx.query("DELETE FROM weather")
- print
- print "SELECT * from weather"
- print pgcnx.query("SELECT * from weather")
-
-# table removal commands
-def remove_table(pgcnx):
- print "-----------------------------"
- print "-- Removing the tables:"
- print "-- DROP TABLE is used to remove tables. After you have"
- print "-- done this, you can no longer use those tables."
- print "-----------------------------"
- print
- print "DROP TABLE weather, cities, temptab"
- pgcnx.query("DROP TABLE weather, cities, temptab")
-
-# main demo function
-def demo(pgcnx):
- create_table(pgcnx)
- wait_key()
- insert_data(pgcnx)
- wait_key()
- select_data1(pgcnx)
- select_data2(pgcnx)
- create_aggregate(pgcnx)
- join_table(pgcnx)
- update_data(pgcnx)
- delete_data(pgcnx)
- remove_table(pgcnx)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/func.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/func.py b/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/func.py
deleted file mode 100755
index af2b412..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/func.py
+++ /dev/null
@@ -1,205 +0,0 @@
-# func.py - demonstrate the use of SQL functions
-# inspired from the PostgreSQL tutorial
-# adapted to Python 1995 by Pascal ANDRE
-
-print """
-__________________________________________________________________
-MODULE FUNC.PY : SQL FUNCTION DEFINITION TUTORIAL
-
-This module is designed for being imported from python prompt
-
-In order to run the samples included here, first create a connection
-using : cnx = func.DB(...)
-
-The "..." should be replaced with whatever arguments you need to open an
-existing database. Usually all you need is the name of the database and,
-in fact, if it is the same as your login name, you can leave it empty.
-
-then start the demo with: func.demo(cnx)
-__________________________________________________________________
-"""
-
-from pg import DB
-import sys
-
-# waits for a key
-def wait_key():
- print "Press <enter>"
- sys.stdin.read(1)
-
-# basic functions declaration
-def base_func(pgcnx):
- print "-----------------------------"
- print "-- Creating SQL Functions on Base Types"
- print "-- a CREATE FUNCTION statement lets you create a new "
- print "-- function that can be used in expressions (in SELECT, "
- print "-- INSERT, etc.). We will start with functions that "
- print "-- return values of base types."
- print "-----------------------------"
- print
- print "--"
- print "-- let's create a simple SQL function that takes no arguments"
- print "-- and returns 1"
- print
- print "CREATE FUNCTION one() RETURNS int4"
- print " AS 'SELECT 1 as ONE' LANGUAGE 'sql'"
- pgcnx.query("""CREATE FUNCTION one() RETURNS int4
- AS 'SELECT 1 as ONE' LANGUAGE 'sql'""")
- wait_key()
- print
- print "--"
- print "-- functions can be used in any expressions (eg. in the target"
- print "-- list or qualifications)"
- print
- print "SELECT one() AS answer"
- print pgcnx.query("SELECT one() AS answer")
- print
- print "--"
- print "-- here's how you create a function that takes arguments. The"
- print "-- following function returns the sum of its two arguments:"
- print
- print "CREATE FUNCTION add_em(int4, int4) RETURNS int4"
- print " AS 'SELECT $1 + $2' LANGUAGE 'sql'"
- pgcnx.query("""CREATE FUNCTION add_em(int4, int4) RETURNS int4
- AS 'SELECT $1 + $2' LANGUAGE 'sql'""")
- print
- print "SELECT add_em(1, 2) AS answer"
- print pgcnx.query("SELECT add_em(1, 2) AS answer")
-
-# functions on composite types
-def comp_func(pgcnx):
- print "-----------------------------"
- print "-- Creating SQL Functions on Composite Types"
- print "-- it is also possible to create functions that return"
- print "-- values of composite types."
- print "-----------------------------"
- print
- print "-- before we create more sophisticated functions, let's "
- print "-- populate an EMP table"
- print
- print "CREATE TABLE EMP ("
- print " name text,"
- print " salary int4,"
- print " age int4,"
- print " dept varchar(16)"
- print ")"
- pgcnx.query("""CREATE TABLE EMP (
- name text,
- salary int4,
- age int4,
- dept varchar(16))""")
- print
- print "INSERT INTO EMP VALUES ('Sam', 1200, 16, 'toy')"
- print "INSERT INTO EMP VALUES ('Claire', 5000, 32, 'shoe')"
- print "INSERT INTO EMP VALUES ('Andy', -1000, 2, 'candy')"
- print "INSERT INTO EMP VALUES ('Bill', 4200, 36, 'shoe')"
- print "INSERT INTO EMP VALUES ('Ginger', 4800, 30, 'candy')"
- pgcnx.query("INSERT INTO EMP VALUES ('Sam', 1200, 16, 'toy')")
- pgcnx.query("INSERT INTO EMP VALUES ('Claire', 5000, 32, 'shoe')")
- pgcnx.query("INSERT INTO EMP VALUES ('Andy', -1000, 2, 'candy')")
- pgcnx.query("INSERT INTO EMP VALUES ('Bill', 4200, 36, 'shoe')")
- pgcnx.query("INSERT INTO EMP VALUES ('Ginger', 4800, 30, 'candy')")
- wait_key()
- print
- print "-- the argument of a function can also be a tuple. For "
- print "-- instance, double_salary takes a tuple of the EMP table"
- print
- print "CREATE FUNCTION double_salary(EMP) RETURNS int4"
- print " AS 'SELECT $1.salary * 2 AS salary' LANGUAGE 'sql'"
- pgcnx.query("""CREATE FUNCTION double_salary(EMP) RETURNS int4
- AS 'SELECT $1.salary * 2 AS salary' LANGUAGE 'sql'""")
- print
- print "SELECT name, double_salary(EMP) AS dream"
- print "FROM EMP"
- print "WHERE EMP.dept = 'toy'"
- print pgcnx.query("""SELECT name, double_salary(EMP) AS dream
- FROM EMP WHERE EMP.dept = 'toy'""")
- print
- print "-- the return value of a function can also be a tuple. However,"
- print "-- make sure that the expressions in the target list is in the "
- print "-- same order as the columns of EMP."
- print
- print "CREATE FUNCTION new_emp() RETURNS EMP"
- print " AS 'SELECT \'None\'::text AS name,"
- print " 1000 AS salary,"
- print " 25 AS age,"
- print " \'none\'::varchar(16) AS dept'"
- print " LANGUAGE 'sql'"
- pgcnx.query("""CREATE FUNCTION new_emp() RETURNS EMP
- AS 'SELECT \\\'None\\\'::text AS name,
- 1000 AS salary,
- 25 AS age,
- \\\'none\\\'::varchar(16) AS dept'
- LANGUAGE 'sql'""")
- wait_key()
- print
- print "-- you can then project a column out of resulting the tuple by"
- print "-- using the \"function notation\" for projection columns. "
- print "-- (ie. bar(foo) is equivalent to foo.bar) Note that we don't"
- print "-- support new_emp().name at this moment."
- print
- print "SELECT name(new_emp()) AS nobody"
- print pgcnx.query("SELECT name(new_emp()) AS nobody")
- print
- print "-- let's try one more function that returns tuples"
- print "CREATE FUNCTION high_pay() RETURNS setof EMP"
- print " AS 'SELECT * FROM EMP where salary > 1500'"
- print " LANGUAGE 'sql'"
- pgcnx.query("""CREATE FUNCTION high_pay() RETURNS setof EMP
- AS 'SELECT * FROM EMP where salary > 1500'
- LANGUAGE 'sql'""")
- print
- print "SELECT name(high_pay()) AS overpaid"
- print pgcnx.query("SELECT name(high_pay()) AS overpaid")
-
-# function with multiple SQL commands
-def mult_func(pgcnx):
- print "-----------------------------"
- print "-- Creating SQL Functions with multiple SQL statements"
- print "-- you can also create functions that do more than just a"
- print "-- SELECT."
- print "-----------------------------"
- print
- print "-- you may have noticed that Andy has a negative salary. We'll"
- print "-- create a function that removes employees with negative "
- print "-- salaries."
- print
- print "SELECT * FROM EMP"
- print pgcnx.query("SELECT * FROM EMP")
- print
- print "CREATE FUNCTION clean_EMP () RETURNS int4"
- print " AS 'DELETE FROM EMP WHERE EMP.salary <= 0"
- print " SELECT 1 AS ignore_this'"
- print " LANGUAGE 'sql'"
- pgcnx.query("CREATE FUNCTION clean_EMP () RETURNS int4 AS 'DELETE FROM EMP WHERE EMP.salary <= 0; SELECT 1 AS ignore_this' LANGUAGE 'sql'")
- print
- print "SELECT clean_EMP()"
- print pgcnx.query("SELECT clean_EMP()")
- print
- print "SELECT * FROM EMP"
- print pgcnx.query("SELECT * FROM EMP")
-
-# base cleanup
-def demo_cleanup(pgcnx):
- print "-- remove functions that were created in this file"
- print
- print "DROP FUNCTION clean_EMP()"
- print "DROP FUNCTION high_pay()"
- print "DROP FUNCTION new_emp()"
- print "DROP FUNCTION add_em(int4, int4)"
- print "DROP FUNCTION one()"
- print
- print "DROP TABLE EMP CASCADE"
- pgcnx.query("DROP FUNCTION clean_EMP()")
- pgcnx.query("DROP FUNCTION high_pay()")
- pgcnx.query("DROP FUNCTION new_emp()")
- pgcnx.query("DROP FUNCTION add_em(int4, int4)")
- pgcnx.query("DROP FUNCTION one()")
- pgcnx.query("DROP TABLE EMP CASCADE")
-
-# main demo function
-def demo(pgcnx):
- base_func(pgcnx)
- comp_func(pgcnx)
- mult_func(pgcnx)
- demo_cleanup(pgcnx)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/syscat.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/syscat.py b/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/syscat.py
deleted file mode 100755
index 1ab1d58..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/tutorial/syscat.py
+++ /dev/null
@@ -1,149 +0,0 @@
-# syscat.py - parses some system catalogs
-# inspired from the PostgreSQL tutorial
-# adapted to Python 1995 by Pascal ANDRE
-
-print """
-__________________________________________________________________
-MODULE SYSCAT.PY : PARSES SOME POSTGRESQL SYSTEM CATALOGS
-
-This module is designed for being imported from python prompt
-
-In order to run the samples included here, first create a connection
-using : cnx = syscat.DB(...)
-
-The "..." should be replaced with whatever arguments you need to open an
-existing database. Usually all you need is the name of the database and,
-in fact, if it is the same as your login name, you can leave it empty.
-
-then start the demo with: syscat.demo(cnx)
-
-Some results may be empty, depending on your base status."
-
-__________________________________________________________________
-"""
-
-from pg import DB
-import sys
-
-# waits for a key
-def wait_key():
- print "Press <enter>"
- sys.stdin.read(1)
-
-# lists all simple indices
-def list_simple_ind(pgcnx):
- result = pgcnx.query("""SELECT bc.relname AS class_name,
- ic.relname AS index_name, a.attname
- FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a
- WHERE i.indrelid = bc.oid AND i.indexrelid = bc.oid
- AND i.indkey[0] = a.attnum AND a.attrelid = bc.oid
- AND i.indproc = '0'::oid AND a.attisdropped = 'f'
- ORDER BY class_name, index_name, attname""")
- return result
-
-# list all user defined attributes and their type in user-defined classes
-def list_all_attr(pgcnx):
- result = pgcnx.query("""SELECT c.relname, a.attname, t.typname
- FROM pg_class c, pg_attribute a, pg_type t
- WHERE c.relkind = 'r' and c.relname !~ '^pg_'
- AND c.relname !~ '^Inv' and a.attnum > 0
- AND a.attrelid = c.oid and a.atttypid = t.oid
- AND a.attisdropped = 'f'
- ORDER BY relname, attname""")
- return result
-
-# list all user defined base type
-def list_user_base_type(pgcnx):
- result = pgcnx.query("""SELECT u.usename, t.typname
- FROM pg_type t, pg_user u
- WHERE u.usesysid = int2in(int4out(t.typowner))
- AND t.typrelid = '0'::oid and t.typelem = '0'::oid
- AND u.usename <> 'postgres' order by usename, typname""")
- return result
-
-# list all right-unary operators
-def list_right_unary_operator(pgcnx):
- result = pgcnx.query("""SELECT o.oprname AS right_unary,
- lt.typname AS operand, result.typname AS return_type
- FROM pg_operator o, pg_type lt, pg_type result
- WHERE o.oprkind='r' and o.oprleft = lt.oid
- AND o.oprresult = result.oid
- ORDER BY operand""")
- return result
-
-# list all left-unary operators
-def list_left_unary_operator(pgcnx):
- result = pgcnx.query("""SELECT o.oprname AS left_unary,
- rt.typname AS operand, result.typname AS return_type
- FROM pg_operator o, pg_type rt, pg_type result
- WHERE o.oprkind='l' AND o.oprright = rt.oid
- AND o.oprresult = result.oid
- ORDER BY operand""")
- return result
-
-# list all binary operators
-def list_binary_operator(pgcnx):
- result = pgcnx.query("""SELECT o.oprname AS binary_op,
- rt.typname AS right_opr, lt.typname AS left_opr,
- result.typname AS return_type
- FROM pg_operator o, pg_type rt, pg_type lt, pg_type result
- WHERE o.oprkind = 'b' AND o.oprright = rt.oid
- AND o.oprleft = lt.oid AND o.oprresult = result.oid""")
- return result
-
-# returns the name, args and return type from all function of lang l
-def list_lang_func(pgcnx, l):
- result = pgcnx.query("""SELECT p.proname, p.pronargs, t.typname
- FROM pg_proc p, pg_language l, pg_type t
- WHERE p.prolang = l.oid AND p.prorettype = t.oid
- AND l.lanname = '%s'
- ORDER BY proname""" % l)
- return result
-
-# lists all the aggregate functions and the type to which they can be applied
-def list_agg_func(pgcnx):
- result = pgcnx.query("""SELECT p.proname, t.typname
- FROM pg_aggregate a, pg_proc p, pg_type t
- WHERE a.aggfnoid = p.oid
- and p.proargtypes[0] = t.oid
- ORDER BY proname, typname""")
- return result
-
-# lists all the operator classes that can be used with each access method as
-# well as the operators that can be used with the respective operator classes
-def list_op_class(pgcnx):
- result = pgcnx.query("""SELECT am.amname, opc.opcname, opr.oprname
- FROM pg_am am, pg_amop amop, pg_opclass opc, pg_operator opr
- WHERE amop.amopid = am.oid and amop.amopclaid = opc.oid
- AND amop.amopopr = opr.oid order by amname, opcname, oprname""")
- return result
-
-# demo function - runs all examples
-def demo(pgcnx):
- import sys, os
- save_stdout = sys.stdout
- sys.stdout = os.popen("more", "w")
- print "Listing simple indices ..."
- print list_simple_ind(pgcnx)
- print "Listing all attributes ..."
- print list_all_attr(pgcnx)
- print "Listing all user-defined base types ..."
- print list_user_base_type(pgcnx)
- print "Listing all left-unary operators defined ..."
- print list_left_unary_operator(pgcnx)
- print "Listing all right-unary operators defined ..."
- print list_right_unary_operator(pgcnx)
- print "Listing all binary operators ..."
- print list_binary_operator(pgcnx)
- print "Listing C external function linked ..."
- print list_lang_func(pgcnx, 'C')
- print "Listing C internal functions ..."
- print list_lang_func(pgcnx, 'internal')
- print "Listing SQL functions defined ..."
- print list_lang_func(pgcnx, 'sql')
- print "Listing 'aggregate functions' ..."
- print list_agg_func(pgcnx)
- print "Listing 'operator classes' ..."
- print list_op_class(pgcnx)
- del sys.stdout
- sys.stdout = save_stdout
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/epydoc-3.0.1.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/epydoc-3.0.1.tar.gz b/tools/bin/pythonSrc/epydoc-3.0.1.tar.gz
deleted file mode 100644
index 97447c5..0000000
Binary files a/tools/bin/pythonSrc/epydoc-3.0.1.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/lockfile-0.9.1.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/lockfile-0.9.1.tar.gz b/tools/bin/pythonSrc/lockfile-0.9.1.tar.gz
deleted file mode 100644
index 747d02a..0000000
Binary files a/tools/bin/pythonSrc/lockfile-0.9.1.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/logilab-astng-0.20.1.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/logilab-astng-0.20.1.tar.gz b/tools/bin/pythonSrc/logilab-astng-0.20.1.tar.gz
deleted file mode 100644
index 49aa1a3..0000000
Binary files a/tools/bin/pythonSrc/logilab-astng-0.20.1.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/logilab-common-0.50.1.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/logilab-common-0.50.1.tar.gz b/tools/bin/pythonSrc/logilab-common-0.50.1.tar.gz
deleted file mode 100644
index 65ec3ed..0000000
Binary files a/tools/bin/pythonSrc/logilab-common-0.50.1.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/paramiko-1.7.6-9.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/paramiko-1.7.6-9.tar.gz b/tools/bin/pythonSrc/paramiko-1.7.6-9.tar.gz
deleted file mode 100644
index 25fa92d..0000000
Binary files a/tools/bin/pythonSrc/paramiko-1.7.6-9.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/pychecker-0.8.18.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pychecker-0.8.18.tar.gz b/tools/bin/pythonSrc/pychecker-0.8.18.tar.gz
deleted file mode 100644
index a1498fe..0000000
Binary files a/tools/bin/pythonSrc/pychecker-0.8.18.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/pycrypto-2.0.1.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pycrypto-2.0.1.tar.gz b/tools/bin/pythonSrc/pycrypto-2.0.1.tar.gz
deleted file mode 100644
index e40d950..0000000
Binary files a/tools/bin/pythonSrc/pycrypto-2.0.1.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/pylint-0.21.0.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pylint-0.21.0.tar.gz b/tools/bin/pythonSrc/pylint-0.21.0.tar.gz
deleted file mode 100644
index cf876d3..0000000
Binary files a/tools/bin/pythonSrc/pylint-0.21.0.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/unittest2-0.5.1.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/unittest2-0.5.1.tar.gz b/tools/bin/pythonSrc/unittest2-0.5.1.tar.gz
deleted file mode 100644
index fad2ab2..0000000
Binary files a/tools/bin/pythonSrc/unittest2-0.5.1.tar.gz and /dev/null differ
[02/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/pgmodule.c
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/pgmodule.c b/tools/bin/pythonSrc/PyGreSQL-4.0/pgmodule.c
deleted file mode 100644
index fbff317..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/pgmodule.c
+++ /dev/null
@@ -1,3756 +0,0 @@
-/*
- * $Id: pgmodule.c,v 1.90 2008/12/03 00:17:15 cito Exp $
- * PyGres, version 2.2 A Python interface for PostgreSQL database. Written by
- * D'Arcy J.M. Cain, (darcy@druid.net). Based heavily on code written by
- * Pascal Andre, andre@chimay.via.ecp.fr. Copyright (c) 1995, Pascal Andre
- * (andre@via.ecp.fr).
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without a written
- * agreement is hereby granted, provided that the above copyright notice and
- * this paragraph and the following two paragraphs appear in all copies or in
- * any new file that contains a substantial portion of this file.
- *
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
- * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
- * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
- * AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
- * AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
- * ENHANCEMENTS, OR MODIFICATIONS.
- *
- * Further modifications copyright 1997, 1998, 1999 by D'Arcy J.M. Cain
- * (darcy@druid.net) subject to the same terms and conditions as above.
- *
- */
-
-/* Note: This should be linked against the same C runtime lib as Python */
-
-#include "postgres.h"
-#include "libpq-fe.h"
-#include "libpq/libpq-fs.h"
-#include "catalog/pg_type.h"
-
-/* these will be defined in Python.h again: */
-#undef _POSIX_C_SOURCE
-#undef HAVE_STRERROR
-#undef snprintf
-#undef vsnprintf
-
-#include <Python.h>
-
-static PyObject *Error, *Warning, *InterfaceError,
- *DatabaseError, *InternalError, *OperationalError, *ProgrammingError,
- *IntegrityError, *DataError, *NotSupportedError;
-
-static const char *PyPgVersion = "4.0";
-
-#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
-typedef int Py_ssize_t;
-#define PY_SSIZE_T_MAX INT_MAX
-#define PY_SSIZE_T_MIN INT_MIN
-#endif
-
-/* taken from fileobject.c */
-#define BUF(v) PyString_AS_STRING((PyStringObject *)(v))
-
-/* default values */
-#define MODULE_NAME "pgsql"
-#define PG_ARRAYSIZE 1
-
-/* flags for object validity checks */
-#define CHECK_OPEN 1
-#define CHECK_CLOSE 2
-#define CHECK_CNX 4
-#define CHECK_RESULT 8
-#define CHECK_DQL 16
-
-/* query result types */
-#define RESULT_EMPTY 1
-#define RESULT_DML 2
-#define RESULT_DDL 3
-#define RESULT_DQL 4
-
-/* flags for move methods */
-#define QUERY_MOVEFIRST 1
-#define QUERY_MOVELAST 2
-#define QUERY_MOVENEXT 3
-#define QUERY_MOVEPREV 4
-
-/* moves names for errors */
-const char *__movename[5] =
-{"", "movefirst", "movelast", "movenext", "moveprev"};
-
-#define MAX_BUFFER_SIZE 8192 /* maximum transaction size */
-
-#ifndef NO_DIRECT
-#define DIRECT_ACCESS 1 /* enables direct access functions */
-#endif
-
-#ifndef NO_LARGE
-#define LARGE_OBJECTS 1 /* enables large objects support */
-#endif
-
-#ifndef NO_DEF_VAR
-#define DEFAULT_VARS 1 /* enables default variables use */
-#endif
-
-#ifndef NO_NOTICES
-#define HANDLE_NOTICES 1 /* enables notices handling */
-#endif /* NO_NOTICES */
-
-#ifndef PG_VERSION_NUM
-#ifdef PQnoPasswordSupplied
-#define PG_VERSION_NUM 80000
-#else
-#define PG_VERSION_NUM 70400
-#endif
-#endif
-
-/* Before 8.0, PQsetdbLogin was not thread-safe with kerberos. */
-#if PG_VERSION_NUM >= 80000 || !(defined(KRB4) || defined(KRB5))
-#define PQsetdbLoginIsThreadSafe 1
-#endif
-
-/* --------------------------------------------------------------------- */
-
-/* MODULE GLOBAL VARIABLES */
-
-#ifdef DEFAULT_VARS
-
-static PyObject *pg_default_host; /* default database host */
-static PyObject *pg_default_base; /* default database name */
-static PyObject *pg_default_opt; /* default connection options */
-static PyObject *pg_default_tty; /* default debug tty */
-static PyObject *pg_default_port; /* default connection port */
-static PyObject *pg_default_user; /* default username */
-static PyObject *pg_default_passwd; /* default password */
-#endif /* DEFAULT_VARS */
-
-#ifdef HANDLE_NOTICES
-#define MAX_BUFFERED_NOTICES 101 /* max notices (+1) to keep for each connection */
-static void notice_processor(void * arg, const char * message);
-#endif /* HANDLE_NOTICES */
-
-DL_EXPORT(void) init_pg(void);
-int *get_type_array(PGresult *result, int nfields);
-
-static PyObject *decimal = NULL; /* decimal type */
-
-/* --------------------------------------------------------------------- */
-/* OBJECTS DECLARATION */
-
-/* pg connection object */
-
-typedef struct
-{
- PyObject_HEAD
- int valid; /* validity flag */
- PGconn *cnx; /* PostGres connection handle */
- PGresult *last_result; /* last result content */
-#ifdef HANDLE_NOTICES
- char **notices; /* dynamically allocated circular buffer for notices */
- int notices_first; /* index of first filled index in notices */
- int notices_next; /* index of first free index in notices */
-#endif /* HANDLE_NOTICES */
-} pgobject;
-
-staticforward PyTypeObject PgType;
-
-#define is_pgobject(v) ((v)->ob_type == &PgType)
-
-static PyObject *
-pgobject_New(void)
-{
- pgobject *pgobj;
-
- if ((pgobj = PyObject_NEW(pgobject, &PgType)) == NULL)
- return NULL;
-
- pgobj->valid = 1;
- pgobj->last_result = NULL;
- pgobj->cnx = NULL;
- pgobj->notices = malloc(sizeof(char*) * MAX_BUFFERED_NOTICES);
- pgobj->notices_first = 0;
- pgobj->notices_next = 0;
- return (PyObject *) pgobj;
-}
-
-/* pg query object */
-
-typedef struct
-{
- PyObject_HEAD
- PGresult *last_result; /* last result content */
- int result_type; /* type of previous result */
- long current_pos; /* current position in last result */
- long num_rows; /* number of (affected) rows */
-} pgqueryobject;
-
-staticforward PyTypeObject PgQueryType;
-
-#define is_pgqueryobject(v) ((v)->ob_type == &PgQueryType)
-
-/* pg source object */
-
-typedef struct
-{
- PyObject_HEAD
- int valid; /* validity flag */
- pgobject *pgcnx; /* parent connection object */
- PGresult *last_result; /* last result content */
- int result_type; /* result type (DDL/DML/DQL) */
- long arraysize; /* array size for fetch method */
- int current_row; /* current selected row */
- int max_row; /* number of rows in the result */
- int num_fields; /* number of fields in each row */
-} pgsourceobject;
-
-staticforward PyTypeObject PgSourceType;
-
-#define is_pgsourceobject(v) ((v)->ob_type == &PgSourceType)
-
-
-#ifdef LARGE_OBJECTS
-/* pg large object */
-
-typedef struct
-{
- PyObject_HEAD
- pgobject *pgcnx; /* parent connection object */
- Oid lo_oid; /* large object oid */
- int lo_fd; /* large object fd */
-} pglargeobject;
-
-staticforward PyTypeObject PglargeType;
-
-#define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
-#endif /* LARGE_OBJECTS */
-
-/* --------------------------------------------------------------------- */
-/* INTERNAL FUNCTIONS */
-
-
-/* prints result (mostly useful for debugging) */
-/* Note: This is a simplified version of the Postgres function PQprint().
- * PQprint() is not used because handing over a stream from Python to
- * Postgres can be problematic if they use different libs for streams.
- * Also, PQprint() is considered obsolete and may be removed sometime.
- */
-static void
-print_result(FILE *fout, const PGresult *res)
-{
- int n = PQnfields(res);
- if (n > 0)
- {
- int i, j;
- int *fieldMax = NULL;
- char **fields = NULL;
- const char **fieldNames;
- int m = PQntuples(res);
- if (!(fieldNames = (const char **) calloc(n, sizeof(char *))))
- {
- fprintf(stderr, "out of memory\n"); exit(1);
- }
- if (!(fieldMax = (int *) calloc(n, sizeof(int))))
- {
- fprintf(stderr, "out of memory\n"); exit(1);
- }
- for (j = 0; j < n; j++)
- {
- const char *s = PQfname(res, j);
- fieldNames[j] = s;
- fieldMax[j] = s ? strlen(s) : 0;
- }
- if (!(fields = (char **) calloc(n * (m + 1), sizeof(char *))))
- {
- fprintf(stderr, "out of memory\n"); exit(1);
- }
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- {
- const char *val;
- int len;
- len = PQgetlength(res, i, j);
- val = PQgetvalue(res, i, j);
- if (len >= 1 && val && *val)
- {
- if (len > fieldMax[j])
- fieldMax[j] = len;
- if (!(fields[i * n + j] = (char *) malloc(len + 1)))
- {
- fprintf(stderr, "out of memory\n"); exit(1);
- }
- strcpy(fields[i * n + j], val);
- }
- }
- }
- for (j = 0; j < n; j++)
- {
- const char *s = PQfname(res, j);
- int len = strlen(s);
- if (len > fieldMax[j])
- fieldMax[j] = len;
- fprintf(fout, "%-*s", fieldMax[j], s);
- if (j + 1 < n)
- fputc('|', fout);
- }
- fputc('\n', fout);
- for (j = 0; j < n; j++)
- {
- for (i = fieldMax[j]; i--; fputc('-', fout));
- if (j + 1 < n)
- fputc('+', fout);
- }
- fputc('\n', fout);
- for (i = 0; i < m; i++)
- {
- for (j = 0; j < n; j++)
- {
- char *s = fields[i * n + j];
- fprintf(fout, "%-*s", fieldMax[j], s ? s : "");
- if (j + 1 < n)
- fputc('|', fout);
- if (s)
- free(s);
- }
- fputc('\n', fout);
- }
- free(fields);
- fprintf(fout, "(%d row%s)\n\n", m, m == 1 ? "" : "s");
- free(fieldMax);
- free((void *) fieldNames);
- }
-}
-
-/* checks connection validity */
-static int
-check_cnx_obj(pgobject * self)
-{
- if (!self->valid)
- {
- PyErr_SetString(IntegrityError, "connection has been closed.");
- return 0;
- }
- return 1;
-}
-
-#ifdef LARGE_OBJECTS
-/* checks large object validity */
-static int
-check_lo_obj(pglargeobject * self, int level)
-{
- if (!check_cnx_obj(self->pgcnx))
- return 0;
-
- if (!self->lo_oid)
- {
- PyErr_SetString(IntegrityError, "object is not valid (null oid).");
- return 0;
- }
-
- if (level & CHECK_OPEN)
- {
- if (self->lo_fd < 0)
- {
- PyErr_SetString(PyExc_IOError, "object is not opened.");
- return 0;
- }
- }
-
- if (level & CHECK_CLOSE)
- {
- if (self->lo_fd >= 0)
- {
- PyErr_SetString(PyExc_IOError, "object is already opened.");
- return 0;
- }
- }
-
- return 1;
-}
-#endif /* LARGE_OBJECTS */
-
-/* checks source object validity */
-static int
-check_source_obj(pgsourceobject * self, int level)
-{
- if (!self->valid)
- {
- PyErr_SetString(IntegrityError, "object has been closed");
- return 0;
- }
-
- if ((level & CHECK_RESULT) && self->last_result == NULL)
- {
- PyErr_SetString(DatabaseError, "no result.");
- return 0;
- }
-
- if ((level & CHECK_DQL) && self->result_type != RESULT_DQL)
- {
- PyErr_SetString(DatabaseError, "last query did not return tuples.");
- return 0;
- }
-
- if ((level & CHECK_CNX) && !check_cnx_obj(self->pgcnx))
- return 0;
-
- return 1;
-}
-
-/* shared functions for converting PG types to Python types */
-int *
-get_type_array(PGresult *result, int nfields)
-{
- int *typ;
- int j;
-
- if ((typ = malloc(sizeof(int) * nfields)) == NULL)
- {
- PyErr_SetString(PyExc_MemoryError, "memory error in getresult().");
- return NULL;
- }
-
- for (j = 0; j < nfields; j++)
- {
- switch (PQftype(result, j))
- {
- case INT2OID:
- case INT4OID:
- case OIDOID:
- typ[j] = 1;
- break;
-
- case INT8OID:
- typ[j] = 2;
- break;
-
- case FLOAT4OID:
- case FLOAT8OID:
- typ[j] = 3;
- break;
-
- case NUMERICOID:
- typ[j] = 4;
- break;
-
- case CASHOID:
- typ[j] = 5;
- break;
-
- default:
- typ[j] = 6;
- break;
- }
- }
-
- return typ;
-}
-
-
-/* prototypes for constructors */
-static pgsourceobject *pgsource_new(pgobject * pgcnx);
-
-/* --------------------------------------------------------------------- */
-/* PG SOURCE OBJECT IMPLEMENTATION */
-
-/* constructor (internal use only) */
-static pgsourceobject *
-pgsource_new(pgobject * pgcnx)
-{
- pgsourceobject *npgobj;
-
- /* allocates new query object */
- if ((npgobj = PyObject_NEW(pgsourceobject, &PgSourceType)) == NULL)
- return NULL;
-
- /* initializes internal parameters */
- Py_XINCREF(pgcnx);
- npgobj->pgcnx = pgcnx;
- npgobj->last_result = NULL;
- npgobj->valid = 1;
- npgobj->arraysize = PG_ARRAYSIZE;
-
- return npgobj;
-}
-
-/* destructor */
-static void
-pgsource_dealloc(pgsourceobject * self)
-{
- if (self->last_result)
- PQclear(self->last_result);
-
- Py_XDECREF(self->pgcnx);
- PyObject_Del(self);
-}
-
-/* closes object */
-static char pgsource_close__doc__[] =
-"close() -- close query object without deleting it. "
-"All instances of the query object can no longer be used after this call.";
-
-static PyObject *
-pgsource_close(pgsourceobject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError, "method close() takes no parameter.");
- return NULL;
- }
-
- /* frees result if necessary and invalidates object */
- if (self->last_result)
- {
- PQclear(self->last_result);
- self->result_type = RESULT_EMPTY;
- self->last_result = NULL;
- }
-
- self->valid = 0;
-
- /* return None */
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* database query */
-static char pgsource_execute__doc__[] =
-"execute(sql) -- execute a SQL statement (string).\n "
-"On success, this call returns the number of affected rows, "
-"or None for DQL (SELECT, ...) statements.\n"
-"The fetch (fetch(), fetchone() and fetchall()) methods can be used "
-"to get result rows.";
-
-static PyObject *
-pgsource_execute(pgsourceobject * self, PyObject * args)
-{
- char *query;
-
- /* checks validity */
- if (!check_source_obj(self, CHECK_CNX))
- return NULL;
-
- /* make sure that the connection object is valid */
- if (!self->pgcnx->cnx)
- return NULL;
-
- /* get query args */
- if (!PyArg_ParseTuple(args, "s", &query))
- {
- PyErr_SetString(PyExc_TypeError, "execute(sql), with sql (string).");
- return NULL;
- }
-
- /* frees previous result */
- if (self->last_result)
- {
- PQclear(self->last_result);
- self->last_result = NULL;
- }
- self->max_row = 0;
- self->current_row = 0;
- self->num_fields = 0;
-
- /* gets result */
- Py_BEGIN_ALLOW_THREADS
- self->last_result = PQexec(self->pgcnx->cnx, query);
- Py_END_ALLOW_THREADS
-
- /* checks result validity */
- if (!self->last_result)
- {
- PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->pgcnx->cnx));
- return NULL;
- }
-
- /* checks result status */
- switch (PQresultStatus(self->last_result))
- {
- long num_rows;
- char *temp;
-
- /* query succeeded */
- case PGRES_TUPLES_OK: /* DQL: returns None (DB-SIG compliant) */
- self->result_type = RESULT_DQL;
- self->max_row = PQntuples(self->last_result);
- self->num_fields = PQnfields(self->last_result);
- Py_INCREF(Py_None);
- return Py_None;
- case PGRES_COMMAND_OK: /* other requests */
- case PGRES_COPY_OUT:
- case PGRES_COPY_IN:
- self->result_type = RESULT_DDL;
- temp = PQcmdTuples(self->last_result);
- num_rows = -1;
- if (temp[0])
- {
- self->result_type = RESULT_DML;
- num_rows = atol(temp);
- }
- return PyInt_FromLong(num_rows);
-
- /* query failed */
- case PGRES_EMPTY_QUERY:
- PyErr_SetString(PyExc_ValueError, "empty query.");
- break;
- case PGRES_BAD_RESPONSE:
- case PGRES_FATAL_ERROR:
- case PGRES_NONFATAL_ERROR:
- PyErr_SetString(ProgrammingError, PQerrorMessage(self->pgcnx->cnx));
- break;
- default:
- PyErr_SetString(InternalError, "internal error: "
- "unknown result status.");
- break;
- }
-
- /* frees result and returns error */
- PQclear(self->last_result);
- self->last_result = NULL;
- self->result_type = RESULT_EMPTY;
- return NULL;
-}
-
-/* gets oid status for last query (valid for INSERTs, 0 for other) */
-static char pgsource_oidstatus__doc__[] =
-"oidstatus() -- return oid of last inserted row (if available).";
-
-static PyObject *
-pgsource_oidstatus(pgsourceobject * self, PyObject * args)
-{
- Oid oid;
-
- /* checks validity */
- if (!check_source_obj(self, CHECK_RESULT))
- return NULL;
-
- /* checks args */
- if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
- {
- PyErr_SetString(PyExc_TypeError,
- "method oidstatus() takes no parameters.");
- return NULL;
- }
-
- /* retrieves oid status */
- if ((oid = PQoidValue(self->last_result)) == InvalidOid)
- {
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- return PyInt_FromLong(oid);
-}
-
-/* fetches rows from last result */
-static char pgsource_fetch__doc__[] =
-"fetch(num) -- return the next num rows from the last result in a list. "
-"If num parameter is omitted arraysize attribute value is used. "
-"If size equals -1, all rows are fetched.";
-
-static PyObject *
-pgsource_fetch(pgsourceobject * self, PyObject * args)
-{
- PyObject *rowtuple,
- *reslist,
- *str;
- int i,
- j;
- long size;
-
- /* checks validity */
- if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
- return NULL;
-
- /* checks args */
- size = self->arraysize;
- if (!PyArg_ParseTuple(args, "|l", &size))
- {
- PyErr_SetString(PyExc_TypeError,
- "fetch(num), with num (integer, optional).");
- return NULL;
- }
-
- /* seeks last line */
- /* limit size to be within the amount of data we actually have */
- if (size == -1 || (self->max_row - self->current_row) < size)
- size = self->max_row - self->current_row;
-
- /* allocate list for result */
- if ((reslist = PyList_New(0)) == NULL)
- return NULL;
-
- /* builds result */
- for (i = 0; i < size; ++i)
- {
- if ((rowtuple = PyTuple_New(self->num_fields)) == NULL)
- {
- Py_DECREF(reslist);
- return NULL;
- }
-
- for (j = 0; j < self->num_fields; j++)
- {
- if (PQgetisnull(self->last_result, self->current_row, j))
- {
- Py_INCREF(Py_None);
- str = Py_None;
- }
- else
- str = PyString_FromString(PQgetvalue(self->last_result, self->current_row, j));
-
- PyTuple_SET_ITEM(rowtuple, j, str);
- }
-
- PyList_Append(reslist, rowtuple);
- Py_DECREF(rowtuple);
- self->current_row++;
- }
-
- return reslist;
-}
-
-/* changes current row (internal wrapper for all "move" methods) */
-static PyObject *
-pgsource_move(pgsourceobject * self, PyObject * args, int move)
-{
- /* checks validity */
- if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
- return NULL;
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- char errbuf[256];
- PyOS_snprintf(errbuf, sizeof(errbuf),
- "method %s() takes no parameter.", __movename[move]);
- PyErr_SetString(PyExc_TypeError, errbuf);
- return NULL;
- }
-
- /* changes the current row */
- switch (move)
- {
- case QUERY_MOVEFIRST:
- self->current_row = 0;
- break;
- case QUERY_MOVELAST:
- self->current_row = self->max_row - 1;
- break;
- case QUERY_MOVENEXT:
- if (self->current_row != self->max_row)
- self->current_row++;
- break;
- case QUERY_MOVEPREV:
- if (self->current_row > 0)
- self->current_row--;
- break;
- }
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* move to first result row */
-static char pgsource_movefirst__doc__[] =
-"movefirst() -- move to first result row.";
-
-static PyObject *
-pgsource_movefirst(pgsourceobject * self, PyObject * args)
-{
- return pgsource_move(self, args, QUERY_MOVEFIRST);
-}
-
-/* move to last result row */
-static char pgsource_movelast__doc__[] =
-"movelast() -- move to last valid result row.";
-
-static PyObject *
-pgsource_movelast(pgsourceobject * self, PyObject * args)
-{
- return pgsource_move(self, args, QUERY_MOVELAST);
-}
-
-/* move to next result row */
-static char pgsource_movenext__doc__[] =
-"movenext() -- move to next result row.";
-
-static PyObject *
-pgsource_movenext(pgsourceobject * self, PyObject * args)
-{
- return pgsource_move(self, args, QUERY_MOVENEXT);
-}
-
-/* move to previous result row */
-static char pgsource_moveprev__doc__[] =
-"moveprev() -- move to previous result row.";
-
-static PyObject *
-pgsource_moveprev(pgsourceobject * self, PyObject * args)
-{
- return pgsource_move(self, args, QUERY_MOVEPREV);
-}
-
-/* finds field number from string/integer (internal use only) */
-static int
-pgsource_fieldindex(pgsourceobject * self, PyObject * param, const char *usage)
-{
- int num;
-
- /* checks validity */
- if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
- return -1;
-
- /* gets field number */
- if (PyString_Check(param))
- num = PQfnumber(self->last_result, PyString_AsString(param));
- else if (PyInt_Check(param))
- num = PyInt_AsLong(param);
- else
- {
- PyErr_SetString(PyExc_TypeError, usage);
- return -1;
- }
-
- /* checks field validity */
- if (num < 0 || num >= self->num_fields)
- {
- PyErr_SetString(PyExc_ValueError, "Unknown field.");
- return -1;
- }
-
- return num;
-}
-
-/* builds field information from position (internal use only) */
-static PyObject *
-pgsource_buildinfo(pgsourceobject * self, int num)
-{
- PyObject *result;
-
- /* allocates tuple */
- result = PyTuple_New(3);
- if (!result)
- return NULL;
-
- /* affects field information */
- PyTuple_SET_ITEM(result, 0, PyInt_FromLong(num));
- PyTuple_SET_ITEM(result, 1,
- PyString_FromString(PQfname(self->last_result, num)));
- PyTuple_SET_ITEM(result, 2,
- PyInt_FromLong(PQftype(self->last_result, num)));
-
- return result;
-}
-
-/* lists fields info */
-static char pgsource_listinfo__doc__[] =
-"listinfo() -- return information for all fields "
-"(position, name, type oid).";
-
-static PyObject *
-pgsource_listinfo(pgsourceobject * self, PyObject * args)
-{
- int i;
- PyObject *result,
- *info;
-
- /* checks validity */
- if (!check_source_obj(self, CHECK_RESULT | CHECK_DQL))
- return NULL;
-
- /* gets args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method listinfo() takes no parameter.");
- return NULL;
- }
-
- /* builds result */
- if ((result = PyTuple_New(self->num_fields)) == NULL)
- return NULL;
-
- for (i = 0; i < self->num_fields; i++)
- {
- info = pgsource_buildinfo(self, i);
- if (!info)
- {
- Py_DECREF(result);
- return NULL;
- }
- PyTuple_SET_ITEM(result, i, info);
- }
-
- /* returns result */
- return result;
-};
-
-/* list fields information for last result */
-static char pgsource_fieldinfo__doc__[] =
-"fieldinfo(string|integer) -- return specified field information "
-"(position, name, type oid).";
-
-static PyObject *
-pgsource_fieldinfo(pgsourceobject * self, PyObject * args)
-{
- static const char short_usage[] =
- "fieldinfo(desc), with desc (string|integer).";
- int num;
- PyObject *param;
-
- /* gets args */
- if (!PyArg_ParseTuple(args, "O", ¶m))
- {
- PyErr_SetString(PyExc_TypeError, short_usage);
- return NULL;
- }
-
- /* checks args and validity */
- if ((num = pgsource_fieldindex(self, param, short_usage)) == -1)
- return NULL;
-
- /* returns result */
- return pgsource_buildinfo(self, num);
-};
-
-/* retrieve field value */
-static char pgsource_field__doc__[] =
-"field(string|integer) -- return specified field value.";
-
-static PyObject *
-pgsource_field(pgsourceobject * self, PyObject * args)
-{
- static const char short_usage[] =
- "field(desc), with desc (string|integer).";
- int num;
- PyObject *param;
-
- /* gets args */
- if (!PyArg_ParseTuple(args, "O", ¶m))
- {
- PyErr_SetString(PyExc_TypeError, short_usage);
- return NULL;
- }
-
- /* checks args and validity */
- if ((num = pgsource_fieldindex(self, param, short_usage)) == -1)
- return NULL;
-
- return PyString_FromString(PQgetvalue(self->last_result,
- self->current_row, num));
-}
-
-/* query object methods */
-static PyMethodDef pgsource_methods[] = {
- {"close", (PyCFunction) pgsource_close, METH_VARARGS,
- pgsource_close__doc__},
- {"execute", (PyCFunction) pgsource_execute, METH_VARARGS,
- pgsource_execute__doc__},
- {"oidstatus", (PyCFunction) pgsource_oidstatus, METH_VARARGS,
- pgsource_oidstatus__doc__},
- {"fetch", (PyCFunction) pgsource_fetch, METH_VARARGS,
- pgsource_fetch__doc__},
- {"movefirst", (PyCFunction) pgsource_movefirst, METH_VARARGS,
- pgsource_movefirst__doc__},
- {"movelast", (PyCFunction) pgsource_movelast, METH_VARARGS,
- pgsource_movelast__doc__},
- {"movenext", (PyCFunction) pgsource_movenext, METH_VARARGS,
- pgsource_movenext__doc__},
- {"moveprev", (PyCFunction) pgsource_moveprev, METH_VARARGS,
- pgsource_moveprev__doc__},
- {"field", (PyCFunction) pgsource_field, METH_VARARGS,
- pgsource_field__doc__},
- {"fieldinfo", (PyCFunction) pgsource_fieldinfo, METH_VARARGS,
- pgsource_fieldinfo__doc__},
- {"listinfo", (PyCFunction) pgsource_listinfo, METH_VARARGS,
- pgsource_listinfo__doc__},
- {NULL, NULL}
-};
-
-/* gets query object attributes */
-static PyObject *
-pgsource_getattr(pgsourceobject * self, char *name)
-{
- /* pg connection object */
- if (!strcmp(name, "pgcnx"))
- {
- if (check_source_obj(self, 0))
- {
- Py_INCREF(self->pgcnx);
- return (PyObject *) (self->pgcnx);
- }
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- /* arraysize */
- if (!strcmp(name, "arraysize"))
- return PyInt_FromLong(self->arraysize);
-
- /* resulttype */
- if (!strcmp(name, "resulttype"))
- return PyInt_FromLong(self->result_type);
-
- /* ntuples */
- if (!strcmp(name, "ntuples"))
- return PyInt_FromLong(self->max_row);
-
- /* nfields */
- if (!strcmp(name, "nfields"))
- return PyInt_FromLong(self->num_fields);
-
- /* attributes list */
- if (!strcmp(name, "__members__"))
- {
- PyObject *list = PyList_New(5);
-
- PyList_SET_ITEM(list, 0, PyString_FromString("pgcnx"));
- PyList_SET_ITEM(list, 1, PyString_FromString("arraysize"));
- PyList_SET_ITEM(list, 2, PyString_FromString("resulttype"));
- PyList_SET_ITEM(list, 3, PyString_FromString("ntuples"));
- PyList_SET_ITEM(list, 4, PyString_FromString("nfields"));
-
- return list;
- }
-
- /* module name */
- if (!strcmp(name, "__module__"))
- return PyString_FromString(MODULE_NAME);
-
- /* class name */
- if (!strcmp(name, "__class__"))
- return PyString_FromString("pgsource");
-
- /* seeks name in methods (fallback) */
- return Py_FindMethod(pgsource_methods, (PyObject *) self, name);
-}
-
-/* sets query object attributes */
-static int
-pgsource_setattr(pgsourceobject * self, char *name, PyObject * v)
-{
- /* arraysize */
- if (!strcmp(name, "arraysize"))
- {
- if (!PyInt_Check(v))
- {
- PyErr_SetString(PyExc_TypeError, "arraysize must be integer.");
- return -1;
- }
-
- self->arraysize = PyInt_AsLong(v);
- return 0;
- }
-
- /* unknown attribute */
- PyErr_SetString(PyExc_TypeError, "not a writable attribute.");
- return -1;
-}
-
-/* prints query object in human readable format */
-
-static int
-pgsource_print(pgsourceobject * self, FILE *fp, int flags)
-{
- switch (self->result_type)
- {
- case RESULT_DQL:
- print_result(fp, self->last_result);
- break;
- case RESULT_DDL:
- case RESULT_DML:
- fputs(PQcmdStatus(self->last_result), fp);
- break;
- case RESULT_EMPTY:
- default:
- fputs("Empty PostgreSQL source object.", fp);
- break;
- }
-
- return 0;
-}
-
-/* query type definition */
-staticforward PyTypeObject PgSourceType = {
- PyObject_HEAD_INIT(NULL)
-
- 0, /* ob_size */
- "pgsourceobject", /* tp_name */
- sizeof(pgsourceobject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor) pgsource_dealloc, /* tp_dealloc */
- (printfunc) pgsource_print, /* tp_print */
- (getattrfunc) pgsource_getattr, /* tp_getattr */
- (setattrfunc) pgsource_setattr, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
-};
-
-/* --------------------------------------------------------------------- */
-/* PG "LARGE" OBJECT IMPLEMENTATION */
-
-#ifdef LARGE_OBJECTS
-
-/* constructor (internal use only) */
-static pglargeobject *
-pglarge_new(pgobject * pgcnx, Oid oid)
-{
- pglargeobject *npglo;
-
- if ((npglo = PyObject_NEW(pglargeobject, &PglargeType)) == NULL)
- return NULL;
-
- Py_XINCREF(pgcnx);
- npglo->pgcnx = pgcnx;
- npglo->lo_fd = -1;
- npglo->lo_oid = oid;
-
- return npglo;
-}
-
-/* destructor */
-static void
-pglarge_dealloc(pglargeobject * self)
-{
- if (self->lo_fd >= 0 && check_cnx_obj(self->pgcnx))
- lo_close(self->pgcnx->cnx, self->lo_fd);
-
- Py_XDECREF(self->pgcnx);
- PyObject_Del(self);
-}
-
-/* opens large object */
-static char pglarge_open__doc__[] =
-"open(mode) -- open access to large object with specified mode "
-"(INV_READ, INV_WRITE constants defined by module).";
-
-static PyObject *
-pglarge_open(pglargeobject * self, PyObject * args)
-{
- int mode,
- fd;
-
- /* check validity */
- if (!check_lo_obj(self, CHECK_CLOSE))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "i", &mode))
- {
- PyErr_SetString(PyExc_TypeError, "open(mode), with mode(integer).");
- return NULL;
- }
-
- /* opens large object */
- if ((fd = lo_open(self->pgcnx->cnx, self->lo_oid, mode)) < 0)
- {
- PyErr_SetString(PyExc_IOError, "can't open large object.");
- return NULL;
- }
- self->lo_fd = fd;
-
- /* no error : returns Py_None */
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* close large object */
-static char pglarge_close__doc__[] =
-"close() -- close access to large object data.";
-
-static PyObject *
-pglarge_close(pglargeobject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method close() takes no parameters.");
- return NULL;
- }
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_OPEN))
- return NULL;
-
- /* closes large object */
- if (lo_close(self->pgcnx->cnx, self->lo_fd))
- {
- PyErr_SetString(PyExc_IOError, "error while closing large object fd.");
- return NULL;
- }
- self->lo_fd = -1;
-
- /* no error : returns Py_None */
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* reads from large object */
-static char pglarge_read__doc__[] =
-"read(integer) -- read from large object to sized string. "
-"Object must be opened in read mode before calling this method.";
-
-static PyObject *
-pglarge_read(pglargeobject * self, PyObject * args)
-{
- int size;
- PyObject *buffer;
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_OPEN))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "i", &size))
- {
- PyErr_SetString(PyExc_TypeError, "read(size), wih size (integer).");
- return NULL;
- }
-
- if (size <= 0)
- {
- PyErr_SetString(PyExc_ValueError, "size must be positive.");
- return NULL;
- }
-
- /* allocate buffer and runs read */
- buffer = PyString_FromStringAndSize((char *) NULL, size);
-
- if ((size = lo_read(self->pgcnx->cnx, self->lo_fd, BUF(buffer), size)) < 0)
- {
- PyErr_SetString(PyExc_IOError, "error while reading.");
- Py_XDECREF(buffer);
- return NULL;
- }
-
- /* resize buffer and returns it */
- _PyString_Resize(&buffer, size);
- return buffer;
-}
-
-/* write to large object */
-static char pglarge_write__doc__[] =
-"write(string) -- write sized string to large object. "
-"Object must be opened in read mode before calling this method.";
-
-static PyObject *
-pglarge_write(pglargeobject * self, PyObject * args)
-{
- char *buffer;
- int size,
- bufsize;
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_OPEN))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "s#", &buffer, &bufsize))
- {
- PyErr_SetString(PyExc_TypeError,
- "write(buffer), with buffer (sized string).");
- return NULL;
- }
-
- /* sends query */
- if ((size = lo_write(self->pgcnx->cnx, self->lo_fd, buffer,
- bufsize)) < bufsize)
- {
- PyErr_SetString(PyExc_IOError, "buffer truncated during write.");
- return NULL;
- }
-
- /* no error : returns Py_None */
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* go to position in large object */
-static char pglarge_seek__doc__[] =
-"seek(off, whence) -- move to specified position. Object must be opened "
-"before calling this method. whence can be SEEK_SET, SEEK_CUR or SEEK_END, "
-"constants defined by module.";
-
-static PyObject *
-pglarge_lseek(pglargeobject * self, PyObject * args)
-{
- /* offset and whence are initialized to keep compiler happy */
- int ret,
- offset = 0,
- whence = 0;
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_OPEN))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "ii", &offset, &whence))
- {
- PyErr_SetString(PyExc_TypeError,
- "lseek(offset, whence), with offset and whence (integers).");
- return NULL;
- }
-
- /* sends query */
- if ((ret = lo_lseek(self->pgcnx->cnx, self->lo_fd, offset, whence)) == -1)
- {
- PyErr_SetString(PyExc_IOError, "error while moving cursor.");
- return NULL;
- }
-
- /* returns position */
- return PyInt_FromLong(ret);
-}
-
-/* gets large object size */
-static char pglarge_size__doc__[] =
-"size() -- return large object size. "
-"Object must be opened before calling this method.";
-
-static PyObject *
-pglarge_size(pglargeobject * self, PyObject * args)
-{
- int start,
- end;
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method size() takes no parameters.");
- return NULL;
- }
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_OPEN))
- return NULL;
-
- /* gets current position */
- if ((start = lo_tell(self->pgcnx->cnx, self->lo_fd)) == -1)
- {
- PyErr_SetString(PyExc_IOError, "error while getting current position.");
- return NULL;
- }
-
- /* gets end position */
- if ((end = lo_lseek(self->pgcnx->cnx, self->lo_fd, 0, SEEK_END)) == -1)
- {
- PyErr_SetString(PyExc_IOError, "error while getting end position.");
- return NULL;
- }
-
- /* move back to start position */
- if ((start = lo_lseek(self->pgcnx->cnx, self->lo_fd, start, SEEK_SET)) == -1)
- {
- PyErr_SetString(PyExc_IOError,
- "error while moving back to first position.");
- return NULL;
- }
-
- /* returns size */
- return PyInt_FromLong(end);
-}
-
-/* gets large object cursor position */
-static char pglarge_tell__doc__[] =
-"tell() -- give current position in large object. "
-"Object must be opened before calling this method.";
-
-static PyObject *
-pglarge_tell(pglargeobject * self, PyObject * args)
-{
- int start;
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method tell() takes no parameters.");
- return NULL;
- }
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_OPEN))
- return NULL;
-
- /* gets current position */
- if ((start = lo_tell(self->pgcnx->cnx, self->lo_fd)) == -1)
- {
- PyErr_SetString(PyExc_IOError, "error while getting position.");
- return NULL;
- }
-
- /* returns size */
- return PyInt_FromLong(start);
-}
-
-/* exports large object as unix file */
-static char pglarge_export__doc__[] =
-"export(string) -- export large object data to specified file. "
-"Object must be closed when calling this method.";
-
-static PyObject *
-pglarge_export(pglargeobject * self, PyObject * args)
-{
- char *name;
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_CLOSE))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "s", &name))
- {
- PyErr_SetString(PyExc_TypeError,
- "export(filename), with filename (string).");
- return NULL;
- }
-
- /* runs command */
- if (!lo_export(self->pgcnx->cnx, self->lo_oid, name))
- {
- PyErr_SetString(PyExc_IOError, "error while exporting large object.");
- return NULL;
- }
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* deletes a large object */
-static char pglarge_unlink__doc__[] =
-"unlink() -- destroy large object. "
-"Object must be closed when calling this method.";
-
-static PyObject *
-pglarge_unlink(pglargeobject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method unlink() takes no parameters.");
- return NULL;
- }
-
- /* checks validity */
- if (!check_lo_obj(self, CHECK_CLOSE))
- return NULL;
-
- /* deletes the object, invalidate it on success */
- if (!lo_unlink(self->pgcnx->cnx, self->lo_oid))
- {
- PyErr_SetString(PyExc_IOError, "error while unlinking large object");
- return NULL;
- }
- self->lo_oid = 0;
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* large object methods */
-static struct PyMethodDef pglarge_methods[] = {
- {"open", (PyCFunction) pglarge_open, METH_VARARGS, pglarge_open__doc__},
- {"close", (PyCFunction) pglarge_close, METH_VARARGS, pglarge_close__doc__},
- {"read", (PyCFunction) pglarge_read, METH_VARARGS, pglarge_read__doc__},
- {"write", (PyCFunction) pglarge_write, METH_VARARGS, pglarge_write__doc__},
- {"seek", (PyCFunction) pglarge_lseek, METH_VARARGS, pglarge_seek__doc__},
- {"size", (PyCFunction) pglarge_size, METH_VARARGS, pglarge_size__doc__},
- {"tell", (PyCFunction) pglarge_tell, METH_VARARGS, pglarge_tell__doc__},
- {"export",(PyCFunction) pglarge_export,METH_VARARGS,pglarge_export__doc__},
- {"unlink",(PyCFunction) pglarge_unlink,METH_VARARGS,pglarge_unlink__doc__},
- {NULL, NULL}
-};
-
-/* get attribute */
-static PyObject *
-pglarge_getattr(pglargeobject * self, char *name)
-{
- /* list postgreSQL large object fields */
-
- /* associated pg connection object */
- if (!strcmp(name, "pgcnx"))
- {
- if (check_lo_obj(self, 0))
- {
- Py_INCREF(self->pgcnx);
- return (PyObject *) (self->pgcnx);
- }
-
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- /* large object oid */
- if (!strcmp(name, "oid"))
- {
- if (check_lo_obj(self, 0))
- return PyInt_FromLong(self->lo_oid);
-
- Py_INCREF(Py_None);
- return Py_None;
- }
-
- /* error (status) message */
- if (!strcmp(name, "error"))
- return PyString_FromString(PQerrorMessage(self->pgcnx->cnx));
-
- /* attributes list */
- if (!strcmp(name, "__members__"))
- {
- PyObject *list = PyList_New(3);
-
- if (list)
- {
- PyList_SET_ITEM(list, 0, PyString_FromString("oid"));
- PyList_SET_ITEM(list, 1, PyString_FromString("pgcnx"));
- PyList_SET_ITEM(list, 2, PyString_FromString("error"));
- }
-
- return list;
- }
-
- /* module name */
- if (!strcmp(name, "__module__"))
- return PyString_FromString(MODULE_NAME);
-
- /* class name */
- if (!strcmp(name, "__class__"))
- return PyString_FromString("pglarge");
-
- /* seeks name in methods (fallback) */
- return Py_FindMethod(pglarge_methods, (PyObject *) self, name);
-}
-
-/* prints query object in human readable format */
-static int
-pglarge_print(pglargeobject * self, FILE *fp, int flags)
-{
- char print_buffer[128];
- PyOS_snprintf(print_buffer, sizeof(print_buffer),
- self->lo_fd >= 0 ?
- "Opened large object, oid %ld" :
- "Closed large object, oid %ld", (long) self->lo_oid);
- fputs(print_buffer, fp);
- return 0;
-}
-
-/* object type definition */
-staticforward PyTypeObject PglargeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pglarge", /* tp_name */
- sizeof(pglargeobject), /* tp_basicsize */
- 0, /* tp_itemsize */
-
- /* methods */
- (destructor) pglarge_dealloc, /* tp_dealloc */
- (printfunc) pglarge_print, /* tp_print */
- (getattrfunc) pglarge_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
-};
-#endif /* LARGE_OBJECTS */
-
-
-/* --------------------------------------------------------------------- */
-/* PG QUERY OBJECT IMPLEMENTATION */
-
-/* connects to a database */
-static char connect__doc__[] =
-"connect(dbname, host, port, opt, tty) -- connect to a PostgreSQL database "
-"using specified parameters (optionals, keywords aware).";
-
-static PyObject *
-pgconnect(pgobject * self, PyObject * args, PyObject * dict)
-{
- static const char *kwlist[] = {"dbname", "host", "port", "opt",
- "tty", "user", "passwd", NULL};
-
- char *pghost,
- *pgopt,
- *pgtty,
- *pgdbname,
- *pguser,
- *pgpasswd;
- int pgport;
- char port_buffer[20];
- pgobject *npgobj;
-
- pghost = pgopt = pgtty = pgdbname = pguser = pgpasswd = NULL;
- pgport = -1;
-
- /*
- * parses standard arguments With the right compiler warnings, this
- * will issue a diagnostic. There is really no way around it. If I
- * don't declare kwlist as const char *kwlist[] then it complains when
- * I try to assign all those constant strings to it.
- */
- if (!PyArg_ParseTupleAndKeywords(args, dict, "|zzizzzz", (char **) kwlist,
- &pgdbname, &pghost, &pgport, &pgopt, &pgtty, &pguser, &pgpasswd))
- return NULL;
-
-#ifdef DEFAULT_VARS
- /* handles defaults variables (for uninitialised vars) */
- if ((!pghost) && (pg_default_host != Py_None))
- pghost = PyString_AsString(pg_default_host);
-
- if ((pgport == -1) && (pg_default_port != Py_None))
- pgport = PyInt_AsLong(pg_default_port);
-
- if ((!pgopt) && (pg_default_opt != Py_None))
- pgopt = PyString_AsString(pg_default_opt);
-
- if ((!pgtty) && (pg_default_tty != Py_None))
- pgtty = PyString_AsString(pg_default_tty);
-
- if ((!pgdbname) && (pg_default_base != Py_None))
- pgdbname = PyString_AsString(pg_default_base);
-
- if ((!pguser) && (pg_default_user != Py_None))
- pguser = PyString_AsString(pg_default_user);
-
- if ((!pgpasswd) && (pg_default_passwd != Py_None))
- pgpasswd = PyString_AsString(pg_default_passwd);
-#endif /* DEFAULT_VARS */
-
- if ((npgobj = (pgobject *) pgobject_New()) == NULL)
- return NULL;
-
- if (pgport != -1)
- {
- memset(port_buffer, 0, sizeof(port_buffer));
- sprintf(port_buffer, "%d", pgport);
- }
-
-#ifdef PQsetdbLoginIsThreadSafe
- Py_BEGIN_ALLOW_THREADS
-#endif
- npgobj->cnx = PQsetdbLogin(pghost, pgport == -1 ? NULL : port_buffer,
- pgopt, pgtty, pgdbname, pguser, pgpasswd);
-#ifdef PQsetdbLoginIsThreadSafe
- Py_END_ALLOW_THREADS
-#endif
-
- if (PQstatus(npgobj->cnx) == CONNECTION_BAD)
- {
- PyErr_SetString(InternalError, PQerrorMessage(npgobj->cnx));
- Py_XDECREF(npgobj);
- return NULL;
- }
-
-#ifdef HANDLE_NOTICES
- PQsetNoticeProcessor(npgobj->cnx, notice_processor, npgobj);
-#endif /* HANDLE_NOTICES */
-
- return (PyObject *) npgobj;
-}
-
-/* pgobject methods */
-
-/* destructor */
-static void
-pg_dealloc(pgobject * self)
-{
-#ifdef HANDLE_NOTICES
- free(self->notices);
-#endif /* HANDLE_NOTICES */
- if (self->cnx)
- {
- Py_BEGIN_ALLOW_THREADS
- PQfinish(self->cnx);
- Py_END_ALLOW_THREADS
- }
- PyObject_Del(self);
-}
-
-/* close without deleting */
-static char pg_close__doc__[] =
-"close() -- close connection. All instances of the connection object and "
-"derived objects (queries and large objects) can no longer be used after "
-"this call.";
-
-static PyObject *
-pg_close(pgobject * self, PyObject * args)
-{
- /* gets args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError, "close().");
- return NULL;
- }
-
- /* connection object cannot already be closed */
- if (!self->cnx)
- {
- PyErr_SetString(InternalError, "Connection already closed");
- return NULL;
- }
-
- Py_BEGIN_ALLOW_THREADS
- PQfinish(self->cnx);
- Py_END_ALLOW_THREADS
-
- self->cnx = NULL;
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-static void
-pgquery_dealloc(pgqueryobject * self)
-{
- if (self->last_result)
- PQclear(self->last_result);
-
- PyObject_Del(self);
-}
-
-/* resets connection */
-static char pg_reset__doc__[] =
-"reset() -- reset connection with current parameters. All derived queries "
-"and large objects derived from this connection will not be usable after "
-"this call.";
-
-static PyObject *
-pg_reset(pgobject * self, PyObject * args)
-{
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method reset() takes no parameters.");
- return NULL;
- }
-
- /* resets the connection */
- PQreset(self->cnx);
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* cancels current command */
-static char pg_cancel__doc__[] =
-"cancel() -- abandon processing of the current command.";
-
-static PyObject *
-pg_cancel(pgobject * self, PyObject * args)
-{
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method cancel() takes no parameters.");
- return NULL;
- }
-
- /* request that the server abandon processing of the current command */
- return PyInt_FromLong((long) PQrequestCancel(self->cnx));
-}
-
-/* get connection socket */
-static char pg_fileno__doc__[] =
-"fileno() -- return database connection socket file handle.";
-
-static PyObject *
-pg_fileno(pgobject * self, PyObject * args)
-{
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method fileno() takes no parameters.");
- return NULL;
- }
-
-#ifdef NO_PQSOCKET
- return PyInt_FromLong((long) self->cnx->sock);
-#else
- return PyInt_FromLong((long) PQsocket(self->cnx));
-#endif
-}
-
-/* get number of rows */
-static char pgquery_ntuples__doc__[] =
-"ntuples() -- returns number of tuples returned by query.";
-
-static PyObject *
-pgquery_ntuples(pgqueryobject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method ntuples() takes no parameters.");
- return NULL;
- }
-
- return PyInt_FromLong((long) PQntuples(self->last_result));
-}
-
-/* list fields names from query result */
-static char pgquery_listfields__doc__[] =
-"listfields() -- Lists field names from result.";
-
-static PyObject *
-pgquery_listfields(pgqueryobject * self, PyObject * args)
-{
- int i,
- n;
- char *name;
- PyObject *fieldstuple,
- *str;
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method listfields() takes no parameters.");
- return NULL;
- }
-
- /* builds tuple */
- n = PQnfields(self->last_result);
- fieldstuple = PyTuple_New(n);
-
- for (i = 0; i < n; i++)
- {
- name = PQfname(self->last_result, i);
- str = PyString_FromString(name);
- PyTuple_SET_ITEM(fieldstuple, i, str);
- }
-
- return fieldstuple;
-}
-
-/* get field name from last result */
-static char pgquery_fieldname__doc__[] =
-"fieldname() -- returns name of field from result from its position.";
-
-static PyObject *
-pgquery_fieldname(pgqueryobject * self, PyObject * args)
-{
- int i;
- char *name;
-
- /* gets args */
- if (!PyArg_ParseTuple(args, "i", &i))
- {
- PyErr_SetString(PyExc_TypeError,
- "fieldname(number), with number(integer).");
- return NULL;
- }
-
- /* checks number validity */
- if (i >= PQnfields(self->last_result))
- {
- PyErr_SetString(PyExc_ValueError, "invalid field number.");
- return NULL;
- }
-
- /* gets fields name and builds object */
- name = PQfname(self->last_result, i);
- return PyString_FromString(name);
-}
-
-/* gets fields number from name in last result */
-static char pgquery_fieldnum__doc__[] =
-"fieldnum() -- returns position in query for field from its name.";
-
-static PyObject *
-pgquery_fieldnum(pgqueryobject * self, PyObject * args)
-{
- int num;
- char *name;
-
- /* gets args */
- if (!PyArg_ParseTuple(args, "s", &name))
- {
- PyErr_SetString(PyExc_TypeError, "fieldnum(name), with name (string).");
- return NULL;
- }
-
- /* gets field number */
- if ((num = PQfnumber(self->last_result, name)) == -1)
- {
- PyErr_SetString(PyExc_ValueError, "Unknown field.");
- return NULL;
- }
-
- return PyInt_FromLong(num);
-}
-
-/* retrieves last result */
-static char pgquery_getresult__doc__[] =
-"getresult() -- Gets the result of a query. The result is returned "
-"as a list of rows, each one a list of fields in the order returned "
-"by the server.";
-
-static PyObject *
-pgquery_getresult(pgqueryobject * self, PyObject * args)
-{
- PyObject *rowtuple,
- *reslist,
- *val;
- int i,
- j,
- m,
- n,
- *typ;
-
- /* checks args (args == NULL for an internal call) */
- if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
- {
- PyErr_SetString(PyExc_TypeError,
- "method getresult() takes no parameters.");
- return NULL;
- }
-
- /* stores result in tuple */
- m = PQntuples(self->last_result);
- n = PQnfields(self->last_result);
- reslist = PyList_New(m);
-
- typ = get_type_array(self->last_result, n);
-
- for (i = 0; i < m; i++)
- {
- if ((rowtuple = PyTuple_New(n)) == NULL)
- {
- Py_DECREF(reslist);
- reslist = NULL;
- goto exit;
- }
-
- for (j = 0; j < n; j++)
- {
- int k;
- char *s = PQgetvalue(self->last_result, i, j);
- char cashbuf[64];
- PyObject *tmp_obj;
-
- if (PQgetisnull(self->last_result, i, j))
- {
- Py_INCREF(Py_None);
- val = Py_None;
- }
- else
- switch (typ[j])
- {
- case 1:
- val = PyInt_FromString(s, NULL, 10);
- break;
-
- case 2:
- val = PyLong_FromString(s, NULL, 10);
- break;
-
- case 3:
- tmp_obj = PyString_FromString(s);
- val = PyFloat_FromString(tmp_obj, NULL);
- Py_DECREF(tmp_obj);
- break;
-
- case 5:
- for (k = 0;
- *s && k < sizeof(cashbuf) / sizeof(cashbuf[0]) - 1;
- s++)
- {
- if (isdigit(*s) || *s == '.')
- cashbuf[k++] = *s;
- else if (*s == '(' || *s == '-')
- cashbuf[k++] = '-';
- }
- cashbuf[k] = 0;
- s = cashbuf;
-
- case 4:
- if (decimal)
- {
- tmp_obj = Py_BuildValue("(s)", s);
- val = PyEval_CallObject(decimal, tmp_obj);
- }
- else
- {
- tmp_obj = PyString_FromString(s);
- val = PyFloat_FromString(tmp_obj, NULL);
- }
- Py_DECREF(tmp_obj);
- break;
-
- default:
- val = PyString_FromString(s);
- break;
- }
-
- if (val == NULL)
- {
- Py_DECREF(reslist);
- Py_DECREF(rowtuple);
- reslist = NULL;
- goto exit;
- }
-
- PyTuple_SET_ITEM(rowtuple, j, val);
- }
-
- PyList_SET_ITEM(reslist, i, rowtuple);
- }
-
-exit:
- free(typ);
-
- /* returns list */
- return reslist;
-}
-
-/* retrieves last result as a list of dictionaries*/
-static char pgquery_dictresult__doc__[] =
-"dictresult() -- Gets the result of a query. The result is returned "
-"as a list of rows, each one a dictionary with the field names used "
-"as the labels.";
-
-static PyObject *
-pgquery_dictresult(pgqueryobject * self, PyObject * args)
-{
- PyObject *dict,
- *reslist,
- *val;
- int i,
- j,
- m,
- n,
- *typ;
-
- /* checks args (args == NULL for an internal call) */
- if ((args != NULL) && (!PyArg_ParseTuple(args, "")))
- {
- PyErr_SetString(PyExc_TypeError,
- "method getresult() takes no parameters.");
- return NULL;
- }
-
- /* stores result in list */
- m = PQntuples(self->last_result);
- n = PQnfields(self->last_result);
- reslist = PyList_New(m);
-
- typ = get_type_array(self->last_result, n);
-
- for (i = 0; i < m; i++)
- {
- if ((dict = PyDict_New()) == NULL)
- {
- Py_DECREF(reslist);
- reslist = NULL;
- goto exit;
- }
-
- for (j = 0; j < n; j++)
- {
- int k;
- char *s = PQgetvalue(self->last_result, i, j);
- char cashbuf[64];
- PyObject *tmp_obj;
-
- if (PQgetisnull(self->last_result, i, j))
- {
- Py_INCREF(Py_None);
- val = Py_None;
- }
- else
- switch (typ[j])
- {
- case 1:
- val = PyInt_FromString(s, NULL, 10);
- break;
-
- case 2:
- val = PyLong_FromString(s, NULL, 10);
- break;
-
- case 3:
- tmp_obj = PyString_FromString(s);
- val = PyFloat_FromString(tmp_obj, NULL);
- Py_DECREF(tmp_obj);
- break;
-
- case 5:
- for (k = 0;
- *s && k < sizeof(cashbuf) / sizeof(cashbuf[0]) - 1;
- s++)
- {
- if (isdigit(*s) || *s == '.')
- cashbuf[k++] = *s;
- else if (*s == '(' || *s == '-')
- cashbuf[k++] = '-';
- }
- cashbuf[k] = 0;
- s = cashbuf;
-
- case 4:
- if (decimal)
- {
- tmp_obj = Py_BuildValue("(s)", s);
- val = PyEval_CallObject(decimal, tmp_obj);
- }
- else
- {
- tmp_obj = PyString_FromString(s);
- val = PyFloat_FromString(tmp_obj, NULL);
- }
- Py_DECREF(tmp_obj);
- break;
-
- default:
- val = PyString_FromString(s);
- break;
- }
-
- if (val == NULL)
- {
- Py_DECREF(dict);
- Py_DECREF(reslist);
- reslist = NULL;
- goto exit;
- }
-
- PyDict_SetItemString(dict, PQfname(self->last_result, j), val);
- Py_DECREF(val);
- }
-
- PyList_SET_ITEM(reslist, i, dict);
- }
-
-exit:
- free(typ);
-
- /* returns list */
- return reslist;
-}
-
-/* gets asynchronous notify */
-static char pg_getnotify__doc__[] =
-"getnotify() -- get database notify for this connection.";
-
-static PyObject *
-pg_getnotify(pgobject * self, PyObject * args)
-{
- PGnotify *notify;
-
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method getnotify() takes no parameters.");
- return NULL;
- }
-
- /* checks for NOTIFY messages */
- PQconsumeInput(self->cnx);
-
- if ((notify = PQnotifies(self->cnx)) == NULL)
- {
- Py_INCREF(Py_None);
- return Py_None;
- }
- else
- {
- PyObject *notify_result,
- *temp;
-
- if ((notify_result = PyTuple_New(2)) == NULL ||
- (temp = PyString_FromString(notify->relname)) == NULL)
- {
- return NULL;
- }
-
- PyTuple_SET_ITEM(notify_result, 0, temp);
-
- if ((temp = PyInt_FromLong(notify->be_pid)) == NULL)
- {
- Py_DECREF(notify_result);
- return NULL;
- }
-
- PyTuple_SET_ITEM(notify_result, 1, temp);
- PQfreemem(notify);
- return notify_result;
- }
-}
-
-/* source creation */
-static char pg_source__doc__[] =
-"source() -- creates a new source object for this connection";
-
-static PyObject *
-pg_source(pgobject * self, PyObject * args)
-{
- /* checks validity */
- if (!check_cnx_obj(self))
- return NULL;
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError, "method source() takes no parameter.");
- return NULL;
- }
-
- /* allocate new pg query object */
- return (PyObject *) pgsource_new(self);
-}
-
-/* database query */
-static char pg_query__doc__[] =
-"query(sql) -- creates a new query object for this connection,"
-" using sql (string) request.";
-
-static PyObject *
-pg_query(pgobject * self, PyObject * args)
-{
- char *query;
- PGresult *result;
- pgqueryobject *npgobj;
- int status;
-
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* get query args */
- if (!PyArg_ParseTuple(args, "s", &query))
- {
- PyErr_SetString(PyExc_TypeError, "query(sql), with sql (string).");
- return NULL;
- }
-
- /* frees previous result */
- if (self->last_result)
- {
- PQclear(self->last_result);
- self->last_result = NULL;
- }
-
- /* gets result */
- Py_BEGIN_ALLOW_THREADS
- result = PQexec(self->cnx, query);
- Py_END_ALLOW_THREADS
-
- /* checks result validity */
- if (!result)
- {
- PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->cnx));
- return NULL;
- }
-
- /* checks result status */
- if ((status = PQresultStatus(result)) != PGRES_TUPLES_OK)
- {
- switch (status)
- {
- case PGRES_EMPTY_QUERY:
- PyErr_SetString(PyExc_ValueError, "empty query.");
- break;
- case PGRES_BAD_RESPONSE:
- case PGRES_FATAL_ERROR:
- case PGRES_NONFATAL_ERROR:
- PyErr_SetString(ProgrammingError, PQerrorMessage(self->cnx));
- break;
- case PGRES_COMMAND_OK:
- { /* INSERT, UPDATE, DELETE */
- Oid oid = PQoidValue(result);
- if (oid == InvalidOid) /* not a single insert */
- {
- char *ret = PQcmdTuples(result);
-
- PQclear(result);
- if (ret[0]) /* return number of rows affected */
- {
- return PyString_FromString(ret);
- }
- Py_INCREF(Py_None);
- return Py_None;
- }
- /* for a single insert, return the oid */
- PQclear(result);
- return PyInt_FromLong(oid);
- }
- case PGRES_COPY_OUT: /* no data will be received */
- case PGRES_COPY_IN:
- PQclear(result);
- Py_INCREF(Py_None);
- return Py_None;
- default:
- PyErr_SetString(InternalError, "internal error: "
- "unknown result status.");
- break;
- }
-
- PQclear(result);
- return NULL; /* error detected on query */
- }
-
- if ((npgobj = PyObject_NEW(pgqueryobject, &PgQueryType)) == NULL)
- return NULL;
-
- /* stores result and returns object */
- npgobj->last_result = result;
- return (PyObject *) npgobj;
-}
-
-#ifdef DIRECT_ACCESS
-static char pg_putline__doc__[] =
-"putline() -- sends a line directly to the backend";
-
-/* direct acces function : putline */
-static PyObject *
-pg_putline(pgobject * self, PyObject * args)
-{
- char *line;
-
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* reads args */
- if (!PyArg_ParseTuple(args, "s", &line))
- {
- PyErr_SetString(PyExc_TypeError, "putline(line), with line (string).");
- return NULL;
- }
-
- /* sends line to backend */
- if (PQputline(self->cnx, line))
- {
- PyErr_SetString(PyExc_IOError, PQerrorMessage(self->cnx));
- return NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* direct access function : getline */
-static char pg_getline__doc__[] =
-"getline() -- gets a line directly from the backend.";
-
-static PyObject *
-pg_getline(pgobject * self, PyObject * args)
-{
- char line[MAX_BUFFER_SIZE];
- PyObject *str = NULL; /* GCC */
-
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method getline() takes no parameters.");
- return NULL;
- }
-
- /* gets line */
- switch (PQgetline(self->cnx, line, MAX_BUFFER_SIZE))
- {
- case 0:
- str = PyString_FromString(line);
- break;
- case 1:
- PyErr_SetString(PyExc_MemoryError, "buffer overflow");
- str = NULL;
- break;
- case EOF:
- Py_INCREF(Py_None);
- str = Py_None;
- break;
- }
-
- return str;
-}
-
-/* direct access function : end copy */
-static char pg_endcopy__doc__[] =
-"endcopy() -- synchronizes client and server";
-
-static PyObject *
-pg_endcopy(pgobject * self, PyObject * args)
-{
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method endcopy() takes no parameters.");
- return NULL;
- }
-
- /* ends direct copy */
- if (PQendcopy(self->cnx))
- {
- PyErr_SetString(PyExc_IOError, PQerrorMessage(self->cnx));
- return NULL;
- }
- Py_INCREF(Py_None);
- return Py_None;
-}
-#endif /* DIRECT_ACCESS */
-
-
-static PyObject *
-pgquery_print(pgqueryobject * self, FILE *fp, int flags)
-{
- print_result(fp, self->last_result);
- return 0;
-}
-
-static PyObject *
-pgquery_repr(pgqueryobject * self)
-{
- return PyString_FromString("<pg query result>");
-}
-
-/* insert table */
-static char pg_inserttable__doc__[] =
-"inserttable(string, list) -- insert list in table. The fields in the "
-"list must be in the same order as in the table.";
-
-static PyObject *
-pg_inserttable(pgobject * self, PyObject * args)
-{
- PGresult *result;
- char *table,
- *buffer,
- *bufpt;
- size_t bufsiz;
- PyObject *list,
- *sublist,
- *item;
- PyObject *(*getitem) (PyObject *, Py_ssize_t);
- PyObject *(*getsubitem) (PyObject *, Py_ssize_t);
- int i,
- j,
- m,
- n;
-
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "sO:filter", &table, &list))
- {
- PyErr_SetString(PyExc_TypeError,
- "inserttable(table, content), with table (string) "
- "and content (list).");
- return NULL;
- }
-
- /* checks list type */
- if (PyTuple_Check(list))
- {
- m = PyTuple_Size(list);
- getitem = PyTuple_GetItem;
- }
- else if (PyList_Check(list))
- {
- m = PyList_Size(list);
- getitem = PyList_GetItem;
- }
- else
- {
- PyErr_SetString(PyExc_TypeError,
- "second arg must be some kind of array.");
- return NULL;
- }
-
- /* allocate buffer */
- if (!(buffer = malloc(MAX_BUFFER_SIZE)))
- {
- PyErr_SetString(PyExc_MemoryError,
- "can't allocate insert buffer.");
- return NULL;
- }
-
- /* starts query */
- sprintf(buffer, "copy %s from stdin", table);
-
- Py_BEGIN_ALLOW_THREADS
- result = PQexec(self->cnx, buffer);
- Py_END_ALLOW_THREADS
-
- if (!result)
- {
- free(buffer);
- PyErr_SetString(PyExc_ValueError, PQerrorMessage(self->cnx));
- return NULL;
- }
-
- PQclear(result);
-
- n = 0; /* not strictly necessary but avoids warning */
-
- /* feed table */
- for (i = 0; i < m; i++)
- {
- sublist = getitem(list, i);
- if (PyTuple_Check(sublist))
- {
- j = PyTuple_Size(sublist);
- getsubitem = PyTuple_GetItem;
- }
- else if (PyList_Check(sublist))
- {
- j = PyList_Size(sublist);
- getsubitem = PyList_GetItem;
- }
- else
- {
- PyErr_SetString(PyExc_TypeError,
- "second arg must contain some kind of arrays.");
- return NULL;
- }
- if (i)
- {
- if (j != n)
- {
- free(buffer);
- PyErr_SetString(PyExc_TypeError,
- "arrays contained in second arg must have same size.");
- return NULL;
- }
- }
- else
- {
- n = j; /* never used before this assignment */
- }
-
- /* builds insert line */
- bufpt = buffer;
- bufsiz = MAX_BUFFER_SIZE - 1;
-
- for (j = 0; j < n; j++)
- {
- if (j)
- {
- *bufpt++ = '\t'; --bufsiz;
- }
-
- item = getsubitem(sublist, j);
-
- /* convert item to string and append to buffer */
- if (item == Py_None)
- {
- if (bufsiz > 2)
- {
- *bufpt++ = '\\'; *bufpt++ = 'N';
- bufsiz -= 2;
- }
- else
- bufsiz = 0;
- }
- else if (PyString_Check(item))
- {
- const char* t = PyString_AS_STRING(item);
- while (*t && bufsiz)
- {
- if (*t == '\\' || *t == '\t' || *t == '\n')
- {
- *bufpt++ = '\\'; --bufsiz;
- if (!bufsiz) break;
- }
- *bufpt++ = *t++; --bufsiz;
- }
- }
- else if (PyInt_Check(item) || PyLong_Check(item))
- {
- PyObject* s = PyObject_Str(item);
- const char* t = PyString_AsString(s);
- while (*t && bufsiz)
- {
- *bufpt++ = *t++; --bufsiz;
- }
- Py_DECREF(s);
- }
- else
- {
- PyObject* s = PyObject_Repr(item);
- const char* t = PyString_AsString(s);
- while (*t && bufsiz)
- {
- if (*t == '\\' || *t == '\t' || *t == '\n')
- {
- *bufpt++ = '\\'; --bufsiz;
- if (!bufsiz) break;
- }
- *bufpt++ = *t++; --bufsiz;
- }
- Py_DECREF(s);
- }
-
- if (bufsiz <= 0)
- {
- free(buffer);
- PyErr_SetString(PyExc_MemoryError,
- "insert buffer overflow.");
- return NULL;
- }
-
- }
-
- *bufpt++ = '\n'; *bufpt = '\0';
-
- /* sends data */
- if (PQputline(self->cnx, buffer))
- {
- PyErr_SetString(PyExc_IOError, PQerrorMessage(self->cnx));
- PQendcopy(self->cnx);
- free(buffer);
- return NULL;
- }
- }
-
- /* ends query */
- if (PQputline(self->cnx, "\\.\n"))
- {
- PyErr_SetString(PyExc_IOError, PQerrorMessage(self->cnx));
- PQendcopy(self->cnx);
- free(buffer);
- return NULL;
- }
-
- if (PQendcopy(self->cnx))
- {
- PyErr_SetString(PyExc_IOError, PQerrorMessage(self->cnx));
- free(buffer);
- return NULL;
- }
-
- free(buffer);
-
- /* no error : returns nothing */
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* get transaction state */
-static char pg_transaction__doc__[] =
-"Returns the current transaction status.";
-
-static PyObject *
-pg_transaction(pgobject * self, PyObject * args)
-{
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method transaction() takes no parameters.");
- return NULL;
- }
-
- return PyInt_FromLong(PQtransactionStatus(self->cnx));
-}
-
-/* get parameter setting */
-static char pg_parameter__doc__[] =
-"Looks up a current parameter setting.";
-
-static PyObject *
-pg_parameter(pgobject * self, PyObject * args)
-{
- const char *name;
-
- if (!self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* get query args */
- if (!PyArg_ParseTuple(args, "s", &name))
- {
- PyErr_SetString(PyExc_TypeError, "parameter(name), with name (string).");
- return NULL;
- }
-
- name = PQparameterStatus(self->cnx, name);
-
- if (name)
- return PyString_FromString(name);
-
- /* unknown parameter, return None */
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* escape string */
-static char pg_escape_string__doc__[] =
-"pg_escape_string(str) -- escape a string for use within SQL.";
-
-static PyObject *
-pg_escape_string(pgobject *self, PyObject *args) {
- char *from; /* our string argument */
- char *to=NULL; /* the result */
- int from_length; /* length of string */
- int to_length; /* length of result */
- PyObject *ret; /* string object to return */
-
- if (!PyArg_ParseTuple(args, "s#", &from, &from_length))
- return NULL;
- to_length = 2*from_length + 1;
- if (to_length < from_length) { /* overflow */
- to_length = from_length;
- from_length = (from_length - 1)/2;
- }
- to = (char *)malloc(to_length);
- to_length = (int)PQescapeStringConn(self->cnx,
- to, from, (size_t)from_length, NULL);
- ret = Py_BuildValue("s#", to, to_length);
- if (to)
- free(to);
- if (!ret) /* pass on exception */
- return NULL;
- return ret;
-}
-
-/* escape bytea */
-static char pg_escape_bytea__doc__[] =
-"pg_escape_bytea(data) -- escape binary data for use within SQL as type bytea.";
-
-static PyObject *
-pg_escape_bytea(pgobject *self, PyObject *args) {
- unsigned char *from; /* our string argument */
- unsigned char *to; /* the result */
- int from_length; /* length of string */
- size_t to_length; /* length of result */
- PyObject *ret; /* string object to return */
-
- if (!PyArg_ParseTuple(args, "s#", &from, &from_length))
- return NULL;
- to = PQescapeByteaConn(self->cnx, from, (int)from_length, &to_length);
- ret = Py_BuildValue("s", to);
- if (to)
- PQfreemem((void *)to);
- if (!ret) /* pass on exception */
- return NULL;
- return ret;
-}
-
-#ifdef LARGE_OBJECTS
-/* creates large object */
-static char pg_locreate__doc__[] =
-"locreate() -- creates a new large object in the database.";
-
-static PyObject *
-pg_locreate(pgobject * self, PyObject * args)
-{
- int mode;
- Oid lo_oid;
-
- /* checks validity */
- if (!check_cnx_obj(self))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "i", &mode))
- {
- PyErr_SetString(PyExc_TypeError,
- "locreate(mode), with mode (integer).");
- return NULL;
- }
-
- /* creates large object */
- lo_oid = lo_creat(self->cnx, mode);
- if (lo_oid == 0)
- {
- PyErr_SetString(OperationalError, "can't create large object.");
- return NULL;
- }
-
- return (PyObject *) pglarge_new(self, lo_oid);
-}
-
-/* init from already known oid */
-static char pg_getlo__doc__[] =
-"getlo(long) -- create a large object instance for the specified oid.";
-
-static PyObject *
-pg_getlo(pgobject * self, PyObject * args)
-{
- int lo_oid;
-
- /* checks validity */
- if (!check_cnx_obj(self))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "i", &lo_oid))
- {
- PyErr_SetString(PyExc_TypeError, "getlo(oid), with oid (integer).");
- return NULL;
- }
-
- if (!lo_oid)
- {
- PyErr_SetString(PyExc_ValueError, "the object oid can't be null.");
- return NULL;
- }
-
- /* creates object */
- return (PyObject *) pglarge_new(self, lo_oid);
-}
-
-/* import unix file */
-static char pg_loimport__doc__[] =
-"loimport(string) -- create a new large object from specified file.";
-
-static PyObject *
-pg_loimport(pgobject * self, PyObject * args)
-{
- char *name;
- Oid lo_oid;
-
- /* checks validity */
- if (!check_cnx_obj(self))
- return NULL;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "s", &name))
- {
- PyErr_SetString(PyExc_TypeError, "loimport(name), with name (string).");
- return NULL;
- }
-
- /* imports file and checks result */
- lo_oid = lo_import(self->cnx, name);
- if (lo_oid == 0)
- {
- PyErr_SetString(OperationalError, "can't create large object.");
- return NULL;
- }
-
- return (PyObject *) pglarge_new(self, lo_oid);
-}
-#endif /* LARGE_OBJECTS */
-
-#ifdef HANDLE_NOTICES
-
-/* fetch accumulated backend notices */
-static char pg_notices__doc__[] =
- "notices() -- returns and clears the list of currently accumulated backend notices for the connection.";
-
-static void
-notice_processor(void * arg, const char * message)
-{
-
- pgobject *pgobj = (pgobject *)arg;
-
- /* skip if memory allocation failed */
- if (pgobj->notices == NULL)
- {
- return;
- }
-
- pgobj->notices[pgobj->notices_next] = strdup(message);
- pgobj->notices_next = (pgobj->notices_next + 1) % MAX_BUFFERED_NOTICES;
- if (pgobj->notices_next == pgobj->notices_first)
- {
- free(pgobj->notices[pgobj->notices_first]);
- pgobj->notices_first = (pgobj->notices_first + 1) % MAX_BUFFERED_NOTICES;
- }
-
- }
-
-static PyObject *
- pg_notices(pgobject * self, PyObject * args)
- {
-
- PyObject *reslist,
- *str;
- int i;
-
- /* allocate list for result */
- if ((reslist = PyList_New(0)) == NULL)
- return NULL;
-
- /* skip if memory allocation failed */
- if (self->notices == NULL)
- {
- return reslist;
- }
-
- /* builds result */
- while (self->notices_first != self->notices_next)
- {
-
- if (self->notices[self->notices_first] != NULL) /* skip if memory allocation failed */
- {
-
- str = PyString_FromString(self->notices[self->notices_first]);
- PyList_Append(reslist, str);
- Py_DECREF(str);
-
- free(self->notices[self->notices_first]);
-
- }
-
- self->notices_first = (self->notices_first + 1) % MAX_BUFFERED_NOTICES;
-
- }
-
- return reslist;
-
- }
-
-#endif /* HANDLE_NOTICES */
-
-/* connection object methods */
-static struct PyMethodDef pgobj_methods[] = {
- {"source", (PyCFunction) pg_source, METH_VARARGS, pg_source__doc__},
- {"query", (PyCFunction) pg_query, METH_VARARGS, pg_query__doc__},
- {"reset", (PyCFunction) pg_reset, METH_VARARGS, pg_reset__doc__},
- {"cancel", (PyCFunction) pg_cancel, METH_VARARGS, pg_cancel__doc__},
- {"close", (PyCFunction) pg_close, METH_VARARGS, pg_close__doc__},
- {"fileno", (PyCFunction) pg_fileno, METH_VARARGS, pg_fileno__doc__},
- {"getnotify", (PyCFunction) pg_getnotify, METH_VARARGS,
- pg_getnotify__doc__},
- {"inserttable", (PyCFunction) pg_inserttable, METH_VARARGS,
- pg_inserttable__doc__},
- {"transaction", (PyCFunction) pg_transaction, METH_VARARGS,
- pg_transaction__doc__},
- {"parameter", (PyCFunction) pg_parameter, METH_VARARGS,
- pg_parameter__doc__},
- {"escape_string", (PyCFunction) pg_escape_string, METH_VARARGS,
- pg_escape_string__doc__},
- {"escape_bytea", (PyCFunction) pg_escape_bytea, METH_VARARGS,
- pg_escape_bytea__doc__},
-
-#ifdef DIRECT_ACCESS
- {"putline", (PyCFunction) pg_putline, 1, pg_putline__doc__},
- {"getline", (PyCFunction) pg_getline, 1, pg_getline__doc__},
- {"endcopy", (PyCFunction) pg_endcopy, 1, pg_endcopy__doc__},
-#endif /* DIRECT_ACCESS */
-
-#ifdef LARGE_OBJECTS
- {"locreate", (PyCFunction) pg_locreate, 1, pg_locreate__doc__},
- {"getlo", (PyCFunction) pg_getlo, 1, pg_getlo__doc__},
- {"loimport", (PyCFunction) pg_loimport, 1, pg_loimport__doc__},
-#endif /* LARGE_OBJECTS */
-
-#ifdef HANDLE_NOTICES
- {"notices", (PyCFunction) pg_notices, 1, pg_notices__doc__},
-#endif /* HANDLE_NOTICES */
-
- {NULL, NULL} /* sentinel */
-};
-
-/* get attribute */
-static PyObject *
-pg_getattr(pgobject * self, char *name)
-{
- /*
- * Although we could check individually, there are only a few
- * attributes that don't require a live connection and unless someone
- * has an urgent need, this will have to do
- */
-
- /* first exception - close which returns a different error */
- if (strcmp(name, "close") && !self->cnx)
- {
- PyErr_SetString(PyExc_TypeError, "Connection is not valid.");
- return NULL;
- }
-
- /* list postgreSQL connection fields */
-
- /* postmaster host */
- if (!strcmp(name, "host"))
- {
- char *r = PQhost(self->cnx);
-
- return r ? PyString_FromString(r) : PyString_FromString("localhost");
- }
-
- /* postmaster port */
- if (!strcmp(name, "port"))
- return PyInt_FromLong(atol(PQport(self->cnx)));
-
- /* selected database */
- if (!strcmp(name, "db"))
- return PyString_FromString(PQdb(self->cnx));
-
- /* selected options */
- if (!strcmp(name, "options"))
- return PyString_FromString(PQoptions(self->cnx));
-
- /* selected postgres tty */
- if (!strcmp(name, "tty"))
- return PyString_FromString(PQtty(self->cnx));
-
- /* error (status) message */
- if (!strcmp(name, "error"))
- return PyString_FromString(PQerrorMessage(self->cnx));
-
- /* connection status : 1 - OK, 0 - BAD */
- if (!strcmp(name, "status"))
- return PyInt_FromLong(PQstatus(self->cnx) == CONNECTION_OK ? 1 : 0);
-
- /* provided user name */
- if (!strcmp(name, "user"))
- return PyString_FromString(PQuser(self->cnx));
-
- /* protocol version */
- if (!strcmp(name, "protocol_version"))
- return PyInt_FromLong(PQprotocolVersion(self->cnx));
-
- /* backend version */
- if (!strcmp(name, "server_version"))
-#if PG_VERSION_NUM < 80000
- return PyInt_FromLong(PG_VERSION_NUM);
-#else
- return PyInt_FromLong(PQserverVersion(self->cnx));
-#endif
-
- /* attributes list */
- if (!strcmp(name, "__members__"))
- {
- PyObject *list = PyList_New(10);
-
- if (list)
- {
- PyList_SET_ITEM(list, 0, PyString_FromString("host"));
- PyList_SET_ITEM(list, 1, PyString_FromString("port"));
- PyList_SET_ITEM(list, 2, PyString_FromString("db"));
- PyList_SET_ITEM(list, 3, PyString_FromString("options"));
- PyList_SET_ITEM(list, 4, PyString_FromString("tty"));
- PyList_SET_ITEM(list, 5, PyString_FromString("error"));
- PyList_SET_ITEM(list, 6, PyString_FromString("status"));
- PyList_SET_ITEM(list, 7, PyString_FromString("user"));
- PyList_SET_ITEM(list, 8, PyString_FromString("protocol_version"));
- PyList_SET_ITEM(list, 9, PyString_FromString("server_version"));
- }
-
- return list;
- }
-
- return Py_FindMethod(pgobj_methods, (PyObject *) self, name);
-}
-
-/* object type definition */
-staticforward PyTypeObject PgType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pgobject", /* tp_name */
- sizeof(pgobject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor) pg_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) pg_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
-};
-
-
-/* query object methods */
-static struct PyMethodDef pgquery_methods[] = {
- {"getresult", (PyCFunction) pgquery_getresult, METH_VARARGS,
- pgquery_getresult__doc__},
- {"dictresult", (PyCFunction) pgquery_dictresult, METH_VARARGS,
- pgquery_dictresult__doc__},
- {"fieldname", (PyCFunction) pgquery_fieldname, METH_VARARGS,
- pgquery_fieldname__doc__},
- {"fieldnum", (PyCFunction) pgquery_fieldnum, METH_VARARGS,
- pgquery_fieldnum__doc__},
- {"listfields", (PyCFunction) pgquery_listfields, METH_VARARGS,
- pgquery_listfields__doc__},
- {"ntuples", (PyCFunction) pgquery_ntuples, METH_VARARGS,
- pgquery_ntuples__doc__},
- {NULL, NULL}
-};
-
-/* gets query object attributes */
-static PyObject *
-pgquery_getattr(pgqueryobject * self, char *name)
-{
- /* list postgreSQL connection fields */
- return Py_FindMethod(pgquery_methods, (PyObject *) self, name);
-}
-
-/* query type definition */
-staticforward PyTypeObject PgQueryType = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "pgqueryobject", /* tp_name */
- sizeof(pgqueryobject), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor) pgquery_dealloc, /* tp_dealloc */
- (printfunc) pgquery_print, /* tp_print */
- (getattrfunc) pgquery_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- (reprfunc) pgquery_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
-};
-
-
-/* --------------------------------------------------------------------- */
-
-/* MODULE FUNCTIONS */
-
-/* escape string */
-static char escape_string__doc__[] =
-"escape_string(str) -- escape a string for use within SQL.";
-
-static PyObject *
-escape_string(PyObject *self, PyObject *args) {
- char *from; /* our string argument */
- char *to=NULL; /* the result */
- int from_length; /* length of string */
- int to_length; /* length of result */
- PyObject *ret; /* string object to return */
-
- if (!PyArg_ParseTuple(args, "s#", &from, &from_length))
- return NULL;
- to_length = 2*from_length + 1;
- if (to_length < from_length) { /* overflow */
- to_length = from_length;
- from_length = (from_length - 1)/2;
- }
- to = (char *)malloc(to_length);
- to_length = (int)PQescapeString(to, from, (size_t)from_length);
- ret = Py_BuildValue("s#", to, to_length);
- if (to)
- free(to);
- if (!ret) /* pass on exception */
- return NULL;
- return ret;
-}
-
-/* escape bytea */
-static char escape_bytea__doc__[] =
-"escape_bytea(data) -- escape binary data for use within SQL as type bytea.";
-
-static PyObject *
-escape_bytea(PyObject *self, PyObject *args) {
- unsigned char *from; /* our string argument */
- unsigned char *to; /* the result */
- int from_length; /* length of string */
- size_t to_length; /* length of result */
- PyObject *ret; /* string object to return */
-
- if (!PyArg_ParseTuple(args, "s#", &from, &from_length))
- return NULL;
- to = PQescapeBytea(from, (int)from_length, &to_length);
- ret = Py_BuildValue("s", to);
- if (to)
- PQfreemem((void *)to);
- if (!ret) /* pass on exception */
- return NULL;
- return ret;
-}
-
-/* unescape bytea */
-static char unescape_bytea__doc__[] =
-"unescape_bytea(str) -- unescape bytea data that has been retrieved as text.";
-
-static PyObject
-*unescape_bytea(PyObject *self, PyObject *args) {
- unsigned char *from; /* our string argument */
- unsigned char *to; /* the result */
- size_t to_length; /* length of result string */
- PyObject *ret; /* string object to return */
-
- if (!PyArg_ParseTuple(args, "s", &from))
- return NULL;
- to = PQunescapeBytea(from, &to_length);
- ret = Py_BuildValue("s#", to, (int)to_length);
- if (to)
- PQfreemem((void *)to);
- if (!ret) /* pass on exception */
- return NULL;
- return ret;
-}
-
-/* set decimal */
-static char set_decimal__doc__[] =
-"set_decimal(cls) -- set a decimal type to be used for numeric values.";
-
-static PyObject *
-set_decimal(PyObject * self, PyObject * args)
-{
- PyObject *ret = NULL;
- PyObject *cls;
-
- if (PyArg_ParseTuple(args, "O", &cls))
- {
- if (cls == Py_None)
- {
- Py_XDECREF(decimal); decimal = NULL;
- Py_INCREF(Py_None); ret = Py_None;
- }
- else if (PyCallable_Check(cls))
- {
- Py_XINCREF(cls); Py_XDECREF(decimal); decimal = cls;
- Py_INCREF(Py_None); ret = Py_None;
- }
- else
- PyErr_SetString(PyExc_TypeError, "decimal type must be None or callable");
- }
- return ret;
-}
-
-#ifdef DEFAULT_VARS
-
-/* gets default host */
-static char getdefhost__doc__[] =
-"get_defhost() -- return default database host.";
-
-static PyObject *
-pggetdefhost(PyObject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method get_defhost() takes no parameter.");
- return NULL;
- }
-
- Py_XINCREF(pg_default_host);
- return pg_default_host;
-}
-
-/* sets default host */
-static char setdefhost__doc__[] =
-"set_defhost(string) -- set default database host. Return previous value.";
-
-static PyObject *
-pgsetdefhost(PyObject * self, PyObject * args)
-{
- char *temp = NULL;
- PyObject *old;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "z", &temp))
- {
- PyErr_SetString(PyExc_TypeError,
- "set_defhost(name), with name (string/None).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_host;
-
- if (temp)
- pg_default_host = PyString_FromString(temp);
- else
- {
- Py_INCREF(Py_None);
- pg_default_host = Py_None;
- }
-
- return old;
-}
-
-/* gets default base */
-static char getdefbase__doc__[] =
-"get_defbase() -- return default database name.";
-
-static PyObject *
-pggetdefbase(PyObject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method get_defbase() takes no parameter.");
- return NULL;
- }
-
- Py_XINCREF(pg_default_base);
- return pg_default_base;
-}
-
-/* sets default base */
-static char setdefbase__doc__[] =
-"set_defbase(string) -- set default database name. Return previous value";
-
-static PyObject *
-pgsetdefbase(PyObject * self, PyObject * args)
-{
- char *temp = NULL;
- PyObject *old;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "z", &temp))
- {
- PyErr_SetString(PyExc_TypeError,
- "set_defbase(name), with name (string/None).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_base;
-
- if (temp)
- pg_default_base = PyString_FromString(temp);
- else
- {
- Py_INCREF(Py_None);
- pg_default_base = Py_None;
- }
-
- return old;
-}
-
-/* gets default options */
-static char getdefopt__doc__[] =
-"get_defopt() -- return default database options.";
-
-static PyObject *
-pggetdefopt(PyObject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method get_defopt() takes no parameter.");
- return NULL;
- }
-
- Py_XINCREF(pg_default_opt);
- return pg_default_opt;
-}
-
-/* sets default opt */
-static char setdefopt__doc__[] =
-"set_defopt(string) -- set default database options. Return previous value.";
-
-static PyObject *
-pgsetdefopt(PyObject * self, PyObject * args)
-{
- char *temp = NULL;
- PyObject *old;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "z", &temp))
- {
- PyErr_SetString(PyExc_TypeError,
- "set_defopt(name), with name (string/None).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_opt;
-
- if (temp)
- pg_default_opt = PyString_FromString(temp);
- else
- {
- Py_INCREF(Py_None);
- pg_default_opt = Py_None;
- }
-
- return old;
-}
-
-/* gets default tty */
-static char getdeftty__doc__[] =
-"get_deftty() -- return default database debug terminal.";
-
-static PyObject *
-pggetdeftty(PyObject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method get_deftty() takes no parameter.");
- return NULL;
- }
-
- Py_XINCREF(pg_default_tty);
- return pg_default_tty;
-}
-
-/* sets default tty */
-static char setdeftty__doc__[] =
-"set_deftty(string) -- set default database debug terminal. "
-"Return previous value.";
-
-static PyObject *
-pgsetdeftty(PyObject * self, PyObject * args)
-{
- char *temp = NULL;
- PyObject *old;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "z", &temp))
- {
- PyErr_SetString(PyExc_TypeError,
- "set_deftty(name), with name (string/None).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_tty;
-
- if (temp)
- pg_default_tty = PyString_FromString(temp);
- else
- {
- Py_INCREF(Py_None);
- pg_default_tty = Py_None;
- }
-
- return old;
-}
-
-/* gets default username */
-static char getdefuser__doc__[] =
-"get_defuser() -- return default database username.";
-
-static PyObject *
-pggetdefuser(PyObject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method get_defuser() takes no parameter.");
-
- return NULL;
- }
-
- Py_XINCREF(pg_default_user);
- return pg_default_user;
-}
-
-/* sets default username */
-static char setdefuser__doc__[] =
-"set_defuser() -- set default database username. Return previous value.";
-
-static PyObject *
-pgsetdefuser(PyObject * self, PyObject * args)
-{
- char *temp = NULL;
- PyObject *old;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "z", &temp))
- {
- PyErr_SetString(PyExc_TypeError,
- "set_defuser(name), with name (string/None).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_user;
-
- if (temp)
- pg_default_user = PyString_FromString(temp);
- else
- {
- Py_INCREF(Py_None);
- pg_default_user = Py_None;
- }
-
- return old;
-}
-
-/* sets default password */
-static char setdefpasswd__doc__[] =
-"set_defpasswd() -- set default database password.";
-
-static PyObject *
-pgsetdefpasswd(PyObject * self, PyObject * args)
-{
- char *temp = NULL;
- PyObject *old;
-
- /* gets arguments */
- if (!PyArg_ParseTuple(args, "z", &temp))
- {
- PyErr_SetString(PyExc_TypeError,
- "set_defpasswd(password), with password (string/None).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_passwd;
-
- if (temp)
- pg_default_passwd = PyString_FromString(temp);
- else
- {
- Py_INCREF(Py_None);
- pg_default_passwd = Py_None;
- }
-
- Py_INCREF(Py_None);
- return Py_None;
-}
-
-/* gets default port */
-static char getdefport__doc__[] =
-"get_defport() -- return default database port.";
-
-static PyObject *
-pggetdefport(PyObject * self, PyObject * args)
-{
- /* checks args */
- if (!PyArg_ParseTuple(args, ""))
- {
- PyErr_SetString(PyExc_TypeError,
- "method get_defport() takes no parameter.");
- return NULL;
- }
-
- Py_XINCREF(pg_default_port);
- return pg_default_port;
-}
-
-/* sets default port */
-static char setdefport__doc__[] =
-"set_defport(integer) -- set default database port. Return previous value.";
-
-static PyObject *
-pgsetdefport(PyObject * self, PyObject * args)
-{
- long int port = -2;
- PyObject *old;
-
- /* gets arguments */
- if ((!PyArg_ParseTuple(args, "l", &port)) || (port < -1))
- {
- PyErr_SetString(PyExc_TypeError, "set_defport(port), with port "
- "(positive integer/-1).");
- return NULL;
- }
-
- /* adjusts value */
- old = pg_default_port;
-
- if (port != -1)
- pg_default_port = PyInt_FromLong(port);
- else
- {
- Py_INCREF(Py_None);
- pg_default_port = Py_None;
- }
-
- return old;
-}
-#endif /* DEFAULT_VARS */
-
-/* List of functions defined in the module */
-
-static struct PyMethodDef pg_methods[] = {
- {"connect", (PyCFunction) pgconnect, METH_VARARGS|METH_KEYWORDS,
- connect__doc__},
- {"escape_string", (PyCFunction) escape_string, METH_VARARGS,
- escape_string__doc__},
- {"escape_bytea", (PyCFunction) escape_bytea, METH_VARARGS,
- escape_bytea__doc__},
- {"unescape_bytea", (PyCFunction) unescape_bytea, METH_VARARGS,
- unescape_bytea__doc__},
- {"set_decimal", (PyCFunction) set_decimal, METH_VARARGS,
- set_decimal__doc__},
-
-#ifdef DEFAULT_VARS
- {"get_defhost", pggetdefhost, METH_VARARGS, getdefhost__doc__},
- {"set_defhost", pgsetdefhost, METH_VARARGS, setdefhost__doc__},
- {"get_defbase", pggetdefbase, METH_VARARGS, getdefbase__doc__},
- {"set_defbase", pgsetdefbase, METH_VARARGS, setdefbase__doc__},
- {"get_defopt", pggetdefopt, METH_VARARGS, getdefopt__doc__},
- {"set_defopt", pgsetdefopt, METH_VARARGS, setdefopt__doc__},
- {"get_deftty", pggetdeftty, METH_VARARGS, getdeftty__doc__},
- {"set_deftty", pgsetdeftty, METH_VARARGS, setdeftty__doc__},
- {"get_defport", pggetdefport, METH_VARARGS, getdefport__doc__},
- {"set_defport", pgsetdefport, METH_VARARGS, setdefport__doc__},
- {"get_defuser", pggetdefuser, METH_VARARGS, getdefuser__doc__},
- {"set_defuser", pgsetdefuser, METH_VARARGS, setdefuser__doc__},
- {"set_defpasswd", pgsetdefpasswd, METH_VARARGS, setdefpasswd__doc__},
-#endif /* DEFAULT_VARS */
- {NULL, NULL} /* sentinel */
-};
-
-static char pg__doc__[] = "Python interface to PostgreSQL DB";
-
-/* Initialization function for the module */
-DL_EXPORT(void)
-init_pg(void)
-{
- PyObject *mod,
- *dict,
- *v;
-
- /* Initialize here because some WIN platforms get confused otherwise */
- PglargeType.ob_type = PgType.ob_type = PgQueryType.ob_type =
- PgSourceType.ob_type = &PyType_Type;
-
- /* Create the module and add the functions *
<TRUNCATED>
[04/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.txt
deleted file mode 100644
index ce98629..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.txt
+++ /dev/null
@@ -1,1382 +0,0 @@
-================================
-PyGreSQL Programming Information
-================================
-
-------------------------------------------
-The classic PyGreSQL interface (pg module)
-------------------------------------------
-
-.. meta::
- :description: The classic PyGreSQL interface (pg module)
- :keywords: PyGreSQL, pg, PostGreSQL, Python
-
-.. sectnum::
-.. contents:: Contents
-
-
-Introduction
-============
-You may either choose to use the
-`"classic" PyGreSQL interface <pg.html>`_
-provided by the `pg` module or else the
-`DB-API 2.0 compliant interface <pgdb.html>`_
-provided by the `pgdb` module.
-
-The following documentation covers only the older `pg` API.
-
-The `pg` module handles three types of objects,
-
-- the `pgobject`, which handles the connection
- and all the requests to the database,
-- the `pglarge` object, which handles
- all the accesses to PostgreSQL large objects,
-- the `pgqueryobject` that handles query results
-
-and it provides a convenient wrapper class `DB` for the `pgobject`.
-
-If you want to see a simple example of the use of some of these functions,
-see http://ontario.bikerides.ca where you can find a link at the bottom to the
-actual Python code for the page.
-
-
-Module functions and constants
-==============================
-The `pg` module defines a few functions that allow to connect
-to a database and to define "default variables" that override
-the environment variables used by PostgreSQL.
-
-These "default variables" were designed to allow you to handle general
-connection parameters without heavy code in your programs. You can prompt the
-user for a value, put it in the default variable, and forget it, without
-having to modify your environment. The support for default variables can be
-disabled by setting the -DNO_DEF_VAR option in the Python setup file. Methods
-relative to this are specified by the tag [DV].
-
-All variables are set to `None` at module initialization, specifying that
-standard environment variables should be used.
-
-connect - opens a pg connection
--------------------------------
-Syntax::
-
- connect([dbname], [host], [port], [opt], [tty], [user], [passwd])
-
-Parameters:
- :dbname: name of connected database (string/None)
- :host: name of the server host (string/None)
- :port: port used by the database server (integer/-1)
- :opt: connection options (string/None)
- :tty: debug terminal (string/None)
- :user: PostgreSQL user (string/None)
- :passwd: password for user (string/None)
-
-Return type:
- :pgobject: If successful, the `pgobject` handling the connection
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
- :SyntaxError: duplicate argument definition
- :pg.InternalError: some error occurred during pg connection definition
-
- (plus all exceptions relative to object allocation)
-
-Description:
- This function opens a connection to a specified database on a given
- PostgreSQL server. You can use keywords here, as described in the
- Python tutorial. The names of the keywords are the name of the
- parameters given in the syntax line. For a precise description
- of the parameters, please refer to the PostgreSQL user manual.
-
-Examples::
-
- import pg
-
- con1 = pg.connect('testdb', 'myhost', 5432, None, None, 'bob', None)
- con2 = pg.connect(dbname='testdb', host='localhost', user='bob')
-
-get_defhost, set_defhost - default server host [DV]
----------------------------------------------------
-Syntax::
-
- get_defhost()
-
-Parameters:
- None
-
-Return type:
- :string, None: default host specification
-
-Exceptions raised:
- :TypeError: too many arguments
-
-Description:
- This method returns the current default host specification,
- or `None` if the environment variables should be used.
- Environment variables won't be looked up.
-
-Syntax::
-
- set_defhost(host)
-
-Parameters:
- :host: new default host (string/None)
-
-Return type:
- :string, None: previous default host specification
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- This methods sets the default host value for new connections.
- If `None` is supplied as parameter, environment variables will
- be used in future connections. It returns the previous setting
- for default host.
-
-get_defport, set_defport - default server port [DV]
----------------------------------------------------
-Syntax::
-
- get_defport()
-
-Parameters:
- None
-
-Return type:
- :integer, None: default port specification
-
-Exceptions raised:
- :TypeError: too many arguments
-
-Description:
- This method returns the current default port specification,
- or `None` if the environment variables should be used.
- Environment variables won't be looked up.
-
-Syntax::
-
- set_defport(port)
-
-Parameters:
- :port: new default port (integer/-1)
-
-Return type:
- :integer, None: previous default port specification
-
-Description:
- This methods sets the default port value for new connections. If -1 is
- supplied as parameter, environment variables will be used in future
- connections. It returns the previous setting for default port.
-
-get_defopt, set_defopt - default connection options [DV]
---------------------------------------------------------
-Syntax::
-
- get_defopt()
-
-Parameters:
- None
-
-Return type:
- :string, None: default options specification
-
-Exceptions raised:
- :TypeError: too many arguments
-
-Description:
- This method returns the current default connection options specification,
- or `None` if the environment variables should be used. Environment variables
- won't be looked up.
-
-Syntax::
-
- set_defopt(options)
-
-Parameters:
- :options: new default connection options (string/None)
-
-Return type:
- :string, None: previous default options specification
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- This methods sets the default connection options value for new connections.
- If `None` is supplied as parameter, environment variables will be used in
- future connections. It returns the previous setting for default options.
-
-get_deftty, set_deftty - default debug tty [DV]
------------------------------------------------
-Syntax::
-
- get_deftty()
-
-Parameters:
- None
-
-Return type:
- :string, None: default debug terminal specification
-
-Exceptions raised:
- :TypeError: too many arguments
-
-Description:
- This method returns the current default debug terminal specification, or
- `None` if the environment variables should be used. Environment variables
- won't be looked up.
-
-Syntax::
-
- set_deftty(terminal)
-
-Parameters:
- :terminal: new default debug terminal (string/None)
-
-Return type:
- :string, None: previous default debug terminal specification
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- This methods sets the default debug terminal value for new connections. If
- `None` is supplied as parameter, environment variables will be used in future
- connections. It returns the previous setting for default terminal.
-
-get_defbase, set_defbase - default database name [DV]
------------------------------------------------------
-Syntax::
-
- get_defbase()
-
-Parameters:
- None
-
-Return type:
- :string, None: default database name specification
-
-Exceptions raised:
- :TypeError: too many arguments
-
-Description:
- This method returns the current default database name specification, or
- `None` if the environment variables should be used. Environment variables
- won't be looked up.
-
-Syntax::
-
- set_defbase(base)
-
-Parameters:
- :base: new default base name (string/None)
-
-Return type:
- :string, None: previous default database name specification
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- This method sets the default database name value for new connections. If
- `None` is supplied as parameter, environment variables will be used in
- future connections. It returns the previous setting for default host.
-
-escape_string - escape a string for use within SQL
---------------------------------------------------
-Syntax::
-
- escape_string(string)
-
-Parameters:
- :string: the string that is to be escaped
-
-Return type:
- :str: the escaped string
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- This function escapes a string for use within an SQL command.
- This is useful when inserting data values as literal constants
- in SQL commands. Certain characters (such as quotes and backslashes)
- must be escaped to prevent them from being interpreted specially
- by the SQL parser. `escape_string` performs this operation.
- Note that there is also a `pgobject` method with the same name
- which takes connection properties into account.
-
-.. caution:: It is especially important to do proper escaping when
- handling strings that were received from an untrustworthy source.
- Otherwise there is a security risk: you are vulnerable to "SQL injection"
- attacks wherein unwanted SQL commands are fed to your database.
-
-Example::
-
- name = raw_input("Name? ")
- phone = con.query("select phone from employees"
- " where name='%s'" % escape_string(name)).getresult()
-
-escape_bytea - escape binary data for use within SQL as type `bytea`
---------------------------------------------------------------------
-Syntax::
-
- escape_bytea(datastring)
-
-Parameters:
- :datastring: string containing the binary data that is to be escaped
-
-Return type:
- :str: the escaped string
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- Escapes binary data for use within an SQL command with the type `bytea`.
- As with `escape_string`, this is only used when inserting data directly
- into an SQL command string.
- Note that there is also a `pgobject` method with the same name
- which takes connection properties into account.
-
-Example::
-
- picture = file('garfield.gif', 'rb').read()
- con.query("update pictures set img='%s' where name='Garfield'"
- % escape_bytea(picture))
-
-unescape_bytea -- unescape `bytea` data that has been retrieved as text
------------------------------------------------------------------------
-Syntax::
-
- unescape_bytea(string)
-
-Parameters:
- :datastring: the `bytea` data string that has been retrieved as text
-
-Return type:
- :str: string containing the binary data
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
-
-Description:
- Converts an escaped string representation of binary data into binary
- data - the reverse of `escape_bytea`. This is needed when retrieving
- `bytea` data with the `getresult()` or `dictresult()` method.
-
-Example::
-
- picture = unescape_bytea(con.query(
- "select img from pictures where name='Garfield'").getresult[0][0])
- file('garfield.gif', 'wb').write(picture)
-
-set_decimal -- set a decimal type to be used for numeric values
----------------------------------------------------------------
-Syntax::
-
- set_decimal(cls)
-
-Parameters:
- :cls: the Python class to be used for PostgreSQL numeric values
-
-Description:
- This function can be used to specify the Python class that shall be
- used by PyGreSQL to hold PostgreSQL numeric values. The default class
- is decimal.Decimal if available, otherwise the float type is used.
-
-Module constants
-----------------
-Some constants are defined in the module dictionary.
-They are intended to be used as parameters for methods calls.
-You should refer to the libpq description in the PostgreSQL user manual
-for more information about them. These constants are:
-
-:version, __version__: constants that give the current version.
-:INV_READ, INV_WRITE: large objects access modes,
- used by `(pgobject.)locreate` and `(pglarge.)open`
-:SEEK_SET, SEEK_CUR, SEEK_END: positional flags,
- used by `(pglarge.)seek`
-
-
-Connection objects: pgobject
-============================
-This object handles a connection to a PostgreSQL database. It embeds and
-hides all the parameters that define this connection, thus just leaving really
-significant parameters in function calls.
-
-.. caution:: Some methods give direct access to the connection socket.
- *Do not use them unless you really know what you are doing.*
- If you prefer disabling them,
- set the -DNO_DIRECT option in the Python setup file.
-
- **These methods are specified by the tag [DA].**
-
-.. note:: Some other methods give access to large objects
- (refer to PostgreSQL user manual for more information about these).
- If you want to forbid access to these from the module,
- set the -DNO_LARGE option in the Python setup file.
-
- **These methods are specified by the tag [LO].**
-
-query - executes a SQL command string
--------------------------------------
-Syntax::
-
- query(command)
-
-Parameters:
- :command: SQL command (string)
-
-Return type:
- :pgqueryobject, None: result values
-
-Exceptions raised:
- :TypeError: bad argument type, or too many arguments
- :ValueError: empty SQL query or lost connection
- :pg.ProgrammingError: error in query
- :pg.InternalError': error during query processing
-
-Description:
- This method simply sends a SQL query to the database. If the query is an
- insert statement that inserted exactly one row into a table that has OIDs, the
- return value is the OID of the newly inserted row. If the query is an update
- or delete statement, or an insert statement that did not insert exactly one
- row in a table with OIDs, then the numer of rows affected is returned as a
- string. If it is a statement that returns rows as a result (usually a select
- statement, but maybe also an "insert/update ... returning" statement), this
- method returns a `pgqueryobject` that can be accessed via the `getresult()`
- or `dictresult()` method or simply printed. Otherwise, it returns `None`.
-
-reset - resets the connection
------------------------------
-Syntax::
-
- reset()
-
-Parameters:
- None
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: too many (any) arguments
-
-Description:
- This method resets the current database connection.
-
-cancel - abandon processing of current SQL command
---------------------------------------------------
-Syntax::
-
- cancel()
-
-Parameters:
- None
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: too many (any) arguments
-
-Description:
- This method requests that the server abandon processing
- of the current SQL command.
-
-close - close the database connection
--------------------------------------
-Syntax::
-
- close()
-
-Parameters:
- None
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: too many (any) arguments
-
-Description:
- This method closes the database connection. The connection will
- be closed in any case when the connection is deleted but this
- allows you to explicitly close it. It is mainly here to allow
- the DB-SIG API wrapper to implement a close function.
-
-fileno - returns the socket used to connect to the database
------------------------------------------------------------
-Syntax::
-
- fileno()
-
-Parameters:
- None
-
-Exceptions raised:
- :TypeError: too many (any) arguments
-
-Description:
- This method returns the underlying socket id used to connect
- to the database. This is useful for use in select calls, etc.
-
-getnotify - gets the last notify from the server
-------------------------------------------------
-Syntax::
-
- getnotify()
-
-Parameters:
- None
-
-Return type:
- :tuple, None: last notify from server
-
-Exceptions raised:
- :TypeError: too many parameters
- :TypeError: invalid connection
-
-Description:
- This methods try to get a notify from the server (from the SQL statement
- NOTIFY). If the server returns no notify, the methods returns None.
- Otherwise, it returns a tuple (couple) `(relname, pid)`, where `relname`
- is the name of the notify and `pid` the process id of the connection that
- triggered the notify. Remember to do a listen query first otherwise
- getnotify() will always return `None`.
-
-inserttable - insert a list into a table
-----------------------------------------
-Syntax::
-
- inserttable(table, values)
-
-Parameters:
- :table: the table name (string)
- :values: list of rows values (list)
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection, bad argument type, or too many arguments
- :MemoryError: insert buffer could not be allocated
- :ValueError: unsupported values
-
-Description:
- This method allow to *quickly* insert large blocks of data in a table:
- It inserts the whole values list into the given table. Internally, it
- uses the COPY command of the PostgreSQL database. The list is a list
- of tuples/lists that define the values for each inserted row. The rows
- values may contain string, integer, long or double (real) values.
-
-.. caution:: *Be very careful*:
- This method doesn't typecheck the fields according to the table definition;
- it just look whether or not it knows how to handle such types.
-
-putline - writes a line to the server socket [DA]
--------------------------------------------------
-Syntax::
-
- putline(line)
-
-Parameters:
- :line: line to be written (string)
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection, bad parameter type, or too many parameters
-
-Description:
- This method allows to directly write a string to the server socket.
-
-getline - gets a line from server socket [DA]
----------------------------------------------
-Syntax::
-
- getline()
-
-Parameters:
- None
-
-Return type:
- :string: the line read
-
-Exceptions raised:
- :TypeError: invalid connection
- :TypeError: too many parameters
- :MemoryError: buffer overflow
-
-Description:
- This method allows to directly read a string from the server socket.
-
-endcopy - synchronizes client and server [DA]
----------------------------------------------
-Syntax::
-
- endcopy()
-
-Parameters:
- None
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection
- :TypeError: too many parameters
-
-Description:
- The use of direct access methods may desynchonize client and server.
- This method ensure that client and server will be synchronized.
-
-locreate - create a large object in the database [LO]
------------------------------------------------------
-Syntax::
-
- locreate(mode)
-
-Parameters:
- :mode: large object create mode
-
-Return type:
- :pglarge: object handling the PostGreSQL large object
-
-Exceptions raised:
-
- :TypeError: invalid connection, bad parameter type, or too many parameters
- :pg.OperationalError: creation error
-
-Description:
- This method creates a large object in the database. The mode can be defined
- by OR-ing the constants defined in the pg module (INV_READ, INV_WRITE and
- INV_ARCHIVE). Please refer to PostgreSQL user manual for a description of
- the mode values.
-
-getlo - build a large object from given oid [LO]
-------------------------------------------------
-Syntax::
-
- getlo(oid)
-
-Parameters:
- :oid: OID of the existing large object (integer)
-
-Return type:
- :pglarge: object handling the PostGreSQL large object
-
-Exceptions raised:
- :TypeError: invalid connection, bad parameter type, or too many parameters
- :ValueError: bad OID value (0 is invalid_oid)
-
-Description:
- This method allows to reuse a formerly created large object through the
- `pglarge` interface, providing the user have its OID.
-
-loimport - import a file to a large object [LO]
------------------------------------------------
-Syntax::
-
- loimport(name)
-
-Parameters:
- :name: the name of the file to be imported (string)
-
-Return type:
- :pglarge: object handling the PostGreSQL large object
-
-Exceptions raised:
- :TypeError: invalid connection, bad argument type, or too many arguments
- :pg.OperationalError: error during file import
-
-Description:
- This methods allows to create large objects in a very simple way. You just
- give the name of a file containing the data to be use.
-
-Object attributes
------------------
-Every `pgobject` defines a set of read-only attributes that describe the
-connection and its status. These attributes are:
-
- :host: the host name of the server (string)
- :port: the port of the server (integer)
- :db: the selected database (string)
- :options: the connection options (string)
- :tty: the connection debug terminal (string)
- :user: user name on the database system (string)
- :protocol_version: the frontend/backend protocol being used (integer)
- :server_version: the backend version (integer, e.g. 80305 for 8.3.5)
- :status: the status of the connection (integer: 1 - OK, 0 - bad)
- :error: the last warning/error message from the server (string)
-
-
-The DB wrapper class
-====================
-The `pgobject` methods are wrapped in the class `DB`.
-The preferred way to use this module is as follows::
-
- import pg
-
- db = pg.DB(...) # see below
-
- for r in db.query( # just for example
- """SELECT foo,bar
- FROM foo_bar_table
- WHERE foo !~ bar"""
- ).dictresult():
-
- print '%(foo)s %(bar)s' % r
-
-This class can be subclassed as in this example::
-
- import pg
-
- class DB_ride(pg.DB):
- """This class encapsulates the database functions and the specific
- methods for the ride database."""
-
- def __init__(self):
- """Opens a database connection to the rides database"""
-
- pg.DB.__init__(self, dbname = 'ride')
- self.query("""SET DATESTYLE TO 'ISO'""")
-
- [Add or override methods here]
-
-The following describes the methods and variables of this class.
-
-Initialization
---------------
-The DB class is initialized with the same arguments as the connect
-function described in section 2. It also initializes a few
-internal variables. The statement `db = DB()` will open the
-local database with the name of the user just like connect() does.
-
-You can also initialize the DB class with an existing `_pg` or `pgdb`
-connection. Pass this connection as a single unnamed parameter, or as a
-single parameter named `db`. This allows you to use all of the methods
-of the DB class with a DB-API 2 compliant connection. Note that the
-`close()` and `reopen()` methods are inoperative in this case.
-
-
-
-pkey - return the primary key of a table
-----------------------------------------
-Syntax::
-
- pkey(table)
-
-Parameters:
- :table: name of table
-
-Return type:
- :string: Name of the field which is the primary key of the table
-
-Description:
- This method returns the primary key of a table. For composite primary
- keys, the return value will be a frozenset. Note that this raises an
- exception if the table does not have a primary key.
-
-get_databases - get list of databases in the system
----------------------------------------------------
-Syntax::
-
- get_databases()
-
-Parameters:
- None
-
-Return type:
- :list: all databases in the system
-
-Description:
- Although you can do this with a simple select, it is added here for
- convenience.
-
-get_relations - get list of relations in connected database
------------------------------------------------------------
-Syntax::
-
- get_relations(kinds)
-
-Parameters:
- :kinds: a string or sequence of type letters
-
-Description:
- The type letters are `r` = ordinary table, `i` = index, `S` = sequence,
- `v` = view, `c` = composite type, `s` = special, `t` = TOAST table.
- If `kinds` is None or an empty string, all relations are returned (this is
- also the default). Although you can do this with a simple select, it is
- added here for convenience.
-
-get_tables - get list of tables in connected database
------------------------------------------------------
-Syntax::
-
- get_tables()
-
-Parameters:
- None
-
-Returns:
- :list: all tables in connected database
-
-Description:
- Although you can do this with a simple select, it is added here for
- convenience.
-
-get_attnames - get the attribute names of a table
--------------------------------------------------
-Syntax::
-
- get_attnames(table)
-
-Parameters:
- :table: name of table
-
-Returns:
- :dictionary: The keys are the attribute names,
- the values are the type names of the attributes.
-
-Description:
- Given the name of a table, digs out the set of attribute names.
-
-has_table_privilege - check whether current user has specified table privilege
-------------------------------------------------------------------------------
-Syntax::
-
- has_table_privilege(table, privilege)
-
-Parameters:
- :table: name of table
- :privilege: privilege to be checked - default is 'select'
-
-Description:
- Returns True if the current user has the specified privilege for the table.
-
-get - get a row from a database table or view
----------------------------------------------
-Syntax::
-
- get(table, arg, [keyname])
-
-Parameters:
- :table: name of table or view
- :arg: either a dictionary or the value to be looked up
- :keyname: name of field to use as key (optional)
-
-Return type:
- :dictionary: The keys are the attribute names,
- the values are the row values.
-
-Description:
- This method is the basic mechanism to get a single row. It assumes
- that the key specifies a unique row. If `keyname` is not specified
- then the primary key for the table is used. If `arg` is a dictionary
- then the value for the key is taken from it and it is modified to
- include the new values, replacing existing values where necessary.
- For a composite key, `keyname` can also be a sequence of key names.
- The OID is also put into the dictionary if the table has one, but in
- order to allow the caller to work with multiple tables, it is munged
- as `oid(schema.table)`.
-
-insert - insert a row into a database table
--------------------------------------------
-Syntax::
-
- insert(table, [d,] [return_changes,] [key = val, ...])
-
-Parameters:
- :table: name of table
- :d: optional dictionary of values
- :return_changes: Return values in new row - default True
-
-Return type:
- :dictionary: The dictionary of values inserted
-
-Description:
- This method inserts a row into a table. If the optional dictionary is
- not supplied then the required values must be included as keyword/value
- pairs. If a dictionary is supplied then any keywords provided will be
- added to or replace the entry in the dictionary.
-
- The dictionary is then, if possible, reloaded with the values actually
- inserted in order to pick up values modified by rules, triggers, etc.
-
- Due to the way that this function works in PostgreSQL versions below
- 8.2, you may find inserts taking longer and longer as your table gets
- bigger. If this happens and it is a table with OID but no primary key
- you can overcome this problem by simply adding an index onto the OID of
- any table that you think may get large over time. You may also consider
- using the inserttable() method described in section 3.
-
- Note: With PostgreSQL versions before 8.2 the table being inserted to
- must have a primary key or an OID to use this method properly. If not
- then the dictionary will not be filled in as described. Also, if this
- method is called within a transaction, the transaction will abort.
-
- Note: The method currently doesn't support insert into views
- although PostgreSQL does.
-
-update - update a row in a database table
------------------------------------------
-Syntax::
-
- update(table, [d,] [key = val, ...])
-
-Parameters:
- :table: name of table
- :d: optional dictionary of values
-
-Return type:
- :dictionary: the new row
-
-Description:
- Similar to insert but updates an existing row. The update is based on the
- OID value as munged by get or passed as keyword, or on the primary key of
- the table. The dictionary is modified, if possible, to reflect any changes
- caused by the update due to triggers, rules, default values, etc.
-
- Like insert, the dictionary is optional and updates will be performed
- on the fields in the keywords. There must be an OID or primary key
- either in the dictionary where the OID must be munged, or in the keywords
- where it can be simply the string "oid".
-
-clear - clears row values in memory
------------------------------------
-Syntax::
-
- clear(table, [a])
-
-Parameters:
- :table: name of table
- :a: optional dictionary of values
-
-Return type:
- :dictionary: an empty row
-
-Description:
- This method clears all the attributes to values determined by the types.
- Numeric types are set to 0, Booleans are set to 'f', dates are set
- to 'now()' and everything else is set to the empty string.
- If the array argument is present, it is used as the array and any entries
- matching attribute names are cleared with everything else left unchanged.
-
- If the dictionary is not supplied a new one is created.
-
-delete - delete a row from a database table
--------------------------------------------
-Syntax::
-
- delete(table, [d,] [key = val, ...])
-
-Parameters:
- :table: name of table
- :d: optional dictionary of values
-
-Returns:
- None
-
-Description:
- This method deletes the row from a table. It deletes based on the OID value
- as munged by get or passed as keyword, or on the primary key of the table.
- The return value is the number of deleted rows (i.e. 0 if the row did not
- exist and 1 if the row was deleted).
-
-escape_string - escape a string for use within SQL
---------------------------------------------------
-Syntax::
-
- escape_string(string)
-
-Parameters:
- :string: the string that is to be escaped
-
-Return type:
- :str: the escaped string
-
-Description:
- Similar to the module function with the same name, but the
- behavior of this method is adjusted depending on the connection properties
- (such as character encoding).
-
-escape_bytea - escape binary data for use within SQL as type `bytea`
---------------------------------------------------------------------
-Syntax::
-
- escape_bytea(datastring)
-
-Parameters:
- :datastring: string containing the binary data that is to be escaped
-
-Return type:
- :str: the escaped string
-
-Description:
- Similar to the module function with the same name, but the
- behavior of this method is adjusted depending on the connection properties
- (in particular, whether standard-conforming strings are enabled).
-
-unescape_bytea -- unescape `bytea` data that has been retrieved as text
------------------------------------------------------------------------
-Syntax::
-
- unescape_bytea(string)
-
-Parameters:
- :datastring: the `bytea` data string that has been retrieved as text
-
-Return type:
- :str: string containing the binary data
-
-Description:
- See the module function with the same name.
-
-
-pgqueryobject methods
-=====================
-
-getresult - get query values as list of tuples
------------------------------------------------
-Syntax::
-
- getresult()
-
-Parameters:
- None
-
-Return type:
- :list: result values as a list of tuples
-
-Exceptions raised:
- :TypeError: too many parameters
- :pg.InternalError: invalid previous result
-
-Description:
- This method returns the list of the values returned by the query.
- More information about this result may be accessed using listfields(),
- fieldname() and fieldnum() methods.
-
-dictresult - get query values as list of dictionaries
------------------------------------------------------
-Syntax::
-
- dictresult()
-
-Parameters:
- None
-
-Return type:
- :list: result values as a list of dictionaries
-
-Exceptions raised:
- :TypeError: too many parameters
- :pg.InternalError: invalid previous result
-
-Description:
- This method returns the list of the values returned by the query
- with each tuple returned as a dictionary with the field names
- used as the dictionary index.
-
-
-listfields - lists fields names of previous query result
---------------------------------------------------------
-Syntax::
-
- listfields()
-
-Parameters:
- None
-
-Return type:
- :list: field names
-
-Exceptions raised:
- :TypeError: too many parameters
- :pg.InternalError: invalid previous result, or lost connection
-
-Description:
- This method returns the list of names of the fields defined for the
- query result. The fields are in the same order as the result values.
-
-fieldname, fieldnum - field name/number conversion
---------------------------------------------------
-Syntax::
-
- fieldname(i)
-
-Parameters:
- :i: field number (integer)
-
-Return type:
- :string: field name
-
-Exceptions raised:
- :TypeError: invalid connection, bad parameter type, or too many parameters
- :ValueError: invalid field number
- :pg.InternalError: invalid previous result, or lost connection
-
-Description:
- This method allows to find a field name from its rank number. It can be
- useful for displaying a result. The fields are in the same order as the
- result values.
-
-Syntax::
-
- fieldnum(name)
-
-Parameters:
- :name: field name (string)
-
-Return type:
- :integer: field number
-
-Exceptions raised:
- :TypeError: invalid connection, bad parameter type, or too many parameters
- :ValueError: unknown field name
- :pg.InternalError: invalid previous result, or lost connection
-
-Description:
- This method returns a field number from its name. It can be used to
- build a function that converts result list strings to their correct
- type, using a hardcoded table definition. The number returned is the
- field rank in the result values list.
-
-ntuples - return number of tuples in query object
--------------------------------------------------
-Syntax::
-
- ntuples()
-
-Parameters:
- None
-
-Return type:
- :integer: number of tuples in `pgqueryobject`
-
-Exceptions raised:
- :TypeError: Too many arguments.
-
-Description:
- This method returns the number of tuples found in a query.
-
-
-Large objects: pglarge
-======================
-This object handles all the request concerning a PostgreSQL large object. It
-embeds and hides all the "recurrent" variables (object OID and connection),
-exactly in the same way `pgobjects` do, thus only keeping significant
-parameters in function calls. It keeps a reference to the `pgobject` used for
-its creation, sending requests though with its parameters. Any modification but
-dereferencing the `pgobject` will thus affect the `pglarge` object.
-Dereferencing the initial `pgobject` is not a problem since Python won't
-deallocate it before the `pglarge` object dereference it.
-All functions return a generic error message on call error, whatever the
-exact error was. The `error` attribute of the object allow to get the exact
-error message.
-
-See also the PostgreSQL programmer's guide for more information about the
-large object interface.
-
-open - opens a large object
----------------------------
-Syntax::
-
- open(mode)
-
-Parameters:
- :mode: open mode definition (integer)
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection, bad parameter type, or too many parameters
- :IOError: already opened object, or open error
-
-Description:
- This method opens a large object for reading/writing, in the same way than
- the Unix open() function. The mode value can be obtained by OR-ing the
- constants defined in the pgmodule (INV_READ, INV_WRITE).
-
-close - closes a large object
------------------------------
-Syntax::
-
- close()
-
-Parameters:
- None
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection
- :TypeError: too many parameters
- :IOError: object is not opened, or close error
-
-Description:
- This method closes a previously opened large object, in the same way than
- the Unix close() function.
-
-read, write, tell, seek, unlink - file like large object handling
------------------------------------------------------------------
-Syntax::
-
- read(size)
-
-Parameters:
- :size: maximal size of the buffer to be read
-
-Return type:
- :sized string: the read buffer
-
-Exceptions raised:
- :TypeError: invalid connection, invalid object,
- bad parameter type, or too many parameters
- :ValueError: if `size` is negative
- :IOError: object is not opened, or read error
-
-Description:
- This function allows to read data from a large object, starting at current
- position.
-
-Syntax::
-
- write(string)
-
-Parameters:
- (sized) string - buffer to be written
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection, bad parameter type, or too many parameters
- :IOError: object is not opened, or write error
-
-Description:
- This function allows to write data to a large object, starting at current
- position.
-
-Syntax::
-
- seek(offset, whence)
-
-Parameters:
- :offset: position offset
- :whence: positional parameter
-
-Return type:
- :integer: new position in object
-
-Exceptions raised:
- :TypeError: binvalid connection or invalid object,
- bad parameter type, or too many parameters
- :IOError: object is not opened, or seek error
-
-Description:
- This method allows to move the position cursor in the large object. The
- whence parameter can be obtained by OR-ing the constants defined in the
- `pg` module (`SEEK_SET`, `SEEK_CUR`, `SEEK_END`).
-
-Syntax::
-
- tell()
-
-Parameters:
- None
-
-Return type:
- :integer: current position in large object
-
-Exceptions raised:
- :TypeError: invalid connection or invalid object
- :TypeError: too many parameters
- :IOError: object is not opened, or seek error
-
-Description:
- This method allows to get the current position in the large object.
-
-Syntax::
-
- unlink()
-
-Parameter:
- None
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection or invalid object
- :TypeError: too many parameters
- :IOError: object is not closed, or unlink error
-
-Description:
- This methods unlinks (deletes) the PostgreSQL large object.
-
-size - gives the large object size
-----------------------------------
-
-Syntax::
-
- size()
-
-Parameters:
- None
-
-Return type:
- :integer: the large object size
-
-Exceptions raised:
- :TypeError: invalid connection or invalid object
- :TypeError: too many parameters
- :IOError: object is not opened, or seek/tell error
-
-Description:
- This (composite) method allows to get the size of a large object. It was
- implemented because this function is very useful for a web interfaced
- database. Currently, the large object needs to be opened first.
-
-export - saves a large object to a file
----------------------------------------
-Syntax::
-
- export(name)
-
-Parameters:
- :name: file to be created
-
-Return type:
- None
-
-Exceptions raised:
- :TypeError: invalid connection or invalid object,
- bad parameter type, or too many parameters
- :IOError: object is not closed, or export error
-
-Description:
- This methods allows to dump the content of a large object in a very simple
- way. The exported file is created on the host of the program, not the
- server host.
-
-Object attributes
------------------
-`pglarge` objects define a read-only set of attributes that allow to get
-some information about it. These attributes are:
-
- :oid: the OID associated with the object
- :pgcnx: the `pgobject` associated with the object
- :error: the last warning/error message of the connection
-
-.. caution:: *Be careful*:
- In multithreaded environments, `error` may be modified by another thread
- using the same pgobject. Remember these object are shared, not duplicated.
- You should provide some locking to be able if you want to check this.
- The `oid` attribute is very interesting because it allow you reuse the OID
- later, creating the `pglarge` object with a `pgobject` getlo() method call.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.html
deleted file mode 100644
index 84962f4..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.html
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL Programming Information</title>
-<meta content="The DB-API compliant interface (pgdb module)" name="description" />
-<meta content="PyGreSQL, pgdb, DB-API, PostGreSQL, Python" name="keywords" />
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-programming-information">
-<h1 class="title">PyGreSQL Programming Information</h1>
-<h2 class="subtitle" id="the-db-api-compliant-interface-pgdb-module">The DB-API compliant interface (pgdb module)</h2>
-<div class="contents topic">
-<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
-<ul class="auto-toc simple">
-<li><a class="reference" href="#introduction" id="id1" name="id1">1 Introduction</a></li>
-<li><a class="reference" href="#the-pgdb-module" id="id2" name="id2">2 The pgdb module</a></li>
-</ul>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id1" id="introduction" name="introduction">1 Introduction</a></h1>
-<p>You may either choose to use the
-<a class="reference" href="pg.html">"classic" PyGreSQL interface</a>
-provided by the <cite>pg</cite> module or else the
-<a class="reference" href="pgdb.html">DB-API 2.0 compliant interface</a>
-provided by the <cite>pgdb</cite> module.</p>
-<p><a class="reference" href="http://www.python.org/dev/peps/pep-0249/">DB-API 2.0</a>
-(Python Database API Specification v2.0)
-is a specification for connecting to databases (not only PostGreSQL)
-from Python that has been developed by the Python DB-SIG in 1999.</p>
-<p>The following documentation covers only the newer <cite>pgdb</cite> API.</p>
-<dl class="docutils">
-<dt>The authoritative programming information for the DB-API is availabe at</dt>
-<dd><a class="reference" href="http://www.python.org/dev/peps/pep-0249/">http://www.python.org/dev/peps/pep-0249/</a></dd>
-<dt>A tutorial-like introduction to the DB-API can be found at</dt>
-<dd><a class="reference" href="http://www2.linuxjournal.com/lj-issues/issue49/2605.html">http://www2.linuxjournal.com/lj-issues/issue49/2605.html</a></dd>
-</dl>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id2" id="the-pgdb-module" name="the-pgdb-module">2 The pgdb module</a></h1>
-<div class="note">
-<p class="first admonition-title">Note</p>
-<p class="last">This section of the documentation still needs to be written.</p>
-</div>
-</div>
-</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.txt
deleted file mode 100644
index b333c01..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.txt
+++ /dev/null
@@ -1,42 +0,0 @@
-================================
-PyGreSQL Programming Information
-================================
-
---------------------------------------------
-The DB-API compliant interface (pgdb module)
---------------------------------------------
-
-.. meta::
- :description: The DB-API compliant interface (pgdb module)
- :keywords: PyGreSQL, pgdb, DB-API, PostGreSQL, Python
-
-.. sectnum::
-.. contents:: Contents
-
-
-Introduction
-============
-You may either choose to use the
-`"classic" PyGreSQL interface <pg.html>`_
-provided by the `pg` module or else the
-`DB-API 2.0 compliant interface <pgdb.html>`_
-provided by the `pgdb` module.
-
-`DB-API 2.0 <http://www.python.org/dev/peps/pep-0249/>`_
-(Python Database API Specification v2.0)
-is a specification for connecting to databases (not only PostGreSQL)
-from Python that has been developed by the Python DB-SIG in 1999.
-
-The following documentation covers only the newer `pgdb` API.
-
-The authoritative programming information for the DB-API is availabe at
- http://www.python.org/dev/peps/pep-0249/
-
-A tutorial-like introduction to the DB-API can be found at
- http://www2.linuxjournal.com/lj-issues/issue49/2605.html
-
-
-The pgdb module
-===============
-.. note:: This section of the documentation still needs to be written.
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.html
deleted file mode 100644
index 656f8cd..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.html
+++ /dev/null
@@ -1,243 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL - Python interface for PostgreSQL</title>
-<meta content="PyGreSQL - Python interface for PostgreSQL" name="description" />
-<meta content="PyGreSQL, PostGreSQL, Python" name="keywords" />
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-python-interface-for-postgresql">
-<h1 class="title">PyGreSQL - Python interface for PostgreSQL</h1>
-<h2 class="subtitle" id="pygresql-version-4-0">PyGreSQL version 4.0</h2>
-<div class="contents topic">
-<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
-<ul class="simple">
-<li><a class="reference" href="#copyright-notice" id="id1" name="id1">Copyright notice</a></li>
-<li><a class="reference" href="#introduction" id="id2" name="id2">Introduction</a></li>
-<li><a class="reference" href="#where-to-get" id="id3" name="id3">Where to get ... ?</a><ul>
-<li><a class="reference" href="#home-sites-of-the-different-packages" id="id4" name="id4">Home sites of the different packages</a></li>
-<li><a class="reference" href="#download-pygresql-here" id="id5" name="id5">Download PyGreSQL here</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#distribution-files" id="id6" name="id6">Distribution files</a></li>
-<li><a class="reference" href="#installation" id="id7" name="id7">Installation</a></li>
-<li><a class="reference" href="#information-and-support" id="id8" name="id8">Information and support</a><ul>
-<li><a class="reference" href="#for-general-information" id="id9" name="id9">For general information</a></li>
-<li><a class="reference" href="#for-support" id="id10" name="id10">For support</a></li>
-<li><a class="reference" href="#pygresql-programming-information" id="id11" name="id11">PyGreSQL programming information</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#changelog-and-future" id="id12" name="id12">ChangeLog and Future</a></li>
-</ul>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id1" id="copyright-notice" name="copyright-notice">Copyright notice</a></h1>
-<p>Written by D'Arcy J.M. Cain (<a class="reference" href="mailto:darcy@druid.net">darcy@druid.net</a>)</p>
-<p>Based heavily on code written by Pascal Andre (<a class="reference" href="mailto:andre@chimay.via.ecp.fr">andre@chimay.via.ecp.fr</a>)</p>
-<p>Copyright (c) 1995, Pascal Andre</p>
-<p>Further modifications copyright (c) 1997-2008 by D'Arcy J.M. Cain
-(<a class="reference" href="mailto:darcy@druid.net">darcy@druid.net</a>)</p>
-<p>Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose, without fee, and without a written agreement
-is hereby granted, provided that the above copyright notice and this
-paragraph and the following two paragraphs appear in all copies or in any
-new file that contains a substantial portion of this file.</p>
-<p>IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
-ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
-AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
-<p>THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
-AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
-ENHANCEMENTS, OR MODIFICATIONS.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id2" id="introduction" name="introduction">Introduction</a></h1>
-<p><strong>PostgreSQL</strong> is a highly scalable, SQL compliant, open source
-object-relational database management system. With more than 15 years
-of development history, it is quickly becoming the de facto database
-for enterprise level open source solutions.
-Best of all, PostgreSQL's source code is available under the most liberal
-open source license: the BSD license.</p>
-<p><strong>Python</strong> Python is an interpreted, interactive, object-oriented
-programming language. It is often compared to Tcl, Perl, Scheme or Java.
-Python combines remarkable power with very clear syntax. It has modules,
-classes, exceptions, very high level dynamic data types, and dynamic typing.
-There are interfaces to many system calls and libraries, as well as to
-various windowing systems (X11, Motif, Tk, Mac, MFC). New built-in modules
-are easily written in C or C++. Python is also usable as an extension
-language for applications that need a programmable interface.
-The Python implementation is copyrighted but freely usable and distributable,
-even for commercial use.</p>
-<p><strong>PyGreSQL</strong> is a Python module that interfaces to a PostgreSQL database.
-It embeds the PostgreSQL query library to allow easy use of the powerful
-PostgreSQL features from a Python script.</p>
-<p>PyGreSQL is developed and tested on a NetBSD system, but it should also
-run on most other platforms where PostgreSQL and Python is running.
-It is based on the PyGres95 code written by Pascal Andre (<a class="reference" href="mailto:andre@chimay.via.ecp.fr">andre@chimay.via.ecp.fr</a>).
-D'Arcy (<a class="reference" href="mailto:darcy@druid.net">darcy@druid.net</a>) renamed it to PyGreSQL starting with
-version 2.0 and serves as the "BDFL" of PyGreSQL.</p>
-<p>The current version PyGreSQL 4.0 needs PostgreSQL 7.2 and Python 2.3 or above.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id3" id="where-to-get" name="where-to-get">Where to get ... ?</a></h1>
-<div class="section">
-<h2><a class="toc-backref" href="#id4" id="home-sites-of-the-different-packages" name="home-sites-of-the-different-packages">Home sites of the different packages</a></h2>
-<dl class="docutils">
-<dt><strong>Python</strong>:</dt>
-<dd><a class="reference" href="http://www.python.org">http://www.python.org</a></dd>
-<dt><strong>PostgreSQL</strong>:</dt>
-<dd><a class="reference" href="http://www.postgresql.org">http://www.postgresql.org</a></dd>
-<dt><strong>PyGreSQL</strong>:</dt>
-<dd><a class="reference" href="http://www.pygresql.org">http://www.pygresql.org</a></dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id5" id="download-pygresql-here" name="download-pygresql-here">Download PyGreSQL here</a></h2>
-<dl class="docutils">
-<dt>The <strong>released version of the source code</strong> is available at</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/PyGreSQL.tgz">ftp://ftp.pygresql.org/pub/distrib/PyGreSQL.tgz</a></li>
-</ul>
-</dd>
-<dt>You can also check the latest <strong>pre-release version</strong> at</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-beta.tgz">ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-beta.tgz</a></li>
-</ul>
-</dd>
-<dt>A <strong>Linux RPM</strong> can be picked up from</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/pygresql.i386.rpm">ftp://ftp.pygresql.org/pub/distrib/pygresql.i386.rpm</a></li>
-</ul>
-</dd>
-<dt>A <strong>NetBSD package</strong> is available in their pkgsrc collection</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/databases/py-postgresql/README.html">ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/databases/py-postgresql/README.html</a></li>
-</ul>
-</dd>
-<dt>A <strong>FreeBSD package</strong> is available in their ports collection</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="http://www.freebsd.org/cgi/cvsweb.cgi/ports/databases/py-PyGreSQL/">http://www.freebsd.org/cgi/cvsweb.cgi/ports/databases/py-PyGreSQL/</a></li>
-</ul>
-</dd>
-<dt>A <strong>Win32 package</strong> for various Python versions is available at</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.3.exe">ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.3.exe</a></li>
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.4.exe">ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.4.exe</a></li>
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.5.exe">ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.5.exe</a></li>
-<li><a class="reference" href="ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.6.exe">ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.6.exe</a></li>
-</ul>
-</dd>
-<dt>You can also find PyGreSQL on the <strong>Python Package Index</strong> at</dt>
-<dd><ul class="first last simple">
-<li><a class="reference" href="http://pypi.python.org/pypi/PyGreSQL/">http://pypi.python.org/pypi/PyGreSQL/</a></li>
-</ul>
-</dd>
-</dl>
-</div>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id6" id="distribution-files" name="distribution-files">Distribution files</a></h1>
-<table border="1" class="docutils">
-<colgroup>
-<col width="15%" />
-<col width="85%" />
-</colgroup>
-<tbody valign="top">
-<tr><td>pgmodule.c</td>
-<td>the C Python module (_pg)</td>
-</tr>
-<tr><td>pg.py</td>
-<td>the "classic" PyGreSQL module</td>
-</tr>
-<tr><td>pgdb.py</td>
-<td>DB-SIG DB-API 2.0 compliant API wrapper for PygreSQL</td>
-</tr>
-<tr><td>docs/</td>
-<td><p class="first">documentation directory</p>
-<p>Contains: readme.txt, announce.txt, install.txt,
-changelog.txt, future.txt, pg.txt and pgdb.txt.</p>
-<p class="last">All text files are in ReST format, so HTML versions
-can be easily created with buildhtml.py from docutils.</p>
-</td>
-</tr>
-<tr><td>tutorial/</td>
-<td><p class="first">demos directory</p>
-<p>Contains: basics.py, syscat.py, advanced.py and func.py.</p>
-<p class="last">The samples here have been taken from the
-PostgreSQL manual and were used for module testing.
-They demonstrate some PostgreSQL features.</p>
-</td>
-</tr>
-</tbody>
-</table>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id7" id="installation" name="installation">Installation</a></h1>
-<p>You will find the installing instructions in
-<a class="reference" href="install.html">install.txt</a>.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id8" id="information-and-support" name="information-and-support">Information and support</a></h1>
-<div class="section">
-<h2><a class="toc-backref" href="#id9" id="for-general-information" name="for-general-information">For general information</a></h2>
-<dl class="docutils">
-<dt><strong>Python</strong>:</dt>
-<dd><a class="reference" href="http://www.python.org">http://www.python.org</a></dd>
-<dt><strong>PostgreSQL</strong>:</dt>
-<dd><a class="reference" href="http://www.postgresql.org">http://www.postgresql.org</a></dd>
-<dt><strong>PyGreSQL</strong>:</dt>
-<dd><a class="reference" href="http://www.pygresql.org">http://www.pygresql.org</a></dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id10" id="for-support" name="for-support">For support</a></h2>
-<dl class="docutils">
-<dt><strong>Python</strong>:</dt>
-<dd>see <a class="reference" href="http://www.python.org/community/">http://www.python.org/community/</a></dd>
-<dt><strong>PostgreSQL</strong>:</dt>
-<dd>see <a class="reference" href="http://www.postgresql.org/support/">http://www.postgresql.org/support/</a></dd>
-<dt><strong>PyGreSQL</strong>:</dt>
-<dd><p class="first">Contact the PyGreSQL mailing list
-concerning PyGreSQL 2.0 and up.</p>
-<p>If you would like to proposes changes, please join the
-PyGreSQL mailing list and send context diffs there.</p>
-<p class="last">See <a class="reference" href="http://mailman.vex.net/mailman/listinfo/pygresql">http://mailman.vex.net/mailman/listinfo/pygresql</a>
-to join the mailing list.</p>
-</dd>
-</dl>
-<p>Please note that messages to individual developers will generally not be
-answered directly. All questions, comments and code changes must be
-submitted to the mailing list for peer review and archiving.</p>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id11" id="pygresql-programming-information" name="pygresql-programming-information">PyGreSQL programming information</a></h2>
-<p>You may either choose to use the "classic" PyGreSQL interface
-provided by the <cite>pg</cite> module or else the newer DB-API 2.0
-compliant interface provided by the <cite>pgdb</cite> module.</p>
-<p><a class="reference" href="http://www.python.org/dev/peps/pep-0249/">DB-API 2.0</a>
-(Python Database API Specification v2.0)
-is a specification for connecting to databases (not only PostGreSQL)
-from Python that has been developed by the Python DB-SIG in 1999.</p>
-<p>The programming information is available in the files
-<a class="reference" href="pg.html">pg.txt</a> and <a class="reference" href="pgdb.html">pgdb.txt</a>.</p>
-<p>Note that PyGreSQL is not thread-safe on the connection level. Therefore
-we recommend using <cite>DBUtils <http://www.webwareforpython.org/DBUtils></cite>
-for multi-threaded environments, which supports both PyGreSQL interfaces.</p>
-</div>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id12" id="changelog-and-future" name="changelog-and-future">ChangeLog and Future</a></h1>
-<p>The ChangeLog with past changes is in the file
-<a class="reference" href="changelog.html">changelog.txt</a>.</p>
-<p>A to do list and wish list is in the file
-<a class="reference" href="future.html">future.txt</a>.</p>
-</div>
-</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.txt
deleted file mode 100644
index 77ed8ef..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/readme.txt
+++ /dev/null
@@ -1,206 +0,0 @@
-==========================================
-PyGreSQL - Python interface for PostgreSQL
-==========================================
-
---------------------
-PyGreSQL version 4.0
---------------------
-
-.. meta::
- :description: PyGreSQL - Python interface for PostgreSQL
- :keywords: PyGreSQL, PostGreSQL, Python
-
-.. contents:: Contents
-
-
-Copyright notice
-================
-
-Written by D'Arcy J.M. Cain (darcy@druid.net)
-
-Based heavily on code written by Pascal Andre (andre@chimay.via.ecp.fr)
-
-Copyright (c) 1995, Pascal Andre
-
-Further modifications copyright (c) 1997-2008 by D'Arcy J.M. Cain
-(darcy@druid.net)
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose, without fee, and without a written agreement
-is hereby granted, provided that the above copyright notice and this
-paragraph and the following two paragraphs appear in all copies or in any
-new file that contains a substantial portion of this file.
-
-IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
-ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
-AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
-AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
-ENHANCEMENTS, OR MODIFICATIONS.
-
-
-Introduction
-============
-
-**PostgreSQL** is a highly scalable, SQL compliant, open source
-object-relational database management system. With more than 15 years
-of development history, it is quickly becoming the de facto database
-for enterprise level open source solutions.
-Best of all, PostgreSQL's source code is available under the most liberal
-open source license: the BSD license.
-
-**Python** Python is an interpreted, interactive, object-oriented
-programming language. It is often compared to Tcl, Perl, Scheme or Java.
-Python combines remarkable power with very clear syntax. It has modules,
-classes, exceptions, very high level dynamic data types, and dynamic typing.
-There are interfaces to many system calls and libraries, as well as to
-various windowing systems (X11, Motif, Tk, Mac, MFC). New built-in modules
-are easily written in C or C++. Python is also usable as an extension
-language for applications that need a programmable interface.
-The Python implementation is copyrighted but freely usable and distributable,
-even for commercial use.
-
-**PyGreSQL** is a Python module that interfaces to a PostgreSQL database.
-It embeds the PostgreSQL query library to allow easy use of the powerful
-PostgreSQL features from a Python script.
-
-PyGreSQL is developed and tested on a NetBSD system, but it should also
-run on most other platforms where PostgreSQL and Python is running.
-It is based on the PyGres95 code written by Pascal Andre (andre@chimay.via.ecp.fr).
-D'Arcy (darcy@druid.net) renamed it to PyGreSQL starting with
-version 2.0 and serves as the "BDFL" of PyGreSQL.
-
-The current version PyGreSQL 4.0 needs PostgreSQL 7.2 and Python 2.3 or above.
-
-
-Where to get ... ?
-==================
-
-Home sites of the different packages
-------------------------------------
-**Python**:
- http://www.python.org
-
-**PostgreSQL**:
- http://www.postgresql.org
-
-**PyGreSQL**:
- http://www.pygresql.org
-
-Download PyGreSQL here
-----------------------
-The **released version of the source code** is available at
- * ftp://ftp.pygresql.org/pub/distrib/PyGreSQL.tgz
-You can also check the latest **pre-release version** at
- * ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-beta.tgz
-A **Linux RPM** can be picked up from
- * ftp://ftp.pygresql.org/pub/distrib/pygresql.i386.rpm
-A **NetBSD package** is available in their pkgsrc collection
- * ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/databases/py-postgresql/README.html
-A **FreeBSD package** is available in their ports collection
- * http://www.freebsd.org/cgi/cvsweb.cgi/ports/databases/py-PyGreSQL/
-A **Win32 package** for various Python versions is available at
- * ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.3.exe
- * ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.4.exe
- * ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.5.exe
- * ftp://ftp.pygresql.org/pub/distrib/PyGreSQL-4.0.win32-py2.6.exe
-You can also find PyGreSQL on the **Python Package Index** at
- * http://pypi.python.org/pypi/PyGreSQL/
-
-
-Distribution files
-==================
-
-========== =
-pgmodule.c the C Python module (_pg)
-pg.py the "classic" PyGreSQL module
-pgdb.py DB-SIG DB-API 2.0 compliant API wrapper for PygreSQL
-docs/ documentation directory
-
- Contains: readme.txt, announce.txt, install.txt,
- changelog.txt, future.txt, pg.txt and pgdb.txt.
-
- All text files are in ReST format, so HTML versions
- can be easily created with buildhtml.py from docutils.
-tutorial/ demos directory
-
- Contains: basics.py, syscat.py, advanced.py and func.py.
-
- The samples here have been taken from the
- PostgreSQL manual and were used for module testing.
- They demonstrate some PostgreSQL features.
-========== =
-
-
-Installation
-============
-You will find the installing instructions in
-`install.txt <install.html>`_.
-
-
-Information and support
-=======================
-
-For general information
------------------------
-**Python**:
- http://www.python.org
-
-**PostgreSQL**:
- http://www.postgresql.org
-
-**PyGreSQL**:
- http://www.pygresql.org
-
-For support
------------
-**Python**:
- see http://www.python.org/community/
-
-**PostgreSQL**:
- see http://www.postgresql.org/support/
-
-**PyGreSQL**:
- Contact the PyGreSQL mailing list
- concerning PyGreSQL 2.0 and up.
-
- If you would like to proposes changes, please join the
- PyGreSQL mailing list and send context diffs there.
-
- See http://mailman.vex.net/mailman/listinfo/pygresql
- to join the mailing list.
-
-Please note that messages to individual developers will generally not be
-answered directly. All questions, comments and code changes must be
-submitted to the mailing list for peer review and archiving.
-
-PyGreSQL programming information
---------------------------------
-You may either choose to use the "classic" PyGreSQL interface
-provided by the `pg` module or else the newer DB-API 2.0
-compliant interface provided by the `pgdb` module.
-
-`DB-API 2.0 <http://www.python.org/dev/peps/pep-0249/>`_
-(Python Database API Specification v2.0)
-is a specification for connecting to databases (not only PostGreSQL)
-from Python that has been developed by the Python DB-SIG in 1999.
-
-The programming information is available in the files
-`pg.txt <pg.html>`_ and `pgdb.txt <pgdb.html>`_.
-
-Note that PyGreSQL is not thread-safe on the connection level. Therefore
-we recommend using `DBUtils <http://www.webwareforpython.org/DBUtils>`
-for multi-threaded environments, which supports both PyGreSQL interfaces.
-
-
-ChangeLog and Future
-====================
-The ChangeLog with past changes is in the file
-`changelog.txt <changelog.html>`_.
-
-A to do list and wish list is in the file
-`future.txt <future.html>`_.
[11/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/protocol.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/protocol.py b/tools/bin/ext/pg8000/protocol.py
deleted file mode 100644
index 377074b..0000000
--- a/tools/bin/ext/pg8000/protocol.py
+++ /dev/null
@@ -1,1340 +0,0 @@
-# vim: sw=4:expandtab:foldmethod=marker
-#
-# Copyright (c) 2007-2009, Mathieu Fenniak
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-__author__ = "Mathieu Fenniak"
-
-import socket
-import select
-import threading
-import struct
-import hashlib
-from cStringIO import StringIO
-
-from errors import *
-from util import MulticastDelegate
-import types
-
-##
-# An SSLRequest message. To initiate an SSL-encrypted connection, an
-# SSLRequest message is used rather than a {@link StartupMessage
-# StartupMessage}. A StartupMessage is still sent, but only after SSL
-# negotiation (if accepted).
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class SSLRequest(object):
- def __init__(self):
- pass
-
- # Int32(8) - Message length, including self.<br>
- # Int32(80877103) - The SSL request code.<br>
- def serialize(self):
- return struct.pack("!ii", 8, 80877103)
-
-
-##
-# A StartupMessage message. Begins a DB session, identifying the user to be
-# authenticated as and the database to connect to.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class StartupMessage(object):
- # Greenplum utility mode
- def __init__(self, user, database=None, options=None):
- self.user = user
- self.database = database
- self.options = options
-
- # Int32 - Message length, including self.
- # Int32(196608) - Protocol version number. Version 3.0.
- # Any number of key/value pairs, terminated by a zero byte:
- # String - A parameter name (user, database, or options)
- # String - Parameter value
- def serialize(self):
- protocol = 196608
- val = struct.pack("!i", protocol)
- val += "user\x00" + self.user + "\x00"
- if self.database:
- val += "database\x00" + self.database + "\x00"
- if self.options:
- val += "options\x00" + self.options + "\x00"
- val += "\x00"
- val = struct.pack("!i", len(val) + 4) + val
- return val
-
-
-##
-# Parse message. Creates a prepared statement in the DB session.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-#
-# @param ps Name of the prepared statement to create.
-# @param qs Query string.
-# @param type_oids An iterable that contains the PostgreSQL type OIDs for
-# parameters in the query string.
-class Parse(object):
- def __init__(self, ps, qs, type_oids):
- self.ps = ps
- self.qs = qs
- self.type_oids = type_oids
-
- def __repr__(self):
- return "<Parse ps=%r qs=%r>" % (self.ps, self.qs)
-
- # Byte1('P') - Identifies the message as a Parse command.
- # Int32 - Message length, including self.
- # String - Prepared statement name. An empty string selects the unnamed
- # prepared statement.
- # String - The query string.
- # Int16 - Number of parameter data types specified (can be zero).
- # For each parameter:
- # Int32 - The OID of the parameter data type.
- def serialize(self):
- val = self.ps + "\x00" + self.qs + "\x00"
- val = val + struct.pack("!h", len(self.type_oids))
- for oid in self.type_oids:
- # Parse message doesn't seem to handle the -1 type_oid for NULL
- # values that other messages handle. So we'll provide type_oid 705,
- # the PG "unknown" type.
- if oid == -1: oid = 705
- val = val + struct.pack("!i", oid)
- val = struct.pack("!i", len(val) + 4) + val
- val = "P" + val
- return val
-
-
-##
-# Bind message. Readies a prepared statement for execution.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-#
-# @param portal Name of the destination portal.
-# @param ps Name of the source prepared statement.
-# @param in_fc An iterable containing the format codes for input
-# parameters. 0 = Text, 1 = Binary.
-# @param params The parameters.
-# @param out_fc An iterable containing the format codes for output
-# parameters. 0 = Text, 1 = Binary.
-# @param kwargs Additional arguments to pass to the type conversion
-# methods.
-class Bind(object):
- def __init__(self, portal, ps, in_fc, params, out_fc, **kwargs):
- self.portal = portal
- self.ps = ps
- self.in_fc = in_fc
- self.params = []
- for i in range(len(params)):
- if len(self.in_fc) == 0:
- fc = 0
- elif len(self.in_fc) == 1:
- fc = self.in_fc[0]
- else:
- fc = self.in_fc[i]
- self.params.append(types.pg_value(params[i], fc, **kwargs))
- self.out_fc = out_fc
-
- def __repr__(self):
- return "<Bind p=%r s=%r>" % (self.portal, self.ps)
-
- # Byte1('B') - Identifies the Bind command.
- # Int32 - Message length, including self.
- # String - Name of the destination portal.
- # String - Name of the source prepared statement.
- # Int16 - Number of parameter format codes.
- # For each parameter format code:
- # Int16 - The parameter format code.
- # Int16 - Number of parameter values.
- # For each parameter value:
- # Int32 - The length of the parameter value, in bytes, not including this
- # this length. -1 indicates a NULL parameter value, in which no
- # value bytes follow.
- # Byte[n] - Value of the parameter.
- # Int16 - The number of result-column format codes.
- # For each result-column format code:
- # Int16 - The format code.
- def serialize(self):
- retval = StringIO()
- retval.write(self.portal + "\x00")
- retval.write(self.ps + "\x00")
- retval.write(struct.pack("!h", len(self.in_fc)))
- for fc in self.in_fc:
- retval.write(struct.pack("!h", fc))
- retval.write(struct.pack("!h", len(self.params)))
- for param in self.params:
- if param == None:
- # special case, NULL value
- retval.write(struct.pack("!i", -1))
- else:
- retval.write(struct.pack("!i", len(param)))
- retval.write(param)
- retval.write(struct.pack("!h", len(self.out_fc)))
- for fc in self.out_fc:
- retval.write(struct.pack("!h", fc))
- val = retval.getvalue()
- val = struct.pack("!i", len(val) + 4) + val
- val = "B" + val
- return val
-
-
-##
-# A Close message, used for closing prepared statements and portals.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-#
-# @param typ 'S' for prepared statement, 'P' for portal.
-# @param name The name of the item to close.
-class Close(object):
- def __init__(self, typ, name):
- if len(typ) != 1:
- raise InternalError("Close typ must be 1 char")
- self.typ = typ
- self.name = name
-
- # Byte1('C') - Identifies the message as a close command.
- # Int32 - Message length, including self.
- # Byte1 - 'S' for prepared statement, 'P' for portal.
- # String - The name of the item to close.
- def serialize(self):
- val = self.typ + self.name + "\x00"
- val = struct.pack("!i", len(val) + 4) + val
- val = "C" + val
- return val
-
-
-##
-# A specialized Close message for a portal.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class ClosePortal(Close):
- def __init__(self, name):
- Close.__init__(self, "P", name)
-
-
-##
-# A specialized Close message for a prepared statement.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class ClosePreparedStatement(Close):
- def __init__(self, name):
- Close.__init__(self, "S", name)
-
-
-##
-# A Describe message, used for obtaining information on prepared statements
-# and portals.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-#
-# @param typ 'S' for prepared statement, 'P' for portal.
-# @param name The name of the item to close.
-class Describe(object):
- def __init__(self, typ, name):
- if len(typ) != 1:
- raise InternalError("Describe typ must be 1 char")
- self.typ = typ
- self.name = name
-
- # Byte1('D') - Identifies the message as a describe command.
- # Int32 - Message length, including self.
- # Byte1 - 'S' for prepared statement, 'P' for portal.
- # String - The name of the item to close.
- def serialize(self):
- val = self.typ + self.name + "\x00"
- val = struct.pack("!i", len(val) + 4) + val
- val = "D" + val
- return val
-
-
-##
-# A specialized Describe message for a portal.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class DescribePortal(Describe):
- def __init__(self, name):
- Describe.__init__(self, "P", name)
-
- def __repr__(self):
- return "<DescribePortal %r>" % (self.name)
-
-
-##
-# A specialized Describe message for a prepared statement.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class DescribePreparedStatement(Describe):
- def __init__(self, name):
- Describe.__init__(self, "S", name)
-
- def __repr__(self):
- return "<DescribePreparedStatement %r>" % (self.name)
-
-
-##
-# A Flush message forces the backend to deliver any data pending in its
-# output buffers.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class Flush(object):
- # Byte1('H') - Identifies the message as a flush command.
- # Int32(4) - Length of message, including self.
- def serialize(self):
- return 'H\x00\x00\x00\x04'
-
- def __repr__(self):
- return "<Flush>"
-
-##
-# Causes the backend to close the current transaction (if not in a BEGIN/COMMIT
-# block), and issue ReadyForQuery.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class Sync(object):
- # Byte1('S') - Identifies the message as a sync command.
- # Int32(4) - Length of message, including self.
- def serialize(self):
- return 'S\x00\x00\x00\x04'
-
- def __repr__(self):
- return "<Sync>"
-
-
-##
-# Transmits a password.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class PasswordMessage(object):
- def __init__(self, pwd):
- self.pwd = pwd
-
- # Byte1('p') - Identifies the message as a password message.
- # Int32 - Message length including self.
- # String - The password. Password may be encrypted.
- def serialize(self):
- val = self.pwd + "\x00"
- val = struct.pack("!i", len(val) + 4) + val
- val = "p" + val
- return val
-
-
-##
-# Requests that the backend execute a portal and retrieve any number of rows.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-# @param row_count The number of rows to return. Can be zero to indicate the
-# backend should return all rows. If the portal represents a
-# query that does not return rows, no rows will be returned
-# no matter what the row_count.
-class Execute(object):
- def __init__(self, portal, row_count):
- self.portal = portal
- self.row_count = row_count
-
- # Byte1('E') - Identifies the message as an execute message.
- # Int32 - Message length, including self.
- # String - The name of the portal to execute.
- # Int32 - Maximum number of rows to return, if portal contains a query that
- # returns rows. 0 = no limit.
- def serialize(self):
- val = self.portal + "\x00" + struct.pack("!i", self.row_count)
- val = struct.pack("!i", len(val) + 4) + val
- val = "E" + val
- return val
-
-
-##
-# Informs the backend that the connection is being closed.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class Terminate(object):
- def __init__(self):
- pass
-
- # Byte1('X') - Identifies the message as a terminate message.
- # Int32(4) - Message length, including self.
- def serialize(self):
- return 'X\x00\x00\x00\x04'
-
-##
-# Base class of all Authentication[*] messages.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class AuthenticationRequest(object):
- def __init__(self, data):
- pass
-
- # Byte1('R') - Identifies the message as an authentication request.
- # Int32(8) - Message length, including self.
- # Int32 - An authentication code that represents different
- # authentication messages:
- # 0 = AuthenticationOk
- # 5 = MD5 pwd
- # 2 = Kerberos v5 (not supported by pg8000)
- # 3 = Cleartext pwd (not supported by pg8000)
- # 4 = crypt() pwd (not supported by pg8000)
- # 6 = SCM credential (not supported by pg8000)
- # 7 = GSSAPI (not supported by pg8000)
- # 8 = GSSAPI data (not supported by pg8000)
- # 9 = SSPI (not supported by pg8000)
- # Some authentication messages have additional data following the
- # authentication code. That data is documented in the appropriate class.
- def createFromData(data):
- ident = struct.unpack("!i", data[:4])[0]
- klass = authentication_codes.get(ident, None)
- if klass != None:
- return klass(data[4:])
- else:
- raise NotSupportedError("authentication method %r not supported" % (ident,))
- createFromData = staticmethod(createFromData)
-
- def ok(self, conn, user, **kwargs):
- raise InternalError("ok method should be overridden on AuthenticationRequest instance")
-
-##
-# A message representing that the backend accepting the provided username
-# without any challenge.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class AuthenticationOk(AuthenticationRequest):
- def ok(self, conn, user, **kwargs):
- return True
-
-
-##
-# A message representing the backend requesting an MD5 hashed password
-# response. The response will be sent as md5(md5(pwd + login) + salt).
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class AuthenticationMD5Password(AuthenticationRequest):
- # Additional message data:
- # Byte4 - Hash salt.
- def __init__(self, data):
- self.salt = "".join(struct.unpack("4c", data))
-
- def ok(self, conn, user, password=None, **kwargs):
- if password == None:
- raise InterfaceError("server requesting MD5 password authentication, but no password was provided")
- pwd = "md5" + hashlib.md5(hashlib.md5(password + user).hexdigest() + self.salt).hexdigest()
- conn._send(PasswordMessage(pwd))
- conn._flush()
-
- reader = MessageReader(conn)
- reader.add_message(AuthenticationRequest, lambda msg, reader: reader.return_value(msg.ok(conn, user)), reader)
- reader.add_message(ErrorResponse, self._ok_error)
- return reader.handle_messages()
-
- def _ok_error(self, msg):
- if msg.code == "28000":
- raise InterfaceError("md5 password authentication failed")
- else:
- raise msg.createException()
-
-authentication_codes = {
- 0: AuthenticationOk,
- 5: AuthenticationMD5Password,
-}
-
-
-##
-# ParameterStatus message sent from backend, used to inform the frotnend of
-# runtime configuration parameter changes.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class ParameterStatus(object):
- def __init__(self, key, value):
- self.key = key
- self.value = value
-
- # Byte1('S') - Identifies ParameterStatus
- # Int32 - Message length, including self.
- # String - Runtime parameter name.
- # String - Runtime parameter value.
- def createFromData(data):
- key = data[:data.find("\x00")]
- value = data[data.find("\x00")+1:-1]
- return ParameterStatus(key, value)
- createFromData = staticmethod(createFromData)
-
-
-##
-# BackendKeyData message sent from backend. Contains a connection's process
-# ID and a secret key. Can be used to terminate the connection's current
-# actions, such as a long running query. Not supported by pg8000 yet.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class BackendKeyData(object):
- def __init__(self, process_id, secret_key):
- self.process_id = process_id
- self.secret_key = secret_key
-
- # Byte1('K') - Identifier.
- # Int32(12) - Message length, including self.
- # Int32 - Process ID.
- # Int32 - Secret key.
- def createFromData(data):
- process_id, secret_key = struct.unpack("!2i", data)
- return BackendKeyData(process_id, secret_key)
- createFromData = staticmethod(createFromData)
-
-
-##
-# Message representing a query with no data.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class NoData(object):
- # Byte1('n') - Identifier.
- # Int32(4) - Message length, including self.
- def createFromData(data):
- return NoData()
- createFromData = staticmethod(createFromData)
-
-
-##
-# Message representing a successful Parse.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class ParseComplete(object):
- # Byte1('1') - Identifier.
- # Int32(4) - Message length, including self.
- def createFromData(data):
- return ParseComplete()
- createFromData = staticmethod(createFromData)
-
-
-##
-# Message representing a successful Bind.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class BindComplete(object):
- # Byte1('2') - Identifier.
- # Int32(4) - Message length, including self.
- def createFromData(data):
- return BindComplete()
- createFromData = staticmethod(createFromData)
-
-
-##
-# Message representing a successful Close.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class CloseComplete(object):
- # Byte1('3') - Identifier.
- # Int32(4) - Message length, including self.
- def createFromData(data):
- return CloseComplete()
- createFromData = staticmethod(createFromData)
-
-
-##
-# Message representing data from an Execute has been received, but more data
-# exists in the portal.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class PortalSuspended(object):
- # Byte1('s') - Identifier.
- # Int32(4) - Message length, including self.
- def createFromData(data):
- return PortalSuspended()
- createFromData = staticmethod(createFromData)
-
-
-##
-# Message representing the backend is ready to process a new query.
-# <p>
-# Stability: This is an internal class. No stability guarantee is made.
-class ReadyForQuery(object):
- def __init__(self, status):
- self._status = status
-
- ##
- # I = Idle, T = Idle in Transaction, E = idle in failed transaction.
- status = property(lambda self: self._status)
-
- def __repr__(self):
- return "<ReadyForQuery %s>" % \
- {"I": "Idle", "T": "Idle in Transaction", "E": "Idle in Failed Transaction"}[self.status]
-
- # Byte1('Z') - Identifier.
- # Int32(5) - Message length, including self.
- # Byte1 - Status indicator.
- def createFromData(data):
- return ReadyForQuery(data)
- createFromData = staticmethod(createFromData)
-
-
-##
-# Represents a notice sent from the server. This is not the same as a
-# notification. A notice is just additional information about a query, such
-# as a notice that a primary key has automatically been created for a table.
-# <p>
-# A NoticeResponse instance will have properties containing the data sent
-# from the server:
-# <ul>
-# <li>severity -- "ERROR", "FATAL', "PANIC", "WARNING", "NOTICE", "DEBUG",
-# "INFO", or "LOG". Always present.</li>
-# <li>code -- the SQLSTATE code for the error. See Appendix A of the
-# PostgreSQL documentation for specific error codes. Always present.</li>
-# <li>msg -- human-readable error message. Always present.</li>
-# <li>detail -- Optional additional information.</li>
-# <li>hint -- Optional suggestion about what to do about the issue.</li>
-# <li>position -- Optional index into the query string.</li>
-# <li>where -- Optional context.</li>
-# <li>file -- Source-code file.</li>
-# <li>line -- Source-code line.</li>
-# <li>routine -- Source-code routine.</li>
-# </ul>
-# <p>
-# Stability: Added in pg8000 v1.03. Required properties severity, code, and
-# msg are guaranteed for v1.xx. Other properties should be checked with
-# hasattr before accessing.
-class NoticeResponse(object):
- responseKeys = {
- "S": "severity", # always present
- "C": "code", # always present
- "M": "msg", # always present
- "D": "detail",
- "H": "hint",
- "P": "position",
- "p": "_position",
- "q": "_query",
- "W": "where",
- "F": "file",
- "L": "line",
- "R": "routine",
- }
-
- def __init__(self, **kwargs):
- for arg, value in kwargs.items():
- setattr(self, arg, value)
-
- def __repr__(self):
- return "<NoticeResponse %s %s %r>" % (self.severity, self.code, self.msg)
-
- def dataIntoDict(data):
- retval = {}
- for s in data.split("\x00"):
- if not s: continue
- key, value = s[0], s[1:]
- key = NoticeResponse.responseKeys.get(key, key)
- retval[key] = value
- return retval
- dataIntoDict = staticmethod(dataIntoDict)
-
- # Byte1('N') - Identifier
- # Int32 - Message length
- # Any number of these, followed by a zero byte:
- # Byte1 - code identifying the field type (see responseKeys)
- # String - field value
- def createFromData(data):
- return NoticeResponse(**NoticeResponse.dataIntoDict(data))
- createFromData = staticmethod(createFromData)
-
-
-##
-# A message sent in case of a server-side error. Contains the same properties
-# that {@link NoticeResponse NoticeResponse} contains.
-# <p>
-# Stability: Added in pg8000 v1.03. Required properties severity, code, and
-# msg are guaranteed for v1.xx. Other properties should be checked with
-# hasattr before accessing.
-class ErrorResponse(object):
- def __init__(self, **kwargs):
- for arg, value in kwargs.items():
- setattr(self, arg, value)
-
- def __repr__(self):
- return "<ErrorResponse %s %s %r>" % (self.severity, self.code, self.msg)
-
- def createException(self):
- return ProgrammingError(self.severity, self.code, self.msg)
-
- def createFromData(data):
- return ErrorResponse(**NoticeResponse.dataIntoDict(data))
- createFromData = staticmethod(createFromData)
-
-
-##
-# A message sent if this connection receives a NOTIFY that it was LISTENing for.
-# <p>
-# Stability: Added in pg8000 v1.03. When limited to accessing properties from
-# a notification event dispatch, stability is guaranteed for v1.xx.
-class NotificationResponse(object):
- def __init__(self, backend_pid, condition, additional_info):
- self._backend_pid = backend_pid
- self._condition = condition
- self._additional_info = additional_info
-
- ##
- # An integer representing the process ID of the backend that triggered
- # the NOTIFY.
- # <p>
- # Stability: Added in pg8000 v1.03, stability guaranteed for v1.xx.
- backend_pid = property(lambda self: self._backend_pid)
-
- ##
- # The name of the notification fired.
- # <p>
- # Stability: Added in pg8000 v1.03, stability guaranteed for v1.xx.
- condition = property(lambda self: self._condition)
-
- ##
- # Currently unspecified by the PostgreSQL documentation as of v8.3.1.
- # <p>
- # Stability: Added in pg8000 v1.03, stability guaranteed for v1.xx.
- additional_info = property(lambda self: self._additional_info)
-
- def __repr__(self):
- return "<NotificationResponse %s %s %r>" % (self.backend_pid, self.condition, self.additional_info)
-
- def createFromData(data):
- backend_pid = struct.unpack("!i", data[:4])[0]
- data = data[4:]
- null = data.find("\x00")
- condition = data[:null]
- data = data[null+1:]
- null = data.find("\x00")
- additional_info = data[:null]
- return NotificationResponse(backend_pid, condition, additional_info)
- createFromData = staticmethod(createFromData)
-
-
-class ParameterDescription(object):
- def __init__(self, type_oids):
- self.type_oids = type_oids
- def createFromData(data):
- count = struct.unpack("!h", data[:2])[0]
- type_oids = struct.unpack("!" + "i"*count, data[2:])
- return ParameterDescription(type_oids)
- createFromData = staticmethod(createFromData)
-
-
-class RowDescription(object):
- def __init__(self, fields):
- self.fields = fields
-
- def createFromData(data):
- count = struct.unpack("!h", data[:2])[0]
- data = data[2:]
- fields = []
- for i in range(count):
- null = data.find("\x00")
- field = {"name": data[:null]}
- data = data[null+1:]
- field["table_oid"], field["column_attrnum"], field["type_oid"], field["type_size"], field["type_modifier"], field["format"] = struct.unpack("!ihihih", data[:18])
- data = data[18:]
- fields.append(field)
- return RowDescription(fields)
- createFromData = staticmethod(createFromData)
-
-class CommandComplete(object):
- def __init__(self, command, rows=None, oid=None):
- self.command = command
- self.rows = rows
- self.oid = oid
-
- def createFromData(data):
- values = data[:-1].split(" ")
- args = {}
- args['command'] = values[0]
- if args['command'] in ("INSERT", "DELETE", "UPDATE", "MOVE", "FETCH", "COPY"):
- args['rows'] = int(values[-1])
- if args['command'] == "INSERT":
- args['oid'] = int(values[1])
- else:
- args['command'] = data[:-1]
- return CommandComplete(**args)
- createFromData = staticmethod(createFromData)
-
-
-class DataRow(object):
- def __init__(self, fields):
- self.fields = fields
-
- def createFromData(data):
- count = struct.unpack("!h", data[:2])[0]
- data = data[2:]
- fields = []
- for i in range(count):
- val_len = struct.unpack("!i", data[:4])[0]
- data = data[4:]
- if val_len == -1:
- fields.append(None)
- else:
- fields.append(data[:val_len])
- data = data[val_len:]
- return DataRow(fields)
- createFromData = staticmethod(createFromData)
-
-
-class CopyData(object):
- # "d": CopyData,
- def __init__(self, data):
- self.data = data
-
- def createFromData(data):
- return CopyData(data)
- createFromData = staticmethod(createFromData)
-
- def serialize(self):
- return 'd' + struct.pack('!i', len(self.data) + 4) + self.data
-
-
-class CopyDone(object):
- # Byte1('c') - Identifier.
- # Int32(4) - Message length, including self.
-
- def createFromData(data):
- return CopyDone()
-
- createFromData = staticmethod(createFromData)
-
- def serialize(self):
- return 'c\x00\x00\x00\x04'
-
-class CopyOutResponse(object):
- # Byte1('H')
- # Int32(4) - Length of message contents in bytes, including self.
- # Int8(1) - 0 textual, 1 binary
- # Int16(2) - Number of columns
- # Int16(N) - Format codes for each column (0 text, 1 binary)
-
- def __init__(self, is_binary, column_formats):
- self.is_binary = is_binary
- self.column_formats = column_formats
-
- def createFromData(data):
- is_binary, num_cols = struct.unpack('!bh', data[:3])
- column_formats = struct.unpack('!' + ('h' * num_cols), data[3:])
- return CopyOutResponse(is_binary, column_formats)
-
- createFromData = staticmethod(createFromData)
-
-
-class CopyInResponse(object):
- # Byte1('G')
- # Otherwise the same as CopyOutResponse
-
- def __init__(self, is_binary, column_formats):
- self.is_binary = is_binary
- self.column_formats = column_formats
-
- def createFromData(data):
- is_binary, num_cols = struct.unpack('!bh', data[:3])
- column_formats = struct.unpack('!' + ('h' * num_cols), data[3:])
- return CopyInResponse(is_binary, column_formats)
-
- createFromData = staticmethod(createFromData)
-
-class SSLWrapper(object):
- def __init__(self, sslobj):
- self.sslobj = sslobj
- def send(self, data):
- self.sslobj.write(data)
- def recv(self, num):
- return self.sslobj.read(num)
-
-
-class MessageReader(object):
- def __init__(self, connection):
- self._conn = connection
- self._msgs = []
-
- # If true, raise exception from an ErrorResponse after messages are
- # processed. This can be used to leave the connection in a usable
- # state after an error response, rather than having unconsumed
- # messages that won't be understood in another context.
- self.delay_raising_exception = False
-
- self.ignore_unhandled_messages = False
-
- def add_message(self, msg_class, handler, *args, **kwargs):
- self._msgs.append((msg_class, handler, args, kwargs))
-
- def clear_messages(self):
- self._msgs = []
-
- def return_value(self, value):
- self._retval = value
-
- def handle_messages(self):
- exc = None
- while 1:
- msg = self._conn._read_message()
- msg_handled = False
- for (msg_class, handler, args, kwargs) in self._msgs:
- if isinstance(msg, msg_class):
- msg_handled = True
- retval = handler(msg, *args, **kwargs)
- if retval:
- # The handler returned a true value, meaning that the
- # message loop should be aborted.
- if exc != None:
- raise exc
- return retval
- elif hasattr(self, "_retval"):
- # The handler told us to return -- used for non-true
- # return values
- if exc != None:
- raise exc
- return self._retval
- if msg_handled:
- continue
- elif isinstance(msg, ErrorResponse):
- exc = msg.createException()
- if not self.delay_raising_exception:
- raise exc
- elif isinstance(msg, NoticeResponse):
- self._conn.handleNoticeResponse(msg)
- elif isinstance(msg, ParameterStatus):
- self._conn.handleParameterStatus(msg)
- elif isinstance(msg, NotificationResponse):
- self._conn.handleNotificationResponse(msg)
- elif not self.ignore_unhandled_messages:
- raise InternalError("Unexpected response msg %r" % (msg))
-
-def sync_on_error(fn):
- def _fn(self, *args, **kwargs):
- try:
- self._sock_lock.acquire()
- return fn(self, *args, **kwargs)
- except:
- self._sync()
- raise
- finally:
- self._sock_lock.release()
- return _fn
-
-class Connection(object):
- def __init__(self, unix_sock=None, host=None, port=5432, socket_timeout=60, ssl=False, records=False):
- self._client_encoding = "ascii"
- self._integer_datetimes = False
- self._record_field_names = {}
- self._sock_buf = ""
- self._sock_buf_pos = 0
- self._send_sock_buf = []
- self._block_size = 8192
- self.user_wants_records = records
- if unix_sock == None and host != None:
- self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- elif unix_sock != None:
- if not hasattr(socket, "AF_UNIX"):
- raise InterfaceError("attempt to connect to unix socket on unsupported platform")
- self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- else:
- raise ProgrammingError("one of host or unix_sock must be provided")
- if unix_sock == None and host != None:
- self._sock.connect((host, port))
- elif unix_sock != None:
- self._sock.connect(unix_sock)
- if ssl:
- self._send(SSLRequest())
- self._flush()
- resp = self._sock.recv(1)
- if resp == 'S':
- self._sock = SSLWrapper(socket.ssl(self._sock))
- else:
- raise InterfaceError("server refuses SSL")
- else:
- # settimeout causes ssl failure, on windows. Python bug 1462352.
- self._sock.settimeout(socket_timeout)
- self._state = "noauth"
- self._backend_key_data = None
- self._sock_lock = threading.Lock()
-
- self.NoticeReceived = MulticastDelegate()
- self.ParameterStatusReceived = MulticastDelegate()
- self.NotificationReceived = MulticastDelegate()
-
- self.ParameterStatusReceived += self._onParameterStatusReceived
-
- def verifyState(self, state):
- if self._state != state:
- raise InternalError("connection state must be %s, is %s" % (state, self._state))
-
- def _send(self, msg):
- assert self._sock_lock.locked()
- #print "_send(%r)" % msg
- data = msg.serialize()
- self._send_sock_buf.append(data)
-
- def _flush(self):
- assert self._sock_lock.locked()
- self._sock.sendall("".join(self._send_sock_buf))
- del self._send_sock_buf[:]
-
- def _read_bytes(self, byte_count):
- retval = []
- bytes_read = 0
- while bytes_read < byte_count:
- if self._sock_buf_pos == len(self._sock_buf):
- self._sock_buf = self._sock.recv(1024)
- self._sock_buf_pos = 0
- rpos = min(len(self._sock_buf), self._sock_buf_pos + (byte_count - bytes_read))
- addt_data = self._sock_buf[self._sock_buf_pos:rpos]
- bytes_read += (rpos - self._sock_buf_pos)
- assert bytes_read <= byte_count
- self._sock_buf_pos = rpos
- retval.append(addt_data)
- return "".join(retval)
-
- def _read_message(self):
- assert self._sock_lock.locked()
- bytes = self._read_bytes(5)
- message_code = bytes[0]
- data_len = struct.unpack("!i", bytes[1:])[0] - 4
- bytes = self._read_bytes(data_len)
- assert len(bytes) == data_len
- msg = message_types[message_code].createFromData(bytes)
- #print "_read_message() -> %r" % msg
- return msg
-
- def authenticate(self, user, **kwargs):
- self.verifyState("noauth")
- self._sock_lock.acquire()
- try:
- self._send(StartupMessage(user, database=kwargs.get("database",None), options=kwargs.get("options", None)))
- self._flush()
- msg = self._read_message()
- if isinstance(msg, ErrorResponse):
- raise msg.createException()
- if not isinstance(msg, AuthenticationRequest):
- raise InternalError("StartupMessage was responded to with non-AuthenticationRequest msg %r" % msg)
- if not msg.ok(self, user, **kwargs):
- raise InterfaceError("authentication method %s failed" % msg.__class__.__name__)
-
- self._state = "auth"
-
- reader = MessageReader(self)
- reader.add_message(ReadyForQuery, self._ready_for_query)
- reader.add_message(BackendKeyData, self._receive_backend_key_data)
- reader.handle_messages()
- finally:
- self._sock_lock.release()
-
- self._cache_record_attnames()
-
- def _ready_for_query(self, msg):
- self._state = "ready"
- return True
-
- def _receive_backend_key_data(self, msg):
- self._backend_key_data = msg
-
- def _cache_record_attnames(self):
- if not self.user_wants_records:
- return
-
- parse_retval = self.parse("",
- """SELECT
- pg_type.oid, attname
- FROM
- pg_type
- INNER JOIN pg_attribute ON (attrelid = pg_type.typrelid)
- WHERE typreceive = 'record_recv'::regproc
- ORDER BY pg_type.oid, attnum""",
- [])
- row_desc, cmd = self.bind("tmp", "", (), parse_retval, None)
- eod, rows = self.fetch_rows("tmp", 0, row_desc)
-
- self._record_field_names = {}
- typoid, attnames = None, []
- for row in rows:
- new_typoid, attname = row
- if new_typoid != typoid and typoid != None:
- self._record_field_names[typoid] = attnames
- attnames = []
- typoid = new_typoid
- attnames.append(attname)
- self._record_field_names[typoid] = attnames
-
- @sync_on_error
- def parse(self, statement, qs, param_types):
- self.verifyState("ready")
-
- type_info = [types.pg_type_info(x) for x in param_types]
- param_types, param_fc = [x[0] for x in type_info], [x[1] for x in type_info] # zip(*type_info) -- fails on empty arr
- self._send(Parse(statement, qs, param_types))
- self._send(DescribePreparedStatement(statement))
- self._send(Flush())
- self._flush()
-
- reader = MessageReader(self)
-
- # ParseComplete is good.
- reader.add_message(ParseComplete, lambda msg: 0)
-
- # Well, we don't really care -- we're going to send whatever we
- # want and let the database deal with it. But thanks anyways!
- reader.add_message(ParameterDescription, lambda msg: 0)
-
- # We're not waiting for a row description. Return something
- # destinctive to let bind know that there is no output.
- reader.add_message(NoData, lambda msg: (None, param_fc))
-
- # Common row description response
- reader.add_message(RowDescription, lambda msg: (msg, param_fc))
-
- return reader.handle_messages()
-
- @sync_on_error
- def bind(self, portal, statement, params, parse_data, copy_stream):
- self.verifyState("ready")
-
- row_desc, param_fc = parse_data
- if row_desc == None:
- # no data coming out
- output_fc = ()
- else:
- # We've got row_desc that allows us to identify what we're going to
- # get back from this statement.
- output_fc = [types.py_type_info(f, self._record_field_names) for f in row_desc.fields]
- self._send(Bind(portal, statement, param_fc, params, output_fc, client_encoding = self._client_encoding, integer_datetimes = self._integer_datetimes))
- # We need to describe the portal after bind, since the return
- # format codes will be different (hopefully, always what we
- # requested).
- self._send(DescribePortal(portal))
- self._send(Flush())
- self._flush()
-
- # Read responses from server...
- reader = MessageReader(self)
-
- # BindComplete is good -- just ignore
- reader.add_message(BindComplete, lambda msg: 0)
-
- # NoData in this case means we're not executing a query. As a
- # result, we won't be fetching rows, so we'll never execute the
- # portal we just created... unless we execute it right away, which
- # we'll do.
- reader.add_message(NoData, self._bind_nodata, portal, reader, copy_stream)
-
- # Return the new row desc, since it will have the format types we
- # asked the server for
- reader.add_message(RowDescription, lambda msg: (msg, None))
-
- return reader.handle_messages()
-
- def _copy_in_response(self, copyin, fileobj, old_reader):
- if fileobj == None:
- raise CopyQueryWithoutStreamError()
- while True:
- data = fileobj.read(self._block_size)
- if not data:
- break
- self._send(CopyData(data))
- self._flush()
- self._send(CopyDone())
- self._send(Sync())
- self._flush()
-
- def _copy_out_response(self, copyout, fileobj, old_reader):
- if fileobj == None:
- raise CopyQueryWithoutStreamError()
- reader = MessageReader(self)
- reader.add_message(CopyData, self._copy_data, fileobj)
- reader.add_message(CopyDone, lambda msg: 1)
- reader.handle_messages()
-
- def _copy_data(self, copydata, fileobj):
- fileobj.write(copydata.data)
-
- def _bind_nodata(self, msg, portal, old_reader, copy_stream):
- # Bind message returned NoData, causing us to execute the command.
- self._send(Execute(portal, 0))
- self._send(Sync())
- self._flush()
-
- output = {}
- reader = MessageReader(self)
- reader.add_message(CopyOutResponse, self._copy_out_response, copy_stream, reader)
- reader.add_message(CopyInResponse, self._copy_in_response, copy_stream, reader)
- reader.add_message(CommandComplete, lambda msg, out: out.setdefault('msg', msg) and False, output)
- reader.add_message(ReadyForQuery, lambda msg: 1)
- reader.delay_raising_exception = True
- reader.handle_messages()
-
- old_reader.return_value((None, output['msg']))
-
- @sync_on_error
- def fetch_rows(self, portal, row_count, row_desc):
- self.verifyState("ready")
-
- self._send(Execute(portal, row_count))
- self._send(Flush())
- self._flush()
- rows = []
-
- reader = MessageReader(self)
- reader.add_message(DataRow, self._fetch_datarow, rows, row_desc)
- reader.add_message(PortalSuspended, lambda msg: 1)
- reader.add_message(CommandComplete, self._fetch_commandcomplete, portal)
- retval = reader.handle_messages()
-
- # retval = 2 when command complete, indicating that we've hit the
- # end of the available data for this command
- return (retval == 2), rows
-
- def _fetch_datarow(self, msg, rows, row_desc):
- rows.append(
- [
- types.py_value(
- msg.fields[i],
- row_desc.fields[i],
- client_encoding=self._client_encoding,
- integer_datetimes=self._integer_datetimes,
- record_field_names=self._record_field_names
- )
- for i in range(len(msg.fields))
- ]
- )
-
- def _fetch_commandcomplete(self, msg, portal):
- self._send(ClosePortal(portal))
- self._send(Sync())
- self._flush()
-
- reader = MessageReader(self)
- reader.add_message(ReadyForQuery, self._fetch_commandcomplete_rfq)
- reader.add_message(CloseComplete, lambda msg: False)
- reader.handle_messages()
-
- return 2 # signal end-of-data
-
- def _fetch_commandcomplete_rfq(self, msg):
- self._state = "ready"
- return True
-
- # Send a Sync message, then read and discard all messages until we
- # receive a ReadyForQuery message.
- def _sync(self):
- # it is assumed _sync is called from sync_on_error, which holds
- # a _sock_lock throughout the call
- self._send(Sync())
- self._flush()
- reader = MessageReader(self)
- reader.ignore_unhandled_messages = True
- reader.add_message(ReadyForQuery, lambda msg: True)
- reader.handle_messages()
-
- def close_statement(self, statement):
- if self._state == "closed":
- return
- self.verifyState("ready")
- self._sock_lock.acquire()
- try:
- self._send(ClosePreparedStatement(statement))
- self._send(Sync())
- self._flush()
-
- reader = MessageReader(self)
- reader.add_message(CloseComplete, lambda msg: 0)
- reader.add_message(ReadyForQuery, lambda msg: 1)
- reader.handle_messages()
- finally:
- self._sock_lock.release()
-
- def close_portal(self, portal):
- if self._state == "closed":
- return
- self.verifyState("ready")
- self._sock_lock.acquire()
- try:
- self._send(ClosePortal(portal))
- self._send(Sync())
- self._flush()
-
- reader = MessageReader(self)
- reader.add_message(CloseComplete, lambda msg: 0)
- reader.add_message(ReadyForQuery, lambda msg: 1)
- reader.handle_messages()
- finally:
- self._sock_lock.release()
-
- def close(self):
- self._sock_lock.acquire()
- try:
- self._send(Terminate())
- self._flush()
- self._sock.close()
- self._state = "closed"
- finally:
- self._sock_lock.release()
-
- def _onParameterStatusReceived(self, msg):
- if msg.key == "client_encoding":
- self._client_encoding = msg.value
- elif msg.key == "integer_datetimes":
- self._integer_datetimes = (msg.value == "on")
-
- def handleNoticeResponse(self, msg):
- self.NoticeReceived(msg)
-
- def handleParameterStatus(self, msg):
- self.ParameterStatusReceived(msg)
-
- def handleNotificationResponse(self, msg):
- self.NotificationReceived(msg)
-
- def fileno(self):
- # This should be safe to do without a lock
- return self._sock.fileno()
-
- def isready(self):
- self._sock_lock.acquire()
- try:
- rlst, _wlst, _xlst = select.select([self], [], [], 0)
- if not rlst:
- return False
-
- self._sync()
- return True
- finally:
- self._sock_lock.release()
-
-message_types = {
- "N": NoticeResponse,
- "R": AuthenticationRequest,
- "S": ParameterStatus,
- "K": BackendKeyData,
- "Z": ReadyForQuery,
- "T": RowDescription,
- "E": ErrorResponse,
- "D": DataRow,
- "C": CommandComplete,
- "1": ParseComplete,
- "2": BindComplete,
- "3": CloseComplete,
- "s": PortalSuspended,
- "n": NoData,
- "t": ParameterDescription,
- "A": NotificationResponse,
- "c": CopyDone,
- "d": CopyData,
- "G": CopyInResponse,
- "H": CopyOutResponse,
- }
-
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/types.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/types.py b/tools/bin/ext/pg8000/types.py
deleted file mode 100644
index c622a7d..0000000
--- a/tools/bin/ext/pg8000/types.py
+++ /dev/null
@@ -1,687 +0,0 @@
-# vim: sw=4:expandtab:foldmethod=marker
-#
-# Copyright (c) 2007-2009, Mathieu Fenniak
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-__author__ = "Mathieu Fenniak"
-
-import datetime
-import decimal
-import struct
-import math
-from errors import (NotSupportedError, ArrayDataParseError, InternalError,
- ArrayContentEmptyError, ArrayContentNotHomogenousError,
- ArrayContentNotSupportedError, ArrayDimensionsNotConsistentError)
-
-try:
- from pytz import utc
-except ImportError:
- ZERO = datetime.timedelta(0)
- class UTC(datetime.tzinfo):
- def utcoffset(self, dt):
- return ZERO
- def tzname(self, dt):
- return "UTC"
- def dst(self, dt):
- return ZERO
- utc = UTC()
-
-class Bytea(str):
- pass
-
-class Interval(object):
- def __init__(self, microseconds=0, days=0, months=0):
- self.microseconds = microseconds
- self.days = days
- self.months = months
-
- def _setMicroseconds(self, value):
- if not isinstance(value, int) and not isinstance(value, long):
- raise TypeError("microseconds must be an int or long")
- elif not (min_int8 < value < max_int8):
- raise OverflowError("microseconds must be representable as a 64-bit integer")
- else:
- self._microseconds = value
-
- def _setDays(self, value):
- if not isinstance(value, int) and not isinstance(value, long):
- raise TypeError("days must be an int or long")
- elif not (min_int4 < value < max_int4):
- raise OverflowError("days must be representable as a 32-bit integer")
- else:
- self._days = value
-
- def _setMonths(self, value):
- if not isinstance(value, int) and not isinstance(value, long):
- raise TypeError("months must be an int or long")
- elif not (min_int4 < value < max_int4):
- raise OverflowError("months must be representable as a 32-bit integer")
- else:
- self._months = value
-
- microseconds = property(lambda self: self._microseconds, _setMicroseconds)
- days = property(lambda self: self._days, _setDays)
- months = property(lambda self: self._months, _setMonths)
-
- def __repr__(self):
- return "<Interval %s months %s days %s microseconds>" % (self.months, self.days, self.microseconds)
-
- def __cmp__(self, other):
- if other == None: return -1
- c = cmp(self.months, other.months)
- if c != 0: return c
- c = cmp(self.days, other.days)
- if c != 0: return c
- return cmp(self.microseconds, other.microseconds)
-
-def pg_type_info(typ):
- value = None
- if isinstance(typ, dict):
- value = typ["value"]
- typ = typ["type"]
-
- data = py_types.get(typ)
- if data == None:
- raise NotSupportedError("type %r not mapped to pg type" % typ)
-
- # permit the type data to be determined by the value, if provided
- inspect_func = data.get("inspect")
- if value != None and inspect_func != None:
- data = inspect_func(value)
-
- type_oid = data.get("typeoid")
- if type_oid == None:
- raise InternalError("type %r has no type_oid" % typ)
- elif type_oid == -1:
- # special case: NULL values
- return type_oid, 0
-
- # prefer bin, but go with whatever exists
- if data.get("bin_out"):
- format = 1
- elif data.get("txt_out"):
- format = 0
- else:
- raise InternalError("no conversion fuction for type %r" % typ)
-
- return type_oid, format
-
-def pg_value(value, fc, **kwargs):
- typ = type(value)
- data = py_types.get(typ)
- if data == None:
- raise NotSupportedError("type %r not mapped to pg type" % typ)
-
- # permit the type conversion to be determined by the value, if provided
- inspect_func = data.get("inspect")
- if value != None and inspect_func != None:
- data = inspect_func(value)
-
- # special case: NULL values
- if data.get("typeoid") == -1:
- return None
-
- if fc == 0:
- func = data.get("txt_out")
- elif fc == 1:
- func = data.get("bin_out")
- else:
- raise InternalError("unrecognized format code %r" % fc)
- if func == None:
- raise NotSupportedError("type %r, format code %r not supported" % (typ, fc))
- return func(value, **kwargs)
-
-def py_type_info(description, record_field_names):
- type_oid = description['type_oid']
- data = pg_types.get(type_oid)
- if data == None:
- record_data = record_field_names.get(type_oid)
- if record_data != None:
- # records are in bin format
- return 1
- raise NotSupportedError("type oid %r not mapped to py type" % type_oid)
- # prefer bin, but go with whatever exists
- if data.get("bin_in"):
- format = 1
- elif data.get("txt_in"):
- format = 0
- else:
- raise InternalError("no conversion fuction for type oid %r" % type_oid)
- return format
-
-def py_value(v, description, record_field_names, **kwargs):
- if v == None:
- # special case - NULL value
- return None
- type_oid = description['type_oid']
- format = description['format']
- data = pg_types.get(type_oid)
- if data == None:
- record_data = record_field_names.get(type_oid)
- if record_data != None:
- data = {"bin_in": record_recv(record_data)}
- if data == None:
- raise NotSupportedError("type oid %r not supported" % type_oid)
- if format == 0:
- func = data.get("txt_in")
- elif format == 1:
- func = data.get("bin_in")
- else:
- raise NotSupportedError("format code %r not supported" % format)
- if func == None:
- raise NotSupportedError("data response format %r, type %r not supported" % (format, type_oid))
- return func(v, **kwargs)
-
-def voidrecv(data, **kwargs):
- return None
-
-def voidsend(v, **kwargs):
- return None
-
-def boolrecv(data, **kwargs):
- return data == "\x01"
-
-def boolsend(v, **kwargs):
- if v:
- return "\x01"
- else:
- return "\x00"
-
-min_int2, max_int2 = -2 ** 15, 2 ** 15
-min_int4, max_int4 = -2 ** 31, 2 ** 31
-min_int8, max_int8 = -2 ** 63, 2 ** 63
-
-def int_inspect(value):
- if min_int2 < value < max_int2:
- return {"typeoid": 21, "bin_out": int2send}
- elif min_int4 < value < max_int4:
- return {"typeoid": 23, "bin_out": int4send}
- elif min_int8 < value < max_int8:
- return {"typeoid": 20, "bin_out": int8send}
- else:
- return {"typeoid": 1700, "bin_out": numeric_send}
-
-def int2recv(data, **kwargs):
- return struct.unpack("!h", data)[0]
-
-def int2send(v, **kwargs):
- return struct.pack("!h", v)
-
-def int4recv(data, **kwargs):
- return struct.unpack("!i", data)[0]
-
-def int4send(v, **kwargs):
- return struct.pack("!i", v)
-
-def int8recv(data, **kwargs):
- return struct.unpack("!q", data)[0]
-
-def int8send(v, **kwargs):
- return struct.pack("!q", v)
-
-def float4recv(data, **kwargs):
- return struct.unpack("!f", data)[0]
-
-def float8recv(data, **kwargs):
- return struct.unpack("!d", data)[0]
-
-def float8send(v, **kwargs):
- return struct.pack("!d", v)
-
-def datetime_inspect(value):
- if value.tzinfo != None:
- # send as timestamptz if timezone is provided
- return {"typeoid": 1184, "bin_out": timestamptz_send}
- else:
- # otherwise send as timestamp
- return {"typeoid": 1114, "bin_out": timestamp_send}
-
-def timestamp_recv(data, integer_datetimes, **kwargs):
- if integer_datetimes:
- # data is 64-bit integer representing milliseconds since 2000-01-01
- val = struct.unpack("!q", data)[0]
- return datetime.datetime(2000, 1, 1) + datetime.timedelta(microseconds = val)
- else:
- # data is double-precision float representing seconds since 2000-01-01
- val = struct.unpack("!d", data)[0]
- return datetime.datetime(2000, 1, 1) + datetime.timedelta(seconds = val)
-
-# return a timezone-aware datetime instance if we're reading from a
-# "timestamp with timezone" type. The timezone returned will always be UTC,
-# but providing that additional information can permit conversion to local.
-def timestamptz_recv(data, **kwargs):
- return timestamp_recv(data, **kwargs).replace(tzinfo=utc)
-
-def timestamp_send(v, integer_datetimes, **kwargs):
- delta = v - datetime.datetime(2000, 1, 1)
- val = delta.microseconds + (delta.seconds * 1000000) + (delta.days * 86400000000)
- if integer_datetimes:
- # data is 64-bit integer representing milliseconds since 2000-01-01
- return struct.pack("!q", val)
- else:
- # data is double-precision float representing seconds since 2000-01-01
- return struct.pack("!d", val / 1000.0 / 1000.0)
-
-def timestamptz_send(v, **kwargs):
- # timestamps should be sent as UTC. If they have zone info,
- # convert them.
- return timestamp_send(v.astimezone(utc).replace(tzinfo=None), **kwargs)
-
-def date_in(data, **kwargs):
- year = int(data[0:4])
- month = int(data[5:7])
- day = int(data[8:10])
- return datetime.date(year, month, day)
-
-def date_out(v, **kwargs):
- return v.isoformat()
-
-def time_in(data, **kwargs):
- hour = int(data[0:2])
- minute = int(data[3:5])
- sec = decimal.Decimal(data[6:])
- return datetime.time(hour, minute, int(sec), int((sec - int(sec)) * 1000000))
-
-def time_out(v, **kwargs):
- return v.isoformat()
-
-def numeric_in(data, **kwargs):
- if data.find(".") == -1:
- return int(data)
- else:
- return decimal.Decimal(data)
-
-def numeric_recv(data, **kwargs):
- num_digits, weight, sign, scale = struct.unpack("!hhhh", data[:8])
- data = data[8:]
- digits = struct.unpack("!" + ("h" * num_digits), data)
- weight = decimal.Decimal(weight)
- retval = 0
- for d in digits:
- d = decimal.Decimal(d)
- retval += d * (10000 ** weight)
- weight -= 1
- if sign:
- retval *= -1
- return retval
-
-def numeric_send(v, **kwargs):
- sign = 0
- if v < 0:
- sign = 16384
- v *= -1
- max_weight = decimal.Decimal(int(math.floor(math.log(v) / math.log(10000))))
- weight = max_weight
- digits = []
- while v != 0:
- digit = int(math.floor(v / (10000 ** weight)))
- v = v - (digit * (10000 ** weight))
- weight -= 1
- digits.append(digit)
- retval = struct.pack("!hhhh", len(digits), max_weight, sign, 0)
- retval += struct.pack("!" + ("h" * len(digits)), *digits)
- return retval
-
-def numeric_out(v, **kwargs):
- return str(v)
-
-# PostgreSQL encodings:
-# http://www.postgresql.org/docs/8.3/interactive/multibyte.html
-# Python encodings:
-# http://www.python.org/doc/2.4/lib/standard-encodings.html
-#
-# Commented out encodings don't require a name change between PostgreSQL and
-# Python. If the py side is None, then the encoding isn't supported.
-pg_to_py_encodings = {
- # Not supported:
- "mule_internal": None,
- "euc_tw": None,
-
- # Name fine as-is:
- #"euc_jp",
- #"euc_jis_2004",
- #"euc_kr",
- #"gb18030",
- #"gbk",
- #"johab",
- #"sjis",
- #"shift_jis_2004",
- #"uhc",
- #"utf8",
-
- # Different name:
- "euc_cn": "gb2312",
- "iso_8859_5": "is8859_5",
- "iso_8859_6": "is8859_6",
- "iso_8859_7": "is8859_7",
- "iso_8859_8": "is8859_8",
- "koi8": "koi8_r",
- "latin1": "iso8859-1",
- "latin2": "iso8859_2",
- "latin3": "iso8859_3",
- "latin4": "iso8859_4",
- "latin5": "iso8859_9",
- "latin6": "iso8859_10",
- "latin7": "iso8859_13",
- "latin8": "iso8859_14",
- "latin9": "iso8859_15",
- "sql_ascii": "ascii",
- "win866": "cp886",
- "win874": "cp874",
- "win1250": "cp1250",
- "win1251": "cp1251",
- "win1252": "cp1252",
- "win1253": "cp1253",
- "win1254": "cp1254",
- "win1255": "cp1255",
- "win1256": "cp1256",
- "win1257": "cp1257",
- "win1258": "cp1258",
-}
-
-def encoding_convert(encoding):
- return pg_to_py_encodings.get(encoding.lower(), encoding)
-
-def varcharin(data, client_encoding, **kwargs):
- return unicode(data, encoding_convert(client_encoding))
-
-def textout(v, client_encoding, **kwargs):
- return v.encode(encoding_convert(client_encoding))
-
-def byteasend(v, **kwargs):
- return str(v)
-
-def bytearecv(data, **kwargs):
- return Bytea(data)
-
-# interval support does not provide a Python-usable interval object yet
-def interval_recv(data, integer_datetimes, **kwargs):
- if integer_datetimes:
- microseconds, days, months = struct.unpack("!qii", data)
- else:
- seconds, days, months = struct.unpack("!dii", data)
- microseconds = int(seconds * 1000 * 1000)
- return Interval(microseconds, days, months)
-
-def interval_send(data, integer_datetimes, **kwargs):
- if integer_datetimes:
- return struct.pack("!qii", data.microseconds, data.days, data.months)
- else:
- return struct.pack("!dii", data.microseconds / 1000.0 / 1000.0, data.days, data.months)
-
-def array_recv(data, **kwargs):
- dim, hasnull, typeoid = struct.unpack("!iii", data[:12])
- data = data[12:]
-
- # get type conversion method for typeoid
- conversion = pg_types[typeoid]["bin_in"]
-
- # Read dimension info
- dim_lengths = []
- element_count = 1
- for idim in range(dim):
- dim_len, dim_lbound = struct.unpack("!ii", data[:8])
- data = data[8:]
- dim_lengths.append(dim_len)
- element_count *= dim_len
-
- # Read all array values
- array_values = []
- for i in range(element_count):
- element_len, = struct.unpack("!i", data[:4])
- data = data[4:]
- if element_len == -1:
- array_values.append(None)
- else:
- array_values.append(conversion(data[:element_len], **kwargs))
- data = data[element_len:]
- if data != "":
- raise ArrayDataParseError("unexpected data left over after array read")
-
- # at this point, {{1,2,3},{4,5,6}}::int[][] looks like [1,2,3,4,5,6].
- # go through the dimensions and fix up the array contents to match
- # expected dimensions
- for dim_length in reversed(dim_lengths[1:]):
- val = []
- while array_values:
- val.append(array_values[:dim_length])
- array_values = array_values[dim_length:]
- array_values = val
-
- return array_values
-
-def array_inspect(value):
- # Check if array has any values. If not, we can't determine the proper
- # array typeoid.
- first_element = array_find_first_element(value)
- if first_element == None:
- raise ArrayContentEmptyError("array has no values")
-
- # supported array output
- typ = type(first_element)
- if issubclass(typ, int) or issubclass(typ, long):
- # special int array support -- send as smallest possible array type
- special_int_support = True
- int2_ok, int4_ok, int8_ok = True, True, True
- for v in array_flatten(value):
- if v == None:
- continue
- if min_int2 < v < max_int2:
- continue
- int2_ok = False
- if min_int4 < v < max_int4:
- continue
- int4_ok = False
- if min_int8 < v < max_int8:
- continue
- int8_ok = False
- if int2_ok:
- array_typeoid = 1005 # INT2[]
- elif int4_ok:
- array_typeoid = 1007 # INT4[]
- elif int8_ok:
- array_typeoid = 1016 # INT8[]
- else:
- raise ArrayContentNotSupportedError("numeric not supported as array contents")
- else:
- special_int_support = False
- array_typeoid = py_array_types.get(typ)
- if array_typeoid == None:
- raise ArrayContentNotSupportedError("type %r not supported as array contents" % typ)
-
- # check for homogenous array
- for v in array_flatten(value):
- if v != None and not (isinstance(v, typ) or (typ == long and isinstance(v, int)) or (typ == int and isinstance(v, long))):
- raise ArrayContentNotHomogenousError("not all array elements are of type %r" % typ)
-
- # check that all array dimensions are consistent
- array_check_dimensions(value)
-
- type_data = py_types[typ]
- if special_int_support:
- if array_typeoid == 1005:
- type_data = {"typeoid": 21, "bin_out": int2send}
- elif array_typeoid == 1007:
- type_data = {"typeoid": 23, "bin_out": int4send}
- elif array_typeoid == 1016:
- type_data = {"typeoid": 20, "bin_out": int8send}
- else:
- type_data = py_types[typ]
- return {
- "typeoid": array_typeoid,
- "bin_out": array_send(type_data["typeoid"], type_data["bin_out"])
- }
-
-def array_find_first_element(arr):
- for v in array_flatten(arr):
- if v != None:
- return v
- return None
-
-def array_flatten(arr):
- for v in arr:
- if isinstance(v, list):
- for v2 in array_flatten(v):
- yield v2
- else:
- yield v
-
-def array_check_dimensions(arr):
- v0 = arr[0]
- if isinstance(v0, list):
- req_len = len(v0)
- req_inner_lengths = array_check_dimensions(v0)
- for v in arr:
- inner_lengths = array_check_dimensions(v)
- if len(v) != req_len or inner_lengths != req_inner_lengths:
- raise ArrayDimensionsNotConsistentError("array dimensions not consistent")
- retval = [req_len]
- retval.extend(req_inner_lengths)
- return retval
- else:
- # make sure nothing else at this level is a list
- for v in arr:
- if isinstance(v, list):
- raise ArrayDimensionsNotConsistentError("array dimensions not consistent")
- return []
-
-def array_has_null(arr):
- for v in array_flatten(arr):
- if v == None:
- return True
- return False
-
-def array_dim_lengths(arr):
- v0 = arr[0]
- if isinstance(v0, list):
- retval = [len(v0)]
- retval.extend(array_dim_lengths(v0))
- else:
- return [len(arr)]
-
-class array_send(object):
- def __init__(self, typeoid, bin_out_func):
- self.typeoid = typeoid
- self.bin_out_func = bin_out_func
-
- def __call__(self, arr, **kwargs):
- has_null = array_has_null(arr)
- dim_lengths = array_dim_lengths(arr)
- data = struct.pack("!iii", len(dim_lengths), has_null, self.typeoid)
- for i in dim_lengths:
- data += struct.pack("!ii", i, 1)
- for v in array_flatten(arr):
- if v == None:
- data += struct.pack("!i", -1)
- else:
- inner_data = self.bin_out_func(v, **kwargs)
- data += struct.pack("!i", len(inner_data))
- data += inner_data
- return data
-
-class record_recv(object):
- def __init__(self, record_field_names):
- self.record_field_names = record_field_names
-
- def __call__(self, data, **kwargs):
- num_fields, = struct.unpack("!i", data[:4])
- data = data[4:]
- retval = {}
- for i in range(num_fields):
- typeoid, size = struct.unpack("!ii", data[:8])
- data = data[8:]
- conversion = pg_types[typeoid]["bin_in"]
- value = conversion(data[:size], **kwargs)
- data = data[size:]
- retval[self.record_field_names[i]] = value
- return retval
-
-py_types = {
- bool: {"typeoid": 16, "bin_out": boolsend},
- int: {"inspect": int_inspect},
- long: {"inspect": int_inspect},
- str: {"typeoid": 25, "bin_out": textout},
- unicode: {"typeoid": 25, "bin_out": textout},
- float: {"typeoid": 701, "bin_out": float8send},
- decimal.Decimal: {"typeoid": 1700, "bin_out": numeric_send},
- Bytea: {"typeoid": 17, "bin_out": byteasend},
- datetime.datetime: {"typeoid": 1114, "bin_out": timestamp_send, "inspect": datetime_inspect},
- datetime.date: {"typeoid": 1082, "txt_out": date_out},
- datetime.time: {"typeoid": 1083, "txt_out": time_out},
- Interval: {"typeoid": 1186, "bin_out": interval_send},
- type(None): {"typeoid": -1},
- list: {"inspect": array_inspect},
-}
-
-# py type -> pg array typeoid
-py_array_types = {
- float: 1022,
- bool: 1000,
- str: 1009, # TEXT[]
- unicode: 1009, # TEXT[]
- decimal.Decimal: 1231, # NUMERIC[]
-}
-
-pg_types = {
- 16: {"bin_in": boolrecv},
- 17: {"bin_in": bytearecv},
- 18: {"txt_in": varcharin}, # char type (Greenplum)
- 19: {"bin_in": varcharin}, # name type
- 20: {"bin_in": int8recv},
- 21: {"bin_in": int2recv},
- 23: {"bin_in": int4recv},
- 24: {"txt_in": varcharin}, # regproc (Greenplum)
- 25: {"bin_in": varcharin}, # TEXT type
- 26: {"txt_in": numeric_in}, # oid type
- 28: {"txt_in": numeric_in}, # xid type (Greenplum)
- 700: {"bin_in": float4recv},
- 701: {"bin_in": float8recv},
- 829: {"txt_in": varcharin}, # MACADDR type
- 1000: {"bin_in": array_recv}, # BOOL[]
- 1003: {"bin_in": array_recv}, # NAME[]
- 1005: {"bin_in": array_recv}, # INT2[]
- 1007: {"bin_in": array_recv}, # INT4[]
- 1009: {"bin_in": array_recv}, # TEXT[]
- 1014: {"bin_in": array_recv}, # CHAR[]
- 1015: {"bin_in": array_recv}, # VARCHAR[]
- 1016: {"bin_in": array_recv}, # INT8[]
- 1021: {"bin_in": array_recv}, # FLOAT4[]
- 1022: {"bin_in": array_recv}, # FLOAT8[]
- 1042: {"bin_in": varcharin}, # CHAR type
- 1043: {"bin_in": varcharin}, # VARCHAR type
- 1082: {"txt_in": date_in},
- 1083: {"txt_in": time_in},
- 1114: {"bin_in": timestamp_recv},
- 1184: {"bin_in": timestamptz_recv}, # timestamp w/ tz
- 1186: {"bin_in": interval_recv},
- 1231: {"bin_in": array_recv}, # NUMERIC[]
- 1263: {"bin_in": array_recv}, # cstring[]
- 1700: {"bin_in": numeric_recv},
- 2275: {"bin_in": varcharin}, # cstring
- 2278: {"txt_in": voidrecv}, # void - This is to allow the code to handle the situation where a SQL function returns void
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/util.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/util.py b/tools/bin/ext/pg8000/util.py
deleted file mode 100644
index d99421e..0000000
--- a/tools/bin/ext/pg8000/util.py
+++ /dev/null
@@ -1,20 +0,0 @@
-
-class MulticastDelegate(object):
- def __init__(self):
- self.delegates = []
-
- def __iadd__(self, delegate):
- self.add(delegate)
- return self
-
- def add(self, delegate):
- self.delegates.append(delegate)
-
- def __isub__(self, delegate):
- self.delegates.remove(delegate)
- return self
-
- def __call__(self, *args, **kwargs):
- for d in self.delegates:
- d(*args, **kwargs)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pygresql/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pygresql/__init__.py b/tools/bin/ext/pygresql/__init__.py
deleted file mode 100644
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/__init__.py b/tools/bin/ext/simplejson/__init__.py
deleted file mode 100755
index 6f0f605..0000000
--- a/tools/bin/ext/simplejson/__init__.py
+++ /dev/null
@@ -1,303 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-r"""
-A simple, fast, extensible JSON encoder and decoder
-
-JSON (JavaScript Object Notation) <http://json.org> is a subset of
-JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
-interchange format.
-
-simplejson exposes an API familiar to uses of the standard library
-marshal and pickle modules.
-
-Encoding basic Python object hierarchies::
-
- >>> import simplejson
- >>> simplejson.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
- '["foo", {"bar": ["baz", null, 1.0, 2]}]'
- >>> print simplejson.dumps("\"foo\bar")
- "\"foo\bar"
- >>> print simplejson.dumps(u'\u1234')
- "\u1234"
- >>> print simplejson.dumps('\\')
- "\\"
- >>> print simplejson.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
- {"a": 0, "b": 0, "c": 0}
- >>> from StringIO import StringIO
- >>> io = StringIO()
- >>> simplejson.dump(['streaming API'], io)
- >>> io.getvalue()
- '["streaming API"]'
-
-Compact encoding::
-
- >>> import simplejson
- >>> simplejson.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
- '[1,2,3,{"4":5,"6":7}]'
-
-Pretty printing::
-
- >>> import simplejson
- >>> print simplejson.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
- {
- "4": 5,
- "6": 7
- }
-
-Decoding JSON::
-
- >>> import simplejson
- >>> simplejson.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
- [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
- >>> simplejson.loads('"\\"foo\\bar"')
- u'"foo\x08ar'
- >>> from StringIO import StringIO
- >>> io = StringIO('["streaming API"]')
- >>> simplejson.load(io)
- [u'streaming API']
-
-Specializing JSON object decoding::
-
- >>> import simplejson
- >>> def as_complex(dct):
- ... if '__complex__' in dct:
- ... return complex(dct['real'], dct['imag'])
- ... return dct
- ...
- >>> simplejson.loads('{"__complex__": true, "real": 1, "imag": 2}',
- ... object_hook=as_complex)
- (1+2j)
-
-Extending JSONEncoder::
-
- >>> import simplejson
- >>> class ComplexEncoder(simplejson.JSONEncoder):
- ... def default(self, obj):
- ... if isinstance(obj, complex):
- ... return [obj.real, obj.imag]
- ... return simplejson.JSONEncoder.default(self, obj)
- ...
- >>> dumps(2 + 1j, cls=ComplexEncoder)
- '[2.0, 1.0]'
- >>> ComplexEncoder().encode(2 + 1j)
- '[2.0, 1.0]'
- >>> list(ComplexEncoder().iterencode(2 + 1j))
- ['[', '2.0', ', ', '1.0', ']']
-
-
-Note that the JSON produced by this module's default settings
-is a subset of YAML, so it may be used as a serializer for that as well.
-"""
-__version__ = '1.7.3'
-__all__ = [
- 'dump', 'dumps', 'load', 'loads',
- 'JSONDecoder', 'JSONEncoder',
-]
-
-from decoder import JSONDecoder
-from encoder import JSONEncoder
-
-_default_encoder = JSONEncoder(
- skipkeys=False,
- ensure_ascii=True,
- check_circular=True,
- allow_nan=True,
- indent=None,
- separators=None,
- encoding='utf-8'
-)
-
-def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
- allow_nan=True, cls=None, indent=None, separators=None,
- encoding='utf-8', **kw):
- """
- Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
- ``.write()``-supporting file-like object).
-
- If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
- (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
- will be skipped instead of raising a ``TypeError``.
-
- If ``ensure_ascii`` is ``False``, then the some chunks written to ``fp``
- may be ``unicode`` instances, subject to normal Python ``str`` to
- ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
- understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
- to cause an error.
-
- If ``check_circular`` is ``False``, then the circular reference check
- for container types will be skipped and a circular reference will
- result in an ``OverflowError`` (or worse).
-
- If ``allow_nan`` is ``False``, then it will be a ``ValueError`` to
- serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
- in strict compliance of the JSON specification, instead of using the
- JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
-
- If ``indent`` is a non-negative integer, then JSON array elements and object
- members will be pretty-printed with that indent level. An indent level
- of 0 will only insert newlines. ``None`` is the most compact representation.
-
- If ``separators`` is an ``(item_separator, dict_separator)`` tuple
- then it will be used instead of the default ``(', ', ': ')`` separators.
- ``(',', ':')`` is the most compact JSON representation.
-
- ``encoding`` is the character encoding for str instances, default is UTF-8.
-
- To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
- ``.default()`` method to serialize additional types), specify it with
- the ``cls`` kwarg.
- """
- # cached encoder
- if (skipkeys is False and ensure_ascii is True and
- check_circular is True and allow_nan is True and
- cls is None and indent is None and separators is None and
- encoding == 'utf-8' and not kw):
- iterable = _default_encoder.iterencode(obj)
- else:
- if cls is None:
- cls = JSONEncoder
- iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
- check_circular=check_circular, allow_nan=allow_nan, indent=indent,
- separators=separators, encoding=encoding, **kw).iterencode(obj)
- # could accelerate with writelines in some versions of Python, at
- # a debuggability cost
- for chunk in iterable:
- fp.write(chunk)
-
-
-def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
- allow_nan=True, cls=None, indent=None, separators=None,
- encoding='utf-8', **kw):
- """
- Serialize ``obj`` to a JSON formatted ``str``.
-
- If ``skipkeys`` is ``True`` then ``dict`` keys that are not basic types
- (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
- will be skipped instead of raising a ``TypeError``.
-
- If ``ensure_ascii`` is ``False``, then the return value will be a
- ``unicode`` instance subject to normal Python ``str`` to ``unicode``
- coercion rules instead of being escaped to an ASCII ``str``.
-
- If ``check_circular`` is ``False``, then the circular reference check
- for container types will be skipped and a circular reference will
- result in an ``OverflowError`` (or worse).
-
- If ``allow_nan`` is ``False``, then it will be a ``ValueError`` to
- serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
- strict compliance of the JSON specification, instead of using the
- JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
-
- If ``indent`` is a non-negative integer, then JSON array elements and
- object members will be pretty-printed with that indent level. An indent
- level of 0 will only insert newlines. ``None`` is the most compact
- representation.
-
- If ``separators`` is an ``(item_separator, dict_separator)`` tuple
- then it will be used instead of the default ``(', ', ': ')`` separators.
- ``(',', ':')`` is the most compact JSON representation.
-
- ``encoding`` is the character encoding for str instances, default is UTF-8.
-
- To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
- ``.default()`` method to serialize additional types), specify it with
- the ``cls`` kwarg.
- """
- # cached encoder
- if (skipkeys is False and ensure_ascii is True and
- check_circular is True and allow_nan is True and
- cls is None and indent is None and separators is None and
- encoding == 'utf-8' and not kw):
- return _default_encoder.encode(obj)
- if cls is None:
- cls = JSONEncoder
- return cls(
- skipkeys=skipkeys, ensure_ascii=ensure_ascii,
- check_circular=check_circular, allow_nan=allow_nan, indent=indent,
- separators=separators, encoding=encoding,
- **kw).encode(obj)
-
-_default_decoder = JSONDecoder(encoding=None, object_hook=None)
-
-def load(fp, encoding=None, cls=None, object_hook=None, **kw):
- """
- Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
- a JSON document) to a Python object.
-
- If the contents of ``fp`` is encoded with an ASCII based encoding other
- than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
- be specified. Encodings that are not ASCII based (such as UCS-2) are
- not allowed, and should be wrapped with
- ``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
- object and passed to ``loads()``
-
- ``object_hook`` is an optional function that will be called with the
- result of any object literal decode (a ``dict``). The return value of
- ``object_hook`` will be used instead of the ``dict``. This feature
- can be used to implement custom decoders (e.g. JSON-RPC class hinting).
-
- To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
- kwarg.
- """
- return loads(fp.read(),
- encoding=encoding, cls=cls, object_hook=object_hook, **kw)
-
-def loads(s, encoding=None, cls=None, object_hook=None, **kw):
- """
- Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
- document) to a Python object.
-
- If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
- other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
- must be specified. Encodings that are not ASCII based (such as UCS-2)
- are not allowed and should be decoded to ``unicode`` first.
-
- ``object_hook`` is an optional function that will be called with the
- result of any object literal decode (a ``dict``). The return value of
- ``object_hook`` will be used instead of the ``dict``. This feature
- can be used to implement custom decoders (e.g. JSON-RPC class hinting).
-
- To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
- kwarg.
- """
- if cls is None and encoding is None and object_hook is None and not kw:
- return _default_decoder.decode(s)
- if cls is None:
- cls = JSONDecoder
- if object_hook is not None:
- kw['object_hook'] = object_hook
- return cls(encoding=encoding, **kw).decode(s)
-
-def read(s):
- """
- json-py API compatibility hook. Use loads(s) instead.
- """
- import warnings
- warnings.warn("simplejson.loads(s) should be used instead of read(s)",
- DeprecationWarning)
- return loads(s)
-
-def write(obj):
- """
- json-py API compatibility hook. Use dumps(s) instead.
- """
- import warnings
- warnings.warn("simplejson.dumps(s) should be used instead of write(s)",
- DeprecationWarning)
- return dumps(obj)
-
-
[10/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/_speedups.c
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/_speedups.c b/tools/bin/ext/simplejson/_speedups.c
deleted file mode 100644
index e4cc18f..0000000
--- a/tools/bin/ext/simplejson/_speedups.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "Python.h"
-#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
-typedef int Py_ssize_t;
-#define PY_SSIZE_T_MAX INT_MAX
-#define PY_SSIZE_T_MIN INT_MIN
-#endif
-
-static Py_ssize_t
-ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars);
-static PyObject *
-ascii_escape_unicode(PyObject *pystr);
-static PyObject *
-ascii_escape_str(PyObject *pystr);
-static PyObject *
-py_encode_basestring_ascii(PyObject* self __attribute__((__unused__)), PyObject *pystr);
-void init_speedups(void);
-
-#define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '/' && c != '"')
-
-#define MIN_EXPANSION 6
-#ifdef Py_UNICODE_WIDE
-#define MAX_EXPANSION (2 * MIN_EXPANSION)
-#else
-#define MAX_EXPANSION MIN_EXPANSION
-#endif
-
-static Py_ssize_t
-ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars) {
- Py_UNICODE x;
- output[chars++] = '\\';
- switch (c) {
- case '/': output[chars++] = (char)c; break;
- case '\\': output[chars++] = (char)c; break;
- case '"': output[chars++] = (char)c; break;
- case '\b': output[chars++] = 'b'; break;
- case '\f': output[chars++] = 'f'; break;
- case '\n': output[chars++] = 'n'; break;
- case '\r': output[chars++] = 'r'; break;
- case '\t': output[chars++] = 't'; break;
- default:
-#ifdef Py_UNICODE_WIDE
- if (c >= 0x10000) {
- /* UTF-16 surrogate pair */
- Py_UNICODE v = c - 0x10000;
- c = 0xd800 | ((v >> 10) & 0x3ff);
- output[chars++] = 'u';
- x = (c & 0xf000) >> 12;
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- x = (c & 0x0f00) >> 8;
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- x = (c & 0x00f0) >> 4;
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- x = (c & 0x000f);
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- c = 0xdc00 | (v & 0x3ff);
- output[chars++] = '\\';
- }
-#endif
- output[chars++] = 'u';
- x = (c & 0xf000) >> 12;
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- x = (c & 0x0f00) >> 8;
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- x = (c & 0x00f0) >> 4;
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- x = (c & 0x000f);
- output[chars++] = (x < 10) ? '0' + x : 'a' + (x - 10);
- }
- return chars;
-}
-
-static PyObject *
-ascii_escape_unicode(PyObject *pystr) {
- Py_ssize_t i;
- Py_ssize_t input_chars;
- Py_ssize_t output_size;
- Py_ssize_t chars;
- PyObject *rval;
- char *output;
- Py_UNICODE *input_unicode;
-
- input_chars = PyUnicode_GET_SIZE(pystr);
- input_unicode = PyUnicode_AS_UNICODE(pystr);
- /* One char input can be up to 6 chars output, estimate 4 of these */
- output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
- rval = PyString_FromStringAndSize(NULL, output_size);
- if (rval == NULL) {
- return NULL;
- }
- output = PyString_AS_STRING(rval);
- chars = 0;
- output[chars++] = '"';
- for (i = 0; i < input_chars; i++) {
- Py_UNICODE c = input_unicode[i];
- if (S_CHAR(c)) {
- output[chars++] = (char)c;
- } else {
- chars = ascii_escape_char(c, output, chars);
- }
- if (output_size - chars < (1 + MAX_EXPANSION)) {
- /* There's more than four, so let's resize by a lot */
- output_size *= 2;
- /* This is an upper bound */
- if (output_size > 2 + (input_chars * MAX_EXPANSION)) {
- output_size = 2 + (input_chars * MAX_EXPANSION);
- }
- if (_PyString_Resize(&rval, output_size) == -1) {
- return NULL;
- }
- output = PyString_AS_STRING(rval);
- }
- }
- output[chars++] = '"';
- if (_PyString_Resize(&rval, chars) == -1) {
- return NULL;
- }
- return rval;
-}
-
-static PyObject *
-ascii_escape_str(PyObject *pystr) {
- Py_ssize_t i;
- Py_ssize_t input_chars;
- Py_ssize_t output_size;
- Py_ssize_t chars;
- PyObject *rval;
- char *output;
- char *input_str;
-
- input_chars = PyString_GET_SIZE(pystr);
- input_str = PyString_AS_STRING(pystr);
- /* One char input can be up to 6 chars output, estimate 4 of these */
- output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
- rval = PyString_FromStringAndSize(NULL, output_size);
- if (rval == NULL) {
- return NULL;
- }
- output = PyString_AS_STRING(rval);
- chars = 0;
- output[chars++] = '"';
- for (i = 0; i < input_chars; i++) {
- Py_UNICODE c = (Py_UNICODE)input_str[i];
- if (S_CHAR(c)) {
- output[chars++] = (char)c;
- } else if (c > 0x7F) {
- /* We hit a non-ASCII character, bail to unicode mode */
- PyObject *uni;
- Py_DECREF(rval);
- uni = PyUnicode_DecodeUTF8(input_str, input_chars, "strict");
- if (uni == NULL) {
- return NULL;
- }
- rval = ascii_escape_unicode(uni);
- Py_DECREF(uni);
- return rval;
- } else {
- chars = ascii_escape_char(c, output, chars);
- }
- /* An ASCII char can't possibly expand to a surrogate! */
- if (output_size - chars < (1 + MIN_EXPANSION)) {
- /* There's more than four, so let's resize by a lot */
- output_size *= 2;
- if (output_size > 2 + (input_chars * MIN_EXPANSION)) {
- output_size = 2 + (input_chars * MIN_EXPANSION);
- }
- if (_PyString_Resize(&rval, output_size) == -1) {
- return NULL;
- }
- output = PyString_AS_STRING(rval);
- }
- }
- output[chars++] = '"';
- if (_PyString_Resize(&rval, chars) == -1) {
- return NULL;
- }
- return rval;
-}
-
-PyDoc_STRVAR(pydoc_encode_basestring_ascii,
- "encode_basestring_ascii(basestring) -> str\n"
- "\n"
- "..."
-);
-
-static PyObject *
-py_encode_basestring_ascii(PyObject* self __attribute__((__unused__)), PyObject *pystr) {
- /* METH_O */
- if (PyString_Check(pystr)) {
- return ascii_escape_str(pystr);
- } else if (PyUnicode_Check(pystr)) {
- return ascii_escape_unicode(pystr);
- }
- PyErr_SetString(PyExc_TypeError, "first argument must be a string");
- return NULL;
-}
-
-#define DEFN(n, k) \
- { \
- #n, \
- (PyCFunction)py_ ##n, \
- k, \
- pydoc_ ##n \
- }
-static PyMethodDef speedups_methods[] = {
- DEFN(encode_basestring_ascii, METH_O),
- {}
-};
-#undef DEFN
-
-void
-init_speedups(void)
-{
- PyObject *m;
- m = Py_InitModule4("_speedups", speedups_methods, NULL, NULL, PYTHON_API_VERSION);
-}
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/decoder.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/decoder.py b/tools/bin/ext/simplejson/decoder.py
deleted file mode 100755
index 5182216..0000000
--- a/tools/bin/ext/simplejson/decoder.py
+++ /dev/null
@@ -1,289 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-Implementation of JSONDecoder
-"""
-import re
-
-from simplejson.scanner import Scanner, pattern
-
-FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
-
-def _floatconstants():
- import struct
- import sys
- _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
- if sys.byteorder != 'big':
- _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
- nan, inf = struct.unpack('dd', _BYTES)
- return nan, inf, -inf
-
-NaN, PosInf, NegInf = _floatconstants()
-
-def linecol(doc, pos):
- lineno = doc.count('\n', 0, pos) + 1
- if lineno == 1:
- colno = pos
- else:
- colno = pos - doc.rindex('\n', 0, pos)
- return lineno, colno
-
-def errmsg(msg, doc, pos, end=None):
- lineno, colno = linecol(doc, pos)
- if end is None:
- return '%s: line %d column %d (char %d)' % (msg, lineno, colno, pos)
- endlineno, endcolno = linecol(doc, end)
- return '%s: line %d column %d - line %d column %d (char %d - %d)' % (
- msg, lineno, colno, endlineno, endcolno, pos, end)
-
-_CONSTANTS = {
- '-Infinity': NegInf,
- 'Infinity': PosInf,
- 'NaN': NaN,
- 'true': True,
- 'false': False,
- 'null': None,
-}
-
-def JSONConstant(match, context, c=_CONSTANTS):
- return c[match.group(0)], None
-pattern('(-?Infinity|NaN|true|false|null)')(JSONConstant)
-
-def JSONNumber(match, context):
- match = JSONNumber.regex.match(match.string, *match.span())
- integer, frac, exp = match.groups()
- if frac or exp:
- res = float(integer + (frac or '') + (exp or ''))
- else:
- res = int(integer)
- return res, None
-pattern(r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?')(JSONNumber)
-
-STRINGCHUNK = re.compile(r'(.*?)(["\\])', FLAGS)
-BACKSLASH = {
- '"': u'"', '\\': u'\\', '/': u'/',
- 'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t',
-}
-
-DEFAULT_ENCODING = "utf-8"
-
-def scanstring(s, end, encoding=None, _b=BACKSLASH, _m=STRINGCHUNK.match):
- if encoding is None:
- encoding = DEFAULT_ENCODING
- chunks = []
- _append = chunks.append
- begin = end - 1
- while 1:
- chunk = _m(s, end)
- if chunk is None:
- raise ValueError(
- errmsg("Unterminated string starting at", s, begin))
- end = chunk.end()
- content, terminator = chunk.groups()
- if content:
- if not isinstance(content, unicode):
- content = unicode(content, encoding)
- _append(content)
- if terminator == '"':
- break
- try:
- esc = s[end]
- except IndexError:
- raise ValueError(
- errmsg("Unterminated string starting at", s, begin))
- if esc != 'u':
- try:
- m = _b[esc]
- except KeyError:
- raise ValueError(
- errmsg("Invalid \\escape: %r" % (esc,), s, end))
- end += 1
- else:
- esc = s[end + 1:end + 5]
- try:
- m = unichr(int(esc, 16))
- if len(esc) != 4 or not esc.isalnum():
- raise ValueError
- except ValueError:
- raise ValueError(errmsg("Invalid \\uXXXX escape", s, end))
- end += 5
- _append(m)
- return u''.join(chunks), end
-
-def JSONString(match, context):
- encoding = getattr(context, 'encoding', None)
- return scanstring(match.string, match.end(), encoding)
-pattern(r'"')(JSONString)
-
-WHITESPACE = re.compile(r'\s*', FLAGS)
-
-def JSONObject(match, context, _w=WHITESPACE.match):
- pairs = {}
- s = match.string
- end = _w(s, match.end()).end()
- nextchar = s[end:end + 1]
- # trivial empty object
- if nextchar == '}':
- return pairs, end + 1
- if nextchar != '"':
- raise ValueError(errmsg("Expecting property name", s, end))
- end += 1
- encoding = getattr(context, 'encoding', None)
- iterscan = JSONScanner.iterscan
- while True:
- key, end = scanstring(s, end, encoding)
- end = _w(s, end).end()
- if s[end:end + 1] != ':':
- raise ValueError(errmsg("Expecting : delimiter", s, end))
- end = _w(s, end + 1).end()
- try:
- value, end = iterscan(s, idx=end, context=context).next()
- except StopIteration:
- raise ValueError(errmsg("Expecting object", s, end))
- pairs[key] = value
- end = _w(s, end).end()
- nextchar = s[end:end + 1]
- end += 1
- if nextchar == '}':
- break
- if nextchar != ',':
- raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
- end = _w(s, end).end()
- nextchar = s[end:end + 1]
- end += 1
- if nextchar != '"':
- raise ValueError(errmsg("Expecting property name", s, end - 1))
- object_hook = getattr(context, 'object_hook', None)
- if object_hook is not None:
- pairs = object_hook(pairs)
- return pairs, end
-pattern(r'{')(JSONObject)
-
-def JSONArray(match, context, _w=WHITESPACE.match):
- values = []
- s = match.string
- end = _w(s, match.end()).end()
- # look-ahead for trivial empty array
- nextchar = s[end:end + 1]
- if nextchar == ']':
- return values, end + 1
- iterscan = JSONScanner.iterscan
- while True:
- try:
- value, end = iterscan(s, idx=end, context=context).next()
- except StopIteration:
- raise ValueError(errmsg("Expecting object", s, end))
- values.append(value)
- end = _w(s, end).end()
- nextchar = s[end:end + 1]
- end += 1
- if nextchar == ']':
- break
- if nextchar != ',':
- raise ValueError(errmsg("Expecting , delimiter", s, end))
- end = _w(s, end).end()
- return values, end
-pattern(r'\[')(JSONArray)
-
-ANYTHING = [
- JSONObject,
- JSONArray,
- JSONString,
- JSONConstant,
- JSONNumber,
-]
-
-JSONScanner = Scanner(ANYTHING)
-
-class JSONDecoder(object):
- """
- Simple JSON <http://json.org> decoder
-
- Performs the following translations in decoding:
-
- +---------------+-------------------+
- | JSON | Python |
- +===============+===================+
- | object | dict |
- +---------------+-------------------+
- | array | list |
- +---------------+-------------------+
- | string | unicode |
- +---------------+-------------------+
- | number (int) | int, long |
- +---------------+-------------------+
- | number (real) | float |
- +---------------+-------------------+
- | true | True |
- +---------------+-------------------+
- | false | False |
- +---------------+-------------------+
- | null | None |
- +---------------+-------------------+
-
- It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as
- their corresponding ``float`` values, which is outside the JSON spec.
- """
-
- _scanner = Scanner(ANYTHING)
- __all__ = ['__init__', 'decode', 'raw_decode']
-
- def __init__(self, encoding=None, object_hook=None):
- """
- ``encoding`` determines the encoding used to interpret any ``str``
- objects decoded by this instance (utf-8 by default). It has no
- effect when decoding ``unicode`` objects.
-
- Note that currently only encodings that are a superset of ASCII work,
- strings of other encodings should be passed in as ``unicode``.
-
- ``object_hook``, if specified, will be called with the result
- of every JSON object decoded and its return value will be used in
- place of the given ``dict``. This can be used to provide custom
- deserializations (e.g. to support JSON-RPC class hinting).
- """
- self.encoding = encoding
- self.object_hook = object_hook
-
- def decode(self, s, _w=WHITESPACE.match):
- """
- Return the Python representation of ``s`` (a ``str`` or ``unicode``
- instance containing a JSON document)
- """
- obj, end = self.raw_decode(s, idx=_w(s, 0).end())
- end = _w(s, end).end()
- if end != len(s):
- raise ValueError(errmsg("Extra data", s, end, len(s)))
- return obj
-
- def raw_decode(self, s, **kw):
- """
- Decode a JSON document from ``s`` (a ``str`` or ``unicode`` beginning
- with a JSON document) and return a 2-tuple of the Python
- representation and the index in ``s`` where the document ended.
-
- This can be used to decode a JSON document from a string that may
- have extraneous data at the end.
- """
- kw.setdefault('context', self)
- try:
- obj, end = self._scanner.iterscan(s, **kw).next()
- except StopIteration:
- raise ValueError("No JSON object could be decoded")
- return obj, end
-
-__all__ = ['JSONDecoder']
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/encoder.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/encoder.py b/tools/bin/ext/simplejson/encoder.py
deleted file mode 100755
index 4bf1746..0000000
--- a/tools/bin/ext/simplejson/encoder.py
+++ /dev/null
@@ -1,387 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-Implementation of JSONEncoder
-"""
-import re
-try:
- from simplejson import _speedups
-except ImportError:
- _speedups = None
-
-ESCAPE = re.compile(r'[\x00-\x19\\"\b\f\n\r\t]')
-ESCAPE_ASCII = re.compile(r'([\\"/]|[^\ -~])')
-ESCAPE_DCT = {
- # escape all forward slashes to prevent </script> attack
- '/': '\\/',
- '\\': '\\\\',
- '"': '\\"',
- '\b': '\\b',
- '\f': '\\f',
- '\n': '\\n',
- '\r': '\\r',
- '\t': '\\t',
-}
-for i in range(0x20):
- ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
-
-# assume this produces an infinity on all machines (probably not guaranteed)
-INFINITY = float('1e66666')
-
-def floatstr(o, allow_nan=True):
- # Check for specials. Note that this type of test is processor- and/or
- # platform-specific, so do tests which don't depend on the internals.
-
- if o != o:
- text = 'NaN'
- elif o == INFINITY:
- text = 'Infinity'
- elif o == -INFINITY:
- text = '-Infinity'
- else:
- return repr(o)
-
- if not allow_nan:
- raise ValueError("Out of range float values are not JSON compliant: %r"
- % (o,))
-
- return text
-
-
-def encode_basestring(s):
- """
- Return a JSON representation of a Python string
- """
- def replace(match):
- return ESCAPE_DCT[match.group(0)]
- return '"' + ESCAPE.sub(replace, s) + '"'
-
-def encode_basestring_ascii(s):
- def replace(match):
- s = match.group(0)
- try:
- return ESCAPE_DCT[s]
- except KeyError:
- n = ord(s)
- if n < 0x10000:
- return '\\u%04x' % (n,)
- else:
- # surrogate pair
- n -= 0x10000
- s1 = 0xd800 | ((n >> 10) & 0x3ff)
- s2 = 0xdc00 | (n & 0x3ff)
- return '\\u%04x\\u%04x' % (s1, s2)
- return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
-
-try:
- encode_basestring_ascii = _speedups.encode_basestring_ascii
- _need_utf8 = True
-except AttributeError:
- _need_utf8 = False
-
-class JSONEncoder(object):
- """
- Extensible JSON <http://json.org> encoder for Python data structures.
-
- Supports the following objects and types by default:
-
- +-------------------+---------------+
- | Python | JSON |
- +===================+===============+
- | dict | object |
- +-------------------+---------------+
- | list, tuple | array |
- +-------------------+---------------+
- | str, unicode | string |
- +-------------------+---------------+
- | int, long, float | number |
- +-------------------+---------------+
- | True | true |
- +-------------------+---------------+
- | False | false |
- +-------------------+---------------+
- | None | null |
- +-------------------+---------------+
-
- To extend this to recognize other objects, subclass and implement a
- ``.default()`` method with another method that returns a serializable
- object for ``o`` if possible, otherwise it should call the superclass
- implementation (to raise ``TypeError``).
- """
- __all__ = ['__init__', 'default', 'encode', 'iterencode']
- item_separator = ', '
- key_separator = ': '
- def __init__(self, skipkeys=False, ensure_ascii=True,
- check_circular=True, allow_nan=True, sort_keys=False,
- indent=None, separators=None, encoding='utf-8'):
- """
- Constructor for JSONEncoder, with sensible defaults.
-
- If skipkeys is False, then it is a TypeError to attempt
- encoding of keys that are not str, int, long, float or None. If
- skipkeys is True, such items are simply skipped.
-
- If ensure_ascii is True, the output is guaranteed to be str
- objects with all incoming unicode characters escaped. If
- ensure_ascii is false, the output will be unicode object.
-
- If check_circular is True, then lists, dicts, and custom encoded
- objects will be checked for circular references during encoding to
- prevent an infinite recursion (which would cause an OverflowError).
- Otherwise, no such check takes place.
-
- If allow_nan is True, then NaN, Infinity, and -Infinity will be
- encoded as such. This behavior is not JSON specification compliant,
- but is consistent with most JavaScript based encoders and decoders.
- Otherwise, it will be a ValueError to encode such floats.
-
- If sort_keys is True, then the output of dictionaries will be
- sorted by key; this is useful for regression tests to ensure
- that JSON serializations can be compared on a day-to-day basis.
-
- If indent is a non-negative integer, then JSON array
- elements and object members will be pretty-printed with that
- indent level. An indent level of 0 will only insert newlines.
- None is the most compact representation.
-
- If specified, separators should be a (item_separator, key_separator)
- tuple. The default is (', ', ': '). To get the most compact JSON
- representation you should specify (',', ':') to eliminate whitespace.
-
- If encoding is not None, then all input strings will be
- transformed into unicode using that encoding prior to JSON-encoding.
- The default is UTF-8.
- """
-
- self.skipkeys = skipkeys
- self.ensure_ascii = ensure_ascii
- self.check_circular = check_circular
- self.allow_nan = allow_nan
- self.sort_keys = sort_keys
- self.indent = indent
- self.current_indent_level = 0
- if separators is not None:
- self.item_separator, self.key_separator = separators
- self.encoding = encoding
-
- def _newline_indent(self):
- return '\n' + (' ' * (self.indent * self.current_indent_level))
-
- def _iterencode_list(self, lst, markers=None):
- if not lst:
- yield '[]'
- return
- if markers is not None:
- markerid = id(lst)
- if markerid in markers:
- raise ValueError("Circular reference detected")
- markers[markerid] = lst
- yield '['
- if self.indent is not None:
- self.current_indent_level += 1
- newline_indent = self._newline_indent()
- separator = self.item_separator + newline_indent
- yield newline_indent
- else:
- newline_indent = None
- separator = self.item_separator
- first = True
- for value in lst:
- if first:
- first = False
- else:
- yield separator
- for chunk in self._iterencode(value, markers):
- yield chunk
- if newline_indent is not None:
- self.current_indent_level -= 1
- yield self._newline_indent()
- yield ']'
- if markers is not None:
- del markers[markerid]
-
- def _iterencode_dict(self, dct, markers=None):
- if not dct:
- yield '{}'
- return
- if markers is not None:
- markerid = id(dct)
- if markerid in markers:
- raise ValueError("Circular reference detected")
- markers[markerid] = dct
- yield '{'
- key_separator = self.key_separator
- if self.indent is not None:
- self.current_indent_level += 1
- newline_indent = self._newline_indent()
- item_separator = self.item_separator + newline_indent
- yield newline_indent
- else:
- newline_indent = None
- item_separator = self.item_separator
- first = True
- if self.ensure_ascii:
- encoder = encode_basestring_ascii
- else:
- encoder = encode_basestring
- allow_nan = self.allow_nan
- if self.sort_keys:
- keys = dct.keys()
- keys.sort()
- items = [(k, dct[k]) for k in keys]
- else:
- items = dct.iteritems()
- _encoding = self.encoding
- _do_decode = (_encoding is not None
- and not (_need_utf8 and _encoding == 'utf-8'))
- for key, value in items:
- if isinstance(key, str):
- if _do_decode:
- key = key.decode(_encoding)
- elif isinstance(key, basestring):
- pass
- # JavaScript is weakly typed for these, so it makes sense to
- # also allow them. Many encoders seem to do something like this.
- elif isinstance(key, float):
- key = floatstr(key, allow_nan)
- elif isinstance(key, (int, long)):
- key = str(key)
- elif key is True:
- key = 'true'
- elif key is False:
- key = 'false'
- elif key is None:
- key = 'null'
- elif self.skipkeys:
- continue
- else:
- raise TypeError("key %r is not a string" % (key,))
- if first:
- first = False
- else:
- yield item_separator
- yield encoder(key)
- yield key_separator
- for chunk in self._iterencode(value, markers):
- yield chunk
- if newline_indent is not None:
- self.current_indent_level -= 1
- yield self._newline_indent()
- yield '}'
- if markers is not None:
- del markers[markerid]
-
- def _iterencode(self, o, markers=None):
- if isinstance(o, basestring):
- if self.ensure_ascii:
- encoder = encode_basestring_ascii
- else:
- encoder = encode_basestring
- _encoding = self.encoding
- if (_encoding is not None and isinstance(o, str)
- and not (_need_utf8 and _encoding == 'utf-8')):
- o = o.decode(_encoding)
- yield encoder(o)
- elif o is None:
- yield 'null'
- elif o is True:
- yield 'true'
- elif o is False:
- yield 'false'
- elif isinstance(o, (int, long)):
- yield str(o)
- elif isinstance(o, float):
- yield floatstr(o, self.allow_nan)
- elif isinstance(o, (list, tuple)):
- for chunk in self._iterencode_list(o, markers):
- yield chunk
- elif isinstance(o, dict):
- for chunk in self._iterencode_dict(o, markers):
- yield chunk
- else:
- if markers is not None:
- markerid = id(o)
- if markerid in markers:
- raise ValueError("Circular reference detected")
- markers[markerid] = o
- for chunk in self._iterencode_default(o, markers):
- yield chunk
- if markers is not None:
- del markers[markerid]
-
- def _iterencode_default(self, o, markers=None):
- newobj = self.default(o)
- return self._iterencode(newobj, markers)
-
- def default(self, o):
- """
- Implement this method in a subclass such that it returns
- a serializable object for ``o``, or calls the base implementation
- (to raise a ``TypeError``).
-
- For example, to support arbitrary iterators, you could
- implement default like this::
-
- def default(self, o):
- try:
- iterable = iter(o)
- except TypeError:
- pass
- else:
- return list(iterable)
- return JSONEncoder.default(self, o)
- """
- raise TypeError("%r is not JSON serializable" % (o,))
-
- def encode(self, o):
- """
- Return a JSON string representation of a Python data structure.
-
- >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
- '{"foo":["bar", "baz"]}'
- """
- # This is for extremely simple cases and benchmarks...
- if isinstance(o, basestring):
- if isinstance(o, str):
- _encoding = self.encoding
- if (_encoding is not None
- and not (_encoding == 'utf-8' and _need_utf8)):
- o = o.decode(_encoding)
- return encode_basestring_ascii(o)
- # This doesn't pass the iterator directly to ''.join() because it
- # sucks at reporting exceptions. It's going to do this internally
- # anyway because it uses PySequence_Fast or similar.
- chunks = list(self.iterencode(o))
- return ''.join(chunks)
-
- def iterencode(self, o):
- """
- Encode the given object and yield each string
- representation as available.
-
- For example::
-
- for chunk in JSONEncoder().iterencode(bigobject):
- mysocket.write(chunk)
- """
- if self.check_circular:
- markers = {}
- else:
- markers = None
- return self._iterencode(o, markers)
-
-__all__ = ['JSONEncoder']
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/jsonfilter.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/jsonfilter.py b/tools/bin/ext/simplejson/jsonfilter.py
deleted file mode 100755
index 074b481..0000000
--- a/tools/bin/ext/simplejson/jsonfilter.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import simplejson
-import cgi
-
-class JSONFilter(object):
- def __init__(self, app, mime_type='text/x-json'):
- self.app = app
- self.mime_type = mime_type
-
- def __call__(self, environ, start_response):
- # Read JSON POST input to jsonfilter.json if matching mime type
- response = {'status': '200 OK', 'headers': []}
- def json_start_response(status, headers):
- response['status'] = status
- response['headers'].extend(headers)
- environ['jsonfilter.mime_type'] = self.mime_type
- if environ.get('REQUEST_METHOD', '') == 'POST':
- if environ.get('CONTENT_TYPE', '') == self.mime_type:
- args = [_ for _ in [environ.get('CONTENT_LENGTH')] if _]
- data = environ['wsgi.input'].read(*map(int, args))
- environ['jsonfilter.json'] = simplejson.loads(data)
- res = simplejson.dumps(self.app(environ, json_start_response))
- jsonp = cgi.parse_qs(environ.get('QUERY_STRING', '')).get('jsonp')
- if jsonp:
- content_type = 'text/javascript'
- res = ''.join(jsonp + ['(', res, ')'])
- elif 'Opera' in environ.get('HTTP_USER_AGENT', ''):
- # Opera has bunk XMLHttpRequest support for most mime types
- content_type = 'text/plain'
- else:
- content_type = self.mime_type
- headers = [
- ('Content-type', content_type),
- ('Content-length', len(res)),
- ]
- headers.extend(response['headers'])
- start_response(response['status'], headers)
- return [res]
-
-def factory(app, global_conf, **kw):
- return JSONFilter(app, **kw)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/scanner.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/scanner.py b/tools/bin/ext/simplejson/scanner.py
deleted file mode 100755
index 5fe4f41..0000000
--- a/tools/bin/ext/simplejson/scanner.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-Iterator based sre token scanner
-"""
-import sre_parse, sre_compile, sre_constants
-from sre_constants import BRANCH, SUBPATTERN
-from re import VERBOSE, MULTILINE, DOTALL
-import re
-
-__all__ = ['Scanner', 'pattern']
-
-FLAGS = (VERBOSE | MULTILINE | DOTALL)
-class Scanner(object):
- def __init__(self, lexicon, flags=FLAGS):
- self.actions = [None]
- # combine phrases into a compound pattern
- s = sre_parse.Pattern()
- s.flags = flags
- p = []
- for idx, token in enumerate(lexicon):
- phrase = token.pattern
- try:
- subpattern = sre_parse.SubPattern(s,
- [(SUBPATTERN, (idx + 1, sre_parse.parse(phrase, flags)))])
- except sre_constants.error:
- raise
- p.append(subpattern)
- self.actions.append(token)
-
- p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
- self.scanner = sre_compile.compile(p)
-
-
- def iterscan(self, string, idx=0, context=None):
- """
- Yield match, end_idx for each match
- """
- match = self.scanner.scanner(string, idx).match
- actions = self.actions
- lastend = idx
- end = len(string)
- while True:
- m = match()
- if m is None:
- break
- matchbegin, matchend = m.span()
- if lastend == matchend:
- break
- action = actions[m.lastindex]
- if action is not None:
- rval, next_pos = action(m, context)
- if next_pos is not None and next_pos != matchend:
- # "fast forward" the scanner
- matchend = next_pos
- match = self.scanner.scanner(string, matchend).match
- yield rval, matchend
- lastend = matchend
-
-def pattern(pattern, flags=FLAGS):
- def decorator(fn):
- fn.pattern = pattern
- fn.regex = re.compile(pattern, flags)
- return fn
- return decorator
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/__init__.py b/tools/bin/ext/simplejson/tests/__init__.py
deleted file mode 100755
index e69de29..0000000
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_attacks.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_attacks.py b/tools/bin/ext/simplejson/tests/test_attacks.py
deleted file mode 100755
index f7bafdd..0000000
--- a/tools/bin/ext/simplejson/tests/test_attacks.py
+++ /dev/null
@@ -1,22 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-def test_script_close_attack():
- import simplejson
- res = simplejson.dumps('</script>')
- assert '</script>' not in res
- res = simplejson.dumps(simplejson.loads('"</script>"'))
- assert '</script>' not in res
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_dump.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_dump.py b/tools/bin/ext/simplejson/tests/test_dump.py
deleted file mode 100755
index 0e4ebfb..0000000
--- a/tools/bin/ext/simplejson/tests/test_dump.py
+++ /dev/null
@@ -1,26 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-from cStringIO import StringIO
-import simplejson as S
-
-def test_dump():
- sio = StringIO()
- S.dump({}, sio)
- assert sio.getvalue() == '{}'
-
-def test_dumps():
- assert S.dumps({}) == '{}'
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_fail.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_fail.py b/tools/bin/ext/simplejson/tests/test_fail.py
deleted file mode 100755
index 7f78720..0000000
--- a/tools/bin/ext/simplejson/tests/test_fail.py
+++ /dev/null
@@ -1,86 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# Fri Dec 30 18:57:26 2005
-JSONDOCS = [
- # http://json.org/JSON_checker/test/fail1.json
- '"A JSON payload should be an object or array, not a string."',
- # http://json.org/JSON_checker/test/fail2.json
- '["Unclosed array"',
- # http://json.org/JSON_checker/test/fail3.json
- '{unquoted_key: "keys must be quoted}',
- # http://json.org/JSON_checker/test/fail4.json
- '["extra comma",]',
- # http://json.org/JSON_checker/test/fail5.json
- '["double extra comma",,]',
- # http://json.org/JSON_checker/test/fail6.json
- '[ , "<-- missing value"]',
- # http://json.org/JSON_checker/test/fail7.json
- '["Comma after the close"],',
- # http://json.org/JSON_checker/test/fail8.json
- '["Extra close"]]',
- # http://json.org/JSON_checker/test/fail9.json
- '{"Extra comma": true,}',
- # http://json.org/JSON_checker/test/fail10.json
- '{"Extra value after close": true} "misplaced quoted value"',
- # http://json.org/JSON_checker/test/fail11.json
- '{"Illegal expression": 1 + 2}',
- # http://json.org/JSON_checker/test/fail12.json
- '{"Illegal invocation": alert()}',
- # http://json.org/JSON_checker/test/fail13.json
- '{"Numbers cannot have leading zeroes": 013}',
- # http://json.org/JSON_checker/test/fail14.json
- '{"Numbers cannot be hex": 0x14}',
- # http://json.org/JSON_checker/test/fail15.json
- '["Illegal backslash escape: \\x15"]',
- # http://json.org/JSON_checker/test/fail16.json
- '["Illegal backslash escape: \\\'"]',
- # http://json.org/JSON_checker/test/fail17.json
- '["Illegal backslash escape: \\017"]',
- # http://json.org/JSON_checker/test/fail18.json
- '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]',
- # http://json.org/JSON_checker/test/fail19.json
- '{"Missing colon" null}',
- # http://json.org/JSON_checker/test/fail20.json
- '{"Double colon":: null}',
- # http://json.org/JSON_checker/test/fail21.json
- '{"Comma instead of colon", null}',
- # http://json.org/JSON_checker/test/fail22.json
- '["Colon instead of comma": false]',
- # http://json.org/JSON_checker/test/fail23.json
- '["Bad value", truth]',
- # http://json.org/JSON_checker/test/fail24.json
- "['single quote']",
-]
-
-SKIPS = {
- 1: "why not have a string payload?",
- 18: "spec doesn't specify any nesting limitations",
-}
-
-def test_failures():
- import simplejson
- for idx, doc in enumerate(JSONDOCS):
- idx = idx + 1
- if idx in SKIPS:
- simplejson.loads(doc)
- continue
- try:
- simplejson.loads(doc)
- except ValueError:
- pass
- else:
- assert False, "Expected failure for fail%d.json: %r" % (idx, doc)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_float.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_float.py b/tools/bin/ext/simplejson/tests/test_float.py
deleted file mode 100755
index e33d3ac..0000000
--- a/tools/bin/ext/simplejson/tests/test_float.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-def test_floats():
- import simplejson
- for num in [1617161771.7650001]:
- assert simplejson.dumps(num) == repr(num)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_indent.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_indent.py b/tools/bin/ext/simplejson/tests/test_indent.py
deleted file mode 100755
index 74227bd..0000000
--- a/tools/bin/ext/simplejson/tests/test_indent.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-
-def test_indent():
- import simplejson
- import textwrap
-
- h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
- {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
-
- expect = textwrap.dedent("""\
- [
- [
- "blorpie"
- ],
- [
- "whoops"
- ],
- [],
- "d-shtaeou",
- "d-nthiouh",
- "i-vhbjkhnth",
- {
- "nifty": 87
- },
- {
- "field": "yes",
- "morefield": false
- }
- ]""")
-
-
- d1 = simplejson.dumps(h)
- d2 = simplejson.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
-
- h1 = simplejson.loads(d1)
- h2 = simplejson.loads(d2)
-
- assert h1 == h
- assert h2 == h
- assert d2 == expect
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_pass1.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_pass1.py b/tools/bin/ext/simplejson/tests/test_pass1.py
deleted file mode 100755
index 87658fd..0000000
--- a/tools/bin/ext/simplejson/tests/test_pass1.py
+++ /dev/null
@@ -1,88 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# from http://json.org/JSON_checker/test/pass1.json
-JSON = r'''
-[
- "JSON Test Pattern pass1",
- {"object with 1 member":["array with 1 element"]},
- {},
- [],
- -42,
- true,
- false,
- null,
- {
- "integer": 1234567890,
- "real": -9876.543210,
- "e": 0.123456789e-12,
- "E": 1.234567890E+34,
- "": 23456789012E666,
- "zero": 0,
- "one": 1,
- "space": " ",
- "quote": "\"",
- "backslash": "\\",
- "controls": "\b\f\n\r\t",
- "slash": "/ & \/",
- "alpha": "abcdefghijklmnopqrstuvwyz",
- "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
- "digit": "0123456789",
- "special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
- "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
- "true": true,
- "false": false,
- "null": null,
- "array":[ ],
- "object":{ },
- "address": "50 St. James Street",
- "url": "http://www.JSON.org/",
- "comment": "// /* <!-- --",
- "# -- --> */": " ",
- " s p a c e d " :[1,2 , 3
-
-,
-
-4 , 5 , 6 ,7 ],
- "compact": [1,2,3,4,5,6,7],
- "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
- "quotes": "" \u0022 %22 0x22 034 "",
- "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
-: "A key can be any string"
- },
- 0.5 ,98.6
-,
-99.44
-,
-
-1066
-
-
-,"rosebud"]
-'''
-
-def test_parse():
- # test in/out equivalence and parsing
- import simplejson
- res = simplejson.loads(JSON)
- out = simplejson.dumps(res)
- assert res == simplejson.loads(out)
- try:
- simplejson.dumps(res, allow_nan=False)
- except ValueError:
- pass
- else:
- assert False, "23456789012E666 should be out of range"
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_pass2.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_pass2.py b/tools/bin/ext/simplejson/tests/test_pass2.py
deleted file mode 100755
index 72bcfd0..0000000
--- a/tools/bin/ext/simplejson/tests/test_pass2.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# from http://json.org/JSON_checker/test/pass2.json
-JSON = r'''
-[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
-'''
-
-def test_parse():
- # test in/out equivalence and parsing
- import simplejson
- res = simplejson.loads(JSON)
- out = simplejson.dumps(res)
- assert res == simplejson.loads(out)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_pass3.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_pass3.py b/tools/bin/ext/simplejson/tests/test_pass3.py
deleted file mode 100755
index 2446aa9..0000000
--- a/tools/bin/ext/simplejson/tests/test_pass3.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# from http://json.org/JSON_checker/test/pass3.json
-JSON = r'''
-{
- "JSON Test Pattern pass3": {
- "The outermost value": "must be an object or array.",
- "In this test": "It is an object."
- }
-}
-'''
-
-def test_parse():
- # test in/out equivalence and parsing
- import simplejson
- res = simplejson.loads(JSON)
- out = simplejson.dumps(res)
- assert res == simplejson.loads(out)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_recursion.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_recursion.py b/tools/bin/ext/simplejson/tests/test_recursion.py
deleted file mode 100755
index 24e013c..0000000
--- a/tools/bin/ext/simplejson/tests/test_recursion.py
+++ /dev/null
@@ -1,78 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import simplejson
-
-def test_listrecursion():
- x = []
- x.append(x)
- try:
- simplejson.dumps(x)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on list recursion"
- x = []
- y = [x]
- x.append(y)
- try:
- simplejson.dumps(x)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on alternating list recursion"
- y = []
- x = [y, y]
- # ensure that the marker is cleared
- simplejson.dumps(x)
-
-def test_dictrecursion():
- x = {}
- x["test"] = x
- try:
- simplejson.dumps(x)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on dict recursion"
- x = {}
- y = {"a": x, "b": x}
- # ensure that the marker is cleared
- simplejson.dumps(x)
-
-class TestObject:
- pass
-
-class RecursiveJSONEncoder(simplejson.JSONEncoder):
- recurse = False
- def default(self, o):
- if o is TestObject:
- if self.recurse:
- return [TestObject]
- else:
- return 'TestObject'
- simplejson.JSONEncoder.default(o)
-
-def test_defaultrecursion():
- enc = RecursiveJSONEncoder()
- assert enc.encode(TestObject) == '"TestObject"'
- enc.recurse = True
- try:
- enc.encode(TestObject)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on default recursion"
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_separators.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_separators.py b/tools/bin/ext/simplejson/tests/test_separators.py
deleted file mode 100755
index f088e09..0000000
--- a/tools/bin/ext/simplejson/tests/test_separators.py
+++ /dev/null
@@ -1,57 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-
-def test_separators():
- import simplejson
- import textwrap
-
- h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
- {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
-
- expect = textwrap.dedent("""\
- [
- [
- "blorpie"
- ] ,
- [
- "whoops"
- ] ,
- [] ,
- "d-shtaeou" ,
- "d-nthiouh" ,
- "i-vhbjkhnth" ,
- {
- "nifty" : 87
- } ,
- {
- "field" : "yes" ,
- "morefield" : false
- }
- ]""")
-
-
- d1 = simplejson.dumps(h)
- d2 = simplejson.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
-
- h1 = simplejson.loads(d1)
- h2 = simplejson.loads(d2)
-
- assert h1 == h
- assert h2 == h
- assert d2 == expect
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/simplejson/tests/test_unicode.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/simplejson/tests/test_unicode.py b/tools/bin/ext/simplejson/tests/test_unicode.py
deleted file mode 100755
index 430bcd3..0000000
--- a/tools/bin/ext/simplejson/tests/test_unicode.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import simplejson as S
-
-def test_encoding1():
- encoder = S.JSONEncoder(encoding='utf-8')
- u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
- s = u.encode('utf-8')
- ju = encoder.encode(u)
- js = encoder.encode(s)
- assert ju == js
-
-def test_encoding2():
- u = u'\N{GREEK SMALL LETTER ALPHA}\N{GREEK CAPITAL LETTER OMEGA}'
- s = u.encode('utf-8')
- ju = S.dumps(u, encoding='utf-8')
- js = S.dumps(s, encoding='utf-8')
- assert ju == js
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/__init__.py b/tools/bin/ext/yaml/__init__.py
deleted file mode 100644
index b6c84f9..0000000
--- a/tools/bin/ext/yaml/__init__.py
+++ /dev/null
@@ -1,306 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-from error import *
-
-from tokens import *
-from events import *
-from nodes import *
-
-from loader import *
-from dumper import *
-
-try:
- from cyaml import *
-except ImportError:
- pass
-
-def scan(stream, Loader=Loader):
- """
- Scan a YAML stream and produce scanning tokens.
- """
- loader = Loader(stream)
- while loader.check_token():
- yield loader.get_token()
-
-def parse(stream, Loader=Loader):
- """
- Parse a YAML stream and produce parsing events.
- """
- loader = Loader(stream)
- while loader.check_event():
- yield loader.get_event()
-
-def compose(stream, Loader=Loader):
- """
- Parse the first YAML document in a stream
- and produce the corresponding representation tree.
- """
- loader = Loader(stream)
- if loader.check_node():
- return loader.get_node()
-
-def compose_all(stream, Loader=Loader):
- """
- Parse all YAML documents in a stream
- and produce corresponsing representation trees.
- """
- loader = Loader(stream)
- while loader.check_node():
- yield loader.get_node()
-
-def load_all(stream, Loader=Loader):
- """
- Parse all YAML documents in a stream
- and produce corresponding Python objects.
- """
- loader = Loader(stream)
- while loader.check_data():
- yield loader.get_data()
-
-def load(stream, Loader=Loader):
- """
- Parse the first YAML document in a stream
- and produce the corresponding Python object.
- """
- loader = Loader(stream)
- if loader.check_data():
- return loader.get_data()
-
-def safe_load_all(stream):
- """
- Parse all YAML documents in a stream
- and produce corresponding Python objects.
- Resolve only basic YAML tags.
- """
- return load_all(stream, SafeLoader)
-
-def safe_load(stream):
- """
- Parse the first YAML document in a stream
- and produce the corresponding Python object.
- Resolve only basic YAML tags.
- """
- return load(stream, SafeLoader)
-
-def emit(events, stream=None, Dumper=Dumper,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None):
- """
- Emit YAML parsing events into a stream.
- If stream is None, return the produced string instead.
- """
- getvalue = None
- if stream is None:
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- stream = StringIO()
- getvalue = stream.getvalue
- dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break)
- for event in events:
- dumper.emit(event)
- if getvalue:
- return getvalue()
-
-def serialize_all(nodes, stream=None, Dumper=Dumper,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding='utf-8', explicit_start=None, explicit_end=None,
- version=None, tags=None):
- """
- Serialize a sequence of representation trees into a YAML stream.
- If stream is None, return the produced string instead.
- """
- getvalue = None
- if stream is None:
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- stream = StringIO()
- getvalue = stream.getvalue
- dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- encoding=encoding, version=version, tags=tags,
- explicit_start=explicit_start, explicit_end=explicit_end)
- dumper.open()
- for node in nodes:
- dumper.serialize(node)
- dumper.close()
- if getvalue:
- return getvalue()
-
-def serialize(node, stream=None, Dumper=Dumper, **kwds):
- """
- Serialize a representation tree into a YAML stream.
- If stream is None, return the produced string instead.
- """
- return serialize_all([node], stream, Dumper=Dumper, **kwds)
-
-def dump_all(documents, stream=None, Dumper=Dumper,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding='utf-8', explicit_start=None, explicit_end=None,
- version=None, tags=None):
- """
- Serialize a sequence of Python objects into a YAML stream.
- If stream is None, return the produced string instead.
- """
- getvalue = None
- if stream is None:
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- stream = StringIO()
- getvalue = stream.getvalue
- dumper = Dumper(stream, default_style=default_style,
- default_flow_style=default_flow_style,
- canonical=canonical, indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- encoding=encoding, version=version, tags=tags,
- explicit_start=explicit_start, explicit_end=explicit_end)
- dumper.open()
- for data in documents:
- dumper.represent(data)
- dumper.close()
- if getvalue:
- return getvalue()
-
-def dump(data, stream=None, Dumper=Dumper, **kwds):
- """
- Serialize a Python object into a YAML stream.
- If stream is None, return the produced string instead.
- """
- return dump_all([data], stream, Dumper=Dumper, **kwds)
-
-def safe_dump_all(documents, stream=None, **kwds):
- """
- Serialize a sequence of Python objects into a YAML stream.
- Produce only basic YAML tags.
- If stream is None, return the produced string instead.
- """
- return dump_all(documents, stream, Dumper=SafeDumper, **kwds)
-
-def safe_dump(data, stream=None, **kwds):
- """
- Serialize a Python object into a YAML stream.
- Produce only basic YAML tags.
- If stream is None, return the produced string instead.
- """
- return dump_all([data], stream, Dumper=SafeDumper, **kwds)
-
-def add_implicit_resolver(tag, regexp, first=None,
- Loader=Loader, Dumper=Dumper):
- """
- Add an implicit scalar detector.
- If an implicit scalar value matches the given regexp,
- the corresponding tag is assigned to the scalar.
- first is a sequence of possible initial characters or None.
- """
- Loader.add_implicit_resolver(tag, regexp, first)
- Dumper.add_implicit_resolver(tag, regexp, first)
-
-def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
- """
- Add a path based resolver for the given tag.
- A path is a list of keys that forms a path
- to a node in the representation tree.
- Keys can be string values, integers, or None.
- """
- Loader.add_path_resolver(tag, path, kind)
- Dumper.add_path_resolver(tag, path, kind)
-
-def add_constructor(tag, constructor, Loader=Loader):
- """
- Add a constructor for the given tag.
- Constructor is a function that accepts a Loader instance
- and a node object and produces the corresponding Python object.
- """
- Loader.add_constructor(tag, constructor)
-
-def add_multi_constructor(tag_prefix, multi_constructor, Loader=Loader):
- """
- Add a multi-constructor for the given tag prefix.
- Multi-constructor is called for a node if its tag starts with tag_prefix.
- Multi-constructor accepts a Loader instance, a tag suffix,
- and a node object and produces the corresponding Python object.
- """
- Loader.add_multi_constructor(tag_prefix, multi_constructor)
-
-def add_representer(data_type, representer, Dumper=Dumper):
- """
- Add a representer for the given type.
- Representer is a function accepting a Dumper instance
- and an instance of the given data type
- and producing the corresponding representation node.
- """
- Dumper.add_representer(data_type, representer)
-
-def add_multi_representer(data_type, multi_representer, Dumper=Dumper):
- """
- Add a representer for the given type.
- Multi-representer is a function accepting a Dumper instance
- and an instance of the given data type or subtype
- and producing the corresponding representation node.
- """
- Dumper.add_multi_representer(data_type, multi_representer)
-
-class YAMLObjectMetaclass(type):
- """
- The metaclass for YAMLObject.
- """
- def __init__(cls, name, bases, kwds):
- super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds)
- if 'yaml_tag' in kwds and kwds['yaml_tag'] is not None:
- cls.yaml_loader.add_constructor(cls.yaml_tag, cls.from_yaml)
- cls.yaml_dumper.add_representer(cls, cls.to_yaml)
-
-class YAMLObject(object):
- """
- An object that can dump itself to a YAML stream
- and load itself from a YAML stream.
- """
-
- __metaclass__ = YAMLObjectMetaclass
- __slots__ = () # no direct instantiation, so allow immutable subclasses
-
- yaml_loader = Loader
- yaml_dumper = Dumper
-
- yaml_tag = None
- yaml_flow_style = None
-
- def from_yaml(cls, loader, node):
- """
- Convert a representation node to a Python object.
- """
- return loader.construct_yaml_object(node, cls)
- from_yaml = classmethod(from_yaml)
-
- def to_yaml(cls, dumper, data):
- """
- Convert a Python object to a representation node.
- """
- return dumper.represent_yaml_object(cls.yaml_tag, data, cls,
- flow_style=cls.yaml_flow_style)
- to_yaml = classmethod(to_yaml)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/composer.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/composer.py b/tools/bin/ext/yaml/composer.py
deleted file mode 100644
index a3fb797..0000000
--- a/tools/bin/ext/yaml/composer.py
+++ /dev/null
@@ -1,134 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['Composer', 'ComposerError']
-
-from error import MarkedYAMLError
-from events import *
-from nodes import *
-
-class ComposerError(MarkedYAMLError):
- pass
-
-class Composer(object):
-
- def __init__(self):
- self.anchors = {}
-
- def check_node(self):
- # Drop the STREAM-START event.
- if self.check_event(StreamStartEvent):
- self.get_event()
-
- # If there are more documents available?
- return not self.check_event(StreamEndEvent)
-
- def get_node(self):
- # Get the root node of the next document.
- if not self.check_event(StreamEndEvent):
- return self.compose_document()
-
- def compose_document(self):
- # Drop the DOCUMENT-START event.
- self.get_event()
-
- # Compose the root node.
- node = self.compose_node(None, None)
-
- # Drop the DOCUMENT-END event.
- self.get_event()
-
- self.anchors = {}
- return node
-
- def compose_node(self, parent, index):
- if self.check_event(AliasEvent):
- event = self.get_event()
- anchor = event.anchor
- if anchor not in self.anchors:
- raise ComposerError(None, None, "found undefined alias %r"
- % anchor.encode('utf-8'), event.start_mark)
- return self.anchors[anchor]
- event = self.peek_event()
- anchor = event.anchor
- if anchor is not None:
- if anchor in self.anchors:
- raise ComposerError("found duplicate anchor %r; first occurence"
- % anchor.encode('utf-8'), self.anchors[anchor].start_mark,
- "second occurence", event.start_mark)
- self.descend_resolver(parent, index)
- if self.check_event(ScalarEvent):
- node = self.compose_scalar_node(anchor)
- elif self.check_event(SequenceStartEvent):
- node = self.compose_sequence_node(anchor)
- elif self.check_event(MappingStartEvent):
- node = self.compose_mapping_node(anchor)
- self.ascend_resolver()
- return node
-
- def compose_scalar_node(self, anchor):
- event = self.get_event()
- tag = event.tag
- if tag is None or tag == u'!':
- tag = self.resolve(ScalarNode, event.value, event.implicit)
- node = ScalarNode(tag, event.value,
- event.start_mark, event.end_mark, style=event.style)
- if anchor is not None:
- self.anchors[anchor] = node
- return node
-
- def compose_sequence_node(self, anchor):
- start_event = self.get_event()
- tag = start_event.tag
- if tag is None or tag == u'!':
- tag = self.resolve(SequenceNode, None, start_event.implicit)
- node = SequenceNode(tag, [],
- start_event.start_mark, None,
- flow_style=start_event.flow_style)
- if anchor is not None:
- self.anchors[anchor] = node
- index = 0
- while not self.check_event(SequenceEndEvent):
- node.value.append(self.compose_node(node, index))
- index += 1
- end_event = self.get_event()
- node.end_mark = end_event.end_mark
- return node
-
- def compose_mapping_node(self, anchor):
- start_event = self.get_event()
- tag = start_event.tag
- if tag is None or tag == u'!':
- tag = self.resolve(MappingNode, None, start_event.implicit)
- node = MappingNode(tag, [],
- start_event.start_mark, None,
- flow_style=start_event.flow_style)
- if anchor is not None:
- self.anchors[anchor] = node
- while not self.check_event(MappingEndEvent):
- #key_event = self.peek_event()
- item_key = self.compose_node(node, None)
- #if item_key in node.value:
- # raise ComposerError("while composing a mapping", start_event.start_mark,
- # "found duplicate key", key_event.start_mark)
- item_value = self.compose_node(node, item_key)
- #node.value[item_key] = item_value
- node.value.append((item_key, item_value))
- end_event = self.get_event()
- node.end_mark = end_event.end_mark
- return node
-
[06/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.html
deleted file mode 100644
index 24c38e9..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.html
+++ /dev/null
@@ -1,333 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL ChangeLog</title>
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-changelog">
-<h1 class="title">PyGreSQL ChangeLog</h1>
-<div class="section">
-<h1><a id="version-4-0-2009-01-01" name="version-4-0-2009-01-01">Version 4.0 (2009-01-01)</a></h1>
-<ul class="simple">
-<li>Dropped support for Python below 2.3 and PostgreSQL below 7.4.</li>
-<li>Improved performance of fetchall() for large result sets
-by speeding up the type casts (as suggested by Peter Schuller).</li>
-<li>Exposed exceptions as attributes of the connection object.</li>
-<li>Exposed connection as attribute of the cursor object.</li>
-<li>Cursors now support the iteration protocol.</li>
-<li>Added new method to get parameter settings.</li>
-<li>Added customizable row_factory as suggested by Simon Pamies.</li>
-<li>Separated between mandatory and additional type objects.</li>
-<li>Added keyword args to insert, update and delete methods.</li>
-<li>Added exception handling for direct copy.</li>
-<li>Release the GIL while making a connection
-(as suggested by Peter Schuller).</li>
-<li>If available, use decimal.Decimal for numeric types.</li>
-<li>Allow DB wrapper to be used with DB-API 2 connections
-(as suggested by Chris Hilton).</li>
-<li>Made private attributes of DB wrapper accessible.</li>
-<li>Dropped dependence on mx.DateTime module.</li>
-<li>Support for PQescapeStringConn() and PQescapeByteaConn();
-these are now also used by the internal _quote() functions.</li>
-<li>Added 'int8' to INTEGER types. New SMALLINT type.</li>
-<li>Added a way to find the number of rows affected by a query()
-with the classic pg module by returning it as a string.
-For single inserts, query() still returns the oid as an integer.
-The pgdb module already provides the "rowcount" cursor attribute
-for the same purpose.</li>
-<li>Improved getnotify() by calling PQconsumeInput() instead of
-submitting an empty command.</li>
-<li>Removed compatibility code for old OID munging style.</li>
-<li>The insert() and update() methods now use the "returning" clause
-if possible to get all changed values, and they also check in advance
-whether a subsequent select is possible, so that ongoing transactions
-won't break if there is no select privilege.</li>
-<li>Added "protocol_version" and "server_version" attributes.</li>
-<li>Revived the "user" attribute.</li>
-<li>The pg module now works correctly with composite primary keys;
-these are represented as frozensets.</li>
-<li>Removed the undocumented and actually unnecessary "view" parameter
-from the get() method.</li>
-<li>get() raises a nicer ProgrammingError instead of a KeyError
-if no primary key was found.</li>
-<li>delete() now also works based on the primary key if no oid available
-and returns whether the row existed or not.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-8-1-2006-06-05" name="version-3-8-1-2006-06-05">Version 3.8.1 (2006-06-05)</a></h1>
-<ul class="simple">
-<li>Use string methods instead of deprecated string functions.</li>
-<li>Only use SQL-standard way of escaping quotes.</li>
-<li>Added the functions escape_string() and escape/unescape_bytea()
-(as suggested by Charlie Dyson and Kavous Bojnourdi a long time ago).</li>
-<li>Reverted code in clear() method that set date to current.</li>
-<li>Added code for backwards compatibility in OID munging code.</li>
-<li>Reorder attnames tests so that "interval" is checked for before "int."</li>
-<li>If caller supplies key dictionary, make sure that all has a namespace.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-8-2006-02-17" name="version-3-8-2006-02-17">Version 3.8 (2006-02-17)</a></h1>
-<ul class="simple">
-<li>Installed new favicon.ico from Matthew Sporleder <<a class="reference" href="mailto:mspo@mspo.com">mspo@mspo.com</a>></li>
-<li>Replaced snprintf by PyOS_snprintf.</li>
-<li>Removed NO_SNPRINTF switch which is not needed any longer</li>
-<li>Clean up some variable names and namespace</li>
-<li>Add get_relations() method to get any type of relation</li>
-<li>Rewrite get_tables() to use get_relations()</li>
-<li>Use new method in get_attnames method to get attributes of views as well</li>
-<li>Add Binary type</li>
-<li>Number of rows is now -1 after executing no-result statements</li>
-<li>Fix some number handling</li>
-<li>Non-simple types do not raise an error any more</li>
-<li>Improvements to documentation framework</li>
-<li>Take into account that nowadays not every table must have an oid column</li>
-<li>Simplification and improvement of the inserttable() function</li>
-<li>Fix up unit tests</li>
-<li>The usual assortment of minor fixes and enhancements</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-7-2005-09-07" name="version-3-7-2005-09-07">Version 3.7 (2005-09-07)</a></h1>
-<p>Improvement of pgdb module:</p>
-<ul class="simple">
-<li>Use Python standard <cite>datetime</cite> if <cite>mxDateTime</cite> is not available</li>
-</ul>
-<p>Major improvements and clean-up in classic pg module:</p>
-<ul class="simple">
-<li>All members of the underlying connection directly available in <cite>DB</cite></li>
-<li>Fixes to quoting function</li>
-<li>Add checks for valid database connection to methods</li>
-<li>Improved namespace support, handle <cite>search_path</cite> correctly</li>
-<li>Removed old dust and unnessesary imports, added docstrings</li>
-<li>Internal sql statements as one-liners, smoothed out ugly code</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-6-2-2005-02-23" name="version-3-6-2-2005-02-23">Version 3.6.2 (2005-02-23)</a></h1>
-<ul class="simple">
-<li>Further fixes to namespace handling</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-6-1-2005-01-11" name="version-3-6-1-2005-01-11">Version 3.6.1 (2005-01-11)</a></h1>
-<ul class="simple">
-<li>Fixes to namespace handling</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-6-2004-12-17" name="version-3-6-2004-12-17">Version 3.6 (2004-12-17)</a></h1>
-<ul class="simple">
-<li>Better DB-API 2.0 compliance</li>
-<li>Exception hierarchy moved into C module and made available to both APIs</li>
-<li>Fix error in update method that caused false exceptions</li>
-<li>Moved to standard exception hierarchy in classic API</li>
-<li>Added new method to get transaction state</li>
-<li>Use proper Python constants where appropriate</li>
-<li>Use Python versions of strtol, etc. Allows Win32 build.</li>
-<li>Bug fixes and cleanups</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-5-2004-08-29" name="version-3-5-2004-08-29">Version 3.5 (2004-08-29)</a></h1>
-<p>Fixes and enhancements:</p>
-<ul class="simple">
-<li>Add interval to list of data types</li>
-<li>fix up method wrapping especially close()</li>
-<li>retry pkeys once if table missing in case it was just added</li>
-<li>wrap query method separately to handle debug better</li>
-<li>use isinstance instead of type</li>
-<li>fix free/PQfreemem issue - finally</li>
-<li>miscellaneous cleanups and formatting</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-4-2004-06-02" name="version-3-4-2004-06-02">Version 3.4 (2004-06-02)</a></h1>
-<p>Some cleanups and fixes.
-This is the first version where PyGreSQL is moved back out of the
-PostgreSQL tree. A lot of the changes mentioned below were actually
-made while in the PostgreSQL tree since their last release.</p>
-<ul class="simple">
-<li>Allow for larger integer returns</li>
-<li>Return proper strings for true and false</li>
-<li>Cleanup convenience method creation</li>
-<li>Enhance debugging method</li>
-<li>Add reopen method</li>
-<li>Allow programs to preload field names for speedup</li>
-<li>Move OID handling so that it returns long instead of int</li>
-<li>Miscellaneous cleanups and formatting</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-3-2001-12-03" name="version-3-3-2001-12-03">Version 3.3 (2001-12-03)</a></h1>
-<p>A few cleanups. Mostly there was some confusion about the latest version
-and so I am bumping the number to keep it straight.</p>
-<ul class="simple">
-<li>Added NUMERICOID to list of returned types. This fixes a bug when
-returning aggregates in the latest version of PostgreSQL.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-2-2001-06-20" name="version-3-2-2001-06-20">Version 3.2 (2001-06-20)</a></h1>
-<p>Note that there are very few changes to PyGreSQL between 3.1 and 3.2.
-The main reason for the release is the move into the PostgreSQL
-development tree. Even the WIN32 changes are pretty minor.</p>
-<ul class="simple">
-<li>Add Win32 support (<a class="reference" href="mailto:gerhard@bigfoot.de">gerhard@bigfoot.de</a>)</li>
-<li>Fix some DB-API quoting problems (<a class="reference" href="mailto:niall.smart@ebeon.com">niall.smart@ebeon.com</a>)</li>
-<li>Moved development into PostgreSQL development tree.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-1-2000-11-06" name="version-3-1-2000-11-06">Version 3.1 (2000-11-06)</a></h1>
-<ul class="simple">
-<li>Fix some quoting functions. In particular handle NULLs better.</li>
-<li>Use a method to add primary key information rather than direct
-manipulation of the class structures</li>
-<li>Break decimal out in <cite>_quote</cite> (in pg.py) and treat it as float</li>
-<li>Treat timestamp like date for quoting purposes</li>
-<li>Remove a redundant SELECT from the <cite>get</cite> method speeding it,
-and <cite>insert</cite> (since it calls <cite>get</cite>) up a little.</li>
-<li>Add test for BOOL type in typecast method to <cite>pgdbTypeCache</cite> class
-(<a class="reference" href="mailto:tv@beamnet.de">tv@beamnet.de</a>)</li>
-<li>Fix pgdb.py to send port as integer to lower level function
-(<a class="reference" href="mailto:dildog@l0pht.com">dildog@l0pht.com</a>)</li>
-<li>Change pg.py to speed up some operations</li>
-<li>Allow updates on tables with no primary keys</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-3-0-2000-05-30" name="version-3-0-2000-05-30">Version 3.0 (2000-05-30)</a></h1>
-<ul class="simple">
-<li>Remove strlen() call from pglarge_write() and get size from object
-(<a class="reference" href="mailto:Richard@Bouska.cz">Richard@Bouska.cz</a>)</li>
-<li>Add a little more error checking to the quote function in the wrapper</li>
-<li>Add extra checking in <cite>_quote</cite> function</li>
-<li>Wrap query in pg.py for debugging</li>
-<li>Add DB-API 2.0 support to pgmodule.c (<a class="reference" href="mailto:andre@via.ecp.fr">andre@via.ecp.fr</a>)</li>
-<li>Add DB-API 2.0 wrapper pgdb.py (<a class="reference" href="mailto:andre@via.ecp.fr">andre@via.ecp.fr</a>)</li>
-<li>Correct keyword clash (temp) in tutorial</li>
-<li>Clean up layout of tutorial</li>
-<li>Return NULL values as None (<a class="reference" href="mailto:rlawrence@lastfoot.com">rlawrence@lastfoot.com</a>)
-(WARNING: This will cause backwards compatibility issues)</li>
-<li>Change None to NULL in insert and update</li>
-<li>Change hash-bang lines to use /usr/bin/env</li>
-<li>Clearing date should be blank (NULL) not TODAY</li>
-<li>Quote backslashes in strings in <cite>_quote</cite> (<a class="reference" href="mailto:brian@CSUA.Berkeley.EDU">brian@CSUA.Berkeley.EDU</a>)</li>
-<li>Expanded and clarified build instructions (<a class="reference" href="mailto:tbryan@starship.python.net">tbryan@starship.python.net</a>)</li>
-<li>Make code thread safe (<a class="reference" href="mailto:Jerome.Alet@unice.fr">Jerome.Alet@unice.fr</a>)</li>
-<li>Add README.distutils (<a class="reference" href="mailto:mwa@gate.net">mwa@gate.net</a> & <a class="reference" href="mailto:jeremy@cnri.reston.va.us">jeremy@cnri.reston.va.us</a>)</li>
-<li>Many fixes and increased DB-API compliance by <a class="reference" href="mailto:chifungfan@yahoo.com">chifungfan@yahoo.com</a>,
-<a class="reference" href="mailto:tony@printra.net">tony@printra.net</a>, <a class="reference" href="mailto:jeremy@alum.mit.edu">jeremy@alum.mit.edu</a> and others to get the final
-version ready to release.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-2-4-1999-06-15" name="version-2-4-1999-06-15">Version 2.4 (1999-06-15)</a></h1>
-<ul class="simple">
-<li>Insert returns None if the user doesn't have select permissions
-on the table. It can (and does) happen that one has insert but
-not select permissions on a table.</li>
-<li>Added ntuples() method to query object (<a class="reference" href="mailto:brit@druid.net">brit@druid.net</a>)</li>
-<li>Corrected a bug related to getresult() and the money type</li>
-<li>Corrected a bug related to negative money amounts</li>
-<li>Allow update based on primary key if munged oid not available and
-table has a primary key</li>
-<li>Add many __doc__ strings (<a class="reference" href="mailto:andre@via.ecp.fr">andre@via.ecp.fr</a>)</li>
-<li>Get method works with views if key specified</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-2-3-1999-04-17" name="version-2-3-1999-04-17">Version 2.3 (1999-04-17)</a></h1>
-<ul class="simple">
-<li>connect.host returns "localhost" when connected to Unix socket
-(<a class="reference" href="mailto:torppa@tuhnu.cutery.fi">torppa@tuhnu.cutery.fi</a>)</li>
-<li>Use <cite>PyArg_ParseTupleAndKeywords</cite> in connect() (<a class="reference" href="mailto:torppa@tuhnu.cutery.fi">torppa@tuhnu.cutery.fi</a>)</li>
-<li>fixes and cleanups (<a class="reference" href="mailto:torppa@tuhnu.cutery.fi">torppa@tuhnu.cutery.fi</a>)</li>
-<li>Fixed memory leak in dictresult() (<a class="reference" href="mailto:terekhov@emc.com">terekhov@emc.com</a>)</li>
-<li>Deprecated pgext.py - functionality now in pg.py</li>
-<li>More cleanups to the tutorial</li>
-<li>Added fileno() method - <a class="reference" href="mailto:terekhov@emc.com">terekhov@emc.com</a> (Mikhail Terekhov)</li>
-<li>added money type to quoting function</li>
-<li>Compiles cleanly with more warnings turned on</li>
-<li>Returns PostgreSQL error message on error</li>
-<li>Init accepts keywords (Jarkko Torppa)</li>
-<li>Convenience functions can be overridden (Jarkko Torppa)</li>
-<li>added close() method</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-2-2-1998-12-21" name="version-2-2-1998-12-21">Version 2.2 (1998-12-21)</a></h1>
-<ul class="simple">
-<li>Added user and password support thanks to Ng Pheng Siong (<a class="reference" href="mailto:ngps@post1.com">ngps@post1.com</a>)</li>
-<li>Insert queries return the inserted oid</li>
-<li>Add new <cite>pg</cite> wrapper (C module renamed to _pg)</li>
-<li>Wrapped database connection in a class</li>
-<li>Cleaned up some of the tutorial. (More work needed.)</li>
-<li>Added <cite>version</cite> and <cite>__version__</cite>.
-Thanks to <a class="reference" href="mailto:thilo@eevolute.com">thilo@eevolute.com</a> for the suggestion.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-2-1-1998-03-07" name="version-2-1-1998-03-07">Version 2.1 (1998-03-07)</a></h1>
-<ul class="simple">
-<li>return fields as proper Python objects for field type</li>
-<li>Cleaned up pgext.py</li>
-<li>Added dictresult method</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-2-0-1997-12-23" name="version-2-0-1997-12-23">Version 2.0 (1997-12-23)</a></h1>
-<ul class="simple">
-<li>Updated code for PostgreSQL 6.2.1 and Python 1.5</li>
-<li>Reformatted code and converted to use full ANSI style prototypes</li>
-<li>Changed name to PyGreSQL (from PyGres95)</li>
-<li>Changed order of arguments to connect function</li>
-<li>Created new type <cite>pgqueryobject</cite> and moved certain methods to it</li>
-<li>Added a print function for pgqueryobject</li>
-<li>Various code changes - mostly stylistic</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-1-0b-1995-11-04" name="version-1-0b-1995-11-04">Version 1.0b (1995-11-04)</a></h1>
-<ul class="simple">
-<li>Keyword support for connect function moved from library file to C code
-and taken away from library</li>
-<li>Rewrote documentation</li>
-<li>Bug fix in connect function</li>
-<li>Enhancements in large objects interface methods</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-1-0a-1995-10-30" name="version-1-0a-1995-10-30">Version 1.0a (1995-10-30)</a></h1>
-<p>A limited release.</p>
-<ul class="simple">
-<li>Module adapted to standard Python syntax</li>
-<li>Keyword support for connect function in library file</li>
-<li>Rewrote default parameters interface (internal use of strings)</li>
-<li>Fixed minor bugs in module interface</li>
-<li>Redefinition of error messages</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-0-9b-1995-10-10" name="version-0-9b-1995-10-10">Version 0.9b (1995-10-10)</a></h1>
-<p>The first public release.</p>
-<ul class="simple">
-<li>Large objects implementation</li>
-<li>Many bug fixes, enhancements, ...</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="version-0-1a-1995-10-07" name="version-0-1a-1995-10-07">Version 0.1a (1995-10-07)</a></h1>
-<ul class="simple">
-<li>Basic libpq functions (SQL access)</li>
-</ul>
-</div>
-</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.txt
deleted file mode 100644
index ea0d71d..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/changelog.txt
+++ /dev/null
@@ -1,285 +0,0 @@
-==================
-PyGreSQL ChangeLog
-==================
-
-Version 4.0 (2009-01-01)
-------------------------
-- Dropped support for Python below 2.3 and PostgreSQL below 7.4.
-- Improved performance of fetchall() for large result sets
- by speeding up the type casts (as suggested by Peter Schuller).
-- Exposed exceptions as attributes of the connection object.
-- Exposed connection as attribute of the cursor object.
-- Cursors now support the iteration protocol.
-- Added new method to get parameter settings.
-- Added customizable row_factory as suggested by Simon Pamies.
-- Separated between mandatory and additional type objects.
-- Added keyword args to insert, update and delete methods.
-- Added exception handling for direct copy.
-- Release the GIL while making a connection
- (as suggested by Peter Schuller).
-- If available, use decimal.Decimal for numeric types.
-- Allow DB wrapper to be used with DB-API 2 connections
- (as suggested by Chris Hilton).
-- Made private attributes of DB wrapper accessible.
-- Dropped dependence on mx.DateTime module.
-- Support for PQescapeStringConn() and PQescapeByteaConn();
- these are now also used by the internal _quote() functions.
-- Added 'int8' to INTEGER types. New SMALLINT type.
-- Added a way to find the number of rows affected by a query()
- with the classic pg module by returning it as a string.
- For single inserts, query() still returns the oid as an integer.
- The pgdb module already provides the "rowcount" cursor attribute
- for the same purpose.
-- Improved getnotify() by calling PQconsumeInput() instead of
- submitting an empty command.
-- Removed compatibility code for old OID munging style.
-- The insert() and update() methods now use the "returning" clause
- if possible to get all changed values, and they also check in advance
- whether a subsequent select is possible, so that ongoing transactions
- won't break if there is no select privilege.
-- Added "protocol_version" and "server_version" attributes.
-- Revived the "user" attribute.
-- The pg module now works correctly with composite primary keys;
- these are represented as frozensets.
-- Removed the undocumented and actually unnecessary "view" parameter
- from the get() method.
-- get() raises a nicer ProgrammingError instead of a KeyError
- if no primary key was found.
-- delete() now also works based on the primary key if no oid available
- and returns whether the row existed or not.
-
-
-Version 3.8.1 (2006-06-05)
---------------------------
-- Use string methods instead of deprecated string functions.
-- Only use SQL-standard way of escaping quotes.
-- Added the functions escape_string() and escape/unescape_bytea()
- (as suggested by Charlie Dyson and Kavous Bojnourdi a long time ago).
-- Reverted code in clear() method that set date to current.
-- Added code for backwards compatibility in OID munging code.
-- Reorder attnames tests so that "interval" is checked for before "int."
-- If caller supplies key dictionary, make sure that all has a namespace.
-
-Version 3.8 (2006-02-17)
-------------------------
-- Installed new favicon.ico from Matthew Sporleder <ms...@mspo.com>
-- Replaced snprintf by PyOS_snprintf.
-- Removed NO_SNPRINTF switch which is not needed any longer
-- Clean up some variable names and namespace
-- Add get_relations() method to get any type of relation
-- Rewrite get_tables() to use get_relations()
-- Use new method in get_attnames method to get attributes of views as well
-- Add Binary type
-- Number of rows is now -1 after executing no-result statements
-- Fix some number handling
-- Non-simple types do not raise an error any more
-- Improvements to documentation framework
-- Take into account that nowadays not every table must have an oid column
-- Simplification and improvement of the inserttable() function
-- Fix up unit tests
-- The usual assortment of minor fixes and enhancements
-
-Version 3.7 (2005-09-07)
-------------------------
-Improvement of pgdb module:
-
-- Use Python standard `datetime` if `mxDateTime` is not available
-
-Major improvements and clean-up in classic pg module:
-
-- All members of the underlying connection directly available in `DB`
-- Fixes to quoting function
-- Add checks for valid database connection to methods
-- Improved namespace support, handle `search_path` correctly
-- Removed old dust and unnessesary imports, added docstrings
-- Internal sql statements as one-liners, smoothed out ugly code
-
-Version 3.6.2 (2005-02-23)
---------------------------
-- Further fixes to namespace handling
-
-Version 3.6.1 (2005-01-11)
---------------------------
-- Fixes to namespace handling
-
-Version 3.6 (2004-12-17)
-------------------------
-- Better DB-API 2.0 compliance
-- Exception hierarchy moved into C module and made available to both APIs
-- Fix error in update method that caused false exceptions
-- Moved to standard exception hierarchy in classic API
-- Added new method to get transaction state
-- Use proper Python constants where appropriate
-- Use Python versions of strtol, etc. Allows Win32 build.
-- Bug fixes and cleanups
-
-Version 3.5 (2004-08-29)
-------------------------
-Fixes and enhancements:
-
-- Add interval to list of data types
-- fix up method wrapping especially close()
-- retry pkeys once if table missing in case it was just added
-- wrap query method separately to handle debug better
-- use isinstance instead of type
-- fix free/PQfreemem issue - finally
-- miscellaneous cleanups and formatting
-
-Version 3.4 (2004-06-02)
-------------------------
-Some cleanups and fixes.
-This is the first version where PyGreSQL is moved back out of the
-PostgreSQL tree. A lot of the changes mentioned below were actually
-made while in the PostgreSQL tree since their last release.
-
-- Allow for larger integer returns
-- Return proper strings for true and false
-- Cleanup convenience method creation
-- Enhance debugging method
-- Add reopen method
-- Allow programs to preload field names for speedup
-- Move OID handling so that it returns long instead of int
-- Miscellaneous cleanups and formatting
-
-Version 3.3 (2001-12-03)
-------------------------
-A few cleanups. Mostly there was some confusion about the latest version
-and so I am bumping the number to keep it straight.
-
-- Added NUMERICOID to list of returned types. This fixes a bug when
- returning aggregates in the latest version of PostgreSQL.
-
-Version 3.2 (2001-06-20)
-------------------------
-Note that there are very few changes to PyGreSQL between 3.1 and 3.2.
-The main reason for the release is the move into the PostgreSQL
-development tree. Even the WIN32 changes are pretty minor.
-
-- Add Win32 support (gerhard@bigfoot.de)
-- Fix some DB-API quoting problems (niall.smart@ebeon.com)
-- Moved development into PostgreSQL development tree.
-
-Version 3.1 (2000-11-06)
-------------------------
-- Fix some quoting functions. In particular handle NULLs better.
-- Use a method to add primary key information rather than direct
- manipulation of the class structures
-- Break decimal out in `_quote` (in pg.py) and treat it as float
-- Treat timestamp like date for quoting purposes
-- Remove a redundant SELECT from the `get` method speeding it,
- and `insert` (since it calls `get`) up a little.
-- Add test for BOOL type in typecast method to `pgdbTypeCache` class
- (tv@beamnet.de)
-- Fix pgdb.py to send port as integer to lower level function
- (dildog@l0pht.com)
-- Change pg.py to speed up some operations
-- Allow updates on tables with no primary keys
-
-Version 3.0 (2000-05-30)
-------------------------
-- Remove strlen() call from pglarge_write() and get size from object
- (Richard@Bouska.cz)
-- Add a little more error checking to the quote function in the wrapper
-- Add extra checking in `_quote` function
-- Wrap query in pg.py for debugging
-- Add DB-API 2.0 support to pgmodule.c (andre@via.ecp.fr)
-- Add DB-API 2.0 wrapper pgdb.py (andre@via.ecp.fr)
-- Correct keyword clash (temp) in tutorial
-- Clean up layout of tutorial
-- Return NULL values as None (rlawrence@lastfoot.com)
- (WARNING: This will cause backwards compatibility issues)
-- Change None to NULL in insert and update
-- Change hash-bang lines to use /usr/bin/env
-- Clearing date should be blank (NULL) not TODAY
-- Quote backslashes in strings in `_quote` (brian@CSUA.Berkeley.EDU)
-- Expanded and clarified build instructions (tbryan@starship.python.net)
-- Make code thread safe (Jerome.Alet@unice.fr)
-- Add README.distutils (mwa@gate.net & jeremy@cnri.reston.va.us)
-- Many fixes and increased DB-API compliance by chifungfan@yahoo.com,
- tony@printra.net, jeremy@alum.mit.edu and others to get the final
- version ready to release.
-
-Version 2.4 (1999-06-15)
-------------------------
-- Insert returns None if the user doesn't have select permissions
- on the table. It can (and does) happen that one has insert but
- not select permissions on a table.
-- Added ntuples() method to query object (brit@druid.net)
-- Corrected a bug related to getresult() and the money type
-- Corrected a bug related to negative money amounts
-- Allow update based on primary key if munged oid not available and
- table has a primary key
-- Add many __doc__ strings (andre@via.ecp.fr)
-- Get method works with views if key specified
-
-Version 2.3 (1999-04-17)
-------------------------
-- connect.host returns "localhost" when connected to Unix socket
- (torppa@tuhnu.cutery.fi)
-- Use `PyArg_ParseTupleAndKeywords` in connect() (torppa@tuhnu.cutery.fi)
-- fixes and cleanups (torppa@tuhnu.cutery.fi)
-- Fixed memory leak in dictresult() (terekhov@emc.com)
-- Deprecated pgext.py - functionality now in pg.py
-- More cleanups to the tutorial
-- Added fileno() method - terekhov@emc.com (Mikhail Terekhov)
-- added money type to quoting function
-- Compiles cleanly with more warnings turned on
-- Returns PostgreSQL error message on error
-- Init accepts keywords (Jarkko Torppa)
-- Convenience functions can be overridden (Jarkko Torppa)
-- added close() method
-
-Version 2.2 (1998-12-21)
-------------------------
-- Added user and password support thanks to Ng Pheng Siong (ngps@post1.com)
-- Insert queries return the inserted oid
-- Add new `pg` wrapper (C module renamed to _pg)
-- Wrapped database connection in a class
-- Cleaned up some of the tutorial. (More work needed.)
-- Added `version` and `__version__`.
- Thanks to thilo@eevolute.com for the suggestion.
-
-Version 2.1 (1998-03-07)
-------------------------
-- return fields as proper Python objects for field type
-- Cleaned up pgext.py
-- Added dictresult method
-
-Version 2.0 (1997-12-23)
--------------------------
-- Updated code for PostgreSQL 6.2.1 and Python 1.5
-- Reformatted code and converted to use full ANSI style prototypes
-- Changed name to PyGreSQL (from PyGres95)
-- Changed order of arguments to connect function
-- Created new type `pgqueryobject` and moved certain methods to it
-- Added a print function for pgqueryobject
-- Various code changes - mostly stylistic
-
-Version 1.0b (1995-11-04)
--------------------------
-- Keyword support for connect function moved from library file to C code
- and taken away from library
-- Rewrote documentation
-- Bug fix in connect function
-- Enhancements in large objects interface methods
-
-Version 1.0a (1995-10-30)
--------------------------
-A limited release.
-
-- Module adapted to standard Python syntax
-- Keyword support for connect function in library file
-- Rewrote default parameters interface (internal use of strings)
-- Fixed minor bugs in module interface
-- Redefinition of error messages
-
-Version 0.9b (1995-10-10)
--------------------------
-The first public release.
-
-- Large objects implementation
-- Many bug fixes, enhancements, ...
-
-Version 0.1a (1995-10-07)
--------------------------
-- Basic libpq functions (SQL access)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/default.css
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/default.css b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/default.css
deleted file mode 100644
index 15d0778..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/default.css
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
-:Author: David Goodger
-:Contact: goodger@users.sourceforge.net
-:Date: $Date: 2006/01/22 16:15:33 $
-:Revision: $Revision: 1.2 $
-:Copyright: This stylesheet has been placed in the public domain.
-
-Default cascading style sheet for the HTML output of Docutils.
-
-See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
-customize this style sheet.
-*/
-
-/* used to remove borders from tables and images */
-.borderless, table.borderless td, table.borderless th {
- border: 0 }
-
-table.borderless td, table.borderless th {
- /* Override padding for "table.docutils td" with "! important".
- The right padding separates the table cells. */
- padding: 0 0.5em 0 0 ! important }
-
-.first {
- /* Override more specific margin styles with "! important". */
- margin-top: 0 ! important }
-
-.last, .with-subtitle {
- margin-bottom: 0 ! important }
-
-.hidden {
- display: none }
-
-a.toc-backref {
- text-decoration: none ;
- color: black }
-
-blockquote.epigraph {
- margin: 2em 5em ; }
-
-dl.docutils dd {
- margin-bottom: 0.5em }
-
-/* Uncomment (and remove this text!) to get bold-faced definition list terms
-dl.docutils dt {
- font-weight: bold }
-*/
-
-div.abstract {
- margin: 2em 5em }
-
-div.abstract p.topic-title {
- font-weight: bold ;
- text-align: center }
-
-div.admonition, div.attention, div.caution, div.danger, div.error,
-div.hint, div.important, div.note, div.tip, div.warning {
- margin: 2em ;
- border: medium outset ;
- padding: 1em }
-
-div.admonition p.admonition-title, div.hint p.admonition-title,
-div.important p.admonition-title, div.note p.admonition-title,
-div.tip p.admonition-title {
- font-weight: bold ;
- font-family: sans-serif }
-
-div.attention p.admonition-title, div.caution p.admonition-title,
-div.danger p.admonition-title, div.error p.admonition-title,
-div.warning p.admonition-title {
- color: red ;
- font-weight: bold ;
- font-family: sans-serif }
-
-/* Uncomment (and remove this text!) to get reduced vertical space in
- compound paragraphs.
-div.compound .compound-first, div.compound .compound-middle {
- margin-bottom: 0.5em }
-
-div.compound .compound-last, div.compound .compound-middle {
- margin-top: 0.5em }
-*/
-
-div.dedication {
- margin: 2em 5em ;
- text-align: center ;
- font-style: italic }
-
-div.dedication p.topic-title {
- font-weight: bold ;
- font-style: normal }
-
-div.figure {
- margin-left: 2em ;
- margin-right: 2em }
-
-div.footer, div.header {
- clear: both;
- font-size: smaller }
-
-div.line-block {
- display: block ;
- margin-top: 1em ;
- margin-bottom: 1em }
-
-div.line-block div.line-block {
- margin-top: 0 ;
- margin-bottom: 0 ;
- margin-left: 1.5em }
-
-div.sidebar {
- margin-left: 1em ;
- border: medium outset ;
- padding: 1em ;
- background-color: #ffffee ;
- width: 40% ;
- float: right ;
- clear: right }
-
-div.sidebar p.rubric {
- font-family: sans-serif ;
- font-size: medium }
-
-div.system-messages {
- margin: 5em }
-
-div.system-messages h1 {
- color: red }
-
-div.system-message {
- border: medium outset ;
- padding: 1em }
-
-div.system-message p.system-message-title {
- color: red ;
- font-weight: bold }
-
-div.topic {
- margin: 2em }
-
-h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
-h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
- margin-top: 0.4em }
-
-h1.title {
- text-align: center }
-
-h2.subtitle {
- text-align: center }
-
-hr.docutils {
- width: 75% }
-
-img.align-left {
- clear: left }
-
-img.align-right {
- clear: right }
-
-ol.simple, ul.simple {
- margin-bottom: 1em }
-
-ol.arabic {
- list-style: decimal }
-
-ol.loweralpha {
- list-style: lower-alpha }
-
-ol.upperalpha {
- list-style: upper-alpha }
-
-ol.lowerroman {
- list-style: lower-roman }
-
-ol.upperroman {
- list-style: upper-roman }
-
-p.attribution {
- text-align: right ;
- margin-left: 50% }
-
-p.caption {
- font-style: italic }
-
-p.credits {
- font-style: italic ;
- font-size: smaller }
-
-p.label {
- white-space: nowrap }
-
-p.rubric {
- font-weight: bold ;
- font-size: larger ;
- color: maroon ;
- text-align: center }
-
-p.sidebar-title {
- font-family: sans-serif ;
- font-weight: bold ;
- font-size: larger }
-
-p.sidebar-subtitle {
- font-family: sans-serif ;
- font-weight: bold }
-
-p.topic-title {
- font-weight: bold }
-
-pre.address {
- margin-bottom: 0 ;
- margin-top: 0 ;
- font-family: serif ;
- font-size: 100% }
-
-pre.literal-block, pre.doctest-block {
- margin-left: 2em ;
- margin-right: 2em ;
- background-color: #eeeeee }
-
-span.classifier {
- font-family: sans-serif ;
- font-style: oblique }
-
-span.classifier-delimiter {
- font-family: sans-serif ;
- font-weight: bold }
-
-span.interpreted {
- font-family: sans-serif }
-
-span.option {
- white-space: nowrap }
-
-span.pre {
- white-space: pre }
-
-span.problematic {
- color: red }
-
-span.section-subtitle {
- /* font-size relative to parent (h1..h6 element) */
- font-size: 80% }
-
-table.citation {
- border-left: solid 1px gray;
- margin-left: 1px }
-
-table.docinfo {
- margin: 2em 4em }
-
-table.docutils {
- margin-top: 0.5em ;
- margin-bottom: 0.5em }
-
-table.footnote {
- border-left: solid 1px black;
- margin-left: 1px }
-
-table.docutils td, table.docutils th,
-table.docinfo td, table.docinfo th {
- padding-left: 0.5em ;
- padding-right: 0.5em ;
- vertical-align: top }
-
-table.docutils th.field-name, table.docinfo th.docinfo-name {
- font-weight: bold ;
- text-align: left ;
- white-space: nowrap ;
- padding-left: 0 }
-
-h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
-h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
- font-size: 100% }
-
-tt.docutils {
- background-color: #eeeeee }
-
-ul.auto-toc {
- list-style-type: none }
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/docs.css
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/docs.css b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/docs.css
deleted file mode 100644
index 3d99c95..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/docs.css
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
-Stylesheet for use with Docutils.
-
-Customized for PyGreSQL docs.
-*/
-
-@import url(default.css);
-
-body {
- margin: 8pt;
- padding: 8pt;
- background-color: #f8f8ff;
- color: #000008;
- text-align: justify;
- font-family: Arial, Verdana, Helvetica, sans-serif;
- font-size: 11pt; }
-
-a {
- text-decoration: none; }
-
-a:hover {
- text-decoration: underline; }
-
-.title, .subtitle {
- color: #003; }
-
-.topic-title {
- color: #006;
- font-size: 14pt; }
-
-h1, h2, h3, h4 {
- color: #006; }
-
-h1 {
- padding-top: 20pt;
- font-size: 17pt; }
-
-div#pygresql-changelog div.section h1 {
- font-size: 12pt;
-}
-
-h1.title {
- font-size: 20pt;
-}
-
-h2 {
- font-size: 14pt; }
-
-h2.subtitle {
- font-size: 16pt;
-}
-
-h3 {
- font-size: 13pt; }
-
-h4 {
- font-size: 12pt; }
-
-a.toc-backref {
- color: #006; }
-
-ul.simple li {
- margin-top: 4pt; }
-
-ul.simple ul li {
- margin-top: 2pt; }
-
-div.contents ul {
- list-style-type: none; }
-
-div.contents ul li {
- margin-top: 4pt;
- font-size: 12pt; }
-
-div.contents ul ul li {
- margin-top: 2pt;
- font-size: 11pt; }
-
-cite {
- font-style: normal;
- font-family: monospace;
- font-weight: bold; }
-
-table.field-list th.field-name {
- font-style: normal;
- font-family: monospace;
- font-weight: bold; }
-
-tt.literal, pre.literal-block {
- font-style: normal;
- font-family: monospace;
- font-weight: bold;
- background-color: #fff; }
-
-tt.literal {
- padding-left: 2pt;
- padding-right: 2pt; }
-
-pre.literal-block {
- padding: 4pt;
- border: 1px dotted #ccc; }
-
-table.docutils {
- border-spacing: 0px;
- border-collapse: collapse; }
-
-table.docutils td {
- margin: 0px;
- padding: 2pt; }
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.html
deleted file mode 100644
index 358de81..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.html
+++ /dev/null
@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL future directions</title>
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-future-directions">
-<h1 class="title">PyGreSQL future directions</h1>
-<div class="section">
-<h1><a id="to-do" name="to-do">To Do</a></h1>
-<ul class="simple">
-<li>Documentation for the pgdb module (everything specific to PyGreSQL).</li>
-<li>The large object and direct access functions need much more attention.</li>
-<li>The C module needs to be cleaned up and redundant code merged,
-and should get its own unit test module.</li>
-<li>The fetch method should use real cursors.</li>
-<li>What shall we do with the "tutorial" directory
-(it's rather a tutorial for Postgres/SQL than for PyGreSQL,
-it's using only the query method from the classic pg module and
-no other PyGreSQL functionality, it's rather a demo than a tutorial)?</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="proposed-patches" name="proposed-patches">Proposed Patches</a></h1>
-<ul class="simple">
-<li>Notice handling with PQsetNoticeReceiver and PQsetNoticeProcessor
-(one possible implementation was already suggested by Dmitry Dvoinikov
-<a class="reference" href="http://mailman.vex.net/pipermail/pygresql/2005-November/001530.html">http://mailman.vex.net/pipermail/pygresql/2005-November/001530.html</a>).
-Maybe also make notifications accessible via the optional cursor and
-connection attribute "messages" proposed in the DB-API specs.</li>
-</ul>
-</div>
-<div class="section">
-<h1><a id="wish-list" name="wish-list">Wish List</a></h1>
-<ul class="simple">
-<li>Make SQLSTATE error codes available.</li>
-<li>Make use of PQexecParams() and PQprepare(). This could speed up
-executemany() and allow retrieving binary data directly by setting
-the resultFormat parameter to one.</li>
-<li>Support optional "errorhandler" extension.</li>
-<li>Support optional cursor and connection attribute "messages".</li>
-<li>Connection as context manager (see <a class="reference" href="http://tinyurl.com/6j9cef">http://tinyurl.com/6j9cef</a>).</li>
-<li>Users should be able to register their own types with _pg.</li>
-<li>Let pg and pgdb support namedtuples (as available in Py 2.6).
-pg could get a new method namedresult(), and pgdb could provide
-a row factory for namedtuples (similar to sqlite3).</li>
-<li>New methods in the classic module, similar to getresult() and
-dictresult(), but returning dictionaries of rows instead of lists
-of rows (with primary key or oids as keys).</li>
-<li>Make PyGreSQL thread-safe on the connection level.</li>
-<li>The API documentation could be created with Epydoc.</li>
-<li>Write a tutorial for beginners and advanced use.</li>
-<li>More and better documented examples.</li>
-</ul>
-</div>
-</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.txt
deleted file mode 100644
index 8dec0fb..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/future.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-==========================
-PyGreSQL future directions
-==========================
-
-
-To Do
------
-
-- Documentation for the pgdb module (everything specific to PyGreSQL).
-- The large object and direct access functions need much more attention.
-- The C module needs to be cleaned up and redundant code merged,
- and should get its own unit test module.
-- The fetch method should use real cursors.
-- What shall we do with the "tutorial" directory
- (it's rather a tutorial for Postgres/SQL than for PyGreSQL,
- it's using only the query method from the classic pg module and
- no other PyGreSQL functionality, it's rather a demo than a tutorial)?
-
-Proposed Patches
-----------------
-
-- Notice handling with PQsetNoticeReceiver and PQsetNoticeProcessor
- (one possible implementation was already suggested by Dmitry Dvoinikov
- http://mailman.vex.net/pipermail/pygresql/2005-November/001530.html).
- Maybe also make notifications accessible via the optional cursor and
- connection attribute "messages" proposed in the DB-API specs.
-
-Wish List
----------
-
-- Make SQLSTATE error codes available.
-- Make use of PQexecParams() and PQprepare(). This could speed up
- executemany() and allow retrieving binary data directly by setting
- the resultFormat parameter to one.
-- Support optional "errorhandler" extension.
-- Support optional cursor and connection attribute "messages".
-- Connection as context manager (see http://tinyurl.com/6j9cef).
-- Users should be able to register their own types with _pg.
-- Let pg and pgdb support namedtuples (as available in Py 2.6).
- pg could get a new method namedresult(), and pgdb could provide
- a row factory for namedtuples (similar to sqlite3).
-- New methods in the classic module, similar to getresult() and
- dictresult(), but returning dictionaries of rows instead of lists
- of rows (with primary key or oids as keys).
-- Make PyGreSQL thread-safe on the connection level.
-- The API documentation could be created with Epydoc.
-- Write a tutorial for beginners and advanced use.
-- More and better documented examples.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/index.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/index.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/index.html
deleted file mode 100644
index be2b37c..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/index.html
+++ /dev/null
@@ -1,182 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>PyGreSQL - PostgreSQL module for Python</title>
- <meta http-equiv="Content-Type" content="text/html; CHARSET=iso-8859-1">
- <meta name="description" content="PyGreSQL homepage">
- <meta name="keywords" content="PyGreSQL, Python, PostgreSQL, database, driver, DB-API, pg, pgdb">
- <style type="text/css">
- <!--
- body {
- margin: 8pt;
- padding: 8pt;
- background-color: #f8f8ff;
- color: #000008;
- text-align: justify;
- font-family: Arial, Verdana, Helvetica, sans-serif;
- font-size: 12pt; }
- a {
- text-decoration: none; }
- a:hover {
- text-decoration: underline; }
- h1, h2 {
- color: #006; }
- h1 {
- padding-top: 16pt;
- font-size: 18pt; }
- h2 {
- padding-top: 8pt;
- font-size: 16pt; }
- ul {
- list-style-type: none; }
- ul li {
- margin-top: 4pt;
- font-size: 13pt; }
- ul ul li {
- margin-top: 2pt;
- font-size: 12pt; }
- #title {
- position: absolute;
- top: 0px;
- left: 16px;
- font-size: 36px;
- font-style: italic;
- letter-spacing: 5px;
- color: #666;
- z-index: 600; }
- #version {
- position: absolute;
- top: 42px;
- left: 64px;
- font-size: 11px;
- font-style: italic;
- letter-spacing: 5px;
- color: #000;
- z-index: 610; }
- #banner {
- position: absolute;
- padding-top: 0px;
- padding-bottom: 0px;
- text-align: center;
- top: 27px;
- left: 0px;
- width: 100%;
- height: 30px;
- background: #ccd4e2;
- z-index: 550;
- border-top: 1px #999 solid;
- border-bottom: 1px #999 solid; }
- #bannertext {
- position: absolute;
- text-align: center;
- font-size: 14px;
- font-weight: bold;
- letter-spacing: 4px;
- color: #000066;
- top: 39px;
- right: 5%;
- z-index: 560; }
- #content {
- margin: 36px 20px 2px 20px;
- padding: 4pt 8pt 4pt 16pt;
- border-left: 1px dashed #555;
- border-bottom: 1px dashed #555; }
- #copyright {
- padding-top: 6pt;
- font-size: 10pt;
- color: #333;
- text-align: center; }
- -->
- </style>
-</head>
-
-<body>
-
- <div id="title">PyGreSQL</div>
- <div id="version">Version 4.0</div>
- <div id="banner"></div>
- <div id="bannertext">:: PostgreSQL module for Python ::</div>
-
- <div id="content">
-
- <h1>PyGreSQL – PostgreSQL module for Python</h1>
-
- <p><b>PyGreSQL</b> is an <em>open-source</em>
- <a href="http://www.python.org">Python</a> module
- that interfaces to a <a href="http://www.postgresql.org">PostgreSQL</a> database.
- It embeds the PostgreSQL query library to allow easy use of the powerful PostgreSQL
- features from a Python script.</p>
-
- <p>This software is copyright © 1995, Pascal Andre.<br />
- Further modifications are copyright © 1997-2006 by D'Arcy J.M. Cain.</p>
-
- <p>See the
- <a href="readme.html#copyright-notice">copyright notice</a>
- for detailed information.</p>
-
- <a name="documentation"></a>
- <h2>Documentation</h2>
-
- <p>The following information is also available in the <b>docs</b> folder of the distribution:</p>
-
- <ul>
- <li><a href="readme.html"><b>readme</b> – General Information</a>
- <ul>
- <li><a href="readme.html#copyright-notice">Copyright notice</a></li>
- <li><a href="readme.html#introduction">Introduction</a></li>
- <li><a href="readme.html#where-to-get">Where to get ... ?</a></li>
- <li><a href="readme.html#distribution-files">Distribution files</a></li>
- </ul></li>
- <li><a href="announce.html"><b>announce</b> – Last announcement</a></li>
- <li><a href="install.html"><b>install</b> – Installation</a></li>
- <li><a href="pg.html"><b>pg</b> – The “classic” PyGreSQL interface</a></li>
- <li><a href="pgdb.html"><b>pgdb</b> – The DB-API compliant PyGreSQL interface</a></li>
- <li><a href="changelog.html"><b>changelog</b> – Historical changes</a></li>
- <li><a href="future.html"><b>future</b> – Future directions</a></li>
- </ul>
-
- <a name="cvs"></a>
- <h2>CVS Access</h2>
-
- <p>The
- <a href="http://www.pygresql.org/cvsweb.cgi/pygresql">CVS repository</a>
- is available through
- <a href="http://www.freebsd.org/projects/cvsweb.html">CVSWeb</a>.</p>
-
- <a name="mailinglist"></a>
- <h2>Mailing list</h2>
-
- <p>You can join
- <a href="http://mailman.vex.net/mailman/listinfo/pygresql">the mailing
- list</a> to discuss future development of the PyGreSQL interface.
- This is usually a low volume list except when there are new features
- being added.</p>
-
- <a name="examples"></a>
- <h2>Examples</h2>
-
- <p>I am starting to collect examples of applications that use PyGreSQL.
- So far I only have a few but if you have an example for me, you can
- either send me the files or the URL for me to point to.</p>
-
- <p>Here is a <a href="http://ontario.bikerides.ca">List of motorcycle
- rides in Ontario</a> that uses a PostgreSQL database to store the
- rides. There is a link at the bottom of the page to view the source code.</p>
-
- <p>
- Oleg Broytmann has written a simple example
- <a href="http://phd.pp.ru/Software/Python/#rgb_example">RGB
- database demo</a>.
- </p>
-
- </div>
-
- <div id="copyright">
- Created and maintained by D'Arcy J.M. Cain –
- last update: 17 February 2006.<br />
- If you have any comments, <a href="mailto:darcy@pygresql.org">send mail</a> to me.
- </div>
-
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.html
deleted file mode 100644
index f1e48c0..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.html
+++ /dev/null
@@ -1,198 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL Installation</title>
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-installation">
-<h1 class="title">PyGreSQL Installation</h1>
-<div class="contents topic">
-<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
-<ul class="auto-toc simple">
-<li><a class="reference" href="#general" id="id1" name="id1">1 General</a></li>
-<li><a class="reference" href="#installing-from-a-binary-distribution" id="id2" name="id2">2 Installing from a Binary Distribution</a></li>
-<li><a class="reference" href="#installing-from-source" id="id3" name="id3">3 Installing from Source</a><ul class="auto-toc">
-<li><a class="reference" href="#building-and-installing-with-distutils" id="id4" name="id4">3.1 Building and installing with Distutils</a></li>
-<li><a class="reference" href="#compiling-manually" id="id5" name="id5">3.2 Compiling Manually</a></li>
-<li><a class="reference" href="#stand-alone" id="id6" name="id6">3.3 Stand-Alone</a></li>
-<li><a class="reference" href="#built-in-to-python-interpreter" id="id7" name="id7">3.4 Built-in to Python interpreter</a></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id1" id="general" name="general">1 General</a></h1>
-<p>You must first have installed Python and PostgreSQL on your system.
-If you want to access remote database only, you don't need to install
-the full PostgreSQL server, but only the C interface (libpq). If you
-are on Windows, make sure that the directory with libpq.dll is in your
-<tt class="docutils literal"><span class="pre">PATH</span></tt> environment variable.</p>
-<p>The current version of PyGreSQL has been tested with Python 2.5 and
-PostGreSQL 8.3. Older version should work as well, but you will need
-at least Python 2.3 and PostgreSQL 7.4.</p>
-<p>PyGreSQL will be installed as three modules, a dynamic module called
-_pg.pyd, and two pure Python wrapper modules called pg.py and pgdb.py.
-All three files will be installed directly into the Python site-packages
-directory. To uninstall PyGreSQL, simply remove these three files again.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id2" id="installing-from-a-binary-distribution" name="installing-from-a-binary-distribution">2 Installing from a Binary Distribution</a></h1>
-<p>This is the easiest way to install PyGreSQL.</p>
-<p>You can currently download PyGreSQL as Linux RPM, NetBSD package and Windows
-installer. Make sure the required Python version of the binary package matches
-the Python version you have installed.</p>
-<p>Install the package as usual on your system.</p>
-<p>Note that the documentation is currently only included in the source package.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id3" id="installing-from-source" name="installing-from-source">3 Installing from Source</a></h1>
-<p>If you want to install PyGreSQL from Source, or there is no binary
-package available for your platform, follow these instructions.</p>
-<p>Make sure the Python header files and PostgreSQL client and server header
-files are installed. These come usually with the "devel" packages on Unix
-systems and the installer executables on Windows systems.</p>
-<p>If you are using a precompiled PostgreSQL, you will also need the pg_config
-tool. This is usually also part of the "devel" package on Unix, and will be
-installed as part of the database server feature on Windows systems.</p>
-<div class="section">
-<h2><a class="toc-backref" href="#id4" id="building-and-installing-with-distutils" name="building-and-installing-with-distutils">3.1 Building and installing with Distutils</a></h2>
-<p>You can build and install PyGreSQL using
-<a class="reference" href="http://docs.python.org/install/">Distutils</a>.</p>
-<p>Download and unpack the PyGreSQL source tarball if you haven't already done so.</p>
-<p>Type the following commands to build and install PyGreSQL:</p>
-<pre class="literal-block">
-python setup.py build
-python setup.py install
-</pre>
-<p>If you are using <a class="reference" href="http://www.mingw.org">MinGW</a> to build PyGreSQL under
-Microsoft Windows, please note that Python newer version 2.3 is using msvcr71
-instead of msvcrt as its common runtime library. You can allow for that by
-editing the file <tt class="docutils literal"><span class="pre">%MinGWpath%/lib/gcc/%MinGWversion%/specs</span></tt> and changing
-the entry that reads <tt class="docutils literal"><span class="pre">-lmsvcrt</span></tt> to <tt class="docutils literal"><span class="pre">-lmsvcr71</span></tt>. You may also need to copy
-<tt class="docutils literal"><span class="pre">libpq.lib</span></tt> to <tt class="docutils literal"><span class="pre">libpq.a</span></tt> in the PostgreSQL <tt class="docutils literal"><span class="pre">lib</span></tt> directory. Then use
-the following command to build and install PyGreSQL:</p>
-<pre class="literal-block">
-python setup.py build -c mingw32 install
-</pre>
-<p>Now you should be ready to use PyGreSQL.</p>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id5" id="compiling-manually" name="compiling-manually">3.2 Compiling Manually</a></h2>
-<p>The source file for compiling the dynamic module is called pgmodule.c.
-You have two options. You can compile PyGreSQL as a stand-alone module
-or you can build it into the Python interpreter.</p>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id6" id="stand-alone" name="stand-alone">3.3 Stand-Alone</a></h2>
-<ul>
-<li><p class="first">In the directory containing <tt class="docutils literal"><span class="pre">pgmodule.c</span></tt>, run the following command:</p>
-<pre class="literal-block">
-cc -fpic -shared -o _pg.so -I$PYINC -I$PGINC -I$PSINC -L$PGLIB -lpq pgmodule.c
-</pre>
-<p>where you have to set:</p>
-<pre class="literal-block">
-PYINC = path to the Python include files
- (usually something like /usr/include/python)
-PGINC = path to the PostgreSQL client include files
- (something like /usr/include/pgsql or /usr/include/postgresql)
-PSINC = path to the PostgreSQL server include files
- (like /usr/include/pgsql/server or /usr/include/postgresql/server)
-PGLIB = path to the PostgreSQL object code libraries (usually /usr/lib)
-</pre>
-<p>If you are not sure about the above paths, try something like:</p>
-<pre class="literal-block">
-PYINC=`find /usr -name Python.h`
-PGINC=`find /usr -name libpq-fe.h`
-PSINC=`find /usr -name postgres.h`
-PGLIB=`find /usr -name libpq.so`
-</pre>
-<p>If you have the <tt class="docutils literal"><span class="pre">pg_config</span></tt> tool installed, you can set:</p>
-<pre class="literal-block">
-PGINC=`pg_config --includedir`
-PSINC=`pg_config --includedir-server`
-PGLIB=`pg_config --libdir`
-</pre>
-<p>Some options may be added to this line:</p>
-<pre class="literal-block">
--DNO_DEF_VAR no default variables support
--DNO_DIRECT no direct access methods
--DNO_LARGE no large object support
--DNO_PQSOCKET if running an older PostgreSQL
-</pre>
-<p>Define <tt class="docutils literal"><span class="pre">NO_PQSOCKET</span></tt> if you are using a version of PostgreSQL before 6.4
-that does not have the PQsocket function. The other options will be
-described in the next sections.</p>
-<p>On some systems you may need to include <tt class="docutils literal"><span class="pre">-lcrypt</span></tt> in the list of libraries
-to make it compile.</p>
-</li>
-<li><p class="first">Test the new module. Something like the following should work:</p>
-<pre class="literal-block">
-$ python
-
->>> import _pg
->>> db = _pg.connect('thilo','localhost')
->>> db.query("INSERT INTO test VALUES ('ping','pong')")
-18304
->>> db.query("SELECT * FROM test")
-eins|zwei
-----+----
-ping|pong
-(1 row)
-</pre>
-</li>
-<li><p class="first">Finally, move the <tt class="docutils literal"><span class="pre">_pg.so</span></tt>, <tt class="docutils literal"><span class="pre">pg.py</span></tt>, and <tt class="docutils literal"><span class="pre">pgdb.py</span></tt> to a directory in
-your <tt class="docutils literal"><span class="pre">PYTHONPATH</span></tt>. A good place would be <tt class="docutils literal"><span class="pre">/usr/lib/python/site-packages</span></tt>
-if your Python modules are in <tt class="docutils literal"><span class="pre">/usr/lib/python</span></tt>.</p>
-</li>
-</ul>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id7" id="built-in-to-python-interpreter" name="built-in-to-python-interpreter">3.4 Built-in to Python interpreter</a></h2>
-<ul>
-<li><p class="first">Find the directory where your <tt class="docutils literal"><span class="pre">Setup</span></tt> file lives (usually in the <tt class="docutils literal"><span class="pre">Modules</span></tt>
-subdirectory) in the Python source hierarchy and copy or symlink the
-<tt class="docutils literal"><span class="pre">pgmodule.c</span></tt> file there.</p>
-</li>
-<li><p class="first">Add the following line to your 'Setup' file:</p>
-<pre class="literal-block">
-_pg pgmodule.c -I$PGINC -I$PSINC -L$PGLIB -lpq
-</pre>
-<p>where:</p>
-<pre class="literal-block">
-PGINC = path to the PostgreSQL client include files (see above)
-PSINC = path to the PostgreSQL server include files (see above)
-PGLIB = path to the PostgreSQL object code libraries (see above)
-</pre>
-<p>Some options may be added to this line:</p>
-<pre class="literal-block">
--DNO_DEF_VAR no default variables support
--DNO_DIRECT no direct access methods
--DNO_LARGE no large object support
--DNO_PQSOCKET if running an older PostgreSQL (see above)
-</pre>
-<p>On some systems you may need to include <tt class="docutils literal"><span class="pre">-lcrypt</span></tt> in the list of libraries
-to make it compile.</p>
-</li>
-<li><p class="first">If you want a shared module, make sure that the <tt class="docutils literal"><span class="pre">shared</span></tt> keyword is
-uncommented and add the above line below it. You used to need to install
-your shared modules with <tt class="docutils literal"><span class="pre">make</span> <span class="pre">sharedinstall</span></tt> but this no longer seems
-to be true.</p>
-</li>
-<li><p class="first">Copy <tt class="docutils literal"><span class="pre">pg.py</span></tt> to the lib directory where the rest of your modules are.
-For example, that's <tt class="docutils literal"><span class="pre">/usr/local/lib/Python</span></tt> on my system.</p>
-</li>
-<li><p class="first">Rebuild Python from the root directory of the Python source hierarchy by
-running <tt class="docutils literal"><span class="pre">make</span> <span class="pre">-f</span> <span class="pre">Makefile.pre.in</span> <span class="pre">boot</span></tt> and <tt class="docutils literal"><span class="pre">make</span> <span class="pre">&&</span> <span class="pre">make</span> <span class="pre">install</span></tt>.</p>
-</li>
-<li><p class="first">For more details read the documentation at the top of <tt class="docutils literal"><span class="pre">Makefile.pre.in</span></tt>.</p>
-</li>
-</ul>
-</div>
-</div>
-</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.txt
deleted file mode 100644
index 3f19a2c..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/install.txt
+++ /dev/null
@@ -1,188 +0,0 @@
-=====================
-PyGreSQL Installation
-=====================
-
-.. sectnum::
-.. contents:: Contents
-
-
-General
-=======
-
-You must first have installed Python and PostgreSQL on your system.
-If you want to access remote database only, you don't need to install
-the full PostgreSQL server, but only the C interface (libpq). If you
-are on Windows, make sure that the directory with libpq.dll is in your
-``PATH`` environment variable.
-
-The current version of PyGreSQL has been tested with Python 2.5 and
-PostGreSQL 8.3. Older version should work as well, but you will need
-at least Python 2.3 and PostgreSQL 7.4.
-
-PyGreSQL will be installed as three modules, a dynamic module called
-_pg.pyd, and two pure Python wrapper modules called pg.py and pgdb.py.
-All three files will be installed directly into the Python site-packages
-directory. To uninstall PyGreSQL, simply remove these three files again.
-
-
-Installing from a Binary Distribution
-=====================================
-
-This is the easiest way to install PyGreSQL.
-
-You can currently download PyGreSQL as Linux RPM, NetBSD package and Windows
-installer. Make sure the required Python version of the binary package matches
-the Python version you have installed.
-
-Install the package as usual on your system.
-
-Note that the documentation is currently only included in the source package.
-
-
-Installing from Source
-======================
-
-If you want to install PyGreSQL from Source, or there is no binary
-package available for your platform, follow these instructions.
-
-Make sure the Python header files and PostgreSQL client and server header
-files are installed. These come usually with the "devel" packages on Unix
-systems and the installer executables on Windows systems.
-
-If you are using a precompiled PostgreSQL, you will also need the pg_config
-tool. This is usually also part of the "devel" package on Unix, and will be
-installed as part of the database server feature on Windows systems.
-
-Building and installing with Distutils
---------------------------------------
-
-You can build and install PyGreSQL using
-`Distutils <http://docs.python.org/install/>`_.
-
-Download and unpack the PyGreSQL source tarball if you haven't already done so.
-
-Type the following commands to build and install PyGreSQL::
-
- python setup.py build
- python setup.py install
-
-If you are using `MinGW <http://www.mingw.org>`_ to build PyGreSQL under
-Microsoft Windows, please note that Python newer version 2.3 is using msvcr71
-instead of msvcrt as its common runtime library. You can allow for that by
-editing the file ``%MinGWpath%/lib/gcc/%MinGWversion%/specs`` and changing
-the entry that reads ``-lmsvcrt`` to ``-lmsvcr71``. You may also need to copy
-``libpq.lib`` to ``libpq.a`` in the PostgreSQL ``lib`` directory. Then use
-the following command to build and install PyGreSQL::
-
- python setup.py build -c mingw32 install
-
-Now you should be ready to use PyGreSQL.
-
-Compiling Manually
-------------------
-
-The source file for compiling the dynamic module is called pgmodule.c.
-You have two options. You can compile PyGreSQL as a stand-alone module
-or you can build it into the Python interpreter.
-
-Stand-Alone
------------
-
-* In the directory containing ``pgmodule.c``, run the following command::
-
- cc -fpic -shared -o _pg.so -I$PYINC -I$PGINC -I$PSINC -L$PGLIB -lpq pgmodule.c
-
- where you have to set::
-
- PYINC = path to the Python include files
- (usually something like /usr/include/python)
- PGINC = path to the PostgreSQL client include files
- (something like /usr/include/pgsql or /usr/include/postgresql)
- PSINC = path to the PostgreSQL server include files
- (like /usr/include/pgsql/server or /usr/include/postgresql/server)
- PGLIB = path to the PostgreSQL object code libraries (usually /usr/lib)
-
- If you are not sure about the above paths, try something like::
-
- PYINC=`find /usr -name Python.h`
- PGINC=`find /usr -name libpq-fe.h`
- PSINC=`find /usr -name postgres.h`
- PGLIB=`find /usr -name libpq.so`
-
- If you have the ``pg_config`` tool installed, you can set::
-
- PGINC=`pg_config --includedir`
- PSINC=`pg_config --includedir-server`
- PGLIB=`pg_config --libdir`
-
- Some options may be added to this line::
-
- -DNO_DEF_VAR no default variables support
- -DNO_DIRECT no direct access methods
- -DNO_LARGE no large object support
- -DNO_PQSOCKET if running an older PostgreSQL
-
- Define ``NO_PQSOCKET`` if you are using a version of PostgreSQL before 6.4
- that does not have the PQsocket function. The other options will be
- described in the next sections.
-
- On some systems you may need to include ``-lcrypt`` in the list of libraries
- to make it compile.
-
-* Test the new module. Something like the following should work::
-
- $ python
-
- >>> import _pg
- >>> db = _pg.connect('thilo','localhost')
- >>> db.query("INSERT INTO test VALUES ('ping','pong')")
- 18304
- >>> db.query("SELECT * FROM test")
- eins|zwei
- ----+----
- ping|pong
- (1 row)
-
-* Finally, move the ``_pg.so``, ``pg.py``, and ``pgdb.py`` to a directory in
- your ``PYTHONPATH``. A good place would be ``/usr/lib/python/site-packages``
- if your Python modules are in ``/usr/lib/python``.
-
-Built-in to Python interpreter
-------------------------------
-
-* Find the directory where your ``Setup`` file lives (usually in the ``Modules``
- subdirectory) in the Python source hierarchy and copy or symlink the
- ``pgmodule.c`` file there.
-
-* Add the following line to your 'Setup' file::
-
- _pg pgmodule.c -I$PGINC -I$PSINC -L$PGLIB -lpq
-
- where::
-
- PGINC = path to the PostgreSQL client include files (see above)
- PSINC = path to the PostgreSQL server include files (see above)
- PGLIB = path to the PostgreSQL object code libraries (see above)
-
- Some options may be added to this line::
-
- -DNO_DEF_VAR no default variables support
- -DNO_DIRECT no direct access methods
- -DNO_LARGE no large object support
- -DNO_PQSOCKET if running an older PostgreSQL (see above)
-
- On some systems you may need to include ``-lcrypt`` in the list of libraries
- to make it compile.
-
-* If you want a shared module, make sure that the ``shared`` keyword is
- uncommented and add the above line below it. You used to need to install
- your shared modules with ``make sharedinstall`` but this no longer seems
- to be true.
-
-* Copy ``pg.py`` to the lib directory where the rest of your modules are.
- For example, that's ``/usr/local/lib/Python`` on my system.
-
-* Rebuild Python from the root directory of the Python source hierarchy by
- running ``make -f Makefile.pre.in boot`` and ``make && make install``.
-
-* For more details read the documentation at the top of ``Makefile.pre.in``.
[13/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
HAWQ-271. Remove external python modules.
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/0672292f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/0672292f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/0672292f
Branch: refs/heads/master
Commit: 0672292f31196287be9538b5fb9420ec854f3d5f
Parents: 7e0ff41
Author: rlei <rl...@pivotal.io>
Authored: Wed Jan 6 10:20:14 2016 +0800
Committer: rlei <rl...@pivotal.io>
Committed: Wed Jan 6 16:19:21 2016 +0800
----------------------------------------------------------------------
tools/bin/Makefile | 126 +-
tools/bin/ext/Makefile | 27 -
tools/bin/ext/__init__.py | 306 --
tools/bin/ext/figleaf/__init__.py | 325 --
tools/bin/ext/figleaf/_lib.py | 22 -
tools/bin/ext/figleaf/annotate.py | 241 --
tools/bin/ext/figleaf/annotate_cover.py | 159 -
tools/bin/ext/figleaf/annotate_html.py | 292 --
tools/bin/ext/figleaf/annotate_sections.py | 95 -
tools/bin/ext/figleaf/figleaf2html | 7 -
tools/bin/ext/figleaf/internals.py | 257 --
tools/bin/ext/figleaf/nose_sections.py | 133 -
tools/bin/ext/pg8000/__init__.py | 37 -
tools/bin/ext/pg8000/dbapi.py | 621 ---
tools/bin/ext/pg8000/errors.py | 115 -
tools/bin/ext/pg8000/interface.py | 542 ---
tools/bin/ext/pg8000/protocol.py | 1340 -------
tools/bin/ext/pg8000/types.py | 687 ----
tools/bin/ext/pg8000/util.py | 20 -
tools/bin/ext/pygresql/__init__.py | 0
tools/bin/ext/simplejson/__init__.py | 303 --
tools/bin/ext/simplejson/_speedups.c | 234 --
tools/bin/ext/simplejson/decoder.py | 289 --
tools/bin/ext/simplejson/encoder.py | 387 --
tools/bin/ext/simplejson/jsonfilter.py | 56 -
tools/bin/ext/simplejson/scanner.py | 79 -
tools/bin/ext/simplejson/tests/__init__.py | 0
tools/bin/ext/simplejson/tests/test_attacks.py | 22 -
tools/bin/ext/simplejson/tests/test_dump.py | 26 -
tools/bin/ext/simplejson/tests/test_fail.py | 86 -
tools/bin/ext/simplejson/tests/test_float.py | 20 -
tools/bin/ext/simplejson/tests/test_indent.py | 57 -
tools/bin/ext/simplejson/tests/test_pass1.py | 88 -
tools/bin/ext/simplejson/tests/test_pass2.py | 27 -
tools/bin/ext/simplejson/tests/test_pass3.py | 32 -
.../bin/ext/simplejson/tests/test_recursion.py | 78 -
.../bin/ext/simplejson/tests/test_separators.py | 57 -
tools/bin/ext/simplejson/tests/test_unicode.py | 32 -
tools/bin/ext/yaml/__init__.py | 306 --
tools/bin/ext/yaml/composer.py | 134 -
tools/bin/ext/yaml/constructor.py | 691 ----
tools/bin/ext/yaml/cyaml.py | 101 -
tools/bin/ext/yaml/dumper.py | 78 -
tools/bin/ext/yaml/emitter.py | 1179 ------
tools/bin/ext/yaml/error.py | 91 -
tools/bin/ext/yaml/events.py | 102 -
tools/bin/ext/yaml/loader.py | 56 -
tools/bin/ext/yaml/nodes.py | 65 -
tools/bin/ext/yaml/parser.py | 602 ---
tools/bin/ext/yaml/reader.py | 241 --
tools/bin/ext/yaml/representer.py | 504 ---
tools/bin/ext/yaml/resolver.py | 239 --
tools/bin/ext/yaml/scanner.py | 1472 -------
tools/bin/ext/yaml/serializer.py | 127 -
tools/bin/ext/yaml/tokens.py | 120 -
tools/bin/generate-greenplum-path.sh | 2 +-
tools/bin/gpcheck | 4 +-
tools/bin/gpextract | 4 +-
tools/bin/gpload.py | 2 +-
tools/bin/gppylib/commands/base.py | 10 +-
tools/bin/gppylib/db/dbconn.py | 2 +-
tools/bin/gppylib/operations/gpMigratorUtil.py | 2 +-
.../bin/gppylib/operations/test_utils_helper.py | 2 +-
.../test/regress/test_regress_pygresql.py | 4 +-
tools/bin/hawq_ctl | 2 +-
tools/bin/hawqconfig | 2 +-
tools/bin/hawqextract | 4 +-
tools/bin/hawqfilespace | 2 +-
tools/bin/hawqstate | 2 +-
tools/bin/lib/gpcheckcat | 4 +-
tools/bin/pythonSrc/.gitignore | 8 -
tools/bin/pythonSrc/PSI-0.3b2_gp.tar.gz | Bin 93810 -> 0 bytes
.../pythonSrc/PyGreSQL-4.0/docs/announce.html | 28 -
.../pythonSrc/PyGreSQL-4.0/docs/announce.txt | 23 -
.../pythonSrc/PyGreSQL-4.0/docs/changelog.html | 333 --
.../pythonSrc/PyGreSQL-4.0/docs/changelog.txt | 285 --
.../bin/pythonSrc/PyGreSQL-4.0/docs/default.css | 279 --
tools/bin/pythonSrc/PyGreSQL-4.0/docs/docs.css | 109 -
.../bin/pythonSrc/PyGreSQL-4.0/docs/future.html | 62 -
.../bin/pythonSrc/PyGreSQL-4.0/docs/future.txt | 48 -
.../bin/pythonSrc/PyGreSQL-4.0/docs/index.html | 182 -
.../pythonSrc/PyGreSQL-4.0/docs/install.html | 198 -
.../bin/pythonSrc/PyGreSQL-4.0/docs/install.txt | 188 -
tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.html | 2429 -----------
tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.txt | 1382 -------
tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.html | 51 -
tools/bin/pythonSrc/PyGreSQL-4.0/docs/pgdb.txt | 42 -
.../bin/pythonSrc/PyGreSQL-4.0/docs/readme.html | 243 --
.../bin/pythonSrc/PyGreSQL-4.0/docs/readme.txt | 206 -
tools/bin/pythonSrc/PyGreSQL-4.0/pg.py | 711 ----
tools/bin/pythonSrc/PyGreSQL-4.0/pgdb.py | 582 ---
tools/bin/pythonSrc/PyGreSQL-4.0/pgmodule.c | 3756 ------------------
tools/bin/pythonSrc/PyGreSQL-4.0/setup.py | 152 -
.../pythonSrc/PyGreSQL-4.0/tutorial/advanced.py | 198 -
.../pythonSrc/PyGreSQL-4.0/tutorial/basics.py | 296 --
.../bin/pythonSrc/PyGreSQL-4.0/tutorial/func.py | 205 -
.../pythonSrc/PyGreSQL-4.0/tutorial/syscat.py | 149 -
tools/bin/pythonSrc/epydoc-3.0.1.tar.gz | Bin 1845788 -> 0 bytes
tools/bin/pythonSrc/lockfile-0.9.1.tar.gz | Bin 16949 -> 0 bytes
tools/bin/pythonSrc/logilab-astng-0.20.1.tar.gz | Bin 103800 -> 0 bytes
.../bin/pythonSrc/logilab-common-0.50.1.tar.gz | Bin 164975 -> 0 bytes
tools/bin/pythonSrc/paramiko-1.7.6-9.tar.gz | Bin 212556 -> 0 bytes
tools/bin/pythonSrc/pychecker-0.8.18.tar.gz | Bin 145805 -> 0 bytes
tools/bin/pythonSrc/pycrypto-2.0.1.tar.gz | Bin 157389 -> 0 bytes
tools/bin/pythonSrc/pylint-0.21.0.tar.gz | Bin 199212 -> 0 bytes
tools/bin/pythonSrc/unittest2-0.5.1.tar.gz | Bin 62470 -> 0 bytes
106 files changed, 29 insertions(+), 25497 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/Makefile
----------------------------------------------------------------------
diff --git a/tools/bin/Makefile b/tools/bin/Makefile
index 88b9634..7d6423c 100644
--- a/tools/bin/Makefile
+++ b/tools/bin/Makefile
@@ -36,7 +36,7 @@ PYLIB_SRC=$(SRC)/pythonSrc
LIB_DIR=$(SRC)/lib
PYLIB_DIR=$(SRC)/ext
-all: lockfile paramiko pycrypto pygresql stream pychecker psi unittest2
+all: stream
#
# Python Libraries
@@ -44,13 +44,6 @@ all: lockfile paramiko pycrypto pygresql stream pychecker psi unittest2
NETPERF_DIR=netperf-2.4.3
-netperf:
- @echo "--- netperf"
- if [ ! -f $(SRC)/src/$(NETPERF_DIR)/Makefile ]; then \
- (cd $(SRC)/src && gzip -d -c $(NETPERF_DIR).tar.gz | tar xvf - && cd $(NETPERF_DIR) && CC="$(CC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure) \
- fi
- cd $(SRC)/src/$(NETPERF_DIR) && $(MAKE)
- cp $(SRC)/src/$(NETPERF_DIR)/src/netperf $(SRC)/src/$(NETPERF_DIR)/src/netserver lib/
#
# STREAM
@@ -61,120 +54,6 @@ stream:
cd $(STREAM_DIR) && NO_M64=TRUE $(CC) $(CFLAGS) stream.c -o stream
cp $(STREAM_DIR)/stream lib/stream
-#
-# PyGreSQL
-#
-PYGRESQL_VERSION=4.0
-PYGRESQL_DIR=PyGreSQL-$(PYGRESQL_VERSION)
-
-pygresql:
- @echo "--- PyGreSQL"
- cd $(PYLIB_SRC)/$(PYGRESQL_DIR) && CC="$(CC)" CFLAGS="${CFLAGS}" LDFLAGS="-L$(top_builddir)/src/interfaces/libpq ${LDFLAGS}" python setup.py build
- mkdir -p $(PYLIB_DIR)/pygresql
- cp -r $(PYLIB_SRC)/$(PYGRESQL_DIR)/build/lib.*/* $(PYLIB_DIR)/pygresql
- touch $(PYLIB_DIR)/__init__.py
-
-#
-# PARAMIKO
-#
-PARAMIKO_VERSION=1.7.6-9
-PARAMIKO_DIR=paramiko-$(PARAMIKO_VERSION)
-paramiko:
- @echo "--- paramiko"
- cd $(PYLIB_SRC)/ && $(TAR) xzf $(PARAMIKO_DIR).tar.gz
- cd $(PYLIB_SRC)/$(PARAMIKO_DIR)/ && python setup.py build
- cp -r $(PYLIB_SRC)/$(PARAMIKO_DIR)/build/lib/paramiko $(PYLIB_DIR)/
-
-#
-# LOCKFILE
-#
-# note the awk commands are used to eliminate references to code in __init__.py
-# that we don't use and also to insert a comment to tell pylint not to complain
-# about these files since we are not in a position to correct those warnings.
-#
-LOCKFILE_VERSION=0.9.1
-LOCKFILE_DIR=lockfile-$(LOCKFILE_VERSION)
-LOCKFILE_SRC=$(PYLIB_SRC)/$(LOCKFILE_DIR)/build/lib/lockfile
-LOCKFILE_DST=$(PYLIB_DIR)/lockfile
-lockfile:
- @echo "--- lockfile"
- cd $(PYLIB_SRC)/ && $(TAR) xzf $(LOCKFILE_DIR).tar.gz
- cd $(PYLIB_SRC)/$(LOCKFILE_DIR)/ && python setup.py build
- mkdir -p $(PYLIB_DIR)/lockfile
- awk 'BEGIN{print "# pylint: disable-all"} /^if hasattr/ {exit} { print }' < $(LOCKFILE_SRC)/__init__.py > $(LOCKFILE_DST)/__init__.py
- awk 'BEGIN{print "# pylint: disable-all"} { print }' < $(LOCKFILE_SRC)/pidlockfile.py > $(LOCKFILE_DST)/pidlockfile.py
-
-#
-# PYCRYPTO
-#
-PYCRYPTO_VERSION=2.0.1
-PYCRYPTO_DIR=pycrypto-$(PYCRYPTO_VERSION)
-
-pycrypto:
- @echo "--- pycrypto"
- cd $(PYLIB_SRC)/ && $(TAR) xzf $(PYCRYPTO_DIR).tar.gz
- cd $(PYLIB_SRC)/$(PYCRYPTO_DIR)/ && CC="$(CC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" python setup.py build
- cp -r $(PYLIB_SRC)/$(PYCRYPTO_DIR)/build/lib.*/Crypto $(PYLIB_DIR)
-
-#
-# PSI
-#
-PSI_VERSION=0.3b2_gp
-PSI_DIR=PSI-$(PSI_VERSION)
-
-psi:
- @echo "--- psi"
- cd $(PYLIB_SRC)/ && $(TAR) xzf $(PSI_DIR).tar.gz
- cd $(PYLIB_SRC)/$(PSI_DIR)/ && CC="$(CC)" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" python setup.py build
- cp -r $(PYLIB_SRC)/$(PSI_DIR)/build/lib.*/psi $(PYLIB_DIR)
-
-
-#
-# PYCHECKER
-#
-PYCHECKER_VERSION=0.8.18
-PYCHECKER_DIR=pychecker-$(PYCHECKER_VERSION)
-
-pychecker:
- @echo "--- pychecker"
- cd $(PYLIB_SRC)/ && $(TAR) xzf $(PYCHECKER_DIR).tar.gz
- cd $(PYLIB_SRC)/$(PYCHECKER_DIR)/ && python setup.py build
- cp -r $(PYLIB_SRC)/$(PYCHECKER_DIR)/build/lib/pychecker $(PYLIB_DIR)/
-
-
-#
-# PYLINT
-#
-
-PYLINT_VERSION=0.21.0
-PYLINT_DIR=pylint-$(PYLINT_VERSION)
-LOGILAB_ASTNG_VERSION=0.20.1
-LOGILAB_ASTNG_DIR=logilab-astng-$(LOGILAB_ASTNG_VERSION)
-LOGILAB_COMMON_VERSION=0.50.1
-LOGILAB_COMMON_DIR=logilab-common-$(LOGILAB_COMMON_VERSION)
-PYLINT_PYTHONPATH=$(PYLIB_DIR):$(PYLIB_SRC)/$(PYLINT_DIR)/build/lib/
-
-pylint:
- @echo "--- pylint"
- @cd $(PYLIB_SRC)/ && $(TAR) xzf $(PYLINT_DIR).tar.gz
- @cd $(PYLIB_SRC)/ && $(TAR) xzf $(LOGILAB_ASTNG_DIR).tar.gz
- @cd $(PYLIB_SRC)/ && $(TAR) xzf $(LOGILAB_COMMON_DIR).tar.gz
- @cd $(PYLIB_SRC)/$(PYLINT_DIR)/ && python setup.py build 1> /dev/null
- @cd $(PYLIB_SRC)/$(LOGILAB_ASTNG_DIR)/ && python setup.py build 1> /dev/null
- @cd $(PYLIB_SRC)/$(LOGILAB_COMMON_DIR)/ && python setup.py build 1> /dev/null
- @cp -r $(PYLIB_SRC)/$(LOGILAB_COMMON_DIR)/build/lib/logilab $(PYLIB_SRC)/$(PYLINT_DIR)/build/lib/
- @cp -r $(PYLIB_SRC)/$(LOGILAB_ASTNG_DIR)/build/lib/logilab $(PYLIB_SRC)/$(PYLINT_DIR)/build/lib/
- @touch $(PYLIB_SRC)/$(PYLINT_DIR)/build/lib/__init__.py
- @touch $(PYLIB_SRC)/$(PYLINT_DIR)/build/lib/logilab/__init__.py
-
-UNITTEST2_VERSION=0.5.1
-UNITTEST2_DIR=unittest2-${UNITTEST2_VERSION}
-unittest2:
- @echo "--- unittest2"
- cd $(PYLIB_SRC)/ && $(TAR) xzf $(UNITTEST2_DIR).tar.gz
- cd $(PYLIB_SRC)/$(UNITTEST2_DIR)/ && python setup.py build
- cp -r $(PYLIB_SRC)/$(UNITTEST2_DIR)/build/lib/unittest2 $(PYLIB_DIR)/
-
PYTHON_FILES=`grep -l --exclude=Makefile --exclude=gplogfilter --exclude=gpcheckos --exclude=gpgenfsmap.py --exclude=throttlingD.py "/bin/env python" *`\
`grep -l "/bin/env python" $(SRC)/../sbin/*`\
@@ -246,9 +125,6 @@ install: all
for files in `find * -maxdepth 0 -type f | grep -x -v -E "${SKIP_INSTALL}"`; do ${INSTALL_SCRIPT} $${files} ${bindir}; done
${MAKE} -C gppylib $@
${MAKE} -C hawqpylib $@
- ${MAKE} -C ext $@
- # for dirs in `find hawqpylib -type d` ; do ${INSTALL_SCRIPT} -d ${bindir}/hawqpylib/$${dirs}; done
- # for files in `find hawqpylib -type f` ; do ${INSTALL_SCRIPT} $${files} ${bindir}/hawqpylib/; done
${INSTALL_SCRIPT} -d ${bindir}/lib
for files in `find lib -type f`; do ${INSTALL_SCRIPT} $${files} ${bindir}/lib; done
unset LIBPATH; ./generate-greenplum-path.sh $(prefix) > ${prefix}/greenplum_path.sh
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/Makefile
----------------------------------------------------------------------
diff --git a/tools/bin/ext/Makefile b/tools/bin/ext/Makefile
deleted file mode 100644
index ba49f09..0000000
--- a/tools/bin/ext/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-#-------------------------------------------------------------------------
-#
-# Makefile for the managerment utilities
-#
-#-------------------------------------------------------------------------
-
-subdir = tools/bin/ext
-top_builddir = ../../..
-include $(top_builddir)/src/Makefile.global
-
-SKIP_INSTALL=.gitignore|.p4ignore|.rcfile|Makefile|test/
-
-install:
- ${INSTALL_SCRIPT} -d ${libdir}/python/
- @for file in `find * -type f | grep -v -E "${SKIP_INSTALL}"`; \
- do \
- echo "install $${file} into ${libdir}/python/$${file}" ; \
- ${INSTALL_SCRIPT} $${file} ${libdir}/python/$${file}; \
- done
- @for dirs in `find * -type d | grep -v test` ;\
- do \
- ${INSTALL_SCRIPT} -d ${libdir}/python/$${dirs}; \
- for file in `find $${dirs} -type f | grep -v -E "${SKIP_INSTALL}"`; do \
- echo "install $${file} into ${libdir}/python/$${file}" ; \
- ${INSTALL_SCRIPT} $${file} ${libdir}/python/$${file}; \
- done \
- done
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/__init__.py b/tools/bin/ext/__init__.py
deleted file mode 100644
index b6c84f9..0000000
--- a/tools/bin/ext/__init__.py
+++ /dev/null
@@ -1,306 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-from error import *
-
-from tokens import *
-from events import *
-from nodes import *
-
-from loader import *
-from dumper import *
-
-try:
- from cyaml import *
-except ImportError:
- pass
-
-def scan(stream, Loader=Loader):
- """
- Scan a YAML stream and produce scanning tokens.
- """
- loader = Loader(stream)
- while loader.check_token():
- yield loader.get_token()
-
-def parse(stream, Loader=Loader):
- """
- Parse a YAML stream and produce parsing events.
- """
- loader = Loader(stream)
- while loader.check_event():
- yield loader.get_event()
-
-def compose(stream, Loader=Loader):
- """
- Parse the first YAML document in a stream
- and produce the corresponding representation tree.
- """
- loader = Loader(stream)
- if loader.check_node():
- return loader.get_node()
-
-def compose_all(stream, Loader=Loader):
- """
- Parse all YAML documents in a stream
- and produce corresponsing representation trees.
- """
- loader = Loader(stream)
- while loader.check_node():
- yield loader.get_node()
-
-def load_all(stream, Loader=Loader):
- """
- Parse all YAML documents in a stream
- and produce corresponding Python objects.
- """
- loader = Loader(stream)
- while loader.check_data():
- yield loader.get_data()
-
-def load(stream, Loader=Loader):
- """
- Parse the first YAML document in a stream
- and produce the corresponding Python object.
- """
- loader = Loader(stream)
- if loader.check_data():
- return loader.get_data()
-
-def safe_load_all(stream):
- """
- Parse all YAML documents in a stream
- and produce corresponding Python objects.
- Resolve only basic YAML tags.
- """
- return load_all(stream, SafeLoader)
-
-def safe_load(stream):
- """
- Parse the first YAML document in a stream
- and produce the corresponding Python object.
- Resolve only basic YAML tags.
- """
- return load(stream, SafeLoader)
-
-def emit(events, stream=None, Dumper=Dumper,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None):
- """
- Emit YAML parsing events into a stream.
- If stream is None, return the produced string instead.
- """
- getvalue = None
- if stream is None:
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- stream = StringIO()
- getvalue = stream.getvalue
- dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break)
- for event in events:
- dumper.emit(event)
- if getvalue:
- return getvalue()
-
-def serialize_all(nodes, stream=None, Dumper=Dumper,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding='utf-8', explicit_start=None, explicit_end=None,
- version=None, tags=None):
- """
- Serialize a sequence of representation trees into a YAML stream.
- If stream is None, return the produced string instead.
- """
- getvalue = None
- if stream is None:
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- stream = StringIO()
- getvalue = stream.getvalue
- dumper = Dumper(stream, canonical=canonical, indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- encoding=encoding, version=version, tags=tags,
- explicit_start=explicit_start, explicit_end=explicit_end)
- dumper.open()
- for node in nodes:
- dumper.serialize(node)
- dumper.close()
- if getvalue:
- return getvalue()
-
-def serialize(node, stream=None, Dumper=Dumper, **kwds):
- """
- Serialize a representation tree into a YAML stream.
- If stream is None, return the produced string instead.
- """
- return serialize_all([node], stream, Dumper=Dumper, **kwds)
-
-def dump_all(documents, stream=None, Dumper=Dumper,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding='utf-8', explicit_start=None, explicit_end=None,
- version=None, tags=None):
- """
- Serialize a sequence of Python objects into a YAML stream.
- If stream is None, return the produced string instead.
- """
- getvalue = None
- if stream is None:
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- stream = StringIO()
- getvalue = stream.getvalue
- dumper = Dumper(stream, default_style=default_style,
- default_flow_style=default_flow_style,
- canonical=canonical, indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- encoding=encoding, version=version, tags=tags,
- explicit_start=explicit_start, explicit_end=explicit_end)
- dumper.open()
- for data in documents:
- dumper.represent(data)
- dumper.close()
- if getvalue:
- return getvalue()
-
-def dump(data, stream=None, Dumper=Dumper, **kwds):
- """
- Serialize a Python object into a YAML stream.
- If stream is None, return the produced string instead.
- """
- return dump_all([data], stream, Dumper=Dumper, **kwds)
-
-def safe_dump_all(documents, stream=None, **kwds):
- """
- Serialize a sequence of Python objects into a YAML stream.
- Produce only basic YAML tags.
- If stream is None, return the produced string instead.
- """
- return dump_all(documents, stream, Dumper=SafeDumper, **kwds)
-
-def safe_dump(data, stream=None, **kwds):
- """
- Serialize a Python object into a YAML stream.
- Produce only basic YAML tags.
- If stream is None, return the produced string instead.
- """
- return dump_all([data], stream, Dumper=SafeDumper, **kwds)
-
-def add_implicit_resolver(tag, regexp, first=None,
- Loader=Loader, Dumper=Dumper):
- """
- Add an implicit scalar detector.
- If an implicit scalar value matches the given regexp,
- the corresponding tag is assigned to the scalar.
- first is a sequence of possible initial characters or None.
- """
- Loader.add_implicit_resolver(tag, regexp, first)
- Dumper.add_implicit_resolver(tag, regexp, first)
-
-def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper):
- """
- Add a path based resolver for the given tag.
- A path is a list of keys that forms a path
- to a node in the representation tree.
- Keys can be string values, integers, or None.
- """
- Loader.add_path_resolver(tag, path, kind)
- Dumper.add_path_resolver(tag, path, kind)
-
-def add_constructor(tag, constructor, Loader=Loader):
- """
- Add a constructor for the given tag.
- Constructor is a function that accepts a Loader instance
- and a node object and produces the corresponding Python object.
- """
- Loader.add_constructor(tag, constructor)
-
-def add_multi_constructor(tag_prefix, multi_constructor, Loader=Loader):
- """
- Add a multi-constructor for the given tag prefix.
- Multi-constructor is called for a node if its tag starts with tag_prefix.
- Multi-constructor accepts a Loader instance, a tag suffix,
- and a node object and produces the corresponding Python object.
- """
- Loader.add_multi_constructor(tag_prefix, multi_constructor)
-
-def add_representer(data_type, representer, Dumper=Dumper):
- """
- Add a representer for the given type.
- Representer is a function accepting a Dumper instance
- and an instance of the given data type
- and producing the corresponding representation node.
- """
- Dumper.add_representer(data_type, representer)
-
-def add_multi_representer(data_type, multi_representer, Dumper=Dumper):
- """
- Add a representer for the given type.
- Multi-representer is a function accepting a Dumper instance
- and an instance of the given data type or subtype
- and producing the corresponding representation node.
- """
- Dumper.add_multi_representer(data_type, multi_representer)
-
-class YAMLObjectMetaclass(type):
- """
- The metaclass for YAMLObject.
- """
- def __init__(cls, name, bases, kwds):
- super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds)
- if 'yaml_tag' in kwds and kwds['yaml_tag'] is not None:
- cls.yaml_loader.add_constructor(cls.yaml_tag, cls.from_yaml)
- cls.yaml_dumper.add_representer(cls, cls.to_yaml)
-
-class YAMLObject(object):
- """
- An object that can dump itself to a YAML stream
- and load itself from a YAML stream.
- """
-
- __metaclass__ = YAMLObjectMetaclass
- __slots__ = () # no direct instantiation, so allow immutable subclasses
-
- yaml_loader = Loader
- yaml_dumper = Dumper
-
- yaml_tag = None
- yaml_flow_style = None
-
- def from_yaml(cls, loader, node):
- """
- Convert a representation node to a Python object.
- """
- return loader.construct_yaml_object(node, cls)
- from_yaml = classmethod(from_yaml)
-
- def to_yaml(cls, dumper, data):
- """
- Convert a Python object to a representation node.
- """
- return dumper.represent_yaml_object(cls.yaml_tag, data, cls,
- flow_style=cls.yaml_flow_style)
- to_yaml = classmethod(to_yaml)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/__init__.py b/tools/bin/ext/figleaf/__init__.py
deleted file mode 100644
index 5761930..0000000
--- a/tools/bin/ext/figleaf/__init__.py
+++ /dev/null
@@ -1,325 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-figleaf is another tool to trace Python code coverage.
-
-figleaf uses the sys.settrace hook to record which statements are
-executed by the CPython interpreter; this record can then be saved
-into a file, or otherwise communicated back to a reporting script.
-
-figleaf differs from the gold standard of Python coverage tools
-('coverage.py') in several ways. First and foremost, figleaf uses the
-same criterion for "interesting" lines of code as the sys.settrace
-function, which obviates some of the complexity in coverage.py (but
-does mean that your "loc" count goes down). Second, figleaf does not
-record code executed in the Python standard library, which results in
-a significant speedup. And third, the format in which the coverage
-format is saved is very simple and easy to work with.
-
-You might want to use figleaf if you're recording coverage from
-multiple types of tests and need to aggregate the coverage in
-interesting ways, and/or control when coverage is recorded.
-coverage.py is a better choice for command-line execution, and its
-reporting is a fair bit nicer.
-
-Command line usage: ::
-
- figleaf <python file to execute> <args to python file>
-
-The figleaf output is saved into the file '.figleaf', which is an
-*aggregate* of coverage reports from all figleaf runs from this
-directory. '.figleaf' contains a pickled dictionary of sets; the keys
-are source code filenames, and the sets contain all line numbers
-executed by the Python interpreter. See the docs or command-line
-programs in bin/ for more information.
-
-High level API: ::
-
- * ``start(ignore_lib=True)`` -- start recording code coverage.
- * ``stop()`` -- stop recording code coverage.
- * ``get_trace_obj()`` -- return the (singleton) trace object.
- * ``get_info()`` -- get the coverage dictionary
-
-Classes & functions worth knowing about (lower level API):
-
- * ``get_lines(fp)`` -- return the set of interesting lines in the fp.
- * ``combine_coverage(d1, d2)`` -- combine coverage info from two dicts.
- * ``read_coverage(filename)`` -- load the coverage dictionary
- * ``write_coverage(filename)`` -- write the coverage out.
- * ``annotate_coverage(...)`` -- annotate a Python file with its coverage info.
-
-Known problems:
-
- -- module docstrings are *covered* but not found.
-
-AUTHOR: C. Titus Brown, titus@idyll.org, with contributions from Iain Lowe.
-
-'figleaf' is Copyright (C) 2006, 2007 C. Titus Brown. It is under the
-BSD license.
-"""
-__version__ = "0.6.1"
-
-# __all__ == @CTB
-
-import sys
-import os
-from cPickle import dump, load
-from optparse import OptionParser
-
-import internals
-
-# use builtin sets if in >= 2.4, otherwise use 'sets' module.
-try:
- set()
-except NameError:
- from sets import Set as set
-
-def get_lines(fp):
- """
- Return the set of interesting lines in the source code read from
- this file handle.
- """
- # rstrip is a workaround for http://bugs.python.org/issue4262
- src = fp.read().rstrip() + "\n"
- code = compile(src, "", "exec")
-
- return internals.get_interesting_lines(code)
-
-def combine_coverage(d1, d2):
- """
- Given two coverage dictionaries, combine the recorded coverage
- and return a new dictionary.
- """
- keys = set(d1.keys())
- keys.update(set(d2.keys()))
-
- new_d = {}
- for k in keys:
- v = d1.get(k, set())
- v2 = d2.get(k, set())
-
- s = set(v)
- s.update(v2)
- new_d[k] = s
-
- return new_d
-
-def write_coverage(filename, append=True):
- """
- Write the current coverage info out to the given filename. If
- 'append' is false, destroy any previously recorded coverage info.
- """
- if _t is None:
- return
-
- data = internals.CoverageData(_t)
-
- d = data.gather_files()
-
- # sum existing coverage?
- if append:
- old = {}
- fp = None
- try:
- fp = open(filename)
- except IOError:
- pass
-
- if fp:
- old = load(fp)
- fp.close()
- d = combine_coverage(d, old)
-
- # ok, save.
- outfp = open(filename, 'w')
- try:
- dump(d, outfp)
- finally:
- outfp.close()
-
-def read_coverage(filename):
- """
- Read a coverage dictionary in from the given file.
- """
- fp = open(filename)
- try:
- d = load(fp)
- finally:
- fp.close()
-
- return d
-
-def dump_pickled_coverage(out_fp):
- """
- Dump coverage information in pickled format into the given file handle.
- """
- dump(_t, out_fp)
-
-def load_pickled_coverage(in_fp):
- """
- Replace (overwrite) coverage information from the given file handle.
- """
- global _t
- _t = load(in_fp)
-
-def annotate_coverage(in_fp, out_fp, covered, all_lines,
- mark_possible_lines=False):
- """
- A simple example coverage annotator that outputs text.
- """
- for i, line in enumerate(in_fp):
- i = i + 1
-
- if i in covered:
- symbol = '>'
- elif i in all_lines:
- symbol = '!'
- else:
- symbol = ' '
-
- symbol2 = ''
- if mark_possible_lines:
- symbol2 = ' '
- if i in all_lines:
- symbol2 = '-'
-
- out_fp.write('%s%s %s' % (symbol, symbol2, line,))
-
-def get_data():
- if _t:
- return internals.CoverageData(_t)
-
-#######################
-
-#
-# singleton functions/top-level API
-#
-
-_t = None
-
-def init(exclude_path=None, include_only=None):
- from internals import CodeTracer
-
- global _t
- if _t is None:
- _t = CodeTracer(exclude_path, include_only)
-
-def start(ignore_python_lib=True):
- """
- Start tracing code coverage. If 'ignore_python_lib' is True on
- initial call, ignore all files that live below the same directory as
- the 'os' module.
- """
- global _t
- if not _t:
- exclude_path = None
- if ignore_python_lib:
- exclude_path = os.path.realpath(os.path.dirname(os.__file__))
-
- init(exclude_path, None)
-
- _t.start()
-
-def start_section(name):
- global _t
- _t.start_section(name)
-
-def stop_section():
- global _t
- _t.stop_section()
-
-def stop():
- """
- Stop tracing code coverage.
- """
- global _t
- if _t is not None:
- _t.stop()
-
-def get_trace_obj():
- """
- Return the (singleton) trace object, if it exists.
- """
- return _t
-
-def get_info(section_name=None):
- """
- Get the coverage dictionary from the trace object.
- """
- if _t:
- return get_data().gather_files(section_name)
-
-#############
-
-def display_ast():
- l = internals.LineGrabber(open(sys.argv[1]))
- l.pretty_print()
- print l.lines
-
-def main():
- """
- Execute the given Python file with coverage, making it look like it is
- __main__.
- """
- ignore_pylibs = False
-
- # gather args
-
- n = 1
- figleaf_args = []
- for n in range(1, len(sys.argv)):
- arg = sys.argv[n]
- if arg.startswith('-'):
- figleaf_args.append(arg)
- else:
- break
-
- remaining_args = sys.argv[n:]
-
- usage = "usage: %prog [options] [python_script arg1 arg2 ...]"
- option_parser = OptionParser(usage=usage)
-
- option_parser.add_option('-i', '--ignore-pylibs', action="store_true",
- dest="ignore_pylibs", default=False,
- help="ignore Python library modules")
-
- (options, args) = option_parser.parse_args(args=figleaf_args)
- assert len(args) == 0
-
- if not remaining_args:
- option_parser.error("you must specify a python script to run!")
-
- ignore_pylibs = options.ignore_pylibs
-
- ## Reset system args so that the subsequently exec'd file can read
- ## from sys.argv
-
- sys.argv = remaining_args
-
- sys.path[0] = os.path.dirname(sys.argv[0])
-
- cwd = os.getcwd()
-
- start(ignore_pylibs) # START code coverage
-
- import __main__
- try:
- execfile(sys.argv[0], __main__.__dict__)
- finally:
- stop() # STOP code coverage
-
- write_coverage(os.path.join(cwd, '.figleaf'))
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/_lib.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/_lib.py b/tools/bin/ext/figleaf/_lib.py
deleted file mode 100644
index 3ee49f8..0000000
--- a/tools/bin/ext/figleaf/_lib.py
+++ /dev/null
@@ -1,22 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import os.path, sys
-libdir = os.path.join(os.path.dirname(__file__), '../')
-libdir = os.path.normpath(libdir)
-
-if libdir not in sys.path:
- sys.path.insert(0, libdir)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/annotate.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/annotate.py b/tools/bin/ext/figleaf/annotate.py
deleted file mode 100644
index 43099f6..0000000
--- a/tools/bin/ext/figleaf/annotate.py
+++ /dev/null
@@ -1,241 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-Common functions for annotating files with figleaf coverage information.
-"""
-import sys, os
-from optparse import OptionParser
-import ConfigParser
-import re
-import logging
-
-import figleaf
-
-thisdir = os.path.dirname(__file__)
-
-try: # 2.3 compatibility
- logging.basicConfig(format='%(message)s', level=logging.WARNING)
-except TypeError:
- pass
-
-logger = logging.getLogger('figleaf.annotate')
-
-DEFAULT_CONFIGURE_FILE = ".figleafrc"
-
-### utilities
-
-def safe_conf_get(conf, section, name, default):
- try:
- val = conf.get(section, name)
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- val = default
-
- return val
-
-def configure(parser):
- """
- Configure the optparse.OptionParser object with defaults, optionally
- loaded from a configuration file.
- """
- CONFIG_FILE = os.environ.get('FIGLEAFRC', DEFAULT_CONFIGURE_FILE)
-
- parser.add_option("-c", "--coverage-file", action="store",
- type="string", dest="coverage_file",
- help="File containing figleaf coverage information.")
-
- parser.add_option("-s", "--sections-file", action="store",
- type="string", dest="sections_file",
- help="File containing figleaf sections coverage info.")
-
- parser.add_option("-v", "--verbose", action="store_true",
- dest="verbose")
-
- conf_file = ConfigParser.ConfigParser()
- conf_file.read(CONFIG_FILE) # ignores if not present
-
- default_coverage_file = safe_conf_get(conf_file,
- 'figleaf', 'coverage_file',
- '.figleaf')
- default_sections_file = safe_conf_get(conf_file,
- 'figleaf', 'sections_file',
- '.figleaf_sections')
- default_verbose = int(safe_conf_get(conf_file, 'figleaf', 'verbose',
- 0))
-
- parser.set_defaults(coverage_file=default_coverage_file,
- sections_file=default_sections_file,
- verbose=default_verbose)
-
-def filter_coverage(coverage, re_match):
- """
- ...
- """
- if not re_match:
- return coverage
-
- regexp = re.compile(re_match)
-
- d = {}
- for filename, lines in coverage.items():
- if regexp.match(filename):
- d[filename] = lines
-
- return d
-
-### commands
-
-def list(options, match=""):
- """
- List the filenames in the coverage file, optionally limiting it to
- those files matching to the regexp 'match'.
- """
- if options.verbose:
- print>>sys.stderr, '** Reading coverage from coverage file %s' % \
- (options.coverage_file,)
- if match:
- print>>sys.stderr, '** Filtering against regexp "%s"' % (match,)
-
- coverage = figleaf.read_coverage(options.coverage_file)
- coverage = filter_coverage(coverage, match)
-
- for filename in coverage.keys():
- print filename
-
-def list_sections(options, match=""):
- """
- List the filenames in the coverage file, optionally limiting it to
- those files matching to the regexp 'match'.
- """
- if options.verbose:
- print>>sys.stderr, '** Reading sections info from sections file %s' % \
- (options.sections_file,)
- if match:
- print>>sys.stderr, '** Filtering against regexp "%s"' % (match,)
-
- fp = open(options.sections_file)
- figleaf.load_pickled_coverage(fp) # @CTB
-
- data = figleaf.internals.CoverageData(figleaf._t)
- coverage = data.gather_files()
- coverage = filter_coverage(coverage, match)
-
- for filename in coverage.keys():
- print filename
-
-###
-
-def read_exclude_patterns(filename):
- """
- Read in exclusion patterns from a file; these are just regexps.
- """
- if not filename:
- return []
-
- exclude_patterns = []
-
- fp = open(filename)
- for line in fp:
- line = line.rstrip()
- if line and not line.startswith('#'):
- pattern = re.compile(line)
- exclude_patterns.append(pattern)
-
- return exclude_patterns
-
-def read_files_list(filename):
- """
- Read in a list of files from a file; these are relative or absolute paths.
- """
- s = {}
- for line in open(filename):
- f = line.strip()
- s[os.path.abspath(f)] = 1
-
- return s
-
-def filter_files(filenames, exclude_patterns = [], files_list = {}):
- files_list = dict(files_list) # make copy
-
- # list of files specified?
- if files_list:
- for filename in files_list.keys():
- yield filename
-
- filenames = [ os.path.abspath(x) for x in filenames ]
- for filename in filenames:
- try:
- del files_list[filename]
- except KeyError:
- logger.info('SKIPPING %s -- not in files list' % (filename,))
-
- return
-
- ### no files list given -- handle differently
-
- for filename in filenames:
- abspath = os.path.abspath(filename)
-
- # check to see if we match anything in the exclude_patterns list
- skip = False
- for pattern in exclude_patterns:
- if pattern.search(filename):
- logger.info('SKIPPING %s -- matches exclusion pattern' % \
- (filename,))
- skip = True
- break
-
- if skip:
- continue
-
- # next, check to see if we're part of the figleaf package.
- if thisdir in filename:
- logger.debug('SKIPPING %s -- part of the figleaf package' % \
- (filename,))
- continue
-
- # also, check for <string> (source file from things like 'exec'):
- if filename == '<string>':
- continue
-
- # miscellaneous other things: doctests
- if filename.startswith('<doctest '):
- continue
-
- yield filename
-
-###
-
-def main():
- parser = OptionParser()
- configure(parser)
-
- options, args = parser.parse_args()
-
- if not len(args):
- print "ERROR: You must specify a command like 'list' or 'report'. Use"
- print "\n %s -h\n" % (sys.argv[0],)
- print "for help on commands and options."
- sys.exit(-1)
-
- cmd = args.pop(0)
-
- if cmd == 'list':
- list(options, *args)
- elif cmd == 'list_sections':
- list_sections(options, *args)
-
- sys.exit(0)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/annotate_cover.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/annotate_cover.py b/tools/bin/ext/figleaf/annotate_cover.py
deleted file mode 100644
index ac72bfa..0000000
--- a/tools/bin/ext/figleaf/annotate_cover.py
+++ /dev/null
@@ -1,159 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import figleaf
-import os
-import re
-
-from annotate import read_exclude_patterns, filter_files, logger
-
-def report_as_cover(coverage, exclude_patterns=[], ):
- ### now, output.
-
- keys = coverage.keys()
- info_dict = {}
-
- for k in filter_files(keys):
- try:
- pyfile = open(k, 'rU')
- lines = figleaf.get_lines(pyfile)
- except IOError:
- logger.warning('CANNOT OPEN: %s' % k)
- continue
- except KeyboardInterrupt:
- raise
- except Exception, e:
- logger.error('ERROR: file %s, exception %s' % (pyfile, str(e)))
- continue
-
- # ok, got all the info. now annotate file ==> html.
-
- covered = coverage[k]
- pyfile = open(k)
- (n_covered, n_lines, output) = make_cover_lines(lines, covered, pyfile)
-
-
- try:
- pcnt = n_covered * 100. / n_lines
- except ZeroDivisionError:
- pcnt = 100
- info_dict[k] = (n_lines, n_covered, pcnt)
-
- outfile = make_cover_filename(k)
- try:
- outfp = open(outfile, 'w')
- outfp.write("\n".join(output))
- outfp.write("\n")
- outfp.close()
- except IOError:
- logger.warning('cannot open filename %s' % (outfile,))
- continue
-
- logger.info('reported on %s' % (outfile,))
-
- ### print a summary, too.
-
- info_dict_items = info_dict.items()
-
- def sort_by_pcnt(a, b):
- a = a[1][2]
- b = b[1][2]
-
- return -cmp(a,b)
-
- info_dict_items.sort(sort_by_pcnt)
-
- logger.info('reported on %d file(s) total\n' % len(info_dict))
- return len(info_dict)
-
-def make_cover_lines(line_info, coverage_info, fp):
- n_covered = n_lines = 0
- output = []
-
- for i, line in enumerate(fp):
- is_covered = False
- is_line = False
-
- i += 1
-
- if i in coverage_info:
- is_covered = True
- prefix = '+'
-
- n_covered += 1
- n_lines += 1
- elif i in line_info:
- prefix = '-'
- is_line = True
-
- n_lines += 1
- else:
- prefix = '0'
-
- line = line.rstrip()
- output.append(prefix + ' ' + line)
-
- return (n_covered, n_lines, output)
-
-def make_cover_filename(orig):
- return orig + '.cover'
-
-def main():
- import sys
- import logging
- from optparse import OptionParser
-
- ###
-
- option_parser = OptionParser()
-
- option_parser.add_option('-x', '--exclude-patterns', action="store",
- dest="exclude_patterns_file",
- help="file containing regexp patterns to exclude")
-
- option_parser.add_option('-q', '--quiet', action='store_true',
- dest='quiet',
- help="file containig regexp patterns of files to exclude from report")
-
- option_parser.add_option('-D', '--debug', action='store_true',
- dest='debug',
- help='Show all debugging messages')
-
- (options, args) = option_parser.parse_args()
-
- if options.quiet:
- logging.disable(logging.DEBUG)
-
- if options.debug:
- logger.setLevel(logging.DEBUG)
-
- ### load
-
- if not args:
- args = ['.figleaf']
-
- coverage = {}
- for filename in args:
- logger.debug("loading coverage info from '%s'\n" % (filename,))
- d = figleaf.read_coverage(filename)
- coverage = figleaf.combine_coverage(coverage, d)
-
- if not coverage:
- logger.warning('EXITING -- no coverage info!\n')
- sys.exit(-1)
-
- exclude = read_exclude_patterns(options.exclude_patterns_file)
- report_as_cover(coverage, exclude)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/annotate_html.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/annotate_html.py b/tools/bin/ext/figleaf/annotate_html.py
deleted file mode 100644
index 594d07a..0000000
--- a/tools/bin/ext/figleaf/annotate_html.py
+++ /dev/null
@@ -1,292 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import figleaf
-import os
-import re
-
-# use builtin sets if in >= 2.4, otherwise use 'sets' module.
-try:
- set()
-except NameError:
- from sets import Set as set
-
-from figleaf.annotate import read_exclude_patterns, filter_files, logger, \
- read_files_list
-
-###
-
-def annotate_file(fp, lines, covered):
- # initialize
- n_covered = n_lines = 0
-
- output = []
- for i, line in enumerate(fp):
- is_covered = False
- is_line = False
-
- i += 1
-
- if i in covered:
- is_covered = True
-
- n_covered += 1
- n_lines += 1
- elif i in lines:
- is_line = True
-
- n_lines += 1
-
- color = 'black'
- if is_covered:
- color = 'green'
- elif is_line:
- color = 'red'
-
- line = escape_html(line.rstrip())
- output.append('<font color="%s">%4d. %s</font>' % (color, i, line))
-
- try:
- percent = n_covered * 100. / n_lines
- except ZeroDivisionError:
- percent = 100
-
- return output, n_covered, n_lines, percent
-
-def write_html_summary(info_dict, directory):
- info_dict_items = info_dict.items()
-
- def sort_by_percent(a, b):
- a = a[1][2]
- b = b[1][2]
-
- return -cmp(a,b)
- info_dict_items.sort(sort_by_percent)
-
- summary_lines = sum([ v[0] for (k, v) in info_dict_items])
- summary_cover = sum([ v[1] for (k, v) in info_dict_items])
-
- summary_percent = 100
- if summary_lines:
- summary_percent = float(summary_cover) * 100. / float(summary_lines)
-
-
- percents = [ float(v[1]) * 100. / float(v[0])
- for (k, v) in info_dict_items if v[0] ]
-
- percent_90 = [ x for x in percents if x >= 90 ]
- percent_75 = [ x for x in percents if x >= 75 ]
- percent_50 = [ x for x in percents if x >= 50 ]
-
- ### write out summary.
-
- index_fp = open('%s/index.html' % (directory,), 'w')
- index_fp.write('''
-<html>
-<title>figleaf code coverage report</title>
-<h2>Summary</h2>
-%d files total: %d files > 90%%, %d files > 75%%, %d files > 50%%
-<p>
-<table border=1>
-<tr>
- <th>Filename</th><th># lines</th><th># covered</th><th>%% covered</th>
-</tr>
-
-<tr>
- <td><b>totals:</b></td>
- <td><b>%d</b></td>
- <td><b>%d</b></td>
- <td><b>%.1f%%</b></td>
-</tr>
-
-<tr></tr>
-
-''' % (len(percents), len(percent_90), len(percent_75), len(percent_50),
- summary_lines, summary_cover, summary_percent,))
-
- for filename, (n_lines, n_covered, percent_covered,) in info_dict_items:
- html_outfile = make_html_filename(filename)
-
- index_fp.write('''
-<tr>
- <td><a href="./%s">%s</a></td>
- <td>%d</td>
- <td>%d</td>
- <td>%.1f</td>
-</tr>
-''' % (html_outfile, filename, n_lines, n_covered, percent_covered,))
-
- index_fp.write('</table>\n')
- index_fp.close()
-
-
-def report_as_html(coverage, directory, exclude_patterns, files_list):
- """
- Write an HTML report on all of the files, plus a summary.
- """
-
- ### now, output.
-
- keys = coverage.keys()
- info_dict = {}
- for pyfile in filter_files(keys, exclude_patterns, files_list):
-
- try:
- fp = open(pyfile, 'rU')
- lines = figleaf.get_lines(fp)
- except KeyboardInterrupt:
- raise
- except IOError:
- logger.error('CANNOT OPEN: %s' % (pyfile,))
- continue
- except Exception, e:
- logger.error('ERROR: file %s, exception %s' % (pyfile, str(e)))
- continue
-
- #
- # ok, we want to annotate this file. now annotate file ==> html.
- #
-
- # initialize
- covered = coverage.get(pyfile, set())
-
- # rewind
- fp.seek(0)
-
- # annotate
- output, n_covered, n_lines, percent = annotate_file(fp, lines, covered)
-
- # summarize
- info_dict[pyfile] = (n_lines, n_covered, percent)
-
- # write out the file
- html_outfile = make_html_filename(pyfile)
- html_outfile = os.path.join(directory, html_outfile)
- html_outfp = open(html_outfile, 'w')
-
- html_outfp.write('source file: <b>%s</b><br>\n' % (pyfile,))
- html_outfp.write('''
-
-file stats: <b>%d lines, %d executed: %.1f%% covered</b>
-<pre>
-%s
-</pre>
-
-''' % (n_lines, n_covered, percent, "\n".join(output)))
-
- html_outfp.close()
-
- logger.info('reported on %s' % (pyfile,))
-
- ### print a summary, too.
- write_html_summary(info_dict, directory)
-
- logger.info('reported on %d file(s) total\n' % len(info_dict))
-
-def prepare_reportdir(dirname):
- "Create output directory."
- try:
- os.mkdir(dirname)
- except OSError: # already exists
- pass
-
-def make_html_filename(orig):
- "'escape' original paths into a single filename"
-
- orig = os.path.abspath(orig)
-# orig = os.path.basename(orig)
- orig = os.path.splitdrive(orig)[1]
- orig = orig.replace('_', '__')
- orig = orig.replace(os.path.sep, '_')
- orig += '.html'
- return orig
-
-def escape_html(s):
- s = s.replace("&", "&")
- s = s.replace("<", "<")
- s = s.replace(">", ">")
- s = s.replace('"', """)
- return s
-
-def main():
- import sys
- import logging
- from optparse import OptionParser
- ###
-
- usage = "usage: %prog [options] [coverage files ... ]"
- option_parser = OptionParser(usage=usage)
-
- option_parser.add_option('-x', '--exclude-patterns', action="store",
- dest="exclude_patterns_file",
- help="file containing regexp patterns of files to exclude from report")
-
- option_parser.add_option('-f', '--files-list', action="store",
- dest="files_list",
- help="file containing filenames to report on")
-
- option_parser.add_option('-d', '--output-directory', action='store',
- dest="output_dir",
- default = "html",
- help="directory for HTML output")
-
- option_parser.add_option('-q', '--quiet', action='store_true',
- dest='quiet',
- help='Suppress all but error messages')
-
- option_parser.add_option('-D', '--debug', action='store_true',
- dest='debug',
- help='Show all debugging messages')
-
- (options, args) = option_parser.parse_args()
-
- if options.quiet:
- logging.disable(logging.DEBUG)
-
- if options.debug:
- logger.setLevel(logging.DEBUG)
-
- ### load/combine
-
- if not args:
- args = ['.figleaf']
-
- coverage = {}
- for filename in args:
- logger.debug("loading coverage info from '%s'\n" % (filename,))
- try:
- d = figleaf.read_coverage(filename)
- coverage = figleaf.combine_coverage(coverage, d)
- except IOError:
- logger.error("cannot open filename '%s'\n" % (filename,))
-
- if not coverage:
- logger.warning('EXITING -- no coverage info!\n')
- sys.exit(-1)
-
- exclude = []
- if options.exclude_patterns_file:
- exclude = read_exclude_patterns(options.exclude_patterns_file)
-
- files_list = {}
- if options.files_list:
- files_list = read_files_list(options.files_list)
-
- ### make directory
- prepare_reportdir(options.output_dir)
- report_as_html(coverage, options.output_dir, exclude, files_list)
-
- print 'figleaf: HTML output written to %s' % (options.output_dir,)
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/annotate_sections.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/annotate_sections.py b/tools/bin/ext/figleaf/annotate_sections.py
deleted file mode 100644
index 6d7fb89..0000000
--- a/tools/bin/ext/figleaf/annotate_sections.py
+++ /dev/null
@@ -1,95 +0,0 @@
-#! /usr/bin/env python
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-import figleaf
-from figleaf import internals
-from sets import Set as set
-import sys
-from cPickle import load
-import os
-from optparse import OptionParser
-
-def main():
- #### OPTIONS
-
- parser = OptionParser()
-
- parser.add_option('-c', '--coverage', nargs=1, action="store",
- dest="coverage_file",
- help = 'load coverage info from this file',
- default='.figleaf_sections')
-
- ####
-
- (options, args) = parser.parse_args(sys.argv[1:])
- coverage_file = options.coverage_file
-
- figleaf.load_pickled_coverage(open(coverage_file))
- data = internals.CoverageData(figleaf._t)
- full_cov = data.gather_files()
-
- for filename in args:
- annotate_file_with_sections(filename, data, full_cov)
-
-def annotate_file_with_sections(short, data, full_cov):
- full = os.path.abspath(short)
-
- tags = {}
- sections = data.gather_sections(full)
- sections.update(data.gather_sections(short))
-
- print data.sections
-
- print '*** PROCESSING:', short, '\n\t==>', short + '.sections'
- for tag, cov in sections.items():
- if cov:
- tags[tag] = cov
-
- if not tags:
- print '*** No coverage info for file', short
-
- tag_names = tags.keys()
- tag_names.sort()
- tag_names.reverse()
-
- tags["-- all coverage --"] = full_cov.get(full, set())
- tag_names.insert(0, "-- all coverage --")
-
- n_tags = len(tag_names)
-
- fp = open(short + '.sections', 'w')
-
- for i, tag in enumerate(tag_names):
- fp.write('%s%s\n' % ('| ' * i, tag))
- fp.write('| ' * n_tags)
- fp.write('\n\n')
-
- source = open(full)
- for n, line in enumerate(source):
- marks = ""
- for tag in tag_names:
- cov = tags[tag]
-
- symbol = ' '
- if (n+1) in cov:
- symbol = '+ '
-
- marks += symbol
-
- fp.write('%s | %s' % (marks, line))
-
- fp.close()
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/figleaf2html
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/figleaf2html b/tools/bin/ext/figleaf/figleaf2html
deleted file mode 100755
index 58636b0..0000000
--- a/tools/bin/ext/figleaf/figleaf2html
+++ /dev/null
@@ -1,7 +0,0 @@
-#! /usr/bin/env python
-"""
-Output an HTML-ized coverage report.
-"""
-import _lib
-import figleaf.annotate_html
-figleaf.annotate_html.main()
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/internals.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/internals.py b/tools/bin/ext/figleaf/internals.py
deleted file mode 100644
index 6a25c0e..0000000
--- a/tools/bin/ext/figleaf/internals.py
+++ /dev/null
@@ -1,257 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-Coverage tracking internals.
-"""
-
-import sys
-import threading
-
-err = sys.stderr
-
-import types, symbol
-
-# use builtin sets if in >= 2.4, otherwise use 'sets' module.
-try:
- set()
-except NameError:
- from sets import Set as set
-
-def get_interesting_lines(code):
- """
- Count 'interesting' lines of Python in a code object, where
- 'interesting' is defined as 'lines that could possibly be
- executed'.
-
- This is done by dissassembling the code objecte and returning
- line numbers.
- """
-
- # clean up weird end-of-file issues
-
- lines = set([ l for (o, l) in findlinestarts(code) ])
- for const in code.co_consts:
- if type(const) == types.CodeType:
- lines.update(get_interesting_lines(const))
-
- return lines
-
-def findlinestarts(code):
- """Find the offsets in a byte code which are start of lines in the source.
-
- Generate pairs (offset, lineno) as described in Python/compile.c.
-
- CTB -- swiped from Python 2.5, module 'dis', so that earlier versions
- of Python could use the function, too.
- """
- byte_increments = [ord(c) for c in code.co_lnotab[0::2]]
- line_increments = [ord(c) for c in code.co_lnotab[1::2]]
-
- lastlineno = None
- lineno = code.co_firstlineno
- addr = 0
- for byte_incr, line_incr in zip(byte_increments, line_increments):
- if byte_incr:
- if lineno != lastlineno:
- yield (addr, lineno)
- lastlineno = lineno
- addr += byte_incr
- lineno += line_incr
- if lineno != lastlineno:
- yield (addr, lineno)
-
-class CodeTracer:
- """
- Basic mechanisms for code coverage tracking, using sys.settrace.
- """
- def __init__(self, exclude_prefix, include_only_prefix):
- self.common = self.c = set()
- self.section_name = None
- self.sections = {}
-
- self.started = False
-
- assert not (exclude_prefix and include_only_prefix), \
- "mutually exclusive"
-
- self.excl = exclude_prefix
- self.incl = include_only_prefix
-
- def start(self):
- """
- Start recording.
- """
- if not self.started:
- self.started = True
-
- if self.excl and not self.incl:
- global_trace_fn = self.g1
- elif self.incl and not self.excl:
- global_trace_fn = self.g2
- else:
- global_trace_fn = self.g0
-
- sys.settrace(global_trace_fn)
-
- if hasattr(threading, 'settrace'):
- threading.settrace(global_trace_fn)
-
- def stop(self):
- if self.started:
- sys.settrace(None)
-
- if hasattr(threading, 'settrace'):
- threading.settrace(None)
-
- self.started = False
- self.stop_section()
-
- def g0(self, f, e, a):
- """
- global trace function, no exclude/include info.
-
- f == frame, e == event, a == arg .
- """
- if e == 'call':
- return self.t
-
- def g1(self, f, e, a):
- """
- global trace function like g0, but ignores files starting with
- 'self.excl'.
- """
- if e == 'call':
- excl = self.excl
- path = f.f_globals.get('__file__')
- if path is None:
- path = f.f_code.co_filename
-
- if excl and path.startswith(excl):
- return
-
- return self.t
-
- def g2(self, f, e, a):
- """
- global trace function like g0, but only records files starting with
- 'self.incl'.
- """
- if e == 'call':
- incl = self.incl
- if incl and f.f_code.co_filename.startswith(incl):
- return self.t
-
- def t(self, f, e, a):
- """
- local trace function.
- """
- if e is 'line':
- self.c.add((f.f_code.co_filename, f.f_lineno))
- return self.t
-
- def clear(self):
- """
- wipe out coverage info
- """
-
- self.c = {}
-
- def start_section(self, name):
- self.stop_section()
-
- self.section_name = name
- self.c = self.sections.get(name, set())
-
- def stop_section(self):
- if self.section_name:
- self.sections[self.section_name] = self.c
- self.section_name = None
- self.c = self.common
-
-class CoverageData:
- """
- A class to manipulate and combine data from the CodeTracer object.
-
- In general, do not pickle this object; it's simpler and more
- straightforward to just pass the basic Python objects around
- (e.g. CoverageData.common, a set, and CoverageData.sections, a
- dictionary of sets).
- """
- def __init__(self, trace_obj=None):
- self.common = set()
- self.sections = {}
-
- if trace_obj:
- self.update(trace_obj)
-
- def update(self, trace_obj):
- # transfer common-block code coverage -- if no sections are set,
- # this will be all of the code coverage info.
- self.common.update(trace_obj.common)
-
- # update our internal section dictionary with the (filename, line_no)
- # pairs from the section coverage as well.
-
- for section_name, section_d in trace_obj.sections.items():
- section_set = self.sections.get(section_name, set())
- section_set.update(section_d)
- self.sections[section_name] = section_set
-
- def gather_files(self, name=None):
- """
- Return the dictionary of lines of executed code; the dict
- keys are filenames and values are sets containing individual
- (integer) line numbers.
-
- 'name', if set, is the desired section name from which to gather
- coverage info.
- """
- cov = set()
- cov.update(self.common)
-
- if name is None:
- for section_name, coverage_set in self.sections.items():
- cov.update(coverage_set)
- else:
- coverage_set = self.sections.get(name, set())
- cov.update(coverage_set)
-
-# cov = list(cov)
-# cov.sort()
-
- files = {}
- for (filename, line) in cov: # @CTB could optimize
- d = files.get(filename, set())
- d.add(line)
- files[filename] = d
-
- return files
-
- def gather_sections(self, file):
- """
- Return a dictionary of sets containing section coverage information for
- a specific file. Dict keys are sections, and the dict values are
- sets containing (integer) line numbers.
- """
- sections = {}
- for k, c in self.sections.items():
- s = set()
- for (filename, line) in c.keys():
- if filename == file:
- s.add(line)
- sections[k] = s
- return sections
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/figleaf/nose_sections.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/figleaf/nose_sections.py b/tools/bin/ext/figleaf/nose_sections.py
deleted file mode 100644
index 09654a5..0000000
--- a/tools/bin/ext/figleaf/nose_sections.py
+++ /dev/null
@@ -1,133 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-"""
-figleafsections plugin for nose.
-
-Automatically records coverage info for Python tests and connects it with
-with test was being run at the time. Can be used to produce a "barcode"
-of code execution.
-"""
-
-DEFAULT_COVERAGE_FILE='.figleaf_sections'
-import pkg_resources
-
-try:
- pkg_resources.require('figleaf>=0.6.1')
- import figleaf
-except ImportError:
- figleaf = None
-
-import sys
-err = sys.stderr
-
-import nose.case
-from nose.plugins.base import Plugin
-
-import logging
-import os
-
-log = logging.getLogger(__name__)
-
-def calc_testname(test):
- """
- Build a reasonably human-readable testname from each test.
- """
- name = str(test)
- if ' ' in name:
- name = name.split(' ')[1]
-
- return name
-
-class FigleafSections(Plugin):
- def __init__(self):
- self.name = 'figleafsections'
- Plugin.__init__(self)
- self.testname = None
-
- def add_options(self, parser, env=os.environ):
- env_opt = 'NOSE_WITH_%s' % self.name.upper()
- env_opt.replace('-', '_')
- parser.add_option("--with-%s" % self.name,
- action="store_true",
- dest=self.enableOpt,
- default=env.get(env_opt),
- help="Enable plugin %s: %s [%s]" %
- (self.__class__.__name__, self.help(), env_opt))
-
- parser.add_option("--figleaf-file",
- action="store",
- dest="figleaf_file",
- default=None,
- help="Store figleaf section coverage in this file")
-
- def configure(self, options, config):
- """
- Configure: enable plugin? And if so, where should the coverage
- info be placed?
- """
- self.conf = config
-
- # enable?
- if hasattr(options, self.enableOpt):
- self.enabled = getattr(options, self.enableOpt)
-
- ### save coverage file name, if given.
- if options.figleaf_file:
- self.figleaf_file = options.figleaf_file
- else:
- self.figleaf_file = DEFAULT_COVERAGE_FILE
-
- if self.enabled and figleaf is None:
- raise Exception("You must install figleaf 0.6.1 before you can use the figleafsections plugin! See http://darcs.idyll.org/~t/projects/figleaf/doc/")
-
- def begin(self):
- """
- Initialize: start recording coverage info.
- """
- figleaf.start()
-
- def finalize(self, result):
- """
- Finalize: stop recording coverage info, save & exit.
- """
- figleaf.stop()
-
- fp = open(self.figleaf_file, 'w')
- figleaf.dump_pickled_coverage(fp)
- fp.close()
-
- def startTest(self, test):
- """
- Run at the beginning of each test, before per-test fixtures.
-
- One weakness is that this is only run for specific kinds of
- nose testcases.
- """
- if isinstance(test, nose.case.Test):
-
- self.testname = calc_testname(test)
- assert self.testname
-
- figleaf.start_section(self.testname)
-
- def stopTest(self, test):
- """
- Run at the end of each test, after per-test fixtures.
- """
- if self.testname:
- figleaf.stop_section()
- self.testname = None
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/__init__.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/__init__.py b/tools/bin/ext/pg8000/__init__.py
deleted file mode 100644
index 57de8e8..0000000
--- a/tools/bin/ext/pg8000/__init__.py
+++ /dev/null
@@ -1,37 +0,0 @@
-# vim: sw=4:expandtab:foldmethod=marker
-#
-# Copyright (c) 2007-2009, Mathieu Fenniak
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-__author__ = "Mathieu Fenniak"
-
-import dbapi as DBAPI
-pg8000_dbapi = DBAPI
-
-from interface import *
-from types import Bytea
-
[07/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/scanner.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/scanner.py b/tools/bin/ext/yaml/scanner.py
deleted file mode 100644
index 369c027..0000000
--- a/tools/bin/ext/yaml/scanner.py
+++ /dev/null
@@ -1,1472 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Scanner produces tokens of the following types:
-# STREAM-START
-# STREAM-END
-# DIRECTIVE(name, value)
-# DOCUMENT-START
-# DOCUMENT-END
-# BLOCK-SEQUENCE-START
-# BLOCK-MAPPING-START
-# BLOCK-END
-# FLOW-SEQUENCE-START
-# FLOW-MAPPING-START
-# FLOW-SEQUENCE-END
-# FLOW-MAPPING-END
-# BLOCK-ENTRY
-# FLOW-ENTRY
-# KEY
-# VALUE
-# ALIAS(value)
-# ANCHOR(value)
-# TAG(value)
-# SCALAR(value, plain, style)
-#
-# Read comments in the Scanner code for more details.
-#
-
-__all__ = ['Scanner', 'ScannerError']
-
-from error import MarkedYAMLError
-from tokens import *
-
-class ScannerError(MarkedYAMLError):
- pass
-
-class SimpleKey(object):
- # See below simple keys treatment.
-
- def __init__(self, token_number, required, index, line, column, mark):
- self.token_number = token_number
- self.required = required
- self.index = index
- self.line = line
- self.column = column
- self.mark = mark
-
-class Scanner(object):
-
- def __init__(self):
- """Initialize the scanner."""
- # It is assumed that Scanner and Reader will have a common descendant.
- # Reader do the dirty work of checking for BOM and converting the
- # input data to Unicode. It also adds NUL to the end.
- #
- # Reader supports the following methods
- # self.peek(i=0) # peek the next i-th character
- # self.prefix(l=1) # peek the next l characters
- # self.forward(l=1) # read the next l characters and move the pointer.
-
- # Had we reached the end of the stream?
- self.done = False
-
- # The number of unclosed '{' and '['. `flow_level == 0` means block
- # context.
- self.flow_level = 0
-
- # List of processed tokens that are not yet emitted.
- self.tokens = []
-
- # Add the STREAM-START token.
- self.fetch_stream_start()
-
- # Number of tokens that were emitted through the `get_token` method.
- self.tokens_taken = 0
-
- # The current indentation level.
- self.indent = -1
-
- # Past indentation levels.
- self.indents = []
-
- # Variables related to simple keys treatment.
-
- # A simple key is a key that is not denoted by the '?' indicator.
- # Example of simple keys:
- # ---
- # block simple key: value
- # ? not a simple key:
- # : { flow simple key: value }
- # We emit the KEY token before all keys, so when we find a potential
- # simple key, we try to locate the corresponding ':' indicator.
- # Simple keys should be limited to a single line and 1024 characters.
-
- # Can a simple key start at the current position? A simple key may
- # start:
- # - at the beginning of the line, not counting indentation spaces
- # (in block context),
- # - after '{', '[', ',' (in the flow context),
- # - after '?', ':', '-' (in the block context).
- # In the block context, this flag also signifies if a block collection
- # may start at the current position.
- self.allow_simple_key = True
-
- # Keep track of possible simple keys. This is a dictionary. The key
- # is `flow_level`; there can be no more that one possible simple key
- # for each level. The value is a SimpleKey record:
- # (token_number, required, index, line, column, mark)
- # A simple key may start with ALIAS, ANCHOR, TAG, SCALAR(flow),
- # '[', or '{' tokens.
- self.possible_simple_keys = {}
-
- # Public methods.
-
- def check_token(self, *choices):
- # Check if the next token is one of the given types.
- while self.need_more_tokens():
- self.fetch_more_tokens()
- if self.tokens:
- if not choices:
- return True
- for choice in choices:
- if isinstance(self.tokens[0], choice):
- return True
- return False
-
- def peek_token(self):
- # Return the next token, but do not delete if from the queue.
- while self.need_more_tokens():
- self.fetch_more_tokens()
- if self.tokens:
- return self.tokens[0]
-
- def get_token(self):
- # Return the next token.
- while self.need_more_tokens():
- self.fetch_more_tokens()
- if self.tokens:
- self.tokens_taken += 1
- return self.tokens.pop(0)
-
- # Private methods.
-
- def need_more_tokens(self):
- if self.done:
- return False
- if not self.tokens:
- return True
- # The current token may be a potential simple key, so we
- # need to look further.
- self.stale_possible_simple_keys()
- if self.next_possible_simple_key() == self.tokens_taken:
- return True
-
- def fetch_more_tokens(self):
-
- # Eat whitespaces and comments until we reach the next token.
- self.scan_to_next_token()
-
- # Remove obsolete possible simple keys.
- self.stale_possible_simple_keys()
-
- # Compare the current indentation and column. It may add some tokens
- # and decrease the current indentation level.
- self.unwind_indent(self.column)
-
- # Peek the next character.
- ch = self.peek()
-
- # Is it the end of stream?
- if ch == u'\0':
- return self.fetch_stream_end()
-
- # Is it a directive?
- if ch == u'%' and self.check_directive():
- return self.fetch_directive()
-
- # Is it the document start?
- if ch == u'-' and self.check_document_start():
- return self.fetch_document_start()
-
- # Is it the document end?
- if ch == u'.' and self.check_document_end():
- return self.fetch_document_end()
-
- # TODO: support for BOM within a stream.
- #if ch == u'\uFEFF':
- # return self.fetch_bom() <-- issue BOMToken
-
- # Note: the order of the following checks is NOT significant.
-
- # Is it the flow sequence start indicator?
- if ch == u'[':
- return self.fetch_flow_sequence_start()
-
- # Is it the flow mapping start indicator?
- if ch == u'{':
- return self.fetch_flow_mapping_start()
-
- # Is it the flow sequence end indicator?
- if ch == u']':
- return self.fetch_flow_sequence_end()
-
- # Is it the flow mapping end indicator?
- if ch == u'}':
- return self.fetch_flow_mapping_end()
-
- # Is it the flow entry indicator?
- if ch == u',':
- return self.fetch_flow_entry()
-
- # Is it the block entry indicator?
- if ch == u'-' and self.check_block_entry():
- return self.fetch_block_entry()
-
- # Is it the key indicator?
- if ch == u'?' and self.check_key():
- return self.fetch_key()
-
- # Is it the value indicator?
- if ch == u':' and self.check_value():
- return self.fetch_value()
-
- # Is it an alias?
- if ch == u'*':
- return self.fetch_alias()
-
- # Is it an anchor?
- if ch == u'&':
- return self.fetch_anchor()
-
- # Is it a tag?
- if ch == u'!':
- return self.fetch_tag()
-
- # Is it a literal scalar?
- if ch == u'|' and not self.flow_level:
- return self.fetch_literal()
-
- # Is it a folded scalar?
- if ch == u'>' and not self.flow_level:
- return self.fetch_folded()
-
- # Is it a single quoted scalar?
- if ch == u'\'':
- return self.fetch_single()
-
- # Is it a double quoted scalar?
- if ch == u'\"':
- return self.fetch_double()
-
- # It must be a plain scalar then.
- if self.check_plain():
- return self.fetch_plain()
-
- # No? It's an error. Let's produce a nice error message.
- raise ScannerError("while scanning for the next token", None,
- "found character %r that cannot start any token"
- % ch.encode('utf-8'), self.get_mark())
-
- # Simple keys treatment.
-
- def next_possible_simple_key(self):
- # Return the number of the nearest possible simple key. Actually we
- # don't need to loop through the whole dictionary. We may replace it
- # with the following code:
- # if not self.possible_simple_keys:
- # return None
- # return self.possible_simple_keys[
- # min(self.possible_simple_keys.keys())].token_number
- min_token_number = None
- for level in self.possible_simple_keys:
- key = self.possible_simple_keys[level]
- if min_token_number is None or key.token_number < min_token_number:
- min_token_number = key.token_number
- return min_token_number
-
- def stale_possible_simple_keys(self):
- # Remove entries that are no longer possible simple keys. According to
- # the YAML specification, simple keys
- # - should be limited to a single line,
- # - should be no longer than 1024 characters.
- # Disabling this procedure will allow simple keys of any length and
- # height (may cause problems if indentation is broken though).
- for level in self.possible_simple_keys.keys():
- key = self.possible_simple_keys[level]
- if key.line != self.line \
- or self.index-key.index > 1024:
- if key.required:
- raise ScannerError("while scanning a simple key", key.mark,
- "could not found expected ':'", self.get_mark())
- del self.possible_simple_keys[level]
-
- def save_possible_simple_key(self):
- # The next token may start a simple key. We check if it's possible
- # and save its position. This function is called for
- # ALIAS, ANCHOR, TAG, SCALAR(flow), '[', and '{'.
-
- # Check if a simple key is required at the current position.
- required = not self.flow_level and self.indent == self.column
-
- # A simple key is required only if it is the first token in the current
- # line. Therefore it is always allowed.
- assert self.allow_simple_key or not required
-
- # The next token might be a simple key. Let's save it's number and
- # position.
- if self.allow_simple_key:
- self.remove_possible_simple_key()
- token_number = self.tokens_taken+len(self.tokens)
- key = SimpleKey(token_number, required,
- self.index, self.line, self.column, self.get_mark())
- self.possible_simple_keys[self.flow_level] = key
-
- def remove_possible_simple_key(self):
- # Remove the saved possible key position at the current flow level.
- if self.flow_level in self.possible_simple_keys:
- key = self.possible_simple_keys[self.flow_level]
-
- if key.required:
- raise ScannerError("while scanning a simple key", key.mark,
- "could not found expected ':'", self.get_mark())
-
- del self.possible_simple_keys[self.flow_level]
-
- # Indentation functions.
-
- def unwind_indent(self, column):
-
- ## In flow context, tokens should respect indentation.
- ## Actually the condition should be `self.indent >= column` according to
- ## the spec. But this condition will prohibit intuitively correct
- ## constructions such as
- ## key : {
- ## }
- #if self.flow_level and self.indent > column:
- # raise ScannerError(None, None,
- # "invalid intendation or unclosed '[' or '{'",
- # self.get_mark())
-
- # In the flow context, indentation is ignored. We make the scanner less
- # restrictive then specification requires.
- if self.flow_level:
- return
-
- # In block context, we may need to issue the BLOCK-END tokens.
- while self.indent > column:
- mark = self.get_mark()
- self.indent = self.indents.pop()
- self.tokens.append(BlockEndToken(mark, mark))
-
- def add_indent(self, column):
- # Check if we need to increase indentation.
- if self.indent < column:
- self.indents.append(self.indent)
- self.indent = column
- return True
- return False
-
- # Fetchers.
-
- def fetch_stream_start(self):
- # We always add STREAM-START as the first token and STREAM-END as the
- # last token.
-
- # Read the token.
- mark = self.get_mark()
-
- # Add STREAM-START.
- self.tokens.append(StreamStartToken(mark, mark,
- encoding=self.encoding))
-
-
- def fetch_stream_end(self):
-
- # Set the current intendation to -1.
- self.unwind_indent(-1)
-
- # Reset everything (not really needed).
- self.allow_simple_key = False
- self.possible_simple_keys = {}
-
- # Read the token.
- mark = self.get_mark()
-
- # Add STREAM-END.
- self.tokens.append(StreamEndToken(mark, mark))
-
- # The steam is finished.
- self.done = True
-
- def fetch_directive(self):
-
- # Set the current intendation to -1.
- self.unwind_indent(-1)
-
- # Reset simple keys.
- self.remove_possible_simple_key()
- self.allow_simple_key = False
-
- # Scan and add DIRECTIVE.
- self.tokens.append(self.scan_directive())
-
- def fetch_document_start(self):
- self.fetch_document_indicator(DocumentStartToken)
-
- def fetch_document_end(self):
- self.fetch_document_indicator(DocumentEndToken)
-
- def fetch_document_indicator(self, TokenClass):
-
- # Set the current intendation to -1.
- self.unwind_indent(-1)
-
- # Reset simple keys. Note that there could not be a block collection
- # after '---'.
- self.remove_possible_simple_key()
- self.allow_simple_key = False
-
- # Add DOCUMENT-START or DOCUMENT-END.
- start_mark = self.get_mark()
- self.forward(3)
- end_mark = self.get_mark()
- self.tokens.append(TokenClass(start_mark, end_mark))
-
- def fetch_flow_sequence_start(self):
- self.fetch_flow_collection_start(FlowSequenceStartToken)
-
- def fetch_flow_mapping_start(self):
- self.fetch_flow_collection_start(FlowMappingStartToken)
-
- def fetch_flow_collection_start(self, TokenClass):
-
- # '[' and '{' may start a simple key.
- self.save_possible_simple_key()
-
- # Increase the flow level.
- self.flow_level += 1
-
- # Simple keys are allowed after '[' and '{'.
- self.allow_simple_key = True
-
- # Add FLOW-SEQUENCE-START or FLOW-MAPPING-START.
- start_mark = self.get_mark()
- self.forward()
- end_mark = self.get_mark()
- self.tokens.append(TokenClass(start_mark, end_mark))
-
- def fetch_flow_sequence_end(self):
- self.fetch_flow_collection_end(FlowSequenceEndToken)
-
- def fetch_flow_mapping_end(self):
- self.fetch_flow_collection_end(FlowMappingEndToken)
-
- def fetch_flow_collection_end(self, TokenClass):
-
- # Reset possible simple key on the current level.
- self.remove_possible_simple_key()
-
- # Decrease the flow level.
- self.flow_level -= 1
-
- # No simple keys after ']' or '}'.
- self.allow_simple_key = False
-
- # Add FLOW-SEQUENCE-END or FLOW-MAPPING-END.
- start_mark = self.get_mark()
- self.forward()
- end_mark = self.get_mark()
- self.tokens.append(TokenClass(start_mark, end_mark))
-
- def fetch_flow_entry(self):
-
- # Simple keys are allowed after ','.
- self.allow_simple_key = True
-
- # Reset possible simple key on the current level.
- self.remove_possible_simple_key()
-
- # Add FLOW-ENTRY.
- start_mark = self.get_mark()
- self.forward()
- end_mark = self.get_mark()
- self.tokens.append(FlowEntryToken(start_mark, end_mark))
-
- def fetch_block_entry(self):
-
- # Block context needs additional checks.
- if not self.flow_level:
-
- # Are we allowed to start a new entry?
- if not self.allow_simple_key:
- raise ScannerError(None, None,
- "sequence entries are not allowed here",
- self.get_mark())
-
- # We may need to add BLOCK-SEQUENCE-START.
- if self.add_indent(self.column):
- mark = self.get_mark()
- self.tokens.append(BlockSequenceStartToken(mark, mark))
-
- # It's an error for the block entry to occur in the flow context,
- # but we let the parser detect this.
- else:
- pass
-
- # Simple keys are allowed after '-'.
- self.allow_simple_key = True
-
- # Reset possible simple key on the current level.
- self.remove_possible_simple_key()
-
- # Add BLOCK-ENTRY.
- start_mark = self.get_mark()
- self.forward()
- end_mark = self.get_mark()
- self.tokens.append(BlockEntryToken(start_mark, end_mark))
-
- def fetch_key(self):
-
- # Block context needs additional checks.
- if not self.flow_level:
-
- # Are we allowed to start a key (not nessesary a simple)?
- if not self.allow_simple_key:
- raise ScannerError(None, None,
- "mapping keys are not allowed here",
- self.get_mark())
-
- # We may need to add BLOCK-MAPPING-START.
- if self.add_indent(self.column):
- mark = self.get_mark()
- self.tokens.append(BlockMappingStartToken(mark, mark))
-
- # Simple keys are allowed after '?' in the block context.
- self.allow_simple_key = not self.flow_level
-
- # Reset possible simple key on the current level.
- self.remove_possible_simple_key()
-
- # Add KEY.
- start_mark = self.get_mark()
- self.forward()
- end_mark = self.get_mark()
- self.tokens.append(KeyToken(start_mark, end_mark))
-
- def fetch_value(self):
-
- # Do we determine a simple key?
- if self.flow_level in self.possible_simple_keys:
-
- # Add KEY.
- key = self.possible_simple_keys[self.flow_level]
- del self.possible_simple_keys[self.flow_level]
- self.tokens.insert(key.token_number-self.tokens_taken,
- KeyToken(key.mark, key.mark))
-
- # If this key starts a new block mapping, we need to add
- # BLOCK-MAPPING-START.
- if not self.flow_level:
- if self.add_indent(key.column):
- self.tokens.insert(key.token_number-self.tokens_taken,
- BlockMappingStartToken(key.mark, key.mark))
-
- # There cannot be two simple keys one after another.
- self.allow_simple_key = False
-
- # It must be a part of a complex key.
- else:
-
- # Block context needs additional checks.
- # (Do we really need them? They will be catched by the parser
- # anyway.)
- if not self.flow_level:
-
- # We are allowed to start a complex value if and only if
- # we can start a simple key.
- if not self.allow_simple_key:
- raise ScannerError(None, None,
- "mapping values are not allowed here",
- self.get_mark())
-
- # If this value starts a new block mapping, we need to add
- # BLOCK-MAPPING-START. It will be detected as an error later by
- # the parser.
- if not self.flow_level:
- if self.add_indent(self.column):
- mark = self.get_mark()
- self.tokens.append(BlockMappingStartToken(mark, mark))
-
- # Simple keys are allowed after ':' in the block context.
- self.allow_simple_key = not self.flow_level
-
- # Reset possible simple key on the current level.
- self.remove_possible_simple_key()
-
- # Add VALUE.
- start_mark = self.get_mark()
- self.forward()
- end_mark = self.get_mark()
- self.tokens.append(ValueToken(start_mark, end_mark))
-
- def fetch_alias(self):
-
- # ALIAS could be a simple key.
- self.save_possible_simple_key()
-
- # No simple keys after ALIAS.
- self.allow_simple_key = False
-
- # Scan and add ALIAS.
- self.tokens.append(self.scan_anchor(AliasToken))
-
- def fetch_anchor(self):
-
- # ANCHOR could start a simple key.
- self.save_possible_simple_key()
-
- # No simple keys after ANCHOR.
- self.allow_simple_key = False
-
- # Scan and add ANCHOR.
- self.tokens.append(self.scan_anchor(AnchorToken))
-
- def fetch_tag(self):
-
- # TAG could start a simple key.
- self.save_possible_simple_key()
-
- # No simple keys after TAG.
- self.allow_simple_key = False
-
- # Scan and add TAG.
- self.tokens.append(self.scan_tag())
-
- def fetch_literal(self):
- self.fetch_block_scalar(style='|')
-
- def fetch_folded(self):
- self.fetch_block_scalar(style='>')
-
- def fetch_block_scalar(self, style):
-
- # A simple key may follow a block scalar.
- self.allow_simple_key = True
-
- # Reset possible simple key on the current level.
- self.remove_possible_simple_key()
-
- # Scan and add SCALAR.
- self.tokens.append(self.scan_block_scalar(style))
-
- def fetch_single(self):
- self.fetch_flow_scalar(style='\'')
-
- def fetch_double(self):
- self.fetch_flow_scalar(style='"')
-
- def fetch_flow_scalar(self, style):
-
- # A flow scalar could be a simple key.
- self.save_possible_simple_key()
-
- # No simple keys after flow scalars.
- self.allow_simple_key = False
-
- # Scan and add SCALAR.
- self.tokens.append(self.scan_flow_scalar(style))
-
- def fetch_plain(self):
-
- # A plain scalar could be a simple key.
- self.save_possible_simple_key()
-
- # No simple keys after plain scalars. But note that `scan_plain` will
- # change this flag if the scan is finished at the beginning of the
- # line.
- self.allow_simple_key = False
-
- # Scan and add SCALAR. May change `allow_simple_key`.
- self.tokens.append(self.scan_plain())
-
- # Checkers.
-
- def check_directive(self):
-
- # DIRECTIVE: ^ '%' ...
- # The '%' indicator is already checked.
- if self.column == 0:
- return True
-
- def check_document_start(self):
-
- # DOCUMENT-START: ^ '---' (' '|'\n')
- if self.column == 0:
- if self.prefix(3) == u'---' \
- and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
- return True
-
- def check_document_end(self):
-
- # DOCUMENT-END: ^ '...' (' '|'\n')
- if self.column == 0:
- if self.prefix(3) == u'...' \
- and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
- return True
-
- def check_block_entry(self):
-
- # BLOCK-ENTRY: '-' (' '|'\n')
- return self.peek(1) in u'\0 \t\r\n\x85\u2028\u2029'
-
- def check_key(self):
-
- # KEY(flow context): '?'
- if self.flow_level:
- return True
-
- # KEY(block context): '?' (' '|'\n')
- else:
- return self.peek(1) in u'\0 \t\r\n\x85\u2028\u2029'
-
- def check_value(self):
-
- # VALUE(flow context): ':'
- if self.flow_level:
- return True
-
- # VALUE(block context): ':' (' '|'\n')
- else:
- return self.peek(1) in u'\0 \t\r\n\x85\u2028\u2029'
-
- def check_plain(self):
-
- # A plain scalar may start with any non-space character except:
- # '-', '?', ':', ',', '[', ']', '{', '}',
- # '#', '&', '*', '!', '|', '>', '\'', '\"',
- # '%', '@', '`'.
- #
- # It may also start with
- # '-', '?', ':'
- # if it is followed by a non-space character.
- #
- # Note that we limit the last rule to the block context (except the
- # '-' character) because we want the flow context to be space
- # independent.
- ch = self.peek()
- return ch not in u'\0 \t\r\n\x85\u2028\u2029-?:,[]{}#&*!|>\'\"%@`' \
- or (self.peek(1) not in u'\0 \t\r\n\x85\u2028\u2029'
- and (ch == u'-' or (not self.flow_level and ch in u'?:')))
-
- # Scanners.
-
- def scan_to_next_token(self):
- # We ignore spaces, line breaks and comments.
- # If we find a line break in the block context, we set the flag
- # `allow_simple_key` on.
- # The byte order mark is stripped if it's the first character in the
- # stream. We do not yet support BOM inside the stream as the
- # specification requires. Any such mark will be considered as a part
- # of the document.
- #
- # TODO: We need to make tab handling rules more sane. A good rule is
- # Tabs cannot precede tokens
- # BLOCK-SEQUENCE-START, BLOCK-MAPPING-START, BLOCK-END,
- # KEY(block), VALUE(block), BLOCK-ENTRY
- # So the checking code is
- # if <TAB>:
- # self.allow_simple_keys = False
- # We also need to add the check for `allow_simple_keys == True` to
- # `unwind_indent` before issuing BLOCK-END.
- # Scanners for block, flow, and plain scalars need to be modified.
-
- if self.index == 0 and self.peek() == u'\uFEFF':
- self.forward()
- found = False
- while not found:
- while self.peek() == u' ':
- self.forward()
- if self.peek() == u'#':
- while self.peek() not in u'\0\r\n\x85\u2028\u2029':
- self.forward()
- if self.scan_line_break():
- if not self.flow_level:
- self.allow_simple_key = True
- else:
- found = True
-
- def scan_directive(self):
- # See the specification for details.
- start_mark = self.get_mark()
- self.forward()
- name = self.scan_directive_name(start_mark)
- value = None
- if name == u'YAML':
- value = self.scan_yaml_directive_value(start_mark)
- end_mark = self.get_mark()
- elif name == u'TAG':
- value = self.scan_tag_directive_value(start_mark)
- end_mark = self.get_mark()
- else:
- end_mark = self.get_mark()
- while self.peek() not in u'\0\r\n\x85\u2028\u2029':
- self.forward()
- self.scan_directive_ignored_line(start_mark)
- return DirectiveToken(name, value, start_mark, end_mark)
-
- def scan_directive_name(self, start_mark):
- # See the specification for details.
- length = 0
- ch = self.peek(length)
- while u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-_':
- length += 1
- ch = self.peek(length)
- if not length:
- raise ScannerError("while scanning a directive", start_mark,
- "expected alphabetic or numeric character, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- value = self.prefix(length)
- self.forward(length)
- ch = self.peek()
- if ch not in u'\0 \r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a directive", start_mark,
- "expected alphabetic or numeric character, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- return value
-
- def scan_yaml_directive_value(self, start_mark):
- # See the specification for details.
- while self.peek() == u' ':
- self.forward()
- major = self.scan_yaml_directive_number(start_mark)
- if self.peek() != '.':
- raise ScannerError("while scanning a directive", start_mark,
- "expected a digit or '.', but found %r"
- % self.peek().encode('utf-8'),
- self.get_mark())
- self.forward()
- minor = self.scan_yaml_directive_number(start_mark)
- if self.peek() not in u'\0 \r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a directive", start_mark,
- "expected a digit or ' ', but found %r"
- % self.peek().encode('utf-8'),
- self.get_mark())
- return (major, minor)
-
- def scan_yaml_directive_number(self, start_mark):
- # See the specification for details.
- ch = self.peek()
- if not (u'0' <= ch <= '9'):
- raise ScannerError("while scanning a directive", start_mark,
- "expected a digit, but found %r" % ch.encode('utf-8'),
- self.get_mark())
- length = 0
- while u'0' <= self.peek(length) <= u'9':
- length += 1
- value = int(self.prefix(length))
- self.forward(length)
- return value
-
- def scan_tag_directive_value(self, start_mark):
- # See the specification for details.
- while self.peek() == u' ':
- self.forward()
- handle = self.scan_tag_directive_handle(start_mark)
- while self.peek() == u' ':
- self.forward()
- prefix = self.scan_tag_directive_prefix(start_mark)
- return (handle, prefix)
-
- def scan_tag_directive_handle(self, start_mark):
- # See the specification for details.
- value = self.scan_tag_handle('directive', start_mark)
- ch = self.peek()
- if ch != u' ':
- raise ScannerError("while scanning a directive", start_mark,
- "expected ' ', but found %r" % ch.encode('utf-8'),
- self.get_mark())
- return value
-
- def scan_tag_directive_prefix(self, start_mark):
- # See the specification for details.
- value = self.scan_tag_uri('directive', start_mark)
- ch = self.peek()
- if ch not in u'\0 \r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a directive", start_mark,
- "expected ' ', but found %r" % ch.encode('utf-8'),
- self.get_mark())
- return value
-
- def scan_directive_ignored_line(self, start_mark):
- # See the specification for details.
- while self.peek() == u' ':
- self.forward()
- if self.peek() == u'#':
- while self.peek() not in u'\0\r\n\x85\u2028\u2029':
- self.forward()
- ch = self.peek()
- if ch not in u'\0\r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a directive", start_mark,
- "expected a comment or a line break, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- self.scan_line_break()
-
- def scan_anchor(self, TokenClass):
- # The specification does not restrict characters for anchors and
- # aliases. This may lead to problems, for instance, the document:
- # [ *alias, value ]
- # can be interpteted in two ways, as
- # [ "value" ]
- # and
- # [ *alias , "value" ]
- # Therefore we restrict aliases to numbers and ASCII letters.
- start_mark = self.get_mark()
- indicator = self.peek()
- if indicator == '*':
- name = 'alias'
- else:
- name = 'anchor'
- self.forward()
- length = 0
- ch = self.peek(length)
- while u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-_':
- length += 1
- ch = self.peek(length)
- if not length:
- raise ScannerError("while scanning an %s" % name, start_mark,
- "expected alphabetic or numeric character, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- value = self.prefix(length)
- self.forward(length)
- ch = self.peek()
- if ch not in u'\0 \t\r\n\x85\u2028\u2029?:,]}%@`':
- raise ScannerError("while scanning an %s" % name, start_mark,
- "expected alphabetic or numeric character, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- end_mark = self.get_mark()
- return TokenClass(value, start_mark, end_mark)
-
- def scan_tag(self):
- # See the specification for details.
- start_mark = self.get_mark()
- ch = self.peek(1)
- if ch == u'<':
- handle = None
- self.forward(2)
- suffix = self.scan_tag_uri('tag', start_mark)
- if self.peek() != u'>':
- raise ScannerError("while parsing a tag", start_mark,
- "expected '>', but found %r" % self.peek().encode('utf-8'),
- self.get_mark())
- self.forward()
- elif ch in u'\0 \t\r\n\x85\u2028\u2029':
- handle = None
- suffix = u'!'
- self.forward()
- else:
- length = 1
- use_handle = False
- while ch not in u'\0 \r\n\x85\u2028\u2029':
- if ch == u'!':
- use_handle = True
- break
- length += 1
- ch = self.peek(length)
- handle = u'!'
- if use_handle:
- handle = self.scan_tag_handle('tag', start_mark)
- else:
- handle = u'!'
- self.forward()
- suffix = self.scan_tag_uri('tag', start_mark)
- ch = self.peek()
- if ch not in u'\0 \r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a tag", start_mark,
- "expected ' ', but found %r" % ch.encode('utf-8'),
- self.get_mark())
- value = (handle, suffix)
- end_mark = self.get_mark()
- return TagToken(value, start_mark, end_mark)
-
- def scan_block_scalar(self, style):
- # See the specification for details.
-
- if style == '>':
- folded = True
- else:
- folded = False
-
- chunks = []
- start_mark = self.get_mark()
-
- # Scan the header.
- self.forward()
- chomping, increment = self.scan_block_scalar_indicators(start_mark)
- self.scan_block_scalar_ignored_line(start_mark)
-
- # Determine the indentation level and go to the first non-empty line.
- min_indent = self.indent+1
- if min_indent < 1:
- min_indent = 1
- if increment is None:
- breaks, max_indent, end_mark = self.scan_block_scalar_indentation()
- indent = max(min_indent, max_indent)
- else:
- indent = min_indent+increment-1
- breaks, end_mark = self.scan_block_scalar_breaks(indent)
- line_break = u''
-
- # Scan the inner part of the block scalar.
- while self.column == indent and self.peek() != u'\0':
- chunks.extend(breaks)
- leading_non_space = self.peek() not in u' \t'
- length = 0
- while self.peek(length) not in u'\0\r\n\x85\u2028\u2029':
- length += 1
- chunks.append(self.prefix(length))
- self.forward(length)
- line_break = self.scan_line_break()
- breaks, end_mark = self.scan_block_scalar_breaks(indent)
- if self.column == indent and self.peek() != u'\0':
-
- # Unfortunately, folding rules are ambiguous.
- #
- # This is the folding according to the specification:
-
- if folded and line_break == u'\n' \
- and leading_non_space and self.peek() not in u' \t':
- if not breaks:
- chunks.append(u' ')
- else:
- chunks.append(line_break)
-
- # This is Clark Evans's interpretation (also in the spec
- # examples):
- #
- #if folded and line_break == u'\n':
- # if not breaks:
- # if self.peek() not in ' \t':
- # chunks.append(u' ')
- # else:
- # chunks.append(line_break)
- #else:
- # chunks.append(line_break)
- else:
- break
-
- # Chomp the tail.
- if chomping is not False:
- chunks.append(line_break)
- if chomping is True:
- chunks.extend(breaks)
-
- # We are done.
- return ScalarToken(u''.join(chunks), False, start_mark, end_mark,
- style)
-
- def scan_block_scalar_indicators(self, start_mark):
- # See the specification for details.
- chomping = None
- increment = None
- ch = self.peek()
- if ch in u'+-':
- if ch == '+':
- chomping = True
- else:
- chomping = False
- self.forward()
- ch = self.peek()
- if ch in u'0123456789':
- increment = int(ch)
- if increment == 0:
- raise ScannerError("while scanning a block scalar", start_mark,
- "expected indentation indicator in the range 1-9, but found 0",
- self.get_mark())
- self.forward()
- elif ch in u'0123456789':
- increment = int(ch)
- if increment == 0:
- raise ScannerError("while scanning a block scalar", start_mark,
- "expected indentation indicator in the range 1-9, but found 0",
- self.get_mark())
- self.forward()
- ch = self.peek()
- if ch in u'+-':
- if ch == '+':
- chomping = True
- else:
- chomping = False
- self.forward()
- ch = self.peek()
- if ch not in u'\0 \r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a block scalar", start_mark,
- "expected chomping or indentation indicators, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- return chomping, increment
-
- def scan_block_scalar_ignored_line(self, start_mark):
- # See the specification for details.
- while self.peek() == u' ':
- self.forward()
- if self.peek() == u'#':
- while self.peek() not in u'\0\r\n\x85\u2028\u2029':
- self.forward()
- ch = self.peek()
- if ch not in u'\0\r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a block scalar", start_mark,
- "expected a comment or a line break, but found %r"
- % ch.encode('utf-8'), self.get_mark())
- self.scan_line_break()
-
- def scan_block_scalar_indentation(self):
- # See the specification for details.
- chunks = []
- max_indent = 0
- end_mark = self.get_mark()
- while self.peek() in u' \r\n\x85\u2028\u2029':
- if self.peek() != u' ':
- chunks.append(self.scan_line_break())
- end_mark = self.get_mark()
- else:
- self.forward()
- if self.column > max_indent:
- max_indent = self.column
- return chunks, max_indent, end_mark
-
- def scan_block_scalar_breaks(self, indent):
- # See the specification for details.
- chunks = []
- end_mark = self.get_mark()
- while self.column < indent and self.peek() == u' ':
- self.forward()
- while self.peek() in u'\r\n\x85\u2028\u2029':
- chunks.append(self.scan_line_break())
- end_mark = self.get_mark()
- while self.column < indent and self.peek() == u' ':
- self.forward()
- return chunks, end_mark
-
- def scan_flow_scalar(self, style):
- # See the specification for details.
- # Note that we loose indentation rules for quoted scalars. Quoted
- # scalars don't need to adhere indentation because " and ' clearly
- # mark the beginning and the end of them. Therefore we are less
- # restrictive then the specification requires. We only need to check
- # that document separators are not included in scalars.
- if style == '"':
- double = True
- else:
- double = False
- chunks = []
- start_mark = self.get_mark()
- quote = self.peek()
- self.forward()
- chunks.extend(self.scan_flow_scalar_non_spaces(double, start_mark))
- while self.peek() != quote:
- chunks.extend(self.scan_flow_scalar_spaces(double, start_mark))
- chunks.extend(self.scan_flow_scalar_non_spaces(double, start_mark))
- self.forward()
- end_mark = self.get_mark()
- return ScalarToken(u''.join(chunks), False, start_mark, end_mark,
- style)
-
- ESCAPE_REPLACEMENTS = {
- u'0': u'\0',
- u'a': u'\x07',
- u'b': u'\x08',
- u't': u'\x09',
- u'\t': u'\x09',
- u'n': u'\x0A',
- u'v': u'\x0B',
- u'f': u'\x0C',
- u'r': u'\x0D',
- u'e': u'\x1B',
- u' ': u'\x20',
- u'\"': u'\"',
- u'\\': u'\\',
- u'N': u'\x85',
- u'_': u'\xA0',
- u'L': u'\u2028',
- u'P': u'\u2029',
- }
-
- ESCAPE_CODES = {
- u'x': 2,
- u'u': 4,
- u'U': 8,
- }
-
- def scan_flow_scalar_non_spaces(self, double, start_mark):
- # See the specification for details.
- chunks = []
- while True:
- length = 0
- while self.peek(length) not in u'\'\"\\\0 \t\r\n\x85\u2028\u2029':
- length += 1
- if length:
- chunks.append(self.prefix(length))
- self.forward(length)
- ch = self.peek()
- if not double and ch == u'\'' and self.peek(1) == u'\'':
- chunks.append(u'\'')
- self.forward(2)
- elif (double and ch == u'\'') or (not double and ch in u'\"\\'):
- chunks.append(ch)
- self.forward()
- elif double and ch == u'\\':
- self.forward()
- ch = self.peek()
- if ch in self.ESCAPE_REPLACEMENTS:
- chunks.append(self.ESCAPE_REPLACEMENTS[ch])
- self.forward()
- elif ch in self.ESCAPE_CODES:
- length = self.ESCAPE_CODES[ch]
- self.forward()
- for k in range(length):
- if self.peek(k) not in u'0123456789ABCDEFabcdef':
- raise ScannerError("while scanning a double-quoted scalar", start_mark,
- "expected escape sequence of %d hexdecimal numbers, but found %r" %
- (length, self.peek(k).encode('utf-8')), self.get_mark())
- code = int(self.prefix(length), 16)
- chunks.append(unichr(code))
- self.forward(length)
- elif ch in u'\r\n\x85\u2028\u2029':
- self.scan_line_break()
- chunks.extend(self.scan_flow_scalar_breaks(double, start_mark))
- else:
- raise ScannerError("while scanning a double-quoted scalar", start_mark,
- "found unknown escape character %r" % ch.encode('utf-8'), self.get_mark())
- else:
- return chunks
-
- def scan_flow_scalar_spaces(self, double, start_mark):
- # See the specification for details.
- chunks = []
- length = 0
- while self.peek(length) in u' \t':
- length += 1
- whitespaces = self.prefix(length)
- self.forward(length)
- ch = self.peek()
- if ch == u'\0':
- raise ScannerError("while scanning a quoted scalar", start_mark,
- "found unexpected end of stream", self.get_mark())
- elif ch in u'\r\n\x85\u2028\u2029':
- line_break = self.scan_line_break()
- breaks = self.scan_flow_scalar_breaks(double, start_mark)
- if line_break != u'\n':
- chunks.append(line_break)
- elif not breaks:
- chunks.append(u' ')
- chunks.extend(breaks)
- else:
- chunks.append(whitespaces)
- return chunks
-
- def scan_flow_scalar_breaks(self, double, start_mark):
- # See the specification for details.
- chunks = []
- while True:
- # Instead of checking indentation, we check for document
- # separators.
- prefix = self.prefix(3)
- if (prefix == u'---' or prefix == u'...') \
- and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
- raise ScannerError("while scanning a quoted scalar", start_mark,
- "found unexpected document separator", self.get_mark())
- while self.peek() in u' \t':
- self.forward()
- if self.peek() in u'\r\n\x85\u2028\u2029':
- chunks.append(self.scan_line_break())
- else:
- return chunks
-
- def scan_plain(self):
- # See the specification for details.
- # We add an additional restriction for the flow context:
- # plain scalars in the flow context cannot contain ',', ':' and '?'.
- # We also keep track of the `allow_simple_key` flag here.
- # Indentation rules are loosed for the flow context.
- chunks = []
- start_mark = self.get_mark()
- end_mark = start_mark
- indent = self.indent+1
- # We allow zero indentation for scalars, but then we need to check for
- # document separators at the beginning of the line.
- #if indent == 0:
- # indent = 1
- spaces = []
- while True:
- length = 0
- if self.peek() == u'#':
- break
- while True:
- ch = self.peek(length)
- if ch in u'\0 \t\r\n\x85\u2028\u2029' \
- or (not self.flow_level and ch == u':' and
- self.peek(length+1) in u'\0 \t\r\n\x85\u2028\u2029') \
- or (self.flow_level and ch in u',:?[]{}'):
- break
- length += 1
- # It's not clear what we should do with ':' in the flow context.
- if (self.flow_level and ch == u':'
- and self.peek(length+1) not in u'\0 \t\r\n\x85\u2028\u2029,[]{}'):
- self.forward(length)
- raise ScannerError("while scanning a plain scalar", start_mark,
- "found unexpected ':'", self.get_mark(),
- "Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.")
- if length == 0:
- break
- self.allow_simple_key = False
- chunks.extend(spaces)
- chunks.append(self.prefix(length))
- self.forward(length)
- end_mark = self.get_mark()
- spaces = self.scan_plain_spaces(indent, start_mark)
- if not spaces or self.peek() == u'#' \
- or (not self.flow_level and self.column < indent):
- break
- return ScalarToken(u''.join(chunks), True, start_mark, end_mark)
-
- def scan_plain_spaces(self, indent, start_mark):
- # See the specification for details.
- # The specification is really confusing about tabs in plain scalars.
- # We just forbid them completely. Do not use tabs in YAML!
- chunks = []
- length = 0
- while self.peek(length) in u' ':
- length += 1
- whitespaces = self.prefix(length)
- self.forward(length)
- ch = self.peek()
- if ch in u'\r\n\x85\u2028\u2029':
- line_break = self.scan_line_break()
- self.allow_simple_key = True
- prefix = self.prefix(3)
- if (prefix == u'---' or prefix == u'...') \
- and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
- return
- breaks = []
- while self.peek() in u' \r\n\x85\u2028\u2029':
- if self.peek() == ' ':
- self.forward()
- else:
- breaks.append(self.scan_line_break())
- prefix = self.prefix(3)
- if (prefix == u'---' or prefix == u'...') \
- and self.peek(3) in u'\0 \t\r\n\x85\u2028\u2029':
- return
- if line_break != u'\n':
- chunks.append(line_break)
- elif not breaks:
- chunks.append(u' ')
- chunks.extend(breaks)
- elif whitespaces:
- chunks.append(whitespaces)
- return chunks
-
- def scan_tag_handle(self, name, start_mark):
- # See the specification for details.
- # For some strange reasons, the specification does not allow '_' in
- # tag handles. I have allowed it anyway.
- ch = self.peek()
- if ch != u'!':
- raise ScannerError("while scanning a %s" % name, start_mark,
- "expected '!', but found %r" % ch.encode('utf-8'),
- self.get_mark())
- length = 1
- ch = self.peek(length)
- if ch != u' ':
- while u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-_':
- length += 1
- ch = self.peek(length)
- if ch != u'!':
- self.forward(length)
- raise ScannerError("while scanning a %s" % name, start_mark,
- "expected '!', but found %r" % ch.encode('utf-8'),
- self.get_mark())
- length += 1
- value = self.prefix(length)
- self.forward(length)
- return value
-
- def scan_tag_uri(self, name, start_mark):
- # See the specification for details.
- # Note: we do not check if URI is well-formed.
- chunks = []
- length = 0
- ch = self.peek(length)
- while u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-;/?:@&=+$,_.!~*\'()[]%':
- if ch == u'%':
- chunks.append(self.prefix(length))
- self.forward(length)
- length = 0
- chunks.append(self.scan_uri_escapes(name, start_mark))
- else:
- length += 1
- ch = self.peek(length)
- if length:
- chunks.append(self.prefix(length))
- self.forward(length)
- length = 0
- if not chunks:
- raise ScannerError("while parsing a %s" % name, start_mark,
- "expected URI, but found %r" % ch.encode('utf-8'),
- self.get_mark())
- return u''.join(chunks)
-
- def scan_uri_escapes(self, name, start_mark):
- # See the specification for details.
- bytes = []
- mark = self.get_mark()
- while self.peek() == u'%':
- self.forward()
- for k in range(2):
- if self.peek(k) not in u'0123456789ABCDEFabcdef':
- raise ScannerError("while scanning a %s" % name, start_mark,
- "expected URI escape sequence of 2 hexdecimal numbers, but found %r" %
- (self.peek(k).encode('utf-8')), self.get_mark())
- bytes.append(chr(int(self.prefix(2), 16)))
- self.forward(2)
- try:
- value = unicode(''.join(bytes), 'utf-8')
- except UnicodeDecodeError, exc:
- raise ScannerError("while scanning a %s" % name, start_mark, str(exc), mark)
- return value
-
- def scan_line_break(self):
- # Transforms:
- # '\r\n' : '\n'
- # '\r' : '\n'
- # '\n' : '\n'
- # '\x85' : '\n'
- # '\u2028' : '\u2028'
- # '\u2029 : '\u2029'
- # default : ''
- ch = self.peek()
- if ch in u'\r\n\x85':
- if self.prefix(2) == u'\r\n':
- self.forward(2)
- else:
- self.forward()
- return u'\n'
- elif ch in u'\u2028\u2029':
- self.forward()
- return ch
- return u''
-
-#try:
-# import psyco
-# psyco.bind(Scanner)
-#except ImportError:
-# pass
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/serializer.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/serializer.py b/tools/bin/ext/yaml/serializer.py
deleted file mode 100644
index eb70372..0000000
--- a/tools/bin/ext/yaml/serializer.py
+++ /dev/null
@@ -1,127 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['Serializer', 'SerializerError']
-
-from error import YAMLError
-from events import *
-from nodes import *
-
-class SerializerError(YAMLError):
- pass
-
-class Serializer(object):
-
- ANCHOR_TEMPLATE = u'id%03d'
-
- def __init__(self, encoding=None,
- explicit_start=None, explicit_end=None, version=None, tags=None):
- self.use_encoding = encoding
- self.use_explicit_start = explicit_start
- self.use_explicit_end = explicit_end
- self.use_version = version
- self.use_tags = tags
- self.serialized_nodes = {}
- self.anchors = {}
- self.last_anchor_id = 0
- self.closed = None
-
- def open(self):
- if self.closed is None:
- self.emit(StreamStartEvent(encoding=self.use_encoding))
- self.closed = False
- elif self.closed:
- raise SerializerError("serializer is closed")
- else:
- raise SerializerError("serializer is already opened")
-
- def close(self):
- if self.closed is None:
- raise SerializerError("serializer is not opened")
- elif not self.closed:
- self.emit(StreamEndEvent())
- self.closed = True
-
- #def __del__(self):
- # self.close()
-
- def serialize(self, node):
- if self.closed is None:
- raise SerializerError("serializer is not opened")
- elif self.closed:
- raise SerializerError("serializer is closed")
- self.emit(DocumentStartEvent(explicit=self.use_explicit_start,
- version=self.use_version, tags=self.use_tags))
- self.anchor_node(node)
- self.serialize_node(node, None, None)
- self.emit(DocumentEndEvent(explicit=self.use_explicit_end))
- self.serialized_nodes = {}
- self.anchors = {}
- self.last_alias_id = 0
-
- def anchor_node(self, node):
- if node in self.anchors:
- if self.anchors[node] is None:
- self.anchors[node] = self.generate_anchor(node)
- else:
- self.anchors[node] = None
- if isinstance(node, SequenceNode):
- for item in node.value:
- self.anchor_node(item)
- elif isinstance(node, MappingNode):
- for key, value in node.value:
- self.anchor_node(key)
- self.anchor_node(value)
-
- def generate_anchor(self, node):
- self.last_anchor_id += 1
- return self.ANCHOR_TEMPLATE % self.last_anchor_id
-
- def serialize_node(self, node, parent, index):
- alias = self.anchors[node]
- if node in self.serialized_nodes:
- self.emit(AliasEvent(alias))
- else:
- self.serialized_nodes[node] = True
- self.descend_resolver(parent, index)
- if isinstance(node, ScalarNode):
- detected_tag = self.resolve(ScalarNode, node.value, (True, False))
- default_tag = self.resolve(ScalarNode, node.value, (False, True))
- implicit = (node.tag == detected_tag), (node.tag == default_tag)
- self.emit(ScalarEvent(alias, node.tag, implicit, node.value,
- style=node.style))
- elif isinstance(node, SequenceNode):
- implicit = (node.tag
- == self.resolve(SequenceNode, node.value, True))
- self.emit(SequenceStartEvent(alias, node.tag, implicit,
- flow_style=node.flow_style))
- index = 0
- for item in node.value:
- self.serialize_node(item, node, index)
- index += 1
- self.emit(SequenceEndEvent())
- elif isinstance(node, MappingNode):
- implicit = (node.tag
- == self.resolve(MappingNode, node.value, True))
- self.emit(MappingStartEvent(alias, node.tag, implicit,
- flow_style=node.flow_style))
- for key, value in node.value:
- self.serialize_node(key, node, None)
- self.serialize_node(value, node, key)
- self.emit(MappingEndEvent())
- self.ascend_resolver()
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/tokens.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/tokens.py b/tools/bin/ext/yaml/tokens.py
deleted file mode 100644
index 41ee0fb..0000000
--- a/tools/bin/ext/yaml/tokens.py
+++ /dev/null
@@ -1,120 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-class Token(object):
- def __init__(self, start_mark, end_mark):
- self.start_mark = start_mark
- self.end_mark = end_mark
- def __repr__(self):
- attributes = [key for key in self.__dict__
- if not key.endswith('_mark')]
- attributes.sort()
- arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
- for key in attributes])
- return '%s(%s)' % (self.__class__.__name__, arguments)
-
-#class BOMToken(Token):
-# id = '<byte order mark>'
-
-class DirectiveToken(Token):
- id = '<directive>'
- def __init__(self, name, value, start_mark, end_mark):
- self.name = name
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
-
-class DocumentStartToken(Token):
- id = '<document start>'
-
-class DocumentEndToken(Token):
- id = '<document end>'
-
-class StreamStartToken(Token):
- id = '<stream start>'
- def __init__(self, start_mark=None, end_mark=None,
- encoding=None):
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.encoding = encoding
-
-class StreamEndToken(Token):
- id = '<stream end>'
-
-class BlockSequenceStartToken(Token):
- id = '<block sequence start>'
-
-class BlockMappingStartToken(Token):
- id = '<block mapping start>'
-
-class BlockEndToken(Token):
- id = '<block end>'
-
-class FlowSequenceStartToken(Token):
- id = '['
-
-class FlowMappingStartToken(Token):
- id = '{'
-
-class FlowSequenceEndToken(Token):
- id = ']'
-
-class FlowMappingEndToken(Token):
- id = '}'
-
-class KeyToken(Token):
- id = '?'
-
-class ValueToken(Token):
- id = ':'
-
-class BlockEntryToken(Token):
- id = '-'
-
-class FlowEntryToken(Token):
- id = ','
-
-class AliasToken(Token):
- id = '<alias>'
- def __init__(self, value, start_mark, end_mark):
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
-
-class AnchorToken(Token):
- id = '<anchor>'
- def __init__(self, value, start_mark, end_mark):
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
-
-class TagToken(Token):
- id = '<tag>'
- def __init__(self, value, start_mark, end_mark):
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
-
-class ScalarToken(Token):
- id = '<scalar>'
- def __init__(self, value, plain, start_mark, end_mark, style=None):
- self.value = value
- self.plain = plain
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.style = style
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/generate-greenplum-path.sh
----------------------------------------------------------------------
diff --git a/tools/bin/generate-greenplum-path.sh b/tools/bin/generate-greenplum-path.sh
index 92c458d..3fcd2fb 100755
--- a/tools/bin/generate-greenplum-path.sh
+++ b/tools/bin/generate-greenplum-path.sh
@@ -91,7 +91,7 @@ fi
#setup PYTHONPATH
cat <<EOF
-PYTHONPATH=\$GPHOME/lib/python:\$PYTHONPATH
+PYTHONPATH=\$GPHOME/lib/python:\$GPHOME/lib/python/pygresql:\$PYTHONPATH
EOF
# openssl configuration file path
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gpcheck
----------------------------------------------------------------------
diff --git a/tools/bin/gpcheck b/tools/bin/gpcheck
index 5b7dcff..4125ed3 100755
--- a/tools/bin/gpcheck
+++ b/tools/bin/gpcheck
@@ -26,8 +26,8 @@ try:
from gppylib.commands.unix import getLocalHostname, getUserName, SYSTEM
from gppylib.commands.base import WorkerPool, Command, REMOTE
from gppylib.gpcheckutil import HostType, hosttype_str
- from pygresql.pgdb import DatabaseError
- from pygresql import pg
+ from pgdb import DatabaseError
+ import pg
except ImportError, e:
sys.exit('Cannot import modules. Please check that you have sourced greenplum_path.sh. Detail: ' + str(e))
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gpextract
----------------------------------------------------------------------
diff --git a/tools/bin/gpextract b/tools/bin/gpextract
index 9a2e182..be08117 100644
--- a/tools/bin/gpextract
+++ b/tools/bin/gpextract
@@ -93,8 +93,8 @@ try:
from gppylib.db import dbconn
from gppylib.gplog import get_default_logger, setup_tool_logging
from gppylib.gpparseopts import OptParser, OptChecker
- from pygresql import pg
- from pygresql.pgdb import DatabaseError
+ import pg
+ from pgdb import DatabaseError
import yaml
except ImportError, e:
print e
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gpload.py
----------------------------------------------------------------------
diff --git a/tools/bin/gpload.py b/tools/bin/gpload.py
index bde5d6c..454da7a 100755
--- a/tools/bin/gpload.py
+++ b/tools/bin/gpload.py
@@ -49,7 +49,7 @@ except ImportError:
sys.exit(2)
try:
- from pygresql import pg
+ import pg
except Exception, e:
errorMsg = "gpload was unable to import The PyGreSQL Python module (pg.py) - %s\n" % str(e)
sys.stderr.write(str(errorMsg))
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gppylib/commands/base.py
----------------------------------------------------------------------
diff --git a/tools/bin/gppylib/commands/base.py b/tools/bin/gppylib/commands/base.py
index 801d85f..132c108 100755
--- a/tools/bin/gppylib/commands/base.py
+++ b/tools/bin/gppylib/commands/base.py
@@ -42,7 +42,7 @@ import time
from gppylib import gplog
from gppylib import gpsubprocess
-from pygresql.pg import DB
+#from pg import DB
# paramiko prints deprecation warnings which are ugly to the end-user
import warnings
@@ -697,11 +697,19 @@ class Command:
def run(self,validateAfter=False):
faultPoint = os.getenv('GP_COMMAND_FAULT_POINT')
+ print "### DEBUG: ENV[GP_COMMAND_FAULT_POINT] = %s" % (faultPoint if faultPoint else "None")
+ print "### DEBUG: self.name = %s" % ("SomeName" if self.name else "None")
if not faultPoint or (self.name and not self.name.startswith(faultPoint)):
+ print "### DEBUG: EXECUTE name = %s" % ("SomeName" if self.name else "None")
+ print "### DEBUG: EXECUTE cmdStr = %s" % ("SomeCmdStr" if self.cmdStr else "None")
+ print "### DEBUG: EXECUTE context = %s" % ("SomeExecContext" if self.exec_context else "None")
+ print "### DEBUG: EXECUTE remoteHost = %s" % ("SomeRemoteHost" if self.remoteHost else "None")
self.exec_context.execute(self)
else:
# simulate error
+ print "### DEBUG: CommandResult"
self.results = CommandResult(1,'Fault Injection','Fault Injection' ,False,True)
+ print self.results
if validateAfter:
self.validate()
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gppylib/db/dbconn.py
----------------------------------------------------------------------
diff --git a/tools/bin/gppylib/db/dbconn.py b/tools/bin/gppylib/db/dbconn.py
index 6a474ce..0d2209a 100644
--- a/tools/bin/gppylib/db/dbconn.py
+++ b/tools/bin/gppylib/db/dbconn.py
@@ -24,7 +24,7 @@ import os
import stat
try:
- from pygresql import pgdb
+ import pgdb
from gppylib.commands.unix import UserId
except ImportError, e:
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gppylib/operations/gpMigratorUtil.py
----------------------------------------------------------------------
diff --git a/tools/bin/gppylib/operations/gpMigratorUtil.py b/tools/bin/gppylib/operations/gpMigratorUtil.py
index a6c8c36..73c5637 100644
--- a/tools/bin/gppylib/operations/gpMigratorUtil.py
+++ b/tools/bin/gppylib/operations/gpMigratorUtil.py
@@ -27,7 +27,7 @@ from threading import Thread
from Queue import Queue
import urllib # for passing strings across gpssh
import shutil # for copying
-from pygresql import pg # Database interaction
+import pg # Database interaction
from gppylib.gplog import * # Greenplum logging facility
from gppylib.commands import base # Greenplum layer for worker pools
from gppylib.commands import unix # Greenplum layer for unix interaction
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gppylib/operations/test_utils_helper.py
----------------------------------------------------------------------
diff --git a/tools/bin/gppylib/operations/test_utils_helper.py b/tools/bin/gppylib/operations/test_utils_helper.py
index 51be194..3cefe97 100755
--- a/tools/bin/gppylib/operations/test_utils_helper.py
+++ b/tools/bin/gppylib/operations/test_utils_helper.py
@@ -58,5 +58,5 @@ class ExceptionWithArgsUnsafe(Exception):
class RaiseOperation_Unpicklable(Operation):
def execute(self):
- from pygresql import pg
+ import pg
raise pg.DatabaseError()
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/gppylib/test/regress/test_regress_pygresql.py
----------------------------------------------------------------------
diff --git a/tools/bin/gppylib/test/regress/test_regress_pygresql.py b/tools/bin/gppylib/test/regress/test_regress_pygresql.py
index e086265..5b5a8b0 100755
--- a/tools/bin/gppylib/test/regress/test_regress_pygresql.py
+++ b/tools/bin/gppylib/test/regress/test_regress_pygresql.py
@@ -22,8 +22,8 @@ import logging
import unittest2 as unittest
-from pygresql import pg
-from pygresql import pgdb
+import pg
+import pgdb
from gppylib import gplog
from gppylib.db.dbconn import *
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/hawq_ctl
----------------------------------------------------------------------
diff --git a/tools/bin/hawq_ctl b/tools/bin/hawq_ctl
index 036f8ea..375c7fa 100755
--- a/tools/bin/hawq_ctl
+++ b/tools/bin/hawq_ctl
@@ -38,7 +38,7 @@ try:
check_syncmaster_running, create_cluster_directory
from hawqpylib.HAWQ_HELP import *
from gppylib.db import dbconn
- from pygresql.pg import DatabaseError
+ from pg import DatabaseError
except ImportError, e:
sys.exit('ERROR: Cannot import modules. Please check that you '
'have sourced greenplum_path.sh. Detail: ' + str(e))
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/hawqconfig
----------------------------------------------------------------------
diff --git a/tools/bin/hawqconfig b/tools/bin/hawqconfig
index f425972..9bbdf5d 100755
--- a/tools/bin/hawqconfig
+++ b/tools/bin/hawqconfig
@@ -20,7 +20,7 @@ import os, sys, re
from optparse import Option, OptionParser
from hawqpylib.hawqlib import HawqXMLParser, parse_hosts_file, remove_property_xml
from gppylib.db import dbconn
-from pygresql.pg import DatabaseError
+from pg import DatabaseError
def parseargs():
parser = OptionParser(usage="HAWQ config options.")
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/hawqextract
----------------------------------------------------------------------
diff --git a/tools/bin/hawqextract b/tools/bin/hawqextract
index 9a2e182..be08117 100755
--- a/tools/bin/hawqextract
+++ b/tools/bin/hawqextract
@@ -93,8 +93,8 @@ try:
from gppylib.db import dbconn
from gppylib.gplog import get_default_logger, setup_tool_logging
from gppylib.gpparseopts import OptParser, OptChecker
- from pygresql import pg
- from pygresql.pgdb import DatabaseError
+ import pg
+ from pgdb import DatabaseError
import yaml
except ImportError, e:
print e
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/hawqfilespace
----------------------------------------------------------------------
diff --git a/tools/bin/hawqfilespace b/tools/bin/hawqfilespace
index eba7c5b..ab9dc9c 100755
--- a/tools/bin/hawqfilespace
+++ b/tools/bin/hawqfilespace
@@ -63,7 +63,7 @@ try:
from gppylib.commands import unix
from gppylib.db import dbconn
from gppylib.db import catalog
- from pygresql import pg # Database interaction
+ import pg # Database interaction
from gppylib.gplog import * # Greenplum logging facility
from getpass import getpass
from gppylib.parseutils import line_reader, parse_fspacename, parse_dfs_url, parse_fspacesys, parse_fspacereplica, parse_gpfilespace_line, \
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/hawqstate
----------------------------------------------------------------------
diff --git a/tools/bin/hawqstate b/tools/bin/hawqstate
index 3344f20..feffb89 100755
--- a/tools/bin/hawqstate
+++ b/tools/bin/hawqstate
@@ -21,7 +21,7 @@ import sys
from optparse import Option, OptionParser
from hawqpylib.hawqlib import HawqXMLParser, parse_hosts_file, check_file_exist_list
from gppylib.db import dbconn
-from pygresql.pg import DatabaseError
+from pg import DatabaseError
from gppylib.gplog import get_default_logger, setup_hawq_tool_logging, quiet_stdout_logging, enable_verbose_logging
from gppylib.commands.unix import getLocalHostname, getUserName
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/lib/gpcheckcat
----------------------------------------------------------------------
diff --git a/tools/bin/lib/gpcheckcat b/tools/bin/lib/gpcheckcat
index a7c2f16..186f9c5 100755
--- a/tools/bin/lib/gpcheckcat
+++ b/tools/bin/lib/gpcheckcat
@@ -46,8 +46,8 @@ try:
from gppylib.gplog import *
from gppylib.gpcatalog import *
from gppylib.commands.unix import *
- from pygresql.pgdb import DatabaseError
- from pygresql import pg
+ from pgdb import DatabaseError
+ import pg
except ImportError, e:
sys.exit('Error: unable to import module: ' + str(e))
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/.gitignore
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/.gitignore b/tools/bin/pythonSrc/.gitignore
deleted file mode 100644
index df40d44..0000000
--- a/tools/bin/pythonSrc/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-lockfile-0.9.1
-paramiko-1.7.6-9
-PSI-0.3b2_gp
-pychecker-0.8.18
-pycrypto-2.0.1
-PyGreSQL-4.0
-unittest2-0.5.1
-._paramiko-1.7.6-9
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PSI-0.3b2_gp.tar.gz
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PSI-0.3b2_gp.tar.gz b/tools/bin/pythonSrc/PSI-0.3b2_gp.tar.gz
deleted file mode 100644
index 303d225..0000000
Binary files a/tools/bin/pythonSrc/PSI-0.3b2_gp.tar.gz and /dev/null differ
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.html
deleted file mode 100644
index 2683a15..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL Announcements</title>
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-announcements">
-<h1 class="title">PyGreSQL Announcements</h1>
-<h2 class="subtitle" id="release-of-pygresql-version-4-0">Release of PyGreSQL version 4.0</h2>
-<p>PyGreSQL v4.0 has been released.</p>
-<p>It is available at: <a class="reference" href="ftp://ftp.PyGreSQL.org/pub/distrib/PyGreSQL-4.0.tgz">ftp://ftp.PyGreSQL.org/pub/distrib/PyGreSQL-4.0.tgz</a>.</p>
-<p>If you are running NetBSD, look in the packages directory under databases.
-There is also a package in the FreeBSD ports collection.</p>
-<p>Please refer to <a class="reference" href="changelog.html">changelog.txt</a>
-for things that have changed in this version.</p>
-<p>Please refer to <a class="reference" href="readme.html">readme.txt</a>
-for general information.</p>
-<div class="line-block">
-<div class="line">D'Arcy J.M. Cain</div>
-<div class="line"><a class="reference" href="mailto:darcy@PyGreSQL.org">darcy@PyGreSQL.org</a></div>
-</div>
-</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.txt
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.txt b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.txt
deleted file mode 100644
index fa08458..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/announce.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-======================
-PyGreSQL Announcements
-======================
-
--------------------------------
-Release of PyGreSQL version 4.0
--------------------------------
-
-PyGreSQL v4.0 has been released.
-
-It is available at: ftp://ftp.PyGreSQL.org/pub/distrib/PyGreSQL-4.0.tgz.
-
-If you are running NetBSD, look in the packages directory under databases.
-There is also a package in the FreeBSD ports collection.
-
-Please refer to `changelog.txt <changelog.html>`_
-for things that have changed in this version.
-
-Please refer to `readme.txt <readme.html>`_
-for general information.
-
-| D'Arcy J.M. Cain
-| darcy@PyGreSQL.org
[08/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/loader.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/loader.py b/tools/bin/ext/yaml/loader.py
deleted file mode 100644
index 29461f4..0000000
--- a/tools/bin/ext/yaml/loader.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['BaseLoader', 'SafeLoader', 'Loader']
-
-from reader import *
-from scanner import *
-from parser import *
-from composer import *
-from constructor import *
-from resolver import *
-
-class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, BaseResolver):
-
- def __init__(self, stream):
- Reader.__init__(self, stream)
- Scanner.__init__(self)
- Parser.__init__(self)
- Composer.__init__(self)
- BaseConstructor.__init__(self)
- BaseResolver.__init__(self)
-
-class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, Resolver):
-
- def __init__(self, stream):
- Reader.__init__(self, stream)
- Scanner.__init__(self)
- Parser.__init__(self)
- Composer.__init__(self)
- SafeConstructor.__init__(self)
- Resolver.__init__(self)
-
-class Loader(Reader, Scanner, Parser, Composer, Constructor, Resolver):
-
- def __init__(self, stream):
- Reader.__init__(self, stream)
- Scanner.__init__(self)
- Parser.__init__(self)
- Composer.__init__(self)
- Constructor.__init__(self)
- Resolver.__init__(self)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/nodes.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/nodes.py b/tools/bin/ext/yaml/nodes.py
deleted file mode 100644
index 3fdfbe6..0000000
--- a/tools/bin/ext/yaml/nodes.py
+++ /dev/null
@@ -1,65 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-class Node(object):
- def __init__(self, tag, value, start_mark, end_mark):
- self.tag = tag
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
- def __repr__(self):
- value = self.value
- #if isinstance(value, list):
- # if len(value) == 0:
- # value = '<empty>'
- # elif len(value) == 1:
- # value = '<1 item>'
- # else:
- # value = '<%d items>' % len(value)
- #else:
- # if len(value) > 75:
- # value = repr(value[:70]+u' ... ')
- # else:
- # value = repr(value)
- value = repr(value)
- return '%s(tag=%r, value=%s)' % (self.__class__.__name__, self.tag, value)
-
-class ScalarNode(Node):
- id = 'scalar'
- def __init__(self, tag, value,
- start_mark=None, end_mark=None, style=None):
- self.tag = tag
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.style = style
-
-class CollectionNode(Node):
- def __init__(self, tag, value,
- start_mark=None, end_mark=None, flow_style=None):
- self.tag = tag
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.flow_style = flow_style
-
-class SequenceNode(CollectionNode):
- id = 'sequence'
-
-class MappingNode(CollectionNode):
- id = 'mapping'
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/parser.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/parser.py b/tools/bin/ext/yaml/parser.py
deleted file mode 100644
index a1228f6..0000000
--- a/tools/bin/ext/yaml/parser.py
+++ /dev/null
@@ -1,602 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# The following YAML grammar is LL(1) and is parsed by a recursive descent
-# parser.
-#
-# stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
-# implicit_document ::= block_node DOCUMENT-END*
-# explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
-# block_node_or_indentless_sequence ::=
-# ALIAS
-# | properties (block_content | indentless_block_sequence)?
-# | block_content
-# | indentless_block_sequence
-# block_node ::= ALIAS
-# | properties block_content?
-# | block_content
-# flow_node ::= ALIAS
-# | properties flow_content?
-# | flow_content
-# properties ::= TAG ANCHOR? | ANCHOR TAG?
-# block_content ::= block_collection | flow_collection | SCALAR
-# flow_content ::= flow_collection | SCALAR
-# block_collection ::= block_sequence | block_mapping
-# flow_collection ::= flow_sequence | flow_mapping
-# block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END
-# indentless_sequence ::= (BLOCK-ENTRY block_node?)+
-# block_mapping ::= BLOCK-MAPPING_START
-# ((KEY block_node_or_indentless_sequence?)?
-# (VALUE block_node_or_indentless_sequence?)?)*
-# BLOCK-END
-# flow_sequence ::= FLOW-SEQUENCE-START
-# (flow_sequence_entry FLOW-ENTRY)*
-# flow_sequence_entry?
-# FLOW-SEQUENCE-END
-# flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
-# flow_mapping ::= FLOW-MAPPING-START
-# (flow_mapping_entry FLOW-ENTRY)*
-# flow_mapping_entry?
-# FLOW-MAPPING-END
-# flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
-#
-# FIRST sets:
-#
-# stream: { STREAM-START }
-# explicit_document: { DIRECTIVE DOCUMENT-START }
-# implicit_document: FIRST(block_node)
-# block_node: { ALIAS TAG ANCHOR SCALAR BLOCK-SEQUENCE-START BLOCK-MAPPING-START FLOW-SEQUENCE-START FLOW-MAPPING-START }
-# flow_node: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START }
-# block_content: { BLOCK-SEQUENCE-START BLOCK-MAPPING-START FLOW-SEQUENCE-START FLOW-MAPPING-START SCALAR }
-# flow_content: { FLOW-SEQUENCE-START FLOW-MAPPING-START SCALAR }
-# block_collection: { BLOCK-SEQUENCE-START BLOCK-MAPPING-START }
-# flow_collection: { FLOW-SEQUENCE-START FLOW-MAPPING-START }
-# block_sequence: { BLOCK-SEQUENCE-START }
-# block_mapping: { BLOCK-MAPPING-START }
-# block_node_or_indentless_sequence: { ALIAS ANCHOR TAG SCALAR BLOCK-SEQUENCE-START BLOCK-MAPPING-START FLOW-SEQUENCE-START FLOW-MAPPING-START BLOCK-ENTRY }
-# indentless_sequence: { ENTRY }
-# flow_collection: { FLOW-SEQUENCE-START FLOW-MAPPING-START }
-# flow_sequence: { FLOW-SEQUENCE-START }
-# flow_mapping: { FLOW-MAPPING-START }
-# flow_sequence_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY }
-# flow_mapping_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY }
-
-__all__ = ['Parser', 'ParserError']
-
-from error import MarkedYAMLError
-from tokens import *
-from events import *
-from scanner import *
-
-class ParserError(MarkedYAMLError):
- pass
-
-class Parser(object):
- # Since writing a recursive-descendant parser is a straightforward task, we
- # do not give many comments here.
- # Note that we use Python generators. If you rewrite the parser in another
- # language, you may replace all 'yield'-s with event handler calls.
-
- DEFAULT_TAGS = {
- u'!': u'!',
- u'!!': u'tag:yaml.org,2002:',
- }
-
- def __init__(self):
- self.current_event = None
- self.yaml_version = None
- self.tag_handles = {}
- self.states = []
- self.marks = []
- self.state = self.parse_stream_start
-
- def check_event(self, *choices):
- # Check the type of the next event.
- if self.current_event is None:
- if self.state:
- self.current_event = self.state()
- if self.current_event is not None:
- if not choices:
- return True
- for choice in choices:
- if isinstance(self.current_event, choice):
- return True
- return False
-
- def peek_event(self):
- # Get the next event.
- if self.current_event is None:
- if self.state:
- self.current_event = self.state()
- return self.current_event
-
- def get_event(self):
- # Get the next event and proceed further.
- if self.current_event is None:
- if self.state:
- self.current_event = self.state()
- value = self.current_event
- self.current_event = None
- return value
-
- # stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
- # implicit_document ::= block_node DOCUMENT-END*
- # explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
-
- def parse_stream_start(self):
-
- # Parse the stream start.
- token = self.get_token()
- event = StreamStartEvent(token.start_mark, token.end_mark,
- encoding=token.encoding)
-
- # Prepare the next state.
- self.state = self.parse_implicit_document_start
-
- return event
-
- def parse_implicit_document_start(self):
-
- # Parse an implicit document.
- if not self.check_token(DirectiveToken, DocumentStartToken,
- StreamEndToken):
- self.tag_handles = self.DEFAULT_TAGS
- token = self.peek_token()
- start_mark = end_mark = token.start_mark
- event = DocumentStartEvent(start_mark, end_mark,
- explicit=False)
-
- # Prepare the next state.
- self.states.append(self.parse_document_end)
- self.state = self.parse_block_node
-
- return event
-
- else:
- return self.parse_document_start()
-
- def parse_document_start(self):
-
- # Parse any extra document end indicators.
- while self.check_token(DocumentEndToken):
- self.get_token()
-
- # Parse an explicit document.
- if not self.check_token(StreamEndToken):
- token = self.peek_token()
- start_mark = token.start_mark
- version, tags = self.process_directives()
- if not self.check_token(DocumentStartToken):
- raise ParserError(None, None,
- "expected '<document start>', but found %r"
- % self.peek_token().id,
- self.peek_token().start_mark)
- token = self.get_token()
- end_mark = token.end_mark
- event = DocumentStartEvent(start_mark, end_mark,
- explicit=True, version=version, tags=tags)
- self.states.append(self.parse_document_end)
- self.state = self.parse_document_content
- else:
- # Parse the end of the stream.
- token = self.get_token()
- event = StreamEndEvent(token.start_mark, token.end_mark)
- assert not self.states
- assert not self.marks
- self.state = None
- return event
-
- def parse_document_end(self):
-
- # Parse the document end.
- token = self.peek_token()
- start_mark = end_mark = token.start_mark
- explicit = False
- if self.check_token(DocumentEndToken):
- token = self.get_token()
- end_mark = token.end_mark
- explicit = True
- event = DocumentEndEvent(start_mark, end_mark,
- explicit=explicit)
-
- # Prepare the next state.
- self.state = self.parse_document_start
-
- return event
-
- def parse_document_content(self):
- if self.check_token(DirectiveToken,
- DocumentStartToken, DocumentEndToken, StreamEndToken):
- event = self.process_empty_scalar(self.peek_token().start_mark)
- self.state = self.states.pop()
- return event
- else:
- return self.parse_block_node()
-
- def process_directives(self):
- self.yaml_version = None
- self.tag_handles = {}
- while self.check_token(DirectiveToken):
- token = self.get_token()
- if token.name == u'YAML':
- if self.yaml_version is not None:
- raise ParserError(None, None,
- "found duplicate YAML directive", token.start_mark)
- major, minor = token.value
- if major != 1:
- raise ParserError(None, None,
- "found incompatible YAML document (version 1.* is required)",
- token.start_mark)
- self.yaml_version = token.value
- elif token.name == u'TAG':
- handle, prefix = token.value
- if handle in self.tag_handles:
- raise ParserError(None, None,
- "duplicate tag handle %r" % handle.encode('utf-8'),
- token.start_mark)
- self.tag_handles[handle] = prefix
- if self.tag_handles:
- value = self.yaml_version, self.tag_handles.copy()
- else:
- value = self.yaml_version, None
- for key in self.DEFAULT_TAGS:
- if key not in self.tag_handles:
- self.tag_handles[key] = self.DEFAULT_TAGS[key]
- return value
-
- # block_node_or_indentless_sequence ::= ALIAS
- # | properties (block_content | indentless_block_sequence)?
- # | block_content
- # | indentless_block_sequence
- # block_node ::= ALIAS
- # | properties block_content?
- # | block_content
- # flow_node ::= ALIAS
- # | properties flow_content?
- # | flow_content
- # properties ::= TAG ANCHOR? | ANCHOR TAG?
- # block_content ::= block_collection | flow_collection | SCALAR
- # flow_content ::= flow_collection | SCALAR
- # block_collection ::= block_sequence | block_mapping
- # flow_collection ::= flow_sequence | flow_mapping
-
- def parse_block_node(self):
- return self.parse_node(block=True)
-
- def parse_flow_node(self):
- return self.parse_node()
-
- def parse_block_node_or_indentless_sequence(self):
- return self.parse_node(block=True, indentless_sequence=True)
-
- def parse_node(self, block=False, indentless_sequence=False):
- if self.check_token(AliasToken):
- token = self.get_token()
- event = AliasEvent(token.value, token.start_mark, token.end_mark)
- self.state = self.states.pop()
- else:
- anchor = None
- tag = None
- start_mark = end_mark = tag_mark = None
- if self.check_token(AnchorToken):
- token = self.get_token()
- start_mark = token.start_mark
- end_mark = token.end_mark
- anchor = token.value
- if self.check_token(TagToken):
- token = self.get_token()
- tag_mark = token.start_mark
- end_mark = token.end_mark
- tag = token.value
- elif self.check_token(TagToken):
- token = self.get_token()
- start_mark = tag_mark = token.start_mark
- end_mark = token.end_mark
- tag = token.value
- if self.check_token(AnchorToken):
- token = self.get_token()
- end_mark = token.end_mark
- anchor = token.value
- if tag is not None:
- handle, suffix = tag
- if handle is not None:
- if handle not in self.tag_handles:
- raise ParserError("while parsing a node", start_mark,
- "found undefined tag handle %r" % handle.encode('utf-8'),
- tag_mark)
- tag = self.tag_handles[handle]+suffix
- else:
- tag = suffix
- #if tag == u'!':
- # raise ParserError("while parsing a node", start_mark,
- # "found non-specific tag '!'", tag_mark,
- # "Please check 'http://pyyaml.org/wiki/YAMLNonSpecificTag' and share your opinion.")
- if start_mark is None:
- start_mark = end_mark = self.peek_token().start_mark
- event = None
- implicit = (tag is None or tag == u'!')
- if indentless_sequence and self.check_token(BlockEntryToken):
- end_mark = self.peek_token().end_mark
- event = SequenceStartEvent(anchor, tag, implicit,
- start_mark, end_mark)
- self.state = self.parse_indentless_sequence_entry
- else:
- if self.check_token(ScalarToken):
- token = self.get_token()
- end_mark = token.end_mark
- if (token.plain and tag is None) or tag == u'!':
- implicit = (True, False)
- elif tag is None:
- implicit = (False, True)
- else:
- implicit = (False, False)
- event = ScalarEvent(anchor, tag, implicit, token.value,
- start_mark, end_mark, style=token.style)
- self.state = self.states.pop()
- elif self.check_token(FlowSequenceStartToken):
- end_mark = self.peek_token().end_mark
- event = SequenceStartEvent(anchor, tag, implicit,
- start_mark, end_mark, flow_style=True)
- self.state = self.parse_flow_sequence_first_entry
- elif self.check_token(FlowMappingStartToken):
- end_mark = self.peek_token().end_mark
- event = MappingStartEvent(anchor, tag, implicit,
- start_mark, end_mark, flow_style=True)
- self.state = self.parse_flow_mapping_first_key
- elif block and self.check_token(BlockSequenceStartToken):
- end_mark = self.peek_token().start_mark
- event = SequenceStartEvent(anchor, tag, implicit,
- start_mark, end_mark, flow_style=False)
- self.state = self.parse_block_sequence_first_entry
- elif block and self.check_token(BlockMappingStartToken):
- end_mark = self.peek_token().start_mark
- event = MappingStartEvent(anchor, tag, implicit,
- start_mark, end_mark, flow_style=False)
- self.state = self.parse_block_mapping_first_key
- elif anchor is not None or tag is not None:
- # Empty scalars are allowed even if a tag or an anchor is
- # specified.
- event = ScalarEvent(anchor, tag, (implicit, False), u'',
- start_mark, end_mark)
- self.state = self.states.pop()
- else:
- if block:
- node = 'block'
- else:
- node = 'flow'
- token = self.peek_token()
- raise ParserError("while parsing a %s node" % node, start_mark,
- "expected the node content, but found %r" % token.id,
- token.start_mark)
- return event
-
- # block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END
-
- def parse_block_sequence_first_entry(self):
- token = self.get_token()
- self.marks.append(token.start_mark)
- return self.parse_block_sequence_entry()
-
- def parse_block_sequence_entry(self):
- if self.check_token(BlockEntryToken):
- token = self.get_token()
- if not self.check_token(BlockEntryToken, BlockEndToken):
- self.states.append(self.parse_block_sequence_entry)
- return self.parse_block_node()
- else:
- self.state = self.parse_block_sequence_entry
- return self.process_empty_scalar(token.end_mark)
- if not self.check_token(BlockEndToken):
- token = self.peek_token()
- raise ParserError("while parsing a block collection", self.marks[-1],
- "expected <block end>, but found %r" % token.id, token.start_mark)
- token = self.get_token()
- event = SequenceEndEvent(token.start_mark, token.end_mark)
- self.state = self.states.pop()
- self.marks.pop()
- return event
-
- # indentless_sequence ::= (BLOCK-ENTRY block_node?)+
-
- def parse_indentless_sequence_entry(self):
- if self.check_token(BlockEntryToken):
- token = self.get_token()
- if not self.check_token(BlockEntryToken,
- KeyToken, ValueToken, BlockEndToken):
- self.states.append(self.parse_indentless_sequence_entry)
- return self.parse_block_node()
- else:
- self.state = self.parse_indentless_sequence_entry
- return self.process_empty_scalar(token.end_mark)
- token = self.peek_token()
- event = SequenceEndEvent(token.start_mark, token.start_mark)
- self.state = self.states.pop()
- return event
-
- # block_mapping ::= BLOCK-MAPPING_START
- # ((KEY block_node_or_indentless_sequence?)?
- # (VALUE block_node_or_indentless_sequence?)?)*
- # BLOCK-END
-
- def parse_block_mapping_first_key(self):
- token = self.get_token()
- self.marks.append(token.start_mark)
- return self.parse_block_mapping_key()
-
- def parse_block_mapping_key(self):
- if self.check_token(KeyToken):
- token = self.get_token()
- if not self.check_token(KeyToken, ValueToken, BlockEndToken):
- self.states.append(self.parse_block_mapping_value)
- return self.parse_block_node_or_indentless_sequence()
- else:
- self.state = self.parse_block_mapping_value
- return self.process_empty_scalar(token.end_mark)
- if not self.check_token(BlockEndToken):
- token = self.peek_token()
- raise ParserError("while parsing a block mapping", self.marks[-1],
- "expected <block end>, but found %r" % token.id, token.start_mark)
- token = self.get_token()
- event = MappingEndEvent(token.start_mark, token.end_mark)
- self.state = self.states.pop()
- self.marks.pop()
- return event
-
- def parse_block_mapping_value(self):
- if self.check_token(ValueToken):
- token = self.get_token()
- if not self.check_token(KeyToken, ValueToken, BlockEndToken):
- self.states.append(self.parse_block_mapping_key)
- return self.parse_block_node_or_indentless_sequence()
- else:
- self.state = self.parse_block_mapping_key
- return self.process_empty_scalar(token.end_mark)
- else:
- self.state = self.parse_block_mapping_key
- token = self.peek_token()
- return self.process_empty_scalar(token.start_mark)
-
- # flow_sequence ::= FLOW-SEQUENCE-START
- # (flow_sequence_entry FLOW-ENTRY)*
- # flow_sequence_entry?
- # FLOW-SEQUENCE-END
- # flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- #
- # Note that while production rules for both flow_sequence_entry and
- # flow_mapping_entry are equal, their interpretations are different.
- # For `flow_sequence_entry`, the part `KEY flow_node? (VALUE flow_node?)?`
- # generate an inline mapping (set syntax).
-
- def parse_flow_sequence_first_entry(self):
- token = self.get_token()
- self.marks.append(token.start_mark)
- return self.parse_flow_sequence_entry(first=True)
-
- def parse_flow_sequence_entry(self, first=False):
- if not self.check_token(FlowSequenceEndToken):
- if not first:
- if self.check_token(FlowEntryToken):
- self.get_token()
- else:
- token = self.peek_token()
- raise ParserError("while parsing a flow sequence", self.marks[-1],
- "expected ',' or ']', but got %r" % token.id, token.start_mark)
-
- if self.check_token(KeyToken):
- token = self.peek_token()
- event = MappingStartEvent(None, None, True,
- token.start_mark, token.end_mark,
- flow_style=True)
- self.state = self.parse_flow_sequence_entry_mapping_key
- return event
- elif not self.check_token(FlowSequenceEndToken):
- self.states.append(self.parse_flow_sequence_entry)
- return self.parse_flow_node()
- token = self.get_token()
- event = SequenceEndEvent(token.start_mark, token.end_mark)
- self.state = self.states.pop()
- self.marks.pop()
- return event
-
- def parse_flow_sequence_entry_mapping_key(self):
- token = self.get_token()
- if not self.check_token(ValueToken,
- FlowEntryToken, FlowSequenceEndToken):
- self.states.append(self.parse_flow_sequence_entry_mapping_value)
- return self.parse_flow_node()
- else:
- self.state = self.parse_flow_sequence_entry_mapping_value
- return self.process_empty_scalar(token.end_mark)
-
- def parse_flow_sequence_entry_mapping_value(self):
- if self.check_token(ValueToken):
- token = self.get_token()
- if not self.check_token(FlowEntryToken, FlowSequenceEndToken):
- self.states.append(self.parse_flow_sequence_entry_mapping_end)
- return self.parse_flow_node()
- else:
- self.state = self.parse_flow_sequence_entry_mapping_end
- return self.process_empty_scalar(token.end_mark)
- else:
- self.state = self.parse_flow_sequence_entry_mapping_end
- token = self.peek_token()
- return self.process_empty_scalar(token.start_mark)
-
- def parse_flow_sequence_entry_mapping_end(self):
- self.state = self.parse_flow_sequence_entry
- token = self.peek_token()
- return MappingEndEvent(token.start_mark, token.start_mark)
-
- # flow_mapping ::= FLOW-MAPPING-START
- # (flow_mapping_entry FLOW-ENTRY)*
- # flow_mapping_entry?
- # FLOW-MAPPING-END
- # flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
-
- def parse_flow_mapping_first_key(self):
- token = self.get_token()
- self.marks.append(token.start_mark)
- return self.parse_flow_mapping_key(first=True)
-
- def parse_flow_mapping_key(self, first=False):
- if not self.check_token(FlowMappingEndToken):
- if not first:
- if self.check_token(FlowEntryToken):
- self.get_token()
- else:
- token = self.peek_token()
- raise ParserError("while parsing a flow mapping", self.marks[-1],
- "expected ',' or '}', but got %r" % token.id, token.start_mark)
- if self.check_token(KeyToken):
- token = self.get_token()
- if not self.check_token(ValueToken,
- FlowEntryToken, FlowMappingEndToken):
- self.states.append(self.parse_flow_mapping_value)
- return self.parse_flow_node()
- else:
- self.state = self.parse_flow_mapping_value
- return self.process_empty_scalar(token.end_mark)
- elif not self.check_token(FlowMappingEndToken):
- self.states.append(self.parse_flow_mapping_empty_value)
- return self.parse_flow_node()
- token = self.get_token()
- event = MappingEndEvent(token.start_mark, token.end_mark)
- self.state = self.states.pop()
- self.marks.pop()
- return event
-
- def parse_flow_mapping_value(self):
- if self.check_token(ValueToken):
- token = self.get_token()
- if not self.check_token(FlowEntryToken, FlowMappingEndToken):
- self.states.append(self.parse_flow_mapping_key)
- return self.parse_flow_node()
- else:
- self.state = self.parse_flow_mapping_key
- return self.process_empty_scalar(token.end_mark)
- else:
- self.state = self.parse_flow_mapping_key
- token = self.peek_token()
- return self.process_empty_scalar(token.start_mark)
-
- def parse_flow_mapping_empty_value(self):
- self.state = self.parse_flow_mapping_key
- return self.process_empty_scalar(self.peek_token().start_mark)
-
- def process_empty_scalar(self, mark):
- return ScalarEvent(None, None, (True, False), u'', mark, mark)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/reader.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/reader.py b/tools/bin/ext/yaml/reader.py
deleted file mode 100644
index f36e647..0000000
--- a/tools/bin/ext/yaml/reader.py
+++ /dev/null
@@ -1,241 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# This module contains abstractions for the input stream. You don't have to
-# looks further, there are no pretty code.
-#
-# We define two classes here.
-#
-# Mark(source, line, column)
-# It's just a record and its only use is producing nice error messages.
-# Parser does not use it for any other purposes.
-#
-# Reader(source, data)
-# Reader determines the encoding of `data` and converts it to unicode.
-# Reader provides the following methods and attributes:
-# reader.peek(length=1) - return the next `length` characters
-# reader.forward(length=1) - move the current position to `length` characters.
-# reader.index - the number of the current character.
-# reader.line, stream.column - the line and the column of the current character.
-
-__all__ = ['Reader', 'ReaderError']
-
-from error import YAMLError, Mark
-
-import codecs, re
-
-# Unfortunately, codec functions in Python 2.3 does not support the `finish`
-# arguments, so we have to write our own wrappers.
-
-try:
- codecs.utf_8_decode('', 'strict', False)
- from codecs import utf_8_decode, utf_16_le_decode, utf_16_be_decode
-
-except TypeError:
-
- def utf_16_le_decode(data, errors, finish=False):
- if not finish and len(data) % 2 == 1:
- data = data[:-1]
- return codecs.utf_16_le_decode(data, errors)
-
- def utf_16_be_decode(data, errors, finish=False):
- if not finish and len(data) % 2 == 1:
- data = data[:-1]
- return codecs.utf_16_be_decode(data, errors)
-
- def utf_8_decode(data, errors, finish=False):
- if not finish:
- # We are trying to remove a possible incomplete multibyte character
- # from the suffix of the data.
- # The first byte of a multi-byte sequence is in the range 0xc0 to 0xfd.
- # All further bytes are in the range 0x80 to 0xbf.
- # UTF-8 encoded UCS characters may be up to six bytes long.
- count = 0
- while count < 5 and count < len(data) \
- and '\x80' <= data[-count-1] <= '\xBF':
- count -= 1
- if count < 5 and count < len(data) \
- and '\xC0' <= data[-count-1] <= '\xFD':
- data = data[:-count-1]
- return codecs.utf_8_decode(data, errors)
-
-class ReaderError(YAMLError):
-
- def __init__(self, name, position, character, encoding, reason):
- self.name = name
- self.character = character
- self.position = position
- self.encoding = encoding
- self.reason = reason
-
- def __str__(self):
- if isinstance(self.character, str):
- return "'%s' codec can't decode byte #x%02x: %s\n" \
- " in \"%s\", position %d" \
- % (self.encoding, ord(self.character), self.reason,
- self.name, self.position)
- else:
- return "unacceptable character #x%04x: %s\n" \
- " in \"%s\", position %d" \
- % (ord(self.character), self.reason,
- self.name, self.position)
-
-class Reader(object):
- # Reader:
- # - determines the data encoding and converts it to unicode,
- # - checks if characters are in allowed range,
- # - adds '\0' to the end.
-
- # Reader accepts
- # - a `str` object,
- # - a `unicode` object,
- # - a file-like object with its `read` method returning `str`,
- # - a file-like object with its `read` method returning `unicode`.
-
- # Yeah, it's ugly and slow.
-
- def __init__(self, stream):
- self.name = None
- self.stream = None
- self.stream_pointer = 0
- self.eof = True
- self.buffer = u''
- self.pointer = 0
- self.raw_buffer = None
- self.raw_decode = None
- self.encoding = None
- self.index = 0
- self.line = 0
- self.column = 0
- if isinstance(stream, unicode):
- self.name = "<unicode string>"
- self.check_printable(stream)
- self.buffer = stream+u'\0'
- elif isinstance(stream, str):
- self.name = "<string>"
- self.raw_buffer = stream
- self.determine_encoding()
- else:
- self.stream = stream
- self.name = getattr(stream, 'name', "<file>")
- self.eof = False
- self.raw_buffer = ''
- self.determine_encoding()
-
- def peek(self, index=0):
- try:
- return self.buffer[self.pointer+index]
- except IndexError:
- self.update(index+1)
- return self.buffer[self.pointer+index]
-
- def prefix(self, length=1):
- if self.pointer+length >= len(self.buffer):
- self.update(length)
- return self.buffer[self.pointer:self.pointer+length]
-
- def forward(self, length=1):
- if self.pointer+length+1 >= len(self.buffer):
- self.update(length+1)
- while length:
- ch = self.buffer[self.pointer]
- self.pointer += 1
- self.index += 1
- if ch in u'\n\x85\u2028\u2029' \
- or (ch == u'\r' and self.buffer[self.pointer] != u'\n'):
- self.line += 1
- self.column = 0
- elif ch != u'\uFEFF':
- self.column += 1
- length -= 1
-
- def get_mark(self):
- if self.stream is None:
- return Mark(self.name, self.index, self.line, self.column,
- self.buffer, self.pointer)
- else:
- return Mark(self.name, self.index, self.line, self.column,
- None, None)
-
- def determine_encoding(self):
- while not self.eof and len(self.raw_buffer) < 2:
- self.update_raw()
- if not isinstance(self.raw_buffer, unicode):
- if self.raw_buffer.startswith(codecs.BOM_UTF16_LE):
- self.raw_decode = utf_16_le_decode
- self.encoding = 'utf-16-le'
- elif self.raw_buffer.startswith(codecs.BOM_UTF16_BE):
- self.raw_decode = utf_16_be_decode
- self.encoding = 'utf-16-be'
- else:
- self.raw_decode = utf_8_decode
- self.encoding = 'utf-8'
- self.update(1)
-
- NON_PRINTABLE = re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
- def check_printable(self, data):
- match = self.NON_PRINTABLE.search(data)
- if match:
- character = match.group()
- position = self.index+(len(self.buffer)-self.pointer)+match.start()
- raise ReaderError(self.name, position, character,
- 'unicode', "special characters are not allowed")
-
- def update(self, length):
- if self.raw_buffer is None:
- return
- self.buffer = self.buffer[self.pointer:]
- self.pointer = 0
- while len(self.buffer) < length:
- if not self.eof:
- self.update_raw()
- if self.raw_decode is not None:
- try:
- data, converted = self.raw_decode(self.raw_buffer,
- 'strict', self.eof)
- except UnicodeDecodeError, exc:
- character = exc.object[exc.start]
- if self.stream is not None:
- position = self.stream_pointer-len(self.raw_buffer)+exc.start
- else:
- position = exc.start
- raise ReaderError(self.name, position, character,
- exc.encoding, exc.reason)
- else:
- data = self.raw_buffer
- converted = len(data)
- self.check_printable(data)
- self.buffer += data
- self.raw_buffer = self.raw_buffer[converted:]
- if self.eof:
- self.buffer += u'\0'
- self.raw_buffer = None
- break
-
- def update_raw(self, size=1024):
- data = self.stream.read(size)
- if data:
- self.raw_buffer += data
- self.stream_pointer += len(data)
- else:
- self.eof = True
-
-#try:
-# import psyco
-# psyco.bind(Reader)
-#except ImportError:
-# pass
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/representer.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/representer.py b/tools/bin/ext/yaml/representer.py
deleted file mode 100644
index b83cc4b..0000000
--- a/tools/bin/ext/yaml/representer.py
+++ /dev/null
@@ -1,504 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['BaseRepresenter', 'SafeRepresenter', 'Representer',
- 'RepresenterError']
-
-from error import *
-from nodes import *
-
-import datetime
-
-try:
- set
-except NameError:
- from sets import Set as set
-
-import sys, copy_reg, types
-
-class RepresenterError(YAMLError):
- pass
-
-class BaseRepresenter(object):
-
- yaml_representers = {}
- yaml_multi_representers = {}
-
- def __init__(self, default_style=None, default_flow_style=None):
- self.default_style = default_style
- self.default_flow_style = default_flow_style
- self.represented_objects = {}
- self.object_keeper = []
- self.alias_key = None
-
- def represent(self, data):
- node = self.represent_data(data)
- self.serialize(node)
- self.represented_objects = {}
- self.object_keeper = []
- self.alias_key = None
-
- def get_classobj_bases(self, cls):
- bases = [cls]
- for base in cls.__bases__:
- bases.extend(self.get_classobj_bases(base))
- return bases
-
- def represent_data(self, data):
- if self.ignore_aliases(data):
- self.alias_key = None
- else:
- self.alias_key = id(data)
- if self.alias_key is not None:
- if self.alias_key in self.represented_objects:
- node = self.represented_objects[self.alias_key]
- #if node is None:
- # raise RepresenterError("recursive objects are not allowed: %r" % data)
- return node
- #self.represented_objects[alias_key] = None
- self.object_keeper.append(data)
- data_types = type(data).__mro__
- if type(data) is types.InstanceType:
- data_types = self.get_classobj_bases(data.__class__)+list(data_types)
- if data_types[0] in self.yaml_representers:
- node = self.yaml_representers[data_types[0]](self, data)
- else:
- for data_type in data_types:
- if data_type in self.yaml_multi_representers:
- node = self.yaml_multi_representers[data_type](self, data)
- break
- else:
- if None in self.yaml_multi_representers:
- node = self.yaml_multi_representers[None](self, data)
- elif None in self.yaml_representers:
- node = self.yaml_representers[None](self, data)
- else:
- node = ScalarNode(None, unicode(data))
- #if alias_key is not None:
- # self.represented_objects[alias_key] = node
- return node
-
- def add_representer(cls, data_type, representer):
- if not 'yaml_representers' in cls.__dict__:
- cls.yaml_representers = cls.yaml_representers.copy()
- cls.yaml_representers[data_type] = representer
- add_representer = classmethod(add_representer)
-
- def add_multi_representer(cls, data_type, representer):
- if not 'yaml_multi_representers' in cls.__dict__:
- cls.yaml_multi_representers = cls.yaml_multi_representers.copy()
- cls.yaml_multi_representers[data_type] = representer
- add_multi_representer = classmethod(add_multi_representer)
-
- def represent_scalar(self, tag, value, style=None):
- if style is None:
- style = self.default_style
- node = ScalarNode(tag, value, style=style)
- if self.alias_key is not None:
- self.represented_objects[self.alias_key] = node
- return node
-
- def represent_sequence(self, tag, sequence, flow_style=None):
- value = []
- node = SequenceNode(tag, value, flow_style=flow_style)
- if self.alias_key is not None:
- self.represented_objects[self.alias_key] = node
- best_style = True
- for item in sequence:
- node_item = self.represent_data(item)
- if not (isinstance(node_item, ScalarNode) and not node_item.style):
- best_style = False
- value.append(node_item)
- if flow_style is None:
- if self.default_flow_style is not None:
- node.flow_style = self.default_flow_style
- else:
- node.flow_style = best_style
- return node
-
- def represent_mapping(self, tag, mapping, flow_style=None):
- value = []
- node = MappingNode(tag, value, flow_style=flow_style)
- if self.alias_key is not None:
- self.represented_objects[self.alias_key] = node
- best_style = True
- if hasattr(mapping, 'items'):
- mapping = mapping.items()
- mapping.sort()
- for item_key, item_value in mapping:
- node_key = self.represent_data(item_key)
- node_value = self.represent_data(item_value)
- if not (isinstance(node_key, ScalarNode) and not node_key.style):
- best_style = False
- if not (isinstance(node_value, ScalarNode) and not node_value.style):
- best_style = False
- value.append((node_key, node_value))
- if flow_style is None:
- if self.default_flow_style is not None:
- node.flow_style = self.default_flow_style
- else:
- node.flow_style = best_style
- return node
-
- def ignore_aliases(self, data):
- return False
-
-class SafeRepresenter(BaseRepresenter):
-
- def ignore_aliases(self, data):
- if data in [None, ()]:
- return True
- if isinstance(data, (str, unicode, bool, int, float)):
- return True
-
- def represent_none(self, data):
- return self.represent_scalar(u'tag:yaml.org,2002:null',
- u'null')
-
- def represent_str(self, data):
- tag = None
- style = None
- try:
- data = unicode(data, 'ascii')
- tag = u'tag:yaml.org,2002:str'
- except UnicodeDecodeError:
- try:
- data = unicode(data, 'utf-8')
- tag = u'tag:yaml.org,2002:str'
- except UnicodeDecodeError:
- data = data.encode('base64')
- tag = u'tag:yaml.org,2002:binary'
- style = '|'
- return self.represent_scalar(tag, data, style=style)
-
- def represent_unicode(self, data):
- return self.represent_scalar(u'tag:yaml.org,2002:str', data)
-
- def represent_bool(self, data):
- if data:
- value = u'true'
- else:
- value = u'false'
- return self.represent_scalar(u'tag:yaml.org,2002:bool', value)
-
- def represent_int(self, data):
- return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
-
- def represent_long(self, data):
- return self.represent_scalar(u'tag:yaml.org,2002:int', unicode(data))
-
- inf_value = 1e300
- while repr(inf_value) != repr(inf_value*inf_value):
- inf_value *= inf_value
-
- def represent_float(self, data):
- if data != data or (data == 0.0 and data == 1.0):
- value = u'.nan'
- elif data == self.inf_value:
- value = u'.inf'
- elif data == -self.inf_value:
- value = u'-.inf'
- else:
- value = unicode(repr(data)).lower()
- # Note that in some cases `repr(data)` represents a float number
- # without the decimal parts. For instance:
- # >>> repr(1e17)
- # '1e17'
- # Unfortunately, this is not a valid float representation according
- # to the definition of the `!!float` tag. We fix this by adding
- # '.0' before the 'e' symbol.
- if u'.' not in value and u'e' in value:
- value = value.replace(u'e', u'.0e', 1)
- return self.represent_scalar(u'tag:yaml.org,2002:float', value)
-
- def represent_list(self, data):
- #pairs = (len(data) > 0 and isinstance(data, list))
- #if pairs:
- # for item in data:
- # if not isinstance(item, tuple) or len(item) != 2:
- # pairs = False
- # break
- #if not pairs:
- return self.represent_sequence(u'tag:yaml.org,2002:seq', data)
- #value = []
- #for item_key, item_value in data:
- # value.append(self.represent_mapping(u'tag:yaml.org,2002:map',
- # [(item_key, item_value)]))
- #return SequenceNode(u'tag:yaml.org,2002:pairs', value)
-
- def represent_dict(self, data):
- return self.represent_mapping(u'tag:yaml.org,2002:map', data)
-
- def represent_set(self, data):
- value = {}
- for key in data:
- value[key] = None
- return self.represent_mapping(u'tag:yaml.org,2002:set', value)
-
- def represent_date(self, data):
- value = unicode(data.isoformat())
- return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
-
- def represent_datetime(self, data):
- value = unicode(data.isoformat(' '))
- return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value)
-
- def represent_yaml_object(self, tag, data, cls, flow_style=None):
- if hasattr(data, '__getstate__'):
- state = data.__getstate__()
- else:
- state = data.__dict__.copy()
- return self.represent_mapping(tag, state, flow_style=flow_style)
-
- def represent_undefined(self, data):
- raise RepresenterError("cannot represent an object: %s" % data)
-
-SafeRepresenter.add_representer(type(None),
- SafeRepresenter.represent_none)
-
-SafeRepresenter.add_representer(str,
- SafeRepresenter.represent_str)
-
-SafeRepresenter.add_representer(unicode,
- SafeRepresenter.represent_unicode)
-
-SafeRepresenter.add_representer(bool,
- SafeRepresenter.represent_bool)
-
-SafeRepresenter.add_representer(int,
- SafeRepresenter.represent_int)
-
-SafeRepresenter.add_representer(long,
- SafeRepresenter.represent_long)
-
-SafeRepresenter.add_representer(float,
- SafeRepresenter.represent_float)
-
-SafeRepresenter.add_representer(list,
- SafeRepresenter.represent_list)
-
-SafeRepresenter.add_representer(tuple,
- SafeRepresenter.represent_list)
-
-SafeRepresenter.add_representer(dict,
- SafeRepresenter.represent_dict)
-
-SafeRepresenter.add_representer(set,
- SafeRepresenter.represent_set)
-
-SafeRepresenter.add_representer(datetime.date,
- SafeRepresenter.represent_date)
-SafeRepresenter.add_representer(datetime.datetime,
- SafeRepresenter.represent_datetime)
-
-SafeRepresenter.add_representer(None,
- SafeRepresenter.represent_undefined)
-
-class Representer(SafeRepresenter):
-
- def represent_str(self, data):
- tag = None
- style = None
- try:
- data = unicode(data, 'ascii')
- tag = u'tag:yaml.org,2002:str'
- except UnicodeDecodeError:
- try:
- data = unicode(data, 'utf-8')
- tag = u'tag:yaml.org,2002:python/str'
- except UnicodeDecodeError:
- data = data.encode('base64')
- tag = u'tag:yaml.org,2002:binary'
- style = '|'
- return self.represent_scalar(tag, data, style=style)
-
- def represent_unicode(self, data):
- tag = None
- try:
- data.encode('ascii')
- tag = u'tag:yaml.org,2002:python/unicode'
- except UnicodeEncodeError:
- tag = u'tag:yaml.org,2002:str'
- return self.represent_scalar(tag, data)
-
- def represent_long(self, data):
- tag = u'tag:yaml.org,2002:int'
- if int(data) is not data:
- tag = u'tag:yaml.org,2002:python/long'
- return self.represent_scalar(tag, unicode(data))
-
- def represent_complex(self, data):
- if data.imag == 0.0:
- data = u'%r' % data.real
- elif data.real == 0.0:
- data = u'%rj' % data.imag
- elif data.imag > 0:
- data = u'%r+%rj' % (data.real, data.imag)
- else:
- data = u'%r%rj' % (data.real, data.imag)
- return self.represent_scalar(u'tag:yaml.org,2002:python/complex', data)
-
- def represent_tuple(self, data):
- return self.represent_sequence(u'tag:yaml.org,2002:python/tuple', data)
-
- def represent_name(self, data):
- name = u'%s.%s' % (data.__module__, data.__name__)
- return self.represent_scalar(u'tag:yaml.org,2002:python/name:'+name, u'')
-
- def represent_module(self, data):
- return self.represent_scalar(
- u'tag:yaml.org,2002:python/module:'+data.__name__, u'')
-
- def represent_instance(self, data):
- # For instances of classic classes, we use __getinitargs__ and
- # __getstate__ to serialize the data.
-
- # If data.__getinitargs__ exists, the object must be reconstructed by
- # calling cls(**args), where args is a tuple returned by
- # __getinitargs__. Otherwise, the cls.__init__ method should never be
- # called and the class instance is created by instantiating a trivial
- # class and assigning to the instance's __class__ variable.
-
- # If data.__getstate__ exists, it returns the state of the object.
- # Otherwise, the state of the object is data.__dict__.
-
- # We produce either a !!python/object or !!python/object/new node.
- # If data.__getinitargs__ does not exist and state is a dictionary, we
- # produce a !!python/object node . Otherwise we produce a
- # !!python/object/new node.
-
- cls = data.__class__
- class_name = u'%s.%s' % (cls.__module__, cls.__name__)
- args = None
- state = None
- if hasattr(data, '__getinitargs__'):
- args = list(data.__getinitargs__())
- if hasattr(data, '__getstate__'):
- state = data.__getstate__()
- else:
- state = data.__dict__
- if args is None and isinstance(state, dict):
- return self.represent_mapping(
- u'tag:yaml.org,2002:python/object:'+class_name, state)
- if isinstance(state, dict) and not state:
- return self.represent_sequence(
- u'tag:yaml.org,2002:python/object/new:'+class_name, args)
- value = {}
- if args:
- value['args'] = args
- value['state'] = state
- return self.represent_mapping(
- u'tag:yaml.org,2002:python/object/new:'+class_name, value)
-
- def represent_object(self, data):
- # We use __reduce__ API to save the data. data.__reduce__ returns
- # a tuple of length 2-5:
- # (function, args, state, listitems, dictitems)
-
- # For reconstructing, we calls function(*args), then set its state,
- # listitems, and dictitems if they are not None.
-
- # A special case is when function.__name__ == '__newobj__'. In this
- # case we create the object with args[0].__new__(*args).
-
- # Another special case is when __reduce__ returns a string - we don't
- # support it.
-
- # We produce a !!python/object, !!python/object/new or
- # !!python/object/apply node.
-
- cls = type(data)
- if cls in copy_reg.dispatch_table:
- reduce = copy_reg.dispatch_table[cls](data)
- elif hasattr(data, '__reduce_ex__'):
- reduce = data.__reduce_ex__(2)
- elif hasattr(data, '__reduce__'):
- reduce = data.__reduce__()
- else:
- raise RepresenterError("cannot represent object: %r" % data)
- reduce = (list(reduce)+[None]*5)[:5]
- function, args, state, listitems, dictitems = reduce
- args = list(args)
- if state is None:
- state = {}
- if listitems is not None:
- listitems = list(listitems)
- if dictitems is not None:
- dictitems = dict(dictitems)
- if function.__name__ == '__newobj__':
- function = args[0]
- args = args[1:]
- tag = u'tag:yaml.org,2002:python/object/new:'
- newobj = True
- else:
- tag = u'tag:yaml.org,2002:python/object/apply:'
- newobj = False
- function_name = u'%s.%s' % (function.__module__, function.__name__)
- if not args and not listitems and not dictitems \
- and isinstance(state, dict) and newobj:
- return self.represent_mapping(
- u'tag:yaml.org,2002:python/object:'+function_name, state)
- if not listitems and not dictitems \
- and isinstance(state, dict) and not state:
- return self.represent_sequence(tag+function_name, args)
- value = {}
- if args:
- value['args'] = args
- if state or not isinstance(state, dict):
- value['state'] = state
- if listitems:
- value['listitems'] = listitems
- if dictitems:
- value['dictitems'] = dictitems
- return self.represent_mapping(tag+function_name, value)
-
-Representer.add_representer(str,
- Representer.represent_str)
-
-Representer.add_representer(unicode,
- Representer.represent_unicode)
-
-Representer.add_representer(long,
- Representer.represent_long)
-
-Representer.add_representer(complex,
- Representer.represent_complex)
-
-Representer.add_representer(tuple,
- Representer.represent_tuple)
-
-Representer.add_representer(type,
- Representer.represent_name)
-
-Representer.add_representer(types.ClassType,
- Representer.represent_name)
-
-Representer.add_representer(types.FunctionType,
- Representer.represent_name)
-
-Representer.add_representer(types.BuiltinFunctionType,
- Representer.represent_name)
-
-Representer.add_representer(types.ModuleType,
- Representer.represent_module)
-
-Representer.add_multi_representer(types.InstanceType,
- Representer.represent_instance)
-
-Representer.add_multi_representer(object,
- Representer.represent_object)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/resolver.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/resolver.py b/tools/bin/ext/yaml/resolver.py
deleted file mode 100644
index 0feb12b..0000000
--- a/tools/bin/ext/yaml/resolver.py
+++ /dev/null
@@ -1,239 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['BaseResolver', 'Resolver']
-
-from error import *
-from nodes import *
-
-import re
-
-class ResolverError(YAMLError):
- pass
-
-class BaseResolver(object):
-
- DEFAULT_SCALAR_TAG = u'tag:yaml.org,2002:str'
- DEFAULT_SEQUENCE_TAG = u'tag:yaml.org,2002:seq'
- DEFAULT_MAPPING_TAG = u'tag:yaml.org,2002:map'
-
- yaml_implicit_resolvers = {}
- yaml_path_resolvers = {}
-
- def __init__(self):
- self.resolver_exact_paths = []
- self.resolver_prefix_paths = []
-
- def add_implicit_resolver(cls, tag, regexp, first):
- if not 'yaml_implicit_resolvers' in cls.__dict__:
- cls.yaml_implicit_resolvers = cls.yaml_implicit_resolvers.copy()
- if first is None:
- first = [None]
- for ch in first:
- cls.yaml_implicit_resolvers.setdefault(ch, []).append((tag, regexp))
- add_implicit_resolver = classmethod(add_implicit_resolver)
-
- def add_path_resolver(cls, tag, path, kind=None):
- # Note: `add_path_resolver` is experimental. The API could be changed.
- # `new_path` is a pattern that is matched against the path from the
- # root to the node that is being considered. `node_path` elements are
- # tuples `(node_check, index_check)`. `node_check` is a node class:
- # `ScalarNode`, `SequenceNode`, `MappingNode` or `None`. `None`
- # matches any kind of a node. `index_check` could be `None`, a boolean
- # value, a string value, or a number. `None` and `False` match against
- # any _value_ of sequence and mapping nodes. `True` matches against
- # any _key_ of a mapping node. A string `index_check` matches against
- # a mapping value that corresponds to a scalar key which content is
- # equal to the `index_check` value. An integer `index_check` matches
- # against a sequence value with the index equal to `index_check`.
- if not 'yaml_path_resolvers' in cls.__dict__:
- cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy()
- new_path = []
- for element in path:
- if isinstance(element, (list, tuple)):
- if len(element) == 2:
- node_check, index_check = element
- elif len(element) == 1:
- node_check = element[0]
- index_check = True
- else:
- raise ResolverError("Invalid path element: %s" % element)
- else:
- node_check = None
- index_check = element
- if node_check is str:
- node_check = ScalarNode
- elif node_check is list:
- node_check = SequenceNode
- elif node_check is dict:
- node_check = MappingNode
- elif node_check not in [ScalarNode, SequenceNode, MappingNode] \
- and not isinstance(node_check, basestring) \
- and node_check is not None:
- raise ResolverError("Invalid node checker: %s" % node_check)
- if not isinstance(index_check, (basestring, int)) \
- and index_check is not None:
- raise ResolverError("Invalid index checker: %s" % index_check)
- new_path.append((node_check, index_check))
- if kind is str:
- kind = ScalarNode
- elif kind is list:
- kind = SequenceNode
- elif kind is dict:
- kind = MappingNode
- elif kind not in [ScalarNode, SequenceNode, MappingNode] \
- and kind is not None:
- raise ResolverError("Invalid node kind: %s" % kind)
- cls.yaml_path_resolvers[tuple(new_path), kind] = tag
- add_path_resolver = classmethod(add_path_resolver)
-
- def descend_resolver(self, current_node, current_index):
- if not self.yaml_path_resolvers:
- return
- exact_paths = {}
- prefix_paths = []
- if current_node:
- depth = len(self.resolver_prefix_paths)
- for path, kind in self.resolver_prefix_paths[-1]:
- if self.check_resolver_prefix(depth, path, kind,
- current_node, current_index):
- if len(path) > depth:
- prefix_paths.append((path, kind))
- else:
- exact_paths[kind] = self.yaml_path_resolvers[path, kind]
- else:
- for path, kind in self.yaml_path_resolvers:
- if not path:
- exact_paths[kind] = self.yaml_path_resolvers[path, kind]
- else:
- prefix_paths.append((path, kind))
- self.resolver_exact_paths.append(exact_paths)
- self.resolver_prefix_paths.append(prefix_paths)
-
- def ascend_resolver(self):
- if not self.yaml_path_resolvers:
- return
- self.resolver_exact_paths.pop()
- self.resolver_prefix_paths.pop()
-
- def check_resolver_prefix(self, depth, path, kind,
- current_node, current_index):
- node_check, index_check = path[depth-1]
- if isinstance(node_check, basestring):
- if current_node.tag != node_check:
- return
- elif node_check is not None:
- if not isinstance(current_node, node_check):
- return
- if index_check is True and current_index is not None:
- return
- if (index_check is False or index_check is None) \
- and current_index is None:
- return
- if isinstance(index_check, basestring):
- if not (isinstance(current_index, ScalarNode)
- and index_check == current_index.value):
- return
- elif isinstance(index_check, int) and not isinstance(index_check, bool):
- if index_check != current_index:
- return
- return True
-
- def resolve(self, kind, value, implicit):
- if kind is ScalarNode and implicit[0]:
- if value == u'':
- resolvers = self.yaml_implicit_resolvers.get(u'', [])
- else:
- resolvers = self.yaml_implicit_resolvers.get(value[0], [])
- resolvers += self.yaml_implicit_resolvers.get(None, [])
- for tag, regexp in resolvers:
- if regexp.match(value):
- return tag
- implicit = implicit[1]
- if self.yaml_path_resolvers:
- exact_paths = self.resolver_exact_paths[-1]
- if kind in exact_paths:
- return exact_paths[kind]
- if None in exact_paths:
- return exact_paths[None]
- if kind is ScalarNode:
- return self.DEFAULT_SCALAR_TAG
- elif kind is SequenceNode:
- return self.DEFAULT_SEQUENCE_TAG
- elif kind is MappingNode:
- return self.DEFAULT_MAPPING_TAG
-
-class Resolver(BaseResolver):
- pass
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:bool',
- re.compile(ur'''^(?:yes|Yes|YES|no|No|NO
- |true|True|TRUE|false|False|FALSE
- |on|On|ON|off|Off|OFF)$''', re.X),
- list(u'yYnNtTfFoO'))
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:float',
- re.compile(ur'''^(?:[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*(?:[eE][-+][0-9]+)?
- |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*
- |[-+]?\.(?:inf|Inf|INF)
- |\.(?:nan|NaN|NAN))$''', re.X),
- list(u'-+0123456789.'))
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:int',
- re.compile(ur'''^(?:[-+]?0b[0-1_]+
- |[-+]?0[0-7_]+
- |[-+]?(?:0|[1-9][0-9_]*)
- |[-+]?0x[0-9a-fA-F_]+
- |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
- list(u'-+0123456789'))
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:merge',
- re.compile(ur'^(?:<<)$'),
- ['<'])
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:null',
- re.compile(ur'''^(?: ~
- |null|Null|NULL
- | )$''', re.X),
- [u'~', u'n', u'N', u''])
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:timestamp',
- re.compile(ur'''^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]
- |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?
- (?:[Tt]|[ \t]+)[0-9][0-9]?
- :[0-9][0-9] :[0-9][0-9] (?:\.[0-9]*)?
- (?:[ \t]*(?:Z|[-+][0-9][0-9]?(?::[0-9][0-9])?))?)$''', re.X),
- list(u'0123456789'))
-
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:value',
- re.compile(ur'^(?:=)$'),
- ['='])
-
-# The following resolver is only for documentation purposes. It cannot work
-# because plain scalars cannot start with '!', '&', or '*'.
-Resolver.add_implicit_resolver(
- u'tag:yaml.org,2002:yaml',
- re.compile(ur'^(?:!|&|\*)$'),
- list(u'!&*'))
-
[12/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/dbapi.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/dbapi.py b/tools/bin/ext/pg8000/dbapi.py
deleted file mode 100644
index 3f90188..0000000
--- a/tools/bin/ext/pg8000/dbapi.py
+++ /dev/null
@@ -1,621 +0,0 @@
-# vim: sw=4:expandtab:foldmethod=marker
-#
-# Copyright (c) 2007-2009, Mathieu Fenniak
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-__author__ = "Mathieu Fenniak"
-
-import datetime
-import time
-import interface
-import types
-import threading
-from errors import *
-
-from warnings import warn
-
-##
-# The DBAPI level supported. Currently 2.0. This property is part of the
-# DBAPI 2.0 specification.
-apilevel = "2.0"
-
-##
-# Integer constant stating the level of thread safety the DBAPI interface
-# supports. This DBAPI interface supports sharing of the module, connections,
-# and cursors. This property is part of the DBAPI 2.0 specification.
-threadsafety = 3
-
-##
-# String property stating the type of parameter marker formatting expected by
-# the interface. This value defaults to "format". This property is part of
-# the DBAPI 2.0 specification.
-# <p>
-# Unlike the DBAPI specification, this value is not constant. It can be
-# changed to any standard paramstyle value (ie. qmark, numeric, named, format,
-# and pyformat).
-paramstyle = 'format' # paramstyle can be changed to any DB-API paramstyle
-
-def convert_paramstyle(src_style, query, args):
- # I don't see any way to avoid scanning the query string char by char,
- # so we might as well take that careful approach and create a
- # state-based scanner. We'll use int variables for the state.
- # 0 -- outside quoted string
- # 1 -- inside single-quote string '...'
- # 2 -- inside quoted identifier "..."
- # 3 -- inside escaped single-quote string, E'...'
-
- if args is None:
- return query, args
-
- state = 0
- output_query = ""
- output_args = []
- if src_style == "numeric":
- output_args = args
- elif src_style in ("pyformat", "named"):
- mapping_to_idx = {}
- i = 0
- while 1:
- if i == len(query):
- break
- c = query[i]
- # print "begin loop", repr(i), repr(c), repr(state)
- if state == 0:
- if c == "'":
- i += 1
- output_query += c
- state = 1
- elif c == '"':
- i += 1
- output_query += c
- state = 2
- elif c == 'E':
- # check for escaped single-quote string
- i += 1
- if i < len(query) and i > 1 and query[i] == "'":
- i += 1
- output_query += "E'"
- state = 3
- else:
- output_query += c
- elif src_style == "qmark" and c == "?":
- i += 1
- param_idx = len(output_args)
- if param_idx == len(args):
- raise QueryParameterIndexError("too many parameter fields, not enough parameters")
- output_args.append(args[param_idx])
- output_query += "$" + str(param_idx + 1)
- elif src_style == "numeric" and c == ":":
- i += 1
- if i < len(query) and i > 1 and query[i].isdigit():
- output_query += "$" + query[i]
- i += 1
- else:
- raise QueryParameterParseError("numeric parameter : does not have numeric arg")
- elif src_style == "named" and c == ":":
- name = ""
- while 1:
- i += 1
- if i == len(query):
- break
- c = query[i]
- if c.isalnum() or c == '_':
- name += c
- else:
- break
- if name == "":
- raise QueryParameterParseError("empty name of named parameter")
- idx = mapping_to_idx.get(name)
- if idx == None:
- idx = len(output_args)
- output_args.append(args[name])
- idx += 1
- mapping_to_idx[name] = idx
- output_query += "$" + str(idx)
- elif src_style == "format" and c == "%":
- i += 1
- if i < len(query) and i > 1:
- if query[i] == "s":
- param_idx = len(output_args)
- if param_idx == len(args):
- raise QueryParameterIndexError("too many parameter fields, not enough parameters")
- output_args.append(args[param_idx])
- output_query += "$" + str(param_idx + 1)
- elif query[i] == "%":
- output_query += "%"
- else:
- raise QueryParameterParseError("Only %s and %% are supported")
- i += 1
- else:
- raise QueryParameterParseError("format parameter % does not have format code")
- elif src_style == "pyformat" and c == "%":
- i += 1
- if i < len(query) and i > 1:
- if query[i] == "(":
- i += 1
- # begin mapping name
- end_idx = query.find(')', i)
- if end_idx == -1:
- raise QueryParameterParseError("began pyformat dict read, but couldn't find end of name")
- else:
- name = query[i:end_idx]
- i = end_idx + 1
- if i < len(query) and query[i] == "s":
- i += 1
- idx = mapping_to_idx.get(name)
- if idx == None:
- idx = len(output_args)
- output_args.append(args[name])
- idx += 1
- mapping_to_idx[name] = idx
- output_query += "$" + str(idx)
- else:
- raise QueryParameterParseError("format not specified or not supported (only %(...)s supported)")
- elif query[i] == "%":
- output_query += "%"
- elif query[i] == "s":
- # we have a %s in a pyformat query string. Assume
- # support for format instead.
- i -= 1
- src_style = "format"
- else:
- raise QueryParameterParseError("Only %(name)s, %s and %% are supported")
- else:
- i += 1
- output_query += c
- elif state == 1:
- output_query += c
- i += 1
- if c == "'":
- # Could be a double ''
- if i < len(query) and query[i] == "'":
- # is a double quote.
- output_query += query[i]
- i += 1
- else:
- state = 0
- elif src_style in ("pyformat","format") and c == "%":
- # hm... we're only going to support an escaped percent sign
- if i < len(query):
- if query[i] == "%":
- # good. We already output the first percent sign.
- i += 1
- else:
- raise QueryParameterParseError("'%" + query[i] + "' not supported in quoted string")
- elif state == 2:
- output_query += c
- i += 1
- if c == '"':
- state = 0
- elif src_style in ("pyformat","format") and c == "%":
- # hm... we're only going to support an escaped percent sign
- if i < len(query):
- if query[i] == "%":
- # good. We already output the first percent sign.
- i += 1
- else:
- raise QueryParameterParseError("'%" + query[i] + "' not supported in quoted string")
- elif state == 3:
- output_query += c
- i += 1
- if c == "\\":
- # check for escaped single-quote
- if i < len(query) and query[i] == "'":
- output_query += "'"
- i += 1
- elif c == "'":
- state = 0
- elif src_style in ("pyformat","format") and c == "%":
- # hm... we're only going to support an escaped percent sign
- if i < len(query):
- if query[i] == "%":
- # good. We already output the first percent sign.
- i += 1
- else:
- raise QueryParameterParseError("'%" + query[i] + "' not supported in quoted string")
-
- return output_query, tuple(output_args)
-
-def require_open_cursor(fn):
- def _fn(self, *args, **kwargs):
- if self.cursor == None:
- raise CursorClosedError()
- return fn(self, *args, **kwargs)
- return _fn
-
-##
-# The class of object returned by the {@link #ConnectionWrapper.cursor cursor method}.
-class CursorWrapper(object):
- def __init__(self, conn, connection):
- self.cursor = interface.Cursor(conn)
- self.arraysize = 1
- self._connection = connection
- self._override_rowcount = None
-
- ##
- # This read-only attribute returns a reference to the connection object on
- # which the cursor was created.
- # <p>
- # Stability: Part of a DBAPI 2.0 extension. A warning "DB-API extension
- # cursor.connection used" will be fired.
- connection = property(lambda self: self._getConnection())
-
- def _getConnection(self):
- warn("DB-API extension cursor.connection used", stacklevel=3)
- return self._connection
-
- ##
- # This read-only attribute specifies the number of rows that the last
- # .execute*() produced (for DQL statements like 'select') or affected (for
- # DML statements like 'update' or 'insert').
- # <p>
- # The attribute is -1 in case no .execute*() has been performed on the
- # cursor or the rowcount of the last operation is cannot be determined by
- # the interface.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- rowcount = property(lambda self: self._getRowCount())
-
- @require_open_cursor
- def _getRowCount(self):
- if self._override_rowcount != None:
- return self._override_rowcount
- return self.cursor.row_count
-
- ##
- # This read-only attribute is a sequence of 7-item sequences. Each value
- # contains information describing one result column. The 7 items returned
- # for each column are (name, type_code, display_size, internal_size,
- # precision, scale, null_ok). Only the first two values are provided by
- # this interface implementation.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- description = property(lambda self: self._getDescription())
-
- @require_open_cursor
- def _getDescription(self):
- if self.cursor.row_description == None:
- return None
- columns = []
- for col in self.cursor.row_description:
- columns.append((col["name"], col["type_oid"], None, None, None, None, None))
- return columns
-
- ##
- # Executes a database operation. Parameters may be provided as a sequence
- # or mapping and will be bound to variables in the operation.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_cursor
- def execute(self, operation, args=()):
- self._override_rowcount = None
- self._execute(operation, args)
-
- def _execute(self, operation, args=()):
- new_query, new_args = convert_paramstyle(paramstyle, operation, args)
- try:
- self.cursor.execute(new_query, *new_args)
- except ConnectionClosedError:
- # can't rollback in this case
- raise
- except:
- # any error will rollback the transaction to-date
- self._connection.rollback()
- raise
-
- def copy_from(self, fileobj, table=None, sep='\t', null=None, query=None):
- if query == None:
- if table == None:
- raise CopyQueryOrTableRequiredError()
- query = "COPY %s FROM stdout DELIMITER '%s'" % (table, sep)
- if null is not None:
- query += " NULL '%s'" % (null,)
- self.copy_execute(fileobj, query)
-
- def copy_to(self, fileobj, table=None, sep='\t', null=None, query=None):
- if query == None:
- if table == None:
- raise CopyQueryOrTableRequiredError()
- query = "COPY %s TO stdout DELIMITER '%s'" % (table, sep)
- if null is not None:
- query += " NULL '%s'" % (null,)
- self.copy_execute(fileobj, query)
-
- @require_open_cursor
- def copy_execute(self, fileobj, query):
- try:
- self.cursor.execute(query, stream=fileobj)
- except ConnectionClosedError:
- # can't rollback in this case
- raise
- except:
- # any error will rollback the transaction to-date
- import traceback; traceback.print_exc()
- self._connection.rollback()
- raise
-
- ##
- # Prepare a database operation and then execute it against all parameter
- # sequences or mappings provided.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_cursor
- def executemany(self, operation, parameter_sets):
- self._override_rowcount = 0
- for parameters in parameter_sets:
- self._execute(operation, parameters)
- if self.cursor.row_count == -1 or self._override_rowcount == -1:
- self._override_rowcount = -1
- else:
- self._override_rowcount += self.cursor.row_count
-
- ##
- # Fetch the next row of a query result set, returning a single sequence, or
- # None when no more data is available.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_cursor
- def fetchone(self):
- return self.cursor.read_tuple()
-
- ##
- # Fetch the next set of rows of a query result, returning a sequence of
- # sequences. An empty sequence is returned when no more rows are
- # available.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- # @param size The number of rows to fetch when called. If not provided,
- # the arraysize property value is used instead.
- def fetchmany(self, size=None):
- if size == None:
- size = self.arraysize
- rows = []
- for i in range(size):
- value = self.fetchone()
- if value == None:
- break
- rows.append(value)
- return rows
-
- ##
- # Fetch all remaining rows of a query result, returning them as a sequence
- # of sequences.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_cursor
- def fetchall(self):
- return tuple(self.cursor.iterate_tuple())
-
- ##
- # Close the cursor.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_cursor
- def close(self):
- self.cursor.close()
- self.cursor = None
- self._override_rowcount = None
-
- def next(self):
- warn("DB-API extension cursor.next() used", stacklevel=2)
- retval = self.fetchone()
- if retval == None:
- raise StopIteration()
- return retval
-
- def __iter__(self):
- warn("DB-API extension cursor.__iter__() used", stacklevel=2)
- return self
-
- def setinputsizes(self, sizes):
- pass
-
- def setoutputsize(self, size, column=None):
- pass
-
- @require_open_cursor
- def fileno(self):
- return self.cursor.fileno()
-
- @require_open_cursor
- def isready(self):
- return self.cursor.isready()
-
-def require_open_connection(fn):
- def _fn(self, *args, **kwargs):
- if self.conn == None:
- raise ConnectionClosedError()
- return fn(self, *args, **kwargs)
- return _fn
-
-##
-# The class of object returned by the {@link #connect connect method}.
-class ConnectionWrapper(object):
- # DBAPI Extension: supply exceptions as attributes on the connection
- Warning = property(lambda self: self._getError(Warning))
- Error = property(lambda self: self._getError(Error))
- InterfaceError = property(lambda self: self._getError(InterfaceError))
- DatabaseError = property(lambda self: self._getError(DatabaseError))
- OperationalError = property(lambda self: self._getError(OperationalError))
- IntegrityError = property(lambda self: self._getError(IntegrityError))
- InternalError = property(lambda self: self._getError(InternalError))
- ProgrammingError = property(lambda self: self._getError(ProgrammingError))
- NotSupportedError = property(lambda self: self._getError(NotSupportedError))
-
- def _getError(self, error):
- warn("DB-API extension connection.%s used" % error.__name__, stacklevel=3)
- return error
-
- def __init__(self, **kwargs):
- self.conn = interface.Connection(**kwargs)
- self.notifies = []
- self.notifies_lock = threading.Lock()
- self.conn.NotificationReceived += self._notificationReceived
- self.conn.begin()
-
- def _notificationReceived(self, notice):
- try:
- # psycopg2 compatible notification interface
- self.notifies_lock.acquire()
- self.notifies.append((notice.backend_pid, notice.condition))
- finally:
- self.notifies_lock.release()
-
- ##
- # Creates a {@link #CursorWrapper CursorWrapper} object bound to this
- # connection.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_connection
- def cursor(self):
- return CursorWrapper(self.conn, self)
-
- ##
- # Commits the current database transaction.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_connection
- def commit(self):
- # There's a threading bug here. If a query is sent after the
- # commit, but before the begin, it will be executed immediately
- # without a surrounding transaction. Like all threading bugs -- it
- # sounds unlikely, until it happens every time in one
- # application... however, to fix this, we need to lock the
- # database connection entirely, so that no cursors can execute
- # statements on other threads. Support for that type of lock will
- # be done later.
- self.conn.commit()
- self.conn.begin()
-
- ##
- # Rolls back the current database transaction.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_connection
- def rollback(self):
- # see bug description in commit.
- self.conn.rollback()
- self.conn.begin()
-
- ##
- # Closes the database connection.
- # <p>
- # Stability: Part of the DBAPI 2.0 specification.
- @require_open_connection
- def close(self):
- self.conn.close()
- self.conn = None
-
- @require_open_connection
- def recache_record_types(self):
- self.conn.recache_record_types()
-
-
-##
-# Creates a DBAPI 2.0 compatible interface to a PostgreSQL database.
-# <p>
-# Stability: Part of the DBAPI 2.0 specification.
-#
-# @param user The username to connect to the PostgreSQL server with. This
-# parameter is required.
-#
-# @keyparam host The hostname of the PostgreSQL server to connect with.
-# Providing this parameter is necessary for TCP/IP connections. One of either
-# host, or unix_sock, must be provided.
-#
-# @keyparam unix_sock The path to the UNIX socket to access the database
-# through, for example, '/tmp/.s.PGSQL.5432'. One of either unix_sock or host
-# must be provided. The port parameter will have no affect if unix_sock is
-# provided.
-#
-# @keyparam port The TCP/IP port of the PostgreSQL server instance. This
-# parameter defaults to 5432, the registered and common port of PostgreSQL
-# TCP/IP servers.
-#
-# @keyparam database The name of the database instance to connect with. This
-# parameter is optional, if omitted the PostgreSQL server will assume the
-# database name is the same as the username.
-#
-# @keyparam password The user password to connect to the server with. This
-# parameter is optional. If omitted, and the database server requests password
-# based authentication, the connection will fail. On the other hand, if this
-# parameter is provided and the database does not request password
-# authentication, then the password will not be used.
-#
-# @keyparam socket_timeout Socket connect timeout measured in seconds.
-# Defaults to 60 seconds.
-#
-# @keyparam ssl Use SSL encryption for TCP/IP socket. Defaults to False.
-#
-# @return An instance of {@link #ConnectionWrapper ConnectionWrapper}.
-def connect(user, host=None, unix_sock=None, port=5432, database=None, password=None, socket_timeout=60, ssl=False, options=None):
- return ConnectionWrapper(user=user, host=host,
- unix_sock=unix_sock, port=port, database=database,
- password=password, socket_timeout=socket_timeout, ssl=ssl, options=options)
-
-def Date(year, month, day):
- return datetime.date(year, month, day)
-
-def Time(hour, minute, second):
- return datetime.time(hour, minute, second)
-
-def Timestamp(year, month, day, hour, minute, second):
- return datetime.datetime(year, month, day, hour, minute, second)
-
-def DateFromTicks(ticks):
- return Date(*time.localtime(ticks)[:3])
-
-def TimeFromTicks(ticks):
- return Time(*time.localtime(ticks)[3:6])
-
-def TimestampFromTicks(ticks):
- return Timestamp(*time.localtime(ticks)[:6])
-
-##
-# Construct an object holding binary data.
-def Binary(value):
- return types.Bytea(value)
-
-# I have no idea what this would be used for by a client app. Should it be
-# TEXT, VARCHAR, CHAR? It will only compare against row_description's
-# type_code if it is this one type. It is the varchar type oid for now, this
-# appears to match expectations in the DB API 2.0 compliance test suite.
-STRING = 1043
-
-# bytea type_oid
-BINARY = 17
-
-# numeric type_oid
-NUMBER = 1700
-
-# timestamp type_oid
-DATETIME = 1114
-
-# oid type_oid
-ROWID = 26
-
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/errors.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/errors.py b/tools/bin/ext/pg8000/errors.py
deleted file mode 100644
index b8b5acf..0000000
--- a/tools/bin/ext/pg8000/errors.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# vim: sw=4:expandtab:foldmethod=marker
-#
-# Copyright (c) 2007-2009, Mathieu Fenniak
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-__author__ = "Mathieu Fenniak"
-
-class Warning(StandardError):
- pass
-
-class Error(StandardError):
- pass
-
-class InterfaceError(Error):
- pass
-
-class ConnectionClosedError(InterfaceError):
- def __init__(self):
- InterfaceError.__init__(self, "connection is closed")
-
-class CursorClosedError(InterfaceError):
- def __init__(self):
- InterfaceError.__init__(self, "cursor is closed")
-
-class DatabaseError(Error):
- pass
-
-class DataError(DatabaseError):
- pass
-
-class OperationalError(DatabaseError):
- pass
-
-class IntegrityError(DatabaseError):
- pass
-
-class InternalError(DatabaseError):
- pass
-
-class ProgrammingError(DatabaseError):
- pass
-
-class NotSupportedError(DatabaseError):
- pass
-
-##
-# An exception that is thrown when an internal error occurs trying to
-# decode binary array data from the server.
-class ArrayDataParseError(InternalError):
- pass
-
-##
-# Thrown when attempting to transmit an array of unsupported data types.
-class ArrayContentNotSupportedError(NotSupportedError):
- pass
-
-##
-# Thrown when attempting to send an array that doesn't contain all the same
-# type of objects (eg. some floats, some ints).
-class ArrayContentNotHomogenousError(ProgrammingError):
- pass
-
-##
-# Attempted to pass an empty array in, but it's not possible to determine the
-# data type for an empty array.
-class ArrayContentEmptyError(ProgrammingError):
- pass
-
-##
-# Attempted to use a multidimensional array with inconsistent array sizes.
-class ArrayDimensionsNotConsistentError(ProgrammingError):
- pass
-
-# A cursor's copy_to or copy_from argument was not provided a table or query
-# to operate on.
-class CopyQueryOrTableRequiredError(ProgrammingError):
- pass
-
-# Raised if a COPY query is executed without using copy_to or copy_from
-# functions to provide a data stream.
-class CopyQueryWithoutStreamError(ProgrammingError):
- pass
-
-# When query parameters don't match up with query args.
-class QueryParameterIndexError(ProgrammingError):
- pass
-
-# Some sort of parse error occured during query parameterization.
-class QueryParameterParseError(ProgrammingError):
- pass
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/pg8000/interface.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/pg8000/interface.py b/tools/bin/ext/pg8000/interface.py
deleted file mode 100644
index d2f70fa..0000000
--- a/tools/bin/ext/pg8000/interface.py
+++ /dev/null
@@ -1,542 +0,0 @@
-# vim: sw=4:expandtab:foldmethod=marker
-#
-# Copyright (c) 2007-2009, Mathieu Fenniak
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * The name of the author may not be used to endorse or promote products
-# derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-
-__author__ = "Mathieu Fenniak"
-
-import socket
-import protocol
-import threading
-from errors import *
-
-class DataIterator(object):
- def __init__(self, obj, func):
- self.obj = obj
- self.func = func
-
- def __iter__(self):
- return self
-
- def next(self):
- retval = self.func(self.obj)
- if retval == None:
- raise StopIteration()
- return retval
-
-statement_number_lock = threading.Lock()
-statement_number = 0
-
-##
-# This class represents a prepared statement. A prepared statement is
-# pre-parsed on the server, which reduces the need to parse the query every
-# time it is run. The statement can have parameters in the form of $1, $2, $3,
-# etc. When parameters are used, the types of the parameters need to be
-# specified when creating the prepared statement.
-# <p>
-# As of v1.01, instances of this class are thread-safe. This means that a
-# single PreparedStatement can be accessed by multiple threads without the
-# internal consistency of the statement being altered. However, the
-# responsibility is on the client application to ensure that one thread reading
-# from a statement isn't affected by another thread starting a new query with
-# the same statement.
-# <p>
-# Stability: Added in v1.00, stability guaranteed for v1.xx.
-#
-# @param connection An instance of {@link Connection Connection}.
-#
-# @param statement The SQL statement to be represented, often containing
-# parameters in the form of $1, $2, $3, etc.
-#
-# @param types Python type objects for each parameter in the SQL
-# statement. For example, int, float, str.
-class PreparedStatement(object):
-
- ##
- # Determines the number of rows to read from the database server at once.
- # Reading more rows increases performance at the cost of memory. The
- # default value is 100 rows. The affect of this parameter is transparent.
- # That is, the library reads more rows when the cache is empty
- # automatically.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx. It is
- # possible that implementation changes in the future could cause this
- # parameter to be ignored.
- row_cache_size = 100
-
- def __init__(self, connection, statement, *types, **kwargs):
- global statement_number
- if connection == None or connection.c == None:
- raise InterfaceError("connection not provided")
- try:
- statement_number_lock.acquire()
- self._statement_number = statement_number
- statement_number += 1
- finally:
- statement_number_lock.release()
- self.c = connection.c
- self._portal_name = None
- self._statement_name = kwargs.get("statement_name", "pg8000_statement_%s" % self._statement_number)
- self._row_desc = None
- self._cached_rows = []
- self._ongoing_row_count = 0
- self._command_complete = True
- self._parse_row_desc = self.c.parse(self._statement_name, statement, types)
- self._lock = threading.RLock()
-
- def close(self):
- if self._statement_name != "": # don't close unnamed statement
- self.c.close_statement(self._statement_name)
- if self._portal_name != None:
- self.c.close_portal(self._portal_name)
- self._portal_name = None
-
- row_description = property(lambda self: self._getRowDescription())
- def _getRowDescription(self):
- if self._row_desc == None:
- return None
- return self._row_desc.fields
-
- ##
- # Run the SQL prepared statement with the given parameters.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def execute(self, *args, **kwargs):
- self._lock.acquire()
- try:
- if not self._command_complete:
- # cleanup last execute
- self._cached_rows = []
- self._ongoing_row_count = 0
- if self._portal_name != None:
- self.c.close_portal(self._portal_name)
- self._command_complete = False
- self._portal_name = "pg8000_portal_%s" % self._statement_number
- self._row_desc, cmd = self.c.bind(self._portal_name, self._statement_name, args, self._parse_row_desc, kwargs.get("stream"))
- if self._row_desc:
- # We execute our cursor right away to fill up our cache. This
- # prevents the cursor from being destroyed, apparently, by a rogue
- # Sync between Bind and Execute. Since it is quite likely that
- # data will be read from us right away anyways, this seems a safe
- # move for now.
- self._fill_cache()
- else:
- self._command_complete = True
- self._ongoing_row_count = -1
- if cmd != None and cmd.rows != None:
- self._ongoing_row_count = cmd.rows
- finally:
- self._lock.release()
-
- def _fill_cache(self):
- self._lock.acquire()
- try:
- if self._cached_rows:
- raise InternalError("attempt to fill cache that isn't empty")
- end_of_data, rows = self.c.fetch_rows(self._portal_name, self.row_cache_size, self._row_desc)
- self._cached_rows = rows
- if end_of_data:
- self._command_complete = True
- finally:
- self._lock.release()
-
- def _fetch(self):
- if not self._row_desc:
- raise ProgrammingError("no result set")
- self._lock.acquire()
- try:
- if not self._cached_rows:
- if self._command_complete:
- return None
- self._fill_cache()
- if self._command_complete and not self._cached_rows:
- # fill cache tells us the command is complete, but yet we have
- # no rows after filling our cache. This is a special case when
- # a query returns no rows.
- return None
- row = self._cached_rows.pop(0)
- self._ongoing_row_count += 1
- return tuple(row)
- finally:
- self._lock.release()
-
- ##
- # Return a count of the number of rows relevant to the executed statement.
- # For a SELECT, this is the number of rows returned. For UPDATE or DELETE,
- # this the number of rows affected. For INSERT, the number of rows
- # inserted. This property may have a value of -1 to indicate that there
- # was no row count.
- # <p>
- # During a result-set query (eg. SELECT, or INSERT ... RETURNING ...),
- # accessing this property requires reading the entire result-set into
- # memory, as reading the data to completion is the only way to determine
- # the total number of rows. Avoid using this property in with
- # result-set queries, as it may cause unexpected memory usage.
- # <p>
- # Stability: Added in v1.03, stability guaranteed for v1.xx.
- row_count = property(lambda self: self._get_row_count())
- def _get_row_count(self):
- self._lock.acquire()
- try:
- if not self._command_complete:
- end_of_data, rows = self.c.fetch_rows(self._portal_name, 0, self._row_desc)
- self._cached_rows += rows
- if end_of_data:
- self._command_complete = True
- else:
- raise InternalError("fetch_rows(0) did not hit end of data")
- return self._ongoing_row_count + len(self._cached_rows)
- finally:
- self._lock.release()
-
- ##
- # Read a row from the database server, and return it in a dictionary
- # indexed by column name/alias. This method will raise an error if two
- # columns have the same name. Returns None after the last row.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def read_dict(self):
- row = self._fetch()
- if row == None:
- return row
- retval = {}
- for i in range(len(self._row_desc.fields)):
- col_name = self._row_desc.fields[i]['name']
- if retval.has_key(col_name):
- raise InterfaceError("cannot return dict of row when two columns have the same name (%r)" % (col_name,))
- retval[col_name] = row[i]
- return retval
-
- ##
- # Read a row from the database server, and return it as a tuple of values.
- # Returns None after the last row.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def read_tuple(self):
- return self._fetch()
-
- ##
- # Return an iterator for the output of this statement. The iterator will
- # return a tuple for each row, in the same manner as {@link
- # #PreparedStatement.read_tuple read_tuple}.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def iterate_tuple(self):
- return DataIterator(self, PreparedStatement.read_tuple)
-
- ##
- # Return an iterator for the output of this statement. The iterator will
- # return a dict for each row, in the same manner as {@link
- # #PreparedStatement.read_dict read_dict}.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def iterate_dict(self):
- return DataIterator(self, PreparedStatement.read_dict)
-
-##
-# The Cursor class allows multiple queries to be performed concurrently with a
-# single PostgreSQL connection. The Cursor object is implemented internally by
-# using a {@link PreparedStatement PreparedStatement} object, so if you plan to
-# use a statement multiple times, you might as well create a PreparedStatement
-# and save a small amount of reparsing time.
-# <p>
-# As of v1.01, instances of this class are thread-safe. See {@link
-# PreparedStatement PreparedStatement} for more information.
-# <p>
-# Stability: Added in v1.00, stability guaranteed for v1.xx.
-#
-# @param connection An instance of {@link Connection Connection}.
-class Cursor(object):
- def __init__(self, connection):
- self.connection = connection
- self._stmt = None
-
- def require_stmt(func):
- def retval(self, *args, **kwargs):
- if self._stmt == None:
- raise ProgrammingError("attempting to use unexecuted cursor")
- return func(self, *args, **kwargs)
- return retval
-
- row_description = property(lambda self: self._getRowDescription())
- def _getRowDescription(self):
- if self._stmt == None:
- return None
- return self._stmt.row_description
-
- ##
- # Run an SQL statement using this cursor. The SQL statement can have
- # parameters in the form of $1, $2, $3, etc., which will be filled in by
- # the additional arguments passed to this function.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- # @param query The SQL statement to execute.
- def execute(self, query, *args, **kwargs):
- if self.connection.is_closed:
- raise ConnectionClosedError()
- self.connection._unnamed_prepared_statement_lock.acquire()
- try:
- self._stmt = PreparedStatement(self.connection, query, statement_name="", *[{"type": type(x), "value": x} for x in args])
- self._stmt.execute(*args, **kwargs)
- finally:
- self.connection._unnamed_prepared_statement_lock.release()
-
- ##
- # Return a count of the number of rows currently being read. If possible,
- # please avoid using this function. It requires reading the entire result
- # set from the database to determine the number of rows being returned.
- # <p>
- # Stability: Added in v1.03, stability guaranteed for v1.xx.
- # Implementation currently requires caching entire result set into memory,
- # avoid using this property.
- row_count = property(lambda self: self._get_row_count())
-
- @require_stmt
- def _get_row_count(self):
- return self._stmt.row_count
-
- ##
- # Read a row from the database server, and return it in a dictionary
- # indexed by column name/alias. This method will raise an error if two
- # columns have the same name. Returns None after the last row.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- @require_stmt
- def read_dict(self):
- return self._stmt.read_dict()
-
- ##
- # Read a row from the database server, and return it as a tuple of values.
- # Returns None after the last row.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- @require_stmt
- def read_tuple(self):
- return self._stmt.read_tuple()
-
- ##
- # Return an iterator for the output of this statement. The iterator will
- # return a tuple for each row, in the same manner as {@link
- # #PreparedStatement.read_tuple read_tuple}.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- @require_stmt
- def iterate_tuple(self):
- return self._stmt.iterate_tuple()
-
- ##
- # Return an iterator for the output of this statement. The iterator will
- # return a dict for each row, in the same manner as {@link
- # #PreparedStatement.read_dict read_dict}.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- @require_stmt
- def iterate_dict(self):
- return self._stmt.iterate_dict()
-
- def close(self):
- if self._stmt != None:
- self._stmt.close()
- self._stmt = None
-
-
- ##
- # Return the fileno of the underlying socket for this cursor's connection.
- # <p>
- # Stability: Added in v1.07, stability guaranteed for v1.xx.
- def fileno(self):
- return self.connection.fileno()
-
- ##
- # Poll the underlying socket for this cursor and sync if there is data waiting
- # to be read. This has the effect of flushing asynchronous messages from the
- # backend. Returns True if messages were read, False otherwise.
- # <p>
- # Stability: Added in v1.07, stability guaranteed for v1.xx.
- def isready(self):
- return self.connection.isready()
-
-
-##
-# This class represents a connection to a PostgreSQL database.
-# <p>
-# The database connection is derived from the {@link #Cursor Cursor} class,
-# which provides a default cursor for running queries. It also provides
-# transaction control via the 'begin', 'commit', and 'rollback' methods.
-# Without beginning a transaction explicitly, all statements will autocommit to
-# the database.
-# <p>
-# As of v1.01, instances of this class are thread-safe. See {@link
-# PreparedStatement PreparedStatement} for more information.
-# <p>
-# Stability: Added in v1.00, stability guaranteed for v1.xx.
-#
-# @param user The username to connect to the PostgreSQL server with. This
-# parameter is required.
-#
-# @keyparam host The hostname of the PostgreSQL server to connect with.
-# Providing this parameter is necessary for TCP/IP connections. One of either
-# host, or unix_sock, must be provided.
-#
-# @keyparam unix_sock The path to the UNIX socket to access the database
-# through, for example, '/tmp/.s.PGSQL.5432'. One of either unix_sock or host
-# must be provided. The port parameter will have no affect if unix_sock is
-# provided.
-#
-# @keyparam port The TCP/IP port of the PostgreSQL server instance. This
-# parameter defaults to 5432, the registered and common port of PostgreSQL
-# TCP/IP servers.
-#
-# @keyparam database The name of the database instance to connect with. This
-# parameter is optional, if omitted the PostgreSQL server will assume the
-# database name is the same as the username.
-#
-# @keyparam password The user password to connect to the server with. This
-# parameter is optional. If omitted, and the database server requests password
-# based authentication, the connection will fail. On the other hand, if this
-# parameter is provided and the database does not request password
-# authentication, then the password will not be used.
-#
-# @keyparam socket_timeout Socket connect timeout measured in seconds.
-# Defaults to 60 seconds.
-#
-# @keyparam ssl Use SSL encryption for TCP/IP socket. Defaults to False.
-class Connection(Cursor):
- def __init__(self, user, host=None, unix_sock=None, port=5432, database=None, password=None, socket_timeout=60, ssl=False, options=None):
- self._row_desc = None
- try:
- self.c = protocol.Connection(unix_sock=unix_sock, host=host, port=port, socket_timeout=socket_timeout, ssl=ssl)
- self.c.authenticate(user, password=password, database=database, options=options)
- except socket.error, e:
- raise InterfaceError("communication error", e)
- Cursor.__init__(self, self)
- self._begin = PreparedStatement(self, "BEGIN TRANSACTION")
- self._commit = PreparedStatement(self, "COMMIT TRANSACTION")
- self._rollback = PreparedStatement(self, "ROLLBACK TRANSACTION")
- self._unnamed_prepared_statement_lock = threading.RLock()
-
- ##
- # An event handler that is fired when NOTIFY occurs for a notification that
- # has been LISTEN'd for. The value of this property is a
- # util.MulticastDelegate. A callback can be added by using
- # connection.NotificationReceived += SomeMethod. The method will be called
- # with a single argument, an object that has properties: backend_pid,
- # condition, and additional_info. Callbacks can be removed with the -=
- # operator.
- # <p>
- # Stability: Added in v1.03, stability guaranteed for v1.xx.
- NotificationReceived = property(
- lambda self: getattr(self.c, "NotificationReceived"),
- lambda self, value: setattr(self.c, "NotificationReceived", value)
- )
-
- ##
- # An event handler that is fired when the database server issues a notice.
- # The value of this property is a util.MulticastDelegate. A callback can
- # be added by using connection.NotificationReceived += SomeMethod. The
- # method will be called with a single argument, an object that has
- # properties: severity, code, msg, and possibly others (detail, hint,
- # position, where, file, line, and routine). Callbacks can be removed with
- # the -= operator.
- # <p>
- # Stability: Added in v1.03, stability guaranteed for v1.xx.
- NoticeReceived = property(
- lambda self: getattr(self.c, "NoticeReceived"),
- lambda self, value: setattr(self.c, "NoticeReceived", value)
- )
-
- ##
- # An event handler that is fired when a runtime configuration option is
- # changed on the server. The value of this property is a
- # util.MulticastDelegate. A callback can be added by using
- # connection.NotificationReceived += SomeMethod. Callbacks can be removed
- # with the -= operator. The method will be called with a single argument,
- # an object that has properties "key" and "value".
- # <p>
- # Stability: Added in v1.03, stability guaranteed for v1.xx.
- ParameterStatusReceived = property(
- lambda self: getattr(self.c, "ParameterStatusReceived"),
- lambda self, value: setattr(self.c, "ParameterStatusReceived", value)
- )
-
- ##
- # Begins a new transaction.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def begin(self):
- if self.is_closed:
- raise ConnectionClosedError()
- self._begin.execute()
-
- ##
- # Commits the running transaction.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def commit(self):
- if self.is_closed:
- raise ConnectionClosedError()
- self._commit.execute()
-
- ##
- # Rolls back the running transaction.
- # <p>
- # Stability: Added in v1.00, stability guaranteed for v1.xx.
- def rollback(self):
- if self.is_closed:
- raise ConnectionClosedError()
- self._rollback.execute()
-
- ##
- # Closes an open connection.
- def close(self):
- if self.is_closed:
- raise ConnectionClosedError()
- self.c.close()
- self.c = None
-
- is_closed = property(lambda self: self.c == None)
-
- def recache_record_types(self):
- self.c._cache_record_attnames()
-
- ##
- # Return the fileno of the underlying socket for this connection.
- # <p>
- # Stability: Added in v1.07, stability guaranteed for v1.xx.
- def fileno(self):
- return self.c.fileno()
-
- ##
- # Poll the underlying socket for this connection and sync if there is data
- # waiting to be read. This has the effect of flushing asynchronous
- # messages from the backend. Returns True if messages were read, False
- # otherwise.
- # <p>
- # Stability: Added in v1.07, stability guaranteed for v1.xx.
- def isready(self):
- return self.c.isready()
-
[05/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.html
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.html b/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.html
deleted file mode 100644
index 2e90378..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/docs/pg.html
+++ /dev/null
@@ -1,2429 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
-<title>PyGreSQL Programming Information</title>
-<meta content="The classic PyGreSQL interface (pg module)" name="description" />
-<meta content="PyGreSQL, pg, PostGreSQL, Python" name="keywords" />
-<link rel="stylesheet" href="docs.css" type="text/css" />
-</head>
-<body>
-<div class="document" id="pygresql-programming-information">
-<h1 class="title">PyGreSQL Programming Information</h1>
-<h2 class="subtitle" id="the-classic-pygresql-interface-pg-module">The classic PyGreSQL interface (pg module)</h2>
-<div class="contents topic">
-<p class="topic-title first"><a id="contents" name="contents">Contents</a></p>
-<ul class="auto-toc simple">
-<li><a class="reference" href="#introduction" id="id5" name="id5">1 Introduction</a></li>
-<li><a class="reference" href="#module-functions-and-constants" id="id6" name="id6">2 Module functions and constants</a><ul class="auto-toc">
-<li><a class="reference" href="#connect-opens-a-pg-connection" id="id7" name="id7">2.1 connect - opens a pg connection</a></li>
-<li><a class="reference" href="#get-defhost-set-defhost-default-server-host-dv" id="id8" name="id8">2.2 get_defhost, set_defhost - default server host [DV]</a></li>
-<li><a class="reference" href="#get-defport-set-defport-default-server-port-dv" id="id9" name="id9">2.3 get_defport, set_defport - default server port [DV]</a></li>
-<li><a class="reference" href="#get-defopt-set-defopt-default-connection-options-dv" id="id10" name="id10">2.4 get_defopt, set_defopt - default connection options [DV]</a></li>
-<li><a class="reference" href="#get-deftty-set-deftty-default-debug-tty-dv" id="id11" name="id11">2.5 get_deftty, set_deftty - default debug tty [DV]</a></li>
-<li><a class="reference" href="#get-defbase-set-defbase-default-database-name-dv" id="id12" name="id12">2.6 get_defbase, set_defbase - default database name [DV]</a></li>
-<li><a class="reference" href="#escape-string-escape-a-string-for-use-within-sql" id="id13" name="id13">2.7 escape_string - escape a string for use within SQL</a></li>
-<li><a class="reference" href="#escape-bytea-escape-binary-data-for-use-within-sql-as-type-bytea" id="id14" name="id14">2.8 escape_bytea - escape binary data for use within SQL as type <cite>bytea</cite></a></li>
-<li><a class="reference" href="#unescape-bytea-unescape-bytea-data-that-has-been-retrieved-as-text" id="id15" name="id15">2.9 unescape_bytea -- unescape <cite>bytea</cite> data that has been retrieved as text</a></li>
-<li><a class="reference" href="#set-decimal-set-a-decimal-type-to-be-used-for-numeric-values" id="id16" name="id16">2.10 set_decimal -- set a decimal type to be used for numeric values</a></li>
-<li><a class="reference" href="#module-constants" id="id17" name="id17">2.11 Module constants</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#connection-objects-pgobject" id="id18" name="id18">3 Connection objects: pgobject</a><ul class="auto-toc">
-<li><a class="reference" href="#query-executes-a-sql-command-string" id="id19" name="id19">3.1 query - executes a SQL command string</a></li>
-<li><a class="reference" href="#reset-resets-the-connection" id="id20" name="id20">3.2 reset - resets the connection</a></li>
-<li><a class="reference" href="#cancel-abandon-processing-of-current-sql-command" id="id21" name="id21">3.3 cancel - abandon processing of current SQL command</a></li>
-<li><a class="reference" href="#close-close-the-database-connection" id="id22" name="id22">3.4 close - close the database connection</a></li>
-<li><a class="reference" href="#fileno-returns-the-socket-used-to-connect-to-the-database" id="id23" name="id23">3.5 fileno - returns the socket used to connect to the database</a></li>
-<li><a class="reference" href="#getnotify-gets-the-last-notify-from-the-server" id="id24" name="id24">3.6 getnotify - gets the last notify from the server</a></li>
-<li><a class="reference" href="#inserttable-insert-a-list-into-a-table" id="id25" name="id25">3.7 inserttable - insert a list into a table</a></li>
-<li><a class="reference" href="#putline-writes-a-line-to-the-server-socket-da" id="id26" name="id26">3.8 putline - writes a line to the server socket [DA]</a></li>
-<li><a class="reference" href="#getline-gets-a-line-from-server-socket-da" id="id27" name="id27">3.9 getline - gets a line from server socket [DA]</a></li>
-<li><a class="reference" href="#endcopy-synchronizes-client-and-server-da" id="id28" name="id28">3.10 endcopy - synchronizes client and server [DA]</a></li>
-<li><a class="reference" href="#locreate-create-a-large-object-in-the-database-lo" id="id29" name="id29">3.11 locreate - create a large object in the database [LO]</a></li>
-<li><a class="reference" href="#getlo-build-a-large-object-from-given-oid-lo" id="id30" name="id30">3.12 getlo - build a large object from given oid [LO]</a></li>
-<li><a class="reference" href="#loimport-import-a-file-to-a-large-object-lo" id="id31" name="id31">3.13 loimport - import a file to a large object [LO]</a></li>
-<li><a class="reference" href="#object-attributes" id="id32" name="id32">3.14 Object attributes</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#the-db-wrapper-class" id="id33" name="id33">4 The DB wrapper class</a><ul class="auto-toc">
-<li><a class="reference" href="#initialization" id="id34" name="id34">4.1 Initialization</a></li>
-<li><a class="reference" href="#pkey-return-the-primary-key-of-a-table" id="id35" name="id35">4.2 pkey - return the primary key of a table</a></li>
-<li><a class="reference" href="#get-databases-get-list-of-databases-in-the-system" id="id36" name="id36">4.3 get_databases - get list of databases in the system</a></li>
-<li><a class="reference" href="#get-relations-get-list-of-relations-in-connected-database" id="id37" name="id37">4.4 get_relations - get list of relations in connected database</a></li>
-<li><a class="reference" href="#get-tables-get-list-of-tables-in-connected-database" id="id38" name="id38">4.5 get_tables - get list of tables in connected database</a></li>
-<li><a class="reference" href="#get-attnames-get-the-attribute-names-of-a-table" id="id39" name="id39">4.6 get_attnames - get the attribute names of a table</a></li>
-<li><a class="reference" href="#has-table-privilege-check-whether-current-user-has-specified-table-privilege" id="id40" name="id40">4.7 has_table_privilege - check whether current user has specified table privilege</a></li>
-<li><a class="reference" href="#get-get-a-row-from-a-database-table-or-view" id="id41" name="id41">4.8 get - get a row from a database table or view</a></li>
-<li><a class="reference" href="#insert-insert-a-row-into-a-database-table" id="id42" name="id42">4.9 insert - insert a row into a database table</a></li>
-<li><a class="reference" href="#update-update-a-row-in-a-database-table" id="id43" name="id43">4.10 update - update a row in a database table</a></li>
-<li><a class="reference" href="#clear-clears-row-values-in-memory" id="id44" name="id44">4.11 clear - clears row values in memory</a></li>
-<li><a class="reference" href="#delete-delete-a-row-from-a-database-table" id="id45" name="id45">4.12 delete - delete a row from a database table</a></li>
-<li><a class="reference" href="#id1" id="id46" name="id46">4.13 escape_string - escape a string for use within SQL</a></li>
-<li><a class="reference" href="#id2" id="id47" name="id47">4.14 escape_bytea - escape binary data for use within SQL as type <cite>bytea</cite></a></li>
-<li><a class="reference" href="#id3" id="id48" name="id48">4.15 unescape_bytea -- unescape <cite>bytea</cite> data that has been retrieved as text</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#pgqueryobject-methods" id="id49" name="id49">5 pgqueryobject methods</a><ul class="auto-toc">
-<li><a class="reference" href="#getresult-get-query-values-as-list-of-tuples" id="id50" name="id50">5.1 getresult - get query values as list of tuples</a></li>
-<li><a class="reference" href="#dictresult-get-query-values-as-list-of-dictionaries" id="id51" name="id51">5.2 dictresult - get query values as list of dictionaries</a></li>
-<li><a class="reference" href="#listfields-lists-fields-names-of-previous-query-result" id="id52" name="id52">5.3 listfields - lists fields names of previous query result</a></li>
-<li><a class="reference" href="#fieldname-fieldnum-field-name-number-conversion" id="id53" name="id53">5.4 fieldname, fieldnum - field name/number conversion</a></li>
-<li><a class="reference" href="#ntuples-return-number-of-tuples-in-query-object" id="id54" name="id54">5.5 ntuples - return number of tuples in query object</a></li>
-</ul>
-</li>
-<li><a class="reference" href="#large-objects-pglarge" id="id55" name="id55">6 Large objects: pglarge</a><ul class="auto-toc">
-<li><a class="reference" href="#open-opens-a-large-object" id="id56" name="id56">6.1 open - opens a large object</a></li>
-<li><a class="reference" href="#close-closes-a-large-object" id="id57" name="id57">6.2 close - closes a large object</a></li>
-<li><a class="reference" href="#read-write-tell-seek-unlink-file-like-large-object-handling" id="id58" name="id58">6.3 read, write, tell, seek, unlink - file like large object handling</a></li>
-<li><a class="reference" href="#size-gives-the-large-object-size" id="id59" name="id59">6.4 size - gives the large object size</a></li>
-<li><a class="reference" href="#export-saves-a-large-object-to-a-file" id="id60" name="id60">6.5 export - saves a large object to a file</a></li>
-<li><a class="reference" href="#id4" id="id61" name="id61">6.6 Object attributes</a></li>
-</ul>
-</li>
-</ul>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id5" id="introduction" name="introduction">1 Introduction</a></h1>
-<p>You may either choose to use the
-<a class="reference" href="pg.html">"classic" PyGreSQL interface</a>
-provided by the <cite>pg</cite> module or else the
-<a class="reference" href="pgdb.html">DB-API 2.0 compliant interface</a>
-provided by the <cite>pgdb</cite> module.</p>
-<p>The following documentation covers only the older <cite>pg</cite> API.</p>
-<p>The <cite>pg</cite> module handles three types of objects,</p>
-<ul class="simple">
-<li>the <cite>pgobject</cite>, which handles the connection
-and all the requests to the database,</li>
-<li>the <cite>pglarge</cite> object, which handles
-all the accesses to PostgreSQL large objects,</li>
-<li>the <cite>pgqueryobject</cite> that handles query results</li>
-</ul>
-<p>and it provides a convenient wrapper class <cite>DB</cite> for the <cite>pgobject</cite>.</p>
-<p>If you want to see a simple example of the use of some of these functions,
-see <a class="reference" href="http://ontario.bikerides.ca">http://ontario.bikerides.ca</a> where you can find a link at the bottom to the
-actual Python code for the page.</p>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id6" id="module-functions-and-constants" name="module-functions-and-constants">2 Module functions and constants</a></h1>
-<p>The <cite>pg</cite> module defines a few functions that allow to connect
-to a database and to define "default variables" that override
-the environment variables used by PostgreSQL.</p>
-<p>These "default variables" were designed to allow you to handle general
-connection parameters without heavy code in your programs. You can prompt the
-user for a value, put it in the default variable, and forget it, without
-having to modify your environment. The support for default variables can be
-disabled by setting the -DNO_DEF_VAR option in the Python setup file. Methods
-relative to this are specified by the tag [DV].</p>
-<p>All variables are set to <cite>None</cite> at module initialization, specifying that
-standard environment variables should be used.</p>
-<div class="section">
-<h2><a class="toc-backref" href="#id7" id="connect-opens-a-pg-connection" name="connect-opens-a-pg-connection">2.1 connect - opens a pg connection</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-connect([dbname], [host], [port], [opt], [tty], [user], [passwd])
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">dbname:</th><td class="field-body">name of connected database (string/None)</td>
-</tr>
-<tr class="field"><th class="field-name">host:</th><td class="field-body">name of the server host (string/None)</td>
-</tr>
-<tr class="field"><th class="field-name">port:</th><td class="field-body">port used by the database server (integer/-1)</td>
-</tr>
-<tr class="field"><th class="field-name">opt:</th><td class="field-body">connection options (string/None)</td>
-</tr>
-<tr class="field"><th class="field-name">tty:</th><td class="field-body">debug terminal (string/None)</td>
-</tr>
-<tr class="field"><th class="field-name">user:</th><td class="field-body">PostgreSQL user (string/None)</td>
-</tr>
-<tr class="field"><th class="field-name">passwd:</th><td class="field-body">password for user (string/None)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">pgobject:</th><td class="field-body">If successful, the <cite>pgobject</cite> handling the connection</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-<tr class="field"><th class="field-name">SyntaxError:</th><td class="field-body">duplicate argument definition</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError:</th></tr>
-<tr><td> </td><td class="field-body">some error occurred during pg connection definition</td>
-</tr>
-</tbody>
-</table>
-<p class="last">(plus all exceptions relative to object allocation)</p>
-</dd>
-<dt>Description:</dt>
-<dd>This function opens a connection to a specified database on a given
-PostgreSQL server. You can use keywords here, as described in the
-Python tutorial. The names of the keywords are the name of the
-parameters given in the syntax line. For a precise description
-of the parameters, please refer to the PostgreSQL user manual.</dd>
-</dl>
-<p>Examples:</p>
-<pre class="literal-block">
-import pg
-
-con1 = pg.connect('testdb', 'myhost', 5432, None, None, 'bob', None)
-con2 = pg.connect(dbname='testdb', host='localhost', user='bob')
-</pre>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id8" id="get-defhost-set-defhost-default-server-host-dv" name="get-defhost-set-defhost-default-server-host-dv">2.2 get_defhost, set_defhost - default server host [DV]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_defhost()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">default host specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the current default host specification,
-or <cite>None</cite> if the environment variables should be used.
-Environment variables won't be looked up.</dd>
-</dl>
-<p>Syntax:</p>
-<pre class="literal-block">
-set_defhost(host)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">host:</th><td class="field-body">new default host (string/None)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">previous default host specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This methods sets the default host value for new connections.
-If <cite>None</cite> is supplied as parameter, environment variables will
-be used in future connections. It returns the previous setting
-for default host.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id9" id="get-defport-set-defport-default-server-port-dv" name="get-defport-set-defport-default-server-port-dv">2.3 get_defport, set_defport - default server port [DV]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_defport()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">integer, None:</th><td class="field-body">default port specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the current default port specification,
-or <cite>None</cite> if the environment variables should be used.
-Environment variables won't be looked up.</dd>
-</dl>
-<p>Syntax:</p>
-<pre class="literal-block">
-set_defport(port)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">port:</th><td class="field-body">new default port (integer/-1)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">integer, None:</th><td class="field-body">previous default port specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This methods sets the default port value for new connections. If -1 is
-supplied as parameter, environment variables will be used in future
-connections. It returns the previous setting for default port.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id10" id="get-defopt-set-defopt-default-connection-options-dv" name="get-defopt-set-defopt-default-connection-options-dv">2.4 get_defopt, set_defopt - default connection options [DV]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_defopt()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">default options specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the current default connection options specification,
-or <cite>None</cite> if the environment variables should be used. Environment variables
-won't be looked up.</dd>
-</dl>
-<p>Syntax:</p>
-<pre class="literal-block">
-set_defopt(options)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">options:</th><td class="field-body">new default connection options (string/None)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">previous default options specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This methods sets the default connection options value for new connections.
-If <cite>None</cite> is supplied as parameter, environment variables will be used in
-future connections. It returns the previous setting for default options.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id11" id="get-deftty-set-deftty-default-debug-tty-dv" name="get-deftty-set-deftty-default-debug-tty-dv">2.5 get_deftty, set_deftty - default debug tty [DV]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_deftty()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">default debug terminal specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the current default debug terminal specification, or
-<cite>None</cite> if the environment variables should be used. Environment variables
-won't be looked up.</dd>
-</dl>
-<p>Syntax:</p>
-<pre class="literal-block">
-set_deftty(terminal)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">terminal:</th><td class="field-body">new default debug terminal (string/None)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">previous default debug terminal specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This methods sets the default debug terminal value for new connections. If
-<cite>None</cite> is supplied as parameter, environment variables will be used in future
-connections. It returns the previous setting for default terminal.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id12" id="get-defbase-set-defbase-default-database-name-dv" name="get-defbase-set-defbase-default-database-name-dv">2.6 get_defbase, set_defbase - default database name [DV]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_defbase()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">default database name specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the current default database name specification, or
-<cite>None</cite> if the environment variables should be used. Environment variables
-won't be looked up.</dd>
-</dl>
-<p>Syntax:</p>
-<pre class="literal-block">
-set_defbase(base)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">base:</th><td class="field-body">new default base name (string/None)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string, None:</th><td class="field-body">previous default database name specification</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method sets the default database name value for new connections. If
-<cite>None</cite> is supplied as parameter, environment variables will be used in
-future connections. It returns the previous setting for default host.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id13" id="escape-string-escape-a-string-for-use-within-sql" name="escape-string-escape-a-string-for-use-within-sql">2.7 escape_string - escape a string for use within SQL</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-escape_string(string)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string:</th><td class="field-body">the string that is to be escaped</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">str:</th><td class="field-body">the escaped string</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This function escapes a string for use within an SQL command.
-This is useful when inserting data values as literal constants
-in SQL commands. Certain characters (such as quotes and backslashes)
-must be escaped to prevent them from being interpreted specially
-by the SQL parser. <cite>escape_string</cite> performs this operation.
-Note that there is also a <cite>pgobject</cite> method with the same name
-which takes connection properties into account.</dd>
-</dl>
-<div class="caution">
-<p class="first admonition-title">Caution!</p>
-<p class="last">It is especially important to do proper escaping when
-handling strings that were received from an untrustworthy source.
-Otherwise there is a security risk: you are vulnerable to "SQL injection"
-attacks wherein unwanted SQL commands are fed to your database.</p>
-</div>
-<p>Example:</p>
-<pre class="literal-block">
-name = raw_input("Name? ")
-phone = con.query("select phone from employees"
- " where name='%s'" % escape_string(name)).getresult()
-</pre>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id14" id="escape-bytea-escape-binary-data-for-use-within-sql-as-type-bytea" name="escape-bytea-escape-binary-data-for-use-within-sql-as-type-bytea">2.8 escape_bytea - escape binary data for use within SQL as type <cite>bytea</cite></a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-escape_bytea(datastring)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">datastring:</th><td class="field-body">string containing the binary data that is to be escaped</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">str:</th><td class="field-body">the escaped string</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Escapes binary data for use within an SQL command with the type <cite>bytea</cite>.
-As with <cite>escape_string</cite>, this is only used when inserting data directly
-into an SQL command string.
-Note that there is also a <cite>pgobject</cite> method with the same name
-which takes connection properties into account.</dd>
-</dl>
-<p>Example:</p>
-<pre class="literal-block">
-picture = file('garfield.gif', 'rb').read()
-con.query("update pictures set img='%s' where name='Garfield'"
- % escape_bytea(picture))
-</pre>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id15" id="unescape-bytea-unescape-bytea-data-that-has-been-retrieved-as-text" name="unescape-bytea-unescape-bytea-data-that-has-been-retrieved-as-text">2.9 unescape_bytea -- unescape <cite>bytea</cite> data that has been retrieved as text</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-unescape_bytea(string)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">datastring:</th><td class="field-body">the <cite>bytea</cite> data string that has been retrieved as text</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">str:</th><td class="field-body">string containing the binary data</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Converts an escaped string representation of binary data into binary
-data - the reverse of <cite>escape_bytea</cite>. This is needed when retrieving
-<cite>bytea</cite> data with the <cite>getresult()</cite> or <cite>dictresult()</cite> method.</dd>
-</dl>
-<p>Example:</p>
-<pre class="literal-block">
-picture = unescape_bytea(con.query(
- "select img from pictures where name='Garfield'").getresult[0][0])
-file('garfield.gif', 'wb').write(picture)
-</pre>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id16" id="set-decimal-set-a-decimal-type-to-be-used-for-numeric-values" name="set-decimal-set-a-decimal-type-to-be-used-for-numeric-values">2.10 set_decimal -- set a decimal type to be used for numeric values</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-set_decimal(cls)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">cls:</th><td class="field-body">the Python class to be used for PostgreSQL numeric values</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This function can be used to specify the Python class that shall be
-used by PyGreSQL to hold PostgreSQL numeric values. The default class
-is decimal.Decimal if available, otherwise the float type is used.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id17" id="module-constants" name="module-constants">2.11 Module constants</a></h2>
-<p>Some constants are defined in the module dictionary.
-They are intended to be used as parameters for methods calls.
-You should refer to the libpq description in the PostgreSQL user manual
-for more information about them. These constants are:</p>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name" colspan="2">version, __version__:</th></tr>
-<tr><td> </td><td class="field-body">constants that give the current version.</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">INV_READ, INV_WRITE:</th></tr>
-<tr><td> </td><td class="field-body">large objects access modes,
-used by <cite>(pgobject.)locreate</cite> and <cite>(pglarge.)open</cite></td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">SEEK_SET, SEEK_CUR, SEEK_END:</th></tr>
-<tr><td> </td><td class="field-body">positional flags,
-used by <cite>(pglarge.)seek</cite></td>
-</tr>
-</tbody>
-</table>
-</div>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id18" id="connection-objects-pgobject" name="connection-objects-pgobject">3 Connection objects: pgobject</a></h1>
-<p>This object handles a connection to a PostgreSQL database. It embeds and
-hides all the parameters that define this connection, thus just leaving really
-significant parameters in function calls.</p>
-<div class="caution">
-<p class="first admonition-title">Caution!</p>
-<p>Some methods give direct access to the connection socket.
-<em>Do not use them unless you really know what you are doing.</em>
-If you prefer disabling them,
-set the -DNO_DIRECT option in the Python setup file.</p>
-<p class="last"><strong>These methods are specified by the tag [DA].</strong></p>
-</div>
-<div class="note">
-<p class="first admonition-title">Note</p>
-<p>Some other methods give access to large objects
-(refer to PostgreSQL user manual for more information about these).
-If you want to forbid access to these from the module,
-set the -DNO_LARGE option in the Python setup file.</p>
-<p class="last"><strong>These methods are specified by the tag [LO].</strong></p>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id19" id="query-executes-a-sql-command-string" name="query-executes-a-sql-command-string">3.1 query - executes a SQL command string</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-query(command)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">command:</th><td class="field-body">SQL command (string)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name" colspan="2">pgqueryobject, None:</th></tr>
-<tr><td> </td><td class="field-body">result values</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">bad argument type, or too many arguments</td>
-</tr>
-<tr class="field"><th class="field-name">ValueError:</th><td class="field-body">empty SQL query or lost connection</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.ProgrammingError:</th></tr>
-<tr><td> </td><td class="field-body">error in query</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError':</th></tr>
-<tr><td> </td><td class="field-body">error during query processing</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method simply sends a SQL query to the database. If the query is an
-insert statement that inserted exactly one row into a table that has OIDs, the
-return value is the OID of the newly inserted row. If the query is an update
-or delete statement, or an insert statement that did not insert exactly one
-row in a table with OIDs, then the numer of rows affected is returned as a
-string. If it is a statement that returns rows as a result (usually a select
-statement, but maybe also an "insert/update ... returning" statement), this
-method returns a <cite>pgqueryobject</cite> that can be accessed via the <cite>getresult()</cite>
-or <cite>dictresult()</cite> method or simply printed. Otherwise, it returns <cite>None</cite>.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id20" id="reset-resets-the-connection" name="reset-resets-the-connection">3.2 reset - resets the connection</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-reset()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many (any) arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method resets the current database connection.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id21" id="cancel-abandon-processing-of-current-sql-command" name="cancel-abandon-processing-of-current-sql-command">3.3 cancel - abandon processing of current SQL command</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-cancel()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many (any) arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method requests that the server abandon processing
-of the current SQL command.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id22" id="close-close-the-database-connection" name="close-close-the-database-connection">3.4 close - close the database connection</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-close()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many (any) arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method closes the database connection. The connection will
-be closed in any case when the connection is deleted but this
-allows you to explicitly close it. It is mainly here to allow
-the DB-SIG API wrapper to implement a close function.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id23" id="fileno-returns-the-socket-used-to-connect-to-the-database" name="fileno-returns-the-socket-used-to-connect-to-the-database">3.5 fileno - returns the socket used to connect to the database</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-fileno()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many (any) arguments</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the underlying socket id used to connect
-to the database. This is useful for use in select calls, etc.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id24" id="getnotify-gets-the-last-notify-from-the-server" name="getnotify-gets-the-last-notify-from-the-server">3.6 getnotify - gets the last notify from the server</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-getnotify()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">tuple, None:</th><td class="field-body">last notify from server</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This methods try to get a notify from the server (from the SQL statement
-NOTIFY). If the server returns no notify, the methods returns None.
-Otherwise, it returns a tuple (couple) <cite>(relname, pid)</cite>, where <cite>relname</cite>
-is the name of the notify and <cite>pid</cite> the process id of the connection that
-triggered the notify. Remember to do a listen query first otherwise
-getnotify() will always return <cite>None</cite>.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id25" id="inserttable-insert-a-list-into-a-table" name="inserttable-insert-a-list-into-a-table">3.7 inserttable - insert a list into a table</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-inserttable(table, values)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">the table name (string)</td>
-</tr>
-<tr class="field"><th class="field-name">values:</th><td class="field-body">list of rows values (list)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad argument type, or too many arguments</td>
-</tr>
-<tr class="field"><th class="field-name">MemoryError:</th><td class="field-body">insert buffer could not be allocated</td>
-</tr>
-<tr class="field"><th class="field-name">ValueError:</th><td class="field-body">unsupported values</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method allow to <em>quickly</em> insert large blocks of data in a table:
-It inserts the whole values list into the given table. Internally, it
-uses the COPY command of the PostgreSQL database. The list is a list
-of tuples/lists that define the values for each inserted row. The rows
-values may contain string, integer, long or double (real) values.</dd>
-</dl>
-<div class="caution">
-<p class="first admonition-title">Caution!</p>
-<p class="last"><em>Be very careful</em>:
-This method doesn't typecheck the fields according to the table definition;
-it just look whether or not it knows how to handle such types.</p>
-</div>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id26" id="putline-writes-a-line-to-the-server-socket-da" name="putline-writes-a-line-to-the-server-socket-da">3.8 putline - writes a line to the server socket [DA]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-putline(line)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">line:</th><td class="field-body">line to be written (string)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad parameter type, or too many parameters</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method allows to directly write a string to the server socket.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id27" id="getline-gets-a-line-from-server-socket-da" name="getline-gets-a-line-from-server-socket-da">3.9 getline - gets a line from server socket [DA]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-getline()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string:</th><td class="field-body">the line read</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection</td>
-</tr>
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name">MemoryError:</th><td class="field-body">buffer overflow</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method allows to directly read a string from the server socket.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id28" id="endcopy-synchronizes-client-and-server-da" name="endcopy-synchronizes-client-and-server-da">3.10 endcopy - synchronizes client and server [DA]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-endcopy()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd>None</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection</td>
-</tr>
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many parameters</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>The use of direct access methods may desynchonize client and server.
-This method ensure that client and server will be synchronized.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id29" id="locreate-create-a-large-object-in-the-database-lo" name="locreate-create-a-large-object-in-the-database-lo">3.11 locreate - create a large object in the database [LO]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-locreate(mode)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">mode:</th><td class="field-body">large object create mode</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">pglarge:</th><td class="field-body">object handling the PostGreSQL large object</td>
-</tr>
-</tbody>
-</table>
-</dd>
-</dl>
-<p>Exceptions raised:</p>
-<blockquote>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad parameter type, or too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.OperationalError:</th></tr>
-<tr><td> </td><td class="field-body">creation error</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-<dl class="docutils">
-<dt>Description:</dt>
-<dd>This method creates a large object in the database. The mode can be defined
-by OR-ing the constants defined in the pg module (INV_READ, INV_WRITE and
-INV_ARCHIVE). Please refer to PostgreSQL user manual for a description of
-the mode values.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id30" id="getlo-build-a-large-object-from-given-oid-lo" name="getlo-build-a-large-object-from-given-oid-lo">3.12 getlo - build a large object from given oid [LO]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-getlo(oid)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">oid:</th><td class="field-body">OID of the existing large object (integer)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">pglarge:</th><td class="field-body">object handling the PostGreSQL large object</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad parameter type, or too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name">ValueError:</th><td class="field-body">bad OID value (0 is invalid_oid)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method allows to reuse a formerly created large object through the
-<cite>pglarge</cite> interface, providing the user have its OID.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id31" id="loimport-import-a-file-to-a-large-object-lo" name="loimport-import-a-file-to-a-large-object-lo">3.13 loimport - import a file to a large object [LO]</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-loimport(name)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">name:</th><td class="field-body">the name of the file to be imported (string)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">pglarge:</th><td class="field-body">object handling the PostGreSQL large object</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad argument type, or too many arguments</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.OperationalError:</th></tr>
-<tr><td> </td><td class="field-body">error during file import</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This methods allows to create large objects in a very simple way. You just
-give the name of a file containing the data to be use.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id32" id="object-attributes" name="object-attributes">3.14 Object attributes</a></h2>
-<p>Every <cite>pgobject</cite> defines a set of read-only attributes that describe the
-connection and its status. These attributes are:</p>
-<blockquote>
-<table class="docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">host:</th><td class="field-body">the host name of the server (string)</td>
-</tr>
-<tr class="field"><th class="field-name">port:</th><td class="field-body">the port of the server (integer)</td>
-</tr>
-<tr class="field"><th class="field-name">db:</th><td class="field-body">the selected database (string)</td>
-</tr>
-<tr class="field"><th class="field-name">options:</th><td class="field-body">the connection options (string)</td>
-</tr>
-<tr class="field"><th class="field-name">tty:</th><td class="field-body">the connection debug terminal (string)</td>
-</tr>
-<tr class="field"><th class="field-name">user:</th><td class="field-body">user name on the database system (string)</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">protocol_version:</th></tr>
-<tr><td> </td><td class="field-body">the frontend/backend protocol being used (integer)</td>
-</tr>
-<tr class="field"><th class="field-name">server_version:</th><td class="field-body">the backend version (integer, e.g. 80305 for 8.3.5)</td>
-</tr>
-<tr class="field"><th class="field-name">status:</th><td class="field-body">the status of the connection (integer: 1 - OK, 0 - bad)</td>
-</tr>
-<tr class="field"><th class="field-name">error:</th><td class="field-body">the last warning/error message from the server (string)</td>
-</tr>
-</tbody>
-</table>
-</blockquote>
-</div>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id33" id="the-db-wrapper-class" name="the-db-wrapper-class">4 The DB wrapper class</a></h1>
-<p>The <cite>pgobject</cite> methods are wrapped in the class <cite>DB</cite>.
-The preferred way to use this module is as follows:</p>
-<pre class="literal-block">
-import pg
-
-db = pg.DB(...) # see below
-
-for r in db.query( # just for example
- """SELECT foo,bar
- FROM foo_bar_table
- WHERE foo !~ bar"""
- ).dictresult():
-
- print '%(foo)s %(bar)s' % r
-</pre>
-<p>This class can be subclassed as in this example:</p>
-<pre class="literal-block">
-import pg
-
-class DB_ride(pg.DB):
- """This class encapsulates the database functions and the specific
- methods for the ride database."""
-
- def __init__(self):
- """Opens a database connection to the rides database"""
-
- pg.DB.__init__(self, dbname = 'ride')
- self.query("""SET DATESTYLE TO 'ISO'""")
-
- [Add or override methods here]
-</pre>
-<p>The following describes the methods and variables of this class.</p>
-<div class="section">
-<h2><a class="toc-backref" href="#id34" id="initialization" name="initialization">4.1 Initialization</a></h2>
-<p>The DB class is initialized with the same arguments as the connect
-function described in section 2. It also initializes a few
-internal variables. The statement <cite>db = DB()</cite> will open the
-local database with the name of the user just like connect() does.</p>
-<p>You can also initialize the DB class with an existing <cite>_pg</cite> or <cite>pgdb</cite>
-connection. Pass this connection as a single unnamed parameter, or as a
-single parameter named <cite>db</cite>. This allows you to use all of the methods
-of the DB class with a DB-API 2 compliant connection. Note that the
-<cite>close()</cite> and <cite>reopen()</cite> methods are inoperative in this case.</p>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id35" id="pkey-return-the-primary-key-of-a-table" name="pkey-return-the-primary-key-of-a-table">4.2 pkey - return the primary key of a table</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-pkey(table)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string:</th><td class="field-body">Name of the field which is the primary key of the table</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the primary key of a table. For composite primary
-keys, the return value will be a frozenset. Note that this raises an
-exception if the table does not have a primary key.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id36" id="get-databases-get-list-of-databases-in-the-system" name="get-databases-get-list-of-databases-in-the-system">4.3 get_databases - get list of databases in the system</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_databases()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">list:</th><td class="field-body">all databases in the system</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Although you can do this with a simple select, it is added here for
-convenience.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id37" id="get-relations-get-list-of-relations-in-connected-database" name="get-relations-get-list-of-relations-in-connected-database">4.4 get_relations - get list of relations in connected database</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_relations(kinds)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">kinds:</th><td class="field-body">a string or sequence of type letters</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>The type letters are <cite>r</cite> = ordinary table, <cite>i</cite> = index, <cite>S</cite> = sequence,
-<cite>v</cite> = view, <cite>c</cite> = composite type, <cite>s</cite> = special, <cite>t</cite> = TOAST table.
-If <cite>kinds</cite> is None or an empty string, all relations are returned (this is
-also the default). Although you can do this with a simple select, it is
-added here for convenience.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id38" id="get-tables-get-list-of-tables-in-connected-database" name="get-tables-get-list-of-tables-in-connected-database">4.5 get_tables - get list of tables in connected database</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_tables()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Returns:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">list:</th><td class="field-body">all tables in connected database</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Although you can do this with a simple select, it is added here for
-convenience.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id39" id="get-attnames-get-the-attribute-names-of-a-table" name="get-attnames-get-the-attribute-names-of-a-table">4.6 get_attnames - get the attribute names of a table</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get_attnames(table)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Returns:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">dictionary:</th><td class="field-body">The keys are the attribute names,
-the values are the type names of the attributes.</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Given the name of a table, digs out the set of attribute names.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id40" id="has-table-privilege-check-whether-current-user-has-specified-table-privilege" name="has-table-privilege-check-whether-current-user-has-specified-table-privilege">4.7 has_table_privilege - check whether current user has specified table privilege</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-has_table_privilege(table, privilege)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-<tr class="field"><th class="field-name">privilege:</th><td class="field-body">privilege to be checked - default is 'select'</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Returns True if the current user has the specified privilege for the table.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id41" id="get-get-a-row-from-a-database-table-or-view" name="get-get-a-row-from-a-database-table-or-view">4.8 get - get a row from a database table or view</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-get(table, arg, [keyname])
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table or view</td>
-</tr>
-<tr class="field"><th class="field-name">arg:</th><td class="field-body">either a dictionary or the value to be looked up</td>
-</tr>
-<tr class="field"><th class="field-name">keyname:</th><td class="field-body">name of field to use as key (optional)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">dictionary:</th><td class="field-body">The keys are the attribute names,
-the values are the row values.</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method is the basic mechanism to get a single row. It assumes
-that the key specifies a unique row. If <cite>keyname</cite> is not specified
-then the primary key for the table is used. If <cite>arg</cite> is a dictionary
-then the value for the key is taken from it and it is modified to
-include the new values, replacing existing values where necessary.
-For a composite key, <cite>keyname</cite> can also be a sequence of key names.
-The OID is also put into the dictionary if the table has one, but in
-order to allow the caller to work with multiple tables, it is munged
-as <cite>oid(schema.table)</cite>.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id42" id="insert-insert-a-row-into-a-database-table" name="insert-insert-a-row-into-a-database-table">4.9 insert - insert a row into a database table</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-insert(table, [d,] [return_changes,] [key = val, ...])
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-<tr class="field"><th class="field-name">d:</th><td class="field-body">optional dictionary of values</td>
-</tr>
-<tr class="field"><th class="field-name">return_changes:</th><td class="field-body">Return values in new row - default True</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">dictionary:</th><td class="field-body">The dictionary of values inserted</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd><p class="first">This method inserts a row into a table. If the optional dictionary is
-not supplied then the required values must be included as keyword/value
-pairs. If a dictionary is supplied then any keywords provided will be
-added to or replace the entry in the dictionary.</p>
-<p>The dictionary is then, if possible, reloaded with the values actually
-inserted in order to pick up values modified by rules, triggers, etc.</p>
-<p>Due to the way that this function works in PostgreSQL versions below
-8.2, you may find inserts taking longer and longer as your table gets
-bigger. If this happens and it is a table with OID but no primary key
-you can overcome this problem by simply adding an index onto the OID of
-any table that you think may get large over time. You may also consider
-using the inserttable() method described in section 3.</p>
-<p>Note: With PostgreSQL versions before 8.2 the table being inserted to
-must have a primary key or an OID to use this method properly. If not
-then the dictionary will not be filled in as described. Also, if this
-method is called within a transaction, the transaction will abort.</p>
-<p class="last">Note: The method currently doesn't support insert into views
-although PostgreSQL does.</p>
-</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id43" id="update-update-a-row-in-a-database-table" name="update-update-a-row-in-a-database-table">4.10 update - update a row in a database table</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-update(table, [d,] [key = val, ...])
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-<tr class="field"><th class="field-name">d:</th><td class="field-body">optional dictionary of values</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">dictionary:</th><td class="field-body">the new row</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd><p class="first">Similar to insert but updates an existing row. The update is based on the
-OID value as munged by get or passed as keyword, or on the primary key of
-the table. The dictionary is modified, if possible, to reflect any changes
-caused by the update due to triggers, rules, default values, etc.</p>
-<p class="last">Like insert, the dictionary is optional and updates will be performed
-on the fields in the keywords. There must be an OID or primary key
-either in the dictionary where the OID must be munged, or in the keywords
-where it can be simply the string "oid".</p>
-</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id44" id="clear-clears-row-values-in-memory" name="clear-clears-row-values-in-memory">4.11 clear - clears row values in memory</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-clear(table, [a])
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-<tr class="field"><th class="field-name">a:</th><td class="field-body">optional dictionary of values</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">dictionary:</th><td class="field-body">an empty row</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd><p class="first">This method clears all the attributes to values determined by the types.
-Numeric types are set to 0, Booleans are set to 'f', dates are set
-to 'now()' and everything else is set to the empty string.
-If the array argument is present, it is used as the array and any entries
-matching attribute names are cleared with everything else left unchanged.</p>
-<p class="last">If the dictionary is not supplied a new one is created.</p>
-</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id45" id="delete-delete-a-row-from-a-database-table" name="delete-delete-a-row-from-a-database-table">4.12 delete - delete a row from a database table</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-delete(table, [d,] [key = val, ...])
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">table:</th><td class="field-body">name of table</td>
-</tr>
-<tr class="field"><th class="field-name">d:</th><td class="field-body">optional dictionary of values</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Returns:</dt>
-<dd>None</dd>
-<dt>Description:</dt>
-<dd>This method deletes the row from a table. It deletes based on the OID value
-as munged by get or passed as keyword, or on the primary key of the table.
-The return value is the number of deleted rows (i.e. 0 if the row did not
-exist and 1 if the row was deleted).</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id46" id="id1" name="id1">4.13 escape_string - escape a string for use within SQL</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-escape_string(string)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string:</th><td class="field-body">the string that is to be escaped</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">str:</th><td class="field-body">the escaped string</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Similar to the module function with the same name, but the
-behavior of this method is adjusted depending on the connection properties
-(such as character encoding).</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id47" id="id2" name="id2">4.14 escape_bytea - escape binary data for use within SQL as type <cite>bytea</cite></a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-escape_bytea(datastring)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">datastring:</th><td class="field-body">string containing the binary data that is to be escaped</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">str:</th><td class="field-body">the escaped string</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>Similar to the module function with the same name, but the
-behavior of this method is adjusted depending on the connection properties
-(in particular, whether standard-conforming strings are enabled).</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id48" id="id3" name="id3">4.15 unescape_bytea -- unescape <cite>bytea</cite> data that has been retrieved as text</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-unescape_bytea(string)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">datastring:</th><td class="field-body">the <cite>bytea</cite> data string that has been retrieved as text</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">str:</th><td class="field-body">string containing the binary data</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>See the module function with the same name.</dd>
-</dl>
-</div>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id49" id="pgqueryobject-methods" name="pgqueryobject-methods">5 pgqueryobject methods</a></h1>
-<div class="section">
-<h2><a class="toc-backref" href="#id50" id="getresult-get-query-values-as-list-of-tuples" name="getresult-get-query-values-as-list-of-tuples">5.1 getresult - get query values as list of tuples</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-getresult()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">list:</th><td class="field-body">result values as a list of tuples</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError:</th></tr>
-<tr><td> </td><td class="field-body">invalid previous result</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the list of the values returned by the query.
-More information about this result may be accessed using listfields(),
-fieldname() and fieldnum() methods.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id51" id="dictresult-get-query-values-as-list-of-dictionaries" name="dictresult-get-query-values-as-list-of-dictionaries">5.2 dictresult - get query values as list of dictionaries</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-dictresult()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">list:</th><td class="field-body">result values as a list of dictionaries</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError:</th></tr>
-<tr><td> </td><td class="field-body">invalid previous result</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the list of the values returned by the query
-with each tuple returned as a dictionary with the field names
-used as the dictionary index.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id52" id="listfields-lists-fields-names-of-previous-query-result" name="listfields-lists-fields-names-of-previous-query-result">5.3 listfields - lists fields names of previous query result</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-listfields()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">list:</th><td class="field-body">field names</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError:</th></tr>
-<tr><td> </td><td class="field-body">invalid previous result, or lost connection</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the list of names of the fields defined for the
-query result. The fields are in the same order as the result values.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id53" id="fieldname-fieldnum-field-name-number-conversion" name="fieldname-fieldnum-field-name-number-conversion">5.4 fieldname, fieldnum - field name/number conversion</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-fieldname(i)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">i:</th><td class="field-body">field number (integer)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">string:</th><td class="field-body">field name</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad parameter type, or too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name">ValueError:</th><td class="field-body">invalid field number</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError:</th></tr>
-<tr><td> </td><td class="field-body">invalid previous result, or lost connection</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method allows to find a field name from its rank number. It can be
-useful for displaying a result. The fields are in the same order as the
-result values.</dd>
-</dl>
-<p>Syntax:</p>
-<pre class="literal-block">
-fieldnum(name)
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">name:</th><td class="field-body">field name (string)</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">integer:</th><td class="field-body">field number</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">invalid connection, bad parameter type, or too many parameters</td>
-</tr>
-<tr class="field"><th class="field-name">ValueError:</th><td class="field-body">unknown field name</td>
-</tr>
-<tr class="field"><th class="field-name" colspan="2">pg.InternalError:</th></tr>
-<tr><td> </td><td class="field-body">invalid previous result, or lost connection</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns a field number from its name. It can be used to
-build a function that converts result list strings to their correct
-type, using a hardcoded table definition. The number returned is the
-field rank in the result values list.</dd>
-</dl>
-</div>
-<div class="section">
-<h2><a class="toc-backref" href="#id54" id="ntuples-return-number-of-tuples-in-query-object" name="ntuples-return-number-of-tuples-in-query-object">5.5 ntuples - return number of tuples in query object</a></h2>
-<p>Syntax:</p>
-<pre class="literal-block">
-ntuples()
-</pre>
-<dl class="docutils">
-<dt>Parameters:</dt>
-<dd>None</dd>
-<dt>Return type:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">integer:</th><td class="field-body">number of tuples in <cite>pgqueryobject</cite></td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Exceptions raised:</dt>
-<dd><table class="first last docutils field-list" frame="void" rules="none">
-<col class="field-name" />
-<col class="field-body" />
-<tbody valign="top">
-<tr class="field"><th class="field-name">TypeError:</th><td class="field-body">Too many arguments.</td>
-</tr>
-</tbody>
-</table>
-</dd>
-<dt>Description:</dt>
-<dd>This method returns the number of tuples found in a query.</dd>
-</dl>
-</div>
-</div>
-<div class="section">
-<h1><a class="toc-backref" href="#id5
<TRUNCATED>
[09/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/constructor.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/constructor.py b/tools/bin/ext/yaml/constructor.py
deleted file mode 100644
index e66dd2c..0000000
--- a/tools/bin/ext/yaml/constructor.py
+++ /dev/null
@@ -1,691 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['BaseConstructor', 'SafeConstructor', 'Constructor',
- 'ConstructorError']
-
-from error import *
-from nodes import *
-
-import datetime
-
-try:
- set
-except NameError:
- from sets import Set as set
-
-import binascii, re, sys, types
-
-class ConstructorError(MarkedYAMLError):
- pass
-
-class BaseConstructor(object):
-
- yaml_constructors = {}
- yaml_multi_constructors = {}
-
- def __init__(self):
- self.constructed_objects = {}
- self.recursive_objects = {}
- self.state_generators = []
- self.deep_construct = False
-
- def check_data(self):
- # If there are more documents available?
- return self.check_node()
-
- def get_data(self):
- # Construct and return the next document.
- if self.check_node():
- return self.construct_document(self.get_node())
-
- def construct_document(self, node):
- data = self.construct_object(node)
- while self.state_generators:
- state_generators = self.state_generators
- self.state_generators = []
- for generator in state_generators:
- for dummy in generator:
- pass
- self.constructed_objects = {}
- self.recursive_objects = {}
- self.deep_construct = False
- return data
-
- def construct_object(self, node, deep=False):
- if deep:
- old_deep = self.deep_construct
- self.deep_construct = True
- if node in self.constructed_objects:
- return self.constructed_objects[node]
- if node in self.recursive_objects:
- raise ConstructorError(None, None,
- "found unconstructable recursive node", node.start_mark)
- self.recursive_objects[node] = None
- constructor = None
- state_constructor = None
- tag_suffix = None
- if node.tag in self.yaml_constructors:
- constructor = self.yaml_constructors[node.tag]
- else:
- for tag_prefix in self.yaml_multi_constructors:
- if node.tag.startswith(tag_prefix):
- tag_suffix = node.tag[len(tag_prefix):]
- constructor = self.yaml_multi_constructors[tag_prefix]
- break
- else:
- if None in self.yaml_multi_constructors:
- tag_suffix = node.tag
- constructor = self.yaml_multi_constructors[None]
- elif None in self.yaml_constructors:
- constructor = self.yaml_constructors[None]
- elif isinstance(node, ScalarNode):
- constructor = self.__class__.construct_scalar
- elif isinstance(node, SequenceNode):
- constructor = self.__class__.construct_sequence
- elif isinstance(node, MappingNode):
- constructor = self.__class__.construct_mapping
- if tag_suffix is None:
- data = constructor(self, node)
- else:
- data = constructor(self, tag_suffix, node)
- if isinstance(data, types.GeneratorType):
- generator = data
- data = generator.next()
- if self.deep_construct:
- for dummy in generator:
- pass
- else:
- self.state_generators.append(generator)
- self.constructed_objects[node] = data
- del self.recursive_objects[node]
- if deep:
- self.deep_construct = old_deep
- return data
-
- def construct_scalar(self, node):
- if not isinstance(node, ScalarNode):
- raise ConstructorError(None, None,
- "expected a scalar node, but found %s" % node.id,
- node.start_mark)
- return node.value
-
- def construct_sequence(self, node, deep=False):
- if not isinstance(node, SequenceNode):
- raise ConstructorError(None, None,
- "expected a sequence node, but found %s" % node.id,
- node.start_mark)
- return [self.construct_object(child, deep=deep)
- for child in node.value]
-
- def construct_mapping(self, node, deep=False):
- if not isinstance(node, MappingNode):
- raise ConstructorError(None, None,
- "expected a mapping node, but found %s" % node.id,
- node.start_mark)
- mapping = {}
- for key_node, value_node in node.value:
- key = self.construct_object(key_node, deep=deep)
- try:
- hash(key)
- except TypeError, exc:
- raise ConstructorError("while constructing a mapping", node.start_mark,
- "found unacceptable key (%s)" % exc, key_node.start_mark)
- value = self.construct_object(value_node, deep=deep)
- mapping[key] = value
- return mapping
-
- def construct_pairs(self, node, deep=False):
- if not isinstance(node, MappingNode):
- raise ConstructorError(None, None,
- "expected a mapping node, but found %s" % node.id,
- node.start_mark)
- pairs = []
- for key_node, value_node in node.value:
- key = self.construct_object(key_node, deep=deep)
- value = self.construct_object(value_node, deep=deep)
- pairs.append((key, value))
- return pairs
-
- def add_constructor(cls, tag, constructor):
- if not 'yaml_constructors' in cls.__dict__:
- cls.yaml_constructors = cls.yaml_constructors.copy()
- cls.yaml_constructors[tag] = constructor
- add_constructor = classmethod(add_constructor)
-
- def add_multi_constructor(cls, tag_prefix, multi_constructor):
- if not 'yaml_multi_constructors' in cls.__dict__:
- cls.yaml_multi_constructors = cls.yaml_multi_constructors.copy()
- cls.yaml_multi_constructors[tag_prefix] = multi_constructor
- add_multi_constructor = classmethod(add_multi_constructor)
-
-class SafeConstructor(BaseConstructor):
-
- def construct_scalar(self, node):
- if isinstance(node, MappingNode):
- for key_node, value_node in node.value:
- if key_node.tag == u'tag:yaml.org,2002:value':
- return self.construct_scalar(value_node)
- return BaseConstructor.construct_scalar(self, node)
-
- def flatten_mapping(self, node):
- merge = []
- index = 0
- while index < len(node.value):
- key_node, value_node = node.value[index]
- if key_node.tag == u'tag:yaml.org,2002:merge':
- del node.value[index]
- if isinstance(value_node, MappingNode):
- self.flatten_mapping(value_node)
- merge.extend(value_node.value)
- elif isinstance(value_node, SequenceNode):
- submerge = []
- for subnode in value_node.value:
- if not isinstance(subnode, MappingNode):
- raise ConstructorError("while constructing a mapping",
- node.start_mark,
- "expected a mapping for merging, but found %s"
- % subnode.id, subnode.start_mark)
- self.flatten_mapping(subnode)
- submerge.append(subnode.value)
- submerge.reverse()
- for value in submerge:
- merge.extend(value)
- else:
- raise ConstructorError("while constructing a mapping", node.start_mark,
- "expected a mapping or list of mappings for merging, but found %s"
- % value_node.id, value_node.start_mark)
- elif key_node.tag == u'tag:yaml.org,2002:value':
- key_node.tag = u'tag:yaml.org,2002:str'
- index += 1
- else:
- index += 1
- if merge:
- node.value = merge + node.value
-
- def construct_mapping(self, node, deep=False):
- if isinstance(node, MappingNode):
- self.flatten_mapping(node)
- return BaseConstructor.construct_mapping(self, node, deep=deep)
-
- def construct_yaml_null(self, node):
- self.construct_scalar(node)
- return None
-
- bool_values = {
- u'yes': True,
- u'no': False,
- u'true': True,
- u'false': False,
- u'on': True,
- u'off': False,
- }
-
- def construct_yaml_bool(self, node):
- value = self.construct_scalar(node)
- return self.bool_values[value.lower()]
-
- def construct_yaml_int(self, node):
- value = str(self.construct_scalar(node))
- value = value.replace('_', '')
- sign = +1
- if value[0] == '-':
- sign = -1
- if value[0] in '+-':
- value = value[1:]
- if value == '0':
- return 0
- elif value.startswith('0b'):
- return sign*int(value[2:], 2)
- elif value.startswith('0x'):
- return sign*int(value[2:], 16)
- elif value[0] == '0':
- return sign*int(value, 8)
- elif ':' in value:
- digits = [int(part) for part in value.split(':')]
- digits.reverse()
- base = 1
- value = 0
- for digit in digits:
- value += digit*base
- base *= 60
- return sign*value
- else:
- return sign*int(value)
-
- inf_value = 1e300
- while inf_value != inf_value*inf_value:
- inf_value *= inf_value
- nan_value = -inf_value/inf_value # Trying to make a quiet NaN (like C99).
-
- def construct_yaml_float(self, node):
- value = str(self.construct_scalar(node))
- value = value.replace('_', '').lower()
- sign = +1
- if value[0] == '-':
- sign = -1
- if value[0] in '+-':
- value = value[1:]
- if value == '.inf':
- return sign*self.inf_value
- elif value == '.nan':
- return self.nan_value
- elif ':' in value:
- digits = [float(part) for part in value.split(':')]
- digits.reverse()
- base = 1
- value = 0.0
- for digit in digits:
- value += digit*base
- base *= 60
- return sign*value
- else:
- return sign*float(value)
-
- def construct_yaml_binary(self, node):
- value = self.construct_scalar(node)
- try:
- return str(value).decode('base64')
- except (binascii.Error, UnicodeEncodeError), exc:
- raise ConstructorError(None, None,
- "failed to decode base64 data: %s" % exc, node.start_mark)
-
- timestamp_regexp = re.compile(
- ur'''^(?P<year>[0-9][0-9][0-9][0-9])
- -(?P<month>[0-9][0-9]?)
- -(?P<day>[0-9][0-9]?)
- (?:(?:[Tt]|[ \t]+)
- (?P<hour>[0-9][0-9]?)
- :(?P<minute>[0-9][0-9])
- :(?P<second>[0-9][0-9])
- (?:\.(?P<fraction>[0-9]*))?
- (?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
- (?::(?P<tz_minute>[0-9][0-9]))?))?)?$''', re.X)
-
- def construct_yaml_timestamp(self, node):
- value = self.construct_scalar(node)
- match = self.timestamp_regexp.match(node.value)
- values = match.groupdict()
- year = int(values['year'])
- month = int(values['month'])
- day = int(values['day'])
- if not values['hour']:
- return datetime.date(year, month, day)
- hour = int(values['hour'])
- minute = int(values['minute'])
- second = int(values['second'])
- fraction = 0
- if values['fraction']:
- fraction = int(values['fraction'][:6].ljust(6, '0'))
- delta = None
- if values['tz_sign']:
- tz_hour = int(values['tz_hour'])
- tz_minute = int(values['tz_minute'] or 0)
- delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute)
- if values['tz_sign'] == '-':
- delta = -delta
- data = datetime.datetime(year, month, day, hour, minute, second, fraction)
- if delta:
- data -= delta
- return data
-
- def construct_yaml_omap(self, node):
- # Note: we do not check for duplicate keys, because it's too
- # CPU-expensive.
- omap = []
- yield omap
- if not isinstance(node, SequenceNode):
- raise ConstructorError("while constructing an ordered map", node.start_mark,
- "expected a sequence, but found %s" % node.id, node.start_mark)
- for subnode in node.value:
- if not isinstance(subnode, MappingNode):
- raise ConstructorError("while constructing an ordered map", node.start_mark,
- "expected a mapping of length 1, but found %s" % subnode.id,
- subnode.start_mark)
- if len(subnode.value) != 1:
- raise ConstructorError("while constructing an ordered map", node.start_mark,
- "expected a single mapping item, but found %d items" % len(subnode.value),
- subnode.start_mark)
- key_node, value_node = subnode.value[0]
- key = self.construct_object(key_node)
- value = self.construct_object(value_node)
- omap.append((key, value))
-
- def construct_yaml_pairs(self, node):
- # Note: the same code as `construct_yaml_omap`.
- pairs = []
- yield pairs
- if not isinstance(node, SequenceNode):
- raise ConstructorError("while constructing pairs", node.start_mark,
- "expected a sequence, but found %s" % node.id, node.start_mark)
- for subnode in node.value:
- if not isinstance(subnode, MappingNode):
- raise ConstructorError("while constructing pairs", node.start_mark,
- "expected a mapping of length 1, but found %s" % subnode.id,
- subnode.start_mark)
- if len(subnode.value) != 1:
- raise ConstructorError("while constructing pairs", node.start_mark,
- "expected a single mapping item, but found %d items" % len(subnode.value),
- subnode.start_mark)
- key_node, value_node = subnode.value[0]
- key = self.construct_object(key_node)
- value = self.construct_object(value_node)
- pairs.append((key, value))
-
- def construct_yaml_set(self, node):
- data = set()
- yield data
- value = self.construct_mapping(node)
- data.update(value)
-
- def construct_yaml_str(self, node):
- value = self.construct_scalar(node)
- try:
- return value.encode('ascii')
- except UnicodeEncodeError:
- return value
-
- def construct_yaml_seq(self, node):
- data = []
- yield data
- data.extend(self.construct_sequence(node))
-
- def construct_yaml_map(self, node):
- data = {}
- yield data
- value = self.construct_mapping(node)
- data.update(value)
-
- def construct_yaml_object(self, node, cls):
- data = cls.__new__(cls)
- yield data
- if hasattr(data, '__setstate__'):
- state = self.construct_mapping(node, deep=True)
- data.__setstate__(state)
- else:
- state = self.construct_mapping(node)
- data.__dict__.update(state)
-
- def construct_undefined(self, node):
- raise ConstructorError(None, None,
- "could not determine a constructor for the tag %r" % node.tag.encode('utf-8'),
- node.start_mark)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:null',
- SafeConstructor.construct_yaml_null)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:bool',
- SafeConstructor.construct_yaml_bool)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:int',
- SafeConstructor.construct_yaml_int)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:float',
- SafeConstructor.construct_yaml_float)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:binary',
- SafeConstructor.construct_yaml_binary)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:timestamp',
- SafeConstructor.construct_yaml_timestamp)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:omap',
- SafeConstructor.construct_yaml_omap)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:pairs',
- SafeConstructor.construct_yaml_pairs)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:set',
- SafeConstructor.construct_yaml_set)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:str',
- SafeConstructor.construct_yaml_str)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:seq',
- SafeConstructor.construct_yaml_seq)
-
-SafeConstructor.add_constructor(
- u'tag:yaml.org,2002:map',
- SafeConstructor.construct_yaml_map)
-
-SafeConstructor.add_constructor(None,
- SafeConstructor.construct_undefined)
-
-class Constructor(SafeConstructor):
-
- def construct_python_str(self, node):
- return self.construct_scalar(node).encode('utf-8')
-
- def construct_python_unicode(self, node):
- return self.construct_scalar(node)
-
- def construct_python_long(self, node):
- return long(self.construct_yaml_int(node))
-
- def construct_python_complex(self, node):
- return complex(self.construct_scalar(node))
-
- def construct_python_tuple(self, node):
- return tuple(self.construct_sequence(node))
-
- def find_python_module(self, name, mark):
- if not name:
- raise ConstructorError("while constructing a Python module", mark,
- "expected non-empty name appended to the tag", mark)
- try:
- __import__(name)
- except ImportError, exc:
- raise ConstructorError("while constructing a Python module", mark,
- "cannot find module %r (%s)" % (name.encode('utf-8'), exc), mark)
- return sys.modules[name]
-
- def find_python_name(self, name, mark):
- if not name:
- raise ConstructorError("while constructing a Python object", mark,
- "expected non-empty name appended to the tag", mark)
- if u'.' in name:
- # Python 2.4 only
- #module_name, object_name = name.rsplit('.', 1)
- items = name.split('.')
- object_name = items.pop()
- module_name = '.'.join(items)
- else:
- module_name = '__builtin__'
- object_name = name
- try:
- __import__(module_name)
- except ImportError, exc:
- raise ConstructorError("while constructing a Python object", mark,
- "cannot find module %r (%s)" % (module_name.encode('utf-8'), exc), mark)
- module = sys.modules[module_name]
- if not hasattr(module, object_name):
- raise ConstructorError("while constructing a Python object", mark,
- "cannot find %r in the module %r" % (object_name.encode('utf-8'),
- module.__name__), mark)
- return getattr(module, object_name)
-
- def construct_python_name(self, suffix, node):
- value = self.construct_scalar(node)
- if value:
- raise ConstructorError("while constructing a Python name", node.start_mark,
- "expected the empty value, but found %r" % value.encode('utf-8'),
- node.start_mark)
- return self.find_python_name(suffix, node.start_mark)
-
- def construct_python_module(self, suffix, node):
- value = self.construct_scalar(node)
- if value:
- raise ConstructorError("while constructing a Python module", node.start_mark,
- "expected the empty value, but found %r" % value.encode('utf-8'),
- node.start_mark)
- return self.find_python_module(suffix, node.start_mark)
-
- class classobj: pass
-
- def make_python_instance(self, suffix, node,
- args=None, kwds=None, newobj=False):
- if not args:
- args = []
- if not kwds:
- kwds = {}
- cls = self.find_python_name(suffix, node.start_mark)
- if newobj and isinstance(cls, type(self.classobj)) \
- and not args and not kwds:
- instance = self.classobj()
- instance.__class__ = cls
- return instance
- elif newobj and isinstance(cls, type):
- return cls.__new__(cls, *args, **kwds)
- else:
- return cls(*args, **kwds)
-
- def set_python_instance_state(self, instance, state):
- if hasattr(instance, '__setstate__'):
- instance.__setstate__(state)
- else:
- slotstate = {}
- if isinstance(state, tuple) and len(state) == 2:
- state, slotstate = state
- if hasattr(instance, '__dict__'):
- instance.__dict__.update(state)
- elif state:
- slotstate.update(state)
- for key, value in slotstate.items():
- setattr(object, key, value)
-
- def construct_python_object(self, suffix, node):
- # Format:
- # !!python/object:module.name { ... state ... }
- instance = self.make_python_instance(suffix, node, newobj=True)
- yield instance
- deep = hasattr(instance, '__setstate__')
- state = self.construct_mapping(node, deep=deep)
- self.set_python_instance_state(instance, state)
-
- def construct_python_object_apply(self, suffix, node, newobj=False):
- # Format:
- # !!python/object/apply # (or !!python/object/new)
- # args: [ ... arguments ... ]
- # kwds: { ... keywords ... }
- # state: ... state ...
- # listitems: [ ... listitems ... ]
- # dictitems: { ... dictitems ... }
- # or short format:
- # !!python/object/apply [ ... arguments ... ]
- # The difference between !!python/object/apply and !!python/object/new
- # is how an object is created, check make_python_instance for details.
- if isinstance(node, SequenceNode):
- args = self.construct_sequence(node, deep=True)
- kwds = {}
- state = {}
- listitems = []
- dictitems = {}
- else:
- value = self.construct_mapping(node, deep=True)
- args = value.get('args', [])
- kwds = value.get('kwds', {})
- state = value.get('state', {})
- listitems = value.get('listitems', [])
- dictitems = value.get('dictitems', {})
- instance = self.make_python_instance(suffix, node, args, kwds, newobj)
- if state:
- self.set_python_instance_state(instance, state)
- if listitems:
- instance.extend(listitems)
- if dictitems:
- for key in dictitems:
- instance[key] = dictitems[key]
- return instance
-
- def construct_python_object_new(self, suffix, node):
- return self.construct_python_object_apply(suffix, node, newobj=True)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/none',
- Constructor.construct_yaml_null)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/bool',
- Constructor.construct_yaml_bool)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/str',
- Constructor.construct_python_str)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/unicode',
- Constructor.construct_python_unicode)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/int',
- Constructor.construct_yaml_int)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/long',
- Constructor.construct_python_long)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/float',
- Constructor.construct_yaml_float)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/complex',
- Constructor.construct_python_complex)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/list',
- Constructor.construct_yaml_seq)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/tuple',
- Constructor.construct_python_tuple)
-
-Constructor.add_constructor(
- u'tag:yaml.org,2002:python/dict',
- Constructor.construct_yaml_map)
-
-Constructor.add_multi_constructor(
- u'tag:yaml.org,2002:python/name:',
- Constructor.construct_python_name)
-
-Constructor.add_multi_constructor(
- u'tag:yaml.org,2002:python/module:',
- Constructor.construct_python_module)
-
-Constructor.add_multi_constructor(
- u'tag:yaml.org,2002:python/object:',
- Constructor.construct_python_object)
-
-Constructor.add_multi_constructor(
- u'tag:yaml.org,2002:python/object/apply:',
- Constructor.construct_python_object_apply)
-
-Constructor.add_multi_constructor(
- u'tag:yaml.org,2002:python/object/new:',
- Constructor.construct_python_object_new)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/cyaml.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/cyaml.py b/tools/bin/ext/yaml/cyaml.py
deleted file mode 100644
index c3eaf77..0000000
--- a/tools/bin/ext/yaml/cyaml.py
+++ /dev/null
@@ -1,101 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['CBaseLoader', 'CSafeLoader', 'CLoader',
- 'CBaseDumper', 'CSafeDumper', 'CDumper']
-
-from _yaml import CParser, CEmitter
-
-from constructor import *
-
-from serializer import *
-from representer import *
-
-from resolver import *
-
-class CBaseLoader(CParser, BaseConstructor, BaseResolver):
-
- def __init__(self, stream):
- CParser.__init__(self, stream)
- BaseConstructor.__init__(self)
- BaseResolver.__init__(self)
-
-class CSafeLoader(CParser, SafeConstructor, Resolver):
-
- def __init__(self, stream):
- CParser.__init__(self, stream)
- SafeConstructor.__init__(self)
- Resolver.__init__(self)
-
-class CLoader(CParser, Constructor, Resolver):
-
- def __init__(self, stream):
- CParser.__init__(self, stream)
- Constructor.__init__(self)
- Resolver.__init__(self)
-
-class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver):
-
- def __init__(self, stream,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding=None, explicit_start=None, explicit_end=None,
- version=None, tags=None):
- CEmitter.__init__(self, stream, canonical=canonical,
- indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- explicit_start=explicit_start, explicit_end=explicit_end,
- version=version, tags=tags)
- Representer.__init__(self, default_style=default_style,
- default_flow_style=default_flow_style)
- Resolver.__init__(self)
-
-class CSafeDumper(CEmitter, SafeRepresenter, Resolver):
-
- def __init__(self, stream,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding=None, explicit_start=None, explicit_end=None,
- version=None, tags=None):
- CEmitter.__init__(self, stream, canonical=canonical,
- indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- explicit_start=explicit_start, explicit_end=explicit_end,
- version=version, tags=tags)
- SafeRepresenter.__init__(self, default_style=default_style,
- default_flow_style=default_flow_style)
- Resolver.__init__(self)
-
-class CDumper(CEmitter, Serializer, Representer, Resolver):
-
- def __init__(self, stream,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding=None, explicit_start=None, explicit_end=None,
- version=None, tags=None):
- CEmitter.__init__(self, stream, canonical=canonical,
- indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break,
- explicit_start=explicit_start, explicit_end=explicit_end,
- version=version, tags=tags)
- Representer.__init__(self, default_style=default_style,
- default_flow_style=default_flow_style)
- Resolver.__init__(self)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/dumper.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/dumper.py b/tools/bin/ext/yaml/dumper.py
deleted file mode 100644
index a955200..0000000
--- a/tools/bin/ext/yaml/dumper.py
+++ /dev/null
@@ -1,78 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['BaseDumper', 'SafeDumper', 'Dumper']
-
-from emitter import *
-from serializer import *
-from representer import *
-from resolver import *
-
-class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
-
- def __init__(self, stream,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding=None, explicit_start=None, explicit_end=None,
- version=None, tags=None):
- Emitter.__init__(self, stream, canonical=canonical,
- indent=indent, width=width,
- allow_uncode=allow_unicode, line_break=line_break)
- Serializer.__init__(self, encoding=encoding,
- explicit_start=explicit_start, explicit_end=explicit_end,
- version=version, tags=tags)
- Representer.__init__(self, default_style=default_style,
- default_flow_style=default_flow_style)
- Resolver.__init__(self)
-
-class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver):
-
- def __init__(self, stream,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding=None, explicit_start=None, explicit_end=None,
- version=None, tags=None):
- Emitter.__init__(self, stream, canonical=canonical,
- indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break)
- Serializer.__init__(self, encoding=encoding,
- explicit_start=explicit_start, explicit_end=explicit_end,
- version=version, tags=tags)
- SafeRepresenter.__init__(self, default_style=default_style,
- default_flow_style=default_flow_style)
- Resolver.__init__(self)
-
-class Dumper(Emitter, Serializer, Representer, Resolver):
-
- def __init__(self, stream,
- default_style=None, default_flow_style=None,
- canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None,
- encoding=None, explicit_start=None, explicit_end=None,
- version=None, tags=None):
- Emitter.__init__(self, stream, canonical=canonical,
- indent=indent, width=width,
- allow_unicode=allow_unicode, line_break=line_break)
- Serializer.__init__(self, encoding=encoding,
- explicit_start=explicit_start, explicit_end=explicit_end,
- version=version, tags=tags)
- Representer.__init__(self, default_style=default_style,
- default_flow_style=default_flow_style)
- Resolver.__init__(self)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/emitter.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/emitter.py b/tools/bin/ext/yaml/emitter.py
deleted file mode 100644
index 23730d8..0000000
--- a/tools/bin/ext/yaml/emitter.py
+++ /dev/null
@@ -1,1179 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Emitter expects events obeying the following grammar:
-# stream ::= STREAM-START document* STREAM-END
-# document ::= DOCUMENT-START node DOCUMENT-END
-# node ::= SCALAR | sequence | mapping
-# sequence ::= SEQUENCE-START node* SEQUENCE-END
-# mapping ::= MAPPING-START (node node)* MAPPING-END
-
-__all__ = ['Emitter', 'EmitterError']
-
-from error import YAMLError
-from events import *
-
-import re
-
-class EmitterError(YAMLError):
- pass
-
-class ScalarAnalysis(object):
- def __init__(self, scalar, empty, multiline,
- allow_flow_plain, allow_block_plain,
- allow_single_quoted, allow_double_quoted,
- allow_block):
- self.scalar = scalar
- self.empty = empty
- self.multiline = multiline
- self.allow_flow_plain = allow_flow_plain
- self.allow_block_plain = allow_block_plain
- self.allow_single_quoted = allow_single_quoted
- self.allow_double_quoted = allow_double_quoted
- self.allow_block = allow_block
-
-class Emitter(object):
-
- DEFAULT_TAG_PREFIXES = {
- u'!' : u'!',
- u'tag:yaml.org,2002:' : u'!!',
- }
-
- def __init__(self, stream, canonical=None, indent=None, width=None,
- allow_unicode=None, line_break=None):
-
- # The stream should have the methods `write` and possibly `flush`.
- self.stream = stream
-
- # Encoding can be overriden by STREAM-START.
- self.encoding = None
-
- # Emitter is a state machine with a stack of states to handle nested
- # structures.
- self.states = []
- self.state = self.expect_stream_start
-
- # Current event and the event queue.
- self.events = []
- self.event = None
-
- # The current indentation level and the stack of previous indents.
- self.indents = []
- self.indent = None
-
- # Flow level.
- self.flow_level = 0
-
- # Contexts.
- self.root_context = False
- self.sequence_context = False
- self.mapping_context = False
- self.simple_key_context = False
-
- # Characteristics of the last emitted character:
- # - current position.
- # - is it a whitespace?
- # - is it an indention character
- # (indentation space, '-', '?', or ':')?
- self.line = 0
- self.column = 0
- self.whitespace = True
- self.indention = True
-
- # Formatting details.
- self.canonical = canonical
- self.allow_unicode = allow_unicode
- self.best_indent = 2
- if indent and 1 < indent < 10:
- self.best_indent = indent
- self.best_width = 80
- if width and width > self.best_indent*2:
- self.best_width = width
- self.best_line_break = u'\n'
- if line_break in [u'\r', u'\n', u'\r\n']:
- self.best_line_break = line_break
-
- # Tag prefixes.
- self.tag_prefixes = None
-
- # Prepared anchor and tag.
- self.prepared_anchor = None
- self.prepared_tag = None
-
- # Scalar analysis and style.
- self.analysis = None
- self.style = None
-
- def emit(self, event):
- self.events.append(event)
- while not self.need_more_events():
- self.event = self.events.pop(0)
- self.state()
- self.event = None
-
- # In some cases, we wait for a few next events before emitting.
-
- def need_more_events(self):
- if not self.events:
- return True
- event = self.events[0]
- if isinstance(event, DocumentStartEvent):
- return self.need_events(1)
- elif isinstance(event, SequenceStartEvent):
- return self.need_events(2)
- elif isinstance(event, MappingStartEvent):
- return self.need_events(3)
- else:
- return False
-
- def need_events(self, count):
- level = 0
- for event in self.events[1:]:
- if isinstance(event, (DocumentStartEvent, CollectionStartEvent)):
- level += 1
- elif isinstance(event, (DocumentEndEvent, CollectionEndEvent)):
- level -= 1
- elif isinstance(event, StreamEndEvent):
- level = -1
- if level < 0:
- return False
- return (len(self.events) < count+1)
-
- def increase_indent(self, flow=False, indentless=False):
- self.indents.append(self.indent)
- if self.indent is None:
- if flow:
- self.indent = self.best_indent
- else:
- self.indent = 0
- elif not indentless:
- self.indent += self.best_indent
-
- # States.
-
- # Stream handlers.
-
- def expect_stream_start(self):
- if isinstance(self.event, StreamStartEvent):
- if self.event.encoding:
- self.encoding = self.event.encoding
- self.write_stream_start()
- self.state = self.expect_first_document_start
- else:
- raise EmitterError("expected StreamStartEvent, but got %s"
- % self.event)
-
- def expect_nothing(self):
- raise EmitterError("expected nothing, but got %s" % self.event)
-
- # Document handlers.
-
- def expect_first_document_start(self):
- return self.expect_document_start(first=True)
-
- def expect_document_start(self, first=False):
- if isinstance(self.event, DocumentStartEvent):
- if self.event.version:
- version_text = self.prepare_version(self.event.version)
- self.write_version_directive(version_text)
- self.tag_prefixes = self.DEFAULT_TAG_PREFIXES.copy()
- if self.event.tags:
- handles = self.event.tags.keys()
- handles.sort()
- for handle in handles:
- prefix = self.event.tags[handle]
- self.tag_prefixes[prefix] = handle
- handle_text = self.prepare_tag_handle(handle)
- prefix_text = self.prepare_tag_prefix(prefix)
- self.write_tag_directive(handle_text, prefix_text)
- implicit = (first and not self.event.explicit and not self.canonical
- and not self.event.version and not self.event.tags
- and not self.check_empty_document())
- if not implicit:
- self.write_indent()
- self.write_indicator(u'---', True)
- if self.canonical:
- self.write_indent()
- self.state = self.expect_document_root
- elif isinstance(self.event, StreamEndEvent):
- self.write_stream_end()
- self.state = self.expect_nothing
- else:
- raise EmitterError("expected DocumentStartEvent, but got %s"
- % self.event)
-
- def expect_document_end(self):
- if isinstance(self.event, DocumentEndEvent):
- self.write_indent()
- if self.event.explicit:
- self.write_indicator(u'...', True)
- self.write_indent()
- self.flush_stream()
- self.state = self.expect_document_start
- else:
- raise EmitterError("expected DocumentEndEvent, but got %s"
- % self.event)
-
- def expect_document_root(self):
- self.states.append(self.expect_document_end)
- self.expect_node(root=True)
-
- # Node handlers.
-
- def expect_node(self, root=False, sequence=False, mapping=False,
- simple_key=False):
- self.root_context = root
- self.sequence_context = sequence
- self.mapping_context = mapping
- self.simple_key_context = simple_key
- if isinstance(self.event, AliasEvent):
- self.expect_alias()
- elif isinstance(self.event, (ScalarEvent, CollectionStartEvent)):
- self.process_anchor(u'&')
- self.process_tag()
- if isinstance(self.event, ScalarEvent):
- self.expect_scalar()
- elif isinstance(self.event, SequenceStartEvent):
- if self.flow_level or self.canonical or self.event.flow_style \
- or self.check_empty_sequence():
- self.expect_flow_sequence()
- else:
- self.expect_block_sequence()
- elif isinstance(self.event, MappingStartEvent):
- if self.flow_level or self.canonical or self.event.flow_style \
- or self.check_empty_mapping():
- self.expect_flow_mapping()
- else:
- self.expect_block_mapping()
- else:
- raise EmitterError("expected NodeEvent, but got %s" % self.event)
-
- def expect_alias(self):
- if self.event.anchor is None:
- raise EmitterError("anchor is not specified for alias")
- self.process_anchor(u'*')
- self.state = self.states.pop()
-
- def expect_scalar(self):
- self.increase_indent(flow=True)
- self.process_scalar()
- self.indent = self.indents.pop()
- self.state = self.states.pop()
-
- # Flow sequence handlers.
-
- def expect_flow_sequence(self):
- self.write_indicator(u'[', True, whitespace=True)
- self.flow_level += 1
- self.increase_indent(flow=True)
- self.state = self.expect_first_flow_sequence_item
-
- def expect_first_flow_sequence_item(self):
- if isinstance(self.event, SequenceEndEvent):
- self.indent = self.indents.pop()
- self.flow_level -= 1
- self.write_indicator(u']', False)
- self.state = self.states.pop()
- else:
- if self.canonical or self.column > self.best_width:
- self.write_indent()
- self.states.append(self.expect_flow_sequence_item)
- self.expect_node(sequence=True)
-
- def expect_flow_sequence_item(self):
- if isinstance(self.event, SequenceEndEvent):
- self.indent = self.indents.pop()
- self.flow_level -= 1
- if self.canonical:
- self.write_indicator(u',', False)
- self.write_indent()
- self.write_indicator(u']', False)
- self.state = self.states.pop()
- else:
- self.write_indicator(u',', False)
- if self.canonical or self.column > self.best_width:
- self.write_indent()
- self.states.append(self.expect_flow_sequence_item)
- self.expect_node(sequence=True)
-
- # Flow mapping handlers.
-
- def expect_flow_mapping(self):
- self.write_indicator(u'{', True, whitespace=True)
- self.flow_level += 1
- self.increase_indent(flow=True)
- self.state = self.expect_first_flow_mapping_key
-
- def expect_first_flow_mapping_key(self):
- if isinstance(self.event, MappingEndEvent):
- self.indent = self.indents.pop()
- self.flow_level -= 1
- self.write_indicator(u'}', False)
- self.state = self.states.pop()
- else:
- if self.canonical or self.column > self.best_width:
- self.write_indent()
- if not self.canonical and self.check_simple_key():
- self.states.append(self.expect_flow_mapping_simple_value)
- self.expect_node(mapping=True, simple_key=True)
- else:
- self.write_indicator(u'?', True)
- self.states.append(self.expect_flow_mapping_value)
- self.expect_node(mapping=True)
-
- def expect_flow_mapping_key(self):
- if isinstance(self.event, MappingEndEvent):
- self.indent = self.indents.pop()
- self.flow_level -= 1
- if self.canonical:
- self.write_indicator(u',', False)
- self.write_indent()
- self.write_indicator(u'}', False)
- self.state = self.states.pop()
- else:
- self.write_indicator(u',', False)
- if self.canonical or self.column > self.best_width:
- self.write_indent()
- if not self.canonical and self.check_simple_key():
- self.states.append(self.expect_flow_mapping_simple_value)
- self.expect_node(mapping=True, simple_key=True)
- else:
- self.write_indicator(u'?', True)
- self.states.append(self.expect_flow_mapping_value)
- self.expect_node(mapping=True)
-
- def expect_flow_mapping_simple_value(self):
- self.write_indicator(u':', False)
- self.states.append(self.expect_flow_mapping_key)
- self.expect_node(mapping=True)
-
- def expect_flow_mapping_value(self):
- if self.canonical or self.column > self.best_width:
- self.write_indent()
- self.write_indicator(u':', True)
- self.states.append(self.expect_flow_mapping_key)
- self.expect_node(mapping=True)
-
- # Block sequence handlers.
-
- def expect_block_sequence(self):
- indentless = (self.mapping_context and not self.indention)
- self.increase_indent(flow=False, indentless=indentless)
- self.state = self.expect_first_block_sequence_item
-
- def expect_first_block_sequence_item(self):
- return self.expect_block_sequence_item(first=True)
-
- def expect_block_sequence_item(self, first=False):
- if not first and isinstance(self.event, SequenceEndEvent):
- self.indent = self.indents.pop()
- self.state = self.states.pop()
- else:
- self.write_indent()
- self.write_indicator(u'-', True, indention=True)
- self.states.append(self.expect_block_sequence_item)
- self.expect_node(sequence=True)
-
- # Block mapping handlers.
-
- def expect_block_mapping(self):
- self.increase_indent(flow=False)
- self.state = self.expect_first_block_mapping_key
-
- def expect_first_block_mapping_key(self):
- return self.expect_block_mapping_key(first=True)
-
- def expect_block_mapping_key(self, first=False):
- if not first and isinstance(self.event, MappingEndEvent):
- self.indent = self.indents.pop()
- self.state = self.states.pop()
- else:
- self.write_indent()
- if self.check_simple_key():
- self.states.append(self.expect_block_mapping_simple_value)
- self.expect_node(mapping=True, simple_key=True)
- else:
- self.write_indicator(u'?', True, indention=True)
- self.states.append(self.expect_block_mapping_value)
- self.expect_node(mapping=True)
-
- def expect_block_mapping_simple_value(self):
- self.write_indicator(u':', False)
- self.states.append(self.expect_block_mapping_key)
- self.expect_node(mapping=True)
-
- def expect_block_mapping_value(self):
- self.write_indent()
- self.write_indicator(u':', True, indention=True)
- self.states.append(self.expect_block_mapping_key)
- self.expect_node(mapping=True)
-
- # Checkers.
-
- def check_empty_sequence(self):
- return (isinstance(self.event, SequenceStartEvent) and self.events
- and isinstance(self.events[0], SequenceEndEvent))
-
- def check_empty_mapping(self):
- return (isinstance(self.event, MappingStartEvent) and self.events
- and isinstance(self.events[0], MappingEndEvent))
-
- def check_empty_document(self):
- if not isinstance(self.event, DocumentStartEvent) or not self.events:
- return False
- event = self.events[0]
- return (isinstance(event, ScalarEvent) and event.anchor is None
- and event.tag is None and event.implicit and event.value == u'')
-
- def check_simple_key(self):
- length = 0
- if isinstance(self.event, NodeEvent) and self.event.anchor is not None:
- if self.prepared_anchor is None:
- self.prepared_anchor = self.prepare_anchor(self.event.anchor)
- length += len(self.prepared_anchor)
- if isinstance(self.event, (ScalarEvent, CollectionStartEvent)) \
- and self.event.tag is not None:
- if self.prepared_tag is None:
- self.prepared_tag = self.prepare_tag(self.event.tag)
- length += len(self.prepared_tag)
- if isinstance(self.event, ScalarEvent):
- if self.analysis is None:
- self.analysis = self.analyze_scalar(self.event.value)
- length += len(self.analysis.scalar)
- return (length < 128 and (isinstance(self.event, AliasEvent)
- or (isinstance(self.event, ScalarEvent)
- and not self.analysis.empty and not self.analysis.multiline)
- or self.check_empty_sequence() or self.check_empty_mapping()))
-
- # Anchor, Tag, and Scalar processors.
-
- def process_anchor(self, indicator):
- if self.event.anchor is None:
- self.prepared_anchor = None
- return
- if self.prepared_anchor is None:
- self.prepared_anchor = self.prepare_anchor(self.event.anchor)
- if self.prepared_anchor:
- self.write_indicator(indicator+self.prepared_anchor, True)
- self.prepared_anchor = None
-
- def process_tag(self):
- tag = self.event.tag
- if isinstance(self.event, ScalarEvent):
- if self.style is None:
- self.style = self.choose_scalar_style()
- if ((not self.canonical or tag is None) and
- ((self.style == '' and self.event.implicit[0])
- or (self.style != '' and self.event.implicit[1]))):
- self.prepared_tag = None
- return
- if self.event.implicit[0] and tag is None:
- tag = u'!'
- self.prepared_tag = None
- else:
- if (not self.canonical or tag is None) and self.event.implicit:
- self.prepared_tag = None
- return
- if tag is None:
- raise EmitterError("tag is not specified")
- if self.prepared_tag is None:
- self.prepared_tag = self.prepare_tag(tag)
- if self.prepared_tag:
- self.write_indicator(self.prepared_tag, True)
- self.prepared_tag = None
-
- def choose_scalar_style(self):
- if self.analysis is None:
- self.analysis = self.analyze_scalar(self.event.value)
- if self.event.style == '"' or self.canonical:
- return '"'
- if not self.event.style and self.event.implicit[0]:
- if (not (self.simple_key_context and
- (self.analysis.empty or self.analysis.multiline))
- and (self.flow_level and self.analysis.allow_flow_plain
- or (not self.flow_level and self.analysis.allow_block_plain))):
- return ''
- if self.event.style and self.event.style in '|>':
- if (not self.flow_level and not self.simple_key_context
- and self.analysis.allow_block):
- return self.event.style
- if not self.event.style or self.event.style == '\'':
- if (self.analysis.allow_single_quoted and
- not (self.simple_key_context and self.analysis.multiline)):
- return '\''
- return '"'
-
- def process_scalar(self):
- if self.analysis is None:
- self.analysis = self.analyze_scalar(self.event.value)
- if self.style is None:
- self.style = self.choose_scalar_style()
- split = (not self.simple_key_context)
- #if self.analysis.multiline and split \
- # and (not self.style or self.style in '\'\"'):
- # self.write_indent()
- if self.style == '"':
- self.write_double_quoted(self.analysis.scalar, split)
- elif self.style == '\'':
- self.write_single_quoted(self.analysis.scalar, split)
- elif self.style == '>':
- self.write_folded(self.analysis.scalar)
- elif self.style == '|':
- self.write_literal(self.analysis.scalar)
- else:
- self.write_plain(self.analysis.scalar, split)
- self.analysis = None
- self.style = None
-
- # Analyzers.
-
- def prepare_version(self, version):
- major, minor = version
- if major != 1:
- raise EmitterError("unsupported YAML version: %d.%d" % (major, minor))
- return u'%d.%d' % (major, minor)
-
- def prepare_tag_handle(self, handle):
- if not handle:
- raise EmitterError("tag handle must not be empty")
- if handle[0] != u'!' or handle[-1] != u'!':
- raise EmitterError("tag handle must start and end with '!': %r"
- % (handle.encode('utf-8')))
- for ch in handle[1:-1]:
- if not (u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-_'):
- raise EmitterError("invalid character %r in the tag handle: %r"
- % (ch.encode('utf-8'), handle.encode('utf-8')))
- return handle
-
- def prepare_tag_prefix(self, prefix):
- if not prefix:
- raise EmitterError("tag prefix must not be empty")
- chunks = []
- start = end = 0
- if prefix[0] == u'!':
- end = 1
- while end < len(prefix):
- ch = prefix[end]
- if u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-;/?!:@&=+$,_.~*\'()[]':
- end += 1
- else:
- if start < end:
- chunks.append(prefix[start:end])
- start = end = end+1
- data = ch.encode('utf-8')
- for ch in data:
- chunks.append(u'%%%02X' % ord(ch))
- if start < end:
- chunks.append(prefix[start:end])
- return u''.join(chunks)
-
- def prepare_tag(self, tag):
- if not tag:
- raise EmitterError("tag must not be empty")
- if tag == u'!':
- return tag
- handle = None
- suffix = tag
- for prefix in self.tag_prefixes:
- if tag.startswith(prefix) \
- and (prefix == u'!' or len(prefix) < len(tag)):
- handle = self.tag_prefixes[prefix]
- suffix = tag[len(prefix):]
- chunks = []
- start = end = 0
- while end < len(suffix):
- ch = suffix[end]
- if u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-;/?:@&=+$,_.~*\'()[]' \
- or (ch == u'!' and handle != u'!'):
- end += 1
- else:
- if start < end:
- chunks.append(suffix[start:end])
- start = end = end+1
- data = ch.encode('utf-8')
- for ch in data:
- chunks.append(u'%%%02X' % ord(ch))
- if start < end:
- chunks.append(suffix[start:end])
- suffix_text = u''.join(chunks)
- if handle:
- return u'%s%s' % (handle, suffix_text)
- else:
- return u'!<%s>' % suffix_text
-
- def prepare_anchor(self, anchor):
- if not anchor:
- raise EmitterError("anchor must not be empty")
- for ch in anchor:
- if not (u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \
- or ch in u'-_'):
- raise EmitterError("invalid character %r in the anchor: %r"
- % (ch.encode('utf-8'), anchor.encode('utf-8')))
- return anchor
-
- def analyze_scalar(self, scalar):
-
- # Empty scalar is a special case.
- if not scalar:
- return ScalarAnalysis(scalar=scalar, empty=True, multiline=False,
- allow_flow_plain=False, allow_block_plain=True,
- allow_single_quoted=True, allow_double_quoted=True,
- allow_block=False)
-
- # Indicators and special characters.
- block_indicators = False
- flow_indicators = False
- line_breaks = False
- special_characters = False
-
- # Whitespaces.
- inline_spaces = False # non-space space+ non-space
- inline_breaks = False # non-space break+ non-space
- leading_spaces = False # ^ space+ (non-space | $)
- leading_breaks = False # ^ break+ (non-space | $)
- trailing_spaces = False # (^ | non-space) space+ $
- trailing_breaks = False # (^ | non-space) break+ $
- inline_breaks_spaces = False # non-space break+ space+ non-space
- mixed_breaks_spaces = False # anything else
-
- # Check document indicators.
- if scalar.startswith(u'---') or scalar.startswith(u'...'):
- block_indicators = True
- flow_indicators = True
-
- # First character or preceded by a whitespace.
- preceeded_by_space = True
-
- # Last character or followed by a whitespace.
- followed_by_space = (len(scalar) == 1 or
- scalar[1] in u'\0 \t\r\n\x85\u2028\u2029')
-
- # The current series of whitespaces contain plain spaces.
- spaces = False
-
- # The current series of whitespaces contain line breaks.
- breaks = False
-
- # The current series of whitespaces contain a space followed by a
- # break.
- mixed = False
-
- # The current series of whitespaces start at the beginning of the
- # scalar.
- leading = False
-
- index = 0
- while index < len(scalar):
- ch = scalar[index]
-
- # Check for indicators.
-
- if index == 0:
- # Leading indicators are special characters.
- if ch in u'#,[]{}&*!|>\'\"%@`':
- flow_indicators = True
- block_indicators = True
- if ch in u'?:':
- flow_indicators = True
- if followed_by_space:
- block_indicators = True
- if ch == u'-' and followed_by_space:
- flow_indicators = True
- block_indicators = True
- else:
- # Some indicators cannot appear within a scalar as well.
- if ch in u',?[]{}':
- flow_indicators = True
- if ch == u':':
- flow_indicators = True
- if followed_by_space:
- block_indicators = True
- if ch == u'#' and preceeded_by_space:
- flow_indicators = True
- block_indicators = True
-
- # Check for line breaks, special, and unicode characters.
-
- if ch in u'\n\x85\u2028\u2029':
- line_breaks = True
- if not (ch == u'\n' or u'\x20' <= ch <= u'\x7E'):
- if (ch == u'\x85' or u'\xA0' <= ch <= u'\uD7FF'
- or u'\uE000' <= ch <= u'\uFFFD') and ch != u'\uFEFF':
- unicode_characters = True
- if not self.allow_unicode:
- special_characters = True
- else:
- special_characters = True
-
- # Spaces, line breaks, and how they are mixed. State machine.
-
- # Start or continue series of whitespaces.
- if ch in u' \n\x85\u2028\u2029':
- if spaces and breaks:
- if ch != u' ': # break+ (space+ break+) => mixed
- mixed = True
- elif spaces:
- if ch != u' ': # (space+ break+) => mixed
- breaks = True
- mixed = True
- elif breaks:
- if ch == u' ': # break+ space+
- spaces = True
- else:
- leading = (index == 0)
- if ch == u' ': # space+
- spaces = True
- else: # break+
- breaks = True
-
- # Series of whitespaces ended with a non-space.
- elif spaces or breaks:
- if leading:
- if spaces and breaks:
- mixed_breaks_spaces = True
- elif spaces:
- leading_spaces = True
- elif breaks:
- leading_breaks = True
- else:
- if mixed:
- mixed_breaks_spaces = True
- elif spaces and breaks:
- inline_breaks_spaces = True
- elif spaces:
- inline_spaces = True
- elif breaks:
- inline_breaks = True
- spaces = breaks = mixed = leading = False
-
- # Series of whitespaces reach the end.
- if (spaces or breaks) and (index == len(scalar)-1):
- if spaces and breaks:
- mixed_breaks_spaces = True
- elif spaces:
- trailing_spaces = True
- if leading:
- leading_spaces = True
- elif breaks:
- trailing_breaks = True
- if leading:
- leading_breaks = True
- spaces = breaks = mixed = leading = False
-
- # Prepare for the next character.
- index += 1
- preceeded_by_space = (ch in u'\0 \t\r\n\x85\u2028\u2029')
- followed_by_space = (index+1 >= len(scalar) or
- scalar[index+1] in u'\0 \t\r\n\x85\u2028\u2029')
-
- # Let's decide what styles are allowed.
- allow_flow_plain = True
- allow_block_plain = True
- allow_single_quoted = True
- allow_double_quoted = True
- allow_block = True
-
- # Leading and trailing whitespace are bad for plain scalars. We also
- # do not want to mess with leading whitespaces for block scalars.
- if leading_spaces or leading_breaks or trailing_spaces:
- allow_flow_plain = allow_block_plain = allow_block = False
-
- # Trailing breaks are fine for block scalars, but unacceptable for
- # plain scalars.
- if trailing_breaks:
- allow_flow_plain = allow_block_plain = False
-
- # The combination of (space+ break+) is only acceptable for block
- # scalars.
- if inline_breaks_spaces:
- allow_flow_plain = allow_block_plain = allow_single_quoted = False
-
- # Mixed spaces and breaks, as well as special character are only
- # allowed for double quoted scalars.
- if mixed_breaks_spaces or special_characters:
- allow_flow_plain = allow_block_plain = \
- allow_single_quoted = allow_block = False
-
- # We don't emit multiline plain scalars.
- if line_breaks:
- allow_flow_plain = allow_block_plain = False
-
- # Flow indicators are forbidden for flow plain scalars.
- if flow_indicators:
- allow_flow_plain = False
-
- # Block indicators are forbidden for block plain scalars.
- if block_indicators:
- allow_block_plain = False
-
- return ScalarAnalysis(scalar=scalar,
- empty=False, multiline=line_breaks,
- allow_flow_plain=allow_flow_plain,
- allow_block_plain=allow_block_plain,
- allow_single_quoted=allow_single_quoted,
- allow_double_quoted=allow_double_quoted,
- allow_block=allow_block)
-
- # Writers.
-
- def flush_stream(self):
- if hasattr(self.stream, 'flush'):
- self.stream.flush()
-
- def write_stream_start(self):
- # Write BOM if needed.
- if self.encoding and self.encoding.startswith('utf-16'):
- self.stream.write(u'\xFF\xFE'.encode(self.encoding))
-
- def write_stream_end(self):
- self.flush_stream()
-
- def write_indicator(self, indicator, need_whitespace,
- whitespace=False, indention=False):
- if self.whitespace or not need_whitespace:
- data = indicator
- else:
- data = u' '+indicator
- self.whitespace = whitespace
- self.indention = self.indention and indention
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
-
- def write_indent(self):
- indent = self.indent or 0
- if not self.indention or self.column > indent \
- or (self.column == indent and not self.whitespace):
- self.write_line_break()
- if self.column < indent:
- self.whitespace = True
- data = u' '*(indent-self.column)
- self.column = indent
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
-
- def write_line_break(self, data=None):
- if data is None:
- data = self.best_line_break
- self.whitespace = True
- self.indention = True
- self.line += 1
- self.column = 0
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
-
- def write_version_directive(self, version_text):
- data = u'%%YAML %s' % version_text
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- self.write_line_break()
-
- def write_tag_directive(self, handle_text, prefix_text):
- data = u'%%TAG %s %s' % (handle_text, prefix_text)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- self.write_line_break()
-
- # Scalar streams.
-
- def write_single_quoted(self, text, split=True):
- self.write_indicator(u'\'', True)
- spaces = False
- breaks = False
- start = end = 0
- while end <= len(text):
- ch = None
- if end < len(text):
- ch = text[end]
- if spaces:
- if ch is None or ch != u' ':
- if start+1 == end and self.column > self.best_width and split \
- and start != 0 and end != len(text):
- self.write_indent()
- else:
- data = text[start:end]
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end
- elif breaks:
- if ch is None or ch not in u'\n\x85\u2028\u2029':
- if text[start] == u'\n':
- self.write_line_break()
- for br in text[start:end]:
- if br == u'\n':
- self.write_line_break()
- else:
- self.write_line_break(br)
- self.write_indent()
- start = end
- else:
- if ch is None or ch in u' \n\x85\u2028\u2029' or ch == u'\'':
- if start < end:
- data = text[start:end]
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end
- if ch == u'\'':
- data = u'\'\''
- self.column += 2
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end + 1
- if ch is not None:
- spaces = (ch == u' ')
- breaks = (ch in u'\n\x85\u2028\u2029')
- end += 1
- self.write_indicator(u'\'', False)
-
- ESCAPE_REPLACEMENTS = {
- u'\0': u'0',
- u'\x07': u'a',
- u'\x08': u'b',
- u'\x09': u't',
- u'\x0A': u'n',
- u'\x0B': u'v',
- u'\x0C': u'f',
- u'\x0D': u'r',
- u'\x1B': u'e',
- u'\"': u'\"',
- u'\\': u'\\',
- u'\x85': u'N',
- u'\xA0': u'_',
- u'\u2028': u'L',
- u'\u2029': u'P',
- }
-
- def write_double_quoted(self, text, split=True):
- self.write_indicator(u'"', True)
- start = end = 0
- while end <= len(text):
- ch = None
- if end < len(text):
- ch = text[end]
- if ch is None or ch in u'"\\\x85\u2028\u2029\uFEFF' \
- or not (u'\x20' <= ch <= u'\x7E'
- or (self.allow_unicode
- and (u'\xA0' <= ch <= u'\uD7FF'
- or u'\uE000' <= ch <= u'\uFFFD'))):
- if start < end:
- data = text[start:end]
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end
- if ch is not None:
- if ch in self.ESCAPE_REPLACEMENTS:
- data = u'\\'+self.ESCAPE_REPLACEMENTS[ch]
- elif ch <= u'\xFF':
- data = u'\\x%02X' % ord(ch)
- elif ch <= u'\uFFFF':
- data = u'\\u%04X' % ord(ch)
- else:
- data = u'\\U%08X' % ord(ch)
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end+1
- if 0 < end < len(text)-1 and (ch == u' ' or start >= end) \
- and self.column+(end-start) > self.best_width and split:
- data = text[start:end]+u'\\'
- if start < end:
- start = end
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- self.write_indent()
- self.whitespace = False
- self.indention = False
- if text[start] == u' ':
- data = u'\\'
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- end += 1
- self.write_indicator(u'"', False)
-
- def determine_chomp(self, text):
- tail = text[-2:]
- while len(tail) < 2:
- tail = u' '+tail
- if tail[-1] in u'\n\x85\u2028\u2029':
- if tail[-2] in u'\n\x85\u2028\u2029':
- return u'+'
- else:
- return u''
- else:
- return u'-'
-
- def write_folded(self, text):
- chomp = self.determine_chomp(text)
- self.write_indicator(u'>'+chomp, True)
- self.write_indent()
- leading_space = False
- spaces = False
- breaks = False
- start = end = 0
- while end <= len(text):
- ch = None
- if end < len(text):
- ch = text[end]
- if breaks:
- if ch is None or ch not in u'\n\x85\u2028\u2029':
- if not leading_space and ch is not None and ch != u' ' \
- and text[start] == u'\n':
- self.write_line_break()
- leading_space = (ch == u' ')
- for br in text[start:end]:
- if br == u'\n':
- self.write_line_break()
- else:
- self.write_line_break(br)
- if ch is not None:
- self.write_indent()
- start = end
- elif spaces:
- if ch != u' ':
- if start+1 == end and self.column > self.best_width:
- self.write_indent()
- else:
- data = text[start:end]
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end
- else:
- if ch is None or ch in u' \n\x85\u2028\u2029':
- data = text[start:end]
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- if ch is None:
- self.write_line_break()
- start = end
- if ch is not None:
- breaks = (ch in u'\n\x85\u2028\u2029')
- spaces = (ch == u' ')
- end += 1
-
- def write_literal(self, text):
- chomp = self.determine_chomp(text)
- self.write_indicator(u'|'+chomp, True)
- self.write_indent()
- breaks = False
- start = end = 0
- while end <= len(text):
- ch = None
- if end < len(text):
- ch = text[end]
- if breaks:
- if ch is None or ch not in u'\n\x85\u2028\u2029':
- for br in text[start:end]:
- if br == u'\n':
- self.write_line_break()
- else:
- self.write_line_break(br)
- if ch is not None:
- self.write_indent()
- start = end
- else:
- if ch is None or ch in u'\n\x85\u2028\u2029':
- data = text[start:end]
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- if ch is None:
- self.write_line_break()
- start = end
- if ch is not None:
- breaks = (ch in u'\n\x85\u2028\u2029')
- end += 1
-
- def write_plain(self, text, split=True):
- if not text:
- return
- if not self.whitespace:
- data = u' '
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- self.writespace = False
- self.indention = False
- spaces = False
- breaks = False
- start = end = 0
- while end <= len(text):
- ch = None
- if end < len(text):
- ch = text[end]
- if spaces:
- if ch != u' ':
- if start+1 == end and self.column > self.best_width and split:
- self.write_indent()
- self.writespace = False
- self.indention = False
- else:
- data = text[start:end]
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end
- elif breaks:
- if ch not in u'\n\x85\u2028\u2029':
- if text[start] == u'\n':
- self.write_line_break()
- for br in text[start:end]:
- if br == u'\n':
- self.write_line_break()
- else:
- self.write_line_break(br)
- self.write_indent()
- self.whitespace = False
- self.indention = False
- start = end
- else:
- if ch is None or ch in u' \n\x85\u2028\u2029':
- data = text[start:end]
- self.column += len(data)
- if self.encoding:
- data = data.encode(self.encoding)
- self.stream.write(data)
- start = end
- if ch is not None:
- spaces = (ch == u' ')
- breaks = (ch in u'\n\x85\u2028\u2029')
- end += 1
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/error.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/error.py b/tools/bin/ext/yaml/error.py
deleted file mode 100644
index 89e4a6a..0000000
--- a/tools/bin/ext/yaml/error.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-__all__ = ['Mark', 'YAMLError', 'MarkedYAMLError']
-
-class Mark(object):
-
- def __init__(self, name, index, line, column, buffer, pointer):
- self.name = name
- self.index = index
- self.line = line
- self.column = column
- self.buffer = buffer
- self.pointer = pointer
-
- def get_snippet(self, indent=4, max_length=75):
- if self.buffer is None:
- return None
- head = ''
- start = self.pointer
- while start > 0 and self.buffer[start-1] not in u'\0\r\n\x85\u2028\u2029':
- start -= 1
- if self.pointer-start > max_length/2-1:
- head = ' ... '
- start += 5
- break
- tail = ''
- end = self.pointer
- while end < len(self.buffer) and self.buffer[end] not in u'\0\r\n\x85\u2028\u2029':
- end += 1
- if end-self.pointer > max_length/2-1:
- tail = ' ... '
- end -= 5
- break
- snippet = self.buffer[start:end].encode('utf-8')
- return ' '*indent + head + snippet + tail + '\n' \
- + ' '*(indent+self.pointer-start+len(head)) + '^'
-
- def __str__(self):
- snippet = self.get_snippet()
- where = " in \"%s\", line %d, column %d" \
- % (self.name, self.line+1, self.column+1)
- if snippet is not None:
- where += ":\n"+snippet
- return where
-
-class YAMLError(Exception):
- pass
-
-class MarkedYAMLError(YAMLError):
-
- def __init__(self, context=None, context_mark=None,
- problem=None, problem_mark=None, note=None):
- self.context = context
- self.context_mark = context_mark
- self.problem = problem
- self.problem_mark = problem_mark
- self.note = note
-
- def __str__(self):
- lines = []
- if self.context is not None:
- lines.append(self.context)
- if self.context_mark is not None \
- and (self.problem is None or self.problem_mark is None
- or self.context_mark.name != self.problem_mark.name
- or self.context_mark.line != self.problem_mark.line
- or self.context_mark.column != self.problem_mark.column):
- lines.append(str(self.context_mark))
- if self.problem is not None:
- lines.append(self.problem)
- if self.problem_mark is not None:
- lines.append(str(self.problem_mark))
- if self.note is not None:
- lines.append(self.note)
- return '\n'.join(lines)
-
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/ext/yaml/events.py
----------------------------------------------------------------------
diff --git a/tools/bin/ext/yaml/events.py b/tools/bin/ext/yaml/events.py
deleted file mode 100644
index f57b773..0000000
--- a/tools/bin/ext/yaml/events.py
+++ /dev/null
@@ -1,102 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Abstract classes.
-
-class Event(object):
- def __init__(self, start_mark=None, end_mark=None):
- self.start_mark = start_mark
- self.end_mark = end_mark
- def __repr__(self):
- attributes = [key for key in ['anchor', 'tag', 'implicit', 'value']
- if hasattr(self, key)]
- arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
- for key in attributes])
- return '%s(%s)' % (self.__class__.__name__, arguments)
-
-class NodeEvent(Event):
- def __init__(self, anchor, start_mark=None, end_mark=None):
- self.anchor = anchor
- self.start_mark = start_mark
- self.end_mark = end_mark
-
-class CollectionStartEvent(NodeEvent):
- def __init__(self, anchor, tag, implicit, start_mark=None, end_mark=None,
- flow_style=None):
- self.anchor = anchor
- self.tag = tag
- self.implicit = implicit
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.flow_style = flow_style
-
-class CollectionEndEvent(Event):
- pass
-
-# Implementations.
-
-class StreamStartEvent(Event):
- def __init__(self, start_mark=None, end_mark=None, encoding=None):
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.encoding = encoding
-
-class StreamEndEvent(Event):
- pass
-
-class DocumentStartEvent(Event):
- def __init__(self, start_mark=None, end_mark=None,
- explicit=None, version=None, tags=None):
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.explicit = explicit
- self.version = version
- self.tags = tags
-
-class DocumentEndEvent(Event):
- def __init__(self, start_mark=None, end_mark=None,
- explicit=None):
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.explicit = explicit
-
-class AliasEvent(NodeEvent):
- pass
-
-class ScalarEvent(NodeEvent):
- def __init__(self, anchor, tag, implicit, value,
- start_mark=None, end_mark=None, style=None):
- self.anchor = anchor
- self.tag = tag
- self.implicit = implicit
- self.value = value
- self.start_mark = start_mark
- self.end_mark = end_mark
- self.style = style
-
-class SequenceStartEvent(CollectionStartEvent):
- pass
-
-class SequenceEndEvent(CollectionEndEvent):
- pass
-
-class MappingStartEvent(CollectionStartEvent):
- pass
-
-class MappingEndEvent(CollectionEndEvent):
- pass
-
[03/13] incubator-hawq git commit: HAWQ-271. Remove external python
modules.
Posted by rl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/pg.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/pg.py b/tools/bin/pythonSrc/PyGreSQL-4.0/pg.py
deleted file mode 100644
index 53c6669..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/pg.py
+++ /dev/null
@@ -1,711 +0,0 @@
-#!/usr/bin/env python
-#
-# pg.py
-#
-# Written by D'Arcy J.M. Cain
-# Improved by Christoph Zwerschke
-#
-# $Id: pg.py,v 1.77 2008/12/30 16:40:00 darcy Exp $
-#
-
-"""PyGreSQL classic interface.
-
-This pg module implements some basic database management stuff.
-It includes the _pg module and builds on it, providing the higher
-level wrapper class named DB with addtional functionality.
-This is known as the "classic" ("old style") PyGreSQL interface.
-For a DB-API 2 compliant interface use the newer pgdb module.
-
-"""
-
-from _pg import *
-try:
- frozenset
-except NameError: # Python < 2.4
- from sets import ImmutableSet as frozenset
-try:
- from decimal import Decimal
- set_decimal(Decimal)
-except ImportError:
- pass # Python < 2.4
-
-
-# Auxiliary functions which are independent from a DB connection:
-
-def _is_quoted(s):
- """Check whether this string is a quoted identifier."""
- s = s.replace('_', 'a')
- return not s.isalnum() or s[:1].isdigit() or s != s.lower()
-
-def _is_unquoted(s):
- """Check whether this string is an unquoted identifier."""
- s = s.replace('_', 'a')
- return s.isalnum() and not s[:1].isdigit()
-
-def _split_first_part(s):
- """Split the first part of a dot separated string."""
- s = s.lstrip()
- if s[:1] == '"':
- p = []
- s = s.split('"', 3)[1:]
- p.append(s[0])
- while len(s) == 3 and s[1] == '':
- p.append('"')
- s = s[2].split('"', 2)
- p.append(s[0])
- p = [''.join(p)]
- s = '"'.join(s[1:]).lstrip()
- if s:
- if s[:0] == '.':
- p.append(s[1:])
- else:
- s = _split_first_part(s)
- p[0] += s[0]
- if len(s) > 1:
- p.append(s[1])
- else:
- p = s.split('.', 1)
- s = p[0].rstrip()
- if _is_unquoted(s):
- s = s.lower()
- p[0] = s
- return p
-
-def _split_parts(s):
- """Split all parts of a dot separated string."""
- q = []
- while s:
- s = _split_first_part(s)
- q.append(s[0])
- if len(s) < 2:
- break
- s = s[1]
- return q
-
-def _join_parts(s):
- """Join all parts of a dot separated string."""
- return '.'.join([_is_quoted(p) and '"%s"' % p or p for p in s])
-
-def _oid_key(qcl):
- """Build oid key from qualified class name."""
- return 'oid(%s)' % qcl
-
-
-# The PostGreSQL database connection interface:
-
-class DB(object):
- """Wrapper class for the _pg connection type."""
-
- def __init__(self, *args, **kw):
- """Create a new connection.
-
- You can pass either the connection parameters or an existing
- _pg or pgdb connection. This allows you to use the methods
- of the classic pg interface with a DB-API 2 pgdb connection.
-
- """
- if not args and len(kw) == 1:
- db = kw.get('db')
- elif not kw and len(args) == 1:
- db = args[0]
- else:
- db = None
- if db:
- if isinstance(db, DB):
- db = db.db
- else:
- try:
- db = db._cnx
- except AttributeError:
- pass
- if not db or not hasattr(db, 'db') or not hasattr(db, 'query'):
- db = connect(*args, **kw)
- self._closeable = 1
- else:
- self._closeable = 0
- self.db = db
- self.dbname = db.db
- self._attnames = {}
- self._pkeys = {}
- self._privileges = {}
- self._args = args, kw
- self.debug = None # For debugging scripts, this can be set
- # * to a string format specification (e.g. in CGI set to "%s<BR>"),
- # * to a file object to write debug statements or
- # * to a callable object which takes a string argument.
-
- def __getattr__(self, name):
- # All undefined members are the same as in the underlying pg connection:
- if self.db:
- return getattr(self.db, name)
- else:
- raise InternalError('Connection is not valid')
-
- # Auxiliary methods
-
- def _do_debug(self, s):
- """Print a debug message."""
- if self.debug:
- if isinstance(self.debug, basestring):
- print self.debug % s
- elif isinstance(self.debug, file):
- print >> self.debug, s
- elif callable(self.debug):
- self.debug(s)
-
- def _quote_text(self, d):
- """Quote text value."""
- if not isinstance(d, basestring):
- d = str(d)
- return "'%s'" % self.escape_string(d)
-
- _bool_true = frozenset('t true 1 y yes on'.split())
-
- def _quote_bool(self, d):
- """Quote boolean value."""
- if isinstance(d, basestring):
- if not d:
- return 'NULL'
- d = d.lower() in self._bool_true
- else:
- d = bool(d)
- return ("'f'", "'t'")[d]
-
- _date_literals = frozenset('current_date current_time'
- ' current_timestamp localtime localtimestamp'.split())
-
- def _quote_date(self, d):
- """Quote date value."""
- if not d:
- return 'NULL'
- if isinstance(d, basestring) and d.lower() in self._date_literals:
- return d
- return self._quote_text(d)
-
- def _quote_num(self, d):
- """Quote numeric value."""
- if not d and d != 0:
- return 'NULL'
- return str(d)
-
- def _quote_money(self, d):
- """Quote money value."""
- if not d:
- return 'NULL'
- return "'%.2f'" % float(d)
-
- _quote_funcs = dict( # quote methods for each type
- text=_quote_text, bool=_quote_bool, date=_quote_date,
- int=_quote_num, num=_quote_num, float=_quote_num,
- money=_quote_money)
-
- def _quote(self, d, t):
- """Return quotes if needed."""
- if d is None:
- return 'NULL'
- try:
- quote_func = self._quote_funcs[t]
- except KeyError:
- quote_func = self._quote_funcs['text']
- return quote_func(self, d)
-
- def _split_schema(self, cl):
- """Return schema and name of object separately.
-
- This auxiliary function splits off the namespace (schema)
- belonging to the class with the name cl. If the class name
- is not qualified, the function is able to determine the schema
- of the class, taking into account the current search path.
-
- """
- s = _split_parts(cl)
- if len(s) > 1: # name already qualfied?
- # should be database.schema.table or schema.table
- if len(s) > 3:
- raise ProgrammingError('Too many dots in class name %s' % cl)
- schema, cl = s[-2:]
- else:
- cl = s[0]
- # determine search path
- q = 'SELECT current_schemas(TRUE)'
- schemas = self.db.query(q).getresult()[0][0][1:-1].split(',')
- if schemas: # non-empty path
- # search schema for this object in the current search path
- q = ' UNION '.join(
- ["SELECT %d::integer AS n, '%s'::name AS nspname"
- % s for s in enumerate(schemas)])
- q = ("SELECT nspname FROM pg_class"
- " JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid"
- " JOIN (%s) AS p USING (nspname)"
- " WHERE pg_class.relname = '%s'"
- " ORDER BY n LIMIT 1" % (q, cl))
- schema = self.db.query(q).getresult()
- if schema: # schema found
- schema = schema[0][0]
- else: # object not found in current search path
- schema = 'public'
- else: # empty path
- schema = 'public'
- return schema, cl
-
- def _add_schema(self, cl):
- """Ensure that the class name is prefixed with a schema name."""
- return _join_parts(self._split_schema(cl))
-
- # Public methods
-
- # escape_string and escape_bytea exist as methods,
- # so we define unescape_bytea as a method as well
- unescape_bytea = staticmethod(unescape_bytea)
-
- def close(self):
- """Close the database connection."""
- # Wraps shared library function so we can track state.
- if self._closeable:
- if self.db:
- self.db.close()
- self.db = None
- else:
- raise InternalError('Connection already closed')
-
- def reset(self):
- """Reset connection with current parameters.
-
- All derived queries and large objects derived from this connection
- will not be usable after this call.
-
- """
- self.db.reset()
-
- def reopen(self):
- """Reopen connection to the database.
-
- Used in case we need another connection to the same database.
- Note that we can still reopen a database that we have closed.
-
- """
- # There is no such shared library function.
- if self._closeable:
- db = connect(*self._args[0], **self._args[1])
- if self.db:
- self.db.close()
- self.db = db
-
- def query(self, qstr):
- """Executes a SQL command string.
-
- This method simply sends a SQL query to the database. If the query is
- an insert statement that inserted exactly one row into a table that
- has OIDs, the return value is the OID of the newly inserted row.
- If the query is an update or delete statement, or an insert statement
- that did not insert exactly one row in a table with OIDs, then the
- numer of rows affected is returned as a string. If it is a statement
- that returns rows as a result (usually a select statement, but maybe
- also an "insert/update ... returning" statement), this method returns
- a pgqueryobject that can be accessed via getresult() or dictresult()
- or simply printed. Otherwise, it returns `None`.
-
- """
- # Wraps shared library function for debugging.
- if not self.db:
- raise InternalError('Connection is not valid')
- self._do_debug(qstr)
- return self.db.query(qstr)
-
- def pkey(self, cl, newpkey=None):
- """This method gets or sets the primary key of a class.
-
- Composite primary keys are represented as frozensets. Note that
- this raises an exception if the table does not have a primary key.
-
- If newpkey is set and is not a dictionary then set that
- value as the primary key of the class. If it is a dictionary
- then replace the _pkeys dictionary with a copy of it.
-
- """
- # First see if the caller is supplying a dictionary
- if isinstance(newpkey, dict):
- # make sure that all classes have a namespace
- self._pkeys = dict([
- ('.' in cl and cl or 'public.' + cl, pkey)
- for cl, pkey in newpkey.iteritems()])
- return self._pkeys
-
- qcl = self._add_schema(cl) # build fully qualified class name
- # Check if the caller is supplying a new primary key for the class
- if newpkey:
- self._pkeys[qcl] = newpkey
- return newpkey
-
- # Get all the primary keys at once
- if qcl not in self._pkeys:
- # if not found, check again in case it was added after we started
- self._pkeys = {}
- if self.server_version >= 80200:
- # the ANY syntax works correctly only with PostgreSQL >= 8.2
- any_indkey = "= ANY (pg_index.indkey)"
- else:
- any_indkey = "IN (%s)" % ', '.join(
- ['pg_index.indkey[%d]' % i for i in range(16)])
- for r in self.db.query(
- "SELECT pg_namespace.nspname, pg_class.relname,"
- " pg_attribute.attname FROM pg_class"
- " JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace"
- " AND pg_namespace.nspname NOT LIKE 'pg_%'"
- " JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid"
- " AND pg_attribute.attisdropped = 'f'"
- " JOIN pg_index ON pg_index.indrelid = pg_class.oid"
- " AND pg_index.indisprimary = 't'"
- " AND pg_attribute.attnum " + any_indkey).getresult():
- cl, pkey = _join_parts(r[:2]), r[2]
- self._pkeys.setdefault(cl, []).append(pkey)
- # (only) for composite primary keys, the values will be frozensets
- for cl, pkey in self._pkeys.iteritems():
- self._pkeys[cl] = len(pkey) > 1 and frozenset(pkey) or pkey[0]
- self._do_debug(self._pkeys)
-
- # will raise an exception if primary key doesn't exist
- return self._pkeys[qcl]
-
- def get_databases(self):
- """Get list of databases in the system."""
- return [s[0] for s in
- self.db.query('SELECT datname FROM pg_database').getresult()]
-
- def get_relations(self, kinds=None):
- """Get list of relations in connected database of specified kinds.
-
- If kinds is None or empty, all kinds of relations are returned.
- Otherwise kinds can be a string or sequence of type letters
- specifying which kind of relations you want to list.
-
- """
- where = kinds and "pg_class.relkind IN (%s) AND" % ','.join(
- ["'%s'" % x for x in kinds]) or ''
- return map(_join_parts, self.db.query(
- "SELECT pg_namespace.nspname, pg_class.relname "
- "FROM pg_class "
- "JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
- "WHERE %s pg_class.relname !~ '^Inv' AND "
- "pg_class.relname !~ '^pg_' "
- "ORDER BY 1, 2" % where).getresult())
-
- def get_tables(self):
- """Return list of tables in connected database."""
- return self.get_relations('r')
-
- def get_attnames(self, cl, newattnames=None):
- """Given the name of a table, digs out the set of attribute names.
-
- Returns a dictionary of attribute names (the names are the keys,
- the values are the names of the attributes' types).
- If the optional newattnames exists, it must be a dictionary and
- will become the new attribute names dictionary.
-
- """
- if isinstance(newattnames, dict):
- self._attnames = newattnames
- return
- elif newattnames:
- raise ProgrammingError(
- 'If supplied, newattnames must be a dictionary')
- cl = self._split_schema(cl) # split into schema and class
- qcl = _join_parts(cl) # build fully qualified name
- # May as well cache them:
- if qcl in self._attnames:
- return self._attnames[qcl]
- if qcl not in self.get_relations('rv'):
- raise ProgrammingError('Class %s does not exist' % qcl)
- t = {}
- for att, typ in self.db.query("SELECT pg_attribute.attname,"
- " pg_type.typname FROM pg_class"
- " JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid"
- " JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid"
- " JOIN pg_type ON pg_type.oid = pg_attribute.atttypid"
- " WHERE pg_namespace.nspname = '%s' AND pg_class.relname = '%s'"
- " AND (pg_attribute.attnum > 0 or pg_attribute.attname = 'oid')"
- " AND pg_attribute.attisdropped = 'f'"
- % cl).getresult():
- if typ.startswith('bool'):
- t[att] = 'bool'
- elif typ.startswith('abstime'):
- t[att] = 'date'
- elif typ.startswith('date'):
- t[att] = 'date'
- elif typ.startswith('interval'):
- t[att] = 'date'
- elif typ.startswith('timestamp'):
- t[att] = 'date'
- elif typ.startswith('oid'):
- t[att] = 'int'
- elif typ.startswith('int'):
- t[att] = 'int'
- elif typ.startswith('float'):
- t[att] = 'float'
- elif typ.startswith('numeric'):
- t[att] = 'num'
- elif typ.startswith('money'):
- t[att] = 'money'
- else:
- t[att] = 'text'
- self._attnames[qcl] = t # cache it
- return self._attnames[qcl]
-
- def has_table_privilege(self, cl, privilege='select'):
- """Check whether current user has specified table privilege."""
- qcl = self._add_schema(cl)
- privilege = privilege.lower()
- try:
- return self._privileges[(qcl, privilege)]
- except KeyError:
- q = "SELECT has_table_privilege('%s', '%s')" % (qcl, privilege)
- ret = self.db.query(q).getresult()[0][0] == 't'
- self._privileges[(qcl, privilege)] = ret
- return ret
-
- def get(self, cl, arg, keyname=None):
- """Get a tuple from a database table or view.
-
- This method is the basic mechanism to get a single row. The keyname
- that the key specifies a unique row. If keyname is not specified
- then the primary key for the table is used. If arg is a dictionary
- then the value for the key is taken from it and it is modified to
- include the new values, replacing existing values where necessary.
- For a composite key, keyname can also be a sequence of key names.
- The OID is also put into the dictionary if the table has one, but
- in order to allow the caller to work with multiple tables, it is
- munged as oid(schema.table).
-
- """
- if cl.endswith('*'): # scan descendant tables?
- cl = cl[:-1].rstrip() # need parent table name
- # build qualified class name
- qcl = self._add_schema(cl)
- # To allow users to work with multiple tables,
- # we munge the name of the "oid" the key
- qoid = _oid_key(qcl)
- if not keyname:
- # use the primary key by default
- try:
- keyname = self.pkey(qcl)
- except KeyError:
- raise ProgrammingError('Class %s has no primary key' % qcl)
- # We want the oid for later updates if that isn't the key
- if keyname == 'oid':
- if isinstance(arg, dict):
- if qoid not in arg:
- raise ProgrammingError('%s not in arg' % qoid)
- else:
- arg = {qoid: arg}
- where = 'oid = %s' % arg[qoid]
- attnames = '*'
- else:
- attnames = self.get_attnames(qcl)
- if isinstance(keyname, basestring):
- keyname = (keyname,)
- if not isinstance(arg, dict):
- if len(keyname) > 1:
- raise ProgrammingError('Composite key needs dict as arg')
- arg = dict([(k, arg) for k in keyname])
- where = ' AND '.join(['%s = %s'
- % (k, self._quote(arg[k], attnames[k])) for k in keyname])
- attnames = ', '.join(attnames)
- q = 'SELECT %s FROM %s WHERE %s LIMIT 1' % (attnames, qcl, where)
- self._do_debug(q)
- res = self.db.query(q).dictresult()
- if not res:
- raise DatabaseError('No such record in %s where %s' % (qcl, where))
- for att, value in res[0].iteritems():
- arg[att == 'oid' and qoid or att] = value
- return arg
-
- def insert(self, cl, d=None, **kw):
- """Insert a tuple into a database table.
-
- This method inserts a row into a table. If a dictionary is
- supplied it starts with that. Otherwise it uses a blank dictionary.
- Either way the dictionary is updated from the keywords.
-
- The dictionary is then, if possible, reloaded with the values actually
- inserted in order to pick up values modified by rules, triggers, etc.
-
- Note: The method currently doesn't support insert into views
- although PostgreSQL does.
-
- """
- qcl = self._add_schema(cl)
- qoid = _oid_key(qcl)
- if d is None:
- d = {}
- d.update(kw)
- attnames = self.get_attnames(qcl)
- names, values = [], []
- for n in attnames:
- if n != 'oid' and n in d:
- names.append('"%s"' % n)
- values.append(self._quote(d[n], attnames[n]))
- names, values = ', '.join(names), ', '.join(values)
- selectable = self.has_table_privilege(qcl)
- if selectable and self.server_version >= 80200:
- ret = ' RETURNING %s*' % ('oid' in attnames and 'oid, ' or '')
- else:
- ret = ''
- q = 'INSERT INTO %s (%s) VALUES (%s)%s' % (qcl, names, values, ret)
- self._do_debug(q)
- res = self.db.query(q)
- if ret:
- res = res.dictresult()
- for att, value in res[0].iteritems():
- d[att == 'oid' and qoid or att] = value
- elif isinstance(res, int):
- d[qoid] = res
- if selectable:
- self.get(qcl, d, 'oid')
- elif selectable:
- if qoid in d:
- self.get(qcl, d, 'oid')
- else:
- try:
- self.get(qcl, d)
- except ProgrammingError:
- pass # table has no primary key
- return d
-
- def update(self, cl, d=None, **kw):
- """Update an existing row in a database table.
-
- Similar to insert but updates an existing row. The update is based
- on the OID value as munged by get or passed as keyword, or on the
- primary key of the table. The dictionary is modified, if possible,
- to reflect any changes caused by the update due to triggers, rules,
- default values, etc.
-
- """
- # Update always works on the oid which get returns if available,
- # otherwise use the primary key. Fail if neither.
- # Note that we only accept oid key from named args for safety
- qcl = self._add_schema(cl)
- qoid = _oid_key(qcl)
- if 'oid' in kw:
- kw[qoid] = kw['oid']
- del kw['oid']
- if d is None:
- d = {}
- d.update(kw)
- attnames = self.get_attnames(qcl)
- if qoid in d:
- where = 'oid = %s' % d[qoid]
- keyname = ()
- else:
- try:
- keyname = self.pkey(qcl)
- except KeyError:
- raise ProgrammingError('Class %s has no primary key' % qcl)
- if isinstance(keyname, basestring):
- keyname = (keyname,)
- try:
- where = ' AND '.join(['%s = %s'
- % (k, self._quote(d[k], attnames[k])) for k in keyname])
- except KeyError:
- raise ProgrammingError('Update needs primary key or oid.')
- values = []
- for n in attnames:
- if n in d and n not in keyname:
- values.append('%s = %s' % (n, self._quote(d[n], attnames[n])))
- if not values:
- return d
- values = ', '.join(values)
- selectable = self.has_table_privilege(qcl)
- if selectable and self.server_version >= 880200:
- ret = ' RETURNING %s*' % ('oid' in attnames and 'oid, ' or '')
- else:
- ret = ''
- q = 'UPDATE %s SET %s WHERE %s%s' % (qcl, values, where, ret)
- self._do_debug(q)
- res = self.db.query(q)
- if ret:
- res = self.db.query(q).dictresult()
- for att, value in res[0].iteritems():
- d[att == 'oid' and qoid or att] = value
- else:
- self.db.query(q)
- if selectable:
- if qoid in d:
- self.get(qcl, d, 'oid')
- else:
- self.get(qcl, d)
- return d
-
- def clear(self, cl, a=None):
- """
-
- This method clears all the attributes to values determined by the types.
- Numeric types are set to 0, Booleans are set to 'f', and everything
- else is set to the empty string. If the array argument is present,
- it is used as the array and any entries matching attribute names are
- cleared with everything else left unchanged.
-
- """
- # At some point we will need a way to get defaults from a table.
- qcl = self._add_schema(cl)
- if a is None:
- a = {} # empty if argument is not present
- attnames = self.get_attnames(qcl)
- for n, t in attnames.iteritems():
- if n == 'oid':
- continue
- if t in ('int', 'float', 'num', 'money'):
- a[n] = 0
- elif t == 'bool':
- a[n] = 'f'
- else:
- a[n] = ''
- return a
-
- def delete(self, cl, d=None, **kw):
- """Delete an existing row in a database table.
-
- This method deletes the row from a table. It deletes based on the
- OID value as munged by get or passed as keyword, or on the primary
- key of the table. The return value is the number of deleted rows
- (i.e. 0 if the row did not exist and 1 if the row was deleted).
-
- """
- # Like update, delete works on the oid.
- # One day we will be testing that the record to be deleted
- # isn't referenced somewhere (or else PostgreSQL will).
- # Note that we only accept oid key from named args for safety
- qcl = self._add_schema(cl)
- qoid = _oid_key(qcl)
- if 'oid' in kw:
- kw[qoid] = kw['oid']
- del kw['oid']
- if d is None:
- d = {}
- d.update(kw)
- if qoid in d:
- where = 'oid = %s' % d[qoid]
- else:
- try:
- keyname = self.pkey(qcl)
- except KeyError:
- raise ProgrammingError('Class %s has no primary key' % qcl)
- if isinstance(keyname, basestring):
- keyname = (keyname,)
- attnames = self.get_attnames(qcl)
- try:
- where = ' AND '.join(['%s = %s'
- % (k, self._quote(d[k], attnames[k])) for k in keyname])
- except KeyError:
- raise ProgrammingError('Delete needs primary key or oid.')
- q = 'DELETE FROM %s WHERE %s' % (qcl, where)
- self._do_debug(q)
- return int(self.db.query(q))
-
-
-# if run as script, print some information
-
-if __name__ == '__main__':
- print 'PyGreSQL version', version
- print
- print __doc__
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/0672292f/tools/bin/pythonSrc/PyGreSQL-4.0/pgdb.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/PyGreSQL-4.0/pgdb.py b/tools/bin/pythonSrc/PyGreSQL-4.0/pgdb.py
deleted file mode 100644
index 4b4344c..0000000
--- a/tools/bin/pythonSrc/PyGreSQL-4.0/pgdb.py
+++ /dev/null
@@ -1,582 +0,0 @@
-#!/usr/bin/env python
-#
-# pgdb.py
-#
-# Written by D'Arcy J.M. Cain
-#
-# $Id: pgdb.py,v 1.54 2008/11/23 14:32:18 cito Exp $
-#
-
-"""pgdb - DB-API 2.0 compliant module for PygreSQL.
-
-(c) 1999, Pascal Andre <an...@via.ecp.fr>.
-See package documentation for further information on copyright.
-
-Inline documentation is sparse.
-See DB-API 2.0 specification for usage information:
-http://www.python.org/peps/pep-0249.html
-
-Basic usage:
-
- pgdb.connect(connect_string) # open a connection
- # connect_string = 'host:database:user:password:opt:tty'
- # All parts are optional. You may also pass host through
- # password as keyword arguments. To pass a port,
- # pass it in the host keyword parameter:
- pgdb.connect(host='localhost:5432')
-
- connection.cursor() # open a cursor
-
- cursor.execute(query[, params])
- # Execute a query, binding params (a dictionary) if they are
- # passed. The binding syntax is the same as the % operator
- # for dictionaries, and no quoting is done.
-
- cursor.executemany(query, list of params)
- # Execute a query many times, binding each param dictionary
- # from the list.
-
- cursor.fetchone() # fetch one row, [value, value, ...]
-
- cursor.fetchall() # fetch all rows, [[value, value, ...], ...]
-
- cursor.fetchmany([size])
- # returns size or cursor.arraysize number of rows,
- # [[value, value, ...], ...] from result set.
- # Default cursor.arraysize is 1.
-
- cursor.description # returns information about the columns
- # [(column_name, type_name, display_size,
- # internal_size, precision, scale, null_ok), ...]
- # Note that precision, scale and null_ok are not implemented.
-
- cursor.rowcount # number of rows available in the result set
- # Available after a call to execute.
-
- connection.commit() # commit transaction
-
- connection.rollback() # or rollback transaction
-
- cursor.close() # close the cursor
-
- connection.close() # close the connection
-
-"""
-
-from _pg import *
-import time
-try:
- frozenset
-except NameError: # Python < 2.4
- from sets import ImmutableSet as frozenset
-from datetime import datetime, timedelta
-try: # use Decimal if available
- from decimal import Decimal
- set_decimal(Decimal)
-except ImportError: # otherwise (Python < 2.4)
- Decimal = float # use float instead of Decimal
-
-
-### Module Constants
-
-# compliant with DB SIG 2.0
-apilevel = '2.0'
-
-# module may be shared, but not connections
-threadsafety = 1
-
-# this module use extended python format codes
-paramstyle = 'pyformat'
-
-
-### Internal Types Handling
-
-def decimal_type(decimal_type=None):
- """Get or set global type to be used for decimal values."""
- global Decimal
- if decimal_type is not None:
- Decimal = decimal_type
- set_decimal(decimal_type)
- return Decimal
-
-
-def _cast_bool(value):
- return value[:1] in ['t', 'T']
-
-
-def _cast_money(value):
- return Decimal(''.join(filter(
- lambda v: v in '0123456789.-', value)))
-
-
-_cast = {'bool': _cast_bool,
- 'int2': int, 'int4': int, 'serial': int,
- 'int8': long, 'oid': long, 'oid8': long,
- 'float4': float, 'float8': float,
- 'numeric': Decimal, 'money': _cast_money}
-
-
-class pgdbTypeCache(dict):
- """Cache for database types."""
-
- def __init__(self, cnx):
- """Initialize type cache for connection."""
- super(pgdbTypeCache, self).__init__()
- self._src = cnx.source()
-
- def typecast(typ, value):
- """Cast value to database type."""
- if value is None:
- # for NULL values, no typecast is necessary
- return None
- cast = _cast.get(typ)
- if cast is None:
- # no typecast available or necessary
- return value
- else:
- return cast(value)
- typecast = staticmethod(typecast)
-
- def getdescr(self, oid):
- """Get name of database type with given oid."""
- try:
- return self[oid]
- except KeyError:
- self._src.execute(
- "SELECT typname, typlen "
- "FROM pg_type WHERE oid=%s" % oid)
- res = self._src.fetch(1)[0]
- # The column name is omitted from the return value.
- # It will have to be prepended by the caller.
- res = (res[0], None, int(res[1]),
- None, None, None)
- self[oid] = res
- return res
-
-
-class _quotedict(dict):
- """Dictionary with auto quoting of its items.
-
- The quote attribute must be set to the desired quote function.
-
- """
-
- def __getitem__(self, key):
- return self.quote(super(_quotedict, self).__getitem__(key))
-
-
-### Cursor Object
-
-class pgdbCursor(object):
- """Cursor Object."""
-
- def __init__(self, dbcnx):
- """Create a cursor object for the database connection."""
- self.connection = self._dbcnx = dbcnx
- self._cnx = dbcnx._cnx
- self._type_cache = dbcnx._type_cache
- self._src = self._cnx.source()
- self.description = None
- self.rowcount = -1
- self.arraysize = 1
- self.lastrowid = None
-
- def __iter__(self):
- """Return self to make cursors compatible to the iteration protocol."""
- return self
-
- def _quote(self, val):
- """Quote value depending on its type."""
- if isinstance(val, datetime):
- val = str(val)
- elif isinstance(val, unicode):
- val = val.encode( 'utf8' )
- if isinstance(val, str):
- val = "'%s'" % self._cnx.escape_string(val)
- elif isinstance(val, (int, long, float)):
- pass
- elif val is None:
- val = 'NULL'
- elif isinstance(val, (list, tuple)):
- val = '(%s)' % ','.join(map(lambda v: str(self._quote(v)), val))
- elif Decimal is not float and isinstance(val, Decimal):
- pass
- elif hasattr(val, '__pg_repr__'):
- val = val.__pg_repr__()
- else:
- raise InterfaceError(
- 'do not know how to handle type %s' % type(val))
- return val
-
- def _quoteparams(self, string, params):
- """Quote parameters.
-
- This function works for both mappings and sequences.
-
- """
- if isinstance(params, dict):
- params = _quotedict(params)
- params.quote = self._quote
- else:
- params = tuple(map(self._quote, params))
- return string % params
-
- def row_factory(row):
- """Process rows before they are returned.
-
- You can overwrite this with a custom row factory,
- e.g. a dict factory:
-
- class myCursor(pgdb.pgdbCursor):
- def cursor.row_factory(self, row):
- d = {}
- for idx, col in enumerate(self.description):
- d[col[0]] = row[idx]
- return d
- cursor = myCursor(cnx)
-
- """
- return row
- row_factory = staticmethod(row_factory)
-
- def close(self):
- """Close the cursor object."""
- self._src.close()
- self.description = None
- self.rowcount = -1
- self.lastrowid = None
-
- def execute(self, operation, params=None):
- """Prepare and execute a database operation (query or command)."""
- # The parameters may also be specified as list of
- # tuples to e.g. insert multiple rows in a single
- # operation, but this kind of usage is deprecated:
- if (params and isinstance(params, list)
- and isinstance(params[0], tuple)):
- self.executemany(operation, params)
- else:
- # not a list of tuples
- self.executemany(operation, (params,))
-
- def executemany(self, operation, param_seq):
- """Prepare operation and execute it against a parameter sequence."""
- if not param_seq:
- # don't do anything without parameters
- return
- self.description = None
- self.rowcount = -1
- # first try to execute all queries
- totrows = 0
- sql = "BEGIN"
- try:
- if not self._dbcnx._tnx:
- try:
- self._cnx.source().execute(sql)
- except Exception:
- raise OperationalError("can't start transaction")
- self._dbcnx._tnx = True
- for params in param_seq:
- if params:
- sql = self._quoteparams(operation, params)
- else:
- sql = operation
- rows = self._src.execute(sql)
- if rows: # true if not DML
- totrows += rows
- else:
- self.rowcount = -1
- except Error, msg:
- raise DatabaseError("error '%s' in '%s'" % (msg, sql))
- except Exception, err:
- raise OperationalError("internal error in '%s': %s" % (sql, err))
- # then initialize result raw count and description
- if self._src.resulttype == RESULT_DQL:
- self.rowcount = self._src.ntuples
- getdescr = self._type_cache.getdescr
- coltypes = self._src.listinfo()
- self.description = [typ[1:2] + getdescr(typ[2]) for typ in coltypes]
- self.lastrowid = self._src.oidstatus()
- else:
- self.rowcount = totrows
- self.description = None
- self.lastrowid = self._src.oidstatus()
-
- def fetchone(self):
- """Fetch the next row of a query result set."""
- res = self.fetchmany(1, False)
- try:
- return res[0]
- except IndexError:
- return None
-
- def fetchall(self):
- """Fetch all (remaining) rows of a query result."""
- return self.fetchmany(-1, False)
-
- def fetchmany(self, size=None, keep=False):
- """Fetch the next set of rows of a query result.
-
- The number of rows to fetch per call is specified by the
- size parameter. If it is not given, the cursor's arraysize
- determines the number of rows to be fetched. If you set
- the keep parameter to true, this is kept as new arraysize.
-
- """
- if size is None:
- size = self.arraysize
- if keep:
- self.arraysize = size
- try:
- result = self._src.fetch(size)
- except Error, err:
- raise DatabaseError(str(err))
- row_factory = self.row_factory
- typecast = self._type_cache.typecast
- coltypes = [desc[1] for desc in self.description]
- return [row_factory([typecast(*args)
- for args in zip(coltypes, row)]) for row in result]
-
- def next(self):
- """Return the next row (support for the iteration protocol)."""
- res = self.fetchone()
- if res is None:
- raise StopIteration
- return res
-
- def nextset():
- """Not supported."""
- raise NotSupportedError("nextset() is not supported")
- nextset = staticmethod(nextset)
-
- def setinputsizes(sizes):
- """Not supported."""
- pass
- setinputsizes = staticmethod(setinputsizes)
-
- def setoutputsize(size, column=0):
- """Not supported."""
- pass
- setoutputsize = staticmethod(setoutputsize)
-
-
-### Connection Objects
-
-class pgdbCnx(object):
- """Connection Object."""
-
- # expose the exceptions as attributes on the connection object
- Error = Error
- Warning = Warning
- InterfaceError = InterfaceError
- DatabaseError = DatabaseError
- InternalError = InternalError
- OperationalError = OperationalError
- ProgrammingError = ProgrammingError
- IntegrityError = IntegrityError
- DataError = DataError
- NotSupportedError = NotSupportedError
-
- def __init__(self, cnx):
- """Create a database connection object."""
- self._cnx = cnx # connection
- self._tnx = False # transaction state
- self._type_cache = pgdbTypeCache(cnx)
- try:
- self._cnx.source()
- except Exception:
- raise OperationalError("invalid connection")
-
- def close(self):
- """Close the connection object."""
- if self._cnx:
- self._cnx.close()
- self._cnx = None
- else:
- raise OperationalError("connection has been closed")
-
- def commit(self):
- """Commit any pending transaction to the database."""
- if self._cnx:
- if self._tnx:
- self._tnx = False
- try:
- self._cnx.source().execute("COMMIT")
- except Exception:
- raise OperationalError("can't commit")
- else:
- raise OperationalError("connection has been closed")
-
- def rollback(self):
- """Roll back to the start of any pending transaction."""
- if self._cnx:
- if self._tnx:
- self._tnx = False
- try:
- self._cnx.source().execute("ROLLBACK")
- except Exception:
- raise OperationalError("can't rollback")
- else:
- raise OperationalError("connection has been closed")
-
- def cursor(self):
- """Return a new Cursor Object using the connection."""
- if self._cnx:
- try:
- return pgdbCursor(self)
- except Exception:
- raise OperationalError("invalid connection")
- else:
- raise OperationalError("connection has been closed")
-
-
-### Module Interface
-
-_connect_ = connect
-
-def connect(dsn=None,
- user=None, password=None,
- host=None, database=None):
- """Connects to a database."""
- # first get params from DSN
- dbport = -1
- dbhost = ""
- dbbase = ""
- dbuser = ""
- dbpasswd = ""
- dbopt = ""
- dbtty = ""
- try:
- params = dsn.split(":")
- dbhost = params[0]
- dbport = int(params[1])
- dbbase = params[2]
- dbuser = params[3]
- dbpasswd = params[4]
- dbopt = params[5]
- dbtty = params[6]
- except (AttributeError, IndexError, TypeError):
- pass
-
- # override if necessary
- if user is not None:
- dbuser = user
- if password is not None:
- dbpasswd = password
- if database is not None:
- dbbase = database
- if host is not None:
- try:
- params = host.split(":")
- dbhost = params[0]
- dbport = int(params[1])
- except (AttributeError, IndexError, TypeError, ValueError):
- pass
-
- # empty host is localhost
- if dbhost == "":
- dbhost = None
- if dbuser == "":
- dbuser = None
-
- # open the connection
- cnx = _connect_(dbbase, dbhost, dbport, dbopt,
- dbtty, dbuser, dbpasswd)
- return pgdbCnx(cnx)
-
-
-### Types Handling
-
-class pgdbType(frozenset):
- """Type class for a couple of PostgreSQL data types.
-
- PostgreSQL is object-oriented: types are dynamic.
- We must thus use type names as internal type codes.
-
- """
-
- if frozenset.__module__ == '__builtin__':
- def __new__(cls, values):
- if isinstance(values, basestring):
- values = values.split()
- return super(pgdbType, cls).__new__(cls, values)
- else: # Python < 2.4
- def __init__(self, values):
- if isinstance(values, basestring):
- values = values.split()
- super(pgdbType, self).__init__(values)
-
- def __eq__(self, other):
- if isinstance(other, basestring):
- return other in self
- else:
- return super(pgdbType, self).__eq__(other)
-
- def __ne__(self, other):
- if isinstance(other, basestring):
- return other not in self
- else:
- return super(pgdbType, self).__ne__(other)
-
-
-# Mandatory type objects defined by DB-API 2 specs:
-
-STRING = pgdbType('char bpchar name text varchar')
-BINARY = pgdbType('bytea')
-NUMBER = pgdbType('int2 int4 serial int8 float4 float8 numeric money')
-DATETIME = pgdbType('date time timetz timestamp timestamptz datetime abstime'
- ' interval tinterval timespan reltime')
-ROWID = pgdbType('oid oid8')
-
-
-# Additional type objects (more specific):
-
-BOOL = pgdbType('bool')
-SMALLINT = pgdbType('int2')
-INTEGER = pgdbType('int2 int4 int8 serial')
-LONG = pgdbType('int8')
-FLOAT = pgdbType('float4 float8')
-NUMERIC = pgdbType('numeric')
-MONEY = pgdbType('money')
-DATE = pgdbType('date')
-TIME = pgdbType('time timetz')
-TIMESTAMP = pgdbType('timestamp timestamptz datetime abstime')
-INTERVAL = pgdbType('interval tinterval timespan reltime')
-
-
-# Mandatory type helpers defined by DB-API 2 specs:
-
-def Date(year, month, day):
- """Construct an object holding a date value."""
- return datetime(year, month, day)
-
-def Time(hour, minute, second):
- """Construct an object holding a time value."""
- return timedelta(hour, minute, second)
-
-def Timestamp(year, month, day, hour, minute, second):
- """construct an object holding a time stamp value."""
- return datetime(year, month, day, hour, minute, second)
-
-def DateFromTicks(ticks):
- """Construct an object holding a date value from the given ticks value."""
- return Date(*time.localtime(ticks)[:3])
-
-def TimeFromTicks(ticks):
- """construct an object holding a time value from the given ticks value."""
- return Time(*time.localtime(ticks)[3:6])
-
-def TimestampFromTicks(ticks):
- """construct an object holding a time stamp from the given ticks value."""
- return Timestamp(*time.localtime(ticks)[:6])
-
-def Binary(value):
- """construct an object capable of holding a binary (long) string value."""
- return value
-
-
-# If run as script, print some information:
-
-if __name__ == '__main__':
- print 'PyGreSQL version', version
- print
- print __doc__