summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradustman <adustman@9fc6cd9a-920d-0410-adcf-ac96716ed7e8>2004-05-19 03:54:01 +0000
committeradustman <adustman@9fc6cd9a-920d-0410-adcf-ac96716ed7e8>2004-05-19 03:54:01 +0000
commit1fdb7422a6f3d0868a78bd1d6a1b66a690d22ff2 (patch)
treedb1da0f86624efbd6dc20801cba85539488e5b81
parent187d93c188bc568929d915af654efcc6d1d8ab97 (diff)
downloadmysqldb1-1fdb7422a6f3d0868a78bd1d6a1b66a690d22ff2.tar.gz
Initial conversion to modern Python.
-rw-r--r--MySQLdb/MySQLdb/__init__.py10
-rw-r--r--MySQLdb/MySQLdb/connections.py4
-rw-r--r--MySQLdb/MySQLdb/converters.py5
-rw-r--r--MySQLdb/MySQLdb/cursors.py120
-rw-r--r--MySQLdb/MySQLdb/mxdatetimes.py6
-rw-r--r--MySQLdb/MySQLdb/pytimes.py19
-rw-r--r--MySQLdb/MySQLdb/sets.py9
-rw-r--r--MySQLdb/MySQLdb/times.py2
-rw-r--r--MySQLdb/_mysql.c6
-rw-r--r--MySQLdb/_mysql_exceptions.py4
-rw-r--r--MySQLdb/setup.cfg2
-rw-r--r--MySQLdb/setup.py2
12 files changed, 58 insertions, 131 deletions
diff --git a/MySQLdb/MySQLdb/__init__.py b/MySQLdb/MySQLdb/__init__.py
index 2fd82c9..3be0608 100644
--- a/MySQLdb/MySQLdb/__init__.py
+++ b/MySQLdb/MySQLdb/__init__.py
@@ -16,11 +16,11 @@ MySQLdb.converters module.
__author__ = "Andy Dustman <andy@dustman.net>"
__revision__ = """$Revision$"""[11:-2]
version_info = (
+ 1,
+ 1,
0,
- 9,
- 3,
- "beta",
- 3)
+ "final",
+ 1)
if version_info[3] == "final": __version__ = "%d.%d.%d" % version_info[:3]
else: __version__ = "%d.%d.%d%1.1s%d" % version_info[:5]
@@ -61,7 +61,7 @@ def Binary(x): return str(x)
def Connect(*args, **kwargs):
"""Factory function for connections.Connection."""
from connections import Connection
- return apply(Connection, args, kwargs)
+ return Connection(*args, **kwargs)
connect = Connection = Connect
diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py
index bf32ec8..341500c 100644
--- a/MySQLdb/MySQLdb/connections.py
+++ b/MySQLdb/MySQLdb/connections.py
@@ -38,14 +38,14 @@ if hasattr(types, "ObjectType"):
class ConnectionBase(_mysql.connection):
def _make_connection(self, args, kwargs):
- apply(super(ConnectionBase, self).__init__, args, kwargs)
+ super(ConnectionBase, self).__init__(*args, **kwargs)
else:
class ConnectionBase:
def _make_connection(self, args, kwargs):
- self._db = apply(_mysql.connect, args, kwargs)
+ self._db = _mysql.connect(*args, **kwargs)
def __getattr__(self, attr):
if hasattr(self, "_db"):
diff --git a/MySQLdb/MySQLdb/converters.py b/MySQLdb/MySQLdb/converters.py
index 82f7abc..8fbe103 100644
--- a/MySQLdb/MySQLdb/converters.py
+++ b/MySQLdb/MySQLdb/converters.py
@@ -29,14 +29,13 @@ from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL
from constants import FIELD_TYPE, FLAG
from sets import *
from times import *
-from string import split
import types
import array
def Str2Set(s):
- values = split(s, ',')
- return apply(Set, tuple(values))
+ values = s.split(',')
+ return Set(*values)
def Thing2Str(s, d):
"""Convert something into a string via str()."""
diff --git a/MySQLdb/MySQLdb/cursors.py b/MySQLdb/MySQLdb/cursors.py
index 517b42a..4138641 100644
--- a/MySQLdb/MySQLdb/cursors.py
+++ b/MySQLdb/MySQLdb/cursors.py
@@ -133,7 +133,6 @@ class BaseCursor:
execute().
"""
- from string import join
from sys import exc_info
del self.messages[:]
if not args: return
@@ -159,13 +158,14 @@ class BaseCursor:
exc, value, tb = exc_info()
del tb
self.errorhandler(self, exc, value)
- r = self._query(join(q,',\n'))
+ r = self._query(',\n'.join(q))
self._executed = query
return r
- def __do_query(self, q):
+ def _do_query(self, q):
+ from warnings import warn
+ from string import atoi
- from string import split, atoi
db = self._get_db()
db.query(q)
self._result = self._get_result()
@@ -173,27 +173,14 @@ class BaseCursor:
self.rownumber = 0
self.description = self._result and self._result.describe() or None
self.lastrowid = db.insert_id()
- self._check_for_warnings()
+ info = db.info()
+ if info:
+ warnings = atoi(info.split()[-1])
+ if warnings:
+ warn(info, self.Warning, stacklevel=4)
return self.rowcount
- def _check_for_warnings(self): pass
-
- _query = __do_query
-
- def info(self):
- """Return some information about the last query (db.info())
- DEPRECATED: Use messages attribute"""
- self._check_executed()
- if self.messages:
- return self.messages[-1]
- else:
- return ''
-
- def insert_id(self):
- """Return the last inserted ID on an AUTO_INCREMENT columns.
- DEPRECATED: use lastrowid attribute"""
- self._check_executed()
- return self.lastrowid
+ def _query(self, q): return self._do_query(q)
def _fetch_row(self, size=1):
if not self._result:
@@ -214,22 +201,6 @@ class BaseCursor:
ProgrammingError = ProgrammingError
NotSupportedError = NotSupportedError
-
-class CursorWarningMixIn:
-
- """This is a MixIn class that provides the capability of raising
- the Warning exception when something went slightly wrong with your
- query."""
-
- def _check_for_warnings(self):
- from string import atoi, split
- info = self._get_db().info()
- if not info:
- return
- warnings = atoi(split(info)[-1])
- if warnings:
- raise Warning, info
-
class CursorStoreResultMixIn:
@@ -246,7 +217,7 @@ class CursorStoreResultMixIn:
BaseCursor.close(self)
def _query(self, q):
- rowcount = self._BaseCursor__do_query(q)
+ rowcount = self._do_query(q)
self._rows = self._fetch_row(0)
self._result = None
return rowcount
@@ -276,24 +247,6 @@ class CursorStoreResultMixIn:
self.rownumber = len(self._rows)
return result
- def seek(self, row, whence=0):
- """seek to a given row of the result set analogously to file.seek().
- This is non-standard extension. DEPRECATED: Use scroll method"""
- self._check_executed()
- if whence == 0:
- self.rownumber = row
- elif whence == 1:
- self.rownumber = self.rownumber + row
- elif whence == 2:
- self.rownumber = len(self._rows) + row
-
- def tell(self):
- """Return the current position in the result set analogously to
- file.tell(). This is a non-standard extension. DEPRECATED:
- use rownumber attribute"""
- self._check_executed()
- return self.rownumber
-
def scroll(self, value, mode='relative'):
"""Scroll the cursor in the result set to a new position according
to mode.
@@ -400,58 +353,31 @@ class CursorOldDictRowsMixIn(CursorDictRowsMixIn):
_fetch_type = 2
-class CursorNW(CursorStoreResultMixIn, CursorTupleRowsMixIn,
- BaseCursor):
-
- """This is a basic Cursor class that returns rows as tuples and
- stores the result set in the client. Warnings are not raised."""
-
-
-class Cursor(CursorWarningMixIn, CursorNW):
+class Cursor(CursorStoreResultMixIn, CursorTupleRowsMixIn,
+ BaseCursor):
"""This is the standard Cursor class that returns rows as tuples
- and stores the result set in the client. Warnings are raised as
- necessary."""
+ and stores the result set in the client."""
-class DictCursorNW(CursorStoreResultMixIn, CursorDictRowsMixIn,
- BaseCursor):
-
- """This is a Cursor class that returns rows as dictionaries and
- stores the result set in the client. Warnings are not raised."""
-
-
-class DictCursor(CursorWarningMixIn, DictCursorNW):
+class DictCursor(CursorStoreResultMixIn, CursorDictRowsMixIn,
+ BaseCursor):
"""This is a Cursor class that returns rows as dictionaries and
- stores the result set in the client. Warnings are raised as
- necessary."""
+ stores the result set in the client."""
-class SSCursorNW(CursorUseResultMixIn, CursorTupleRowsMixIn,
- BaseCursor):
-
- """This is a basic Cursor class that returns rows as tuples and
- stores the result set in the server. Warnings are not raised."""
-
-
-class SSCursor(CursorWarningMixIn, SSCursorNW):
+class SSCursor(CursorUseResultMixIn, CursorTupleRowsMixIn,
+ BaseCursor):
"""This is a Cursor class that returns rows as tuples and stores
- the result set in the server. Warnings are raised as necessary."""
-
+ the result set in the server."""
-class SSDictCursorNW(CursorUseResultMixIn, CursorDictRowsMixIn,
- BaseCursor):
- """This is a Cursor class that returns rows as dictionaries and
- stores the result set in the server. Warnings are not raised."""
-
-
-class SSDictCursor(CursorWarningMixIn, SSDictCursorNW):
+class SSDictCursor(CursorUseResultMixIn, CursorDictRowsMixIn,
+ BaseCursor):
"""This is a Cursor class that returns rows as dictionaries and
- stores the result set in the server. Warnings are raised as
- necessary."""
+ stores the result set in the server."""
diff --git a/MySQLdb/MySQLdb/mxdatetimes.py b/MySQLdb/MySQLdb/mxdatetimes.py
index f2200b5..e1f0583 100644
--- a/MySQLdb/MySQLdb/mxdatetimes.py
+++ b/MySQLdb/MySQLdb/mxdatetimes.py
@@ -13,15 +13,15 @@ except ImportError:
def DateFromTicks(ticks):
"""Convert UNIX ticks into a mx.DateTime.Date."""
- return apply(Date, localtime(ticks)[:3])
+ return Date(*localtime(ticks)[:3])
def TimeFromTicks(ticks):
"""Convert UNIX ticks into a mx.DateTime.Time."""
- return apply(Time, localtime(ticks)[3:6])
+ return Time(*localtime(ticks)[3:6])
def TimestampFromTicks(ticks):
"""Convert UNIX ticks into a mx.DateTime.Timestamp."""
- return apply(Timestamp, localtime(ticks)[:6])
+ return Timestamp(*localtime(ticks)[:6])
def format_DATE(d):
"""Format a DateTime object as an ISO date."""
diff --git a/MySQLdb/MySQLdb/pytimes.py b/MySQLdb/MySQLdb/pytimes.py
index 8f2d1c6..ea52b14 100644
--- a/MySQLdb/MySQLdb/pytimes.py
+++ b/MySQLdb/MySQLdb/pytimes.py
@@ -1,8 +1,7 @@
"""Use Python datetime module to handle date and time columns."""
# datetime is only in Python 2.3 or newer, so it is safe to use
-# string methods. However, have to use apply(func, args) instead
-# of func(*args) because 1.5.2 will reject the syntax.
+# string methods.
from time import localtime
from datetime import date, datetime, time, timedelta
@@ -16,17 +15,21 @@ DateTimeType = type(datetime)
def DateFromTicks(ticks):
"""Convert UNIX ticks into a date instance."""
- return apply(date, localtime(ticks)[:3])
+ return date(*localtime(ticks)[:3])
def TimeFromTicks(ticks):
"""Convert UNIX ticks into a time instance."""
- return apply(time, localtime(ticks)[3:6])
+ return time(*localtime(ticks)[3:6])
def TimestampFromTicks(ticks):
"""Convert UNIX ticks into a datetime instance."""
- return apply(datetime, localtime(ticks)[:6])
+ return datetime(*localtime(ticks)[:6])
+
+format_TIME = format_DATE = str
+
+def format_TIMESTAMP(d):
+ return d.strftime("%Y-%m-%d %H:%M:%S")
-format_TIME = format_TIMESTAMP = format_DATE = str
def DateTime_or_None(s):
if ' ' in s:
@@ -38,7 +41,7 @@ def DateTime_or_None(s):
try:
d, t = s.split(sep, 1)
- return apply(datetime, tuple(map(int, d.split('-')+t.split(':'))))
+ return datetime(*[ int(x) for x in d.split('-')+t.split(':') ])
except:
return None
@@ -65,5 +68,5 @@ def Time_or_None(s):
return None
def Date_or_None(s):
- try: return apply(date, tuple(map(int, s.split('-',2))))
+ try: return date(*[ int(x) for x in s.split('-',2)])
except: return None
diff --git a/MySQLdb/MySQLdb/sets.py b/MySQLdb/MySQLdb/sets.py
index b4bf877..edc1a3e 100644
--- a/MySQLdb/MySQLdb/sets.py
+++ b/MySQLdb/MySQLdb/sets.py
@@ -17,8 +17,7 @@ class Set:
def __str__(self):
"""Returns the values as a comma-separated string."""
- from string import join
- return join(map(str, self._values),',')
+ return ','.join([ str(x) for x in self._values])
def __repr__(self):
return "%s%s" % (self.__class__.__name__, `self._values`)
@@ -32,7 +31,7 @@ class Set:
values.append(v)
elif other not in self._values:
values.append(other)
- return apply(self.__class__, values)
+ return self.__class__(*values)
__add__ = __or__
@@ -44,7 +43,7 @@ class Set:
values.remove(v)
elif other in self:
values.remove(other)
- return apply(self.__class__, tuple(values))
+ return self.__class__(*values)
def __and__(self, other):
"Intersection."
@@ -55,7 +54,7 @@ class Set:
values.append(v)
elif other in self:
values.append(other)
- return apply(self.__class__, tuple(values))
+ return self.__class__(*values)
__mul__ = __and__
diff --git a/MySQLdb/MySQLdb/times.py b/MySQLdb/MySQLdb/times.py
index 924a136..8a9c55d 100644
--- a/MySQLdb/MySQLdb/times.py
+++ b/MySQLdb/MySQLdb/times.py
@@ -29,5 +29,5 @@ def mysql_timestamp_converter(s):
s = s + "0"*(14-len(s)) # padding
parts = map(int, filter(None, (s[:4],s[4:6],s[6:8],
s[8:10],s[10:12],s[12:14])))
- try: return apply(Timestamp, tuple(parts))
+ try: return Timestamp(*parts)
except: return None
diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c
index c519936..956b425 100644
--- a/MySQLdb/_mysql.c
+++ b/MySQLdb/_mysql.c
@@ -1,5 +1,5 @@
-#define version_info "(0,9,3,'beta',3)"
-#define __version__ "0.9.3"
+#define version_info "(1,1,0,'final',1)"
+#define __version__ "1.1.0"
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -434,7 +434,7 @@ _mysql_ConnectionObject_Initialize(
MYSQL *conn=NULL;
PyObject *conv = NULL;
PyObject *ssl = NULL;
- PyObject *value = NULL;;
+ PyObject *value = NULL;
char *key = NULL, *cert = NULL, *ca = NULL,
*capath = NULL, *cipher = NULL;
char *host = NULL, *user = NULL, *passwd = NULL,
diff --git a/MySQLdb/_mysql_exceptions.py b/MySQLdb/_mysql_exceptions.py
index 9614121..98037e5 100644
--- a/MySQLdb/_mysql_exceptions.py
+++ b/MySQLdb/_mysql_exceptions.py
@@ -5,14 +5,14 @@ These classes are dictated by the DB API v2.0:
http://www.python.org/topics/database/DatabaseAPI-2.0.html
"""
-from exceptions import Exception, StandardError
+from exceptions import Exception, StandardError, Warning
class MySQLError(StandardError):
"""Exception related to operation with MySQL."""
-class Warning(MySQLError):
+class Warning(Warning, MySQLError):
"""Exception raised for important warnings like data truncations
while inserting, etc."""
diff --git a/MySQLdb/setup.cfg b/MySQLdb/setup.cfg
index 3f4aa5b..3474781 100644
--- a/MySQLdb/setup.cfg
+++ b/MySQLdb/setup.cfg
@@ -1,5 +1,5 @@
[bdist_rpm]
-doc_files = README doc/*.?tml CHANGELOG
+doc_files = README doc/*.??ml CHANGELOG
vendor = MySQL-python SourceForge Project
packager = Andy Dustman <andy@dustman.net>
distribution-name = Red Hat Linux
diff --git a/MySQLdb/setup.py b/MySQLdb/setup.py
index b44ade9..58ad692 100644
--- a/MySQLdb/setup.py
+++ b/MySQLdb/setup.py
@@ -18,7 +18,7 @@ embedded_server = (mysqlclient == 'mysqld')
name = "MySQL-%s" % os.path.basename(sys.executable)
if embedded_server:
name = name + "-embedded"
-version = "0.9.3b3"
+version = "1.1.0"
# include files and library locations should cover most platforms
include_dirs = [