~radix/storm/database-trace-hook

« back to all changes in this revision

Viewing changes to storm/databases/mysql.py

Merge no-underscore-parse-methods [r=niemeyer,jkakar] [f=128060]

Now it's easy to tell what you can touch in Storm: If it begins with
an underscore, you definitely can't touch it in any way. If it doesn't
begin with an underscore, read the documentation to see how it's meant
to be used. If it doesn't have a docstring, file a bug. :-)

This branch renames _parse_get, _parse_set, _from_database, _to_database,
_build_raw_cursor, _raw_execute, _result_factory, _param_mark, _compile,
and _connection_factory so that they no longer have preceding underscores,
because they were all meant to be overridden in subclasses. Documentation
was added on their intended usage.

It also adds a LOT of documentation to store.py, variables.py, and
database.py, and fixes a few existing docstrings to be valid epytext.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        return And(*equals)
67
67
 
68
68
    @staticmethod
69
 
    def _from_database(row):
 
69
    def from_database(row):
 
70
        """Convert MySQL-specific datatypes to "normal" Python types.
 
71
 
 
72
        If there are any C{array} instances in the row, convert them
 
73
        to strings.
 
74
        """
70
75
        for value in row:
71
76
            if isinstance(value, array):
72
77
                yield value.tostring()
76
81
 
77
82
class MySQLConnection(Connection):
78
83
 
79
 
    _result_factory = MySQLResult
80
 
    _param_mark = "%s"
81
 
    _compile = compile
 
84
    result_factory = MySQLResult
 
85
    param_mark = "%s"
 
86
    compile = compile
82
87
 
83
88
 
84
89
class MySQL(Database):
85
90
 
86
 
    _connection_factory = MySQLConnection
 
91
    connection_factory = MySQLConnection
87
92
    _converters = None
88
93
 
89
94
    def __init__(self, uri):
115
120
 
116
121
    def connect(self):
117
122
        raw_connection = MySQLdb.connect(**self._connect_kwargs)
118
 
        return self._connection_factory(self, raw_connection)
 
123
        return self.connection_factory(self, raw_connection)
119
124
 
120
125
 
121
126
create_from_uri = MySQL