[Sqlalchemy-commits] [1214] sqlalchemy/trunk/doc/build/content/types.myt: fixed pickle example, its
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-03-26 19:58:19
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1214] sqlalchemy/trunk/doc/build/content/types.myt: fixed pickle example, its standard anyway....</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1214</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-03-26 13:58:08 -0600 (Sun, 26 Mar 2006)</dd> </dl> <h3>Log Message</h3> <pre>fixed pickle example, its standard anyway....</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkdocbuildcontenttypesmyt">sqlalchemy/trunk/doc/build/content/types.myt</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkdocbuildcontenttypesmyt"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/doc/build/content/types.myt (1213 => 1214)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/doc/build/content/types.myt 2006-03-26 15:36:43 UTC (rev 1213) +++ sqlalchemy/trunk/doc/build/content/types.myt 2006-03-26 19:58:08 UTC (rev 1214) </span><span class="lines">@@ -39,6 +39,10 @@ </span><span class="cx"> # rowset values, using the unicode encoding </span><span class="cx"> # setting on the engine (defaults to 'utf-8') </span><span class="cx"> class Unicode(String) </span><ins>+ + # uses the pickle protocol to serialize data + # in/out of Binary columns + class PickleType(Binary) </ins><span class="cx"> </&> </span><span class="cx"> <p>More specific subclasses of these types are available, which various database engines may choose to implement specifically, allowing finer grained control over types:</p> </span><span class="cx"> <&|formatting.myt:code&> </span><span class="lines">@@ -87,16 +91,21 @@ </span><span class="cx"> <&|formatting.myt:code, title="Pickle Type"&> </span><span class="cx"> import cPickle </span><span class="cx"> </span><del>- class PickleType(types.Binary): - def __init__(self, protocol=cPickle.HIGHEST_PROTOCOL): </del><ins>+ class PickleType(Binary): + def __init__(self, protocol=pickle.HIGHEST_PROTOCOL): </ins><span class="cx"> """allows the pickle protocol to be specified""" </span><span class="cx"> self.protocol = protocol </span><span class="cx"> def convert_result_value(self, value, engine): </span><del>- return cpickle.loads(super(PickleType, self).convert_result_value(value, engine), self.protocol) </del><ins>+ if value is None: + return None + buf = Binary.convert_result_value(self, value, engine) + return pickle.loads(str(buf)) </ins><span class="cx"> def convert_bind_param(self, value, engine): </span><del>- return super(PickleType, self).convert_bind_param(cpickle.dumps(value, self.protocol), engine) </del><ins>+ if value is None: + return None + return Binary.convert_bind_param(self, pickle.dumps(value, self.protocol), engine) </ins><span class="cx"> def get_constructor_args(self): </span><del>- return {'protocol':self.protocol} </del><ins>+ return {} </ins><span class="cx"> </&> </span><span class="cx"> <p>Which can be used like:</p> </span><span class="cx"> <&|formatting.myt:code&> </span></span></pre> </div> </div> </body> </html> |