annotate MySQLdb/__init__.py @ 32:4a5668deee4a MySQLdb

Merge back r554 for deprecated sets module
author kylev
date Wed, 11 Feb 2009 23:45:57 +0000
parents d55bfb1a4701
children df4d804244ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
1 """
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
2 MySQLdb
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
3 =======
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
4 A DB API v2.0 compatible interface to MySQL
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
5 -------------------------------------------
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
6
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
7 This package is a wrapper around _mysql, which mostly implements the
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
8 MySQL C API.
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
9
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
10 See the C API specification and the MySQL documentation for more info
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
11 on other items.
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
12
15
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
13 For information on the DB API, see PEP-249.
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
14
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
15 For information on how MySQLdb handles type conversion, see the
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
16 MySQLdb.converters module.
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
17 """
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
18
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
19 __revision__ = """$Revision$"""[11:-2]
10
3f4c6af70e52 Me and PyLint had a knife fight, but PyLint had a gun.
adustman
parents: 4
diff changeset
20 from MySQLdb.release import __version__, version_info, __author__
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
21 from MySQLdb.exceptions import Warning, Error, InterfaceError, DataError, \
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
22 DatabaseError, OperationalError, IntegrityError, InternalError, \
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
23 NotSupportedError, ProgrammingError
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
24
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
25 threadsafety = 1
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
26 apilevel = "2.0"
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
27 paramstyle = "format"
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
28
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
29 from MySQLdb.constants import FIELD_TYPE
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
30 from MySQLdb.times import Date, Time, Timestamp, \
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
31 DateFromTicks, TimeFromTicks, TimestampFromTicks
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
32
32
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
33 try:
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
34 frozenset
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
35 except NameError:
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
36 from sets import ImmutableSet as frozenset
15
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
37
32
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
38 class DBAPISet(frozenset):
15
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
39 """A special type of set for which A == x is True if A is a
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
40 DBAPISet and x is a member of that set.
a275593a1630 More doc fixes
adustman
parents: 10
diff changeset
41 """
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
42 def __eq__(self, other):
32
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
43 if isinstance(other, DBAPISet):
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
44 return not self.difference(other)
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
45 return other in self
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
46
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
47
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
48 STRING = DBAPISet([FIELD_TYPE.ENUM, FIELD_TYPE.STRING,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
49 FIELD_TYPE.VAR_STRING])
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
50 BINARY = DBAPISet([FIELD_TYPE.BLOB, FIELD_TYPE.LONG_BLOB,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
51 FIELD_TYPE.MEDIUM_BLOB, FIELD_TYPE.TINY_BLOB])
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
52 NUMBER = DBAPISet([FIELD_TYPE.DECIMAL, FIELD_TYPE.DOUBLE, FIELD_TYPE.FLOAT,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
53 FIELD_TYPE.INT24, FIELD_TYPE.LONG, FIELD_TYPE.LONGLONG,
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
54 FIELD_TYPE.TINY, FIELD_TYPE.YEAR])
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
55 DATE = DBAPISet([FIELD_TYPE.DATE, FIELD_TYPE.NEWDATE])
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
56 TIME = DBAPISet([FIELD_TYPE.TIME])
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
57 TIMESTAMP = DBAPISet([FIELD_TYPE.TIMESTAMP, FIELD_TYPE.DATETIME])
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
58 DATETIME = TIMESTAMP
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
59 ROWID = DBAPISet()
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
60
32
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
61 def test_DBAPISet_set_equality():
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
62 assert STRING == STRING
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
63
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
64 def test_DBAPISet_set_inequality():
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
65 assert STRING != NUMBER
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
66
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
67 def test_DBAPISet_set_equality_membership():
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
68 assert FIELD_TYPE.VAR_STRING == STRING
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
69
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
70 def test_DBAPISet_set_inequality_membership():
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
71 assert FIELD_TYPE.DATE != STRING
4a5668deee4a Merge back r554 for deprecated sets module
kylev
parents: 18
diff changeset
72
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
73 def Binary(x):
10
3f4c6af70e52 Me and PyLint had a knife fight, but PyLint had a gun.
adustman
parents: 4
diff changeset
74 """Return x as a binary type."""
4
b5a377255eea Merge changes from MySQLdb-1.2 branch (448-455)
adustman
parents: 0
diff changeset
75 return str(x)
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
76
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
77 def Connect(*args, **kwargs):
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
78 """Factory function for connections.Connection."""
10
3f4c6af70e52 Me and PyLint had a knife fight, but PyLint had a gun.
adustman
parents: 4
diff changeset
79 from MySQLdb.connections import Connection
0
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
80 return Connection(*args, **kwargs)
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
81
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
82 connect = Connection = Connect
e48810735f11 Copying 1.2.1 to be the new trunk
adustman
parents:
diff changeset
83
18
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
84 __all__ = [
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
85 'BINARY', 'Binary', 'Connect', 'Connection', 'DATE', 'Date',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
86 'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
87 'DataError', 'DatabaseError', 'Error', 'FIELD_TYPE', 'IntegrityError',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
88 'InterfaceError', 'InternalError', 'MySQLError', 'NULL', 'NUMBER',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
89 'NotSupportedError', 'DBAPISet', 'OperationalError', 'ProgrammingError',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
90 'ROWID', 'STRING', 'TIME', 'TIMESTAMP', 'Warning', 'apilevel', 'connect',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
91 'connections', 'constants', 'converters', 'cursors', 'debug', 'escape',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
92 'escape_dict', 'escape_sequence', 'escape_string', 'get_client_info',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
93 'paramstyle', 'string_literal', 'threadsafety', 'version_info',
d55bfb1a4701 Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents: 15
diff changeset
94 ]